@genesislcap/foundation-ai 14.455.0 → 14.455.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.
@@ -5,9 +5,10 @@ export { GeminiProvider } from './providers/gemini-provider';
5
5
  export { AnthropicTransport } from './transports/anthropic-transport';
6
6
  export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
7
7
  export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
8
+ export { ChatTemperature } from './utils/temperature';
8
9
  export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS } from './types';
9
10
  export type { AIConfig, AIStatus, AIProviderType, AnthropicAIConfig, AnthropicModelId, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId, ServerAIConfig, } from './types';
10
- export type { AgentPickerMode, ChatAgentConfig, ChatAgentPickerConfig, ChatAnimationsConfig, ChatAttachment, ChatConfig, ChatDriverResult, ChatInputDuringExecutionMode, ChatMessage, ChatInteraction, ChatRequestOptions, ChatRole, ChatStreamChunk, ChatToolCall, ChatToolCallUnknown, ChatToolDefinition, ChatToolHandlers, ChatToolResult, ChatUiConfig, ChatSuggestionsConfig, InteractionRequestOptions, InteractionResult, SubAgentFailureReason, SubAgentRequestOptions, } from './types/chat.types';
11
+ export type { AgentPickerMode, ChatAgentConfig, ChatAgentPickerConfig, ChatAnimationsConfig, ChatAttachment, ChatConfig, ChatDriverResult, ChatInputDuringExecutionMode, ChatMessage, ChatInteraction, ChatRequestOptions, ChatResponseMeta, ChatRole, ChatStreamChunk, ChatToolCall, ChatToolCallUnknown, ChatToolChoice, ChatToolDefinition, ChatToolHandlers, ChatToolResult, ChatUiConfig, ChatSuggestionsConfig, InteractionRequestOptions, InteractionResult, SubAgentFailureReason, SubAgentRequestOptions, } from './types/chat.types';
11
12
  export { isChatToolCallUnknown } from './types/chat.types';
12
13
  export type { ChatTransport } from './types/chat-transport.types';
13
14
  export type { CostReportingTransport } from './types/transports.types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AACpF,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CA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,EAC5B,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/anthropic-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAEV,WAAW,EACX,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAoD7B,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,cAAc,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AE,wBAA6B;IAmBjD,SAAS,IAAI;QAAE,QAAQ,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,gBAAgB,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE;IAQrF,iGAAiG;IACjG,eAAe,IAAI,MAAM;IAIzB,oFAAoF;IACpF,iBAAiB,IAAI,IAAI;IAMnB,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgDvE,eAAe,CACnB,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC;IA2CvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAa;IACvD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAEhD;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA0BrB;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;IAkE3B,OAAO,CAAC,qBAAqB;IAkD7B,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAK;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAIxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;CA8DnB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A tool call recovered from a malformed `finishMessage`: the tool name plus
3
+ * its decoded keyword arguments. The transport stamps an id and wraps it in a
4
+ * `ChatMessage` exactly as it would a well-formed call.
5
+ */
6
+ export interface ParsedFunctionCall {
7
+ name: string;
8
+ args: Record<string, unknown>;
9
+ }
10
+ /**
11
+ * Attempts to recover a structured tool call from a Gemini
12
+ * `MALFORMED_FUNCTION_CALL` `finishMessage`. Returns the parsed call only when
13
+ * it parses cleanly AND its tool name is one of the offered tools; otherwise
14
+ * returns null so the caller can fall back to the existing retry path.
15
+ */
16
+ export declare function repairMalformedFunctionCall(finishMessage: string | undefined, offeredToolNames: ReadonlySet<string>): ParsedFunctionCall | null;
17
+ //# sourceMappingURL=gemini-malformed-call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-malformed-call.d.ts","sourceRoot":"","sources":["../../../src/transports/gemini-malformed-call.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AA+MD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,GACpC,kBAAkB,GAAG,IAAI,CAU3B"}
@@ -74,6 +74,16 @@ export declare class GeminiTransport implements AITransport, ChatTransport, Cost
74
74
  private logTokenUsage;
