@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.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 +141 -3
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-25G6SHWM.mjs} +458 -331
- package/dist/chunk-25G6SHWM.mjs.map +1 -0
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-AFKLCW76.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-D6J2N5ZQ.mjs} +2 -2
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-PIUHAIBR.mjs} +2 -2
- 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 +832 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- 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 +737 -459
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- 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 +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 +4 -4
- 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/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 +184 -154
- 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-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-K67A6XOJ.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-AFKLCW76.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-D6J2N5ZQ.mjs.map} +0 -0
- /package/dist/{chunk-QNQ6UT3D.mjs.map → chunk-PIUHAIBR.mjs.map} +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.5.0
|
|
47
|
+
version: "1.5.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -424,6 +424,8 @@ var OpenAIAdapter = class {
|
|
|
424
424
|
eventSource.stream(async (eventStream$) => {
|
|
425
425
|
var _a, _b;
|
|
426
426
|
let mode = null;
|
|
427
|
+
let currentMessageId;
|
|
428
|
+
let currentToolCallId;
|
|
427
429
|
for await (const chunk of stream) {
|
|
428
430
|
if (chunk.choices.length === 0) {
|
|
429
431
|
continue;
|
|
@@ -432,30 +434,52 @@ var OpenAIAdapter = class {
|
|
|
432
434
|
const content = chunk.choices[0].delta.content;
|
|
433
435
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
434
436
|
mode = null;
|
|
435
|
-
eventStream$.sendTextMessageEnd(
|
|
437
|
+
eventStream$.sendTextMessageEnd({
|
|
438
|
+
messageId: currentMessageId
|
|
439
|
+
});
|
|
436
440
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
437
441
|
mode = null;
|
|
438
|
-
eventStream$.sendActionExecutionEnd(
|
|
442
|
+
eventStream$.sendActionExecutionEnd({
|
|
443
|
+
actionExecutionId: currentToolCallId
|
|
444
|
+
});
|
|
439
445
|
}
|
|
440
446
|
if (mode === null) {
|
|
441
447
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
442
448
|
mode = "function";
|
|
443
|
-
|
|
449
|
+
currentToolCallId = toolCall.id;
|
|
450
|
+
eventStream$.sendActionExecutionStart({
|
|
451
|
+
actionExecutionId: currentToolCallId,
|
|
452
|
+
parentMessageId: chunk.id,
|
|
453
|
+
actionName: toolCall.function.name
|
|
454
|
+
});
|
|
444
455
|
} else if (content) {
|
|
445
456
|
mode = "message";
|
|
446
|
-
|
|
457
|
+
currentMessageId = chunk.id;
|
|
458
|
+
eventStream$.sendTextMessageStart({
|
|
459
|
+
messageId: currentMessageId
|
|
460
|
+
});
|
|
447
461
|
}
|
|
448
462
|
}
|
|
449
463
|
if (mode === "message" && content) {
|
|
450
|
-
eventStream$.sendTextMessageContent(
|
|
464
|
+
eventStream$.sendTextMessageContent({
|
|
465
|
+
messageId: currentMessageId,
|
|
466
|
+
content
|
|
467
|
+
});
|
|
451
468
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
452
|
-
eventStream$.sendActionExecutionArgs(
|
|
469
|
+
eventStream$.sendActionExecutionArgs({
|
|
470
|
+
actionExecutionId: currentToolCallId,
|
|
471
|
+
args: toolCall.function.arguments
|
|
472
|
+
});
|
|
453
473
|
}
|
|
454
474
|
}
|
|
455
475
|
if (mode === "message") {
|
|
456
|
-
eventStream$.sendTextMessageEnd(
|
|
476
|
+
eventStream$.sendTextMessageEnd({
|
|
477
|
+
messageId: currentMessageId
|
|
478
|
+
});
|
|
457
479
|
} else if (mode === "function") {
|
|
458
|
-
eventStream$.sendActionExecutionEnd(
|
|
480
|
+
eventStream$.sendActionExecutionEnd({
|
|
481
|
+
actionExecutionId: currentToolCallId
|
|
482
|
+
});
|
|
459
483
|
}
|
|
460
484
|
eventStream$.complete();
|
|
461
485
|
});
|
|
@@ -523,17 +547,25 @@ function isBaseMessageChunk(message) {
|
|
|
523
547
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
524
548
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
525
549
|
if (actionExecution) {
|
|
526
|
-
eventStream$.sendActionExecutionResult(
|
|
550
|
+
eventStream$.sendActionExecutionResult({
|
|
551
|
+
actionExecutionId: actionExecution.id,
|
|
552
|
+
actionName: actionExecution.name,
|
|
553
|
+
result: "Sending a message"
|
|
554
|
+
});
|
|
527
555
|
}
|
|
528
556
|
}
|
|
529
557
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
530
558
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
531
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
559
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
532
560
|
if (typeof result === "string") {
|
|
533
561
|
if (!actionExecution) {
|
|
534
562
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
535
563
|
} else {
|
|
536
|
-
eventStream$.sendActionExecutionResult(
|
|
564
|
+
eventStream$.sendActionExecutionResult({
|
|
565
|
+
actionExecutionId: actionExecution.id,
|
|
566
|
+
actionName: actionExecution.name,
|
|
567
|
+
result
|
|
568
|
+
});
|
|
537
569
|
}
|
|
538
570
|
} else if (isAIMessage(result)) {
|
|
539
571
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -541,7 +573,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
541
573
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
542
574
|
}
|
|
543
575
|
for (const toolCall of result.tool_calls) {
|
|
544
|
-
eventStream$.sendActionExecution(
|
|
576
|
+
eventStream$.sendActionExecution({
|
|
577
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
578
|
+
actionName: toolCall.name,
|
|
579
|
+
args: JSON.stringify(toolCall.args)
|
|
580
|
+
});
|
|
545
581
|
}
|
|
546
582
|
} else if (isBaseMessageChunk(result)) {
|
|
547
583
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -550,13 +586,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
550
586
|
}
|
|
551
587
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
552
588
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
553
|
-
eventStream$.sendActionExecution(
|
|
589
|
+
eventStream$.sendActionExecution({
|
|
590
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
591
|
+
actionName: toolCall.name,
|
|
592
|
+
args: JSON.stringify(toolCall.args)
|
|
593
|
+
});
|
|
554
594
|
}
|
|
555
595
|
}
|
|
556
596
|
} else if (result && "getReader" in result) {
|
|
557
597
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
558
598
|
let reader = result.getReader();
|
|
559
599
|
let mode = null;
|
|
600
|
+
let currentMessageId;
|
|
560
601
|
const toolCallDetails = {
|
|
561
602
|
name: null,
|
|
562
603
|
id: null,
|
|
@@ -570,9 +611,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
570
611
|
let toolCallId = void 0;
|
|
571
612
|
let toolCallArgs = void 0;
|
|
572
613
|
let hasToolCall = false;
|
|
573
|
-
let content =
|
|
614
|
+
let content = "";
|
|
615
|
+
if (value && value.content) {
|
|
616
|
+
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
617
|
+
}
|
|
574
618
|
if (isAIMessageChunk(value)) {
|
|
575
|
-
let chunk = (
|
|
619
|
+
let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
|
|
576
620
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
577
621
|
hasToolCall = chunk != void 0;
|
|
578
622
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -587,18 +631,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
587
631
|
toolCallName = toolCallDetails.name;
|
|
588
632
|
toolCallId = toolCallDetails.id;
|
|
589
633
|
} else if (isBaseMessageChunk(value)) {
|
|
590
|
-
let chunk = (
|
|
591
|
-
toolCallName = (
|
|
634
|
+
let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
|
|
635
|
+
toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
|
|
592
636
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
593
|
-
toolCallArgs = (
|
|
637
|
+
toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
|
|
594
638
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
595
639
|
}
|
|
596
640
|
if (mode === "message" && (toolCallId || done)) {
|
|
597
641
|
mode = null;
|
|
598
|
-
eventStream$.sendTextMessageEnd(
|
|
642
|
+
eventStream$.sendTextMessageEnd({
|
|
643
|
+
messageId: currentMessageId
|
|
644
|
+
});
|
|
599
645
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
600
646
|
mode = null;
|
|
601
|
-
eventStream$.sendActionExecutionEnd(
|
|
647
|
+
eventStream$.sendActionExecutionEnd({
|
|
648
|
+
actionExecutionId: toolCallId
|
|
649
|
+
});
|
|
602
650
|
}
|
|
603
651
|
if (done) {
|
|
604
652
|
break;
|
|
@@ -606,21 +654,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
606
654
|
if (mode === null) {
|
|
607
655
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
608
656
|
mode = "function";
|
|
609
|
-
eventStream$.sendActionExecutionStart(
|
|
657
|
+
eventStream$.sendActionExecutionStart({
|
|
658
|
+
actionExecutionId: toolCallId,
|
|
659
|
+
actionName: toolCallName,
|
|
660
|
+
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
661
|
+
});
|
|
610
662
|
} else if (content) {
|
|
611
663
|
mode = "message";
|
|
612
|
-
|
|
664
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared2.randomId)();
|
|
665
|
+
eventStream$.sendTextMessageStart({
|
|
666
|
+
messageId: currentMessageId
|
|
667
|
+
});
|
|
613
668
|
}
|
|
614
669
|
}
|
|
615
670
|
if (mode === "message" && content) {
|
|
616
|
-
eventStream$.sendTextMessageContent(
|
|
671
|
+
eventStream$.sendTextMessageContent({
|
|
672
|
+
messageId: currentMessageId,
|
|
673
|
+
content
|
|
674
|
+
});
|
|
617
675
|
} else if (mode === "function" && toolCallArgs) {
|
|
618
676
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
619
|
-
eventStream$.sendActionExecutionEnd(
|
|
620
|
-
|
|
677
|
+
eventStream$.sendActionExecutionEnd({
|
|
678
|
+
actionExecutionId: toolCallId
|
|
679
|
+
});
|
|
680
|
+
eventStream$.sendActionExecutionStart({
|
|
681
|
+
actionExecutionId: toolCallId,
|
|
682
|
+
actionName: toolCallName,
|
|
683
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
684
|
+
});
|
|
621
685
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
622
686
|
}
|
|
623
|
-
eventStream$.sendActionExecutionArgs(
|
|
687
|
+
eventStream$.sendActionExecutionArgs({
|
|
688
|
+
actionExecutionId: toolCallId,
|
|
689
|
+
args: toolCallArgs
|
|
690
|
+
});
|
|
624
691
|
}
|
|
625
692
|
} catch (error) {
|
|
626
693
|
console.error("Error reading from stream", error);
|
|
@@ -628,7 +695,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
628
695
|
}
|
|
629
696
|
}
|
|
630
697
|
} else if (actionExecution) {
|
|
631
|
-
eventStream$.sendActionExecutionResult(
|
|
698
|
+
eventStream$.sendActionExecutionResult({
|
|
699
|
+
actionExecutionId: actionExecution.id,
|
|
700
|
+
actionName: actionExecution.name,
|
|
701
|
+
result: encodeResult(result)
|
|
702
|
+
});
|
|
632
703
|
} else {
|
|
633
704
|
throw new Error("Invalid return type from LangChain function.");
|
|
634
705
|
}
|
|
@@ -808,21 +879,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
808
879
|
eventSource.stream(async (eventStream$) => {
|
|
809
880
|
var _a, _b, _c, _d, _e, _f;
|
|
810
881
|
let inFunctionCall = false;
|
|
882
|
+
let currentMessageId;
|
|
883
|
+
let currentToolCallId;
|
|
811
884
|
for await (const chunk of stream) {
|
|
812
885
|
switch (chunk.event) {
|
|
813
886
|
case "thread.message.created":
|
|
814
887
|
if (inFunctionCall) {
|
|
815
|
-
eventStream$.sendActionExecutionEnd(
|
|
888
|
+
eventStream$.sendActionExecutionEnd({
|
|
889
|
+
actionExecutionId: currentToolCallId
|
|
890
|
+
});
|
|
816
891
|
}
|
|
817
|
-
|
|
892
|
+
currentMessageId = chunk.data.id;
|
|
893
|
+
eventStream$.sendTextMessageStart({
|
|
894
|
+
messageId: currentMessageId
|
|
895
|
+
});
|
|
818
896
|
break;
|
|
819
897
|
case "thread.message.delta":
|
|
820
898
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
821
|
-
eventStream$.sendTextMessageContent(
|
|
899
|
+
eventStream$.sendTextMessageContent({
|
|
900
|
+
messageId: currentMessageId,
|
|
901
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
902
|
+
});
|
|
822
903
|
}
|
|
823
904
|
break;
|
|
824
905
|
case "thread.message.completed":
|
|
825
|
-
eventStream$.sendTextMessageEnd(
|
|
906
|
+
eventStream$.sendTextMessageEnd({
|
|
907
|
+
messageId: currentMessageId
|
|
908
|
+
});
|
|
826
909
|
break;
|
|
827
910
|
case "thread.run.step.delta":
|
|
828
911
|
let toolCallId;
|
|
@@ -835,18 +918,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
835
918
|
}
|
|
836
919
|
if (toolCallName && toolCallId) {
|
|
837
920
|
if (inFunctionCall) {
|
|
838
|
-
eventStream$.sendActionExecutionEnd(
|
|
921
|
+
eventStream$.sendActionExecutionEnd({
|
|
922
|
+
actionExecutionId: currentToolCallId
|
|
923
|
+
});
|
|
839
924
|
}
|
|
840
925
|
inFunctionCall = true;
|
|
841
|
-
|
|
926
|
+
currentToolCallId = toolCallId;
|
|
927
|
+
eventStream$.sendActionExecutionStart({
|
|
928
|
+
actionExecutionId: currentToolCallId,
|
|
929
|
+
parentMessageId: chunk.data.id,
|
|
930
|
+
actionName: toolCallName
|
|
931
|
+
});
|
|
842
932
|
} else if (toolCallArgs) {
|
|
843
|
-
eventStream$.sendActionExecutionArgs(
|
|
933
|
+
eventStream$.sendActionExecutionArgs({
|
|
934
|
+
actionExecutionId: currentToolCallId,
|
|
935
|
+
args: toolCallArgs
|
|
936
|
+
});
|
|
844
937
|
}
|
|
845
938
|
break;
|
|
846
939
|
}
|
|
847
940
|
}
|
|
848
941
|
if (inFunctionCall) {
|
|
849
|
-
eventStream$.sendActionExecutionEnd(
|
|
942
|
+
eventStream$.sendActionExecutionEnd({
|
|
943
|
+
actionExecutionId: currentToolCallId
|
|
944
|
+
});
|
|
850
945
|
}
|
|
851
946
|
eventStream$.complete();
|
|
852
947
|
});
|
|
@@ -899,46 +994,77 @@ var UnifyAdapter = class {
|
|
|
899
994
|
}
|
|
900
995
|
});
|
|
901
996
|
let model = null;
|
|
997
|
+
let currentMessageId;
|
|
998
|
+
let currentToolCallId;
|
|
902
999
|
request.eventSource.stream(async (eventStream$) => {
|
|
903
1000
|
var _a, _b;
|
|
904
1001
|
let mode = null;
|
|
905
1002
|
for await (const chunk of stream) {
|
|
906
1003
|
if (this.start) {
|
|
907
1004
|
model = chunk.model;
|
|
908
|
-
|
|
909
|
-
eventStream$.
|
|
910
|
-
|
|
911
|
-
|
|
1005
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
1006
|
+
eventStream$.sendTextMessageStart({
|
|
1007
|
+
messageId: currentMessageId
|
|
1008
|
+
});
|
|
1009
|
+
eventStream$.sendTextMessageContent({
|
|
1010
|
+
messageId: currentMessageId,
|
|
1011
|
+
content: `Model used: ${model}
|
|
1012
|
+
`
|
|
1013
|
+
});
|
|
1014
|
+
eventStream$.sendTextMessageEnd({
|
|
1015
|
+
messageId: currentMessageId
|
|
1016
|
+
});
|
|
912
1017
|
this.start = false;
|
|
913
1018
|
}
|
|
914
1019
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
915
1020
|
const content = chunk.choices[0].delta.content;
|
|
916
1021
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
917
1022
|
mode = null;
|
|
918
|
-
eventStream$.sendTextMessageEnd(
|
|
1023
|
+
eventStream$.sendTextMessageEnd({
|
|
1024
|
+
messageId: currentMessageId
|
|
1025
|
+
});
|
|
919
1026
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
920
1027
|
mode = null;
|
|
921
|
-
eventStream$.sendActionExecutionEnd(
|
|
1028
|
+
eventStream$.sendActionExecutionEnd({
|
|
1029
|
+
actionExecutionId: currentToolCallId
|
|
1030
|
+
});
|
|
922
1031
|
}
|
|
923
1032
|
if (mode === null) {
|
|
924
1033
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
925
1034
|
mode = "function";
|
|
926
|
-
|
|
1035
|
+
currentToolCallId = toolCall.id;
|
|
1036
|
+
eventStream$.sendActionExecutionStart({
|
|
1037
|
+
actionExecutionId: currentToolCallId,
|
|
1038
|
+
actionName: toolCall.function.name
|
|
1039
|
+
});
|
|
927
1040
|
} else if (content) {
|
|
928
1041
|
mode = "message";
|
|
929
|
-
|
|
1042
|
+
currentMessageId = chunk.id;
|
|
1043
|
+
eventStream$.sendTextMessageStart({
|
|
1044
|
+
messageId: currentMessageId
|
|
1045
|
+
});
|
|
930
1046
|
}
|
|
931
1047
|
}
|
|
932
1048
|
if (mode === "message" && content) {
|
|
933
|
-
eventStream$.sendTextMessageContent(
|
|
1049
|
+
eventStream$.sendTextMessageContent({
|
|
1050
|
+
messageId: currentMessageId,
|
|
1051
|
+
content
|
|
1052
|
+
});
|
|
934
1053
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
935
|
-
eventStream$.sendActionExecutionArgs(
|
|
1054
|
+
eventStream$.sendActionExecutionArgs({
|
|
1055
|
+
actionExecutionId: currentToolCallId,
|
|
1056
|
+
args: toolCall.function.arguments
|
|
1057
|
+
});
|
|
936
1058
|
}
|
|
937
1059
|
}
|
|
938
1060
|
if (mode === "message") {
|
|
939
|
-
eventStream$.sendTextMessageEnd(
|
|
1061
|
+
eventStream$.sendTextMessageEnd({
|
|
1062
|
+
messageId: currentMessageId
|
|
1063
|
+
});
|
|
940
1064
|
} else if (mode === "function") {
|
|
941
|
-
eventStream$.sendActionExecutionEnd(
|
|
1065
|
+
eventStream$.sendActionExecutionEnd({
|
|
1066
|
+
actionExecutionId: currentToolCallId
|
|
1067
|
+
});
|
|
942
1068
|
}
|
|
943
1069
|
eventStream$.complete();
|
|
944
1070
|
});
|
|
@@ -1004,35 +1130,59 @@ var GroqAdapter = class {
|
|
|
1004
1130
|
eventSource.stream(async (eventStream$) => {
|
|
1005
1131
|
var _a, _b;
|
|
1006
1132
|
let mode = null;
|
|
1133
|
+
let currentMessageId;
|
|
1134
|
+
let currentToolCallId;
|
|
1007
1135
|
for await (const chunk of stream) {
|
|
1008
1136
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1009
1137
|
const content = chunk.choices[0].delta.content;
|
|
1010
1138
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1011
1139
|
mode = null;
|
|
1012
|
-
eventStream$.sendTextMessageEnd(
|
|
1140
|
+
eventStream$.sendTextMessageEnd({
|
|
1141
|
+
messageId: currentMessageId
|
|
1142
|
+
});
|
|
1013
1143
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1014
1144
|
mode = null;
|
|
1015
|
-
eventStream$.sendActionExecutionEnd(
|
|
1145
|
+
eventStream$.sendActionExecutionEnd({
|
|
1146
|
+
actionExecutionId: currentToolCallId
|
|
1147
|
+
});
|
|
1016
1148
|
}
|
|
1017
1149
|
if (mode === null) {
|
|
1018
1150
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1019
1151
|
mode = "function";
|
|
1020
|
-
|
|
1152
|
+
currentToolCallId = toolCall.id;
|
|
1153
|
+
eventStream$.sendActionExecutionStart({
|
|
1154
|
+
actionExecutionId: currentToolCallId,
|
|
1155
|
+
actionName: toolCall.function.name,
|
|
1156
|
+
parentMessageId: chunk.id
|
|
1157
|
+
});
|
|
1021
1158
|
} else if (content) {
|
|
1022
1159
|
mode = "message";
|
|
1023
|
-
|
|
1160
|
+
currentMessageId = chunk.id;
|
|
1161
|
+
eventStream$.sendTextMessageStart({
|
|
1162
|
+
messageId: currentMessageId
|
|
1163
|
+
});
|
|
1024
1164
|
}
|
|
1025
1165
|
}
|
|
1026
1166
|
if (mode === "message" && content) {
|
|
1027
|
-
eventStream$.sendTextMessageContent(
|
|
1167
|
+
eventStream$.sendTextMessageContent({
|
|
1168
|
+
messageId: currentMessageId,
|
|
1169
|
+
content
|
|
1170
|
+
});
|
|
1028
1171
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1029
|
-
eventStream$.sendActionExecutionArgs(
|
|
1172
|
+
eventStream$.sendActionExecutionArgs({
|
|
1173
|
+
actionExecutionId: currentToolCallId,
|
|
1174
|
+
args: toolCall.function.arguments
|
|
1175
|
+
});
|
|
1030
1176
|
}
|
|
1031
1177
|
}
|
|
1032
1178
|
if (mode === "message") {
|
|
1033
|
-
eventStream$.sendTextMessageEnd(
|
|
1179
|
+
eventStream$.sendTextMessageEnd({
|
|
1180
|
+
messageId: currentMessageId
|
|
1181
|
+
});
|
|
1034
1182
|
} else if (mode === "function") {
|
|
1035
|
-
eventStream$.sendActionExecutionEnd(
|
|
1183
|
+
eventStream$.sendActionExecutionEnd({
|
|
1184
|
+
actionExecutionId: currentToolCallId
|
|
1185
|
+
});
|
|
1036
1186
|
}
|
|
1037
1187
|
eventStream$.complete();
|
|
1038
1188
|
});
|
|
@@ -1093,163 +1243,167 @@ var RemoteLangGraphEventSource = class {
|
|
|
1093
1243
|
}
|
|
1094
1244
|
return shouldEmitToolCalls === toolCallName;
|
|
1095
1245
|
}
|
|
1246
|
+
getCurrentContent(event) {
|
|
1247
|
+
var _a, _b, _c, _d, _e;
|
|
1248
|
+
const content = ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.content) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.content);
|
|
1249
|
+
if (!content) {
|
|
1250
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1251
|
+
for (const chunk of toolCallChunks) {
|
|
1252
|
+
if (chunk.args) {
|
|
1253
|
+
return chunk.args;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
if (typeof content === "string") {
|
|
1258
|
+
return content;
|
|
1259
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1260
|
+
return content[0].text;
|
|
1261
|
+
}
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
getCurrentMessageId(event) {
|
|
1265
|
+
var _a, _b, _c, _d, _e;
|
|
1266
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.id) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.id);
|
|
1267
|
+
}
|
|
1268
|
+
getCurrentToolCallChunks(event) {
|
|
1269
|
+
var _a, _b, _c, _d, _e;
|
|
1270
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.tool_call_chunks);
|
|
1271
|
+
}
|
|
1272
|
+
getResponseMetadata(event) {
|
|
1273
|
+
var _a, _b, _c, _d, _e;
|
|
1274
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.response_metadata) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.response_metadata);
|
|
1275
|
+
}
|
|
1096
1276
|
processLangGraphEvents() {
|
|
1097
1277
|
let lastEventWithState = null;
|
|
1098
1278
|
return this.eventStream$.pipe((0, import_rxjs.scan)((acc, event) => {
|
|
1099
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1100
1279
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1116
|
-
acc.toolCallMessageId = toolCallMessageId;
|
|
1117
|
-
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1118
|
-
acc.toolCallName = toolCallChunks[0].name;
|
|
1119
|
-
}
|
|
1120
|
-
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1121
|
-
acc.toolCallId = toolCallChunks[0].id;
|
|
1122
|
-
}
|
|
1123
|
-
acc.prevMessageId = acc.messageId;
|
|
1124
|
-
acc.messageId = toolCallMessageId;
|
|
1125
|
-
} else if (acc.content && acc.content != "") {
|
|
1126
|
-
acc.prevMessageId = acc.messageId;
|
|
1127
|
-
acc.messageId = toolCallMessageId;
|
|
1128
|
-
} else {
|
|
1129
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1130
|
-
acc.prevMessageId = acc.messageId;
|
|
1131
|
-
}
|
|
1132
|
-
} else {
|
|
1133
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1134
|
-
acc.toolCallMessageId = null;
|
|
1135
|
-
acc.prevMessageId = acc.messageId;
|
|
1136
|
-
acc.messageId = null;
|
|
1137
|
-
acc.toolCallName = null;
|
|
1280
|
+
const prevMessageId = acc.lastMessageId;
|
|
1281
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
1282
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1283
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1284
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
1285
|
+
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1286
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1287
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
1288
|
+
acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1289
|
+
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1290
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1291
|
+
name: acc.lastToolCallName,
|
|
1292
|
+
id: acc.lastToolCallId
|
|
1293
|
+
});
|
|
1138
1294
|
}
|
|
1139
1295
|
acc.event = event;
|
|
1140
1296
|
lastEventWithState = acc;
|
|
1141
1297
|
return acc;
|
|
1142
1298
|
}, {
|
|
1143
1299
|
event: null,
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1300
|
+
isMessageStart: false,
|
|
1301
|
+
isMessageEnd: false,
|
|
1302
|
+
isToolCallStart: false,
|
|
1303
|
+
isToolCallEnd: false,
|
|
1304
|
+
isToolCall: false,
|
|
1305
|
+
lastMessageId: null,
|
|
1306
|
+
lastToolCallId: null,
|
|
1307
|
+
lastToolCallName: null,
|
|
1308
|
+
currentContent: null
|
|
1309
|
+
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1153
1310
|
const events = [];
|
|
1154
1311
|
let shouldEmitMessages = true;
|
|
1155
|
-
let shouldEmitToolCalls =
|
|
1156
|
-
if (
|
|
1157
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1158
|
-
shouldEmitToolCalls =
|
|
1312
|
+
let shouldEmitToolCalls = true;
|
|
1313
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1314
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
1315
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
1159
1316
|
}
|
|
1160
|
-
if ("copilotkit:emit-messages" in (
|
|
1161
|
-
shouldEmitMessages =
|
|
1317
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
1318
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
1162
1319
|
}
|
|
1163
1320
|
}
|
|
1164
|
-
|
|
1321
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1322
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1165
1323
|
events.push({
|
|
1166
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1324
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1325
|
+
actionExecutionId: acc.lastToolCallId
|
|
1167
1326
|
});
|
|
1168
1327
|
}
|
|
1169
|
-
if (
|
|
1328
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1170
1329
|
events.push({
|
|
1171
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1330
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1331
|
+
messageId: acc.lastMessageId
|
|
1172
1332
|
});
|
|
1173
1333
|
}
|
|
1174
|
-
switch (
|
|
1334
|
+
switch (acc.event.event) {
|
|
1175
1335
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1176
|
-
if (
|
|
1336
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1177
1337
|
events.push({
|
|
1178
1338
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1179
|
-
messageId:
|
|
1339
|
+
messageId: acc.event.data.message_id
|
|
1180
1340
|
});
|
|
1181
1341
|
events.push({
|
|
1182
1342
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1183
|
-
|
|
1343
|
+
messageId: acc.event.data.message_id,
|
|
1344
|
+
content: acc.event.data.message
|
|
1184
1345
|
});
|
|
1185
1346
|
events.push({
|
|
1186
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1347
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1348
|
+
messageId: acc.event.data.message_id
|
|
1187
1349
|
});
|
|
1188
|
-
} else if (
|
|
1350
|
+
} else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1189
1351
|
events.push({
|
|
1190
1352
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1191
|
-
actionExecutionId:
|
|
1192
|
-
actionName:
|
|
1353
|
+
actionExecutionId: acc.event.data.id,
|
|
1354
|
+
actionName: acc.event.data.name,
|
|
1355
|
+
parentMessageId: acc.event.data.id
|
|
1193
1356
|
});
|
|
1194
1357
|
events.push({
|
|
1195
1358
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1196
|
-
|
|
1359
|
+
actionExecutionId: acc.event.data.id,
|
|
1360
|
+
args: JSON.stringify(acc.event.data.args)
|
|
1197
1361
|
});
|
|
1198
1362
|
events.push({
|
|
1199
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1363
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1364
|
+
actionExecutionId: acc.event.data.id
|
|
1200
1365
|
});
|
|
1201
1366
|
}
|
|
1202
1367
|
break;
|
|
1203
1368
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1204
1369
|
events.push({
|
|
1205
1370
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1206
|
-
threadId:
|
|
1207
|
-
role:
|
|
1208
|
-
agentName:
|
|
1209
|
-
nodeName:
|
|
1210
|
-
runId:
|
|
1211
|
-
active:
|
|
1212
|
-
state: JSON.stringify(
|
|
1213
|
-
running:
|
|
1371
|
+
threadId: acc.event.thread_id,
|
|
1372
|
+
role: acc.event.role,
|
|
1373
|
+
agentName: acc.event.agent_name,
|
|
1374
|
+
nodeName: acc.event.node_name,
|
|
1375
|
+
runId: acc.event.run_id,
|
|
1376
|
+
active: acc.event.active,
|
|
1377
|
+
state: JSON.stringify(acc.event.state),
|
|
1378
|
+
running: acc.event.running
|
|
1214
1379
|
});
|
|
1215
1380
|
break;
|
|
1216
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
1217
|
-
break;
|
|
1218
1381
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1219
|
-
if (
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
type: RuntimeEventTypes.TextMessageStart,
|
|
1232
|
-
messageId: eventWithState.messageId
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1382
|
+
if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1383
|
+
events.push({
|
|
1384
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1385
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1386
|
+
actionName: acc.lastToolCallName,
|
|
1387
|
+
parentMessageId: acc.lastMessageId
|
|
1388
|
+
});
|
|
1389
|
+
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1390
|
+
events.push({
|
|
1391
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1392
|
+
messageId: acc.lastMessageId
|
|
1393
|
+
});
|
|
1235
1394
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
events.push({
|
|
1249
|
-
type: RuntimeEventTypes.TextMessageContent,
|
|
1250
|
-
content
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1395
|
+
if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1396
|
+
events.push({
|
|
1397
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1398
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1399
|
+
args: acc.currentContent
|
|
1400
|
+
});
|
|
1401
|
+
} else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
1402
|
+
events.push({
|
|
1403
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1404
|
+
messageId: acc.lastMessageId,
|
|
1405
|
+
content: acc.currentContent
|
|
1406
|
+
});
|
|
1253
1407
|
}
|
|
1254
1408
|
break;
|
|
1255
1409
|
}
|
|
@@ -1257,14 +1411,16 @@ var RemoteLangGraphEventSource = class {
|
|
|
1257
1411
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1258
1412
|
console.error(error);
|
|
1259
1413
|
const events = [];
|
|
1260
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1414
|
+
if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
|
|
1261
1415
|
events.push({
|
|
1262
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1416
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1417
|
+
messageId: lastEventWithState.lastMessageId
|
|
1263
1418
|
});
|
|
1264
1419
|
}
|
|
1265
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1420
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
|
|
1266
1421
|
events.push({
|
|
1267
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1422
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1423
|
+
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1268
1424
|
});
|
|
1269
1425
|
}
|
|
1270
1426
|
const messageId = (0, import_shared6.randomId)();
|
|
@@ -1274,10 +1430,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1274
1430
|
});
|
|
1275
1431
|
events.push({
|
|
1276
1432
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1433
|
+
messageId,
|
|
1277
1434
|
content: "\u274C An error occurred. Please try again."
|
|
1278
1435
|
});
|
|
1279
1436
|
events.push({
|
|
1280
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1437
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1438
|
+
messageId
|
|
1281
1439
|
});
|
|
1282
1440
|
return events;
|
|
1283
1441
|
}));
|
|
@@ -1299,12 +1457,6 @@ var MessageRole;
|
|
|
1299
1457
|
MessageRole2["system"] = "system";
|
|
1300
1458
|
MessageRole2["tool"] = "tool";
|
|
1301
1459
|
})(MessageRole || (MessageRole = {}));
|
|
1302
|
-
var ActionExecutionScope;
|
|
1303
|
-
(function(ActionExecutionScope2) {
|
|
1304
|
-
ActionExecutionScope2["server"] = "server";
|
|
1305
|
-
ActionExecutionScope2["client"] = "client";
|
|
1306
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1307
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1308
1460
|
var CopilotRequestType;
|
|
1309
1461
|
(function(CopilotRequestType2) {
|
|
1310
1462
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1323,10 +1475,6 @@ var ActionInputAvailability;
|
|
|
1323
1475
|
name: "MessageRole",
|
|
1324
1476
|
description: "The role of the message"
|
|
1325
1477
|
});
|
|
1326
|
-
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1327
|
-
name: "ActionExecutionScope",
|
|
1328
|
-
description: "The scope of the action"
|
|
1329
|
-
});
|
|
1330
1478
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1331
1479
|
name: "CopilotRequestType",
|
|
1332
1480
|
description: "The type of Copilot request"
|
|
@@ -1364,8 +1512,6 @@ async function streamEvents(controller, args) {
|
|
|
1364
1512
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1365
1513
|
initialThreadId = initialThreadId.substring(3);
|
|
1366
1514
|
}
|
|
1367
|
-
const assistants = await client.assistants.search();
|
|
1368
|
-
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1369
1515
|
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1370
1516
|
if (initialThreadId === threadId) {
|
|
1371
1517
|
await client.threads.get(threadId);
|
|
@@ -1385,7 +1531,7 @@ async function streamEvents(controller, args) {
|
|
|
1385
1531
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1386
1532
|
let formattedMessages = [];
|
|
1387
1533
|
try {
|
|
1388
|
-
formattedMessages =
|
|
1534
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1389
1535
|
} catch (e) {
|
|
1390
1536
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1391
1537
|
}
|
|
@@ -1396,8 +1542,16 @@ async function streamEvents(controller, args) {
|
|
|
1396
1542
|
asNode: nodeName
|
|
1397
1543
|
});
|
|
1398
1544
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1545
|
+
let streamInfo = {
|
|
1546
|
+
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1547
|
+
};
|
|
1548
|
+
const assistants = await client.assistants.search();
|
|
1549
|
+
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1550
|
+
if (!retrievedAssistant) {
|
|
1551
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1552
|
+
...streamInfo,
|
|
1553
|
+
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1554
|
+
});
|
|
1401
1555
|
console.error(`
|
|
1402
1556
|
No agent found for the agent name specified in CopilotKit provider
|
|
1403
1557
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1407,6 +1561,7 @@ async function streamEvents(controller, args) {
|
|
|
1407
1561
|
`);
|
|
1408
1562
|
throw new Error("No agent id found");
|
|
1409
1563
|
}
|
|
1564
|
+
const assistantId = retrievedAssistant.assistant_id;
|
|
1410
1565
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1411
1566
|
const streamInput = mode === "start" ? state : null;
|
|
1412
1567
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1425,9 +1580,6 @@ async function streamEvents(controller, args) {
|
|
|
1425
1580
|
let latestStateValues = {};
|
|
1426
1581
|
let updatedState = state;
|
|
1427
1582
|
let manuallyEmittedState = null;
|
|
1428
|
-
let streamInfo = {
|
|
1429
|
-
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1430
|
-
};
|
|
1431
1583
|
try {
|
|
1432
1584
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1433
1585
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1440,7 +1592,6 @@ async function streamEvents(controller, args) {
|
|
|
1440
1592
|
].includes(chunk.event))
|
|
1441
1593
|
continue;
|
|
1442
1594
|
if (chunk.event === "error") {
|
|
1443
|
-
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1444
1595
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1445
1596
|
}
|
|
1446
1597
|
if (chunk.event === "values") {
|
|
@@ -1533,21 +1684,34 @@ async function streamEvents(controller, args) {
|
|
|
1533
1684
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1534
1685
|
state: state.values,
|
|
1535
1686
|
running: !shouldExit,
|
|
1536
|
-
active: false
|
|
1687
|
+
active: false,
|
|
1688
|
+
includeMessages: true
|
|
1537
1689
|
}));
|
|
1538
1690
|
return Promise.resolve();
|
|
1539
1691
|
} catch (e) {
|
|
1692
|
+
logger2.error(e);
|
|
1693
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1694
|
+
...streamInfo,
|
|
1695
|
+
error: e.message
|
|
1696
|
+
});
|
|
1540
1697
|
return Promise.resolve();
|
|
1541
1698
|
}
|
|
1542
1699
|
}
|
|
1543
1700
|
__name(streamEvents, "streamEvents");
|
|
1544
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1701
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
1702
|
+
if (!includeMessages) {
|
|
1703
|
+
state = Object.keys(state).reduce((acc, key) => {
|
|
1704
|
+
if (key !== "messages") {
|
|
1705
|
+
acc[key] = state[key];
|
|
1706
|
+
}
|
|
1707
|
+
return acc;
|
|
1708
|
+
}, {});
|
|
1709
|
+
} else {
|
|
1710
|
+
state = {
|
|
1711
|
+
...state,
|
|
1712
|
+
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1551
1715
|
return JSON.stringify({
|
|
1552
1716
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1553
1717
|
thread_id: threadId,
|
|
@@ -1555,7 +1719,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1555
1719
|
agent_name: agentName,
|
|
1556
1720
|
node_name: nodeName,
|
|
1557
1721
|
active,
|
|
1558
|
-
state
|
|
1722
|
+
state,
|
|
1559
1723
|
running,
|
|
1560
1724
|
role: "assistant"
|
|
1561
1725
|
}) + "\n";
|
|
@@ -1631,134 +1795,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1631
1795
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1632
1796
|
messages = messages.slice(1);
|
|
1633
1797
|
}
|
|
1634
|
-
const
|
|
1635
|
-
const existingMessageIds = new Set(
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1798
|
+
const existingMessages = state.messages || [];
|
|
1799
|
+
const existingMessageIds = new Set(existingMessages.map((message) => message.id));
|
|
1800
|
+
const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
|
|
1801
|
+
return {
|
|
1802
|
+
...state,
|
|
1803
|
+
messages: newMessages,
|
|
1804
|
+
copilotkit: {
|
|
1805
|
+
actions
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1810
|
+
function langchainMessagesToCopilotKit(messages) {
|
|
1811
|
+
const result = [];
|
|
1812
|
+
const tool_call_names = {};
|
|
1813
|
+
for (const message of messages) {
|
|
1814
|
+
if (message.type === "ai") {
|
|
1815
|
+
for (const tool_call of message.tool_calls) {
|
|
1816
|
+
tool_call_names[tool_call.id] = tool_call.name;
|
|
1817
|
+
}
|
|
1640
1818
|
}
|
|
1641
1819
|
}
|
|
1642
1820
|
for (const message of messages) {
|
|
1643
|
-
|
|
1644
|
-
|
|
1821
|
+
let content = message.content;
|
|
1822
|
+
if (content instanceof Array) {
|
|
1823
|
+
content = content[0];
|
|
1645
1824
|
}
|
|
1646
|
-
if (
|
|
1647
|
-
|
|
1825
|
+
if (content instanceof Object) {
|
|
1826
|
+
content = content.text;
|
|
1648
1827
|
}
|
|
1649
|
-
if (
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
} else {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1828
|
+
if (message.type === "human") {
|
|
1829
|
+
result.push({
|
|
1830
|
+
role: "user",
|
|
1831
|
+
content,
|
|
1832
|
+
id: message.id
|
|
1833
|
+
});
|
|
1834
|
+
} else if (message.type === "system") {
|
|
1835
|
+
result.push({
|
|
1836
|
+
role: "system",
|
|
1837
|
+
content,
|
|
1838
|
+
id: message.id
|
|
1839
|
+
});
|
|
1840
|
+
} else if (message.type === "ai") {
|
|
1841
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
1842
|
+
for (const tool_call of message.tool_calls) {
|
|
1843
|
+
result.push({
|
|
1844
|
+
id: tool_call.id,
|
|
1845
|
+
name: tool_call.name,
|
|
1846
|
+
arguments: tool_call.args,
|
|
1847
|
+
parentMessageId: message.id
|
|
1848
|
+
});
|
|
1663
1849
|
}
|
|
1850
|
+
} else {
|
|
1851
|
+
result.push({
|
|
1852
|
+
role: "assistant",
|
|
1853
|
+
content,
|
|
1854
|
+
id: message.id,
|
|
1855
|
+
parentMessageId: message.id
|
|
1856
|
+
});
|
|
1664
1857
|
}
|
|
1858
|
+
} else if (message.type === "tool") {
|
|
1859
|
+
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1860
|
+
result.push({
|
|
1861
|
+
actionExecutionId: message.tool_call_id,
|
|
1862
|
+
actionName,
|
|
1863
|
+
result: content,
|
|
1864
|
+
id: message.id
|
|
1865
|
+
});
|
|
1665
1866
|
}
|
|
1666
1867
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1868
|
+
const resultsDict = {};
|
|
1869
|
+
for (const msg of result) {
|
|
1870
|
+
if (msg.actionExecutionId) {
|
|
1871
|
+
resultsDict[msg.actionExecutionId] = msg;
|
|
1672
1872
|
}
|
|
1673
1873
|
}
|
|
1674
|
-
const
|
|
1675
|
-
for (
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1679
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1680
|
-
if (!nextMessage) {
|
|
1681
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1682
|
-
continue;
|
|
1683
|
-
}
|
|
1684
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1685
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1686
|
-
if (toolMessage) {
|
|
1687
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1688
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1689
|
-
continue;
|
|
1690
|
-
} else {
|
|
1691
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1692
|
-
continue;
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
correctedMessages.push(currentMessage);
|
|
1696
|
-
continue;
|
|
1874
|
+
const reorderedResult = [];
|
|
1875
|
+
for (const msg of result) {
|
|
1876
|
+
if (!("actionExecutionId" in msg)) {
|
|
1877
|
+
reorderedResult.push(msg);
|
|
1697
1878
|
}
|
|
1698
|
-
if ("
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1703
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1704
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1705
|
-
continue;
|
|
1879
|
+
if ("arguments" in msg) {
|
|
1880
|
+
const msgId = msg.id;
|
|
1881
|
+
if (msgId in resultsDict) {
|
|
1882
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1706
1883
|
}
|
|
1707
|
-
correctedMessages.push(currentMessage);
|
|
1708
|
-
continue;
|
|
1709
1884
|
}
|
|
1710
|
-
correctedMessages.push(currentMessage);
|
|
1711
1885
|
}
|
|
1712
|
-
return
|
|
1713
|
-
...state,
|
|
1714
|
-
messages: correctedMessages,
|
|
1715
|
-
copilotkit: {
|
|
1716
|
-
actions
|
|
1717
|
-
}
|
|
1718
|
-
};
|
|
1886
|
+
return reorderedResult;
|
|
1719
1887
|
}
|
|
1720
|
-
__name(
|
|
1721
|
-
function
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1888
|
+
__name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
|
|
1889
|
+
function copilotkitMessagesToLangChain(messages) {
|
|
1890
|
+
const result = [];
|
|
1891
|
+
const processedActionExecutions = /* @__PURE__ */ new Set();
|
|
1892
|
+
for (const message of messages) {
|
|
1893
|
+
if (message.isTextMessage()) {
|
|
1894
|
+
if (message.role === "user") {
|
|
1895
|
+
result.push({
|
|
1896
|
+
...message,
|
|
1897
|
+
role: MessageRole.user
|
|
1898
|
+
});
|
|
1899
|
+
} else if (message.role === "system") {
|
|
1900
|
+
result.push({
|
|
1901
|
+
...message,
|
|
1902
|
+
role: MessageRole.system
|
|
1903
|
+
});
|
|
1904
|
+
} else if (message.role === "assistant") {
|
|
1905
|
+
result.push({
|
|
1906
|
+
...message,
|
|
1907
|
+
role: MessageRole.assistant
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
continue;
|
|
1731
1911
|
}
|
|
1732
1912
|
if (message.isActionExecutionMessage()) {
|
|
1733
|
-
const
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1913
|
+
const messageId = message.parentMessageId ?? message.id;
|
|
1914
|
+
if (processedActionExecutions.has(messageId)) {
|
|
1915
|
+
continue;
|
|
1916
|
+
}
|
|
1917
|
+
processedActionExecutions.add(messageId);
|
|
1918
|
+
const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
|
|
1919
|
+
const tool_calls = relatedActionExecutions.map((m) => ({
|
|
1920
|
+
name: m.name,
|
|
1921
|
+
args: m.arguments,
|
|
1922
|
+
id: m.id
|
|
1923
|
+
}));
|
|
1924
|
+
result.push({
|
|
1925
|
+
id: messageId,
|
|
1926
|
+
type: "ActionExecutionMessage",
|
|
1740
1927
|
content: "",
|
|
1741
|
-
tool_calls
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
id: message.id
|
|
1746
|
-
};
|
|
1928
|
+
tool_calls,
|
|
1929
|
+
role: MessageRole.assistant
|
|
1930
|
+
});
|
|
1931
|
+
continue;
|
|
1747
1932
|
}
|
|
1748
1933
|
if (message.isResultMessage()) {
|
|
1749
|
-
|
|
1934
|
+
result.push({
|
|
1750
1935
|
type: message.type,
|
|
1751
1936
|
content: message.result,
|
|
1752
1937
|
id: message.id,
|
|
1753
1938
|
tool_call_id: message.actionExecutionId,
|
|
1754
1939
|
name: message.actionName,
|
|
1755
1940
|
role: MessageRole.tool
|
|
1756
|
-
};
|
|
1941
|
+
});
|
|
1942
|
+
continue;
|
|
1757
1943
|
}
|
|
1758
1944
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1759
|
-
}
|
|
1945
|
+
}
|
|
1946
|
+
return result;
|
|
1760
1947
|
}
|
|
1761
|
-
__name(
|
|
1948
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
1762
1949
|
|
|
1763
1950
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1764
1951
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1768,7 +1955,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1768
1955
|
parameters: [],
|
|
1769
1956
|
handler: async (_args) => {
|
|
1770
1957
|
},
|
|
1771
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1958
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1772
1959
|
var _a;
|
|
1773
1960
|
logger2.debug({
|
|
1774
1961
|
actionName: agent.name
|
|
@@ -1794,7 +1981,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1794
1981
|
agent,
|
|
1795
1982
|
threadId,
|
|
1796
1983
|
nodeName,
|
|
1797
|
-
messages
|
|
1984
|
+
messages: [
|
|
1985
|
+
...messages,
|
|
1986
|
+
...additionalMessages
|
|
1987
|
+
],
|
|
1798
1988
|
state,
|
|
1799
1989
|
properties: graphqlContext.properties,
|
|
1800
1990
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1822,6 +2012,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1822
2012
|
}
|
|
1823
2013
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1824
2014
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2015
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
1825
2016
|
const actions = json["actions"].map((action) => ({
|
|
1826
2017
|
name: action.name,
|
|
1827
2018
|
description: action.description,
|
|
@@ -1835,7 +2026,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1835
2026
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1836
2027
|
agentExecution: false,
|
|
1837
2028
|
type: "self-hosted",
|
|
1838
|
-
agentsAmount:
|
|
2029
|
+
agentsAmount: totalAgents
|
|
1839
2030
|
});
|
|
1840
2031
|
try {
|
|
1841
2032
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -1870,13 +2061,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1870
2061
|
}
|
|
1871
2062
|
}
|
|
1872
2063
|
}));
|
|
1873
|
-
const agents = json["agents"].map((agent) => ({
|
|
2064
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
1874
2065
|
name: agent.name,
|
|
1875
2066
|
description: agent.description,
|
|
1876
2067
|
parameters: [],
|
|
1877
2068
|
handler: async (_args) => {
|
|
1878
2069
|
},
|
|
1879
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2070
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1880
2071
|
var _a;
|
|
1881
2072
|
logger2.debug({
|
|
1882
2073
|
actionName: agent.name
|
|
@@ -1901,7 +2092,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1901
2092
|
name,
|
|
1902
2093
|
threadId,
|
|
1903
2094
|
nodeName,
|
|
1904
|
-
messages
|
|
2095
|
+
messages: [
|
|
2096
|
+
...messages,
|
|
2097
|
+
...additionalMessages
|
|
2098
|
+
],
|
|
1905
2099
|
state,
|
|
1906
2100
|
properties: graphqlContext.properties,
|
|
1907
2101
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1923,7 +2117,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1923
2117
|
streamResponse(response.body, eventSource.eventStream$);
|
|
1924
2118
|
return eventSource.processLangGraphEvents();
|
|
1925
2119
|
}
|
|
1926
|
-
}));
|
|
2120
|
+
})) : [];
|
|
1927
2121
|
return [
|
|
1928
2122
|
...actions,
|
|
1929
2123
|
...agents
|
|
@@ -2144,7 +2338,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2144
2338
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2145
2339
|
var telemetry_client_default = telemetryClient;
|
|
2146
2340
|
|
|
2341
|
+
// src/graphql/types/base/index.ts
|
|
2342
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2343
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2344
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2345
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2346
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2347
|
+
else
|
|
2348
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2349
|
+
if (d = decorators[i])
|
|
2350
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2351
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2352
|
+
}
|
|
2353
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2354
|
+
function _ts_metadata(k, v) {
|
|
2355
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2356
|
+
return Reflect.metadata(k, v);
|
|
2357
|
+
}
|
|
2358
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2359
|
+
var BaseMessageInput = class {
|
|
2360
|
+
id;
|
|
2361
|
+
createdAt;
|
|
2362
|
+
};
|
|
2363
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2364
|
+
_ts_decorate([
|
|
2365
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2366
|
+
_ts_metadata("design:type", String)
|
|
2367
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2368
|
+
_ts_decorate([
|
|
2369
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2370
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2371
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2372
|
+
BaseMessageInput = _ts_decorate([
|
|
2373
|
+
(0, import_type_graphql2.InputType)()
|
|
2374
|
+
], BaseMessageInput);
|
|
2375
|
+
|
|
2376
|
+
// src/graphql/types/converted/index.ts
|
|
2377
|
+
var Message = class extends BaseMessageInput {
|
|
2378
|
+
type;
|
|
2379
|
+
isTextMessage() {
|
|
2380
|
+
return this.type === "TextMessage";
|
|
2381
|
+
}
|
|
2382
|
+
isActionExecutionMessage() {
|
|
2383
|
+
return this.type === "ActionExecutionMessage";
|
|
2384
|
+
}
|
|
2385
|
+
isResultMessage() {
|
|
2386
|
+
return this.type === "ResultMessage";
|
|
2387
|
+
}
|
|
2388
|
+
isAgentStateMessage() {
|
|
2389
|
+
return this.type === "AgentStateMessage";
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
__name(Message, "Message");
|
|
2393
|
+
var TextMessage = class extends Message {
|
|
2394
|
+
type = "TextMessage";
|
|
2395
|
+
content;
|
|
2396
|
+
role;
|
|
2397
|
+
parentMessageId;
|
|
2398
|
+
};
|
|
2399
|
+
__name(TextMessage, "TextMessage");
|
|
2400
|
+
var ActionExecutionMessage = class extends Message {
|
|
2401
|
+
type = "ActionExecutionMessage";
|
|
2402
|
+
name;
|
|
2403
|
+
arguments;
|
|
2404
|
+
parentMessageId;
|
|
2405
|
+
};
|
|
2406
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2407
|
+
var ResultMessage = class extends Message {
|
|
2408
|
+
type = "ResultMessage";
|
|
2409
|
+
actionExecutionId;
|
|
2410
|
+
actionName;
|
|
2411
|
+
result;
|
|
2412
|
+
};
|
|
2413
|
+
__name(ResultMessage, "ResultMessage");
|
|
2414
|
+
var AgentStateMessage = class extends Message {
|
|
2415
|
+
type = "AgentStateMessage";
|
|
2416
|
+
threadId;
|
|
2417
|
+
agentName;
|
|
2418
|
+
nodeName;
|
|
2419
|
+
runId;
|
|
2420
|
+
active;
|
|
2421
|
+
role;
|
|
2422
|
+
state;
|
|
2423
|
+
running;
|
|
2424
|
+
};
|
|
2425
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2426
|
+
|
|
2147
2427
|
// src/service-adapters/events.ts
|
|
2428
|
+
var import_class_transformer = require("class-transformer");
|
|
2148
2429
|
var RuntimeEventTypes;
|
|
2149
2430
|
(function(RuntimeEventTypes2) {
|
|
2150
2431
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2160,52 +2441,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2160
2441
|
constructor() {
|
|
2161
2442
|
super();
|
|
2162
2443
|
}
|
|
2163
|
-
sendTextMessageStart(messageId) {
|
|
2444
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2164
2445
|
this.next({
|
|
2165
2446
|
type: "TextMessageStart",
|
|
2166
|
-
messageId
|
|
2447
|
+
messageId,
|
|
2448
|
+
parentMessageId
|
|
2167
2449
|
});
|
|
2168
2450
|
}
|
|
2169
|
-
sendTextMessageContent(content) {
|
|
2451
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2170
2452
|
this.next({
|
|
2171
2453
|
type: "TextMessageContent",
|
|
2172
|
-
content
|
|
2454
|
+
content,
|
|
2455
|
+
messageId
|
|
2173
2456
|
});
|
|
2174
2457
|
}
|
|
2175
|
-
sendTextMessageEnd() {
|
|
2458
|
+
sendTextMessageEnd({ messageId }) {
|
|
2176
2459
|
this.next({
|
|
2177
|
-
type: "TextMessageEnd"
|
|
2460
|
+
type: "TextMessageEnd",
|
|
2461
|
+
messageId
|
|
2178
2462
|
});
|
|
2179
2463
|
}
|
|
2180
2464
|
sendTextMessage(messageId, content) {
|
|
2181
|
-
this.sendTextMessageStart(
|
|
2182
|
-
|
|
2183
|
-
|
|
2465
|
+
this.sendTextMessageStart({
|
|
2466
|
+
messageId
|
|
2467
|
+
});
|
|
2468
|
+
this.sendTextMessageContent({
|
|
2469
|
+
messageId,
|
|
2470
|
+
content
|
|
2471
|
+
});
|
|
2472
|
+
this.sendTextMessageEnd({
|
|
2473
|
+
messageId
|
|
2474
|
+
});
|
|
2184
2475
|
}
|
|
2185
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2476
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2186
2477
|
this.next({
|
|
2187
2478
|
type: "ActionExecutionStart",
|
|
2188
2479
|
actionExecutionId,
|
|
2189
|
-
actionName
|
|
2480
|
+
actionName,
|
|
2481
|
+
parentMessageId
|
|
2190
2482
|
});
|
|
2191
2483
|
}
|
|
2192
|
-
sendActionExecutionArgs(args) {
|
|
2484
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2193
2485
|
this.next({
|
|
2194
2486
|
type: "ActionExecutionArgs",
|
|
2195
|
-
args
|
|
2487
|
+
args,
|
|
2488
|
+
actionExecutionId
|
|
2196
2489
|
});
|
|
2197
2490
|
}
|
|
2198
|
-
sendActionExecutionEnd() {
|
|
2491
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2199
2492
|
this.next({
|
|
2200
|
-
type: "ActionExecutionEnd"
|
|
2493
|
+
type: "ActionExecutionEnd",
|
|
2494
|
+
actionExecutionId
|
|
2201
2495
|
});
|
|
2202
2496
|
}
|
|
2203
|
-
sendActionExecution(actionExecutionId,
|
|
2204
|
-
this.sendActionExecutionStart(
|
|
2205
|
-
|
|
2206
|
-
|
|
2497
|
+
sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
|
|
2498
|
+
this.sendActionExecutionStart({
|
|
2499
|
+
actionExecutionId,
|
|
2500
|
+
actionName,
|
|
2501
|
+
parentMessageId
|
|
2502
|
+
});
|
|
2503
|
+
this.sendActionExecutionArgs({
|
|
2504
|
+
actionExecutionId,
|
|
2505
|
+
args
|
|
2506
|
+
});
|
|
2507
|
+
this.sendActionExecutionEnd({
|
|
2508
|
+
actionExecutionId
|
|
2509
|
+
});
|
|
2207
2510
|
}
|
|
2208
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2511
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2209
2512
|
this.next({
|
|
2210
2513
|
type: "ActionExecutionResult",
|
|
2211
2514
|
actionName,
|
|
@@ -2213,7 +2516,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2213
2516
|
result
|
|
2214
2517
|
});
|
|
2215
2518
|
}
|
|
2216
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2519
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2217
2520
|
this.next({
|
|
2218
2521
|
type: "AgentStateMessage",
|
|
2219
2522
|
threadId,
|
|
@@ -2234,8 +2537,8 @@ var RuntimeEventSource = class {
|
|
|
2234
2537
|
async stream(callback) {
|
|
2235
2538
|
this.callback = callback;
|
|
2236
2539
|
}
|
|
2237
|
-
sendErrorMessageToChat() {
|
|
2238
|
-
const errorMessage =
|
|
2540
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2541
|
+
const errorMessage = `\u274C ${message}`;
|
|
2239
2542
|
if (!this.callback) {
|
|
2240
2543
|
this.stream(async (eventStream$) => {
|
|
2241
2544
|
eventStream$.sendTextMessage((0, import_shared8.randomId)(), errorMessage);
|
|
@@ -2250,27 +2553,19 @@ var RuntimeEventSource = class {
|
|
|
2250
2553
|
this.sendErrorMessageToChat();
|
|
2251
2554
|
});
|
|
2252
2555
|
return this.eventStream$.pipe(
|
|
2253
|
-
// mark tools for server side execution
|
|
2254
|
-
(0, import_rxjs2.map)((event) => {
|
|
2255
|
-
if (event.type === "ActionExecutionStart") {
|
|
2256
|
-
if (event.scope !== "passThrough") {
|
|
2257
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
return event;
|
|
2261
|
-
}),
|
|
2262
2556
|
// track state
|
|
2263
2557
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2264
2558
|
acc = {
|
|
2265
2559
|
...acc
|
|
2266
2560
|
};
|
|
2267
2561
|
if (event.type === "ActionExecutionStart") {
|
|
2268
|
-
acc.callActionServerSide =
|
|
2562
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2269
2563
|
acc.args = "";
|
|
2270
2564
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2271
2565
|
if (acc.callActionServerSide) {
|
|
2272
2566
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2273
2567
|
}
|
|
2568
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2274
2569
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2275
2570
|
acc.args += event.args;
|
|
2276
2571
|
}
|
|
@@ -2281,12 +2576,13 @@ var RuntimeEventSource = class {
|
|
|
2281
2576
|
callActionServerSide: false,
|
|
2282
2577
|
args: "",
|
|
2283
2578
|
actionExecutionId: null,
|
|
2284
|
-
action: null
|
|
2579
|
+
action: null,
|
|
2580
|
+
actionExecutionParentMessageId: null
|
|
2285
2581
|
}),
|
|
2286
2582
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2287
2583
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2288
2584
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2289
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2585
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2290
2586
|
console.error(error);
|
|
2291
2587
|
});
|
|
2292
2588
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2299,7 +2595,7 @@ var RuntimeEventSource = class {
|
|
|
2299
2595
|
}
|
|
2300
2596
|
};
|
|
2301
2597
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2302
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2598
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2303
2599
|
var _a;
|
|
2304
2600
|
if (guardrailsResult$) {
|
|
2305
2601
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2319,10 +2615,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2319
2615
|
}
|
|
2320
2616
|
}
|
|
2321
2617
|
if (isLangGraphAgentAction(action)) {
|
|
2322
|
-
|
|
2618
|
+
const result = `${action.name} agent started`;
|
|
2619
|
+
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2620
|
+
id: actionExecutionId,
|
|
2621
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2622
|
+
name: action.name,
|
|
2623
|
+
arguments: JSON.parse(actionArguments),
|
|
2624
|
+
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2625
|
+
});
|
|
2626
|
+
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2627
|
+
id: "result-" + actionExecutionId,
|
|
2628
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2629
|
+
actionExecutionId,
|
|
2630
|
+
actionName: action.name,
|
|
2631
|
+
result
|
|
2632
|
+
});
|
|
2633
|
+
eventStream$.sendActionExecutionResult({
|
|
2634
|
+
actionExecutionId,
|
|
2635
|
+
actionName: action.name,
|
|
2636
|
+
result
|
|
2637
|
+
});
|
|
2323
2638
|
const stream = await action.langGraphAgentHandler({
|
|
2324
2639
|
name: action.name,
|
|
2325
|
-
actionInputsWithoutAgents
|
|
2640
|
+
actionInputsWithoutAgents,
|
|
2641
|
+
additionalMessages: [
|
|
2642
|
+
agentExecution,
|
|
2643
|
+
agentExecutionResult
|
|
2644
|
+
]
|
|
2326
2645
|
});
|
|
2327
2646
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2328
2647
|
next: (event) => eventStream$.next(event),
|
|
@@ -2343,113 +2662,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2343
2662
|
}
|
|
2344
2663
|
__name(executeAction, "executeAction");
|
|
2345
2664
|
|
|
2346
|
-
// src/graphql/types/base/index.ts
|
|
2347
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2348
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2349
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2350
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2351
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2352
|
-
else
|
|
2353
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2354
|
-
if (d = decorators[i])
|
|
2355
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2356
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2357
|
-
}
|
|
2358
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2359
|
-
function _ts_metadata(k, v) {
|
|
2360
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2361
|
-
return Reflect.metadata(k, v);
|
|
2362
|
-
}
|
|
2363
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2364
|
-
var BaseMessageInput = class {
|
|
2365
|
-
id;
|
|
2366
|
-
createdAt;
|
|
2367
|
-
};
|
|
2368
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2369
|
-
_ts_decorate([
|
|
2370
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2371
|
-
_ts_metadata("design:type", String)
|
|
2372
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2373
|
-
_ts_decorate([
|
|
2374
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2375
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2376
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2377
|
-
BaseMessageInput = _ts_decorate([
|
|
2378
|
-
(0, import_type_graphql2.InputType)()
|
|
2379
|
-
], BaseMessageInput);
|
|
2380
|
-
|
|
2381
|
-
// src/graphql/types/converted/index.ts
|
|
2382
|
-
var Message = class extends BaseMessageInput {
|
|
2383
|
-
type;
|
|
2384
|
-
isTextMessage() {
|
|
2385
|
-
return this.type === "TextMessage";
|
|
2386
|
-
}
|
|
2387
|
-
isActionExecutionMessage() {
|
|
2388
|
-
return this.type === "ActionExecutionMessage";
|
|
2389
|
-
}
|
|
2390
|
-
isResultMessage() {
|
|
2391
|
-
return this.type === "ResultMessage";
|
|
2392
|
-
}
|
|
2393
|
-
isAgentStateMessage() {
|
|
2394
|
-
return this.type === "AgentStateMessage";
|
|
2395
|
-
}
|
|
2396
|
-
};
|
|
2397
|
-
__name(Message, "Message");
|
|
2398
|
-
var TextMessage = class extends Message {
|
|
2399
|
-
type = "TextMessage";
|
|
2400
|
-
content;
|
|
2401
|
-
role;
|
|
2402
|
-
};
|
|
2403
|
-
__name(TextMessage, "TextMessage");
|
|
2404
|
-
var ActionExecutionMessage = class extends Message {
|
|
2405
|
-
type = "ActionExecutionMessage";
|
|
2406
|
-
name;
|
|
2407
|
-
arguments;
|
|
2408
|
-
scope;
|
|
2409
|
-
};
|
|
2410
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2411
|
-
var ResultMessage = class extends Message {
|
|
2412
|
-
type = "ResultMessage";
|
|
2413
|
-
actionExecutionId;
|
|
2414
|
-
actionName;
|
|
2415
|
-
result;
|
|
2416
|
-
};
|
|
2417
|
-
__name(ResultMessage, "ResultMessage");
|
|
2418
|
-
var AgentStateMessage = class extends Message {
|
|
2419
|
-
type = "AgentStateMessage";
|
|
2420
|
-
threadId;
|
|
2421
|
-
agentName;
|
|
2422
|
-
nodeName;
|
|
2423
|
-
runId;
|
|
2424
|
-
active;
|
|
2425
|
-
role;
|
|
2426
|
-
state;
|
|
2427
|
-
running;
|
|
2428
|
-
};
|
|
2429
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2430
|
-
|
|
2431
2665
|
// src/service-adapters/conversion.ts
|
|
2432
|
-
var
|
|
2666
|
+
var import_class_transformer2 = require("class-transformer");
|
|
2433
2667
|
function convertGqlInputToMessages(inputMessages) {
|
|
2434
2668
|
const messages = [];
|
|
2435
2669
|
for (const message of inputMessages) {
|
|
2436
2670
|
if (message.textMessage) {
|
|
2437
|
-
messages.push((0,
|
|
2671
|
+
messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2438
2672
|
id: message.id,
|
|
2439
2673
|
createdAt: message.createdAt,
|
|
2440
2674
|
role: message.textMessage.role,
|
|
2441
|
-
content: message.textMessage.content
|
|
2675
|
+
content: message.textMessage.content,
|
|
2676
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2442
2677
|
}));
|
|
2443
2678
|
} else if (message.actionExecutionMessage) {
|
|
2444
|
-
messages.push((0,
|
|
2679
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2445
2680
|
id: message.id,
|
|
2446
2681
|
createdAt: message.createdAt,
|
|
2447
2682
|
name: message.actionExecutionMessage.name,
|
|
2448
2683
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2449
|
-
|
|
2684
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2450
2685
|
}));
|
|
2451
2686
|
} else if (message.resultMessage) {
|
|
2452
|
-
messages.push((0,
|
|
2687
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2453
2688
|
id: message.id,
|
|
2454
2689
|
createdAt: message.createdAt,
|
|
2455
2690
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2457,7 +2692,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2457
2692
|
result: message.resultMessage.result
|
|
2458
2693
|
}));
|
|
2459
2694
|
} else if (message.agentStateMessage) {
|
|
2460
|
-
messages.push((0,
|
|
2695
|
+
messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
2461
2696
|
id: message.id,
|
|
2462
2697
|
threadId: message.agentStateMessage.threadId,
|
|
2463
2698
|
createdAt: message.createdAt,
|
|
@@ -2557,13 +2792,7 @@ var CopilotRuntime = class {
|
|
|
2557
2792
|
} catch (error) {
|
|
2558
2793
|
console.error("Error getting response:", error);
|
|
2559
2794
|
eventSource.sendErrorMessageToChat();
|
|
2560
|
-
|
|
2561
|
-
threadId: threadId || (0, import_shared9.randomId)(),
|
|
2562
|
-
runId: runId || (0, import_shared9.randomId)(),
|
|
2563
|
-
eventSource,
|
|
2564
|
-
serverSideActions: [],
|
|
2565
|
-
actionInputsWithoutAgents: []
|
|
2566
|
-
};
|
|
2795
|
+
throw error;
|
|
2567
2796
|
}
|
|
2568
2797
|
}
|
|
2569
2798
|
async processAgentRequest(request) {
|
|
@@ -2766,6 +2995,7 @@ MessageInput = _ts_decorate2([
|
|
|
2766
2995
|
], MessageInput);
|
|
2767
2996
|
var TextMessageInput = class {
|
|
2768
2997
|
content;
|
|
2998
|
+
parentMessageId;
|
|
2769
2999
|
role;
|
|
2770
3000
|
};
|
|
2771
3001
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -2773,6 +3003,12 @@ _ts_decorate2([
|
|
|
2773
3003
|
(0, import_type_graphql3.Field)(() => String),
|
|
2774
3004
|
_ts_metadata2("design:type", String)
|
|
2775
3005
|
], TextMessageInput.prototype, "content", void 0);
|
|
3006
|
+
_ts_decorate2([
|
|
3007
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3008
|
+
nullable: true
|
|
3009
|
+
}),
|
|
3010
|
+
_ts_metadata2("design:type", String)
|
|
3011
|
+
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
2776
3012
|
_ts_decorate2([
|
|
2777
3013
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
2778
3014
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -2783,6 +3019,7 @@ TextMessageInput = _ts_decorate2([
|
|
|
2783
3019
|
var ActionExecutionMessageInput = class {
|
|
2784
3020
|
name;
|
|
2785
3021
|
arguments;
|
|
3022
|
+
parentMessageId;
|
|
2786
3023
|
scope;
|
|
2787
3024
|
};
|
|
2788
3025
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -2795,8 +3032,17 @@ _ts_decorate2([
|
|
|
2795
3032
|
_ts_metadata2("design:type", String)
|
|
2796
3033
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
2797
3034
|
_ts_decorate2([
|
|
2798
|
-
(0, import_type_graphql3.Field)(() =>
|
|
2799
|
-
|
|
3035
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3036
|
+
nullable: true
|
|
3037
|
+
}),
|
|
3038
|
+
_ts_metadata2("design:type", String)
|
|
3039
|
+
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3040
|
+
_ts_decorate2([
|
|
3041
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3042
|
+
nullable: true,
|
|
3043
|
+
deprecationReason: "This field will be removed in a future version"
|
|
3044
|
+
}),
|
|
3045
|
+
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
2800
3046
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
2801
3047
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
2802
3048
|
(0, import_type_graphql3.InputType)()
|
|
@@ -2804,6 +3050,7 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
2804
3050
|
var ResultMessageInput = class {
|
|
2805
3051
|
actionExecutionId;
|
|
2806
3052
|
actionName;
|
|
3053
|
+
parentMessageId;
|
|
2807
3054
|
result;
|
|
2808
3055
|
};
|
|
2809
3056
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -2815,6 +3062,12 @@ _ts_decorate2([
|
|
|
2815
3062
|
(0, import_type_graphql3.Field)(() => String),
|
|
2816
3063
|
_ts_metadata2("design:type", String)
|
|
2817
3064
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3065
|
+
_ts_decorate2([
|
|
3066
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3067
|
+
nullable: true
|
|
3068
|
+
}),
|
|
3069
|
+
_ts_metadata2("design:type", String)
|
|
3070
|
+
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
2818
3071
|
_ts_decorate2([
|
|
2819
3072
|
(0, import_type_graphql3.Field)(() => String),
|
|
2820
3073
|
_ts_metadata2("design:type", String)
|
|
@@ -3537,6 +3790,7 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3537
3790
|
var TextMessageOutput = class {
|
|
3538
3791
|
role;
|
|
3539
3792
|
content;
|
|
3793
|
+
parentMessageId;
|
|
3540
3794
|
};
|
|
3541
3795
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3542
3796
|
_ts_decorate13([
|
|
@@ -3549,6 +3803,12 @@ _ts_decorate13([
|
|
|
3549
3803
|
]),
|
|
3550
3804
|
_ts_metadata13("design:type", Array)
|
|
3551
3805
|
], TextMessageOutput.prototype, "content", void 0);
|
|
3806
|
+
_ts_decorate13([
|
|
3807
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
3808
|
+
nullable: true
|
|
3809
|
+
}),
|
|
3810
|
+
_ts_metadata13("design:type", String)
|
|
3811
|
+
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
3552
3812
|
TextMessageOutput = _ts_decorate13([
|
|
3553
3813
|
(0, import_type_graphql14.ObjectType)({
|
|
3554
3814
|
implements: BaseMessageOutput
|
|
@@ -3558,6 +3818,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
3558
3818
|
name;
|
|
3559
3819
|
scope;
|
|
3560
3820
|
arguments;
|
|
3821
|
+
parentMessageId;
|
|
3561
3822
|
};
|
|
3562
3823
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3563
3824
|
_ts_decorate13([
|
|
@@ -3565,8 +3826,11 @@ _ts_decorate13([
|
|
|
3565
3826
|
_ts_metadata13("design:type", String)
|
|
3566
3827
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3567
3828
|
_ts_decorate13([
|
|
3568
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3569
|
-
|
|
3829
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
3830
|
+
nullable: true,
|
|
3831
|
+
deprecationReason: "This field will be removed in a future version"
|
|
3832
|
+
}),
|
|
3833
|
+
_ts_metadata13("design:type", String)
|
|
3570
3834
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3571
3835
|
_ts_decorate13([
|
|
3572
3836
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3574,6 +3838,12 @@ _ts_decorate13([
|
|
|
3574
3838
|
]),
|
|
3575
3839
|
_ts_metadata13("design:type", Array)
|
|
3576
3840
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
3841
|
+
_ts_decorate13([
|
|
3842
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
3843
|
+
nullable: true
|
|
3844
|
+
}),
|
|
3845
|
+
_ts_metadata13("design:type", String)
|
|
3846
|
+
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
3577
3847
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3578
3848
|
(0, import_type_graphql14.ObjectType)({
|
|
3579
3849
|
implements: BaseMessageOutput
|
|
@@ -3684,7 +3954,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3684
3954
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3685
3955
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3686
3956
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3687
|
-
var
|
|
3957
|
+
var import_class_transformer3 = require("class-transformer");
|
|
3688
3958
|
var import_graphql = require("graphql");
|
|
3689
3959
|
|
|
3690
3960
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -3882,7 +4152,7 @@ var CopilotResolver = class {
|
|
|
3882
4152
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
3883
4153
|
});
|
|
3884
4154
|
outputMessages = [
|
|
3885
|
-
(0,
|
|
4155
|
+
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
3886
4156
|
id: (0, import_shared10.randomId)(),
|
|
3887
4157
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3888
4158
|
content: result.reason,
|
|
@@ -3931,12 +4201,15 @@ var CopilotResolver = class {
|
|
|
3931
4201
|
// skip until this message start event
|
|
3932
4202
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
3933
4203
|
// take until the message end event
|
|
3934
|
-
(0, import_rxjs4.takeWhile)((e) => e.type
|
|
4204
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
4205
|
+
// filter out any other message events or message ids
|
|
4206
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
3935
4207
|
);
|
|
3936
4208
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
3937
4209
|
const messageId = event.messageId;
|
|
3938
4210
|
pushMessage({
|
|
3939
4211
|
id: messageId,
|
|
4212
|
+
parentMessageId: event.parentMessageId,
|
|
3940
4213
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
3941
4214
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3942
4215
|
role: MessageRole.assistant,
|
|
@@ -3949,7 +4222,7 @@ var CopilotResolver = class {
|
|
|
3949
4222
|
reason,
|
|
3950
4223
|
messageId: messageId2
|
|
3951
4224
|
}, "Text streaming interrupted");
|
|
3952
|
-
streamingTextStatus.next((0,
|
|
4225
|
+
streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
3953
4226
|
reason
|
|
3954
4227
|
}));
|
|
3955
4228
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -3982,7 +4255,7 @@ var CopilotResolver = class {
|
|
|
3982
4255
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
3983
4256
|
stopStreamingText();
|
|
3984
4257
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
3985
|
-
outputMessages.push((0,
|
|
4258
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
3986
4259
|
id: messageId,
|
|
3987
4260
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3988
4261
|
content: textChunks.join(""),
|
|
@@ -3995,14 +4268,20 @@ var CopilotResolver = class {
|
|
|
3995
4268
|
break;
|
|
3996
4269
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
3997
4270
|
logger2.debug("Action execution start event received");
|
|
3998
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4271
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4272
|
+
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4273
|
+
// take until the action execution end event
|
|
4274
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4275
|
+
// filter out any other action execution events or action execution ids
|
|
4276
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4277
|
+
);
|
|
3999
4278
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4000
4279
|
pushMessage({
|
|
4001
4280
|
id: event.actionExecutionId,
|
|
4281
|
+
parentMessageId: event.parentMessageId,
|
|
4002
4282
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4003
4283
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4004
4284
|
name: event.actionName,
|
|
4005
|
-
scope: event.scope,
|
|
4006
4285
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4007
4286
|
logger2.debug("Action execution argument stream created");
|
|
4008
4287
|
const argumentChunks = [];
|
|
@@ -4018,7 +4297,7 @@ var CopilotResolver = class {
|
|
|
4018
4297
|
logger2.error({
|
|
4019
4298
|
err
|
|
4020
4299
|
}, "Error in action execution argument stream");
|
|
4021
|
-
streamingArgumentsStatus.next((0,
|
|
4300
|
+
streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4022
4301
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4023
4302
|
}));
|
|
4024
4303
|
stopStreamingArguments();
|
|
@@ -4029,11 +4308,10 @@ var CopilotResolver = class {
|
|
|
4029
4308
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4030
4309
|
stopStreamingArguments();
|
|
4031
4310
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4032
|
-
outputMessages.push((0,
|
|
4311
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
|
|
4033
4312
|
id: event.actionExecutionId,
|
|
4034
4313
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4035
4314
|
name: event.actionName,
|
|
4036
|
-
scope: event.scope,
|
|
4037
4315
|
arguments: argumentChunks.join("")
|
|
4038
4316
|
}));
|
|
4039
4317
|
}
|
|
@@ -4046,15 +4324,15 @@ var CopilotResolver = class {
|
|
|
4046
4324
|
result: event.result
|
|
4047
4325
|
}, "Action execution result event received");
|
|
4048
4326
|
pushMessage({
|
|
4049
|
-
id:
|
|
4327
|
+
id: "result-" + event.actionExecutionId,
|
|
4050
4328
|
status: new SuccessMessageStatus(),
|
|
4051
4329
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4052
4330
|
actionExecutionId: event.actionExecutionId,
|
|
4053
4331
|
actionName: event.actionName,
|
|
4054
4332
|
result: event.result
|
|
4055
4333
|
});
|
|
4056
|
-
outputMessages.push((0,
|
|
4057
|
-
id:
|
|
4334
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
|
|
4335
|
+
id: "result-" + event.actionExecutionId,
|
|
4058
4336
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4059
4337
|
actionExecutionId: event.actionExecutionId,
|
|
4060
4338
|
actionName: event.actionName,
|
|
@@ -4078,7 +4356,7 @@ var CopilotResolver = class {
|
|
|
4078
4356
|
role: MessageRole.assistant,
|
|
4079
4357
|
createdAt: /* @__PURE__ */ new Date()
|
|
4080
4358
|
});
|
|
4081
|
-
outputMessages.push((0,
|
|
4359
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
4082
4360
|
id: (0, import_shared10.randomId)(),
|
|
4083
4361
|
threadId: event.threadId,
|
|
4084
4362
|
agentName: event.agentName,
|