scheduler-gateway/lib/client.js
Liuxinyu176 bbb364cd69 feat: DSH 调度网关(互联网关)v6.0.0 — 四模型合并版 R1+R2+R3
- 零第三方依赖,Node >=20 原生 ESM
- 团队式编排引擎:拆解/路由/执行/审查/合并全真实 LLM
- 阶段心跳、单一权威清单守卫、all-keys-failed 如实上报
- H4 会话视图/amend/watchdog 有界重试/产物区 artifacts.json
- H5 零依赖三栏控制台
2026-10-09 23:20:27 +08:00

63 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* DSH client 半(H2):侧边栏「调度网关」面板 + 编程客户端。
* 侧边栏直接内嵌 standalone 中心网关自带面板(同一套核心/同一 API)。
*/
const GW = (typeof process !== "undefined" && process.env?.GATEWAY_URL) || "http://127.0.0.1:4180";
export class GatewayClient {
constructor(baseUrl = GW, nodeToken) {
this.base = baseUrl.replace(/\/$/, "");
this.nodeToken = nodeToken;
}
async _p(path, opts = {}) {
const headers = { ...(opts.headers || {}) };
if (opts.body) headers["content-type"] = "application/json";
if (this.nodeToken) headers["x-node-token"] = this.nodeToken;
const r = await fetch(this.base + path, { ...opts, headers });
return r.json();
}
status() {
return this._p("/api/status");
}
tasks() {
return this._p("/api/tasks");
}
nodes() {
return this._p("/api/nodes");
}
createTask(task) {
return this._p("/api/tasks", { method: "POST", body: JSON.stringify(task) });
}
pipeline(goal, opts = {}) {
return this._p("/api/pipeline", { method: "POST", body: JSON.stringify({ goal, opts }) });
}
approve(taskId) {
return this._p(`/api/tasks/${taskId}/approve`, { method: "POST" });
}
requeueDead(taskId) {
return this._p(`/api/deadletter/${taskId}/retry`, { method: "POST" });
}
events(onEvent) {
const es = new EventSource(this.base + "/api/events");
es.onmessage = (e) => onEvent(JSON.parse(e.data));
return () => es.close();
}
}
/** DSH 侧边栏注册(宿主支持时)。 */
export function registerSidebar(dsh) {
if (!dsh?.ui?.registerPanel) return false;
dsh.ui.registerPanel({
id: "scheduler-gateway-live",
title: "调度网关",
render: () => ({
type: "iframe",
src: `${GW}/panel`,
}),
});
return true;
}
export default GatewayClient;