@copilotkit/runtime 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -5
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-APVJZO3R.mjs → chunk-7BOO3OFP.mjs} +2 -2
- package/dist/{chunk-OSWF5QDO.mjs → chunk-GSTWFOZF.mjs} +2 -2
- package/dist/{chunk-M74ZTUCC.mjs → chunk-OMAAKIJQ.mjs} +2 -2
- package/dist/{chunk-36AYTJIE.mjs → chunk-PXS4SBRF.mjs} +447 -321
- package/dist/chunk-PXS4SBRF.mjs.map +1 -0
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +824 -473
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +729 -452
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +79 -31
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +79 -31
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +79 -31
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +79 -31
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/logger.ts +4 -0
- package/src/lib/runtime/copilot-runtime.ts +1 -7
- package/src/lib/runtime/remote-action-constructors.ts +64 -58
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +159 -140
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-36AYTJIE.mjs.map +0 -1
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-APVJZO3R.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
- /package/dist/{chunk-OSWF5QDO.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
- /package/dist/{chunk-M74ZTUCC.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
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.
|
|
47
|
+
version: "1.5.0-coagents-v0-3.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"
|
|
@@ -1383,7 +1531,7 @@ async function streamEvents(controller, args) {
|
|
|
1383
1531
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1384
1532
|
let formattedMessages = [];
|
|
1385
1533
|
try {
|
|
1386
|
-
formattedMessages =
|
|
1534
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1387
1535
|
} catch (e) {
|
|
1388
1536
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1389
1537
|
}
|
|
@@ -1536,7 +1684,8 @@ async function streamEvents(controller, args) {
|
|
|
1536
1684
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1537
1685
|
state: state.values,
|
|
1538
1686
|
running: !shouldExit,
|
|
1539
|
-
active: false
|
|
1687
|
+
active: false,
|
|
1688
|
+
includeMessages: true
|
|
1540
1689
|
}));
|
|
1541
1690
|
return Promise.resolve();
|
|
1542
1691
|
} catch (e) {
|
|
@@ -1549,13 +1698,20 @@ async function streamEvents(controller, args) {
|
|
|
1549
1698
|
}
|
|
1550
1699
|
}
|
|
1551
1700
|
__name(streamEvents, "streamEvents");
|
|
1552
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
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
|
+
}
|
|
1559
1715
|
return JSON.stringify({
|
|
1560
1716
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1561
1717
|
thread_id: threadId,
|
|
@@ -1563,7 +1719,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1563
1719
|
agent_name: agentName,
|
|
1564
1720
|
node_name: nodeName,
|
|
1565
1721
|
active,
|
|
1566
|
-
state
|
|
1722
|
+
state,
|
|
1567
1723
|
running,
|
|
1568
1724
|
role: "assistant"
|
|
1569
1725
|
}) + "\n";
|
|
@@ -1639,134 +1795,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1639
1795
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1640
1796
|
messages = messages.slice(1);
|
|
1641
1797
|
}
|
|
1642
|
-
const
|
|
1643
|
-
const existingMessageIds = new Set(
|
|
1644
|
-
const
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
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
|
+
}
|
|
1648
1818
|
}
|
|
1649
1819
|
}
|
|
1650
1820
|
for (const message of messages) {
|
|
1651
|
-
|
|
1652
|
-
|
|
1821
|
+
let content = message.content;
|
|
1822
|
+
if (content instanceof Array) {
|
|
1823
|
+
content = content[0];
|
|
1653
1824
|
}
|
|
1654
|
-
if (
|
|
1655
|
-
|
|
1825
|
+
if (content instanceof Object) {
|
|
1826
|
+
content = content.text;
|
|
1656
1827
|
}
|
|
1657
|
-
if (
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
} else {
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
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
|
+
});
|
|
1671
1849
|
}
|
|
1850
|
+
} else {
|
|
1851
|
+
result.push({
|
|
1852
|
+
role: "assistant",
|
|
1853
|
+
content,
|
|
1854
|
+
id: message.id,
|
|
1855
|
+
parentMessageId: message.id
|
|
1856
|
+
});
|
|
1672
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
|
+
});
|
|
1673
1866
|
}
|
|
1674
1867
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
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;
|
|
1680
1872
|
}
|
|
1681
1873
|
}
|
|
1682
|
-
const
|
|
1683
|
-
for (
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1687
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1688
|
-
if (!nextMessage) {
|
|
1689
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1690
|
-
continue;
|
|
1691
|
-
}
|
|
1692
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1693
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1694
|
-
if (toolMessage) {
|
|
1695
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1696
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1697
|
-
continue;
|
|
1698
|
-
} else {
|
|
1699
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1700
|
-
continue;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
correctedMessages.push(currentMessage);
|
|
1704
|
-
continue;
|
|
1874
|
+
const reorderedResult = [];
|
|
1875
|
+
for (const msg of result) {
|
|
1876
|
+
if (!("actionExecutionId" in msg)) {
|
|
1877
|
+
reorderedResult.push(msg);
|
|
1705
1878
|
}
|
|
1706
|
-
if ("
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
}
|
|
1711
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1712
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1713
|
-
continue;
|
|
1879
|
+
if ("arguments" in msg) {
|
|
1880
|
+
const msgId = msg.id;
|
|
1881
|
+
if (msgId in resultsDict) {
|
|
1882
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1714
1883
|
}
|
|
1715
|
-
correctedMessages.push(currentMessage);
|
|
1716
|
-
continue;
|
|
1717
1884
|
}
|
|
1718
|
-
correctedMessages.push(currentMessage);
|
|
1719
1885
|
}
|
|
1720
|
-
return
|
|
1721
|
-
...state,
|
|
1722
|
-
messages: correctedMessages,
|
|
1723
|
-
copilotkit: {
|
|
1724
|
-
actions
|
|
1725
|
-
}
|
|
1726
|
-
};
|
|
1886
|
+
return reorderedResult;
|
|
1727
1887
|
}
|
|
1728
|
-
__name(
|
|
1729
|
-
function
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
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;
|
|
1739
1911
|
}
|
|
1740
1912
|
if (message.isActionExecutionMessage()) {
|
|
1741
|
-
const
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
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",
|
|
1748
1927
|
content: "",
|
|
1749
|
-
tool_calls
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
id: message.id
|
|
1754
|
-
};
|
|
1928
|
+
tool_calls,
|
|
1929
|
+
role: MessageRole.assistant
|
|
1930
|
+
});
|
|
1931
|
+
continue;
|
|
1755
1932
|
}
|
|
1756
1933
|
if (message.isResultMessage()) {
|
|
1757
|
-
|
|
1934
|
+
result.push({
|
|
1758
1935
|
type: message.type,
|
|
1759
1936
|
content: message.result,
|
|
1760
1937
|
id: message.id,
|
|
1761
1938
|
tool_call_id: message.actionExecutionId,
|
|
1762
1939
|
name: message.actionName,
|
|
1763
1940
|
role: MessageRole.tool
|
|
1764
|
-
};
|
|
1941
|
+
});
|
|
1942
|
+
continue;
|
|
1765
1943
|
}
|
|
1766
1944
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1767
|
-
}
|
|
1945
|
+
}
|
|
1946
|
+
return result;
|
|
1768
1947
|
}
|
|
1769
|
-
__name(
|
|
1948
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
1770
1949
|
|
|
1771
1950
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1772
1951
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1776,7 +1955,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1776
1955
|
parameters: [],
|
|
1777
1956
|
handler: async (_args) => {
|
|
1778
1957
|
},
|
|
1779
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1958
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1780
1959
|
var _a;
|
|
1781
1960
|
logger2.debug({
|
|
1782
1961
|
actionName: agent.name
|
|
@@ -1802,7 +1981,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1802
1981
|
agent,
|
|
1803
1982
|
threadId,
|
|
1804
1983
|
nodeName,
|
|
1805
|
-
messages
|
|
1984
|
+
messages: [
|
|
1985
|
+
...messages,
|
|
1986
|
+
...additionalMessages
|
|
1987
|
+
],
|
|
1806
1988
|
state,
|
|
1807
1989
|
properties: graphqlContext.properties,
|
|
1808
1990
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1830,6 +2012,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1830
2012
|
}
|
|
1831
2013
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1832
2014
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2015
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
1833
2016
|
const actions = json["actions"].map((action) => ({
|
|
1834
2017
|
name: action.name,
|
|
1835
2018
|
description: action.description,
|
|
@@ -1843,7 +2026,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1843
2026
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1844
2027
|
agentExecution: false,
|
|
1845
2028
|
type: "self-hosted",
|
|
1846
|
-
agentsAmount:
|
|
2029
|
+
agentsAmount: totalAgents
|
|
1847
2030
|
});
|
|
1848
2031
|
try {
|
|
1849
2032
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -1878,13 +2061,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1878
2061
|
}
|
|
1879
2062
|
}
|
|
1880
2063
|
}));
|
|
1881
|
-
const agents = json["agents"].map((agent) => ({
|
|
2064
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
1882
2065
|
name: agent.name,
|
|
1883
2066
|
description: agent.description,
|
|
1884
2067
|
parameters: [],
|
|
1885
2068
|
handler: async (_args) => {
|
|
1886
2069
|
},
|
|
1887
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2070
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1888
2071
|
var _a;
|
|
1889
2072
|
logger2.debug({
|
|
1890
2073
|
actionName: agent.name
|
|
@@ -1909,7 +2092,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1909
2092
|
name,
|
|
1910
2093
|
threadId,
|
|
1911
2094
|
nodeName,
|
|
1912
|
-
messages
|
|
2095
|
+
messages: [
|
|
2096
|
+
...messages,
|
|
2097
|
+
...additionalMessages
|
|
2098
|
+
],
|
|
1913
2099
|
state,
|
|
1914
2100
|
properties: graphqlContext.properties,
|
|
1915
2101
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1931,7 +2117,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1931
2117
|
streamResponse(response.body, eventSource.eventStream$);
|
|
1932
2118
|
return eventSource.processLangGraphEvents();
|
|
1933
2119
|
}
|
|
1934
|
-
}));
|
|
2120
|
+
})) : [];
|
|
1935
2121
|
return [
|
|
1936
2122
|
...actions,
|
|
1937
2123
|
...agents
|
|
@@ -2152,7 +2338,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2152
2338
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2153
2339
|
var telemetry_client_default = telemetryClient;
|
|
2154
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
|
+
|
|
2155
2427
|
// src/service-adapters/events.ts
|
|
2428
|
+
var import_class_transformer = require("class-transformer");
|
|
2156
2429
|
var RuntimeEventTypes;
|
|
2157
2430
|
(function(RuntimeEventTypes2) {
|
|
2158
2431
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2168,52 +2441,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2168
2441
|
constructor() {
|
|
2169
2442
|
super();
|
|
2170
2443
|
}
|
|
2171
|
-
sendTextMessageStart(messageId) {
|
|
2444
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2172
2445
|
this.next({
|
|
2173
2446
|
type: "TextMessageStart",
|
|
2174
|
-
messageId
|
|
2447
|
+
messageId,
|
|
2448
|
+
parentMessageId
|
|
2175
2449
|
});
|
|
2176
2450
|
}
|
|
2177
|
-
sendTextMessageContent(content) {
|
|
2451
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2178
2452
|
this.next({
|
|
2179
2453
|
type: "TextMessageContent",
|
|
2180
|
-
content
|
|
2454
|
+
content,
|
|
2455
|
+
messageId
|
|
2181
2456
|
});
|
|
2182
2457
|
}
|
|
2183
|
-
sendTextMessageEnd() {
|
|
2458
|
+
sendTextMessageEnd({ messageId }) {
|
|
2184
2459
|
this.next({
|
|
2185
|
-
type: "TextMessageEnd"
|
|
2460
|
+
type: "TextMessageEnd",
|
|
2461
|
+
messageId
|
|
2186
2462
|
});
|
|
2187
2463
|
}
|
|
2188
2464
|
sendTextMessage(messageId, content) {
|
|
2189
|
-
this.sendTextMessageStart(
|
|
2190
|
-
|
|
2191
|
-
|
|
2465
|
+
this.sendTextMessageStart({
|
|
2466
|
+
messageId
|
|
2467
|
+
});
|
|
2468
|
+
this.sendTextMessageContent({
|
|
2469
|
+
messageId,
|
|
2470
|
+
content
|
|
2471
|
+
});
|
|
2472
|
+
this.sendTextMessageEnd({
|
|
2473
|
+
messageId
|
|
2474
|
+
});
|
|
2192
2475
|
}
|
|
2193
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2476
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2194
2477
|
this.next({
|
|
2195
2478
|
type: "ActionExecutionStart",
|
|
2196
2479
|
actionExecutionId,
|
|
2197
|
-
actionName
|
|
2480
|
+
actionName,
|
|
2481
|
+
parentMessageId
|
|
2198
2482
|
});
|
|
2199
2483
|
}
|
|
2200
|
-
sendActionExecutionArgs(args) {
|
|
2484
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2201
2485
|
this.next({
|
|
2202
2486
|
type: "ActionExecutionArgs",
|
|
2203
|
-
args
|
|
2487
|
+
args,
|
|
2488
|
+
actionExecutionId
|
|
2204
2489
|
});
|
|
2205
2490
|
}
|
|
2206
|
-
sendActionExecutionEnd() {
|
|
2491
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2207
2492
|
this.next({
|
|
2208
|
-
type: "ActionExecutionEnd"
|
|
2493
|
+
type: "ActionExecutionEnd",
|
|
2494
|
+
actionExecutionId
|
|
2209
2495
|
});
|
|
2210
2496
|
}
|
|
2211
|
-
sendActionExecution(actionExecutionId,
|
|
2212
|
-
this.sendActionExecutionStart(
|
|
2213
|
-
|
|
2214
|
-
|
|
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
|
+
});
|
|
2215
2510
|
}
|
|
2216
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2511
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2217
2512
|
this.next({
|
|
2218
2513
|
type: "ActionExecutionResult",
|
|
2219
2514
|
actionName,
|
|
@@ -2221,7 +2516,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2221
2516
|
result
|
|
2222
2517
|
});
|
|
2223
2518
|
}
|
|
2224
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2519
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2225
2520
|
this.next({
|
|
2226
2521
|
type: "AgentStateMessage",
|
|
2227
2522
|
threadId,
|
|
@@ -2242,8 +2537,8 @@ var RuntimeEventSource = class {
|
|
|
2242
2537
|
async stream(callback) {
|
|
2243
2538
|
this.callback = callback;
|
|
2244
2539
|
}
|
|
2245
|
-
sendErrorMessageToChat() {
|
|
2246
|
-
const errorMessage =
|
|
2540
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2541
|
+
const errorMessage = `\u274C ${message}`;
|
|
2247
2542
|
if (!this.callback) {
|
|
2248
2543
|
this.stream(async (eventStream$) => {
|
|
2249
2544
|
eventStream$.sendTextMessage((0, import_shared8.randomId)(), errorMessage);
|
|
@@ -2258,27 +2553,19 @@ var RuntimeEventSource = class {
|
|
|
2258
2553
|
this.sendErrorMessageToChat();
|
|
2259
2554
|
});
|
|
2260
2555
|
return this.eventStream$.pipe(
|
|
2261
|
-
// mark tools for server side execution
|
|
2262
|
-
(0, import_rxjs2.map)((event) => {
|
|
2263
|
-
if (event.type === "ActionExecutionStart") {
|
|
2264
|
-
if (event.scope !== "passThrough") {
|
|
2265
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
return event;
|
|
2269
|
-
}),
|
|
2270
2556
|
// track state
|
|
2271
2557
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2272
2558
|
acc = {
|
|
2273
2559
|
...acc
|
|
2274
2560
|
};
|
|
2275
2561
|
if (event.type === "ActionExecutionStart") {
|
|
2276
|
-
acc.callActionServerSide =
|
|
2562
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2277
2563
|
acc.args = "";
|
|
2278
2564
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2279
2565
|
if (acc.callActionServerSide) {
|
|
2280
2566
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2281
2567
|
}
|
|
2568
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2282
2569
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2283
2570
|
acc.args += event.args;
|
|
2284
2571
|
}
|
|
@@ -2289,12 +2576,13 @@ var RuntimeEventSource = class {
|
|
|
2289
2576
|
callActionServerSide: false,
|
|
2290
2577
|
args: "",
|
|
2291
2578
|
actionExecutionId: null,
|
|
2292
|
-
action: null
|
|
2579
|
+
action: null,
|
|
2580
|
+
actionExecutionParentMessageId: null
|
|
2293
2581
|
}),
|
|
2294
2582
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2295
2583
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2296
2584
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2297
|
-
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) => {
|
|
2298
2586
|
console.error(error);
|
|
2299
2587
|
});
|
|
2300
2588
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2307,7 +2595,7 @@ var RuntimeEventSource = class {
|
|
|
2307
2595
|
}
|
|
2308
2596
|
};
|
|
2309
2597
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2310
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2598
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2311
2599
|
var _a;
|
|
2312
2600
|
if (guardrailsResult$) {
|
|
2313
2601
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2327,10 +2615,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2327
2615
|
}
|
|
2328
2616
|
}
|
|
2329
2617
|
if (isLangGraphAgentAction(action)) {
|
|
2330
|
-
|
|
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
|
+
});
|
|
2331
2638
|
const stream = await action.langGraphAgentHandler({
|
|
2332
2639
|
name: action.name,
|
|
2333
|
-
actionInputsWithoutAgents
|
|
2640
|
+
actionInputsWithoutAgents,
|
|
2641
|
+
additionalMessages: [
|
|
2642
|
+
agentExecution,
|
|
2643
|
+
agentExecutionResult
|
|
2644
|
+
]
|
|
2334
2645
|
});
|
|
2335
2646
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2336
2647
|
next: (event) => eventStream$.next(event),
|
|
@@ -2351,113 +2662,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2351
2662
|
}
|
|
2352
2663
|
__name(executeAction, "executeAction");
|
|
2353
2664
|
|
|
2354
|
-
// src/graphql/types/base/index.ts
|
|
2355
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2356
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2357
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2358
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2359
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2360
|
-
else
|
|
2361
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2362
|
-
if (d = decorators[i])
|
|
2363
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2364
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2365
|
-
}
|
|
2366
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2367
|
-
function _ts_metadata(k, v) {
|
|
2368
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2369
|
-
return Reflect.metadata(k, v);
|
|
2370
|
-
}
|
|
2371
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2372
|
-
var BaseMessageInput = class {
|
|
2373
|
-
id;
|
|
2374
|
-
createdAt;
|
|
2375
|
-
};
|
|
2376
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2377
|
-
_ts_decorate([
|
|
2378
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2379
|
-
_ts_metadata("design:type", String)
|
|
2380
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2381
|
-
_ts_decorate([
|
|
2382
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2383
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2384
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2385
|
-
BaseMessageInput = _ts_decorate([
|
|
2386
|
-
(0, import_type_graphql2.InputType)()
|
|
2387
|
-
], BaseMessageInput);
|
|
2388
|
-
|
|
2389
|
-
// src/graphql/types/converted/index.ts
|
|
2390
|
-
var Message = class extends BaseMessageInput {
|
|
2391
|
-
type;
|
|
2392
|
-
isTextMessage() {
|
|
2393
|
-
return this.type === "TextMessage";
|
|
2394
|
-
}
|
|
2395
|
-
isActionExecutionMessage() {
|
|
2396
|
-
return this.type === "ActionExecutionMessage";
|
|
2397
|
-
}
|
|
2398
|
-
isResultMessage() {
|
|
2399
|
-
return this.type === "ResultMessage";
|
|
2400
|
-
}
|
|
2401
|
-
isAgentStateMessage() {
|
|
2402
|
-
return this.type === "AgentStateMessage";
|
|
2403
|
-
}
|
|
2404
|
-
};
|
|
2405
|
-
__name(Message, "Message");
|
|
2406
|
-
var TextMessage = class extends Message {
|
|
2407
|
-
type = "TextMessage";
|
|
2408
|
-
content;
|
|
2409
|
-
role;
|
|
2410
|
-
};
|
|
2411
|
-
__name(TextMessage, "TextMessage");
|
|
2412
|
-
var ActionExecutionMessage = class extends Message {
|
|
2413
|
-
type = "ActionExecutionMessage";
|
|
2414
|
-
name;
|
|
2415
|
-
arguments;
|
|
2416
|
-
scope;
|
|
2417
|
-
};
|
|
2418
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2419
|
-
var ResultMessage = class extends Message {
|
|
2420
|
-
type = "ResultMessage";
|
|
2421
|
-
actionExecutionId;
|
|
2422
|
-
actionName;
|
|
2423
|
-
result;
|
|
2424
|
-
};
|
|
2425
|
-
__name(ResultMessage, "ResultMessage");
|
|
2426
|
-
var AgentStateMessage = class extends Message {
|
|
2427
|
-
type = "AgentStateMessage";
|
|
2428
|
-
threadId;
|
|
2429
|
-
agentName;
|
|
2430
|
-
nodeName;
|
|
2431
|
-
runId;
|
|
2432
|
-
active;
|
|
2433
|
-
role;
|
|
2434
|
-
state;
|
|
2435
|
-
running;
|
|
2436
|
-
};
|
|
2437
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2438
|
-
|
|
2439
2665
|
// src/service-adapters/conversion.ts
|
|
2440
|
-
var
|
|
2666
|
+
var import_class_transformer2 = require("class-transformer");
|
|
2441
2667
|
function convertGqlInputToMessages(inputMessages) {
|
|
2442
2668
|
const messages = [];
|
|
2443
2669
|
for (const message of inputMessages) {
|
|
2444
2670
|
if (message.textMessage) {
|
|
2445
|
-
messages.push((0,
|
|
2671
|
+
messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2446
2672
|
id: message.id,
|
|
2447
2673
|
createdAt: message.createdAt,
|
|
2448
2674
|
role: message.textMessage.role,
|
|
2449
|
-
content: message.textMessage.content
|
|
2675
|
+
content: message.textMessage.content,
|
|
2676
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2450
2677
|
}));
|
|
2451
2678
|
} else if (message.actionExecutionMessage) {
|
|
2452
|
-
messages.push((0,
|
|
2679
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2453
2680
|
id: message.id,
|
|
2454
2681
|
createdAt: message.createdAt,
|
|
2455
2682
|
name: message.actionExecutionMessage.name,
|
|
2456
2683
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2457
|
-
|
|
2684
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2458
2685
|
}));
|
|
2459
2686
|
} else if (message.resultMessage) {
|
|
2460
|
-
messages.push((0,
|
|
2687
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2461
2688
|
id: message.id,
|
|
2462
2689
|
createdAt: message.createdAt,
|
|
2463
2690
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2465,7 +2692,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2465
2692
|
result: message.resultMessage.result
|
|
2466
2693
|
}));
|
|
2467
2694
|
} else if (message.agentStateMessage) {
|
|
2468
|
-
messages.push((0,
|
|
2695
|
+
messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
2469
2696
|
id: message.id,
|
|
2470
2697
|
threadId: message.agentStateMessage.threadId,
|
|
2471
2698
|
createdAt: message.createdAt,
|
|
@@ -2565,13 +2792,7 @@ var CopilotRuntime = class {
|
|
|
2565
2792
|
} catch (error) {
|
|
2566
2793
|
console.error("Error getting response:", error);
|
|
2567
2794
|
eventSource.sendErrorMessageToChat();
|
|
2568
|
-
|
|
2569
|
-
threadId: threadId || (0, import_shared9.randomId)(),
|
|
2570
|
-
runId: runId || (0, import_shared9.randomId)(),
|
|
2571
|
-
eventSource,
|
|
2572
|
-
serverSideActions: [],
|
|
2573
|
-
actionInputsWithoutAgents: []
|
|
2574
|
-
};
|
|
2795
|
+
throw error;
|
|
2575
2796
|
}
|
|
2576
2797
|
}
|
|
2577
2798
|
async processAgentRequest(request) {
|
|
@@ -2774,6 +2995,7 @@ MessageInput = _ts_decorate2([
|
|
|
2774
2995
|
], MessageInput);
|
|
2775
2996
|
var TextMessageInput = class {
|
|
2776
2997
|
content;
|
|
2998
|
+
parentMessageId;
|
|
2777
2999
|
role;
|
|
2778
3000
|
};
|
|
2779
3001
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -2781,6 +3003,12 @@ _ts_decorate2([
|
|
|
2781
3003
|
(0, import_type_graphql3.Field)(() => String),
|
|
2782
3004
|
_ts_metadata2("design:type", String)
|
|
2783
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);
|
|
2784
3012
|
_ts_decorate2([
|
|
2785
3013
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
2786
3014
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -2791,6 +3019,7 @@ TextMessageInput = _ts_decorate2([
|
|
|
2791
3019
|
var ActionExecutionMessageInput = class {
|
|
2792
3020
|
name;
|
|
2793
3021
|
arguments;
|
|
3022
|
+
parentMessageId;
|
|
2794
3023
|
scope;
|
|
2795
3024
|
};
|
|
2796
3025
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -2803,8 +3032,17 @@ _ts_decorate2([
|
|
|
2803
3032
|
_ts_metadata2("design:type", String)
|
|
2804
3033
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
2805
3034
|
_ts_decorate2([
|
|
2806
|
-
(0, import_type_graphql3.Field)(() =>
|
|
2807
|
-
|
|
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)
|
|
2808
3046
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
2809
3047
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
2810
3048
|
(0, import_type_graphql3.InputType)()
|
|
@@ -2812,6 +3050,7 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
2812
3050
|
var ResultMessageInput = class {
|
|
2813
3051
|
actionExecutionId;
|
|
2814
3052
|
actionName;
|
|
3053
|
+
parentMessageId;
|
|
2815
3054
|
result;
|
|
2816
3055
|
};
|
|
2817
3056
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -2823,6 +3062,12 @@ _ts_decorate2([
|
|
|
2823
3062
|
(0, import_type_graphql3.Field)(() => String),
|
|
2824
3063
|
_ts_metadata2("design:type", String)
|
|
2825
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);
|
|
2826
3071
|
_ts_decorate2([
|
|
2827
3072
|
(0, import_type_graphql3.Field)(() => String),
|
|
2828
3073
|
_ts_metadata2("design:type", String)
|
|
@@ -3545,6 +3790,7 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3545
3790
|
var TextMessageOutput = class {
|
|
3546
3791
|
role;
|
|
3547
3792
|
content;
|
|
3793
|
+
parentMessageId;
|
|
3548
3794
|
};
|
|
3549
3795
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3550
3796
|
_ts_decorate13([
|
|
@@ -3557,6 +3803,12 @@ _ts_decorate13([
|
|
|
3557
3803
|
]),
|
|
3558
3804
|
_ts_metadata13("design:type", Array)
|
|
3559
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);
|
|
3560
3812
|
TextMessageOutput = _ts_decorate13([
|
|
3561
3813
|
(0, import_type_graphql14.ObjectType)({
|
|
3562
3814
|
implements: BaseMessageOutput
|
|
@@ -3566,6 +3818,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
3566
3818
|
name;
|
|
3567
3819
|
scope;
|
|
3568
3820
|
arguments;
|
|
3821
|
+
parentMessageId;
|
|
3569
3822
|
};
|
|
3570
3823
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3571
3824
|
_ts_decorate13([
|
|
@@ -3573,8 +3826,11 @@ _ts_decorate13([
|
|
|
3573
3826
|
_ts_metadata13("design:type", String)
|
|
3574
3827
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3575
3828
|
_ts_decorate13([
|
|
3576
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3577
|
-
|
|
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)
|
|
3578
3834
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3579
3835
|
_ts_decorate13([
|
|
3580
3836
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3582,6 +3838,12 @@ _ts_decorate13([
|
|
|
3582
3838
|
]),
|
|
3583
3839
|
_ts_metadata13("design:type", Array)
|
|
3584
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);
|
|
3585
3847
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3586
3848
|
(0, import_type_graphql14.ObjectType)({
|
|
3587
3849
|
implements: BaseMessageOutput
|
|
@@ -3692,7 +3954,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3692
3954
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3693
3955
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3694
3956
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3695
|
-
var
|
|
3957
|
+
var import_class_transformer3 = require("class-transformer");
|
|
3696
3958
|
var import_graphql = require("graphql");
|
|
3697
3959
|
|
|
3698
3960
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -3890,7 +4152,7 @@ var CopilotResolver = class {
|
|
|
3890
4152
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
3891
4153
|
});
|
|
3892
4154
|
outputMessages = [
|
|
3893
|
-
(0,
|
|
4155
|
+
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
3894
4156
|
id: (0, import_shared10.randomId)(),
|
|
3895
4157
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3896
4158
|
content: result.reason,
|
|
@@ -3939,12 +4201,15 @@ var CopilotResolver = class {
|
|
|
3939
4201
|
// skip until this message start event
|
|
3940
4202
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
3941
4203
|
// take until the message end event
|
|
3942
|
-
(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)
|
|
3943
4207
|
);
|
|
3944
4208
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
3945
4209
|
const messageId = event.messageId;
|
|
3946
4210
|
pushMessage({
|
|
3947
4211
|
id: messageId,
|
|
4212
|
+
parentMessageId: event.parentMessageId,
|
|
3948
4213
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
3949
4214
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3950
4215
|
role: MessageRole.assistant,
|
|
@@ -3957,7 +4222,7 @@ var CopilotResolver = class {
|
|
|
3957
4222
|
reason,
|
|
3958
4223
|
messageId: messageId2
|
|
3959
4224
|
}, "Text streaming interrupted");
|
|
3960
|
-
streamingTextStatus.next((0,
|
|
4225
|
+
streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
3961
4226
|
reason
|
|
3962
4227
|
}));
|
|
3963
4228
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -3990,7 +4255,7 @@ var CopilotResolver = class {
|
|
|
3990
4255
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
3991
4256
|
stopStreamingText();
|
|
3992
4257
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
3993
|
-
outputMessages.push((0,
|
|
4258
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
3994
4259
|
id: messageId,
|
|
3995
4260
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3996
4261
|
content: textChunks.join(""),
|
|
@@ -4003,14 +4268,20 @@ var CopilotResolver = class {
|
|
|
4003
4268
|
break;
|
|
4004
4269
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4005
4270
|
logger2.debug("Action execution start event received");
|
|
4006
|
-
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
|
+
);
|
|
4007
4278
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4008
4279
|
pushMessage({
|
|
4009
4280
|
id: event.actionExecutionId,
|
|
4281
|
+
parentMessageId: event.parentMessageId,
|
|
4010
4282
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4011
4283
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4012
4284
|
name: event.actionName,
|
|
4013
|
-
scope: event.scope,
|
|
4014
4285
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4015
4286
|
logger2.debug("Action execution argument stream created");
|
|
4016
4287
|
const argumentChunks = [];
|
|
@@ -4026,7 +4297,7 @@ var CopilotResolver = class {
|
|
|
4026
4297
|
logger2.error({
|
|
4027
4298
|
err
|
|
4028
4299
|
}, "Error in action execution argument stream");
|
|
4029
|
-
streamingArgumentsStatus.next((0,
|
|
4300
|
+
streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4030
4301
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4031
4302
|
}));
|
|
4032
4303
|
stopStreamingArguments();
|
|
@@ -4037,11 +4308,10 @@ var CopilotResolver = class {
|
|
|
4037
4308
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4038
4309
|
stopStreamingArguments();
|
|
4039
4310
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4040
|
-
outputMessages.push((0,
|
|
4311
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
|
|
4041
4312
|
id: event.actionExecutionId,
|
|
4042
4313
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4043
4314
|
name: event.actionName,
|
|
4044
|
-
scope: event.scope,
|
|
4045
4315
|
arguments: argumentChunks.join("")
|
|
4046
4316
|
}));
|
|
4047
4317
|
}
|
|
@@ -4054,15 +4324,15 @@ var CopilotResolver = class {
|
|
|
4054
4324
|
result: event.result
|
|
4055
4325
|
}, "Action execution result event received");
|
|
4056
4326
|
pushMessage({
|
|
4057
|
-
id:
|
|
4327
|
+
id: "result-" + event.actionExecutionId,
|
|
4058
4328
|
status: new SuccessMessageStatus(),
|
|
4059
4329
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4060
4330
|
actionExecutionId: event.actionExecutionId,
|
|
4061
4331
|
actionName: event.actionName,
|
|
4062
4332
|
result: event.result
|
|
4063
4333
|
});
|
|
4064
|
-
outputMessages.push((0,
|
|
4065
|
-
id:
|
|
4334
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
|
|
4335
|
+
id: "result-" + event.actionExecutionId,
|
|
4066
4336
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4067
4337
|
actionExecutionId: event.actionExecutionId,
|
|
4068
4338
|
actionName: event.actionName,
|
|
@@ -4086,7 +4356,7 @@ var CopilotResolver = class {
|
|
|
4086
4356
|
role: MessageRole.assistant,
|
|
4087
4357
|
createdAt: /* @__PURE__ */ new Date()
|
|
4088
4358
|
});
|
|
4089
|
-
outputMessages.push((0,
|
|
4359
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
4090
4360
|
id: (0, import_shared10.randomId)(),
|
|
4091
4361
|
threadId: event.threadId,
|
|
4092
4362
|
agentName: event.agentName,
|
|
@@ -4168,7 +4438,14 @@ function createLogger(options) {
|
|
|
4168
4438
|
colorize: true
|
|
4169
4439
|
});
|
|
4170
4440
|
const logger2 = (0, import_pino.default)({
|
|
4171
|
-
level: process.env.LOG_LEVEL || level || "error"
|
|
4441
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
4442
|
+
redact: {
|
|
4443
|
+
paths: [
|
|
4444
|
+
"pid",
|
|
4445
|
+
"hostname"
|
|
4446
|
+
],
|
|
4447
|
+
remove: true
|
|
4448
|
+
}
|
|
4172
4449
|
}, stream);
|
|
4173
4450
|
if (component) {
|
|
4174
4451
|
return logger2.child({
|