agentfootprint 9.28.0 → 9.30.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 (101) hide show
  1. package/README.md +3 -2
  2. package/dist/adapters/google/aiPlatform.js +23 -1
  3. package/dist/adapters/google/aiPlatform.js.map +1 -1
  4. package/dist/adapters/hosting/googleAgentEngine.js +180 -61
  5. package/dist/adapters/hosting/googleAgentEngine.js.map +1 -1
  6. package/dist/adapters/identity/google.js +18 -4
  7. package/dist/adapters/identity/google.js.map +1 -1
  8. package/dist/adapters/llm/GeminiProvider.js +198 -36
  9. package/dist/adapters/llm/GeminiProvider.js.map +1 -1
  10. package/dist/adapters/llm/OpenAIProvider.js +66 -2
  11. package/dist/adapters/llm/OpenAIProvider.js.map +1 -1
  12. package/dist/adapters/llm/googleGenAI.js +155 -8
  13. package/dist/adapters/llm/googleGenAI.js.map +1 -1
  14. package/dist/adapters/memory/memoryBank.js +250 -6
  15. package/dist/adapters/memory/memoryBank.js.map +1 -1
  16. package/dist/adapters/types.js.map +1 -1
  17. package/dist/artifacts/gcsArtifacts.js +21 -5
  18. package/dist/artifacts/gcsArtifacts.js.map +1 -1
  19. package/dist/embedders/index.js +8 -6
  20. package/dist/embedders/index.js.map +1 -1
  21. package/dist/esm/adapters/google/aiPlatform.d.ts +44 -0
  22. package/dist/esm/adapters/google/aiPlatform.js +23 -1
  23. package/dist/esm/adapters/google/aiPlatform.js.map +1 -1
  24. package/dist/esm/adapters/hosting/googleAgentEngine.d.ts +104 -18
  25. package/dist/esm/adapters/hosting/googleAgentEngine.js +179 -60
  26. package/dist/esm/adapters/hosting/googleAgentEngine.js.map +1 -1
  27. package/dist/esm/adapters/identity/google.d.ts +18 -4
  28. package/dist/esm/adapters/identity/google.js +18 -4
  29. package/dist/esm/adapters/identity/google.js.map +1 -1
  30. package/dist/esm/adapters/llm/GeminiProvider.d.ts +96 -15
  31. package/dist/esm/adapters/llm/GeminiProvider.js +199 -37
  32. package/dist/esm/adapters/llm/GeminiProvider.js.map +1 -1
  33. package/dist/esm/adapters/llm/OpenAIProvider.d.ts +34 -2
  34. package/dist/esm/adapters/llm/OpenAIProvider.js +66 -2
  35. package/dist/esm/adapters/llm/OpenAIProvider.js.map +1 -1
  36. package/dist/esm/adapters/llm/googleGenAI.d.ts +105 -4
  37. package/dist/esm/adapters/llm/googleGenAI.js +152 -7
  38. package/dist/esm/adapters/llm/googleGenAI.js.map +1 -1
  39. package/dist/esm/adapters/memory/memoryBank.d.ts +42 -3
  40. package/dist/esm/adapters/memory/memoryBank.js +249 -5
  41. package/dist/esm/adapters/memory/memoryBank.js.map +1 -1
  42. package/dist/esm/adapters/types.d.ts +27 -0
  43. package/dist/esm/adapters/types.js.map +1 -1
  44. package/dist/esm/artifacts/gcsArtifacts.d.ts +21 -5
  45. package/dist/esm/artifacts/gcsArtifacts.js +21 -5
  46. package/dist/esm/artifacts/gcsArtifacts.js.map +1 -1
  47. package/dist/esm/core/agent/types.d.ts +1 -0
  48. package/dist/esm/embedders/index.js +9 -7
  49. package/dist/esm/embedders/index.js.map +1 -1
  50. package/dist/esm/events/payloads.d.ts +22 -0
  51. package/dist/esm/hosting-providers.d.ts +4 -2
  52. package/dist/esm/hosting-providers.js +4 -2
  53. package/dist/esm/hosting-providers.js.map +1 -1
  54. package/dist/esm/memory-providers.d.ts +1 -1
  55. package/dist/esm/memory-providers.js +4 -2
  56. package/dist/esm/memory-providers.js.map +1 -1
  57. package/dist/esm/providers.js.map +1 -1
  58. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.js +5 -1
  59. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.js.map +1 -1
  60. package/dist/esm/recorders/observability/commentary/commentaryTemplates.js +44 -3
  61. package/dist/esm/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
  62. package/dist/hosting-providers.js +5 -2
  63. package/dist/hosting-providers.js.map +1 -1
  64. package/dist/memory-providers.js +5 -2
  65. package/dist/memory-providers.js.map +1 -1
  66. package/dist/providers.js.map +1 -1
  67. package/dist/recorders/observability/AgentThinkingTraceRecorder.js +5 -1
  68. package/dist/recorders/observability/AgentThinkingTraceRecorder.js.map +1 -1
  69. package/dist/recorders/observability/commentary/commentaryTemplates.js +44 -3
  70. package/dist/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
  71. package/dist/types/adapters/google/aiPlatform.d.ts +44 -0
  72. package/dist/types/adapters/google/aiPlatform.d.ts.map +1 -1
  73. package/dist/types/adapters/hosting/googleAgentEngine.d.ts +104 -18
  74. package/dist/types/adapters/hosting/googleAgentEngine.d.ts.map +1 -1
  75. package/dist/types/adapters/identity/google.d.ts +18 -4
  76. package/dist/types/adapters/identity/google.d.ts.map +1 -1
  77. package/dist/types/adapters/llm/GeminiProvider.d.ts +96 -15
  78. package/dist/types/adapters/llm/GeminiProvider.d.ts.map +1 -1
  79. package/dist/types/adapters/llm/OpenAIProvider.d.ts +34 -2
  80. package/dist/types/adapters/llm/OpenAIProvider.d.ts.map +1 -1
  81. package/dist/types/adapters/llm/googleGenAI.d.ts +105 -4
  82. package/dist/types/adapters/llm/googleGenAI.d.ts.map +1 -1
  83. package/dist/types/adapters/memory/memoryBank.d.ts +42 -3
  84. package/dist/types/adapters/memory/memoryBank.d.ts.map +1 -1
  85. package/dist/types/adapters/types.d.ts +27 -0
  86. package/dist/types/adapters/types.d.ts.map +1 -1
  87. package/dist/types/artifacts/gcsArtifacts.d.ts +21 -5
  88. package/dist/types/artifacts/gcsArtifacts.d.ts.map +1 -1
  89. package/dist/types/core/agent/types.d.ts +1 -0
  90. package/dist/types/core/agent/types.d.ts.map +1 -1
  91. package/dist/types/embedders/index.d.ts.map +1 -1
  92. package/dist/types/events/payloads.d.ts +22 -0
  93. package/dist/types/events/payloads.d.ts.map +1 -1
  94. package/dist/types/hosting-providers.d.ts +4 -2
  95. package/dist/types/hosting-providers.d.ts.map +1 -1
  96. package/dist/types/memory-providers.d.ts +1 -1
  97. package/dist/types/memory-providers.d.ts.map +1 -1
  98. package/dist/types/providers.d.ts.map +1 -1
  99. package/dist/types/recorders/observability/AgentThinkingTraceRecorder.d.ts.map +1 -1
  100. package/dist/types/recorders/observability/commentary/commentaryTemplates.d.ts.map +1 -1
  101. package/package.json +1 -1
