@meetsmore-oss/use-ai-server 1.2.2 → 1.2.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.
Files changed (53) hide show
  1. package/dist/agents/AISDKAgent.d.ts +49 -0
  2. package/dist/agents/AISDKAgent.d.ts.map +1 -1
  3. package/dist/agents/anthropicCache.d.ts +65 -0
  4. package/dist/agents/anthropicCache.d.ts.map +1 -0
  5. package/dist/agents/index.d.ts +1 -0
  6. package/dist/agents/index.d.ts.map +1 -1
  7. package/dist/agents/plugins/__tests__/runner.test.d.ts +2 -0
  8. package/dist/agents/plugins/__tests__/runner.test.d.ts.map +1 -0
  9. package/dist/agents/plugins/citations/citationPlugin.d.ts +72 -0
  10. package/dist/agents/plugins/citations/citationPlugin.d.ts.map +1 -0
  11. package/dist/agents/plugins/citations/citationPlugin.test.d.ts +2 -0
  12. package/dist/agents/plugins/citations/citationPlugin.test.d.ts.map +1 -0
  13. package/dist/agents/plugins/citations/index.d.ts +7 -0
  14. package/dist/agents/plugins/citations/index.d.ts.map +1 -0
  15. package/dist/agents/plugins/index.d.ts +34 -0
  16. package/dist/agents/plugins/index.d.ts.map +1 -0
  17. package/dist/agents/plugins/runner.d.ts +76 -0
  18. package/dist/agents/plugins/runner.d.ts.map +1 -0
  19. package/dist/agents/plugins/types.d.ts +280 -0
  20. package/dist/agents/plugins/types.d.ts.map +1 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +54 -6
  24. package/dist/server.d.ts.map +1 -1
  25. package/dist/src/agents/AISDKAgent.d.ts +49 -0
  26. package/dist/src/agents/AISDKAgent.d.ts.map +1 -1
  27. package/dist/src/agents/anthropicCache.d.ts +65 -0
  28. package/dist/src/agents/anthropicCache.d.ts.map +1 -0
  29. package/dist/src/agents/index.d.ts +1 -0
  30. package/dist/src/agents/index.d.ts.map +1 -1
  31. package/dist/src/agents/plugins/__tests__/runner.test.d.ts +2 -0
  32. package/dist/src/agents/plugins/__tests__/runner.test.d.ts.map +1 -0
  33. package/dist/src/agents/plugins/citations/citationPlugin.d.ts +72 -0
  34. package/dist/src/agents/plugins/citations/citationPlugin.d.ts.map +1 -0
  35. package/dist/src/agents/plugins/citations/citationPlugin.test.d.ts +2 -0
  36. package/dist/src/agents/plugins/citations/citationPlugin.test.d.ts.map +1 -0
  37. package/dist/src/agents/plugins/citations/index.d.ts +7 -0
  38. package/dist/src/agents/plugins/citations/index.d.ts.map +1 -0
  39. package/dist/src/agents/plugins/index.d.ts +34 -0
  40. package/dist/src/agents/plugins/index.d.ts.map +1 -0
  41. package/dist/src/agents/plugins/runner.d.ts +76 -0
  42. package/dist/src/agents/plugins/runner.d.ts.map +1 -0
  43. package/dist/src/agents/plugins/types.d.ts +280 -0
  44. package/dist/src/agents/plugins/types.d.ts.map +1 -0
  45. package/dist/src/index.d.ts +2 -2
  46. package/dist/src/index.d.ts.map +1 -1
  47. package/dist/src/server.d.ts.map +1 -1
  48. package/dist/src/types.d.ts +21 -0
  49. package/dist/src/types.d.ts.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/dist/types.d.ts +21 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/package.json +3 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/agents/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,QAAQ,EAAE,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,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE5C;;;;;;;OAOG;IACH,WAAW,CAAC,CACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,kBAAkB,GAC1B,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE1C;;;;;;;OAOG;IACH,gBAAgB,CAAC,CACf,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,kBAAkB,GAC1B,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAEtD;;;;;;;OAOG;IACH,eAAe,CAAC,CACd,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,CACN,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,kBAAkB,GAC1B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;OAGG;IACH,OAAO,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { UseAIServer } from './server';
2
- export type { UseAIServerConfig, McpEndpointConfig, ToolDefinition } from './types';
2
+ export type { UseAIServerConfig, McpEndpointConfig, ToolDefinition, CorsOptions } from './types';
3
3
  export type { ClientSession } from './server';
