@copilotkit/runtime 1.5.12-next.5 → 1.5.12-next.6

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{chunk-QDMAQO2C.mjs → chunk-BKIGYRXE.mjs} +2 -2
  3. package/dist/{chunk-MFDRA3BJ.mjs → chunk-ON4AESON.mjs} +125 -77
  4. package/dist/chunk-ON4AESON.mjs.map +1 -0
  5. package/dist/{chunk-NORCONUM.mjs → chunk-XM2VJFL6.mjs} +2 -2
  6. package/dist/{chunk-XRW7ZSWJ.mjs → chunk-YGXAWYRB.mjs} +2 -2
  7. package/dist/{copilot-runtime-1a224a0f.d.ts → copilot-runtime-da917bd5.d.ts} +3 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +136 -88
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +4 -4
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +136 -88
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/index.mjs +4 -4
  16. package/dist/lib/integrations/index.d.ts +2 -2
  17. package/dist/lib/integrations/index.js +12 -10
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +4 -4
  20. package/dist/lib/integrations/nest/index.d.ts +1 -1
  21. package/dist/lib/integrations/nest/index.js +12 -10
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +2 -2
  24. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  25. package/dist/lib/integrations/node-express/index.js +12 -10
  26. package/dist/lib/integrations/node-express/index.js.map +1 -1
  27. package/dist/lib/integrations/node-express/index.mjs +2 -2
  28. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  29. package/dist/lib/integrations/node-http/index.js +12 -10
  30. package/dist/lib/integrations/node-http/index.js.map +1 -1
  31. package/dist/lib/integrations/node-http/index.mjs +1 -1
  32. package/package.json +2 -2
  33. package/src/lib/runtime/copilot-runtime.ts +61 -27
  34. package/src/lib/runtime/remote-action-constructors.ts +42 -33
  35. package/src/lib/runtime/remote-actions.ts +12 -7
  36. package/dist/chunk-MFDRA3BJ.mjs.map +0 -1
  37. /package/dist/{chunk-QDMAQO2C.mjs.map → chunk-BKIGYRXE.mjs.map} +0 -0
  38. /package/dist/{chunk-NORCONUM.mjs.map → chunk-XM2VJFL6.mjs.map} +0 -0
  39. /package/dist/{chunk-XRW7ZSWJ.mjs.map → chunk-YGXAWYRB.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.5.12-next.5",
47
+ version: "1.5.12-next.6",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -157,7 +157,8 @@ module.exports = __toCommonJS(src_exports);
157
157
  var import_reflect_metadata = require("reflect-metadata");
158
158
 
159
159
  // src/lib/runtime/copilot-runtime.ts
160
- var import_shared12 = require("@copilotkit/shared");
160
+ var import_shared14 = require("@copilotkit/shared");
161
+ var import_langgraph_sdk2 = require("@langchain/langgraph-sdk");
161
162
 
162
163
  // src/service-adapters/langchain/langserve.ts
163
164
  var import_remote = require("langchain/runnables/remote");
@@ -1551,11 +1552,11 @@ __name(EmptyAdapter, "EmptyAdapter");
1551
1552
  var ExperimentalEmptyAdapter = EmptyAdapter;
1552
1553
 
1553
1554
  // src/service-adapters/events.ts
1554
- var import_shared11 = require("@copilotkit/shared");
1555
+ var import_shared13 = require("@copilotkit/shared");
1555
1556
  var import_rxjs2 = require("rxjs");
1556
1557
 
1557
1558
  // src/lib/telemetry-client.ts
1558
- var import_shared10 = require("@copilotkit/shared");
1559
+ var import_shared12 = require("@copilotkit/shared");
1559
1560
 
1560
1561
  // src/lib/runtime/remote-action-constructors.ts
1561
1562
  var import_node_crypto2 = require("crypto");
@@ -2305,6 +2306,7 @@ function copilotkitMessagesToLangChain(messages) {
2305
2306
  __name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
2306
2307
 
2307
2308
  // src/lib/runtime/remote-action-constructors.ts
2309
+ var import_shared10 = require("@copilotkit/shared");
2308
2310
  function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
2309
2311
  const agents = endpoint.agents.map((agent) => ({
2310
2312
  name: agent.name,
@@ -2385,8 +2387,9 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2385
2387
  type: "self-hosted",
2386
2388
  agentsAmount: totalAgents
2387
2389
  });
2390
+ const fetchUrl = `${url}/actions/execute`;
2388
2391
  try {
2389
- const response = await fetch(`${url}/actions/execute`, {
2392
+ const response = await fetch(fetchUrl, {
2390
2393
  method: "POST",
2391
2394
  headers,
2392
2395
  body: JSON.stringify({
@@ -2411,10 +2414,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2411
2414
  }, "Executed remote action");
2412
2415
  return result;
2413
2416
  } catch (error) {
2414
- logger2.error({
2415
- error: error.message ? error.message : error + ""
2416
- }, "Failed to execute remote action");
2417
- return "Failed to execute remote action";
2417
+ if (error instanceof import_shared10.CopilotKitError) {
2418
+ throw error;
2419
+ }
2420
+ throw new import_shared10.CopilotKitLowLevelError({
2421
+ error,
2422
+ url: fetchUrl
2423
+ });
2418
2424
  }
2419
2425
  }
2420
2426
  }));
@@ -2442,37 +2448,48 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2442
2448
  state = JSON.parse(jsonState);
2443
2449
  }
2444
2450
  }
2445
- const response = await fetch(`${url}/agents/execute`, {
2446
- method: "POST",
2447
- headers,
2448
- body: JSON.stringify({
2449
- name,
2450
- threadId,
2451
- nodeName,
2452
- messages: [
2453
- ...messages,
2454
- ...additionalMessages
2455
- ],
2456
- state,
2457
- properties: graphqlContext.properties,
2458
- actions: actionInputsWithoutAgents.map((action) => ({
2459
- name: action.name,
2460
- description: action.description,
2461
- parameters: JSON.parse(action.jsonSchema)
2462
- }))
2463
- })
2464
- });
2465
- if (!response.ok) {
2466
- logger2.error({
2467
- url,
2468
- status: response.status,
2469
- body: await response.text()
2470
- }, "Failed to execute remote agent");
2471
- throw new Error("Failed to execute remote agent");
2451
+ const fetchUrl = `${url}/agents/execute`;
2452
+ try {
2453
+ const response = await fetch(fetchUrl, {
2454
+ method: "POST",
2455
+ headers,
2456
+ body: JSON.stringify({
2457
+ name,
2458
+ threadId,
2459
+ nodeName,
2460
+ messages: [
2461
+ ...messages,
2462
+ ...additionalMessages
2463
+ ],
2464
+ state,
2465
+ properties: graphqlContext.properties,
2466
+ actions: actionInputsWithoutAgents.map((action) => ({
2467
+ name: action.name,
2468
+ description: action.description,
2469
+ parameters: JSON.parse(action.jsonSchema)
2470
+ }))
2471
+ })
2472
+ });
2473
+ if (!response.ok) {
2474
+ logger2.error({
2475
+ url,
2476
+ status: response.status,
2477
+ body: await response.text()
2478
+ }, "Failed to execute remote agent");
2479
+ throw new Error("Failed to execute remote agent");
2480
+ }
2481
+ const eventSource = new RemoteLangGraphEventSource();
2482
+ streamResponse(response.body, eventSource.eventStream$);
2483
+ return eventSource.processLangGraphEvents();
2484
+ } catch (error) {
2485
+ if (error instanceof import_shared10.CopilotKitError) {
2486
+ throw error;
2487
+ }
2488
+ throw new import_shared10.CopilotKitLowLevelError({
2489
+ error,
2490
+ url: fetchUrl
2491
+ });
2472
2492
  }
2473
- const eventSource = new RemoteLangGraphEventSource();
2474
- streamResponse(response.body, eventSource.eventStream$);
2475
- return eventSource.processLangGraphEvents();
2476
2493
  }
2477
2494
  })) : [];
