@copilotkit/runtime 1.9.2-next.24 → 1.9.2-next.26

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 (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{chunk-S2YGYQDH.mjs → chunk-3RL34U4Q.mjs} +2 -2
  3. package/dist/{chunk-FR4C3TPU.mjs → chunk-D7OAY4CQ.mjs} +2 -2
  4. package/dist/{chunk-GAUZHH2X.mjs → chunk-GRU5EPNU.mjs} +91 -39
  5. package/dist/chunk-GRU5EPNU.mjs.map +1 -0
  6. package/dist/{chunk-ECQRTXJX.mjs → chunk-PQG7ZI72.mjs} +2 -2
  7. package/dist/{chunk-TBVA4IGX.mjs → chunk-SE7TPKR2.mjs} +2 -2
  8. package/dist/{groq-adapter-098f97f6.d.ts → groq-adapter-742818f2.d.ts} +1 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +83 -31
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +6 -6
  13. package/dist/{langserve-fc5cac89.d.ts → langserve-3e8d0e06.d.ts} +6 -0
  14. package/dist/lib/index.d.ts +3 -3
  15. package/dist/lib/index.js +83 -31
  16. package/dist/lib/index.js.map +1 -1
  17. package/dist/lib/index.mjs +6 -6
  18. package/dist/lib/integrations/index.d.ts +3 -3
  19. package/dist/lib/integrations/index.js +1 -1
  20. package/dist/lib/integrations/index.js.map +1 -1
  21. package/dist/lib/integrations/index.mjs +5 -5
  22. package/dist/lib/integrations/nest/index.d.ts +2 -2
  23. package/dist/lib/integrations/nest/index.js +1 -1
  24. package/dist/lib/integrations/nest/index.js.map +1 -1
  25. package/dist/lib/integrations/nest/index.mjs +3 -3
  26. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  27. package/dist/lib/integrations/node-express/index.js +1 -1
  28. package/dist/lib/integrations/node-express/index.js.map +1 -1
  29. package/dist/lib/integrations/node-express/index.mjs +3 -3
  30. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  31. package/dist/lib/integrations/node-http/index.js +1 -1
  32. package/dist/lib/integrations/node-http/index.js.map +1 -1
  33. package/dist/lib/integrations/node-http/index.mjs +2 -2
  34. package/dist/service-adapters/index.d.ts +4 -4
  35. package/dist/{shared-6b6dbf8b.d.ts → shared-96b46379.d.ts} +1 -1
  36. package/package.json +2 -2
  37. package/src/lib/runtime/copilot-runtime.ts +46 -28
  38. package/src/service-adapters/events.ts +40 -1
  39. package/dist/chunk-GAUZHH2X.mjs.map +0 -1
  40. /package/dist/{chunk-S2YGYQDH.mjs.map → chunk-3RL34U4Q.mjs.map} +0 -0
  41. /package/dist/{chunk-FR4C3TPU.mjs.map → chunk-D7OAY4CQ.mjs.map} +0 -0
  42. /package/dist/{chunk-ECQRTXJX.mjs.map → chunk-PQG7ZI72.mjs.map} +0 -0
  43. /package/dist/{chunk-TBVA4IGX.mjs.map → chunk-SE7TPKR2.mjs.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-GAUZHH2X.mjs";
3
+ } from "../../../chunk-GRU5EPNU.mjs";
4
+ import "../../../chunk-SHBDMA63.mjs";
4
5
  import "../../../chunk-QLLV2QVK.mjs";
5
6
  import "../../../chunk-XWBDEXDA.mjs";
6
7
  import "../../../chunk-AMUJQ6IR.mjs";
7
- import "../../../chunk-SHBDMA63.mjs";
8
8
  import "../../../chunk-2OZAGFV3.mjs";
9
9
  import "../../../chunk-FHD4JECV.mjs";
10
10
  export {
@@ -1,8 +1,8 @@
1
- import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-fc5cac89.js';
2
- export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-fc5cac89.js';
1
+ import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-3e8d0e06.js';
2
+ export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-3e8d0e06.js';
3
3
  export { convertServiceAdapterError } from './shared/index.js';
4
- import { L as LangChainAdapter } from '../groq-adapter-098f97f6.js';
5
- export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-098f97f6.js';
4
+ import { L as LangChainAdapter } from '../groq-adapter-742818f2.js';
5
+ export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-742818f2.js';
6
6
  import Anthropic from '@anthropic-ai/sdk';
7
7
  import '../index-d4614f9b.js';
8
8
  import '../graphql/types/base/index.js';
@@ -3,7 +3,7 @@ import * as createPinoLogger from 'pino';
3
3
  import createPinoLogger__default from 'pino';
4
4
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
5
5
  import { Parameter, Action, CopilotErrorHandler } from '@copilotkit/shared';
6
- import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters, f as RuntimeEventSource, g as ExtensionsResponse } from './langserve-fc5cac89.js';
6
+ import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters, f as RuntimeEventSource, g as ExtensionsResponse } from './langserve-3e8d0e06.js';
7
7
  import { M as MessageInput, a as Message } from './index-d4614f9b.js';
