Files
Ethan de42c37f76 refactor(coderd): share chat creation with in-process callers (#30027)
Right now, the only way to create a chat is through `POST
/api/v2/chats`. That's fine for clients, but an integration running
inside coderd (say, a Slack bot) would have to store or mint an API key
just to call its own server.

So, we'll pull chat creation out of the handler into a shared function,
and add `api.CreateChatAsUser` for in-process callers. They get the same
validation, errors, and audit entry as the endpoint, and the endpoint's
behaviour doesn't change. This is the same pattern `chatCreateWorkspace`
already uses to let chatd create workspaces as a user. I've also
exported the chat daemon for in-process callers.

Chat errors are now just values that carry the endpoint's status,
message, and cause, so in-process callers can use `errors.As` on them
(e.g. to spot a prompt hook denial) rather than decoding an HTTP
response. The audit entry is written in the background, as auto-archive
already does, rather than through a fake request. As with an API key, a
dormant user is activated on use, whilst a suspended or deleted user
gets a 403.

The PRs above this one do the same for sending, interrupting, and
updating chats.
2026-10-19 14:37:36 +11:00
..