@copilotkit/runtime 1.9.2-next.10 → 1.9.2-next.2

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 (84) hide show
  1. package/CHANGELOG.md +0 -59
  2. package/dist/{chunk-XWBDEXDA.mjs → chunk-5BIEM2UU.mjs} +3 -4
  3. package/dist/{chunk-XWBDEXDA.mjs.map → chunk-5BIEM2UU.mjs.map} +1 -1
  4. package/dist/{chunk-TOBFVWZU.mjs → chunk-6TQCQ3WJ.mjs} +2 -2
  5. package/dist/{chunk-VBXBFZEL.mjs → chunk-CD2SZGIZ.mjs} +2 -2
  6. package/dist/{chunk-6RUTA76W.mjs → chunk-D3SPXEVJ.mjs} +2 -2
  7. package/dist/{chunk-PMIAGZGS.mjs → chunk-DOWRU5U6.mjs} +2414 -2928
  8. package/dist/chunk-DOWRU5U6.mjs.map +1 -0
  9. package/dist/{chunk-GS7DO47Q.mjs → chunk-IIXJVVTV.mjs} +78 -155
  10. package/dist/chunk-IIXJVVTV.mjs.map +1 -0
  11. package/dist/{chunk-5OK4GLKL.mjs → chunk-ODF35LFG.mjs} +2 -19
  12. package/dist/chunk-ODF35LFG.mjs.map +1 -0
  13. package/dist/{groq-adapter-172a2ca4.d.ts → groq-adapter-25a2bd35.d.ts} +1 -1
  14. package/dist/index.d.ts +3 -4
  15. package/dist/index.js +2598 -3250
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +8 -12
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/lib/index.d.ts +4 -5
  20. package/dist/lib/index.js +2730 -3339
  21. package/dist/lib/index.js.map +1 -1
  22. package/dist/lib/index.mjs +8 -9
  23. package/dist/lib/integrations/index.d.ts +3 -3
  24. package/dist/lib/integrations/index.js +96 -160
  25. package/dist/lib/integrations/index.js.map +1 -1
  26. package/dist/lib/integrations/index.mjs +6 -7
  27. package/dist/lib/integrations/nest/index.d.ts +2 -2
  28. package/dist/lib/integrations/nest/index.js +96 -160
  29. package/dist/lib/integrations/nest/index.js.map +1 -1
  30. package/dist/lib/integrations/nest/index.mjs +4 -5
  31. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  32. package/dist/lib/integrations/node-express/index.js +96 -160
  33. package/dist/lib/integrations/node-express/index.js.map +1 -1
  34. package/dist/lib/integrations/node-express/index.mjs +4 -5
  35. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  36. package/dist/lib/integrations/node-http/index.js +96 -160
  37. package/dist/lib/integrations/node-http/index.js.map +1 -1
  38. package/dist/lib/integrations/node-http/index.mjs +3 -4
  39. package/dist/service-adapters/index.d.ts +4 -6
  40. package/dist/service-adapters/index.js +107 -225
  41. package/dist/service-adapters/index.js.map +1 -1
  42. package/dist/service-adapters/index.mjs +2 -6
  43. package/dist/{shared-bd953ebf.d.ts → shared-e272b15a.d.ts} +5 -45
  44. package/dist/utils/index.d.ts +1 -17
  45. package/dist/utils/index.js +2 -3
  46. package/dist/utils/index.js.map +1 -1
  47. package/dist/utils/index.mjs +1 -1
  48. package/package.json +2 -2
  49. package/src/agents/langgraph/event-source.ts +38 -36
  50. package/src/agents/langgraph/events.ts +1 -19
  51. package/src/graphql/resolvers/copilot.resolver.ts +45 -108
  52. package/src/graphql/resolvers/state.resolver.ts +3 -3
  53. package/src/lib/integrations/shared.ts +0 -43
  54. package/src/lib/runtime/copilot-runtime.ts +83 -412
  55. package/src/lib/runtime/langgraph/langgraph-agent.ts +0 -12
  56. package/src/lib/runtime/remote-action-constructors.ts +3 -28
  57. package/src/lib/runtime/remote-lg-action.ts +40 -130
  58. package/src/lib/streaming.ts +36 -125
  59. package/src/service-adapters/anthropic/anthropic-adapter.ts +8 -67
  60. package/src/service-adapters/anthropic/utils.ts +8 -3
  61. package/src/service-adapters/events.ts +81 -37
  62. package/src/service-adapters/groq/groq-adapter.ts +56 -66
  63. package/src/service-adapters/index.ts +0 -1
  64. package/src/service-adapters/openai/openai-adapter.ts +3 -18
  65. package/src/utils/failed-response-status-reasons.ts +1 -23
  66. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +387 -172
  67. package/dist/chunk-5OK4GLKL.mjs.map +0 -1
  68. package/dist/chunk-AMUJQ6IR.mjs +0 -50
  69. package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
  70. package/dist/chunk-GS7DO47Q.mjs.map +0 -1
  71. package/dist/chunk-PMIAGZGS.mjs.map +0 -1
  72. package/dist/service-adapters/shared/index.d.ts +0 -9
  73. package/dist/service-adapters/shared/index.js +0 -72
  74. package/dist/service-adapters/shared/index.js.map +0 -1
  75. package/dist/service-adapters/shared/index.mjs +0 -8
  76. package/dist/service-adapters/shared/index.mjs.map +0 -1
  77. package/src/lib/error-messages.ts +0 -200
  78. package/src/lib/runtime/__tests__/copilot-runtime-trace.test.ts +0 -169
  79. package/src/service-adapters/shared/error-utils.ts +0 -61
  80. package/src/service-adapters/shared/index.ts +0 -1
  81. package/dist/{chunk-TOBFVWZU.mjs.map → chunk-6TQCQ3WJ.mjs.map} +0 -0
  82. package/dist/{chunk-VBXBFZEL.mjs.map → chunk-CD2SZGIZ.mjs.map} +0 -0
  83. package/dist/{chunk-6RUTA76W.mjs.map → chunk-D3SPXEVJ.mjs.map} +0 -0
  84. package/dist/{langserve-fc5cac89.d.ts → langserve-4a5c9217.d.ts} +7 -7