4
4
  export type { Agent, AgentInput, EventEmitter, AgentResult } from './agents';
5
- export { AISDKAgent, type AISDKAgentConfig } from './agents';
5
+ export { AISDKAgent, type AISDKAgentConfig, type MessageWithCacheContext, type CacheTtl, type CacheBreakpointResult, type CacheBreakpointFn } from './agents';
6
6
  export type { UseAIServerPlugin, MessageHandler } from './plugins';
7
7
  export { logger } from './logger';
8
8
  export { createClientToolExecutor, isRemoteTool, createGlobFilter, and, or, not, } from './utils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACpF,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG7D,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,GAAG,EACH,EAAE,EACF,GAAG,GACJ,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACjG,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,KAAK,QAAQ,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG9J,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,GAAG,EACH,EAAE,EACF,GAAG,GACJ,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -56420,7 +56420,8 @@ class UseAIServer {
56420
56420
  port: config.port ?? 8081,
56421
56421
  rateLimitMaxRequests: config.rateLimitMaxRequests ?? 0,
56422
56422
  rateLimitWindowMs: config.rateLimitWindowMs ?? 60000,
56423
- maxHttpBufferSize: config.maxHttpBufferSize ?? 20 * 1024 * 1024
56423
+ maxHttpBufferSize: config.maxHttpBufferSize ?? 20 * 1024 * 1024,
56424
+ cors: config.cors
56424
56425
  };
56425
56426
  this.agents = config.agents;
56426
56427
  const defaultAgent = this.agents[config.defaultAgent];
@@ -56455,10 +56456,7 @@ class UseAIServer {
56455
56456
  }
56456
56457
  });
56457
56458
  this.io = new Server(this.httpServer, {
56458
- cors: {
56459
- origin: "*",
56460
- methods: ["GET", "POST"]
56461
- },
56459
+ cors: this.config.cors,
56462
56460
  allowUpgrades: true,
56463
56461
  transports: ["polling", "websocket"],
56464
56462
  maxHttpBufferSize: this.config.maxHttpBufferSize
@@ -80246,6 +80244,53 @@ function initializeLangfuse() {
80246
80244
  }
80247
80245
  }
80248
80246
 
80247
+ // src/agents/anthropicCache.ts
80248
+ function isAnthropicModel(model) {
80249
+ if (typeof model === "string") {
80250
+ return model.startsWith("anthropic/");
80251
+ }
80252
+ const provider = model.provider;
80253
+ return provider?.startsWith("anthropic") ?? false;
80254
+ }
80255
+ function applyCacheBreakpoints(messages, cacheBreakpoint, model) {
80256
+ if (!cacheBreakpoint || !isAnthropicModel(model)) {
80257
+ return messages;
80258
+ }
80259
+ const totalCount = messages.length;
80260
+ let cacheBreakpointCount = 0;
80261
+ const result = messages.map((message, index) => {
80262
+ const context = {
80263
+ ...message,
80264
+ index,
80265
+ totalCount,
80266
+ isFirst: index === 0,
80267
+ isLast: index === totalCount - 1
80268
+ };
80269
+ const breakpointResult = cacheBreakpoint(context);
80270
+ if (breakpointResult) {
80271
+ cacheBreakpointCount++;
80272
+ const cacheControl = typeof breakpointResult === "string" ? { type: "ephemeral", ttl: breakpointResult } : { type: "ephemeral" };
80273
+ return {
80274
+ ...message,
80275
+ providerOptions: {
80276
+ ...message.providerOptions,
80277
+ anthropic: {
80278
+ cacheControl
80279
+ }
80280
+ }
80281
+ };
80282
+ }
80283
+ return message;
80284
+ });
80285
+ if (cacheBreakpointCount > 0) {
80286
+ logger2.debug("Applied cache breakpoints", {
80287
+ totalMessages: totalCount,
80288
+ cacheBreakpointCount
80289
+ });
80290
+ }
80291
+ return result;
80292
+ }
80293
+
80249
80294
  // src/agents/AISDKAgent.ts
80250
80295
  class AISDKAgent {
80251
80296
  model;
@@ -80254,12 +80299,14 @@ class AISDKAgent {
80254
80299
  langfuse;
80255
80300
  toolFilter;
80256
80301
  systemPrompt;
80302
+ cacheBreakpoint;
80257
80303
  constructor(config2) {
80258
80304
  this.model = config2.model;
80259
80305
  this.name = config2.name || "ai-sdk";
80260
80306
  this.annotation = config2.annotation;
80261
80307
  this.toolFilter = config2.toolFilter;
80262
80308
  this.systemPrompt = config2.systemPrompt;
80309
+ this.cacheBreakpoint = config2.cacheBreakpoint;
80263
80310
  this.langfuse = initializeLangfuse();
80264
80311
  }
80265
80312
  getName() {
@@ -80314,9 +80361,10 @@ class AISDKAgent {
80314
80361
  })),
80315
80362
  systemMessages: systemMessages?.map((m) => m.content.substring(0, 80) + (m.content.length > 80 ? "..." : ""))
80316
80363
  });
