Commit Graph
3 Commits
Author SHA1 Message Date
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
Danielle Maywood 29a731375e refactor: untangle workspace creation from http logic (#19639)
Coder Tasks requires us to create a workspace, but we want to be able to
return a `codersdk.Task` instead of a `codersdk.Workspace`. This
requires untangling `createWorkspace` from directly writing to
`http.ResponseWriter`.
2025-08-29 14:17:33 +01:00
Steven Masley 699dd8e554 chore: create interface for pkgs to return codersdk errors (#18719)
This interface allows it to create rich codersdk errors and pass them up to the `wsbuilder` error handling.
2025-07-03 08:33:45 -05:00