@copilotkit/runtime 1.5.11 → 1.5.12-next.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/{chunk-A6VFRI4R.mjs → chunk-GOA7HNXW.mjs} +2 -2
  3. package/dist/chunk-HNUNXFTW.mjs +129 -0
  4. package/dist/chunk-HNUNXFTW.mjs.map +1 -0
  5. package/dist/{chunk-IJASJOA2.mjs → chunk-NTSKJEJQ.mjs} +2 -2
  6. package/dist/{chunk-QIJT75EM.mjs → chunk-P34QEPO5.mjs} +61 -19
  7. package/dist/chunk-P34QEPO5.mjs.map +1 -0
  8. package/dist/{chunk-OKJI7OJY.mjs → chunk-ZF34MJL7.mjs} +2 -2
  9. package/dist/{copilot-runtime-36700e00.d.ts → copilot-runtime-1a224a0f.d.ts} +2 -2
  10. package/dist/graphql/types/converted/index.d.ts +1 -1
  11. package/dist/graphql/types/converted/index.js +63 -0
  12. package/dist/graphql/types/converted/index.js.map +1 -1
  13. package/dist/graphql/types/converted/index.mjs +1 -1
  14. package/dist/{groq-adapter-696b5d29.d.ts → groq-adapter-c35c5374.d.ts} +1 -1
  15. package/dist/{index-cc2b17be.d.ts → index-24315d90.d.ts} +16 -0
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +121 -16
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +5 -5
  20. package/dist/{langserve-9125a12e.d.ts → langserve-a16ef8f4.d.ts} +7 -3
  21. package/dist/lib/index.d.ts +4 -4
  22. package/dist/lib/index.js +121 -16
  23. package/dist/lib/index.js.map +1 -1
  24. package/dist/lib/index.mjs +5 -5
  25. package/dist/lib/integrations/index.d.ts +4 -4
  26. package/dist/lib/integrations/index.js +64 -1
  27. package/dist/lib/integrations/index.js.map +1 -1
  28. package/dist/lib/integrations/index.mjs +5 -5
  29. package/dist/lib/integrations/nest/index.d.ts +3 -3
  30. package/dist/lib/integrations/nest/index.js +64 -1
  31. package/dist/lib/integrations/nest/index.js.map +1 -1
  32. package/dist/lib/integrations/nest/index.mjs +3 -3
  33. package/dist/lib/integrations/node-express/index.d.ts +3 -3
  34. package/dist/lib/integrations/node-express/index.js +64 -1
  35. package/dist/lib/integrations/node-express/index.js.map +1 -1
  36. package/dist/lib/integrations/node-express/index.mjs +3 -3
  37. package/dist/lib/integrations/node-http/index.d.ts +3 -3
  38. package/dist/lib/integrations/node-http/index.js +64 -1
  39. package/dist/lib/integrations/node-http/index.js.map +1 -1
  40. package/dist/lib/integrations/node-http/index.mjs +2 -2
  41. package/dist/service-adapters/index.d.ts +4 -4
  42. package/package.json +2 -2
  43. package/src/graphql/types/converted/index.ts +66 -0
  44. package/src/lib/runtime/copilot-runtime.ts +5 -1
  45. package/src/service-adapters/events.ts +58 -16
  46. package/dist/chunk-QIJT75EM.mjs.map +0 -1
  47. package/dist/chunk-RFF5IIZJ.mjs +0 -66
  48. package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
  49. /package/dist/{chunk-A6VFRI4R.mjs.map → chunk-GOA7HNXW.mjs.map} +0 -0
  50. /package/dist/{chunk-IJASJOA2.mjs.map → chunk-NTSKJEJQ.mjs.map} +0 -0
  51. /package/dist/{chunk-OKJI7OJY.mjs.map → chunk-ZF34MJL7.mjs.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-QIJT75EM.mjs";
3
+ } from "../../../chunk-P34QEPO5.mjs";
4
4
  import "../../../chunk-CLGKEUOA.mjs";
5
5
  import "../../../chunk-U3V2BCGI.mjs";
6
- import "../../../chunk-RFF5IIZJ.mjs";
6
+ import "../../../chunk-HNUNXFTW.mjs";
7
7
  import "../../../chunk-D2WLFQS6.mjs";