@@ -26,18 +26,77 @@
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: field-validated.** The signature round trip
44
+ * below was built from the trial's captured 400, and the same independent
45
+ * trial then re-ran it on live Vertex against the published fix
46
+ * (2026-08-14): `gemini-3.1-flash-lite` called a tool, the tool answered,
47
+ * the signature went back byte for byte, and the second model call
48
+ * completed with the right answer — two LLM calls, one tool execution, real
49
+ * token counts. What it does NOT cover is a signature attached to a TEXT
50
+ * part with no function call beside it; see below.
51
+ *
29
52
  * ─── Why native, and not `openai({ baseURL })` ──────────────────────
30
53
  *
31
54
  * 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.
55
+ * an hour. It authenticates with an OAuth access token that expires (9.29.0
56
+ * gives `openai({ apiKey })` a callback form so a long-running process can
57
+ * refresh one, which is a mitigation and not a fix); its
58
+ * `tools.function.parameters` is **OpenAPI**, not JSON Schema, so `$ref` /
59
+ * `oneOf` / `additionalProperties` diverge silently; unsupported parameters are
60
+ * ignored rather than refused; and its documented response carries no cached-
61
+ * or reasoning-token counts. This adapter exists because every one of those is
62
+ * answerable on the native SDK: ADC refreshes itself, tools go over as JSON
63
+ * Schema untranslated (`parametersJsonSchema`), a forced single tool is
64
+ * expressible, and `usageMetadata` reports cached and thinking tokens as
65
+ * separate numbers.
66
+ *
67
+ * A field trial measured both halves of that: the native path completed a call
68
+ * after a forced credential expiry, while the compatible path returned HTTP 401
69
+ * on an expired token (FINDINGS "Part 2B").
70
+ *
71
+ * ─── Thought signatures: the round trip a tool loop cannot skip ─────
72
+ *
73
+ * A current Gemini model does not merely PREFER its thought signature back —
74
+ * it refuses the turn without it. An independent field trial on live GCP ran
75
+ * `gemini-3.1-flash-lite` on Vertex through one ordinary tool loop: the first
76
+ * call asked for the function, the tool ran, and the second call came back
77
+ *
78
+ * 400 INVALID_ARGUMENT — "Function call is missing a thought_signature in
79
+ * functionCall parts. This is required for tools to work correctly …"
80
+ *
81
+ * (FINDINGS "Failure 4"). The cost of that shape is what makes it worth this
82
+ * paragraph: the failure lands AFTER the tool has already executed, so a
83
+ * side-effecting tool has run and the answer is unreachable.
84
+ *
85
+ * So the signature is CARRIED, not dropped. `Part.thoughtSignature` (a base64
86
+ * string on the installed @google/genai 2.16.0 `Part`) is read off the same
87
+ * part as the `functionCall` it belongs to, parked on the port's neutral
88
+ * `toolCalls[].providerMeta`, and written back onto the reconstructed
89
+ * `functionCall` part on the next request — byte for byte, because a signature
90
+ * is checked and not read. This is the same round trip the Anthropic adapter
91
+ * does with signed thinking blocks, one field along: there the carrier is
92
+ * `LLMMessage.thinkingBlocks[].signature`, here it is the tool call itself,
93
+ * because that is where Google puts it.
94
+ *
95
+ * What that does NOT cover, said plainly: a signature attached to a TEXT part
96
+ * of an answer with no function call. The port's assistant turn is a string,
97
+ * and a string has nowhere to keep one. The trial's failure was the functionCall
98
+ * shape; that shape is fixed here, and the other one is named rather than
99
+ * quietly half-handled.
41
100
  *
