@kairos-sdk/core 0.3.2 → 0.4.5

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/dist/index.d.ts CHANGED
@@ -1,220 +1,5 @@
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
- workflow: N8nWorkflow;
71
- credentialsNeeded: CredentialRequirement[];
72
- activationRequired: boolean;
73
- generationAttempts: number;
74
- dryRun: boolean;
75
- }
76
- interface DeployResult {
77
- workflowId: string;
78
- name: string;
79
- }
80
- interface WorkflowListItem {
81
- id: string;
82
- name: string;
83
- active: boolean;
84
- createdAt: string;
85
- updatedAt: string;
86
- tags?: Array<{
87
- id: string;
88
- name: string;
89
- }>;
90
- }
91
- interface ExecutionSummary {
92
- id: string;
93
- workflowId: string;
94
- status: 'success' | 'error' | 'waiting' | 'running' | 'canceled';
95
- startedAt: string;
96
- stoppedAt?: string;
97
- mode: string;
98
- }
99
- interface ExecutionDetail extends ExecutionSummary {
100
- data?: unknown;
101
- workflowData?: unknown;
102
- }
103
-
104
- interface ILogger {
105
- debug(msg: string, meta?: Record<string, unknown>): void;
106
- info(msg: string, meta?: Record<string, unknown>): void;
107
- warn(msg: string, meta?: Record<string, unknown>): void;
108
- error(msg: string, meta?: Record<string, unknown>): void;
109
- }
110
- declare const nullLogger: ILogger;
111
-
112
- interface FailurePattern {
113
- rule: number;
114
- message: string;
115
- occurrences: number;
116
- }
117
- type SourceKind = 'organic' | 'n8n-template' | 'imported';
118
- type TrustLevel = 'safe' | 'review' | 'blocked';
119
- interface WorkflowMetadataInput {
120
- description: string;
121
- tags?: string[];
122
- platform?: string;
123
- failurePatterns?: Array<{
124
- rule: number;
125
- message: string;
126
- }>;
127
- sourceWorkflowIds?: string[];
128
- generationMode?: 'direct' | 'reference' | 'scratch';
129
- topMatchScore?: number;
130
- generationAttempts?: number;
131
- credentialsNeeded?: CredentialRequirement[];
132
- sourceKind?: SourceKind;
133
- sourceId?: string;
134
- sourceUrl?: string;
135
- trustLevel?: TrustLevel;
136
- }
137
- interface OutcomeData {
138
- attempts: number;
139
- firstTryPass: boolean;
140
- failedRules: number[];
141
- mode: 'direct' | 'reference';
142
- }
143
- interface OutcomeStats {
144
- totalUses: number;
145
- totalAttempts: number;
146
- firstTryPasses: number;
147
- failedRules: Record<string, number>;
148
- }
149
- interface StoredWorkflow {
150
- id: string;
151
- workflow: N8nWorkflow;
152
- description: string;
153
- tags: string[];
154
- platform: string;
155
- deployCount: number;
156
- createdAt: string;
157
- lastDeployedAt?: string;
158
- failurePatterns?: FailurePattern[];
159
- sourceWorkflowIds?: string[];
160
- generationMode?: 'direct' | 'reference' | 'scratch';
161
- topMatchScore?: number;
162
- generationAttempts?: number;
163
- credentialsNeeded?: CredentialRequirement[];
164
- sourceKind?: SourceKind;
165
- sourceId?: string;
166
- sourceUrl?: string;
167
- trustLevel?: TrustLevel;
168
- timesRetrieved?: number;
169
- timesUsedAsDirect?: number;
170
- timesUsedAsReference?: number;
171
- outcomeStats?: OutcomeStats;
172
- }
173
- interface WorkflowMatch {
174
- workflow: StoredWorkflow;
175
- score: number;
176
- mode: 'direct' | 'reference' | 'scratch';
177
- }
178
- interface SearchOptions {
179
- limit?: number;
180
- platform?: string;
181
- }
182
- interface LibraryFilters {
183
- platform?: string;
184
- tags?: string[];
185
- }
186
- interface IWorkflowLibrary {
187
- initialize(): Promise<void>;
188
- search(description: string, options?: SearchOptions): Promise<WorkflowMatch[]>;
189
- save(workflow: N8nWorkflow, metadata: WorkflowMetadataInput): Promise<string>;
190
- recordDeployment(id: string): Promise<void>;
191
- recordOutcome(id: string, outcome: OutcomeData): Promise<void>;
192
- get(id: string): Promise<StoredWorkflow | null>;
193
- list(filters?: LibraryFilters): Promise<StoredWorkflow[]>;
194
- }
195
-
196
- interface ClientOptions {
197
- anthropicApiKey: string;
198
- n8nBaseUrl?: string;
199
- n8nApiKey?: string;
200
- model?: string;
201
- logger?: ILogger;
202
- library?: IWorkflowLibrary;
203
- telemetry?: boolean | string;
204
- }
205
- interface BuildOptions {
206
- dryRun?: boolean;
207
- activate?: boolean;
208
- name?: string;
209
- }
210
- interface DeleteOptions {
211
- confirm: true;
212
- }
213
- interface ExecutionFilter {
214
- status?: 'success' | 'error' | 'waiting' | 'running';
215
- limit?: number;
216
- cursor?: string;
217
- }
1
+ import { C as ClientOptions, B as BuildOptions, a as BuildResult, N as N8nWorkflow, W as WorkflowListItem, D as DeleteOptions, E as ExecutionFilter, b as ExecutionSummary, c as ExecutionDetail, T as Tag } from './reader-CpUcHhKW.js';
2
+ export { A as ApiError, d as AttemptMetadata, e as CredentialRequirement, f as DEFAULT_REGISTRY, g as DeployResult, F as FailurePattern, h as FileLibrary, G as GenerationError, i as GuardError, I as ILogger, j as IProvider, k as IWorkflowLibrary, K as KairosError, l as N8nApiClient, m as N8nConnections, n as N8nFieldStripper, o as N8nNode, p as N8nProvider, q as N8nSettings, r as N8nValidator, s as NodeRegistry, t as NullLibrary, O as OutcomeData, u as OutcomeStats, P as ProviderError, R as ResponseParseError, v as RuleFailureRate, S as ScoredEntry, w as SourceKind, x as StoredWorkflow, y as SyncProgress, z as TelemetryCollector, H as TelemetryEvent, J as TelemetryReader, L as TemplateSyncer, M as TrustLevel, V as ValidationError, Q as ValidationIssue, U as ValidationResult, X as WorkflowCluster, Y as WorkflowMatch, Z as WorkflowMetadataInput, _ as buildSearchCorpus, $ as clusterWorkflows, a0 as hybridScore, a1 as nullLogger, a2 as rerank, a3 as tokenize } from './reader-CpUcHhKW.js';
218
3
 
