@node-llm/core 1.18.0 → 1.19.0

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 (183) hide show
  1. package/README.md +14 -12
  2. package/dist/agent/Agent.d.ts +17 -3
  3. package/dist/agent/Agent.d.ts.map +1 -1
  4. package/dist/agent/Agent.js +11 -0
  5. package/dist/aliases.d.ts +341 -316
  6. package/dist/aliases.d.ts.map +1 -1
  7. package/dist/aliases.js +467 -442
  8. package/dist/chat/Chat.d.ts +12 -5
  9. package/dist/chat/Chat.d.ts.map +1 -1
  10. package/dist/chat/Chat.js +45 -13
  11. package/dist/chat/ChatOptions.d.ts +17 -0
  12. package/dist/chat/ChatOptions.d.ts.map +1 -1
  13. package/dist/chat/ChatResponse.d.ts +5 -0
  14. package/dist/chat/ChatResponse.d.ts.map +1 -1
  15. package/dist/chat/ChatResponse.js +12 -4
  16. package/dist/chat/ChatStream.d.ts.map +1 -1
  17. package/dist/chat/ChatStream.js +20 -10
  18. package/dist/chat/PromptCache.d.ts +7 -0
  19. package/dist/chat/PromptCache.d.ts.map +1 -0
  20. package/dist/chat/PromptCache.js +7 -0
  21. package/dist/chat/Temperature.d.ts +7 -0
  22. package/dist/chat/Temperature.d.ts.map +1 -0
  23. package/dist/chat/Temperature.js +17 -0
  24. package/dist/chat/Tool.d.ts +26 -3
  25. package/dist/chat/Tool.d.ts.map +1 -1
  26. package/dist/chat/Tool.js +28 -2
  27. package/dist/chat/ToolCallOutcome.d.ts +12 -0
  28. package/dist/chat/ToolCallOutcome.d.ts.map +1 -1
  29. package/dist/chat/ToolCallOutcome.js +14 -0
  30. package/dist/chat/ToolResultWindow.d.ts +16 -0
  31. package/dist/chat/ToolResultWindow.d.ts.map +1 -0
  32. package/dist/chat/ToolResultWindow.js +25 -0
  33. package/dist/config.d.ts +30 -0
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/config.js +66 -30
  36. package/dist/errors/billing.d.ts +7 -0
  37. package/dist/errors/billing.d.ts.map +1 -0
  38. package/dist/errors/billing.js +24 -0
  39. package/dist/errors/index.d.ts +28 -0
  40. package/dist/errors/index.d.ts.map +1 -1
  41. package/dist/errors/index.js +32 -0
  42. package/dist/executor/Executor.d.ts.map +1 -1
  43. package/dist/executor/Executor.js +5 -3
  44. package/dist/index.d.ts +4 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1 -1
  47. package/dist/llm.d.ts +2 -1
  48. package/dist/llm.d.ts.map +1 -1
  49. package/dist/llm.js +8 -2
  50. package/dist/models/ModelRegistry.d.ts +12 -1
  51. package/dist/models/ModelRegistry.d.ts.map +1 -1
  52. package/dist/models/ModelRegistry.js +22 -2
  53. package/dist/models/models.json +11900 -4568
  54. package/dist/models/types.d.ts +14 -1
  55. package/dist/models/types.d.ts.map +1 -1
  56. package/dist/providers/Provider.d.ts +23 -1
  57. package/dist/providers/Provider.d.ts.map +1 -1
  58. package/dist/providers/anthropic/AnthropicProvider.d.ts +2 -0
  59. package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
  60. package/dist/providers/anthropic/AnthropicProvider.js +2 -0
  61. package/dist/providers/anthropic/Capabilities.d.ts +1 -0
  62. package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
  63. package/dist/providers/anthropic/Capabilities.js +3 -0
  64. package/dist/providers/anthropic/Chat.d.ts.map +1 -1
  65. package/dist/providers/anthropic/Chat.js +7 -75
  66. package/dist/providers/anthropic/Errors.d.ts.map +1 -1
  67. package/dist/providers/anthropic/Errors.js +4 -3
  68. package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
  69. package/dist/providers/anthropic/Streaming.js +4 -66
  70. package/dist/providers/anthropic/Utils.d.ts +33 -1
  71. package/dist/providers/anthropic/Utils.d.ts.map +1 -1
  72. package/dist/providers/anthropic/Utils.js +114 -0
  73. package/dist/providers/anthropic/types.d.ts +17 -3
  74. package/dist/providers/anthropic/types.d.ts.map +1 -1
  75. package/dist/providers/azure/AzureProvider.d.ts +54 -0
  76. package/dist/providers/azure/AzureProvider.d.ts.map +1 -0
  77. package/dist/providers/azure/AzureProvider.js +110 -0
  78. package/dist/providers/azure/Capabilities.d.ts +16 -0
  79. package/dist/providers/azure/Capabilities.d.ts.map +1 -0
  80. package/dist/providers/azure/Capabilities.js +36 -0
  81. package/dist/providers/azure/Embedding.d.ts +11 -0
  82. package/dist/providers/azure/Embedding.d.ts.map +1 -0
  83. package/dist/providers/azure/Embedding.js +23 -0
  84. package/dist/providers/azure/Models.d.ts +18 -0
  85. package/dist/providers/azure/Models.d.ts.map +1 -0
  86. package/dist/providers/azure/Models.js +29 -0
  87. package/dist/providers/azure/index.d.ts +5 -0
  88. package/dist/providers/azure/index.d.ts.map +1 -0
  89. package/dist/providers/azure/index.js +28 -0
  90. package/dist/providers/bedrock/BedrockProvider.d.ts.map +1 -1
  91. package/dist/providers/bedrock/BedrockProvider.js +1 -0
  92. package/dist/providers/bedrock/Capabilities.d.ts +1 -0
  93. package/dist/providers/bedrock/Capabilities.d.ts.map +1 -1
  94. package/dist/providers/bedrock/Capabilities.js +3 -0
  95. package/dist/providers/bedrock/Chat.d.ts.map +1 -1
  96. package/dist/providers/bedrock/Chat.js +6 -2
  97. package/dist/providers/bedrock/Errors.d.ts.map +1 -1
  98. package/dist/providers/bedrock/Errors.js +4 -0
  99. package/dist/providers/bedrock/Streaming.d.ts.map +1 -1
  100. package/dist/providers/bedrock/Streaming.js +4 -1
  101. package/dist/providers/deepseek/Capabilities.d.ts +1 -0
  102. package/dist/providers/deepseek/Capabilities.d.ts.map +1 -1
  103. package/dist/providers/deepseek/Capabilities.js +3 -0
  104. package/dist/providers/deepseek/Chat.d.ts.map +1 -1
  105. package/dist/providers/deepseek/Chat.js +3 -2
  106. package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -0
  107. package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
  108. package/dist/providers/deepseek/DeepSeekProvider.js +1 -0
  109. package/dist/providers/deepseek/Errors.d.ts.map +1 -1
  110. package/dist/providers/deepseek/Errors.js +5 -4
  111. package/dist/providers/gemini/Capabilities.d.ts +1 -0
  112. package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
  113. package/dist/providers/gemini/Capabilities.js +3 -0
  114. package/dist/providers/gemini/Chat.d.ts.map +1 -1
  115. package/dist/providers/gemini/Chat.js +3 -2
  116. package/dist/providers/gemini/Errors.d.ts.map +1 -1
  117. package/dist/providers/gemini/Errors.js +4 -3
  118. package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
  119. package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
  120. package/dist/providers/gemini/GeminiProvider.js +1 -0
  121. package/dist/providers/mistral/Capabilities.d.ts +1 -0
  122. package/dist/providers/mistral/Capabilities.d.ts.map +1 -1
  123. package/dist/providers/mistral/Capabilities.js +3 -0
  124. package/dist/providers/mistral/Chat.d.ts.map +1 -1
  125. package/dist/providers/mistral/Chat.js +3 -2
  126. package/dist/providers/mistral/Errors.d.ts.map +1 -1
  127. package/dist/providers/mistral/Errors.js +4 -3
  128. package/dist/providers/mistral/MistralProvider.d.ts +1 -0
  129. package/dist/providers/mistral/MistralProvider.d.ts.map +1 -1
  130. package/dist/providers/mistral/MistralProvider.js +1 -0
  131. package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
  132. package/dist/providers/ollama/OllamaProvider.js +1 -0
  133. package/dist/providers/openai/Capabilities.d.ts +6 -0
  134. package/dist/providers/openai/Capabilities.d.ts.map +1 -1
  135. package/dist/providers/openai/Capabilities.js +10 -0
  136. package/dist/providers/openai/Chat.d.ts +3 -0
  137. package/dist/providers/openai/Chat.d.ts.map +1 -1
  138. package/dist/providers/openai/Chat.js +26 -7
  139. package/dist/providers/openai/Embedding.d.ts +2 -0
  140. package/dist/providers/openai/Embedding.d.ts.map +1 -1
  141. package/dist/providers/openai/Embedding.js +8 -5
  142. package/dist/providers/openai/Errors.d.ts.map +1 -1
  143. package/dist/providers/openai/Errors.js +4 -3
  144. package/dist/providers/openai/Models.d.ts +10 -0
  145. package/dist/providers/openai/Models.d.ts.map +1 -1
  146. package/dist/providers/openai/Models.js +12 -8
  147. package/dist/providers/openai/OpenAIProvider.d.ts +11 -1
  148. package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
  149. package/dist/providers/openai/OpenAIProvider.js +36 -0
  150. package/dist/providers/openai/Responses.d.ts +30 -0
  151. package/dist/providers/openai/Responses.d.ts.map +1 -0
  152. package/dist/providers/openai/Responses.js +176 -0
  153. package/dist/providers/openai/Streaming.d.ts +2 -0
  154. package/dist/providers/openai/Streaming.d.ts.map +1 -1
  155. package/dist/providers/openai/Streaming.js +19 -5
  156. package/dist/providers/openrouter/Capabilities.d.ts +1 -0
  157. package/dist/providers/openrouter/Capabilities.d.ts.map +1 -1
  158. package/dist/providers/openrouter/Capabilities.js +3 -0
  159. package/dist/providers/openrouter/OpenRouterProvider.d.ts +1 -0
  160. package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
  161. package/dist/providers/openrouter/OpenRouterProvider.js +1 -0
  162. package/dist/providers/registry.d.ts +2 -1
  163. package/dist/providers/registry.d.ts.map +1 -1
  164. package/dist/providers/registry.js +2 -1
  165. package/dist/providers/xai/Capabilities.d.ts +1 -0
  166. package/dist/providers/xai/Capabilities.d.ts.map +1 -1
  167. package/dist/providers/xai/Capabilities.js +3 -0
  168. package/dist/providers/xai/Chat.d.ts.map +1 -1
  169. package/dist/providers/xai/Chat.js +3 -2
  170. package/dist/providers/xai/Errors.d.ts.map +1 -1
  171. package/dist/providers/xai/Errors.js +5 -2
  172. package/dist/providers/xai/XAIProvider.d.ts +1 -0
  173. package/dist/providers/xai/XAIProvider.d.ts.map +1 -1
  174. package/dist/providers/xai/XAIProvider.js +1 -0
  175. package/dist/schema/Schema.d.ts +3 -3
  176. package/dist/schema/Schema.d.ts.map +1 -1
  177. package/dist/schema/to-json-schema.d.ts +2 -2
  178. package/dist/schema/to-json-schema.d.ts.map +1 -1
  179. package/dist/schema/to-json-schema.js +3 -8
  180. package/dist/schema/zod.d.ts +32 -0
  181. package/dist/schema/zod.d.ts.map +1 -0
  182. package/dist/schema/zod.js +31 -0
  183. package/package.json +14 -15
