aiprox-workflows 1.0.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 (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +186 -0
  3. package/index.d.ts +93 -0
  4. package/index.js +147 -0
  5. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LPX Digital Group LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # aiprox-workflows
2
+
3
+ Create, run, and manage [AIProx](https://aiprox.dev) workflows programmatically. Chain AI agents into multi-step pipelines, schedule them, and get notified by email or webhook. Pay per execution in sats.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install aiprox-workflows
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```javascript
14
+ import AIProxWorkflows from 'aiprox-workflows';
15
+ // or: const { AIProxWorkflows } = require('aiprox-workflows');
16
+
17
+ const workflows = new AIProxWorkflows({ spendToken: 'lnpx_...' });
18
+
19
+ // Create and run a daily news digest
20
+ const wf = await workflows.create({
21
+ name: 'daily-bitcoin-brief',
22
+ steps: [
23
+ { capability: 'web-search', input: 'latest Bitcoin news today' },
24
+ { capability: 'sentiment-analysis', input: '$step1.result' },
25
+ { capability: 'email', input: '$step2.result' },
26
+ ],
27
+ schedule: '@daily',
28
+ notifyEmail: 'you@example.com',
29
+ });
30
+
31
+ await workflows.run(wf.workflow_id);
32
+ ```
33
+
34
+ > Get a spend token at [lightningprox.com](https://lightningprox.com). Or use the env var `AIPROX_SPEND_TOKEN`.
35
+
36
+ ---
37
+
38
+ ## Methods
39
+
40
+ ### `workflows.create(options)`
41
+
42
+ Create a new workflow.
43
+
44
+ ```javascript
45
+ const wf = await workflows.create({
46
+ name: 'daily-intel',
47
+ steps: [
48
+ { capability: 'web-search', input: 'latest AI news' },
49
+ { capability: 'sentiment-analysis', input: '$step1.result' },
50
+ { capability: 'email', input: '$step2.result — deliver to inbox' },
51
+ ],
52
+ schedule: '@daily', // optional: '@hourly' | '@daily' | '@weekly' | cron expr
53
+ notifyEmail: 'you@example.com', // optional
54
+ webhookUrl: 'https://your-site.com/webhook', // optional
55
+ });
56
+ // → { workflow_id: 'wf_...', name: '...', status: 'ready', ... }
57
+ ```
58
+
59
+ **Available capabilities:**
60
+
61
+ | Capability | Agent |
62
+ |---|---|
63
+ | `web-search` | search-bot |
64
+ | `sentiment-analysis` | sentiment-bot |
65
+ | `scraping` | data-spider |
66
+ | `data-analysis` | doc-miner / isitarug |
67
+ | `translation` | polyglot |
68
+ | `vision` | vision-bot |
69
+ | `code-execution` | code-auditor |
70
+ | `email` | email-bot |
71
+ | `market-data` | market-oracle |
72
+
73
+ Use `$step1.result`, `$step2.result` etc. to chain outputs between steps.
74
+
75
+ ---
76
+
77
+ ### `workflows.run(workflowId)`
78
+
79
+ Trigger a workflow immediately.
80
+
81
+ ```javascript
82
+ const receipt = await workflows.run('wf_123456');
83
+ // → { run_id: '...', status: 'running', sats_spent: 120, ... }
84
+ ```
85
+
86
+ ---
87
+
88
+ ### `workflows.list()`
89
+
90
+ List all workflows for your spend token.
91
+
92
+ ```javascript
93
+ const list = await workflows.list();
94
+ list.forEach(w => console.log(w.workflow_id, w.name, w.status));
95
+ ```
96
+
97
+ ---
98
+
99
+ ### `workflows.history(workflowId)`
100
+
101
+ Get run history for a workflow.
102
+
103
+ ```javascript
104
+ const runs = await workflows.history('wf_123456');
105
+ runs.forEach(r => console.log(r.run_id, r.status, r.sats_spent + ' sats'));
106
+ ```
107
+
108
+ ---
109
+
110
+ ### `workflows.delete(workflowId)`
111
+
112
+ Delete a workflow.
113
+
114
+ ```javascript
115
+ await workflows.delete('wf_123456');
116
+ ```
117
+
118
+ ---
119
+
120
+ ## `runWorkflow` — One-shot Helper
121
+
122
+ Create a workflow, run it, and get the receipt in a single call. No workflow ID needed.
123
+
124
+ ```javascript
125
+ import { runWorkflow } from 'aiprox-workflows';
126
+
127
+ const result = await runWorkflow({
128
+ spendToken: 'lnpx_...',
129
+ steps: [
130
+ { capability: 'web-search', input: 'Bitcoin news today' },
131
+ { capability: 'sentiment-analysis', input: '$step1.result' },
132
+ ],
133
+ });
134
+
135
+ console.log(result.status); // 'completed'
136
+ console.log(result.sats_spent); // 145
137
+ console.log(result.result); // final output text
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Pre-built Templates
143
+
144
+ Not sure where to start? Browse [aiprox.dev/templates](https://aiprox.dev/templates) for pre-built pipelines:
145
+
146
+ - ⚡ **Daily Bitcoin News Digest** — search → sentiment → email (~150 sats/run)
147
+ - 🔍 **Token Safety Scanner** — scrape → analyze → email (~120 sats/run)
148
+ - 📊 **Competitive Intelligence Brief** — search → mine → sentiment → email (~200 sats/run)
149
+ - 🌍 **Multilingual Content Pipeline** — scrape → summarize → translate (~180 sats/run)
150
+ - 👁️ **Visual Site Audit** — vision → audit → report (~220 sats/run)
151
+ - 📈 **Polymarket Signal Digest** — market → sentiment → email (~160 sats/run)
152
+
153
+ ---
154
+
155
+ ## Dashboard
156
+
157
+ Manage, monitor, and schedule workflows visually at [aiprox.dev/workflows](https://aiprox.dev/workflows).
158
+
159
+ ---
160
+
161
+ ## Auth
162
+
163
+ Pass your spend token via constructor option or env var:
164
+
165
+ ```javascript
166
+ // Option 1: constructor
167
+ const workflows = new AIProxWorkflows({ spendToken: process.env.AIPROX_SPEND_TOKEN });
168
+
169
+ // Option 2: env var (in your shell)
170
+ // export AIPROX_SPEND_TOKEN=lnpx_...
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Pricing
176
+
177
+ ~50–220 sats per workflow run depending on agents used and steps count. No monthly fee. Pay only for what runs.
178
+
179
+ ---
180
+
181
+ ## Links
182
+
183
+ - Dashboard: [aiprox.dev/workflows](https://aiprox.dev/workflows)
184
+ - Templates: [aiprox.dev/templates](https://aiprox.dev/templates)
185
+ - Registry: [aiprox.dev/registry.html](https://aiprox.dev/registry.html)
186
+ - Spend tokens: [lightningprox.com](https://lightningprox.com)
package/index.d.ts ADDED
@@ -0,0 +1,93 @@
1
+ export interface WorkflowStep {
2
+ /** Agent capability to invoke (e.g. 'web-search', 'sentiment-analysis', 'email') */
3
+ capability: string;
4
+ /** Input text or task. Use $step1.result to chain from previous steps */
5
+ input: string;
6
+ }
7
+
8
+ export interface CreateWorkflowOptions {
9
+ /** Workflow name */
10
+ name: string;
11
+ /** Ordered list of agent steps */
12
+ steps: WorkflowStep[];
13
+ /** Cron schedule or shorthand: '@hourly', '@daily', '@weekly', '0 9 * * *' */
14
+ schedule?: string;
15
+ /** Email address to notify after each run */
16
+ notifyEmail?: string;
17
+ /** Webhook URL to POST results to after each run */
18
+ webhookUrl?: string;
19
+ }
20
+
21
+ export interface WorkflowReceipt {
22
+ workflow_id?: string;
23
+ id?: string;
24
+ run_id?: string;
25
+ status: string;
26
+ sats_spent?: number;
27
+ agents_used?: string[];
28
+ result?: string;
29
+ steps?: Array<{
30
+ step: number;
31
+ capability: string;
32
+ agent?: string;
33
+ duration_ms?: number;
34
+ success: boolean;
35
+ }>;
36
+ [key: string]: unknown;
37
+ }
38
+
39
+ export interface WorkflowSummary {
40
+ workflow_id: string;
41
+ name: string;
42
+ steps_count: number;
43
+ schedule?: string;
44
+ status: string;
45
+ last_run_at?: string;
46
+ next_run_at?: string;
47
+ [key: string]: unknown;
48
+ }
49
+
50
+ export interface RunWorkflowOptions {
51
+ /** AIProx / LightningProx spend token */
52
+ spendToken: string;
53
+ /** Ordered list of agent steps */
54
+ steps: WorkflowStep[];
55
+ /** Email address to notify after each run */
56
+ notifyEmail?: string;
57
+ /** Webhook URL to POST results to */
58
+ webhookUrl?: string;
59
+ }
60
+
61
+ export interface ClientOptions {
62
+ /** AIProx / LightningProx spend token (lnpx_...) */
63
+ spendToken: string;
64
+ /** Override base URL. Default: https://aiprox.dev */
65
+ baseURL?: string;
66
+ }
67
+
68
+ export declare class AIProxWorkflows {
69
+ constructor(options: ClientOptions);
70
+
71
+ /** Create a new workflow */
72
+ create(options: CreateWorkflowOptions): Promise<WorkflowSummary>;
73
+
74
+ /** Trigger a workflow by ID */
75
+ run(workflowId: string): Promise<WorkflowReceipt>;
76
+
77
+ /** List all workflows for this spend token */
78
+ list(): Promise<WorkflowSummary[]>;
79
+
80
+ /** Get run history for a workflow */
81
+ history(workflowId: string): Promise<WorkflowReceipt[]>;
82
+
83
+ /** Delete a workflow by ID */
84
+ delete(workflowId: string): Promise<{ deleted: boolean }>;
85
+ }
86
+
87
+ /**
88
+ * One-shot helper: create a workflow, run it, return the receipt.
89
+ * No workflow ID needed — handles create + run in one call.
90
+ */
91
+ export declare function runWorkflow(options: RunWorkflowOptions): Promise<WorkflowReceipt>;
92
+
93
+ export { AIProxWorkflows as default };
package/index.js ADDED
@@ -0,0 +1,147 @@
1
+ 'use strict';
2
+
3
+ // Node 18+ has native fetch. No external dependencies needed.
4
+ const AIPROX_URL = 'https://aiprox.dev';
5
+
6
+ class AIProxWorkflows {
7
+ constructor({ spendToken, baseURL = AIPROX_URL } = {}) {
8
+ if (!spendToken) {
9
+ throw new Error(
10
+ 'AIProx spend token required. ' +
11
+ 'Pass spendToken: "lnpx_..." or set AIPROX_SPEND_TOKEN env var. ' +
12
+ 'Get a token at lightningprox.com'
13
+ );
14
+ }
15
+ this.spendToken = spendToken;
16
+ this.baseURL = baseURL.replace(/\/$/, '');
17
+ }
18
+
19
+ // ── Create a workflow ──────────────────────────────────────────────────────
20
+ async create({ name, steps, schedule, notifyEmail, webhookUrl } = {}) {
21
+ if (!name) throw new Error('name is required');
22
+ if (!steps || !steps.length) throw new Error('steps array is required');
23
+
24
+ const payload = {
25
+ name,
26
+ spend_token: this.spendToken,
27
+ steps: steps.map((s, i) => ({
28
+ step: i + 1,
29
+ capability: s.capability,
30
+ input: s.input,
31
+ })),
32
+ };
33
+ if (schedule) payload.schedule = schedule;
34
+ if (notifyEmail) payload.notify_email = notifyEmail;
35
+ if (webhookUrl) payload.webhook_url = webhookUrl;
36
+
37
+ const res = await this._post('/api/workflows', payload);
38
+ return res;
39
+ }
40
+
41
+ // ── Run a workflow ─────────────────────────────────────────────────────────
42
+ async run(workflowId) {
43
+ if (!workflowId) throw new Error('workflowId is required');
44
+ const res = await this._post(`/api/workflows/${workflowId}/run`, {
45
+ spend_token: this.spendToken,
46
+ });
47
+ return res;
48
+ }
49
+
50
+ // ── List workflows ─────────────────────────────────────────────────────────
51
+ async list() {
52
+ const res = await this._get('/api/workflows');
53
+ return res.workflows || res;
54
+ }
55
+
56
+ // ── Get run history ────────────────────────────────────────────────────────
57
+ async history(workflowId) {
58
+ if (!workflowId) throw new Error('workflowId is required');
59
+ const res = await this._get(`/api/workflows/${workflowId}/runs`);
60
+ return res.runs || res;
61
+ }
62
+
63
+ // ── Delete a workflow ──────────────────────────────────────────────────────
64
+ async delete(workflowId) {
65
+ if (!workflowId) throw new Error('workflowId is required');
66
+ const res = await fetch(`${this.baseURL}/api/workflows/${workflowId}`, {
67
+ method: 'DELETE',
68
+ headers: {
69
+ 'Content-Type': 'application/json',
70
+ 'X-Spend-Token': this.spendToken,
71
+ },
72
+ });
73
+ if (!res.ok) await this._handleError(res);
74
+ return res.json();
75
+ }
76
+
77
+ // ── Internal helpers ───────────────────────────────────────────────────────
78
+ async _post(path, body) {
79
+ const res = await fetch(`${this.baseURL}${path}`, {
80
+ method: 'POST',
81
+ headers: {
82
+ 'Content-Type': 'application/json',
83
+ 'X-Spend-Token': this.spendToken,
84
+ },
85
+ body: JSON.stringify(body),
86
+ });
87
+ if (!res.ok) await this._handleError(res);
88
+ return res.json();
89
+ }
90
+
91
+ async _get(path) {
92
+ const res = await fetch(`${this.baseURL}${path}`, {
93
+ headers: {
94
+ 'X-Spend-Token': this.spendToken,
95
+ },
96
+ });
97
+ if (!res.ok) await this._handleError(res);
98
+ return res.json();
99
+ }
100
+
101
+ async _handleError(res) {
102
+ let body = '';
103
+ try { body = await res.text(); } catch {}
104
+ let parsed;
105
+ try { parsed = JSON.parse(body); } catch { parsed = null; }
106
+ const msg = parsed?.error || parsed?.message || body || 'Unknown error';
107
+
108
+ if (res.status === 402) {
109
+ const err = new Error(`Insufficient balance — top up at lightningprox.com. (${msg})`);
110
+ err.status = 402;
111
+ err.code = 'insufficient_balance';
112
+ throw err;
113
+ }
114
+ if (res.status === 401) {
115
+ const err = new Error(`Invalid spend token. Get one at lightningprox.com. (${msg})`);
116
+ err.status = 401;
117
+ err.code = 'invalid_token';
118
+ throw err;
119
+ }
120
+ const err = new Error(`AIProx error ${res.status}: ${msg}`);
121
+ err.status = res.status;
122
+ throw err;
123
+ }
124
+ }
125
+
126
+ // ── runWorkflow helper ─────────────────────────────────────────────────────────
127
+ // One-shot: create an anonymous workflow, run it, and return the receipt.
128
+ async function runWorkflow({ spendToken, steps, notifyEmail, webhookUrl } = {}) {
129
+ if (!spendToken) throw new Error('spendToken is required');
130
+ if (!steps || !steps.length) throw new Error('steps is required');
131
+
132
+ const name = `run-${Date.now()}`;
133
+ const wf = new AIProxWorkflows({ spendToken });
134
+
135
+ const created = await wf.create({ name, steps, notifyEmail, webhookUrl });
136
+ const workflowId = created.workflow_id || created.id;
137
+ if (!workflowId) throw new Error('Failed to create workflow: no ID returned');
138
+
139
+ const runResult = await wf.run(workflowId);
140
+ return runResult;
141
+ }
142
+
143
+ // All export styles for maximum compatibility
144
+ module.exports = AIProxWorkflows;
145
+ module.exports.default = AIProxWorkflows;
146
+ module.exports.AIProxWorkflows = AIProxWorkflows;
147
+ module.exports.runWorkflow = runWorkflow;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "aiprox-workflows",
3
+ "version": "1.0.0",
4
+ "description": "Create, run, and manage AIProx workflows programmatically",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "keywords": [
8
+ "aiprox",
9
+ "workflows",
10
+ "agents",
11
+ "ai",
12
+ "automation",
13
+ "bitcoin",
14
+ "lightning",
15
+ "sats",
16
+ "multi-agent",
17
+ "orchestration",
18
+ "pipeline"
19
+ ],
20
+ "author": "LPX Digital Group LLC",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/solanaprox/aiprox-workflows"
25
+ },
26
+ "homepage": "https://aiprox.dev/workflows",
27
+ "bugs": {
28
+ "url": "https://github.com/solanaprox/aiprox-workflows/issues"
29
+ },
30
+ "dependencies": {},
31
+ "engines": {
32
+ "node": ">=18.0.0"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "index.d.ts",
37
+ "README.md",
38
+ "LICENSE"
39
+ ]
40
+ }