@copilotkit/runtime 1.4.0-pre-1-4-0.11 → 1.4.0-pre-1-4-0-alpha.10
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 +33 -100
- package/dist/{chunk-BNQDVBQH.mjs → chunk-56IQ6PGC.mjs} +449 -75
- package/dist/chunk-56IQ6PGC.mjs.map +1 -0
- package/dist/chunk-DFOKBSIS.mjs +1 -0
- package/dist/chunk-DFOKBSIS.mjs.map +1 -0
- package/dist/{chunk-VBGS6IWV.mjs → chunk-RDHJQVWH.mjs} +483 -71
- package/dist/chunk-RDHJQVWH.mjs.map +1 -0
- package/dist/{chunk-V2YEM4Z5.mjs → chunk-SBWLAAB3.mjs} +4 -3
- package/dist/chunk-SBWLAAB3.mjs.map +1 -0
- package/dist/{chunk-677K33J7.mjs → chunk-SVL5LEKB.mjs} +4 -3
- package/dist/chunk-SVL5LEKB.mjs.map +1 -0
- package/dist/{chunk-3DNY5YTL.mjs → chunk-YUJSVJWS.mjs} +5 -4
- package/dist/chunk-YUJSVJWS.mjs.map +1 -0
- package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-dbe5fa02.d.ts} +4 -4
- package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-192d2413.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +486 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -22
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f00629d2.d.ts → langserve-878c62b9.d.ts} +46 -9
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +465 -163
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +21 -21
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +161 -85
- 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 +158 -82
- 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 +158 -82
- 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 +157 -81
- 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 +243 -73
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -2
- package/package.json +4 -4
- package/src/agents/langgraph/event-source.ts +12 -0
- package/src/agents/langgraph/events.ts +2 -0
- package/src/graphql/resolvers/copilot.resolver.ts +28 -2
- package/src/lib/integrations/nest/index.ts +5 -2
- package/src/lib/integrations/nextjs/app-router.ts +5 -2
- package/src/lib/integrations/nextjs/pages-router.ts +5 -2
- package/src/lib/integrations/node-express/index.ts +5 -2
- package/src/lib/integrations/node-http/index.ts +5 -2
- package/src/lib/runtime/copilot-runtime.ts +48 -42
- package/src/lib/runtime/remote-action-constructors.ts +17 -3
- package/src/lib/runtime/remote-lg-cloud-action.ts +41 -15
- package/src/lib/telemetry-client.ts +43 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +15 -6
- package/src/service-adapters/events.ts +86 -36
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/google/google-genai-adapter.ts +2 -2
- package/src/service-adapters/groq/groq-adapter.ts +22 -8
- package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
- package/src/service-adapters/langchain/utils.ts +47 -31
- package/src/service-adapters/openai/openai-adapter.ts +25 -8
- package/src/service-adapters/openai/openai-assistant-adapter.ts +21 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-3DNY5YTL.mjs.map +0 -1
- package/dist/chunk-677K33J7.mjs.map +0 -1
- package/dist/chunk-BNQDVBQH.mjs.map +0 -1
- package/dist/chunk-FL67XJAX.mjs +0 -288
- package/dist/chunk-FL67XJAX.mjs.map +0 -1
- package/dist/chunk-MXXPWWBF.mjs +0 -218
- package/dist/chunk-MXXPWWBF.mjs.map +0 -1
- package/dist/chunk-V2YEM4Z5.mjs.map +0 -1
- package/dist/chunk-VBGS6IWV.mjs.map +0 -1
|
@@ -315,35 +315,61 @@ var OpenAIAdapter = class {
|
|
|
315
315
|
eventSource.stream(async (eventStream$) => {
|
|
316
316
|
var _a, _b;
|
|
317
317
|
let mode = null;
|
|
318
|
+
let currentMessageId;
|
|
319
|
+
let currentToolCallId;
|
|
318
320
|
for await (const chunk of stream) {
|
|
321
|
+
if (chunk.choices.length === 0) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
319
324
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
320
325
|
const content = chunk.choices[0].delta.content;
|
|
321
326
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
322
327
|
mode = null;
|
|
323
|
-
eventStream$.sendTextMessageEnd(
|
|
328
|
+
eventStream$.sendTextMessageEnd({
|
|
329
|
+
messageId: currentMessageId
|
|
330
|
+
});
|
|
324
331
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
325
332
|
mode = null;
|
|
326
|
-
eventStream$.sendActionExecutionEnd(
|
|
333
|
+
eventStream$.sendActionExecutionEnd({
|
|
334
|
+
actionExecutionId: currentToolCallId
|
|
335
|
+
});
|
|
327
336
|
}
|
|
328
337
|
if (mode === null) {
|
|
329
338
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
330
339
|
mode = "function";
|
|
331
|
-
|
|
340
|
+
currentToolCallId = toolCall.id;
|
|
341
|
+
eventStream$.sendActionExecutionStart({
|
|
342
|
+
actionExecutionId: currentToolCallId,
|
|
343
|
+
actionName: toolCall.function.name
|
|
344
|
+
});
|
|
332
345
|
} else if (content) {
|
|
333
346
|
mode = "message";
|
|
334
|
-
|
|
347
|
+
currentMessageId = chunk.id;
|
|
348
|
+
eventStream$.sendTextMessageStart({
|
|
349
|
+
messageId: currentMessageId
|
|
350
|
+
});
|
|
335
351
|
}
|
|
336
352
|
}
|
|
337
353
|
if (mode === "message" && content) {
|
|
338
|
-
eventStream$.sendTextMessageContent(
|
|
354
|
+
eventStream$.sendTextMessageContent({
|
|
355
|
+
messageId: currentMessageId,
|
|
356
|
+
content
|
|
357
|
+
});
|
|
339
358
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
340
|
-
eventStream$.sendActionExecutionArgs(
|
|
359
|
+
eventStream$.sendActionExecutionArgs({
|
|
360
|
+
actionExecutionId: currentToolCallId,
|
|
361
|
+
args: toolCall.function.arguments
|
|
362
|
+
});
|
|
341
363
|
}
|
|
342
364
|
}
|
|
343
365
|
if (mode === "message") {
|
|
344
|
-
eventStream$.sendTextMessageEnd(
|
|
366
|
+
eventStream$.sendTextMessageEnd({
|
|
367
|
+
messageId: currentMessageId
|
|
368
|
+
});
|
|
345
369
|
} else if (mode === "function") {
|
|
346
|
-
eventStream$.sendActionExecutionEnd(
|
|
370
|
+
eventStream$.sendActionExecutionEnd({
|
|
371
|
+
actionExecutionId: currentToolCallId
|
|
372
|
+
});
|
|
347
373
|
}
|
|
348
374
|
eventStream$.complete();
|
|
349
375
|
});
|
|
@@ -439,7 +465,11 @@ function isBaseMessageChunk(message) {
|
|
|
439
465
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
440
466
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
441
467
|
if (actionExecution) {
|
|
442
|
-
eventStream$.sendActionExecutionResult(
|
|
468
|
+
eventStream$.sendActionExecutionResult({
|
|
469
|
+
actionExecutionId: actionExecution.id,
|
|
470
|
+
actionName: actionExecution.name,
|
|
471
|
+
result: "Sending a message"
|
|
472
|
+
});
|
|
443
473
|
}
|
|
444
474
|
}
|
|
445
475
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
@@ -449,7 +479,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
449
479
|
if (!actionExecution) {
|
|
450
480
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
451
481
|
} else {
|
|
452
|
-
eventStream$.sendActionExecutionResult(
|
|
482
|
+
eventStream$.sendActionExecutionResult({
|
|
483
|
+
actionExecutionId: actionExecution.id,
|
|
484
|
+
actionName: actionExecution.name,
|
|
485
|
+
result
|
|
486
|
+
});
|
|
453
487
|
}
|
|
454
488
|
} else if (isAIMessage(result)) {
|
|
455
489
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -457,7 +491,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
457
491
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
458
492
|
}
|
|
459
493
|
for (const toolCall of result.tool_calls) {
|
|
460
|
-
eventStream$.sendActionExecution(
|
|
494
|
+
eventStream$.sendActionExecution({
|
|
495
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
496
|
+
actionName: toolCall.name,
|
|
497
|
+
args: JSON.stringify(toolCall.args)
|
|
498
|
+
});
|
|
461
499
|
}
|
|
462
500
|
} else if (isBaseMessageChunk(result)) {
|
|
463
501
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -466,7 +504,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
466
504
|
}
|
|
467
505
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
468
506
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
469
|
-
eventStream$.sendActionExecution(
|
|
507
|
+
eventStream$.sendActionExecution({
|
|
508
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
509
|
+
actionName: toolCall.name,
|
|
510
|
+
args: JSON.stringify(toolCall.args)
|
|
511
|
+
});
|
|
470
512
|
}
|
|
471
513
|
}
|
|
472
514
|
} else if (result && "getReader" in result) {
|
|
@@ -484,6 +526,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
484
526
|
const { done, value } = await reader.read();
|
|
485
527
|
let toolCallName = void 0;
|
|
486
528
|
let toolCallId = void 0;
|
|
529
|
+
let currentMessageId;
|
|
487
530
|
let toolCallArgs = void 0;
|
|
488
531
|
let hasToolCall = false;
|
|
489
532
|
let content = value == null ? void 0 : value.content;
|
|
@@ -511,10 +554,14 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
511
554
|
}
|
|
512
555
|
if (mode === "message" && (toolCallId || done)) {
|
|
513
556
|
mode = null;
|
|
514
|
-
eventStream$.sendTextMessageEnd(
|
|
557
|
+
eventStream$.sendTextMessageEnd({
|
|
558
|
+
messageId: currentMessageId
|
|
559
|
+
});
|
|
515
560
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
516
561
|
mode = null;
|
|
517
|
-
eventStream$.sendActionExecutionEnd(
|
|
562
|
+
eventStream$.sendActionExecutionEnd({
|
|
563
|
+
actionExecutionId: toolCallId
|
|
564
|
+
});
|
|
518
565
|
}
|
|
519
566
|
if (done) {
|
|
520
567
|
break;
|
|
@@ -522,21 +569,38 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
522
569
|
if (mode === null) {
|
|
523
570
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
524
571
|
mode = "function";
|
|
525
|
-
eventStream$.sendActionExecutionStart(
|
|
572
|
+
eventStream$.sendActionExecutionStart({
|
|
573
|
+
actionExecutionId: toolCallId,
|
|
574
|
+
actionName: toolCallName
|
|
575
|
+
});
|
|
526
576
|
} else if (content) {
|
|
527
577
|
mode = "message";
|
|
528
|
-
|
|
578
|
+
currentMessageId = (0, import_shared2.randomId)();
|
|
579
|
+
eventStream$.sendTextMessageStart({
|
|
580
|
+
messageId: currentMessageId
|
|
581
|
+
});
|
|
529
582
|
}
|
|
530
583
|
}
|
|
531
584
|
if (mode === "message" && content) {
|
|
532
|
-
eventStream$.sendTextMessageContent(
|
|
585
|
+
eventStream$.sendTextMessageContent({
|
|
586
|
+
messageId: currentMessageId,
|
|
587
|
+
content: Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content
|
|
588
|
+
});
|
|
533
589
|
} else if (mode === "function" && toolCallArgs) {
|
|
534
590
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
535
|
-
eventStream$.sendActionExecutionEnd(
|
|
536
|
-
|
|
591
|
+
eventStream$.sendActionExecutionEnd({
|
|
592
|
+
actionExecutionId: toolCallId
|
|
593
|
+
});
|
|
594
|
+
eventStream$.sendActionExecutionStart({
|
|
595
|
+
actionExecutionId: toolCallId,
|
|
596
|
+
actionName: toolCallName
|
|
597
|
+
});
|
|
537
598
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
538
599
|
}
|
|
539
|
-
eventStream$.sendActionExecutionArgs(
|
|
600
|
+
eventStream$.sendActionExecutionArgs({
|
|
601
|
+
actionExecutionId: toolCallId,
|
|
602
|
+
args: toolCallArgs
|
|
603
|
+
});
|
|
540
604
|
}
|
|
541
605
|
} catch (error) {
|
|
542
606
|
console.error("Error reading from stream", error);
|
|
@@ -544,7 +608,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
544
608
|
}
|
|
545
609
|
}
|
|
546
610
|
} else if (actionExecution) {
|
|
547
|
-
eventStream$.sendActionExecutionResult(
|
|
611
|
+
eventStream$.sendActionExecutionResult({
|
|
612
|
+
actionExecutionId: actionExecution.id,
|
|
613
|
+
actionName: actionExecution.name,
|
|
614
|
+
result: encodeResult(result)
|
|
615
|
+
});
|
|
548
616
|
} else {
|
|
549
617
|
throw new Error("Invalid return type from LangChain function.");
|
|
550
618
|
}
|
|
@@ -564,6 +632,7 @@ __name(encodeResult, "encodeResult");
|
|
|
564
632
|
|
|
565
633
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
566
634
|
var import_shared3 = require("@copilotkit/shared");
|
|
635
|
+
var import_promises = require("@langchain/core/callbacks/promises");
|
|
567
636
|
var LangChainAdapter = class {
|
|
568
637
|
options;
|
|
569
638
|
/**
|
|
@@ -573,23 +642,28 @@ var LangChainAdapter = class {
|
|
|
573
642
|
this.options = options;
|
|
574
643
|
}
|
|
575
644
|
async process(request) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
await streamLangChainResponse({
|
|
586
|
-
result,
|
|
587
|
-
eventStream$
|
|
645
|
+
try {
|
|
646
|
+
const { eventSource, model, actions, messages, runId } = request;
|
|
647
|
+
const threadId = request.threadId ?? (0, import_shared3.randomId)();
|
|
648
|
+
const result = await this.options.chainFn({
|
|
649
|
+
messages: messages.map(convertMessageToLangChainMessage),
|
|
650
|
+
tools: actions.map(convertActionInputToLangChainTool),
|
|
651
|
+
model,
|
|
652
|
+
threadId,
|
|
653
|
+
runId
|
|
588
654
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
655
|
+
eventSource.stream(async (eventStream$) => {
|
|
656
|
+
await streamLangChainResponse({
|
|
657
|
+
result,
|
|
658
|
+
eventStream$
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
return {
|
|
662
|
+
threadId
|
|
663
|
+
};
|
|
664
|
+
} finally {
|
|
665
|
+
await (0, import_promises.awaitAllCallbacks)();
|
|
666
|
+
}
|
|
593
667
|
}
|
|
594
668
|
};
|
|
595
669
|
__name(LangChainAdapter, "LangChainAdapter");
|
|
@@ -599,12 +673,16 @@ var import_google_gauth = require("@langchain/google-gauth");
|
|
|
599
673
|
var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
600
674
|
constructor(options) {
|
|
601
675
|
super({
|
|
602
|
-
chainFn: async ({ messages, tools }) => {
|
|
676
|
+
chainFn: async ({ messages, tools, threadId }) => {
|
|
603
677
|
const model = new import_google_gauth.ChatGoogle({
|
|
604
678
|
modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
|
|
605
679
|
apiVersion: "v1beta"
|
|
606
680
|
}).bindTools(tools);
|
|
607
|
-
return model.stream(messages
|
|
681
|
+
return model.stream(messages, {
|
|
682
|
+
metadata: {
|
|
683
|
+
conversation_id: threadId
|
|
684
|
+
}
|
|
685
|
+
});
|
|
608
686
|
}
|
|
609
687
|
});
|
|
610
688
|
}
|
|
@@ -714,21 +792,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
714
792
|
eventSource.stream(async (eventStream$) => {
|
|
715
793
|
var _a, _b, _c, _d, _e, _f;
|
|
716
794
|
let inFunctionCall = false;
|
|
795
|
+
let currentMessageId;
|
|
796
|
+
let currentToolCallId;
|
|
717
797
|
for await (const chunk of stream) {
|
|
718
798
|
switch (chunk.event) {
|
|
719
799
|
case "thread.message.created":
|
|
720
800
|
if (inFunctionCall) {
|
|
721
|
-
eventStream$.sendActionExecutionEnd(
|
|
801
|
+
eventStream$.sendActionExecutionEnd({
|
|
802
|
+
actionExecutionId: currentToolCallId
|
|
803
|
+
});
|
|
722
804
|
}
|
|
723
|
-
|
|
805
|
+
currentMessageId = chunk.data.id;
|
|
806
|
+
eventStream$.sendTextMessageStart({
|
|
807
|
+
messageId: currentMessageId
|
|
808
|
+
});
|
|
724
809
|
break;
|
|
725
810
|
case "thread.message.delta":
|
|
726
811
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
727
|
-
eventStream$.sendTextMessageContent(
|
|
812
|
+
eventStream$.sendTextMessageContent({
|
|
813
|
+
messageId: currentMessageId,
|
|
814
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
815
|
+
});
|
|
728
816
|
}
|
|
729
817
|
break;
|
|
730
818
|
case "thread.message.completed":
|
|
731
|
-
eventStream$.sendTextMessageEnd(
|
|
819
|
+
eventStream$.sendTextMessageEnd({
|
|
820
|
+
messageId: currentMessageId
|
|
821
|
+
});
|
|
732
822
|
break;
|
|
733
823
|
case "thread.run.step.delta":
|
|
734
824
|
let toolCallId;
|
|
@@ -741,18 +831,29 @@ var OpenAIAssistantAdapter = class {
|
|
|
741
831
|
}
|
|
742
832
|
if (toolCallName && toolCallId) {
|
|
743
833
|
if (inFunctionCall) {
|
|
744
|
-
eventStream$.sendActionExecutionEnd(
|
|
834
|
+
eventStream$.sendActionExecutionEnd({
|
|
835
|
+
actionExecutionId: currentToolCallId
|
|
836
|
+
});
|
|
745
837
|
}
|
|
746
838
|
inFunctionCall = true;
|
|
747
|
-
|
|
839
|
+
currentToolCallId = toolCallId;
|
|
840
|
+
eventStream$.sendActionExecutionStart({
|
|
841
|
+
actionExecutionId: currentToolCallId,
|
|
842
|
+
actionName: toolCallName
|
|
843
|
+
});
|
|
748
844
|
} else if (toolCallArgs) {
|
|
749
|
-
eventStream$.sendActionExecutionArgs(
|
|
845
|
+
eventStream$.sendActionExecutionArgs({
|
|
846
|
+
actionExecutionId: currentToolCallId,
|
|
847
|
+
args: toolCallArgs
|
|
848
|
+
});
|
|
750
849
|
}
|
|
751
850
|
break;
|
|
752
851
|
}
|
|
753
852
|
}
|
|
754
853
|
if (inFunctionCall) {
|
|
755
|
-
eventStream$.sendActionExecutionEnd(
|
|
854
|
+
eventStream$.sendActionExecutionEnd({
|
|
855
|
+
actionExecutionId: currentToolCallId
|
|
856
|
+
});
|
|
756
857
|
}
|
|
757
858
|
eventStream$.complete();
|
|
758
859
|
});
|
|
@@ -805,46 +906,77 @@ var UnifyAdapter = class {
|
|
|
805
906
|
}
|
|
806
907
|
});
|
|
807
908
|
let model = null;
|
|
909
|
+
let currentMessageId;
|
|
910
|
+
let currentToolCallId;
|
|
808
911
|
request.eventSource.stream(async (eventStream$) => {
|
|
809
912
|
var _a, _b;
|
|
810
913
|
let mode = null;
|
|
811
914
|
for await (const chunk of stream) {
|
|
812
915
|
if (this.start) {
|
|
813
916
|
model = chunk.model;
|
|
814
|
-
|
|
815
|
-
eventStream$.
|
|
816
|
-
|
|
817
|
-
|
|
917
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
918
|
+
eventStream$.sendTextMessageStart({
|
|
919
|
+
messageId: currentMessageId
|
|
920
|
+
});
|
|
921
|
+
eventStream$.sendTextMessageContent({
|
|
922
|
+
messageId: currentMessageId,
|
|
923
|
+
content: `Model used: ${model}
|
|
924
|
+
`
|
|
925
|
+
});
|
|
926
|
+
eventStream$.sendTextMessageEnd({
|
|
927
|
+
messageId: currentMessageId
|
|
928
|
+
});
|
|
818
929
|
this.start = false;
|
|
819
930
|
}
|
|
820
931
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
821
932
|
const content = chunk.choices[0].delta.content;
|
|
822
933
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
823
934
|
mode = null;
|
|
824
|
-
eventStream$.sendTextMessageEnd(
|
|
935
|
+
eventStream$.sendTextMessageEnd({
|
|
936
|
+
messageId: currentMessageId
|
|
937
|
+
});
|
|
825
938
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
826
939
|
mode = null;
|
|
827
|
-
eventStream$.sendActionExecutionEnd(
|
|
940
|
+
eventStream$.sendActionExecutionEnd({
|
|
941
|
+
actionExecutionId: currentToolCallId
|
|
942
|
+
});
|
|
828
943
|
}
|
|
829
944
|
if (mode === null) {
|
|
830
945
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
831
946
|
mode = "function";
|
|
832
|
-
|
|
947
|
+
currentToolCallId = toolCall.id;
|
|
948
|
+
eventStream$.sendActionExecutionStart({
|
|
949
|
+
actionExecutionId: currentToolCallId,
|
|
950
|
+
actionName: toolCall.function.name
|
|
951
|
+
});
|
|
833
952
|
} else if (content) {
|
|
834
953
|
mode = "message";
|
|
835
|
-
|
|
954
|
+
currentMessageId = chunk.id;
|
|
955
|
+
eventStream$.sendTextMessageStart({
|
|
956
|
+
messageId: currentMessageId
|
|
957
|
+
});
|
|
836
958
|
}
|
|
837
959
|
}
|
|
838
960
|
if (mode === "message" && content) {
|
|
839
|
-
eventStream$.sendTextMessageContent(
|
|
961
|
+
eventStream$.sendTextMessageContent({
|
|
962
|
+
messageId: currentMessageId,
|
|
963
|
+
content
|
|
964
|
+
});
|
|
840
965
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
841
|
-
eventStream$.sendActionExecutionArgs(
|
|
966
|
+
eventStream$.sendActionExecutionArgs({
|
|
967
|
+
actionExecutionId: currentToolCallId,
|
|
968
|
+
args: toolCall.function.arguments
|
|
969
|
+
});
|
|
842
970
|
}
|
|
843
971
|
}
|
|
844
972
|
if (mode === "message") {
|
|
845
|
-
eventStream$.sendTextMessageEnd(
|
|
973
|
+
eventStream$.sendTextMessageEnd({
|
|
974
|
+
messageId: currentMessageId
|
|
975
|
+
});
|
|
846
976
|
} else if (mode === "function") {
|
|
847
|
-
eventStream$.sendActionExecutionEnd(
|
|
977
|
+
eventStream$.sendActionExecutionEnd({
|
|
978
|
+
actionExecutionId: currentToolCallId
|
|
979
|
+
});
|
|
848
980
|
}
|
|
849
981
|
eventStream$.complete();
|
|
850
982
|
});
|
|
@@ -910,35 +1042,58 @@ var GroqAdapter = class {
|
|
|
910
1042
|
eventSource.stream(async (eventStream$) => {
|
|
911
1043
|
var _a, _b;
|
|
912
1044
|
let mode = null;
|
|
1045
|
+
let currentMessageId;
|
|
1046
|
+
let currentToolCallId;
|
|
913
1047
|
for await (const chunk of stream) {
|
|
914
1048
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
915
1049
|
const content = chunk.choices[0].delta.content;
|
|
916
1050
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
917
1051
|
mode = null;
|
|
918
|
-
eventStream$.sendTextMessageEnd(
|
|
1052
|
+
eventStream$.sendTextMessageEnd({
|
|
1053
|
+
messageId: currentMessageId
|
|
1054
|
+
});
|
|
919
1055
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
920
1056
|
mode = null;
|
|
921
|
-
eventStream$.sendActionExecutionEnd(
|
|
1057
|
+
eventStream$.sendActionExecutionEnd({
|
|
1058
|
+
actionExecutionId: currentToolCallId
|
|
1059
|
+
});
|
|
922
1060
|
}
|
|
923
1061
|
if (mode === null) {
|
|
924
1062
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
925
1063
|
mode = "function";
|
|
926
|
-
|
|
1064
|
+
currentToolCallId = toolCall.id;
|
|
1065
|
+
eventStream$.sendActionExecutionStart({
|
|
1066
|
+
actionExecutionId: currentToolCallId,
|
|
1067
|
+
actionName: toolCall.function.name
|
|
1068
|
+
});
|
|
927
1069
|
} else if (content) {
|
|
928
1070
|
mode = "message";
|
|
929
|
-
|
|
1071
|
+
currentMessageId = chunk.id;
|
|
1072
|
+
eventStream$.sendTextMessageStart({
|
|
1073
|
+
messageId: currentMessageId
|
|
1074
|
+
});
|
|
930
1075
|
}
|
|
931
1076
|
}
|
|
932
1077
|
if (mode === "message" && content) {
|
|
933
|
-
eventStream$.sendTextMessageContent(
|
|
1078
|
+
eventStream$.sendTextMessageContent({
|
|
1079
|
+
messageId: currentMessageId,
|
|
1080
|
+
content
|
|
1081
|
+
});
|
|
934
1082
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
935
|
-
eventStream$.sendActionExecutionArgs(
|
|
1083
|
+
eventStream$.sendActionExecutionArgs({
|
|
1084
|
+
actionExecutionId: currentToolCallId,
|
|
1085
|
+
args: toolCall.function.arguments
|
|
1086
|
+
});
|
|
936
1087
|
}
|
|
937
1088
|
}
|
|
938
1089
|
if (mode === "message") {
|
|
939
|
-
eventStream$.sendTextMessageEnd(
|
|
1090
|
+
eventStream$.sendTextMessageEnd({
|
|
1091
|
+
messageId: currentMessageId
|
|
1092
|
+
});
|
|
940
1093
|
} else if (mode === "function") {
|
|
941
|
-
eventStream$.sendActionExecutionEnd(
|
|
1094
|
+
eventStream$.sendActionExecutionEnd({
|
|
1095
|
+
actionExecutionId: currentToolCallId
|
|
1096
|
+
});
|
|
942
1097
|
}
|
|
943
1098
|
eventStream$.complete();
|
|
944
1099
|
});
|
|
@@ -1146,7 +1301,10 @@ var AnthropicAdapter = class {
|
|
|
1146
1301
|
mode = "message";
|
|
1147
1302
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1148
1303
|
currentToolCallId = chunk.content_block.id;
|
|
1149
|
-
eventStream$.sendActionExecutionStart(
|
|
1304
|
+
eventStream$.sendActionExecutionStart({
|
|
1305
|
+
actionExecutionId: currentToolCallId,
|
|
1306
|
+
actionName: chunk.content_block.name
|
|
1307
|
+
});
|
|
1150
1308
|
mode = "function";
|
|
1151
1309
|
}
|
|
1152
1310
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1154,21 +1312,33 @@ var AnthropicAdapter = class {
|
|
|
1154
1312
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1155
1313
|
if (text.length > 0) {
|
|
1156
1314
|
if (!didOutputText) {
|
|
1157
|
-
eventStream$.sendTextMessageStart(
|
|
1315
|
+
eventStream$.sendTextMessageStart({
|
|
1316
|
+
messageId: currentMessageId
|
|
1317
|
+
});
|
|
1158
1318
|
didOutputText = true;
|
|
1159
1319
|
}
|
|
1160
|
-
eventStream$.sendTextMessageContent(
|
|
1320
|
+
eventStream$.sendTextMessageContent({
|
|
1321
|
+
messageId: currentMessageId,
|
|
1322
|
+
content: text
|
|
1323
|
+
});
|
|
1161
1324
|
}
|
|
1162
1325
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1163
|
-
eventStream$.sendActionExecutionArgs(
|
|
1326
|
+
eventStream$.sendActionExecutionArgs({
|
|
1327
|
+
actionExecutionId: currentToolCallId,
|
|
1328
|
+
args: chunk.delta.partial_json
|
|
1329
|
+
});
|
|
1164
1330
|
}
|
|
1165
1331
|
} else if (chunk.type === "content_block_stop") {
|
|
1166
1332
|
if (mode === "message") {
|
|
1167
1333
|
if (didOutputText) {
|
|
1168
|
-
eventStream$.sendTextMessageEnd(
|
|
1334
|
+
eventStream$.sendTextMessageEnd({
|
|
1335
|
+
messageId: currentMessageId
|
|
1336
|
+
});
|
|
1169
1337
|
}
|
|
1170
1338
|
} else if (mode === "function") {
|
|
1171
|
-
eventStream$.sendActionExecutionEnd(
|
|
1339
|
+
eventStream$.sendActionExecutionEnd({
|
|
1340
|
+
actionExecutionId: currentToolCallId
|
|
1341
|
+
});
|
|
1172
1342
|
}
|
|
1173
1343
|
}
|
|
1174
1344
|
}
|