@@ -1,11 +1,11 @@
1
1
  import { Message } from "./Message.js";
2
2
  import { ContentPart, MessageContent } from "./Content.js";
3
3
  import { ChatOptions } from "./ChatOptions.js";
4
- import { Provider, Usage, ChatChunk, ThinkingConfig, ToolChoice } from "../providers/Provider.js";
4
+ import { Provider, Usage, ChatChunk, ThinkingConfig, ThinkingEffort, ToolChoice } from "../providers/Provider.js";
5
5
  import { Stream } from "../streaming/Stream.js";
6
6
  import { ToolResolvable, ToolCall } from "./Tool.js";
7
7
  import { Schema } from "../schema/Schema.js";
8
- import { z } from "zod";
8
+ import { Zod3Schema, Zod4Schema, ZodSchema } from "../schema/zod.js";
9
9
  import { ToolExecutionModeInput } from "../constants.js";
10
10
  export interface AskOptions {
11
11
  images?: string[];
@@ -134,8 +134,9 @@ export declare class Chat<S = unknown> {
134
134
  * Enforce a specific schema for the output.
135
135
  * Can accept a Schema object or a Zod schema/JSON Schema directly.
136
136
  */
137
- withSchema<T>(schema: z.ZodType<T>): Chat<T>;
138
- withSchema<T = unknown>(schema: Schema | z.ZodType<T> | Record<string, unknown> | null): Chat<T>;
137
+ withSchema<T>(schema: Zod4Schema<T>): Chat<T>;
138
+ withSchema<T>(schema: Zod3Schema<T>): Chat<T>;
139
+ withSchema<T = unknown>(schema: Schema | ZodSchema<T> | Record<string, unknown> | null): Chat<T>;
139
140
  /**
140
141
  * Provide a prediction of the expected output to reduce latency.
141
142
  * Particularly useful for code-editing agents modifying existing text.
@@ -148,7 +149,7 @@ export declare class Chat<S = unknown> {
148
149
  /**
149
150
  * Shortcut to set thinking effort.
150
151
  */
151
- withEffort(effort: "low" | "medium" | "high" | "none"): this;
152
+ withEffort(effort: ThinkingEffort): this;
152
153
  onNewMessage(handler: () => void): this;
153
154
  onEndMessage(handler: (message: ChatResponseString) => void): this;
154
155
  onToolCall(handler: (toolCall: ToolCall) => void): this;
@@ -177,6 +178,12 @@ export declare class Chat<S = unknown> {
177
178
  * sequentially since approval is interactive).
178
179
  */
179
180
  withToolConcurrency(enabled: boolean): this;
181
+ /**
182
+ * Cache the repeated start of each request (instructions, tools and earlier turns), so a
183
+ * long conversation or agent loop pays the full input price only once. Providers that cache
184
+ * automatically, such as OpenAI and Gemini, need no change and ignore this.
185
+ */
186
+ withPromptCache(enabled?: boolean): this;
180
187
  /**
181
188
  * Hook for confirming tool execution in "confirm" mode.
182
189
  * Return true to proceed, false to cancel the specific call. When multiple
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../src/chat/Chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,WAAW,EAGX,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EAET,cAAc,EACd,UAAU,EACX,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAkB,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAEL,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAqBzB,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA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;OAEG;IAGG,GAAG,CACP,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,EAC/B,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,kBAAkB,GAAG;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;IAqf5C;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAAC,SAAS,CAAC;IAWpF;;OAEG;IACH,OAAO,CAAC,aAAa;CAoDtB"}
package/dist/chat/Chat.js CHANGED
@@ -1,18 +1,21 @@
1
+ import { windowToolResults } from "./ToolResultWindow.js";
1
2
  import { FileLoader } from "../utils/FileLoader.js";
2
3
  import { isBinaryContent, formatMultimodalContent } from "./Content.js";
3
4
  import { Executor } from "../executor/Executor.js";
4
5
  import { ChatStream } from "./ChatStream.js";
6
+ import { requestTemperature } from "./Temperature.js";
7
+ import { requestPromptCache } from "./PromptCache.js";
5
8
  import { ModelRegistry } from "../models/ModelRegistry.js";
6
9
  import { Schema } from "../schema/Schema.js";
7
10
  import { toJsonSchema } from "../schema/to-json-schema.js";
11
+ import { isZodSchema } from "../schema/zod.js";
8
12
  import { randomUUID } from "node:crypto";
9
- import { z } from "zod";
10
13
  import { config } from "../config.js";
11
- import { ToolExecutionMode, DEFAULT_MAX_CORRECTIONS } from "../constants.js";
12
- import { ConfigurationError } from "../errors/index.js";
14
+ import { ToolExecutionMode, DEFAULT_MAX_CORRECTIONS, DEFAULT_MAX_TOOL_CALLS } from "../constants.js";
15
+ import { ConfigurationError, CostLimitError, ToolCallLimitError } from "../errors/index.js";
13
16
  import { ChatValidator } from "./Validation.js";
14
17
  import { ToolHandler } from "./ToolHandler.js";
15
- import { shouldRunToolCallsConcurrently, executeToolCallOutcomes } from "./ToolCallOutcome.js";
18
+ import { shouldRunToolCallsConcurrently, executeToolCallOutcomes, toolCallLimitResults, unrunToolCallResults } from "./ToolCallOutcome.js";
16
19
  import { logger } from "../utils/logger.js";
17
20
  import { runMiddleware } from "../utils/middleware-runner.js";
18
21
  import { collectHandlers, runAllHandlers, runDirectiveHandlers, runConfirmHandlers, runChainHandlers } from "../utils/handler-stacking.js";
@@ -37,7 +40,7 @@ export class Chat {
37
40
  // like a Schema - an instance, or an object carrying `definition` - is left
38
41
  // exactly as it was.
39
42
  const rawSchema = options.schema;
40
- if (rawSchema instanceof z.ZodType ||
43
+ if (isZodSchema(rawSchema) ||
41
44
  (rawSchema &&
42
45
  typeof rawSchema === "object" &&
43
46
  !(rawSchema instanceof Schema) &&
@@ -263,7 +266,7 @@ export class Chat {
263
266
  if (schema instanceof Schema) {
264
267
  this.options.schema = schema;
265
268
  }
266
- else if (schema instanceof z.ZodType) {
269
+ else if (isZodSchema(schema)) {
267
270
  this.options.schema = Schema.fromZod("output", schema);
268
271
  }
269
272
  else {
@@ -357,6 +360,15 @@ export class Chat {
357
360
  this.options.toolConcurrency = enabled;
358
361
  return this;
359
362
  }
363
+ /**
364
+ * Cache the repeated start of each request (instructions, tools and earlier turns), so a
365
+ * long conversation or agent loop pays the full input price only once. Providers that cache
366
+ * automatically, such as OpenAI and Gemini, need no change and ignore this.
367
+ */
368
+ withPromptCache(enabled = true) {
369
+ this.options.promptCache = enabled;
370
+ return this;
371
+ }
360
372
  /**
361
373
  * Hook for confirming tool execution in "confirm" mode.
362
374
  * Return true to proceed, false to cancel the specific call. When multiple
@@ -473,9 +485,9 @@ export class Chat {
473
485
  const messagesToUse = context.messages || [];
474
486
  const executeOptions = {
475
487
  model: this.model,
476
- messages: messagesToUse,
488
+ messages: windowToolResults(messagesToUse, this.options.keepToolResults),
477
489
  tools: this.options.tools,
478
- temperature: options?.temperature ?? this.options.temperature,
490
+ temperature: requestTemperature(this.provider, this.model, options?.temperature ?? this.options.temperature),
479
491
  max_tokens: options?.maxTokens ?? this.options.maxTokens ?? config.maxTokens,
480
492
  headers: { ...this.options.headers, ...options?.headers },
481
493
  response_format: responseFormat, // Pass to provider
@@ -484,6 +496,7 @@ export class Chat {
484
496
  requestTimeout: options?.requestTimeout ?? this.options.requestTimeout ?? config.requestTimeout,
485
497
  thinking: options?.thinking ?? this.options.thinking,
486
498
  prediction: options?.prediction ?? this.options.prediction,
499
+ promptCache: requestPromptCache(this.provider, this.model, this.options.promptCache),
487
500
  signal: options?.signal,
488
501
  ...this.options.params
489
502
  };
@@ -492,7 +505,7 @@ export class Chat {
492
505
  const trackUsage = (u) => {
493
506
  if (u) {
494
507
  if (u.cost === undefined) {
495
- const withCost = ModelRegistry.calculateCost(u, this.model, this.provider.id);
508
+ const withCost = ModelRegistry.calculateCost(u, this.provider.registryModel?.(this.model) ?? this.model, this.provider.id);
496
509
  u.cost = withCost.cost;
497
510
  u.input_cost = withCost.input_cost;
498
511
  u.output_cost = withCost.output_cost;
@@ -516,9 +529,13 @@ export class Chat {
516
529
  };
517
530
  // Start generation
518
531
  await runAllHandlers(newMessageHandlers);
532
+ let requestStarted = Date.now();
519
533
  let response = await this.executor.executeChat(executeOptions);
534
+ const firstLatency = Date.now() - requestStarted;
535
+ let totalLatency = firstLatency;
520
536
  trackUsage(response.usage);
521
537
  assistantMessage = new ChatResponseString(response.content ?? "", response.usage ?? { input_tokens: 0, output_tokens: 0, total_tokens: 0 }, this.model, this.provider.id, response.thinking, response.reasoning, response.tool_calls, response.finish_reason, this.options.schema, response.metadata, response.attachments);
538
+ assistantMessage.latency = firstLatency;
522
539
  // --- Content Policy Hooks (Output - Turn 1) ---
523
540
  assistantMessage = await runChainHandlers(afterResponseHandlers, assistantMessage);
524
541
  // Add to history (temporary, might be rolled back on retry)
@@ -531,7 +548,7 @@ export class Chat {
531
548
  if (!response.tool_calls || response.tool_calls.length === 0) {
532
549
  await runAllHandlers(endMessageHandlers, assistantMessage);
533
550
  }
534
- const maxToolCalls = options?.maxToolCalls ?? this.options.maxToolCalls ?? 5;
551
+ const maxToolCalls = options?.maxToolCalls ?? this.options.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS;
535
552
  let stepCount = 0;
536
553
  let haltTriggered = false;
537
554
  // Tool Calling Loop
@@ -541,7 +558,13 @@ export class Chat {
541
558
  }
542
559
  stepCount++;
543
560
  if (stepCount > maxToolCalls) {
544
- throw new Error(`[NodeLLM] Maximum tool execution calls (${maxToolCalls}) exceeded.`);
561
+ this.messages.push(...toolCallLimitResults(this.provider, response.tool_calls, maxToolCalls));
562
+ throw new ToolCallLimitError(maxToolCalls, totalUsage);
563
+ }
564
+ const maxCost = this.options.maxCost;
565
+ if (maxCost !== undefined && (totalUsage.cost ?? 0) >= maxCost) {
566
+ this.messages.push(...unrunToolCallResults(this.provider, response.tool_calls, `the cost limit ($${maxCost}) was reached`));
567
+ throw new CostLimitError(maxCost, totalUsage);
545
568
  }
546
569
  const runConcurrently = shouldRunToolCallsConcurrently(this.options.toolConcurrency, this.options.toolExecution, response.tool_calls.length);
547
570
  const outcomes = await executeToolCallOutcomes(response.tool_calls, {
@@ -596,11 +619,14 @@ export class Chat {
596
619
  }
597
620
  if (haltTriggered)
598
621
  break;
622
+ // Content policy hooks see every request in the loop, as they do when streaming.
623
+ const followUpMessages = await runChainHandlers(beforeRequestHandlers, windowToolResults([...this.systemMessages, ...this.messages], this.options.keepToolResults));
624
+ requestStarted = Date.now();
599
625
  response = await this.executor.executeChat({
600
626
  model: this.model,
601
- messages: [...this.systemMessages, ...this.messages],
627
+ messages: followUpMessages,
602
628
  tools: this.options.tools,
603
- temperature: options?.temperature ?? this.options.temperature,
629
+ temperature: requestTemperature(this.provider, this.model, options?.temperature ?? this.options.temperature),
604
630
  max_tokens: options?.maxTokens ?? this.options.maxTokens ?? config.maxTokens,
605
631
  headers: this.options.headers,
606
632
  response_format: responseFormat,
@@ -608,11 +634,15 @@ export class Chat {
608
634
  parallel_tool_calls: this.options.toolCalls === "one" || this.options.toolCalls === 1 ? false : undefined,
609
635
  requestTimeout: options?.requestTimeout ?? this.options.requestTimeout ?? config.requestTimeout,
610
636
  prediction: options?.prediction ?? this.options.prediction,
637
+ promptCache: requestPromptCache(this.provider, this.model, this.options.promptCache),
611
638
  signal: options?.signal,
612
639
  ...this.options.params
613
640
  });
641
+ const latency = Date.now() - requestStarted;
642
+ totalLatency += latency;
614
643
  trackUsage(response.usage);
615
644
  assistantMessage = new ChatResponseString(response.content ?? "", response.usage ?? { input_tokens: 0, output_tokens: 0, total_tokens: 0 }, this.model, this.provider.id, response.thinking, response.reasoning, response.tool_calls, response.finish_reason, this.options.schema, response.metadata, response.attachments);
645
+ assistantMessage.latency = latency;
616
646
  assistantMessage = await runChainHandlers(afterResponseHandlers, assistantMessage);
617
647
  this.messages.push({
618
648
  role: "assistant",
@@ -625,6 +655,8 @@ export class Chat {
625
655
  }
626
656
  }
627
657
  finalResponse = new ChatResponseString(assistantMessage.toString() || "", totalUsage, this.model, this.provider.id, assistantMessage.thinking, assistantMessage.reasoning, response.tool_calls, assistantMessage.finish_reason, this.options.schema, assistantMessage.metadata, assistantMessage.attachments);
658
+ // What ask() returns covers every request in it, so its latency is their total.
659
+ finalResponse.latency = totalLatency;
628
660
  // 5. onResponse Hook
629
661
  const requestDirective = await runMiddleware(this.middlewares, "onResponse", context, finalResponse);
630
662
  if (requestDirective && typeof requestDirective === "object") {
@@ -38,6 +38,18 @@ export interface ChatOptions {
38
38
  assumeModelExists?: boolean;
39
39
  provider?: string;
40
40
  maxToolCalls?: number;
41
+ /**
42
+ * Sends only the most recent N tool results in full; older ones are replaced with a short
43
+ * placeholder in each request (the chat's history keeps them). Keeps long tool loops, such as
44
+ * an agent reading many pages, from resending every earlier result on every request.
45
+ */
46
+ keepToolResults?: number;
47
+ /**
48
+ * The most an ask may spend, in US dollars. A tool loop that has spent this much stops before
49
+ * its next request and throws CostLimitError. It needs the model's pricing, so it does nothing
50
+ * for models without it.
51
+ */
52
+ maxCost?: number;
41
53
  maxCorrections?: number;
42
54
  requestTimeout?: number;
43
55
  toolExecution?: ToolExecutionModeInput;
@@ -46,6 +58,11 @@ export interface ChatOptions {
46
58
  * concurrently instead of one at a time. Defaults to `config.toolConcurrency`.
47
59
  */
48
60
  toolConcurrency?: boolean;
61
+ /**
62
+ * Cache the repeated start of each request (instructions, tools and earlier turns) on providers
63
+ * that need asking to, such as Anthropic. Others cache automatically.
64
+ */
65
+ promptCache?: boolean;
49
66
  toolChoice?: ToolChoice;
50
67
  toolCalls?: "one" | "many" | number;
51
68
  onConfirmToolCall?: (toolCall: ToolCall) => Promise<boolean> | boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ChatOptions.d.ts","sourceRoot":"","sources":["../../src/chat/ChatOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtF,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,QAA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AAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACvE,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACrE,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACvF,yBAAyB,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;IACtF,uBAAuB,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACpF,uBAAuB,CAAC,EAAE,KAAK,CAC7B,CAAC,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CACrE,CAAC;CACH"}
@@ -18,6 +18,11 @@ export declare class ChatResponseString extends String {
18
18
  readonly attachments?: Attachment[] | undefined;
19
19
  private _cachedData;
20
20
  private _validationError;
21
+ /**
22
+ * How long the provider took to answer, in milliseconds: for one request in afterResponse hooks,
23
+ * and in total across an ask's requests on what ask() returns.
24
+ */
25
+ latency?: number;
21
26
  constructor(content: string, usage: Usage, model: string, provider: string, thinking?: ThinkingResult | undefined, reasoning?: string | null | undefined, tool_calls?: ToolCall[] | undefined, finish_reason?: string | null | undefined, schema?: Schema | undefined, metadata?: Record<string, unknown> | undefined, attachments?: Attachment[] | undefined);
22
27
  get finishReason(): string | null | undefined;
23
28
  get input_tokens(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"ChatResponse.d.ts","sourceRoot":"","sources":["../../src/chat/ChatResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,E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tB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAQrB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,KAAK,GAAG,IAAI,CAOlC;CACF"}
@@ -1,5 +1,5 @@
1
1
  import { extractJson } from "../utils/json.js";
2
- import { z } from "zod";
2
+ import { isZodSchema } from "../schema/zod.js";
3
3
  /**
4
4
  * Enhanced string that includes token usage metadata.
5
5
  * Behaves like a regular string but has .usage and .input_tokens etc.
@@ -17,6 +17,11 @@ export class ChatResponseString extends String {
17
17
  attachments;
18
18
  _cachedData = undefined;
19
19
  _validationError = null;
20
+ /**
21
+ * How long the provider took to answer, in milliseconds: for one request in afterResponse hooks,
22
+ * and in total across an ask's requests on what ask() returns.
23
+ */
24
+ latency;
20
25
  constructor(content, usage, model, provider, thinking, reasoning, tool_calls, finish_reason, schema, metadata, attachments) {
21
26
  super(content);
22
27
  this.usage = usage;
@@ -103,7 +108,9 @@ export class ChatResponseString extends String {
103
108
  * Return a new ChatResponseString with modified content but preserved metadata.
104
109
  */
105
110
  withContent(newContent) {
106
- return new ChatResponseString(newContent, this.usage, this.model, this.provider, this.thinking, this.reasoning, this.tool_calls, this.finish_reason, this.schema, this.metadata, this.attachments);
111
+ const changed = new ChatResponseString(newContent, this.usage, this.model, this.provider, this.thinking, this.reasoning, this.tool_calls, this.finish_reason, this.schema, this.metadata, this.attachments);
112
+ changed.latency = this.latency;
113
+ return changed;
107
114
  }
108
115
  /**
109
116
  * Attempt to extract and parse the content as JSON.
@@ -128,9 +135,10 @@ export class ChatResponseString extends String {
128
135
  if (this._validationError)
129
136
  throw this._validationError;
130
137
  const json = this.parsed;
131
- if (this.schema && this.schema.definition.schema instanceof z.ZodType) {
138
+ const schema = this.schema?.definition.schema;
139
+ if (isZodSchema(schema)) {
132
140
  try {
133
- this._cachedData = this.schema.definition.schema.parse(json);
141
+ this._cachedData = schema.parse(json);
134
142
  return this._cachedData;
135
143
  }
136
144
  catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"ChatStream.d.ts","sourceRoot":"","sources":["../../src/chat/ChatStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,WAAW,EAIZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAyB,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAqBvC;;;GAGG;AACH,qBAAa,UAAU;IAKnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAY;gBAGf,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,EAC1C,QAAQ,CAAC,EAAE,OAAO,EAAE,EACpB,cAAc,CAAC,EAAE,OAAO,EAAE;IAiC5B,IAAI,OAAO,IAAI,SAAS,OAAO,EAAE,CAEhC;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAAC,SAAS,CAAC;CAuZrF"}
1
+ {"version":3,"file":"ChatStream.d.ts","sourceRoot":"","sources":["../../src/chat/ChatStream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,WAAW,EAIZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAyB,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA6BvC;;;GAGG;AACH,qBAAa,UAAU;IAKnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAY;gBAGf,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,EAC1C,QAAQ,CAAC,EAAE,OAAO,EAAE,EACpB,cAAc,CAAC,EAAE,OAAO,EAAE;IAiC5B,IAAI,OAAO,IAAI,SAAS,OAAO,EAAE,CAEhC;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAAC,SAAS,CAAC;CAsarF"}
@@ -1,18 +1,22 @@
1
+ import { windowToolResults } from "./ToolResultWindow.js";
1
2
  import { isBinaryContent, formatMultimodalContent } from "./Content.js";
2
3
  import { ChatResponseString } from "./ChatResponse.js";
3
4
  import { Stream } from "../streaming/Stream.js";
4
5
  import { config } from "../config.js";
5
- import { ToolExecutionMode } from "../constants.js";
6
+ import { ToolExecutionMode, DEFAULT_MAX_TOOL_CALLS } from "../constants.js";
6
7
  import { FileLoader } from "../utils/FileLoader.js";
7
8
  import { toJsonSchema } from "../schema/to-json-schema.js";
8
9
  import { ChatValidator } from "./Validation.js";
9
10
  import { ToolHandler } from "./ToolHandler.js";
10
11
  import { logger } from "../utils/logger.js";
12
+ import { CostLimitError, ToolCallLimitError } from "../errors/index.js";
11
13
  import { ModelRegistry } from "../models/ModelRegistry.js";
12
14
  import { runMiddleware } from "../utils/middleware-runner.js";
13
15
  import { randomUUID } from "node:crypto";
14
- import { shouldRunToolCallsConcurrently, executeToolCallOutcomes } from "./ToolCallOutcome.js";
16
+ import { shouldRunToolCallsConcurrently, executeToolCallOutcomes, toolCallLimitResults, unrunToolCallResults } from "./ToolCallOutcome.js";
15
17
  import { collectHandlers, runAllHandlers, runDirectiveHandlers, runConfirmHandlers, runChainHandlers } from "../utils/handler-stacking.js";
18
+ import { requestTemperature } from "./Temperature.js";
19
+ import { requestPromptCache } from "./PromptCache.js";
16
20
  /**
17
21
  * Internal handler for chat streaming logic.
18
22
  * Wraps the provider's stream with side effects like history updates and events.
@@ -129,14 +133,14 @@ export class ChatStream {
129
133
  };
130
134
  }
131
135
  let isFirst = true;
132
- const maxToolCalls = options.maxToolCalls ?? 5;
136
+ const maxToolCalls = options.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS;
133
137
  let stepCount = 0;
134
138
  const totalUsage = { input_tokens: 0, output_tokens: 0, total_tokens: 0 };
135
139
  const trackUsage = (u) => {
136
140
  if (u) {
137
141
  // Fallback cost calculation if provider didn't return it
138
142
  if (u.cost === undefined) {
139
- const withCost = ModelRegistry.calculateCost(u, model, provider.id);
143
+ const withCost = ModelRegistry.calculateCost(u, provider.registryModel?.(model) ?? model, provider.id);
140
144
  u.cost = withCost.cost;
141
145
  u.input_cost = withCost.input_cost;
142
146
  u.output_cost = withCost.output_cost;
@@ -154,23 +158,19 @@ export class ChatStream {
154
158
  };
155
159
  let assistantResponse;
156
160
  while (true) {
157
- stepCount++;
158
- if (stepCount > maxToolCalls) {
159
- throw new Error(`[NodeLLM] Maximum tool execution calls (${maxToolCalls}) exceeded during streaming.`);
160
- }
161
161
  let fullContent = "";
162
162
  let fullReasoning = "";
163
163
  const thinking = { text: "" };
164
164
  let toolCalls;
165
165
  let currentTurnUsage;
166
166
  context.messages = [...systemMessages, ...messages];
167
- let requestMessages = context.messages; // Use up-to-date messages from context
167
+ let requestMessages = windowToolResults(context.messages, options.keepToolResults);
168
168
  requestMessages = await runChainHandlers(beforeRequestHandlers, requestMessages);
169
169
  const streamRequest = {
170
170
  model,
171
171
  messages: requestMessages,
172
172
  tools: options.tools,
173
- temperature: options.temperature,
173
+ temperature: requestTemperature(provider, model, options.temperature),
174
174
  max_tokens: options.maxTokens ?? config.maxTokens,
175
175
  response_format: responseFormat,
176
176
  headers: options.headers,
@@ -179,6 +179,7 @@ export class ChatStream {
179
179
  requestTimeout: options.requestTimeout ?? config.requestTimeout,
180
180
  thinking: options.thinking,
181
181
  prediction: options.prediction,
182
+ promptCache: requestPromptCache(provider, model, options.promptCache),
182
183
  signal: abortController.signal,
183
184
  ...options.params
184
185
  };
@@ -235,6 +236,15 @@ export class ChatStream {
235
236
  if (!ToolHandler.shouldExecuteTools(toolCalls, options.toolExecution)) {
236
237
  break;
237
238
  }
239
+ stepCount++;
240
+ if (stepCount > maxToolCalls) {
241
+ messages.push(...toolCallLimitResults(provider, toolCalls, maxToolCalls));
242
+ throw new ToolCallLimitError(maxToolCalls, totalUsage);
243
+ }
244
+ if (options.maxCost !== undefined && (totalUsage.cost ?? 0) >= options.maxCost) {
245
+ messages.push(...unrunToolCallResults(provider, toolCalls, `the cost limit ($${options.maxCost}) was reached`));
246
+ throw new CostLimitError(options.maxCost, totalUsage);
247
+ }
238
248
  const runConcurrently = shouldRunToolCallsConcurrently(options.toolConcurrency, options.toolExecution, toolCalls.length);
239
249
  const outcomes = await executeToolCallOutcomes(toolCalls, {
240
250
  ...options,
@@ -0,0 +1,7 @@
1
+ import { Provider } from "../providers/Provider.js";
2
+ /**
3
+ * Whether to ask the provider to cache the request. Only providers that declare
4
+ * `supportsPromptCaching` get the flag, so it never reaches another provider's request body.
5
+ */
6
+ export declare function requestPromptCache(provider: Provider, model: string, enabled: boolean | undefined): true | undefined;
7
+ //# sourceMappingURL=PromptCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromptCache.d.ts","sourceRoot":"","sources":["../../src/chat/PromptCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GAAG,SAAS,GAC3B,IAAI,GAAG,SAAS,CAElB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether to ask the provider to cache the request. Only providers that declare
3
+ * `supportsPromptCaching` get the flag, so it never reaches another provider's request body.
4
+ */
5
+ export function requestPromptCache(provider, model, enabled) {
6
+ return enabled && provider.capabilities?.supportsPromptCaching?.(model) ? true : undefined;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { Provider } from "../providers/Provider.js";
2
+ /**
3
+ * The temperature to send. Models that reject one (such as Claude Opus 4.7 and later) get none,
4
+ * so a chat or agent configured with a temperature keeps working when it moves to them.
5
+ */
6
+ export declare function requestTemperature(provider: Provider, model: string, temperature: number | undefined): number | undefined;
7
+ //# sourceMappingURL=Temperature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Temperature.d.ts","sourceRoot":"","sources":["../../src/chat/Temperature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKpD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CASpB"}
@@ -0,0 +1,17 @@
1
+ import { logger } from "../utils/logger.js";
2
+ const warnedModels = new Set();
3
+ /**
4
+ * The temperature to send. Models that reject one (such as Claude Opus 4.7 and later) get none,
5
+ * so a chat or agent configured with a temperature keeps working when it moves to them.
6
+ */
7
+ export function requestTemperature(provider, model, temperature) {
8
+ if (temperature === undefined)
9
+ return undefined;
10
+ if (provider.capabilities?.supportsTemperature?.(model) !== false)
11
+ return temperature;
12
+ if (!warnedModels.has(model)) {
13
+ warnedModels.add(model);
14
+ logger.warn(`Model ${model} does not accept a temperature; sending the request without it.`);
15
+ }
16
+ return undefined;
17
+ }
@@ -1,4 +1,5 @@
1
- import { z } from "zod";
1
+ import { z } from "zod/v3";
2
+ import { Zod3Schema, Zod4Schema, ZodSchema } from "../schema/zod.js";
2
3
  export interface ToolCall {
3
4
  id: string;
4
5
  type: "function";
@@ -83,9 +84,9 @@ export declare abstract class Tool<T = Record<string, any>> {
83
84
  abstract description: string;
84
85
  /**
85
86
  * Parameters the tool accepts.
86
- * Can be a Zod object (for auto-schema + type safety) or a raw JSON Schema.
87
+ * Can be a Zod 4 or Zod 3 object (for auto-schema + type safety) or a raw JSON Schema.
87
88
  */
88
- abstract schema: z.ZodObject<z.ZodRawShape> | Record<string, unknown>;
89
+ abstract schema: Zod4Schema | Zod3Schema | z.ZodObject<z.ZodRawShape> | Record<string, unknown>;
89
90
  /**
90
91
  * Whether to enforce strict JSON schema constraints for OpenAI and similar providers.
91
92
  * When true, additionalProperties: false and full required arrays are automatically applied.
@@ -123,4 +124,26 @@ export declare abstract class Tool<T = Record<string, any>> {
123
124
  */
124
125
  toLLMTool(): ToolDefinition;
125
126
  }
127
+ /**
128
+ * Defines a tool without a class, mirroring `defineAgent`. `execute` receives arguments typed
129
+ * from the Zod schema; return `new ToolHalt(message)` from it to end the turn.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const WeatherTool = defineTool({
134
+ * name: "get_weather",
135
+ * description: "Get the current weather for a location",
136
+ * schema: z.object({ location: z.string() }),
137
+ * execute: async ({ location }) => `Sunny in ${location}`
138
+ * });
139
+ * chat.withTool(WeatherTool);
140
+ * ```
141
+ */
142
+ export declare function defineTool<Args extends Record<string, unknown>>(definition: {
143
+ name: string;
144
+ description: string;
145
+ schema: ZodSchema<Args>;
146
+ strict?: boolean;
147
+ execute: (args: Args) => unknown;
148
+ }): new () => Tool<Args>;
126
149
  //# sourceMappingURL=Tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../../src/chat/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,C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AG,UAAU,IAAI,CAAC,IAAI,CAAC,CAWvB"}
package/dist/chat/Tool.js CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { isZodSchema } from "../schema/zod.js";
2
2
  import { toJsonSchema } from "../schema/to-json-schema.js";
3
3
  /**
4
4
  * Stops the agentic tool execution loop and returns the content as the final response.
@@ -85,7 +85,7 @@ export class Tool {
85
85
  try {
86
86
  // 1. Runtime validation if Zod schema is provided
87
87
  let validatedArgs = args;
88
- if (this.schema instanceof z.ZodType) {
88
+ if (isZodSchema(this.schema)) {
89
89
  try {
90
90
  validatedArgs = this.schema.parse(args);
91
91
  }
@@ -132,3 +132,29 @@ export class Tool {
132
132
  };
133
133
  }
134
134
  }
135
+ /**
136
+ * Defines a tool without a class, mirroring `defineAgent`. `execute` receives arguments typed
137
+ * from the Zod schema; return `new ToolHalt(message)` from it to end the turn.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const WeatherTool = defineTool({
142
+ * name: "get_weather",
143
+ * description: "Get the current weather for a location",
144
+ * schema: z.object({ location: z.string() }),
145
+ * execute: async ({ location }) => `Sunny in ${location}`
146
+ * });
147
+ * chat.withTool(WeatherTool);
148
+ * ```
149
+ */
150
+ export function defineTool(definition) {
151
+ return class extends Tool {
152
+ name = definition.name;
153
+ description = definition.description;
154
+ schema = definition.schema;
155
+ strict = definition.strict;
156
+ async execute(args) {
157
+ return definition.execute(args);
158
+ }
159
+ };
160
+ }
@@ -2,6 +2,8 @@ import { ToolCall, ToolDefinition } from "./Tool.js";
2
2
  import { ToolExecutionModeInput } from "../constants.js";
3
3
  import { ToolExecutionResult } from "./ToolHandler.js";
4
4
  import { Middleware, MiddlewareContext } from "../types/Middleware.js";
5
+ import { Provider } from "../providers/Provider.js";
6
+ import { Message } from "./Message.js";
5
7
  export type ToolCallOutcome = {
6
8
  kind: "cancelled";
7
9
  toolCall: ToolCall;
@@ -27,4 +29,14 @@ export interface ToolCallExecutionOptions {
27
29
  */
28
30
  export declare function shouldRunToolCallsConcurrently(toolConcurrency: boolean | undefined, toolExecution: ToolExecutionModeInput | undefined, callCount: number): boolean;
29
31
  export declare function executeToolCallOutcomes(toolCalls: ToolCall[], options: ToolCallExecutionOptions, middlewares: Middleware[], context: MiddlewareContext, concurrent: boolean): Promise<ToolCallOutcome[]>;
32
+ /**
33
+ * Error results for the tool calls a chat stopped before running because it reached
34
+ * `maxToolCalls`, so its history stays valid for the next request.
35
+ */
36
+ export declare function toolCallLimitResults(provider: Provider, toolCalls: ToolCall[], limit: number): Message[];
37
+ /**
38
+ * Answers tool calls a loop stopped before running, so the history stays valid for the next ask:
39
+ * every tool call a model makes needs a result.
40
+ */
41
+ export declare function unrunToolCallResults(provider: Provider, toolCalls: ToolCall[], reason: string): Message[];
30
42
  //# sourceMappingURL=ToolCallOutcome.d.ts.map