clawmoney 0.8.4 → 0.8.6
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/commands/hub.js +1 -8
- package/dist/hub/executor.js +28 -68
- package/dist/hub/provider.js +3 -11
- package/dist/hub/types.d.ts +0 -3
- package/dist/index.js +1 -1
- package/dist/utils/config.d.ts +0 -3
- package/package.json +1 -1
package/dist/commands/hub.js
CHANGED
|
@@ -41,15 +41,8 @@ export async function hubStartCommand(options) {
|
|
|
41
41
|
const pid = readPid();
|
|
42
42
|
if (pid && isPidAlive(pid)) {
|
|
43
43
|
spinner.succeed(chalk.green(`Hub Provider started (PID ${pid})`));
|
|
44
|
-
const mode = config.provider?.execution_mode || "webhook";
|
|
45
44
|
console.log(chalk.dim(` Log file: ${LOG_FILE}`));
|
|
46
|
-
console.log(chalk.dim(`
|
|
47
|
-
if (mode === "cli") {
|
|
48
|
-
console.log(chalk.dim(` CLI command: ${options.cli || config.provider?.cli_command || "claude"}`));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
console.log(chalk.dim(` Webhook: ${config.provider?.webhook_url || "http://127.0.0.1:18789/hooks/agent"}`));
|
|
52
|
-
}
|
|
45
|
+
console.log(chalk.dim(` CLI: ${options.cli || config.provider?.cli_command || "openclaw"}`));
|
|
53
46
|
console.log(chalk.dim(` API key: ${config.api_key.slice(0, 8)}...`));
|
|
54
47
|
}
|
|
55
48
|
else {
|
package/dist/hub/executor.js
CHANGED
|
@@ -24,52 +24,19 @@ function buildPrompt(call, config) {
|
|
|
24
24
|
"Return ONLY the JSON result, no other text.",
|
|
25
25
|
].join("\n");
|
|
26
26
|
}
|
|
27
|
-
// ──
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "application/json",
|
|
38
|
-
Authorization: `Bearer ${webhook_token}`,
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify({
|
|
41
|
-
message: prompt,
|
|
42
|
-
name: `Hub: ${call.skill}`,
|
|
43
|
-
deliver: false, // don't send to messaging channel
|
|
44
|
-
timeoutSeconds: timeoutS,
|
|
45
|
-
}),
|
|
46
|
-
signal: controller.signal,
|
|
47
|
-
});
|
|
48
|
-
clearTimeout(timer);
|
|
49
|
-
if (!resp.ok) {
|
|
50
|
-
const text = await resp.text();
|
|
51
|
-
throw new Error(`Webhook returned ${resp.status}: ${text}`);
|
|
27
|
+
// ── CLI execution (openclaw agent / claude -p) ──
|
|
28
|
+
function runCli(command, prompt, timeoutMs) {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
// Build args based on command
|
|
31
|
+
let args;
|
|
32
|
+
if (command === "openclaw") {
|
|
33
|
+
// openclaw agent --message "..." --local
|
|
34
|
+
args = ["agent", "--message", prompt, "--local"];
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (parsed)
|
|
57
|
-
return parsed;
|
|
58
|
-
// If response is not JSON, wrap as text result
|
|
59
|
-
return { result: text.trim().slice(0, 5000) };
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
clearTimeout(timer);
|
|
63
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
64
|
-
throw new Error(`Webhook timed out after ${timeoutS}s`);
|
|
36
|
+
else {
|
|
37
|
+
// claude -p "..." --output-format json
|
|
38
|
+
args = ["-p", prompt, "--output-format", "json"];
|
|
65
39
|
}
|
|
66
|
-
throw err;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// ── CLI (claude -p) execution — fallback ──
|
|
70
|
-
function executeViaCli(command, prompt, timeoutMs) {
|
|
71
|
-
return new Promise((resolve) => {
|
|
72
|
-
const args = ["-p", prompt, "--output-format", "json"];
|
|
73
40
|
const child = spawn(command, args, {
|
|
74
41
|
stdio: ["ignore", "pipe", "pipe"],
|
|
75
42
|
timeout: timeoutMs,
|
|
@@ -140,7 +107,7 @@ export class Executor {
|
|
|
140
107
|
}
|
|
141
108
|
markProcessed(call.order_id);
|
|
142
109
|
this.activeTasks.add(call.order_id);
|
|
143
|
-
logger.info(`Processing order=${call.order_id} skill="${call.skill}" from=${call.from}
|
|
110
|
+
logger.info(`Processing order=${call.order_id} skill="${call.skill}" from=${call.from}`);
|
|
144
111
|
this.executeTask(call).catch((err) => {
|
|
145
112
|
logger.error(`Unhandled error in executeTask for ${call.order_id}:`, err);
|
|
146
113
|
});
|
|
@@ -153,7 +120,6 @@ export class Executor {
|
|
|
153
120
|
output: {
|
|
154
121
|
echo: call.input,
|
|
155
122
|
provider_status: "ok",
|
|
156
|
-
execution_mode: this.config.provider.execution_mode,
|
|
157
123
|
active_tasks: this.activeTasks.size,
|
|
158
124
|
max_concurrent: this.config.provider.max_concurrent,
|
|
159
125
|
},
|
|
@@ -164,29 +130,23 @@ export class Executor {
|
|
|
164
130
|
try {
|
|
165
131
|
const prompt = buildPrompt(call, this.config);
|
|
166
132
|
const timeoutS = Math.max(call.timeout - TIMEOUT_BUFFER_S, 30);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
logger.error(`CLI failed (code=${exitCode}):`, errMsg);
|
|
180
|
-
this.send({
|
|
181
|
-
event: "deliver",
|
|
182
|
-
order_id: call.order_id,
|
|
183
|
-
error: errMsg.slice(0, 2000),
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const parsed = parseJsonOutput(stdout);
|
|
188
|
-
output = parsed ?? { result: stdout.trim().slice(0, 5000) };
|
|
133
|
+
const command = this.config.provider.cli_command;
|
|
134
|
+
logger.info(`Executing: ${command} for skill="${call.skill}" order=${call.order_id} (timeout=${timeoutS}s)`);
|
|
135
|
+
const { stdout, stderr, exitCode } = await runCli(command, prompt, timeoutS * 1000);
|
|
136
|
+
if (exitCode !== 0) {
|
|
137
|
+
const errMsg = stderr.trim() || `CLI exited with code ${exitCode}`;
|
|
138
|
+
logger.error(`CLI failed (code=${exitCode}):`, errMsg);
|
|
139
|
+
this.send({
|
|
140
|
+
event: "deliver",
|
|
141
|
+
order_id: call.order_id,
|
|
142
|
+
error: errMsg.slice(0, 2000),
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
189
145
|
}
|
|
146
|
+
const parsed = parseJsonOutput(stdout);
|
|
147
|
+
let output = parsed ?? {
|
|
148
|
+
result: stdout.trim().slice(0, 5000),
|
|
149
|
+
};
|
|
190
150
|
// Upload local files to R2 if any
|
|
191
151
|
output = await replaceLocalPaths(output, this.config);
|
|
192
152
|
const sent = this.send({
|
package/dist/hub/provider.js
CHANGED
|
@@ -11,10 +11,7 @@ const CONFIG_DIR = join(homedir(), ".clawmoney");
|
|
|
11
11
|
const CONFIG_FILE = join(CONFIG_DIR, "config.yaml");
|
|
12
12
|
const PID_FILE = join(CONFIG_DIR, "provider.pid");
|
|
13
13
|
const DEFAULT_PROVIDER = {
|
|
14
|
-
|
|
15
|
-
cli_command: "claude",
|
|
16
|
-
webhook_url: "http://127.0.0.1:18789/hooks/agent",
|
|
17
|
-
webhook_token: "",
|
|
14
|
+
cli_command: "openclaw",
|
|
18
15
|
max_concurrent: 3,
|
|
19
16
|
ws_url: "wss://api.bnbot.ai/api/v1/ws/agent",
|
|
20
17
|
api_base_url: "https://api.bnbot.ai/api/v1",
|
|
@@ -75,11 +72,9 @@ function loadProviderConfig(cliCommand) {
|
|
|
75
72
|
process.exit(1);
|
|
76
73
|
}
|
|
77
74
|
const userProvider = (raw.provider ?? {});
|
|
75
|
+
logger.info(`Config raw provider: ${JSON.stringify(raw.provider)}, cliCommand arg: ${cliCommand}`);
|
|
78
76
|
const provider = {
|
|
79
|
-
execution_mode: userProvider.execution_mode ?? DEFAULT_PROVIDER.execution_mode,
|
|
80
77
|
cli_command: cliCommand ?? userProvider.cli_command ?? DEFAULT_PROVIDER.cli_command,
|
|
81
|
-
webhook_url: userProvider.webhook_url ?? DEFAULT_PROVIDER.webhook_url,
|
|
82
|
-
webhook_token: userProvider.webhook_token ?? DEFAULT_PROVIDER.webhook_token,
|
|
83
78
|
max_concurrent: userProvider.max_concurrent ?? DEFAULT_PROVIDER.max_concurrent,
|
|
84
79
|
ws_url: userProvider.ws_url ?? DEFAULT_PROVIDER.ws_url,
|
|
85
80
|
api_base_url: userProvider.api_base_url ?? DEFAULT_PROVIDER.api_base_url,
|
|
@@ -165,8 +160,5 @@ export function runProvider(cliCommand) {
|
|
|
165
160
|
wsClient.start();
|
|
166
161
|
poller.start();
|
|
167
162
|
logger.info("Hub Provider running. Listening for service calls...");
|
|
168
|
-
logger.info(`Config:
|
|
169
|
-
(config.provider.execution_mode === "webhook"
|
|
170
|
-
? `, webhook=${config.provider.webhook_url}`
|
|
171
|
-
: `, cli=${config.provider.cli_command}`));
|
|
163
|
+
logger.info(`Config: cli=${config.provider.cli_command}, max_concurrent=${config.provider.max_concurrent}`);
|
|
172
164
|
}
|
package/dist/hub/types.d.ts
CHANGED
|
@@ -38,10 +38,7 @@ export interface TestResponseEvent {
|
|
|
38
38
|
}
|
|
39
39
|
export type OutgoingEvent = DeliverEvent | TestResponseEvent;
|
|
40
40
|
export interface ProviderSettings {
|
|
41
|
-
execution_mode: "webhook" | "cli";
|
|
42
41
|
cli_command: string;
|
|
43
|
-
webhook_url: string;
|
|
44
|
-
webhook_token: string;
|
|
45
42
|
max_concurrent: number;
|
|
46
43
|
ws_url: string;
|
|
47
44
|
api_base_url: string;
|
package/dist/index.js
CHANGED
package/dist/utils/config.d.ts
CHANGED