@copilotkit/runtime 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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.
- package/CHANGELOG.md +20 -5
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-APVJZO3R.mjs → chunk-7BOO3OFP.mjs} +2 -2
- package/dist/{chunk-OSWF5QDO.mjs → chunk-GSTWFOZF.mjs} +2 -2
- package/dist/{chunk-M74ZTUCC.mjs → chunk-OMAAKIJQ.mjs} +2 -2
- package/dist/{chunk-36AYTJIE.mjs → chunk-PXS4SBRF.mjs} +447 -321
- package/dist/chunk-PXS4SBRF.mjs.map +1 -0
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +824 -473
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +729 -452
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +79 -31
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +79 -31
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +79 -31
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +79 -31
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/logger.ts +4 -0
- package/src/lib/runtime/copilot-runtime.ts +1 -7
- package/src/lib/runtime/remote-action-constructors.ts +64 -58
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +159 -140
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-36AYTJIE.mjs.map +0 -1
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-APVJZO3R.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
- /package/dist/{chunk-OSWF5QDO.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
- /package/dist/{chunk-M74ZTUCC.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
|
@@ -5,13 +5,17 @@ import { randomId } from "@copilotkit/shared";
|
|
|
5
5
|
|
|
6
6
|
interface LangGraphEventWithState {
|
|
7
7
|
event: LangGraphEvent | null;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
|
|
9
|
+
isMessageStart: boolean;
|
|
10
|
+
isMessageEnd: boolean;
|
|
11
|
+
isToolCallStart: boolean;
|
|
12
|
+
isToolCallEnd: boolean;
|
|
13
|
+
isToolCall: boolean;
|
|
14
|
+
|
|
15
|
+
lastMessageId: string | null;
|
|
16
|
+
lastToolCallId: string | null;
|
|
17
|
+
lastToolCallName: string | null;
|
|
18
|
+
currentContent: string | null;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export class RemoteLangGraphEventSource {
|
|
@@ -30,6 +34,43 @@ export class RemoteLangGraphEventSource {
|
|
|
30
34
|
return shouldEmitToolCalls === toolCallName;
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
private getCurrentContent(event: LangGraphEvent) {
|
|
38
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
39
|
+
const content = event.data?.chunk?.kwargs?.content ?? event.data?.chunk?.content;
|
|
40
|
+
|
|
41
|
+
if (!content) {
|
|
42
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
43
|
+
for (const chunk of toolCallChunks) {
|
|
44
|
+
if (chunk.args) {
|
|
45
|
+
return chunk.args;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof content === "string") {
|
|
51
|
+
return content;
|
|
52
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
53
|
+
return content[0].text;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private getCurrentMessageId(event: LangGraphEvent) {
|
|
60
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
61
|
+
return event.data?.chunk?.kwargs?.id ?? event.data?.chunk?.id;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private getCurrentToolCallChunks(event: LangGraphEvent) {
|
|
65
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
66
|
+
return event.data?.chunk?.kwargs?.tool_call_chunks ?? event.data?.chunk?.tool_call_chunks;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private getResponseMetadata(event: LangGraphEvent) {
|
|
70
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
71
|
+
return event.data?.chunk?.kwargs?.response_metadata ?? event.data?.chunk?.response_metadata;
|
|
72
|
+
}
|
|
73
|
+
|
|
33
74
|
processLangGraphEvents() {
|
|
34
75
|
let lastEventWithState: LangGraphEventWithState | null = null;
|
|
35
76
|
|
|
@@ -37,104 +78,75 @@ export class RemoteLangGraphEventSource {
|
|
|
37
78
|
scan(
|
|
38
79
|
(acc, event) => {
|
|
39
80
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else if (Array.isArray(content) && content.length > 0) {
|
|
46
|
-
acc.content = content[0].text;
|
|
47
|
-
} else {
|
|
48
|
-
acc.content = null;
|
|
49
|
-
}
|
|
81
|
+
const prevMessageId = acc.lastMessageId;
|
|
82
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
83
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
84
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
85
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
60
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
61
|
-
acc.toolCallMessageId = toolCallMessageId;
|
|
62
|
-
if (toolCallChunks[0]?.name) {
|
|
63
|
-
acc.toolCallName = toolCallChunks[0].name;
|
|
64
|
-
}
|
|
65
|
-
if (toolCallChunks[0]?.id) {
|
|
66
|
-
acc.toolCallId = toolCallChunks[0].id;
|
|
67
|
-
}
|
|
68
|
-
acc.prevMessageId = acc.messageId;
|
|
69
|
-
acc.messageId = toolCallMessageId;
|
|
70
|
-
} else if (acc.content && acc.content != "") {
|
|
71
|
-
acc.prevMessageId = acc.messageId;
|
|
72
|
-
acc.messageId = toolCallMessageId;
|
|
73
|
-
} else {
|
|
74
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
75
|
-
acc.prevMessageId = acc.messageId;
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
79
|
-
acc.toolCallMessageId = null;
|
|
80
|
-
acc.prevMessageId = acc.messageId;
|
|
81
|
-
acc.messageId = null;
|
|
82
|
-
acc.toolCallName = null;
|
|
87
|
+
acc.isToolCallStart = toolCallChunks.some((chunk: any) => chunk.name && chunk.id);
|
|
88
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
89
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
90
|
+
acc.isToolCallEnd = responseMetadata?.finish_reason === "tool_calls";
|
|
91
|
+
acc.isMessageEnd = responseMetadata?.finish_reason === "stop";
|
|
92
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find(
|
|
93
|
+
(chunk: any) => chunk.name && chunk.id,
|
|
94
|
+
) ?? { name: acc.lastToolCallName, id: acc.lastToolCallId });
|
|
83
95
|
}
|
|
84
|
-
|
|
85
96
|
acc.event = event;
|
|
86
97
|
lastEventWithState = acc; // Capture the state
|
|
87
98
|
return acc;
|
|
88
99
|
},
|
|
89
100
|
{
|
|
90
101
|
event: null,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
isMessageStart: false,
|
|
103
|
+
isMessageEnd: false,
|
|
104
|
+
isToolCallStart: false,
|
|
105
|
+
isToolCallEnd: false,
|
|
106
|
+
isToolCall: false,
|
|
107
|
+
lastMessageId: null,
|
|
108
|
+
lastToolCallId: null,
|
|
109
|
+
lastToolCallName: null,
|
|
110
|
+
currentContent: null,
|
|
98
111
|
} as LangGraphEventWithState,
|
|
99
112
|
),
|
|
100
|
-
mergeMap((
|
|
113
|
+
mergeMap((acc): RuntimeEvent[] => {
|
|
101
114
|
const events: RuntimeEvent[] = [];
|
|
102
115
|
|
|
103
116
|
let shouldEmitMessages = true;
|
|
104
|
-
let shouldEmitToolCalls: string | string[] | boolean =
|
|
117
|
+
let shouldEmitToolCalls: string | string[] | boolean = true;
|
|
105
118
|
|
|
106
|
-
if (
|
|
107
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
108
|
-
shouldEmitToolCalls =
|
|
119
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
120
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
121
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
109
122
|
}
|
|
110
|
-
if ("copilotkit:emit-messages" in (
|
|
111
|
-
shouldEmitMessages =
|
|
123
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
124
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
|
|
128
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
129
|
+
|
|
115
130
|
// Tool call ended: emit ActionExecutionEnd
|
|
116
131
|
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)
|
|
132
|
+
responseMetadata?.finish_reason === "tool_calls" &&
|
|
133
|
+
this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
|
|
120
134
|
) {
|
|
121
135
|
events.push({
|
|
122
136
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
137
|
+
actionExecutionId: acc.lastToolCallId,
|
|
123
138
|
});
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
// Message ended: emit TextMessageEnd
|
|
127
|
-
if (
|
|
128
|
-
eventWithState.prevMessageId !== null &&
|
|
129
|
-
eventWithState.prevMessageId !== eventWithState.messageId &&
|
|
130
|
-
shouldEmitMessages
|
|
131
|
-
) {
|
|
142
|
+
if (responseMetadata?.finish_reason === "stop" && shouldEmitMessages) {
|
|
132
143
|
events.push({
|
|
133
144
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
145
|
+
messageId: acc.lastMessageId,
|
|
134
146
|
});
|
|
135
147
|
}
|
|
136
148
|
|
|
137
|
-
switch (
|
|
149
|
+
switch (acc.event!.event) {
|
|
138
150
|
//
|
|
139
151
|
// Custom events
|
|
140
152
|
//
|
|
@@ -142,118 +154,94 @@ export class RemoteLangGraphEventSource {
|
|
|
142
154
|
//
|
|
143
155
|
// Manually emit a message
|
|
144
156
|
//
|
|
145
|
-
if (
|
|
157
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
146
158
|
events.push({
|
|
147
159
|
type: RuntimeEventTypes.TextMessageStart,
|
|
148
|
-
messageId:
|
|
160
|
+
messageId: acc.event.data.message_id,
|
|
149
161
|
});
|
|
150
162
|
events.push({
|
|
151
163
|
type: RuntimeEventTypes.TextMessageContent,
|
|
152
|
-
|
|
164
|
+
messageId: acc.event.data.message_id,
|
|
165
|
+
content: acc.event.data.message,
|
|
153
166
|
});
|
|
154
167
|
events.push({
|
|
155
168
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
169
|
+
messageId: acc.event.data.message_id,
|
|
156
170
|
});
|
|
157
171
|
}
|
|
158
172
|
//
|
|
159
173
|
// Manually emit a tool call
|
|
160
174
|
//
|
|
161
|
-
else if (
|
|
162
|
-
eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall
|
|
163
|
-
) {
|
|
175
|
+
else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
164
176
|
events.push({
|
|
165
177
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
166
|
-
actionExecutionId:
|
|
167
|
-
actionName:
|
|
178
|
+
actionExecutionId: acc.event.data.id,
|
|
179
|
+
actionName: acc.event.data.name,
|
|
180
|
+
parentMessageId: acc.event.data.id,
|
|
168
181
|
});
|
|
169
182
|
events.push({
|
|
170
183
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
171
|
-
|
|
184
|
+
actionExecutionId: acc.event.data.id,
|
|
185
|
+
args: JSON.stringify(acc.event.data.args),
|
|
172
186
|
});
|
|
173
187
|
events.push({
|
|
174
188
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
189
|
+
actionExecutionId: acc.event.data.id,
|
|
175
190
|
});
|
|
176
191
|
}
|
|
177
192
|
break;
|
|
178
193
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
179
194
|
events.push({
|
|
180
195
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
181
|
-
threadId:
|
|
182
|
-
role:
|
|
183
|
-
agentName:
|
|
184
|
-
nodeName:
|
|
185
|
-
runId:
|
|
186
|
-
active:
|
|
187
|
-
state: JSON.stringify(
|
|
188
|
-
running:
|
|
196
|
+
threadId: acc.event.thread_id,
|
|
197
|
+
role: acc.event.role,
|
|
198
|
+
agentName: acc.event.agent_name,
|
|
199
|
+
nodeName: acc.event.node_name,
|
|
200
|
+
runId: acc.event.run_id,
|
|
201
|
+
active: acc.event.active,
|
|
202
|
+
state: JSON.stringify(acc.event.state),
|
|
203
|
+
running: acc.event.running,
|
|
189
204
|
});
|
|
190
205
|
break;
|
|
191
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
192
|
-
// TODO-AGENTS: emit ActionExecutionResult when needed
|
|
193
|
-
// Need a special tool node for that?
|
|
194
|
-
|
|
195
|
-
// const result = eventWithState.event.data?.output?.kwargs?.content?.[0];
|
|
196
|
-
// const toolCallId = eventWithState.event.data?.output?.kwargs?.tool_call_id;
|
|
197
|
-
// const toolCallName = eventWithState.event.data?.output?.kwargs?.name;
|
|
198
|
-
// if (result && toolCallId && toolCallName) {
|
|
199
|
-
// events.push({
|
|
200
|
-
// type: RuntimeEventTypes.ActionExecutionResult,
|
|
201
|
-
// actionExecutionId: toolCallId,
|
|
202
|
-
// actionName: toolCallName,
|
|
203
|
-
// result,
|
|
204
|
-
// });
|
|
205
|
-
// }
|
|
206
|
-
break;
|
|
207
206
|
case LangGraphEventTypes.OnChatModelStream:
|
|
208
207
|
if (
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
acc.isToolCallStart &&
|
|
209
|
+
this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
|
|
211
210
|
) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
}
|
|
211
|
+
events.push({
|
|
212
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
213
|
+
actionExecutionId: acc.lastToolCallId,
|
|
214
|
+
actionName: acc.lastToolCallName,
|
|
215
|
+
parentMessageId: acc.lastMessageId,
|
|
216
|
+
});
|
|
220
217
|
}
|
|
221
218
|
// Message started: emit TextMessageStart
|
|
222
|
-
else if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
events.push({
|
|
228
|
-
type: RuntimeEventTypes.TextMessageStart,
|
|
229
|
-
messageId: eventWithState.messageId,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
219
|
+
else if (acc.isMessageStart && shouldEmitMessages) {
|
|
220
|
+
events.push({
|
|
221
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
222
|
+
messageId: acc.lastMessageId,
|
|
223
|
+
});
|
|
232
224
|
}
|
|
233
225
|
|
|
234
|
-
const args =
|
|
235
|
-
eventWithState.event.data?.chunk?.kwargs?.tool_call_chunks?.[0]?.args ??
|
|
236
|
-
// @ts-expect-error -- sdf
|
|
237
|
-
eventWithState.event.data?.chunk?.tool_call_chunks?.[0]?.args;
|
|
238
|
-
const content = eventWithState.content;
|
|
239
|
-
|
|
240
226
|
// Tool call args: emit ActionExecutionArgs
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
if (
|
|
228
|
+
acc.isToolCall &&
|
|
229
|
+
acc.currentContent &&
|
|
230
|
+
this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
|
|
231
|
+
) {
|
|
232
|
+
events.push({
|
|
233
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
234
|
+
actionExecutionId: acc.lastToolCallId,
|
|
235
|
+
args: acc.currentContent,
|
|
236
|
+
});
|
|
248
237
|
}
|
|
249
238
|
// Message content: emit TextMessageContent
|
|
250
|
-
else if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
239
|
+
else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
240
|
+
events.push({
|
|
241
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
242
|
+
messageId: acc.lastMessageId,
|
|
243
|
+
content: acc.currentContent,
|
|
244
|
+
});
|
|
257
245
|
}
|
|
258
246
|
break;
|
|
259
247
|
}
|
|
@@ -263,14 +251,16 @@ export class RemoteLangGraphEventSource {
|
|
|
263
251
|
console.error(error);
|
|
264
252
|
const events: RuntimeEvent[] = [];
|
|
265
253
|
|
|
266
|
-
if (lastEventWithState?.
|
|
254
|
+
if (lastEventWithState?.lastMessageId && !lastEventWithState.isToolCall) {
|
|
267
255
|
events.push({
|
|
268
256
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
257
|
+
messageId: lastEventWithState.lastMessageId,
|
|
269
258
|
});
|
|
270
259
|
}
|
|
271
|
-
if (lastEventWithState?.
|
|
260
|
+
if (lastEventWithState?.lastToolCallId) {
|
|
272
261
|
events.push({
|
|
273
262
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
263
|
+
actionExecutionId: lastEventWithState.lastToolCallId,
|
|
274
264
|
});
|
|
275
265
|
}
|
|
276
266
|
|
|
@@ -282,10 +272,12 @@ export class RemoteLangGraphEventSource {
|
|
|
282
272
|
});
|
|
283
273
|
events.push({
|
|
284
274
|
type: RuntimeEventTypes.TextMessageContent,
|
|
275
|
+
messageId: messageId,
|
|
285
276
|
content: "❌ An error occurred. Please try again.",
|
|
286
277
|
});
|
|
287
278
|
events.push({
|
|
288
279
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
280
|
+
messageId: messageId,
|
|
289
281
|
});
|
|
290
282
|
|
|
291
283
|
return events;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field, InputType } from "type-graphql";
|
|
2
|
-
import { MessageRole
|
|
2
|
+
import { MessageRole } from "../types/enums";
|
|
3
3
|
import { BaseMessageInput } from "../types/base";
|
|
4
4
|
|
|
5
5
|
// GraphQL does not support union types in inputs, so we need to use
|
|
@@ -24,6 +24,9 @@ export class TextMessageInput {
|
|
|
24
24
|
@Field(() => String)
|
|
25
25
|
content: string;
|
|
26
26
|
|
|
27
|
+
@Field(() => String, { nullable: true })
|
|
28
|
+
parentMessageId?: string;
|
|
29
|
+
|
|
27
30
|
@Field(() => MessageRole)
|
|
28
31
|
role: MessageRole;
|
|
29
32
|
}
|
|
@@ -36,8 +39,14 @@ export class ActionExecutionMessageInput {
|
|
|
36
39
|
@Field(() => String)
|
|
37
40
|
arguments: string;
|
|
38
41
|
|
|
39
|
-
@Field(() =>
|
|
40
|
-
|
|
42
|
+
@Field(() => String, { nullable: true })
|
|
43
|
+
parentMessageId?: string;
|
|
44
|
+
|
|
45
|
+
@Field(() => String, {
|
|
46
|
+
nullable: true,
|
|
47
|
+
deprecationReason: "This field will be removed in a future version",
|
|
48
|
+
})
|
|
49
|
+
scope?: String;
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
@InputType()
|
|
@@ -48,6 +57,9 @@ export class ResultMessageInput {
|
|
|
48
57
|
@Field(() => String)
|
|
49
58
|
actionName: string;
|
|
50
59
|
|
|
60
|
+
@Field(() => String, { nullable: true })
|
|
61
|
+
parentMessageId?: string;
|
|
62
|
+
|
|
51
63
|
@Field(() => String)
|
|
52
64
|
result: string;
|
|
53
65
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ReplaySubject,
|
|
4
4
|
Subject,
|
|
5
5
|
Subscription,
|
|
6
|
+
filter,
|
|
6
7
|
finalize,
|
|
7
8
|
firstValueFrom,
|
|
8
9
|
shareReplay,
|
|
@@ -288,7 +289,19 @@ export class CopilotResolver {
|
|
|
288
289
|
// skip until this message start event
|
|
289
290
|
skipWhile((e) => e !== event),
|
|
290
291
|
// take until the message end event
|
|
291
|
-
takeWhile(
|
|
292
|
+
takeWhile(
|
|
293
|
+
(e) =>
|
|
294
|
+
!(
|
|
295
|
+
e.type === RuntimeEventTypes.TextMessageEnd &&
|
|
296
|
+
e.messageId == event.messageId
|
|
297
|
+
),
|
|
298
|
+
),
|
|
299
|
+
// filter out any other message events or message ids
|
|
300
|
+
filter(
|
|
301
|
+
(e) =>
|
|
302
|
+
e.type == RuntimeEventTypes.TextMessageContent &&
|
|
303
|
+
e.messageId == event.messageId,
|
|
304
|
+
),
|
|
292
305
|
);
|
|
293
306
|
|
|
294
307
|
// signal when we are done streaming
|
|
@@ -298,6 +311,7 @@ export class CopilotResolver {
|
|
|
298
311
|
// push the new message
|
|
299
312
|
pushMessage({
|
|
300
313
|
id: messageId,
|
|
314
|
+
parentMessageId: event.parentMessageId,
|
|
301
315
|
status: firstValueFrom(streamingTextStatus),
|
|
302
316
|
createdAt: new Date(),
|
|
303
317
|
role: MessageRole.assistant,
|
|
@@ -369,15 +383,28 @@ export class CopilotResolver {
|
|
|
369
383
|
logger.debug("Action execution start event received");
|
|
370
384
|
const actionExecutionArgumentStream = eventStream.pipe(
|
|
371
385
|
skipWhile((e) => e !== event),
|
|
372
|
-
|
|
386
|
+
// take until the action execution end event
|
|
387
|
+
takeWhile(
|
|
388
|
+
(e) =>
|
|
389
|
+
!(
|
|
390
|
+
e.type === RuntimeEventTypes.ActionExecutionEnd &&
|
|
391
|
+
e.actionExecutionId == event.actionExecutionId
|
|
392
|
+
),
|
|
393
|
+
),
|
|
394
|
+
// filter out any other action execution events or action execution ids
|
|
395
|
+
filter(
|
|
396
|
+
(e) =>
|
|
397
|
+
e.type == RuntimeEventTypes.ActionExecutionArgs &&
|
|
398
|
+
e.actionExecutionId == event.actionExecutionId,
|
|
399
|
+
),
|
|
373
400
|
);
|
|
374
401
|
const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
|
|
375
402
|
pushMessage({
|
|
376
403
|
id: event.actionExecutionId,
|
|
404
|
+
parentMessageId: event.parentMessageId,
|
|
377
405
|
status: firstValueFrom(streamingArgumentsStatus),
|
|
378
406
|
createdAt: new Date(),
|
|
379
407
|
name: event.actionName,
|
|
380
|
-
scope: event.scope!,
|
|
381
408
|
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
382
409
|
logger.debug("Action execution argument stream created");
|
|
383
410
|
|
|
@@ -413,7 +440,6 @@ export class CopilotResolver {
|
|
|
413
440
|
id: event.actionExecutionId,
|
|
414
441
|
createdAt: new Date(),
|
|
415
442
|
name: event.actionName,
|
|
416
|
-
scope: event.scope!,
|
|
417
443
|
arguments: argumentChunks.join(""),
|
|
418
444
|
}),
|
|
419
445
|
);
|
|
@@ -428,7 +454,7 @@ export class CopilotResolver {
|
|
|
428
454
|
case RuntimeEventTypes.ActionExecutionResult:
|
|
429
455
|
logger.debug({ result: event.result }, "Action execution result event received");
|
|
430
456
|
pushMessage({
|
|
431
|
-
id:
|
|
457
|
+
id: "result-" + event.actionExecutionId,
|
|
432
458
|
status: new SuccessMessageStatus(),
|
|
433
459
|
createdAt: new Date(),
|
|
434
460
|
actionExecutionId: event.actionExecutionId,
|
|
@@ -438,7 +464,7 @@ export class CopilotResolver {
|
|
|
438
464
|
|
|
439
465
|
outputMessages.push(
|
|
440
466
|
plainToInstance(ResultMessage, {
|
|
441
|
-
id:
|
|
467
|
+
id: "result-" + event.actionExecutionId,
|
|
442
468
|
createdAt: new Date(),
|
|
443
469
|
actionExecutionId: event.actionExecutionId,
|
|
444
470
|
actionName: event.actionName,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
AgentStateMessageInput,
|
|
6
6
|
} from "../../inputs/message.input";
|
|
7
7
|
import { BaseMessageInput } from "../base";
|
|
8
|
-
import {
|
|
8
|
+
import { MessageRole } from "../enums";
|
|
9
9
|
|
|
10
10
|
export type MessageType =
|
|
11
11
|
| "TextMessage"
|
|
@@ -37,16 +37,17 @@ export class TextMessage extends Message implements TextMessageInput {
|
|
|
37
37
|
type: MessageType = "TextMessage";
|
|
38
38
|
content: string;
|
|
39
39
|
role: MessageRole;
|
|
40
|
+
parentMessageId?: string;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export class ActionExecutionMessage
|
|
43
44
|
extends Message
|
|
44
|
-
implements Omit<ActionExecutionMessageInput, "arguments">
|
|
45
|
+
implements Omit<ActionExecutionMessageInput, "arguments" | "scope">
|
|
45
46
|
{
|
|
46
47
|
type: MessageType = "ActionExecutionMessage";
|
|
47
48
|
name: string;
|
|
48
49
|
arguments: Record<string, any>;
|
|
49
|
-
|
|
50
|
+
parentMessageId?: string;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export class ResultMessage extends Message implements ResultMessageInput {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field, InterfaceType, ObjectType } from "type-graphql";
|
|
2
|
-
import { MessageRole
|
|
2
|
+
import { MessageRole } from "./enums";
|
|
3
3
|
import { MessageStatusUnion } from "./message-status.type";
|
|
4
4
|
import { ResponseStatusUnion } from "./response-status.type";
|
|
5
5
|
|
|
@@ -35,6 +35,9 @@ export class TextMessageOutput {
|
|
|
35
35
|
|
|
36
36
|
@Field(() => [String])
|
|
37
37
|
content: string[];
|
|
38
|
+
|
|
39
|
+
@Field(() => String, { nullable: true })
|
|
40
|
+
parentMessageId?: string;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
@ObjectType({ implements: BaseMessageOutput })
|
|
@@ -42,11 +45,17 @@ export class ActionExecutionMessageOutput {
|
|
|
42
45
|
@Field(() => String)
|
|
43
46
|
name: string;
|
|
44
47
|
|
|
45
|
-
@Field(() =>
|
|
46
|
-
|
|
48
|
+
@Field(() => String, {
|
|
49
|
+
nullable: true,
|
|
50
|
+
deprecationReason: "This field will be removed in a future version",
|
|
51
|
+
})
|
|
52
|
+
scope?: string;
|
|
47
53
|
|
|
48
54
|
@Field(() => [String])
|
|
49
55
|
arguments: string[];
|
|
56
|
+
|
|
57
|
+
@Field(() => String, { nullable: true })
|
|
58
|
+
parentMessageId?: string;
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
@ObjectType({ implements: BaseMessageOutput })
|
|
@@ -7,12 +7,6 @@ export enum MessageRole {
|
|
|
7
7
|
tool = "tool",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export enum ActionExecutionScope {
|
|
11
|
-
server = "server",
|
|
12
|
-
client = "client",
|
|
13
|
-
passThrough = "passThrough",
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
export enum CopilotRequestType {
|
|
17
11
|
Chat = "Chat",
|
|
18
12
|
Task = "Task",
|
|
@@ -32,11 +26,6 @@ registerEnumType(MessageRole, {
|
|
|
32
26
|
description: "The role of the message",
|
|
33
27
|
});
|
|
34
28
|
|
|
35
|
-
registerEnumType(ActionExecutionScope, {
|
|
36
|
-
name: "ActionExecutionScope",
|
|
37
|
-
description: "The scope of the action",
|
|
38
|
-
});
|
|
39
|
-
|
|
40
29
|
registerEnumType(CopilotRequestType, {
|
|
41
30
|
name: "CopilotRequestType",
|
|
42
31
|
description: "The type of Copilot request",
|
package/src/lib/logger.ts
CHANGED
|
@@ -12,6 +12,10 @@ export function createLogger(options?: { level?: LogLevel; component?: string })
|
|
|
12
12
|
const logger = createPinoLogger(
|
|
13
13
|
{
|
|
14
14
|
level: process.env.LOG_LEVEL || level || "error",
|
|
15
|
+
redact: {
|
|
16
|
+
paths: ["pid", "hostname"],
|
|
17
|
+
remove: true,
|
|
18
|
+
},
|
|
15
19
|
},
|
|
16
20
|
stream,
|
|
17
21
|
);
|