@mininglamp-oss/octo-runtime 1.1.2 → 1.1.4
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/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/help.js +5 -1
- package/apps/cli/dist/main.js +32 -6
- package/apps/cli/dist/manifest.json +5 -0
- package/apps/cli/dist/openclaw.js +32 -8
- package/apps/cli/dist/output.js +3 -0
- package/apps/cli/dist/playboard.d.ts +5 -0
- package/apps/cli/dist/playboard.js +41 -13
- package/dist/public/dsh.d.ts +2 -0
- package/dist/public/dsh.js +1 -0
- package/dist/public/executor-kernel.d.ts +1 -1
- package/dist/public/executor-kernel.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +32 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +181 -27
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +167 -25
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +20 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +49 -17
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +10 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +35 -29
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
- package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-sdk-client@0.2.1-rc.3_516a7f74d7ed21fb3cb8eaabc4dfc7e7/node_modules/@deepseek-ai/dsh-sdk-client/lib/index.js
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-sdk-protocol@0.2.1-rc.3_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-llm_e931ccc464b293b33bd51dc55601f7a2/node_modules/@deepseek-ai/dsh-sdk-protocol/lib/index.js
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { StringDecoder } from "node:string_decoder";
|
|
8
|
+
var JsonRpcResponseError = class extends Error {
|
|
9
|
+
code;
|
|
10
|
+
data;
|
|
11
|
+
/**
|
|
12
|
+
* @param code - the wire error code, or `undefined` when the peer sent none.
|
|
13
|
+
* @param message - the wire error message.
|
|
14
|
+
* @param data - the optional structured error payload, verbatim.
|
|
15
|
+
*/
|
|
16
|
+
constructor(code, message, data) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.data = data;
|
|
20
|
+
this.name = "JsonRpcResponseError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var JsonRpcLineTransport = class {
|
|
24
|
+
input;
|
|
25
|
+
output;
|
|
26
|
+
buffer = "";
|
|
27
|
+
decoder = new StringDecoder("utf8");
|
|
28
|
+
started = false;
|
|
29
|
+
requestHandler;
|
|
30
|
+
notificationHandler;
|
|
31
|
+
pending = /* @__PURE__ */ new Map();
|
|
32
|
+
constructor(input, output) {
|
|
33
|
+
this.input = input;
|
|
34
|
+
this.output = output;
|
|
35
|
+
}
|
|
36
|
+
/** Attach the input listeners and begin reading frames. Idempotent. */
|
|
37
|
+
start() {
|
|
38
|
+
if (this.started) return;
|
|
39
|
+
this.started = true;
|
|
40
|
+
this.input.on("data", this.onData);
|
|
41
|
+
this.input.on("error", this.onInputError);
|
|
42
|
+
this.input.on("end", this.onInputEnd);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Detach listeners and reject pending requests. Safe before {@link start}.
|
|
46
|
+
*/
|
|
47
|
+
close() {
|
|
48
|
+
this.input.off("data", this.onData);
|
|
49
|
+
this.input.off("error", this.onInputError);
|
|
50
|
+
this.input.off("end", this.onInputEnd);
|
|
51
|
+
this.failPending(/* @__PURE__ */ new Error("JSON-RPC transport closed"));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Install the request handler, replacing any prior handler.
|
|
55
|
+
* @param handler - resolves to the response `result`; a rejection becomes a
|
|
56
|
+
* `-32603` error response carrying the message.
|
|
57
|
+
*/
|
|
58
|
+
onRequest(handler) {
|
|
59
|
+
this.requestHandler = handler;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Install the notification handler, replacing any prior handler.
|
|
63
|
+
* @param handler - invoked per notification with the method and normalized
|
|
64
|
+
* params object.
|
|
65
|
+
*/
|
|
66
|
+
onNotification(handler) {
|
|
67
|
+
this.notificationHandler = handler;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send a request and await its response.
|
|
71
|
+
* @param method - the JSON-RPC method name.
|
|
72
|
+
* @param params - the request parameters object.
|
|
73
|
+
* @param signal - optional abandonment signal: aborting removes the pending
|
|
74
|
+
* entry (no state is retained for a response that may never come) and
|
|
75
|
+
* rejects with the signal's reason.
|
|
76
|
+
* @returns the result; rejects per {@link JsonRpcTransportPeer.request}.
|
|
77
|
+
*/
|
|
78
|
+
request(method, params, signal) {
|
|
79
|
+
const id = `req_${randomUUID().replaceAll("-", "")}`;
|
|
80
|
+
const message = {
|
|
81
|
+
jsonrpc: "2.0",
|
|
82
|
+
id,
|
|
83
|
+
method,
|
|
84
|
+
params
|
|
85
|
+
};
|
|
86
|
+
return new Promise((resolve2, reject) => {
|
|
87
|
+
let detach = () => {
|
|
88
|
+
};
|
|
89
|
+
if (signal !== void 0) {
|
|
90
|
+
if (signal.aborted) {
|
|
91
|
+
reject(abortError(signal.reason));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const onAbort = () => {
|
|
95
|
+
this.pending.delete(id);
|
|
96
|
+
reject(abortError(signal.reason));
|
|
97
|
+
};
|
|
98
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
99
|
+
detach = () => {
|
|
100
|
+
signal.removeEventListener("abort", onAbort);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
this.pending.set(id, {
|
|
104
|
+
resolve: (value) => {
|
|
105
|
+
detach();
|
|
106
|
+
resolve2(value);
|
|
107
|
+
},
|
|
108
|
+
reject: (error) => {
|
|
109
|
+
detach();
|
|
110
|
+
reject(error);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
try {
|
|
114
|
+
this.write(message);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
this.pending.delete(id);
|
|
117
|
+
detach();
|
|
118
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
notify(method, params) {
|
|
123
|
+
this.write(params === void 0 ? {
|
|
124
|
+
jsonrpc: "2.0",
|
|
125
|
+
method
|
|
126
|
+
} : {
|
|
127
|
+
jsonrpc: "2.0",
|
|
128
|
+
method,
|
|
129
|
+
params
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Wait for prior frame write callbacks. The empty barrier emits no bytes.
|
|
134
|
+
* @returns a promise that settles with the output write callback.
|
|
135
|
+
*/
|
|
136
|
+
flush() {
|
|
137
|
+
return new Promise((resolve2, reject) => {
|
|
138
|
+
this.output.write("", (error) => {
|
|
139
|
+
if (error) reject(error);
|
|
140
|
+
else resolve2();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
onData = (chunk) => {
|
|
145
|
+
this.buffer += typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
146
|
+
this.drainLines();
|
|
147
|
+
};
|
|
148
|
+
drainLines() {
|
|
149
|
+
for (; ; ) {
|
|
150
|
+
const newline = this.buffer.indexOf("\n");
|
|
151
|
+
if (newline < 0) break;
|
|
152
|
+
const line = this.buffer.slice(0, newline).trim();
|
|
153
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
154
|
+
if (!line) continue;
|
|
155
|
+
this.handleLine(line);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
onInputError = (error) => {
|
|
159
|
+
this.failPending(error);
|
|
160
|
+
};
|
|
161
|
+
onInputEnd = () => {
|
|
162
|
+
this.buffer += this.decoder.end();
|
|
163
|
+
this.drainLines();
|
|
164
|
+
this.failPending(/* @__PURE__ */ new Error("JSON-RPC input closed"));
|
|
165
|
+
};
|
|
166
|
+
async handleLine(line) {
|
|
167
|
+
let message;
|
|
168
|
+
try {
|
|
169
|
+
message = JSON.parse(line);
|
|
170
|
+
} catch {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!message || typeof message !== "object") return;
|
|
174
|
+
const frame = message;
|
|
175
|
+
const id = frame.id;
|
|
176
|
+
const method = frame.method;
|
|
177
|
+
if ((typeof id === "string" || typeof id === "number") && typeof method === "string") {
|
|
178
|
+
await this.handleIncomingRequest(id, method, objectParams(frame.params));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (typeof id === "string" || typeof id === "number") {
|
|
182
|
+
this.handleIncomingResponse(id, frame);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (typeof method === "string") this.notificationHandler?.(method, objectParams(frame.params));
|
|
186
|
+
}
|
|
187
|
+
async handleIncomingRequest(id, method, params) {
|
|
188
|
+
const handler = this.requestHandler;
|
|
189
|
+
if (!handler) {
|
|
190
|
+
this.writeError(id, -32601, `method not found: ${method}`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const result = await handler(method, params);
|
|
195
|
+
this.write({
|
|
196
|
+
jsonrpc: "2.0",
|
|
197
|
+
id,
|
|
198
|
+
result
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
this.writeError(id, -32603, error instanceof Error ? error.message : String(error));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
handleIncomingResponse(id, frame) {
|
|
205
|
+
const pending = this.pending.get(id);
|
|
206
|
+
if (!pending) return;
|
|
207
|
+
this.pending.delete(id);
|
|
208
|
+
if (frame.error && typeof frame.error === "object") {
|
|
209
|
+
const error = frame.error;
|
|
210
|
+
pending.reject(new JsonRpcResponseError(typeof error.code === "number" ? error.code : void 0, typeof error.message === "string" ? error.message : "JSON-RPC error", error.data));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
pending.resolve(frame.result);
|
|
214
|
+
}
|
|
215
|
+
writeError(id, code, message) {
|
|
216
|
+
this.write({
|
|
217
|
+
jsonrpc: "2.0",
|
|
218
|
+
id,
|
|
219
|
+
error: {
|
|
220
|
+
code,
|
|
221
|
+
message
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
write(message) {
|
|
226
|
+
this.output.write(`${JSON.stringify(message)}
|
|
227
|
+
`);
|
|
228
|
+
}
|
|
229
|
+
failPending(error) {
|
|
230
|
+
const pending = [...this.pending.values()];
|
|
231
|
+
this.pending.clear();
|
|
232
|
+
for (const waiter of pending) waiter.reject(error);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
function objectParams(params) {
|
|
236
|
+
return params && typeof params === "object" && !Array.isArray(params) ? params : {};
|
|
237
|
+
}
|
|
238
|
+
function abortError(reason) {
|
|
239
|
+
return reason instanceof Error ? reason : /* @__PURE__ */ new Error(`JSON-RPC request aborted: ${String(reason)}`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-sdk-client@0.2.1-rc.3_516a7f74d7ed21fb3cb8eaabc4dfc7e7/node_modules/@deepseek-ai/dsh-sdk-client/lib/index.js
|
|
243
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
244
|
+
import { fileURLToPath } from "node:url";
|
|
245
|
+
function exitsWithin(child, ms) {
|
|
246
|
+
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
|
|
247
|
+
return new Promise((resolve2) => {
|
|
248
|
+
const onExit = () => {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
resolve2(true);
|
|
251
|
+
};
|
|
252
|
+
const timer = setTimeout(() => {
|
|
253
|
+
child.removeListener("exit", onExit);
|
|
254
|
+
resolve2(false);
|
|
255
|
+
}, ms).unref();
|
|
256
|
+
child.once("exit", onExit);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function forceTerminateWithin(child, ms) {
|
|
260
|
+
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve();
|
|
261
|
+
return new Promise((resolve2, reject) => {
|
|
262
|
+
let accepted = false;
|
|
263
|
+
let settled = false;
|
|
264
|
+
const cleanup = () => {
|
|
265
|
+
clearTimeout(timer);
|
|
266
|
+
child.off("exit", onExit);
|
|
267
|
+
child.off("error", onError);
|
|
268
|
+
};
|
|
269
|
+
const settle = (complete) => {
|
|
270
|
+
if (settled) return;
|
|
271
|
+
settled = true;
|
|
272
|
+
cleanup();
|
|
273
|
+
complete();
|
|
274
|
+
};
|
|
275
|
+
const onExit = () => {
|
|
276
|
+
settle(resolve2);
|
|
277
|
+
};
|
|
278
|
+
const onError = (error) => {
|
|
279
|
+
settle(() => {
|
|
280
|
+
reject(error);
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
child.once("exit", onExit);
|
|
284
|
+
child.once("error", onError);
|
|
285
|
+
const timer = setTimeout(() => {
|
|
286
|
+
const disposition = accepted ? "accepted" : "refused";
|
|
287
|
+
settle(() => {
|
|
288
|
+
reject(/* @__PURE__ */ new Error(`runtime process did not exit within ${ms}ms after SIGKILL was ${disposition}`));
|
|
289
|
+
});
|
|
290
|
+
}, ms).unref();
|
|
291
|
+
try {
|
|
292
|
+
accepted = child.kill("SIGKILL");
|
|
293
|
+
if (child.exitCode !== null || child.signalCode !== null) settle(resolve2);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
settle(() => {
|
|
296
|
+
reject(new Error("SIGKILL failed", { cause: error }));
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async function disposeRuntimeProcess(child, graces, platform = process.platform) {
|
|
302
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
303
|
+
child.stdin?.end();
|
|
304
|
+
if (await exitsWithin(child, graces.disposeEofGraceMs)) return;
|
|
305
|
+
if (platform !== "win32") {
|
|
306
|
+
child.kill("SIGTERM");
|
|
307
|
+
if (await exitsWithin(child, graces.disposeGraceMs)) return;
|
|
308
|
+
}
|
|
309
|
+
await forceTerminateWithin(child, graces.disposeGraceMs);
|
|
310
|
+
}
|
|
311
|
+
function manifest(url) {
|
|
312
|
+
return JSON.parse(readFileSync(fileURLToPath(url), "utf8"));
|
|
313
|
+
}
|
|
314
|
+
function resolveDshBinFromManifests(dshManifestUrl, clientManifestUrl) {
|
|
315
|
+
const dshManifest = manifest(dshManifestUrl);
|
|
316
|
+
const clientManifest = manifest(clientManifestUrl);
|
|
317
|
+
if (typeof dshManifest.version !== "string" || dshManifest.version !== clientManifest.version) throw new Error(`dsh SDK client ${String(clientManifest.version)} requires the same dsh version, got ${String(dshManifest.version)}`);
|
|
318
|
+
const bin = typeof dshManifest.bin === "object" && dshManifest.bin !== null ? dshManifest.bin.dsh : dshManifest.bin;
|
|
319
|
+
if (typeof bin !== "string" || bin === "") throw new Error("@deepseek-ai/dsh declares no dsh executable");
|
|
320
|
+
return resolve(dirname(fileURLToPath(dshManifestUrl)), bin);
|
|
321
|
+
}
|
|
322
|
+
function resolveDshNodeLaunchFromManifests(dshManifestUrl, clientManifestUrl, sourceLoaderUrl) {
|
|
323
|
+
const bin = resolveDshBinFromManifests(dshManifestUrl, clientManifestUrl);
|
|
324
|
+
if (existsSync(bin)) return {
|
|
325
|
+
nodeArgs: [bin],
|
|
326
|
+
patches: [],
|
|
327
|
+
environment: {}
|
|
328
|
+
};
|
|
329
|
+
const packageDir = dirname(fileURLToPath(dshManifestUrl));
|
|
330
|
+
const sourceBin = resolve(packageDir, "src/bin.ts");
|
|
331
|
+
const sourcePatch = resolve(packageDir, "src/sdk-source.cordis.patch.yml");
|
|
332
|
+
const sourceTsconfig = resolve(packageDir, "tsconfig.json");
|
|
333
|
+
if (!existsSync(sourceBin) || !existsSync(sourcePatch) || !existsSync(sourceTsconfig)) throw new Error(`@deepseek-ai/dsh is missing its built executable ${bin} and complete source launch files ${sourceBin}, ${sourcePatch}, ${sourceTsconfig}`);
|
|
334
|
+
return {
|
|
335
|
+
nodeArgs: [
|
|
336
|
+
"--import",
|
|
337
|
+
sourceLoaderUrl ?? import.meta.resolve("tsx/esm"),
|
|
338
|
+
sourceBin
|
|
339
|
+
],
|
|
340
|
+
patches: [sourcePatch],
|
|
341
|
+
environment: { TSX_TSCONFIG_PATH: sourceTsconfig }
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function installedDshNodeLaunch() {
|
|
345
|
+
return resolveDshNodeLaunchFromManifests(import.meta.resolve("@deepseek-ai/dsh/package.json"), new URL("../package.json", import.meta.url).href);
|
|
346
|
+
}
|
|
347
|
+
function resolveDshLaunch(options = {}, callerCwd = process.cwd()) {
|
|
348
|
+
const profile = options.profile ?? "sdk";
|
|
349
|
+
const dshLaunch = options.dshBin === void 0 ? installedDshNodeLaunch() : {
|
|
350
|
+
nodeArgs: [resolve(callerCwd, options.dshBin)],
|
|
351
|
+
patches: [],
|
|
352
|
+
environment: {}
|
|
353
|
+
};
|
|
354
|
+
const patches = [...dshLaunch.patches, ...(options.patches ?? []).map((path) => resolve(callerCwd, path))];
|
|
355
|
+
const dshHome = options.dshHome === void 0 ? void 0 : resolve(callerCwd, options.dshHome);
|
|
356
|
+
return {
|
|
357
|
+
command: process.execPath,
|
|
358
|
+
args: [
|
|
359
|
+
...dshLaunch.nodeArgs,
|
|
360
|
+
"--profile",
|
|
361
|
+
profile,
|
|
362
|
+
...patches.flatMap((path) => ["--patch", path])
|
|
363
|
+
],
|
|
364
|
+
...options.processCwd === void 0 ? {} : { cwd: resolve(callerCwd, options.processCwd) },
|
|
365
|
+
environment: () => ({
|
|
366
|
+
...options.env ?? process.env,
|
|
367
|
+
...dshLaunch.environment,
|
|
368
|
+
...dshHome === void 0 ? {} : { DSH_HOME: dshHome }
|
|
369
|
+
}),
|
|
370
|
+
description: `dsh profile ${JSON.stringify(profile)}`,
|
|
371
|
+
initializeTimeoutMs: options.initializeTimeoutMs ?? 1e4,
|
|
372
|
+
...options.requestTimeoutMs === void 0 ? {} : { requestTimeoutMs: options.requestTimeoutMs },
|
|
373
|
+
...options.shutdownTimeoutMs === void 0 ? {} : { shutdownTimeoutMs: options.shutdownTimeoutMs },
|
|
374
|
+
...options.disposeEofGraceMs === void 0 ? {} : { disposeEofGraceMs: options.disposeEofGraceMs },
|
|
375
|
+
...options.disposeGraceMs === void 0 ? {} : { disposeGraceMs: options.disposeGraceMs }
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
var STDERR_TAIL_LIMIT = 400;
|
|
379
|
+
var STREAM_SETTLE_MS = 100;
|
|
380
|
+
var TransportClosedError = class extends Error {
|
|
381
|
+
/** @param message - the failure description, including any stderr tail. */
|
|
382
|
+
constructor(message) {
|
|
383
|
+
super(message);
|
|
384
|
+
this.name = "TransportClosedError";
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
var RequestTimeoutError = class extends Error {
|
|
388
|
+
/** @param message - which method timed out. */
|
|
389
|
+
constructor(message) {
|
|
390
|
+
super(message);
|
|
391
|
+
this.name = "RequestTimeoutError";
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var SdkProtocolError = class extends Error {
|
|
395
|
+
/** @param message - the protocol violation description. */
|
|
396
|
+
constructor(message) {
|
|
397
|
+
super(message);
|
|
398
|
+
this.name = "SdkProtocolError";
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var NotificationSubscriptionImpl = class {
|
|
402
|
+
state;
|
|
403
|
+
unsubscribe;
|
|
404
|
+
constructor(state, unsubscribe) {
|
|
405
|
+
this.state = state;
|
|
406
|
+
this.unsubscribe = unsubscribe;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Await the next matching notification.
|
|
410
|
+
* @returns the notification; after the runtime died, drains what was
|
|
411
|
+
* already delivered and then rejects; after {@link close}, rejects
|
|
412
|
+
* immediately (the queue is dropped).
|
|
413
|
+
*/
|
|
414
|
+
next() {
|
|
415
|
+
const queued = this.state.queue.shift();
|
|
416
|
+
if (queued !== void 0) return Promise.resolve(queued);
|
|
417
|
+
if (this.state.failure !== void 0) return Promise.reject(this.state.failure);
|
|
418
|
+
return new Promise((resolve2, reject) => {
|
|
419
|
+
this.state.waiters.push({
|
|
420
|
+
resolve: resolve2,
|
|
421
|
+
reject
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Drain one already-delivered notification without waiting.
|
|
427
|
+
* @returns the next queued notification, or `undefined` when none is queued.
|
|
428
|
+
*/
|
|
429
|
+
tryNext() {
|
|
430
|
+
return this.state.queue.shift();
|
|
431
|
+
}
|
|
432
|
+
/** Detach from the client; queued items drop and pending waiters reject. */
|
|
433
|
+
close() {
|
|
434
|
+
this.unsubscribe();
|
|
435
|
+
this.state.queue.length = 0;
|
|
436
|
+
this.fail(new TransportClosedError("notification subscription closed"));
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Reject pending and future waits (delivery stops; the first failure wins).
|
|
440
|
+
* Already-queued notifications remain drainable via {@link next}/{@link tryNext}.
|
|
441
|
+
* @param error - the terminal failure delivered to waiters.
|
|
442
|
+
*/
|
|
443
|
+
fail(error) {
|
|
444
|
+
this.state.failure ??= error;
|
|
445
|
+
for (const waiter of this.state.waiters.splice(0)) waiter.reject(this.state.failure);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Deliver one notification to a waiter or the queue when the filter
|
|
449
|
+
* matches. A throwing filter fails only THIS subscription (detached, the
|
|
450
|
+
* throw becomes its terminal error) — it never disturbs sibling
|
|
451
|
+
* subscriptions or the transport's read loop.
|
|
452
|
+
* @param notification - the wire notification to deliver.
|
|
453
|
+
*/
|
|
454
|
+
push(notification) {
|
|
455
|
+
let matches;
|
|
456
|
+
try {
|
|
457
|
+
matches = this.state.filter === void 0 || this.state.filter(notification);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
this.unsubscribe();
|
|
460
|
+
this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (!matches) return;
|
|
464
|
+
const waiter = this.state.waiters.shift();
|
|
465
|
+
if (waiter !== void 0) waiter.resolve(notification);
|
|
466
|
+
else this.state.queue.push(notification);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Iterate notifications until the subscription or runtime closes (the
|
|
470
|
+
* terminating rejection propagates).
|
|
471
|
+
* @returns an async iterator over {@link next} results.
|
|
472
|
+
*/
|
|
473
|
+
async *[Symbol.asyncIterator]() {
|
|
474
|
+
for (; ; ) yield await this.next();
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var HarnessClient = class {
|
|
478
|
+
/** Original public dsh launch and timeout options for this client. */
|
|
479
|
+
options;
|
|
480
|
+
runtime;
|
|
481
|
+
child;
|
|
482
|
+
transport;
|
|
483
|
+
stderrTail = [];
|
|
484
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
485
|
+
sessionParents = /* @__PURE__ */ new Map();
|
|
486
|
+
subscriptionSerial = 0;
|
|
487
|
+
exitCode;
|
|
488
|
+
spawnError;
|
|
489
|
+
streamsSettled = Promise.resolve();
|
|
490
|
+
closeTask;
|
|
491
|
+
constructor(options = {}, runtime) {
|
|
492
|
+
this.options = options;
|
|
493
|
+
this.runtime = runtime ?? resolveDshLaunch(options);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Spawn the runtime subprocess and start reading frames. Idempotent while
|
|
497
|
+
* the process is live; rejects reuse after {@link close}.
|
|
498
|
+
*/
|
|
499
|
+
start() {
|
|
500
|
+
if (this.closeTask !== void 0) throw new TransportClosedError("DeepSeek Harness runtime client is closed");
|
|
501
|
+
if (this.child !== void 0) return;
|
|
502
|
+
const child = spawn(this.runtime.command, this.runtime.args, {
|
|
503
|
+
cwd: this.runtime.cwd,
|
|
504
|
+
env: this.runtime.environment(),
|
|
505
|
+
stdio: [
|
|
506
|
+
"pipe",
|
|
507
|
+
"pipe",
|
|
508
|
+
"pipe"
|
|
509
|
+
]
|
|
510
|
+
});
|
|
511
|
+
this.child = child;
|
|
512
|
+
child.once("error", (error) => {
|
|
513
|
+
this.spawnError = error;
|
|
514
|
+
this.transport?.close();
|
|
515
|
+
this.failSubscriptions(this.closedError("DeepSeek Harness runtime failed to start"));
|
|
516
|
+
});
|
|
517
|
+
child.stdin.on("error", () => {
|
|
518
|
+
});
|
|
519
|
+
let stderrBuffer = "";
|
|
520
|
+
child.stderr.setEncoding("utf8");
|
|
521
|
+
child.stderr.on("data", (chunk) => {
|
|
522
|
+
stderrBuffer += chunk;
|
|
523
|
+
const newline = stderrBuffer.lastIndexOf("\n");
|
|
524
|
+
if (newline >= 0) {
|
|
525
|
+
this.appendStderr(stderrBuffer.slice(0, newline).split("\n"));
|
|
526
|
+
stderrBuffer = stderrBuffer.slice(newline + 1);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
let signalStreamsSettled;
|
|
530
|
+
this.streamsSettled = new Promise((resolve2) => {
|
|
531
|
+
signalStreamsSettled = resolve2;
|
|
532
|
+
});
|
|
533
|
+
const settled = {
|
|
534
|
+
stderr: false,
|
|
535
|
+
exited: false
|
|
536
|
+
};
|
|
537
|
+
const maybeSettle = () => {
|
|
538
|
+
if (settled.stderr && settled.exited) signalStreamsSettled();
|
|
539
|
+
};
|
|
540
|
+
child.stderr.once("close", () => {
|
|
541
|
+
if (stderrBuffer.length > 0) this.appendStderr([stderrBuffer]);
|
|
542
|
+
settled.stderr = true;
|
|
543
|
+
maybeSettle();
|
|
544
|
+
});
|
|
545
|
+
child.once("exit", (code) => {
|
|
546
|
+
this.exitCode = code;
|
|
547
|
+
settled.exited = true;
|
|
548
|
+
maybeSettle();
|
|
549
|
+
this.failSubscriptions(this.closedError("DeepSeek Harness runtime exited"));
|
|
550
|
+
});
|
|
551
|
+
child.once("close", () => {
|
|
552
|
+
this.transport?.close();
|
|
553
|
+
});
|
|
554
|
+
const transport = new JsonRpcLineTransport(child.stdout, child.stdin);
|
|
555
|
+
transport.onNotification((method, params) => {
|
|
556
|
+
this.dispatchNotification({
|
|
557
|
+
method,
|
|
558
|
+
params
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
transport.start();
|
|
562
|
+
this.transport = transport;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Perform the process-wide handshake.
|
|
566
|
+
* @param params - workspace cwd plus the provider/model route.
|
|
567
|
+
* @returns the runtime's wire identity.
|
|
568
|
+
*/
|
|
569
|
+
async initialize(params) {
|
|
570
|
+
const result = await this.request("initialize", { ...params }, this.runtime.initializeTimeoutMs);
|
|
571
|
+
if (!isRecord(result) || !isRecord(result.serverInfo) || typeof result.serverInfo.name !== "string" || typeof result.serverInfo.version !== "string") throw new SdkProtocolError(`initialize returned no server identity: ${JSON.stringify(result)}`);
|
|
572
|
+
return { serverInfo: {
|
|
573
|
+
name: result.serverInfo.name,
|
|
574
|
+
version: result.serverInfo.version
|
|
575
|
+
} };
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Queue one prompt and return its durable inbox identity.
|
|
579
|
+
* @param sessionId - target session; an unknown id creates it.
|
|
580
|
+
* @param contentBlocks - the user message, sent verbatim.
|
|
581
|
+
* @returns the queued message id.
|
|
582
|
+
*/
|
|
583
|
+
async prompt(sessionId, contentBlocks) {
|
|
584
|
+
const params = {
|
|
585
|
+
sessionId,
|
|
586
|
+
contentBlocks
|
|
587
|
+
};
|
|
588
|
+
const result = await this.request("session/prompt", { ...params });
|
|
589
|
+
if (!isRecord(result) || typeof result.messageId !== "string") throw new SdkProtocolError(`session/prompt returned no message id: ${JSON.stringify(result)}`);
|
|
590
|
+
return result.messageId;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Restore persisted history without sending a prompt; failures propagate without creating a session.
|
|
594
|
+
* @param sessionId - persisted identity in this runtime's configured persistence store.
|
|
595
|
+
* @returns after the session is ready for prompts.
|
|
596
|
+
*/
|
|
597
|
+
async resumeSession(sessionId) {
|
|
598
|
+
await this.request("session/resume", { sessionId });
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Read a Session's effective working directory, recovering it if missing.
|
|
602
|
+
* @param sessionId - target Session; an unknown id creates it.
|
|
603
|
+
* @returns the absolute effective directory.
|
|
604
|
+
*/
|
|
605
|
+
getWorkingDirectory(sessionId) {
|
|
606
|
+
return this.workingDirectoryRequest("session/working-directory/get", { sessionId });
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Change a Session's effective directory without changing origin or permissions.
|
|
610
|
+
* @param sessionId - target Session; an unknown id creates it.
|
|
611
|
+
* @param path - absolute or Session-current-directory-relative path.
|
|
612
|
+
* @returns the validated absolute directory.
|
|
613
|
+
*/
|
|
614
|
+
setWorkingDirectory(sessionId, path) {
|
|
615
|
+
return this.workingDirectoryRequest("session/working-directory/set", {
|
|
616
|
+
sessionId,
|
|
617
|
+
path
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
async workingDirectoryRequest(method, params) {
|
|
621
|
+
const result = await this.request(method, params);
|
|
622
|
+
if (!isRecord(result) || typeof result.cwd !== "string") throw new SdkProtocolError(`${method} returned no working directory: ${JSON.stringify(result)}`);
|
|
623
|
+
return result.cwd;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Send one JSON-RPC request and await its result.
|
|
627
|
+
* @param method - the wire method name.
|
|
628
|
+
* @param params - the params object; omitted params send `{}`.
|
|
629
|
+
* @param timeoutMs - per-call override of {@link HarnessClientOptions.requestTimeoutMs}.
|
|
630
|
+
* @returns the raw result; rejects with {@link JsonRpcResponseError} on a
|
|
631
|
+
* protocol error response, {@link RequestTimeoutError} on timeout, and
|
|
632
|
+
* {@link TransportClosedError} when the runtime is gone.
|
|
633
|
+
*/
|
|
634
|
+
async request(method, params, timeoutMs) {
|
|
635
|
+
this.start();
|
|
636
|
+
if (this.exitCode !== void 0 || this.spawnError !== void 0) {
|
|
637
|
+
await this.settleStreams();
|
|
638
|
+
throw this.closedError("DeepSeek Harness runtime is not running");
|
|
639
|
+
}
|
|
640
|
+
const transport = this.transport;
|
|
641
|
+
if (transport === void 0) throw new TransportClosedError("DeepSeek Harness runtime is not running");
|
|
642
|
+
const timeout = timeoutMs ?? this.runtime.requestTimeoutMs;
|
|
643
|
+
try {
|
|
644
|
+
if (timeout === void 0) return await transport.request(method, params ?? {});
|
|
645
|
+
const abandon = new AbortController();
|
|
646
|
+
const timer = setTimeout(() => {
|
|
647
|
+
const stderr = this.stderrTail.length === 0 ? "" : `; stderr tail:
|
|
648
|
+
${this.stderrTail.join("\n")}`;
|
|
649
|
+
abandon.abort(new RequestTimeoutError(`${method} timed out after ${timeout}ms waiting for ${this.runtime.description}${stderr}`));
|
|
650
|
+
}, timeout);
|
|
651
|
+
try {
|
|
652
|
+
return await transport.request(method, params ?? {}, abandon.signal);
|
|
653
|
+
} finally {
|
|
654
|
+
clearTimeout(timer);
|
|
655
|
+
}
|
|
656
|
+
} catch (error) {
|
|
657
|
+
if (error instanceof JsonRpcResponseError || error instanceof RequestTimeoutError) throw error;
|
|
658
|
+
await this.settleStreams();
|
|
659
|
+
throw this.closedError(errorMessage(error));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Subscribe to server notifications.
|
|
664
|
+
* @param filter - optional predicate; omitted means every notification.
|
|
665
|
+
* @returns the subscription handle; close it to stop delivery. After
|
|
666
|
+
* {@link close} or runtime death the handle is born failed — there is no
|
|
667
|
+
* producer left, so `next()` rejects instead of waiting forever.
|
|
668
|
+
*/
|
|
669
|
+
subscribe(filter) {
|
|
670
|
+
const id = String(this.subscriptionSerial++);
|
|
671
|
+
const subscription = new NotificationSubscriptionImpl({
|
|
672
|
+
queue: [],
|
|
673
|
+
waiters: [],
|
|
674
|
+
filter,
|
|
675
|
+
failure: void 0
|
|
676
|
+
}, () => {
|
|
677
|
+
this.subscriptions.delete(id);
|
|
678
|
+
});
|
|
679
|
+
if (this.closeTask !== void 0 || this.exitCode !== void 0 || this.spawnError !== void 0) {
|
|
680
|
+
subscription.fail(this.closedError("DeepSeek Harness runtime closed"));
|
|
681
|
+
return subscription;
|
|
682
|
+
}
|
|
683
|
+
this.subscriptions.set(id, subscription);
|
|
684
|
+
return subscription;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Subscribe to one session and the descendants discovered from
|
|
688
|
+
* `subagent.started` lineage edges. The runtime notifies for every session
|
|
689
|
+
* in its context, so this client applies the scope.
|
|
690
|
+
* @param sessionId - the root session id.
|
|
691
|
+
* @returns the filtered subscription handle.
|
|
692
|
+
*/
|
|
693
|
+
subscribeSessionTree(sessionId) {
|
|
694
|
+
return this.subscribe((notification) => {
|
|
695
|
+
const params = notification.params;
|
|
696
|
+
if (notification.method === "subagent.started" || notification.method === "subagent.finished") {
|
|
697
|
+
const parentId = params.parentSessionId;
|
|
698
|
+
if (typeof parentId === "string" && this.isDescendantOf(parentId, sessionId)) return true;
|
|
699
|
+
return params.childSessionId === sessionId;
|
|
700
|
+
}
|
|
701
|
+
const relatedId = params.sessionId;
|
|
702
|
+
return typeof relatedId === "string" && this.isDescendantOf(relatedId, sessionId);
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Shut the runtime down and reap it: a best-effort protocol `shutdown`
|
|
707
|
+
* bounded by `shutdownTimeoutMs`, then the shared stdin-EOF → SIGTERM →
|
|
708
|
+
* SIGKILL ladder until the process actually exited. Idempotent.
|
|
709
|
+
* @returns settlement of the complete teardown.
|
|
710
|
+
*/
|
|
711
|
+
close() {
|
|
712
|
+
this.closeTask ??= this.performClose();
|
|
713
|
+
return this.closeTask;
|
|
714
|
+
}
|
|
715
|
+
async performClose() {
|
|
716
|
+
const child = this.child;
|
|
717
|
+
if (child === void 0) return;
|
|
718
|
+
try {
|
|
719
|
+
await this.request("shutdown", void 0, this.runtime.shutdownTimeoutMs ?? 1e3);
|
|
720
|
+
} catch (error) {
|
|
721
|
+
this.appendStderr([`shutdown request failed: ${errorMessage(error)}`]);
|
|
722
|
+
}
|
|
723
|
+
await disposeRuntimeProcess(child, {
|
|
724
|
+
disposeEofGraceMs: this.runtime.disposeEofGraceMs ?? 6e3,
|
|
725
|
+
disposeGraceMs: this.runtime.disposeGraceMs ?? 3e3
|
|
726
|
+
});
|
|
727
|
+
this.transport?.close();
|
|
728
|
+
this.failSubscriptions(this.closedError("DeepSeek Harness runtime closed"));
|
|
729
|
+
}
|
|
730
|
+
dispatchNotification(notification) {
|
|
731
|
+
this.recordSessionRelationship(notification);
|
|
732
|
+
for (const subscription of this.subscriptions.values()) subscription.push(notification);
|
|
733
|
+
}
|
|
734
|
+
recordSessionRelationship(notification) {
|
|
735
|
+
if (notification.method !== "subagent.started") return;
|
|
736
|
+
const parentId = notification.params.parentSessionId;
|
|
737
|
+
const childId = notification.params.childSessionId;
|
|
738
|
+
if (typeof parentId === "string" && parentId !== "" && typeof childId === "string" && childId !== "" && parentId !== childId) this.sessionParents.set(childId, parentId);
|
|
739
|
+
}
|
|
740
|
+
isDescendantOf(sessionId, rootSessionId) {
|
|
741
|
+
const visited = /* @__PURE__ */ new Set();
|
|
742
|
+
let current = sessionId;
|
|
743
|
+
while (!visited.has(current)) {
|
|
744
|
+
if (current === rootSessionId) return true;
|
|
745
|
+
visited.add(current);
|
|
746
|
+
const parent = this.sessionParents.get(current);
|
|
747
|
+
if (parent === void 0) return false;
|
|
748
|
+
current = parent;
|
|
749
|
+
}
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
failSubscriptions(error) {
|
|
753
|
+
for (const subscription of this.subscriptions.values()) subscription.fail(error);
|
|
754
|
+
}
|
|
755
|
+
appendStderr(lines) {
|
|
756
|
+
const kept = lines.filter((line) => line.length > 0);
|
|
757
|
+
this.stderrTail.push(...kept);
|
|
758
|
+
if (this.stderrTail.length > STDERR_TAIL_LIMIT) this.stderrTail.splice(0, this.stderrTail.length - STDERR_TAIL_LIMIT);
|
|
759
|
+
}
|
|
760
|
+
settleStreams() {
|
|
761
|
+
return Promise.race([this.streamsSettled, new Promise((resolve2) => {
|
|
762
|
+
setTimeout(resolve2, STREAM_SETTLE_MS);
|
|
763
|
+
})]);
|
|
764
|
+
}
|
|
765
|
+
closedError(reason) {
|
|
766
|
+
const parts = [`${this.runtime.description}: ${reason}`];
|
|
767
|
+
if (this.spawnError !== void 0) parts.push(`spawn error: ${this.spawnError.message}`);
|
|
768
|
+
if (this.exitCode !== void 0) parts.push(`exit code: ${String(this.exitCode)}`);
|
|
769
|
+
if (this.stderrTail.length > 0) parts.push(`stderr tail:
|
|
770
|
+
${this.stderrTail.join("\n")}`);
|
|
771
|
+
return new TransportClosedError(parts.join("\n"));
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
function isRecord(value) {
|
|
775
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
776
|
+
}
|
|
777
|
+
function errorMessage(error) {
|
|
778
|
+
return error instanceof Error ? error.message : String(error);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// packages/octo-runtime-adapter-dsh/dist/errors.js
|
|
782
|
+
var DSH_VERSION = "0.2.1-rc.3";
|
|
783
|
+
var messages = {
|
|
784
|
+
DSH_CONFIG_INVALID: "DeepSeek Harness configuration is invalid for this invocation.",
|
|
785
|
+
DSH_ACTMODE_UNSUPPORTED: "DeepSeek Harness supports only the default actmode.",
|
|
786
|
+
PROVIDER_MESSAGE_TOO_LARGE: "DeepSeek Harness protocol line exceeded the configured limit.",
|
|
787
|
+
STREAM_QUEUE_ITEM_TOO_LARGE: "DeepSeek Harness event exceeded the configured queue item limit.",
|
|
788
|
+
STREAM_QUEUE_BYTES_EXCEEDED: "DeepSeek Harness event queue exceeded the configured byte limit.",
|
|
789
|
+
STREAM_QUEUE_ITEMS_EXCEEDED: "DeepSeek Harness event queue exceeded the configured item limit.",
|
|
790
|
+
DSH_EXECUTABLE_NOT_FOUND: "Install a compatible DeepSeek Harness or select its executable.",
|
|
791
|
+
DSH_VERSION_UNSUPPORTED: "DeepSeek Harness version is incompatible with this adapter.",
|
|
792
|
+
DSH_START_FAILED: "DeepSeek Harness could not start.",
|
|
793
|
+
DSH_INITIALIZE_TIMEOUT: "DeepSeek Harness initialization timed out.",
|
|
794
|
+
DSH_RPC_ERROR: "DeepSeek Harness rejected a protocol request.",
|
|
795
|
+
DSH_REQUEST_TIMEOUT: "DeepSeek Harness request timed out; execution may have occurred.",
|
|
796
|
+
DSH_TRANSPORT_CLOSED: "DeepSeek Harness transport closed before execution was confirmed.",
|
|
797
|
+
DSH_PROTOCOL_ERROR: "DeepSeek Harness returned an invalid protocol envelope.",
|
|
798
|
+
DSH_TRAJECTORY_INVALID: "DeepSeek Harness execution evidence was incomplete or inconsistent.",
|
|
799
|
+
DSH_SESSION_RESUME_FAILED: "DeepSeek Harness could not restore the requested session.",
|
|
800
|
+
DSH_SESSION_BUSY: "The requested DeepSeek Harness session is already executing.",
|
|
801
|
+
DSH_EXECUTION_FAILED: "DeepSeek Harness reported an execution failure.",
|
|
802
|
+
DSH_NO_FINAL_OUTPUT: "DeepSeek Harness returned no committed assistant answer.",
|
|
803
|
+
DSH_CANCEL_FAILED: "DeepSeek Harness cancellation cleanup could not be confirmed.",
|
|
804
|
+
DSH_CLEANUP_FAILED: "DeepSeek Harness process cleanup could not be confirmed."
|
|
805
|
+
};
|
|
806
|
+
var DshError = class extends Error {
|
|
807
|
+
code;
|
|
808
|
+
diagnostics;
|
|
809
|
+
constructor(code, diagnostics = {}, options) {
|
|
810
|
+
super(`${code}: ${messages[code]}`, options);
|
|
811
|
+
this.code = code;
|
|
812
|
+
this.diagnostics = diagnostics;
|
|
813
|
+
this.name = "DshError";
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
function record(value) {
|
|
817
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
818
|
+
}
|
|
819
|
+
function nativeCode(value) {
|
|
820
|
+
if (typeof value === "number" && Number.isSafeInteger(value))
|
|
821
|
+
return value;
|
|
822
|
+
if (typeof value === "string" && /^[A-Z][A-Z0-9_]{0,95}$/.test(value))
|
|
823
|
+
return value;
|
|
824
|
+
return void 0;
|
|
825
|
+
}
|
|
826
|
+
function dshError(error, fallback) {
|
|
827
|
+
if (error instanceof DshError)
|
|
828
|
+
return error;
|
|
829
|
+
if (error instanceof RequestTimeoutError)
|
|
830
|
+
return new DshError(fallback === "DSH_INITIALIZE_TIMEOUT" ? fallback : "DSH_REQUEST_TIMEOUT", {}, { cause: error });
|
|
831
|
+
if (error instanceof TransportClosedError)
|
|
832
|
+
return new DshError("DSH_TRANSPORT_CLOSED", {}, { cause: error });
|
|
833
|
+
if (error instanceof SdkProtocolError)
|
|
834
|
+
return new DshError("DSH_PROTOCOL_ERROR", {}, { cause: error });
|
|
835
|
+
if (error instanceof JsonRpcResponseError) {
|
|
836
|
+
const code2 = nativeCode(error.code);
|
|
837
|
+
return new DshError("DSH_RPC_ERROR", code2 === void 0 ? {} : { nativeCode: code2 }, {
|
|
838
|
+
cause: error
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
const code = record(error) ? nativeCode(error.code) : void 0;
|
|
842
|
+
if (typeof code === "string" && Object.hasOwn(messages, code))
|
|
843
|
+
return new DshError(code, {}, { cause: error });
|
|
844
|
+
return new DshError(fallback, code === void 0 ? {} : { nativeCode: code }, { cause: error });
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export {
|
|
848
|
+
HarnessClient,
|
|
849
|
+
DSH_VERSION,
|
|
850
|
+
DshError,
|
|
851
|
+
record,
|
|
852
|
+
nativeCode,
|
|
853
|
+
dshError
|
|
854
|
+
};
|