@copilotkit/runtime 1.5.12-next.5 → 1.5.12-next.6
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 +10 -0
- package/dist/{chunk-QDMAQO2C.mjs → chunk-BKIGYRXE.mjs} +2 -2
- package/dist/{chunk-MFDRA3BJ.mjs → chunk-ON4AESON.mjs} +125 -77
- package/dist/chunk-ON4AESON.mjs.map +1 -0
- package/dist/{chunk-NORCONUM.mjs → chunk-XM2VJFL6.mjs} +2 -2
- package/dist/{chunk-XRW7ZSWJ.mjs → chunk-YGXAWYRB.mjs} +2 -2
- package/dist/{copilot-runtime-1a224a0f.d.ts → copilot-runtime-da917bd5.d.ts} +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +136 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +136 -88
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +12 -10
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +12 -10
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +12 -10
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +12 -10
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/package.json +2 -2
- package/src/lib/runtime/copilot-runtime.ts +61 -27
- package/src/lib/runtime/remote-action-constructors.ts +42 -33
- package/src/lib/runtime/remote-actions.ts +12 -7
- package/dist/chunk-MFDRA3BJ.mjs.map +0 -1
- /package/dist/{chunk-QDMAQO2C.mjs.map → chunk-BKIGYRXE.mjs.map} +0 -0
- /package/dist/{chunk-NORCONUM.mjs.map → chunk-XM2VJFL6.mjs.map} +0 -0
- /package/dist/{chunk-XRW7ZSWJ.mjs.map → chunk-YGXAWYRB.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.5.12-next.
|
|
12
|
+
"version": "1.5.12-next.6",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"rxjs": "^7.8.1",
|
|
59
59
|
"type-graphql": "2.0.0-rc.1",
|
|
60
60
|
"zod": "^3.23.3",
|
|
61
|
-
"@copilotkit/shared": "1.5.12-next.
|
|
61
|
+
"@copilotkit/shared": "1.5.12-next.6"
|
|
62
62
|
},
|
|
63
63
|
"keywords": [
|
|
64
64
|
"copilotkit",
|
|
@@ -12,7 +12,19 @@
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
Action,
|
|
17
|
+
actionParametersToJsonSchema,
|
|
18
|
+
Parameter,
|
|
19
|
+
ResolvedCopilotKitError,
|
|
20
|
+
CopilotKitApiDiscoveryError,
|
|
21
|
+
randomId,
|
|
22
|
+
CopilotKitError,
|
|
23
|
+
CopilotKitLowLevelError,
|
|
24
|
+
CopilotKitAgentDiscoveryError,
|
|
25
|
+
CopilotKitMisuseError,
|
|
26
|
+
} from "@copilotkit/shared";
|
|
27
|
+
import { Client as LangGraphClient } from "@langchain/langgraph-sdk";
|
|
16
28
|
import {
|
|
17
29
|
CopilotServiceAdapter,
|
|
18
30
|
EmptyAdapter,
|
|
@@ -190,10 +202,11 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
190
202
|
return await this.processAgentRequest(request);
|
|
191
203
|
}
|
|
192
204
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
193
|
-
|
|
194
|
-
|
|
205
|
+
throw new CopilotKitMisuseError({
|
|
206
|
+
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
195
207
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
196
|
-
please use an LLM adapter instead
|
|
208
|
+
please use an LLM adapter instead.`,
|
|
209
|
+
});
|
|
197
210
|
}
|
|
198
211
|
|
|
199
212
|
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
@@ -260,30 +273,36 @@ please use an LLM adapter instead.`);
|
|
|
260
273
|
),
|
|
261
274
|
};
|
|
262
275
|
} catch (error) {
|
|
276
|
+
if (error instanceof CopilotKitError) {
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
263
279
|
console.error("Error getting response:", error);
|
|
264
280
|
eventSource.sendErrorMessageToChat();
|
|
265
281
|
throw error;
|
|
266
282
|
}
|
|
267
283
|
}
|
|
268
284
|
|
|
269
|
-
async discoverAgentsFromEndpoints(
|
|
285
|
+
async discoverAgentsFromEndpoints(
|
|
286
|
+
graphqlContext: GraphQLContext,
|
|
287
|
+
): Promise<(Agent & { endpoint: EndpointDefinition })[]> {
|
|
270
288
|
const headers = createHeaders(null, graphqlContext);
|
|
271
289
|
const agents = this.remoteEndpointDefinitions.reduce(
|
|
272
290
|
async (acc: Promise<Agent[]>, endpoint) => {
|
|
273
291
|
const agents = await acc;
|
|
274
292
|
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const data: Array<{ assistant_id: string; graph_id: string }> = await response.json();
|
|
293
|
+
const client = new LangGraphClient({
|
|
294
|
+
apiUrl: endpoint.deploymentUrl,
|
|
295
|
+
apiKey: endpoint.langsmithApiKey,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const data: Array<{ assistant_id: string; graph_id: string }> =
|
|
299
|
+
await client.assistants.search();
|
|
300
|
+
|
|
284
301
|
const endpointAgents = (data ?? []).map((entry) => ({
|
|
285
302
|
name: entry.graph_id,
|
|
286
303
|
id: entry.assistant_id,
|
|
304
|
+
description: "",
|
|
305
|
+
endpoint,
|
|
287
306
|
}));
|
|
288
307
|
return [...agents, ...endpointAgents];
|
|
289
308
|
}
|
|
@@ -295,18 +314,33 @@ please use an LLM adapter instead.`);
|
|
|
295
314
|
}>;
|
|
296
315
|
}
|
|
297
316
|
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
317
|
+
const fetchUrl = `${(endpoint as CopilotKitEndpoint).url}/info`;
|
|
318
|
+
try {
|
|
319
|
+
const response = await fetch(fetchUrl, {
|
|
320
|
+
method: "POST",
|
|
321
|
+
headers,
|
|
322
|
+
body: JSON.stringify({ properties: graphqlContext.properties }),
|
|
323
|
+
});
|
|
324
|
+
if (!response.ok) {
|
|
325
|
+
if (response.status === 404) {
|
|
326
|
+
throw new CopilotKitApiDiscoveryError();
|
|
327
|
+
}
|
|
328
|
+
throw new ResolvedCopilotKitError({ status: response.status, isRemoteEndpoint: true });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const data: InfoResponse = await response.json();
|
|
332
|
+
const endpointAgents = (data?.agents ?? []).map((agent) => ({
|
|
333
|
+
name: agent.name,
|
|
334
|
+
description: agent.description ?? "",
|
|
335
|
+
id: randomId(), // Required by Agent type
|
|
336
|
+
}));
|
|
337
|
+
return [...agents, ...endpointAgents];
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (error instanceof CopilotKitError) {
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
throw new CopilotKitLowLevelError({ error: error as Error, url: fetchUrl });
|
|
343
|
+
}
|
|
310
344
|
},
|
|
311
345
|
Promise.resolve([]),
|
|
312
346
|
);
|
|
@@ -328,7 +362,7 @@ please use an LLM adapter instead.`);
|
|
|
328
362
|
) as LangGraphAgentAction;
|
|
329
363
|
|
|
330
364
|
if (!agent) {
|
|
331
|
-
throw new
|
|
365
|
+
throw new CopilotKitAgentDiscoveryError({ agentName });
|
|
332
366
|
}
|
|
333
367
|
|
|
334
368
|
const serverSideActionsInput: ActionInput[] = serverSideActions
|
|
@@ -16,6 +16,7 @@ import { RemoteLangGraphEventSource } from "../../agents/langgraph/event-source"
|
|
|
16
16
|
import { Action } from "@copilotkit/shared";
|
|
17
17
|
import { LangGraphEvent } from "../../agents/langgraph/events";
|
|
18
18
|
import { execute } from "./remote-lg-action";
|
|
19
|
+
import { CopilotKitError, CopilotKitLowLevelError } from "@copilotkit/shared";
|
|
19
20
|
|
|
20
21
|
export function constructLGCRemoteAction({
|
|
21
22
|
endpoint,
|
|
@@ -126,8 +127,9 @@ export function constructRemoteActions({
|
|
|
126
127
|
agentsAmount: totalAgents,
|
|
127
128
|
});
|
|
128
129
|
|
|
130
|
+
const fetchUrl = `${url}/actions/execute`;
|
|
129
131
|
try {
|
|
130
|
-
const response = await fetch(
|
|
132
|
+
const response = await fetch(fetchUrl, {
|
|
131
133
|
method: "POST",
|
|
132
134
|
headers,
|
|
133
135
|
body: JSON.stringify({
|
|
@@ -151,11 +153,10 @@ export function constructRemoteActions({
|
|
|
151
153
|
logger.debug({ actionName: action.name, result }, "Executed remote action");
|
|
152
154
|
return result;
|
|
153
155
|
} catch (error) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
);
|
|
158
|
-
return "Failed to execute remote action";
|
|
156
|
+
if (error instanceof CopilotKitError) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
throw new CopilotKitLowLevelError({ error, url: fetchUrl });
|
|
159
160
|
}
|
|
160
161
|
},
|
|
161
162
|
}));
|
|
@@ -191,35 +192,43 @@ export function constructRemoteActions({
|
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
195
|
+
const fetchUrl = `${url}/agents/execute`;
|
|
196
|
+
try {
|
|
197
|
+
const response = await fetch(fetchUrl, {
|
|
198
|
+
method: "POST",
|
|
199
|
+
headers,
|
|
200
|
+
body: JSON.stringify({
|
|
201
|
+
name,
|
|
202
|
+
threadId,
|
|
203
|
+
nodeName,
|
|
204
|
+
messages: [...messages, ...additionalMessages],
|
|
205
|
+
state,
|
|
206
|
+
properties: graphqlContext.properties,
|
|
207
|
+
actions: actionInputsWithoutAgents.map((action) => ({
|
|
208
|
+
name: action.name,
|
|
209
|
+
description: action.description,
|
|
210
|
+
parameters: JSON.parse(action.jsonSchema),
|
|
211
|
+
})),
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
logger.error(
|
|
217
|
+
{ url, status: response.status, body: await response.text() },
|
|
218
|
+
"Failed to execute remote agent",
|
|
219
|
+
);
|
|
220
|
+
throw new Error("Failed to execute remote agent");
|
|
221
|
+
}
|
|
211
222
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
)
|
|
217
|
-
|
|
223
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
224
|
+
streamResponse(response.body!, eventSource.eventStream$);
|
|
225
|
+
return eventSource.processLangGraphEvents();
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (error instanceof CopilotKitError) {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
throw new CopilotKitLowLevelError({ error, url: fetchUrl });
|
|
218
231
|
}
|
|
219
|
-
|
|
220
|
-
const eventSource = new RemoteLangGraphEventSource();
|
|
221
|
-
streamResponse(response.body!, eventSource.eventStream$);
|
|
222
|
-
return eventSource.processLangGraphEvents();
|
|
223
232
|
},
|
|
224
233
|
}))
|
|
225
234
|
: [];
|
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
constructRemoteActions,
|
|
12
12
|
createHeaders,
|
|
13
13
|
} from "./remote-action-constructors";
|
|
14
|
+
import {
|
|
15
|
+
CopilotKitLowLevelError,
|
|
16
|
+
ResolvedCopilotKitError,
|
|
17
|
+
CopilotKitError,
|
|
18
|
+
} from "@copilotkit/shared";
|
|
14
19
|
|
|
15
20
|
export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
|
|
16
21
|
|
|
@@ -83,8 +88,9 @@ async function fetchRemoteInfo({
|
|
|
83
88
|
logger.debug({ url }, "Fetching actions from url");
|
|
84
89
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
85
90
|
|
|
91
|
+
const fetchUrl = `${url}/info`;
|
|
86
92
|
try {
|
|
87
|
-
const response = await fetch(
|
|
93
|
+
const response = await fetch(fetchUrl, {
|
|
88
94
|
method: "POST",
|
|
89
95
|
headers,
|
|
90
96
|
body: JSON.stringify({ properties: graphqlContext.properties, frontendUrl }),
|
|
@@ -95,18 +101,17 @@ async function fetchRemoteInfo({
|
|
|
95
101
|
{ url, status: response.status, body: await response.text() },
|
|
96
102
|
"Failed to fetch actions from url",
|
|
97
103
|
);
|
|
98
|
-
|
|
104
|
+
throw new ResolvedCopilotKitError({ status: response.status, isRemoteEndpoint: true });
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
const json = await response.json();
|
|
102
108
|
logger.debug({ json }, "Fetched actions from url");
|
|
103
109
|
return json;
|
|
104
110
|
} catch (error) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
109
|
-
return { actions: [], agents: [] };
|
|
111
|
+
if (error instanceof CopilotKitError) {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
throw new CopilotKitLowLevelError({ error, url: fetchUrl });
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
|