Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(studio): normalize missing compile sources (#5611)

z1gon2819c0806ef1
diff --git a/web-studio/src/routes/compile/-lib/api.test.ts b/web-studio/src/routes/compile/-lib/api.test.ts
new file mode 100644
index 000000000..2f7dd1526
--- /dev/null
+++ b/web-studio/src/routes/compile/-lib/api.test.ts
@@ -0,0 +1,57 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { fetchCompileTask, fetchCompileTasks } from './api'
+
+const clientMocks = vi.hoisted(() => ({
+ get: vi.fn(),
+}))
+
+vi.mock('#/lib/ov-client', () => ({
+ getOvResult: async (value: unknown) => value,
+ OvClientError: class extends Error {},
+ ovClient: { client: clientMocks },
+}))
+
+const taskWithoutSources = {
+ task_id: 'cmp_memory',
+ task_type: 'compile',
+ status: 'failed',
+ meta: {
+ request: {
+ to: 'viking://user/default/memories/events',
+ skill: 'memory',
+ },
+ },
+}
+
+beforeEach(() => {
+ vi.clearAllMocks()
+})
+
+describe('compile task API normalization', () => {
+ it('normalizes an omitted source list in task pages', async () => {
+ clientMocks.get.mockResolvedValue({
+ items: [taskWithoutSources],
+ next_cursor: null,
+ has_more: false,
+ })
+
+ const page = await fetchCompileTasks()
+
+ expect(page.items[0].meta?.request?.from).toEqual([])
+ expect(taskWithoutSources.meta.request).not.toHaveProperty('from')
+ })
+
+ it('normalizes a null source list in task details', async () => {
+ clientMocks.get.mockResolvedValue({
+ ...taskWithoutSources,
+ meta: {
+ request: { ...taskWithoutSources.meta.request, from: null },
+ },
+ })
+
+ const task = await fetchCompileTask('cmp_memory')
+
+ expect(task.meta?.request?.from).toEqual([])
+ })
+})
diff --git a/web-studio/src/routes/compile/-lib/api.ts b/web-studio/src/routes/compile/-lib/api.ts
index 990fc0c59..92bc2e92a 100644
--- a/web-studio/src/routes/compile/-lib/api.ts
+++ b/web-studio/src/routes/compile/-lib/api.ts
@@ -12,11 +12,26 @@ export type CompileTask = TaskRecord & {
task_id: string
meta?: { request?: CompileRequest }
}
+type CompileTaskPayload = Omit<CompileTask, 'meta'> & {
+ meta?: {
+ request?: Omit<CompileRequest, 'from'> & { from?: string[] | null }
+ }
+}
export type TaskPage = {
items: CompileTask[]
next_cursor: string | null
has_more: boolean
}
+type TaskPagePayload = Omit<TaskPage, 'items'> & { items: CompileTaskPayload[] }
+
+const normalizeCompileTask = (task: CompileTaskPayload): CompileTask => {
+ const request = task.meta?.request
+ if (!request) return task as CompileTask
+ return {
+ ...task,
+ meta: { ...task.meta, request: { ...request, from: request.from ?? [] } },
+ }
+}
export const active = (status?: string) =>
['pending', 'running', 'cancelling'].includes(status ?? '')
export const taskTitle = (task: CompileTask) =>
@@ -33,7 +48,7 @@ export async function fetchCompileTasks(
cursor?: string,
signal?: AbortSignal,
) {
- const page = await getOvResult<TaskPage>(
+ const page = await getOvResult<TaskPagePayload>(
ovClient.client.get({
url: '/api/v1/tasks',
signal,
@@ -53,31 +68,37 @@ export async function fetchCompileTasks(
message:
'The server does not support paginated tasks. Update OpenViking and retry.',
})
- return page
+ return { ...page, items: page.items.map(normalizeCompileTask) }
}
-export function fetchCompileTask(id: string, signal?: AbortSignal) {
- return getOvResult<CompileTask>(
- ovClient.client.get({
- url: `/api/v1/tasks/${encodeURIComponent(id)}`,
- signal,
- query: { include_events: true },
- }),
+export async function fetchCompileTask(id: string, signal?: AbortSignal) {
+ return normalizeCompileTask(
+ await getOvResult<CompileTaskPayload>(
+ ovClient.client.get({
+ url: `/api/v1/tasks/${encodeURIComponent(id)}`,
+ signal,
+ query: { include_events: true },
+ }),
+ ),
)
}
-export function createCompile(body: CompileRequest, key: string) {
- return getOvResult<CompileTask>(
- ovClient.client.post({
- url: '/api/v1/compile',
- body,
- headers: { 'Idempotency-Key': key },
- }),
+export async function createCompile(body: CompileRequest, key: string) {
+ return normalizeCompileTask(
+ await getOvResult<CompileTaskPayload>(
+ ovClient.client.post({
+ url: '/api/v1/compile',
+ body,
+ headers: { 'Idempotency-Key': key },
+ }),
+ ),
)
}
-export function cancelCompile(id: string) {
- return getOvResult<CompileTask>(
- ovClient.client.post({
- url: `/api/v1/tasks/${encodeURIComponent(id)}/cancel`,
- }),
+export async function cancelCompile(id: string) {
+ return normalizeCompileTask(
+ await getOvResult<CompileTaskPayload>(
+ ovClient.client.post({
+ url: `/api/v1/tasks/${encodeURIComponent(id)}/cancel`,
+ }),
+ ),
)
}
export function fetchCapabilities() {
@@ -87,11 +108,13 @@ export function fetchCapabilities() {
reason_code?: string
}>(ovClient.client.get({ url: '/api/v1/compile/capabilities' }))
}
-export function lookupSubmission(key: string) {
- return getOvResult<CompileTask>(
- ovClient.client.get({
- url: `/api/v1/compile/submissions/${encodeURIComponent(key)}`,
- }),
+export async function lookupSubmission(key: string) {
+ return normalizeCompileTask(
+ await getOvResult<CompileTaskPayload>(
+ ovClient.client.get({
+ url: `/api/v1/compile/submissions/${encodeURIComponent(key)}`,
+ }),
+ ),
)
}
export type CompileSkill = { name: string; uri: string; description: string }