@goodandready/dsh-subscriptions 0.6.71 → 0.6.72
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 +6 -0
- package/README.ru.md +6 -0
- package/README.zh.md +6 -0
- package/lib/accounts-view.js +4 -0
- package/lib/accounts.js +13 -0
- package/lib/client.js +609 -820
- package/lib/doctor.js +163 -0
- package/lib/instructions.js +138 -0
- package/lib/routes/accounts.js +72 -0
- package/lib/routes/status.js +99 -5
- package/package.json +1 -1
package/lib/doctor.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor Auth Doctor: Diagnose authentication, authorization, quota, and network errors
|
|
3
|
+
* into structured, human-understandable recommendations.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const DOCTOR_CODES = {
|
|
7
|
+
GEO_BLOCKED: 'GEO_BLOCKED',
|
|
8
|
+
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
|
|
9
|
+
TOKEN_REVOKED: 'TOKEN_REVOKED',
|
|
10
|
+
MISSING_SCOPE: 'MISSING_SCOPE',
|
|
11
|
+
QUOTA_EXHAUSTED: 'QUOTA_EXHAUSTED',
|
|
12
|
+
RATE_LIMIT: 'RATE_LIMIT',
|
|
13
|
+
PROXY_ERROR: 'PROXY_ERROR',
|
|
14
|
+
UNKNOWN: 'UNKNOWN',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Classifies vendor errors and generates actionable recommendations.
|
|
19
|
+
* @param {any} err
|
|
20
|
+
* @param {string} [provider]
|
|
21
|
+
* @param {any} [_account]
|
|
22
|
+
* @returns {{ code: string, title: string, details: string, recommendation: string } | null}
|
|
23
|
+
*/
|
|
24
|
+
export function diagnoseVendorError(err, provider = '', _account = null) {
|
|
25
|
+
if (!err) return null
|
|
26
|
+
|
|
27
|
+
const msg = String(err.message || err.error || err || '').toLowerCase()
|
|
28
|
+
const code = String(err.code || err.status || err.statusCode || '').toUpperCase()
|
|
29
|
+
const p = String(provider || '').toLowerCase()
|
|
30
|
+
|
|
31
|
+
// 1. Geo-blocking / Cloudflare Firewall (403, 1020, region forbidden)
|
|
32
|
+
if (
|
|
33
|
+
msg.includes('country') ||
|
|
34
|
+
msg.includes('location') ||
|
|
35
|
+
msg.includes('region') ||
|
|
36
|
+
msg.includes('not supported in your country') ||
|
|
37
|
+
msg.includes('cloudflare') ||
|
|
38
|
+
msg.includes('cf-ray') ||
|
|
39
|
+
msg.includes('error 1020') ||
|
|
40
|
+
msg.includes('access denied') ||
|
|
41
|
+
(code === '403' && (msg.includes('forbidden') || msg.includes('blocked') || msg.includes('geoblock')))
|
|
42
|
+
) {
|
|
43
|
+
return {
|
|
44
|
+
code: DOCTOR_CODES.GEO_BLOCKED,
|
|
45
|
+
title: 'Region or IP Blocked by Vendor Firewall',
|
|
46
|
+
details: `The vendor (${p || 'provider'}) returned a geo-restriction or Cloudflare block.`,
|
|
47
|
+
recommendation: 'Configure a dedicated SOCKS5 or HTTP proxy located in a supported region (US, EU, JP) in proxy settings.',
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 2. Token Expired / Session Expired
|
|
52
|
+
if (
|
|
53
|
+
msg.includes('token_expired') ||
|
|
54
|
+
msg.includes('jwt expired') ||
|
|
55
|
+
msg.includes('invalid_grant') ||
|
|
56
|
+
msg.includes('session expired') ||
|
|
57
|
+
msg.includes('refresh token expired') ||
|
|
58
|
+
msg.includes('token has expired') ||
|
|
59
|
+
msg.includes('login_required')
|
|
60
|
+
) {
|
|
61
|
+
return {
|
|
62
|
+
code: DOCTOR_CODES.TOKEN_EXPIRED,
|
|
63
|
+
title: 'OAuth Access or Refresh Token Expired',
|
|
64
|
+
details: 'The stored OAuth credentials have expired and could not be refreshed automatically.',
|
|
65
|
+
recommendation: 'Click "Connect" or "Device Login" to re-authorize the account and establish a fresh session.',
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 3. Token Revoked / Bad Credentials
|
|
70
|
+
if (
|
|
71
|
+
msg.includes('token_revoked') ||
|
|
72
|
+
msg.includes('revoked') ||
|
|
73
|
+
msg.includes('account_deactivated') ||
|
|
74
|
+
msg.includes('invalid_token') ||
|
|
75
|
+
msg.includes('bad_credentials') ||
|
|
76
|
+
code === 'TOKEN_REVOKED' ||
|
|
77
|
+
(code === '401' && (msg.includes('unauthorized') || msg.includes('invalid api key') || msg.includes('incorrect api key')))
|
|
78
|
+
) {
|
|
79
|
+
return {
|
|
80
|
+
code: DOCTOR_CODES.TOKEN_REVOKED,
|
|
81
|
+
title: 'Token Invalid or Revoked',
|
|
82
|
+
details: 'The vendor rejected the API key or OAuth token as invalid or revoked.',
|
|
83
|
+
recommendation: 'Re-issue a fresh session token, API key, or CLI credentials in the vendor dashboard and save it.',
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 4. Missing Scope / Permissions
|
|
88
|
+
if (
|
|
89
|
+
msg.includes('insufficient_scope') ||
|
|
90
|
+
msg.includes('missing_scope') ||
|
|
91
|
+
msg.includes('scope required') ||
|
|
92
|
+
msg.includes('permission_denied') ||
|
|
93
|
+
msg.includes('model_not_found') ||
|
|
94
|
+
msg.includes('not have access') ||
|
|
95
|
+
msg.includes('license_required')
|
|
96
|
+
) {
|
|
97
|
+
return {
|
|
98
|
+
code: DOCTOR_CODES.MISSING_SCOPE,
|
|
99
|
+
title: 'Missing Scope or Model Permissions',
|
|
100
|
+
details: 'The account does not have sufficient entitlements or required scope permissions for this model.',
|
|
101
|
+
recommendation: 'Check your organization role or subscription tier to ensure permissions and access to requested models is granted.',
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 5. Quota Exhausted / Balance Zero
|
|
106
|
+
if (
|
|
107
|
+
msg.includes('insufficient_quota') ||
|
|
108
|
+
msg.includes('exceeded your current quota') ||
|
|
109
|
+
msg.includes('credit_balance_zero') ||
|
|
110
|
+
msg.includes('billing_not_active') ||
|
|
111
|
+
msg.includes('quota exceeded') ||
|
|
112
|
+
msg.includes('run out of credits') ||
|
|
113
|
+
code === 'QUOTA'
|
|
114
|
+
) {
|
|
115
|
+
return {
|
|
116
|
+
code: DOCTOR_CODES.QUOTA_EXHAUSTED,
|
|
117
|
+
title: 'Subscription Quota or Credits Exhausted',
|
|
118
|
+
details: 'The account has consumed 100% of its current billing cycle or token usage quota.',
|
|
119
|
+
recommendation: 'Check your subscription billing dashboard or wait until the quota window resets.',
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 6. Rate Limit / 429
|
|
124
|
+
if (
|
|
125
|
+
code === '429' ||
|
|
126
|
+
code === 'RATE_LIMIT' ||
|
|
127
|
+
msg.includes('too many requests') ||
|
|
128
|
+
msg.includes('rate_limit') ||
|
|
129
|
+
msg.includes('rate limit')
|
|
130
|
+
) {
|
|
131
|
+
return {
|
|
132
|
+
code: DOCTOR_CODES.RATE_LIMIT,
|
|
133
|
+
title: 'Temporary Rate Limit Reached',
|
|
134
|
+
details: 'The vendor is throttling requests (RPM/TPM limit reached) for this account.',
|
|
135
|
+
recommendation: 'Account is placed in temporary cooldown. Requests will automatically route to another account.',
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 7. Network / Proxy Connectivity
|
|
140
|
+
if (
|
|
141
|
+
msg.includes('econnrefused') ||
|
|
142
|
+
msg.includes('etimedout') ||
|
|
143
|
+
msg.includes('enotfound') ||
|
|
144
|
+
msg.includes('fetch failed') ||
|
|
145
|
+
msg.includes('socks') ||
|
|
146
|
+
code === 'ENOTFOUND' ||
|
|
147
|
+
code === 'ETIMEDOUT'
|
|
148
|
+
) {
|
|
149
|
+
return {
|
|
150
|
+
code: DOCTOR_CODES.PROXY_ERROR,
|
|
151
|
+
title: 'Network or Proxy Connection Failure',
|
|
152
|
+
details: 'Failed to establish TCP/TLS connection with the provider API or configured proxy server.',
|
|
153
|
+
recommendation: 'Check server network access, DNS resolution, and verify the configured SOCKS/HTTP proxy is online.',
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
code: DOCTOR_CODES.UNKNOWN,
|
|
159
|
+
title: 'Unexpected Vendor Error',
|
|
160
|
+
details: msg.slice(0, 200) || 'Unknown error occurred during vendor request.',
|
|
161
|
+
recommendation: 'Review vendor API status or re-check account credentials.',
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export const INSTRUCTIONS = {
|
|
2
|
+
codex: {
|
|
3
|
+
title: "OpenAI / ChatGPT Codex",
|
|
4
|
+
stepsEn: [
|
|
5
|
+
"1. Log in via CLI on server: run \"codex login\" in terminal.",
|
|
6
|
+
"2. Click \"📥 From CLI\" to auto-import ~/.codex/auth.json.",
|
|
7
|
+
"3. Or click \"Device Login\" above and enter the code at auth.openai.com.",
|
|
8
|
+
],
|
|
9
|
+
stepsZh: [
|
|
10
|
+
"1. 在服务器上通过 CLI 登录:在终端运行 \"codex login\"。",
|
|
11
|
+
"2. 点击 \"📥 从 CLI 导入\" 自动读取 ~/.codex/auth.json。",
|
|
12
|
+
"3. 或者点击上方的 \"设备码登录\" (Device Login) 并在 auth.openai.com 输入代码。",
|
|
13
|
+
],
|
|
14
|
+
link: "https://chatgpt.com",
|
|
15
|
+
},
|
|
16
|
+
claude: {
|
|
17
|
+
title: "Claude Code",
|
|
18
|
+
stepsEn: [
|
|
19
|
+
"1. Run \"claude login\" in server console.",
|
|
20
|
+
"2. Click \"📥 From CLI\" — plugin will import ~/.claude/credentials.json.",
|
|
21
|
+
"3. Or paste your Session Token / API Key from Anthropic Console and click \"Save token\".",
|
|
22
|
+
],
|
|
23
|
+
stepsZh: [
|
|
24
|
+
"1. 在服务器控制台运行 \"claude login\"。",
|
|
25
|
+
"2. 点击 \"📥 从 CLI 导入\" — 插件将自动导入 ~/.claude/credentials.json。",
|
|
26
|
+
"3. 或者从 Anthropic 控制台复制您的 Session Token 或 API Key 并点击 \"保存令牌\"。",
|
|
27
|
+
],
|
|
28
|
+
link: "https://console.anthropic.com/settings/keys",
|
|
29
|
+
},
|
|
30
|
+
cursor: {
|
|
31
|
+
title: "Cursor IDE",
|
|
32
|
+
stepsEn: [
|
|
33
|
+
"1. Auto CLI: if Cursor is used on server, click \"📥 From CLI\" (reads from ~/.cursor/cli-config.json).",
|
|
34
|
+
"2. Manual: open Cursor Settings (Connect button or link below), copy your session token or API key.",
|
|
35
|
+
"3. Paste it into the input field and click \"Save token\".",
|
|
36
|
+
],
|
|
37
|
+
stepsZh: [
|
|
38
|
+
"1. CLI 自动导入:若服务器安装了 Cursor,点击 \"📥 从 CLI 导入\" (读取自 ~/.cursor/cli-config.json)。",
|
|
39
|
+
"2. 手动导入:打开 Cursor 设置页面(点击连接或下方链接),复制 WorkOS 会话令牌或 API 密钥。",
|
|
40
|
+
"3. 将其粘贴到输入框中并点击 \"保存令牌\"。",
|
|
41
|
+
],
|
|
42
|
+
link: "https://cursor.com/settings",
|
|
43
|
+
},
|
|
44
|
+
antigravity: {
|
|
45
|
+
title: "Google Antigravity / Gemini",
|
|
46
|
+
stepsEn: [
|
|
47
|
+
"1. Easiest way: click \"📥 From CLI\" — server already has active token in ~/.gemini/antigravity-cli/antigravity-oauth-token.",
|
|
48
|
+
"2. Clicking \"📥 From CLI\" instantly loads fresh credentials.",
|
|
49
|
+
"3. Manual: paste session JSON or OAuth tokens and click \"Save token\".",
|
|
50
|
+
"Note: \"Connect\" button requires custom Google client_id in plugin settings; use \"📥 From CLI\" for seamless login!",
|
|
51
|
+
],
|
|
52
|
+
stepsZh: [
|
|
53
|
+
"1. 推荐方式:点击 \"📥 从 CLI 导入\" — 服务器已保存 ~/.gemini/antigravity-cli/antigravity-oauth-token 会话。",
|
|
54
|
+
"2. 点击 \"📥 从 CLI 导入\" 可即时加载最新的凭据与 refresh_token。",
|
|
55
|
+
"3. 手动输入:将会话 JSON 或 OAuth access_token/refresh_token 粘贴至输入框并保存。",
|
|
56
|
+
"注:\"连接\" 按钮需要自定义 Google OAuth Client ID,推荐直接使用 \"📥 从 CLI 导入\"!",
|
|
57
|
+
],
|
|
58
|
+
link: "https://antigravity.google",
|
|
59
|
+
},
|
|
60
|
+
kimi: {
|
|
61
|
+
title: "Moonshot Kimi",
|
|
62
|
+
stepsEn: [
|
|
63
|
+
"1. Open Moonshot developer console (link below or click Connect).",
|
|
64
|
+
"2. Generate and copy your API Key (sk-...).",
|
|
65
|
+
"3. Paste it into the input field and click \"Save token\".",
|
|
66
|
+
"4. Or click \"📥 From CLI\" if ~/.kimi-code is configured.",
|
|
67
|
+
],
|
|
68
|
+
stepsZh: [
|
|
69
|
+
"1. 打开 Moonshot 开发者控制台(点击下方链接或点击连接)。",
|
|
70
|
+
"2. 创建并复制您的 API 密钥 (sk-...)。",
|
|
71
|
+
"3. 将密钥粘贴到槽位输入框中并点击 \"保存令牌\"。",
|
|
72
|
+
"4. 如果配置了 Kimi Code CLI,也可点击 \"📥 从 CLI 导入\" (~/.kimi-code)。",
|
|
73
|
+
],
|
|
74
|
+
link: "https://platform.moonshot.cn/console/api-keys",
|
|
75
|
+
},
|
|
76
|
+
glm: {
|
|
77
|
+
title: "Zhipu GLM (Z.AI)",
|
|
78
|
+
stepsEn: [
|
|
79
|
+
"1. Open Zhipu BigModel API Keys center (link below or click Connect).",
|
|
80
|
+
"2. Copy your GLM API Key.",
|
|
81
|
+
"3. Paste it into the input field and click \"Save token\".",
|
|
82
|
+
"4. Or click \"📥 From CLI\" if ZCode CLI is installed (~/.zcode).",
|
|
83
|
+
],
|
|
84
|
+
stepsZh: [
|
|
85
|
+
"1. 打开智谱 AI 开放平台(点击下方链接或点击连接)。",
|
|
86
|
+
"2. 复制您的 GLM API 密钥。",
|
|
87
|
+
"3. 粘贴到输入框中并点击 \"保存令牌\"。",
|
|
88
|
+
"4. 若已安装 ZCode CLI (~/.zcode),点击 \"📥 从 CLI 导入\" 即可自动导入。",
|
|
89
|
+
],
|
|
90
|
+
link: "https://bigmodel.cn/usercenter/proj-mgmt/apikeys",
|
|
91
|
+
},
|
|
92
|
+
grok: {
|
|
93
|
+
title: "xAI Grok",
|
|
94
|
+
stepsEn: [
|
|
95
|
+
"1. Click \"Device Login\" (or \"Connect\") on the slot card.",
|
|
96
|
+
"2. A one-time code will appear on the card.",
|
|
97
|
+
"3. Open https://accounts.x.ai/oauth2/device, enter the code, and approve access for your xAI account.",
|
|
98
|
+
"4. The plugin automatically captures tokens and enables Grok models.",
|
|
99
|
+
"5. Or click \"📥 From CLI\" (~/.grok/auth.json) / paste an xAI API Key.",
|
|
100
|
+
],
|
|
101
|
+
stepsZh: [
|
|
102
|
+
"1. 点击卡片上的 \"设备码登录\" (Device Login) 或 \"连接\"。",
|
|
103
|
+
"2. 界面将展示一次性设备授权码。",
|
|
104
|
+
"3. 打开 https://accounts.x.ai/oauth2/device,输入代码,并为您拥有 Grok 订阅的 xAI 账户授权。",
|
|
105
|
+
"4. 授权成功后,插件会自动捕获会话并激活 Grok 官方模型。",
|
|
106
|
+
"5. 或点击 \"📥 从 CLI 导入\" (~/.grok/auth.json) / 直接粘贴 xAI API 密钥。",
|
|
107
|
+
],
|
|
108
|
+
link: "https://accounts.x.ai/oauth2/device",
|
|
109
|
+
},
|
|
110
|
+
kiro: {
|
|
111
|
+
title: "AWS Kiro",
|
|
112
|
+
stepsEn: [
|
|
113
|
+
"1. Click \"📥 From CLI\" to import from ~/.kiro/credentials.json.",
|
|
114
|
+
"2. Or paste KIRO_API_KEY and click \"Save token\".",
|
|
115
|
+
],
|
|
116
|
+
stepsZh: [
|
|
117
|
+
"1. 点击 \"📥 从 CLI 导入\" 从 ~/.kiro/credentials.json 或 ~/.aws/sso 导入凭据。",
|
|
118
|
+
"2. 或直接粘贴 KIRO_API_KEY 并点击 \"保存令牌\"。",
|
|
119
|
+
],
|
|
120
|
+
link: "https://aws.amazon.com",
|
|
121
|
+
},
|
|
122
|
+
copilot: {
|
|
123
|
+
title: "GitHub Copilot",
|
|
124
|
+
stepsEn: [
|
|
125
|
+
"1. Click \"Device Login\" (or \"Connect\") on the slot card.",
|
|
126
|
+
"2. A one-time code will appear on the card.",
|
|
127
|
+
"3. Open https://github.com/login/device, enter the code, and approve access for your GitHub account with Copilot subscription.",
|
|
128
|
+
"4. The plugin automatically captures tokens and enables Copilot models.",
|
|
129
|
+
],
|
|
130
|
+
stepsZh: [
|
|
131
|
+
"1. 点击卡片上的 \"设备码登录\" (Device Login) 或 \"连接\"。",
|
|
132
|
+
"2. 界面将展示一次性设备授权码。",
|
|
133
|
+
"3. 在浏览器打开 https://github.com/login/device 输入代码,并为您拥有 Copilot 订阅的 GitHub 账户授权。",
|
|
134
|
+
"4. 授权成功后,插件会自动捕获会话并激活 GitHub Copilot 官方模型。",
|
|
135
|
+
],
|
|
136
|
+
link: "https://github.com/login/device",
|
|
137
|
+
},
|
|
138
|
+
}
|
package/lib/routes/accounts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { diagnoseVendorError } from '../doctor.js'
|
|
1
2
|
import { exportVault, importVault } from '../vault.js'
|
|
2
3
|
import { normalizeSlots, vendorConfig } from '../accounts.js'
|
|
3
4
|
import { getVendor } from '../vendors/index.js'
|
|
@@ -445,6 +446,77 @@ export function registerAccountsRoutes(ctx, state) {
|
|
|
445
446
|
}),
|
|
446
447
|
}), 'dsh-subscriptions: /import-token')
|
|
447
448
|
|
|
449
|
+
// Issue #541: Dynamic model catalog discovery & sync
|
|
450
|
+
ctx.effect(() => ctx.webServer.register({
|
|
451
|
+
kind: 'exact',
|
|
452
|
+
path: '/dsh-subscriptions/accounts/sync-models',
|
|
453
|
+
handler: safeJsonHandler(async (req, res) => {
|
|
454
|
+
if (req.method !== 'POST') {
|
|
455
|
+
writeJson(res, 405, { ok: false, error: { code: 'method', message: 'POST only' } })
|
|
456
|
+
return
|
|
457
|
+
}
|
|
458
|
+
if (!isTrustedSettingsRequest(req, ctx)) {
|
|
459
|
+
writeJson(res, 403, { ok: false, error: { code: 'forbidden', message: 'same-origin only' } })
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
let payload = {}
|
|
463
|
+
try { payload = JSON.parse((await readBody(req, 64 * 1024)).toString('utf8') || '{}') } catch { /* ignore */ }
|
|
464
|
+
const provider = payload.provider
|
|
465
|
+
const index = payload.index || 1
|
|
466
|
+
if (!provider || !isProvider(provider)) {
|
|
467
|
+
writeJson(res, 400, { ok: false, error: { code: 'invalid_provider', message: 'Invalid or missing provider' } })
|
|
468
|
+
return
|
|
469
|
+
}
|
|
470
|
+
const ref = oauthRef(provider, index)
|
|
471
|
+
const info = await store.describeRef(ref)
|
|
472
|
+
if (!info.configured) {
|
|
473
|
+
writeJson(res, 400, { ok: false, error: { code: 'not_configured', message: 'Account is not configured' } })
|
|
474
|
+
return
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
let blob = await store.loadBlob(ref)
|
|
478
|
+
blob = await store.ensureFresh(provider, blob, ref)
|
|
479
|
+
const vendor = getVendor(provider)
|
|
480
|
+
const cfg = vendorConfig(provider, live())
|
|
481
|
+
const doFetch = (typeof state.fetchForRef === 'function' && state.fetchForRef(ref)) || fetch
|
|
482
|
+
let models = []
|
|
483
|
+
if (typeof vendor.listModels === 'function') {
|
|
484
|
+
const cat = await vendor.listModels(blob, cfg, doFetch)
|
|
485
|
+
if (Array.isArray(cat)) {
|
|
486
|
+
models = cat.map((m) => (typeof m === 'string' ? m : (m.id || m.slug || m.name))).filter(Boolean)
|
|
487
|
+
} else if (cat && Array.isArray(cat.models)) {
|
|
488
|
+
models = cat.models.map((m) => (typeof m === 'string' ? m : (m.id || m.slug || m.name))).filter(Boolean)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (!models.length && vendor.defaults) {
|
|
492
|
+
models = (vendor.defaults().models || []).map((m) => (typeof m === 'string' ? m : (m.id || m.slug || m.name))).filter(Boolean)
|
|
493
|
+
}
|
|
494
|
+
if (typeof store.rememberDynamicModels === 'function') {
|
|
495
|
+
store.rememberDynamicModels(ref, models)
|
|
496
|
+
}
|
|
497
|
+
writeJson(res, 200, {
|
|
498
|
+
ok: true,
|
|
499
|
+
provider,
|
|
500
|
+
index,
|
|
501
|
+
ref,
|
|
502
|
+
count: models.length,
|
|
503
|
+
models,
|
|
504
|
+
})
|
|
505
|
+
} catch (err) {
|
|
506
|
+
const doc = diagnoseVendorError(err, provider)
|
|
507
|
+
writeJson(res, 502, {
|
|
508
|
+
ok: false,
|
|
509
|
+
provider,
|
|
510
|
+
index,
|
|
511
|
+
ref,
|
|
512
|
+
doctor: doc,
|
|
513
|
+
error: { code: 'sync_failed', message: String(err && err.message || err) },
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
}),
|
|
517
|
+
}), 'dsh-subscriptions: /accounts/sync-models')
|
|
518
|
+
|
|
519
|
+
|
|
448
520
|
|
|
449
521
|
ctx.effect(() => ctx.webServer.register({
|
|
450
522
|
kind: 'exact',
|
package/lib/routes/status.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { diagnoseVendorError } from '../doctor.js'
|
|
2
|
+
import { INSTRUCTIONS } from '../instructions.js'
|
|
1
3
|
import {
|
|
2
4
|
getModelReasoningCapabilities,
|
|
3
5
|
setSessionReasoning,
|
|
@@ -505,9 +507,13 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
505
507
|
blob = await store.loadBlob(ref)
|
|
506
508
|
blob = await store.ensureFresh(provider, blob, ref)
|
|
507
509
|
} catch (e) {
|
|
508
|
-
const latencyMs = Date.now() - t0
|
|
510
|
+
const latencyMs = Math.max(1, Date.now() - t0)
|
|
511
|
+
const latencyGrade = latencyMs < 250 ? 'good' : (latencyMs < 750 ? 'fair' : 'poor')
|
|
512
|
+
if (typeof store.rememberPing === "function") store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
513
|
+
const docVerdict = diagnoseVendorError(e, provider, blob)
|
|
514
|
+
if (typeof store.rememberDoctorVerdict === "function") store.rememberDoctorVerdict(ref, docVerdict)
|
|
509
515
|
history.add({ provider, ref, path: "/smoke", status: 401, ms: latencyMs })
|
|
510
|
-
writeJson(res, 502, { ok: false, provider, index, ref, latencyMs, error: { code: 'auth_failed', message: String(e && e.message || e) } })
|
|
516
|
+
writeJson(res, 502, { ok: false, provider, index, ref, latencyMs, latencyGrade, doctor: docVerdict, error: { code: 'auth_failed', message: String(e && e.message || e) } })
|
|
511
517
|
return
|
|
512
518
|
}
|
|
513
519
|
|
|
@@ -525,7 +531,10 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
525
531
|
}
|
|
526
532
|
try {
|
|
527
533
|
await vendor.check(blob, vendorConfig(provider, live()), probeFetch)
|
|
528
|
-
const latencyMs = Date.now() - t0
|
|
534
|
+
const latencyMs = Math.max(1, Date.now() - t0)
|
|
535
|
+
const latencyGrade = latencyMs < 250 ? 'good' : (latencyMs < 750 ? 'fair' : 'poor')
|
|
536
|
+
if (typeof store.rememberPing === "function") store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
537
|
+
if (typeof store.rememberDoctorVerdict === "function") store.rememberDoctorVerdict(ref, null)
|
|
529
538
|
history.add({ provider, ref, path: "/smoke", status: 200, ms: latencyMs })
|
|
530
539
|
writeJson(res, 200, {
|
|
531
540
|
ok: true,
|
|
@@ -533,6 +542,7 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
533
542
|
index,
|
|
534
543
|
ref,
|
|
535
544
|
latencyMs,
|
|
545
|
+
latencyGrade,
|
|
536
546
|
label: pmL(blob.label),
|
|
537
547
|
email: pmE(blob.email),
|
|
538
548
|
quota: capturedQuota || info.quota || null,
|
|
@@ -540,7 +550,11 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
540
550
|
})
|
|
541
551
|
return
|
|
542
552
|
} catch (e) {
|
|
543
|
-
const latencyMs = Date.now() - t0
|
|
553
|
+
const latencyMs = Math.max(1, Date.now() - t0)
|
|
554
|
+
const latencyGrade = latencyMs < 250 ? 'good' : (latencyMs < 750 ? 'fair' : 'poor')
|
|
555
|
+
if (typeof store.rememberPing === "function") store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
556
|
+
const docVerdict = diagnoseVendorError(e, provider, blob)
|
|
557
|
+
if (typeof store.rememberDoctorVerdict === "function") store.rememberDoctorVerdict(ref, docVerdict)
|
|
544
558
|
history.add({ provider, ref, path: "/smoke", status: 502, ms: latencyMs })
|
|
545
559
|
writeJson(res, 502, {
|
|
546
560
|
ok: false,
|
|
@@ -548,13 +562,18 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
548
562
|
index,
|
|
549
563
|
ref,
|
|
550
564
|
latencyMs,
|
|
565
|
+
latencyGrade,
|
|
566
|
+
doctor: docVerdict,
|
|
551
567
|
error: { code: e && e.code ? e.code : 'VENDOR', message: String(e && e.message || e).slice(0, 300) },
|
|
552
568
|
})
|
|
553
569
|
return
|
|
554
570
|
}
|
|
555
571
|
}
|
|
556
572
|
|
|
557
|
-
const latencyMs = Date.now() - t0
|
|
573
|
+
const latencyMs = Math.max(1, Date.now() - t0)
|
|
574
|
+
const latencyGrade = latencyMs < 250 ? 'good' : (latencyMs < 750 ? 'fair' : 'poor')
|
|
575
|
+
if (typeof store.rememberPing === "function") store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
576
|
+
if (typeof store.rememberDoctorVerdict === "function") store.rememberDoctorVerdict(ref, null)
|
|
558
577
|
history.add({ provider, ref, path: "/smoke", status: 200, ms: latencyMs })
|
|
559
578
|
writeJson(res, 200, {
|
|
560
579
|
ok: true,
|
|
@@ -562,6 +581,7 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
562
581
|
index,
|
|
563
582
|
ref,
|
|
564
583
|
latencyMs,
|
|
584
|
+
latencyGrade,
|
|
565
585
|
label: pmL(blob.label),
|
|
566
586
|
email: pmE(blob.email),
|
|
567
587
|
quota: info.quota || null,
|
|
@@ -569,6 +589,80 @@ export function registerStatusRoutes(ctx, state) {
|
|
|
569
589
|
}),
|
|
570
590
|
}), 'dsh-subscriptions: /smoke')
|
|
571
591
|
|
|
592
|
+
// Issue #542: Latency RTT ping test endpoint
|
|
593
|
+
ctx.effect(() => ctx.webServer.register({
|
|
594
|
+
kind: 'exact',
|
|
595
|
+
path: '/dsh-subscriptions/ping',
|
|
596
|
+
handler: safeJsonHandler(async (req, res) => {
|
|
597
|
+
if (req.method !== 'POST') {
|
|
598
|
+
writeJson(res, 405, { ok: false, error: { code: 'method', message: 'POST only' } })
|
|
599
|
+
return
|
|
600
|
+
}
|
|
601
|
+
if (!isTrustedSettingsRequest(req, ctx)) {
|
|
602
|
+
writeJson(res, 403, { ok: false, error: { code: 'forbidden', message: 'same-origin only' } })
|
|
603
|
+
return
|
|
604
|
+
}
|
|
605
|
+
let payload = {}
|
|
606
|
+
try { payload = JSON.parse((await readBody(req, 64 * 1024)).toString('utf8') || '{}') } catch { /* ignore ping payload */ }
|
|
607
|
+
const provider = payload.provider
|
|
608
|
+
const index = payload.index || 1
|
|
609
|
+
if (!provider || !isProvider(provider)) {
|
|
610
|
+
writeJson(res, 400, { ok: false, error: { code: 'invalid_provider', message: 'Provider required' } })
|
|
611
|
+
return
|
|
612
|
+
}
|
|
613
|
+
const ref = oauthRef(provider, index)
|
|
614
|
+
const info = await store.describeRef(ref)
|
|
615
|
+
if (!info.configured) {
|
|
616
|
+
writeJson(res, 400, { ok: false, error: { code: 'not_configured', message: 'Account is not configured' } })
|
|
617
|
+
return
|
|
618
|
+
}
|
|
619
|
+
const t0 = Date.now()
|
|
620
|
+
let latencyMs = 0
|
|
621
|
+
let latencyGrade = 'good'
|
|
622
|
+
try {
|
|
623
|
+
const blob = await store.loadBlob(ref)
|
|
624
|
+
const vendor = getVendor(provider)
|
|
625
|
+
const cfg = vendorConfig(provider, live())
|
|
626
|
+
const doFetch = (typeof fetchForRef === 'function' && fetchForRef(ref)) || fetch
|
|
627
|
+
if (typeof vendor.check === 'function') {
|
|
628
|
+
await vendor.check(blob, cfg, doFetch)
|
|
629
|
+
} else if (typeof vendor.listModels === 'function') {
|
|
630
|
+
await vendor.listModels(blob, cfg, doFetch)
|
|
631
|
+
}
|
|
632
|
+
latencyMs = Math.max(1, Date.now() - t0)
|
|
633
|
+
latencyGrade = latencyMs < 250 ? 'good' : (latencyMs < 750 ? 'fair' : 'poor')
|
|
634
|
+
if (typeof store.rememberPing === 'function') store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
635
|
+
if (typeof store.rememberDoctorVerdict === 'function') store.rememberDoctorVerdict(ref, null)
|
|
636
|
+
writeJson(res, 200, { ok: true, provider, index, ref, latencyMs, latencyGrade })
|
|
637
|
+
} catch (err) {
|
|
638
|
+
latencyMs = Math.max(1, Date.now() - t0)
|
|
639
|
+
latencyGrade = 'poor'
|
|
640
|
+
const doc = diagnoseVendorError(err, provider)
|
|
641
|
+
if (typeof store.rememberPing === 'function') store.rememberPing(ref, { latencyMs, latencyGrade })
|
|
642
|
+
if (typeof store.rememberDoctorVerdict === 'function') store.rememberDoctorVerdict(ref, doc)
|
|
643
|
+
writeJson(res, 502, { ok: false, provider, index, ref, latencyMs, latencyGrade, doctor: doc, error: { message: String(err && err.message || err) } })
|
|
644
|
+
}
|
|
645
|
+
}),
|
|
646
|
+
}), 'dsh-subscriptions: /ping')
|
|
647
|
+
|
|
648
|
+
// Issue #540: Dynamic vendor instructions API
|
|
649
|
+
ctx.effect(() => ctx.webServer.register({
|
|
650
|
+
kind: 'exact',
|
|
651
|
+
path: '/dsh-subscriptions/instructions',
|
|
652
|
+
handler: safeJsonHandler(async (req, res) => {
|
|
653
|
+
if (req.method !== 'GET') {
|
|
654
|
+
writeJson(res, 405, { ok: false, error: { code: 'method', message: 'GET only' } })
|
|
655
|
+
return
|
|
656
|
+
}
|
|
657
|
+
if (!isTrustedSettingsRequest(req, ctx)) {
|
|
658
|
+
writeJson(res, 403, { ok: false, error: { code: 'forbidden', message: 'same-origin only' } })
|
|
659
|
+
return
|
|
660
|
+
}
|
|
661
|
+
writeJson(res, 200, { ok: true, instructions: INSTRUCTIONS })
|
|
662
|
+
}),
|
|
663
|
+
}), 'dsh-subscriptions: /instructions')
|
|
664
|
+
|
|
665
|
+
|
|
572
666
|
// #351: Quota and session alerts API
|
|
573
667
|
ctx.effect(() => ctx.webServer.register({
|
|
574
668
|
kind: 'exact',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-subscriptions",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.72",
|
|
4
4
|
"description": "Use ChatGPT Codex, Claude, Grok, Antigravity, Kimi, GLM, Cursor, Kiro, Copilot, Qwen, ERNIE, Spark, JetBrains, Perplexity, Replit, and Cody subscriptions as DeepSeek Harness LLM providers via OAuth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|