@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
|
@@ -108,9 +108,6 @@ export class GroqAdapter implements CopilotServiceAdapter {
|
|
|
108
108
|
|
|
109
109
|
eventSource.stream(async (eventStream$) => {
|
|
110
110
|
let mode: "function" | "message" | null = null;
|
|
111
|
-
let currentMessageId: string;
|
|
112
|
-
let currentToolCallId: string;
|
|
113
|
-
|
|
114
111
|
for await (const chunk of stream) {
|
|
115
112
|
const toolCall = chunk.choices[0].delta.tool_calls?.[0];
|
|
116
113
|
const content = chunk.choices[0].delta.content;
|
|
@@ -120,47 +117,36 @@ export class GroqAdapter implements CopilotServiceAdapter {
|
|
|
120
117
|
// If toolCall?.id is defined, it means a new tool call starts.
|
|
121
118
|
if (mode === "message" && toolCall?.id) {
|
|
122
119
|
mode = null;
|
|
123
|
-
eventStream$.sendTextMessageEnd(
|
|
120
|
+
eventStream$.sendTextMessageEnd();
|
|
124
121
|
} else if (mode === "function" && (toolCall === undefined || toolCall?.id)) {
|
|
125
122
|
mode = null;
|
|
126
|
-
eventStream$.sendActionExecutionEnd(
|
|
123
|
+
eventStream$.sendActionExecutionEnd();
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
// If we send a new message type, send the appropriate start event.
|
|
130
127
|
if (mode === null) {
|
|
131
128
|
if (toolCall?.id) {
|
|
132
129
|
mode = "function";
|
|
133
|
-
|
|
134
|
-
eventStream$.sendActionExecutionStart({
|
|
135
|
-
actionExecutionId: currentToolCallId,
|
|
136
|
-
actionName: toolCall!.function!.name,
|
|
137
|
-
});
|
|
130
|
+
eventStream$.sendActionExecutionStart(toolCall!.id, toolCall!.function!.name);
|
|
138
131
|
} else if (content) {
|
|
139
132
|
mode = "message";
|
|
140
|
-
|
|
141
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
133
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
142
134
|
}
|
|
143
135
|
}
|
|
144
136
|
|
|
145
137
|
// send the content events
|
|
146
138
|
if (mode === "message" && content) {
|
|
147
|
-
eventStream$.sendTextMessageContent(
|
|
148
|
-
messageId: currentMessageId,
|
|
149
|
-
content,
|
|
150
|
-
});
|
|
139
|
+
eventStream$.sendTextMessageContent(content);
|
|
151
140
|
} else if (mode === "function" && toolCall?.function?.arguments) {
|
|
152
|
-
eventStream$.sendActionExecutionArgs(
|
|
153
|
-
actionExecutionId: currentToolCallId,
|
|
154
|
-
args: toolCall.function.arguments,
|
|
155
|
-
});
|
|
141
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
156
142
|
}
|
|
157
143
|
}
|
|
158
144
|
|
|
159
145
|
// send the end events
|
|
160
146
|
if (mode === "message") {
|
|
161
|
-
eventStream$.sendTextMessageEnd(
|
|
147
|
+
eventStream$.sendTextMessageEnd();
|
|
162
148
|
} else if (mode === "function") {
|
|
163
|
-
eventStream$.sendActionExecutionEnd(
|
|
149
|
+
eventStream$.sendActionExecutionEnd();
|
|
164
150
|
}
|
|
165
151
|
|
|
166
152
|
eventStream$.complete();
|
|
@@ -129,11 +129,11 @@ function maybeSendActionExecutionResultIsMessage(
|
|
|
129
129
|
// language models need a result after the function call
|
|
130
130
|
// we simply let them know that we are sending a message
|
|
131
131
|
if (actionExecution) {
|
|
132
|
-
eventStream$.sendActionExecutionResult(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
eventStream$.sendActionExecutionResult(
|
|
133
|
+
actionExecution.id,
|
|
134
|
+
actionExecution.name,
|
|
135
|
+
"Sending a message",
|
|
136
|
+
);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -152,11 +152,7 @@ export async function streamLangChainResponse({
|
|
|
152
152
|
eventStream$.sendTextMessage(randomId(), result);
|
|
153
153
|
} else {
|
|
154
154
|
// Send as a result
|
|
155
|
-
eventStream$.sendActionExecutionResult(
|
|
156
|
-
actionExecutionId: actionExecution.id,
|
|
157
|
-
actionName: actionExecution.name,
|
|
158
|
-
result: result,
|
|
159
|
-
});
|
|
155
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
160
156
|
}
|
|
161
157
|
}
|
|
162
158
|
|
|
@@ -169,11 +165,11 @@ export async function streamLangChainResponse({
|
|
|
169
165
|
eventStream$.sendTextMessage(randomId(), result.content as string);
|
|
170
166
|
}
|
|
171
167
|
for (const toolCall of result.tool_calls) {
|
|
172
|
-
eventStream$.sendActionExecution(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
168
|
+
eventStream$.sendActionExecution(
|
|
169
|
+
toolCall.id || randomId(),
|
|
170
|
+
toolCall.name,
|
|
171
|
+
JSON.stringify(toolCall.args),
|
|
172
|
+
);
|
|
177
173
|
}
|
|
178
174
|
}
|
|
179
175
|
|
|
@@ -187,11 +183,11 @@ export async function streamLangChainResponse({
|
|
|
187
183
|
}
|
|
188
184
|
if (result.lc_kwargs?.tool_calls) {
|
|
189
185
|
for (const toolCall of result.lc_kwargs?.tool_calls) {
|
|
190
|
-
eventStream$.sendActionExecution(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
eventStream$.sendActionExecution(
|
|
187
|
+
toolCall.id || randomId(),
|
|
188
|
+
toolCall.name,
|
|
189
|
+
JSON.stringify(toolCall.args),
|
|
190
|
+
);
|
|
195
191
|
}
|
|
196
192
|
}
|
|
197
193
|
}
|
|
@@ -218,7 +214,6 @@ export async function streamLangChainResponse({
|
|
|
218
214
|
|
|
219
215
|
let toolCallName: string | undefined = undefined;
|
|
220
216
|
let toolCallId: string | undefined = undefined;
|
|
221
|
-
let currentMessageId: string;
|
|
222
217
|
let toolCallArgs: string | undefined = undefined;
|
|
223
218
|
let hasToolCall: boolean = false;
|
|
224
219
|
let content = value?.content as string;
|
|
@@ -253,10 +248,10 @@ export async function streamLangChainResponse({
|
|
|
253
248
|
// If toolCallName is defined, it means a new tool call starts.
|
|
254
249
|
if (mode === "message" && (toolCallId || done)) {
|
|
255
250
|
mode = null;
|
|
256
|
-
eventStream$.sendTextMessageEnd(
|
|
251
|
+
eventStream$.sendTextMessageEnd();
|
|
257
252
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
258
253
|
mode = null;
|
|
259
|
-
eventStream$.sendActionExecutionEnd(
|
|
254
|
+
eventStream$.sendActionExecutionEnd();
|
|
260
255
|
}
|
|
261
256
|
|
|
262
257
|
if (done) {
|
|
@@ -267,37 +262,26 @@ export async function streamLangChainResponse({
|
|
|
267
262
|
if (mode === null) {
|
|
268
263
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
269
264
|
mode = "function";
|
|
270
|
-
eventStream$.sendActionExecutionStart(
|
|
271
|
-
actionExecutionId: toolCallId,
|
|
272
|
-
actionName: toolCallName,
|
|
273
|
-
});
|
|
265
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
274
266
|
} else if (content) {
|
|
275
267
|
mode = "message";
|
|
276
|
-
|
|
277
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
268
|
+
eventStream$.sendTextMessageStart(randomId());
|
|
278
269
|
}
|
|
279
270
|
}
|
|
280
271
|
|
|
281
272
|
// send the content events
|
|
282
273
|
if (mode === "message" && content) {
|
|
283
|
-
eventStream$.sendTextMessageContent(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
274
|
+
eventStream$.sendTextMessageContent(
|
|
275
|
+
Array.isArray(content) ? (content[0]?.text ?? "") : content,
|
|
276
|
+
);
|
|
287
277
|
} else if (mode === "function" && toolCallArgs) {
|
|
288
278
|
// For calls of the same tool with different index, we seal last tool call and register a new one
|
|
289
279
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
290
|
-
eventStream$.sendActionExecutionEnd(
|
|
291
|
-
eventStream$.sendActionExecutionStart(
|
|
292
|
-
actionExecutionId: toolCallId,
|
|
293
|
-
actionName: toolCallName,
|
|
294
|
-
});
|
|
280
|
+
eventStream$.sendActionExecutionEnd();
|
|
281
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
295
282
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
296
283
|
}
|
|
297
|
-
eventStream$.sendActionExecutionArgs(
|
|
298
|
-
actionExecutionId: toolCallId,
|
|
299
|
-
args: toolCallArgs,
|
|
300
|
-
});
|
|
284
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
301
285
|
}
|
|
302
286
|
} catch (error) {
|
|
303
287
|
console.error("Error reading from stream", error);
|
|
@@ -305,11 +289,11 @@ export async function streamLangChainResponse({
|
|
|
305
289
|
}
|
|
306
290
|
}
|
|
307
291
|
} else if (actionExecution) {
|
|
308
|
-
eventStream$.sendActionExecutionResult(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
292
|
+
eventStream$.sendActionExecutionResult(
|
|
293
|
+
actionExecution.id,
|
|
294
|
+
actionExecution.name,
|
|
295
|
+
encodeResult(result),
|
|
296
|
+
);
|
|
313
297
|
}
|
|
314
298
|
|
|
315
299
|
// unsupported type
|
|
@@ -144,8 +144,7 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
144
144
|
|
|
145
145
|
eventSource.stream(async (eventStream$) => {
|
|
146
146
|
let mode: "function" | "message" | null = null;
|
|
147
|
-
|
|
148
|
-
let currentToolCallId: string;
|
|
147
|
+
|
|
149
148
|
for await (const chunk of stream) {
|
|
150
149
|
if (chunk.choices.length === 0) {
|
|
151
150
|
continue;
|
|
@@ -159,47 +158,36 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
159
158
|
// If toolCall?.id is defined, it means a new tool call starts.
|
|
160
159
|
if (mode === "message" && toolCall?.id) {
|
|
161
160
|
mode = null;
|
|
162
|
-
eventStream$.sendTextMessageEnd(
|
|
161
|
+
eventStream$.sendTextMessageEnd();
|
|
163
162
|
} else if (mode === "function" && (toolCall === undefined || toolCall?.id)) {
|
|
164
163
|
mode = null;
|
|
165
|
-
eventStream$.sendActionExecutionEnd(
|
|
164
|
+
eventStream$.sendActionExecutionEnd();
|
|
166
165
|
}
|
|
167
166
|
|
|
168
167
|
// If we send a new message type, send the appropriate start event.
|
|
169
168
|
if (mode === null) {
|
|
170
169
|
if (toolCall?.id) {
|
|
171
170
|
mode = "function";
|
|
172
|
-
|
|
173
|
-
eventStream$.sendActionExecutionStart({
|
|
174
|
-
actionExecutionId: currentToolCallId,
|
|
175
|
-
actionName: toolCall!.function!.name,
|
|
176
|
-
});
|
|
171
|
+
eventStream$.sendActionExecutionStart(toolCall!.id, toolCall!.function!.name);
|
|
177
172
|
} else if (content) {
|
|
178
173
|
mode = "message";
|
|
179
|
-
|
|
180
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
174
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
181
175
|
}
|
|
182
176
|
}
|
|
183
177
|
|
|
184
178
|
// send the content events
|
|
185
179
|
if (mode === "message" && content) {
|
|
186
|
-
eventStream$.sendTextMessageContent(
|
|
187
|
-
messageId: currentMessageId,
|
|
188
|
-
content: content,
|
|
189
|
-
});
|
|
180
|
+
eventStream$.sendTextMessageContent(content);
|
|
190
181
|
} else if (mode === "function" && toolCall?.function?.arguments) {
|
|
191
|
-
eventStream$.sendActionExecutionArgs(
|
|
192
|
-
actionExecutionId: currentToolCallId,
|
|
193
|
-
args: toolCall.function.arguments,
|
|
194
|
-
});
|
|
182
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
195
183
|
}
|
|
196
184
|
}
|
|
197
185
|
|
|
198
186
|
// send the end events
|
|
199
187
|
if (mode === "message") {
|
|
200
|
-
eventStream$.sendTextMessageEnd(
|
|
188
|
+
eventStream$.sendTextMessageEnd();
|
|
201
189
|
} else if (mode === "function") {
|
|
202
|
-
eventStream$.sendActionExecutionEnd(
|
|
190
|
+
eventStream$.sendActionExecutionEnd();
|
|
203
191
|
}
|
|
204
192
|
|
|
205
193
|
eventStream$.complete();
|
|
@@ -228,28 +228,22 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
228
228
|
private async streamResponse(stream: AssistantStream, eventSource: RuntimeEventSource) {
|
|
229
229
|
eventSource.stream(async (eventStream$) => {
|
|
230
230
|
let inFunctionCall = false;
|
|
231
|
-
let currentMessageId: string;
|
|
232
|
-
let currentToolCallId: string;
|
|
233
231
|
|
|
234
232
|
for await (const chunk of stream) {
|
|
235
233
|
switch (chunk.event) {
|
|
236
234
|
case "thread.message.created":
|
|
237
235
|
if (inFunctionCall) {
|
|
238
|
-
eventStream$.sendActionExecutionEnd(
|
|
236
|
+
eventStream$.sendActionExecutionEnd();
|
|
239
237
|
}
|
|
240
|
-
|
|
241
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
238
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
242
239
|
break;
|
|
243
240
|
case "thread.message.delta":
|
|
244
241
|
if (chunk.data.delta.content?.[0].type === "text") {
|
|
245
|
-
eventStream$.sendTextMessageContent(
|
|
246
|
-
messageId: currentMessageId,
|
|
247
|
-
content: chunk.data.delta.content?.[0].text.value,
|
|
248
|
-
});
|
|
242
|
+
eventStream$.sendTextMessageContent(chunk.data.delta.content?.[0].text.value);
|
|
249
243
|
}
|
|
250
244
|
break;
|
|
251
245
|
case "thread.message.completed":
|
|
252
|
-
eventStream$.sendTextMessageEnd(
|
|
246
|
+
eventStream$.sendTextMessageEnd();
|
|
253
247
|
break;
|
|
254
248
|
case "thread.run.step.delta":
|
|
255
249
|
let toolCallId: string | undefined;
|
|
@@ -266,25 +260,18 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
266
260
|
|
|
267
261
|
if (toolCallName && toolCallId) {
|
|
268
262
|
if (inFunctionCall) {
|
|
269
|
-
eventStream$.sendActionExecutionEnd(
|
|
263
|
+
eventStream$.sendActionExecutionEnd();
|
|
270
264
|
}
|
|
271
265
|
inFunctionCall = true;
|
|
272
|
-
|
|
273
|
-
eventStream$.sendActionExecutionStart({
|
|
274
|
-
actionExecutionId: currentToolCallId,
|
|
275
|
-
actionName: toolCallName,
|
|
276
|
-
});
|
|
266
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
277
267
|
} else if (toolCallArgs) {
|
|
278
|
-
eventStream$.sendActionExecutionArgs(
|
|
279
|
-
actionExecutionId: currentToolCallId,
|
|
280
|
-
args: toolCallArgs,
|
|
281
|
-
});
|
|
268
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
282
269
|
}
|
|
283
270
|
break;
|
|
284
271
|
}
|
|
285
272
|
}
|
|
286
273
|
if (inFunctionCall) {
|
|
287
|
-
eventStream$.sendActionExecutionEnd(
|
|
274
|
+
eventStream$.sendActionExecutionEnd();
|
|
288
275
|
}
|
|
289
276
|
eventStream$.complete();
|
|
290
277
|
});
|
|
@@ -66,20 +66,14 @@ export class UnifyAdapter implements CopilotServiceAdapter {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
let model = null;
|
|
69
|
-
let currentMessageId: string;
|
|
70
|
-
let currentToolCallId: string;
|
|
71
69
|
request.eventSource.stream(async (eventStream$) => {
|
|
72
70
|
let mode: "function" | "message" | null = null;
|
|
73
71
|
for await (const chunk of stream) {
|
|
74
72
|
if (this.start) {
|
|
75
73
|
model = chunk.model;
|
|
76
|
-
|
|
77
|
-
eventStream$.
|
|
78
|
-
eventStream$.
|
|
79
|
-
messageId: currentMessageId,
|
|
80
|
-
content: `Model used: ${model}\n`,
|
|
81
|
-
});
|
|
82
|
-
eventStream$.sendTextMessageEnd({ messageId: currentMessageId });
|
|
74
|
+
eventStream$.sendTextMessageStart(randomId());
|
|
75
|
+
eventStream$.sendTextMessageContent(`Model used: ${model}\n`);
|
|
76
|
+
eventStream$.sendTextMessageEnd();
|
|
83
77
|
this.start = false;
|
|
84
78
|
}
|
|
85
79
|
const toolCall = chunk.choices[0].delta.tool_calls?.[0];
|
|
@@ -90,47 +84,36 @@ export class UnifyAdapter implements CopilotServiceAdapter {
|
|
|
90
84
|
// If toolCall?.id is defined, it means a new tool call starts.
|
|
91
85
|
if (mode === "message" && toolCall?.id) {
|
|
92
86
|
mode = null;
|
|
93
|
-
eventStream$.sendTextMessageEnd(
|
|
87
|
+
eventStream$.sendTextMessageEnd();
|
|
94
88
|
} else if (mode === "function" && (toolCall === undefined || toolCall?.id)) {
|
|
95
89
|
mode = null;
|
|
96
|
-
eventStream$.sendActionExecutionEnd(
|
|
90
|
+
eventStream$.sendActionExecutionEnd();
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
// If we send a new message type, send the appropriate start event.
|
|
100
94
|
if (mode === null) {
|
|
101
95
|
if (toolCall?.id) {
|
|
102
96
|
mode = "function";
|
|
103
|
-
|
|
104
|
-
eventStream$.sendActionExecutionStart({
|
|
105
|
-
actionExecutionId: currentToolCallId,
|
|
106
|
-
actionName: toolCall!.function!.name,
|
|
107
|
-
});
|
|
97
|
+
eventStream$.sendActionExecutionStart(toolCall!.id, toolCall!.function!.name);
|
|
108
98
|
} else if (content) {
|
|
109
99
|
mode = "message";
|
|
110
|
-
|
|
111
|
-
eventStream$.sendTextMessageStart({ messageId: currentMessageId });
|
|
100
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
112
101
|
}
|
|
113
102
|
}
|
|
114
103
|
|
|
115
104
|
// send the content events
|
|
116
105
|
if (mode === "message" && content) {
|
|
117
|
-
eventStream$.sendTextMessageContent(
|
|
118
|
-
messageId: currentMessageId,
|
|
119
|
-
content: content,
|
|
120
|
-
});
|
|
106
|
+
eventStream$.sendTextMessageContent(content);
|
|
121
107
|
} else if (mode === "function" && toolCall?.function?.arguments) {
|
|
122
|
-
eventStream$.sendActionExecutionArgs(
|
|
123
|
-
actionExecutionId: currentToolCallId,
|
|
124
|
-
args: toolCall.function.arguments,
|
|
125
|
-
});
|
|
108
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
126
109
|
}
|
|
127
110
|
}
|
|
128
111
|
|
|
129
112
|
// send the end events
|
|
130
113
|
if (mode === "message") {
|
|
131
|
-
eventStream$.sendTextMessageEnd(
|
|
114
|
+
eventStream$.sendTextMessageEnd();
|
|
132
115
|
} else if (mode === "function") {
|
|
133
|
-
eventStream$.sendActionExecutionEnd(
|
|
116
|
+
eventStream$.sendActionExecutionEnd();
|
|
134
117
|
}
|
|
135
118
|
|
|
136
119
|
eventStream$.complete();
|