@copilotkit/runtime 1.10.7-next.0 → 1.50.0-beta.0

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 (134) hide show
  1. package/CHANGELOG.md +0 -6
  2. package/dist/index.d.ts +1655 -27
  3. package/dist/index.js +2172 -5049
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +5441 -99
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/v2/index.d.ts +1 -0
  8. package/dist/v2/index.js +15 -0
  9. package/dist/v2/index.js.map +1 -0
  10. package/dist/v2/index.mjs +4 -0
  11. package/dist/v2/index.mjs.map +1 -0
  12. package/package.json +33 -21
  13. package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
  14. package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
  15. package/src/graphql/message-conversion/gql-to-agui.test.ts +1578 -0
  16. package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
  17. package/src/graphql/message-conversion/index.ts +2 -0
  18. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
  19. package/src/graphql/resolvers/copilot.resolver.ts +3 -48
  20. package/src/graphql/resolvers/state.resolver.ts +3 -2
  21. package/src/graphql/types/converted/index.ts +32 -6
  22. package/src/graphql/types/enums.ts +2 -2
  23. package/src/graphql/types/message-status.type.ts +3 -1
  24. package/src/lib/index.ts +1 -1
  25. package/src/lib/integrations/nextjs/app-router.ts +10 -11
  26. package/src/lib/integrations/nextjs/pages-router.ts +4 -11
  27. package/src/lib/integrations/node-http/index.ts +64 -5
  28. package/src/lib/integrations/shared.ts +1 -1
  29. package/src/lib/observability.ts +87 -0
  30. package/src/lib/runtime/{langgraph/langgraph-agent.ts → agent-integrations/langgraph.agent.ts} +5 -0
  31. package/src/lib/runtime/copilot-runtime.ts +346 -1333
  32. package/src/lib/runtime/types.ts +49 -0
  33. package/src/lib/runtime/utils.ts +87 -0
  34. package/src/lib/telemetry-client.ts +6 -5
  35. package/src/service-adapters/anthropic/anthropic-adapter.ts +5 -1
  36. package/src/service-adapters/bedrock/bedrock-adapter.ts +6 -1
  37. package/src/service-adapters/empty/empty-adapter.ts +3 -0
  38. package/src/service-adapters/events.ts +0 -254
  39. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +5 -1
  40. package/src/service-adapters/google/google-genai-adapter.ts +7 -1
  41. package/src/service-adapters/groq/groq-adapter.ts +5 -1
  42. package/src/service-adapters/langchain/langchain-adapter.ts +3 -0
  43. package/src/service-adapters/openai/openai-adapter.ts +5 -1
  44. package/src/service-adapters/openai/openai-assistant-adapter.ts +4 -0
  45. package/src/service-adapters/service-adapter.ts +3 -0
  46. package/src/service-adapters/unify/unify-adapter.ts +6 -1
  47. package/src/v2/index.ts +2 -0
  48. package/tsup.config.ts +2 -1
  49. package/dist/chunk-27JKTS6P.mjs +0 -1704
  50. package/dist/chunk-27JKTS6P.mjs.map +0 -1
  51. package/dist/chunk-2OZAGFV3.mjs +0 -43
  52. package/dist/chunk-2OZAGFV3.mjs.map +0 -1
  53. package/dist/chunk-5BW5IBTZ.mjs +0 -80
  54. package/dist/chunk-5BW5IBTZ.mjs.map +0 -1
  55. package/dist/chunk-AMUJQ6IR.mjs +0 -50
  56. package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
  57. package/dist/chunk-BMIYSM5W.mjs +0 -25
  58. package/dist/chunk-BMIYSM5W.mjs.map +0 -1
  59. package/dist/chunk-FDTCG47E.mjs +0 -25
  60. package/dist/chunk-FDTCG47E.mjs.map +0 -1
  61. package/dist/chunk-FHD4JECV.mjs +0 -33
  62. package/dist/chunk-FHD4JECV.mjs.map +0 -1
  63. package/dist/chunk-LRCKLBMO.mjs +0 -6020
  64. package/dist/chunk-LRCKLBMO.mjs.map +0 -1
  65. package/dist/chunk-R7RMYEPZ.mjs +0 -175
  66. package/dist/chunk-R7RMYEPZ.mjs.map +0 -1
  67. package/dist/chunk-SHBDMA63.mjs +0 -141
  68. package/dist/chunk-SHBDMA63.mjs.map +0 -1
  69. package/dist/chunk-XWBDEXDA.mjs +0 -153
  70. package/dist/chunk-XWBDEXDA.mjs.map +0 -1
  71. package/dist/graphql/types/base/index.d.ts +0 -6
  72. package/dist/graphql/types/base/index.js +0 -63
  73. package/dist/graphql/types/base/index.js.map +0 -1
  74. package/dist/graphql/types/base/index.mjs +0 -8
  75. package/dist/graphql/types/base/index.mjs.map +0 -1
  76. package/dist/graphql/types/converted/index.d.ts +0 -2
  77. package/dist/graphql/types/converted/index.js +0 -200
  78. package/dist/graphql/types/converted/index.js.map +0 -1
  79. package/dist/graphql/types/converted/index.mjs +0 -19
  80. package/dist/graphql/types/converted/index.mjs.map +0 -1
  81. package/dist/groq-adapter-c8aec5c5.d.ts +0 -321
  82. package/dist/index-96b330da.d.ts +0 -119
  83. package/dist/langserve-0c6100e3.d.ts +0 -257
  84. package/dist/lib/cloud/index.d.ts +0 -6
  85. package/dist/lib/cloud/index.js +0 -18
  86. package/dist/lib/cloud/index.js.map +0 -1
  87. package/dist/lib/cloud/index.mjs +0 -1
  88. package/dist/lib/cloud/index.mjs.map +0 -1
  89. package/dist/lib/index.d.ts +0 -212
  90. package/dist/lib/index.js +0 -7843
  91. package/dist/lib/index.js.map +0 -1
  92. package/dist/lib/index.mjs +0 -76
  93. package/dist/lib/index.mjs.map +0 -1
  94. package/dist/lib/integrations/index.d.ts +0 -34
  95. package/dist/lib/integrations/index.js +0 -3052
  96. package/dist/lib/integrations/index.js.map +0 -1
  97. package/dist/lib/integrations/index.mjs +0 -37
  98. package/dist/lib/integrations/index.mjs.map +0 -1
  99. package/dist/lib/integrations/nest/index.d.ts +0 -15
  100. package/dist/lib/integrations/nest/index.js +0 -2959
  101. package/dist/lib/integrations/nest/index.js.map +0 -1
  102. package/dist/lib/integrations/nest/index.mjs +0 -14
  103. package/dist/lib/integrations/nest/index.mjs.map +0 -1
  104. package/dist/lib/integrations/node-express/index.d.ts +0 -15
  105. package/dist/lib/integrations/node-express/index.js +0 -2959
  106. package/dist/lib/integrations/node-express/index.js.map +0 -1
  107. package/dist/lib/integrations/node-express/index.mjs +0 -14
  108. package/dist/lib/integrations/node-express/index.mjs.map +0 -1
  109. package/dist/lib/integrations/node-http/index.d.ts +0 -15
  110. package/dist/lib/integrations/node-http/index.js +0 -2945
  111. package/dist/lib/integrations/node-http/index.js.map +0 -1
  112. package/dist/lib/integrations/node-http/index.mjs +0 -13
  113. package/dist/lib/integrations/node-http/index.mjs.map +0 -1
  114. package/dist/service-adapters/index.d.ts +0 -162
  115. package/dist/service-adapters/index.js +0 -1787
  116. package/dist/service-adapters/index.js.map +0 -1
  117. package/dist/service-adapters/index.mjs +0 -34
  118. package/dist/service-adapters/index.mjs.map +0 -1
  119. package/dist/service-adapters/shared/index.d.ts +0 -9
  120. package/dist/service-adapters/shared/index.js +0 -72
  121. package/dist/service-adapters/shared/index.js.map +0 -1
  122. package/dist/service-adapters/shared/index.mjs +0 -8
  123. package/dist/service-adapters/shared/index.mjs.map +0 -1
  124. package/dist/shared-0a7346ce.d.ts +0 -466
  125. package/dist/utils/index.d.ts +0 -65
  126. package/dist/utils/index.js +0 -175
  127. package/dist/utils/index.js.map +0 -1
  128. package/dist/utils/index.mjs +0 -12
  129. package/dist/utils/index.mjs.map +0 -1
  130. package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +0 -246
  131. package/src/lib/runtime/agui-action.ts +0 -180
  132. package/src/lib/runtime/remote-action-constructors.ts +0 -331
  133. package/src/lib/runtime/remote-actions.ts +0 -217
  134. package/src/lib/runtime/remote-lg-action.ts +0 -1006
