agentfootprint 9.28.0 → 9.29.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 (73) hide show
  1. package/README.md +3 -2
  2. package/dist/adapters/hosting/googleAgentEngine.js +17 -3
  3. package/dist/adapters/hosting/googleAgentEngine.js.map +1 -1
  4. package/dist/adapters/llm/GeminiProvider.js +193 -36
  5. package/dist/adapters/llm/GeminiProvider.js.map +1 -1
  6. package/dist/adapters/llm/OpenAIProvider.js +66 -2
  7. package/dist/adapters/llm/OpenAIProvider.js.map +1 -1
  8. package/dist/adapters/llm/googleGenAI.js +155 -8
  9. package/dist/adapters/llm/googleGenAI.js.map +1 -1
  10. package/dist/adapters/memory/memoryBank.js +24 -0
  11. package/dist/adapters/memory/memoryBank.js.map +1 -1
  12. package/dist/adapters/types.js.map +1 -1
  13. package/dist/artifacts/gcsArtifacts.js +21 -5
  14. package/dist/artifacts/gcsArtifacts.js.map +1 -1
  15. package/dist/embedders/index.js +8 -6
  16. package/dist/embedders/index.js.map +1 -1
  17. package/dist/esm/adapters/hosting/googleAgentEngine.d.ts +17 -3
  18. package/dist/esm/adapters/hosting/googleAgentEngine.js +17 -3
  19. package/dist/esm/adapters/hosting/googleAgentEngine.js.map +1 -1
  20. package/dist/esm/adapters/llm/GeminiProvider.d.ts +91 -15
  21. package/dist/esm/adapters/llm/GeminiProvider.js +194 -37
  22. package/dist/esm/adapters/llm/GeminiProvider.js.map +1 -1
  23. package/dist/esm/adapters/llm/OpenAIProvider.d.ts +34 -2
  24. package/dist/esm/adapters/llm/OpenAIProvider.js +66 -2
  25. package/dist/esm/adapters/llm/OpenAIProvider.js.map +1 -1
  26. package/dist/esm/adapters/llm/googleGenAI.d.ts +105 -4
  27. package/dist/esm/adapters/llm/googleGenAI.js +152 -7
  28. package/dist/esm/adapters/llm/googleGenAI.js.map +1 -1
  29. package/dist/esm/adapters/memory/memoryBank.d.ts +24 -0
  30. package/dist/esm/adapters/memory/memoryBank.js +24 -0
  31. package/dist/esm/adapters/memory/memoryBank.js.map +1 -1
  32. package/dist/esm/adapters/types.d.ts +27 -0
  33. package/dist/esm/adapters/types.js.map +1 -1
  34. package/dist/esm/artifacts/gcsArtifacts.d.ts +21 -5
  35. package/dist/esm/artifacts/gcsArtifacts.js +21 -5
  36. package/dist/esm/artifacts/gcsArtifacts.js.map +1 -1
  37. package/dist/esm/core/agent/types.d.ts +1 -0
  38. package/dist/esm/embedders/index.js +9 -7
  39. package/dist/esm/embedders/index.js.map +1 -1
  40. package/dist/esm/events/payloads.d.ts +22 -0
  41. package/dist/esm/providers.js.map +1 -1
  42. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.js +5 -1
  43. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.js.map +1 -1
  44. package/dist/esm/recorders/observability/commentary/commentaryTemplates.js +44 -3
  45. package/dist/esm/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
  46. package/dist/providers.js.map +1 -1
  47. package/dist/recorders/observability/AgentThinkingTraceRecorder.js +5 -1
  48. package/dist/recorders/observability/AgentThinkingTraceRecorder.js.map +1 -1
  49. package/dist/recorders/observability/commentary/commentaryTemplates.js +44 -3
  50. package/dist/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
  51. package/dist/types/adapters/hosting/googleAgentEngine.d.ts +17 -3
  52. package/dist/types/adapters/hosting/googleAgentEngine.d.ts.map +1 -1
  53. package/dist/types/adapters/llm/GeminiProvider.d.ts +91 -15
  54. package/dist/types/adapters/llm/GeminiProvider.d.ts.map +1 -1
  55. package/dist/types/adapters/llm/OpenAIProvider.d.ts +34 -2
  56. package/dist/types/adapters/llm/OpenAIProvider.d.ts.map +1 -1
  57. package/dist/types/adapters/llm/googleGenAI.d.ts +105 -4
  58. package/dist/types/adapters/llm/googleGenAI.d.ts.map +1 -1
  59. package/dist/types/adapters/memory/memoryBank.d.ts +24 -0
  60. package/dist/types/adapters/memory/memoryBank.d.ts.map +1 -1
  61. package/dist/types/adapters/types.d.ts +27 -0
  62. package/dist/types/adapters/types.d.ts.map +1 -1
  63. package/dist/types/artifacts/gcsArtifacts.d.ts +21 -5
  64. package/dist/types/artifacts/gcsArtifacts.d.ts.map +1 -1
  65. package/dist/types/core/agent/types.d.ts +1 -0
  66. package/dist/types/core/agent/types.d.ts.map +1 -1
  67. package/dist/types/embedders/index.d.ts.map +1 -1
  68. package/dist/types/events/payloads.d.ts +22 -0
  69. package/dist/types/events/payloads.d.ts.map +1 -1
  70. package/dist/types/providers.d.ts.map +1 -1
  71. package/dist/types/recorders/observability/AgentThinkingTraceRecorder.d.ts.map +1 -1
  72. package/dist/types/recorders/observability/commentary/commentaryTemplates.d.ts.map +1 -1
  73. package/package.json +1 -1
