@powerhousedao/switchboard 4.1.0-dev.3 → 4.1.0-dev.31

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/CHANGELOG.md CHANGED
@@ -1,3 +1,253 @@
1
+ ## 4.1.0-dev.31 (2025-08-20)
2
+
3
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
4
+
5
+ ## 4.1.0-dev.30 (2025-08-20)
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - add additional tags ([4f0cf8658](https://github.com/powerhouse-inc/powerhouse/commit/4f0cf8658))
10
+
11
+ ### ❤️ Thank You
12
+
13
+ - Frank
14
+
15
+ ## 4.1.0-dev.29 (2025-08-20)
16
+
17
+ ### 🩹 Fixes
18
+
19
+ - fetch tags :-) ([df0b7beba](https://github.com/powerhouse-inc/powerhouse/commit/df0b7beba))
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Frank
24
+
25
+ ## 4.1.0-dev.28 (2025-08-20)
26
+
27
+ ### 🩹 Fixes
28
+
29
+ - removed metadata extraction from commit ([637960021](https://github.com/powerhouse-inc/powerhouse/commit/637960021))
30
+
31
+ ### ❤️ Thank You
32
+
33
+ - Frank
34
+
35
+ ## 4.1.0-dev.27 (2025-08-20)
36
+
37
+ ### 🩹 Fixes
38
+
39
+ - extract metadata tags and labels for docker ([bb9c81ce7](https://github.com/powerhouse-inc/powerhouse/commit/bb9c81ce7))
40
+ - use github tag properly ([95ccff4b8](https://github.com/powerhouse-inc/powerhouse/commit/95ccff4b8))
41
+ - proper tag for docker images ([e73e10617](https://github.com/powerhouse-inc/powerhouse/commit/e73e10617))
42
+ - use patname secret instead of github token ([db9dfd5cd](https://github.com/powerhouse-inc/powerhouse/commit/db9dfd5cd))
43
+
44
+ ### ❤️ Thank You
45
+
46
+ - Frank
47
+
48
+ ## 4.1.0-dev.26 (2025-08-20)
49
+
50
+ ### 🩹 Fixes
51
+
52
+ - docker deploy alternative approach ([2a5522cdc](https://github.com/powerhouse-inc/powerhouse/commit/2a5522cdc))
53
+
54
+ ### ❤️ Thank You
55
+
56
+ - Frank
57
+
58
+ ## 4.1.0-dev.25 (2025-08-20)
59
+
60
+ ### 🩹 Fixes
61
+
62
+ - docker deploy ([b057a7cce](https://github.com/powerhouse-inc/powerhouse/commit/b057a7cce))
63
+
64
+ ### ❤️ Thank You
65
+
66
+ - Frank
67
+
68
+ ## 4.1.0-dev.24 (2025-08-20)
69
+
70
+ ### 🚀 Features
71
+
72
+ - **codegen:** add drive explorer template ([9c27219dc](https://github.com/powerhouse-inc/powerhouse/commit/9c27219dc))
73
+ - **connect,reactor-browser:** remove more old electron garbage ([5cd255568](https://github.com/powerhouse-inc/powerhouse/commit/5cd255568))
74
+ - **connect:** remove broken electron code ([3f28d6a46](https://github.com/powerhouse-inc/powerhouse/commit/3f28d6a46))
75
+ - **reactor-browser,connect,vetra:** move state hooks into reactor browser and eliminate redundant and dead code ([30fa16f1f](https://github.com/powerhouse-inc/powerhouse/commit/30fa16f1f))
76
+ - **connect,state,renown:** add state hook for renown ([5beb1252b](https://github.com/powerhouse-inc/powerhouse/commit/5beb1252b))
77
+ - **connect:** remove unused dep ([ef492bc7a](https://github.com/powerhouse-inc/powerhouse/commit/ef492bc7a))
78
+ - **connect,state,reactor-browser:** eliminate jotai ([53b1ab759](https://github.com/powerhouse-inc/powerhouse/commit/53b1ab759))
79
+ - **state:** rename to vetra packages ([c415b7dc2](https://github.com/powerhouse-inc/powerhouse/commit/c415b7dc2))
80
+ - **state:** use ph packages atoms ([6421fbeea](https://github.com/powerhouse-inc/powerhouse/commit/6421fbeea))
81
+
82
+ ### 🩹 Fixes
83
+
84
+ - today claude taught me I could mock a package to fix circular references ([dcb83174c](https://github.com/powerhouse-inc/powerhouse/commit/dcb83174c))
85
+ - **monorepo:** numerous build issues ([04349dd25](https://github.com/powerhouse-inc/powerhouse/commit/04349dd25))
86
+
87
+ ### ❤️ Thank You
88
+
89
+ - Benjamin Jordan (@thegoldenmule)
90
+ - ryanwolhuter @ryanwolhuter
91
+
92
+ ## 4.1.0-dev.23 (2025-08-19)
93
+
94
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
95
+
96
+ ## 4.1.0-dev.22 (2025-08-15)
97
+
98
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
99
+
100
+ ## 4.1.0-dev.21 (2025-08-15)
101
+
102
+ ### 🚀 Features
103
+
104
+ - **vetra:** update manifest when new module is added ([#1766](https://github.com/powerhouse-inc/powerhouse/pull/1766))
105
+
106
+ ### 🩹 Fixes
107
+
108
+ - fixed debug launch configuration now that source maps are in the proper locations ([c75d793ed](https://github.com/powerhouse-inc/powerhouse/commit/c75d793ed))
109
+
110
+ ### ❤️ Thank You
111
+
112
+ - Benjamin Jordan (@thegoldenmule)
113
+ - Guillermo Puente Sandoval @gpuente
114
+
115
+ ## 4.1.0-dev.20 (2025-08-15)
116
+
117
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
118
+
119
+ ## 4.1.0-dev.19 (2025-08-14)
120
+
121
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
122
+
123
+ ## 4.1.0-dev.18 (2025-08-14)
124
+
125
+ ### 🩹 Fixes
126
+
127
+ - overly aggressive linter fixes ([e074de3df](https://github.com/powerhouse-inc/powerhouse/commit/e074de3df))
128
+
129
+ ### ❤️ Thank You
130
+
131
+ - Benjamin Jordan (@thegoldenmule)
132
+
133
+ ## 4.1.0-dev.17 (2025-08-12)
134
+
135
+ ### 🚀 Features
136
+
137
+ - refactor vetra command and remove vetra deps in connect and reactor ([#1753](https://github.com/powerhouse-inc/powerhouse/pull/1753))
138
+
139
+ ### ❤️ Thank You
140
+
141
+ - Guillermo Puente Sandoval @gpuente
142
+
143
+ ## 4.1.0-dev.16 (2025-08-12)
144
+
145
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
146
+
147
+ ## 4.1.0-dev.15 (2025-08-12)
148
+
149
+ ### 🚀 Features
150
+
151
+ - **reactor-mcp,reactor-api,reactor-local,switchboard,ph-cli:** run mcp on express app ([d51fa590e](https://github.com/powerhouse-inc/powerhouse/commit/d51fa590e))
152
+
153
+ ### ❤️ Thank You
154
+
155
+ - acaldas @acaldas
156
+
157
+ ## 4.1.0-dev.14 (2025-08-11)
158
+
159
+ ### 🚀 Features
160
+
161
+ - update document engineering dep ([54dcee90d](https://github.com/powerhouse-inc/powerhouse/commit/54dcee90d))
162
+
163
+ ### ❤️ Thank You
164
+
165
+ - acaldas @acaldas
166
+
167
+ ## 4.1.0-dev.13 (2025-08-09)
168
+
169
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
170
+
171
+ ## 4.1.0-dev.12 (2025-08-08)
172
+
173
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
174
+
175
+ ## 4.1.0-dev.11 (2025-08-07)
176
+
177
+ ### 🚀 Features
178
+
179
+ - **switchboard:** added dev mode to switchboard where local document models are loaded ([449e730b6](https://github.com/powerhouse-inc/powerhouse/commit/449e730b6))
180
+ - **switchboard,reactor-local,reactor-api:** moved vite loader to reactor-api package ([c84f0a2a3](https://github.com/powerhouse-inc/powerhouse/commit/c84f0a2a3))
181
+ - vetra package documents and app integration ([0e4053302](https://github.com/powerhouse-inc/powerhouse/commit/0e4053302))
182
+ - **vetra:** added vetra drive editor ([4ebafd143](https://github.com/powerhouse-inc/powerhouse/commit/4ebafd143))
183
+ - integrate package documents into reactor system ([939fe8e80](https://github.com/powerhouse-inc/powerhouse/commit/939fe8e80))
184
+ - **connect:** integrate Vetra package documents and editors ([2ecb9bd15](https://github.com/powerhouse-inc/powerhouse/commit/2ecb9bd15))
185
+
186
+ ### ❤️ Thank You
187
+
188
+ - acaldas @acaldas
189
+ - Guillermo Puente @gpuente
190
+ - Guillermo Puente Sandoval @gpuente
191
+
192
+ ## 4.1.0-dev.10 (2025-08-07)
193
+
194
+ ### 🚀 Features
195
+
196
+ - **builder-tools,codegen,design-system,reactor-api:** updated document-engineering version ([e74068b43](https://github.com/powerhouse-inc/powerhouse/commit/e74068b43))
197
+
198
+ ### ❤️ Thank You
199
+
200
+ - acaldas @acaldas
201
+
202
+ ## 4.1.0-dev.9 (2025-08-07)
203
+
204
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
205
+
206
+ ## 4.1.0-dev.8 (2025-08-06)
207
+
208
+ ### 🚀 Features
209
+
210
+ - **switchboard,config,reactor-api:** handle auth in reactor-api ([f33c921ee](https://github.com/powerhouse-inc/powerhouse/commit/f33c921ee))
211
+
212
+ ### ❤️ Thank You
213
+
214
+ - acaldas @acaldas
215
+
216
+ ## 4.1.0-dev.7 (2025-08-06)
217
+
218
+ ### 🚀 Features
219
+
220
+ - **switchboard:** added readme ([fbadfca11](https://github.com/powerhouse-inc/powerhouse/commit/fbadfca11))
221
+
222
+ ### ❤️ Thank You
223
+
224
+ - Frank
225
+
226
+ ## 4.1.0-dev.6 (2025-08-06)
227
+
228
+ ### 🚀 Features
229
+
230
+ - **reactor-mcp:** load local document models and reload when they change ([0408a017c](https://github.com/powerhouse-inc/powerhouse/commit/0408a017c))
231
+ - **reactor-local,reactor-api,document-drive:** reload local document models when they change ([5d9af3951](https://github.com/powerhouse-inc/powerhouse/commit/5d9af3951))
232
+
233
+ ### ❤️ Thank You
234
+
235
+ - acaldas @acaldas
236
+
237
+ ## 4.1.0-dev.5 (2025-08-05)
238
+
239
+ This was a version bump only for @powerhousedao/switchboard to align it with other projects, there were no code changes.
240
+
241
+ ## 4.1.0-dev.4 (2025-08-02)
242
+
243
+ ### 🚀 Features
244
+
245
+ - ts morph integration ([#1729](https://github.com/powerhouse-inc/powerhouse/pull/1729))
246
+
247
+ ### ❤️ Thank You
248
+
249
+ - Guillermo Puente Sandoval @gpuente
250
+
1
251
  ## 4.1.0-dev.3 (2025-08-01)
2
252
 
3
253
  ### 🚀 Features
package/Dockerfile CHANGED
@@ -38,8 +38,10 @@ ARG TAG=latest
38
38
  ENV TAG=$TAG
39
39
 
40
40
  RUN pnpm add -g ph-cmd@$TAG
41
- RUN if [ "$TAG" = "dev" ] || [ "$TAG" = "staging" ]; then \
42
- ph init project --${TAG} --package-manager pnpm; \
41
+ RUN if [[ "$TAG" == *"dev"* ]]; then \
42
+ ph init project --dev --package-manager pnpm; \
43
+ elif [[ "$TAG" == *"staging"* ]]; then \
44
+ ph init project --staging --package-manager pnpm; \
43
45
  else \
44
46
  ph init project --package-manager pnpm; \
45
47
  fi
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # Switchboard
2
+
3
+ A powerful document-driven server that provides a unified API for managing and serving document models, drives, and reactors in the Powerhouse ecosystem.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **Document Model Management**: Serve and manage document models with GraphQL API
8
+ - **Document Drive Support**: Handle document drives with filesystem and PostgreSQL storage
9
+ - **Reactor Integration**: Built-in support for Powerhouse reactors
10
+ - **Flexible Storage**: Support for filesystem, PostgreSQL, and Redis caching
11
+ - **Docker Ready**: Containerized deployment with comprehensive environment configuration
12
+ - **Authentication**: Configurable authentication with guest, user, and admin roles
13
+ - **HTTPS Support**: Built-in HTTPS server with custom certificates
14
+ - **Profiling**: Integration with Pyroscope for performance monitoring
15
+ - **Error Tracking**: Sentry integration for error monitoring and reporting
16
+
17
+ ## 📦 Installation
18
+
19
+ ### Prerequisites
20
+
21
+ - Node.js 22+
22
+ - pnpm (recommended) or npm
23
+ - Redis (optional, for caching)
24
+ - PostgreSQL (optional, for persistent storage)
25
+
26
+ ### Local Development
27
+
28
+ ```bash
29
+ # Clone the repository
30
+ git clone https://github.com/powerhouse-inc/powerhouse.git
31
+ cd powerhouse
32
+
33
+ # Install dependencies
34
+ pnpm install
35
+
36
+ # Build the switchboard
37
+ pnpm --filter @powerhousedao/switchboard build
38
+
39
+ # Start in development mode
40
+ pnpm --filter @powerhousedao/switchboard dev
41
+ ```
42
+
43
+ ### Global Installation
44
+
45
+ ```bash
46
+ # Install globally
47
+ npm install -g @powerhousedao/switchboard
48
+
49
+ # Or using pnpm
50
+ pnpm add -g @powerhousedao/switchboard
51
+ ```
52
+
53
+ ## 🏃‍♂️ Quick Start
54
+
55
+ ## ⚙️ Configuration
56
+
57
+ ### Environment Variables
58
+
59
+ | Variable | Description | Default |
60
+ |----------|-------------|---------|
61
+ | `PORT` | Server port | `4001` |
62
+ | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
63
+ | `REDIS_URL` | Redis connection URL | - |
64
+ | `REDIS_TLS_URL` | Redis TLS connection URL | - |
65
+ | `SENTRY_DSN` | Sentry DSN for error tracking | - |
66
+ | `SENTRY_ENV` | Sentry environment | - |
67
+ | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
68
+
69
+ ### Authentication Configuration
70
+
71
+ ```typescript
72
+ const options = {
73
+ auth: {
74
+ enabled: true,
75
+ guests: ['0x123', '0x456'],
76
+ users: ['0x789', '0xabc'],
77
+ admins: ['0xdef', '0xghi']
78
+ }
79
+ };
80
+ ```
81
+
82
+ ### Storage Options
83
+
84
+ Switchboard supports multiple storage backends:
85
+
86
+ - **Filesystem**: Local file-based storage (default)
87
+ - **PostgreSQL**: Persistent database storage
88
+ - **Redis**: Caching layer (optional)
89
+
90
+ ## 🐳 Docker Deployment
91
+
92
+ ### Using Docker Compose
93
+
94
+ ```yaml
95
+ version: '3.8'
96
+ services:
97
+ switchboard:
98
+ image: powerhouse/switchboard:latest
99
+ ports:
100
+ - "4001:4001"
101
+ environment:
102
+ - PORT=4001
103
+ - DATABASE_URL=postgresql://user:pass@db:5432/switchboard
104
+ - REDIS_URL=redis://redis:6379
105
+ depends_on:
106
+ - db
107
+ - redis
108
+
109
+ db:
110
+ image: postgres:15
111
+ environment:
112
+ POSTGRES_DB: switchboard
113
+ POSTGRES_USER: user
114
+ POSTGRES_PASSWORD: pass
115
+
116
+ redis:
117
+ image: redis:7-alpine
118
+ ```
119
+
120
+ ### Environment Variables for Docker
121
+
122
+ ```bash
123
+ # Database
124
+ PH_SWITCHBOARD_DATABASE_URL="postgresql://user:pass@db:5432/switchboard"
125
+ PH_SWITCHBOARD_REDIS_URL="redis://redis:6379"
126
+
127
+ # Authentication
128
+ PH_SWITCHBOARD_AUTH_ENABLED=true
129
+ PH_SWITCHBOARD_ADMINS_LIST="0x123,0x456"
130
+ PH_SWITCHBOARD_USERS_LIST="0x789,0xabc"
131
+ PH_SWITCHBOARD_GUESTS_LIST="0xdef,0xghi"
132
+
133
+ # Packages
134
+ PH_PACKAGES="package1,package2,package3"
135
+ ```
136
+
137
+ ## 🔧 Development
138
+
139
+ ### Project Structure
140
+
141
+ ```
142
+ src/
143
+ ├── index.ts # Main entry point
144
+ ├── server.ts # Server implementation
145
+ ├── config.ts # Configuration management
146
+ ├── types.ts # TypeScript type definitions
147
+ ├── utils.ts # Utility functions
148
+ ├── profiler.ts # Profiling integration
149
+ ├── install-packages.ts # Package installation
150
+ └── clients/ # External client integrations
151
+ └── redis.ts # Redis client
152
+ ```
153
+
154
+ ### Available Scripts
155
+
156
+ ```bash
157
+ # Build the project
158
+ pnpm build
159
+
160
+ # Start in development mode
161
+ pnpm dev
162
+
163
+ # Start production server
164
+ pnpm start
165
+
166
+ # Lint code
167
+ pnpm lint
168
+
169
+ # Clean build artifacts
170
+ pnpm clean
171
+ ```
172
+
173
+ ### Adding New Features
174
+
175
+ 1. **Document Models**: Add new document model modules to the reactor builder
176
+ 2. **Storage Backends**: Implement new storage adapters
177
+ 3. **Authentication**: Extend authentication logic
178
+ 4. **API Endpoints**: Add new GraphQL resolvers
179
+
180
+ ## 📚 API Reference
181
+
182
+ ### GraphQL Endpoints
183
+
184
+ Switchboard exposes a GraphQL API for document operations:
185
+
186
+ - **Document Models**: Query and mutate document models
187
+ - **Document Drives**: Manage document drives
188
+ - **Reactor Operations**: Execute reactor operations
189
+
190
+ ### REST Endpoints
191
+
192
+ - `GET /health` - Health check endpoint
193
+ - `POST /graphql` - GraphQL endpoint
194
+ - `GET /graphql` - GraphQL playground (development)
195
+
196
+ ## 🤝 Contributing
197
+
198
+ 1. Fork the repository
199
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
200
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
201
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
202
+ 5. Open a Pull Request
203
+
204
+ ## 📄 License
205
+
206
+ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
207
+
208
+ ## 🆘 Support
209
+
210
+ - **Documentation**: [Powerhouse Docs](https://docs.powerhouse.com)
211
+ - **Issues**: [GitHub Issues](https://github.com/powerhouse-inc/powerhouse/issues)
212
+ - **Discussions**: [GitHub Discussions](https://github.com/powerhouse-inc/powerhouse/discussions)
213
+
214
+ ## 🔗 Related Projects
215
+
216
+ - [@powerhousedao/reactor-api](https://github.com/powerhouse-inc/powerhouse/tree/main/packages/reactor-api) - Reactor API package
217
+ - [@powerhousedao/document-drive](https://github.com/powerhouse-inc/powerhouse/tree/main/packages/document-drive) - Document drive management
218
+ - [@powerhousedao/document-model](https://github.com/powerhouse-inc/powerhouse/tree/main/packages/document-model) - Document model system
@@ -3,6 +3,7 @@ interface Config {
3
3
  url: string;
4
4
  };
5
5
  port: number;
6
+ mcp: boolean;
6
7
  }
7
8
  export declare const config: Config;
8
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAMA,UAAU,MAAM;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;CACd;AACD,eAAO,MAAM,MAAM,EAAE,MAapB,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAMA,UAAU,MAAM;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;CACd;AACD,eAAO,MAAM,MAAM,EAAE,MAcpB,CAAC"}
@@ -14,5 +14,6 @@ export const config = {
14
14
  !isNaN(Number(process.env.PH_SWITCHBOARD_PORT))
15
15
  ? Number(process.env.PH_SWITCHBOARD_PORT)
16
16
  : (switchboard?.port ?? 4001),
17
+ mcp: true,
17
18
  };
18
19
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC;AAC7B,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AAOjC,MAAM,CAAC,MAAM,MAAM,GAAW;IAC5B,QAAQ,EAAE;QACR,0FAA0F;QAC1F,GAAG,EACD,OAAO,CAAC,GAAG,CAAC,2BAA2B;YACvC,WAAW,EAAE,QAAQ,EAAE,GAAG;YAC1B,QAAQ;KACX;IACD,IAAI,EACF,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC/B,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC7C,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACzC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,IAAI,IAAI,CAAC;CAClC,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC;AAC7B,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AAQjC,MAAM,CAAC,MAAM,MAAM,GAAW;IAC5B,QAAQ,EAAE;QACR,0FAA0F;QAC1F,GAAG,EACD,OAAO,CAAC,GAAG,CAAC,2BAA2B;YACvC,WAAW,EAAE,QAAQ,EAAE,GAAG;YAC1B,QAAQ;KACX;IACD,IAAI,EACF,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC/B,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC7C,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACzC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,IAAI,IAAI,CAAC;IACjC,GAAG,EAAE,IAAI;CACV,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";AAqBA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAoB9E,eAAO,MAAM,gBAAgB,GAC3B,UAAS,kBAAuB,KAC/B,OAAO,CAAC,kBAAkB,CAiF5B,CAAC;AAEF,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";AA0BA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAyI9E,eAAO,MAAM,gBAAgB,GAC3B,UAAS,kBAAuB,KAC/B,OAAO,CAAC,kBAAkB,CAmB5B,CAAC;AAEF,cAAc,YAAY,CAAC"}
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { startAPI } from "@powerhousedao/reactor-api";
3
+ import { VitePackageLoader, startViteServer, } from "@powerhousedao/reactor-api/packages/vite-loader";
3
4
  import * as Sentry from "@sentry/node";
4
5
  import { InMemoryCache, ReactorBuilder, driveDocumentModelModule, } from "document-drive";
6
+ import { DocumentAlreadyExistsError } from "document-drive/server/error";
5
7
  import RedisCache from "document-drive/cache/redis";
6
8
  import { FilesystemStorage } from "document-drive/storage/filesystem";
7
9
  import { PrismaStorageFactory } from "document-drive/storage/prisma";
@@ -24,6 +26,106 @@ if (process.env.SENTRY_DSN) {
24
26
  Sentry.setupExpressErrorHandler(app);
25
27
  }
26
28
  const DEFAULT_PORT = process.env.PORT ? Number(process.env.PORT) : 4001;
29
+ async function initServer(serverPort, options) {
30
+ const { dev, packages = [], remoteDrives = [] } = options;
31
+ // start redis if configured
32
+ const redisUrl = process.env.REDIS_TLS_URL ?? process.env.REDIS_URL;
33
+ let redis;
34
+ if (redisUrl) {
35
+ try {
36
+ redis = await initRedis(redisUrl);
37
+ }
38
+ catch (e) {
39
+ console.error(e);
40
+ }
41
+ }
42
+ const connectionString = process.env.DATABASE_URL ?? "./.ph/drive-storage";
43
+ const dbUrl = connectionString.includes("amazonaws") &&
44
+ !connectionString.includes("sslmode=no-verify")
45
+ ? connectionString + "?sslmode=no-verify"
46
+ : connectionString;
47
+ const cache = redis ? new RedisCache(redis) : new InMemoryCache();
48
+ const storageFactory = dbUrl.startsWith("postgresql")
49
+ ? new PrismaStorageFactory(dbUrl, cache)
50
+ : undefined;
51
+ const storage = storageFactory
52
+ ? storageFactory.build()
53
+ : new FilesystemStorage(path.join(process.cwd(), dbUrl));
54
+ const reactor = new ReactorBuilder([
55
+ documentModelDocumentModelModule,
56
+ driveDocumentModelModule,
57
+ ])
58
+ .withStorage(storage)
59
+ .withCache(cache)
60
+ .build();
61
+ // init drive server
62
+ await reactor.initialize();
63
+ const dbPath = dbUrl.startsWith("postgresql") ? dbUrl : ".ph/read-storage";
64
+ let defaultDriveUrl = undefined;
65
+ // Create default drive if provided
66
+ if (options.drive) {
67
+ defaultDriveUrl = await addDefaultDrive(reactor, options.drive, serverPort);
68
+ }
69
+ // start vite server if dev mode is enabled
70
+ const vite = dev ? await startViteServer() : undefined;
71
+ // get paths to local document models
72
+ if (dev) {
73
+ // TODO get path from powerhouse config
74
+ const basePath = process.cwd();
75
+ packages.push(basePath);
76
+ }
77
+ // create loader
78
+ const packageLoader = vite ? await VitePackageLoader.build(vite) : undefined;
79
+ // Start the API with the reactor and options
80
+ const api = await startAPI(reactor, {
81
+ express: app,
82
+ port: serverPort,
83
+ dbPath: options.dbPath ?? dbPath,
84
+ https: options.https,
85
+ packageLoader,
86
+ packages: options.packages,
87
+ configFile: options.configFile ?? path.join(process.cwd(), "powerhouse.config.json"),
88
+ mcp: options.mcp ?? true,
89
+ });
90
+ // add vite middleware after express app is initialized if applicable
91
+ if (vite) {
92
+ api.app.use(vite.middlewares);
93
+ }
94
+ // Connect to remote drives AFTER packages are loaded
95
+ if (remoteDrives.length > 0) {
96
+ for (const remoteDriveUrl of remoteDrives) {
97
+ try {
98
+ await reactor.addRemoteDrive(remoteDriveUrl, {
99
+ availableOffline: true,
100
+ sharingType: "public",
101
+ listeners: [],
102
+ triggers: [],
103
+ });
104
+ // Use the first remote drive URL as the default
105
+ if (!defaultDriveUrl) {
106
+ defaultDriveUrl = remoteDriveUrl;
107
+ }
108
+ }
109
+ catch (error) {
110
+ if (error instanceof DocumentAlreadyExistsError) {
111
+ console.info(`Remote drive already added: ${remoteDriveUrl}`);
112
+ // Still use this drive URL as default if not already set
113
+ if (!defaultDriveUrl) {
114
+ defaultDriveUrl = remoteDriveUrl;
115
+ }
116
+ }
117
+ else {
118
+ console.error(`Failed to connect to remote drive ${remoteDriveUrl}:`, error);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ return {
124
+ defaultDriveUrl,
125
+ api,
126
+ reactor,
127
+ };
128
+ }
27
129
  export const startSwitchboard = async (options = {}) => {
28
130
  const serverPort = options.port ?? DEFAULT_PORT;
29
131
  if (process.env.PYROSCOPE_SERVER_ADDRESS) {
@@ -36,56 +138,7 @@ export const startSwitchboard = async (options = {}) => {
36
138
  }
37
139
  }
38
140
  try {
39
- const redisUrl = process.env.REDIS_TLS_URL ?? process.env.REDIS_URL;
40
- let redis;
41
- if (redisUrl) {
42
- try {
43
- redis = await initRedis(redisUrl);
44
- }
45
- catch (e) {
46
- console.error(e);
47
- }
48
- }
49
- const connectionString = process.env.DATABASE_URL ?? "./.ph/drive-storage";
50
- const dbUrl = connectionString.includes("amazonaws") &&
51
- !connectionString.includes("sslmode=no-verify")
52
- ? connectionString + "?sslmode=no-verify"
53
- : connectionString;
54
- const cache = redis ? new RedisCache(redis) : new InMemoryCache();
55
- const storageFactory = dbUrl.startsWith("postgresql")
56
- ? new PrismaStorageFactory(dbUrl, cache)
57
- : undefined;
58
- const storage = storageFactory
59
- ? storageFactory.build()
60
- : new FilesystemStorage(path.join(process.cwd(), dbUrl));
61
- const reactor = new ReactorBuilder([
62
- documentModelDocumentModelModule,
63
- driveDocumentModelModule,
64
- ])
65
- .withStorage(storage)
66
- .withCache(cache)
67
- .build();
68
- // init drive server
69
- await reactor.initialize();
70
- const dbPath = dbUrl.startsWith("postgresql") ? dbUrl : ".ph/read-storage";
71
- let defaultDriveUrl = undefined;
72
- if (options.drive) {
73
- defaultDriveUrl = await addDefaultDrive(reactor, options.drive, serverPort);
74
- }
75
- // Start the API with the reactor and options
76
- await startAPI(reactor, {
77
- express: app,
78
- port: serverPort,
79
- dbPath: options.dbPath ?? dbPath,
80
- https: options.https,
81
- packages: options.packages,
82
- configFile: options.configFile ??
83
- path.join(process.cwd(), "powerhouse.config.json"),
84
- });
85
- return {
86
- defaultDriveUrl,
87
- reactor,
88
- };
141
+ return await initServer(serverPort, options);
89
142
  }
90
143
  catch (e) {
91
144
  Sentry.captureException(e);