Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(studio): forward admin key for bot chat requests (#6215)
Luciena3169a824f50
diff --git a/web-studio/src/lib/sessions/api.test.ts b/web-studio/src/lib/sessions/api.test.tsindex b3531fcaf..12371fe68 100644--- a/web-studio/src/lib/sessions/api.test.ts+++ b/web-studio/src/lib/sessions/api.test.ts@@ -1,11 +1,15 @@-import { beforeEach, describe, expect, it, vi } from 'vitest'+// @vitest-environment jsdom++import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { OvClientError, ovClient } from '#/lib/ov-client'import {fetchSessionFirstTitle,fetchSessionMessages,+ fetchBotHealth,interruptChatSession,+ sendChatStream,steerChatSession,serializeParts,} from './api'@@ -411,6 +415,58 @@ describe('fetchSessionFirstTitle', () => {})})+describe('Bot fetch credentials', () => {+ afterEach(() => {+ ovClient.clearConnection()+ vi.unstubAllGlobals()+ })++ it.each([+ { apiKey: '', expectedKey: 'root-key' },+ { apiKey: 'data-key', expectedKey: 'data-key' },+ ])('uses $expectedKey for Bot requests', async ({ apiKey, expectedKey }) => {+ ovClient.setOptions({ baseUrl: 'http://localhost:1933' })+ ovClient.setConnection({+ accountId: 'account-1',+ adminApiKey: 'root-key',+ apiKey,+ identityHeaders: true,+ userId: 'user-1',+ })+ const fetchMock = vi.fn().mockImplementation(async (url: string) =>+ url.endsWith('/stream')+ ? new Response('data: hello\n\n', {+ headers: { 'Content-Type': 'text/event-stream' },+ })+ : new Response(JSON.stringify({ accepted: true, interrupted: true })),+ )+ vi.stubGlobal('fetch', fetchMock)++ await fetchBotHealth()+ const messages = []+ for await (const event of await sendChatStream({ message: 'hello' })) {+ messages.push(event.data)+ }+ expect(messages).toEqual(['hello'])+ await steerChatSession('session 1', { message: 'next input' })+ await interruptChatSession('session 1')++ expect(fetchMock.mock.calls.map(([url]) => url)).toEqual([+ 'http://localhost:1933/bot/v1/health',+ 'http://localhost:1933/bot/v1/chat/stream',+ 'http://localhost:1933/bot/v1/sessions/session%201/steer',+ 'http://localhost:1933/bot/v1/sessions/session%201/interrupt',+ ])+ for (const [, options] of fetchMock.mock.calls) {+ expect(options.headers).toMatchObject({+ 'X-API-Key': expectedKey,+ 'X-OpenViking-Account': 'account-1',+ 'X-OpenViking-User': 'user-1',+ })+ }+ })+})+describe('interruptChatSession', () => {beforeEach(() => {ovClient.setOptions({ baseUrl: 'http://localhost:1933' })diff --git a/web-studio/src/lib/sessions/api.ts b/web-studio/src/lib/sessions/api.tsindex 03efed735..4a29d3a2d 100644--- a/web-studio/src/lib/sessions/api.ts+++ b/web-studio/src/lib/sessions/api.ts@@ -433,7 +433,8 @@ function extractErrorMessage(text: string, fallback: string): string {function buildFetchHeaders(): Record<string, string> {const conn = ovClient.getConnection()const headers: Record<string, string> = { 'Content-Type': 'application/json' }- if (conn.apiKey) headers['X-API-Key'] = conn.apiKey+ const apiKey = conn.apiKey || conn.adminApiKey+ if (apiKey) headers['X-API-Key'] = apiKeyif (conn.identityHeaders) {if (conn.accountId) headers['X-OpenViking-Account'] = conn.accountIdif (conn.userId) headers['X-OpenViking-User'] = conn.userId