-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Text processing assistant integration
Signed-off-by: Julius Härtl <[email protected]>
- Loading branch information
1 parent
c998357
commit a3ffbd8
Showing
2 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2023 Julius Härtl <[email protected]> | ||
- | ||
- @author Julius Härtl <[email protected]> | ||
- | ||
- @license GNU AGPL version 3 or any later version | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<template> | ||
<div class="text-assistant" v-if="showAssistant"> | ||
<h4> | ||
<span class="assistant-bubble"> | ||
<CreationIcon :size="16" class="icon" /> | ||
<span>{{ t('text', 'Nextcloud assistant') }}</span> | ||
</span> | ||
<NcActions :aria-label="t('text', 'Run assistant tasks')"> | ||
<template #icon> | ||
<CreationIcon :size="20" class="icon" /> | ||
</template> | ||
<NcActionButton v-for="provider in providers" :key="provider.task" @click="openAssistantForm(provider.task)"> | ||
<template #icon> | ||
</template> | ||
{{ provider.name }} | ||
</NcActionButton> | ||
</NcActions> | ||
</h4> | ||
<ul> | ||
<NcListItem v-for="task in tasks" | ||
:name="task.title" | ||
:bold="false" | ||
:force-display-actions="true"> | ||
<template #icon> | ||
<CheckIcon v-if="task.status === STATUS_SUCCESSFUL" :size="20" /> | ||
<AlertCircleOutline v-else-if="task.status === STATUS_FAILED" :size="20" /> | ||
<ClockOutline v-else :size="20" /> | ||
</template> | ||
<template #actions> | ||
<NcActionButton v-if="task.status === STATUS_SUCCESSFUL" :title="task.output"> | ||
<template #icon> | ||
<TextBoxPlusOutlineIcon :size="20" /> | ||
</template> | ||
{{ t('text', 'Insert result') }} | ||
</NcActionButton> | ||
</template> | ||
</NcListItem> | ||
</ul> | ||
</div> | ||
</template> | ||
<script> | ||
import axios from '@nextcloud/axios' | ||
import { generateOcsUrl } from '@nextcloud/router' | ||
import AlertCircleOutline from 'vue-material-design-icons/AlertCircleOutline.vue' | ||
import CreationIcon from 'vue-material-design-icons/Creation.vue' | ||
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue' | ||
import CheckIcon from 'vue-material-design-icons/Check.vue' | ||
import TextBoxPlusOutlineIcon from 'vue-material-design-icons/TextBoxPlusOutline.vue' | ||
const STATUS_FAILED = 4; | ||
const STATUS_SUCCESSFUL = 3; | ||
const STATUS_RUNNING = 2; | ||
const STATUS_SCHEDULED = 1; | ||
const STATUS_UNKNOWN = 0; | ||
import { NcActions, NcActionButton, NcButton, NcListItem } from '@nextcloud/vue' | ||
import { | ||
useEditorMixin, | ||
useIsRichWorkspaceMixin, | ||
useFileMixin, | ||
useIsPublicMixin, | ||
} from './Editor.provider.js' | ||
export default { | ||
name: 'Assistant', | ||
components: { | ||
AlertCircleOutline, | ||
CreationIcon, | ||
ClockOutline, | ||
CheckIcon, | ||
TextBoxPlusOutlineIcon, | ||
NcActions, | ||
NcActionButton, | ||
NcButton, | ||
NcListItem, | ||
}, | ||
mixins: [ | ||
useEditorMixin, | ||
useIsPublicMixin, | ||
useIsRichWorkspaceMixin, | ||
useFileMixin, | ||
], | ||
data() { | ||
return { | ||
providers: OCP.InitialState.loadState('text','textprocessing'), | ||
selection: '', | ||
tasks: [], | ||
STATUS_FAILED, | ||
STATUS_RUNNING, | ||
STATUS_SCHEDULED, | ||
STATUS_SUCCESSFUL, | ||
STATUS_UNKNOWN, | ||
/** { | ||
"id": 9, | ||
"type": "OCP\\TextProcessing\\HeadlineTaskType", | ||
"status": 1, | ||
"userId": "admin", | ||
"appId": "text", | ||
"input": "25 April to 10 May 2022 \"Open Source Programme Office\" at the European Commission organizes NextGov Hackathon and awards up to 5000 EUR for improvements to Nextcloud apps and security.[43][44][45]Nextcloud is a suite of client-server software for creating and using file hosting services. Nextcloud provides functionality similar to Dropbox, Office 365 or Google Drive when used with integrated office suites Collabora Online or OnlyOffice. It can be hosted in the cloud or on-premises. It is scalable, from home office software based on the low cost Raspberry Pi, all the way through to full sized data centers that support millions of users.[8][9][10] Translations in 60 languages exist for web interface and client applications.[11] ", | ||
"output": null, | ||
"identifier": "text-file:1486" | ||
}*/ | ||
} | ||
}, | ||
computed: { | ||
showAssistant() { | ||
return !this.$isRichWorkspace && !this.$isPublic && window?.OCA?.TPAssistant?.openAssistantForm | ||
}, | ||
identifier() { | ||
return 'text-file:' + this.$file.fileId | ||
}, | ||
}, | ||
beforeMount() { | ||
if (!this.showAssistant) { | ||
return | ||
} | ||
this.$editor.on('selectionUpdate', this.onSelection) | ||
this.fetchTasks() | ||
}, | ||
beforeDestroy() { | ||
if (!this.showAssistant) { | ||
return | ||
} | ||
this.$editor.off('selectionUpdate', this.onSelection) | ||
}, | ||
methods: { | ||
async fetchTasks() { | ||
const result = await axios.get(generateOcsUrl('/textprocessing/tasks/app/text') + '?identifier=' + this.identifier) | ||
const taskMap = {} | ||
for (const index in this.providers) { | ||
const provider = this.providers[index] | ||
taskMap[provider.task] = provider | ||
} | ||
this.tasks = result.data.ocs.data.tasks.map((task) => { | ||
return { | ||
...task, | ||
title: taskMap[task.type].name, | ||
} | ||
}) | ||
}, | ||
onSelection() { | ||
const { state } = this.$editor | ||
const { from, to } = state.selection | ||
this.selection = state.doc.textBetween(from, to, ' ') | ||
}, | ||
async openAssistantForm(taskType = null) { | ||
try { | ||
await window.OCA.TPAssistant.openAssistantForm('text', this.identifier, taskType, this.selection, true) | ||
this.fetchTasks() | ||
} catch (e) {} | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style scoped lang="scss"> | ||
.text-assistant { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
margin: calc(var(--default-grid-baseline) * 3); | ||
overflow: auto; | ||
width: 250px; | ||
max-height: 200px; | ||
} | ||
h4 { | ||
display: flex; | ||
align-items: center; | ||
justify-items: center; | ||
justify-content: space-between; | ||
position: sticky; | ||
top: 0; | ||
z-index: 1; | ||
} | ||
.assistant-bubble { | ||
display: flex; | ||
gap: 8px; | ||
background-color: var(--color-primary-element-light); | ||
border-radius: var(--border-radius-rounded); | ||
padding: 2px 8px; | ||
.icon { | ||
color: var(--color-primary); | ||
} | ||
} | ||
ul { | ||
width: calc(100% - 16px); | ||
& :deep(.list-item) { | ||
padding-top: 0; | ||
padding-bottom: 0; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters