@copilotkit/runtime 1.73.0 → 1.73.1
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/agent/index.cjs +1 -1
- package/dist/agent/index.d.mts +1 -1
- package/dist/agent/index.mjs +1 -1
- package/dist/lib/integrations/nextjs/app-router.cjs +1 -1
- package/dist/lib/integrations/nextjs/app-router.cjs.map +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs.map +1 -1
- package/dist/lib/integrations/node-http/index.cjs +1 -1
- package/dist/lib/integrations/node-http/index.cjs.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/lib/integrations/node-http/index.mjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +79 -37
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +52 -2
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +54 -4
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +79 -37
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/lib/runtime/mcp-client-cache.cjs +135 -0
- package/dist/lib/runtime/mcp-client-cache.cjs.map +1 -0
- package/dist/lib/runtime/mcp-client-cache.mjs +132 -0
- package/dist/lib/runtime/mcp-client-cache.mjs.map +1 -0
- package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.mts +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
- package/dist/package.cjs +7 -5
- package/dist/package.mjs +7 -5
- package/dist/v2/index.cjs +3 -3
- package/dist/v2/index.d.cts +7 -7
- package/dist/v2/index.d.mts +7 -7
- package/dist/v2/index.mjs +4 -4
- package/dist/v2/runtime/core/channel-manager.cjs +1 -1
- package/dist/v2/runtime/core/channel-manager.mjs +1 -1
- package/dist/v2/runtime/core/fetch-handler.cjs +1 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.cts +2 -2
- package/dist/v2/runtime/core/fetch-handler.d.mts +2 -2
- package/dist/v2/runtime/core/fetch-handler.mjs +1 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.cts +2 -2
- package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.mts +2 -2
- package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.cjs +2 -3
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.cts +26 -7
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.mts +26 -7
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express.mjs +2 -2
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.cts +2 -2
- package/dist/v2/runtime/endpoints/hono.d.mts +2 -2
- package/dist/v2/runtime/endpoints/index.d.cts +3 -3
- package/dist/v2/runtime/endpoints/index.d.mts +3 -3
- package/dist/v2/runtime/endpoints/load-express.cjs +36 -0
- package/dist/v2/runtime/endpoints/load-express.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/load-express.mjs +35 -0
- package/dist/v2/runtime/endpoints/load-express.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-stop.cjs +18 -14
- package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-stop.mjs +18 -14
- package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +3 -4
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -2
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/index.d.cts +7 -7
- package/dist/v2/runtime/index.d.mts +7 -7
- package/dist/v2/runtime/intelligence-platform/client.cjs +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +1 -1
- package/package.json +10 -6
- package/dist/v2/runtime/open-generative-ui-middleware.cjs +0 -286
- package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/v2/runtime/open-generative-ui-middleware.mjs +0 -284
- package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +0 -1
package/dist/agent/index.cjs
CHANGED
|
@@ -11,13 +11,13 @@ let _copilotkit_shared = require("@copilotkit/shared");
|
|
|
11
11
|
let _ai_sdk_google = require("@ai-sdk/google");
|
|
12
12
|
let rxjs = require("rxjs");
|
|
13
13
|
let _ag_ui_client = require("@ag-ui/client");
|
|
14
|
-
let zod = require("zod");
|
|
15
14
|
let _ag_ui_a2ui_middleware = require("@ag-ui/a2ui-middleware");
|
|
16
15
|
let _cfworker_json_schema = require("@cfworker/json-schema");
|
|
17
16
|
let ai = require("ai");
|
|
18
17
|
let _ai_sdk_mcp = require("@ai-sdk/mcp");
|
|
19
18
|
let _ai_sdk_anthropic = require("@ai-sdk/anthropic");
|
|
20
19
|
let _ai_sdk_google_vertex = require("@ai-sdk/google-vertex");
|
|
20
|
+
let zod = require("zod");
|
|
21
21
|
let _modelcontextprotocol_sdk_client_streamableHttp_js = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
22
22
|
|
|
23
23
|
//#region src/agent/index.ts
|
package/dist/agent/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ import "./converters/index.mjs";
|
|
|
6
6
|
import { InferSchemaOutput, ModelHostClass, StandardSchemaV1 } from "@copilotkit/shared";
|
|
7
7
|
import { Observable } from "rxjs";
|
|
8
8
|
import { AbstractAgent, BaseEvent, Interrupt, Message, ResumeEntry, RunAgentInput } from "@ag-ui/client";
|
|
9
|
-
import { z } from "zod";
|
|
10
9
|
import { LanguageModel, ModelMessage, ToolChoice, ToolSet } from "ai";
|
|
10
|
+
import { z } from "zod";
|
|
11
11
|
import { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
12
12
|
import { AgentCapabilities } from "@ag-ui/core";
|
|
13
13
|
|
package/dist/agent/index.mjs
CHANGED
|
@@ -10,13 +10,13 @@ import { classifyModelHost, randomUUID, safeParseToolArgs, schemaToJsonSchema }
|
|
|
10
10
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
11
11
|
import { Observable } from "rxjs";
|
|
12
12
|
import { AbstractAgent, EventType } from "@ag-ui/client";
|
|
13
|
-
import { z } from "zod";
|
|
14
13
|
import { RENDER_A2UI_TOOL } from "@ag-ui/a2ui-middleware";
|
|
15
14
|
import { Validator } from "@cfworker/json-schema";
|
|
16
15
|
import { jsonSchema, stepCountIs, streamText, tool } from "ai";
|
|
17
16
|
import { createMCPClient } from "@ai-sdk/mcp";
|
|
18
17
|
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
19
18
|
import { createVertex } from "@ai-sdk/google-vertex";
|
|
19
|
+
import { z } from "zod";
|
|
20
20
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
21
21
|
|
|
22
22
|
//#region src/agent/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require("reflect-metadata");
|
|
2
2
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_hono_single = require('../../../v2/runtime/endpoints/hono-single.cjs');
|
|
4
3
|
const require_telemetry_client = require('../../telemetry-client.cjs');
|
|
5
4
|
const require_shared = require('../shared.cjs');
|
|
5
|
+
const require_hono_single = require('../../../v2/runtime/endpoints/hono-single.cjs');
|
|
6
6
|
let hono_vercel = require("hono/vercel");
|
|
7
7
|
|
|
8
8
|
//#region src/v1-deprecated/lib/integrations/nextjs/app-router.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-router.cjs","names":["getCommonConfig","getRuntimeInstanceTelemetryInfo","createCopilotEndpointSingleRoute"],"sources":["../../../../../src/v1-deprecated/lib/integrations/nextjs/app-router.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 — copilotRuntimeNextJSAppRouterEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime\";\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { handle } from \"hono/vercel\";\n\nexport function copilotRuntimeNextJSAppRouterEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"nextjs-app-router\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating NextJS App Router endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const copilotRoute = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handleRequest = handle(copilotRoute as any);\n return { handleRequest };\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgB,sCACd,SACA;CACA,MAAM,eAAeA,+BAAgB,QAAQ;AAE7C,kCAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,qBACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,kCAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACAC,yDAAgC,QAAQ,CACzC;AAGD,CADe,aAAa,QACrB,MAAM,sCAAsC;CAEnD,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;AAWtD,QAAO,EAAE,uCAPYC,qDAAiC;EACpD,SAAS,QAAQ,QAAQ;EACzB,UAAU,QAAQ,WAAW,QAAQ;EACrC,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM;EAC3C,CAAQ,CAEwC,EACzB"}
|
|
1
|
+
{"version":3,"file":"app-router.cjs","names":["getCommonConfig","getRuntimeInstanceTelemetryInfo","createCopilotEndpointSingleRoute"],"sources":["../../../../../src/v1-deprecated/lib/integrations/nextjs/app-router.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 — copilotRuntimeNextJSAppRouterEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime/endpoints/hono-single\";\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { handle } from \"hono/vercel\";\n\nexport function copilotRuntimeNextJSAppRouterEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"nextjs-app-router\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating NextJS App Router endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const copilotRoute = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handleRequest = handle(copilotRoute as any);\n return { handleRequest };\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgB,sCACd,SACA;CACA,MAAM,eAAeA,+BAAgB,QAAQ;AAE7C,kCAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,qBACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,kCAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACAC,yDAAgC,QAAQ,CACzC;AAGD,CADe,aAAa,QACrB,MAAM,sCAAsC;CAEnD,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;AAWtD,QAAO,EAAE,uCAPYC,qDAAiC;EACpD,SAAS,QAAQ,QAAQ;EACzB,UAAU,QAAQ,WAAW,QAAQ;EACrC,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM;EAC3C,CAAQ,CAEwC,EACzB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { createCopilotEndpointSingleRoute } from "../../../v2/runtime/endpoints/hono-single.mjs";
|
|
3
2
|
import telemetryClient, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client.mjs";
|
|
4
3
|
import { getCommonConfig } from "../shared.mjs";
|
|
4
|
+
import { createCopilotEndpointSingleRoute } from "../../../v2/runtime/endpoints/hono-single.mjs";
|
|
5
5
|
import { handle } from "hono/vercel";
|
|
6
6
|
|
|
7
7
|
//#region src/v1-deprecated/lib/integrations/nextjs/app-router.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-router.mjs","names":[],"sources":["../../../../../src/v1-deprecated/lib/integrations/nextjs/app-router.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 — copilotRuntimeNextJSAppRouterEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime\";\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { handle } from \"hono/vercel\";\n\nexport function copilotRuntimeNextJSAppRouterEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"nextjs-app-router\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating NextJS App Router endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const copilotRoute = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handleRequest = handle(copilotRoute as any);\n return { handleRequest };\n}\n"],"mappings":";;;;;;;AA2BA,SAAgB,sCACd,SACA;CACA,MAAM,eAAe,gBAAgB,QAAQ;AAE7C,iBAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,qBACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,iBAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACA,gCAAgC,QAAQ,CACzC;AAGD,CADe,aAAa,QACrB,MAAM,sCAAsC;CAEnD,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;AAWtD,QAAO,EAAE,eADa,OAND,iCAAiC;EACpD,SAAS,QAAQ,QAAQ;EACzB,UAAU,QAAQ,WAAW,QAAQ;EACrC,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM;EAC3C,CAAQ,CAEwC,EACzB"}
|
|
1
|
+
{"version":3,"file":"app-router.mjs","names":[],"sources":["../../../../../src/v1-deprecated/lib/integrations/nextjs/app-router.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 — copilotRuntimeNextJSAppRouterEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime/endpoints/hono-single\";\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { handle } from \"hono/vercel\";\n\nexport function copilotRuntimeNextJSAppRouterEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"nextjs-app-router\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating NextJS App Router endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const copilotRoute = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handleRequest = handle(copilotRoute as any);\n return { handleRequest };\n}\n"],"mappings":";;;;;;;AA2BA,SAAgB,sCACd,SACA;CACA,MAAM,eAAe,gBAAgB,QAAQ;AAE7C,iBAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,qBACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,iBAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACA,gCAAgC,QAAQ,CACzC;AAGD,CADe,aAAa,QACrB,MAAM,sCAAsC;CAEnD,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;AAWtD,QAAO,EAAE,eADa,OAND,iCAAiC;EACpD,SAAS,QAAQ,QAAQ;EACzB,UAAU,QAAQ,WAAW,QAAQ;EACrC,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM;EAC3C,CAAQ,CAEwC,EACzB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require("reflect-metadata");
|
|
2
|
-
const require_hono_single = require('../../../v2/runtime/endpoints/hono-single.cjs');
|
|
3
2
|
const require_telemetry_client = require('../../telemetry-client.cjs');
|
|
4
3
|
const require_shared = require('../shared.cjs');
|
|
4
|
+
const require_hono_single = require('../../../v2/runtime/endpoints/hono-single.cjs');
|
|
5
5
|
const require_request_handler = require('./request-handler.cjs');
|
|
6
6
|
|
|
7
7
|
//#region src/v1-deprecated/lib/integrations/node-http/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["getCommonConfig","getRuntimeInstanceTelemetryInfo","createCopilotEndpointSingleRoute","getFullUrl","toHeaders","isStreamConsumed","nodeStreamToReadableStream","synthesizeBodyFromParsedBody","isDisturbedOrLockedError"],"sources":["../../../../../src/v1-deprecated/lib/integrations/node-http/index.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 — copilotRuntimeNodeHttpEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { IncomingWithBody } from \"./request-handler\";\nimport {\n getFullUrl,\n isDisturbedOrLockedError,\n isStreamConsumed,\n nodeStreamToReadableStream,\n readableStreamToNodeStream,\n synthesizeBodyFromParsedBody,\n toHeaders,\n} from \"./request-handler\";\n\nexport function copilotRuntimeNodeHttpEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"node-http\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating Node HTTP endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const honoApp = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handle = async function handler(\n req: IncomingWithBody,\n res: ServerResponse,\n ) {\n const url = getFullUrl(req);\n const hasBody = req.method !== \"GET\" && req.method !== \"HEAD\";\n\n const baseHeaders = toHeaders(req.headers);\n const parsedBody = req.body;\n\n const streamConsumed = isStreamConsumed(req) || parsedBody !== undefined;\n const canStream = hasBody && !streamConsumed;\n\n let requestBody: BodyInit | null | undefined = undefined;\n let useDuplex = false;\n\n if (hasBody && canStream) {\n requestBody = nodeStreamToReadableStream(req);\n useDuplex = true;\n }\n\n if (hasBody && streamConsumed) {\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n baseHeaders,\n );\n requestBody = synthesized.body ?? undefined;\n baseHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n baseHeaders.set(\"content-type\", synthesized.contentType);\n }\n\n logger.debug(\n \"Request stream already consumed; using parsed req.body to rebuild request.\",\n );\n } else {\n logger.warn(\n \"Request stream consumed with no available body; sending empty payload.\",\n );\n requestBody = undefined;\n }\n }\n\n const buildRequest = (\n body: BodyInit | null | undefined,\n headers: Headers,\n duplex: boolean,\n ) =>\n new Request(url, {\n method: req.method,\n headers,\n body,\n duplex: duplex ? \"half\" : undefined,\n } as RequestInit);\n\n let response: Response;\n try {\n response = await honoApp.fetch(\n buildRequest(requestBody, baseHeaders, useDuplex),\n );\n } catch (error) {\n if (isDisturbedOrLockedError(error) && hasBody) {\n logger.warn(\n \"Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.\",\n );\n\n const fallbackHeaders = new Headers(baseHeaders);\n let fallbackBody: BodyInit | null | undefined;\n\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n fallbackHeaders,\n );\n fallbackBody = synthesized.body ?? undefined;\n fallbackHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n fallbackHeaders.set(\"content-type\", synthesized.contentType);\n }\n } else {\n fallbackBody = undefined;\n }\n\n response = await honoApp.fetch(\n buildRequest(fallbackBody, fallbackHeaders, false),\n );\n } else {\n throw error;\n }\n }\n\n res.statusCode = response.status;\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (response.body) {\n readableStreamToNodeStream(response.body).pipe(res);\n } else {\n res.end();\n }\n };\n\n // Duck-type check for Request-like objects (handles polyfilled Request from @hono/node-server)\n function isRequestLike(obj: unknown): obj is Request {\n return (\n obj instanceof Request ||\n (typeof obj === \"object\" &&\n obj !== null &&\n \"url\" in obj &&\n \"method\" in obj &&\n \"headers\" in obj &&\n typeof (obj as any).url === \"string\" &&\n typeof (obj as any).method === \"string\")\n );\n }\n\n return function (\n reqOrRequest: IncomingMessage | Request,\n res?: ServerResponse,\n ): Promise<void> | Promise<Response> | Response {\n if (isRequestLike(reqOrRequest) && !res) {\n return honoApp.fetch(reqOrRequest as Request);\n }\n if (!res) {\n throw new TypeError(\"ServerResponse is required for Node HTTP requests\");\n }\n return handle(reqOrRequest as IncomingMessage, res);\n };\n}\n"],"mappings":";;;;;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K;GACf,QAAQ,IAAI;GACZ;GACA;GACA,QAAQ,SAAS,SAAS;GAC3B,CAAgB;EAEnB,IAAI;AACJ,MAAI;AACF,cAAW,MAAM,QAAQ,MACvB,aAAa,aAAa,aAAa,UAAU,CAClD;WACM,OAAO;AACd,OAAIC,iDAAyB,MAAM,IAAI,SAAS;AAC9C,WAAO,KACL,oGACD;IAED,MAAM,kBAAkB,IAAI,QAAQ,YAAY;IAChD,IAAI;AAEJ,QAAI,eAAe,QAAW;KAC5B,MAAM,cAAcD,qDAClB,YACA,gBACD;AACD,oBAAe,YAAY,QAAQ;AACnC,qBAAgB,OAAO,iBAAiB;AAExC,SAAI,YAAY,YACd,iBAAgB,IAAI,gBAAgB,YAAY,YAAY;UAG9D,gBAAe;AAGjB,eAAW,MAAM,QAAQ,MACvB,aAAa,cAAc,iBAAiB,MAAM,CACnD;SAED,OAAM;;AAIV,MAAI,aAAa,SAAS;AAC1B,WAAS,QAAQ,SAAS,OAAO,QAAQ;AACvC,OAAI,UAAU,KAAK,MAAM;IACzB;AAEF,MAAI,SAAS,KACX,oDAA2B,SAAS,KAAK,CAAC,KAAK,IAAI;MAEnD,KAAI,KAAK;;CAKb,SAAS,cAAc,KAA8B;AACnD,SACE,eAAe,WACd,OAAO,QAAQ,YACd,QAAQ,QACR,SAAS,OACT,YAAY,OACZ,aAAa,OACb,OAAQ,IAAY,QAAQ,YAC5B,OAAQ,IAAY,WAAW;;AAIrC,QAAO,SACL,cACA,KAC8C;AAC9C,MAAI,cAAc,aAAa,IAAI,CAAC,IAClC,QAAO,QAAQ,MAAM,aAAwB;AAE/C,MAAI,CAAC,IACH,OAAM,IAAI,UAAU,oDAAoD;AAE1E,SAAO,OAAO,cAAiC,IAAI"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getCommonConfig","getRuntimeInstanceTelemetryInfo","createCopilotEndpointSingleRoute","getFullUrl","toHeaders","isStreamConsumed","nodeStreamToReadableStream","synthesizeBodyFromParsedBody","isDisturbedOrLockedError"],"sources":["../../../../../src/v1-deprecated/lib/integrations/node-http/index.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 — copilotRuntimeNodeHttpEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime/endpoints/hono-single\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { IncomingWithBody } from \"./request-handler\";\nimport {\n getFullUrl,\n isDisturbedOrLockedError,\n isStreamConsumed,\n nodeStreamToReadableStream,\n readableStreamToNodeStream,\n synthesizeBodyFromParsedBody,\n toHeaders,\n} from \"./request-handler\";\n\nexport function copilotRuntimeNodeHttpEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"node-http\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating Node HTTP endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const honoApp = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handle = async function handler(\n req: IncomingWithBody,\n res: ServerResponse,\n ) {\n const url = getFullUrl(req);\n const hasBody = req.method !== \"GET\" && req.method !== \"HEAD\";\n\n const baseHeaders = toHeaders(req.headers);\n const parsedBody = req.body;\n\n const streamConsumed = isStreamConsumed(req) || parsedBody !== undefined;\n const canStream = hasBody && !streamConsumed;\n\n let requestBody: BodyInit | null | undefined = undefined;\n let useDuplex = false;\n\n if (hasBody && canStream) {\n requestBody = nodeStreamToReadableStream(req);\n useDuplex = true;\n }\n\n if (hasBody && streamConsumed) {\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n baseHeaders,\n );\n requestBody = synthesized.body ?? undefined;\n baseHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n baseHeaders.set(\"content-type\", synthesized.contentType);\n }\n\n logger.debug(\n \"Request stream already consumed; using parsed req.body to rebuild request.\",\n );\n } else {\n logger.warn(\n \"Request stream consumed with no available body; sending empty payload.\",\n );\n requestBody = undefined;\n }\n }\n\n const buildRequest = (\n body: BodyInit | null | undefined,\n headers: Headers,\n duplex: boolean,\n ) =>\n new Request(url, {\n method: req.method,\n headers,\n body,\n duplex: duplex ? \"half\" : undefined,\n } as RequestInit);\n\n let response: Response;\n try {\n response = await honoApp.fetch(\n buildRequest(requestBody, baseHeaders, useDuplex),\n );\n } catch (error) {\n if (isDisturbedOrLockedError(error) && hasBody) {\n logger.warn(\n \"Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.\",\n );\n\n const fallbackHeaders = new Headers(baseHeaders);\n let fallbackBody: BodyInit | null | undefined;\n\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n fallbackHeaders,\n );\n fallbackBody = synthesized.body ?? undefined;\n fallbackHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n fallbackHeaders.set(\"content-type\", synthesized.contentType);\n }\n } else {\n fallbackBody = undefined;\n }\n\n response = await honoApp.fetch(\n buildRequest(fallbackBody, fallbackHeaders, false),\n );\n } else {\n throw error;\n }\n }\n\n res.statusCode = response.status;\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (response.body) {\n readableStreamToNodeStream(response.body).pipe(res);\n } else {\n res.end();\n }\n };\n\n // Duck-type check for Request-like objects (handles polyfilled Request from @hono/node-server)\n function isRequestLike(obj: unknown): obj is Request {\n return (\n obj instanceof Request ||\n (typeof obj === \"object\" &&\n obj !== null &&\n \"url\" in obj &&\n \"method\" in obj &&\n \"headers\" in obj &&\n typeof (obj as any).url === \"string\" &&\n typeof (obj as any).method === \"string\")\n );\n }\n\n return function (\n reqOrRequest: IncomingMessage | Request,\n res?: ServerResponse,\n ): Promise<void> | Promise<Response> | Response {\n if (isRequestLike(reqOrRequest) && !res) {\n return honoApp.fetch(reqOrRequest as Request);\n }\n if (!res) {\n throw new TypeError(\"ServerResponse is required for Node HTTP requests\");\n }\n return handle(reqOrRequest as IncomingMessage, res);\n };\n}\n"],"mappings":";;;;;;;AAqCA,SAAgB,+BACd,SACA;CACA,MAAM,eAAeA,+BAAgB,QAAQ;AAE7C,kCAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,aACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,kCAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACAC,yDAAgC,QAAQ,CACzC;CAED,MAAM,SAAS,aAAa;AAC5B,QAAO,MAAM,8BAA8B;CAE3C,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qB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,iBAAiB;AAExC,SAAI,YAAY,YACd,iBAAgB,IAAI,gBAAgB,YAAY,YAAY;UAG9D,gBAAe;AAGjB,eAAW,MAAM,QAAQ,MACvB,aAAa,cAAc,iBAAiB,MAAM,CACnD;SAED,OAAM;;AAIV,MAAI,aAAa,SAAS;AAC1B,WAAS,QAAQ,SAAS,OAAO,QAAQ;AACvC,OAAI,UAAU,KAAK,MAAM;IACzB;AAEF,MAAI,SAAS,KACX,oDAA2B,SAAS,KAAK,CAAC,KAAK,IAAI;MAEnD,KAAI,KAAK;;CAKb,SAAS,cAAc,KAA8B;AACnD,SACE,eAAe,WACd,OAAO,QAAQ,YACd,QAAQ,QACR,SAAS,OACT,YAAY,OACZ,aAAa,OACb,OAAQ,IAAY,QAAQ,YAC5B,OAAQ,IAAY,WAAW;;AAIrC,QAAO,SACL,cACA,KAC8C;AAC9C,MAAI,cAAc,aAAa,IAAI,CAAC,IAClC,QAAO,QAAQ,MAAM,aAAwB;AAE/C,MAAI,CAAC,IACH,OAAM,IAAI,UAAU,oDAAoD;AAE1E,SAAO,OAAO,cAAiC,IAAI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { createCopilotEndpointSingleRoute } from "../../../v2/runtime/endpoints/hono-single.mjs";
|
|
3
2
|
import telemetryClient, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client.mjs";
|
|
4
3
|
import { getCommonConfig } from "../shared.mjs";
|
|
4
|
+
import { createCopilotEndpointSingleRoute } from "../../../v2/runtime/endpoints/hono-single.mjs";
|
|
5
5
|
import { getFullUrl, isDisturbedOrLockedError, isStreamConsumed, nodeStreamToReadableStream, readableStreamToNodeStream, synthesizeBodyFromParsedBody, toHeaders } from "./request-handler.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/v1-deprecated/lib/integrations/node-http/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../src/v1-deprecated/lib/integrations/node-http/index.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 — copilotRuntimeNodeHttpEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { IncomingWithBody } from \"./request-handler\";\nimport {\n getFullUrl,\n isDisturbedOrLockedError,\n isStreamConsumed,\n nodeStreamToReadableStream,\n readableStreamToNodeStream,\n synthesizeBodyFromParsedBody,\n toHeaders,\n} from \"./request-handler\";\n\nexport function copilotRuntimeNodeHttpEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"node-http\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating Node HTTP endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const honoApp = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handle = async function handler(\n req: IncomingWithBody,\n res: ServerResponse,\n ) {\n const url = getFullUrl(req);\n const hasBody = req.method !== \"GET\" && req.method !== \"HEAD\";\n\n const baseHeaders = toHeaders(req.headers);\n const parsedBody = req.body;\n\n const streamConsumed = isStreamConsumed(req) || parsedBody !== undefined;\n const canStream = hasBody && !streamConsumed;\n\n let requestBody: BodyInit | null | undefined = undefined;\n let useDuplex = false;\n\n if (hasBody && canStream) {\n requestBody = nodeStreamToReadableStream(req);\n useDuplex = true;\n }\n\n if (hasBody && streamConsumed) {\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n baseHeaders,\n );\n requestBody = synthesized.body ?? undefined;\n baseHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n baseHeaders.set(\"content-type\", synthesized.contentType);\n }\n\n logger.debug(\n \"Request stream already consumed; using parsed req.body to rebuild request.\",\n );\n } else {\n logger.warn(\n \"Request stream consumed with no available body; sending empty payload.\",\n );\n requestBody = undefined;\n }\n }\n\n const buildRequest = (\n body: BodyInit | null | undefined,\n headers: Headers,\n duplex: boolean,\n ) =>\n new Request(url, {\n method: req.method,\n headers,\n body,\n duplex: duplex ? \"half\" : undefined,\n } as RequestInit);\n\n let response: Response;\n try {\n response = await honoApp.fetch(\n buildRequest(requestBody, baseHeaders, useDuplex),\n );\n } catch (error) {\n if (isDisturbedOrLockedError(error) && hasBody) {\n logger.warn(\n \"Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.\",\n );\n\n const fallbackHeaders = new Headers(baseHeaders);\n let fallbackBody: BodyInit | null | undefined;\n\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n fallbackHeaders,\n );\n fallbackBody = synthesized.body ?? undefined;\n fallbackHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n fallbackHeaders.set(\"content-type\", synthesized.contentType);\n }\n } else {\n fallbackBody = undefined;\n }\n\n response = await honoApp.fetch(\n buildRequest(fallbackBody, fallbackHeaders, false),\n );\n } else {\n throw error;\n }\n }\n\n res.statusCode = response.status;\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (response.body) {\n readableStreamToNodeStream(response.body).pipe(res);\n } else {\n res.end();\n }\n };\n\n // Duck-type check for Request-like objects (handles polyfilled Request from @hono/node-server)\n function isRequestLike(obj: unknown): obj is Request {\n return (\n obj instanceof Request ||\n (typeof obj === \"object\" &&\n obj !== null &&\n \"url\" in obj &&\n \"method\" in obj &&\n \"headers\" in obj &&\n typeof (obj as any).url === \"string\" &&\n typeof (obj as any).method === \"string\")\n );\n }\n\n return function (\n reqOrRequest: IncomingMessage | Request,\n res?: ServerResponse,\n ): Promise<void> | Promise<Response> | Response {\n if (isRequestLike(reqOrRequest) && !res) {\n return honoApp.fetch(reqOrRequest as Request);\n }\n if (!res) {\n throw new TypeError(\"ServerResponse is required for Node HTTP requests\");\n }\n return handle(reqOrRequest as IncomingMessage, res);\n };\n}\n"],"mappings":";;;;;;;AAqCA,SAAgB,+BACd,SACA;CACA,MAAM,eAAe,gBAAgB,QAAQ;AAE7C,iBAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,aACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,iBAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACA,gCAAgC,QAAQ,CACzC;CAED,MAAM,SAAS,aAAa;AAC5B,QAAO,MAAM,8BAA8B;CAE3C,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;CAItD,MAAM,UAAU,iCAAiC;EAC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,YAAY,YAAY;UAG9D,gBAAe;AAGjB,eAAW,MAAM,QAAQ,MACvB,aAAa,cAAc,iBAAiB,MAAM,CACnD;SAED,OAAM;;AAIV,MAAI,aAAa,SAAS;AAC1B,WAAS,QAAQ,SAAS,OAAO,QAAQ;AACvC,OAAI,UAAU,KAAK,MAAM;IACzB;AAEF,MAAI,SAAS,KACX,4BAA2B,SAAS,KAAK,CAAC,KAAK,IAAI;MAEnD,KAAI,KAAK;;CAKb,SAAS,cAAc,KAA8B;AACnD,SACE,eAAe,WACd,OAAO,QAAQ,YACd,QAAQ,QACR,SAAS,OACT,YAAY,OACZ,aAAa,OACb,OAAQ,IAAY,QAAQ,YAC5B,OAAQ,IAAY,WAAW;;AAIrC,QAAO,SACL,cACA,KAC8C;AAC9C,MAAI,cAAc,aAAa,IAAI,CAAC,IAClC,QAAO,QAAQ,MAAM,aAAwB;AAE/C,MAAI,CAAC,IACH,OAAM,IAAI,UAAU,oDAAoD;AAE1E,SAAO,OAAO,cAAiC,IAAI"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../src/v1-deprecated/lib/integrations/node-http/index.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 — copilotRuntimeNodeHttpEndpoint:\n * V2 import and usage:\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * const v2CreateCopilotRuntimeHandler = createCopilotRuntimeHandler;\n * V2 replacement source: packages/runtime/src/v2/runtime/core/fetch-handler.ts\n * V2 docs: https://docs.copilotkit.ai/runtime-server-adapter\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport type { CreateCopilotRuntimeServerOptions } from \"../shared\";\nimport { getCommonConfig } from \"../shared\";\nimport telemetry, {\n getRuntimeInstanceTelemetryInfo,\n} from \"../../telemetry-client\";\nimport { createCopilotEndpointSingleRoute } from \"../../../../v2/runtime/endpoints/hono-single\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { IncomingWithBody } from \"./request-handler\";\nimport {\n getFullUrl,\n isDisturbedOrLockedError,\n isStreamConsumed,\n nodeStreamToReadableStream,\n readableStreamToNodeStream,\n synthesizeBodyFromParsedBody,\n toHeaders,\n} from \"./request-handler\";\n\nexport function copilotRuntimeNodeHttpEndpoint(\n options: CreateCopilotRuntimeServerOptions,\n) {\n const commonConfig = getCommonConfig(options);\n\n telemetry.setGlobalProperties({\n runtime: {\n framework: \"node-http\",\n },\n });\n\n if (options.properties?._copilotkit) {\n telemetry.setGlobalProperties({\n _copilotkit: options.properties._copilotkit,\n });\n }\n\n options.runtime.telemetry.capture(\n \"oss.runtime.instance_created\",\n getRuntimeInstanceTelemetryInfo(options),\n );\n\n const logger = commonConfig.logging;\n logger.debug(\"Creating Node HTTP endpoint\");\n\n const serviceAdapter = options.serviceAdapter;\n if (serviceAdapter) {\n options.runtime.handleServiceAdapter(serviceAdapter);\n }\n\n // Note: cors option requires @copilotkit/runtime with credentials support\n const honoApp = createCopilotEndpointSingleRoute({\n runtime: options.runtime.instance,\n basePath: options.baseUrl ?? options.endpoint,\n ...(options.cors && { cors: options.cors }),\n } as any);\n\n const handle = async function handler(\n req: IncomingWithBody,\n res: ServerResponse,\n ) {\n const url = getFullUrl(req);\n const hasBody = req.method !== \"GET\" && req.method !== \"HEAD\";\n\n const baseHeaders = toHeaders(req.headers);\n const parsedBody = req.body;\n\n const streamConsumed = isStreamConsumed(req) || parsedBody !== undefined;\n const canStream = hasBody && !streamConsumed;\n\n let requestBody: BodyInit | null | undefined = undefined;\n let useDuplex = false;\n\n if (hasBody && canStream) {\n requestBody = nodeStreamToReadableStream(req);\n useDuplex = true;\n }\n\n if (hasBody && streamConsumed) {\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n baseHeaders,\n );\n requestBody = synthesized.body ?? undefined;\n baseHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n baseHeaders.set(\"content-type\", synthesized.contentType);\n }\n\n logger.debug(\n \"Request stream already consumed; using parsed req.body to rebuild request.\",\n );\n } else {\n logger.warn(\n \"Request stream consumed with no available body; sending empty payload.\",\n );\n requestBody = undefined;\n }\n }\n\n const buildRequest = (\n body: BodyInit | null | undefined,\n headers: Headers,\n duplex: boolean,\n ) =>\n new Request(url, {\n method: req.method,\n headers,\n body,\n duplex: duplex ? \"half\" : undefined,\n } as RequestInit);\n\n let response: Response;\n try {\n response = await honoApp.fetch(\n buildRequest(requestBody, baseHeaders, useDuplex),\n );\n } catch (error) {\n if (isDisturbedOrLockedError(error) && hasBody) {\n logger.warn(\n \"Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.\",\n );\n\n const fallbackHeaders = new Headers(baseHeaders);\n let fallbackBody: BodyInit | null | undefined;\n\n if (parsedBody !== undefined) {\n const synthesized = synthesizeBodyFromParsedBody(\n parsedBody,\n fallbackHeaders,\n );\n fallbackBody = synthesized.body ?? undefined;\n fallbackHeaders.delete(\"content-length\");\n\n if (synthesized.contentType) {\n fallbackHeaders.set(\"content-type\", synthesized.contentType);\n }\n } else {\n fallbackBody = undefined;\n }\n\n response = await honoApp.fetch(\n buildRequest(fallbackBody, fallbackHeaders, false),\n );\n } else {\n throw error;\n }\n }\n\n res.statusCode = response.status;\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (response.body) {\n readableStreamToNodeStream(response.body).pipe(res);\n } else {\n res.end();\n }\n };\n\n // Duck-type check for Request-like objects (handles polyfilled Request from @hono/node-server)\n function isRequestLike(obj: unknown): obj is Request {\n return (\n obj instanceof Request ||\n (typeof obj === \"object\" &&\n obj !== null &&\n \"url\" in obj &&\n \"method\" in obj &&\n \"headers\" in obj &&\n typeof (obj as any).url === \"string\" &&\n typeof (obj as any).method === \"string\")\n );\n }\n\n return function (\n reqOrRequest: IncomingMessage | Request,\n res?: ServerResponse,\n ): Promise<void> | Promise<Response> | Response {\n if (isRequestLike(reqOrRequest) && !res) {\n return honoApp.fetch(reqOrRequest as Request);\n }\n if (!res) {\n throw new TypeError(\"ServerResponse is required for Node HTTP requests\");\n }\n return handle(reqOrRequest as IncomingMessage, res);\n };\n}\n"],"mappings":";;;;;;;AAqCA,SAAgB,+BACd,SACA;CACA,MAAM,eAAe,gBAAgB,QAAQ;AAE7C,iBAAU,oBAAoB,EAC5B,SAAS,EACP,WAAW,aACZ,EACF,CAAC;AAEF,KAAI,QAAQ,YAAY,YACtB,iBAAU,oBAAoB,EAC5B,aAAa,QAAQ,WAAW,aACjC,CAAC;AAGJ,SAAQ,QAAQ,UAAU,QACxB,gCACA,gCAAgC,QAAQ,CACzC;CAED,MAAM,SAAS,aAAa;AAC5B,QAAO,MAAM,8BAA8B;CAE3C,MAAM,iBAAiB,QAAQ;AAC/B,KAAI,eACF,SAAQ,QAAQ,qBAAqB,eAAe;CAItD,MAAM,UAAU,iCAAiC;EAC/C,SAAS,QAAQ,QAAQ;EACzB,UAAU,QAAQ,WAAW,QAAQ;EACrC,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,MAAM;EAC3C,CAAQ;CAET,MAAM,SAAS,eAAe,QAC5B,KACA,KACA;EACA,MAAM,MAAM,WAAW,IAAI;EAC3B,MAAM,UAAU,IAAI,WAAW,SAAS,IAAI,WAAW;EAEvD,MAAM,cAAc,UAAU,IAAI,QAAQ;EAC1C,MAAM,aAAa,IAAI;EAEvB,MAAM,iBAAiB,iBAAiB,IAAI,IAAI,eAAe;EAC/D,MAAM,YAAY,WAAW,CAAC;EAE9B,IAAI,cAA2C;EAC/C,IAAI,YAAY;AAEhB,MAAI,WAAW,WAAW;AACxB,iBAAc,2BAA2B,IAAI;AAC7C,eAAY;;AAGd,MAAI,WAAW,eACb,KAAI,eAAe,QAAW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,MAAM,aAAwB;AAE/C,MAAI,CAAC,IACH,OAAM,IAAI,UAAU,oDAAoD;AAE1E,SAAO,OAAO,cAAiC,IAAI"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require("reflect-metadata");
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_mcp_client_cache = require('./mcp-client-cache.cjs');
|
|
3
4
|
const require_agui_to_gql = require('../../graphql/message-conversion/agui-to-gql.cjs');
|
|
4
5
|
const require_telemetry_disclosure = require('../telemetry-disclosure.cjs');
|
|
5
6
|
const require_in_memory = require('../../v2/runtime/runner/in-memory.cjs');
|
|
@@ -39,7 +40,6 @@ let _copilotkit_shared = require("@copilotkit/shared");
|
|
|
39
40
|
*/
|
|
40
41
|
var CopilotRuntime = class {
|
|
41
42
|
constructor(params) {
|
|
42
|
-
this.mcpToolsCache = /* @__PURE__ */ new Map();
|
|
43
43
|
require_telemetry_disclosure.logRuntimeTelemetryDisclosure();
|
|
44
44
|
const agents = params?.agents ?? {};
|
|
45
45
|
const endpointAgents = this.assignEndpointsToAgents(params?.remoteEndpoints ?? []);
|
|
@@ -107,29 +107,68 @@ var CopilotRuntime = class {
|
|
|
107
107
|
return result;
|
|
108
108
|
}
|
|
109
109
|
handleServiceAdapter(serviceAdapter) {
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else if (serviceAdapter.provider && serviceAdapter.model) agentsList.default = new require_index.BuiltInAgent({ model: `${serviceAdapter.provider}/${serviceAdapter.model}` });
|
|
120
|
-
else throw new _copilotkit_shared.CopilotKitMisuseError({ message: `Service adapter "${serviceAdapter.name ?? "unknown"}" does not provide model information. When using adapters like LangChainAdapter without an explicit agents list, please provide a default agent in the runtime config. Example:\n new CopilotRuntime({\n agents: { default: new BuiltInAgent({ model: "openai/gpt-4o" }) }\n })` });
|
|
121
|
-
}
|
|
110
|
+
this.configuredAgents ??= this.runtimeArgs.agents ?? {};
|
|
111
|
+
const configuredAgents = this.configuredAgents;
|
|
112
|
+
if (typeof configuredAgents !== "function") {
|
|
113
|
+
this.baseAgents ??= Promise.resolve(configuredAgents).then((agents) => this.ensureDefaultAgent(agents, serviceAdapter));
|
|
114
|
+
this.baseAgents.catch(() => {});
|
|
115
|
+
}
|
|
116
|
+
const resolvePerRequest = async ({ request }) => {
|
|
117
|
+
const baseAgents = typeof configuredAgents === "function" ? this.ensureDefaultAgent({ ...await configuredAgents({ request }) }, serviceAdapter) : await this.baseAgents;
|
|
118
|
+
const properties = await this.readRequestProperties(request);
|
|
122
119
|
const actions = this.params?.actions;
|
|
123
|
-
const mcpTools = await this.getToolsFromMCP();
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
const mcpTools = await this.getToolsFromMCP({ properties });
|
|
121
|
+
const tools = [...actions ? this.getToolsFromActions(actions, {
|
|
122
|
+
properties,
|
|
123
|
+
url: request.url
|
|
124
|
+
}) : [], ...mcpTools];
|
|
125
|
+
if (!tools.length) return baseAgents;
|
|
126
|
+
const perRequestAgents = {};
|
|
127
|
+
for (const [agentId, agent] of Object.entries(baseAgents)) {
|
|
128
|
+
const clone = agent.clone();
|
|
129
|
+
if (Reflect.get(clone, "config") === void 0 && Reflect.get(agent, "config") !== void 0) Reflect.set(clone, "config", Reflect.get(agent, "config"));
|
|
130
|
+
perRequestAgents[agentId] = clone;
|
|
131
|
+
}
|
|
132
|
+
return this.assignToolsToAgents(perRequestAgents, tools);
|
|
133
|
+
};
|
|
134
|
+
this.runtimeArgs.agents = resolvePerRequest;
|
|
128
135
|
}
|
|
129
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Fill in the default agent the service adapter implies, and reject a
|
|
138
|
+
* configuration that names no model at all.
|
|
139
|
+
*/
|
|
140
|
+
ensureDefaultAgent(agentsList, serviceAdapter) {
|
|
141
|
+
const isAgentsListEmpty = !Object.keys(agentsList).length;
|
|
142
|
+
const hasServiceAdapter = Boolean(serviceAdapter);
|
|
143
|
+
const serviceAdapterCanBeUsedForAgent = !["EmptyAdapter"].includes(serviceAdapter.name);
|
|
144
|
+
if (isAgentsListEmpty && (!hasServiceAdapter || !serviceAdapterCanBeUsedForAgent)) throw new _copilotkit_shared.CopilotKitMisuseError({ message: "No default agent provided. Please provide a default agent in the runtime config." });
|
|
145
|
+
if (isAgentsListEmpty) {
|
|
146
|
+
const languageModel = serviceAdapter.getLanguageModel?.();
|
|
147
|
+
if (languageModel) agentsList.default = new require_index.BuiltInAgent({ model: languageModel });
|
|
148
|
+
else if (serviceAdapter.provider && serviceAdapter.model) agentsList.default = new require_index.BuiltInAgent({ model: `${serviceAdapter.provider}/${serviceAdapter.model}` });
|
|
149
|
+
else throw new _copilotkit_shared.CopilotKitMisuseError({ message: `Service adapter "${serviceAdapter.name ?? "unknown"}" does not provide model information. When using adapters like LangChainAdapter without an explicit agents list, please provide a default agent in the runtime config. Example:\n new CopilotRuntime({\n agents: { default: new BuiltInAgent({ model: "openai/gpt-4o" }) }\n })` });
|
|
150
|
+
}
|
|
151
|
+
return agentsList;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The `forwardedProps` the browser sent with this request, which is what a
|
|
155
|
+
* v1 `actions` function and `mcpServers` overrides are documented to read.
|
|
156
|
+
*
|
|
157
|
+
* `readBody` clones, so the handler still gets an unconsumed body, and it
|
|
158
|
+
* returns `undefined` for GET, which is how the `/info` route reaches here.
|
|
159
|
+
*/
|
|
160
|
+
async readRequestProperties(request) {
|
|
161
|
+
try {
|
|
162
|
+
const properties = (await (0, _copilotkit_shared.readBody)(request))?.forwardedProps;
|
|
163
|
+
return properties && typeof properties === "object" ? properties : {};
|
|
164
|
+
} catch {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
getToolsFromActions(actions, ctx) {
|
|
130
169
|
return (typeof actions === "function" ? actions({
|
|
131
|
-
properties:
|
|
132
|
-
url:
|
|
170
|
+
properties: ctx.properties,
|
|
171
|
+
url: ctx.url
|
|
133
172
|
}) : actions).map((action) => {
|
|
134
173
|
const zodSchema = (0, _copilotkit_shared.getZodParameters)(action.parameters || []);
|
|
135
174
|
return {
|
|
@@ -261,27 +300,30 @@ var CopilotRuntime = class {
|
|
|
261
300
|
})();
|
|
262
301
|
const allTools = [];
|
|
263
302
|
for (const config of effectiveEndpoints) {
|
|
264
|
-
const
|
|
265
|
-
const cached = this.mcpToolsCache.get(endpointUrl);
|
|
266
|
-
if (cached) {
|
|
267
|
-
allTools.push(...cached);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
303
|
+
const endpointLabel = require_mcp_client_cache.describeEndpoint(config.endpoint);
|
|
270
304
|
try {
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
const
|
|
305
|
+
const entry = await require_mcp_client_cache.resolveMCPEntry(createMCPClient, config, async () => {
|
|
306
|
+
const client = await createMCPClient(config);
|
|
307
|
+
const toolsMap = await client.tools();
|
|
274
308
|
return {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
309
|
+
client,
|
|
310
|
+
tools: Object.entries(toolsMap).map(([toolName, tool]) => {
|
|
311
|
+
const zodSchema = (0, _copilotkit_shared.getZodParameters)(require_mcp_tools_utils.extractParametersFromSchema(tool));
|
|
312
|
+
return {
|
|
313
|
+
name: toolName,
|
|
314
|
+
description: tool.description || `MCP tool: ${toolName} (from ${endpointLabel})`,
|
|
315
|
+
parameters: zodSchema,
|
|
316
|
+
execute: async (args) => {
|
|
317
|
+
require_mcp_client_cache.touchMCPEntry(createMCPClient, config);
|
|
318
|
+
return tool.execute(args);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
})
|
|
279
322
|
};
|
|
280
323
|
});
|
|
281
|
-
|
|
282
|
-
allTools.push(...toolDefs);
|
|
324
|
+
allTools.push(...entry.tools ?? []);
|
|
283
325
|
} catch (error) {
|
|
284
|
-
console.error(`MCP: Failed to fetch tools from endpoint ${
|
|
326
|
+
console.error(`MCP: Failed to fetch tools from endpoint ${endpointLabel}. Skipping. Error:`, error);
|
|
285
327
|
}
|
|
286
328
|
}
|
|
287
329
|
const dedupedByName = /* @__PURE__ */ new Map();
|