@cascadeflow/n8n-nodes-cascadeflow 0.4.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 ADDED
@@ -0,0 +1,357 @@
1
+ <div align="center">
2
+
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="../../../.github/assets/CF_logo_bright.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="../../../.github/assets/CF_logo_dark.svg">
6
+ <img alt="cascadeflow Logo" src="../../../.github/assets/CF_logo_dark.svg" width="533">
7
+ </picture>
8
+
9
+ # n8n-nodes-cascadeflow
10
+
11
+ [![npm version](https://img.shields.io/npm/v/n8n-nodes-cascadeflow?color=red&label=npm)](https://www.npmjs.com/package/n8n-nodes-cascadeflow)
12
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](../../../LICENSE)
13
+ [![n8n](https://img.shields.io/badge/n8n-1.0+-orange.svg)](https://n8n.io/)
14
+
15
+ **<img src="../../../.github/assets/CF_n8n_color.svg" width="22" height="22" alt="n8n" style="vertical-align: middle;"/> n8n community node for cascadeflow**
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ **Intelligent AI model cascading for n8n workflows.**
22
+
23
+ This is an n8n community node that brings cascadeflow's intelligent AI model cascading to n8n workflows.
24
+
25
+ **cascadeflow** reduces LLM API costs by 40-85% by trying a cheap model first, validating quality, and only escalating to expensive models when needed.
26
+
27
+ [n8n](https://n8n.io/) is a fair-code licensed workflow automation platform.
28
+
29
+ ## Installation
30
+
31
+ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.
32
+
33
+ ### Community Nodes (Recommended)
34
+
35
+ 1. Go to **Settings** > **Community Nodes**
36
+ 2. Select **Install**
37
+ 3. Enter `n8n-nodes-cascadeflow` in **Enter npm package name**
38
+ 4. Agree to the risks and install
39
+
40
+ ### Manual installation
41
+
42
+ To get started install the package in your n8n root directory:
43
+
44
+ ```bash
45
+ npm install n8n-nodes-cascadeflow
46
+ ```
47
+
48
+ For Docker-based deployments add the following line before the font installation command in your [n8n Dockerfile](https://github.com/n8n-io/n8n/blob/master/docker/images/n8n/Dockerfile):
49
+
50
+ ```dockerfile
51
+ RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-cascadeflow
52
+ ```
53
+
54
+ ## Operations
55
+
56
+ The cascadeflow node supports these operations:
57
+
58
+ ### Generate Text
59
+
60
+ Generate AI responses with intelligent cascading between draft and verifier models.
61
+
62
+ **How it works:**
63
+ 1. Sends query to cheap draft model (e.g., Claude-3.5-Haiku or GPT-4o-mini)
64
+ 2. Validates quality automatically
65
+ 3. If quality passes → return draft (fast + cheap) ✅
66
+ 4. If quality fails → escalate to verifier model (e.g., GPT-5) ⚠️
67
+
68
+ **Result:** 70-80% of queries accept the draft, saving 40-85% on costs.
69
+
70
+ ### Generate with Tools
71
+
72
+ Same cascading logic but with tool calling support for function-based AI.
73
+
74
+ ## Configuration
75
+
76
+ ### Credentials
77
+
78
+ The node requires a cascadeflow API credential with API keys for the providers you want to use:
79
+
80
+ - **OpenAI API Key** - For GPT models
81
+ - **Anthropic API Key** - For Claude models
82
+ - **Groq API Key** - For fast Llama inference
83
+ - **Together AI API Key** - For open-source models
84
+ - **HuggingFace API Key** - For HuggingFace models
85
+
86
+ You only need to provide keys for the providers you're actually using.
87
+
88
+ ### Node Parameters
89
+
90
+ #### Required Parameters
91
+
92
+ - **Message**: The query or prompt to send to AI
93
+ - **Draft Model**: Configuration for the cheap model
94
+ - Provider (OpenAI, Anthropic, Groq, etc.)
95
+ - Model name (e.g., `claude-3-5-haiku-20241022`, `gpt-4o-mini`)
96
+ - Cost per 1K tokens
97
+ - **Verifier Model**: Configuration for the expensive model
98
+ - Provider
99
+ - Model name (e.g., `gpt-5`, `claude-3-5-sonnet-20241022`)
100
+ - Cost per 1K tokens
101
+
102
+ #### Optional Parameters
103
+
104
+ - **Quality Settings**
105
+ - Quality Threshold (0-1): Minimum score to accept draft
106
+ - Require Validation: Whether to validate before accepting
107
+ - **Advanced Options**
108
+ - Max Tokens: Maximum tokens to generate
109
+ - Temperature: Sampling temperature (0-2)
110
+ - System Prompt: Optional system instructions
111
+ - **Output Mode**: What data to return
112
+ - Full Metrics: All cascade diagnostics
113
+ - Content Only: Just the AI response
114
+ - Metrics Summary: Response + key metrics
115
+
116
+ ## Example Workflows
117
+
118
+ ### Basic Chat
119
+
120
+ ```
121
+ Input: "What is TypeScript?"
122
+
123
+ cascadeflow Node:
124
+ Draft: gpt-4o-mini ($0.00015)
125
+ Verifier: gpt-5 ($0.00125)
126
+
127
+ Output:
128
+ content: "TypeScript is a superset of JavaScript..."
129
+ modelUsed: "gpt-4o-mini"
130
+ totalCost: 0.000211
131
+ savingsPercentage: 83.2%
132
+ draftAccepted: true
133
+ ```
134
+
135
+ ### Customer Support
136
+
137
+ ```
138
+ Trigger: Webhook (customer question)
139
+
140
+ cascadeflow Node (draft: claude-3-haiku, verifier: claude-3-sonnet)
141
+
142
+ IF Node (check if escalated)
143
+ ├─ Yes → Send to human support
144
+ └─ No → Send automated response
145
+ ```
146
+
147
+ ### Content Generation
148
+
149
+ ```
150
+ Schedule: Daily at 9am
151
+
152
+ Code Node: Generate topic ideas
153
+
154
+ cascadeflow Node: Generate blog post
155
+
156
+ cascadeflow Node: Proofread and edit
157
+
158
+ Notion Node: Save to content calendar
159
+ ```
160
+
161
+ ### Tool Calling
162
+
163
+ ```
164
+ cascadeflow Node (Generate with Tools):
165
+ Message: "What's the weather in Paris?"
166
+ Tools: [
167
+ {
168
+ "type": "function",
169
+ "function": {
170
+ "name": "get_weather",
171
+ "description": "Get current weather",
172
+ "parameters": {
173
+ "type": "object",
174
+ "properties": {
175
+ "location": { "type": "string" }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ ]
181
+
182
+ Output:
183
+ toolCalls: [
184
+ {
185
+ "id": "call_abc123",
186
+ "function": {
187
+ "name": "get_weather",
188
+ "arguments": "{\"location\": \"Paris\"}"
189
+ }
190
+ }
191
+ ]
192
+ ```
193
+
194
+ ## Output Format
195
+
196
+ ### Full Metrics (default)
197
+
198
+ ```json
199
+ {
200
+ "content": "AI response here...",
201
+ "modelUsed": "gpt-4o-mini",
202
+ "totalCost": 0.000211,
203
+ "savingsPercentage": 97.8,
204
+ "latencyMs": 820,
205
+ "cascaded": true,
206
+ "draftAccepted": true,
207
+ "complexity": "simple",
208
+ "routingStrategy": "cascade",
209
+ "qualityScore": 0.89,
210
+ "draftCost": 0.000211,
211
+ "verifierCost": 0.0,
212
+ "summary": {
213
+ "saved": "97.8%",
214
+ "cost": "$0.000211",
215
+ "model": "gpt-4o-mini",
216
+ "speed": "820ms",
217
+ "status": "✅ Draft accepted"
218
+ }
219
+ }
220
+ ```
221
+
222
+ ### Content Only
223
+
224
+ ```json
225
+ {
226
+ "content": "AI response here..."
227
+ }
228
+ ```
229
+
230
+ ### Metrics Summary
231
+
232
+ ```json
233
+ {
234
+ "content": "AI response here...",
235
+ "modelUsed": "gpt-4o-mini",
236
+ "totalCost": 0.000211,
237
+ "savingsPercentage": 97.8,
238
+ "cascaded": true,
239
+ "draftAccepted": true,
240
+ "latencyMs": 820
241
+ }
242
+ ```
243
+
244
+ ## Cost Savings Examples
245
+
246
+ **With GPT-5 (Recommended):**
247
+
248
+ | Use Case | Traditional GPT-5 Only | cascadeflow (Haiku + GPT-5) | Savings |
249
+ |----------|------------------------|------------------------------|---------|
250
+ | Simple Q&A (70% of traffic) | $0.00125 | $0.0008 | 36% |
251
+ | Complex query (30% of traffic) | $0.00125 | $0.00125 | 0% (correctly escalated) |
252
+ | **Average** | **$0.00125** | **$0.00094** | **24.8%** |
253
+
254
+ **Monthly savings (10,000 queries):**
255
+ - Traditional (GPT-5 only): $12.50
256
+ - cascadeflow (Haiku + GPT-5): $9.40
257
+ - **You save: $3.10/month** (25% savings)
258
+
259
+ **Monthly savings (100,000 queries):**
260
+ - Traditional (GPT-5 only): $125.00
261
+ - cascadeflow (Haiku + GPT-5): $94.00
262
+ - **You save: $31.00/month** (25% savings)
263
+
264
+ **Note:** GPT-5 is already 50% cheaper input than GPT-4o. Cascading adds additional 25-30% savings on top!
265
+
266
+ ## Recommended Model Configurations
267
+
268
+ ### ⭐ Best Overall: Claude Haiku + GPT-5 (Recommended)
269
+
270
+ ```
271
+ Draft: claude-3-5-haiku-20241022 ($0.0008)
272
+ Verifier: gpt-5 ($0.00125)
273
+ Savings: ~50-65%
274
+ Why: Haiku's fast, high-quality drafts + GPT-5's superior reasoning
275
+ Use for: Coding, reasoning, complex queries, agentic workflows
276
+ ```
277
+
278
+ > **⚠️ Important:** GPT-5 requires OpenAI organization verification. Visit [OpenAI Settings](https://platform.openai.com/settings/organization/general) and verify your organization. The cascade works immediately (Claude handles 75% of queries), GPT-5 verification unlocks the remaining 25%.
279
+
280
+ ### OpenAI Only (Good Balance)
281
+
282
+ ```
283
+ Draft: gpt-4o-mini ($0.00015)
284
+ Verifier: gpt-5 ($0.00125)
285
+ Savings: ~50-60%
286
+ Why: GPT-5 is 50% cheaper input than GPT-4o, better performance
287
+ Note: GPT-5 excels at coding (75% vs 31%), reasoning, math
288
+ ```
289
+
290
+ ### Anthropic Only (High Quality)
291
+
292
+ ```
293
+ Draft: claude-3-5-haiku-20241022 ($0.0008)
294
+ Verifier: claude-3-5-sonnet-20241022 ($0.003)
295
+ Savings: ~40-50%
296
+ Why: Consistent Anthropic experience, excellent quality
297
+ ```
298
+
299
+ ### Groq + GPT-5 (Ultra Fast + Best Quality)
300
+
301
+ ```
302
+ Draft: groq/llama-3.1-8b-instant ($0.00005)
303
+ Verifier: gpt-5 ($0.00125)
304
+ Savings: ~75-85%
305
+ Why: Groq's instant speed + GPT-5's reasoning power
306
+ Note: Highest cost savings, best for high-volume workloads
307
+ ```
308
+
309
+ ### Legacy: GPT-4o (Not Recommended)
310
+
311
+ ```
312
+ Draft: gpt-4o-mini ($0.00015)
313
+ Verifier: gpt-4o ($0.0025)
314
+ Savings: ~40-50%
315
+ Note: GPT-5 is cheaper and significantly better at coding/reasoning
316
+ ```
317
+
318
+ ## Compatibility
319
+
320
+ Tested with n8n version 1.0+
321
+
322
+ ## Resources
323
+
324
+ - [n8n community nodes documentation](https://docs.n8n.io/integrations/community-nodes/)
325
+ - [cascadeflow GitHub](https://github.com/lemony-ai/cascadeflow)
326
+ - [cascadeflow Documentation](https://docs.lemony.ai/cascadeflow)
327
+
328
+ ## License
329
+
330
+ [MIT](https://github.com/lemony-ai/cascadeflow/blob/main/LICENSE)
331
+
332
+ ## Version history
333
+
334
+ ### 1.1.0 (v0.2.1) - Coming Soon
335
+
336
+ **Multi-Tenant Production Features:**
337
+ - User profile system with 5 subscription tiers (FREE, STARTER, PRO, BUSINESS, ENTERPRISE)
338
+ - Per-user rate limiting (hourly/daily request limits + budget enforcement)
339
+ - Content safety guardrails (content moderation + PII detection)
340
+ - Batch processing for high-volume workflows
341
+ - Domain-specific model routing (medical, legal, code, etc.)
342
+
343
+ **Python Library Features** (use via Python subprocess or HTTP API):
344
+ - `UserProfile` for multi-tenant applications
345
+ - `RateLimiter` with sliding window algorithm
346
+ - `GuardrailsManager` for content moderation and PII detection
347
+ - `BatchConfig` for efficient bulk processing
348
+
349
+ *Note: Full n8n node integration coming in future release. Currently available in Python API.*
350
+
351
+ ### 1.0.0
352
+
353
+ - Initial release
354
+ - Support for OpenAI, Anthropic, Groq, Together AI, Ollama, HuggingFace
355
+ - Text generation with cascading
356
+ - Tool calling support
357
+ - Full metrics and cost tracking
@@ -0,0 +1,10 @@
1
+ import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class cascadeflowApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
10
+ //# sourceMappingURL=cascadeflowApi.credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cascadeflowApi.credentials.d.ts","sourceRoot":"","sources":["../../credentials/cascadeflowApi.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,qBAAa,cAAe,YAAW,eAAe;IACpD,IAAI,SAAoB;IACxB,WAAW,SAAqB;IAChC,gBAAgB,SAA8C;IAC9D,UAAU,EAAE,eAAe,EAAE,CA8C3B;IAEF,YAAY,EAAE,oBAAoB,CAGhC;IAEF,IAAI,EAAE,sBAAsB,CAS1B;CACH"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cascadeflowApi = void 0;
4
+ class cascadeflowApi {
5
+ constructor() {
6
+ this.name = 'cascadeFlowApi';
7
+ this.displayName = 'Cascadeflow API';
8
+ this.documentationUrl = 'https://github.com/lemony-ai/cascadeflow';
9
+ this.properties = [
10
+ {
11
+ displayName: 'OpenAI API Key',
12
+ name: 'openaiApiKey',
13
+ type: 'string',
14
+ typeOptions: { password: true },
15
+ default: '',
16
+ description: 'API key for OpenAI (GPT-4, GPT-4o, etc.)',
17
+ placeholder: 'sk-...',
18
+ },
19
+ {
20
+ displayName: 'Anthropic API Key',
21
+ name: 'anthropicApiKey',
22
+ type: 'string',
23
+ typeOptions: { password: true },
24
+ default: '',
25
+ description: 'API key for Anthropic (Claude models)',
26
+ placeholder: 'sk-ant-...',
27
+ },
28
+ {
29
+ displayName: 'Groq API Key',
30
+ name: 'groqApiKey',
31
+ type: 'string',
32
+ typeOptions: { password: true },
33
+ default: '',
34
+ description: 'API key for Groq (fast Llama inference)',
35
+ placeholder: 'gsk_...',
36
+ },
37
+ {
38
+ displayName: 'Together AI API Key',
39
+ name: 'togetherApiKey',
40
+ type: 'string',
41
+ typeOptions: { password: true },
42
+ default: '',
43
+ description: 'API key for Together AI',
44
+ placeholder: '',
45
+ },
46
+ {
47
+ displayName: 'HuggingFace API Key',
48
+ name: 'huggingfaceApiKey',
49
+ type: 'string',
50
+ typeOptions: { password: true },
51
+ default: '',
52
+ description: 'API key for HuggingFace Inference',
53
+ placeholder: 'hf_...',
54
+ },
55
+ ];
56
+ this.authenticate = {
57
+ type: 'generic',
58
+ properties: {},
59
+ };
60
+ this.test = {
61
+ request: {
62
+ baseURL: 'https://api.openai.com/v1',
63
+ url: '/models',
64
+ method: 'GET',
65
+ headers: {
66
+ Authorization: '=Bearer {{$credentials.openaiApiKey}}',
67
+ },
68
+ },
69
+ };
70
+ }
71
+ }
72
+ exports.cascadeflowApi = cascadeflowApi;
73
+ //# sourceMappingURL=cascadeflowApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cascadeflowApi.credentials.js","sourceRoot":"","sources":["../../credentials/cascadeflowApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,cAAc;IAA3B;QACE,SAAI,GAAG,gBAAgB,CAAC;QACxB,gBAAW,GAAG,iBAAiB,CAAC;QAChC,qBAAgB,GAAG,0CAA0C,CAAC;QAC9D,eAAU,GAAsB;YAC9B;gBACE,WAAW,EAAE,gBAAgB;gBAC7B,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,0CAA0C;gBACvD,WAAW,EAAE,QAAQ;aACtB;YACD;gBACE,WAAW,EAAE,mBAAmB;gBAChC,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,uCAAuC;gBACpD,WAAW,EAAE,YAAY;aAC1B;YACD;gBACE,WAAW,EAAE,cAAc;gBAC3B,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,yCAAyC;gBACtD,WAAW,EAAE,SAAS;aACvB;YACD;gBACE,WAAW,EAAE,qBAAqB;gBAClC,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,yBAAyB;gBACtC,WAAW,EAAE,EAAE;aAChB;YACD;gBACE,WAAW,EAAE,qBAAqB;gBAClC,IAAI,EAAE,mBAAmB;gBACzB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,mCAAmC;gBAChD,WAAW,EAAE,QAAQ;aACtB;SACF,CAAC;QAEF,iBAAY,GAAyB;YACnC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE;SACf,CAAC;QAEF,SAAI,GAA2B;YAC7B,OAAO,EAAE;gBACP,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,SAAS;gBACd,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,aAAa,EAAE,uCAAuC;iBACvD;aACF;SACF,CAAC;IACJ,CAAC;CAAA;AAnED,wCAmEC"}
@@ -0,0 +1,6 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class cascadeflow implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
6
+ //# sourceMappingURL=CascadeFlow.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CascadeFlow.node.d.ts","sourceRoot":"","sources":["../../../nodes/CascadeFlow/CascadeFlow.node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EAErB,MAAM,cAAc,CAAC;AAItB,qBAAa,WAAY,YAAW,SAAS;IAC3C,WAAW,EAAE,oBAAoB,CAyR/B;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAyJxE"}
@@ -0,0 +1,420 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cascadeflow = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const core_1 = require("@cascadeflow/core");
6
+ class cascadeflow {
7
+ constructor() {
8
+ this.description = {
9
+ displayName: 'cascadeflow',
10
+ name: 'cascadeFlow',
11
+ icon: 'file:cascadeflow.svg',
12
+ group: ['transform'],
13
+ version: 1,
14
+ subtitle: '={{$parameter["operation"]}}',
15
+ description: 'Smart AI model cascading with 40-85% cost savings',
16
+ defaults: {
17
+ name: 'cascadeflow',
18
+ },
19
+ inputs: ['main'],
20
+ outputs: ['main'],
21
+ credentials: [
22
+ {
23
+ name: 'cascadeFlowApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ properties: [
28
+ {
29
+ displayName: 'Operation',
30
+ name: 'operation',
31
+ type: 'options',
32
+ noDataExpression: true,
33
+ options: [
34
+ {
35
+ name: 'Generate Text',
36
+ value: 'generateText',
37
+ description: 'Generate AI response with cascading',
38
+ action: 'Generate text with cascading',
39
+ },
40
+ {
41
+ name: 'Generate with Tools',
42
+ value: 'generateWithTools',
43
+ description: 'Generate AI response with tool calling',
44
+ action: 'Generate with tool calling',
45
+ },
46
+ ],
47
+ default: 'generateText',
48
+ },
49
+ // Input message
50
+ {
51
+ displayName: 'Message',
52
+ name: 'message',
53
+ type: 'string',
54
+ default: '',
55
+ required: true,
56
+ typeOptions: {
57
+ rows: 4,
58
+ },
59
+ description: 'The message or query to send to AI',
60
+ placeholder: 'What is the capital of France?',
61
+ },
62
+ // Model Configuration
63
+ {
64
+ displayName: 'Models Configuration',
65
+ name: 'modelsConfig',
66
+ type: 'fixedCollection',
67
+ typeOptions: {
68
+ multipleValues: false,
69
+ },
70
+ default: {},
71
+ options: [
72
+ {
73
+ name: 'models',
74
+ displayName: 'Models',
75
+ values: [
76
+ {
77
+ displayName: 'Draft Model Cost',
78
+ name: 'draftCost',
79
+ type: 'number',
80
+ default: 0.000375,
81
+ description: 'Cost per 1K tokens (blended)',
82
+ },
83
+ {
84
+ displayName: 'Draft Model Name',
85
+ name: 'draftModel',
86
+ type: 'string',
87
+ default: 'gpt-4o-mini',
88
+ description: 'Model name for draft generation',
89
+ placeholder: 'gpt-4o-mini',
90
+ },
91
+ {
92
+ displayName: 'Draft Model Provider',
93
+ name: 'draftProvider',
94
+ type: 'options',
95
+ default: 'openai',
96
+ options: [
97
+ {
98
+ name: 'Anthropic',
99
+ value: 'anthropic',
100
+ },
101
+ {
102
+ name: 'Groq',
103
+ value: 'groq',
104
+ },
105
+ {
106
+ name: 'Ollama (Local)',
107
+ value: 'ollama',
108
+ },
109
+ {
110
+ name: 'OpenAI',
111
+ value: 'openai',
112
+ },
113
+ {
114
+ name: 'Together AI',
115
+ value: 'together',
116
+ },
117
+ ],
118
+ description: 'Provider for the cheap draft model',
119
+ },
120
+ {
121
+ displayName: 'Verifier Model Cost',
122
+ name: 'verifierCost',
123
+ type: 'number',
124
+ default: 0.00625,
125
+ description: 'Cost per 1K tokens (blended)',
126
+ },
127
+ {
128
+ displayName: 'Verifier Model Name',
129
+ name: 'verifierModel',
130
+ type: 'string',
131
+ default: 'gpt-4o',
132
+ description: 'Model name for verification',
133
+ placeholder: 'gpt-4o',
134
+ },
135
+ {
136
+ displayName: 'Verifier Model Provider',
137
+ name: 'verifierProvider',
138
+ type: 'options',
139
+ default: 'openai',
140
+ options: [
141
+ {
142
+ name: 'OpenAI',
143
+ value: 'openai',
144
+ },
145
+ {
146
+ name: 'Anthropic',
147
+ value: 'anthropic',
148
+ },
149
+ {
150
+ name: 'Groq',
151
+ value: 'groq',
152
+ },
153
+ {
154
+ name: 'Together AI',
155
+ value: 'together',
156
+ },
157
+ ],
158
+ description: 'Provider for the expensive verifier model',
159
+ },
160
+ ],
161
+ },
162
+ ],
163
+ },
164
+ // Quality Configuration
165
+ {
166
+ displayName: 'Quality Settings',
167
+ name: 'qualitySettings',
168
+ type: 'fixedCollection',
169
+ typeOptions: {
170
+ multipleValues: false,
171
+ },
172
+ default: {},
173
+ options: [
174
+ {
175
+ name: 'quality',
176
+ displayName: 'Quality',
177
+ values: [
178
+ {
179
+ displayName: 'Quality Threshold',
180
+ name: 'threshold',
181
+ type: 'number',
182
+ default: 0.7,
183
+ typeOptions: {
184
+ minValue: 0,
185
+ maxValue: 1,
186
+ numberPrecision: 2,
187
+ },
188
+ description: 'Minimum quality score to accept draft (0-1)',
189
+ },
190
+ {
191
+ displayName: 'Require Minimum Tokens',
192
+ name: 'requireMinimumTokens',
193
+ type: 'number',
194
+ default: 10,
195
+ typeOptions: {
196
+ minValue: 0,
197
+ },
198
+ description: 'Minimum response length in tokens',
199
+ },
200
+ ],
201
+ },
202
+ ],
203
+ },
204
+ // Advanced Options
205
+ {
206
+ displayName: 'Advanced Options',
207
+ name: 'advancedOptions',
208
+ type: 'collection',
209
+ default: {},
210
+ placeholder: 'Add Option',
211
+ options: [
212
+ {
213
+ displayName: 'Max Tokens',
214
+ name: 'maxTokens',
215
+ type: 'number',
216
+ default: 1000,
217
+ description: 'Maximum tokens to generate',
218
+ },
219
+ {
220
+ displayName: 'Temperature',
221
+ name: 'temperature',
222
+ type: 'number',
223
+ default: 0.7,
224
+ typeOptions: {
225
+ minValue: 0,
226
+ maxValue: 2,
227
+ numberPrecision: 1,
228
+ },
229
+ description: 'Sampling temperature (0-2)',
230
+ },
231
+ {
232
+ displayName: 'System Prompt',
233
+ name: 'systemPrompt',
234
+ type: 'string',
235
+ default: '',
236
+ typeOptions: {
237
+ rows: 3,
238
+ },
239
+ description: 'Optional system prompt',
240
+ },
241
+ ],
242
+ },
243
+ // Tool Calling (for generateWithTools operation)
244
+ {
245
+ displayName: 'Tools',
246
+ name: 'tools',
247
+ type: 'json',
248
+ displayOptions: {
249
+ show: {
250
+ operation: ['generateWithTools'],
251
+ },
252
+ },
253
+ default: '[]',
254
+ description: 'Tools in OpenAI format (JSON array)',
255
+ placeholder: '[{"type": "function", "function": {"name": "get_weather", ...}}]',
256
+ },
257
+ // Output Options
258
+ {
259
+ displayName: 'Output',
260
+ name: 'output',
261
+ type: 'options',
262
+ default: 'fullMetrics',
263
+ options: [
264
+ {
265
+ name: 'Full Metrics',
266
+ value: 'fullMetrics',
267
+ description: 'Return response + all cascade metrics',
268
+ },
269
+ {
270
+ name: 'Content Only',
271
+ value: 'contentOnly',
272
+ description: 'Return only the AI response text',
273
+ },
274
+ {
275
+ name: 'Metrics Summary',
276
+ value: 'metricsSummary',
277
+ description: 'Return response + key metrics (cost, savings, model)',
278
+ },
279
+ ],
280
+ description: 'What data to return',
281
+ },
282
+ ],
283
+ };
284
+ }
285
+ async execute() {
286
+ const items = this.getInputData();
287
+ const returnData = [];
288
+ // Get credentials
289
+ const credentials = await this.getCredentials('cascadeFlowApi');
290
+ // Helper to get API key for provider (moved inside execute for proper 'this' context)
291
+ const getApiKeyForProvider = (creds, provider) => {
292
+ const keyMap = {
293
+ openai: 'openaiApiKey',
294
+ anthropic: 'anthropicApiKey',
295
+ groq: 'groqApiKey',
296
+ together: 'togetherApiKey',
297
+ huggingface: 'huggingfaceApiKey',
298
+ };
299
+ const keyName = keyMap[provider];
300
+ if (!keyName) {
301
+ return '';
302
+ }
303
+ return creds[keyName] || '';
304
+ };
305
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
306
+ try {
307
+ // Get parameters
308
+ const operation = this.getNodeParameter('operation', itemIndex);
309
+ const message = this.getNodeParameter('message', itemIndex);
310
+ const modelsConfig = this.getNodeParameter('modelsConfig', itemIndex, {});
311
+ const qualitySettings = this.getNodeParameter('qualitySettings', itemIndex, {});
312
+ const advancedOptions = this.getNodeParameter('advancedOptions', itemIndex, {});
313
+ const outputMode = this.getNodeParameter('output', itemIndex, 'fullMetrics');
314
+ // Extract model configuration
315
+ const models = modelsConfig.models || {};
316
+ const quality = qualitySettings.quality || {};
317
+ // Build model configs
318
+ const modelConfigs = [
319
+ // Draft model
320
+ {
321
+ name: models.draftModel || 'gpt-4o-mini',
322
+ provider: models.draftProvider || 'openai',
323
+ cost: models.draftCost || 0.000375,
324
+ apiKey: getApiKeyForProvider(credentials, models.draftProvider || 'openai'),
325
+ },
326
+ // Verifier model
327
+ {
328
+ name: models.verifierModel || 'gpt-4o',
329
+ provider: models.verifierProvider || 'openai',
330
+ cost: models.verifierCost || 0.00625,
331
+ apiKey: getApiKeyForProvider(credentials, models.verifierProvider || 'openai'),
332
+ },
333
+ ];
334
+ // Create CascadeAgent
335
+ const agent = new core_1.CascadeAgent({
336
+ models: modelConfigs,
337
+ quality: {
338
+ threshold: quality.threshold || 0.7,
339
+ requireMinimumTokens: quality.requireMinimumTokens || 10,
340
+ },
341
+ });
342
+ // Prepare run options
343
+ const runOptions = {
344
+ maxTokens: advancedOptions.maxTokens,
345
+ temperature: advancedOptions.temperature,
346
+ systemPrompt: advancedOptions.systemPrompt,
347
+ };
348
+ // Add tools if generateWithTools operation
349
+ if (operation === 'generateWithTools') {
350
+ const toolsJson = this.getNodeParameter('tools', itemIndex, '[]');
351
+ try {
352
+ runOptions.tools = JSON.parse(toolsJson);
353
+ }
354
+ catch (error) {
355
+ const errorMessage = error instanceof Error ? error.message : String(error);
356
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid tools JSON: ${errorMessage}`, { itemIndex });
357
+ }
358
+ }
359
+ // Execute cascade
360
+ const result = await agent.run(message, runOptions);
361
+ // Format output based on outputMode
362
+ let outputData;
363
+ switch (outputMode) {
364
+ case 'contentOnly':
365
+ outputData = {
366
+ content: result.content,
367
+ toolCalls: result.toolCalls,
368
+ };
369
+ break;
370
+ case 'metricsSummary':
371
+ outputData = {
372
+ content: result.content,
373
+ toolCalls: result.toolCalls,
374
+ modelUsed: result.modelUsed,
375
+ totalCost: result.totalCost,
376
+ savingsPercentage: result.savingsPercentage,
377
+ cascaded: result.cascaded,
378
+ draftAccepted: result.draftAccepted,
379
+ latencyMs: result.latencyMs,
380
+ };
381
+ break;
382
+ case 'fullMetrics':
383
+ default:
384
+ outputData = {
385
+ ...result,
386
+ // Add n8n-friendly summary
387
+ summary: {
388
+ saved: `${result.savingsPercentage?.toFixed(1)}%`,
389
+ cost: `$${result.totalCost.toFixed(6)}`,
390
+ model: result.modelUsed,
391
+ speed: `${result.latencyMs}ms`,
392
+ status: result.draftAccepted ? '✅ Draft accepted' : '⚠️ Escalated to verifier',
393
+ },
394
+ };
395
+ break;
396
+ }
397
+ returnData.push({
398
+ json: outputData,
399
+ pairedItem: { item: itemIndex },
400
+ });
401
+ }
402
+ catch (error) {
403
+ if (this.continueOnFail()) {
404
+ const errorMessage = error instanceof Error ? error.message : String(error);
405
+ returnData.push({
406
+ json: {
407
+ error: errorMessage,
408
+ },
409
+ pairedItem: { item: itemIndex },
410
+ });
411
+ continue;
412
+ }
413
+ throw error;
414
+ }
415
+ }
416
+ return [returnData];
417
+ }
418
+ }
419
+ exports.cascadeflow = cascadeflow;
420
+ //# sourceMappingURL=CascadeFlow.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CascadeFlow.node.js","sourceRoot":"","sources":["../../../nodes/CascadeFlow/CascadeFlow.node.ts"],"names":[],"mappings":";;;AAAA,+CAMsB;AAEtB,4CAA8D;AAE9D,MAAa,WAAW;IAAxB;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,aAAa;YAC1B,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,8BAA8B;YACxC,WAAW,EAAE,mDAAmD;YAChE,QAAQ,EAAE;gBACR,IAAI,EAAE,aAAa;aACpB;YACD,MA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="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#667eea;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#764ba2;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+
9
+ <!-- Cascade symbol -->
10
+ <g fill="url(#grad1)">
11
+ <!-- Top tier (draft) -->
12
+ <circle cx="50" cy="20" r="8" opacity="0.6"/>
13
+ <text x="50" y="24" text-anchor="middle" font-size="10" fill="white" font-weight="bold">D</text>
14
+
15
+ <!-- Arrow -->
16
+ <path d="M 50 28 L 50 40" stroke="url(#grad1)" stroke-width="2" fill="none" opacity="0.6"/>
17
+ <polygon points="50,40 47,35 53,35" fill="url(#grad1)" opacity="0.6"/>
18
+
19
+ <!-- Quality check diamond -->
20
+ <g opacity="0.8">
21
+ <path d="M 50 42 L 58 50 L 50 58 L 42 50 Z" fill="url(#grad1)"/>
22
+ <text x="50" y="53" text-anchor="middle" font-size="8" fill="white" font-weight="bold">✓</text>
23
+ </g>
24
+
25
+ <!-- Branch paths -->
26
+ <path d="M 50 58 L 30 75" stroke="url(#grad1)" stroke-width="2" fill="none" opacity="0.6" stroke-dasharray="2,2"/>
27
+ <path d="M 50 58 L 50 75" stroke="url(#grad1)" stroke-width="2" fill="none"/>
28
+
29
+ <!-- Bottom tier (verifier - optional) -->
30
+ <circle cx="30" cy="80" r="7" opacity="0.4" stroke="#764ba2" stroke-width="1" fill="none"/>
31
+ <text x="30" y="84" text-anchor="middle" font-size="9" fill="#764ba2" opacity="0.4">V</text>
32
+
33
+ <!-- Result -->
34
+ <circle cx="50" cy="80" r="8"/>
35
+ <text x="50" y="84" text-anchor="middle" font-size="10" fill="white" font-weight="bold">✓</text>
36
+ </g>
37
+
38
+ <!-- Cost savings indicator -->
39
+ <g opacity="0.9">
40
+ <rect x="65" y="75" width="30" height="14" rx="3" fill="#10b981"/>
41
+ <text x="80" y="84" text-anchor="middle" font-size="9" fill="white" font-weight="bold">-85%</text>
42
+ </g>
43
+ </svg>
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@cascadeflow/n8n-nodes-cascadeflow",
3
+ "version": "0.4.0",
4
+ "description": "n8n node for cascadeflow - Smart AI model cascading with 40-85% cost savings",
5
+ "keywords": [
6
+ "n8n-community-node-package",
7
+ "n8n",
8
+ "cascadeflow",
9
+ "ai",
10
+ "llm",
11
+ "cost-optimization"
12
+ ],
13
+ "license": "MIT",
14
+ "homepage": "https://github.com/lemony-ai/cascadeflow",
15
+ "author": {
16
+ "name": "Lemony Inc.",
17
+ "email": "hello@lemony.ai"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/lemony-ai/cascadeflow.git",
22
+ "directory": "packages/integrations/n8n"
23
+ },
24
+ "main": "index.js",
25
+ "scripts": {
26
+ "build": "tsc && gulp build:icons",
27
+ "dev": "tsc --watch",
28
+ "format": "prettier nodes credentials --write",
29
+ "lint": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" package.json",
30
+ "lintfix": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" package.json --fix",
31
+ "prepublishOnly": "npm run build && npm run lint"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "n8n": {
37
+ "n8nNodesApiVersion": 1,
38
+ "credentials": [
39
+ "dist/credentials/cascadeflowApi.credentials.js"
40
+ ],
41
+ "nodes": [
42
+ "dist/nodes/cascadeflow/cascadeflow.node.js"
43
+ ]
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.10.0",
47
+ "@typescript-eslint/parser": "^6.0.0",
48
+ "eslint": "^8.42.0",
49
+ "eslint-plugin-n8n-nodes-base": "^1.11.0",
50
+ "gulp": "^4.0.2",
51
+ "n8n-workflow": "^1.0.0",
52
+ "prettier": "^2.7.1",
53
+ "typescript": "^5.1.6"
54
+ },
55
+ "peerDependencies": {
56
+ "n8n-workflow": "*"
57
+ },
58
+ "dependencies": {
59
+ "@cascadeflow/core": "workspace:*",
60
+ "openai": "^4.73.1",
61
+ "@anthropic-ai/sdk": "^0.30.0",
62
+ "groq-sdk": "^0.5.0"
63
+ }
64
+ }