@copilotkit/runtime 1.9.2-next.9 → 1.9.3-next.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/CHANGELOG.md +176 -0
- package/dist/{chunk-Z5GYTKMD.mjs → chunk-EK5RTZVJ.mjs} +225 -149
- package/dist/chunk-EK5RTZVJ.mjs.map +1 -0
- package/dist/{chunk-SMDVD4VG.mjs → chunk-KCYFFRJY.mjs} +2 -2
- package/dist/{chunk-4JBKY7XT.mjs → chunk-QLLV2QVK.mjs} +48 -28
- package/dist/chunk-QLLV2QVK.mjs.map +1 -0
- package/dist/{chunk-5YGKE5SN.mjs → chunk-R5D7D7YN.mjs} +2 -2
- package/dist/{chunk-UUXRYAB4.mjs → chunk-RCCT2GOF.mjs} +2 -2
- package/dist/{chunk-ALZ5H3VD.mjs → chunk-YGS5B7PN.mjs} +2 -2
- package/dist/{groq-adapter-172a2ca4.d.ts → groq-adapter-742818f2.d.ts} +5 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +267 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/{langserve-fc5cac89.d.ts → langserve-3e8d0e06.d.ts} +6 -0
- package/dist/lib/index.d.ts +155 -5
- package/dist/lib/index.js +221 -168
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -9
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +11 -11
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +8 -8
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +11 -11
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +11 -11
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +11 -11
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +5 -4
- package/dist/service-adapters/index.js +47 -27
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/dist/{shared-bd953ebf.d.ts → shared-96b46379.d.ts} +16 -18
- package/package.json +11 -11
- package/src/graphql/resolvers/copilot.resolver.ts +1 -2
- package/src/lib/runtime/__tests__/{copilot-runtime-trace.test.ts → copilot-runtime-error.test.ts} +27 -27
- package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +464 -0
- package/src/lib/runtime/agui-action.ts +9 -3
- package/src/lib/runtime/copilot-runtime.ts +112 -124
- package/src/lib/runtime/mcp-tools-utils.ts +84 -18
- package/src/lib/runtime/remote-actions.ts +6 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +64 -4
- package/src/service-adapters/anthropic/utils.ts +3 -8
- package/src/service-adapters/events.ts +40 -1
- package/src/service-adapters/google/google-genai-adapter.ts +5 -0
- package/src/service-adapters/openai/openai-adapter.ts +0 -14
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +172 -387
- package/dist/chunk-4JBKY7XT.mjs.map +0 -1
- package/dist/chunk-Z5GYTKMD.mjs.map +0 -1
- /package/dist/{chunk-SMDVD4VG.mjs.map → chunk-KCYFFRJY.mjs.map} +0 -0
- /package/dist/{chunk-5YGKE5SN.mjs.map → chunk-R5D7D7YN.mjs.map} +0 -0
- /package/dist/{chunk-UUXRYAB4.mjs.map → chunk-RCCT2GOF.mjs.map} +0 -0
- /package/dist/{chunk-ALZ5H3VD.mjs.map → chunk-YGS5B7PN.mjs.map} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-EK5RTZVJ.mjs";
|
|
4
4
|
import "../../../chunk-SHBDMA63.mjs";
|
|
5
|
-
import "../../../chunk-
|
|
5
|
+
import "../../../chunk-2OZAGFV3.mjs";
|
|
6
|
+
import "../../../chunk-QLLV2QVK.mjs";
|
|
6
7
|
import "../../../chunk-XWBDEXDA.mjs";
|
|
7
8
|
import "../../../chunk-AMUJQ6IR.mjs";
|
|
8
|
-
import "../../../chunk-2OZAGFV3.mjs";
|
|
9
9
|
import "../../../chunk-FHD4JECV.mjs";
|
|
10
10
|
export {
|
|
11
11
|
copilotRuntimeNodeHttpEndpoint
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-
|
|
2
|
-
export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-
|
|
1
|
+
import { b as CopilotServiceAdapter, C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse } from '../langserve-3e8d0e06.js';
|
|
2
|
+
export { c as RemoteChain, R as RemoteChainParameters } from '../langserve-3e8d0e06.js';
|
|
3
3
|
export { convertServiceAdapterError } from './shared/index.js';
|
|
4
|
-
import { L as LangChainAdapter } from '../groq-adapter-
|
|
5
|
-
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-
|
|
4
|
+
import { L as LangChainAdapter } from '../groq-adapter-742818f2.js';
|
|
5
|
+
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-742818f2.js';
|
|
6
6
|
import Anthropic from '@anthropic-ai/sdk';
|
|
7
7
|
import '../index-d4614f9b.js';
|
|
8
8
|
import '../graphql/types/base/index.js';
|
|
@@ -49,6 +49,7 @@ declare class AnthropicAdapter implements CopilotServiceAdapter {
|
|
|
49
49
|
private _anthropic;
|
|
50
50
|
get anthropic(): Anthropic;
|
|
51
51
|
constructor(params?: AnthropicAdapterParams);
|
|
52
|
+
private shouldGenerateFallbackResponse;
|
|
52
53
|
process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -374,7 +374,6 @@ var OpenAIAdapter = class {
|
|
|
374
374
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
375
375
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
376
376
|
const threadId = threadIdFromRequest ?? (0, import_shared3.randomUUID)();
|
|
377
|
-
console.log("messages", messages);
|
|
378
377
|
const validToolUseIds = /* @__PURE__ */ new Set();
|
|
379
378
|
for (const message of messages) {
|
|
380
379
|
if (message.isActionExecutionMessage()) {
|
|
@@ -404,29 +403,6 @@ var OpenAIAdapter = class {
|
|
|
404
403
|
}
|
|
405
404
|
};
|
|
406
405
|
}
|
|
407
|
-
console.log("INPUT", {
|
|
408
|
-
model,
|
|
409
|
-
stream: true,
|
|
410
|
-
messages: openaiMessages,
|
|
411
|
-
...tools.length > 0 && {
|
|
412
|
-
tools
|
|
413
|
-
},
|
|
414
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
|
|
415
|
-
max_tokens: forwardedParameters.maxTokens
|
|
416
|
-
},
|
|
417
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
|
|
418
|
-
stop: forwardedParameters.stop
|
|
419
|
-
},
|
|
420
|
-
...toolChoice && {
|
|
421
|
-
tool_choice: toolChoice
|
|
422
|
-
},
|
|
423
|
-
...this.disableParallelToolCalls && {
|
|
424
|
-
parallel_tool_calls: false
|
|
425
|
-
},
|
|
426
|
-
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
427
|
-
temperature: forwardedParameters.temperature
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
406
|
try {
|
|
431
407
|
const stream = this.openai.beta.chat.completions.stream({
|
|
432
408
|
model,
|
|
@@ -808,6 +784,7 @@ var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
|
|
|
808
784
|
return message.content && String(message.content).trim().length > 0 || message.tool_calls && message.tool_calls.length > 0;
|
|
809
785
|
});
|
|
810
786
|
const model = new import_google_gauth.ChatGoogle({
|
|
787
|
+
apiKey: (options == null ? void 0 : options.apiKey) ?? process.env.GOOGLE_API_KEY,
|
|
811
788
|
modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
|
|
812
789
|
apiVersion: "v1beta"
|
|
813
790
|
}).bindTools(tools);
|
|
@@ -1412,7 +1389,7 @@ function convertMessageToAnthropicMessage(message) {
|
|
|
1412
1389
|
content: [
|
|
1413
1390
|
{
|
|
1414
1391
|
type: "tool_result",
|
|
1415
|
-
content: message.result,
|
|
1392
|
+
content: message.result || "Action completed successfully",
|
|
1416
1393
|
tool_use_id: message.actionExecutionId
|
|
1417
1394
|
}
|
|
1418
1395
|
]
|
|
@@ -1436,6 +1413,22 @@ var AnthropicAdapter = class {
|
|
|
1436
1413
|
this.model = params.model;
|
|
1437
1414
|
}
|
|
1438
1415
|
}
|
|
1416
|
+
shouldGenerateFallbackResponse(messages) {
|
|
1417
|
+
var _a, _b, _c;
|
|
1418
|
+
if (messages.length === 0)
|
|
1419
|
+
return false;
|
|
1420
|
+
const lastMessage = messages[messages.length - 1];
|
|
1421
|
+
const endsWithToolResult = lastMessage.role === "user" && Array.isArray(lastMessage.content) && lastMessage.content.some((content) => content.type === "tool_result");
|
|
1422
|
+
if (messages.length >= 3 && endsWithToolResult) {
|
|
1423
|
+
const lastThree = messages.slice(-3);
|
|
1424
|
+
const hasRecentToolPattern = ((_a = lastThree[0]) == null ? void 0 : _a.role) === "user" && // Initial user message
|
|
1425
|
+
((_b = lastThree[1]) == null ? void 0 : _b.role) === "assistant" && // Assistant tool use
|
|
1426
|
+
Array.isArray(lastThree[1].content) && lastThree[1].content.some((content) => content.type === "tool_use") && ((_c = lastThree[2]) == null ? void 0 : _c.role) === "user" && // Tool result
|
|
1427
|
+
Array.isArray(lastThree[2].content) && lastThree[2].content.some((content) => content.type === "tool_result");
|
|
1428
|
+
return hasRecentToolPattern;
|
|
1429
|
+
}
|
|
1430
|
+
return endsWithToolResult;
|
|
1431
|
+
}
|
|
1439
1432
|
async process(request) {
|
|
1440
1433
|
const { threadId, model = this.model, messages: rawMessages, actions, eventSource, forwardedParameters } = request;
|
|
1441
1434
|
const tools = actions.map(convertActionInputToAnthropicTool);
|
|
@@ -1450,18 +1443,22 @@ var AnthropicAdapter = class {
|
|
|
1450
1443
|
validToolUseIds.add(message.id);
|
|
1451
1444
|
}
|
|
1452
1445
|
}
|
|
1446
|
+
const processedToolResultIds = /* @__PURE__ */ new Set();
|
|
1453
1447
|
const anthropicMessages = messages.map((message) => {
|
|
1454
1448
|
if (message.isResultMessage()) {
|
|
1455
1449
|
if (!validToolUseIds.has(message.actionExecutionId)) {
|
|
1456
1450
|
return null;
|
|
1457
1451
|
}
|
|
1458
|
-
|
|
1452
|
+
if (processedToolResultIds.has(message.actionExecutionId)) {
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
processedToolResultIds.add(message.actionExecutionId);
|
|
1459
1456
|
return {
|
|
1460
1457
|
role: "user",
|
|
1461
1458
|
content: [
|
|
1462
1459
|
{
|
|
1463
1460
|
type: "tool_result",
|
|
1464
|
-
content: message.result,
|
|
1461
|
+
content: message.result || "Action completed successfully",
|
|
1465
1462
|
tool_use_id: message.actionExecutionId
|
|
1466
1463
|
}
|
|
1467
1464
|
]
|
|
@@ -1507,11 +1504,13 @@ var AnthropicAdapter = class {
|
|
|
1507
1504
|
let currentMessageId = (0, import_shared10.randomId)();
|
|
1508
1505
|
let currentToolCallId = (0, import_shared10.randomId)();
|
|
1509
1506
|
let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
|
|
1507
|
+
let hasReceivedContent = false;
|
|
1510
1508
|
try {
|
|
1511
1509
|
for await (const chunk of stream) {
|
|
1512
1510
|
if (chunk.type === "message_start") {
|
|
1513
1511
|
currentMessageId = chunk.message.id;
|
|
1514
1512
|
} else if (chunk.type === "content_block_start") {
|
|
1513
|
+
hasReceivedContent = true;
|
|
1515
1514
|
if (chunk.content_block.type === "text") {
|
|
1516
1515
|
didOutputText = false;
|
|
1517
1516
|
filterThinkingTextBuffer.reset();
|
|
@@ -1563,6 +1562,27 @@ var AnthropicAdapter = class {
|
|
|
1563
1562
|
} catch (error) {
|
|
1564
1563
|
throw convertServiceAdapterError(error, "Anthropic");
|
|
1565
1564
|
}
|
|
1565
|
+
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(limitedMessages)) {
|
|
1566
|
+
let fallbackContent = "Task completed successfully.";
|
|
1567
|
+
const lastMessage = limitedMessages[limitedMessages.length - 1];
|
|
1568
|
+
if ((lastMessage == null ? void 0 : lastMessage.role) === "user" && Array.isArray(lastMessage.content)) {
|
|
1569
|
+
const toolResult = lastMessage.content.find((c) => c.type === "tool_result");
|
|
1570
|
+
if ((toolResult == null ? void 0 : toolResult.content) && toolResult.content !== "Action completed successfully") {
|
|
1571
|
+
fallbackContent = toolResult.content;
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
currentMessageId = (0, import_shared10.randomId)();
|
|
1575
|
+
eventStream$.sendTextMessageStart({
|
|
1576
|
+
messageId: currentMessageId
|
|
1577
|
+
});
|
|
1578
|
+
eventStream$.sendTextMessageContent({
|
|
1579
|
+
messageId: currentMessageId,
|
|
1580
|
+
content: fallbackContent
|
|
1581
|
+
});
|
|
1582
|
+
eventStream$.sendTextMessageEnd({
|
|
1583
|
+
messageId: currentMessageId
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1566
1586
|
eventStream$.complete();
|
|
1567
1587
|
});
|
|
1568
1588
|
} catch (error) {
|