@clawos-dev/clawd 0.2.169 → 0.2.170
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/dist/cli.cjs +55 -5
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -40755,6 +40755,8 @@ async function handleRpcRequest(input) {
|
|
|
40755
40755
|
// src/transport/http-router.ts
|
|
40756
40756
|
var RPC_ROUTE_PREFIX = "/api/rpc/";
|
|
40757
40757
|
var RPC_BODY_MAX_BYTES = 1 * 1024 * 1024;
|
|
40758
|
+
var DISPATCH_HEARTBEAT_MS = 25e3;
|
|
40759
|
+
var DISPATCH_HOLD_METHOD = "personaDispatch:run";
|
|
40758
40760
|
var AUTHED_RPC_ROUTE_PREFIX = "/rpc/";
|
|
40759
40761
|
var AUTHED_RPC_CORS_HEADERS = {
|
|
40760
40762
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -40903,12 +40905,60 @@ function createHttpRouter(deps) {
|
|
|
40903
40905
|
sendJson(res, 400, { ok: false, error: "INVALID_BODY", message: err instanceof Error ? err.message : String(err) }, AUTHED_RPC_CORS_HEADERS);
|
|
40904
40906
|
return true;
|
|
40905
40907
|
}
|
|
40908
|
+
const dispatchArgs = typeof body === "object" && body != null ? body : {};
|
|
40909
|
+
if (method === DISPATCH_HOLD_METHOD) {
|
|
40910
|
+
const heartbeatMs = deps.dispatchHeartbeatMs ?? DISPATCH_HEARTBEAT_MS;
|
|
40911
|
+
let headSent = false;
|
|
40912
|
+
let hbInterval;
|
|
40913
|
+
const startStreaming = () => {
|
|
40914
|
+
headSent = true;
|
|
40915
|
+
req.socket?.setTimeout?.(0);
|
|
40916
|
+
res.socket?.setTimeout?.(0);
|
|
40917
|
+
res.writeHead(200, {
|
|
40918
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
40919
|
+
"Transfer-Encoding": "chunked",
|
|
40920
|
+
// nginx 专用:禁用该响应缓冲,让心跳字节即时 flush 到上游 read(否则被攒着不重置计时)
|
|
40921
|
+
"X-Accel-Buffering": "no",
|
|
40922
|
+
...AUTHED_RPC_CORS_HEADERS
|
|
40923
|
+
});
|
|
40924
|
+
res.write(" ");
|
|
40925
|
+
hbInterval = setInterval(() => {
|
|
40926
|
+
try {
|
|
40927
|
+
res.write(" ");
|
|
40928
|
+
} catch {
|
|
40929
|
+
}
|
|
40930
|
+
}, heartbeatMs);
|
|
40931
|
+
};
|
|
40932
|
+
const graceTimer = setTimeout(startStreaming, heartbeatMs);
|
|
40933
|
+
const cleanup = () => {
|
|
40934
|
+
clearTimeout(graceTimer);
|
|
40935
|
+
if (hbInterval) clearInterval(hbInterval);
|
|
40936
|
+
};
|
|
40937
|
+
const safeEnd = (payload) => {
|
|
40938
|
+
if (res.writableEnded || res.destroyed) return;
|
|
40939
|
+
try {
|
|
40940
|
+
res.end(payload);
|
|
40941
|
+
} catch {
|
|
40942
|
+
}
|
|
40943
|
+
};
|
|
40944
|
+
res.on("close", cleanup);
|
|
40945
|
+
try {
|
|
40946
|
+
const result = await deps.authedRpc.dispatch(method, dispatchArgs, auth.context);
|
|
40947
|
+
cleanup();
|
|
40948
|
+
if (headSent) safeEnd(JSON.stringify({ ok: true, result: result.response }));
|
|
40949
|
+
else sendJson(res, 200, { ok: true, result: result.response }, AUTHED_RPC_CORS_HEADERS);
|
|
40950
|
+
} catch (err) {
|
|
40951
|
+
cleanup();
|
|
40952
|
+
const e = err;
|
|
40953
|
+
const code = e?.code ?? "INTERNAL";
|
|
40954
|
+
const payload = { ok: false, error: code, message: e?.message ?? String(err) };
|
|
40955
|
+
if (headSent) safeEnd(JSON.stringify(payload));
|
|
40956
|
+
else sendJson(res, authedRpcErrorStatus(code), payload, AUTHED_RPC_CORS_HEADERS);
|
|
40957
|
+
}
|
|
40958
|
+
return true;
|
|
40959
|
+
}
|
|
40906
40960
|
try {
|
|
40907
|
-
const result = await deps.authedRpc.dispatch(
|
|
40908
|
-
method,
|
|
40909
|
-
typeof body === "object" && body != null ? body : {},
|
|
40910
|
-
auth.context
|
|
40911
|
-
);
|
|
40961
|
+
const result = await deps.authedRpc.dispatch(method, dispatchArgs, auth.context);
|
|
40912
40962
|
sendJson(res, 200, { ok: true, result: result.response }, AUTHED_RPC_CORS_HEADERS);
|
|
40913
40963
|
} catch (err) {
|
|
40914
40964
|
const e = err;
|