@memberjunction/ai-gemini 6.2.0-edge.4 → 6.2.0-edge.6

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.
package/dist/index.d.ts CHANGED
@@ -17,7 +17,6 @@ export declare class GeminiLLM extends BaseLLM {
17
17
  private _geminiPromise;
18
18
  private _streamingState;
19
19
  private _cacheDiagContext;
20
- private _streamingCancellationToken;
21
20
  constructor(apiKey: string);
22
21
  /**
23
22
  * Factory method to create the GoogleGenAI client instance
@@ -40,31 +39,6 @@ export declare class GeminiLLM extends BaseLLM {
40
39
  * Note: This is async now because the client may not be initialized yet
41
40
  */
42
41
  get GeminiClient(): GoogleGenAI;
43
- /**
44
- * Convert MJ effort level (1-100) to Gemini thinkingBudget (0-24576)
45
- *
46
- * Mapping strategy:
47
- * - 1 (minimal): 0 (disabled) on Flash; clamped to ~1024 on Pro
48
- * - 2-33 (low): 1024-4096 tokens
49
- * - 34-66 (medium): 4097-12288 tokens
50
- * - 67-100 (high): 12289-24576 tokens
51
- * - undefined: No thinkingConfig (Gemini default ~8192)
52
- *
53
- * Model-specific behavior:
54
- * - Gemini 2.5 Flash/Flash-Lite: Can disable thinking with budget=0
55
- * - Gemini 2.5 Pro: Cannot disable thinking, minimum ~1024
56
- * - Gemini 3 models: Use thinkingLevel instead (future consideration)
57
- *
58
- * @param effortLevel - MJ normalized effort level (1-100) as string or number
59
- * @param modelName - The Gemini model name to check capabilities
60
- * @returns thinkingBudget value or undefined for default behavior
61
- */
62
- private getThinkingBudget;
63
- /**
64
- * Check if a model supports thinking configuration
65
- * Thinking is supported on Gemini 2.5+ models
66
- */
67
- private supportsThinking;
68
42
  /**
69
43
  * Gemini supports streaming
70
44
  */
@@ -79,11 +53,6 @@ export declare class GeminiLLM extends BaseLLM {
79
53
  * Implementation of non-streaming chat completion for Gemini
80
54
  */
81
55
  protected nonStreamingChatCompletion(params: ChatParams): Promise<ChatResult>;
82
- /**
83
- * Attach the caller's cancellation token to a Gemini per-request config. @google/genai reads
84
- * `GenerateContentConfig.abortSignal` and forwards it to the underlying `fetch` call, so an
85
- * abort tears down the HTTP socket instead of merely abandoning the promise.
86
- */
87
56
  /**
88
57
  * Maps the neutral {@link ChatParams.tools} onto Gemini's `tools` / `toolConfig` request fields.
89
58
  *
@@ -109,6 +78,12 @@ export declare class GeminiLLM extends BaseLLM {
109
78
  protected get ThoughtSignatureEndpoint(): string;
110
79
  /** Endpoint plus model — the scope a thought signature validates in. */
111
80
  protected thoughtSignatureOrigin(modelName: string): string;
81
+ /**
82
+ * The normalized finish reason for a tool call Gemini rejected — `MALFORMED_FUNCTION_CALL` (the
83
+ * call could not be read) or `UNEXPECTED_TOOL_CALL` (a call to a tool the request did not offer)
84
+ * — or undefined for any other finish reason.
85
+ */
86
+ private static rejectedToolCallReason;
112
87
  /**
113
88
  * Pulls `functionCall` parts out of a Gemini candidate and normalizes them.
114
89
  *
@@ -121,21 +96,65 @@ export declare class GeminiLLM extends BaseLLM {
121
96
  * @returns The normalized calls, or undefined when the model called nothing
122
97
  */
123
98
  private extractToolCalls;
99
+ /**
100
+ * Attach the caller's cancellation token to a Gemini per-request config. @google/genai reads
101
+ * `GenerateContentConfig.abortSignal` and forwards it to the underlying `fetch` call, so an
102
+ * abort tears down the HTTP socket instead of merely abandoning the promise.
103
+ */
124
104
  private applyCancellationToken;
125
- /** Throw immediately (before any socket is opened) when the caller has already cancelled. */
126
- private throwIfCancelled;
127
- /** The canonical abort error we raise for a pre-aborted request, shaped like fetch's own. */
128
- private createCancellationError;
129
- /** True when this failure is the caller's cancellation rather than a provider/network fault. */
130
- private isCancelled;
131
- /** Human-readable reason for a cancellation, preferring the signal's own reason when present. */
132
- private describeCancellation;
133
105
  /**
134
- * Build the typed ChatResult for a cancelled request. Reported as a normal failed ChatResult —
135
- * same shape as every other Gemini error path — never as an unhandled rejection.
106
+ * Model + field pairs already warned about, so a prompt that sets `temperature` on every call
107
+ * logs once per process instead of once per request.
136
108
  */
137
- private buildCancelledResult;
138
- private setThinkingConfig;
109
+ private static readonly _warnedUnsupportedSampling;
110
+ /**
111
+ * Builds the per-request generation options: sampling, stop sequences, seed, response format.
112
+ *
113
+ * Sampling fields depend on the model's version. Models before Gemini 3.6 keep the original
114
+ * shape (`temperature` defaulting to 0.5, `topP`, `topK`) because they still honor it. Every
115
+ * other model gets none of the three: Google ignores them since Gemini 3.6 Flash and upcoming
116
+ * models reject them with a 400, so a caller-supplied value is dropped with a one-time warning.
117
+ *
118
+ * A `ModelSpecific` response format is merged in after this gate, so it can still set these
119
+ * fields explicitly; that is the caller's deliberate override.
120
+ */
121
+ private buildGenerationOptions;
122
+ private warnUnsupportedSampling;
123
+ /**
124
+ * Thinking settings a model rejected in this process, mapped to what was sent instead (`null`
125
+ * for no setting). Keyed by driver, model and setting, so a rejected `MINIMAL` does not stop
126
+ * `HIGH` being sent, and a rejection through one driver does not affect another.
127
+ */
128
+ private static readonly _thinkingReplacements;
129
+ /** Thinking warnings already logged, so each is logged once per process. */
130
+ private static readonly _warnedThinking;
131
+ private thinkingReplacementKey;
132
+ /**
133
+ * Puts the `thinkingConfig` for `effortLevel` on the request (see {@link ResolveGeminiThinkingConfig}),
134
+ * or what replaced it after the model rejected it earlier in this process. Nothing is added when
135
+ * no effort is set; an effort that cannot be used is reported once.
136
+ */
137
+ private applyThinkingConfig;
138
+ /**
139
+ * Sends a request, and when it carried a thinking setting and Google answered 400, sends it once
140
+ * more with the setting's fallback (see {@link GeminiThinkingFallback}: `LOW` for a rejected
141
+ * `MINIMAL`, otherwise none). Which levels a model accepts varies (Gemini 3.8 Flash rejects
142
+ * `MINIMAL`), so an unsupported level must not fail the request. When the retry succeeds, the
143
+ * rejected setting is replaced for this driver and model for the rest of the process; when it also
144
+ * fails, the 400 had another cause, so the original error is thrown and nothing is remembered.
145
+ */
146
+ private sendWithThinkingFallback;
147
+ private warnThinkingOnce;
148
+ /**
149
+ * Normalizes Gemini usage to the {@link ModelUsage} contract.
150
+ *
151
+ * - `promptTokenCount` includes cached tokens, reported separately as `cachedContentTokenCount`,
152
+ * so the cached count is subtracted (clamped at 0) and recorded as `cacheReadTokens`. Gemini
153
+ * reports no separate cache-write charge.
154
+ * - `candidatesTokenCount` leaves out thinking, which Google counts in `thoughtsTokenCount` and
155
+ * bills as output, so completion tokens are the sum of the two.
156
+ */
157
+ private static usageFromMetadata;
139
158
  /**
140
159
  * Reset streaming state for a new request
141
160
  */
@@ -210,6 +229,28 @@ export declare class GeminiLLM extends BaseLLM {
210
229
  * otherwise the documented placeholder. A signature with no recorded origin is replayed as-is.
211
230
  */
212
231
  private static signatureForReplay;
232
+ /**
233
+ * A turn's thought parts and signed text parts, as replayable reasoning.
234
+ *
235
+ * Thought parts are kept with their signature when they have one. Text parts are kept only when
236
+ * at least one of them is signed, and then all of them, in order — the replay rebuilds the
237
+ * turn's text from these blocks, so each signature lands back on the text it was minted for.
238
+ * Function-call signatures travel on the calls themselves (see {@link extractToolCalls}).
239
+ *
240
+ * @param parts The candidate's content parts
241
+ * @param signatureOrigin Where this response's signatures validate (see {@link thoughtSignatureOrigin})
242
+ * @returns The blocks, or undefined when the turn had nothing to replay
243
+ */
244
+ private static extractReasoning;
245
+ /**
246
+ * The parts that replay a model turn's own reasoning: its thought parts, and — when its text
247
+ * parts were signed and the message text is still exactly theirs — those text parts with their
248
+ * signatures. `text` is undefined when the message's content should be mapped as usual: no
249
+ * signed text, or text that was changed after the turn (compaction), which a signature would
250
+ * no longer match. Blocks from another provider, or signed where this request is not going,
251
+ * are dropped — a foreign signature is a hard 400.
252
+ */
253
+ private static reasoningPartsForReplay;
213
254
  /**
214
255
  * Maps one MJ message to a Gemini history entry.
215
256
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAA6F,MAAM,eAAe,CAAC;AAGtJ,OAAO,EAAE,OAAO,EAAE,WAA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