@copilotkit/runtime 1.4.0-pre-1-4-0-alpha.10 → 1.4.0-pre-1-4-0.14
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 +160 -24
- package/dist/{chunk-YUJSVJWS.mjs → chunk-6H45CJUK.mjs} +2 -2
- package/dist/{chunk-SBWLAAB3.mjs → chunk-N4ROMSZN.mjs} +2 -2
- package/dist/{chunk-SVL5LEKB.mjs → chunk-NFMXFL2C.mjs} +2 -2
- package/dist/{chunk-56IQ6PGC.mjs → chunk-WHJ3DAYL.mjs} +56 -213
- package/dist/chunk-WHJ3DAYL.mjs.map +1 -0
- package/dist/{chunk-RDHJQVWH.mjs → chunk-X4FFTYTH.mjs} +49 -92
- package/dist/chunk-X4FFTYTH.mjs.map +1 -0
- package/dist/{copilot-runtime-dbe5fa02.d.ts → copilot-runtime-335a610d.d.ts} +8 -8
- package/dist/{groq-adapter-192d2413.d.ts → groq-adapter-2f8fd767.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +103 -303
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/{langserve-878c62b9.d.ts → langserve-cc06e76e.d.ts} +9 -45
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +97 -282
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +6 -14
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +6 -14
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +6 -14
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +6 -14
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +3 -3
- package/dist/service-adapters/index.js +55 -212
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +4 -4
- package/src/agents/langgraph/event-source.ts +2 -14
- package/src/graphql/resolvers/copilot.resolver.ts +2 -28
- package/src/lib/runtime/copilot-runtime.ts +6 -6
- package/src/lib/runtime/remote-action-constructors.ts +7 -7
- package/src/lib/runtime/remote-actions.ts +9 -9
- package/src/lib/runtime/{remote-lg-cloud-action.ts → remote-lg-action.ts} +18 -18
- package/src/lib/telemetry-client.ts +3 -3
- package/src/service-adapters/anthropic/anthropic-adapter.ts +6 -15
- package/src/service-adapters/events.ts +35 -73
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -7
- package/src/service-adapters/groq/groq-adapter.ts +8 -22
- package/src/service-adapters/langchain/utils.ts +31 -47
- package/src/service-adapters/openai/openai-adapter.ts +9 -21
- package/src/service-adapters/openai/openai-assistant-adapter.ts +8 -21
- package/src/service-adapters/unify/unify-adapter.ts +11 -28
- package/dist/chunk-56IQ6PGC.mjs.map +0 -1
- package/dist/chunk-RDHJQVWH.mjs.map +0 -1
- /package/dist/{chunk-YUJSVJWS.mjs.map → chunk-6H45CJUK.mjs.map} +0 -0
- /package/dist/{chunk-SBWLAAB3.mjs.map → chunk-N4ROMSZN.mjs.map} +0 -0
- /package/dist/{chunk-SVL5LEKB.mjs.map → chunk-NFMXFL2C.mjs.map} +0 -0
|
@@ -37,7 +37,7 @@ export class RemoteLangGraphEventSource {
|
|
|
37
37
|
scan(
|
|
38
38
|
(acc, event) => {
|
|
39
39
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
40
|
-
// @ts-expect-error -- LangGraph
|
|
40
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
41
41
|
const content = event.data?.chunk?.kwargs?.content ?? event.data?.chunk?.content;
|
|
42
42
|
|
|
43
43
|
if (typeof content === "string") {
|
|
@@ -49,7 +49,7 @@ export class RemoteLangGraphEventSource {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const toolCallChunks =
|
|
52
|
-
// @ts-expect-error -- LangGraph
|
|
52
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
53
53
|
event.data?.chunk?.kwargs?.tool_call_chunks ?? event.data?.chunk?.tool_call_chunks;
|
|
54
54
|
|
|
55
55
|
const toolCallMessageId =
|
|
@@ -120,7 +120,6 @@ export class RemoteLangGraphEventSource {
|
|
|
120
120
|
) {
|
|
121
121
|
events.push({
|
|
122
122
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
123
|
-
actionExecutionId: eventWithState.prevToolCallMessageId,
|
|
124
123
|
});
|
|
125
124
|
}
|
|
126
125
|
|
|
@@ -132,7 +131,6 @@ export class RemoteLangGraphEventSource {
|
|
|
132
131
|
) {
|
|
133
132
|
events.push({
|
|
134
133
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
135
|
-
messageId: eventWithState.prevMessageId,
|
|
136
134
|
});
|
|
137
135
|
}
|
|
138
136
|
|
|
@@ -151,12 +149,10 @@ export class RemoteLangGraphEventSource {
|
|
|
151
149
|
});
|
|
152
150
|
events.push({
|
|
153
151
|
type: RuntimeEventTypes.TextMessageContent,
|
|
154
|
-
messageId: eventWithState.event.data.message_id,
|
|
155
152
|
content: eventWithState.event.data.message,
|
|
156
153
|
});
|
|
157
154
|
events.push({
|
|
158
155
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
159
|
-
messageId: eventWithState.event.data.message_id,
|
|
160
156
|
});
|
|
161
157
|
}
|
|
162
158
|
//
|
|
@@ -172,12 +168,10 @@ export class RemoteLangGraphEventSource {
|
|
|
172
168
|
});
|
|
173
169
|
events.push({
|
|
174
170
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
175
|
-
actionExecutionId: eventWithState.event.data.id,
|
|
176
171
|
args: JSON.stringify(eventWithState.event.data.args),
|
|
177
172
|
});
|
|
178
173
|
events.push({
|
|
179
174
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
180
|
-
actionExecutionId: eventWithState.event.data.id,
|
|
181
175
|
});
|
|
182
176
|
}
|
|
183
177
|
break;
|
|
@@ -248,7 +242,6 @@ export class RemoteLangGraphEventSource {
|
|
|
248
242
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
249
243
|
events.push({
|
|
250
244
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
251
|
-
actionExecutionId: eventWithState.toolCallMessageId,
|
|
252
245
|
args,
|
|
253
246
|
});
|
|
254
247
|
}
|
|
@@ -258,7 +251,6 @@ export class RemoteLangGraphEventSource {
|
|
|
258
251
|
if (shouldEmitMessages) {
|
|
259
252
|
events.push({
|
|
260
253
|
type: RuntimeEventTypes.TextMessageContent,
|
|
261
|
-
messageId: eventWithState.messageId,
|
|
262
254
|
content,
|
|
263
255
|
});
|
|
264
256
|
}
|
|
@@ -274,13 +266,11 @@ export class RemoteLangGraphEventSource {
|
|
|
274
266
|
if (lastEventWithState?.messageId) {
|
|
275
267
|
events.push({
|
|
276
268
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
277
|
-
messageId: lastEventWithState.messageId,
|
|
278
269
|
});
|
|
279
270
|
}
|
|
280
271
|
if (lastEventWithState?.toolCallMessageId) {
|
|
281
272
|
events.push({
|
|
282
273
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
283
|
-
actionExecutionId: lastEventWithState.toolCallMessageId,
|
|
284
274
|
});
|
|
285
275
|
}
|
|
286
276
|
|
|
@@ -292,12 +282,10 @@ export class RemoteLangGraphEventSource {
|
|
|
292
282
|
});
|
|
293
283
|
events.push({
|
|
294
284
|
type: RuntimeEventTypes.TextMessageContent,
|
|
295
|
-
messageId: messageId,
|
|
296
285
|
content: "❌ An error occurred. Please try again.",
|
|
297
286
|
});
|
|
298
287
|
events.push({
|
|
299
288
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
300
|
-
messageId: messageId,
|
|
301
289
|
});
|
|
302
290
|
|
|
303
291
|
return events;
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
ReplaySubject,
|
|
4
4
|
Subject,
|
|
5
5
|
Subscription,
|
|
6
|
-
filter,
|
|
7
6
|
finalize,
|
|
8
7
|
firstValueFrom,
|
|
9
8
|
shareReplay,
|
|
@@ -287,19 +286,7 @@ export class CopilotResolver {
|
|
|
287
286
|
// skip until this message start event
|
|
288
287
|
skipWhile((e) => e !== event),
|
|
289
288
|
// take until the message end event
|
|
290
|
-
takeWhile(
|
|
291
|
-
(e) =>
|
|
292
|
-
!(
|
|
293
|
-
e.type === RuntimeEventTypes.TextMessageEnd &&
|
|
294
|
-
e.messageId == event.messageId
|
|
295
|
-
),
|
|
296
|
-
),
|
|
297
|
-
// filter out any other message events or message ids
|
|
298
|
-
filter(
|
|
299
|
-
(e) =>
|
|
300
|
-
e.type == RuntimeEventTypes.TextMessageContent &&
|
|
301
|
-
e.messageId == event.messageId,
|
|
302
|
-
),
|
|
289
|
+
takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd),
|
|
303
290
|
);
|
|
304
291
|
|
|
305
292
|
// signal when we are done streaming
|
|
@@ -380,20 +367,7 @@ export class CopilotResolver {
|
|
|
380
367
|
logger.debug("Action execution start event received");
|
|
381
368
|
const actionExecutionArgumentStream = eventStream.pipe(
|
|
382
369
|
skipWhile((e) => e !== event),
|
|
383
|
-
|
|
384
|
-
takeWhile(
|
|
385
|
-
(e) =>
|
|
386
|
-
!(
|
|
387
|
-
e.type === RuntimeEventTypes.ActionExecutionEnd &&
|
|
388
|
-
e.actionExecutionId == event.actionExecutionId
|
|
389
|
-
),
|
|
390
|
-
),
|
|
391
|
-
// filter out any other action execution events or action execution ids
|
|
392
|
-
filter(
|
|
393
|
-
(e) =>
|
|
394
|
-
e.type == RuntimeEventTypes.ActionExecutionArgs &&
|
|
395
|
-
e.actionExecutionId == event.actionExecutionId,
|
|
396
|
-
),
|
|
370
|
+
takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd),
|
|
397
371
|
);
|
|
398
372
|
const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
|
|
399
373
|
pushMessage({
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
setupRemoteActions,
|
|
28
28
|
EndpointDefinition,
|
|
29
29
|
CopilotKitEndpoint,
|
|
30
|
-
|
|
30
|
+
LangGraphPlatformEndpoint,
|
|
31
31
|
} from "./remote-actions";
|
|
32
32
|
import { GraphQLContext } from "../integrations/shared";
|
|
33
33
|
import { AgentSessionInput } from "../../graphql/inputs/agent-session.input";
|
|
@@ -392,19 +392,19 @@ export function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): Co
|
|
|
392
392
|
};
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
export function
|
|
396
|
-
config: Omit<
|
|
397
|
-
):
|
|
395
|
+
export function langGraphPlatformEndpoint(
|
|
396
|
+
config: Omit<LangGraphPlatformEndpoint, "type">,
|
|
397
|
+
): LangGraphPlatformEndpoint {
|
|
398
398
|
return {
|
|
399
399
|
...config,
|
|
400
|
-
type: EndpointType.
|
|
400
|
+
type: EndpointType.LangGraphPlatform,
|
|
401
401
|
};
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
export function resolveEndpointType(endpoint: EndpointDefinition) {
|
|
405
405
|
if (!endpoint.type) {
|
|
406
406
|
if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
407
|
-
return EndpointType.
|
|
407
|
+
return EndpointType.LangGraphPlatform;
|
|
408
408
|
} else {
|
|
409
409
|
return EndpointType.CopilotKit;
|
|
410
410
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CopilotKitEndpoint,
|
|
4
4
|
LangGraphAgentHandlerParams,
|
|
5
5
|
RemoteActionInfoResponse,
|
|
6
|
-
|
|
6
|
+
LangGraphPlatformEndpoint,
|
|
7
7
|
} from "./remote-actions";
|
|
8
8
|
import { GraphQLContext } from "../integrations";
|
|
9
9
|
import { Logger } from "pino";
|
|
@@ -15,7 +15,7 @@ import telemetry from "../telemetry-client";
|
|
|
15
15
|
import { RemoteLangGraphEventSource } from "../../agents/langgraph/event-source";
|
|
16
16
|
import { Action } from "@copilotkit/shared";
|
|
17
17
|
import { LangGraphEvent } from "../../agents/langgraph/events";
|
|
18
|
-
import { execute } from "./remote-lg-
|
|
18
|
+
import { execute } from "./remote-lg-action";
|
|
19
19
|
|
|
20
20
|
export function constructLGCRemoteAction({
|
|
21
21
|
endpoint,
|
|
@@ -24,7 +24,7 @@ export function constructLGCRemoteAction({
|
|
|
24
24
|
messages,
|
|
25
25
|
agentStates,
|
|
26
26
|
}: {
|
|
27
|
-
endpoint:
|
|
27
|
+
endpoint: LangGraphPlatformEndpoint;
|
|
28
28
|
graphqlContext: GraphQLContext;
|
|
29
29
|
logger: Logger;
|
|
30
30
|
messages: Message[];
|
|
@@ -41,11 +41,11 @@ export function constructLGCRemoteAction({
|
|
|
41
41
|
threadId,
|
|
42
42
|
nodeName,
|
|
43
43
|
}: LangGraphAgentHandlerParams): Promise<Observable<RuntimeEvent>> => {
|
|
44
|
-
logger.debug({ actionName: agent.name }, "Executing LangGraph
|
|
44
|
+
logger.debug({ actionName: agent.name }, "Executing LangGraph Platform agent");
|
|
45
45
|
|
|
46
46
|
telemetry.capture("oss.runtime.remote_action_executed", {
|
|
47
47
|
agentExecution: true,
|
|
48
|
-
type: "langgraph-
|
|
48
|
+
type: "langgraph-platform",
|
|
49
49
|
agentsAmount: endpoint.agents.length,
|
|
50
50
|
hashedLgcKey: createHash("sha256").update(endpoint.langsmithApiKey).digest("hex"),
|
|
51
51
|
});
|
|
@@ -82,9 +82,9 @@ export function constructLGCRemoteAction({
|
|
|
82
82
|
} catch (error) {
|
|
83
83
|
logger.error(
|
|
84
84
|
{ url: endpoint.deploymentUrl, status: 500, body: error.message },
|
|
85
|
-
"Failed to execute LangGraph
|
|
85
|
+
"Failed to execute LangGraph Platform agent",
|
|
86
86
|
);
|
|
87
|
-
throw new Error("Failed to execute LangGraph
|
|
87
|
+
throw new Error("Failed to execute LangGraph Platform agent");
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
}));
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
createHeaders,
|
|
13
13
|
} from "./remote-action-constructors";
|
|
14
14
|
|
|
15
|
-
export type EndpointDefinition = CopilotKitEndpoint |
|
|
15
|
+
export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
|
|
16
16
|
|
|
17
17
|
export enum EndpointType {
|
|
18
18
|
CopilotKit = "copilotKit",
|
|
19
|
-
|
|
19
|
+
LangGraphPlatform = "langgraph-platform",
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface BaseEndpointDefinition<TActionType extends EndpointType> {
|
|
@@ -30,17 +30,17 @@ export interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export interface
|
|
33
|
+
export interface LangGraphPlatformAgent {
|
|
34
34
|
name: string;
|
|
35
35
|
description: string;
|
|
36
36
|
assistantId?: string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface
|
|
40
|
-
extends BaseEndpointDefinition<EndpointType.
|
|
39
|
+
export interface LangGraphPlatformEndpoint
|
|
40
|
+
extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
|
|
41
41
|
deploymentUrl: string;
|
|
42
42
|
langsmithApiKey: string;
|
|
43
|
-
agents:
|
|
43
|
+
agents: LangGraphPlatformAgent[];
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export type RemoteActionInfoResponse = {
|
|
@@ -127,7 +127,7 @@ export async function setupRemoteActions({
|
|
|
127
127
|
|
|
128
128
|
// Remove duplicates of remoteEndpointDefinitions.url
|
|
129
129
|
const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
|
|
130
|
-
if (value.type === EndpointType.
|
|
130
|
+
if (value.type === EndpointType.LangGraphPlatform) {
|
|
131
131
|
return value;
|
|
132
132
|
}
|
|
133
133
|
return index === self.findIndex((t: CopilotKitEndpoint) => t.url === value.url);
|
|
@@ -135,8 +135,8 @@ export async function setupRemoteActions({
|
|
|
135
135
|
|
|
136
136
|
const result = await Promise.all(
|
|
137
137
|
filtered.map(async (endpoint) => {
|
|
138
|
-
// Check for properties that can distinguish LG
|
|
139
|
-
if (endpoint.type === EndpointType.
|
|
138
|
+
// Check for properties that can distinguish LG platform from other actions
|
|
139
|
+
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
140
140
|
return constructLGCRemoteAction({
|
|
141
141
|
endpoint,
|
|
142
142
|
messages,
|
|
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
3
3
|
import { parse as parsePartialJson } from "partial-json";
|
|
4
4
|
import { Logger } from "pino";
|
|
5
5
|
import { ActionInput } from "../../graphql/inputs/action.input";
|
|
6
|
-
import {
|
|
6
|
+
import { LangGraphPlatformAgent, LangGraphPlatformEndpoint } from "./remote-actions";
|
|
7
7
|
import { CopilotRequestContextProperties } from "../integrations";
|
|
8
8
|
import { Message, MessageType } from "../../graphql/types/converted";
|
|
9
9
|
import { MessageRole } from "../../graphql/types/enums";
|
|
@@ -14,8 +14,8 @@ type State = Record<string, any>;
|
|
|
14
14
|
|
|
15
15
|
type ExecutionAction = Pick<ActionInput, "name" | "description"> & { parameters: string };
|
|
16
16
|
|
|
17
|
-
interface ExecutionArgs extends Omit<
|
|
18
|
-
agent:
|
|
17
|
+
interface ExecutionArgs extends Omit<LangGraphPlatformEndpoint, "agents"> {
|
|
18
|
+
agent: LangGraphPlatformAgent;
|
|
19
19
|
threadId: string;
|
|
20
20
|
nodeName: string;
|
|
21
21
|
messages: Message[];
|
|
@@ -25,14 +25,14 @@ interface ExecutionArgs extends Omit<LangGraphCloudEndpoint, "agents"> {
|
|
|
25
25
|
logger: Logger;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// The following types are our own definition to the messages accepted by LangGraph
|
|
28
|
+
// The following types are our own definition to the messages accepted by LangGraph Platform, enhanced with some of our extra data.
|
|
29
29
|
interface ToolCall {
|
|
30
30
|
id: string;
|
|
31
31
|
name: string;
|
|
32
32
|
args: Record<string, unknown>;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
type
|
|
35
|
+
type BaseLangGraphPlatformMessage = Omit<
|
|
36
36
|
Message,
|
|
37
37
|
| "isResultMessage"
|
|
38
38
|
| "isTextMessage"
|
|
@@ -47,19 +47,19 @@ type BaseLangGraphCloudMessage = Omit<
|
|
|
47
47
|
type: MessageType;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
interface
|
|
50
|
+
interface LangGraphPlatformResultMessage extends BaseLangGraphPlatformMessage {
|
|
51
51
|
tool_call_id: string;
|
|
52
52
|
name: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
interface
|
|
55
|
+
interface LangGraphPlatformActionExecutionMessage extends BaseLangGraphPlatformMessage {
|
|
56
56
|
tool_calls: ToolCall[];
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
type
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
59
|
+
type LangGraphPlatformMessage =
|
|
60
|
+
| LangGraphPlatformActionExecutionMessage
|
|
61
|
+
| LangGraphPlatformResultMessage
|
|
62
|
+
| BaseLangGraphPlatformMessage;
|
|
63
63
|
|
|
64
64
|
export async function execute(args: ExecutionArgs): Promise<ReadableStream<Uint8Array>> {
|
|
65
65
|
return new ReadableStream({
|
|
@@ -128,7 +128,7 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
|
|
|
128
128
|
if (!assistantId) {
|
|
129
129
|
console.error(`
|
|
130
130
|
No agent found for the agent name specified in CopilotKit provider
|
|
131
|
-
Please check your available agents or provide an agent ID in the LangGraph
|
|
131
|
+
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.\n
|
|
132
132
|
|
|
133
133
|
These are the available agents: [${assistants.map((a) => `${a.name} (ID: ${a.assistant_id})`).join(", ")}]
|
|
134
134
|
`);
|
|
@@ -439,7 +439,7 @@ class StreamingStateExtractor {
|
|
|
439
439
|
// Start of Selection
|
|
440
440
|
function langGraphDefaultMergeState(
|
|
441
441
|
state: State,
|
|
442
|
-
messages:
|
|
442
|
+
messages: LangGraphPlatformMessage[],
|
|
443
443
|
actions: ExecutionAction[],
|
|
444
444
|
agentName: string,
|
|
445
445
|
): State {
|
|
@@ -449,7 +449,7 @@ function langGraphDefaultMergeState(
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
// merge with existing messages
|
|
452
|
-
const mergedMessages:
|
|
452
|
+
const mergedMessages: LangGraphPlatformMessage[] = state.messages || [];
|
|
453
453
|
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
454
454
|
const existingToolCallResults = new Set<string>();
|
|
455
455
|
|
|
@@ -515,7 +515,7 @@ function langGraphDefaultMergeState(
|
|
|
515
515
|
}
|
|
516
516
|
|
|
517
517
|
// try to auto-correct and log alignment issues
|
|
518
|
-
const correctedMessages:
|
|
518
|
+
const correctedMessages: LangGraphPlatformMessage[] = [];
|
|
519
519
|
|
|
520
520
|
for (let i = 0; i < mergedMessages.length; i++) {
|
|
521
521
|
const currentMessage = mergedMessages[i];
|
|
@@ -586,7 +586,7 @@ function langGraphDefaultMergeState(
|
|
|
586
586
|
};
|
|
587
587
|
}
|
|
588
588
|
|
|
589
|
-
function formatMessages(messages: Message[]):
|
|
589
|
+
function formatMessages(messages: Message[]): LangGraphPlatformMessage[] {
|
|
590
590
|
return messages.map((message) => {
|
|
591
591
|
if (message.isTextMessage() && message.role === "assistant") {
|
|
592
592
|
return message;
|
|
@@ -609,7 +609,7 @@ function formatMessages(messages: Message[]): LangGraphCloudMessage[] {
|
|
|
609
609
|
tool_calls: [toolCall],
|
|
610
610
|
role: MessageRole.assistant,
|
|
611
611
|
id: message.id,
|
|
612
|
-
} satisfies
|
|
612
|
+
} satisfies LangGraphPlatformActionExecutionMessage;
|
|
613
613
|
}
|
|
614
614
|
if (message.isResultMessage()) {
|
|
615
615
|
return {
|
|
@@ -619,7 +619,7 @@ function formatMessages(messages: Message[]): LangGraphCloudMessage[] {
|
|
|
619
619
|
tool_call_id: message.actionExecutionId,
|
|
620
620
|
name: message.actionName,
|
|
621
621
|
role: MessageRole.tool,
|
|
622
|
-
} satisfies
|
|
622
|
+
} satisfies LangGraphPlatformResultMessage;
|
|
623
623
|
}
|
|
624
624
|
|
|
625
625
|
throw new Error(`Unknown message type ${message.type}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
2
|
-
import { EndpointType,
|
|
2
|
+
import { EndpointType, LangGraphPlatformEndpoint } from "./runtime/remote-actions";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { CopilotRuntime, resolveEndpointType } from "./runtime/copilot-runtime";
|
|
5
5
|
import { RuntimeInstanceCreatedInfo } from "@copilotkit/shared/src/telemetry/events";
|
|
@@ -25,9 +25,9 @@ export function getRuntimeInstanceTelemetryInfo(
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if (endpointType === EndpointType.
|
|
28
|
+
if (endpointType === EndpointType.LangGraphPlatform) {
|
|
29
29
|
// When type is resolved, recreating a const with casting of type
|
|
30
|
-
const ep = endpoint as
|
|
30
|
+
const ep = endpoint as LangGraphPlatformEndpoint;
|
|
31
31
|
info = {
|
|
32
32
|
...info,
|
|
33
33
|
agentsAmount: ep.agents.length,
|
|
@@ -122,10 +122,7 @@ export class AnthropicAdapter implements CopilotServiceAdapter {
|
|
|
122
122
|
mode = "message";
|
|
123
123
|
} else if (chunk.content_block.type === "tool_use") {
|
|
124
124
|
currentToolCallId = chunk.content_block.id;
|
|
125
|
-
eventStream$.sendActionExecutionStart(
|
|
126
|
-
actionExecutionId: currentToolCallId,
|
|
127
|
-
actionName: chunk.content_block.name,
|
|
128
|
-
});
|
|
125
|
+
eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
|
|
129
126
|
mode = "function";
|
|
130
127
|
}
|
|
131
128
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -133,27 +130,21 @@ export class AnthropicAdapter implements CopilotServiceAdapter {
|
|
|
133
130
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
134
131
|
if (text.length > 0) {
|
|
135
132
|
if (!didOutputText) {
|
|
136
|
-
eventStream$.sendTextMessageStart(
|
|
133
|
+
eventStream$.sendTextMessageStart(currentMessageId);
|
|
137
134
|
didOutputText = true;
|
|
138
135
|
}
|
|
139
|
-
eventStream$.sendTextMessageContent(
|
|
140
|
-
messageId: currentMessageId,
|
|
141
|
-
content: text,
|
|
142
|
-
});
|
|
136
|
+
eventStream$.sendTextMessageContent(text);
|
|
143
137
|
}
|
|
144
138
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
145
|
-
eventStream$.sendActionExecutionArgs(
|
|
146
|
-
actionExecutionId: currentToolCallId,
|
|
147
|
-
args: chunk.delta.partial_json,
|
|
148
|
-
});
|
|
139
|
+
eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
|
|
149
140
|
}
|
|
150
141
|
} else if (chunk.type === "content_block_stop") {
|
|
151
142
|
if (mode === "message") {
|
|
152
143
|
if (didOutputText) {
|
|
153
|
-
eventStream$.sendTextMessageEnd(
|
|
144
|
+
eventStream$.sendTextMessageEnd();
|
|
154
145
|
}
|
|
155
146
|
} else if (mode === "function") {
|
|
156
|
-
eventStream$.sendActionExecutionEnd(
|
|
147
|
+
eventStream$.sendActionExecutionEnd();
|
|
157
148
|
}
|
|
158
149
|
}
|
|
159
150
|
}
|
|
@@ -33,18 +33,17 @@ export type RuntimeEvent =
|
|
|
33
33
|
| { type: RuntimeEventTypes.TextMessageStart; messageId: string }
|
|
34
34
|
| {
|
|
35
35
|
type: RuntimeEventTypes.TextMessageContent;
|
|
36
|
-
messageId: string;
|
|
37
36
|
content: string;
|
|
38
37
|
}
|
|
39
|
-
| { type: RuntimeEventTypes.TextMessageEnd
|
|
38
|
+
| { type: RuntimeEventTypes.TextMessageEnd }
|
|
40
39
|
| {
|
|
41
40
|
type: RuntimeEventTypes.ActionExecutionStart;
|
|
42
41
|
actionExecutionId: string;
|
|
43
42
|
actionName: string;
|
|
44
43
|
scope?: FunctionCallScope;
|
|
45
44
|
}
|
|
46
|
-
| { type: RuntimeEventTypes.ActionExecutionArgs;
|
|
47
|
-
| { type: RuntimeEventTypes.ActionExecutionEnd
|
|
45
|
+
| { type: RuntimeEventTypes.ActionExecutionArgs; args: string }
|
|
46
|
+
| { type: RuntimeEventTypes.ActionExecutionEnd }
|
|
48
47
|
| {
|
|
49
48
|
type: RuntimeEventTypes.ActionExecutionResult;
|
|
50
49
|
actionName: string;
|
|
@@ -78,31 +77,25 @@ export class RuntimeEventSubject extends ReplaySubject<RuntimeEvent> {
|
|
|
78
77
|
super();
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
sendTextMessageStart(
|
|
80
|
+
sendTextMessageStart(messageId: string) {
|
|
82
81
|
this.next({ type: RuntimeEventTypes.TextMessageStart, messageId });
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
sendTextMessageContent(
|
|
86
|
-
this.next({ type: RuntimeEventTypes.TextMessageContent, content
|
|
84
|
+
sendTextMessageContent(content: string) {
|
|
85
|
+
this.next({ type: RuntimeEventTypes.TextMessageContent, content });
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
sendTextMessageEnd(
|
|
90
|
-
this.next({ type: RuntimeEventTypes.TextMessageEnd
|
|
88
|
+
sendTextMessageEnd() {
|
|
89
|
+
this.next({ type: RuntimeEventTypes.TextMessageEnd });
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
sendTextMessage(messageId: string, content: string) {
|
|
94
|
-
this.sendTextMessageStart(
|
|
95
|
-
this.sendTextMessageContent(
|
|
96
|
-
this.sendTextMessageEnd(
|
|
93
|
+
this.sendTextMessageStart(messageId);
|
|
94
|
+
this.sendTextMessageContent(content);
|
|
95
|
+
this.sendTextMessageEnd();
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
sendActionExecutionStart({
|
|
100
|
-
actionExecutionId,
|
|
101
|
-
actionName,
|
|
102
|
-
}: {
|
|
103
|
-
actionExecutionId: string;
|
|
104
|
-
actionName: string;
|
|
105
|
-
}) {
|
|
98
|
+
sendActionExecutionStart(actionExecutionId: string, actionName: string) {
|
|
106
99
|
this.next({
|
|
107
100
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
108
101
|
actionExecutionId,
|
|
@@ -110,43 +103,21 @@ export class RuntimeEventSubject extends ReplaySubject<RuntimeEvent> {
|
|
|
110
103
|
});
|
|
111
104
|
}
|
|
112
105
|
|
|
113
|
-
sendActionExecutionArgs({
|
|
114
|
-
|
|
115
|
-
args,
|
|
116
|
-
}: {
|
|
117
|
-
actionExecutionId: string;
|
|
118
|
-
args: string;
|
|
119
|
-
}) {
|
|
120
|
-
this.next({ type: RuntimeEventTypes.ActionExecutionArgs, args, actionExecutionId });
|
|
106
|
+
sendActionExecutionArgs(args: string) {
|
|
107
|
+
this.next({ type: RuntimeEventTypes.ActionExecutionArgs, args });
|
|
121
108
|
}
|
|
122
109
|
|
|
123
|
-
sendActionExecutionEnd(
|
|
124
|
-
this.next({ type: RuntimeEventTypes.ActionExecutionEnd
|
|
110
|
+
sendActionExecutionEnd() {
|
|
111
|
+
this.next({ type: RuntimeEventTypes.ActionExecutionEnd });
|
|
125
112
|
}
|
|
126
113
|
|
|
127
|
-
sendActionExecution({
|
|
128
|
-
actionExecutionId,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}: {
|
|
132
|
-
actionExecutionId: string;
|
|
133
|
-
actionName: string;
|
|
134
|
-
args: string;
|
|
135
|
-
}) {
|
|
136
|
-
this.sendActionExecutionStart({ actionExecutionId, actionName });
|
|
137
|
-
this.sendActionExecutionArgs({ actionExecutionId, args });
|
|
138
|
-
this.sendActionExecutionEnd({ actionExecutionId });
|
|
114
|
+
sendActionExecution(actionExecutionId: string, toolName: string, args: string) {
|
|
115
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
116
|
+
this.sendActionExecutionArgs(args);
|
|
117
|
+
this.sendActionExecutionEnd();
|
|
139
118
|
}
|
|
140
119
|
|
|
141
|
-
sendActionExecutionResult({
|
|
142
|
-
actionExecutionId,
|
|
143
|
-
actionName,
|
|
144
|
-
result,
|
|
145
|
-
}: {
|
|
146
|
-
actionExecutionId: string;
|
|
147
|
-
actionName: string;
|
|
148
|
-
result: string;
|
|
149
|
-
}) {
|
|
120
|
+
sendActionExecutionResult(actionExecutionId: string, actionName: string, result: string) {
|
|
150
121
|
this.next({
|
|
151
122
|
type: RuntimeEventTypes.ActionExecutionResult,
|
|
152
123
|
actionName,
|
|
@@ -155,25 +126,16 @@ export class RuntimeEventSubject extends ReplaySubject<RuntimeEvent> {
|
|
|
155
126
|
});
|
|
156
127
|
}
|
|
157
128
|
|
|
158
|
-
sendAgentStateMessage(
|
|
159
|
-
threadId,
|
|
160
|
-
agentName,
|
|
161
|
-
nodeName,
|
|
162
|
-
runId,
|
|
163
|
-
active,
|
|
164
|
-
role,
|
|
165
|
-
state,
|
|
166
|
-
running,
|
|
167
|
-
|
|
168
|
-
threadId: string;
|
|
169
|
-
agentName: string;
|
|
170
|
-
nodeName: string;
|
|
171
|
-
runId: string;
|
|
172
|
-
active: boolean;
|
|
173
|
-
role: string;
|
|
174
|
-
state: string;
|
|
175
|
-
running: boolean;
|
|
176
|
-
}) {
|
|
129
|
+
sendAgentStateMessage(
|
|
130
|
+
threadId: string,
|
|
131
|
+
agentName: string,
|
|
132
|
+
nodeName: string,
|
|
133
|
+
runId: string,
|
|
134
|
+
active: boolean,
|
|
135
|
+
role: string,
|
|
136
|
+
state: string,
|
|
137
|
+
running: boolean,
|
|
138
|
+
) {
|
|
177
139
|
this.next({
|
|
178
140
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
179
141
|
threadId,
|
|
@@ -319,11 +281,11 @@ async function executeAction(
|
|
|
319
281
|
|
|
320
282
|
// handle LangGraph agents
|
|
321
283
|
if (isLangGraphAgentAction(action)) {
|
|
322
|
-
eventStream$.sendActionExecutionResult(
|
|
284
|
+
eventStream$.sendActionExecutionResult(
|
|
323
285
|
actionExecutionId,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
286
|
+
action.name,
|
|
287
|
+
`${action.name} agent started`,
|
|
288
|
+
);
|
|
327
289
|
const stream = await action.langGraphAgentHandler({
|
|
328
290
|
name: action.name,
|
|
329
291
|
actionInputsWithoutAgents,
|
|
@@ -58,15 +58,11 @@ export class ExperimentalOllamaAdapter implements CopilotServiceAdapter {
|
|
|
58
58
|
const _stream = await ollama.stream(contents); // [TODO] role info is dropped...
|
|
59
59
|
|
|
60
60
|
eventSource.stream(async (eventStream$) => {
|
|
61
|
-
|
|
62
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
61
|
+
eventStream$.sendTextMessageStart(randomId());
|
|
63
62
|
for await (const chunkText of _stream) {
|
|
64
|
-
eventStream$.sendTextMessageContent(
|
|
65
|
-
messageId: currentMessageId,
|
|
66
|
-
content: chunkText,
|
|
67
|
-
});
|
|
63
|
+
eventStream$.sendTextMessageContent(chunkText);
|
|
68
64
|
}
|
|
69
|
-
eventStream$.sendTextMessageEnd(
|
|
65
|
+
eventStream$.sendTextMessageEnd();
|
|
70
66
|
// we may need to add this later.. [nc]
|
|
71
67
|
// let calls = (await result.response).functionCalls();
|
|
72
68
|
|