- Voice messages: record from the microphone and transcribe to the input via Open WebUI's /api/v1/audio/transcriptions (mic button in composer). - Camera capture: attach the stream via a ref callback so the preview is no longer a black frame (the ref could be read before the video mounted). - Notes: fetch the full note body on attach. The list endpoint truncates content to 1000 chars, so attached notes were cut off; getNote returns the complete markdown.
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import dayjs from "dayjs";
|
|
|
|
import { createIntegrationAsync } from "@homarr/integrations";
|
|
import type {
|
|
OpenWebUiChat,
|
|
OpenWebUiChatListItem,
|
|
OpenWebUiFileSummary,
|
|
OpenWebUiKnowledge,
|
|
OpenWebUiModel,
|
|
OpenWebUiNote,
|
|
} from "@homarr/integrations/types";
|
|
|
|
import { createCachedIntegrationRequestHandler } from "./lib/cached-integration-request-handler";
|
|
|
|
export const openWebUiModelsRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiModel[],
|
|
"openWebUi",
|
|
Record<string, never>
|
|
>({
|
|
async requestAsync(integration) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.getModelsAsync();
|
|
},
|
|
cacheDuration: dayjs.duration(5, "minutes"),
|
|
queryKey: "openWebUiModels",
|
|
});
|
|
|
|
export const openWebUiKnowledgeRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiKnowledge[],
|
|
"openWebUi",
|
|
Record<string, never>
|
|
>({
|
|
async requestAsync(integration) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.getKnowledgeAsync();
|
|
},
|
|
cacheDuration: dayjs.duration(5, "minutes"),
|
|
queryKey: "openWebUiKnowledge",
|
|
});
|
|
|
|
export const openWebUiKnowledgeFilesRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiFileSummary[],
|
|
"openWebUi",
|
|
{ knowledgeId: string }
|
|
>({
|
|
async requestAsync(integration, input) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.getKnowledgeFilesAsync(input.knowledgeId);
|
|
},
|
|
cacheDuration: dayjs.duration(1, "minute"),
|
|
queryKey: "openWebUiKnowledgeFiles",
|
|
});
|
|
|
|
export const openWebUiFilesRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiFileSummary[],
|
|
"openWebUi",
|
|
Record<string, never>
|
|
>({
|
|
async requestAsync(integration) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.listFilesAsync();
|
|
},
|
|
cacheDuration: dayjs.duration(30, "seconds"),
|
|
queryKey: "openWebUiFiles",
|
|
});
|
|
|
|
export const openWebUiNotesRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiNote[],
|
|
"openWebUi",
|
|
Record<string, never>
|
|
>({
|
|
async requestAsync(integration) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.listNotesAsync();
|
|
},
|
|
cacheDuration: dayjs.duration(30, "seconds"),
|
|
queryKey: "openWebUiNotes",
|
|
});
|
|
|
|
export const openWebUiNoteRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiNote,
|
|
"openWebUi",
|
|
{ noteId: string }
|
|
>({
|
|
async requestAsync(integration, input) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.getNoteAsync(input.noteId);
|
|
},
|
|
cacheDuration: dayjs.duration(30, "seconds"),
|
|
queryKey: "openWebUiNote",
|
|
});
|
|
|
|
export const openWebUiChatsRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiChatListItem[],
|
|
"openWebUi",
|
|
Record<string, never>
|
|
>({
|
|
async requestAsync(integration) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.listChatsAsync();
|
|
},
|
|
cacheDuration: dayjs.duration(15, "seconds"),
|
|
queryKey: "openWebUiChats",
|
|
});
|
|
|
|
export const openWebUiChatRequestHandler = createCachedIntegrationRequestHandler<
|
|
OpenWebUiChat,
|
|
"openWebUi",
|
|
{ chatId: string }
|
|
>({
|
|
async requestAsync(integration, input) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
return await integrationInstance.getChatAsync(input.chatId);
|
|
},
|
|
cacheDuration: dayjs.duration(15, "seconds"),
|
|
queryKey: "openWebUiChat",
|
|
});
|