75
75
  private toGeminiContents;
76
76
  private fromGeminiResponse;
77
+ /**
78
+ * Log the full shape of a blank or non-STOP response so its cause is legible
79
+ * without re-deriving it: a thinking-only STOP (substantial `thoughtsTokenCount`,
80
+ * ~0 `candidatesTokenCount`) vs a content block (`SAFETY` / `RECITATION`) vs a
81
+ * token cap (`MAX_TOKENS`) vs a prompt-level block (top-level
82
+ * `promptFeedback.blockReason`). On 2.5 Pro — which always thinks — a blank
83
+ * STOP carrying substantial thought tokens is the "thought, then stopped
84
+ * without answering" signature.
85
+ */
86
+ private logAbnormalResponse;
77
87
  private buildEndpoint;
78
88
  private static readonly MAX_RETRIES;
79
89
  private static readonly RATE_LIMIT_STATUS;
@@ -1 +1 @@
1
- {"version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BrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAK;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAGxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;IA+DlB,OAAO,CAAC,eAAe;CAexB"}
@@ -150,6 +150,44 @@ export interface ChatMessage {
150
150
  * cost without re-deriving rates.
151
151
  */
152
152
  cost?: number;
153
+ /**
154
+ * Provider diagnostic for the request that produced this message — the raw
155
+ * finish reason plus, where the provider reports them, the reasoning-token
156
+ * count and a parts breakdown. Set by transports that expose it (Gemini); the
157
+ * driver folds it into the debug-log meta events (e.g. an empty-response
158
+ * `turn.retry`/`turn.error`) so a blank or truncated turn's cause is legible.
159
+ * Not shown to the user.
160
+ */
161
+ responseMeta?: ChatResponseMeta;
162
+ }
163
+ /**
164
+ * Provider-reported diagnostic for a single chat response, surfaced so the
165
+ * driver can attribute a blank/abnormal turn without re-deriving it. All fields
166
+ * are optional — a transport sets only what its provider reports.
167
+ *
168
+ * @beta
169
+ */
170
+ export interface ChatResponseMeta {
171
+ /**
172
+ * Raw provider finish reason for the turn, verbatim — e.g. Gemini `'STOP'` |
173
+ * `'MAX_TOKENS'` | `'SAFETY'` | `'RECITATION'`. The key signal when triaging a
174
+ * blank or truncated turn.
175
+ */
176
+ finishReason?: string;
177
+ /**
178
+ * Reasoning ("thinking") tokens billed for this turn, when the provider
179
+ * reports them (Gemini 2.5). A high count alongside ~0 output tokens and a
180
+ * `'STOP'` finish is the "thought, then stopped without answering" signature.
181
+ */
182
+ thoughtsTokens?: number;
183
+ /** Count of response parts by kind — distinguishes a truly empty turn from a thinking-only one. */
184
+ parts?: {
185
+ functionCall: number;
186
+ thought: number;
187
+ text: number;
188
+ };
189
+ /** Provider block reason when the prompt/response was blocked rather than generated. */
190
+ blockReason?: string;
153
191
  }
154
192
  /**
155
193
  * JSON Schema-based tool definition for function calling.
@@ -290,6 +328,36 @@ export type ChatToolHandlers<TSubAgent extends {
290
328
  */
291
329
  releaseAgent?: () => void;
292
330
  }) => Promise<unknown>>;
