dsh-vertex-argon 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  `dsh-vertex-argon` 为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) 提供完整的 **Gemini 4 Argon** 接入支持,自动聚合 **Google Vertex AI**(服务账号 / ADC)与 **Google Gemini Developer API**(AI Studio API Key)双通道,修复内置 `pi-ai` 适配器误传 `thinkingBudget` 导致的 `HTTP 400` 报错,完整打通原生三档思考、思维链(Thought Summaries)、`v1beta1` **Long Decode 跨段长生成自动续传**与带签名的多轮工具调用。
16
16
 
17
- Current release: **[1.2.0](https://github.com/higekibaka/dsh-vertex-argon)** · [npm](https://www.npmjs.com/package/dsh-vertex-argon)
17
+ Current release: **[1.3.0](https://github.com/higekibaka/dsh-vertex-argon)** · [npm](https://www.npmjs.com/package/dsh-vertex-argon)
18
18
 
19
19
  ---
20
20
 
@@ -25,9 +25,9 @@ Current release: **[1.2.0](https://github.com/higekibaka/dsh-vertex-argon)** ·
25
25
  | **思考控制参数** | 误判为旧模型并发送 `thinkingBudget: -1`,触发云端 `HTTP 400` | 原生发送 `thinkingLevel: "LOW" \| "MEDIUM" \| "HIGH"`,绝不传 `thinkingBudget` |
26
26
  | **思维链(思考摘要)** | 手动新增模型默认无 `reasoning` 标记,不请求摘要 | 固定开启 `includeThoughts: true`,流式解析 `thought: true` 实时展示思维链 |
27
27
  | **多轮工具调用回传** | 路由切换或签名不对齐时易丢失上下文 | 保持 `provider` / `model` 与 `thoughtSignature` 签名全链路一致 |
28
- | **Long Decode 长生成** | Vertex 硬编码 `v1` 且锁死 64K,遇 `CONTINUATION` 直接抛错断流 | 自动切换 `v1beta1` 跨 64K 分段续传(最高 512K)、断流检查点恢复,按首跳输入上报水位防误压缩 |
28
+ | **Long Decode 长生成** | Vertex 硬编码 `v1` 且锁死 64K,遇 `CONTINUATION` 直接抛错断流 | 自动切换 `v1beta1` 跨 64K 分段零延迟续传(最高 512K)、断流检查点指数退避恢复,按首跳输入上报水位防误压缩 |
29
29
  | **采样参数净化** | 可能携带被 Argon 拒绝或忽略的采样字段 | 自动剥离 `temperature`、`topP`、`topK` 等无效采样参数 |
30
- | **通道管理与设置** | 需手改 `cordis.patch.yml` 并反复排查校验报错 | 自动检测双通道 + 内置 **设置 → Vertex Argon** 图形化实时调节页面 |
30
+ | **通道管理与设置** | 需手改 `cordis.patch.yml` 并反复排查校验报错 | 自动检测双通道 + 内置 **设置 → Vertex Argon** 实时调节与「最近请求诊断摘要」折叠面板 |
31
31
 
32
32
  ---
33
33
 
@@ -108,6 +108,12 @@ dsh plugin --profile web add dsh-vertex-argon
108
108
  | `maxTokens` | `65536` | `1` – `524288` | 最大输出预算(默认 `65,536`;开启 `longDecode` 后最高可设为 `524,288` 跨 64K 分段续传) |
109
109
  | `contextWindow` | `1048576` | `1` – `1048576` | 输入、思考与输出共享的总上下文窗口(官方上限为 `1,048,576`) |
110
110
 
111
+ ### 🩺 结构化请求诊断与「最近请求诊断摘要」面板(v1.3.0+)
112
+
113
+ - **有界持久化存储(`vertex_argon_diagnostics`)**:通过宿主 `storageDomain` 自动在 `~/.dsh/storages/vertex_argon_diagnostics/requests/` 下记录最近 **200 条**请求元数据(单请求最多记录 16 跳,异步队列上限 32 条,严格脱敏,绝不保存对话正文、图片、`continuationToken` 明文或密钥)。
114
+ - **逐跳与双轨 Token 追踪**:完整记录每次请求的通道(`google-vertex` / `google-generative-ai`)、API 版本(`v1beta1` / `v1`)、思考档位、每一跳的触发原因(`initial` / `continuation` / `checkpoint-reconnect` / `retry-same-checkpoint`)、退避等待耗时(`backoffDelayMs`)、底层传输错误码白名单(如 `ECONNRESET`、`ETIMEDOUT`)以及上报水位(首跳输入)与多跳累计计费 Token 对比。
115
+ - **图形化折叠面板**:在 **设置 → Vertex Argon** 页面底部点击展开 **「最近请求诊断摘要」**,即可直接查看最近 20 次请求的耗时、跳数、断流自愈状态与逐跳明细。
116
+
111
117
  ---
112
118
 
113
119
  ## ⚠️ 与 `billion-context` 配合使用的兼容性说明
package/adapter.js CHANGED
@@ -2,6 +2,7 @@ import { access } from 'node:fs/promises'
2
2
  import { homedir } from 'node:os'
3
3
  import { resolve } from 'node:path'
4
4
  import { shared } from './runtime.js'
5
+ import { createArgonDiagnosticTracker } from './diagnostics.js'
5
6
  const { LlmAdapter, LlmError, resolveRetryPolicy, resolveImageAttachmentAccess } = await shared('@deepseek-ai/dsh-llm')
6
7
  const { PiAiAdapter } = await shared('@deepseek-ai/dsh-llm-pi-ai')
7
8
  const { launchEnvironmentOf } = await shared('@deepseek-ai/dsh-launch-environment')
@@ -17,6 +18,9 @@ export const LEVELS = ['low', 'medium', 'high']
17
18
  export const MAX_SINGLE_CALL_TOKENS = 65536
18
19
  export const MAX_LONG_DECODE_TOKENS = 524288
19
20
  export const MAX_CONTINUATION_HOPS = 32
21
+ export const RECONNECT_INITIAL_DELAY_MS = 500
22
+ export const RECONNECT_MAX_DELAY_MS = 10000
23
+ export const RECONNECT_JITTER_RATIO = 0.1
20
24
  const MAX_STREAM_RECONNECTS_WITHOUT_PROGRESS = 3
21
25
  const COMPACTION_HEADROOM_FLOOR = 131072
22
26
  const ENV_KEYS = ['GOOGLE_APPLICATION_CREDENTIALS', 'GOOGLE_CLOUD_PROJECT', 'GCLOUD_PROJECT', 'GOOGLE_CLOUD_LOCATION', 'GOOGLE_CLOUD_API_KEY']
@@ -91,17 +95,55 @@ function isAbortedError(err, signal) {
91
95
  return Boolean(signal?.aborted) || (err instanceof Error && err.name === 'AbortError')
92
96
  }
93
97
 
94
- function isInitialApiRejection(err, receivedAnyChunk) {
95
- return Boolean(
96
- !receivedAnyChunk &&
97
- err instanceof Error &&
98
- (err.name === 'ApiError' || ('status' in err && typeof err.status === 'number')),
99
- )
98
+ function isNonRetryableApiRejection(err, receivedAnyChunk, hopCount, hasCheckpointToken) {
99
+ if (receivedAnyChunk) return false
100
+ if (!(err instanceof Error && (err.name === 'ApiError' || ('status' in err && typeof err.status === 'number')))) {
101
+ return false
102
+ }
103
+ if (!hasCheckpointToken || hopCount <= 1) return true
104
+ const status = typeof err.status === 'number' ? err.status : 0
105
+ if (status === 408 || status === 429 || (status >= 500 && status < 600)) return false
106
+ return true
107
+ }
108
+
109
+ export function computeReconnectDelayMs(attempt, options = {}) {
110
+ const initialDelayMs = options?.initialDelayMs ?? RECONNECT_INITIAL_DELAY_MS
111
+ if (!(initialDelayMs > 0)) return 0
112
+ const maxDelayMs = options?.maxDelayMs ?? RECONNECT_MAX_DELAY_MS
113
+ const jitterRatio = options?.jitterRatio ?? RECONNECT_JITTER_RATIO
114
+ const random = options?.random ?? Math.random
115
+ const exponent = Math.min(Math.max(0, attempt - 1), 10)
116
+ const exponential = Math.min(initialDelayMs * (2 ** exponent), maxDelayMs)
117
+ const jitter = 1 - jitterRatio + 2 * jitterRatio * random()
118
+ return Math.round(Math.min(exponential * jitter, maxDelayMs))
119
+ }
120
+
121
+ function waitWithAbort(delayMs, signal) {
122
+ if (!(delayMs > 0)) return Promise.resolve()
123
+ if (signal?.aborted) {
124
+ const err = new Error('The operation was aborted')
125
+ err.name = 'AbortError'
126
+ return Promise.reject(err)
127
+ }
128
+ return new Promise((resolve, reject) => {
129
+ const timer = setTimeout(() => {
130
+ signal?.removeEventListener?.('abort', onAbort)
131
+ resolve()
132
+ }, delayMs)
133
+ function onAbort() {
134
+ clearTimeout(timer)
135
+ const err = new Error('The operation was aborted')
136
+ err.name = 'AbortError'
137
+ reject(err)
138
+ }
139
+ signal?.addEventListener?.('abort', onAbort, { once: true })
140
+ })
100
141
  }
101
142
 
102
143
  async function continueArgonRequestStream(apiClient, origRequestStream, request, meta) {
103
144
  const { [ARGON_LONG_DECODE_SYMBOL]: _, ...restHttpOptions } = request?.httpOptions ?? {}
104
145
  const enableContinuation = meta?.enabled !== false
146
+ const tracker = meta?.tracker
105
147
  if (
106
148
  enableContinuation &&
107
149
  typeof apiClient?.isVertexAI === 'function' &&
@@ -111,17 +153,40 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
111
153
  ) {
112
154
  restHttpOptions.apiVersion = 'v1beta1'
113
155
  }
156
+ const effectiveApiVersion =
157
+ restHttpOptions.apiVersion || apiClient?.clientOptions?.httpOptions?.apiVersion || 'v1beta1'
158
+ tracker?.setApiVersion(effectiveApiVersion)
114
159
  const hopHttpOptions = Object.keys(restHttpOptions).length > 0 ? restHttpOptions : undefined
115
160
  const firstReq = { ...request, httpOptions: hopHttpOptions }
116
- const firstStream = await origRequestStream.call(apiClient, firstReq)
117
- if (!enableContinuation) return firstStream
161
+ const hop1Tracker = tracker?.beginHop({
162
+ hopIndex: 1,
163
+ trigger: 'initial',
164
+ usedContinuationToken: false,
165
+ backoffDelayMs: 0,
166
+ body: firstReq.body,
167
+ })
168
+ let firstStream
169
+ try {
170
+ firstStream = await origRequestStream.call(apiClient, firstReq)
171
+ } catch (error) {
172
+ hop1Tracker?.finish({
173
+ error,
174
+ aborted: isAbortedError(error, request?.abortSignal),
175
+ })
176
+ throw error
177
+ }
178
+ if (!enableContinuation && !tracker) return firstStream
118
179
 
119
180
  return (async function* () {
120
181
  let baseBodyObj
121
182
  let resumeToken
122
183
  let reconnectsWithoutProgress = 0
184
+ let consecutiveReconnectFailures = 0
123
185
  let lastError
124
186
  let hopCount = 0
187
+ let nextHopTrigger = 'initial'
188
+ let nextHopBackoffMs = 0
189
+ let nextHopBody = firstReq.body
125
190
  let initialPromptTokens
126
191
  let initialCachedTokens
127
192
  let completedCandidatesTokens = 0
@@ -135,6 +200,16 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
135
200
  while (true) {
136
201
  hopCount += 1
137
202
  const hopStartToken = resumeToken
203
+ const hopTracker =
204
+ hopCount === 1
205
+ ? hop1Tracker
206
+ : tracker?.beginHop({
207
+ hopIndex: hopCount,
208
+ trigger: nextHopTrigger,
209
+ usedContinuationToken: Boolean(hopStartToken),
210
+ backoffDelayMs: nextHopBackoffMs,
211
+ body: nextHopBody,
212
+ })
138
213
  let hopToken
139
214
  let hopFinishReason
140
215
  let hopHasPromptFeedback = false
@@ -156,6 +231,13 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
156
231
  }
157
232
  let outRaw = raw
158
233
  const candidate = Array.isArray(raw.candidates) ? raw.candidates[0] : undefined
234
+ hopTracker?.onChunk({
235
+ status: 200,
236
+ hasCheckpoint: Boolean(
237
+ candidate && typeof candidate.continuationToken === 'string' && candidate.continuationToken.length > 0,
238
+ ),
239
+ finishReason: candidate?.finishReason,
240
+ })
159
241
  if (candidate && typeof candidate === 'object') {
160
242
  if (typeof candidate.continuationToken === 'string' && candidate.continuationToken.length > 0) {
161
243
  hopToken = candidate.continuationToken
@@ -169,6 +251,7 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
169
251
  hopHasYieldedContent = true
170
252
  }
171
253
  const canContinueHop =
254
+ enableContinuation &&
172
255
  !hopHasPromptFeedback &&
173
256
  Boolean(hopToken) &&
174
257
  hopToken !== hopStartToken &&
@@ -245,13 +328,29 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
245
328
  completedBilledPromptTokens += hopUsage.prompt
246
329
  completedBilledCachedTokens += hopUsage.cached
247
330
  completedBilledTotalTokens += hopUsage.total
331
+ tracker?.recordTokenUsage({
332
+ reportedInputTokens: initialPromptTokens,
333
+ reportedCacheTokens: initialCachedTokens ?? 0,
334
+ outputTokens: completedCandidatesTokens,
335
+ thoughtsTokens: completedThoughtsTokens,
336
+ billedPromptTokens: completedBilledPromptTokens,
337
+ billedCachedTokens: completedBilledCachedTokens,
338
+ billedTotalTokens: completedBilledTotalTokens,
339
+ })
248
340
  }
249
341
 
342
+ const abortedHop = Boolean(hopError && isAbortedError(hopError.error, request?.abortSignal))
250
343
  if (
251
344
  hopError &&
252
- (isAbortedError(hopError.error, request?.abortSignal) ||
253
- isInitialApiRejection(hopError.error, hopReceivedAnyChunk))
345
+ (abortedHop ||
346
+ isNonRetryableApiRejection(hopError.error, hopReceivedAnyChunk, hopCount, Boolean(hopToken || hopStartToken)))
254
347
  ) {
348
+ hopTracker?.finish({
349
+ error: hopError.error,
350
+ aborted: abortedHop,
351
+ finishReason: hopFinishReason,
352
+ continued: false,
353
+ })
255
354
  throw hopError.error
256
355
  }
257
356
 
@@ -260,36 +359,59 @@ async function continueArgonRequestStream(apiClient, origRequestStream, request,
260
359
  if (hopError) lastError = hopError
261
360
  else if (madeProgress) lastError = undefined
262
361
 
263
- if (hopCount >= MAX_CONTINUATION_HOPS || hopHasPromptFeedback) {
362
+ if (!enableContinuation || hopCount >= MAX_CONTINUATION_HOPS || hopHasPromptFeedback) {
264
363
  resumeToken = undefined
265
364
  } else if (hopFinishReason !== undefined) {
266
365
  if (hopFinishReason === 'CONTINUATION' && hasNewToken) {
267
366
  resumeToken = hopToken
268
367
  reconnectsWithoutProgress = 0
368
+ consecutiveReconnectFailures = hopError ? 1 : 0
369
+ nextHopTrigger = hopError ? 'checkpoint-reconnect' : 'continuation'
269
370
  } else {
270
371
  resumeToken = undefined
271
372
  reconnectsWithoutProgress = 0
373
+ consecutiveReconnectFailures = 0
272
374
  }
273
375
  } else if (hasNewToken) {
274
376
  resumeToken = hopToken
275
377
  reconnectsWithoutProgress = 0
378
+ consecutiveReconnectFailures = 1
379
+ nextHopTrigger = 'checkpoint-reconnect'
276
380
  } else if (!hopHasYieldedContent && hopStartToken && reconnectsWithoutProgress < MAX_STREAM_RECONNECTS_WITHOUT_PROGRESS) {
277
381
  resumeToken = hopStartToken
278
382
  reconnectsWithoutProgress += 1
383
+ consecutiveReconnectFailures += 1
384
+ nextHopTrigger = 'retry-same-checkpoint'
279
385
  } else {
280
386
  resumeToken = undefined
281
387
  }
282
388
 
283
389
  const canResume =
390
+ enableContinuation &&
284
391
  Boolean(resumeToken) &&
285
392
  !hopHasPromptFeedback &&
286
393
  (hopFinishReason === 'CONTINUATION' || hopFinishReason === undefined)
287
394
 
395
+ hopTracker?.finish({
396
+ error: hopError?.error,
397
+ aborted: false,
398
+ finishReason: hopFinishReason,
399
+ continued: canResume && hopFinishReason === 'CONTINUATION' && !hopError,
400
+ })
401
+
288
402
  if (canResume) {
403
+ let delayMs = 0
404
+ if (consecutiveReconnectFailures > 0) {
405
+ delayMs = computeReconnectDelayMs(consecutiveReconnectFailures, meta?.reconnectBackoff)
406
+ await waitWithAbort(delayMs, request?.abortSignal)
407
+ }
289
408
  if (!baseBodyObj) baseBodyObj = JSON.parse(request.body)
409
+ const nextBody = JSON.stringify({ ...baseBodyObj, continuationToken: resumeToken })
410
+ nextHopBackoffMs = delayMs
411
+ nextHopBody = nextBody
290
412
  const nextReq = {
291
413
  ...request,
292
- body: JSON.stringify({ ...baseBodyObj, continuationToken: resumeToken }),
414
+ body: nextBody,
293
415
  httpOptions: hopHttpOptions,
294
416
  }
295
417
  openHop = () => origRequestStream.call(apiClient, nextReq)
@@ -344,24 +466,49 @@ export function ensureGemini4ApiClientPatch() {
344
466
  }
345
467
  }
346
468
 
347
- function wrapGemini4Stream(rawStream) {
469
+ function wrapGemini4Stream(rawStream, tracker, signal) {
348
470
  if (!rawStream || typeof rawStream[Symbol.asyncIterator] !== 'function') return rawStream
349
471
  return {
350
472
  [Symbol.asyncIterator]: async function* () {
351
- for await (const event of rawStream) {
352
- if (event?.type === 'error' && typeof event?.error?.errorMessage === 'string' && TRANSIENT_GEMINI_STOP_RE.test(event.error.errorMessage)) {
353
- yield {
354
- ...event,
355
- error: {
356
- ...event.error,
357
- errorMessage: `${event.error.errorMessage} (502 upstream transient finishReason)`,
358
- },
473
+ try {
474
+ for await (const event of rawStream) {
475
+ if (event?.type === 'done') {
476
+ const stop = event.message?.stopReason
477
+ const outcome = stop === 'toolUse' ? 'tool-calls' : stop === 'length' ? 'max-tokens' : 'done'
478
+ tracker?.finishStream({ outcome })
479
+ } else if (event?.type === 'error') {
480
+ const isTransient =
481
+ typeof event?.error?.errorMessage === 'string' &&
482
+ TRANSIENT_GEMINI_STOP_RE.test(event.error.errorMessage)
483
+ tracker?.finishStream({
484
+ outcome: signal?.aborted ? 'aborted' : 'error',
485
+ error: event.error,
486
+ transientFinishReason: isTransient,
487
+ })
488
+ if (isTransient) {
489
+ yield {
490
+ ...event,
491
+ error: {
492
+ ...event.error,
493
+ errorMessage: `${event.error.errorMessage} (502 upstream transient finishReason)`,
494
+ },
495
+ }
496
+ continue
497
+ }
359
498
  }
360
- continue
499
+ yield event
361
500
  }
362
- yield event
501
+ } catch (error) {
502
+ tracker?.finishStream({
503
+ outcome: signal?.aborted ? 'aborted' : 'error',
504
+ error,
505
+ })
506
+ throw error
507
+ } finally {
508
+ tracker?.finalize(Boolean(signal?.aborted))
363
509
  }
364
510
  },
511
+ ...(typeof rawStream.result === 'function' ? { result: rawStream.result.bind(rawStream) } : {}),
365
512
  }
366
513
  }
367
514
 
@@ -373,6 +520,7 @@ export function gemini4StreamSimple(
373
520
  defaultLevel = 'medium',
374
521
  upstreamModelId = requestModel.id,
375
522
  longDecode = true,
523
+ recordDiagnostic,
376
524
  ) {
377
525
  ensureGemini4ApiClientPatch()
378
526
  const fallback = defaultLevel ?? (/cyber-permissive/i.test(requestModel?.id ?? '') ? 'high' : 'medium')
@@ -386,41 +534,60 @@ export function gemini4StreamSimple(
386
534
  longDecode === false && typeof requestedMaxTokens === 'number' && requestedMaxTokens > MAX_SINGLE_CALL_TOKENS
387
535
  ? MAX_SINGLE_CALL_TOKENS
388
536
  : requestedMaxTokens
389
- return wrapGemini4Stream(nativeStream(requestModel, context, {
390
- ...rest,
391
- maxTokens: effectiveMaxTokens,
392
- async onPayload(payload, payloadModel) {
393
- const replacement = await prior?.(payload, payloadModel)
394
- const body = replacement === undefined ? payload : replacement
395
- if (!body || typeof body !== 'object' || Array.isArray(body) || !Array.isArray(body.contents) || !body.config || typeof body.config !== 'object' || Array.isArray(body.config)) {
396
- throw new LlmError('Gemini 4 Argon received an incompatible native payload.', 'INVALID_REQUEST')
397
- }
398
- if (body.model !== requestModel.id && body.model !== upstreamModelId) {
399
- throw new LlmError('Gemini 4 Argon received an incompatible model payload.', 'INVALID_REQUEST')
400
- }
401
- const { temperature: _t, topP: _tp, topK: _tk, candidateCount: _cc, frequencyPenalty: _fp, presencePenalty: _pp, ...cleanConfig } = body.config
402
- const prevHttpOptions =
403
- cleanConfig.httpOptions && typeof cleanConfig.httpOptions === 'object' && !Array.isArray(cleanConfig.httpOptions)
404
- ? cleanConfig.httpOptions
405
- : {}
406
- return {
407
- ...body,
408
- model: upstreamModelId,
409
- config: {
410
- ...cleanConfig,
411
- automaticContinuation: false,
412
- thinkingConfig: { thinkingLevel: level.toUpperCase(), includeThoughts: true },
413
- httpOptions: {
414
- ...prevHttpOptions,
415
- [ARGON_LONG_DECODE_SYMBOL]: { enabled: longDecode !== false },
416
- },
417
- },
418
- }
537
+ const tracker = createArgonDiagnosticTracker(
538
+ {
539
+ model: requestModel?.id,
540
+ route: requestModel?.api,
541
+ apiVersion: longDecode === false ? 'v1' : 'v1beta1',
542
+ thinkingLevel: level.toUpperCase(),
543
+ longDecode: longDecode !== false,
544
+ maxTokens: effectiveMaxTokens,
545
+ sessionId: options.sessionId,
419
546
  },
420
- }))
547
+ recordDiagnostic,
548
+ )
549
+ return wrapGemini4Stream(
550
+ nativeStream(requestModel, context, {
551
+ ...rest,
552
+ maxTokens: effectiveMaxTokens,
553
+ async onPayload(payload, payloadModel) {
554
+ const replacement = await prior?.(payload, payloadModel)
555
+ const body = replacement === undefined ? payload : replacement
556
+ if (!body || typeof body !== 'object' || Array.isArray(body) || !Array.isArray(body.contents) || !body.config || typeof body.config !== 'object' || Array.isArray(body.config)) {
557
+ throw new LlmError('Gemini 4 Argon received an incompatible native payload.', 'INVALID_REQUEST')
558
+ }
559
+ if (body.model !== requestModel.id && body.model !== upstreamModelId) {
560
+ throw new LlmError('Gemini 4 Argon received an incompatible model payload.', 'INVALID_REQUEST')
561
+ }
562
+ const { temperature: _t, topP: _tp, topK: _tk, candidateCount: _cc, frequencyPenalty: _fp, presencePenalty: _pp, ...cleanConfig } = body.config
563
+ const prevHttpOptions =
564
+ cleanConfig.httpOptions && typeof cleanConfig.httpOptions === 'object' && !Array.isArray(cleanConfig.httpOptions)
565
+ ? cleanConfig.httpOptions
566
+ : {}
567
+ return {
568
+ ...body,
569
+ model: upstreamModelId,
570
+ config: {
571
+ ...cleanConfig,
572
+ automaticContinuation: false,
573
+ thinkingConfig: { thinkingLevel: level.toUpperCase(), includeThoughts: true },
574
+ httpOptions: {
575
+ ...prevHttpOptions,
576
+ [ARGON_LONG_DECODE_SYMBOL]: {
577
+ enabled: longDecode !== false,
578
+ tracker,
579
+ },
580
+ },
581
+ },
582
+ }
583
+ },
584
+ }),
585
+ tracker,
586
+ options.signal,
587
+ )
421
588
  }
422
589
 
423
- export function installGemini4PiAiPatch() {
590
+ export function installGemini4PiAiPatch(recordDiagnostic) {
424
591
  const unpatchApiClient = ensureGemini4ApiClientPatch()
425
592
  const proto = PiAiAdapter?.prototype
426
593
  if (!proto || typeof proto.current !== 'function') return unpatchApiClient
@@ -445,7 +612,7 @@ export function installGemini4PiAiPatch() {
445
612
  patchedProviders.set(piProvider, origStreamSimple)
446
613
  piProvider.streamSimple = function (requestModel, context, options = {}) {
447
614
  if (isGemini4Model(requestModel)) {
448
- return gemini4StreamSimple((m, c, o) => piProvider.stream(m, c, o), requestModel, context, options, defaultReasoning, requestModel.id, true)
615
+ return gemini4StreamSimple((m, c, o) => piProvider.stream(m, c, o), requestModel, context, options, defaultReasoning, requestModel.id, true, recordDiagnostic)
449
616
  }
450
617
  return origStreamSimple.call(this, requestModel, context, options)
451
618
  }
@@ -496,7 +663,7 @@ export function resolveConfigValues(raw = {}) {
496
663
  }
497
664
 
498
665
  /** Serve both Vertex AI Argon and Gemini API (google) Argon under the unified plugin group. */
499
- export function argonProvider(nativeVertex, models, defaultLevel = 'medium', nativeGoogle = googleProvider(), longDecode = true) {
666
+ export function argonProvider(nativeVertex, models, defaultLevel = 'medium', nativeGoogle = googleProvider(), longDecode = true, recordDiagnostic) {
500
667
  const modelMap = new Map((Array.isArray(models) ? models : [models]).map(m => [m.id, m]))
501
668
  return {
502
669
  id: PROVIDER,
@@ -522,6 +689,7 @@ export function argonProvider(nativeVertex, models, defaultLevel = 'medium', nat
522
689
  defaultLevel,
523
690
  MODEL,
524
691
  longDecode,
692
+ recordDiagnostic,
525
693
  )
526
694
  }
527
695
  if (requestModel.api !== 'google-vertex') {
@@ -535,6 +703,7 @@ export function argonProvider(nativeVertex, models, defaultLevel = 'medium', nat
535
703
  defaultLevel,
536
704
  MODEL,
537
705
  longDecode,
706
+ recordDiagnostic,
538
707
  )
539
708
  },
540
709
  }
@@ -558,7 +727,7 @@ export class ArgonAdapter extends LlmAdapter {
558
727
  stream(options) { return this.inner.stream(options) }
559
728
  }
560
729
 
561
- export function createArgonAdapter(ctx, configInput, nativeVertex = googleVertexProvider(), nativeGoogle = googleProvider()) {
730
+ export function createArgonAdapter(ctx, configInput, nativeVertex = googleVertexProvider(), nativeGoogle = googleProvider(), recordDiagnostic) {
562
731
  resolveConfigValues(configInput)
563
732
  const environment = launchEnvironmentOf(ctx)
564
733
  const resolveSecret = async name => {
@@ -649,7 +818,7 @@ export function createArgonAdapter(ctx, configInput, nativeVertex = googleVertex
649
818
  })
650
819
  }
651
820
  const configuredMaxTokens = new Map(models.map(m => [m.id, cfg.maxTokens]))
652
- const provider = argonProvider({ ...nativeVertex, auth }, models, cfg.reasoning, nativeGoogle, cfg.longDecode)
821
+ const provider = argonProvider({ ...nativeVertex, auth }, models, cfg.reasoning, nativeGoogle, cfg.longDecode, recordDiagnostic)
653
822
  cachedKey = key
654
823
  cachedProfiles = new Map([[PROVIDER, {
655
824
  provider: PROVIDER,