@copilotkit/runtime 1.5.1-next.2 → 1.5.1-next.3
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 +8 -0
- package/__snapshots__/schema/schema.graphql +9 -19
- package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
- package/dist/chunk-B74M7FXG.mjs.map +1 -0
- package/dist/{chunk-2FY7EQEE.mjs → chunk-M4QD67S3.mjs} +2 -2
- package/dist/{chunk-CLGKEUOA.mjs → chunk-OKQVDDJ2.mjs} +63 -298
- package/dist/chunk-OKQVDDJ2.mjs.map +1 -0
- package/dist/{chunk-2ZPE55QG.mjs → chunk-U3AYI5XZ.mjs} +2 -2
- package/dist/{chunk-W6E7AVR7.mjs → chunk-U75F2RAQ.mjs} +2 -2
- package/dist/{chunk-2V7BHSFE.mjs → chunk-ZSWCEADS.mjs} +331 -579
- package/dist/chunk-ZSWCEADS.mjs.map +1 -0
- package/dist/{copilot-runtime-36700e00.d.ts → copilot-runtime-12e7ac40.d.ts} +2 -9
- 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-696b5d29.d.ts → groq-adapter-24abe931.d.ts} +1 -1
- package/dist/{index-cc2b17be.d.ts → index-10b1c870.d.ts} +9 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +498 -984
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -15
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-9125a12e.d.ts → langserve-f021ab9c.d.ts} +14 -54
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +477 -886
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +48 -171
- 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 +48 -171
- 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 +48 -171
- 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 +48 -171
- 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 +5 -36
- package/dist/service-adapters/index.js +61 -298
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -5
- package/package.json +2 -2
- package/dist/chunk-2V7BHSFE.mjs.map +0 -1
- package/dist/chunk-CLGKEUOA.mjs.map +0 -1
- package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
- /package/dist/{chunk-2FY7EQEE.mjs.map → chunk-M4QD67S3.mjs.map} +0 -0
- /package/dist/{chunk-2ZPE55QG.mjs.map → chunk-U3AYI5XZ.mjs.map} +0 -0
- /package/dist/{chunk-W6E7AVR7.mjs.map → chunk-U75F2RAQ.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.4.1-pre.6",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -419,16 +419,11 @@ var OpenAIAdapter = class {
|
|
|
419
419
|
},
|
|
420
420
|
...this.disableParallelToolCalls && {
|
|
421
421
|
parallel_tool_calls: false
|
|
422
|
-
},
|
|
423
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
424
|
-
temperature: forwardedParameters.temperature
|
|
425
422
|
}
|
|
426
423
|
});
|
|
427
424
|
eventSource.stream(async (eventStream$) => {
|
|
428
425
|
var _a, _b;
|
|
429
426
|
let mode = null;
|
|
430
|
-
let currentMessageId;
|
|
431
|
-
let currentToolCallId;
|
|
432
427
|
for await (const chunk of stream) {
|
|
433
428
|
if (chunk.choices.length === 0) {
|
|
434
429
|
continue;
|
|
@@ -437,52 +432,30 @@ var OpenAIAdapter = class {
|
|
|
437
432
|
const content = chunk.choices[0].delta.content;
|
|
438
433
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
439
434
|
mode = null;
|
|
440
|
-
eventStream$.sendTextMessageEnd(
|
|
441
|
-
messageId: currentMessageId
|
|
442
|
-
});
|
|
435
|
+
eventStream$.sendTextMessageEnd();
|
|
443
436
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
444
437
|
mode = null;
|
|
445
|
-
eventStream$.sendActionExecutionEnd(
|
|
446
|
-
actionExecutionId: currentToolCallId
|
|
447
|
-
});
|
|
438
|
+
eventStream$.sendActionExecutionEnd();
|
|
448
439
|
}
|
|
449
440
|
if (mode === null) {
|
|
450
441
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
451
442
|
mode = "function";
|
|
452
|
-
|
|
453
|
-
eventStream$.sendActionExecutionStart({
|
|
454
|
-
actionExecutionId: currentToolCallId,
|
|
455
|
-
parentMessageId: chunk.id,
|
|
456
|
-
actionName: toolCall.function.name
|
|
457
|
-
});
|
|
443
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
458
444
|
} else if (content) {
|
|
459
445
|
mode = "message";
|
|
460
|
-
|
|
461
|
-
eventStream$.sendTextMessageStart({
|
|
462
|
-
messageId: currentMessageId
|
|
463
|
-
});
|
|
446
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
464
447
|
}
|
|
465
448
|
}
|
|
466
449
|
if (mode === "message" && content) {
|
|
467
|
-
eventStream$.sendTextMessageContent(
|
|
468
|
-
messageId: currentMessageId,
|
|
469
|
-
content
|
|
470
|
-
});
|
|
450
|
+
eventStream$.sendTextMessageContent(content);
|
|
471
451
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
472
|
-
eventStream$.sendActionExecutionArgs(
|
|
473
|
-
actionExecutionId: currentToolCallId,
|
|
474
|
-
args: toolCall.function.arguments
|
|
475
|
-
});
|
|
452
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
476
453
|
}
|
|
477
454
|
}
|
|
478
455
|
if (mode === "message") {
|
|
479
|
-
eventStream$.sendTextMessageEnd(
|
|
480
|
-
messageId: currentMessageId
|
|
481
|
-
});
|
|
456
|
+
eventStream$.sendTextMessageEnd();
|
|
482
457
|
} else if (mode === "function") {
|
|
483
|
-
eventStream$.sendActionExecutionEnd(
|
|
484
|
-
actionExecutionId: currentToolCallId
|
|
485
|
-
});
|
|
458
|
+
eventStream$.sendActionExecutionEnd();
|
|
486
459
|
}
|
|
487
460
|
eventStream$.complete();
|
|
488
461
|
});
|
|
@@ -550,25 +523,17 @@ function isBaseMessageChunk(message) {
|
|
|
550
523
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
551
524
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
552
525
|
if (actionExecution) {
|
|
553
|
-
eventStream$.sendActionExecutionResult(
|
|
554
|
-
actionExecutionId: actionExecution.id,
|
|
555
|
-
actionName: actionExecution.name,
|
|
556
|
-
result: "Sending a message"
|
|
557
|
-
});
|
|
526
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
558
527
|
}
|
|
559
528
|
}
|
|
560
529
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
561
530
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
562
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
531
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
563
532
|
if (typeof result === "string") {
|
|
564
533
|
if (!actionExecution) {
|
|
565
534
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
566
535
|
} else {
|
|
567
|
-
eventStream$.sendActionExecutionResult(
|
|
568
|
-
actionExecutionId: actionExecution.id,
|
|
569
|
-
actionName: actionExecution.name,
|
|
570
|
-
result
|
|
571
|
-
});
|
|
536
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
572
537
|
}
|
|
573
538
|
} else if (isAIMessage(result)) {
|
|
574
539
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -576,11 +541,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
576
541
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
577
542
|
}
|
|
578
543
|
for (const toolCall of result.tool_calls) {
|
|
579
|
-
eventStream$.sendActionExecution(
|
|
580
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
581
|
-
actionName: toolCall.name,
|
|
582
|
-
args: JSON.stringify(toolCall.args)
|
|
583
|
-
});
|
|
544
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
584
545
|
}
|
|
585
546
|
} else if (isBaseMessageChunk(result)) {
|
|
586
547
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -589,18 +550,13 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
589
550
|
}
|
|
590
551
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
591
552
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
592
|
-
eventStream$.sendActionExecution(
|
|
593
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
594
|
-
actionName: toolCall.name,
|
|
595
|
-
args: JSON.stringify(toolCall.args)
|
|
596
|
-
});
|
|
553
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
597
554
|
}
|
|
598
555
|
}
|
|
599
556
|
} else if (result && "getReader" in result) {
|
|
600
557
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
601
558
|
let reader = result.getReader();
|
|
602
559
|
let mode = null;
|
|
603
|
-
let currentMessageId;
|
|
604
560
|
const toolCallDetails = {
|
|
605
561
|
name: null,
|
|
606
562
|
id: null,
|
|
@@ -614,12 +570,9 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
614
570
|
let toolCallId = void 0;
|
|
615
571
|
let toolCallArgs = void 0;
|
|
616
572
|
let hasToolCall = false;
|
|
617
|
-
let content =
|
|
618
|
-
if (value && value.content) {
|
|
619
|
-
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
620
|
-
}
|
|
573
|
+
let content = value == null ? void 0 : value.content;
|
|
621
574
|
if (isAIMessageChunk(value)) {
|
|
622
|
-
let chunk = (
|
|
575
|
+
let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
|
|
623
576
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
624
577
|
hasToolCall = chunk != void 0;
|
|
625
578
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -634,22 +587,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
634
587
|
toolCallName = toolCallDetails.name;
|
|
635
588
|
toolCallId = toolCallDetails.id;
|
|
636
589
|
} else if (isBaseMessageChunk(value)) {
|
|
637
|
-
let chunk = (
|
|
638
|
-
toolCallName = (
|
|
590
|
+
let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
|
|
591
|
+
toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
|
|
639
592
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
640
|
-
toolCallArgs = (
|
|
593
|
+
toolCallArgs = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.arguments;
|
|
641
594
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
642
595
|
}
|
|
643
596
|
if (mode === "message" && (toolCallId || done)) {
|
|
644
597
|
mode = null;
|
|
645
|
-
eventStream$.sendTextMessageEnd(
|
|
646
|
-
messageId: currentMessageId
|
|
647
|
-
});
|
|
598
|
+
eventStream$.sendTextMessageEnd();
|
|
648
599
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
649
600
|
mode = null;
|
|
650
|
-
eventStream$.sendActionExecutionEnd(
|
|
651
|
-
actionExecutionId: toolCallId
|
|
652
|
-
});
|
|
601
|
+
eventStream$.sendActionExecutionEnd();
|
|
653
602
|
}
|
|
654
603
|
if (done) {
|
|
655
604
|
break;
|
|
@@ -657,40 +606,21 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
657
606
|
if (mode === null) {
|
|
658
607
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
659
608
|
mode = "function";
|
|
660
|
-
eventStream$.sendActionExecutionStart(
|
|
661
|
-
actionExecutionId: toolCallId,
|
|
662
|
-
actionName: toolCallName,
|
|
663
|
-
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
664
|
-
});
|
|
609
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
665
610
|
} else if (content) {
|
|
666
611
|
mode = "message";
|
|
667
|
-
|
|
668
|
-
eventStream$.sendTextMessageStart({
|
|
669
|
-
messageId: currentMessageId
|
|
670
|
-
});
|
|
612
|
+
eventStream$.sendTextMessageStart((0, import_shared2.randomId)());
|
|
671
613
|
}
|
|
672
614
|
}
|
|
673
615
|
if (mode === "message" && content) {
|
|
674
|
-
eventStream$.sendTextMessageContent(
|
|
675
|
-
messageId: currentMessageId,
|
|
676
|
-
content
|
|
677
|
-
});
|
|
616
|
+
eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
|
|
678
617
|
} else if (mode === "function" && toolCallArgs) {
|
|
679
618
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
680
|
-
eventStream$.sendActionExecutionEnd(
|
|
681
|
-
|
|
682
|
-
});
|
|
683
|
-
eventStream$.sendActionExecutionStart({
|
|
684
|
-
actionExecutionId: toolCallId,
|
|
685
|
-
actionName: toolCallName,
|
|
686
|
-
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
687
|
-
});
|
|
619
|
+
eventStream$.sendActionExecutionEnd();
|
|
620
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
688
621
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
689
622
|
}
|
|
690
|
-
eventStream$.sendActionExecutionArgs(
|
|
691
|
-
actionExecutionId: toolCallId,
|
|
692
|
-
args: toolCallArgs
|
|
693
|
-
});
|
|
623
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
694
624
|
}
|
|
695
625
|
} catch (error) {
|
|
696
626
|
console.error("Error reading from stream", error);
|
|
@@ -698,11 +628,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
698
628
|
}
|
|
699
629
|
}
|
|
700
630
|
} else if (actionExecution) {
|
|
701
|
-
eventStream$.sendActionExecutionResult(
|
|
702
|
-
actionExecutionId: actionExecution.id,
|
|
703
|
-
actionName: actionExecution.name,
|
|
704
|
-
result: encodeResult(result)
|
|
705
|
-
});
|
|
631
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
706
632
|
} else {
|
|
707
633
|
throw new Error("Invalid return type from LangChain function.");
|
|
708
634
|
}
|
|
@@ -882,33 +808,21 @@ var OpenAIAssistantAdapter = class {
|
|
|
882
808
|
eventSource.stream(async (eventStream$) => {
|
|
883
809
|
var _a, _b, _c, _d, _e, _f;
|
|
884
810
|
let inFunctionCall = false;
|
|
885
|
-
let currentMessageId;
|
|
886
|
-
let currentToolCallId;
|
|
887
811
|
for await (const chunk of stream) {
|
|
888
812
|
switch (chunk.event) {
|
|
889
813
|
case "thread.message.created":
|
|
890
814
|
if (inFunctionCall) {
|
|
891
|
-
eventStream$.sendActionExecutionEnd(
|
|
892
|
-
actionExecutionId: currentToolCallId
|
|
893
|
-
});
|
|
815
|
+
eventStream$.sendActionExecutionEnd();
|
|
894
816
|
}
|
|
895
|
-
|
|
896
|
-
eventStream$.sendTextMessageStart({
|
|
897
|
-
messageId: currentMessageId
|
|
898
|
-
});
|
|
817
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
899
818
|
break;
|
|
900
819
|
case "thread.message.delta":
|
|
901
820
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
902
|
-
eventStream$.sendTextMessageContent(
|
|
903
|
-
messageId: currentMessageId,
|
|
904
|
-
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
905
|
-
});
|
|
821
|
+
eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
|
|
906
822
|
}
|
|
907
823
|
break;
|
|
908
824
|
case "thread.message.completed":
|
|
909
|
-
eventStream$.sendTextMessageEnd(
|
|
910
|
-
messageId: currentMessageId
|
|
911
|
-
});
|
|
825
|
+
eventStream$.sendTextMessageEnd();
|
|
912
826
|
break;
|
|
913
827
|
case "thread.run.step.delta":
|
|
914
828
|
let toolCallId;
|
|
@@ -921,30 +835,18 @@ var OpenAIAssistantAdapter = class {
|
|
|
921
835
|
}
|
|
922
836
|
if (toolCallName && toolCallId) {
|
|
923
837
|
if (inFunctionCall) {
|
|
924
|
-
eventStream$.sendActionExecutionEnd(
|
|
925
|
-
actionExecutionId: currentToolCallId
|
|
926
|
-
});
|
|
838
|
+
eventStream$.sendActionExecutionEnd();
|
|
927
839
|
}
|
|
928
840
|
inFunctionCall = true;
|
|
929
|
-
|
|
930
|
-
eventStream$.sendActionExecutionStart({
|
|
931
|
-
actionExecutionId: currentToolCallId,
|
|
932
|
-
parentMessageId: chunk.data.id,
|
|
933
|
-
actionName: toolCallName
|
|
934
|
-
});
|
|
841
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
935
842
|
} else if (toolCallArgs) {
|
|
936
|
-
eventStream$.sendActionExecutionArgs(
|
|
937
|
-
actionExecutionId: currentToolCallId,
|
|
938
|
-
args: toolCallArgs
|
|
939
|
-
});
|
|
843
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
940
844
|
}
|
|
941
845
|
break;
|
|
942
846
|
}
|
|
943
847
|
}
|
|
944
848
|
if (inFunctionCall) {
|
|
945
|
-
eventStream$.sendActionExecutionEnd(
|
|
946
|
-
actionExecutionId: currentToolCallId
|
|
947
|
-
});
|
|
849
|
+
eventStream$.sendActionExecutionEnd();
|
|
948
850
|
}
|
|
949
851
|
eventStream$.complete();
|
|
950
852
|
});
|
|
@@ -987,7 +889,6 @@ var UnifyAdapter = class {
|
|
|
987
889
|
apiKey: this.apiKey,
|
|
988
890
|
baseURL: "https://api.unify.ai/v0/"
|
|
989
891
|
});
|
|
990
|
-
const forwardedParameters = request.forwardedParameters;
|
|
991
892
|
const messages = request.messages.map(convertMessageToOpenAIMessage);
|
|
992
893
|
const stream = await openai.chat.completions.create({
|
|
993
894
|
model: this.model,
|
|
@@ -995,83 +896,49 @@ var UnifyAdapter = class {
|
|
|
995
896
|
stream: true,
|
|
996
897
|
...tools.length > 0 && {
|
|
997
898
|
tools
|
|
998
|
-
},
|
|
999
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
1000
|
-
temperature: forwardedParameters.temperature
|
|
1001
899
|
}
|
|
1002
900
|
});
|
|
1003
901
|
let model = null;
|
|
1004
|
-
let currentMessageId;
|
|
1005
|
-
let currentToolCallId;
|
|
1006
902
|
request.eventSource.stream(async (eventStream$) => {
|
|
1007
903
|
var _a, _b;
|
|
1008
904
|
let mode = null;
|
|
1009
905
|
for await (const chunk of stream) {
|
|
1010
906
|
if (this.start) {
|
|
1011
907
|
model = chunk.model;
|
|
1012
|
-
|
|
1013
|
-
eventStream$.
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
eventStream$.sendTextMessageContent({
|
|
1017
|
-
messageId: currentMessageId,
|
|
1018
|
-
content: `Model used: ${model}
|
|
1019
|
-
`
|
|
1020
|
-
});
|
|
1021
|
-
eventStream$.sendTextMessageEnd({
|
|
1022
|
-
messageId: currentMessageId
|
|
1023
|
-
});
|
|
908
|
+
eventStream$.sendTextMessageStart((0, import_shared4.randomId)());
|
|
909
|
+
eventStream$.sendTextMessageContent(`Model used: ${model}
|
|
910
|
+
`);
|
|
911
|
+
eventStream$.sendTextMessageEnd();
|
|
1024
912
|
this.start = false;
|
|
1025
913
|
}
|
|
1026
914
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1027
915
|
const content = chunk.choices[0].delta.content;
|
|
1028
916
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1029
917
|
mode = null;
|
|
1030
|
-
eventStream$.sendTextMessageEnd(
|
|
1031
|
-
messageId: currentMessageId
|
|
1032
|
-
});
|
|
918
|
+
eventStream$.sendTextMessageEnd();
|
|
1033
919
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1034
920
|
mode = null;
|
|
1035
|
-
eventStream$.sendActionExecutionEnd(
|
|
1036
|
-
actionExecutionId: currentToolCallId
|
|
1037
|
-
});
|
|
921
|
+
eventStream$.sendActionExecutionEnd();
|
|
1038
922
|
}
|
|
1039
923
|
if (mode === null) {
|
|
1040
924
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1041
925
|
mode = "function";
|
|
1042
|
-
|
|
1043
|
-
eventStream$.sendActionExecutionStart({
|
|
1044
|
-
actionExecutionId: currentToolCallId,
|
|
1045
|
-
actionName: toolCall.function.name
|
|
1046
|
-
});
|
|
926
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1047
927
|
} else if (content) {
|
|
1048
928
|
mode = "message";
|
|
1049
|
-
|
|
1050
|
-
eventStream$.sendTextMessageStart({
|
|
1051
|
-
messageId: currentMessageId
|
|
1052
|
-
});
|
|
929
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1053
930
|
}
|
|
1054
931
|
}
|
|
1055
932
|
if (mode === "message" && content) {
|
|
1056
|
-
eventStream$.sendTextMessageContent(
|
|
1057
|
-
messageId: currentMessageId,
|
|
1058
|
-
content
|
|
1059
|
-
});
|
|
933
|
+
eventStream$.sendTextMessageContent(content);
|
|
1060
934
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1061
|
-
eventStream$.sendActionExecutionArgs(
|
|
1062
|
-
actionExecutionId: currentToolCallId,
|
|
1063
|
-
args: toolCall.function.arguments
|
|
1064
|
-
});
|
|
935
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1065
936
|
}
|
|
1066
937
|
}
|
|
1067
938
|
if (mode === "message") {
|
|
1068
|
-
eventStream$.sendTextMessageEnd(
|
|
1069
|
-
messageId: currentMessageId
|
|
1070
|
-
});
|
|
939
|
+
eventStream$.sendTextMessageEnd();
|
|
1071
940
|
} else if (mode === "function") {
|
|
1072
|
-
eventStream$.sendActionExecutionEnd(
|
|
1073
|
-
actionExecutionId: currentToolCallId
|
|
1074
|
-
});
|
|
941
|
+
eventStream$.sendActionExecutionEnd();
|
|
1075
942
|
}
|
|
1076
943
|
eventStream$.complete();
|
|
1077
944
|
});
|
|
@@ -1132,67 +999,40 @@ var GroqAdapter = class {
|
|
|
1132
999
|
},
|
|
1133
1000
|
...this.disableParallelToolCalls && {
|
|
1134
1001
|
parallel_tool_calls: false
|
|
1135
|
-
},
|
|
1136
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
1137
|
-
temperature: forwardedParameters.temperature
|
|
1138
1002
|
}
|
|
1139
1003
|
});
|
|
1140
1004
|
eventSource.stream(async (eventStream$) => {
|
|
1141
1005
|
var _a, _b;
|
|
1142
1006
|
let mode = null;
|
|
1143
|
-
let currentMessageId;
|
|
1144
|
-
let currentToolCallId;
|
|
1145
1007
|
for await (const chunk of stream) {
|
|
1146
1008
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1147
1009
|
const content = chunk.choices[0].delta.content;
|
|
1148
1010
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1149
1011
|
mode = null;
|
|
1150
|
-
eventStream$.sendTextMessageEnd(
|
|
1151
|
-
messageId: currentMessageId
|
|
1152
|
-
});
|
|
1012
|
+
eventStream$.sendTextMessageEnd();
|
|
1153
1013
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1154
1014
|
mode = null;
|
|
1155
|
-
eventStream$.sendActionExecutionEnd(
|
|
1156
|
-
actionExecutionId: currentToolCallId
|
|
1157
|
-
});
|
|
1015
|
+
eventStream$.sendActionExecutionEnd();
|
|
1158
1016
|
}
|
|
1159
1017
|
if (mode === null) {
|
|
1160
1018
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1161
1019
|
mode = "function";
|
|
1162
|
-
|
|
1163
|
-
eventStream$.sendActionExecutionStart({
|
|
1164
|
-
actionExecutionId: currentToolCallId,
|
|
1165
|
-
actionName: toolCall.function.name,
|
|
1166
|
-
parentMessageId: chunk.id
|
|
1167
|
-
});
|
|
1020
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1168
1021
|
} else if (content) {
|
|
1169
1022
|
mode = "message";
|
|
1170
|
-
|
|
1171
|
-
eventStream$.sendTextMessageStart({
|
|
1172
|
-
messageId: currentMessageId
|
|
1173
|
-
});
|
|
1023
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1174
1024
|
}
|
|
1175
1025
|
}
|
|
1176
1026
|
if (mode === "message" && content) {
|
|
1177
|
-
eventStream$.sendTextMessageContent(
|
|
1178
|
-
messageId: currentMessageId,
|
|
1179
|
-
content
|
|
1180
|
-
});
|
|
1027
|
+
eventStream$.sendTextMessageContent(content);
|
|
1181
1028
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1182
|
-
eventStream$.sendActionExecutionArgs(
|
|
1183
|
-
actionExecutionId: currentToolCallId,
|
|
1184
|
-
args: toolCall.function.arguments
|
|
1185
|
-
});
|
|
1029
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1186
1030
|
}
|
|
1187
1031
|
}
|
|
1188
1032
|
if (mode === "message") {
|
|
1189
|
-
eventStream$.sendTextMessageEnd(
|
|
1190
|
-
messageId: currentMessageId
|
|
1191
|
-
});
|
|
1033
|
+
eventStream$.sendTextMessageEnd();
|
|
1192
1034
|
} else if (mode === "function") {
|
|
1193
|
-
eventStream$.sendActionExecutionEnd(
|
|
1194
|
-
actionExecutionId: currentToolCallId
|
|
1195
|
-
});
|
|
1035
|
+
eventStream$.sendActionExecutionEnd();
|
|
1196
1036
|
}
|
|
1197
1037
|
eventStream$.complete();
|
|
1198
1038
|
});
|
|
@@ -1253,167 +1093,163 @@ var RemoteLangGraphEventSource = class {
|
|
|
1253
1093
|
}
|
|
1254
1094
|
return shouldEmitToolCalls === toolCallName;
|
|
1255
1095
|
}
|
|
1256
|
-
getCurrentContent(event) {
|
|
1257
|
-
var _a, _b, _c, _d, _e;
|
|
1258
|
-
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);
|
|
1259
|
-
if (!content) {
|
|
1260
|
-
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1261
|
-
for (const chunk of toolCallChunks) {
|
|
1262
|
-
if (chunk.args) {
|
|
1263
|
-
return chunk.args;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
if (typeof content === "string") {
|
|
1268
|
-
return content;
|
|
1269
|
-
} else if (Array.isArray(content) && content.length > 0) {
|
|
1270
|
-
return content[0].text;
|
|
1271
|
-
}
|
|
1272
|
-
return null;
|
|
1273
|
-
}
|
|
1274
|
-
getCurrentMessageId(event) {
|
|
1275
|
-
var _a, _b, _c, _d, _e;
|
|
1276
|
-
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);
|
|
1277
|
-
}
|
|
1278
|
-
getCurrentToolCallChunks(event) {
|
|
1279
|
-
var _a, _b, _c, _d, _e;
|
|
1280
|
-
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);
|
|
1281
|
-
}
|
|
1282
|
-
getResponseMetadata(event) {
|
|
1283
|
-
var _a, _b, _c, _d, _e;
|
|
1284
|
-
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);
|
|
1285
|
-
}
|
|
1286
1096
|
processLangGraphEvents() {
|
|
1287
1097
|
let lastEventWithState = null;
|
|
1288
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;
|
|
1289
1100
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1290
|
-
const
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
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;
|
|
1304
1138
|
}
|
|
1305
1139
|
acc.event = event;
|
|
1306
1140
|
lastEventWithState = acc;
|
|
1307
1141
|
return acc;
|
|
1308
1142
|
}, {
|
|
1309
1143
|
event: null,
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
}), (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;
|
|
1320
1153
|
const events = [];
|
|
1321
1154
|
let shouldEmitMessages = true;
|
|
1322
|
-
let shouldEmitToolCalls =
|
|
1323
|
-
if (
|
|
1324
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1325
|
-
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"];
|
|
1326
1159
|
}
|
|
1327
|
-
if ("copilotkit:emit-messages" in (
|
|
1328
|
-
shouldEmitMessages =
|
|
1160
|
+
if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
|
|
1161
|
+
shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
|
|
1329
1162
|
}
|
|
1330
1163
|
}
|
|
1331
|
-
|
|
1332
|
-
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)) {
|
|
1333
1165
|
events.push({
|
|
1334
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1335
|
-
actionExecutionId: acc.lastToolCallId
|
|
1166
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1336
1167
|
});
|
|
1337
1168
|
}
|
|
1338
|
-
if (
|
|
1169
|
+
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1339
1170
|
events.push({
|
|
1340
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1341
|
-
messageId: acc.lastMessageId
|
|
1171
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1342
1172
|
});
|
|
1343
1173
|
}
|
|
1344
|
-
switch (
|
|
1174
|
+
switch (eventWithState.event.event) {
|
|
1345
1175
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1346
|
-
if (
|
|
1176
|
+
if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1347
1177
|
events.push({
|
|
1348
1178
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1349
|
-
messageId:
|
|
1179
|
+
messageId: eventWithState.event.data.message_id
|
|
1350
1180
|
});
|
|
1351
1181
|
events.push({
|
|
1352
1182
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1353
|
-
|
|
1354
|
-
content: acc.event.data.message
|
|
1183
|
+
content: eventWithState.event.data.message
|
|
1355
1184
|
});
|
|
1356
1185
|
events.push({
|
|
1357
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1358
|
-
messageId: acc.event.data.message_id
|
|
1186
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1359
1187
|
});
|
|
1360
|
-
} else if (
|
|
1188
|
+
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1361
1189
|
events.push({
|
|
1362
1190
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1363
|
-
actionExecutionId:
|
|
1364
|
-
actionName:
|
|
1365
|
-
parentMessageId: acc.event.data.id
|
|
1191
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1192
|
+
actionName: eventWithState.event.data.name
|
|
1366
1193
|
});
|
|
1367
1194
|
events.push({
|
|
1368
1195
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1369
|
-
|
|
1370
|
-
args: JSON.stringify(acc.event.data.args)
|
|
1196
|
+
args: JSON.stringify(eventWithState.event.data.args)
|
|
1371
1197
|
});
|
|
1372
1198
|
events.push({
|
|
1373
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1374
|
-
actionExecutionId: acc.event.data.id
|
|
1199
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1375
1200
|
});
|
|
1376
1201
|
}
|
|
1377
1202
|
break;
|
|
1378
1203
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1379
1204
|
events.push({
|
|
1380
1205
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1381
|
-
threadId:
|
|
1382
|
-
role:
|
|
1383
|
-
agentName:
|
|
1384
|
-
nodeName:
|
|
1385
|
-
runId:
|
|
1386
|
-
active:
|
|
1387
|
-
state: JSON.stringify(
|
|
1388
|
-
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
|
|
1389
1214
|
});
|
|
1390
1215
|
break;
|
|
1216
|
+
case LangGraphEventTypes.OnToolEnd:
|
|
1217
|
+
break;
|
|
1391
1218
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1392
|
-
if (
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
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
|
+
}
|
|
1404
1235
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
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
|
+
}
|
|
1417
1253
|
}
|
|
1418
1254
|
break;
|
|
1419
1255
|
}
|
|
@@ -1421,16 +1257,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1421
1257
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1422
1258
|
console.error(error);
|
|
1423
1259
|
const events = [];
|
|
1424
|
-
if (
|
|
1260
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1425
1261
|
events.push({
|
|
1426
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1427
|
-
messageId: lastEventWithState.lastMessageId
|
|
1262
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1428
1263
|
});
|
|
1429
1264
|
}
|
|
1430
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1265
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1431
1266
|
events.push({
|
|
1432
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1433
|
-
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1267
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1434
1268
|
});
|
|
1435
1269
|
}
|
|
1436
1270
|
const messageId = (0, import_shared6.randomId)();
|
|
@@ -1440,12 +1274,10 @@ var RemoteLangGraphEventSource = class {
|
|
|
1440
1274
|
});
|
|
1441
1275
|
events.push({
|
|
1442
1276
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1443
|
-
messageId,
|
|
1444
1277
|
content: "\u274C An error occurred. Please try again."
|
|
1445
1278
|
});
|
|
1446
1279
|
events.push({
|
|
1447
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1448
|
-
messageId
|
|
1280
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1449
1281
|
});
|
|
1450
1282
|
return events;
|
|
1451
1283
|
}));
|
|
@@ -1467,6 +1299,12 @@ var MessageRole;
|
|
|
1467
1299
|
MessageRole2["system"] = "system";
|
|
1468
1300
|
MessageRole2["tool"] = "tool";
|
|
1469
1301
|
})(MessageRole || (MessageRole = {}));
|
|
1302
|
+
var ActionExecutionScope;
|
|
1303
|
+
(function(ActionExecutionScope2) {
|
|
1304
|
+
ActionExecutionScope2["server"] = "server";
|
|
1305
|
+
ActionExecutionScope2["client"] = "client";
|
|
1306
|
+
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1307
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1470
1308
|
var CopilotRequestType;
|
|
1471
1309
|
(function(CopilotRequestType2) {
|
|
1472
1310
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1485,6 +1323,10 @@ var ActionInputAvailability;
|
|
|
1485
1323
|
name: "MessageRole",
|
|
1486
1324
|
description: "The role of the message"
|
|
1487
1325
|
});
|
|
1326
|
+
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1327
|
+
name: "ActionExecutionScope",
|
|
1328
|
+
description: "The scope of the action"
|
|
1329
|
+
});
|
|
1488
1330
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1489
1331
|
name: "CopilotRequestType",
|
|
1490
1332
|
description: "The type of Copilot request"
|
|
@@ -1522,6 +1364,8 @@ async function streamEvents(controller, args) {
|
|
|
1522
1364
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1523
1365
|
initialThreadId = initialThreadId.substring(3);
|
|
1524
1366
|
}
|
|
1367
|
+
const assistants = await client.assistants.search();
|
|
1368
|
+
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1525
1369
|
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1526
1370
|
if (initialThreadId === threadId) {
|
|
1527
1371
|
await client.threads.get(threadId);
|
|
@@ -1541,7 +1385,7 @@ async function streamEvents(controller, args) {
|
|
|
1541
1385
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1542
1386
|
let formattedMessages = [];
|
|
1543
1387
|
try {
|
|
1544
|
-
formattedMessages =
|
|
1388
|
+
formattedMessages = formatMessages(messages);
|
|
1545
1389
|
} catch (e) {
|
|
1546
1390
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1547
1391
|
}
|
|
@@ -1552,16 +1396,8 @@ async function streamEvents(controller, args) {
|
|
|
1552
1396
|
asNode: nodeName
|
|
1553
1397
|
});
|
|
1554
1398
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
};
|
|
1558
|
-
const assistants = await client.assistants.search();
|
|
1559
|
-
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1560
|
-
if (!retrievedAssistant) {
|
|
1561
|
-
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1562
|
-
...streamInfo,
|
|
1563
|
-
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1564
|
-
});
|
|
1399
|
+
const assistantId = initialAssistantId ?? (retrievedAssistant == null ? void 0 : retrievedAssistant.assistant_id);
|
|
1400
|
+
if (!assistantId) {
|
|
1565
1401
|
console.error(`
|
|
1566
1402
|
No agent found for the agent name specified in CopilotKit provider
|
|
1567
1403
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1571,7 +1407,6 @@ async function streamEvents(controller, args) {
|
|
|
1571
1407
|
`);
|
|
1572
1408
|
throw new Error("No agent id found");
|
|
1573
1409
|
}
|
|
1574
|
-
const assistantId = retrievedAssistant.assistant_id;
|
|
1575
1410
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1576
1411
|
const streamInput = mode === "start" ? state : null;
|
|
1577
1412
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1590,6 +1425,9 @@ async function streamEvents(controller, args) {
|
|
|
1590
1425
|
let latestStateValues = {};
|
|
1591
1426
|
let updatedState = state;
|
|
1592
1427
|
let manuallyEmittedState = null;
|
|
1428
|
+
let streamInfo = {
|
|
1429
|
+
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1430
|
+
};
|
|
1593
1431
|
try {
|
|
1594
1432
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1595
1433
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1602,6 +1440,7 @@ async function streamEvents(controller, args) {
|
|
|
1602
1440
|
].includes(chunk.event))
|
|
1603
1441
|
continue;
|
|
1604
1442
|
if (chunk.event === "error") {
|
|
1443
|
+
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1605
1444
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1606
1445
|
}
|
|
1607
1446
|
if (chunk.event === "values") {
|
|
@@ -1694,34 +1533,21 @@ async function streamEvents(controller, args) {
|
|
|
1694
1533
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1695
1534
|
state: state.values,
|
|
1696
1535
|
running: !shouldExit,
|
|
1697
|
-
active: false
|
|
1698
|
-
includeMessages: true
|
|
1536
|
+
active: false
|
|
1699
1537
|
}));
|
|
1700
1538
|
return Promise.resolve();
|
|
1701
1539
|
} catch (e) {
|
|
1702
|
-
logger2.error(e);
|
|
1703
|
-
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1704
|
-
...streamInfo,
|
|
1705
|
-
error: e.message
|
|
1706
|
-
});
|
|
1707
1540
|
return Promise.resolve();
|
|
1708
1541
|
}
|
|
1709
1542
|
}
|
|
1710
1543
|
__name(streamEvents, "streamEvents");
|
|
1711
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
}, {});
|
|
1719
|
-
} else {
|
|
1720
|
-
state = {
|
|
1721
|
-
...state,
|
|
1722
|
-
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1544
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1545
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1546
|
+
if (key !== "messages") {
|
|
1547
|
+
acc[key] = state[key];
|
|
1548
|
+
}
|
|
1549
|
+
return acc;
|
|
1550
|
+
}, {});
|
|
1725
1551
|
return JSON.stringify({
|
|
1726
1552
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1727
1553
|
thread_id: threadId,
|
|
@@ -1729,7 +1555,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1729
1555
|
agent_name: agentName,
|
|
1730
1556
|
node_name: nodeName,
|
|
1731
1557
|
active,
|
|
1732
|
-
state,
|
|
1558
|
+
state: stateWithoutMessages,
|
|
1733
1559
|
running,
|
|
1734
1560
|
role: "assistant"
|
|
1735
1561
|
}) + "\n";
|
|
@@ -1805,157 +1631,134 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1805
1631
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1806
1632
|
messages = messages.slice(1);
|
|
1807
1633
|
}
|
|
1808
|
-
const
|
|
1809
|
-
const existingMessageIds = new Set(
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
copilotkit: {
|
|
1815
|
-
actions
|
|
1816
|
-
}
|
|
1817
|
-
};
|
|
1818
|
-
}
|
|
1819
|
-
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1820
|
-
function langchainMessagesToCopilotKit(messages) {
|
|
1821
|
-
const result = [];
|
|
1822
|
-
const tool_call_names = {};
|
|
1823
|
-
for (const message of messages) {
|
|
1824
|
-
if (message.type === "ai") {
|
|
1825
|
-
for (const tool_call of message.tool_calls) {
|
|
1826
|
-
tool_call_names[tool_call.id] = tool_call.name;
|
|
1827
|
-
}
|
|
1634
|
+
const mergedMessages = state.messages || [];
|
|
1635
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1636
|
+
const existingToolCallResults = /* @__PURE__ */ new Set();
|
|
1637
|
+
for (const message of mergedMessages) {
|
|
1638
|
+
if ("tool_call_id" in message) {
|
|
1639
|
+
existingToolCallResults.add(message.tool_call_id);
|
|
1828
1640
|
}
|
|
1829
1641
|
}
|
|
1830
1642
|
for (const message of messages) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
content = content[0];
|
|
1643
|
+
if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
|
|
1644
|
+
continue;
|
|
1834
1645
|
}
|
|
1835
|
-
if (
|
|
1836
|
-
|
|
1646
|
+
if ("name" in message && message.name === agentName) {
|
|
1647
|
+
continue;
|
|
1837
1648
|
}
|
|
1838
|
-
if (message.
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
} else
|
|
1845
|
-
|
|
1846
|
-
role
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
for (const tool_call of message.tool_calls) {
|
|
1853
|
-
result.push({
|
|
1854
|
-
id: tool_call.id,
|
|
1855
|
-
name: tool_call.name,
|
|
1856
|
-
arguments: tool_call.args,
|
|
1857
|
-
parentMessageId: message.id
|
|
1858
|
-
});
|
|
1649
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1650
|
+
if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
|
|
1651
|
+
console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
mergedMessages.push(message);
|
|
1655
|
+
} else {
|
|
1656
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1657
|
+
if (mergedMessages[i].id === message.id && message.role === "assistant") {
|
|
1658
|
+
if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
|
|
1659
|
+
message.tool_calls = mergedMessages[i]["tool_calls"];
|
|
1660
|
+
message.additional_kwargs = mergedMessages[i].additional_kwargs;
|
|
1661
|
+
}
|
|
1662
|
+
mergedMessages[i] = message;
|
|
1859
1663
|
}
|
|
1860
|
-
} else {
|
|
1861
|
-
result.push({
|
|
1862
|
-
role: "assistant",
|
|
1863
|
-
content,
|
|
1864
|
-
id: message.id,
|
|
1865
|
-
parentMessageId: message.id
|
|
1866
|
-
});
|
|
1867
1664
|
}
|
|
1868
|
-
} else if (message.type === "tool") {
|
|
1869
|
-
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1870
|
-
result.push({
|
|
1871
|
-
actionExecutionId: message.tool_call_id,
|
|
1872
|
-
actionName,
|
|
1873
|
-
result: content,
|
|
1874
|
-
id: message.id
|
|
1875
|
-
});
|
|
1876
1665
|
}
|
|
1877
1666
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1667
|
+
for (let i = 0; i < mergedMessages.length - 1; i++) {
|
|
1668
|
+
const currentMessage = mergedMessages[i];
|
|
1669
|
+
const nextMessage = mergedMessages[i + 1];
|
|
1670
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
|
|
1671
|
+
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1882
1672
|
}
|
|
1883
1673
|
}
|
|
1884
|
-
const
|
|
1885
|
-
for (
|
|
1886
|
-
|
|
1887
|
-
|
|
1674
|
+
const correctedMessages = [];
|
|
1675
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1676
|
+
const currentMessage = mergedMessages[i];
|
|
1677
|
+
const nextMessage = mergedMessages[i + 1] || null;
|
|
1678
|
+
const prevMessage = mergedMessages[i - 1] || null;
|
|
1679
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1680
|
+
if (!nextMessage) {
|
|
1681
|
+
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1685
|
+
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1686
|
+
if (toolMessage) {
|
|
1687
|
+
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1688
|
+
correctedMessages.push(currentMessage, toolMessage);
|
|
1689
|
+
continue;
|
|
1690
|
+
} else {
|
|
1691
|
+
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1692
|
+
continue;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
correctedMessages.push(currentMessage);
|
|
1696
|
+
continue;
|
|
1888
1697
|
}
|
|
1889
|
-
if ("
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1698
|
+
if ("tool_call_id" in currentMessage) {
|
|
1699
|
+
if (!prevMessage || !("tool_calls" in prevMessage)) {
|
|
1700
|
+
console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
|
|
1701
|
+
continue;
|
|
1893
1702
|
}
|
|
1703
|
+
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1704
|
+
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
correctedMessages.push(currentMessage);
|
|
1708
|
+
continue;
|
|
1894
1709
|
}
|
|
1710
|
+
correctedMessages.push(currentMessage);
|
|
1895
1711
|
}
|
|
1896
|
-
return
|
|
1712
|
+
return {
|
|
1713
|
+
...state,
|
|
1714
|
+
messages: correctedMessages,
|
|
1715
|
+
copilotkit: {
|
|
1716
|
+
actions
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1897
1719
|
}
|
|
1898
|
-
__name(
|
|
1899
|
-
function
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
} else if (message.role === "system") {
|
|
1910
|
-
result.push({
|
|
1911
|
-
...message,
|
|
1912
|
-
role: MessageRole.system
|
|
1913
|
-
});
|
|
1914
|
-
} else if (message.role === "assistant") {
|
|
1915
|
-
result.push({
|
|
1916
|
-
...message,
|
|
1917
|
-
role: MessageRole.assistant
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
continue;
|
|
1720
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1721
|
+
function formatMessages(messages) {
|
|
1722
|
+
return messages.map((message) => {
|
|
1723
|
+
if (message.isTextMessage() && message.role === "assistant") {
|
|
1724
|
+
return message;
|
|
1725
|
+
}
|
|
1726
|
+
if (message.isTextMessage() && message.role === "system") {
|
|
1727
|
+
return message;
|
|
1728
|
+
}
|
|
1729
|
+
if (message.isTextMessage() && message.role === "user") {
|
|
1730
|
+
return message;
|
|
1921
1731
|
}
|
|
1922
1732
|
if (message.isActionExecutionMessage()) {
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
name: m.name,
|
|
1931
|
-
args: m.arguments,
|
|
1932
|
-
id: m.id
|
|
1933
|
-
}));
|
|
1934
|
-
result.push({
|
|
1935
|
-
id: messageId,
|
|
1936
|
-
type: "ActionExecutionMessage",
|
|
1733
|
+
const toolCall = {
|
|
1734
|
+
name: message.name,
|
|
1735
|
+
args: message.arguments,
|
|
1736
|
+
id: message.id
|
|
1737
|
+
};
|
|
1738
|
+
return {
|
|
1739
|
+
type: message.type,
|
|
1937
1740
|
content: "",
|
|
1938
|
-
tool_calls
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1741
|
+
tool_calls: [
|
|
1742
|
+
toolCall
|
|
1743
|
+
],
|
|
1744
|
+
role: MessageRole.assistant,
|
|
1745
|
+
id: message.id
|
|
1746
|
+
};
|
|
1942
1747
|
}
|
|
1943
1748
|
if (message.isResultMessage()) {
|
|
1944
|
-
|
|
1749
|
+
return {
|
|
1945
1750
|
type: message.type,
|
|
1946
1751
|
content: message.result,
|
|
1947
1752
|
id: message.id,
|
|
1948
1753
|
tool_call_id: message.actionExecutionId,
|
|
1949
1754
|
name: message.actionName,
|
|
1950
1755
|
role: MessageRole.tool
|
|
1951
|
-
}
|
|
1952
|
-
continue;
|
|
1756
|
+
};
|
|
1953
1757
|
}
|
|
1954
1758
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1955
|
-
}
|
|
1956
|
-
return result;
|
|
1759
|
+
});
|
|
1957
1760
|
}
|
|
1958
|
-
__name(
|
|
1761
|
+
__name(formatMessages, "formatMessages");
|
|
1959
1762
|
|
|
1960
1763
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1961
1764
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1965,7 +1768,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1965
1768
|
parameters: [],
|
|
1966
1769
|
handler: async (_args) => {
|
|
1967
1770
|
},
|
|
1968
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1771
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1969
1772
|
var _a;
|
|
1970
1773
|
logger2.debug({
|
|
1971
1774
|
actionName: agent.name
|
|
@@ -1991,10 +1794,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1991
1794
|
agent,
|
|
1992
1795
|
threadId,
|
|
1993
1796
|
nodeName,
|
|
1994
|
-
messages
|
|
1995
|
-
...messages,
|
|
1996
|
-
...additionalMessages
|
|
1997
|
-
],
|
|
1797
|
+
messages,
|
|
1998
1798
|
state,
|
|
1999
1799
|
properties: graphqlContext.properties,
|
|
2000
1800
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2022,7 +1822,6 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2022
1822
|
}
|
|
2023
1823
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2024
1824
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2025
|
-
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2026
1825
|
const actions = json["actions"].map((action) => ({
|
|
2027
1826
|
name: action.name,
|
|
2028
1827
|
description: action.description,
|
|
@@ -2036,7 +1835,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2036
1835
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2037
1836
|
agentExecution: false,
|
|
2038
1837
|
type: "self-hosted",
|
|
2039
|
-
agentsAmount:
|
|
1838
|
+
agentsAmount: json["agents"].length
|
|
2040
1839
|
});
|
|
2041
1840
|
try {
|
|
2042
1841
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2071,13 +1870,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2071
1870
|
}
|
|
2072
1871
|
}
|
|
2073
1872
|
}));
|
|
2074
|
-
const agents =
|
|
1873
|
+
const agents = json["agents"].map((agent) => ({
|
|
2075
1874
|
name: agent.name,
|
|
2076
1875
|
description: agent.description,
|
|
2077
1876
|
parameters: [],
|
|
2078
1877
|
handler: async (_args) => {
|
|
2079
1878
|
},
|
|
2080
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1879
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2081
1880
|
var _a;
|
|
2082
1881
|
logger2.debug({
|
|
2083
1882
|
actionName: agent.name
|
|
@@ -2102,10 +1901,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2102
1901
|
name,
|
|
2103
1902
|
threadId,
|
|
2104
1903
|
nodeName,
|
|
2105
|
-
messages
|
|
2106
|
-
...messages,
|
|
2107
|
-
...additionalMessages
|
|
2108
|
-
],
|
|
1904
|
+
messages,
|
|
2109
1905
|
state,
|
|
2110
1906
|
properties: graphqlContext.properties,
|
|
2111
1907
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2127,7 +1923,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2127
1923
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2128
1924
|
return eventSource.processLangGraphEvents();
|
|
2129
1925
|
}
|
|
2130
|
-
}))
|
|
1926
|
+
}));
|
|
2131
1927
|
return [
|
|
2132
1928
|
...actions,
|
|
2133
1929
|
...agents
|
|
@@ -2348,94 +2144,7 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2348
2144
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2349
2145
|
var telemetry_client_default = telemetryClient;
|
|
2350
2146
|
|
|
2351
|
-
// src/graphql/types/base/index.ts
|
|
2352
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2353
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2354
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2355
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2356
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2357
|
-
else
|
|
2358
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2359
|
-
if (d = decorators[i])
|
|
2360
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2361
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2362
|
-
}
|
|
2363
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2364
|
-
function _ts_metadata(k, v) {
|
|
2365
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2366
|
-
return Reflect.metadata(k, v);
|
|
2367
|
-
}
|
|
2368
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2369
|
-
var BaseMessageInput = class {
|
|
2370
|
-
id;
|
|
2371
|
-
createdAt;
|
|
2372
|
-
};
|
|
2373
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2374
|
-
_ts_decorate([
|
|
2375
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2376
|
-
_ts_metadata("design:type", String)
|
|
2377
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2378
|
-
_ts_decorate([
|
|
2379
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2380
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2381
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2382
|
-
BaseMessageInput = _ts_decorate([
|
|
2383
|
-
(0, import_type_graphql2.InputType)()
|
|
2384
|
-
], BaseMessageInput);
|
|
2385
|
-
|
|
2386
|
-
// src/graphql/types/converted/index.ts
|
|
2387
|
-
var Message = class extends BaseMessageInput {
|
|
2388
|
-
type;
|
|
2389
|
-
isTextMessage() {
|
|
2390
|
-
return this.type === "TextMessage";
|
|
2391
|
-
}
|
|
2392
|
-
isActionExecutionMessage() {
|
|
2393
|
-
return this.type === "ActionExecutionMessage";
|
|
2394
|
-
}
|
|
2395
|
-
isResultMessage() {
|
|
2396
|
-
return this.type === "ResultMessage";
|
|
2397
|
-
}
|
|
2398
|
-
isAgentStateMessage() {
|
|
2399
|
-
return this.type === "AgentStateMessage";
|
|
2400
|
-
}
|
|
2401
|
-
};
|
|
2402
|
-
__name(Message, "Message");
|
|
2403
|
-
var TextMessage = class extends Message {
|
|
2404
|
-
type = "TextMessage";
|
|
2405
|
-
content;
|
|
2406
|
-
role;
|
|
2407
|
-
parentMessageId;
|
|
2408
|
-
};
|
|
2409
|
-
__name(TextMessage, "TextMessage");
|
|
2410
|
-
var ActionExecutionMessage = class extends Message {
|
|
2411
|
-
type = "ActionExecutionMessage";
|
|
2412
|
-
name;
|
|
2413
|
-
arguments;
|
|
2414
|
-
parentMessageId;
|
|
2415
|
-
};
|
|
2416
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2417
|
-
var ResultMessage = class extends Message {
|
|
2418
|
-
type = "ResultMessage";
|
|
2419
|
-
actionExecutionId;
|
|
2420
|
-
actionName;
|
|
2421
|
-
result;
|
|
2422
|
-
};
|
|
2423
|
-
__name(ResultMessage, "ResultMessage");
|
|
2424
|
-
var AgentStateMessage = class extends Message {
|
|
2425
|
-
type = "AgentStateMessage";
|
|
2426
|
-
threadId;
|
|
2427
|
-
agentName;
|
|
2428
|
-
nodeName;
|
|
2429
|
-
runId;
|
|
2430
|
-
active;
|
|
2431
|
-
role;
|
|
2432
|
-
state;
|
|
2433
|
-
running;
|
|
2434
|
-
};
|
|
2435
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2436
|
-
|
|
2437
2147
|
// src/service-adapters/events.ts
|
|
2438
|
-
var import_class_transformer = require("class-transformer");
|
|
2439
2148
|
var RuntimeEventTypes;
|
|
2440
2149
|
(function(RuntimeEventTypes2) {
|
|
2441
2150
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2451,74 +2160,52 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2451
2160
|
constructor() {
|
|
2452
2161
|
super();
|
|
2453
2162
|
}
|
|
2454
|
-
sendTextMessageStart(
|
|
2163
|
+
sendTextMessageStart(messageId) {
|
|
2455
2164
|
this.next({
|
|
2456
2165
|
type: "TextMessageStart",
|
|
2457
|
-
messageId
|
|
2458
|
-
parentMessageId
|
|
2166
|
+
messageId
|
|
2459
2167
|
});
|
|
2460
2168
|
}
|
|
2461
|
-
sendTextMessageContent(
|
|
2169
|
+
sendTextMessageContent(content) {
|
|
2462
2170
|
this.next({
|
|
2463
2171
|
type: "TextMessageContent",
|
|
2464
|
-
content
|
|
2465
|
-
messageId
|
|
2172
|
+
content
|
|
2466
2173
|
});
|
|
2467
2174
|
}
|
|
2468
|
-
sendTextMessageEnd(
|
|
2175
|
+
sendTextMessageEnd() {
|
|
2469
2176
|
this.next({
|
|
2470
|
-
type: "TextMessageEnd"
|
|
2471
|
-
messageId
|
|
2177
|
+
type: "TextMessageEnd"
|
|
2472
2178
|
});
|
|
2473
2179
|
}
|
|
2474
2180
|
sendTextMessage(messageId, content) {
|
|
2475
|
-
this.sendTextMessageStart(
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
this.sendTextMessageContent({
|
|
2479
|
-
messageId,
|
|
2480
|
-
content
|
|
2481
|
-
});
|
|
2482
|
-
this.sendTextMessageEnd({
|
|
2483
|
-
messageId
|
|
2484
|
-
});
|
|
2181
|
+
this.sendTextMessageStart(messageId);
|
|
2182
|
+
this.sendTextMessageContent(content);
|
|
2183
|
+
this.sendTextMessageEnd();
|
|
2485
2184
|
}
|
|
2486
|
-
sendActionExecutionStart(
|
|
2185
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2487
2186
|
this.next({
|
|
2488
2187
|
type: "ActionExecutionStart",
|
|
2489
2188
|
actionExecutionId,
|
|
2490
|
-
actionName
|
|
2491
|
-
parentMessageId
|
|
2189
|
+
actionName
|
|
2492
2190
|
});
|
|
2493
2191
|
}
|
|
2494
|
-
sendActionExecutionArgs(
|
|
2192
|
+
sendActionExecutionArgs(args) {
|
|
2495
2193
|
this.next({
|
|
2496
2194
|
type: "ActionExecutionArgs",
|
|
2497
|
-
args
|
|
2498
|
-
actionExecutionId
|
|
2195
|
+
args
|
|
2499
2196
|
});
|
|
2500
2197
|
}
|
|
2501
|
-
sendActionExecutionEnd(
|
|
2198
|
+
sendActionExecutionEnd() {
|
|
2502
2199
|
this.next({
|
|
2503
|
-
type: "ActionExecutionEnd"
|
|
2504
|
-
actionExecutionId
|
|
2200
|
+
type: "ActionExecutionEnd"
|
|
2505
2201
|
});
|
|
2506
2202
|
}
|
|
2507
|
-
sendActionExecution(
|
|
2508
|
-
this.sendActionExecutionStart(
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
parentMessageId
|
|
2512
|
-
});
|
|
2513
|
-
this.sendActionExecutionArgs({
|
|
2514
|
-
actionExecutionId,
|
|
2515
|
-
args
|
|
2516
|
-
});
|
|
2517
|
-
this.sendActionExecutionEnd({
|
|
2518
|
-
actionExecutionId
|
|
2519
|
-
});
|
|
2203
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
2204
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
2205
|
+
this.sendActionExecutionArgs(args);
|
|
2206
|
+
this.sendActionExecutionEnd();
|
|
2520
2207
|
}
|
|
2521
|
-
sendActionExecutionResult(
|
|
2208
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2522
2209
|
this.next({
|
|
2523
2210
|
type: "ActionExecutionResult",
|
|
2524
2211
|
actionName,
|
|
@@ -2526,7 +2213,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2526
2213
|
result
|
|
2527
2214
|
});
|
|
2528
2215
|
}
|
|
2529
|
-
sendAgentStateMessage(
|
|
2216
|
+
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2530
2217
|
this.next({
|
|
2531
2218
|
type: "AgentStateMessage",
|
|
2532
2219
|
threadId,
|
|
@@ -2547,8 +2234,8 @@ var RuntimeEventSource = class {
|
|
|
2547
2234
|
async stream(callback) {
|
|
2548
2235
|
this.callback = callback;
|
|
2549
2236
|
}
|
|
2550
|
-
sendErrorMessageToChat(
|
|
2551
|
-
const errorMessage =
|
|
2237
|
+
sendErrorMessageToChat() {
|
|
2238
|
+
const errorMessage = "\u274C An error occurred. Please try again.";
|
|
2552
2239
|
if (!this.callback) {
|
|
2553
2240
|
this.stream(async (eventStream$) => {
|
|
2554
2241
|
eventStream$.sendTextMessage((0, import_shared8.randomId)(), errorMessage);
|
|
@@ -2563,19 +2250,27 @@ var RuntimeEventSource = class {
|
|
|
2563
2250
|
this.sendErrorMessageToChat();
|
|
2564
2251
|
});
|
|
2565
2252
|
return this.eventStream$.pipe(
|
|
2253
|
+
// mark tools for server side execution
|
|
2254
|
+
(0, import_rxjs2.map)((event) => {
|
|
2255
|
+
if (event.type === "ActionExecutionStart") {
|
|
2256
|
+
if (event.scope !== "passThrough") {
|
|
2257
|
+
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return event;
|
|
2261
|
+
}),
|
|
2566
2262
|
// track state
|
|
2567
2263
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2568
2264
|
acc = {
|
|
2569
2265
|
...acc
|
|
2570
2266
|
};
|
|
2571
2267
|
if (event.type === "ActionExecutionStart") {
|
|
2572
|
-
acc.callActionServerSide =
|
|
2268
|
+
acc.callActionServerSide = event.scope === "server";
|
|
2573
2269
|
acc.args = "";
|
|
2574
2270
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2575
2271
|
if (acc.callActionServerSide) {
|
|
2576
2272
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2577
2273
|
}
|
|
2578
|
-
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2579
2274
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2580
2275
|
acc.args += event.args;
|
|
2581
2276
|
}
|
|
@@ -2586,13 +2281,12 @@ var RuntimeEventSource = class {
|
|
|
2586
2281
|
callActionServerSide: false,
|
|
2587
2282
|
args: "",
|
|
2588
2283
|
actionExecutionId: null,
|
|
2589
|
-
action: null
|
|
2590
|
-
actionExecutionParentMessageId: null
|
|
2284
|
+
action: null
|
|
2591
2285
|
}),
|
|
2592
2286
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2593
2287
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2594
2288
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2595
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.
|
|
2289
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2596
2290
|
console.error(error);
|
|
2597
2291
|
});
|
|
2598
2292
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2605,7 +2299,7 @@ var RuntimeEventSource = class {
|
|
|
2605
2299
|
}
|
|
2606
2300
|
};
|
|
2607
2301
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2608
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments,
|
|
2302
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2609
2303
|
var _a;
|
|
2610
2304
|
if (guardrailsResult$) {
|
|
2611
2305
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2625,33 +2319,10 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2625
2319
|
}
|
|
2626
2320
|
}
|
|
2627
2321
|
if (isLangGraphAgentAction(action)) {
|
|
2628
|
-
|
|
2629
|
-
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2630
|
-
id: actionExecutionId,
|
|
2631
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2632
|
-
name: action.name,
|
|
2633
|
-
arguments: JSON.parse(actionArguments),
|
|
2634
|
-
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2635
|
-
});
|
|
2636
|
-
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2637
|
-
id: "result-" + actionExecutionId,
|
|
2638
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2639
|
-
actionExecutionId,
|
|
2640
|
-
actionName: action.name,
|
|
2641
|
-
result
|
|
2642
|
-
});
|
|
2643
|
-
eventStream$.sendActionExecutionResult({
|
|
2644
|
-
actionExecutionId,
|
|
2645
|
-
actionName: action.name,
|
|
2646
|
-
result
|
|
2647
|
-
});
|
|
2322
|
+
eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
|
|
2648
2323
|
const stream = await action.langGraphAgentHandler({
|
|
2649
2324
|
name: action.name,
|
|
2650
|
-
actionInputsWithoutAgents
|
|
2651
|
-
additionalMessages: [
|
|
2652
|
-
agentExecution,
|
|
2653
|
-
agentExecutionResult
|
|
2654
|
-
]
|
|
2325
|
+
actionInputsWithoutAgents
|
|
2655
2326
|
});
|
|
2656
2327
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2657
2328
|
next: (event) => eventStream$.next(event),
|
|
@@ -2672,29 +2343,113 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2672
2343
|
}
|
|
2673
2344
|
__name(executeAction, "executeAction");
|
|
2674
2345
|
|
|
2346
|
+
// src/graphql/types/base/index.ts
|
|
2347
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2348
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2349
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2350
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2351
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2352
|
+
else
|
|
2353
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2354
|
+
if (d = decorators[i])
|
|
2355
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2356
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2357
|
+
}
|
|
2358
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2359
|
+
function _ts_metadata(k, v) {
|
|
2360
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2361
|
+
return Reflect.metadata(k, v);
|
|
2362
|
+
}
|
|
2363
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2364
|
+
var BaseMessageInput = class {
|
|
2365
|
+
id;
|
|
2366
|
+
createdAt;
|
|
2367
|
+
};
|
|
2368
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2369
|
+
_ts_decorate([
|
|
2370
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2371
|
+
_ts_metadata("design:type", String)
|
|
2372
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2373
|
+
_ts_decorate([
|
|
2374
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2375
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2376
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2377
|
+
BaseMessageInput = _ts_decorate([
|
|
2378
|
+
(0, import_type_graphql2.InputType)()
|
|
2379
|
+
], BaseMessageInput);
|
|
2380
|
+
|
|
2381
|
+
// src/graphql/types/converted/index.ts
|
|
2382
|
+
var Message = class extends BaseMessageInput {
|
|
2383
|
+
type;
|
|
2384
|
+
isTextMessage() {
|
|
2385
|
+
return this.type === "TextMessage";
|
|
2386
|
+
}
|
|
2387
|
+
isActionExecutionMessage() {
|
|
2388
|
+
return this.type === "ActionExecutionMessage";
|
|
2389
|
+
}
|
|
2390
|
+
isResultMessage() {
|
|
2391
|
+
return this.type === "ResultMessage";
|
|
2392
|
+
}
|
|
2393
|
+
isAgentStateMessage() {
|
|
2394
|
+
return this.type === "AgentStateMessage";
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2397
|
+
__name(Message, "Message");
|
|
2398
|
+
var TextMessage = class extends Message {
|
|
2399
|
+
type = "TextMessage";
|
|
2400
|
+
content;
|
|
2401
|
+
role;
|
|
2402
|
+
};
|
|
2403
|
+
__name(TextMessage, "TextMessage");
|
|
2404
|
+
var ActionExecutionMessage = class extends Message {
|
|
2405
|
+
type = "ActionExecutionMessage";
|
|
2406
|
+
name;
|
|
2407
|
+
arguments;
|
|
2408
|
+
scope;
|
|
2409
|
+
};
|
|
2410
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2411
|
+
var ResultMessage = class extends Message {
|
|
2412
|
+
type = "ResultMessage";
|
|
2413
|
+
actionExecutionId;
|
|
2414
|
+
actionName;
|
|
2415
|
+
result;
|
|
2416
|
+
};
|
|
2417
|
+
__name(ResultMessage, "ResultMessage");
|
|
2418
|
+
var AgentStateMessage = class extends Message {
|
|
2419
|
+
type = "AgentStateMessage";
|
|
2420
|
+
threadId;
|
|
2421
|
+
agentName;
|
|
2422
|
+
nodeName;
|
|
2423
|
+
runId;
|
|
2424
|
+
active;
|
|
2425
|
+
role;
|
|
2426
|
+
state;
|
|
2427
|
+
running;
|
|
2428
|
+
};
|
|
2429
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2430
|
+
|
|
2675
2431
|
// src/service-adapters/conversion.ts
|
|
2676
|
-
var
|
|
2432
|
+
var import_class_transformer = require("class-transformer");
|
|
2677
2433
|
function convertGqlInputToMessages(inputMessages) {
|
|
2678
2434
|
const messages = [];
|
|
2679
2435
|
for (const message of inputMessages) {
|
|
2680
2436
|
if (message.textMessage) {
|
|
2681
|
-
messages.push((0,
|
|
2437
|
+
messages.push((0, import_class_transformer.plainToInstance)(TextMessage, {
|
|
2682
2438
|
id: message.id,
|
|
2683
2439
|
createdAt: message.createdAt,
|
|
2684
2440
|
role: message.textMessage.role,
|
|
2685
|
-
content: message.textMessage.content
|
|
2686
|
-
parentMessageId: message.textMessage.parentMessageId
|
|
2441
|
+
content: message.textMessage.content
|
|
2687
2442
|
}));
|
|
2688
2443
|
} else if (message.actionExecutionMessage) {
|
|
2689
|
-
messages.push((0,
|
|
2444
|
+
messages.push((0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2690
2445
|
id: message.id,
|
|
2691
2446
|
createdAt: message.createdAt,
|
|
2692
2447
|
name: message.actionExecutionMessage.name,
|
|
2693
2448
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2694
|
-
|
|
2449
|
+
scope: message.actionExecutionMessage.scope
|
|
2695
2450
|
}));
|
|
2696
2451
|
} else if (message.resultMessage) {
|
|
2697
|
-
messages.push((0,
|
|
2452
|
+
messages.push((0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2698
2453
|
id: message.id,
|
|
2699
2454
|
createdAt: message.createdAt,
|
|
2700
2455
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2702,7 +2457,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2702
2457
|
result: message.resultMessage.result
|
|
2703
2458
|
}));
|
|
2704
2459
|
} else if (message.agentStateMessage) {
|
|
2705
|
-
messages.push((0,
|
|
2460
|
+
messages.push((0, import_class_transformer.plainToInstance)(AgentStateMessage, {
|
|
2706
2461
|
id: message.id,
|
|
2707
2462
|
threadId: message.agentStateMessage.threadId,
|
|
2708
2463
|
createdAt: message.createdAt,
|
|
@@ -2802,48 +2557,15 @@ var CopilotRuntime = class {
|
|
|
2802
2557
|
} catch (error) {
|
|
2803
2558
|
console.error("Error getting response:", error);
|
|
2804
2559
|
eventSource.sendErrorMessageToChat();
|
|
2805
|
-
|
|
2560
|
+
return {
|
|
2561
|
+
threadId: threadId || (0, import_shared9.randomId)(),
|
|
2562
|
+
runId: runId || (0, import_shared9.randomId)(),
|
|
2563
|
+
eventSource,
|
|
2564
|
+
serverSideActions: [],
|
|
2565
|
+
actionInputsWithoutAgents: []
|
|
2566
|
+
};
|
|
2806
2567
|
}
|
|
2807
2568
|
}
|
|
2808
|
-
async discoverAgentsFromEndpoints(graphqlContext) {
|
|
2809
|
-
const headers = createHeaders(null, graphqlContext);
|
|
2810
|
-
const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
|
|
2811
|
-
const agents2 = await acc;
|
|
2812
|
-
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
2813
|
-
const response2 = await fetch(`${endpoint.deploymentUrl}/assistants/search`, {
|
|
2814
|
-
method: "POST",
|
|
2815
|
-
headers
|
|
2816
|
-
});
|
|
2817
|
-
const data2 = await response2.json();
|
|
2818
|
-
const endpointAgents2 = (data2 ?? []).map((entry) => ({
|
|
2819
|
-
name: entry.graph_id,
|
|
2820
|
-
id: entry.assistant_id
|
|
2821
|
-
}));
|
|
2822
|
-
return [
|
|
2823
|
-
...agents2,
|
|
2824
|
-
...endpointAgents2
|
|
2825
|
-
];
|
|
2826
|
-
}
|
|
2827
|
-
const response = await fetch(`${endpoint.url}/info`, {
|
|
2828
|
-
method: "POST",
|
|
2829
|
-
headers,
|
|
2830
|
-
body: JSON.stringify({
|
|
2831
|
-
properties: graphqlContext.properties
|
|
2832
|
-
})
|
|
2833
|
-
});
|
|
2834
|
-
const data = await response.json();
|
|
2835
|
-
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
2836
|
-
name: agent.name,
|
|
2837
|
-
description: agent.description,
|
|
2838
|
-
id: (0, import_shared9.randomId)()
|
|
2839
|
-
}));
|
|
2840
|
-
return [
|
|
2841
|
-
...agents2,
|
|
2842
|
-
...endpointAgents
|
|
2843
|
-
];
|
|
2844
|
-
}, Promise.resolve([]));
|
|
2845
|
-
return agents;
|
|
2846
|
-
}
|
|
2847
2569
|
async processAgentRequest(request) {
|
|
2848
2570
|
var _a;
|
|
2849
2571
|
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
@@ -2981,10 +2703,10 @@ function resolveEndpointType(endpoint) {
|
|
|
2981
2703
|
__name(resolveEndpointType, "resolveEndpointType");
|
|
2982
2704
|
|
|
2983
2705
|
// src/lib/integrations/shared.ts
|
|
2984
|
-
var
|
|
2706
|
+
var import_type_graphql16 = require("type-graphql");
|
|
2985
2707
|
|
|
2986
2708
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2987
|
-
var
|
|
2709
|
+
var import_type_graphql15 = require("type-graphql");
|
|
2988
2710
|
var import_rxjs4 = require("rxjs");
|
|
2989
2711
|
|
|
2990
2712
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
@@ -3044,7 +2766,6 @@ MessageInput = _ts_decorate2([
|
|
|
3044
2766
|
], MessageInput);
|
|
3045
2767
|
var TextMessageInput = class {
|
|
3046
2768
|
content;
|
|
3047
|
-
parentMessageId;
|
|
3048
2769
|
role;
|
|
3049
2770
|
};
|
|
3050
2771
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3052,12 +2773,6 @@ _ts_decorate2([
|
|
|
3052
2773
|
(0, import_type_graphql3.Field)(() => String),
|
|
3053
2774
|
_ts_metadata2("design:type", String)
|
|
3054
2775
|
], TextMessageInput.prototype, "content", void 0);
|
|
3055
|
-
_ts_decorate2([
|
|
3056
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3057
|
-
nullable: true
|
|
3058
|
-
}),
|
|
3059
|
-
_ts_metadata2("design:type", String)
|
|
3060
|
-
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
3061
2776
|
_ts_decorate2([
|
|
3062
2777
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3063
2778
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3068,7 +2783,6 @@ TextMessageInput = _ts_decorate2([
|
|
|
3068
2783
|
var ActionExecutionMessageInput = class {
|
|
3069
2784
|
name;
|
|
3070
2785
|
arguments;
|
|
3071
|
-
parentMessageId;
|
|
3072
2786
|
scope;
|
|
3073
2787
|
};
|
|
3074
2788
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3081,17 +2795,8 @@ _ts_decorate2([
|
|
|
3081
2795
|
_ts_metadata2("design:type", String)
|
|
3082
2796
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3083
2797
|
_ts_decorate2([
|
|
3084
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3085
|
-
|
|
3086
|
-
}),
|
|
3087
|
-
_ts_metadata2("design:type", String)
|
|
3088
|
-
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3089
|
-
_ts_decorate2([
|
|
3090
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3091
|
-
nullable: true,
|
|
3092
|
-
deprecationReason: "This field will be removed in a future version"
|
|
3093
|
-
}),
|
|
3094
|
-
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
2798
|
+
(0, import_type_graphql3.Field)(() => ActionExecutionScope),
|
|
2799
|
+
_ts_metadata2("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
3095
2800
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3096
2801
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3097
2802
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3099,7 +2804,6 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3099
2804
|
var ResultMessageInput = class {
|
|
3100
2805
|
actionExecutionId;
|
|
3101
2806
|
actionName;
|
|
3102
|
-
parentMessageId;
|
|
3103
2807
|
result;
|
|
3104
2808
|
};
|
|
3105
2809
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3111,12 +2815,6 @@ _ts_decorate2([
|
|
|
3111
2815
|
(0, import_type_graphql3.Field)(() => String),
|
|
3112
2816
|
_ts_metadata2("design:type", String)
|
|
3113
2817
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3114
|
-
_ts_decorate2([
|
|
3115
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3116
|
-
nullable: true
|
|
3117
|
-
}),
|
|
3118
|
-
_ts_metadata2("design:type", String)
|
|
3119
|
-
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
3120
2818
|
_ts_decorate2([
|
|
3121
2819
|
(0, import_type_graphql3.Field)(() => String),
|
|
3122
2820
|
_ts_metadata2("design:type", String)
|
|
@@ -3380,7 +3078,6 @@ var ForwardedParametersInput = class {
|
|
|
3380
3078
|
stop;
|
|
3381
3079
|
toolChoice;
|
|
3382
3080
|
toolChoiceFunctionName;
|
|
3383
|
-
temperature;
|
|
3384
3081
|
};
|
|
3385
3082
|
__name(ForwardedParametersInput, "ForwardedParametersInput");
|
|
3386
3083
|
_ts_decorate7([
|
|
@@ -3415,12 +3112,6 @@ _ts_decorate7([
|
|
|
3415
3112
|
}),
|
|
3416
3113
|
_ts_metadata7("design:type", String)
|
|
3417
3114
|
], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
|
|
3418
|
-
_ts_decorate7([
|
|
3419
|
-
(0, import_type_graphql8.Field)(() => Number, {
|
|
3420
|
-
nullable: true
|
|
3421
|
-
}),
|
|
3422
|
-
_ts_metadata7("design:type", Number)
|
|
3423
|
-
], ForwardedParametersInput.prototype, "temperature", void 0);
|
|
3424
3115
|
ForwardedParametersInput = _ts_decorate7([
|
|
3425
3116
|
(0, import_type_graphql8.InputType)()
|
|
3426
3117
|
], ForwardedParametersInput);
|
|
@@ -3846,7 +3537,6 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3846
3537
|
var TextMessageOutput = class {
|
|
3847
3538
|
role;
|
|
3848
3539
|
content;
|
|
3849
|
-
parentMessageId;
|
|
3850
3540
|
};
|
|
3851
3541
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3852
3542
|
_ts_decorate13([
|
|
@@ -3859,12 +3549,6 @@ _ts_decorate13([
|
|
|
3859
3549
|
]),
|
|
3860
3550
|
_ts_metadata13("design:type", Array)
|
|
3861
3551
|
], TextMessageOutput.prototype, "content", void 0);
|
|
3862
|
-
_ts_decorate13([
|
|
3863
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
3864
|
-
nullable: true
|
|
3865
|
-
}),
|
|
3866
|
-
_ts_metadata13("design:type", String)
|
|
3867
|
-
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
3868
3552
|
TextMessageOutput = _ts_decorate13([
|
|
3869
3553
|
(0, import_type_graphql14.ObjectType)({
|
|
3870
3554
|
implements: BaseMessageOutput
|
|
@@ -3874,7 +3558,6 @@ var ActionExecutionMessageOutput = class {
|
|
|
3874
3558
|
name;
|
|
3875
3559
|
scope;
|
|
3876
3560
|
arguments;
|
|
3877
|
-
parentMessageId;
|
|
3878
3561
|
};
|
|
3879
3562
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3880
3563
|
_ts_decorate13([
|
|
@@ -3882,11 +3565,8 @@ _ts_decorate13([
|
|
|
3882
3565
|
_ts_metadata13("design:type", String)
|
|
3883
3566
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3884
3567
|
_ts_decorate13([
|
|
3885
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3886
|
-
|
|
3887
|
-
deprecationReason: "This field will be removed in a future version"
|
|
3888
|
-
}),
|
|
3889
|
-
_ts_metadata13("design:type", String)
|
|
3568
|
+
(0, import_type_graphql14.Field)(() => ActionExecutionScope),
|
|
3569
|
+
_ts_metadata13("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
3890
3570
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3891
3571
|
_ts_decorate13([
|
|
3892
3572
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3894,12 +3574,6 @@ _ts_decorate13([
|
|
|
3894
3574
|
]),
|
|
3895
3575
|
_ts_metadata13("design:type", Array)
|
|
3896
3576
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
3897
|
-
_ts_decorate13([
|
|
3898
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
3899
|
-
nullable: true
|
|
3900
|
-
}),
|
|
3901
|
-
_ts_metadata13("design:type", String)
|
|
3902
|
-
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
3903
3577
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3904
3578
|
(0, import_type_graphql14.ObjectType)({
|
|
3905
3579
|
implements: BaseMessageOutput
|
|
@@ -4010,7 +3684,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
4010
3684
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4011
3685
|
var import_graphql_yoga = require("graphql-yoga");
|
|
4012
3686
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
4013
|
-
var
|
|
3687
|
+
var import_class_transformer2 = require("class-transformer");
|
|
4014
3688
|
var import_graphql = require("graphql");
|
|
4015
3689
|
|
|
4016
3690
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -4048,9 +3722,6 @@ __name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
|
4048
3722
|
|
|
4049
3723
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4050
3724
|
var import_shared10 = require("@copilotkit/shared");
|
|
4051
|
-
|
|
4052
|
-
// src/graphql/types/agents-response.type.ts
|
|
4053
|
-
var import_type_graphql15 = require("type-graphql");
|
|
4054
3725
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
4055
3726
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4056
3727
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4067,58 +3738,6 @@ function _ts_metadata14(k, v) {
|
|
|
4067
3738
|
return Reflect.metadata(k, v);
|
|
4068
3739
|
}
|
|
4069
3740
|
__name(_ts_metadata14, "_ts_metadata");
|
|
4070
|
-
var Agent = class {
|
|
4071
|
-
id;
|
|
4072
|
-
name;
|
|
4073
|
-
description;
|
|
4074
|
-
};
|
|
4075
|
-
__name(Agent, "Agent");
|
|
4076
|
-
_ts_decorate14([
|
|
4077
|
-
(0, import_type_graphql15.Field)(() => String),
|
|
4078
|
-
_ts_metadata14("design:type", String)
|
|
4079
|
-
], Agent.prototype, "id", void 0);
|
|
4080
|
-
_ts_decorate14([
|
|
4081
|
-
(0, import_type_graphql15.Field)(() => String),
|
|
4082
|
-
_ts_metadata14("design:type", String)
|
|
4083
|
-
], Agent.prototype, "name", void 0);
|
|
4084
|
-
_ts_decorate14([
|
|
4085
|
-
(0, import_type_graphql15.Field)(() => String),
|
|
4086
|
-
_ts_metadata14("design:type", String)
|
|
4087
|
-
], Agent.prototype, "description", void 0);
|
|
4088
|
-
Agent = _ts_decorate14([
|
|
4089
|
-
(0, import_type_graphql15.ObjectType)()
|
|
4090
|
-
], Agent);
|
|
4091
|
-
var AgentsResponse = class {
|
|
4092
|
-
agents;
|
|
4093
|
-
};
|
|
4094
|
-
__name(AgentsResponse, "AgentsResponse");
|
|
4095
|
-
_ts_decorate14([
|
|
4096
|
-
(0, import_type_graphql15.Field)(() => [
|
|
4097
|
-
Agent
|
|
4098
|
-
]),
|
|
4099
|
-
_ts_metadata14("design:type", Array)
|
|
4100
|
-
], AgentsResponse.prototype, "agents", void 0);
|
|
4101
|
-
AgentsResponse = _ts_decorate14([
|
|
4102
|
-
(0, import_type_graphql15.ObjectType)()
|
|
4103
|
-
], AgentsResponse);
|
|
4104
|
-
|
|
4105
|
-
// src/graphql/resolvers/copilot.resolver.ts
|
|
4106
|
-
function _ts_decorate15(decorators, target, key, desc) {
|
|
4107
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4108
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4109
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
4110
|
-
else
|
|
4111
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
4112
|
-
if (d = decorators[i])
|
|
4113
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4114
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4115
|
-
}
|
|
4116
|
-
__name(_ts_decorate15, "_ts_decorate");
|
|
4117
|
-
function _ts_metadata15(k, v) {
|
|
4118
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
4119
|
-
return Reflect.metadata(k, v);
|
|
4120
|
-
}
|
|
4121
|
-
__name(_ts_metadata15, "_ts_metadata");
|
|
4122
3741
|
function _ts_param(paramIndex, decorator) {
|
|
4123
3742
|
return function(target, key) {
|
|
4124
3743
|
decorator(target, key, paramIndex);
|
|
@@ -4160,17 +3779,6 @@ var CopilotResolver = class {
|
|
|
4160
3779
|
async hello() {
|
|
4161
3780
|
return "Hello World";
|
|
4162
3781
|
}
|
|
4163
|
-
async availableAgents(ctx) {
|
|
4164
|
-
let logger2 = ctx.logger.child({
|
|
4165
|
-
component: "CopilotResolver.availableAgents"
|
|
4166
|
-
});
|
|
4167
|
-
logger2.debug("Processing");
|
|
4168
|
-
const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
|
|
4169
|
-
logger2.debug("Event source created, creating response");
|
|
4170
|
-
return {
|
|
4171
|
-
agents
|
|
4172
|
-
};
|
|
4173
|
-
}
|
|
4174
3782
|
async generateCopilotResponse(ctx, data, properties) {
|
|
4175
3783
|
var _a, _b, _c;
|
|
4176
3784
|
telemetry_client_default.capture("oss.runtime.copilot_request_created", {
|
|
@@ -4274,7 +3882,7 @@ var CopilotResolver = class {
|
|
|
4274
3882
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4275
3883
|
});
|
|
4276
3884
|
outputMessages = [
|
|
4277
|
-
(0,
|
|
3885
|
+
(0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4278
3886
|
id: (0, import_shared10.randomId)(),
|
|
4279
3887
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4280
3888
|
content: result.reason,
|
|
@@ -4323,15 +3931,12 @@ var CopilotResolver = class {
|
|
|
4323
3931
|
// skip until this message start event
|
|
4324
3932
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4325
3933
|
// take until the message end event
|
|
4326
|
-
(0, import_rxjs4.takeWhile)((e) =>
|
|
4327
|
-
// filter out any other message events or message ids
|
|
4328
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
3934
|
+
(0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
4329
3935
|
);
|
|
4330
3936
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4331
3937
|
const messageId = event.messageId;
|
|
4332
3938
|
pushMessage({
|
|
4333
3939
|
id: messageId,
|
|
4334
|
-
parentMessageId: event.parentMessageId,
|
|
4335
3940
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4336
3941
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4337
3942
|
role: MessageRole.assistant,
|
|
@@ -4344,7 +3949,7 @@ var CopilotResolver = class {
|
|
|
4344
3949
|
reason,
|
|
4345
3950
|
messageId: messageId2
|
|
4346
3951
|
}, "Text streaming interrupted");
|
|
4347
|
-
streamingTextStatus.next((0,
|
|
3952
|
+
streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4348
3953
|
reason
|
|
4349
3954
|
}));
|
|
4350
3955
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4377,7 +3982,7 @@ var CopilotResolver = class {
|
|
|
4377
3982
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4378
3983
|
stopStreamingText();
|
|
4379
3984
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4380
|
-
outputMessages.push((0,
|
|
3985
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4381
3986
|
id: messageId,
|
|
4382
3987
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4383
3988
|
content: textChunks.join(""),
|
|
@@ -4390,20 +3995,14 @@ var CopilotResolver = class {
|
|
|
4390
3995
|
break;
|
|
4391
3996
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4392
3997
|
logger2.debug("Action execution start event received");
|
|
4393
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4394
|
-
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4395
|
-
// take until the action execution end event
|
|
4396
|
-
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4397
|
-
// filter out any other action execution events or action execution ids
|
|
4398
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4399
|
-
);
|
|
3998
|
+
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs4.skipWhile)((e) => e !== event), (0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
4400
3999
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4401
4000
|
pushMessage({
|
|
4402
4001
|
id: event.actionExecutionId,
|
|
4403
|
-
parentMessageId: event.parentMessageId,
|
|
4404
4002
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4405
4003
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4406
4004
|
name: event.actionName,
|
|
4005
|
+
scope: event.scope,
|
|
4407
4006
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4408
4007
|
logger2.debug("Action execution argument stream created");
|
|
4409
4008
|
const argumentChunks = [];
|
|
@@ -4419,7 +4018,7 @@ var CopilotResolver = class {
|
|
|
4419
4018
|
logger2.error({
|
|
4420
4019
|
err
|
|
4421
4020
|
}, "Error in action execution argument stream");
|
|
4422
|
-
streamingArgumentsStatus.next((0,
|
|
4021
|
+
streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4423
4022
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4424
4023
|
}));
|
|
4425
4024
|
stopStreamingArguments();
|
|
@@ -4430,10 +4029,11 @@ var CopilotResolver = class {
|
|
|
4430
4029
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4431
4030
|
stopStreamingArguments();
|
|
4432
4031
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4433
|
-
outputMessages.push((0,
|
|
4032
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
4434
4033
|
id: event.actionExecutionId,
|
|
4435
4034
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4436
4035
|
name: event.actionName,
|
|
4036
|
+
scope: event.scope,
|
|
4437
4037
|
arguments: argumentChunks.join("")
|
|
4438
4038
|
}));
|
|
4439
4039
|
}
|
|
@@ -4446,15 +4046,15 @@ var CopilotResolver = class {
|
|
|
4446
4046
|
result: event.result
|
|
4447
4047
|
}, "Action execution result event received");
|
|
4448
4048
|
pushMessage({
|
|
4449
|
-
id:
|
|
4049
|
+
id: (0, import_shared10.randomId)(),
|
|
4450
4050
|
status: new SuccessMessageStatus(),
|
|
4451
4051
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4452
4052
|
actionExecutionId: event.actionExecutionId,
|
|
4453
4053
|
actionName: event.actionName,
|
|
4454
4054
|
result: event.result
|
|
4455
4055
|
});
|
|
4456
|
-
outputMessages.push((0,
|
|
4457
|
-
id:
|
|
4056
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
4057
|
+
id: (0, import_shared10.randomId)(),
|
|
4458
4058
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4459
4059
|
actionExecutionId: event.actionExecutionId,
|
|
4460
4060
|
actionName: event.actionName,
|
|
@@ -4478,7 +4078,7 @@ var CopilotResolver = class {
|
|
|
4478
4078
|
role: MessageRole.assistant,
|
|
4479
4079
|
createdAt: /* @__PURE__ */ new Date()
|
|
4480
4080
|
});
|
|
4481
|
-
outputMessages.push((0,
|
|
4081
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
4482
4082
|
id: (0, import_shared10.randomId)(),
|
|
4483
4083
|
threadId: event.threadId,
|
|
4484
4084
|
agentName: event.agentName,
|
|
@@ -4523,38 +4123,29 @@ var CopilotResolver = class {
|
|
|
4523
4123
|
}
|
|
4524
4124
|
};
|
|
4525
4125
|
__name(CopilotResolver, "CopilotResolver");
|
|
4526
|
-
|
|
4527
|
-
(0,
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4126
|
+
_ts_decorate14([
|
|
4127
|
+
(0, import_type_graphql15.Query)(() => String),
|
|
4128
|
+
_ts_metadata14("design:type", Function),
|
|
4129
|
+
_ts_metadata14("design:paramtypes", []),
|
|
4130
|
+
_ts_metadata14("design:returntype", Promise)
|
|
4531
4131
|
], CopilotResolver.prototype, "hello", null);
|
|
4532
|
-
|
|
4533
|
-
(0,
|
|
4534
|
-
_ts_param(0, (0,
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
typeof GraphQLContext === "undefined" ? Object : GraphQLContext
|
|
4538
|
-
]),
|
|
4539
|
-
_ts_metadata15("design:returntype", Promise)
|
|
4540
|
-
], CopilotResolver.prototype, "availableAgents", null);
|
|
4541
|
-
_ts_decorate15([
|
|
4542
|
-
(0, import_type_graphql16.Mutation)(() => CopilotResponse),
|
|
4543
|
-
_ts_param(0, (0, import_type_graphql16.Ctx)()),
|
|
4544
|
-
_ts_param(1, (0, import_type_graphql16.Arg)("data")),
|
|
4545
|
-
_ts_param(2, (0, import_type_graphql16.Arg)("properties", () => import_graphql_scalars2.GraphQLJSONObject, {
|
|
4132
|
+
_ts_decorate14([
|
|
4133
|
+
(0, import_type_graphql15.Mutation)(() => CopilotResponse),
|
|
4134
|
+
_ts_param(0, (0, import_type_graphql15.Ctx)()),
|
|
4135
|
+
_ts_param(1, (0, import_type_graphql15.Arg)("data")),
|
|
4136
|
+
_ts_param(2, (0, import_type_graphql15.Arg)("properties", () => import_graphql_scalars2.GraphQLJSONObject, {
|
|
4546
4137
|
nullable: true
|
|
4547
4138
|
})),
|
|
4548
|
-
|
|
4549
|
-
|
|
4139
|
+
_ts_metadata14("design:type", Function),
|
|
4140
|
+
_ts_metadata14("design:paramtypes", [
|
|
4550
4141
|
typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
|
|
4551
4142
|
typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
|
|
4552
4143
|
typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
|
|
4553
4144
|
]),
|
|
4554
|
-
|
|
4145
|
+
_ts_metadata14("design:returntype", Promise)
|
|
4555
4146
|
], CopilotResolver.prototype, "generateCopilotResponse", null);
|
|
4556
|
-
CopilotResolver =
|
|
4557
|
-
(0,
|
|
4147
|
+
CopilotResolver = _ts_decorate14([
|
|
4148
|
+
(0, import_type_graphql15.Resolver)(() => CopilotResponse)
|
|
4558
4149
|
], CopilotResolver);
|
|
4559
4150
|
|
|
4560
4151
|
// src/lib/integrations/shared.ts
|
|
@@ -4609,7 +4200,7 @@ async function createContext(initialContext, copilotKitContext, contextLogger, p
|
|
|
4609
4200
|
__name(createContext, "createContext");
|
|
4610
4201
|
function buildSchema(options = {}) {
|
|
4611
4202
|
logger.debug("Building GraphQL schema...");
|
|
4612
|
-
const schema = (0,
|
|
4203
|
+
const schema = (0, import_type_graphql16.buildSchemaSync)({
|
|
4613
4204
|
resolvers: [
|
|
4614
4205
|
CopilotResolver
|
|
4615
4206
|
],
|