8
8
  import "../../../chunk-44O2JGUY.mjs";
9
9
  export {
@@ -1,8 +1,8 @@
1
- import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-9125a12e.js';
2
- export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-9125a12e.js';
3
- export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-696b5d29.js';
1
+ import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-a16ef8f4.js';
2
+ export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-a16ef8f4.js';
3
+ export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-c35c5374.js';
4
4
  import Anthropic from '@anthropic-ai/sdk';
5
- import '../index-cc2b17be.js';
5
+ import '../index-24315d90.js';
6
6
  import '../graphql/types/base/index.js';
7
7
  import 'rxjs';
8
8
  import '@copilotkit/shared';
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.5.11",
12
+ "version": "1.5.12-next.1",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -58,7 +58,7 @@
58
58
  "rxjs": "^7.8.1",
59
59
  "type-graphql": "2.0.0-rc.1",
60
60
  "zod": "^3.23.3",
61
- "@copilotkit/shared": "1.5.11"
61
+ "@copilotkit/shared": "1.5.12-next.1"
62
62
  },
63
63
  "keywords": [
64
64
  "copilotkit",
@@ -55,6 +55,72 @@ export class ResultMessage extends Message implements ResultMessageInput {
55
55
  actionExecutionId: string;
56
56
  actionName: string;
57
57
  result: string;
58
+
59
+ static encodeResult(
60
+ result: any,
61
+ error?: { code: string; message: string } | string | Error,
62
+ ): string {
63
+ const errorObj = error
64
+ ? typeof error === "string"
65
+ ? { code: "ERROR", message: error }
66
+ : error instanceof Error
67
+ ? { code: "ERROR", message: error.message }
68
+ : error
69
+ : undefined;
70
+
71
+ if (errorObj) {
72
+ return JSON.stringify({
73
+ error: errorObj,
74
+ result: result || "",
75
+ });
76
+ }
77
+ if (result === undefined) {
78
+ return "";
79
+ }
80
+ return typeof result === "string" ? result : JSON.stringify(result);
81
+ }
82
+
83
+ static decodeResult(result: string): {
84
+ error?: { code: string; message: string };
85
+ result: string;
86
+ } {
87
+ if (!result) {
88
+ return { result: "" };
89
+ }
90
+ try {
91
+ const parsed = JSON.parse(result);
92
+ if (parsed && typeof parsed === "object") {
93
+ if ("error" in parsed) {
94
+ return {
95
+ error: parsed.error,
96
+ result: parsed.result || "",
97
+ };
98
+ }
99
+ return { result: JSON.stringify(parsed) };
100
+ }
101
+ return { result };
102
+ } catch (e) {
103
+ return { result };
104
+ }
105
+ }
106
+
107
+ hasError(): boolean {
108
+ try {
109
+ const { error } = ResultMessage.decodeResult(this.result);
110
+ return !!error;
111
+ } catch {
112
+ return false;
113
+ }
114
+ }
115
+
116
+ getError(): { code: string; message: string } | undefined {
117
+ try {
118
+ const { error } = ResultMessage.decodeResult(this.result);
119
+ return error;
120
+ } catch {
121
+ return undefined;
122
+ }
123
+ }
58
124
  }
59
125
 
60
126
  export class AgentStateMessage extends Message implements Omit<AgentStateMessageInput, "state"> {
@@ -351,7 +351,11 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
351
351
  eventSource.stream(async (eventStream$) => {
352
352
  from(stream).subscribe({
353
353
  next: (event) => eventStream$.next(event),
354
- error: (err) => console.error("Error in stream", err),
354
+ error: (err) => {
355
+ console.error("Error in stream", err);
356
+ eventStream$.error(err);
357
+ eventStream$.complete();
358
+ },
355
359
  complete: () => eventStream$.complete(),
356
360
  });
357
361
  });
@@ -2,13 +2,14 @@ import { Action, randomId } from "@copilotkit/shared";
2
2
  import {
3
3
  of,
4
4
  concat,
5
- map,
6
5
  scan,
7
6
  concatMap,
8
7
  ReplaySubject,
9
8
  Subject,
10
9
  firstValueFrom,
11
10
  from,
11
+ catchError,
12
+ EMPTY,
12
13
  } from "rxjs";
13
14
  import { streamLangChainResponse } from "./langchain/utils";
14
15
  import { GuardrailsResult } from "../graphql/types/guardrails-result.type";
@@ -154,16 +155,18 @@ export class RuntimeEventSubject extends ReplaySubject<RuntimeEvent> {
154
155
  actionExecutionId,
155
156
  actionName,
156
157
  result,
158
+ error,
157
159
  }: {
158
160
  actionExecutionId: string;
159
161
  actionName: string;
160
- result: string;
162
+ result?: string;
163
+ error?: { code: string; message: string };
161
164
  }) {
162
165
  this.next({
163
166
  type: RuntimeEventTypes.ActionExecutionResult,
164
167
  actionName,
165
168
  actionExecutionId,
166
- result,
169
+ result: ResultMessage.encodeResult(result, error),
167
170
  });
168
171
  }
169
172
 
@@ -231,6 +234,7 @@ export class RuntimeEventSource {
231
234
  this.callback(this.eventStream$).catch((error) => {
232
235
  console.error("Error in event source callback", error);
233
236
  this.sendErrorMessageToChat();
237
+ this.eventStream$.complete();
234
238
  });
235
239
  return this.eventStream$.pipe(
236
240
  // track state
@@ -286,7 +290,13 @@ export class RuntimeEventSource {
286
290
  });
287
291
 
288
292
  telemetry.capture("oss.runtime.server_action_executed", {});
289
- return concat(of(eventWithState.event!), toolCallEventStream$);
293
+ return concat(of(eventWithState.event!), toolCallEventStream$).pipe(
294
+ catchError((error) => {
295
+ console.error("Error in tool call stream", error);
296
+ this.sendErrorMessageToChat();
297
+ return EMPTY;
298
+ }),
299
+ );
290
300
  } else {
291
301
  return of(eventWithState.event!);
292
302
  }
@@ -319,7 +329,16 @@ async function executeAction(
319
329
  try {
320
330
  args = JSON.parse(actionArguments);
321
331
  } catch (e) {
322
- console.warn("Action argument unparsable", { actionArguments });
332
+ console.error("Action argument unparsable", { actionArguments });
333
+ eventStream$.sendActionExecutionResult({
334
+ actionExecutionId,
335
+ actionName: action.name,
336
+ error: {
337
+ code: "INVALID_ARGUMENTS",
338
+ message: "Failed to parse action arguments",
339
+ },
340
+ });
341
+ return;
323
342
  }
324
343
  }
325
344
 
@@ -358,20 +377,43 @@ async function executeAction(
358
377
  // forward to eventStream$
359
378
  from(stream).subscribe({
360
379
  next: (event) => eventStream$.next(event),
361
- error: (err) => console.error("Error in stream", err),
380
+ error: (err) => {
381
+ console.error("Error in stream", err);
382
+ eventStream$.sendActionExecutionResult({
383
+ actionExecutionId,
384
+ actionName: action.name,
385
+ error: {
386
+ code: "STREAM_ERROR",
387
+ message: err.message,
388
+ },
389
+ });
390
+ eventStream$.complete();
391
+ },
362
392
  complete: () => eventStream$.complete(),
363
393
  });
364
394
  } else {
365
395
  // call the function
366
- const result = await action.handler?.(args);
367
-
368
- await streamLangChainResponse({
369
- result,
370
- eventStream$,
371
- actionExecution: {
372
- name: action.name,
373
- id: actionExecutionId,
374
- },
375
- });
396
+ try {
397
+ const result = await action.handler?.(args);
398
+ await streamLangChainResponse({
399
+ result,
400
+ eventStream$,
401
+ actionExecution: {
402
+ name: action.name,
403
+ id: actionExecutionId,
404
+ },
405
+ });
406
+ } catch (e) {
407
+ console.error("Error in action handler", e);
408
+ eventStream$.sendActionExecutionResult({
409
+ actionExecutionId,
410
+ actionName: action.name,
411
+ error: {
412
+ code: "HANDLER_ERROR",
413
+ message: e.message,
414
+ },
415
+ });
416
+ eventStream$.complete();
417
+ }
376
418
  }
377
419
  }