@copilotkit/runtime 1.10.0-next.1 → 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 +60 -0
- package/dist/{chunk-VOCP3OKE.mjs → chunk-7QWSTCMV.mjs} +2 -2
- package/dist/{chunk-NV4PTNDU.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-5OSQ6CM5.mjs → chunk-N2JYIOSQ.mjs} +2 -2
- package/dist/{chunk-YBAPVMN4.mjs → chunk-RGWWA76W.mjs} +7 -6
- package/dist/chunk-RGWWA76W.mjs.map +1 -0
- package/dist/{chunk-7WC4OMOL.mjs → chunk-WENKPOOD.mjs} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +70 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/lib/index.js +6 -5
- 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 +5 -7
- package/src/lib/runtime/agui-action.ts +3 -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-YBAPVMN4.mjs.map +0 -1
- /package/dist/{chunk-VOCP3OKE.mjs.map → chunk-7QWSTCMV.mjs.map} +0 -0
- /package/dist/{chunk-NV4PTNDU.mjs.map → chunk-AQTTXIMS.mjs.map} +0 -0
- /package/dist/{chunk-5OSQ6CM5.mjs.map → chunk-N2JYIOSQ.mjs.map} +0 -0
- /package/dist/{chunk-7WC4OMOL.mjs.map → chunk-WENKPOOD.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getCommonConfig,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RGWWA76W.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
config,
|
|
78
78
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-WENKPOOD.mjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { CustomEventNames, LangGraphAgent, PredictStateTool, State, TextMessageE
|
|
|
8
8
|
export { GuardrailsValidationFailureResponse, MessageStreamInterruptedResponse, UnknownErrorResponse } from './utils/index.js';
|
|
9
9
|
export { C as CopilotRuntimeChatCompletionRequest, a as CopilotRuntimeChatCompletionResponse, b as CopilotServiceAdapter, c as RemoteChain, R as RemoteChainParameters } from './langserve-3e8d0e06.js';
|
|
10
10
|
export { convertServiceAdapterError } from './service-adapters/shared/index.js';
|
|
11
|
-
export { AnthropicAdapter, AnthropicAdapterParams, BedrockAdapter, BedrockAdapterParams, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter } from './service-adapters/index.js';
|
|
11
|
+
export { AnthropicAdapter, AnthropicAdapterParams, AnthropicPromptCachingConfig, BedrockAdapter, BedrockAdapterParams, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter } from './service-adapters/index.js';
|
|
12
12
|
export { LangGraphHttpAgent } from '@ag-ui/langgraph';
|
|
13
13
|
import 'openai';
|
|
14
14
|
import '@langchain/core/messages';
|
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.10.0-next.
|
|
47
|
+
version: "1.10.0-next.10",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -87,7 +87,7 @@ var require_package = __commonJS({
|
|
|
87
87
|
"@ag-ui/encoder": "0.0.35",
|
|
88
88
|
"@ag-ui/langgraph": "0.0.7",
|
|
89
89
|
"@ag-ui/proto": "0.0.35",
|
|
90
|
-
"@anthropic-ai/sdk": "^0.
|
|
90
|
+
"@anthropic-ai/sdk": "^0.57.0",
|
|
91
91
|
"@copilotkit/shared": "workspace:*",
|
|
92
92
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
93
93
|
"@langchain/aws": "^0.1.9",
|
|
@@ -97,7 +97,6 @@ var require_package = __commonJS({
|
|
|
97
97
|
"@langchain/langgraph-sdk": "^0.0.70",
|
|
98
98
|
"@langchain/openai": "^0.4.2",
|
|
99
99
|
"@scarf/scarf": "^1.3.0",
|
|
100
|
-
"@types/ip": "^1.1.3",
|
|
101
100
|
"class-transformer": "^0.5.1",
|
|
102
101
|
"class-validator": "^0.14.1",
|
|
103
102
|
express: "^4.19.2",
|
|
@@ -105,7 +104,6 @@ var require_package = __commonJS({
|
|
|
105
104
|
"graphql-scalars": "^1.23.0",
|
|
106
105
|
"graphql-yoga": "^5.3.1",
|
|
107
106
|
"groq-sdk": "^0.5.0",
|
|
108
|
-
ip: "^2.0.1",
|
|
109
107
|
langchain: "^0.3.3",
|
|
110
108
|
openai: "^4.85.1",
|
|
111
109
|
"partial-json": "^0.1.7",
|
|
@@ -473,7 +471,7 @@ var OpenAIAdapter = class {
|
|
|
473
471
|
tools
|
|
474
472
|
},
|
|
475
473
|
...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
|
|
476
|
-
|
|
474
|
+
max_completion_tokens: forwardedParameters.maxTokens
|
|
477
475
|
},
|
|
478
476
|
...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
|
|
479
477
|
stop: forwardedParameters.stop
|
|
@@ -3177,6 +3175,7 @@ var import_shared10 = require("@copilotkit/shared");
|
|
|
3177
3175
|
var DEFAULT_MODEL3 = "claude-3-5-sonnet-latest";
|
|
3178
3176
|
var AnthropicAdapter = class {
|
|
3179
3177
|
model = DEFAULT_MODEL3;
|
|
3178
|
+
promptCaching;
|
|
3180
3179
|
_anthropic;
|
|
3181
3180
|
get anthropic() {
|
|
3182
3181
|
return this._anthropic;
|
|
@@ -3186,6 +3185,63 @@ var AnthropicAdapter = class {
|
|
|
3186
3185
|
if (params == null ? void 0 : params.model) {
|
|
3187
3186
|
this.model = params.model;
|
|
3188
3187
|
}
|
|
3188
|
+
this.promptCaching = (params == null ? void 0 : params.promptCaching) || {
|
|
3189
|
+
enabled: false
|
|
3190
|
+
};
|
|
3191
|
+
}
|
|
3192
|
+
/**
|
|
3193
|
+
* Adds cache control to system prompt
|
|
3194
|
+
*/
|
|
3195
|
+
addSystemPromptCaching(system, debug = false) {
|
|
3196
|
+
if (!this.promptCaching.enabled || !system) {
|
|
3197
|
+
return system;
|
|
3198
|
+
}
|
|
3199
|
+
const originalTextLength = system.length;
|
|
3200
|
+
if (debug) {
|
|
3201
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to system prompt (${originalTextLength} chars).`);
|
|
3202
|
+
}
|
|
3203
|
+
return [
|
|
3204
|
+
{
|
|
3205
|
+
type: "text",
|
|
3206
|
+
text: system,
|
|
3207
|
+
cache_control: {
|
|
3208
|
+
type: "ephemeral"
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
];
|
|
3212
|
+
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Adds cache control to the final message
|
|
3215
|
+
*/
|
|
3216
|
+
addIncrementalMessageCaching(messages, debug = false) {
|
|
3217
|
+
if (!this.promptCaching.enabled || messages.length === 0) {
|
|
3218
|
+
return messages;
|
|
3219
|
+
}
|
|
3220
|
+
const finalMessage = messages[messages.length - 1];
|
|
3221
|
+
const messageNumber = messages.length;
|
|
3222
|
+
if (Array.isArray(finalMessage.content) && finalMessage.content.length > 0) {
|
|
3223
|
+
const finalBlock = finalMessage.content[finalMessage.content.length - 1];
|
|
3224
|
+
const updatedMessages = [
|
|
3225
|
+
...messages.slice(0, -1),
|
|
3226
|
+
{
|
|
3227
|
+
...finalMessage,
|
|
3228
|
+
content: [
|
|
3229
|
+
...finalMessage.content.slice(0, -1),
|
|
3230
|
+
{
|
|
3231
|
+
...finalBlock,
|
|
3232
|
+
cache_control: {
|
|
3233
|
+
type: "ephemeral"
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
]
|
|
3237
|
+
}
|
|
3238
|
+
];
|
|
3239
|
+
if (debug) {
|
|
3240
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to final message (message ${messageNumber}).`);
|
|
3241
|
+
}
|
|
3242
|
+
return updatedMessages;
|
|
3243
|
+
}
|
|
3244
|
+
return messages;
|
|
3189
3245
|
}
|
|
3190
3246
|
shouldGenerateFallbackResponse(messages) {
|
|
3191
3247
|
var _a, _b, _c;
|
|
@@ -3247,6 +3303,8 @@ var AnthropicAdapter = class {
|
|
|
3247
3303
|
return true;
|
|
3248
3304
|
});
|
|
3249
3305
|
const limitedMessages = limitMessagesToTokenCount2(anthropicMessages, tools, model);
|
|
3306
|
+
const cachedSystemPrompt = this.addSystemPromptCaching(instructions, this.promptCaching.debug);
|
|
3307
|
+
const cachedMessages = this.addIncrementalMessageCaching(limitedMessages, this.promptCaching.debug);
|
|
3250
3308
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
3251
3309
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
3252
3310
|
toolChoice = {
|
|
@@ -3256,9 +3314,9 @@ var AnthropicAdapter = class {
|
|
|
3256
3314
|
}
|
|
3257
3315
|
try {
|
|
3258
3316
|
const createParams = {
|
|
3259
|
-
system:
|
|
3317
|
+
system: cachedSystemPrompt,
|
|
3260
3318
|
model: this.model,
|
|
3261
|
-
messages:
|
|
3319
|
+
messages: cachedMessages,
|
|
3262
3320
|
max_tokens: (forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) || 1024,
|
|
3263
3321
|
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) ? {
|
|
3264
3322
|
temperature: forwardedParameters.temperature
|
|
@@ -3336,9 +3394,9 @@ var AnthropicAdapter = class {
|
|
|
3336
3394
|
} catch (error) {
|
|
3337
3395
|
throw convertServiceAdapterError(error, "Anthropic");
|
|
3338
3396
|
}
|
|
3339
|
-
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(
|
|
3397
|
+
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(cachedMessages)) {
|
|
3340
3398
|
let fallbackContent = "Task completed successfully.";
|
|
3341
|
-
const lastMessage =
|
|
3399
|
+
const lastMessage = cachedMessages[cachedMessages.length - 1];
|
|
3342
3400
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "user" && Array.isArray(lastMessage.content)) {
|
|
3343
3401
|
const toolResult = lastMessage.content.find((c) => c.type === "tool_result");
|
|
3344
3402
|
if ((toolResult == null ? void 0 : toolResult.content) && toolResult.content !== "Action completed successfully") {
|
|
@@ -6365,10 +6423,12 @@ function constructAGUIRemoteAction({ logger: logger2, messages, agentStates, age
|
|
|
6365
6423
|
agentsAmount: 1
|
|
6366
6424
|
});
|
|
6367
6425
|
let state = {};
|
|
6426
|
+
let config2 = {};
|
|
6368
6427
|
if (agentStates) {
|
|
6369
6428
|
const jsonState = agentStates.find((state2) => state2.agentName === agent.agentId);
|
|
6370
6429
|
if (jsonState) {
|
|
6371
6430
|
state = (0, import_shared24.parseJson)(jsonState.state, {});
|
|
6431
|
+
config2 = (0, import_shared24.parseJson)(jsonState.config, {});
|
|
6372
6432
|
}
|
|
6373
6433
|
}
|
|
6374
6434
|
agent.state = state;
|
|
@@ -6380,6 +6440,7 @@ function constructAGUIRemoteAction({ logger: logger2, messages, agentStates, age
|
|
|
6380
6440
|
};
|
|
6381
6441
|
});
|
|
6382
6442
|
const forwardedProps = {
|
|
6443
|
+
config: config2,
|
|
6383
6444
|
...(metaEvents == null ? void 0 : metaEvents.length) ? {
|
|
6384
6445
|
command: {
|
|
6385
6446
|
resume: (_a = metaEvents[0]) == null ? void 0 : _a.response
|