rax-flow 0.1.0 → 0.1.2

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,156 @@
1
+ import { WebSocketServer, WebSocket } from "ws";
2
+ import { RuntimeEventBus } from "rax-flow-core";
3
+ import { readdir, readFile, mkdir, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+
6
+ export class WebSocketRelay {
7
+ private wss: WebSocketServer | null = null;
8
+ private clients = new Set<WebSocket>();
9
+ private bus: RuntimeEventBus | null = null;
10
+
11
+ constructor(private port: number = 3002) { }
12
+
13
+ public start(eventBus: RuntimeEventBus): void {
14
+ this.bus = eventBus;
15
+ try {
16
+ this.wss = new WebSocketServer({ port: this.port });
17
+ console.log(`\n[UI] 📡 WebSocket relay started on ws://localhost:${this.port}`);
18
+
19
+ this.wss.on("connection", (ws) => {
20
+ this.clients.add(ws);
21
+ ws.send(JSON.stringify({ type: "HELLO", timestamp: Date.now() }));
22
+
23
+ ws.on("close", () => {
24
+ this.clients.delete(ws);
25
+ });
26
+
27
+ ws.on("message", async (data) => {
28
+ try {
29
+ const message = JSON.parse(data.toString());
30
+ const historyDir = path.join(process.cwd(), ".rax-flow", "history");
31
+
32
+ if (message.type === "GET_HISTORY") {
33
+ try {
34
+ const files = await readdir(historyDir);
35
+ const runs = await Promise.all(
36
+ files.filter(f => f.endsWith(".json")).map(async f => {
37
+ const content = await readFile(path.join(historyDir, f), "utf8");
38
+ const parsed = JSON.parse(content);
39
+ return {
40
+ taskId: parsed.taskId,
41
+ timestamp: parsed.timestamp,
42
+ prompt: parsed.prompt,
43
+ success: parsed.result.success,
44
+ costUsd: parsed.metrics.totalCostUsd
45
+ };
46
+ })
47
+ );
48
+ ws.send(JSON.stringify({ type: "HISTORY_LIST", runs: runs.sort((a, b) => b.timestamp - a.timestamp) }));
49
+ } catch {
50
+ ws.send(JSON.stringify({ type: "HISTORY_LIST", runs: [] }));
51
+ }
52
+ }
53
+
54
+ else if (message.type === "LOAD_RUN") {
55
+ try {
56
+ const file = path.join(historyDir, `${message.taskId}.json`);
57
+ const content = await readFile(file, "utf8");
58
+ ws.send(JSON.stringify({ type: "RUN_DATA", data: JSON.parse(content) }));
59
+ } catch (err) {
60
+ ws.send(JSON.stringify({ type: "ERROR", message: "Run not found" }));
61
+ }
62
+ }
63
+
64
+ else if (message.type === "LIST_WORKFLOWS") {
65
+ const workflowsDir = path.join(process.cwd(), ".rax-flow", "workflows");
66
+ try {
67
+ const files = await readdir(workflowsDir);
68
+ const list = files.filter(f => f.endsWith(".json")).map(f => ({
69
+ id: f.replace(".json", ""),
70
+ filename: f
71
+ }));
72
+ ws.send(JSON.stringify({ type: "WORKFLOW_LIST", workflows: list }));
73
+ } catch {
74
+ ws.send(JSON.stringify({ type: "WORKFLOW_LIST", workflows: [] }));
75
+ }
76
+ }
77
+
78
+ else if (message.type === "RESOLVE_APPROVAL") {
79
+ this.bus?.emit({
80
+ type: "INTERNAL_RESOLVE_APPROVAL",
81
+ taskId: message.taskId,
82
+ nodeId: message.nodeId,
83
+ approved: message.approved,
84
+ feedback: message.feedback
85
+ } as any);
86
+ }
87
+
88
+ else if (message.type === "SAVE_WORKFLOW") {
89
+ try {
90
+ const workflowsDir = path.join(process.cwd(), ".rax-flow", "workflows");
91
+ await mkdir(workflowsDir, { recursive: true });
92
+ const file = path.join(workflowsDir, `${message.id}.json`);
93
+ const data = {
94
+ id: message.id,
95
+ nodes: message.nodes,
96
+ edges: message.edges
97
+ };
98
+ await writeFile(file, JSON.stringify(data, null, 2));
99
+ ws.send(JSON.stringify({ type: "INFO", message: `Workflow ${message.id} saved.` }));
100
+ this.broadcast({ type: "REFRESH_WORKFLOWS" });
101
+ } catch (err) {
102
+ ws.send(JSON.stringify({ type: "ERROR", message: "Failed to save workflow" }));
103
+ }
104
+ }
105
+
106
+ else if (message.type === "DELETE_WORKFLOW") {
107
+ try {
108
+ const url = path.join(process.cwd(), ".rax-flow", "workflows", `${message.id}.json`);
109
+ const { unlink } = await import("node:fs/promises");
110
+ await unlink(url);
111
+ this.broadcast({ type: "REFRESH_WORKFLOWS" });
112
+ } catch (err) {
113
+ ws.send(JSON.stringify({ type: "ERROR", message: "Failed to delete workflow" }));
114
+ }
115
+ }
116
+ } catch (e) {
117
+ console.error("[WS] Message parse error:", e);
118
+ }
119
+ });
120
+
121
+ ws.on("error", () => {
122
+ this.clients.delete(ws);
123
+ });
124
+ });
125
+
126
+ this.wss.on("error", (err) => {
127
+ console.error(`[UI] WebSocket server error: ${err.message}`);
128
+ });
129
+
130
+ eventBus.onEvent((event) => {
131
+ this.broadcast(event);
132
+ });
133
+ } catch (err) {
134
+ console.error(`[UI] Failed to start WebSocket server: ${err}`);
135
+ }
136
+ }
137
+
138
+ private broadcast(event: unknown): void {
139
+ if (!this.wss) return;
140
+ const payload = JSON.stringify(event);
141
+ for (const client of this.clients) {
142
+ if (client.readyState === WebSocket.OPEN) {
143
+ client.send(payload);
144
+ }
145
+ }
146
+ }
147
+
148
+ public stop(): void {
149
+ if (this.wss) {
150
+ this.wss.close();
151
+ this.wss = null;
152
+ this.clients.clear();
153
+ console.log("[UI] 📡 WebSocket relay stopped.");
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "composite": true,
7
+ "declaration": true,
8
+ "declarationMap": true
9
+ },
10
+ "include": ["src/**/*.ts"],
11
+ "references": [{ "path": "../core" }, { "path": "../agents" }, { "path": "../providers" }]
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rax-flow",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,9 +14,9 @@
14
14
  "typecheck": "tsc -p tsconfig.json --noEmit"
15
15
  },
16
16
  "dependencies": {
17
- "rax-flow-agents": "0.1.0",
18
- "rax-flow-core": "0.1.0",
19
- "rax-flow-providers": "0.1.0",
17
+ "rax-flow-agents": "0.1.2",
18
+ "rax-flow-core": "0.1.2",
19
+ "rax-flow-providers": "0.1.2",
20
20
  "ws": "^8.19.0"
21
21
  },
22
22
  "publishConfig": {
@@ -25,4 +25,4 @@
25
25
  "devDependencies": {
26
26
  "@types/ws": "^8.18.1"
27
27
  }
28
- }
28
+ }
Binary file
package/src/benchmark.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { mkdir, writeFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { performance } from "node:perf_hooks";
4
- import { CoreOrchestrator } from "@rax-flow/core";
5
- import { buildOfficialAgentsRuntime } from "@rax-flow/agents";
6
- import { ClaudeAdapter, GenericRestAdapter, HostBridgeAdapter, OpenAIAdapter } from "@rax-flow/providers";
4
+ import { CoreOrchestrator } from "rax-flow-core";
5
+ import { buildOfficialAgentsRuntime } from "rax-flow-agents";
6
+ import { ClaudeAdapter, GenericRestAdapter, HostBridgeAdapter, OpenAIAdapter } from "rax-flow-providers";
7
7
  import { c } from "./styles.js";
8
8
  import { readFile } from "node:fs/promises";
9
9
 
package/src/doctor.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { HostBridgeAdapter } from "@rax-flow/providers";
3
+ import { HostBridgeAdapter } from "rax-flow-providers";
4
4
  import { c } from "./styles.js";
5
5
 
6
6
  interface DoctorOptions {
package/src/run.ts CHANGED
@@ -4,9 +4,9 @@ import path from "node:path";
4
4
  import * as readline from "node:readline/promises";
5
5
  import { stdin as input, stdout as output } from "node:process";
6
6
 
7
- import { CoreOrchestrator, WorkflowGraph } from "@rax-flow/core";
8
- import { buildOfficialAgentsRuntime } from "@rax-flow/agents";
9
- import { ClaudeAdapter, GenericRestAdapter, HostBridgeAdapter, OpenAIAdapter } from "@rax-flow/providers";
7
+ import { CoreOrchestrator, WorkflowGraph } from "rax-flow-core";
8
+ import { buildOfficialAgentsRuntime } from "rax-flow-agents";
9
+ import { ClaudeAdapter, GenericRestAdapter, HostBridgeAdapter, OpenAIAdapter } from "rax-flow-providers";
10
10
  import { WebSocketRelay } from "./ws-relay.js";
11
11
  import { c } from "./styles.js";
12
12
 
@@ -155,7 +155,7 @@ export async function runWorkflow(options: RunOptions): Promise<number> {
155
155
  const workflow = await loadWorkflow(options.cwd, options.workflowPath);
156
156
  // Memory System: Quantum Semantic Graph Memory (QSGM)
157
157
  const memoryDir = path.join(options.cwd, ".rax-flow", "memory");
158
- const { LocalVectorStore, GraphMemory, MemoryManager } = await import("@rax-flow/core");
158
+ const { LocalVectorStore, GraphMemory, MemoryManager } = await import("rax-flow-core");
159
159
 
160
160
  const vectorStore = new LocalVectorStore(path.join(memoryDir, "vector-index.json"));
161
161
  await vectorStore.load();
@@ -168,7 +168,7 @@ export async function runWorkflow(options: RunOptions): Promise<number> {
168
168
  const orchestrator = new CoreOrchestrator(providers, agents, { memory: memoryManager }, { maxParallel: options.maxParallel ?? 4, cacheTtlMs: 1000 * 60 * 60 * 24 });
169
169
 
170
170
  // Governance System: Enterprise security & compliance
171
- const { GovernancePlugin, PIIPolicy } = await import("@rax-flow/core");
171
+ const { GovernancePlugin, PIIPolicy } = await import("rax-flow-core");
172
172
  const governancePlugin = new GovernancePlugin(
173
173
  [new PIIPolicy()],
174
174
  path.join(options.cwd, ".rax-flow", "audit"),
@@ -179,7 +179,7 @@ export async function runWorkflow(options: RunOptions): Promise<number> {
179
179
 
180
180
  // Register Memory Plugin if an embedding provider is available (OpenAI in this case)
181
181
  if (providers.openai) {
182
- const { LongTermMemoryPlugin } = await import("@rax-flow/core");
182
+ const { LongTermMemoryPlugin } = await import("rax-flow-core");
183
183
  orchestrator.registerPlugin(new LongTermMemoryPlugin(memoryManager, providers.openai as any));
184
184
  }
185
185
 
package/src/ws-relay.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebSocketServer, WebSocket } from "ws";
2
- import { RuntimeEventBus } from "@rax-flow/core";
2
+ import { RuntimeEventBus } from "rax-flow-core";
3
3
  import { readdir, readFile, mkdir, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5