@@ -26,18 +26,72 @@
26
26
  * the first call, which reads like a network problem rather than a missing
27
27
  * setting.
28
28
  *
29
+ * ─── Status, per door, because the doors differ ─────────────────────
30
+ *
31
+ * • **Vertex: field-validated.** An independent trial ran this adapter,
32
+ * unchanged since 9.13.0, against a live project through Application Default
33
+ * Credentials: a two-call tool loop on `gemini-2.5-flash` returning the
34
+ * expected answer with real token counts, and a stream delivering 10 content
35
+ * chunks that reconstructed exactly (FINDINGS "Part 1 — native Gemini on
36
+ * Vertex through ADC", "Part 2C"). `geminiEmbedder` passed on the same door.
37
+ * • **Gemini API (AI Studio): NOT field-validated, and not for want of
38
+ * trying.** The trial's key-door calls never reached a model: the old
39
+ * default model answered 404 for a new account, and a current model answered
40
+ * 429 for AI Studio prepayment, which is billing SEPARATE from the Google
41
+ * Cloud account's credit. What that door does with a funded key is
42
+ * untested here, which is why it has no default model.
43
+ * • **Tool calling on a 3.x model** now round-trips thought signatures (below).
44
+ * That fix is built from the trial's captured 400, not from a live green run
45
+ * — nothing in this repository has yet completed a 3.x tool loop.
46
+ *
29
47
  * ─── Why native, and not `openai({ baseURL })` ──────────────────────
30
48
  *
31
49
  * Google publishes an OpenAI-compatible endpoint, and it does work — for about
32
- * an hour. It authenticates with an OAuth access token that expires and has no
33
- * refresh home in `OpenAIProviderOptions`; its `tools.function.parameters` is
34
- * **OpenAPI**, not JSON Schema, so `$ref` / `oneOf` / `additionalProperties`
35
- * diverge silently; unsupported parameters are ignored rather than refused; and
36
- * its documented response carries no cached- or reasoning-token counts. This
37
- * adapter exists because every one of those is answerable on the native SDK:
38
- * ADC refreshes itself, tools go over as JSON Schema untranslated
39
- * (`parametersJsonSchema`), a forced single tool is expressible, and
40
- * `usageMetadata` reports cached and thinking tokens as separate numbers.
50
+ * an hour. It authenticates with an OAuth access token that expires (9.29.0
51
+ * gives `openai({ apiKey })` a callback form so a long-running process can
52
+ * refresh one, which is a mitigation and not a fix); its
53
+ * `tools.function.parameters` is **OpenAPI**, not JSON Schema, so `$ref` /
54
+ * `oneOf` / `additionalProperties` diverge silently; unsupported parameters are
55
+ * ignored rather than refused; and its documented response carries no cached-
56
+ * or reasoning-token counts. This adapter exists because every one of those is
57
+ * answerable on the native SDK: ADC refreshes itself, tools go over as JSON
58
+ * Schema untranslated (`parametersJsonSchema`), a forced single tool is
59
+ * expressible, and `usageMetadata` reports cached and thinking tokens as
60
+ * separate numbers.
61
+ *
62
+ * A field trial measured both halves of that: the native path completed a call
63
+ * after a forced credential expiry, while the compatible path returned HTTP 401
64
+ * on an expired token (FINDINGS "Part 2B").
65
+ *
66
+ * ─── Thought signatures: the round trip a tool loop cannot skip ─────
67
+ *
68
+ * A current Gemini model does not merely PREFER its thought signature back —
69
+ * it refuses the turn without it. An independent field trial on live GCP ran
70
+ * `gemini-3.1-flash-lite` on Vertex through one ordinary tool loop: the first
71
+ * call asked for the function, the tool ran, and the second call came back
72
+ *
73
+ * 400 INVALID_ARGUMENT — "Function call is missing a thought_signature in
74
+ * functionCall parts. This is required for tools to work correctly …"
75
+ *
76
+ * (FINDINGS "Failure 4"). The cost of that shape is what makes it worth this
77
+ * paragraph: the failure lands AFTER the tool has already executed, so a
78
+ * side-effecting tool has run and the answer is unreachable.
79
+ *
80
+ * So the signature is CARRIED, not dropped. `Part.thoughtSignature` (a base64
81
+ * string on the installed @google/genai 2.16.0 `Part`) is read off the same
82
+ * part as the `functionCall` it belongs to, parked on the port's neutral
83
+ * `toolCalls[].providerMeta`, and written back onto the reconstructed
84
+ * `functionCall` part on the next request — byte for byte, because a signature
85
+ * is checked and not read. This is the same round trip the Anthropic adapter
86
+ * does with signed thinking blocks, one field along: there the carrier is
87
+ * `LLMMessage.thinkingBlocks[].signature`, here it is the tool call itself,
88
+ * because that is where Google puts it.
89
+ *
90
+ * What that does NOT cover, said plainly: a signature attached to a TEXT part
91
+ * of an answer with no function call. The port's assistant turn is a string,
92
+ * and a string has nowhere to keep one. The trial's failure was the functionCall
93
+ * shape; that shape is fixed here, and the other one is named rather than
94
+ * quietly half-handled.
41
95
  *
42
96
  * ─── Limitations (stated, not discovered) ───────────────────────────
43
97
  *
@@ -47,12 +101,12 @@
47
101
  * • **Thought summaries are not requested.** `usage.thinking` is reported
48
102
  * honestly from `thoughtsTokenCount`, and `req.thinking.budget` is threaded
49
103
  * to `thinkingConfig.thinkingBudget` — but `includeThoughts` is deliberately
50
- * left unset, so no `rawThinking` is produced. Gemini's thought parts carry a
51
- * `thoughtSignature` that has to be echoed byte-exact on the next turn, and
52
- * there is no Gemini `ThinkingHandler` in this release to normalize and
53
- * round-trip them. Asking for content nothing can carry would be a leak, not
54
- * a feature. `thinkingConfig.thinkingLevel` has no field on `LLMRequest` and
55
- * is likewise not sent.
104
+ * left unset, so no `rawThinking` is produced and there is no Gemini
105
+ * `ThinkingHandler` in this release to normalize thought TEXT. Asking for
106
+ * content nothing can carry would be a leak, not a feature. Signature
107
+ * round-tripping (above) is a separate thing and does not need one.
108
+ * `thinkingConfig.thinkingLevel` has no field on `LLMRequest` and is
109
+ * likewise not sent.
56
110
  * • `responseJsonSchema` (native structured output) is NOT exposed; use
57
111
  * `.outputSchema(...)`, which goes over as a forced tool — a shape this
58
112
  * adapter DOES carry.
@@ -60,7 +114,7 @@
60
114
  * are not exposed. `tools` carries function declarations only.
61
115
  */
62
116
  import { asContextWindowExceeded } from './contextWindow.js';
63
- import { resolveGoogleGenAIClient } from './googleGenAI.js';
117
+ import { createGoogleGenAIClientResolver, resolveGoogleDoor, } from './googleGenAI.js';
64
118
  /**
65
119
  * Which roles this wire carries inside `contents`.
66
120
  *
@@ -72,8 +126,22 @@ import { resolveGoogleGenAIClient } from './googleGenAI.js';
72
126
  * the recording and the request.
73
127
  */
74
128
  const CARRIES_IN_MESSAGES = Object.freeze(['user', 'assistant']);
75
- /** The model asked for when the request says only `'gemini'`. */
76
- const DEFAULT_MODEL = 'gemini-2.5-flash';
129
+ /**
130
+ * The model asked for when the request says only `'gemini'` — **on Vertex**.
131
+ *
132
+ * Field-proven rather than assumed: an independent trial on live GCP completed
133
+ * a real Vertex tool round trip on `gemini-2.5-flash` through Application
134
+ * Default Credentials, two LLM calls and one tool execution (FINDINGS "Part 1 —
135
+ * native Gemini on Vertex through ADC"). Google lists the model's retirement
136
+ * for **October 16, 2026**, so this is a default with an expiry date, not a
137
+ * recommendation — name a current model in `defaultModel` when you have one.
138
+ *
139
+ * There is deliberately NO sibling constant for the key door. See
140
+ * {@link GeminiProviderOptions.defaultModel}.
141
+ */
142
+ const DEFAULT_VERTEX_MODEL = 'gemini-2.5-flash';
143
+ /** The request-side shorthand that asks for whatever the door's default is. */
144
+ const MODEL_SHORTHAND = 'gemini';
77
145
  /**
78
146
  * Prefix on a tool-call id THIS ADAPTER invented.
79
147
  *
@@ -112,16 +180,24 @@ const SYNTHETIC_ID_PREFIX = 'gemini-call-';
112
180
  * and when `@google/genai` is not installed.
113
181
  */
114
182
  export function gemini(options = {}) {
115
- const client = resolveGoogleGenAIClient(options, 'gemini', options._client);
116
- const defaultModel = options.defaultModel ?? DEFAULT_MODEL;
183
+ // Eager, so a missing `@google/genai` and an unanswerable door are still
184
+ // refused where the consumer typed `gemini(...)`. Under a callback key
185
+ // there is nothing to build yet — see the resolver.
186
+ const connect = createGoogleGenAIClientResolver(options, 'gemini', options._client, true);
187
+ // A double talks to nobody, so its door comes from the options alone and
188
+ // never from the ambient environment of whoever is running the tests.
189
+ const door = resolveGoogleDoor(options, options._client === undefined);
190
+ const defaultModel = options.defaultModel ?? (door === 'vertex' ? DEFAULT_VERTEX_MODEL : undefined);
117
191
  const defaultMaxTokens = options.defaultMaxTokens;
118
192
  // Ids are invented per PROVIDER INSTANCE, in call order — the same shape
119
193
  // `ollama()` uses, and for the same reason: the wire omits them.
120
194
  let toolCallSeq = 0;
121
195
  const nextToolCallId = () => `${SYNTHETIC_ID_PREFIX}${++toolCallSeq}`;
122
196
  // The ONE secret this adapter holds, so the ONE string its errors promise
123
- // never to print — see `wrapError`.
124
- const wrap = (err) => wrapError(err, options.apiKey);
197
+ // never to print — see `wrapError`. Under a callback key the secret CHANGES,
198
+ // so the string to redact is the one the failing call actually used, not the
199
+ // one the options were built with.
200
+ const wrap = (err, apiKey) => wrapError(err, apiKey);
125
201
  const provider = {
126
202
  name: 'gemini',
127
203
  carriesInMessages: CARRIES_IN_MESSAGES,
@@ -132,29 +208,40 @@ export function gemini(options = {}) {
132
208
  // is no endpoint whose behaviour we would be promising on its behalf.
133
209
  carriesForcedToolChoice: true,
134
210
  async complete(req) {
135
- const params = buildParams(req, defaultModel, defaultMaxTokens);
211
+ const params = buildParams(req, resolveModel(req.model, defaultModel, door), defaultMaxTokens);
212
+ // Resolved BEFORE the try so a lease failure carries no key to redact
213
+ // that we would have had to guess at; the resolver's own refusals never
214
+ // quote the credential.
215
+ const lease = await connect();
136
216
  try {
137
- const response = await client.models.generateContent(params);
217
+ const response = await lease.client.models.generateContent(params);
138
218
  return fromGeminiResponse(response, nextToolCallId);
139
219
  }
140
220
  catch (err) {
141
- throw wrap(err);
221
+ throw wrap(err, lease.apiKey);
142
222
  }
143
223
  },
144
224
  async *stream(req) {
145
- const params = buildParams(req, defaultModel, defaultMaxTokens);
225
+ const params = buildParams(req, resolveModel(req.model, defaultModel, door), defaultMaxTokens);
226
+ // One lease for the whole stream. A key that rotates mid-stream cannot
227
+ // be applied to a socket that is already open — see the refresh boundary
228
+ // in googleGenAI.ts.
229
+ const lease = await connect();
146
230
  let stream;
147
231
  try {
148
232
  // Two awaits, one call: `generateContentStream` answers with a PROMISE
149
233
  // of an async generator, so `for await` over the return value directly
150
234
  // iterates a promise and yields nothing.
151
- stream = await client.models.generateContentStream(params);
235
+ stream = await lease.client.models.generateContentStream(params);
152
236
  }
153
237
  catch (err) {
154
- throw wrap(err);
238
+ throw wrap(err, lease.apiKey);
155
239
  }
156
240
  const textParts = [];
157
- const functionCalls = [];
241
+ // The PART, not just its `functionCall`: the thought signature is the
242
+ // part's field, and a call collected without it is a call that cannot
243
+ // go back (see the file header's Failure-4 note).
244
+ const functionParts = [];
158
245
  let usage;
159
246
  let finishReason;
160
247
  let responseId;
@@ -176,7 +263,7 @@ export function gemini(options = {}) {
176
263
  finishReason = candidate.finishReason;
177
264
  for (const part of candidate?.content?.parts ?? []) {
178
265
  if (part.functionCall)
179
- functionCalls.push(part.functionCall);
266
+ functionParts.push(part);
180
267
  // A thought-summary part is not visible content and is never
181
268
  // streamed as one. Nothing asks for them today (see the file
182
269
  // header); the guard is here so that a model that volunteers one
@@ -190,7 +277,7 @@ export function gemini(options = {}) {
190
277
  }
191
278
  }
192
279
  }
193
- const toolCalls = functionCalls.map((fc) => toLLMToolCall(fc, nextToolCallId));
280
+ const toolCalls = functionParts.map((part) => toLLMToolCall(part, nextToolCallId));
194
281
  const response = {
195
282
  content: textParts.join(''),
196
283
  toolCalls,
@@ -207,12 +294,40 @@ export function gemini(options = {}) {
207
294
  yield { tokenIndex, content: '', done: true, response };
208
295
  }
209
296
  catch (err) {
210
- throw wrap(err);
297
+ throw wrap(err, lease.apiKey);
211
298
  }
212
299
  },
213
300
  };
214
301
  return provider;
215
302
  }
303
+ /**
304
+ * The model this request is for — and the ONE refusal the doors do not share.
305
+ *
306
+ * A request naming a model wins, always. The shorthand `'gemini'` resolves to
307
+ * the door's default, and the Gemini API door HAS no default (see
308
+ * {@link GeminiProviderOptions.defaultModel}): the one this package used to
309
+ * send was measured returning HTTP 404 on that door for a new account.
310
+ *
311
+ * Refused here rather than at construction because a consumer who always names
312
+ * a model never needs a default, and a factory that refused them at the call
313
+ * site they typed would be charging everyone for a setting only some use.
314
+ */
315
+ function resolveModel(requested, defaultModel, door) {
316
+ if (requested !== MODEL_SHORTHAND)
317
+ return requested;
318
+ if (defaultModel !== undefined)
319
+ return defaultModel;
320
+ throw new Error(`gemini: model 'gemini' is a shorthand for this door's default model, and the ` +
321
+ `${door === 'vertex' ? 'Vertex' : 'Gemini API (AI Studio)'} door has no default.\n` +
322
+ " A live field trial called that door with this package's old default, " +
323
+ "'gemini-2.5-flash', and Google answered 404: \"This model models/gemini-2.5-flash is no " +
324
+ 'longer available to new users." Sending it anyway would fail on YOUR first call, after ' +
325
+ 'the request was built and paid for in latency.\n' +
326
+ " Fix: gemini({ apiKey, defaultModel: 'the-model-your-key-can-use' })\n" +
327
+ " Or: name the model per call — Agent.create({ model: 'gemini-3.1-flash-lite' }).\n" +
328
+ ' On VERTEX the shorthand still resolves — to gemini-2.5-flash, which the same trial ran ' +
329
+ 'end to end (Google retires it 2026-10-16).');
330
+ }
216
331
  /**
217
332
  * Class form for consumers who prefer `new GeminiProvider(...)` over the
218
333
  * `gemini(...)` factory. Identical behavior; trivial wrapper.
@@ -237,7 +352,7 @@ export class GeminiProvider {
237
352
  }
238
353
  }
239
354
  // ─── Internals ──────────────────────────────────────────────────────
240
- function buildParams(req, defaultModel, defaultMaxTokens) {
355
+ function buildParams(req, model, defaultMaxTokens) {
241
356
  const config = {};
242
357
  // The system prompt is a top-level field, not a turn — see
243
358
  // CARRIES_IN_MESSAGES.
@@ -271,7 +386,7 @@ function buildParams(req, defaultModel, defaultMaxTokens) {
271
386
  };
272
387
  }
273
388
  return {
274
- model: req.model === 'gemini' ? defaultModel : req.model,
389
+ model,
275
390
  contents: toGeminiContents(req.messages),
276
391
  ...(Object.keys(config).length > 0 && { config }),
277
392
  };
@@ -282,7 +397,9 @@ function buildParams(req, defaultModel, defaultMaxTokens) {
282
397
  * Key transforms:
283
398
  * • `role: 'system'` is DROPPED — it rides `config.systemInstruction`.
284
399
  * • `role: 'assistant'` becomes `role: 'model'`, with `toolCalls` restored as
285
- * `functionCall` parts so a multi-turn tool conversation round-trips.
400
+ * `functionCall` parts so a multi-turn tool conversation round-trips —
401
+ * each one carrying back the `thoughtSignature` it arrived with, which is
402
+ * what makes the SECOND call of a tool loop legal on a current model.
286
403
  * • `role: 'tool'` becomes a `functionResponse` part inside a **user** turn,
287
404
  * which is where Gemini expects results. Consecutive tool messages merge
288
405
  * into ONE user turn, so a reply that called three tools is answered by one
@@ -303,7 +420,12 @@ function toGeminiContents(messages) {
303
420
  if (m.content)
304
421
  parts.push({ text: m.content });
305
422
  for (const tc of m.toolCalls ?? []) {
423
+ const signature = thoughtSignatureOf(tc.providerMeta);
306
424
  parts.push({
425
+ // Back on the PART, exactly where it came from and byte for byte.
426
+ // Absent when the model never sent one (a 2.5-series turn), because
427
+ // an invented signature is worse than a missing one.
428
+ ...(signature !== undefined && { thoughtSignature: signature }),
307
429
  functionCall: {
308
430
  // Only an id GEMINI issued goes back to Gemini — see
309
431
  // SYNTHETIC_ID_PREFIX.
@@ -348,6 +470,20 @@ function toGeminiContents(messages) {
348
470
  function isRealId(id) {
349
471
  return id !== undefined && id.length > 0 && !id.startsWith(SYNTHETIC_ID_PREFIX);
350
472
  }
473
+ /** The key this adapter parks a thought signature under on `providerMeta`. */
474
+ const THOUGHT_SIGNATURE = 'thoughtSignature';
475
+ /**
476
+ * A signature off the port's neutral metadata bag — or nothing.
477
+ *
478
+ * Shape-checked rather than trusted: `providerMeta` survives a checkpoint, a
479
+ * `structuredClone` and whatever a consumer did to the history in between, and
480
+ * a non-string in the `thoughtSignature` field would go on the wire as a
481
+ * garbled signature, which the service rejects less clearly than a missing one.
482
+ */
483
+ function thoughtSignatureOf(meta) {
484
+ const raw = meta?.[THOUGHT_SIGNATURE];
485
+ return typeof raw === 'string' && raw.length > 0 ? raw : undefined;
486
+ }
351
487
  /**
352
488
  * `LLMToolSchema` → `FunctionDeclaration`, with the schema untranslated.
353
489
  *
@@ -371,7 +507,7 @@ function fromGeminiResponse(response, nextToolCallId) {
371
507
  const toolCalls = [];
372
508
  for (const part of candidate?.content?.parts ?? []) {
373
509
  if (part.functionCall)
374
- toolCalls.push(toLLMToolCall(part.functionCall, nextToolCallId));
510
+ toolCalls.push(toLLMToolCall(part, nextToolCallId));
375
511
  // Thought summaries are not the answer. See the header.
376
512
  if (part.thought)
377
513
  continue;
@@ -386,11 +522,24 @@ function fromGeminiResponse(response, nextToolCallId) {
386
522
  ...(response.responseId !== undefined && { providerRef: response.responseId }),
387
523
  };
388
524
  }
389
- function toLLMToolCall(fc, nextToolCallId) {
525
+ /**
526
+ * One `functionCall` PART → one port tool call, signature included.
527
+ *
528
+ * Takes the part rather than the `functionCall` because the two fields that
529
+ * have to travel together live at different levels: the call is inside the
530
+ * part, the signature is on it.
531
+ */
532
+ function toLLMToolCall(part, nextToolCallId) {
533
+ const fc = part.functionCall ?? {};
534
+ const signature = part.thoughtSignature;
390
535
  return {
391
536
  id: fc.id && fc.id.length > 0 ? fc.id : nextToolCallId(),
392
537
  name: fc.name ?? '',
393
538
  args: { ...(fc.args ?? {}) },
539
+ // Only when there IS one. An empty bag on every tool call would be noise
540
+ // in every recording, every checkpoint and every narrative line.
541
+ ...(typeof signature === 'string' &&
542
+ signature.length > 0 && { providerMeta: { [THOUGHT_SIGNATURE]: signature } }),
394
543
  };
395
544
  }
396
545
  /**
@@ -405,6 +554,14 @@ function toLLMToolCall(fc, nextToolCallId) {
405
554
  * `cacheWrite` stays undefined on purpose: Gemini's context caching is created
406
555
  * by a separate `caches.create` call that this adapter does not make, so there
407
556
  * is no write for a `generateContent` turn to report.
557
+ *
558
+ * **`output` does not include thinking on this wire, and that matters for
559
+ * money.** A field trial's 256-token stream came back `input 21, output 9,
560
+ * thinking 243` — 243 tokens that were spent, were billed, and appear in
561
+ * neither `input` nor `output` (FINDINGS "Failure 5"). Anything adding
562
+ * `input + output` to estimate a Gemini turn is under-counting by whatever the
563
+ * model thought. `usage.thinking` is the number to add, and it now survives all
564
+ * the way to `agentfootprint.stream.llm_end`.
408
565
  */
409
566
  function toUsage(usage) {
410
567
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"GeminiProvider.js","sourceRoot":"","sources":["../../../../src/adapters/llm/GeminiProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAYH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAqC,MAAM,kBAAkB,CAAC;AAyH/F;;;;;;;;;GASG;AACH,MAAM,mBAAmB,GAAwB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAEtF,iEAAiE;AACjE,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,MAAM,CAAC,UAAiC,EAAE;IACxD,MAAM,MAAM,GAAG,wBAAwB,CAAmB,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9F,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;IAC3D,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAElD,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC,GAAG,mBAAmB,GAAG,EAAE,WAAW,EAAE,CAAC;IAE9E,0EAA0E;IAC1E,oCAAoC;IACpC,M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,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -116,8 +116,40 @@ interface OpenAIStreamChunk {
116
116
  };
117
117
  }
118
118
  export interface OpenAIProviderOptions {
119
- /** API key. Defaults to `OPENAI_API_KEY` env var. */
120
- readonly apiKey?: string;
119
+ /**
120
+ * API key. Defaults to the `OPENAI_API_KEY` env var.
121
+ *
122
+ * **A FUNCTION here is re-read before every request (9.29.0).** That is what
123
+ * makes this adapter usable in front of an endpoint whose credential is a
124
+ * short-lived OAuth token rather than a key — Vertex AI's OpenAI-compatible
125
+ * endpoint being the case that forced it. An independent field trial ran a
126
+ * real call through that endpoint with a current token, then repeated it
127
+ * with an expired one and got HTTP 401 with nowhere to put a fresh token:
128
+ * *"`OpenAIProviderOptions` accepts a fixed `apiKey` and exposes no
129
+ * credential callback"* (FINDINGS "Part 2B"). A process living longer than
130
+ * an hour had to rebuild the provider, and usually found out it hadn't at
131
+ * 3am.
132
+ *
133
+ * The boundary, stated so nobody has to guess:
134
+ * • called ONCE PER REQUEST, before the request is built;
135
+ * • the SDK client is rebuilt only when the returned string CHANGED, so a
136
+ * cached token costs one function call;
137
+ * • a stream keeps the key it started with — nothing can re-authenticate
138
+ * a socket that is already open;
139
+ * • what expiry means is the callback's business. This adapter does not
140
+ * inspect, decode or schedule anything; it asks every time and uses what
141
+ * it is given.
142
+ *
143
+ * ```ts
144
+ * const auth = new GoogleAuth({ scopes: ['https://www.googleapis.com/auth/cloud-platform'] });
145
+ * const client = await auth.getClient();
146
+ * openai({
147
+ * baseURL: 'https://…/openapi',
148
+ * apiKey: async () => (await client.getAccessToken()).token ?? '',
149
+ * });
150
+ * ```
151
+ */
152
+ readonly apiKey?: string | (() => string | Promise<string>);
121
153
  /** Base URL — set for OpenAI-compatible APIs (Ollama, Together, vLLM). */
122
154
  readonly baseURL?: string;
123
155
  /**
@@ -44,7 +44,7 @@ const CARRIES_IN_MESSAGES = Object.freeze(['system', 'user', 'assistant']);
44
44
  * .build();
45
45
  */
46
46
  export function openai(options = {}) {
47
- const client = resolveClient(options);
47
+ const connect = createClientResolver(options);
48
48
  const defaultModel = options.defaultModel ?? 'gpt-4o-mini';
49
49
  const defaultMaxTokens = options.defaultMaxTokens;
50
50
  // A custom baseURL means an OpenAI-COMPATIBLE endpoint (Ollama/vLLM/Together/Groq),
@@ -66,6 +66,9 @@ export function openai(options = {}) {
66
66
  carriesForcedToolChoice: !legacyEndpoint,
67
67
  async complete(req) {
68
68
  const params = buildParams(req, { ...cfg, stream: false });
69
+ // The credential is asked for HERE, per request, so a token that expired
70
+ // since the last call is a new token and not a 401.
71
+ const client = await connect();
69
72
  try {
70
73
  const response = (await client.chat.completions.create(params));
71
74
  return fromOpenAIResponse(response);
@@ -76,6 +79,7 @@ export function openai(options = {}) {
76
79
  },
77
80
  async *stream(req) {
78
81
  const params = buildParams(req, { ...cfg, stream: true });
82
+ const client = await connect();
79
83
  let stream;
80
84
  try {
81
85
  stream = client.chat.completions.create(params);
@@ -286,6 +290,63 @@ function resolveAzureClient(options) {
286
290
  //
287
291
  // openai({ baseURL: 'http://localhost:11434/v1', apiKey: 'ollama' })
288
292
  // ─── Internals ──────────────────────────────────────────────────────
293
+ /**
294
+ * The client seam — one answer per request.
295
+ *
296
+ * Three paths, and only the third is new (the same three the Google adapters
297
+ * take, deliberately: two doors that solved the same problem differently would
298
+ * be two doors to learn):
299
+ *
300
+ * 1. `_client` injected → the double, always (the credential callback still
301
+ * runs, because the double replaces the client and not the credential).
302
+ * 2. `apiKey` a string or absent → built ONCE, at factory time, so a missing
303
+ * `openai` package is still refused where the consumer typed `openai(...)`.
304
+ * 3. `apiKey` a callback → called before every request; the SDK client is
305
+ * rebuilt only when the answer changed. Not eager: calling a consumer's
306
+ * credential provider from a factory fetches a token nobody asked for yet.
307
+ */
308
+ function createClientResolver(options) {
309
+ const source = options.apiKey;
310
+ if (options._client) {
311
+ const injected = options._client;
312
+ // A double stands in for the SDK client, not for the credential: a
313
+ // callback is still called per request, so the rotation is observable in a
314
+ // test that never opens a socket.
315
+ if (typeof source !== 'function')
316
+ return () => injected;
317
+ return async () => {
318
+ await requireKey(source);
319
+ return injected;
320
+ };
321
+ }
322
+ if (typeof source !== 'function') {
323
+ const built = resolveClient(options);
324
+ return () => built;
325
+ }
326
+ let lastKey;
327
+ let built;
328
+ return async () => {
329
+ const answer = await requireKey(source);
330
+ if (built === undefined || answer !== lastKey) {
331
+ built = resolveClient({ ...options, apiKey: answer });
332
+ lastKey = answer;
333
+ }
334
+ return built;
335
+ };
336
+ }
337
+ /** Call the credential callback and insist on something usable. */
338
+ async function requireKey(source) {
339
+ const answer = await source();
340
+ if (typeof answer === 'string' && answer.trim().length > 0)
341
+ return answer;
342
+ // The value is never quoted back: it is a credential when it is right.
343
+ throw new Error('openai: the `apiKey` callback returned ' +
344
+ (typeof answer === 'string' ? 'an empty string' : `a ${typeof answer}`) +
345
+ ', and a key has to be a non-empty string.\n' +
346
+ ' The callback runs before every request, so this is a live credential failure — a ' +
347
+ 'token fetch that failed usually throws rather than returning nothing.\n' +
348
+ ' Fix: return the token, or throw from the callback so openai() can report why.');
349
+ }
289
350
  function resolveClient(options) {
290
351
  if (options._client)
291
352
  return options._client;
@@ -299,7 +360,10 @@ function resolveClient(options) {
299
360
  ' Install: npm install openai\n' +
300
361
  ' Or pass `_client` for test injection.');
301
362
  }
302
- const apiKey = options.apiKey ?? process.env.OPENAI_API_KEY;
363
+ // A callback has already been resolved to a string by `createClientResolver`
364
+ // before it reaches here; the guard is what keeps a function from being
365
+ // stringified into an `Authorization` header by a future call site.
366
+ const apiKey = (typeof options.apiKey === 'string' ? options.apiKey : undefined) ?? process.env.OPENAI_API_KEY;
303
367
  return new OpenAI({ apiKey, ...(options.baseURL && { baseURL: options.baseURL }) });
304
368
  }
305
369
  /** o-series reasoning ids (o1, o1-mini, o3, o3-mini, o4-mini, o5, …). `gpt-4o`