80364
+ const messagesWithCache = applyCacheBreakpoints(messagesWithSystem, this.cacheBreakpoint, this.model);
80317
80365
  const stream = streamText({
80318
80366
  model: this.model,
80319
- messages: messagesWithSystem,
80367
+ messages: messagesWithCache,
80320
80368
  tools: tools.length > 0 ? this.sanitizeToolsForAPI(this.filterTools(tools), session) : undefined,
80321
80369
  stopWhen: stepCountIs(10),
80322
80370
  maxOutputTokens: 4096,
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.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+CnC;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAwC5B;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAoBtB;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;;OAGG;IACI,KAAK;CASb"}
@@ -1,6 +1,7 @@
1
1
  import { LanguageModel } from 'ai';
2
2
  import type { Agent, AgentInput, EventEmitter, AgentResult } from './types';
3
3
  import type { ToolDefinition } from '../types';
4
+ import { type CacheBreakpointFn } from './anthropicCache';
4
5
  /**
5
6
  * Configuration for AISDKAgent.
6
7
  */
@@ -99,6 +100,53 @@ export interface AISDKAgentConfig {
99
100
  * ```
100
101
  */
101
102
  toolFilter?: (tool: ToolDefinition) => boolean;
103
+ /**
104
+ * Anthropic-specific: Configure cache breakpoints for prompt caching.
105
+ * Only applies when using Anthropic models (Claude).
106
+ *
107
+ * Prompt caching reduces costs and latency by caching message prefixes.
108
+ * Cache breakpoints mark where the cacheable prefix ends.
109
+ *
110
+ * The function receives each message with positional context and returns
111
+ * true to add a cache breakpoint after that message.
112
+ *
113
+ * System prompt is included as role: 'system' at index 0 when present.
114
+ *
115
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Cache system prompt + last message (most common pattern)
120
+ * {
121
+ * cacheBreakpoint: (msg) => msg.role === 'system' || msg.isLast
122
+ * }
123
+ *
124
+ * // Cache only the last message
125
+ * {
126
+ * cacheBreakpoint: (msg) => msg.isLast
127
+ * }
128
+ *
129
+ * // Cache system prompt only
130
+ * {
131
+ * cacheBreakpoint: (msg) => msg.role === 'system'
132
+ * }
133
+ *
134
+ * // Cache first 3 messages + last
135
+ * {
136
+ * cacheBreakpoint: (msg) => msg.index < 3 || msg.isLast
137
+ * }
138
+ *
139
+ * // System prompt with 1h TTL, last message with 5m TTL
140
+ * {
141
+ * cacheBreakpoint: (msg) => {
142
+ * if (msg.role === 'system') return '1h';
143
+ * if (msg.isLast) return '5m';
144
+ * return false;
145
+ * }
146
+ * }
147
+ * ```
148
+ */
149
+ cacheBreakpoint?: CacheBreakpointFn;
102
150
  }
103
151
  /**
104
152
  * Agent implementation for AI SDK models (Anthropic, OpenAI, Google, etc.).
@@ -151,6 +199,7 @@ export declare class AISDKAgent implements Agent {
151
199
  private langfuse;
152
200
  private toolFilter?;
153
201
  private systemPrompt?;
202
+ private cacheBreakpoint?;
154
203
  constructor(config: AISDKAgentConfig);
155
204
  getName(): string;
156
205
  getAnnotation(): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"AISDKAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,aAAa,EAA2D,MAAM,IAAI,CAAC;AAIpH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA8C/C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,UAAW,YAAW,KAAK;IACtC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,I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AAI,MAAM;IAIjB,aAAa,IAAI,MAAM,GAAG,SAAS;IAInC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IA6XxE;;;;;OAKG;YACW,mBAAmB;IAcjC;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAsBnB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IA6B7B,OAAO,CAAC,mBAAmB;IA2B3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAMpC;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAKlC;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAG9B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAG/B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAI9B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAMtC;IAEH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAM1B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAqC;IAEhF;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Anthropic prompt caching utilities for AI SDK Agent.
3
+ *
4
+ * This module handles cache breakpoint configuration for Anthropic models (Claude).
5
+ * Prompt caching reduces costs and latency by caching message prefixes.
6
+ *
7
+ * @see https://platform.claude.com/docs/en/build-with-claude/prompt-caching
8
+ */
9
+ import type { LanguageModel, ModelMessage } from 'ai';
10
+ /**
11
+ * ModelMessage extended with positional context for cache breakpoint decisions.
12
+ * Used by the cacheBreakpoint config to determine which messages should have
13
+ * Anthropic's cache_control breakpoints applied.
14
+ *
15
+ * System prompt is included as role: 'system' at index 0 when present.
16
+ */
17
+ export type MessageWithCacheContext = ModelMessage & {
18
+ /** Position in the messages array (0-indexed, system prompt is 0 if present) */
19
+ index: number;
20
+ /** Total number of messages including system prompt */
21
+ totalCount: number;
22
+ /** True if this is the first message */
23
+ isFirst: boolean;
24
+ /** True if this is the last message */
25
+ isLast: boolean;
26
+ };
27
+ /**
28
+ * Cache TTL options for Anthropic prompt caching.
29
+ * - '5m': 5-minute cache (default, refreshed on each use at no cost)
30
+ * - '1h': 1-hour cache (additional cost, useful for infrequent access patterns)
31
+ *
32
+ * @see https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration
33
+ */
34
+ export type CacheTtl = '5m' | '1h';
35
+ /**
36
+ * Return type for cacheBreakpoint function.
37
+ * - `false` / `null` / `undefined`: No cache breakpoint
38
+ * - `true`: Cache breakpoint with default TTL (5m)
39
+ * - `'5m'` / `'1h'`: Cache breakpoint with specified TTL
40
+ */
41
+ export type CacheBreakpointResult = boolean | CacheTtl | null | undefined;
42
+ /**
43
+ * Function type for determining cache breakpoints.
44
+ */
45
+ export type CacheBreakpointFn = (message: MessageWithCacheContext) => CacheBreakpointResult;
46
+ /**
47
+ * Checks if the given model is an Anthropic model (Claude).
48
+ */
49
+ export declare function isAnthropicModel(model: LanguageModel): boolean;
50
+ /**
51
+ * Applies cache breakpoints to messages for Anthropic prompt caching.
52
+ * Only applies when:
53
+ * 1. cacheBreakpoint config is provided
54
+ * 2. Model is an Anthropic model
55
+ *
56
+ * Adds providerOptions.anthropic.cacheControl to messages where
57
+ * the cacheBreakpoint function returns true.
58
+ *
59
+ * @param messages - The messages array (system prompt should be prepended as role: 'system')
60
+ * @param cacheBreakpoint - Function to determine which messages should have cache breakpoints
61
+ * @param model - The AI SDK LanguageModel to check if it's Anthropic
62
+ * @returns Messages with cache control providerOptions added where applicable
63
+ */
64
+ export declare function applyCacheBreakpoints(messages: ModelMessage[], cacheBreakpoint: CacheBreakpointFn | undefined, model: LanguageModel): ModelMessage[];
65
+ //# sourceMappingURL=anthropicCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropicCache.d.ts","sourceRoot":"","sources":["../../../src/agents/anthropicCache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAGtD;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,YAAY,GAAG;IACnD,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,uBAAuB,KAAK,qBAAqB,CAAC;AAE5F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAQ9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,YAAY,EAAE,EACxB,eAAe,EAAE,iBAAiB,GAAG,SAAS,EAC9C,KAAK,EAAE,aAAa,GACnB,YAAY,EAAE,CAyDhB"}
@@ -4,4 +4,5 @@
4
4
  */
5
5
  export type { Agent, AgentInput, EventEmitter, AgentResult, ClientSession } from './types';
6
6
  export { AISDKAgent, type AISDKAgentConfig } from './AISDKAgent';
7
+ export { applyCacheBreakpoints, isAnthropicModel, type MessageWithCacheContext, type CacheTtl, type CacheBreakpointResult, type CacheBreakpointFn, } from './anthropicCache';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runner.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.test.d.ts","sourceRoot":"","sources":["../../../../../src/agents/plugins/__tests__/runner.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ import type { AgentPlugin } from '../types';
2
+ /**
3
+ * Citation source that can be included in tool results.
4
+ * Tools (like RAG) can return citations in their results using this format.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // In your RAG tool implementation:
9
+ * return {
10
+ * answer: "Based on the documentation...",
11
+ * _citations: [
12
+ * { url: "https://docs.example.com/api", title: "API Reference" },
13
+ * { url: "https://docs.example.com/guide", title: "Getting Started Guide" },
14
+ * ]
15
+ * };
16
+ * ```
17
+ */
18
+ export interface ToolCitationSource {
19
+ /** URL of the source document */
20
+ url: string;
21
+ /** Title of the source (optional) */
22
+ title?: string;
23
+ /** Additional metadata (optional) */
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ /**
27
+ * Available citation types.
28
+ *
29
+ * - `anthropic`: Extracts from Anthropic web search source chunks (streaming) and result.sources
30
+ * - `openai`: Extracts from OpenAI url_citation annotations in response messages
31
+ * - `rag`: Extracts from tool results with `_citations`, `citations`, or `sources` fields
32
+ */
33
+ export type CitationType = 'rag';
34
+ /**
35
+ * Plugin that handles citation collection and emission.
36
+ *
37
+ * Supports multiple citation sources:
38
+ * - **rag**: Citations in tool results via `_citations`, `citations`, or `sources` fields
39
+ * - **anthropic**: Source chunks during streaming + result.sources (for future use)
40
+ * - **openai**: url_citation annotations in response (for future use)
41
+ *
42
+ * @param enabledTypes - Which extractors to enable. If not provided, all extractors are enabled.
43
+ * Extractors run in the order specified.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // With custom RAG tool - return citations in the tool result
48
+ * import { AISDKAgent, citationPlugin } from '@meetsmore-oss/use-ai-server';
49
+ *
50
+ * const ragTool = defineTool(
51
+ * 'Search internal documentation',
52
+ * z.object({ query: z.string() }),
53
+ * async ({ query }) => {
54
+ * const results = await vectorDb.search(query);
55
+ * return {
56
+ * answer: results.map(r => r.content).join('\n'),
57
+ * _citations: results.map(r => ({
58
+ * url: r.sourceUrl,
59
+ * title: r.title,
60
+ * })),
61
+ * };
62
+ * }
63
+ * );
64
+ *
65
+ * const agent = new AISDKAgent({
66
+ * model: anthropic('claude-sonnet-4-20250514'),
67
+ * plugins: [citationPlugin(['rag'])],
68
+ * });
69
+ * ```
70
+ */
71
+ export declare function citationPlugin(enabledTypes?: CitationType[]): AgentPlugin;
72
+ //# sourceMappingURL=citationPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"citationPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/agents/plugins/citations/citationPlugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAgF,MAAM,UAAU,CAAC;AAI1H;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC;AAoPjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,cAAc,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,GAAG,WAAW,CA4CzE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=citationPlugin.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"citationPlugin.test.d.ts","sourceRoot":"","sources":["../../../../../src/agents/plugins/citations/citationPlugin.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Citation plugin for AISDKAgent.
3
+ * Collects sources from AI responses and emits citation events.
4
+ */
5
+ export { citationPlugin } from './citationPlugin';
6
+ export type { ToolCitationSource, CitationType } from './citationPlugin';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agents/plugins/citations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Agent plugin system for extending AISDKAgent functionality.
3
+ *
4
+ * Plugins can hook into the agent lifecycle to:
5
+ * - Modify inputs before sending to AI
6
+ * - Transform streaming chunks
7
+ * - Intercept or modify tool calls
8
+ * - Process and transform responses
9
+ * - Handle errors
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { AISDKAgent } from '@meetsmore-oss/use-ai-server';
14
+ * import type { AgentPlugin } from '@meetsmore-oss/use-ai-server';
15
+ *
16
+ * const loggingPlugin: AgentPlugin = {
17
+ * id: 'logging',
18
+ * onUserMessage(input, ctx) {
19
+ * ctx.logger.info('Message received');
20
+ * return input;
21
+ * },
22
+ * };
23
+ *
24
+ * const agent = new AISDKAgent({
25
+ * model: anthropic('claude-3-5-sonnet-20241022'),
26
+ * plugins: [loggingPlugin],
27
+ * });
28
+ * ```
29
+ */
30
+ export type { AgentPlugin, AgentPluginContext, AgentRunInput, AgentRunResult, ToolCallInfo, ToolResultInfo, StreamChunk, TextDeltaChunk, ReasoningDeltaChunk, SourceChunk, ToolInputStartChunk, ToolInputDeltaChunk, ToolCallChunk, ToolResultChunk, StartStepChunk, FinishStepChunk, ErrorChunk, UnknownChunk, } from './types';
31
+ export { AgentPluginRunner } from './runner';
32
+ export { citationPlugin } from './citations';
33
+ export type { ToolCitationSource, CitationType } from './citations';
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agents/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EAEd,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,UAAU,EACV,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,76 @@
1
+ import type { AgentPlugin, AgentPluginContext, AgentRunInput, AgentRunResult, ToolCallInfo, ToolResultInfo, StreamChunk } from './types';
2
+ /**
3
+ * Orchestrates plugin execution for AISDKAgent.
4
+ *
5
+ * Plugins are executed in the order they were registered.
6
+ * Each hook is called sequentially, with the output of one plugin
7
+ * becoming the input of the next.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const runner = new AgentPluginRunner([
12
+ * loggingPlugin,
13
+ * metricsPlugin,
14
+ * ]);
15
+ *
16
+ * // Initialize plugins
17
+ * await runner.initialize({ provider: 'anthropic' });
18
+ *
19
+ * // Use in agent run
20
+ * const processedInput = await runner.onUserMessage(input, context);
21
+ * ```
22
+ */
23
+ export declare class AgentPluginRunner {
24
+ private plugins;
25
+ constructor(plugins?: AgentPlugin[]);
26
+ /**
27
+ * Initialize all plugins.
28
+ * Called once when the agent is created.
29
+ */
30
+ initialize(context: {
31
+ provider: string;
32
+ }): Promise<void>;
33
+ /**
34
+ * Run onUserMessage hook for all plugins.
35
+ * Each plugin receives the output of the previous plugin.
36
+ */
37
+ onUserMessage(input: AgentRunInput, context: AgentPluginContext): Promise<AgentRunInput>;
38
+ /**
39
+ * Run onAgentResponse hook for all plugins.
40
+ * Each plugin receives the output of the previous plugin.
41
+ */
42
+ onAgentResponse(result: AgentRunResult, context: AgentPluginContext): Promise<AgentRunResult>;
43
+ /**
44
+ * Run onTextChunk hook for all plugins.
45
+ * Returns the transformed chunk (or original if no transform).
46
+ */
47
+ onTextChunk(chunk: string, context: AgentPluginContext): Promise<string>;
48
+ /**
49
+ * Run onBeforeToolCall hook for all plugins.
50
+ * Returns null if any plugin returns null (tool call should be skipped).
51
+ */
52
+ onBeforeToolCall(toolCall: ToolCallInfo, context: AgentPluginContext): Promise<ToolCallInfo | null>;
53
+ /**
54
+ * Run onAfterToolCall hook for all plugins.
55
+ * Returns the final transformed result.
56
+ */
57
+ onAfterToolCall(toolResult: ToolResultInfo, context: AgentPluginContext): Promise<unknown>;
58
+ /**
59
+ * Run onChunk hook for all plugins.
60
+ * Called for each chunk from the AI SDK stream.
61
+ */
62
+ onChunk(chunk: StreamChunk, context: AgentPluginContext): Promise<void>;
63
+ /**
64
+ * Destroy all plugins and release resources.
65
+ */
66
+ destroy(): Promise<void>;
67
+ /**
68
+ * Check if any plugins are registered.
69
+ */
70
+ hasPlugins(): boolean;
71
+ /**
72
+ * Get the number of registered plugins.
73
+ */
74
+ get pluginCount(): number;
75
+ }
76
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../../src/agents/plugins/runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAqB;gBAExB,OAAO,GAAE,WAAW,EAAO;IAIvC;;;OAGG;IACG,UAAU,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9D;;;OAGG;IACG,aAAa,CACjB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,aAAa,CAAC;IAUzB;;;OAGG;IACG,eAAe,CACnB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC;IAU1B;;;OAGG;IACG,WAAW,CACf,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC;IAalB;;;OAGG;IACG,gBAAgB,CACp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