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 8.12 kB
{"version":3,"file":"shared.cjs","names":["createLogger","CopilotResolver","StateResolver"],"sources":["../../../../src/v1-deprecated/lib/integrations/shared.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — buildSchema:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — CommonConfig:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — CopilotEndpointCorsConfig:\n * V2 import and usage:\n * import type { CopilotEndpointCorsConfig } from \"@copilotkit/runtime/v2\";\n * type V2CopilotEndpointCorsConfig = CopilotEndpointCorsConfig;\n * V2 replacement source: packages/runtime/src/v2/runtime/endpoints/hono.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * @copilotkit/runtime — CopilotRequestContextProperties:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — CreateCopilotRuntimeServerOptions:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — getCommonConfig:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — GraphQLContext:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { buildSchemaSync } from \"type-graphql\";\nimport { CopilotResolver } from \"../../graphql/resolvers/copilot.resolver\";\nimport type { CopilotRuntime } from \"../runtime/copilot-runtime\";\nimport type { CopilotServiceAdapter } from \"../../service-adapters\";\nimport type { CopilotCloudOptions } from \"../cloud\";\nimport type { LogLevel } from \"../../lib/logger\";\nimport { createLogger } from \"../../lib/logger\";\nimport telemetry from \"../telemetry-client\";\nimport { StateResolver } from \"../../graphql/resolvers/state.resolver\";\n\n/**\n * CORS configuration for CopilotKit endpoints.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s). Can be a string, array of strings, or a function that returns the origin.\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to include credentials (cookies, authorization headers) in CORS requests.\n * When true, origin cannot be \"*\" - must be an explicit origin.\n */\n credentials?: boolean;\n}\n\nconst logger = createLogger();\n\ntype AnyPrimitive = string | boolean | number | null;\nexport type CopilotRequestContextProperties = Record<\n string,\n AnyPrimitive | Record<string, AnyPrimitive>\n>;\n\n/**\n * The request-scoped fields the v1 middleware hooks read off the GraphQL\n * context.\n *\n * Declared here rather than imported as Yoga's `YogaInitialContext`. Nothing in\n * this package serves GraphQL any more -- every v1 integration entry point\n * delegates to the v2 Hono endpoint -- but that one type reference was enough to\n * pull the whole `graphql-yoga` barrel, and with it `lru-cache@10`, into every\n * consumer's program. `lru-cache@10` declares `implements Map`, which costs five\n * TS2416 errors under `strict` with `skipLibCheck: false` (OSS-899).\n *\n * Structurally identical to `YogaInitialContext`, so a real Yoga context still\n * satisfies it.\n */\nexport interface GraphQLRequestContext {\n /** GraphQL parameters parsed from the request. */\n params: {\n operationName?: string;\n query?: string;\n variables?: Record<string, any>;\n extensions?: Record<string, any>;\n };\n /** The incoming HTTP request. */\n request: Request;\n /** Defers work past the response, where the host runtime supports it. */\n waitUntil(promise: Promise<unknown> | void): void;\n}\n\nexport type GraphQLContext = GraphQLRequestContext & {\n _copilotkit: CreateCopilotRuntimeServerOptions;\n properties: CopilotRequestContextProperties;\n logger: typeof logger;\n};\n\nexport interface CreateCopilotRuntimeServerOptions {\n runtime: CopilotRuntime<any>;\n serviceAdapter?: CopilotServiceAdapter;\n endpoint: string;\n baseUrl?: string;\n cloud?: CopilotCloudOptions;\n properties?: CopilotRequestContextProperties;\n logLevel?: LogLevel;\n /**\n * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n}\n\nexport function buildSchema(\n options: {\n emitSchemaFile?: string;\n } = {},\n) {\n logger.debug(\"Building GraphQL schema...\");\n const schema = buildSchemaSync({\n resolvers: [CopilotResolver, StateResolver],\n emitSchemaFile: options.emitSchemaFile,\n });\n logger.debug(\"GraphQL schema built successfully\");\n return schema;\n}\n\nexport type CommonConfig = {\n logging: typeof logger;\n};\n\nexport function getCommonConfig(\n options: CreateCopilotRuntimeServerOptions,\n): CommonConfig {\n const logLevel =\n (process.env.LOG_LEVEL as LogLevel) ||\n (options.logLevel as LogLevel) ||\n \"error\";\n const logger = createLogger({\n level: logLevel,\n component: \"getCommonConfig\",\n });\n\n if (options.cloud) {\n telemetry.setCloudConfiguration({\n publicApiKey: options.cloud.publicApiKey,\n baseUrl: options.cloud.baseUrl,\n });\n }\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: {\n ...(options.properties._copilotkit as Record<string, any>),\n },\n });\n }\n\n telemetry.setGlobalProperties({\n runtime: {\n serviceAdapter: options.serviceAdapter?.constructor?.name ?? \"none\",\n },\n });\n\n return {\n logging: createLogger({ component: \"CopilotKit Runtime\", level: logLevel }),\n };\n}\n"],"mappings":";;;;;;;;;AAyFA,MAAM,SAASA,6BAAc;AAyD7B,SAAgB,YACd,UAEI,EAAE,EACN;AACA,QAAO,MAAM,6BAA6B;CAC1C,MAAM,2CAAyB;EAC7B,WAAW,CAACC,0CAAiBC,qCAAc;EAC3C,gBAAgB,QAAQ;EACzB,CAAC;AACF,QAAO,MAAM,oCAAoC;AACjD,QAAO;;AAOT,SAAgB,gBACd,SACc;CACd,MAAM,WACH,QAAQ,IAAI,aACZ,QAAQ,YACT;AACa,6BAAa;EAC1B,OAAO;EACP,WAAW;EACZ,CAAC;AAEF,KAAI,QAAQ,MACV,kCAAU,sBAAsB;EAC9B,cAAc,QAAQ,MAAM;EAC5B,SAAS,QAAQ,MAAM;EACxB,CAAC;AAGJ,KAAI,QAAQ,YAAY,YACtB,kCAAU,oBAAoB,EAC5B,aAAa,EACX,GAAI,QAAQ,WAAW,aACxB,EACF,CAAC;AAGJ,kCAAU,oBAAoB,EAC5B,SAAS,EACP,gBAAgB,QAAQ,gBAAgB,aAAa,QAAQ,QAC9D,EACF,CAAC;AAEF,QAAO,EACL,SAASF,4BAAa;EAAE,WAAW;EAAsB,OAAO;EAAU,CAAC,EAC5E"}