@copilotkit/runtime 1.8.15-next.1 → 1.9.0-next.2
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 +11 -0
- package/dist/{chunk-WPALAYGE.mjs → chunk-6A27R7IP.mjs} +4 -2
- package/dist/chunk-6A27R7IP.mjs.map +1 -0
- package/dist/{chunk-2DM4G7DN.mjs → chunk-G4NOAQUA.mjs} +2 -2
- package/dist/{chunk-XRKKSNLV.mjs → chunk-S5TNKSNR.mjs} +2 -2
- package/dist/chunk-XB3TW5NJ.mjs +141 -0
- package/dist/chunk-XB3TW5NJ.mjs.map +1 -0
- package/dist/{chunk-76QVO5FK.mjs → chunk-XPTVSVNM.mjs} +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +140 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -5
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +154 -2
- package/dist/lib/index.js +140 -6
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -5
- package/dist/lib/integrations/index.js +2 -1
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.js +2 -1
- 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.js +2 -1
- 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.js +2 -1
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/package.json +3 -2
- package/src/lib/index.ts +1 -0
- package/src/lib/runtime/langgraph/langgraph-agent.ts +190 -0
- package/dist/chunk-Q6JA6YY3.mjs +0 -1
- package/dist/chunk-Q6JA6YY3.mjs.map +0 -1
- package/dist/chunk-WPALAYGE.mjs.map +0 -1
- /package/dist/{chunk-2DM4G7DN.mjs.map → chunk-G4NOAQUA.mjs.map} +0 -0
- /package/dist/{chunk-XRKKSNLV.mjs.map → chunk-S5TNKSNR.mjs.map} +0 -0
- /package/dist/{chunk-76QVO5FK.mjs.map → chunk-XPTVSVNM.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6A27R7IP.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
config,
|
|
78
78
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-G4NOAQUA.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6A27R7IP.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNodeExpressEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-S5TNKSNR.mjs.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LangGraphEventTypes
|
|
3
|
+
} from "./chunk-6A27R7IP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-FHD4JECV.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/runtime/langgraph/langgraph-agent.ts
|
|
9
|
+
import { EventType } from "@ag-ui/client";
|
|
10
|
+
import { map } from "rxjs";
|
|
11
|
+
import { LangGraphAgent as AGUILangGraphAgent } from "@ag-ui/langgraph";
|
|
12
|
+
var CustomEventNames;
|
|
13
|
+
(function(CustomEventNames2) {
|
|
14
|
+
CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
15
|
+
CustomEventNames2["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
16
|
+
CustomEventNames2["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
17
|
+
CustomEventNames2["CopilotKitExit"] = "copilotkit_exit";
|
|
18
|
+
})(CustomEventNames || (CustomEventNames = {}));
|
|
19
|
+
var LangGraphAgent = class extends AGUILangGraphAgent {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
super(config);
|
|
22
|
+
}
|
|
23
|
+
dispatchEvent(event) {
|
|
24
|
+
if (event.type === EventType.CUSTOM) {
|
|
25
|
+
const customEvent = event;
|
|
26
|
+
if (customEvent.name === "copilotkit_manually_emit_message") {
|
|
27
|
+
this.subscriber.next({
|
|
28
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
29
|
+
role: "assistant",
|
|
30
|
+
messageId: customEvent.value.message_id,
|
|
31
|
+
rawEvent: event
|
|
32
|
+
});
|
|
33
|
+
this.subscriber.next({
|
|
34
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
35
|
+
messageId: customEvent.value.message_id,
|
|
36
|
+
delta: customEvent.value.message,
|
|
37
|
+
rawEvent: event
|
|
38
|
+
});
|
|
39
|
+
this.subscriber.next({
|
|
40
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
41
|
+
messageId: customEvent.value.message_id,
|
|
42
|
+
rawEvent: event
|
|
43
|
+
});
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (customEvent.name === "copilotkit_manually_emit_tool_call") {
|
|
47
|
+
this.subscriber.next({
|
|
48
|
+
type: EventType.TOOL_CALL_START,
|
|
49
|
+
toolCallId: customEvent.value.id,
|
|
50
|
+
toolCallName: customEvent.value.name,
|
|
51
|
+
parentMessageId: customEvent.value.id,
|
|
52
|
+
rawEvent: event
|
|
53
|
+
});
|
|
54
|
+
this.subscriber.next({
|
|
55
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
56
|
+
toolCallId: customEvent.value.id,
|
|
57
|
+
delta: customEvent.value.args,
|
|
58
|
+
rawEvent: event
|
|
59
|
+
});
|
|
60
|
+
this.subscriber.next({
|
|
61
|
+
type: EventType.TOOL_CALL_END,
|
|
62
|
+
toolCallId: customEvent.value.id,
|
|
63
|
+
rawEvent: event
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (customEvent.name === "copilotkit_manually_emit_intermediate_state") {
|
|
68
|
+
this.activeRun.manuallyEmittedState = customEvent.value;
|
|
69
|
+
this.dispatchEvent({
|
|
70
|
+
type: EventType.STATE_SNAPSHOT,
|
|
71
|
+
snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),
|
|
72
|
+
rawEvent: event
|
|
73
|
+
});
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (customEvent.name === "copilotkit_exit") {
|
|
77
|
+
this.subscriber.next({
|
|
78
|
+
type: EventType.CUSTOM,
|
|
79
|
+
name: "Exit",
|
|
80
|
+
value: true
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const rawEvent = event.rawEvent;
|
|
86
|
+
if (!rawEvent) {
|
|
87
|
+
this.subscriber.next(event);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
const isMessageEvent = event.type === EventType.TEXT_MESSAGE_START || event.type === EventType.TEXT_MESSAGE_CONTENT || event.type === EventType.TEXT_MESSAGE_END;
|
|
91
|
+
const isToolEvent = event.type === EventType.TOOL_CALL_START || event.type === EventType.TOOL_CALL_ARGS || event.type === EventType.TOOL_CALL_END;
|
|
92
|
+
if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
|
|
93
|
+
if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
|
|
98
|
+
if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
this.subscriber.next(event);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
run(input) {
|
|
107
|
+
return super.run(input).pipe(map((processedEvent) => {
|
|
108
|
+
var _a, _b, _c, _d, _e;
|
|
109
|
+
if (processedEvent.type === EventType.RAW) {
|
|
110
|
+
const event = processedEvent.event ?? processedEvent.rawEvent;
|
|
111
|
+
const eventType = event.event;
|
|
112
|
+
const toolCallData = (_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.tool_call_chunks) == null ? void 0 : _c[0];
|
|
113
|
+
const toolCallUsedToPredictState = (_e = (_d = event.metadata) == null ? void 0 : _d["copilotkit:emit-intermediate-state"]) == null ? void 0 : _e.some((predictStateTool) => predictStateTool.tool === (toolCallData == null ? void 0 : toolCallData.name));
|
|
114
|
+
if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
|
|
115
|
+
return {
|
|
116
|
+
type: EventType.CUSTOM,
|
|
117
|
+
name: "PredictState",
|
|
118
|
+
value: event.metadata["copilotkit:emit-intermediate-state"]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return processedEvent;
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
langGraphDefaultMergeState(state, messages, tools) {
|
|
126
|
+
const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(state, messages, tools);
|
|
127
|
+
return {
|
|
128
|
+
...rest,
|
|
129
|
+
copilotkit: {
|
|
130
|
+
actions: returnedTools
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
__name(LangGraphAgent, "LangGraphAgent");
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
CustomEventNames,
|
|
139
|
+
LangGraphAgent
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=chunk-XB3TW5NJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/runtime/langgraph/langgraph-agent.ts"],"sourcesContent":["import {\n RunAgentInput,\n EventType,\n CustomEvent,\n TextMessageStartEvent,\n TextMessageContentEvent,\n TextMessageEndEvent,\n ToolCallStartEvent,\n ToolCallArgsEvent,\n ToolCallEndEvent,\n} from \"@ag-ui/client\";\nimport { map } from \"rxjs\";\nimport { LangGraphEventTypes } from \"../../../agents/langgraph/events\";\nimport { RawEvent } from \"@ag-ui/core\";\nimport {\n LangGraphAgent as AGUILangGraphAgent,\n type LangGraphAgentConfig,\n ProcessedEvents,\n} from \"@ag-ui/langgraph\";\nimport { Message as LangGraphMessage } from \"@langchain/langgraph-sdk/dist/types.messages\";\n\nexport interface PredictStateTool {\n tool: string;\n state_key: string;\n tool_argument: string;\n}\nexport type State = Record<string, any>;\n\nexport type TextMessageEvents =\n | TextMessageStartEvent\n | TextMessageContentEvent\n | TextMessageEndEvent;\n\nexport type ToolCallEvents = ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;\n\nexport enum CustomEventNames {\n CopilotKitManuallyEmitMessage = \"copilotkit_manually_emit_message\",\n CopilotKitManuallyEmitToolCall = \"copilotkit_manually_emit_tool_call\",\n CopilotKitManuallyEmitIntermediateState = \"copilotkit_manually_emit_intermediate_state\",\n CopilotKitExit = \"copilotkit_exit\",\n}\n\nexport class LangGraphAgent extends AGUILangGraphAgent {\n constructor(config: LangGraphAgentConfig) {\n super(config);\n }\n\n dispatchEvent(event: ProcessedEvents) {\n if (event.type === EventType.CUSTOM) {\n // const event = processedEvent as unknown as CustomEvent;\n const customEvent = event as unknown as CustomEvent;\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitMessage) {\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_START,\n role: \"assistant\",\n messageId: customEvent.value.message_id,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId: customEvent.value.message_id,\n delta: customEvent.value.message,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_END,\n messageId: customEvent.value.message_id,\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {\n this.subscriber.next({\n type: EventType.TOOL_CALL_START,\n toolCallId: customEvent.value.id,\n toolCallName: customEvent.value.name,\n parentMessageId: customEvent.value.id,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TOOL_CALL_ARGS,\n toolCallId: customEvent.value.id,\n delta: customEvent.value.args,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TOOL_CALL_END,\n toolCallId: customEvent.value.id,\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState) {\n this.activeRun.manuallyEmittedState = customEvent.value;\n this.dispatchEvent({\n type: EventType.STATE_SNAPSHOT,\n snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitExit) {\n this.subscriber.next({\n type: EventType.CUSTOM,\n name: \"Exit\",\n value: true,\n });\n return true;\n }\n }\n\n // Intercept all text message and tool call events and check if should disable\n const rawEvent = (event as ToolCallEvents | TextMessageEvents).rawEvent;\n if (!rawEvent) {\n this.subscriber.next(event);\n return true;\n }\n\n const isMessageEvent =\n event.type === EventType.TEXT_MESSAGE_START ||\n event.type === EventType.TEXT_MESSAGE_CONTENT ||\n event.type === EventType.TEXT_MESSAGE_END;\n const isToolEvent =\n event.type === EventType.TOOL_CALL_START ||\n event.type === EventType.TOOL_CALL_ARGS ||\n event.type === EventType.TOOL_CALL_END;\n if (\"copilotkit:emit-tool-calls\" in (rawEvent.metadata || {})) {\n if (rawEvent.metadata[\"copilotkit:emit-tool-calls\"] === false && isToolEvent) {\n return false;\n }\n }\n if (\"copilotkit:emit-messages\" in (rawEvent.metadata || {})) {\n if (rawEvent.metadata[\"copilotkit:emit-messages\"] === false && isMessageEvent) {\n return false;\n }\n }\n\n this.subscriber.next(event);\n return true;\n }\n\n // @ts-ignore\n run(input: RunAgentInput) {\n return super.run(input).pipe(\n map((processedEvent) => {\n // Turn raw event into emit state snapshot from tool call event\n if (processedEvent.type === EventType.RAW) {\n // Get the LangGraph event from the AGUI event.\n const event = (processedEvent as RawEvent).event ?? (processedEvent as RawEvent).rawEvent;\n\n const eventType = event.event;\n const toolCallData = event.data?.chunk?.tool_call_chunks?.[0];\n const toolCallUsedToPredictState = event.metadata?.[\n \"copilotkit:emit-intermediate-state\"\n ]?.some(\n (predictStateTool: PredictStateTool) => predictStateTool.tool === toolCallData?.name,\n );\n\n if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {\n return {\n type: EventType.CUSTOM,\n name: \"PredictState\",\n value: event.metadata[\"copilotkit:emit-intermediate-state\"],\n };\n }\n }\n\n return processedEvent;\n }),\n );\n }\n\n langGraphDefaultMergeState(state: State, messages: LangGraphMessage[], tools: any): State {\n const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(\n state,\n messages,\n tools,\n );\n return {\n ...rest,\n copilotkit: {\n actions: returnedTools,\n },\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAEEA,iBAQK;AACP,SAASC,WAAW;AAGpB,SAC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C8C,KACD,CAACC,qBAAuCA,iBAAiBC,UAASP,6CAAcpC;AAGlF,YAAImC,cAAcS,oBAAoBC,qBAAqBL,4BAA4B;AACrF,iBAAO;YACL5C,MAAMC,UAAUC;YAChBE,MAAM;YACNM,OAAOX,MAAMiC,SAAS,oCAAA;UACxB;QACF;MACF;AAEA,aAAOK;IACT,CAAA,CAAA;EAEJ;EAEAa,2BAA2BC,OAAcC,UAA8BC,OAAmB;AACxF,UAAM,EAAEA,OAAOC,eAAe,GAAGC,KAAAA,IAAS,MAAML,2BAC9CC,OACAC,UACAC,KAAAA;AAEF,WAAO;MACL,GAAGE;MACHC,YAAY;QACVC,SAASH;MACX;IACF;EACF;AACF;AAnJa5D;","names":["EventType","map","LangGraphAgent","AGUILangGraphAgent","CustomEventNames","LangGraphAgent","AGUILangGraphAgent","constructor","config","dispatchEvent","event","type","EventType","CUSTOM","customEvent","name","subscriber","next","TEXT_MESSAGE_START","role","messageId","value","message_id","rawEvent","TEXT_MESSAGE_CONTENT","delta","message","TEXT_MESSAGE_END","TOOL_CALL_START","toolCallId","id","toolCallName","parentMessageId","TOOL_CALL_ARGS","args","TOOL_CALL_END","activeRun","manuallyEmittedState","STATE_SNAPSHOT","snapshot","getStateSnapshot","isMessageEvent","isToolEvent","metadata","run","input","pipe","map","processedEvent","RAW","eventType","toolCallData","data","chunk","tool_call_chunks","toolCallUsedToPredictState","some","predictStateTool","tool","LangGraphEventTypes","OnChatModelStream","langGraphDefaultMergeState","state","messages","tools","returnedTools","rest","copilotkit","actions"]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6A27R7IP.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNestEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-XPTVSVNM.mjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndp
|
|
|
4
4
|
export { copilotRuntimeNodeHttpEndpoint } from './lib/integrations/node-http/index.js';
|
|
5
5
|
export { copilotRuntimeNodeExpressEndpoint } from './lib/integrations/node-express/index.js';
|
|
6
6
|
export { copilotRuntimeNestEndpoint } from './lib/integrations/nest/index.js';
|
|
7
|
+
export { CustomEventNames, LangGraphAgent, PredictStateTool, State, TextMessageEvents, ToolCallEvents } from './lib/index.js';
|
|
7
8
|
export { GuardrailsValidationFailureResponse, MessageStreamInterruptedResponse, UnknownErrorResponse } from './utils/index.js';
|
|
8
9
|
export { C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse, b as CopilotServiceAdapter, c as RemoteChain, R as RemoteChainParameters } from './langserve-4a5c9217.js';
|
|
9
10
|
export { AnthropicAdapter, AnthropicAdapterParams, BedrockAdapter, BedrockAdapterParams, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter } from './service-adapters/index.js';
|
|
@@ -21,4 +22,6 @@ import './graphql/types/base/index.js';
|
|
|
21
22
|
import './lib/cloud/index.js';
|
|
22
23
|
import '@ag-ui/client';
|
|
23
24
|
import 'rxjs';
|
|
25
|
+
import '@ag-ui/langgraph';
|
|
26
|
+
import '@langchain/langgraph-sdk/dist/types.messages';
|
|
24
27
|
import '@anthropic-ai/sdk';
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.
|
|
47
|
+
version: "1.9.0-next.2",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -85,6 +85,7 @@ var require_package = __commonJS({
|
|
|
85
85
|
"@ag-ui/client": "0.0.28",
|
|
86
86
|
"@ag-ui/core": "0.0.28",
|
|
87
87
|
"@ag-ui/encoder": "0.0.28",
|
|
88
|
+
"@ag-ui/langgraph": "0.0.3",
|
|
88
89
|
"@ag-ui/proto": "0.0.28",
|
|
89
90
|
"@anthropic-ai/sdk": "^0.27.3",
|
|
90
91
|
"@copilotkit/shared": "workspace:*",
|
|
@@ -140,6 +141,7 @@ __export(src_exports, {
|
|
|
140
141
|
AnthropicAdapter: () => AnthropicAdapter,
|
|
141
142
|
BedrockAdapter: () => BedrockAdapter,
|
|
142
143
|
CopilotRuntime: () => CopilotRuntime,
|
|
144
|
+
CustomEventNames: () => CustomEventNames2,
|
|
143
145
|
EmptyAdapter: () => EmptyAdapter,
|
|
144
146
|
ExperimentalEmptyAdapter: () => ExperimentalEmptyAdapter,
|
|
145
147
|
ExperimentalOllamaAdapter: () => ExperimentalOllamaAdapter,
|
|
@@ -147,6 +149,7 @@ __export(src_exports, {
|
|
|
147
149
|
GroqAdapter: () => GroqAdapter,
|
|
148
150
|
GuardrailsValidationFailureResponse: () => GuardrailsValidationFailureResponse,
|
|
149
151
|
LangChainAdapter: () => LangChainAdapter,
|
|
152
|
+
LangGraphAgent: () => LangGraphAgent,
|
|
150
153
|
MessageStreamInterruptedResponse: () => MessageStreamInterruptedResponse,
|
|
151
154
|
OpenAIAdapter: () => OpenAIAdapter,
|
|
152
155
|
OpenAIAssistantAdapter: () => OpenAIAssistantAdapter,
|
|
@@ -2780,11 +2783,11 @@ var MetaEventNames;
|
|
|
2780
2783
|
MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
2781
2784
|
})(MetaEventNames || (MetaEventNames = {}));
|
|
2782
2785
|
var CustomEventNames;
|
|
2783
|
-
(function(
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2786
|
+
(function(CustomEventNames3) {
|
|
2787
|
+
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
2788
|
+
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
2789
|
+
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
2790
|
+
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
2788
2791
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
2789
2792
|
|
|
2790
2793
|
// src/agents/langgraph/event-source.ts
|
|
@@ -7078,11 +7081,141 @@ function copilotRuntimeNestEndpoint(options) {
|
|
|
7078
7081
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
7079
7082
|
}
|
|
7080
7083
|
__name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
7084
|
+
|
|
7085
|
+
// src/lib/runtime/langgraph/langgraph-agent.ts
|
|
7086
|
+
var import_client = require("@ag-ui/client");
|
|
7087
|
+
var import_rxjs5 = require("rxjs");
|
|
7088
|
+
var import_langgraph = require("@ag-ui/langgraph");
|
|
7089
|
+
var CustomEventNames2;
|
|
7090
|
+
(function(CustomEventNames3) {
|
|
7091
|
+
CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
7092
|
+
CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
|
|
7093
|
+
CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
|
|
7094
|
+
CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
|
|
7095
|
+
})(CustomEventNames2 || (CustomEventNames2 = {}));
|
|
7096
|
+
var LangGraphAgent = class extends import_langgraph.LangGraphAgent {
|
|
7097
|
+
constructor(config2) {
|
|
7098
|
+
super(config2);
|
|
7099
|
+
}
|
|
7100
|
+
dispatchEvent(event) {
|
|
7101
|
+
if (event.type === import_client.EventType.CUSTOM) {
|
|
7102
|
+
const customEvent = event;
|
|
7103
|
+
if (customEvent.name === "copilotkit_manually_emit_message") {
|
|
7104
|
+
this.subscriber.next({
|
|
7105
|
+
type: import_client.EventType.TEXT_MESSAGE_START,
|
|
7106
|
+
role: "assistant",
|
|
7107
|
+
messageId: customEvent.value.message_id,
|
|
7108
|
+
rawEvent: event
|
|
7109
|
+
});
|
|
7110
|
+
this.subscriber.next({
|
|
7111
|
+
type: import_client.EventType.TEXT_MESSAGE_CONTENT,
|
|
7112
|
+
messageId: customEvent.value.message_id,
|
|
7113
|
+
delta: customEvent.value.message,
|
|
7114
|
+
rawEvent: event
|
|
7115
|
+
});
|
|
7116
|
+
this.subscriber.next({
|
|
7117
|
+
type: import_client.EventType.TEXT_MESSAGE_END,
|
|
7118
|
+
messageId: customEvent.value.message_id,
|
|
7119
|
+
rawEvent: event
|
|
7120
|
+
});
|
|
7121
|
+
return true;
|
|
7122
|
+
}
|
|
7123
|
+
if (customEvent.name === "copilotkit_manually_emit_tool_call") {
|
|
7124
|
+
this.subscriber.next({
|
|
7125
|
+
type: import_client.EventType.TOOL_CALL_START,
|
|
7126
|
+
toolCallId: customEvent.value.id,
|
|
7127
|
+
toolCallName: customEvent.value.name,
|
|
7128
|
+
parentMessageId: customEvent.value.id,
|
|
7129
|
+
rawEvent: event
|
|
7130
|
+
});
|
|
7131
|
+
this.subscriber.next({
|
|
7132
|
+
type: import_client.EventType.TOOL_CALL_ARGS,
|
|
7133
|
+
toolCallId: customEvent.value.id,
|
|
7134
|
+
delta: customEvent.value.args,
|
|
7135
|
+
rawEvent: event
|
|
7136
|
+
});
|
|
7137
|
+
this.subscriber.next({
|
|
7138
|
+
type: import_client.EventType.TOOL_CALL_END,
|
|
7139
|
+
toolCallId: customEvent.value.id,
|
|
7140
|
+
rawEvent: event
|
|
7141
|
+
});
|
|
7142
|
+
return true;
|
|
7143
|
+
}
|
|
7144
|
+
if (customEvent.name === "copilotkit_manually_emit_intermediate_state") {
|
|
7145
|
+
this.activeRun.manuallyEmittedState = customEvent.value;
|
|
7146
|
+
this.dispatchEvent({
|
|
7147
|
+
type: import_client.EventType.STATE_SNAPSHOT,
|
|
7148
|
+
snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),
|
|
7149
|
+
rawEvent: event
|
|
7150
|
+
});
|
|
7151
|
+
return true;
|
|
7152
|
+
}
|
|
7153
|
+
if (customEvent.name === "copilotkit_exit") {
|
|
7154
|
+
this.subscriber.next({
|
|
7155
|
+
type: import_client.EventType.CUSTOM,
|
|
7156
|
+
name: "Exit",
|
|
7157
|
+
value: true
|
|
7158
|
+
});
|
|
7159
|
+
return true;
|
|
7160
|
+
}
|
|
7161
|
+
}
|
|
7162
|
+
const rawEvent = event.rawEvent;
|
|
7163
|
+
if (!rawEvent) {
|
|
7164
|
+
this.subscriber.next(event);
|
|
7165
|
+
return true;
|
|
7166
|
+
}
|
|
7167
|
+
const isMessageEvent = event.type === import_client.EventType.TEXT_MESSAGE_START || event.type === import_client.EventType.TEXT_MESSAGE_CONTENT || event.type === import_client.EventType.TEXT_MESSAGE_END;
|
|
7168
|
+
const isToolEvent = event.type === import_client.EventType.TOOL_CALL_START || event.type === import_client.EventType.TOOL_CALL_ARGS || event.type === import_client.EventType.TOOL_CALL_END;
|
|
7169
|
+
if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
|
|
7170
|
+
if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
|
|
7171
|
+
return false;
|
|
7172
|
+
}
|
|
7173
|
+
}
|
|
7174
|
+
if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
|
|
7175
|
+
if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
|
|
7176
|
+
return false;
|
|
7177
|
+
}
|
|
7178
|
+
}
|
|
7179
|
+
this.subscriber.next(event);
|
|
7180
|
+
return true;
|
|
7181
|
+
}
|
|
7182
|
+
// @ts-ignore
|
|
7183
|
+
run(input) {
|
|
7184
|
+
return super.run(input).pipe((0, import_rxjs5.map)((processedEvent) => {
|
|
7185
|
+
var _a, _b, _c, _d, _e;
|
|
7186
|
+
if (processedEvent.type === import_client.EventType.RAW) {
|
|
7187
|
+
const event = processedEvent.event ?? processedEvent.rawEvent;
|
|
7188
|
+
const eventType = event.event;
|
|
7189
|
+
const toolCallData = (_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.tool_call_chunks) == null ? void 0 : _c[0];
|
|
7190
|
+
const toolCallUsedToPredictState = (_e = (_d = event.metadata) == null ? void 0 : _d["copilotkit:emit-intermediate-state"]) == null ? void 0 : _e.some((predictStateTool) => predictStateTool.tool === (toolCallData == null ? void 0 : toolCallData.name));
|
|
7191
|
+
if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
|
|
7192
|
+
return {
|
|
7193
|
+
type: import_client.EventType.CUSTOM,
|
|
7194
|
+
name: "PredictState",
|
|
7195
|
+
value: event.metadata["copilotkit:emit-intermediate-state"]
|
|
7196
|
+
};
|
|
7197
|
+
}
|
|
7198
|
+
}
|
|
7199
|
+
return processedEvent;
|
|
7200
|
+
}));
|
|
7201
|
+
}
|
|
7202
|
+
langGraphDefaultMergeState(state, messages, tools) {
|
|
7203
|
+
const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(state, messages, tools);
|
|
7204
|
+
return {
|
|
7205
|
+
...rest,
|
|
7206
|
+
copilotkit: {
|
|
7207
|
+
actions: returnedTools
|
|
7208
|
+
}
|
|
7209
|
+
};
|
|
7210
|
+
}
|
|
7211
|
+
};
|
|
7212
|
+
__name(LangGraphAgent, "LangGraphAgent");
|
|
7081
7213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7082
7214
|
0 && (module.exports = {
|
|
7083
7215
|
AnthropicAdapter,
|
|
7084
7216
|
BedrockAdapter,
|
|
7085
7217
|
CopilotRuntime,
|
|
7218
|
+
CustomEventNames,
|
|
7086
7219
|
EmptyAdapter,
|
|
7087
7220
|
ExperimentalEmptyAdapter,
|
|
7088
7221
|
ExperimentalOllamaAdapter,
|
|
@@ -7090,6 +7223,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
7090
7223
|
GroqAdapter,
|
|
7091
7224
|
GuardrailsValidationFailureResponse,
|
|
7092
7225
|
LangChainAdapter,
|
|
7226
|
+
LangGraphAgent,
|
|
7093
7227
|
MessageStreamInterruptedResponse,
|
|
7094
7228
|
OpenAIAdapter,
|
|
7095
7229
|
OpenAIAssistantAdapter,
|