()
| 211 | } |
| 212 | |
| 213 | async start() { |
| 214 | if (this._started) throw new Error('Proxy already started'); |
| 215 | |
| 216 | this.store = new MailboxStore(this.dataDir); |
| 217 | |
| 218 | this.lifecycle = new LifecycleManager({ |
| 219 | hubUrl: this.hubUrl, |
| 220 | store: this.store, |
| 221 | logger: this.logger, |
| 222 | getTaskMeta: () => this.taskMonitor ? this.taskMonitor.getHeartbeatMeta() : {}, |
| 223 | }); |
| 224 | |
| 225 | this.taskMonitor = new TaskMonitor({ |
| 226 | store: this.store, |
| 227 | logger: this.logger, |
| 228 | }); |
| 229 | |
| 230 | this.skillUpdater = new SkillUpdater({ |
| 231 | store: this.store, |
| 232 | skillPath: this._skillPath, |
| 233 | logger: this.logger, |
| 234 | }); |
| 235 | |
| 236 | this.dmHandler = new DmHandler({ |
| 237 | store: this.store, |
| 238 | logger: this.logger, |
| 239 | }); |
| 240 | |
| 241 | this.sessionHandler = new SessionHandler({ |
| 242 | store: this.store, |
| 243 | logger: this.logger, |
| 244 | }); |
| 245 | |
| 246 | this.traceControl = new TraceControl({ |
| 247 | store: this.store, |
| 248 | logger: this.logger, |
| 249 | }); |
| 250 | try { this.traceControl.pollAndApply(); } catch (e) { |
| 251 | this.logger?.warn?.('[proxy] traceControl initial poll failed:', e.message); |
| 252 | } |
| 253 | |
| 254 | const getHeaders = () => this.lifecycle._buildHeaders(); |
| 255 | const taskMonitor = this.taskMonitor; |
| 256 | |
| 257 | this.sync = new SyncEngine({ |
| 258 | store: this.store, |
| 259 | hubUrl: this.hubUrl, |
| 260 | getHeaders, |
| 261 | logger: this.logger, |
| 262 | onAuthError: () => this.lifecycle.reAuthenticate(), |
| 263 | onOutboundFlushed: () => this._drainProxyTraceBackfill({ |
| 264 | maxMs: TRACE_BACKFILL_RUNTIME_DRAIN_MAX_MS, |
| 265 | }), |
| 266 | onInboundReceived: () => { |
| 267 | try { this.skillUpdater?.pollAndApply(); } catch (e) { |
| 268 | this.logger?.warn?.('[proxy] skillUpdater.pollAndApply failed:', e.message); |
| 269 | } |
| 270 | try { this.traceControl?.pollAndApply(); } catch (e) { |
no test coverage detected