* List available Coder templates.
()
| 876 | * List available Coder templates. |
| 877 | */ |
| 878 | async listTemplates(): Promise<CoderListTemplatesResult> { |
| 879 | try { |
| 880 | const stdout = await this.runCoderJsonCommand(["templates", "list", "--output=json"]); |
| 881 | |
| 882 | // Handle empty output (no templates) |
| 883 | if (!stdout.trim()) { |
| 884 | return { ok: true, templates: [] }; |
| 885 | } |
| 886 | |
| 887 | // CLI returns [{Template: {...}}, ...] wrapper structure |
| 888 | const raw = JSON.parse(stdout) as Array<{ |
| 889 | Template: { |
| 890 | name: string; |
| 891 | display_name?: string; |
| 892 | organization_name?: string; |
| 893 | }; |
| 894 | }>; |
| 895 | |
| 896 | return { |
| 897 | ok: true, |
| 898 | templates: raw.map((entry) => ({ |
| 899 | name: entry.Template.name, |
| 900 | displayName: entry.Template.display_name ?? entry.Template.name, |
| 901 | organizationName: entry.Template.organization_name ?? "default", |
| 902 | })), |
| 903 | }; |
| 904 | } catch (error) { |
| 905 | const message = sanitizeCoderCliErrorForUi(error); |
| 906 | // Surface CLI failures so the UI doesn't show "No templates" incorrectly. |
| 907 | log.warn("Failed to list Coder templates", { error }); |
| 908 | return { ok: false, error: message || "Unknown error" }; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * List presets for a template. |
no test coverage detected