agent402-client 0.1.0 → 0.2.1

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.
Files changed (3) hide show
  1. package/README.md +18 -0
  2. package/index.js +26 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,12 +47,30 @@ const a = new Agent402({ fetch: payFetch });
47
47
  const article = await a.call("extract", { url: "https://example.com/article" });
48
48
  ```
49
49
 
50
+ ## Workflows (skill packs)
51
+
52
+ For jobs that no single tool covers — e.g. "audit a domain", "build a stock
53
+ brief" — Agent402 ships curated multi-tool **skill packs**: 5–7 catalog tools
54
+ composed into a Claude-ready task template. Discover them the same way you'd
55
+ discover a tool:
56
+
57
+ ```js
58
+ const packs = await a.findWorkflows("security audit");
59
+ // → [{ slug: "security-audit", title, tagline, toolSlugs, score, url, promptName }]
60
+
61
+ // Render the full prompt with arguments substituted in (same output as MCP prompts/get).
62
+ const { messages } = await a.getWorkflowPrompt("security-audit", { domain: "stripe.com" });
63
+ // → feed messages straight to any LLM
64
+ ```
65
+
50
66
  ## API
51
67
 
52
68
  | Method | What |
53
69
  |---|---|
54
70
  | `new Agent402({ baseUrl?, fetch?, cache?, fetchImpl? })` | `fetch` is your x402-wrapped fetch for paid tools (optional); `cache` (default `true`) memoizes deterministic results |
55
71
  | `await a.find(task, { k = 5 })` | Resolve a plain-language task to the best-matching tools (route, price, schema, example) |
72
+ | `await a.findWorkflows(task, { k = 2 })` | Resolve a task to matching multi-tool workflow templates (skill packs) |
73
+ | `await a.getWorkflowPrompt(slug, args)` | Fetch the rendered prompt messages for a skill pack with arguments substituted in |
56
74
  | `await a.call(slug, params, { idempotencyKey?, cache? })` | Call a tool; auto-pays (PoW for free tools, x402 for wallet-only); returns the JSON result |
57
75
  | `Agent402.solvePow(pow)` | Solve a proof-of-work challenge object → an `X-Pow-Solution` value |
58
76
  | `a.clearCache()` | Drop the in-memory result cache |
package/index.js CHANGED
@@ -51,6 +51,32 @@ export class Agent402 {
51
51
  return (await r.json()).results || [];
52
52
  }
53
53
 
54
+ /**
55
+ * Resolve a task to matching multi-tool workflow templates (skill packs).
56
+ * Each pack composes 5–7 catalog tools into a Claude-ready task template
57
+ * for jobs that no single tool covers (e.g. audit a domain). Returns
58
+ * `[{slug, title, tagline, toolSlugs, score, url, promptName}]` (possibly
59
+ * empty when the lexical signal is weak). Use `getWorkflowPrompt(slug, args)`
60
+ * to fetch the rendered prompt messages, or hand the slug to an MCP client.
61
+ */
62
+ async findWorkflows(task, { k = 2 } = {}) {
63
+ const r = await this.f(`${this.baseUrl}/api/find?q=${encodeURIComponent(task)}&k=${k}`);
64
+ if (!r.ok) throw new Error(`findWorkflows failed: HTTP ${r.status}`);
65
+ return (await r.json()).packs || [];
66
+ }
67
+
68
+ /**
69
+ * Fetch the rendered prompt messages for a skill pack with arguments
70
+ * substituted in. Same output as MCP `prompts/get` — usable directly with
71
+ * any LLM. `args` are passed by promptArg name (see /api/skill-packs.json).
72
+ */
73
+ async getWorkflowPrompt(slug, args = {}) {
74
+ const qs = new URLSearchParams(Object.entries(args).map(([k, v]) => [k, String(v)])).toString();
75
+ const r = await this.f(`${this.baseUrl}/api/skill-packs/${encodeURIComponent(slug)}/prompt${qs ? `?${qs}` : ""}`);
76
+ if (!r.ok) throw new Error(`getWorkflowPrompt("${slug}") failed: HTTP ${r.status}`);
77
+ return r.json();
78
+ }
79
+
54
80
  /** Solve a proof-of-work challenge object (from a 402 body) into an X-Pow-Solution value. */
55
81
  static solvePow(pow) {
56
82
  let n = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent402-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Tiny buyer-side client for Agent402 (x402): resolve a task to a tool and call it with payment handled for you — free tools settle via built-in proof-of-work (no wallet), wallet-only tools via your x402 fetch. Caching + idempotent retries.",
5
5
  "type": "module",
6
6
  "main": "index.js",