fix(open-webui): list knowledge-base files for the sub-document picker
The knowledge detail endpoint returns `files: null` on recent Open WebUI
versions, so the expandable picker showed nothing to select. List the
files endpoint and filter by the base's collection id instead; each file
grounds via its own `file-{id}` collection.
This commit is contained in:
1 parent
46454cc0f0
commit
18afb866b7
2 files changed
+16
-5
No files matched your search
@@ -24,7 +24,6 @@ import {
|
||||
openWebUiCollectionQueryResponseSchema,
|
||||
openWebUiCompletionChunkSchema,
|
||||
openWebUiFileListSchema,
|
||||
openWebUiKnowledgeDetailSchema,
|
||||
openWebUiKnowledgeListSchema,
|
||||
openWebUiModelsResponseSchema,
|
||||
openWebUiNoteListSchema,
|
||||
@@ -99,9 +98,11 @@ export class OpenWebUiIntegration extends Integration {
|
||||
|
||||
/**
|
||||
* List the files contained in a knowledge base (for the expandable picker).
|
||||
* The knowledge detail endpoint returns `files: null` on recent versions, so
|
||||
* we read the files list and filter by the base's collection id instead.
|
||||
*/
|
||||
public async getKnowledgeFilesAsync(knowledgeId: string): Promise<OpenWebUiFileSummary[]> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/knowledge/${knowledgeId}`), {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/files/"), {
|
||||
headers: this.getAuthHeaders(),
|
||||
});
|
||||
|
||||
@@ -109,8 +110,11 @@ export class OpenWebUiIntegration extends Integration {
|
||||
throw new ResponseError(response);
|
||||
}
|
||||
|
||||
const parsed = openWebUiKnowledgeDetailSchema.parse(await response.json());
|
||||
return (parsed.files ?? []).map((file) => ({ id: file.id, name: file.meta?.name ?? file.filename ?? file.id }));
|
||||
const parsed = openWebUiFileListSchema.parse(await response.json());
|
||||
const files = Array.isArray(parsed) ? parsed : parsed.items;
|
||||
return files
|
||||
.filter((file) => file.meta?.collection_name === knowledgeId)
|
||||
.map((file) => ({ id: file.id, name: file.meta?.name ?? file.filename ?? file.id }));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,10 +87,17 @@ export const openWebUiKnowledgeListSchema = z.union([
|
||||
]);
|
||||
|
||||
// A file stored in Open WebUI (uploaded directly or part of a knowledge base).
|
||||
// `meta.collection_name` is the knowledge base id when the file belongs to one.
|
||||
export const openWebUiFileSchema = z.object({
|
||||
id: z.string(),
|
||||
filename: z.string().nullish(),
|
||||
meta: z.object({ name: z.string().nullish(), content_type: z.string().nullish() }).nullish(),
|
||||
meta: z
|
||||
.object({
|
||||
name: z.string().nullish(),
|
||||
content_type: z.string().nullish(),
|
||||
collection_name: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
});
|
||||
|
||||
export type OpenWebUiFile = z.infer<typeof openWebUiFileSchema>;
|
||||
|
||||
Reference in new issue
Block a user