@@ -0,0 +1,49 @@
1
+ import { GraphQLContext } from "../integrations";
2
+ import { ActionInput } from "../../graphql/inputs/action.input";
3
+ import { Message } from "../../graphql/types/converted";
4
+ import { MetaEventInput } from "../../graphql/inputs/meta-event.input";
5
+
6
+ export interface BaseEndpointDefinition<TActionType extends EndpointType> {
7
+ type?: TActionType;
8
+ }
9
+
10
+ export interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.CopilotKit> {
11
+ url: string;
12
+ onBeforeRequest?: ({ ctx }: { ctx: GraphQLContext }) => {
13
+ headers?: Record<string, string> | undefined;
14
+ };
15
+ }
16
+
17
+ export interface LangGraphPlatformAgent {
18
+ name: string;
19
+ description: string;
20
+ assistantId?: string;
21
+ }
22
+
23
+ export interface LangGraphPlatformEndpoint
24
+ extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
25
+ deploymentUrl: string;
26
+ langsmithApiKey?: string | null;
27
+ agents: LangGraphPlatformAgent[];
28
+ }
29
+
30
+ export type RemoteActionInfoResponse = {
31
+ actions: any[];
32
+ agents: any[];
33
+ };
34
+
35
+ export type RemoteAgentHandlerParams = {
36
+ name: string;
37
+ actionInputsWithoutAgents: ActionInput[];
38
+ threadId?: string;
39
+ nodeName?: string;
40
+ additionalMessages?: Message[];
41
+ metaEvents?: MetaEventInput[];
42
+ };
43
+
44
+ export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
45
+
46
+ export enum EndpointType {
47
+ CopilotKit = "copilotKit",
48
+ LangGraphPlatform = "langgraph-platform",
49
+ }
@@ -0,0 +1,87 @@
1
+ import { GraphQLContext } from "../integrations";
2
+ import { Logger } from "pino";
3
+ import { CopilotKitEndpoint, RemoteActionInfoResponse } from "./types";
4
+ import {
5
+ Action,
6
+ CopilotKitError,
7
+ CopilotKitLowLevelError,
8
+ ResolvedCopilotKitError,
9
+ } from "@copilotkit/shared";
10
+
11
+ async function fetchRemoteInfo({
12
+ url,
13
+ onBeforeRequest,
14
+ graphqlContext,
15
+ logger,
16
+ frontendUrl,
17
+ }: {
18
+ url: string;
19
+ onBeforeRequest?: CopilotKitEndpoint["onBeforeRequest"];
20
+ graphqlContext: GraphQLContext;
21
+ logger: Logger;
22
+ frontendUrl?: string;
23
+ }): Promise<RemoteActionInfoResponse> {
24
+ logger.debug({ url }, "Fetching actions from url");
25
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
26
+
27
+ const fetchUrl = `${url}/info`;
28
+ try {
29
+ const response = await fetch(fetchUrl, {
30
+ method: "POST",
31
+ headers,
32
+ body: JSON.stringify({ properties: graphqlContext.properties, frontendUrl }),
33
+ });
34
+
35
+ if (!response.ok) {
36
+ logger.error(
37
+ { url, status: response.status, body: await response.text() },
38
+ "Failed to fetch actions from url",
39
+ );
40
+ throw new ResolvedCopilotKitError({
41
+ status: response.status,
42
+ url: fetchUrl,
43
+ isRemoteEndpoint: true,
44
+ });
45
+ }
46
+
47
+ const json = await response.json();
48
+ logger.debug({ json }, "Fetched actions from url");
49
+ return json;
50
+ } catch (error) {
51
+ if (error instanceof CopilotKitError) {
52
+ throw error;
53
+ }
54
+ throw new CopilotKitLowLevelError({ error, url: fetchUrl });
55
+ }
56
+ }
57
+
58
+ // Utility to determine if an error is a user configuration issue vs system error
59
+ export function isUserConfigurationError(error: any): boolean {
60
+ return (
61
+ (error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError) &&
62
+ (error.code === "NETWORK_ERROR" ||
63
+ error.code === "AUTHENTICATION_ERROR" ||
64
+ error.statusCode === 401 ||
65
+ error.statusCode === 403 ||
66
+ error.message?.toLowerCase().includes("authentication") ||
67
+ error.message?.toLowerCase().includes("api key"))
68
+ );
69
+ }
70
+
71
+ export function createHeaders(
72
+ onBeforeRequest: CopilotKitEndpoint["onBeforeRequest"],
73
+ graphqlContext: GraphQLContext,
74
+ ) {
75
+ const headers = {
76
+ "Content-Type": "application/json",
77
+ };
78
+
79
+ if (onBeforeRequest) {
80
+ const { headers: additionalHeaders } = onBeforeRequest({ ctx: graphqlContext });
81
+ if (additionalHeaders) {
82
+ Object.assign(headers, additionalHeaders);
83
+ }
84
+ }
85
+
86
+ return headers;
87
+ }
@@ -1,9 +1,9 @@
1
1
  import { TelemetryClient } from "@copilotkit/shared";