331
+ /**
332
+ * Controls whether (and how) the model may call a tool on a given turn. Maps to
333
+ * each provider's "tool choice" / "function calling mode" control:
334
+ *
335
+ * - `'auto'` (the default when omitted) — the model decides whether to call a
336
+ * tool or answer with text. Anthropic leaves `tool_choice` unset; Gemini
337
+ * leaves `functionCallingConfig` unset (`AUTO`).
338
+ * - `'required'` — the model MUST call one of the available tools. Maps to
339
+ * Anthropic `tool_choice: { type: 'any' }` and Gemini
340
+ * `functionCallingConfig.mode: 'ANY'`.
341
+ * - `'none'` — the model MUST NOT call a tool (text answer only). Maps to
342
+ * Anthropic `tool_choice: { type: 'none' }` and Gemini
343
+ * `functionCallingConfig.mode: 'NONE'`.
344
+ * - `{ tool: name }` — the model MUST call exactly the named tool. Maps to
345
+ * Anthropic `tool_choice: { type: 'tool', name }` and Gemini
346
+ * `functionCallingConfig.mode: 'ANY', allowedFunctionNames: [name]`. Use this
347
+ * for surgical forcing at a single-tool juncture (e.g. force a classifier
348
+ * tool in an intake step) while leaving `'auto'` everywhere multi-step work
349
+ * happens.
350
+ *
351
+ * Forcing (`'required'` / `{ tool }`) is a no-op when no tools are advertised.
352
+ *
353
+ * NOTE: forcing is incompatible with Anthropic extended/adaptive thinking — a
354
+ * request must not enable both.
355
+ *
356
+ * @beta
357
+ */
358
+ export type ChatToolChoice = 'auto' | 'required' | 'none' | {
359
+ tool: string;
360
+ };
293
361
  /**
294
362
  * Options for a chat request.
295
363
  *
@@ -301,19 +369,29 @@ export interface ChatRequestOptions {
301
369
  attachments?: ChatAttachment[];
302
370
  signal?: AbortSignal;
303
371
  /**
304
- * Whether the model MAY call a tool (`'auto'`, the default when omitted) or
305
- * MUST call one (`'required'`). `'required'` maps to Anthropic
306
- * `tool_choice: { type: 'any' }` and Gemini
307
- * `functionCallingConfig.mode: 'ANY'`. Used by sub-agent loops so a sub-agent
308
- * can only end a turn by calling a tool (e.g. its completion tool), never by
309
- * emitting a free-text answer.
372
+ * Whether (and how) the model may call a tool this turn. Defaults to `'auto'`
373
+ * when omitted. Used by sub-agent loops (which force `'required'` so a turn
374
+ * can only end via a tool call) and configurable per agent / per agent state.
375
+ * See {@link ChatToolChoice}.
310
376
  *
311
- * NOTE: `'required'` is incompatible with Anthropic extended/adaptive
312
- * thinking — a request must not enable both.
377
+ * @beta
378
+ */
379
+ toolChoice?: ChatToolChoice;
380
+ /**
381
+ * Provider-agnostic sampling temperature, normalized to `0`–`1` and anchored
382
+ * on each provider's own default: `0` is fully deterministic, `0.5` is the
383
+ * provider's default, and `1` is the most random it allows. So `< 0.5` is
384
+ * "more focused than default" and `> 0.5` is "more random than default" on
385
+ * every provider, even though their native ranges differ (Anthropic
386
+ * `temperature` `0`–`1`, Gemini `generationConfig.temperature` `0`–`2`). Where
387
+ * a provider's default equals its max (Anthropic), the upper half is flat.
388
+ * Values outside `0`–`1` are clamped. Omit to use the provider/model default
389
+ * (equivalent to `0.5`). Prefer the `ChatTemperature` presets for common
390
+ * intents.
313
391
  *
314
392
  * @beta
315
393
  */
316
- toolChoice?: 'auto' | 'required';
394
+ temperature?: number;
317
395
  }
