dsh-vertex-argon 1.2.1 → 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 +8 -2
- package/adapter.js +173 -53
- package/client.js +338 -5
- package/diagnostic-store.js +258 -0
- package/diagnostics.js +259 -0
- package/index.js +45 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -2
package/client.js
CHANGED
|
@@ -4,6 +4,52 @@ window.__ModuleLoader__.load({
|
|
|
4
4
|
const React = require('react')
|
|
5
5
|
const h = React.createElement
|
|
6
6
|
const ns = 'settings.localVertexArgon'
|
|
7
|
+
|
|
8
|
+
function parseListRecentRequest(value) {
|
|
9
|
+
if (value === undefined || value === null) return { limit: 20 }
|
|
10
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid diagnostics request')
|
|
11
|
+
const limit = value.limit === undefined ? 20 : Number(value.limit)
|
|
12
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error('Invalid diagnostics limit')
|
|
13
|
+
return { limit }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseListRecentResult(value) {
|
|
17
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid diagnostics response')
|
|
18
|
+
if (value.ok === false) {
|
|
19
|
+
if (typeof value.error !== 'string') throw new Error('Invalid diagnostics error response')
|
|
20
|
+
return value
|
|
21
|
+
}
|
|
22
|
+
if (value.ok !== true || !Array.isArray(value.records)) throw new Error('Invalid diagnostics records response')
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function diagnosticsCodec(direction) {
|
|
27
|
+
const schema = {
|
|
28
|
+
parse: value => (direction === 'request' ? parseListRecentRequest(value) : parseListRecentResult(value)),
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
mode: 'strict',
|
|
32
|
+
typeSymbol: 'dsh-vertex-argon/listRecent' + (direction === 'request' ? 'Request' : 'Result'),
|
|
33
|
+
schema,
|
|
34
|
+
create: () => schema,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const DIAGNOSTICS_INVOCATION = {
|
|
39
|
+
id: 'dsh-vertex-argon#vertexArgonDiagnostics/listRecent',
|
|
40
|
+
service: 'vertexArgonDiagnostics',
|
|
41
|
+
namespace: 'vertexArgonDiagnostics',
|
|
42
|
+
method: 'listRecent',
|
|
43
|
+
invocation: { kind: 'direct' },
|
|
44
|
+
parameters: [{ name: 'request', wire: 'request', source: 'json', codec: diagnosticsCodec('request') }],
|
|
45
|
+
result: diagnosticsCodec('result'),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const DIAGNOSTICS_REMOTE = {
|
|
49
|
+
package: 'dsh-vertex-argon',
|
|
50
|
+
descriptors: [DIAGNOSTICS_INVOCATION],
|
|
51
|
+
}
|
|
52
|
+
|
|
7
53
|
const dictionaries = {
|
|
8
54
|
zh: {
|
|
9
55
|
title: 'Vertex Argon',
|
|
@@ -18,7 +64,7 @@ window.__ModuleLoader__.load({
|
|
|
18
64
|
level_medium: 'Medium(默认)',
|
|
19
65
|
level_high: 'High(高)',
|
|
20
66
|
longDecodeLabel: '长生成自动续传(Long Decode Continuation)',
|
|
21
|
-
longDecodeHint: '开启后自动走 v1beta1 端点并处理 CONTINUATION
|
|
67
|
+
longDecodeHint: '开启后自动走 v1beta1 端点并处理 CONTINUATION 令牌与断流检查点指数退避恢复;多段续传时按首跳输入上报上下文水位,避免误触发自动压缩。',
|
|
22
68
|
longDecodeOn: '已开启',
|
|
23
69
|
longDecodeOff: '已关闭',
|
|
24
70
|
maxTokensLabel: '最大输出预算(Max Output Tokens)',
|
|
@@ -38,6 +84,29 @@ window.__ModuleLoader__.load({
|
|
|
38
84
|
scope: '通道特性与双保险',
|
|
39
85
|
detail: '本插件不仅提供完整支持 thought: true 思考摘要、thoughtSignature 签名回传与 v1beta1 Long Decode 自动续传的模型入口,还同时为原生的 google 与 google-vertex 路由注入了 Gemini 4 兼容补丁。',
|
|
40
86
|
route: '提供方路由:google-vertex-argon · 模型 ID:gemini-4-argon (Vertex AI) / gemini-4-argon-google (Gemini API)',
|
|
87
|
+
diagTitle: '最近请求诊断摘要',
|
|
88
|
+
diagSubtitle: '点击展开查看最近 20 次请求的通道版本、64K 续传跳数、断流检查点自愈与双轨 Token 计量',
|
|
89
|
+
diagRefresh: '刷新诊断',
|
|
90
|
+
diagLoading: '正在读取诊断记录…',
|
|
91
|
+
diagEmpty: '暂无请求诊断记录。使用 Gemini 4 Argon 发起一次对话后即可在此查看。',
|
|
92
|
+
diagError: '读取诊断记录失败,请确认已重启 DSH 加载最新版插件后重试。',
|
|
93
|
+
diagStorageHint: '诊断落盘目录:~/.dsh/storages/vertex_argon_diagnostics/requests/(最多保留最近 200 条,严格脱敏,不保存对话正文、图片或密钥)',
|
|
94
|
+
diagStatTotal: '最近记录',
|
|
95
|
+
diagStatOk: '成功完成',
|
|
96
|
+
diagStatCont: '64K 续传跳数',
|
|
97
|
+
diagStatRecovered: '断流自愈',
|
|
98
|
+
diagStatErr: '异常/失败',
|
|
99
|
+
diagOutcome_done: '完成',
|
|
100
|
+
diagOutcome_tool: '工具调用',
|
|
101
|
+
diagOutcome_max: '达到上限',
|
|
102
|
+
diagOutcome_error: '失败',
|
|
103
|
+
diagOutcome_aborted: '已取消',
|
|
104
|
+
diagOutcome_incomplete: '中断',
|
|
105
|
+
diagOutcome_recovered: '断流已自愈',
|
|
106
|
+
diagTrigger_initial: '首跳',
|
|
107
|
+
diagTrigger_continuation: '64K续传',
|
|
108
|
+
diagTrigger_reconnect: '检查点重连',
|
|
109
|
+
diagTrigger_retry: '同检查点重试',
|
|
41
110
|
},
|
|
42
111
|
en: {
|
|
43
112
|
title: 'Vertex Argon',
|
|
@@ -52,7 +121,7 @@ window.__ModuleLoader__.load({
|
|
|
52
121
|
level_medium: 'Medium (Default)',
|
|
53
122
|
level_high: 'High',
|
|
54
123
|
longDecodeLabel: 'Long Decode Automatic Continuation',
|
|
55
|
-
longDecodeHint: 'Routes Vertex AI via v1beta1 and automatically resumes CONTINUATION tokens and mid-stream checkpoints while preserving first-hop prompt token accounting for compaction.',
|
|
124
|
+
longDecodeHint: 'Routes Vertex AI via v1beta1 and automatically resumes CONTINUATION tokens and mid-stream checkpoints with exponential backoff while preserving first-hop prompt token accounting for compaction.',
|
|
56
125
|
longDecodeOn: 'Enabled',
|
|
57
126
|
longDecodeOff: 'Disabled',
|
|
58
127
|
maxTokensLabel: 'Max Output Budget (Max Output Tokens)',
|
|
@@ -72,6 +141,29 @@ window.__ModuleLoader__.load({
|
|
|
72
141
|
scope: 'Scope & fallback protection',
|
|
73
142
|
detail: 'In addition to the dedicated Vertex Argon group with Long Decode continuation, this plugin patches native google and google-vertex Gemini 4 requests so selecting the original entries also sends thinkingLevel instead of thinkingBudget.',
|
|
74
143
|
route: 'Provider route: google-vertex-argon · Models: gemini-4-argon (Vertex AI) / gemini-4-argon-google (Gemini API)',
|
|
144
|
+
diagTitle: 'Recent Request Diagnostics Summary',
|
|
145
|
+
diagSubtitle: 'Expand to inspect the latest 20 requests: route/API version, 64K continuation hops, checkpoint drop recovery, and dual-track token accounting',
|
|
146
|
+
diagRefresh: 'Refresh',
|
|
147
|
+
diagLoading: 'Loading diagnostics…',
|
|
148
|
+
diagEmpty: 'No request diagnostics recorded yet. Send a message with Gemini 4 Argon to populate this view.',
|
|
149
|
+
diagError: 'Could not load diagnostics. Restart DSH after upgrading the plugin and try again.',
|
|
150
|
+
diagStorageHint: 'Persisted under ~/.dsh/storages/vertex_argon_diagnostics/requests/ (retains latest 200 records; strictly scrubbed—no prompts, images, or credentials).',
|
|
151
|
+
diagStatTotal: 'Records',
|
|
152
|
+
diagStatOk: 'Succeeded',
|
|
153
|
+
diagStatCont: '64K Cont. Hops',
|
|
154
|
+
diagStatRecovered: 'Drop Recoveries',
|
|
155
|
+
diagStatErr: 'Errors',
|
|
156
|
+
diagOutcome_done: 'Done',
|
|
157
|
+
diagOutcome_tool: 'Tool Calls',
|
|
158
|
+
diagOutcome_max: 'Max Tokens',
|
|
159
|
+
diagOutcome_error: 'Error',
|
|
160
|
+
diagOutcome_aborted: 'Aborted',
|
|
161
|
+
diagOutcome_incomplete: 'Incomplete',
|
|
162
|
+
diagOutcome_recovered: 'Recovered',
|
|
163
|
+
diagTrigger_initial: 'Initial',
|
|
164
|
+
diagTrigger_continuation: '64K Cont.',
|
|
165
|
+
diagTrigger_reconnect: 'Ckpt Reconnect',
|
|
166
|
+
diagTrigger_retry: 'Ckpt Retry',
|
|
75
167
|
},
|
|
76
168
|
}
|
|
77
169
|
|
|
@@ -131,7 +223,163 @@ window.__ModuleLoader__.load({
|
|
|
131
223
|
})
|
|
132
224
|
}
|
|
133
225
|
|
|
134
|
-
function
|
|
226
|
+
function formatTimeShort(iso) {
|
|
227
|
+
if (typeof iso !== 'string') return ''
|
|
228
|
+
const d = new Date(iso)
|
|
229
|
+
if (Number.isNaN(d.getTime())) return iso.slice(11, 19)
|
|
230
|
+
return d.toLocaleTimeString([], { hour12: false })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function formatDuration(ms) {
|
|
234
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms)) return '0ms'
|
|
235
|
+
if (ms < 1000) return Math.round(ms) + 'ms'
|
|
236
|
+
return (ms / 1000).toFixed(2) + 's'
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function DiagnosticsPanel({ loadDiagnostics, t }) {
|
|
240
|
+
const [open, setOpen] = React.useState(false)
|
|
241
|
+
const [loading, setLoading] = React.useState(false)
|
|
242
|
+
const [error, setError] = React.useState(false)
|
|
243
|
+
const [records, setRecords] = React.useState([])
|
|
244
|
+
|
|
245
|
+
const refresh = React.useCallback(async () => {
|
|
246
|
+
if (typeof loadDiagnostics !== 'function') {
|
|
247
|
+
setError(true)
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
setLoading(true)
|
|
251
|
+
setError(false)
|
|
252
|
+
try {
|
|
253
|
+
const res = await loadDiagnostics(20)
|
|
254
|
+
if (res && res.ok === true && Array.isArray(res.records)) {
|
|
255
|
+
setRecords(res.records)
|
|
256
|
+
} else {
|
|
257
|
+
setError(true)
|
|
258
|
+
}
|
|
259
|
+
} catch {
|
|
260
|
+
setError(true)
|
|
261
|
+
} finally {
|
|
262
|
+
setLoading(false)
|
|
263
|
+
}
|
|
264
|
+
}, [loadDiagnostics])
|
|
265
|
+
|
|
266
|
+
React.useEffect(() => {
|
|
267
|
+
if (open) void refresh()
|
|
268
|
+
}, [open, refresh])
|
|
269
|
+
|
|
270
|
+
const fmt = n => (typeof n === 'number' && Number.isFinite(n) ? Number(n).toLocaleString() : '-')
|
|
271
|
+
const total = records.length
|
|
272
|
+
const okCount = records.filter(r => r.outcome === 'done' || r.outcome === 'tool-calls' || r.outcome === 'max-tokens').length
|
|
273
|
+
const contHops = records.reduce((acc, r) => acc + (r.continuationCount || 0), 0)
|
|
274
|
+
const recoveredCount = records.filter(r => r.recoveredFromDrop).length
|
|
275
|
+
const errCount = records.filter(r => r.outcome === 'error').length
|
|
276
|
+
|
|
277
|
+
const outcomeBadge = r => {
|
|
278
|
+
if (r.recoveredFromDrop) return { text: t('diagOutcome_recovered'), cls: 'badge-recovered' }
|
|
279
|
+
switch (r.outcome) {
|
|
280
|
+
case 'done': return { text: t('diagOutcome_done'), cls: 'badge-ok' }
|
|
281
|
+
case 'tool-calls': return { text: t('diagOutcome_tool'), cls: 'badge-ok' }
|
|
282
|
+
case 'max-tokens': return { text: t('diagOutcome_max'), cls: 'badge-warn' }
|
|
283
|
+
case 'error': return { text: t('diagOutcome_error'), cls: 'badge-err' }
|
|
284
|
+
case 'aborted': return { text: t('diagOutcome_aborted'), cls: 'badge-muted' }
|
|
285
|
+
default: return { text: t('diagOutcome_incomplete'), cls: 'badge-muted' }
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const triggerLabel = tr => {
|
|
290
|
+
switch (tr) {
|
|
291
|
+
case 'continuation': return t('diagTrigger_continuation')
|
|
292
|
+
case 'checkpoint-reconnect': return t('diagTrigger_reconnect')
|
|
293
|
+
case 'retry-same-checkpoint': return t('diagTrigger_retry')
|
|
294
|
+
default: return t('diagTrigger_initial')
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return h('div', { className: 'card' },
|
|
299
|
+
h('div', { className: 'row', style: { marginBottom: '4px' } },
|
|
300
|
+
h('button', {
|
|
301
|
+
type: 'button',
|
|
302
|
+
className: 'diag-toggle',
|
|
303
|
+
'aria-expanded': open,
|
|
304
|
+
onClick: () => setOpen(!open),
|
|
305
|
+
},
|
|
306
|
+
h('span', { style: { marginRight: '6px', display: 'inline-block' } }, open ? '▾' : '▸'),
|
|
307
|
+
h('strong', null, t('diagTitle')),
|
|
308
|
+
),
|
|
309
|
+
open
|
|
310
|
+
? h('button', { type: 'button', disabled: loading, onClick: refresh }, loading ? t('diagLoading') : t('diagRefresh'))
|
|
311
|
+
: null,
|
|
312
|
+
),
|
|
313
|
+
h('p', { className: 'muted', style: { marginBottom: open ? '12px' : '0' } }, t('diagSubtitle')),
|
|
314
|
+
open
|
|
315
|
+
? h('div', { className: 'diag-body' },
|
|
316
|
+
error
|
|
317
|
+
? h('p', { className: 'status error', role: 'alert' }, t('diagError'))
|
|
318
|
+
: records.length === 0 && !loading
|
|
319
|
+
? h('p', { className: 'muted' }, t('diagEmpty'))
|
|
320
|
+
: h(React.Fragment, null,
|
|
321
|
+
h('div', { className: 'diag-stats' },
|
|
322
|
+
h('span', { className: 'diag-stat' }, t('diagStatTotal') + ': ' + total),
|
|
323
|
+
h('span', { className: 'diag-stat' }, t('diagStatOk') + ': ' + okCount),
|
|
324
|
+
h('span', { className: 'diag-stat' }, t('diagStatCont') + ': ' + contHops),
|
|
325
|
+
h('span', { className: 'diag-stat' }, t('diagStatRecovered') + ': ' + recoveredCount),
|
|
326
|
+
h('span', { className: 'diag-stat' }, t('diagStatErr') + ': ' + errCount),
|
|
327
|
+
),
|
|
328
|
+
h('div', { className: 'diag-list' },
|
|
329
|
+
...records.map(r => {
|
|
330
|
+
const badge = outcomeBadge(r)
|
|
331
|
+
const u = r.tokenUsage || {}
|
|
332
|
+
const hops = Array.isArray(r.hops) ? r.hops : []
|
|
333
|
+
const showHops = hops.length > 1 || r.reconnectCount > 0 || r.outcome === 'error'
|
|
334
|
+
const routeLabel = r.route === 'google-generative-ai' ? 'Gemini API' : 'Vertex AI'
|
|
335
|
+
return h('div', { key: r.id, className: 'diag-item' },
|
|
336
|
+
h('div', { className: 'diag-item-head' },
|
|
337
|
+
h('span', { className: 'diag-mono' }, formatTimeShort(r.startedAt)),
|
|
338
|
+
h('span', { className: 'diag-chip' }, routeLabel + ' · ' + r.apiVersion),
|
|
339
|
+
h('span', { className: 'diag-chip' }, r.thinkingLevel),
|
|
340
|
+
h('span', { className: 'diag-badge ' + badge.cls }, badge.text),
|
|
341
|
+
r.failureCategory ? h('span', { className: 'diag-chip badge-err' }, r.failureCategory) : null,
|
|
342
|
+
h('span', { className: 'diag-mono', style: { marginLeft: 'auto' } },
|
|
343
|
+
(r.hopCount || 1) + ' hop' + ((r.hopCount || 1) > 1 ? 's' : '') + ' · ' + formatDuration(r.durationMs)
|
|
344
|
+
),
|
|
345
|
+
),
|
|
346
|
+
u.reportedInputTokens !== null || u.outputTokens !== null
|
|
347
|
+
? h('div', { className: 'diag-tokens muted' },
|
|
348
|
+
'Tokens — In: ' + fmt(u.reportedInputTokens) +
|
|
349
|
+
(u.reportedCacheTokens ? ' (Cache: ' + fmt(u.reportedCacheTokens) + ')' : '') +
|
|
350
|
+
' · Out: ' + fmt(u.outputTokens) +
|
|
351
|
+
(u.thoughtsTokens ? ' · Think: ' + fmt(u.thoughtsTokens) : '') +
|
|
352
|
+
((r.hopCount || 1) > 1 && u.billedTotalTokens !== null
|
|
353
|
+
? ' | Billed In: ' + fmt(u.billedPromptTokens) + ' · Billed Total: ' + fmt(u.billedTotalTokens)
|
|
354
|
+
: '')
|
|
355
|
+
)
|
|
356
|
+
: null,
|
|
357
|
+
showHops
|
|
358
|
+
? h('div', { className: 'diag-hops' },
|
|
359
|
+
...hops.map(hp =>
|
|
360
|
+
h('div', { key: hp.hopIndex, className: 'diag-hop-row' },
|
|
361
|
+
'#' + hp.hopIndex + ' [' + triggerLabel(hp.trigger) + ']' +
|
|
362
|
+
(hp.backoffDelayMs > 0 ? ' (backoff ' + hp.backoffDelayMs + 'ms)' : '') +
|
|
363
|
+
' · HTTP ' + (hp.status ?? '-') +
|
|
364
|
+
' · ' + hp.chunkCount + ' chunks' +
|
|
365
|
+
(hp.finishReason ? ' · ' + hp.finishReason : '') +
|
|
366
|
+
(Array.isArray(hp.errorCodes) && hp.errorCodes.length > 0 ? ' · ' + hp.errorCodes.join(',') : '') +
|
|
367
|
+
' · ' + formatDuration(hp.durationMs)
|
|
368
|
+
)
|
|
369
|
+
),
|
|
370
|
+
)
|
|
371
|
+
: null,
|
|
372
|
+
)
|
|
373
|
+
}),
|
|
374
|
+
),
|
|
375
|
+
),
|
|
376
|
+
h('p', { className: 'muted', style: { marginTop: '10px', fontSize: '12px' } }, t('diagStorageHint')),
|
|
377
|
+
)
|
|
378
|
+
: null,
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function Settings({ form, loadDiagnostics, t }) {
|
|
135
383
|
const state = React.useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot())
|
|
136
384
|
const [pending, setPending] = React.useState(false)
|
|
137
385
|
const [notice, setNotice] = React.useState('')
|
|
@@ -186,7 +434,24 @@ window.__ModuleLoader__.load({
|
|
|
186
434
|
'.local-vertex-argon button:disabled{opacity:.55;cursor:default}' +
|
|
187
435
|
'.local-vertex-argon .status{min-height:22px;font-size:13px;color:var(--dsw-alias-label-secondary);margin-top:6px}' +
|
|
188
436
|
'.local-vertex-argon .status.error{color:var(--dsw-alias-state-error-primary)}' +
|
|
189
|
-
'.local-vertex-argon ol{padding-left:22px;margin:8px 0}.local-vertex-argon li{margin:8px 0}'
|
|
437
|
+
'.local-vertex-argon ol{padding-left:22px;margin:8px 0}.local-vertex-argon li{margin:8px 0}' +
|
|
438
|
+
'.local-vertex-argon .diag-toggle{border:none;background:transparent;padding:4px 0;min-width:0;text-align:left}' +
|
|
439
|
+
'.local-vertex-argon .diag-toggle:hover:not(:disabled){background:transparent;opacity:.85}' +
|
|
440
|
+
'.local-vertex-argon .diag-stats{display:flex;gap:12px;flex-wrap:wrap;padding:8px 12px;border-radius:8px;background:var(--dsw-alias-bg-layer-2);margin-bottom:10px;font-size:12px}' +
|
|
441
|
+
'.local-vertex-argon .diag-stat{font-weight:500}' +
|
|
442
|
+
'.local-vertex-argon .diag-list{display:flex;flex-direction:column;gap:8px;max-height:360px;overflow-y:auto;padding-right:2px}' +
|
|
443
|
+
'.local-vertex-argon .diag-item{padding:10px 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);font-size:12.5px}' +
|
|
444
|
+
'.local-vertex-argon .diag-item-head{display:flex;gap:8px;align-items:center;flex-wrap:wrap}' +
|
|
445
|
+
'.local-vertex-argon .diag-mono{font-family:ui-monospace,monospace;font-size:12px}' +
|
|
446
|
+
'.local-vertex-argon .diag-chip{padding:1px 7px;border-radius:6px;background:var(--dsw-alias-bg-layer-2);font-size:11.5px}' +
|
|
447
|
+
'.local-vertex-argon .diag-badge{padding:1px 8px;border-radius:999px;font-weight:600;font-size:11.5px}' +
|
|
448
|
+
'.local-vertex-argon .badge-ok{color:var(--dsw-alias-state-success-primary);background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 12%,transparent)}' +
|
|
449
|
+
'.local-vertex-argon .badge-recovered{color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 14%,transparent)}' +
|
|
450
|
+
'.local-vertex-argon .badge-warn{color:var(--dsw-alias-state-warn-primary);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 14%,transparent)}' +
|
|
451
|
+
'.local-vertex-argon .badge-err{color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 12%,transparent)}' +
|
|
452
|
+
'.local-vertex-argon .badge-muted{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2)}' +
|
|
453
|
+
'.local-vertex-argon .diag-tokens{margin-top:6px;font-size:12px;font-family:ui-monospace,monospace}' +
|
|
454
|
+
'.local-vertex-argon .diag-hops{margin-top:6px;padding-top:6px;border-top:1px dashed var(--dsw-alias-border-l2);display:flex;flex-direction:column;gap:3px;font-family:ui-monospace,monospace;font-size:11.5px;color:var(--dsw-alias-label-secondary)}'
|
|
190
455
|
),
|
|
191
456
|
h('h2', null, t('title')),
|
|
192
457
|
h('p', { className: 'muted' }, t('subtitle')),
|
|
@@ -266,6 +531,7 @@ window.__ModuleLoader__.load({
|
|
|
266
531
|
h('p', null, t('detail')),
|
|
267
532
|
h('p', { className: 'muted' }, t('route')),
|
|
268
533
|
),
|
|
534
|
+
h(DiagnosticsPanel, { loadDiagnostics, t }),
|
|
269
535
|
)
|
|
270
536
|
}
|
|
271
537
|
|
|
@@ -275,10 +541,77 @@ window.__ModuleLoader__.load({
|
|
|
275
541
|
ctx.effect(() => ctx.locale.register(ns, dictionaries), 'vertex-argon: locale')
|
|
276
542
|
const form = ctx.configForms.get('local-vertex-argon')
|
|
277
543
|
ctx.effect(() => installAdjacentPicker(ctx), 'vertex-argon: adjacent model picker')
|
|
544
|
+
|
|
545
|
+
let active = true
|
|
546
|
+
let mountedOn
|
|
547
|
+
let pendingMount
|
|
548
|
+
let disposeMount
|
|
549
|
+
const getRemote = () => {
|
|
550
|
+
try { return ctx.get('remote') } catch { return undefined }
|
|
551
|
+
}
|
|
552
|
+
const identity = remote => remote?.[Symbol.for('cordis.original')] ?? remote
|
|
553
|
+
async function ensureRemoteReady() {
|
|
554
|
+
if (!active) throw new Error('Vertex Argon client disposed')
|
|
555
|
+
if (pendingMount) return pendingMount
|
|
556
|
+
const remote = getRemote()
|
|
557
|
+
if (mountedOn && mountedOn === identity(remote)) return
|
|
558
|
+
pendingMount = (async () => {
|
|
559
|
+
const release = disposeMount
|
|
560
|
+
disposeMount = undefined
|
|
561
|
+
mountedOn = undefined
|
|
562
|
+
await release?.()
|
|
563
|
+
if (!remote || typeof remote.$mount !== 'function') throw new Error('Remote connection not ready')
|
|
564
|
+
const dispose = await remote.$mount(DIAGNOSTICS_REMOTE)
|
|
565
|
+
if (!active) {
|
|
566
|
+
await dispose?.()
|
|
567
|
+
throw new Error('Vertex Argon client disposed')
|
|
568
|
+
}
|
|
569
|
+
disposeMount = dispose
|
|
570
|
+
mountedOn = identity(remote)
|
|
571
|
+
})()
|
|
572
|
+
try {
|
|
573
|
+
await pendingMount
|
|
574
|
+
} finally {
|
|
575
|
+
pendingMount = undefined
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async function loadDiagnostics(limit = 20) {
|
|
580
|
+
try {
|
|
581
|
+
await ensureRemoteReady()
|
|
582
|
+
const api = ctx.get('remote.vertexArgonDiagnostics')
|
|
583
|
+
if (typeof api?.listRecent !== 'function') return { ok: false, error: 'Diagnostics service unavailable' }
|
|
584
|
+
const response = await api.listRecent({ limit })
|
|
585
|
+
if (response?.ok === false && typeof response.error === 'object') {
|
|
586
|
+
return { ok: false, error: String(response.error?.message || 'Read failed') }
|
|
587
|
+
}
|
|
588
|
+
const result = response?.ok === true && Object.hasOwn(response, 'value') ? response.value : response
|
|
589
|
+
return parseListRecentResult(result)
|
|
590
|
+
} catch (err) {
|
|
591
|
+
return { ok: false, error: err instanceof Error ? err.message : 'Read failed' }
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
ctx.effect(() => {
|
|
596
|
+
void ensureRemoteReady().catch(() => {})
|
|
597
|
+
return async () => {
|
|
598
|
+
active = false
|
|
599
|
+
await pendingMount?.catch(() => {})
|
|
600
|
+
const dispose = disposeMount
|
|
601
|
+
disposeMount = undefined
|
|
602
|
+
mountedOn = undefined
|
|
603
|
+
await dispose?.()
|
|
604
|
+
}
|
|
605
|
+
}, 'vertex-argon: diagnostics remote lifetime')
|
|
606
|
+
|
|
607
|
+
ctx.on?.('connection/reset', () => {
|
|
608
|
+
void ensureRemoteReady().catch(() => {})
|
|
609
|
+
})
|
|
610
|
+
|
|
278
611
|
ctx.effect(() => ctx.configForms.whileServed(['local-vertex-argon'], () =>
|
|
279
612
|
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
280
613
|
name: 'settings.section', id: 'local-vertex-argon', order: 36,
|
|
281
|
-
label: () => ctx.locale.bind(ns)('title'), locale: ns, inject: () => ({ form }),
|
|
614
|
+
label: () => ctx.locale.bind(ns)('title'), locale: ns, inject: () => ({ form, loadDiagnostics }),
|
|
282
615
|
}, Settings)),
|
|
283
616
|
), 'vertex-argon: settings section')
|
|
284
617
|
},
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { shared } from './runtime.js'
|
|
2
|
+
import { transportErrorCodes, MAX_RECORDED_HOPS } from './diagnostics.js'
|
|
3
|
+
|
|
4
|
+
const { z } = await shared('zod')
|
|
5
|
+
const { TypertRemoteService, Remote } = await shared('@deepseek-ai/dsh-typert-protocol')
|
|
6
|
+
|
|
7
|
+
const nullableId = z.string().regex(/^[A-Za-z0-9._:/-]{1,160}$/).nullable()
|
|
8
|
+
const nullableFinishReason = z.string().regex(/^[A-Z0-9_]{1,64}$/).nullable()
|
|
9
|
+
const count = z.number().int().nonnegative()
|
|
10
|
+
const positiveInt = z.number().int().positive()
|
|
11
|
+
|
|
12
|
+
const hopSchema = z.object({
|
|
13
|
+
hopIndex: positiveInt,
|
|
14
|
+
trigger: z.enum(['initial', 'continuation', 'checkpoint-reconnect', 'retry-same-checkpoint']),
|
|
15
|
+
usedContinuationToken: z.boolean(),
|
|
16
|
+
backoffDelayMs: count,
|
|
17
|
+
bodyBytes: count.nullable(),
|
|
18
|
+
status: z.number().int().min(100).max(599).nullable(),
|
|
19
|
+
durationMs: count,
|
|
20
|
+
chunkCount: count,
|
|
21
|
+
hasCheckpoint: z.boolean(),
|
|
22
|
+
finishReason: nullableFinishReason,
|
|
23
|
+
outcome: z.enum(['pending', 'done', 'continued', 'dropped', 'transport-error', 'api-error', 'aborted']),
|
|
24
|
+
errorCodes: z.array(z.enum(transportErrorCodes)).max(8),
|
|
25
|
+
}).strict()
|
|
26
|
+
|
|
27
|
+
const tokenUsageSchema = z.object({
|
|
28
|
+
reportedInputTokens: count.nullable(),
|
|
29
|
+
reportedCacheTokens: count.nullable(),
|
|
30
|
+
outputTokens: count.nullable(),
|
|
31
|
+
thoughtsTokens: count.nullable(),
|
|
32
|
+
billedPromptTokens: count.nullable(),
|
|
33
|
+
billedCachedTokens: count.nullable(),
|
|
34
|
+
billedTotalTokens: count.nullable(),
|
|
35
|
+
}).strict()
|
|
36
|
+
|
|
37
|
+
export const recordSchema = z.object({
|
|
38
|
+
schemaVersion: z.literal(1),
|
|
39
|
+
id: z.string().uuid(),
|
|
40
|
+
startedAt: z.string().datetime(),
|
|
41
|
+
sessionHash: z.string().regex(/^[0-9a-f]{24}$/).nullable(),
|
|
42
|
+
route: z.enum(['google-vertex', 'google-generative-ai']),
|
|
43
|
+
model: nullableId,
|
|
44
|
+
apiVersion: z.enum(['v1', 'v1beta1', 'v1beta']),
|
|
45
|
+
thinkingLevel: z.enum(['LOW', 'MEDIUM', 'HIGH']),
|
|
46
|
+
longDecodeEnabled: z.boolean(),
|
|
47
|
+
configuredMaxTokens: positiveInt.nullable(),
|
|
48
|
+
hopCount: count,
|
|
49
|
+
continuationCount: count,
|
|
50
|
+
reconnectCount: count,
|
|
51
|
+
recoveredFromDrop: z.boolean(),
|
|
52
|
+
hops: z.array(hopSchema).max(MAX_RECORDED_HOPS),
|
|
53
|
+
hopsDropped: count,
|
|
54
|
+
tokenUsage: tokenUsageSchema,
|
|
55
|
+
outcome: z.enum(['unknown', 'done', 'max-tokens', 'tool-calls', 'error', 'aborted', 'incomplete']),
|
|
56
|
+
failureCategory: z.enum([
|
|
57
|
+
'initial-connect-error',
|
|
58
|
+
'mid-stream-drop',
|
|
59
|
+
'api-status-error',
|
|
60
|
+
'transient-finish-reason',
|
|
61
|
+
'other',
|
|
62
|
+
]).nullable(),
|
|
63
|
+
durationMs: count,
|
|
64
|
+
}).strict()
|
|
65
|
+
|
|
66
|
+
export const diagnosticDomain = {
|
|
67
|
+
name: 'vertex_argon_diagnostics',
|
|
68
|
+
version: 1,
|
|
69
|
+
layout: 'per-record',
|
|
70
|
+
tables: { requests: { valueSchema: recordSchema } },
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function diagnosticWriter(domain, warn = () => {}, limit = 200) {
|
|
74
|
+
let tail = Promise.resolve()
|
|
75
|
+
let pending = 0
|
|
76
|
+
let closed = false
|
|
77
|
+
let warned = false
|
|
78
|
+
let failed = false
|
|
79
|
+
const notify = () => {
|
|
80
|
+
if (!warned) {
|
|
81
|
+
warned = true
|
|
82
|
+
try {
|
|
83
|
+
warn('Vertex Argon diagnostic storage unavailable or overloaded; some metadata was not saved.')
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const table = domain.table('requests')
|
|
88
|
+
return {
|
|
89
|
+
record(value) {
|
|
90
|
+
if (closed || failed || pending >= 32) {
|
|
91
|
+
notify()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
const parsed = recordSchema.safeParse(value)
|
|
95
|
+
if (!parsed.success) {
|
|
96
|
+
notify()
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
pending++
|
|
100
|
+
tail = tail
|
|
101
|
+
.then(async () => {
|
|
102
|
+
if (failed) return
|
|
103
|
+
const oldest = [...table.entries()].sort((a, b) => a[1].startedAt.localeCompare(b[1].startedAt))
|
|
104
|
+
for (const [id] of oldest.slice(0, Math.max(0, oldest.length - limit + 1))) {
|
|
105
|
+
if (!(await table.delete(id))) throw new Error('diagnostic retention failed')
|
|
106
|
+
}
|
|
107
|
+
await table.put(parsed.data.id, parsed.data)
|
|
108
|
+
})
|
|
109
|
+
.catch(() => {
|
|
110
|
+
failed = true
|
|
111
|
+
notify()
|
|
112
|
+
})
|
|
113
|
+
.finally(() => {
|
|
114
|
+
pending--
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
list(max = 20) {
|
|
118
|
+
try {
|
|
119
|
+
const cap = Math.min(Math.max(1, Number(max) || 20), limit)
|
|
120
|
+
return [...table.entries()]
|
|
121
|
+
.map(([, v]) => v)
|
|
122
|
+
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
123
|
+
.slice(0, cap)
|
|
124
|
+
} catch {
|
|
125
|
+
return []
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
async close() {
|
|
129
|
+
closed = true
|
|
130
|
+
await tail
|
|
131
|
+
await domain.close()
|
|
132
|
+
},
|
|
133
|
+
async flush() {
|
|
134
|
+
await tail
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function createDiagnosticHub(limit = 200) {
|
|
140
|
+
const memory = new Map()
|
|
141
|
+
let activeWriter = null
|
|
142
|
+
const trimMemory = () => {
|
|
143
|
+
if (memory.size <= limit) return
|
|
144
|
+
const sorted = [...memory.entries()].sort((a, b) => a[1].startedAt.localeCompare(b[1].startedAt))
|
|
145
|
+
for (const [id] of sorted.slice(0, memory.size - limit)) {
|
|
146
|
+
memory.delete(id)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
record(value) {
|
|
151
|
+
const parsed = recordSchema.safeParse(value)
|
|
152
|
+
if (!parsed.success) return
|
|
153
|
+
memory.set(parsed.data.id, parsed.data)
|
|
154
|
+
trimMemory()
|
|
155
|
+
activeWriter?.record(parsed.data)
|
|
156
|
+
},
|
|
157
|
+
attachWriter(writer) {
|
|
158
|
+
activeWriter = writer
|
|
159
|
+
try {
|
|
160
|
+
for (const item of writer.list(limit)) {
|
|
161
|
+
if (!memory.has(item.id)) memory.set(item.id, item)
|
|
162
|
+
}
|
|
163
|
+
trimMemory()
|
|
164
|
+
} catch {}
|
|
165
|
+
},
|
|
166
|
+
detachWriter(writer) {
|
|
167
|
+
if (activeWriter === writer) activeWriter = null
|
|
168
|
+
},
|
|
169
|
+
listRecent(max = 20) {
|
|
170
|
+
const cap = Math.min(Math.max(1, Number(max) || 20), limit)
|
|
171
|
+
const merged = new Map(memory)
|
|
172
|
+
if (activeWriter) {
|
|
173
|
+
for (const item of activeWriter.list(limit)) {
|
|
174
|
+
merged.set(item.id, item)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return [...merged.values()]
|
|
178
|
+
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
179
|
+
.slice(0, cap)
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function remoteMarker(prototype, name) {
|
|
185
|
+
let initializer
|
|
186
|
+
Remote(prototype[name], {
|
|
187
|
+
name,
|
|
188
|
+
private: false,
|
|
189
|
+
static: false,
|
|
190
|
+
addInitializer(fn) {
|
|
191
|
+
initializer = fn
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
return initializer
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function parseListRecentRequest(value) {
|
|
198
|
+
if (value === undefined || value === null) return { limit: 20 }
|
|
199
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid diagnostics request')
|
|
200
|
+
const limit = value.limit === undefined ? 20 : Number(value.limit)
|
|
201
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error('Invalid diagnostics limit')
|
|
202
|
+
return { limit }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function parseListRecentResult(value) {
|
|
206
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid diagnostics response')
|
|
207
|
+
if (value.ok === false) {
|
|
208
|
+
if (typeof value.error !== 'string') throw new Error('Invalid diagnostics error response')
|
|
209
|
+
return value
|
|
210
|
+
}
|
|
211
|
+
if (value.ok !== true || !Array.isArray(value.records)) throw new Error('Invalid diagnostics records response')
|
|
212
|
+
return value
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function diagnosticsCodec(direction) {
|
|
216
|
+
const schema = {
|
|
217
|
+
parse: value => (direction === 'request' ? parseListRecentRequest(value) : parseListRecentResult(value)),
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
mode: 'strict',
|
|
221
|
+
typeSymbol: 'dsh-vertex-argon/listRecent' + (direction === 'request' ? 'Request' : 'Result'),
|
|
222
|
+
schema,
|
|
223
|
+
create: () => schema,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function diagnosticsInvocation() {
|
|
228
|
+
return {
|
|
229
|
+
id: 'dsh-vertex-argon#vertexArgonDiagnostics/listRecent',
|
|
230
|
+
service: 'vertexArgonDiagnostics',
|
|
231
|
+
namespace: 'vertexArgonDiagnostics',
|
|
232
|
+
method: 'listRecent',
|
|
233
|
+
invocation: { kind: 'direct' },
|
|
234
|
+
parameters: [{ name: 'request', wire: 'request', source: 'json', codec: diagnosticsCodec('request') }],
|
|
235
|
+
result: diagnosticsCodec('result'),
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const DIAGNOSTICS_REMOTE = {
|
|
240
|
+
package: 'dsh-vertex-argon',
|
|
241
|
+
descriptors: [diagnosticsInvocation()],
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export class ArgonDiagnosticsService extends TypertRemoteService {
|
|
245
|
+
constructor(ctx, hub) {
|
|
246
|
+
super(ctx, 'vertexArgonDiagnostics')
|
|
247
|
+
this.hub = hub
|
|
248
|
+
remoteMarker(Object.getPrototypeOf(this), 'listRecent').call(this)
|
|
249
|
+
}
|
|
250
|
+
async listRecent(request) {
|
|
251
|
+
try {
|
|
252
|
+
const { limit } = parseListRecentRequest(request)
|
|
253
|
+
return { ok: true, records: this.hub.listRecent(limit) }
|
|
254
|
+
} catch {
|
|
255
|
+
return { ok: false, error: 'Failed to read Vertex Argon diagnostics' }
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|