Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
27692b6
feat(site/src): edit chat project templates from the project details
jaaydenh Oct 16, 2026
ffa4674
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Oct 16, 2026
2f6c79a
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Oct 16, 2026
1bf80b1
chore(site/src/api/queries): export templateVersionPresetsKey for the…
jaaydenh Oct 16, 2026
7150763
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Oct 16, 2026
b5c4fbb
fix(site/src/pages/AgentsPage/components/ProjectPage): send one templ…
jaaydenh Oct 16, 2026
5afa418
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Oct 19, 2026
8163bb3
test(site/src/pages/AgentsPage/components/ProjectPage): seed presets …
jaaydenh Oct 19, 2026
9f8f89e
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Oct 20, 2026
384312a
fix(site/src/pages/AgentsPage/components): show failed preset and par…
jaaydenh Oct 20, 2026
481a4a1
fix(site/src/pages/AgentsPage/components/ProjectPage): hide template …
jaaydenh Oct 20, 2026
a228884
fix(site/src/pages/AgentsPage/components/ProjectPage): save removal o…
jaaydenh Oct 20, 2026
83c7ea1
Merge branch 'resync-tpl-site-v2' into resync-tpl-project-page-v2
jaaydenh Oct 22, 2026
901379f
Merge branch 'resync-tpl-site' into resync-tpl-page
jaaydenh Nov 13, 2026
46e035b
Merge branch 'cpt-site' into cpt-page
jaaydenh Nov 13, 2026
fd88561
fix(site/src/pages/AgentsPage/components/ProjectPage): block template…
jaaydenh Nov 13, 2026
1bca6c3
refactor(site/src/pages/AgentsPage/components/ProjectPage): share the…
jaaydenh Nov 13, 2026
c279416
docs(docs/coder-agents): document chat project templates
jaaydenh Nov 13, 2026
1f2acf1
test(site/src/pages/AgentsPage/components/ProjectPage): drop a restat…
jaaydenh Nov 13, 2026
a3a5dd8
fix(site/src/pages/AgentsPage/components/ProjectPage): clear the temp…
jaaydenh Nov 13, 2026
39a6ad5
fix(site/src/pages/AgentsPage/components/ProjectPage): keep saved emp…
jaaydenh Nov 13, 2026
7cdfc9b
Merge branch 'cpt-site' into cpt-page
jaaydenh Nov 13, 2026
b2de8e9
fix(site/src/pages/AgentsPage/components/ProjectPage): refresh templa…
jaaydenh Nov 13, 2026
77bf880
docs(docs/coder-agents): note that the template conflict warning need…
jaaydenh Nov 13, 2026
d7afbe4
fix(site/src/pages/AgentsPage/components/ProjectPage): drop default v…
jaaydenh Nov 13, 2026
e737f31
Merge branch 'cpt-site' into cpt-page
jaaydenh Nov 13, 2026
af2f8bc
fix(site/src/pages/AgentsPage/components/ProjectPage): keep dynamic p…
jaaydenh Nov 13, 2026
0e00f35
fix(site/src/pages/AgentsPage/components/ProjectPage): pause template…
jaaydenh Nov 13, 2026
51498b2
fix(site/src/pages/AgentsPage/components/ProjectPage): keep saved emp…
jaaydenh Nov 13, 2026
9242f53
Merge branch 'cpt-site' into cpt-page
jaaydenh Nov 13, 2026
79e266c
fix(site/src/pages/AgentsPage/components/ProjectPage): check for newe…
jaaydenh Nov 13, 2026
caaf9d3
docs(docs/coder-agents): clarify project template edits, defaults, an…
jaaydenh Nov 13, 2026
77a2d19
fix(site/src/pages/AgentsPage/components/ProjectPage): freeze the tem…
jaaydenh Nov 13, 2026
fc7b357
fix(site/src/pages/AgentsPage/components/ProjectPage): keep the templ…
jaaydenh Nov 13, 2026
c8a35df
Merge branch 'cpt-site' into cpt-page
jaaydenh Nov 13, 2026
4018cd4
fix(site/src/pages/AgentsPage/components/ProjectPage): guard double s…
jaaydenh Nov 13, 2026
adc9fe6
fix(site/src/pages/AgentsPage/components/ProjectPage): restore focus …
jaaydenh Nov 13, 2026
185e037
fix(site/src/pages/AgentsPage/components/ProjectPage): return focus t…
jaaydenh Nov 13, 2026
a7c6704
fix(site/src/pages/AgentsPage/components/ProjectPage): wait for fresh…
jaaydenh Nov 13, 2026
75dcc2b
fix(site/src/pages/AgentsPage/components/ProjectPage): keep the templ…
jaaydenh Nov 13, 2026
da71eef
fix(site/src/pages/AgentsPage/components/ProjectPage): pause template…
jaaydenh Nov 13, 2026
a876557
fix(site/src/pages/AgentsPage/components/ProjectPage): track draft ed…
jaaydenh Nov 13, 2026
0a89588
fix(site/src/pages/AgentsPage/components/ProjectPage): settle focus a…
jaaydenh Nov 13, 2026
b8f302b
fix(site/src/pages/AgentsPage/components/ProjectPage): ignore inactiv…
jaaydenh Nov 13, 2026
5061c8e
fix(site/src/pages/AgentsPage/components/ProjectPage): keep Save focu…
jaaydenh Nov 13, 2026
43473b0
fix(site/src/pages/AgentsPage/components/ProjectPage): move focus to …
jaaydenh Nov 13, 2026
a226053
fix(site/src/pages/AgentsPage/components/ProjectPage): refresh eligib…
jaaydenh Nov 13, 2026
1abed3e
fix(site/src/pages/AgentsPage/components/ProjectPage): send a templat…
jaaydenh Nov 13, 2026
d7de855
fix(site/src/pages/AgentsPage/components/ProjectPage): compare only t…
jaaydenh Nov 13, 2026
efb7538
fix(site/src/pages/AgentsPage/components/ProjectPage): recheck parame…
jaaydenh Nov 13, 2026
5c60ca3
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
a0b3f34
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
d6b03ce
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
67c0936
feat(site/src): attach and detach project templates and edit the limi…
jaaydenh Nov 16, 2026
c3bb882
docs: describe attached templates and the opt-in limit for chat projects
jaaydenh Nov 16, 2026
8c0009b
fix(site/src/pages/AgentsPage/components/ProjectPage): rebase the tem…
jaaydenh Nov 16, 2026
4e37101
refactor(site/src/pages/AgentsPage/components/ProjectPage): move the …
jaaydenh Nov 16, 2026
61f73b3
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
842b9dd
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
b71e58d
fix(site/src): show the template limit in project details and save ag…
jaaydenh Nov 16, 2026
01991c1
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
4ff697d
fix(site/src/pages/AgentsPage/components/ProjectPage): pluralize the …
jaaydenh Nov 16, 2026
0099073
docs: correct who can edit project templates and use one term for tem…
jaaydenh Nov 16, 2026
b023449
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
1a7bb6d
chore(site/src/pages/AgentsPage/components/ProjectPage): drop an attr…
jaaydenh Nov 16, 2026
11598eb
Merge branch 'sfh-tpl-site' into sfh-tpl-page
jaaydenh Nov 16, 2026
58005ab
chore(site/src/pages/AgentsPage/components/ProjectPage): inline each …
jaaydenh Nov 16, 2026
59aa7f0
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 16, 2026
abacf16
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
ba26b2d
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
6a1eaf0
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
ae8cb92
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
bb42519
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
a649b31
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
c507b92
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
f4288a1
fix(site): adapt the Edit templates dialog to evaluated default param…
jaaydenh Nov 17, 2026
d6a61b9
Merge branch 'chat-project-templates/site' into chat-project-template…
jaaydenh Nov 17, 2026
164cb9d
test(site): look up evaluated parameters by the preview fixtures
jaaydenh Nov 17, 2026
5c8f775
Merge branch 'chat-project-templates/templates-dialog' into chat-proj…
jaaydenh Nov 18, 2026
ba1dce4
refactor(site): move the templates editor's conflict handling and doc…
jaaydenh Nov 18, 2026
9e2e43e
Merge branch 'chat-project-templates/templates-dialog' into chat-proj…
jaaydenh Nov 18, 2026
2659abc
Merge branch 'chat-project-templates/templates-dialog' into chat-proj…
jaaydenh Nov 18, 2026
cb89438
Merge branch 'chat-project-templates/templates-dialog' into chat-proj…
jaaydenh Nov 18, 2026
c7b0b7d
Merge branch 'chat-project-templates/templates-dialog' into chat-proj…
jaaydenh Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,26 @@ class ExperimentalApiMethods {
return response.data;
};

