@copilotkit/runtime 1.4.8-coagents-v0-3.1 → 1.4.8-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -4
- package/__snapshots__/schema/schema.graphql +10 -7
- package/dist/{chunk-FVYNRYIB.mjs → chunk-5KJYPVQJ.mjs} +307 -423
- package/dist/chunk-5KJYPVQJ.mjs.map +1 -0
- package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
- package/dist/chunk-B74M7FXG.mjs.map +1 -0
- package/dist/{chunk-BACNNHHI.mjs → chunk-CGGI46KC.mjs} +2 -2
- package/dist/{chunk-YFG3Q3YH.mjs → chunk-EU52BTKR.mjs} +2 -2
- package/dist/{chunk-MQJNZYAH.mjs → chunk-KO4QCMY4.mjs} +2 -2
- package/dist/{chunk-2PK2SFRB.mjs → chunk-W7GP2EOT.mjs} +106 -221
- package/dist/chunk-W7GP2EOT.mjs.map +1 -0
- package/dist/{copilot-runtime-b15b683d.d.ts → copilot-runtime-1c5bf72b.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +1 -2
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-50aa9621.d.ts → groq-adapter-b6a40422.d.ts} +1 -1
- package/dist/{index-ff3fbc33.d.ts → index-10b1c870.d.ts} +8 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +515 -745
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-8ec29cba.d.ts → langserve-6245df39.d.ts} +14 -52
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +442 -706
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +37 -71
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +37 -71
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +37 -71
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +37 -71
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +106 -219
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +148 -140
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/forwarded-parameters.input.ts +3 -0
- package/src/graphql/inputs/message.input.ts +3 -15
- package/src/graphql/resolvers/copilot.resolver.ts +6 -32
- package/src/graphql/types/converted/index.ts +3 -4
- package/src/graphql/types/copilot-response.type.ts +3 -12
- package/src/graphql/types/enums.ts +11 -0
- package/src/lib/runtime/remote-action-constructors.ts +62 -60
- package/src/lib/runtime/remote-actions.ts +0 -1
- package/src/lib/runtime/remote-lg-action.ts +140 -161
- package/src/service-adapters/anthropic/anthropic-adapter.ts +6 -16
- package/src/service-adapters/conversion.ts +1 -2
- package/src/service-adapters/events.ts +52 -111
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -7
- package/src/service-adapters/groq/groq-adapter.ts +8 -23
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +31 -49
- package/src/service-adapters/openai/openai-adapter.ts +9 -22
- package/src/service-adapters/openai/openai-assistant-adapter.ts +8 -22
- package/src/service-adapters/unify/unify-adapter.ts +11 -28
- package/dist/chunk-2PK2SFRB.mjs.map +0 -1
- package/dist/chunk-FVYNRYIB.mjs.map +0 -1
- package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
- /package/dist/{chunk-BACNNHHI.mjs.map → chunk-CGGI46KC.mjs.map} +0 -0
- /package/dist/{chunk-YFG3Q3YH.mjs.map → chunk-EU52BTKR.mjs.map} +0 -0
- /package/dist/{chunk-MQJNZYAH.mjs.map → chunk-KO4QCMY4.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.4.8-
|
|
47
|
+
version: "1.4.8-next.1",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -126,6 +126,8 @@ var src_exports = {};
|
|
|
126
126
|
__export(src_exports, {
|
|
127
127
|
AnthropicAdapter: () => AnthropicAdapter,
|
|
128
128
|
CopilotRuntime: () => CopilotRuntime,
|
|
129
|
+
ExperimentalEmptyAdapter: () => ExperimentalEmptyAdapter,
|
|
130
|
+
ExperimentalOllamaAdapter: () => ExperimentalOllamaAdapter,
|
|
129
131
|
GoogleGenerativeAIAdapter: () => GoogleGenerativeAIAdapter,
|
|
130
132
|
GroqAdapter: () => GroqAdapter,
|
|
131
133
|
GuardrailsValidationFailureResponse: () => GuardrailsValidationFailureResponse,
|
|
@@ -154,7 +156,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
154
156
|
var import_reflect_metadata = require("reflect-metadata");
|
|
155
157
|
|
|
156
158
|
// src/lib/runtime/copilot-runtime.ts
|
|
157
|
-
var
|
|
159
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
158
160
|
|
|
159
161
|
// src/service-adapters/langchain/langserve.ts
|
|
160
162
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -430,8 +432,6 @@ var OpenAIAdapter = class {
|
|
|
430
432
|
eventSource.stream(async (eventStream$) => {
|
|
431
433
|
var _a, _b;
|
|
432
434
|
let mode = null;
|
|
433
|
-
let currentMessageId;
|
|
434
|
-
let currentToolCallId;
|
|
435
435
|
for await (const chunk of stream) {
|
|
436
436
|
if (chunk.choices.length === 0) {
|
|
437
437
|
continue;
|
|
@@ -440,52 +440,30 @@ var OpenAIAdapter = class {
|
|
|
440
440
|
const content = chunk.choices[0].delta.content;
|
|
441
441
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
442
442
|
mode = null;
|
|
443
|
-
eventStream$.sendTextMessageEnd(
|
|
444
|
-
messageId: currentMessageId
|
|
445
|
-
});
|
|
443
|
+
eventStream$.sendTextMessageEnd();
|
|
446
444
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
447
445
|
mode = null;
|
|
448
|
-
eventStream$.sendActionExecutionEnd(
|
|
449
|
-
actionExecutionId: currentToolCallId
|
|
450
|
-
});
|
|
446
|
+
eventStream$.sendActionExecutionEnd();
|
|
451
447
|
}
|
|
452
448
|
if (mode === null) {
|
|
453
449
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
454
450
|
mode = "function";
|
|
455
|
-
|
|
456
|
-
eventStream$.sendActionExecutionStart({
|
|
457
|
-
actionExecutionId: currentToolCallId,
|
|
458
|
-
parentMessageId: chunk.id,
|
|
459
|
-
actionName: toolCall.function.name
|
|
460
|
-
});
|
|
451
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
461
452
|
} else if (content) {
|
|
462
453
|
mode = "message";
|
|
463
|
-
|
|
464
|
-
eventStream$.sendTextMessageStart({
|
|
465
|
-
messageId: currentMessageId
|
|
466
|
-
});
|
|
454
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
467
455
|
}
|
|
468
456
|
}
|
|
469
457
|
if (mode === "message" && content) {
|
|
470
|
-
eventStream$.sendTextMessageContent(
|
|
471
|
-
messageId: currentMessageId,
|
|
472
|
-
content
|
|
473
|
-
});
|
|
458
|
+
eventStream$.sendTextMessageContent(content);
|
|
474
459
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
475
|
-
eventStream$.sendActionExecutionArgs(
|
|
476
|
-
actionExecutionId: currentToolCallId,
|
|
477
|
-
args: toolCall.function.arguments
|
|
478
|
-
});
|
|
460
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
479
461
|
}
|
|
480
462
|
}
|
|
481
463
|
if (mode === "message") {
|
|
482
|
-
eventStream$.sendTextMessageEnd(
|
|
483
|
-
messageId: currentMessageId
|
|
484
|
-
});
|
|
464
|
+
eventStream$.sendTextMessageEnd();
|
|
485
465
|
} else if (mode === "function") {
|
|
486
|
-
eventStream$.sendActionExecutionEnd(
|
|
487
|
-
actionExecutionId: currentToolCallId
|
|
488
|
-
});
|
|
466
|
+
eventStream$.sendActionExecutionEnd();
|
|
489
467
|
}
|
|
490
468
|
eventStream$.complete();
|
|
491
469
|
});
|
|
@@ -553,25 +531,17 @@ function isBaseMessageChunk(message) {
|
|
|
553
531
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
554
532
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
555
533
|
if (actionExecution) {
|
|
556
|
-
eventStream$.sendActionExecutionResult(
|
|
557
|
-
actionExecutionId: actionExecution.id,
|
|
558
|
-
actionName: actionExecution.name,
|
|
559
|
-
result: "Sending a message"
|
|
560
|
-
});
|
|
534
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
561
535
|
}
|
|
562
536
|
}
|
|
563
537
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
564
538
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
565
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
539
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
566
540
|
if (typeof result === "string") {
|
|
567
541
|
if (!actionExecution) {
|
|
568
542
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
569
543
|
} else {
|
|
570
|
-
eventStream$.sendActionExecutionResult(
|
|
571
|
-
actionExecutionId: actionExecution.id,
|
|
572
|
-
actionName: actionExecution.name,
|
|
573
|
-
result
|
|
574
|
-
});
|
|
544
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
575
545
|
}
|
|
576
546
|
} else if (isAIMessage(result)) {
|
|
577
547
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -579,11 +549,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
579
549
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
580
550
|
}
|
|
581
551
|
for (const toolCall of result.tool_calls) {
|
|
582
|
-
eventStream$.sendActionExecution(
|
|
583
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
584
|
-
actionName: toolCall.name,
|
|
585
|
-
args: JSON.stringify(toolCall.args)
|
|
586
|
-
});
|
|
552
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
587
553
|
}
|
|
588
554
|
} else if (isBaseMessageChunk(result)) {
|
|
589
555
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -592,18 +558,13 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
592
558
|
}
|
|
593
559
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
594
560
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
595
|
-
eventStream$.sendActionExecution(
|
|
596
|
-
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
597
|
-
actionName: toolCall.name,
|
|
598
|
-
args: JSON.stringify(toolCall.args)
|
|
599
|
-
});
|
|
561
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
600
562
|
}
|
|
601
563
|
}
|
|
602
564
|
} else if (result && "getReader" in result) {
|
|
603
565
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
604
566
|
let reader = result.getReader();
|
|
605
567
|
let mode = null;
|
|
606
|
-
let currentMessageId;
|
|
607
568
|
const toolCallDetails = {
|
|
608
569
|
name: null,
|
|
609
570
|
id: null,
|
|
@@ -642,14 +603,10 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
642
603
|
}
|
|
643
604
|
if (mode === "message" && (toolCallId || done)) {
|
|
644
605
|
mode = null;
|
|
645
|
-
eventStream$.sendTextMessageEnd(
|
|
646
|
-
messageId: currentMessageId
|
|
647
|
-
});
|
|
606
|
+
eventStream$.sendTextMessageEnd();
|
|
648
607
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
649
608
|
mode = null;
|
|
650
|
-
eventStream$.sendActionExecutionEnd(
|
|
651
|
-
actionExecutionId: toolCallId
|
|
652
|
-
});
|
|
609
|
+
eventStream$.sendActionExecutionEnd();
|
|
653
610
|
}
|
|
654
611
|
if (done) {
|
|
655
612
|
break;
|
|
@@ -657,40 +614,21 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
657
614
|
if (mode === null) {
|
|
658
615
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
659
616
|
mode = "function";
|
|
660
|
-
eventStream$.sendActionExecutionStart(
|
|
661
|
-
actionExecutionId: toolCallId,
|
|
662
|
-
actionName: toolCallName,
|
|
663
|
-
parentMessageId: (_i = value.lc_kwargs) == null ? void 0 : _i.id
|
|
664
|
-
});
|
|
617
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
665
618
|
} else if (content) {
|
|
666
619
|
mode = "message";
|
|
667
|
-
|
|
668
|
-
eventStream$.sendTextMessageStart({
|
|
669
|
-
messageId: currentMessageId
|
|
670
|
-
});
|
|
620
|
+
eventStream$.sendTextMessageStart((0, import_shared2.randomId)());
|
|
671
621
|
}
|
|
672
622
|
}
|
|
673
623
|
if (mode === "message" && content) {
|
|
674
|
-
eventStream$.sendTextMessageContent(
|
|
675
|
-
messageId: currentMessageId,
|
|
676
|
-
content: Array.isArray(content) ? ((_k = content[0]) == null ? void 0 : _k.text) ?? "" : content
|
|
677
|
-
});
|
|
624
|
+
eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
|
|
678
625
|
} else if (mode === "function" && toolCallArgs) {
|
|
679
626
|
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
|
-
});
|
|
627
|
+
eventStream$.sendActionExecutionEnd();
|
|
628
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
688
629
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
689
630
|
}
|
|
690
|
-
eventStream$.sendActionExecutionArgs(
|
|
691
|
-
actionExecutionId: toolCallId,
|
|
692
|
-
args: toolCallArgs
|
|
693
|
-
});
|
|
631
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
694
632
|
}
|
|
695
633
|
} catch (error) {
|
|
696
634
|
console.error("Error reading from stream", error);
|
|
@@ -698,11 +636,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
698
636
|
}
|
|
699
637
|
}
|
|
700
638
|
} else if (actionExecution) {
|
|
701
|
-
eventStream$.sendActionExecutionResult(
|
|
702
|
-
actionExecutionId: actionExecution.id,
|
|
703
|
-
actionName: actionExecution.name,
|
|
704
|
-
result: encodeResult(result)
|
|
705
|
-
});
|
|
639
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
706
640
|
} else {
|
|
707
641
|
throw new Error("Invalid return type from LangChain function.");
|
|
708
642
|
}
|
|
@@ -882,33 +816,21 @@ var OpenAIAssistantAdapter = class {
|
|
|
882
816
|
eventSource.stream(async (eventStream$) => {
|
|
883
817
|
var _a, _b, _c, _d, _e, _f;
|
|
884
818
|
let inFunctionCall = false;
|
|
885
|
-
let currentMessageId;
|
|
886
|
-
let currentToolCallId;
|
|
887
819
|
for await (const chunk of stream) {
|
|
888
820
|
switch (chunk.event) {
|
|
889
821
|
case "thread.message.created":
|
|
890
822
|
if (inFunctionCall) {
|
|
891
|
-
eventStream$.sendActionExecutionEnd(
|
|
892
|
-
actionExecutionId: currentToolCallId
|
|
893
|
-
});
|
|
823
|
+
eventStream$.sendActionExecutionEnd();
|
|
894
824
|
}
|
|
895
|
-
|
|
896
|
-
eventStream$.sendTextMessageStart({
|
|
897
|
-
messageId: currentMessageId
|
|
898
|
-
});
|
|
825
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
899
826
|
break;
|
|
900
827
|
case "thread.message.delta":
|
|
901
828
|
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
|
-
});
|
|
829
|
+
eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
|
|
906
830
|
}
|
|
907
831
|
break;
|
|
908
832
|
case "thread.message.completed":
|
|
909
|
-
eventStream$.sendTextMessageEnd(
|
|
910
|
-
messageId: currentMessageId
|
|
911
|
-
});
|
|
833
|
+
eventStream$.sendTextMessageEnd();
|
|
912
834
|
break;
|
|
913
835
|
case "thread.run.step.delta":
|
|
914
836
|
let toolCallId;
|
|
@@ -921,30 +843,18 @@ var OpenAIAssistantAdapter = class {
|
|
|
921
843
|
}
|
|
922
844
|
if (toolCallName && toolCallId) {
|
|
923
845
|
if (inFunctionCall) {
|
|
924
|
-
eventStream$.sendActionExecutionEnd(
|
|
925
|
-
actionExecutionId: currentToolCallId
|
|
926
|
-
});
|
|
846
|
+
eventStream$.sendActionExecutionEnd();
|
|
927
847
|
}
|
|
928
848
|
inFunctionCall = true;
|
|
929
|
-
|
|
930
|
-
eventStream$.sendActionExecutionStart({
|
|
931
|
-
actionExecutionId: currentToolCallId,
|
|
932
|
-
parentMessageId: chunk.data.id,
|
|
933
|
-
actionName: toolCallName
|
|
934
|
-
});
|
|
849
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
935
850
|
} else if (toolCallArgs) {
|
|
936
|
-
eventStream$.sendActionExecutionArgs(
|
|
937
|
-
actionExecutionId: currentToolCallId,
|
|
938
|
-
args: toolCallArgs
|
|
939
|
-
});
|
|
851
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
940
852
|
}
|
|
941
853
|
break;
|
|
942
854
|
}
|
|
943
855
|
}
|
|
944
856
|
if (inFunctionCall) {
|
|
945
|
-
eventStream$.sendActionExecutionEnd(
|
|
946
|
-
actionExecutionId: currentToolCallId
|
|
947
|
-
});
|
|
857
|
+
eventStream$.sendActionExecutionEnd();
|
|
948
858
|
}
|
|
949
859
|
eventStream$.complete();
|
|
950
860
|
});
|
|
@@ -997,77 +907,46 @@ var UnifyAdapter = class {
|
|
|
997
907
|
}
|
|
998
908
|
});
|
|
999
909
|
let model = null;
|
|
1000
|
-
let currentMessageId;
|
|
1001
|
-
let currentToolCallId;
|
|
1002
910
|
request.eventSource.stream(async (eventStream$) => {
|
|
1003
911
|
var _a, _b;
|
|
1004
912
|
let mode = null;
|
|
1005
913
|
for await (const chunk of stream) {
|
|
1006
914
|
if (this.start) {
|
|
1007
915
|
model = chunk.model;
|
|
1008
|
-
|
|
1009
|
-
eventStream$.
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
eventStream$.sendTextMessageContent({
|
|
1013
|
-
messageId: currentMessageId,
|
|
1014
|
-
content: `Model used: ${model}
|
|
1015
|
-
`
|
|
1016
|
-
});
|
|
1017
|
-
eventStream$.sendTextMessageEnd({
|
|
1018
|
-
messageId: currentMessageId
|
|
1019
|
-
});
|
|
916
|
+
eventStream$.sendTextMessageStart((0, import_shared4.randomId)());
|
|
917
|
+
eventStream$.sendTextMessageContent(`Model used: ${model}
|
|
918
|
+
`);
|
|
919
|
+
eventStream$.sendTextMessageEnd();
|
|
1020
920
|
this.start = false;
|
|
1021
921
|
}
|
|
1022
922
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1023
923
|
const content = chunk.choices[0].delta.content;
|
|
1024
924
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1025
925
|
mode = null;
|
|
1026
|
-
eventStream$.sendTextMessageEnd(
|
|
1027
|
-
messageId: currentMessageId
|
|
1028
|
-
});
|
|
926
|
+
eventStream$.sendTextMessageEnd();
|
|
1029
927
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1030
928
|
mode = null;
|
|
1031
|
-
eventStream$.sendActionExecutionEnd(
|
|
1032
|
-
actionExecutionId: currentToolCallId
|
|
1033
|
-
});
|
|
929
|
+
eventStream$.sendActionExecutionEnd();
|
|
1034
930
|
}
|
|
1035
931
|
if (mode === null) {
|
|
1036
932
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1037
933
|
mode = "function";
|
|
1038
|
-
|
|
1039
|
-
eventStream$.sendActionExecutionStart({
|
|
1040
|
-
actionExecutionId: currentToolCallId,
|
|
1041
|
-
actionName: toolCall.function.name
|
|
1042
|
-
});
|
|
934
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1043
935
|
} else if (content) {
|
|
1044
936
|
mode = "message";
|
|
1045
|
-
|
|
1046
|
-
eventStream$.sendTextMessageStart({
|
|
1047
|
-
messageId: currentMessageId
|
|
1048
|
-
});
|
|
937
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1049
938
|
}
|
|
1050
939
|
}
|
|
1051
940
|
if (mode === "message" && content) {
|
|
1052
|
-
eventStream$.sendTextMessageContent(
|
|
1053
|
-
messageId: currentMessageId,
|
|
1054
|
-
content
|
|
1055
|
-
});
|
|
941
|
+
eventStream$.sendTextMessageContent(content);
|
|
1056
942
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1057
|
-
eventStream$.sendActionExecutionArgs(
|
|
1058
|
-
actionExecutionId: currentToolCallId,
|
|
1059
|
-
args: toolCall.function.arguments
|
|
1060
|
-
});
|
|
943
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1061
944
|
}
|
|
1062
945
|
}
|
|
1063
946
|
if (mode === "message") {
|
|
1064
|
-
eventStream$.sendTextMessageEnd(
|
|
1065
|
-
messageId: currentMessageId
|
|
1066
|
-
});
|
|
947
|
+
eventStream$.sendTextMessageEnd();
|
|
1067
948
|
} else if (mode === "function") {
|
|
1068
|
-
eventStream$.sendActionExecutionEnd(
|
|
1069
|
-
actionExecutionId: currentToolCallId
|
|
1070
|
-
});
|
|
949
|
+
eventStream$.sendActionExecutionEnd();
|
|
1071
950
|
}
|
|
1072
951
|
eventStream$.complete();
|
|
1073
952
|
});
|
|
@@ -1133,59 +1012,35 @@ var GroqAdapter = class {
|
|
|
1133
1012
|
eventSource.stream(async (eventStream$) => {
|
|
1134
1013
|
var _a, _b;
|
|
1135
1014
|
let mode = null;
|
|
1136
|
-
let currentMessageId;
|
|
1137
|
-
let currentToolCallId;
|
|
1138
1015
|
for await (const chunk of stream) {
|
|
1139
1016
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1140
1017
|
const content = chunk.choices[0].delta.content;
|
|
1141
1018
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1142
1019
|
mode = null;
|
|
1143
|
-
eventStream$.sendTextMessageEnd(
|
|
1144
|
-
messageId: currentMessageId
|
|
1145
|
-
});
|
|
1020
|
+
eventStream$.sendTextMessageEnd();
|
|
1146
1021
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1147
1022
|
mode = null;
|
|
1148
|
-
eventStream$.sendActionExecutionEnd(
|
|
1149
|
-
actionExecutionId: currentToolCallId
|
|
1150
|
-
});
|
|
1023
|
+
eventStream$.sendActionExecutionEnd();
|
|
1151
1024
|
}
|
|
1152
1025
|
if (mode === null) {
|
|
1153
1026
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1154
1027
|
mode = "function";
|
|
1155
|
-
|
|
1156
|
-
eventStream$.sendActionExecutionStart({
|
|
1157
|
-
actionExecutionId: currentToolCallId,
|
|
1158
|
-
actionName: toolCall.function.name,
|
|
1159
|
-
parentMessageId: chunk.id
|
|
1160
|
-
});
|
|
1028
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1161
1029
|
} else if (content) {
|
|
1162
1030
|
mode = "message";
|
|
1163
|
-
|
|
1164
|
-
eventStream$.sendTextMessageStart({
|
|
1165
|
-
messageId: currentMessageId
|
|
1166
|
-
});
|
|
1031
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1167
1032
|
}
|
|
1168
1033
|
}
|
|
1169
1034
|
if (mode === "message" && content) {
|
|
1170
|
-
eventStream$.sendTextMessageContent(
|
|
1171
|
-
messageId: currentMessageId,
|
|
1172
|
-
content
|
|
1173
|
-
});
|
|
1035
|
+
eventStream$.sendTextMessageContent(content);
|
|
1174
1036
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1175
|
-
eventStream$.sendActionExecutionArgs(
|
|
1176
|
-
actionExecutionId: currentToolCallId,
|
|
1177
|
-
args: toolCall.function.arguments
|
|
1178
|
-
});
|
|
1037
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1179
1038
|
}
|
|
1180
1039
|
}
|
|
1181
1040
|
if (mode === "message") {
|
|
1182
|
-
eventStream$.sendTextMessageEnd(
|
|
1183
|
-
messageId: currentMessageId
|
|
1184
|
-
});
|
|
1041
|
+
eventStream$.sendTextMessageEnd();
|
|
1185
1042
|
} else if (mode === "function") {
|
|
1186
|
-
eventStream$.sendActionExecutionEnd(
|
|
1187
|
-
actionExecutionId: currentToolCallId
|
|
1188
|
-
});
|
|
1043
|
+
eventStream$.sendActionExecutionEnd();
|
|
1189
1044
|
}
|
|
1190
1045
|
eventStream$.complete();
|
|
1191
1046
|
});
|
|
@@ -1393,11 +1248,7 @@ var AnthropicAdapter = class {
|
|
|
1393
1248
|
mode = "message";
|
|
1394
1249
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1395
1250
|
currentToolCallId = chunk.content_block.id;
|
|
1396
|
-
eventStream$.sendActionExecutionStart(
|
|
1397
|
-
actionExecutionId: currentToolCallId,
|
|
1398
|
-
actionName: chunk.content_block.name,
|
|
1399
|
-
parentMessageId: currentMessageId
|
|
1400
|
-
});
|
|
1251
|
+
eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
|
|
1401
1252
|
mode = "function";
|
|
1402
1253
|
}
|
|
1403
1254
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1405,33 +1256,21 @@ var AnthropicAdapter = class {
|
|
|
1405
1256
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1406
1257
|
if (text.length > 0) {
|
|
1407
1258
|
if (!didOutputText) {
|
|
1408
|
-
eventStream$.sendTextMessageStart(
|
|
1409
|
-
messageId: currentMessageId
|
|
1410
|
-
});
|
|
1259
|
+
eventStream$.sendTextMessageStart(currentMessageId);
|
|
1411
1260
|
didOutputText = true;
|
|
1412
1261
|
}
|
|
1413
|
-
eventStream$.sendTextMessageContent(
|
|
1414
|
-
messageId: currentMessageId,
|
|
1415
|
-
content: text
|
|
1416
|
-
});
|
|
1262
|
+
eventStream$.sendTextMessageContent(text);
|
|
1417
1263
|
}
|
|
1418
1264
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1419
|
-
eventStream$.sendActionExecutionArgs(
|
|
1420
|
-
actionExecutionId: currentToolCallId,
|
|
1421
|
-
args: chunk.delta.partial_json
|
|
1422
|
-
});
|
|
1265
|
+
eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
|
|
1423
1266
|
}
|
|
1424
1267
|
} else if (chunk.type === "content_block_stop") {
|
|
1425
1268
|
if (mode === "message") {
|
|
1426
1269
|
if (didOutputText) {
|
|
1427
|
-
eventStream$.sendTextMessageEnd(
|
|
1428
|
-
messageId: currentMessageId
|
|
1429
|
-
});
|
|
1270
|
+
eventStream$.sendTextMessageEnd();
|
|
1430
1271
|
}
|
|
1431
1272
|
} else if (mode === "function") {
|
|
1432
|
-
eventStream$.sendActionExecutionEnd(
|
|
1433
|
-
actionExecutionId: currentToolCallId
|
|
1434
|
-
});
|
|
1273
|
+
eventStream$.sendActionExecutionEnd();
|
|
1435
1274
|
}
|
|
1436
1275
|
}
|
|
1437
1276
|
}
|
|
@@ -1476,12 +1315,58 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1476
1315
|
}
|
|
1477
1316
|
}, "FilterThinkingTextBuffer");
|
|
1478
1317
|
|
|
1318
|
+
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1319
|
+
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1320
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1321
|
+
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1322
|
+
var ExperimentalOllamaAdapter = class {
|
|
1323
|
+
model;
|
|
1324
|
+
constructor(options) {
|
|
1325
|
+
if (options == null ? void 0 : options.model) {
|
|
1326
|
+
this.model = options.model;
|
|
1327
|
+
} else {
|
|
1328
|
+
this.model = DEFAULT_MODEL4;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
async process(request) {
|
|
1332
|
+
const { messages, actions, eventSource } = request;
|
|
1333
|
+
const ollama = new import_ollama.Ollama({
|
|
1334
|
+
model: this.model
|
|
1335
|
+
});
|
|
1336
|
+
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1337
|
+
const _stream = await ollama.stream(contents);
|
|
1338
|
+
eventSource.stream(async (eventStream$) => {
|
|
1339
|
+
eventStream$.sendTextMessageStart((0, import_shared7.randomId)());
|
|
1340
|
+
for await (const chunkText of _stream) {
|
|
1341
|
+
eventStream$.sendTextMessageContent(chunkText);
|
|
1342
|
+
}
|
|
1343
|
+
eventStream$.sendTextMessageEnd();
|
|
1344
|
+
eventStream$.complete();
|
|
1345
|
+
});
|
|
1346
|
+
return {
|
|
1347
|
+
threadId: request.threadId || (0, import_shared7.randomId)()
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1352
|
+
|
|
1353
|
+
// src/service-adapters/experimental/empty/empty-adapter.ts
|
|
1354
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1355
|
+
var ExperimentalEmptyAdapter = class {
|
|
1356
|
+
async process(request) {
|
|
1357
|
+
return {
|
|
1358
|
+
threadId: request.threadId || (0, import_shared8.randomId)()
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
__name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
|
|
1363
|
+
|
|
1479
1364
|
// src/service-adapters/events.ts
|
|
1480
|
-
var
|
|
1365
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1481
1366
|
var import_rxjs2 = require("rxjs");
|
|
1482
1367
|
|
|
1483
1368
|
// src/lib/telemetry-client.ts
|
|
1484
|
-
var
|
|
1369
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1485
1370
|
|
|
1486
1371
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1487
1372
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1514,7 +1399,7 @@ var CustomEventNames;
|
|
|
1514
1399
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1515
1400
|
|
|
1516
1401
|
// src/agents/langgraph/event-source.ts
|
|
1517
|
-
var
|
|
1402
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1518
1403
|
var RemoteLangGraphEventSource = class {
|
|
1519
1404
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1520
1405
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1526,167 +1411,163 @@ var RemoteLangGraphEventSource = class {
|
|
|
1526
1411
|
}
|
|
1527
1412
|
return shouldEmitToolCalls === toolCallName;
|
|
1528
1413
|
}
|
|
1529
|
-
getCurrentContent(event) {
|
|
1530
|
-
var _a, _b, _c, _d, _e;
|
|
1531
|
-
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);
|
|
1532
|
-
if (!content) {
|
|
1533
|
-
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1534
|
-
for (const chunk of toolCallChunks) {
|
|
1535
|
-
if (chunk.args) {
|
|
1536
|
-
return chunk.args;
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
if (typeof content === "string") {
|
|
1541
|
-
return content;
|
|
1542
|
-
} else if (Array.isArray(content) && content.length > 0) {
|
|
1543
|
-
return content[0].text;
|
|
1544
|
-
}
|
|
1545
|
-
return null;
|
|
1546
|
-
}
|
|
1547
|
-
getCurrentMessageId(event) {
|
|
1548
|
-
var _a, _b, _c, _d, _e;
|
|
1549
|
-
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);
|
|
1550
|
-
}
|
|
1551
|
-
getCurrentToolCallChunks(event) {
|
|
1552
|
-
var _a, _b, _c, _d, _e;
|
|
1553
|
-
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);
|
|
1554
|
-
}
|
|
1555
|
-
getResponseMetadata(event) {
|
|
1556
|
-
var _a, _b, _c, _d, _e;
|
|
1557
|
-
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);
|
|
1558
|
-
}
|
|
1559
1414
|
processLangGraphEvents() {
|
|
1560
1415
|
let lastEventWithState = null;
|
|
1561
1416
|
return this.eventStream$.pipe((0, import_rxjs.scan)((acc, event) => {
|
|
1417
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1562
1418
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1563
|
-
const
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1419
|
+
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);
|
|
1420
|
+
if (typeof content === "string") {
|
|
1421
|
+
acc.content = content;
|
|
1422
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1423
|
+
acc.content = content[0].text;
|
|
1424
|
+
} else {
|
|
1425
|
+
acc.content = null;
|
|
1426
|
+
}
|
|
1427
|
+
const toolCallChunks = (
|
|
1428
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
1429
|
+
((_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)
|
|
1430
|
+
);
|
|
1431
|
+
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);
|
|
1432
|
+
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
1433
|
+
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1434
|
+
acc.toolCallMessageId = toolCallMessageId;
|
|
1435
|
+
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1436
|
+
acc.toolCallName = toolCallChunks[0].name;
|
|
1437
|
+
}
|
|
1438
|
+
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1439
|
+
acc.toolCallId = toolCallChunks[0].id;
|
|
1440
|
+
}
|
|
1441
|
+
acc.prevMessageId = acc.messageId;
|
|
1442
|
+
acc.messageId = toolCallMessageId;
|
|
1443
|
+
} else if (acc.content && acc.content != "") {
|
|
1444
|
+
acc.prevMessageId = acc.messageId;
|
|
1445
|
+
acc.messageId = toolCallMessageId;
|
|
1446
|
+
} else {
|
|
1447
|
+
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1448
|
+
acc.prevMessageId = acc.messageId;
|
|
1449
|
+
}
|
|
1450
|
+
} else {
|
|
1451
|
+
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1452
|
+
acc.toolCallMessageId = null;
|
|
1453
|
+
acc.prevMessageId = acc.messageId;
|
|
1454
|
+
acc.messageId = null;
|
|
1455
|
+
acc.toolCallName = null;
|
|
1577
1456
|
}
|
|
1578
1457
|
acc.event = event;
|
|
1579
1458
|
lastEventWithState = acc;
|
|
1580
1459
|
return acc;
|
|
1581
1460
|
}, {
|
|
1582
1461
|
event: null,
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1462
|
+
toolCallId: null,
|
|
1463
|
+
toolCallMessageId: null,
|
|
1464
|
+
prevToolCallMessageId: null,
|
|
1465
|
+
messageId: null,
|
|
1466
|
+
toolCallName: null,
|
|
1467
|
+
prevMessageId: null,
|
|
1468
|
+
content: null
|
|
1469
|
+
}), (0, import_rxjs.mergeMap)((eventWithState) => {
|
|
1470
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1593
1471
|
const events = [];
|
|
1594
1472
|
let shouldEmitMessages = true;
|
|
1595
|
-
let shouldEmitToolCalls =
|
|
1596
|
-
if (
|
|
1597
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1598
|
-
shouldEmitToolCalls =
|
|
1473
|
+
let shouldEmitToolCalls = false;
|
|
1474
|
+
if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1475
|
+
if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
|
|
1476
|
+
shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
|
|
1599
1477
|
}
|
|
1600
|
-
if ("copilotkit:emit-messages" in (
|
|
1601
|
-
shouldEmitMessages =
|
|
1478
|
+
if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
|
|
1479
|
+
shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
|
|
1602
1480
|
}
|
|
1603
1481
|
}
|
|
1604
|
-
|
|
1605
|
-
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1482
|
+
if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1606
1483
|
events.push({
|
|
1607
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1608
|
-
actionExecutionId: acc.lastToolCallId
|
|
1484
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1609
1485
|
});
|
|
1610
1486
|
}
|
|
1611
|
-
if (
|
|
1487
|
+
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1612
1488
|
events.push({
|
|
1613
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1614
|
-
messageId: acc.lastMessageId
|
|
1489
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1615
1490
|
});
|
|
1616
1491
|
}
|
|
1617
|
-
switch (
|
|
1492
|
+
switch (eventWithState.event.event) {
|
|
1618
1493
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1619
|
-
if (
|
|
1494
|
+
if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1620
1495
|
events.push({
|
|
1621
1496
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1622
|
-
messageId:
|
|
1497
|
+
messageId: eventWithState.event.data.message_id
|
|
1623
1498
|
});
|
|
1624
1499
|
events.push({
|
|
1625
1500
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1626
|
-
|
|
1627
|
-
content: acc.event.data.message
|
|
1501
|
+
content: eventWithState.event.data.message
|
|
1628
1502
|
});
|
|
1629
1503
|
events.push({
|
|
1630
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1631
|
-
messageId: acc.event.data.message_id
|
|
1504
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1632
1505
|
});
|
|
1633
|
-
} else if (
|
|
1506
|
+
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1634
1507
|
events.push({
|
|
1635
1508
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1636
|
-
actionExecutionId:
|
|
1637
|
-
actionName:
|
|
1638
|
-
parentMessageId: acc.event.data.id
|
|
1509
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1510
|
+
actionName: eventWithState.event.data.name
|
|
1639
1511
|
});
|
|
1640
1512
|
events.push({
|
|
1641
1513
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1642
|
-
|
|
1643
|
-
args: JSON.stringify(acc.event.data.args)
|
|
1514
|
+
args: JSON.stringify(eventWithState.event.data.args)
|
|
1644
1515
|
});
|
|
1645
1516
|
events.push({
|
|
1646
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1647
|
-
actionExecutionId: acc.event.data.id
|
|
1517
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1648
1518
|
});
|
|
1649
1519
|
}
|
|
1650
1520
|
break;
|
|
1651
1521
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1652
1522
|
events.push({
|
|
1653
1523
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1654
|
-
threadId:
|
|
1655
|
-
role:
|
|
1656
|
-
agentName:
|
|
1657
|
-
nodeName:
|
|
1658
|
-
runId:
|
|
1659
|
-
active:
|
|
1660
|
-
state: JSON.stringify(
|
|
1661
|
-
running:
|
|
1524
|
+
threadId: eventWithState.event.thread_id,
|
|
1525
|
+
role: eventWithState.event.role,
|
|
1526
|
+
agentName: eventWithState.event.agent_name,
|
|
1527
|
+
nodeName: eventWithState.event.node_name,
|
|
1528
|
+
runId: eventWithState.event.run_id,
|
|
1529
|
+
active: eventWithState.event.active,
|
|
1530
|
+
state: JSON.stringify(eventWithState.event.state),
|
|
1531
|
+
running: eventWithState.event.running
|
|
1662
1532
|
});
|
|
1663
1533
|
break;
|
|
1534
|
+
case LangGraphEventTypes.OnToolEnd:
|
|
1535
|
+
break;
|
|
1664
1536
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1665
|
-
if (
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1537
|
+
if (eventWithState.toolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId) {
|
|
1538
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1539
|
+
events.push({
|
|
1540
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1541
|
+
actionExecutionId: eventWithState.toolCallMessageId,
|
|
1542
|
+
actionName: eventWithState.toolCallName,
|
|
1543
|
+
scope: "client"
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
} else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
|
|
1547
|
+
if (shouldEmitMessages) {
|
|
1548
|
+
events.push({
|
|
1549
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1550
|
+
messageId: eventWithState.messageId
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1677
1553
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1554
|
+
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
|
|
1555
|
+
((_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);
|
|
1556
|
+
const content = eventWithState.content;
|
|
1557
|
+
if (args) {
|
|
1558
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1559
|
+
events.push({
|
|
1560
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1561
|
+
args
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
} else if (eventWithState.messageId !== null && content) {
|
|
1565
|
+
if (shouldEmitMessages) {
|
|
1566
|
+
events.push({
|
|
1567
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1568
|
+
content
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1690
1571
|
}
|
|
1691
1572
|
break;
|
|
1692
1573
|
}
|
|
@@ -1694,31 +1575,27 @@ var RemoteLangGraphEventSource = class {
|
|
|
1694
1575
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1695
1576
|
console.error(error);
|
|
1696
1577
|
const events = [];
|
|
1697
|
-
if (
|
|
1578
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1698
1579
|
events.push({
|
|
1699
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1700
|
-
messageId: lastEventWithState.lastMessageId
|
|
1580
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1701
1581
|
});
|
|
1702
1582
|
}
|
|
1703
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1583
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1704
1584
|
events.push({
|
|
1705
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1706
|
-
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1585
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1707
1586
|
});
|
|
1708
1587
|
}
|
|
1709
|
-
const messageId = (0,
|
|
1588
|
+
const messageId = (0, import_shared9.randomId)();
|
|
1710
1589
|
events.push({
|
|
1711
1590
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1712
1591
|
messageId
|
|
1713
1592
|
});
|
|
1714
1593
|
events.push({
|
|
1715
1594
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1716
|
-
messageId,
|
|
1717
1595
|
content: "\u274C An error occurred. Please try again."
|
|
1718
1596
|
});
|
|
1719
1597
|
events.push({
|
|
1720
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1721
|
-
messageId
|
|
1598
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1722
1599
|
});
|
|
1723
1600
|
return events;
|
|
1724
1601
|
}));
|
|
@@ -1740,6 +1617,12 @@ var MessageRole;
|
|
|
1740
1617
|
MessageRole2["system"] = "system";
|
|
1741
1618
|
MessageRole2["tool"] = "tool";
|
|
1742
1619
|
})(MessageRole || (MessageRole = {}));
|
|
1620
|
+
var ActionExecutionScope;
|
|
1621
|
+
(function(ActionExecutionScope2) {
|
|
1622
|
+
ActionExecutionScope2["server"] = "server";
|
|
1623
|
+
ActionExecutionScope2["client"] = "client";
|
|
1624
|
+
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1625
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1743
1626
|
var CopilotRequestType;
|
|
1744
1627
|
(function(CopilotRequestType2) {
|
|
1745
1628
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1758,6 +1641,10 @@ var ActionInputAvailability;
|
|
|
1758
1641
|
name: "MessageRole",
|
|
1759
1642
|
description: "The role of the message"
|
|
1760
1643
|
});
|
|
1644
|
+
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1645
|
+
name: "ActionExecutionScope",
|
|
1646
|
+
description: "The scope of the action"
|
|
1647
|
+
});
|
|
1761
1648
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1762
1649
|
name: "CopilotRequestType",
|
|
1763
1650
|
description: "The type of Copilot request"
|
|
@@ -1814,7 +1701,7 @@ async function streamEvents(controller, args) {
|
|
|
1814
1701
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1815
1702
|
let formattedMessages = [];
|
|
1816
1703
|
try {
|
|
1817
|
-
formattedMessages =
|
|
1704
|
+
formattedMessages = formatMessages(messages);
|
|
1818
1705
|
} catch (e) {
|
|
1819
1706
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1820
1707
|
}
|
|
@@ -1967,8 +1854,7 @@ async function streamEvents(controller, args) {
|
|
|
1967
1854
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1968
1855
|
state: state.values,
|
|
1969
1856
|
running: !shouldExit,
|
|
1970
|
-
active: false
|
|
1971
|
-
includeMessages: true
|
|
1857
|
+
active: false
|
|
1972
1858
|
}));
|
|
1973
1859
|
return Promise.resolve();
|
|
1974
1860
|
} catch (e) {
|
|
@@ -1981,20 +1867,13 @@ async function streamEvents(controller, args) {
|
|
|
1981
1867
|
}
|
|
1982
1868
|
}
|
|
1983
1869
|
__name(streamEvents, "streamEvents");
|
|
1984
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
}, {});
|
|
1992
|
-
} else {
|
|
1993
|
-
state = {
|
|
1994
|
-
...state,
|
|
1995
|
-
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1996
|
-
};
|
|
1997
|
-
}
|
|
1870
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1871
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1872
|
+
if (key !== "messages") {
|
|
1873
|
+
acc[key] = state[key];
|
|
1874
|
+
}
|
|
1875
|
+
return acc;
|
|
1876
|
+
}, {});
|
|
1998
1877
|
return JSON.stringify({
|
|
1999
1878
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
2000
1879
|
thread_id: threadId,
|
|
@@ -2002,7 +1881,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
2002
1881
|
agent_name: agentName,
|
|
2003
1882
|
node_name: nodeName,
|
|
2004
1883
|
active,
|
|
2005
|
-
state,
|
|
1884
|
+
state: stateWithoutMessages,
|
|
2006
1885
|
running,
|
|
2007
1886
|
role: "assistant"
|
|
2008
1887
|
}) + "\n";
|
|
@@ -2078,159 +1957,134 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
2078
1957
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
2079
1958
|
messages = messages.slice(1);
|
|
2080
1959
|
}
|
|
2081
|
-
const
|
|
2082
|
-
const existingMessageIds = new Set(
|
|
2083
|
-
const
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
copilotkit: {
|
|
2088
|
-
actions
|
|
2089
|
-
}
|
|
2090
|
-
};
|
|
2091
|
-
}
|
|
2092
|
-
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
2093
|
-
function langchainMessagesToCopilotKit(messages) {
|
|
2094
|
-
const result = [];
|
|
2095
|
-
const tool_call_names = {};
|
|
2096
|
-
for (const message of messages) {
|
|
2097
|
-
if (message.type === "ai") {
|
|
2098
|
-
for (const tool_call of message.tool_calls) {
|
|
2099
|
-
tool_call_names[tool_call.id] = tool_call.name;
|
|
2100
|
-
}
|
|
1960
|
+
const mergedMessages = state.messages || [];
|
|
1961
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1962
|
+
const existingToolCallResults = /* @__PURE__ */ new Set();
|
|
1963
|
+
for (const message of mergedMessages) {
|
|
1964
|
+
if ("tool_call_id" in message) {
|
|
1965
|
+
existingToolCallResults.add(message.tool_call_id);
|
|
2101
1966
|
}
|
|
2102
1967
|
}
|
|
2103
1968
|
for (const message of messages) {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
content = content[0];
|
|
1969
|
+
if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
|
|
1970
|
+
continue;
|
|
2107
1971
|
}
|
|
2108
|
-
if (
|
|
2109
|
-
|
|
1972
|
+
if ("name" in message && message.name === agentName) {
|
|
1973
|
+
continue;
|
|
2110
1974
|
}
|
|
2111
|
-
if (message.
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
} else
|
|
2118
|
-
|
|
2119
|
-
role
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
for (const tool_call of message.tool_calls) {
|
|
2126
|
-
result.push({
|
|
2127
|
-
id: tool_call.id,
|
|
2128
|
-
name: tool_call.name,
|
|
2129
|
-
arguments: tool_call.args,
|
|
2130
|
-
parentMessageId: message.id
|
|
2131
|
-
});
|
|
1975
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1976
|
+
if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
|
|
1977
|
+
console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
|
|
1978
|
+
continue;
|
|
1979
|
+
}
|
|
1980
|
+
mergedMessages.push(message);
|
|
1981
|
+
} else {
|
|
1982
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1983
|
+
if (mergedMessages[i].id === message.id && message.role === "assistant") {
|
|
1984
|
+
if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
|
|
1985
|
+
message.tool_calls = mergedMessages[i]["tool_calls"];
|
|
1986
|
+
message.additional_kwargs = mergedMessages[i].additional_kwargs;
|
|
1987
|
+
}
|
|
1988
|
+
mergedMessages[i] = message;
|
|
2132
1989
|
}
|
|
2133
|
-
} else {
|
|
2134
|
-
result.push({
|
|
2135
|
-
role: "assistant",
|
|
2136
|
-
content,
|
|
2137
|
-
id: message.id,
|
|
2138
|
-
parentMessageId: message.id
|
|
2139
|
-
});
|
|
2140
1990
|
}
|
|
2141
|
-
} else if (message.type === "tool") {
|
|
2142
|
-
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
2143
|
-
result.push({
|
|
2144
|
-
actionExecutionId: message.tool_call_id,
|
|
2145
|
-
actionName,
|
|
2146
|
-
result: content,
|
|
2147
|
-
id: message.id
|
|
2148
|
-
});
|
|
2149
1991
|
}
|
|
2150
1992
|
}
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
1993
|
+
for (let i = 0; i < mergedMessages.length - 1; i++) {
|
|
1994
|
+
const currentMessage = mergedMessages[i];
|
|
1995
|
+
const nextMessage = mergedMessages[i + 1];
|
|
1996
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
|
|
1997
|
+
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
2155
1998
|
}
|
|
2156
1999
|
}
|
|
2157
|
-
const
|
|
2158
|
-
for (
|
|
2159
|
-
|
|
2160
|
-
|
|
2000
|
+
const correctedMessages = [];
|
|
2001
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
2002
|
+
const currentMessage = mergedMessages[i];
|
|
2003
|
+
const nextMessage = mergedMessages[i + 1] || null;
|
|
2004
|
+
const prevMessage = mergedMessages[i - 1] || null;
|
|
2005
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
2006
|
+
if (!nextMessage) {
|
|
2007
|
+
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
2008
|
+
continue;
|
|
2009
|
+
}
|
|
2010
|
+
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
2011
|
+
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
2012
|
+
if (toolMessage) {
|
|
2013
|
+
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
2014
|
+
correctedMessages.push(currentMessage, toolMessage);
|
|
2015
|
+
continue;
|
|
2016
|
+
} else {
|
|
2017
|
+
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
correctedMessages.push(currentMessage);
|
|
2022
|
+
continue;
|
|
2161
2023
|
}
|
|
2162
|
-
if ("
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2024
|
+
if ("tool_call_id" in currentMessage) {
|
|
2025
|
+
if (!prevMessage || !("tool_calls" in prevMessage)) {
|
|
2026
|
+
console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
|
|
2027
|
+
continue;
|
|
2028
|
+
}
|
|
2029
|
+
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
2030
|
+
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
2031
|
+
continue;
|
|
2168
2032
|
}
|
|
2033
|
+
correctedMessages.push(currentMessage);
|
|
2034
|
+
continue;
|
|
2169
2035
|
}
|
|
2036
|
+
correctedMessages.push(currentMessage);
|
|
2170
2037
|
}
|
|
2171
|
-
return
|
|
2038
|
+
return {
|
|
2039
|
+
...state,
|
|
2040
|
+
messages: correctedMessages,
|
|
2041
|
+
copilotkit: {
|
|
2042
|
+
actions
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2172
2045
|
}
|
|
2173
|
-
__name(
|
|
2174
|
-
function
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
} else if (message.role === "system") {
|
|
2185
|
-
result.push({
|
|
2186
|
-
...message,
|
|
2187
|
-
role: MessageRole.system
|
|
2188
|
-
});
|
|
2189
|
-
} else if (message.role === "assistant") {
|
|
2190
|
-
result.push({
|
|
2191
|
-
...message,
|
|
2192
|
-
role: MessageRole.assistant
|
|
2193
|
-
});
|
|
2194
|
-
}
|
|
2195
|
-
continue;
|
|
2046
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
2047
|
+
function formatMessages(messages) {
|
|
2048
|
+
return messages.map((message) => {
|
|
2049
|
+
if (message.isTextMessage() && message.role === "assistant") {
|
|
2050
|
+
return message;
|
|
2051
|
+
}
|
|
2052
|
+
if (message.isTextMessage() && message.role === "system") {
|
|
2053
|
+
return message;
|
|
2054
|
+
}
|
|
2055
|
+
if (message.isTextMessage() && message.role === "user") {
|
|
2056
|
+
return message;
|
|
2196
2057
|
}
|
|
2197
2058
|
if (message.isActionExecutionMessage()) {
|
|
2198
|
-
const
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
name: m.name,
|
|
2206
|
-
args: m.arguments,
|
|
2207
|
-
id: m.id
|
|
2208
|
-
}));
|
|
2209
|
-
result.push({
|
|
2210
|
-
id: messageId,
|
|
2211
|
-
type: "ActionExecutionMessage",
|
|
2059
|
+
const toolCall = {
|
|
2060
|
+
name: message.name,
|
|
2061
|
+
args: message.arguments,
|
|
2062
|
+
id: message.id
|
|
2063
|
+
};
|
|
2064
|
+
return {
|
|
2065
|
+
type: message.type,
|
|
2212
2066
|
content: "",
|
|
2213
|
-
tool_calls
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2067
|
+
tool_calls: [
|
|
2068
|
+
toolCall
|
|
2069
|
+
],
|
|
2070
|
+
role: MessageRole.assistant,
|
|
2071
|
+
id: message.id
|
|
2072
|
+
};
|
|
2217
2073
|
}
|
|
2218
2074
|
if (message.isResultMessage()) {
|
|
2219
|
-
|
|
2075
|
+
return {
|
|
2220
2076
|
type: message.type,
|
|
2221
2077
|
content: message.result,
|
|
2222
2078
|
id: message.id,
|
|
2223
2079
|
tool_call_id: message.actionExecutionId,
|
|
2224
2080
|
name: message.actionName,
|
|
2225
2081
|
role: MessageRole.tool
|
|
2226
|
-
}
|
|
2227
|
-
continue;
|
|
2082
|
+
};
|
|
2228
2083
|
}
|
|
2229
2084
|
throw new Error(`Unknown message type ${message.type}`);
|
|
2230
|
-
}
|
|
2231
|
-
return result;
|
|
2085
|
+
});
|
|
2232
2086
|
}
|
|
2233
|
-
__name(
|
|
2087
|
+
__name(formatMessages, "formatMessages");
|
|
2234
2088
|
|
|
2235
2089
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2236
2090
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -2240,7 +2094,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2240
2094
|
parameters: [],
|
|
2241
2095
|
handler: async (_args) => {
|
|
2242
2096
|
},
|
|
2243
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
2097
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2244
2098
|
var _a;
|
|
2245
2099
|
logger2.debug({
|
|
2246
2100
|
actionName: agent.name
|
|
@@ -2266,10 +2120,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2266
2120
|
agent,
|
|
2267
2121
|
threadId,
|
|
2268
2122
|
nodeName,
|
|
2269
|
-
messages
|
|
2270
|
-
...messages,
|
|
2271
|
-
...additionalMessages
|
|
2272
|
-
],
|
|
2123
|
+
messages,
|
|
2273
2124
|
state,
|
|
2274
2125
|
properties: graphqlContext.properties,
|
|
2275
2126
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2297,6 +2148,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2297
2148
|
}
|
|
2298
2149
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2299
2150
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2151
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2300
2152
|
const actions = json["actions"].map((action) => ({
|
|
2301
2153
|
name: action.name,
|
|
2302
2154
|
description: action.description,
|
|
@@ -2310,7 +2162,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2310
2162
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2311
2163
|
agentExecution: false,
|
|
2312
2164
|
type: "self-hosted",
|
|
2313
|
-
agentsAmount:
|
|
2165
|
+
agentsAmount: totalAgents
|
|
2314
2166
|
});
|
|
2315
2167
|
try {
|
|
2316
2168
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2345,13 +2197,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2345
2197
|
}
|
|
2346
2198
|
}
|
|
2347
2199
|
}));
|
|
2348
|
-
const agents = json["agents"].map((agent) => ({
|
|
2200
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
2349
2201
|
name: agent.name,
|
|
2350
2202
|
description: agent.description,
|
|
2351
2203
|
parameters: [],
|
|
2352
2204
|
handler: async (_args) => {
|
|
2353
2205
|
},
|
|
2354
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
2206
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2355
2207
|
var _a;
|
|
2356
2208
|
logger2.debug({
|
|
2357
2209
|
actionName: agent.name
|
|
@@ -2376,10 +2228,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2376
2228
|
name,
|
|
2377
2229
|
threadId,
|
|
2378
2230
|
nodeName,
|
|
2379
|
-
messages
|
|
2380
|
-
...messages,
|
|
2381
|
-
...additionalMessages
|
|
2382
|
-
],
|
|
2231
|
+
messages,
|
|
2383
2232
|
state,
|
|
2384
2233
|
properties: graphqlContext.properties,
|
|
2385
2234
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2401,7 +2250,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2401
2250
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2402
2251
|
return eventSource.processLangGraphEvents();
|
|
2403
2252
|
}
|
|
2404
|
-
}));
|
|
2253
|
+
})) : [];
|
|
2405
2254
|
return [
|
|
2406
2255
|
...actions,
|
|
2407
2256
|
...agents
|
|
@@ -2578,7 +2427,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2578
2427
|
// src/lib/telemetry-client.ts
|
|
2579
2428
|
var import_node_crypto3 = require("crypto");
|
|
2580
2429
|
var packageJson = require_package();
|
|
2581
|
-
var telemetryClient = new
|
|
2430
|
+
var telemetryClient = new import_shared10.TelemetryClient({
|
|
2582
2431
|
packageName: packageJson.name,
|
|
2583
2432
|
packageVersion: packageJson.version
|
|
2584
2433
|
});
|
|
@@ -2622,94 +2471,7 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2622
2471
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2623
2472
|
var telemetry_client_default = telemetryClient;
|
|
2624
2473
|
|
|
2625
|
-
// src/graphql/types/base/index.ts
|
|
2626
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2627
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2628
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2629
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2630
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2631
|
-
else
|
|
2632
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2633
|
-
if (d = decorators[i])
|
|
2634
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2635
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2636
|
-
}
|
|
2637
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2638
|
-
function _ts_metadata(k, v) {
|
|
2639
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2640
|
-
return Reflect.metadata(k, v);
|
|
2641
|
-
}
|
|
2642
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2643
|
-
var BaseMessageInput = class {
|
|
2644
|
-
id;
|
|
2645
|
-
createdAt;
|
|
2646
|
-
};
|
|
2647
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2648
|
-
_ts_decorate([
|
|
2649
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2650
|
-
_ts_metadata("design:type", String)
|
|
2651
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2652
|
-
_ts_decorate([
|
|
2653
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2654
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2655
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2656
|
-
BaseMessageInput = _ts_decorate([
|
|
2657
|
-
(0, import_type_graphql2.InputType)()
|
|
2658
|
-
], BaseMessageInput);
|
|
2659
|
-
|
|
2660
|
-
// src/graphql/types/converted/index.ts
|
|
2661
|
-
var Message = class extends BaseMessageInput {
|
|
2662
|
-
type;
|
|
2663
|
-
isTextMessage() {
|
|
2664
|
-
return this.type === "TextMessage";
|
|
2665
|
-
}
|
|
2666
|
-
isActionExecutionMessage() {
|
|
2667
|
-
return this.type === "ActionExecutionMessage";
|
|
2668
|
-
}
|
|
2669
|
-
isResultMessage() {
|
|
2670
|
-
return this.type === "ResultMessage";
|
|
2671
|
-
}
|
|
2672
|
-
isAgentStateMessage() {
|
|
2673
|
-
return this.type === "AgentStateMessage";
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
__name(Message, "Message");
|
|
2677
|
-
var TextMessage = class extends Message {
|
|
2678
|
-
type = "TextMessage";
|
|
2679
|
-
content;
|
|
2680
|
-
role;
|
|
2681
|
-
parentMessageId;
|
|
2682
|
-
};
|
|
2683
|
-
__name(TextMessage, "TextMessage");
|
|
2684
|
-
var ActionExecutionMessage = class extends Message {
|
|
2685
|
-
type = "ActionExecutionMessage";
|
|
2686
|
-
name;
|
|
2687
|
-
arguments;
|
|
2688
|
-
parentMessageId;
|
|
2689
|
-
};
|
|
2690
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2691
|
-
var ResultMessage = class extends Message {
|
|
2692
|
-
type = "ResultMessage";
|
|
2693
|
-
actionExecutionId;
|
|
2694
|
-
actionName;
|
|
2695
|
-
result;
|
|
2696
|
-
};
|
|
2697
|
-
__name(ResultMessage, "ResultMessage");
|
|
2698
|
-
var AgentStateMessage = class extends Message {
|
|
2699
|
-
type = "AgentStateMessage";
|
|
2700
|
-
threadId;
|
|
2701
|
-
agentName;
|
|
2702
|
-
nodeName;
|
|
2703
|
-
runId;
|
|
2704
|
-
active;
|
|
2705
|
-
role;
|
|
2706
|
-
state;
|
|
2707
|
-
running;
|
|
2708
|
-
};
|
|
2709
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2710
|
-
|
|
2711
2474
|
// src/service-adapters/events.ts
|
|
2712
|
-
var import_class_transformer = require("class-transformer");
|
|
2713
2475
|
var RuntimeEventTypes;
|
|
2714
2476
|
(function(RuntimeEventTypes2) {
|
|
2715
2477
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2725,74 +2487,52 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2725
2487
|
constructor() {
|
|
2726
2488
|
super();
|
|
2727
2489
|
}
|
|
2728
|
-
sendTextMessageStart(
|
|
2490
|
+
sendTextMessageStart(messageId) {
|
|
2729
2491
|
this.next({
|
|
2730
2492
|
type: "TextMessageStart",
|
|
2731
|
-
messageId
|
|
2732
|
-
parentMessageId
|
|
2493
|
+
messageId
|
|
2733
2494
|
});
|
|
2734
2495
|
}
|
|
2735
|
-
sendTextMessageContent(
|
|
2496
|
+
sendTextMessageContent(content) {
|
|
2736
2497
|
this.next({
|
|
2737
2498
|
type: "TextMessageContent",
|
|
2738
|
-
content
|
|
2739
|
-
messageId
|
|
2499
|
+
content
|
|
2740
2500
|
});
|
|
2741
2501
|
}
|
|
2742
|
-
sendTextMessageEnd(
|
|
2502
|
+
sendTextMessageEnd() {
|
|
2743
2503
|
this.next({
|
|
2744
|
-
type: "TextMessageEnd"
|
|
2745
|
-
messageId
|
|
2504
|
+
type: "TextMessageEnd"
|
|
2746
2505
|
});
|
|
2747
2506
|
}
|
|
2748
2507
|
sendTextMessage(messageId, content) {
|
|
2749
|
-
this.sendTextMessageStart(
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
this.sendTextMessageContent({
|
|
2753
|
-
messageId,
|
|
2754
|
-
content
|
|
2755
|
-
});
|
|
2756
|
-
this.sendTextMessageEnd({
|
|
2757
|
-
messageId
|
|
2758
|
-
});
|
|
2508
|
+
this.sendTextMessageStart(messageId);
|
|
2509
|
+
this.sendTextMessageContent(content);
|
|
2510
|
+
this.sendTextMessageEnd();
|
|
2759
2511
|
}
|
|
2760
|
-
sendActionExecutionStart(
|
|
2512
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2761
2513
|
this.next({
|
|
2762
2514
|
type: "ActionExecutionStart",
|
|
2763
2515
|
actionExecutionId,
|
|
2764
|
-
actionName
|
|
2765
|
-
parentMessageId
|
|
2516
|
+
actionName
|
|
2766
2517
|
});
|
|
2767
2518
|
}
|
|
2768
|
-
sendActionExecutionArgs(
|
|
2519
|
+
sendActionExecutionArgs(args) {
|
|
2769
2520
|
this.next({
|
|
2770
2521
|
type: "ActionExecutionArgs",
|
|
2771
|
-
args
|
|
2772
|
-
actionExecutionId
|
|
2522
|
+
args
|
|
2773
2523
|
});
|
|
2774
2524
|
}
|
|
2775
|
-
sendActionExecutionEnd(
|
|
2525
|
+
sendActionExecutionEnd() {
|
|
2776
2526
|
this.next({
|
|
2777
|
-
type: "ActionExecutionEnd"
|
|
2778
|
-
actionExecutionId
|
|
2527
|
+
type: "ActionExecutionEnd"
|
|
2779
2528
|
});
|
|
2780
2529
|
}
|
|
2781
|
-
sendActionExecution(
|
|
2782
|
-
this.sendActionExecutionStart(
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
parentMessageId
|
|
2786
|
-
});
|
|
2787
|
-
this.sendActionExecutionArgs({
|
|
2788
|
-
actionExecutionId,
|
|
2789
|
-
args
|
|
2790
|
-
});
|
|
2791
|
-
this.sendActionExecutionEnd({
|
|
2792
|
-
actionExecutionId
|
|
2793
|
-
});
|
|
2530
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
2531
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
2532
|
+
this.sendActionExecutionArgs(args);
|
|
2533
|
+
this.sendActionExecutionEnd();
|
|
2794
2534
|
}
|
|
2795
|
-
sendActionExecutionResult(
|
|
2535
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2796
2536
|
this.next({
|
|
2797
2537
|
type: "ActionExecutionResult",
|
|
2798
2538
|
actionName,
|
|
@@ -2800,7 +2540,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2800
2540
|
result
|
|
2801
2541
|
});
|
|
2802
2542
|
}
|
|
2803
|
-
sendAgentStateMessage(
|
|
2543
|
+
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2804
2544
|
this.next({
|
|
2805
2545
|
type: "AgentStateMessage",
|
|
2806
2546
|
threadId,
|
|
@@ -2825,10 +2565,10 @@ var RuntimeEventSource = class {
|
|
|
2825
2565
|
const errorMessage = "\u274C An error occurred. Please try again.";
|
|
2826
2566
|
if (!this.callback) {
|
|
2827
2567
|
this.stream(async (eventStream$) => {
|
|
2828
|
-
eventStream$.sendTextMessage((0,
|
|
2568
|
+
eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2829
2569
|
});
|
|
2830
2570
|
} else {
|
|
2831
|
-
this.eventStream$.sendTextMessage((0,
|
|
2571
|
+
this.eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2832
2572
|
}
|
|
2833
2573
|
}
|
|
2834
2574
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2837,13 +2577,22 @@ var RuntimeEventSource = class {
|
|
|
2837
2577
|
this.sendErrorMessageToChat();
|
|
2838
2578
|
});
|
|
2839
2579
|
return this.eventStream$.pipe(
|
|
2580
|
+
// mark tools for server side execution
|
|
2581
|
+
(0, import_rxjs2.map)((event) => {
|
|
2582
|
+
if (event.type === "ActionExecutionStart") {
|
|
2583
|
+
if (event.scope !== "passThrough") {
|
|
2584
|
+
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
return event;
|
|
2588
|
+
}),
|
|
2840
2589
|
// track state
|
|
2841
2590
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2842
2591
|
acc = {
|
|
2843
2592
|
...acc
|
|
2844
2593
|
};
|
|
2845
2594
|
if (event.type === "ActionExecutionStart") {
|
|
2846
|
-
acc.callActionServerSide =
|
|
2595
|
+
acc.callActionServerSide = event.scope === "server";
|
|
2847
2596
|
acc.args = "";
|
|
2848
2597
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2849
2598
|
if (acc.callActionServerSide) {
|
|
@@ -2897,33 +2646,10 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2897
2646
|
}
|
|
2898
2647
|
}
|
|
2899
2648
|
if (isLangGraphAgentAction(action)) {
|
|
2900
|
-
|
|
2901
|
-
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2902
|
-
id: actionExecutionId,
|
|
2903
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2904
|
-
name: action.name,
|
|
2905
|
-
arguments: JSON.parse(actionArguments),
|
|
2906
|
-
parentMessageId: actionExecutionId
|
|
2907
|
-
});
|
|
2908
|
-
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2909
|
-
id: "result-" + actionExecutionId,
|
|
2910
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2911
|
-
actionExecutionId,
|
|
2912
|
-
actionName: action.name,
|
|
2913
|
-
result
|
|
2914
|
-
});
|
|
2915
|
-
eventStream$.sendActionExecutionResult({
|
|
2916
|
-
actionExecutionId,
|
|
2917
|
-
actionName: action.name,
|
|
2918
|
-
result
|
|
2919
|
-
});
|
|
2649
|
+
eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
|
|
2920
2650
|
const stream = await action.langGraphAgentHandler({
|
|
2921
2651
|
name: action.name,
|
|
2922
|
-
actionInputsWithoutAgents
|
|
2923
|
-
additionalMessages: [
|
|
2924
|
-
agentExecution,
|
|
2925
|
-
agentExecutionResult
|
|
2926
|
-
]
|
|
2652
|
+
actionInputsWithoutAgents
|
|
2927
2653
|
});
|
|
2928
2654
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2929
2655
|
next: (event) => eventStream$.next(event),
|
|
@@ -2944,29 +2670,113 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2944
2670
|
}
|
|
2945
2671
|
__name(executeAction, "executeAction");
|
|
2946
2672
|
|
|
2673
|
+
// src/graphql/types/base/index.ts
|
|
2674
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2675
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2676
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2677
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2678
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2679
|
+
else
|
|
2680
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2681
|
+
if (d = decorators[i])
|
|
2682
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2683
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2684
|
+
}
|
|
2685
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2686
|
+
function _ts_metadata(k, v) {
|
|
2687
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2688
|
+
return Reflect.metadata(k, v);
|
|
2689
|
+
}
|
|
2690
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2691
|
+
var BaseMessageInput = class {
|
|
2692
|
+
id;
|
|
2693
|
+
createdAt;
|
|
2694
|
+
};
|
|
2695
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2696
|
+
_ts_decorate([
|
|
2697
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2698
|
+
_ts_metadata("design:type", String)
|
|
2699
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2700
|
+
_ts_decorate([
|
|
2701
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2702
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2703
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2704
|
+
BaseMessageInput = _ts_decorate([
|
|
2705
|
+
(0, import_type_graphql2.InputType)()
|
|
2706
|
+
], BaseMessageInput);
|
|
2707
|
+
|
|
2708
|
+
// src/graphql/types/converted/index.ts
|
|
2709
|
+
var Message = class extends BaseMessageInput {
|
|
2710
|
+
type;
|
|
2711
|
+
isTextMessage() {
|
|
2712
|
+
return this.type === "TextMessage";
|
|
2713
|
+
}
|
|
2714
|
+
isActionExecutionMessage() {
|
|
2715
|
+
return this.type === "ActionExecutionMessage";
|
|
2716
|
+
}
|
|
2717
|
+
isResultMessage() {
|
|
2718
|
+
return this.type === "ResultMessage";
|
|
2719
|
+
}
|
|
2720
|
+
isAgentStateMessage() {
|
|
2721
|
+
return this.type === "AgentStateMessage";
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
__name(Message, "Message");
|
|
2725
|
+
var TextMessage = class extends Message {
|
|
2726
|
+
type = "TextMessage";
|
|
2727
|
+
content;
|
|
2728
|
+
role;
|
|
2729
|
+
};
|
|
2730
|
+
__name(TextMessage, "TextMessage");
|
|
2731
|
+
var ActionExecutionMessage = class extends Message {
|
|
2732
|
+
type = "ActionExecutionMessage";
|
|
2733
|
+
name;
|
|
2734
|
+
arguments;
|
|
2735
|
+
scope;
|
|
2736
|
+
};
|
|
2737
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2738
|
+
var ResultMessage = class extends Message {
|
|
2739
|
+
type = "ResultMessage";
|
|
2740
|
+
actionExecutionId;
|
|
2741
|
+
actionName;
|
|
2742
|
+
result;
|
|
2743
|
+
};
|
|
2744
|
+
__name(ResultMessage, "ResultMessage");
|
|
2745
|
+
var AgentStateMessage = class extends Message {
|
|
2746
|
+
type = "AgentStateMessage";
|
|
2747
|
+
threadId;
|
|
2748
|
+
agentName;
|
|
2749
|
+
nodeName;
|
|
2750
|
+
runId;
|
|
2751
|
+
active;
|
|
2752
|
+
role;
|
|
2753
|
+
state;
|
|
2754
|
+
running;
|
|
2755
|
+
};
|
|
2756
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2757
|
+
|
|
2947
2758
|
// src/service-adapters/conversion.ts
|
|
2948
|
-
var
|
|
2759
|
+
var import_class_transformer = require("class-transformer");
|
|
2949
2760
|
function convertGqlInputToMessages(inputMessages) {
|
|
2950
2761
|
const messages = [];
|
|
2951
2762
|
for (const message of inputMessages) {
|
|
2952
2763
|
if (message.textMessage) {
|
|
2953
|
-
messages.push((0,
|
|
2764
|
+
messages.push((0, import_class_transformer.plainToInstance)(TextMessage, {
|
|
2954
2765
|
id: message.id,
|
|
2955
2766
|
createdAt: message.createdAt,
|
|
2956
2767
|
role: message.textMessage.role,
|
|
2957
|
-
content: message.textMessage.content
|
|
2958
|
-
parentMessageId: message.textMessage.parentMessageId
|
|
2768
|
+
content: message.textMessage.content
|
|
2959
2769
|
}));
|
|
2960
2770
|
} else if (message.actionExecutionMessage) {
|
|
2961
|
-
messages.push((0,
|
|
2771
|
+
messages.push((0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2962
2772
|
id: message.id,
|
|
2963
2773
|
createdAt: message.createdAt,
|
|
2964
2774
|
name: message.actionExecutionMessage.name,
|
|
2965
2775
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2966
|
-
|
|
2776
|
+
scope: message.actionExecutionMessage.scope
|
|
2967
2777
|
}));
|
|
2968
2778
|
} else if (message.resultMessage) {
|
|
2969
|
-
messages.push((0,
|
|
2779
|
+
messages.push((0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2970
2780
|
id: message.id,
|
|
2971
2781
|
createdAt: message.createdAt,
|
|
2972
2782
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2974,7 +2784,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2974
2784
|
result: message.resultMessage.result
|
|
2975
2785
|
}));
|
|
2976
2786
|
} else if (message.agentStateMessage) {
|
|
2977
|
-
messages.push((0,
|
|
2787
|
+
messages.push((0, import_class_transformer.plainToInstance)(AgentStateMessage, {
|
|
2978
2788
|
id: message.id,
|
|
2979
2789
|
threadId: message.agentStateMessage.threadId,
|
|
2980
2790
|
createdAt: message.createdAt,
|
|
@@ -3025,7 +2835,7 @@ var CopilotRuntime = class {
|
|
|
3025
2835
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3026
2836
|
name: action.name,
|
|
3027
2837
|
description: action.description,
|
|
3028
|
-
jsonSchema: JSON.stringify((0,
|
|
2838
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
3029
2839
|
}));
|
|
3030
2840
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3031
2841
|
...serverSideActionsInput,
|
|
@@ -3075,8 +2885,8 @@ var CopilotRuntime = class {
|
|
|
3075
2885
|
console.error("Error getting response:", error);
|
|
3076
2886
|
eventSource.sendErrorMessageToChat();
|
|
3077
2887
|
return {
|
|
3078
|
-
threadId: threadId || (0,
|
|
3079
|
-
runId: runId || (0,
|
|
2888
|
+
threadId: threadId || (0, import_shared12.randomId)(),
|
|
2889
|
+
runId: runId || (0, import_shared12.randomId)(),
|
|
3080
2890
|
eventSource,
|
|
3081
2891
|
serverSideActions: [],
|
|
3082
2892
|
actionInputsWithoutAgents: []
|
|
@@ -3096,7 +2906,7 @@ var CopilotRuntime = class {
|
|
|
3096
2906
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
3097
2907
|
name: action.name,
|
|
3098
2908
|
description: action.description,
|
|
3099
|
-
jsonSchema: JSON.stringify((0,
|
|
2909
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
3100
2910
|
}));
|
|
3101
2911
|
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
3102
2912
|
...serverSideActionsInput,
|
|
@@ -3283,7 +3093,6 @@ MessageInput = _ts_decorate2([
|
|
|
3283
3093
|
], MessageInput);
|
|
3284
3094
|
var TextMessageInput = class {
|
|
3285
3095
|
content;
|
|
3286
|
-
parentMessageId;
|
|
3287
3096
|
role;
|
|
3288
3097
|
};
|
|
3289
3098
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3291,12 +3100,6 @@ _ts_decorate2([
|
|
|
3291
3100
|
(0, import_type_graphql3.Field)(() => String),
|
|
3292
3101
|
_ts_metadata2("design:type", String)
|
|
3293
3102
|
], TextMessageInput.prototype, "content", void 0);
|
|
3294
|
-
_ts_decorate2([
|
|
3295
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3296
|
-
nullable: true
|
|
3297
|
-
}),
|
|
3298
|
-
_ts_metadata2("design:type", String)
|
|
3299
|
-
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
3300
3103
|
_ts_decorate2([
|
|
3301
3104
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3302
3105
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3307,7 +3110,6 @@ TextMessageInput = _ts_decorate2([
|
|
|
3307
3110
|
var ActionExecutionMessageInput = class {
|
|
3308
3111
|
name;
|
|
3309
3112
|
arguments;
|
|
3310
|
-
parentMessageId;
|
|
3311
3113
|
scope;
|
|
3312
3114
|
};
|
|
3313
3115
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3320,17 +3122,8 @@ _ts_decorate2([
|
|
|
3320
3122
|
_ts_metadata2("design:type", String)
|
|
3321
3123
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3322
3124
|
_ts_decorate2([
|
|
3323
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3324
|
-
|
|
3325
|
-
}),
|
|
3326
|
-
_ts_metadata2("design:type", String)
|
|
3327
|
-
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3328
|
-
_ts_decorate2([
|
|
3329
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3330
|
-
nullable: true,
|
|
3331
|
-
deprecationReason: "This field will be removed in a future version"
|
|
3332
|
-
}),
|
|
3333
|
-
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
3125
|
+
(0, import_type_graphql3.Field)(() => ActionExecutionScope),
|
|
3126
|
+
_ts_metadata2("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
3334
3127
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3335
3128
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3336
3129
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3338,7 +3131,6 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3338
3131
|
var ResultMessageInput = class {
|
|
3339
3132
|
actionExecutionId;
|
|
3340
3133
|
actionName;
|
|
3341
|
-
parentMessageId;
|
|
3342
3134
|
result;
|
|
3343
3135
|
};
|
|
3344
3136
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3350,12 +3142,6 @@ _ts_decorate2([
|
|
|
3350
3142
|
(0, import_type_graphql3.Field)(() => String),
|
|
3351
3143
|
_ts_metadata2("design:type", String)
|
|
3352
3144
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3353
|
-
_ts_decorate2([
|
|
3354
|
-
(0, import_type_graphql3.Field)(() => String, {
|
|
3355
|
-
nullable: true
|
|
3356
|
-
}),
|
|
3357
|
-
_ts_metadata2("design:type", String)
|
|
3358
|
-
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
3359
3145
|
_ts_decorate2([
|
|
3360
3146
|
(0, import_type_graphql3.Field)(() => String),
|
|
3361
3147
|
_ts_metadata2("design:type", String)
|
|
@@ -3619,6 +3405,7 @@ var ForwardedParametersInput = class {
|
|
|
3619
3405
|
stop;
|
|
3620
3406
|
toolChoice;
|
|
3621
3407
|
toolChoiceFunctionName;
|
|
3408
|
+
temperature;
|
|
3622
3409
|
};
|
|
3623
3410
|
__name(ForwardedParametersInput, "ForwardedParametersInput");
|
|
3624
3411
|
_ts_decorate7([
|
|
@@ -3653,6 +3440,12 @@ _ts_decorate7([
|
|
|
3653
3440
|
}),
|
|
3654
3441
|
_ts_metadata7("design:type", String)
|
|
3655
3442
|
], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
|
|
3443
|
+
_ts_decorate7([
|
|
3444
|
+
(0, import_type_graphql8.Field)(() => Number, {
|
|
3445
|
+
nullable: true
|
|
3446
|
+
}),
|
|
3447
|
+
_ts_metadata7("design:type", Number)
|
|
3448
|
+
], ForwardedParametersInput.prototype, "temperature", void 0);
|
|
3656
3449
|
ForwardedParametersInput = _ts_decorate7([
|
|
3657
3450
|
(0, import_type_graphql8.InputType)()
|
|
3658
3451
|
], ForwardedParametersInput);
|
|
@@ -4078,7 +3871,6 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
4078
3871
|
var TextMessageOutput = class {
|
|
4079
3872
|
role;
|
|
4080
3873
|
content;
|
|
4081
|
-
parentMessageId;
|
|
4082
3874
|
};
|
|
4083
3875
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
4084
3876
|
_ts_decorate13([
|
|
@@ -4091,12 +3883,6 @@ _ts_decorate13([
|
|
|
4091
3883
|
]),
|
|
4092
3884
|
_ts_metadata13("design:type", Array)
|
|
4093
3885
|
], TextMessageOutput.prototype, "content", void 0);
|
|
4094
|
-
_ts_decorate13([
|
|
4095
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
4096
|
-
nullable: true
|
|
4097
|
-
}),
|
|
4098
|
-
_ts_metadata13("design:type", String)
|
|
4099
|
-
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
4100
3886
|
TextMessageOutput = _ts_decorate13([
|
|
4101
3887
|
(0, import_type_graphql14.ObjectType)({
|
|
4102
3888
|
implements: BaseMessageOutput
|
|
@@ -4106,7 +3892,6 @@ var ActionExecutionMessageOutput = class {
|
|
|
4106
3892
|
name;
|
|
4107
3893
|
scope;
|
|
4108
3894
|
arguments;
|
|
4109
|
-
parentMessageId;
|
|
4110
3895
|
};
|
|
4111
3896
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
4112
3897
|
_ts_decorate13([
|
|
@@ -4114,11 +3899,8 @@ _ts_decorate13([
|
|
|
4114
3899
|
_ts_metadata13("design:type", String)
|
|
4115
3900
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
4116
3901
|
_ts_decorate13([
|
|
4117
|
-
(0, import_type_graphql14.Field)(() =>
|
|
4118
|
-
|
|
4119
|
-
deprecationReason: "This field will be removed in a future version"
|
|
4120
|
-
}),
|
|
4121
|
-
_ts_metadata13("design:type", String)
|
|
3902
|
+
(0, import_type_graphql14.Field)(() => ActionExecutionScope),
|
|
3903
|
+
_ts_metadata13("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
4122
3904
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
4123
3905
|
_ts_decorate13([
|
|
4124
3906
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -4126,12 +3908,6 @@ _ts_decorate13([
|
|
|
4126
3908
|
]),
|
|
4127
3909
|
_ts_metadata13("design:type", Array)
|
|
4128
3910
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
4129
|
-
_ts_decorate13([
|
|
4130
|
-
(0, import_type_graphql14.Field)(() => String, {
|
|
4131
|
-
nullable: true
|
|
4132
|
-
}),
|
|
4133
|
-
_ts_metadata13("design:type", String)
|
|
4134
|
-
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
4135
3911
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
4136
3912
|
(0, import_type_graphql14.ObjectType)({
|
|
4137
3913
|
implements: BaseMessageOutput
|
|
@@ -4242,7 +4018,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
4242
4018
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4243
4019
|
var import_graphql_yoga = require("graphql-yoga");
|
|
4244
4020
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
4245
|
-
var
|
|
4021
|
+
var import_class_transformer2 = require("class-transformer");
|
|
4246
4022
|
var import_graphql = require("graphql");
|
|
4247
4023
|
|
|
4248
4024
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -4279,7 +4055,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
4279
4055
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
4280
4056
|
|
|
4281
4057
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4282
|
-
var
|
|
4058
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
4283
4059
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
4284
4060
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4285
4061
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4396,7 +4172,7 @@ var CopilotResolver = class {
|
|
|
4396
4172
|
rejectOutputMessagesPromise = reject;
|
|
4397
4173
|
});
|
|
4398
4174
|
logger2.debug("Processing");
|
|
4399
|
-
const { eventSource, threadId = (0,
|
|
4175
|
+
const { eventSource, threadId = (0, import_shared13.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
4400
4176
|
serviceAdapter,
|
|
4401
4177
|
messages: data.messages,
|
|
4402
4178
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -4440,8 +4216,8 @@ var CopilotResolver = class {
|
|
|
4440
4216
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4441
4217
|
});
|
|
4442
4218
|
outputMessages = [
|
|
4443
|
-
(0,
|
|
4444
|
-
id: (0,
|
|
4219
|
+
(0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4220
|
+
id: (0, import_shared13.randomId)(),
|
|
4445
4221
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4446
4222
|
content: result.reason,
|
|
4447
4223
|
role: MessageRole.assistant
|
|
@@ -4489,15 +4265,12 @@ var CopilotResolver = class {
|
|
|
4489
4265
|
// skip until this message start event
|
|
4490
4266
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4491
4267
|
// take until the message end event
|
|
4492
|
-
(0, import_rxjs4.takeWhile)((e) =>
|
|
4493
|
-
// filter out any other message events or message ids
|
|
4494
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
4268
|
+
(0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
4495
4269
|
);
|
|
4496
4270
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4497
4271
|
const messageId = event.messageId;
|
|
4498
4272
|
pushMessage({
|
|
4499
4273
|
id: messageId,
|
|
4500
|
-
parentMessageId: event.parentMessageId,
|
|
4501
4274
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4502
4275
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4503
4276
|
role: MessageRole.assistant,
|
|
@@ -4510,7 +4283,7 @@ var CopilotResolver = class {
|
|
|
4510
4283
|
reason,
|
|
4511
4284
|
messageId: messageId2
|
|
4512
4285
|
}, "Text streaming interrupted");
|
|
4513
|
-
streamingTextStatus.next((0,
|
|
4286
|
+
streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4514
4287
|
reason
|
|
4515
4288
|
}));
|
|
4516
4289
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4543,7 +4316,7 @@ var CopilotResolver = class {
|
|
|
4543
4316
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4544
4317
|
stopStreamingText();
|
|
4545
4318
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4546
|
-
outputMessages.push((0,
|
|
4319
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4547
4320
|
id: messageId,
|
|
4548
4321
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4549
4322
|
content: textChunks.join(""),
|
|
@@ -4556,20 +4329,14 @@ var CopilotResolver = class {
|
|
|
4556
4329
|
break;
|
|
4557
4330
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4558
4331
|
logger2.debug("Action execution start event received");
|
|
4559
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4560
|
-
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4561
|
-
// take until the action execution end event
|
|
4562
|
-
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4563
|
-
// filter out any other action execution events or action execution ids
|
|
4564
|
-
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4565
|
-
);
|
|
4332
|
+
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs4.skipWhile)((e) => e !== event), (0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
4566
4333
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4567
4334
|
pushMessage({
|
|
4568
4335
|
id: event.actionExecutionId,
|
|
4569
|
-
parentMessageId: event.parentMessageId,
|
|
4570
4336
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4571
4337
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4572
4338
|
name: event.actionName,
|
|
4339
|
+
scope: event.scope,
|
|
4573
4340
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4574
4341
|
logger2.debug("Action execution argument stream created");
|
|
4575
4342
|
const argumentChunks = [];
|
|
@@ -4585,7 +4352,7 @@ var CopilotResolver = class {
|
|
|
4585
4352
|
logger2.error({
|
|
4586
4353
|
err
|
|
4587
4354
|
}, "Error in action execution argument stream");
|
|
4588
|
-
streamingArgumentsStatus.next((0,
|
|
4355
|
+
streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
4589
4356
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4590
4357
|
}));
|
|
4591
4358
|
stopStreamingArguments();
|
|
@@ -4596,10 +4363,11 @@ var CopilotResolver = class {
|
|
|
4596
4363
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4597
4364
|
stopStreamingArguments();
|
|
4598
4365
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4599
|
-
outputMessages.push((0,
|
|
4366
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
4600
4367
|
id: event.actionExecutionId,
|
|
4601
4368
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4602
4369
|
name: event.actionName,
|
|
4370
|
+
scope: event.scope,
|
|
4603
4371
|
arguments: argumentChunks.join("")
|
|
4604
4372
|
}));
|
|
4605
4373
|
}
|
|
@@ -4612,15 +4380,15 @@ var CopilotResolver = class {
|
|
|
4612
4380
|
result: event.result
|
|
4613
4381
|
}, "Action execution result event received");
|
|
4614
4382
|
pushMessage({
|
|
4615
|
-
id:
|
|
4383
|
+
id: (0, import_shared13.randomId)(),
|
|
4616
4384
|
status: new SuccessMessageStatus(),
|
|
4617
4385
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4618
4386
|
actionExecutionId: event.actionExecutionId,
|
|
4619
4387
|
actionName: event.actionName,
|
|
4620
4388
|
result: event.result
|
|
4621
4389
|
});
|
|
4622
|
-
outputMessages.push((0,
|
|
4623
|
-
id:
|
|
4390
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
4391
|
+
id: (0, import_shared13.randomId)(),
|
|
4624
4392
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4625
4393
|
actionExecutionId: event.actionExecutionId,
|
|
4626
4394
|
actionName: event.actionName,
|
|
@@ -4632,7 +4400,7 @@ var CopilotResolver = class {
|
|
|
4632
4400
|
event
|
|
4633
4401
|
}, "Agent message event received");
|
|
4634
4402
|
pushMessage({
|
|
4635
|
-
id: (0,
|
|
4403
|
+
id: (0, import_shared13.randomId)(),
|
|
4636
4404
|
status: new SuccessMessageStatus(),
|
|
4637
4405
|
threadId: event.threadId,
|
|
4638
4406
|
agentName: event.agentName,
|
|
@@ -4644,8 +4412,8 @@ var CopilotResolver = class {
|
|
|
4644
4412
|
role: MessageRole.assistant,
|
|
4645
4413
|
createdAt: /* @__PURE__ */ new Date()
|
|
4646
4414
|
});
|
|
4647
|
-
outputMessages.push((0,
|
|
4648
|
-
id: (0,
|
|
4415
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
4416
|
+
id: (0, import_shared13.randomId)(),
|
|
4649
4417
|
threadId: event.threadId,
|
|
4650
4418
|
agentName: event.agentName,
|
|
4651
4419
|
nodeName: event.nodeName,
|
|
@@ -4936,6 +4704,8 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4936
4704
|
0 && (module.exports = {
|
|
4937
4705
|
AnthropicAdapter,
|
|
4938
4706
|
CopilotRuntime,
|
|
4707
|
+
ExperimentalEmptyAdapter,
|
|
4708
|
+
ExperimentalOllamaAdapter,
|
|
4939
4709
|
GoogleGenerativeAIAdapter,
|
|
4940
4710
|
GroqAdapter,
|
|
4941
4711
|
GuardrailsValidationFailureResponse,
|