@copilotkit/runtime 1.4.8-coagents-v0-3.1 → 1.4.8-next.1
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 +5 -4
- package/__snapshots__/schema/schema.graphql +10 -7
- package/dist/{chunk-FVYNRYIB.mjs → chunk-5KJYPVQJ.mjs} +307 -423
- package/dist/chunk-5KJYPVQJ.mjs.map +1 -0
- package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
- package/dist/chunk-B74M7FXG.mjs.map +1 -0
- package/dist/{chunk-BACNNHHI.mjs → chunk-CGGI46KC.mjs} +2 -2
- package/dist/{chunk-YFG3Q3YH.mjs → chunk-EU52BTKR.mjs} +2 -2
- package/dist/{chunk-MQJNZYAH.mjs → chunk-KO4QCMY4.mjs} +2 -2
- package/dist/{chunk-2PK2SFRB.mjs → chunk-W7GP2EOT.mjs} +106 -221
- package/dist/chunk-W7GP2EOT.mjs.map +1 -0
- package/dist/{copilot-runtime-b15b683d.d.ts → copilot-runtime-1c5bf72b.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +1 -2
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-50aa9621.d.ts → groq-adapter-b6a40422.d.ts} +1 -1
- package/dist/{index-ff3fbc33.d.ts → index-10b1c870.d.ts} +8 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +515 -745
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-8ec29cba.d.ts → langserve-6245df39.d.ts} +14 -52
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +442 -706
- 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 +37 -71
- 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 +37 -71
- 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 +37 -71
- 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 +37 -71
- 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 +106 -219
- 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 +148 -140
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/forwarded-parameters.input.ts +3 -0
- package/src/graphql/inputs/message.input.ts +3 -15
- package/src/graphql/resolvers/copilot.resolver.ts +6 -32
- package/src/graphql/types/converted/index.ts +3 -4
- package/src/graphql/types/copilot-response.type.ts +3 -12
- package/src/graphql/types/enums.ts +11 -0
- package/src/lib/runtime/remote-action-constructors.ts +62 -60
- package/src/lib/runtime/remote-actions.ts +0 -1
- package/src/lib/runtime/remote-lg-action.ts +140 -161
- package/src/service-adapters/anthropic/anthropic-adapter.ts +6 -16
- package/src/service-adapters/conversion.ts +1 -2
- package/src/service-adapters/events.ts +52 -111
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -7
- package/src/service-adapters/groq/groq-adapter.ts +8 -23
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +31 -49
- package/src/service-adapters/openai/openai-adapter.ts +9 -22
- package/src/service-adapters/openai/openai-assistant-adapter.ts +8 -22
- package/src/service-adapters/unify/unify-adapter.ts +11 -28
- package/dist/chunk-2PK2SFRB.mjs.map +0 -1
- package/dist/chunk-FVYNRYIB.mjs.map +0 -1
- package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
- /package/dist/{chunk-BACNNHHI.mjs.map → chunk-CGGI46KC.mjs.map} +0 -0
- /package/dist/{chunk-YFG3Q3YH.mjs.map → chunk-EU52BTKR.mjs.map} +0 -0
- /package/dist/{chunk-MQJNZYAH.mjs.map → chunk-KO4QCMY4.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.4.8-
|
|
47
|
+
version: "1.4.8-next.1",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -424,8 +424,6 @@ 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;
|
|
429
427
|
for await (const chunk of stream) {
|
|
430
428
|
if (chunk.choices.length === 0) {
|
|
431
429
|
continue;
|
|
@@ -434,52 +432,30 @@ var OpenAIAdapter = class {
|
|
|
434
432
|
const content = chunk.choices[0].delta.content;
|
|
435
433
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
436
434
|
mode = null;
|
|
437
|
-
eventStream$.sendTextMessageEnd(
|
|
438
|
-
messageId: currentMessageId
|
|
439
|
-
});
|
|
435
|
+
eventStream$.sendTextMessageEnd();
|
|
440
436
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
441
437
|
mode = null;
|
|
442
|
-
eventStream$.sendActionExecutionEnd(
|
|
443
|
-
actionExecutionId: currentToolCallId
|
|
444
|
-
});
|
|
438
|
+
eventStream$.sendActionExecutionEnd();
|
|
445
439
|
}
|
|
446
440
|
if (mode === null) {
|
|
447
441
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
448
442
|
mode = "function";
|
|
449
|
-
|
|
450
|
-
eventStream$.sendActionExecutionStart({
|
|
451
|
-
actionExecutionId: currentToolCallId,
|
|
452
|
-
parentMessageId: chunk.id,
|
|
453
|
-
actionName: toolCall.function.name
|
|
454
|
-
});
|
|
443
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
455
444
|
} else if (content) {
|
|
456
445
|
mode = "message";
|
|
457
|
-
|
|
458
|
-
eventStream$.sendTextMessageStart({
|
|
459
|
-
messageId: currentMessageId
|
|
460
|
-
});
|
|
446
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
461
447
|
}
|
|
462
448
|
}
|
|
463
449
|
if (mode === "message" && content) {
|
|
464
|
-
eventStream$.sendTextMessageContent(
|
|
465
|
-
messageId: currentMessageId,
|
|
466
|
-
content
|
|
467
|
-
});
|
|
450
|
+
eventStream$.sendTextMessageContent(content);
|
|
468
451
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
469
|
-
eventStream$.sendActionExecutionArgs(
|
|
470
|
-
actionExecutionId: currentToolCallId,
|
|
471
|
-
args: toolCall.function.arguments
|
|
472
|
-
});
|
|
452
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
473
453
|
}
|
|
474
454
|
}
|
|
475
455
|
if (mode === "message") {
|
|
476
|
-
eventStream$.sendTextMessageEnd(
|
|
477
|
-
messageId: currentMessageId
|
|
478
|
-
});
|
|
456
|
+
eventStream$.sendTextMessageEnd();
|
|
479
457
|
} else if (mode === "function") {
|
|
480
|
-
eventStream$.sendActionExecutionEnd(
|
|
481
|
-
actionExecutionId: currentToolCallId
|
|
482
|
-
});
|
|
458
|
+
eventStream$.sendActionExecutionEnd();
|
|
483
459
|
}
|
|
484
460
|
eventStream$.complete();
|
|
485
461
|
});
|
|
@@ -547,25 +523,17 @@ function isBaseMessageChunk(message) {
|
|
|
547
523
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
548
524
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
549
525
|
if (actionExecution) {
|
|
550
|
-
eventStream$.sendActionExecutionResult(
|
|
551
|
-
actionExecutionId: actionExecution.id,
|
|
552
|
-
actionName: actionExecution.name,
|
|
553
|
-
result: "Sending a message"
|
|
554
|
-
});
|
|
526
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
555
527
|
}
|
|
556
528
|
}
|
|
557
529
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
558
530
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
559
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
531
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
560
532
|
if (typeof result === "string") {
|
|
561
533
|
if (!actionExecution) {
|
|
562
534
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
563
535
|
} else {
|
|
564
|
-
eventStream$.sendActionExecutionResult(
|
|
565
|
-
actionExecutionId: actionExecution.id,
|
|
566
|
-
actionName: actionExecution.name,
|
|
567
|
-
result
|
|
568
|
-
});
|
|
536
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
569
537
|
}
|
|
570
538
|
} else if (isAIMessage(result)) {
|
|
571
539
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -573,11 +541,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
573
541
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
574
542
|
}
|
|
575
543
|
for (const toolCall of result.tool_calls) {
|
|
576
|
-
eventStream$.sendActionExecution(
|
|
577
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
578
|
-
actionName: toolCall.name,
|
|
579
|
-
args: JSON.stringify(toolCall.args)
|
|
580
|
-
});
|
|
544
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
581
545
|
}
|
|
582
546
|
} else if (isBaseMessageChunk(result)) {
|
|
583
547
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -586,18 +550,13 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
586
550
|
}
|
|
587
551
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
588
552
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
589
|
-
eventStream$.sendActionExecution(
|
|
590
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
591
|
-
actionName: toolCall.name,
|
|
592
|
-
args: JSON.stringify(toolCall.args)
|
|
593
|
-
});
|
|
553
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
594
554
|
}
|
|
595
555
|
}
|
|
596
556
|
} else if (result && "getReader" in result) {
|
|
597
557
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
598
558
|
let reader = result.getReader();
|
|
599
559
|
let mode = null;
|
|
600
|
-
let currentMessageId;
|
|
601
560
|
const toolCallDetails = {
|
|
602
561
|
name: null,
|
|
603
562
|
id: null,
|
|
@@ -636,14 +595,10 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
636
595
|
}
|
|
637
596
|
if (mode === "message" && (toolCallId || done)) {
|
|
638
597
|
mode = null;
|
|
639
|
-
eventStream$.sendTextMessageEnd(
|
|
640
|
-
messageId: currentMessageId
|
|
641
|
-
});
|
|
598
|
+
eventStream$.sendTextMessageEnd();
|
|
642
599
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
643
600
|
mode = null;
|
|
644
|
-
eventStream$.sendActionExecutionEnd(
|
|
645
|
-
actionExecutionId: toolCallId
|
|
646
|
-
});
|
|
601
|
+
eventStream$.sendActionExecutionEnd();
|
|
647
602
|
}
|
|
648
603
|
if (done) {
|
|
649
604
|
break;
|
|
@@ -651,40 +606,21 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
651
606
|
if (mode === null) {
|
|
652
607
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
653
608
|
mode = "function";
|
|
654
|
-
eventStream$.sendActionExecutionStart(
|
|
655
|
-
actionExecutionId: toolCallId,
|
|
656
|
-
actionName: toolCallName,
|
|
657
|
-
parentMessageId: (_i = value.lc_kwargs) == null ? void 0 : _i.id
|
|
658
|
-
});
|
|
609
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
659
610
|
} else if (content) {
|
|
660
611
|
mode = "message";
|
|
661
|
-
|
|
662
|
-
eventStream$.sendTextMessageStart({
|
|
663
|
-
messageId: currentMessageId
|
|
664
|
-
});
|
|
612
|
+
eventStream$.sendTextMessageStart((0, import_shared2.randomId)());
|
|
665
613
|
}
|
|
666
614
|
}
|
|
667
615
|
if (mode === "message" && content) {
|
|
668
|
-
eventStream$.sendTextMessageContent(
|
|
669
|
-
messageId: currentMessageId,
|
|
670
|
-
content: Array.isArray(content) ? ((_k = content[0]) == null ? void 0 : _k.text) ?? "" : content
|
|
671
|
-
});
|
|
616
|
+
eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
|
|
672
617
|
} else if (mode === "function" && toolCallArgs) {
|
|
673
618
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
674
|
-
eventStream$.sendActionExecutionEnd(
|
|
675
|
-
|
|
676
|
-
});
|
|
677
|
-
eventStream$.sendActionExecutionStart({
|
|
678
|
-
actionExecutionId: toolCallId,
|
|
679
|
-
actionName: toolCallName,
|
|
680
|
-
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
681
|
-
});
|
|
619
|
+
eventStream$.sendActionExecutionEnd();
|
|
620
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
682
621
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
683
622
|
}
|
|
684
|
-
eventStream$.sendActionExecutionArgs(
|
|
685
|
-
actionExecutionId: toolCallId,
|
|
686
|
-
args: toolCallArgs
|
|
687
|
-
});
|
|
623
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
688
624
|
}
|
|
689
625
|
} catch (error) {
|
|
690
626
|
console.error("Error reading from stream", error);
|
|
@@ -692,11 +628,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
692
628
|
}
|
|
693
629
|
}
|
|
694
630
|
} else if (actionExecution) {
|
|
695
|
-
eventStream$.sendActionExecutionResult(
|
|
696
|
-
actionExecutionId: actionExecution.id,
|
|
697
|
-
actionName: actionExecution.name,
|
|
698
|
-
result: encodeResult(result)
|
|
699
|
-
});
|
|
631
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
700
632
|
} else {
|
|
701
633
|
throw new Error("Invalid return type from LangChain function.");
|
|
702
634
|
}
|
|
@@ -876,33 +808,21 @@ var OpenAIAssistantAdapter = class {
|
|
|
876
808
|
eventSource.stream(async (eventStream$) => {
|
|
877
809
|
var _a, _b, _c, _d, _e, _f;
|
|
878
810
|
let inFunctionCall = false;
|
|
879
|
-
let currentMessageId;
|
|
880
|
-
let currentToolCallId;
|
|
881
811
|
for await (const chunk of stream) {
|
|
882
812
|
switch (chunk.event) {
|
|
883
813
|
case "thread.message.created":
|
|
884
814
|
if (inFunctionCall) {
|
|
885
|
-
eventStream$.sendActionExecutionEnd(
|
|
886
|
-
actionExecutionId: currentToolCallId
|
|
887
|
-
});
|
|
815
|
+
eventStream$.sendActionExecutionEnd();
|
|
888
816
|
}
|
|
889
|
-
|
|
890
|
-
eventStream$.sendTextMessageStart({
|
|
891
|
-
messageId: currentMessageId
|
|
892
|
-
});
|
|
817
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
893
818
|
break;
|
|
894
819
|
case "thread.message.delta":
|
|
895
820
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
896
|
-
eventStream$.sendTextMessageContent(
|
|
897
|
-
messageId: currentMessageId,
|
|
898
|
-
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
899
|
-
});
|
|
821
|
+
eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
|
|
900
822
|
}
|
|
901
823
|
break;
|
|
902
824
|
case "thread.message.completed":
|
|
903
|
-
eventStream$.sendTextMessageEnd(
|
|
904
|
-
messageId: currentMessageId
|
|
905
|
-
});
|
|
825
|
+
eventStream$.sendTextMessageEnd();
|
|
906
826
|
break;
|
|
907
827
|
case "thread.run.step.delta":
|
|
908
828
|
let toolCallId;
|
|
@@ -915,30 +835,18 @@ var OpenAIAssistantAdapter = class {
|
|
|
915
835
|
}
|
|
916
836
|
if (toolCallName && toolCallId) {
|
|
917
837
|
if (inFunctionCall) {
|
|
918
|
-
eventStream$.sendActionExecutionEnd(
|
|
919
|
-
actionExecutionId: currentToolCallId
|
|
920
|
-
});
|
|
838
|
+
eventStream$.sendActionExecutionEnd();
|
|
921
839
|
}
|
|
922
840
|
inFunctionCall = true;
|
|
923
|
-
|
|
924
|
-
eventStream$.sendActionExecutionStart({
|
|
925
|
-
actionExecutionId: currentToolCallId,
|
|
926
|
-
parentMessageId: chunk.data.id,
|
|
927
|
-
actionName: toolCallName
|
|
928
|
-
});
|
|
841
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
929
842
|
} else if (toolCallArgs) {
|
|
930
|
-
eventStream$.sendActionExecutionArgs(
|
|
931
|
-
actionExecutionId: currentToolCallId,
|
|
932
|
-
args: toolCallArgs
|
|
933
|
-
});
|
|
843
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
934
844
|
}
|
|
935
845
|
break;
|
|
936
846
|
}
|
|
937
847
|
}
|
|
938
848
|
if (inFunctionCall) {
|
|
939
|
-
eventStream$.sendActionExecutionEnd(
|
|
940
|
-
actionExecutionId: currentToolCallId
|
|
941
|
-
});
|
|
849
|
+
eventStream$.sendActionExecutionEnd();
|
|
942
850
|
}
|
|
943
851
|
eventStream$.complete();
|
|
944
852
|
});
|
|
@@ -991,77 +899,46 @@ var UnifyAdapter = class {
|
|
|
991
899
|
}
|
|
992
900
|
});
|
|
993
901
|
let model = null;
|
|
994
|
-
let currentMessageId;
|
|
995
|
-
let currentToolCallId;
|
|
996
902
|
request.eventSource.stream(async (eventStream$) => {
|
|
997
903
|
var _a, _b;
|
|
998
904
|
let mode = null;
|
|
999
905
|
for await (const chunk of stream) {
|
|
1000
906
|
if (this.start) {
|
|
1001
907
|
model = chunk.model;
|
|
1002
|
-
|
|
1003
|
-
eventStream$.
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
eventStream$.sendTextMessageContent({
|
|
1007
|
-
messageId: currentMessageId,
|
|
1008
|
-
content: `Model used: ${model}
|
|
1009
|
-
`
|
|
1010
|
-
});
|
|
1011
|
-
eventStream$.sendTextMessageEnd({
|
|
1012
|
-
messageId: currentMessageId
|
|
1013
|
-
});
|
|
908
|
+
eventStream$.sendTextMessageStart((0, import_shared4.randomId)());
|
|
909
|
+
eventStream$.sendTextMessageContent(`Model used: ${model}
|
|
910
|
+
`);
|
|
911
|
+
eventStream$.sendTextMessageEnd();
|
|
1014
912
|
this.start = false;
|
|
1015
913
|
}
|
|
1016
914
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1017
915
|
const content = chunk.choices[0].delta.content;
|
|
1018
916
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1019
917
|
mode = null;
|
|
1020
|
-
eventStream$.sendTextMessageEnd(
|
|
1021
|
-
messageId: currentMessageId
|
|
1022
|
-
});
|
|
918
|
+
eventStream$.sendTextMessageEnd();
|
|
1023
919
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1024
920
|
mode = null;
|
|
1025
|
-
eventStream$.sendActionExecutionEnd(
|
|
1026
|
-
actionExecutionId: currentToolCallId
|
|
1027
|
-
});
|
|
921
|
+
eventStream$.sendActionExecutionEnd();
|
|
1028
922
|
}
|
|
1029
923
|
if (mode === null) {
|
|
1030
924
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1031
925
|
mode = "function";
|
|
1032
|
-
|
|
1033
|
-
eventStream$.sendActionExecutionStart({
|
|
1034
|
-
actionExecutionId: currentToolCallId,
|
|
1035
|
-
actionName: toolCall.function.name
|
|
1036
|
-
});
|
|
926
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1037
927
|
} else if (content) {
|
|
1038
928
|
mode = "message";
|
|
1039
|
-
|
|
1040
|
-
eventStream$.sendTextMessageStart({
|
|
1041
|
-
messageId: currentMessageId
|
|
1042
|
-
});
|
|
929
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1043
930
|
}
|
|
1044
931
|
}
|
|
1045
932
|
if (mode === "message" && content) {
|
|
1046
|
-
eventStream$.sendTextMessageContent(
|
|
1047
|
-
messageId: currentMessageId,
|
|
1048
|
-
content
|
|
1049
|
-
});
|
|
933
|
+
eventStream$.sendTextMessageContent(content);
|
|
1050
934
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1051
|
-
eventStream$.sendActionExecutionArgs(
|
|
1052
|
-
actionExecutionId: currentToolCallId,
|
|
1053
|
-
args: toolCall.function.arguments
|
|
1054
|
-
});
|
|
935
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1055
936
|
}
|
|
1056
937
|
}
|
|
1057
938
|
if (mode === "message") {
|
|
1058
|
-
eventStream$.sendTextMessageEnd(
|
|
1059
|
-
messageId: currentMessageId
|
|
1060
|
-
});
|
|
939
|
+
eventStream$.sendTextMessageEnd();
|
|
1061
940
|
} else if (mode === "function") {
|
|
1062
|
-
eventStream$.sendActionExecutionEnd(
|
|
1063
|
-
actionExecutionId: currentToolCallId
|
|
1064
|
-
});
|
|
941
|
+
eventStream$.sendActionExecutionEnd();
|
|
1065
942
|
}
|
|
1066
943
|
eventStream$.complete();
|
|
1067
944
|
});
|
|
@@ -1127,59 +1004,35 @@ var GroqAdapter = class {
|
|
|
1127
1004
|
eventSource.stream(async (eventStream$) => {
|
|
1128
1005
|
var _a, _b;
|
|
1129
1006
|
let mode = null;
|
|
1130
|
-
let currentMessageId;
|
|
1131
|
-
let currentToolCallId;
|
|
1132
1007
|
for await (const chunk of stream) {
|
|
1133
1008
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1134
1009
|
const content = chunk.choices[0].delta.content;
|
|
1135
1010
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1136
1011
|
mode = null;
|
|
1137
|
-
eventStream$.sendTextMessageEnd(
|
|
1138
|
-
messageId: currentMessageId
|
|
1139
|
-
});
|
|
1012
|
+
eventStream$.sendTextMessageEnd();
|
|
1140
1013
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1141
1014
|
mode = null;
|
|
1142
|
-
eventStream$.sendActionExecutionEnd(
|
|
1143
|
-
actionExecutionId: currentToolCallId
|
|
1144
|
-
});
|
|
1015
|
+
eventStream$.sendActionExecutionEnd();
|
|
1145
1016
|
}
|
|
1146
1017
|
if (mode === null) {
|
|
1147
1018
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1148
1019
|
mode = "function";
|
|
1149
|
-
|
|
1150
|
-
eventStream$.sendActionExecutionStart({
|
|
1151
|
-
actionExecutionId: currentToolCallId,
|
|
1152
|
-
actionName: toolCall.function.name,
|
|
1153
|
-
parentMessageId: chunk.id
|
|
1154
|
-
});
|
|
1020
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1155
1021
|
} else if (content) {
|
|
1156
1022
|
mode = "message";
|
|
1157
|
-
|
|
1158
|
-
eventStream$.sendTextMessageStart({
|
|
1159
|
-
messageId: currentMessageId
|
|
1160
|
-
});
|
|
1023
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1161
1024
|
}
|
|
1162
1025
|
}
|
|
1163
1026
|
if (mode === "message" && content) {
|
|
1164
|
-
eventStream$.sendTextMessageContent(
|
|
1165
|
-
messageId: currentMessageId,
|
|
1166
|
-
content
|
|
1167
|
-
});
|
|
1027
|
+
eventStream$.sendTextMessageContent(content);
|
|
1168
1028
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1169
|
-
eventStream$.sendActionExecutionArgs(
|
|
1170
|
-
actionExecutionId: currentToolCallId,
|
|
1171
|
-
args: toolCall.function.arguments
|
|
1172
|
-
});
|
|
1029
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1173
1030
|
}
|
|
1174
1031
|
}
|
|
1175
1032
|
if (mode === "message") {
|
|
1176
|
-
eventStream$.sendTextMessageEnd(
|
|
1177
|
-
messageId: currentMessageId
|
|
1178
|
-
});
|
|
1033
|
+
eventStream$.sendTextMessageEnd();
|
|
1179
1034
|
} else if (mode === "function") {
|
|
1180
|
-
eventStream$.sendActionExecutionEnd(
|
|
1181
|
-
actionExecutionId: currentToolCallId
|
|
1182
|
-
});
|
|
1035
|
+
eventStream$.sendActionExecutionEnd();
|
|
1183
1036
|
}
|
|
1184
1037
|
eventStream$.complete();
|
|
1185
1038
|
});
|
|
@@ -1240,167 +1093,163 @@ var RemoteLangGraphEventSource = class {
|
|
|
1240
1093
|
}
|
|
1241
1094
|
return shouldEmitToolCalls === toolCallName;
|
|
1242
1095
|
}
|
|
1243
|
-
getCurrentContent(event) {
|
|
1244
|
-
var _a, _b, _c, _d, _e;
|
|
1245
|
-
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);
|
|
1246
|
-
if (!content) {
|
|
1247
|
-
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1248
|
-
for (const chunk of toolCallChunks) {
|
|
1249
|
-
if (chunk.args) {
|
|
1250
|
-
return chunk.args;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
if (typeof content === "string") {
|
|
1255
|
-
return content;
|
|
1256
|
-
} else if (Array.isArray(content) && content.length > 0) {
|
|
1257
|
-
return content[0].text;
|
|
1258
|
-
}
|
|
1259
|
-
return null;
|
|
1260
|
-
}
|
|
1261
|
-
getCurrentMessageId(event) {
|
|
1262
|
-
var _a, _b, _c, _d, _e;
|
|
1263
|
-
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);
|
|
1264
|
-
}
|
|
1265
|
-
getCurrentToolCallChunks(event) {
|
|
1266
|
-
var _a, _b, _c, _d, _e;
|
|
1267
|
-
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);
|
|
1268
|
-
}
|
|
1269
|
-
getResponseMetadata(event) {
|
|
1270
|
-
var _a, _b, _c, _d, _e;
|
|
1271
|
-
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);
|
|
1272
|
-
}
|
|
1273
1096
|
processLangGraphEvents() {
|
|
1274
1097
|
let lastEventWithState = null;
|
|
1275
1098
|
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;
|
|
1276
1100
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1101
|
+
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);
|
|
1102
|
+
if (typeof content === "string") {
|
|
1103
|
+
acc.content = content;
|
|
1104
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1105
|
+
acc.content = content[0].text;
|
|
1106
|
+
} else {
|
|
1107
|
+
acc.content = null;
|
|
1108
|
+
}
|
|
1109
|
+
const toolCallChunks = (
|
|
1110
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
1111
|
+
((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
|
|
1112
|
+
);
|
|
1113
|
+
const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
|
|
1114
|
+
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
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;
|
|
1291
1138
|
}
|
|
1292
1139
|
acc.event = event;
|
|
1293
1140
|
lastEventWithState = acc;
|
|
1294
1141
|
return acc;
|
|
1295
1142
|
}, {
|
|
1296
1143
|
event: null,
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1144
|
+
toolCallId: null,
|
|
1145
|
+
toolCallMessageId: null,
|
|
1146
|
+
prevToolCallMessageId: null,
|
|
1147
|
+
messageId: null,
|
|
1148
|
+
toolCallName: null,
|
|
1149
|
+
prevMessageId: null,
|
|
1150
|
+
content: null
|
|
1151
|
+
}), (0, import_rxjs.mergeMap)((eventWithState) => {
|
|
1152
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1307
1153
|
const events = [];
|
|
1308
1154
|
let shouldEmitMessages = true;
|
|
1309
|
-
let shouldEmitToolCalls =
|
|
1310
|
-
if (
|
|
1311
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1312
|
-
shouldEmitToolCalls =
|
|
1155
|
+
let shouldEmitToolCalls = false;
|
|
1156
|
+
if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1157
|
+
if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
|
|
1158
|
+
shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
|
|
1313
1159
|
}
|
|
1314
|
-
if ("copilotkit:emit-messages" in (
|
|
1315
|
-
shouldEmitMessages =
|
|
1160
|
+
if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
|
|
1161
|
+
shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
|
|
1316
1162
|
}
|
|
1317
1163
|
}
|
|
1318
|
-
|
|
1319
|
-
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1164
|
+
if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1320
1165
|
events.push({
|
|
1321
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1322
|
-
actionExecutionId: acc.lastToolCallId
|
|
1166
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1323
1167
|
});
|
|
1324
1168
|
}
|
|
1325
|
-
if (
|
|
1169
|
+
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1326
1170
|
events.push({
|
|
1327
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1328
|
-
messageId: acc.lastMessageId
|
|
1171
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1329
1172
|
});
|
|
1330
1173
|
}
|
|
1331
|
-
switch (
|
|
1174
|
+
switch (eventWithState.event.event) {
|
|
1332
1175
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1333
|
-
if (
|
|
1176
|
+
if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1334
1177
|
events.push({
|
|
1335
1178
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1336
|
-
messageId:
|
|
1179
|
+
messageId: eventWithState.event.data.message_id
|
|
1337
1180
|
});
|
|
1338
1181
|
events.push({
|
|
1339
1182
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1340
|
-
|
|
1341
|
-
content: acc.event.data.message
|
|
1183
|
+
content: eventWithState.event.data.message
|
|
1342
1184
|
});
|
|
1343
1185
|
events.push({
|
|
1344
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1345
|
-
messageId: acc.event.data.message_id
|
|
1186
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1346
1187
|
});
|
|
1347
|
-
} else if (
|
|
1188
|
+
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1348
1189
|
events.push({
|
|
1349
1190
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1350
|
-
actionExecutionId:
|
|
1351
|
-
actionName:
|
|
1352
|
-
parentMessageId: acc.event.data.id
|
|
1191
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1192
|
+
actionName: eventWithState.event.data.name
|
|
1353
1193
|
});
|
|
1354
1194
|
events.push({
|
|
1355
1195
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1356
|
-
|
|
1357
|
-
args: JSON.stringify(acc.event.data.args)
|
|
1196
|
+
args: JSON.stringify(eventWithState.event.data.args)
|
|
1358
1197
|
});
|
|
1359
1198
|
events.push({
|
|
1360
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1361
|
-
actionExecutionId: acc.event.data.id
|
|
1199
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1362
1200
|
});
|
|
1363
1201
|
}
|
|
1364
1202
|
break;
|
|
1365
1203
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1366
1204
|
events.push({
|
|
1367
1205
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1368
|
-
threadId:
|
|
1369
|
-
role:
|
|
1370
|
-
agentName:
|
|
1371
|
-
nodeName:
|
|
1372
|
-
runId:
|
|
1373
|
-
active:
|
|
1374
|
-
state: JSON.stringify(
|
|
1375
|
-
running:
|
|
1206
|
+
threadId: eventWithState.event.thread_id,
|
|
1207
|
+
role: eventWithState.event.role,
|
|
1208
|
+
agentName: eventWithState.event.agent_name,
|
|
1209
|
+
nodeName: eventWithState.event.node_name,
|
|
1210
|
+
runId: eventWithState.event.run_id,
|
|
1211
|
+
active: eventWithState.event.active,
|
|
1212
|
+
state: JSON.stringify(eventWithState.event.state),
|
|
1213
|
+
running: eventWithState.event.running
|
|
1376
1214
|
});
|
|
1377
1215
|
break;
|
|
1216
|
+
case LangGraphEventTypes.OnToolEnd:
|
|
1217
|
+
break;
|
|
1378
1218
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1379
|
-
if (
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1219
|
+
if (eventWithState.toolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId) {
|
|
1220
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1221
|
+
events.push({
|
|
1222
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1223
|
+
actionExecutionId: eventWithState.toolCallMessageId,
|
|
1224
|
+
actionName: eventWithState.toolCallName,
|
|
1225
|
+
scope: "client"
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
} else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
|
|
1229
|
+
if (shouldEmitMessages) {
|
|
1230
|
+
events.push({
|
|
1231
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1232
|
+
messageId: eventWithState.messageId
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1391
1235
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1236
|
+
const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
|
|
1237
|
+
((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
|
|
1238
|
+
const content = eventWithState.content;
|
|
1239
|
+
if (args) {
|
|
1240
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1241
|
+
events.push({
|
|
1242
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1243
|
+
args
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
} else if (eventWithState.messageId !== null && content) {
|
|
1247
|
+
if (shouldEmitMessages) {
|
|
1248
|
+
events.push({
|
|
1249
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1250
|
+
content
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1404
1253
|
}
|
|
1405
1254
|
break;
|
|
1406
1255
|
}
|
|
@@ -1408,16 +1257,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1408
1257
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1409
1258
|
console.error(error);
|
|
1410
1259
|
const events = [];
|
|
1411
|
-
if (
|
|
1260
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1412
1261
|
events.push({
|
|
1413
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1414
|
-
messageId: lastEventWithState.lastMessageId
|
|
1262
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1415
1263
|
});
|
|
1416
1264
|
}
|
|
1417
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1265
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1418
1266
|
events.push({
|
|
1419
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1420
|
-
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1267
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1421
1268
|
});
|
|
1422
1269
|
}
|
|
1423
1270
|
const messageId = (0, import_shared6.randomId)();
|
|
@@ -1427,12 +1274,10 @@ var RemoteLangGraphEventSource = class {
|
|
|
1427
1274
|
});
|
|
1428
1275
|
events.push({
|
|
1429
1276
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1430
|
-
messageId,
|
|
1431
1277
|
content: "\u274C An error occurred. Please try again."
|
|
1432
1278
|
});
|
|
1433
1279
|
events.push({
|
|
1434
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1435
|
-
messageId
|
|
1280
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1436
1281
|
});
|
|
1437
1282
|
return events;
|
|
1438
1283
|
}));
|
|
@@ -1454,6 +1299,12 @@ var MessageRole;
|
|
|
1454
1299
|
MessageRole2["system"] = "system";
|
|
1455
1300
|
MessageRole2["tool"] = "tool";
|
|
1456
1301
|
})(MessageRole || (MessageRole = {}));
|
|
1302
|
+
var ActionExecutionScope;
|
|
1303
|
+
(function(ActionExecutionScope2) {
|
|
1304
|
+
ActionExecutionScope2["server"] = "server";
|
|
1305
|
+
ActionExecutionScope2["client"] = "client";
|
|
1306
|
+
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1307
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1457
1308
|
var CopilotRequestType;
|
|
1458
1309
|
(function(CopilotRequestType2) {
|
|
1459
1310
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1472,6 +1323,10 @@ var ActionInputAvailability;
|
|
|
1472
1323
|
name: "MessageRole",
|
|
1473
1324
|
description: "The role of the message"
|
|
1474
1325
|
});
|
|
1326
|
+
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1327
|
+
name: "ActionExecutionScope",
|
|
1328
|
+
description: "The scope of the action"
|
|
1329
|
+
});
|
|
1475
1330
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1476
1331
|
name: "CopilotRequestType",
|
|
1477
1332
|
description: "The type of Copilot request"
|
|
@@ -1528,7 +1383,7 @@ async function streamEvents(controller, args) {
|
|
|
1528
1383
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1529
1384
|
let formattedMessages = [];
|
|
1530
1385
|
try {
|
|
1531
|
-
formattedMessages =
|
|
1386
|
+
formattedMessages = formatMessages(messages);
|
|
1532
1387
|
} catch (e) {
|
|
1533
1388
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1534
1389
|
}
|
|
@@ -1681,8 +1536,7 @@ async function streamEvents(controller, args) {
|
|
|
1681
1536
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1682
1537
|
state: state.values,
|
|
1683
1538
|
running: !shouldExit,
|
|
1684
|
-
active: false
|
|
1685
|
-
includeMessages: true
|
|
1539
|
+
active: false
|
|
1686
1540
|
}));
|
|
1687
1541
|
return Promise.resolve();
|
|
1688
1542
|
} catch (e) {
|
|
@@ -1695,20 +1549,13 @@ async function streamEvents(controller, args) {
|
|
|
1695
1549
|
}
|
|
1696
1550
|
}
|
|
1697
1551
|
__name(streamEvents, "streamEvents");
|
|
1698
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
}, {});
|
|
1706
|
-
} else {
|
|
1707
|
-
state = {
|
|
1708
|
-
...state,
|
|
1709
|
-
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1552
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1553
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1554
|
+
if (key !== "messages") {
|
|
1555
|
+
acc[key] = state[key];
|
|
1556
|
+
}
|
|
1557
|
+
return acc;
|
|
1558
|
+
}, {});
|
|
1712
1559
|
return JSON.stringify({
|
|
1713
1560
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1714
1561
|
thread_id: threadId,
|
|
@@ -1716,7 +1563,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1716
1563
|
agent_name: agentName,
|
|
1717
1564
|
node_name: nodeName,
|
|
1718
1565
|
active,
|
|
1719
|
-
state,
|
|
1566
|
+
state: stateWithoutMessages,
|
|
1720
1567
|
running,
|
|
1721
1568
|
role: "assistant"
|
|
1722
1569
|
}) + "\n";
|
|
@@ -1792,159 +1639,134 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1792
1639
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1793
1640
|
messages = messages.slice(1);
|
|
1794
1641
|
}
|
|
1795
|
-
const
|
|
1796
|
-
const existingMessageIds = new Set(
|
|
1797
|
-
const
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
copilotkit: {
|
|
1802
|
-
actions
|
|
1803
|
-
}
|
|
1804
|
-
};
|
|
1805
|
-
}
|
|
1806
|
-
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1807
|
-
function langchainMessagesToCopilotKit(messages) {
|
|
1808
|
-
const result = [];
|
|
1809
|
-
const tool_call_names = {};
|
|
1810
|
-
for (const message of messages) {
|
|
1811
|
-
if (message.type === "ai") {
|
|
1812
|
-
for (const tool_call of message.tool_calls) {
|
|
1813
|
-
tool_call_names[tool_call.id] = tool_call.name;
|
|
1814
|
-
}
|
|
1642
|
+
const mergedMessages = state.messages || [];
|
|
1643
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1644
|
+
const existingToolCallResults = /* @__PURE__ */ new Set();
|
|
1645
|
+
for (const message of mergedMessages) {
|
|
1646
|
+
if ("tool_call_id" in message) {
|
|
1647
|
+
existingToolCallResults.add(message.tool_call_id);
|
|
1815
1648
|
}
|
|
1816
1649
|
}
|
|
1817
1650
|
for (const message of messages) {
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
content = content[0];
|
|
1651
|
+
if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
|
|
1652
|
+
continue;
|
|
1821
1653
|
}
|
|
1822
|
-
if (
|
|
1823
|
-
|
|
1654
|
+
if ("name" in message && message.name === agentName) {
|
|
1655
|
+
continue;
|
|
1824
1656
|
}
|
|
1825
|
-
if (message.
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
} else
|
|
1832
|
-
|
|
1833
|
-
role
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
for (const tool_call of message.tool_calls) {
|
|
1840
|
-
result.push({
|
|
1841
|
-
id: tool_call.id,
|
|
1842
|
-
name: tool_call.name,
|
|
1843
|
-
arguments: tool_call.args,
|
|
1844
|
-
parentMessageId: message.id
|
|
1845
|
-
});
|
|
1657
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1658
|
+
if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
|
|
1659
|
+
console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
|
|
1660
|
+
continue;
|
|
1661
|
+
}
|
|
1662
|
+
mergedMessages.push(message);
|
|
1663
|
+
} else {
|
|
1664
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1665
|
+
if (mergedMessages[i].id === message.id && message.role === "assistant") {
|
|
1666
|
+
if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
|
|
1667
|
+
message.tool_calls = mergedMessages[i]["tool_calls"];
|
|
1668
|
+
message.additional_kwargs = mergedMessages[i].additional_kwargs;
|
|
1669
|
+
}
|
|
1670
|
+
mergedMessages[i] = message;
|
|
1846
1671
|
}
|
|
1847
|
-
} else {
|
|
1848
|
-
result.push({
|
|
1849
|
-
role: "assistant",
|
|
1850
|
-
content,
|
|
1851
|
-
id: message.id,
|
|
1852
|
-
parentMessageId: message.id
|
|
1853
|
-
});
|
|
1854
1672
|
}
|
|
1855
|
-
} else if (message.type === "tool") {
|
|
1856
|
-
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1857
|
-
result.push({
|
|
1858
|
-
actionExecutionId: message.tool_call_id,
|
|
1859
|
-
actionName,
|
|
1860
|
-
result: content,
|
|
1861
|
-
id: message.id
|
|
1862
|
-
});
|
|
1863
1673
|
}
|
|
1864
1674
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1675
|
+
for (let i = 0; i < mergedMessages.length - 1; i++) {
|
|
1676
|
+
const currentMessage = mergedMessages[i];
|
|
1677
|
+
const nextMessage = mergedMessages[i + 1];
|
|
1678
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
|
|
1679
|
+
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1869
1680
|
}
|
|
1870
1681
|
}
|
|
1871
|
-
const
|
|
1872
|
-
for (
|
|
1873
|
-
|
|
1874
|
-
|
|
1682
|
+
const correctedMessages = [];
|
|
1683
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1684
|
+
const currentMessage = mergedMessages[i];
|
|
1685
|
+
const nextMessage = mergedMessages[i + 1] || null;
|
|
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;
|
|
1875
1705
|
}
|
|
1876
|
-
if ("
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1706
|
+
if ("tool_call_id" in currentMessage) {
|
|
1707
|
+
if (!prevMessage || !("tool_calls" in prevMessage)) {
|
|
1708
|
+
console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
|
|
1709
|
+
continue;
|
|
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;
|
|
1882
1714
|
}
|
|
1715
|
+
correctedMessages.push(currentMessage);
|
|
1716
|
+
continue;
|
|
1883
1717
|
}
|
|
1718
|
+
correctedMessages.push(currentMessage);
|
|
1884
1719
|
}
|
|
1885
|
-
return
|
|
1720
|
+
return {
|
|
1721
|
+
...state,
|
|
1722
|
+
messages: correctedMessages,
|
|
1723
|
+
copilotkit: {
|
|
1724
|
+
actions
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1886
1727
|
}
|
|
1887
|
-
__name(
|
|
1888
|
-
function
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
} else if (message.role === "system") {
|
|
1899
|
-
result.push({
|
|
1900
|
-
...message,
|
|
1901
|
-
role: MessageRole.system
|
|
1902
|
-
});
|
|
1903
|
-
} else if (message.role === "assistant") {
|
|
1904
|
-
result.push({
|
|
1905
|
-
...message,
|
|
1906
|
-
role: MessageRole.assistant
|
|
1907
|
-
});
|
|
1908
|
-
}
|
|
1909
|
-
continue;
|
|
1728
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1729
|
+
function formatMessages(messages) {
|
|
1730
|
+
return messages.map((message) => {
|
|
1731
|
+
if (message.isTextMessage() && message.role === "assistant") {
|
|
1732
|
+
return message;
|
|
1733
|
+
}
|
|
1734
|
+
if (message.isTextMessage() && message.role === "system") {
|
|
1735
|
+
return message;
|
|
1736
|
+
}
|
|
1737
|
+
if (message.isTextMessage() && message.role === "user") {
|
|
1738
|
+
return message;
|
|
1910
1739
|
}
|
|
1911
1740
|
if (message.isActionExecutionMessage()) {
|
|
1912
|
-
const
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
name: m.name,
|
|
1920
|
-
args: m.arguments,
|
|
1921
|
-
id: m.id
|
|
1922
|
-
}));
|
|
1923
|
-
result.push({
|
|
1924
|
-
id: messageId,
|
|
1925
|
-
type: "ActionExecutionMessage",
|
|
1741
|
+
const toolCall = {
|
|
1742
|
+
name: message.name,
|
|
1743
|
+
args: message.arguments,
|
|
1744
|
+
id: message.id
|
|
1745
|
+
};
|
|
1746
|
+
return {
|
|
1747
|
+
type: message.type,
|
|
1926
1748
|
content: "",
|
|
1927
|
-
tool_calls
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1749
|
+
tool_calls: [
|
|
1750
|
+
toolCall
|
|
1751
|
+
],
|
|
1752
|
+
role: MessageRole.assistant,
|
|
1753
|
+
id: message.id
|
|
1754
|
+
};
|
|
1931
1755
|
}
|
|
1932
1756
|
if (message.isResultMessage()) {
|
|
1933
|
-
|
|
1757
|
+
return {
|
|
1934
1758
|
type: message.type,
|
|
1935
1759
|
content: message.result,
|
|
1936
1760
|
id: message.id,
|
|
1937
1761
|
tool_call_id: message.actionExecutionId,
|
|
1938
1762
|
name: message.actionName,
|
|
1939
1763
|
role: MessageRole.tool
|
|
1940
|
-
}
|
|
1941
|
-
continue;
|
|
1764
|
+
};
|
|
1942
1765
|
}
|
|
1943
1766
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1944
|
-
}
|
|
1945
|
-
return result;
|
|
1767
|
+
});
|
|
1946
1768
|
}
|
|
1947
|
-
__name(
|
|
1769
|
+
__name(formatMessages, "formatMessages");
|
|
1948
1770
|
|
|
1949
1771
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1950
1772
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1954,7 +1776,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1954
1776
|
parameters: [],
|
|
1955
1777
|
handler: async (_args) => {
|
|
1956
1778
|
},
|
|
1957
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1779
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1958
1780
|
var _a;
|
|
1959
1781
|
logger2.debug({
|
|
1960
1782
|
actionName: agent.name
|
|
@@ -1980,10 +1802,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1980
1802
|
agent,
|
|
1981
1803
|
threadId,
|
|
1982
1804
|
nodeName,
|
|
1983
|
-
messages
|
|
1984
|
-
...messages,
|
|
1985
|
-
...additionalMessages
|
|
1986
|
-
],
|
|
1805
|
+
messages,
|
|
1987
1806
|
state,
|
|
1988
1807
|
properties: graphqlContext.properties,
|
|
1989
1808
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2011,6 +1830,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2011
1830
|
}
|
|
2012
1831
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2013
1832
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1833
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2014
1834
|
const actions = json["actions"].map((action) => ({
|
|
2015
1835
|
name: action.name,
|
|
2016
1836
|
description: action.description,
|
|
@@ -2024,7 +1844,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2024
1844
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2025
1845
|
agentExecution: false,
|
|
2026
1846
|
type: "self-hosted",
|
|
2027
|
-
agentsAmount:
|
|
1847
|
+
agentsAmount: totalAgents
|
|
2028
1848
|
});
|
|
2029
1849
|
try {
|
|
2030
1850
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2059,13 +1879,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2059
1879
|
}
|
|
2060
1880
|
}
|
|
2061
1881
|
}));
|
|
2062
|
-
const agents = json["agents"].map((agent) => ({
|
|
1882
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
2063
1883
|
name: agent.name,
|
|
2064
1884
|
description: agent.description,
|
|
2065
1885
|
parameters: [],
|
|
2066
1886
|
handler: async (_args) => {
|
|
2067
1887
|
},
|
|
2068
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1888
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2069
1889
|
var _a;
|
|
2070
1890
|
logger2.debug({
|
|
2071
1891
|
actionName: agent.name
|
|
@@ -2090,10 +1910,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2090
1910
|
name,
|
|
2091
1911
|
threadId,
|
|
2092
1912
|
nodeName,
|
|
2093
|
-
messages
|
|
2094
|
-
...messages,
|
|
2095
|
-
...additionalMessages
|
|
2096
|
-
],
|
|
1913
|
+
messages,
|
|
2097
1914
|
state,
|
|
2098
1915
|
properties: graphqlContext.properties,
|
|
2099
1916
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2115,7 +1932,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2115
1932
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2116
1933
|
return eventSource.processLangGraphEvents();
|
|
2117
1934
|
}
|
|
2118
|
-
}));
|
|
1935
|
+
})) : [];
|
|
2119
1936
|
return [
|
|
2120
1937
|
...actions,
|
|
2121
1938
|
...agents
|
|
@@ -2336,94 +2153,7 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2336
2153
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2337
2154
|
var telemetry_client_default = telemetryClient;
|
|
2338
2155
|
|
|
2339
|
-
// src/graphql/types/base/index.ts
|
|
2340
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2341
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2342
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2343
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2344
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2345
|
-
else
|
|
2346
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2347
|
-
if (d = decorators[i])
|
|
2348
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2349
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2350
|
-
}
|
|
2351
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2352
|
-
function _ts_metadata(k, v) {
|
|
2353
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2354
|
-
return Reflect.metadata(k, v);
|
|
2355
|
-
}
|
|
2356
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2357
|
-
var BaseMessageInput = class {
|
|
2358
|
-
id;
|
|
2359
|
-
createdAt;
|
|
2360
|
-
};
|
|
2361
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2362
|
-
_ts_decorate([
|
|
2363
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2364
|
-
_ts_metadata("design:type", String)
|
|
2365
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2366
|
-
_ts_decorate([
|
|
2367
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2368
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2369
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2370
|
-
BaseMessageInput = _ts_decorate([
|
|
2371
|
-
(0, import_type_graphql2.InputType)()
|
|
2372
|
-
], BaseMessageInput);
|
|
2373
|
-
|
|
2374
|
-
// src/graphql/types/converted/index.ts
|
|
2375
|
-
var Message = class extends BaseMessageInput {
|
|
2376
|
-
type;
|
|
2377
|
-
isTextMessage() {
|
|
2378
|
-
return this.type === "TextMessage";
|
|
2379
|
-
}
|
|
2380
|
-
isActionExecutionMessage() {
|
|
2381
|
-
return this.type === "ActionExecutionMessage";
|
|
2382
|
-
}
|
|
2383
|
-
isResultMessage() {
|
|
2384
|
-
return this.type === "ResultMessage";
|
|
2385
|
-
}
|
|
2386
|
-
isAgentStateMessage() {
|
|
2387
|
-
return this.type === "AgentStateMessage";
|
|
2388
|
-
}
|
|
2389
|
-
};
|
|
2390
|
-
__name(Message, "Message");
|
|
2391
|
-
var TextMessage = class extends Message {
|
|
2392
|
-
type = "TextMessage";
|
|
2393
|
-
content;
|
|
2394
|
-
role;
|
|
2395
|
-
parentMessageId;
|
|
2396
|
-
};
|
|
2397
|
-
__name(TextMessage, "TextMessage");
|
|
2398
|
-
var ActionExecutionMessage = class extends Message {
|
|
2399
|
-
type = "ActionExecutionMessage";
|
|
2400
|
-
name;
|
|
2401
|
-
arguments;
|
|
2402
|
-
parentMessageId;
|
|
2403
|
-
};
|
|
2404
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2405
|
-
var ResultMessage = class extends Message {
|
|
2406
|
-
type = "ResultMessage";
|
|
2407
|
-
actionExecutionId;
|
|
2408
|
-
actionName;
|
|
2409
|
-
result;
|
|
2410
|
-
};
|
|
2411
|
-
__name(ResultMessage, "ResultMessage");
|
|
2412
|
-
var AgentStateMessage = class extends Message {
|
|
2413
|
-
type = "AgentStateMessage";
|
|
2414
|
-
threadId;
|
|
2415
|
-
agentName;
|
|
2416
|
-
nodeName;
|
|
2417
|
-
runId;
|
|
2418
|
-
active;
|
|
2419
|
-
role;
|
|
2420
|
-
state;
|
|
2421
|
-
running;
|
|
2422
|
-
};
|
|
2423
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2424
|
-
|
|
2425
2156
|
// src/service-adapters/events.ts
|
|
2426
|
-
var import_class_transformer = require("class-transformer");
|
|
2427
2157
|
var RuntimeEventTypes;
|
|
2428
2158
|
(function(RuntimeEventTypes2) {
|
|
2429
2159
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2439,74 +2169,52 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2439
2169
|
constructor() {
|
|
2440
2170
|
super();
|
|
2441
2171
|
}
|
|
2442
|
-
sendTextMessageStart(
|
|
2172
|
+
sendTextMessageStart(messageId) {
|
|
2443
2173
|
this.next({
|
|
2444
2174
|
type: "TextMessageStart",
|
|
2445
|
-
messageId
|
|
2446
|
-
parentMessageId
|
|
2175
|
+
messageId
|
|
2447
2176
|
});
|
|
2448
2177
|
}
|
|
2449
|
-
sendTextMessageContent(
|
|
2178
|
+
sendTextMessageContent(content) {
|
|
2450
2179
|
this.next({
|
|
2451
2180
|
type: "TextMessageContent",
|
|
2452
|
-
content
|
|
2453
|
-
messageId
|
|
2181
|
+
content
|
|
2454
2182
|
});
|
|
2455
2183
|
}
|
|
2456
|
-
sendTextMessageEnd(
|
|
2184
|
+
sendTextMessageEnd() {
|
|
2457
2185
|
this.next({
|
|
2458
|
-
type: "TextMessageEnd"
|
|
2459
|
-
messageId
|
|
2186
|
+
type: "TextMessageEnd"
|
|
2460
2187
|
});
|
|
2461
2188
|
}
|
|
2462
2189
|
sendTextMessage(messageId, content) {
|
|
2463
|
-
this.sendTextMessageStart(
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
this.sendTextMessageContent({
|
|
2467
|
-
messageId,
|
|
2468
|
-
content
|
|
2469
|
-
});
|
|
2470
|
-
this.sendTextMessageEnd({
|
|
2471
|
-
messageId
|
|
2472
|
-
});
|
|
2190
|
+
this.sendTextMessageStart(messageId);
|
|
2191
|
+
this.sendTextMessageContent(content);
|
|
2192
|
+
this.sendTextMessageEnd();
|
|
2473
2193
|
}
|
|
2474
|
-
sendActionExecutionStart(
|
|
2194
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2475
2195
|
this.next({
|
|
2476
2196
|
type: "ActionExecutionStart",
|
|
2477
2197
|
actionExecutionId,
|
|
2478
|
-
actionName
|
|
2479
|
-
parentMessageId
|
|
2198
|
+
actionName
|
|
2480
2199
|
});
|
|
2481
2200
|
}
|
|
2482
|
-
sendActionExecutionArgs(
|
|
2201
|
+
sendActionExecutionArgs(args) {
|
|
2483
2202
|
this.next({
|
|
2484
2203
|
type: "ActionExecutionArgs",
|
|
2485
|
-
args
|
|
2486
|
-
actionExecutionId
|
|
2204
|
+
args
|
|
2487
2205
|
});
|
|
2488
2206
|
}
|
|
2489
|
-
sendActionExecutionEnd(
|
|
2207
|
+
sendActionExecutionEnd() {
|
|
2490
2208
|
this.next({
|
|
2491
|
-
type: "ActionExecutionEnd"
|
|
2492
|
-
actionExecutionId
|
|
2209
|
+
type: "ActionExecutionEnd"
|
|
2493
2210
|
});
|
|
2494
2211
|
}
|
|
2495
|
-
sendActionExecution(
|
|
2496
|
-
this.sendActionExecutionStart(
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
parentMessageId
|
|
2500
|
-
});
|
|
2501
|
-
this.sendActionExecutionArgs({
|
|
2502
|
-
actionExecutionId,
|
|
2503
|
-
args
|
|
2504
|
-
});
|
|
2505
|
-
this.sendActionExecutionEnd({
|
|
2506
|
-
actionExecutionId
|
|
2507
|
-
});
|
|
2212
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
2213
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
2214
|
+
this.sendActionExecutionArgs(args);
|
|
2215
|
+
this.sendActionExecutionEnd();
|
|
2508
2216
|
}
|
|
2509
|
-
sendActionExecutionResult(
|
|
2217
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2510
2218
|
this.next({
|
|
2511
2219
|
type: "ActionExecutionResult",
|
|
2512
2220
|
actionName,
|
|
@@ -2514,7 +2222,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2514
2222
|
result
|
|
2515
2223
|
});
|
|
2516
2224
|
}
|
|
2517
|
-
sendAgentStateMessage(
|
|
2225
|
+
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2518
2226
|
this.next({
|
|
2519
2227
|
type: "AgentStateMessage",
|
|
2520
2228
|
threadId,
|
|
@@ -2551,13 +2259,22 @@ var RuntimeEventSource = class {
|
|
|
2551
2259
|
this.sendErrorMessageToChat();
|
|
2552
2260
|
});
|
|
2553
2261
|
return this.eventStream$.pipe(
|
|
2262
|
+
// mark tools for server side execution
|
|
2263
|
+
(0, import_rxjs2.map)((event) => {
|
|
2264
|
+
if (event.type === "ActionExecutionStart") {
|
|
2265
|
+
if (event.scope !== "passThrough") {
|
|
2266
|
+
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return event;
|
|
2270
|
+
}),
|
|
2554
2271
|
// track state
|
|
2555
2272
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2556
2273
|
acc = {
|
|
2557
2274
|
...acc
|
|
2558
2275
|
};
|
|
2559
2276
|
if (event.type === "ActionExecutionStart") {
|
|
2560
|
-
acc.callActionServerSide =
|
|
2277
|
+
acc.callActionServerSide = event.scope === "server";
|
|
2561
2278
|
acc.args = "";
|
|
2562
2279
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2563
2280
|
if (acc.callActionServerSide) {
|
|
@@ -2611,33 +2328,10 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2611
2328
|
}
|
|
2612
2329
|
}
|
|
2613
2330
|
if (isLangGraphAgentAction(action)) {
|
|
2614
|
-
|
|
2615
|
-
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2616
|
-
id: actionExecutionId,
|
|
2617
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2618
|
-
name: action.name,
|
|
2619
|
-
arguments: JSON.parse(actionArguments),
|
|
2620
|
-
parentMessageId: actionExecutionId
|
|
2621
|
-
});
|
|
2622
|
-
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2623
|
-
id: "result-" + actionExecutionId,
|
|
2624
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2625
|
-
actionExecutionId,
|
|
2626
|
-
actionName: action.name,
|
|
2627
|
-
result
|
|
2628
|
-
});
|
|
2629
|
-
eventStream$.sendActionExecutionResult({
|
|
2630
|
-
actionExecutionId,
|
|
2631
|
-
actionName: action.name,
|
|
2632
|
-
result
|
|
2633
|
-
});
|
|
2331
|
+
eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
|
|
2634
2332
|
const stream = await action.langGraphAgentHandler({
|
|
2635
2333
|
name: action.name,
|
|
2636
|
-
actionInputsWithoutAgents
|
|
2637
|
-
additionalMessages: [
|
|
2638
|
-
agentExecution,
|
|
2639
|
-
agentExecutionResult
|
|
2640
|
-
]
|
|
2334
|
+
actionInputsWithoutAgents
|
|
2641
2335
|
});
|
|
2642
2336
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2643
2337
|
next: (event) => eventStream$.next(event),
|
|
@@ -2658,29 +2352,113 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2658
2352
|
}
|
|
2659
2353
|
__name(executeAction, "executeAction");
|
|
2660
2354
|
|
|
2355
|
+
// src/graphql/types/base/index.ts
|
|
2356
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2357
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2358
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2359
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2360
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2361
|
+
else
|
|
2362
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2363
|
+
if (d = decorators[i])
|
|
2364
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2365
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2366
|
+
}
|
|
2367
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2368
|
+
function _ts_metadata(k, v) {
|
|
2369
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2370
|
+
return Reflect.metadata(k, v);
|
|
2371
|
+
}
|
|
2372
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2373
|
+
var BaseMessageInput = class {
|
|
2374
|
+
id;
|
|
2375
|
+
createdAt;
|
|
2376
|
+
};
|
|
2377
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2378
|
+
_ts_decorate([
|
|
2379
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2380
|
+
_ts_metadata("design:type", String)
|
|
2381
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2382
|
+
_ts_decorate([
|
|
2383
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2384
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2385
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2386
|
+
BaseMessageInput = _ts_decorate([
|
|
2387
|
+
(0, import_type_graphql2.InputType)()
|
|
2388
|
+
], BaseMessageInput);
|
|
2389
|
+
|
|
2390
|
+
// src/graphql/types/converted/index.ts
|
|
2391
|
+
var Message = class extends BaseMessageInput {
|
|
2392
|
+
type;
|
|
2393
|
+
isTextMessage() {
|
|
2394
|
+
return this.type === "TextMessage";
|
|
2395
|
+
}
|
|
2396
|
+
isActionExecutionMessage() {
|
|
2397
|
+
return this.type === "ActionExecutionMessage";
|
|
2398
|
+
}
|
|
2399
|
+
isResultMessage() {
|
|
2400
|
+
return this.type === "ResultMessage";
|
|
2401
|
+
}
|
|
2402
|
+
isAgentStateMessage() {
|
|
2403
|
+
return this.type === "AgentStateMessage";
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
__name(Message, "Message");
|
|
2407
|
+
var TextMessage = class extends Message {
|
|
2408
|
+
type = "TextMessage";
|
|
2409
|
+
content;
|
|
2410
|
+
role;
|
|
2411
|
+
};
|
|
2412
|
+
__name(TextMessage, "TextMessage");
|
|
2413
|
+
var ActionExecutionMessage = class extends Message {
|
|
2414
|
+
type = "ActionExecutionMessage";
|
|
2415
|
+
name;
|
|
2416
|
+
arguments;
|
|
2417
|
+
scope;
|
|
2418
|
+
};
|
|
2419
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2420
|
+
var ResultMessage = class extends Message {
|
|
2421
|
+
type = "ResultMessage";
|
|
2422
|
+
actionExecutionId;
|
|
2423
|
+
actionName;
|
|
2424
|
+
result;
|
|
2425
|
+
};
|
|
2426
|
+
__name(ResultMessage, "ResultMessage");
|
|
2427
|
+
var AgentStateMessage = class extends Message {
|
|
2428
|
+
type = "AgentStateMessage";
|
|
2429
|
+
threadId;
|
|
2430
|
+
agentName;
|
|
2431
|
+
nodeName;
|
|
2432
|
+
runId;
|
|
2433
|
+
active;
|
|
2434
|
+
role;
|
|
2435
|
+
state;
|
|
2436
|
+
running;
|
|
2437
|
+
};
|
|
2438
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2439
|
+
|
|
2661
2440
|
// src/service-adapters/conversion.ts
|
|
2662
|
-
var
|
|
2441
|
+
var import_class_transformer = require("class-transformer");
|
|
2663
2442
|
function convertGqlInputToMessages(inputMessages) {
|
|
2664
2443
|
const messages = [];
|
|
2665
2444
|
for (const message of inputMessages) {
|
|
2666
2445
|
if (message.textMessage) {
|
|
2667
|
-
messages.push((0,
|
|
2446
|
+
messages.push((0, import_class_transformer.plainToInstance)(TextMessage, {
|
|
2668
2447
|
id: message.id,
|
|
2669
2448
|
createdAt: message.createdAt,
|
|
2670
2449
|
role: message.textMessage.role,
|
|
2671
|
-
content: message.textMessage.content
|
|
2672
|
-
parentMessageId: message.textMessage.parentMessageId
|
|
2450
|
+
content: message.textMessage.content
|
|
2673
2451
|
}));
|
|
2674
2452
|
} else if (message.actionExecutionMessage) {
|
|
2675
|
-
messages.push((0,
|
|
2453
|
+
messages.push((0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2676
2454
|
id: message.id,
|
|
2677
2455
|
createdAt: message.createdAt,
|
|
2678
2456
|
name: message.actionExecutionMessage.name,
|
|
2679
2457
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2680
|
-
|
|
2458
|
+
scope: message.actionExecutionMessage.scope
|
|
2681
2459
|
}));
|
|
2682
2460
|
} else if (message.resultMessage) {
|
|
2683
|
-
messages.push((0,
|
|
2461
|
+
messages.push((0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2684
2462
|
id: message.id,
|
|
2685
2463
|
createdAt: message.createdAt,
|
|
2686
2464
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2688,7 +2466,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2688
2466
|
result: message.resultMessage.result
|
|
2689
2467
|
}));
|
|
2690
2468
|
} else if (message.agentStateMessage) {
|
|
2691
|
-
messages.push((0,
|
|
2469
|
+
messages.push((0, import_class_transformer.plainToInstance)(AgentStateMessage, {
|
|
2692
2470
|
id: message.id,
|
|
2693
2471
|
threadId: message.agentStateMessage.threadId,
|
|
2694
2472
|
createdAt: message.createdAt,
|
|
@@ -2997,7 +2775,6 @@ MessageInput = _ts_decorate2([
|
|
|
2997
2775
|
], MessageInput);
|
|
2998
2776
|
var TextMessageInput = class {
|
|
2999
2777
|
content;
|
|
3000
|
-
parentMessageId;
|
|
3001
2778
|
role;
|
|
3002
2779
|
};
|
|
3003
2780
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3005,12 +2782,6 @@ _ts_decorate2([
|
|
|
3005
2782
|
(0, import_type_graphql3.Field)(() => String),
|
|
3006
2783
|
_ts_metadata2("design:type", String)
|
|
3007
2784
|
], TextMessageInput.prototype, "content", void 0);
|
|
3008
|
-
_ts_decorate2([
|
|
3009
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3010
|
-
nullable: true
|
|
3011
|
-
}),
|
|
3012
|
-
_ts_metadata2("design:type", String)
|
|
3013
|
-
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
3014
2785
|
_ts_decorate2([
|
|
3015
2786
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3016
2787
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3021,7 +2792,6 @@ TextMessageInput = _ts_decorate2([
|
|
|
3021
2792
|
var ActionExecutionMessageInput = class {
|
|
3022
2793
|
name;
|
|
3023
2794
|
arguments;
|
|
3024
|
-
parentMessageId;
|
|
3025
2795
|
scope;
|
|
3026
2796
|
};
|
|
3027
2797
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3034,17 +2804,8 @@ _ts_decorate2([
|
|
|
3034
2804
|
_ts_metadata2("design:type", String)
|
|
3035
2805
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3036
2806
|
_ts_decorate2([
|
|
3037
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3038
|
-
|
|
3039
|
-
}),
|
|
3040
|
-
_ts_metadata2("design:type", String)
|
|
3041
|
-
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3042
|
-
_ts_decorate2([
|
|
3043
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3044
|
-
nullable: true,
|
|
3045
|
-
deprecationReason: "This field will be removed in a future version"
|
|
3046
|
-
}),
|
|
3047
|
-
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
2807
|
+
(0, import_type_graphql3.Field)(() => ActionExecutionScope),
|
|
2808
|
+
_ts_metadata2("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
3048
2809
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3049
2810
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3050
2811
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3052,7 +2813,6 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3052
2813
|
var ResultMessageInput = class {
|
|
3053
2814
|
actionExecutionId;
|
|
3054
2815
|
actionName;
|
|
3055
|
-
parentMessageId;
|
|
3056
2816
|
result;
|
|
3057
2817
|
};
|
|
3058
2818
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3064,12 +2824,6 @@ _ts_decorate2([
|
|
|
3064
2824
|
(0, import_type_graphql3.Field)(() => String),
|
|
3065
2825
|
_ts_metadata2("design:type", String)
|
|
3066
2826
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3067
|
-
_ts_decorate2([
|
|
3068
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3069
|
-
nullable: true
|
|
3070
|
-
}),
|
|
3071
|
-
_ts_metadata2("design:type", String)
|
|
3072
|
-
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
3073
2827
|
_ts_decorate2([
|
|
3074
2828
|
(0, import_type_graphql3.Field)(() => String),
|
|
3075
2829
|
_ts_metadata2("design:type", String)
|
|
@@ -3333,6 +3087,7 @@ var ForwardedParametersInput = class {
|
|
|
3333
3087
|
stop;
|
|
3334
3088
|
toolChoice;
|
|
3335
3089
|
toolChoiceFunctionName;
|
|
3090
|
+
temperature;
|
|
3336
3091
|
};
|
|
3337
3092
|
__name(ForwardedParametersInput, "ForwardedParametersInput");
|
|
3338
3093
|
_ts_decorate7([
|
|
@@ -3367,6 +3122,12 @@ _ts_decorate7([
|
|
|
3367
3122
|
}),
|
|
3368
3123
|
_ts_metadata7("design:type", String)
|
|
3369
3124
|
], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
|
|
3125
|
+
_ts_decorate7([
|
|
3126
|
+
(0, import_type_graphql8.Field)(() => Number, {
|
|
3127
|
+
nullable: true
|
|
3128
|
+
}),
|
|
3129
|
+
_ts_metadata7("design:type", Number)
|
|
3130
|
+
], ForwardedParametersInput.prototype, "temperature", void 0);
|
|
3370
3131
|
ForwardedParametersInput = _ts_decorate7([
|
|
3371
3132
|
(0, import_type_graphql8.InputType)()
|
|
3372
3133
|
], ForwardedParametersInput);
|
|
@@ -3792,7 +3553,6 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3792
3553
|
var TextMessageOutput = class {
|
|
3793
3554
|
role;
|
|
3794
3555
|
content;
|
|
3795
|
-
parentMessageId;
|
|
3796
3556
|
};
|
|
3797
3557
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3798
3558
|
_ts_decorate13([
|
|
@@ -3805,12 +3565,6 @@ _ts_decorate13([
|
|
|
3805
3565
|
]),
|
|
3806
3566
|
_ts_metadata13("design:type", Array)
|
|
3807
3567
|
], TextMessageOutput.prototype, "content", void 0);
|
|
3808
|
-
_ts_decorate13([
|
|
3809
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
3810
|
-
nullable: true
|
|
3811
|
-
}),
|
|
3812
|
-
_ts_metadata13("design:type", String)
|
|
3813
|
-
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
3814
3568
|
TextMessageOutput = _ts_decorate13([
|
|
3815
3569
|
(0, import_type_graphql14.ObjectType)({
|
|
3816
3570
|
implements: BaseMessageOutput
|
|
@@ -3820,7 +3574,6 @@ var ActionExecutionMessageOutput = class {
|
|
|
3820
3574
|
name;
|
|
3821
3575
|
scope;
|
|
3822
3576
|
arguments;
|
|
3823
|
-
parentMessageId;
|
|
3824
3577
|
};
|
|
3825
3578
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3826
3579
|
_ts_decorate13([
|
|
@@ -3828,11 +3581,8 @@ _ts_decorate13([
|
|
|
3828
3581
|
_ts_metadata13("design:type", String)
|
|
3829
3582
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3830
3583
|
_ts_decorate13([
|
|
3831
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3832
|
-
|
|
3833
|
-
deprecationReason: "This field will be removed in a future version"
|
|
3834
|
-
}),
|
|
3835
|
-
_ts_metadata13("design:type", String)
|
|
3584
|
+
(0, import_type_graphql14.Field)(() => ActionExecutionScope),
|
|
3585
|
+
_ts_metadata13("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
3836
3586
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3837
3587
|
_ts_decorate13([
|
|
3838
3588
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3840,12 +3590,6 @@ _ts_decorate13([
|
|
|
3840
3590
|
]),
|
|
3841
3591
|
_ts_metadata13("design:type", Array)
|
|
3842
3592
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
3843
|
-
_ts_decorate13([
|
|
3844
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
3845
|
-
nullable: true
|
|
3846
|
-
}),
|
|
3847
|
-
_ts_metadata13("design:type", String)
|
|
3848
|
-
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
3849
3593
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3850
3594
|
(0, import_type_graphql14.ObjectType)({
|
|
3851
3595
|
implements: BaseMessageOutput
|
|
@@ -3956,7 +3700,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3956
3700
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3957
3701
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3958
3702
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3959
|
-
var
|
|
3703
|
+
var import_class_transformer2 = require("class-transformer");
|
|
3960
3704
|
var import_graphql = require("graphql");
|
|
3961
3705
|
|
|
3962
3706
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -4154,7 +3898,7 @@ var CopilotResolver = class {
|
|
|
4154
3898
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4155
3899
|
});
|
|
4156
3900
|
outputMessages = [
|
|
4157
|
-
(0,
|
|
3901
|
+
(0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4158
3902
|
id: (0, import_shared10.randomId)(),
|
|
4159
3903
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4160
3904
|
content: result.reason,
|
|
@@ -4203,15 +3947,12 @@ var CopilotResolver = class {
|
|
|
4203
3947
|
// skip until this message start event
|
|
4204
3948
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4205
3949
|
// take until the message end event
|
|
4206
|
-
(0, import_rxjs4.takeWhile)((e) =>
|
|
4207
|
-
// filter out any other message events or message ids
|
|
4208
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
3950
|
+
(0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
4209
3951
|
);
|
|
4210
3952
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4211
3953
|
const messageId = event.messageId;
|
|
4212
3954
|
pushMessage({
|
|
4213
3955
|
id: messageId,
|
|
4214
|
-
parentMessageId: event.parentMessageId,
|
|
4215
3956
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4216
3957
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4217
3958
|
role: MessageRole.assistant,
|
|
@@ -4224,7 +3965,7 @@ var CopilotResolver = class {
|
|
|
4224
3965
|
reason,
|
|
4225
3966
|
messageId: messageId2
|
|
4226
3967
|
}, "Text streaming interrupted");
|
|
4227
|
-
streamingTextStatus.next((0,
|
|
3968
|
+
streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4228
3969
|
reason
|
|
4229
3970
|
}));
|
|
4230
3971
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4257,7 +3998,7 @@ var CopilotResolver = class {
|
|
|
4257
3998
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4258
3999
|
stopStreamingText();
|
|
4259
4000
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4260
|
-
outputMessages.push((0,
|
|
4001
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4261
4002
|
id: messageId,
|
|
4262
4003
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4263
4004
|
content: textChunks.join(""),
|
|
@@ -4270,20 +4011,14 @@ var CopilotResolver = class {
|
|
|
4270
4011
|
break;
|
|
4271
4012
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4272
4013
|
logger2.debug("Action execution start event received");
|
|
4273
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4274
|
-
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4275
|
-
// take until the action execution end event
|
|
4276
|
-
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4277
|
-
// filter out any other action execution events or action execution ids
|
|
4278
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4279
|
-
);
|
|
4014
|
+
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs4.skipWhile)((e) => e !== event), (0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
4280
4015
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4281
4016
|
pushMessage({
|
|
4282
4017
|
id: event.actionExecutionId,
|
|
4283
|
-
parentMessageId: event.parentMessageId,
|
|
4284
4018
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4285
4019
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4286
4020
|
name: event.actionName,
|
|
4021
|
+
scope: event.scope,
|
|
4287
4022
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4288
4023
|
logger2.debug("Action execution argument stream created");
|
|
4289
4024
|
const argumentChunks = [];
|
|
@@ -4299,7 +4034,7 @@ var CopilotResolver = class {
|
|
|
4299
4034
|
logger2.error({
|
|
4300
4035
|
err
|
|
4301
4036
|
}, "Error in action execution argument stream");
|
|
4302
|
-
streamingArgumentsStatus.next((0,
|
|
4037
|
+
streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4303
4038
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4304
4039
|
}));
|
|
4305
4040
|
stopStreamingArguments();
|
|
@@ -4310,10 +4045,11 @@ var CopilotResolver = class {
|
|
|
4310
4045
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4311
4046
|
stopStreamingArguments();
|
|
4312
4047
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4313
|
-
outputMessages.push((0,
|
|
4048
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
4314
4049
|
id: event.actionExecutionId,
|
|
4315
4050
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4316
4051
|
name: event.actionName,
|
|
4052
|
+
scope: event.scope,
|
|
4317
4053
|
arguments: argumentChunks.join("")
|
|
4318
4054
|
}));
|
|
4319
4055
|
}
|
|
@@ -4326,15 +4062,15 @@ var CopilotResolver = class {
|
|
|
4326
4062
|
result: event.result
|
|
4327
4063
|
}, "Action execution result event received");
|
|
4328
4064
|
pushMessage({
|
|
4329
|
-
id:
|
|
4065
|
+
id: (0, import_shared10.randomId)(),
|
|
4330
4066
|
status: new SuccessMessageStatus(),
|
|
4331
4067
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4332
4068
|
actionExecutionId: event.actionExecutionId,
|
|
4333
4069
|
actionName: event.actionName,
|
|
4334
4070
|
result: event.result
|
|
4335
4071
|
});
|
|
4336
|
-
outputMessages.push((0,
|
|
4337
|
-
id:
|
|
4072
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
4073
|
+
id: (0, import_shared10.randomId)(),
|
|
4338
4074
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4339
4075
|
actionExecutionId: event.actionExecutionId,
|
|
4340
4076
|
actionName: event.actionName,
|
|
@@ -4358,7 +4094,7 @@ var CopilotResolver = class {
|
|
|
4358
4094
|
role: MessageRole.assistant,
|
|
4359
4095
|
createdAt: /* @__PURE__ */ new Date()
|
|
4360
4096
|
});
|
|
4361
|
-
outputMessages.push((0,
|
|
4097
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
4362
4098
|
id: (0, import_shared10.randomId)(),
|
|
4363
4099
|
threadId: event.threadId,
|
|
4364
4100
|
agentName: event.agentName,
|