@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.1-custom-tag-pre.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 +150 -3
- package/__snapshots__/schema/schema.graphql +8 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-3ECBC2K2.mjs} +462 -328
- package/dist/chunk-3ECBC2K2.mjs.map +1 -0
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-5E6LOP76.mjs} +2 -2
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-CLGKEUOA.mjs} +298 -63
- package/dist/chunk-CLGKEUOA.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-MKDG5ZHT.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-MYZB2EKG.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-6285d897.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-15d41154.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 +852 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-48e976ac.d.ts} +54 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +754 -459
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +78 -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 +78 -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 +78 -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 +78 -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 +298 -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/forwarded-parameters.input.ts +3 -0
- 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 +17 -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 +24 -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 +23 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +30 -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-QNQ6UT3D.mjs.map → chunk-5E6LOP76.mjs.map} +0 -0
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-MKDG5ZHT.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-MYZB2EKG.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.
|
|
47
|
+
version: "1.5.1-custom-tag-pre.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");
|
|
@@ -425,11 +427,16 @@ var OpenAIAdapter = class {
|
|
|
425
427
|
},
|
|
426
428
|
...this.disableParallelToolCalls && {
|
|
427
429
|
parallel_tool_calls: false
|
|
430
|
+
},
|
|
431
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
432
|
+
temperature: forwardedParameters.temperature
|
|
428
433
|
}
|
|
429
434
|
});
|
|
430
435
|
eventSource.stream(async (eventStream$) => {
|
|
431
436
|
var _a, _b;
|
|
432
437
|
let mode = null;
|
|
438
|
+
let currentMessageId;
|
|
439
|
+
let currentToolCallId;
|
|
433
440
|
for await (const chunk of stream) {
|
|
434
441
|
if (chunk.choices.length === 0) {
|
|
435
442
|
continue;
|
|
@@ -438,30 +445,52 @@ var OpenAIAdapter = class {
|
|
|
438
445
|
const content = chunk.choices[0].delta.content;
|
|
439
446
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
440
447
|
mode = null;
|
|
441
|
-
eventStream$.sendTextMessageEnd(
|
|
448
|
+
eventStream$.sendTextMessageEnd({
|
|
449
|
+
messageId: currentMessageId
|
|
450
|
+
});
|
|
442
451
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
443
452
|
mode = null;
|
|
444
|
-
eventStream$.sendActionExecutionEnd(
|
|
453
|
+
eventStream$.sendActionExecutionEnd({
|
|
454
|
+
actionExecutionId: currentToolCallId
|
|
455
|
+
});
|
|
445
456
|
}
|
|
446
457
|
if (mode === null) {
|
|
447
458
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
448
459
|
mode = "function";
|
|
449
|
-
|
|
460
|
+
currentToolCallId = toolCall.id;
|
|
461
|
+
eventStream$.sendActionExecutionStart({
|
|
462
|
+
actionExecutionId: currentToolCallId,
|
|
463
|
+
parentMessageId: chunk.id,
|
|
464
|
+
actionName: toolCall.function.name
|
|
465
|
+
});
|
|
450
466
|
} else if (content) {
|
|
451
467
|
mode = "message";
|
|
452
|
-
|
|
468
|
+
currentMessageId = chunk.id;
|
|
469
|
+
eventStream$.sendTextMessageStart({
|
|
470
|
+
messageId: currentMessageId
|
|
471
|
+
});
|
|
453
472
|
}
|
|
454
473
|
}
|
|
455
474
|
if (mode === "message" && content) {
|
|
456
|
-
eventStream$.sendTextMessageContent(
|
|
475
|
+
eventStream$.sendTextMessageContent({
|
|
476
|
+
messageId: currentMessageId,
|
|
477
|
+
content
|
|
478
|
+
});
|
|
457
479
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
458
|
-
eventStream$.sendActionExecutionArgs(
|
|
480
|
+
eventStream$.sendActionExecutionArgs({
|
|
481
|
+
actionExecutionId: currentToolCallId,
|
|
482
|
+
args: toolCall.function.arguments
|
|
483
|
+
});
|
|
459
484
|
}
|
|
460
485
|
}
|
|
461
486
|
if (mode === "message") {
|
|
462
|
-
eventStream$.sendTextMessageEnd(
|
|
487
|
+
eventStream$.sendTextMessageEnd({
|
|
488
|
+
messageId: currentMessageId
|
|
489
|
+
});
|
|
463
490
|
} else if (mode === "function") {
|
|
464
|
-
eventStream$.sendActionExecutionEnd(
|
|
491
|
+
eventStream$.sendActionExecutionEnd({
|
|
492
|
+
actionExecutionId: currentToolCallId
|
|
493
|
+
});
|
|
465
494
|
}
|
|
466
495
|
eventStream$.complete();
|
|
467
496
|
});
|
|
@@ -529,17 +558,25 @@ function isBaseMessageChunk(message) {
|
|
|
529
558
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
530
559
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
531
560
|
if (actionExecution) {
|
|
532
|
-
eventStream$.sendActionExecutionResult(
|
|
561
|
+
eventStream$.sendActionExecutionResult({
|
|
562
|
+
actionExecutionId: actionExecution.id,
|
|
563
|
+
actionName: actionExecution.name,
|
|
564
|
+
result: "Sending a message"
|
|
565
|
+
});
|
|
533
566
|
}
|
|
534
567
|
}
|
|
535
568
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
536
569
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
537
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
570
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
538
571
|
if (typeof result === "string") {
|
|
539
572
|
if (!actionExecution) {
|
|
540
573
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
541
574
|
} else {
|
|
542
|
-
eventStream$.sendActionExecutionResult(
|
|
575
|
+
eventStream$.sendActionExecutionResult({
|
|
576
|
+
actionExecutionId: actionExecution.id,
|
|
577
|
+
actionName: actionExecution.name,
|
|
578
|
+
result
|
|
579
|
+
});
|
|
543
580
|
}
|
|
544
581
|
} else if (isAIMessage(result)) {
|
|
545
582
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -547,7 +584,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
547
584
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
548
585
|
}
|
|
549
586
|
for (const toolCall of result.tool_calls) {
|
|
550
|
-
eventStream$.sendActionExecution(
|
|
587
|
+
eventStream$.sendActionExecution({
|
|
588
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
589
|
+
actionName: toolCall.name,
|
|
590
|
+
args: JSON.stringify(toolCall.args)
|
|
591
|
+
});
|
|
551
592
|
}
|
|
552
593
|
} else if (isBaseMessageChunk(result)) {
|
|
553
594
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -556,13 +597,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
556
597
|
}
|
|
557
598
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
558
599
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
559
|
-
eventStream$.sendActionExecution(
|
|
600
|
+
eventStream$.sendActionExecution({
|
|
601
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
602
|
+
actionName: toolCall.name,
|
|
603
|
+
args: JSON.stringify(toolCall.args)
|
|
604
|
+
});
|
|
560
605
|
}
|
|
561
606
|
}
|
|
562
607
|
} else if (result && "getReader" in result) {
|
|
563
608
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
564
609
|
let reader = result.getReader();
|
|
565
610
|
let mode = null;
|
|
611
|
+
let currentMessageId;
|
|
566
612
|
const toolCallDetails = {
|
|
567
613
|
name: null,
|
|
568
614
|
id: null,
|
|
@@ -576,9 +622,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
576
622
|
let toolCallId = void 0;
|
|
577
623
|
let toolCallArgs = void 0;
|
|
578
624
|
let hasToolCall = false;
|
|
579
|
-
let content =
|
|
625
|
+
let content = "";
|
|
626
|
+
if (value && value.content) {
|
|
627
|
+
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
628
|
+
}
|
|
580
629
|
if (isAIMessageChunk(value)) {
|
|
581
|
-
let chunk = (
|
|
630
|
+
let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
|
|
582
631
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
583
632
|
hasToolCall = chunk != void 0;
|
|
584
633
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -593,18 +642,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
593
642
|
toolCallName = toolCallDetails.name;
|
|
594
643
|
toolCallId = toolCallDetails.id;
|
|
595
644
|
} else if (isBaseMessageChunk(value)) {
|
|
596
|
-
let chunk = (
|
|
597
|
-
toolCallName = (
|
|
645
|
+
let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
|
|
646
|
+
toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
|
|
598
647
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
599
|
-
toolCallArgs = (
|
|
648
|
+
toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
|
|
600
649
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
601
650
|
}
|
|
602
651
|
if (mode === "message" && (toolCallId || done)) {
|
|
603
652
|
mode = null;
|
|
604
|
-
eventStream$.sendTextMessageEnd(
|
|
653
|
+
eventStream$.sendTextMessageEnd({
|
|
654
|
+
messageId: currentMessageId
|
|
655
|
+
});
|
|
605
656
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
606
657
|
mode = null;
|
|
607
|
-
eventStream$.sendActionExecutionEnd(
|
|
658
|
+
eventStream$.sendActionExecutionEnd({
|
|
659
|
+
actionExecutionId: toolCallId
|
|
660
|
+
});
|
|
608
661
|
}
|
|
609
662
|
if (done) {
|
|
610
663
|
break;
|
|
@@ -612,21 +665,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
612
665
|
if (mode === null) {
|
|
613
666
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
614
667
|
mode = "function";
|
|
615
|
-
eventStream$.sendActionExecutionStart(
|
|
668
|
+
eventStream$.sendActionExecutionStart({
|
|
669
|
+
actionExecutionId: toolCallId,
|
|
670
|
+
actionName: toolCallName,
|
|
671
|
+
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
672
|
+
});
|
|
616
673
|
} else if (content) {
|
|
617
674
|
mode = "message";
|
|
618
|
-
|
|
675
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared2.randomId)();
|
|
676
|
+
eventStream$.sendTextMessageStart({
|
|
677
|
+
messageId: currentMessageId
|
|
678
|
+
});
|
|
619
679
|
}
|
|
620
680
|
}
|
|
621
681
|
if (mode === "message" && content) {
|
|
622
|
-
eventStream$.sendTextMessageContent(
|
|
682
|
+
eventStream$.sendTextMessageContent({
|
|
683
|
+
messageId: currentMessageId,
|
|
684
|
+
content
|
|
685
|
+
});
|
|
623
686
|
} else if (mode === "function" && toolCallArgs) {
|
|
624
687
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
625
|
-
eventStream$.sendActionExecutionEnd(
|
|
626
|
-
|
|
688
|
+
eventStream$.sendActionExecutionEnd({
|
|
689
|
+
actionExecutionId: toolCallId
|
|
690
|
+
});
|
|
691
|
+
eventStream$.sendActionExecutionStart({
|
|
692
|
+
actionExecutionId: toolCallId,
|
|
693
|
+
actionName: toolCallName,
|
|
694
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
695
|
+
});
|
|
627
696
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
628
697
|
}
|
|
629
|
-
eventStream$.sendActionExecutionArgs(
|
|
698
|
+
eventStream$.sendActionExecutionArgs({
|
|
699
|
+
actionExecutionId: toolCallId,
|
|
700
|
+
args: toolCallArgs
|
|
701
|
+
});
|
|
630
702
|
}
|
|
631
703
|
} catch (error) {
|
|
632
704
|
console.error("Error reading from stream", error);
|
|
@@ -634,7 +706,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
634
706
|
}
|
|
635
707
|
}
|
|
636
708
|
} else if (actionExecution) {
|
|
637
|
-
eventStream$.sendActionExecutionResult(
|
|
709
|
+
eventStream$.sendActionExecutionResult({
|
|
710
|
+
actionExecutionId: actionExecution.id,
|
|
711
|
+
actionName: actionExecution.name,
|
|
712
|
+
result: encodeResult(result)
|
|
713
|
+
});
|
|
638
714
|
} else {
|
|
639
715
|
throw new Error("Invalid return type from LangChain function.");
|
|
640
716
|
}
|
|
@@ -814,21 +890,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
814
890
|
eventSource.stream(async (eventStream$) => {
|
|
815
891
|
var _a, _b, _c, _d, _e, _f;
|
|
816
892
|
let inFunctionCall = false;
|
|
893
|
+
let currentMessageId;
|
|
894
|
+
let currentToolCallId;
|
|
817
895
|
for await (const chunk of stream) {
|
|
818
896
|
switch (chunk.event) {
|
|
819
897
|
case "thread.message.created":
|
|
820
898
|
if (inFunctionCall) {
|
|
821
|
-
eventStream$.sendActionExecutionEnd(
|
|
899
|
+
eventStream$.sendActionExecutionEnd({
|
|
900
|
+
actionExecutionId: currentToolCallId
|
|
901
|
+
});
|
|
822
902
|
}
|
|
823
|
-
|
|
903
|
+
currentMessageId = chunk.data.id;
|
|
904
|
+
eventStream$.sendTextMessageStart({
|
|
905
|
+
messageId: currentMessageId
|
|
906
|
+
});
|
|
824
907
|
break;
|
|
825
908
|
case "thread.message.delta":
|
|
826
909
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
827
|
-
eventStream$.sendTextMessageContent(
|
|
910
|
+
eventStream$.sendTextMessageContent({
|
|
911
|
+
messageId: currentMessageId,
|
|
912
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
913
|
+
});
|
|
828
914
|
}
|
|
829
915
|
break;
|
|
830
916
|
case "thread.message.completed":
|
|
831
|
-
eventStream$.sendTextMessageEnd(
|
|
917
|
+
eventStream$.sendTextMessageEnd({
|
|
918
|
+
messageId: currentMessageId
|
|
919
|
+
});
|
|
832
920
|
break;
|
|
833
921
|
case "thread.run.step.delta":
|
|
834
922
|
let toolCallId;
|
|
@@ -841,18 +929,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
841
929
|
}
|
|
842
930
|
if (toolCallName && toolCallId) {
|
|
843
931
|
if (inFunctionCall) {
|
|
844
|
-
eventStream$.sendActionExecutionEnd(
|
|
932
|
+
eventStream$.sendActionExecutionEnd({
|
|
933
|
+
actionExecutionId: currentToolCallId
|
|
934
|
+
});
|
|
845
935
|
}
|
|
846
936
|
inFunctionCall = true;
|
|
847
|
-
|
|
937
|
+
currentToolCallId = toolCallId;
|
|
938
|
+
eventStream$.sendActionExecutionStart({
|
|
939
|
+
actionExecutionId: currentToolCallId,
|
|
940
|
+
parentMessageId: chunk.data.id,
|
|
941
|
+
actionName: toolCallName
|
|
942
|
+
});
|
|
848
943
|
} else if (toolCallArgs) {
|
|
849
|
-
eventStream$.sendActionExecutionArgs(
|
|
944
|
+
eventStream$.sendActionExecutionArgs({
|
|
945
|
+
actionExecutionId: currentToolCallId,
|
|
946
|
+
args: toolCallArgs
|
|
947
|
+
});
|
|
850
948
|
}
|
|
851
949
|
break;
|
|
852
950
|
}
|
|
853
951
|
}
|
|
854
952
|
if (inFunctionCall) {
|
|
855
|
-
eventStream$.sendActionExecutionEnd(
|
|
953
|
+
eventStream$.sendActionExecutionEnd({
|
|
954
|
+
actionExecutionId: currentToolCallId
|
|
955
|
+
});
|
|
856
956
|
}
|
|
857
957
|
eventStream$.complete();
|
|
858
958
|
});
|
|
@@ -895,6 +995,7 @@ var UnifyAdapter = class {
|
|
|
895
995
|
apiKey: this.apiKey,
|
|
896
996
|
baseURL: "https://api.unify.ai/v0/"
|
|
897
997
|
});
|
|
998
|
+
const forwardedParameters = request.forwardedParameters;
|
|
898
999
|
const messages = request.messages.map(convertMessageToOpenAIMessage);
|
|
899
1000
|
const stream = await openai.chat.completions.create({
|
|
900
1001
|
model: this.model,
|
|
@@ -902,49 +1003,83 @@ var UnifyAdapter = class {
|
|
|
902
1003
|
stream: true,
|
|
903
1004
|
...tools.length > 0 && {
|
|
904
1005
|
tools
|
|
1006
|
+
},
|
|
1007
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
1008
|
+
temperature: forwardedParameters.temperature
|
|
905
1009
|
}
|
|
906
1010
|
});
|
|
907
1011
|
let model = null;
|
|
1012
|
+
let currentMessageId;
|
|
1013
|
+
let currentToolCallId;
|
|
908
1014
|
request.eventSource.stream(async (eventStream$) => {
|
|
909
1015
|
var _a, _b;
|
|
910
1016
|
let mode = null;
|
|
911
1017
|
for await (const chunk of stream) {
|
|
912
1018
|
if (this.start) {
|
|
913
1019
|
model = chunk.model;
|
|
914
|
-
|
|
915
|
-
eventStream$.
|
|
916
|
-
|
|
917
|
-
|
|
1020
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
1021
|
+
eventStream$.sendTextMessageStart({
|
|
1022
|
+
messageId: currentMessageId
|
|
1023
|
+
});
|
|
1024
|
+
eventStream$.sendTextMessageContent({
|
|
1025
|
+
messageId: currentMessageId,
|
|
1026
|
+
content: `Model used: ${model}
|
|
1027
|
+
`
|
|
1028
|
+
});
|
|
1029
|
+
eventStream$.sendTextMessageEnd({
|
|
1030
|
+
messageId: currentMessageId
|
|
1031
|
+
});
|
|
918
1032
|
this.start = false;
|
|
919
1033
|
}
|
|
920
1034
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
921
1035
|
const content = chunk.choices[0].delta.content;
|
|
922
1036
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
923
1037
|
mode = null;
|
|
924
|
-
eventStream$.sendTextMessageEnd(
|
|
1038
|
+
eventStream$.sendTextMessageEnd({
|
|
1039
|
+
messageId: currentMessageId
|
|
1040
|
+
});
|
|
925
1041
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
926
1042
|
mode = null;
|
|
927
|
-
eventStream$.sendActionExecutionEnd(
|
|
1043
|
+
eventStream$.sendActionExecutionEnd({
|
|
1044
|
+
actionExecutionId: currentToolCallId
|
|
1045
|
+
});
|
|
928
1046
|
}
|
|
929
1047
|
if (mode === null) {
|
|
930
1048
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
931
1049
|
mode = "function";
|
|
932
|
-
|
|
1050
|
+
currentToolCallId = toolCall.id;
|
|
1051
|
+
eventStream$.sendActionExecutionStart({
|
|
1052
|
+
actionExecutionId: currentToolCallId,
|
|
1053
|
+
actionName: toolCall.function.name
|
|
1054
|
+
});
|
|
933
1055
|
} else if (content) {
|
|
934
1056
|
mode = "message";
|
|
935
|
-
|
|
1057
|
+
currentMessageId = chunk.id;
|
|
1058
|
+
eventStream$.sendTextMessageStart({
|
|
1059
|
+
messageId: currentMessageId
|
|
1060
|
+
});
|
|
936
1061
|
}
|
|
937
1062
|
}
|
|
938
1063
|
if (mode === "message" && content) {
|
|
939
|
-
eventStream$.sendTextMessageContent(
|
|
1064
|
+
eventStream$.sendTextMessageContent({
|
|
1065
|
+
messageId: currentMessageId,
|
|
1066
|
+
content
|
|
1067
|
+
});
|
|
940
1068
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
941
|
-
eventStream$.sendActionExecutionArgs(
|
|
1069
|
+
eventStream$.sendActionExecutionArgs({
|
|
1070
|
+
actionExecutionId: currentToolCallId,
|
|
1071
|
+
args: toolCall.function.arguments
|
|
1072
|
+
});
|
|
942
1073
|
}
|
|
943
1074
|
}
|
|
944
1075
|
if (mode === "message") {
|
|
945
|
-
eventStream$.sendTextMessageEnd(
|
|
1076
|
+
eventStream$.sendTextMessageEnd({
|
|
1077
|
+
messageId: currentMessageId
|
|
1078
|
+
});
|
|
946
1079
|
} else if (mode === "function") {
|
|
947
|
-
eventStream$.sendActionExecutionEnd(
|
|
1080
|
+
eventStream$.sendActionExecutionEnd({
|
|
1081
|
+
actionExecutionId: currentToolCallId
|
|
1082
|
+
});
|
|
948
1083
|
}
|
|
949
1084
|
eventStream$.complete();
|
|
950
1085
|
});
|
|
@@ -1005,40 +1140,67 @@ var GroqAdapter = class {
|
|
|
1005
1140
|
},
|
|
1006
1141
|
...this.disableParallelToolCalls && {
|
|
1007
1142
|
parallel_tool_calls: false
|
|
1143
|
+
},
|
|
1144
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
1145
|
+
temperature: forwardedParameters.temperature
|
|
1008
1146
|
}
|
|
1009
1147
|
});
|
|
1010
1148
|
eventSource.stream(async (eventStream$) => {
|
|
1011
1149
|
var _a, _b;
|
|
1012
1150
|
let mode = null;
|
|
1151
|
+
let currentMessageId;
|
|
1152
|
+
let currentToolCallId;
|
|
1013
1153
|
for await (const chunk of stream) {
|
|
1014
1154
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1015
1155
|
const content = chunk.choices[0].delta.content;
|
|
1016
1156
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1017
1157
|
mode = null;
|
|
1018
|
-
eventStream$.sendTextMessageEnd(
|
|
1158
|
+
eventStream$.sendTextMessageEnd({
|
|
1159
|
+
messageId: currentMessageId
|
|
1160
|
+
});
|
|
1019
1161
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1020
1162
|
mode = null;
|
|
1021
|
-
eventStream$.sendActionExecutionEnd(
|
|
1163
|
+
eventStream$.sendActionExecutionEnd({
|
|
1164
|
+
actionExecutionId: currentToolCallId
|
|
1165
|
+
});
|
|
1022
1166
|
}
|
|
1023
1167
|
if (mode === null) {
|
|
1024
1168
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1025
1169
|
mode = "function";
|
|
1026
|
-
|
|
1170
|
+
currentToolCallId = toolCall.id;
|
|
1171
|
+
eventStream$.sendActionExecutionStart({
|
|
1172
|
+
actionExecutionId: currentToolCallId,
|
|
1173
|
+
actionName: toolCall.function.name,
|
|
1174
|
+
parentMessageId: chunk.id
|
|
1175
|
+
});
|
|
1027
1176
|
} else if (content) {
|
|
1028
1177
|
mode = "message";
|
|
1029
|
-
|
|
1178
|
+
currentMessageId = chunk.id;
|
|
1179
|
+
eventStream$.sendTextMessageStart({
|
|
1180
|
+
messageId: currentMessageId
|
|
1181
|
+
});
|
|
1030
1182
|
}
|
|
1031
1183
|
}
|
|
1032
1184
|
if (mode === "message" && content) {
|
|
1033
|
-
eventStream$.sendTextMessageContent(
|
|
1185
|
+
eventStream$.sendTextMessageContent({
|
|
1186
|
+
messageId: currentMessageId,
|
|
1187
|
+
content
|
|
1188
|
+
});
|
|
1034
1189
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1035
|
-
eventStream$.sendActionExecutionArgs(
|
|
1190
|
+
eventStream$.sendActionExecutionArgs({
|
|
1191
|
+
actionExecutionId: currentToolCallId,
|
|
1192
|
+
args: toolCall.function.arguments
|
|
1193
|
+
});
|
|
1036
1194
|
}
|
|
1037
1195
|
}
|
|
1038
1196
|
if (mode === "message") {
|
|
1039
|
-
eventStream$.sendTextMessageEnd(
|
|
1197
|
+
eventStream$.sendTextMessageEnd({
|
|
1198
|
+
messageId: currentMessageId
|
|
1199
|
+
});
|
|
1040
1200
|
} else if (mode === "function") {
|
|
1041
|
-
eventStream$.sendActionExecutionEnd(
|
|
1201
|
+
eventStream$.sendActionExecutionEnd({
|
|
1202
|
+
actionExecutionId: currentToolCallId
|
|
1203
|
+
});
|
|
1042
1204
|
}
|
|
1043
1205
|
eventStream$.complete();
|
|
1044
1206
|
});
|
|
@@ -1222,6 +1384,9 @@ var AnthropicAdapter = class {
|
|
|
1222
1384
|
model: this.model,
|
|
1223
1385
|
messages: anthropicMessages,
|
|
1224
1386
|
max_tokens: (forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) || 1024,
|
|
1387
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) ? {
|
|
1388
|
+
temperature: forwardedParameters.temperature
|
|
1389
|
+
} : {},
|
|
1225
1390
|
...tools.length > 0 && {
|
|
1226
1391
|
tools
|
|
1227
1392
|
},
|
|
@@ -1246,7 +1411,11 @@ var AnthropicAdapter = class {
|
|
|
1246
1411
|
mode = "message";
|
|
1247
1412
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1248
1413
|
currentToolCallId = chunk.content_block.id;
|
|
1249
|
-
eventStream$.sendActionExecutionStart(
|
|
1414
|
+
eventStream$.sendActionExecutionStart({
|
|
1415
|
+
actionExecutionId: currentToolCallId,
|
|
1416
|
+
actionName: chunk.content_block.name,
|
|
1417
|
+
parentMessageId: currentMessageId
|
|
1418
|
+
});
|
|
1250
1419
|
mode = "function";
|
|
1251
1420
|
}
|
|
1252
1421
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1254,21 +1423,33 @@ var AnthropicAdapter = class {
|
|
|
1254
1423
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1255
1424
|
if (text.length > 0) {
|
|
1256
1425
|
if (!didOutputText) {
|
|
1257
|
-
eventStream$.sendTextMessageStart(
|
|
1426
|
+
eventStream$.sendTextMessageStart({
|
|
1427
|
+
messageId: currentMessageId
|
|
1428
|
+
});
|
|
1258
1429
|
didOutputText = true;
|
|
1259
1430
|
}
|
|
1260
|
-
eventStream$.sendTextMessageContent(
|
|
1431
|
+
eventStream$.sendTextMessageContent({
|
|
1432
|
+
messageId: currentMessageId,
|
|
1433
|
+
content: text
|
|
1434
|
+
});
|
|
1261
1435
|
}
|
|
1262
1436
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1263
|
-
eventStream$.sendActionExecutionArgs(
|
|
1437
|
+
eventStream$.sendActionExecutionArgs({
|
|
1438
|
+
actionExecutionId: currentToolCallId,
|
|
1439
|
+
args: chunk.delta.partial_json
|
|
1440
|
+
});
|
|
1264
1441
|
}
|
|
1265
1442
|
} else if (chunk.type === "content_block_stop") {
|
|
1266
1443
|
if (mode === "message") {
|
|
1267
1444
|
if (didOutputText) {
|
|
1268
|
-
eventStream$.sendTextMessageEnd(
|
|
1445
|
+
eventStream$.sendTextMessageEnd({
|
|
1446
|
+
messageId: currentMessageId
|
|
1447
|
+
});
|
|
1269
1448
|
}
|
|
1270
1449
|
} else if (mode === "function") {
|
|
1271
|
-
eventStream$.sendActionExecutionEnd(
|
|
1450
|
+
eventStream$.sendActionExecutionEnd({
|
|
1451
|
+
actionExecutionId: currentToolCallId
|
|
1452
|
+
});
|
|
1272
1453
|
}
|
|
1273
1454
|
}
|
|
1274
1455
|
}
|
|
@@ -1313,12 +1494,66 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1313
1494
|
}
|
|
1314
1495
|
}, "FilterThinkingTextBuffer");
|
|
1315
1496
|
|
|
1497
|
+
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1498
|
+
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1499
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1500
|
+
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1501
|
+
var ExperimentalOllamaAdapter = class {
|
|
1502
|
+
model;
|
|
1503
|
+
constructor(options) {
|
|
1504
|
+
if (options == null ? void 0 : options.model) {
|
|
1505
|
+
this.model = options.model;
|
|
1506
|
+
} else {
|
|
1507
|
+
this.model = DEFAULT_MODEL4;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
async process(request) {
|
|
1511
|
+
const { messages, actions, eventSource } = request;
|
|
1512
|
+
const ollama = new import_ollama.Ollama({
|
|
1513
|
+
model: this.model
|
|
1514
|
+
});
|
|
1515
|
+
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1516
|
+
const _stream = await ollama.stream(contents);
|
|
1517
|
+
eventSource.stream(async (eventStream$) => {
|
|
1518
|
+
const currentMessageId = (0, import_shared7.randomId)();
|
|
1519
|
+
eventStream$.sendTextMessageStart({
|
|
1520
|
+
messageId: currentMessageId
|
|
1521
|
+
});
|
|
1522
|
+
for await (const chunkText of _stream) {
|
|
1523
|
+
eventStream$.sendTextMessageContent({
|
|
1524
|
+
messageId: currentMessageId,
|
|
1525
|
+
content: chunkText
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
eventStream$.sendTextMessageEnd({
|
|
1529
|
+
messageId: currentMessageId
|
|
1530
|
+
});
|
|
1531
|
+
eventStream$.complete();
|
|
1532
|
+
});
|
|
1533
|
+
return {
|
|
1534
|
+
threadId: request.threadId || (0, import_shared7.randomId)()
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1539
|
+
|
|
1540
|
+
// src/service-adapters/experimental/empty/empty-adapter.ts
|
|
1541
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1542
|
+
var ExperimentalEmptyAdapter = class {
|
|
1543
|
+
async process(request) {
|
|
1544
|
+
return {
|
|
1545
|
+
threadId: request.threadId || (0, import_shared8.randomId)()
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
__name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
|
|
1550
|
+
|
|
1316
1551
|
// src/service-adapters/events.ts
|
|
1317
|
-
var
|
|
1552
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1318
1553
|
var import_rxjs2 = require("rxjs");
|
|
1319
1554
|
|
|
1320
1555
|
// src/lib/telemetry-client.ts
|
|
1321
|
-
var
|
|
1556
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1322
1557
|
|
|
1323
1558
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1324
1559
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1351,7 +1586,7 @@ var CustomEventNames;
|
|
|
1351
1586
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1352
1587
|
|
|
1353
1588
|
// src/agents/langgraph/event-source.ts
|
|
1354
|
-
var
|
|
1589
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1355
1590
|
var RemoteLangGraphEventSource = class {
|
|
1356
1591
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1357
1592
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1363,163 +1598,167 @@ var RemoteLangGraphEventSource = class {
|
|
|
1363
1598
|
}
|
|
1364
1599
|
return shouldEmitToolCalls === toolCallName;
|
|
1365
1600
|
}
|
|
1601
|
+
getCurrentContent(event) {
|
|
1602
|
+
var _a, _b, _c, _d, _e;
|
|
1603
|
+
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);
|
|
1604
|
+
if (!content) {
|
|
1605
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1606
|
+
for (const chunk of toolCallChunks) {
|
|
1607
|
+
if (chunk.args) {
|
|
1608
|
+
return chunk.args;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (typeof content === "string") {
|
|
1613
|
+
return content;
|
|
1614
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1615
|
+
return content[0].text;
|
|
1616
|
+
}
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
getCurrentMessageId(event) {
|
|
1620
|
+
var _a, _b, _c, _d, _e;
|
|
1621
|
+
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);
|
|
1622
|
+
}
|
|
1623
|
+
getCurrentToolCallChunks(event) {
|
|
1624
|
+
var _a, _b, _c, _d, _e;
|
|
1625
|
+
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);
|
|
1626
|
+
}
|
|
1627
|
+
getResponseMetadata(event) {
|
|
1628
|
+
var _a, _b, _c, _d, _e;
|
|
1629
|
+
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);
|
|
1630
|
+
}
|
|
1366
1631
|
processLangGraphEvents() {
|
|
1367
1632
|
let lastEventWithState = null;
|
|
1368
1633
|
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
1634
|
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;
|
|
1635
|
+
const prevMessageId = acc.lastMessageId;
|
|
1636
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
1637
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1638
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1639
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
1640
|
+
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1641
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1642
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
1643
|
+
acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1644
|
+
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1645
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1646
|
+
name: acc.lastToolCallName,
|
|
1647
|
+
id: acc.lastToolCallId
|
|
1648
|
+
});
|
|
1408
1649
|
}
|
|
1409
1650
|
acc.event = event;
|
|
1410
1651
|
lastEventWithState = acc;
|
|
1411
1652
|
return acc;
|
|
1412
1653
|
}, {
|
|
1413
1654
|
event: null,
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1655
|
+
isMessageStart: false,
|
|
1656
|
+
isMessageEnd: false,
|
|
1657
|
+
isToolCallStart: false,
|
|
1658
|
+
isToolCallEnd: false,
|
|
1659
|
+
isToolCall: false,
|
|
1660
|
+
lastMessageId: null,
|
|
1661
|
+
lastToolCallId: null,
|
|
1662
|
+
lastToolCallName: null,
|
|
1663
|
+
currentContent: null
|
|
1664
|
+
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1423
1665
|
const events = [];
|
|
1424
1666
|
let shouldEmitMessages = true;
|
|
1425
|
-
let shouldEmitToolCalls =
|
|
1426
|
-
if (
|
|
1427
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1428
|
-
shouldEmitToolCalls =
|
|
1667
|
+
let shouldEmitToolCalls = true;
|
|
1668
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1669
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
1670
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
1429
1671
|
}
|
|
1430
|
-
if ("copilotkit:emit-messages" in (
|
|
1431
|
-
shouldEmitMessages =
|
|
1672
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
1673
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
1432
1674
|
}
|
|
1433
1675
|
}
|
|
1434
|
-
|
|
1676
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1677
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1435
1678
|
events.push({
|
|
1436
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1679
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1680
|
+
actionExecutionId: acc.lastToolCallId
|
|
1437
1681
|
});
|
|
1438
1682
|
}
|
|
1439
|
-
if (
|
|
1683
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1440
1684
|
events.push({
|
|
1441
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1685
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1686
|
+
messageId: acc.lastMessageId
|
|
1442
1687
|
});
|
|
1443
1688
|
}
|
|
1444
|
-
switch (
|
|
1689
|
+
switch (acc.event.event) {
|
|
1445
1690
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1446
|
-
if (
|
|
1691
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1447
1692
|
events.push({
|
|
1448
1693
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1449
|
-
messageId:
|
|
1694
|
+
messageId: acc.event.data.message_id
|
|
1450
1695
|
});
|
|
1451
1696
|
events.push({
|
|
1452
1697
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1453
|
-
|
|
1698
|
+
messageId: acc.event.data.message_id,
|
|
1699
|
+
content: acc.event.data.message
|
|
1454
1700
|
});
|
|
1455
1701
|
events.push({
|
|
1456
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1702
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1703
|
+
messageId: acc.event.data.message_id
|
|
1457
1704
|
});
|
|
1458
|
-
} else if (
|
|
1705
|
+
} else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1459
1706
|
events.push({
|
|
1460
1707
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1461
|
-
actionExecutionId:
|
|
1462
|
-
actionName:
|
|
1708
|
+
actionExecutionId: acc.event.data.id,
|
|
1709
|
+
actionName: acc.event.data.name,
|
|
1710
|
+
parentMessageId: acc.event.data.id
|
|
1463
1711
|
});
|
|
1464
1712
|
events.push({
|
|
1465
1713
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1466
|
-
|
|
1714
|
+
actionExecutionId: acc.event.data.id,
|
|
1715
|
+
args: JSON.stringify(acc.event.data.args)
|
|
1467
1716
|
});
|
|
1468
1717
|
events.push({
|
|
1469
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1718
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1719
|
+
actionExecutionId: acc.event.data.id
|
|
1470
1720
|
});
|
|
1471
1721
|
}
|
|
1472
1722
|
break;
|
|
1473
1723
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1474
1724
|
events.push({
|
|
1475
1725
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1476
|
-
threadId:
|
|
1477
|
-
role:
|
|
1478
|
-
agentName:
|
|
1479
|
-
nodeName:
|
|
1480
|
-
runId:
|
|
1481
|
-
active:
|
|
1482
|
-
state: JSON.stringify(
|
|
1483
|
-
running:
|
|
1726
|
+
threadId: acc.event.thread_id,
|
|
1727
|
+
role: acc.event.role,
|
|
1728
|
+
agentName: acc.event.agent_name,
|
|
1729
|
+
nodeName: acc.event.node_name,
|
|
1730
|
+
runId: acc.event.run_id,
|
|
1731
|
+
active: acc.event.active,
|
|
1732
|
+
state: JSON.stringify(acc.event.state),
|
|
1733
|
+
running: acc.event.running
|
|
1484
1734
|
});
|
|
1485
1735
|
break;
|
|
1486
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
1487
|
-
break;
|
|
1488
1736
|
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
|
-
}
|
|
1737
|
+
if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1738
|
+
events.push({
|
|
1739
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1740
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1741
|
+
actionName: acc.lastToolCallName,
|
|
1742
|
+
parentMessageId: acc.lastMessageId
|
|
1743
|
+
});
|
|
1744
|
+
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1745
|
+
events.push({
|
|
1746
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1747
|
+
messageId: acc.lastMessageId
|
|
1748
|
+
});
|
|
1505
1749
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
events.push({
|
|
1519
|
-
type: RuntimeEventTypes.TextMessageContent,
|
|
1520
|
-
content
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1750
|
+
if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1751
|
+
events.push({
|
|
1752
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1753
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1754
|
+
args: acc.currentContent
|
|
1755
|
+
});
|
|
1756
|
+
} else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
1757
|
+
events.push({
|
|
1758
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1759
|
+
messageId: acc.lastMessageId,
|
|
1760
|
+
content: acc.currentContent
|
|
1761
|
+
});
|
|
1523
1762
|
}
|
|
1524
1763
|
break;
|
|
1525
1764
|
}
|
|
@@ -1527,27 +1766,31 @@ var RemoteLangGraphEventSource = class {
|
|
|
1527
1766
|
}), (0, import_rxjs.catchError)((error) => {
|
|
1528
1767
|
console.error(error);
|
|
1529
1768
|
const events = [];
|
|
1530
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1769
|
+
if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
|
|
1531
1770
|
events.push({
|
|
1532
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1771
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1772
|
+
messageId: lastEventWithState.lastMessageId
|
|
1533
1773
|
});
|
|
1534
1774
|
}
|
|
1535
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1775
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
|
|
1536
1776
|
events.push({
|
|
1537
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1777
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1778
|
+
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1538
1779
|
});
|
|
1539
1780
|
}
|
|
1540
|
-
const messageId = (0,
|
|
1781
|
+
const messageId = (0, import_shared9.randomId)();
|
|
1541
1782
|
events.push({
|
|
1542
1783
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1543
1784
|
messageId
|
|
1544
1785
|
});
|
|
1545
1786
|
events.push({
|
|
1546
1787
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1788
|
+
messageId,
|
|
1547
1789
|
content: "\u274C An error occurred. Please try again."
|
|
1548
1790
|
});
|
|
1549
1791
|
events.push({
|
|
1550
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1792
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1793
|
+
messageId
|
|
1551
1794
|
});
|
|
1552
1795
|
return events;
|
|
1553
1796
|
}));
|
|
@@ -1569,12 +1812,6 @@ var MessageRole;
|
|
|
1569
1812
|
MessageRole2["system"] = "system";
|
|
1570
1813
|
MessageRole2["tool"] = "tool";
|
|
1571
1814
|
})(MessageRole || (MessageRole = {}));
|
|
1572
|
-
var ActionExecutionScope;
|
|
1573
|
-
(function(ActionExecutionScope2) {
|
|
1574
|
-
ActionExecutionScope2["server"] = "server";
|
|
1575
|
-
ActionExecutionScope2["client"] = "client";
|
|
1576
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1577
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1578
1815
|
var CopilotRequestType;
|
|
1579
1816
|
(function(CopilotRequestType2) {
|
|
1580
1817
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -1593,10 +1830,6 @@ var ActionInputAvailability;
|
|
|
1593
1830
|
name: "MessageRole",
|
|
1594
1831
|
description: "The role of the message"
|
|
1595
1832
|
});
|
|
1596
|
-
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1597
|
-
name: "ActionExecutionScope",
|
|
1598
|
-
description: "The scope of the action"
|
|
1599
|
-
});
|
|
1600
1833
|
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1601
1834
|
name: "CopilotRequestType",
|
|
1602
1835
|
description: "The type of Copilot request"
|
|
@@ -1634,8 +1867,6 @@ async function streamEvents(controller, args) {
|
|
|
1634
1867
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1635
1868
|
initialThreadId = initialThreadId.substring(3);
|
|
1636
1869
|
}
|
|
1637
|
-
const assistants = await client.assistants.search();
|
|
1638
|
-
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1639
1870
|
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1640
1871
|
if (initialThreadId === threadId) {
|
|
1641
1872
|
await client.threads.get(threadId);
|
|
@@ -1655,7 +1886,7 @@ async function streamEvents(controller, args) {
|
|
|
1655
1886
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1656
1887
|
let formattedMessages = [];
|
|
1657
1888
|
try {
|
|
1658
|
-
formattedMessages =
|
|
1889
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1659
1890
|
} catch (e) {
|
|
1660
1891
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1661
1892
|
}
|
|
@@ -1666,8 +1897,16 @@ async function streamEvents(controller, args) {
|
|
|
1666
1897
|
asNode: nodeName
|
|
1667
1898
|
});
|
|
1668
1899
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1900
|
+
let streamInfo = {
|
|
1901
|
+
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1902
|
+
};
|
|
1903
|
+
const assistants = await client.assistants.search();
|
|
1904
|
+
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1905
|
+
if (!retrievedAssistant) {
|
|
1906
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1907
|
+
...streamInfo,
|
|
1908
|
+
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1909
|
+
});
|
|
1671
1910
|
console.error(`
|
|
1672
1911
|
No agent found for the agent name specified in CopilotKit provider
|
|
1673
1912
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1677,6 +1916,7 @@ async function streamEvents(controller, args) {
|
|
|
1677
1916
|
`);
|
|
1678
1917
|
throw new Error("No agent id found");
|
|
1679
1918
|
}
|
|
1919
|
+
const assistantId = retrievedAssistant.assistant_id;
|
|
1680
1920
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1681
1921
|
const streamInput = mode === "start" ? state : null;
|
|
1682
1922
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1695,9 +1935,6 @@ async function streamEvents(controller, args) {
|
|
|
1695
1935
|
let latestStateValues = {};
|
|
1696
1936
|
let updatedState = state;
|
|
1697
1937
|
let manuallyEmittedState = null;
|
|
1698
|
-
let streamInfo = {
|
|
1699
|
-
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1700
|
-
};
|
|
1701
1938
|
try {
|
|
1702
1939
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1703
1940
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1710,7 +1947,6 @@ async function streamEvents(controller, args) {
|
|
|
1710
1947
|
].includes(chunk.event))
|
|
1711
1948
|
continue;
|
|
1712
1949
|
if (chunk.event === "error") {
|
|
1713
|
-
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1714
1950
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1715
1951
|
}
|
|
1716
1952
|
if (chunk.event === "values") {
|
|
@@ -1803,21 +2039,34 @@ async function streamEvents(controller, args) {
|
|
|
1803
2039
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1804
2040
|
state: state.values,
|
|
1805
2041
|
running: !shouldExit,
|
|
1806
|
-
active: false
|
|
2042
|
+
active: false,
|
|
2043
|
+
includeMessages: true
|
|
1807
2044
|
}));
|
|
1808
2045
|
return Promise.resolve();
|
|
1809
2046
|
} catch (e) {
|
|
2047
|
+
logger2.error(e);
|
|
2048
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
2049
|
+
...streamInfo,
|
|
2050
|
+
error: e.message
|
|
2051
|
+
});
|
|
1810
2052
|
return Promise.resolve();
|
|
1811
2053
|
}
|
|
1812
2054
|
}
|
|
1813
2055
|
__name(streamEvents, "streamEvents");
|
|
1814
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
2056
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
2057
|
+
if (!includeMessages) {
|
|
2058
|
+
state = Object.keys(state).reduce((acc, key) => {
|
|
2059
|
+
if (key !== "messages") {
|
|
2060
|
+
acc[key] = state[key];
|
|
2061
|
+
}
|
|
2062
|
+
return acc;
|
|
2063
|
+
}, {});
|
|
2064
|
+
} else {
|
|
2065
|
+
state = {
|
|
2066
|
+
...state,
|
|
2067
|
+
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
1821
2070
|
return JSON.stringify({
|
|
1822
2071
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1823
2072
|
thread_id: threadId,
|
|
@@ -1825,7 +2074,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1825
2074
|
agent_name: agentName,
|
|
1826
2075
|
node_name: nodeName,
|
|
1827
2076
|
active,
|
|
1828
|
-
state
|
|
2077
|
+
state,
|
|
1829
2078
|
running,
|
|
1830
2079
|
role: "assistant"
|
|
1831
2080
|
}) + "\n";
|
|
@@ -1901,134 +2150,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1901
2150
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1902
2151
|
messages = messages.slice(1);
|
|
1903
2152
|
}
|
|
1904
|
-
const
|
|
1905
|
-
const existingMessageIds = new Set(
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2153
|
+
const existingMessages = state.messages || [];
|
|
2154
|
+
const existingMessageIds = new Set(existingMessages.map((message) => message.id));
|
|
2155
|
+
const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
|
|
2156
|
+
return {
|
|
2157
|
+
...state,
|
|
2158
|
+
messages: newMessages,
|
|
2159
|
+
copilotkit: {
|
|
2160
|
+
actions
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
2165
|
+
function langchainMessagesToCopilotKit(messages) {
|
|
2166
|
+
const result = [];
|
|
2167
|
+
const tool_call_names = {};
|
|
2168
|
+
for (const message of messages) {
|
|
2169
|
+
if (message.type === "ai") {
|
|
2170
|
+
for (const tool_call of message.tool_calls) {
|
|
2171
|
+
tool_call_names[tool_call.id] = tool_call.name;
|
|
2172
|
+
}
|
|
1910
2173
|
}
|
|
1911
2174
|
}
|
|
1912
2175
|
for (const message of messages) {
|
|
1913
|
-
|
|
1914
|
-
|
|
2176
|
+
let content = message.content;
|
|
2177
|
+
if (content instanceof Array) {
|
|
2178
|
+
content = content[0];
|
|
1915
2179
|
}
|
|
1916
|
-
if (
|
|
1917
|
-
|
|
2180
|
+
if (content instanceof Object) {
|
|
2181
|
+
content = content.text;
|
|
1918
2182
|
}
|
|
1919
|
-
if (
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
} else {
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2183
|
+
if (message.type === "human") {
|
|
2184
|
+
result.push({
|
|
2185
|
+
role: "user",
|
|
2186
|
+
content,
|
|
2187
|
+
id: message.id
|
|
2188
|
+
});
|
|
2189
|
+
} else if (message.type === "system") {
|
|
2190
|
+
result.push({
|
|
2191
|
+
role: "system",
|
|
2192
|
+
content,
|
|
2193
|
+
id: message.id
|
|
2194
|
+
});
|
|
2195
|
+
} else if (message.type === "ai") {
|
|
2196
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
2197
|
+
for (const tool_call of message.tool_calls) {
|
|
2198
|
+
result.push({
|
|
2199
|
+
id: tool_call.id,
|
|
2200
|
+
name: tool_call.name,
|
|
2201
|
+
arguments: tool_call.args,
|
|
2202
|
+
parentMessageId: message.id
|
|
2203
|
+
});
|
|
1933
2204
|
}
|
|
2205
|
+
} else {
|
|
2206
|
+
result.push({
|
|
2207
|
+
role: "assistant",
|
|
2208
|
+
content,
|
|
2209
|
+
id: message.id,
|
|
2210
|
+
parentMessageId: message.id
|
|
2211
|
+
});
|
|
1934
2212
|
}
|
|
2213
|
+
} else if (message.type === "tool") {
|
|
2214
|
+
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
2215
|
+
result.push({
|
|
2216
|
+
actionExecutionId: message.tool_call_id,
|
|
2217
|
+
actionName,
|
|
2218
|
+
result: content,
|
|
2219
|
+
id: message.id
|
|
2220
|
+
});
|
|
1935
2221
|
}
|
|
1936
2222
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
2223
|
+
const resultsDict = {};
|
|
2224
|
+
for (const msg of result) {
|
|
2225
|
+
if (msg.actionExecutionId) {
|
|
2226
|
+
resultsDict[msg.actionExecutionId] = msg;
|
|
1942
2227
|
}
|
|
1943
2228
|
}
|
|
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;
|
|
2229
|
+
const reorderedResult = [];
|
|
2230
|
+
for (const msg of result) {
|
|
2231
|
+
if (!("actionExecutionId" in msg)) {
|
|
2232
|
+
reorderedResult.push(msg);
|
|
1967
2233
|
}
|
|
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;
|
|
2234
|
+
if ("arguments" in msg) {
|
|
2235
|
+
const msgId = msg.id;
|
|
2236
|
+
if (msgId in resultsDict) {
|
|
2237
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1976
2238
|
}
|
|
1977
|
-
correctedMessages.push(currentMessage);
|
|
1978
|
-
continue;
|
|
1979
2239
|
}
|
|
1980
|
-
correctedMessages.push(currentMessage);
|
|
1981
2240
|
}
|
|
1982
|
-
return
|
|
1983
|
-
...state,
|
|
1984
|
-
messages: correctedMessages,
|
|
1985
|
-
copilotkit: {
|
|
1986
|
-
actions
|
|
1987
|
-
}
|
|
1988
|
-
};
|
|
2241
|
+
return reorderedResult;
|
|
1989
2242
|
}
|
|
1990
|
-
__name(
|
|
1991
|
-
function
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2243
|
+
__name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
|
|
2244
|
+
function copilotkitMessagesToLangChain(messages) {
|
|
2245
|
+
const result = [];
|
|
2246
|
+
const processedActionExecutions = /* @__PURE__ */ new Set();
|
|
2247
|
+
for (const message of messages) {
|
|
2248
|
+
if (message.isTextMessage()) {
|
|
2249
|
+
if (message.role === "user") {
|
|
2250
|
+
result.push({
|
|
2251
|
+
...message,
|
|
2252
|
+
role: MessageRole.user
|
|
2253
|
+
});
|
|
2254
|
+
} else if (message.role === "system") {
|
|
2255
|
+
result.push({
|
|
2256
|
+
...message,
|
|
2257
|
+
role: MessageRole.system
|
|
2258
|
+
});
|
|
2259
|
+
} else if (message.role === "assistant") {
|
|
2260
|
+
result.push({
|
|
2261
|
+
...message,
|
|
2262
|
+
role: MessageRole.assistant
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
continue;
|
|
2001
2266
|
}
|
|
2002
2267
|
if (message.isActionExecutionMessage()) {
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2268
|
+
const messageId = message.parentMessageId ?? message.id;
|
|
2269
|
+
if (processedActionExecutions.has(messageId)) {
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
processedActionExecutions.add(messageId);
|
|
2273
|
+
const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
|
|
2274
|
+
const tool_calls = relatedActionExecutions.map((m) => ({
|
|
2275
|
+
name: m.name,
|
|
2276
|
+
args: m.arguments,
|
|
2277
|
+
id: m.id
|
|
2278
|
+
}));
|
|
2279
|
+
result.push({
|
|
2280
|
+
id: messageId,
|
|
2281
|
+
type: "ActionExecutionMessage",
|
|
2010
2282
|
content: "",
|
|
2011
|
-
tool_calls
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
id: message.id
|
|
2016
|
-
};
|
|
2283
|
+
tool_calls,
|
|
2284
|
+
role: MessageRole.assistant
|
|
2285
|
+
});
|
|
2286
|
+
continue;
|
|
2017
2287
|
}
|
|
2018
2288
|
if (message.isResultMessage()) {
|
|
2019
|
-
|
|
2289
|
+
result.push({
|
|
2020
2290
|
type: message.type,
|
|
2021
2291
|
content: message.result,
|
|
2022
2292
|
id: message.id,
|
|
2023
2293
|
tool_call_id: message.actionExecutionId,
|
|
2024
2294
|
name: message.actionName,
|
|
2025
2295
|
role: MessageRole.tool
|
|
2026
|
-
};
|
|
2296
|
+
});
|
|
2297
|
+
continue;
|
|
2027
2298
|
}
|
|
2028
2299
|
throw new Error(`Unknown message type ${message.type}`);
|
|
2029
|
-
}
|
|
2300
|
+
}
|
|
2301
|
+
return result;
|
|
2030
2302
|
}
|
|
2031
|
-
__name(
|
|
2303
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2032
2304
|
|
|
2033
2305
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2034
2306
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -2038,7 +2310,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2038
2310
|
parameters: [],
|
|
2039
2311
|
handler: async (_args) => {
|
|
2040
2312
|
},
|
|
2041
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2313
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2042
2314
|
var _a;
|
|
2043
2315
|
logger2.debug({
|
|
2044
2316
|
actionName: agent.name
|
|
@@ -2064,7 +2336,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2064
2336
|
agent,
|
|
2065
2337
|
threadId,
|
|
2066
2338
|
nodeName,
|
|
2067
|
-
messages
|
|
2339
|
+
messages: [
|
|
2340
|
+
...messages,
|
|
2341
|
+
...additionalMessages
|
|
2342
|
+
],
|
|
2068
2343
|
state,
|
|
2069
2344
|
properties: graphqlContext.properties,
|
|
2070
2345
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2092,6 +2367,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2092
2367
|
}
|
|
2093
2368
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
2094
2369
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2370
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
2095
2371
|
const actions = json["actions"].map((action) => ({
|
|
2096
2372
|
name: action.name,
|
|
2097
2373
|
description: action.description,
|
|
@@ -2105,7 +2381,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2105
2381
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2106
2382
|
agentExecution: false,
|
|
2107
2383
|
type: "self-hosted",
|
|
2108
|
-
agentsAmount:
|
|
2384
|
+
agentsAmount: totalAgents
|
|
2109
2385
|
});
|
|
2110
2386
|
try {
|
|
2111
2387
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -2140,13 +2416,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2140
2416
|
}
|
|
2141
2417
|
}
|
|
2142
2418
|
}));
|
|
2143
|
-
const agents = json["agents"].map((agent) => ({
|
|
2419
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
2144
2420
|
name: agent.name,
|
|
2145
2421
|
description: agent.description,
|
|
2146
2422
|
parameters: [],
|
|
2147
2423
|
handler: async (_args) => {
|
|
2148
2424
|
},
|
|
2149
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
2425
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
2150
2426
|
var _a;
|
|
2151
2427
|
logger2.debug({
|
|
2152
2428
|
actionName: agent.name
|
|
@@ -2171,7 +2447,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2171
2447
|
name,
|
|
2172
2448
|
threadId,
|
|
2173
2449
|
nodeName,
|
|
2174
|
-
messages
|
|
2450
|
+
messages: [
|
|
2451
|
+
...messages,
|
|
2452
|
+
...additionalMessages
|
|
2453
|
+
],
|
|
2175
2454
|
state,
|
|
2176
2455
|
properties: graphqlContext.properties,
|
|
2177
2456
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -2193,7 +2472,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2193
2472
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2194
2473
|
return eventSource.processLangGraphEvents();
|
|
2195
2474
|
}
|
|
2196
|
-
}));
|
|
2475
|
+
})) : [];
|
|
2197
2476
|
return [
|
|
2198
2477
|
...actions,
|
|
2199
2478
|
...agents
|
|
@@ -2370,7 +2649,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2370
2649
|
// src/lib/telemetry-client.ts
|
|
2371
2650
|
var import_node_crypto3 = require("crypto");
|
|
2372
2651
|
var packageJson = require_package();
|
|
2373
|
-
var telemetryClient = new
|
|
2652
|
+
var telemetryClient = new import_shared10.TelemetryClient({
|
|
2374
2653
|
packageName: packageJson.name,
|
|
2375
2654
|
packageVersion: packageJson.version
|
|
2376
2655
|
});
|
|
@@ -2414,7 +2693,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
|
2414
2693
|
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2415
2694
|
var telemetry_client_default = telemetryClient;
|
|
2416
2695
|
|
|
2696
|
+
// src/graphql/types/base/index.ts
|
|
2697
|
+
var import_type_graphql2 = require("type-graphql");
|
|
2698
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2699
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2700
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2701
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2702
|
+
else
|
|
2703
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2704
|
+
if (d = decorators[i])
|
|
2705
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2706
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2707
|
+
}
|
|
2708
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
2709
|
+
function _ts_metadata(k, v) {
|
|
2710
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2711
|
+
return Reflect.metadata(k, v);
|
|
2712
|
+
}
|
|
2713
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
2714
|
+
var BaseMessageInput = class {
|
|
2715
|
+
id;
|
|
2716
|
+
createdAt;
|
|
2717
|
+
};
|
|
2718
|
+
__name(BaseMessageInput, "BaseMessageInput");
|
|
2719
|
+
_ts_decorate([
|
|
2720
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
2721
|
+
_ts_metadata("design:type", String)
|
|
2722
|
+
], BaseMessageInput.prototype, "id", void 0);
|
|
2723
|
+
_ts_decorate([
|
|
2724
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
2725
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
2726
|
+
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
2727
|
+
BaseMessageInput = _ts_decorate([
|
|
2728
|
+
(0, import_type_graphql2.InputType)()
|
|
2729
|
+
], BaseMessageInput);
|
|
2730
|
+
|
|
2731
|
+
// src/graphql/types/converted/index.ts
|
|
2732
|
+
var Message = class extends BaseMessageInput {
|
|
2733
|
+
type;
|
|
2734
|
+
isTextMessage() {
|
|
2735
|
+
return this.type === "TextMessage";
|
|
2736
|
+
}
|
|
2737
|
+
isActionExecutionMessage() {
|
|
2738
|
+
return this.type === "ActionExecutionMessage";
|
|
2739
|
+
}
|
|
2740
|
+
isResultMessage() {
|
|
2741
|
+
return this.type === "ResultMessage";
|
|
2742
|
+
}
|
|
2743
|
+
isAgentStateMessage() {
|
|
2744
|
+
return this.type === "AgentStateMessage";
|
|
2745
|
+
}
|
|
2746
|
+
};
|
|
2747
|
+
__name(Message, "Message");
|
|
2748
|
+
var TextMessage = class extends Message {
|
|
2749
|
+
type = "TextMessage";
|
|
2750
|
+
content;
|
|
2751
|
+
role;
|
|
2752
|
+
parentMessageId;
|
|
2753
|
+
};
|
|
2754
|
+
__name(TextMessage, "TextMessage");
|
|
2755
|
+
var ActionExecutionMessage = class extends Message {
|
|
2756
|
+
type = "ActionExecutionMessage";
|
|
2757
|
+
name;
|
|
2758
|
+
arguments;
|
|
2759
|
+
parentMessageId;
|
|
2760
|
+
};
|
|
2761
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
2762
|
+
var ResultMessage = class extends Message {
|
|
2763
|
+
type = "ResultMessage";
|
|
2764
|
+
actionExecutionId;
|
|
2765
|
+
actionName;
|
|
2766
|
+
result;
|
|
2767
|
+
};
|
|
2768
|
+
__name(ResultMessage, "ResultMessage");
|
|
2769
|
+
var AgentStateMessage = class extends Message {
|
|
2770
|
+
type = "AgentStateMessage";
|
|
2771
|
+
threadId;
|
|
2772
|
+
agentName;
|
|
2773
|
+
nodeName;
|
|
2774
|
+
runId;
|
|
2775
|
+
active;
|
|
2776
|
+
role;
|
|
2777
|
+
state;
|
|
2778
|
+
running;
|
|
2779
|
+
};
|
|
2780
|
+
__name(AgentStateMessage, "AgentStateMessage");
|
|
2781
|
+
|
|
2417
2782
|
// src/service-adapters/events.ts
|
|
2783
|
+
var import_class_transformer = require("class-transformer");
|
|
2418
2784
|
var RuntimeEventTypes;
|
|
2419
2785
|
(function(RuntimeEventTypes2) {
|
|
2420
2786
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2430,52 +2796,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2430
2796
|
constructor() {
|
|
2431
2797
|
super();
|
|
2432
2798
|
}
|
|
2433
|
-
sendTextMessageStart(messageId) {
|
|
2799
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2434
2800
|
this.next({
|
|
2435
2801
|
type: "TextMessageStart",
|
|
2436
|
-
messageId
|
|
2802
|
+
messageId,
|
|
2803
|
+
parentMessageId
|
|
2437
2804
|
});
|
|
2438
2805
|
}
|
|
2439
|
-
sendTextMessageContent(content) {
|
|
2806
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2440
2807
|
this.next({
|
|
2441
2808
|
type: "TextMessageContent",
|
|
2442
|
-
content
|
|
2809
|
+
content,
|
|
2810
|
+
messageId
|
|
2443
2811
|
});
|
|
2444
2812
|
}
|
|
2445
|
-
sendTextMessageEnd() {
|
|
2813
|
+
sendTextMessageEnd({ messageId }) {
|
|
2446
2814
|
this.next({
|
|
2447
|
-
type: "TextMessageEnd"
|
|
2815
|
+
type: "TextMessageEnd",
|
|
2816
|
+
messageId
|
|
2448
2817
|
});
|
|
2449
2818
|
}
|
|
2450
2819
|
sendTextMessage(messageId, content) {
|
|
2451
|
-
this.sendTextMessageStart(
|
|
2452
|
-
|
|
2453
|
-
|
|
2820
|
+
this.sendTextMessageStart({
|
|
2821
|
+
messageId
|
|
2822
|
+
});
|
|
2823
|
+
this.sendTextMessageContent({
|
|
2824
|
+
messageId,
|
|
2825
|
+
content
|
|
2826
|
+
});
|
|
2827
|
+
this.sendTextMessageEnd({
|
|
2828
|
+
messageId
|
|
2829
|
+
});
|
|
2454
2830
|
}
|
|
2455
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2831
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2456
2832
|
this.next({
|
|
2457
2833
|
type: "ActionExecutionStart",
|
|
2458
2834
|
actionExecutionId,
|
|
2459
|
-
actionName
|
|
2835
|
+
actionName,
|
|
2836
|
+
parentMessageId
|
|
2460
2837
|
});
|
|
2461
2838
|
}
|
|
2462
|
-
sendActionExecutionArgs(args) {
|
|
2839
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2463
2840
|
this.next({
|
|
2464
2841
|
type: "ActionExecutionArgs",
|
|
2465
|
-
args
|
|
2842
|
+
args,
|
|
2843
|
+
actionExecutionId
|
|
2466
2844
|
});
|
|
2467
2845
|
}
|
|
2468
|
-
sendActionExecutionEnd() {
|
|
2846
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2469
2847
|
this.next({
|
|
2470
|
-
type: "ActionExecutionEnd"
|
|
2848
|
+
type: "ActionExecutionEnd",
|
|
2849
|
+
actionExecutionId
|
|
2471
2850
|
});
|
|
2472
2851
|
}
|
|
2473
|
-
sendActionExecution(actionExecutionId,
|
|
2474
|
-
this.sendActionExecutionStart(
|
|
2475
|
-
|
|
2476
|
-
|
|
2852
|
+
sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
|
|
2853
|
+
this.sendActionExecutionStart({
|
|
2854
|
+
actionExecutionId,
|
|
2855
|
+
actionName,
|
|
2856
|
+
parentMessageId
|
|
2857
|
+
});
|
|
2858
|
+
this.sendActionExecutionArgs({
|
|
2859
|
+
actionExecutionId,
|
|
2860
|
+
args
|
|
2861
|
+
});
|
|
2862
|
+
this.sendActionExecutionEnd({
|
|
2863
|
+
actionExecutionId
|
|
2864
|
+
});
|
|
2477
2865
|
}
|
|
2478
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2866
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2479
2867
|
this.next({
|
|
2480
2868
|
type: "ActionExecutionResult",
|
|
2481
2869
|
actionName,
|
|
@@ -2483,7 +2871,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2483
2871
|
result
|
|
2484
2872
|
});
|
|
2485
2873
|
}
|
|
2486
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2874
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2487
2875
|
this.next({
|
|
2488
2876
|
type: "AgentStateMessage",
|
|
2489
2877
|
threadId,
|
|
@@ -2504,14 +2892,14 @@ var RuntimeEventSource = class {
|
|
|
2504
2892
|
async stream(callback) {
|
|
2505
2893
|
this.callback = callback;
|
|
2506
2894
|
}
|
|
2507
|
-
sendErrorMessageToChat() {
|
|
2508
|
-
const errorMessage =
|
|
2895
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2896
|
+
const errorMessage = `\u274C ${message}`;
|
|
2509
2897
|
if (!this.callback) {
|
|
2510
2898
|
this.stream(async (eventStream$) => {
|
|
2511
|
-
eventStream$.sendTextMessage((0,
|
|
2899
|
+
eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2512
2900
|
});
|
|
2513
2901
|
} else {
|
|
2514
|
-
this.eventStream$.sendTextMessage((0,
|
|
2902
|
+
this.eventStream$.sendTextMessage((0, import_shared11.randomId)(), errorMessage);
|
|
2515
2903
|
}
|
|
2516
2904
|
}
|
|
2517
2905
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2520,27 +2908,19 @@ var RuntimeEventSource = class {
|
|
|
2520
2908
|
this.sendErrorMessageToChat();
|
|
2521
2909
|
});
|
|
2522
2910
|
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
2911
|
// track state
|
|
2533
2912
|
(0, import_rxjs2.scan)((acc, event) => {
|
|
2534
2913
|
acc = {
|
|
2535
2914
|
...acc
|
|
2536
2915
|
};
|
|
2537
2916
|
if (event.type === "ActionExecutionStart") {
|
|
2538
|
-
acc.callActionServerSide =
|
|
2917
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2539
2918
|
acc.args = "";
|
|
2540
2919
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2541
2920
|
if (acc.callActionServerSide) {
|
|
2542
2921
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2543
2922
|
}
|
|
2923
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2544
2924
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2545
2925
|
acc.args += event.args;
|
|
2546
2926
|
}
|
|
@@ -2551,12 +2931,13 @@ var RuntimeEventSource = class {
|
|
|
2551
2931
|
callActionServerSide: false,
|
|
2552
2932
|
args: "",
|
|
2553
2933
|
actionExecutionId: null,
|
|
2554
|
-
action: null
|
|
2934
|
+
action: null,
|
|
2935
|
+
actionExecutionParentMessageId: null
|
|
2555
2936
|
}),
|
|
2556
2937
|
(0, import_rxjs2.concatMap)((eventWithState) => {
|
|
2557
2938
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2558
2939
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2559
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2940
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2560
2941
|
console.error(error);
|
|
2561
2942
|
});
|
|
2562
2943
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2569,7 +2950,7 @@ var RuntimeEventSource = class {
|
|
|
2569
2950
|
}
|
|
2570
2951
|
};
|
|
2571
2952
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2572
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2953
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2573
2954
|
var _a;
|
|
2574
2955
|
if (guardrailsResult$) {
|
|
2575
2956
|
const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
@@ -2589,10 +2970,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2589
2970
|
}
|
|
2590
2971
|
}
|
|
2591
2972
|
if (isLangGraphAgentAction(action)) {
|
|
2592
|
-
|
|
2973
|
+
const result = `${action.name} agent started`;
|
|
2974
|
+
const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
2975
|
+
id: actionExecutionId,
|
|
2976
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2977
|
+
name: action.name,
|
|
2978
|
+
arguments: JSON.parse(actionArguments),
|
|
2979
|
+
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2980
|
+
});
|
|
2981
|
+
const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
2982
|
+
id: "result-" + actionExecutionId,
|
|
2983
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2984
|
+
actionExecutionId,
|
|
2985
|
+
actionName: action.name,
|
|
2986
|
+
result
|
|
2987
|
+
});
|
|
2988
|
+
eventStream$.sendActionExecutionResult({
|
|
2989
|
+
actionExecutionId,
|
|
2990
|
+
actionName: action.name,
|
|
2991
|
+
result
|
|
2992
|
+
});
|
|
2593
2993
|
const stream = await action.langGraphAgentHandler({
|
|
2594
2994
|
name: action.name,
|
|
2595
|
-
actionInputsWithoutAgents
|
|
2995
|
+
actionInputsWithoutAgents,
|
|
2996
|
+
additionalMessages: [
|
|
2997
|
+
agentExecution,
|
|
2998
|
+
agentExecutionResult
|
|
2999
|
+
]
|
|
2596
3000
|
});
|
|
2597
3001
|
(0, import_rxjs2.from)(stream).subscribe({
|
|
2598
3002
|
next: (event) => eventStream$.next(event),
|
|
@@ -2613,113 +3017,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2613
3017
|
}
|
|
2614
3018
|
__name(executeAction, "executeAction");
|
|
2615
3019
|
|
|
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
3020
|
// src/service-adapters/conversion.ts
|
|
2702
|
-
var
|
|
3021
|
+
var import_class_transformer2 = require("class-transformer");
|
|
2703
3022
|
function convertGqlInputToMessages(inputMessages) {
|
|
2704
3023
|
const messages = [];
|
|
2705
3024
|
for (const message of inputMessages) {
|
|
2706
3025
|
if (message.textMessage) {
|
|
2707
|
-
messages.push((0,
|
|
3026
|
+
messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2708
3027
|
id: message.id,
|
|
2709
3028
|
createdAt: message.createdAt,
|
|
2710
3029
|
role: message.textMessage.role,
|
|
2711
|
-
content: message.textMessage.content
|
|
3030
|
+
content: message.textMessage.content,
|
|
3031
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2712
3032
|
}));
|
|
2713
3033
|
} else if (message.actionExecutionMessage) {
|
|
2714
|
-
messages.push((0,
|
|
3034
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2715
3035
|
id: message.id,
|
|
2716
3036
|
createdAt: message.createdAt,
|
|
2717
3037
|
name: message.actionExecutionMessage.name,
|
|
2718
3038
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2719
|
-
|
|
3039
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2720
3040
|
}));
|
|
2721
3041
|
} else if (message.resultMessage) {
|
|
2722
|
-
messages.push((0,
|
|
3042
|
+
messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2723
3043
|
id: message.id,
|
|
2724
3044
|
createdAt: message.createdAt,
|
|
2725
3045
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
@@ -2727,7 +3047,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2727
3047
|
result: message.resultMessage.result
|
|
2728
3048
|
}));
|
|
2729
3049
|
} else if (message.agentStateMessage) {
|
|
2730
|
-
messages.push((0,
|
|
3050
|
+
messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
2731
3051
|
id: message.id,
|
|
2732
3052
|
threadId: message.agentStateMessage.threadId,
|
|
2733
3053
|
createdAt: message.createdAt,
|
|
@@ -2778,7 +3098,7 @@ var CopilotRuntime = class {
|
|
|
2778
3098
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2779
3099
|
name: action.name,
|
|
2780
3100
|
description: action.description,
|
|
2781
|
-
jsonSchema: JSON.stringify((0,
|
|
3101
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2782
3102
|
}));
|
|
2783
3103
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2784
3104
|
...serverSideActionsInput,
|
|
@@ -2827,13 +3147,7 @@ var CopilotRuntime = class {
|
|
|
2827
3147
|
} catch (error) {
|
|
2828
3148
|
console.error("Error getting response:", error);
|
|
2829
3149
|
eventSource.sendErrorMessageToChat();
|
|
2830
|
-
|
|
2831
|
-
threadId: threadId || (0, import_shared10.randomId)(),
|
|
2832
|
-
runId: runId || (0, import_shared10.randomId)(),
|
|
2833
|
-
eventSource,
|
|
2834
|
-
serverSideActions: [],
|
|
2835
|
-
actionInputsWithoutAgents: []
|
|
2836
|
-
};
|
|
3150
|
+
throw error;
|
|
2837
3151
|
}
|
|
2838
3152
|
}
|
|
2839
3153
|
async processAgentRequest(request) {
|
|
@@ -2849,7 +3163,7 @@ var CopilotRuntime = class {
|
|
|
2849
3163
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2850
3164
|
name: action.name,
|
|
2851
3165
|
description: action.description,
|
|
2852
|
-
jsonSchema: JSON.stringify((0,
|
|
3166
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters))
|
|
2853
3167
|
}));
|
|
2854
3168
|
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2855
3169
|
...serverSideActionsInput,
|
|
@@ -3036,6 +3350,7 @@ MessageInput = _ts_decorate2([
|
|
|
3036
3350
|
], MessageInput);
|
|
3037
3351
|
var TextMessageInput = class {
|
|
3038
3352
|
content;
|
|
3353
|
+
parentMessageId;
|
|
3039
3354
|
role;
|
|
3040
3355
|
};
|
|
3041
3356
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -3043,6 +3358,12 @@ _ts_decorate2([
|
|
|
3043
3358
|
(0, import_type_graphql3.Field)(() => String),
|
|
3044
3359
|
_ts_metadata2("design:type", String)
|
|
3045
3360
|
], TextMessageInput.prototype, "content", void 0);
|
|
3361
|
+
_ts_decorate2([
|
|
3362
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3363
|
+
nullable: true
|
|
3364
|
+
}),
|
|
3365
|
+
_ts_metadata2("design:type", String)
|
|
3366
|
+
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
3046
3367
|
_ts_decorate2([
|
|
3047
3368
|
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
3048
3369
|
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -3053,6 +3374,7 @@ TextMessageInput = _ts_decorate2([
|
|
|
3053
3374
|
var ActionExecutionMessageInput = class {
|
|
3054
3375
|
name;
|
|
3055
3376
|
arguments;
|
|
3377
|
+
parentMessageId;
|
|
3056
3378
|
scope;
|
|
3057
3379
|
};
|
|
3058
3380
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -3065,8 +3387,17 @@ _ts_decorate2([
|
|
|
3065
3387
|
_ts_metadata2("design:type", String)
|
|
3066
3388
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
3067
3389
|
_ts_decorate2([
|
|
3068
|
-
(0, import_type_graphql3.Field)(() =>
|
|
3069
|
-
|
|
3390
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3391
|
+
nullable: true
|
|
3392
|
+
}),
|
|
3393
|
+
_ts_metadata2("design:type", String)
|
|
3394
|
+
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
3395
|
+
_ts_decorate2([
|
|
3396
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3397
|
+
nullable: true,
|
|
3398
|
+
deprecationReason: "This field will be removed in a future version"
|
|
3399
|
+
}),
|
|
3400
|
+
_ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
|
|
3070
3401
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
3071
3402
|
ActionExecutionMessageInput = _ts_decorate2([
|
|
3072
3403
|
(0, import_type_graphql3.InputType)()
|
|
@@ -3074,6 +3405,7 @@ ActionExecutionMessageInput = _ts_decorate2([
|
|
|
3074
3405
|
var ResultMessageInput = class {
|
|
3075
3406
|
actionExecutionId;
|
|
3076
3407
|
actionName;
|
|
3408
|
+
parentMessageId;
|
|
3077
3409
|
result;
|
|
3078
3410
|
};
|
|
3079
3411
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -3085,6 +3417,12 @@ _ts_decorate2([
|
|
|
3085
3417
|
(0, import_type_graphql3.Field)(() => String),
|
|
3086
3418
|
_ts_metadata2("design:type", String)
|
|
3087
3419
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
3420
|
+
_ts_decorate2([
|
|
3421
|
+
(0, import_type_graphql3.Field)(() => String, {
|
|
3422
|
+
nullable: true
|
|
3423
|
+
}),
|
|
3424
|
+
_ts_metadata2("design:type", String)
|
|
3425
|
+
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
3088
3426
|
_ts_decorate2([
|
|
3089
3427
|
(0, import_type_graphql3.Field)(() => String),
|
|
3090
3428
|
_ts_metadata2("design:type", String)
|
|
@@ -3348,6 +3686,7 @@ var ForwardedParametersInput = class {
|
|
|
3348
3686
|
stop;
|
|
3349
3687
|
toolChoice;
|
|
3350
3688
|
toolChoiceFunctionName;
|
|
3689
|
+
temperature;
|
|
3351
3690
|
};
|
|
3352
3691
|
__name(ForwardedParametersInput, "ForwardedParametersInput");
|
|
3353
3692
|
_ts_decorate7([
|
|
@@ -3382,6 +3721,12 @@ _ts_decorate7([
|
|
|
3382
3721
|
}),
|
|
3383
3722
|
_ts_metadata7("design:type", String)
|
|
3384
3723
|
], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
|
|
3724
|
+
_ts_decorate7([
|
|
3725
|
+
(0, import_type_graphql8.Field)(() => Number, {
|
|
3726
|
+
nullable: true
|
|
3727
|
+
}),
|
|
3728
|
+
_ts_metadata7("design:type", Number)
|
|
3729
|
+
], ForwardedParametersInput.prototype, "temperature", void 0);
|
|
3385
3730
|
ForwardedParametersInput = _ts_decorate7([
|
|
3386
3731
|
(0, import_type_graphql8.InputType)()
|
|
3387
3732
|
], ForwardedParametersInput);
|
|
@@ -3807,6 +4152,7 @@ BaseMessageOutput = _ts_decorate13([
|
|
|
3807
4152
|
var TextMessageOutput = class {
|
|
3808
4153
|
role;
|
|
3809
4154
|
content;
|
|
4155
|
+
parentMessageId;
|
|
3810
4156
|
};
|
|
3811
4157
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
3812
4158
|
_ts_decorate13([
|
|
@@ -3819,6 +4165,12 @@ _ts_decorate13([
|
|
|
3819
4165
|
]),
|
|
3820
4166
|
_ts_metadata13("design:type", Array)
|
|
3821
4167
|
], TextMessageOutput.prototype, "content", void 0);
|
|
4168
|
+
_ts_decorate13([
|
|
4169
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4170
|
+
nullable: true
|
|
4171
|
+
}),
|
|
4172
|
+
_ts_metadata13("design:type", String)
|
|
4173
|
+
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
3822
4174
|
TextMessageOutput = _ts_decorate13([
|
|
3823
4175
|
(0, import_type_graphql14.ObjectType)({
|
|
3824
4176
|
implements: BaseMessageOutput
|
|
@@ -3828,6 +4180,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
3828
4180
|
name;
|
|
3829
4181
|
scope;
|
|
3830
4182
|
arguments;
|
|
4183
|
+
parentMessageId;
|
|
3831
4184
|
};
|
|
3832
4185
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
3833
4186
|
_ts_decorate13([
|
|
@@ -3835,8 +4188,11 @@ _ts_decorate13([
|
|
|
3835
4188
|
_ts_metadata13("design:type", String)
|
|
3836
4189
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
3837
4190
|
_ts_decorate13([
|
|
3838
|
-
(0, import_type_graphql14.Field)(() =>
|
|
3839
|
-
|
|
4191
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4192
|
+
nullable: true,
|
|
4193
|
+
deprecationReason: "This field will be removed in a future version"
|
|
4194
|
+
}),
|
|
4195
|
+
_ts_metadata13("design:type", String)
|
|
3840
4196
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
3841
4197
|
_ts_decorate13([
|
|
3842
4198
|
(0, import_type_graphql14.Field)(() => [
|
|
@@ -3844,6 +4200,12 @@ _ts_decorate13([
|
|
|
3844
4200
|
]),
|
|
3845
4201
|
_ts_metadata13("design:type", Array)
|
|
3846
4202
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
4203
|
+
_ts_decorate13([
|
|
4204
|
+
(0, import_type_graphql14.Field)(() => String, {
|
|
4205
|
+
nullable: true
|
|
4206
|
+
}),
|
|
4207
|
+
_ts_metadata13("design:type", String)
|
|
4208
|
+
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
3847
4209
|
ActionExecutionMessageOutput = _ts_decorate13([
|
|
3848
4210
|
(0, import_type_graphql14.ObjectType)({
|
|
3849
4211
|
implements: BaseMessageOutput
|
|
@@ -3954,7 +4316,7 @@ CopilotResponse = _ts_decorate13([
|
|
|
3954
4316
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3955
4317
|
var import_graphql_yoga = require("graphql-yoga");
|
|
3956
4318
|
var import_graphql_scalars2 = require("graphql-scalars");
|
|
3957
|
-
var
|
|
4319
|
+
var import_class_transformer3 = require("class-transformer");
|
|
3958
4320
|
var import_graphql = require("graphql");
|
|
3959
4321
|
|
|
3960
4322
|
// src/utils/failed-response-status-reasons.ts
|
|
@@ -3991,7 +4353,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
3991
4353
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
3992
4354
|
|
|
3993
4355
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3994
|
-
var
|
|
4356
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
3995
4357
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
3996
4358
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3997
4359
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4108,7 +4470,7 @@ var CopilotResolver = class {
|
|
|
4108
4470
|
rejectOutputMessagesPromise = reject;
|
|
4109
4471
|
});
|
|
4110
4472
|
logger2.debug("Processing");
|
|
4111
|
-
const { eventSource, threadId = (0,
|
|
4473
|
+
const { eventSource, threadId = (0, import_shared13.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
4112
4474
|
serviceAdapter,
|
|
4113
4475
|
messages: data.messages,
|
|
4114
4476
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -4152,8 +4514,8 @@ var CopilotResolver = class {
|
|
|
4152
4514
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
4153
4515
|
});
|
|
4154
4516
|
outputMessages = [
|
|
4155
|
-
(0,
|
|
4156
|
-
id: (0,
|
|
4517
|
+
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4518
|
+
id: (0, import_shared13.randomId)(),
|
|
4157
4519
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4158
4520
|
content: result.reason,
|
|
4159
4521
|
role: MessageRole.assistant
|
|
@@ -4201,12 +4563,15 @@ var CopilotResolver = class {
|
|
|
4201
4563
|
// skip until this message start event
|
|
4202
4564
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4203
4565
|
// take until the message end event
|
|
4204
|
-
(0, import_rxjs4.takeWhile)((e) => e.type
|
|
4566
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
4567
|
+
// filter out any other message events or message ids
|
|
4568
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
4205
4569
|
);
|
|
4206
4570
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4207
4571
|
const messageId = event.messageId;
|
|
4208
4572
|
pushMessage({
|
|
4209
4573
|
id: messageId,
|
|
4574
|
+
parentMessageId: event.parentMessageId,
|
|
4210
4575
|
status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
|
|
4211
4576
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4212
4577
|
role: MessageRole.assistant,
|
|
@@ -4219,7 +4584,7 @@ var CopilotResolver = class {
|
|
|
4219
4584
|
reason,
|
|
4220
4585
|
messageId: messageId2
|
|
4221
4586
|
}, "Text streaming interrupted");
|
|
4222
|
-
streamingTextStatus.next((0,
|
|
4587
|
+
streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4223
4588
|
reason
|
|
4224
4589
|
}));
|
|
4225
4590
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -4252,7 +4617,7 @@ var CopilotResolver = class {
|
|
|
4252
4617
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
4253
4618
|
stopStreamingText();
|
|
4254
4619
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
4255
|
-
outputMessages.push((0,
|
|
4620
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
4256
4621
|
id: messageId,
|
|
4257
4622
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4258
4623
|
content: textChunks.join(""),
|
|
@@ -4265,14 +4630,20 @@ var CopilotResolver = class {
|
|
|
4265
4630
|
break;
|
|
4266
4631
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4267
4632
|
logger2.debug("Action execution start event received");
|
|
4268
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4633
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4634
|
+
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4635
|
+
// take until the action execution end event
|
|
4636
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4637
|
+
// filter out any other action execution events or action execution ids
|
|
4638
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4639
|
+
);
|
|
4269
4640
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4270
4641
|
pushMessage({
|
|
4271
4642
|
id: event.actionExecutionId,
|
|
4643
|
+
parentMessageId: event.parentMessageId,
|
|
4272
4644
|
status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
|
|
4273
4645
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4274
4646
|
name: event.actionName,
|
|
4275
|
-
scope: event.scope,
|
|
4276
4647
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
4277
4648
|
logger2.debug("Action execution argument stream created");
|
|
4278
4649
|
const argumentChunks = [];
|
|
@@ -4288,7 +4659,7 @@ var CopilotResolver = class {
|
|
|
4288
4659
|
logger2.error({
|
|
4289
4660
|
err
|
|
4290
4661
|
}, "Error in action execution argument stream");
|
|
4291
|
-
streamingArgumentsStatus.next((0,
|
|
4662
|
+
streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
|
|
4292
4663
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
4293
4664
|
}));
|
|
4294
4665
|
stopStreamingArguments();
|
|
@@ -4299,11 +4670,10 @@ var CopilotResolver = class {
|
|
|
4299
4670
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
4300
4671
|
stopStreamingArguments();
|
|
4301
4672
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
4302
|
-
outputMessages.push((0,
|
|
4673
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
|
|
4303
4674
|
id: event.actionExecutionId,
|
|
4304
4675
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4305
4676
|
name: event.actionName,
|
|
4306
|
-
scope: event.scope,
|
|
4307
4677
|
arguments: argumentChunks.join("")
|
|
4308
4678
|
}));
|
|
4309
4679
|
}
|
|
@@ -4316,15 +4686,15 @@ var CopilotResolver = class {
|
|
|
4316
4686
|
result: event.result
|
|
4317
4687
|
}, "Action execution result event received");
|
|
4318
4688
|
pushMessage({
|
|
4319
|
-
id:
|
|
4689
|
+
id: "result-" + event.actionExecutionId,
|
|
4320
4690
|
status: new SuccessMessageStatus(),
|
|
4321
4691
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4322
4692
|
actionExecutionId: event.actionExecutionId,
|
|
4323
4693
|
actionName: event.actionName,
|
|
4324
4694
|
result: event.result
|
|
4325
4695
|
});
|
|
4326
|
-
outputMessages.push((0,
|
|
4327
|
-
id:
|
|
4696
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
|
|
4697
|
+
id: "result-" + event.actionExecutionId,
|
|
4328
4698
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4329
4699
|
actionExecutionId: event.actionExecutionId,
|
|
4330
4700
|
actionName: event.actionName,
|
|
@@ -4336,7 +4706,7 @@ var CopilotResolver = class {
|
|
|
4336
4706
|
event
|
|
4337
4707
|
}, "Agent message event received");
|
|
4338
4708
|
pushMessage({
|
|
4339
|
-
id: (0,
|
|
4709
|
+
id: (0, import_shared13.randomId)(),
|
|
4340
4710
|
status: new SuccessMessageStatus(),
|
|
4341
4711
|
threadId: event.threadId,
|
|
4342
4712
|
agentName: event.agentName,
|
|
@@ -4348,8 +4718,8 @@ var CopilotResolver = class {
|
|
|
4348
4718
|
role: MessageRole.assistant,
|
|
4349
4719
|
createdAt: /* @__PURE__ */ new Date()
|
|
4350
4720
|
});
|
|
4351
|
-
outputMessages.push((0,
|
|
4352
|
-
id: (0,
|
|
4721
|
+
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
4722
|
+
id: (0, import_shared13.randomId)(),
|
|
4353
4723
|
threadId: event.threadId,
|
|
4354
4724
|
agentName: event.agentName,
|
|
4355
4725
|
nodeName: event.nodeName,
|
|
@@ -4640,6 +5010,8 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4640
5010
|
0 && (module.exports = {
|
|
4641
5011
|
AnthropicAdapter,
|
|
4642
5012
|
CopilotRuntime,
|
|
5013
|
+
ExperimentalEmptyAdapter,
|
|
5014
|
+
ExperimentalOllamaAdapter,
|
|
4643
5015
|
GoogleGenerativeAIAdapter,
|
|
4644
5016
|
GroqAdapter,
|
|
4645
5017
|
GuardrailsValidationFailureResponse,
|