@copilotkit/runtime 1.9.2-next.7 → 1.9.2-next.9
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.
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-IIXJVVTV.mjs → chunk-4JBKY7XT.mjs} +109 -75
- package/dist/chunk-4JBKY7XT.mjs.map +1 -0
- package/dist/{chunk-LSB3QZHS.mjs → chunk-5YGKE5SN.mjs} +2 -2
- package/dist/{chunk-2PQGAIVB.mjs → chunk-ALZ5H3VD.mjs} +2 -2
- package/dist/chunk-AMUJQ6IR.mjs +50 -0
- package/dist/chunk-AMUJQ6IR.mjs.map +1 -0
- package/dist/{chunk-2UAJCT5X.mjs → chunk-SMDVD4VG.mjs} +2 -2
- package/dist/{chunk-GW6ERFKI.mjs → chunk-UUXRYAB4.mjs} +2 -2
- package/dist/{chunk-5BIEM2UU.mjs → chunk-XWBDEXDA.mjs} +4 -3
- package/dist/{chunk-5BIEM2UU.mjs.map → chunk-XWBDEXDA.mjs.map} +1 -1
- package/dist/{chunk-HB4D2KJC.mjs → chunk-Z5GYTKMD.mjs} +2345 -2066
- package/dist/chunk-Z5GYTKMD.mjs.map +1 -0
- package/dist/{groq-adapter-25a2bd35.d.ts → groq-adapter-172a2ca4.d.ts} +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3713 -3356
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -8
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +2981 -2624
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -8
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +141 -86
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +7 -6
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +141 -86
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +5 -4
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +141 -86
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +5 -4
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +141 -86
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +4 -3
- package/dist/service-adapters/index.d.ts +5 -4
- package/dist/service-adapters/index.js +179 -104
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +6 -2
- package/dist/service-adapters/shared/index.d.ts +9 -0
- package/dist/service-adapters/shared/index.js +72 -0
- package/dist/service-adapters/shared/index.js.map +1 -0
- package/dist/service-adapters/shared/index.mjs +8 -0
- package/dist/service-adapters/shared/index.mjs.map +1 -0
- package/dist/{shared-941d59dc.d.ts → shared-bd953ebf.d.ts} +8 -4
- package/dist/utils/index.d.ts +17 -1
- package/dist/utils/index.js +3 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +36 -38
- package/src/agents/langgraph/events.ts +19 -1
- package/src/graphql/resolvers/copilot.resolver.ts +84 -40
- package/src/lib/error-messages.ts +200 -0
- package/src/lib/integrations/shared.ts +43 -0
- package/src/lib/runtime/copilot-runtime.ts +56 -48
- package/src/lib/runtime/remote-action-constructors.ts +28 -3
- package/src/lib/runtime/remote-lg-action.ts +130 -40
- package/src/lib/streaming.ts +125 -36
- package/src/service-adapters/anthropic/anthropic-adapter.ts +3 -4
- package/src/service-adapters/events.ts +37 -81
- package/src/service-adapters/groq/groq-adapter.ts +66 -56
- package/src/service-adapters/index.ts +1 -0
- package/src/service-adapters/openai/openai-adapter.ts +18 -3
- package/src/service-adapters/shared/error-utils.ts +61 -0
- package/src/service-adapters/shared/index.ts +1 -0
- package/src/utils/failed-response-status-reasons.ts +23 -1
- package/dist/chunk-HB4D2KJC.mjs.map +0 -1
- package/dist/chunk-IIXJVVTV.mjs.map +0 -1
- package/dist/{chunk-LSB3QZHS.mjs.map → chunk-5YGKE5SN.mjs.map} +0 -0
- package/dist/{chunk-2PQGAIVB.mjs.map → chunk-ALZ5H3VD.mjs.map} +0 -0
- package/dist/{chunk-2UAJCT5X.mjs.map → chunk-SMDVD4VG.mjs.map} +0 -0
- package/dist/{chunk-GW6ERFKI.mjs.map → chunk-UUXRYAB4.mjs.map} +0 -0
- package/dist/{langserve-4a5c9217.d.ts → langserve-fc5cac89.d.ts} +7 -7
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
limitMessagesToTokenCount,
|
|
28
28
|
} from "../openai/utils";
|
|
29
29
|
import { randomUUID } from "@copilotkit/shared";
|
|
30
|
+
import { convertServiceAdapterError } from "../shared";
|
|
30
31
|
|
|
31
32
|
const DEFAULT_MODEL = "llama-3.3-70b-versatile";
|
|
32
33
|
|
|
@@ -94,76 +95,85 @@ export class GroqAdapter implements CopilotServiceAdapter {
|
|
|
94
95
|
function: { name: forwardedParameters.toolChoiceFunctionName },
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
stream
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
let stream;
|
|
99
|
+
try {
|
|
100
|
+
stream = await this.groq.chat.completions.create({
|
|
101
|
+
model: model,
|
|
102
|
+
stream: true,
|
|
103
|
+
messages: openaiMessages as unknown as ChatCompletionMessageParam[],
|
|
104
|
+
...(tools.length > 0 && { tools }),
|
|
105
|
+
...(forwardedParameters?.maxTokens && {
|
|
106
|
+
max_tokens: forwardedParameters.maxTokens,
|
|
107
|
+
}),
|
|
108
|
+
...(forwardedParameters?.stop && { stop: forwardedParameters.stop }),
|
|
109
|
+
...(toolChoice && { tool_choice: toolChoice }),
|
|
110
|
+
...(this.disableParallelToolCalls && { parallel_tool_calls: false }),
|
|
111
|
+
...(forwardedParameters?.temperature && { temperature: forwardedParameters.temperature }),
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw convertServiceAdapterError(error, "Groq");
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
eventSource.stream(async (eventStream$) => {
|
|
112
118
|
let mode: "function" | "message" | null = null;
|
|
113
119
|
let currentMessageId: string;
|
|
114
120
|
let currentToolCallId: string;
|
|
115
121
|
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
122
|
+
try {
|
|
123
|
+
for await (const chunk of stream) {
|
|
124
|
+
const toolCall = chunk.choices[0].delta.tool_calls?.[0];
|
|
125
|
+
const content = chunk.choices[0].delta.content;
|
|
126
|
+
|
|
127
|
+
// When switching from message to function or vice versa,
|
|
128
|
+
// send the respective end event.
|
|
129
|
+
// If toolCall?.id is defined, it means a new tool call starts.
|
|
130
|
+
if (mode === "message" && toolCall?.id) {
|
|
131
|
+
mode = null;
|
|
132
|
+
eventStream$.sendTextMessageEnd({ messageId: currentMessageId });
|
|
133
|
+
} else if (mode === "function" && (toolCall === undefined || toolCall?.id)) {
|
|
134
|
+
mode = null;
|
|
135
|
+
eventStream$.sendActionExecutionEnd({ actionExecutionId: currentToolCallId });
|
|
136
|
+
}
|
|
119
137
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
// If we send a new message type, send the appropriate start event.
|
|
139
|
+
if (mode === null) {
|
|
140
|
+
if (toolCall?.id) {
|
|
141
|
+
mode = "function";
|
|
142
|
+
currentToolCallId = toolCall!.id;
|
|
143
|
+
eventStream$.sendActionExecutionStart({
|
|
144
|
+
actionExecutionId: currentToolCallId,
|
|
145
|
+
actionName: toolCall!.function!.name,
|
|
146
|
+
parentMessageId: chunk.id,
|
|
147
|
+
});
|
|
148
|
+
} else if (content) {
|
|
149
|
+
mode = "message";
|
|
150
|
+
currentMessageId = chunk.id;
|
|
151
|
+
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
130
154
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
// send the content events
|
|
156
|
+
if (mode === "message" && content) {
|
|
157
|
+
eventStream$.sendTextMessageContent({
|
|
158
|
+
messageId: currentMessageId,
|
|
159
|
+
content,
|
|
160
|
+
});
|
|
161
|
+
} else if (mode === "function" && toolCall?.function?.arguments) {
|
|
162
|
+
eventStream$.sendActionExecutionArgs({
|
|
137
163
|
actionExecutionId: currentToolCallId,
|
|
138
|
-
|
|
139
|
-
parentMessageId: chunk.id,
|
|
164
|
+
args: toolCall.function.arguments,
|
|
140
165
|
});
|
|
141
|
-
} else if (content) {
|
|
142
|
-
mode = "message";
|
|
143
|
-
currentMessageId = chunk.id;
|
|
144
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
145
166
|
}
|
|
146
167
|
}
|
|
147
168
|
|
|
148
|
-
// send the
|
|
149
|
-
if (mode === "message"
|
|
150
|
-
eventStream$.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
} else if (mode === "function" && toolCall?.function?.arguments) {
|
|
155
|
-
eventStream$.sendActionExecutionArgs({
|
|
156
|
-
actionExecutionId: currentToolCallId,
|
|
157
|
-
args: toolCall.function.arguments,
|
|
158
|
-
});
|
|
169
|
+
// send the end events
|
|
170
|
+
if (mode === "message") {
|
|
171
|
+
eventStream$.sendTextMessageEnd({ messageId: currentMessageId });
|
|
172
|
+
} else if (mode === "function") {
|
|
173
|
+
eventStream$.sendActionExecutionEnd({ actionExecutionId: currentToolCallId });
|
|
159
174
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// send the end events
|
|
163
|
-
if (mode === "message") {
|
|
164
|
-
eventStream$.sendTextMessageEnd({ messageId: currentMessageId });
|
|
165
|
-
} else if (mode === "function") {
|
|
166
|
-
eventStream$.sendActionExecutionEnd({ actionExecutionId: currentToolCallId });
|
|
175
|
+
} catch (error) {
|
|
176
|
+
throw convertServiceAdapterError(error, "Groq");
|
|
167
177
|
}
|
|
168
178
|
|
|
169
179
|
eventStream$.complete();
|
|
@@ -5,6 +5,7 @@ export type {
|
|
|
5
5
|
} from "./service-adapter";
|
|
6
6
|
export type { RemoteChainParameters } from "./langchain/langserve";
|
|
7
7
|
export { RemoteChain } from "./langchain/langserve";
|
|
8
|
+
export * from "./shared";
|
|
8
9
|
export * from "./openai/openai-adapter";
|
|
9
10
|
export * from "./langchain/langchain-adapter";
|
|
10
11
|
export * from "./google/google-genai-adapter";
|
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
limitMessagesToTokenCount,
|
|
61
61
|
} from "./utils";
|
|
62
62
|
import { randomUUID } from "@copilotkit/shared";
|
|
63
|
+
import { convertServiceAdapterError } from "../shared";
|
|
63
64
|
|
|
64
65
|
const DEFAULT_MODEL = "gpt-4o";
|
|
65
66
|
|
|
@@ -128,6 +129,8 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
128
129
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
129
130
|
const threadId = threadIdFromRequest ?? randomUUID();
|
|
130
131
|
|
|
132
|
+
console.log("messages", messages);
|
|
133
|
+
|
|
131
134
|
// ALLOWLIST APPROACH: Only include tool_result messages that correspond to valid tool_calls
|
|
132
135
|
// Step 1: Extract valid tool_call IDs
|
|
133
136
|
const validToolUseIds = new Set<string>();
|
|
@@ -168,6 +171,18 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
168
171
|
};
|
|
169
172
|
}
|
|
170
173
|
|
|
174
|
+
console.log("INPUT", {
|
|
175
|
+
model: model,
|
|
176
|
+
stream: true,
|
|
177
|
+
messages: openaiMessages,
|
|
178
|
+
...(tools.length > 0 && { tools }),
|
|
179
|
+
...(forwardedParameters?.maxTokens && { max_tokens: forwardedParameters.maxTokens }),
|
|
180
|
+
...(forwardedParameters?.stop && { stop: forwardedParameters.stop }),
|
|
181
|
+
...(toolChoice && { tool_choice: toolChoice }),
|
|
182
|
+
...(this.disableParallelToolCalls && { parallel_tool_calls: false }),
|
|
183
|
+
...(forwardedParameters?.temperature && { temperature: forwardedParameters.temperature }),
|
|
184
|
+
});
|
|
185
|
+
|
|
171
186
|
try {
|
|
172
187
|
const stream = this.openai.beta.chat.completions.stream({
|
|
173
188
|
model: model,
|
|
@@ -244,15 +259,15 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
244
259
|
eventStream$.sendActionExecutionEnd({ actionExecutionId: currentToolCallId });
|
|
245
260
|
}
|
|
246
261
|
} catch (error) {
|
|
247
|
-
console.error("[OpenAI] Error
|
|
248
|
-
throw error;
|
|
262
|
+
console.error("[OpenAI] Error during API call:", error);
|
|
263
|
+
throw convertServiceAdapterError(error, "OpenAI");
|
|
249
264
|
}
|
|
250
265
|
|
|
251
266
|
eventStream$.complete();
|
|
252
267
|
});
|
|
253
268
|
} catch (error) {
|
|
254
269
|
console.error("[OpenAI] Error during API call:", error);
|
|
255
|
-
throw error;
|
|
270
|
+
throw convertServiceAdapterError(error, "OpenAI");
|
|
256
271
|
}
|
|
257
272
|
|
|
258
273
|
return {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CopilotKitLowLevelError, CopilotKitErrorCode } from "@copilotkit/shared";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts service adapter errors to structured CopilotKitError format using HTTP status codes.
|
|
5
|
+
* This provides consistent error classification across all service adapters.
|
|
6
|
+
*/
|
|
7
|
+
export function convertServiceAdapterError(
|
|
8
|
+
error: any,
|
|
9
|
+
adapterName: string,
|
|
10
|
+
): CopilotKitLowLevelError {
|
|
11
|
+
const errorName = error?.constructor?.name || error.name;
|
|
12
|
+
const errorMessage = error?.message || String(error);
|
|
13
|
+
const statusCode = error.status || error.statusCode || error.response?.status;
|
|
14
|
+
const responseData = error.error || error.response?.data || error.data;
|
|
15
|
+
|
|
16
|
+
// Create the base error with the constructor signature
|
|
17
|
+
const structuredError = new CopilotKitLowLevelError({
|
|
18
|
+
error: error instanceof Error ? error : new Error(errorMessage),
|
|
19
|
+
url: `${adapterName} service adapter`,
|
|
20
|
+
message: `${adapterName} API error: ${errorMessage}`,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Add additional properties after construction
|
|
24
|
+
if (statusCode) {
|
|
25
|
+
(structuredError as any).statusCode = statusCode;
|
|
26
|
+
}
|
|
27
|
+
if (responseData) {
|
|
28
|
+
(structuredError as any).responseData = responseData;
|
|
29
|
+
}
|
|
30
|
+
if (errorName) {
|
|
31
|
+
(structuredError as any).originalErrorType = errorName;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Classify error based on HTTP status codes (reliable and provider-agnostic)
|
|
35
|
+
let newCode: CopilotKitErrorCode;
|
|
36
|
+
|
|
37
|
+
if (statusCode === 401) {
|
|
38
|
+
// 401 = Authentication/API key issues
|
|
39
|
+
newCode = CopilotKitErrorCode.AUTHENTICATION_ERROR;
|
|
40
|
+
} else if (statusCode >= 400 && statusCode < 500) {
|
|
41
|
+
// 4xx = Client errors (bad request, invalid params, etc.) - these are configuration issues
|
|
42
|
+
newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
|
|
43
|
+
} else if (statusCode >= 500) {
|
|
44
|
+
// 5xx = Server errors - keep as NETWORK_ERROR since it's infrastructure related
|
|
45
|
+
newCode = CopilotKitErrorCode.NETWORK_ERROR;
|
|
46
|
+
} else if (statusCode) {
|
|
47
|
+
// Any other HTTP status with an error - likely configuration
|
|
48
|
+
newCode = CopilotKitErrorCode.CONFIGURATION_ERROR;
|
|
49
|
+
} else {
|
|
50
|
+
// No status code - likely a genuine network/connection error
|
|
51
|
+
newCode = CopilotKitErrorCode.NETWORK_ERROR;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Update both the instance property and the extensions
|
|
55
|
+
(structuredError as any).code = newCode;
|
|
56
|
+
if ((structuredError as any).extensions) {
|
|
57
|
+
(structuredError as any).extensions.code = newCode;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return structuredError;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./error-utils";
|
|
@@ -37,12 +37,34 @@ export class UnknownErrorResponse extends FailedResponseStatus {
|
|
|
37
37
|
reason = FailedResponseStatusReason.UNKNOWN_ERROR;
|
|
38
38
|
declare details: {
|
|
39
39
|
description?: string;
|
|
40
|
+
originalError?: {
|
|
41
|
+
code?: string;
|
|
42
|
+
statusCode?: number;
|
|
43
|
+
severity?: string;
|
|
44
|
+
visibility?: string;
|
|
45
|
+
originalErrorType?: string;
|
|
46
|
+
extensions?: any;
|
|
47
|
+
};
|
|
40
48
|
};
|
|
41
49
|
|
|
42
|
-
constructor({
|
|
50
|
+
constructor({
|
|
51
|
+
description,
|
|
52
|
+
originalError,
|
|
53
|
+
}: {
|
|
54
|
+
description?: string;
|
|
55
|
+
originalError?: {
|
|
56
|
+
code?: string;
|
|
57
|
+
statusCode?: number;
|
|
58
|
+
severity?: string;
|
|
59
|
+
visibility?: string;
|
|
60
|
+
originalErrorType?: string;
|
|
61
|
+
extensions?: any;
|
|
62
|
+
};
|
|
63
|
+
}) {
|
|
43
64
|
super();
|
|
44
65
|
this.details = {
|
|
45
66
|
description,
|
|
67
|
+
originalError,
|
|
46
68
|
};
|
|
47
69
|
}
|
|
48
70
|
}
|