( tag: string, template: string, agents?: readonly string[], )
| 91 | * `WorkspaceCreator.create`). Pass an explicit set only to pin a subset. |
| 92 | */ |
| 93 | export async function createWorkspace( |
| 94 | tag: string, |
| 95 | template: string, |
| 96 | agents?: readonly string[], |
| 97 | ): Promise<CreateResult> { |
| 98 | const res = await fetch('/api/workspaces', { |
| 99 | method: 'POST', |
| 100 | headers: { 'content-type': 'application/json' }, |
| 101 | body: JSON.stringify(agents && agents.length > 0 ? { tag, template, agents } : { tag, template }), |
| 102 | }); |
| 103 | if (res.ok) { |
| 104 | const body = (await res.json()) as { workspace: Workspace }; |
| 105 | return { ok: true, workspace: body.workspace }; |
| 106 | } |
| 107 | let err: CreateError; |
| 108 | try { |
| 109 | err = (await res.json()) as CreateError; |
| 110 | } catch { |
| 111 | err = { error: 'bootstrap_failed', message: `HTTP ${res.status}` }; |
| 112 | } |
| 113 | return { ok: false, status: res.status, error: err }; |
| 114 | } |
| 115 | |
| 116 | export interface TemplateInfo { |
| 117 | readonly name: string; |
no test coverage detected