@copilotkit/runtime 1.6.0-next.3 → 1.6.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-25Z2ZUVM.mjs → chunk-3C73PW47.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-7EXH7PVD.mjs} +3 -2
- package/dist/chunk-7EXH7PVD.mjs.map +1 -0
- package/dist/{chunk-J6E3ZTJ3.mjs → chunk-F6WKKTYT.mjs} +29 -31
- package/dist/chunk-F6WKKTYT.mjs.map +1 -0
- package/dist/{chunk-7HPGWUP7.mjs → chunk-I6W6FUR5.mjs} +2 -2
- package/dist/{chunk-ZM4JOETB.mjs → chunk-RG3UJM7Q.mjs} +2 -2
- package/dist/index.js +99 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/lib/index.js +92 -93
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/lib/integrations/index.js +2 -2
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.js +2 -2
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.js +2 -2
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.js +2 -2
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.js +28 -27
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +3 -3
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +236 -0
- package/src/lib/runtime/remote-action-constructors.ts +9 -7
- package/src/lib/runtime/remote-lg-action.ts +2 -6
- package/src/service-adapters/conversion.ts +39 -46
- package/src/service-adapters/openai/utils.ts +2 -1
- package/tsconfig.json +3 -2
- package/dist/chunk-J6E3ZTJ3.mjs.map +0 -1
- package/dist/chunk-OS5YD32G.mjs.map +0 -1
- /package/dist/{chunk-25Z2ZUVM.mjs.map → chunk-3C73PW47.mjs.map} +0 -0
- /package/dist/{chunk-7HPGWUP7.mjs.map → chunk-I6W6FUR5.mjs.map} +0 -0
- /package/dist/{chunk-ZM4JOETB.mjs.map → chunk-RG3UJM7Q.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.6.0-next.
|
|
47
|
+
version: "1.6.0-next.5",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -66,7 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
devDependencies: {
|
|
67
67
|
"@swc/core": "1.5.28",
|
|
68
68
|
"@types/express": "^4.17.21",
|
|
69
|
-
"@types/jest": "^29.5.
|
|
69
|
+
"@types/jest": "^29.5.12",
|
|
70
70
|
"@types/node": "^18.11.17",
|
|
71
71
|
"@whatwg-node/server": "^0.9.34",
|
|
72
72
|
eslint: "^8.56.0",
|
|
@@ -159,7 +159,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
159
159
|
var import_reflect_metadata = require("reflect-metadata");
|
|
160
160
|
|
|
161
161
|
// src/lib/runtime/copilot-runtime.ts
|
|
162
|
-
var
|
|
162
|
+
var import_shared20 = require("@copilotkit/shared");
|
|
163
163
|
|
|
164
164
|
// src/service-adapters/langchain/langserve.ts
|
|
165
165
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -243,6 +243,7 @@ __name(RemoteChain, "RemoteChain");
|
|
|
243
243
|
var import_openai = __toESM(require("openai"));
|
|
244
244
|
|
|
245
245
|
// src/service-adapters/openai/utils.ts
|
|
246
|
+
var import_shared = require("@copilotkit/shared");
|
|
246
247
|
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
247
248
|
maxTokens || (maxTokens = maxTokensForOpenAIModel(model));
|
|
248
249
|
const result = [];
|
|
@@ -336,7 +337,7 @@ function convertActionInputToOpenAITool(action) {
|
|
|
336
337
|
function: {
|
|
337
338
|
name: action.name,
|
|
338
339
|
description: action.description,
|
|
339
|
-
parameters:
|
|
340
|
+
parameters: (0, import_shared.parseJson)(action.jsonSchema, {})
|
|
340
341
|
}
|
|
341
342
|
};
|
|
342
343
|
}
|
|
@@ -382,7 +383,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
382
383
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
383
384
|
|
|
384
385
|
// src/service-adapters/openai/openai-adapter.ts
|
|
385
|
-
var
|
|
386
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
386
387
|
var DEFAULT_MODEL = "gpt-4o";
|
|
387
388
|
var OpenAIAdapter = class {
|
|
388
389
|
model = DEFAULT_MODEL;
|
|
@@ -401,7 +402,7 @@ var OpenAIAdapter = class {
|
|
|
401
402
|
async process(request) {
|
|
402
403
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
403
404
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
404
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
405
|
+
const threadId = threadIdFromRequest ?? (0, import_shared2.randomUUID)();
|
|
405
406
|
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
406
407
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
407
408
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
@@ -508,7 +509,7 @@ __name(OpenAIAdapter, "OpenAIAdapter");
|
|
|
508
509
|
// src/service-adapters/langchain/utils.ts
|
|
509
510
|
var import_messages = require("@langchain/core/messages");
|
|
510
511
|
var import_tools = require("@langchain/core/tools");
|
|
511
|
-
var
|
|
512
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
512
513
|
function convertMessageToLangChainMessage(message) {
|
|
513
514
|
if (message.isTextMessage()) {
|
|
514
515
|
if (message.role == "user") {
|
|
@@ -541,7 +542,7 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
541
542
|
return new import_tools.DynamicStructuredTool({
|
|
542
543
|
name: actionInput.name,
|
|
543
544
|
description: actionInput.description,
|
|
544
|
-
schema: (0,
|
|
545
|
+
schema: (0, import_shared3.convertJsonSchemaToZodSchema)(JSON.parse(actionInput.jsonSchema), true),
|
|
545
546
|
func: async () => {
|
|
546
547
|
return "";
|
|
547
548
|
}
|
|
@@ -574,7 +575,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
574
575
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
575
576
|
if (typeof result === "string") {
|
|
576
577
|
if (!actionExecution) {
|
|
577
|
-
eventStream$.sendTextMessage((0,
|
|
578
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result);
|
|
578
579
|
} else {
|
|
579
580
|
eventStream$.sendActionExecutionResult({
|
|
580
581
|
actionExecutionId: actionExecution.id,
|
|
@@ -585,11 +586,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
585
586
|
} else if (isAIMessage(result)) {
|
|
586
587
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
587
588
|
if (result.content) {
|
|
588
|
-
eventStream$.sendTextMessage((0,
|
|
589
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
589
590
|
}
|
|
590
591
|
for (const toolCall of result.tool_calls) {
|
|
591
592
|
eventStream$.sendActionExecution({
|
|
592
|
-
actionExecutionId: toolCall.id || (0,
|
|
593
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
593
594
|
actionName: toolCall.name,
|
|
594
595
|
args: JSON.stringify(toolCall.args)
|
|
595
596
|
});
|
|
@@ -597,12 +598,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
597
598
|
} else if (isBaseMessageChunk(result)) {
|
|
598
599
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
599
600
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
600
|
-
eventStream$.sendTextMessage((0,
|
|
601
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
601
602
|
}
|
|
602
603
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
603
604
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
604
605
|
eventStream$.sendActionExecution({
|
|
605
|
-
actionExecutionId: toolCall.id || (0,
|
|
606
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
606
607
|
actionName: toolCall.name,
|
|
607
608
|
args: JSON.stringify(toolCall.args)
|
|
608
609
|
});
|
|
@@ -676,7 +677,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
676
677
|
});
|
|
677
678
|
} else if (content) {
|
|
678
679
|
mode = "message";
|
|
679
|
-
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0,
|
|
680
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared3.randomId)();
|
|
680
681
|
eventStream$.sendTextMessageStart({
|
|
681
682
|
messageId: currentMessageId
|
|
682
683
|
});
|
|
@@ -733,7 +734,7 @@ function encodeResult(result) {
|
|
|
733
734
|
__name(encodeResult, "encodeResult");
|
|
734
735
|
|
|
735
736
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
736
|
-
var
|
|
737
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
737
738
|
var import_promises = require("@langchain/core/callbacks/promises");
|
|
738
739
|
var LangChainAdapter = class {
|
|
739
740
|
options;
|
|
@@ -746,7 +747,7 @@ var LangChainAdapter = class {
|
|
|
746
747
|
async process(request) {
|
|
747
748
|
try {
|
|
748
749
|
const { eventSource, model, actions, messages, runId, threadId: threadIdFromRequest } = request;
|
|
749
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
750
|
+
const threadId = threadIdFromRequest ?? (0, import_shared4.randomUUID)();
|
|
750
751
|
const result = await this.options.chainFn({
|
|
751
752
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
752
753
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -990,7 +991,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
|
|
|
990
991
|
|
|
991
992
|
// src/service-adapters/unify/unify-adapter.ts
|
|
992
993
|
var import_openai3 = __toESM(require("openai"));
|
|
993
|
-
var
|
|
994
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
994
995
|
var UnifyAdapter = class {
|
|
995
996
|
apiKey;
|
|
996
997
|
model;
|
|
@@ -1032,7 +1033,7 @@ var UnifyAdapter = class {
|
|
|
1032
1033
|
for await (const chunk of stream) {
|
|
1033
1034
|
if (this.start) {
|
|
1034
1035
|
model = chunk.model;
|
|
1035
|
-
currentMessageId = (0,
|
|
1036
|
+
currentMessageId = (0, import_shared5.randomId)();
|
|
1036
1037
|
eventStream$.sendTextMessageStart({
|
|
1037
1038
|
messageId: currentMessageId
|
|
1038
1039
|
});
|
|
@@ -1099,7 +1100,7 @@ var UnifyAdapter = class {
|
|
|
1099
1100
|
eventStream$.complete();
|
|
1100
1101
|
});
|
|
1101
1102
|
return {
|
|
1102
|
-
threadId: request.threadId || (0,
|
|
1103
|
+
threadId: request.threadId || (0, import_shared5.randomUUID)()
|
|
1103
1104
|
};
|
|
1104
1105
|
}
|
|
1105
1106
|
};
|
|
@@ -1107,7 +1108,7 @@ __name(UnifyAdapter, "UnifyAdapter");
|
|
|
1107
1108
|
|
|
1108
1109
|
// src/service-adapters/groq/groq-adapter.ts
|
|
1109
1110
|
var import_groq_sdk = require("groq-sdk");
|
|
1110
|
-
var
|
|
1111
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1111
1112
|
var DEFAULT_MODEL2 = "llama3-groq-70b-8192-tool-use-preview";
|
|
1112
1113
|
var GroqAdapter = class {
|
|
1113
1114
|
model = DEFAULT_MODEL2;
|
|
@@ -1220,7 +1221,7 @@ var GroqAdapter = class {
|
|
|
1220
1221
|
eventStream$.complete();
|
|
1221
1222
|
});
|
|
1222
1223
|
return {
|
|
1223
|
-
threadId: request.threadId || (0,
|
|
1224
|
+
threadId: request.threadId || (0, import_shared6.randomUUID)()
|
|
1224
1225
|
};
|
|
1225
1226
|
}
|
|
1226
1227
|
};
|
|
@@ -1362,7 +1363,7 @@ function groupAnthropicMessagesByRole(messageParams) {
|
|
|
1362
1363
|
__name(groupAnthropicMessagesByRole, "groupAnthropicMessagesByRole");
|
|
1363
1364
|
|
|
1364
1365
|
// src/service-adapters/anthropic/anthropic-adapter.ts
|
|
1365
|
-
var
|
|
1366
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1366
1367
|
var DEFAULT_MODEL3 = "claude-3-sonnet-20240229";
|
|
1367
1368
|
var AnthropicAdapter = class {
|
|
1368
1369
|
model = DEFAULT_MODEL3;
|
|
@@ -1413,8 +1414,8 @@ var AnthropicAdapter = class {
|
|
|
1413
1414
|
eventSource.stream(async (eventStream$) => {
|
|
1414
1415
|
let mode = null;
|
|
1415
1416
|
let didOutputText = false;
|
|
1416
|
-
let currentMessageId = (0,
|
|
1417
|
-
let currentToolCallId = (0,
|
|
1417
|
+
let currentMessageId = (0, import_shared7.randomId)();
|
|
1418
|
+
let currentToolCallId = (0, import_shared7.randomId)();
|
|
1418
1419
|
let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
|
|
1419
1420
|
for await (const chunk of await stream) {
|
|
1420
1421
|
if (chunk.type === "message_start") {
|
|
@@ -1471,7 +1472,7 @@ var AnthropicAdapter = class {
|
|
|
1471
1472
|
eventStream$.complete();
|
|
1472
1473
|
});
|
|
1473
1474
|
return {
|
|
1474
|
-
threadId: threadId || (0,
|
|
1475
|
+
threadId: threadId || (0, import_shared7.randomUUID)()
|
|
1475
1476
|
};
|
|
1476
1477
|
}
|
|
1477
1478
|
};
|
|
@@ -1511,7 +1512,7 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1511
1512
|
|
|
1512
1513
|
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1513
1514
|
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1514
|
-
var
|
|
1515
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1515
1516
|
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1516
1517
|
var ExperimentalOllamaAdapter = class {
|
|
1517
1518
|
model;
|
|
@@ -1530,7 +1531,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1530
1531
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1531
1532
|
const _stream = await ollama.stream(contents);
|
|
1532
1533
|
eventSource.stream(async (eventStream$) => {
|
|
1533
|
-
const currentMessageId = (0,
|
|
1534
|
+
const currentMessageId = (0, import_shared8.randomId)();
|
|
1534
1535
|
eventStream$.sendTextMessageStart({
|
|
1535
1536
|
messageId: currentMessageId
|
|
1536
1537
|
});
|
|
@@ -1546,18 +1547,18 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1546
1547
|
eventStream$.complete();
|
|
1547
1548
|
});
|
|
1548
1549
|
return {
|
|
1549
|
-
threadId: request.threadId || (0,
|
|
1550
|
+
threadId: request.threadId || (0, import_shared8.randomUUID)()
|
|
1550
1551
|
};
|
|
1551
1552
|
}
|
|
1552
1553
|
};
|
|
1553
1554
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1554
1555
|
|
|
1555
1556
|
// src/service-adapters/empty/empty-adapter.ts
|
|
1556
|
-
var
|
|
1557
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1557
1558
|
var EmptyAdapter = class {
|
|
1558
1559
|
async process(request) {
|
|
1559
1560
|
return {
|
|
1560
|
-
threadId: request.threadId || (0,
|
|
1561
|
+
threadId: request.threadId || (0, import_shared9.randomUUID)()
|
|
1561
1562
|
};
|
|
1562
1563
|
}
|
|
1563
1564
|
};
|
|
@@ -1565,11 +1566,11 @@ __name(EmptyAdapter, "EmptyAdapter");
|
|
|
1565
1566
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
1566
1567
|
|
|
1567
1568
|
// src/service-adapters/events.ts
|
|
1568
|
-
var
|
|
1569
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
1569
1570
|
var import_rxjs2 = require("rxjs");
|
|
1570
1571
|
|
|
1571
1572
|
// src/lib/telemetry-client.ts
|
|
1572
|
-
var
|
|
1573
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
1573
1574
|
|
|
1574
1575
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1575
1576
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1609,7 +1610,7 @@ var CustomEventNames;
|
|
|
1609
1610
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1610
1611
|
|
|
1611
1612
|
// src/agents/langgraph/event-source.ts
|
|
1612
|
-
var
|
|
1613
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1613
1614
|
var RemoteLangGraphEventSource = class {
|
|
1614
1615
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1615
1616
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1815,7 +1816,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1815
1816
|
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1816
1817
|
});
|
|
1817
1818
|
}
|
|
1818
|
-
const messageId = (0,
|
|
1819
|
+
const messageId = (0, import_shared10.randomId)();
|
|
1819
1820
|
events.push({
|
|
1820
1821
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1821
1822
|
messageId
|
|
@@ -1838,7 +1839,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1838
1839
|
// src/lib/runtime/remote-lg-action.ts
|
|
1839
1840
|
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1840
1841
|
var import_node_crypto = require("crypto");
|
|
1841
|
-
var
|
|
1842
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1842
1843
|
var import_partial_json = require("partial-json");
|
|
1843
1844
|
|
|
1844
1845
|
// src/graphql/types/enums.ts
|
|
@@ -2467,6 +2468,7 @@ CopilotKitLangGraphInterruptEvent = _ts_decorate5([
|
|
|
2467
2468
|
], CopilotKitLangGraphInterruptEvent);
|
|
2468
2469
|
|
|
2469
2470
|
// src/lib/runtime/remote-lg-action.ts
|
|
2471
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2470
2472
|
var activeInterruptEvent = false;
|
|
2471
2473
|
async function execute(args) {
|
|
2472
2474
|
return new ReadableStream({
|
|
@@ -2496,11 +2498,11 @@ async function streamEvents(controller, args) {
|
|
|
2496
2498
|
...propertyHeaders
|
|
2497
2499
|
}
|
|
2498
2500
|
});
|
|
2499
|
-
let threadId = argsInitialThreadId ?? (0,
|
|
2501
|
+
let threadId = argsInitialThreadId ?? (0, import_shared11.randomUUID)();
|
|
2500
2502
|
if (argsInitialThreadId && argsInitialThreadId.startsWith("ck-")) {
|
|
2501
2503
|
threadId = argsInitialThreadId.substring(3);
|
|
2502
2504
|
}
|
|
2503
|
-
if (!(0,
|
|
2505
|
+
if (!(0, import_shared11.isValidUUID)(threadId)) {
|
|
2504
2506
|
console.warn(`Cannot use the threadId ${threadId} with LangGraph Platform. Must be a valid UUID.`);
|
|
2505
2507
|
}
|
|
2506
2508
|
let wasInitiatedWithExistingThread = true;
|
|
@@ -2546,15 +2548,9 @@ async function streamEvents(controller, args) {
|
|
|
2546
2548
|
}
|
|
2547
2549
|
if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
|
|
2548
2550
|
let response = lgInterruptMetaEvent.response;
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
};
|
|
2553
|
-
} catch (e) {
|
|
2554
|
-
payload.command = {
|
|
2555
|
-
resume: response
|
|
2556
|
-
};
|
|
2557
|
-
}
|
|
2551
|
+
payload.command = {
|
|
2552
|
+
resume: (0, import_shared12.parseJson)(response, response)
|
|
2553
|
+
};
|
|
2558
2554
|
}
|
|
2559
2555
|
if (mode === "continue" && !activeInterruptEvent) {
|
|
2560
2556
|
await client.threads.updateState(threadId, {
|
|
@@ -2994,8 +2990,9 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
2994
2990
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2995
2991
|
|
|
2996
2992
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2997
|
-
var
|
|
2998
|
-
var
|
|
2993
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2994
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2995
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2999
2996
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
3000
2997
|
const agents = endpoint.agents.map((agent) => ({
|
|
3001
2998
|
name: agent.name,
|
|
@@ -3018,8 +3015,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3018
3015
|
if (agentStates) {
|
|
3019
3016
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3020
3017
|
if (jsonState) {
|
|
3021
|
-
state =
|
|
3022
|
-
configurable =
|
|
3018
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3019
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3023
3020
|
}
|
|
3024
3021
|
}
|
|
3025
3022
|
try {
|
|
@@ -3039,7 +3036,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3039
3036
|
state,
|
|
3040
3037
|
configurable,
|
|
3041
3038
|
properties: graphqlContext.properties,
|
|
3042
|
-
actions:
|
|
3039
|
+
actions: (0, import_shared15.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
3043
3040
|
name: action.name,
|
|
3044
3041
|
description: action.description,
|
|
3045
3042
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -3099,11 +3096,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3099
3096
|
body: await response.text()
|
|
3100
3097
|
}, "Failed to execute remote action");
|
|
3101
3098
|
if (response.status === 404) {
|
|
3102
|
-
throw new
|
|
3099
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3103
3100
|
url: fetchUrl
|
|
3104
3101
|
});
|
|
3105
3102
|
}
|
|
3106
|
-
throw new
|
|
3103
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3107
3104
|
status: response.status,
|
|
3108
3105
|
url: fetchUrl,
|
|
3109
3106
|
isRemoteEndpoint: true
|
|
@@ -3117,10 +3114,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3117
3114
|
}, "Executed remote action");
|
|
3118
3115
|
return result;
|
|
3119
3116
|
} catch (error) {
|
|
3120
|
-
if (error instanceof
|
|
3117
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3121
3118
|
throw error;
|
|
3122
3119
|
}
|
|
3123
|
-
throw new
|
|
3120
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3124
3121
|
error,
|
|
3125
3122
|
url: fetchUrl
|
|
3126
3123
|
});
|
|
@@ -3148,8 +3145,8 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3148
3145
|
if (agentStates) {
|
|
3149
3146
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3150
3147
|
if (jsonState) {
|
|
3151
|
-
state =
|
|
3152
|
-
configurable =
|
|
3148
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3149
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3153
3150
|
}
|
|
3154
3151
|
}
|
|
3155
3152
|
const fetchUrl = `${url}/agents/execute`;
|
|
@@ -3168,7 +3165,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3168
3165
|
state,
|
|
3169
3166
|
configurable,
|
|
3170
3167
|
properties: graphqlContext.properties,
|
|
3171
|
-
actions:
|
|
3168
|
+
actions: (0, import_shared15.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
3172
3169
|
name: action.name,
|
|
3173
3170
|
description: action.description,
|
|
3174
3171
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -3183,11 +3180,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3183
3180
|
body: await response.text()
|
|
3184
3181
|
}, "Failed to execute remote agent");
|
|
3185
3182
|
if (response.status === 404) {
|
|
3186
|
-
throw new
|
|
3183
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3187
3184
|
url: fetchUrl
|
|
3188
3185
|
});
|
|
3189
3186
|
}
|
|
3190
|
-
throw new
|
|
3187
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3191
3188
|
status: response.status,
|
|
3192
3189
|
url: fetchUrl,
|
|
3193
3190
|
isRemoteEndpoint: true
|
|
@@ -3197,10 +3194,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3197
3194
|
streamResponse(response.body, eventSource.eventStream$);
|
|
3198
3195
|
return eventSource.processLangGraphEvents();
|
|
3199
3196
|
} catch (error) {
|
|
3200
|
-
if (error instanceof
|
|
3197
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3201
3198
|
throw error;
|
|
3202
3199
|
}
|
|
3203
|
-
throw new
|
|
3200
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3204
3201
|
error,
|
|
3205
3202
|
url: fetchUrl
|
|
3206
3203
|
});
|
|
@@ -3274,7 +3271,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
3274
3271
|
__name(createHeaders, "createHeaders");
|
|
3275
3272
|
|
|
3276
3273
|
// src/lib/runtime/remote-actions.ts
|
|
3277
|
-
var
|
|
3274
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
3278
3275
|
var EndpointType;
|
|
3279
3276
|
(function(EndpointType2) {
|
|
3280
3277
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -3308,7 +3305,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3308
3305
|
status: response.status,
|
|
3309
3306
|
body: await response.text()
|
|
3310
3307
|
}, "Failed to fetch actions from url");
|
|
3311
|
-
throw new
|
|
3308
|
+
throw new import_shared16.ResolvedCopilotKitError({
|
|
3312
3309
|
status: response.status,
|
|
3313
3310
|
url: fetchUrl,
|
|
3314
3311
|
isRemoteEndpoint: true
|
|
@@ -3320,10 +3317,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3320
3317
|
}, "Fetched actions from url");
|
|
3321
3318
|
return json;
|
|
3322
3319
|
} catch (error) {
|
|
3323
|
-
if (error instanceof
|
|
3320
|
+
if (error instanceof import_shared16.CopilotKitError) {
|
|
3324
3321
|
throw error;
|
|
3325
3322
|
}
|
|
3326
|
-
throw new
|
|
3323
|
+
throw new import_shared16.CopilotKitLowLevelError({
|
|
3327
3324
|
error,
|
|
3328
3325
|
url: fetchUrl
|
|
3329
3326
|
});
|
|
@@ -3386,7 +3383,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3386
3383
|
// src/lib/telemetry-client.ts
|
|
3387
3384
|
var import_node_crypto3 = require("crypto");
|
|
3388
3385
|
var packageJson = require_package();
|
|
3389
|
-
var telemetryClient = new
|
|
3386
|
+
var telemetryClient = new import_shared17.TelemetryClient({
|
|
3390
3387
|
packageName: packageJson.name,
|
|
3391
3388
|
packageVersion: packageJson.version
|
|
3392
3389
|
});
|
|
@@ -3703,10 +3700,10 @@ var RuntimeEventSource = class {
|
|
|
3703
3700
|
const errorMessage = `\u274C ${message}`;
|
|
3704
3701
|
if (!this.callback) {
|
|
3705
3702
|
this.stream(async (eventStream$) => {
|
|
3706
|
-
eventStream$.sendTextMessage((0,
|
|
3703
|
+
eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3707
3704
|
});
|
|
3708
3705
|
} else {
|
|
3709
|
-
this.eventStream$.sendTextMessage((0,
|
|
3706
|
+
this.eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3710
3707
|
}
|
|
3711
3708
|
}
|
|
3712
3709
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -3865,35 +3862,35 @@ __name(executeAction, "executeAction");
|
|
|
3865
3862
|
|
|
3866
3863
|
// src/service-adapters/conversion.ts
|
|
3867
3864
|
var import_class_transformer2 = require("class-transformer");
|
|
3865
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
3868
3866
|
function convertGqlInputToMessages(inputMessages) {
|
|
3869
|
-
const messages =
|
|
3870
|
-
for (const message of inputMessages) {
|
|
3867
|
+
const messages = (0, import_shared19.tryMap)(inputMessages, (message) => {
|
|
3871
3868
|
if (message.textMessage) {
|
|
3872
|
-
|
|
3869
|
+
return (0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
3873
3870
|
id: message.id,
|
|
3874
3871
|
createdAt: message.createdAt,
|
|
3875
3872
|
role: message.textMessage.role,
|
|
3876
3873
|
content: message.textMessage.content,
|
|
3877
3874
|
parentMessageId: message.textMessage.parentMessageId
|
|
3878
|
-
})
|
|
3875
|
+
});
|
|
3879
3876
|
} else if (message.actionExecutionMessage) {
|
|
3880
|
-
|
|
3877
|
+
return (0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
3881
3878
|
id: message.id,
|
|
3882
3879
|
createdAt: message.createdAt,
|
|
3883
3880
|
name: message.actionExecutionMessage.name,
|
|
3884
3881
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
3885
3882
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3886
|
-
})
|
|
3883
|
+
});
|
|
3887
3884
|
} else if (message.resultMessage) {
|
|
3888
|
-
|
|
3885
|
+
return (0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
3889
3886
|
id: message.id,
|
|
3890
3887
|
createdAt: message.createdAt,
|
|
3891
3888
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
3892
3889
|
actionName: message.resultMessage.actionName,
|
|
3893
3890
|
result: message.resultMessage.result
|
|
3894
|
-
})
|
|
3891
|
+
});
|
|
3895
3892
|
} else if (message.agentStateMessage) {
|
|
3896
|
-
|
|
3893
|
+
return (0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
3897
3894
|
id: message.id,
|
|
3898
3895
|
threadId: message.agentStateMessage.threadId,
|
|
3899
3896
|
createdAt: message.createdAt,
|
|
@@ -3904,10 +3901,12 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3904
3901
|
role: message.agentStateMessage.role,
|
|
3905
3902
|
state: JSON.parse(message.agentStateMessage.state),
|
|
3906
3903
|
running: message.agentStateMessage.running
|
|
3907
|
-
})
|
|
3904
|
+
});
|
|
3905
|
+
} else {
|
|
3906
|
+
return null;
|
|
3908
3907
|
}
|
|
3909
|
-
}
|
|
3910
|
-
return messages;
|
|
3908
|
+
});
|
|
3909
|
+
return messages.filter((m) => m);
|
|
3911
3910
|
}
|
|
3912
3911
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
3913
3912
|
|
|
@@ -3942,7 +3941,7 @@ var CopilotRuntime = class {
|
|
|
3942
3941
|
return await this.processAgentRequest(request);
|
|
3943
3942
|
}
|
|
3944
3943
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3945
|
-
throw new
|
|
3944
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
3946
3945
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3947
3946
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3948
3947
|
please use an LLM adapter instead.`
|
|
@@ -3954,7 +3953,7 @@ please use an LLM adapter instead.`
|
|
|
3954
3953
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3955
3954
|
name: action.name,
|
|
3956
3955
|
description: action.description,
|
|
3957
|
-
jsonSchema: JSON.stringify((0,
|
|
3956
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
3958
3957
|
}));
|
|
3959
3958
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3960
3959
|
...serverSideActionsInput,
|
|
@@ -4006,7 +4005,7 @@ please use an LLM adapter instead.`
|
|
|
4006
4005
|
extensions: result.extensions
|
|
4007
4006
|
};
|
|
4008
4007
|
} catch (error) {
|
|
4009
|
-
if (error instanceof
|
|
4008
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4010
4009
|
throw error;
|
|
4011
4010
|
}
|
|
4012
4011
|
console.error("Error getting response:", error);
|
|
@@ -4052,11 +4051,11 @@ please use an LLM adapter instead.`
|
|
|
4052
4051
|
});
|
|
4053
4052
|
if (!response.ok) {
|
|
4054
4053
|
if (response.status === 404) {
|
|
4055
|
-
throw new
|
|
4054
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4056
4055
|
url: fetchUrl
|
|
4057
4056
|
});
|
|
4058
4057
|
}
|
|
4059
|
-
throw new
|
|
4058
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4060
4059
|
status: response.status,
|
|
4061
4060
|
url: fetchUrl,
|
|
4062
4061
|
isRemoteEndpoint: true
|
|
@@ -4066,7 +4065,7 @@ please use an LLM adapter instead.`
|
|
|
4066
4065
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
4067
4066
|
name: agent.name,
|
|
4068
4067
|
description: agent.description ?? "" ?? "",
|
|
4069
|
-
id: (0,
|
|
4068
|
+
id: (0, import_shared20.randomId)(),
|
|
4070
4069
|
endpoint
|
|
4071
4070
|
}));
|
|
4072
4071
|
return [
|
|
@@ -4074,10 +4073,10 @@ please use an LLM adapter instead.`
|
|
|
4074
4073
|
...endpointAgents
|
|
4075
4074
|
];
|
|
4076
4075
|
} catch (error) {
|
|
4077
|
-
if (error instanceof
|
|
4076
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4078
4077
|
throw error;
|
|
4079
4078
|
}
|
|
4080
|
-
throw new
|
|
4079
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4081
4080
|
error,
|
|
4082
4081
|
url: fetchUrl
|
|
4083
4082
|
});
|
|
@@ -4139,11 +4138,11 @@ please use an LLM adapter instead.`
|
|
|
4139
4138
|
});
|
|
4140
4139
|
if (!response.ok) {
|
|
4141
4140
|
if (response.status === 404) {
|
|
4142
|
-
throw new
|
|
4141
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4143
4142
|
url: fetchUrl
|
|
4144
4143
|
});
|
|
4145
4144
|
}
|
|
4146
|
-
throw new
|
|
4145
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4147
4146
|
status: response.status,
|
|
4148
4147
|
url: fetchUrl,
|
|
4149
4148
|
isRemoteEndpoint: true
|
|
@@ -4156,10 +4155,10 @@ please use an LLM adapter instead.`
|
|
|
4156
4155
|
messages: JSON.stringify(data.messages)
|
|
4157
4156
|
};
|
|
4158
4157
|
} catch (error) {
|
|
4159
|
-
if (error instanceof
|
|
4158
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4160
4159
|
throw error;
|
|
4161
4160
|
}
|
|
4162
|
-
throw new
|
|
4161
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4163
4162
|
error,
|
|
4164
4163
|
url: fetchUrl
|
|
4165
4164
|
});
|
|
@@ -4177,7 +4176,7 @@ please use an LLM adapter instead.`
|
|
|
4177
4176
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4178
4177
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
4179
4178
|
if (!currentAgent) {
|
|
4180
|
-
throw new
|
|
4179
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4181
4180
|
agentName
|
|
4182
4181
|
});
|
|
4183
4182
|
}
|
|
@@ -4188,7 +4187,7 @@ please use an LLM adapter instead.`
|
|
|
4188
4187
|
)).map((action) => ({
|
|
4189
4188
|
name: action.name,
|
|
4190
4189
|
description: action.description,
|
|
4191
|
-
jsonSchema: JSON.stringify((0,
|
|
4190
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4192
4191
|
}));
|
|
4193
4192
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
4194
4193
|
...availableActionsForCurrentAgent,
|
|
@@ -5113,7 +5112,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
5113
5112
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
5114
5113
|
|
|
5115
5114
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
5116
|
-
var
|
|
5115
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
5117
5116
|
|
|
5118
5117
|
// src/graphql/types/agents-response.type.ts
|
|
5119
5118
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -5296,7 +5295,7 @@ var CopilotResolver = class {
|
|
|
5296
5295
|
rejectOutputMessagesPromise = reject;
|
|
5297
5296
|
});
|
|
5298
5297
|
logger2.debug("Processing");
|
|
5299
|
-
const { eventSource, threadId = (0,
|
|
5298
|
+
const { eventSource, threadId = (0, import_shared21.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5300
5299
|
serviceAdapter,
|
|
5301
5300
|
messages: data.messages,
|
|
5302
5301
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5429,7 +5428,7 @@ var CopilotResolver = class {
|
|
|
5429
5428
|
});
|
|
5430
5429
|
outputMessages = [
|
|
5431
5430
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5432
|
-
id: (0,
|
|
5431
|
+
id: (0, import_shared21.randomId)(),
|
|
5433
5432
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5434
5433
|
content: result.reason,
|
|
5435
5434
|
role: MessageRole.assistant
|
|
@@ -5607,7 +5606,7 @@ var CopilotResolver = class {
|
|
|
5607
5606
|
event
|
|
5608
5607
|
}, "Agent message event received");
|
|
5609
5608
|
pushMessage({
|
|
5610
|
-
id: (0,
|
|
5609
|
+
id: (0, import_shared21.randomId)(),
|
|
5611
5610
|
status: new SuccessMessageStatus(),
|
|
5612
5611
|
threadId: event.threadId,
|
|
5613
5612
|
agentName: event.agentName,
|
|
@@ -5620,7 +5619,7 @@ var CopilotResolver = class {
|
|
|
5620
5619
|
createdAt: /* @__PURE__ */ new Date()
|
|
5621
5620
|
});
|
|
5622
5621
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5623
|
-
id: (0,
|
|
5622
|
+
id: (0, import_shared21.randomId)(),
|
|
5624
5623
|
threadId: event.threadId,
|
|
5625
5624
|
agentName: event.agentName,
|
|
5626
5625
|
nodeName: event.nodeName,
|