@copilotkit/runtime 1.10.6 → 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 (133) hide show
  1. package/dist/index.d.ts +1655 -27
  2. package/dist/index.js +2172 -5049
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +5441 -99
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/v2/index.d.ts +1 -0
  7. package/dist/v2/index.js +15 -0
  8. package/dist/v2/index.js.map +1 -0
  9. package/dist/v2/index.mjs +4 -0
  10. package/dist/v2/index.mjs.map +1 -0
  11. package/package.json +33 -21
  12. package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
  13. package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
  14. package/src/graphql/message-conversion/gql-to-agui.test.ts +1578 -0
  15. package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
  16. package/src/graphql/message-conversion/index.ts +2 -0
  17. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
  18. package/src/graphql/resolvers/copilot.resolver.ts +3 -48
  19. package/src/graphql/resolvers/state.resolver.ts +3 -2
  20. package/src/graphql/types/converted/index.ts +32 -6
  21. package/src/graphql/types/enums.ts +2 -2
  22. package/src/graphql/types/message-status.type.ts +3 -1
  23. package/src/lib/index.ts +1 -1
  24. package/src/lib/integrations/nextjs/app-router.ts +10 -11
  25. package/src/lib/integrations/nextjs/pages-router.ts +4 -11
  26. package/src/lib/integrations/node-http/index.ts +64 -5
  27. package/src/lib/integrations/shared.ts +1 -1
  28. package/src/lib/observability.ts +87 -0
  29. package/src/lib/runtime/{langgraph/langgraph-agent.ts → agent-integrations/langgraph.agent.ts} +5 -0
  30. package/src/lib/runtime/copilot-runtime.ts +346 -1333
  31. package/src/lib/runtime/types.ts +49 -0
  32. package/src/lib/runtime/utils.ts +87 -0
  33. package/src/lib/telemetry-client.ts +6 -5
  34. package/src/service-adapters/anthropic/anthropic-adapter.ts +5 -1
  35. package/src/service-adapters/bedrock/bedrock-adapter.ts +6 -1
  36. package/src/service-adapters/empty/empty-adapter.ts +3 -0
  37. package/src/service-adapters/events.ts +0 -254
  38. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +5 -1
  39. package/src/service-adapters/google/google-genai-adapter.ts +7 -1
  40. package/src/service-adapters/groq/groq-adapter.ts +5 -1
  41. package/src/service-adapters/langchain/langchain-adapter.ts +3 -0
  42. package/src/service-adapters/openai/openai-adapter.ts +5 -1
  43. package/src/service-adapters/openai/openai-assistant-adapter.ts +4 -0
  44. package/src/service-adapters/service-adapter.ts +3 -0
  45. package/src/service-adapters/unify/unify-adapter.ts +6 -1
  46. package/src/v2/index.ts +2 -0
  47. package/tsup.config.ts +2 -1
  48. package/dist/chunk-27JKTS6P.mjs +0 -1704
  49. package/dist/chunk-27JKTS6P.mjs.map +0 -1
  50. package/dist/chunk-2OZAGFV3.mjs +0 -43
  51. package/dist/chunk-2OZAGFV3.mjs.map +0 -1
  52. package/dist/chunk-AMUJQ6IR.mjs +0 -50
  53. package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
  54. package/dist/chunk-CEOMFPJU.mjs +0 -6020
  55. package/dist/chunk-CEOMFPJU.mjs.map +0 -1
  56. package/dist/chunk-DTPRUTNV.mjs +0 -25
  57. package/dist/chunk-DTPRUTNV.mjs.map +0 -1
  58. package/dist/chunk-FHD4JECV.mjs +0 -33
  59. package/dist/chunk-FHD4JECV.mjs.map +0 -1
  60. package/dist/chunk-I27F2UPA.mjs +0 -175
  61. package/dist/chunk-I27F2UPA.mjs.map +0 -1
  62. package/dist/chunk-LPEPX6NH.mjs +0 -25
  63. package/dist/chunk-LPEPX6NH.mjs.map +0 -1
  64. package/dist/chunk-PTYRVXXP.mjs +0 -80
  65. package/dist/chunk-PTYRVXXP.mjs.map +0 -1
  66. package/dist/chunk-SHBDMA63.mjs +0 -141
  67. package/dist/chunk-SHBDMA63.mjs.map +0 -1
  68. package/dist/chunk-XWBDEXDA.mjs +0 -153
  69. package/dist/chunk-XWBDEXDA.mjs.map +0 -1
  70. package/dist/graphql/types/base/index.d.ts +0 -6
  71. package/dist/graphql/types/base/index.js +0 -63
  72. package/dist/graphql/types/base/index.js.map +0 -1
  73. package/dist/graphql/types/base/index.mjs +0 -8
  74. package/dist/graphql/types/base/index.mjs.map +0 -1
  75. package/dist/graphql/types/converted/index.d.ts +0 -2
  76. package/dist/graphql/types/converted/index.js +0 -200
  77. package/dist/graphql/types/converted/index.js.map +0 -1
  78. package/dist/graphql/types/converted/index.mjs +0 -19
  79. package/dist/graphql/types/converted/index.mjs.map +0 -1
  80. package/dist/groq-adapter-c8aec5c5.d.ts +0 -321
  81. package/dist/index-96b330da.d.ts +0 -119
  82. package/dist/langserve-0c6100e3.d.ts +0 -257
  83. package/dist/lib/cloud/index.d.ts +0 -6
  84. package/dist/lib/cloud/index.js +0 -18
  85. package/dist/lib/cloud/index.js.map +0 -1
  86. package/dist/lib/cloud/index.mjs +0 -1
  87. package/dist/lib/cloud/index.mjs.map +0 -1
  88. package/dist/lib/index.d.ts +0 -212
  89. package/dist/lib/index.js +0 -7843
  90. package/dist/lib/index.js.map +0 -1
  91. package/dist/lib/index.mjs +0 -76
  92. package/dist/lib/index.mjs.map +0 -1
  93. package/dist/lib/integrations/index.d.ts +0 -34
  94. package/dist/lib/integrations/index.js +0 -3052
  95. package/dist/lib/integrations/index.js.map +0 -1
  96. package/dist/lib/integrations/index.mjs +0 -37
  97. package/dist/lib/integrations/index.mjs.map +0 -1
  98. package/dist/lib/integrations/nest/index.d.ts +0 -15
  99. package/dist/lib/integrations/nest/index.js +0 -2959
  100. package/dist/lib/integrations/nest/index.js.map +0 -1
  101. package/dist/lib/integrations/nest/index.mjs +0 -14
  102. package/dist/lib/integrations/nest/index.mjs.map +0 -1
  103. package/dist/lib/integrations/node-express/index.d.ts +0 -15
  104. package/dist/lib/integrations/node-express/index.js +0 -2959
  105. package/dist/lib/integrations/node-express/index.js.map +0 -1
  106. package/dist/lib/integrations/node-express/index.mjs +0 -14
  107. package/dist/lib/integrations/node-express/index.mjs.map +0 -1
  108. package/dist/lib/integrations/node-http/index.d.ts +0 -15
  109. package/dist/lib/integrations/node-http/index.js +0 -2945
  110. package/dist/lib/integrations/node-http/index.js.map +0 -1
  111. package/dist/lib/integrations/node-http/index.mjs +0 -13
  112. package/dist/lib/integrations/node-http/index.mjs.map +0 -1
  113. package/dist/service-adapters/index.d.ts +0 -162
  114. package/dist/service-adapters/index.js +0 -1787
  115. package/dist/service-adapters/index.js.map +0 -1
  116. package/dist/service-adapters/index.mjs +0 -34
  117. package/dist/service-adapters/index.mjs.map +0 -1
  118. package/dist/service-adapters/shared/index.d.ts +0 -9
  119. package/dist/service-adapters/shared/index.js +0 -72
  120. package/dist/service-adapters/shared/index.js.map +0 -1
  121. package/dist/service-adapters/shared/index.mjs +0 -8
  122. package/dist/service-adapters/shared/index.mjs.map +0 -1
  123. package/dist/shared-0a7346ce.d.ts +0 -466
  124. package/dist/utils/index.d.ts +0 -65
  125. package/dist/utils/index.js +0 -175
  126. package/dist/utils/index.js.map +0 -1
  127. package/dist/utils/index.mjs +0 -12
  128. package/dist/utils/index.mjs.map +0 -1
  129. package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +0 -246
  130. package/src/lib/runtime/agui-action.ts +0 -180
  131. package/src/lib/runtime/remote-action-constructors.ts +0 -331
  132. package/src/lib/runtime/remote-actions.ts +0 -217
  133. 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";