@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.
@@ -0,0 +1,417 @@
1
+ interface Tag {
2
+ id: string;
3
+ name: string;
4
+ }
5
+ interface N8nCredentialReference {
6
+ id: string;
7
+ name: string;
8
+ }
9
+ type ConnectionPort = {
10
+ node: string;
11
+ type: string;
12
+ index: number;
13
+ };
14
+ type ConnectionPortList = ConnectionPort[];
15
+ interface N8nConnections {
16
+ [nodeName: string]: {
17
+ main?: ConnectionPortList[];
18
+ ai_languageModel?: ConnectionPortList[];
19
+ ai_memory?: ConnectionPortList[];
20
+ ai_tool?: ConnectionPortList[];
21
+ ai_document?: ConnectionPortList[];
22
+ ai_embedding?: ConnectionPortList[];
23
+ ai_vectorStore?: ConnectionPortList[];
24
+ ai_retriever?: ConnectionPortList[];
25
+ ai_outputParser?: ConnectionPortList[];
26
+ ai_textSplitter?: ConnectionPortList[];
27
+ [key: string]: ConnectionPortList[] | undefined;
28
+ };
29
+ }
30
+ interface N8nNode {
31
+ id: string;
32
+ name: string;
33
+ type: string;
34
+ typeVersion: number;
35
+ position: [number, number];
36
+ parameters: Record<string, unknown>;
37
+ credentials?: Record<string, N8nCredentialReference>;
38
+ disabled?: boolean;
39
+ notes?: string;
40
+ notesInFlow?: boolean;
41
+ continueOnFail?: boolean;
42
+ retryOnFail?: boolean;
43
+ maxTries?: number;
44
+ waitBetweenTries?: number;
45
+ }
46
+ interface N8nSettings {
47
+ executionOrder?: 'v0' | 'v1';
48
+ saveManualExecutions?: boolean;
49
+ callerPolicy?: string;
50
+ errorWorkflow?: string;
51
+ timezone?: string;
52
+ [key: string]: unknown;
53
+ }
54
+ interface N8nWorkflow {
55
+ name: string;
56
+ nodes: N8nNode[];
57
+ connections: N8nConnections;
58
+ settings?: N8nSettings;
59
+ tags?: Tag[];
60
+ }
61
+
62
+ interface CredentialRequirement {
63
+ service: string;
64
+ credentialType: string;
65
+ description: string;
66
+ }
67
+ interface BuildResult {
68
+ workflowId: string | null;
69
+ name: string;
70
+ credentialsNeeded: CredentialRequirement[];
71
+ activationRequired: boolean;
72
+ generationAttempts: number;
73
+ dryRun: boolean;
74
+ }
75
+ interface DeployResult {
76
+ workflowId: string;
77
+ name: string;
78
+ }
79
+ interface WorkflowListItem {
80
+ id: string;
81
+ name: string;
82
+ active: boolean;
83
+ createdAt: string;
84
+ updatedAt: string;
85
+ tags?: Array<{
86
+ id: string;
87
+ name: string;
88
+ }>;
89
+ }
90
+ interface ExecutionSummary {
91
+ id: string;
92
+ workflowId: string;
93
+ status: 'success' | 'error' | 'waiting' | 'running' | 'canceled';
94
+ startedAt: string;
95
+ stoppedAt?: string;
96
+ mode: string;
97
+ }
98
+ interface ExecutionDetail extends ExecutionSummary {
99
+ data?: unknown;
100
+ workflowData?: unknown;
101
+ }
102
+
103
+ interface ILogger {
104
+ debug(msg: string, meta?: Record<string, unknown>): void;
105
+ info(msg: string, meta?: Record<string, unknown>): void;
106
+ warn(msg: string, meta?: Record<string, unknown>): void;
107
+ error(msg: string, meta?: Record<string, unknown>): void;
108
+ }
109
+ declare const nullLogger: ILogger;
110
+
111
+ interface WorkflowMetadataInput {
112
+ description: string;
113
+ tags?: string[];
114
+ platform?: string;
115
+ }
116
+ interface StoredWorkflow {
117
+ id: string;
118
+ workflow: N8nWorkflow;
119
+ description: string;
120
+ tags: string[];
121
+ platform: string;
122
+ deployCount: number;
123
+ createdAt: string;
124
+ lastDeployedAt?: string;
125
+ }
126
+ interface WorkflowMatch {
127
+ workflow: StoredWorkflow;
128
+ score: number;
129
+ mode: 'direct' | 'reference' | 'scratch';
130
+ }
131
+ interface SearchOptions {
132
+ limit?: number;
133
+ platform?: string;
134
+ }
135
+ interface LibraryFilters {
136
+ platform?: string;
137
+ tags?: string[];
138
+ }
139
+ interface IWorkflowLibrary {
140
+ initialize(): Promise<void>;
141
+ search(description: string, options?: SearchOptions): Promise<WorkflowMatch[]>;
142
+ save(workflow: N8nWorkflow, metadata: WorkflowMetadataInput): Promise<string>;
143
+ recordDeployment(id: string): Promise<void>;
144
+ get(id: string): Promise<StoredWorkflow | null>;
145
+ list(filters?: LibraryFilters): Promise<StoredWorkflow[]>;
146
+ }
147
+
148
+ interface ClientOptions {
149
+ anthropicApiKey: string;
150
+ n8nBaseUrl: string;
151
+ n8nApiKey: string;
152
+ model?: string;
153
+ logger?: ILogger;
154
+ library?: IWorkflowLibrary;
155
+ telemetry?: boolean | string;
156
+ }
157
+ interface BuildOptions {
158
+ dryRun?: boolean;
159
+ activate?: boolean;
160
+ name?: string;
161
+ }
162
+ interface DeleteOptions {
163
+ confirm: true;
164
+ }
165
+ interface ExecutionFilter {
166
+ status?: 'success' | 'error' | 'waiting' | 'running';
167
+ limit?: number;
168
+ cursor?: string;
169
+ }
170
+
171
+ declare class Kairos {
172
+ private readonly provider;
173
+ private readonly designer;
174
+ private readonly validator;
175
+ private readonly library;
176
+ private readonly logger;
177
+ private readonly telemetry;
178
+ private readonly model;
179
+ constructor(options: ClientOptions);
180
+ build(description: string, options?: BuildOptions): Promise<BuildResult>;
181
+ update(id: string, description: string): Promise<BuildResult>;
182
+ get(id: string): Promise<N8nWorkflow>;
183
+ list(): Promise<WorkflowListItem[]>;
184
+ activate(id: string): Promise<void>;
185
+ deactivate(id: string): Promise<void>;
186
+ delete(id: string, options: DeleteOptions): Promise<void>;
187
+ executions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
188
+ execution(id: string): Promise<ExecutionDetail>;
189
+ listTags(): Promise<Tag[]>;
190
+ createTag(name: string): Promise<Tag>;
191
+ tag(workflowId: string, tagIds: string[]): Promise<void>;
192
+ untag(workflowId: string, tagIds: string[]): Promise<void>;
193
+ }
194
+
195
+ interface IProvider {
196
+ readonly platform: string;
197
+ deploy(workflow: N8nWorkflow): Promise<DeployResult>;
198
+ update(id: string, workflow: N8nWorkflow): Promise<DeployResult>;
199
+ get(id: string): Promise<N8nWorkflow>;
200
+ list(): Promise<WorkflowListItem[]>;
201
+ activate(id: string): Promise<void>;
202
+ deactivate(id: string): Promise<void>;
203
+ delete(id: string, options: DeleteOptions): Promise<void>;
204
+ executions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
205
+ execution(id: string): Promise<ExecutionDetail>;
206
+ tag(workflowId: string, tagIds: string[]): Promise<void>;
207
+ untag(workflowId: string, tagIds: string[]): Promise<void>;
208
+ listTags(): Promise<Tag[]>;
209
+ createTag(name: string): Promise<Tag>;
210
+ }
211
+
212
+ interface N8nWorkflowResponse {
213
+ id: string;
214
+ name: string;
215
+ active: boolean;
216
+ nodes: N8nNode[];
217
+ connections: N8nConnections;
218
+ settings?: N8nSettings;
219
+ tags?: Tag[];
220
+ createdAt: string;
221
+ updatedAt: string;
222
+ versionId?: string;
223
+ meta?: Record<string, unknown>;
224
+ pinData?: Record<string, unknown>;
225
+ staticData?: unknown;
226
+ triggerCount?: number;
227
+ shared?: boolean;
228
+ isArchived?: boolean;
229
+ }
230
+
231
+ declare class N8nApiClient {
232
+ private readonly baseUrl;
233
+ private readonly apiKey;
234
+ private readonly logger;
235
+ constructor(baseUrl: string, apiKey: string, logger: ILogger);
236
+ private request;
237
+ createWorkflow(workflow: N8nWorkflow): Promise<N8nWorkflowResponse>;
238
+ updateWorkflow(id: string, workflow: N8nWorkflow): Promise<N8nWorkflowResponse>;
239
+ getWorkflow(id: string): Promise<N8nWorkflowResponse>;
240
+ listWorkflows(): Promise<WorkflowListItem[]>;
241
+ deleteWorkflow(id: string): Promise<void>;
242
+ activateWorkflow(id: string): Promise<void>;
243
+ deactivateWorkflow(id: string): Promise<void>;
244
+ getExecutions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
245
+ getExecution(id: string): Promise<ExecutionDetail>;
246
+ listTags(): Promise<Tag[]>;
247
+ createTag(name: string): Promise<Tag>;
248
+ tagWorkflow(workflowId: string, tagIds: string[]): Promise<void>;
249
+ untagWorkflow(workflowId: string, tagIds: string[]): Promise<void>;
250
+ private mapExecution;
251
+ }
252
+
253
+ declare class N8nFieldStripper {
254
+ stripForCreate(workflow: N8nWorkflow): N8nWorkflow;
255
+ stripForUpdate(workflow: N8nWorkflow): N8nWorkflow;
256
+ private strip;
257
+ }
258
+
259
+ declare class N8nProvider implements IProvider {
260
+ private readonly client;
261
+ private readonly stripper;
262
+ readonly platform = "n8n";
263
+ constructor(client: N8nApiClient, stripper: N8nFieldStripper);
264
+ deploy(workflow: N8nWorkflow): Promise<DeployResult>;
265
+ update(id: string, workflow: N8nWorkflow): Promise<DeployResult>;
266
+ get(id: string): Promise<N8nWorkflow>;
267
+ list(): Promise<WorkflowListItem[]>;
268
+ activate(id: string): Promise<void>;
269
+ deactivate(id: string): Promise<void>;
270
+ delete(id: string, options: DeleteOptions): Promise<void>;
271
+ executions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
272
+ execution(id: string): Promise<ExecutionDetail>;
273
+ listTags(): Promise<Tag[]>;
274
+ createTag(name: string): Promise<Tag>;
275
+ tag(workflowId: string, tagIds: string[]): Promise<void>;
276
+ untag(workflowId: string, tagIds: string[]): Promise<void>;
277
+ }
278
+
279
+ declare class NullLibrary implements IWorkflowLibrary {
280
+ initialize(): Promise<void>;
281
+ search(_description: string, _options?: SearchOptions): Promise<WorkflowMatch[]>;
282
+ save(_workflow: N8nWorkflow, _metadata: WorkflowMetadataInput): Promise<string>;
283
+ recordDeployment(_id: string): Promise<void>;
284
+ get(_id: string): Promise<StoredWorkflow | null>;
285
+ list(_filters?: LibraryFilters): Promise<StoredWorkflow[]>;
286
+ }
287
+
288
+ declare class FileLibrary implements IWorkflowLibrary {
289
+ private readonly dir;
290
+ private workflows;
291
+ private initialized;
292
+ constructor(dir?: string);
293
+ initialize(): Promise<void>;
294
+ search(description: string, options?: SearchOptions): Promise<WorkflowMatch[]>;
295
+ save(workflow: N8nWorkflow, metadata: WorkflowMetadataInput): Promise<string>;
296
+ recordDeployment(id: string): Promise<void>;
297
+ get(id: string): Promise<StoredWorkflow | null>;
298
+ list(filters?: LibraryFilters): Promise<StoredWorkflow[]>;
299
+ private persist;
300
+ }
301
+
302
+ interface ValidationIssue$1 {
303
+ rule: number;
304
+ severity: 'error' | 'warn';
305
+ message: string;
306
+ nodeId?: string;
307
+ }
308
+ interface ValidationResult {
309
+ valid: boolean;
310
+ issues: ValidationIssue$1[];
311
+ }
312
+
313
+ interface NodeDefinition {
314
+ type: string;
315
+ safeTypeVersions: number[];
316
+ requiredParams: string[];
317
+ credentialType?: string;
318
+ isTrigger?: boolean;
319
+ }
320
+ declare const DEFAULT_REGISTRY: NodeDefinition[];
321
+ declare class NodeRegistry {
322
+ private readonly byType;
323
+ constructor(definitions?: NodeDefinition[]);
324
+ get(type: string): NodeDefinition | undefined;
325
+ isTrigger(type: string): boolean;
326
+ isVersionSafe(type: string, version: number): boolean;
327
+ }
328
+
329
+ declare class N8nValidator {
330
+ private readonly registry;
331
+ constructor(registry?: NodeRegistry);
332
+ validate(workflow: N8nWorkflow): ValidationResult;
333
+ private err;
334
+ private warn;
335
+ private isTriggerNode;
336
+ private checkRule1;
337
+ private checkRule2;
338
+ private checkRule3;
339
+ private checkRule4;
340
+ private checkRule5;
341
+ private checkRule6;
342
+ private checkRule7;
343
+ private checkRule8;
344
+ private checkRule9;
345
+ private checkRule10;
346
+ private checkRule11;
347
+ private checkRule12;
348
+ private checkRule13;
349
+ private checkRule14;
350
+ private checkRule15;
351
+ private checkRule16;
352
+ private checkRule17;
353
+ private checkRule18;
354
+ private checkRule19;
355
+ }
356
+
357
+ declare class KairosError extends Error {
358
+ readonly cause?: unknown | undefined;
359
+ constructor(message: string, cause?: unknown | undefined);
360
+ }
361
+
362
+ interface ValidationIssue {
363
+ rule: number;
364
+ severity: 'error' | 'warn';
365
+ message: string;
366
+ nodeId?: string;
367
+ }
368
+ declare class ValidationError extends KairosError {
369
+ readonly issues: ValidationIssue[];
370
+ constructor(message: string, issues: ValidationIssue[]);
371
+ }
372
+
373
+ declare class GenerationError extends KairosError {
374
+ constructor(message: string, cause?: unknown);
375
+ }
376
+
377
+ declare class ResponseParseError extends KairosError {
378
+ constructor(message: string, cause?: unknown);
379
+ }
380
+
381
+ declare class ProviderError extends KairosError {
382
+ constructor(message: string, cause?: unknown);
383
+ }
384
+
385
+ declare class ApiError extends KairosError {
386
+ readonly statusCode: number;
387
+ constructor(message: string, statusCode: number, cause?: unknown);
388
+ }
389
+
390
+ declare class GuardError extends KairosError {
391
+ constructor(message: string);
392
+ }
393
+
394
+ interface TelemetryEvent {
395
+ timestamp: string;
396
+ sessionId: string;
397
+ eventType: 'build_start' | 'generation_attempt' | 'build_complete';
398
+ data: Record<string, unknown>;
399
+ }
400
+ interface AttemptMetadata {
401
+ attempt: number;
402
+ temperature: number;
403
+ durationMs: number;
404
+ tokensInput: number;
405
+ tokensOutput: number;
406
+ validationPassed: boolean;
407
+ issues: ValidationIssue[];
408
+ }
409
+
410
+ declare class TelemetryCollector {
411
+ private readonly dir;
412
+ readonly sessionId: string;
413
+ constructor(dir?: string);
414
+ emit(eventType: TelemetryEvent['eventType'], data: Record<string, unknown>): Promise<void>;
415
+ }
416
+
417
+ export { ApiError, type AttemptMetadata, type BuildOptions, type BuildResult, type ClientOptions, type CredentialRequirement, DEFAULT_REGISTRY, type DeleteOptions, type DeployResult, type ExecutionDetail, type ExecutionFilter, type ExecutionSummary, FileLibrary, GenerationError, GuardError, type ILogger, type IProvider, type IWorkflowLibrary, Kairos, KairosError, N8nApiClient, type N8nConnections, N8nFieldStripper, type N8nNode, N8nProvider, type N8nSettings, N8nValidator, type N8nWorkflow, NodeRegistry, NullLibrary, ProviderError, ResponseParseError, type StoredWorkflow, type Tag, TelemetryCollector, type TelemetryEvent, ValidationError, type ValidationIssue, type ValidationResult, type WorkflowListItem, type WorkflowMatch, nullLogger };