@1agents/dsh-a2a 0.1.0 → 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 +1 -1
- package/dist/approvals.js +1 -0
- package/dist/cli.js +32586 -5
- package/dist/executor.js +24817 -42
- package/dist/index.js +32584 -7
- package/dist/sdk-runtime.js +52 -2
- package/dist/server.js +32552 -17
- package/dist/shared/a2a/workbench-ui.js +6 -2
- package/dist/workbench.js +171 -2
- package/package.json +11 -3
package/dist/sdk-runtime.js
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
|
+
// src/sdk-runtime.js
|
|
1
2
|
import { spawn } from "node:child_process";
|
|
2
3
|
import { createInterface } from "node:readline";
|
|
4
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
// src/approvals.js
|
|
3
7
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import {
|
|
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
|
|
5
55
|
async function runSdk(runtime, record, prompt, options, save) {
|
|
6
56
|
if (!runtime.provider || !runtime.model) throw new Error("SDK runtime requires provider and model configuration");
|
|
7
57
|
const child = spawn(runtime.command, runtime.args, { cwd: record.cwd, env: { ...process.env, ...runtime.env }, stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -86,7 +136,7 @@ async function runSdk(runtime, record, prompt, options, save) {
|
|
|
86
136
|
if (initialized?.serverInfo?.name !== "deepseek-harness-sdk-runtime") throw new Error("Unexpected DSH runtime");
|
|
87
137
|
if (record.runtimeSessionId) await request("session/resume", { sessionId: record.runtimeSessionId });
|
|
88
138
|
else {
|
|
89
|
-
record.runtimeSessionId = `session-${
|
|
139
|
+
record.runtimeSessionId = `session-${randomUUID2()}`;
|
|
90
140
|
await save(record);
|
|
91
141
|
}
|
|
92
142
|
if (runtime.permissionMode) await request("session/query", { sessionId: record.runtimeSessionId, contentBlocks: [{ type: "text", text: `/permission ${runtime.permissionMode}` }] });
|