@clawcash/forge 0.1.7 → 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 CHANGED
@@ -2,77 +2,76 @@
2
2
 
3
3
  The fastest way to make an **existing** SaaS/API app agent-native.
4
4
 
5
- Define a high-level agent action on top of your backend, mount Express routes, attach x402, and register with the ClawCash gateway. Humans keep the same product; agents get a paid one-shot.
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
- **Stack note:** `defineAgentService` / payTo / heartbeat are framework-agnostic. `mountAgentServices` is the **Express** adapter today. Next/Nest ship later as thin adapters (`@clawcash/forge/next`, etc.) — not one mega environment-agnostic package. A separate greenfield “build agent-native apps” SDK is a future product, not this one.
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 express
20
+ npm install @clawcash/forge
15
21
  ```
16
22
 
17
- ## Quick start (no PAY_TO env required)
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
- import express from "express";
21
- import { defineAgentService, mountAgentServices } from "@clawcash/forge";
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
- amount: "0.10",
30
- currency: "USDC",
31
- protocols: ["x402"],
32
- },
33
- async execute({ imageUrl }, context) {
34
- return { resultUrl: "https://example.com/out.png" };
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 };
35
46
  },
36
47
  });
37
48
 
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",
48
- },
49
- });
50
-
51
- app.listen(3000);
49
+ forgeWorker({ services: [removeBackground], handle: "my-app" });
52
50
  ```
53
51
 
54
- Resolution order: `PAY_TO` env (optional override) → live Forge API → `payToFallback`.
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
+ ```
55
56
 
56
- Agents call `POST /agent/remove-background` and pay via x402 when challenged with HTTP 402.
57
+ Env: `FORGE_API_KEY` (required, from the Forge dashboard), `FORGE_HANDLE` (if not passed as an option), `GATEWAY_URL` (optional override).
57
58
 
58
- After mount, the merchant also exposes liveliness probes:
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.
59
60
 
60
- - `GET /forge/health` — process up + Forge mounted
61
- - `GET /forge/status` — readiness (`ready` needs fulfill secret + public URL + actions)
62
- - `GET /.well-known/clawcash.json` — discovery
61
+ ## Fetch-handler mode (inbound alternative)
63
62
 
64
- Default payment network is **Base mainnet** (`eip155:8453`) via the public **XPay** facilitator (`https://facilitator.xpay.sh`) no API keys.
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.
65
64
 
66
65
  ## API
67
66
 
68
67
  | Export | Purpose |
69
68
  |--------|---------|
70
69
  | `defineAgentService` | Declare name, schemas, payment, and `execute` |
71
- | `mountAgentServices` | Async mount agent + fulfill + health/status routes |
72
- | `resolvePayTo` | Resolve merchant wallet (env Forge → fallback) |
73
- | `generateSkillMarkdown` | Build a `SKILL.md` for agents |
74
- | `waitUntil` / `context.waitUntil` | Poll until a job completes |
75
- | `heartbeatGateway` | Push live base URL to the ClawCash gateway |
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 |
76
75
 
77
76
  ## Build
78
77