@copilotkit/runtime 1.5.18-next.1 → 1.5.18-next.3

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 (32) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-2NWLEHMA.mjs → chunk-JTTO2AKP.mjs} +70 -24
  3. package/dist/chunk-JTTO2AKP.mjs.map +1 -0
  4. package/dist/{chunk-CJZ7QUXU.mjs → chunk-SHQLPOL4.mjs} +2 -2
  5. package/dist/{chunk-OS4N57XE.mjs → chunk-THWPPRSF.mjs} +2 -2
  6. package/dist/{chunk-326WWZNE.mjs → chunk-V2PWHEPG.mjs} +2 -2
  7. package/dist/index.js +89 -43
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +4 -4
  10. package/dist/lib/index.js +89 -43
  11. package/dist/lib/index.js.map +1 -1
  12. package/dist/lib/index.mjs +4 -4
  13. package/dist/lib/integrations/index.js +1 -1
  14. package/dist/lib/integrations/index.js.map +1 -1
  15. package/dist/lib/integrations/index.mjs +4 -4
  16. package/dist/lib/integrations/nest/index.js +1 -1
  17. package/dist/lib/integrations/nest/index.js.map +1 -1
  18. package/dist/lib/integrations/nest/index.mjs +2 -2
  19. package/dist/lib/integrations/node-express/index.js +1 -1
  20. package/dist/lib/integrations/node-express/index.js.map +1 -1
  21. package/dist/lib/integrations/node-express/index.mjs +2 -2
  22. package/dist/lib/integrations/node-http/index.js +1 -1
  23. package/dist/lib/integrations/node-http/index.js.map +1 -1
  24. package/dist/lib/integrations/node-http/index.mjs +1 -1
  25. package/package.json +2 -2
  26. package/src/lib/runtime/copilot-runtime.ts +33 -13
  27. package/src/lib/runtime/remote-action-constructors.ts +17 -2
  28. package/src/lib/runtime/remote-actions.ts +5 -1
  29. package/dist/chunk-2NWLEHMA.mjs.map +0 -1
  30. /package/dist/{chunk-CJZ7QUXU.mjs.map → chunk-SHQLPOL4.mjs.map} +0 -0
  31. /package/dist/{chunk-OS4N57XE.mjs.map → chunk-THWPPRSF.mjs.map} +0 -0
  32. /package/dist/{chunk-326WWZNE.mjs.map → chunk-V2PWHEPG.mjs.map} +0 -0
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-2NWLEHMA.mjs";
5
+ } from "./chunk-JTTO2AKP.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
22
22
  export {
23
23
  copilotRuntimeNestEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-CJZ7QUXU.mjs.map
25
+ //# sourceMappingURL=chunk-SHQLPOL4.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-2NWLEHMA.mjs";
5
+ } from "./chunk-JTTO2AKP.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
22
22
  export {
23
23
  copilotRuntimeNodeExpressEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-OS4N57XE.mjs.map
25
+ //# sourceMappingURL=chunk-THWPPRSF.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  getCommonConfig,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-2NWLEHMA.mjs";
5
+ } from "./chunk-JTTO2AKP.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -77,4 +77,4 @@ export {
77
77
  config,
78
78
  copilotRuntimeNextJSPagesRouterEndpoint
79
79
  };
80
- //# sourceMappingURL=chunk-326WWZNE.mjs.map
80
+ //# sourceMappingURL=chunk-V2PWHEPG.mjs.map
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.18-next.1",
47
+ version: "1.5.18-next.3",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -158,7 +158,7 @@ module.exports = __toCommonJS(src_exports);
158
158
  var import_reflect_metadata = require("reflect-metadata");
159
159
 
160
160
  // src/lib/runtime/copilot-runtime.ts
161
- var import_shared15 = require("@copilotkit/shared");
161
+ var import_shared16 = require("@copilotkit/shared");
162
162
 
163
163
  // src/service-adapters/langchain/langserve.ts
164
164
  var import_remote = require("langchain/runnables/remote");
@@ -1564,11 +1564,11 @@ __name(EmptyAdapter, "EmptyAdapter");
1564
1564
  var ExperimentalEmptyAdapter = EmptyAdapter;
1565
1565
 
1566
1566
  // src/service-adapters/events.ts
1567
- var import_shared14 = require("@copilotkit/shared");
1567
+ var import_shared15 = require("@copilotkit/shared");
1568
1568
  var import_rxjs2 = require("rxjs");
1569
1569
 
1570
1570
  // src/lib/telemetry-client.ts
1571
- var import_shared13 = require("@copilotkit/shared");
1571
+ var import_shared14 = require("@copilotkit/shared");
1572
1572
 