@@ -11,10 +11,7 @@ import {
11
11
  OpenAIAssistantAdapter,
12
12
  RemoteChain,
13
13
  UnifyAdapter
14
- } from "../chunk-GS7DO47Q.mjs";
15
- import {
16
- convertServiceAdapterError
17
- } from "../chunk-AMUJQ6IR.mjs";
14
+ } from "../chunk-IIXJVVTV.mjs";
18
15
  import "../chunk-FHD4JECV.mjs";
19
16
  export {
20
17
  AnthropicAdapter,
@@ -28,7 +25,6 @@ export {
28
25
  OpenAIAdapter,
29
26
  OpenAIAssistantAdapter,
30
27
  RemoteChain,
31
- UnifyAdapter,
32
- convertServiceAdapterError
28
+ UnifyAdapter
33
29
  };
34
30
  //# sourceMappingURL=index.mjs.map
@@ -1,9 +1,8 @@
1
1
  import * as graphql from 'graphql';
2
- import * as createPinoLogger from 'pino';
3
- import createPinoLogger__default from 'pino';
2
+ import * as pino from 'pino';
4
3
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
5
- import { Parameter, Action, CopilotTraceHandler } 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';
4
+ import { Parameter, Action } from '@copilotkit/shared';
5
+ 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-4a5c9217.js';
7
6
  import { M as MessageInput, a as Message } from './index-d4614f9b.js';
8
7
  import { CopilotCloudOptions } from './lib/cloud/index.js';
9
8
  import { AbstractAgent } from '@ag-ui/client';
@@ -339,24 +338,6 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
339
338
  * ```
340
339
  */
341
340
  createMCPClient?: CreateMCPClientFunction;
342
- /**
343
- * Optional trace handler for comprehensive debugging and observability.
344
- *
345
- * **Requires publicApiKey**: Tracing only works when requests include a valid publicApiKey.
346
- * This is a premium CopilotKit Cloud feature.
347
- *
348
- * @param traceEvent - Structured trace event with rich debugging context
349
- *
350
- * @example
351
- * ```typescript
352
- * const runtime = new CopilotRuntime({
353
- * onTrace: (traceEvent) => {
354
- * debugDashboard.capture(traceEvent);
355
- * }
356
- * });
357
- * ```
358
- */
359
- onTrace?: CopilotTraceHandler;
360
341
  }
361
342
  declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
362
343
  actions: ActionsConfiguration<T>;
@@ -368,36 +349,18 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
368
349
  private delegateAgentProcessingToServiceAdapter;
369
350
  private observability?;
370
351
  private availableAgents;
371
- private onTrace?;
372
- private hasWarnedAboutTracing;
373
352
  private readonly mcpServersConfig?;
374
353
  private mcpActionCache;
375
354
  private readonly createMCPClientImpl?;
376
355
  constructor(params?: CopilotRuntimeConstructorParams<T>);
377
356
  private injectMCPToolInstructions;
378
357
  processRuntimeRequest(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
379
- getAllAgents(graphqlContext: GraphQLContext): Promise<(AgentWithEndpoint | Agent)[]>;
380
358
  discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]>;
381
- discoverAgentsFromAgui(): Promise<AgentWithEndpoint[]>;
382
359
  loadAgentState(graphqlContext: GraphQLContext, threadId: string, agentName: string): Promise<LoadAgentStateResponse>;
383
360
  private processAgentRequest;
384
361
  private getServerSideActions;
385
362
  private detectProvider;
386
363
  private convertStreamingErrorToStructured;
387
- private trace;
388
- /**
389
- * Public method to trace GraphQL validation errors
390
- * This allows the GraphQL resolver to send validation errors through the trace system
391
- */
392
- traceGraphQLError(error: {
393
- message: string;
394
- code: string;
395
- type: string;
396
- }, context: {
397
- operation: string;
398
- cloudConfigPresent: boolean;
399
- guardrailsEnabled: boolean;
400
- }): Promise<void>;
401
364
  }
402
365
  declare function flattenToolCallsNoDuplicates(toolsByPriority: ActionInput[]): ActionInput[];
403
366
  declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): CopilotKitEndpoint;
@@ -409,9 +372,9 @@ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
409
372
  declare function createLogger(options?: {
410
373
  level?: LogLevel;
411
374
  component?: string;
412
- }): createPinoLogger__default.Logger<never>;
375
+ }): pino.Logger<never>;
413
376
 
414
- declare const logger: createPinoLogger.default.Logger<never>;
377
+ declare const logger: pino.Logger<never>;
415
378
  declare const addCustomHeaderPlugin: {
416
379
  onResponse({ response }: {
417
380
  response: any;
@@ -442,9 +405,6 @@ type CommonConfig = {
442
405
  schema: ReturnType<typeof buildSchema>;
443
406
  plugins: Parameters<typeof createYoga>[0]["plugins"];
444
407
  context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
445
- maskedErrors: {
446
- maskError: (error: any, message: string, isDev?: boolean) => any;
447
- };
448
408
  };
449
409
  declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
450
410
 
@@ -40,25 +40,9 @@ declare class UnknownErrorResponse extends FailedResponseStatus {
40
40
  reason: FailedResponseStatusReason;
41
41
  details: {
42
42
  description?: string;
43
- originalError?: {
44
- code?: string;
45
- statusCode?: number;
46
- severity?: string;
47
- visibility?: string;
48
- originalErrorType?: string;
49
- extensions?: any;
50
- };
51
43
  };
52
- constructor({ description, originalError, }: {
44
+ constructor({ description }: {
53
45
  description?: string;
54
- originalError?: {
55
- code?: string;
56
- statusCode?: number;
57
- severity?: string;
58
- visibility?: string;
59
- originalErrorType?: string;
60
- extensions?: any;
61
- };
62
46
  });
63
47
  }
64
48
 
@@ -157,11 +157,10 @@ var MessageStreamInterruptedResponse = class extends FailedResponseStatus {
157
157
  __name(MessageStreamInterruptedResponse, "MessageStreamInterruptedResponse");
158
158
  var UnknownErrorResponse = class extends FailedResponseStatus {
159
159
  reason = FailedResponseStatusReason.UNKNOWN_ERROR;
160
- constructor({ description, originalError }) {
160
+ constructor({ description }) {
161
161
  super();
162
162
  this.details = {
163
- description,
164
- originalError
163
+ description
165
164
  };
166
165
  }
167
166
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts","../../src/graphql/types/response-status.type.ts","../../src/utils/failed-response-status-reasons.ts"],"sourcesContent":["export * from \"./failed-response-status-reasons\";\n","import { GraphQLJSON } from \"graphql-scalars\";\nimport { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from \"type-graphql\";\n\nexport enum ResponseStatusCode {\n Pending = \"pending\",\n Success = \"success\",\n Failed = \"failed\",\n}\n\nregisterEnumType(ResponseStatusCode, {\n name: \"ResponseStatusCode\",\n});\n\n@InterfaceType({\n resolveType(value) {\n if (value.code === ResponseStatusCode.Success) {\n return SuccessResponseStatus;\n } else if (value.code === ResponseStatusCode.Failed) {\n return FailedResponseStatus;\n } else if (value.code === ResponseStatusCode.Pending) {\n return PendingResponseStatus;\n }\n return undefined;\n },\n})\n@ObjectType()\nabstract class BaseResponseStatus {\n @Field(() => ResponseStatusCode)\n code: ResponseStatusCode;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class PendingResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Pending;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class SuccessResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Success;\n}\n\nexport enum FailedResponseStatusReason {\n GUARDRAILS_VALIDATION_FAILED = \"GUARDRAILS_VALIDATION_FAILED\",\n MESSAGE_STREAM_INTERRUPTED = \"MESSAGE_STREAM_INTERRUPTED\",\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\nregisterEnumType(FailedResponseStatusReason, {\n name: \"FailedResponseStatusReason\",\n});\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class FailedResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Failed;\n\n @Field(() => FailedResponseStatusReason)\n reason: FailedResponseStatusReason;\n\n @Field(() => GraphQLJSON, { nullable: true })\n details?: Record<string, any> = null;\n}\n\nexport const ResponseStatusUnion = createUnionType({\n name: \"ResponseStatus\",\n types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,\n});\n","import {\n FailedResponseStatus,\n FailedResponseStatusReason,\n} from \"../graphql/types/response-status.type\";\n\nexport class GuardrailsValidationFailureResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;\n declare details: {\n guardrailsReason: string;\n };\n\n constructor({ guardrailsReason }) {\n super();\n this.details = {\n guardrailsReason,\n };\n }\n}\n\nexport class MessageStreamInterruptedResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;\n declare details: {\n messageId: string;\n description: string;\n };\n\n constructor({ messageId }: { messageId: string }) {\n super();\n this.details = {\n messageId,\n description: \"Check the message for mode details\",\n };\n }\n}\n\nexport class UnknownErrorResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.UNKNOWN_ERROR;\n declare details: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n };\n\n constructor({\n description,\n originalError,\n }: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n }) {\n super();\n this.details = {\n description,\n originalError,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,6BAA4B;AAC5B,0BAAoF;;;;;;;;;;;;;;;;;;UAExEA,qBAAAA;;;;GAAAA,uBAAAA,qBAAAA,CAAAA,EAAAA;IAMZC,sCAAiBD,oBAAoB;EACnCE,MAAM;AACR,CAAA;AAeA,IAAeC,qBAAf,6BAAeA,oBAAAA;EAEbC;AACF,GAHA;;MACGC,2BAAM,MAAML,kBAAAA;;GADAG,mBAAAA,WAAAA,QAAAA,MAAAA;AAAAA,qBAAAA,aAAAA;MAbdG,mCAAc;IACbC,YAAYC,OAAK;AACf,UAAIA,MAAMJ,SAAI,WAAiC;AAC7C,eAAOK;MACT,WAAWD,MAAMJ,SAAI,UAAgC;AACnD,eAAOM;MACT,WAAWF,MAAMJ,SAAI,WAAiC;AACpD,eAAOO;MACT;AACA,aAAOC;IACT;EACF,CAAA;MACCC,gCAAAA;GACcV,kBAAAA;AAMR,IAAMQ,wBAAN,cAAoCR,mBAAAA;EACzCC,OAAAA;AACF;AAFaO;AAAAA,wBAAAA,aAAAA;MADZE,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCQ,qBAAAA;AAKN,IAAM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","code","Field","InterfaceType","resolveType","value","SuccessResponseStatus","FailedResponseStatus","PendingResponseStatus","undefined","ObjectType","implements","FailedResponseStatusReason","reason","details","GraphQLJSON","nullable","ResponseStatusUnion","createUnionType","types","GuardrailsValidationFailureResponse","FailedResponseStatus","reason","FailedResponseStatusReason","GUARDRAILS_VALIDATION_FAILED","constructor","guardrailsReason","details","MessageStreamInterruptedResponse","MESSAGE_STREAM_INTERRUPTED","messageId","description","UnknownErrorResponse","UNKNOWN_ERROR","originalError"]}
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/graphql/types/response-status.type.ts","../../src/utils/failed-response-status-reasons.ts"],"sourcesContent":["export * from \"./failed-response-status-reasons\";\n","import { GraphQLJSON } from \"graphql-scalars\";\nimport { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from \"type-graphql\";\n\nexport enum ResponseStatusCode {\n Pending = \"pending\",\n Success = \"success\",\n Failed = \"failed\",\n}\n\nregisterEnumType(ResponseStatusCode, {\n name: \"ResponseStatusCode\",\n});\n\n@InterfaceType({\n resolveType(value) {\n if (value.code === ResponseStatusCode.Success) {\n return SuccessResponseStatus;\n } else if (value.code === ResponseStatusCode.Failed) {\n return FailedResponseStatus;\n } else if (value.code === ResponseStatusCode.Pending) {\n return PendingResponseStatus;\n }\n return undefined;\n },\n})\n@ObjectType()\nabstract class BaseResponseStatus {\n @Field(() => ResponseStatusCode)\n code: ResponseStatusCode;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class PendingResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Pending;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class SuccessResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Success;\n}\n\nexport enum FailedResponseStatusReason {\n GUARDRAILS_VALIDATION_FAILED = \"GUARDRAILS_VALIDATION_FAILED\",\n MESSAGE_STREAM_INTERRUPTED = \"MESSAGE_STREAM_INTERRUPTED\",\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\nregisterEnumType(FailedResponseStatusReason, {\n name: \"FailedResponseStatusReason\",\n});\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class FailedResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Failed;\n\n @Field(() => FailedResponseStatusReason)\n reason: FailedResponseStatusReason;\n\n @Field(() => GraphQLJSON, { nullable: true })\n details?: Record<string, any> = null;\n}\n\nexport const ResponseStatusUnion = createUnionType({\n name: \"ResponseStatus\",\n types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,\n});\n","import {\n FailedResponseStatus,\n FailedResponseStatusReason,\n} from \"../graphql/types/response-status.type\";\n\nexport class GuardrailsValidationFailureResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;\n declare details: {\n guardrailsReason: string;\n };\n\n constructor({ guardrailsReason }) {\n super();\n this.details = {\n guardrailsReason,\n };\n }\n}\n\nexport class MessageStreamInterruptedResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;\n declare details: {\n messageId: string;\n description: string;\n };\n\n constructor({ messageId }: { messageId: string }) {\n super();\n this.details = {\n messageId,\n description: \"Check the message for mode details\",\n };\n }\n}\n\nexport class UnknownErrorResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.UNKNOWN_ERROR;\n declare details: {\n description?: string;\n };\n\n constructor({ description }: { description?: string }) {\n super();\n this.details = {\n description,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,6BAA4B;AAC5B,0BAAoF;;;;;;;;;;;;;;;;;;UAExEA,qBAAAA;;;;GAAAA,uBAAAA,qBAAAA,CAAAA,EAAAA;IAMZC,sCAAiBD,oBAAoB;EACnCE,MAAM;AACR,CAAA;AAeA,IAAeC,qBAAf,6BAAeA,oBAAAA;EAEbC;AACF,GAHA;;MACGC,2BAAM,MAAML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EAKpCC,YAAY,EAAEC,iBAAgB,GAAI;AAChC,UAAK;AACL,SAAKC,UAAU;MACbD;IACF;EACF;AACF;AAZaN;AAcN,IAAMQ,mCAAN,cAA+CP,qBAAAA;EACpDC,SAASC,2BAA2BM;EAMpCJ,YAAY,EAAEK,UAAS,GAA2B;AAChD,UAAK;AACL,SAAKH,UAAU;MACbG;MACAC,aAAa;IACf;EACF;AACF;AAdaH;AAgBN,IAAMI,uBAAN,cAAmCX,qBAAAA;EACxCC,SAASC,2BAA2BU;EAKpCR,YAAY,EAAEM,YAAW,GAA8B;AACrD,UAAK;AACL,SAAKJ,UAAU;MACbI;IACF;EACF;AACF;AAZaC;","names":["ResponseStatusCode","registerEnumType","name","BaseResponseStatus","code","Field","InterfaceType","resolveType","value","SuccessResponseStatus","FailedResponseStatus","PendingResponseStatus","undefined","ObjectType","implements","FailedResponseStatusReason","reason","details","GraphQLJSON","nullable","ResponseStatusUnion","createUnionType","types","GuardrailsValidationFailureResponse","FailedResponseStatus","reason","FailedResponseStatusReason","GUARDRAILS_VALIDATION_FAILED","constructor","guardrailsReason","details","MessageStreamInterruptedResponse","MESSAGE_STREAM_INTERRUPTED","messageId","description","UnknownErrorResponse","UNKNOWN_ERROR"]}
@@ -2,7 +2,7 @@ import {
2
2
  GuardrailsValidationFailureResponse,
3
3
  MessageStreamInterruptedResponse,
4
4
  UnknownErrorResponse
5
- } from "../chunk-XWBDEXDA.mjs";
5
+ } from "../chunk-5BIEM2UU.mjs";
6
6
  import "../chunk-FHD4JECV.mjs";
7
7
  export {
8
8
  GuardrailsValidationFailureResponse,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.9.2-next.10",
12
+ "version": "1.9.2-next.2",
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.10"
69
+ "@copilotkit/shared": "1.9.2-next.2"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@ag-ui/client": ">=0.0.28",
@@ -1,12 +1,11 @@
1
- import { CopilotKitLowLevelError, isStructuredCopilotKitError } from "@copilotkit/shared";
2
1
  import { catchError, mergeMap, ReplaySubject, scan } from "rxjs";
3
- import { generateHelpfulErrorMessage } from "../../lib/streaming";
2
+ import { CustomEventNames, LangGraphEvent, LangGraphEventTypes } from "./events";
4
3
  import {
5
4
  RuntimeEvent,
6
5
  RuntimeEventTypes,
7
6
  RuntimeMetaEventName,
8
7
  } from "../../service-adapters/events";
9
- import { CustomEventNames, LangGraphEvent, LangGraphEventTypes } from "./events";
8
+ import { randomId, CopilotKitError } from "@copilotkit/shared";
10
9
 
11
10
  interface LangGraphEventWithState {
12
11
  event: LangGraphEvent | null;
@@ -156,31 +155,6 @@ export class RemoteLangGraphEventSource {
156
155
  });
157
156
  }
158
157
 
159
- // Handle CopilotKit error events with preserved semantic information
160
- if (acc.event.event === LangGraphEventTypes.OnCopilotKitError) {
161
- const errorData = acc.event.data.error;
162
-
163
- // Create a structured error with the original semantic information
164
- const preservedError = new CopilotKitLowLevelError({
165
- error: new Error(errorData.message),
166
- url: "langgraph agent",
167
- message: `${errorData.type}: ${errorData.message}`,
168
- });
169
-
170
- // Add additional error context to the error object
171
- if (errorData.status_code) {
172
- (preservedError as any).statusCode = errorData.status_code;
173
- }
174
- if (errorData.response_data) {
175
- (preservedError as any).responseData = errorData.response_data;
176
- }
177
- (preservedError as any).agentName = errorData.agent_name;
178
- (preservedError as any).originalErrorType = errorData.type;
179
-
180
- // Throw the structured error to be handled by the catchError operator
181
- throw preservedError;
182
- }
183
-
184
158
  const responseMetadata = this.getResponseMetadata(acc.event);
185
159
 
186
160
  // Tool call ended: emit ActionExecutionEnd
@@ -309,20 +283,48 @@ export class RemoteLangGraphEventSource {
309
283
  return events;
310
284
  }),
311
285
  catchError((error) => {
286
+ console.error(error);
287
+
312
288
  // If it's a structured CopilotKitError, re-throw it to be handled by the frontend error system
313
- if (isStructuredCopilotKitError(error)) {
289
+ if (
290
+ error instanceof CopilotKitError ||
291
+ (error?.name && error.name.includes("CopilotKit"))
292
+ ) {
314
293
  throw error;
315
294
  }
316
295
 
317
- // Determine a more helpful error message based on context
318
- let helpfulMessage = generateHelpfulErrorMessage(error, "LangGraph agent connection");
296
+ const events: RuntimeEvent[] = [];
297
+
298
+ if (lastEventWithState?.lastMessageId && !lastEventWithState.isToolCall) {
299
+ events.push({
300
+ type: RuntimeEventTypes.TextMessageEnd,
301
+ messageId: lastEventWithState.lastMessageId,
302
+ });
303
+ }
304
+ if (lastEventWithState?.lastToolCallId) {
305
+ events.push({
306
+ type: RuntimeEventTypes.ActionExecutionEnd,
307
+ actionExecutionId: lastEventWithState.lastToolCallId,
308
+ });
309
+ }
310
+
311
+ const messageId = randomId();
319
312
 
320
- // For all other errors, preserve the raw error information in a structured format
321
- throw new CopilotKitLowLevelError({
322
- error: error instanceof Error ? error : new Error(String(error)),
323
- url: "langgraph event stream",
324
- message: helpfulMessage,
313
+ events.push({
314
+ type: RuntimeEventTypes.TextMessageStart,
315
+ messageId: messageId,
316
+ });
317
+ events.push({
318
+ type: RuntimeEventTypes.TextMessageContent,
319
+ messageId: messageId,
320
+ content: "❌ An error occurred. Please try again.",
325
321
  });
322
+ events.push({
323
+ type: RuntimeEventTypes.TextMessageEnd,
324
+ messageId: messageId,
325
+ });
326
+
327
+ return events;
326
328
  }),
327
329
  );
328
330
  }
@@ -15,7 +15,6 @@ export enum LangGraphEventTypes {
15
15
  OnCustomEvent = "on_custom_event",
16
16
  OnInterrupt = "on_interrupt",
17
17
  OnCopilotKitInterrupt = "on_copilotkit_interrupt",
18
- OnCopilotKitError = "on_copilotkit_error",
19
18
  }
20
19
 
21
20
  export enum MetaEventNames {
@@ -345,22 +344,6 @@ interface CopilotKitLangGraphInterruptEvent {
345
344
  data: { value: string; messages: (TextMessage | ActionExecutionMessage | ResultMessage)[] };
346
345
  }
347
346
 
348
- interface CopilotKitLangGraphErrorEvent {
349
- event: LangGraphEventTypes.OnCopilotKitError;
350
- data: {
351
- error: {
352
- message: string;
353
- type: string;
354
- agent_name: string;
355
- status_code?: number;
356
- response_data?: any;
357
- };
358
- thread_id: string;
359
- agent_name: string;
360
- node_name: string;
361
- };
362
- }
363
-
364
347
  export type LangGraphEvent =
365
348
  | LangGraphOnChainStartEvent
366
349
  | LangGraphOnChainStreamEvent
@@ -373,5 +356,4 @@ export type LangGraphEvent =
373
356
  | LangGraphOnCopilotKitStateSyncEvent
374
357
  | LangGraphOnCustomEvent
375
358
  | LangGraphInterruptEvent
376
- | CopilotKitLangGraphInterruptEvent
377
- | CopilotKitLangGraphErrorEvent;
359
+ | CopilotKitLangGraphInterruptEvent;
@@ -54,11 +54,7 @@ import telemetry from "../../lib/telemetry-client";
54
54
  import { randomId } from "@copilotkit/shared";
55
55
  import { AgentsResponse } from "../types/agents-response.type";
56
56
  import { LangGraphEventTypes } from "../../agents/langgraph/events";
57
- import {
58
- CopilotKitError,
59
- CopilotKitLowLevelError,
60
- isStructuredCopilotKitError,
61
- } from "@copilotkit/shared";
57
+ import { CopilotKitError } from "@copilotkit/shared";
62
58
 
63
59
  const invokeGuardrails = async ({
64
60
  baseUrl,
@@ -178,34 +174,15 @@ export class CopilotResolver {
178
174
  let copilotCloudPublicApiKey: string | null = null;
179
175
  let copilotCloudBaseUrl: string;
180
176
 
181
- // Extract publicApiKey from headers for both cloud and non-cloud requests
182
- // This enables onTrace functionality regardless of cloud configuration
183
- const publicApiKeyFromHeaders = ctx.request.headers.get("x-copilotcloud-public-api-key");
184
- if (publicApiKeyFromHeaders) {
185
- copilotCloudPublicApiKey = publicApiKeyFromHeaders;
186
- }
187
-
188
177
  if (data.cloud) {
189
178
  logger = logger.child({ cloud: true });
190
179
  logger.debug("Cloud configuration provided, checking for public API key in headers");
191
-
192
- if (!copilotCloudPublicApiKey) {
180
+ const key = ctx.request.headers.get("x-copilotcloud-public-api-key");
181
+ if (key) {
182
+ logger.debug("Public API key found in headers");
183
+ copilotCloudPublicApiKey = key;
184
+ } else {
193
185
  logger.error("Public API key not found in headers");
194
-
195
- // Trace the validation error for debugging visibility
196
- await copilotRuntime.traceGraphQLError(
197
- {
198
- message: "X-CopilotCloud-Public-API-Key header is required",
199
- code: "MISSING_PUBLIC_API_KEY",
200
- type: "GraphQLError",
201
- },
202
- {
203
- operation: "generateCopilotResponse",
204
- cloudConfigPresent: Boolean(data.cloud),
205
- guardrailsEnabled: Boolean(data.cloud?.guardrails),
206
- },
207
- );
208
-
209
186
  throw new GraphQLError("X-CopilotCloud-Public-API-Key header is required");
210
187
  }
211
188
 
@@ -239,40 +216,6 @@ export class CopilotResolver {
239
216
  }
240
217
 
241
218
  logger.debug("Processing");
242
- let runtimeResponse;
243
- try {
244
- runtimeResponse = await copilotRuntime.processRuntimeRequest({
245
- serviceAdapter,
246
- messages: data.messages,
247
- actions: data.frontend.actions.filter(
248
- (action) => action.available !== ActionInputAvailability.disabled,
249
- ),
250
- threadId: data.threadId,
251
- runId: data.runId,
252
- publicApiKey: copilotCloudPublicApiKey,
253
- outputMessagesPromise,
254
- graphqlContext: ctx,
255
- forwardedParameters: data.forwardedParameters,
256
- agentSession: data.agentSession,
257
- agentStates: data.agentStates,
258
- url: data.frontend.url,
259
- extensions: data.extensions,
260
- metaEvents: data.metaEvents,
261
- });
262
- } catch (error) {
263
- // Catch structured CopilotKit errors at the main mutation level and re-throw as GraphQL errors
264
- if (isStructuredCopilotKitError(error) || (error as any)?.extensions?.visibility) {
265
- throw new GraphQLError(error.message || "Agent error occurred", {
266
- extensions: {
267
- ...(error as any).extensions,
268
- code: (error as any).code || (error as any).extensions?.code || "AGENT_ERROR",
269
- originalError: error,
270
- },
271
- });
272
- }
273
- throw error; // Re-throw non-CopilotKit errors as-is
274
- }
275
-
276
219
  const {
277
220
  eventSource,
278
221
  threadId = randomId(),
@@ -280,7 +223,24 @@ export class CopilotResolver {
280
223
  serverSideActions,
281
224
  actionInputsWithoutAgents,
282
225
  extensions,
283
- } = runtimeResponse;
226
+ } = await copilotRuntime.processRuntimeRequest({
227
+ serviceAdapter,
228
+ messages: data.messages,
229
+ actions: data.frontend.actions.filter(
230
+ (action) => action.available !== ActionInputAvailability.disabled,
231
+ ),
232
+ threadId: data.threadId,
233
+ runId: data.runId,
234
+ publicApiKey: copilotCloudPublicApiKey,
235
+ outputMessagesPromise,
236
+ graphqlContext: ctx,
237
+ forwardedParameters: data.forwardedParameters,
238
+ agentSession: data.agentSession,
239
+ agentStates: data.agentStates,
240
+ url: data.frontend.url,
241
+ extensions: data.extensions,
242
+ metaEvents: data.metaEvents,
243
+ });
284
244
 
285
245
  logger.debug("Event source created, creating response");
286
246
  // run and process the event stream
@@ -378,21 +338,12 @@ export class CopilotResolver {
378
338
  }
379
339
  },
380
340
  error: (err) => {
381
- // For structured CopilotKit errors, set proper error response status
382
- if (err?.name?.includes("CopilotKit") || err?.extensions?.visibility) {
383
- responseStatus$.next(
384
- new UnknownErrorResponse({
385
- description: err.message || "Agent error occurred",
386
- }),
387
- );
388
- } else {
389
- responseStatus$.next(
390
- new UnknownErrorResponse({
391
- description: `An unknown error has occurred in the event stream`,
392
- }),
393
- );
394
- }
395
-
341
+ logger.error({ err }, "Error in meta events stream");
342
+ responseStatus$.next(
343
+ new UnknownErrorResponse({
344
+ description: `An unknown error has occurred in the event stream`,
345
+ }),
346
+ );
396
347
  eventStreamSubscription?.unsubscribe();
397
348
  stop();
398
349
  },
@@ -474,20 +425,20 @@ export class CopilotResolver {
474
425
  // create a sub stream that contains the message content
475
426
  const textMessageContentStream = eventStream.pipe(
476
427
  // skip until this message start event
477
- skipWhile((e: RuntimeEvent) => e !== event),
428
+ skipWhile((e) => e !== event),
478
429
  // take until the message end event
479
430
  takeWhile(
480
- (e: RuntimeEvent) =>
431
+ (e) =>
481
432
  !(
482
433
  e.type === RuntimeEventTypes.TextMessageEnd &&
483
- (e as any).messageId == event.messageId
434
+ e.messageId == event.messageId
484
435
  ),
485
436
  ),
486
437
  // filter out any other message events or message ids
487
438
  filter(
488
- (e: RuntimeEvent) =>
439
+ (e) =>
489
440
  e.type == RuntimeEventTypes.TextMessageContent &&
490
- (e as any).messageId == event.messageId,
441
+ e.messageId == event.messageId,
491
442
  ),
492
443
  );
493
444
 
@@ -569,20 +520,20 @@ export class CopilotResolver {
569
520
  case RuntimeEventTypes.ActionExecutionStart:
570
521
  logger.debug("Action execution start event received");
571
522
  const actionExecutionArgumentStream = eventStream.pipe(
572
- skipWhile((e: RuntimeEvent) => e !== event),
523
+ skipWhile((e) => e !== event),
573
524
  // take until the action execution end event
574
525
  takeWhile(
575
- (e: RuntimeEvent) =>
526
+ (e) =>
576
527
  !(
577
528
  e.type === RuntimeEventTypes.ActionExecutionEnd &&
578
- (e as any).actionExecutionId == event.actionExecutionId
529
+ e.actionExecutionId == event.actionExecutionId
579
530
  ),
580
531
  ),
581
532
  // filter out any other action execution events or action execution ids
582
533
  filter(
583
- (e: RuntimeEvent) =>
534
+ (e) =>
584
535
  e.type == RuntimeEventTypes.ActionExecutionArgs &&
585
- (e as any).actionExecutionId == event.actionExecutionId,
536
+ e.actionExecutionId == event.actionExecutionId,
586
537
  ),
587
538
  );
588
539
  const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
@@ -695,30 +646,16 @@ export class CopilotResolver {
695
646
  }
696
647
  },
697
648
  error: (err) => {
698
- // For structured CopilotKit errors, set proper error response status
649
+ logger.error({ err }, "Error in event stream");
650
+
651
+ // If it's a structured CopilotKitError, stop the repeater with the error so frontend can handle it
699
652
  if (
700
653
  err instanceof CopilotKitError ||
701
- err instanceof CopilotKitLowLevelError ||
702
- (err instanceof Error && err.name && err.name.includes("CopilotKit")) ||
703
- err?.extensions?.visibility
654
+ (err instanceof Error && err.name && err.name.includes("CopilotKit"))
704
655
  ) {
705
- responseStatus$.next(
706
- new UnknownErrorResponse({
707
- description: err.message || "Agent error occurred",
708
- // Include original error information for frontend to extract
709
- originalError: {
710
- code: err.code || err.extensions?.code,
711
- statusCode: err.statusCode || err.extensions?.statusCode,
712
- severity: err.severity || err.extensions?.severity,
713
- visibility: err.visibility || err.extensions?.visibility,
714
- originalErrorType: err.originalErrorType || err.extensions?.originalErrorType,
715
- extensions: err.extensions,
716
- },
717
- }),
718
- );
719
656
  eventStreamSubscription?.unsubscribe();
720
657
  rejectOutputMessagesPromise(err);
721
- stopStreamingMessages();
658
+ stopStreamingMessages(err); // Pass the error to stop the GraphQL stream with this error
722
659
  return;
723
660
  }
724
661
 
@@ -10,9 +10,9 @@ import { CopilotKitAgentDiscoveryError } from "@copilotkit/shared";
10
10
  export class StateResolver {
11
11
  @Query(() => LoadAgentStateResponse)
12
12
  async loadAgentState(@Ctx() ctx: GraphQLContext, @Arg("data") data: LoadAgentStateInput) {
13
- const agents = await ctx._copilotkit.runtime.getAllAgents(ctx);
14
- const hasAgent = agents.some((agent) => agent.name === data.agentName);
15
- if (!hasAgent) {
13
+ const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
14
+ const agent = agents.find((agent) => agent.name === data.agentName);
15
+ if (!agent) {
16
16
  throw new CopilotKitAgentDiscoveryError({
17
17
  agentName: data.agentName,
18
18
  availableAgents: agents.map((a) => ({ name: a.name, id: a.name })),