MCPcopy Index your code
hub / github.com/coder/mux / getActiveTemplateVersionId

Method getActiveTemplateVersionId

src/node/services/coderService.ts:637–669  ·  view source on GitHub ↗

* Get the active template version ID for a template. * Throws if template not found.

(
    templateName: string,
    org?: string,
    signal?: AbortSignal
  )

Source from the content-addressed store, hash-verified

635 * Throws if template not found.
636 */
637 private async getActiveTemplateVersionId(
638 templateName: string,
639 org?: string,
640 signal?: AbortSignal
641 ): Promise<string> {
642 // Note: `coder templates list` doesn't support --org flag, so we filter client-side
643 const stdout = await this.runCoderJsonCommand(["templates", "list", "--output=json"], {
644 signal,
645 });
646
647 if (!stdout.trim()) {
648 throw new Error(`Template "${templateName}" not found (no templates exist)`);
649 }
650
651 const raw = JSON.parse(stdout) as Array<{
652 Template: {
653 name: string;
654 organization_name: string;
655 active_version_id: string;
656 };
657 }>;
658
659 // Filter by name and optionally by org for disambiguation
660 const template = raw.find(
661 (t) => t.Template.name === templateName && (!org || t.Template.organization_name === org)
662 );
663 if (!template) {
664 const orgSuffix = org ? ` in organization "${org}"` : "";
665 throw new Error(`Template "${templateName}" not found${orgSuffix}`);
666 }
667
668 return template.Template.active_version_id;
669 }
670
671 /**
672 * Get parameter names covered by a preset.

Callers 1

createWorkspaceMethod · 0.95

Calls 2

runCoderJsonCommandMethod · 0.95
parseMethod · 0.45

Tested by

no test coverage detected