2
- import { EndpointType, LangGraphPlatformEndpoint } from "./runtime/remote-actions";
3
2
  import { createHash } from "node:crypto";
4
3
  import { CopilotRuntime, resolveEndpointType } from "./runtime/copilot-runtime";
5
4
  import { RuntimeInstanceCreatedInfo } from "@copilotkit/shared/src/telemetry/events";
6
5
  import { CreateCopilotRuntimeServerOptions } from "./integrations/shared";
6
+ import { EndpointType, LangGraphPlatformEndpoint } from "./runtime/types";
7
7
  const packageJson = require("../../package.json");
8
8
 
9
9
  const telemetryClient = new TelemetryClient({
@@ -15,7 +15,8 @@ export function getRuntimeInstanceTelemetryInfo(
15
15
  options: CreateCopilotRuntimeServerOptions,
16
16
  ): RuntimeInstanceCreatedInfo {
17
17
  const runtime = options.runtime;
18
- const endpointsInfo = runtime.remoteEndpointDefinitions.reduce(
18
+ const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];
19
+ const endpointsInfo = remoteEndpoints.reduce(
19
20
  (acc, endpoint) => {
20
21
  let info = { ...acc };
21
22
 
@@ -49,10 +50,10 @@ export function getRuntimeInstanceTelemetryInfo(
49
50
  const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;
50
51
 
51
52
  return {
52
- actionsAmount: runtime.actions.length,
53
- endpointsAmount: runtime.remoteEndpointDefinitions.length,
53
+ actionsAmount: runtime.params?.actions?.length ?? 0,
54
+ endpointsAmount: remoteEndpoints.length,
54
55
  endpointTypes: endpointsInfo.endpointTypes,
55
- agentsAmount: endpointsInfo.agentsAmount,
56
+ agentsAmount: Object.keys(runtime.instance.agents).length,
56
57
  hashedLgcKey: endpointsInfo.hashedKey,
57
58
  "cloud.api_key_provided": apiKeyProvided,
58
59
  ...(apiKeyProvided ? { "cloud.public_api_key": publicApiKey } : {}),
@@ -71,13 +71,17 @@ export interface AnthropicAdapterParams {
71
71
  }
72
72
 
73
73
  export class AnthropicAdapter implements CopilotServiceAdapter {
74
- private model: string = DEFAULT_MODEL;
74
+ public model: string = DEFAULT_MODEL;
75
+ public provider = "anthropic";
75
76
  private promptCaching: AnthropicPromptCachingConfig;
76
77
 
77
78
  private _anthropic: Anthropic;
78
79
  public get anthropic(): Anthropic {
79
80
  return this._anthropic;
80
81
  }
82
+ public get name() {
83
+ return "AnthropicAdapter";
84
+ }
81
85
 
82
86
  constructor(params?: AnthropicAdapterParams) {
83
87
  this._anthropic = params?.anthropic || new Anthropic({});
@@ -44,12 +44,17 @@ export interface BedrockAdapterParams {
44
44
  };
45
45
  }
46
46
 
47
+ const DEFAULT_MODEL = "amazon.nova-lite-v1:0";
48
+
47
49
  export class BedrockAdapter extends LangChainAdapter {
50
+ public provider = "bedrock";
51
+ public model: string = DEFAULT_MODEL;
48
52
  constructor(options?: BedrockAdapterParams) {
49
53
  super({
50
54
  chainFn: async ({ messages, tools, threadId }) => {
55
+ this.model = options?.model ?? "amazon.nova-lite-v1:0";
51
56
  const model = new ChatBedrockConverse({
52
- model: options?.model ?? "amazon.nova-lite-v1:0",
57
+ model: this.model,
53
58
  region: options?.region ?? "us-east-1",
54
59
  credentials: options?.credentials
55
60
  ? {
@@ -30,6 +30,9 @@ export class EmptyAdapter implements CopilotServiceAdapter {
30
30
  threadId: request.threadId || randomUUID(),
31
31
  };
32
32
  }
33
+ public get name() {
34
+ return "EmptyAdapter";
35
+ }
33
36
  }
34
37
 
35
38
  export const ExperimentalEmptyAdapter = EmptyAdapter;
@@ -23,7 +23,6 @@ import {
23
23
  import { ActionInput } from "../graphql/inputs/action.input";
24
24
  import { ActionExecutionMessage, ResultMessage, TextMessage } from "../graphql/types/converted";
25
25
  import { GuardrailsResult } from "../graphql/types/guardrails-result.type";
26
- import { isRemoteAgentAction } from "../lib/runtime/remote-actions";
27
26
  import { generateHelpfulErrorMessage } from "../lib/streaming";
28
27
  import telemetry from "../lib/telemetry-client";
29
28
  import { streamLangChainResponse } from "./langchain/utils";
@@ -262,259 +261,6 @@ export class RuntimeEventSource {
262
261
  async stream(callback: EventSourceCallback): Promise<void> {
263
262
  this.callback = callback;
264
263
  }
265
-
266
- sendErrorMessageToChat(message = "An error occurred. Please try again.") {
267
- const errorMessage = `❌ ${message}`;
268
- if (!this.callback) {
269
- this.stream(async (eventStream$) => {
270
- eventStream$.sendTextMessage(randomId(), errorMessage);
271
- });
272
- } else {
273
- this.eventStream$.sendTextMessage(randomId(), errorMessage);
274
- }
275
- }
276
-
277
- processRuntimeEvents({
278
- serverSideActions,
279
- guardrailsResult$,
280
- actionInputsWithoutAgents,
281
- threadId,
282
- }: {
283
- serverSideActions: Action<any>[];
284
- guardrailsResult$?: Subject<GuardrailsResult>;
285
- actionInputsWithoutAgents: ActionInput[];
286
- threadId: string;
287
- }) {
288
- this.callback(this.eventStream$).catch(async (error) => {
289
- // Convert streaming errors to structured errors, but preserve already structured ones
290
- const structuredError = ensureStructuredError(error, convertStreamingErrorToStructured);
291
-
292
- // Call the runtime error handler if provided
293
- if (this.errorHandler && this.errorContext) {
294
- try {
295
- await this.errorHandler(structuredError, this.errorContext);
296
- } catch (errorHandlerError) {
297
- console.error("Error in streaming error handler:", errorHandlerError);
298
- }
299
- }
300
-
301
- this.eventStream$.error(structuredError);
302
- this.eventStream$.complete();
303
- });
304
- return this.eventStream$.pipe(
305
- // track state
306
- scan(
307
- (acc, event) => {
308
- // It seems like this is needed so that rxjs recognizes the object has changed
309
- // This fixes an issue where action were executed multiple times
310
- // Not investigating further for now (Markus)
311
- acc = { ...acc };
312
-
313
- if (event.type === RuntimeEventTypes.ActionExecutionStart) {
314
- acc.callActionServerSide =
315
- serverSideActions.find((action) => action.name === event.actionName) !== undefined;
316
- acc.args = "";
317
- acc.actionExecutionId = event.actionExecutionId;
318
- if (acc.callActionServerSide) {
319
- acc.action = serverSideActions.find((action) => action.name === event.actionName);
320
- }
321
- acc.actionExecutionParentMessageId = event.parentMessageId;
322
- } else if (event.type === RuntimeEventTypes.ActionExecutionArgs) {
323
- acc.args += event.args;
324
- }
325
-
326
- acc.event = event;
327
-
328
- return acc;
329
- },
330
- {
331
- event: null,
332
- callActionServerSide: false,
333
- args: "",
334
- actionExecutionId: null,
335
- action: null,
336
- actionExecutionParentMessageId: null,
337
- } as RuntimeEventWithState,
338
- ),
339
- concatMap((eventWithState) => {
340
- if (
341
- eventWithState.event!.type === RuntimeEventTypes.ActionExecutionEnd &&
342
- eventWithState.callActionServerSide
343
- ) {
344
- const toolCallEventStream$ = new RuntimeEventSubject();
345
- executeAction(
346
- toolCallEventStream$,
347
- guardrailsResult$ ? guardrailsResult$ : null,
348
- eventWithState.action!,
349
- eventWithState.args,
350
- eventWithState.actionExecutionParentMessageId,
351
- eventWithState.actionExecutionId,
352
- actionInputsWithoutAgents,
353
- threadId,
354
- ).catch((error) => {});
355
-
356
- telemetry.capture("oss.runtime.server_action_executed", {});
357
- return concat(of(eventWithState.event!), toolCallEventStream$).pipe(
358
- catchError((error) => {
359
- // Convert streaming errors to structured errors and send as action result, but preserve already structured ones
360
- const structuredError = ensureStructuredError(
361
- error,
362
- convertStreamingErrorToStructured,
363
- );
364
-
365
- // Call the runtime error handler if provided
366
- if (this.errorHandler && this.errorContext) {
367
- // Use from() to handle async error handler
368
- from(
369
- this.errorHandler(structuredError, {
370
- ...this.errorContext,
371
- action: {
372
- name: eventWithState.action!.name,
373
- executionId: eventWithState.actionExecutionId,
374
- },
375
- }),
376
- ).subscribe({
377
- error: (errorHandlerError) => {
378
- console.error("Error in action execution error handler:", errorHandlerError);
379
- },
380
- });
381
- }
382
-
383
- toolCallEventStream$.sendActionExecutionResult({
384
- actionExecutionId: eventWithState.actionExecutionId!,
385
- actionName: eventWithState.action!.name,
386
- error: {
387
- code: structuredError.code,
388
- message: structuredError.message,
389
- },
390
- });
391
-
392
- return EMPTY;
393
- }),
394
- );
395
- } else {
396
- return of(eventWithState.event!);
397
- }
398
- }),
399
- );
400
- }
401
- }
402
-
403
- async function executeAction(
404
- eventStream$: RuntimeEventSubject,
405
- guardrailsResult$: Subject<GuardrailsResult> | null,
406
- action: Action<any>,
407
- actionArguments: string,
408
- actionExecutionParentMessageId: string | null,
409
- actionExecutionId: string,
410
- actionInputsWithoutAgents: ActionInput[],
411
- threadId: string,
412
- ) {
413
- if (guardrailsResult$) {
414
- const { status } = await firstValueFrom(guardrailsResult$);
415
-
416
- if (status === "denied") {
417
- eventStream$.complete();
418
- return;
419
- }
420
- }
421
-
422
- // Prepare arguments for function calling
423
- let args: Record<string, any>[] = [];
424
- if (actionArguments) {
425
- try {
426
- args = JSON.parse(actionArguments);
427
- } catch (e) {
428
- console.error("Action argument unparsable", { actionArguments });
429
- eventStream$.sendActionExecutionResult({
430
- actionExecutionId,
431
- actionName: action.name,
432
- error: {
433
- code: "INVALID_ARGUMENTS",
434
- message: "Failed to parse action arguments",
435
- },
436
- });
437
- return;
438
- }
439
- }
440
-
441
- // handle LangGraph agents
442
- if (isRemoteAgentAction(action)) {
443
- const result = `${action.name} agent started`;
444
-
445
- const agentExecution = plainToInstance(ActionExecutionMessage, {
446
- id: actionExecutionId,
447
- createdAt: new Date(),
448
- name: action.name,
449
- arguments: JSON.parse(actionArguments),
450
- parentMessageId: actionExecutionParentMessageId ?? actionExecutionId,
451
- });
452
-
453
- const agentExecutionResult = plainToInstance(ResultMessage, {
454
- id: "result-" + actionExecutionId,
455
- createdAt: new Date(),
456
- actionExecutionId,
457
- actionName: action.name,
458
- result,
459
- });
460
-
461
- eventStream$.sendActionExecutionResult({
462
- actionExecutionId,
463
- actionName: action.name,
464
- result,
465
- });
466
-
467
- const stream = await action.remoteAgentHandler({
468
- name: action.name,
469
- threadId,
470
- actionInputsWithoutAgents,
471
- additionalMessages: [agentExecution, agentExecutionResult],
472
- });
473
-
474
- // forward to eventStream$
475
- from(stream).subscribe({
476
- next: (event) => eventStream$.next(event),
477
- error: (err) => {
478
- // Preserve already structured CopilotKit errors, only convert unstructured errors
479
- const structuredError = ensureStructuredError(err, convertStreamingErrorToStructured);
480
- eventStream$.sendActionExecutionResult({
481
- actionExecutionId,
482
- actionName: action.name,
483
- error: {
484
- code: structuredError.code,
485
- message: structuredError.message,
486
- },
487
- });
488
- eventStream$.complete();
489
- },
490
- complete: () => eventStream$.complete(),
491
- });
492
- } else {
493
- // call the function
494
- try {
495
- const result = await action.handler?.(args);
496
- await streamLangChainResponse({
497
- result,
498
- eventStream$,
499
- actionExecution: {
500
- name: action.name,
501
- id: actionExecutionId,
502
- returnDirect: action.additionalConfig?.returnDirect,
503
- },
504
- });
505
- } catch (e) {
506
- console.error("Error in action handler", e);
507
- eventStream$.sendActionExecutionResult({
508
- actionExecutionId,
509
- actionName: action.name,
510
- error: {
511
- code: "HANDLER_ERROR",
512
- message: e.message,
513
- },
514
- });
515
- eventStream$.complete();
516
- }
517
- }
518
264
  }
519
265
 
520
266
  function convertStreamingErrorToStructured(error: any): CopilotKitError {
@@ -33,7 +33,11 @@ interface OllamaAdapterOptions {
33
33
  }
34
34
 
35
35
  export class ExperimentalOllamaAdapter implements CopilotServiceAdapter {
36
- private model: string;
36
+ public model: string;
37
+ public provider = "ollama";
38
+ public get name() {
39
+ return "OllamaAdapter";
40
+ }
37
41
 
38
42
  constructor(options?: OllamaAdapterOptions) {
39
43
  if (options?.model) {
@@ -29,7 +29,12 @@ interface GoogleGenerativeAIAdapterOptions {
29
29
  apiKey?: string;
30
30
  }
31
31
 
32
+ const DEFAULT_MODEL = "gemini-1.5-pro";
33
+
32
34
  export class GoogleGenerativeAIAdapter extends LangChainAdapter {
35
+ public provider = "google";
36
+ public model: string = DEFAULT_MODEL;
37
+
33
38
  constructor(options?: GoogleGenerativeAIAdapterOptions) {
34
39
  super({
35
40
  chainFn: async ({ messages, tools, threadId }) => {
@@ -49,9 +54,10 @@ export class GoogleGenerativeAIAdapter extends LangChainAdapter {
49
54
  );
50
55
  });
51
56
 
57
+ this.model = options?.model ?? "gemini-1.5-pro";
52
58
  const model = new ChatGoogle({
53
59
  apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,
54
- modelName: options?.model ?? "gemini-1.5-pro",
60
+ modelName: this.model,
55
61
  apiVersion: "v1beta",
56
62
  }).bindTools(tools);
57
63
 
@@ -54,13 +54,17 @@ export interface GroqAdapterParams {
54
54
  }
55
55
 
56
56
  export class GroqAdapter implements CopilotServiceAdapter {
57
- private model: string = DEFAULT_MODEL;
57
+ public model: string = DEFAULT_MODEL;
58
+ public provider = "groq";
58
59
 
59
60
  private disableParallelToolCalls: boolean = false;
60
61
  private _groq: Groq;
61
62
  public get groq(): Groq {
62
63
  return this._groq;
63
64
  }
65
+ public get name() {
66
+ return "GroqAdapter";
67
+ }
64
68
 
65
69
  constructor(params?: GroqAdapterParams) {
66
70
  this._groq = params?.groq || new Groq({});
@@ -66,6 +66,9 @@ export class LangChainAdapter implements CopilotServiceAdapter {
66
66
  /**
67
67
  * To use LangChain as a backend, provide a handler function to the adapter with your custom LangChain logic.
68
68
  */
69
+ public get name() {
70
+ return "LangChainAdapter";
71
+ }
69
72
  constructor(private options: LangChainAdapterOptions) {}
70
73
 
71
74
  async process(
@@ -96,7 +96,8 @@ export interface OpenAIAdapterParams {
96
96
  }
97
97
 
98
98
  export class OpenAIAdapter implements CopilotServiceAdapter {
99
- private model: string = DEFAULT_MODEL;
99
+ public model: string = DEFAULT_MODEL;
100
+ public provider = "openai";
100
101
 
101
102
  private disableParallelToolCalls: boolean = false;
102
103
  private _openai: OpenAI;
@@ -105,6 +106,9 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
105
106
  public get openai(): OpenAI {
106
107
  return this._openai;
107
108
  }
109
+ public get name() {
110
+ return "OpenAIAdapter";
111
+ }
108
112
 
109
113
  constructor(params?: OpenAIAdapterParams) {
110
114
  this._openai = params?.openai || new OpenAI({});
@@ -91,6 +91,10 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
91
91
  private disableParallelToolCalls: boolean;
92
92
  private keepSystemRole: boolean = false;
93
93
 
94
+ public get name() {
95
+ return "OpenAIAssistantAdapter";
96
+ }
97
+
94
98
  constructor(params: OpenAIAssistantAdapterParams) {
95
99
  this.openai = params.openai || new OpenAI({});
96
100
  this.codeInterpreterEnabled = params.codeInterpreterEnabled === false || true;
@@ -32,7 +32,10 @@ export interface CopilotRuntimeChatCompletionResponse {
32
32
  }
33
33
 
34
34
  export interface CopilotServiceAdapter {
35
+ provider?: string;
36
+ model?: string;
35
37
  process(
36
38
  request: CopilotRuntimeChatCompletionRequest,
37
39
  ): Promise<CopilotRuntimeChatCompletionResponse>;
40
+ name?: string;
38
41
  }
@@ -33,8 +33,13 @@ export interface UnifyAdapterParams {
33
33
 
34
34
  export class UnifyAdapter implements CopilotServiceAdapter {
35
35
  private apiKey: string;
36
- private model: string;
36
+ public model: string;
37
37
  private start: boolean;
38
+ public provider = "unify";
39
+
40
+ public get name() {
41
+ return "UnifyAdapter";
42
+ }
38
43
 
39
44
  constructor(options?: UnifyAdapterParams) {
40
45
  if (options?.apiKey) {
@@ -0,0 +1,2 @@
1
+ import "reflect-metadata";
2
+ export * from "@copilotkitnext/runtime";
package/tsup.config.ts CHANGED
@@ -2,7 +2,7 @@ import { defineConfig, Options } from "tsup";
2
2
 
3
3
  export default defineConfig((options: Options) => ({
4
4
  ...options,
5
- entry: ["src/**/index.ts"],
5
+ entry: ["src/index.ts", "src/v2/index.ts"],
6
6
  format: ["esm", "cjs"],
7
7
  dts: true,
8
8
  minify: false,
@@ -13,4 +13,5 @@ export default defineConfig((options: Options) => ({
13
13
  "**/*.test.tsx", // Exclude TypeScript React test files
14
14
  "**/__tests__/*", // Exclude any files inside a __tests__ directory
15
15
  ],
16
+ treeshake: true,
16
17
  }));