@copilotkit/runtime 1.4.8 → 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 +13 -0
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-W7GP2EOT.mjs → chunk-4AYRDPWK.mjs} +239 -65
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-LSLFIYKP.mjs → chunk-7BOO3OFP.mjs} +2 -2
- package/dist/{chunk-GGNRDS7N.mjs → chunk-GSTWFOZF.mjs} +2 -2
- package/dist/{chunk-TA5I5LYF.mjs → chunk-OMAAKIJQ.mjs} +2 -2
- package/dist/{chunk-R6AUAQK6.mjs → chunk-PXS4SBRF.mjs} +423 -299
- 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-48d7c2fc.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-ac43305a.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 +4 -4
- package/dist/index.js +747 -448
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/{langserve-b74e8606.d.ts → langserve-f318db89.d.ts} +51 -12
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +714 -439
- 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 +71 -30
- 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 +71 -30
- 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 +71 -30
- 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 +71 -30
- 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 +4 -4
- package/dist/service-adapters/index.js +238 -64
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -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/runtime/remote-action-constructors.ts +4 -2
- 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 +116 -52
- 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/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-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-R6AUAQK6.mjs.map +0 -1
- package/dist/chunk-W7GP2EOT.mjs.map +0 -1
- /package/dist/{chunk-LSLFIYKP.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
- /package/dist/{chunk-GGNRDS7N.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
- /package/dist/{chunk-TA5I5LYF.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-
|
|
2
|
-
export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-
|
|
3
|
-
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-
|
|
1
|
+
import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-f318db89.js';
|
|
2
|
+
export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-f318db89.js';
|
|
3
|
+
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-7bf6824b.js';
|
|
4
4
|
import Anthropic from '@anthropic-ai/sdk';
|
|
5
|
-
import '../index-
|
|
5
|
+
import '../index-ff3fbc33.js';
|
|
6
6
|
import '../graphql/types/base/index.js';
|
|
7
7
|
import 'rxjs';
|
|
8
8
|
import '@copilotkit/shared';
|
|
@@ -317,6 +317,8 @@ var OpenAIAdapter = class {
|
|
|
317
317
|
eventSource.stream(async (eventStream$) => {
|
|
318
318
|
var _a, _b;
|
|
319
319
|
let mode = null;
|
|
320
|
+
let currentMessageId;
|
|
321
|
+
let currentToolCallId;
|
|
320
322
|
for await (const chunk of stream) {
|
|
321
323
|
if (chunk.choices.length === 0) {
|
|
322
324
|
continue;
|
|
@@ -325,30 +327,52 @@ var OpenAIAdapter = class {
|
|
|
325
327
|
const content = chunk.choices[0].delta.content;
|
|
326
328
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
327
329
|
mode = null;
|
|
328
|
-
eventStream$.sendTextMessageEnd(
|
|
330
|
+
eventStream$.sendTextMessageEnd({
|
|
331
|
+
messageId: currentMessageId
|
|
332
|
+
});
|
|
329
333
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
330
334
|
mode = null;
|
|
331
|
-
eventStream$.sendActionExecutionEnd(
|
|
335
|
+
eventStream$.sendActionExecutionEnd({
|
|
336
|
+
actionExecutionId: currentToolCallId
|
|
337
|
+
});
|
|
332
338
|
}
|
|
333
339
|
if (mode === null) {
|
|
334
340
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
335
341
|
mode = "function";
|
|
336
|
-
|
|
342
|
+
currentToolCallId = toolCall.id;
|
|
343
|
+
eventStream$.sendActionExecutionStart({
|
|
344
|
+
actionExecutionId: currentToolCallId,
|
|
345
|
+
parentMessageId: chunk.id,
|
|
346
|
+
actionName: toolCall.function.name
|
|
347
|
+
});
|
|
337
348
|
} else if (content) {
|
|
338
349
|
mode = "message";
|
|
339
|
-
|
|
350
|
+
currentMessageId = chunk.id;
|
|
351
|
+
eventStream$.sendTextMessageStart({
|
|
352
|
+
messageId: currentMessageId
|
|
353
|
+
});
|
|
340
354
|
}
|
|
341
355
|
}
|
|
342
356
|
if (mode === "message" && content) {
|
|
343
|
-
eventStream$.sendTextMessageContent(
|
|
357
|
+
eventStream$.sendTextMessageContent({
|
|
358
|
+
messageId: currentMessageId,
|
|
359
|
+
content
|
|
360
|
+
});
|
|
344
361
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
345
|
-
eventStream$.sendActionExecutionArgs(
|
|
362
|
+
eventStream$.sendActionExecutionArgs({
|
|
363
|
+
actionExecutionId: currentToolCallId,
|
|
364
|
+
args: toolCall.function.arguments
|
|
365
|
+
});
|
|
346
366
|
}
|
|
347
367
|
}
|
|
348
368
|
if (mode === "message") {
|
|
349
|
-
eventStream$.sendTextMessageEnd(
|
|
369
|
+
eventStream$.sendTextMessageEnd({
|
|
370
|
+
messageId: currentMessageId
|
|
371
|
+
});
|
|
350
372
|
} else if (mode === "function") {
|
|
351
|
-
eventStream$.sendActionExecutionEnd(
|
|
373
|
+
eventStream$.sendActionExecutionEnd({
|
|
374
|
+
actionExecutionId: currentToolCallId
|
|
375
|
+
});
|
|
352
376
|
}
|
|
353
377
|
eventStream$.complete();
|
|
354
378
|
});
|
|
@@ -416,17 +440,25 @@ function isBaseMessageChunk(message) {
|
|
|
416
440
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
417
441
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
418
442
|
if (actionExecution) {
|
|
419
|
-
eventStream$.sendActionExecutionResult(
|
|
443
|
+
eventStream$.sendActionExecutionResult({
|
|
444
|
+
actionExecutionId: actionExecution.id,
|
|
445
|
+
actionName: actionExecution.name,
|
|
446
|
+
result: "Sending a message"
|
|
447
|
+
});
|
|
420
448
|
}
|
|
421
449
|
}
|
|
422
450
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
423
451
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
424
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
452
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
425
453
|
if (typeof result === "string") {
|
|
426
454
|
if (!actionExecution) {
|
|
427
455
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
428
456
|
} else {
|
|
429
|
-
eventStream$.sendActionExecutionResult(
|
|
457
|
+
eventStream$.sendActionExecutionResult({
|
|
458
|
+
actionExecutionId: actionExecution.id,
|
|
459
|
+
actionName: actionExecution.name,
|
|
460
|
+
result
|
|
461
|
+
});
|
|
430
462
|
}
|
|
431
463
|
} else if (isAIMessage(result)) {
|
|
432
464
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -434,7 +466,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
434
466
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
435
467
|
}
|
|
436
468
|
for (const toolCall of result.tool_calls) {
|
|
437
|
-
eventStream$.sendActionExecution(
|
|
469
|
+
eventStream$.sendActionExecution({
|
|
470
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
471
|
+
actionName: toolCall.name,
|
|
472
|
+
args: JSON.stringify(toolCall.args)
|
|
473
|
+
});
|
|
438
474
|
}
|
|
439
475
|
} else if (isBaseMessageChunk(result)) {
|
|
440
476
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -443,13 +479,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
443
479
|
}
|
|
444
480
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
445
481
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
446
|
-
eventStream$.sendActionExecution(
|
|
482
|
+
eventStream$.sendActionExecution({
|
|
483
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
484
|
+
actionName: toolCall.name,
|
|
485
|
+
args: JSON.stringify(toolCall.args)
|
|
486
|
+
});
|
|
447
487
|
}
|
|
448
488
|
}
|
|
449
489
|
} else if (result && "getReader" in result) {
|
|
450
490
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
451
491
|
let reader = result.getReader();
|
|
452
492
|
let mode = null;
|
|
493
|
+
let currentMessageId;
|
|
453
494
|
const toolCallDetails = {
|
|
454
495
|
name: null,
|
|
455
496
|
id: null,
|
|
@@ -463,9 +504,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
463
504
|
let toolCallId = void 0;
|
|
464
505
|
let toolCallArgs = void 0;
|
|
465
506
|
let hasToolCall = false;
|
|
466
|
-
let content =
|
|
507
|
+
let content = "";
|
|
508
|
+
if (value && value.content) {
|
|
509
|
+
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
510
|
+
}
|
|
467
511
|
if (isAIMessageChunk(value)) {
|
|
468
|
-
let chunk = (
|
|
512
|
+
let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
|
|
469
513
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
470
514
|
hasToolCall = chunk != void 0;
|
|
471
515
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -480,18 +524,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
480
524
|
toolCallName = toolCallDetails.name;
|
|
481
525
|
toolCallId = toolCallDetails.id;
|
|
482
526
|
} else if (isBaseMessageChunk(value)) {
|
|
483
|
-
let chunk = (
|
|
484
|
-
toolCallName = (
|
|
527
|
+
let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
|
|
528
|
+
toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
|
|
485
529
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
486
|
-
toolCallArgs = (
|
|
530
|
+
toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
|
|
487
531
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
488
532
|
}
|
|
489
533
|
if (mode === "message" && (toolCallId || done)) {
|
|
490
534
|
mode = null;
|
|
491
|
-
eventStream$.sendTextMessageEnd(
|
|
535
|
+
eventStream$.sendTextMessageEnd({
|
|
536
|
+
messageId: currentMessageId
|
|
537
|
+
});
|
|
492
538
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
493
539
|
mode = null;
|
|
494
|
-
eventStream$.sendActionExecutionEnd(
|
|
540
|
+
eventStream$.sendActionExecutionEnd({
|
|
541
|
+
actionExecutionId: toolCallId
|
|
542
|
+
});
|
|
495
543
|
}
|
|
496
544
|
if (done) {
|
|
497
545
|
break;
|
|
@@ -499,21 +547,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
499
547
|
if (mode === null) {
|
|
500
548
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
501
549
|
mode = "function";
|
|
502
|
-
eventStream$.sendActionExecutionStart(
|
|
550
|
+
eventStream$.sendActionExecutionStart({
|
|
551
|
+
actionExecutionId: toolCallId,
|
|
552
|
+
actionName: toolCallName,
|
|
553
|
+
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
554
|
+
});
|
|
503
555
|
} else if (content) {
|
|
504
556
|
mode = "message";
|
|
505
|
-
|
|
557
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared2.randomId)();
|
|
558
|
+
eventStream$.sendTextMessageStart({
|
|
559
|
+
messageId: currentMessageId
|
|
560
|
+
});
|
|
506
561
|
}
|
|
507
562
|
}
|
|
508
563
|
if (mode === "message" && content) {
|
|
509
|
-
eventStream$.sendTextMessageContent(
|
|
564
|
+
eventStream$.sendTextMessageContent({
|
|
565
|
+
messageId: currentMessageId,
|
|
566
|
+
content
|
|
567
|
+
});
|
|
510
568
|
} else if (mode === "function" && toolCallArgs) {
|
|
511
569
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
512
|
-
eventStream$.sendActionExecutionEnd(
|
|
513
|
-
|
|
570
|
+
eventStream$.sendActionExecutionEnd({
|
|
571
|
+
actionExecutionId: toolCallId
|
|
572
|
+
});
|
|
573
|
+
eventStream$.sendActionExecutionStart({
|
|
574
|
+
actionExecutionId: toolCallId,
|
|
575
|
+
actionName: toolCallName,
|
|
576
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
577
|
+
});
|
|
514
578
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
515
579
|
}
|
|
516
|
-
eventStream$.sendActionExecutionArgs(
|
|
580
|
+
eventStream$.sendActionExecutionArgs({
|
|
581
|
+
actionExecutionId: toolCallId,
|
|
582
|
+
args: toolCallArgs
|
|
583
|
+
});
|
|
517
584
|
}
|
|
518
585
|
} catch (error) {
|
|
519
586
|
console.error("Error reading from stream", error);
|
|
@@ -521,7 +588,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
521
588
|
}
|
|
522
589
|
}
|
|
523
590
|
} else if (actionExecution) {
|
|
524
|
-
eventStream$.sendActionExecutionResult(
|
|
591
|
+
eventStream$.sendActionExecutionResult({
|
|
592
|
+
actionExecutionId: actionExecution.id,
|
|
593
|
+
actionName: actionExecution.name,
|
|
594
|
+
result: encodeResult(result)
|
|
595
|
+
});
|
|
525
596
|
} else {
|
|
526
597
|
throw new Error("Invalid return type from LangChain function.");
|
|
527
598
|
}
|
|
@@ -701,21 +772,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
701
772
|
eventSource.stream(async (eventStream$) => {
|
|
702
773
|
var _a, _b, _c, _d, _e, _f;
|
|
703
774
|
let inFunctionCall = false;
|
|
775
|
+
let currentMessageId;
|
|
776
|
+
let currentToolCallId;
|
|
704
777
|
for await (const chunk of stream) {
|
|
705
778
|
switch (chunk.event) {
|
|
706
779
|
case "thread.message.created":
|
|
707
780
|
if (inFunctionCall) {
|
|
708
|
-
eventStream$.sendActionExecutionEnd(
|
|
781
|
+
eventStream$.sendActionExecutionEnd({
|
|
782
|
+
actionExecutionId: currentToolCallId
|
|
783
|
+
});
|
|
709
784
|
}
|
|
710
|
-
|
|
785
|
+
currentMessageId = chunk.data.id;
|
|
786
|
+
eventStream$.sendTextMessageStart({
|
|
787
|
+
messageId: currentMessageId
|
|
788
|
+
});
|
|
711
789
|
break;
|
|
712
790
|
case "thread.message.delta":
|
|
713
791
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
714
|
-
eventStream$.sendTextMessageContent(
|
|
792
|
+
eventStream$.sendTextMessageContent({
|
|
793
|
+
messageId: currentMessageId,
|
|
794
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
795
|
+
});
|
|
715
796
|
}
|
|
716
797
|
break;
|
|
717
798
|
case "thread.message.completed":
|
|
718
|
-
eventStream$.sendTextMessageEnd(
|
|
799
|
+
eventStream$.sendTextMessageEnd({
|
|
800
|
+
messageId: currentMessageId
|
|
801
|
+
});
|
|
719
802
|
break;
|
|
720
803
|
case "thread.run.step.delta":
|
|
721
804
|
let toolCallId;
|
|
@@ -728,18 +811,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
728
811
|
}
|
|
729
812
|
if (toolCallName && toolCallId) {
|
|
730
813
|
if (inFunctionCall) {
|
|
731
|
-
eventStream$.sendActionExecutionEnd(
|
|
814
|
+
eventStream$.sendActionExecutionEnd({
|
|
815
|
+
actionExecutionId: currentToolCallId
|
|
816
|
+
});
|
|
732
817
|
}
|
|
733
818
|
inFunctionCall = true;
|
|
734
|
-
|
|
819
|
+
currentToolCallId = toolCallId;
|
|
820
|
+
eventStream$.sendActionExecutionStart({
|
|
821
|
+
actionExecutionId: currentToolCallId,
|
|
822
|
+
parentMessageId: chunk.data.id,
|
|
823
|
+
actionName: toolCallName
|
|
824
|
+
});
|
|
735
825
|
} else if (toolCallArgs) {
|
|
736
|
-
eventStream$.sendActionExecutionArgs(
|
|
826
|
+
eventStream$.sendActionExecutionArgs({
|
|
827
|
+
actionExecutionId: currentToolCallId,
|
|
828
|
+
args: toolCallArgs
|
|
829
|
+
});
|
|
737
830
|
}
|
|
738
831
|
break;
|
|
739
832
|
}
|
|
740
833
|
}
|
|
741
834
|
if (inFunctionCall) {
|
|
742
|
-
eventStream$.sendActionExecutionEnd(
|
|
835
|
+
eventStream$.sendActionExecutionEnd({
|
|
836
|
+
actionExecutionId: currentToolCallId
|
|
837
|
+
});
|
|
743
838
|
}
|
|
744
839
|
eventStream$.complete();
|
|
745
840
|
});
|
|
@@ -792,46 +887,77 @@ var UnifyAdapter = class {
|
|
|
792
887
|
}
|
|
793
888
|
});
|
|
794
889
|
let model = null;
|
|
890
|
+
let currentMessageId;
|
|
891
|
+
let currentToolCallId;
|
|
795
892
|
request.eventSource.stream(async (eventStream$) => {
|
|
796
893
|
var _a, _b;
|
|
797
894
|
let mode = null;
|
|
798
895
|
for await (const chunk of stream) {
|
|
799
896
|
if (this.start) {
|
|
800
897
|
model = chunk.model;
|
|
801
|
-
|
|
802
|
-
eventStream$.
|
|
803
|
-
|
|
804
|
-
|
|
898
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
899
|
+
eventStream$.sendTextMessageStart({
|
|
900
|
+
messageId: currentMessageId
|
|
901
|
+
});
|
|
902
|
+
eventStream$.sendTextMessageContent({
|
|
903
|
+
messageId: currentMessageId,
|
|
904
|
+
content: `Model used: ${model}
|
|
905
|
+
`
|
|
906
|
+
});
|
|
907
|
+
eventStream$.sendTextMessageEnd({
|
|
908
|
+
messageId: currentMessageId
|
|
909
|
+
});
|
|
805
910
|
this.start = false;
|
|
806
911
|
}
|
|
807
912
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
808
913
|
const content = chunk.choices[0].delta.content;
|
|
809
914
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
810
915
|
mode = null;
|
|
811
|
-
eventStream$.sendTextMessageEnd(
|
|
916
|
+
eventStream$.sendTextMessageEnd({
|
|
917
|
+
messageId: currentMessageId
|
|
918
|
+
});
|
|
812
919
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
813
920
|
mode = null;
|
|
814
|
-
eventStream$.sendActionExecutionEnd(
|
|
921
|
+
eventStream$.sendActionExecutionEnd({
|
|
922
|
+
actionExecutionId: currentToolCallId
|
|
923
|
+
});
|
|
815
924
|
}
|
|
816
925
|
if (mode === null) {
|
|
817
926
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
818
927
|
mode = "function";
|
|
819
|
-
|
|
928
|
+
currentToolCallId = toolCall.id;
|
|
929
|
+
eventStream$.sendActionExecutionStart({
|
|
930
|
+
actionExecutionId: currentToolCallId,
|
|
931
|
+
actionName: toolCall.function.name
|
|
932
|
+
});
|
|
820
933
|
} else if (content) {
|
|
821
934
|
mode = "message";
|
|
822
|
-
|
|
935
|
+
currentMessageId = chunk.id;
|
|
936
|
+
eventStream$.sendTextMessageStart({
|
|
937
|
+
messageId: currentMessageId
|
|
938
|
+
});
|
|
823
939
|
}
|
|
824
940
|
}
|
|
825
941
|
if (mode === "message" && content) {
|
|
826
|
-
eventStream$.sendTextMessageContent(
|
|
942
|
+
eventStream$.sendTextMessageContent({
|
|
943
|
+
messageId: currentMessageId,
|
|
944
|
+
content
|
|
945
|
+
});
|
|
827
946
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
828
|
-
eventStream$.sendActionExecutionArgs(
|
|
947
|
+
eventStream$.sendActionExecutionArgs({
|
|
948
|
+
actionExecutionId: currentToolCallId,
|
|
949
|
+
args: toolCall.function.arguments
|
|
950
|
+
});
|
|
829
951
|
}
|
|
830
952
|
}
|
|
831
953
|
if (mode === "message") {
|
|
832
|
-
eventStream$.sendTextMessageEnd(
|
|
954
|
+
eventStream$.sendTextMessageEnd({
|
|
955
|
+
messageId: currentMessageId
|
|
956
|
+
});
|
|
833
957
|
} else if (mode === "function") {
|
|
834
|
-
eventStream$.sendActionExecutionEnd(
|
|
958
|
+
eventStream$.sendActionExecutionEnd({
|
|
959
|
+
actionExecutionId: currentToolCallId
|
|
960
|
+
});
|
|
835
961
|
}
|
|
836
962
|
eventStream$.complete();
|
|
837
963
|
});
|
|
@@ -897,35 +1023,59 @@ var GroqAdapter = class {
|
|
|
897
1023
|
eventSource.stream(async (eventStream$) => {
|
|
898
1024
|
var _a, _b;
|
|
899
1025
|
let mode = null;
|
|
1026
|
+
let currentMessageId;
|
|
1027
|
+
let currentToolCallId;
|
|
900
1028
|
for await (const chunk of stream) {
|
|
901
1029
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
902
1030
|
const content = chunk.choices[0].delta.content;
|
|
903
1031
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
904
1032
|
mode = null;
|
|
905
|
-
eventStream$.sendTextMessageEnd(
|
|
1033
|
+
eventStream$.sendTextMessageEnd({
|
|
1034
|
+
messageId: currentMessageId
|
|
1035
|
+
});
|
|
906
1036
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
907
1037
|
mode = null;
|
|
908
|
-
eventStream$.sendActionExecutionEnd(
|
|
1038
|
+
eventStream$.sendActionExecutionEnd({
|
|
1039
|
+
actionExecutionId: currentToolCallId
|
|
1040
|
+
});
|
|
909
1041
|
}
|
|
910
1042
|
if (mode === null) {
|
|
911
1043
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
912
1044
|
mode = "function";
|
|
913
|
-
|
|
1045
|
+
currentToolCallId = toolCall.id;
|
|
1046
|
+
eventStream$.sendActionExecutionStart({
|
|
1047
|
+
actionExecutionId: currentToolCallId,
|
|
1048
|
+
actionName: toolCall.function.name,
|
|
1049
|
+
parentMessageId: chunk.id
|
|
1050
|
+
});
|
|
914
1051
|
} else if (content) {
|
|
915
1052
|
mode = "message";
|
|
916
|
-
|
|
1053
|
+
currentMessageId = chunk.id;
|
|
1054
|
+
eventStream$.sendTextMessageStart({
|
|
1055
|
+
messageId: currentMessageId
|
|
1056
|
+
});
|
|
917
1057
|
}
|
|
918
1058
|
}
|
|
919
1059
|
if (mode === "message" && content) {
|
|
920
|
-
eventStream$.sendTextMessageContent(
|
|
1060
|
+
eventStream$.sendTextMessageContent({
|
|
1061
|
+
messageId: currentMessageId,
|
|
1062
|
+
content
|
|
1063
|
+
});
|
|
921
1064
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
922
|
-
eventStream$.sendActionExecutionArgs(
|
|
1065
|
+
eventStream$.sendActionExecutionArgs({
|
|
1066
|
+
actionExecutionId: currentToolCallId,
|
|
1067
|
+
args: toolCall.function.arguments
|
|
1068
|
+
});
|
|
923
1069
|
}
|
|
924
1070
|
}
|
|
925
1071
|
if (mode === "message") {
|
|
926
|
-
eventStream$.sendTextMessageEnd(
|
|
1072
|
+
eventStream$.sendTextMessageEnd({
|
|
1073
|
+
messageId: currentMessageId
|
|
1074
|
+
});
|
|
927
1075
|
} else if (mode === "function") {
|
|
928
|
-
eventStream$.sendActionExecutionEnd(
|
|
1076
|
+
eventStream$.sendActionExecutionEnd({
|
|
1077
|
+
actionExecutionId: currentToolCallId
|
|
1078
|
+
});
|
|
929
1079
|
}
|
|
930
1080
|
eventStream$.complete();
|
|
931
1081
|
});
|
|
@@ -1133,7 +1283,11 @@ var AnthropicAdapter = class {
|
|
|
1133
1283
|
mode = "message";
|
|
1134
1284
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1135
1285
|
currentToolCallId = chunk.content_block.id;
|
|
1136
|
-
eventStream$.sendActionExecutionStart(
|
|
1286
|
+
eventStream$.sendActionExecutionStart({
|
|
1287
|
+
actionExecutionId: currentToolCallId,
|
|
1288
|
+
actionName: chunk.content_block.name,
|
|
1289
|
+
parentMessageId: currentMessageId
|
|
1290
|
+
});
|
|
1137
1291
|
mode = "function";
|
|
1138
1292
|
}
|
|
1139
1293
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1141,21 +1295,33 @@ var AnthropicAdapter = class {
|
|
|
1141
1295
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1142
1296
|
if (text.length > 0) {
|
|
1143
1297
|
if (!didOutputText) {
|
|
1144
|
-
eventStream$.sendTextMessageStart(
|
|
1298
|
+
eventStream$.sendTextMessageStart({
|
|
1299
|
+
messageId: currentMessageId
|
|
1300
|
+
});
|
|
1145
1301
|
didOutputText = true;
|
|
1146
1302
|
}
|
|
1147
|
-
eventStream$.sendTextMessageContent(
|
|
1303
|
+
eventStream$.sendTextMessageContent({
|
|
1304
|
+
messageId: currentMessageId,
|
|
1305
|
+
content: text
|
|
1306
|
+
});
|
|
1148
1307
|
}
|
|
1149
1308
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1150
|
-
eventStream$.sendActionExecutionArgs(
|
|
1309
|
+
eventStream$.sendActionExecutionArgs({
|
|
1310
|
+
actionExecutionId: currentToolCallId,
|
|
1311
|
+
args: chunk.delta.partial_json
|
|
1312
|
+
});
|
|
1151
1313
|
}
|
|
1152
1314
|
} else if (chunk.type === "content_block_stop") {
|
|
1153
1315
|
if (mode === "message") {
|
|
1154
1316
|
if (didOutputText) {
|
|
1155
|
-
eventStream$.sendTextMessageEnd(
|
|
1317
|
+
eventStream$.sendTextMessageEnd({
|
|
1318
|
+
messageId: currentMessageId
|
|
1319
|
+
});
|
|
1156
1320
|
}
|
|
1157
1321
|
} else if (mode === "function") {
|
|
1158
|
-
eventStream$.sendActionExecutionEnd(
|
|
1322
|
+
eventStream$.sendActionExecutionEnd({
|
|
1323
|
+
actionExecutionId: currentToolCallId
|
|
1324
|
+
});
|
|
1159
1325
|
}
|
|
1160
1326
|
}
|
|
1161
1327
|
}
|
|
@@ -1221,11 +1387,19 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1221
1387
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1222
1388
|
const _stream = await ollama.stream(contents);
|
|
1223
1389
|
eventSource.stream(async (eventStream$) => {
|
|
1224
|
-
|
|
1390
|
+
const currentMessageId = (0, import_shared7.randomId)();
|
|
1391
|
+
eventStream$.sendTextMessageStart({
|
|
1392
|
+
messageId: currentMessageId
|
|
1393
|
+
});
|
|
1225
1394
|
for await (const chunkText of _stream) {
|
|
1226
|
-
eventStream$.sendTextMessageContent(
|
|
1395
|
+
eventStream$.sendTextMessageContent({
|
|
1396
|
+
messageId: currentMessageId,
|
|
1397
|
+
content: chunkText
|
|
1398
|
+
});
|
|
1227
1399
|
}
|
|
1228
|
-
eventStream$.sendTextMessageEnd(
|
|
1400
|
+
eventStream$.sendTextMessageEnd({
|
|
1401
|
+
messageId: currentMessageId
|
|
1402
|
+
});
|
|
1229
1403
|
eventStream$.complete();
|
|
1230
1404
|
});
|
|
1231
1405
|
return {
|