Skip to content

Commit acd9760

Browse files
committed
Horizontal attachments layout and viewer for inputs
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 89f7804 commit acd9760

1 file changed

Lines changed: 41 additions & 18 deletions

File tree

src/components/ChattyLLM/Message.vue

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@
103103
:file-id="a.file_id"
104104
:task-id="message.role === 'human' ? undefined : (a.ocp_task_id ?? message.ocp_task_id)"
105105
:is-output="isOutput" />
106-
<FileDisplay v-for="f in fileAttachments"
107-
:key="f.type + '-' + f.file_id"
108-
class="message__content"
109-
:file-id="f.file_id"
110-
:task-id="message.role === 'human' ? undefined : (f.ocp_task_id ?? message.ocp_task_id)"
111-
:is-output="isOutput"
112-
:clickable="isOutput"
113-
@click.native="onPreviewClick(f)" />
106+
<div v-if="fileAttachments.length" class="message__content message__files">
107+
<FileDisplay v-for="f in fileAttachments"
108+
:key="f.type + '-' + f.file_id"
109+
:file-id="f.file_id"
110+
:task-id="message.role === 'human' ? undefined : (f.ocp_task_id ?? message.ocp_task_id)"
111+
:is-output="isOutput"
112+
:clickable="true"
113+
@click.native="onPreviewClick(f)" />
114+
</div>
114115
</div>
115116
</template>
116117

@@ -289,20 +290,35 @@ export default {
289290
}
290291
return this.informationSourceNames[source] ? this.informationSourceNames[source] : source
291292
},
293+
toViewerPath(path) {
294+
// `/userId/files/foo` -> `/foo` (Viewer expects a user-files-relative path)
295+
const match = /^\/[^/]+\/files(\/.*)$/.exec(path)
296+
return match ? match[1] : path
297+
},
292298
onPreviewClick(file) {
293-
// do not open input media files in the viewer
294-
if (file.file_id === null || !this.isOutput) {
299+
if (file.file_id === null) {
295300
return
296301
}
297302
298-
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', {
299-
taskId: file.ocp_task_id ?? this.message.ocp_task_id,
300-
fileId: file.file_id,
301-
})
302-
return axios.post(url).then(response => {
303-
const savedPath = response.data.ocs.data.path
304-
console.debug('[assistant] view output file', savedPath)
305-
OCA.Viewer.open({ path: savedPath })
303+
if (this.isOutput) {
304+
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', {
305+
taskId: file.ocp_task_id ?? this.message.ocp_task_id,
306+
fileId: file.file_id,
307+
})
308+
return axios.post(url).then(response => {
309+
const savedPath = response.data.ocs.data.path
310+
console.debug('[assistant] view output file', savedPath)
311+
OCA.Viewer.open({ path: savedPath })
312+
}).catch(error => {
313+
console.error(error)
314+
})
315+
}
316+
317+
const url = generateOcsUrl('/apps/assistant/api/v1/file/{fileId}/info', { fileId: file.file_id })
318+
return axios.get(url).then(response => {
319+
const path = this.toViewerPath(response.data.ocs.data.path)
320+
console.debug('[assistant] view input file', path)
321+
OCA.Viewer.open({ path })
306322
}).catch(error => {
307323
console.error(error)
308324
})
@@ -365,6 +381,13 @@ export default {
365381
width: auto !important;
366382
}
367383
}
384+
385+
&__files {
386+
display: flex;
387+
flex-direction: row;
388+
flex-wrap: wrap;
389+
gap: 0.5em;
390+
}
368391
}
369392
</style>
370393

0 commit comments

Comments
 (0)