318
396
  /**
319
397
  * The result returned by a driver after processing a user turn.
@@ -1 +1 @@
1
- {"version":3,"file":"chat.types.d.ts","sourceRoot":"","sources":["../../../src/types/chat.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,cAAc,CAAC;AAEjF;;;;GAIG;AACH,KAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAA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K,CAAC,EAAE,KAAK,CAAC;IACd,+CAA+C;IAC/C,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACE;;;OAGG;IACH,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Translate a provider-agnostic, normalized temperature into a provider's
3
+ * native range, anchored on the provider's own default so the normalized scale
4
+ * means the same thing everywhere:
5
+ *
6
+ * - `0` → `0` (fully deterministic),
7
+ * - `0.5` → the provider's default temperature,
8
+ * - `1` → the provider's maximum.
9
+ *
10
+ * Values between the anchors interpolate linearly within each half, so `< 0.5`
11
+ * is "more focused than default" and `> 0.5` is "more random than default" on
12
+ * every provider — even though the providers' native ranges differ (Anthropic
13
+ * default/max `1`/`1`, Gemini `1`/`2`). Where a provider's default equals its
14
+ * max (Anthropic), the upper half is flat: it cannot go hotter than its default.
15
+ *
16
+ * The input is clamped to `[0, 1]` before scaling, so an out-of-range value can
17
+ * never produce a native temperature the provider would reject.
18
+ */
19
+ export declare function scaleTemperature(normalized: number, { defaultTemp, maxTemp }: {
20
+ defaultTemp: number;
21
+ maxTemp: number;
22
+ }): number;
23
+ /**
24
+ * Provider-agnostic, normalized sampling-temperature presets in `0`–`1` space —
25
+ * named handles for the values most callers actually want, so intent reads
26
+ * better than a bare magnitude. Each maps through `scaleTemperature` to the
27
+ * active provider's native range, so the same preset means the same intent
28
+ * whichever provider services the turn:
29
+ *
30
+ * - `ChatTemperature.Deterministic` (`0`) — greedy/argmax sampling.
31
+ * - `ChatTemperature.Focused` (`0.25`) — low but not greedy; precise tool calls
32
+ * and extraction work where you still want a little slack.
33
+ * - `ChatTemperature.Balanced` (`0.5`) — the provider's own default.
34
+ * - `ChatTemperature.Creative` (`0.75`) — hotter than default, short of the ceiling.
35
+ * - `ChatTemperature.Maximum` (`1`) — the hottest the active provider allows.
36
+ *
37
+ * (On a provider whose default equals its max — Anthropic — `Creative` and
38
+ * `Maximum` coincide; see `scaleTemperature`.)
39
+ *
40
+ * @beta
41
+ */
42
+ export declare const ChatTemperature: {
43
+ readonly Deterministic: 0;
44
+ readonly Focused: 0.25;
45
+ readonly Balanced: 0.5;
46
+ readonly Creative: 0.75;
47
+ readonly Maximum: 1;
48
+ };
49
+ //# sourceMappingURL=temperature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temperature.d.ts","sourceRoot":"","sources":["../../../src/utils/temperature.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjE,MAAM,CAKR;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -4,6 +4,7 @@ export { GeminiProvider } from './providers/gemini-provider';
4
4
  export { AnthropicTransport } from './transports/anthropic-transport';
5
5
  export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
6
6
  export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
7
+ export { ChatTemperature } from './utils/temperature';
7
8
  export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS } from './types';
8
9
  export { isChatToolCallUnknown } from './types/chat.types';
9
10
  export { isSpeechRecognitionAvailable, startSpeechRecognition } from './utils/speech-to-text';
@@ -2,11 +2,28 @@ import { __awaiter } from "tslib";
2
2
  import { SUPPORTED_ANTHROPIC_MODEL_IDS, } from '../types';
3
3
  import { combineSignals } from '../utils/combine-signals';
4
4
  import { logger } from '../utils/logger';
5
+ import { scaleTemperature } from '../utils/temperature';
5
6
  const ANTHROPIC_DIRECT_URL = 'https://api.anthropic.com/v1/messages';
6
7
  const ANTHROPIC_API_VERSION = '2023-06-01';
7
8
  const DEFAULT_MODEL = 'claude-haiku-4-5-20251001';
8
9
  const DEFAULT_TIMEOUT = 180000; // 3 minutes
9
10
  const DEFAULT_MAX_TOKENS = 4096;
