#!/usr/bin/env node // 验证:本人的 per-user key 能否过公司网关;DSH 链路(OpenAI 格式) 与 弹匣链路(Anthropic 格式) 是否都可用。 // 只发最小请求(max_tokens=16),不打印任何 key。 import { readFileSync } from 'node:fs' import { homedir } from 'node:os' import { join } from 'node:path' const cfgPath = join(homedir(), 'Documents/Essay_AI/Essay_system/dsh-markmag/.local-credentials.json') const cfg = JSON.parse(readFileSync(cfgPath, 'utf8')) const key = cfg.key2 || cfg.key1 const BASE = 'https://brain.sidaocai.cn' async function call(name, url, headers, body) { const t0 = Date.now() try { const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', ...headers }, body: JSON.stringify(body), signal: AbortSignal.timeout(40000), }) const text = await res.text() const ms = Date.now() - t0 console.log(`[${name}] status=${res.status} ${ms}ms`) console.log(' body:', text.slice(0, 400).replace(/\n/g, ' ')) return res.status } catch (e) { console.log(`[${name}] FAIL ${Date.now() - t0}ms err=${e.name}: ${e.message}`) return -1 } } console.log('key source: key2 =', Boolean(cfg.key2), ' key1 =', Boolean(cfg.key1)) // A. 弹匣链路:Anthropic messages await call('A-anthropic/claude-code', BASE + '/tdb-api/claude-code/default/v1/messages', { 'x-api-key': key, 'anthropic-version': '2023-06-01' }, { model: 'deepseek-v4-pro', max_tokens: 16, messages: [{ role: 'user', content: 'ping' }] }) // B. DSH 链路:OpenAI chat/completions + 团队头 await call('B-openai/dsh', BASE + '/tdb-api/dsh/default/chat/completions', { authorization: 'Bearer ' + key, 'x-team-id': 'team-oek7kp1cy7', 'x-agent-id': 'agt-of5x44h7ns' }, { model: 'deepseek-v4-pro', max_tokens: 16, messages: [{ role: 'user', content: 'ping' }] }) // C. DSH 链路但不带头(看团队头是否必需) await call('C-openai/dsh-no-header', BASE + '/tdb-api/dsh/default/chat/completions', { authorization: 'Bearer ' + key }, { model: 'deepseek-v4-pro', max_tokens: 16, messages: [{ role: 'user', content: 'ping' }] }) // D. 坏 key(确认鉴权是否真的在拦) await call('D-bad-key', BASE + '/tdb-api/dsh/default/chat/completions', { authorization: 'Bearer sk-mem-INVALID_INVALID_INVALID' }, { model: 'deepseek-v4-pro', max_tokens: 16, messages: [{ role: 'user', content: 'ping' }] })