@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.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 +141 -3
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-25G6SHWM.mjs} +458 -331
- package/dist/chunk-25G6SHWM.mjs.map +1 -0
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-AFKLCW76.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-D6J2N5ZQ.mjs} +2 -2
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-PIUHAIBR.mjs} +2 -2
- 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 +832 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- 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 +737 -459
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +71 -30
- 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 +71 -30
- 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 +71 -30
- 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 +71 -30
- 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 +4 -4
- 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/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 +184 -154
- 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-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-K67A6XOJ.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-AFKLCW76.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-D6J2N5ZQ.mjs.map} +0 -0
- /package/dist/{chunk-QNQ6UT3D.mjs.map → chunk-PIUHAIBR.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.5.0
|
|
47
|
+
version: "1.5.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"
|
|
@@ -1634,8 +1854,6 @@ async function streamEvents(controller, args) {
|
|
|
1634
1854
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1635
1855
|
initialThreadId = initialThreadId.substring(3);
|
|
1636
1856
|
}
|
|
1637
|
-
const assistants = await client.assistants.search();
|
|
1638
|
-
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1639
1857
|
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1640
1858
|
if (initialThreadId === threadId) {
|
|
1641
1859
|
await client.threads.get(threadId);
|
|
@@ -1655,7 +1873,7 @@ async function streamEvents(controller, args) {
|
|
|
1655
1873
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1656
1874
|
let formattedMessages = [];
|
|
1657
1875
|
try {
|
|
1658
|
-
formattedMessages =
|
|
1876
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1659
1877
|
} catch (e) {
|
|
1660
1878
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1661
1879
|
}
|
|
@@ -1666,8 +1884,16 @@ async function streamEvents(controller, args) {
|
|
|
1666
1884
|
asNode: nodeName
|
|
1667
1885
|
});
|
|
1668
1886
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1887
|
+
let streamInfo = {
|
|
1888
|
+
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1889
|
+
};
|
|
1890
|
+
const assistants = await client.assistants.search();
|
|
1891
|
+
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1892
|
+
if (!retrievedAssistant) {
|
|
1893
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1894
|
+
...streamInfo,
|
|
1895
|
+
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1896
|
+
});
|
|
1671
1897
|
console.error(`
|
|
1672
1898
|
No agent found for the agent name specified in CopilotKit provider
|
|
1673
1899
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1677,6 +1903,7 @@ async function streamEvents(controller, args) {
|
|
|
1677
1903
|
`);
|
|
1678
1904
|
throw new Error("No agent id found");
|
|
1679
1905
|
}
|
|
1906
|
+
const assistantId = retrievedAssistant.assistant_id;
|
|
1680
1907
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1681
1908
|
const streamInput = mode === "start" ? state : null;
|
|
1682
1909
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1695,9 +1922,6 @@ async function streamEvents(controller, args) {
|
|
|
1695
1922
|
let latestStateValues = {};
|
|
1696
1923
|
let updatedState = state;
|
|
1697
1924
|
let manuallyEmittedState = null;
|
|
1698
|
-
let streamInfo = {
|
|
1699
|
-
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1700
|
-
};
|
|
1701
1925
|
try {
|
|
1702
1926
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1703
1927
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1710,7 +1934,6 @@ async function streamEvents(controller, args) {
|
|
|
1710
1934
|
].includes(chunk.event))
|
|
1711
1935
|
continue;
|
|
1712
1936
|
if (chunk.event === "error") {
|
|
1713
|
-
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1714
1937
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1715
1938
|
}
|
|
1716
1939
|
if (chunk.event === "values") {
|
|
@@ -1803,21 +2026,34 @@ async function streamEvents(controller, args) {
|
|
|
1803
2026
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1804
2027
|
state: state.values,
|
|
1805
2028
|
running: !shouldExit,
|
|
1806
|
-
active: false
|
|
2029
|
+
active: false,
|
|
2030
|
+
includeMessages: true
|
|
1807
2031
|
}));
|
|
1808
2032
|
return Promise.resolve();
|
|
1809
2033
|
} catch (e) {
|
|
2034
|
+
logger2.error(e);
|
|
2035
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
2036
|
+
...streamInfo,
|
|
2037
|
+
error: e.message
|
|
2038
|
+
});
|
|
1810
2039
|
return Promise.resolve();
|
|
1811
2040
|
}
|
|
1812
2041
|
}
|
|
1813
2042
|
__name(streamEvents, "streamEvents");
|
|
1814
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
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
|
+
}
|
|
1821
2057
|
return JSON.stringify({
|
|
1822
2058
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1823
2059
|
thread_id: threadId,
|
|
@@ -1825,7 +2061,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1825
2061
|
agent_name: agentName,
|
|
1826
2062
|
node_name: nodeName,
|
|
1827
2063
|
active,
|
|
1828
|
-
state
|
|
2064
|
+
state,
|
|
1829
2065
|
running,
|
|
1830
2066
|
role: "assistant"
|
|
1831
2067
|
}) + "\n";
|
|
@@ -1901,134 +2137,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1901
2137
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1902
2138
|
messages = messages.slice(1);
|
|
1903
2139
|
}
|
|
1904
|
-
const
|
|
1905
|
-
const existingMessageIds = new Set(
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
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
|
+
}
|
|
1910
2160
|
}
|
|
1911
2161
|
}
|
|
1912
2162
|
for (const message of messages) {
|
|
1913
|
-
|
|
1914
|
-
|
|
2163
|
+
let content = message.content;
|
|
2164
|
+
if (content instanceof Array) {
|
|
2165
|
+
content = content[0];
|
|
1915
2166
|
}
|
|
1916
|
-
if (
|
|
1917
|
-
|
|
2167
|
+
if (content instanceof Object) {
|
|
2168
|
+
content = content.text;
|
|
1918
2169
|
}
|
|
1919
|
-
if (
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
} else {
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
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
|
+
});
|
|
1933
2191
|
}
|
|
2192
|
+
} else {
|
|
2193
|
+
result.push({
|
|
2194
|
+
role: "assistant",
|
|
2195
|
+
content,
|
|
2196
|
+
id: message.id,
|
|
2197
|
+
parentMessageId: message.id
|
|
2198
|
+
});
|
|
1934
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
|
+
});
|
|
1935
2208
|
}
|
|
1936
2209
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
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;
|
|
1942
2214
|
}
|
|
1943
2215
|
}
|
|
1944
|
-
const
|
|
1945
|
-
for (
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1949
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1950
|
-
if (!nextMessage) {
|
|
1951
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1952
|
-
continue;
|
|
1953
|
-
}
|
|
1954
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1955
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1956
|
-
if (toolMessage) {
|
|
1957
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1958
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1959
|
-
continue;
|
|
1960
|
-
} else {
|
|
1961
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1962
|
-
continue;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
correctedMessages.push(currentMessage);
|
|
1966
|
-
continue;
|
|
2216
|
+
const reorderedResult = [];
|
|
2217
|
+
for (const msg of result) {
|
|
2218
|
+
if (!("actionExecutionId" in msg)) {
|
|
2219
|
+
reorderedResult.push(msg);
|
|
1967
2220
|
}
|
|
1968
|
-
if ("
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
}
|
|
1973
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1974
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1975
|
-
continue;
|
|
2221
|
+
if ("arguments" in msg) {
|
|
2222
|
+
const msgId = msg.id;
|
|
2223
|
+
if (msgId in resultsDict) {
|
|
2224
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1976
2225
|
}
|
|
1977
|
-
correctedMessages.push(currentMessage);
|
|
1978
|
-
continue;
|
|
1979
2226
|
}
|
|
1980
|
-
correctedMessages.push(currentMessage);
|
|
1981
2227
|
}
|
|
1982
|
-
return
|
|
1983
|
-
...state,
|
|
1984
|
-
messages: correctedMessages,
|
|
1985
|
-
copilotkit: {
|
|
1986
|
-
actions
|
|
1987
|
-
}
|
|
1988
|
-
};
|
|
2228
|
+
return reorderedResult;
|
|
1989
2229
|
}
|
|
1990
|
-
__name(
|
|
1991
|
-
function
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
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;
|
|
2001
2253
|
}
|
|
2002
2254
|
if (message.isActionExecutionMessage()) {
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
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",
|
|
2010
2269
|
content: "",
|
|
2011
|
-
tool_calls
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
id: message.id
|
|
2016
|
-
};
|
|
2270
|
+
tool_calls,
|
|
2271
|
+
role: MessageRole.assistant
|
|
2272
|
+
});
|
|
2273
|
+
continue;
|
|
2017
2274
|
}
|
|
2018
2275
|
if (message.isResultMessage()) {
|
|
2019
|
-
|
|
2276
|
+
result.push({
|
|
2020
2277
|
type: message.type,
|
|
2021
2278
|
content: message.result,
|
|
2022
2279
|
id: message.id,
|
|
2023
2280
|
tool_call_id: message.actionExecutionId,
|
|
2024
2281
|
name: message.actionName,
|
|
2025
2282
|
role: MessageRole.tool
|
|
2026
|
-
};
|
|
2283
|
+
});
|
|
2284
|
+
continue;
|
|
2027
2285
|
}
|
|
2028
2286
|
throw new Error(`Unknown message type ${message.type}`);
|
|
2029
|
-
}
|
|
2287
|
+
}
|
|
2288
|
+
return result;
|
|
2030
2289
|
}
|
|
2031
|
-
__name(
|
|
2290
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2032
2291
|
|
|
2033
2292
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2034
2293
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -2038,7 +2297,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2038
2297
|
parameters: [],
|
|
2039
2298
|
handler: async (_args) => {
|
|
2040
2299
|
},
|
|
2041
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2300
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2042
2301
|
var _a;
|
|
2043
2302
|
logger2.debug({
|
|
2044
2303
|
actionName: agent.name
|
|
@@ -2064,7 +2323,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2064
2323
|
agent,
|
|
2065
2324
|
threadId,
|
|
2066
2325
|
nodeName,
|
|
2067
|
-
messages
|
|
2326
|
+
messages: [
|
|
2327
|
+
...messages,
|
|
2328
|
+
...additionalMessages
|
|
2329
|
+
],
|
|
2068
2330
|
state,
|
|
2069
2331
|
properties: graphqlContext.properties,
|
|
2070
2332
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2092,6 +2354,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2092
2354
|
}
|
|
2093
2355
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2094
2356
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2357
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2095
2358
|
const actions = json["actions"].map((action) => ({
|
|
2096
2359
|
name: action.name,
|
|
2097
2360
|
description: action.description,
|
|
@@ -2105,7 +2368,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2105
2368
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2106
2369
|
agentExecution: false,
|
|
2107
2370
|
type: "self-hosted",
|
|
2108
|
-
agentsAmount:
|
|
2371
|
+
agentsAmount: totalAgents
|
|
2109
2372
|
});
|
|
2110
2373
|
try {
|
|
2111
2374
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2140,13 +2403,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2140
2403
|
}
|
|
2141
2404
|
}
|
|
2142
2405
|
}));
|
|
2143
|
-
const agents = json["agents"].map((agent) => ({
|
|
2406
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
2144
2407
|
name: agent.name,
|
|
2145
2408
|
description: agent.description,
|
|
2146
2409
|
parameters: [],
|
|
2147
2410
|
handler: async (_args) => {
|
|
2148
2411
|
},
|
|
2149
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2412
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2150
2413
|
var _a;
|
|
2151
2414
|
logger2.debug({
|
|
2152
2415
|
actionName: agent.name
|
|
@@ -2171,7 +2434,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2171
2434
|
name,
|
|
2172
2435
|
threadId,
|
|
2173
2436
|
nodeName,
|
|
2174
|
-
messages
|
|
2437
|
+
messages: [
|
|
2438
|
+
...messages,
|
|
2439
|
+
...additionalMessages
|
|
2440
|
+
],
|
|
2175
2441
|
state,
|
|
2176
2442
|
properties: graphqlContext.properties,
|
|
2177
2443
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2193,7 +2459,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2193
2459
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2194
2460
|
return eventSource.processLangGraphEvents();
|
|
2195
2461
|
}
|
|
2196
|
-
}));
|
|
2462
|
+
})) : [];
|
|
2197
2463
|
return [
|
|
2198
2464
|
...actions,
|
|
2199
2465
|
...agents
|
|
@@ -2370,7 +2636,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2370
2636
|
// src/lib/telemetry-client.ts
|
|
2371
2637
|
var import_node_crypto3 = require("crypto");
|
|
2372
2638
|
var packageJson = require_package();
|
|
2373
|
-
var telemetryClient = new
|
|
2639
|
+
var telemetryClient = new import_shared10.TelemetryClient({
|
|
2374
2640
|
packageName: packageJson.name,
|
|
2375
2641
|
packageVersion: packageJson.version
|
|
2376
2642
|
});
|
|
@@ -2414,7 +2680,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2414
2680
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2415
2681
|
var telemetry_client_default = telemetryClient;
|
|
2416
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
|
+
|
|
2417
2769
|
// src/service-adapters/events.ts
|
|
2770
|
+
var import_class_transformer = require("class-transformer");
|
|
2418
2771
|
var RuntimeEventTypes;
|
|
2419
2772
|
(function(RuntimeEventTypes2) {
|
|
2420
2773
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2430,52 +2783,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2430
2783
|
constructor() {
|
|
2431
2784
|
super();
|
|
2432
2785
|
}
|
|
2433
|
-
sendTextMessageStart(messageId) {
|
|
2786
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2434
2787
|
this.next({
|
|
2435
2788
|
type: "TextMessageStart",
|
|
2436
|
-
messageId
|
|
2789
|
+
messageId,
|
|
2790
|
+
parentMessageId
|
|
2437
2791
|
});
|
|
2438
2792
|
}
|
|
2439
|
-
sendTextMessageContent(content) {
|
|
2793
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2440
2794
|
this.next({
|
|
2441
2795
|
type: "TextMessageContent",
|
|
2442
|
-
content
|
|
2796
|
+
content,
|
|
2797
|
+
messageId
|
|
2443
2798
|
});
|
|
2444
2799
|
}
|
|
2445
|
-
sendTextMessageEnd() {
|
|
2800
|
+
sendTextMessageEnd({ messageId }) {
|
|
2446
2801
|
this.next({
|
|
2447
|
-
type: "TextMessageEnd"
|
|
2802
|
+
type: "TextMessageEnd",
|
|
2803
|
+
messageId
|
|
2448
2804
|
});
|
|
2449
2805
|
}
|
|
2450
2806
|
sendTextMessage(messageId, content) {
|
|
2451
|
-
this.sendTextMessageStart(
|
|
2452
|
-
|
|
2453
|
-
|
|
2807
|
+
this.sendTextMessageStart({
|
|
2808
|
+
messageId
|
|
2809
|
+
});
|
|
2810
|
+
this.sendTextMessageContent({
|
|
2811
|
+
messageId,
|
|
2812
|
+
content
|
|
2813
|
+
});
|
|
2814
|
+
this.sendTextMessageEnd({
|
|
2815
|
+
messageId
|
|
2816
|
+
});
|
|
2454
2817
|
}
|
|
2455
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2818
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2456
2819
|
this.next({
|
|
2457
2820
|
type: "ActionExecutionStart",
|
|
2458
2821
|
actionExecutionId,
|
|
2459
|
-
actionName
|
|
2822
|
+
actionName,
|
|
2823
|
+
parentMessageId
|
|
2460
2824
|
});
|
|
2461
2825
|
}
|
|
2462
|
-
sendActionExecutionArgs(args) {
|
|
2826
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2463
2827
|
this.next({
|
|
2464
2828
|
type: "ActionExecutionArgs",
|
|
2465
|
-
args
|
|
2829
|
+
args,
|
|
2830
|
+
actionExecutionId
|
|
2466
2831
|
});
|
|
2467
2832
|
}
|
|
2468
|
-
sendActionExecutionEnd() {
|
|
2833
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2469
2834
|
this.next({
|
|
2470
|
-
type: "ActionExecutionEnd"
|
|
2835
|
+
type: "ActionExecutionEnd",
|
|
2836
|
+
actionExecutionId
|
|
2471
2837
|
});
|
|
2472
2838
|
}
|
|
2473
|
-
sendActionExecution(actionExecutionId,
|
|
2474
|
-
this.sendActionExecutionStart(
|
|
2475
|
-
|
|
2476
|
-
|
|
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
|
+
});
|
|
2477
2852
|
}
|
|
2478
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2853
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2479
2854
|
this.next({
|
|
2480
2855
|
type: "ActionExecutionResult",
|
|
2481
2856
|
actionName,
|
|
@@ -2483,7 +2858,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2483
2858
|
result
|
|
2484
2859
|
});
|
|
2485
2860
|
}
|
|
2486
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2861
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2487
2862
|
this.next({
|
|
2488
2863
|
type: "AgentStateMessage",
|
|
2489
2864
|
threadId,
|
|
@@ -2504,14 +2879,14 @@ var RuntimeEventSource = class {
|
|
|
2504
2879
|
async stream(callback) {
|
|
2505
2880
|
this.callback = callback;
|
|
2506
2881
|
}
|
|
2507
|
-
sendErrorMessageToChat() {
|
|
2508
|
-
const errorMessage =
|
|
2882
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2883
|
+
const errorMessage = `\u274C ${message}`;
|
|
2509
2884
|
if (!this.callback) {
|
|
2510
2885
|
this.stream(async (eventStream$) => {
|
|
2511
|
-
eventStream$.sendTextMessage((0,
|
|
2886
|
+
eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2512
2887
|
});
|
|
2513
2888
|
} else {
|
|
2514
|
-
this.eventStream$.sendTextMessage((0,
|
|
2889
|
+
this.eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2515
2890
|
}
|
|
2516
2891
|
}
|
|
2517
2892
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2520,27 +2895,19 @@ var RuntimeEventSource = class {
|
|
|
2520
2895
|
this.sendErrorMessageToChat();
|
|
2521
2896
|
});
|
|
2522
2897
|
return this.eventStream$.pipe(
|
|
2523
|
-
// mark tools for server side execution
|
|
2524
|
-
(0, import_rxjs2.map)((event) => {
|
|
2525
|
-
if (event.type === "ActionExecutionStart") {
|
|
2526
|
-
if (event.scope !== "passThrough") {
|
|
2527
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
return event;
|
|
2531
|
-
}),
|
|
2532
2898
|
// track state
|
|
2533
2899
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2534
2900
|
acc = {
|
|
2535
2901
|
...acc
|
|
2536
2902
|
};
|
|
2537
2903
|
if (event.type === "ActionExecutionStart") {
|
|
2538
|
-
acc.callActionServerSide =
|
|
2904
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2539
2905
|
acc.args = "";
|
|
2540
2906
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2541
2907
|
if (acc.callActionServerSide) {
|
|
2542
2908
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2543
2909
|
}
|
|
2910
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2544
2911
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2545
2912
|
acc.args += event.args;
|
|
2546
2913
|
}
|
|
@@ -2551,12 +2918,13 @@ var RuntimeEventSource = class {
|
|
|
2551
2918
|
callActionServerSide: false,
|
|
2552
2919
|
args: "",
|
|
2553
2920
|
actionExecutionId: null,
|
|
2554
|
-
action: null
|
|
2921
|
+
action: null,
|
|
2922
|
+
actionExecutionParentMessageId: null
|
|
2555
2923
|
}),
|
|
2556
2924
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2557
2925
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2558
2926
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2559
|
-
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) => {
|
|
2560
2928
|
console.error(error);
|
|
2561
2929
|
});
|
|
2562
2930
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2569,7 +2937,7 @@ var RuntimeEventSource = class {
|
|
|
2569
2937
|
}
|
|
2570
2938
|
};
|
|
2571
2939
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2572
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2940
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2573
2941
|
var _a;
|
|
2574
2942
|
if (guardrailsResult$) {
|
|
2575
2943
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2589,10 +2957,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2589
2957
|
}
|
|
2590
2958
|
}
|
|
2591
2959
|
if (isLangGraphAgentAction(action)) {
|
|
2592
|
-
|
|
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
|
+
});
|
|
2593
2980
|
const stream = await action.langGraphAgentHandler({
|
|
2594
2981
|
name: action.name,
|
|
2595
|
-
actionInputsWithoutAgents
|
|
2982
|
+
actionInputsWithoutAgents,
|
|
2983
|
+
additionalMessages: [
|
|
2984
|
+
agentExecution,
|
|
2985
|
+
agentExecutionResult
|
|
2986
|
+
]
|
|
2596
2987
|
});
|
|
2597
2988
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2598
2989
|
next: (event) => eventStream$.next(event),
|
|
@@ -2613,113 +3004,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2613
3004
|
}
|
|
2614
3005
|
__name(executeAction, "executeAction");
|
|
2615
3006
|
|
|
2616
|
-
// src/graphql/types/base/index.ts
|
|
2617
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2618
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2619
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2620
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2621
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2622
|
-
else
|
|
2623
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2624
|
-
if (d = decorators[i])
|
|
2625
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2626
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2627
|
-
}
|
|
2628
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
2629
|
-
function _ts_metadata(k, v) {
|
|
2630
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2631
|
-
return Reflect.metadata(k, v);
|
|
2632
|
-
}
|
|
2633
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
2634
|
-
var BaseMessageInput = class {
|
|
2635
|
-
id;
|
|
2636
|
-
createdAt;
|
|
2637
|
-
};
|
|
2638
|
-
__name(BaseMessageInput, "BaseMessageInput");
|
|
2639
|
-
_ts_decorate([
|
|
2640
|
-
(0, import_type_graphql2.Field)(() => String),
|
|
2641
|
-
_ts_metadata("design:type", String)
|
|
2642
|
-
], BaseMessageInput.prototype, "id", void 0);
|
|
2643
|
-
_ts_decorate([
|
|
2644
|
-
(0, import_type_graphql2.Field)(() => Date),
|
|
2645
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2646
|
-
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2647
|
-
BaseMessageInput = _ts_decorate([
|
|
2648
|
-
(0, import_type_graphql2.InputType)()
|
|
2649
|
-
], BaseMessageInput);
|
|
2650
|
-
|
|
2651
|
-
// src/graphql/types/converted/index.ts
|
|
2652
|
-
var Message = class extends BaseMessageInput {
|
|
2653
|
-
type;
|
|
2654
|
-
isTextMessage() {
|
|
2655
|
-
return this.type === "TextMessage";
|
|
2656
|
-
}
|
|
2657
|
-
isActionExecutionMessage() {
|
|
2658
|
-
return this.type === "ActionExecutionMessage";
|
|
2659
|
-
}
|
|
2660
|
-
isResultMessage() {
|
|
2661
|
-
return this.type === "ResultMessage";
|
|
2662
|
-
}
|
|
2663
|
-
isAgentStateMessage() {
|
|
2664
|
-
return this.type === "AgentStateMessage";
|
|
2665
|
-
}
|
|
2666
|
-
};
|
|
2667
|
-
__name(Message, "Message");
|
|
2668
|
-
var TextMessage = class extends Message {
|
|
2669
|
-
type = "TextMessage";
|
|
2670
|
-
content;
|
|
2671
|
-
role;
|
|
2672
|
-
};
|
|
2673
|
-
__name(TextMessage, "TextMessage");
|
|
2674
|
-
var ActionExecutionMessage = class extends Message {
|
|
2675
|
-
type = "ActionExecutionMessage";
|
|
2676
|
-
name;
|
|
2677
|
-
arguments;
|
|
2678
|
-
scope;
|
|
2679
|
-
};
|
|
2680
|
-
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2681
|
-
var ResultMessage = class extends Message {
|
|
2682
|
-
type = "ResultMessage";
|
|
2683
|
-
actionExecutionId;
|
|
2684
|
-
actionName;
|
|
2685
|
-
result;
|
|
2686
|
-
};
|
|
2687
|
-
__name(ResultMessage, "ResultMessage");
|
|
2688
|
-
var AgentStateMessage = class extends Message {
|
|
2689
|
-
type = "AgentStateMessage";
|
|
2690
|
-
threadId;
|
|
2691
|
-
agentName;
|
|
2692
|
-
nodeName;
|
|
2693
|
-
runId;
|
|
2694
|
-
active;
|
|
2695
|
-
role;
|
|
2696
|
-
state;
|
|
2697
|
-
running;
|
|
2698
|
-
};
|
|
2699
|
-
__name(AgentStateMessage, "AgentStateMessage");
|
|
2700
|
-
|
|
2701
3007
|
// src/service-adapters/conversion.ts
|
|
2702
|
-
var
|
|
3008
|
+
var import_class_transformer2 = require("class-transformer");
|
|
2703
3009
|
function convertGqlInputToMessages(inputMessages) {
|
|
2704
3010
|
const messages = [];
|
|
2705
3011
|
for (const message of inputMessages) {
|
|
2706
3012
|
if (message.textMessage) {
|
|
2707
|
-
messages.push((0,
|
|
3013
|
+
messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2708
3014
|
id: message.id,
|
|
2709
3015
|
createdAt: message.createdAt,
|
|
2710
3016
|
role: message.textMessage.role,
|
|
2711
|
-
content: message.textMessage.content
|
|
3017
|
+
content: message.textMessage.content,
|
|
3018
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2712
3019
|
}));
|
|
2713
3020
|
} else if (message.actionExecutionMessage) {
|
|
2714
|
-
messages.push((0,
|
|
3021
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2715
3022
|
id: message.id,
|
|
2716
3023
|
createdAt: message.createdAt,
|
|
2717
3024
|
name: message.actionExecutionMessage.name,
|
|
2718
3025
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2719
|
-
|
|
3026
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2720
3027
|
}));
|
|
2721
3028
|
} else if (message.resultMessage) {
|
|
2722
|
-
messages.push((0,
|
|
3029
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2723
3030
|
id: message.id,
|
|
2724
3031
|
createdAt: message.createdAt,
|
|
2725
3032
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2727,7 +3034,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2727
3034
|
result: message.resultMessage.result
|
|
2728
3035
|
}));
|
|
2729
3036
|
} else if (message.agentStateMessage) {
|
|
2730
|
-
messages.push((0,
|
|
3037
|
+
messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
2731
3038
|
id: message.id,
|
|
2732
3039
|
threadId: message.agentStateMessage.threadId,
|
|
2733
3040
|
createdAt: message.createdAt,
|
|
@@ -2778,7 +3085,7 @@ var CopilotRuntime = class {
|
|
|
2778
3085
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2779
3086
|
name: action.name,
|
|
2780
3087
|
description: action.description,
|
|
2781
|
-
jsonSchema: JSON.stringify((0,
|
|
3088
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2782
3089
|
}));
|
|
2783
3090
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2784
3091
|
...serverSideActionsInput,
|
|
@@ -2827,13 +3134,7 @@ var CopilotRuntime = class {
|
|
|
2827
3134
|
} catch (error) {
|
|
2828
3135
|
console.error("Error getting response:", error);
|
|
2829
3136
|
eventSource.sendErrorMessageToChat();
|
|
2830
|
-
|
|
2831
|
-
threadId: threadId || (0, import_shared10.randomId)(),
|
|
2832
|
-
runId: runId || (0, import_shared10.randomId)(),
|
|
2833
|
-
eventSource,
|
|
2834
|
-
serverSideActions: [],
|
|
2835
|
-
actionInputsWithoutAgents: []
|
|
2836
|
-
};
|
|
3137
|
+
throw error;
|
|
2837
3138
|
}
|
|
2838
3139
|
}
|
|
2839
3140
|
async processAgentRequest(request) {
|
|
@@ -2849,7 +3150,7 @@ var CopilotRuntime = class {
|
|
|
2849
3150
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2850
3151
|
name: action.name,
|
|
2851
3152
|
description: action.description,
|
|
2852
|
-
jsonSchema: JSON.stringify((0,
|
|
3153
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2853
3154
|
}));
|
|
2854
3155
|
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2855
3156
|
...serverSideActionsInput,
|
|
@@ -3036,6 +3337,7 @@ MessageInput = _ts_decorate2([
|
|
|
3036
3337
|
], MessageInput);
|
|
3037
3338
|
var TextMessageInput = class {
|
|
3038
3339
|
content;
|
|
3340
|
+
parentMessageId;
|
|
3039
3341
|
role;
|
|
3040
3342
|
};
|
|
3041
3343
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3043,6 +3345,12 @@ _ts_decorate2([
|
|
|
3043
3345
|
(0, import_type_graphql3.Field)(() => String),
|
|
3044
3346
|
_ts_metadata2("design:type", String)
|
|
3045
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);
|
|
3046
3354
|
_ts_decorate2([
|
|
3047
3355
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3048
3356
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3053,6 +3361,7 @@ TextMessageInput = _ts_decorate2([
|
|
|
3053
3361
|
var ActionExecutionMessageInput = class {
|
|
3054
3362
|
name;
|
|
3055
3363
|
arguments;
|
|
3364
|
+
parentMessageId;
|
|
3056
3365
|
scope;
|
|
3057
3366
|
};
|
|
3058
3367
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3065,8 +3374,17 @@ _ts_decorate2([
|
|
|
3065
3374
|
_ts_metadata2("design:type", String)
|
|
3066
3375
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3067
3376
|
_ts_decorate2([
|
|
3068
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3069
|
-
|
|
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)
|
|
3070
3388
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3071
3389
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3072
3390
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3074,6 +3392,7 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3074
3392
|
var ResultMessageInput = class {
|
|
3075
3393
|
actionExecutionId;
|
|
3076
3394
|
actionName;
|
|
3395
|
+
parentMessageId;
|
|
3077
3396
|
result;
|
|
3078
3397
|
};
|
|
3079
3398
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3085,6 +3404,12 @@ _ts_decorate2([
|
|
|
3085
3404
|
(0, import_type_graphql3.Field)(() => String),
|
|
3086
3405
|
_ts_metadata2("design:type", String)
|
|
3087
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);
|
|
3088
3413
|
_ts_decorate2([
|
|
3089
3414
|
(0, import_type_graphql3.Field)(() => String),
|
|
3090
3415
|
_ts_metadata2("design:type", String)
|
|
@@ -3807,6 +4132,7 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3807
4132
|
var TextMessageOutput = class {
|
|
3808
4133
|
role;
|
|
3809
4134
|
content;
|
|
4135
|
+
parentMessageId;
|
|
3810
4136
|
};
|
|
3811
4137
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3812
4138
|
_ts_decorate13([
|
|
@@ -3819,6 +4145,12 @@ _ts_decorate13([
|
|
|
3819
4145
|
]),
|
|
3820
4146
|
_ts_metadata13("design:type", Array)
|
|
3821
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);
|
|
3822
4154
|
TextMessageOutput = _ts_decorate13([
|
|
3823
4155
|
(0, import_type_graphql14.ObjectType)({
|
|
3824
4156
|
implements: BaseMessageOutput
|
|
@@ -3828,6 +4160,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
3828
4160
|
name;
|
|
3829
4161
|
scope;
|
|
3830
4162
|
arguments;
|
|
4163
|
+
parentMessageId;
|
|
3831
4164
|
};
|
|
3832
4165
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3833
4166
|
_ts_decorate13([
|
|
@@ -3835,8 +4168,11 @@ _ts_decorate13([
|
|
|
3835
4168
|
_ts_metadata13("design:type", String)
|
|
3836
4169
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3837
4170
|
_ts_decorate13([
|
|
3838
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3839
|
-
|
|
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)
|
|
3840
4176
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3841
4177
|
_ts_decorate13([
|
|
3842
4178
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3844,6 +4180,12 @@ _ts_decorate13([
|
|
|
3844
4180
|
]),
|
|
3845
4181
|
_ts_metadata13("design:type", Array)
|
|
3846
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);
|
|
3847
4189
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3848
4190
|
(0, import_type_graphql14.ObjectType)({
|
|
3849
4191
|
implements: BaseMessageOutput
|
|
@@ -3954,7 +4296,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3954
4296
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3955
4297
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3956
4298
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3957
|
-
var
|
|
4299
|
+
var import_class_transformer3 = require("class-transformer");
|
|
3958
4300
|
var import_graphql = require("graphql");
|
|
3959
4301
|
|
|
3960
4302
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -3991,7 +4333,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
3991
4333
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
3992
4334
|
|
|
3993
4335
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3994
|
-
var
|
|
4336
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
3995
4337
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
3996
4338
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3997
4339
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4108,7 +4450,7 @@ var CopilotResolver = class {
|
|
|
4108
4450
|
rejectOutputMessagesPromise = reject;
|
|
4109
4451
|
});
|
|
4110
4452
|
logger2.debug("Processing");
|
|
4111
|
-
const { eventSource, threadId = (0,
|
|
4453
|
+
const { eventSource, threadId = (0, import_shared13.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
4112
4454
|
serviceAdapter,
|
|
4113
4455
|
messages: data.messages,
|
|
4114
4456
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -4152,8 +4494,8 @@ var CopilotResolver = class {
|
|
|
4152
4494
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4153
4495
|
});
|
|
4154
4496
|
outputMessages = [
|
|
4155
|
-
(0,
|
|
4156
|
-
id: (0,
|
|
4497
|
+
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4498
|
+
id: (0, import_shared13.randomId)(),
|
|
4157
4499
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4158
4500
|
content: result.reason,
|
|
4159
4501
|
role: MessageRole.assistant
|
|
@@ -4201,12 +4543,15 @@ var CopilotResolver = class {
|
|
|
4201
4543
|
// skip until this message start event
|
|
4202
4544
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4203
4545
|
// take until the message end event
|
|
4204
|
-
(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)
|
|
4205
4549
|
);
|
|
4206
4550
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4207
4551
|
const messageId = event.messageId;
|
|
4208
4552
|
pushMessage({
|
|
4209
4553
|
id: messageId,
|
|
4554
|
+
parentMessageId: event.parentMessageId,
|
|
4210
4555
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4211
4556
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4212
4557
|
role: MessageRole.assistant,
|
|
@@ -4219,7 +4564,7 @@ var CopilotResolver = class {
|
|
|
4219
4564
|
reason,
|
|
4220
4565
|
messageId: messageId2
|
|
4221
4566
|
}, "Text streaming interrupted");
|
|
4222
|
-
streamingTextStatus.next((0,
|
|
4567
|
+
streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4223
4568
|
reason
|
|
4224
4569
|
}));
|
|
4225
4570
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4252,7 +4597,7 @@ var CopilotResolver = class {
|
|
|
4252
4597
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4253
4598
|
stopStreamingText();
|
|
4254
4599
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4255
|
-
outputMessages.push((0,
|
|
4600
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4256
4601
|
id: messageId,
|
|
4257
4602
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4258
4603
|
content: textChunks.join(""),
|
|
@@ -4265,14 +4610,20 @@ var CopilotResolver = class {
|
|
|
4265
4610
|
break;
|
|
4266
4611
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4267
4612
|
logger2.debug("Action execution start event received");
|
|
4268
|
-
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
|
+
);
|
|
4269
4620
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4270
4621
|
pushMessage({
|
|
4271
4622
|
id: event.actionExecutionId,
|
|
4623
|
+
parentMessageId: event.parentMessageId,
|
|
4272
4624
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4273
4625
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4274
4626
|
name: event.actionName,
|
|
4275
|
-
scope: event.scope,
|
|
4276
4627
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4277
4628
|
logger2.debug("Action execution argument stream created");
|
|
4278
4629
|
const argumentChunks = [];
|
|
@@ -4288,7 +4639,7 @@ var CopilotResolver = class {
|
|
|
4288
4639
|
logger2.error({
|
|
4289
4640
|
err
|
|
4290
4641
|
}, "Error in action execution argument stream");
|
|
4291
|
-
streamingArgumentsStatus.next((0,
|
|
4642
|
+
streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4292
4643
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4293
4644
|
}));
|
|
4294
4645
|
stopStreamingArguments();
|
|
@@ -4299,11 +4650,10 @@ var CopilotResolver = class {
|
|
|
4299
4650
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4300
4651
|
stopStreamingArguments();
|
|
4301
4652
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4302
|
-
outputMessages.push((0,
|
|
4653
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
|
|
4303
4654
|
id: event.actionExecutionId,
|
|
4304
4655
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4305
4656
|
name: event.actionName,
|
|
4306
|
-
scope: event.scope,
|
|
4307
4657
|
arguments: argumentChunks.join("")
|
|
4308
4658
|
}));
|
|
4309
4659
|
}
|
|
@@ -4316,15 +4666,15 @@ var CopilotResolver = class {
|
|
|
4316
4666
|
result: event.result
|
|
4317
4667
|
}, "Action execution result event received");
|
|
4318
4668
|
pushMessage({
|
|
4319
|
-
id:
|
|
4669
|
+
id: "result-" + event.actionExecutionId,
|
|
4320
4670
|
status: new SuccessMessageStatus(),
|
|
4321
4671
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4322
4672
|
actionExecutionId: event.actionExecutionId,
|
|
4323
4673
|
actionName: event.actionName,
|
|
4324
4674
|
result: event.result
|
|
4325
4675
|
});
|
|
4326
|
-
outputMessages.push((0,
|
|
4327
|
-
id:
|
|
4676
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
|
|
4677
|
+
id: "result-" + event.actionExecutionId,
|
|
4328
4678
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4329
4679
|
actionExecutionId: event.actionExecutionId,
|
|
4330
4680
|
actionName: event.actionName,
|
|
@@ -4336,7 +4686,7 @@ var CopilotResolver = class {
|
|
|
4336
4686
|
event
|
|
4337
4687
|
}, "Agent message event received");
|
|
4338
4688
|
pushMessage({
|
|
4339
|
-
id: (0,
|
|
4689
|
+
id: (0, import_shared13.randomId)(),
|
|
4340
4690
|
status: new SuccessMessageStatus(),
|
|
4341
4691
|
threadId: event.threadId,
|
|
4342
4692
|
agentName: event.agentName,
|
|
@@ -4348,8 +4698,8 @@ var CopilotResolver = class {
|
|
|
4348
4698
|
role: MessageRole.assistant,
|
|
4349
4699
|
createdAt: /* @__PURE__ */ new Date()
|
|
4350
4700
|
});
|
|
4351
|
-
outputMessages.push((0,
|
|
4352
|
-
id: (0,
|
|
4701
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
4702
|
+
id: (0, import_shared13.randomId)(),
|
|
4353
4703
|
threadId: event.threadId,
|
|
4354
4704
|
agentName: event.agentName,
|
|
4355
4705
|
nodeName: event.nodeName,
|
|
@@ -4640,6 +4990,8 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4640
4990
|
0 && (module.exports = {
|
|
4641
4991
|
AnthropicAdapter,
|
|
4642
4992
|
CopilotRuntime,
|
|
4993
|
+
ExperimentalEmptyAdapter,
|
|
4994
|
+
ExperimentalOllamaAdapter,
|
|
4643
4995
|
GoogleGenerativeAIAdapter,
|
|
4644
4996
|
GroqAdapter,
|
|
4645
4997
|
GuardrailsValidationFailureResponse,
|