@1agents/dsh-a2a 0.0.0-stage → 0.1.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/README.md +57 -2
- package/cordis.patch.yml +10 -0
- package/dist/approvals.js +50 -0
- package/dist/cli.js +32596 -0
- package/dist/executor.js +24896 -0
- package/dist/index.js +32595 -0
- package/dist/sdk-runtime.js +166 -0
- package/dist/server.js +32581 -0
- package/dist/shared/a2a/workbench-ui.js +186 -0
- package/dist/workbench-ui/app.css +453 -0
- package/dist/workbench-ui/app.js +13 -0
- package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
- package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
- package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
- package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
- package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
- package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
- package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
- package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
- package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
- package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
- package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
- package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
- package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
- package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
- package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
- package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
- package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
- package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
- package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
- package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
- package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
- package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
- package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
- package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
- package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
- package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
- package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
- package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
- package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
- package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
- package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
- package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
- package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
- package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
- package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
- package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
- package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
- package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
- package/dist/workbench-ui/chunk-E253Y562.js +1 -0
- package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
- package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
- package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
- package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
- package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
- package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
- package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
- package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
- package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
- package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
- package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
- package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
- package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
- package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
- package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
- package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
- package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
- package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
- package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
- package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
- package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
- package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
- package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
- package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
- package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
- package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
- package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
- package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
- package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
- package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
- package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
- package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
- package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
- package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
- package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
- package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
- package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
- package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
- package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
- package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
- package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
- package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
- package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
- package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
- package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
- package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
- package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
- package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
- package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
- package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
- package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
- package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
- package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
- package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
- package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
- package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
- package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
- package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
- package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
- package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
- package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
- package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
- package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
- package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
- package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
- package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
- package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
- package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
- package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
- package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
- package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
- package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
- package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
- package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
- package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
- package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
- package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
- package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
- package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
- package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
- package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
- package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
- package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
- package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
- package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
- package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
- package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
- package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
- package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
- package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
- package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
- package/dist/workbench-ui/index.html +14 -0
- package/dist/workbench.js +222 -0
- package/package.json +33 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/sdk-runtime.js
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
// src/approvals.js
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
9
|
+
async function requestApproval(workbench, execution, sessionId, params, signal) {
|
|
10
|
+
if (!workbench?.url || !execution?.jobId || !execution?.attemptId) return { outcome: "cancelled" };
|
|
11
|
+
const origin = new URL(workbench.url).origin;
|
|
12
|
+
const headers = { "Content-Type": "application/json", ...workbench.token ? { Authorization: `Bearer ${workbench.token}` } : {} };
|
|
13
|
+
const requestId = `prc-${randomUUID().replaceAll("-", "")}`;
|
|
14
|
+
const path = `/workbench/tasks/${encodeURIComponent(execution.jobId)}/process-requests`;
|
|
15
|
+
const send = async (suffix, method, body, requestSignal = signal) => {
|
|
16
|
+
const response = await fetch(new URL(path + suffix, origin), {
|
|
17
|
+
method,
|
|
18
|
+
headers,
|
|
19
|
+
signal: requestSignal,
|
|
20
|
+
redirect: "error",
|
|
21
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) throw new Error(`Approval gateway returned ${response.status}`);
|
|
24
|
+
return response.json();
|
|
25
|
+
};
|
|
26
|
+
try {
|
|
27
|
+
const opened = await send("", "POST", {
|
|
28
|
+
requestId,
|
|
29
|
+
jobId: execution.jobId,
|
|
30
|
+
attemptId: execution.attemptId,
|
|
31
|
+
sessionId,
|
|
32
|
+
kind: "permission",
|
|
33
|
+
toolTitle: String(params.toolName ?? "DSH operation").slice(0, 500),
|
|
34
|
+
toolDetail: String(params.reason ?? "").slice(0, 16384)
|
|
35
|
+
});
|
|
36
|
+
if (opened.requestId !== requestId) throw new Error("Approval receipt identity mismatch");
|
|
37
|
+
for (; ; ) {
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
const view = await send(`/${requestId}`, "GET");
|
|
40
|
+
if (view.requestId !== requestId || view.jobId !== execution.jobId) throw new Error("Approval identity mismatch");
|
|
41
|
+
if (view.status === "answered") return { outcome: view.answer?.outcome === "approved" ? "allowed-once" : view.answer?.outcome === "rejected" ? "rejected" : "cancelled" };
|
|
42
|
+
if (view.status !== "pending" || !Number.isFinite(Date.parse(view.deadlineAt)) || Date.parse(view.deadlineAt) <= Date.now()) break;
|
|
43
|
+
await delay(workbench.pollMs ?? 200, void 0, { signal });
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await send(`/${requestId}/answers`, "POST", { clientRequestId: `cancel:${requestId}`, outcome: "cancelled" }, AbortSignal.timeout(5e3));
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
return { outcome: "cancelled" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/sdk-runtime.js
|
|
55
|
+
async function runSdk(runtime, record, prompt, options, save) {
|
|
56
|
+
if (!runtime.provider || !runtime.model) throw new Error("SDK runtime requires provider and model configuration");
|
|
57
|
+
const child = spawn(runtime.command, runtime.args, { cwd: record.cwd, env: { ...process.env, ...runtime.env }, stdio: ["pipe", "pipe", "pipe"] });
|
|
58
|
+
const controller = new AbortController(), signal = AbortSignal.any([options.signal, controller.signal]);
|
|
59
|
+
const pending = /* @__PURE__ */ new Map(), approvalTasks = /* @__PURE__ */ new Set();
|
|
60
|
+
let serial = 0, terminal, text = "", alive = true;
|
|
61
|
+
const write = (value) => {
|
|
62
|
+
if (alive && !child.stdin.destroyed) child.stdin.write(`${JSON.stringify(value)}
|
|
63
|
+
`);
|
|
64
|
+
};
|
|
65
|
+
child.stdin.on("error", () => {
|
|
66
|
+
});
|
|
67
|
+
child.stderr.resume();
|
|
68
|
+
const exited = new Promise((resolve) => child.once("close", (code) => resolve(code)));
|
|
69
|
+
const fail = (error) => {
|
|
70
|
+
controller.abort(error);
|
|
71
|
+
for (const task of pending.values()) task.reject(error);
|
|
72
|
+
pending.clear();
|
|
73
|
+
};
|
|
74
|
+
child.once("error", fail);
|
|
75
|
+
child.once("close", () => {
|
|
76
|
+
alive = false;
|
|
77
|
+
fail(new Error("DSH SDK transport closed"));
|
|
78
|
+
});
|
|
79
|
+
const request = (method, params) => new Promise((resolve, reject) => {
|
|
80
|
+
if (signal.aborted) return reject(signal.reason);
|
|
81
|
+
const id = ++serial;
|
|
82
|
+
const timer = ["initialize", "shutdown", "session/resume"].includes(method) ? setTimeout(() => {
|
|
83
|
+
pending.delete(id);
|
|
84
|
+
reject(new Error(`DSH SDK ${method} timed out`));
|
|
85
|
+
}, runtime.timeoutMs ?? 3e4) : void 0;
|
|
86
|
+
pending.set(id, { resolve: (value) => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
resolve(value);
|
|
89
|
+
}, reject: (error) => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
reject(error);
|
|
92
|
+
} });
|
|
93
|
+
write({ jsonrpc: "2.0", id, method, params });
|
|
94
|
+
});
|
|
95
|
+
const lines = createInterface({ input: child.stdout });
|
|
96
|
+
lines.on("line", (line) => {
|
|
97
|
+
let frame;
|
|
98
|
+
try {
|
|
99
|
+
frame = JSON.parse(line);
|
|
100
|
+
} catch {
|
|
101
|
+
return fail(new Error("Malformed DSH SDK frame"));
|
|
102
|
+
}
|
|
103
|
+
if (frame.method && frame.id !== void 0) {
|
|
104
|
+
if (frame.method !== "approval/request") return write({ jsonrpc: "2.0", id: frame.id, error: { code: -32601, message: "Unsupported runtime request" } });
|
|
105
|
+
const task = (frame.params?.sessionId === record.runtimeSessionId ? requestApproval(runtime.workbench, options.execution, record.sessionId, frame.params, signal) : Promise.resolve({ outcome: "cancelled" })).then((result) => {
|
|
106
|
+
if (!signal.aborted) write({ jsonrpc: "2.0", id: frame.id, result });
|
|
107
|
+
});
|
|
108
|
+
approvalTasks.add(task);
|
|
109
|
+
void task.finally(() => approvalTasks.delete(task));
|
|
110
|
+
} else if (frame.method === "session.event" && frame.params?.sessionId === record.runtimeSessionId) {
|
|
111
|
+
const event = frame.params.event;
|
|
112
|
+
if (event?.type === "turn/end") terminal = event.data?.reason;
|
|
113
|
+
if (event?.type === "assistant/message") {
|
|
114
|
+
const content = event.data?.message?.content;
|
|
115
|
+
if (Array.isArray(content)) text = content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
116
|
+
}
|
|
117
|
+
} else if (frame.id !== void 0) {
|
|
118
|
+
const task = pending.get(frame.id);
|
|
119
|
+
if (!task) return;
|
|
120
|
+
pending.delete(frame.id);
|
|
121
|
+
if (frame.error) task.reject(new Error("DSH SDK request failed"));
|
|
122
|
+
else task.resolve(frame.result);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
const abort = () => {
|
|
126
|
+
fail(options.signal.reason);
|
|
127
|
+
child.kill("SIGTERM");
|
|
128
|
+
};
|
|
129
|
+
options.signal.addEventListener("abort", abort, { once: true });
|
|
130
|
+
const force = setInterval(() => {
|
|
131
|
+
if (signal.aborted) child.kill("SIGKILL");
|
|
132
|
+
}, 1e3);
|
|
133
|
+
try {
|
|
134
|
+
options.signal.throwIfAborted();
|
|
135
|
+
const initialized = await request("initialize", { cwd: record.cwd, provider: runtime.provider, model: runtime.model, approvalRequests: true });
|
|
136
|
+
if (initialized?.serverInfo?.name !== "deepseek-harness-sdk-runtime") throw new Error("Unexpected DSH runtime");
|
|
137
|
+
if (record.runtimeSessionId) await request("session/resume", { sessionId: record.runtimeSessionId });
|
|
138
|
+
else {
|
|
139
|
+
record.runtimeSessionId = `session-${randomUUID2()}`;
|
|
140
|
+
await save(record);
|
|
141
|
+
}
|
|
142
|
+
if (runtime.permissionMode) await request("session/query", { sessionId: record.runtimeSessionId, contentBlocks: [{ type: "text", text: `/permission ${runtime.permissionMode}` }] });
|
|
143
|
+
terminal = void 0;
|
|
144
|
+
text = "";
|
|
145
|
+
await request("session/prompt", { sessionId: record.runtimeSessionId, contentBlocks: [{ type: "text", text: prompt }] });
|
|
146
|
+
await request("session/wait", { sessionId: record.runtimeSessionId });
|
|
147
|
+
record.uncertain = !terminal;
|
|
148
|
+
await save(record);
|
|
149
|
+
await request("shutdown", {});
|
|
150
|
+
const code = await exited;
|
|
151
|
+
return { outcome: code === 0 && terminal?.kind === "completed" ? "completed" : "failed", text };
|
|
152
|
+
} finally {
|
|
153
|
+
controller.abort();
|
|
154
|
+
child.kill("SIGTERM");
|
|
155
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), 1e3);
|
|
156
|
+
await exited;
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
clearInterval(force);
|
|
159
|
+
options.signal.removeEventListener("abort", abort);
|
|
160
|
+
lines.close();
|
|
161
|
+
await Promise.allSettled(approvalTasks);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
runSdk
|
|
166
|
+
};
|