@siftd/connect-agent 0.2.11 → 0.2.12

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/heartbeat.js CHANGED
@@ -10,7 +10,7 @@ import { hostname } from 'os';
10
10
  import { createHash } from 'crypto';
11
11
  import { getServerUrl, getAgentToken, getUserId, isCloudMode } from './config.js';
12
12
  const HEARTBEAT_INTERVAL = 10000; // 10 seconds
13
- const VERSION = '0.2.11'; // Should match package.json
13
+ const VERSION = '0.2.12'; // Should match package.json
14
14
  const state = {
15
15
  intervalId: null,
16
16
  runnerId: null,
@@ -11,6 +11,7 @@ export declare class MasterOrchestrator {
11
11
  private model;
12
12
  private maxTokens;
13
13
  private memory;
14
+ private postgresMemory;
14
15
  private scheduler;
15
16
  private indexer;
16
17
  private jobs;
@@ -19,6 +20,8 @@ export declare class MasterOrchestrator {
19
20
  private workspaceDir;
20
21
  private claudePath;
21
22
  private initialized;
23
+ private usingPostgres;
24
+ private voyageApiKey?;
22
25
  private bashTool;
23
26
  private webTools;
24
27
  private workerTools;
@@ -149,5 +152,5 @@ export declare class MasterOrchestrator {
149
152
  /**
150
153
  * Shutdown cleanly
151
154
  */
152
- shutdown(): void;
155
+ shutdown(): Promise<void>;
153
156
  }
@@ -8,6 +8,7 @@ import Anthropic from '@anthropic-ai/sdk';
8
8
  import { spawn, execSync } from 'child_process';
9
9
  import { existsSync } from 'fs';
10
10
  import { AdvancedMemoryStore } from './core/memory-advanced.js';
11
+ import { PostgresMemoryStore, isPostgresConfigured } from './core/memory-postgres.js';
11
12
  import { TaskScheduler } from './core/scheduler.js';
12
13
  import { SystemIndexer } from './core/system-indexer.js';
13
14
  import { FileWatcher } from './core/file-watcher.js';
@@ -75,6 +76,7 @@ export class MasterOrchestrator {
75
76
  model;
76
77
  maxTokens;
77
78
  memory;
79
+ postgresMemory = null;
78
80
  scheduler;
79
81
  indexer;
80
82
  jobs = new Map();
@@ -83,6 +85,8 @@ export class MasterOrchestrator {
83
85
  workspaceDir;
84
86
  claudePath;
85
87
  initialized = false;
88
+ usingPostgres = false;
89
+ voyageApiKey;
86
90
  // New tools from whatsapp-claude
87
91
  bashTool;
88
92
  webTools;
@@ -96,17 +100,19 @@ export class MasterOrchestrator {
96
100
  this.maxTokens = options.maxTokens || 4096;
97
101
  this.userId = options.userId;
98
102
  this.workspaceDir = options.workspaceDir || process.env.HOME || '/tmp';
103
+ this.voyageApiKey = options.voyageApiKey;
99
104
  // Find claude binary - critical for worker delegation
100
105
  this.claudePath = this.findClaudeBinary();
101
106
  console.log(`[ORCHESTRATOR] Claude binary: ${this.claudePath}`);
102
- // Initialize memory with user-specific paths
107
+ // Memory initialization is deferred to initialize() for async Postgres support
108
+ // For now, create SQLite as fallback (will be replaced if Postgres is configured)
103
109
  this.memory = new AdvancedMemoryStore({
104
110
  dbPath: `memories_${options.userId}.db`,
105
111
  vectorPath: `./memory_vectors_${options.userId}`,
106
112
  voyageApiKey: options.voyageApiKey
107
113
  });
108
114
  this.scheduler = new TaskScheduler(`scheduled_${options.userId}.json`);
109
- // Create indexer (will index on first initialize call)
115
+ // Create indexer (will be re-initialized after memory setup)
110
116
  this.indexer = new SystemIndexer(this.memory);
111
117
  // Initialize new tools
112
118
  this.bashTool = new BashTool(this.workspaceDir);
@@ -129,14 +135,39 @@ export class MasterOrchestrator {
129
135
  if (this.initialized)
130
136
  return;
131
137
  console.log('[ORCHESTRATOR] Initializing...');
132
- // Index the filesystem into memory
133
- try {
134
- const result = await this.indexer.indexHome();
135
- console.log(`[ORCHESTRATOR] Filesystem indexed: ${result.projects} projects, ${result.directories} directories`);
138
+ // Check for Postgres and switch memory backend if configured
139
+ if (isPostgresConfigured()) {
140
+ try {
141
+ console.log('[ORCHESTRATOR] DATABASE_URL detected, using PostgreSQL + pgvector');
142
+ this.postgresMemory = new PostgresMemoryStore({
143
+ connectionString: process.env.DATABASE_URL,
144
+ userId: this.userId
145
+ });
146
+ await this.postgresMemory.initialize();
147
+ this.memory = this.postgresMemory;
148
+ this.usingPostgres = true;
149
+ // Re-create indexer with Postgres memory
150
+ // Note: SystemIndexer expects AdvancedMemoryStore, so we skip indexing for Postgres
151
+ console.log('[ORCHESTRATOR] Memory backend: PostgreSQL + pgvector');
152
+ }
153
+ catch (error) {
154
+ console.error('[ORCHESTRATOR] PostgreSQL initialization failed, falling back to SQLite:', error);
155
+ this.usingPostgres = false;
156
+ }
136
157
  }
137
- catch (error) {
138
- console.error('[ORCHESTRATOR] Filesystem indexing failed:', error);
139
- // Continue anyway - indexing is a nice-to-have
158
+ else {
159
+ console.log('[ORCHESTRATOR] Memory backend: SQLite + vectra (local)');
160
+ }
161
+ // Index the filesystem into memory (only for SQLite - Postgres typically runs in cloud)
162
+ if (!this.usingPostgres) {
163
+ try {
164
+ const result = await this.indexer.indexHome();
165
+ console.log(`[ORCHESTRATOR] Filesystem indexed: ${result.projects} projects, ${result.directories} directories`);
166
+ }
167
+ catch (error) {
168
+ console.error('[ORCHESTRATOR] Filesystem indexing failed:', error);
169
+ // Continue anyway - indexing is a nice-to-have
170
+ }
140
171
  }
141
172
  this.initialized = true;
142
173
  }
@@ -1337,9 +1368,15 @@ This enables parallel workers to coordinate.`;
1337
1368
  /**
1338
1369
  * Shutdown cleanly
1339
1370
  */
1340
- shutdown() {
1371
+ async shutdown() {
1341
1372
  this.fileWatcher.stopAll();
1342
1373
  this.scheduler.shutdown();
1343
- this.memory.close();
1374
+ // Close memory store (Postgres is async, SQLite is sync)
1375
+ if (this.usingPostgres && this.postgresMemory) {
1376
+ await this.postgresMemory.close();
1377
+ }
1378
+ else if ('close' in this.memory) {
1379
+ this.memory.close();
1380
+ }
1344
1381
  }
1345
1382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siftd/connect-agent",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Master orchestrator agent - control Claude Code remotely via web",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",