@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
@@ -1,11 +1,11 @@
1
1
  import { registerEnumType } from "type-graphql";
2
2
 
3
3
  export enum MessageRole {
4
- user = "user",
5
4
  assistant = "assistant",
5
+ developer = "developer",
6
6
  system = "system",
7
7
  tool = "tool",
8
- developer = "developer",
8
+ user = "user",
9
9
  }
10
10
 
11
11
  export enum CopilotRequestType {
@@ -11,7 +11,7 @@ registerEnumType(MessageStatusCode, {
11
11
  });
12
12
 
13
13
  @ObjectType()
14
- class BaseMessageStatus {
14
+ export class BaseMessageStatus {
15
15
  @Field(() => MessageStatusCode)
16
16
  code: MessageStatusCode;
17
17
  }
@@ -38,3 +38,5 @@ export const MessageStatusUnion = createUnionType({
38
38
  name: "MessageStatus",
39
39
  types: () => [PendingMessageStatus, SuccessMessageStatus, FailedMessageStatus] as const,
40
40
  });
41
+
42
+ export type MessageStatus = typeof MessageStatusUnion;
package/src/lib/index.ts CHANGED
@@ -8,4 +8,4 @@ export * from "./integrations";
8
8
  export * from "./logger";
9
9
  export * from "./runtime/copilot-runtime";
10
10
  export * from "./runtime/mcp-tools-utils";
11
- export * from "./runtime/langgraph/langgraph-agent";
11
+ export * from "./runtime/agent-integrations/langgraph.agent";
@@ -1,6 +1,7 @@
1
- import { createYoga } from "graphql-yoga";
1
+ import { createCopilotEndpointSingleRoute } from "@copilotkitnext/runtime";
2
2
  import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
3
3
  import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+ import { handle } from "hono/vercel";
4
5
 
5
6
  export function copilotRuntimeNextJSAppRouterEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
7
  const commonConfig = getCommonConfig(options);
@@ -22,16 +23,14 @@ export function copilotRuntimeNextJSAppRouterEndpoint(options: CreateCopilotRunt
22
23
  const logger = commonConfig.logging;
23
24
  logger.debug("Creating NextJS App Router endpoint");
24
25
 
25
- const yoga = createYoga({
26
- ...commonConfig,
27
- graphqlEndpoint: options.endpoint,
28
- fetchAPI: { Response: globalThis.Response },
26
+ const serviceAdapter = options.serviceAdapter;
27
+ options.runtime.handleServiceAdapter(serviceAdapter);
28
+
29
+ const copilotRoute = createCopilotEndpointSingleRoute({
30
+ runtime: options.runtime.instance,
31
+ basePath: options.baseUrl ?? options.endpoint,
29
32
  });
30
33
 
31
- return {
32
- handleRequest: yoga,
33
- GET: yoga as any,
34
- POST: yoga as any,
35
- OPTIONS: yoga as any,
36
- };
34
+ const handleRequest = handle(copilotRoute as any);
35
+ return { handleRequest };
37
36
  }
@@ -1,6 +1,6 @@
1
- import { YogaServerInstance, createYoga } from "graphql-yoga";
2
- import { CreateCopilotRuntimeServerOptions, GraphQLContext, getCommonConfig } from "../shared";
1
+ import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
3
2
  import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
3
+ import { copilotRuntimeNodeHttpEndpoint } from "../node-http";
4
4
 
5
5
  export const config = {
6
6
  api: {
@@ -8,8 +8,6 @@ export const config = {
8
8
  },
9
9
  };
10
10
 
11
- export type CopilotRuntimeServerInstance<T> = YogaServerInstance<T, Partial<GraphQLContext>>;
12
-
13
11
  // This import is needed to fix the type error
14
12
  // Fix is currently in TypeScript 5.5 beta, waiting for stable version
15
13
  // https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2066874644
@@ -17,7 +15,7 @@ export type {} from "@whatwg-node/server";
17
15
 
18
16
  export function copilotRuntimeNextJSPagesRouterEndpoint(
19
17
  options: CreateCopilotRuntimeServerOptions,
20
- ): CopilotRuntimeServerInstance<GraphQLContext> {
18
+ ) {
21
19
  const commonConfig = getCommonConfig(options);
22
20
 
23
21
  telemetry.setGlobalProperties({
@@ -37,10 +35,5 @@ export function copilotRuntimeNextJSPagesRouterEndpoint(
37
35
  const logger = commonConfig.logging;
38
36
  logger.debug("Creating NextJS Pages Router endpoint");
39
37
 
40
- const yoga = createYoga({
41
- ...commonConfig,
42
- graphqlEndpoint: options.endpoint,
43
- });
44
-
45
- return yoga;
38
+ return copilotRuntimeNodeHttpEndpoint(options);
46
39
  }
@@ -1,6 +1,38 @@
1
- import { createYoga } from "graphql-yoga";
2
1
  import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
3
2
  import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
3
+ import { createCopilotEndpointSingleRoute } from "@copilotkitnext/runtime";
4
+ import { IncomingMessage, ServerResponse } from "http";
5
+ import { Readable } from "node:stream";
6
+
7
+ export function readableStreamToNodeStream(webStream: ReadableStream): Readable {
8
+ const reader = webStream.getReader();
9
+
10
+ return new Readable({
11
+ async read() {
12
+ try {
13
+ const { done, value } = await reader.read();
14
+ if (done) {
15
+ this.push(null);
16
+ } else {
17
+ this.push(Buffer.from(value));
18
+ }
19
+ } catch (err) {
20
+ this.destroy(err as Error);
21
+ }
22
+ },
23
+ });
24
+ }
25
+
26
+ function getFullUrl(req: IncomingMessage): string {
27
+ const path = req.url || "/";
28
+ const host =
29
+ (req.headers["x-forwarded-host"] as string) || (req.headers.host as string) || "localhost";
30
+ const proto =
31
+ (req.headers["x-forwarded-proto"] as string) ||
32
+ ((req.socket as any).encrypted ? "https" : "http");
33
+
34
+ return `${proto}://${host}${path}`;
35
+ }
4
36
 
5
37
  export function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
38
  const commonConfig = getCommonConfig(options);
@@ -22,10 +54,37 @@ export function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServ
22
54
  const logger = commonConfig.logging;
23
55
  logger.debug("Creating Node HTTP endpoint");
24
56
 
25
- const yoga = createYoga({
26
- ...commonConfig,
27
- graphqlEndpoint: options.endpoint,
57
+ const serviceAdapter = options.serviceAdapter;
58
+ options.runtime.handleServiceAdapter(serviceAdapter);
59
+
60
+ const honoApp = createCopilotEndpointSingleRoute({
61
+ runtime: options.runtime.instance,
62
+ basePath: options.baseUrl ?? options.endpoint,
28
63
  });
29
64
 
30
- return yoga;
65
+ return async function handler(req: IncomingMessage, res: ServerResponse) {
66
+ const url = getFullUrl(req);
67
+ const hasBody = req.method !== "GET" && req.method !== "HEAD";
68
+
69
+ const request = new Request(url, {
70
+ method: req.method,
71
+ headers: req.headers as any,
72
+ body: hasBody ? (req as any) : undefined,
73
+ // Node/undici extension
74
+ duplex: hasBody ? "half" : undefined,
75
+ } as any);
76
+
77
+ const response = await honoApp.fetch(request);
78
+
79
+ res.statusCode = response.status;
80
+ response.headers.forEach((value, key) => {
81
+ res.setHeader(key, value);
82
+ });
83
+
84
+ if (response.body) {
85
+ readableStreamToNodeStream(response.body).pipe(res);
86
+ } else {
87
+ res.end();
88
+ }
89
+ };
31
90
  }
@@ -34,7 +34,7 @@ export type GraphQLContext = YogaInitialContext & {
34
34
  };
35
35
 
36
36
  export interface CreateCopilotRuntimeServerOptions {
37
- runtime: CopilotRuntime<any>;
37
+ runtime: CopilotRuntime;
38
38
  serviceAdapter: CopilotServiceAdapter;
39
39
  endpoint: string;
40
40
  baseUrl?: string;
@@ -1,3 +1,5 @@
1
+ import { RuntimeEventSource, RuntimeEventTypes } from "../service-adapters/events";
2
+
1
3
  export interface LLMRequestData {
2
4
  threadId?: string;
3
5
  runId?: string;
@@ -71,3 +73,88 @@ export interface CopilotObservabilityConfig {
71
73
  */
72
74
  hooks: CopilotObservabilityHooks;
73
75
  }
76
+
77
+ /**
78
+ * Setup progressive logging by wrapping the event stream
79
+ */
80
+ function setupProgressiveLogging(
81
+ eventSource: RuntimeEventSource,
82
+ streamedChunks: any[],
83
+ requestStartTime: number,
84
+ context: {
85
+ threadId?: string;
86
+ runId?: string;
87
+ model?: string;
88
+ provider?: string;
89
+ agentName?: string;
90
+ nodeName?: string;
91
+ },
92
+ publicApiKey?: string,
93
+ ): void {
94
+ if (this.observability?.enabled && this.observability.progressive && publicApiKey) {
95
+ // Keep reference to original stream function
96
+ const originalStream = eventSource.stream.bind(eventSource);
97
+
98
+ // Wrap the stream function to intercept events
99
+ eventSource.stream = async (callback) => {
100
+ await originalStream(async (eventStream$) => {
101
+ // Create subscription to capture streaming events
102
+ eventStream$.subscribe({
103
+ next: (event) => {
104
+ // Only log content chunks
105
+ if (event.type === RuntimeEventTypes.TextMessageContent) {
106
+ // Store the chunk
107
+ streamedChunks.push(event.content);
108
+
109
+ // Log each chunk separately for progressive mode
110
+ try {
111
+ const progressiveData: LLMResponseData = {
112
+ threadId: context.threadId || "",
113
+ runId: context.runId,
114
+ model: context.model,
115
+ output: event.content,
116
+ latency: Date.now() - requestStartTime,
117
+ timestamp: Date.now(),
118
+ provider: context.provider,
119
+ isProgressiveChunk: true,
120
+ agentName: context.agentName,
121
+ nodeName: context.nodeName,
122
+ };
123
+
124
+ // Use Promise to handle async logger without awaiting
125
+ Promise.resolve()
126
+ .then(() => {
127
+ this.observability.hooks.handleResponse(progressiveData);
128
+ })
129
+ .catch((error) => {
130
+ console.error("Error in progressive logging:", error);
131
+ });
132
+ } catch (error) {
133
+ console.error("Error preparing progressive log data:", error);
134
+ }
135
+ }
136
+ },
137
+ });
138
+
139
+ // Call the original callback with the event stream
140
+ await callback(eventStream$);
141
+ });
142
+ };
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Log error if observability is enabled
148
+ */
149
+ async function logObservabilityError(
150
+ errorData: LLMErrorData,
151
+ publicApiKey?: string,
152
+ ): Promise<void> {
153
+ if (this.observability?.enabled && publicApiKey) {
154
+ try {
155
+ await this.observability.hooks.handleError(errorData);
156
+ } catch (logError) {
157
+ console.error("Error logging LLM error:", logError);
158
+ }
159
+ }
160
+ }
@@ -56,6 +56,11 @@ export class LangGraphAgent extends AGUILangGraphAgent {
56
56
  super(config);
57
57
  }
58
58
 
59
+ // @ts-ignore
60
+ public clone() {
61
+ return new LangGraphAgent(this.config);
62
+ }
63
+
59
64
  dispatchEvent(event: ProcessedEvents) {
60
65
  if (event.type === EventType.CUSTOM) {
61
66
  // const event = processedEvent as unknown as CustomEvent;