Skip to content

Commit 9d27df7

Browse files
committed
fix: resolve config and db paths relative to workspace root
pnpm --filter changes cwd to the package directory, so relative paths like 'raiflow.yaml' and './raiflow.db' resolved inside packages/runtime/ instead of the workspace root. Now walks up to find pnpm-workspace.yaml and resolves all paths from there.
1 parent d120578 commit 9d27df7

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

packages/runtime/src/main.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// Configuration via YAML file (default: ./raiflow.yaml) or RAIFLOW_CONFIG_PATH env var.
88

99
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http';
10+
import { resolve, dirname } from 'node:path';
11+
import { existsSync } from 'node:fs';
12+
import { fileURLToPath } from 'node:url';
1013
import { loadConfig, type RaiFlowConfig } from '@openrai/config';
1114
import { createDatabase, createMigrationRunner, createSqliteInvoiceStore, createSqlitePaymentStore, createSqliteAccountStore, createSqliteSendStore, createSqliteEventStore, createSqliteWebhookStore, type Database } from '@openrai/storage';
1215
import { createEventBus, createPersistentEventStore } from '@openrai/events';
@@ -17,7 +20,21 @@ import { Runtime } from './runtime.js';
1720
// Config
1821
// ---------------------------------------------------------------------------
1922

20-
const CONFIG_PATH = process.env['RAIFLOW_CONFIG_PATH'] ?? 'raiflow.yaml';
23+
function findWorkspaceRoot(): string {
24+
// Walk up from this file (packages/runtime/dist/main.js) to find pnpm-workspace.yaml
25+
let dir = dirname(fileURLToPath(import.meta.url));
26+
while (true) {
27+
if (existsSync(resolve(dir, 'pnpm-workspace.yaml'))) return dir;
28+
const parent = dirname(dir);
29+
if (parent === dir) break;
30+
dir = parent;
31+
}
32+
// Fallback: current working directory
33+
return process.cwd();
34+
}
35+
36+
const WORKSPACE_ROOT = findWorkspaceRoot();
37+
const CONFIG_PATH = resolve(WORKSPACE_ROOT, process.env['RAIFLOW_CONFIG_PATH'] ?? 'raiflow.yaml');
2138

2239
let config: RaiFlowConfig;
2340
try {
@@ -69,8 +86,9 @@ const logger = {
6986

7087
let db: Database;
7188
try {
72-
db = createDatabase(config.storage.path);
73-
logger.info('sqlite open', config.storage.path);
89+
const dbPath = resolve(WORKSPACE_ROOT, config.storage.path);
90+
db = createDatabase(dbPath);
91+
logger.info('sqlite open', dbPath);
7492
} catch (err) {
7593
logger.error('failed to open database:', err instanceof Error ? err.message : err);
7694
process.exit(1);

raiflow.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# RaiFlow Configuration
2+
#
3+
# Copy this file to raiflow.yaml and fill in your values.
4+
# All values support env: references to inject from environment variables.
5+
#
6+
# Example:
7+
# daemon:
8+
# host: "0.0.0.0"
9+
# port: 3100
10+
# apiKey: "env:RAIFLOW_API_KEY"
11+
12+
daemon:
13+
host: "0.0.0.0"
14+
port: 3100
15+
apiKey: "qKen"
16+
17+
nano:
18+
nodes:
19+
- rpc: "https://rainstorm.city/api"
20+
ws: "wss://rainstorm.city/websocket"
21+
priority: 1
22+
23+
custody:
24+
seed: "95A55B7E8162F89C0F314BBFF55E2063C85AF1FA65E383EC80B3CAECB02ABE6C"
25+
representative: "nano_3strnmn7h9b7oghxa6h9ckrpf5r454fsobpicixps6xwiwc5q4hat7wjbpqz"
26+
27+
invoices:
28+
defaultExpirySeconds: 3600
29+
autoSweep: true
30+
sweepDestination: "nano_33u43z4ucsh4tbpsjhmp149mp7ex8xu6cnyt8k9ex4ogwbkwc3igcy1c1bgp"
31+
32+
storage:
33+
driver: "sqlite"
34+
path: "./raiflow.db"
35+
36+
webhooks:
37+
- url: "env:WEBHOOK_URL"
38+
secret: "env:WEBHOOK_SECRET"
39+
events:
40+
- "*"
41+
42+
logging:
43+
level: "debug"
44+
format: "pretty"

0 commit comments

Comments
 (0)