@copilotkitnext/runtime 1.54.1-next.2 → 1.54.1-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/intelligence/run.cjs +8 -6
- package/dist/handlers/intelligence/run.cjs.map +1 -1
- package/dist/handlers/intelligence/run.mjs +8 -6
- package/dist/handlers/intelligence/run.mjs.map +1 -1
- package/dist/handlers/intelligence/thread-names.cjs +2 -1
- package/dist/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/handlers/intelligence/thread-names.mjs +2 -1
- package/dist/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/handlers/intelligence/threads.cjs +52 -34
- package/dist/handlers/intelligence/threads.cjs.map +1 -1
- package/dist/handlers/intelligence/threads.mjs +52 -34
- package/dist/handlers/intelligence/threads.mjs.map +1 -1
- package/dist/handlers/shared/json-response.cjs +4 -0
- package/dist/handlers/shared/json-response.cjs.map +1 -1
- package/dist/handlers/shared/json-response.mjs +4 -1
- package/dist/handlers/shared/json-response.mjs.map +1 -1
- package/dist/handlers/shared/resolve-intelligence-user.cjs +19 -0
- package/dist/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
- package/dist/handlers/shared/resolve-intelligence-user.mjs +19 -0
- package/dist/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/runtime.cjs +5 -0
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +11 -1
- package/dist/runtime.d.cts.map +1 -1
- package/dist/runtime.d.mts +11 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +5 -0
- package/dist/runtime.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_telemetry_client = require('../../telemetry/telemetry-client.cjs');
|
|
3
3
|
require('../../telemetry/index.cjs');
|
|
4
|
-
const
|
|
4
|
+
const require_json_response = require('../shared/json-response.cjs');
|
|
5
5
|
const require_thread_names = require('./thread-names.cjs');
|
|
6
|
+
const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
|
|
6
7
|
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
7
8
|
|
|
8
9
|
//#region src/handlers/intelligence/run.ts
|
|
@@ -11,11 +12,12 @@ async function handleIntelligenceRun({ runtime, request, agentId, agent, input }
|
|
|
11
12
|
error: "Intelligence not configured",
|
|
12
13
|
message: "Intelligence mode requires a CopilotKitIntelligence"
|
|
13
14
|
}, { status: 500 });
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
|
|
16
|
+
runtime,
|
|
17
|
+
request
|
|
18
|
+
});
|
|
19
|
+
if (require_json_response.isHandlerResponse(user)) return user;
|
|
20
|
+
const userId = user.id;
|
|
19
21
|
try {
|
|
20
22
|
const { thread, created } = await runtime.intelligence.getOrCreateThread({
|
|
21
23
|
threadId: input.threadId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.cjs","names":["
|
|
1
|
+
{"version":3,"file":"run.cjs","names":["resolveIntelligenceUser","isHandlerResponse","generateThreadNameForNewThread"],"sources":["../../../src/handlers/intelligence/run.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport { generateThreadNameForNewThread } from \"./thread-names\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { telemetry } from \"../../telemetry\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceRunParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n}\n\nexport async function handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n}: HandleIntelligenceRunParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n const userId = user.id;\n\n try {\n const { thread, created } = await runtime.intelligence.getOrCreateThread({\n threadId: input.threadId,\n userId,\n agentId,\n });\n\n if (created && runtime.generateThreadNames && !thread.name?.trim()) {\n void generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput: input,\n thread,\n userId,\n }).catch((nameError) => {\n logger.error(\"Failed to generate thread name:\", nameError);\n });\n }\n } catch (error) {\n logger.error(\"Failed to get or create thread:\", error);\n return Response.json(\n {\n error: \"Failed to initialize thread\",\n },\n { status: 502 },\n );\n }\n\n let joinCode: string | undefined;\n let joinToken: string | undefined;\n try {\n const lockResult = await runtime.intelligence.ɵacquireThreadLock({\n threadId: input.threadId,\n runId: input.runId,\n });\n joinToken = lockResult.joinToken;\n joinCode = lockResult.joinCode;\n } catch (error) {\n logger.error(\"Thread lock denied:\", error);\n return Response.json(\n {\n error: \"Thread lock denied\",\n },\n { status: 409 },\n );\n }\n\n if (!joinToken) {\n return Response.json(\n {\n error: \"Join token not available\",\n message: \"Intelligence platform did not return a join token\",\n },\n { status: 502 },\n );\n }\n\n let persistedInputMessages: Message[] | undefined;\n if (Array.isArray(input.messages)) {\n try {\n const history = await runtime.intelligence.getThreadMessages({\n threadId: input.threadId,\n });\n const historicMessageIds = new Set(\n history.messages.map((message) => message.id),\n );\n persistedInputMessages = input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n );\n } catch (error) {\n logger.error(\"Thread history lookup failed:\", error);\n return Response.json(\n {\n error: \"Thread history lookup failed\",\n },\n { status: 502 },\n );\n }\n }\n\n telemetry.capture(\"oss.runtime.agent_execution_stream_started\", {});\n\n runtime.runner\n .run({\n threadId: input.threadId,\n agent,\n input,\n ...(persistedInputMessages !== undefined\n ? { persistedInputMessages }\n : {}),\n ...(joinCode ? { joinCode } : {}),\n })\n .subscribe({\n error: (error) => {\n telemetry.capture(\"oss.runtime.agent_execution_stream_errored\", {\n error: error instanceof Error ? error.message : String(error),\n });\n logger.error(\"Error running agent:\", error);\n },\n complete: () => {\n telemetry.capture(\"oss.runtime.agent_execution_stream_ended\", {});\n },\n });\n\n return Response.json(\n { joinToken },\n {\n headers: { \"Cache-Control\": \"no-cache\" },\n },\n );\n}\n"],"mappings":";;;;;;;;;AAgBA,eAAsB,sBAAsB,EAC1C,SACA,SACA,SACA,OACA,SACiD;AACjD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;CAGH,MAAM,OAAO,MAAMA,0DAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAIC,wCAAkB,KAAK,CACzB,QAAO;CAET,MAAM,SAAS,KAAK;AAEpB,KAAI;EACF,MAAM,EAAE,QAAQ,YAAY,MAAM,QAAQ,aAAa,kBAAkB;GACvE,UAAU,MAAM;GAChB;GACA;GACD,CAAC;AAEF,MAAI,WAAW,QAAQ,uBAAuB,CAAC,OAAO,MAAM,MAAM,CAChE,CAAKC,oDAA+B;GAClC;GACA;GACA;GACA,aAAa;GACb;GACA;GACD,CAAC,CAAC,OAAO,cAAc;AACtB,iCAAO,MAAM,mCAAmC,UAAU;IAC1D;UAEG,OAAO;AACd,gCAAO,MAAM,mCAAmC,MAAM;AACtD,SAAO,SAAS,KACd,EACE,OAAO,+BACR,EACD,EAAE,QAAQ,KAAK,CAChB;;CAGH,IAAI;CACJ,IAAI;AACJ,KAAI;EACF,MAAM,aAAa,MAAM,QAAQ,aAAa,mBAAmB;GAC/D,UAAU,MAAM;GAChB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telemetry from "../../telemetry/telemetry-client.mjs";
|
|
2
2
|
import "../../telemetry/index.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { isHandlerResponse } from "../shared/json-response.mjs";
|
|
4
4
|
import { generateThreadNameForNewThread } from "./thread-names.mjs";
|
|
5
|
+
import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
|
|
5
6
|
import { logger } from "@copilotkitnext/shared";
|
|
6
7
|
|
|
7
8
|
//#region src/handlers/intelligence/run.ts
|
|
@@ -10,11 +11,12 @@ async function handleIntelligenceRun({ runtime, request, agentId, agent, input }
|
|
|
10
11
|
error: "Intelligence not configured",
|
|
11
12
|
message: "Intelligence mode requires a CopilotKitIntelligence"
|
|
12
13
|
}, { status: 500 });
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const user = await resolveIntelligenceUser({
|
|
15
|
+
runtime,
|
|
16
|
+
request
|
|
17
|
+
});
|
|
18
|
+
if (isHandlerResponse(user)) return user;
|
|
19
|
+
const userId = user.id;
|
|
18
20
|
try {
|
|
19
21
|
const { thread, created } = await runtime.intelligence.getOrCreateThread({
|
|
20
22
|
threadId: input.threadId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.mjs","names":[],"sources":["../../../src/handlers/intelligence/run.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport {
|
|
1
|
+
{"version":3,"file":"run.mjs","names":[],"sources":["../../../src/handlers/intelligence/run.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport { generateThreadNameForNewThread } from \"./thread-names\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { telemetry } from \"../../telemetry\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceRunParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n}\n\nexport async function handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n}: HandleIntelligenceRunParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n const userId = user.id;\n\n try {\n const { thread, created } = await runtime.intelligence.getOrCreateThread({\n threadId: input.threadId,\n userId,\n agentId,\n });\n\n if (created && runtime.generateThreadNames && !thread.name?.trim()) {\n void generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput: input,\n thread,\n userId,\n }).catch((nameError) => {\n logger.error(\"Failed to generate thread name:\", nameError);\n });\n }\n } catch (error) {\n logger.error(\"Failed to get or create thread:\", error);\n return Response.json(\n {\n error: \"Failed to initialize thread\",\n },\n { status: 502 },\n );\n }\n\n let joinCode: string | undefined;\n let joinToken: string | undefined;\n try {\n const lockResult = await runtime.intelligence.ɵacquireThreadLock({\n threadId: input.threadId,\n runId: input.runId,\n });\n joinToken = lockResult.joinToken;\n joinCode = lockResult.joinCode;\n } catch (error) {\n logger.error(\"Thread lock denied:\", error);\n return Response.json(\n {\n error: \"Thread lock denied\",\n },\n { status: 409 },\n );\n }\n\n if (!joinToken) {\n return Response.json(\n {\n error: \"Join token not available\",\n message: \"Intelligence platform did not return a join token\",\n },\n { status: 502 },\n );\n }\n\n let persistedInputMessages: Message[] | undefined;\n if (Array.isArray(input.messages)) {\n try {\n const history = await runtime.intelligence.getThreadMessages({\n threadId: input.threadId,\n });\n const historicMessageIds = new Set(\n history.messages.map((message) => message.id),\n );\n persistedInputMessages = input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n );\n } catch (error) {\n logger.error(\"Thread history lookup failed:\", error);\n return Response.json(\n {\n error: \"Thread history lookup failed\",\n },\n { status: 502 },\n );\n }\n }\n\n telemetry.capture(\"oss.runtime.agent_execution_stream_started\", {});\n\n runtime.runner\n .run({\n threadId: input.threadId,\n agent,\n input,\n ...(persistedInputMessages !== undefined\n ? { persistedInputMessages }\n : {}),\n ...(joinCode ? { joinCode } : {}),\n })\n .subscribe({\n error: (error) => {\n telemetry.capture(\"oss.runtime.agent_execution_stream_errored\", {\n error: error instanceof Error ? error.message : String(error),\n });\n logger.error(\"Error running agent:\", error);\n },\n complete: () => {\n telemetry.capture(\"oss.runtime.agent_execution_stream_ended\", {});\n },\n });\n\n return Response.json(\n { joinToken },\n {\n headers: { \"Cache-Control\": \"no-cache\" },\n },\n );\n}\n"],"mappings":";;;;;;;;AAgBA,eAAsB,sBAAsB,EAC1C,SACA,SACA,SACA,OACA,SACiD;AACjD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;CAGH,MAAM,OAAO,MAAM,wBAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,kBAAkB,KAAK,CACzB,QAAO;CAET,MAAM,SAAS,KAAK;AAEpB,KAAI;EACF,MAAM,EAAE,QAAQ,YAAY,MAAM,QAAQ,aAAa,kBAAkB;GACvE,UAAU,MAAM;GAChB;GACA;GACD,CAAC;AAEF,MAAI,WAAW,QAAQ,uBAAuB,CAAC,OAAO,MAAM,MAAM,CAChE,CAAK,+BAA+B;GAClC;GACA;GACA;GACA,aAAa;GACb;GACA;GACD,CAAC,CAAC,OAAO,cAAc;AACtB,UAAO,MAAM,mCAAmC,UAAU;IAC1D;UAEG,OAAO;AACd,SAAO,MAAM,mCAAmC,MAAM;AACtD,SAAO,SAAS,KACd,EACE,OAAO,+BACR,EACD,EAAE,QAAQ,KAAK,CAChB;;CAGH,IAAI;CACJ,IAAI;AAC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AE,iBAAiB,YAAY,EACzC,CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_agent_utils = require('../shared/agent-utils.cjs');
|
|
3
|
+
const require_json_response = require('../shared/json-response.cjs');
|
|
3
4
|
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
4
5
|
let node_crypto = require("node:crypto");
|
|
5
6
|
|
|
@@ -59,7 +60,7 @@ async function generateThreadNameForNewThread({ runtime, request, agentId, sourc
|
|
|
59
60
|
async function runTitleGenerationAttempt(params) {
|
|
60
61
|
const { runtime, request, agentId, threadId, prompt } = params;
|
|
61
62
|
const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId);
|
|
62
|
-
if (agent
|
|
63
|
+
if (require_json_response.isHandlerResponse(agent)) {
|
|
63
64
|
_copilotkitnext_shared.logger.warn({
|
|
64
65
|
agentId,
|
|
65
66
|
threadId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-names.cjs","names":["cloneAgentForRequest"],"sources":["../../../src/handlers/intelligence/thread-names.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { randomUUID } from \"node:crypto\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n} from \"../shared/agent-utils\";\nimport { ThreadSummary } from \"../../intelligence-platform\";\n\nconst THREAD_NAME_SYSTEM_PROMPT = [\n \"You generate short, specific conversation titles.\",\n 'Return JSON only in this exact shape: {\"title\":\"...\"}',\n \"The title must be 2 to 5 words.\",\n \"Use sentence case.\",\n \"No quotes.\",\n \"No emoji.\",\n \"No markdown characters or formatting.\",\n \"Do not use *, _, #, `, [, ], (, ), !, ~, >, or |.\",\n \"No trailing punctuation.\",\n \"No explanations.\",\n \"Do not call tools.\",\n].join(\"\\n\");\n\nconst MAX_TITLE_LENGTH = 80;\nconst MAX_TITLE_WORDS = 8;\nconst MAX_TRANSCRIPT_MESSAGES = 8;\nconst MAX_TITLE_GENERATION_ATTEMPTS = 3;\nconst FALLBACK_THREAD_TITLE = \"Untitled\";\n\ninterface GenerateThreadNameParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n sourceInput: RunAgentInput;\n thread: ThreadSummary;\n userId: string;\n}\n\nexport async function generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput,\n thread,\n userId,\n}: GenerateThreadNameParams): Promise<void> {\n if (!runtime.generateThreadNames || hasThreadName(thread.name)) {\n return;\n }\n\n const prompt = buildThreadTitlePrompt(sourceInput.messages);\n if (!prompt) {\n return;\n }\n\n let generatedTitle: string | null = null;\n\n for (let attempt = 1; attempt <= MAX_TITLE_GENERATION_ATTEMPTS; attempt++) {\n try {\n generatedTitle = await runTitleGenerationAttempt({\n runtime,\n request,\n agentId,\n threadId: thread.id,\n prompt,\n });\n\n if (generatedTitle) {\n break;\n }\n\n logger.warn(\n { agentId, attempt, threadId: thread.id },\n \"Thread name generation returned an empty or invalid title\",\n );\n } catch (error) {\n logger.warn(\n { err: error, agentId, attempt, threadId: thread.id },\n \"Thread name generation attempt failed\",\n );\n }\n }\n\n await runtime.intelligence.updateThread({\n threadId: thread.id,\n userId,\n agentId,\n updates: { name: generatedTitle ?? FALLBACK_THREAD_TITLE },\n });\n}\n\nasync function runTitleGenerationAttempt(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n prompt: string;\n}): Promise<string | null> {\n const { runtime, request, agentId, threadId, prompt } = params;\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (agent
|
|
1
|
+
{"version":3,"file":"thread-names.cjs","names":["cloneAgentForRequest","isHandlerResponse"],"sources":["../../../src/handlers/intelligence/thread-names.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { randomUUID } from \"node:crypto\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n} from \"../shared/agent-utils\";\nimport { ThreadSummary } from \"../../intelligence-platform\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\nconst THREAD_NAME_SYSTEM_PROMPT = [\n \"You generate short, specific conversation titles.\",\n 'Return JSON only in this exact shape: {\"title\":\"...\"}',\n \"The title must be 2 to 5 words.\",\n \"Use sentence case.\",\n \"No quotes.\",\n \"No emoji.\",\n \"No markdown characters or formatting.\",\n \"Do not use *, _, #, `, [, ], (, ), !, ~, >, or |.\",\n \"No trailing punctuation.\",\n \"No explanations.\",\n \"Do not call tools.\",\n].join(\"\\n\");\n\nconst MAX_TITLE_LENGTH = 80;\nconst MAX_TITLE_WORDS = 8;\nconst MAX_TRANSCRIPT_MESSAGES = 8;\nconst MAX_TITLE_GENERATION_ATTEMPTS = 3;\nconst FALLBACK_THREAD_TITLE = \"Untitled\";\n\ninterface GenerateThreadNameParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n sourceInput: RunAgentInput;\n thread: ThreadSummary;\n userId: string;\n}\n\nexport async function generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput,\n thread,\n userId,\n}: GenerateThreadNameParams): Promise<void> {\n if (!runtime.generateThreadNames || hasThreadName(thread.name)) {\n return;\n }\n\n const prompt = buildThreadTitlePrompt(sourceInput.messages);\n if (!prompt) {\n return;\n }\n\n let generatedTitle: string | null = null;\n\n for (let attempt = 1; attempt <= MAX_TITLE_GENERATION_ATTEMPTS; attempt++) {\n try {\n generatedTitle = await runTitleGenerationAttempt({\n runtime,\n request,\n agentId,\n threadId: thread.id,\n prompt,\n });\n\n if (generatedTitle) {\n break;\n }\n\n logger.warn(\n { agentId, attempt, threadId: thread.id },\n \"Thread name generation returned an empty or invalid title\",\n );\n } catch (error) {\n logger.warn(\n { err: error, agentId, attempt, threadId: thread.id },\n \"Thread name generation attempt failed\",\n );\n }\n }\n\n await runtime.intelligence.updateThread({\n threadId: thread.id,\n userId,\n agentId,\n updates: { name: generatedTitle ?? FALLBACK_THREAD_TITLE },\n });\n}\n\nasync function runTitleGenerationAttempt(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n prompt: string;\n}): Promise<string | null> {\n const { runtime, request, agentId, threadId, prompt } = params;\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (isHandlerResponse(agent)) {\n logger.warn(\n { agentId, threadId },\n \"Skipping thread naming because the agent could not be cloned\",\n );\n return null;\n }\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n });\n\n const messages: Message[] = [\n {\n id: randomUUID(),\n role: \"system\",\n content: THREAD_NAME_SYSTEM_PROMPT,\n },\n {\n id: randomUUID(),\n role: \"user\",\n content: prompt,\n },\n ];\n\n agent.setMessages(messages);\n agent.setState({});\n agent.threadId = `thread-name:${threadId}:${randomUUID()}`;\n const { newMessages } = await agent.runAgent({\n messages,\n state: {},\n tools: [],\n context: [],\n forwardedProps: {},\n });\n\n const lastMessage = newMessages.at(-1);\n const titleContent = lastMessage\n ? stringifyMessageContent(lastMessage.content)\n : \"\";\n\n return normalizeGeneratedTitle(titleContent);\n}\n\nfunction buildThreadTitlePrompt(\n messages: Message[] | undefined,\n): string | null {\n const transcript = (messages ?? [])\n .filter((message) =>\n [\"user\", \"assistant\", \"system\", \"developer\"].includes(message.role),\n )\n .map((message) => {\n const content = stringifyMessageContent(message.content);\n if (!content) {\n return null;\n }\n\n return `${message.role}: ${content}`;\n })\n .filter((message): message is string => !!message)\n .slice(-MAX_TRANSCRIPT_MESSAGES);\n\n if (transcript.length === 0) {\n return null;\n }\n\n return [\n \"Generate a short title for this conversation.\",\n \"Conversation:\",\n transcript.join(\"\\n\"),\n ].join(\"\\n\\n\");\n}\n\nfunction stringifyMessageContent(content: Message[\"content\"]): string {\n if (typeof content === \"string\") {\n return content.trim();\n }\n\n if (content == null) {\n return \"\";\n }\n\n try {\n return JSON.stringify(content).trim();\n } catch {\n return \"\";\n }\n}\n\nfunction normalizeGeneratedTitle(rawTitle: string): string | null {\n let candidate = rawTitle.trim();\n if (!candidate) {\n return null;\n }\n\n candidate = candidate\n .replace(/^```(?:json)?\\s*/i, \"\")\n .replace(/\\s*```$/, \"\")\n .trim();\n\n try {\n const parsed = JSON.parse(candidate) as { title?: unknown };\n if (typeof parsed.title === \"string\") {\n candidate = parsed.title;\n }\n } catch {\n // Fall back to using the raw text.\n }\n\n candidate = candidate\n .replace(/^[\"'`]+|[\"'`]+$/g, \"\")\n .replace(/[*_#[\\]()!~>|]+/g, \"\")\n .replace(/[.!?,;:]+$/g, \"\")\n .replace(/\\s+/g, \" \")\n .trim();\n\n if (!candidate) {\n return null;\n }\n\n if (candidate.length > MAX_TITLE_LENGTH) {\n candidate = candidate.slice(0, MAX_TITLE_LENGTH).trim();\n }\n\n if (candidate.split(/\\s+/).length > MAX_TITLE_WORDS) {\n return null;\n }\n\n return candidate;\n}\n\nfunction hasThreadName(name: string | null | undefined): boolean {\n return typeof name === \"string\" && name.trim().length > 0;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,0BAA0B;AAChC,MAAM,gCAAgC;AACtC,MAAM,wBAAwB;AAW9B,eAAsB,+BAA+B,EACnD,SACA,SACA,SACA,aACA,QACA,UAC0C;AAC1C,KAAI,CAAC,QAAQ,uBAAuB,cAAc,OAAO,KAAK,CAC5D;CAGF,MAAM,SAAS,uBAAuB,YAAY,SAAS;AAC3D,KAAI,CAAC,OACH;CAGF,IAAI,iBAAgC;AAEpC,MAAK,IAAI,UAAU,GAAG,WAAW,+BAA+B,UAC9D,KAAI;AACF,mB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AU,wBAAwB,QAAQ,QAAQ;AACxD,MAAI,CAAC,QACH,QAAO;AAGT,SAAO,GAAG,QAAQ,KAAK,IAAI;GAC3B,CACD,QAAQ,YAA+B,CAAC,CAAC,QAAQ,CACjD,MAAM,CAAC,wBAAwB;AAElC,KAAI,WAAW,WAAW,EACxB,QAAO;AAGT,QAAO;EACL;EACA;EACA,WAAW,KAAK,KAAK;EACtB,CAAC,KAAK,OAAO;;AAGhB,SAAS,wBAAwB,SAAqC;AACpE,KAAI,OAAO,YAAY,SACrB,QAAO,QAAQ,MAAM;AAGvB,KAAI,WAAW,KACb,QAAO;AAGT,KAAI;AACF,SAAO,KAAK,UAAU,QAAQ,CAAC,MAAM;SAC/B;AACN,SAAO;;;AAIX,SAAS,wBAAwB,UAAiC;CAChE,IAAI,YAAY,SAAS,MAAM;AAC/B,KAAI,CAAC,UACH,QAAO;AAGT,aAAY,UACT,QAAQ,qBAAqB,GAAG,CAChC,QAAQ,WAAW,GAAG,CACtB,MAAM;AAET,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,UAAU;AACpC,MAAI,OAAO,OAAO,UAAU,SAC1B,aAAY,OAAO;SAEf;AAIR,aAAY,UACT,QAAQ,oBAAoB,GAAG,CAC/B,QAAQ,oBAAoB,GAAG,CAC/B,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,MAAM;AAET,KAAI,CAAC,UACH,QAAO;AAGT,KAAI,UAAU,SAAS,iBACrB,aAAY,UAAU,MAAM,GAAG,iBAAiB,CAAC,MAAM;AAGzD,KAAI,UAAU,MAAM,MAAM,CAAC,SAAS,gBAClC,QAAO;AAGT,QAAO;;AAGT,SAAS,cAAc,MAA0C;AAC/D,QAAO,OAAO,SAAS,YAAY,KAAK,MAAM,CAAC,SAAS"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cloneAgentForRequest, configureAgentForRequest } from "../shared/agent-utils.mjs";
|
|
2
|
+
import { isHandlerResponse } from "../shared/json-response.mjs";
|
|
2
3
|
import { logger } from "@copilotkitnext/shared";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
|
|
@@ -58,7 +59,7 @@ async function generateThreadNameForNewThread({ runtime, request, agentId, sourc
|
|
|
58
59
|
async function runTitleGenerationAttempt(params) {
|
|
59
60
|
const { runtime, request, agentId, threadId, prompt } = params;
|
|
60
61
|
const agent = await cloneAgentForRequest(runtime, agentId);
|
|
61
|
-
if (agent
|
|
62
|
+
if (isHandlerResponse(agent)) {
|
|
62
63
|
logger.warn({
|
|
63
64
|
agentId,
|
|
64
65
|
threadId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-names.mjs","names":[],"sources":["../../../src/handlers/intelligence/thread-names.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { randomUUID } from \"node:crypto\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n} from \"../shared/agent-utils\";\nimport { ThreadSummary } from \"../../intelligence-platform\";\n\nconst THREAD_NAME_SYSTEM_PROMPT = [\n \"You generate short, specific conversation titles.\",\n 'Return JSON only in this exact shape: {\"title\":\"...\"}',\n \"The title must be 2 to 5 words.\",\n \"Use sentence case.\",\n \"No quotes.\",\n \"No emoji.\",\n \"No markdown characters or formatting.\",\n \"Do not use *, _, #, `, [, ], (, ), !, ~, >, or |.\",\n \"No trailing punctuation.\",\n \"No explanations.\",\n \"Do not call tools.\",\n].join(\"\\n\");\n\nconst MAX_TITLE_LENGTH = 80;\nconst MAX_TITLE_WORDS = 8;\nconst MAX_TRANSCRIPT_MESSAGES = 8;\nconst MAX_TITLE_GENERATION_ATTEMPTS = 3;\nconst FALLBACK_THREAD_TITLE = \"Untitled\";\n\ninterface GenerateThreadNameParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n sourceInput: RunAgentInput;\n thread: ThreadSummary;\n userId: string;\n}\n\nexport async function generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput,\n thread,\n userId,\n}: GenerateThreadNameParams): Promise<void> {\n if (!runtime.generateThreadNames || hasThreadName(thread.name)) {\n return;\n }\n\n const prompt = buildThreadTitlePrompt(sourceInput.messages);\n if (!prompt) {\n return;\n }\n\n let generatedTitle: string | null = null;\n\n for (let attempt = 1; attempt <= MAX_TITLE_GENERATION_ATTEMPTS; attempt++) {\n try {\n generatedTitle = await runTitleGenerationAttempt({\n runtime,\n request,\n agentId,\n threadId: thread.id,\n prompt,\n });\n\n if (generatedTitle) {\n break;\n }\n\n logger.warn(\n { agentId, attempt, threadId: thread.id },\n \"Thread name generation returned an empty or invalid title\",\n );\n } catch (error) {\n logger.warn(\n { err: error, agentId, attempt, threadId: thread.id },\n \"Thread name generation attempt failed\",\n );\n }\n }\n\n await runtime.intelligence.updateThread({\n threadId: thread.id,\n userId,\n agentId,\n updates: { name: generatedTitle ?? FALLBACK_THREAD_TITLE },\n });\n}\n\nasync function runTitleGenerationAttempt(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n prompt: string;\n}): Promise<string | null> {\n const { runtime, request, agentId, threadId, prompt } = params;\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (agent
|
|
1
|
+
{"version":3,"file":"thread-names.mjs","names":[],"sources":["../../../src/handlers/intelligence/thread-names.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { randomUUID } from \"node:crypto\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../runtime\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n} from \"../shared/agent-utils\";\nimport { ThreadSummary } from \"../../intelligence-platform\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\nconst THREAD_NAME_SYSTEM_PROMPT = [\n \"You generate short, specific conversation titles.\",\n 'Return JSON only in this exact shape: {\"title\":\"...\"}',\n \"The title must be 2 to 5 words.\",\n \"Use sentence case.\",\n \"No quotes.\",\n \"No emoji.\",\n \"No markdown characters or formatting.\",\n \"Do not use *, _, #, `, [, ], (, ), !, ~, >, or |.\",\n \"No trailing punctuation.\",\n \"No explanations.\",\n \"Do not call tools.\",\n].join(\"\\n\");\n\nconst MAX_TITLE_LENGTH = 80;\nconst MAX_TITLE_WORDS = 8;\nconst MAX_TRANSCRIPT_MESSAGES = 8;\nconst MAX_TITLE_GENERATION_ATTEMPTS = 3;\nconst FALLBACK_THREAD_TITLE = \"Untitled\";\n\ninterface GenerateThreadNameParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n sourceInput: RunAgentInput;\n thread: ThreadSummary;\n userId: string;\n}\n\nexport async function generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput,\n thread,\n userId,\n}: GenerateThreadNameParams): Promise<void> {\n if (!runtime.generateThreadNames || hasThreadName(thread.name)) {\n return;\n }\n\n const prompt = buildThreadTitlePrompt(sourceInput.messages);\n if (!prompt) {\n return;\n }\n\n let generatedTitle: string | null = null;\n\n for (let attempt = 1; attempt <= MAX_TITLE_GENERATION_ATTEMPTS; attempt++) {\n try {\n generatedTitle = await runTitleGenerationAttempt({\n runtime,\n request,\n agentId,\n threadId: thread.id,\n prompt,\n });\n\n if (generatedTitle) {\n break;\n }\n\n logger.warn(\n { agentId, attempt, threadId: thread.id },\n \"Thread name generation returned an empty or invalid title\",\n );\n } catch (error) {\n logger.warn(\n { err: error, agentId, attempt, threadId: thread.id },\n \"Thread name generation attempt failed\",\n );\n }\n }\n\n await runtime.intelligence.updateThread({\n threadId: thread.id,\n userId,\n agentId,\n updates: { name: generatedTitle ?? FALLBACK_THREAD_TITLE },\n });\n}\n\nasync function runTitleGenerationAttempt(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n prompt: string;\n}): Promise<string | null> {\n const { runtime, request, agentId, threadId, prompt } = params;\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (isHandlerResponse(agent)) {\n logger.warn(\n { agentId, threadId },\n \"Skipping thread naming because the agent could not be cloned\",\n );\n return null;\n }\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n });\n\n const messages: Message[] = [\n {\n id: randomUUID(),\n role: \"system\",\n content: THREAD_NAME_SYSTEM_PROMPT,\n },\n {\n id: randomUUID(),\n role: \"user\",\n content: prompt,\n },\n ];\n\n agent.setMessages(messages);\n agent.setState({});\n agent.threadId = `thread-name:${threadId}:${randomUUID()}`;\n const { newMessages } = await agent.runAgent({\n messages,\n state: {},\n tools: [],\n context: [],\n forwardedProps: {},\n });\n\n const lastMessage = newMessages.at(-1);\n const titleContent = lastMessage\n ? stringifyMessageContent(lastMessage.content)\n : \"\";\n\n return normalizeGeneratedTitle(titleContent);\n}\n\nfunction buildThreadTitlePrompt(\n messages: Message[] | undefined,\n): string | null {\n const transcript = (messages ?? [])\n .filter((message) =>\n [\"user\", \"assistant\", \"system\", \"developer\"].includes(message.role),\n )\n .map((message) => {\n const content = stringifyMessageContent(message.content);\n if (!content) {\n return null;\n }\n\n return `${message.role}: ${content}`;\n })\n .filter((message): message is string => !!message)\n .slice(-MAX_TRANSCRIPT_MESSAGES);\n\n if (transcript.length === 0) {\n return null;\n }\n\n return [\n \"Generate a short title for this conversation.\",\n \"Conversation:\",\n transcript.join(\"\\n\"),\n ].join(\"\\n\\n\");\n}\n\nfunction stringifyMessageContent(content: Message[\"content\"]): string {\n if (typeof content === \"string\") {\n return content.trim();\n }\n\n if (content == null) {\n return \"\";\n }\n\n try {\n return JSON.stringify(content).trim();\n } catch {\n return \"\";\n }\n}\n\nfunction normalizeGeneratedTitle(rawTitle: string): string | null {\n let candidate = rawTitle.trim();\n if (!candidate) {\n return null;\n }\n\n candidate = candidate\n .replace(/^```(?:json)?\\s*/i, \"\")\n .replace(/\\s*```$/, \"\")\n .trim();\n\n try {\n const parsed = JSON.parse(candidate) as { title?: unknown };\n if (typeof parsed.title === \"string\") {\n candidate = parsed.title;\n }\n } catch {\n // Fall back to using the raw text.\n }\n\n candidate = candidate\n .replace(/^[\"'`]+|[\"'`]+$/g, \"\")\n .replace(/[*_#[\\]()!~>|]+/g, \"\")\n .replace(/[.!?,;:]+$/g, \"\")\n .replace(/\\s+/g, \" \")\n .trim();\n\n if (!candidate) {\n return null;\n }\n\n if (candidate.length > MAX_TITLE_LENGTH) {\n candidate = candidate.slice(0, MAX_TITLE_LENGTH).trim();\n }\n\n if (candidate.split(/\\s+/).length > MAX_TITLE_WORDS) {\n return null;\n }\n\n return candidate;\n}\n\nfunction hasThreadName(name: string | null | undefined): boolean {\n return typeof name === \"string\" && name.trim().length > 0;\n}\n"],"mappings":";;;;;;AAWA,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,0BAA0B;AAChC,MAAM,gCAAgC;AACtC,MAAM,wBAAwB;AAW9B,eAAsB,+BAA+B,EACnD,SACA,SACA,SACA,aACA,QACA,UAC0C;AAC1C,KAAI,CAAC,QAAQ,uBAAuB,cAAc,OAAO,KAAK,CAC5D;CAGF,MAAM,SAAS,uBAAuB,YAAY,SAAS;AAC3D,KAAI,CAAC,OACH;CAGF,IAAI,iBAAgC;AAEpC,MAAK,IAAI,UAAU,GAAG,WAAW,+BAA+B,UAC9D,KAAI;AACF,mBAAiB,MAAM,0BAA0B;GAC/C;GACA;GACA;GACA,UAAU,OAAO;GACjB;GACD,CAAC;AAEF,MAAI,eACF;AAGF,SAAO,KACL;GAAE;GAAS;GAAS,UAAU,OAAO;GAAI,EACzC,4DACD;UACM,OAAO;AACd,SAAO,KACL;GAAE,KAAK;GAAO;GAAS;GAAS,UAAU,OAAO;GAAI,EACrD,wCACD;;AAIL,OAAM,QAAQ,a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C,KAAK,OAAO;;AAGhB,SAAS,wBAAwB,SAAqC;AACpE,KAAI,OAAO,YAAY,SACrB,QAAO,QAAQ,MAAM;AAGvB,KAAI,WAAW,KACb,QAAO;AAGT,KAAI;AACF,SAAO,KAAK,UAAU,QAAQ,CAAC,MAAM;SAC/B;AACN,SAAO;;;AAIX,SAAS,wBAAwB,UAAiC;CAChE,IAAI,YAAY,SAAS,MAAM;AAC/B,KAAI,CAAC,UACH,QAAO;AAGT,aAAY,UACT,QAAQ,qBAAqB,GAAG,CAChC,QAAQ,WAAW,GAAG,CACtB,MAAM;AAET,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,UAAU;AACpC,MAAI,OAAO,OAAO,UAAU,SAC1B,aAAY,OAAO;SAEf;AAIR,aAAY,UACT,QAAQ,oBAAoB,GAAG,CAC/B,QAAQ,oBAAoB,GAAG,CAC/B,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,MAAM;AAET,KAAI,CAAC,UACH,QAAO;AAGT,KAAI,UAAU,SAAS,iBACrB,aAAY,UAAU,MAAM,GAAG,iBAAiB,CAAC,MAAM;AAGzD,KAAI,UAAU,MAAM,MAAM,CAAC,SAAS,gBAClC,QAAO;AAGT,QAAO;;AAGT,SAAS,cAAc,MAA0C;AAC/D,QAAO,OAAO,SAAS,YAAY,KAAK,MAAM,CAAC,SAAS"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_runtime$1 = require('../../runtime.cjs');
|
|
3
|
-
const require_intelligence_utils = require('../shared/intelligence-utils.cjs');
|
|
4
3
|
const require_json_response = require('../shared/json-response.cjs');
|
|
4
|
+
const require_intelligence_utils = require('../shared/intelligence-utils.cjs');
|
|
5
|
+
const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
|
|
5
6
|
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
6
7
|
|
|
7
8
|
//#region src/handlers/intelligence/threads.ts
|
|
@@ -17,16 +18,35 @@ function requireIntelligenceRuntime(runtime) {
|
|
|
17
18
|
if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse("Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
|
|
18
19
|
return runtime;
|
|
19
20
|
}
|
|
21
|
+
async function resolveThreadMutationContext(runtime, request) {
|
|
22
|
+
const body = await parseJsonBody(request);
|
|
23
|
+
if (require_json_response.isHandlerResponse(body)) return body;
|
|
24
|
+
const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
|
|
25
|
+
runtime,
|
|
26
|
+
request
|
|
27
|
+
});
|
|
28
|
+
if (require_json_response.isHandlerResponse(user)) return user;
|
|
29
|
+
const agentId = body.agentId;
|
|
30
|
+
if (!require_intelligence_utils.isValidIdentifier(agentId)) return require_json_response.errorResponse("Valid agentId is required", 400);
|
|
31
|
+
return {
|
|
32
|
+
body,
|
|
33
|
+
userId: user.id,
|
|
34
|
+
agentId
|
|
35
|
+
};
|
|
36
|
+
}
|
|
20
37
|
async function handleListThreads({ runtime, request }) {
|
|
21
38
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
22
|
-
if (intelligenceRuntime
|
|
39
|
+
if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
23
40
|
try {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
const agentId = new URL(request.url).searchParams.get("agentId");
|
|
42
|
+
const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
|
|
43
|
+
runtime: intelligenceRuntime,
|
|
44
|
+
request
|
|
45
|
+
});
|
|
46
|
+
if (require_json_response.isHandlerResponse(user)) return user;
|
|
47
|
+
if (!require_intelligence_utils.isValidIdentifier(agentId)) return require_json_response.errorResponse("Valid agentId query param is required", 400);
|
|
28
48
|
const data = await intelligenceRuntime.intelligence.listThreads({
|
|
29
|
-
userId,
|
|
49
|
+
userId: user.id,
|
|
30
50
|
agentId
|
|
31
51
|
});
|
|
32
52
|
return Response.json(data);
|
|
@@ -37,16 +57,17 @@ async function handleListThreads({ runtime, request }) {
|
|
|
37
57
|
}
|
|
38
58
|
async function handleUpdateThread({ runtime, request, threadId }) {
|
|
39
59
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
40
|
-
if (intelligenceRuntime
|
|
60
|
+
if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
41
61
|
try {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
|
|
62
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
63
|
+
if (require_json_response.isHandlerResponse(mutation)) return mutation;
|
|
64
|
+
const updates = { ...mutation.body };
|
|
65
|
+
delete updates.agentId;
|
|
66
|
+
delete updates.userId;
|
|
46
67
|
const thread = await intelligenceRuntime.intelligence.updateThread({
|
|
47
68
|
threadId,
|
|
48
|
-
userId,
|
|
49
|
-
agentId,
|
|
69
|
+
userId: mutation.userId,
|
|
70
|
+
agentId: mutation.agentId,
|
|
50
71
|
updates
|
|
51
72
|
});
|
|
52
73
|
return Response.json(thread);
|
|
@@ -60,13 +81,14 @@ async function handleUpdateThread({ runtime, request, threadId }) {
|
|
|
60
81
|
}
|
|
61
82
|
async function handleSubscribeToThreads({ runtime, request }) {
|
|
62
83
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
63
|
-
if (intelligenceRuntime
|
|
84
|
+
if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
64
85
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
|
|
87
|
+
runtime: intelligenceRuntime,
|
|
88
|
+
request
|
|
89
|
+
});
|
|
90
|
+
if (require_json_response.isHandlerResponse(user)) return user;
|
|
91
|
+
const credentials = await intelligenceRuntime.intelligence.ɵsubscribeToThreads({ userId: user.id });
|
|
70
92
|
return Response.json({ joinToken: credentials.joinToken });
|
|
71
93
|
} catch (error) {
|
|
72
94
|
_copilotkitnext_shared.logger.error({ err: error }, "Error subscribing to threads");
|
|
@@ -75,16 +97,14 @@ async function handleSubscribeToThreads({ runtime, request }) {
|
|
|
75
97
|
}
|
|
76
98
|
async function handleArchiveThread({ runtime, request, threadId }) {
|
|
77
99
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
78
|
-
if (intelligenceRuntime
|
|
100
|
+
if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
79
101
|
try {
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
const { userId, agentId } = body;
|
|
83
|
-
if (!require_intelligence_utils.isValidIdentifier(userId) || !require_intelligence_utils.isValidIdentifier(agentId)) return require_json_response.errorResponse("Valid userId and agentId are required", 400);
|
|
102
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
103
|
+
if (require_json_response.isHandlerResponse(mutation)) return mutation;
|
|
84
104
|
await intelligenceRuntime.intelligence.archiveThread({
|
|
85
105
|
threadId,
|
|
86
|
-
userId,
|
|
87
|
-
agentId
|
|
106
|
+
userId: mutation.userId,
|
|
107
|
+
agentId: mutation.agentId
|
|
88
108
|
});
|
|
89
109
|
return Response.json({
|
|
90
110
|
threadId,
|
|
@@ -100,16 +120,14 @@ async function handleArchiveThread({ runtime, request, threadId }) {
|
|
|
100
120
|
}
|
|
101
121
|
async function handleDeleteThread({ runtime, request, threadId }) {
|
|
102
122
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
103
|
-
if (intelligenceRuntime
|
|
123
|
+
if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
104
124
|
try {
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
const { userId, agentId } = body;
|
|
108
|
-
if (!require_intelligence_utils.isValidIdentifier(userId) || !require_intelligence_utils.isValidIdentifier(agentId)) return require_json_response.errorResponse("Valid userId and agentId are required", 400);
|
|
125
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
126
|
+
if (require_json_response.isHandlerResponse(mutation)) return mutation;
|
|
109
127
|
await intelligenceRuntime.intelligence.deleteThread({
|
|
110
128
|
threadId,
|
|
111
|
-
userId,
|
|
112
|
-
agentId
|
|
129
|
+
userId: mutation.userId,
|
|
130
|
+
agentId: mutation.agentId
|
|
113
131
|
});
|
|
114
132
|
return Response.json({
|
|
115
133
|
threadId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.cjs","names":["errorResponse","isIntelligenceRuntime","isValidIdentifier"],"sources":["../../../src/handlers/intelligence/threads.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n} from \"../../runtime\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { errorResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (intelligenceRuntime
|
|
1
|
+
{"version":3,"file":"threads.cjs","names":["errorResponse","isIntelligenceRuntime","isHandlerResponse","resolveIntelligenceUser","isValidIdentifier"],"sources":["../../../src/handlers/intelligence/threads.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n} from \"../../runtime\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\ninterface ThreadMutationContext {\n userId: string;\n agentId: string;\n body: Record<string, unknown>;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nasync function resolveThreadMutationContext(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<ThreadMutationContext | Response> {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const agentId = body.agentId;\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId is required\", 400);\n }\n\n return {\n body,\n userId: user.id,\n agentId,\n };\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId query param is required\", 400);\n }\n\n const data = await intelligenceRuntime.intelligence.listThreads({\n userId: user.id,\n agentId,\n });\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing threads\");\n return errorResponse(\"Failed to list threads\", 500);\n }\n}\n\nexport async function handleUpdateThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n const updates = { ...mutation.body };\n delete updates.agentId;\n delete updates.userId;\n\n const thread = await intelligenceRuntime.intelligence.updateThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n updates,\n });\n\n return Response.json(thread);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error updating thread\");\n return errorResponse(\"Failed to update thread\", 500);\n }\n}\n\nexport async function handleSubscribeToThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const credentials =\n await intelligenceRuntime.intelligence.ɵsubscribeToThreads({\n userId: user.id,\n });\n\n return Response.json({ joinToken: credentials.joinToken });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to threads\");\n return errorResponse(\"Failed to subscribe to threads\", 500);\n }\n}\n\nexport async function handleArchiveThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.archiveThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, archived: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error archiving thread\");\n return errorResponse(\"Failed to archive thread\", 500);\n }\n}\n\nexport async function handleDeleteThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.deleteThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, deleted: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error deleting thread\");\n return errorResponse(\"Failed to delete thread\", 500);\n }\n}\n"],"mappings":";;;;;;;;AAyBA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,gCAAO,MAAM,EAAE,KAAK,OAAO,EAAE,iCAAiC;AAC9D,SAAOA,oCAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAACC,wCAAsB,QAAQ,CACjC,QAAOD,oCACL,uJACA,IACD;AAGH,QAA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sBAAsB,2BAA2B,QAAQ;AAC/D,KAAIE,wCAAkB,oBAAoB,CACxC,QAAO;AAGT,KAAI;EACF,MAAM,WAAW,MAAM,6BACrB,qBACA,QACD;AACD,MAAIA,wCAAkB,SAAS,CAAE,QAAO;AAExC,QAAM,oBAAoB,aAAa,aAAa;GAClD;GACA,QAAQ,SAAS;GACjB,SAAS,SAAS;GACnB,CAAC;AAEF,SAAO,SAAS,KAAK;GAAE;GAAU,SAAS;GAAM,CAAC;UAC1C,OAAO;AACd,gCAAO,MAAM;GAAE,KAAK;GAAO;GAAU,EAAE,wBAAwB;AAC/D,SAAOF,oCAAc,2BAA2B,IAAI"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isIntelligenceRuntime } from "../../runtime.mjs";
|
|
2
|
+
import { errorResponse, isHandlerResponse } from "../shared/json-response.mjs";
|
|
2
3
|
import { isValidIdentifier } from "../shared/intelligence-utils.mjs";
|
|
3
|
-
import {
|
|
4
|
+
import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
|
|
4
5
|
import { logger } from "@copilotkitnext/shared";
|
|
5
6
|
|
|
6
7
|
//#region src/handlers/intelligence/threads.ts
|
|
@@ -16,16 +17,35 @@ function requireIntelligenceRuntime(runtime) {
|
|
|
16
17
|
if (!isIntelligenceRuntime(runtime)) return errorResponse("Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
|
|
17
18
|
return runtime;
|
|
18
19
|
}
|
|
20
|
+
async function resolveThreadMutationContext(runtime, request) {
|
|
21
|
+
const body = await parseJsonBody(request);
|
|
22
|
+
if (isHandlerResponse(body)) return body;
|
|
23
|
+
const user = await resolveIntelligenceUser({
|
|
24
|
+
runtime,
|
|
25
|
+
request
|
|
26
|
+
});
|
|
27
|
+
if (isHandlerResponse(user)) return user;
|
|
28
|
+
const agentId = body.agentId;
|
|
29
|
+
if (!isValidIdentifier(agentId)) return errorResponse("Valid agentId is required", 400);
|
|
30
|
+
return {
|
|
31
|
+
body,
|
|
32
|
+
userId: user.id,
|
|
33
|
+
agentId
|
|
34
|
+
};
|
|
35
|
+
}
|
|
19
36
|
async function handleListThreads({ runtime, request }) {
|
|
20
37
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
21
|
-
if (intelligenceRuntime
|
|
38
|
+
if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
22
39
|
try {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
const agentId = new URL(request.url).searchParams.get("agentId");
|
|
41
|
+
const user = await resolveIntelligenceUser({
|
|
42
|
+
runtime: intelligenceRuntime,
|
|
43
|
+
request
|
|
44
|
+
});
|
|
45
|
+
if (isHandlerResponse(user)) return user;
|
|
46
|
+
if (!isValidIdentifier(agentId)) return errorResponse("Valid agentId query param is required", 400);
|
|
27
47
|
const data = await intelligenceRuntime.intelligence.listThreads({
|
|
28
|
-
userId,
|
|
48
|
+
userId: user.id,
|
|
29
49
|
agentId
|
|
30
50
|
});
|
|
31
51
|
return Response.json(data);
|
|
@@ -36,16 +56,17 @@ async function handleListThreads({ runtime, request }) {
|
|
|
36
56
|
}
|
|
37
57
|
async function handleUpdateThread({ runtime, request, threadId }) {
|
|
38
58
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
39
|
-
if (intelligenceRuntime
|
|
59
|
+
if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
40
60
|
try {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
|
|
61
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
62
|
+
if (isHandlerResponse(mutation)) return mutation;
|
|
63
|
+
const updates = { ...mutation.body };
|
|
64
|
+
delete updates.agentId;
|
|
65
|
+
delete updates.userId;
|
|
45
66
|
const thread = await intelligenceRuntime.intelligence.updateThread({
|
|
46
67
|
threadId,
|
|
47
|
-
userId,
|
|
48
|
-
agentId,
|
|
68
|
+
userId: mutation.userId,
|
|
69
|
+
agentId: mutation.agentId,
|
|
49
70
|
updates
|
|
50
71
|
});
|
|
51
72
|
return Response.json(thread);
|
|
@@ -59,13 +80,14 @@ async function handleUpdateThread({ runtime, request, threadId }) {
|
|
|
59
80
|
}
|
|
60
81
|
async function handleSubscribeToThreads({ runtime, request }) {
|
|
61
82
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
62
|
-
if (intelligenceRuntime
|
|
83
|
+
if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
63
84
|
try {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
85
|
+
const user = await resolveIntelligenceUser({
|
|
86
|
+
runtime: intelligenceRuntime,
|
|
87
|
+
request
|
|
88
|
+
});
|
|
89
|
+
if (isHandlerResponse(user)) return user;
|
|
90
|
+
const credentials = await intelligenceRuntime.intelligence.ɵsubscribeToThreads({ userId: user.id });
|
|
69
91
|
return Response.json({ joinToken: credentials.joinToken });
|
|
70
92
|
} catch (error) {
|
|
71
93
|
logger.error({ err: error }, "Error subscribing to threads");
|
|
@@ -74,16 +96,14 @@ async function handleSubscribeToThreads({ runtime, request }) {
|
|
|
74
96
|
}
|
|
75
97
|
async function handleArchiveThread({ runtime, request, threadId }) {
|
|
76
98
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
77
|
-
if (intelligenceRuntime
|
|
99
|
+
if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
78
100
|
try {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
const { userId, agentId } = body;
|
|
82
|
-
if (!isValidIdentifier(userId) || !isValidIdentifier(agentId)) return errorResponse("Valid userId and agentId are required", 400);
|
|
101
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
102
|
+
if (isHandlerResponse(mutation)) return mutation;
|
|
83
103
|
await intelligenceRuntime.intelligence.archiveThread({
|
|
84
104
|
threadId,
|
|
85
|
-
userId,
|
|
86
|
-
agentId
|
|
105
|
+
userId: mutation.userId,
|
|
106
|
+
agentId: mutation.agentId
|
|
87
107
|
});
|
|
88
108
|
return Response.json({
|
|
89
109
|
threadId,
|
|
@@ -99,16 +119,14 @@ async function handleArchiveThread({ runtime, request, threadId }) {
|
|
|
99
119
|
}
|
|
100
120
|
async function handleDeleteThread({ runtime, request, threadId }) {
|
|
101
121
|
const intelligenceRuntime = requireIntelligenceRuntime(runtime);
|
|
102
|
-
if (intelligenceRuntime
|
|
122
|
+
if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
|
|
103
123
|
try {
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
const { userId, agentId } = body;
|
|
107
|
-
if (!isValidIdentifier(userId) || !isValidIdentifier(agentId)) return errorResponse("Valid userId and agentId are required", 400);
|
|
124
|
+
const mutation = await resolveThreadMutationContext(intelligenceRuntime, request);
|
|
125
|
+
if (isHandlerResponse(mutation)) return mutation;
|
|
108
126
|
await intelligenceRuntime.intelligence.deleteThread({
|
|
109
127
|
threadId,
|
|
110
|
-
userId,
|
|
111
|
-
agentId
|
|
128
|
+
userId: mutation.userId,
|
|
129
|
+
agentId: mutation.agentId
|
|
112
130
|
});
|
|
113
131
|
return Response.json({
|
|
114
132
|
threadId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.mjs","names":[],"sources":["../../../src/handlers/intelligence/threads.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n} from \"../../runtime\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { errorResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (intelligenceRuntime
|
|
1
|
+
{"version":3,"file":"threads.mjs","names":[],"sources":["../../../src/handlers/intelligence/threads.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n} from \"../../runtime\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\ninterface ThreadMutationContext {\n userId: string;\n agentId: string;\n body: Record<string, unknown>;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nasync function resolveThreadMutationContext(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<ThreadMutationContext | Response> {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const agentId = body.agentId;\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId is required\", 400);\n }\n\n return {\n body,\n userId: user.id,\n agentId,\n };\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId query param is required\", 400);\n }\n\n const data = await intelligenceRuntime.intelligence.listThreads({\n userId: user.id,\n agentId,\n });\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing threads\");\n return errorResponse(\"Failed to list threads\", 500);\n }\n}\n\nexport async function handleUpdateThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n const updates = { ...mutation.body };\n delete updates.agentId;\n delete updates.userId;\n\n const thread = await intelligenceRuntime.intelligence.updateThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n updates,\n });\n\n return Response.json(thread);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error updating thread\");\n return errorResponse(\"Failed to update thread\", 500);\n }\n}\n\nexport async function handleSubscribeToThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const credentials =\n await intelligenceRuntime.intelligence.ɵsubscribeToThreads({\n userId: user.id,\n });\n\n return Response.json({ joinToken: credentials.joinToken });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to threads\");\n return errorResponse(\"Failed to subscribe to threads\", 500);\n }\n}\n\nexport async function handleArchiveThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.archiveThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, archived: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error archiving thread\");\n return errorResponse(\"Failed to archive thread\", 500);\n }\n}\n\nexport async function handleDeleteThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.deleteThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, deleted: true });\n } catch (error) {\n logger.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CAAE,QAAO;AAExC,QAAM,oBAAoB,aAAa,cAAc;GACnD;GACA,QAAQ,SAAS;GACjB,SAAS,SAAS;GACnB,CAAC;AAEF,SAAO,SAAS,KAAK;GAAE;GAAU,UAAU;GAAM,CAAC;UAC3C,OAAO;AACd,SAAO,MAAM;GAAE,KAAK;GAAO;GAAU,EAAE,yBAAyB;AAChE,SAAO,cAAc,4BAA4B,IAAI;;;AAIzD,eAAsB,mBAAmB,EACvC,SACA,SACA,YAC0C;CAC1C,MAAM,sBAAsB,2BAA2B,QAAQ;AAC/D,KAAI,kBAAkB,oBAAoB,CACxC,QAAO;AAGT,KAAI;EACF,MAAM,WAAW,MAAM,6BACrB,qBACA,QACD;AACD,MAAI,kBAAkB,SAAS,CAAE,QAAO;AAExC,QAAM,oBAAoB,aAAa,aAAa;GAClD;GACA,QAAQ,SAAS;GACjB,SAAS,SAAS;GACnB,CAAC;AAEF,SAAO,SAAS,KAAK;GAAE;GAAU,SAAS;GAAM,CAAC;UAC1C,OAAO;AACd,SAAO,MAAM;GAAE,KAAK;GAAO;GAAU,EAAE,wBAAwB;AAC/D,SAAO,cAAc,2BAA2B,IAAI"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/handlers/shared/json-response.ts
|
|
3
3
|
const errorResponse = (message, status) => Response.json({ error: message }, { status });
|
|
4
|
+
function isHandlerResponse(value) {
|
|
5
|
+
return value instanceof Response;
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
//#endregion
|
|
6
9
|
exports.errorResponse = errorResponse;
|
|
10
|
+
exports.isHandlerResponse = isHandlerResponse;
|
|
7
11
|
//# sourceMappingURL=json-response.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-response.cjs","names":[],"sources":["../../../src/handlers/shared/json-response.ts"],"sourcesContent":["export const errorResponse = (message: string, status: number) =>\n Response.json({ error: message }, { status });\n"],"mappings":";;AAAA,MAAa,iBAAiB,SAAiB,WAC7C,SAAS,KAAK,EAAE,OAAO,SAAS,EAAE,EAAE,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"json-response.cjs","names":[],"sources":["../../../src/handlers/shared/json-response.ts"],"sourcesContent":["export const errorResponse = (message: string, status: number) =>\n Response.json({ error: message }, { status });\n\nexport function isHandlerResponse(value: unknown): value is Response {\n return value instanceof Response;\n}\n"],"mappings":";;AAAA,MAAa,iBAAiB,SAAiB,WAC7C,SAAS,KAAK,EAAE,OAAO,SAAS,EAAE,EAAE,QAAQ,CAAC;AAE/C,SAAgB,kBAAkB,OAAmC;AACnE,QAAO,iBAAiB"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/handlers/shared/json-response.ts
|
|
2
2
|
const errorResponse = (message, status) => Response.json({ error: message }, { status });
|
|
3
|
+
function isHandlerResponse(value) {
|
|
4
|
+
return value instanceof Response;
|
|
5
|
+
}
|
|
3
6
|
|
|
4
7
|
//#endregion
|
|
5
|
-
export { errorResponse };
|
|
8
|
+
export { errorResponse, isHandlerResponse };
|
|
6
9
|
//# sourceMappingURL=json-response.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-response.mjs","names":[],"sources":["../../../src/handlers/shared/json-response.ts"],"sourcesContent":["export const errorResponse = (message: string, status: number) =>\n Response.json({ error: message }, { status });\n"],"mappings":";AAAA,MAAa,iBAAiB,SAAiB,WAC7C,SAAS,KAAK,EAAE,OAAO,SAAS,EAAE,EAAE,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"json-response.mjs","names":[],"sources":["../../../src/handlers/shared/json-response.ts"],"sourcesContent":["export const errorResponse = (message: string, status: number) =>\n Response.json({ error: message }, { status });\n\nexport function isHandlerResponse(value: unknown): value is Response {\n return value instanceof Response;\n}\n"],"mappings":";AAAA,MAAa,iBAAiB,SAAiB,WAC7C,SAAS,KAAK,EAAE,OAAO,SAAS,EAAE,EAAE,QAAQ,CAAC;AAE/C,SAAgB,kBAAkB,OAAmC;AACnE,QAAO,iBAAiB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_json_response = require('./json-response.cjs');
|
|
2
|
+
const require_intelligence_utils = require('./intelligence-utils.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/handlers/shared/resolve-intelligence-user.ts
|
|
5
|
+
async function resolveIntelligenceUser(params) {
|
|
6
|
+
const { runtime, request } = params;
|
|
7
|
+
try {
|
|
8
|
+
const user = await runtime.identifyUser(request);
|
|
9
|
+
if (!require_intelligence_utils.isValidIdentifier(user?.id)) return require_json_response.errorResponse("identifyUser must return a valid user id", 400);
|
|
10
|
+
return { id: user.id };
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error identifying intelligence user:", error);
|
|
13
|
+
return require_json_response.errorResponse("Failed to identify user", 500);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.resolveIntelligenceUser = resolveIntelligenceUser;
|
|
19
|
+
//# sourceMappingURL=resolve-intelligence-user.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-intelligence-user.cjs","names":["isValidIdentifier","errorResponse"],"sources":["../../../src/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n\n return { id: user.id };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;AAOA,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAACA,6CAAkB,MAAM,GAAG,CAC9B,QAAOC,oCAAc,4CAA4C,IAAI;AAGvE,SAAO,EAAE,IAAI,KAAK,IAAI;UACf,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAOA,oCAAc,2BAA2B,IAAI"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { errorResponse } from "./json-response.mjs";
|
|
2
|
+
import { isValidIdentifier } from "./intelligence-utils.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/handlers/shared/resolve-intelligence-user.ts
|
|
5
|
+
async function resolveIntelligenceUser(params) {
|
|
6
|
+
const { runtime, request } = params;
|
|
7
|
+
try {
|
|
8
|
+
const user = await runtime.identifyUser(request);
|
|
9
|
+
if (!isValidIdentifier(user?.id)) return errorResponse("identifyUser must return a valid user id", 400);
|
|
10
|
+
return { id: user.id };
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error identifying intelligence user:", error);
|
|
13
|
+
return errorResponse("Failed to identify user", 500);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveIntelligenceUser };
|
|
19
|
+
//# sourceMappingURL=resolve-intelligence-user.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-intelligence-user.mjs","names":[],"sources":["../../../src/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n\n return { id: user.id };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;AAOA,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAAC,kBAAkB,MAAM,GAAG,CAC9B,QAAO,cAAc,4CAA4C,IAAI;AAGvE,SAAO,EAAE,IAAI,KAAK,IAAI;UACf,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAO,cAAc,2BAA2B,IAAI"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TranscribeFileOptions, TranscriptionService } from "./transcription-service/transcription-service.cjs";
|
|
2
2
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest } from "./runner/agent-runner.cjs";
|
|
3
3
|
import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.cjs";
|
|
4
|
-
import { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime } from "./runtime.cjs";
|
|
4
|
+
import { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime } from "./runtime.cjs";
|
|
5
5
|
import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./endpoints/hono.cjs";
|
|
6
6
|
import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.cjs";
|
|
7
7
|
import { InMemoryAgentRunner } from "./runner/in-memory.cjs";
|
|
8
8
|
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions } from "./runner/intelligence.cjs";
|
|
9
9
|
import { finalizeRunEvents } from "./runner/index.cjs";
|
|
10
|
-
export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotEndpointCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, type CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, type CreateThreadRequest, InMemoryAgentRunner, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, type ListThreadsResponse, McpAppsConfig, McpAppsServerConfig, type SubscribeToThreadsRequest, type SubscribeToThreadsResponse, type ThreadSummary, TranscribeFileOptions, TranscriptionService, type UpdateThreadRequest, VERSION, createCopilotEndpoint, createCopilotEndpointSingleRoute, finalizeRunEvents, isIntelligenceRuntime };
|
|
10
|
+
export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotEndpointCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, type CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, type CreateThreadRequest, IdentifyUserCallback, InMemoryAgentRunner, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, type ListThreadsResponse, McpAppsConfig, McpAppsServerConfig, type SubscribeToThreadsRequest, type SubscribeToThreadsResponse, type ThreadSummary, TranscribeFileOptions, TranscriptionService, type UpdateThreadRequest, VERSION, createCopilotEndpoint, createCopilotEndpointSingleRoute, finalizeRunEvents, isIntelligenceRuntime };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,11 +2,11 @@ import { TranscribeFileOptions, TranscriptionService } from "./transcription-ser
|
|
|
2
2
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest } from "./runner/agent-runner.mjs";
|
|
3
3
|
import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.mjs";
|
|
4
4
|
import "./intelligence-platform/index.mjs";
|
|
5
|
-
import { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime } from "./runtime.mjs";
|
|
5
|
+
import { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime } from "./runtime.mjs";
|
|
6
6
|
import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./endpoints/hono.mjs";
|
|
7
7
|
import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.mjs";
|
|
8
8
|
import "./endpoints/index.mjs";
|
|
9
9
|
import { InMemoryAgentRunner } from "./runner/in-memory.mjs";
|
|
10
10
|
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions } from "./runner/intelligence.mjs";
|
|
11
11
|
import { finalizeRunEvents } from "./runner/index.mjs";
|
|
12
|
-
export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotEndpointCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, type CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, type CreateThreadRequest, InMemoryAgentRunner, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, type ListThreadsResponse, McpAppsConfig, McpAppsServerConfig, type SubscribeToThreadsRequest, type SubscribeToThreadsResponse, type ThreadSummary, TranscribeFileOptions, TranscriptionService, type UpdateThreadRequest, VERSION, createCopilotEndpoint, createCopilotEndpointSingleRoute, finalizeRunEvents, isIntelligenceRuntime };
|
|
12
|
+
export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotEndpointCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, type CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, type CreateThreadRequest, IdentifyUserCallback, InMemoryAgentRunner, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, type ListThreadsResponse, McpAppsConfig, McpAppsServerConfig, type SubscribeToThreadsRequest, type SubscribeToThreadsResponse, type ThreadSummary, TranscribeFileOptions, TranscriptionService, type UpdateThreadRequest, VERSION, createCopilotEndpoint, createCopilotEndpointSingleRoute, finalizeRunEvents, isIntelligenceRuntime };
|
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/dist/runtime.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var CopilotSseRuntime = class extends BaseCopilotRuntime {
|
|
|
34
34
|
};
|
|
35
35
|
var CopilotIntelligenceRuntime = class extends BaseCopilotRuntime {
|
|
36
36
|
intelligence;
|
|
37
|
+
identifyUser;
|
|
37
38
|
generateThreadNames;
|
|
38
39
|
mode = _copilotkitnext_shared.RUNTIME_MODE_INTELLIGENCE;
|
|
39
40
|
constructor(options) {
|
|
@@ -42,6 +43,7 @@ var CopilotIntelligenceRuntime = class extends BaseCopilotRuntime {
|
|
|
42
43
|
authToken: options.intelligence.ɵgetRunnerAuthToken()
|
|
43
44
|
}));
|
|
44
45
|
this.intelligence = options.intelligence;
|
|
46
|
+
this.identifyUser = options.identifyUser;
|
|
45
47
|
this.generateThreadNames = options.generateThreadNames ?? true;
|
|
46
48
|
}
|
|
47
49
|
};
|
|
@@ -87,6 +89,9 @@ var CopilotRuntime = class {
|
|
|
87
89
|
get generateThreadNames() {
|
|
88
90
|
return isIntelligenceRuntime(this.delegate) ? this.delegate.generateThreadNames : void 0;
|
|
89
91
|
}
|
|
92
|
+
get identifyUser() {
|
|
93
|
+
return isIntelligenceRuntime(this.delegate) ? this.delegate.identifyUser : void 0;
|
|
94
|
+
}
|
|
90
95
|
get mode() {
|
|
91
96
|
return this.delegate.mode;
|
|
92
97
|
}
|
package/dist/runtime.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.cjs","names":["RUNTIME_MODE_SSE","InMemoryAgentRunner","RUNTIME_MODE_INTELLIGENCE","IntelligenceAgentRunner"],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkitnext/shared\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { TranscriptionService } from \"./transcription-service/transcription-service\";\nimport { AgentRunner } from \"./runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"./runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"./runner/intelligence\";\nimport { CopilotKitIntelligence } from \"./intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\ninterface CopilotRuntimeMiddlewares {\n /** Auto-apply A2UIMiddleware to agents at run time. */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /** Map of available agents (loaded lazily is fine). */\n agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n}\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n intelligence?: CopilotKitIntelligence;\n mode: RuntimeMode;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n generateThreadNames: boolean;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui;\n this.mcpApps = mcpApps;\n this.runner = runner;\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly generateThreadNames: boolean;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n }),\n );\n this.intelligence = options.intelligence;\n this.generateThreadNames = options.generateThreadNames ?? true;\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n}\n"],"mappings":";;;;;;;AAqBA,MAAa;
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":["RUNTIME_MODE_SSE","InMemoryAgentRunner","RUNTIME_MODE_INTELLIGENCE","IntelligenceAgentRunner"],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkitnext/shared\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { TranscriptionService } from \"./transcription-service/transcription-service\";\nimport { AgentRunner } from \"./runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"./runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"./runner/intelligence\";\nimport { CopilotKitIntelligence } from \"./intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\ninterface CopilotRuntimeMiddlewares {\n /** Auto-apply A2UIMiddleware to agents at run time. */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /** Map of available agents (loaded lazily is fine). */\n agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser: IdentifyUserCallback;\n generateThreadNames: boolean;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui;\n this.mcpApps = mcpApps;\n this.runner = runner;\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n }),\n );\n this.intelligence = options.intelligence;\n this.identifyUser = options.identifyUser;\n this.generateThreadNames = options.generateThreadNames ?? true;\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n}\n"],"mappings":";;;;;;;AAqBA,MAAa;AAwFb,IAAe,qBAAf,MAAgE;CAC9D,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAKP,YAAY,SAAoC,QAAqB;EACnE,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,YACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;AAC5B,OAAK,0BAA0B;AAC/B,OAAK,yBAAyB;AAC9B,OAAK,OAAO;AACZ,OAAK,UAAU;AACf,OAAK,SAAS;;;AAIlB,IAAa,oBAAb,cACU,mBAEV;CACE,AAAS,eAAe;CACxB,AAAS,OAAOA;CAEhB,YAAY,SAAmC;AAC7C,QAAM,SAAS,QAAQ,UAAU,IAAIC,uCAAqB,CAAC;;;AAI/D,IAAa,6BAAb,cACU,mBAEV;CACE,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS,OAAOC;CAEhB,YAAY,SAA4C;AACtD,QACE,SACA,IAAIC,6CAAwB;GAC1B,KAAK,QAAQ,aAAa,iBAAiB;GAC3C,WAAW,QAAQ,aAAa,qBAAqB;GACtD,CAAC,CACH;AACD,OAAK,eAAe,QAAQ;AAC5B,OAAK,eAAe,QAAQ;AAC5B,OAAK,sBAAsB,QAAQ,uBAAuB;;;AAI9D,SAAS,uBACP,SAC8C;AAC9C,QAAO,kBAAkB,WAAW,CAAC,CAAC,QAAQ;;AAGhD,SAAgB,sBACd,SAC2C;AAC3C,QAAO,QAAQ,SAASD,oDAA6B,CAAC,CAAC,QAAQ;;;;;;AAOjE,IAAa,iBAAb,MAA0D;CACxD,AAAQ;CAER,YAAY,SAAgC;AAC1C,OAAK,WAAW,uBAAuB,QAAQ,GAC3C,IAAI,2BAA2B,QAAQ,GACvC,IAAI,kBAAkB,QAAQ;;CAGpC,IAAI,SAA0C;AAC5C,SAAO,KAAK,SAAS;;CAGvB,IAAI,uBAAsE;AACxE,SAAO,KAAK,SAAS;;CAGvB,IAAI,0BAA4E;AAC9E,SAAO,KAAK,SAAS;;CAGvB,IAAI,yBAA0E;AAC5E,SAAO,KAAK,SAAS;;CAGvB,IAAI,SAAsB;AACxB,SAAO,KAAK,SAAS;;CAGvB,IAAI,OAAsC;AACxC,SAAO,KAAK,SAAS;;CAGvB,IAAI,UAA4C;AAC9C,SAAO,KAAK,SAAS;;CAGvB,IAAI,eAAmD;AACrD,SAAO,KAAK,SAAS;;CAGvB,IAAI,sBAA2C;AAC7C,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,sBACd;;CAGN,IAAI,eAAiD;AACnD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,eACd;;CAGN,IAAI,OAAoB;AACtB,SAAO,KAAK,SAAS"}
|
package/dist/runtime.d.cts
CHANGED
|
@@ -36,6 +36,10 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
|
|
|
36
36
|
/** Optional *after* middleware – callback function or webhook URL. */
|
|
37
37
|
afterRequestMiddleware?: AfterRequestMiddleware;
|
|
38
38
|
}
|
|
39
|
+
interface CopilotRuntimeUser {
|
|
40
|
+
id: string;
|
|
41
|
+
}
|
|
42
|
+
type IdentifyUserCallback = (request: Request) => MaybePromise<CopilotRuntimeUser>;
|
|
39
43
|
interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
40
44
|
/** The runner to use for running agents in SSE mode. */
|
|
41
45
|
runner?: AgentRunner;
|
|
@@ -45,6 +49,8 @@ interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
|
45
49
|
interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
46
50
|
/** Configures Intelligence mode for durable threads and realtime events. */
|
|
47
51
|
intelligence: CopilotKitIntelligence;
|
|
52
|
+
/** Resolves the authenticated user for intelligence requests. */
|
|
53
|
+
identifyUser: IdentifyUserCallback;
|
|
48
54
|
/** Auto-generate short names for newly created threads. */
|
|
49
55
|
generateThreadNames?: boolean;
|
|
50
56
|
}
|
|
@@ -58,6 +64,7 @@ interface CopilotRuntimeLike {
|
|
|
58
64
|
a2ui: CopilotRuntimeOptions["a2ui"];
|
|
59
65
|
mcpApps: CopilotRuntimeOptions["mcpApps"];
|
|
60
66
|
intelligence?: CopilotKitIntelligence;
|
|
67
|
+
identifyUser?: IdentifyUserCallback;
|
|
61
68
|
mode: RuntimeMode;
|
|
62
69
|
}
|
|
63
70
|
interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
@@ -66,6 +73,7 @@ interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
|
66
73
|
}
|
|
67
74
|
interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
|
|
68
75
|
intelligence: CopilotKitIntelligence;
|
|
76
|
+
identifyUser: IdentifyUserCallback;
|
|
69
77
|
generateThreadNames: boolean;
|
|
70
78
|
mode: RUNTIME_MODE_INTELLIGENCE;
|
|
71
79
|
}
|
|
@@ -88,6 +96,7 @@ declare class CopilotSseRuntime extends BaseCopilotRuntime implements CopilotSse
|
|
|
88
96
|
}
|
|
89
97
|
declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements CopilotIntelligenceRuntimeLike {
|
|
90
98
|
readonly intelligence: CopilotKitIntelligence;
|
|
99
|
+
readonly identifyUser: IdentifyUserCallback;
|
|
91
100
|
readonly generateThreadNames: boolean;
|
|
92
101
|
readonly mode: any;
|
|
93
102
|
constructor(options: CopilotIntelligenceRuntimeOptions);
|
|
@@ -109,8 +118,9 @@ declare class CopilotRuntime implements CopilotRuntimeLike {
|
|
|
109
118
|
get mcpApps(): CopilotRuntimeOptions["mcpApps"];
|
|
110
119
|
get intelligence(): CopilotKitIntelligence | undefined;
|
|
111
120
|
get generateThreadNames(): boolean | undefined;
|
|
121
|
+
get identifyUser(): IdentifyUserCallback | undefined;
|
|
112
122
|
get mode(): RuntimeMode;
|
|
113
123
|
}
|
|
114
124
|
//#endregion
|
|
115
|
-
export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime };
|
|
125
|
+
export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime };
|
|
116
126
|
//# sourceMappingURL=runtime.d.cts.map
|
package/dist/runtime.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../src/runtime.ts"],"mappings":";;;;;;;;;;cAqBa,OAAA;AAAA,UAEH,mCAAA;EAFG;EAIX,MAAA;AAAA;AAAA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;AAAA;AAAA,iBAoBP,qBAAA,CACd,OAAA,EAAS,kBAAA,GACR,OAAA,IAAW,8BAAA;;;;;cAQD,cAAA,YAA0B,kBAAA;EAAA,QAC7B,QAAA;cAEI,OAAA,EAAS,qBAAA;EAAA,IAMjB,MAAA,CAAA,GAAU,qBAAA;EAAA,IAIV,oBAAA,CAAA,GAAwB,qBAAA;EAAA,IAIxB,uBAAA,CAAA,GAA2B,qBAAA;EAAA,IAI3B,sBAAA,CAAA,GAA0B,qBAAA;EAAA,IAI1B,MAAA,CAAA,GAAU,WAAA;EAAA,IAIV,IAAA,CAAA,GAAQ,qBAAA;EAAA,IAIR,OAAA,CAAA,GAAW,qBAAA;EAAA,IAIX,YAAA,CAAA,GAAgB,sBAAA;EAAA,IAIhB,mBAAA,CAAA;EAAA,IAMA,YAAA,CAAA,GAAgB,oBAAA;EAAA,IAMhB,IAAA,CAAA,GAAQ,WAAA;AAAA"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -37,6 +37,10 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
|
|
|
37
37
|
/** Optional *after* middleware – callback function or webhook URL. */
|
|
38
38
|
afterRequestMiddleware?: AfterRequestMiddleware;
|
|
39
39
|
}
|
|
40
|
+
interface CopilotRuntimeUser {
|
|
41
|
+
id: string;
|
|
42
|
+
}
|
|
43
|
+
type IdentifyUserCallback = (request: Request) => MaybePromise<CopilotRuntimeUser>;
|
|
40
44
|
interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
41
45
|
/** The runner to use for running agents in SSE mode. */
|
|
42
46
|
runner?: AgentRunner;
|
|
@@ -46,6 +50,8 @@ interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
|
46
50
|
interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
47
51
|
/** Configures Intelligence mode for durable threads and realtime events. */
|
|
48
52
|
intelligence: CopilotKitIntelligence;
|
|
53
|
+
/** Resolves the authenticated user for intelligence requests. */
|
|
54
|
+
identifyUser: IdentifyUserCallback;
|
|
49
55
|
/** Auto-generate short names for newly created threads. */
|
|
50
56
|
generateThreadNames?: boolean;
|
|
51
57
|
}
|
|
@@ -59,6 +65,7 @@ interface CopilotRuntimeLike {
|
|
|
59
65
|
a2ui: CopilotRuntimeOptions["a2ui"];
|
|
60
66
|
mcpApps: CopilotRuntimeOptions["mcpApps"];
|
|
61
67
|
intelligence?: CopilotKitIntelligence;
|
|
68
|
+
identifyUser?: IdentifyUserCallback;
|
|
62
69
|
mode: RuntimeMode;
|
|
63
70
|
}
|
|
64
71
|
interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
@@ -67,6 +74,7 @@ interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
|
67
74
|
}
|
|
68
75
|
interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
|
|
69
76
|
intelligence: CopilotKitIntelligence;
|
|
77
|
+
identifyUser: IdentifyUserCallback;
|
|
70
78
|
generateThreadNames: boolean;
|
|
71
79
|
mode: RUNTIME_MODE_INTELLIGENCE;
|
|
72
80
|
}
|
|
@@ -89,6 +97,7 @@ declare class CopilotSseRuntime extends BaseCopilotRuntime implements CopilotSse
|
|
|
89
97
|
}
|
|
90
98
|
declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements CopilotIntelligenceRuntimeLike {
|
|
91
99
|
readonly intelligence: CopilotKitIntelligence;
|
|
100
|
+
readonly identifyUser: IdentifyUserCallback;
|
|
92
101
|
readonly generateThreadNames: boolean;
|
|
93
102
|
readonly mode: any;
|
|
94
103
|
constructor(options: CopilotIntelligenceRuntimeOptions);
|
|
@@ -110,8 +119,9 @@ declare class CopilotRuntime implements CopilotRuntimeLike {
|
|
|
110
119
|
get mcpApps(): CopilotRuntimeOptions["mcpApps"];
|
|
111
120
|
get intelligence(): CopilotKitIntelligence | undefined;
|
|
112
121
|
get generateThreadNames(): boolean | undefined;
|
|
122
|
+
get identifyUser(): IdentifyUserCallback | undefined;
|
|
113
123
|
get mode(): RuntimeMode;
|
|
114
124
|
}
|
|
115
125
|
//#endregion
|
|
116
|
-
export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime };
|
|
126
|
+
export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, VERSION, isIntelligenceRuntime };
|
|
117
127
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/runtime.ts"],"mappings":";;;;;;;;;;;cAqBa,OAAA;AAAA,UAEH,mCAAA;;EAER,MAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA;EAPA,uFAShC,OAAA;AAAA;AAAA,UAGe,aAAA;;EAEf,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGD,yBAAA;EAVqB;EAY7B,IAAA,GAAO,mCAAA,GAAsC,oBAAA;EAZb;EAchC,OAAA,GAAU,aAAA;AAAA;AAAA,UAGF,yBAAA,SAAkC,yBAAA;;EAE1C,MAAA,EAAQ,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA;EAZvB;EAc5B,oBAAA,GAAuB,oBAAA;EAXU;EAajC,uBAAA,GAA0B,uBAAA;EAXnB;EAaP,sBAAA,GAAyB,sBAAA;AAAA;AAAA,UAGV,wBAAA,SAAiC,yBAAA;
|
|
1
|
+
{"version":3,"file":"runtime.d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hB,mBAAA,CAAA;EAAA,IAMA,YAAA,CAAA,GAAgB,oBAAA;EAAA,IAMhB,IAAA,CAAA,GAAQ,WAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -33,6 +33,7 @@ var CopilotSseRuntime = class extends BaseCopilotRuntime {
|
|
|
33
33
|
};
|
|
34
34
|
var CopilotIntelligenceRuntime = class extends BaseCopilotRuntime {
|
|
35
35
|
intelligence;
|
|
36
|
+
identifyUser;
|
|
36
37
|
generateThreadNames;
|
|
37
38
|
mode = RUNTIME_MODE_INTELLIGENCE;
|
|
38
39
|
constructor(options) {
|
|
@@ -41,6 +42,7 @@ var CopilotIntelligenceRuntime = class extends BaseCopilotRuntime {
|
|
|
41
42
|
authToken: options.intelligence.ɵgetRunnerAuthToken()
|
|
42
43
|
}));
|
|
43
44
|
this.intelligence = options.intelligence;
|
|
45
|
+
this.identifyUser = options.identifyUser;
|
|
44
46
|
this.generateThreadNames = options.generateThreadNames ?? true;
|
|
45
47
|
}
|
|
46
48
|
};
|
|
@@ -86,6 +88,9 @@ var CopilotRuntime = class {
|
|
|
86
88
|
get generateThreadNames() {
|
|
87
89
|
return isIntelligenceRuntime(this.delegate) ? this.delegate.generateThreadNames : void 0;
|
|
88
90
|
}
|
|
91
|
+
get identifyUser() {
|
|
92
|
+
return isIntelligenceRuntime(this.delegate) ? this.delegate.identifyUser : void 0;
|
|
93
|
+
}
|
|
89
94
|
get mode() {
|
|
90
95
|
return this.delegate.mode;
|
|
91
96
|
}
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":["pkg.version"],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkitnext/shared\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { TranscriptionService } from \"./transcription-service/transcription-service\";\nimport { AgentRunner } from \"./runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"./runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"./runner/intelligence\";\nimport { CopilotKitIntelligence } from \"./intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\ninterface CopilotRuntimeMiddlewares {\n /** Auto-apply A2UIMiddleware to agents at run time. */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /** Map of available agents (loaded lazily is fine). */\n agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n}\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n intelligence?: CopilotKitIntelligence;\n mode: RuntimeMode;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n generateThreadNames: boolean;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui;\n this.mcpApps = mcpApps;\n this.runner = runner;\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly generateThreadNames: boolean;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n }),\n );\n this.intelligence = options.intelligence;\n this.generateThreadNames = options.generateThreadNames ?? true;\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n}\n"],"mappings":";;;;;;AAqBA,MAAa,UAAUA;
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["pkg.version"],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkitnext/shared\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { TranscriptionService } from \"./transcription-service/transcription-service\";\nimport { AgentRunner } from \"./runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"./runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"./runner/intelligence\";\nimport { CopilotKitIntelligence } from \"./intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\ninterface CopilotRuntimeMiddlewares {\n /** Auto-apply A2UIMiddleware to agents at run time. */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /** Map of available agents (loaded lazily is fine). */\n agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser: IdentifyUserCallback;\n generateThreadNames: boolean;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui;\n this.mcpApps = mcpApps;\n this.runner = runner;\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n }),\n );\n this.intelligence = options.intelligence;\n this.identifyUser = options.identifyUser;\n this.generateThreadNames = options.generateThreadNames ?? true;\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n}\n"],"mappings":";;;;;;AAqBA,MAAa,UAAUA;AAwFvB,IAAe,qBAAf,MAAgE;CAC9D,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAKP,YAAY,SAAoC,QAAqB;EACnE,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,YACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;AAC5B,OAAK,0BAA0B;AAC/B,OAAK,yBAAyB;AAC9B,OAAK,OAAO;AACZ,OAAK,UAAU;AACf,OAAK,SAAS;;;AAIlB,IAAa,oBAAb,cACU,mBAEV;CACE,AAAS,eAAe;CACxB,AAAS,OAAO;CAEhB,YAAY,SAAmC;AAC7C,QAAM,SAAS,QAAQ,UAAU,IAAI,qBAAqB,CAAC;;;AAI/D,IAAa,6BAAb,cACU,mBAEV;CACE,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS,OAAO;CAEhB,YAAY,SAA4C;AACtD,QACE,SACA,IAAI,wBAAwB;GAC1B,KAAK,QAAQ,aAAa,iBAAiB;GAC3C,WAAW,QAAQ,aAAa,qBAAqB;GACtD,CAAC,CACH;AACD,OAAK,eAAe,QAAQ;AAC5B,OAAK,eAAe,QAAQ;AAC5B,OAAK,sBAAsB,QAAQ,uBAAuB;;;AAI9D,SAAS,uBACP,SAC8C;AAC9C,QAAO,kBAAkB,WAAW,CAAC,CAAC,QAAQ;;AAGhD,SAAgB,sBACd,SAC2C;AAC3C,QAAO,QAAQ,SAAS,6BAA6B,CAAC,CAAC,QAAQ;;;;;;AAOjE,IAAa,iBAAb,MAA0D;CACxD,AAAQ;CAER,YAAY,SAAgC;AAC1C,OAAK,WAAW,uBAAuB,QAAQ,GAC3C,IAAI,2BAA2B,QAAQ,GACvC,IAAI,kBAAkB,QAAQ;;CAGpC,IAAI,SAA0C;AAC5C,SAAO,KAAK,SAAS;;CAGvB,IAAI,uBAAsE;AACxE,SAAO,KAAK,SAAS;;CAGvB,IAAI,0BAA4E;AAC9E,SAAO,KAAK,SAAS;;CAGvB,IAAI,yBAA0E;AAC5E,SAAO,KAAK,SAAS;;CAGvB,IAAI,SAAsB;AACxB,SAAO,KAAK,SAAS;;CAGvB,IAAI,OAAsC;AACxC,SAAO,KAAK,SAAS;;CAGvB,IAAI,UAA4C;AAC9C,SAAO,KAAK,SAAS;;CAGvB,IAAI,eAAmD;AACrD,SAAO,KAAK,SAAS;;CAGvB,IAAI,sBAA2C;AAC7C,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,sBACd;;CAGN,IAAI,eAAiD;AACnD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,eACd;;CAGN,IAAI,OAAoB;AACtB,SAAO,KAAK,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkitnext/runtime",
|
|
3
|
-
"version": "1.54.1-next.
|
|
3
|
+
"version": "1.54.1-next.4",
|
|
4
4
|
"deprecated": "This package is deprecated. Use @copilotkit/runtime instead. V2 features are being integrated into the main @copilotkit exports and will be available under the /v2 subpath.",
|
|
5
5
|
"description": "Server-side runtime package for CopilotKit2",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"tsdown": "^0.20.3",
|
|
31
31
|
"typescript": "5.8.2",
|
|
32
32
|
"vitest": "^3.0.5",
|
|
33
|
-
"@copilotkitnext/eslint-config": "1.54.1-next.
|
|
34
|
-
"@copilotkitnext/typescript-config": "1.54.1-next.
|
|
33
|
+
"@copilotkitnext/eslint-config": "1.54.1-next.4",
|
|
34
|
+
"@copilotkitnext/typescript-config": "1.54.1-next.4"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@ag-ui/a2ui-middleware": "0.0.2",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"express": "^4.21.2",
|
|
47
47
|
"hono": "^4.11.4",
|
|
48
48
|
"rxjs": "7.8.1",
|
|
49
|
-
"@copilotkitnext/shared": "1.54.1-next.
|
|
49
|
+
"@copilotkitnext/shared": "1.54.1-next.4"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@ag-ui/client": "0.0.47",
|
|
53
53
|
"@ag-ui/core": "0.0.47",
|
|
54
54
|
"@ag-ui/encoder": "0.0.47",
|
|
55
|
-
"@copilotkitnext/shared": "1.54.1-next.
|
|
55
|
+
"@copilotkitnext/shared": "1.54.1-next.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {},
|
|
58
58
|
"engines": {
|