@steve31415/baselib 3.73.0 → 3.74.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.
package/dist/http.d.ts CHANGED
@@ -6,6 +6,18 @@ export interface RequestLoggingOptions {
6
6
  * `?app=`, so one service's sockets can be told apart by app); fields
7
7
  * whose value is undefined are left out. */
8
8
  meta?: (c: Context) => Record<string, unknown>;
9
+ /** Await `logger.flush()` after the exit line, before the response goes
10
+ * out, for requests where it returns true. On request-billed Cloud Run
11
+ * the CPU is throttled to almost nothing once the response is sent, so
12
+ * lines left for the shipper's batch timer — the handler's last lines and
13
+ * this exit line itself — often wait for the next request, and their
14
+ * 10 s ship attempt times out (radar's 5-minute scheduler pokes, task
15
+ * acb5a5e1, 2026-11-24). A handler's own `await logger.flush()` cannot
16
+ * cover the exit line, which is logged after the handler returns. Use it
17
+ * for machine callers (Scheduler pokes, `/internal/*`), not for user
18
+ * requests: it adds one Axiom round trip (bounded by the shipper's
19
+ * attempt timeout) to the response. */
20
+ flush?: (c: Context) => boolean;
9
21
  }
10
22
  /** One INFO line per request on exit (method, path, status, elapsed,
11
23
  * identity, plus `options.meta`); /health excluded. Entry-point detail
package/dist/http.js CHANGED
@@ -26,6 +26,8 @@ export function requestLogging(logger, options = {}) {
26
26
  ...(identity ? { identity: identity.email } : {}),
27
27
  ...Object.fromEntries(extra),
28
28
  });
29
+ if (options.flush?.(c))
30
+ await logger.flush();
29
31
  });
30
32
  }
31
33
  /** The address of the client that connected to Google's edge, read from
@@ -153,7 +153,19 @@ export const geminiProvider = {
153
153
  }
154
154
  const data = JSON.parse(responseText);
155
155
  const latencyMs = Date.now() - startTime;
156
- const text = data.candidates?.[0]?.content?.parts?.[0]?.text || '';
156
+ // The answer is every non-thought text part of the first candidate, in
157
+ // order — not just part 0. Gemini may split one answer over several
158
+ // parts: live on gemini-3.6-flash with audio at thinking level `low`
159
+ // (2026-11-28), part 0 held a stray reasoning fragment and part 1 the
160
+ // whole real transcript, so reading part 0 alone stored the fragment and
161
+ // dropped the transcript (Mirror row 3271ad65). Parts flagged
162
+ // `thought: true` are reasoning summaries, sent only when a request asks
163
+ // for them (`includeThoughts`, which this adapter never sets) and never
164
+ // part of the answer. Reasoning the model writes into an ordinary part is
165
+ // indistinguishable from the answer here: see "Audio input" in LLM.md.
166
+ const answerParts = (data.candidates?.[0]?.content?.parts ?? [])
167
+ .filter((part) => part.thought !== true && typeof part.text === 'string');
168
+ const text = answerParts.map((part) => part.text).join('');
157
169
  // totalTokenCount = promptTokenCount (cached part included) + candidates
158
170
  // + thoughts (verified live on 3.6 Flash, 2026-11-07). Google bills
159
171
  // thoughts at the output rate and implicit-cache hits at a tenth of the
@@ -180,6 +192,8 @@ export const geminiProvider = {
180
192
  status: response.status, latencyMs, tokensUsed, outputTokens, finishReason,
181
193
  ...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
182
194
  ...(cacheReadTokens !== undefined ? { cacheReadTokens } : {}),
195
+ // A split answer is rare and has meant leaked reasoning (above).
196
+ ...(answerParts.length > 1 ? { textParts: answerParts.length } : {}),
183
197
  ...(request.callSite ? { callSite: request.callSite } : {}),
184
198
  });
185
199
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.73.0",
3
+ "version": "3.74.1",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",