@copilotkit/runtime 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -5
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-APVJZO3R.mjs → chunk-7BOO3OFP.mjs} +2 -2
- package/dist/{chunk-OSWF5QDO.mjs → chunk-GSTWFOZF.mjs} +2 -2
- package/dist/{chunk-M74ZTUCC.mjs → chunk-OMAAKIJQ.mjs} +2 -2
- package/dist/{chunk-36AYTJIE.mjs → chunk-PXS4SBRF.mjs} +447 -321
- package/dist/chunk-PXS4SBRF.mjs.map +1 -0
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +824 -473
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +729 -452
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +79 -31
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +79 -31
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +79 -31
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +79 -31
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/logger.ts +4 -0
- package/src/lib/runtime/copilot-runtime.ts +1 -7
- package/src/lib/runtime/remote-action-constructors.ts +64 -58
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +159 -140
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-36AYTJIE.mjs.map +0 -1
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-APVJZO3R.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
- /package/dist/{chunk-OSWF5QDO.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
- /package/dist/{chunk-M74ZTUCC.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.
|
|
47
|
+
version: "1.5.0-coagents-v0-3.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -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,6 +432,8 @@ var OpenAIAdapter = class {
|
|
|
430
432
|
eventSource.stream(async (eventStream$) => {
|
|
431
433
|
var _a, _b;
|
|
432
434
|
let mode = null;
|
|
435
|
+
let currentMessageId;
|
|
436
|
+
let currentToolCallId;
|
|
433
437
|
for await (const chunk of stream) {
|
|
434
438
|
if (chunk.choices.length === 0) {
|
|
435
439
|
continue;
|
|
@@ -438,30 +442,52 @@ var OpenAIAdapter = class {
|
|
|
438
442
|
const content = chunk.choices[0].delta.content;
|
|
439
443
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
440
444
|
mode = null;
|
|
441
|
-
eventStream$.sendTextMessageEnd(
|
|
445
|
+
eventStream$.sendTextMessageEnd({
|
|
446
|
+
messageId: currentMessageId
|
|
447
|
+
});
|
|
442
448
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
443
449
|
mode = null;
|
|
444
|
-
eventStream$.sendActionExecutionEnd(
|
|
450
|
+
eventStream$.sendActionExecutionEnd({
|
|
451
|
+
actionExecutionId: currentToolCallId
|
|
452
|
+
});
|
|
445
453
|
}
|
|
446
454
|
if (mode === null) {
|
|
447
455
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
448
456
|
mode = "function";
|
|
449
|
-
|
|
457
|
+
currentToolCallId = toolCall.id;
|
|
458
|
+
eventStream$.sendActionExecutionStart({
|
|
459
|
+
actionExecutionId: currentToolCallId,
|
|
460
|
+
parentMessageId: chunk.id,
|
|
461
|
+
actionName: toolCall.function.name
|
|
462
|
+
});
|
|
450
463
|
} else if (content) {
|
|
451
464
|
mode = "message";
|
|
452
|
-
|
|
465
|
+
currentMessageId = chunk.id;
|
|
466
|
+
eventStream$.sendTextMessageStart({
|
|
467
|
+
messageId: currentMessageId
|
|
468
|
+
});
|
|
453
469
|
}
|
|
454
470
|
}
|
|
455
471
|
if (mode === "message" && content) {
|
|
456
|
-
eventStream$.sendTextMessageContent(
|
|
472
|
+
eventStream$.sendTextMessageContent({
|
|
473
|
+
messageId: currentMessageId,
|
|
474
|
+
content
|
|
475
|
+
});
|
|
457
476
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
458
|
-
eventStream$.sendActionExecutionArgs(
|
|
477
|
+
eventStream$.sendActionExecutionArgs({
|
|
478
|
+
actionExecutionId: currentToolCallId,
|
|
479
|
+
args: toolCall.function.arguments
|
|
480
|
+
});
|
|
459
481
|
}
|
|
460
482
|
}
|
|
461
483
|
if (mode === "message") {
|
|
462
|
-
eventStream$.sendTextMessageEnd(
|
|
484
|
+
eventStream$.sendTextMessageEnd({
|
|
485
|
+
messageId: currentMessageId
|
|
486
|
+
});
|
|
463
487
|
} else if (mode === "function") {
|
|
464
|
-
eventStream$.sendActionExecutionEnd(
|
|
488
|
+
eventStream$.sendActionExecutionEnd({
|
|
489
|
+
actionExecutionId: currentToolCallId
|
|
490
|
+
});
|
|
465
491
|
}
|
|
466
492
|
eventStream$.complete();
|
|
467
493
|
});
|
|
@@ -529,17 +555,25 @@ function isBaseMessageChunk(message) {
|
|
|
529
555
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
530
556
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
531
557
|
if (actionExecution) {
|
|
532
|
-
eventStream$.sendActionExecutionResult(
|
|
558
|
+
eventStream$.sendActionExecutionResult({
|
|
559
|
+
actionExecutionId: actionExecution.id,
|
|
560
|
+
actionName: actionExecution.name,
|
|
561
|
+
result: "Sending a message"
|
|
562
|
+
});
|
|
533
563
|
}
|
|
534
564
|
}
|
|
535
565
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
536
566
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
537
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
567
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
538
568
|
if (typeof result === "string") {
|
|
539
569
|
if (!actionExecution) {
|
|
540
570
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
541
571
|
} else {
|
|
542
|
-
eventStream$.sendActionExecutionResult(
|
|
572
|
+
eventStream$.sendActionExecutionResult({
|
|
573
|
+
actionExecutionId: actionExecution.id,
|
|
574
|
+
actionName: actionExecution.name,
|
|
575
|
+
result
|
|
576
|
+
});
|
|
543
577
|
}
|
|
544
578
|
} else if (isAIMessage(result)) {
|
|
545
579
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -547,7 +581,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
547
581
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
548
582
|
}
|
|
549
583
|
for (const toolCall of result.tool_calls) {
|
|
550
|
-
eventStream$.sendActionExecution(
|
|
584
|
+
eventStream$.sendActionExecution({
|
|
585
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
586
|
+
actionName: toolCall.name,
|
|
587
|
+
args: JSON.stringify(toolCall.args)
|
|
588
|
+
});
|
|
551
589
|
}
|
|
552
590
|
} else if (isBaseMessageChunk(result)) {
|
|
553
591
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -556,13 +594,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
556
594
|
}
|
|
557
595
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
558
596
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
559
|
-
eventStream$.sendActionExecution(
|
|
597
|
+
eventStream$.sendActionExecution({
|
|
598
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
599
|
+
actionName: toolCall.name,
|
|
600
|
+
args: JSON.stringify(toolCall.args)
|
|
601
|
+
});
|
|
560
602
|
}
|
|
561
603
|
}
|
|
562
604
|
} else if (result && "getReader" in result) {
|
|
563
605
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
564
606
|
let reader = result.getReader();
|
|
565
607
|
let mode = null;
|
|
608
|
+
let currentMessageId;
|
|
566
609
|
const toolCallDetails = {
|
|
567
610
|
name: null,
|
|
568
611
|
id: null,
|
|
@@ -576,9 +619,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
576
619
|
let toolCallId = void 0;
|
|
577
620
|
let toolCallArgs = void 0;
|
|
578
621
|
let hasToolCall = false;
|
|
579
|
-
let content =
|
|
622
|
+
let content = "";
|
|
623
|
+
if (value && value.content) {
|
|
624
|
+
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
625
|
+
}
|
|
580
626
|
if (isAIMessageChunk(value)) {
|
|
581
|
-
let chunk = (
|
|
627
|
+
let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
|
|
582
628
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
583
629
|
hasToolCall = chunk != void 0;
|
|
584
630
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -593,18 +639,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
593
639
|
toolCallName = toolCallDetails.name;
|
|
594
640
|
toolCallId = toolCallDetails.id;
|
|
595
641
|
} else if (isBaseMessageChunk(value)) {
|
|
596
|
-
let chunk = (
|
|
597
|
-
toolCallName = (
|
|
642
|
+
let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
|
|
643
|
+
toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
|
|
598
644
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
599
|
-
toolCallArgs = (
|
|
645
|
+
toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
|
|
600
646
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
601
647
|
}
|
|
602
648
|
if (mode === "message" && (toolCallId || done)) {
|
|
603
649
|
mode = null;
|
|
604
|
-
eventStream$.sendTextMessageEnd(
|
|
650
|
+
eventStream$.sendTextMessageEnd({
|
|
651
|
+
messageId: currentMessageId
|
|
652
|
+
});
|
|
605
653
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
606
654
|
mode = null;
|
|
607
|
-
eventStream$.sendActionExecutionEnd(
|
|
655
|
+
eventStream$.sendActionExecutionEnd({
|
|
656
|
+
actionExecutionId: toolCallId
|
|
657
|
+
});
|
|
608
658
|
}
|
|
609
659
|
if (done) {
|
|
610
660
|
break;
|
|
@@ -612,21 +662,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
612
662
|
if (mode === null) {
|
|
613
663
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
614
664
|
mode = "function";
|
|
615
|
-
eventStream$.sendActionExecutionStart(
|
|
665
|
+
eventStream$.sendActionExecutionStart({
|
|
666
|
+
actionExecutionId: toolCallId,
|
|
667
|
+
actionName: toolCallName,
|
|
668
|
+
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
669
|
+
});
|
|
616
670
|
} else if (content) {
|
|
617
671
|
mode = "message";
|
|
618
|
-
|
|
672
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared2.randomId)();
|
|
673
|
+
eventStream$.sendTextMessageStart({
|
|
674
|
+
messageId: currentMessageId
|
|
675
|
+
});
|
|
619
676
|
}
|
|
620
677
|
}
|
|
621
678
|
if (mode === "message" && content) {
|
|
622
|
-
eventStream$.sendTextMessageContent(
|
|
679
|
+
eventStream$.sendTextMessageContent({
|
|
680
|
+
messageId: currentMessageId,
|
|
681
|
+
content
|
|
682
|
+
});
|
|
623
683
|
} else if (mode === "function" && toolCallArgs) {
|
|
624
684
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
625
|
-
eventStream$.sendActionExecutionEnd(
|
|
626
|
-
|
|
685
|
+
eventStream$.sendActionExecutionEnd({
|
|
686
|
+
actionExecutionId: toolCallId
|
|
687
|
+
});
|
|
688
|
+
eventStream$.sendActionExecutionStart({
|
|
689
|
+
actionExecutionId: toolCallId,
|
|
690
|
+
actionName: toolCallName,
|
|
691
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
692
|
+
});
|
|
627
693
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
628
694
|
}
|
|
629
|
-
eventStream$.sendActionExecutionArgs(
|
|
695
|
+
eventStream$.sendActionExecutionArgs({
|
|
696
|
+
actionExecutionId: toolCallId,
|
|
697
|
+
args: toolCallArgs
|
|
698
|
+
});
|
|
630
699
|
}
|
|
631
700
|
} catch (error) {
|
|
632
701
|
console.error("Error reading from stream", error);
|
|
@@ -634,7 +703,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
634
703
|
}
|
|
635
704
|
}
|
|
636
705
|
} else if (actionExecution) {
|
|
637
|
-
eventStream$.sendActionExecutionResult(
|
|
706
|
+
eventStream$.sendActionExecutionResult({
|
|
707
|
+
actionExecutionId: actionExecution.id,
|
|
708
|
+
actionName: actionExecution.name,
|
|
709
|
+
result: encodeResult(result)
|
|
710
|
+
});
|
|
638
711
|
} else {
|
|
639
712
|
throw new Error("Invalid return type from LangChain function.");
|
|
640
713
|
}
|
|
@@ -814,21 +887,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
814
887
|
eventSource.stream(async (eventStream$) => {
|
|
815
888
|
var _a, _b, _c, _d, _e, _f;
|
|
816
889
|
let inFunctionCall = false;
|
|
890
|
+
let currentMessageId;
|
|
891
|
+
let currentToolCallId;
|
|
817
892
|
for await (const chunk of stream) {
|
|
818
893
|
switch (chunk.event) {
|
|
819
894
|
case "thread.message.created":
|
|
820
895
|
if (inFunctionCall) {
|
|
821
|
-
eventStream$.sendActionExecutionEnd(
|
|
896
|
+
eventStream$.sendActionExecutionEnd({
|
|
897
|
+
actionExecutionId: currentToolCallId
|
|
898
|
+
});
|
|
822
899
|
}
|
|
823
|
-
|
|
900
|
+
currentMessageId = chunk.data.id;
|
|
901
|
+
eventStream$.sendTextMessageStart({
|
|
902
|
+
messageId: currentMessageId
|
|
903
|
+
});
|
|
824
904
|
break;
|
|
825
905
|
case "thread.message.delta":
|
|
826
906
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
827
|
-
eventStream$.sendTextMessageContent(
|
|
907
|
+
eventStream$.sendTextMessageContent({
|
|
908
|
+
messageId: currentMessageId,
|
|
909
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
910
|
+
});
|
|
828
911
|
}
|
|
829
912
|
break;
|
|
830
913
|
case "thread.message.completed":
|
|
831
|
-
eventStream$.sendTextMessageEnd(
|
|
914
|
+
eventStream$.sendTextMessageEnd({
|
|
915
|
+
messageId: currentMessageId
|
|
916
|
+
});
|
|
832
917
|
break;
|
|
833
918
|
case "thread.run.step.delta":
|
|
834
919
|
let toolCallId;
|
|
@@ -841,18 +926,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
841
926
|
}
|
|
842
927
|
if (toolCallName && toolCallId) {
|
|
843
928
|
if (inFunctionCall) {
|
|
844
|
-
eventStream$.sendActionExecutionEnd(
|
|
929
|
+
eventStream$.sendActionExecutionEnd({
|
|
930
|
+
actionExecutionId: currentToolCallId
|
|
931
|
+
});
|
|
845
932
|
}
|
|
846
933
|
inFunctionCall = true;
|
|
847
|
-
|
|
934
|
+
currentToolCallId = toolCallId;
|
|
935
|
+
eventStream$.sendActionExecutionStart({
|
|
936
|
+
actionExecutionId: currentToolCallId,
|
|
937
|
+
parentMessageId: chunk.data.id,
|
|
938
|
+
actionName: toolCallName
|
|
939
|
+
});
|
|
848
940
|
} else if (toolCallArgs) {
|
|
849
|
-
eventStream$.sendActionExecutionArgs(
|
|
941
|
+
eventStream$.sendActionExecutionArgs({
|
|
942
|
+
actionExecutionId: currentToolCallId,
|
|
943
|
+
args: toolCallArgs
|
|
944
|
+
});
|
|
850
945
|
}
|
|
851
946
|
break;
|
|
852
947
|
}
|
|
853
948
|
}
|
|
854
949
|
if (inFunctionCall) {
|
|
855
|
-
eventStream$.sendActionExecutionEnd(
|
|
950
|
+
eventStream$.sendActionExecutionEnd({
|
|
951
|
+
actionExecutionId: currentToolCallId
|
|
952
|
+
});
|
|
856
953
|
}
|
|
857
954
|
eventStream$.complete();
|
|
858
955
|
});
|
|
@@ -905,46 +1002,77 @@ var UnifyAdapter = class {
|
|
|
905
1002
|
}
|
|
906
1003
|
});
|
|
907
1004
|
let model = null;
|
|
1005
|
+
let currentMessageId;
|
|
1006
|
+
let currentToolCallId;
|
|
908
1007
|
request.eventSource.stream(async (eventStream$) => {
|
|
909
1008
|
var _a, _b;
|
|
910
1009
|
let mode = null;
|
|
911
1010
|
for await (const chunk of stream) {
|
|
912
1011
|
if (this.start) {
|
|
913
1012
|
model = chunk.model;
|
|
914
|
-
|
|
915
|
-
eventStream$.
|
|
916
|
-
|
|
917
|
-
|
|
1013
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
1014
|
+
eventStream$.sendTextMessageStart({
|
|
1015
|
+
messageId: currentMessageId
|
|
1016
|
+
});
|
|
1017
|
+
eventStream$.sendTextMessageContent({
|
|
1018
|
+
messageId: currentMessageId,
|
|
1019
|
+
content: `Model used: ${model}
|
|
1020
|
+
`
|
|
1021
|
+
});
|
|
1022
|
+
eventStream$.sendTextMessageEnd({
|
|
1023
|
+
messageId: currentMessageId
|
|
1024
|
+
});
|
|
918
1025
|
this.start = false;
|
|
919
1026
|
}
|
|
920
1027
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
921
1028
|
const content = chunk.choices[0].delta.content;
|
|
922
1029
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
923
1030
|
mode = null;
|
|
924
|
-
eventStream$.sendTextMessageEnd(
|
|
1031
|
+
eventStream$.sendTextMessageEnd({
|
|
1032
|
+
messageId: currentMessageId
|
|
1033
|
+
});
|
|
925
1034
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
926
1035
|
mode = null;
|
|
927
|
-
eventStream$.sendActionExecutionEnd(
|
|
1036
|
+
eventStream$.sendActionExecutionEnd({
|
|
1037
|
+
actionExecutionId: currentToolCallId
|
|
1038
|
+
});
|
|
928
1039
|
}
|
|
929
1040
|
if (mode === null) {
|
|
930
1041
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
931
1042
|
mode = "function";
|
|
932
|
-
|
|
1043
|
+
currentToolCallId = toolCall.id;
|
|
1044
|
+
eventStream$.sendActionExecutionStart({
|
|
1045
|
+
actionExecutionId: currentToolCallId,
|
|
1046
|
+
actionName: toolCall.function.name
|
|
1047
|
+
});
|
|
933
1048
|
} else if (content) {
|
|
934
1049
|
mode = "message";
|
|
935
|
-
|
|
1050
|
+
currentMessageId = chunk.id;
|
|
1051
|
+
eventStream$.sendTextMessageStart({
|
|
1052
|
+
messageId: currentMessageId
|
|
1053
|
+
});
|
|
936
1054
|
}
|
|
937
1055
|
}
|
|
938
1056
|
if (mode === "message" && content) {
|
|
939
|
-
eventStream$.sendTextMessageContent(
|
|
1057
|
+
eventStream$.sendTextMessageContent({
|
|
1058
|
+
messageId: currentMessageId,
|
|
1059
|
+
content
|
|
1060
|
+
});
|
|
940
1061
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
941
|
-
eventStream$.sendActionExecutionArgs(
|
|
1062
|
+
eventStream$.sendActionExecutionArgs({
|
|
1063
|
+
actionExecutionId: currentToolCallId,
|
|
1064
|
+
args: toolCall.function.arguments
|
|
1065
|
+
});
|
|
942
1066
|
}
|
|
943
1067
|
}
|
|
944
1068
|
if (mode === "message") {
|
|
945
|
-
eventStream$.sendTextMessageEnd(
|
|
1069
|
+
eventStream$.sendTextMessageEnd({
|
|
1070
|
+
messageId: currentMessageId
|
|
1071
|
+
});
|
|
946
1072
|
} else if (mode === "function") {
|
|
947
|
-
eventStream$.sendActionExecutionEnd(
|
|
1073
|
+
eventStream$.sendActionExecutionEnd({
|
|
1074
|
+
actionExecutionId: currentToolCallId
|
|
1075
|
+
});
|
|
948
1076
|
}
|
|
949
1077
|
eventStream$.complete();
|
|
950
1078
|
});
|
|
@@ -1010,35 +1138,59 @@ var GroqAdapter = class {
|
|
|
1010
1138
|
eventSource.stream(async (eventStream$) => {
|
|
1011
1139
|
var _a, _b;
|
|
1012
1140
|
let mode = null;
|
|
1141
|
+
let currentMessageId;
|
|
1142
|
+
let currentToolCallId;
|
|
1013
1143
|
for await (const chunk of stream) {
|
|
1014
1144
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1015
1145
|
const content = chunk.choices[0].delta.content;
|
|
1016
1146
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1017
1147
|
mode = null;
|
|
1018
|
-
eventStream$.sendTextMessageEnd(
|
|
1148
|
+
eventStream$.sendTextMessageEnd({
|
|
1149
|
+
messageId: currentMessageId
|
|
1150
|
+
});
|
|
1019
1151
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1020
1152
|
mode = null;
|
|
1021
|
-
eventStream$.sendActionExecutionEnd(
|
|
1153
|
+
eventStream$.sendActionExecutionEnd({
|
|
1154
|
+
actionExecutionId: currentToolCallId
|
|
1155
|
+
});
|
|
1022
1156
|
}
|
|
1023
1157
|
if (mode === null) {
|
|
1024
1158
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1025
1159
|
mode = "function";
|
|
1026
|
-
|
|
1160
|
+
currentToolCallId = toolCall.id;
|
|
1161
|
+
eventStream$.sendActionExecutionStart({
|
|
1162
|
+
actionExecutionId: currentToolCallId,
|
|
1163
|
+
actionName: toolCall.function.name,
|
|
1164
|
+
parentMessageId: chunk.id
|
|
1165
|
+
});
|
|
1027
1166
|
} else if (content) {
|
|
1028
1167
|
mode = "message";
|
|
1029
|
-
|
|
1168
|
+
currentMessageId = chunk.id;
|
|
1169
|
+
eventStream$.sendTextMessageStart({
|
|
1170
|
+
messageId: currentMessageId
|
|
1171
|
+
});
|
|
1030
1172
|
}
|
|
1031
1173
|
}
|
|
1032
1174
|
if (mode === "message" && content) {
|
|
1033
|
-
eventStream$.sendTextMessageContent(
|
|
1175
|
+
eventStream$.sendTextMessageContent({
|
|
1176
|
+
messageId: currentMessageId,
|
|
1177
|
+
content
|
|
1178
|
+
});
|
|
1034
1179
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1035
|
-
eventStream$.sendActionExecutionArgs(
|
|
1180
|
+
eventStream$.sendActionExecutionArgs({
|
|
1181
|
+
actionExecutionId: currentToolCallId,
|
|
1182
|
+
args: toolCall.function.arguments
|
|
1183
|
+
});
|
|
1036
1184
|
}
|
|
1037
1185
|
}
|
|
1038
1186
|
if (mode === "message") {
|
|
1039
|
-
eventStream$.sendTextMessageEnd(
|
|
1187
|
+
eventStream$.sendTextMessageEnd({
|
|
1188
|
+
messageId: currentMessageId
|
|
1189
|
+
});
|
|
1040
1190
|
} else if (mode === "function") {
|
|
1041
|
-
eventStream$.sendActionExecutionEnd(
|
|
1191
|
+
eventStream$.sendActionExecutionEnd({
|
|
1192
|
+
actionExecutionId: currentToolCallId
|
|
1193
|
+
});
|
|
1042
1194
|
}
|
|
1043
1195
|
eventStream$.complete();
|
|
1044
1196
|
});
|
|
@@ -1246,7 +1398,11 @@ var AnthropicAdapter = class {
|
|
|
1246
1398
|
mode = "message";
|
|
1247
1399
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1248
1400
|
currentToolCallId = chunk.content_block.id;
|
|
1249
|
-
eventStream$.sendActionExecutionStart(
|
|
1401
|
+
eventStream$.sendActionExecutionStart({
|
|
1402
|
+
actionExecutionId: currentToolCallId,
|
|
1403
|
+
actionName: chunk.content_block.name,
|
|
1404
|
+
parentMessageId: currentMessageId
|
|
1405
|
+
});
|
|
1250
1406
|
mode = "function";
|
|
1251
1407
|
}
|
|
1252
1408
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1254,21 +1410,33 @@ var AnthropicAdapter = class {
|
|
|
1254
1410
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1255
1411
|
if (text.length > 0) {
|
|
1256
1412
|
if (!didOutputText) {
|
|
1257
|
-
eventStream$.sendTextMessageStart(
|
|
1413
|
+
eventStream$.sendTextMessageStart({
|
|
1414
|
+
messageId: currentMessageId
|
|
1415
|
+
});
|
|
1258
1416
|
didOutputText = true;
|
|
1259
1417
|
}
|
|
1260
|
-
eventStream$.sendTextMessageContent(
|
|
1418
|
+
eventStream$.sendTextMessageContent({
|
|
1419
|
+
messageId: currentMessageId,
|
|
1420
|
+
content: text
|
|
1421
|
+
});
|
|
1261
1422
|
}
|
|
1262
1423
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1263
|
-
eventStream$.sendActionExecutionArgs(
|
|
1424
|
+
eventStream$.sendActionExecutionArgs({
|
|
1425
|
+
actionExecutionId: currentToolCallId,
|
|
1426
|
+
args: chunk.delta.partial_json
|
|
1427
|
+
});
|
|
1264
1428
|
}
|
|
1265
1429
|
} else if (chunk.type === "content_block_stop") {
|
|
1266
1430
|
if (mode === "message") {
|
|
1267
1431
|
if (didOutputText) {
|
|
1268
|
-
eventStream$.sendTextMessageEnd(
|
|
1432
|
+
eventStream$.sendTextMessageEnd({
|
|
1433
|
+
messageId: currentMessageId
|
|
1434
|
+
});
|
|
1269
1435
|
}
|
|
1270
1436
|
} else if (mode === "function") {
|
|
1271
|
-
eventStream$.sendActionExecutionEnd(
|
|
1437
|
+
eventStream$.sendActionExecutionEnd({
|
|
1438
|
+
actionExecutionId: currentToolCallId
|
|
1439
|
+
});
|
|
1272
1440
|
}
|
|
1273
1441
|
}
|
|
1274
1442
|
}
|
|
@@ -1313,12 +1481,66 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1313
1481
|
}
|
|
1314
1482
|
}, "FilterThinkingTextBuffer");
|
|
1315
1483
|
|
|
1484
|
+
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1485
|
+
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1486
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1487
|
+
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1488
|
+
var ExperimentalOllamaAdapter = class {
|
|
1489
|
+
model;
|
|
1490
|
+
constructor(options) {
|
|
1491
|
+
if (options == null ? void 0 : options.model) {
|
|
1492
|
+
this.model = options.model;
|
|
1493
|
+
} else {
|
|
1494
|
+
this.model = DEFAULT_MODEL4;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
async process(request) {
|
|
1498
|
+
const { messages, actions, eventSource } = request;
|
|
1499
|
+
const ollama = new import_ollama.Ollama({
|
|
1500
|
+
model: this.model
|
|
1501
|
+
});
|
|
1502
|
+
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1503
|
+
const _stream = await ollama.stream(contents);
|
|
1504
|
+
eventSource.stream(async (eventStream$) => {
|
|
1505
|
+
const currentMessageId = (0, import_shared7.randomId)();
|
|
1506
|
+
eventStream$.sendTextMessageStart({
|
|
1507
|
+
messageId: currentMessageId
|
|
1508
|
+
});
|
|
1509
|
+
for await (const chunkText of _stream) {
|
|
1510
|
+
eventStream$.sendTextMessageContent({
|
|
1511
|
+
messageId: currentMessageId,
|
|
1512
|
+
content: chunkText
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
eventStream$.sendTextMessageEnd({
|
|
1516
|
+
messageId: currentMessageId
|
|
1517
|
+
});
|
|
1518
|
+
eventStream$.complete();
|
|
1519
|
+
});
|
|
1520
|
+
return {
|
|
1521
|
+
threadId: request.threadId || (0, import_shared7.randomId)()
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1526
|
+
|
|
1527
|
+
// src/service-adapters/experimental/empty/empty-adapter.ts
|
|
1528
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1529
|
+
var ExperimentalEmptyAdapter = class {
|
|
1530
|
+
async process(request) {
|
|
1531
|
+
return {
|
|
1532
|
+
threadId: request.threadId || (0, import_shared8.randomId)()
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
__name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
|
|
1537
|
+
|
|
1316
1538
|
// src/service-adapters/events.ts
|
|
1317
|
-
var
|
|
1539
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1318
1540
|
var import_rxjs2 = require("rxjs");
|
|
1319
1541
|
|
|
1320
1542
|
// src/lib/telemetry-client.ts
|
|
1321
|
-
var
|
|
1543
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1322
1544
|
|
|
1323
1545
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1324
1546
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1351,7 +1573,7 @@ var CustomEventNames;
|
|
|
1351
1573
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1352
1574
|
|
|
1353
1575
|
// src/agents/langgraph/event-source.ts
|
|
1354
|
-
var
|
|
1576
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1355
1577
|
var RemoteLangGraphEventSource = class {
|
|
1356
1578
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1357
1579
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1363,163 +1585,167 @@ var RemoteLangGraphEventSource = class {
|
|
|
1363
1585
|
}
|
|
1364
1586
|
return shouldEmitToolCalls === toolCallName;
|
|
1365
1587
|
}
|
|
1588
|
+
getCurrentContent(event) {
|
|
1589
|
+
var _a, _b, _c, _d, _e;
|
|
1590
|
+
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);
|
|
1591
|
+
if (!content) {
|
|
1592
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1593
|
+
for (const chunk of toolCallChunks) {
|
|
1594
|
+
if (chunk.args) {
|
|
1595
|
+
return chunk.args;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
if (typeof content === "string") {
|
|
1600
|
+
return content;
|
|
1601
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1602
|
+
return content[0].text;
|
|
1603
|
+
}
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1606
|
+
getCurrentMessageId(event) {
|
|
1607
|
+
var _a, _b, _c, _d, _e;
|
|
1608
|
+
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);
|
|
1609
|
+
}
|
|
1610
|
+
getCurrentToolCallChunks(event) {
|
|
1611
|
+
var _a, _b, _c, _d, _e;
|
|
1612
|
+
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);
|
|
1613
|
+
}
|
|
1614
|
+
getResponseMetadata(event) {
|
|
1615
|
+
var _a, _b, _c, _d, _e;
|
|
1616
|
+
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);
|
|
1617
|
+
}
|
|
1366
1618
|
processLangGraphEvents() {
|
|
1367
1619
|
let lastEventWithState = null;
|
|
1368
1620
|
return this.eventStream$.pipe((0, import_rxjs.scan)((acc, event) => {
|
|
1369
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1370
1621
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1386
|
-
acc.toolCallMessageId = toolCallMessageId;
|
|
1387
|
-
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1388
|
-
acc.toolCallName = toolCallChunks[0].name;
|
|
1389
|
-
}
|
|
1390
|
-
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1391
|
-
acc.toolCallId = toolCallChunks[0].id;
|
|
1392
|
-
}
|
|
1393
|
-
acc.prevMessageId = acc.messageId;
|
|
1394
|
-
acc.messageId = toolCallMessageId;
|
|
1395
|
-
} else if (acc.content && acc.content != "") {
|
|
1396
|
-
acc.prevMessageId = acc.messageId;
|
|
1397
|
-
acc.messageId = toolCallMessageId;
|
|
1398
|
-
} else {
|
|
1399
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1400
|
-
acc.prevMessageId = acc.messageId;
|
|
1401
|
-
}
|
|
1402
|
-
} else {
|
|
1403
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1404
|
-
acc.toolCallMessageId = null;
|
|
1405
|
-
acc.prevMessageId = acc.messageId;
|
|
1406
|
-
acc.messageId = null;
|
|
1407
|
-
acc.toolCallName = null;
|
|
1622
|
+
const prevMessageId = acc.lastMessageId;
|
|
1623
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
1624
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1625
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1626
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
1627
|
+
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1628
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1629
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
1630
|
+
acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1631
|
+
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1632
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1633
|
+
name: acc.lastToolCallName,
|
|
1634
|
+
id: acc.lastToolCallId
|
|
1635
|
+
});
|
|
1408
1636
|
}
|
|
1409
1637
|
acc.event = event;
|
|
1410
1638
|
lastEventWithState = acc;
|
|
1411
1639
|
return acc;
|
|
1412
1640
|
}, {
|
|
1413
1641
|
event: null,
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1642
|
+
isMessageStart: false,
|
|
1643
|
+
isMessageEnd: false,
|
|
1644
|
+
isToolCallStart: false,
|
|
1645
|
+
isToolCallEnd: false,
|
|
1646
|
+
isToolCall: false,
|
|
1647
|
+
lastMessageId: null,
|
|
1648
|
+
lastToolCallId: null,
|
|
1649
|
+
lastToolCallName: null,
|
|
1650
|
+
currentContent: null
|
|
1651
|
+
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1423
1652
|
const events = [];
|
|
1424
1653
|
let shouldEmitMessages = true;
|
|
1425
|
-
let shouldEmitToolCalls =
|
|
1426
|
-
if (
|
|
1427
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1428
|
-
shouldEmitToolCalls =
|
|
1654
|
+
let shouldEmitToolCalls = true;
|
|
1655
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1656
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
1657
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
1429
1658
|
}
|
|
1430
|
-
if ("copilotkit:emit-messages" in (
|
|
1431
|
-
shouldEmitMessages =
|
|
1659
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
1660
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
1432
1661
|
}
|
|
1433
1662
|
}
|
|
1434
|
-
|
|
1663
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1664
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1435
1665
|
events.push({
|
|
1436
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1666
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1667
|
+
actionExecutionId: acc.lastToolCallId
|
|
1437
1668
|
});
|
|
1438
1669
|
}
|
|
1439
|
-
if (
|
|
1670
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1440
1671
|
events.push({
|
|
1441
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1672
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1673
|
+
messageId: acc.lastMessageId
|
|
1442
1674
|
});
|
|
1443
1675
|
}
|
|
1444
|
-
switch (
|
|
1676
|
+
switch (acc.event.event) {
|
|
1445
1677
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1446
|
-
if (
|
|
1678
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1447
1679
|
events.push({
|
|
1448
1680
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1449
|
-
messageId:
|
|
1681
|
+
messageId: acc.event.data.message_id
|
|
1450
1682
|
});
|
|
1451
1683
|
events.push({
|
|
1452
1684
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1453
|
-
|
|
1685
|
+
messageId: acc.event.data.message_id,
|
|
1686
|
+
content: acc.event.data.message
|
|
1454
1687
|
});
|
|
1455
1688
|
events.push({
|
|
1456
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1689
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1690
|
+
messageId: acc.event.data.message_id
|
|
1457
1691
|
});
|
|
1458
|
-
} else if (
|
|
1692
|
+
} else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1459
1693
|
events.push({
|
|
1460
1694
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1461
|
-
actionExecutionId:
|
|
1462
|
-
actionName:
|
|
1695
|
+
actionExecutionId: acc.event.data.id,
|
|
1696
|
+
actionName: acc.event.data.name,
|
|
1697
|
+
parentMessageId: acc.event.data.id
|
|
1463
1698
|
});
|
|
1464
1699
|
events.push({
|
|
1465
1700
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1466
|
-
|
|
1701
|
+
actionExecutionId: acc.event.data.id,
|
|
1702
|
+
args: JSON.stringify(acc.event.data.args)
|
|
1467
1703
|
});
|
|
1468
1704
|
events.push({
|
|
1469
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1705
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1706
|
+
actionExecutionId: acc.event.data.id
|
|
1470
1707
|
});
|
|
1471
1708
|
}
|
|
1472
1709
|
break;
|
|
1473
1710
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1474
1711
|
events.push({
|
|
1475
1712
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1476
|
-
threadId:
|
|
1477
|
-
role:
|
|
1478
|
-
agentName:
|
|
1479
|
-
nodeName:
|
|
1480
|
-
runId:
|
|
1481
|
-
active:
|
|
1482
|
-
state: JSON.stringify(
|
|
1483
|
-
running:
|
|
1713
|
+
threadId: acc.event.thread_id,
|
|
1714
|
+
role: acc.event.role,
|
|
1715
|
+
agentName: acc.event.agent_name,
|
|
1716
|
+
nodeName: acc.event.node_name,
|
|
1717
|
+
runId: acc.event.run_id,
|
|
1718
|
+
active: acc.event.active,
|
|
1719
|
+
state: JSON.stringify(acc.event.state),
|
|
1720
|
+
running: acc.event.running
|
|
1484
1721
|
});
|
|
1485
1722
|
break;
|
|
1486
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
1487
|
-
break;
|
|
1488
1723
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1489
|
-
if (
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
type: RuntimeEventTypes.TextMessageStart,
|
|
1502
|
-
messageId: eventWithState.messageId
|
|
1503
|
-
});
|
|
1504
|
-
}
|
|
1724
|
+
if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1725
|
+
events.push({
|
|
1726
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1727
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1728
|
+
actionName: acc.lastToolCallName,
|
|
1729
|
+
parentMessageId: acc.lastMessageId
|
|
1730
|
+
});
|
|
1731
|
+
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1732
|
+
events.push({
|
|
1733
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1734
|
+
messageId: acc.lastMessageId
|
|
1735
|
+
});
|
|
1505
1736
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
events.push({
|
|
1519
|
-
type: RuntimeEventTypes.TextMessageContent,
|
|
1520
|
-
content
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1737
|
+
if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1738
|
+
events.push({
|
|
1739
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1740
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1741
|
+
args: acc.currentContent
|
|
1742
|
+
});
|
|
1743
|
+
} else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
1744
|
+
events.push({
|
|
1745
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1746
|
+
messageId: acc.lastMessageId,
|
|
1747
|
+
content: acc.currentContent
|
|
1748
|
+
});
|
|
1523
1749
|
}
|
|
1524
1750
|
break;
|
|
1525
1751
|
}
|
|
@@ -1527,27 +1753,31 @@ var RemoteLangGraphEventSource = class {
|
|
|
1527
1753
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1528
1754
|
console.error(error);
|
|
1529
1755
|
const events = [];
|
|
1530
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1756
|
+
if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
|
|
1531
1757
|
events.push({
|
|
1532
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1758
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1759
|
+
messageId: lastEventWithState.lastMessageId
|
|
1533
1760
|
});
|
|
1534
1761
|
}
|
|
1535
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1762
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
|
|
1536
1763
|
events.push({
|
|
1537
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1764
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1765
|
+
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1538
1766
|
});
|
|
1539
1767
|
}
|
|
1540
|
-
const messageId = (0,
|
|
1768
|
+
const messageId = (0, import_shared9.randomId)();
|
|
1541
1769
|
events.push({
|
|
1542
1770
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1543
1771
|
messageId
|
|
1544
1772
|
});
|
|
1545
1773
|
events.push({
|
|
1546
1774
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1775
|
+
messageId,
|
|
1547
1776
|
content: "\u274C An error occurred. Please try again."
|
|
1548
1777
|
});
|
|
1549
1778
|
events.push({
|
|
1550
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1779
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1780
|
+
messageId
|
|
1551
1781
|
});
|
|
1552
1782
|
return events;
|
|
1553
1783
|
}));
|
|
@@ -1569,12 +1799,6 @@ var MessageRole;
|
|
|
1569
1799
|
MessageRole2["system"] = "system";
|
|
1570
1800
|
MessageRole2["tool"] = "tool";
|
|
1571
1801
|
})(MessageRole || (MessageRole = {}));
|
|
1572
|
-
var ActionExecutionScope;
|
|
1573
|
-
(function(ActionExecutionScope2) {
|
|
1574
|
-
ActionExecutionScope2["server"] = "server";
|
|
1575
|
-
ActionExecutionScope2["client"] = "client";
|
|
1576
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1577
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1578
1802
|
var CopilotRequestType;
|
|
1579
1803
|
(function(CopilotRequestType2) {
|
|
1580
1804
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1593,10 +1817,6 @@ var ActionInputAvailability;
|
|
|
1593
1817
|
name: "MessageRole",
|
|
1594
1818
|
description: "The role of the message"
|
|
1595
1819
|
});
|
|
1596
|
-
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1597
|
-
name: "ActionExecutionScope",
|
|
1598
|
-
description: "The scope of the action"
|
|
1599
|
-
});
|
|
1600
1820
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1601
1821
|
name: "CopilotRequestType",
|
|
1602
1822
|
description: "The type of Copilot request"
|
|
@@ -1653,7 +1873,7 @@ async function streamEvents(controller, args) {
|
|
|
1653
1873
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1654
1874
|
let formattedMessages = [];
|
|
1655
1875
|
try {
|
|
1656
|
-
formattedMessages =
|
|
1876
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1657
1877
|
} catch (e) {
|
|
1658
1878
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1659
1879
|
}
|
|
@@ -1806,7 +2026,8 @@ async function streamEvents(controller, args) {
|
|
|
1806
2026
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1807
2027
|
state: state.values,
|
|
1808
2028
|
running: !shouldExit,
|
|
1809
|
-
active: false
|
|
2029
|
+
active: false,
|
|
2030
|
+
includeMessages: true
|
|
1810
2031
|
}));
|
|
1811
2032
|
return Promise.resolve();
|
|
1812
2033
|
} catch (e) {
|
|
@@ -1819,13 +2040,20 @@ async function streamEvents(controller, args) {
|
|
|
1819
2040
|
}
|
|
1820
2041
|
}
|
|
1821
2042
|
__name(streamEvents, "streamEvents");
|
|
1822
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
2043
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
2044
|
+
if (!includeMessages) {
|
|
2045
|
+
state = Object.keys(state).reduce((acc, key) => {
|
|
2046
|
+
if (key !== "messages") {
|
|
2047
|
+
acc[key] = state[key];
|
|
2048
|
+
}
|
|
2049
|
+
return acc;
|
|
2050
|
+
}, {});
|
|
2051
|
+
} else {
|
|
2052
|
+
state = {
|
|
2053
|
+
...state,
|
|
2054
|
+
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
1829
2057
|
return JSON.stringify({
|
|
1830
2058
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1831
2059
|
thread_id: threadId,
|
|
@@ -1833,7 +2061,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1833
2061
|
agent_name: agentName,
|
|
1834
2062
|
node_name: nodeName,
|
|
1835
2063
|
active,
|
|
1836
|
-
state
|
|
2064
|
+
state,
|
|
1837
2065
|
running,
|
|
1838
2066
|
role: "assistant"
|
|
1839
2067
|
}) + "\n";
|
|
@@ -1909,134 +2137,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1909
2137
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1910
2138
|
messages = messages.slice(1);
|
|
1911
2139
|
}
|
|
1912
|
-
const
|
|
1913
|
-
const existingMessageIds = new Set(
|
|
1914
|
-
const
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
2140
|
+
const existingMessages = state.messages || [];
|
|
2141
|
+
const existingMessageIds = new Set(existingMessages.map((message) => message.id));
|
|
2142
|
+
const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
|
|
2143
|
+
return {
|
|
2144
|
+
...state,
|
|
2145
|
+
messages: newMessages,
|
|
2146
|
+
copilotkit: {
|
|
2147
|
+
actions
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
2152
|
+
function langchainMessagesToCopilotKit(messages) {
|
|
2153
|
+
const result = [];
|
|
2154
|
+
const tool_call_names = {};
|
|
2155
|
+
for (const message of messages) {
|
|
2156
|
+
if (message.type === "ai") {
|
|
2157
|
+
for (const tool_call of message.tool_calls) {
|
|
2158
|
+
tool_call_names[tool_call.id] = tool_call.name;
|
|
2159
|
+
}
|
|
1918
2160
|
}
|
|
1919
2161
|
}
|
|
1920
2162
|
for (const message of messages) {
|
|
1921
|
-
|
|
1922
|
-
|
|
2163
|
+
let content = message.content;
|
|
2164
|
+
if (content instanceof Array) {
|
|
2165
|
+
content = content[0];
|
|
1923
2166
|
}
|
|
1924
|
-
if (
|
|
1925
|
-
|
|
2167
|
+
if (content instanceof Object) {
|
|
2168
|
+
content = content.text;
|
|
1926
2169
|
}
|
|
1927
|
-
if (
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
} else {
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2170
|
+
if (message.type === "human") {
|
|
2171
|
+
result.push({
|
|
2172
|
+
role: "user",
|
|
2173
|
+
content,
|
|
2174
|
+
id: message.id
|
|
2175
|
+
});
|
|
2176
|
+
} else if (message.type === "system") {
|
|
2177
|
+
result.push({
|
|
2178
|
+
role: "system",
|
|
2179
|
+
content,
|
|
2180
|
+
id: message.id
|
|
2181
|
+
});
|
|
2182
|
+
} else if (message.type === "ai") {
|
|
2183
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
2184
|
+
for (const tool_call of message.tool_calls) {
|
|
2185
|
+
result.push({
|
|
2186
|
+
id: tool_call.id,
|
|
2187
|
+
name: tool_call.name,
|
|
2188
|
+
arguments: tool_call.args,
|
|
2189
|
+
parentMessageId: message.id
|
|
2190
|
+
});
|
|
1941
2191
|
}
|
|
2192
|
+
} else {
|
|
2193
|
+
result.push({
|
|
2194
|
+
role: "assistant",
|
|
2195
|
+
content,
|
|
2196
|
+
id: message.id,
|
|
2197
|
+
parentMessageId: message.id
|
|
2198
|
+
});
|
|
1942
2199
|
}
|
|
2200
|
+
} else if (message.type === "tool") {
|
|
2201
|
+
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
2202
|
+
result.push({
|
|
2203
|
+
actionExecutionId: message.tool_call_id,
|
|
2204
|
+
actionName,
|
|
2205
|
+
result: content,
|
|
2206
|
+
id: message.id
|
|
2207
|
+
});
|
|
1943
2208
|
}
|
|
1944
2209
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
2210
|
+
const resultsDict = {};
|
|
2211
|
+
for (const msg of result) {
|
|
2212
|
+
if (msg.actionExecutionId) {
|
|
2213
|
+
resultsDict[msg.actionExecutionId] = msg;
|
|
1950
2214
|
}
|
|
1951
2215
|
}
|
|
1952
|
-
const
|
|
1953
|
-
for (
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1957
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1958
|
-
if (!nextMessage) {
|
|
1959
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1960
|
-
continue;
|
|
1961
|
-
}
|
|
1962
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1963
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1964
|
-
if (toolMessage) {
|
|
1965
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1966
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1967
|
-
continue;
|
|
1968
|
-
} else {
|
|
1969
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1970
|
-
continue;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
correctedMessages.push(currentMessage);
|
|
1974
|
-
continue;
|
|
2216
|
+
const reorderedResult = [];
|
|
2217
|
+
for (const msg of result) {
|
|
2218
|
+
if (!("actionExecutionId" in msg)) {
|
|
2219
|
+
reorderedResult.push(msg);
|
|
1975
2220
|
}
|
|
1976
|
-
if ("
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2221
|
+
if ("arguments" in msg) {
|
|
2222
|
+
const msgId = msg.id;
|
|
2223
|
+
if (msgId in resultsDict) {
|
|
2224
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1980
2225
|
}
|
|
1981
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1982
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1983
|
-
continue;
|
|
1984
|
-
}
|
|
1985
|
-
correctedMessages.push(currentMessage);
|
|
1986
|
-
continue;
|
|
1987
2226
|
}
|
|
1988
|
-
correctedMessages.push(currentMessage);
|
|
1989
2227
|
}
|
|
1990
|
-
return
|
|
1991
|
-
...state,
|
|
1992
|
-
messages: correctedMessages,
|
|
1993
|
-
copilotkit: {
|
|
1994
|
-
actions
|
|
1995
|
-
}
|
|
1996
|
-
};
|
|
2228
|
+
return reorderedResult;
|
|
1997
2229
|
}
|
|
1998
|
-
__name(
|
|
1999
|
-
function
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2230
|
+
__name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
|
|
2231
|
+
function copilotkitMessagesToLangChain(messages) {
|
|
2232
|
+
const result = [];
|
|
2233
|
+
const processedActionExecutions = /* @__PURE__ */ new Set();
|
|
2234
|
+
for (const message of messages) {
|
|
2235
|
+
if (message.isTextMessage()) {
|
|
2236
|
+
if (message.role === "user") {
|
|
2237
|
+
result.push({
|
|
2238
|
+
...message,
|
|
2239
|
+
role: MessageRole.user
|
|
2240
|
+
});
|
|
2241
|
+
} else if (message.role === "system") {
|
|
2242
|
+
result.push({
|
|
2243
|
+
...message,
|
|
2244
|
+
role: MessageRole.system
|
|
2245
|
+
});
|
|
2246
|
+
} else if (message.role === "assistant") {
|
|
2247
|
+
result.push({
|
|
2248
|
+
...message,
|
|
2249
|
+
role: MessageRole.assistant
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
continue;
|
|
2009
2253
|
}
|
|
2010
2254
|
if (message.isActionExecutionMessage()) {
|
|
2011
|
-
const
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2255
|
+
const messageId = message.parentMessageId ?? message.id;
|
|
2256
|
+
if (processedActionExecutions.has(messageId)) {
|
|
2257
|
+
continue;
|
|
2258
|
+
}
|
|
2259
|
+
processedActionExecutions.add(messageId);
|
|
2260
|
+
const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
|
|
2261
|
+
const tool_calls = relatedActionExecutions.map((m) => ({
|
|
2262
|
+
name: m.name,
|
|
2263
|
+
args: m.arguments,
|
|
2264
|
+
id: m.id
|
|
2265
|
+
}));
|
|
2266
|
+
result.push({
|
|
2267
|
+
id: messageId,
|
|
2268
|
+
type: "ActionExecutionMessage",
|
|
2018
2269
|
content: "",
|
|
2019
|
-
tool_calls
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
id: message.id
|
|
2024
|
-
};
|
|
2270
|
+
tool_calls,
|
|
2271
|
+
role: MessageRole.assistant
|
|
2272
|
+
});
|
|
2273
|
+
continue;
|
|
2025
2274
|
}
|
|
2026
2275
|
if (message.isResultMessage()) {
|
|
2027
|
-
|
|
2276
|
+
result.push({
|
|
2028
2277
|
type: message.type,
|
|
2029
2278
|
content: message.result,
|
|
2030
2279
|
id: message.id,
|
|
2031
2280
|
tool_call_id: message.actionExecutionId,
|
|
2032
2281
|
name: message.actionName,
|
|
2033
2282
|
role: MessageRole.tool
|
|
2034
|
-
};
|
|
2283
|
+
});
|
|
2284
|
+
continue;
|
|
2035
2285
|
}
|
|
2036
2286
|
throw new Error(`Unknown message type ${message.type}`);
|
|
2037
|
-
}
|
|
2287
|
+
}
|
|
2288
|
+
return result;
|
|
2038
2289
|
}
|
|
2039
|
-
__name(
|
|
2290
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2040
2291
|
|
|
2041
2292
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2042
2293
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -2046,7 +2297,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2046
2297
|
parameters: [],
|
|
2047
2298
|
handler: async (_args) => {
|
|
2048
2299
|
},
|
|
2049
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2300
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2050
2301
|
var _a;
|
|
2051
2302
|
logger2.debug({
|
|
2052
2303
|
actionName: agent.name
|
|
@@ -2072,7 +2323,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2072
2323
|
agent,
|
|
2073
2324
|
threadId,
|
|
2074
2325
|
nodeName,
|
|
2075
|
-
messages
|
|
2326
|
+
messages: [
|
|
2327
|
+
...messages,
|
|
2328
|
+
...additionalMessages
|
|
2329
|
+
],
|
|
2076
2330
|
state,
|
|
2077
2331
|
properties: graphqlContext.properties,
|
|
2078
2332
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2100,6 +2354,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2100
2354
|
}
|
|
2101
2355
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2102
2356
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2357
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2103
2358
|
const actions = json["actions"].map((action) => ({
|
|
2104
2359
|
name: action.name,
|
|
2105
2360
|
description: action.description,
|
|
@@ -2113,7 +2368,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2113
2368
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2114
2369
|
agentExecution: false,
|
|
2115
2370
|
type: "self-hosted",
|
|
2116
|
-
agentsAmount:
|
|
2371
|
+
agentsAmount: totalAgents
|
|
2117
2372
|
});
|
|
2118
2373
|
try {
|
|
2119
2374
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2148,13 +2403,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2148
2403
|
}
|
|
2149
2404
|
}
|
|
2150
2405
|
}));
|
|
2151
|
-
const agents = json["agents"].map((agent) => ({
|
|
2406
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
2152
2407
|
name: agent.name,
|
|
2153
2408
|
description: agent.description,
|
|
2154
2409
|
parameters: [],
|
|
2155
2410
|
handler: async (_args) => {
|
|
2156
2411
|
},
|
|
2157
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2412
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2158
2413
|
var _a;
|
|
2159
2414
|
logger2.debug({
|
|
2160
2415
|
actionName: agent.name
|
|
@@ -2179,7 +2434,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2179
2434
|
name,
|
|
2180
2435
|
threadId,
|
|
2181
2436
|
nodeName,
|
|
2182
|
-
messages
|
|
2437
|
+
messages: [
|
|
2438
|
+
...messages,
|
|
2439
|
+
...additionalMessages
|
|
2440
|
+
],
|
|
2183
2441
|
state,
|
|
2184
2442
|
properties: graphqlContext.properties,
|
|
2185
2443
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2201,7 +2459,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2201
2459
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2202
2460
|
return eventSource.processLangGraphEvents();
|
|
2203
2461
|
}
|
|
2204
|
-
}));
|
|
2462
|
+
})) : [];
|
|
2205
2463
|
return [
|
|
2206
2464
|
...actions,
|
|
2207
2465
|
...agents
|
|
@@ -2378,7 +2636,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2378
2636
|
// src/lib/telemetry-client.ts
|
|
2379
2637
|
var import_node_crypto3 = require("crypto");
|
|
2380
2638
|
var packageJson = require_package();
|
|
2381
|
-
var telemetryClient = new
|
|
2639
|
+
var telemetryClient = new import_shared10.TelemetryClient({
|
|
2382
2640
|
packageName: packageJson.name,
|
|
2383
2641
|
packageVersion: packageJson.version
|
|
2384
2642
|
});
|
|
@@ -2422,7 +2680,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2422
2680
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2423
2681
|
var telemetry_client_default = telemetryClient;
|
|
2424
2682
|
|
|
2683
|
+
// src/graphql/types/base/index.ts
|
|
2684
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2685
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2686
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2687
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2688
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2689
|
+
else
|
|
2690
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2691
|
+
if (d = decorators[i])
|
|
2692
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2693
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2694
|
+
}
|
|
2695
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2696
|
+
function _ts_metadata(k, v) {
|
|
2697
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2698
|
+
return Reflect.metadata(k, v);
|
|
2699
|
+
}
|
|
2700
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2701
|
+
var BaseMessageInput = class {
|
|
2702
|
+
id;
|
|
2703
|
+
createdAt;
|
|
2704
|
+
};
|
|
2705
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2706
|
+
_ts_decorate([
|
|
2707
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2708
|
+
_ts_metadata("design:type", String)
|
|
2709
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2710
|
+
_ts_decorate([
|
|
2711
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2712
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2713
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2714
|
+
BaseMessageInput = _ts_decorate([
|
|
2715
|
+
(0, import_type_graphql2.InputType)()
|
|
2716
|
+
], BaseMessageInput);
|
|
2717
|
+
|
|
2718
|
+
// src/graphql/types/converted/index.ts
|
|
2719
|
+
var Message = class extends BaseMessageInput {
|
|
2720
|
+
type;
|
|
2721
|
+
isTextMessage() {
|
|
2722
|
+
return this.type === "TextMessage";
|
|
2723
|
+
}
|
|
2724
|
+
isActionExecutionMessage() {
|
|
2725
|
+
return this.type === "ActionExecutionMessage";
|
|
2726
|
+
}
|
|
2727
|
+
isResultMessage() {
|
|
2728
|
+
return this.type === "ResultMessage";
|
|
2729
|
+
}
|
|
2730
|
+
isAgentStateMessage() {
|
|
2731
|
+
return this.type === "AgentStateMessage";
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
__name(Message, "Message");
|
|
2735
|
+
var TextMessage = class extends Message {
|
|
2736
|
+
type = "TextMessage";
|
|
2737
|
+
content;
|
|
2738
|
+
role;
|
|
2739
|
+
parentMessageId;
|
|
2740
|
+
};
|
|
2741
|
+
__name(TextMessage, "TextMessage");
|
|
2742
|
+
var ActionExecutionMessage = class extends Message {
|
|
2743
|
+
type = "ActionExecutionMessage";
|
|
2744
|
+
name;
|
|
2745
|
+
arguments;
|
|
2746
|
+
parentMessageId;
|
|
2747
|
+
};
|
|
2748
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2749
|
+
var ResultMessage = class extends Message {
|
|
2750
|
+
type = "ResultMessage";
|
|
2751
|
+
actionExecutionId;
|
|
2752
|
+
actionName;
|
|
2753
|
+
result;
|
|
2754
|
+
};
|
|
2755
|
+
__name(ResultMessage, "ResultMessage");
|
|
2756
|
+
var AgentStateMessage = class extends Message {
|
|
2757
|
+
type = "AgentStateMessage";
|
|
2758
|
+
threadId;
|
|
2759
|
+
agentName;
|
|
2760
|
+
nodeName;
|
|
2761
|
+
runId;
|
|
2762
|
+
active;
|
|
2763
|
+
role;
|
|
2764
|
+
state;
|
|
2765
|
+
running;
|
|
2766
|
+
};
|
|
2767
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2768
|
+
|
|
2425
2769
|
// src/service-adapters/events.ts
|
|
2770
|
+
var import_class_transformer = require("class-transformer");
|
|
2426
2771
|
var RuntimeEventTypes;
|
|
2427
2772
|
(function(RuntimeEventTypes2) {
|
|
2428
2773
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2438,52 +2783,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2438
2783
|
constructor() {
|
|
2439
2784
|
super();
|
|
2440
2785
|
}
|
|
2441
|
-
sendTextMessageStart(messageId) {
|
|
2786
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2442
2787
|
this.next({
|
|
2443
2788
|
type: "TextMessageStart",
|
|
2444
|
-
messageId
|
|
2789
|
+
messageId,
|
|
2790
|
+
parentMessageId
|
|
2445
2791
|
});
|
|
2446
2792
|
}
|
|
2447
|
-
sendTextMessageContent(content) {
|
|
2793
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2448
2794
|
this.next({
|
|
2449
2795
|
type: "TextMessageContent",
|
|
2450
|
-
content
|
|
2796
|
+
content,
|
|
2797
|
+
messageId
|
|
2451
2798
|
});
|
|
2452
2799
|
}
|
|
2453
|
-
sendTextMessageEnd() {
|
|
2800
|
+
sendTextMessageEnd({ messageId }) {
|
|
2454
2801
|
this.next({
|
|
2455
|
-
type: "TextMessageEnd"
|
|
2802
|
+
type: "TextMessageEnd",
|
|
2803
|
+
messageId
|
|
2456
2804
|
});
|
|
2457
2805
|
}
|
|
2458
2806
|
sendTextMessage(messageId, content) {
|
|
2459
|
-
this.sendTextMessageStart(
|
|
2460
|
-
|
|
2461
|
-
|
|
2807
|
+
this.sendTextMessageStart({
|
|
2808
|
+
messageId
|
|
2809
|
+
});
|
|
2810
|
+
this.sendTextMessageContent({
|
|
2811
|
+
messageId,
|
|
2812
|
+
content
|
|
2813
|
+
});
|
|
2814
|
+
this.sendTextMessageEnd({
|
|
2815
|
+
messageId
|
|
2816
|
+
});
|
|
2462
2817
|
}
|
|
2463
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2818
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2464
2819
|
this.next({
|
|
2465
2820
|
type: "ActionExecutionStart",
|
|
2466
2821
|
actionExecutionId,
|
|
2467
|
-
actionName
|
|
2822
|
+
actionName,
|
|
2823
|
+
parentMessageId
|
|
2468
2824
|
});
|
|
2469
2825
|
}
|
|
2470
|
-
sendActionExecutionArgs(args) {
|
|
2826
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2471
2827
|
this.next({
|
|
2472
2828
|
type: "ActionExecutionArgs",
|
|
2473
|
-
args
|
|
2829
|
+
args,
|
|
2830
|
+
actionExecutionId
|
|
2474
2831
|
});
|
|
2475
2832
|
}
|
|
2476
|
-
sendActionExecutionEnd() {
|
|
2833
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2477
2834
|
this.next({
|
|
2478
|
-
type: "ActionExecutionEnd"
|
|
2835
|
+
type: "ActionExecutionEnd",
|
|
2836
|
+
actionExecutionId
|
|
2479
2837
|
});
|
|
2480
2838
|
}
|
|
2481
|
-
sendActionExecution(actionExecutionId,
|
|
2482
|
-
this.sendActionExecutionStart(
|
|
2483
|
-
|
|
2484
|
-
|
|
2839
|
+
sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
|
|
2840
|
+
this.sendActionExecutionStart({
|
|
2841
|
+
actionExecutionId,
|
|
2842
|
+
actionName,
|
|
2843
|
+
parentMessageId
|
|
2844
|
+
});
|
|
2845
|
+
this.sendActionExecutionArgs({
|
|
2846
|
+
actionExecutionId,
|
|
2847
|
+
args
|
|
2848
|
+
});
|
|
2849
|
+
this.sendActionExecutionEnd({
|
|
2850
|
+
actionExecutionId
|
|
2851
|
+
});
|
|
2485
2852
|
}
|
|
2486
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2853
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2487
2854
|
this.next({
|
|
2488
2855
|
type: "ActionExecutionResult",
|
|
2489
2856
|
actionName,
|
|
@@ -2491,7 +2858,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2491
2858
|
result
|
|
2492
2859
|
});
|
|
2493
2860
|
}
|
|
2494
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2861
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2495
2862
|
this.next({
|
|
2496
2863
|
type: "AgentStateMessage",
|
|
2497
2864
|
threadId,
|
|
@@ -2512,14 +2879,14 @@ var RuntimeEventSource = class {
|
|
|
2512
2879
|
async stream(callback) {
|
|
2513
2880
|
this.callback = callback;
|
|
2514
2881
|
}
|
|
2515
|
-
sendErrorMessageToChat() {
|
|
2516
|
-
const errorMessage =
|
|
2882
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2883
|
+
const errorMessage = `\u274C ${message}`;
|
|
2517
2884
|
if (!this.callback) {
|
|
2518
2885
|
this.stream(async (eventStream$) => {
|
|
2519
|
-
eventStream$.sendTextMessage((0,
|
|
2886
|
+
eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2520
2887
|
});
|
|
2521
2888
|
} else {
|
|
2522
|
-
this.eventStream$.sendTextMessage((0,
|
|
2889
|
+
this.eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2523
2890
|
}
|
|
2524
2891
|
}
|
|
2525
2892
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2528,27 +2895,19 @@ var RuntimeEventSource = class {
|
|
|
2528
2895
|
this.sendErrorMessageToChat();
|
|
2529
2896
|
});
|
|
2530
2897
|
return this.eventStream$.pipe(
|
|
2531
|
-
// mark tools for server side execution
|
|
2532
|
-
(0, import_rxjs2.map)((event) => {
|
|
2533
|
-
if (event.type === "ActionExecutionStart") {
|
|
2534
|
-
if (event.scope !== "passThrough") {
|
|
2535
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
return event;
|
|
2539
|
-
}),
|
|
2540
2898
|
// track state
|
|
2541
2899
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2542
2900
|
acc = {
|
|
2543
2901
|
...acc
|
|
2544
2902
|
};
|
|
2545
2903
|
if (event.type === "ActionExecutionStart") {
|
|
2546
|
-
acc.callActionServerSide =
|
|
2904
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2547
2905
|
acc.args = "";
|
|
2548
2906
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2549
2907
|
if (acc.callActionServerSide) {
|
|
2550
2908
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2551
2909
|
}
|
|
2910
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2552
2911
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2553
2912
|
acc.args += event.args;
|
|
2554
2913
|
}
|
|
@@ -2559,12 +2918,13 @@ var RuntimeEventSource = class {
|
|
|
2559
2918
|
callActionServerSide: false,
|
|
2560
2919
|
args: "",
|
|
2561
2920
|
actionExecutionId: null,
|
|
2562
|
-
action: null
|
|
2921
|
+
action: null,
|
|
2922
|
+
actionExecutionParentMessageId: null
|
|
2563
2923
|
}),
|
|
2564
2924
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2565
2925
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2566
2926
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2567
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2927
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2568
2928
|
console.error(error);
|
|
2569
2929
|
});
|
|
2570
2930
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2577,7 +2937,7 @@ var RuntimeEventSource = class {
|
|
|
2577
2937
|
}
|
|
2578
2938
|
};
|
|
2579
2939
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2580
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2940
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2581
2941
|
var _a;
|
|
2582
2942
|
if (guardrailsResult$) {
|
|
2583
2943
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2597,10 +2957,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2597
2957
|
}
|
|
2598
2958
|
}
|
|
2599
2959
|
if (isLangGraphAgentAction(action)) {
|
|
2600
|
-
|
|
2960
|
+
const result = `${action.name} agent started`;
|
|
2961
|
+
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2962
|
+
id: actionExecutionId,
|
|
2963
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2964
|
+
name: action.name,
|
|
2965
|
+
arguments: JSON.parse(actionArguments),
|
|
2966
|
+
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2967
|
+
});
|
|
2968
|
+
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2969
|
+
id: "result-" + actionExecutionId,
|
|
2970
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2971
|
+
actionExecutionId,
|
|
2972
|
+
actionName: action.name,
|
|
2973
|
+
result
|
|
2974
|
+
});
|
|
2975
|
+
eventStream$.sendActionExecutionResult({
|
|
2976
|
+
actionExecutionId,
|
|
2977
|
+
actionName: action.name,
|
|
2978
|
+
result
|
|
2979
|
+
});
|
|
2601
2980
|
const stream = await action.langGraphAgentHandler({
|
|
2602
2981
|
name: action.name,
|
|
2603
|
-
actionInputsWithoutAgents
|
|
2982
|
+
actionInputsWithoutAgents,
|
|
2983
|
+
additionalMessages: [
|
|
2984
|
+
agentExecution,
|
|
2985
|
+
agentExecutionResult
|
|
2986
|
+
]
|
|
2604
2987
|
});
|
|
2605
2988
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2606
2989
|
next: (event) => eventStream$.next(event),
|
|
@@ -2621,113 +3004,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2621
3004
|
}
|
|
2622
3005
|
__name(executeAction, "executeAction");
|
|
2623
3006
|
|
|
2624
|
-
// src/graphql/types/base/index.ts
|
|
2625
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2626
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2627
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2628
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2629
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2630
|
-
else
|
|
2631
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2632
|
-
if (d = decorators[i])
|
|
2633
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2634
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2635
|
-
}
|
|
2636
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2637
|
-
function _ts_metadata(k, v) {
|
|
2638
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2639
|
-
return Reflect.metadata(k, v);
|
|
2640
|
-
}
|
|
2641
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2642
|
-
var BaseMessageInput = class {
|
|
2643
|
-
id;
|
|
2644
|
-
createdAt;
|
|
2645
|
-
};
|
|
2646
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2647
|
-
_ts_decorate([
|
|
2648
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2649
|
-
_ts_metadata("design:type", String)
|
|
2650
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2651
|
-
_ts_decorate([
|
|
2652
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2653
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2654
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2655
|
-
BaseMessageInput = _ts_decorate([
|
|
2656
|
-
(0, import_type_graphql2.InputType)()
|
|
2657
|
-
], BaseMessageInput);
|
|
2658
|
-
|
|
2659
|
-
// src/graphql/types/converted/index.ts
|
|
2660
|
-
var Message = class extends BaseMessageInput {
|
|
2661
|
-
type;
|
|
2662
|
-
isTextMessage() {
|
|
2663
|
-
return this.type === "TextMessage";
|
|
2664
|
-
}
|
|
2665
|
-
isActionExecutionMessage() {
|
|
2666
|
-
return this.type === "ActionExecutionMessage";
|
|
2667
|
-
}
|
|
2668
|
-
isResultMessage() {
|
|
2669
|
-
return this.type === "ResultMessage";
|
|
2670
|
-
}
|
|
2671
|
-
isAgentStateMessage() {
|
|
2672
|
-
return this.type === "AgentStateMessage";
|
|
2673
|
-
}
|
|
2674
|
-
};
|
|
2675
|
-
__name(Message, "Message");
|
|
2676
|
-
var TextMessage = class extends Message {
|
|
2677
|
-
type = "TextMessage";
|
|
2678
|
-
content;
|
|
2679
|
-
role;
|
|
2680
|
-
};
|
|
2681
|
-
__name(TextMessage, "TextMessage");
|
|
2682
|
-
var ActionExecutionMessage = class extends Message {
|
|
2683
|
-
type = "ActionExecutionMessage";
|
|
2684
|
-
name;
|
|
2685
|
-
arguments;
|
|
2686
|
-
scope;
|
|
2687
|
-
};
|
|
2688
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2689
|
-
var ResultMessage = class extends Message {
|
|
2690
|
-
type = "ResultMessage";
|
|
2691
|
-
actionExecutionId;
|
|
2692
|
-
actionName;
|
|
2693
|
-
result;
|
|
2694
|
-
};
|
|
2695
|
-
__name(ResultMessage, "ResultMessage");
|
|
2696
|
-
var AgentStateMessage = class extends Message {
|
|
2697
|
-
type = "AgentStateMessage";
|
|
2698
|
-
threadId;
|
|
2699
|
-
agentName;
|
|
2700
|
-
nodeName;
|
|
2701
|
-
runId;
|
|
2702
|
-
active;
|
|
2703
|
-
role;
|
|
2704
|
-
state;
|
|
2705
|
-
running;
|
|
2706
|
-
};
|
|
2707
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2708
|
-
|
|
2709
3007
|
// src/service-adapters/conversion.ts
|
|
2710
|
-
var
|
|
3008
|
+
var import_class_transformer2 = require("class-transformer");
|
|
2711
3009
|
function convertGqlInputToMessages(inputMessages) {
|
|
2712
3010
|
const messages = [];
|
|
2713
3011
|
for (const message of inputMessages) {
|
|
2714
3012
|
if (message.textMessage) {
|
|
2715
|
-
messages.push((0,
|
|
3013
|
+
messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2716
3014
|
id: message.id,
|
|
2717
3015
|
createdAt: message.createdAt,
|
|
2718
3016
|
role: message.textMessage.role,
|
|
2719
|
-
content: message.textMessage.content
|
|
3017
|
+
content: message.textMessage.content,
|
|
3018
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2720
3019
|
}));
|
|
2721
3020
|
} else if (message.actionExecutionMessage) {
|
|
2722
|
-
messages.push((0,
|
|
3021
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2723
3022
|
id: message.id,
|
|
2724
3023
|
createdAt: message.createdAt,
|
|
2725
3024
|
name: message.actionExecutionMessage.name,
|
|
2726
3025
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2727
|
-
|
|
3026
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2728
3027
|
}));
|
|
2729
3028
|
} else if (message.resultMessage) {
|
|
2730
|
-
messages.push((0,
|
|
3029
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2731
3030
|
id: message.id,
|
|
2732
3031
|
createdAt: message.createdAt,
|
|
2733
3032
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2735,7 +3034,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2735
3034
|
result: message.resultMessage.result
|
|
2736
3035
|
}));
|
|
2737
3036
|
} else if (message.agentStateMessage) {
|
|
2738
|
-
messages.push((0,
|
|
3037
|
+
messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
2739
3038
|
id: message.id,
|
|
2740
3039
|
threadId: message.agentStateMessage.threadId,
|
|
2741
3040
|
createdAt: message.createdAt,
|
|
@@ -2786,7 +3085,7 @@ var CopilotRuntime = class {
|
|
|
2786
3085
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2787
3086
|
name: action.name,
|
|
2788
3087
|
description: action.description,
|
|
2789
|
-
jsonSchema: JSON.stringify((0,
|
|
3088
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2790
3089
|
}));
|
|
2791
3090
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2792
3091
|
...serverSideActionsInput,
|
|
@@ -2835,13 +3134,7 @@ var CopilotRuntime = class {
|
|
|
2835
3134
|
} catch (error) {
|
|
2836
3135
|
console.error("Error getting response:", error);
|
|
2837
3136
|
eventSource.sendErrorMessageToChat();
|
|
2838
|
-
|
|
2839
|
-
threadId: threadId || (0, import_shared10.randomId)(),
|
|
2840
|
-
runId: runId || (0, import_shared10.randomId)(),
|
|
2841
|
-
eventSource,
|
|
2842
|
-
serverSideActions: [],
|
|
2843
|
-
actionInputsWithoutAgents: []
|
|
2844
|
-
};
|
|
3137
|
+
throw error;
|
|
2845
3138
|
}
|
|
2846
3139
|
}
|
|
2847
3140
|
async processAgentRequest(request) {
|
|
@@ -2857,7 +3150,7 @@ var CopilotRuntime = class {
|
|
|
2857
3150
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2858
3151
|
name: action.name,
|
|
2859
3152
|
description: action.description,
|
|
2860
|
-
jsonSchema: JSON.stringify((0,
|
|
3153
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2861
3154
|
}));
|
|
2862
3155
|
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2863
3156
|
...serverSideActionsInput,
|
|
@@ -3044,6 +3337,7 @@ MessageInput = _ts_decorate2([
|
|
|
3044
3337
|
], MessageInput);
|
|
3045
3338
|
var TextMessageInput = class {
|
|
3046
3339
|
content;
|
|
3340
|
+
parentMessageId;
|
|
3047
3341
|
role;
|
|
3048
3342
|
};
|
|
3049
3343
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3051,6 +3345,12 @@ _ts_decorate2([
|
|
|
3051
3345
|
(0, import_type_graphql3.Field)(() => String),
|
|
3052
3346
|
_ts_metadata2("design:type", String)
|
|
3053
3347
|
], TextMessageInput.prototype, "content", void 0);
|
|
3348
|
+
_ts_decorate2([
|
|
3349
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3350
|
+
nullable: true
|
|
3351
|
+
}),
|
|
3352
|
+
_ts_metadata2("design:type", String)
|
|
3353
|
+
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
3054
3354
|
_ts_decorate2([
|
|
3055
3355
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3056
3356
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3061,6 +3361,7 @@ TextMessageInput = _ts_decorate2([
|
|
|
3061
3361
|
var ActionExecutionMessageInput = class {
|
|
3062
3362
|
name;
|
|
3063
3363
|
arguments;
|
|
3364
|
+
parentMessageId;
|
|
3064
3365
|
scope;
|
|
3065
3366
|
};
|
|
3066
3367
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3073,8 +3374,17 @@ _ts_decorate2([
|
|
|
3073
3374
|
_ts_metadata2("design:type", String)
|
|
3074
3375
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3075
3376
|
_ts_decorate2([
|
|
3076
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3077
|
-
|
|
3377
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3378
|
+
nullable: true
|
|
3379
|
+
}),
|
|
3380
|
+
_ts_metadata2("design:type", String)
|
|
3381
|
+
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3382
|
+
_ts_decorate2([
|
|
3383
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3384
|
+
nullable: true,
|
|
3385
|
+
deprecationReason: "This field will be removed in a future version"
|
|
3386
|
+
}),
|
|
3387
|
+
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
3078
3388
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3079
3389
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3080
3390
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3082,6 +3392,7 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3082
3392
|
var ResultMessageInput = class {
|
|
3083
3393
|
actionExecutionId;
|
|
3084
3394
|
actionName;
|
|
3395
|
+
parentMessageId;
|
|
3085
3396
|
result;
|
|
3086
3397
|
};
|
|
3087
3398
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3093,6 +3404,12 @@ _ts_decorate2([
|
|
|
3093
3404
|
(0, import_type_graphql3.Field)(() => String),
|
|
3094
3405
|
_ts_metadata2("design:type", String)
|
|
3095
3406
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3407
|
+
_ts_decorate2([
|
|
3408
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3409
|
+
nullable: true
|
|
3410
|
+
}),
|
|
3411
|
+
_ts_metadata2("design:type", String)
|
|
3412
|
+
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
3096
3413
|
_ts_decorate2([
|
|
3097
3414
|
(0, import_type_graphql3.Field)(() => String),
|
|
3098
3415
|
_ts_metadata2("design:type", String)
|
|
@@ -3815,6 +4132,7 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3815
4132
|
var TextMessageOutput = class {
|
|
3816
4133
|
role;
|
|
3817
4134
|
content;
|
|
4135
|
+
parentMessageId;
|
|
3818
4136
|
};
|
|
3819
4137
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3820
4138
|
_ts_decorate13([
|
|
@@ -3827,6 +4145,12 @@ _ts_decorate13([
|
|
|
3827
4145
|
]),
|
|
3828
4146
|
_ts_metadata13("design:type", Array)
|
|
3829
4147
|
], TextMessageOutput.prototype, "content", void 0);
|
|
4148
|
+
_ts_decorate13([
|
|
4149
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4150
|
+
nullable: true
|
|
4151
|
+
}),
|
|
4152
|
+
_ts_metadata13("design:type", String)
|
|
4153
|
+
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
3830
4154
|
TextMessageOutput = _ts_decorate13([
|
|
3831
4155
|
(0, import_type_graphql14.ObjectType)({
|
|
3832
4156
|
implements: BaseMessageOutput
|
|
@@ -3836,6 +4160,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
3836
4160
|
name;
|
|
3837
4161
|
scope;
|
|
3838
4162
|
arguments;
|
|
4163
|
+
parentMessageId;
|
|
3839
4164
|
};
|
|
3840
4165
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3841
4166
|
_ts_decorate13([
|
|
@@ -3843,8 +4168,11 @@ _ts_decorate13([
|
|
|
3843
4168
|
_ts_metadata13("design:type", String)
|
|
3844
4169
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3845
4170
|
_ts_decorate13([
|
|
3846
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3847
|
-
|
|
4171
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4172
|
+
nullable: true,
|
|
4173
|
+
deprecationReason: "This field will be removed in a future version"
|
|
4174
|
+
}),
|
|
4175
|
+
_ts_metadata13("design:type", String)
|
|
3848
4176
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3849
4177
|
_ts_decorate13([
|
|
3850
4178
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3852,6 +4180,12 @@ _ts_decorate13([
|
|
|
3852
4180
|
]),
|
|
3853
4181
|
_ts_metadata13("design:type", Array)
|
|
3854
4182
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
4183
|
+
_ts_decorate13([
|
|
4184
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4185
|
+
nullable: true
|
|
4186
|
+
}),
|
|
4187
|
+
_ts_metadata13("design:type", String)
|
|
4188
|
+
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
3855
4189
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3856
4190
|
(0, import_type_graphql14.ObjectType)({
|
|
3857
4191
|
implements: BaseMessageOutput
|
|
@@ -3962,7 +4296,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3962
4296
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3963
4297
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3964
4298
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3965
|
-
var
|
|
4299
|
+
var import_class_transformer3 = require("class-transformer");
|
|
3966
4300
|
var import_graphql = require("graphql");
|
|
3967
4301
|
|
|
3968
4302
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -3999,7 +4333,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
3999
4333
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
4000
4334
|
|
|
4001
4335
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4002
|
-
var
|
|
4336
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
4003
4337
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
4004
4338
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4005
4339
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4116,7 +4450,7 @@ var CopilotResolver = class {
|
|
|
4116
4450
|
rejectOutputMessagesPromise = reject;
|
|
4117
4451
|
});
|
|
4118
4452
|
logger2.debug("Processing");
|
|
4119
|
-
const { eventSource, threadId = (0,
|
|
4453
|
+
const { eventSource, threadId = (0, import_shared13.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
4120
4454
|
serviceAdapter,
|
|
4121
4455
|
messages: data.messages,
|
|
4122
4456
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -4160,8 +4494,8 @@ var CopilotResolver = class {
|
|
|
4160
4494
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4161
4495
|
});
|
|
4162
4496
|
outputMessages = [
|
|
4163
|
-
(0,
|
|
4164
|
-
id: (0,
|
|
4497
|
+
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4498
|
+
id: (0, import_shared13.randomId)(),
|
|
4165
4499
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4166
4500
|
content: result.reason,
|
|
4167
4501
|
role: MessageRole.assistant
|
|
@@ -4209,12 +4543,15 @@ var CopilotResolver = class {
|
|
|
4209
4543
|
// skip until this message start event
|
|
4210
4544
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4211
4545
|
// take until the message end event
|
|
4212
|
-
(0, import_rxjs4.takeWhile)((e) => e.type
|
|
4546
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
4547
|
+
// filter out any other message events or message ids
|
|
4548
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
4213
4549
|
);
|
|
4214
4550
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4215
4551
|
const messageId = event.messageId;
|
|
4216
4552
|
pushMessage({
|
|
4217
4553
|
id: messageId,
|
|
4554
|
+
parentMessageId: event.parentMessageId,
|
|
4218
4555
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4219
4556
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4220
4557
|
role: MessageRole.assistant,
|
|
@@ -4227,7 +4564,7 @@ var CopilotResolver = class {
|
|
|
4227
4564
|
reason,
|
|
4228
4565
|
messageId: messageId2
|
|
4229
4566
|
}, "Text streaming interrupted");
|
|
4230
|
-
streamingTextStatus.next((0,
|
|
4567
|
+
streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4231
4568
|
reason
|
|
4232
4569
|
}));
|
|
4233
4570
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4260,7 +4597,7 @@ var CopilotResolver = class {
|
|
|
4260
4597
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4261
4598
|
stopStreamingText();
|
|
4262
4599
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4263
|
-
outputMessages.push((0,
|
|
4600
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4264
4601
|
id: messageId,
|
|
4265
4602
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4266
4603
|
content: textChunks.join(""),
|
|
@@ -4273,14 +4610,20 @@ var CopilotResolver = class {
|
|
|
4273
4610
|
break;
|
|
4274
4611
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4275
4612
|
logger2.debug("Action execution start event received");
|
|
4276
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4613
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4614
|
+
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4615
|
+
// take until the action execution end event
|
|
4616
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4617
|
+
// filter out any other action execution events or action execution ids
|
|
4618
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4619
|
+
);
|
|
4277
4620
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4278
4621
|
pushMessage({
|
|
4279
4622
|
id: event.actionExecutionId,
|
|
4623
|
+
parentMessageId: event.parentMessageId,
|
|
4280
4624
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4281
4625
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4282
4626
|
name: event.actionName,
|
|
4283
|
-
scope: event.scope,
|
|
4284
4627
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4285
4628
|
logger2.debug("Action execution argument stream created");
|
|
4286
4629
|
const argumentChunks = [];
|
|
@@ -4296,7 +4639,7 @@ var CopilotResolver = class {
|
|
|
4296
4639
|
logger2.error({
|
|
4297
4640
|
err
|
|
4298
4641
|
}, "Error in action execution argument stream");
|
|
4299
|
-
streamingArgumentsStatus.next((0,
|
|
4642
|
+
streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4300
4643
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4301
4644
|
}));
|
|
4302
4645
|
stopStreamingArguments();
|
|
@@ -4307,11 +4650,10 @@ var CopilotResolver = class {
|
|
|
4307
4650
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4308
4651
|
stopStreamingArguments();
|
|
4309
4652
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4310
|
-
outputMessages.push((0,
|
|
4653
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
|
|
4311
4654
|
id: event.actionExecutionId,
|
|
4312
4655
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4313
4656
|
name: event.actionName,
|
|
4314
|
-
scope: event.scope,
|
|
4315
4657
|
arguments: argumentChunks.join("")
|
|
4316
4658
|
}));
|
|
4317
4659
|
}
|
|
@@ -4324,15 +4666,15 @@ var CopilotResolver = class {
|
|
|
4324
4666
|
result: event.result
|
|
4325
4667
|
}, "Action execution result event received");
|
|
4326
4668
|
pushMessage({
|
|
4327
|
-
id:
|
|
4669
|
+
id: "result-" + event.actionExecutionId,
|
|
4328
4670
|
status: new SuccessMessageStatus(),
|
|
4329
4671
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4330
4672
|
actionExecutionId: event.actionExecutionId,
|
|
4331
4673
|
actionName: event.actionName,
|
|
4332
4674
|
result: event.result
|
|
4333
4675
|
});
|
|
4334
|
-
outputMessages.push((0,
|
|
4335
|
-
id:
|
|
4676
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
|
|
4677
|
+
id: "result-" + event.actionExecutionId,
|
|
4336
4678
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4337
4679
|
actionExecutionId: event.actionExecutionId,
|
|
4338
4680
|
actionName: event.actionName,
|
|
@@ -4344,7 +4686,7 @@ var CopilotResolver = class {
|
|
|
4344
4686
|
event
|
|
4345
4687
|
}, "Agent message event received");
|
|
4346
4688
|
pushMessage({
|
|
4347
|
-
id: (0,
|
|
4689
|
+
id: (0, import_shared13.randomId)(),
|
|
4348
4690
|
status: new SuccessMessageStatus(),
|
|
4349
4691
|
threadId: event.threadId,
|
|
4350
4692
|
agentName: event.agentName,
|
|
@@ -4356,8 +4698,8 @@ var CopilotResolver = class {
|
|
|
4356
4698
|
role: MessageRole.assistant,
|
|
4357
4699
|
createdAt: /* @__PURE__ */ new Date()
|
|
4358
4700
|
});
|
|
4359
|
-
outputMessages.push((0,
|
|
4360
|
-
id: (0,
|
|
4701
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
4702
|
+
id: (0, import_shared13.randomId)(),
|
|
4361
4703
|
threadId: event.threadId,
|
|
4362
4704
|
agentName: event.agentName,
|
|
4363
4705
|
nodeName: event.nodeName,
|
|
@@ -4438,7 +4780,14 @@ function createLogger(options) {
|
|
|
4438
4780
|
colorize: true
|
|
4439
4781
|
});
|
|
4440
4782
|
const logger2 = (0, import_pino.default)({
|
|
4441
|
-
level: process.env.LOG_LEVEL || level || "error"
|
|
4783
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
4784
|
+
redact: {
|
|
4785
|
+
paths: [
|
|
4786
|
+
"pid",
|
|
4787
|
+
"hostname"
|
|
4788
|
+
],
|
|
4789
|
+
remove: true
|
|
4790
|
+
}
|
|
4442
4791
|
}, stream);
|
|
4443
4792
|
if (component) {
|
|
4444
4793
|
return logger2.child({
|
|
@@ -4641,6 +4990,8 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4641
4990
|
0 && (module.exports = {
|
|
4642
4991
|
AnthropicAdapter,
|
|
4643
4992
|
CopilotRuntime,
|
|
4993
|
+
ExperimentalEmptyAdapter,
|
|
4994
|
+
ExperimentalOllamaAdapter,
|
|
4644
4995
|
GoogleGenerativeAIAdapter,
|
|
4645
4996
|
GroqAdapter,
|
|
4646
4997
|
GuardrailsValidationFailureResponse,
|