dsh-vertex-argon 2.2.4 → 2.2.6
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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/adapter.js +35 -7
- package/google-signatures.js +66 -17
- package/index.js +10 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to **Gemini 4 Adapter** (`dsh-vertex-argon`) are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.2.6] - 2026-11-19
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **Fail-Closed Unsupported Part Validation (`google-signatures.js`)**:
|
|
9
|
+
- Validated every candidate Part inside `observe(chunk)` against the supported `pi-ai` replay contract (`text`, `thought`, `thoughtSignature` / `thought_signature`, `functionCall` / `function_call`); unrepresentable parts (`executableCode`, `codeExecutionResult`, `functionResponse`, `inlineData`, `fileData`, mixed `text + functionCall`, `functionCall` with `thought: true`, or bare `{ thought: true }`) now fail closed with `ARGON_SIGNATURE_REPLAY` instead of being silently dropped.
|
|
10
|
+
- **Symmetric Cross-Chunk & Same-Chunk Text/Thinking Merge (`google-signatures.js`)**:
|
|
11
|
+
- Made `splitSigned` symmetric between `text` and `thinking`: cross-chunk continuations from a non-empty signed block to an unsigned block merge while preserving the signature, whereas same-chunk signature boundaries, conflicting signatures (`S1` → `S2`), and explicit empty signed carriers split 1:1.
|
|
12
|
+
- **Immutable Deep-Frozen Model Descriptors (`adapter.js`)**:
|
|
13
|
+
- Added `freezeDescriptor` deep-freezing returned/registered model descriptors (`input`, `thinkingLevelMap`, `cost`, and the descriptor object itself while preserving `MAX_TOKENS_CEILING`) in both `getProfiles()` and `argonProvider()`, preventing callers from mutating cached descriptor state via `getModels()`.
|
|
14
|
+
|
|
15
|
+
## [2.2.5] - 2026-11-19
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- **Same-Chunk Unsigned-to-Signed Part Boundaries (`google-signatures.js`)**:
|
|
19
|
+
- Tracked `currentFromThisChunk` inside `observe(chunk)` so an unsigned part followed immediately by a signed part (`text` or `thinking`) within the same `candidates[0].content.parts` array always splits 1:1 into separate blocks while preserving cross-chunk delta merging.
|
|
20
|
+
- **Strict `extraBody` Effort/Null Hardening & Direct-Provider Origin Pinning (`adapter.js`)**:
|
|
21
|
+
- Added `'reasoningEffort'`, `'reasoning_effort'`, `'thinkingLevel'`, and `'thinking_level'` to `EXTRA_BODY_STRIPPED_KEYS` (and stripped `reasoningEffort` / `reasoning_effort` on `body` & `cleanConfig` in `gemini4StreamSimple`), and rejected explicit `null` / non-plain-object values for `httpOptions.extraBody`, `extraBody.generationConfig`, and `extraBody.generation_config` with `INVALID_REQUEST`.
|
|
22
|
+
- Pinned `baseUrl` and `contextWindow` on `effectiveModel` in `argonProvider.streamSimple` from `configured` alongside `id`, `provider`, `api`, `maxTokens`, `thinkingLevelMap`, and `[MAX_TOKENS_CEILING]`.
|
|
23
|
+
- **Two-Stage `apply()` Cleanup Rollback (`index.js`)**:
|
|
24
|
+
- Rolled back both `registration?.()` and `unpatchPiAi()` in `try/finally` inside both the `ctx.effect` disposer and `catch` handler if `ctx.effect(...)` throws after `ctx.llm.registerAdapter()` has succeeded.
|
|
25
|
+
|
|
5
26
|
## [2.2.4] - 2026-11-19
|
|
6
27
|
|
|
7
28
|
### Fixed
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**面向 [DeepSeek Harness](<https://github.com/deepseek-ai/deepseek-harness>) 的 Google 官方双通道(Vertex AI + Gemini Developer API)Gemini 4 适配器,原生支持 Argon、Carbon、Hydrogen 与 Neon 八模型路由、GenerateContent / Interactions 双协议、65K+ 多跳长解码与请求级诊断。**
|
|
6
6
|
|
|
7
|
-
- **当前版本**:`2.2.
|
|
7
|
+
- **当前版本**:`2.2.6`([CHANGELOG.md](<CHANGELOG.md>))
|
|
8
8
|
- **npm 包名**:`dsh-vertex-argon`(保留既有包名、官方通道路由与本地存储域 ID,官方通道用户可直接原地升级;`2.0.0` 已移除 `1.6.x` 非官方反代通道)
|
|
9
9
|
- **运行要求**:DSH `>=0.2.0-rc.2`,Node.js `^22.19.0 || >=24.0.0`(见 [package.json](<package.json>))
|
|
10
10
|
|
package/adapter.js
CHANGED
|
@@ -423,6 +423,10 @@ const EXTRA_BODY_STRIPPED_KEYS = [
|
|
|
423
423
|
'thinking_config',
|
|
424
424
|
'thinkingBudget',
|
|
425
425
|
'thinking_budget',
|
|
426
|
+
'thinkingLevel',
|
|
427
|
+
'thinking_level',
|
|
428
|
+
'reasoningEffort',
|
|
429
|
+
'reasoning_effort',
|
|
426
430
|
'includeThoughts',
|
|
427
431
|
'include_thoughts',
|
|
428
432
|
'temperature',
|
|
@@ -439,7 +443,7 @@ const EXTRA_BODY_STRIPPED_KEYS = [
|
|
|
439
443
|
]
|
|
440
444
|
|
|
441
445
|
function sanitizeGemini4ExtraBody(extraBody, stripExplicitCache) {
|
|
442
|
-
if (extraBody === undefined
|
|
446
|
+
if (extraBody === undefined) return extraBody
|
|
443
447
|
if (!isPlainObjectRecord(extraBody)) {
|
|
444
448
|
throw new LlmError('Gemini 4 httpOptions.extraBody must be a plain object.', 'INVALID_REQUEST')
|
|
445
449
|
}
|
|
@@ -450,7 +454,7 @@ function sanitizeGemini4ExtraBody(extraBody, stripExplicitCache) {
|
|
|
450
454
|
delete cleanExtraBody.cached_content
|
|
451
455
|
}
|
|
452
456
|
for (const cfgKey of ['generationConfig', 'generation_config']) {
|
|
453
|
-
if (cleanExtraBody
|
|
457
|
+
if (!Object.hasOwn(cleanExtraBody, cfgKey) || cleanExtraBody[cfgKey] === undefined) continue
|
|
454
458
|
if (!isPlainObjectRecord(cleanExtraBody[cfgKey])) {
|
|
455
459
|
throw new LlmError(`Gemini 4 httpOptions.extraBody.${cfgKey} must be a plain object.`, 'INVALID_REQUEST')
|
|
456
460
|
}
|
|
@@ -580,7 +584,9 @@ export function gemini4StreamSimple(
|
|
|
580
584
|
delete body.cachedContent
|
|
581
585
|
delete body.cached_content
|
|
582
586
|
}
|
|
583
|
-
|
|
587
|
+
delete body.reasoningEffort
|
|
588
|
+
delete body.reasoning_effort
|
|
589
|
+
const { temperature: _t, topP: _tp, topK: _tk, candidateCount: _cc, frequencyPenalty: _fp, presencePenalty: _pp, reasoningEffort: _reBody, reasoning_effort: _reSnake, ...cleanConfig } = body.config
|
|
584
590
|
if (supportsXhigh) {
|
|
585
591
|
delete cleanConfig.cachedContent
|
|
586
592
|
delete cleanConfig.cached_content
|
|
@@ -846,14 +852,33 @@ export function resolveConfigValues(raw = {}) {
|
|
|
846
852
|
}
|
|
847
853
|
}
|
|
848
854
|
|
|
855
|
+
function freezeDescriptor(descriptor) {
|
|
856
|
+
if (!descriptor || typeof descriptor !== 'object') return descriptor
|
|
857
|
+
const copy = {
|
|
858
|
+
...descriptor,
|
|
859
|
+
...(Array.isArray(descriptor.input) ? { input: Object.freeze([...descriptor.input]) } : {}),
|
|
860
|
+
...(descriptor.thinkingLevelMap && typeof descriptor.thinkingLevelMap === 'object'
|
|
861
|
+
? { thinkingLevelMap: Object.freeze({ ...descriptor.thinkingLevelMap }) }
|
|
862
|
+
: {}),
|
|
863
|
+
...(descriptor.cost && typeof descriptor.cost === 'object'
|
|
864
|
+
? { cost: Object.freeze({ ...descriptor.cost }) }
|
|
865
|
+
: {}),
|
|
866
|
+
}
|
|
867
|
+
for (const sym of Object.getOwnPropertySymbols(descriptor)) {
|
|
868
|
+
copy[sym] = descriptor[sym]
|
|
869
|
+
}
|
|
870
|
+
return Object.freeze(copy)
|
|
871
|
+
}
|
|
872
|
+
|
|
849
873
|
/** Serve the official Vertex AI and Gemini API models in one plugin group. */
|
|
850
874
|
export function argonProvider(nativeVertex, models, defaultLevel = undefined, nativeGoogle = googleProvider(), longDecode = true, recordDiagnostic, serviceConfig = {}, responseHub, structuredOutput) {
|
|
851
|
-
const
|
|
875
|
+
const frozenModels = (Array.isArray(models) ? models : [models]).map(freezeDescriptor)
|
|
876
|
+
const modelMap = new Map(frozenModels.map(m => [m.id, m]))
|
|
852
877
|
return {
|
|
853
878
|
id: PROVIDER,
|
|
854
879
|
name: 'Gemini 4 Adapter',
|
|
855
880
|
auth: nativeVertex.auth,
|
|
856
|
-
getModels: () => [...
|
|
881
|
+
getModels: () => [...frozenModels],
|
|
857
882
|
streamSimple(requestModel, context, options = {}) {
|
|
858
883
|
const configured = modelMap.get(requestModel?.id)
|
|
859
884
|
if (!configured || requestModel?.provider !== PROVIDER) {
|
|
@@ -868,6 +893,8 @@ export function argonProvider(nativeVertex, models, defaultLevel = undefined, na
|
|
|
868
893
|
id: configured.id,
|
|
869
894
|
provider: PROVIDER,
|
|
870
895
|
api: configured.api,
|
|
896
|
+
baseUrl: configured.baseUrl,
|
|
897
|
+
contextWindow: configured.contextWindow,
|
|
871
898
|
maxTokens: configured.maxTokens,
|
|
872
899
|
thinkingLevelMap: configured.thinkingLevelMap,
|
|
873
900
|
[MAX_TOKENS_CEILING]: configured[MAX_TOKENS_CEILING] ?? (Number.isSafeInteger(configured.maxTokens) ? configured.maxTokens : undefined),
|
|
@@ -1187,8 +1214,9 @@ export function createArgonAdapter(ctx, configInput, nativeVertex = googleVertex
|
|
|
1187
1214
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1188
1215
|
})
|
|
1189
1216
|
}
|
|
1190
|
-
for (
|
|
1191
|
-
|
|
1217
|
+
for (let i = 0; i < models.length; i++) {
|
|
1218
|
+
models[i][MAX_TOKENS_CEILING] = cfg.explicitMaxTokensCap
|
|
1219
|
+
models[i] = freezeDescriptor(models[i])
|
|
1192
1220
|
}
|
|
1193
1221
|
const configuredMaxTokens = new Map(models.map(m => [m.id, cfg.maxTokens]))
|
|
1194
1222
|
const configuredReasoning = cfg.hasExplicitReasoning ? cfg.reasoning : undefined
|
package/google-signatures.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto'
|
|
2
2
|
|
|
3
|
+
const ALLOWED_PART_KEYS = new Set(['text', 'thought', 'thoughtSignature', 'thought_signature', 'functionCall', 'function_call'])
|
|
4
|
+
|
|
3
5
|
const PREFIX = '{"dshGoogleSignatureOnly":'
|
|
4
6
|
const base64 = value => typeof value === 'string' && value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value)
|
|
5
7
|
const digest = content => createHash('sha256').update(JSON.stringify(content.map(block => block.type === 'text' ? ['text', block.text] : block.type === 'thinking' ? ['thinking', block.thinking] : ['toolCall', block.id, block.name, block.arguments]))).digest('hex')
|
|
@@ -115,7 +117,7 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
115
117
|
const historyDigest = history.digest('hex')
|
|
116
118
|
const content = [], pending = [], standalone = new Map(), usedToolIds = new Set()
|
|
117
119
|
const partial = { role: 'assistant', api: model.api, provider: model.provider, model: model.id, content }
|
|
118
|
-
let current,
|
|
120
|
+
let current, currentFromThisChunk = false, seen = false, bytes = 0
|
|
119
121
|
const emit = event => {
|
|
120
122
|
if (pending.length >= 32768) throw failure('Google response exceeded the bounded pending event count.')
|
|
121
123
|
pending.push({ ...event, partial })
|
|
@@ -136,7 +138,7 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
136
138
|
...(sig ? { contentSignature: sig } : {}),
|
|
137
139
|
})
|
|
138
140
|
current = undefined
|
|
139
|
-
|
|
141
|
+
currentFromThisChunk = false
|
|
140
142
|
}
|
|
141
143
|
const finishMessage = message => {
|
|
142
144
|
close()
|
|
@@ -160,15 +162,56 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
160
162
|
},
|
|
161
163
|
observe(chunk) {
|
|
162
164
|
seen = true
|
|
163
|
-
|
|
165
|
+
currentFromThisChunk = false
|
|
164
166
|
for (const part of chunk.candidates?.[0]?.content?.parts ?? []) {
|
|
167
|
+
if (!part || typeof part !== 'object' || Array.isArray(part)) {
|
|
168
|
+
close()
|
|
169
|
+
throw failure('Google returned a malformed candidate part.')
|
|
170
|
+
}
|
|
171
|
+
const definedKeys = Object.keys(part).filter(key => part[key] !== undefined)
|
|
172
|
+
if (definedKeys.length === 0) continue
|
|
173
|
+
const unsupportedKeys = definedKeys.filter(key => !ALLOWED_PART_KEYS.has(key))
|
|
174
|
+
if (unsupportedKeys.length > 0) {
|
|
175
|
+
close()
|
|
176
|
+
throw failure('Google returned an unsupported candidate part (' + unsupportedKeys.join(', ') + ') that cannot be replayed.')
|
|
177
|
+
}
|
|
178
|
+
const call = part.functionCall ?? part.function_call
|
|
179
|
+
const hasText = part.text !== undefined
|
|
180
|
+
const hasCall = call !== undefined
|
|
181
|
+
if (part.thought !== undefined && typeof part.thought !== 'boolean') {
|
|
182
|
+
close()
|
|
183
|
+
throw failure('Google returned a candidate part with an invalid thought flag.')
|
|
184
|
+
}
|
|
185
|
+
if (hasText && typeof part.text !== 'string') {
|
|
186
|
+
close()
|
|
187
|
+
throw failure('Google returned a candidate part with an invalid text field.')
|
|
188
|
+
}
|
|
189
|
+
if (hasCall && (!call || typeof call !== 'object' || Array.isArray(call))) {
|
|
190
|
+
close()
|
|
191
|
+
throw failure('Google returned a candidate part with an invalid functionCall payload.')
|
|
192
|
+
}
|
|
193
|
+
if (hasText && hasCall) {
|
|
194
|
+
close()
|
|
195
|
+
throw failure('Google returned a mixed text/functionCall part that cannot be represented losslessly.')
|
|
196
|
+
}
|
|
197
|
+
if (hasCall && part.thought === true) {
|
|
198
|
+
close()
|
|
199
|
+
throw failure('Google returned a thought-flagged functionCall part that cannot be represented in replay history.')
|
|
200
|
+
}
|
|
165
201
|
bytes += Buffer.byteLength(JSON.stringify(part))
|
|
166
202
|
if (bytes > 64 * 1024 * 1024) throw failure('Google response exceeded the bounded signature replay buffer.')
|
|
167
203
|
// A Part may serialize the signature in either wire spelling.
|
|
168
204
|
const sig = part.thoughtSignature ?? part.thought_signature
|
|
169
|
-
|
|
205
|
+
if (sig !== undefined && typeof sig !== 'string') {
|
|
206
|
+
close()
|
|
207
|
+
throw failure('Google returned a candidate part with an invalid thoughtSignature.')
|
|
208
|
+
}
|
|
209
|
+
const onlySignature = typeof sig === 'string' && !hasText && !hasCall
|
|
170
210
|
if (onlySignature) {
|
|
171
|
-
if (!sig
|
|
211
|
+
if (!sig) {
|
|
212
|
+
close()
|
|
213
|
+
throw failure('Google returned an invalid standalone signature.')
|
|
214
|
+
}
|
|
172
215
|
bytes += 320 // Include the local versioned codec and content binding in the retention bound.
|
|
173
216
|
if (bytes > 64 * 1024 * 1024) throw failure('Google signature replay metadata exceeded the bounded response buffer.')
|
|
174
217
|
close()
|
|
@@ -177,13 +220,17 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
177
220
|
emit({ type: 'text_start', contentIndex: index }); emit({ type: 'text_end', contentIndex: index, content: '' })
|
|
178
221
|
continue
|
|
179
222
|
}
|
|
180
|
-
if (
|
|
223
|
+
if (hasText) {
|
|
181
224
|
const type = part.thought === true ? 'thinking' : 'text'
|
|
182
225
|
const sigKey = type === 'text' ? 'textSignature' : 'thinkingSignature'
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
226
|
+
const curText = type === 'text' ? current?.text : current?.thinking
|
|
227
|
+
const curSig = current?.[sigKey]
|
|
228
|
+
const sameChunkSigBoundary = currentFromThisChunk && (Boolean(curSig) || Boolean(sig))
|
|
229
|
+
const crossChunkSigConflict =
|
|
230
|
+
(Boolean(curSig) && Boolean(sig)) ||
|
|
231
|
+
(Boolean(curSig) && curText === '') ||
|
|
232
|
+
(Boolean(sig) && part.text === '')
|
|
233
|
+
const splitSigned = sameChunkSigBoundary || crossChunkSigConflict
|
|
187
234
|
if (!current || current.type !== type || splitSigned) {
|
|
188
235
|
close(); current = type === 'text' ? { type, text: '' } : { type, thinking: '' }
|
|
189
236
|
const index = start(current)
|
|
@@ -191,23 +238,25 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
191
238
|
}
|
|
192
239
|
const key = type === 'text' ? 'text' : 'thinking'
|
|
193
240
|
current[key] += part.text
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (type === 'thinking') currentSignedInThisChunk = true
|
|
197
|
-
}
|
|
241
|
+
currentFromThisChunk = true
|
|
242
|
+
if (sig) current[sigKey] = sig
|
|
198
243
|
emit({ type: type === 'text' ? 'text_delta' : 'thinking_delta', contentIndex: content.length - 1, delta: part.text })
|
|
244
|
+
continue
|
|
199
245
|
}
|
|
200
|
-
if (
|
|
246
|
+
if (hasCall) {
|
|
201
247
|
close()
|
|
202
|
-
const
|
|
203
|
-
const id =
|
|
248
|
+
const rawId = call.id ?? call.call_id
|
|
249
|
+
const id = rawId && !usedToolIds.has(rawId) ? rawId : 'argon_' + randomUUID().replaceAll('-', '')
|
|
204
250
|
usedToolIds.add(id)
|
|
205
251
|
const block = { type: 'toolCall', id, name: call.name || '', arguments: call.args ?? {}, ...(sig ? { thoughtSignature: sig } : {}) }
|
|
206
252
|
const index = start(block)
|
|
207
253
|
emit({ type: 'toolcall_start', contentIndex: index })
|
|
208
254
|
emit({ type: 'toolcall_delta', contentIndex: index, delta: JSON.stringify(block.arguments) })
|
|
209
255
|
emit({ type: 'toolcall_end', contentIndex: index, toolCall: block })
|
|
256
|
+
continue
|
|
210
257
|
}
|
|
258
|
+
close()
|
|
259
|
+
throw failure('Google returned an unrepresentable candidate part.')
|
|
211
260
|
}
|
|
212
261
|
},
|
|
213
262
|
stream(source) {
|
package/index.js
CHANGED
|
@@ -123,11 +123,18 @@ export function apply(ctx, config) {
|
|
|
123
123
|
try {
|
|
124
124
|
registration = ctx.llm.registerAdapter([PROVIDER], adapter)
|
|
125
125
|
ctx.effect(() => () => {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
try {
|
|
127
|
+
registration?.()
|
|
128
|
+
} finally {
|
|
129
|
+
unpatchPiAi()
|
|
130
|
+
}
|
|
128
131
|
})
|
|
129
132
|
} catch (error) {
|
|
130
|
-
|
|
133
|
+
try {
|
|
134
|
+
registration?.()
|
|
135
|
+
} finally {
|
|
136
|
+
unpatchPiAi()
|
|
137
|
+
}
|
|
131
138
|
throw error
|
|
132
139
|
}
|
|
133
140
|
if (typeof ctx.on === 'function') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vertex-argon",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"description": "Gemini 4 Adapter for DSH: official Vertex AI & Gemini API channels (Argon, Carbon, Hydrogen & Neon), resilient long decode, explicit service tiers, and request diagnostics.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|