42
101
  * ─── Limitations (stated, not discovered) ───────────────────────────
43
102
  *
@@ -47,12 +106,12 @@
47
106
  * • **Thought summaries are not requested.** `usage.thinking` is reported
48
107
  * honestly from `thoughtsTokenCount`, and `req.thinking.budget` is threaded
49
108
  * 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.
109
+ * left unset, so no `rawThinking` is produced and there is no Gemini
110
+ * `ThinkingHandler` in this release to normalize thought TEXT. Asking for
111
+ * content nothing can carry would be a leak, not a feature. Signature
112
+ * round-tripping (above) is a separate thing and does not need one.
113
+ * `thinkingConfig.thinkingLevel` has no field on `LLMRequest` and is
114
+ * likewise not sent.
56
115
  * • `responseJsonSchema` (native structured output) is NOT exposed; use
57
116
  * `.outputSchema(...)`, which goes over as a forced tool — a shape this
58
117
  * adapter DOES carry.
@@ -60,7 +119,7 @@
60
119
  * are not exposed. `tools` carries function declarations only.
61
120
  */
62
121
  import { asContextWindowExceeded } from './contextWindow.js';
63
- import { resolveGoogleGenAIClient } from './googleGenAI.js';
122
+ import { createGoogleGenAIClientResolver, resolveGoogleDoor, } from './googleGenAI.js';
64
123
  /**
65
124
  * Which roles this wire carries inside `contents`.
66
125
  *
@@ -72,8 +131,22 @@ import { resolveGoogleGenAIClient } from './googleGenAI.js';
72
131
  * the recording and the request.
73
132
  */