1573
1573
  // src/lib/runtime/remote-action-constructors.ts
1574
1574
  var import_node_crypto2 = require("crypto");
@@ -2987,6 +2987,7 @@ __name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
2987
2987
 
2988
2988
  // src/lib/runtime/remote-action-constructors.ts
2989
2989
  var import_shared11 = require("@copilotkit/shared");
2990
+ var import_shared12 = require("@copilotkit/shared");
2990
2991
  function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
2991
2992
  const agents = endpoint.agents.map((agent) => ({
2992
2993
  name: agent.name,
@@ -3087,7 +3088,16 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
3087
3088
  status: response.status,
3088
3089
  body: await response.text()
3089
3090
  }, "Failed to execute remote action");
3090
- return "Failed to execute remote action";
3091
+ if (response.status === 404) {
3092
+ throw new import_shared12.CopilotKitApiDiscoveryError({
3093
+ url: fetchUrl
3094
+ });
3095
+ }
3096
+ throw new import_shared12.ResolvedCopilotKitError({
3097
+ status: response.status,
3098
+ url: fetchUrl,
3099
+ isRemoteEndpoint: true
3100
+ });
3091
3101
  }
3092
3102
  const requestResult = await response.json();
3093
3103
  const result = requestResult["result"];
@@ -3160,7 +3170,16 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
3160
3170
  status: response.status,
3161
3171
  body: await response.text()
3162
3172
  }, "Failed to execute remote agent");
3163
- throw new Error("Failed to execute remote agent");
3173
+ if (response.status === 404) {
3174
+ throw new import_shared12.CopilotKitApiDiscoveryError({
3175
+ url: fetchUrl
3176
+ });
3177
+ }
3178
+ throw new import_shared12.ResolvedCopilotKitError({
3179
+ status: response.status,
3180
+ url: fetchUrl,
3181
+ isRemoteEndpoint: true
3182
+ });
3164
3183
  }
3165
3184
  const eventSource = new RemoteLangGraphEventSource();
3166
3185
  streamResponse(response.body, eventSource.eventStream$);
@@ -3243,7 +3262,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
3243
3262
  __name(createHeaders, "createHeaders");
3244
3263
 
3245
3264
  // src/lib/runtime/remote-actions.ts
3246
- var import_shared12 = require("@copilotkit/shared");
3265
+ var import_shared13 = require("@copilotkit/shared");
3247
3266
  var EndpointType;
3248
3267
  (function(EndpointType2) {
3249
3268
  EndpointType2["CopilotKit"] = "copilotKit";
@@ -3277,8 +3296,9 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
3277
3296
  status: response.status,
3278
3297
  body: await response.text()
3279
3298
  }, "Failed to fetch actions from url");
3280
- throw new import_shared12.ResolvedCopilotKitError({
3299
+ throw new import_shared13.ResolvedCopilotKitError({
3281
3300
  status: response.status,
3301
+ url: fetchUrl,
3282
3302
  isRemoteEndpoint: true
3283
3303
  });
3284
3304
  }
@@ -3288,10 +3308,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
3288
3308
  }, "Fetched actions from url");
3289
3309
  return json;
