UNPKG

@copilotkit/runtime

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

1 lines 3.84 kB
{"version":3,"file":"learning.mjs","names":[],"sources":["../../../../src/v2/runtime/core/learning.ts"],"sourcesContent":["import type { RunAgentInput } from \"@ag-ui/client\";\nimport type { MaybePromise } from \"@copilotkit/shared\";\n\n/** Application user resolved by an Intelligence runtime. */\nexport interface CopilotRuntimeUser {\n readonly id: string;\n readonly name: string;\n}\n\n/** Context for choosing a Learning Container through the public Intelligence SDK. */\nexport type LearningContainerSelectorInput =\n | {\n readonly surface: \"web\";\n readonly user: CopilotRuntimeUser;\n readonly agentId: string;\n readonly input: Readonly<RunAgentInput>;\n }\n | {\n readonly surface: \"channel\";\n readonly user: CopilotRuntimeUser | null;\n readonly agentId: string;\n readonly input: Readonly<RunAgentInput>;\n };\n\n/** Chooses one developer-created Learning Container for an Intelligence run. */\nexport type GetLearningContainerId = (\n input: LearningContainerSelectorInput,\n) => MaybePromise<string | null | undefined>;\n\n/** Context for choosing one Learning Container for an Intelligence run. */\nexport type CopilotRuntimeLearningContext =\n | {\n readonly surface: \"web\";\n readonly request: Request;\n readonly threadId: string;\n readonly runId: string;\n readonly agentId: string;\n readonly userId: string;\n }\n | {\n readonly surface: \"channel\";\n readonly threadId: string;\n readonly runId: string;\n readonly agentId: string;\n readonly userId: string;\n readonly deliveryId: string;\n };\n\n/** Assigns each Intelligence Thread to one developer-created Learning Container. */\nexport interface CopilotRuntimeLearningConfig {\n readonly containerId:\n | string\n | ((\n input: CopilotRuntimeLearningContext,\n ) => MaybePromise<string | null | undefined>);\n}\n\nconst STABLE_CONTAINER_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/** Validates and returns a stable Learning Container ID. */\nexport function assertStableLearningContainerId(value: unknown): string {\n if (\n typeof value !== \"string\" ||\n value.length < 1 ||\n value.length > 64 ||\n !STABLE_CONTAINER_ID.test(value)\n ) {\n throw new Error(\n \"Learning Container must use a 1-64 character stable ID with lowercase letters, numbers, and single hyphens\",\n );\n }\n return value;\n}\n\n/** Resolves and validates a public Intelligence Learning Container selection. */\nexport async function resolveLearningContainerSelector(\n selector: GetLearningContainerId,\n input: LearningContainerSelectorInput,\n): Promise<string | undefined> {\n const value = await selector(input);\n if (value == null) return undefined;\n return assertStableLearningContainerId(value);\n}\n\n/** Resolves the configured Container once for one web or Channel run. */\nexport async function resolveLearningContainerId(\n config: CopilotRuntimeLearningConfig | undefined,\n input: CopilotRuntimeLearningContext,\n): Promise<string | undefined> {\n if (config === undefined) return undefined;\n const value =\n typeof config.containerId === \"function\"\n ? await config.containerId(input)\n : config.containerId;\n if (value == null) return undefined;\n return assertStableLearningContainerId(value);\n}\n"],"mappings":";;AAyDA,MAAM,sBAAsB;;AAG5B,SAAgB,gCAAgC,OAAwB;AACtE,KACE,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,SAAS,MACf,CAAC,oBAAoB,KAAK,MAAM,CAEhC,OAAM,IAAI,MACR,6GACD;AAEH,QAAO;;;AAIT,eAAsB,iCACpB,UACA,OAC6B;CAC7B,MAAM,QAAQ,MAAM,SAAS,MAAM;AACnC,KAAI,SAAS,KAAM,QAAO;AAC1B,QAAO,gCAAgC,MAAM;;;AAI/C,eAAsB,2BACpB,QACA,OAC6B;AAC7B,KAAI,WAAW,OAAW,QAAO;CACjC,MAAM,QACJ,OAAO,OAAO,gBAAgB,aAC1B,MAAM,OAAO,YAAY,MAAM,GAC/B,OAAO;AACb,KAAI,SAAS,KAAM,QAAO;AAC1B,QAAO,gCAAgC,MAAM"}