@kairos-sdk/core 0.1.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/LICENSE +21 -0
- package/README.md +326 -0
- package/dist/chunk-IADOKKFO.js +1296 -0
- package/dist/chunk-IADOKKFO.js.map +1 -0
- package/dist/cli.cjs +1508 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +213 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1456 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +417 -0
- package/dist/index.d.ts +417 -0
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jordan Krutman
|
|
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,326 @@
|
|
|
1
|
+
# @kairos-sdk/core
|
|
2
|
+
|
|
3
|
+
**Turn plain English into deployed n8n workflows.**
|
|
4
|
+
|
|
5
|
+
Kairos is a TypeScript SDK that takes a natural-language description of an automation, calls Claude to generate valid n8n workflow JSON, runs it through a 19-rule validator with an automatic correction loop, and deploys it to your n8n instance via REST API — all in a single `build()` call.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Kairos } from '@kairos-sdk/core'
|
|
9
|
+
|
|
10
|
+
const kairos = new Kairos({
|
|
11
|
+
anthropicApiKey: process.env.ANTHROPIC_API_KEY!,
|
|
12
|
+
n8nBaseUrl: 'https://your-instance.app.n8n.cloud',
|
|
13
|
+
n8nApiKey: process.env.N8N_API_KEY!,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const result = await kairos.build(
|
|
17
|
+
'Every morning at 9am, send a message to #daily-digest on Slack saying "Good morning team!"'
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
console.log(result.workflowId) // deployed workflow ID
|
|
21
|
+
console.log(result.credentialsNeeded) // what the user still needs to configure
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @kairos-sdk/core @anthropic-ai/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`@anthropic-ai/sdk` is a peer dependency — install it alongside Kairos.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
- Node.js 18+
|
|
39
|
+
- An [Anthropic API key](https://console.anthropic.com)
|
|
40
|
+
- An n8n instance with API access enabled (Cloud or self-hosted)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { Kairos } from '@kairos-sdk/core'
|
|
48
|
+
|
|
49
|
+
const kairos = new Kairos({
|
|
50
|
+
anthropicApiKey: 'sk-ant-...',
|
|
51
|
+
n8nBaseUrl: 'https://your-instance.app.n8n.cloud',
|
|
52
|
+
n8nApiKey: 'your-n8n-api-key',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Dry run — generates and validates but does not deploy
|
|
56
|
+
const preview = await kairos.build(
|
|
57
|
+
'Receive a webhook, call an external API, and store the result in Google Sheets',
|
|
58
|
+
{ dryRun: true }
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
console.log(preview.name) // workflow name Claude chose
|
|
62
|
+
console.log(preview.generationAttempts) // 1–3 (correction loop)
|
|
63
|
+
console.log(preview.credentialsNeeded) // services that need credentials configured
|
|
64
|
+
|
|
65
|
+
// Live deploy
|
|
66
|
+
const deployed = await kairos.build(
|
|
67
|
+
'Receive a webhook, call an external API, and store the result in Google Sheets'
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
console.log(deployed.workflowId) // now live in n8n
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## How It Works
|
|
76
|
+
|
|
77
|
+
1. **Generate** — Kairos sends your description to Claude with a detailed system prompt and forces a `generate_workflow` tool call, producing structured n8n workflow JSON.
|
|
78
|
+
2. **Validate** — The workflow is checked against 19 rules covering node structure, connection integrity, forbidden fields, trigger presence, AI connection direction, and more.
|
|
79
|
+
3. **Correct** — If validation fails, Kairos automatically sends the issues back to Claude and retries (up to 3 attempts, with tighter temperature on the final try).
|
|
80
|
+
4. **Strip** — Forbidden server-assigned fields (`id`, `createdAt`, `updatedAt`, etc.) are stripped before deployment.
|
|
81
|
+
5. **Deploy** — The validated workflow is posted to your n8n instance via REST API.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### `new Kairos(options)`
|
|
88
|
+
|
|
89
|
+
| Option | Type | Required | Description |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| `anthropicApiKey` | `string` | ✓ | Anthropic API key |
|
|
92
|
+
| `n8nBaseUrl` | `string` | ✓ | Base URL of your n8n instance |
|
|
93
|
+
| `n8nApiKey` | `string` | ✓ | n8n API key |
|
|
94
|
+
| `model` | `string` | | Claude model to use (default: `claude-sonnet-4-6`) |
|
|
95
|
+
| `logger` | `ILogger` | | Custom logger (default: silent) |
|
|
96
|
+
| `telemetry` | `boolean \| string` | | Enable JSONL telemetry logging (`true` for default dir, or a path) |
|
|
97
|
+
| `library` | `IWorkflowLibrary` | | Workflow library for RAG (default: `NullLibrary`) |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### `kairos.build(description, options?)`
|
|
102
|
+
|
|
103
|
+
Generates and optionally deploys a workflow from a plain-English description.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const result = await kairos.build(description, {
|
|
107
|
+
dryRun: false, // set true to skip deployment
|
|
108
|
+
name: 'My Workflow', // override the generated name
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Returns `BuildResult`:**
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
{
|
|
116
|
+
workflowId: string | null // null on dry run
|
|
117
|
+
name: string
|
|
118
|
+
generationAttempts: number // 1–3
|
|
119
|
+
activationRequired: boolean // true if workflow needs manual activation
|
|
120
|
+
credentialsNeeded: Array<{
|
|
121
|
+
service: string
|
|
122
|
+
credentialType: string
|
|
123
|
+
description: string
|
|
124
|
+
}>
|
|
125
|
+
dryRun: boolean
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### Workflow management
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// List all workflows
|
|
135
|
+
const workflows = await kairos.list()
|
|
136
|
+
|
|
137
|
+
// Get a specific workflow
|
|
138
|
+
const workflow = await kairos.get(workflowId)
|
|
139
|
+
|
|
140
|
+
// Update a workflow from a new description
|
|
141
|
+
const updated = await kairos.update(workflowId, 'new description')
|
|
142
|
+
|
|
143
|
+
// Activate / deactivate
|
|
144
|
+
await kairos.activate(workflowId)
|
|
145
|
+
await kairos.deactivate(workflowId)
|
|
146
|
+
|
|
147
|
+
// Delete (requires explicit confirmation)
|
|
148
|
+
await kairos.delete(workflowId, { confirm: true })
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### Executions
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
// List recent executions for a workflow
|
|
157
|
+
const executions = await kairos.executions(workflowId, { limit: 20 })
|
|
158
|
+
|
|
159
|
+
// Get a specific execution with full details
|
|
160
|
+
const detail = await kairos.execution(executionId)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
### Tags
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const tags = await kairos.listTags()
|
|
169
|
+
const newTag = await kairos.createTag('production')
|
|
170
|
+
await kairos.tag(workflowId, [newTag.id])
|
|
171
|
+
await kairos.untag(workflowId, [newTag.id])
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Error Handling
|
|
177
|
+
|
|
178
|
+
All errors extend `KairosError` so you can catch them at different levels of specificity:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import {
|
|
182
|
+
KairosError,
|
|
183
|
+
GenerationError,
|
|
184
|
+
ValidationError,
|
|
185
|
+
ApiError,
|
|
186
|
+
GuardError,
|
|
187
|
+
} from '@kairos-sdk/core'
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
await kairos.build('...')
|
|
191
|
+
} catch (err) {
|
|
192
|
+
if (err instanceof ValidationError) {
|
|
193
|
+
// Claude failed to produce a valid workflow after 3 attempts
|
|
194
|
+
for (const issue of err.issues) {
|
|
195
|
+
console.error(`[Rule ${issue.rule}] ${issue.message}`)
|
|
196
|
+
}
|
|
197
|
+
} else if (err instanceof GenerationError) {
|
|
198
|
+
// Anthropic API call failed (auth, quota, timeout)
|
|
199
|
+
console.error(err.message, err.cause)
|
|
200
|
+
} else if (err instanceof ApiError) {
|
|
201
|
+
// n8n returned a 4xx/5xx
|
|
202
|
+
console.error(`n8n error ${err.statusCode}:`, err.message)
|
|
203
|
+
} else if (err instanceof KairosError) {
|
|
204
|
+
// Any other SDK error
|
|
205
|
+
console.error(err.message)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
| Error class | When it's thrown |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `GenerationError` | Anthropic API call failed |
|
|
213
|
+
| `ResponseParseError` | Claude responded but produced no usable tool call |
|
|
214
|
+
| `ValidationError` | Workflow failed 19-rule validation after max retries |
|
|
215
|
+
| `ProviderError` | Network/auth failure talking to n8n |
|
|
216
|
+
| `ApiError` | n8n returned a 4xx or 5xx (carries `.statusCode`) |
|
|
217
|
+
| `GuardError` | `delete()` called without `{ confirm: true }` |
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## CLI
|
|
222
|
+
|
|
223
|
+
Deploy workflows from the command line — no code required:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Generate and deploy
|
|
227
|
+
kairos build "Every morning at 9am, send a Slack digest to #daily-updates"
|
|
228
|
+
|
|
229
|
+
# Dry run only
|
|
230
|
+
kairos build "Monitor a webhook and log payloads" --dry-run
|
|
231
|
+
|
|
232
|
+
# Manage workflows
|
|
233
|
+
kairos list
|
|
234
|
+
kairos get <workflow-id>
|
|
235
|
+
kairos activate <workflow-id>
|
|
236
|
+
kairos deactivate <workflow-id>
|
|
237
|
+
kairos delete <workflow-id> --confirm
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Set your credentials as environment variables:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
244
|
+
export N8N_BASE_URL=https://your-instance.app.n8n.cloud
|
|
245
|
+
export N8N_API_KEY=your-n8n-key
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Telemetry
|
|
251
|
+
|
|
252
|
+
Enable telemetry to log every generation attempt, validation result, and token usage to JSONL:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
const kairos = new Kairos({
|
|
256
|
+
anthropicApiKey: '...',
|
|
257
|
+
n8nBaseUrl: '...',
|
|
258
|
+
n8nApiKey: '...',
|
|
259
|
+
telemetry: true, // writes to ~/.kairos/telemetry/
|
|
260
|
+
})
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Or specify a custom directory:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
telemetry: '/path/to/telemetry/dir'
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Each event includes timestamp, session ID, token counts, validation issues, and duration — useful for benchmarking and analyzing the correction loop.
|
|
270
|
+
|
|
271
|
+
For CLI usage, set `KAIROS_TELEMETRY=true` in your environment.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Workflow Library (RAG)
|
|
276
|
+
|
|
277
|
+
Kairos includes a file-based workflow library that stores successful generations and uses them as few-shot examples for future builds:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { Kairos, FileLibrary } from '@kairos-sdk/core'
|
|
281
|
+
|
|
282
|
+
const kairos = new Kairos({
|
|
283
|
+
anthropicApiKey: '...',
|
|
284
|
+
n8nBaseUrl: '...',
|
|
285
|
+
n8nApiKey: '...',
|
|
286
|
+
library: new FileLibrary(), // stores in ~/.kairos/library/
|
|
287
|
+
})
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Every successful `build()` is saved automatically. Over time, the library improves generation quality by providing relevant examples to Claude — a self-improving few-shot learning system.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Custom Logger
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
const kairos = new Kairos({
|
|
298
|
+
anthropicApiKey: '...',
|
|
299
|
+
n8nBaseUrl: '...',
|
|
300
|
+
n8nApiKey: '...',
|
|
301
|
+
logger: {
|
|
302
|
+
debug: (msg, meta) => console.debug(msg, meta),
|
|
303
|
+
info: (msg, meta) => console.info(msg, meta),
|
|
304
|
+
warn: (msg, meta) => console.warn(msg, meta),
|
|
305
|
+
error: (msg, meta) => console.error(msg, meta),
|
|
306
|
+
},
|
|
307
|
+
})
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Supported n8n Node Types
|
|
313
|
+
|
|
314
|
+
Kairos knows about 60+ n8n nodes out of the box, including:
|
|
315
|
+
|
|
316
|
+
- **Triggers:** Webhook, Schedule, Chat, Manual, Email, GitHub, Telegram
|
|
317
|
+
- **Core:** HTTP Request, Set, If, Switch, Merge, Code, Wait
|
|
318
|
+
- **Apps:** Slack, Gmail, Google Sheets, Notion, Airtable, GitHub, Telegram
|
|
319
|
+
- **Data:** PostgreSQL, Redis, S3, Execute SQL
|
|
320
|
+
- **AI (LangChain):** Agent, OpenAI Chat Model, Anthropic Claude Model, Buffer Memory, Tool Workflow, Vector Store Retriever
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## License
|
|
325
|
+
|
|
326
|
+
MIT — © 2026 Jordan Krutman
|