(config: ChatLabConfig)
| 75 | } |
| 76 | |
| 77 | function ensureToken(config: ChatLabConfig): string { |
| 78 | if (config.api.token) return config.api.token |
| 79 | |
| 80 | const token = `clb_${crypto.randomBytes(32).toString('hex')}` |
| 81 | try { |
| 82 | writeConfigField('api', 'token', token) |
| 83 | } catch { |
| 84 | // best-effort: token still usable for this session |
| 85 | } |
| 86 | return token |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * 启动独立 HTTP API 服务 |
no test coverage detected