@copilotkit/runtime 0.37.0 → 0.38.0-mme-alpha.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-NFCPM5AM.mjs → chunk-6NZ4UMOD.mjs} +4 -4
- package/dist/chunk-6NZ4UMOD.mjs.map +1 -0
- package/dist/{chunk-2CCVVJDU.mjs → chunk-6OJ47NCG.mjs} +13 -15
- package/dist/chunk-6OJ47NCG.mjs.map +1 -0
- package/dist/chunk-BYB2LNMK.mjs +152 -0
- package/dist/chunk-BYB2LNMK.mjs.map +1 -0
- package/dist/{chunk-XPAUPJMW.mjs → chunk-EWS5TMDA.mjs} +411 -206
- package/dist/chunk-EWS5TMDA.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-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/{chunk-5HGYI6EG.mjs → chunk-XI3HBDMA.mjs} +13 -5
- package/dist/chunk-XI3HBDMA.mjs.map +1 -0
- package/dist/{chunk-4UA4RB4C.mjs → chunk-XXYCNRFT.mjs} +12 -10
- package/dist/chunk-XXYCNRFT.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-d5ba24be.d.ts} +24 -23
- package/dist/index.d.ts +7 -4
- package/dist/index.js +486 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{langchain-adapter-9ce103f3.d.ts → langchain-adapter-54784d29.d.ts} +1 -1
- package/dist/{langserve-fd5066ee.d.ts → langserve-63794237.d.ts} +24 -7
- 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 +480 -96
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -7
- package/dist/lib/integrations/index.d.ts +5 -3
- package/dist/lib/integrations/index.js +419 -80
- 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 +409 -68
- 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-d94f01da.d.ts +21 -0
- package/dist/service-adapters/index.d.ts +2 -2
- package/dist/service-adapters/index.js +54 -8
- 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 +269 -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 +13 -37
- 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 +37 -17
- package/src/lib/logger.ts +28 -0
- package/src/service-adapters/events.ts +20 -2
- package/src/service-adapters/google/google-genai-adapter.ts +3 -0
- package/src/service-adapters/google/utils.ts +1 -1
- package/src/service-adapters/index.ts +1 -1
- package/src/service-adapters/langchain/langserve.ts +10 -4
- package/src/service-adapters/langchain/utils.ts +58 -9
- 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/guardrails.ts +0 -3
package/dist/lib/index.js
CHANGED
|
@@ -505,7 +505,7 @@ function convertMessageToGoogleGenAIMessage(message) {
|
|
|
505
505
|
};
|
|
506
506
|
} else if (message instanceof ResultMessage) {
|
|
507
507
|
return {
|
|
508
|
-
role: "
|
|
508
|
+
role: "function",
|
|
509
509
|
parts: [
|
|
510
510
|
{
|
|
511
511
|
functionResponse: {
|
|
@@ -622,6 +622,9 @@ var GoogleGenerativeAIAdapter = class {
|
|
|
622
622
|
let isTextMessage = false;
|
|
623
623
|
for await (const chunk of result.stream) {
|
|
624
624
|
const chunkText = chunk.text();
|
|
625
|
+
if (chunkText === "") {
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
625
628
|
if (!isTextMessage) {
|
|
626
629
|
isTextMessage = true;
|
|
627
630
|
eventStream$.sendTextMessageStart((0, import_nanoid.nanoid)());
|
|
@@ -729,6 +732,31 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
729
732
|
});
|
|
730
733
|
}
|
|
731
734
|
__name(convertActionInputToLangChainTool, "convertActionInputToLangChainTool");
|
|
735
|
+
function getConstructorName(object) {
|
|
736
|
+
if (object && typeof object === "object" && object.constructor && object.constructor.name) {
|
|
737
|
+
return object.constructor.name;
|
|
738
|
+
}
|
|
739
|
+
return "";
|
|
740
|
+
}
|
|
741
|
+
__name(getConstructorName, "getConstructorName");
|
|
742
|
+
function isAIMessage(message) {
|
|
743
|
+
return getConstructorName(message) === "AIMessage";
|
|
744
|
+
}
|
|
745
|
+
__name(isAIMessage, "isAIMessage");
|
|
746
|
+
function isAIMessageChunk(message) {
|
|
747
|
+
return getConstructorName(message) === "AIMessageChunk";
|
|
748
|
+
}
|
|
749
|
+
__name(isAIMessageChunk, "isAIMessageChunk");
|
|
750
|
+
function isBaseMessageChunk(message) {
|
|
751
|
+
return getConstructorName(message) === "BaseMessageChunk";
|
|
752
|
+
}
|
|
753
|
+
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
754
|
+
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
755
|
+
if (actionExecution) {
|
|
756
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
732
760
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
733
761
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
734
762
|
if (typeof result === "string") {
|
|
@@ -737,14 +765,16 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
737
765
|
} else {
|
|
738
766
|
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
739
767
|
}
|
|
740
|
-
} else if (result
|
|
768
|
+
} else if (isAIMessage(result)) {
|
|
769
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
741
770
|
if (result.content) {
|
|
742
771
|
eventStream$.sendTextMessage((0, import_nanoid2.nanoid)(), result.content);
|
|
743
772
|
}
|
|
744
773
|
for (const toolCall of result.tool_calls) {
|
|
745
774
|
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid2.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
746
775
|
}
|
|
747
|
-
} else if (result
|
|
776
|
+
} else if (isBaseMessageChunk(result)) {
|
|
777
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
748
778
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
749
779
|
eventStream$.sendTextMessage((0, import_nanoid2.nanoid)(), result.content);
|
|
750
780
|
}
|
|
@@ -753,7 +783,8 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
753
783
|
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid2.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
754
784
|
}
|
|
755
785
|
}
|
|
756
|
-
} else if ("getReader" in result) {
|
|
786
|
+
} else if (result && "getReader" in result) {
|
|
787
|
+
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
757
788
|
let reader = result.getReader();
|
|
758
789
|
let mode = null;
|
|
759
790
|
while (true) {
|
|
@@ -763,14 +794,14 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
763
794
|
let toolCallId = void 0;
|
|
764
795
|
let toolCallArgs = void 0;
|
|
765
796
|
let hasToolCall = false;
|
|
766
|
-
let content = value.content;
|
|
767
|
-
if (value
|
|
797
|
+
let content = value == null ? void 0 : value.content;
|
|
798
|
+
if (isAIMessageChunk(value)) {
|
|
768
799
|
let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
|
|
769
800
|
toolCallName = chunk == null ? void 0 : chunk.name;
|
|
770
801
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
771
802
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
772
803
|
hasToolCall = chunk != void 0;
|
|
773
|
-
} else if (value
|
|
804
|
+
} else if (isBaseMessageChunk(value)) {
|
|
774
805
|
let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
|
|
775
806
|
toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
|
|
776
807
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
@@ -807,13 +838,23 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
807
838
|
}
|
|
808
839
|
}
|
|
809
840
|
} else if (actionExecution) {
|
|
810
|
-
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name,
|
|
841
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
811
842
|
} else {
|
|
812
843
|
throw new Error("Invalid return type from LangChain function.");
|
|
813
844
|
}
|
|
814
845
|
eventStream$.complete();
|
|
815
846
|
}
|
|
816
847
|
__name(streamLangChainResponse, "streamLangChainResponse");
|
|
848
|
+
function encodeResult(result) {
|
|
849
|
+
if (result === void 0) {
|
|
850
|
+
return "";
|
|
851
|
+
} else if (typeof result === "string") {
|
|
852
|
+
return result;
|
|
853
|
+
} else {
|
|
854
|
+
return JSON.stringify(result);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
__name(encodeResult, "encodeResult");
|
|
817
858
|
|
|
818
859
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
819
860
|
var LangChainAdapter = class {
|
|
@@ -846,6 +887,11 @@ __name(LangChainAdapter, "LangChainAdapter");
|
|
|
846
887
|
// src/service-adapters/langchain/langserve.ts
|
|
847
888
|
var import_remote = require("langchain/runnables/remote");
|
|
848
889
|
var RemoteChain = class {
|
|
890
|
+
name;
|
|
891
|
+
description;
|
|
892
|
+
chainUrl;
|
|
893
|
+
parameters;
|
|
894
|
+
parameterType;
|
|
849
895
|
constructor(options) {
|
|
850
896
|
this.name = options.name;
|
|
851
897
|
this.description = options.description;
|
|
@@ -1037,7 +1083,7 @@ var RuntimeEventSource = class {
|
|
|
1037
1083
|
async stream(callback) {
|
|
1038
1084
|
this.callback = callback;
|
|
1039
1085
|
}
|
|
1040
|
-
process(serversideActions) {
|
|
1086
|
+
process({ serversideActions, guardrailsResult$ }) {
|
|
1041
1087
|
this.callback(this.eventStream$).catch((error) => {
|
|
1042
1088
|
console.error("Error in event source callback", error);
|
|
1043
1089
|
});
|
|
@@ -1073,7 +1119,7 @@ var RuntimeEventSource = class {
|
|
|
1073
1119
|
(0, import_rxjs.concatMap)((eventWithState) => {
|
|
1074
1120
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
1075
1121
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
1076
|
-
executeAction(toolCallEventStream$, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1122
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1077
1123
|
console.error(error);
|
|
1078
1124
|
});
|
|
1079
1125
|
return (0, import_rxjs.concat)((0, import_rxjs.of)(eventWithState.event), toolCallEventStream$);
|
|
@@ -1085,7 +1131,14 @@ var RuntimeEventSource = class {
|
|
|
1085
1131
|
}
|
|
1086
1132
|
};
|
|
1087
1133
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
1088
|
-
async function executeAction(eventStream$, action, actionArguments, actionExecutionId) {
|
|
1134
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId) {
|
|
1135
|
+
if (guardrailsResult$) {
|
|
1136
|
+
const { status } = await (0, import_rxjs.firstValueFrom)(guardrailsResult$);
|
|
1137
|
+
if (status === "denied") {
|
|
1138
|
+
eventStream$.complete();
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1089
1142
|
let args = [];
|
|
1090
1143
|
if (actionArguments) {
|
|
1091
1144
|
args = JSON.parse(actionArguments);
|
|
@@ -1168,15 +1221,16 @@ var CopilotRuntime = class {
|
|
|
1168
1221
|
console.error("Error loading langserve chain:", error);
|
|
1169
1222
|
}
|
|
1170
1223
|
}
|
|
1171
|
-
const
|
|
1224
|
+
const actions = [
|
|
1172
1225
|
...this.actions,
|
|
1173
1226
|
...langserveFunctions
|
|
1174
|
-
]
|
|
1227
|
+
];
|
|
1228
|
+
const serverSideActionsInput = actions.map((action) => ({
|
|
1175
1229
|
name: action.name,
|
|
1176
1230
|
description: action.description,
|
|
1177
1231
|
jsonSchema: JSON.stringify((0, import_shared2.actionParametersToJsonSchema)(action.parameters))
|
|
1178
1232
|
}));
|
|
1179
|
-
const
|
|
1233
|
+
const actionInputs = flattenToolCallsNoDuplicates([
|
|
1180
1234
|
...serverSideActionsInput,
|
|
1181
1235
|
...clientSideActionsInput
|
|
1182
1236
|
]);
|
|
@@ -1184,7 +1238,7 @@ var CopilotRuntime = class {
|
|
|
1184
1238
|
const eventSource = new RuntimeEventSource();
|
|
1185
1239
|
const result = await serviceAdapter.process({
|
|
1186
1240
|
messages: convertGqlInputToMessages(messages),
|
|
1187
|
-
actions,
|
|
1241
|
+
actions: actionInputs,
|
|
1188
1242
|
threadId,
|
|
1189
1243
|
runId,
|
|
1190
1244
|
eventSource
|
|
@@ -1192,7 +1246,8 @@ var CopilotRuntime = class {
|
|
|
1192
1246
|
return {
|
|
1193
1247
|
threadId: result.threadId,
|
|
1194
1248
|
runId: result.runId,
|
|
1195
|
-
eventSource
|
|
1249
|
+
eventSource,
|
|
1250
|
+
actions
|
|
1196
1251
|
};
|
|
1197
1252
|
} catch (error) {
|
|
1198
1253
|
console.error("Error getting response:", error);
|
|
@@ -1218,10 +1273,10 @@ var CopilotBackend = class extends CopilotRuntime {
|
|
|
1218
1273
|
__name(CopilotBackend, "CopilotBackend");
|
|
1219
1274
|
|
|
1220
1275
|
// src/lib/integrations/shared.ts
|
|
1221
|
-
var
|
|
1276
|
+
var import_type_graphql14 = require("type-graphql");
|
|
1222
1277
|
|
|
1223
1278
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
1224
|
-
var
|
|
1279
|
+
var import_type_graphql13 = require("type-graphql");
|
|
1225
1280
|
var import_rxjs2 = require("rxjs");
|
|
1226
1281
|
|
|
1227
1282
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
@@ -1458,15 +1513,10 @@ function _ts_metadata5(k, v) {
|
|
|
1458
1513
|
}
|
|
1459
1514
|
__name(_ts_metadata5, "_ts_metadata");
|
|
1460
1515
|
var GuardrailsRuleInput = class {
|
|
1461
|
-
id;
|
|
1462
1516
|
allowList = [];
|
|
1463
1517
|
denyList = [];
|
|
1464
1518
|
};
|
|
1465
1519
|
__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
1520
|
_ts_decorate5([
|
|
1471
1521
|
(0, import_type_graphql6.Field)(() => [
|
|
1472
1522
|
String
|
|
@@ -1487,16 +1537,17 @@ GuardrailsRuleInput = _ts_decorate5([
|
|
|
1487
1537
|
(0, import_type_graphql6.InputType)()
|
|
1488
1538
|
], GuardrailsRuleInput);
|
|
1489
1539
|
var GuardrailsInput = class {
|
|
1490
|
-
inputValidationRules =
|
|
1540
|
+
inputValidationRules = {
|
|
1541
|
+
allowList: [],
|
|
1542
|
+
denyList: []
|
|
1543
|
+
};
|
|
1491
1544
|
};
|
|
1492
1545
|
__name(GuardrailsInput, "GuardrailsInput");
|
|
1493
1546
|
_ts_decorate5([
|
|
1494
|
-
(0, import_type_graphql6.Field)(() =>
|
|
1495
|
-
GuardrailsRuleInput
|
|
1496
|
-
], {
|
|
1547
|
+
(0, import_type_graphql6.Field)(() => GuardrailsRuleInput, {
|
|
1497
1548
|
nullable: true
|
|
1498
1549
|
}),
|
|
1499
|
-
_ts_metadata5("design:type",
|
|
1550
|
+
_ts_metadata5("design:type", typeof GuardrailsRuleInput === "undefined" ? Object : GuardrailsRuleInput)
|
|
1500
1551
|
], GuardrailsInput.prototype, "inputValidationRules", void 0);
|
|
1501
1552
|
GuardrailsInput = _ts_decorate5([
|
|
1502
1553
|
(0, import_type_graphql6.InputType)()
|
|
@@ -1524,7 +1575,9 @@ var CloudInput = class {
|
|
|
1524
1575
|
};
|
|
1525
1576
|
__name(CloudInput, "CloudInput");
|
|
1526
1577
|
_ts_decorate6([
|
|
1527
|
-
(0, import_type_graphql7.Field)(() => GuardrailsInput
|
|
1578
|
+
(0, import_type_graphql7.Field)(() => GuardrailsInput, {
|
|
1579
|
+
nullable: true
|
|
1580
|
+
}),
|
|
1528
1581
|
_ts_metadata6("design:type", typeof GuardrailsInput === "undefined" ? Object : GuardrailsInput)
|
|
1529
1582
|
], CloudInput.prototype, "guardrails", void 0);
|
|
1530
1583
|
CloudInput = _ts_decorate6([
|
|
@@ -1664,6 +1717,7 @@ var MessageStatusUnion = (0, import_type_graphql9.createUnionType)({
|
|
|
1664
1717
|
});
|
|
1665
1718
|
|
|
1666
1719
|
// src/graphql/types/response-status.type.ts
|
|
1720
|
+
var import_graphql_scalars = require("graphql-scalars");
|
|
1667
1721
|
var import_type_graphql10 = require("type-graphql");
|
|
1668
1722
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
1669
1723
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1730,15 +1784,31 @@ SuccessResponseStatus = _ts_decorate9([
|
|
|
1730
1784
|
implements: BaseResponseStatus
|
|
1731
1785
|
})
|
|
1732
1786
|
], SuccessResponseStatus);
|
|
1787
|
+
var FailedResponseStatusReason;
|
|
1788
|
+
(function(FailedResponseStatusReason2) {
|
|
1789
|
+
FailedResponseStatusReason2["GUARDRAILS_VALIDATION_FAILED"] = "GUARDRAILS_VALIDATION_FAILED";
|
|
1790
|
+
FailedResponseStatusReason2["MESSAGE_STREAM_INTERRUPTED"] = "MESSAGE_STREAM_INTERRUPTED";
|
|
1791
|
+
FailedResponseStatusReason2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1792
|
+
})(FailedResponseStatusReason || (FailedResponseStatusReason = {}));
|
|
1793
|
+
(0, import_type_graphql10.registerEnumType)(FailedResponseStatusReason, {
|
|
1794
|
+
name: "FailedResponseStatusReason"
|
|
1795
|
+
});
|
|
1733
1796
|
var FailedResponseStatus = class extends BaseResponseStatus {
|
|
1734
1797
|
code = "failed";
|
|
1735
1798
|
reason;
|
|
1799
|
+
details = null;
|
|
1736
1800
|
};
|
|
1737
1801
|
__name(FailedResponseStatus, "FailedResponseStatus");
|
|
1738
1802
|
_ts_decorate9([
|
|
1739
|
-
(0, import_type_graphql10.Field)(() =>
|
|
1803
|
+
(0, import_type_graphql10.Field)(() => FailedResponseStatusReason),
|
|
1740
1804
|
_ts_metadata9("design:type", String)
|
|
1741
1805
|
], FailedResponseStatus.prototype, "reason", void 0);
|
|
1806
|
+
_ts_decorate9([
|
|
1807
|
+
(0, import_type_graphql10.Field)(() => import_graphql_scalars.GraphQLJSON, {
|
|
1808
|
+
nullable: true
|
|
1809
|
+
}),
|
|
1810
|
+
_ts_metadata9("design:type", typeof Record === "undefined" ? Object : Record)
|
|
1811
|
+
], FailedResponseStatus.prototype, "details", void 0);
|
|
1742
1812
|
FailedResponseStatus = _ts_decorate9([
|
|
1743
1813
|
(0, import_type_graphql10.ObjectType)({
|
|
1744
1814
|
implements: BaseResponseStatus
|
|
@@ -1903,7 +1973,11 @@ CopilotResponse = _ts_decorate10([
|
|
|
1903
1973
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
1904
1974
|
var import_graphql_yoga = require("graphql-yoga");
|
|
1905
1975
|
var import_nanoid3 = require("nanoid");
|
|
1906
|
-
var
|
|
1976
|
+
var import_graphql_scalars2 = require("graphql-scalars");
|
|
1977
|
+
var import_class_transformer2 = require("class-transformer");
|
|
1978
|
+
|
|
1979
|
+
// src/graphql/types/guardrails-result.type.ts
|
|
1980
|
+
var import_type_graphql12 = require("type-graphql");
|
|
1907
1981
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
1908
1982
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1909
1983
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1920,27 +1994,182 @@ function _ts_metadata11(k, v) {
|
|
|
1920
1994
|
return Reflect.metadata(k, v);
|
|
1921
1995
|
}
|
|
1922
1996
|
__name(_ts_metadata11, "_ts_metadata");
|
|
1997
|
+
var GuardrailsResultStatus;
|
|
1998
|
+
(function(GuardrailsResultStatus2) {
|
|
1999
|
+
GuardrailsResultStatus2["ALLOWED"] = "allowed";
|
|
2000
|
+
GuardrailsResultStatus2["DENIED"] = "denied";
|
|
2001
|
+
})(GuardrailsResultStatus || (GuardrailsResultStatus = {}));
|
|
2002
|
+
(0, import_type_graphql12.registerEnumType)(GuardrailsResultStatus, {
|
|
2003
|
+
name: "GuardrailsResultStatus",
|
|
2004
|
+
description: "The status of the guardrails check"
|
|
2005
|
+
});
|
|
2006
|
+
var GuardrailsResult = class {
|
|
2007
|
+
status;
|
|
2008
|
+
reason;
|
|
2009
|
+
};
|
|
2010
|
+
__name(GuardrailsResult, "GuardrailsResult");
|
|
2011
|
+
_ts_decorate11([
|
|
2012
|
+
(0, import_type_graphql12.Field)(() => GuardrailsResultStatus),
|
|
2013
|
+
_ts_metadata11("design:type", String)
|
|
2014
|
+
], GuardrailsResult.prototype, "status", void 0);
|
|
2015
|
+
_ts_decorate11([
|
|
2016
|
+
(0, import_type_graphql12.Field)(() => String, {
|
|
2017
|
+
nullable: true
|
|
2018
|
+
}),
|
|
2019
|
+
_ts_metadata11("design:type", String)
|
|
2020
|
+
], GuardrailsResult.prototype, "reason", void 0);
|
|
2021
|
+
GuardrailsResult = _ts_decorate11([
|
|
2022
|
+
(0, import_type_graphql12.ObjectType)()
|
|
2023
|
+
], GuardrailsResult);
|
|
2024
|
+
|
|
2025
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
2026
|
+
var import_graphql = require("graphql");
|
|
2027
|
+
|
|
2028
|
+
// src/utils/failed-response-status-reasons.ts
|
|
2029
|
+
var GuardrailsValidationFailureResponse = class extends FailedResponseStatus {
|
|
2030
|
+
reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;
|
|
2031
|
+
constructor({ guardrailsReason }) {
|
|
2032
|
+
super();
|
|
2033
|
+
this.details = {
|
|
2034
|
+
guardrailsReason
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
__name(GuardrailsValidationFailureResponse, "GuardrailsValidationFailureResponse");
|
|
2039
|
+
var MessageStreamInterruptedResponse = class extends FailedResponseStatus {
|
|
2040
|
+
reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;
|
|
2041
|
+
constructor({ messageId }) {
|
|
2042
|
+
super();
|
|
2043
|
+
this.details = {
|
|
2044
|
+
messageId,
|
|
2045
|
+
description: "Check the message for mode details"
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
__name(MessageStreamInterruptedResponse, "MessageStreamInterruptedResponse");
|
|
2050
|
+
var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
2051
|
+
reason = FailedResponseStatusReason.UNKNOWN_ERROR;
|
|
2052
|
+
constructor({ description }) {
|
|
2053
|
+
super();
|
|
2054
|
+
this.details = {
|
|
2055
|
+
description
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
2060
|
+
|
|
2061
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
2062
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2063
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2064
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2065
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2066
|
+
else
|
|
2067
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2068
|
+
if (d = decorators[i])
|
|
2069
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2070
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2071
|
+
}
|
|
2072
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
2073
|
+
function _ts_metadata12(k, v) {
|
|
2074
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
2075
|
+
return Reflect.metadata(k, v);
|
|
2076
|
+
}
|
|
2077
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1923
2078
|
function _ts_param(paramIndex, decorator) {
|
|
1924
2079
|
return function(target, key) {
|
|
1925
2080
|
decorator(target, key, paramIndex);
|
|
1926
2081
|
};
|
|
1927
2082
|
}
|
|
1928
2083
|
__name(_ts_param, "_ts_param");
|
|
2084
|
+
var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, logger: logger2, onResult }) => {
|
|
2085
|
+
var _a;
|
|
2086
|
+
if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
|
|
2087
|
+
const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
|
|
2088
|
+
role: m.textMessage.role,
|
|
2089
|
+
content: m.textMessage.content
|
|
2090
|
+
}));
|
|
2091
|
+
const lastMessage = messages[messages.length - 1];
|
|
2092
|
+
const restOfMessages = messages.slice(0, -1);
|
|
2093
|
+
const body = {
|
|
2094
|
+
input: lastMessage.content,
|
|
2095
|
+
validTopics: data.cloud.guardrails.inputValidationRules.allowList,
|
|
2096
|
+
invalidTopics: data.cloud.guardrails.inputValidationRules.denyList,
|
|
2097
|
+
messages: restOfMessages
|
|
2098
|
+
};
|
|
2099
|
+
const guardrailsResult = await fetch(`${baseUrl}/guardrails/validate`, {
|
|
2100
|
+
method: "POST",
|
|
2101
|
+
headers: {
|
|
2102
|
+
"Content-Type": "application/json",
|
|
2103
|
+
"X-CopilotCloud-Public-API-Key": copilotCloudPublicApiKey
|
|
2104
|
+
},
|
|
2105
|
+
body: JSON.stringify(body)
|
|
2106
|
+
});
|
|
2107
|
+
const responseBody = await guardrailsResult.json();
|
|
2108
|
+
if (!guardrailsResult.ok) {
|
|
2109
|
+
logger2.error({
|
|
2110
|
+
error: responseBody
|
|
2111
|
+
}, "Failed to invoke guardrails");
|
|
2112
|
+
throw new import_graphql.GraphQLError("Failed to invoke guardrails");
|
|
2113
|
+
}
|
|
2114
|
+
onResult(responseBody);
|
|
2115
|
+
} else {
|
|
2116
|
+
onResult({
|
|
2117
|
+
status: GuardrailsResultStatus.ALLOWED
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
}, "invokeGuardrails");
|
|
1929
2121
|
var CopilotResolver = class {
|
|
1930
2122
|
async hello() {
|
|
1931
2123
|
return "Hello World";
|
|
1932
2124
|
}
|
|
1933
2125
|
async generateCopilotResponse(ctx, data, properties) {
|
|
2126
|
+
let logger2 = ctx.logger.child({
|
|
2127
|
+
component: "CopilotResolver.generateCopilotResponse"
|
|
2128
|
+
});
|
|
2129
|
+
logger2.debug({
|
|
2130
|
+
data
|
|
2131
|
+
}, "Generating Copilot response");
|
|
2132
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2133
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
1934
2134
|
if (properties) {
|
|
1935
|
-
|
|
1936
|
-
|
|
2135
|
+
logger2.debug("Properties provided, merging with context properties");
|
|
2136
|
+
ctx.properties = {
|
|
2137
|
+
...ctx.properties,
|
|
1937
2138
|
...properties
|
|
1938
2139
|
};
|
|
1939
2140
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2141
|
+
let copilotCloudPublicApiKey = null;
|
|
2142
|
+
let copilotCloudBaseUrl;
|
|
2143
|
+
if (data.cloud) {
|
|
2144
|
+
logger2 = logger2.child({
|
|
2145
|
+
cloud: true
|
|
2146
|
+
});
|
|
2147
|
+
logger2.debug("Cloud configuration provided, checking for public API key in headers");
|
|
2148
|
+
const key = ctx.request.headers.get("x-copilotcloud-public-api-key");
|
|
2149
|
+
if (key) {
|
|
2150
|
+
logger2.debug("Public API key found in headers");
|
|
2151
|
+
copilotCloudPublicApiKey = key;
|
|
2152
|
+
} else {
|
|
2153
|
+
logger2.error("Public API key not found in headers");
|
|
2154
|
+
throw new import_graphql.GraphQLError("X-CopilotCloud-Public-API-Key header is required");
|
|
2155
|
+
}
|
|
2156
|
+
if (process.env.COPILOT_CLOUD_BASE_URL) {
|
|
2157
|
+
copilotCloudBaseUrl = process.env.COPILOT_CLOUD_BASE_URL;
|
|
2158
|
+
} else if (ctx._copilotkit.baseUrl) {
|
|
2159
|
+
copilotCloudBaseUrl = ctx._copilotkit.baseUrl;
|
|
2160
|
+
} else {
|
|
2161
|
+
copilotCloudBaseUrl = "https://api.cloud.copilotkit.ai";
|
|
2162
|
+
}
|
|
2163
|
+
logger2 = logger2.child({
|
|
2164
|
+
copilotCloudBaseUrl
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
logger2.debug("Setting up subjects");
|
|
2168
|
+
const responseStatus$ = new import_rxjs2.ReplaySubject();
|
|
2169
|
+
const interruptStreaming$ = new import_rxjs2.ReplaySubject();
|
|
2170
|
+
const guardrailsResult$ = new import_rxjs2.ReplaySubject();
|
|
2171
|
+
logger2.debug("Processing");
|
|
2172
|
+
const { eventSource, threadId = (0, import_nanoid3.nanoid)(), runId, actions } = await copilotRuntime.process({
|
|
1944
2173
|
serviceAdapter,
|
|
1945
2174
|
messages: data.messages,
|
|
1946
2175
|
actions: data.frontend.actions,
|
|
@@ -1948,17 +2177,55 @@ var CopilotResolver = class {
|
|
|
1948
2177
|
runId: data.runId,
|
|
1949
2178
|
publicApiKey: void 0
|
|
1950
2179
|
});
|
|
2180
|
+
logger2.debug("Event source created, creating response");
|
|
1951
2181
|
const response = {
|
|
1952
2182
|
threadId,
|
|
1953
2183
|
runId,
|
|
1954
|
-
status: (0, import_rxjs2.firstValueFrom)(responseStatus),
|
|
2184
|
+
status: (0, import_rxjs2.firstValueFrom)(responseStatus$),
|
|
1955
2185
|
messages: new import_graphql_yoga.Repeater(async (pushMessage, stopStreamingMessages) => {
|
|
1956
|
-
|
|
2186
|
+
var _a, _b;
|
|
2187
|
+
logger2.debug("Messages repeater created");
|
|
2188
|
+
if ((_a = data.cloud) == null ? void 0 : _a.guardrails) {
|
|
2189
|
+
logger2 = logger2.child({
|
|
2190
|
+
guardrails: true
|
|
2191
|
+
});
|
|
2192
|
+
logger2.debug("Guardrails is enabled, validating input");
|
|
2193
|
+
invokeGuardrails({
|
|
2194
|
+
baseUrl: copilotCloudBaseUrl,
|
|
2195
|
+
copilotCloudPublicApiKey,
|
|
2196
|
+
data,
|
|
2197
|
+
logger: logger2,
|
|
2198
|
+
onResult: (result) => {
|
|
2199
|
+
logger2.debug({
|
|
2200
|
+
status: result.status
|
|
2201
|
+
}, "Guardrails validation done");
|
|
2202
|
+
guardrailsResult$.next(result);
|
|
2203
|
+
if (result.status === "denied") {
|
|
2204
|
+
responseStatus$.next(new GuardrailsValidationFailureResponse({
|
|
2205
|
+
guardrailsReason: result.reason
|
|
2206
|
+
}));
|
|
2207
|
+
interruptStreaming$.next({
|
|
2208
|
+
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
let eventStreamSubscription;
|
|
2215
|
+
const eventStream = eventSource.process({
|
|
2216
|
+
serversideActions: copilotRuntime.actions,
|
|
2217
|
+
guardrailsResult$: ((_b = data.cloud) == null ? void 0 : _b.guardrails) ? guardrailsResult$ : null
|
|
2218
|
+
}).pipe(
|
|
1957
2219
|
// shareReplay() ensures that later subscribers will see the whole stream instead of
|
|
1958
2220
|
// just the events that were emitted after the subscriber was added.
|
|
1959
|
-
(0, import_rxjs2.shareReplay)()
|
|
2221
|
+
(0, import_rxjs2.shareReplay)(),
|
|
2222
|
+
(0, import_rxjs2.finalize)(() => {
|
|
2223
|
+
logger2.debug("Event stream finalized, stopping streaming messages");
|
|
2224
|
+
stopStreamingMessages();
|
|
2225
|
+
})
|
|
1960
2226
|
);
|
|
1961
|
-
|
|
2227
|
+
logger2.debug("Event stream created, subscribing to event stream");
|
|
2228
|
+
eventStreamSubscription = eventStream.subscribe({
|
|
1962
2229
|
next: async (event) => {
|
|
1963
2230
|
switch (event.type) {
|
|
1964
2231
|
case RuntimeEventTypes.TextMessageStart:
|
|
@@ -1969,23 +2236,59 @@ var CopilotResolver = class {
|
|
|
1969
2236
|
(0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
1970
2237
|
);
|
|
1971
2238
|
const streamingTextStatus = new import_rxjs2.Subject();
|
|
2239
|
+
const messageId = (0, import_nanoid3.nanoid)();
|
|
1972
2240
|
pushMessage({
|
|
1973
|
-
id:
|
|
2241
|
+
id: messageId,
|
|
1974
2242
|
status: (0, import_rxjs2.firstValueFrom)(streamingTextStatus),
|
|
1975
2243
|
createdAt: /* @__PURE__ */ new Date(),
|
|
1976
2244
|
role: MessageRole.assistant,
|
|
1977
2245
|
content: new import_graphql_yoga.Repeater(async (pushTextChunk, stopStreamingText) => {
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2246
|
+
logger2.debug("Text message content repeater created");
|
|
2247
|
+
let textSubscription;
|
|
2248
|
+
interruptStreaming$.pipe((0, import_rxjs2.shareReplay)(), (0, import_rxjs2.take)(1), (0, import_rxjs2.tap)(({ reason, messageId: messageId2 }) => {
|
|
2249
|
+
logger2.debug({
|
|
2250
|
+
reason,
|
|
2251
|
+
messageId: messageId2
|
|
2252
|
+
}, "Text streaming interrupted");
|
|
2253
|
+
streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
2254
|
+
reason
|
|
2255
|
+
}));
|
|
2256
|
+
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
2257
|
+
messageId: messageId2
|
|
2258
|
+
}));
|
|
2259
|
+
stopStreamingText();
|
|
2260
|
+
textSubscription.unsubscribe();
|
|
2261
|
+
})).subscribe();
|
|
2262
|
+
logger2.debug("Subscribing to text message content stream");
|
|
2263
|
+
textSubscription = textMessageContentStream.subscribe({
|
|
2264
|
+
next: async (e) => {
|
|
2265
|
+
if (e.type == RuntimeEventTypes.TextMessageContent) {
|
|
2266
|
+
await pushTextChunk(e.content);
|
|
2267
|
+
}
|
|
2268
|
+
},
|
|
2269
|
+
error: (err) => {
|
|
2270
|
+
logger2.error({
|
|
2271
|
+
err
|
|
2272
|
+
}, "Error in text message content stream");
|
|
2273
|
+
interruptStreaming$.next({
|
|
2274
|
+
reason: "Error streaming message content",
|
|
2275
|
+
messageId
|
|
2276
|
+
});
|
|
2277
|
+
stopStreamingText();
|
|
2278
|
+
textSubscription.unsubscribe();
|
|
2279
|
+
},
|
|
2280
|
+
complete: () => {
|
|
2281
|
+
logger2.debug("Text message content stream completed");
|
|
2282
|
+
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2283
|
+
stopStreamingText();
|
|
2284
|
+
textSubscription.unsubscribe();
|
|
1981
2285
|
}
|
|
1982
2286
|
});
|
|
1983
|
-
stopStreamingText();
|
|
1984
|
-
streamingTextStatus.next(new SuccessMessageStatus());
|
|
1985
2287
|
})
|
|
1986
2288
|
});
|
|
1987
2289
|
break;
|
|
1988
2290
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2291
|
+
logger2.debug("Action execution start event received");
|
|
1989
2292
|
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs2.skipWhile)((e) => e !== event), (0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
1990
2293
|
const streamingArgumentsStatus = new import_rxjs2.Subject();
|
|
1991
2294
|
pushMessage({
|
|
@@ -1995,17 +2298,36 @@ var CopilotResolver = class {
|
|
|
1995
2298
|
name: event.actionName,
|
|
1996
2299
|
scope: event.scope,
|
|
1997
2300
|
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2301
|
+
logger2.debug("Action execution argument stream created");
|
|
2302
|
+
let actionExecutionArgumentSubscription;
|
|
2303
|
+
actionExecutionArgumentSubscription = actionExecutionArgumentStream.subscribe({
|
|
2304
|
+
next: async (e) => {
|
|
2305
|
+
if (e.type == RuntimeEventTypes.ActionExecutionArgs) {
|
|
2306
|
+
await pushArgumentsChunk(e.args);
|
|
2307
|
+
}
|
|
2308
|
+
},
|
|
2309
|
+
error: (err) => {
|
|
2310
|
+
logger2.error({
|
|
2311
|
+
err
|
|
2312
|
+
}, "Error in action execution argument stream");
|
|
2313
|
+
streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
|
|
2314
|
+
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2315
|
+
}));
|
|
2316
|
+
stopStreamingArguments();
|
|
2317
|
+
actionExecutionArgumentSubscription.unsubscribe();
|
|
2318
|
+
},
|
|
2319
|
+
complete: () => {
|
|
2320
|
+
logger2.debug("Action execution argument stream completed");
|
|
2321
|
+
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2322
|
+
stopStreamingArguments();
|
|
2323
|
+
actionExecutionArgumentSubscription.unsubscribe();
|
|
2001
2324
|
}
|
|
2002
2325
|
});
|
|
2003
|
-
stopStreamingArguments();
|
|
2004
|
-
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2005
2326
|
})
|
|
2006
2327
|
});
|
|
2007
2328
|
break;
|
|
2008
2329
|
case RuntimeEventTypes.ActionExecutionResult:
|
|
2330
|
+
logger2.debug("Action execution result event received");
|
|
2009
2331
|
pushMessage({
|
|
2010
2332
|
id: (0, import_nanoid3.nanoid)(),
|
|
2011
2333
|
status: new SuccessMessageStatus(),
|
|
@@ -2017,9 +2339,25 @@ var CopilotResolver = class {
|
|
|
2017
2339
|
break;
|
|
2018
2340
|
}
|
|
2019
2341
|
},
|
|
2020
|
-
error: (err) =>
|
|
2021
|
-
|
|
2022
|
-
|
|
2342
|
+
error: (err) => {
|
|
2343
|
+
logger2.error({
|
|
2344
|
+
err
|
|
2345
|
+
}, "Error in event stream");
|
|
2346
|
+
responseStatus$.next(new UnknownErrorResponse({
|
|
2347
|
+
description: `An unknown error has occurred in the event stream`
|
|
2348
|
+
}));
|
|
2349
|
+
eventStreamSubscription.unsubscribe();
|
|
2350
|
+
stopStreamingMessages();
|
|
2351
|
+
},
|
|
2352
|
+
complete: async () => {
|
|
2353
|
+
var _a2;
|
|
2354
|
+
logger2.debug("Event stream completed");
|
|
2355
|
+
if ((_a2 = data.cloud) == null ? void 0 : _a2.guardrails) {
|
|
2356
|
+
logger2.debug("Guardrails is enabled, waiting for guardrails result");
|
|
2357
|
+
await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
|
|
2358
|
+
}
|
|
2359
|
+
responseStatus$.next(new SuccessResponseStatus());
|
|
2360
|
+
eventStreamSubscription.unsubscribe();
|
|
2023
2361
|
stopStreamingMessages();
|
|
2024
2362
|
}
|
|
2025
2363
|
});
|
|
@@ -2029,78 +2367,126 @@ var CopilotResolver = class {
|
|
|
2029
2367
|
}
|
|
2030
2368
|
};
|
|
2031
2369
|
__name(CopilotResolver, "CopilotResolver");
|
|
2032
|
-
|
|
2033
|
-
(0,
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2370
|
+
_ts_decorate12([
|
|
2371
|
+
(0, import_type_graphql13.Query)(() => String),
|
|
2372
|
+
_ts_metadata12("design:type", Function),
|
|
2373
|
+
_ts_metadata12("design:paramtypes", []),
|
|
2374
|
+
_ts_metadata12("design:returntype", Promise)
|
|
2037
2375
|
], CopilotResolver.prototype, "hello", null);
|
|
2038
|
-
|
|
2039
|
-
(0,
|
|
2040
|
-
_ts_param(0, (0,
|
|
2041
|
-
_ts_param(1, (0,
|
|
2042
|
-
_ts_param(2, (0,
|
|
2376
|
+
_ts_decorate12([
|
|
2377
|
+
(0, import_type_graphql13.Mutation)(() => CopilotResponse),
|
|
2378
|
+
_ts_param(0, (0, import_type_graphql13.Ctx)()),
|
|
2379
|
+
_ts_param(1, (0, import_type_graphql13.Arg)("data")),
|
|
2380
|
+
_ts_param(2, (0, import_type_graphql13.Arg)("properties", () => import_graphql_scalars2.GraphQLJSONObject, {
|
|
2043
2381
|
nullable: true
|
|
2044
2382
|
})),
|
|
2045
|
-
|
|
2046
|
-
|
|
2383
|
+
_ts_metadata12("design:type", Function),
|
|
2384
|
+
_ts_metadata12("design:paramtypes", [
|
|
2047
2385
|
typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
|
|
2048
2386
|
typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
|
|
2049
2387
|
typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
|
|
2050
2388
|
]),
|
|
2051
|
-
|
|
2389
|
+
_ts_metadata12("design:returntype", Promise)
|
|
2052
2390
|
], CopilotResolver.prototype, "generateCopilotResponse", null);
|
|
2053
|
-
CopilotResolver =
|
|
2054
|
-
(0,
|
|
2391
|
+
CopilotResolver = _ts_decorate12([
|
|
2392
|
+
(0, import_type_graphql13.Resolver)(() => CopilotResponse)
|
|
2055
2393
|
], CopilotResolver);
|
|
2056
2394
|
|
|
2057
2395
|
// src/lib/integrations/shared.ts
|
|
2058
2396
|
var import_plugin_defer_stream = require("@graphql-yoga/plugin-defer-stream");
|
|
2059
|
-
|
|
2397
|
+
|
|
2398
|
+
// src/lib/logger.ts
|
|
2399
|
+
var import_pino = __toESM(require("pino"));
|
|
2400
|
+
var import_pino_pretty = __toESM(require("pino-pretty"));
|
|
2401
|
+
function createLogger(options) {
|
|
2402
|
+
const { level, component } = options || {};
|
|
2403
|
+
const stream = (0, import_pino_pretty.default)({
|
|
2404
|
+
colorize: true
|
|
2405
|
+
});
|
|
2406
|
+
const logger2 = (0, import_pino.default)({
|
|
2407
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
2408
|
+
redact: {
|
|
2409
|
+
paths: [
|
|
2410
|
+
"pid",
|
|
2411
|
+
"hostname"
|
|
2412
|
+
],
|
|
2413
|
+
remove: true
|
|
2414
|
+
}
|
|
2415
|
+
}, stream);
|
|
2416
|
+
if (component) {
|
|
2417
|
+
return logger2.child({
|
|
2418
|
+
component
|
|
2419
|
+
});
|
|
2420
|
+
} else {
|
|
2421
|
+
return logger2;
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
__name(createLogger, "createLogger");
|
|
2425
|
+
|
|
2426
|
+
// src/lib/integrations/shared.ts
|
|
2427
|
+
var logger = createLogger();
|
|
2428
|
+
async function createContext(initialContext, copilotKitContext, contextLogger, properties = {}) {
|
|
2429
|
+
logger.debug({
|
|
2430
|
+
copilotKitContext
|
|
2431
|
+
}, "Creating GraphQL context");
|
|
2060
2432
|
const ctx = {
|
|
2061
2433
|
...initialContext,
|
|
2062
2434
|
_copilotkit: {
|
|
2063
2435
|
...copilotKitContext
|
|
2064
|
-
}
|
|
2436
|
+
},
|
|
2437
|
+
properties: {
|
|
2438
|
+
...properties
|
|
2439
|
+
},
|
|
2440
|
+
logger: contextLogger
|
|
2065
2441
|
};
|
|
2066
2442
|
return ctx;
|
|
2067
2443
|
}
|
|
2068
2444
|
__name(createContext, "createContext");
|
|
2069
2445
|
function buildSchema(options = {}) {
|
|
2070
|
-
|
|
2446
|
+
logger.debug("Building GraphQL schema...");
|
|
2447
|
+
const schema = (0, import_type_graphql14.buildSchemaSync)({
|
|
2071
2448
|
resolvers: [
|
|
2072
2449
|
CopilotResolver
|
|
2073
2450
|
],
|
|
2074
2451
|
emitSchemaFile: options.emitSchemaFile
|
|
2075
2452
|
});
|
|
2453
|
+
logger.debug("GraphQL schema built successfully");
|
|
2076
2454
|
return schema;
|
|
2077
2455
|
}
|
|
2078
2456
|
__name(buildSchema, "buildSchema");
|
|
2079
2457
|
function getCommonConfig(options) {
|
|
2458
|
+
const logLevel = process.env.LOG_LEVEL || options.logLevel || "error";
|
|
2459
|
+
const logger2 = createLogger({
|
|
2460
|
+
level: logLevel,
|
|
2461
|
+
component: "getCommonConfig"
|
|
2462
|
+
});
|
|
2463
|
+
logger2.debug("Getting common config");
|
|
2464
|
+
const contextLogger = createLogger({
|
|
2465
|
+
level: logLevel
|
|
2466
|
+
});
|
|
2080
2467
|
return {
|
|
2468
|
+
logging: createLogger({
|
|
2469
|
+
component: "Yoga GraphQL",
|
|
2470
|
+
level: logLevel
|
|
2471
|
+
}),
|
|
2081
2472
|
schema: buildSchema(),
|
|
2082
2473
|
plugins: [
|
|
2083
2474
|
(0, import_plugin_defer_stream.useDeferStream)()
|
|
2084
2475
|
],
|
|
2085
|
-
context: (ctx) => createContext(ctx,
|
|
2086
|
-
runtime: options.runtime,
|
|
2087
|
-
serviceAdapter: options.serviceAdapter,
|
|
2088
|
-
properties: {}
|
|
2089
|
-
})
|
|
2476
|
+
context: (ctx) => createContext(ctx, options, contextLogger, options.properties)
|
|
2090
2477
|
};
|
|
2091
2478
|
}
|
|
2092
2479
|
__name(getCommonConfig, "getCommonConfig");
|
|
2093
2480
|
|
|
2094
2481
|
// src/lib/integrations/nextjs/app-router.ts
|
|
2095
2482
|
var import_graphql_yoga2 = require("graphql-yoga");
|
|
2096
|
-
function copilotRuntimeNextJSAppRouterEndpoint(
|
|
2097
|
-
const commonConfig = getCommonConfig(
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
});
|
|
2483
|
+
function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
2484
|
+
const commonConfig = getCommonConfig(options);
|
|
2485
|
+
const logger2 = commonConfig.logging;
|
|
2486
|
+
logger2.debug("Creating NextJS App Router endpoint");
|
|
2101
2487
|
const yoga = (0, import_graphql_yoga2.createYoga)({
|
|
2102
2488
|
...commonConfig,
|
|
2103
|
-
graphqlEndpoint: endpoint,
|
|
2489
|
+
graphqlEndpoint: options.endpoint,
|
|
2104
2490
|
fetchAPI: {
|
|
2105
2491
|
Response: globalThis.Response
|
|
2106
2492
|
}
|
|
@@ -2121,14 +2507,13 @@ var config = {
|
|
|
2121
2507
|
bodyParser: false
|
|
2122
2508
|
}
|
|
2123
2509
|
};
|
|
2124
|
-
function copilotRuntimeNextJSPagesRouterEndpoint(
|
|
2125
|
-
const commonConfig = getCommonConfig(
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
});
|
|
2510
|
+
function copilotRuntimeNextJSPagesRouterEndpoint(options) {
|
|
2511
|
+
const commonConfig = getCommonConfig(options);
|
|
2512
|
+
const logger2 = commonConfig.logging;
|
|
2513
|
+
logger2.debug("Creating NextJS Pages Router endpoint");
|
|
2129
2514
|
const yoga = (0, import_graphql_yoga3.createYoga)({
|
|
2130
2515
|
...commonConfig,
|
|
2131
|
-
graphqlEndpoint: endpoint
|
|
2516
|
+
graphqlEndpoint: options.endpoint
|
|
2132
2517
|
});
|
|
2133
2518
|
return yoga;
|
|
2134
2519
|
}
|
|
@@ -2136,14 +2521,13 @@ __name(copilotRuntimeNextJSPagesRouterEndpoint, "copilotRuntimeNextJSPagesRouter
|
|
|
2136
2521
|
|
|
2137
2522
|
// src/lib/integrations/node-http/index.ts
|
|
2138
2523
|
var import_graphql_yoga4 = require("graphql-yoga");
|
|
2139
|
-
function copilotRuntimeNodeHttpEndpoint(
|
|
2140
|
-
const commonConfig = getCommonConfig(
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
});
|
|
2524
|
+
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
2525
|
+
const commonConfig = getCommonConfig(options);
|
|
2526
|
+
const logger2 = commonConfig.logging;
|
|
2527
|
+
logger2.debug("Creating Node HTTP endpoint");
|
|
2144
2528
|
const yoga = (0, import_graphql_yoga4.createYoga)({
|
|
2145
2529
|
...commonConfig,
|
|
2146
|
-
graphqlEndpoint: endpoint
|
|
2530
|
+
graphqlEndpoint: options.endpoint
|
|
2147
2531
|
});
|
|
2148
2532
|
return yoga;
|
|
2149
2533
|
}
|