-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from nextcloud/fix/context-chat-sources-ui
fix: render context chat's the referenced source items
- Loading branch information
Showing
3 changed files
with
255 additions
and
62 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,107 @@ | ||
<template> | ||
<div class="output"> | ||
<ContextChatOutputForm v-if="selectedTaskTypeId === 'context_chat:context_chat'" | ||
class="output-fields" | ||
:output-shape="selectedTaskType.outputShape" | ||
:output="outputs" /> | ||
<TaskTypeFields v-else | ||
class="output-fields" | ||
:is-output="true" | ||
:shape="selectedTaskType.outputShape" | ||
:optional-shape="selectedTaskType.optionalOutputShape ?? null" | ||
:shape-options="selectedTaskType.outputShapeEnumValues ?? null" | ||
:optional-shape-options="selectedTaskType.optionalOutputShapeEnumValues ?? null" | ||
:values="outputs" | ||
:show-advanced="showAdvanced" | ||
@update:outputs="$emit('update:outputs', $event)" | ||
@update:show-advanced="$emit('update:show-advanced', $event)" /> | ||
<NcNoteCard v-if="outputEqualsInput" | ||
class="warning-note" | ||
type="warning"> | ||
{{ t('assistant', 'The task ran successfully but the result is identical to the input.') }} | ||
</NcNoteCard> | ||
<NcNoteCard v-else-if="hasInitialOutput" | ||
class="warning-note" | ||
type="warning"> | ||
{{ t('assistant', 'This output was generated by AI. Make sure to double-check and adjust.') }} | ||
</NcNoteCard> | ||
</div> | ||
</template> | ||
<script> | ||
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js' | ||
import ContextChatOutputForm from './ContextChat/ContextChatOutputForm.vue' | ||
import TaskTypeFields from './fields/TaskTypeFields.vue' | ||
export default { | ||
name: 'AssistantFormOutputs', | ||
components: { | ||
ContextChatOutputForm, | ||
TaskTypeFields, | ||
NcNoteCard, | ||
}, | ||
props: { | ||
inputs: { | ||
type: Object, | ||
default: () => {}, | ||
}, | ||
outputs: { | ||
type: Object, | ||
default: () => {}, | ||
}, | ||
selectedTaskType: { | ||
type: [Object, null], | ||
default: null, | ||
}, | ||
showAdvanced: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
computed: { | ||
selectedTaskTypeId() { | ||
return this.selectedTaskType?.id ?? null | ||
}, | ||
outputEqualsInput() { | ||
if (typeof this.inputs?.input === 'string' && typeof this.outputs?.output === 'string') { | ||
return this.hasInitialOutput && this.outputs.output?.trim() === this.inputs.input?.trim() | ||
} | ||
return false | ||
}, | ||
hasInitialOutput() { | ||
return !!this.outputs.output?.trim() | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.output { | ||
margin-top: 24px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: start; | ||
justify-content: center; | ||
.warning-note { | ||
align-self: normal; | ||
} | ||
hr { | ||
width: 100%; | ||
} | ||
.input-label { | ||
align-self: start; | ||
font-weight: bold; | ||
} | ||
.output-fields { | ||
width: 100%; | ||
} | ||
} | ||
</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
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,138 @@ | ||
<template> | ||
<div class="cc-output"> | ||
<div class="cc-output__text"> | ||
<TextField | ||
field-key="cc-output-text" | ||
:value="output.output" | ||
:field="outputShape.output" | ||
:is-output="true" /> | ||
</div> | ||
<div class="cc-output__sources"> | ||
<label for="v-select" class="cc-output__sources__label"> | ||
{{ outputShape.sources.description }} | ||
</label> | ||
<NcSelect | ||
:value="sources" | ||
:placeholder="t('assistant', 'No sources referenced')" | ||
:multiple="true" | ||
:close-on-select="false" | ||
:no-wrap="false" | ||
:label-outside="true" | ||
:append-to-body="false" | ||
:dropdown-should-open="() => false"> | ||
<template #option="option"> | ||
<a class="select-option" :href="option.url"> | ||
<NcAvatar | ||
:size="24" | ||
:url="option.icon" | ||
:display-name="option.label" /> | ||
<span class="multiselect-name"> | ||
{{ option.label }} | ||
</span> | ||
</a> | ||
</template> | ||
<template #selected-option="option"> | ||
<a class="select-option" :href="option.url"> | ||
<NcAvatar | ||
:size="24" | ||
:url="option.icon" | ||
:display-name="option.label" /> | ||
<span class="multiselect-name"> | ||
{{ option.label }} | ||
</span> | ||
</a> | ||
</template> | ||
</NcSelect> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js' | ||
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js' | ||
import TextField from '../fields/TextField.vue' | ||
export default { | ||
name: 'ContextChatOutputForm', | ||
components: { | ||
NcAvatar, | ||
NcSelect, | ||
TextField, | ||
}, | ||
props: { | ||
outputShape: { | ||
type: Object, | ||
required: true, | ||
}, | ||
output: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
sources() { | ||
try { | ||
return JSON.parse(this.output.sources) | ||
} catch (e) { | ||
console.error('Failed to parse sources', e) | ||
return [] | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.cc-output { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: start; | ||
gap: 8px; | ||
.advanced { | ||
width: 100%; | ||
} | ||
&__text { | ||
width: 100%; | ||
} | ||
&__sources { | ||
display: flex; | ||
flex-direction: column; | ||
:deep .v-select { | ||
min-width: 400px !important; | ||
> div { | ||
border: 2px solid var(--color-primary-element) !important; | ||
} | ||
.avatardiv { | ||
border-radius: 50%; | ||
&> img { | ||
border-radius: 0 !important; | ||
} | ||
} | ||
.vs__actions { | ||
display: none !important; | ||
} | ||
} | ||
.select-option { | ||
display: flex; | ||
align-items: center; | ||
} | ||
.multiselect-name { | ||
margin-left: 8px; | ||
} | ||
} | ||
} | ||
</style> |