@senpi/runtime 3.0.236 → 3.0.238
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/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +15 -0
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +25 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +83 -15
- package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +15 -0
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/adapter/api-wrapper.d.ts +61 -0
- package/dist/adapter/api-wrapper.d.ts.map +1 -0
- package/dist/adapter/api-wrapper.js +92 -0
- package/dist/adapter/api-wrapper.js.map +1 -0
- package/dist/adapter/approvals-file.d.ts +35 -0
- package/dist/adapter/approvals-file.d.ts.map +1 -0
- package/dist/adapter/approvals-file.js +80 -0
- package/dist/adapter/approvals-file.js.map +1 -0
- package/dist/adapter/busy-file.d.ts +56 -0
- package/dist/adapter/busy-file.d.ts.map +1 -0
- package/dist/adapter/busy-file.js +86 -0
- package/dist/adapter/busy-file.js.map +1 -0
- package/dist/adapter/daemon-client.d.ts +37 -0
- package/dist/adapter/daemon-client.d.ts.map +1 -0
- package/dist/adapter/daemon-client.js +74 -0
- package/dist/adapter/daemon-client.js.map +1 -0
- package/dist/adapter/mode.d.ts +28 -0
- package/dist/adapter/mode.d.ts.map +1 -0
- package/dist/adapter/mode.js +42 -0
- package/dist/adapter/mode.js.map +1 -0
- package/dist/adapter/passthrough-cli.d.ts +30 -0
- package/dist/adapter/passthrough-cli.d.ts.map +1 -0
- package/dist/adapter/passthrough-cli.js +44 -0
- package/dist/adapter/passthrough-cli.js.map +1 -0
- package/dist/adapter/runtime-skill-cap.d.ts +13 -0
- package/dist/adapter/runtime-skill-cap.d.ts.map +1 -0
- package/dist/adapter/runtime-skill-cap.js +17 -0
- package/dist/adapter/runtime-skill-cap.js.map +1 -0
- package/dist/approvals/tool-approval-gate.d.ts +2 -0
- package/dist/approvals/tool-approval-gate.d.ts.map +1 -1
- package/dist/approvals/tool-approval-gate.js +5 -2
- package/dist/approvals/tool-approval-gate.js.map +1 -1
- package/dist/cli/daemon-call.d.ts +50 -0
- package/dist/cli/daemon-call.d.ts.map +1 -0
- package/dist/cli/daemon-call.js +165 -0
- package/dist/cli/daemon-call.js.map +1 -0
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +53 -17
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts +8 -6
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +101 -67
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/cli/standalone.d.ts +24 -0
- package/dist/cli/standalone.d.ts.map +1 -0
- package/dist/cli/standalone.js +111 -0
- package/dist/cli/standalone.js.map +1 -0
- package/dist/cli/update-command.d.ts +7 -8
- package/dist/cli/update-command.d.ts.map +1 -1
- package/dist/cli/update-command.js +8 -33
- package/dist/cli/update-command.js.map +1 -1
- package/dist/daemon/api-version.d.ts +3 -0
- package/dist/daemon/api-version.d.ts.map +1 -0
- package/dist/daemon/api-version.js +3 -0
- package/dist/daemon/api-version.js.map +1 -0
- package/dist/daemon/errors.d.ts +36 -0
- package/dist/daemon/errors.d.ts.map +1 -0
- package/dist/daemon/errors.js +97 -0
- package/dist/daemon/errors.js.map +1 -0
- package/dist/daemon/host.d.ts +130 -0
- package/dist/daemon/host.d.ts.map +1 -0
- package/dist/daemon/host.js +202 -0
- package/dist/daemon/host.js.map +1 -0
- package/dist/daemon/http-routes.d.ts +37 -0
- package/dist/daemon/http-routes.d.ts.map +1 -0
- package/dist/daemon/http-routes.js +233 -0
- package/dist/daemon/http-routes.js.map +1 -0
- package/dist/daemon/main.d.ts +93 -0
- package/dist/daemon/main.d.ts.map +1 -0
- package/dist/daemon/main.js +308 -0
- package/dist/daemon/main.js.map +1 -0
- package/dist/daemon/mcp-endpoint.d.ts +55 -0
- package/dist/daemon/mcp-endpoint.d.ts.map +1 -0
- package/dist/daemon/mcp-endpoint.js +178 -0
- package/dist/daemon/mcp-endpoint.js.map +1 -0
- package/dist/daemon/memory.d.ts +29 -0
- package/dist/daemon/memory.d.ts.map +1 -0
- package/dist/daemon/memory.js +74 -0
- package/dist/daemon/memory.js.map +1 -0
- package/dist/daemon/owner-lock.d.ts +44 -0
- package/dist/daemon/owner-lock.d.ts.map +1 -0
- package/dist/daemon/owner-lock.js +149 -0
- package/dist/daemon/owner-lock.js.map +1 -0
- package/dist/daemon/request-ids.d.ts +48 -0
- package/dist/daemon/request-ids.d.ts.map +1 -0
- package/dist/daemon/request-ids.js +123 -0
- package/dist/daemon/request-ids.js.map +1 -0
- package/dist/daemon/route-table.d.ts +51 -0
- package/dist/daemon/route-table.d.ts.map +1 -0
- package/dist/daemon/route-table.js +120 -0
- package/dist/daemon/route-table.js.map +1 -0
- package/dist/daemon/telemetry-ws.d.ts +60 -0
- package/dist/daemon/telemetry-ws.d.ts.map +1 -0
- package/dist/daemon/telemetry-ws.js +166 -0
- package/dist/daemon/telemetry-ws.js.map +1 -0
- package/dist/daemon/update-request.d.ts +145 -0
- package/dist/daemon/update-request.d.ts.map +1 -0
- package/dist/daemon/update-request.js +250 -0
- package/dist/daemon/update-request.js.map +1 -0
- package/dist/deploy/messages.d.ts +1 -0
- package/dist/deploy/messages.d.ts.map +1 -1
- package/dist/deploy/messages.js +9 -0
- package/dist/deploy/messages.js.map +1 -1
- package/dist/deploy/orchestrator.d.ts.map +1 -1
- package/dist/deploy/orchestrator.js +13 -1
- package/dist/deploy/orchestrator.js.map +1 -1
- package/dist/deploy/package.d.ts +8 -0
- package/dist/deploy/package.d.ts.map +1 -1
- package/dist/deploy/package.js +8 -0
- package/dist/deploy/package.js.map +1 -1
- package/dist/deploy/recheck-commands.d.ts +2 -0
- package/dist/deploy/recheck-commands.d.ts.map +1 -1
- package/dist/deploy/recheck-commands.js +4 -0
- package/dist/deploy/recheck-commands.js.map +1 -1
- package/dist/deploy/sim-admission.d.ts +94 -0
- package/dist/deploy/sim-admission.d.ts.map +1 -0
- package/dist/deploy/sim-admission.js +138 -0
- package/dist/deploy/sim-admission.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +174 -14
- package/dist/index.js.map +1 -1
- package/dist/runtime/agent-wake.d.ts +116 -0
- package/dist/runtime/agent-wake.d.ts.map +1 -0
- package/dist/runtime/agent-wake.js +181 -0
- package/dist/runtime/agent-wake.js.map +1 -0
- package/dist/runtime/auto-update/coordinator.d.ts +18 -0
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +80 -2
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/idle-gate.d.ts +12 -1
- package/dist/runtime/auto-update/idle-gate.d.ts.map +1 -1
- package/dist/runtime/auto-update/idle-gate.js +7 -4
- package/dist/runtime/auto-update/idle-gate.js.map +1 -1
- package/dist/runtime/create-actions.d.ts +5 -1
- package/dist/runtime/create-actions.d.ts.map +1 -1
- package/dist/runtime/create-actions.js +17 -2
- package/dist/runtime/create-actions.js.map +1 -1
- package/dist/runtime/decision-errors.d.ts +5 -0
- package/dist/runtime/decision-errors.d.ts.map +1 -1
- package/dist/runtime/decision-errors.js +10 -0
- package/dist/runtime/decision-errors.js.map +1 -1
- package/dist/runtime/recipe-file.d.ts +73 -0
- package/dist/runtime/recipe-file.d.ts.map +1 -0
- package/dist/runtime/recipe-file.js +194 -0
- package/dist/runtime/recipe-file.js.map +1 -0
- package/dist/runtime/runtime-descriptor.d.ts +23 -0
- package/dist/runtime/runtime-descriptor.d.ts.map +1 -1
- package/dist/runtime/runtime-descriptor.js +40 -0
- package/dist/runtime/runtime-descriptor.js.map +1 -1
- package/dist/runtime/runtime.d.ts +12 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +109 -4
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +4 -2
- package/dist/runtime/update-apply-deps.d.ts.map +1 -1
- package/dist/runtime/update-apply-deps.js +4 -2
- package/dist/runtime/update-apply-deps.js.map +1 -1
- package/dist/runtime/update-handler.d.ts +6 -0
- package/dist/runtime/update-handler.d.ts.map +1 -1
- package/dist/runtime/update-handler.js +159 -12
- package/dist/runtime/update-handler.js.map +1 -1
- package/dist/runtime/update-register.d.ts.map +1 -1
- package/dist/runtime/update-register.js +18 -0
- package/dist/runtime/update-register.js.map +1 -1
- package/dist/runtime-api/extensions.d.ts +20 -0
- package/dist/runtime-api/extensions.d.ts.map +1 -0
- package/dist/runtime-api/extensions.js +28 -0
- package/dist/runtime-api/extensions.js.map +1 -0
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +3 -1
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/lifecycle.d.ts.map +1 -1
- package/dist/runtime-api/lifecycle.js +6 -0
- package/dist/runtime-api/lifecycle.js.map +1 -1
- package/dist/runtime-api/server.d.ts.map +1 -1
- package/dist/runtime-api/server.js +3 -0
- package/dist/runtime-api/server.js.map +1 -1
- package/dist/scanners/external-scanner-receiver.d.ts +2 -0
- package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
- package/dist/scanners/external-scanner-receiver.js +4 -0
- package/dist/scanners/external-scanner-receiver.js.map +1 -1
- package/dist/telemetry/context.d.ts +17 -0
- package/dist/telemetry/context.d.ts.map +1 -1
- package/dist/telemetry/context.js.map +1 -1
- package/dist/telemetry/otel-sdk.d.ts +2 -0
- package/dist/telemetry/otel-sdk.d.ts.map +1 -1
- package/dist/telemetry/otel-sdk.js +2 -0
- package/dist/telemetry/otel-sdk.js.map +1 -1
- package/dist/types/scanner.d.ts +6 -0
- package/dist/types/scanner.d.ts.map +1 -1
- package/dist/validate/package-gates-stage.d.ts +13 -1
- package/dist/validate/package-gates-stage.d.ts.map +1 -1
- package/dist/validate/package-gates-stage.js +3 -8
- package/dist/validate/package-gates-stage.js.map +1 -1
- package/dist/validate/target.d.ts +75 -1
- package/dist/validate/target.d.ts.map +1 -1
- package/dist/validate/target.js +94 -28
- package/dist/validate/target.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter mode: the same `register()` runs against a wrapped OpenClaw api, so every agent-side
|
|
3
|
+
* registration (hooks, approval gate, tracing, widget tool, crib sheet, skills methods) goes
|
|
4
|
+
* through unchanged, while the trading side is replaced:
|
|
5
|
+
*
|
|
6
|
+
* - each runtime gateway method the daemon serves → an alias with the same name and scope that
|
|
7
|
+
* forwards to the daemon and returns today's exact answer (counted per call);
|
|
8
|
+
* - methods the daemon deliberately does not serve → a named refusal;
|
|
9
|
+
* - `senpi.skills.*` → kept (the skills manager lives in the adapter);
|
|
10
|
+
* - the trading service (`senpi-runtime`) → not registered (the daemon trades);
|
|
11
|
+
* - the `senpi` CLI → replaced by a pass-through to the `senpi` binary.
|
|
12
|
+
*/
|
|
13
|
+
import { DAEMON_METHODS, NOT_SERVED_BY_DAEMON } from "../daemon/route-table.js";
|
|
14
|
+
export function createAliasCounter(log) {
|
|
15
|
+
const counts = new Map();
|
|
16
|
+
return {
|
|
17
|
+
hit(method) {
|
|
18
|
+
const n = (counts.get(method) ?? 0) + 1;
|
|
19
|
+
counts.set(method, n);
|
|
20
|
+
// One structured line per call: the alias-removal query counts these (component=adapter).
|
|
21
|
+
log(`[senpi-adapter] alias call | method=${method} count=${n}`);
|
|
22
|
+
},
|
|
23
|
+
count: (method) => counts.get(method) ?? 0,
|
|
24
|
+
snapshot: () => Object.fromEntries(counts),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Methods kept in the adapter as registered by today's code. */
|
|
28
|
+
export function isAdapterLocalMethod(name) {
|
|
29
|
+
return name.startsWith("senpi.skills.");
|
|
30
|
+
}
|
|
31
|
+
/** Today's trading service id; the adapter never runs it. */
|
|
32
|
+
export const TRADING_SERVICE_ID = "senpi-runtime";
|
|
33
|
+
const MAY_HAVE_BEEN_SENT = /may have been sent/i;
|
|
34
|
+
export function makeAliasHandler(method, opts) {
|
|
35
|
+
return async ({ respond, params }) => {
|
|
36
|
+
opts.counter.hit(method);
|
|
37
|
+
const blocked = opts.blocked?.();
|
|
38
|
+
if (blocked)
|
|
39
|
+
return respond(false, undefined, { code: "API_VERSION_MISMATCH", message: `[API_VERSION_MISMATCH] ${blocked}` });
|
|
40
|
+
const result = await opts.client.call(method, params ?? {});
|
|
41
|
+
if (!result.ok) {
|
|
42
|
+
// A gateway method can only answer with code + message, so "may have been sent" is said in
|
|
43
|
+
// the message: a caller must not read this answer as a plain refusal and send the write again.
|
|
44
|
+
const error = result.sent === "maybe" && !MAY_HAVE_BEEN_SENT.test(result.error.message)
|
|
45
|
+
? { ...result.error, message: `${result.error.message} (the request may have been sent: check status before retrying)` }
|
|
46
|
+
: result.error;
|
|
47
|
+
return respond(false, undefined, error);
|
|
48
|
+
}
|
|
49
|
+
const decorate = opts.decorators?.get(method);
|
|
50
|
+
respond(true, decorate ? decorate(result.payload) : result.payload);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function wrapApiForAdapter(api, opts) {
|
|
54
|
+
const daemonMethods = new Set(DAEMON_METHODS);
|
|
55
|
+
return new Proxy(api, {
|
|
56
|
+
get(target, prop, receiver) {
|
|
57
|
+
if (prop === "registerGatewayMethod") {
|
|
58
|
+
return (name, handler, regOpts) => {
|
|
59
|
+
if (isAdapterLocalMethod(name))
|
|
60
|
+
return target.registerGatewayMethod(name, handler, regOpts);
|
|
61
|
+
if (daemonMethods.has(name)) {
|
|
62
|
+
// Same name and scope as today; the body forwards to the daemon.
|
|
63
|
+
return target.registerGatewayMethod(name, makeAliasHandler(name, opts), regOpts);
|
|
64
|
+
}
|
|
65
|
+
const reason = NOT_SERVED_BY_DAEMON[name];
|
|
66
|
+
if (reason) {
|
|
67
|
+
return target.registerGatewayMethod(name, ({ respond }) => {
|
|
68
|
+
opts.counter.hit(name);
|
|
69
|
+
respond(false, undefined, { code: "NOT_AVAILABLE", message: `${name} is not available on this box: ${reason}` });
|
|
70
|
+
}, regOpts);
|
|
71
|
+
}
|
|
72
|
+
// A method added to the runtime later and not yet routed to the daemon: refuse rather
|
|
73
|
+
// than run trading code inside OpenClaw. The adapter's method-set test catches it.
|
|
74
|
+
opts.warn(`[senpi-adapter] ${name} has no daemon route; answering NOT_AVAILABLE`);
|
|
75
|
+
return target.registerGatewayMethod(name, ({ respond }) => respond(false, undefined, { code: "NOT_AVAILABLE", message: `${name} is not available on this box yet` }), regOpts);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (prop === "registerService") {
|
|
79
|
+
return (service) => {
|
|
80
|
+
if (service.id === TRADING_SERVICE_ID)
|
|
81
|
+
return; // the daemon trades
|
|
82
|
+
return target.registerService(service);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (prop === "registerCli") {
|
|
86
|
+
return (_fn, cliOpts) => target.registerCli((ctx) => opts.registerPassThroughCli(ctx.program), cliOpts ?? { commands: ["senpi"] });
|
|
87
|
+
}
|
|
88
|
+
return Reflect.get(target, prop, receiver);
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=api-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-wrapper.js","sourceRoot":"","sources":["../../src/adapter/api-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAiBhF,M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3B,OAAO,CAAC,GAAY,EAAE,OAAgC,EAAE,EAAE,CACxD,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,IAAI,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC9G,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter's approval-gate status, read by the runtime daemon for `senpi status`.
|
|
3
|
+
*
|
|
4
|
+
* The approval gate runs inside OpenClaw (the adapter), not in the daemon, so the daemon cannot
|
|
5
|
+
* see it. The adapter writes what `senpi.getHealthStatus` → `approvals` reports today, next to the
|
|
6
|
+
* busy file, on start and every 30 s:
|
|
7
|
+
*
|
|
8
|
+
* { ...ApprovalsHostStatus, "updatedAt": ISO }
|
|
9
|
+
*
|
|
10
|
+
* The daemon reports the last written status with `reportedAt` (the adapter stops writing while
|
|
11
|
+
* the gateway sleeps, and its counts restart with OpenClaw). No file yet: the daemon reports no
|
|
12
|
+
* `approvals` section rather than its own view of a gate it does not run.
|
|
13
|
+
*/
|
|
14
|
+
import type { ApprovalsHostStatus } from "../approvals/turn-context.js";
|
|
15
|
+
export declare const APPROVALS_REFRESH_MS = 30000;
|
|
16
|
+
export declare const DEFAULT_APPROVALS_FILE = "/data/.openclaw/senpi-adapter/approvals.json";
|
|
17
|
+
export type ReportedApprovalsStatus = ApprovalsHostStatus & {
|
|
18
|
+
reportedAt: string;
|
|
19
|
+
};
|
|
20
|
+
/** The file both sides use: SENPI_APPROVALS_FILE, else next to SENPI_BUSY_FILE, else the default. */
|
|
21
|
+
export declare function approvalsFilePath(env?: NodeJS.ProcessEnv): string;
|
|
22
|
+
export declare function writeApprovalsFile(file: string, status: ApprovalsHostStatus, now?: number): void;
|
|
23
|
+
/** The adapter's last written status, or undefined when there is none (or it is unreadable). */
|
|
24
|
+
export declare function readApprovalsFile(file: string): ReportedApprovalsStatus | undefined;
|
|
25
|
+
export interface ApprovalsFileWriter {
|
|
26
|
+
touch(): void;
|
|
27
|
+
stop(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function startApprovalsFileWriter(opts: {
|
|
30
|
+
file: string;
|
|
31
|
+
status: () => ApprovalsHostStatus;
|
|
32
|
+
refreshMs?: number;
|
|
33
|
+
onError?: (err: unknown) => void;
|
|
34
|
+
}): ApprovalsFileWriter;
|
|
35
|
+
//# sourceMappingURL=approvals-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approvals-file.d.ts","sourceRoot":"","sources":["../../src/adapter/approvals-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,eAAO,MAAM,sBAAsB,iDAAiD,CAAC;AAErF,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,qGAAqG;AACrG,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAK9E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,GAAE,MAAmB,GAAG,IAAI,CAK5G;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAwBnF;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;CACd;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,mBAAmB,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC,GAAG,mBAAmB,CAYtB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter's approval-gate status, read by the runtime daemon for `senpi status`.
|
|
3
|
+
*
|
|
4
|
+
* The approval gate runs inside OpenClaw (the adapter), not in the daemon, so the daemon cannot
|
|
5
|
+
* see it. The adapter writes what `senpi.getHealthStatus` → `approvals` reports today, next to the
|
|
6
|
+
* busy file, on start and every 30 s:
|
|
7
|
+
*
|
|
8
|
+
* { ...ApprovalsHostStatus, "updatedAt": ISO }
|
|
9
|
+
*
|
|
10
|
+
* The daemon reports the last written status with `reportedAt` (the adapter stops writing while
|
|
11
|
+
* the gateway sleeps, and its counts restart with OpenClaw). No file yet: the daemon reports no
|
|
12
|
+
* `approvals` section rather than its own view of a gate it does not run.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
export const APPROVALS_REFRESH_MS = 30_000;
|
|
17
|
+
export const DEFAULT_APPROVALS_FILE = "/data/.openclaw/senpi-adapter/approvals.json";
|
|
18
|
+
/** The file both sides use: SENPI_APPROVALS_FILE, else next to SENPI_BUSY_FILE, else the default. */
|
|
19
|
+
export function approvalsFilePath(env = process.env) {
|
|
20
|
+
const explicit = env.SENPI_APPROVALS_FILE?.trim();
|
|
21
|
+
if (explicit)
|
|
22
|
+
return explicit;
|
|
23
|
+
const busy = env.SENPI_BUSY_FILE?.trim();
|
|
24
|
+
return busy ? path.join(path.dirname(busy), "approvals.json") : DEFAULT_APPROVALS_FILE;
|
|
25
|
+
}
|
|
26
|
+
export function writeApprovalsFile(file, status, now = Date.now()) {
|
|
27
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
28
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
29
|
+
writeFileSync(tmp, `${JSON.stringify({ ...status, updatedAt: new Date(now).toISOString() })}\n`);
|
|
30
|
+
renameSync(tmp, file);
|
|
31
|
+
}
|
|
32
|
+
/** The adapter's last written status, or undefined when there is none (or it is unreadable). */
|
|
33
|
+
export function readApprovalsFile(file) {
|
|
34
|
+
let raw;
|
|
35
|
+
try {
|
|
36
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
42
|
+
return undefined;
|
|
43
|
+
const { updatedAt, ...rest } = raw;
|
|
44
|
+
if (typeof updatedAt !== "string")
|
|
45
|
+
return undefined;
|
|
46
|
+
if (rest.turnClassification === "available") {
|
|
47
|
+
const out = { turnClassification: "available", reportedAt: updatedAt };
|
|
48
|
+
if (typeof rest.runsRecorded === "number")
|
|
49
|
+
out.runsRecorded = rest.runsRecorded;
|
|
50
|
+
if (typeof rest.unclassifiedBlocks === "number")
|
|
51
|
+
out.unclassifiedBlocks = rest.unclassifiedBlocks;
|
|
52
|
+
if (typeof rest.lastUnclassifiedBlockAt === "string")
|
|
53
|
+
out.lastUnclassifiedBlockAt = rest.lastUnclassifiedBlockAt;
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
if (rest.turnClassification === "unavailable") {
|
|
57
|
+
const out = { turnClassification: "unavailable", reportedAt: updatedAt };
|
|
58
|
+
if (typeof rest.reason === "string")
|
|
59
|
+
out.reason = rest.reason;
|
|
60
|
+
if (rest.hostLimit === true)
|
|
61
|
+
out.hostLimit = true;
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
export function startApprovalsFileWriter(opts) {
|
|
67
|
+
const write = () => {
|
|
68
|
+
try {
|
|
69
|
+
writeApprovalsFile(opts.file, opts.status());
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
opts.onError?.(err);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
write();
|
|
76
|
+
const timer = setInterval(write, opts.refreshMs ?? APPROVALS_REFRESH_MS);
|
|
77
|
+
timer.unref();
|
|
78
|
+
return { touch: write, stop: () => clearInterval(timer) };
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=approvals-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approvals-file.js","sourceRoot":"","sources":["../../src/adapter/approvals-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,8CAA8C,CAAC;AAIrF,qGAAqG;AACrG,MAAM,UAAU,iBAAiB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACpE,MAAM,QAAQ,GAAG,GAAG,CAAC,oBAAoB,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IACzC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,MAA2B,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;IACpG,SAAS,CAAC,IAAI,C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
*
|
|
4
|
+
* { "running": boolean, "runs": [{ "kind", "startedAt" }], "pendingApprovals": number,
|
|
5
|
+
* "lastUserMessageAt", "updatedAt" }
|
|
6
|
+
*
|
|
7
|
+
* `pendingApprovals` counts trade approvals waiting for the user's answer, only those not yet
|
|
8
|
+
* expired; one with no expiry stops counting after 30 min (`PendingApprovalTracker`). A reader
|
|
9
|
+
* treats an absent field as 0 (older adapter).
|
|
10
|
+
*
|
|
11
|
+
* Built from the activity today's idle gate already tracks from OpenClaw's events (agent runs,
|
|
12
|
+
* sub-agents, `message_received`), so it counts work exactly as the runtime does today.
|
|
13
|
+
* Refreshed every 30 s while OpenClaw is alive, written atomically (temp file, then rename).
|
|
14
|
+
* A run stays in the file until it ends (`agent_end` / the lifecycle `end`); only a run older than
|
|
15
|
+
* OpenClaw's own run timeout (48 h) is dropped as stale, so a long agent turn keeps the box awake.
|
|
16
|
+
* The wrapper treats a file not refreshed for ~2 min as stale (stay awake); the file is reset when
|
|
17
|
+
* OpenClaw (the adapter) starts.
|
|
18
|
+
*/
|
|
19
|
+
import type { IdleGateActivity } from "../runtime/auto-update/idle-gate.js";
|
|
20
|
+
export declare const BUSY_REFRESH_MS = 30000;
|
|
21
|
+
/** OpenClaw's run timeout: a run with no end after this long cannot still be running. */
|
|
22
|
+
export declare const BUSY_STALE_RUN_MS: number;
|
|
23
|
+
export declare const DEFAULT_BUSY_FILE = "/data/.openclaw/senpi-adapter/busy.json";
|
|
24
|
+
export type BusyRunKind = "user" | "background" | "agent" | "subagent";
|
|
25
|
+
export interface BusyFile {
|
|
26
|
+
running: boolean;
|
|
27
|
+
runs: Array<{
|
|
28
|
+
kind: BusyRunKind;
|
|
29
|
+
startedAt: string;
|
|
30
|
+
}>;
|
|
31
|
+
/** Unexpired approvals waiting for the user. */
|
|
32
|
+
pendingApprovals: number;
|
|
33
|
+
lastUserMessageAt: string | null;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function buildBusyFile(activity: IdleGateActivity, now: number, pendingApprovals?: number): BusyFile;
|
|
37
|
+
export declare function writeBusyFile(file: string, content: BusyFile): void;
|
|
38
|
+
export interface BusyFileWriter {
|
|
39
|
+
/** Write now (after an event, so the wrapper sees work start without waiting 30 s). */
|
|
40
|
+
touch(): void;
|
|
41
|
+
stop(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Start writing: once now, from the activity as it is (empty when OpenClaw just started), then
|
|
45
|
+
* every 30 s.
|
|
46
|
+
*/
|
|
47
|
+
export declare function startBusyFileWriter(opts: {
|
|
48
|
+
file: string;
|
|
49
|
+
activity: () => IdleGateActivity;
|
|
50
|
+
/** Unexpired approvals waiting for the user (`PendingApprovalTracker.count`). */
|
|
51
|
+
pendingApprovals?: () => number;
|
|
52
|
+
now?: () => number;
|
|
53
|
+
refreshMs?: number;
|
|
54
|
+
onError?: (err: unknown) => void;
|
|
55
|
+
}): BusyFileWriter;
|
|
56
|
+
//# sourceMappingURL=busy-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"busy-file.d.ts","sourceRoot":"","sources":["../../src/adapter/busy-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,yFAAyF;AACzF,eAAO,MAAM,iBAAiB,QAAmB,CAAC;AAClD,eAAO,MAAM,iBAAiB,4CAA4C,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC;AAEvE,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,wBAAgB,aAAa,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,gBAAgB,SAAI,GAAG,QAAQ,CAmBrG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAKnE;AAED,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,gBAAgB,CAAC;IACjC,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,MAAM,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC,GAAG,cAAc,CAyBjB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter's busy file, read by the wrapper's gateway-sleep logic:
|
|
3
|
+
*
|
|
4
|
+
* { "running": boolean, "runs": [{ "kind", "startedAt" }], "pendingApprovals": number,
|
|
5
|
+
* "lastUserMessageAt", "updatedAt" }
|
|
6
|
+
*
|
|
7
|
+
* `pendingApprovals` counts trade approvals waiting for the user's answer, only those not yet
|
|
8
|
+
* expired; one with no expiry stops counting after 30 min (`PendingApprovalTracker`). A reader
|
|
9
|
+
* treats an absent field as 0 (older adapter).
|
|
10
|
+
*
|
|
11
|
+
* Built from the activity today's idle gate already tracks from OpenClaw's events (agent runs,
|
|
12
|
+
* sub-agents, `message_received`), so it counts work exactly as the runtime does today.
|
|
13
|
+
* Refreshed every 30 s while OpenClaw is alive, written atomically (temp file, then rename).
|
|
14
|
+
* A run stays in the file until it ends (`agent_end` / the lifecycle `end`); only a run older than
|
|
15
|
+
* OpenClaw's own run timeout (48 h) is dropped as stale, so a long agent turn keeps the box awake.
|
|
16
|
+
* The wrapper treats a file not refreshed for ~2 min as stale (stay awake); the file is reset when
|
|
17
|
+
* OpenClaw (the adapter) starts.
|
|
18
|
+
*/
|
|
19
|
+
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
export const BUSY_REFRESH_MS = 30_000;
|
|
22
|
+
/** OpenClaw's run timeout: a run with no end after this long cannot still be running. */
|
|
23
|
+
export const BUSY_STALE_RUN_MS = 48 * 60 * 60_000;
|
|
24
|
+
export const DEFAULT_BUSY_FILE = "/data/.openclaw/senpi-adapter/busy.json";
|
|
25
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
26
|
+
export function buildBusyFile(activity, now, pendingApprovals = 0) {
|
|
27
|
+
const runs = [];
|
|
28
|
+
for (const run of activity.runs.values()) {
|
|
29
|
+
if (now - run.startedAt > BUSY_STALE_RUN_MS)
|
|
30
|
+
continue;
|
|
31
|
+
const kind = run.user === true ? "user" : run.user === false ? "background" : "agent";
|
|
32
|
+
runs.push({ kind, startedAt: iso(run.startedAt) });
|
|
33
|
+
}
|
|
34
|
+
for (const sub of activity.subagents.values()) {
|
|
35
|
+
if (now - sub.startedAt > BUSY_STALE_RUN_MS)
|
|
36
|
+
continue;
|
|
37
|
+
runs.push({ kind: "subagent", startedAt: iso(sub.startedAt) });
|
|
38
|
+
}
|
|
39
|
+
runs.sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
40
|
+
return {
|
|
41
|
+
running: runs.length > 0,
|
|
42
|
+
runs,
|
|
43
|
+
pendingApprovals: Number.isFinite(pendingApprovals) && pendingApprovals > 0 ? Math.floor(pendingApprovals) : 0,
|
|
44
|
+
lastUserMessageAt: activity.lastUserMessageAt !== undefined ? iso(activity.lastUserMessageAt) : null,
|
|
45
|
+
updatedAt: iso(now),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function writeBusyFile(file, content) {
|
|
49
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
50
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
51
|
+
writeFileSync(tmp, `${JSON.stringify(content)}\n`);
|
|
52
|
+
renameSync(tmp, file);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Start writing: once now, from the activity as it is (empty when OpenClaw just started), then
|
|
56
|
+
* every 30 s.
|
|
57
|
+
*/
|
|
58
|
+
export function startBusyFileWriter(opts) {
|
|
59
|
+
const now = opts.now ?? Date.now;
|
|
60
|
+
const write = () => {
|
|
61
|
+
try {
|
|
62
|
+
let pending = 0;
|
|
63
|
+
try {
|
|
64
|
+
pending = opts.pendingApprovals?.() ?? 0;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// An unreadable count must not stop the file: report one, so the box stays awake.
|
|
68
|
+
pending = 1;
|
|
69
|
+
}
|
|
70
|
+
writeBusyFile(opts.file, buildBusyFile(opts.activity(), now(), pending));
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
opts.onError?.(err);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// First write at start. A fresh OpenClaw process has no activity yet, so this is the reset; a
|
|
77
|
+
// plugin reload inside a running OpenClaw keeps its live runs, and the file must keep saying so.
|
|
78
|
+
write();
|
|
79
|
+
const timer = setInterval(write, opts.refreshMs ?? BUSY_REFRESH_MS);
|
|
80
|
+
timer.unref();
|
|
81
|
+
return {
|
|
82
|
+
touch: write,
|
|
83
|
+
stop: () => clearInterval(timer),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=busy-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"busy-file.js","sourceRoot":"","sources":["../../src/adapter/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H,IAAI,OAAO,GAAG,CAAC,CAAC;YAChB,IAAI,CAAC;gBACH,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAAC;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACP,kFAAkF;gBAClF,OAAO,GAAG,CAAC,CAAC;YACd,CAAC;YACD,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,CAAC;IACF,8FAA8F;IAC9F,iGAAiG;IACjG,KAAK,EAAE,CAAC;IACR,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,IAAI,eAAe,CAAC,CAAC;IACpE,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,OAAO;QACL,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter's client for the runtime daemon on 127.0.0.1:8787.
|
|
3
|
+
*
|
|
4
|
+
* The daemon listens on 127.0.0.1 only and takes no token. Aliases use `POST /v1/call/:method`, which hands OpenClaw's params to the handler untouched, so the answer
|
|
5
|
+
* and every refusal are exactly today's.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_DAEMON_URL = "http://127.0.0.1:8787";
|
|
8
|
+
export type DaemonCallResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
payload: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
error: {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
sent: "nothing" | "maybe";
|
|
18
|
+
};
|
|
19
|
+
export interface DaemonHello {
|
|
20
|
+
apiVersion: number;
|
|
21
|
+
daemonVersion: string;
|
|
22
|
+
capabilities: Record<string, boolean>;
|
|
23
|
+
methods: string[];
|
|
24
|
+
runtimeSkillMaxMajor: number | null;
|
|
25
|
+
}
|
|
26
|
+
export interface DaemonClientOptions {
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
fetchImpl?: typeof fetch;
|
|
30
|
+
}
|
|
31
|
+
export interface DaemonClient {
|
|
32
|
+
call(method: string, params: Record<string, unknown>): Promise<DaemonCallResult>;
|
|
33
|
+
hello(): Promise<DaemonHello | null>;
|
|
34
|
+
}
|
|
35
|
+
export declare function daemonClientFromEnv(env?: NodeJS.ProcessEnv): DaemonClient;
|
|
36
|
+
export declare function createDaemonClient(opts?: DaemonClientOptions): DaemonClient;
|
|
37
|
+
//# sourceMappingURL=daemon-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon-client.d.ts","sourceRoot":"","sources":["../../src/adapter/daemon-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC9B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAA;CAAE,CAAC;AAEvF,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjF,KAAK,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACtC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,YAAY,CAItF;AAID,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,mBAAwB,GAAG,YAAY,CAwD/E"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter's client for the runtime daemon on 127.0.0.1:8787.
|
|
3
|
+
*
|
|
4
|
+
* The daemon listens on 127.0.0.1 only and takes no token. Aliases use `POST /v1/call/:method`, which hands OpenClaw's params to the handler untouched, so the answer
|
|
5
|
+
* and every refusal are exactly today's.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_DAEMON_URL = "http://127.0.0.1:8787";
|
|
8
|
+
export function daemonClientFromEnv(env = process.env) {
|
|
9
|
+
return createDaemonClient({
|
|
10
|
+
baseUrl: env.SENPI_DAEMON_URL?.trim() || DEFAULT_DAEMON_URL,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const UNAVAILABLE = "runtime restarting or not running, retry";
|
|
14
|
+
export function createDaemonClient(opts = {}) {
|
|
15
|
+
const baseUrl = opts.baseUrl ?? DEFAULT_DAEMON_URL;
|
|
16
|
+
const timeoutMs = opts.timeoutMs ?? 120_000;
|
|
17
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
18
|
+
return {
|
|
19
|
+
async call(method, params) {
|
|
20
|
+
let res;
|
|
21
|
+
try {
|
|
22
|
+
res = await doFetch(`${baseUrl}/v1/call/${encodeURIComponent(method)}`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "content-type": "application/json" },
|
|
25
|
+
body: JSON.stringify(params ?? {}),
|
|
26
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// Only a connection that was never made means nothing reached the daemon. A timeout, or a
|
|
31
|
+
// connection that broke after the request left (daemon killed mid-call), may have been applied.
|
|
32
|
+
const e = err;
|
|
33
|
+
if (e.name === "TimeoutError" || e.name === "AbortError") {
|
|
34
|
+
return { ok: false, sent: "maybe", error: { code: "TIMEOUT", message: `${method} gave no answer in time` } };
|
|
35
|
+
}
|
|
36
|
+
const code = e.cause?.code;
|
|
37
|
+
if (code === "ECONNREFUSED" || code === "ENOENT" || code === "EHOSTUNREACH") {
|
|
38
|
+
return { ok: false, sent: "nothing", error: { code: "RUNTIME_UNAVAILABLE", message: UNAVAILABLE } };
|
|
39
|
+
}
|
|
40
|
+
return { ok: false, sent: "maybe", error: { code: "RUNTIME_UNAVAILABLE", message: "the runtime stopped answering mid-call" } };
|
|
41
|
+
}
|
|
42
|
+
let body;
|
|
43
|
+
try {
|
|
44
|
+
body = await res.json();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { ok: false, sent: "maybe", error: { code: "INTERNAL_ERROR", message: `unreadable answer from the daemon (HTTP ${res.status})` } };
|
|
48
|
+
}
|
|
49
|
+
const b = body;
|
|
50
|
+
if (b.ok === true)
|
|
51
|
+
return { ok: true, payload: b.result };
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
sent: b.error?.sent ?? "maybe",
|
|
55
|
+
error: { code: b.error?.code ?? "INTERNAL_ERROR", message: b.error?.message ?? `HTTP ${res.status}` },
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
async hello() {
|
|
59
|
+
try {
|
|
60
|
+
const res = await doFetch(`${baseUrl}/v1/hello`, {
|
|
61
|
+
signal: AbortSignal.timeout(10_000),
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
return null;
|
|
65
|
+
const b = (await res.json());
|
|
66
|
+
return b.ok ? (b.result ?? null) : null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=daemon-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon-client.js","sourceRoot":"","sources":["../../src/adapter/daemon-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAyB1D,MAAM,UAAU,mBAAmB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACtE,OAAO,kBAAkB,CAAC;QACxB,OAAO,EAAE,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,kBAAkB;KAC5D,CAAC,CAAC;AACL,CAAC;AAED,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAE/D,MAAM,UAAU,kBAAkB,CAAC,OAA4B,EAAE;IAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,kBAAkB,CAAC;IACnD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IAExC,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM;YACvB,IAAI,GAAa,CAAC;YAClB,IAAI,CAAC;gBACH,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,OAAO,YAAY,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE;oBACtE,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*
|
|
4
|
+
* - `plugin` — today: the whole runtime inside OpenClaw (default; every box not yet migrated).
|
|
5
|
+
* - `adapter` — inside OpenClaw on a migrated box: `RUNTIME_MODE=daemon` AND
|
|
6
|
+
* `SENPI_DAEMON_MANAGED=1`, which the wrapper sets only when it actually runs the
|
|
7
|
+
* daemon. Agent-side features only; trading calls forward to the daemon.
|
|
8
|
+
*
|
|
9
|
+
* `RUNTIME_MODE=daemon` without `SENPI_DAEMON_MANAGED=1` (an older wrapper, or the mode set by hand)
|
|
10
|
+
* would forward every trading call to a daemon that is not there, so the plugin stays in plugin
|
|
11
|
+
* mode and says so ({@link RUNTIME_MODE_IGNORED_WARNING}).
|
|
12
|
+
* - `daemon` — the runtime daemon process itself (`src/daemon/main.ts` sets
|
|
13
|
+
* `SENPI_RUNTIME_COMPONENT=daemon` before registering).
|
|
14
|
+
*/
|
|
15
|
+
export type RegisterMode = "plugin" | "adapter" | "daemon";
|
|
16
|
+
export declare const RUNTIME_MODE_IGNORED_WARNING = "RUNTIME_MODE=daemon ignored: no wrapper-managed daemon on this box";
|
|
17
|
+
export interface RegisterModeDetail {
|
|
18
|
+
mode: RegisterMode;
|
|
19
|
+
/** `RUNTIME_MODE=daemon` was set but no wrapper-managed daemon runs: plugin mode instead. */
|
|
20
|
+
daemonModeIgnored: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function resolveRegisterModeDetail(env?: NodeJS.ProcessEnv): RegisterModeDetail;
|
|
23
|
+
export declare function resolveRegisterMode(env?: NodeJS.ProcessEnv): RegisterMode;
|
|
24
|
+
/** Log the ignored-mode warning once per process. Returns whether it logged now. */
|
|
25
|
+
export declare function logDaemonModeIgnoredOnce(warn: (line: string) => void): boolean;
|
|
26
|
+
/** Tests only. */
|
|
27
|
+
export declare function resetDaemonModeIgnoredLogForTests(): void;
|
|
28
|
+
//# sourceMappingURL=mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode.d.ts","sourceRoot":"","sources":["../../src/adapter/mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3D,eAAO,MAAM,4BAA4B,uEAAuE,CAAC;AAEjH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,6FAA6F;IAC7F,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,yBAAyB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,kBAAkB,CAOlG;AAED,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,YAAY,CAEtF;AAID,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAK9E;AAED,kBAAkB;AAClB,wBAAgB,iCAAiC,IAAI,IAAI,CAExD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which role this `register()` call plays.
|
|
3
|
+
*
|
|
4
|
+
* - `plugin` — today: the whole runtime inside OpenClaw (default; every box not yet migrated).
|
|
5
|
+
* - `adapter` — inside OpenClaw on a migrated box: `RUNTIME_MODE=daemon` AND
|
|
6
|
+
* `SENPI_DAEMON_MANAGED=1`, which the wrapper sets only when it actually runs the
|
|
7
|
+
* daemon. Agent-side features only; trading calls forward to the daemon.
|
|
8
|
+
*
|
|
9
|
+
* `RUNTIME_MODE=daemon` without `SENPI_DAEMON_MANAGED=1` (an older wrapper, or the mode set by hand)
|
|
10
|
+
* would forward every trading call to a daemon that is not there, so the plugin stays in plugin
|
|
11
|
+
* mode and says so ({@link RUNTIME_MODE_IGNORED_WARNING}).
|
|
12
|
+
* - `daemon` — the runtime daemon process itself (`src/daemon/main.ts` sets
|
|
13
|
+
* `SENPI_RUNTIME_COMPONENT=daemon` before registering).
|
|
14
|
+
*/
|
|
15
|
+
export const RUNTIME_MODE_IGNORED_WARNING = "RUNTIME_MODE=daemon ignored: no wrapper-managed daemon on this box";
|
|
16
|
+
export function resolveRegisterModeDetail(env = process.env) {
|
|
17
|
+
if (env.SENPI_RUNTIME_COMPONENT === "daemon")
|
|
18
|
+
return { mode: "daemon", daemonModeIgnored: false };
|
|
19
|
+
if (env.RUNTIME_MODE?.trim().toLowerCase() === "daemon") {
|
|
20
|
+
if (env.SENPI_DAEMON_MANAGED?.trim() === "1")
|
|
21
|
+
return { mode: "adapter", daemonModeIgnored: false };
|
|
22
|
+
return { mode: "plugin", daemonModeIgnored: true };
|
|
23
|
+
}
|
|
24
|
+
return { mode: "plugin", daemonModeIgnored: false };
|
|
25
|
+
}
|
|
26
|
+
export function resolveRegisterMode(env = process.env) {
|
|
27
|
+
return resolveRegisterModeDetail(env).mode;
|
|
28
|
+
}
|
|
29
|
+
let ignoredLogged = false;
|
|
30
|
+
/** Log the ignored-mode warning once per process. Returns whether it logged now. */
|
|
31
|
+
export function logDaemonModeIgnoredOnce(warn) {
|
|
32
|
+
if (ignoredLogged)
|
|
33
|
+
return false;
|
|
34
|
+
ignoredLogged = true;
|
|
35
|
+
warn(`[senpi-runtime] ${RUNTIME_MODE_IGNORED_WARNING}; running the full runtime in plugin mode`);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** Tests only. */
|
|
39
|
+
export function resetDaemonModeIgnoredLogForTests() {
|
|
40
|
+
ignoredLogged = false;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode.js","sourceRoot":"","sources":["../../src/adapter/mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,CAAC,MAAM,4BAA4B,GAAG,oEAAoE,CAAC;AAQjH,MAAM,UAAU,yBAAyB,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5E,IAAI,GAAG,CAAC,uBAAuB,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;IAClG,IAAI,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE,CAAC;QACxD,IAAI,GAAG,CAAC,oBAAoB,EAAE,IAAI,EAAE,KAAK,GAAG;YAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;QACnG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;IACrD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACtE,OAAO,yBAAyB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,oFAAoF;AACpF,MAAM,UAAU,wBAAwB,CAAC,IAA4B;IACnE,IAAI,aAAa;QAAE,OAAO,KAAK,CAAC;IAChC,aAAa,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,mBAAmB,4BAA4B,2CAA2C,CAAC,CAAC;IACjG,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kBAAkB;AAClB,MAAM,UAAU,iCAAiC;IAC/C,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `openclaw senpi …` in adapter mode: runs `senpi …` (the daemon package's CLI, on the PATH via
|
|
3
|
+
* the wrapper's launcher) and passes its output and exit code through unchanged. One
|
|
4
|
+
* implementation of every command: the new CLI. Each call is counted, so the pass-through can be
|
|
5
|
+
* removed once nothing uses it.
|
|
6
|
+
*/
|
|
7
|
+
import { spawnSync } from "../utils/safe-spawn.js";
|
|
8
|
+
export interface CommandLike {
|
|
9
|
+
command(name: string, desc?: string): CommandLike;
|
|
10
|
+
description?(d: string): CommandLike;
|
|
11
|
+
allowUnknownOption?(allow?: boolean): CommandLike;
|
|
12
|
+
allowExcessArguments?(allow?: boolean): CommandLike;
|
|
13
|
+
helpOption?(flags: string | false): CommandLike;
|
|
14
|
+
argument?(name: string, desc?: string): CommandLike;
|
|
15
|
+
action(fn: (...args: unknown[]) => void): CommandLike;
|
|
16
|
+
}
|
|
17
|
+
export interface PassThroughDeps {
|
|
18
|
+
/** The `senpi` binary (default: `senpi` on the PATH). */
|
|
19
|
+
bin?: string;
|
|
20
|
+
argv?: string[];
|
|
21
|
+
onCall?: () => void;
|
|
22
|
+
spawn?: typeof spawnSync;
|
|
23
|
+
setExitCode?: (code: number) => void;
|
|
24
|
+
writeErr?: (text: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/** Everything after the first `senpi` word in `openclaw … senpi <args>`. */
|
|
27
|
+
export declare function argsAfterSenpi(argv: string[]): string[];
|
|
28
|
+
export declare function runPassThrough(deps?: PassThroughDeps): number;
|
|
29
|
+
export declare function registerPassThroughCli(program: unknown, deps?: PassThroughDeps): void;
|
|
30
|
+
//# sourceMappingURL=passthrough-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passthrough-cli.d.ts","sourceRoot":"","sources":["../../src/adapter/passthrough-cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAClD,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACrC,kBAAkB,CAAC,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAClD,oBAAoB,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