agent402-client 0.1.0 → 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.
Files changed (2) hide show
  1. package/index.js +26 -0
  2. package/package.json +1 -1
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.0",
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",