fix(commands): restore /cost slash command and improve command execution errors

The /cost command was listed as built-in but had no handler, causing execution to
fall through to custom command logic and return 400 ("command path is required").

- Add a built-in /cost handler in server/routes/commands.js
- Return the expected payload shape for the chat UI (`action: "cost"`, token usage,
  estimated cost, model)
- Normalize token usage inputs and compute usage percentage
- Add provider-based default pricing for cost estimation
- Fix model selection in command execution context so codex uses `codexModel`
  instead of `claudeModel`
- Improve frontend command error handling by parsing backend error responses and
  showing meaningful error messages instead of a generic failure
This commit is contained in:
Haileyesus
2026-02-11 15:58:49 +03:00
parent 79d7934a4b
commit fa09eba829
2 changed files with 90 additions and 2 deletions

View File

@@ -280,7 +280,7 @@ export function useChatComposerState({
projectName: selectedProject.name,
sessionId: currentSessionId,
provider,
model: provider === 'cursor' ? cursorModel : claudeModel,
model: provider === 'cursor' ? cursorModel : provider === 'codex' ? codexModel : claudeModel,
tokenUsage: tokenBudget,
};
@@ -298,7 +298,14 @@ export function useChatComposerState({
});
if (!response.ok) {
throw new Error('Failed to execute command');
let errorMessage = `Failed to execute command (${response.status})`;
try {
const errorData = await response.json();
errorMessage = errorData?.message || errorData?.error || errorMessage;
} catch {
// Ignore JSON parse failures and use fallback message.
}
throw new Error(errorMessage);
}
const result = (await response.json()) as CommandExecutionResult;
@@ -324,6 +331,7 @@ export function useChatComposerState({
},
[
claudeModel,
codexModel,
currentSessionId,
cursorModel,
handleBuiltInCommand,