@copilotkit/runtime 0.37.0 → 0.38.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +69 -54
- package/CHANGELOG.md +11 -0
- package/__snapshots__/schema/schema.graphql +15 -4
- package/dist/{chunk-2CCVVJDU.mjs → chunk-2PJG3NAC.mjs} +13 -15
- package/dist/chunk-2PJG3NAC.mjs.map +1 -0
- package/dist/{chunk-NFCPM5AM.mjs → chunk-6NZ4UMOD.mjs} +4 -4
- package/dist/chunk-6NZ4UMOD.mjs.map +1 -0
- package/dist/{chunk-XPAUPJMW.mjs → chunk-6YGDE3YI.mjs} +432 -220
- package/dist/chunk-6YGDE3YI.mjs.map +1 -0
- package/dist/chunk-BYB2LNMK.mjs +152 -0
- package/dist/chunk-BYB2LNMK.mjs.map +1 -0
- package/dist/{chunk-7IFP53C6.mjs → chunk-FRK6BXXV.mjs} +49 -11
- package/dist/chunk-FRK6BXXV.mjs.map +1 -0
- package/dist/{chunk-5HGYI6EG.mjs → chunk-JBDOA7MK.mjs} +34 -15
- package/dist/chunk-JBDOA7MK.mjs.map +1 -0
- package/dist/{chunk-4UA4RB4C.mjs → chunk-JIKPSUGQ.mjs} +45 -76
- package/dist/chunk-JIKPSUGQ.mjs.map +1 -0
- package/dist/{chunk-BLTAUVRP.mjs → chunk-OZMCHYYR.mjs} +5 -3
- package/dist/{chunk-BLTAUVRP.mjs.map → chunk-OZMCHYYR.mjs.map} +1 -1
- package/dist/chunk-RHQLCJGG.mjs +7 -0
- package/dist/chunk-RHQLCJGG.mjs.map +1 -0
- package/dist/failed-response-status-reasons-0ab19e06.d.ts +49 -0
- package/dist/graphql/types/base/index.mjs +2 -1
- package/dist/graphql/types/converted/index.mjs +3 -2
- package/dist/{index-f0875df3.d.ts → index-0e75acd2.d.ts} +86 -59
- package/dist/index.d.ts +7 -4
- package/dist/index.js +536 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -13
- package/dist/index.mjs.map +1 -1
- package/dist/{langchain-adapter-9ce103f3.d.ts → langchain-adapter-a02d1d38.d.ts} +4 -4
- package/dist/{langserve-fd5066ee.d.ts → langserve-75ebbc38.d.ts} +25 -9
- package/dist/lib/cloud/index.d.ts +6 -0
- package/dist/lib/cloud/index.js +18 -0
- package/dist/lib/cloud/index.js.map +1 -0
- package/dist/lib/cloud/index.mjs +1 -0
- package/dist/lib/cloud/index.mjs.map +1 -0
- package/dist/lib/index.d.ts +6 -4
- package/dist/lib/index.js +530 -169
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -13
- package/dist/lib/integrations/index.d.ts +5 -3
- package/dist/lib/integrations/index.js +426 -64
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +7 -5
- package/dist/lib/integrations/node-http/index.d.ts +4 -2
- package/dist/lib/integrations/node-http/index.js +416 -52
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +6 -4
- package/dist/pages-router-e81920d5.d.ts +21 -0
- package/dist/service-adapters/index.d.ts +2 -2
- package/dist/service-adapters/index.js +82 -25
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -4
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +174 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +6 -4
- package/src/graphql/inputs/cloud-guardrails.input.ts +2 -5
- package/src/graphql/inputs/cloud.input.ts +2 -2
- package/src/graphql/resolvers/copilot.resolver.ts +340 -30
- package/src/graphql/types/response-status.type.ts +16 -2
- package/src/index.ts +1 -0
- package/src/lib/cloud/index.ts +4 -0
- package/src/lib/copilot-runtime.ts +116 -70
- package/src/lib/index.ts +0 -1
- package/src/lib/integrations/nextjs/app-router.ts +9 -17
- package/src/lib/integrations/nextjs/pages-router.ts +9 -15
- package/src/lib/integrations/node-http/index.ts +6 -14
- package/src/lib/integrations/shared.ts +38 -18
- package/src/lib/logger.ts +28 -0
- package/src/service-adapters/events.ts +20 -2
- package/src/service-adapters/experimental/groq/groq-adapter.ts +3 -1
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -1
- package/src/service-adapters/google/google-genai-adapter.ts +6 -1
- package/src/service-adapters/google/utils.ts +1 -1
- package/src/service-adapters/index.ts +1 -1
- package/src/service-adapters/langchain/langchain-adapter.ts +8 -9
- package/src/service-adapters/langchain/langserve.ts +10 -4
- package/src/service-adapters/langchain/utils.ts +58 -9
- package/src/service-adapters/openai/openai-adapter.ts +8 -7
- package/src/service-adapters/openai/openai-assistant-adapter.ts +6 -8
- package/src/service-adapters/service-adapter.ts +1 -2
- package/src/utils/failed-response-status-reasons.ts +48 -0
- package/src/utils/index.ts +1 -0
- package/dist/chunk-2CCVVJDU.mjs.map +0 -1
- package/dist/chunk-4UA4RB4C.mjs.map +0 -1
- package/dist/chunk-5HGYI6EG.mjs.map +0 -1
- package/dist/chunk-7IFP53C6.mjs.map +0 -1
- package/dist/chunk-NFCPM5AM.mjs.map +0 -1
- package/dist/chunk-XPAUPJMW.mjs.map +0 -1
- package/dist/pages-router-b6bc6c60.d.ts +0 -30
- package/src/lib/copilot-cloud.ts +0 -63
- package/src/lib/guardrails.ts +0 -3
package/dist/lib/index.js
CHANGED
|
@@ -30,14 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/lib/index.ts
|
|
31
31
|
var lib_exports = {};
|
|
32
32
|
__export(lib_exports, {
|
|
33
|
-
CopilotBackend: () => CopilotBackend,
|
|
34
|
-
CopilotCloud: () => CopilotCloud,
|
|
35
33
|
CopilotRuntime: () => CopilotRuntime,
|
|
36
34
|
GoogleGenerativeAIAdapter: () => GoogleGenerativeAIAdapter,
|
|
37
35
|
LangChainAdapter: () => LangChainAdapter,
|
|
38
36
|
OpenAIAdapter: () => OpenAIAdapter,
|
|
39
37
|
OpenAIAssistantAdapter: () => OpenAIAssistantAdapter,
|
|
40
|
-
RemoteCopilotCloud: () => RemoteCopilotCloud,
|
|
41
38
|
buildSchema: () => buildSchema,
|
|
42
39
|
config: () => config,
|
|
43
40
|
copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
|
|
@@ -50,7 +47,7 @@ __export(lib_exports, {
|
|
|
50
47
|
module.exports = __toCommonJS(lib_exports);
|
|
51
48
|
|
|
52
49
|
// src/lib/copilot-runtime.ts
|
|
53
|
-
var
|
|
50
|
+
var import_shared = require("@copilotkit/shared");
|
|
54
51
|
|
|
55
52
|
// src/service-adapters/openai/openai-adapter.ts
|
|
56
53
|
var import_openai = __toESM(require("openai"));
|
|
@@ -256,6 +253,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
256
253
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
257
254
|
|
|
258
255
|
// src/service-adapters/openai/openai-adapter.ts
|
|
256
|
+
var import_nanoid = require("nanoid");
|
|
259
257
|
var DEFAULT_MODEL = "gpt-4o";
|
|
260
258
|
var OpenAIAdapter = class {
|
|
261
259
|
model = DEFAULT_MODEL;
|
|
@@ -269,7 +267,8 @@ var OpenAIAdapter = class {
|
|
|
269
267
|
this.model = params.model;
|
|
270
268
|
}
|
|
271
269
|
}
|
|
272
|
-
async process(
|
|
270
|
+
async process(request) {
|
|
271
|
+
const { threadId, model = this.model, messages, actions, eventSource } = request;
|
|
273
272
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
274
273
|
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
275
274
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
@@ -316,7 +315,9 @@ var OpenAIAdapter = class {
|
|
|
316
315
|
}
|
|
317
316
|
eventStream$.complete();
|
|
318
317
|
});
|
|
319
|
-
return {
|
|
318
|
+
return {
|
|
319
|
+
threadId: threadId || (0, import_nanoid.nanoid)()
|
|
320
|
+
};
|
|
320
321
|
}
|
|
321
322
|
};
|
|
322
323
|
__name(OpenAIAdapter, "OpenAIAdapter");
|
|
@@ -334,8 +335,9 @@ var OpenAIAssistantAdapter = class {
|
|
|
334
335
|
this.fileSearchEnabled = params.fileSearchEnabled === false || true;
|
|
335
336
|
this.assistantId = params.assistantId;
|
|
336
337
|
}
|
|
337
|
-
async process(
|
|
338
|
-
|
|
338
|
+
async process(request) {
|
|
339
|
+
const { messages, actions, eventSource, runId } = request;
|
|
340
|
+
let threadId = request.threadId || (await this.openai.beta.threads.create()).id;
|
|
339
341
|
const lastMessage = messages.at(-1);
|
|
340
342
|
let nextRunId = void 0;
|
|
341
343
|
if (lastMessage instanceof ResultMessage && runId) {
|
|
@@ -505,7 +507,7 @@ function convertMessageToGoogleGenAIMessage(message) {
|
|
|
505
507
|
};
|
|
506
508
|
} else if (message instanceof ResultMessage) {
|
|
507
509
|
return {
|
|
508
|
-
role: "
|
|
510
|
+
role: "function",
|
|
509
511
|
parts: [
|
|
510
512
|
{
|
|
511
513
|
functionResponse: {
|
|
@@ -560,7 +562,7 @@ function tryParseJson(str) {
|
|
|
560
562
|
__name(tryParseJson, "tryParseJson");
|
|
561
563
|
|
|
562
564
|
// src/service-adapters/google/google-genai-adapter.ts
|
|
563
|
-
var
|
|
565
|
+
var import_nanoid2 = require("nanoid");
|
|
564
566
|
var GoogleGenerativeAIAdapter = class {
|
|
565
567
|
model;
|
|
566
568
|
constructor(options) {
|
|
@@ -622,9 +624,12 @@ var GoogleGenerativeAIAdapter = class {
|
|
|
622
624
|
let isTextMessage = false;
|
|
623
625
|
for await (const chunk of result.stream) {
|
|
624
626
|
const chunkText = chunk.text();
|
|
627
|
+
if (chunkText === "") {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
625
630
|
if (!isTextMessage) {
|
|
626
631
|
isTextMessage = true;
|
|
627
|
-
eventStream$.sendTextMessageStart((0,
|
|
632
|
+
eventStream$.sendTextMessageStart((0, import_nanoid2.nanoid)());
|
|
628
633
|
}
|
|
629
634
|
eventStream$.sendTextMessageContent(chunkText);
|
|
630
635
|
}
|
|
@@ -634,12 +639,14 @@ var GoogleGenerativeAIAdapter = class {
|
|
|
634
639
|
let calls = (await result.response).functionCalls();
|
|
635
640
|
if (calls) {
|
|
636
641
|
for (let call of calls) {
|
|
637
|
-
eventStream$.sendActionExecution((0,
|
|
642
|
+
eventStream$.sendActionExecution((0, import_nanoid2.nanoid)(), call.name, JSON.stringify(replaceNewlinesInObject(call.args)));
|
|
638
643
|
}
|
|
639
644
|
}
|
|
640
645
|
eventStream$.complete();
|
|
641
646
|
});
|
|
642
|
-
return {
|
|
647
|
+
return {
|
|
648
|
+
threadId: request.threadId || (0, import_nanoid2.nanoid)()
|
|
649
|
+
};
|
|
643
650
|
}
|
|
644
651
|
};
|
|
645
652
|
__name(GoogleGenerativeAIAdapter, "GoogleGenerativeAIAdapter");
|
|
@@ -665,7 +672,7 @@ __name(replaceNewlinesInObject, "replaceNewlinesInObject");
|
|
|
665
672
|
var import_messages = require("@langchain/core/messages");
|
|
666
673
|
var import_tools = require("@langchain/core/tools");
|
|
667
674
|
var import_zod = require("zod");
|
|
668
|
-
var
|
|
675
|
+
var import_nanoid3 = require("nanoid");
|
|
669
676
|
function convertMessageToLangChainMessage(message) {
|
|
670
677
|
if (message instanceof TextMessage) {
|
|
671
678
|
if (message.role == "user") {
|
|
@@ -729,31 +736,59 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
729
736
|
});
|
|
730
737
|
}
|
|
731
738
|
__name(convertActionInputToLangChainTool, "convertActionInputToLangChainTool");
|
|
739
|
+
function getConstructorName(object) {
|
|
740
|
+
if (object && typeof object === "object" && object.constructor && object.constructor.name) {
|
|
741
|
+
return object.constructor.name;
|
|
742
|
+
}
|
|
743
|
+
return "";
|
|
744
|
+
}
|
|
745
|
+
__name(getConstructorName, "getConstructorName");
|
|
746
|
+
function isAIMessage(message) {
|
|
747
|
+
return getConstructorName(message) === "AIMessage";
|
|
748
|
+
}
|
|
749
|
+
__name(isAIMessage, "isAIMessage");
|
|
750
|
+
function isAIMessageChunk(message) {
|
|
751
|
+
return getConstructorName(message) === "AIMessageChunk";
|
|
752
|
+
}
|
|
753
|
+
__name(isAIMessageChunk, "isAIMessageChunk");
|
|
754
|
+
function isBaseMessageChunk(message) {
|
|
755
|
+
return getConstructorName(message) === "BaseMessageChunk";
|
|
756
|
+
}
|
|
757
|
+
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
758
|
+
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
759
|
+
if (actionExecution) {
|
|
760
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
732
764
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
733
765
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
734
766
|
if (typeof result === "string") {
|
|
735
767
|
if (!actionExecution) {
|
|
736
|
-
eventStream$.sendTextMessage((0,
|
|
768
|
+
eventStream$.sendTextMessage((0, import_nanoid3.nanoid)(), result);
|
|
737
769
|
} else {
|
|
738
770
|
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
739
771
|
}
|
|
740
|
-
} else if (result
|
|
772
|
+
} else if (isAIMessage(result)) {
|
|
773
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
741
774
|
if (result.content) {
|
|
742
|
-
eventStream$.sendTextMessage((0,
|
|
775
|
+
eventStream$.sendTextMessage((0, import_nanoid3.nanoid)(), result.content);
|
|
743
776
|
}
|
|
744
777
|
for (const toolCall of result.tool_calls) {
|
|
745
|
-
eventStream$.sendActionExecution(toolCall.id || (0,
|
|
778
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid3.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
746
779
|
}
|
|
747
|
-
} else if (result
|
|
780
|
+
} else if (isBaseMessageChunk(result)) {
|
|
781
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
748
782
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
749
|
-
eventStream$.sendTextMessage((0,
|
|
783
|
+
eventStream$.sendTextMessage((0, import_nanoid3.nanoid)(), result.content);
|
|
750
784
|
}
|
|
751
785
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
752
786
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
753
|
-
eventStream$.sendActionExecution(toolCall.id || (0,
|
|
787
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid3.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
754
788
|
}
|
|
755
789
|
}
|
|
756
|
-
} else if ("getReader" in result) {
|
|
790
|
+
} else if (result && "getReader" in result) {
|
|
791
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
757
792
|
let reader = result.getReader();
|
|
758
793
|
let mode = null;
|
|
759
794
|
while (true) {
|
|
@@ -763,14 +798,14 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
763
798
|
let toolCallId = void 0;
|
|
764
799
|
let toolCallArgs = void 0;
|
|
765
800
|
let hasToolCall = false;
|
|
766
|
-
let content = value.content;
|
|
767
|
-
if (value
|
|
801
|
+
let content = value == null ? void 0 : value.content;
|
|
802
|
+
if (isAIMessageChunk(value)) {
|
|
768
803
|
let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
|
|
769
804
|
toolCallName = chunk == null ? void 0 : chunk.name;
|
|
770
805
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
771
806
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
772
807
|
hasToolCall = chunk != void 0;
|
|
773
|
-
} else if (value
|
|
808
|
+
} else if (isBaseMessageChunk(value)) {
|
|
774
809
|
let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
|
|
775
810
|
toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
|
|
776
811
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
@@ -793,7 +828,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
793
828
|
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
794
829
|
} else if (content) {
|
|
795
830
|
mode = "message";
|
|
796
|
-
eventStream$.sendTextMessageStart((0,
|
|
831
|
+
eventStream$.sendTextMessageStart((0, import_nanoid3.nanoid)());
|
|
797
832
|
}
|
|
798
833
|
}
|
|
799
834
|
if (mode === "message" && content) {
|
|
@@ -807,15 +842,26 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
807
842
|
}
|
|
808
843
|
}
|
|
809
844
|
} else if (actionExecution) {
|
|
810
|
-
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name,
|
|
845
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
811
846
|
} else {
|
|
812
847
|
throw new Error("Invalid return type from LangChain function.");
|
|
813
848
|
}
|
|
814
849
|
eventStream$.complete();
|
|
815
850
|
}
|
|
816
851
|
__name(streamLangChainResponse, "streamLangChainResponse");
|
|
852
|
+
function encodeResult(result) {
|
|
853
|
+
if (result === void 0) {
|
|
854
|
+
return "";
|
|
855
|
+
} else if (typeof result === "string") {
|
|
856
|
+
return result;
|
|
857
|
+
} else {
|
|
858
|
+
return JSON.stringify(result);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
__name(encodeResult, "encodeResult");
|
|
817
862
|
|
|
818
863
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
864
|
+
var import_nanoid4 = require("nanoid");
|
|
819
865
|
var LangChainAdapter = class {
|
|
820
866
|
options;
|
|
821
867
|
/**
|
|
@@ -824,7 +870,8 @@ var LangChainAdapter = class {
|
|
|
824
870
|
constructor(options) {
|
|
825
871
|
this.options = options;
|
|
826
872
|
}
|
|
827
|
-
async process(
|
|
873
|
+
async process(request) {
|
|
874
|
+
const { eventSource, model, actions, messages, threadId, runId } = request;
|
|
828
875
|
const result = await this.options.chainFn({
|
|
829
876
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
830
877
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -838,7 +885,9 @@ var LangChainAdapter = class {
|
|
|
838
885
|
eventStream$
|
|
839
886
|
});
|
|
840
887
|
});
|
|
841
|
-
return {
|
|
888
|
+
return {
|
|
889
|
+
threadId: threadId || (0, import_nanoid4.nanoid)()
|
|
890
|
+
};
|
|
842
891
|
}
|
|
843
892
|
};
|
|
844
893
|
__name(LangChainAdapter, "LangChainAdapter");
|
|
@@ -846,6 +895,11 @@ __name(LangChainAdapter, "LangChainAdapter");
|
|
|
846
895
|
// src/service-adapters/langchain/langserve.ts
|
|
847
896
|
var import_remote = require("langchain/runnables/remote");
|
|
848
897
|
var RemoteChain = class {
|
|
898
|
+
name;
|
|
899
|
+
description;
|
|
900
|
+
chainUrl;
|
|
901
|
+
parameters;
|
|
902
|
+
parameterType;
|
|
849
903
|
constructor(options) {
|
|
850
904
|
this.name = options.name;
|
|
851
905
|
this.description = options.description;
|
|
@@ -916,50 +970,6 @@ var RemoteChain = class {
|
|
|
916
970
|
};
|
|
917
971
|
__name(RemoteChain, "RemoteChain");
|
|
918
972
|
|
|
919
|
-
// src/lib/copilot-cloud.ts
|
|
920
|
-
var import_shared = require("@copilotkit/shared");
|
|
921
|
-
var CopilotCloud = class {
|
|
922
|
-
};
|
|
923
|
-
__name(CopilotCloud, "CopilotCloud");
|
|
924
|
-
var RemoteCopilotCloud = class extends CopilotCloud {
|
|
925
|
-
cloudApiUrl;
|
|
926
|
-
constructor(cloudApiUrl = import_shared.COPILOT_CLOUD_API_URL) {
|
|
927
|
-
super();
|
|
928
|
-
this.cloudApiUrl = cloudApiUrl;
|
|
929
|
-
}
|
|
930
|
-
async checkGuardrailsInput({ cloud, publicApiKey, messages }) {
|
|
931
|
-
const url = `${this.cloudApiUrl}/${import_shared.COPILOT_CLOUD_VERSION}/copilotkit/guardrails/input`;
|
|
932
|
-
const response = await fetch(url, {
|
|
933
|
-
method: "PUT",
|
|
934
|
-
headers: {
|
|
935
|
-
"Content-Type": "application/json",
|
|
936
|
-
[import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
937
|
-
},
|
|
938
|
-
body: JSON.stringify({
|
|
939
|
-
messages,
|
|
940
|
-
cloud
|
|
941
|
-
})
|
|
942
|
-
});
|
|
943
|
-
if (!response.ok) {
|
|
944
|
-
let message = response.statusText;
|
|
945
|
-
try {
|
|
946
|
-
const json2 = await response.json();
|
|
947
|
-
if (json2.message) {
|
|
948
|
-
message = json2.message;
|
|
949
|
-
}
|
|
950
|
-
} catch (error) {
|
|
951
|
-
}
|
|
952
|
-
throw new Error("Failed to check input guardrails: " + message);
|
|
953
|
-
}
|
|
954
|
-
const json = await response.json();
|
|
955
|
-
return {
|
|
956
|
-
status: json.status,
|
|
957
|
-
reason: json.reason
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
__name(RemoteCopilotCloud, "RemoteCopilotCloud");
|
|
962
|
-
|
|
963
973
|
// src/service-adapters/events.ts
|
|
964
974
|
var import_rxjs = require("rxjs");
|
|
965
975
|
var RuntimeEventTypes;
|
|
@@ -1037,7 +1047,7 @@ var RuntimeEventSource = class {
|
|
|
1037
1047
|
async stream(callback) {
|
|
1038
1048
|
this.callback = callback;
|
|
1039
1049
|
}
|
|
1040
|
-
process(serversideActions) {
|
|
1050
|
+
process({ serversideActions, guardrailsResult$ }) {
|
|
1041
1051
|
this.callback(this.eventStream$).catch((error) => {
|
|
1042
1052
|
console.error("Error in event source callback", error);
|
|
1043
1053
|
});
|
|
@@ -1073,7 +1083,7 @@ var RuntimeEventSource = class {
|
|
|
1073
1083
|
(0, import_rxjs.concatMap)((eventWithState) => {
|
|
1074
1084
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
1075
1085
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
1076
|
-
executeAction(toolCallEventStream$, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1086
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1077
1087
|
console.error(error);
|
|
1078
1088
|
});
|
|
1079
1089
|
return (0, import_rxjs.concat)((0, import_rxjs.of)(eventWithState.event), toolCallEventStream$);
|
|
@@ -1085,7 +1095,14 @@ var RuntimeEventSource = class {
|
|
|
1085
1095
|
}
|
|
1086
1096
|
};
|
|
1087
1097
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
1088
|
-
async function executeAction(eventStream$, action, actionArguments, actionExecutionId) {
|
|
1098
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId) {
|
|
1099
|
+
if (guardrailsResult$) {
|
|
1100
|
+
const { status } = await (0, import_rxjs.firstValueFrom)(guardrailsResult$);
|
|
1101
|
+
if (status === "denied") {
|
|
1102
|
+
eventStream$.complete();
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1089
1106
|
let args = [];
|
|
1090
1107
|
if (actionArguments) {
|
|
1091
1108
|
args = JSON.parse(actionArguments);
|
|
@@ -1138,27 +1155,23 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
1138
1155
|
|
|
1139
1156
|
// src/lib/copilot-runtime.ts
|
|
1140
1157
|
var CopilotRuntime = class {
|
|
1141
|
-
actions
|
|
1158
|
+
actions;
|
|
1142
1159
|
langserve = [];
|
|
1143
|
-
|
|
1144
|
-
|
|
1160
|
+
onBeforeRequest;
|
|
1161
|
+
onAfterRequest;
|
|
1145
1162
|
constructor(params) {
|
|
1163
|
+
var _a, _b;
|
|
1146
1164
|
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
1147
1165
|
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
1148
1166
|
const remoteChain = new RemoteChain(chain);
|
|
1149
1167
|
this.langserve.push(remoteChain.toAction());
|
|
1150
1168
|
}
|
|
1151
|
-
this.
|
|
1152
|
-
this.
|
|
1153
|
-
}
|
|
1154
|
-
addAction(action) {
|
|
1155
|
-
this.removeAction(action.name);
|
|
1156
|
-
this.actions.push(action);
|
|
1157
|
-
}
|
|
1158
|
-
removeAction(actionName) {
|
|
1159
|
-
this.actions = this.actions.filter((f) => f.name !== actionName);
|
|
1169
|
+
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
1170
|
+
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
1160
1171
|
}
|
|
1161
|
-
async process(
|
|
1172
|
+
async process(request) {
|
|
1173
|
+
var _a;
|
|
1174
|
+
const { serviceAdapter, messages, actions: clientSideActionsInput, threadId, runId, properties, outputMessagesPromise } = request;
|
|
1162
1175
|
const langserveFunctions = [];
|
|
1163
1176
|
for (const chainPromise of this.langserve) {
|
|
1164
1177
|
try {
|
|
@@ -1168,31 +1181,54 @@ var CopilotRuntime = class {
|
|
|
1168
1181
|
console.error("Error loading langserve chain:", error);
|
|
1169
1182
|
}
|
|
1170
1183
|
}
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1184
|
+
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
1185
|
+
properties
|
|
1186
|
+
}) : this.actions;
|
|
1187
|
+
const actions = [
|
|
1188
|
+
...configuredActions,
|
|
1173
1189
|
...langserveFunctions
|
|
1174
|
-
]
|
|
1190
|
+
];
|
|
1191
|
+
const serverSideActionsInput = actions.map((action) => ({
|
|
1175
1192
|
name: action.name,
|
|
1176
1193
|
description: action.description,
|
|
1177
|
-
jsonSchema: JSON.stringify((0,
|
|
1194
|
+
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters))
|
|
1178
1195
|
}));
|
|
1179
|
-
const
|
|
1196
|
+
const actionInputs = flattenToolCallsNoDuplicates([
|
|
1180
1197
|
...serverSideActionsInput,
|
|
1181
1198
|
...clientSideActionsInput
|
|
1182
1199
|
]);
|
|
1200
|
+
const inputMessages = convertGqlInputToMessages(messages);
|
|
1201
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
1202
|
+
threadId,
|
|
1203
|
+
runId,
|
|
1204
|
+
inputMessages,
|
|
1205
|
+
properties
|
|
1206
|
+
}));
|
|
1183
1207
|
try {
|
|
1184
1208
|
const eventSource = new RuntimeEventSource();
|
|
1185
1209
|
const result = await serviceAdapter.process({
|
|
1186
|
-
messages:
|
|
1187
|
-
actions,
|
|
1210
|
+
messages: inputMessages,
|
|
1211
|
+
actions: actionInputs,
|
|
1188
1212
|
threadId,
|
|
1189
1213
|
runId,
|
|
1190
1214
|
eventSource
|
|
1191
1215
|
});
|
|
1216
|
+
outputMessagesPromise.then((outputMessages) => {
|
|
1217
|
+
var _a2;
|
|
1218
|
+
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
1219
|
+
threadId: result.threadId,
|
|
1220
|
+
runId: result.runId,
|
|
1221
|
+
inputMessages,
|
|
1222
|
+
outputMessages,
|
|
1223
|
+
properties
|
|
1224
|
+
});
|
|
1225
|
+
}).catch((_error) => {
|
|
1226
|
+
});
|
|
1192
1227
|
return {
|
|
1193
1228
|
threadId: result.threadId,
|
|
1194
1229
|
runId: result.runId,
|
|
1195
|
-
eventSource
|
|
1230
|
+
eventSource,
|
|
1231
|
+
actions
|
|
1196
1232
|
};
|
|
1197
1233
|
} catch (error) {
|
|
1198
1234
|
console.error("Error getting response:", error);
|
|
@@ -1213,9 +1249,6 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
|
1213
1249
|
return allTools;
|
|
1214
1250
|
}
|
|
1215
1251
|
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
1216
|
-
var CopilotBackend = class extends CopilotRuntime {
|
|
1217
|
-
};
|
|
1218
|
-
__name(CopilotBackend, "CopilotBackend");
|
|
1219
1252
|
|
|
1220
1253
|
// src/lib/integrations/shared.ts
|
|
1221
1254
|
var import_type_graphql13 = require("type-graphql");
|
|
@@ -1458,15 +1491,10 @@ function _ts_metadata5(k, v) {
|
|
|
1458
1491
|
}
|
|
1459
1492
|
__name(_ts_metadata5, "_ts_metadata");
|
|
1460
1493
|
var GuardrailsRuleInput = class {
|
|
1461
|
-
id;
|
|
1462
1494
|
allowList = [];
|
|
1463
1495
|
denyList = [];
|
|
1464
1496
|
};
|
|
1465
1497
|
__name(GuardrailsRuleInput, "GuardrailsRuleInput");
|
|
1466
|
-
_ts_decorate5([
|
|
1467
|
-
(0, import_type_graphql6.Field)(() => String),
|
|
1468
|
-
_ts_metadata5("design:type", String)
|
|
1469
|
-
], GuardrailsRuleInput.prototype, "id", void 0);
|
|
1470
1498
|
_ts_decorate5([
|
|
1471
1499
|
(0, import_type_graphql6.Field)(() => [
|
|
1472
1500
|
String
|
|
@@ -1487,16 +1515,17 @@ GuardrailsRuleInput = _ts_decorate5([
|
|
|
1487
1515
|
(0, import_type_graphql6.InputType)()
|
|
1488
1516
|
], GuardrailsRuleInput);
|
|
1489
1517
|
var GuardrailsInput = class {
|
|
1490
|
-
inputValidationRules =
|
|
1518
|
+
inputValidationRules = {
|
|
1519
|
+
allowList: [],
|
|
1520
|
+
denyList: []
|
|
1521
|
+
};
|
|
1491
1522
|
};
|
|
1492
1523
|
__name(GuardrailsInput, "GuardrailsInput");
|
|
1493
1524
|
_ts_decorate5([
|
|
1494
|
-
(0, import_type_graphql6.Field)(() =>
|
|
1495
|
-
GuardrailsRuleInput
|
|
1496
|
-
], {
|
|
1525
|
+
(0, import_type_graphql6.Field)(() => GuardrailsRuleInput, {
|
|
1497
1526
|
nullable: true
|
|
1498
1527
|
}),
|
|
1499
|
-
_ts_metadata5("design:type",
|
|
1528
|
+
_ts_metadata5("design:type", typeof GuardrailsRuleInput === "undefined" ? Object : GuardrailsRuleInput)
|
|
1500
1529
|
], GuardrailsInput.prototype, "inputValidationRules", void 0);
|
|
1501
1530
|
GuardrailsInput = _ts_decorate5([
|
|
1502
1531
|
(0, import_type_graphql6.InputType)()
|
|
@@ -1524,7 +1553,9 @@ var CloudInput = class {
|
|
|
1524
1553
|
};
|
|
1525
1554
|
__name(CloudInput, "CloudInput");
|
|
1526
1555
|
_ts_decorate6([
|
|
1527
|
-
(0, import_type_graphql7.Field)(() => GuardrailsInput
|
|
1556
|
+
(0, import_type_graphql7.Field)(() => GuardrailsInput, {
|
|
1557
|
+
nullable: true
|
|
1558
|
+
}),
|
|
1528
1559
|
_ts_metadata6("design:type", typeof GuardrailsInput === "undefined" ? Object : GuardrailsInput)
|
|
1529
1560
|
], CloudInput.prototype, "guardrails", void 0);
|
|
1530
1561
|
CloudInput = _ts_decorate6([
|
|
@@ -1664,6 +1695,7 @@ var MessageStatusUnion = (0, import_type_graphql9.createUnionType)({
|
|
|
1664
1695
|
});
|
|
1665
1696
|
|
|
1666
1697
|
// src/graphql/types/response-status.type.ts
|
|
1698
|
+
var import_graphql_scalars = require("graphql-scalars");
|
|
1667
1699
|
var import_type_graphql10 = require("type-graphql");
|
|
1668
1700
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
1669
1701
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1730,15 +1762,31 @@ SuccessResponseStatus = _ts_decorate9([
|
|
|
1730
1762
|
implements: BaseResponseStatus
|
|
1731
1763
|
})
|
|
1732
1764
|
], SuccessResponseStatus);
|
|
1765
|
+
var FailedResponseStatusReason;
|
|
1766
|
+
(function(FailedResponseStatusReason2) {
|
|
1767
|
+
FailedResponseStatusReason2["GUARDRAILS_VALIDATION_FAILED"] = "GUARDRAILS_VALIDATION_FAILED";
|
|
1768
|
+
FailedResponseStatusReason2["MESSAGE_STREAM_INTERRUPTED"] = "MESSAGE_STREAM_INTERRUPTED";
|
|
1769
|
+
FailedResponseStatusReason2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1770
|
+
})(FailedResponseStatusReason || (FailedResponseStatusReason = {}));
|
|
1771
|
+
(0, import_type_graphql10.registerEnumType)(FailedResponseStatusReason, {
|
|
1772
|
+
name: "FailedResponseStatusReason"
|
|
1773
|
+
});
|
|
1733
1774
|
var FailedResponseStatus = class extends BaseResponseStatus {
|
|
1734
1775
|
code = "failed";
|
|
1735
1776
|
reason;
|
|
1777
|
+
details = null;
|
|
1736
1778
|
};
|
|
1737
1779
|
__name(FailedResponseStatus, "FailedResponseStatus");
|
|
1738
1780
|
_ts_decorate9([
|
|
1739
|
-
(0, import_type_graphql10.Field)(() =>
|
|
1781
|
+
(0, import_type_graphql10.Field)(() => FailedResponseStatusReason),
|
|
1740
1782
|
_ts_metadata9("design:type", String)
|
|
1741
1783
|
], FailedResponseStatus.prototype, "reason", void 0);
|
|
1784
|
+
_ts_decorate9([
|
|
1785
|
+
(0, import_type_graphql10.Field)(() => import_graphql_scalars.GraphQLJSON, {
|
|
1786
|
+
nullable: true
|
|
1787
|
+
}),
|
|
1788
|
+
_ts_metadata9("design:type", typeof Record === "undefined" ? Object : Record)
|
|
1789
|
+
], FailedResponseStatus.prototype, "details", void 0);
|
|
1742
1790
|
FailedResponseStatus = _ts_decorate9([
|
|
1743
1791
|
(0, import_type_graphql10.ObjectType)({
|
|
1744
1792
|
implements: BaseResponseStatus
|
|
@@ -1902,8 +1950,45 @@ CopilotResponse = _ts_decorate10([
|
|
|
1902
1950
|
|
|
1903
1951
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
1904
1952
|
var import_graphql_yoga = require("graphql-yoga");
|
|
1905
|
-
var
|
|
1906
|
-
var
|
|
1953
|
+
var import_nanoid5 = require("nanoid");
|
|
1954
|
+
var import_graphql_scalars2 = require("graphql-scalars");
|
|
1955
|
+
var import_class_transformer2 = require("class-transformer");
|
|
1956
|
+
var import_graphql = require("graphql");
|
|
1957
|
+
|
|
1958
|
+
// src/utils/failed-response-status-reasons.ts
|
|
1959
|
+
var GuardrailsValidationFailureResponse = class extends FailedResponseStatus {
|
|
1960
|
+
reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;
|
|
1961
|
+
constructor({ guardrailsReason }) {
|
|
1962
|
+
super();
|
|
1963
|
+
this.details = {
|
|
1964
|
+
guardrailsReason
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
__name(GuardrailsValidationFailureResponse, "GuardrailsValidationFailureResponse");
|
|
1969
|
+
var MessageStreamInterruptedResponse = class extends FailedResponseStatus {
|
|
1970
|
+
reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;
|
|
1971
|
+
constructor({ messageId }) {
|
|
1972
|
+
super();
|
|
1973
|
+
this.details = {
|
|
1974
|
+
messageId,
|
|
1975
|
+
description: "Check the message for mode details"
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
__name(MessageStreamInterruptedResponse, "MessageStreamInterruptedResponse");
|
|
1980
|
+
var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
1981
|
+
reason = FailedResponseStatusReason.UNKNOWN_ERROR;
|
|
1982
|
+
constructor({ description }) {
|
|
1983
|
+
super();
|
|
1984
|
+
this.details = {
|
|
1985
|
+
description
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
1990
|
+
|
|
1991
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
1907
1992
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
1908
1993
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1909
1994
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1926,39 +2011,173 @@ function _ts_param(paramIndex, decorator) {
|
|
|
1926
2011
|
};
|
|
1927
2012
|
}
|
|
1928
2013
|
__name(_ts_param, "_ts_param");
|
|
2014
|
+
var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
|
|
2015
|
+
var _a;
|
|
2016
|
+
if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
|
|
2017
|
+
const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
|
|
2018
|
+
role: m.textMessage.role,
|
|
2019
|
+
content: m.textMessage.content
|
|
2020
|
+
}));
|
|
2021
|
+
const lastMessage = messages[messages.length - 1];
|
|
2022
|
+
const restOfMessages = messages.slice(0, -1);
|
|
2023
|
+
const body = {
|
|
2024
|
+
input: lastMessage.content,
|
|
2025
|
+
validTopics: data.cloud.guardrails.inputValidationRules.allowList,
|
|
2026
|
+
invalidTopics: data.cloud.guardrails.inputValidationRules.denyList,
|
|
2027
|
+
messages: restOfMessages
|
|
2028
|
+
};
|
|
2029
|
+
const guardrailsResult = await fetch(`${baseUrl}/guardrails/validate`, {
|
|
2030
|
+
method: "POST",
|
|
2031
|
+
headers: {
|
|
2032
|
+
"Content-Type": "application/json",
|
|
2033
|
+
"X-CopilotCloud-Public-API-Key": copilotCloudPublicApiKey
|
|
2034
|
+
},
|
|
2035
|
+
body: JSON.stringify(body)
|
|
2036
|
+
});
|
|
2037
|
+
if (guardrailsResult.ok) {
|
|
2038
|
+
const resultJson = await guardrailsResult.json();
|
|
2039
|
+
onResult(resultJson);
|
|
2040
|
+
} else {
|
|
2041
|
+
onError(await guardrailsResult.json());
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
}, "invokeGuardrails");
|
|
1929
2045
|
var CopilotResolver = class {
|
|
1930
2046
|
async hello() {
|
|
1931
2047
|
return "Hello World";
|
|
1932
2048
|
}
|
|
1933
2049
|
async generateCopilotResponse(ctx, data, properties) {
|
|
2050
|
+
let logger2 = ctx.logger.child({
|
|
2051
|
+
component: "CopilotResolver.generateCopilotResponse"
|
|
2052
|
+
});
|
|
2053
|
+
logger2.debug({
|
|
2054
|
+
data
|
|
2055
|
+
}, "Generating Copilot response");
|
|
2056
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2057
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
1934
2058
|
if (properties) {
|
|
1935
|
-
|
|
1936
|
-
|
|
2059
|
+
logger2.debug("Properties provided, merging with context properties");
|
|
2060
|
+
ctx.properties = {
|
|
2061
|
+
...ctx.properties,
|
|
1937
2062
|
...properties
|
|
1938
2063
|
};
|
|
1939
2064
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2065
|
+
let copilotCloudPublicApiKey = null;
|
|
2066
|
+
let copilotCloudBaseUrl;
|
|
2067
|
+
if (data.cloud) {
|
|
2068
|
+
logger2 = logger2.child({
|
|
2069
|
+
cloud: true
|
|
2070
|
+
});
|
|
2071
|
+
logger2.debug("Cloud configuration provided, checking for public API key in headers");
|
|
2072
|
+
const key = ctx.request.headers.get("x-copilotcloud-public-api-key");
|
|
2073
|
+
if (key) {
|
|
2074
|
+
logger2.debug("Public API key found in headers");
|
|
2075
|
+
copilotCloudPublicApiKey = key;
|
|
2076
|
+
} else {
|
|
2077
|
+
logger2.error("Public API key not found in headers");
|
|
2078
|
+
throw new import_graphql.GraphQLError("X-CopilotCloud-Public-API-Key header is required");
|
|
2079
|
+
}
|
|
2080
|
+
if (process.env.COPILOT_CLOUD_BASE_URL) {
|
|
2081
|
+
copilotCloudBaseUrl = process.env.COPILOT_CLOUD_BASE_URL;
|
|
2082
|
+
} else if (ctx._copilotkit.baseUrl) {
|
|
2083
|
+
copilotCloudBaseUrl = ctx._copilotkit.baseUrl;
|
|
2084
|
+
} else {
|
|
2085
|
+
copilotCloudBaseUrl = "https://api.cloud.copilotkit.ai";
|
|
2086
|
+
}
|
|
2087
|
+
logger2 = logger2.child({
|
|
2088
|
+
copilotCloudBaseUrl
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
logger2.debug("Setting up subjects");
|
|
2092
|
+
const responseStatus$ = new import_rxjs2.ReplaySubject();
|
|
2093
|
+
const interruptStreaming$ = new import_rxjs2.ReplaySubject();
|
|
2094
|
+
const guardrailsResult$ = new import_rxjs2.ReplaySubject();
|
|
2095
|
+
let outputMessages = [];
|
|
2096
|
+
let resolveOutputMessagesPromise;
|
|
2097
|
+
let rejectOutputMessagesPromise;
|
|
2098
|
+
const outputMessagesPromise = new Promise((resolve, reject) => {
|
|
2099
|
+
resolveOutputMessagesPromise = resolve;
|
|
2100
|
+
rejectOutputMessagesPromise = reject;
|
|
2101
|
+
});
|
|
2102
|
+
logger2.debug("Processing");
|
|
2103
|
+
const { eventSource, threadId = (0, import_nanoid5.nanoid)(), runId, actions } = await copilotRuntime.process({
|
|
1944
2104
|
serviceAdapter,
|
|
1945
2105
|
messages: data.messages,
|
|
1946
2106
|
actions: data.frontend.actions,
|
|
1947
2107
|
threadId: data.threadId,
|
|
1948
2108
|
runId: data.runId,
|
|
1949
|
-
publicApiKey: void 0
|
|
2109
|
+
publicApiKey: void 0,
|
|
2110
|
+
properties: ctx.properties || {},
|
|
2111
|
+
outputMessagesPromise
|
|
1950
2112
|
});
|
|
2113
|
+
logger2.debug("Event source created, creating response");
|
|
1951
2114
|
const response = {
|
|
1952
2115
|
threadId,
|
|
1953
2116
|
runId,
|
|
1954
|
-
status: (0, import_rxjs2.firstValueFrom)(responseStatus),
|
|
2117
|
+
status: (0, import_rxjs2.firstValueFrom)(responseStatus$),
|
|
1955
2118
|
messages: new import_graphql_yoga.Repeater(async (pushMessage, stopStreamingMessages) => {
|
|
1956
|
-
|
|
2119
|
+
var _a, _b;
|
|
2120
|
+
logger2.debug("Messages repeater created");
|
|
2121
|
+
if ((_a = data.cloud) == null ? void 0 : _a.guardrails) {
|
|
2122
|
+
logger2 = logger2.child({
|
|
2123
|
+
guardrails: true
|
|
2124
|
+
});
|
|
2125
|
+
logger2.debug("Guardrails is enabled, validating input");
|
|
2126
|
+
invokeGuardrails({
|
|
2127
|
+
baseUrl: copilotCloudBaseUrl,
|
|
2128
|
+
copilotCloudPublicApiKey,
|
|
2129
|
+
data,
|
|
2130
|
+
onResult: (result) => {
|
|
2131
|
+
logger2.debug({
|
|
2132
|
+
status: result.status
|
|
2133
|
+
}, "Guardrails validation done");
|
|
2134
|
+
guardrailsResult$.next(result);
|
|
2135
|
+
if (result.status === "denied") {
|
|
2136
|
+
responseStatus$.next(new GuardrailsValidationFailureResponse({
|
|
2137
|
+
guardrailsReason: result.reason
|
|
2138
|
+
}));
|
|
2139
|
+
interruptStreaming$.next({
|
|
2140
|
+
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2141
|
+
});
|
|
2142
|
+
outputMessages = [
|
|
2143
|
+
(0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2144
|
+
id: (0, import_nanoid5.nanoid)(),
|
|
2145
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2146
|
+
content: result.reason,
|
|
2147
|
+
role: MessageRole.assistant
|
|
2148
|
+
})
|
|
2149
|
+
];
|
|
2150
|
+
resolveOutputMessagesPromise(outputMessages);
|
|
2151
|
+
}
|
|
2152
|
+
},
|
|
2153
|
+
onError: (err) => {
|
|
2154
|
+
logger2.error({
|
|
2155
|
+
err
|
|
2156
|
+
}, "Error in guardrails validation");
|
|
2157
|
+
responseStatus$.next(new UnknownErrorResponse({
|
|
2158
|
+
description: `An unknown error has occurred in the guardrails validation`
|
|
2159
|
+
}));
|
|
2160
|
+
interruptStreaming$.next({
|
|
2161
|
+
reason: `Interrupted due to unknown error in guardrails validation`
|
|
2162
|
+
});
|
|
2163
|
+
rejectOutputMessagesPromise(err);
|
|
2164
|
+
}
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
let eventStreamSubscription;
|
|
2168
|
+
const eventStream = eventSource.process({
|
|
2169
|
+
serversideActions: actions,
|
|
2170
|
+
guardrailsResult$: ((_b = data.cloud) == null ? void 0 : _b.guardrails) ? guardrailsResult$ : null
|
|
2171
|
+
}).pipe(
|
|
1957
2172
|
// shareReplay() ensures that later subscribers will see the whole stream instead of
|
|
1958
2173
|
// just the events that were emitted after the subscriber was added.
|
|
1959
|
-
(0, import_rxjs2.shareReplay)()
|
|
2174
|
+
(0, import_rxjs2.shareReplay)(),
|
|
2175
|
+
(0, import_rxjs2.finalize)(() => {
|
|
2176
|
+
logger2.debug("Event stream finalized");
|
|
2177
|
+
})
|
|
1960
2178
|
);
|
|
1961
|
-
|
|
2179
|
+
logger2.debug("Event stream created, subscribing to event stream");
|
|
2180
|
+
eventStreamSubscription = eventStream.subscribe({
|
|
1962
2181
|
next: async (event) => {
|
|
1963
2182
|
switch (event.type) {
|
|
1964
2183
|
case RuntimeEventTypes.TextMessageStart:
|
|
@@ -1969,23 +2188,67 @@ var CopilotResolver = class {
|
|
|
1969
2188
|
(0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
1970
2189
|
);
|
|
1971
2190
|
const streamingTextStatus = new import_rxjs2.Subject();
|
|
2191
|
+
const messageId = (0, import_nanoid5.nanoid)();
|
|
1972
2192
|
pushMessage({
|
|
1973
|
-
id:
|
|
2193
|
+
id: messageId,
|
|
1974
2194
|
status: (0, import_rxjs2.firstValueFrom)(streamingTextStatus),
|
|
1975
2195
|
createdAt: /* @__PURE__ */ new Date(),
|
|
1976
2196
|
role: MessageRole.assistant,
|
|
1977
2197
|
content: new import_graphql_yoga.Repeater(async (pushTextChunk, stopStreamingText) => {
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2198
|
+
logger2.debug("Text message content repeater created");
|
|
2199
|
+
const textChunks = [];
|
|
2200
|
+
let textSubscription;
|
|
2201
|
+
interruptStreaming$.pipe((0, import_rxjs2.shareReplay)(), (0, import_rxjs2.take)(1), (0, import_rxjs2.tap)(({ reason, messageId: messageId2 }) => {
|
|
2202
|
+
logger2.debug({
|
|
2203
|
+
reason,
|
|
2204
|
+
messageId: messageId2
|
|
2205
|
+
}, "Text streaming interrupted");
|
|
2206
|
+
streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
2207
|
+
reason
|
|
2208
|
+
}));
|
|
2209
|
+
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
2210
|
+
messageId: messageId2
|
|
2211
|
+
}));
|
|
2212
|
+
stopStreamingText();
|
|
2213
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2214
|
+
})).subscribe();
|
|
2215
|
+
logger2.debug("Subscribing to text message content stream");
|
|
2216
|
+
textSubscription = textMessageContentStream.subscribe({
|
|
2217
|
+
next: async (e) => {
|
|
2218
|
+
if (e.type == RuntimeEventTypes.TextMessageContent) {
|
|
2219
|
+
await pushTextChunk(e.content);
|
|
2220
|
+
textChunks.push(e.content);
|
|
2221
|
+
}
|
|
2222
|
+
},
|
|
2223
|
+
error: (err) => {
|
|
2224
|
+
logger2.error({
|
|
2225
|
+
err
|
|
2226
|
+
}, "Error in text message content stream");
|
|
2227
|
+
interruptStreaming$.next({
|
|
2228
|
+
reason: "Error streaming message content",
|
|
2229
|
+
messageId
|
|
2230
|
+
});
|
|
2231
|
+
stopStreamingText();
|
|
2232
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2233
|
+
},
|
|
2234
|
+
complete: () => {
|
|
2235
|
+
logger2.debug("Text message content stream completed");
|
|
2236
|
+
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2237
|
+
stopStreamingText();
|
|
2238
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2239
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
2240
|
+
id: messageId,
|
|
2241
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2242
|
+
content: textChunks.join(""),
|
|
2243
|
+
role: MessageRole.assistant
|
|
2244
|
+
}));
|
|
1981
2245
|
}
|
|
1982
2246
|
});
|
|
1983
|
-
stopStreamingText();
|
|
1984
|
-
streamingTextStatus.next(new SuccessMessageStatus());
|
|
1985
2247
|
})
|
|
1986
2248
|
});
|
|
1987
2249
|
break;
|
|
1988
2250
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2251
|
+
logger2.debug("Action execution start event received");
|
|
1989
2252
|
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs2.skipWhile)((e) => e !== event), (0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
1990
2253
|
const streamingArgumentsStatus = new import_rxjs2.Subject();
|
|
1991
2254
|
pushMessage({
|
|
@@ -1995,32 +2258,87 @@ var CopilotResolver = class {
|
|
|
1995
2258
|
name: event.actionName,
|
|
1996
2259
|
scope: event.scope,
|
|
1997
2260
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2261
|
+
logger2.debug("Action execution argument stream created");
|
|
2262
|
+
const argumentChunks = [];
|
|
2263
|
+
let actionExecutionArgumentSubscription;
|
|
2264
|
+
actionExecutionArgumentSubscription = actionExecutionArgumentStream.subscribe({
|
|
2265
|
+
next: async (e) => {
|
|
2266
|
+
if (e.type == RuntimeEventTypes.ActionExecutionArgs) {
|
|
2267
|
+
await pushArgumentsChunk(e.args);
|
|
2268
|
+
argumentChunks.push(e.args);
|
|
2269
|
+
}
|
|
2270
|
+
},
|
|
2271
|
+
error: (err) => {
|
|
2272
|
+
logger2.error({
|
|
2273
|
+
err
|
|
2274
|
+
}, "Error in action execution argument stream");
|
|
2275
|
+
streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
2276
|
+
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2277
|
+
}));
|
|
2278
|
+
stopStreamingArguments();
|
|
2279
|
+
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2280
|
+
},
|
|
2281
|
+
complete: () => {
|
|
2282
|
+
logger2.debug("Action execution argument stream completed");
|
|
2283
|
+
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2284
|
+
stopStreamingArguments();
|
|
2285
|
+
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2286
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
2287
|
+
id: event.actionExecutionId,
|
|
2288
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2289
|
+
name: event.actionName,
|
|
2290
|
+
scope: event.scope,
|
|
2291
|
+
arguments: argumentChunks.join("")
|
|
2292
|
+
}));
|
|
2001
2293
|
}
|
|
2002
2294
|
});
|
|
2003
|
-
stopStreamingArguments();
|
|
2004
|
-
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2005
2295
|
})
|
|
2006
2296
|
});
|
|
2007
2297
|
break;
|
|
2008
2298
|
case RuntimeEventTypes.ActionExecutionResult:
|
|
2299
|
+
logger2.debug({
|
|
2300
|
+
result: event.result
|
|
2301
|
+
}, "Action execution result event received");
|
|
2009
2302
|
pushMessage({
|
|
2010
|
-
id: (0,
|
|
2303
|
+
id: (0, import_nanoid5.nanoid)(),
|
|
2011
2304
|
status: new SuccessMessageStatus(),
|
|
2012
2305
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2013
2306
|
actionExecutionId: event.actionExecutionId,
|
|
2014
2307
|
actionName: event.actionName,
|
|
2015
2308
|
result: event.result
|
|
2016
2309
|
});
|
|
2310
|
+
outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
2311
|
+
id: (0, import_nanoid5.nanoid)(),
|
|
2312
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2313
|
+
actionExecutionId: event.actionExecutionId,
|
|
2314
|
+
actionName: event.actionName,
|
|
2315
|
+
result: event.result
|
|
2316
|
+
}));
|
|
2017
2317
|
break;
|
|
2018
2318
|
}
|
|
2019
2319
|
},
|
|
2020
|
-
error: (err) =>
|
|
2021
|
-
|
|
2022
|
-
|
|
2320
|
+
error: (err) => {
|
|
2321
|
+
logger2.error({
|
|
2322
|
+
err
|
|
2323
|
+
}, "Error in event stream");
|
|
2324
|
+
responseStatus$.next(new UnknownErrorResponse({
|
|
2325
|
+
description: `An unknown error has occurred in the event stream`
|
|
2326
|
+
}));
|
|
2327
|
+
eventStreamSubscription == null ? void 0 : eventStreamSubscription.unsubscribe();
|
|
2328
|
+
stopStreamingMessages();
|
|
2329
|
+
rejectOutputMessagesPromise(err);
|
|
2330
|
+
},
|
|
2331
|
+
complete: async () => {
|
|
2332
|
+
var _a2;
|
|
2333
|
+
logger2.debug("Event stream completed");
|
|
2334
|
+
if ((_a2 = data.cloud) == null ? void 0 : _a2.guardrails) {
|
|
2335
|
+
logger2.debug("Guardrails is enabled, waiting for guardrails result");
|
|
2336
|
+
await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
2337
|
+
}
|
|
2338
|
+
responseStatus$.next(new SuccessResponseStatus());
|
|
2339
|
+
eventStreamSubscription == null ? void 0 : eventStreamSubscription.unsubscribe();
|
|
2023
2340
|
stopStreamingMessages();
|
|
2341
|
+
resolveOutputMessagesPromise(outputMessages);
|
|
2024
2342
|
}
|
|
2025
2343
|
});
|
|
2026
2344
|
})
|
|
@@ -2039,7 +2357,7 @@ _ts_decorate11([
|
|
|
2039
2357
|
(0, import_type_graphql12.Mutation)(() => CopilotResponse),
|
|
2040
2358
|
_ts_param(0, (0, import_type_graphql12.Ctx)()),
|
|
2041
2359
|
_ts_param(1, (0, import_type_graphql12.Arg)("data")),
|
|
2042
|
-
_ts_param(2, (0, import_type_graphql12.Arg)("properties", () =>
|
|
2360
|
+
_ts_param(2, (0, import_type_graphql12.Arg)("properties", () => import_graphql_scalars2.GraphQLJSONObject, {
|
|
2043
2361
|
nullable: true
|
|
2044
2362
|
})),
|
|
2045
2363
|
_ts_metadata11("design:type", Function),
|
|
@@ -2056,51 +2374,99 @@ CopilotResolver = _ts_decorate11([
|
|
|
2056
2374
|
|
|
2057
2375
|
// src/lib/integrations/shared.ts
|
|
2058
2376
|
var import_plugin_defer_stream = require("@graphql-yoga/plugin-defer-stream");
|
|
2059
|
-
|
|
2377
|
+
|
|
2378
|
+
// src/lib/logger.ts
|
|
2379
|
+
var import_pino = __toESM(require("pino"));
|
|
2380
|
+
var import_pino_pretty = __toESM(require("pino-pretty"));
|
|
2381
|
+
function createLogger(options) {
|
|
2382
|
+
const { level, component } = options || {};
|
|
2383
|
+
const stream = (0, import_pino_pretty.default)({
|
|
2384
|
+
colorize: true
|
|
2385
|
+
});
|
|
2386
|
+
const logger2 = (0, import_pino.default)({
|
|
2387
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
2388
|
+
redact: {
|
|
2389
|
+
paths: [
|
|
2390
|
+
"pid",
|
|
2391
|
+
"hostname"
|
|
2392
|
+
],
|
|
2393
|
+
remove: true
|
|
2394
|
+
}
|
|
2395
|
+
}, stream);
|
|
2396
|
+
if (component) {
|
|
2397
|
+
return logger2.child({
|
|
2398
|
+
component
|
|
2399
|
+
});
|
|
2400
|
+
} else {
|
|
2401
|
+
return logger2;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
__name(createLogger, "createLogger");
|
|
2405
|
+
|
|
2406
|
+
// src/lib/integrations/shared.ts
|
|
2407
|
+
var logger = createLogger();
|
|
2408
|
+
async function createContext(initialContext, copilotKitContext, contextLogger, properties = {}) {
|
|
2409
|
+
logger.debug({
|
|
2410
|
+
copilotKitContext
|
|
2411
|
+
}, "Creating GraphQL context");
|
|
2060
2412
|
const ctx = {
|
|
2061
2413
|
...initialContext,
|
|
2062
2414
|
_copilotkit: {
|
|
2063
2415
|
...copilotKitContext
|
|
2064
|
-
}
|
|
2416
|
+
},
|
|
2417
|
+
properties: {
|
|
2418
|
+
...properties
|
|
2419
|
+
},
|
|
2420
|
+
logger: contextLogger
|
|
2065
2421
|
};
|
|
2066
2422
|
return ctx;
|
|
2067
2423
|
}
|
|
2068
2424
|
__name(createContext, "createContext");
|
|
2069
2425
|
function buildSchema(options = {}) {
|
|
2426
|
+
logger.debug("Building GraphQL schema...");
|
|
2070
2427
|
const schema = (0, import_type_graphql13.buildSchemaSync)({
|
|
2071
2428
|
resolvers: [
|
|
2072
2429
|
CopilotResolver
|
|
2073
2430
|
],
|
|
2074
2431
|
emitSchemaFile: options.emitSchemaFile
|
|
2075
2432
|
});
|
|
2433
|
+
logger.debug("GraphQL schema built successfully");
|
|
2076
2434
|
return schema;
|
|
2077
2435
|
}
|
|
2078
2436
|
__name(buildSchema, "buildSchema");
|
|
2079
2437
|
function getCommonConfig(options) {
|
|
2438
|
+
const logLevel = process.env.LOG_LEVEL || options.logLevel || "error";
|
|
2439
|
+
const logger2 = createLogger({
|
|
2440
|
+
level: logLevel,
|
|
2441
|
+
component: "getCommonConfig"
|
|
2442
|
+
});
|
|
2443
|
+
logger2.debug("Getting common config");
|
|
2444
|
+
const contextLogger = createLogger({
|
|
2445
|
+
level: logLevel
|
|
2446
|
+
});
|
|
2080
2447
|
return {
|
|
2448
|
+
logging: createLogger({
|
|
2449
|
+
component: "Yoga GraphQL",
|
|
2450
|
+
level: logLevel
|
|
2451
|
+
}),
|
|
2081
2452
|
schema: buildSchema(),
|
|
2082
2453
|
plugins: [
|
|
2083
2454
|
(0, import_plugin_defer_stream.useDeferStream)()
|
|
2084
2455
|
],
|
|
2085
|
-
context: (ctx) => createContext(ctx,
|
|
2086
|
-
runtime: options.runtime,
|
|
2087
|
-
serviceAdapter: options.serviceAdapter,
|
|
2088
|
-
properties: {}
|
|
2089
|
-
})
|
|
2456
|
+
context: (ctx) => createContext(ctx, options, contextLogger, options.properties)
|
|
2090
2457
|
};
|
|
2091
2458
|
}
|
|
2092
2459
|
__name(getCommonConfig, "getCommonConfig");
|
|
2093
2460
|
|
|
2094
2461
|
// src/lib/integrations/nextjs/app-router.ts
|
|
2095
2462
|
var import_graphql_yoga2 = require("graphql-yoga");
|
|
2096
|
-
function copilotRuntimeNextJSAppRouterEndpoint(
|
|
2097
|
-
const commonConfig = getCommonConfig(
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
});
|
|
2463
|
+
function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
2464
|
+
const commonConfig = getCommonConfig(options);
|
|
2465
|
+
const logger2 = commonConfig.logging;
|
|
2466
|
+
logger2.debug("Creating NextJS App Router endpoint");
|
|
2101
2467
|
const yoga = (0, import_graphql_yoga2.createYoga)({
|
|
2102
2468
|
...commonConfig,
|
|
2103
|
-
graphqlEndpoint: endpoint,
|
|
2469
|
+
graphqlEndpoint: options.endpoint,
|
|
2104
2470
|
fetchAPI: {
|
|
2105
2471
|
Response: globalThis.Response
|
|
2106
2472
|
}
|
|
@@ -2121,14 +2487,13 @@ var config = {
|
|
|
2121
2487
|
bodyParser: false
|
|
2122
2488
|
}
|
|
2123
2489
|
};
|
|
2124
|
-
function copilotRuntimeNextJSPagesRouterEndpoint(
|
|
2125
|
-
const commonConfig = getCommonConfig(
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
});
|
|
2490
|
+
function copilotRuntimeNextJSPagesRouterEndpoint(options) {
|
|
2491
|
+
const commonConfig = getCommonConfig(options);
|
|
2492
|
+
const logger2 = commonConfig.logging;
|
|
2493
|
+
logger2.debug("Creating NextJS Pages Router endpoint");
|
|
2129
2494
|
const yoga = (0, import_graphql_yoga3.createYoga)({
|
|
2130
2495
|
...commonConfig,
|
|
2131
|
-
graphqlEndpoint: endpoint
|
|
2496
|
+
graphqlEndpoint: options.endpoint
|
|
2132
2497
|
});
|
|
2133
2498
|
return yoga;
|
|
2134
2499
|
}
|
|
@@ -2136,28 +2501,24 @@ __name(copilotRuntimeNextJSPagesRouterEndpoint, "copilotRuntimeNextJSPagesRouter
|
|
|
2136
2501
|
|
|
2137
2502
|
// src/lib/integrations/node-http/index.ts
|
|
2138
2503
|
var import_graphql_yoga4 = require("graphql-yoga");
|
|
2139
|
-
function copilotRuntimeNodeHttpEndpoint(
|
|
2140
|
-
const commonConfig = getCommonConfig(
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
});
|
|
2504
|
+
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
2505
|
+
const commonConfig = getCommonConfig(options);
|
|
2506
|
+
const logger2 = commonConfig.logging;
|
|
2507
|
+
logger2.debug("Creating Node HTTP endpoint");
|
|
2144
2508
|
const yoga = (0, import_graphql_yoga4.createYoga)({
|
|
2145
2509
|
...commonConfig,
|
|
2146
|
-
graphqlEndpoint: endpoint
|
|
2510
|
+
graphqlEndpoint: options.endpoint
|
|
2147
2511
|
});
|
|
2148
2512
|
return yoga;
|
|
2149
2513
|
}
|
|
2150
2514
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
2151
2515
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2152
2516
|
0 && (module.exports = {
|
|
2153
|
-
CopilotBackend,
|
|
2154
|
-
CopilotCloud,
|
|
2155
2517
|
CopilotRuntime,
|
|
2156
2518
|
GoogleGenerativeAIAdapter,
|
|
2157
2519
|
LangChainAdapter,
|
|
2158
2520
|
OpenAIAdapter,
|
|
2159
2521
|
OpenAIAssistantAdapter,
|
|
2160
|
-
RemoteCopilotCloud,
|
|
2161
2522
|
buildSchema,
|
|
2162
2523
|
config,
|
|
2163
2524
|
copilotRuntimeNextJSAppRouterEndpoint,
|