3290
3310
  } catch (error) {
3291
- if (error instanceof import_shared12.CopilotKitError) {
3311
+ if (error instanceof import_shared13.CopilotKitError) {
3292
3312
  throw error;
3293
3313
  }
3294
- throw new import_shared12.CopilotKitLowLevelError({
3314
+ throw new import_shared13.CopilotKitLowLevelError({
3295
3315
  error,
3296
3316
  url: fetchUrl
3297
3317
  });
@@ -3354,7 +3374,7 @@ __name(setupRemoteActions, "setupRemoteActions");
3354
3374
  // src/lib/telemetry-client.ts
3355
3375
  var import_node_crypto3 = require("crypto");
3356
3376
  var packageJson = require_package();
3357
- var telemetryClient = new import_shared13.TelemetryClient({
3377
+ var telemetryClient = new import_shared14.TelemetryClient({
3358
3378
  packageName: packageJson.name,
3359
3379
  packageVersion: packageJson.version
3360
3380
  });
@@ -3671,10 +3691,10 @@ var RuntimeEventSource = class {
3671
3691
  const errorMessage = `\u274C ${message}`;
3672
3692
  if (!this.callback) {
3673
3693
  this.stream(async (eventStream$) => {
3674
- eventStream$.sendTextMessage((0, import_shared14.randomId)(), errorMessage);
3694
+ eventStream$.sendTextMessage((0, import_shared15.randomId)(), errorMessage);
3675
3695
  });
3676
3696
  } else {
3677
- this.eventStream$.sendTextMessage((0, import_shared14.randomId)(), errorMessage);
3697
+ this.eventStream$.sendTextMessage((0, import_shared15.randomId)(), errorMessage);
3678
3698
  }
3679
3699
  }
3680
3700
  processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
@@ -3910,7 +3930,7 @@ var CopilotRuntime = class {
3910
3930
  return await this.processAgentRequest(request);
3911
3931
  }
3912
3932
  if (serviceAdapter instanceof EmptyAdapter) {
3913
- throw new import_shared15.CopilotKitMisuseError({
3933
+ throw new import_shared16.CopilotKitMisuseError({
3914
3934
  message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
3915
3935
  For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
3916
3936
  please use an LLM adapter instead.`
@@ -3922,7 +3942,7 @@ please use an LLM adapter instead.`
3922
3942
  const serverSideActionsInput = serverSideActions.map((action) => ({
3923
3943
  name: action.name,
3924
3944
  description: action.description,
3925
- jsonSchema: JSON.stringify((0, import_shared15.actionParametersToJsonSchema)(action.parameters))
3945
+ jsonSchema: JSON.stringify((0, import_shared16.actionParametersToJsonSchema)(action.parameters))
3926
3946
  }));
3927
3947
  const actionInputs = flattenToolCallsNoDuplicates([
3928
3948
  ...serverSideActionsInput,
@@ -3974,7 +3994,7 @@ please use an LLM adapter instead.`
3974
3994
  extensions: result.extensions
3975
3995
  };
3976
3996
  } catch (error) {
3977
- if (error instanceof import_shared15.CopilotKitError) {
3997
+ if (error instanceof import_shared16.CopilotKitError) {
3978
3998
  throw error;
3979
3999
  }
3980
4000
  console.error("Error getting response:", error);
@@ -4020,10 +4040,13 @@ please use an LLM adapter instead.`
4020
4040
  });
4021
4041
  if (!response.ok) {
4022
4042
  if (response.status === 404) {
4023
- throw new import_shared15.CopilotKitApiDiscoveryError();
4043
+ throw new import_shared16.CopilotKitApiDiscoveryError({
4044
+ url: fetchUrl
4045
+ });
4024
4046
  }
4025
- throw new import_shared15.ResolvedCopilotKitError({
4047
+ throw new import_shared16.ResolvedCopilotKitError({
4026
4048
  status: response.status,
4049
+ url: fetchUrl,
4027
4050
  isRemoteEndpoint: true
4028
4051
  });
4029
4052
  }
@@ -4031,7 +4054,7 @@ please use an LLM adapter instead.`
4031
4054
  const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
4032
4055
  name: agent.name,
4033
4056
  description: agent.description ?? "" ?? "",
4034
- id: (0, import_shared15.randomId)(),
4057
+ id: (0, import_shared16.randomId)(),
4035
4058
  endpoint
4036
4059
  }));
4037
4060
  return [
@@ -4039,10 +4062,10 @@ please use an LLM adapter instead.`
4039
4062
  ...endpointAgents
4040
4063
  ];
4041
4064
  } catch (error) {
4042
- if (error instanceof import_shared15.CopilotKitError) {
4065
+ if (error instanceof import_shared16.CopilotKitError) {
4043
4066
  throw error;
4044
4067
  }
4045
- throw new import_shared15.CopilotKitLowLevelError({
4068
+ throw new import_shared16.CopilotKitLowLevelError({
4046
4069
  error,
4047
4070
  url: fetchUrl
4048
4071
  });
@@ -4091,21 +4114,44 @@ please use an LLM adapter instead.`
4091
4114
  };
4092
4115
  }
4093
4116
  } else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
4094
- const response = await fetch(`${agentWithEndpoint.endpoint.url}/agents/state`, {
4095
- method: "POST",
4096
- headers,
4097
- body: JSON.stringify({
4098
- properties: graphqlContext.properties,
4099
- threadId,
4100
- name: agentName
4101
- })
4102
- });
4103
- const data = await response.json();
4104
- return {
4105
- ...data,
4106
- state: JSON.stringify(data.state),
4107
- messages: JSON.stringify(data.messages)
4108
- };
4117
+ const fetchUrl = `${agentWithEndpoint.endpoint.url}/agents/state`;
4118
+ try {
4119
+ const response = await fetch(fetchUrl, {
4120
+ method: "POST",
4121
+ headers,
4122
+ body: JSON.stringify({
4123
+ properties: graphqlContext.properties,
4124
+ threadId,
4125
+ name: agentName
4126
+ })
4127
+ });
4128
+ if (!response.ok) {
4129
+ if (response.status === 404) {
4130
+ throw new import_shared16.CopilotKitApiDiscoveryError({
4131
+ url: fetchUrl
4132
+ });
4133
+ }
4134
+ throw new import_shared16.ResolvedCopilotKitError({
4135
+ status: response.status,
4136
+ url: fetchUrl,
4137
+ isRemoteEndpoint: true
4138
+ });
4139
+ }
4140
+ const data = await response.json();
4141
+ return {
4142
+ ...data,
4143
+ state: JSON.stringify(data.state),
4144
+ messages: JSON.stringify(data.messages)
4145
+ };
4146
+ } catch (error) {
4147
+ if (error instanceof import_shared16.CopilotKitError) {
4148
+ throw error;
4149
+ }
4150
+ throw new import_shared16.CopilotKitLowLevelError({
4151
+ error,
4152
+ url: fetchUrl
4153
+ });
4154
+ }
4109
4155
  } else {
4110
4156
  throw new Error(`Unknown endpoint type: ${agentWithEndpoint.endpoint.type}`);
4111
4157
  }
@@ -4119,7 +4165,7 @@ please use an LLM adapter instead.`
4119
4165
  const messages = convertGqlInputToMessages(rawMessages);
4120
4166
  const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
4121
4167
  if (!currentAgent) {
4122
- throw new import_shared15.CopilotKitAgentDiscoveryError({
4168
+ throw new import_shared16.CopilotKitAgentDiscoveryError({
4123
4169
  agentName
4124
4170
  });
4125
4171
  }
@@ -4130,7 +4176,7 @@ please use an LLM adapter instead.`
4130
4176
  )).map((action) => ({
4131
4177
  name: action.name,
4132
4178
  description: action.description,
4133
- jsonSchema: JSON.stringify((0, import_shared15.actionParametersToJsonSchema)(action.parameters))
4179
+ jsonSchema: JSON.stringify((0, import_shared16.actionParametersToJsonSchema)(action.parameters))
4134
4180
  }));
4135
4181
  const allAvailableActions = flattenToolCallsNoDuplicates([
4136
4182
  ...availableActionsForCurrentAgent,
@@ -5048,7 +5094,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
5048
5094
  __name(UnknownErrorResponse, "UnknownErrorResponse");
5049
5095
 
5050
5096
  // src/graphql/resolvers/copilot.resolver.ts
5051
- var import_shared16 = require("@copilotkit/shared");
5097
+ var import_shared17 = require("@copilotkit/shared");
5052
5098
 
5053
5099
  // src/graphql/types/agents-response.type.ts
5054
5100
  var import_type_graphql19 = require("type-graphql");
@@ -5231,7 +5277,7 @@ var CopilotResolver = class {
5231
5277
  rejectOutputMessagesPromise = reject;
5232
5278
  });
5233
5279
  logger2.debug("Processing");
5234
- const { eventSource, threadId = (0, import_shared16.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
5280
+ const { eventSource, threadId = (0, import_shared17.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
5235
5281
  serviceAdapter,
5236
5282
  messages: data.messages,
5237
5283
  actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
@@ -5364,7 +5410,7 @@ var CopilotResolver = class {
5364
5410
  });
5365
5411
  outputMessages = [
5366
5412
  (0, import_class_transformer3.plainToInstance)(TextMessage, {
5367
- id: (0, import_shared16.randomId)(),
5413
+ id: (0, import_shared17.randomId)(),
5368
5414
  createdAt: /* @__PURE__ */ new Date(),
5369
5415
  content: result.reason,
5370
5416
  role: MessageRole.assistant
@@ -5542,7 +5588,7 @@ var CopilotResolver = class {
5542
5588
  event
5543
5589
  }, "Agent message event received");
5544
5590
  pushMessage({
5545
- id: (0, import_shared16.randomId)(),
5591
+ id: (0, import_shared17.randomId)(),
5546
5592
  status: new SuccessMessageStatus(),
5547
5593
  threadId: event.threadId,
5548
5594
  agentName: event.agentName,
@@ -5555,7 +5601,7 @@ var CopilotResolver = class {
5555
5601
  createdAt: /* @__PURE__ */ new Date()
5556
5602
  });
5557
5603
  outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
5558
- id: (0, import_shared16.randomId)(),
5604
+ id: (0, import_shared17.randomId)(),
5559
5605
  threadId: event.threadId,
5560
5606
  agentName: event.agentName,
5561
5607
  nodeName: event.nodeName,