74
133
  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';
134
+ /**
135
+ * The model asked for when the request says only `'gemini'` — **on Vertex**.
136
+ *
137
+ * Field-proven rather than assumed: an independent trial on live GCP completed
138
+ * a real Vertex tool round trip on `gemini-2.5-flash` through Application
139
+ * Default Credentials, two LLM calls and one tool execution (FINDINGS "Part 1 —
140
+ * native Gemini on Vertex through ADC"). Google lists the model's retirement
141
+ * for **October 16, 2026**, so this is a default with an expiry date, not a
142
+ * recommendation — name a current model in `defaultModel` when you have one.
143
+ *
144
+ * There is deliberately NO sibling constant for the key door. See
145
+ * {@link GeminiProviderOptions.defaultModel}.
146
+ */
147
+ const DEFAULT_VERTEX_MODEL = 'gemini-2.5-flash';
148
+ /** The request-side shorthand that asks for whatever the door's default is. */
149
+ const MODEL_SHORTHAND = 'gemini';
77
150
  /**
78
151
  * Prefix on a tool-call id THIS ADAPTER invented.
79
152
  *
@@ -112,16 +185,24 @@ const SYNTHETIC_ID_PREFIX = 'gemini-call-';
112
185
  * and when `@google/genai` is not installed.
113
186
  */
