dsh-vertex-argon 2.2.5 → 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 +10 -0
- package/README.md +1 -1
- package/adapter.js +24 -4
- package/google-signatures.js +61 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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
|
+
|
|
5
15
|
## [2.2.5] - 2026-11-19
|
|
6
16
|
|
|
7
17
|
### 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
|
@@ -852,14 +852,33 @@ export function resolveConfigValues(raw = {}) {
|
|
|
852
852
|
}
|
|
853
853
|
}
|
|
854
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
|
+
|
|
855
873
|
/** Serve the official Vertex AI and Gemini API models in one plugin group. */
|
|
856
874
|
export function argonProvider(nativeVertex, models, defaultLevel = undefined, nativeGoogle = googleProvider(), longDecode = true, recordDiagnostic, serviceConfig = {}, responseHub, structuredOutput) {
|
|
857
|
-
const
|
|
875
|
+
const frozenModels = (Array.isArray(models) ? models : [models]).map(freezeDescriptor)
|
|
876
|
+
const modelMap = new Map(frozenModels.map(m => [m.id, m]))
|
|
858
877
|
return {
|
|
859
878
|
id: PROVIDER,
|
|
860
879
|
name: 'Gemini 4 Adapter',
|
|
861
880
|
auth: nativeVertex.auth,
|
|
862
|
-
getModels: () => [...
|
|
881
|
+
getModels: () => [...frozenModels],
|
|
863
882
|
streamSimple(requestModel, context, options = {}) {
|
|
864
883
|
const configured = modelMap.get(requestModel?.id)
|
|
865
884
|
if (!configured || requestModel?.provider !== PROVIDER) {
|
|
@@ -1195,8 +1214,9 @@ export function createArgonAdapter(ctx, configInput, nativeVertex = googleVertex
|
|
|
1195
1214
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1196
1215
|
})
|
|
1197
1216
|
}
|
|
1198
|
-
for (
|
|
1199
|
-
|
|
1217
|
+
for (let i = 0; i < models.length; i++) {
|
|
1218
|
+
models[i][MAX_TOKENS_CEILING] = cfg.explicitMaxTokensCap
|
|
1219
|
+
models[i] = freezeDescriptor(models[i])
|
|
1200
1220
|
}
|
|
1201
1221
|
const configuredMaxTokens = new Map(models.map(m => [m.id, cfg.maxTokens]))
|
|
1202
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')
|
|
@@ -162,13 +164,54 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
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,15 +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
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
189
234
|
if (!current || current.type !== type || splitSigned) {
|
|
190
235
|
close(); current = type === 'text' ? { type, text: '' } : { type, thinking: '' }
|
|
191
236
|
const index = start(current)
|
|
@@ -196,18 +241,22 @@ export function createGoogleSignatureBridge(context, model) {
|
|
|
196
241
|
currentFromThisChunk = true
|
|
197
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/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": {
|