11
+ /** Anthropic's native default + ceiling temperature — https://docs.claude.com/en/api/messages */
12
+ const ANTHROPIC_DEFAULT_TEMPERATURE = 1;
13
+ const ANTHROPIC_MAX_TEMPERATURE = 1;
14
+ /**
15
+ * Map a provider-agnostic {@link ChatToolChoice} to Anthropic's `tool_choice`.
16
+ * Returns undefined for the default (`'auto'`) so the request omits the field.
17
+ */
18
+ function toAnthropicToolChoice(choice) {
19
+ if (!choice || choice === 'auto')
20
+ return undefined;
21
+ if (choice === 'required')
22
+ return { type: 'any' };
23
+ if (choice === 'none')
24
+ return { type: 'none' };
25
+ return { type: 'tool', name: choice.tool };
26
+ }
10
27
  /**
11
28
  * Maximum input context window (tokens) per supported Claude model.
12
29
  * Source: https://docs.claude.com/en/docs/about-claude/models/overview
@@ -149,14 +166,24 @@ export class AnthropicTransport {
149
166
  input_schema: t.parameters,
150
167
  }));
151
168
  }
152
- // `toolChoice: 'required'` forces the model to call one of the provided
153
- // tools instead of answering with text used by sub-agent loops so the
154
- // turn can only end via a tool call. Only meaningful when tools exist.
169
+ // Map the requested tool-call mode to Anthropic's tool_choice only
170
+ // meaningful when tools exist. `'required'`/`{ tool }` force a tool call so
171
+ // a turn can only end via one (e.g. a sub-agent's completion tool).
155
172
  // NOTE: Anthropic rejects forced tool use when extended/adaptive thinking
156
173
  // is enabled; this transport never sets `thinking` on the chat path, so the
157
174
  // two never collide. Keep that invariant if `thinking` is ever added here.
158
- if ((options === null || options === void 0 ? void 0 : options.toolChoice) === 'required' && ((_b = body.tools) === null || _b === void 0 ? void 0 : _b.length)) {
159
- body.tool_choice = { type: 'any' };
175
+ if ((_b = body.tools) === null || _b === void 0 ? void 0 : _b.length) {
176
+ const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
177
+ if (toolChoice)
178
+ body.tool_choice = toolChoice;
179
+ }
180
+ // Normalized [0,1] temperature → Anthropic's native range, anchored so 0.5
181
+ // maps to its default. (Default == max here, so the upper half is flat.)
182
+ if ((options === null || options === void 0 ? void 0 : options.temperature) != null) {
183
+ body.temperature = scaleTemperature(options.temperature, {
184
+ defaultTemp: ANTHROPIC_DEFAULT_TEMPERATURE,
185
+ maxTemp: ANTHROPIC_MAX_TEMPERATURE,
186
+ });
160
187
  }
161
188
  const response = yield this.post(body, options === null || options === void 0 ? void 0 : options.signal);
162
189
  return this.fromAnthropicResponse(response);
@@ -0,0 +1,242 @@
1
+ // ── MALFORMED_FUNCTION_CALL repair ─────────────────────────────────────────
2
+ //
3
+ // Gemini occasionally returns `finishReason: "MALFORMED_FUNCTION_CALL"` when it
4
+ // has actually produced a complete, correct tool call but serialised it as a
5
+ // Python statement instead of the API's structured format, e.g.
6
+ //
7
+ // print(default_api.vfs_edit(new_string = "…", old_string = "…", path = "…", replace_all = true))
8
+ //
9
+ // The intended call is fully present in `candidates[0].finishMessage`. Rather
10
+ // than throw and burn a ChatDriver retry (a full re-roll that may regenerate
11
+ // something worse, or malform again), we parse the call back out and hand it to
12
+ // the transport as a normal structured tool call — unwrapping a wrong envelope,
13
+ // not guessing. The parser is deliberately fail-closed: on ANY ambiguity it
14
+ // returns null and the transport falls back to throwing
15
+ // `MalformedFunctionCallError`, leaving today's retry behaviour unchanged. It
16
+ // never returns a half-parsed call.
17
+ const MALFORMED_CALL_ANCHOR = 'default_api.';
18
+ const PRINT_WRAPPER_RE = /print\(\s*$/;
19
+ const UNICODE_ESCAPE_DIGITS = 4;
20
+ const HEX_ESCAPE_DIGITS = 2;
21
+ const HEX_RADIX = 16;
22
+ /**
23
+ * Recursive-descent scanner for a single Python-style `default_api.<tool>(...)`
24
+ * call. Walks the string character by character so that delimiters (commas,
25
+ * parens, quotes, brackets, newlines) appearing *inside* string-literal
26
+ * arguments don't prematurely terminate parsing. Throws on the first unexpected
27
+ * token; callers treat any throw as "not confidently parseable".
28
+ */
29
+ class MalformedFunctionCallParser {
30
+ constructor(src) {
31
+ this.src = src;
32
+ this.pos = 0;
33
+ }
34
+ parse() {
35
+ const anchor = this.src.indexOf(MALFORMED_CALL_ANCHOR);
36
+ if (anchor === -1)
37
+ this.bail();
38
+ // Tolerate an enclosing `print(` wrapper (the observed Python form) or a
39
+ // bare call. Any other preamble (e.g. "Malformed function call: ") is
40
+ // ignored — we only anchor on `default_api.`.
41
+ const wrapped = PRINT_WRAPPER_RE.test(this.src.slice(0, anchor));
42
+ this.pos = anchor;
43
+ const call = this.parseCall();
44
+ this.skipWhitespace();
45
+ if (wrapped) {
46
+ this.expect(')');
47
+ this.skipWhitespace();
48
+ }
49
+ // Strict: nothing may follow the call. In particular a second
50
+ // `default_api.` (batched calls) bails rather than silently dropping work.
51
+ if (this.pos !== this.src.length)
52
+ this.bail();
53
+ return call;
54
+ }
55
+ parseCall() {
56
+ this.expectLiteral(MALFORMED_CALL_ANCHOR);
57
+ const name = this.readIdentifier();
58
+ this.expect('(');
59
+ const args = this.parseKwargs();
60
+ this.expect(')');
61
+ return { name, args };
62
+ }
63
+ parseKwargs() {
64
+ const args = {};
65
+ for (;;) {
66
+ this.skipWhitespace();
67
+ // Empty arg list, or a tolerated trailing comma before the closing paren.
68
+ if (this.peek() === ')')
69
+ break;
70
+ const key = this.readIdentifier();
71
+ this.skipWhitespace();
72
+ this.expect('=');
73
+ this.skipWhitespace();
74
+ const value = this.parseValue();
75
+ if (Object.prototype.hasOwnProperty.call(args, key))
76
+ this.bail();
77
+ args[key] = value;
78
+ this.skipWhitespace();
79
+ const next = this.peek();
80
+ if (next === ',') {
81
+ this.pos += 1;
82
+ continue;
83
+ }
84
+ if (next === ')')
85
+ break;
86
+ this.bail();
87
+ }
88
+ return args;
89
+ }
90
+ parseValue() {
91
+ const ch = this.peek();
92
+ if (ch === '"' || ch === "'")
93
+ return this.readString();
94
+ if (ch === '-' || ch === '+' || this.isDigit(ch))
95
+ return this.readNumber();
96
+ if (/[A-Za-z]/.test(ch))
97
+ return this.readBareword();
98
+ // Unhandled value form (e.g. a list `[…]` or dict `{…}`) — bail.
99
+ return this.bail();
100
+ }
101
+ readString() {
102
+ const quote = this.src[this.pos];
103
+ this.pos += 1; // opening quote
104
+ let out = '';
105
+ for (;;) {
106
+ if (this.pos >= this.src.length)
107
+ this.bail(); // unterminated → truncation guard
108
+ const c = this.src[this.pos];
109
+ this.pos += 1;
110
+ if (c === quote)
111
+ return out; // closing quote
112
+ if (c === '\\') {
113
+ out += this.readEscape();
114
+ continue;
115
+ }
116
+ out += c;
117
+ }
118
+ }
119
+ readEscape() {
120
+ if (this.pos >= this.src.length)
121
+ this.bail();
122
+ const e = this.src[this.pos];
123
+ this.pos += 1;
124
+ switch (e) {
125
+ case 'n':
126
+ return '\n';
127
+ case 't':
128
+ return '\t';
129
+ case 'r':
130
+ return '\r';
131
+ case 'b':
132
+ return '\b';
133
+ case 'f':
134
+ return '\f';
135
+ case '\\':
136
+ return '\\';
137
+ case '"':
138
+ return '"';
139
+ case "'":
140
+ return "'";
141
+ case '/':
142
+ return '/';
143
+ case 'u':
144
+ return this.readHexCodepoint(UNICODE_ESCAPE_DIGITS);
145
+ case 'x':
146
+ return this.readHexCodepoint(HEX_ESCAPE_DIGITS);
147
+ default:
148
+ // Unknown escape — refuse rather than risk a silent mis-decode.
149
+ return this.bail();
150
+ }
151
+ }
152
+ readHexCodepoint(digits) {
153
+ const hex = this.src.slice(this.pos, this.pos + digits);
154
+ if (hex.length !== digits || !/^[0-9a-fA-F]+$/.test(hex))
155
+ this.bail();
156
+ this.pos += digits;
157
+ return String.fromCharCode(parseInt(hex, HEX_RADIX));
158
+ }
159
+ readNumber() {
160
+ const start = this.pos;
161
+ if (this.peek() === '-' || this.peek() === '+')
162
+ this.pos += 1;
163
+ while (this.pos < this.src.length && /[0-9.eE+-]/.test(this.src[this.pos])) {
164
+ this.pos += 1;
165
+ }
166
+ const value = Number(this.src.slice(start, this.pos));
167
+ if (!Number.isFinite(value))
168
+ this.bail();
169
+ return value;
170
+ }
171
+ readBareword() {
172
+ const word = this.readIdentifier();
173
+ switch (word) {
174
+ case 'true':
175
+ case 'True':
176
+ return true;
177
+ case 'false':
178
+ case 'False':
179
+ return false;
180
+ // Python serialises an omitted/optional kwarg as `None` (and sometimes a
181
+ // JSON-ish `null`); decode both to `null` rather than bailing the whole call.
182
+ case 'null':
183
+ case 'None':
184
+ return null;
185
+ default:
186
+ return this.bail();
187
+ }
188
+ }
189
+ readIdentifier() {
190
+ const start = this.pos;
191
+ if (!/[A-Za-z_]/.test(this.peek()))
192
+ this.bail();
193
+ while (this.pos < this.src.length && /[A-Za-z0-9_]/.test(this.src[this.pos])) {
194
+ this.pos += 1;
195
+ }
196
+ return this.src.slice(start, this.pos);
197
+ }
198
+ isDigit(ch) {
199
+ return ch >= '0' && ch <= '9';
200
+ }
201
+ peek() {
202
+ return this.pos < this.src.length ? this.src[this.pos] : '';
203
+ }
204
+ skipWhitespace() {
205
+ while (this.pos < this.src.length && /\s/.test(this.src[this.pos])) {
206
+ this.pos += 1;
207
+ }
208
+ }
209
+ expect(ch) {
210
+ if (this.src[this.pos] !== ch)
211
+ this.bail();
212
+ this.pos += 1;
213
+ }
214
+ expectLiteral(literal) {
215
+ if (this.src.slice(this.pos, this.pos + literal.length) !== literal)
216
+ this.bail();
217
+ this.pos += literal.length;
218
+ }
219
+ bail() {
220
+ throw new Error('MalformedFunctionCallParser: unexpected token');
221
+ }
222
+ }
223
+ /**
224
+ * Attempts to recover a structured tool call from a Gemini
225
+ * `MALFORMED_FUNCTION_CALL` `finishMessage`. Returns the parsed call only when
226
+ * it parses cleanly AND its tool name is one of the offered tools; otherwise
227
+ * returns null so the caller can fall back to the existing retry path.
228
+ */
229
+ export function repairMalformedFunctionCall(finishMessage, offeredToolNames) {
230
+ if (!finishMessage)
231
+ return null;
232
+ let call;
233
+ try {
234
+ call = new MalformedFunctionCallParser(finishMessage).parse();
235
+ }
236
+ catch (_a) {
237
+ return null;
238
+ }
239
+ if (!offeredToolNames.has(call.name))
240
+ return null;
241
+ return call;
242
+ }