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