clawmoney 0.9.2 → 0.9.3
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 +21 -9
- package/package.json +1 -1
package/dist/commands/hub.js
CHANGED
|
@@ -4,7 +4,7 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import { requireConfig } from "../utils/config.js";
|
|
7
|
-
import { apiGet, apiPost
|
|
7
|
+
import { apiGet, apiPost } from "../utils/api.js";
|
|
8
8
|
import { awalExec } from "../utils/awal.js";
|
|
9
9
|
import { readPid, isPidAlive, removePid } from "../hub/provider.js";
|
|
10
10
|
const LOG_FILE = join(homedir(), ".clawmoney", "provider.log");
|
|
@@ -157,10 +157,15 @@ export async function hubCallCommand(options) {
|
|
|
157
157
|
const spinner = ora(`Calling ${options.agent}/${options.skill}...`).start();
|
|
158
158
|
try {
|
|
159
159
|
if (options.pay) {
|
|
160
|
-
// x402 payment
|
|
161
|
-
// Step 1:
|
|
162
|
-
spinner.text = `
|
|
163
|
-
const
|
|
160
|
+
// x402 payment flow via pay.clawmoney.ai Worker
|
|
161
|
+
// Step 1: Look up skill price
|
|
162
|
+
spinner.text = `Looking up price for ${options.agent}/${options.skill}...`;
|
|
163
|
+
const searchResp = await apiGet(`/api/v1/hub/skills/search?q=${encodeURIComponent(options.skill)}&agent_slug=${encodeURIComponent(options.agent)}&limit=1`);
|
|
164
|
+
const skills = searchResp.data?.data ?? [];
|
|
165
|
+
const skillPrice = skills[0]?.price ?? 0.01;
|
|
166
|
+
// Step 2: Pay via awal x402 → pay.clawmoney.ai Worker
|
|
167
|
+
spinner.text = `Paying $${skillPrice} USDC for ${options.agent}/${options.skill}...`;
|
|
168
|
+
const payUrl = `https://pay.clawmoney.ai/hub/${encodeURIComponent(options.agent)}/${encodeURIComponent(options.skill)}?price=${skillPrice}`;
|
|
164
169
|
let payResult;
|
|
165
170
|
try {
|
|
166
171
|
payResult = await awalExec(["x402", "pay", payUrl]);
|
|
@@ -169,13 +174,21 @@ export async function hubCallCommand(options) {
|
|
|
169
174
|
spinner.fail(chalk.red(`Payment failed: ${err.message}`));
|
|
170
175
|
process.exit(1);
|
|
171
176
|
}
|
|
172
|
-
//
|
|
177
|
+
// Extract payment_token from Worker response
|
|
178
|
+
const paymentToken = payResult.data?.payment_token;
|
|
179
|
+
if (!paymentToken) {
|
|
180
|
+
spinner.fail(chalk.red("Payment succeeded but no payment_token returned"));
|
|
181
|
+
console.error(chalk.dim(` Raw response: ${JSON.stringify(payResult.data).slice(0, 200)}`));
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
// Step 3: Invoke with payment_token
|
|
173
185
|
spinner.text = `Executing ${options.agent}/${options.skill}...`;
|
|
174
186
|
const qs = new URLSearchParams({
|
|
175
187
|
agent_id: options.agent,
|
|
176
188
|
skill: options.skill,
|
|
177
189
|
timeout: String(timeout),
|
|
178
|
-
payment_method: "
|
|
190
|
+
payment_method: "x402",
|
|
191
|
+
payment_token: paymentToken,
|
|
179
192
|
});
|
|
180
193
|
const resp = await apiPost(`/api/v1/hub/gateway/invoke?${qs}`, inputData, config.api_key);
|
|
181
194
|
if (!resp.ok) {
|
|
@@ -191,8 +204,7 @@ export async function hubCallCommand(options) {
|
|
|
191
204
|
console.log("");
|
|
192
205
|
console.log(` ${chalk.bold("Order:")} ${result.id ?? "-"}`);
|
|
193
206
|
console.log(` ${chalk.bold("Duration:")} ${typeof result.duration === "number" ? result.duration.toFixed(1) + "s" : "-"}`);
|
|
194
|
-
console.log(` ${chalk.bold("Cost:")} $${
|
|
195
|
-
console.log(` ${chalk.bold("Payment:")} ${JSON.stringify(payResult.data).slice(0, 100)}`);
|
|
207
|
+
console.log(` ${chalk.bold("Cost:")} $${skillPrice} USDC`);
|
|
196
208
|
console.log("");
|
|
197
209
|
console.log(chalk.bold(" Output:"));
|
|
198
210
|
console.log(chalk.cyan(" " + JSON.stringify(result.output_data ?? result.output ?? {}, null, 2).replace(/\n/g, "\n ")));
|