MCPcopy
hub / github.com/coder/mux / createWorkspace

Method createWorkspace

src/node/services/coderService.ts:1279–1358  ·  view source on GitHub ↗

* Create a new Coder workspace. Yields build log lines as they arrive. * * Pre-fetches template parameters and passes defaults via --parameter flags * to avoid interactive prompts during creation. * * @param name Workspace name * @param template Template name * @param preset Opt

(
    name: string,
    template: string,
    preset?: string,
    abortSignal?: AbortSignal,
    org?: string,
    session?: CoderApiSession
  )

Source from the content-addressed store, hash-verified

1277 * @param session Optional API session to reuse across deployment endpoints
1278 */
1279 async *createWorkspace(
1280 name: string,
1281 template: string,
1282 preset?: string,
1283 abortSignal?: AbortSignal,
1284 org?: string,
1285 session?: CoderApiSession
1286 ): AsyncGenerator<string, void, unknown> {
1287 log.debug("Creating Coder workspace", { name, template, preset, org });
1288
1289 if (abortSignal?.aborted) {
1290 throw new Error("Coder workspace creation aborted");
1291 }
1292
1293 // 1. Get deployment URL
1294 const deploymentUrl = await this.getDeploymentUrl(abortSignal);
1295
1296 if (abortSignal?.aborted) {
1297 throw new Error("Coder workspace creation aborted");
1298 }
1299
1300 // 2. Get active template version ID
1301 const versionId = await this.getActiveTemplateVersionId(template, org, abortSignal);
1302
1303 if (abortSignal?.aborted) {
1304 throw new Error("Coder workspace creation aborted");
1305 }
1306
1307 // 3. Get parameter names covered by preset (if any)
1308 const coveredByPreset = preset
1309 ? await this.getPresetParamNames(template, preset, org, abortSignal)
1310 : new Set<string>();
1311
1312 if (abortSignal?.aborted) {
1313 throw new Error("Coder workspace creation aborted");
1314 }
1315
1316 // 4. Fetch all template parameters from API
1317 const allParams = await this.getTemplateRichParameters(
1318 deploymentUrl,
1319 versionId,
1320 name,
1321 session,
1322 abortSignal
1323 );
1324
1325 // 5. Validate required params have values
1326 this.validateRequiredParams(allParams, coveredByPreset);
1327
1328 // 6. Compute extra --parameter flags for non-ephemeral params not in preset
1329 const extraParams = this.computeExtraParams(allParams, coveredByPreset);
1330
1331 log.debug("Computed extra params for coder create", {
1332 name,
1333 template,
1334 preset,
1335 org,
1336 extraParamCount: extraParams.length,

Callers

nothing calls this directly

Calls 9

getDeploymentUrlMethod · 0.95
getPresetParamNamesMethod · 0.95
computeExtraParamsMethod · 0.95
streamCoderCommandFunction · 0.85
debugMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected