@copilotkit/runtime 0.0.0-fix-debug-infosys-20251107151227 → 0.0.0-fix-restore-handle-method-node-http-20251222114321

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 (142) hide show
  1. package/CHANGELOG.md +259 -3
  2. package/dist/index.d.ts +1493 -28
  3. package/dist/index.js +2568 -5467
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +5429 -99
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/{lib/index.d.ts → langgraph.d.ts} +104 -32
  8. package/dist/langgraph.js +211 -0
  9. package/dist/langgraph.js.map +1 -0
  10. package/dist/{chunk-XPALJ76U.mjs → langgraph.mjs} +57 -26
  11. package/dist/langgraph.mjs.map +1 -0
  12. package/dist/v2/index.d.ts +2 -0
  13. package/dist/v2/index.js +22 -0
  14. package/dist/v2/index.js.map +1 -0
  15. package/dist/v2/index.mjs +5 -0
  16. package/dist/v2/index.mjs.map +1 -0
  17. package/package.json +64 -20
  18. package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
  19. package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
  20. package/src/graphql/message-conversion/gql-to-agui.test.ts +1580 -0
  21. package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
  22. package/src/graphql/message-conversion/index.ts +2 -0
  23. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
  24. package/src/graphql/resolvers/copilot.resolver.ts +3 -51
  25. package/src/graphql/resolvers/state.resolver.ts +3 -2
  26. package/src/graphql/types/converted/index.ts +32 -6
  27. package/src/graphql/types/enums.ts +2 -2
  28. package/src/graphql/types/message-status.type.ts +3 -1
  29. package/src/langgraph.ts +1 -0
  30. package/src/lib/index.ts +42 -1
  31. package/src/lib/integrations/nextjs/app-router.ts +12 -11
  32. package/src/lib/integrations/nextjs/pages-router.ts +4 -11
  33. package/src/lib/integrations/node-http/index.ts +10 -5
  34. package/src/lib/integrations/shared.ts +1 -1
  35. package/src/lib/observability.ts +87 -0
  36. package/src/lib/runtime/{langgraph/langgraph-agent.ts → agent-integrations/langgraph/agent.ts} +10 -30
  37. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +34 -0
  38. package/src/lib/runtime/agent-integrations/langgraph/index.ts +2 -0
  39. package/src/lib/runtime/copilot-runtime.ts +387 -1360
  40. package/src/lib/runtime/telemetry-agent-runner.ts +139 -0
  41. package/src/lib/runtime/types.ts +49 -0
  42. package/src/lib/runtime/utils.ts +87 -0
  43. package/src/lib/telemetry-client.ts +6 -5
  44. package/src/service-adapters/anthropic/anthropic-adapter.ts +21 -4
  45. package/src/service-adapters/bedrock/bedrock-adapter.ts +10 -2
  46. package/src/service-adapters/empty/empty-adapter.ts +3 -0
  47. package/src/service-adapters/events.ts +0 -254
  48. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -2
  49. package/src/service-adapters/google/google-genai-adapter.ts +33 -7
  50. package/src/service-adapters/groq/groq-adapter.ts +21 -4
  51. package/src/service-adapters/langchain/langchain-adapter.ts +8 -3
  52. package/src/service-adapters/langchain/langserve.ts +2 -1
  53. package/src/service-adapters/openai/openai-adapter.ts +22 -4
  54. package/src/service-adapters/openai/openai-assistant-adapter.ts +30 -11
  55. package/src/service-adapters/service-adapter.ts +3 -0
  56. package/src/service-adapters/unify/unify-adapter.ts +9 -2
  57. package/src/v2/index.ts +3 -0
  58. package/tsup.config.ts +6 -2
  59. package/dist/chunk-27JKTS6P.mjs +0 -1704
  60. package/dist/chunk-27JKTS6P.mjs.map +0 -1
  61. package/dist/chunk-2DHC2YFK.mjs +0 -6026
  62. package/dist/chunk-2DHC2YFK.mjs.map +0 -1
  63. package/dist/chunk-2OZAGFV3.mjs +0 -43
  64. package/dist/chunk-2OZAGFV3.mjs.map +0 -1
  65. package/dist/chunk-5HHH4SZ3.mjs +0 -25
  66. package/dist/chunk-5HHH4SZ3.mjs.map +0 -1
  67. package/dist/chunk-AMUJQ6IR.mjs +0 -50
  68. package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
  69. package/dist/chunk-FHD4JECV.mjs +0 -33
  70. package/dist/chunk-FHD4JECV.mjs.map +0 -1
  71. package/dist/chunk-FVG3IQG7.mjs +0 -25
  72. package/dist/chunk-FVG3IQG7.mjs.map +0 -1
  73. package/dist/chunk-QU2FLIQB.mjs +0 -80
  74. package/dist/chunk-QU2FLIQB.mjs.map +0 -1
  75. package/dist/chunk-SHBDMA63.mjs +0 -141
  76. package/dist/chunk-SHBDMA63.mjs.map +0 -1
  77. package/dist/chunk-XPALJ76U.mjs.map +0 -1
  78. package/dist/chunk-XWBDEXDA.mjs +0 -153
  79. package/dist/chunk-XWBDEXDA.mjs.map +0 -1
  80. package/dist/graphql/types/base/index.d.ts +0 -6
  81. package/dist/graphql/types/base/index.js +0 -63
  82. package/dist/graphql/types/base/index.js.map +0 -1
  83. package/dist/graphql/types/base/index.mjs +0 -8
  84. package/dist/graphql/types/base/index.mjs.map +0 -1
  85. package/dist/graphql/types/converted/index.d.ts +0 -2
  86. package/dist/graphql/types/converted/index.js +0 -200
  87. package/dist/graphql/types/converted/index.js.map +0 -1
  88. package/dist/graphql/types/converted/index.mjs +0 -19
  89. package/dist/graphql/types/converted/index.mjs.map +0 -1
  90. package/dist/groq-adapter-c8aec5c5.d.ts +0 -321
  91. package/dist/index-96b330da.d.ts +0 -119
  92. package/dist/langserve-0c6100e3.d.ts +0 -257
  93. package/dist/lib/cloud/index.d.ts +0 -6
  94. package/dist/lib/cloud/index.js +0 -18
  95. package/dist/lib/cloud/index.js.map +0 -1
  96. package/dist/lib/cloud/index.mjs +0 -1
  97. package/dist/lib/cloud/index.mjs.map +0 -1
  98. package/dist/lib/index.js +0 -7849
  99. package/dist/lib/index.js.map +0 -1
  100. package/dist/lib/index.mjs +0 -76
  101. package/dist/lib/index.mjs.map +0 -1
  102. package/dist/lib/integrations/index.d.ts +0 -34
  103. package/dist/lib/integrations/index.js +0 -3055
  104. package/dist/lib/integrations/index.js.map +0 -1
  105. package/dist/lib/integrations/index.mjs +0 -37
  106. package/dist/lib/integrations/index.mjs.map +0 -1
  107. package/dist/lib/integrations/nest/index.d.ts +0 -15
  108. package/dist/lib/integrations/nest/index.js +0 -2962
  109. package/dist/lib/integrations/nest/index.js.map +0 -1
  110. package/dist/lib/integrations/nest/index.mjs +0 -14
  111. package/dist/lib/integrations/nest/index.mjs.map +0 -1
  112. package/dist/lib/integrations/node-express/index.d.ts +0 -15
  113. package/dist/lib/integrations/node-express/index.js +0 -2962
  114. package/dist/lib/integrations/node-express/index.js.map +0 -1
  115. package/dist/lib/integrations/node-express/index.mjs +0 -14
  116. package/dist/lib/integrations/node-express/index.mjs.map +0 -1
  117. package/dist/lib/integrations/node-http/index.d.ts +0 -15
  118. package/dist/lib/integrations/node-http/index.js +0 -2948
  119. package/dist/lib/integrations/node-http/index.js.map +0 -1
  120. package/dist/lib/integrations/node-http/index.mjs +0 -13
  121. package/dist/lib/integrations/node-http/index.mjs.map +0 -1
  122. package/dist/service-adapters/index.d.ts +0 -162
  123. package/dist/service-adapters/index.js +0 -1787
  124. package/dist/service-adapters/index.js.map +0 -1
  125. package/dist/service-adapters/index.mjs +0 -34
  126. package/dist/service-adapters/index.mjs.map +0 -1
  127. package/dist/service-adapters/shared/index.d.ts +0 -9
  128. package/dist/service-adapters/shared/index.js +0 -72
  129. package/dist/service-adapters/shared/index.js.map +0 -1
  130. package/dist/service-adapters/shared/index.mjs +0 -8
  131. package/dist/service-adapters/shared/index.mjs.map +0 -1
  132. package/dist/shared-0a7346ce.d.ts +0 -466
  133. package/dist/utils/index.d.ts +0 -65
  134. package/dist/utils/index.js +0 -175
  135. package/dist/utils/index.js.map +0 -1
  136. package/dist/utils/index.mjs +0 -12
  137. package/dist/utils/index.mjs.map +0 -1
  138. package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +0 -246
  139. package/src/lib/runtime/agui-action.ts +0 -180
  140. package/src/lib/runtime/remote-action-constructors.ts +0 -331
  141. package/src/lib/runtime/remote-actions.ts +0 -217
  142. package/src/lib/runtime/remote-lg-action.ts +0 -1006
@@ -0,0 +1,278 @@
1
+ import * as gql from "../types/converted/index";
2
+ import agui from "@copilotkit/shared";
3
+ import { MessageStatusCode } from "../types/message-status.type";
4
+
5
+ // Define valid image formats based on the supported formats in the codebase
6
+ const VALID_IMAGE_FORMATS = ["jpeg", "png", "webp", "gif"] as const;
7
+ type ValidImageFormat = (typeof VALID_IMAGE_FORMATS)[number];
8
+
9
+ // Validation function for image format
10
+ function validateImageFormat(format: string): format is ValidImageFormat {
11
+ return VALID_IMAGE_FORMATS.includes(format as ValidImageFormat);
12
+ }
13
+
14
+ /*
15
+ ----------------------------
16
+ GQL Message -> AGUI Message
17
+ ----------------------------
18
+ */
19
+ export function gqlToAGUI(
20
+ messages: gql.Message[] | gql.Message,
21
+ actions?: Record<string, any>,
22
+ coAgentStateRenders?: Record<string, any>,
23
+ ): agui.Message[] {
24
+ let aguiMessages: agui.Message[] = [];
25
+ messages = Array.isArray(messages) ? messages : [messages];
26
+
27
+ // Create a map of action execution ID to result for completed actions
28
+ const actionResults = new Map<string, string>();
29
+ for (const message of messages) {
30
+ if (message.isResultMessage()) {
31
+ actionResults.set(message.actionExecutionId, message.result);
32
+ }
33
+ }
34
+
35
+ for (const message of messages) {
36
+ if (message.isTextMessage()) {
37
+ aguiMessages.push(gqlTextMessageToAGUIMessage(message));
38
+ } else if (message.isResultMessage()) {
39
+ aguiMessages.push(gqlResultMessageToAGUIMessage(message));
40
+ } else if (message.isActionExecutionMessage()) {
41
+ aguiMessages.push(gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults));
42
+ } else if (message.isAgentStateMessage()) {
43
+ aguiMessages.push(gqlAgentStateMessageToAGUIMessage(message, coAgentStateRenders));
44
+ } else if (message.isImageMessage()) {
45
+ aguiMessages.push(gqlImageMessageToAGUIMessage(message));
46
+ } else {
47
+ throw new Error("Unknown message type");
48
+ }
49
+ }
50
+
51
+ return aguiMessages;
52
+ }
53
+
54
+ export function gqlActionExecutionMessageToAGUIMessage(
55
+ message: gql.ActionExecutionMessage,
56
+ actions?: Record<string, any>,
57
+ actionResults?: Map<string, string>,
58
+ ): agui.Message {
59
+ // Check if we have actions and if there's a specific action or wild card action
60
+ const hasSpecificAction =
61
+ actions && Object.values(actions).some((action: any) => action.name === message.name);
62
+ const hasWildcardAction =
63
+ actions && Object.values(actions).some((action: any) => action.name === "*");
64
+
65
+ if (!actions || (!hasSpecificAction && !hasWildcardAction)) {
66
+ return {
67
+ id: message.id,
68
+ role: "assistant",
69
+ toolCalls: [actionExecutionMessageToAGUIMessage(message)],
70
+ name: message.name,
71
+ };
72
+ }
73
+
74
+ // Find the specific action first, then fall back to wild card action
75
+ const action =
76
+ Object.values(actions).find((action: any) => action.name === message.name) ||
77
+ Object.values(actions).find((action: any) => action.name === "*");
78
+
79
+ // Create render function wrapper that provides proper props
80
+ const createRenderWrapper = (originalRender: any) => {
81
+ if (!originalRender) return undefined;
82
+
83
+ return (props?: any) => {
84
+ // Determine the correct status based on the same logic as RenderActionExecutionMessage
85
+ let actionResult: any = actionResults?.get(message.id);
86
+ let status: "inProgress" | "executing" | "complete" = "inProgress";
87
+
88
+ if (actionResult !== undefined) {
89
+ status = "complete";
90
+ } else if (message.status?.code !== MessageStatusCode.Pending) {
91
+ status = "executing";
92
+ }
93
+
94
+ // if props.result is a string, parse it as JSON but don't throw an error if it's not valid JSON
95
+ if (typeof props?.result === "string") {
96
+ try {
97
+ props.result = JSON.parse(props.result);
98
+ } catch (e) {
99
+ /* do nothing */
100
+ }
101
+ }
102
+
103
+ // if actionResult is a string, parse it as JSON but don't throw an error if it's not valid JSON
104
+ if (typeof actionResult === "string") {
105
+ try {
106
+ actionResult = JSON.parse(actionResult);
107
+ } catch (e) {
108
+ /* do nothing */
109
+ }
110
+ }
111
+
112
+ // Base props that all actions receive
113
+ const baseProps = {
114
+ status: props?.status || status,
115
+ args: message.arguments || {},
116
+ result: props?.result || actionResult || undefined,
117
+ messageId: message.id,
118
+ };
119
+
120
+ // Add properties based on action type
121
+ if (action.name === "*") {
122
+ // Wildcard actions get the tool name; ensure it cannot be overridden by incoming props
123
+ return originalRender({
124
+ ...baseProps,
125
+ ...props,
126
+ name: message.name,
127
+ });
128
+ } else {
129
+ // Regular actions get respond (defaulting to a no-op if not provided)
130
+ const respond = props?.respond ?? (() => {});
131
+ return originalRender({
132
+ ...baseProps,
133
+ ...props,
134
+ respond,
135
+ });
136
+ }
137
+ };
138
+ };
139
+
140
+ return {
141
+ id: message.id,
142
+ role: "assistant",
143
+ content: "",
144
+ toolCalls: [actionExecutionMessageToAGUIMessage(message)],
145
+ generativeUI: createRenderWrapper(action.render),
146
+ name: message.name,
147
+ } as agui.AIMessage;
148
+ }
149
+
150
+ function gqlAgentStateMessageToAGUIMessage(
151
+ message: gql.AgentStateMessage,
152
+ coAgentStateRenders?: Record<string, any>,
153
+ ): agui.Message {
154
+ if (
155
+ coAgentStateRenders &&
156
+ Object.values(coAgentStateRenders).some((render: any) => render.name === message.agentName)
157
+ ) {
158
+ const render = Object.values(coAgentStateRenders).find(
159
+ (render: any) => render.name === message.agentName,
160
+ );
161
+
162
+ // Create render function wrapper that provides proper props
163
+ const createRenderWrapper = (originalRender: any) => {
164
+ if (!originalRender) return undefined;
165
+
166
+ return (props?: any) => {
167
+ // Determine the correct status based on the same logic as RenderActionExecutionMessage
168
+ const state = message.state;
169
+
170
+ // Provide the full props structure that the render function expects
171
+ const renderProps = {
172
+ state: state,
173
+ };
174
+
175
+ return originalRender(renderProps);
176
+ };
177
+ };
178
+
179
+ return {
180
+ id: message.id,
181
+ role: "assistant",
182
+ generativeUI: createRenderWrapper(render.render),
183
+ agentName: message.agentName,
184
+ state: message.state,
185
+ };
186
+ }
187
+
188
+ return {
189
+ id: message.id,
190
+ role: "assistant",
191
+ agentName: message.agentName,
192
+ state: message.state,
193
+ };
194
+ }
195
+
196
+ function actionExecutionMessageToAGUIMessage(
197
+ actionExecutionMessage: gql.ActionExecutionMessage,
198
+ ): agui.ToolCall {
199
+ return {
200
+ id: actionExecutionMessage.id,
201
+ function: {
202
+ name: actionExecutionMessage.name,
203
+ arguments: JSON.stringify(actionExecutionMessage.arguments),
204
+ },
205
+ type: "function",
206
+ };
207
+ }
208
+
209
+ export function gqlTextMessageToAGUIMessage(message: gql.TextMessage): agui.Message {
210
+ switch (message.role) {
211
+ case gql.Role.developer:
212
+ return {
213
+ id: message.id,
214
+ role: "developer",
215
+ content: message.content,
216
+ };
217
+ case gql.Role.system:
218
+ return {
219
+ id: message.id,
220
+ role: "system",
221
+ content: message.content,
222
+ };
223
+ case gql.Role.assistant:
224
+ return {
225
+ id: message.id,
226
+ role: "assistant",
227
+ content: message.content,
228
+ };
229
+ case gql.Role.user:
230
+ return {
231
+ id: message.id,
232
+ role: "user",
233
+ content: message.content,
234
+ };
235
+ default:
236
+ throw new Error("Unknown message role");
237
+ }
238
+ }
239
+
240
+ export function gqlResultMessageToAGUIMessage(message: gql.ResultMessage): agui.Message {
241
+ return {
242
+ id: message.id,
243
+ role: "tool",
244
+ content: message.result,
245
+ toolCallId: message.actionExecutionId,
246
+ toolName: message.actionName,
247
+ };
248
+ }
249
+
250
+ export function gqlImageMessageToAGUIMessage(message: gql.ImageMessage): agui.Message {
251
+ // Validate image format
252
+ if (!validateImageFormat(message.format)) {
253
+ throw new Error(
254
+ `Invalid image format: ${message.format}. Supported formats are: ${VALID_IMAGE_FORMATS.join(", ")}`,
255
+ );
256
+ }
257
+
258
+ // Validate that bytes is a non-empty string
259
+ if (!message.bytes || typeof message.bytes !== "string" || message.bytes.trim() === "") {
260
+ throw new Error("Image bytes must be a non-empty string");
261
+ }
262
+
263
+ // Determine the role based on the message role
264
+ const role = message.role === gql.Role.assistant ? "assistant" : "user";
265
+
266
+ // Create the image message with proper typing
267
+ const imageMessage: agui.Message = {
268
+ id: message.id,
269
+ role,
270
+ content: "",
271
+ image: {
272
+ format: message.format,
273
+ bytes: message.bytes,
274
+ },
275
+ };
276
+
277
+ return imageMessage;
278
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./agui-to-gql";
2
+ export * from "./gql-to-agui";