(options: WorkspaceOptions)
| 269 | declare readonly stat?: ThinkWorkspaceCompatibility["stat"]; |
| 270 | |
| 271 | constructor(options: WorkspaceOptions) { |
| 272 | this.#now = options.now ?? Date.now; |
| 273 | this.#waitUntil = options.waitUntil; |
| 274 | this.#retryScheduler = options.retryScheduler; |
| 275 | this.#retryInitialDelayMs = positiveRetryOption( |
| 276 | options.retry?.initialDelayMs, |
| 277 | DEFAULT_RETRY_INITIAL_DELAY_MS, |
| 278 | "initialDelayMs", |
| 279 | ); |
| 280 | this.#retryMaxDelayMs = positiveRetryOption( |
| 281 | options.retry?.maxDelayMs, |
| 282 | DEFAULT_RETRY_MAX_DELAY_MS, |
| 283 | "maxDelayMs", |
| 284 | ); |
| 285 | this.#retryMaxAttempts = positiveRetryOption( |
| 286 | options.retry?.maxAttempts, |
| 287 | DEFAULT_RETRY_MAX_ATTEMPTS, |
| 288 | "maxAttempts", |
| 289 | ); |
| 290 | this.#sessionId = options.sessionId ?? ""; |
| 291 | this.#gitFactory = options.git; |
| 292 | this.#defaultGitIdentity = options.defaultGitIdentity; |
| 293 | this.#useThink = options.useThink ?? false; |
| 294 | this.#artifacts = options.artifacts |
| 295 | ? createArtifact( |
| 296 | options.artifacts.binding, |
| 297 | options.artifacts.sessionId ?? options.sessionId ?? "", |
| 298 | ) |
| 299 | : createDisabledArtifactsClient(); |
| 300 | this.#db = new Database(options.storage); |
| 301 | initializeSchema(this.#db, this.#now); |
| 302 | this.#fs = new WorkspaceFilesystem(this.#db, { now: this.#now }); |
| 303 | const registered = (options.backends ?? []).slice(); |
| 304 | if (registered.some((backend) => isModuleBackend(backend) && backend.requiresWaitUntil)) { |
| 305 | if (!options.waitUntil) { |
| 306 | throw new Error( |
| 307 | "Workspace module backend requires waitUntil; pass ctx.waitUntil.bind(ctx).", |
| 308 | ); |
| 309 | } |
| 310 | } |
| 311 | this.#backends = registered.filter( |
| 312 | (backend): backend is WorkspaceBackend => !isModuleBackend(backend), |
| 313 | ); |
| 314 | this.#backendsById = new Map(this.#backends.map((backend) => [backend.id, backend])); |
| 315 | this.#moduleBackendsById = new Map( |
| 316 | registered.filter(isModuleBackend).map((backend) => [backend.id, backend]), |
| 317 | ); |
| 318 | this.#registeredBackendIds = new Set(); |
| 319 | this.#callableBackendIds = new Set( |
| 320 | registered.filter((backend) => backend.callable === true).map((backend) => backend.id), |
| 321 | ); |
| 322 | for (const backend of registered) { |
| 323 | if (this.#registeredBackendIds.has(backend.id)) { |
| 324 | throw new Error( |
| 325 | `Workspace: duplicate backend id ${JSON.stringify(backend.id)}. ` + |
| 326 | "Pass an explicit `id` on each backend's constructor options to " + |
| 327 | "distinguish them.", |
| 328 | ); |
nothing calls this directly
no test coverage detected