From cd7492cd5c3caecd67163e24857252981e2b346c Mon Sep 17 00:00:00 2001 From: tylerslaton Date: Tue, 15 Oct 2024 10:57:54 -0400 Subject: [PATCH] feat: add custom error messages for service requests Signed-off-by: tylerslaton --- ui/admin/app/lib/service/api/agentService.ts | 5 +++++ ui/admin/app/lib/service/api/invokeService.ts | 1 + ui/admin/app/lib/service/api/knowledgeService.ts | 8 ++++++++ ui/admin/app/lib/service/api/runsService.ts | 3 +++ ui/admin/app/lib/service/api/threadsService.ts | 7 +++++++ ui/admin/app/lib/service/api/toolreferenceService.ts | 6 ++++++ ui/admin/app/lib/service/api/workflowService.ts | 7 ++++++- 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ui/admin/app/lib/service/api/agentService.ts b/ui/admin/app/lib/service/api/agentService.ts index 0d7ba6ea..b7a5ec85 100644 --- a/ui/admin/app/lib/service/api/agentService.ts +++ b/ui/admin/app/lib/service/api/agentService.ts @@ -5,6 +5,7 @@ import { request } from "~/lib/service/api/primitives"; async function getAgents() { const res = await request<{ items: Agent[] }>({ url: ApiRoutes.agents.base().url, + errorMessage: "Failed to fetch agents", }); return res.data.items ?? ([] as Agent[]); @@ -14,6 +15,7 @@ getAgents.key = () => ({ url: ApiRoutes.agents.base().path }) as const; const getAgentById = async (agentId: string) => { const res = await request({ url: ApiRoutes.agents.getById(agentId).url, + errorMessage: "Failed to fetch agent", }); if (!res.data) return null; @@ -31,6 +33,7 @@ async function createAgent({ agent }: { agent: CreateAgent }) { url: ApiRoutes.agents.base().url, method: "POST", data: agent, + errorMessage: "Failed to create agent", }); return res.data; @@ -41,6 +44,7 @@ async function updateAgent({ id, agent }: { id: string; agent: UpdateAgent }) { url: ApiRoutes.agents.getById(id).url, method: "PUT", data: agent, + errorMessage: "Failed to update agent", }); return res.data; @@ -50,6 +54,7 @@ async function deleteAgent(id: string) { await request({ url: ApiRoutes.agents.getById(id).url, method: "DELETE", + errorMessage: "Failed to delete agent", }); } diff --git a/ui/admin/app/lib/service/api/invokeService.ts b/ui/admin/app/lib/service/api/invokeService.ts index cf9e16fb..46f09c43 100644 --- a/ui/admin/app/lib/service/api/invokeService.ts +++ b/ui/admin/app/lib/service/api/invokeService.ts @@ -16,6 +16,7 @@ async function invokeWithStream({ headers: { Accept: "text/event-stream" }, responseType: "stream", data: prompt, + errorMessage: "Failed to invoke agent", }); const reader = response.data diff --git a/ui/admin/app/lib/service/api/knowledgeService.ts b/ui/admin/app/lib/service/api/knowledgeService.ts index d5e19f68..7ba1a2c7 100644 --- a/ui/admin/app/lib/service/api/knowledgeService.ts +++ b/ui/admin/app/lib/service/api/knowledgeService.ts @@ -9,6 +9,7 @@ import { request } from "~/lib/service/api/primitives"; async function getKnowledgeForAgent(agentId: string, includeDeleted = false) { const res = await request<{ items: KnowledgeFile[] }>({ url: ApiRoutes.agents.getKnowledge(agentId).url, + errorMessage: "Failed to fetch knowledge for agent", }); if (includeDeleted) return res.data.items; @@ -28,6 +29,7 @@ async function addKnowledgeToAgent(agentId: string, file: File) { method: "POST", data: await file.arrayBuffer(), headers: { "Content-Type": "application/x-www-form-urlencoded" }, + errorMessage: "Failed to add knowledge to agent", }); } @@ -35,6 +37,7 @@ async function deleteKnowledgeFromAgent(agentId: string, fileName: string) { await request({ url: ApiRoutes.agents.deleteKnowledge(agentId, fileName).url, method: "DELETE", + errorMessage: "Failed to delete knowledge from agent", }); } @@ -42,6 +45,7 @@ async function triggerKnowledgeIngestion(agentId: string) { await request({ url: ApiRoutes.agents.triggerKnowledgeIngestion(agentId).url, method: "POST", + errorMessage: "Failed to trigger knowledge ingestion", }); } @@ -53,6 +57,7 @@ async function createRemoteKnowledgeSource( url: ApiRoutes.agents.createRemoteKnowledgeSource(agentId).url, method: "POST", data: JSON.stringify(input), + errorMessage: "Failed to create remote knowledge source", }); return res.data; } @@ -69,6 +74,7 @@ async function updateRemoteKnowledgeSource( ).url, method: "PUT", data: JSON.stringify(input), + errorMessage: "Failed to update remote knowledge source", }); } @@ -82,6 +88,7 @@ async function resyncRemoteKnowledgeSource( remoteKnowledgeSourceId ).url, method: "PATCH", + errorMessage: "Failed to resync remote knowledge source", }); } @@ -90,6 +97,7 @@ async function getRemoteKnowledgeSource(agentId: string) { items: RemoteKnowledgeSource[]; }>({ url: ApiRoutes.agents.getRemoteKnowledgeSource(agentId).url, + errorMessage: "Failed to fetch remote knowledge source", }); return res.data.items; } diff --git a/ui/admin/app/lib/service/api/runsService.ts b/ui/admin/app/lib/service/api/runsService.ts index d9524011..d0a10b4b 100644 --- a/ui/admin/app/lib/service/api/runsService.ts +++ b/ui/admin/app/lib/service/api/runsService.ts @@ -5,6 +5,7 @@ import { request } from "~/lib/service/api/primitives"; const getRuns = async () => { const res = await request<{ items: Run[] }>({ url: ApiRoutes.runs.base().url, + errorMessage: "Failed to fetch runs", }); return res.data.items ?? ([] as Run[]); @@ -14,6 +15,7 @@ getRuns.key = () => ({ url: ApiRoutes.runs.base().path }); const getRunDebugById = async (runId: string) => { const res = await request({ url: ApiRoutes.runs.getDebugById(runId).url, + errorMessage: "Failed to fetch run debug", }); return res.data; @@ -27,6 +29,7 @@ getRunDebugById.key = (runId?: Nullish) => { const getRunsByThread = async (threadId: string) => { const res = await request<{ items: Run[] }>({ url: ApiRoutes.runs.getByThread(threadId).url, + errorMessage: "Failed to fetch runs by thread", }); return res.data.items; diff --git a/ui/admin/app/lib/service/api/threadsService.ts b/ui/admin/app/lib/service/api/threadsService.ts index 45028adc..fd2a5b1c 100644 --- a/ui/admin/app/lib/service/api/threadsService.ts +++ b/ui/admin/app/lib/service/api/threadsService.ts @@ -8,6 +8,7 @@ import { request } from "~/lib/service/api/primitives"; const getThreads = async () => { const res = await request<{ items: Thread[] }>({ url: ApiRoutes.threads.base().url, + errorMessage: "Failed to fetch threads", }); return res.data.items ?? ([] as Thread[]); @@ -17,6 +18,7 @@ getThreads.key = () => ({ url: ApiRoutes.threads.base().path }) as const; const getThreadById = async (threadId: string) => { const res = await request({ url: ApiRoutes.threads.getById(threadId).url, + errorMessage: "Failed to fetch thread", }); return res.data; @@ -30,6 +32,7 @@ getThreadById.key = (threadId?: Nullish) => { const getThreadsByAgent = async (agentId: string) => { const res = await request<{ items: Thread[] }>({ url: ApiRoutes.threads.getByAgent(agentId).url, + errorMessage: "Failed to fetch threads by agent", }); return res.data.items ?? ([] as Thread[]); @@ -44,6 +47,7 @@ const getThreadEvents = async (threadId: string) => { const res = await request<{ items: ChatEvent[] }>({ url: ApiRoutes.threads.events(threadId).url, headers: { Accept: "application/json" }, + errorMessage: "Failed to fetch thread events", }); return res.data.items ?? ([] as ChatEvent[]); @@ -58,12 +62,14 @@ const deleteThread = async (threadId: string) => { await request({ url: ApiRoutes.threads.getById(threadId).url, method: "DELETE", + errorMessage: "Failed to delete thread", }); }; const getKnowledge = async (threadId: string) => { const res = await request<{ items: KnowledgeFile[] }>({ url: ApiRoutes.threads.getKnowledge(threadId).url, + errorMessage: "Failed to fetch knowledge for thread", }); return res.data.items ?? ([] as KnowledgeFile[]); @@ -77,6 +83,7 @@ getKnowledge.key = (threadId?: Nullish) => { const getFiles = async (threadId: string) => { const res = await request<{ items: WorkspaceFile[] }>({ url: ApiRoutes.threads.getFiles(threadId).url, + errorMessage: "Failed to fetch files", }); return res.data.items ?? ([] as WorkspaceFile[]); diff --git a/ui/admin/app/lib/service/api/toolreferenceService.ts b/ui/admin/app/lib/service/api/toolreferenceService.ts index 3b5b9772..aa35441b 100644 --- a/ui/admin/app/lib/service/api/toolreferenceService.ts +++ b/ui/admin/app/lib/service/api/toolreferenceService.ts @@ -10,6 +10,7 @@ import { request } from "~/lib/service/api/primitives"; async function getToolReferences(type?: ToolReferenceType) { const res = await request<{ items: ToolReference[] }>({ url: ApiRoutes.toolReferences.base({ type }).url, + errorMessage: "Failed to fetch tool references", }); return res.data.items ?? ([] as ToolReference[]); @@ -27,6 +28,7 @@ export type ToolCategoryMap = Record; async function getToolReferencesCategoryMap(type?: ToolReferenceType) { const res = await request<{ items: ToolReference[] }>({ url: ApiRoutes.toolReferences.base({ type }).url, + errorMessage: "Failed to fetch tool references category map", }); const toolReferences = res.data.items; @@ -58,6 +60,7 @@ getToolReferencesCategoryMap.key = (type?: ToolReferenceType) => const getToolReferenceById = async (toolReferenceId: string) => { const res = await request({ url: ApiRoutes.toolReferences.getById(toolReferenceId).url, + errorMessage: "Failed to fetch tool reference", }); return res.data; @@ -80,6 +83,7 @@ async function createToolReference({ url: ApiRoutes.toolReferences.base().url, method: "POST", data: toolReference, + errorMessage: "Failed to create tool reference", }); return res.data; @@ -96,6 +100,7 @@ async function updateToolReference({ url: ApiRoutes.toolReferences.getById(id).url, method: "PUT", data: toolReference, + errorMessage: "Failed to update tool reference", }); return res.data; @@ -105,6 +110,7 @@ async function deleteToolReference(id: string) { await request({ url: ApiRoutes.toolReferences.getById(id).url, method: "DELETE", + errorMessage: "Failed to delete tool reference", }); } diff --git a/ui/admin/app/lib/service/api/workflowService.ts b/ui/admin/app/lib/service/api/workflowService.ts index b167c690..e8b957ed 100644 --- a/ui/admin/app/lib/service/api/workflowService.ts +++ b/ui/admin/app/lib/service/api/workflowService.ts @@ -9,6 +9,7 @@ import { request } from "~/lib/service/api/primitives"; async function getWorkflows() { const res = await request<{ items: Workflow[] }>({ url: ApiRoutes.workflows.base().url, + errorMessage: "Failed to fetch workflows", }); return res.data.items ?? ([] as Workflow[]); @@ -18,7 +19,8 @@ getWorkflows.key = () => ({ url: ApiRoutes.workflows.base().path }) as const; const getWorkflowById = async (workflowId: string) => { const res = await request({ url: ApiRoutes.workflows.getById(workflowId).url, - }); + errorMessage: "Failed to fetch workflow", + }); return res.data; }; @@ -33,6 +35,7 @@ async function createWorkflow({ workflow }: { workflow: CreateWorkflow }) { url: ApiRoutes.workflows.base().url, method: "POST", data: workflow, + errorMessage: "Failed to create workflow", }); return res.data; @@ -49,6 +52,7 @@ async function updateWorkflow({ url: ApiRoutes.workflows.getById(id).url, method: "PUT", data: workflow, + errorMessage: "Failed to update workflow", }); return res.data; @@ -58,6 +62,7 @@ async function deleteWorkflow(id: string) { await request({ url: ApiRoutes.workflows.getById(id).url, method: "DELETE", + errorMessage: "Failed to delete workflow", }); }