@dsh-plus/subagent-model 0.2.1 → 0.3.1
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/lib/client.js +62638 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +110 -2
- package/lib/style.css +1639 -0
- package/package.json +30 -9
- package/src/catalog.ts +127 -0
- package/src/client/api.ts +45 -0
- package/src/client/card.tsx +332 -0
- package/src/client/client.ts +79 -0
- package/src/client/draft.ts +69 -0
- package/src/client/i18n.ts +65 -0
- package/src/client/styles.ts +30 -0
- package/src/config-api.ts +53 -0
- package/src/index.ts +4 -2
- package/src/service.ts +8 -1
package/lib/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ declare class SubagentModelService extends Service {
|
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region src/index.d.ts
|
|
49
49
|
declare const name = "dsh-plus-subagent-model";
|
|
50
|
-
declare const inject: readonly ["subagents"];
|
|
50
|
+
declare const inject: readonly ["subagents", "llm"];
|
|
51
51
|
declare function apply(ctx: Context, config: SubagentModelConfig): void;
|
|
52
52
|
//#endregion
|
|
53
53
|
export { Config, type EntryConfig, type InjectedOptions, type SubagentModelConfig, SubagentModelService, apply, inject, name };
|
package/lib/index.js
CHANGED
|
@@ -86,6 +86,109 @@ function validateEntries(entries) {
|
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
88
88
|
//#endregion
|
|
89
|
+
//#region src/catalog.ts
|
|
90
|
+
function toEffort(effort) {
|
|
91
|
+
return {
|
|
92
|
+
id: String(effort.id),
|
|
93
|
+
name: effort.name,
|
|
94
|
+
...effort.description === void 0 ? {} : { description: effort.description }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 构建目录。单个提供商失败只进入 failures,不拖垮其余组;
|
|
99
|
+
* 无模型的组被丢弃(与官方 buildModelCatalog 同语义)。
|
|
100
|
+
*/
|
|
101
|
+
async function buildModelCatalog(ctx) {
|
|
102
|
+
const llm = ctx.get("llm");
|
|
103
|
+
if (llm === void 0) return {
|
|
104
|
+
providers: [],
|
|
105
|
+
failures: [],
|
|
106
|
+
subagentProviders: subagentProvidersOf(ctx)
|
|
107
|
+
};
|
|
108
|
+
const catalog = await Promise.all(llm.listProviders().map(async (provider) => {
|
|
109
|
+
try {
|
|
110
|
+
const models = await llm.listModels(provider.id);
|
|
111
|
+
const entries = await Promise.all(models.map(async (model) => {
|
|
112
|
+
const resolved = await llm.resolveModelInfo(provider.id, model.id);
|
|
113
|
+
const reasoning = resolved.reasoning === void 0 ? void 0 : {
|
|
114
|
+
efforts: resolved.reasoning.efforts.map(toEffort),
|
|
115
|
+
...resolved.reasoning.defaultEffort === void 0 ? {} : { defaultEffort: String(resolved.reasoning.defaultEffort) }
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
id: model.id,
|
|
119
|
+
name: model.name,
|
|
120
|
+
...model.description === void 0 ? {} : { description: model.description },
|
|
121
|
+
...reasoning === void 0 ? {} : { reasoning }
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
return {
|
|
125
|
+
kind: "group",
|
|
126
|
+
group: {
|
|
127
|
+
id: provider.id,
|
|
128
|
+
name: provider.name,
|
|
129
|
+
models: entries
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "failure",
|
|
135
|
+
failure: {
|
|
136
|
+
id: provider.id,
|
|
137
|
+
name: provider.name,
|
|
138
|
+
message: error instanceof Error ? error.message : String(error)
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
return {
|
|
144
|
+
providers: catalog.filter((item) => item.kind === "group" && item.group.models.length > 0).map((item) => item.kind === "group" ? item.group : void 0).filter((group) => group !== void 0),
|
|
145
|
+
failures: catalog.filter((item) => item.kind === "failure").map((item) => item.kind === "failure" ? item.failure : void 0).filter((failure) => failure !== void 0),
|
|
146
|
+
subagentProviders: subagentProvidersOf(ctx)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** 已注册的子代理 provider 名(llm 服务缺失时同样返回,卡片仍可渲染)。 */
|
|
150
|
+
function subagentProvidersOf(ctx) {
|
|
151
|
+
const subagents = ctx.get("subagents");
|
|
152
|
+
return subagents === void 0 ? [] : [...subagents.list()];
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/config-api.ts
|
|
156
|
+
const ROUTE_CATALOG = "/dsh-plus/subagent-model/catalog";
|
|
157
|
+
function sendJson(res, status, body) {
|
|
158
|
+
res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
159
|
+
res.end(JSON.stringify(body));
|
|
160
|
+
}
|
|
161
|
+
async function handleCatalog(ctx, res) {
|
|
162
|
+
sendJson(res, 200, await buildModelCatalog(ctx));
|
|
163
|
+
}
|
|
164
|
+
/** 注册目录路由;返回是否注册成功(webServer 缺失时由调用方保证不调用)。 */
|
|
165
|
+
function registerCatalogApi(ctx) {
|
|
166
|
+
const logger = ctx.logger("subagent-model");
|
|
167
|
+
const guard = (handler) => {
|
|
168
|
+
return async (req, res) => {
|
|
169
|
+
try {
|
|
170
|
+
await handler(req, res);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
173
|
+
logger.warn(`catalog api ${req.method ?? "?"} ${req.url ?? "?"} failed: ${message}`);
|
|
174
|
+
if (!res.headersSent) sendJson(res, 400, { error: message });
|
|
175
|
+
else res.end();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
ctx.webServer.register({
|
|
180
|
+
kind: "exact",
|
|
181
|
+
path: ROUTE_CATALOG,
|
|
182
|
+
handler: guard(async (req, res) => {
|
|
183
|
+
if (req.method !== "GET") {
|
|
184
|
+
sendJson(res, 405, { error: "method not allowed" });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
await handleCatalog(ctx, res);
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
89
192
|
//#region src/delegation.ts
|
|
90
193
|
const WRAPPED = Symbol("dsh-plus-subagent-model.wrapped");
|
|
91
194
|
/**
|
|
@@ -143,10 +246,12 @@ function installDelegationHook(ctx, current) {
|
|
|
143
246
|
* 走 validateEntries 规则(model 不能脱离 provider 等),非法即拒。
|
|
144
247
|
* - 委托挂钩:包装 ctx.subagents.start/startContinuable,按 provider 名
|
|
145
248
|
* (未命中回落 default 条目)注入 agentOptions(provider/model/effort)。
|
|
249
|
+
* - 自定义端点:ctx.webServer 仅注册模型目录路由(配置读写已走官方
|
|
250
|
+
* remote.settings 直连,settings.plugin.item 卡片见 client 半)。
|
|
146
251
|
* @module @dsh-plus/subagent-model
|
|
147
252
|
*/
|
|
148
253
|
var SubagentModelService = class extends Service {
|
|
149
|
-
static [Context.inject] = ["subagents"];
|
|
254
|
+
static [Context.inject] = ["subagents", "llm"];
|
|
150
255
|
current;
|
|
151
256
|
constructor(ctx, config) {
|
|
152
257
|
super(ctx, "subagentModel");
|
|
@@ -164,6 +269,9 @@ var SubagentModelService = class extends Service {
|
|
|
164
269
|
});
|
|
165
270
|
});
|
|
166
271
|
installDelegationHook(ctx, () => this.current());
|
|
272
|
+
ctx.inject(["webServer"], (webCtx) => {
|
|
273
|
+
registerCatalogApi(webCtx);
|
|
274
|
+
});
|
|
167
275
|
}
|
|
168
276
|
/** 当前生效配置(settings 用户层解析结果或 cordis 行级 config)。 */
|
|
169
277
|
currentConfig() {
|
|
@@ -173,7 +281,7 @@ var SubagentModelService = class extends Service {
|
|
|
173
281
|
//#endregion
|
|
174
282
|
//#region src/index.ts
|
|
175
283
|
const name = "dsh-plus-subagent-model";
|
|
176
|
-
const inject = ["subagents"];
|
|
284
|
+
const inject = ["subagents", "llm"];
|
|
177
285
|
function apply(ctx, config) {
|
|
178
286
|
ctx.plugin(SubagentModelService, config);
|
|
179
287
|
}
|