219
4
  declare class Kairos {
220
5
  private readonly provider;
@@ -224,6 +9,7 @@ declare class Kairos {
224
9
  private readonly logger;
225
10
  private readonly telemetry;
226
11
  private readonly telemetryReader;
12
+ private readonly patternAnalyzer;
227
13
  private readonly model;
228
14
  private saveQueue;
229
15
  constructor(options: ClientOptions);
@@ -232,6 +18,7 @@ declare class Kairos {
232
18
  build(description: string, options?: BuildOptions): Promise<BuildResult>;
233
19
  replace(id: string, description: string): Promise<BuildResult>;
234
20
  drain(): Promise<void>;
21
+ private updatePatterns;
235
22
  private emitAttemptTelemetry;
236
23
  private recordDeploy;
237
24
  private saveToLibrary;
@@ -248,323 +35,4 @@ declare class Kairos {
248
35
  untag(workflowId: string, tagIds: string[]): Promise<void>;
249
36
  }
250
37
 
251
- interface IProvider {
252
- readonly platform: string;
253
- deploy(workflow: N8nWorkflow): Promise<DeployResult>;
254
- update(id: string, workflow: N8nWorkflow): Promise<DeployResult>;
255
- get(id: string): Promise<N8nWorkflow>;
256
- list(): Promise<WorkflowListItem[]>;
257
- activate(id: string): Promise<void>;
258
- deactivate(id: string): Promise<void>;
259
- delete(id: string, options: DeleteOptions): Promise<void>;
260
- executions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
261
- execution(id: string): Promise<ExecutionDetail>;
262
- tag(workflowId: string, tagIds: string[]): Promise<void>;
263
- untag(workflowId: string, tagIds: string[]): Promise<void>;
264
- listTags(): Promise<Tag[]>;
265
- createTag(name: string): Promise<Tag>;
266
- }
267
-
268
- interface N8nWorkflowResponse {
269
- id: string;
270
- name: string;
271
- active: boolean;
272
- nodes: N8nNode[];
273
- connections: N8nConnections;
274
- settings?: N8nSettings;
275
- tags?: Tag[];
276
- createdAt: string;
277
- updatedAt: string;
278
- versionId?: string;
279
- meta?: Record<string, unknown>;
280
- pinData?: Record<string, unknown>;
281
- staticData?: unknown;
282
- triggerCount?: number;
283
- shared?: boolean;
284
- isArchived?: boolean;
285
- }
286
- interface N8nNodeTypeInfo {
287
- name: string;
288
- displayName: string;
289
- version: number | number[];
290
- description?: string;
291
- group?: string[];
292
- credentials?: Array<{
293
- name: string;
294
- required?: boolean;
295
- }>;
296
- }
297
-
298
- declare class N8nApiClient {
299
- private readonly baseUrl;
300
- private readonly apiKey;
301
- private readonly logger;
302
- constructor(baseUrl: string, apiKey: string, logger: ILogger);
303
- private request;
304
- private singleRequest;
305
- createWorkflow(workflow: N8nWorkflow): Promise<N8nWorkflowResponse>;
306
- updateWorkflow(id: string, workflow: N8nWorkflow): Promise<N8nWorkflowResponse>;
307
- getWorkflow(id: string): Promise<N8nWorkflowResponse>;
308
- listWorkflows(): Promise<WorkflowListItem[]>;
309
- deleteWorkflow(id: string): Promise<void>;
310
- activateWorkflow(id: string): Promise<void>;
311
- deactivateWorkflow(id: string): Promise<void>;
312
- getExecutions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
313
- getExecution(id: string): Promise<ExecutionDetail>;
314
- listTags(): Promise<Tag[]>;
315
- createTag(name: string): Promise<Tag>;
316
- tagWorkflow(workflowId: string, tagIds: string[]): Promise<void>;
317
- untagWorkflow(workflowId: string, tagIds: string[]): Promise<void>;
318
- getNodeTypes(): Promise<N8nNodeTypeInfo[]>;
319
- private mapExecution;
320
- }
321
-
322
- declare class N8nFieldStripper {
323
- stripForCreate(workflow: N8nWorkflow): N8nWorkflow;
324
- stripForUpdate(workflow: N8nWorkflow): N8nWorkflow;
325
- private strip;
326
- }
327
-
328
- declare class N8nProvider implements IProvider {
329
- private readonly client;
330
- private readonly stripper;
331
- readonly platform = "n8n";
332
- constructor(client: N8nApiClient, stripper: N8nFieldStripper);
333
- deploy(workflow: N8nWorkflow): Promise<DeployResult>;
334
- update(id: string, workflow: N8nWorkflow): Promise<DeployResult>;
335
- get(id: string): Promise<N8nWorkflow>;
336
- list(): Promise<WorkflowListItem[]>;
337
- activate(id: string): Promise<void>;
338
- deactivate(id: string): Promise<void>;
339
- delete(id: string, options: DeleteOptions): Promise<void>;
340
- executions(workflowId?: string, filter?: ExecutionFilter): Promise<ExecutionSummary[]>;
341
- execution(id: string): Promise<ExecutionDetail>;
342
- listTags(): Promise<Tag[]>;
343
- createTag(name: string): Promise<Tag>;
344
- tag(workflowId: string, tagIds: string[]): Promise<void>;
345
- untag(workflowId: string, tagIds: string[]): Promise<void>;
346
- }
347
-
348
- declare class NullLibrary implements IWorkflowLibrary {
349
- initialize(): Promise<void>;
350
- search(_description: string, _options?: SearchOptions): Promise<WorkflowMatch[]>;
351
- save(_workflow: N8nWorkflow, _metadata: WorkflowMetadataInput): Promise<string>;
352
- recordDeployment(_id: string): Promise<void>;
353
- recordOutcome(_id: string, _outcome: OutcomeData): Promise<void>;
354
- get(_id: string): Promise<StoredWorkflow | null>;
355
- list(_filters?: LibraryFilters): Promise<StoredWorkflow[]>;
356
- }
357
-
358
- declare function tokenize(text: string): string[];
359
- declare function buildSearchCorpus(w: StoredWorkflow): string;
360
- declare class FileLibrary implements IWorkflowLibrary {
361
- private readonly dir;
362
- private workflows;
363
- private initPromise;
364
- private writeQueue;
365
- constructor(dir?: string);
366
- initialize(): Promise<void>;
367
- private doInitialize;
368
- search(description: string, options?: SearchOptions): Promise<WorkflowMatch[]>;
369
- save(workflow: N8nWorkflow, metadata: WorkflowMetadataInput): Promise<string>;
370
- recordDeployment(id: string): Promise<void>;
371
- recordOutcome(id: string, outcome: OutcomeData): Promise<void>;
372
- drain(): Promise<void>;
373
- get(id: string): Promise<StoredWorkflow | null>;
374
- list(filters?: LibraryFilters): Promise<StoredWorkflow[]>;
375
- private deduplicateFailurePatterns;
376
- private persist;
377
- }
378
-
379
- interface ScoredEntry {
380
- workflow: StoredWorkflow;
381
- score: number;
382
- signals: {
383
- tfidf: number;
384
- nodeFingerprint: number;
385
- outcome: number;
386
- deploy: number;
387
- };
388
- }
389
- declare function hybridScore(queryTokens: string[], queryDescription: string, workflows: StoredWorkflow[], docTokenArrays: string[][], idf: Map<string, number>): ScoredEntry[];
390
-
391
- interface WorkflowCluster {
392
- pattern: string;
393
- fingerprint: string[];
394
- members: StoredWorkflow[];
395
- avgFirstTryPassRate: number;
396
- avgAttempts: number;
397
- commonFailedRules: Array<{
398
- rule: number;
399
- frequency: number;
400
- }>;
401
- }
402
- declare function clusterWorkflows(workflows: StoredWorkflow[]): WorkflowCluster[];
403
- declare function rerank(candidates: Array<{
404
- workflow: StoredWorkflow;
405
- score: number;
406
- }>, clusters: WorkflowCluster[]): Array<{
407
- workflow: StoredWorkflow;
408
- score: number;
409
- clusterPattern?: string;
410
- }>;
411
-
412
- interface ValidationIssue {
413
- rule: number;
414
- severity: 'error' | 'warn';
415
- message: string;
416
- nodeId?: string;
417
- }
418
- interface ValidationResult {
419
- valid: boolean;
420
- issues: ValidationIssue[];
421
- }
422
-
423
- interface NodeDefinition {
424
- type: string;
425
- safeTypeVersions: number[];
426
- requiredParams: string[];
427
- credentialType?: string;
428
- isTrigger?: boolean;
429
- }
430
- declare const DEFAULT_REGISTRY: NodeDefinition[];
431
- declare class NodeRegistry {
432
- private readonly byType;
433
- constructor(definitions?: NodeDefinition[]);
434
- get(type: string): NodeDefinition | undefined;
435
- isTrigger(type: string): boolean;
436
- isKnown(type: string): boolean;
437
- isVersionSafe(type: string, version: number): boolean;
438
- getRequiredParams(type: string): string[];
439
- }
440
-
441
- declare class N8nValidator {
442
- private readonly registry;
443
- constructor(registry?: NodeRegistry);
444
- validate(workflow: N8nWorkflow): ValidationResult;
445
- private err;
446
- private warn;
447
- private isTriggerNode;
448
- private checkRule1;
449
- private checkRule2;
450
- private checkRule3;
451
- private checkRule4;
452
- private checkRule5;
453
- private checkRule6;
454
- private checkRule7;
455
- private checkRule8;
456
- private checkRule9;
457
- private checkRule10;
458
- private checkRule11;
459
- private checkRule12;
460
- private checkRule13;
461
- private checkRule14;
462
- private checkRule15;
463
- private checkRule16;
464
- private checkRule17;
465
- private checkRule18;
466
- private checkRule19;
467
- private checkRule20;
468
- private checkRule22;
469
- private checkRule23;
470
- private checkRule21;
471
- }
472
-
473
- declare class KairosError extends Error {
474
- readonly cause?: unknown | undefined;
475
- constructor(message: string, cause?: unknown | undefined);
476
- }
477
-
478
- declare class ValidationError extends KairosError {
479
- readonly issues: ValidationIssue[];
480
- constructor(message: string, issues: ValidationIssue[]);
481
- }
482
-
483
- declare class GenerationError extends KairosError {
484
- constructor(message: string, cause?: unknown);
485
- }
486
-
487
- declare class ResponseParseError extends KairosError {
488
- constructor(message: string, cause?: unknown);
489
- }
490
-
491
- declare class ProviderError extends KairosError {
492
- constructor(message: string, cause?: unknown);
493
- }
494
-
495
- declare class ApiError extends KairosError {
496
- readonly statusCode: number;
497
- constructor(message: string, statusCode: number, cause?: unknown);
498
- }
499
-
500
- declare class GuardError extends KairosError {
501
- constructor(message: string);
502
- }
503
-
504
- interface SyncProgress {
505
- total: number;
506
- processed: number;
507
- saved: number;
508
- skippedPaid: number;
509
- skippedDuplicate: number;
510
- blocked: number;
511
- reviewed: number;
512
- }
513
-
514
- interface SyncOptions {
515
- maxTemplates?: number;
516
- onProgress?: (progress: SyncProgress) => void;
517
- }
518
- declare class TemplateSyncer {
519
- private readonly library;
520
- private readonly validator;
521
- private readonly logger;
522
- constructor(library: IWorkflowLibrary, logger: ILogger);
523
- sync(options?: SyncOptions): Promise<SyncProgress>;
524
- private fetchTemplateIds;
525
- private processTemplate;
526
- private cleanDescription;
527
- }
528
-
529
- interface TelemetryEvent {
530
- schemaVersion: number;
531
- timestamp: string;
532
- sessionId: string;
533
- eventType: 'build_start' | 'generation_attempt' | 'build_complete';
534
- data: Record<string, unknown>;
535
- }
536
- interface AttemptMetadata {
537
- attempt: number;
538
- temperature: number;
539
- durationMs: number;
540
- tokensInput: number;
541
- tokensOutput: number;
542
- validationPassed: boolean;
543
- issues: ValidationIssue[];
544
- }
545
-
546
- declare class TelemetryCollector {
547
- private readonly dir;
548
- readonly sessionId: string;
549
- private dirReady;
550
- constructor(dir?: string);
551
- emit(eventType: TelemetryEvent['eventType'], data: Record<string, unknown>): Promise<void>;
552
- }
553
-
554
- interface RuleFailureRate {
555
- rule: number;
556
- failureCount: number;
557
- totalBuilds: number;
558
- rate: number;
559
- commonMessage: string;
560
- }
561
- declare class TelemetryReader {
562
- private readonly dir;
563
- private cache;
564
- private cacheTime;
565
- constructor(dir?: string);
566
- getFailureRates(days?: number): Promise<RuleFailureRate[]>;
567
- private readRecentEvents;
568
- }
569
-
570
- export { ApiError, type AttemptMetadata, type BuildOptions, type BuildResult, type ClientOptions, type CredentialRequirement, DEFAULT_REGISTRY, type DeleteOptions, type DeployResult, type ExecutionDetail, type ExecutionFilter, type ExecutionSummary, type FailurePattern, 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, type OutcomeData, type OutcomeStats, ProviderError, ResponseParseError, type RuleFailureRate, type ScoredEntry, type SourceKind, type StoredWorkflow, type SyncProgress, type Tag, TelemetryCollector, type TelemetryEvent, TelemetryReader, TemplateSyncer, type TrustLevel, ValidationError, type ValidationIssue, type ValidationResult, type WorkflowCluster, type WorkflowListItem, type WorkflowMatch, type WorkflowMetadataInput, buildSearchCorpus, clusterWorkflows, hybridScore, nullLogger, rerank, tokenize };
38
+ export { BuildOptions, BuildResult, ClientOptions, DeleteOptions, ExecutionDetail, ExecutionFilter, ExecutionSummary, Kairos, N8nWorkflow, Tag, WorkflowListItem };
package/dist/index.js CHANGED
@@ -1,14 +1,17 @@
1
+ import {
2
+ Kairos
3
+ } from "./chunk-4TS6GW6O.js";
4
+ import "./chunk-CR2NHLOH.js";
5
+ import "./chunk-6FOFWVMG.js";
1
6
  import {
2
7
  GenerationError,
3
8
  GuardError,
4
- Kairos,
5
9
  N8nProvider,
6
10
  NullLibrary,
7
11
  ResponseParseError,
8
- TelemetryCollector,
9
12
  TemplateSyncer,
10
13
  ValidationError
11
- } from "./chunk-KQSNT3HZ.js";
14
+ } from "./chunk-6CLI43FI.js";
12
15
  import {
13
16
  ApiError,
14
17
  DEFAULT_REGISTRY,
@@ -19,6 +22,7 @@ import {
19
22
  N8nValidator,
20
23
  NodeRegistry,
21
24
  ProviderError,
25
+ TelemetryCollector,
22
26
  TelemetryReader,
23
27
  buildSearchCorpus,
24
28
  clusterWorkflows,
@@ -26,7 +30,7 @@ import {
26
30
  nullLogger,
27
31
  rerank,
28
32
  tokenize
29
- } from "./chunk-RYGYNOR6.js";
33
+ } from "./chunk-6IXW3WCC.js";
30
34
  export {
31
35
  ApiError,
32
36
  DEFAULT_REGISTRY,