@cognipeer/agent-sdk 0.20.0 → 0.22.1

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.
@@ -1,5 +1,6 @@
1
1
  type RuleFamily = "openai" | "anthropic" | "gemini" | "other";
2
- type ReasoningStyle = "effort" | "adaptive" | "budget" | "toggle" | "none";
2
+ /** `level` = a discrete thinking level instead of a token budget (Gemini 3 `thinkingConfig.thinkingLevel`). */
3
+ type ReasoningStyle = "effort" | "adaptive" | "budget" | "toggle" | "level" | "none";
3
4
  /** How "reasoning off" is spelled on the wire (`none` = the effort value itself). */
4
5
  type OffMechanism = "none" | "disabled" | "between_tools";
5
6
  type TemperatureRule = "any" | "default-only" | "unsupported" | "thinking-requires-1";
@@ -17,6 +18,21 @@ type ModelRule = {
17
18
  /** Efforts the OpenAI Responses endpoint accepts, when they differ from `efforts`. */
18
19
  responsesEfforts?: ReasoningEffort[];
19
20
  off: OffMechanism | null;
21
+ /**
22
+ * Budget style only: the smallest thinking budget the model accepts, used for
23
+ * effort `none` when `efforts` has no `none` (the model cannot turn thinking off,
24
+ * e.g. Gemini 2.5 Pro: 128).
25
+ */
26
+ minBudget?: number;
27
+ /**
28
+ * Adaptive style only: the model already thinks when a request carries no
29
+ * `thinking` field (Claude 5.x), but returns the thinking text empty because
30
+ * `display` defaults to "omitted". `includeThoughts: true` without any effort or
31
+ * budget then sends `thinking: { type: "adaptive", display: "summarized" }` alone
32
+ * (no `output_config`, no `max_tokens` raise). Unset: thinking is opt-in, and
33
+ * `includeThoughts` alone sends nothing.
34
+ */
35
+ defaultOn?: boolean;
20
36
  };