8
8
  import { CopilotCloudOptions } from './lib/cloud/index.js';
9
9
  import { AbstractAgent } from '@ag-ui/client';
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.9.2-next.24",
12
+ "version": "1.9.2-next.26",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -66,7 +66,7 @@
66
66
  "rxjs": "7.8.1",
67
67
  "type-graphql": "2.0.0-rc.1",
68
68
  "zod": "^3.23.3",
69
- "@copilotkit/shared": "1.9.2-next.24"
69
+ "@copilotkit/shared": "1.9.2-next.26"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@ag-ui/client": ">=0.0.34",
@@ -486,16 +486,11 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
486
486
  publicApiKey,
487
487
  } = request;
488
488
 
489
- const eventSource = new RuntimeEventSource();
490
- // Track request start time for logging
491
- const requestStartTime = Date.now();
492
- // For storing streamed chunks if progressive logging is enabled
493
- const streamedChunks: any[] = [];
494
-
495
- // Track request start
496
- await this.error(
497
- "request",
498
- {
489
+ const eventSource = new RuntimeEventSource({
490
+ errorHandler: async (error, context) => {
491
+ await this.error("error", context, error, publicApiKey);
492
+ },
493
+ errorContext: {
499
494
  threadId,
500
495
  runId,
501
496
  source: "runtime",
@@ -503,20 +498,18 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
503
498
  operation: "processRuntimeRequest",
504
499
  method: "POST",
505
500
  url: url,
506
- startTime: requestStartTime,
501
+ startTime: Date.now(),
507
502
  },
508
503
  agent: agentSession ? { name: agentSession.agentName } : undefined,
509
- messages: {
510
- input: rawMessages,
511
- messageCount: rawMessages.length,
512
- },
513
504
  technical: {
514
505
  environment: process.env.NODE_ENV,
515
506
  },
516
507
  },
517
- undefined,
518
- publicApiKey,
519
- );
508
+ });
509
+ // Track request start time for logging
510
+ const requestStartTime = Date.now();
511
+ // For storing streamed chunks if progressive logging is enabled
512
+ const streamedChunks: any[] = [];
520
513
 
521
514
  try {
522
515
  if (
@@ -982,16 +975,21 @@ please use an LLM adapter instead.`,
982
975
  } catch (error) {
983
976
  // All errors from agent state loading are user configuration issues
984
977
  const errorMessage = error instanceof Error ? error.message : String(error);
978
+ const errorStatus = error?.response?.status || error?.status;
985
979
 
986
- // Log user configuration errors at debug level to reduce noise
987
- console.debug(`Agent '${agentName}' configuration issue: ${errorMessage}`);
988
-
989
- // Throw a configuration error - all agent state loading failures are user setup issues
990
- throw new ResolvedCopilotKitError({
991
- status: 400,
992
- message: `Agent '${agentName}' failed to execute: ${errorMessage}`,
993
- code: CopilotKitErrorCode.CONFIGURATION_ERROR,
994
- });
980
+ if (errorStatus === 404) {
981
+ state = {};
982
+ } else {
983
+ // Log user configuration errors at debug level to reduce noise
984
+ console.debug(`Agent '${agentName}' configuration issue: ${errorMessage}`);
985
+
986
+ // Throw a configuration error - all agent state loading failures are user setup issues
987
+ throw new ResolvedCopilotKitError({
988
+ status: 400,
989
+ message: `Agent '${agentName}' failed to execute: ${errorMessage}`,
990
+ code: CopilotKitErrorCode.CONFIGURATION_ERROR,
991
+ });
992
+ }
995
993
  }
996
994
 
997
995
  if (Object.keys(state).length === 0) {
@@ -1129,7 +1127,27 @@ please use an LLM adapter instead.`,
1129
1127
  });
