mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fall back to local git watcher for chat diff drawer (#24512)
The Ctrl+D diff drawer in `coder exp agents` only rendered PR-backed
diffs returned by `/api/experimental/chats/{id}/diff`. Local working
tree changes in a chat's workspace returned an empty diff, so the
drawer showed "No diff contents" with no file summary.
Centralise diff loading behind a single `fetchChatDiffContents` helper
that first hits `/diff`, then falls back to the chat git watcher
WebSocket (`/stream/git`) when the remote diff is empty. Aggregate the
agent's `WorkspaceAgentRepoChanges` into a `ChatDiffContents` value so
the drawer can derive the file summary and styled body from the local
unified diff. Missing workspaces, missing agents, and watcher timeouts
are treated as graceful fallbacks that render the empty-diff
placeholder instead of a hard error.
> Mux is opening this PR on Mike's behalf.
This commit is contained in:
@@ -372,15 +372,6 @@ export type GetTemplatesQuery = Readonly<{
|
||||
readonly q: string;
|
||||
}>;
|
||||
|
||||
interface ChatGitChangeResponse extends TypesGen.ChatGitChange {
|
||||
readonly patch?: string;
|
||||
readonly diff_patch?: string;
|
||||
readonly unified_diff?: string;
|
||||
readonly diffs_url?: string;
|
||||
readonly diff_url?: string;
|
||||
readonly diffs_link?: string;
|
||||
}
|
||||
|
||||
function normalizeGetTemplatesOptions(
|
||||
options: GetTemplatesOptions | GetTemplatesQuery = {},
|
||||
): Record<string, string> {
|
||||
@@ -3226,15 +3217,6 @@ class ExperimentalApiMethods {
|
||||
return response.data;
|
||||
};
|
||||
|
||||
getChatGitChanges = async (
|
||||
chatId: string,
|
||||
): Promise<ChatGitChangeResponse[]> => {
|
||||
const response = await this.axios.get<ChatGitChangeResponse[]>(
|
||||
`/api/experimental/chats/${chatId}/git-changes`,
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
getChatDiffContents = async (
|
||||
chatId: string,
|
||||
): Promise<TypesGen.ChatDiffContents> => {
|
||||
|
||||
Generated
+53
@@ -1653,6 +1653,59 @@ export interface ChatGitChange {
|
||||
readonly detected_at: string;
|
||||
}
|
||||
|
||||
// From codersdk/chats.go
|
||||
/**
|
||||
* Chat git watch error messages. These are the user-visible messages
|
||||
* the server returns in 400 responses from
|
||||
* /api/experimental/chats/{id}/stream/git when the chat cannot be
|
||||
* observed through a workspace agent. They are exported so the CLI
|
||||
* (and any future consumer) can match them structurally via
|
||||
* IsChatGitWatchFallbackMessage instead of coupling to exact wording.
|
||||
* Keep these in sync with coderd/exp_chats.go.
|
||||
* ChatGitWatchAgentStatePrefix is the common prefix of the
|
||||
* message produced by ChatGitWatchAgentStateMessage. The CLI
|
||||
* uses it as a mechanical fingerprint for the "agent not yet
|
||||
* connected" case without depending on the formatted values.
|
||||
*/
|
||||
export const ChatGitWatchAgentStatePrefix = "Agent state is ";
|
||||
|
||||
// From codersdk/chats.go
|
||||
/**
|
||||
* Chat git watch error messages. These are the user-visible messages
|
||||
* the server returns in 400 responses from
|
||||
* /api/experimental/chats/{id}/stream/git when the chat cannot be
|
||||
* observed through a workspace agent. They are exported so the CLI
|
||||
* (and any future consumer) can match them structurally via
|
||||
* IsChatGitWatchFallbackMessage instead of coupling to exact wording.
|
||||
* Keep these in sync with coderd/exp_chats.go.
|
||||
*/
|
||||
export const ChatGitWatchNoWorkspaceMessage = "Chat has no workspace to watch.";
|
||||
|
||||
// From codersdk/chats.go
|
||||
/**
|
||||
* Chat git watch error messages. These are the user-visible messages
|
||||
* the server returns in 400 responses from
|
||||
* /api/experimental/chats/{id}/stream/git when the chat cannot be
|
||||
* observed through a workspace agent. They are exported so the CLI
|
||||
* (and any future consumer) can match them structurally via
|
||||
* IsChatGitWatchFallbackMessage instead of coupling to exact wording.
|
||||
* Keep these in sync with coderd/exp_chats.go.
|
||||
*/
|
||||
export const ChatGitWatchWorkspaceNoAgentsMessage =
|
||||
"Chat workspace has no agents.";
|
||||
|
||||
// From codersdk/chats.go
|
||||
/**
|
||||
* Chat git watch error messages. These are the user-visible messages
|
||||
* the server returns in 400 responses from
|
||||
* /api/experimental/chats/{id}/stream/git when the chat cannot be
|
||||
* observed through a workspace agent. They are exported so the CLI
|
||||
* (and any future consumer) can match them structurally via
|
||||
* IsChatGitWatchFallbackMessage instead of coupling to exact wording.
|
||||
* Keep these in sync with coderd/exp_chats.go.
|
||||
*/
|
||||
export const ChatGitWatchWorkspaceNotFoundMessage = "Chat workspace not found.";
|
||||
|
||||
// From codersdk/chats.go
|
||||
/**
|
||||
* ChatInputPart is a single user input part for creating a chat.
|
||||
|
||||
Reference in New Issue
Block a user