fix: integrate Claude CLI provider state

This commit is contained in:
Bohdan Triapitsyn
2026-08-15 01:59:26 +03:00
parent 72cd861eb8
commit d353638f39
17 changed files with 229 additions and 21 deletions
+5 -4
View File
@@ -3,6 +3,7 @@ import * as gitHttp from './gitApiHttp';
import { opencodeClient } from './opencode/client';
import { renderMagicPrompt } from './magicPrompts';
import { runtimeFetch } from './runtime-fetch';
import { requestSmallModel } from './smallModelRequest';
import { materializeOpenDraftSession, useSessionUIStore } from '@/sync/session-ui-store';
import { useSelectionStore } from '@/sync/selection-store';
import { useConfigStore } from '@/stores/useConfigStore';
@@ -283,7 +284,7 @@ export async function generateCommitMessage(
try {
const diffs = await collectSelectedFileDiffs(directory, files);
const { currentProviderId, currentModelId } = useConfigStore.getState();
const response = await runtimeFetch('/api/small-model/generate', {
const response = await requestSmallModel({
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -293,7 +294,7 @@ export async function generateCommitMessage(
...(currentProviderId ? { preferredProviderID: currentProviderId } : {}),
...(currentModelId ? { preferredModelID: currentModelId } : {}),
}),
});
}, { silentStatuses: [404] });
if (response.status === 404) {
// No authenticated provider has a small model — fall back to the
@@ -411,7 +412,7 @@ export async function generatePullRequestDescription(
try {
const { currentProviderId, currentModelId } = useConfigStore.getState();
const response = await runtimeFetch('/api/small-model/generate', {
const response = await requestSmallModel({
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -421,7 +422,7 @@ export async function generatePullRequestDescription(
...(currentProviderId ? { preferredProviderID: currentProviderId } : {}),
...(currentModelId ? { preferredModelID: currentModelId } : {}),
}),
});
}, { silentStatuses: [404] });
if (response.status === 404) {
// No authenticated provider has a small model — fall back to the
+3 -3
View File
@@ -1,4 +1,4 @@
import { runtimeFetch } from '@/lib/runtime-fetch';
import { requestSmallModel } from '@/lib/smallModelRequest';
import { useConfigStore } from '@/stores/useConfigStore';
import { getSessionLastAssistantModel } from '@/sync/session-actions';
@@ -34,7 +34,7 @@ export async function summarizeSelectionForNotes(text: string, sessionId?: strin
const { currentProviderId, currentModelId } = useConfigStore.getState();
const preferredProviderID = sessionModel?.providerID || currentProviderId || '';
const preferredModelID = sessionModel?.modelID || currentModelId || '';
const response = await runtimeFetch('/api/small-model/generate', {
const response = await requestSmallModel({
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -77,7 +77,7 @@ const GOAL_OBJECTIVE_SYSTEM_PROMPT = [
export async function distillGoalObjective(planContent: string): Promise<string | null> {
try {
const { currentProviderId, currentModelId } = useConfigStore.getState();
const response = await runtimeFetch('/api/small-model/generate', {
const response = await requestSmallModel({
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
+27
View File
@@ -0,0 +1,27 @@
import { toast } from 'sonner';
import { runtimeFetch } from '@/lib/runtime-fetch';
const SMALL_MODEL_TOAST_ID = 'small-model-unavailable';
const notifySmallModelUnavailable = (): void => {
toast.error('Small Model unavailable', {
id: SMALL_MODEL_TOAST_ID,
description: 'Choose another model in Settings → Sessions → Small Model and try again.',
});
};
export async function requestSmallModel(
init: RequestInit,
options: { silentStatuses?: number[] } = {},
): Promise<Response> {
try {
const response = await runtimeFetch('/api/small-model/generate', init);
if (!response.ok && !options.silentStatuses?.includes(response.status)) {
notifySmallModelUnavailable();
}
return response;
} catch (error) {
notifySmallModelUnavailable();
throw error;
}
}