@copilotkit/runtime 1.10.0-next.0 → 1.10.0-next.10
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 +70 -0
- package/dist/{chunk-Z5WUVWW7.mjs → chunk-7QWSTCMV.mjs} +2 -2
- package/dist/{chunk-HB5Z72TJ.mjs → chunk-AQTTXIMS.mjs} +2 -2
- package/dist/{chunk-QLLV2QVK.mjs → chunk-F7IANE7Z.mjs} +66 -6
- package/dist/chunk-F7IANE7Z.mjs.map +1 -0
- package/dist/{chunk-I5VNKUWI.mjs → chunk-N2JYIOSQ.mjs} +2 -2
- package/dist/{chunk-X76SZ4PE.mjs → chunk-RGWWA76W.mjs} +13 -9
- package/dist/chunk-RGWWA76W.mjs.map +1 -0
- package/dist/{chunk-IMZSBLG7.mjs → chunk-WENKPOOD.mjs} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/lib/index.js +12 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.js +2 -4
- 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 -4
- 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 -4
- 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 -4
- 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.d.ts +32 -2
- package/dist/service-adapters/index.js +65 -5
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +3 -5
- package/src/lib/runtime/agui-action.ts +8 -0
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +106 -5
- package/src/service-adapters/anthropic/utils.ts +1 -1
- package/src/service-adapters/openai/openai-adapter.ts +3 -1
- package/dist/chunk-QLLV2QVK.mjs.map +0 -1
- package/dist/chunk-X76SZ4PE.mjs.map +0 -1
- /package/dist/{chunk-Z5WUVWW7.mjs.map → chunk-7QWSTCMV.mjs.map} +0 -0
- /package/dist/{chunk-HB5Z72TJ.mjs.map → chunk-AQTTXIMS.mjs.map} +0 -0
- /package/dist/{chunk-I5VNKUWI.mjs.map → chunk-N2JYIOSQ.mjs.map} +0 -0
- /package/dist/{chunk-IMZSBLG7.mjs.map → chunk-WENKPOOD.mjs.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-RGWWA76W.mjs";
|
|
4
4
|
import "../../../chunk-SHBDMA63.mjs";
|
|
5
|
-
import "../../../chunk-
|
|
5
|
+
import "../../../chunk-F7IANE7Z.mjs";
|
|
6
6
|
import "../../../chunk-XWBDEXDA.mjs";
|
|
7
7
|
import "../../../chunk-AMUJQ6IR.mjs";
|
|
8
8
|
import "../../../chunk-2OZAGFV3.mjs";
|
|
@@ -29,10 +29,26 @@ import 'groq-sdk';
|
|
|
29
29
|
* apiKey: "<your-api-key>",
|
|
30
30
|
* });
|
|
31
31
|
*
|
|
32
|
-
* return new AnthropicAdapter({
|
|
32
|
+
* return new AnthropicAdapter({
|
|
33
|
+
* anthropic,
|
|
34
|
+
* promptCaching: {
|
|
35
|
+
* enabled: true,
|
|
36
|
+
* debug: true
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
33
39
|
* ```
|
|
34
40
|
*/
|
|
35
41
|
|
|
42
|
+
interface AnthropicPromptCachingConfig {
|
|
43
|
+
/**
|
|
44
|
+
* Whether to enable prompt caching.
|
|
45
|
+
*/
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to enable debug logging for cache operations.
|
|
49
|
+
*/
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
}
|
|
36
52
|
interface AnthropicAdapterParams {
|
|
37
53
|
/**
|
|
38
54
|
* An optional Anthropic instance to use. If not provided, a new instance will be
|
|
@@ -43,12 +59,26 @@ interface AnthropicAdapterParams {
|
|
|
43
59
|
* The model to use.
|
|
44
60
|
*/
|
|
45
61
|
model?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for prompt caching.
|
|
64
|
+
* See: https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
|
65
|
+
*/
|
|
66
|
+
promptCaching?: AnthropicPromptCachingConfig;
|
|
46
67
|
}
|
|
47
68
|
declare class AnthropicAdapter implements CopilotServiceAdapter {
|
|
48
69
|
private model;
|
|
70
|
+
private promptCaching;
|
|
49
71
|
private _anthropic;
|
|
50
72
|
get anthropic(): Anthropic;
|
|
51
73
|
constructor(params?: AnthropicAdapterParams);
|
|
74
|
+
/**
|
|
75
|
+
* Adds cache control to system prompt
|
|
76
|
+
*/
|
|
77
|
+
private addSystemPromptCaching;
|
|
78
|
+
/**
|
|
79
|
+
* Adds cache control to the final message
|
|
80
|
+
*/
|
|
81
|
+
private addIncrementalMessageCaching;
|
|
52
82
|
private shouldGenerateFallbackResponse;
|
|
53
83
|
process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
|
|
54
84
|
}
|
|
@@ -129,4 +159,4 @@ declare class EmptyAdapter implements CopilotServiceAdapter {
|
|
|
129
159
|
}
|
|
130
160
|
declare const ExperimentalEmptyAdapter: typeof EmptyAdapter;
|
|
131
161
|
|
|
132
|
-
export { AnthropicAdapter, AnthropicAdapterParams, BedrockAdapter, BedrockAdapterParams, CopilotRuntimeChatCompletionRequest, CopilotRuntimeChatCompletionResponse, CopilotServiceAdapter, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, LangChainAdapter };
|
|
162
|
+
export { AnthropicAdapter, AnthropicAdapterParams, AnthropicPromptCachingConfig, BedrockAdapter, BedrockAdapterParams, CopilotRuntimeChatCompletionRequest, CopilotRuntimeChatCompletionResponse, CopilotServiceAdapter, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, LangChainAdapter };
|
|
@@ -412,7 +412,7 @@ var OpenAIAdapter = class {
|
|
|
412
412
|
tools
|
|
413
413
|
},
|
|
414
414
|
...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
|
|
415
|
-
|
|
415
|
+
max_completion_tokens: forwardedParameters.maxTokens
|
|
416
416
|
},
|
|
417
417
|
...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
|
|
418
418
|
stop: forwardedParameters.stop
|
|
@@ -1403,6 +1403,7 @@ var import_shared10 = require("@copilotkit/shared");
|
|
|
1403
1403
|
var DEFAULT_MODEL3 = "claude-3-5-sonnet-latest";
|
|
1404
1404
|
var AnthropicAdapter = class {
|
|
1405
1405
|
model = DEFAULT_MODEL3;
|
|
1406
|
+
promptCaching;
|
|
1406
1407
|
_anthropic;
|
|
1407
1408
|
get anthropic() {
|
|
1408
1409
|
return this._anthropic;
|
|
@@ -1412,6 +1413,63 @@ var AnthropicAdapter = class {
|
|
|
1412
1413
|
if (params == null ? void 0 : params.model) {
|
|
1413
1414
|
this.model = params.model;
|
|
1414
1415
|
}
|
|
1416
|
+
this.promptCaching = (params == null ? void 0 : params.promptCaching) || {
|
|
1417
|
+
enabled: false
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Adds cache control to system prompt
|
|
1422
|
+
*/
|
|
1423
|
+
addSystemPromptCaching(system, debug = false) {
|
|
1424
|
+
if (!this.promptCaching.enabled || !system) {
|
|
1425
|
+
return system;
|
|
1426
|
+
}
|
|
1427
|
+
const originalTextLength = system.length;
|
|
1428
|
+
if (debug) {
|
|
1429
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to system prompt (${originalTextLength} chars).`);
|
|
1430
|
+
}
|
|
1431
|
+
return [
|
|
1432
|
+
{
|
|
1433
|
+
type: "text",
|
|
1434
|
+
text: system,
|
|
1435
|
+
cache_control: {
|
|
1436
|
+
type: "ephemeral"
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
];
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Adds cache control to the final message
|
|
1443
|
+
*/
|
|
1444
|
+
addIncrementalMessageCaching(messages, debug = false) {
|
|
1445
|
+
if (!this.promptCaching.enabled || messages.length === 0) {
|
|
1446
|
+
return messages;
|
|
1447
|
+
}
|
|
1448
|
+
const finalMessage = messages[messages.length - 1];
|
|
1449
|
+
const messageNumber = messages.length;
|
|
1450
|
+
if (Array.isArray(finalMessage.content) && finalMessage.content.length > 0) {
|
|
1451
|
+
const finalBlock = finalMessage.content[finalMessage.content.length - 1];
|
|
1452
|
+
const updatedMessages = [
|
|
1453
|
+
...messages.slice(0, -1),
|
|
1454
|
+
{
|
|
1455
|
+
...finalMessage,
|
|
1456
|
+
content: [
|
|
1457
|
+
...finalMessage.content.slice(0, -1),
|
|
1458
|
+
{
|
|
1459
|
+
...finalBlock,
|
|
1460
|
+
cache_control: {
|
|
1461
|
+
type: "ephemeral"
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
]
|
|
1465
|
+
}
|
|
1466
|
+
];
|
|
1467
|
+
if (debug) {
|
|
1468
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to final message (message ${messageNumber}).`);
|
|
1469
|
+
}
|
|
1470
|
+
return updatedMessages;
|
|
1471
|
+
}
|
|
1472
|
+
return messages;
|
|
1415
1473
|
}
|
|
1416
1474
|
shouldGenerateFallbackResponse(messages) {
|
|
1417
1475
|
var _a, _b, _c;
|
|
@@ -1473,6 +1531,8 @@ var AnthropicAdapter = class {
|
|
|
1473
1531
|
return true;
|
|
1474
1532
|
});
|
|
1475
1533
|
const limitedMessages = limitMessagesToTokenCount2(anthropicMessages, tools, model);
|
|
1534
|
+
const cachedSystemPrompt = this.addSystemPromptCaching(instructions, this.promptCaching.debug);
|
|
1535
|
+
const cachedMessages = this.addIncrementalMessageCaching(limitedMessages, this.promptCaching.debug);
|
|
1476
1536
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
1477
1537
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
1478
1538
|
toolChoice = {
|
|
@@ -1482,9 +1542,9 @@ var AnthropicAdapter = class {
|
|
|
1482
1542
|
}
|
|
1483
1543
|
try {
|
|
1484
1544
|
const createParams = {
|
|
1485
|
-
system:
|
|
1545
|
+
system: cachedSystemPrompt,
|
|
1486
1546
|
model: this.model,
|
|
1487
|
-
messages:
|
|
1547
|
+
messages: cachedMessages,
|
|
1488
1548
|
max_tokens: (forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) || 1024,
|
|
1489
1549
|
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) ? {
|
|
1490
1550
|
temperature: forwardedParameters.temperature
|
|
@@ -1562,9 +1622,9 @@ var AnthropicAdapter = class {
|
|
|
1562
1622
|
} catch (error) {
|
|
1563
1623
|
throw convertServiceAdapterError(error, "Anthropic");
|
|
1564
1624
|
}
|
|
1565
|
-
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(
|
|
1625
|
+
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(cachedMessages)) {
|
|
1566
1626
|
let fallbackContent = "Task completed successfully.";
|
|
1567
|
-
const lastMessage =
|
|
1627
|
+
const lastMessage = cachedMessages[cachedMessages.length - 1];
|
|
1568
1628
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "user" && Array.isArray(lastMessage.content)) {
|
|
1569
1629
|
const toolResult = lastMessage.content.find((c) => c.type === "tool_result");
|
|
1570
1630
|
if ((toolResult == null ? void 0 : toolResult.content) && toolResult.content !== "Action completed successfully") {
|