1130
1128
 
1131
1129
  try {
1132
- const eventSource = new RuntimeEventSource();
1130
+ const eventSource = new RuntimeEventSource({
1131
+ errorHandler: async (error, context) => {
1132
+ await this.error("error", context, error, publicApiKey);
1133
+ },
1134
+ errorContext: {
1135
+ threadId,
1136
+ source: "agent",
1137
+ request: {
1138
+ operation: "processAgentRequest",
1139
+ method: "POST",
1140
+ startTime: requestStartTime,
1141
+ },
1142
+ agent: {
1143
+ name: agentName,
1144
+ nodeName: nodeName,
1145
+ },
1146
+ technical: {
1147
+ environment: process.env.NODE_ENV,
1148
+ },
1149
+ },
1150
+ });
1133
1151
  const stream = await currentAgent.remoteAgentHandler({
1134
1152
  name: agentName,
1135
1153
  threadId,
@@ -240,6 +240,16 @@ export class RuntimeEventSubject extends ReplaySubject<RuntimeEvent> {
240
240
  export class RuntimeEventSource {
241
241
  private eventStream$ = new RuntimeEventSubject();
242
242
  private callback!: EventSourceCallback;
243
+ private errorHandler?: (error: any, context: any) => Promise<void>;
244
+ private errorContext?: any;
245
+
246
+ constructor(params?: {
247
+ errorHandler?: (error: any, context: any) => Promise<void>;
248
+ errorContext?: any;
249
+ }) {
250
+ this.errorHandler = params?.errorHandler;
251
+ this.errorContext = params?.errorContext;
252
+ }
243
253
 
244
254
  async stream(callback: EventSourceCallback): Promise<void> {
245
255
  this.callback = callback;
@@ -267,9 +277,19 @@ export class RuntimeEventSource {
267
277
  actionInputsWithoutAgents: ActionInput[];
268
278
  threadId: string;
269
279
  }) {
270
- this.callback(this.eventStream$).catch((error) => {
280
+ this.callback(this.eventStream$).catch(async (error) => {
271
281
  // Convert streaming errors to structured errors, but preserve already structured ones
272
282
  const structuredError = ensureStructuredError(error, convertStreamingErrorToStructured);
283
+
284
+ // Call the runtime error handler if provided
285
+ if (this.errorHandler && this.errorContext) {
286
+ try {
287
+ await this.errorHandler(structuredError, this.errorContext);
288
+ } catch (errorHandlerError) {
289
+ console.error("Error in streaming error handler:", errorHandlerError);
290
+ }
291
+ }
292
+
273
293
  this.eventStream$.error(structuredError);
274
294
  this.eventStream$.complete();
275
295
  });
@@ -333,6 +353,25 @@ export class RuntimeEventSource {
333
353
  error,
334
354
  convertStreamingErrorToStructured,
335
355
  );
356
+
357
+ // Call the runtime error handler if provided
358
+ if (this.errorHandler && this.errorContext) {
359
+ // Use from() to handle async error handler
360
+ from(
361
+ this.errorHandler(structuredError, {
362
+ ...this.errorContext,
363
+ action: {
364
+ name: eventWithState.action!.name,
365
+ executionId: eventWithState.actionExecutionId,
366
+ },
367
+ }),
368
+ ).subscribe({
369
+ error: (errorHandlerError) => {
370
+ console.error("Error in action execution error handler:", errorHandlerError);
371
+ },
372
+ });
373
+ }
374
+
336
375
  toolCallEventStream$.sendActionExecutionResult({
337
376
  actionExecutionId: eventWithState.actionExecutionId!,
338
377
  actionName: eventWithState.action!.name,