@clawcash/forge 0.1.8 → 0.2.0
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/README.md +38 -45
- package/dist/index.cjs +320 -562
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -171
- package/dist/index.d.ts +75 -171
- package/dist/index.js +305 -549
- package/dist/index.js.map +1 -1
- package/package.json +2 -12
package/README.md
CHANGED
|
@@ -2,83 +2,76 @@
|
|
|
2
2
|
|
|
3
3
|
The fastest way to make an **existing** SaaS/API app agent-native.
|
|
4
4
|
|
|
5
|
-
Define a
|
|
5
|
+
Define a paid action on top of your backend and run an outbound worker that fulfills jobs from the ClawCash gateway. Agents discover, pay (x402/USDC), and call **the gateway** — your app adds no routes, no middleware, and no public agent surface. **Zero runtime dependencies.**
|
|
6
6
|
|
|
7
7
|
Published under the [ClawCash](https://www.npmjs.com/org/clawcash) npm org.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```text
|
|
10
|
+
agent -> gateway.clawca.sh/<handle>/<action> (x402)
|
|
11
|
+
| job queued
|
|
12
|
+
worker -> claims job (outbound long-poll), runs execute(), posts result
|
|
13
|
+
|
|
|
14
|
+
agent <- result, same request
|
|
15
|
+
```
|
|
10
16
|
|
|
11
17
|
## Install
|
|
12
18
|
|
|
13
19
|
```bash
|
|
14
|
-
npm install @clawcash/forge
|
|
20
|
+
npm install @clawcash/forge
|
|
15
21
|
```
|
|
16
22
|
|
|
17
|
-
## Quick start (
|
|
23
|
+
## Quick start (worker mode — the default)
|
|
24
|
+
|
|
25
|
+
One self-contained file. Your web server is not touched.
|
|
18
26
|
|
|
19
27
|
```ts
|
|
20
|
-
|
|
21
|
-
import { defineAgentService,
|
|
28
|
+
// src/forge/agent-worker.ts
|
|
29
|
+
import { defineAgentService, forgeWorker } from "@clawcash/forge";
|
|
22
30
|
|
|
23
31
|
const removeBackground = defineAgentService({
|
|
24
32
|
name: "remove_background",
|
|
25
33
|
description: "Remove the background from an image.",
|
|
26
34
|
input: { imageUrl: "url" },
|
|
27
35
|
output: { resultUrl: "url" },
|
|
28
|
-
payment: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const app = express();
|
|
39
|
-
app.use(express.json());
|
|
40
|
-
|
|
41
|
-
await mountAgentServices(app, [removeBackground], {
|
|
42
|
-
// Baked in by Forge PR — works with zero host env for payments
|
|
43
|
-
payToFallback: "0xYourForgeWallet",
|
|
44
|
-
forge: {
|
|
45
|
-
owner: "acme",
|
|
46
|
-
repo: "my-app",
|
|
47
|
-
baseUrl: process.env.FORGE_URL ?? "https://forge.clawca.sh",
|
|
36
|
+
payment: { amount: "0.10", currency: "USDC", protocols: ["x402"] },
|
|
37
|
+
async execute({ imageUrl }) {
|
|
38
|
+
// call the API your product already has — loopback, hosted, or direct import
|
|
39
|
+
const res = await fetch("http://127.0.0.1:3000/api/remove", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "content-type": "application/json" },
|
|
42
|
+
body: JSON.stringify({ imageUrl }),
|
|
43
|
+
});
|
|
44
|
+
const data = await res.json();
|
|
45
|
+
return { resultUrl: data.resultUrl };
|
|
48
46
|
},
|
|
49
|
-
gateway: { handle: "my-app" },
|
|
50
47
|
});
|
|
51
48
|
|
|
52
|
-
app
|
|
49
|
+
forgeWorker({ services: [removeBackground], handle: "my-app" });
|
|
53
50
|
```
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
- **Handle** — baked into the mount options by Forge codegen (`FORGE_HANDLE` to override).
|
|
60
|
-
- **Public base URL** — `PUBLIC_BASE_URL` env → platform vars (Railway, Render, Vercel, Fly, Heroku) → inferred from the first inbound probe and self-verified (the SDK fetches its own `/forge/health` at the candidate URL and checks the per-boot instance nonce before trusting it).
|
|
52
|
+
```bash
|
|
53
|
+
FORGE_API_KEY=fk_live_... node --import tsx src/forge/agent-worker.ts
|
|
54
|
+
# [forge-worker] my-app polling https://gateway.clawca.sh/jobs/claim ...
|
|
55
|
+
```
|
|
61
56
|
|
|
62
|
-
|
|
57
|
+
Env: `FORGE_API_KEY` (required, from the Forge dashboard), `FORGE_HANDLE` (if not passed as an option), `GATEWAY_URL` (optional override).
|
|
63
58
|
|
|
64
|
-
|
|
59
|
+
The worker makes outbound requests only. It runs behind NAT, on localhost, in a private subnet — anywhere with outbound HTTPS. Polling doubles as the merchant heartbeat.
|
|
65
60
|
|
|
66
|
-
-
|
|
67
|
-
- `GET /forge/status` — readiness (`ready` needs fulfill secret + public URL + actions)
|
|
68
|
-
- `GET /.well-known/clawcash.json` — discovery
|
|
61
|
+
## Fetch-handler mode (inbound alternative)
|
|
69
62
|
|
|
70
|
-
|
|
63
|
+
For gateway-push deployments, `createForgeHandler(services)` returns a web-standard `(Request) => Promise<Response>` serving `/forge/health`, `/forge/status`, `/.well-known/clawcash.json`, and `POST /forge/fulfill/{action}` (gated by `FORGE_API_KEY`). Mounts natively in Next.js route handlers, Hono, Bun, Deno; `createForgeRequestMatcher` returns `null` on unmatched routes for fall-through mounting.
|
|
71
64
|
|
|
72
65
|
## API
|
|
73
66
|
|
|
74
67
|
| Export | Purpose |
|
|
75
68
|
|--------|---------|
|
|
76
69
|
| `defineAgentService` | Declare name, schemas, payment, and `execute` |
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `waitUntil` / `context.waitUntil` | Poll until a job completes |
|
|
81
|
-
| `
|
|
70
|
+
| `forgeWorker` | Outbound worker: claim paid jobs, execute, report results |
|
|
71
|
+
| `createForgeHandler` / `createForgeRequestMatcher` | Web-standard inbound fulfillment surface |
|
|
72
|
+
| `validateInput` / `checkType` | Schema validation |
|
|
73
|
+
| `waitUntil` / `context.waitUntil` | Poll until a job completes inside `execute` |
|
|
74
|
+
| `getForgeApiKey` / `forgeGatewayLoopbackHeaders` | Auth helpers for fulfillment traffic |
|
|
82
75
|
|
|
83
76
|
## Build
|
|
84
77
|
|