@copilotkit/runtime 1.4.0-pre-1-4-0.11 → 1.4.0-pre-1-4-0-alpha.10
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 +33 -100
- package/dist/{chunk-BNQDVBQH.mjs → chunk-56IQ6PGC.mjs} +449 -75
- package/dist/chunk-56IQ6PGC.mjs.map +1 -0
- package/dist/chunk-DFOKBSIS.mjs +1 -0
- package/dist/chunk-DFOKBSIS.mjs.map +1 -0
- package/dist/{chunk-VBGS6IWV.mjs → chunk-RDHJQVWH.mjs} +483 -71
- package/dist/chunk-RDHJQVWH.mjs.map +1 -0
- package/dist/{chunk-V2YEM4Z5.mjs → chunk-SBWLAAB3.mjs} +4 -3
- package/dist/chunk-SBWLAAB3.mjs.map +1 -0
- package/dist/{chunk-677K33J7.mjs → chunk-SVL5LEKB.mjs} +4 -3
- package/dist/chunk-SVL5LEKB.mjs.map +1 -0
- package/dist/{chunk-3DNY5YTL.mjs → chunk-YUJSVJWS.mjs} +5 -4
- package/dist/chunk-YUJSVJWS.mjs.map +1 -0
- package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-dbe5fa02.d.ts} +4 -4
- package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-192d2413.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +486 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -22
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f00629d2.d.ts → langserve-878c62b9.d.ts} +46 -9
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +465 -163
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +21 -21
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +161 -85
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +158 -82
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +158 -82
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +157 -81
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +3 -3
- package/dist/service-adapters/index.js +243 -73
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -2
- package/package.json +4 -4
- package/src/agents/langgraph/event-source.ts +12 -0
- package/src/agents/langgraph/events.ts +2 -0
- package/src/graphql/resolvers/copilot.resolver.ts +28 -2
- package/src/lib/integrations/nest/index.ts +5 -2
- package/src/lib/integrations/nextjs/app-router.ts +5 -2
- package/src/lib/integrations/nextjs/pages-router.ts +5 -2
- package/src/lib/integrations/node-express/index.ts +5 -2
- package/src/lib/integrations/node-http/index.ts +5 -2
- package/src/lib/runtime/copilot-runtime.ts +48 -42
- package/src/lib/runtime/remote-action-constructors.ts +17 -3
- package/src/lib/runtime/remote-lg-cloud-action.ts +41 -15
- package/src/lib/telemetry-client.ts +43 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +15 -6
- package/src/service-adapters/events.ts +86 -36
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/google/google-genai-adapter.ts +2 -2
- package/src/service-adapters/groq/groq-adapter.ts +22 -8
- package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
- package/src/service-adapters/langchain/utils.ts +47 -31
- package/src/service-adapters/openai/openai-adapter.ts +25 -8
- package/src/service-adapters/openai/openai-assistant-adapter.ts +21 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-3DNY5YTL.mjs.map +0 -1
- package/dist/chunk-677K33J7.mjs.map +0 -1
- package/dist/chunk-BNQDVBQH.mjs.map +0 -1
- package/dist/chunk-FL67XJAX.mjs +0 -288
- package/dist/chunk-FL67XJAX.mjs.map +0 -1
- package/dist/chunk-MXXPWWBF.mjs +0 -218
- package/dist/chunk-MXXPWWBF.mjs.map +0 -1
- package/dist/chunk-V2YEM4Z5.mjs.map +0 -1
- package/dist/chunk-VBGS6IWV.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.4.0-pre-1-4-0.
|
|
47
|
+
version: "1.4.0-pre-1-4-0-alpha.10",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -147,13 +147,14 @@ __export(src_exports, {
|
|
|
147
147
|
createContext: () => createContext,
|
|
148
148
|
flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
|
|
149
149
|
getCommonConfig: () => getCommonConfig,
|
|
150
|
-
langGraphCloudEndpoint: () => langGraphCloudEndpoint
|
|
150
|
+
langGraphCloudEndpoint: () => langGraphCloudEndpoint,
|
|
151
|
+
resolveEndpointType: () => resolveEndpointType
|
|
151
152
|
});
|
|
152
153
|
module.exports = __toCommonJS(src_exports);
|
|
153
154
|
var import_reflect_metadata = require("reflect-metadata");
|
|
154
155
|
|
|
155
156
|
// src/lib/runtime/copilot-runtime.ts
|
|
156
|
-
var
|
|
157
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
157
158
|
|
|
158
159
|
// src/service-adapters/langchain/langserve.ts
|
|
159
160
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -429,35 +430,61 @@ var OpenAIAdapter = class {
|
|
|
429
430
|
eventSource.stream(async (eventStream$) => {
|
|
430
431
|
var _a, _b;
|
|
431
432
|
let mode = null;
|
|
433
|
+
let currentMessageId;
|
|
434
|
+
let currentToolCallId;
|
|
432
435
|
for await (const chunk of stream) {
|
|
436
|
+
if (chunk.choices.length === 0) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
433
439
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
434
440
|
const content = chunk.choices[0].delta.content;
|
|
435
441
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
436
442
|
mode = null;
|
|
437
|
-
eventStream$.sendTextMessageEnd(
|
|
443
|
+
eventStream$.sendTextMessageEnd({
|
|
444
|
+
messageId: currentMessageId
|
|
445
|
+
});
|
|
438
446
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
439
447
|
mode = null;
|
|
440
|
-
eventStream$.sendActionExecutionEnd(
|
|
448
|
+
eventStream$.sendActionExecutionEnd({
|
|
449
|
+
actionExecutionId: currentToolCallId
|
|
450
|
+
});
|
|
441
451
|
}
|
|
442
452
|
if (mode === null) {
|
|
443
453
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
444
454
|
mode = "function";
|
|
445
|
-
|
|
455
|
+
currentToolCallId = toolCall.id;
|
|
456
|
+
eventStream$.sendActionExecutionStart({
|
|
457
|
+
actionExecutionId: currentToolCallId,
|
|
458
|
+
actionName: toolCall.function.name
|
|
459
|
+
});
|
|
446
460
|
} else if (content) {
|
|
447
461
|
mode = "message";
|
|
448
|
-
|
|
462
|
+
currentMessageId = chunk.id;
|
|
463
|
+
eventStream$.sendTextMessageStart({
|
|
464
|
+
messageId: currentMessageId
|
|
465
|
+
});
|
|
449
466
|
}
|
|
450
467
|
}
|
|
451
468
|
if (mode === "message" && content) {
|
|
452
|
-
eventStream$.sendTextMessageContent(
|
|
469
|
+
eventStream$.sendTextMessageContent({
|
|
470
|
+
messageId: currentMessageId,
|
|
471
|
+
content
|
|
472
|
+
});
|
|
453
473
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
454
|
-
eventStream$.sendActionExecutionArgs(
|
|
474
|
+
eventStream$.sendActionExecutionArgs({
|
|
475
|
+
actionExecutionId: currentToolCallId,
|
|
476
|
+
args: toolCall.function.arguments
|
|
477
|
+
});
|
|
455
478
|
}
|
|
456
479
|
}
|
|
457
480
|
if (mode === "message") {
|
|
458
|
-
eventStream$.sendTextMessageEnd(
|
|
481
|
+
eventStream$.sendTextMessageEnd({
|
|
482
|
+
messageId: currentMessageId
|
|
483
|
+
});
|
|
459
484
|
} else if (mode === "function") {
|
|
460
|
-
eventStream$.sendActionExecutionEnd(
|
|
485
|
+
eventStream$.sendActionExecutionEnd({
|
|
486
|
+
actionExecutionId: currentToolCallId
|
|
487
|
+
});
|
|
461
488
|
}
|
|
462
489
|
eventStream$.complete();
|
|
463
490
|
});
|
|
@@ -553,7 +580,11 @@ function isBaseMessageChunk(message) {
|
|
|
553
580
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
554
581
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
555
582
|
if (actionExecution) {
|
|
556
|
-
eventStream$.sendActionExecutionResult(
|
|
583
|
+
eventStream$.sendActionExecutionResult({
|
|
584
|
+
actionExecutionId: actionExecution.id,
|
|
585
|
+
actionName: actionExecution.name,
|
|
586
|
+
result: "Sending a message"
|
|
587
|
+
});
|
|
557
588
|
}
|
|
558
589
|
}
|
|
559
590
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
@@ -563,7 +594,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
563
594
|
if (!actionExecution) {
|
|
564
595
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
565
596
|
} else {
|
|
566
|
-
eventStream$.sendActionExecutionResult(
|
|
597
|
+
eventStream$.sendActionExecutionResult({
|
|
598
|
+
actionExecutionId: actionExecution.id,
|
|
599
|
+
actionName: actionExecution.name,
|
|
600
|
+
result
|
|
601
|
+
});
|
|
567
602
|
}
|
|
568
603
|
} else if (isAIMessage(result)) {
|
|
569
604
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -571,7 +606,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
571
606
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
572
607
|
}
|
|
573
608
|
for (const toolCall of result.tool_calls) {
|
|
574
|
-
eventStream$.sendActionExecution(
|
|
609
|
+
eventStream$.sendActionExecution({
|
|
610
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
611
|
+
actionName: toolCall.name,
|
|
612
|
+
args: JSON.stringify(toolCall.args)
|
|
613
|
+
});
|
|
575
614
|
}
|
|
576
615
|
} else if (isBaseMessageChunk(result)) {
|
|
577
616
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -580,7 +619,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
580
619
|
}
|
|
581
620
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
582
621
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
583
|
-
eventStream$.sendActionExecution(
|
|
622
|
+
eventStream$.sendActionExecution({
|
|
623
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
624
|
+
actionName: toolCall.name,
|
|
625
|
+
args: JSON.stringify(toolCall.args)
|
|
626
|
+
});
|
|
584
627
|
}
|
|
585
628
|
}
|
|
586
629
|
} else if (result && "getReader" in result) {
|
|
@@ -598,6 +641,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
598
641
|
const { done, value } = await reader.read();
|
|
599
642
|
let toolCallName = void 0;
|
|
600
643
|
let toolCallId = void 0;
|
|
644
|
+
let currentMessageId;
|
|
601
645
|
let toolCallArgs = void 0;
|
|
602
646
|
let hasToolCall = false;
|
|
603
647
|
let content = value == null ? void 0 : value.content;
|
|
@@ -625,10 +669,14 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
625
669
|
}
|
|
626
670
|
if (mode === "message" && (toolCallId || done)) {
|
|
627
671
|
mode = null;
|
|
628
|
-
eventStream$.sendTextMessageEnd(
|
|
672
|
+
eventStream$.sendTextMessageEnd({
|
|
673
|
+
messageId: currentMessageId
|
|
674
|
+
});
|
|
629
675
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
630
676
|
mode = null;
|
|
631
|
-
eventStream$.sendActionExecutionEnd(
|
|
677
|
+
eventStream$.sendActionExecutionEnd({
|
|
678
|
+
actionExecutionId: toolCallId
|
|
679
|
+
});
|
|
632
680
|
}
|
|
633
681
|
if (done) {
|
|
634
682
|
break;
|
|
@@ -636,21 +684,38 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
636
684
|
if (mode === null) {
|
|
637
685
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
638
686
|
mode = "function";
|
|
639
|
-
eventStream$.sendActionExecutionStart(
|
|
687
|
+
eventStream$.sendActionExecutionStart({
|
|
688
|
+
actionExecutionId: toolCallId,
|
|
689
|
+
actionName: toolCallName
|
|
690
|
+
});
|
|
640
691
|
} else if (content) {
|
|
641
692
|
mode = "message";
|
|
642
|
-
|
|
693
|
+
currentMessageId = (0, import_shared2.randomId)();
|
|
694
|
+
eventStream$.sendTextMessageStart({
|
|
695
|
+
messageId: currentMessageId
|
|
696
|
+
});
|
|
643
697
|
}
|
|
644
698
|
}
|
|
645
699
|
if (mode === "message" && content) {
|
|
646
|
-
eventStream$.sendTextMessageContent(
|
|
700
|
+
eventStream$.sendTextMessageContent({
|
|
701
|
+
messageId: currentMessageId,
|
|
702
|
+
content: Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content
|
|
703
|
+
});
|
|
647
704
|
} else if (mode === "function" && toolCallArgs) {
|
|
648
705
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
649
|
-
eventStream$.sendActionExecutionEnd(
|
|
650
|
-
|
|
706
|
+
eventStream$.sendActionExecutionEnd({
|
|
707
|
+
actionExecutionId: toolCallId
|
|
708
|
+
});
|
|
709
|
+
eventStream$.sendActionExecutionStart({
|
|
710
|
+
actionExecutionId: toolCallId,
|
|
711
|
+
actionName: toolCallName
|
|
712
|
+
});
|
|
651
713
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
652
714
|
}
|
|
653
|
-
eventStream$.sendActionExecutionArgs(
|
|
715
|
+
eventStream$.sendActionExecutionArgs({
|
|
716
|
+
actionExecutionId: toolCallId,
|
|
717
|
+
args: toolCallArgs
|
|
718
|
+
});
|
|
654
719
|
}
|
|
655
720
|
} catch (error) {
|
|
656
721
|
console.error("Error reading from stream", error);
|
|
@@ -658,7 +723,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
658
723
|
}
|
|
659
724
|
}
|
|
660
725
|
} else if (actionExecution) {
|
|
661
|
-
eventStream$.sendActionExecutionResult(
|
|
726
|
+
eventStream$.sendActionExecutionResult({
|
|
727
|
+
actionExecutionId: actionExecution.id,
|
|
728
|
+
actionName: actionExecution.name,
|
|
729
|
+
result: encodeResult(result)
|
|
730
|
+
});
|
|
662
731
|
} else {
|
|
663
732
|
throw new Error("Invalid return type from LangChain function.");
|
|
664
733
|
}
|
|
@@ -678,6 +747,7 @@ __name(encodeResult, "encodeResult");
|
|
|
678
747
|
|
|
679
748
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
680
749
|
var import_shared3 = require("@copilotkit/shared");
|
|
750
|
+
var import_promises = require("@langchain/core/callbacks/promises");
|
|
681
751
|
var LangChainAdapter = class {
|
|
682
752
|
options;
|
|
683
753
|
/**
|
|
@@ -687,23 +757,28 @@ var LangChainAdapter = class {
|
|
|
687
757
|
this.options = options;
|
|
688
758
|
}
|
|
689
759
|
async process(request) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
await streamLangChainResponse({
|
|
700
|
-
result,
|
|
701
|
-
eventStream$
|
|
760
|
+
try {
|
|
761
|
+
const { eventSource, model, actions, messages, runId } = request;
|
|
762
|
+
const threadId = request.threadId ?? (0, import_shared3.randomId)();
|
|
763
|
+
const result = await this.options.chainFn({
|
|
764
|
+
messages: messages.map(convertMessageToLangChainMessage),
|
|
765
|
+
tools: actions.map(convertActionInputToLangChainTool),
|
|
766
|
+
model,
|
|
767
|
+
threadId,
|
|
768
|
+
runId
|
|
702
769
|
});
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
770
|
+
eventSource.stream(async (eventStream$) => {
|
|
771
|
+
await streamLangChainResponse({
|
|
772
|
+
result,
|
|
773
|
+
eventStream$
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
return {
|
|
777
|
+
threadId
|
|
778
|
+
};
|
|
779
|
+
} finally {
|
|
780
|
+
await (0, import_promises.awaitAllCallbacks)();
|
|
781
|
+
}
|
|
707
782
|
}
|
|
708
783
|
};
|
|
709
784
|
__name(LangChainAdapter, "LangChainAdapter");
|
|
@@ -713,12 +788,16 @@ var import_google_gauth = require("@langchain/google-gauth");
|
|
|
713
788
|
var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
714
789
|
constructor(options) {
|
|
715
790
|
super({
|
|
716
|
-
chainFn: async ({ messages, tools }) => {
|
|
791
|
+
chainFn: async ({ messages, tools, threadId }) => {
|
|
717
792
|
const model = new import_google_gauth.ChatGoogle({
|
|
718
793
|
modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
|
|
719
794
|
apiVersion: "v1beta"
|
|
720
795
|
}).bindTools(tools);
|
|
721
|
-
return model.stream(messages
|
|
796
|
+
return model.stream(messages, {
|
|
797
|
+
metadata: {
|
|
798
|
+
conversation_id: threadId
|
|
799
|
+
}
|
|
800
|
+
});
|
|
722
801
|
}
|
|
723
802
|
});
|
|
724
803
|
}
|
|
@@ -828,21 +907,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
828
907
|
eventSource.stream(async (eventStream$) => {
|
|
829
908
|
var _a, _b, _c, _d, _e, _f;
|
|
830
909
|
let inFunctionCall = false;
|
|
910
|
+
let currentMessageId;
|
|
911
|
+
let currentToolCallId;
|
|
831
912
|
for await (const chunk of stream) {
|
|
832
913
|
switch (chunk.event) {
|
|
833
914
|
case "thread.message.created":
|
|
834
915
|
if (inFunctionCall) {
|
|
835
|
-
eventStream$.sendActionExecutionEnd(
|
|
916
|
+
eventStream$.sendActionExecutionEnd({
|
|
917
|
+
actionExecutionId: currentToolCallId
|
|
918
|
+
});
|
|
836
919
|
}
|
|
837
|
-
|
|
920
|
+
currentMessageId = chunk.data.id;
|
|
921
|
+
eventStream$.sendTextMessageStart({
|
|
922
|
+
messageId: currentMessageId
|
|
923
|
+
});
|
|
838
924
|
break;
|
|
839
925
|
case "thread.message.delta":
|
|
840
926
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
841
|
-
eventStream$.sendTextMessageContent(
|
|
927
|
+
eventStream$.sendTextMessageContent({
|
|
928
|
+
messageId: currentMessageId,
|
|
929
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
930
|
+
});
|
|
842
931
|
}
|
|
843
932
|
break;
|
|
844
933
|
case "thread.message.completed":
|
|
845
|
-
eventStream$.sendTextMessageEnd(
|
|
934
|
+
eventStream$.sendTextMessageEnd({
|
|
935
|
+
messageId: currentMessageId
|
|
936
|
+
});
|
|
846
937
|
break;
|
|
847
938
|
case "thread.run.step.delta":
|
|
848
939
|
let toolCallId;
|
|
@@ -855,18 +946,29 @@ var OpenAIAssistantAdapter = class {
|
|
|
855
946
|
}
|
|
856
947
|
if (toolCallName && toolCallId) {
|
|
857
948
|
if (inFunctionCall) {
|
|
858
|
-
eventStream$.sendActionExecutionEnd(
|
|
949
|
+
eventStream$.sendActionExecutionEnd({
|
|
950
|
+
actionExecutionId: currentToolCallId
|
|
951
|
+
});
|
|
859
952
|
}
|
|
860
953
|
inFunctionCall = true;
|
|
861
|
-
|
|
954
|
+
currentToolCallId = toolCallId;
|
|
955
|
+
eventStream$.sendActionExecutionStart({
|
|
956
|
+
actionExecutionId: currentToolCallId,
|
|
957
|
+
actionName: toolCallName
|
|
958
|
+
});
|
|
862
959
|
} else if (toolCallArgs) {
|
|
863
|
-
eventStream$.sendActionExecutionArgs(
|
|
960
|
+
eventStream$.sendActionExecutionArgs({
|
|
961
|
+
actionExecutionId: currentToolCallId,
|
|
962
|
+
args: toolCallArgs
|
|
963
|
+
});
|
|
864
964
|
}
|
|
865
965
|
break;
|
|
866
966
|
}
|
|
867
967
|
}
|
|
868
968
|
if (inFunctionCall) {
|
|
869
|
-
eventStream$.sendActionExecutionEnd(
|
|
969
|
+
eventStream$.sendActionExecutionEnd({
|
|
970
|
+
actionExecutionId: currentToolCallId
|
|
971
|
+
});
|
|
870
972
|
}
|
|
871
973
|
eventStream$.complete();
|
|
872
974
|
});
|
|
@@ -919,46 +1021,77 @@ var UnifyAdapter = class {
|
|
|
919
1021
|
}
|
|
920
1022
|
});
|
|
921
1023
|
let model = null;
|
|
1024
|
+
let currentMessageId;
|
|
1025
|
+
let currentToolCallId;
|
|
922
1026
|
request.eventSource.stream(async (eventStream$) => {
|
|
923
1027
|
var _a, _b;
|
|
924
1028
|
let mode = null;
|
|
925
1029
|
for await (const chunk of stream) {
|
|
926
1030
|
if (this.start) {
|
|
927
1031
|
model = chunk.model;
|
|
928
|
-
|
|
929
|
-
eventStream$.
|
|
930
|
-
|
|
931
|
-
|
|
1032
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
1033
|
+
eventStream$.sendTextMessageStart({
|
|
1034
|
+
messageId: currentMessageId
|
|
1035
|
+
});
|
|
1036
|
+
eventStream$.sendTextMessageContent({
|
|
1037
|
+
messageId: currentMessageId,
|
|
1038
|
+
content: `Model used: ${model}
|
|
1039
|
+
`
|
|
1040
|
+
});
|
|
1041
|
+
eventStream$.sendTextMessageEnd({
|
|
1042
|
+
messageId: currentMessageId
|
|
1043
|
+
});
|
|
932
1044
|
this.start = false;
|
|
933
1045
|
}
|
|
934
1046
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
935
1047
|
const content = chunk.choices[0].delta.content;
|
|
936
1048
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
937
1049
|
mode = null;
|
|
938
|
-
eventStream$.sendTextMessageEnd(
|
|
1050
|
+
eventStream$.sendTextMessageEnd({
|
|
1051
|
+
messageId: currentMessageId
|
|
1052
|
+
});
|
|
939
1053
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
940
1054
|
mode = null;
|
|
941
|
-
eventStream$.sendActionExecutionEnd(
|
|
1055
|
+
eventStream$.sendActionExecutionEnd({
|
|
1056
|
+
actionExecutionId: currentToolCallId
|
|
1057
|
+
});
|
|
942
1058
|
}
|
|
943
1059
|
if (mode === null) {
|
|
944
1060
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
945
1061
|
mode = "function";
|
|
946
|
-
|
|
1062
|
+
currentToolCallId = toolCall.id;
|
|
1063
|
+
eventStream$.sendActionExecutionStart({
|
|
1064
|
+
actionExecutionId: currentToolCallId,
|
|
1065
|
+
actionName: toolCall.function.name
|
|
1066
|
+
});
|
|
947
1067
|
} else if (content) {
|
|
948
1068
|
mode = "message";
|
|
949
|
-
|
|
1069
|
+
currentMessageId = chunk.id;
|
|
1070
|
+
eventStream$.sendTextMessageStart({
|
|
1071
|
+
messageId: currentMessageId
|
|
1072
|
+
});
|
|
950
1073
|
}
|
|
951
1074
|
}
|
|
952
1075
|
if (mode === "message" && content) {
|
|
953
|
-
eventStream$.sendTextMessageContent(
|
|
1076
|
+
eventStream$.sendTextMessageContent({
|
|
1077
|
+
messageId: currentMessageId,
|
|
1078
|
+
content
|
|
1079
|
+
});
|
|
954
1080
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
955
|
-
eventStream$.sendActionExecutionArgs(
|
|
1081
|
+
eventStream$.sendActionExecutionArgs({
|
|
1082
|
+
actionExecutionId: currentToolCallId,
|
|
1083
|
+
args: toolCall.function.arguments
|
|
1084
|
+
});
|
|
956
1085
|
}
|
|
957
1086
|
}
|
|
958
1087
|
if (mode === "message") {
|
|
959
|
-
eventStream$.sendTextMessageEnd(
|
|
1088
|
+
eventStream$.sendTextMessageEnd({
|
|
1089
|
+
messageId: currentMessageId
|
|
1090
|
+
});
|
|
960
1091
|
} else if (mode === "function") {
|
|
961
|
-
eventStream$.sendActionExecutionEnd(
|
|
1092
|
+
eventStream$.sendActionExecutionEnd({
|
|
1093
|
+
actionExecutionId: currentToolCallId
|
|
1094
|
+
});
|
|
962
1095
|
}
|
|
963
1096
|
eventStream$.complete();
|
|
964
1097
|
});
|
|
@@ -1024,35 +1157,58 @@ var GroqAdapter = class {
|
|
|
1024
1157
|
eventSource.stream(async (eventStream$) => {
|
|
1025
1158
|
var _a, _b;
|
|
1026
1159
|
let mode = null;
|
|
1160
|
+
let currentMessageId;
|
|
1161
|
+
let currentToolCallId;
|
|
1027
1162
|
for await (const chunk of stream) {
|
|
1028
1163
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
1029
1164
|
const content = chunk.choices[0].delta.content;
|
|
1030
1165
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
1031
1166
|
mode = null;
|
|
1032
|
-
eventStream$.sendTextMessageEnd(
|
|
1167
|
+
eventStream$.sendTextMessageEnd({
|
|
1168
|
+
messageId: currentMessageId
|
|
1169
|
+
});
|
|
1033
1170
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
1034
1171
|
mode = null;
|
|
1035
|
-
eventStream$.sendActionExecutionEnd(
|
|
1172
|
+
eventStream$.sendActionExecutionEnd({
|
|
1173
|
+
actionExecutionId: currentToolCallId
|
|
1174
|
+
});
|
|
1036
1175
|
}
|
|
1037
1176
|
if (mode === null) {
|
|
1038
1177
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1039
1178
|
mode = "function";
|
|
1040
|
-
|
|
1179
|
+
currentToolCallId = toolCall.id;
|
|
1180
|
+
eventStream$.sendActionExecutionStart({
|
|
1181
|
+
actionExecutionId: currentToolCallId,
|
|
1182
|
+
actionName: toolCall.function.name
|
|
1183
|
+
});
|
|
1041
1184
|
} else if (content) {
|
|
1042
1185
|
mode = "message";
|
|
1043
|
-
|
|
1186
|
+
currentMessageId = chunk.id;
|
|
1187
|
+
eventStream$.sendTextMessageStart({
|
|
1188
|
+
messageId: currentMessageId
|
|
1189
|
+
});
|
|
1044
1190
|
}
|
|
1045
1191
|
}
|
|
1046
1192
|
if (mode === "message" && content) {
|
|
1047
|
-
eventStream$.sendTextMessageContent(
|
|
1193
|
+
eventStream$.sendTextMessageContent({
|
|
1194
|
+
messageId: currentMessageId,
|
|
1195
|
+
content
|
|
1196
|
+
});
|
|
1048
1197
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1049
|
-
eventStream$.sendActionExecutionArgs(
|
|
1198
|
+
eventStream$.sendActionExecutionArgs({
|
|
1199
|
+
actionExecutionId: currentToolCallId,
|
|
1200
|
+
args: toolCall.function.arguments
|
|
1201
|
+
});
|
|
1050
1202
|
}
|
|
1051
1203
|
}
|
|
1052
1204
|
if (mode === "message") {
|
|
1053
|
-
eventStream$.sendTextMessageEnd(
|
|
1205
|
+
eventStream$.sendTextMessageEnd({
|
|
1206
|
+
messageId: currentMessageId
|
|
1207
|
+
});
|
|
1054
1208
|
} else if (mode === "function") {
|
|
1055
|
-
eventStream$.sendActionExecutionEnd(
|
|
1209
|
+
eventStream$.sendActionExecutionEnd({
|
|
1210
|
+
actionExecutionId: currentToolCallId
|
|
1211
|
+
});
|
|
1056
1212
|
}
|
|
1057
1213
|
eventStream$.complete();
|
|
1058
1214
|
});
|
|
@@ -1260,7 +1416,10 @@ var AnthropicAdapter = class {
|
|
|
1260
1416
|
mode = "message";
|
|
1261
1417
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1262
1418
|
currentToolCallId = chunk.content_block.id;
|
|
1263
|
-
eventStream$.sendActionExecutionStart(
|
|
1419
|
+
eventStream$.sendActionExecutionStart({
|
|
1420
|
+
actionExecutionId: currentToolCallId,
|
|
1421
|
+
actionName: chunk.content_block.name
|
|
1422
|
+
});
|
|
1264
1423
|
mode = "function";
|
|
1265
1424
|
}
|
|
1266
1425
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1268,21 +1427,33 @@ var AnthropicAdapter = class {
|
|
|
1268
1427
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1269
1428
|
if (text.length > 0) {
|
|
1270
1429
|
if (!didOutputText) {
|
|
1271
|
-
eventStream$.sendTextMessageStart(
|
|
1430
|
+
eventStream$.sendTextMessageStart({
|
|
1431
|
+
messageId: currentMessageId
|
|
1432
|
+
});
|
|
1272
1433
|
didOutputText = true;
|
|
1273
1434
|
}
|
|
1274
|
-
eventStream$.sendTextMessageContent(
|
|
1435
|
+
eventStream$.sendTextMessageContent({
|
|
1436
|
+
messageId: currentMessageId,
|
|
1437
|
+
content: text
|
|
1438
|
+
});
|
|
1275
1439
|
}
|
|
1276
1440
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1277
|
-
eventStream$.sendActionExecutionArgs(
|
|
1441
|
+
eventStream$.sendActionExecutionArgs({
|
|
1442
|
+
actionExecutionId: currentToolCallId,
|
|
1443
|
+
args: chunk.delta.partial_json
|
|
1444
|
+
});
|
|
1278
1445
|
}
|
|
1279
1446
|
} else if (chunk.type === "content_block_stop") {
|
|
1280
1447
|
if (mode === "message") {
|
|
1281
1448
|
if (didOutputText) {
|
|
1282
|
-
eventStream$.sendTextMessageEnd(
|
|
1449
|
+
eventStream$.sendTextMessageEnd({
|
|
1450
|
+
messageId: currentMessageId
|
|
1451
|
+
});
|
|
1283
1452
|
}
|
|
1284
1453
|
} else if (mode === "function") {
|
|
1285
|
-
eventStream$.sendActionExecutionEnd(
|
|
1454
|
+
eventStream$.sendActionExecutionEnd({
|
|
1455
|
+
actionExecutionId: currentToolCallId
|
|
1456
|
+
});
|
|
1286
1457
|
}
|
|
1287
1458
|
}
|
|
1288
1459
|
}
|
|
@@ -1328,16 +1499,14 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1328
1499
|
}, "FilterThinkingTextBuffer");
|
|
1329
1500
|
|
|
1330
1501
|
// src/service-adapters/events.ts
|
|
1502
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1331
1503
|
var import_rxjs2 = require("rxjs");
|
|
1332
1504
|
|
|
1333
1505
|
// src/lib/telemetry-client.ts
|
|
1334
|
-
var
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
packageVersion: packageJson.version
|
|
1339
|
-
});
|
|
1340
|
-
var telemetry_client_default = telemetryClient;
|
|
1506
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1507
|
+
|
|
1508
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1509
|
+
var import_node_crypto2 = require("crypto");
|
|
1341
1510
|
|
|
1342
1511
|
// src/agents/langgraph/event-source.ts
|
|
1343
1512
|
var import_rxjs = require("rxjs");
|
|
@@ -1354,6 +1523,8 @@ var LangGraphEventTypes;
|
|
|
1354
1523
|
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
1355
1524
|
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
1356
1525
|
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
1526
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
1527
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
1357
1528
|
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
1358
1529
|
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
1359
1530
|
var CustomEventNames;
|
|
@@ -1365,7 +1536,7 @@ var CustomEventNames;
|
|
|
1365
1536
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1366
1537
|
|
|
1367
1538
|
// src/agents/langgraph/event-source.ts
|
|
1368
|
-
var
|
|
1539
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1369
1540
|
var RemoteLangGraphEventSource = class {
|
|
1370
1541
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1371
1542
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1447,12 +1618,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1447
1618
|
}
|
|
1448
1619
|
if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1449
1620
|
events.push({
|
|
1450
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1621
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1622
|
+
actionExecutionId: eventWithState.prevToolCallMessageId
|
|
1451
1623
|
});
|
|
1452
1624
|
}
|
|
1453
1625
|
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1454
1626
|
events.push({
|
|
1455
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1627
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1628
|
+
messageId: eventWithState.prevMessageId
|
|
1456
1629
|
});
|
|
1457
1630
|
}
|
|
1458
1631
|
switch (eventWithState.event.event) {
|
|
@@ -1464,10 +1637,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1464
1637
|
});
|
|
1465
1638
|
events.push({
|
|
1466
1639
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1640
|
+
messageId: eventWithState.event.data.message_id,
|
|
1467
1641
|
content: eventWithState.event.data.message
|
|
1468
1642
|
});
|
|
1469
1643
|
events.push({
|
|
1470
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1644
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1645
|
+
messageId: eventWithState.event.data.message_id
|
|
1471
1646
|
});
|
|
1472
1647
|
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1473
1648
|
events.push({
|
|
@@ -1477,10 +1652,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1477
1652
|
});
|
|
1478
1653
|
events.push({
|
|
1479
1654
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1655
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1480
1656
|
args: JSON.stringify(eventWithState.event.data.args)
|
|
1481
1657
|
});
|
|
1482
1658
|
events.push({
|
|
1483
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1659
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1660
|
+
actionExecutionId: eventWithState.event.data.id
|
|
1484
1661
|
});
|
|
1485
1662
|
}
|
|
1486
1663
|
break;
|
|
@@ -1524,6 +1701,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1524
1701
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1525
1702
|
events.push({
|
|
1526
1703
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1704
|
+
actionExecutionId: eventWithState.toolCallMessageId,
|
|
1527
1705
|
args
|
|
1528
1706
|
});
|
|
1529
1707
|
}
|
|
@@ -1531,6 +1709,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1531
1709
|
if (shouldEmitMessages) {
|
|
1532
1710
|
events.push({
|
|
1533
1711
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1712
|
+
messageId: eventWithState.messageId,
|
|
1534
1713
|
content
|
|
1535
1714
|
});
|
|
1536
1715
|
}
|
|
@@ -1543,25 +1722,29 @@ var RemoteLangGraphEventSource = class {
|
|
|
1543
1722
|
const events = [];
|
|
1544
1723
|
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1545
1724
|
events.push({
|
|
1546
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1725
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1726
|
+
messageId: lastEventWithState.messageId
|
|
1547
1727
|
});
|
|
1548
1728
|
}
|
|
1549
1729
|
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1550
1730
|
events.push({
|
|
1551
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1731
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1732
|
+
actionExecutionId: lastEventWithState.toolCallMessageId
|
|
1552
1733
|
});
|
|
1553
1734
|
}
|
|
1554
|
-
const messageId = (0,
|
|
1735
|
+
const messageId = (0, import_shared7.randomId)();
|
|
1555
1736
|
events.push({
|
|
1556
1737
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1557
1738
|
messageId
|
|
1558
1739
|
});
|
|
1559
1740
|
events.push({
|
|
1560
1741
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1742
|
+
messageId,
|
|
1561
1743
|
content: "\u274C An error occurred. Please try again."
|
|
1562
1744
|
});
|
|
1563
1745
|
events.push({
|
|
1564
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1746
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1747
|
+
messageId
|
|
1565
1748
|
});
|
|
1566
1749
|
return events;
|
|
1567
1750
|
}));
|
|
@@ -1624,6 +1807,7 @@ async function execute(args) {
|
|
|
1624
1807
|
}
|
|
1625
1808
|
__name(execute, "execute");
|
|
1626
1809
|
async function streamEvents(controller, args) {
|
|
1810
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1627
1811
|
const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions, logger: logger2 } = args;
|
|
1628
1812
|
let nodeName = initialNodeName;
|
|
1629
1813
|
let state = initialState;
|
|
@@ -1697,7 +1881,14 @@ async function streamEvents(controller, args) {
|
|
|
1697
1881
|
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1698
1882
|
let latestStateValues = {};
|
|
1699
1883
|
let updatedState = state;
|
|
1884
|
+
let manuallyEmittedState = null;
|
|
1885
|
+
let streamInfo = {
|
|
1886
|
+
hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
|
|
1887
|
+
};
|
|
1700
1888
|
try {
|
|
1889
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1890
|
+
hashedLgcKey: streamInfo.hashedLgcKey
|
|
1891
|
+
});
|
|
1701
1892
|
for await (const chunk of streamResponse2) {
|
|
1702
1893
|
if (![
|
|
1703
1894
|
"events",
|
|
@@ -1719,26 +1910,37 @@ async function streamEvents(controller, args) {
|
|
|
1719
1910
|
const runId = event.metadata.run_id;
|
|
1720
1911
|
externalRunId = runId;
|
|
1721
1912
|
const metadata = event.metadata;
|
|
1913
|
+
if (((_b = (_a = event.data) == null ? void 0 : _a.output) == null ? void 0 : _b.model) != null && ((_d = (_c = event.data) == null ? void 0 : _c.output) == null ? void 0 : _d.model) != "") {
|
|
1914
|
+
streamInfo.provider = (_f = (_e = event.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
|
|
1915
|
+
}
|
|
1916
|
+
if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
|
|
1917
|
+
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
1918
|
+
}
|
|
1919
|
+
if (metadata.langgraph_version != null && metadata.langgraph_version != "") {
|
|
1920
|
+
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
1921
|
+
}
|
|
1722
1922
|
shouldExit = shouldExit || eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitExit;
|
|
1723
1923
|
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1724
1924
|
const manuallyEmitIntermediateState = eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
|
|
1925
|
+
const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
|
|
1926
|
+
if (exitingNode) {
|
|
1927
|
+
manuallyEmittedState = null;
|
|
1928
|
+
}
|
|
1725
1929
|
if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
|
|
1726
1930
|
nodeName = currentNodeName;
|
|
1727
|
-
if (eventType === LangGraphEventTypes.OnChainStart || eventType === LangGraphEventTypes.OnChainEnd) {
|
|
1728
|
-
updatedState = latestStateValues;
|
|
1729
|
-
}
|
|
1730
1931
|
}
|
|
1932
|
+
updatedState = manuallyEmittedState ?? latestStateValues;
|
|
1731
1933
|
if (!nodeName) {
|
|
1732
1934
|
continue;
|
|
1733
1935
|
}
|
|
1734
1936
|
if (manuallyEmitIntermediateState) {
|
|
1735
|
-
|
|
1937
|
+
manuallyEmittedState = event.data;
|
|
1736
1938
|
emit(getStateSyncEvent({
|
|
1737
1939
|
threadId,
|
|
1738
1940
|
runId,
|
|
1739
1941
|
agentName: agent.name,
|
|
1740
1942
|
nodeName,
|
|
1741
|
-
state:
|
|
1943
|
+
state: manuallyEmittedState,
|
|
1742
1944
|
running: true,
|
|
1743
1945
|
active: true
|
|
1744
1946
|
}));
|
|
@@ -1762,7 +1964,6 @@ async function streamEvents(controller, args) {
|
|
|
1762
1964
|
if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === LangGraphEventTypes.OnChainEnd) {
|
|
1763
1965
|
emitIntermediateStateUntilEnd = null;
|
|
1764
1966
|
}
|
|
1765
|
-
const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
|
|
1766
1967
|
if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
|
|
1767
1968
|
state = updatedState;
|
|
1768
1969
|
prevNodeName = nodeName;
|
|
@@ -1781,6 +1982,7 @@ async function streamEvents(controller, args) {
|
|
|
1781
1982
|
state = await client.threads.getState(threadId);
|
|
1782
1983
|
const isEndNode = state.next.length === 0;
|
|
1783
1984
|
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1985
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
|
|
1784
1986
|
emit(getStateSyncEvent({
|
|
1785
1987
|
threadId,
|
|
1786
1988
|
runId: externalRunId,
|
|
@@ -2028,7 +2230,12 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2028
2230
|
logger2.debug({
|
|
2029
2231
|
actionName: agent.name
|
|
2030
2232
|
}, "Executing LangGraph Cloud agent");
|
|
2031
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2233
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2234
|
+
agentExecution: true,
|
|
2235
|
+
type: "langgraph-cloud",
|
|
2236
|
+
agentsAmount: endpoint.agents.length,
|
|
2237
|
+
hashedLgcKey: (0, import_node_crypto2.createHash)("sha256").update(endpoint.langsmithApiKey).digest("hex")
|
|
2238
|
+
});
|
|
2032
2239
|
let state = {};
|
|
2033
2240
|
if (agentStates) {
|
|
2034
2241
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -2082,7 +2289,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2082
2289
|
args
|
|
2083
2290
|
}, "Executing remote action");
|
|
2084
2291
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
2085
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2292
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2293
|
+
agentExecution: false,
|
|
2294
|
+
type: "self-hosted",
|
|
2295
|
+
agentsAmount: json["agents"].length
|
|
2296
|
+
});
|
|
2086
2297
|
try {
|
|
2087
2298
|
const response = await fetch(`${url}/actions/execute`, {
|
|
2088
2299
|
method: "POST",
|
|
@@ -2128,7 +2339,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2128
2339
|
actionName: agent.name
|
|
2129
2340
|
}, "Executing remote agent");
|
|
2130
2341
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
2131
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2342
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
2343
|
+
agentExecution: true,
|
|
2344
|
+
type: "self-hosted",
|
|
2345
|
+
agentsAmount: json["agents"].length
|
|
2346
|
+
});
|
|
2132
2347
|
let state = {};
|
|
2133
2348
|
if (agentStates) {
|
|
2134
2349
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -2339,6 +2554,53 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
|
|
|
2339
2554
|
}
|
|
2340
2555
|
__name(setupRemoteActions, "setupRemoteActions");
|
|
2341
2556
|
|
|
2557
|
+
// src/lib/telemetry-client.ts
|
|
2558
|
+
var import_node_crypto3 = require("crypto");
|
|
2559
|
+
var packageJson = require_package();
|
|
2560
|
+
var telemetryClient = new import_shared8.TelemetryClient({
|
|
2561
|
+
packageName: packageJson.name,
|
|
2562
|
+
packageVersion: packageJson.version
|
|
2563
|
+
});
|
|
2564
|
+
function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
2565
|
+
const endpointsInfo = runtime.remoteEndpointDefinitions.reduce((acc, endpoint) => {
|
|
2566
|
+
let info = {
|
|
2567
|
+
...acc
|
|
2568
|
+
};
|
|
2569
|
+
const endpointType = resolveEndpointType(endpoint);
|
|
2570
|
+
if (!info.endpointTypes.includes(endpointType)) {
|
|
2571
|
+
info = {
|
|
2572
|
+
...info,
|
|
2573
|
+
endpointTypes: [
|
|
2574
|
+
...info.endpointTypes,
|
|
2575
|
+
endpointType
|
|
2576
|
+
]
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
if (endpointType === EndpointType.LangGraphCloud) {
|
|
2580
|
+
const ep = endpoint;
|
|
2581
|
+
info = {
|
|
2582
|
+
...info,
|
|
2583
|
+
agentsAmount: ep.agents.length,
|
|
2584
|
+
hashedKey: (0, import_node_crypto3.createHash)("sha256").update(ep.langsmithApiKey).digest("hex")
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
return info;
|
|
2588
|
+
}, {
|
|
2589
|
+
endpointTypes: [],
|
|
2590
|
+
agentsAmount: null,
|
|
2591
|
+
hashedKey: null
|
|
2592
|
+
});
|
|
2593
|
+
return {
|
|
2594
|
+
actionsAmount: runtime.actions.length,
|
|
2595
|
+
endpointsAmount: runtime.remoteEndpointDefinitions.length,
|
|
2596
|
+
endpointTypes: endpointsInfo.endpointTypes,
|
|
2597
|
+
agentsAmount: endpointsInfo.agentsAmount,
|
|
2598
|
+
hashedLgcKey: endpointsInfo.hashedKey
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2602
|
+
var telemetry_client_default = telemetryClient;
|
|
2603
|
+
|
|
2342
2604
|
// src/service-adapters/events.ts
|
|
2343
2605
|
var RuntimeEventTypes;
|
|
2344
2606
|
(function(RuntimeEventTypes2) {
|
|
@@ -2355,52 +2617,71 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2355
2617
|
constructor() {
|
|
2356
2618
|
super();
|
|
2357
2619
|
}
|
|
2358
|
-
sendTextMessageStart(messageId) {
|
|
2620
|
+
sendTextMessageStart({ messageId }) {
|
|
2359
2621
|
this.next({
|
|
2360
2622
|
type: "TextMessageStart",
|
|
2361
2623
|
messageId
|
|
2362
2624
|
});
|
|
2363
2625
|
}
|
|
2364
|
-
sendTextMessageContent(content) {
|
|
2626
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2365
2627
|
this.next({
|
|
2366
2628
|
type: "TextMessageContent",
|
|
2367
|
-
content
|
|
2629
|
+
content,
|
|
2630
|
+
messageId
|
|
2368
2631
|
});
|
|
2369
2632
|
}
|
|
2370
|
-
sendTextMessageEnd() {
|
|
2633
|
+
sendTextMessageEnd({ messageId }) {
|
|
2371
2634
|
this.next({
|
|
2372
|
-
type: "TextMessageEnd"
|
|
2635
|
+
type: "TextMessageEnd",
|
|
2636
|
+
messageId
|
|
2373
2637
|
});
|
|
2374
2638
|
}
|
|
2375
2639
|
sendTextMessage(messageId, content) {
|
|
2376
|
-
this.sendTextMessageStart(
|
|
2377
|
-
|
|
2378
|
-
|
|
2640
|
+
this.sendTextMessageStart({
|
|
2641
|
+
messageId
|
|
2642
|
+
});
|
|
2643
|
+
this.sendTextMessageContent({
|
|
2644
|
+
messageId,
|
|
2645
|
+
content
|
|
2646
|
+
});
|
|
2647
|
+
this.sendTextMessageEnd({
|
|
2648
|
+
messageId
|
|
2649
|
+
});
|
|
2379
2650
|
}
|
|
2380
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2651
|
+
sendActionExecutionStart({ actionExecutionId, actionName }) {
|
|
2381
2652
|
this.next({
|
|
2382
2653
|
type: "ActionExecutionStart",
|
|
2383
2654
|
actionExecutionId,
|
|
2384
2655
|
actionName
|
|
2385
2656
|
});
|
|
2386
2657
|
}
|
|
2387
|
-
sendActionExecutionArgs(args) {
|
|
2658
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2388
2659
|
this.next({
|
|
2389
2660
|
type: "ActionExecutionArgs",
|
|
2390
|
-
args
|
|
2661
|
+
args,
|
|
2662
|
+
actionExecutionId
|
|
2391
2663
|
});
|
|
2392
2664
|
}
|
|
2393
|
-
sendActionExecutionEnd() {
|
|
2665
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2394
2666
|
this.next({
|
|
2395
|
-
type: "ActionExecutionEnd"
|
|
2667
|
+
type: "ActionExecutionEnd",
|
|
2668
|
+
actionExecutionId
|
|
2396
2669
|
});
|
|
2397
2670
|
}
|
|
2398
|
-
sendActionExecution(actionExecutionId,
|
|
2399
|
-
this.sendActionExecutionStart(
|
|
2400
|
-
|
|
2401
|
-
|
|
2671
|
+
sendActionExecution({ actionExecutionId, actionName, args }) {
|
|
2672
|
+
this.sendActionExecutionStart({
|
|
2673
|
+
actionExecutionId,
|
|
2674
|
+
actionName
|
|
2675
|
+
});
|
|
2676
|
+
this.sendActionExecutionArgs({
|
|
2677
|
+
actionExecutionId,
|
|
2678
|
+
args
|
|
2679
|
+
});
|
|
2680
|
+
this.sendActionExecutionEnd({
|
|
2681
|
+
actionExecutionId
|
|
2682
|
+
});
|
|
2402
2683
|
}
|
|
2403
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2684
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2404
2685
|
this.next({
|
|
2405
2686
|
type: "ActionExecutionResult",
|
|
2406
2687
|
actionName,
|
|
@@ -2408,7 +2689,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
|
|
|
2408
2689
|
result
|
|
2409
2690
|
});
|
|
2410
2691
|
}
|
|
2411
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2692
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2412
2693
|
this.next({
|
|
2413
2694
|
type: "AgentStateMessage",
|
|
2414
2695
|
threadId,
|
|
@@ -2429,9 +2710,20 @@ var RuntimeEventSource = class {
|
|
|
2429
2710
|
async stream(callback) {
|
|
2430
2711
|
this.callback = callback;
|
|
2431
2712
|
}
|
|
2713
|
+
sendErrorMessageToChat() {
|
|
2714
|
+
const errorMessage = "\u274C An error occurred. Please try again.";
|
|
2715
|
+
if (!this.callback) {
|
|
2716
|
+
this.stream(async (eventStream$) => {
|
|
2717
|
+
eventStream$.sendTextMessage((0, import_shared9.randomId)(), errorMessage);
|
|
2718
|
+
});
|
|
2719
|
+
} else {
|
|
2720
|
+
this.eventStream$.sendTextMessage((0, import_shared9.randomId)(), errorMessage);
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2432
2723
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
2433
2724
|
this.callback(this.eventStream$).catch((error) => {
|
|
2434
2725
|
console.error("Error in event source callback", error);
|
|
2726
|
+
this.sendErrorMessageToChat();
|
|
2435
2727
|
});
|
|
2436
2728
|
return this.eventStream$.pipe(
|
|
2437
2729
|
// mark tools for server side execution
|
|
@@ -2503,7 +2795,11 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2503
2795
|
}
|
|
2504
2796
|
}
|
|
2505
2797
|
if (isLangGraphAgentAction(action)) {
|
|
2506
|
-
eventStream$.sendActionExecutionResult(
|
|
2798
|
+
eventStream$.sendActionExecutionResult({
|
|
2799
|
+
actionExecutionId,
|
|
2800
|
+
actionName: action.name,
|
|
2801
|
+
result: `${action.name} agent started`
|
|
2802
|
+
});
|
|
2507
2803
|
const stream = await action.langGraphAgentHandler({
|
|
2508
2804
|
name: action.name,
|
|
2509
2805
|
actionInputsWithoutAgents
|
|
@@ -2674,37 +2970,37 @@ var CopilotRuntime = class {
|
|
|
2674
2970
|
const remoteChain = new RemoteChain(chain);
|
|
2675
2971
|
this.langserve.push(remoteChain.toAction());
|
|
2676
2972
|
}
|
|
2677
|
-
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints)
|
|
2973
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) ?? (params == null ? void 0 : params.remoteActions) ?? [];
|
|
2678
2974
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
2679
2975
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2680
2976
|
}
|
|
2681
2977
|
async processRuntimeRequest(request) {
|
|
2682
2978
|
var _a;
|
|
2683
2979
|
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, agentSession, url } = request;
|
|
2684
|
-
|
|
2685
|
-
return this.processAgentRequest(request);
|
|
2686
|
-
}
|
|
2687
|
-
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2688
|
-
const inputMessages = convertGqlInputToMessages(messages);
|
|
2689
|
-
const serverSideActions = await this.getServerSideActions(request);
|
|
2690
|
-
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2691
|
-
name: action.name,
|
|
2692
|
-
description: action.description,
|
|
2693
|
-
jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters))
|
|
2694
|
-
}));
|
|
2695
|
-
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2696
|
-
...serverSideActionsInput,
|
|
2697
|
-
...clientSideActionsInput
|
|
2698
|
-
]);
|
|
2699
|
-
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2700
|
-
threadId,
|
|
2701
|
-
runId,
|
|
2702
|
-
inputMessages,
|
|
2703
|
-
properties: graphqlContext.properties,
|
|
2704
|
-
url
|
|
2705
|
-
}));
|
|
2980
|
+
const eventSource = new RuntimeEventSource();
|
|
2706
2981
|
try {
|
|
2707
|
-
|
|
2982
|
+
if (agentSession) {
|
|
2983
|
+
return await this.processAgentRequest(request);
|
|
2984
|
+
}
|
|
2985
|
+
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2986
|
+
const inputMessages = convertGqlInputToMessages(messages);
|
|
2987
|
+
const serverSideActions = await this.getServerSideActions(request);
|
|
2988
|
+
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2989
|
+
name: action.name,
|
|
2990
|
+
description: action.description,
|
|
2991
|
+
jsonSchema: JSON.stringify((0, import_shared10.actionParametersToJsonSchema)(action.parameters))
|
|
2992
|
+
}));
|
|
2993
|
+
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2994
|
+
...serverSideActionsInput,
|
|
2995
|
+
...clientSideActionsInput
|
|
2996
|
+
]);
|
|
2997
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2998
|
+
threadId,
|
|
2999
|
+
runId,
|
|
3000
|
+
inputMessages,
|
|
3001
|
+
properties: graphqlContext.properties,
|
|
3002
|
+
url
|
|
3003
|
+
}));
|
|
2708
3004
|
const result = await serviceAdapter.process({
|
|
2709
3005
|
messages: inputMessages,
|
|
2710
3006
|
actions: actionInputs,
|
|
@@ -2737,7 +3033,14 @@ var CopilotRuntime = class {
|
|
|
2737
3033
|
};
|
|
2738
3034
|
} catch (error) {
|
|
2739
3035
|
console.error("Error getting response:", error);
|
|
2740
|
-
|
|
3036
|
+
eventSource.sendErrorMessageToChat();
|
|
3037
|
+
return {
|
|
3038
|
+
threadId: threadId || (0, import_shared10.randomId)(),
|
|
3039
|
+
runId: runId || (0, import_shared10.randomId)(),
|
|
3040
|
+
eventSource,
|
|
3041
|
+
serverSideActions: [],
|
|
3042
|
+
actionInputsWithoutAgents: []
|
|
3043
|
+
};
|
|
2741
3044
|
}
|
|
2742
3045
|
}
|
|
2743
3046
|
async processAgentRequest(request) {
|
|
@@ -2753,7 +3056,7 @@ var CopilotRuntime = class {
|
|
|
2753
3056
|
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2754
3057
|
name: action.name,
|
|
2755
3058
|
description: action.description,
|
|
2756
|
-
jsonSchema: JSON.stringify((0,
|
|
3059
|
+
jsonSchema: JSON.stringify((0, import_shared10.actionParametersToJsonSchema)(action.parameters))
|
|
2757
3060
|
}));
|
|
2758
3061
|
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2759
3062
|
...serverSideActionsInput,
|
|
@@ -2817,7 +3120,7 @@ var CopilotRuntime = class {
|
|
|
2817
3120
|
}
|
|
2818
3121
|
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2819
3122
|
...endpoint,
|
|
2820
|
-
type:
|
|
3123
|
+
type: resolveEndpointType(endpoint)
|
|
2821
3124
|
}));
|
|
2822
3125
|
const remoteActions = await setupRemoteActions({
|
|
2823
3126
|
remoteEndpointDefinitions,
|
|
@@ -2836,12 +3139,6 @@ var CopilotRuntime = class {
|
|
|
2836
3139
|
...remoteActions
|
|
2837
3140
|
];
|
|
2838
3141
|
}
|
|
2839
|
-
resolveEndpointType(endpoint) {
|
|
2840
|
-
if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2841
|
-
return EndpointType.LangGraphCloud;
|
|
2842
|
-
}
|
|
2843
|
-
return endpoint.type;
|
|
2844
|
-
}
|
|
2845
3142
|
};
|
|
2846
3143
|
__name(CopilotRuntime, "CopilotRuntime");
|
|
2847
3144
|
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
@@ -2870,6 +3167,17 @@ function langGraphCloudEndpoint(config2) {
|
|
|
2870
3167
|
};
|
|
2871
3168
|
}
|
|
2872
3169
|
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
3170
|
+
function resolveEndpointType(endpoint) {
|
|
3171
|
+
if (!endpoint.type) {
|
|
3172
|
+
if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
3173
|
+
return EndpointType.LangGraphCloud;
|
|
3174
|
+
} else {
|
|
3175
|
+
return EndpointType.CopilotKit;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
return endpoint.type;
|
|
3179
|
+
}
|
|
3180
|
+
__name(resolveEndpointType, "resolveEndpointType");
|
|
2873
3181
|
|
|
2874
3182
|
// src/lib/integrations/shared.ts
|
|
2875
3183
|
var import_type_graphql16 = require("type-graphql");
|
|
@@ -3883,7 +4191,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
3883
4191
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
3884
4192
|
|
|
3885
4193
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
3886
|
-
var
|
|
4194
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
3887
4195
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
3888
4196
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3889
4197
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -4000,7 +4308,7 @@ var CopilotResolver = class {
|
|
|
4000
4308
|
rejectOutputMessagesPromise = reject;
|
|
4001
4309
|
});
|
|
4002
4310
|
logger2.debug("Processing");
|
|
4003
|
-
const { eventSource, threadId = (0,
|
|
4311
|
+
const { eventSource, threadId = (0, import_shared11.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
4004
4312
|
serviceAdapter,
|
|
4005
4313
|
messages: data.messages,
|
|
4006
4314
|
actions: data.frontend.actions,
|
|
@@ -4045,7 +4353,7 @@ var CopilotResolver = class {
|
|
|
4045
4353
|
});
|
|
4046
4354
|
outputMessages = [
|
|
4047
4355
|
(0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
4048
|
-
id: (0,
|
|
4356
|
+
id: (0, import_shared11.randomId)(),
|
|
4049
4357
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4050
4358
|
content: result.reason,
|
|
4051
4359
|
role: MessageRole.assistant
|
|
@@ -4093,7 +4401,9 @@ var CopilotResolver = class {
|
|
|
4093
4401
|
// skip until this message start event
|
|
4094
4402
|
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4095
4403
|
// take until the message end event
|
|
4096
|
-
(0, import_rxjs4.takeWhile)((e) => e.type
|
|
4404
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
4405
|
+
// filter out any other message events or message ids
|
|
4406
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
4097
4407
|
);
|
|
4098
4408
|
const streamingTextStatus = new import_rxjs4.Subject();
|
|
4099
4409
|
const messageId = event.messageId;
|
|
@@ -4157,7 +4467,13 @@ var CopilotResolver = class {
|
|
|
4157
4467
|
break;
|
|
4158
4468
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
4159
4469
|
logger2.debug("Action execution start event received");
|
|
4160
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4470
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
4471
|
+
(0, import_rxjs4.skipWhile)((e) => e !== event),
|
|
4472
|
+
// take until the action execution end event
|
|
4473
|
+
(0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
4474
|
+
// filter out any other action execution events or action execution ids
|
|
4475
|
+
(0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
4476
|
+
);
|
|
4161
4477
|
const streamingArgumentsStatus = new import_rxjs4.Subject();
|
|
4162
4478
|
pushMessage({
|
|
4163
4479
|
id: event.actionExecutionId,
|
|
@@ -4208,7 +4524,7 @@ var CopilotResolver = class {
|
|
|
4208
4524
|
result: event.result
|
|
4209
4525
|
}, "Action execution result event received");
|
|
4210
4526
|
pushMessage({
|
|
4211
|
-
id: (0,
|
|
4527
|
+
id: (0, import_shared11.randomId)(),
|
|
4212
4528
|
status: new SuccessMessageStatus(),
|
|
4213
4529
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4214
4530
|
actionExecutionId: event.actionExecutionId,
|
|
@@ -4216,7 +4532,7 @@ var CopilotResolver = class {
|
|
|
4216
4532
|
result: event.result
|
|
4217
4533
|
});
|
|
4218
4534
|
outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
4219
|
-
id: (0,
|
|
4535
|
+
id: (0, import_shared11.randomId)(),
|
|
4220
4536
|
createdAt: /* @__PURE__ */ new Date(),
|
|
4221
4537
|
actionExecutionId: event.actionExecutionId,
|
|
4222
4538
|
actionName: event.actionName,
|
|
@@ -4228,7 +4544,7 @@ var CopilotResolver = class {
|
|
|
4228
4544
|
event
|
|
4229
4545
|
}, "Agent message event received");
|
|
4230
4546
|
pushMessage({
|
|
4231
|
-
id: (0,
|
|
4547
|
+
id: (0, import_shared11.randomId)(),
|
|
4232
4548
|
status: new SuccessMessageStatus(),
|
|
4233
4549
|
threadId: event.threadId,
|
|
4234
4550
|
agentName: event.agentName,
|
|
@@ -4241,7 +4557,7 @@ var CopilotResolver = class {
|
|
|
4241
4557
|
createdAt: /* @__PURE__ */ new Date()
|
|
4242
4558
|
});
|
|
4243
4559
|
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
4244
|
-
id: (0,
|
|
4560
|
+
id: (0, import_shared11.randomId)(),
|
|
4245
4561
|
threadId: event.threadId,
|
|
4246
4562
|
agentName: event.agentName,
|
|
4247
4563
|
nodeName: event.nodeName,
|
|
@@ -4429,7 +4745,7 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4429
4745
|
_copilotkit: options.properties._copilotkit
|
|
4430
4746
|
});
|
|
4431
4747
|
}
|
|
4432
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
4748
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
4433
4749
|
const logger2 = commonConfig.logging;
|
|
4434
4750
|
logger2.debug("Creating NextJS App Router endpoint");
|
|
4435
4751
|
const yoga = (0, import_graphql_yoga2.createYoga)({
|
|
@@ -4468,7 +4784,7 @@ function copilotRuntimeNextJSPagesRouterEndpoint(options) {
|
|
|
4468
4784
|
_copilotkit: options.properties._copilotkit
|
|
4469
4785
|
});
|
|
4470
4786
|
}
|
|
4471
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
4787
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
4472
4788
|
const logger2 = commonConfig.logging;
|
|
4473
4789
|
logger2.debug("Creating NextJS Pages Router endpoint");
|
|
4474
4790
|
const yoga = (0, import_graphql_yoga3.createYoga)({
|
|
@@ -4494,7 +4810,7 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4494
4810
|
_copilotkit: options.properties._copilotkit
|
|
4495
4811
|
});
|
|
4496
4812
|
}
|
|
4497
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
4813
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
4498
4814
|
const logger2 = commonConfig.logging;
|
|
4499
4815
|
logger2.debug("Creating Node HTTP endpoint");
|
|
4500
4816
|
const yoga = (0, import_graphql_yoga4.createYoga)({
|
|
@@ -4512,7 +4828,7 @@ function copilotRuntimeNodeExpressEndpoint(options) {
|
|
|
4512
4828
|
framework: "node-express"
|
|
4513
4829
|
}
|
|
4514
4830
|
});
|
|
4515
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
4831
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
4516
4832
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
4517
4833
|
}
|
|
4518
4834
|
__name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
@@ -4524,7 +4840,7 @@ function copilotRuntimeNestEndpoint(options) {
|
|
|
4524
4840
|
framework: "nest"
|
|
4525
4841
|
}
|
|
4526
4842
|
});
|
|
4527
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
4843
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
4528
4844
|
return copilotRuntimeNodeHttpEndpoint(options);
|
|
4529
4845
|
}
|
|
4530
4846
|
__name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
@@ -4553,6 +4869,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4553
4869
|
createContext,
|
|
4554
4870
|
flattenToolCallsNoDuplicates,
|
|
4555
4871
|
getCommonConfig,
|
|
4556
|
-
langGraphCloudEndpoint
|
|
4872
|
+
langGraphCloudEndpoint,
|
|
4873
|
+
resolveEndpointType
|
|
4557
4874
|
});
|
|
4558
4875
|
//# sourceMappingURL=index.js.map
|