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