rax-flow-core 0.2.0 → 2.0.1

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 (46) hide show
  1. package/dist/governance/audit-trail.d.ts +94 -0
  2. package/dist/governance/audit-trail.d.ts.map +1 -0
  3. package/dist/governance/audit-trail.js +246 -0
  4. package/dist/governance/audit-trail.js.map +1 -0
  5. package/dist/governance/policy-engine.d.ts +101 -0
  6. package/dist/governance/policy-engine.d.ts.map +1 -0
  7. package/dist/governance/policy-engine.js +446 -0
  8. package/dist/governance/policy-engine.js.map +1 -0
  9. package/dist/governance/rbac-engine.d.ts +59 -0
  10. package/dist/governance/rbac-engine.d.ts.map +1 -0
  11. package/dist/governance/rbac-engine.js +183 -0
  12. package/dist/governance/rbac-engine.js.map +1 -0
  13. package/dist/index.d.ts +5 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/memory/embeddings-service.d.ts +116 -0
  18. package/dist/memory/embeddings-service.d.ts.map +1 -0
  19. package/dist/memory/embeddings-service.js +287 -0
  20. package/dist/memory/embeddings-service.js.map +1 -0
  21. package/dist/memory/local-vector-store.d.ts +37 -3
  22. package/dist/memory/local-vector-store.d.ts.map +1 -1
  23. package/dist/memory/local-vector-store.js +91 -8
  24. package/dist/memory/local-vector-store.js.map +1 -1
  25. package/dist/orchestrator/core-orchestrator.d.ts +12 -0
  26. package/dist/orchestrator/core-orchestrator.d.ts.map +1 -1
  27. package/dist/orchestrator/core-orchestrator.js +75 -0
  28. package/dist/orchestrator/core-orchestrator.js.map +1 -1
  29. package/dist/orchestrator/task-decomposer.d.ts +56 -0
  30. package/dist/orchestrator/task-decomposer.d.ts.map +1 -0
  31. package/dist/orchestrator/task-decomposer.js +286 -0
  32. package/dist/orchestrator/task-decomposer.js.map +1 -0
  33. package/dist/plugins/plugin-system.d.ts +84 -1
  34. package/dist/plugins/plugin-system.d.ts.map +1 -1
  35. package/dist/plugins/plugin-system.js +91 -0
  36. package/dist/plugins/plugin-system.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/governance/audit-trail.ts +375 -0
  39. package/src/governance/policy-engine.ts +582 -0
  40. package/src/governance/rbac-engine.ts +244 -0
  41. package/src/index.ts +5 -2
  42. package/src/memory/embeddings-service.ts +322 -0
  43. package/src/memory/local-vector-store.ts +105 -8
  44. package/src/orchestrator/core-orchestrator.ts +78 -0
  45. package/src/orchestrator/task-decomposer.ts +428 -0
  46. package/src/plugins/plugin-system.ts +162 -1
@@ -1,23 +1,112 @@
1
- import { AgentInput, AgentOutput, WorkflowNode } from "../types/contracts.js";
1
+ import { AgentInput, AgentOutput, WorkflowNode, Intent, RoutedPlan } from "../types/contracts.js";
2
+
3
+ export interface CacheHookParams {
4
+ key: string;
5
+ intent: Intent;
6
+ prompt: string;
7
+ cached: boolean;
8
+ cachedValue?: unknown;
9
+ }
10
+
11
+ export interface MemoryHookParams {
12
+ taskId: string;
13
+ nodeId?: string;
14
+ action: "read" | "write" | "search";
15
+ data?: unknown;
16
+ result?: unknown;
17
+ }
18
+
19
+ export interface FallbackHookParams {
20
+ taskId: string;
21
+ nodeId: string;
22
+ agent: string;
23
+ originalProvider: string;
24
+ fallbackProvider: string;
25
+ reason: string;
26
+ attempt: number;
27
+ }
28
+
29
+ export interface EscalationHookParams {
30
+ taskId: string;
31
+ nodeId: string;
32
+ agent: string;
33
+ fromTier: string;
34
+ toTier: string;
35
+ reason: string;
36
+ confidence: number;
37
+ }
38
+
39
+ export interface RoutingHookParams {
40
+ prompt: string;
41
+ intent: Intent;
42
+ route: RoutedPlan;
43
+ changedBy?: string;
44
+ }
45
+
46
+ export interface WorkflowHookParams {
47
+ taskId: string;
48
+ workflow: { id: string; nodes: WorkflowNode[] };
49
+ phase: "planned" | "executing" | "completed" | "failed";
50
+ }
2
51
 
