dsh-agentone 0.5.30 → 0.5.31

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.
Files changed (2) hide show
  1. package/lib/model.js +25 -9
  2. package/package.json +2 -2
package/lib/model.js CHANGED
@@ -5,8 +5,10 @@
5
5
  // settings.yaml llm-pi-ai.providers.platform + agent-default-model
6
6
  // .credentials.yaml refs.AGENTONE_API_KEY(dsh 凭据库,owner-only,watch 热加载)
7
7
  //
8
- // 密钥形态是 30 天插件令牌(M1 exchange 签发),指向平台 /api/plugin/v1 代理;
9
- // 真实 Token Hub 密钥不出平台。
8
+ // 密钥形态:平台 /api/plugin/v1/models 下发 direct(Token Hub base_url + 该用户
9
+ // 自己的 Token Hub 用户级 key),dsh 直连 Token Hub,运行时流量不过境平台(平台
10
+ // 部署国外时避免跨境转发延迟);计量/配额由 Token Hub 按用户令牌口径执行。
11
+ // 旧版平台不下发 direct 时回退为 30 天插件令牌 + 平台 /api/plugin/v1 代理。
10
12
  import { readFile, rename, writeFile } from 'node:fs/promises';
11
13
  import { join } from 'node:path';
12
14
  import { parse, stringify } from 'yaml';
@@ -77,8 +79,13 @@ function parseYamlObject(text) {
77
79
  return {};
78
80
  }
79
81
 
80
- /** 合并出 settings.yaml 文本:覆盖 platform provider 与 agent-default-model。 */
81
- export function buildSettingsYaml(existingText, { baseUrl, models, defaultModel }) {
82
+ /** 合并出 settings.yaml 文本:覆盖 platform provider 与 agent-default-model。
83
+ * direct(直连 Token Hub)时写 compat.supportsDeveloperRole=false:pi-ai 对
84
+ * reasoning 模型默认把系统提示发成 developer 角色(自定义域名不在它的
85
+ * 非标准名单里),GLM 上游只认 system 会 400;false 保持 system。该配置键
86
+ * 需要 dsh-llm-pi-ai ≥ 0.1.0-rc.8,代理模式不写(网关侧有同样的归一化)。
87
+ */
88
+ export function buildSettingsYaml(existingText, { baseUrl, models, defaultModel, direct = false }) {
82
89
  const settings = parseYamlObject(existingText);
83
90
  const existing = settings['llm-pi-ai'];
84
91
  const llmPiAi =
@@ -90,6 +97,7 @@ export function buildSettingsYaml(existingText, { baseUrl, models, defaultModel
90
97
  apiKeyEnv: CREDENTIAL_REF,
91
98
  api: 'openai-completions',
92
99
  baseURL: baseUrl,
100
+ ...(direct ? { compat: { supportsDeveloperRole: false } } : {}),
93
101
  reasoning: 'high',
94
102
  models: models
95
103
  .map((item) => platformModelEntry(item))
@@ -151,7 +159,11 @@ export async function fetchPlatformModels(platformUrl, accessToken) {
151
159
  .filter(Boolean)
152
160
  : [];
153
161
  if (models.length === 0) throw new Error('平台返回的可用模型列表为空');
154
- return { models, defaultModel: data.default_model || (models[0]?.id ?? models[0]) };
162
+ const direct =
163
+ data.direct && typeof data.direct.base_url === 'string' && typeof data.direct.api_key === 'string'
164
+ ? { baseUrl: data.direct.base_url.replace(/\/+$/, ''), apiKey: data.direct.api_key }
165
+ : null;
166
+ return { models, defaultModel: data.default_model || (models[0]?.id ?? models[0]), direct };
155
167
  }
156
168
 
157
169
  async function writeFileAtomic(path, text, mode) {
@@ -172,11 +184,15 @@ function tmpName(path) {
172
184
  export async function applyPlatformModel(config) {
173
185
  const credentials = await loadCredentials(config);
174
186
  if (!credentials) throw new Error('尚未登录平台');
175
- const baseUrl = `${String(credentials.platform_url || config.platformUrl).replace(/\/+$/, '')}/api/plugin/v1`;
176
- const { models, defaultModel } = await fetchPlatformModels(
187
+ const { models, defaultModel, direct } = await fetchPlatformModels(
177
188
  credentials.platform_url || config.platformUrl,
178
189
  credentials.access_token,
179
190
  );
191
+ // 平台下发 direct 时 dsh 直连 Token Hub;否则回退平台代理(旧版平台)。
192
+ const baseUrl = direct
193
+ ? direct.baseUrl
194
+ : `${String(credentials.platform_url || config.platformUrl).replace(/\/+$/, '')}/api/plugin/v1`;
195
+ const providerKey = direct ? direct.apiKey : credentials.access_token;
180
196
  const home = resolveDshHome(config);
181
197
  const settingsPath = join(home, 'settings.yaml');
182
198
  const credentialsPath = join(home, '.credentials.yaml');
@@ -184,10 +200,10 @@ export async function applyPlatformModel(config) {
184
200
  readFile(settingsPath, 'utf8').catch(() => ''),
185
201
  readFile(credentialsPath, 'utf8').catch(() => ''),
186
202
  ]);
187
- await writeFileAtomic(credentialsPath, buildCredentialsYaml(existingCredentials, credentials.access_token), 0o600);
203
+ await writeFileAtomic(credentialsPath, buildCredentialsYaml(existingCredentials, providerKey), 0o600);
188
204
  await writeFileAtomic(
189
205
  settingsPath,
190
- buildSettingsYaml(existingSettings, { baseUrl, models, defaultModel }),
206
+ buildSettingsYaml(existingSettings, { baseUrl, models, defaultModel, direct: direct !== null }),
191
207
  );
192
208
  return { models, defaultModel };
193
209
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-agentone",
3
- "version": "0.5.30",
4
- "description": "AgentOne 平台集成插件:飞书登录、平台模型(同步失败自愈重试)、SkillHub 技能(升级检测一键升级、装后即时刷新、套餐技能自动同步)、套餐申请、插件管理与自助升级、lark-cli / ccpg-cli 探测与一键安装(请求超时与错误码透传、令牌轮换 single-flight、凭据损坏容错与并发安全写入、状态页 UX 增强、全局中文回复默认(AGENTS.md 受标记管理、永不覆盖用户设置))",
3
+ "version": "0.5.31",
4
+ "description": "AgentOne 平台集成插件:飞书登录、平台模型(直连 Token Hub 不过境平台、同步失败自愈重试)、SkillHub 技能(升级检测一键升级、装后即时刷新、套餐技能自动同步)、套餐申请、插件管理与自助升级、lark-cli / ccpg-cli 探测与一键安装(请求超时与错误码透传、令牌轮换 single-flight、凭据损坏容错与并发安全写入、状态页 UX 增强、全局中文回复默认(AGENTS.md 受标记管理、永不覆盖用户设置))",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "smoke": "node scripts/env-matrix-smoke.mjs"