2478
2495
  return [
@@ -2542,6 +2559,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
2542
2559
  __name(createHeaders, "createHeaders");
2543
2560
 
2544
2561
  // src/lib/runtime/remote-actions.ts
2562
+ var import_shared11 = require("@copilotkit/shared");
2545
2563
  var EndpointType;
2546
2564
  (function(EndpointType2) {
2547
2565
  EndpointType2["CopilotKit"] = "copilotKit";
@@ -2559,8 +2577,9 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
2559
2577
  url
2560
2578
  }, "Fetching actions from url");
2561
2579
  const headers = createHeaders(onBeforeRequest, graphqlContext);
2580
+ const fetchUrl = `${url}/info`;
2562
2581
  try {
2563
- const response = await fetch(`${url}/info`, {
2582
+ const response = await fetch(fetchUrl, {
2564
2583
  method: "POST",
2565
2584
  headers,
2566
2585
  body: JSON.stringify({
@@ -2574,10 +2593,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
2574
2593
  status: response.status,
2575
2594
  body: await response.text()
2576
2595
  }, "Failed to fetch actions from url");
2577
- return {
2578
- actions: [],
2579
- agents: []
2580
- };
2596
+ throw new import_shared11.ResolvedCopilotKitError({
2597
+ status: response.status,
2598
+ isRemoteEndpoint: true
2599
+ });
2581
2600
  }
2582
2601
  const json = await response.json();
2583
2602
  logger2.debug({
@@ -2585,13 +2604,13 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
2585
2604
  }, "Fetched actions from url");
2586
2605
  return json;
2587
2606
  } catch (error) {
2588
- logger2.error({
2589
- error: error.message ? error.message : error + ""
2590
- }, "Failed to fetch actions from url");
2591
- return {
2592
- actions: [],
2593
- agents: []
2594
- };
2607
+ if (error instanceof import_shared11.CopilotKitError) {
2608
+ throw error;
2609
+ }
2610
+ throw new import_shared11.CopilotKitLowLevelError({
2611
+ error,
2612
+ url: fetchUrl
2613
+ });
2595
2614
  }
2596
2615
  }
2597
2616
  __name(fetchRemoteInfo, "fetchRemoteInfo");
@@ -2651,7 +2670,7 @@ __name(setupRemoteActions, "setupRemoteActions");
2651
2670
  // src/lib/telemetry-client.ts
2652
2671
  var import_node_crypto3 = require("crypto");
2653
2672
  var packageJson = require_package();
2654
- var telemetryClient = new import_shared10.TelemetryClient({
2673
+ var telemetryClient = new import_shared12.TelemetryClient({
2655
2674
  packageName: packageJson.name,
2656
2675
  packageVersion: packageJson.version
2657
2676
  });
@@ -2961,10 +2980,10 @@ var RuntimeEventSource = class {
2961
2980
  const errorMessage = `\u274C ${message}`;
2962
2981
  if (!this.callback) {
2963
2982
  this.stream(async (eventStream$) => {
2964
- eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
2983
+ eventStream$.sendTextMessage((0, import_shared13.randomId)(), errorMessage);
2965
2984
  });
2966
2985
  } else {
2967
- this.eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
2986
+ this.eventStream$.sendTextMessage((0, import_shared13.randomId)(), errorMessage);
2968
2987
  }
2969
2988
  }
2970
2989
  processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
@@ -3196,9 +3215,11 @@ var CopilotRuntime = class {
3196
3215
  return await this.processAgentRequest(request);
3197
3216
  }
3198
3217
  if (serviceAdapter instanceof EmptyAdapter) {
3199
- throw new Error(`Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
3218
+ throw new import_shared14.CopilotKitMisuseError({
3219
+ message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
3200
3220
  For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
3201
- please use an LLM adapter instead.`);
3221
+ please use an LLM adapter instead.`
3222
+ });
3202
3223
  }
3203
3224
  const messages = rawMessages.filter((message) => !message.agentStateMessage);
3204
3225
  const inputMessages = convertGqlInputToMessages(messages);
@@ -3206,7 +3227,7 @@ please use an LLM adapter instead.`);
3206
3227
  const serverSideActionsInput = serverSideActions.map((action) => ({
3207
3228
  name: action.name,
3208
3229
  description: action.description,
3209
- jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
3230
+ jsonSchema: JSON.stringify((0, import_shared14.actionParametersToJsonSchema)(action.parameters))
3210
3231
  }));
3211
3232
  const actionInputs = flattenToolCallsNoDuplicates([
3212
3233
  ...serverSideActionsInput,
@@ -3253,6 +3274,9 @@ please use an LLM adapter instead.`);
3253
3274
  ))
3254
3275
  };
3255
3276
  } catch (error) {
3277
+ if (error instanceof import_shared14.CopilotKitError) {
3278
+ throw error;
3279
+ }
3256
3280
  console.error("Error getting response:", error);
3257
3281
  eventSource.sendErrorMessageToChat();
3258
3282
  throw error;
@@ -3263,37 +3287,59 @@ please use an LLM adapter instead.`);
3263
3287
  const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
3264
3288
  const agents2 = await acc;
3265
3289
  if (endpoint.type === EndpointType.LangGraphPlatform) {
3266
- const response2 = await fetch(`${endpoint.deploymentUrl}/assistants/search`, {
3267
- method: "POST",
3268
- headers
3290
+ const client = new import_langgraph_sdk2.Client({
3291
+ apiUrl: endpoint.deploymentUrl,
3292
+ apiKey: endpoint.langsmithApiKey
3269
3293
  });
3270
- const data2 = await response2.json();
3271
- const endpointAgents2 = (data2 ?? []).map((entry) => ({
3294
+ const data = await client.assistants.search();
3295
+ const endpointAgents = (data ?? []).map((entry) => ({
3272
3296
  name: entry.graph_id,
3273
- id: entry.assistant_id
3297
+ id: entry.assistant_id,
3298
+ description: "",
3299
+ endpoint
3274
3300
  }));
3275
3301
  return [
3276
3302
  ...agents2,
3277
- ...endpointAgents2
3303
+ ...endpointAgents
3278
3304
  ];
3279
3305
  }
3280
- const response = await fetch(`${endpoint.url}/info`, {
3281
- method: "POST",
3282
- headers,
3283
- body: JSON.stringify({
3284
- properties: graphqlContext.properties
3285
- })
3286
- });
3287
- const data = await response.json();
3288
- const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
3289
- name: agent.name,
3290
- description: agent.description,
3291
- id: (0, import_shared12.randomId)()
3292
- }));
3293
- return [
3294
- ...agents2,
3295
- ...endpointAgents
3296
- ];
3306
+ const fetchUrl = `${endpoint.url}/info`;
3307
+ try {
3308
+ const response = await fetch(fetchUrl, {
3309
+ method: "POST",
3310
+ headers,
3311
+ body: JSON.stringify({
3312
+ properties: graphqlContext.properties
3313
+ })
3314
+ });
3315
+ if (!response.ok) {
3316
+ if (response.status === 404) {
3317
+ throw new import_shared14.CopilotKitApiDiscoveryError();
3318
+ }
3319
+ throw new import_shared14.ResolvedCopilotKitError({
3320
+ status: response.status,
3321
+ isRemoteEndpoint: true
3322
+ });
3323
+ }
3324
+ const data = await response.json();
3325
+ const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
3326
+ name: agent.name,
3327
+ description: agent.description ?? "",
3328
+ id: (0, import_shared14.randomId)()
3329
+ }));
3330
+ return [
3331
+ ...agents2,
3332
+ ...endpointAgents
3333
+ ];
3334
+ } catch (error) {
3335
+ if (error instanceof import_shared14.CopilotKitError) {
3336
+ throw error;
3337
+ }
3338
+ throw new import_shared14.CopilotKitLowLevelError({
3339
+ error,
3340
+ url: fetchUrl
3341
+ });
3342
+ }
3297
3343
  }, Promise.resolve([]));
3298
3344
  return agents;
3299
3345
  }
@@ -3305,12 +3351,14 @@ please use an LLM adapter instead.`);
3305
3351
  const messages = convertGqlInputToMessages(rawMessages);
3306
3352
  const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
3307
3353
  if (!agent) {
3308
- throw new Error(`Agent ${agentName} not found`);
3354
+ throw new import_shared14.CopilotKitAgentDiscoveryError({
3355
+ agentName
3356
+ });
3309
3357
  }
3310
3358
  const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
3311
3359
  name: action.name,
3312
3360
  description: action.description,
3313
- jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
3361
+ jsonSchema: JSON.stringify((0, import_shared14.actionParametersToJsonSchema)(action.parameters))
3314
3362
  }));
3315
3363
  const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
3316
3364
  ...serverSideActionsInput,
@@ -4504,7 +4552,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
4504
4552
  __name(UnknownErrorResponse, "UnknownErrorResponse");
4505
4553
 
4506
4554
  // src/graphql/resolvers/copilot.resolver.ts
4507
- var import_shared13 = require("@copilotkit/shared");
4555
+ var import_shared15 = require("@copilotkit/shared");
4508
4556
 
4509
4557
  // src/graphql/types/agents-response.type.ts
4510
4558
  var import_type_graphql15 = require("type-graphql");
@@ -4687,7 +4735,7 @@ var CopilotResolver = class {
4687
4735
  rejectOutputMessagesPromise = reject;
4688
4736
  });
4689
4737
  logger2.debug("Processing");
4690
- const { eventSource, threadId = (0, import_shared13.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
4738
+ const { eventSource, threadId = (0, import_shared15.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
4691
4739
  serviceAdapter,
4692
4740
  messages: data.messages,
4693
4741
  actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
@@ -4732,7 +4780,7 @@ var CopilotResolver = class {
4732
4780
  });
4733
4781
  outputMessages = [
4734
4782
  (0, import_class_transformer3.plainToInstance)(TextMessage, {
4735
- id: (0, import_shared13.randomId)(),
4783
+ id: (0, import_shared15.randomId)(),
4736
4784
  createdAt: /* @__PURE__ */ new Date(),
4737
4785
  content: result.reason,
4738
4786
  role: MessageRole.assistant
@@ -4923,7 +4971,7 @@ var CopilotResolver = class {
4923
4971
  event
4924
4972
  }, "Agent message event received");
4925
4973
  pushMessage({
4926
- id: (0, import_shared13.randomId)(),
4974
+ id: (0, import_shared15.randomId)(),
4927
4975
  status: new SuccessMessageStatus(),
4928
4976
  threadId: event.threadId,
4929
4977
  agentName: event.agentName,
@@ -4936,7 +4984,7 @@ var CopilotResolver = class {
4936
4984
  createdAt: /* @__PURE__ */ new Date()
4937
4985
  });
4938
4986
  outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
4939
- id: (0, import_shared13.randomId)(),
4987
+ id: (0, import_shared15.randomId)(),
4940
4988
  threadId: event.threadId,
4941
4989
  agentName: event.agentName,
4942
4990
  nodeName: event.nodeName,