@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/{chunk-Z5WUVWW7.mjs → chunk-7QWSTCMV.mjs} +2 -2
  3. package/dist/{chunk-HB5Z72TJ.mjs → chunk-AQTTXIMS.mjs} +2 -2
  4. package/dist/{chunk-QLLV2QVK.mjs → chunk-F7IANE7Z.mjs} +66 -6
  5. package/dist/chunk-F7IANE7Z.mjs.map +1 -0
  6. package/dist/{chunk-I5VNKUWI.mjs → chunk-N2JYIOSQ.mjs} +2 -2
  7. package/dist/{chunk-X76SZ4PE.mjs → chunk-RGWWA76W.mjs} +13 -9
  8. package/dist/chunk-RGWWA76W.mjs.map +1 -0
  9. package/dist/{chunk-IMZSBLG7.mjs → chunk-WENKPOOD.mjs} +2 -2
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +76 -12
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +6 -6
  14. package/dist/lib/index.js +12 -8
  15. package/dist/lib/index.js.map +1 -1
  16. package/dist/lib/index.mjs +6 -6
  17. package/dist/lib/integrations/index.js +2 -4
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +5 -5
  20. package/dist/lib/integrations/nest/index.js +2 -4
  21. package/dist/lib/integrations/nest/index.js.map +1 -1
  22. package/dist/lib/integrations/nest/index.mjs +3 -3
  23. package/dist/lib/integrations/node-express/index.js +2 -4
  24. package/dist/lib/integrations/node-express/index.js.map +1 -1
  25. package/dist/lib/integrations/node-express/index.mjs +3 -3
  26. package/dist/lib/integrations/node-http/index.js +2 -4
  27. package/dist/lib/integrations/node-http/index.js.map +1 -1
  28. package/dist/lib/integrations/node-http/index.mjs +2 -2
  29. package/dist/service-adapters/index.d.ts +32 -2
  30. package/dist/service-adapters/index.js +65 -5
  31. package/dist/service-adapters/index.js.map +1 -1
  32. package/dist/service-adapters/index.mjs +1 -1
  33. package/package.json +3 -5
  34. package/src/lib/runtime/agui-action.ts +8 -0
  35. package/src/lib/runtime/remote-actions.ts +1 -0
  36. package/src/service-adapters/anthropic/anthropic-adapter.ts +106 -5
  37. package/src/service-adapters/anthropic/utils.ts +1 -1
  38. package/src/service-adapters/openai/openai-adapter.ts +3 -1
  39. package/dist/chunk-QLLV2QVK.mjs.map +0 -1
  40. package/dist/chunk-X76SZ4PE.mjs.map +0 -1
  41. /package/dist/{chunk-Z5WUVWW7.mjs.map → chunk-7QWSTCMV.mjs.map} +0 -0
  42. /package/dist/{chunk-HB5Z72TJ.mjs.map → chunk-AQTTXIMS.mjs.map} +0 -0
  43. /package/dist/{chunk-I5VNKUWI.mjs.map → chunk-N2JYIOSQ.mjs.map} +0 -0
  44. /package/dist/{chunk-IMZSBLG7.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-X76SZ4PE.mjs";
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-IMZSBLG7.mjs.map
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.0",
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.27.3",
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
- max_tokens: forwardedParameters.maxTokens
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: instructions,
3317
+ system: cachedSystemPrompt,
3260
3318
  model: this.model,
3261
- messages: limitedMessages,
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(limitedMessages)) {
3397
+ if (!hasReceivedContent && this.shouldGenerateFallbackResponse(cachedMessages)) {
3340
3398
  let fallbackContent = "Task completed successfully.";
3341
- const lastMessage = limitedMessages[limitedMessages.length - 1];
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") {
@@ -6344,7 +6402,7 @@ var import_shared26 = require("@copilotkit/shared");
6344
6402
 
6345
6403
  // src/lib/runtime/agui-action.ts
6346
6404
  var import_shared24 = require("@copilotkit/shared");
6347
- function constructAGUIRemoteAction({ logger: logger2, messages, agentStates, agent, metaEvents, threadMetadata, nodeName }) {
6405
+ function constructAGUIRemoteAction({ logger: logger2, messages, agentStates, agent, metaEvents, threadMetadata, nodeName, graphqlContext }) {
6348
6406
  const action = {
6349
6407
  name: agent.agentId,
6350
6408
  description: agent.description,
@@ -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
@@ -6390,7 +6451,9 @@ function constructAGUIRemoteAction({ logger: logger2, messages, agentStates, age
6390
6451
  } : {},
6391
6452
  ...nodeName ? {
6392
6453
  nodeName
6393
- } : {}
6454
+ } : {},
6455
+ // Forward properties from the graphql context to the agent, e.g Authorization token
6456
+ ...graphqlContext.properties
6394
6457
  };
6395
6458
  return agent.legacy_to_be_removed_runAgentBridged({
6396
6459
  tools,
@@ -6572,7 +6635,8 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
6572
6635
  agent,
6573
6636
  metaEvents,
6574
6637
  threadMetadata,
6575
- nodeName
6638
+ nodeName,
6639
+ graphqlContext
6576
6640
  }));
6577
6641
  }
6578
6642
  return result.flat();