@copilotkit/runtime 1.6.0-next.3 → 1.6.0-next.4
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 +7 -0
- package/dist/{chunk-ZM4JOETB.mjs → chunk-4FCUC27H.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-7EXH7PVD.mjs} +3 -2
- package/dist/chunk-7EXH7PVD.mjs.map +1 -0
- package/dist/{chunk-25Z2ZUVM.mjs → chunk-ROFUPT7E.mjs} +2 -2
- package/dist/{chunk-J6E3ZTJ3.mjs → chunk-YUCVJM6E.mjs} +22 -25
- package/dist/chunk-YUCVJM6E.mjs.map +1 -0
- package/dist/{chunk-7HPGWUP7.mjs → chunk-Z5VUD7NL.mjs} +2 -2
- package/dist/index.js +88 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/lib/index.js +81 -83
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- 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 +7 -6
- package/src/lib/runtime/remote-lg-action.ts +2 -6
- package/src/service-adapters/conversion.ts +3 -2
- 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-ZM4JOETB.mjs.map → chunk-4FCUC27H.mjs.map} +0 -0
- /package/dist/{chunk-25Z2ZUVM.mjs.map → chunk-ROFUPT7E.mjs.map} +0 -0
- /package/dist/{chunk-7HPGWUP7.mjs.map → chunk-Z5VUD7NL.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-YUCVJM6E.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNodeExpressEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-Z5VUD7NL.mjs.map
|
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.4",
|
|
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 {
|
|
@@ -3042,7 +3039,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3042
3039
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
3043
3040
|
name: action.name,
|
|
3044
3041
|
description: action.description,
|
|
3045
|
-
parameters:
|
|
3042
|
+
parameters: (0, import_shared15.parseJson)(action.jsonSchema, "")
|
|
3046
3043
|
})),
|
|
3047
3044
|
metaEvents
|
|
3048
3045
|
});
|
|
@@ -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`;
|
|
@@ -3171,7 +3168,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3171
3168
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
3172
3169
|
name: action.name,
|
|
3173
3170
|
description: action.description,
|
|
3174
|
-
parameters:
|
|
3171
|
+
parameters: (0, import_shared15.parseJson)(action.jsonSchema, {})
|
|
3175
3172
|
})),
|
|
3176
3173
|
metaEvents
|
|
3177
3174
|
})
|
|
@@ -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,6 +3862,7 @@ __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
3867
|
const messages = [];
|
|
3870
3868
|
for (const message of inputMessages) {
|
|
@@ -3881,7 +3879,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3881
3879
|
id: message.id,
|
|
3882
3880
|
createdAt: message.createdAt,
|
|
3883
3881
|
name: message.actionExecutionMessage.name,
|
|
3884
|
-
arguments:
|
|
3882
|
+
arguments: (0, import_shared19.parseJson)(message.actionExecutionMessage.arguments, {}),
|
|
3885
3883
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3886
3884
|
}));
|
|
3887
3885
|
} else if (message.resultMessage) {
|
|
@@ -3902,7 +3900,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3902
3900
|
runId: message.agentStateMessage.runId,
|
|
3903
3901
|
active: message.agentStateMessage.active,
|
|
3904
3902
|
role: message.agentStateMessage.role,
|
|
3905
|
-
state:
|
|
3903
|
+
state: (0, import_shared19.parseJson)(message.agentStateMessage.state, {}),
|
|
3906
3904
|
running: message.agentStateMessage.running
|
|
3907
3905
|
}));
|
|
3908
3906
|
}
|
|
@@ -3942,7 +3940,7 @@ var CopilotRuntime = class {
|
|
|
3942
3940
|
return await this.processAgentRequest(request);
|
|
3943
3941
|
}
|
|
3944
3942
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3945
|
-
throw new
|
|
3943
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
3946
3944
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3947
3945
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3948
3946
|
please use an LLM adapter instead.`
|
|
@@ -3954,7 +3952,7 @@ please use an LLM adapter instead.`
|
|
|
3954
3952
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3955
3953
|
name: action.name,
|
|
3956
3954
|
description: action.description,
|
|
3957
|
-
jsonSchema: JSON.stringify((0,
|
|
3955
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
3958
3956
|
}));
|
|
3959
3957
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3960
3958
|
...serverSideActionsInput,
|
|
@@ -4006,7 +4004,7 @@ please use an LLM adapter instead.`
|
|
|
4006
4004
|
extensions: result.extensions
|
|
4007
4005
|
};
|
|
4008
4006
|
} catch (error) {
|
|
4009
|
-
if (error instanceof
|
|
4007
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4010
4008
|
throw error;
|
|
4011
4009
|
}
|
|
4012
4010
|
console.error("Error getting response:", error);
|
|
@@ -4052,11 +4050,11 @@ please use an LLM adapter instead.`
|
|
|
4052
4050
|
});
|
|
4053
4051
|
if (!response.ok) {
|
|
4054
4052
|
if (response.status === 404) {
|
|
4055
|
-
throw new
|
|
4053
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4056
4054
|
url: fetchUrl
|
|
4057
4055
|
});
|
|
4058
4056
|
}
|
|
4059
|
-
throw new
|
|
4057
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4060
4058
|
status: response.status,
|
|
4061
4059
|
url: fetchUrl,
|
|
4062
4060
|
isRemoteEndpoint: true
|
|
@@ -4066,7 +4064,7 @@ please use an LLM adapter instead.`
|
|
|
4066
4064
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
4067
4065
|
name: agent.name,
|
|
4068
4066
|
description: agent.description ?? "" ?? "",
|
|
4069
|
-
id: (0,
|
|
4067
|
+
id: (0, import_shared20.randomId)(),
|
|
4070
4068
|
endpoint
|
|
4071
4069
|
}));
|
|
4072
4070
|
return [
|
|
@@ -4074,10 +4072,10 @@ please use an LLM adapter instead.`
|
|
|
4074
4072
|
...endpointAgents
|
|
4075
4073
|
];
|
|
4076
4074
|
} catch (error) {
|
|
4077
|
-
if (error instanceof
|
|
4075
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4078
4076
|
throw error;
|
|
4079
4077
|
}
|
|
4080
|
-
throw new
|
|
4078
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4081
4079
|
error,
|
|
4082
4080
|
url: fetchUrl
|
|
4083
4081
|
});
|
|
@@ -4139,11 +4137,11 @@ please use an LLM adapter instead.`
|
|
|
4139
4137
|
});
|
|
4140
4138
|
if (!response.ok) {
|
|
4141
4139
|
if (response.status === 404) {
|
|
4142
|
-
throw new
|
|
4140
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4143
4141
|
url: fetchUrl
|
|
4144
4142
|
});
|
|
4145
4143
|
}
|
|
4146
|
-
throw new
|
|
4144
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4147
4145
|
status: response.status,
|
|
4148
4146
|
url: fetchUrl,
|
|
4149
4147
|
isRemoteEndpoint: true
|
|
@@ -4156,10 +4154,10 @@ please use an LLM adapter instead.`
|
|
|
4156
4154
|
messages: JSON.stringify(data.messages)
|
|
4157
4155
|
};
|
|
4158
4156
|
} catch (error) {
|
|
4159
|
-
if (error instanceof
|
|
4157
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4160
4158
|
throw error;
|
|
4161
4159
|
}
|
|
4162
|
-
throw new
|
|
4160
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4163
4161
|
error,
|
|
4164
4162
|
url: fetchUrl
|
|
4165
4163
|
});
|
|
@@ -4177,7 +4175,7 @@ please use an LLM adapter instead.`
|
|
|
4177
4175
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4178
4176
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
4179
4177
|
if (!currentAgent) {
|
|
4180
|
-
throw new
|
|
4178
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4181
4179
|
agentName
|
|
4182
4180
|
});
|
|
4183
4181
|
}
|
|
@@ -4188,7 +4186,7 @@ please use an LLM adapter instead.`
|
|
|
4188
4186
|
)).map((action) => ({
|
|
4189
4187
|
name: action.name,
|
|
4190
4188
|
description: action.description,
|
|
4191
|
-
jsonSchema: JSON.stringify((0,
|
|
4189
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4192
4190
|
}));
|
|
4193
4191
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
4194
4192
|
...availableActionsForCurrentAgent,
|
|
@@ -5113,7 +5111,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
5113
5111
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
5114
5112
|
|
|
5115
5113
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
5116
|
-
var
|
|
5114
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
5117
5115
|
|
|
5118
5116
|
// src/graphql/types/agents-response.type.ts
|
|
5119
5117
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -5296,7 +5294,7 @@ var CopilotResolver = class {
|
|
|
5296
5294
|
rejectOutputMessagesPromise = reject;
|
|
5297
5295
|
});
|
|
5298
5296
|
logger2.debug("Processing");
|
|
5299
|
-
const { eventSource, threadId = (0,
|
|
5297
|
+
const { eventSource, threadId = (0, import_shared21.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5300
5298
|
serviceAdapter,
|
|
5301
5299
|
messages: data.messages,
|
|
5302
5300
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5429,7 +5427,7 @@ var CopilotResolver = class {
|
|
|
5429
5427
|
});
|
|
5430
5428
|
outputMessages = [
|
|
5431
5429
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5432
|
-
id: (0,
|
|
5430
|
+
id: (0, import_shared21.randomId)(),
|
|
5433
5431
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5434
5432
|
content: result.reason,
|
|
5435
5433
|
role: MessageRole.assistant
|
|
@@ -5607,7 +5605,7 @@ var CopilotResolver = class {
|
|
|
5607
5605
|
event
|
|
5608
5606
|
}, "Agent message event received");
|
|
5609
5607
|
pushMessage({
|
|
5610
|
-
id: (0,
|
|
5608
|
+
id: (0, import_shared21.randomId)(),
|
|
5611
5609
|
status: new SuccessMessageStatus(),
|
|
5612
5610
|
threadId: event.threadId,
|
|
5613
5611
|
agentName: event.agentName,
|
|
@@ -5620,7 +5618,7 @@ var CopilotResolver = class {
|
|
|
5620
5618
|
createdAt: /* @__PURE__ */ new Date()
|
|
5621
5619
|
});
|
|
5622
5620
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5623
|
-
id: (0,
|
|
5621
|
+
id: (0, import_shared21.randomId)(),
|
|
5624
5622
|
threadId: event.threadId,
|
|
5625
5623
|
agentName: event.agentName,
|
|
5626
5624
|
nodeName: event.nodeName,
|