114
187
  export function gemini(options = {}) {
115
- const client = resolveGoogleGenAIClient(options, 'gemini', options._client);
116
- const defaultModel = options.defaultModel ?? DEFAULT_MODEL;
188
+ // Eager, so a missing `@google/genai` and an unanswerable door are still
189
+ // refused where the consumer typed `gemini(...)`. Under a callback key
190
+ // there is nothing to build yet — see the resolver.
191
+ const connect = createGoogleGenAIClientResolver(options, 'gemini', options._client, true);
192
+ // A double talks to nobody, so its door comes from the options alone and
193
+ // never from the ambient environment of whoever is running the tests.
194
+ const door = resolveGoogleDoor(options, options._client === undefined);
195
+ const defaultModel = options.defaultModel ?? (door === 'vertex' ? DEFAULT_VERTEX_MODEL : undefined);
117
196
  const defaultMaxTokens = options.defaultMaxTokens;
118
197
  // Ids are invented per PROVIDER INSTANCE, in call order — the same shape
119
198
  // `ollama()` uses, and for the same reason: the wire omits them.
120
199
  let toolCallSeq = 0;
121
200
  const nextToolCallId = () => `${SYNTHETIC_ID_PREFIX}${++toolCallSeq}`;
122
201
  // 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);
202
+ // never to print — see `wrapError`. Under a callback key the secret CHANGES,
203
+ // so the string to redact is the one the failing call actually used, not the
204
+ // one the options were built with.
205
+ const wrap = (err, apiKey) => wrapError(err, apiKey);
125
206
  const provider = {
126
207
  name: 'gemini',
127
208
  carriesInMessages: CARRIES_IN_MESSAGES,
@@ -132,29 +213,40 @@ export function gemini(options = {}) {
132
213
  // is no endpoint whose behaviour we would be promising on its behalf.
133
214
  carriesForcedToolChoice: true,
134
215
  async complete(req) {
135
- const params = buildParams(req, defaultModel, defaultMaxTokens);
216
+ const params = buildParams(req, resolveModel(req.model, defaultModel, door), defaultMaxTokens);
217
+ // Resolved BEFORE the try so a lease failure carries no key to redact
218
+ // that we would have had to guess at; the resolver's own refusals never
219
+ // quote the credential.
220
+ const lease = await connect();
136
221
  try {
137
- const response = await client.models.generateContent(params);
222
+ const response = await lease.client.models.generateContent(params);
138
223
  return fromGeminiResponse(response, nextToolCallId);
139
224
  }
140
225
  catch (err) {
141
- throw wrap(err);
226
+ throw wrap(err, lease.apiKey);
142
227
  }
143
228
  },
144
229
  async *stream(req) {
145
- const params = buildParams(req, defaultModel, defaultMaxTokens);
230
+ const params = buildParams(req, resolveModel(req.model, defaultModel, door), defaultMaxTokens);
231
+ // One lease for the whole stream. A key that rotates mid-stream cannot
232
+ // be applied to a socket that is already open — see the refresh boundary
233
+ // in googleGenAI.ts.
234
+ const lease = await connect();
146
235
  let stream;
147
236
  try {
148
237
  // Two awaits, one call: `generateContentStream` answers with a PROMISE
149
238
  // of an async generator, so `for await` over the return value directly
150
239
  // iterates a promise and yields nothing.
151
- stream = await client.models.generateContentStream(params);
240
+ stream = await lease.client.models.generateContentStream(params);
152
241
  }
153
242
  catch (err) {
154
- throw wrap(err);
243
+ throw wrap(err, lease.apiKey);
155
244
  }
156
245
  const textParts = [];
157
- const functionCalls = [];
246
+ // The PART, not just its `functionCall`: the thought signature is the
247
+ // part's field, and a call collected without it is a call that cannot
248
+ // go back (see the file header's Failure-4 note).
249
+ const functionParts = [];
158
250
  let usage;
159
251
  let finishReason;
160
252
  let responseId;
@@ -176,7 +268,7 @@ export function gemini(options = {}) {
176
268
  finishReason = candidate.finishReason;
177
269
  for (const part of candidate?.content?.parts ?? []) {
178
270
  if (part.functionCall)
179
- functionCalls.push(part.functionCall);
271
+ functionParts.push(part);
180
272
  // A thought-summary part is not visible content and is never
181
273
  // streamed as one. Nothing asks for them today (see the file
182
274
  // header); the guard is here so that a model that volunteers one
@@ -190,7 +282,7 @@ export function gemini(options = {}) {
190
282
  }
191
283
  }
192
284
  }
193
- const toolCalls = functionCalls.map((fc) => toLLMToolCall(fc, nextToolCallId));
285
+ const toolCalls = functionParts.map((part) => toLLMToolCall(part, nextToolCallId));
194
286
  const response = {
195
287
  content: textParts.join(''),
196
288
  toolCalls,
@@ -207,12 +299,40 @@ export function gemini(options = {}) {
207
299
  yield { tokenIndex, content: '', done: true, response };
208
300
  }
209
301
  catch (err) {
210
- throw wrap(err);
302
+ throw wrap(err, lease.apiKey);
211
303
  }
212
304
  },
213
305
  };
214
306
  return provider;
215
307
  }
308
+ /**
309
+ * The model this request is for — and the ONE refusal the doors do not share.
310
+ *
311
+ * A request naming a model wins, always. The shorthand `'gemini'` resolves to
312
+ * the door's default, and the Gemini API door HAS no default (see
313
+ * {@link GeminiProviderOptions.defaultModel}): the one this package used to
314
+ * send was measured returning HTTP 404 on that door for a new account.
315
+ *
316
+ * Refused here rather than at construction because a consumer who always names
317
+ * a model never needs a default, and a factory that refused them at the call
318
+ * site they typed would be charging everyone for a setting only some use.
319
+ */
320
+ function resolveModel(requested, defaultModel, door) {
321
+ if (requested !== MODEL_SHORTHAND)
322
+ return requested;
323
+ if (defaultModel !== undefined)
324
+ return defaultModel;
325
+ throw new Error(`gemini: model 'gemini' is a shorthand for this door's default model, and the ` +
326
+ `${door === 'vertex' ? 'Vertex' : 'Gemini API (AI Studio)'} door has no default.\n` +
327
+ " A live field trial called that door with this package's old default, " +
328
+ "'gemini-2.5-flash', and Google answered 404: \"This model models/gemini-2.5-flash is no " +
329
+ 'longer available to new users." Sending it anyway would fail on YOUR first call, after ' +
330
+ 'the request was built and paid for in latency.\n' +
331
+ " Fix: gemini({ apiKey, defaultModel: 'the-model-your-key-can-use' })\n" +
332
+ " Or: name the model per call — Agent.create({ model: 'gemini-3.1-flash-lite' }).\n" +
333
+ ' On VERTEX the shorthand still resolves — to gemini-2.5-flash, which the same trial ran ' +
334
+ 'end to end (Google retires it 2026-10-16).');
335
+ }
216
336
  /**
217
337
  * Class form for consumers who prefer `new GeminiProvider(...)` over the
218
338
  * `gemini(...)` factory. Identical behavior; trivial wrapper.
@@ -237,7 +357,7 @@ export class GeminiProvider {
237
357
  }
238
358
  }
239
359
  // ─── Internals ──────────────────────────────────────────────────────
240
- function buildParams(req, defaultModel, defaultMaxTokens) {
360
+ function buildParams(req, model, defaultMaxTokens) {
241
361
  const config = {};
242
362
  // The system prompt is a top-level field, not a turn — see
243
363
  // CARRIES_IN_MESSAGES.
@@ -271,7 +391,7 @@ function buildParams(req, defaultModel, defaultMaxTokens) {
271
391
  };
272
392
  }
273
393
  return {
274
- model: req.model === 'gemini' ? defaultModel : req.model,
394
+ model,
275
395
  contents: toGeminiContents(req.messages),
276
396
  ...(Object.keys(config).length > 0 && { config }),
277
397
  };
@@ -282,7 +402,9 @@ function buildParams(req, defaultModel, defaultMaxTokens) {
282
402
  * Key transforms:
283
403
  * • `role: 'system'` is DROPPED — it rides `config.systemInstruction`.
284
404
  * • `role: 'assistant'` becomes `role: 'model'`, with `toolCalls` restored as
285
- * `functionCall` parts so a multi-turn tool conversation round-trips.
405
+ * `functionCall` parts so a multi-turn tool conversation round-trips —
406
+ * each one carrying back the `thoughtSignature` it arrived with, which is
407
+ * what makes the SECOND call of a tool loop legal on a current model.
286
408
  * • `role: 'tool'` becomes a `functionResponse` part inside a **user** turn,
287
409
  * which is where Gemini expects results. Consecutive tool messages merge
288
410
  * into ONE user turn, so a reply that called three tools is answered by one
@@ -303,7 +425,12 @@ function toGeminiContents(messages) {
303
425
  if (m.content)
304
426
  parts.push({ text: m.content });
305
427
  for (const tc of m.toolCalls ?? []) {
428
+ const signature = thoughtSignatureOf(tc.providerMeta);
306
429
  parts.push({
430
+ // Back on the PART, exactly where it came from and byte for byte.
431
+ // Absent when the model never sent one (a 2.5-series turn), because
432
+ // an invented signature is worse than a missing one.
433
+ ...(signature !== undefined && { thoughtSignature: signature }),
307
434
  functionCall: {
308
435
  // Only an id GEMINI issued goes back to Gemini — see
309
436
  // SYNTHETIC_ID_PREFIX.
@@ -348,6 +475,20 @@ function toGeminiContents(messages) {
348
475
  function isRealId(id) {
349
476
  return id !== undefined && id.length > 0 && !id.startsWith(SYNTHETIC_ID_PREFIX);
350
477
  }
478
+ /** The key this adapter parks a thought signature under on `providerMeta`. */
479
+ const THOUGHT_SIGNATURE = 'thoughtSignature';
480
+ /**
481
+ * A signature off the port's neutral metadata bag — or nothing.
482
+ *
483
+ * Shape-checked rather than trusted: `providerMeta` survives a checkpoint, a
484
+ * `structuredClone` and whatever a consumer did to the history in between, and
485
+ * a non-string in the `thoughtSignature` field would go on the wire as a
486
+ * garbled signature, which the service rejects less clearly than a missing one.
487
+ */
488
+ function thoughtSignatureOf(meta) {
489
+ const raw = meta?.[THOUGHT_SIGNATURE];
490
+ return typeof raw === 'string' && raw.length > 0 ? raw : undefined;
491
+ }
351
492
  /**
352
493
  * `LLMToolSchema` → `FunctionDeclaration`, with the schema untranslated.
353
494
  *
@@ -371,7 +512,7 @@ function fromGeminiResponse(response, nextToolCallId) {
371
512
  const toolCalls = [];
372
513
  for (const part of candidate?.content?.parts ?? []) {
373
514
  if (part.functionCall)
374
- toolCalls.push(toLLMToolCall(part.functionCall, nextToolCallId));
515
+ toolCalls.push(toLLMToolCall(part, nextToolCallId));
375
516
  // Thought summaries are not the answer. See the header.
376
517
  if (part.thought)
377
518
  continue;
@@ -386,11 +527,24 @@ function fromGeminiResponse(response, nextToolCallId) {
386
527
  ...(response.responseId !== undefined && { providerRef: response.responseId }),
387
528
  };
388
529
  }
389
- function toLLMToolCall(fc, nextToolCallId) {
530
+ /**
531
+ * One `functionCall` PART → one port tool call, signature included.
532
+ *
533
+ * Takes the part rather than the `functionCall` because the two fields that
534
+ * have to travel together live at different levels: the call is inside the
535
+ * part, the signature is on it.
536
+ */
537
+ function toLLMToolCall(part, nextToolCallId) {
538
+ const fc = part.functionCall ?? {};
539
+ const signature = part.thoughtSignature;
390
540
  return {
391
541
  id: fc.id && fc.id.length > 0 ? fc.id : nextToolCallId(),
392
542
  name: fc.name ?? '',
393
543
  args: { ...(fc.args ?? {}) },
544
+ // Only when there IS one. An empty bag on every tool call would be noise
545
+ // in every recording, every checkpoint and every narrative line.
546
+ ...(typeof signature === 'string' &&
547
+ signature.length > 0 && { providerMeta: { [THOUGHT_SIGNATURE]: signature } }),
394
548
  };
395
549
  }
396
550
  /**
@@ -405,6 +559,14 @@ function toLLMToolCall(fc, nextToolCallId) {
405
559
  * `cacheWrite` stays undefined on purpose: Gemini's context caching is created
406
560
  * by a separate `caches.create` call that this adapter does not make, so there
407
561
  * is no write for a `generateContent` turn to report.
562
+ *
563
+ * **`output` does not include thinking on this wire, and that matters for
564
+ * money.** A field trial's 256-token stream came back `input 21, output 9,
565
+ * thinking 243` — 243 tokens that were spent, were billed, and appear in
566
+ * neither `input` nor `output` (FINDINGS "Failure 5"). Anything adding
567
+ * `input + output` to estimate a Gemini turn is under-counting by whatever the
568
+ * model thought. `usage.thinking` is the number to add, and it now survives all
569
+ * the way to `agentfootprint.stream.llm_end`.
408
570
  */
409
571
  function toUsage(usage) {
410
572
  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,MAAM,IAAI,GAAG,CAAC,GAAY,EAAS,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErE,MAAM,QAAQ,GAAgB;QAC5B,IAAI,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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`