attachChatProjectTemplate = async (
organizationId: string,
projectId: string,
templateId: string,
): Promise<void> => {
await this.axios.put(
`/api/experimental/organizations/${organizationId}/chats/projects/${projectId}/templates/${templateId}`,
);
};

detachChatProjectTemplate = async (
organizationId: string,
projectId: string,
templateId: string,
): Promise<void> => {
await this.axios.delete(
`/api/experimental/organizations/${organizationId}/chats/projects/${projectId}/templates/${templateId}`,
);
};

deleteChatProject = async (
organizationId: string,
projectId: string,
Expand Down
51 changes: 51 additions & 0 deletions site/src/api/queries/chatProjects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mutationOptions, type QueryClient, queryOptions } from "react-query";
import { API } from "#/api/api";
import { getErrorStatus } from "#/api/errors";
import type * as TypesGen from "#/api/typesGenerated";
import {
chatEntitiesFamilyKey,
Expand Down Expand Up @@ -77,6 +78,56 @@ export type ChatProjectTemplatesChange = {
>;
};

/**
* Attaching first lets the update name a new default template, and detaching
* last keeps the old default when the update fails. The first failure stops
* the save; earlier steps stay saved.
*/
export const updateChatProjectTemplates = (queryClient: QueryClient) =>
mutationOptions({
mutationFn: async ({
project,
change,
}: {
project: TypesGen.ChatProject;
change: ChatProjectTemplatesChange;
}) => {
const { organization_id: organizationId, id: projectId } = project;
for (const templateId of change.attach) {
await API.experimental.attachChatProjectTemplate(
organizationId,
projectId,
templateId,
);
}
if (change.request) {
await API.experimental.updateChatProject(
organizationId,
projectId,
change.request,
);
}
for (const templateId of change.detach) {
try {
await API.experimental.detachChatProjectTemplate(
organizationId,
projectId,
templateId,
);
} catch (error) {
// A 404 means the template is already detached or no longer
// readable, so this user has nothing left to detach.
if (getErrorStatus(error) !== 404) {
throw error;
}
}
}
},
// Returned so the save settles only after the project refreshed.
onSettled: () =>
queryClient.invalidateQueries({ queryKey: chatProjectsKey, exact: true }),
});

export const deleteChatProject = (queryClient: QueryClient) =>
mutationOptions({
mutationFn: (project: TypesGen.ChatProject) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export const templatesValidationDetail = (error: unknown) =>
)?.detail
: undefined;

/**
* Explains the templates attached to a project that the user cannot access.
* Only their count is known.
*/
export const hiddenTemplatesNote = (count: number) => {
const hidden =
count === 1
? "1 template in this project isn't shown because you don't have access to it."
: `${count} templates in this project aren't shown because you don't have access to them.`;
return `${hidden} A template admin or organization admin can give you access.`;
};

const templateLabel = (template: Template) =>
template.display_name || template.name;

Expand All @@ -132,6 +144,8 @@ type ChatProjectTemplatesFieldsProps = {
/** The server's rejection of the saved templates, if any. */
readonly saveError: string | undefined;
readonly value: ChatProjectTemplatesValues;
/** Attached templates the user cannot access, which `templates` lacks. */
readonly hiddenTemplateCount?: number;
readonly onChange: (value: ChatProjectTemplatesValues) => void;
readonly disabled: boolean;
};
Expand All @@ -143,10 +157,24 @@ type ChatProjectTemplatesFieldsProps = {
*/
export const ChatProjectTemplatesFields: React.FC<
ChatProjectTemplatesFieldsProps
> = ({ templates, templatesError, saveError, value, onChange, disabled }) => {
> = ({
templates,
templatesError,
saveError,
value,
hiddenTemplateCount = 0,
onChange,
disabled,
}) => {
const defaultTemplateId = useId();
const hiddenNoteId = useId();
const hiddenNote =
hiddenTemplateCount > 0
? hiddenTemplatesNote(hiddenTemplateCount)
: undefined;
const limitsToNothing =
value.limitTemplates && value.templateIds.length === 0;
value.limitTemplates &&
value.templateIds.length + hiddenTemplateCount === 0;
const options = (templates ?? []).map((template) => ({
value: template.id,
label: templateLabel(template),
Expand Down Expand Up @@ -192,6 +220,9 @@ export const ChatProjectTemplatesFields: React.FC<
{templates && (
<MultiSelectCombobox
commandProps={{ label: "Templates" }}
inputProps={{
"aria-describedby": hiddenNote && hiddenNoteId,
}}
options={options}
value={options.filter((o) => value.templateIds.includes(o.value))}
onChange={(selected) =>
Expand Down Expand Up @@ -219,6 +250,11 @@ export const ChatProjectTemplatesFields: React.FC<
Agents see these templates first when they choose a template for a
workspace.
</p>
{hiddenNote && (
<p id={hiddenNoteId} className="m-0 text-xs text-content-secondary">
{hiddenNote}
</p>
)}
</div>
<SettingSwitch
label="Limit chats to these templates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { chatProjectInstructionsKey } from "#/api/queries/chatProjects";
import type {
ChatProject,
ChatProjectInstructions,
Template,
} from "#/api/typesGenerated";
import { TooltipProvider } from "#/components/Tooltip/Tooltip";
import { ThemeOverride } from "#/contexts/ThemeProvider";
Expand All @@ -20,6 +21,7 @@ import {
MockChatProjectInstructions,
MockOrganizationMember,
MockOrganizationMember2,
MockTemplate,
MockUnsetChatProjectInstructions,
MockUserMember,
mockApiError,
Expand Down Expand Up @@ -647,3 +649,191 @@ describe("ProjectDetailsPanel", () => {
);
});
});

const mockDockerTemplate: Template = {
...MockTemplate,
id: "template-docker",
name: "docker",
display_name: "Docker",
};
const mockKubernetesTemplate: Template = {
...MockTemplate,
id: "template-kubernetes",
name: "kubernetes",
display_name: "Kubernetes",
};

describe("ProjectDetailsPanel templates", () => {
afterEach(() => {
vi.restoreAllMocks();
});

const setup = (project: ChatProject = MockChatProject) => {
mockInstructions(MockUnsetChatProjectInstructions);
vi.spyOn(API, "getTemplates").mockResolvedValue([
mockDockerTemplate,
mockKubernetesTemplate,
]);
vi.spyOn(API, "getTemplateVersionPresets").mockResolvedValue([]);
const attach = vi
.spyOn(API.experimental, "attachChatProjectTemplate")
.mockResolvedValue();
const detach = vi
.spyOn(API.experimental, "detachChatProjectTemplate")
.mockResolvedValue();
const updateProject = vi
.spyOn(API.experimental, "updateChatProject")
.mockResolvedValue(project);
const panel = renderPanel(project);
return {
attach,
detach,
updateProject,
...panel,
};
};

const projectArgs = [MockChatProject.organization_id, MockChatProject.id];
const mockProjectWithTemplates: ChatProject = {
...MockChatProject,
templates: [mockDockerTemplate, mockKubernetesTemplate],
};

it("attaches the templates picked in the editor and sends nothing else", async () => {
const { user, attach, detach, updateProject } = setup();

await user.click(
screen.getByRole("button", { name: "Edit templates: 0 templates" }),
);
await user.click(await screen.findByRole("button", { name: "Select all" }));
await user.click(screen.getByRole("button", { name: "Save" }));

await waitFor(() => expect(attach).toHaveBeenCalledTimes(2));
expect(attach).toHaveBeenCalledWith(...projectArgs, mockDockerTemplate.id);
expect(attach).toHaveBeenCalledWith(
...projectArgs,
mockKubernetesTemplate.id,
);
expect(updateProject).not.toHaveBeenCalled();
expect(detach).not.toHaveBeenCalled();
});

it("attaches the new default, then updates the limit and default, then detaches the old default", async () => {
const { user, attach, detach, updateProject } = setup({
...MockChatProject,
templates: [mockDockerTemplate],
default_template: { template_id: mockDockerTemplate.id },
});

await user.click(
screen.getByRole("button", { name: "Edit templates: 1 template" }),
);
await user.click(
await screen.findByRole("combobox", { name: "Templates" }),
);
await user.click(await screen.findByRole("option", { name: "Kubernetes" }));
await user.click(
screen.getByRole("combobox", { name: "Default template" }),
);
await user.click(screen.getByRole("option", { name: "Kubernetes" }));
await user.click(screen.getByRole("button", { name: "Remove Docker" }));
await user.click(
screen.getByRole("switch", { name: "Limit chats to these templates" }),
);
const save = screen.getByRole("button", { name: "Save" });
await waitFor(() => expect(save).toHaveAttribute("aria-disabled", "false"));
await user.click(save);

await waitFor(() =>
expect(detach).toHaveBeenCalledWith(
...projectArgs,
mockDockerTemplate.id,
),
);
expect(attach.mock.calls).toEqual([
[...projectArgs, mockKubernetesTemplate.id],
]);
expect(updateProject.mock.calls).toEqual([
[
...projectArgs,
{
limit_templates: true,
default_template: { template_id: mockKubernetesTemplate.id },
},
],
]);
expect(detach).toHaveBeenCalledTimes(1);
expect(attach.mock.invocationCallOrder[0]).toBeLessThan(
updateProject.mock.invocationCallOrder[0],
);
expect(updateProject.mock.invocationCallOrder[0]).toBeLessThan(
detach.mock.invocationCallOrder[0],
);
});

it("sends one save when Save is double clicked", async () => {
const { user, attach } = setup();
attach.mockReturnValue(new Promise(() => {}));

await user.click(
screen.getByRole("button", { name: "Edit templates: 0 templates" }),
);
await user.click(await screen.findByRole("button", { name: "Select all" }));
await userEvent
.setup({ delay: null })
.dblClick(screen.getByRole("button", { name: "Save" }));

await waitFor(() => expect(attach).toHaveBeenCalled());
expect(attach).toHaveBeenCalledTimes(1);
});

it("detaches a template removed from the saved templates and sends nothing else", async () => {
const { user, attach, detach, updateProject, rerenderWithProject } =
setup();
rerenderWithProject(mockProjectWithTemplates);

await user.click(
screen.getByRole("button", { name: "Edit templates: 2 templates" }),
);
await user.click(
await screen.findByRole("combobox", { name: "Templates" }),
);
await user.keyboard("{Backspace}");
await user.click(screen.getByRole("button", { name: "Save" }));

await waitFor(() =>
expect(detach.mock.calls).toEqual([
[...projectArgs, mockKubernetesTemplate.id],
]),
);
expect(attach).not.toHaveBeenCalled();
expect(updateProject).not.toHaveBeenCalled();
});

it("returns focus to the edit button when the editor closes", async () => {
const { user } = setup();
const editButton = screen.getByRole("button", {
name: "Edit templates: 0 templates",
});

await user.click(editButton);
await user.click(await screen.findByRole("button", { name: "Cancel" }));

await waitFor(() => expect(editButton).toHaveFocus());
});

it("returns focus to the template count when edit permission is lost while editing", async () => {
const { user, rerenderWithProject } = setup();

await user.click(
screen.getByRole("button", { name: "Edit templates: 0 templates" }),
);
rerenderWithProject({
...MockChatProject,
permissions: { ...MockChatProject.permissions, update: false },
});
await user.click(await screen.findByRole("button", { name: "Cancel" }));

await waitFor(() => expect(screen.getByText("0 templates")).toHaveFocus());
});
});
Loading
Loading