21
37
  sampling: {
22
38
  temperature: TemperatureRule;
@@ -39,6 +55,8 @@ type ModelRules = {
39
55
  effortLadder: ReasoningEffort[];
40
56
  /** Thinking-token budgets for budget-style engines (Anthropic 3.7/4.x, Bedrock). */
41
57
  budgets: Record<Exclude<ReasoningEffort, "none">, number>;
58
+ /** `max_tokens` floor per effort for adaptive thinking, where thinking and the answer share the cap. */
59
+ adaptiveMaxTokens: Record<Exclude<ReasoningEffort, "none">, number>;
42
60
  geminiBudgets: Record<Exclude<ReasoningEffort, "none">, number>;
43
61
  rules: ModelRule[];
44
62
  };
@@ -76,8 +94,10 @@ declare function clearLearnedModelRules(): void;
76
94
  /**
77
95
  * Finds the rule for a model: the first matching rule of the provider's family
78
96
  * (or families, for gateways such as Bedrock), else the family's permissive
79
- * default. Learned adjustments for (provider, model) are merged in; `patch`
80
- * lets a caller layer one more override on top (used by the retry loop).
97
+ * default. A Bedrock id that is not Claude has no Anthropic default to fall back
98
+ * on: it gets the generic `other` one. Learned adjustments for (provider, model)
99
+ * are merged in; `patch` lets a caller layer one more override on top (used by the
100
+ * retry loop).
81
101
  */
82
102
  declare function resolveModelRule(opts: {
83
103
  provider?: string;
@@ -111,7 +131,7 @@ declare function applyDropParams(body: Record<string, any>, rule: ModelRule): vo
111
131
  declare function effortBudget(effort: ReasoningEffort, table?: "anthropic" | "gemini"): number;
112
132
 
113
133
  declare const MAX_ADJUSTMENTS = 3;
114
- type ParsedModelErrorKind = "unsupported_parameter" | "unsupported_value" | "max_tokens_rename" | "default_only" | "chat_tools_effort" | "thinking_enabled_unsupported" | "thinking_adaptive_unsupported" | "thinking_off_between_tools" | "thinking_disabled_unsupported" | "temperature_thinking";
134
+ type ParsedModelErrorKind = "unsupported_parameter" | "unsupported_value" | "max_tokens_rename" | "max_tokens_too_large" | "default_only" | "chat_tools_effort" | "thinking_enabled_unsupported" | "thinking_adaptive_unsupported" | "thinking_off_between_tools" | "thinking_disabled_unsupported" | "temperature_thinking";
115
135
  type ParsedModelError = {
116
136
  kind: ParsedModelErrorKind;
117
137
  param?: string;
@@ -119,6 +139,12 @@ type ParsedModelError = {
119
139
  supportedValues?: string[];
120
140
  /** `max_tokens` / `max_completion_tokens` for `max_tokens_rename`. */
121
141
  renameTo?: "max_tokens" | "max_completion_tokens";
142
+ /**
143
+ * `max_tokens_too_large` only: the most completion tokens the server says it
144
+ * accepts, when the message states it (a context-length message gives the
145
+ * window minus the prompt). Absent when the message states no usable number.
146
+ */
147
+ maxAllowed?: number;
122
148
  message: string;
123
149
  };
124
150
  type ModelRuleLearnedEvent = {
@@ -158,6 +184,19 @@ type MessageRole = "system" | "user" | "assistant" | "tool";
158
184
  type TextContent = {
159
185
  type: "text";
160
186
  text: string;
187
+ /**
188
+ * Explicit prompt-cache breakpoint on this text part (a 5-minute lifetime
189
+ * unless `ttl: "1h"`). Sent as `cache_control` by the Anthropic provider
190
+ * (Claude on Vertex included) and by the OpenAI-compatible provider
191
+ * (OpenRouter and LiteLLM forward it to Claude and similar models; Chat
192
+ * Completions only). Other providers ignore it: OpenAI and Azure never send
193
+ * the field. On an agent's messages it is set on the part itself (`cacheControl`,
194
+ * or Anthropic's `cache_control`); `fromNativeProvider` carries it through.
195
+ */
196
+ cacheControl?: {
197
+ type: "ephemeral";
198
+ ttl?: "5m" | "1h";
199
+ };
161
200
  };
162
201
  type ImageContent = {
163
202
  type: "image";
@@ -248,6 +287,11 @@ type UnifiedMessage = {
248
287
  name?: string;
249
288
  toolCalls?: ToolCall[];
250
289
  toolCallId?: string;
290
+ /**
291
+ * Tool-role messages only: the tool result is an error. A provider with a
292
+ * native error flag for tool results maps it; the others ignore it.
293
+ */
294
+ isError?: boolean;
251
295
  /** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
252
296
  reasoning?: ReasoningPayload;
253
297
  };
@@ -294,6 +338,13 @@ type ChatCompletionRequest = {
294
338
  /** OpenAI-family: how many top log probabilities per token. Passed through. */
295
339
  topLogprobs?: number;
296
340
  extra?: Record<string, any>;
341
+ /**
342
+ * What this call is for (`"summarization"`, `"reflection"`): the agent's own
343
+ * side calls tag themselves through the invoke options and the adapter copies
344
+ * the tag here. Providers ignore it and never put it on the wire; a host that
345
+ * reads the request (cost attribution, routing) can use it.
346
+ */
347
+ purpose?: string;
297
348
  /**
298
349
  * Unified native-reasoning request config. Each provider maps this to its
299
350
  * own shape:
@@ -344,6 +395,15 @@ type ReasoningRequestConfig = {
344
395
  /** Provider-specific passthrough merged on top of the mapped shape. */
345
396
  providerExtras?: Record<string, any>;
346
397
  };
398
+ /**
399
+ * A provider's own usage counters, on the provider's NATIVE basis: Anthropic and
400
+ * Bedrock `inputTokens` leave out the cache read + write, Vertex `outputTokens`
401
+ * leaves out the reasoning; OpenAI-style providers are inclusive. `cachedInputTokens`
402
+ * / `cachedWriteTokens` / `reasoningTokens` are 0 when the provider does not report
403
+ * them (never an estimate). `fromNativeProvider` converts to the inclusive
404
+ * `MessageUsage` (see `BaseProvider.usageBasis`). A streaming provider may yield
405
+ * several usage chunks; each one is CUMULATIVE, so a consumer keeps the last.
406
+ */
347
407
  type TokenUsage = {
348
408
  inputTokens: number;
349
409
  outputTokens: number;
@@ -396,6 +456,14 @@ type ChatCompletionChunk = {
396
456
  rawFinishReason?: string;
397
457
  /** See ChatCompletionResponse.providerFields; per-chunk (fingerprint, tier, delta refusal/annotations, logprobs). */
398
458
  providerFields?: ProviderResponseFields;
459
+ /**
460
+ * The provider is starting the answer over (for example a host that retries a
461
+ * call cut off by its output limit inside one stream): `fromNativeProvider`
462
+ * drops the text, tool calls, reasoning and finish reason gathered so far. Text
463
+ * and reasoning deltas already yielded to the consumer cannot be taken back.
464
+ * Usage is not reset: usage chunks are cumulative, the last one wins.
465
+ */
466
+ reset?: boolean;
399
467
  };
400
468
  /** Why the text is being embedded; mapped to each provider's own task/input type. */
401
469
  type EmbeddingInputType = "search_document" | "search_query" | "classification" | "clustering" | "semantic_similarity" | "question_answering" | "fact_verification" | "code_retrieval_query" | (string & {});
@@ -548,6 +616,20 @@ type OpenAIProviderConfig = ProviderTransportConfig & {
548
616
  */
549
617
  responsesStreaming?: boolean;
550
618
  };
619
+ /** Prompt caching options shared by the Anthropic, Bedrock, Vertex (Claude models) and OpenAI-compatible providers. */
620
+ type PromptCachingConfig = {
621
+ /** Turns caching on. Off (or omitted) sends no cache markers. */
622
+ enabled: boolean;
623
+ /**
624
+ * `"auto"` (default): cache the static prefix (system + tools) AND the moving
625
+ * conversation tail (Anthropic: top-level automatic `cache_control`; Bedrock:
626
+ * a `cachePoint` after the last user message; OpenAI-compatible: the last text
627
+ * part of the last user or tool message). `"static"`: system (+ tools) only.
628
+ */
629
+ strategy?: "auto" | "static";
630
+ /** Cache lifetime: `"5m"` (default) or `"1h"`. Bedrock Nova is always 5 minutes. */
631
+ ttl?: "5m" | "1h";
632
+ };
551
633
  type AnthropicProviderConfig = ProviderTransportConfig & {
552
634
  provider: "anthropic";
553
635
  apiKey: string;
@@ -557,13 +639,13 @@ type AnthropicProviderConfig = ProviderTransportConfig & {
557
639
  anthropicVersion?: string;
558
640
  retry?: ProviderRetryConfig;
559
641
  /**
560
- * Prompt caching configuration. When enabled, places cache_control:
561
- * ephemeral breakpoints on the system prompt and the final tool definition,
562
- * which is the recommended Anthropic recipe for static system + tools.
642
+ * Prompt caching configuration. When enabled, places explicit cache_control
643
+ * breakpoints on the system prompt and the final tool definition (the static
644
+ * prefix) and, with the default `strategy: "auto"`, also sets the top-level
645
+ * automatic `cache_control` so the breakpoint follows the conversation tail.
646
+ * See {@link PromptCachingConfig}.
563
647
  */
564
- prompt_caching?: {
565
- enabled: boolean;
566
- };
648
+ prompt_caching?: PromptCachingConfig;
567
649
  /**
568
650
  * Thinking request shape. `auto` (default) picks per model id: Claude 5.x
569
651
  * and newer use `thinking:{type:"adaptive"}` + `output_config.effort`, older
@@ -607,6 +689,31 @@ type OpenAICompatibleProviderConfig = ProviderTransportConfig & {
607
689
  baseURL: string;
608
690
  defaultModel?: string;
609
691
  defaultHeaders?: Record<string, string>;
692
+ /**
693
+ * Explicit prompt caching through servers that route to Claude and similar
694
+ * models (OpenRouter, LiteLLM): places `cache_control` markers on Chat
695
+ * Completions text parts. Off unless `enabled: true`.
696
+ *
697
+ * - `strategy: "static"`: the end of the system prompt (leading system
698
+ * messages; sent as a text part).
699
+ * - `strategy: "auto"` (default): that, plus the last text part of the last
700
+ * user or tool message.
701
+ * - `ttl`: `"5m"` (default, the field is omitted) or `"1h"`.
702
+ *
703
+ * At most 4 markers go out in total, counting the `cacheControl` the caller
704
+ * set on its own text parts (those are always kept and sent, with or without
705
+ * this option). A plain string message becomes one text part only when a
706
+ * marker is added to it. Not sent to a server that rejects `cache_control`:
707
+ * leave this off for those. Ignored on the Responses API.
708
+ */
709
+ prompt_caching?: PromptCachingConfig;
710
+ /**
711
+ * Send the reasoning text of assistant messages back as `reasoning_content`
712
+ * (the DeepSeek spelling), for servers whose thinking mode requires it to be
713
+ * echoed in a tool loop. Default false. See the `reasoning_content` handling
714
+ * in the server's own documentation before enabling it.
715
+ */
716
+ replayReasoningContent?: boolean;
610
717
  };
611
718
  type BedrockProviderConfig = ProviderTransportConfig & {
612
719
  provider: "bedrock";
@@ -621,12 +728,12 @@ type BedrockProviderConfig = ProviderTransportConfig & {
621
728
  retry?: ProviderRetryConfig;
622
729
  /**
623
730
  * Insert Bedrock Converse `cachePoint` blocks at the end of the system
624
- * prompt and tools list. Only supported by models that implement Converse
625
- * prompt caching (most Anthropic Claude variants on Bedrock).
731
+ * prompt and tools list and, with the default `strategy: "auto"`, at the end
732
+ * of the last user message. Applies to Claude and Amazon Nova (Nova: no tools
733
+ * checkpoint, 5-minute only); models of families without explicit caching get
734
+ * no checkpoints. See {@link PromptCachingConfig}.
626
735
  */
627
- prompt_caching?: {
628
- enabled: boolean;
629
- };
736
+ prompt_caching?: PromptCachingConfig;
630
737
  };
631
738
  type VertexProviderConfig = ProviderTransportConfig & {
632
739
  provider: "vertex";
@@ -638,6 +745,19 @@ type VertexProviderConfig = ProviderTransportConfig & {
638
745
  defaultHeaders?: Record<string, string>;
639
746
  /** Retry policy for 429/5xx (default 3 retries, exponential backoff). */
640
747
  retry?: ProviderRetryConfig;
748
+ /**
749
+ * Prompt caching for Claude models served by Vertex (ignored for Gemini): the
750
+ * same shape and meaning as on `AnthropicProviderConfig.prompt_caching`. Off
751
+ * unless `enabled: true`. See {@link PromptCachingConfig}.
752
+ */
753
+ prompt_caching?: PromptCachingConfig;
754
+ /**
755
+ * Thinking request shape for Claude models on Vertex (ignored for Gemini):
756
+ * `auto` (default, by model id), `adaptive` or `budget`, as on
757
+ * `AnthropicProviderConfig.thinkingMode`. Spelled out here because
758
+ * `utils/reasoning.ts`, which owns `ThinkingMode`, imports from this file.
759
+ */
760
+ thinkingMode?: "auto" | "adaptive" | "budget";
641
761
  };
642
762
  type JevProviderConfig = ProviderTransportConfig & {
643
763
  provider: "jev";
@@ -657,4 +777,4 @@ declare class ProviderError extends Error {
657
777
  constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
658
778
  }
659
779
 
660
- export { type EmbeddingUsage as $, type AnthropicProviderConfig as A, type BedrockProviderConfig as B, type ChatCompletionRequest as C, type ModelRule as D, type EmbeddingRequest as E, type ModelRules as F, type ResolvedModelRule as G, type ReasoningEffort as H, type EffortMapping as I, type JevProviderConfig as J, type RuleFamily as K, type RuleSource as L, type ModelRuleLearnedEvent as M, type ReasoningStyle as N, type OpenAICompatibleProviderConfig as O, type ProviderType as P, type OffMechanism as Q, type RulePatch as R, type TemperatureRule as S, type ToolDefinition as T, type UnifiedMessage as U, type VertexProviderConfig as V, type MaxTokensParam as W, type SamplingField as X, type ParsedModelError as Y, type FinishReason as Z, type ProviderResponseFields as _, type EmbeddingResponse as a, type EmbeddingInputType as a0, type TextContent as a1, type ImageContent as a2, type FileContent as a3, type AudioContent as a4, type ToolCall as a5, type ProviderTransportConfig as a6, type ChatCompletionResponse as b, type ChatCompletionChunk as c, type OpenAIProviderConfig as d, type TokenUsage as e, type AzureProviderConfig as f, type ReasoningRequestConfig as g, type ProviderConfig as h, ProviderError as i, emptyUsage as j, MODEL_RULES as k, modelIdCandidates as l, mapReasoningEffort as m, allowsSampling as n, applyDropParams as o, effortBudget as p, mergeRulePatch as q, resolveModelRule as r, parseModelError as s, runWithModelAdjustments as t, asModelRequestError as u, MAX_ADJUSTMENTS as v, listLearnedModelRules as w, getLearnedModelRulePatch as x, rememberModelRulePatch as y, clearLearnedModelRules as z };
780
+ export { type FinishReason as $, type AnthropicProviderConfig as A, type BedrockProviderConfig as B, type ChatCompletionRequest as C, rememberModelRulePatch as D, type EmbeddingRequest as E, clearLearnedModelRules as F, type ModelRule as G, type ModelRules as H, type ResolvedModelRule as I, type JevProviderConfig as J, type ReasoningEffort as K, type EffortMapping as L, type ModelRuleLearnedEvent as M, type RuleFamily as N, type OpenAICompatibleProviderConfig as O, type ProviderType as P, type RuleSource as Q, type RulePatch as R, type ReasoningStyle as S, type ToolDefinition as T, type UnifiedMessage as U, type VertexProviderConfig as V, type OffMechanism as W, type TemperatureRule as X, type MaxTokensParam as Y, type SamplingField as Z, type ParsedModelError as _, type EmbeddingResponse as a, type ProviderResponseFields as a0, type EmbeddingUsage as a1, type EmbeddingInputType as a2, type TextContent as a3, type ImageContent as a4, type FileContent as a5, type AudioContent as a6, type ToolCall as a7, type ProviderTransportConfig as a8, type ChatCompletionResponse as b, type ChatCompletionChunk as c, type OpenAIProviderConfig as d, type ReasoningBlock as e, type TokenUsage as f, type AzureProviderConfig as g, type PromptCachingConfig as h, type ReasoningRequestConfig as i, type ProviderConfig as j, ProviderError as k, emptyUsage as l, MODEL_RULES as m, mapReasoningEffort as n, modelIdCandidates as o, allowsSampling as p, applyDropParams as q, resolveModelRule as r, effortBudget as s, mergeRulePatch as t, parseModelError as u, runWithModelAdjustments as v, asModelRequestError as w, MAX_ADJUSTMENTS as x, listLearnedModelRules as y, getLearnedModelRulePatch as z };
@@ -1,5 +1,6 @@
1
1
  type RuleFamily = "openai" | "anthropic" | "gemini" | "other";
2
- type ReasoningStyle = "effort" | "adaptive" | "budget" | "toggle" | "none";
2
+ /** `level` = a discrete thinking level instead of a token budget (Gemini 3 `thinkingConfig.thinkingLevel`). */
3
+ type ReasoningStyle = "effort" | "adaptive" | "budget" | "toggle" | "level" | "none";
3
4
  /** How "reasoning off" is spelled on the wire (`none` = the effort value itself). */
4
5
  type OffMechanism = "none" | "disabled" | "between_tools";
5
6
  type TemperatureRule = "any" | "default-only" | "unsupported" | "thinking-requires-1";
@@ -17,6 +18,21 @@ type ModelRule = {
17
18
  /** Efforts the OpenAI Responses endpoint accepts, when they differ from `efforts`. */
18
19
  responsesEfforts?: ReasoningEffort[];
19
20
  off: OffMechanism | null;
21
+ /**
22
+ * Budget style only: the smallest thinking budget the model accepts, used for
23
+ * effort `none` when `efforts` has no `none` (the model cannot turn thinking off,
24
+ * e.g. Gemini 2.5 Pro: 128).
25
+ */
26
+ minBudget?: number;
27
+ /**
28
+ * Adaptive style only: the model already thinks when a request carries no
29
+ * `thinking` field (Claude 5.x), but returns the thinking text empty because
30
+ * `display` defaults to "omitted". `includeThoughts: true` without any effort or
31
+ * budget then sends `thinking: { type: "adaptive", display: "summarized" }` alone
32
+ * (no `output_config`, no `max_tokens` raise). Unset: thinking is opt-in, and
33
+ * `includeThoughts` alone sends nothing.
34
+ */
35
+ defaultOn?: boolean;
20
36
  };
21
37
  sampling: {
22
38
  temperature: TemperatureRule;
@@ -39,6 +55,8 @@ type ModelRules = {
39
55
  effortLadder: ReasoningEffort[];
40
56
  /** Thinking-token budgets for budget-style engines (Anthropic 3.7/4.x, Bedrock). */
41
57
  budgets: Record<Exclude<ReasoningEffort, "none">, number>;
58
+ /** `max_tokens` floor per effort for adaptive thinking, where thinking and the answer share the cap. */
59
+ adaptiveMaxTokens: Record<Exclude<ReasoningEffort, "none">, number>;
42
60
  geminiBudgets: Record<Exclude<ReasoningEffort, "none">, number>;
43
61
  rules: ModelRule[];
44
62
  };
@@ -76,8 +94,10 @@ declare function clearLearnedModelRules(): void;
76
94
  /**
77
95
  * Finds the rule for a model: the first matching rule of the provider's family
78
96
  * (or families, for gateways such as Bedrock), else the family's permissive
79
- * default. Learned adjustments for (provider, model) are merged in; `patch`
80
- * lets a caller layer one more override on top (used by the retry loop).
97
+ * default. A Bedrock id that is not Claude has no Anthropic default to fall back
98
+ * on: it gets the generic `other` one. Learned adjustments for (provider, model)
99
+ * are merged in; `patch` lets a caller layer one more override on top (used by the
100
+ * retry loop).
81
101
  */
82
102
  declare function resolveModelRule(opts: {
83
103
  provider?: string;
@@ -111,7 +131,7 @@ declare function applyDropParams(body: Record<string, any>, rule: ModelRule): vo
111
131
  declare function effortBudget(effort: ReasoningEffort, table?: "anthropic" | "gemini"): number;
112
132
 
113
133
  declare const MAX_ADJUSTMENTS = 3;
114
- type ParsedModelErrorKind = "unsupported_parameter" | "unsupported_value" | "max_tokens_rename" | "default_only" | "chat_tools_effort" | "thinking_enabled_unsupported" | "thinking_adaptive_unsupported" | "thinking_off_between_tools" | "thinking_disabled_unsupported" | "temperature_thinking";
134
+ type ParsedModelErrorKind = "unsupported_parameter" | "unsupported_value" | "max_tokens_rename" | "max_tokens_too_large" | "default_only" | "chat_tools_effort" | "thinking_enabled_unsupported" | "thinking_adaptive_unsupported" | "thinking_off_between_tools" | "thinking_disabled_unsupported" | "temperature_thinking";
115
135
  type ParsedModelError = {
116
136
  kind: ParsedModelErrorKind;
117
137
  param?: string;
@@ -119,6 +139,12 @@ type ParsedModelError = {
119
139
  supportedValues?: string[];
120
140
  /** `max_tokens` / `max_completion_tokens` for `max_tokens_rename`. */
121
141
  renameTo?: "max_tokens" | "max_completion_tokens";
142
+ /**
143
+ * `max_tokens_too_large` only: the most completion tokens the server says it
144
+ * accepts, when the message states it (a context-length message gives the
145
+ * window minus the prompt). Absent when the message states no usable number.
146
+ */
147
+ maxAllowed?: number;
122
148
  message: string;
123
149
  };
124
150
  type ModelRuleLearnedEvent = {
@@ -158,6 +184,19 @@ type MessageRole = "system" | "user" | "assistant" | "tool";
158
184
  type TextContent = {
159
185
  type: "text";
160
186
  text: string;
187
+ /**
188
+ * Explicit prompt-cache breakpoint on this text part (a 5-minute lifetime
189
+ * unless `ttl: "1h"`). Sent as `cache_control` by the Anthropic provider
190
+ * (Claude on Vertex included) and by the OpenAI-compatible provider
191
+ * (OpenRouter and LiteLLM forward it to Claude and similar models; Chat
192
+ * Completions only). Other providers ignore it: OpenAI and Azure never send
193
+ * the field. On an agent's messages it is set on the part itself (`cacheControl`,
194
+ * or Anthropic's `cache_control`); `fromNativeProvider` carries it through.
195
+ */
196
+ cacheControl?: {
197
+ type: "ephemeral";
198
+ ttl?: "5m" | "1h";
199
+ };
161
200
  };
162
201
  type ImageContent = {
163
202
  type: "image";
@@ -248,6 +287,11 @@ type UnifiedMessage = {
248
287
  name?: string;
249
288
  toolCalls?: ToolCall[];
250
289
  toolCallId?: string;
290
+ /**
291
+ * Tool-role messages only: the tool result is an error. A provider with a
292
+ * native error flag for tool results maps it; the others ignore it.
293
+ */
294
+ isError?: boolean;
251
295
  /** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
252
296
  reasoning?: ReasoningPayload;
253
297
  };
@@ -294,6 +338,13 @@ type ChatCompletionRequest = {
294
338
  /** OpenAI-family: how many top log probabilities per token. Passed through. */
295
339
  topLogprobs?: number;
296
340
  extra?: Record<string, any>;
341
+ /**
342
+ * What this call is for (`"summarization"`, `"reflection"`): the agent's own
343
+ * side calls tag themselves through the invoke options and the adapter copies
344
+ * the tag here. Providers ignore it and never put it on the wire; a host that
345
+ * reads the request (cost attribution, routing) can use it.
346
+ */
347
+ purpose?: string;
297
348
  /**
298
349
  * Unified native-reasoning request config. Each provider maps this to its
299
350
  * own shape:
@@ -344,6 +395,15 @@ type ReasoningRequestConfig = {
344
395
  /** Provider-specific passthrough merged on top of the mapped shape. */
345
396
  providerExtras?: Record<string, any>;
346
397
  };
398
+ /**
399
+ * A provider's own usage counters, on the provider's NATIVE basis: Anthropic and
400
+ * Bedrock `inputTokens` leave out the cache read + write, Vertex `outputTokens`
401
+ * leaves out the reasoning; OpenAI-style providers are inclusive. `cachedInputTokens`
402
+ * / `cachedWriteTokens` / `reasoningTokens` are 0 when the provider does not report
403
+ * them (never an estimate). `fromNativeProvider` converts to the inclusive
404
+ * `MessageUsage` (see `BaseProvider.usageBasis`). A streaming provider may yield
405
+ * several usage chunks; each one is CUMULATIVE, so a consumer keeps the last.
406
+ */
347
407
  type TokenUsage = {
348
408
  inputTokens: number;
349
409
  outputTokens: number;
@@ -396,6 +456,14 @@ type ChatCompletionChunk = {
396
456
  rawFinishReason?: string;
397
457
  /** See ChatCompletionResponse.providerFields; per-chunk (fingerprint, tier, delta refusal/annotations, logprobs). */
398
458
  providerFields?: ProviderResponseFields;
459
+ /**
460
+ * The provider is starting the answer over (for example a host that retries a
461
+ * call cut off by its output limit inside one stream): `fromNativeProvider`
462
+ * drops the text, tool calls, reasoning and finish reason gathered so far. Text
463
+ * and reasoning deltas already yielded to the consumer cannot be taken back.
464
+ * Usage is not reset: usage chunks are cumulative, the last one wins.
465
+ */
466
+ reset?: boolean;
399
467
  };
400
468
  /** Why the text is being embedded; mapped to each provider's own task/input type. */
401
469
  type EmbeddingInputType = "search_document" | "search_query" | "classification" | "clustering" | "semantic_similarity" | "question_answering" | "fact_verification" | "code_retrieval_query" | (string & {});
@@ -548,6 +616,20 @@ type OpenAIProviderConfig = ProviderTransportConfig & {
548
616
  */
549
617
  responsesStreaming?: boolean;
550
618
  };
619
+ /** Prompt caching options shared by the Anthropic, Bedrock, Vertex (Claude models) and OpenAI-compatible providers. */
620
+ type PromptCachingConfig = {
621
+ /** Turns caching on. Off (or omitted) sends no cache markers. */
622
+ enabled: boolean;
623
+ /**
624
+ * `"auto"` (default): cache the static prefix (system + tools) AND the moving
625
+ * conversation tail (Anthropic: top-level automatic `cache_control`; Bedrock:
626
+ * a `cachePoint` after the last user message; OpenAI-compatible: the last text
627
+ * part of the last user or tool message). `"static"`: system (+ tools) only.
628
+ */
629
+ strategy?: "auto" | "static";
630
+ /** Cache lifetime: `"5m"` (default) or `"1h"`. Bedrock Nova is always 5 minutes. */
631
+ ttl?: "5m" | "1h";
632
+ };
551
633
  type AnthropicProviderConfig = ProviderTransportConfig & {
552
634
  provider: "anthropic";
553
635
  apiKey: string;
@@ -557,13 +639,13 @@ type AnthropicProviderConfig = ProviderTransportConfig & {
557
639
  anthropicVersion?: string;
558
640
  retry?: ProviderRetryConfig;
559
641
  /**
560
- * Prompt caching configuration. When enabled, places cache_control:
561
- * ephemeral breakpoints on the system prompt and the final tool definition,
562
- * which is the recommended Anthropic recipe for static system + tools.
642
+ * Prompt caching configuration. When enabled, places explicit cache_control
643
+ * breakpoints on the system prompt and the final tool definition (the static
644
+ * prefix) and, with the default `strategy: "auto"`, also sets the top-level
645
+ * automatic `cache_control` so the breakpoint follows the conversation tail.
646
+ * See {@link PromptCachingConfig}.
563
647
  */
564
- prompt_caching?: {
565
- enabled: boolean;
566
- };
648
+ prompt_caching?: PromptCachingConfig;
567
649
  /**
568
650
  * Thinking request shape. `auto` (default) picks per model id: Claude 5.x
569
651
  * and newer use `thinking:{type:"adaptive"}` + `output_config.effort`, older
@@ -607,6 +689,31 @@ type OpenAICompatibleProviderConfig = ProviderTransportConfig & {
607
689
  baseURL: string;
608
690
  defaultModel?: string;
609
691
  defaultHeaders?: Record<string, string>;
692
+ /**
693
+ * Explicit prompt caching through servers that route to Claude and similar
694
+ * models (OpenRouter, LiteLLM): places `cache_control` markers on Chat
695
+ * Completions text parts. Off unless `enabled: true`.
696
+ *
697
+ * - `strategy: "static"`: the end of the system prompt (leading system
698
+ * messages; sent as a text part).
699
+ * - `strategy: "auto"` (default): that, plus the last text part of the last
700
+ * user or tool message.
701
+ * - `ttl`: `"5m"` (default, the field is omitted) or `"1h"`.
702
+ *
703
+ * At most 4 markers go out in total, counting the `cacheControl` the caller
704
+ * set on its own text parts (those are always kept and sent, with or without
705
+ * this option). A plain string message becomes one text part only when a
706
+ * marker is added to it. Not sent to a server that rejects `cache_control`:
707
+ * leave this off for those. Ignored on the Responses API.
708
+ */
709
+ prompt_caching?: PromptCachingConfig;
710
+ /**
711
+ * Send the reasoning text of assistant messages back as `reasoning_content`
712
+ * (the DeepSeek spelling), for servers whose thinking mode requires it to be
713
+ * echoed in a tool loop. Default false. See the `reasoning_content` handling
714
+ * in the server's own documentation before enabling it.
715
+ */
716
+ replayReasoningContent?: boolean;
610
717
  };
611
718
  type BedrockProviderConfig = ProviderTransportConfig & {
612
719
  provider: "bedrock";
@@ -621,12 +728,12 @@ type BedrockProviderConfig = ProviderTransportConfig & {
621
728
  retry?: ProviderRetryConfig;
622
729
  /**
623
730
  * Insert Bedrock Converse `cachePoint` blocks at the end of the system
624
- * prompt and tools list. Only supported by models that implement Converse
625
- * prompt caching (most Anthropic Claude variants on Bedrock).
731
+ * prompt and tools list and, with the default `strategy: "auto"`, at the end
732
+ * of the last user message. Applies to Claude and Amazon Nova (Nova: no tools
733
+ * checkpoint, 5-minute only); models of families without explicit caching get
734
+ * no checkpoints. See {@link PromptCachingConfig}.
626
735
  */
627
- prompt_caching?: {
628
- enabled: boolean;
629
- };
736
+ prompt_caching?: PromptCachingConfig;
630
737
  };
631
738
  type VertexProviderConfig = ProviderTransportConfig & {
632
739
  provider: "vertex";
@@ -638,6 +745,19 @@ type VertexProviderConfig = ProviderTransportConfig & {
638
745
  defaultHeaders?: Record<string, string>;
639
746
  /** Retry policy for 429/5xx (default 3 retries, exponential backoff). */
640
747
  retry?: ProviderRetryConfig;
748
+ /**
749
+ * Prompt caching for Claude models served by Vertex (ignored for Gemini): the
750
+ * same shape and meaning as on `AnthropicProviderConfig.prompt_caching`. Off
751
+ * unless `enabled: true`. See {@link PromptCachingConfig}.
752
+ */
753
+ prompt_caching?: PromptCachingConfig;
754
+ /**
755
+ * Thinking request shape for Claude models on Vertex (ignored for Gemini):
756
+ * `auto` (default, by model id), `adaptive` or `budget`, as on
757
+ * `AnthropicProviderConfig.thinkingMode`. Spelled out here because
758
+ * `utils/reasoning.ts`, which owns `ThinkingMode`, imports from this file.
759
+ */
760
+ thinkingMode?: "auto" | "adaptive" | "budget";
641
761
  };
642
762
  type JevProviderConfig = ProviderTransportConfig & {
643
763
  provider: "jev";
@@ -657,4 +777,4 @@ declare class ProviderError extends Error {
657
777
  constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
658
778
  }
659
779
 
660
- export { type EmbeddingUsage as $, type AnthropicProviderConfig as A, type BedrockProviderConfig as B, type ChatCompletionRequest as C, type ModelRule as D, type EmbeddingRequest as E, type ModelRules as F, type ResolvedModelRule as G, type ReasoningEffort as H, type EffortMapping as I, type JevProviderConfig as J, type RuleFamily as K, type RuleSource as L, type ModelRuleLearnedEvent as M, type ReasoningStyle as N, type OpenAICompatibleProviderConfig as O, type ProviderType as P, type OffMechanism as Q, type RulePatch as R, type TemperatureRule as S, type ToolDefinition as T, type UnifiedMessage as U, type VertexProviderConfig as V, type MaxTokensParam as W, type SamplingField as X, type ParsedModelError as Y, type FinishReason as Z, type ProviderResponseFields as _, type EmbeddingResponse as a, type EmbeddingInputType as a0, type TextContent as a1, type ImageContent as a2, type FileContent as a3, type AudioContent as a4, type ToolCall as a5, type ProviderTransportConfig as a6, type ChatCompletionResponse as b, type ChatCompletionChunk as c, type OpenAIProviderConfig as d, type TokenUsage as e, type AzureProviderConfig as f, type ReasoningRequestConfig as g, type ProviderConfig as h, ProviderError as i, emptyUsage as j, MODEL_RULES as k, modelIdCandidates as l, mapReasoningEffort as m, allowsSampling as n, applyDropParams as o, effortBudget as p, mergeRulePatch as q, resolveModelRule as r, parseModelError as s, runWithModelAdjustments as t, asModelRequestError as u, MAX_ADJUSTMENTS as v, listLearnedModelRules as w, getLearnedModelRulePatch as x, rememberModelRulePatch as y, clearLearnedModelRules as z };
780
+ export { type FinishReason as $, type AnthropicProviderConfig as A, type BedrockProviderConfig as B, type ChatCompletionRequest as C, rememberModelRulePatch as D, type EmbeddingRequest as E, clearLearnedModelRules as F, type ModelRule as G, type ModelRules as H, type ResolvedModelRule as I, type JevProviderConfig as J, type ReasoningEffort as K, type EffortMapping as L, type ModelRuleLearnedEvent as M, type RuleFamily as N, type OpenAICompatibleProviderConfig as O, type ProviderType as P, type RuleSource as Q, type RulePatch as R, type ReasoningStyle as S, type ToolDefinition as T, type UnifiedMessage as U, type VertexProviderConfig as V, type OffMechanism as W, type TemperatureRule as X, type MaxTokensParam as Y, type SamplingField as Z, type ParsedModelError as _, type EmbeddingResponse as a, type ProviderResponseFields as a0, type EmbeddingUsage as a1, type EmbeddingInputType as a2, type TextContent as a3, type ImageContent as a4, type FileContent as a5, type AudioContent as a6, type ToolCall as a7, type ProviderTransportConfig as a8, type ChatCompletionResponse as b, type ChatCompletionChunk as c, type OpenAIProviderConfig as d, type ReasoningBlock as e, type TokenUsage as f, type AzureProviderConfig as g, type PromptCachingConfig as h, type ReasoningRequestConfig as i, type ProviderConfig as j, ProviderError as k, emptyUsage as l, MODEL_RULES as m, mapReasoningEffort as n, modelIdCandidates as o, allowsSampling as p, applyDropParams as q, resolveModelRule as r, effortBudget as s, mergeRulePatch as t, parseModelError as u, runWithModelAdjustments as v, asModelRequestError as w, MAX_ADJUSTMENTS as x, listLearnedModelRules as y, getLearnedModelRulePatch as z };