3
52
  export interface RaxPlugin {
4
53
  name: string;
54
+ priority?: number;
5
55
  setup?(): Promise<void> | void;
56
+ teardown?(): Promise<void> | void;
6
57
  beforeNode?(params: { node: WorkflowNode; input: AgentInput }): Promise<void> | void;
7
58
  afterNode?(params: { node: WorkflowNode; input: AgentInput; output: AgentOutput }): Promise<void> | void;
59
+ beforeCache?(params: CacheHookParams): Promise<CacheHookParams | void> | CacheHookParams | void;
60
+ afterCache?(params: CacheHookParams): Promise<void> | void;
61
+ beforeMemory?(params: MemoryHookParams): Promise<MemoryHookParams | void> | MemoryHookParams | void;
62
+ afterMemory?(params: MemoryHookParams): Promise<void> | void;
63
+ beforeFallback?(params: FallbackHookParams): Promise<FallbackHookParams | void> | FallbackHookParams | void;
64
+ afterFallback?(params: FallbackHookParams): Promise<void> | void;
65
+ onEscalation?(params: EscalationHookParams): Promise<void> | void;
66
+ onRouting?(params: RoutingHookParams): Promise<RoutingHookParams | void> | RoutingHookParams | void;
67
+ onWorkflowPhase?(params: WorkflowHookParams): Promise<void> | void;
68
+ onError?(params: { taskId: string; nodeId?: string; error: Error; phase: string }): Promise<void> | void;
8
69
  }
9
70
 
10
71
  export class PluginSystem {
11
72
  private readonly plugins: RaxPlugin[] = [];
73
+ private initialized = false;
12
74
 
13
75
  register(plugin: RaxPlugin): void {
14
76
  this.plugins.push(plugin);
77
+ this.plugins.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
78
+ }
79
+
80
+ unregister(pluginName: string): boolean {
81
+ const idx = this.plugins.findIndex(p => p.name === pluginName);
82
+ if (idx >= 0) {
83
+ this.plugins.splice(idx, 1);
84
+ return true;
85
+ }
86
+ return false;
15
87
  }
16
88
 
17
89
  async initialize(): Promise<void> {
90
+ if (this.initialized) return;
18
91
  for (const plugin of this.plugins) {
19
92
  await plugin.setup?.();
20
93
  }
94
+ this.initialized = true;
95
+ }
96
+
97
+ async teardown(): Promise<void> {
98
+ for (const plugin of this.plugins) {
99
+ await plugin.teardown?.();
100
+ }
101
+ this.initialized = false;
102
+ }
103
+
104
+ getPlugin(name: string): RaxPlugin | undefined {
105
+ return this.plugins.find(p => p.name === name);
106
+ }
107
+
108
+ listPlugins(): RaxPlugin[] {
109
+ return [...this.plugins];
21
110
  }
22
111
 
23
112
  async runBeforeNode(params: { node: WorkflowNode; input: AgentInput }): Promise<void> {
@@ -31,4 +120,76 @@ export class PluginSystem {
31
120
  await plugin.afterNode?.(params);
32
121
  }
33
122
  }
123
+
124
+ async runBeforeCache(params: CacheHookParams): Promise<CacheHookParams> {
125
+ let result = params;
126
+ for (const plugin of this.plugins) {
127
+ const modified = await plugin.beforeCache?.(result);
128
+ if (modified) result = modified;
129
+ }
130
+ return result;
131
+ }
132
+
133
+ async runAfterCache(params: CacheHookParams): Promise<void> {
134
+ for (const plugin of this.plugins) {
135
+ await plugin.afterCache?.(params);
136
+ }
137
+ }
138
+
139
+ async runBeforeMemory(params: MemoryHookParams): Promise<MemoryHookParams> {
140
+ let result = params;
141
+ for (const plugin of this.plugins) {
142
+ const modified = await plugin.beforeMemory?.(result);
143
+ if (modified) result = modified;
144
+ }
145
+ return result;
146
+ }
147
+
148
+ async runAfterMemory(params: MemoryHookParams): Promise<void> {
149
+ for (const plugin of this.plugins) {
150
+ await plugin.afterMemory?.(params);
151
+ }
152
+ }
153
+
154
+ async runBeforeFallback(params: FallbackHookParams): Promise<FallbackHookParams> {
155
+ let result = params;
156
+ for (const plugin of this.plugins) {
157
+ const modified = await plugin.beforeFallback?.(result);
158
+ if (modified) result = modified;
159
+ }
160
+ return result;
161
+ }
162
+
163
+ async runAfterFallback(params: FallbackHookParams): Promise<void> {
164
+ for (const plugin of this.plugins) {
165
+ await plugin.afterFallback?.(params);
166
+ }
167
+ }
168
+
169
+ async runOnEscalation(params: EscalationHookParams): Promise<void> {
170
+ for (const plugin of this.plugins) {
171
+ await plugin.onEscalation?.(params);
172
+ }
173
+ }
174
+
175
+ async runOnRouting(params: RoutingHookParams): Promise<RoutingHookParams> {
176
+ let result = params;
177
+ for (const plugin of this.plugins) {
178
+ const modified = await plugin.onRouting?.(result);
179
+ if (modified) result = modified;
180
+ }
181
+ return result;
182
+ }
183
+
184
+ async runOnWorkflowPhase(params: WorkflowHookParams): Promise<void> {
185
+ for (const plugin of this.plugins) {
186
+ await plugin.onWorkflowPhase?.(params);
187
+ }
188
+ }
189
+
190
+ async runOnError(params: { taskId: string; nodeId?: string; error: Error; phase: string }): Promise<void> {
191
+ for (const plugin of this.plugins) {
192
+ await plugin.onError?.(params);
193
+ }
194
+ }
34
195
  }