Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(ai): improve API retry handling

Abeautifulsnow52d5c99a923b
diff --git a/.gitignore b/.gitignore
index e0ab873c30..514c389733 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,6 +50,10 @@ Thumbs.db
# Temp
tmp/
+# Code review tool artifacts
+review_diff.json
+review_classified.json
+
# Logs
*.log
diff --git a/Cargo.lock b/Cargo.lock
index 3d8b9ba386..9591b00f43 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1920,6 +1920,7 @@ dependencies = [
"flate2",
"font-kit",
"futures",
+ "httpdate",
"iana-time-zone",
"insta",
"json5",
diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
index 7a07e06191..b9e50aec56 100644
--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue
+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
@@ -65,6 +65,8 @@ import {
getAppSupportInfo,
loadMaxAgentTurns,
saveMaxAgentTurns,
+ loadMaxRetries,
+ saveMaxRetries,
saveWebdavSyncSecretsPreference,
saveWebdavSavedPassword,
saveSnippetSavedToken,
@@ -148,12 +150,28 @@ const selectedLocaleOption = computed(() => LOCALE_OPTIONS.find((locale) => loca
const appThemeModeOptions = computed(() => [
{ value: "light" as AppThemeMode, label: t("toolbar.themeLight"), icon: Sun },
{ value: "dark" as AppThemeMode, label: t("toolbar.themeDark"), icon: Moon },
- { value: "system" as AppThemeMode, label: t("toolbar.themeSystem"), icon: SunMoon },
+ {
+ value: "system" as AppThemeMode,
+ label: t("toolbar.themeSystem"),
+ icon: SunMoon,
+ },
]);
const appCornerStyleOptions = computed(() => [
- { value: "none" as AppCornerStyle, label: t("settings.cornerStyleNone"), previewRadius: "0px" },
- { value: "small" as AppCornerStyle, label: t("settings.cornerStyleSmall"), previewRadius: "4px" },
- { value: "large" as AppCornerStyle, label: t("settings.cornerStyleLarge"), previewRadius: "10px" },
+ {
+ value: "none" as AppCornerStyle,
+ label: t("settings.cornerStyleNone"),
+ previewRadius: "0px",
+ },
+ {
+ value: "small" as AppCornerStyle,
+ label: t("settings.cornerStyleSmall"),
+ previewRadius: "4px",
+ },
+ {
+ value: "large" as AppCornerStyle,
+ label: t("settings.cornerStyleLarge"),
+ previewRadius: "10px",
+ },
]);
const props = defineProps<{
@@ -333,7 +351,9 @@ function setSqlVariableSyntaxToggle(key: keyof SqlVariableSyntaxToggles, value:
...editSqlVariableSyntaxOverrides.value[dbType],
[key]: value,
};
- const next: SqlVariableSyntaxOverrides = { ...editSqlVariableSyntaxOverrides.value };
+ const next: SqlVariableSyntaxOverrides = {
+ ...editSqlVariableSyntaxOverrides.value,
+ };
// Keep storage sparse: an all-enabled type has no entry; otherwise persist only the disabled syntaxes.
if (SQL_VARIABLE_SYNTAX_KEYS.every((toggleKey) => merged[toggleKey])) {
delete next[dbType];
@@ -490,13 +510,19 @@ const snippetDialogOpen = ref(false);
const snippetEditingId = ref<string | null>(null);
const snippetForm = ref({ label: "", prefix: "", body: "" });
const snippetFormPrefixError = ref("");
-const iconThemeDescTruncated = { default: ref<boolean>(false), black: ref<boolean>(false) };
+const iconThemeDescTruncated = {
+ default: ref<boolean>(false),
+ black: ref<boolean>(false),
+};
const iconThemeDescRef = {
default: ref<HTMLElement | null>(null),
black: ref<HTMLElement | null>(null),
};
const iconThemeBlackDescriptionText = computed(() => (isMacOS() ? t("settings.iconThemeBlackDescriptionMac") : t("settings.iconThemeBlackDescription")));
-const layoutDescTruncated = { separated: ref<boolean>(false), classic: ref<boolean>(false) };
+const layoutDescTruncated = {
+ separated: ref<boolean>(false),
+ classic: ref<boolean>(false),
+};
const layoutDescRefs = {
separated: ref<HTMLElement | null>(null),
classic: ref<HTMLElement | null>(null),
@@ -580,7 +606,11 @@ function openAddSnippetDialog() {
function openEditSnippetDialog(snippet: SqlSnippet) {
snippetEditingId.value = snippet.id;
- snippetForm.value = { label: snippet.label, prefix: snippet.prefix, body: snippet.body };
+ snippetForm.value = {
+ label: snippet.label,
+ prefix: snippet.prefix,
+ body: snippet.body,
+ };
snippetFormPrefixError.value = "";
snippetDialogOpen.value = true;
}
@@ -1275,7 +1305,10 @@ function cancelShortcutEdit() {
function resetShortcut(actionId: ShortcutActionId) {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
if (!definition) return;
- editShortcuts.value = { ...editShortcuts.value, [actionId]: definition.defaultShortcut };
+ editShortcuts.value = {
+ ...editShortcuts.value,
+ [actionId]: definition.defaultShortcut,
+ };
}
function clearShortcut(actionId: ShortcutActionId) {
@@ -1685,7 +1718,10 @@ async function uploadSnippetSnapshot() {
const summary = await snippetSyncUpload(currentSnippetConfig(), settingsStore.editorSettings, webdavSyncSecrets.value ? webdavSecretsPassphrase.value : undefined);
snippetId.value = summary.snippetId;
localStorage.setItem(`dbx-snippet-id-${snippetProvider.value}`, summary.snippetId);
- return t("settings.syncSnippetUploadSuccess", { bytes: summary.bytes, id: summary.snippetId });
+ return t("settings.syncSnippetUploadSuccess", {
+ bytes: summary.bytes,
+ id: summary.snippetId,
+ });
});
}
@@ -1701,7 +1737,10 @@ async function downloadSnippetSnapshot() {
// the already-loaded Pinia store instead of leaving the UI stale.
await tunnelProfileStore.refresh();
await settingsStore.reloadAiConfigs();
- let message = t("settings.syncSnippetDownloadSuccess", { bytes: result.summary.bytes, id: result.summary.snippetId });
+ let message = t("settings.syncSnippetDownloadSuccess", {
+ bytes: result.summary.bytes,
+ id: result.summary.snippetId,
+ });
if (result.applySummary.encryptedSecretsPresent && !result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsSkipped")}`;
if (result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsApplied")}`;
return message;
@@ -1823,7 +1862,10 @@ async function testWebDav() {
async function uploadWebDavSnapshot() {
await runWebDavAction("upload", async () => {
const summary = await webdavSyncUpload(currentWebDavConfig(), settingsStore.editorSettings, webdavSyncSecrets.value ? webdavSecretsPassphrase.value : undefined);
- return t("settings.syncUploadSuccess", { bytes: summary.bytes, path: summary.remotePath });
+ return t("settings.syncUploadSuccess", {
+ bytes: summary.bytes,
+ path: summary.remotePath,
+ });
});
}
@@ -1864,7 +1906,10 @@ const changingPassword = ref(false);
async function scrollToInitialSettingsSection() {
await nextTick();
if (props.initialSection === "tableColumnTemplates") {
- tableColumnTemplateSectionRef.value?.scrollIntoView({ block: "center", behavior: "smooth" });
+ tableColumnTemplateSectionRef.value?.scrollIntoView({
+ block: "center",
+ behavior: "smooth",
+ });
}
}
@@ -1896,7 +1941,12 @@ watch(
localStorage.removeItem(MCP_SCOPE_CONNECTION_STORAGE_KEY);
} catch (e: any) {
mcpPolicyLoadError.value = e?.message || String(e);
- toast(t("settings.mcpPolicyLoadFailed", { error: mcpPolicyLoadError.value }), 5000);
+ toast(
+ t("settings.mcpPolicyLoadFailed", {
+ error: mcpPolicyLoadError.value,
+ }),
+ 5000,
+ );
} finally {
mcpPolicyLoading.value = false;
}
@@ -1969,6 +2019,7 @@ watch(activeSettingsTab, async (tab) => {
if (tab === "ai" && aiIsCliProvider.value) void ensureCliMcpStatus();
if (tab === "ai") {
void loadMaxAgentTurnsSetting();
+ void loadMaxRetriesSetting();
// Await completion so we don't snapshot an empty default when the store
// is still loading its first payload (init via App.vue is fire-and-forget).
await promptTemplateStore.ensureLoaded();
@@ -2017,7 +2068,10 @@ async function changePassword() {
const res = await fetch(apiUrl("/api/auth/change-password"), {
method: "POST",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ old_password: oldPassword.value, new_password: newPassword.value }),
+ body: JSON.stringify({
+ old_password: oldPassword.value,
+ new_password: newPassword.value,
+ }),
});
if (res.ok) {
passwordMessage.value = t("auth.passwordChanged");
@@ -2049,7 +2103,10 @@ const globalInstructionsSaving = ref(false);
// Prompt Templates Management
const templateEditing = ref<PromptTemplate | null>(null);
const templateFormOpen = ref(false);
-const templateForm = ref<{ name: string; content: string }>({ name: "", content: "" });
+const templateForm = ref<{ name: string; content: string }>({
+ name: "",
+ content: "",
+});
const templateFormIsNew = ref(true);
const templateSaving = ref(false);
const templateDeleteConfirm = ref<PromptTemplate | null>(null);
@@ -2191,6 +2248,54 @@ async function saveMaxAgentTurnsSetting() {
}
}
+// Max Retries (global). Default 2, range 0–10. Applied to all API-backed
+// AI providers. CLI providers (claude-code, codex, pi) are unaffected
+// because they use their own retry logic.
+const editMaxRetries = ref<number | undefined>(undefined);
+const maxRetriesSaving = ref(false);
+const maxRetriesLoaded = ref(false);
+const maxRetriesLoading = ref(false);
+const maxRetriesLoadError = ref("");
+
+async function loadMaxRetriesSetting() {
+ if (maxRetriesLoaded.value || maxRetriesLoading.value) return;
+ maxRetriesLoading.value = true;
+ maxRetriesLoadError.value = "";
+ try {
+ editMaxRetries.value = await loadMaxRetries();
+ maxRetriesLoaded.value = true;
+ } catch (e: any) {
+ maxRetriesLoadError.value = e?.message || String(e);
+ toast(maxRetriesLoadError.value, 5000);
+ } finally {
+ maxRetriesLoading.value = false;
+ }
+}
+
+async function saveMaxRetriesSetting() {
+ if (!maxRetriesLoaded.value) return;
+ const clamped = normalizeMaxRetries(editMaxRetries.value);
+ maxRetriesSaving.value = true;
+ try {
+ await saveMaxRetries(clamped);
+ editMaxRetries.value = clamped;
+ toast(t("ai.maxRetriesSaved"));
+ } catch (e: any) {
+ toast(e?.message || String(e), 5000);
+ } finally {
+ maxRetriesSaving.value = false;
+ }
+}
+
+function maxRetriesOutOfRange(value: number | undefined): boolean {
+ return typeof value === "number" && (value < 0 || value > 10);
+}
+
+function normalizeMaxRetries(value: number | undefined): number {
+ const rounded = typeof value === "number" && Number.isFinite(value) ? Math.round(value) : 2;
+ return Math.min(10, Math.max(0, rounded));
+}
+
// AI Config Delete Confirmation
const aiDeleteConfirmOpen = ref(false);
const aiDeleteConfigId = ref<string | null>(null);
@@ -2329,7 +2434,11 @@ const aiCliPathError = computed(() => {
const aiCliValidationError = computed(() => (aiIsCliProvider.value ? aiCliPathError.value || aiCliEnvError.value : ""));
function aiEnvRowsFromConfig(env: unknown): AiEnvRow[] {
- return Object.entries(normalizeAiEnv(env)).map(([key, value]) => ({ id: uuid(), key, value }));
+ return Object.entries(normalizeAiEnv(env)).map(([key, value]) => ({
+ id: uuid(),
+ key,
+ value,
+ }));
}
function cliEnvFromRows(rows = aiEditCliEnvRows.value): Record<string, string> {
@@ -2647,7 +2756,12 @@ let diagnosticComp: import("@codemirror/state").Compartment | null = null;
let previewRunGutterComp: import("@codemirror/state").Compartment | null = null;
let currentStatementFrameComp: import("@codemirror/state").Compartment | null = null;
let setPreviewDiagnosticsEffect: import("@codemirror/state").StateEffectType<PreviewSqlDiagnostic[]> | null = null;
-let setPreviewRunHighlightEffect: import("@codemirror/state").StateEffectType<{ from: number; to: number } | null> | null = null;
+let setPreviewRunHighlightEffect:
+ | import("@codemirror/state").StateEffectType<{
+ from: number;
+ to: number;
+ } | null>
+ | null = null;
let editorViewModule: typeof import("@codemirror/view") | null = null;
let previewSqlDiagnostics: PreviewSqlDiagnostic[] = [];
let previewExecutableCache: ExecutableStatementRangeCache | null = null;
@@ -2691,14 +2805,18 @@ function previewExecutableStatementRangeStartingAt(currentView: EditorViewType,
function clearPreviewRunHighlight() {
previewRunHighlightRange = null;
if (previewView.value && setPreviewRunHighlightEffect) {
- previewView.value.dispatch({ effects: setPreviewRunHighlightEffect.of(null) });
+ previewView.value.dispatch({
+ effects: setPreviewRunHighlightEffect.of(null),
+ });
}
}
function flashPreviewRunHighlight(range: { from: number; to: number }, event: Event) {
previewRunHighlightRange = range;
if (previewView.value && setPreviewRunHighlightEffect) {
- previewView.value.dispatch({ effects: setPreviewRunHighlightEffect.of(range) });
+ previewView.value.dispatch({
+ effects: setPreviewRunHighlightEffect.of(range),
+ });
}
if (event.target instanceof Element) {
const marker = event.target.closest(".cm-run-statement-marker");
@@ -2780,7 +2898,14 @@ function buildPreviewCurrentStatementFrameExtension(viewModule: Pick<typeof impo
const classes = ["cm-db-current-statement-line"];
if (lineNumber === startLine.number) classes.push("cm-db-current-statement-line--first");
if (lineNumber === endLine.number) classes.push("cm-db-current-statement-line--last");
- deco.push(Decoration.line({ class: classes.join(" "), attributes: { style: `--dbx-current-statement-frame-width: ${frameWidth};` } }).range(line.from));
+ deco.push(
+ Decoration.line({
+ class: classes.join(" "),
+ attributes: {
+ style: `--dbx-current-statement-frame-width: ${frameWidth};`,
+ },
+ }).range(line.from),
+ );
}
return Decoration.set(deco);
}
@@ -2856,14 +2981,21 @@ watch(previewRef, async (el) => {
const [{ EditorView, Decoration, ViewPlugin, gutter, GutterMarker }, { EditorState, Compartment, StateEffect, StateField }, { sql, MySQL }, { basicSetup }] = await Promise.all([import("@codemirror/view"), import("@codemirror/state"), import("@codemirror/lang-sql"), import("codemirror")]);
- editorViewModule = { Decoration, EditorView, ViewPlugin } as typeof import("@codemirror/view");
+ editorViewModule = {
+ Decoration,
+ EditorView,
+ ViewPlugin,
+ } as typeof import("@codemirror/view");
fontThemeComp = new Compartment();
themeComp = new Compartment();
diagnosticComp = new Compartment();
previewRunGutterComp = new Compartment();
currentStatementFrameComp = new Compartment();
setPreviewDiagnosticsEffect = StateEffect.define<PreviewSqlDiagnostic[]>();
- setPreviewRunHighlightEffect = StateEffect.define<{ from: number; to: number } | null>();
+ setPreviewRunHighlightEffect = StateEffect.define<{
+ from: number;
+ to: number;
+ } | null>();
previewSqlDiagnostics = previewDiagnosticsForSql(currentPreviewSql());
const ss = previewSettings.value;
@@ -2921,7 +3053,17 @@ watch(previewRef, async (el) => {
const buildPreviewRunHighlightExtension = () => {
const highlightEffect = setPreviewRunHighlightEffect;
- const buildDecorations = () => (previewRunHighlightRange ? Decoration.set([Decoration.mark({ class: "cm-settings-preview-run-highlight" }).range(previewRunHighlightRange.from, previewRunHighlightRange.to)], true) : Decoration.none);
+ const buildDecorations = () =>
+ previewRunHighlightRange
+ ? Decoration.set(
+ [
+ Decoration.mark({
+ class: "cm-settings-preview-run-highlight",
+ }).range(previewRunHighlightRange.from, previewRunHighlightRange.to),
+ ],
+ true,
+ )
+ : Decoration.none;
const field = StateField.define({
create: buildDecorations,
update(value, transaction) {
@@ -3010,7 +3152,11 @@ onUnmounted(cleanupPreviewEditor);
</template>
<template #custom-option-label="{ value }">
<span class="truncate" :style="{ fontFamily: value }">
- {{ t("settings.useCustomFont", { font: readableFontFamily(value) }) }}
+ {{
+ t("settings.useCustomFont", {
+ font: readableFontFamily(value),
+ })
+ }}
</span>
</template>
</SearchableSelect>
@@ -3074,7 +3220,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-show-execution-target-picker">{{ t("settings.showExecutionTargetPicker") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.showExecutionTargetPickerDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.showExecutionTargetPickerDescription") }}
+ </p>
</div>
<Switch id="editor-show-execution-target-picker" v-model="editShowExecutionTargetPicker" class="mt-0.5" />
</div>
@@ -3082,7 +3230,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-show-statement-run-buttons">{{ t("settings.showStatementRunButtons") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.showStatementRunButtonsDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.showStatementRunButtonsDescription") }}
+ </p>
</div>
<Switch id="editor-show-statement-run-buttons" v-model="editShowStatementRunButtons" class="mt-0.5" />
</div>
@@ -3090,7 +3240,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-show-current-statement-frame">{{ t("settings.showCurrentStatementFrame") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.showCurrentStatementFrameDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.showCurrentStatementFrameDescription") }}
+ </p>
</div>
<Switch id="editor-show-current-statement-frame" v-model="editShowCurrentStatementFrame" class="mt-0.5" />
</div>
@@ -3098,7 +3250,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-show-insert-value-hints">{{ t("settings.showInsertValueHints") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.showInsertValueHintsDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.showInsertValueHintsDescription") }}
+ </p>
</div>
<Switch id="editor-show-insert-value-hints" v-model="editShowInsertValueHints" class="mt-0.5" />
</div>
@@ -3106,7 +3260,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-word-wrap">{{ t("settings.wordWrap") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.wordWrapDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.wordWrapDescription") }}
+ </p>
</div>
<Switch id="editor-word-wrap" v-model="editWordWrap" class="mt-0.5" />
</div>
@@ -3114,7 +3270,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-vim-mode">{{ t("settings.vimMode") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.vimModeDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.vimModeDescription") }}
+ </p>
</div>
<Switch id="editor-vim-mode" v-model="editVimModeEnabled" class="mt-0.5" />
</div>
@@ -3122,7 +3280,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-auto-close-brackets">{{ t("settings.autoCloseBrackets") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.autoCloseBracketsDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.autoCloseBracketsDescription") }}
+ </p>
</div>
<Switch id="editor-auto-close-brackets" v-model="editAutoCloseBrackets" class="mt-0.5" />
</div>
@@ -3130,7 +3290,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-insert-space-after-completion">{{ t("settings.insertSpaceAfterCompletion") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.insertSpaceAfterCompletionDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.insertSpaceAfterCompletionDescription") }}
+ </p>
</div>
<Switch id="editor-insert-space-after-completion" v-model="editInsertSpaceAfterCompletion" class="mt-0.5" />
</div>
@@ -3138,7 +3300,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-auto-alias-tables">{{ t("settings.autoAliasTables") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.autoAliasTablesDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.autoAliasTablesDescription") }}
+ </p>
</div>
<Switch id="editor-auto-alias-tables" v-model="editAutoAliasTables" class="mt-0.5" />
</div>
@@ -3188,7 +3352,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="editor-prefill-new-query">{{ t("settings.prefillNewQueryWithSelect") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.prefillNewQueryWithSelectDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.prefillNewQueryWithSelectDescription") }}
+ </p>
</div>
<Switch id="editor-prefill-new-query" v-model="editPrefillNewQueryWithSelect" class="mt-0.5" />
</div>
@@ -3199,8 +3365,12 @@ onUnmounted(cleanupPreviewEditor);
<div class="space-y-3">
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="space-y-1">
- <div class="text-sm font-medium text-muted-foreground">{{ t("settings.sqlVariableSyntax") }}</div>
- <p class="text-xs text-muted-foreground">{{ t("settings.sqlVariableSyntaxDescription") }}</p>
+ <div class="text-sm font-medium text-muted-foreground">
+ {{ t("settings.sqlVariableSyntax") }}
+ </div>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.sqlVariableSyntaxDescription") }}
+ </p>
</div>
<Select v-model="editSqlVariableSyntaxDatabaseType">
<SelectTrigger class="h-8 w-44 px-2 text-xs">
@@ -3220,7 +3390,9 @@ onUnmounted(cleanupPreviewEditor);
<span class="font-mono text-xs text-primary">{{ SQL_VARIABLE_SYNTAX_TOKENS[key] }}</span>
<span>{{ t(`settings.sqlVariableSyntax_${key}`) }}</span>
</Label>
- <p class="text-xs text-muted-foreground">{{ t(`settings.sqlVariableSyntax_${key}Description`) }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t(`settings.sqlVariableSyntax_${key}Description`) }}
+ </p>
</div>
<Switch :id="`sql-var-syntax-${key}`" :model-value="sqlVariableSyntaxToggle(key)" class="mt-0.5 shrink-0" @update:model-value="(value) => setSqlVariableSyntaxToggle(key, value as boolean)" />
</div>
@@ -3240,7 +3412,9 @@ onUnmounted(cleanupPreviewEditor);
<section v-else-if="activeSettingsTab === 'formatter'" class="flex flex-col gap-5 py-2">
<div class="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
- <div class="text-sm font-medium">{{ t("settings.sqlFormatterEditorShortcuts") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.sqlFormatterEditorShortcuts") }}
+ </div>
<div class="overflow-hidden rounded-md border border-border/70 bg-background">
<div v-for="definition in formatterEditorShortcutDefinitions" :key="definition.id" class="group -mt-px grid gap-2 border-t border-border/70 px-3 py-2 transition-colors first:mt-0 first:border-t-0 hover:bg-muted/40 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center">
<div class="min-w-0">
@@ -3347,7 +3521,12 @@ onUnmounted(cleanupPreviewEditor);
<SelectTrigger class="h-8 w-full gap-1">
<SelectValue :placeholder="t('settings.selectColorTheme')">
<span v-if="selectedThemePaletteOption" class="flex min-w-0 items-center gap-1">
- <span class="h-3 w-3 shrink-0 rounded-full border border-border shadow-xs" :style="{ background: selectedThemePaletteOption.previewColor }" />
+ <span
+ class="h-3 w-3 shrink-0 rounded-full border border-border shadow-xs"
+ :style="{
+ background: selectedThemePaletteOption.previewColor,
+ }"
+ />
<span class="truncate">{{ selectedThemePaletteOption.label }}</span>
</span>
</SelectValue>
@@ -3425,7 +3604,11 @@ onUnmounted(cleanupPreviewEditor);
</template>
<template #custom-option-label="{ value }">
<span class="truncate" :style="{ fontFamily: value }">
- {{ t("settings.useCustomFont", { font: readableFontFamily(value) }) }}
+ {{
+ t("settings.useCustomFont", {
+ font: readableFontFamily(value),
+ })
+ }}
</span>
</template>
</SearchableSelect>
@@ -3464,7 +3647,11 @@ onUnmounted(cleanupPreviewEditor);
</template>
<template #custom-option-label="{ value }">
<span class="truncate" :style="{ fontFamily: value }">
- {{ t("settings.useCustomFont", { font: readableFontFamily(value) }) }}
+ {{
+ t("settings.useCustomFont", {
+ font: readableFontFamily(value),
+ })
+ }}
</span>
</template>
</SearchableSelect>
@@ -3512,8 +3699,12 @@ onUnmounted(cleanupPreviewEditor);
<Tooltip>
<TooltipTrigger as-child>
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.appLayoutSeparated") }}</div>
- <div :ref="(el) => setLayoutDescRef('separated', el)" class="text-xs text-muted-foreground truncate">{{ t("settings.appLayoutSeparatedDescription") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.appLayoutSeparated") }}
+ </div>
+ <div :ref="(el) => setLayoutDescRef('separated', el)" class="text-xs text-muted-foreground truncate">
+ {{ t("settings.appLayoutSeparatedDescription") }}
+ </div>
</div>
</TooltipTrigger>
<TooltipContent v-if="layoutDescTruncated.separated.value" class="max-w-[320px] text-xs leading-relaxed">
@@ -3527,8 +3718,12 @@ onUnmounted(cleanupPreviewEditor);
<Tooltip>
<TooltipTrigger as-child>
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.appLayoutClassic") }}</div>
- <div :ref="(el) => setLayoutDescRef('classic', el)" class="text-xs text-muted-foreground truncate">{{ t("settings.appLayoutClassicDescription") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.appLayoutClassic") }}
+ </div>
+ <div :ref="(el) => setLayoutDescRef('classic', el)" class="text-xs text-muted-foreground truncate">
+ {{ t("settings.appLayoutClassicDescription") }}
+ </div>
</div>
</TooltipTrigger>
<TooltipContent v-if="layoutDescTruncated.classic.value" class="max-w-[320px] text-xs leading-relaxed">
@@ -3547,14 +3742,22 @@ onUnmounted(cleanupPreviewEditor);
<div class="settings-appearance-choice-grid">
<Button type="button" variant="outline" class="settings-choice-card h-auto justify-start border p-3" :class="editTabLayout === 'scroll' ? 'dbx-choice-selected' : ''" @click="setTabLayout('scroll')">
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.tabLayoutScroll") }}</div>
- <div class="text-xs text-muted-foreground">{{ t("settings.tabLayoutScrollDescription") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.tabLayoutScroll") }}
+ </div>
+ <div class="text-xs text-muted-foreground">
+ {{ t("settings.tabLayoutScrollDescription") }}
+ </div>
</div>
</Button>
<Button type="button" variant="outline" class="settings-choice-card h-auto justify-start border p-3" :class="editTabLayout === 'wrap' ? 'dbx-choice-selected' : ''" @click="setTabLayout('wrap')">
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.tabLayoutWrap") }}</div>
- <div class="text-xs text-muted-foreground">{{ t("settings.tabLayoutWrapDescription") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.tabLayoutWrap") }}
+ </div>
+ <div class="text-xs text-muted-foreground">
+ {{ t("settings.tabLayoutWrapDescription") }}
+ </div>
</div>
</Button>
</div>
@@ -3571,8 +3774,12 @@ onUnmounted(cleanupPreviewEditor);
<Tooltip>
<TooltipTrigger as-child>
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.iconThemeDefault") }}</div>
- <div :ref="(el) => setIconThemeDescRef('default', el)" class="text-xs text-muted-foreground truncate">{{ t("settings.iconThemeDefaultDescription") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.iconThemeDefault") }}
+ </div>
+ <div :ref="(el) => setIconThemeDescRef('default', el)" class="text-xs text-muted-foreground truncate">
+ {{ t("settings.iconThemeDefaultDescription") }}
+ </div>
</div>
</TooltipTrigger>
<TooltipContent v-if="iconThemeDescTruncated.default.value" class="max-w-[320px] text-xs leading-relaxed">
@@ -3589,8 +3796,12 @@ onUnmounted(cleanupPreviewEditor);
<Tooltip>
<TooltipTrigger as-child>
<div class="w-full min-w-0 text-left">
- <div class="text-sm font-medium">{{ t("settings.iconThemeBlack") }}</div>
- <div :ref="(el) => setIconThemeDescRef('black', el)" class="text-xs text-muted-foreground truncate">{{ iconThemeBlackDescriptionText }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.iconThemeBlack") }}
+ </div>
+ <div :ref="(el) => setIconThemeDescRef('black', el)" class="text-xs text-muted-foreground truncate">
+ {{ iconThemeBlackDescriptionText }}
+ </div>
</div>
</TooltipTrigger>
<TooltipContent v-if="iconThemeDescTruncated.black.value" class="max-w-[320px] text-xs leading-relaxed">
@@ -3606,7 +3817,9 @@ onUnmounted(cleanupPreviewEditor);
<div v-if="!isWeb" class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="show-tray-icon">{{ t("settings.showTrayIcon") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.showTrayIconDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.showTrayIconDescription") }}
+ </p>
</div>
<Switch id="show-tray-icon" v-model="editShowTrayIcon" />
</div>
@@ -3614,7 +3827,9 @@ onUnmounted(cleanupPreviewEditor);
<div v-if="!isWeb" class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="quit-on-close">{{ t("settings.quitOnClose") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.quitOnCloseDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.quitOnCloseDescription") }}
+ </p>
</div>
<Switch id="quit-on-close" v-model="editQuitOnClose" />
</div>
@@ -3766,15 +3981,23 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4 rounded-md border border-border/60 p-3">
<div class="space-y-1">
<Label for="exclusive-right-sidebar-panels" class="text-sm cursor-pointer">{{ t("settings.exclusiveRightSidebarPanels") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.exclusiveRightSidebarPanelsDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.exclusiveRightSidebarPanelsDescription") }}
+ </p>
</div>
<Switch id="exclusive-right-sidebar-panels" v-model="editToolbarItems.exclusiveRightSidebarPanels" />
</div>
<div class="grid grid-cols-3 gap-2 mt-2">
<div
v-for="item in [
- { key: 'dataTransfer', label: t('transfer.dataTransfer') },
- { key: 'driverManager', label: t('toolbar.driverManager') },
+ {
+ key: 'dataTransfer',
+ label: t('transfer.dataTransfer'),
+ },
+ {
+ key: 'driverManager',
+ label: t('toolbar.driverManager'),
+ },
{ key: 'sqlFile', label: t('sqlFile.title') },
{ key: 'schemaDiff', label: t('diff.title') },
{ key: 'dataCompare', label: t('dataCompare.title') },
@@ -3802,7 +4025,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="grid grid-cols-2 gap-2">
<Button type="button" variant="outline" class="h-auto justify-start border p-3" :class="editSidebarActivation === 'single' ? 'dbx-choice-selected' : ''" @click="setSidebarActivation('single')">
<div class="text-left">
- <div class="text-sm font-medium">{{ t("settings.sidebarActivationSingle") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.sidebarActivationSingle") }}
+ </div>
<div class="text-xs text-muted-foreground">
{{ t("settings.sidebarActivationSingleDescription") }}
</div>
@@ -3810,7 +4035,9 @@ onUnmounted(cleanupPreviewEditor);
</Button>
<Button type="button" variant="outline" class="h-auto justify-start border p-3" :class="editSidebarActivation === 'double' ? 'dbx-choice-selected' : ''" @click="setSidebarActivation('double')">
<div class="text-left">
- <div class="text-sm font-medium">{{ t("settings.sidebarActivationDouble") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.sidebarActivationDouble") }}
+ </div>
<div class="text-xs text-muted-foreground">
{{ t("settings.sidebarActivationDoubleDescription") }}
</div>
@@ -3833,7 +4060,9 @@ onUnmounted(cleanupPreviewEditor);
<Button type="button" variant="outline" class="h-auto justify-start border p-3" :class="editSidebarObjectDisplay === 'grouped' ? 'dbx-choice-selected' : ''" @click="setSidebarObjectDisplay('grouped')">
<div class="text-left">
<div class="flex items-center gap-2">
- <div class="text-sm font-medium">{{ t("settings.sidebarObjectDisplayGrouped") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.sidebarObjectDisplayGrouped") }}
+ </div>
<Tooltip :open="sidebarObjectDisplayHelp === 'grouped'">
<TooltipTrigger as-child>
<span class="inline-flex shrink-0 cursor-help text-muted-foreground hover:text-foreground" @click.stop @pointerdown.stop @mouseenter="sidebarObjectDisplayHelp = 'grouped'" @mouseleave="sidebarObjectDisplayHelp = null">
@@ -3850,7 +4079,9 @@ onUnmounted(cleanupPreviewEditor);
<Button type="button" variant="outline" class="h-auto justify-start border p-3" :class="editSidebarObjectDisplay === 'simple' ? 'dbx-choice-selected' : ''" @click="setSidebarObjectDisplay('simple')">
<div class="text-left">
<div class="flex items-center gap-2">
- <div class="text-sm font-medium">{{ t("settings.sidebarObjectDisplaySimple") }}</div>
+ <div class="text-sm font-medium">
+ {{ t("settings.sidebarObjectDisplaySimple") }}
+ </div>
<Tooltip :open="sidebarObjectDisplayHelp === 'simple'">
<TooltipTrigger as-child>
<span class="inline-flex shrink-0 cursor-help text-muted-foreground hover:text-foreground" @click.stop @pointerdown.stop @mouseenter="sidebarObjectDisplayHelp = 'simple'" @mouseleave="sidebarObjectDisplayHelp = null">
@@ -4001,7 +4232,9 @@ onUnmounted(cleanupPreviewEditor);
<!-- Data Tab -->
<section v-else-if="activeSettingsTab === 'data'" class="flex flex-col gap-5 py-2">
<div class="space-y-3">
- <div class="text-sm font-medium text-muted-foreground">{{ t("settings.dataGridDisplay") }}</div>
+ <div class="text-sm font-medium text-muted-foreground">
+ {{ t("settings.dataGridDisplay") }}
+ </div>
<div class="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="table-open-page-size">
@@ -4067,11 +4300,15 @@ onUnmounted(cleanupPreviewEditor);
</template>
<div class="space-y-3">
- <div class="text-sm font-medium text-muted-foreground">{{ t("settings.dateTimeSection") }}</div>
+ <div class="text-sm font-medium text-muted-foreground">
+ {{ t("settings.dateTimeSection") }}
+ </div>
<div class="grid gap-3 rounded-md border bg-muted/20 px-3 py-3 sm:grid-cols-[minmax(0,1fr)_minmax(220px,0.8fr)] sm:items-center">
<div>
<Label>{{ t("settings.globalDateTimeDisplayFormat") }}</Label>
- <p class="mt-1 text-xs text-muted-foreground">{{ t("settings.globalDateTimeDisplayFormatDescription") }}</p>
+ <p class="mt-1 text-xs text-muted-foreground">
+ {{ t("settings.globalDateTimeDisplayFormatDescription") }}
+ </p>
</div>
<SearchableSelect
v-model="editGlobalDateTimeDisplayFormat"
@@ -4088,7 +4325,9 @@ onUnmounted(cleanupPreviewEditor);
/>
<div>
<Label>{{ t("settings.globalDateTimeExportFormat") }}</Label>
- <p class="mt-1 text-xs text-muted-foreground">{{ t("settings.globalDateTimeExportFormatDescription") }}</p>
+ <p class="mt-1 text-xs text-muted-foreground">
+ {{ t("settings.globalDateTimeExportFormatDescription") }}
+ </p>
</div>
<SearchableSelect
v-model="editGlobalDateTimeExportFormat"
@@ -4105,7 +4344,9 @@ onUnmounted(cleanupPreviewEditor);
/>
<div>
<Label>{{ t("settings.globalDateTimeImportFormat") }}</Label>
- <p class="mt-1 text-xs text-muted-foreground">{{ t("settings.globalDateTimeImportFormatDescription") }}</p>
+ <p class="mt-1 text-xs text-muted-foreground">
+ {{ t("settings.globalDateTimeImportFormatDescription") }}
+ </p>
</div>
<SearchableSelect
v-model="editGlobalDateTimeImportFormat"
@@ -4126,7 +4367,9 @@ onUnmounted(cleanupPreviewEditor);
<Separator />
<div class="space-y-3">
- <div class="text-sm font-medium text-muted-foreground">{{ t("settings.exportSection") }}</div>
+ <div class="text-sm font-medium text-muted-foreground">
+ {{ t("settings.exportSection") }}
+ </div>
<div class="space-y-2">
<Label>{{ t("settings.exportBatchSize") }}</Label>
<div class="flex items-center gap-3">
@@ -4144,7 +4387,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-start justify-between gap-3">
<div class="space-y-0.5">
<Label for="export-row-limit-enabled">{{ t("settings.exportRowLimitEnabled") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.exportRowLimitEnabledDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.exportRowLimitEnabledDescription") }}
+ </p>
</div>
<Switch id="export-row-limit-enabled" v-model="editExportRowLimitEnabled" class="mt-0.5" />
</div>
@@ -4160,7 +4405,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-start justify-between gap-3">
<div class="space-y-0.5">
<Label for="query-export-keyset-enabled">{{ t("settings.queryExportKeysetOptimizationEnabled") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.queryExportKeysetOptimizationEnabledDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.queryExportKeysetOptimizationEnabledDescription") }}
+ </p>
</div>
<Switch id="query-export-keyset-enabled" v-model="editQueryExportKeysetOptimizationEnabled" class="mt-0.5" />
</div>
@@ -4169,12 +4416,16 @@ onUnmounted(cleanupPreviewEditor);
<Separator />
<div class="space-y-3">
- <div class="text-sm font-medium text-muted-foreground">{{ t("settings.tableStructureSection") }}</div>
+ <div class="text-sm font-medium text-muted-foreground">
+ {{ t("settings.tableStructureSection") }}
+ </div>
<div ref="tableColumnTemplateSectionRef" class="space-y-2 rounded-md border bg-muted/20 px-3 py-2">
<div class="flex items-start justify-between gap-3">
<div class="space-y-1">
<Label>{{ t("settings.tableColumnTemplateFields") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.tableColumnTemplateFieldsDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.tableColumnTemplateFieldsDescription") }}
+ </p>
</div>
<div class="flex items-center gap-2">
<Select v-model="editTableColumnTemplateDatabaseType">
@@ -4197,12 +4448,24 @@ onUnmounted(cleanupPreviewEditor);
<thead class="bg-muted/50 text-muted-foreground">
<tr>
<th class="w-8 border-b px-2 py-1.5" />
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateColumn") }}</th>
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateType") }}</th>
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateLength") }}</th>
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateDefault") }}</th>
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateRequired") }}</th>
- <th class="border-b px-2 py-1.5 text-left font-medium">{{ t("settings.tableColumnTemplateComment") }}</th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateColumn") }}
+ </th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateType") }}
+ </th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateLength") }}
+ </th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateDefault") }}
+ </th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateRequired") }}
+ </th>
+ <th class="border-b px-2 py-1.5 text-left font-medium">
+ {{ t("settings.tableColumnTemplateComment") }}
+ </th>
<th class="w-10 border-b px-2 py-1.5" />
</tr>
</thead>
@@ -4341,7 +4604,9 @@ onUnmounted(cleanupPreviewEditor);
<!-- Snippets Tab -->
<section v-else-if="activeSettingsTab === 'snippets'" class="flex flex-col gap-4 py-2">
<div class="flex items-center justify-between">
- <p class="text-sm text-muted-foreground">{{ t("settings.snippetsDescription") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("settings.snippetsDescription") }}
+ </p>
<Button variant="outline" size="sm" @click="openAddSnippetDialog">
<Plus class="mr-2 h-4 w-4" />
{{ t("settings.snippetsAdd") }}
@@ -4419,7 +4684,9 @@ onUnmounted(cleanupPreviewEditor);
<Cloud class="h-4 w-4 text-muted-foreground" />
{{ t("settings.syncWebDavTitle") }}
</div>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncWebDavDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncWebDavDescription") }}
+ </p>
</div>
<div class="grid gap-4 md:grid-cols-2">
@@ -4466,7 +4733,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="space-y-2 md:col-span-2">
<Label for="webdav-remote-path">{{ t("settings.syncRemotePath") }}</Label>
<Input id="webdav-remote-path" v-model="webdavRemotePath" autocomplete="off" />
- <p class="text-xs text-muted-foreground">{{ t("settings.syncRemotePathDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncRemotePathDescription") }}
+ </p>
</div>
<div class="space-y-2 md:col-span-2 rounded-md border bg-muted/20 px-3 py-3">
<label class="flex items-center gap-2 text-xs">
@@ -4478,7 +4747,9 @@ onUnmounted(cleanupPreviewEditor);
<Input id="webdav-auto-upload-interval" v-model.number="webdavAutoUploadIntervalMinutes" type="number" min="1" max="1440" step="1" class="h-7 w-24 text-xs" :disabled="!webdavAutoUploadEnabled" />
<span class="text-xs text-muted-foreground">{{ t("settings.syncAutoUploadMinutes") }}</span>
</div>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncAutoUploadDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncAutoUploadDescription") }}
+ </p>
</div>
</div>
@@ -4515,7 +4786,9 @@ onUnmounted(cleanupPreviewEditor);
{{ t("settings.syncSnippetGuide") }}
</Button>
</div>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncSnippetDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncSnippetDescription") }}
+ </p>
</div>
<div class="grid gap-4 rounded-md border p-4 md:grid-cols-2">
@@ -4556,7 +4829,9 @@ onUnmounted(cleanupPreviewEditor);
<input v-model="snippetRememberToken" type="checkbox" class="h-4 w-4 shrink-0 accent-primary" />
<span>{{ t("settings.syncSnippetRememberToken") }}</span>
</label>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncSnippetTokenDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncSnippetTokenDescription") }}
+ </p>
</div>
<div class="flex flex-wrap items-center justify-between gap-3 md:col-span-2">
<div v-if="snippetMessage" class="min-w-0 flex-1 text-xs" :class="snippetError ? 'text-destructive' : 'text-green-600 dark:text-green-400'">
@@ -4588,7 +4863,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex items-center justify-between gap-4">
<div class="space-y-1">
<Label for="sync-secrets">{{ t("settings.syncSecrets") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncSecretsSharedDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncSecretsSharedDescription") }}
+ </p>
</div>
<Switch id="sync-secrets" v-model="webdavSyncSecrets" />
</div>
@@ -4612,7 +4889,9 @@ onUnmounted(cleanupPreviewEditor);
<X class="size-3.5" />
</Button>
</div>
- <p class="text-xs text-muted-foreground">{{ t("settings.syncSecretsPassphraseDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.syncSecretsPassphraseDescription") }}
+ </p>
</div>
</div>
</section>
@@ -4630,7 +4909,9 @@ onUnmounted(cleanupPreviewEditor);
</div>
<div v-if="settingsStore.aiConfigs.length === 0" class="rounded-md border border-dashed p-6 text-center">
- <p class="text-sm text-muted-foreground">{{ t("ai.noAiConfigs") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("ai.noAiConfigs") }}
+ </p>
<Button type="button" size="sm" class="mt-2" @click="aiEnterEditMode()">
<Plus class="mr-1 h-3.5 w-3.5" />
{{ t("ai.addConfig") }}
@@ -4644,56 +4925,111 @@ onUnmounted(cleanupPreviewEditor);
<div>
<div class="flex items-center gap-2">
<span class="text-sm font-medium">{{ config.name }}</span>
- <Badge v-if="config.isDefault" variant="default" class="h-5 text-[10px]"> {{ t("ai.default") }} </Badge>
+ <Badge v-if="config.isDefault" variant="default" class="h-5 text-[10px]">
+ {{ t("ai.default") }}
+ </Badge>
+ </div>
+ <div class="text-xs text-muted-foreground">
+ {{ AI_PROVIDER_PRESETS[config.provider].label }}
</div>
- <div class="text-xs text-muted-foreground">{{ AI_PROVIDER_PRESETS[config.provider].label }}</div>
</div>
</div>
<div class="flex items-center gap-1">
- <Button v-if="!config.isDefault" type="button" size="sm" variant="ghost" @click="aiSetDefaultConfig(config.id)"> {{ t("ai.setDefault") }} </Button>
- <Button type="button" size="sm" variant="ghost" @click="aiEnterEditMode(config.id)"> {{ t("common.edit") }} </Button>
- <Button v-if="!config.isDefault" type="button" size="sm" variant="ghost" class="text-destructive" @click="aiDeleteConfig(config.id)"> {{ t("common.delete") }} </Button>
+ <Button v-if="!config.isDefault" type="button" size="sm" variant="ghost" @click="aiSetDefaultConfig(config.id)">
+ {{ t("ai.setDefault") }}
+ </Button>
+ <Button type="button" size="sm" variant="ghost" @click="aiEnterEditMode(config.id)">
+ {{ t("common.edit") }}
+ </Button>
+ <Button v-if="!config.isDefault" type="button" size="sm" variant="ghost" class="text-destructive" @click="aiDeleteConfig(config.id)">
+ {{ t("common.delete") }}
+ </Button>
</div>
</div>
</div>
</div>
- <!-- Global Custom Instructions (list mode) -->
+ <!-- Agent Turn Limit (list mode, global) -->
<div v-if="aiConfigListMode === 'list'" class="space-y-3">
<Separator />
<div>
- <h3 class="text-sm font-medium">{{ t("ai.globalInstructions") }}</h3>
- <p class="text-xs text-muted-foreground">{{ t("ai.globalInstructionsDescription") }}</p>
+ <h3 class="text-sm font-medium">
+ {{ t("ai.maxAgentTurns") }}
+ </h3>
+ <p class="text-xs text-muted-foreground">
+ {{ t("ai.maxAgentTurnsDescription") }}
+ </p>
</div>
- <textarea v-model="editGlobalInstructions" class="w-full rounded-md border bg-background px-3 py-2 text-xs font-mono resize-y min-h-[80px]" rows="4" :placeholder="t('ai.globalInstructionsDescription')"></textarea>
- <div class="flex items-center justify-between">
- <span class="text-xs" :class="globalInstructionsTooLong() ? 'text-destructive' : 'text-muted-foreground'">
- {{ t("ai.globalInstructionsCharCount", { count: promptTemplateCharacterCount(editGlobalInstructions), max: GLOBAL_INSTRUCTIONS_MAX }) }}
+ <div class="flex items-center gap-2">
+ <Input v-model.number="editMaxAgentTurns" type="number" :min="MAX_AGENT_TURNS_MIN" :max="MAX_AGENT_TURNS_MAX" step="1" class="h-8 w-32 text-xs" :placeholder="String(MAX_AGENT_TURNS_DEFAULT)" :disabled="!maxAgentTurnsLoaded || maxAgentTurnsSaving" />
+ <span class="text-xs" :class="maxAgentTurnsOutOfRange(editMaxAgentTurns) ? 'text-destructive' : 'text-muted-foreground'">
+ {{
+ t("ai.maxAgentTurnsRange", {
+ min: MAX_AGENT_TURNS_MIN,
+ max: MAX_AGENT_TURNS_MAX,
+ default: MAX_AGENT_TURNS_DEFAULT,
+ })
+ }}
</span>
- <Button type="button" size="sm" :disabled="!promptTemplateStore.isLoaded || globalInstructionsTooLong() || globalInstructionsSaving" @click="saveGlobalInstructions">
- {{ globalInstructionsSaving ? t("common.processing") : t("ai.globalInstructionsSave") }}
+ <div class="flex-1"></div>
+ <Button v-if="maxAgentTurnsLoadError" type="button" size="sm" variant="outline" :disabled="maxAgentTurnsLoading" @click="loadMaxAgentTurnsSetting">
+ {{ t("common.retry") }}
+ </Button>
+ <Button type="button" size="sm" :disabled="!maxAgentTurnsLoaded || maxAgentTurnsSaving || maxAgentTurnsOutOfRange(editMaxAgentTurns)" @click="saveMaxAgentTurnsSetting">
+ {{ maxAgentTurnsSaving ? t("common.processing") : t("common.save") }}
</Button>
</div>
</div>
- <!-- Agent Turn Limit (list mode, global) -->
+ <!-- Max Retries (list mode, global) -->
<div v-if="aiConfigListMode === 'list'" class="space-y-3">
<Separator />
<div>
- <h3 class="text-sm font-medium">{{ t("ai.maxAgentTurns") }}</h3>
- <p class="text-xs text-muted-foreground">{{ t("ai.maxAgentTurnsDescription") }}</p>
+ <h3 class="text-sm font-medium">
+ {{ t("ai.maxRetriesGlobal") }}
+ </h3>
+ <p class="text-xs text-muted-foreground">
+ {{ t("ai.maxRetriesGlobalDescription") }}
+ </p>
</div>
<div class="flex items-center gap-2">
- <Input v-model.number="editMaxAgentTurns" type="number" :min="MAX_AGENT_TURNS_MIN" :max="MAX_AGENT_TURNS_MAX" step="1" class="h-8 w-32 text-xs" :placeholder="String(MAX_AGENT_TURNS_DEFAULT)" :disabled="!maxAgentTurnsLoaded || maxAgentTurnsSaving" />
- <span class="text-xs" :class="maxAgentTurnsOutOfRange(editMaxAgentTurns) ? 'text-destructive' : 'text-muted-foreground'">
- {{ t("ai.maxAgentTurnsRange", { min: MAX_AGENT_TURNS_MIN, max: MAX_AGENT_TURNS_MAX, default: MAX_AGENT_TURNS_DEFAULT }) }}
+ <Input v-model.number="editMaxRetries" type="number" min="0" max="10" step="1" class="h-8 w-32 text-xs" placeholder="2" :disabled="!maxRetriesLoaded || maxRetriesSaving" />
+ <span class="text-xs" :class="maxRetriesOutOfRange(editMaxRetries) ? 'text-destructive' : 'text-muted-foreground'">
+ {{ t("ai.maxRetriesRange", { min: 0, max: 10, default: 2 }) }}
</span>
<div class="flex-1"></div>
- <Button v-if="maxAgentTurnsLoadError" type="button" size="sm" variant="outline" :disabled="maxAgentTurnsLoading" @click="loadMaxAgentTurnsSetting">
+ <Button v-if="maxRetriesLoadError" type="button" size="sm" variant="outline" :disabled="maxRetriesLoading" @click="loadMaxRetriesSetting">
{{ t("common.retry") }}
</Button>
- <Button type="button" size="sm" :disabled="!maxAgentTurnsLoaded || maxAgentTurnsSaving || maxAgentTurnsOutOfRange(editMaxAgentTurns)" @click="saveMaxAgentTurnsSetting">
- {{ maxAgentTurnsSaving ? t("common.processing") : t("common.save") }}
+ <Button type="button" size="sm" :disabled="!maxRetriesLoaded || maxRetriesSaving || maxRetriesOutOfRange(editMaxRetries)" @click="saveMaxRetriesSetting">
+ {{ maxRetriesSaving ? t("common.processing") : t("common.save") }}
+ </Button>
+ </div>
+ </div>
+
+ <!-- Global Custom Instructions (list mode) -->
+ <div v-if="aiConfigListMode === 'list'" class="space-y-3">
+ <Separator />
+ <div>
+ <h3 class="text-sm font-medium">
+ {{ t("ai.globalInstructions") }}
+ </h3>
+ <p class="text-xs text-muted-foreground">
+ {{ t("ai.globalInstructionsDescription") }}
+ </p>
+ </div>
+ <textarea v-model="editGlobalInstructions" class="w-full rounded-md border bg-background px-3 py-2 text-xs font-mono resize-y min-h-[80px]" rows="4" :placeholder="t('ai.globalInstructionsDescription')"></textarea>
+ <div class="flex items-center justify-between">
+ <span class="text-xs" :class="globalInstructionsTooLong() ? 'text-destructive' : 'text-muted-foreground'">
+ {{
+ t("ai.globalInstructionsCharCount", {
+ count: promptTemplateCharacterCount(editGlobalInstructions),
+ max: GLOBAL_INSTRUCTIONS_MAX,
+ })
+ }}
+ </span>
+ <Button type="button" size="sm" :disabled="!promptTemplateStore.isLoaded || globalInstructionsTooLong() || globalInstructionsSaving" @click="saveGlobalInstructions">
+ {{ globalInstructionsSaving ? t("common.processing") : t("ai.globalInstructionsSave") }}
</Button>
</div>
</div>
@@ -4703,8 +5039,12 @@ onUnmounted(cleanupPreviewEditor);
<Separator />
<div class="flex items-center justify-between">
<div>
- <h3 class="text-sm font-medium">{{ t("ai.promptTemplates") }}</h3>
- <p class="text-xs text-muted-foreground">{{ t("ai.promptTemplatesDescription") }}</p>
+ <h3 class="text-sm font-medium">
+ {{ t("ai.promptTemplates") }}
+ </h3>
+ <p class="text-xs text-muted-foreground">
+ {{ t("ai.promptTemplatesDescription") }}
+ </p>
</div>
<Button v-if="!templateFormOpen" type="button" size="sm" @click="openNewTemplate">
<Plus class="mr-1 h-3.5 w-3.5" />
@@ -4716,7 +5056,9 @@ onUnmounted(cleanupPreviewEditor);
<div v-if="!templateFormOpen && promptTemplateStore.templates.length > 0" class="space-y-1.5">
<div v-for="tpl in promptTemplateStore.templates" :key="tpl.id" class="flex items-center justify-between rounded-md border p-3">
<div class="min-w-0 flex-1">
- <div class="text-sm font-medium truncate">{{ tpl.name }}</div>
+ <div class="text-sm font-medium truncate">
+ {{ tpl.name }}
+ </div>
<div class="text-xs text-muted-foreground truncate">{{ tpl.content.slice(0, 100) }}{{ tpl.content.length > 100 ? "..." : "" }}</div>
</div>
<div class="flex items-center gap-1 shrink-0 ml-2">
@@ -4727,13 +5069,17 @@ onUnmounted(cleanupPreviewEditor);
</div>
<div v-if="!templateFormOpen && promptTemplateStore.templates.length === 0" class="rounded-md border border-dashed p-6 text-center">
- <p class="text-sm text-muted-foreground">{{ t("ai.promptTemplateNoTemplates") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("ai.promptTemplateNoTemplates") }}
+ </p>
</div>
<!-- Template Edit Form -->
<div v-if="templateFormOpen" class="rounded-md border p-4 space-y-3">
<div class="flex items-center justify-between">
- <h4 class="text-sm font-medium">{{ templateFormIsNew ? t("ai.promptTemplateNew") : t("ai.promptTemplateEdit") }}</h4>
+ <h4 class="text-sm font-medium">
+ {{ templateFormIsNew ? t("ai.promptTemplateNew") : t("ai.promptTemplateEdit") }}
+ </h4>
<Button type="button" variant="ghost" size="sm" @click="closeTemplateForm">
<X class="h-3.5 w-3.5" />
</Button>
@@ -4742,8 +5088,20 @@ onUnmounted(cleanupPreviewEditor);
<Label class="text-xs">{{ t("ai.promptTemplateName") }}</Label>
<Input v-model="templateForm.name" class="mt-1 h-8 text-xs" :placeholder="t('ai.promptTemplateNamePlaceholder')" />
<div class="flex justify-between mt-0.5">
- <p v-if="templateNameTooLong()" class="text-xs text-destructive">{{ t("ai.promptTemplateNameTooLong", { max: PROMPT_TEMPLATE_NAME_MAX }) }}</p>
- <p v-else-if="localNameDuplicate()" class="text-xs text-destructive">{{ t("ai.promptTemplateNameExists", { name: templateForm.name.trim() }) }}</p>
+ <p v-if="templateNameTooLong()" class="text-xs text-destructive">
+ {{
+ t("ai.promptTemplateNameTooLong", {
+ max: PROMPT_TEMPLATE_NAME_MAX,
+ })
+ }}
+ </p>
+ <p v-else-if="localNameDuplicate()" class="text-xs text-destructive">
+ {{
+ t("ai.promptTemplateNameExists", {
+ name: templateForm.name.trim(),
+ })
+ }}
+ </p>
<span v-else></span>
<span class="text-xs" :class="templateNameTooLong() ? 'text-destructive' : 'text-muted-foreground'">{{ promptTemplateCharacterCount(templateForm.name) }}/{{ PROMPT_TEMPLATE_NAME_MAX }}</span>
</div>
@@ -4752,7 +5110,13 @@ onUnmounted(cleanupPreviewEditor);
<Label class="text-xs">{{ t("ai.promptTemplateContent") }}</Label>
<textarea v-model="templateForm.content" class="mt-1 w-full rounded-md border bg-background px-3 py-2 text-xs font-mono resize-y min-h-[80px]" rows="4" :placeholder="t('ai.promptTemplateContentPlaceholder')"></textarea>
<div class="flex justify-between mt-0.5">
- <p v-if="templateContentTooLong()" class="text-xs text-destructive">{{ t("ai.promptTemplateTooLong", { max: PROMPT_TEMPLATE_CONTENT_MAX }) }}</p>
+ <p v-if="templateContentTooLong()" class="text-xs text-destructive">
+ {{
+ t("ai.promptTemplateTooLong", {
+ max: PROMPT_TEMPLATE_CONTENT_MAX,
+ })
+ }}
+ </p>
<span v-else></span>
<span class="text-xs" :class="templateContentTooLong() ? 'text-destructive' : 'text-muted-foreground'">{{ promptTemplateCharacterCount(templateForm.content) }}/{{ PROMPT_TEMPLATE_CONTENT_MAX }}</span>
</div>
@@ -4773,7 +5137,9 @@ onUnmounted(cleanupPreviewEditor);
<ArrowLeft class="mr-1 h-3.5 w-3.5" />
{{ t("common.back") }}
</Button>
- <h3 class="text-sm font-medium">{{ aiEditConfigId ? t("ai.editConfig") : t("ai.addConfig") }}</h3>
+ <h3 class="text-sm font-medium">
+ {{ aiEditConfigId ? t("ai.editConfig") : t("ai.addConfig") }}
+ </h3>
</div>
<!-- Config Name Input -->
@@ -4821,7 +5187,11 @@ onUnmounted(cleanupPreviewEditor);
</Badge>
</div>
<p class="leading-relaxed">
- {{ t("ai.cliMcpRequiredDescription", { provider: aiCliProviderLabel }) }}
+ {{
+ t("ai.cliMcpRequiredDescription", {
+ provider: aiCliProviderLabel,
+ })
+ }}
</p>
<p v-if="mcpStatus?.error || mcpStatusError" class="select-text leading-relaxed">
{{ mcpStatusError || mcpStatus?.error }}
@@ -4866,7 +5236,9 @@ onUnmounted(cleanupPreviewEditor);
<Label class="pt-2 text-right text-xs">Endpoint</Label>
<div class="col-span-2 space-y-1.5">
<Input v-model="aiEditEndpoint" :placeholder="aiEndpointPlaceholder" autocomplete="off" class="h-8 text-xs" />
- <p v-if="aiEndpointHint" class="text-[11px] text-muted-foreground">{{ aiEndpointHint }}</p>
+ <p v-if="aiEndpointHint" class="text-[11px] text-muted-foreground">
+ {{ aiEndpointHint }}
+ </p>
</div>
</div>
@@ -4875,8 +5247,17 @@ onUnmounted(cleanupPreviewEditor);
<Label class="pt-2 text-right text-xs">{{ t("ai.cliPath", { provider: aiCliProviderLabel }) }}</Label>
<div class="col-span-2 space-y-1.5">
<Input v-model="aiEditCliPath" autocomplete="off" class="h-8 text-xs" :placeholder="aiCliCommandName" />
- <p class="text-[11px] text-muted-foreground">{{ t("ai.cliPathHint", { command: aiCliCommandName, loginCommand: aiCliLoginCommand }) }}</p>
- <p v-if="aiCliPathError" class="text-[11px] text-destructive">{{ aiCliPathError }}</p>
+ <p class="text-[11px] text-muted-foreground">
+ {{
+ t("ai.cliPathHint", {
+ command: aiCliCommandName,
+ loginCommand: aiCliLoginCommand,
+ })
+ }}
+ </p>
+ <p v-if="aiCliPathError" class="text-[11px] text-destructive">
+ {{ aiCliPathError }}
+ </p>
</div>
</div>
@@ -4897,8 +5278,12 @@ onUnmounted(cleanupPreviewEditor);
<Plus class="mr-1 h-3.5 w-3.5" />
{{ t("ai.cliEnvAdd") }}
</Button>
- <p v-if="aiCliEnvError" class="text-[11px] text-destructive">{{ aiCliEnvError }}</p>
- <p v-else class="text-[11px] text-muted-foreground">{{ t("ai.cliEnvHint", { provider: aiCliProviderLabel }) }}</p>
+ <p v-if="aiCliEnvError" class="text-[11px] text-destructive">
+ {{ aiCliEnvError }}
+ </p>
+ <p v-else class="text-[11px] text-muted-foreground">
+ {{ t("ai.cliEnvHint", { provider: aiCliProviderLabel }) }}
+ </p>
</div>
</div>
@@ -4906,9 +5291,37 @@ onUnmounted(cleanupPreviewEditor);
<div v-if="aiSupportsApiStyle" class="grid grid-cols-3 items-center gap-3">
<Label class="text-right text-xs">API</Label>
<div class="col-span-2 flex gap-2">
- <Button size="sm" variant="outline" class="h-8 flex-1 text-xs" :class="{ 'dbx-choice-selected': aiEditApiStyle === 'completions' }" @click="aiSelectApiStyle('completions')">/chat/completions</Button>
- <Button size="sm" variant="outline" class="h-8 flex-1 text-xs" :class="{ 'dbx-choice-selected': aiEditApiStyle === 'responses' }" @click="aiSelectApiStyle('responses')">/responses</Button>
- <Button v-if="aiSupportsAnthropicApiStyle" size="sm" variant="outline" class="h-8 flex-1 text-xs" :class="{ 'dbx-choice-selected': aiEditApiStyle === 'anthropic-messages' }" @click="aiSelectApiStyle('anthropic-messages')">/messages</Button>
+ <Button
+ size="sm"
+ variant="outline"
+ class="h-8 flex-1 text-xs"
+ :class="{
+ 'dbx-choice-selected': aiEditApiStyle === 'completions',
+ }"
+ @click="aiSelectApiStyle('completions')"
+ >/chat/completions</Button
+ >
+ <Button
+ size="sm"
+ variant="outline"
+ class="h-8 flex-1 text-xs"
+ :class="{
+ 'dbx-choice-selected': aiEditApiStyle === 'responses',
+ }"
+ @click="aiSelectApiStyle('responses')"
+ >/responses</Button
+ >
+ <Button
+ v-if="aiSupportsAnthropicApiStyle"
+ size="sm"
+ variant="outline"
+ class="h-8 flex-1 text-xs"
+ :class="{
+ 'dbx-choice-selected': aiEditApiStyle === 'anthropic-messages',
+ }"
+ @click="aiSelectApiStyle('anthropic-messages')"
+ >/messages</Button
+ >
</div>
</div>
@@ -4917,7 +5330,9 @@ onUnmounted(cleanupPreviewEditor);
<Label class="text-right text-xs">{{ t("ai.contextWindow") }}</Label>
<div class="col-span-2">
<Input v-model.number="aiEditContextWindow" type="number" min="1000" step="1000" class="h-8 text-xs" :placeholder="t('ai.contextWindowAuto')" />
- <p class="mt-1 text-xs text-muted-foreground">{{ t("ai.contextWindowHint") }}</p>
+ <p class="mt-1 text-xs text-muted-foreground">
+ {{ t("ai.contextWindowHint") }}
+ </p>
</div>
</div>
@@ -4961,13 +5376,17 @@ onUnmounted(cleanupPreviewEditor);
<div v-if="!isWeb" class="grid gap-3 sm:grid-cols-2">
<div class="rounded-md border p-3">
- <div class="text-xs font-medium uppercase text-muted-foreground">{{ t("settings.mcpCurrent") }}</div>
+ <div class="text-xs font-medium uppercase text-muted-foreground">
+ {{ t("settings.mcpCurrent") }}
+ </div>
<div class="mt-2 font-mono text-sm">
{{ mcpStatus?.current_version ? `v${mcpStatus.current_version}` : t("settings.mcpVersionMissing") }}
</div>
</div>
<div class="rounded-md border p-3">
- <div class="text-xs font-medium uppercase text-muted-foreground">{{ t("settings.mcpLatest") }}</div>
+ <div class="text-xs font-medium uppercase text-muted-foreground">
+ {{ t("settings.mcpLatest") }}
+ </div>
<div class="mt-2 font-mono text-sm">
{{ mcpStatus?.latest_version ? `v${mcpStatus.latest_version}` : t("settings.mcpVersionUnknown") }}
</div>
@@ -5018,13 +5437,23 @@ onUnmounted(cleanupPreviewEditor);
</div>
<div class="space-y-2">
- <p class="text-xs text-muted-foreground">{{ t("settings.mcpConfigOptionsHint") }}</p>
- <p v-if="mcpPolicyLoadError" class="rounded-md border border-red-500/30 bg-red-500/5 px-3 py-2 text-xs text-red-600 dark:text-red-400">{{ t("settings.mcpPolicyLoadFailed", { error: mcpPolicyLoadError }) }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.mcpConfigOptionsHint") }}
+ </p>
+ <p v-if="mcpPolicyLoadError" class="rounded-md border border-red-500/30 bg-red-500/5 px-3 py-2 text-xs text-red-600 dark:text-red-400">
+ {{
+ t("settings.mcpPolicyLoadFailed", {
+ error: mcpPolicyLoadError,
+ })
+ }}
+ </p>
<McpConnectionScopePicker :connections="mcpSelectableConnections" :allowed-connection-ids="mcpAllowedConnectionIds" :disabled="mcpPolicyControlsDisabled" :busy="mcpPolicyLoading || mcpPolicySaving" @update:allowed-connection-ids="onMcpAllowedConnectionIdsChange" />
<div class="space-y-3 rounded-md border bg-muted/20 p-3">
<div class="space-y-1">
<Label id="mcp-execution-mode-label">{{ t("settings.mcpExecutionMode") }}</Label>
- <p class="text-xs text-muted-foreground">{{ t("settings.mcpExecutionModeDescription") }}</p>
+ <p class="text-xs text-muted-foreground">
+ {{ t("settings.mcpExecutionModeDescription") }}
+ </p>
</div>
<div class="grid grid-cols-1 p-1 sm:grid-cols-3 gap-2.5" role="radiogroup" aria-labelledby="mcp-execution-mode-label">
<Button
@@ -5089,14 +5518,20 @@ onUnmounted(cleanupPreviewEditor);
</div>
<div class="space-y-1.5">
<div class="space-y-0.5">
- <p class="text-xs font-medium">{{ t("settings.mcpCapabilityTitle") }}</p>
- <p class="text-[11px] text-muted-foreground">{{ t("settings.mcpCapabilityDescription") }}</p>
+ <p class="text-xs font-medium">
+ {{ t("settings.mcpCapabilityTitle") }}
+ </p>
+ <p class="text-[11px] text-muted-foreground">
+ {{ t("settings.mcpCapabilityDescription") }}
+ </p>
</div>
<div class="overflow-x-auto rounded-md border bg-background">
<table class="w-full min-w-[36rem] table-fixed text-xs">
<thead class="bg-muted/50 text-muted-foreground">
<tr>
- <th scope="col" class="w-[46%] px-3 py-2 text-left font-medium">{{ t("settings.mcpCapabilityOperation") }}</th>
+ <th scope="col" class="w-[46%] px-3 py-2 text-left font-medium">
+ {{ t("settings.mcpCapabilityOperation") }}
+ </th>
<th v-for="column in MCP_EXECUTION_MODE_COLUMNS" :key="column.mode" scope="col" class="px-2 py-2 text-center font-medium">
{{ t(column.labelKey) }}
</th>
@@ -5104,7 +5539,9 @@ onUnmounted(cleanupPreviewEditor);
</thead>
<tbody class="divide-y">
<tr v-for="row in MCP_CAPABILITY_ROWS" :key="row.labelKey">
- <th scope="row" class="px-3 py-2 text-left font-normal leading-relaxed">{{ t(row.labelKey) }}</th>
+ <th scope="row" class="px-3 py-2 text-left font-normal leading-relaxed">
+ {{ t(row.labelKey) }}
+ </th>
<td v-for="column in MCP_EXECUTION_MODE_COLUMNS" :key="column.mode" class="px-2 py-2 text-center">
<span class="inline-flex items-center justify-center" :class="row[column.mode] ? 'text-green-600 dark:text-green-400' : 'text-muted-foreground/60'">
<Check v-if="row[column.mode]" class="h-4 w-4" aria-hidden="true" />
@@ -5116,7 +5553,9 @@ onUnmounted(cleanupPreviewEditor);
</tbody>
</table>
</div>
- <p class="text-[11px] leading-relaxed text-muted-foreground">{{ t("settings.mcpCapabilityAlwaysEnforced") }}</p>
+ <p class="text-[11px] leading-relaxed text-muted-foreground">
+ {{ t("settings.mcpCapabilityAlwaysEnforced") }}
+ </p>
</div>
</div>
</div>
@@ -5265,7 +5704,9 @@ onUnmounted(cleanupPreviewEditor);
<section v-else-if="activeSettingsTab === 'security' && isWeb" class="flex flex-col gap-5 py-2">
<div class="space-y-3">
<Label class="text-base">{{ t("auth.changePassword") }}</Label>
- <p class="text-sm text-muted-foreground">{{ t("auth.changePasswordDescription") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("auth.changePasswordDescription") }}
+ </p>
<PasswordInput v-model="oldPassword" :placeholder="t('auth.oldPassword')" inputClass="h-9" autocomplete="off" />
<PasswordInput v-model="newPassword" :placeholder="t('auth.newPassword')" inputClass="h-9" autocomplete="off" />
<PasswordInput v-model="confirmNewPassword" :placeholder="t('auth.confirmPassword')" inputClass="h-9" autocomplete="off" />
@@ -5284,7 +5725,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
<div class="min-w-0 space-y-1">
<Label>{{ t("settings.supportInfoTitle") }}</Label>
- <p class="text-sm text-muted-foreground">{{ t("settings.supportInfoDescription") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("settings.supportInfoDescription") }}
+ </p>
</div>
<Button type="button" variant="outline" size="sm" class="shrink-0" :disabled="appSupportInfoLoading && !appSupportInfo" @click="copyAppSupportInfo">
<Loader2 v-if="appSupportInfoLoading && !appSupportInfo" class="mr-1 h-3.5 w-3.5 animate-spin" />
@@ -5295,12 +5738,24 @@ onUnmounted(cleanupPreviewEditor);
</div>
<div v-if="appSupportInfoRows.length" class="mt-4 grid gap-3 sm:grid-cols-2">
<div v-for="row in appSupportInfoRows" :key="row.key" class="min-w-0 rounded-md bg-muted/30 px-3 py-2">
- <div class="text-xs font-medium text-muted-foreground">{{ row.label }}</div>
- <div class="mt-1 min-w-0 select-text break-words font-mono text-xs text-foreground">{{ row.value }}</div>
+ <div class="text-xs font-medium text-muted-foreground">
+ {{ row.label }}
+ </div>
+ <div class="mt-1 min-w-0 select-text break-words font-mono text-xs text-foreground">
+ {{ row.value }}
+ </div>
</div>
</div>
- <p v-else class="mt-4 text-sm text-muted-foreground">{{ t("settings.supportInfoLoading") }}</p>
- <p v-if="appSupportInfoError" class="mt-3 text-xs text-destructive">{{ t("settings.supportInfoLoadFailed", { message: appSupportInfoError }) }}</p>
+ <p v-else class="mt-4 text-sm text-muted-foreground">
+ {{ t("settings.supportInfoLoading") }}
+ </p>
+ <p v-if="appSupportInfoError" class="mt-3 text-xs text-destructive">
+ {{
+ t("settings.supportInfoLoadFailed", {
+ message: appSupportInfoError,
+ })
+ }}
+ </p>
</div>
<ChangelogPanel />
@@ -5309,7 +5764,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div class="min-w-0 space-y-1">
<Label>{{ t("settings.updateDownloadSource") }}</Label>
- <p class="text-sm text-muted-foreground">{{ t("settings.updateDownloadSourceDescription") }}</p>
+ <p class="text-sm text-muted-foreground">
+ {{ t("settings.updateDownloadSourceDescription") }}
+ </p>
</div>
<Select :model-value="editUpdateDownloadSource" @update:model-value="onUpdateDownloadSourceChange">
<SelectTrigger class="h-9 w-full sm:w-[180px]">
@@ -5365,7 +5822,9 @@ onUnmounted(cleanupPreviewEditor);
{{ t("settings.wechatGroup") }}
<ExternalLink class="ml-auto h-3.5 w-3.5 text-muted-foreground" />
</div>
- <div class="mt-1 text-sm text-primary">{{ t("settings.wechatGroupInvite") }}</div>
+ <div class="mt-1 text-sm text-primary">
+ {{ t("settings.wechatGroupInvite") }}
+ </div>
</button>
<button type="button" class="rounded-lg border p-4 text-left transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" @click="openExternalUrl('https://github.com/t8y2/dbx')">
<div class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
@@ -5517,7 +5976,9 @@ onUnmounted(cleanupPreviewEditor);
<div class="flex flex-col gap-1.5">
<Label for="snippet-prefix">{{ t("settings.snippetsPrefix") }}</Label>
<Input id="snippet-prefix" v-model="snippetForm.prefix" :placeholder="t('settings.snippetsPrefixPlaceholder')" />
- <p v-if="snippetFormPrefixError" class="text-xs text-destructive">{{ snippetFormPrefixError }}</p>
+ <p v-if="snippetFormPrefixError" class="text-xs text-destructive">
+ {{ snippetFormPrefixError }}
+ </p>
</div>
<div class="flex flex-col gap-1.5">
<Label for="snippet-body">{{ t("settings.snippetsBody") }}</Label>
@@ -5542,7 +6003,11 @@ onUnmounted(cleanupPreviewEditor);
<DangerConfirmDialog
v-model:open="templateDeleteConfirmOpen"
:title="t('ai.promptTemplateDeleteTitle')"
- :message="t('ai.promptTemplateDeleteConfirm', { name: templateDeleteConfirm?.name ?? '' })"
+ :message="
+ t('ai.promptTemplateDeleteConfirm', {
+ name: templateDeleteConfirm?.name ?? '',
+ })
+ "
:confirm-label="t('common.delete')"
@confirm="templateDeleteConfirm && confirmDeleteTemplate(templateDeleteConfirm)"
/>
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index ca969391c3..388cef63f0 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -1776,6 +1776,12 @@ export default {
contextWindow: "Context Window",
contextWindowAuto: "Auto (detect from model name)",
contextWindowHint: "Tokens. Leave empty to auto-detect. Set manually for local/custom models.",
+ maxRetries: "Max Retries",
+ maxRetriesHint: "Retry on rate limits, timeouts, and temporary network errors. 0 = never, max 10.",
+ maxRetriesGlobal: "Max Retries",
+ maxRetriesGlobalDescription: "Number of automatic retries on transient API errors (rate limits, timeouts, network blips). Applies to all API-backed AI providers. CLI providers (claude-code, codex, pi) are unaffected.",
+ maxRetriesRange: "{min}–{max}, default {default}",
+ maxRetriesSaved: "Max retries saved",
codexCliPath: "Codex CLI Path",
codexCliPathHint: "Leave empty to use codex from PATH. Sign in separately with codex login.",
codexCliPathEnvError: "Codex CLI Path should contain only the executable path. Add environment variables below.",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 2a1077a13a..344c3a2e7f 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -1815,6 +1815,10 @@ export default withEnglishFallback({
contextWindow: "Ventana de contexto",
contextWindowAuto: "Auto (detectar desde el nombre del modelo)",
contextWindowHint: "Tokens. Déjalo vacío para detección automática. Configúralo manualmente para modelos locales/personalizados.",
+ maxRetriesGlobal: "Reintentos máximos",
+ maxRetriesGlobalDescription: "Número de reintentos automáticos en errores transitorios de API (límite de tasa, timeout, fallos de red). Se aplica a todos los proveedores de IA por API. Los proveedores CLI (claude-code, codex, pi) no se ven afectados.",
+ maxRetriesRange: "{min}–{max}, predeterminado {default}",
+ maxRetriesSaved: "Reintentos máximos guardados",
codexCliPath: "Ruta de Codex CLI",
codexCliPathHint: "Déjalo vacío para usar codex desde PATH. Inicia sesión por separado con codex login.",
actions: {
@@ -1846,6 +1850,8 @@ export default withEnglishFallback({
editResend: "Reenviar",
editCancel: "Cancelar",
cannotDeleteActiveConfig: "No se puede eliminar la configuración activa actual. Cambie a otra configuración primero.",
+ maxRetries: "Número máximo de reintentos",
+ maxRetriesHint: "Reintentar automáticamente en caso de limitación de tasa, tiempo de espera o error de red temporal. 0 = no reintentar, máximo 10.",
},
contextMenu: {
openConnection: "Abrir conexión",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 574045ee93..dd32614c98 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -1755,6 +1755,10 @@ export default withEnglishFallback({
contextWindow: "Finestra di Contesto",
contextWindowAuto: "Auto (rileva dal nome del modello)",
contextWindowHint: "Token. Lascia vuoto per il rilevamento automatico. Imposta manualmente per modelli locali/personalizzati.",
+ maxRetriesGlobal: "Tentativi massimi",
+ maxRetriesGlobalDescription: "Numero di tentativi automatici su errori API transitori (limite di velocità, timeout, problemi di rete). Si applica a tutti i provider IA via API. I provider CLI (claude-code, codex, pi) non sono interessati.",
+ maxRetriesRange: "{min}–{max}, predefinito {default}",
+ maxRetriesSaved: "Tentativi massimi salvati",
codexCliPath: "Percorso Codex CLI",
codexCliPathHint: "Lascia vuoto per usare codex dal PATH. Esegui login separatamente con codex login.",
codexCliPathEnvError: "Codex CLI Path deve contenere solo il percorso dell'eseguibile. Aggiungi le variabili d'ambiente sotto.",
@@ -1844,6 +1848,8 @@ export default withEnglishFallback({
editResend: "Invia di nuovo",
editCancel: "Annulla",
cannotDeleteActiveConfig: "Non è possibile eliminare la configurazione attualmente attiva. Passa a un'altra configurazione prima.",
+ maxRetries: "Numero massimo di tentativi",
+ maxRetriesHint: "Riprova automaticamente in caso di limitazione, timeout o errore di rete temporaneo. 0 = nessun tentativo, massimo 10.",
},
contextMenu: {
openConnection: "Apri Connessione",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index a730ed8e5c..a9394f57d8 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -1649,6 +1649,10 @@ export default withEnglishFallback({
contextWindow: "コンテキストウィンドウ",
contextWindowAuto: "自動(モデル名から検出)",
contextWindowHint: "トークン数。空欄で自動検出。ローカル/カスタムモデルは手動設定してください。",
+ maxRetriesGlobal: "最大再試行回数",
+ maxRetriesGlobalDescription: "一時的なAPIエラー(レート制限、タイムアウト、ネットワーク障害)発生時の自動再試行回数。すべてのAPI対応AIプロバイダーに適用されます。CLIプロバイダー(claude-code、codex、pi)は影響を受けません。",
+ maxRetriesRange: "{min}–{max}、デフォルト {default}",
+ maxRetriesSaved: "最大再試行回数を保存しました",
codexCliPath: "Codex CLI パス",
codexCliPathHint: "空欄の場合はPATHからcodexを使用します。codex loginで別途サインインしてください。",
reasoningLevel: "推論レベル",
@@ -1845,6 +1849,8 @@ export default withEnglishFallback({
editResend: "再送信",
editCancel: "キャンセル",
cannotDeleteActiveConfig: "現在アクティブな設定は削除できません。先に他の設定に切り替えてください。",
+ maxRetries: "最大リトライ回数",
+ maxRetriesHint: "レート制限、タイムアウト、または一時的なネットワークエラーが発生した場合に自動的にリトライします。0 = リトライなし、最大10。",
},
contextMenu: {
openConnection: "接続を開く",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index 9a27824bc0..a29211b035 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -1813,6 +1813,10 @@ export default withEnglishFallback({
contextWindow: "Janela de Contexto",
contextWindowAuto: "Automático (detectar pelo nome do modelo)",
contextWindowHint: "Tokens. Deixe vazio para detecção automática. Defina manualmente para modelos locais/personalizados.",
+ maxRetriesGlobal: "Máximo de Tentativas",
+ maxRetriesGlobalDescription: "Número de tentativas automáticas em erros transitórios de API (limite de taxa, timeout, falhas de rede). Aplica-se a todos os provedores de IA via API. Provedores CLI (claude-code, codex, pi) não são afetados.",
+ maxRetriesRange: "{min}–{max}, padrão {default}",
+ maxRetriesSaved: "Máximo de tentativas salvo",
enableThinking: "Raciocínio",
enableThinkingOn: "Ativado",
enableThinkingOff: "Desativado",
@@ -1846,6 +1850,8 @@ export default withEnglishFallback({
editResend: "Reenviar",
editCancel: "Cancelar",
cannotDeleteActiveConfig: "Não é possível excluir a configuração ativa atual. Mude para outra configuração primeiro.",
+ maxRetries: "Número máximo de tentativas",
+ maxRetriesHint: "Tente novamente automaticamente ao encontrar limitação de taxa, tempo limite ou erro de rede temporário. 0 = não tentar novamente, máximo 10.",
},
contextMenu: {
openConnection: "Abrir Conexão",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 1ef31f1dd7..c3ff1f4644 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -1777,6 +1777,12 @@ export default withEnglishFallback({
contextWindow: "上下文窗口",
contextWindowAuto: "自动(根据模型名称推断)",
contextWindowHint: "单位:token。留空自动推断,本地/自定义模型建议手动设置。",
+ maxRetries: "最大重试次数",
+ maxRetriesHint: "遇到限流、超时或临时网络错误时自动重试。0 = 不重试,最大 10。",
+ maxRetriesGlobal: "最大重试次数",
+ maxRetriesGlobalDescription: "遇到临时 API 错误(限流、超时、网络波动)时的自动重试次数。适用于所有 API 模式 AI 供应商。CLI 供应商(claude-code、codex、pi)不受影响。",
+ maxRetriesRange: "{min}–{max},默认 {default}",
+ maxRetriesSaved: "最大重试次数已保存",
codexCliPath: "Codex CLI 路径",
codexCliPathHint: "留空则使用 PATH 中的 codex。请先在终端执行 codex login 登录。",
codexCliPathEnvError: "Codex CLI 路径只能填写可执行文件路径。请在下方添加环境变量。",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index 523676181d..d2c5aea23d 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -1756,6 +1756,12 @@ export default withEnglishFallback({
contextWindow: "Context Window",
contextWindowAuto: "自動(從模型名稱偵測)",
contextWindowHint: "Token 數。留空以自動偵測。本機/自訂模型請手動設定。",
+ maxRetries: "最大重試次數",
+ maxRetriesHint: "遇到限流、超時或暫時性網路錯誤時自動重試。0 = 不重試,最大 10。",
+ maxRetriesGlobal: "最大重試次數",
+ maxRetriesGlobalDescription: "遇到暫時性 API 錯誤(限流、超時、網路波動)時的自動重試次數。適用於所有 API 模式 AI 供應商。CLI 供應商(claude-code、codex、pi)不受影響。",
+ maxRetriesRange: "{min}–{max},預設 {default}",
+ maxRetriesSaved: "最大重試次數已儲存",
codexCliPath: "Codex CLI 路徑",
codexCliPathHint: "留空以使用 PATH 中的 codex。請另外以 codex login 登入。",
codexMcpRequiredTitle: "需要 DBX MCP Server",
diff --git a/apps/desktop/src/lib/backend/api.ts b/apps/desktop/src/lib/backend/api.ts
index 5342f16df1..7d6e648503 100644
--- a/apps/desktop/src/lib/backend/api.ts
+++ b/apps/desktop/src/lib/backend/api.ts
@@ -272,6 +272,8 @@ export const loadMcpGlobalPolicy = forward("loadMcpGlobalPolicy");
export const saveMcpGlobalPolicy = forward("saveMcpGlobalPolicy");
export const loadMaxAgentTurns = forward("loadMaxAgentTurns");
export const saveMaxAgentTurns = forward("saveMaxAgentTurns");
+export const loadMaxRetries = forward("loadMaxRetries");
+export const saveMaxRetries = forward("saveMaxRetries");
export const completeAppClose = forward("completeAppClose");
export const requestAppClose = forward("requestAppClose");
export const setDriverStoreDir = forward("setDriverStoreDir");
diff --git a/apps/desktop/src/lib/backend/http.ts b/apps/desktop/src/lib/backend/http.ts
index eb880bb0f2..9526c3ae06 100644
--- a/apps/desktop/src/lib/backend/http.ts
+++ b/apps/desktop/src/lib/backend/http.ts
@@ -281,7 +281,10 @@ export async function connectionDatabaseInfo(connectionId: string, database?: st
}
export async function saveConnectionDatabaseInfo(connectionId: string, databaseInfo: DatabaseConnectionInfo): Promise<void> {
- return post("/api/connection/database-info/save", { connectionId, databaseInfo });
+ return post("/api/connection/database-info/save", {
+ connectionId,
+ databaseInfo,
+ });
}
export async function connectionFinalProxyPort(config: ConnectionConfig): Promise<number> {
@@ -297,7 +300,10 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
}
export async function connectionIdentifierQuote(connectionId: string, database?: string): Promise<string | undefined> {
- const quote = await post<string | null>("/api/connection/identifier-quote", { connectionId, database });
+ const quote = await post<string | null>("/api/connection/identifier-quote", {
+ connectionId,
+ database,
+ });
return quote ?? undefined;
}
@@ -376,7 +382,10 @@ export async function importJdbcDrivers(pathsOrFiles: (string | File)[]): Promis
formData.append("files", blob, fileName);
}
}
- const res = await fetch(apiUrl("/api/jdbc/drivers"), { method: "POST", body: formData });
+ const res = await fetch(apiUrl("/api/jdbc/drivers"), {
+ method: "POST",
+ body: formData,
+ });
if (!res.ok) throw new Error(await res.text());
return res.json();
}
@@ -422,7 +431,10 @@ export async function installJdbcPluginLocal(pathOrFile: string | File): Promise
}
const formData = new FormData();
formData.append("file", blob, fileName);
- const uploadRes = await fetch(apiUrl("/api/jdbc/plugin/install-local"), { method: "POST", body: formData });
+ const uploadRes = await fetch(apiUrl("/api/jdbc/plugin/install-local"), {
+ method: "POST",
+ body: formData,
+ });
if (!uploadRes.ok) throw new Error(await uploadRes.text());
return uploadRes.json();
}
@@ -498,7 +510,10 @@ export async function importAgentsFromZip(fileOrPath: string | File, operationId
const formData = new FormData();
if (operationId) formData.append("operationId", operationId);
formData.append("file", fileOrPath);
- const res = await fetch(apiUrl("/api/agents/import-offline"), { method: "POST", body: formData });
+ const res = await fetch(apiUrl("/api/agents/import-offline"), {
+ method: "POST",
+ body: formData,
+ });
if (!res.ok) throw new Error(await res.text());
const result: { count: number } = await res.json();
return result.count;
@@ -517,7 +532,10 @@ export async function importAgentDriver(dbType: string, pathOrFile: string | Fil
const formData = new FormData();
formData.append("dbType", dbType);
formData.append("file", blob, fileName);
- const uploadRes = await fetch(apiUrl("/api/agents/import-driver"), { method: "POST", body: formData });
+ const uploadRes = await fetch(apiUrl("/api/agents/import-driver"), {
+ method: "POST",
+ body: formData,
+ });
if (!uploadRes.ok) throw new Error(await uploadRes.text());
}
@@ -604,7 +622,10 @@ export async function listDatabases(connectionId: string): Promise<DatabaseInfo[
}
export async function listDatabaseStorage(connectionId: string, databases: string[]): Promise<DatabaseStorageInfo[]> {
- return post("/api/schema/database-storage", { connection_id: connectionId, databases });
+ return post("/api/schema/database-storage", {
+ connection_id: connectionId,
+ databases,
+ });
}
export async function listDorisCatalogs(connectionId: string): Promise<CatalogInfo[]> {
@@ -800,7 +821,14 @@ export async function executeQuery(
executionMode?: "simple";
},
): Promise<QueryResult> {
- return post("/api/query/execute", { connectionId, database, sql, schema, executionId, ...options });
+ return post("/api/query/execute", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ executionId,
+ ...options,
+ });
}
export async function executeMulti(
@@ -821,7 +849,14 @@ export async function executeMulti(
executionMode?: "simple";
},
): Promise<QueryResult[]> {
- return post("/api/query/execute-multi", { connectionId, database, sql, schema, executionId, ...options });
+ return post("/api/query/execute-multi", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ executionId,
+ ...options,
+ });
}
export interface ExecuteMultiProgress {
@@ -851,32 +886,66 @@ export async function executeMultiWithProgress(
): Promise<QueryResult[]> {
const executionId = crypto.randomUUID();
const results = await executeMulti(connectionId, database, sql, schema, executionId, options);
- onProgress({ executionId, completed: results.length, total: results.length, success: !results.some((result) => result.execution_error === true) });
+ onProgress({
+ executionId,
+ completed: results.length,
+ total: results.length,
+ success: !results.some((result) => result.execution_error === true),
+ });
return results;
}
export async function closeQuerySession(connectionId: string, database: string, sessionId: string, clientSessionId?: string): Promise<boolean> {
- return post("/api/query/close-session", { connectionId, database, sessionId, clientSessionId });
+ return post("/api/query/close-session", {
+ connectionId,
+ database,
+ sessionId,
+ clientSessionId,
+ });
}
export async function closeClientConnectionSession(connectionId: string, database: string, clientSessionId: string): Promise<boolean> {
- return post("/api/query/close-client-session", { connectionId, database, clientSessionId });
+ return post("/api/query/close-client-session", {
+ connectionId,
+ database,
+ clientSessionId,
+ });
}
export async function executeBatch(connectionId: string, database: string, statements: string[], schema?: string): Promise<QueryResult> {
- return post("/api/query/execute-batch", { connectionId, database, statements, schema });
+ return post("/api/query/execute-batch", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ });
}
export async function executeScript(connectionId: string, database: string, sql: string, schema?: string): Promise<QueryResult> {
- return post("/api/query/execute-script", { connectionId, database, sql, schema });
+ return post("/api/query/execute-script", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ });
}
export async function executeScriptWith2pc(connectionId: string, database: string, statements: string[], schema?: string): Promise<any> {
- return post("/api/query/execute-script-2pc", { connectionId, database, statements, schema });
+ return post("/api/query/execute-script-2pc", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ });
}
export async function executeInTransaction(connectionId: string, database: string, statements: string[], schema?: string): Promise<QueryResult> {
- return post("/api/query/execute-in-transaction", { connectionId, database, statements, schema });
+ return post("/api/query/execute-in-transaction", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ });
}
export async function beginManualTransaction(_connectionId: string, _database: string, _schema?: string): Promise<string> {
@@ -905,7 +974,11 @@ export async function analyzeSqlReferences(sql: string, dialect?: string): Promi
}
export async function findStatementAtCursor(sql: string, cursorPos: number, databaseType?: DatabaseType): Promise<string> {
- return post("/api/query/find-statement-at-cursor", { sql, cursorPos, databaseType });
+ return post("/api/query/find-statement-at-cursor", {
+ sql,
+ cursorPos,
+ databaseType,
+ });
}
export async function prepareQueryPaginationExecutionPlan(options: QueryPaginationExecutionPlanOptions): Promise<QueryPaginationExecutionPlan> {
@@ -921,12 +994,22 @@ export async function buildExplainSql(options: BuildExplainSqlOptions): Promise<
}
export async function buildCreateUserSql(username: string, password: string, tablespace: string): Promise<string> {
- return post("/api/query/build-create-user-sql", { username, password, tablespace });
+ return post("/api/query/build-create-user-sql", {
+ username,
+ password,
+ tablespace,
+ });
}
export async function getExplainInfo(connectionId: string, database: string | undefined, schema: string | undefined, sql: string, mode: string): Promise<string | undefined> {
// Match the Tauri path: transport and Agent failures must remain distinguishable from an empty plan.
- return post<string>("/api/query/get-explain-info", { connectionId, database, schema, sql, mode });
+ return post<string>("/api/query/get-explain-info", {
+ connectionId,
+ database,
+ schema,
+ sql,
+ mode,
+ });
}
export async function buildDroppedFilePreviewSql(options: DroppedFilePreviewSqlOptions): Promise<string | undefined> {
@@ -955,11 +1038,15 @@ export async function buildCreateDatabaseSql(options: CreateDatabaseSqlOptions):
}
export async function buildDuckDbAttachDatabaseSql(path: string, name: string): Promise<string> {
- return post("/api/query/build-duckdb-attach-database-sql", { options: { path, name } });
+ return post("/api/query/build-duckdb-attach-database-sql", {
+ options: { path, name },
+ });
}
export async function buildSqliteAttachDatabaseSql(path: string, name: string): Promise<string> {
- return post("/api/query/build-sqlite-attach-database-sql", { options: { path, name } });
+ return post("/api/query/build-sqlite-attach-database-sql", {
+ options: { path, name },
+ });
}
export async function buildDropObjectSql(options: DropObjectSqlOptions): Promise<string> {
@@ -1007,7 +1094,9 @@ export async function buildCopyTableDataSql(options: CopyTableDataSqlOptions): P
}
export async function buildExecutableObjectSourceStatements(input: BuildEditableObjectSourceSqlInput): Promise<string[]> {
- return post("/api/query/build-executable-object-source-statements", { input });
+ return post("/api/query/build-executable-object-source-statements", {
+ input,
+ });
}
export async function buildExecutableObjectSourceSql(input: BuildEditableObjectSourceSqlInput): Promise<string> {
@@ -1019,7 +1108,9 @@ export async function buildEditableObjectSource(input: BuildEditableObjectSource
}
export async function buildRoutineRenameObjectSourceStatements(input: BuildRoutineRenameObjectSourceInput): Promise<string[]> {
- return post("/api/query/build-routine-rename-object-source-statements", { input });
+ return post("/api/query/build-routine-rename-object-source-statements", {
+ input,
+ });
}
export async function buildViewDdlSql(input: BuildViewDdlInput): Promise<string> {
@@ -1031,11 +1122,20 @@ export async function buildTableStructureChangeSql(options: BuildTableStructureC
}
export async function previewSqliteTableStructureChange(connectionId: string, database: string, options: BuildTableStructureChangeSqlOptions): Promise<SqliteTableStructureChangePreview> {
- return post("/api/query/preview-sqlite-table-structure-change", { connectionId, database, options });
+ return post("/api/query/preview-sqlite-table-structure-change", {
+ connectionId,
+ database,
+ options,
+ });
}
export async function applySqliteTableStructureChange(connectionId: string, database: string, options: BuildTableStructureChangeSqlOptions, schemaRevision: string): Promise<QueryResult> {
- return post("/api/query/apply-sqlite-table-structure-change", { connectionId, database, options, schemaRevision });
+ return post("/api/query/apply-sqlite-table-structure-change", {
+ connectionId,
+ database,
+ options,
+ schemaRevision,
+ });
}
export async function buildCreateTableSql(options: BuildTableStructureChangeSqlOptions): Promise<TableStructureChangeSql> {
@@ -1083,7 +1183,9 @@ export async function buildDataGridColumnValuesFilterCondition(options: DataGrid
}
export async function buildDataGridColumnDistinctValuesSql(options: DataGridColumnDistinctValuesSqlOptions): Promise<string> {
- return post("/api/query/build-data-grid-column-distinct-values-sql", { options });
+ return post("/api/query/build-data-grid-column-distinct-values-sql", {
+ options,
+ });
}
export async function buildDataGridCountSql(options: DataGridCountSqlOptions): Promise<string> {
@@ -1214,7 +1316,18 @@ export async function aiAgentStream(
const res = await fetch(apiUrl("/api/ai/agent-stream"), {
method: "POST",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ sessionId, request, connectionId, database, dbType, mode: mode || "ask", allowWriteSql, confirmedWriteSql, confirmedConnectionId, confirmedDatabase }),
+ body: JSON.stringify({
+ sessionId,
+ request,
+ connectionId,
+ database,
+ dbType,
+ mode: mode || "ask",
+ allowWriteSql,
+ confirmedWriteSql,
+ confirmedConnectionId,
+ confirmedDatabase,
+ }),
signal,
});
if (!res.ok) throw new Error(await res.text());
@@ -1295,7 +1408,12 @@ export async function deleteAiConfig(configId: string): Promise<void> {
export async function loadDesktopSettings(): Promise<DesktopSettings> {
try {
const raw = safeLocalStorageGet(DESKTOP_SETTINGS_STORAGE_KEY);
- return raw ? { ...DEFAULT_DESKTOP_SETTINGS, ...(JSON.parse(raw) as Partial<DesktopSettings>) } : { ...DEFAULT_DESKTOP_SETTINGS };
+ return raw
+ ? {
+ ...DEFAULT_DESKTOP_SETTINGS,
+ ...(JSON.parse(raw) as Partial<DesktopSettings>),
+ }
+ : { ...DEFAULT_DESKTOP_SETTINGS };
} catch {
return { ...DEFAULT_DESKTOP_SETTINGS };
}
@@ -1331,6 +1449,19 @@ export async function saveMaxAgentTurns(maxAgentTurns: number): Promise<void> {
if (!res.ok) throw new Error(await res.text());
}
+export async function loadMaxRetries(): Promise<number> {
+ return get("/api/app-settings/max-retries");
+}
+
+export async function saveMaxRetries(maxRetries: number): Promise<void> {
+ const res = await fetch(apiUrl("/api/app-settings/max-retries"), {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ maxRetries }),
+ });
+ if (!res.ok) throw new Error(await res.text());
+}
+
export interface OpenTabsStatePayload {
tabs: unknown[];
activeTabId: string | null;
@@ -1348,7 +1479,12 @@ export async function loadOpenTabsState(): Promise<OpenTabsStatePayload | null>
const value = await loadBrowserAppState("open_tabs");
if (!value || typeof value !== "object") return null;
const payload = value as Partial<OpenTabsStatePayload>;
- return Array.isArray(payload.tabs) ? { tabs: payload.tabs, activeTabId: typeof payload.activeTabId === "string" ? payload.activeTabId : null } : null;
+ return Array.isArray(payload.tabs)
+ ? {
+ tabs: payload.tabs,
+ activeTabId: typeof payload.activeTabId === "string" ? payload.activeTabId : null,
+ }
+ : null;
}
export async function saveOpenTabsState(payload: OpenTabsStatePayload): Promise<void> {
@@ -1487,7 +1623,10 @@ export async function webdavSyncSecretsStatus(): Promise<WebDavSyncSecretsStatus
}
export async function saveWebdavSyncSecretsPreference(enabled: boolean, passphrase?: string): Promise<void> {
- return post("/api/cloud-sync/webdav/save-sync-secrets-preference", { enabled, passphrase });
+ return post("/api/cloud-sync/webdav/save-sync-secrets-preference", {
+ enabled,
+ passphrase,
+ });
}
export async function forgetWebdavSyncSecretsPassphrase(): Promise<void> {
@@ -1495,7 +1634,11 @@ export async function forgetWebdavSyncSecretsPassphrase(): Promise<void> {
}
export async function webdavSyncUpload(config: WebDavConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<WebDavSyncSummary> {
- return post("/api/cloud-sync/webdav/upload", { config, editorSettings, secretsPassphrase });
+ return post("/api/cloud-sync/webdav/upload", {
+ config,
+ editorSettings,
+ secretsPassphrase,
+ });
}
export async function webdavSyncDownload(config: WebDavConfig, secretsPassphrase?: string): Promise<WebDavDownloadResult> {
@@ -1519,11 +1662,18 @@ export async function forgetSnippetSavedToken(config: SnippetSyncConfig): Promis
}
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
- return post("/api/cloud-sync/snippet/upload", { config, editorSettings, secretsPassphrase });
+ return post("/api/cloud-sync/snippet/upload", {
+ config,
+ editorSettings,
+ secretsPassphrase,
+ });
}
export async function snippetSyncDownload(config: SnippetSyncConfig, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
- return post("/api/cloud-sync/snippet/download", { config, secretsPassphrase });
+ return post("/api/cloud-sync/snippet/download", {
+ config,
+ secretsPassphrase,
+ });
}
export async function loadPinnedTreeNodeIds(): Promise<string[]> {
@@ -1584,7 +1734,10 @@ export async function previewSqlFile(fileOrPath: string | File): Promise<SqlFile
}
const formData = new FormData();
formData.append("file", fileOrPath);
- const res = await fetch(apiUrl("/api/sql-file/preview"), { method: "POST", body: formData });
+ const res = await fetch(apiUrl("/api/sql-file/preview"), {
+ method: "POST",
+ body: formData,
+ });
if (!res.ok) throw new Error(await res.text());
return res.json();
}
@@ -1725,7 +1878,10 @@ export async function previewTableImportFile(fileOrPath: string | File | TableIm
if (options.sourceFormat) formData.append("sourceFormat", options.sourceFormat);
if (options.parseOptions) formData.append("parseOptions", JSON.stringify(options.parseOptions));
if (options.previewLimit != null) formData.append("previewLimit", String(options.previewLimit));
- const res = await fetch(apiUrl("/api/import/preview"), { method: "POST", body: formData });
+ const res = await fetch(apiUrl("/api/import/preview"), {
+ method: "POST",
+ body: formData,
+ });
if (!res.ok) throw new Error(await res.text());
return res.json();
}
@@ -1947,7 +2103,9 @@ export async function exportQueryResultCsv(filePath: string, columns: string[],
const { formatCsv } = await import("@/lib/export/exportFormats");
const content = formatCsv(columns, rows as (string | number | boolean | null)[][]);
const fileName = filePath.split(/[\\/]/).pop() || "export.csv";
- const blob = new Blob(["\uFEFF", content], { type: "text/csv;charset=utf-8" });
+ const blob = new Blob(["\uFEFF", content], {
+ type: "text/csv;charset=utf-8",
+ });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
@@ -1992,7 +2150,16 @@ export async function exportQueryResultXlsx(filePath: string, sheetName: string
URL.revokeObjectURL(url);
}
-export async function exportQueryResultsXlsx(filePath: string, worksheets: readonly { sheetName?: string; columns: readonly string[]; columnTypes?: readonly string[]; rows: readonly (readonly XlsxCellValue[])[]; numericColumnRightAlign?: boolean }[]): Promise<void> {
+export async function exportQueryResultsXlsx(
+ filePath: string,
+ worksheets: readonly {
+ sheetName?: string;
+ columns: readonly string[];
+ columnTypes?: readonly string[];
+ rows: readonly (readonly XlsxCellValue[])[];
+ numericColumnRightAlign?: boolean;
+ }[],
+): Promise<void> {
const { buildXlsxWorkbookMulti } = await import("@/lib/export/xlsxExport");
const workbook = buildXlsxWorkbookMulti(worksheets);
const fileName = filePath.split(/[\\/]/).pop() || "export.xlsx";
@@ -2026,15 +2193,37 @@ export async function redisListDatabases(connectionId: string): Promise<RedisDat
}
export async function redisScanKeys(connectionId: string, db: number, cursor: number, pattern: string, count: number): Promise<RedisScanResult> {
- return post("/api/redis/scan-keys", { connectionId, db, cursor, pattern, count });
+ return post("/api/redis/scan-keys", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ count,
+ });
}
export async function redisScanKeysBatch(connectionId: string, db: number, cursor: number, pattern: string, count: number, maxIterations: number, includeTypes = true): Promise<RedisScanResult> {
- return post("/api/redis/scan-keys-batch", { connectionId, db, cursor, pattern, count, maxIterations, includeTypes });
+ return post("/api/redis/scan-keys-batch", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ count,
+ maxIterations,
+ includeTypes,
+ });
}
export async function redisScanValues(connectionId: string, db: number, cursor: number, pattern: string, query: string, count: number, includeKeyMatches = false): Promise<RedisScanResult> {
- return post("/api/redis/scan-values", { connectionId, db, cursor, pattern, query, includeKeyMatches, count });
+ return post("/api/redis/scan-values", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ query,
+ includeKeyMatches,
+ count,
+ });
}
export async function redisGetValue(connectionId: string, db: number, keyRaw: string): Promise<RedisValue> {
@@ -2046,15 +2235,33 @@ export async function redisGetStreamGroups(connectionId: string, db: number, key
}
export async function redisGetStreamConsumers(connectionId: string, db: number, keyRaw: string, groupRaw: string): Promise<RedisStreamConsumer[]> {
- return post("/api/redis/get-stream-consumers", { connectionId, db, keyRaw, groupRaw });
+ return post("/api/redis/get-stream-consumers", {
+ connectionId,
+ db,
+ keyRaw,
+ groupRaw,
+ });
}
export async function redisGetStreamPending(connectionId: string, db: number, keyRaw: string, groupRaw: string, cursor?: string, consumerRaw?: string): Promise<RedisStreamPendingPage> {
- return post("/api/redis/get-stream-pending", { connectionId, db, keyRaw, groupRaw, cursor, ...(consumerRaw === undefined ? {} : { consumerRaw }) });
+ return post("/api/redis/get-stream-pending", {
+ connectionId,
+ db,
+ keyRaw,
+ groupRaw,
+ cursor,
+ ...(consumerRaw === undefined ? {} : { consumerRaw }),
+ });
}
export async function redisSetString(connectionId: string, db: number, keyRaw: string, value: string, ttl?: number): Promise<void> {
- return post("/api/redis/set-string", { connectionId, db, keyRaw, value, ttl });
+ return post("/api/redis/set-string", {
+ connectionId,
+ db,
+ keyRaw,
+ value,
+ ttl,
+ });
}
export async function redisDeleteKey(connectionId: string, db: number, keyRaw: string): Promise<void> {
@@ -2062,7 +2269,14 @@ export async function redisDeleteKey(connectionId: string, db: number, keyRaw: s
}
export async function redisHashSet(connectionId: string, db: number, keyRaw: string, field: string, value: string, ttl?: number): Promise<void> {
- return post("/api/redis/hash-set", { connectionId, db, keyRaw, field, value, ttl });
+ return post("/api/redis/hash-set", {
+ connectionId,
+ db,
+ keyRaw,
+ field,
+ value,
+ ttl,
+ });
}
export async function redisHashDel(connectionId: string, db: number, keyRaw: string, field: string): Promise<void> {
@@ -2074,7 +2288,13 @@ export async function redisListPush(connectionId: string, db: number, keyRaw: st
}
export async function redisListSet(connectionId: string, db: number, keyRaw: string, index: number, value: string): Promise<void> {
- return post("/api/redis/list-set", { connectionId, db, keyRaw, index, value });
+ return post("/api/redis/list-set", {
+ connectionId,
+ db,
+ keyRaw,
+ index,
+ value,
+ });
}
export async function redisListRemove(connectionId: string, db: number, keyRaw: string, index: number): Promise<void> {
@@ -2090,7 +2310,14 @@ export async function redisSetRemove(connectionId: string, db: number, keyRaw: s
}
export async function redisZadd(connectionId: string, db: number, keyRaw: string, member: string, score: number, ttl?: number): Promise<void> {
- return post("/api/redis/zadd", { connectionId, db, keyRaw, member, score, ttl });
+ return post("/api/redis/zadd", {
+ connectionId,
+ db,
+ keyRaw,
+ member,
+ score,
+ ttl,
+ });
}
export async function redisZrem(connectionId: string, db: number, keyRaw: string, member: string): Promise<void> {
@@ -2098,7 +2325,14 @@ export async function redisZrem(connectionId: string, db: number, keyRaw: string
}
export async function redisStreamAdd(connectionId: string, db: number, keyRaw: string, entryId: string, fields: [string, string][], ttl?: number): Promise<void> {
- return post("/api/redis/stream-add", { connectionId, db, keyRaw, entryId, fields, ttl });
+ return post("/api/redis/stream-add", {
+ connectionId,
+ db,
+ keyRaw,
+ entryId,
+ fields,
+ ttl,
+ });
}
export async function redisJsonSet(connectionId: string, db: number, keyRaw: string, value: string, ttl?: number): Promise<void> {
@@ -2114,7 +2348,12 @@ export async function redisSetTtl(connectionId: string, db: number, keyRaw: stri
}
export async function redisSetExpireAt(connectionId: string, db: number, keyRaw: string, expireAt: number): Promise<void> {
- return post("/api/redis/set-expire-at", { connectionId, db, keyRaw, expireAt });
+ return post("/api/redis/set-expire-at", {
+ connectionId,
+ db,
+ keyRaw,
+ expireAt,
+ });
}
export async function redisDeleteKeys(connectionId: string, db: number, keyRaws: string[]): Promise<number> {
@@ -2126,15 +2365,33 @@ export async function redisFlushDb(connectionId: string, db: number): Promise<vo
}
export async function redisExecuteCommand(connectionId: string, db: number, command: string, skipSafetyCheck?: boolean): Promise<RedisCommandResult> {
- return post("/api/redis/execute-command", { connectionId, db, command, skipSafetyCheck: skipSafetyCheck ?? false });
+ return post("/api/redis/execute-command", {
+ connectionId,
+ db,
+ command,
+ skipSafetyCheck: skipSafetyCheck ?? false,
+ });
}
export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisCollectionPage> {
- return post("/api/redis/load-more", { connectionId, db, keyRaw, keyType, cursor, count, filter });
+ return post("/api/redis/load-more", {
+ connectionId,
+ db,
+ keyRaw,
+ keyType,
+ cursor,
+ count,
+ filter,
+ });
}
export async function redisPubSubPublish(connectionId: string, db: number, channel: string, message: string): Promise<{ subscribers: number }> {
- return post("/api/redis/pubsub/publish", { connectionId, db, channel, message });
+ return post("/api/redis/pubsub/publish", {
+ connectionId,
+ db,
+ channel,
+ message,
+ });
}
export async function redisPubSubConnect(connectionId: string): Promise<WebSocket> {
@@ -2142,7 +2399,12 @@ export async function redisPubSubConnect(connectionId: string): Promise<WebSocke
}
export async function redisSlowlogGet(connectionId: string, count: number, nodeHost?: string, nodePort?: number): Promise<RedisSlowlogEntry[]> {
- return post("/api/redis/slowlog-get", { connectionId, count, nodeHost, nodePort });
+ return post("/api/redis/slowlog-get", {
+ connectionId,
+ count,
+ nodeHost,
+ nodePort,
+ });
}
export async function redisClusterMasterNodes(connectionId: string): Promise<RedisNodeEndpoint[]> {
@@ -2154,7 +2416,14 @@ export async function redisClusterMasterNodes(connectionId: string): Promise<Red
// ---------------------------------------------------------------------------
export async function etcdListPrefix(connectionId: string, prefix: string, limit: number, continuation?: string | null, options?: KvListPrefixOptions | null): Promise<KvListPrefixResponse> {
- return post("/api/etcd/list-prefix", { connectionId, prefix, limit, continuation, revision: options?.revision ?? null, includeValues: options?.includeValues ?? null });
+ return post("/api/etcd/list-prefix", {
+ connectionId,
+ prefix,
+ limit,
+ continuation,
+ revision: options?.revision ?? null,
+ includeValues: options?.includeValues ?? null,
+ });
}
export async function etcdSupportsTtl(connectionId: string): Promise<boolean> {
@@ -2162,7 +2431,13 @@ export async function etcdSupportsTtl(connectionId: string): Promise<boolean> {
}
export async function etcdGet(connectionId: string, key: string, options?: KvGetOptions | null): Promise<KvGetResponse> {
- return post("/api/etcd/get", { connectionId, key, keyBytes: options?.keyBytes ?? null, revision: options?.revision ?? null, metadataOnly: options?.metadataOnly ?? null });
+ return post("/api/etcd/get", {
+ connectionId,
+ key,
+ keyBytes: options?.keyBytes ?? null,
+ revision: options?.revision ?? null,
+ metadataOnly: options?.metadataOnly ?? null,
+ });
}
export async function etcdPut(connectionId: string, key: string, value: KvValue, options?: KvPutOptions | number | null): Promise<KvPutResponse> {
@@ -2182,14 +2457,36 @@ export async function etcdPut(connectionId: string, key: string, value: KvValue,
}
export async function etcdDelete(connectionId: string, key: string, options?: KvDeleteOptions | null): Promise<KvDeleteResponse> {
- return post("/api/etcd/delete", { connectionId, key, keyBytes: options?.keyBytes ?? null, expectedModRevision: options?.expectedModRevision ?? null });
+ return post("/api/etcd/delete", {
+ connectionId,
+ key,
+ keyBytes: options?.keyBytes ?? null,
+ expectedModRevision: options?.expectedModRevision ?? null,
+ });
}
-export async function etcdRename(connectionId: string, request: { key: string; keyBytes?: KvValue | null; newKey: string; expectedModRevision?: KvInt64 | null }): Promise<{ renamed: boolean; revision?: KvInt64 | null }> {
+export async function etcdRename(
+ connectionId: string,
+ request: {
+ key: string;
+ keyBytes?: KvValue | null;
+ newKey: string;
+ expectedModRevision?: KvInt64 | null;
+ },
+): Promise<{ renamed: boolean; revision?: KvInt64 | null }> {
return post("/api/etcd/rename", { connectionId, request });
}
-export async function etcdHistory(connectionId: string, request: { key: string; keyBytes?: KvValue | null; startRevision?: KvInt64 | null; endRevision?: KvInt64 | null; limit: number }): Promise<KvHistoryResponse> {
+export async function etcdHistory(
+ connectionId: string,
+ request: {
+ key: string;
+ keyBytes?: KvValue | null;
+ startRevision?: KvInt64 | null;
+ endRevision?: KvInt64 | null;
+ limit: number;
+ },
+): Promise<KvHistoryResponse> {
return post("/api/etcd/history", { connectionId, request });
}
@@ -2202,7 +2499,13 @@ export async function etcdStatus(connectionId: string): Promise<KvStatusResponse
// ---------------------------------------------------------------------------
export async function zookeeperListPrefix(connectionId: string, prefix: string, limit: number, continuation?: string | null, options?: KvListPrefixOptions | null): Promise<KvListPrefixResponse> {
- return post("/api/zookeeper/list-prefix", { connectionId, prefix, limit, continuation, recursive: options?.recursive ?? null });
+ return post("/api/zookeeper/list-prefix", {
+ connectionId,
+ prefix,
+ limit,
+ continuation,
+ recursive: options?.recursive ?? null,
+ });
}
export async function zookeeperGet(connectionId: string, key: string): Promise<KvGetResponse> {
@@ -2210,7 +2513,12 @@ export async function zookeeperGet(connectionId: string, key: string): Promise<K
}
export async function zookeeperPut(connectionId: string, key: string, value: KvValue, options?: KvPutOptions | null): Promise<KvPutResponse> {
- return post("/api/zookeeper/put", { connectionId, key, value, options: options ?? null });
+ return post("/api/zookeeper/put", {
+ connectionId,
+ key,
+ value,
+ options: options ?? null,
+ });
}
export async function zookeeperDelete(connectionId: string, key: string): Promise<KvDeleteResponse> {
@@ -2322,14 +2630,24 @@ export async function nacosPreviewConfigImport(connectionId: string, targetNames
formData.append("connectionId", connectionId);
formData.append("targetNamespace", targetNamespace);
formData.append("file", archivePath, archivePath.name);
- const response = await fetch(apiUrl("/api/nacos/configs/import/preview"), { method: "POST", body: formData });
+ const response = await fetch(apiUrl("/api/nacos/configs/import/preview"), {
+ method: "POST",
+ body: formData,
+ });
if (!response.ok) throw new Error(await response.text());
return response.json();
}
export async function nacosApplyConfigImport(connectionId: string, operationId: string, targetNamespace: string, _archivePath: string | File, planHash: string, conflictPolicy: NacosConflictPolicy, archiveToken?: string): Promise<NacosBatchReport> {
if (!archiveToken) throw new Error("The Nacos import preview token is missing or expired");
- return post("/api/nacos/configs/import/apply", { connectionId, operationId, targetNamespace, archiveToken, planHash, conflictPolicy });
+ return post("/api/nacos/configs/import/apply", {
+ connectionId,
+ operationId,
+ targetNamespace,
+ archiveToken,
+ planHash,
+ conflictPolicy,
+ });
}
export async function nacosPreviewConfigTransfer(req: NacosConfigTransferRequest): Promise<NacosBatchPreview> {
@@ -2389,11 +2707,23 @@ export async function hbaseGetTableSchema(connectionId: string, namespace: strin
}
export async function hbaseScanRows(connectionId: string, namespace: string, table: string, rowKeyPrefix: string | undefined, limit: number): Promise<import("@/types/hbase").HBaseScanResult> {
- return post("/api/hbase/scan-rows", { connectionId, namespace, table, rowKeyPrefix, limit });
+ return post("/api/hbase/scan-rows", {
+ connectionId,
+ namespace,
+ table,
+ rowKeyPrefix,
+ limit,
+ });
}
export async function hbaseGetRow(connectionId: string, namespace: string, table: string, rowKey: string, rowKeyEncoding?: import("@/types/hbase").HBaseValueEncoding): Promise<import("@/types/hbase").HBaseRow | null> {
- return post("/api/hbase/get-row", { connectionId, namespace, table, rowKey, rowKeyEncoding });
+ return post("/api/hbase/get-row", {
+ connectionId,
+ namespace,
+ table,
+ rowKey,
+ rowKeyEncoding,
+ });
}
export async function hbasePutRow(connectionId: string, namespace: string, table: string, input: import("@/types/hbase").HBasePutRowInput): Promise<void> {
@@ -2401,11 +2731,22 @@ export async function hbasePutRow(connectionId: string, namespace: string, table
}
export async function hbaseDeleteRow(connectionId: string, namespace: string, table: string, rowKey: string, rowKeyEncoding?: import("@/types/hbase").HBaseValueEncoding): Promise<void> {
- return post("/api/hbase/delete-row", { connectionId, namespace, table, rowKey, rowKeyEncoding });
+ return post("/api/hbase/delete-row", {
+ connectionId,
+ namespace,
+ table,
+ rowKey,
+ rowKeyEncoding,
+ });
}
export async function hbaseCreateTable(connectionId: string, namespace: string, table: string, columnFamilies: string[]): Promise<void> {
- return post("/api/hbase/create-table", { connectionId, namespace, table, columnFamilies });
+ return post("/api/hbase/create-table", {
+ connectionId,
+ namespace,
+ table,
+ columnFamilies,
+ });
}
export async function hbaseDeleteTable(connectionId: string, namespace: string, table: string): Promise<void> {
@@ -2425,7 +2766,10 @@ export async function mongoListDatabases(connectionId: string): Promise<string[]
}
export async function documentListCollections(connectionId: string, database: string): Promise<CollectionInfo[]> {
- return post("/api/document-store/list-collections", { connectionId, database });
+ return post("/api/document-store/list-collections", {
+ connectionId,
+ database,
+ });
}
export async function mongoListCollections(connectionId: string, database: string): Promise<CollectionInfo[]> {
@@ -2441,11 +2785,20 @@ export async function mongoDropDatabase(connectionId: string, database: string):
}
export async function mongoDropCollection(connectionId: string, database: string, collection: string): Promise<void> {
- await post("/api/mongo/drop-collection", { connectionId, database, collection });
+ await post("/api/mongo/drop-collection", {
+ connectionId,
+ database,
+ collection,
+ });
}
export async function mongoRenameCollection(connectionId: string, database: string, collection: string, newName: string): Promise<void> {
- await post("/api/mongo/rename-collection", { connectionId, database, collection, newName });
+ await post("/api/mongo/rename-collection", {
+ connectionId,
+ database,
+ collection,
+ newName,
+ });
}
export async function elasticsearchListIndices(connectionId: string): Promise<string[]> {
@@ -2458,7 +2811,11 @@ export async function vectorListCollections(connectionId: string, database?: str
}
export async function vectorGetCollectionDetail(connectionId: string, database: string, collection: string): Promise<CollectionInfo> {
- return post("/api/mongo/vector-collection-detail", { connectionId, database, collection });
+ return post("/api/mongo/vector-collection-detail", {
+ connectionId,
+ database,
+ collection,
+ });
}
export async function mongoFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, executionId?: string): Promise<MongoDocumentResult> {
@@ -2471,35 +2828,84 @@ export async function mongoParseShellCommand(source: string): Promise<MongoComma
}
export async function mongoFindOne(connectionId: string, database: string, collection: string, filter?: string, projection?: string, options?: string, executionId?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/find-one", { connectionId, database, collection, filter, projection, options, executionId });
+ return post("/api/mongo/find-one", {
+ connectionId,
+ database,
+ collection,
+ filter,
+ projection,
+ options,
+ executionId,
+ });
}
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, executionId?: string): Promise<DocumentQueryResult> {
- return post("/api/document-store/find-documents", { connectionId, database, collection, skip, limit, filter, projection, sort, executionId });
+ return post("/api/document-store/find-documents", {
+ connectionId,
+ database,
+ collection,
+ skip,
+ limit,
+ filter,
+ projection,
+ sort,
+ executionId,
+ });
}
export async function elasticsearchCountDocuments(connectionId: string, index: string, filter?: string, executionId?: string): Promise<number> {
- return post("/api/document-store/elasticsearch-count-documents", { connectionId, index, filter, executionId });
+ return post("/api/document-store/elasticsearch-count-documents", {
+ connectionId,
+ index,
+ filter,
+ executionId,
+ });
}
export async function mongoCountDocuments(connectionId: string, database: string, collection: string, filter?: string, mode?: "accurate" | "legacy", executionId?: string): Promise<number> {
- return post("/api/mongo/count-documents", { connectionId, database, collection, filter, mode, executionId });
+ return post("/api/mongo/count-documents", {
+ connectionId,
+ database,
+ collection,
+ filter,
+ mode,
+ executionId,
+ });
}
export async function documentListGridFsFiles(connectionId: string, database: string, bucket: string, filter?: string, sort?: string): Promise<MongoGridFsFileInfo[]> {
- return post("/api/document-store/list-gridfs-files", { connectionId, database, bucket, filter, sort });
+ return post("/api/document-store/list-gridfs-files", {
+ connectionId,
+ database,
+ bucket,
+ filter,
+ sort,
+ });
}
export async function documentListGridFsBuckets(connectionId: string, database: string, filter?: string, sort?: string): Promise<MongoGridFsBucketInfo[]> {
- return post("/api/document-store/list-gridfs-buckets", { connectionId, database, filter, sort });
+ return post("/api/document-store/list-gridfs-buckets", {
+ connectionId,
+ database,
+ filter,
+ sort,
+ });
}
export async function documentCreateGridFsBucket(connectionId: string, database: string, bucket: string): Promise<void> {
- return post("/api/document-store/create-gridfs-bucket", { connectionId, database, bucket });
+ return post("/api/document-store/create-gridfs-bucket", {
+ connectionId,
+ database,
+ bucket,
+ });
}
export async function documentDeleteGridFsBucket(connectionId: string, database: string, bucket: string): Promise<void> {
- return post("/api/document-store/delete-gridfs-bucket", { connectionId, database, bucket });
+ return post("/api/document-store/delete-gridfs-bucket", {
+ connectionId,
+ database,
+ bucket,
+ });
}
export async function documentDownloadGridFsFile(connectionId: string, database: string, bucket: string, fileId: string): Promise<Uint8Array> {
@@ -2532,31 +2938,73 @@ export async function documentUploadGridFsFile(connectionId: string, database: s
}
export async function documentDeleteGridFsFile(connectionId: string, database: string, bucket: string, fileId: string): Promise<void> {
- return post("/api/document-store/delete-gridfs-file", { connectionId, database, bucket, fileId });
+ return post("/api/document-store/delete-gridfs-file", {
+ connectionId,
+ database,
+ bucket,
+ fileId,
+ });
}
export async function mongoServerVersion(connectionId: string, database: string, executionId?: string): Promise<string> {
- return post("/api/mongo/server-version", { connectionId, database, executionId });
+ return post("/api/mongo/server-version", {
+ connectionId,
+ database,
+ executionId,
+ });
}
export async function mongoAggregateDocuments(connectionId: string, database: string, collection: string, pipelineJson: string, maxRows?: number, optionsJson?: string, executionId?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/aggregate-documents", { connectionId, database, collection, pipelineJson, maxRows, optionsJson, executionId });
+ return post("/api/mongo/aggregate-documents", {
+ connectionId,
+ database,
+ collection,
+ pipelineJson,
+ maxRows,
+ optionsJson,
+ executionId,
+ });
}
export async function mongoDistinct(connectionId: string, database: string, collection: string, field: string, filter?: string, executionId?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/distinct", { connectionId, database, collection, field, filter, executionId });
+ return post("/api/mongo/distinct", {
+ connectionId,
+ database,
+ collection,
+ field,
+ filter,
+ executionId,
+ });
}
export async function mongoCollectionStats(connectionId: string, database: string, collection: string, scale?: number, executionId?: string): Promise<MongoCollectionStatsResult> {
- return post("/api/mongo/collection-stats", { connectionId, database, collection, scale, executionId });
+ return post("/api/mongo/collection-stats", {
+ connectionId,
+ database,
+ collection,
+ scale,
+ executionId,
+ });
}
export async function mongoCreateIndex(connectionId: string, database: string, collection: string, keysJson: string, optionsJson?: string): Promise<{ name: string }> {
- return post("/api/mongo/create-index", { connectionId, database, collection, keysJson, optionsJson });
+ return post("/api/mongo/create-index", {
+ connectionId,
+ database,
+ collection,
+ keysJson,
+ optionsJson,
+ });
}
export async function mongoDropIndexes(connectionId: string, database: string, collection: string, indexesJson?: string, single = false): Promise<{ dropped_names: string[]; affected_rows: number }> {
- return post("/api/mongo/drop-indexes", { connectionId, database, collection, indexesJson, single });
+ return post("/api/mongo/drop-indexes", {
+ connectionId,
+ database,
+ collection,
+ indexesJson,
+ single,
+ });
}
export async function mongoInsertDocument(connectionId: string, database: string, collection: string, docJson: string, routing?: string): Promise<string> {
@@ -2564,11 +3012,22 @@ export async function mongoInsertDocument(connectionId: string, database: string
}
export async function documentInsertDocument(connectionId: string, database: string, collection: string, docJson: string, routing?: string): Promise<string> {
- return post("/api/document-store/insert-document", { connectionId, database, collection, docJson, routing });
+ return post("/api/document-store/insert-document", {
+ connectionId,
+ database,
+ collection,
+ docJson,
+ routing,
+ });
}
export async function mongoInsertDocuments(connectionId: string, database: string, collection: string, docsJson: string): Promise<{ affected_rows: number }> {
- return post("/api/mongo/insert-documents", { connectionId, database, collection, docsJson });
+ return post("/api/mongo/insert-documents", {
+ connectionId,
+ database,
+ collection,
+ docsJson,
+ });
}
export async function mongoUpdateDocument(connectionId: string, database: string, collection: string, id: string, docJson: string, routing?: string): Promise<number> {
@@ -2576,11 +3035,26 @@ export async function mongoUpdateDocument(connectionId: string, database: string
}
export async function documentUpdateDocument(connectionId: string, database: string, collection: string, id: string, docJson: string, routing?: string): Promise<number> {
- return post("/api/document-store/update-document", { connectionId, database, collection, id, docJson, routing });
+ return post("/api/document-store/update-document", {
+ connectionId,
+ database,
+ collection,
+ id,
+ docJson,
+ routing,
+ });
}
export async function mongoUpdateDocuments(connectionId: string, database: string, collection: string, filterJson: string, updateJson: string, many: boolean, optionsJson?: string): Promise<{ affected_rows: number }> {
- return post("/api/mongo/update-documents", { connectionId, database, collection, filterJson, updateJson, many, optionsJson });
+ return post("/api/mongo/update-documents", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ updateJson,
+ many,
+ optionsJson,
+ });
}
export async function mongoDeleteDocument(connectionId: string, database: string, collection: string, id: string, routing?: string): Promise<number> {
@@ -2588,23 +3062,55 @@ export async function mongoDeleteDocument(connectionId: string, database: string
}
export async function documentDeleteDocument(connectionId: string, database: string, collection: string, id: string, routing?: string): Promise<number> {
- return post("/api/document-store/delete-document", { connectionId, database, collection, id, routing });
+ return post("/api/document-store/delete-document", {
+ connectionId,
+ database,
+ collection,
+ id,
+ routing,
+ });
}
export async function mongoDeleteDocuments(connectionId: string, database: string, collection: string, filterJson: string, many: boolean): Promise<{ affected_rows: number }> {
- return post("/api/mongo/delete-documents", { connectionId, database, collection, filterJson, many });
+ return post("/api/mongo/delete-documents", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ many,
+ });
}
export async function mongoFindOneAndUpdate(connectionId: string, database: string, collection: string, filterJson: string, updateJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/find-one-and-update", { connectionId, database, collection, filterJson, updateJson, optionsJson });
+ return post("/api/mongo/find-one-and-update", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ updateJson,
+ optionsJson,
+ });
}
export async function mongoFindOneAndReplace(connectionId: string, database: string, collection: string, filterJson: string, replacementJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/find-one-and-replace", { connectionId, database, collection, filterJson, replacementJson, optionsJson });
+ return post("/api/mongo/find-one-and-replace", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ replacementJson,
+ optionsJson,
+ });
}
export async function mongoFindOneAndDelete(connectionId: string, database: string, collection: string, filterJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return post("/api/mongo/find-one-and-delete", { connectionId, database, collection, filterJson, optionsJson });
+ return post("/api/mongo/find-one-and-delete", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ optionsJson,
+ });
}
// ---------------------------------------------------------------------------
diff --git a/apps/desktop/src/lib/backend/tauri.ts b/apps/desktop/src/lib/backend/tauri.ts
index f0d25ed3d0..df2f708b1f 100644
--- a/apps/desktop/src/lib/backend/tauri.ts
+++ b/apps/desktop/src/lib/backend/tauri.ts
@@ -393,11 +393,29 @@ export type AgentEvent =
| { type: "turn_start"; turn: number }
| { type: "text_delta"; delta: string }
| { type: "reasoning_delta"; delta: string }
- | { type: "tool_call_start"; tool_call_id: string; tool_name: string; args: Record<string, unknown> }
- | { type: "tool_call_end"; tool_call_id: string; tool_name: string; result: unknown; is_error: boolean }
+ | {
+ type: "tool_call_start";
+ tool_call_id: string;
+ tool_name: string;
+ args: Record<string, unknown>;
+ }
+ | {
+ type: "tool_call_end";
+ tool_call_id: string;
+ tool_name: string;
+ result: unknown;
+ is_error: boolean;
+ }
| { type: "turn_end"; turn: number }
| { type: "agent_end"; input_tokens?: number; output_tokens?: number }
- | { type: "context_compacted"; summary: string; summary_tokens: number; compacted_messages: number; estimated_before: number; estimated_after: number }
+ | {
+ type: "context_compacted";
+ summary: string;
+ summary_tokens: number;
+ compacted_messages: number;
+ estimated_before: number;
+ estimated_after: number;
+ }
| { type: "error"; message: string };
export async function aiAgentStream(
@@ -421,7 +439,18 @@ export async function aiAgentStream(
}
});
try {
- return await invoke("ai_agent_stream", { sessionId, request, connectionId, database, dbType, mode, allowWriteSql, confirmedWriteSql, confirmedConnectionId, confirmedDatabase });
+ return await invoke("ai_agent_stream", {
+ sessionId,
+ request,
+ connectionId,
+ database,
+ dbType,
+ mode,
+ allowWriteSql,
+ confirmedWriteSql,
+ confirmedConnectionId,
+ confirmedDatabase,
+ });
} catch (e) {
unlisten();
throw e;
@@ -512,6 +541,14 @@ export async function saveMaxAgentTurns(maxAgentTurns: number): Promise<void> {
return invoke("save_max_agent_turns", { maxAgentTurns });
}
+export async function loadMaxRetries(): Promise<number> {
+ return invoke("load_max_retries");
+}
+
+export async function saveMaxRetries(maxRetries: number): Promise<void> {
+ return invoke("save_max_retries", { maxRetries });
+}
+
export interface OpenTabsStatePayload {
tabs: unknown[];
activeTabId: string | null;
@@ -612,7 +649,11 @@ export async function forgetWebdavSyncSecretsPassphrase(): Promise<void> {
}
export async function webdavSyncUpload(config: WebDavConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<WebDavSyncSummary> {
- return invoke("webdav_sync_upload", { config, editorSettings, secretsPassphrase });
+ return invoke("webdav_sync_upload", {
+ config,
+ editorSettings,
+ secretsPassphrase,
+ });
}
export async function webdavSyncDownload(config: WebDavConfig, secretsPassphrase?: string): Promise<WebDavDownloadResult> {
@@ -636,7 +677,11 @@ export async function forgetSnippetSavedToken(config: SnippetSyncConfig): Promis
}
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
- return invoke("snippet_sync_upload", { config, editorSettings, secretsPassphrase });
+ return invoke("snippet_sync_upload", {
+ config,
+ editorSettings,
+ secretsPassphrase,
+ });
}
export async function snippetSyncDownload(config: SnippetSyncConfig, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
@@ -766,7 +811,9 @@ export async function testConnection(config: ConnectionConfig): Promise<string>
export async function testConnectionWithInfo(config: ConnectionConfig): Promise<ConnectionTestResult> {
try {
- const result = await invoke<unknown>("test_connection_with_info", { config });
+ const result = await invoke<unknown>("test_connection_with_info", {
+ config,
+ });
return normalizeConnectionTestResult(result, config);
} catch (error) {
if (!isTauriCommandUnavailable(error, "test_connection_with_info")) throw error;
@@ -784,7 +831,10 @@ export async function connectionDatabaseInfo(connectionId: string, database?: st
}
export async function saveConnectionDatabaseInfo(connectionId: string, databaseInfo: DatabaseConnectionInfo): Promise<void> {
- return invoke("save_connection_database_info", { connectionId, databaseInfo });
+ return invoke("save_connection_database_info", {
+ connectionId,
+ databaseInfo,
+ });
}
export async function connectionFinalProxyPort(config: ConnectionConfig): Promise<number> {
@@ -800,7 +850,10 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
}
export async function connectionIdentifierQuote(connectionId: string, database?: string): Promise<string | undefined> {
- const quote = await invoke<string | null>("connection_identifier_quote", { connectionId, database });
+ const quote = await invoke<string | null>("connection_identifier_quote", {
+ connectionId,
+ database,
+ });
return quote ?? undefined;
}
@@ -829,15 +882,30 @@ export async function listSqlServerLinkedServers(connectionId: string): Promise<
}
export async function listSqlServerLinkedServerCatalogs(connectionId: string, server: string): Promise<DatabaseInfo[]> {
- return invoke("list_sqlserver_linked_server_catalogs", { connectionId, server });
+ return invoke("list_sqlserver_linked_server_catalogs", {
+ connectionId,
+ server,
+ });
}
export async function listSqlServerLinkedServerSchemas(connectionId: string, server: string, catalog: string): Promise<string[]> {
- return invoke("list_sqlserver_linked_server_schemas", { connectionId, server, catalog });
+ return invoke("list_sqlserver_linked_server_schemas", {
+ connectionId,
+ server,
+ catalog,
+ });
}
export async function listSqlServerLinkedServerTables(connectionId: string, server: string, catalog: string, schema: string, filter?: string, limit?: number, offset?: number): Promise<TableInfo[]> {
- return invoke("list_sqlserver_linked_server_tables", { connectionId, server, catalog, schema, filter, limit, offset });
+ return invoke("list_sqlserver_linked_server_tables", {
+ connectionId,
+ server,
+ catalog,
+ schema,
+ filter,
+ limit,
+ offset,
+ });
}
export async function saveSchemaCache(cacheKey: string, payload: unknown): Promise<void> {
@@ -853,15 +921,40 @@ export async function deleteSchemaCachePrefix(prefix: string): Promise<void> {
}
export async function listTables(connectionId: string, database: string, schema: string, filter?: string, limit?: number, offset?: number, objectTypes?: SidebarObjectKind[], catalog?: string, tableNameFilter?: import("@/types/database").TableNameFilter): Promise<TableInfo[]> {
- return invoke("list_tables", { connectionId, database, schema, filter, limit, offset, objectTypes, catalog, tableNameFilter });
+ return invoke("list_tables", {
+ connectionId,
+ database,
+ schema,
+ filter,
+ limit,
+ offset,
+ objectTypes,
+ catalog,
+ tableNameFilter,
+ });
}
export async function getTableComment(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<string | null> {
- return invoke("get_table_comment", { connectionId, database, schema, table, catalog });
+ return invoke("get_table_comment", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listObjects(connectionId: string, database: string, schema: string, objectTypes?: SidebarObjectKind[], filter?: string, limit?: number, offset?: number, catalog?: string): Promise<ObjectInfo[]> {
- return invoke("list_objects", { connectionId, database, schema, objectTypes, filter, limit, offset, catalog });
+ return invoke("list_objects", {
+ connectionId,
+ database,
+ schema,
+ objectTypes,
+ filter,
+ limit,
+ offset,
+ catalog,
+ });
}
export async function listObjectStatistics(connectionId: string, database: string, schema: string): Promise<ObjectStatistics[]> {
@@ -877,7 +970,15 @@ export async function completionAssistantSearch(request: CompletionAssistantRequ
}
export async function getObjectSource(connectionId: string, database: string, schema: string, name: string, objectType: ObjectSourceKind, signature?: string, relationName?: string): Promise<ObjectSource> {
- return invoke("get_object_source", { connectionId, database, schema, name, objectType, signature, relationName });
+ return invoke("get_object_source", {
+ connectionId,
+ database,
+ schema,
+ name,
+ objectType,
+ signature,
+ relationName,
+ });
}
export async function listSchemas(connectionId: string, database: string, applyVisibleFilter = false): Promise<string[]> {
@@ -889,11 +990,23 @@ export async function listSchemaInfos(connectionId: string, database: string): P
}
export async function getColumns(connectionId: string, database: string, schema: string, table: string, catalog?: string, clientSessionId?: string): Promise<ColumnInfo[]> {
- return invoke("get_columns", { connectionId, database, schema, table, catalog, clientSessionId });
+ return invoke("get_columns", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ clientSessionId,
+ });
}
export async function getSqlServerColumnMetadata(connectionId: string, database: string, schema: string, table: string): Promise<SqlServerColumnMetadata[]> {
- return invoke("get_sqlserver_column_metadata", { connectionId, database, schema, table });
+ return invoke("get_sqlserver_column_metadata", {
+ connectionId,
+ database,
+ schema,
+ table,
+ });
}
export async function listDataTypes(connectionId: string, database: string): Promise<string[]> {
@@ -916,7 +1029,14 @@ export async function executeQuery(
executionMode?: "simple";
},
): Promise<QueryResult> {
- return invoke("execute_query", { connectionId, database, sql, schema, executionId, ...options });
+ return invoke("execute_query", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ executionId,
+ ...options,
+ });
}
export async function executeMulti(
@@ -937,7 +1057,14 @@ export async function executeMulti(
executionMode?: "simple";
},
): Promise<QueryResult[]> {
- return invoke("execute_multi", { connectionId, database, sql, schema, executionId, ...options });
+ return invoke("execute_multi", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ executionId,
+ ...options,
+ });
}
export interface ExecuteMultiProgress {
@@ -970,7 +1097,14 @@ export async function executeMultiWithProgress(
if (event.payload.executionId === executionId) onProgress(event.payload);
});
try {
- return await invoke("execute_multi", { connectionId, database, sql, schema, executionId, ...options });
+ return await invoke("execute_multi", {
+ connectionId,
+ database,
+ sql,
+ schema,
+ executionId,
+ ...options,
+ });
} finally {
unlisten();
}
@@ -985,15 +1119,30 @@ export async function cancelQuery(executionId: string): Promise<boolean> {
}
export async function closeQuerySession(connectionId: string, database: string, sessionId: string, clientSessionId?: string): Promise<boolean> {
- return invoke("close_query_session", { connectionId, database, sessionId, clientSessionId });
+ return invoke("close_query_session", {
+ connectionId,
+ database,
+ sessionId,
+ clientSessionId,
+ });
}
export async function closeClientConnectionSession(connectionId: string, database: string, clientSessionId: string): Promise<boolean> {
- return invoke("close_client_connection_session", { connectionId, database, clientSessionId });
+ return invoke("close_client_connection_session", {
+ connectionId,
+ database,
+ clientSessionId,
+ });
}
export async function executeBatch(connectionId: string, database: string, statements: string[], schema?: string, timeoutSecs?: number): Promise<QueryResult> {
- return invoke("execute_batch", { connectionId, database, statements, schema, timeoutSecs });
+ return invoke("execute_batch", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ timeoutSecs,
+ });
}
export async function executeScript(connectionId: string, database: string, sql: string, schema?: string): Promise<QueryResult> {
@@ -1001,11 +1150,21 @@ export async function executeScript(connectionId: string, database: string, sql:
}
export async function executeScriptWith2pc(connectionId: string, database: string, statements: string[], schema?: string): Promise<TransactionLog> {
- return invoke("execute_script_with_2pc", { connectionId, database, statements, schema });
+ return invoke("execute_script_with_2pc", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ });
}
export async function executeInTransaction(connectionId: string, database: string, statements: string[], schema?: string): Promise<QueryResult> {
- return invoke("execute_in_transaction", { connectionId, database, statements, schema });
+ return invoke("execute_in_transaction", {
+ connectionId,
+ database,
+ statements,
+ schema,
+ });
}
export async function beginManualTransaction(connectionId: string, database: string, schema?: string): Promise<string> {
@@ -1013,7 +1172,13 @@ export async function beginManualTransaction(connectionId: string, database: str
}
export async function executeInManualTransaction(txnSessionId: string, sql: string, database: string, schema?: string, maxRows?: number): Promise<QueryResult[]> {
- return invoke("execute_in_manual_transaction", { txnSessionId, sql, database, schema, maxRows });
+ return invoke("execute_in_manual_transaction", {
+ txnSessionId,
+ sql,
+ database,
+ schema,
+ maxRows,
+ });
}
export async function commitManualTransaction(txnSessionId: string): Promise<QueryResult> {
@@ -1050,11 +1215,19 @@ export async function buildCreateUserSql(username: string, password: string, tab
export async function getExplainInfo(connectionId: string, database: string | undefined, schema: string | undefined, sql: string, mode: string): Promise<string | undefined> {
// Preserve Agent/driver errors so the explain view can show the actionable cause.
- return invoke<string>("get_explain_info", { connectionId, database, schema, sql, mode });
+ return invoke<string>("get_explain_info", {
+ connectionId,
+ database,
+ schema,
+ sql,
+ mode,
+ });
}
export async function buildDroppedFilePreviewSql(options: DroppedFilePreviewSqlOptions): Promise<string | undefined> {
- const result = await invoke<string | null>("build_dropped_file_preview_sql", { options });
+ const result = await invoke<string | null>("build_dropped_file_preview_sql", {
+ options,
+ });
return result ?? undefined;
}
@@ -1079,11 +1252,15 @@ export async function buildCreateDatabaseSql(options: CreateDatabaseSqlOptions):
}
export async function buildDuckDbAttachDatabaseSql(path: string, name: string): Promise<string> {
- return invoke("build_duckdb_attach_database_sql", { options: { path, name } });
+ return invoke("build_duckdb_attach_database_sql", {
+ options: { path, name },
+ });
}
export async function buildSqliteAttachDatabaseSql(path: string, name: string): Promise<string> {
- return invoke("build_sqlite_attach_database_sql", { options: { path, name } });
+ return invoke("build_sqlite_attach_database_sql", {
+ options: { path, name },
+ });
}
export async function buildDropObjectSql(options: DropObjectSqlOptions): Promise<string> {
@@ -1155,11 +1332,20 @@ export async function buildTableStructureChangeSql(options: BuildTableStructureC
}
export async function previewSqliteTableStructureChange(connectionId: string, database: string, options: BuildTableStructureChangeSqlOptions): Promise<SqliteTableStructureChangePreview> {
- return invoke("preview_sqlite_table_structure_change", { connectionId, database, options });
+ return invoke("preview_sqlite_table_structure_change", {
+ connectionId,
+ database,
+ options,
+ });
}
export async function applySqliteTableStructureChange(connectionId: string, database: string, options: BuildTableStructureChangeSqlOptions, schemaRevision: string): Promise<QueryResult> {
- return invoke("apply_sqlite_table_structure_change", { connectionId, database, options, schemaRevision });
+ return invoke("apply_sqlite_table_structure_change", {
+ connectionId,
+ database,
+ options,
+ schemaRevision,
+ });
}
export async function buildCreateTableSql(options: BuildTableStructureChangeSqlOptions): Promise<TableStructureChangeSql> {
@@ -1254,35 +1440,86 @@ export async function buildDataCompareSyncPlan(options: DataCompareSyncPlanOptio
}
export async function listIndexes(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<IndexInfo[]> {
- return invoke("list_indexes", { connectionId, database, schema, table, catalog });
+ return invoke("list_indexes", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listForeignKeys(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<ForeignKeyInfo[]> {
- return invoke("list_foreign_keys", { connectionId, database, schema, table, catalog });
+ return invoke("list_foreign_keys", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listTriggers(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<TriggerInfo[]> {
- return invoke("list_triggers", { connectionId, database, schema, table, catalog });
+ return invoke("list_triggers", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listConstraints(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<ConstraintInfo[]> {
- return invoke("list_constraints", { connectionId, database, schema, table, catalog });
+ return invoke("list_constraints", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listPartitions(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<PartitionInfo[]> {
- return invoke("list_partitions", { connectionId, database, schema, table, catalog });
+ return invoke("list_partitions", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function listSubpartitions(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<SubpartitionInfo[]> {
- return invoke("list_subpartitions", { connectionId, database, schema, table, catalog });
+ return invoke("list_subpartitions", {
+ connectionId,
+ database,
+ schema,
+ table,
+ catalog,
+ });
}
export async function getTableDdl(connectionId: string, database: string, schema: string, table: string, objectType?: ObjectSourceKind, catalog?: string): Promise<string> {
- return invoke("get_table_ddl", { connectionId, database, schema, table, objectType, catalog });
+ return invoke("get_table_ddl", {
+ connectionId,
+ database,
+ schema,
+ table,
+ objectType,
+ catalog,
+ });
}
export async function getTableDisplayDdl(connectionId: string, database: string, schema: string, table: string, objectType?: ObjectSourceKind, catalog?: string): Promise<string> {
- return invoke("get_table_ddl", { connectionId, database, schema, table, objectType, catalog, includePostgresAccess: true });
+ return invoke("get_table_ddl", {
+ connectionId,
+ database,
+ schema,
+ table,
+ objectType,
+ catalog,
+ includePostgresAccess: true,
+ });
}
export async function prepareSchemaDiff(options: SchemaDiffPreparationOptions): Promise<SchemaDiffPreparation> {
@@ -1311,7 +1548,12 @@ export async function listFunctions(connectionId: string, database: string, sche
}
export async function listSequences(connectionId: string, database: string, schema: string, withLastValues: boolean): Promise<SequenceInfo[]> {
- return invoke("list_sequences", { connectionId, database, schema, withLastValues });
+ return invoke("list_sequences", {
+ connectionId,
+ database,
+ schema,
+ withLastValues,
+ });
}
export async function listRules(connectionId: string, database: string, schema: string): Promise<RuleInfo[]> {
@@ -1391,7 +1633,9 @@ export async function importJdbcDrivers(paths: (string | File)[]): Promise<JdbcD
}
export async function installJdbcDriverFromMaven(coordinate: string, repositories: string[] = []): Promise<JdbcDriverInfo[]> {
- return invoke("install_jdbc_driver_from_maven", { request: { coordinate, repositories } });
+ return invoke("install_jdbc_driver_from_maven", {
+ request: { coordinate, repositories },
+ });
}
export async function installPrestoSqlJdbcDriver(): Promise<JdbcDriverInfo[]> {
@@ -1734,10 +1978,25 @@ export interface RedisStreamPendingPage {
export type RedisValueData =
| { kind: "string"; content: RedisBlob }
| { kind: "json"; value: string }
- | { kind: "list"; items: RedisListItem[]; total: number; scan_cursor?: number }
+ | {
+ kind: "list";
+ items: RedisListItem[];
+ total: number;
+ scan_cursor?: number;
+ }
| { kind: "set"; items: RedisSetItem[]; total: number; scan_cursor?: number }
- | { kind: "hash"; items: RedisHashItem[]; total: number; scan_cursor?: number }
- | { kind: "zset"; items: RedisZsetItem[]; total: number; scan_cursor?: number }
+ | {
+ kind: "hash";
+ items: RedisHashItem[];
+ total: number;
+ scan_cursor?: number;
+ }
+ | {
+ kind: "zset";
+ items: RedisZsetItem[];
+ total: number;
+ scan_cursor?: number;
+ }
| { kind: "stream"; entries: RedisStreamEntry[] }
| { kind: "unknown" };
@@ -1784,15 +2043,37 @@ export async function redisListDatabases(connectionId: string): Promise<RedisDat
}
export async function redisScanKeys(connectionId: string, db: number, cursor: number, pattern: string, count: number): Promise<RedisScanResult> {
- return invoke("redis_scan_keys", { connectionId, db, cursor, pattern, count });
+ return invoke("redis_scan_keys", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ count,
+ });
}
export async function redisScanKeysBatch(connectionId: string, db: number, cursor: number, pattern: string, count: number, maxIterations: number, includeTypes = true): Promise<RedisScanResult> {
- return invoke("redis_scan_keys_batch", { connectionId, db, cursor, pattern, count, maxIterations, includeTypes });
+ return invoke("redis_scan_keys_batch", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ count,
+ maxIterations,
+ includeTypes,
+ });
}
export async function redisScanValues(connectionId: string, db: number, cursor: number, pattern: string, query: string, count: number, includeKeyMatches = false): Promise<RedisScanResult> {
- return invoke("redis_scan_values", { connectionId, db, cursor, pattern, query, includeKeyMatches, count });
+ return invoke("redis_scan_values", {
+ connectionId,
+ db,
+ cursor,
+ pattern,
+ query,
+ includeKeyMatches,
+ count,
+ });
}
export async function redisGetValue(connectionId: string, db: number, keyRaw: string): Promise<RedisValue> {
@@ -1804,11 +2085,23 @@ export async function redisGetStreamGroups(connectionId: string, db: number, key
}
export async function redisGetStreamConsumers(connectionId: string, db: number, keyRaw: string, groupRaw: string): Promise<RedisStreamConsumer[]> {
- return invoke("redis_get_stream_consumers", { connectionId, db, keyRaw, groupRaw });
+ return invoke("redis_get_stream_consumers", {
+ connectionId,
+ db,
+ keyRaw,
+ groupRaw,
+ });
}
export async function redisGetStreamPending(connectionId: string, db: number, keyRaw: string, groupRaw: string, cursor?: string, consumerRaw?: string): Promise<RedisStreamPendingPage> {
- return invoke("redis_get_stream_pending", { connectionId, db, keyRaw, groupRaw, cursor, ...(consumerRaw === undefined ? {} : { consumerRaw }) });
+ return invoke("redis_get_stream_pending", {
+ connectionId,
+ db,
+ keyRaw,
+ groupRaw,
+ cursor,
+ ...(consumerRaw === undefined ? {} : { consumerRaw }),
+ });
}
export async function redisSetString(connectionId: string, db: number, keyRaw: string, value: string, ttl?: number): Promise<void> {
@@ -1820,7 +2113,14 @@ export async function redisDeleteKey(connectionId: string, db: number, keyRaw: s
}
export async function redisHashSet(connectionId: string, db: number, keyRaw: string, field: string, value: string, ttl?: number): Promise<void> {
- return invoke("redis_hash_set", { connectionId, db, keyRaw, field, value, ttl });
+ return invoke("redis_hash_set", {
+ connectionId,
+ db,
+ keyRaw,
+ field,
+ value,
+ ttl,
+ });
}
export async function redisHashDel(connectionId: string, db: number, keyRaw: string, field: string): Promise<void> {
@@ -1856,7 +2156,14 @@ export async function redisZrem(connectionId: string, db: number, keyRaw: string
}
export async function redisStreamAdd(connectionId: string, db: number, keyRaw: string, entryId: string, fields: [string, string][], ttl?: number): Promise<void> {
- return invoke("redis_stream_add", { connectionId, db, keyRaw, entryId, fields, ttl });
+ return invoke("redis_stream_add", {
+ connectionId,
+ db,
+ keyRaw,
+ entryId,
+ fields,
+ ttl,
+ });
}
export async function redisJsonSet(connectionId: string, db: number, keyRaw: string, value: string, ttl?: number): Promise<void> {
@@ -1884,11 +2191,24 @@ export async function redisFlushDb(connectionId: string, db: number): Promise<vo
}
export async function redisExecuteCommand(connectionId: string, db: number, command: string, skipSafetyCheck?: boolean): Promise<RedisCommandResult> {
- return invoke("redis_execute_command", { connectionId, db, command, skipSafetyCheck: skipSafetyCheck ?? false });
+ return invoke("redis_execute_command", {
+ connectionId,
+ db,
+ command,
+ skipSafetyCheck: skipSafetyCheck ?? false,
+ });
}
export async function redisLoadMore(connectionId: string, db: number, keyRaw: string, keyType: string, cursor: number, count: number, filter?: string): Promise<RedisCollectionPage> {
- return invoke("redis_load_more", { connectionId, db, keyRaw, keyType, cursor, count, filter });
+ return invoke("redis_load_more", {
+ connectionId,
+ db,
+ keyRaw,
+ keyType,
+ cursor,
+ count,
+ filter,
+ });
}
export async function redisPubSubPublish(connectionId: string, db: number, channel: string, message: string): Promise<{ subscribers: number }> {
@@ -1901,7 +2221,12 @@ export async function redisPubSubConnect(connectionId: string): Promise<WebSocke
}
export async function redisSlowlogGet(connectionId: string, count: number, nodeHost?: string, nodePort?: number): Promise<RedisSlowlogEntry[]> {
- return invoke("redis_slowlog_get", { connectionId, count, nodeHost, nodePort });
+ return invoke("redis_slowlog_get", {
+ connectionId,
+ count,
+ nodeHost,
+ nodePort,
+ });
}
export async function redisClusterMasterNodes(connectionId: string): Promise<RedisNodeEndpoint[]> {
@@ -2134,7 +2459,14 @@ export interface KvStatusResponse {
}
export async function etcdListPrefix(connectionId: string, prefix: string, limit: number, continuation?: string | null, options?: KvListPrefixOptions | null): Promise<KvListPrefixResponse> {
- return invoke("etcd_list_prefix", { connectionId, prefix, limit, continuation, revision: options?.revision ?? null, includeValues: options?.includeValues ?? null });
+ return invoke("etcd_list_prefix", {
+ connectionId,
+ prefix,
+ limit,
+ continuation,
+ revision: options?.revision ?? null,
+ includeValues: options?.includeValues ?? null,
+ });
}
export async function etcdSupportsTtl(connectionId: string): Promise<boolean> {
@@ -2142,7 +2474,13 @@ export async function etcdSupportsTtl(connectionId: string): Promise<boolean> {
}
export async function etcdGet(connectionId: string, key: string, options?: KvGetOptions | null): Promise<KvGetResponse> {
- return invoke("etcd_get", { connectionId, key, keyBytes: options?.keyBytes ?? null, revision: options?.revision ?? null, metadataOnly: options?.metadataOnly ?? null });
+ return invoke("etcd_get", {
+ connectionId,
+ key,
+ keyBytes: options?.keyBytes ?? null,
+ revision: options?.revision ?? null,
+ metadataOnly: options?.metadataOnly ?? null,
+ });
}
export async function etcdPut(connectionId: string, key: string, value: KvValue, options?: KvPutOptions | number | null): Promise<KvPutResponse> {
@@ -2162,13 +2500,35 @@ export async function etcdPut(connectionId: string, key: string, value: KvValue,
}
export async function etcdDelete(connectionId: string, key: string, options?: KvDeleteOptions | null): Promise<KvDeleteResponse> {
- return invoke("etcd_delete", { connectionId, key, keyBytes: options?.keyBytes ?? null, expectedModRevision: options?.expectedModRevision ?? null });
+ return invoke("etcd_delete", {
+ connectionId,
+ key,
+ keyBytes: options?.keyBytes ?? null,
+ expectedModRevision: options?.expectedModRevision ?? null,
+ });
}
-export async function etcdRename(connectionId: string, request: { key: string; keyBytes?: KvValue | null; newKey: string; expectedModRevision?: KvInt64 | null }): Promise<{ renamed: boolean; revision?: KvInt64 | null }> {
+export async function etcdRename(
+ connectionId: string,
+ request: {
+ key: string;
+ keyBytes?: KvValue | null;
+ newKey: string;
+ expectedModRevision?: KvInt64 | null;
+ },
+): Promise<{ renamed: boolean; revision?: KvInt64 | null }> {
return invoke("etcd_rename", { connectionId, request });
}
-export async function etcdHistory(connectionId: string, request: { key: string; keyBytes?: KvValue | null; startRevision?: KvInt64 | null; endRevision?: KvInt64 | null; limit: number }): Promise<KvHistoryResponse> {
+export async function etcdHistory(
+ connectionId: string,
+ request: {
+ key: string;
+ keyBytes?: KvValue | null;
+ startRevision?: KvInt64 | null;
+ endRevision?: KvInt64 | null;
+ limit: number;
+ },
+): Promise<KvHistoryResponse> {
return invoke("etcd_history", { connectionId, request });
}
export async function etcdStatus(connectionId: string): Promise<KvStatusResponse> {
@@ -2177,7 +2537,13 @@ export async function etcdStatus(connectionId: string): Promise<KvStatusResponse
// --- ZooKeeper ---
export async function zookeeperListPrefix(connectionId: string, prefix: string, limit: number, continuation?: string | null, options?: KvListPrefixOptions | null): Promise<KvListPrefixResponse> {
- return invoke("zookeeper_list_prefix", { connectionId, prefix, limit, continuation, recursive: options?.recursive ?? null });
+ return invoke("zookeeper_list_prefix", {
+ connectionId,
+ prefix,
+ limit,
+ continuation,
+ recursive: options?.recursive ?? null,
+ });
}
export async function zookeeperGet(connectionId: string, key: string): Promise<KvGetResponse> {
@@ -2185,7 +2551,12 @@ export async function zookeeperGet(connectionId: string, key: string): Promise<K
}
export async function zookeeperPut(connectionId: string, key: string, value: KvValue, options?: KvPutOptions | null): Promise<KvPutResponse> {
- return invoke("zookeeper_put", { connectionId, key, value, options: options ?? null });
+ return invoke("zookeeper_put", {
+ connectionId,
+ key,
+ value,
+ options: options ?? null,
+ });
}
export async function zookeeperDelete(connectionId: string, key: string): Promise<KvDeleteResponse> {
@@ -2198,11 +2569,23 @@ export async function hbaseGetTableSchema(connectionId: string, namespace: strin
}
export async function hbaseScanRows(connectionId: string, namespace: string, table: string, rowKeyPrefix: string | undefined, limit: number): Promise<import("@/types/hbase").HBaseScanResult> {
- return invoke("hbase_scan_rows", { connectionId, namespace, table, rowKeyPrefix, limit });
+ return invoke("hbase_scan_rows", {
+ connectionId,
+ namespace,
+ table,
+ rowKeyPrefix,
+ limit,
+ });
}
export async function hbaseGetRow(connectionId: string, namespace: string, table: string, rowKey: string, rowKeyEncoding?: import("@/types/hbase").HBaseValueEncoding): Promise<import("@/types/hbase").HBaseRow | null> {
- return invoke("hbase_get_row", { connectionId, namespace, table, rowKey, rowKeyEncoding });
+ return invoke("hbase_get_row", {
+ connectionId,
+ namespace,
+ table,
+ rowKey,
+ rowKeyEncoding,
+ });
}
export async function hbasePutRow(connectionId: string, namespace: string, table: string, input: import("@/types/hbase").HBasePutRowInput): Promise<void> {
@@ -2210,11 +2593,22 @@ export async function hbasePutRow(connectionId: string, namespace: string, table
}
export async function hbaseDeleteRow(connectionId: string, namespace: string, table: string, rowKey: string, rowKeyEncoding?: import("@/types/hbase").HBaseValueEncoding): Promise<void> {
- return invoke("hbase_delete_row", { connectionId, namespace, table, rowKey, rowKeyEncoding });
+ return invoke("hbase_delete_row", {
+ connectionId,
+ namespace,
+ table,
+ rowKey,
+ rowKeyEncoding,
+ });
}
export async function hbaseCreateTable(connectionId: string, namespace: string, table: string, columnFamilies: string[]): Promise<void> {
- return invoke("hbase_create_table", { connectionId, namespace, table, columnFamilies });
+ return invoke("hbase_create_table", {
+ connectionId,
+ namespace,
+ table,
+ columnFamilies,
+ });
}
export async function hbaseDeleteTable(connectionId: string, namespace: string, table: string): Promise<void> {
@@ -2277,7 +2671,11 @@ export async function mongoListCollections(connectionId: string, database: strin
}
export async function vectorGetCollectionDetail(connectionId: string, database: string, collection: string): Promise<CollectionInfo> {
- return invoke("vector_collection_detail", { connectionId, database, collection });
+ return invoke("vector_collection_detail", {
+ connectionId,
+ database,
+ collection,
+ });
}
export async function mongoCreateDatabase(connectionId: string, database: string): Promise<void> {
@@ -2289,11 +2687,20 @@ export async function mongoDropDatabase(connectionId: string, database: string):
}
export async function mongoDropCollection(connectionId: string, database: string, collection: string): Promise<void> {
- return invoke("mongo_drop_collection", { connectionId, database, collection });
+ return invoke("mongo_drop_collection", {
+ connectionId,
+ database,
+ collection,
+ });
}
export async function mongoRenameCollection(connectionId: string, database: string, collection: string, newName: string): Promise<void> {
- return invoke("mongo_rename_collection", { connectionId, database, collection, newName });
+ return invoke("mongo_rename_collection", {
+ connectionId,
+ database,
+ collection,
+ newName,
+ });
}
export async function elasticsearchListIndices(connectionId: string): Promise<string[]> {
@@ -2310,7 +2717,15 @@ export async function mongoFindDocuments(connectionId: string, database: string,
}
export async function mongoFindOne(connectionId: string, database: string, collection: string, filter?: string, projection?: string, options?: string, executionId?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_find_one", { connectionId, database, collection, filter, projection, options, executionId });
+ return invoke("mongo_find_one", {
+ connectionId,
+ database,
+ collection,
+ filter,
+ projection,
+ options,
+ executionId,
+ });
}
export async function mongoParseShellCommand(source: string): Promise<MongoCommand> {
@@ -2319,35 +2734,81 @@ export async function mongoParseShellCommand(source: string): Promise<MongoComma
}
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, executionId?: string): Promise<DocumentQueryResult> {
- return invoke("document_find_documents", { connectionId, database, collection, skip, limit, filter, projection, sort, executionId });
+ return invoke("document_find_documents", {
+ connectionId,
+ database,
+ collection,
+ skip,
+ limit,
+ filter,
+ projection,
+ sort,
+ executionId,
+ });
}
export async function elasticsearchCountDocuments(connectionId: string, index: string, filter?: string, executionId?: string): Promise<number> {
- return invoke("elasticsearch_count_documents", { connectionId, index, filter, executionId });
+ return invoke("elasticsearch_count_documents", {
+ connectionId,
+ index,
+ filter,
+ executionId,
+ });
}
export async function mongoCountDocuments(connectionId: string, database: string, collection: string, filter?: string, mode?: "accurate" | "legacy", executionId?: string): Promise<number> {
- return invoke("mongo_count_documents", { connectionId, database, collection, filter, mode, executionId });
+ return invoke("mongo_count_documents", {
+ connectionId,
+ database,
+ collection,
+ filter,
+ mode,
+ executionId,
+ });
}
export async function documentListGridFsFiles(connectionId: string, database: string, bucket: string, filter?: string, sort?: string): Promise<MongoGridFsFileInfo[]> {
- return invoke("document_list_gridfs_files", { connectionId, database, bucket, filter, sort });
+ return invoke("document_list_gridfs_files", {
+ connectionId,
+ database,
+ bucket,
+ filter,
+ sort,
+ });
}
export async function documentListGridFsBuckets(connectionId: string, database: string, filter?: string, sort?: string): Promise<MongoGridFsBucketInfo[]> {
- return invoke("document_list_gridfs_buckets", { connectionId, database, filter, sort });
+ return invoke("document_list_gridfs_buckets", {
+ connectionId,
+ database,
+ filter,
+ sort,
+ });
}
export async function documentCreateGridFsBucket(connectionId: string, database: string, bucket: string): Promise<void> {
- return invoke("document_create_gridfs_bucket", { connectionId, database, bucket });
+ return invoke("document_create_gridfs_bucket", {
+ connectionId,
+ database,
+ bucket,
+ });
}
export async function documentDeleteGridFsBucket(connectionId: string, database: string, bucket: string): Promise<void> {
- return invoke("document_delete_gridfs_bucket", { connectionId, database, bucket });
+ return invoke("document_delete_gridfs_bucket", {
+ connectionId,
+ database,
+ bucket,
+ });
}
export async function documentDownloadGridFsFile(connectionId: string, database: string, bucket: string, fileId: string): Promise<Uint8Array> {
- const data = await invoke<number[]>("document_download_gridfs_file", { connectionId, database, bucket, fileId });
+ const data = await invoke<number[]>("document_download_gridfs_file", {
+ connectionId,
+ database,
+ bucket,
+ fileId,
+ });
return new Uint8Array(data);
}
@@ -2363,31 +2824,73 @@ export async function documentUploadGridFsFile(connectionId: string, database: s
}
export async function documentDeleteGridFsFile(connectionId: string, database: string, bucket: string, fileId: string): Promise<void> {
- return invoke("document_delete_gridfs_file", { connectionId, database, bucket, fileId });
+ return invoke("document_delete_gridfs_file", {
+ connectionId,
+ database,
+ bucket,
+ fileId,
+ });
}
export async function mongoServerVersion(connectionId: string, database: string, executionId?: string): Promise<string> {
- return invoke("mongo_server_version", { connectionId, database, executionId });
+ return invoke("mongo_server_version", {
+ connectionId,
+ database,
+ executionId,
+ });
}
export async function mongoAggregateDocuments(connectionId: string, database: string, collection: string, pipelineJson: string, maxRows?: number, optionsJson?: string, executionId?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_aggregate_documents", { connectionId, database, collection, pipelineJson, maxRows, optionsJson, executionId });
+ return invoke("mongo_aggregate_documents", {
+ connectionId,
+ database,
+ collection,
+ pipelineJson,
+ maxRows,
+ optionsJson,
+ executionId,
+ });
}
export async function mongoDistinct(connectionId: string, database: string, collection: string, field: string, filter?: string, executionId?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_distinct", { connectionId, database, collection, field, filter, executionId });
+ return invoke("mongo_distinct", {
+ connectionId,
+ database,
+ collection,
+ field,
+ filter,
+ executionId,
+ });
}
export async function mongoCollectionStats(connectionId: string, database: string, collection: string, scale?: number, executionId?: string): Promise<MongoCollectionStatsResult> {
- return invoke("mongo_collection_stats", { connectionId, database, collection, scale, executionId });
+ return invoke("mongo_collection_stats", {
+ connectionId,
+ database,
+ collection,
+ scale,
+ executionId,
+ });
}
export async function mongoCreateIndex(connectionId: string, database: string, collection: string, keysJson: string, optionsJson?: string): Promise<{ name: string }> {
- return invoke("mongo_create_index", { connectionId, database, collection, keysJson, optionsJson });
+ return invoke("mongo_create_index", {
+ connectionId,
+ database,
+ collection,
+ keysJson,
+ optionsJson,
+ });
}
export async function mongoDropIndexes(connectionId: string, database: string, collection: string, indexesJson?: string, single = false): Promise<{ dropped_names: string[]; affected_rows: number }> {
- return invoke("mongo_drop_indexes", { connectionId, database, collection, indexesJson, single });
+ return invoke("mongo_drop_indexes", {
+ connectionId,
+ database,
+ collection,
+ indexesJson,
+ single,
+ });
}
export async function mongoInsertDocument(connectionId: string, database: string, collection: string, docJson: string, routing?: string): Promise<string> {
@@ -2395,11 +2898,22 @@ export async function mongoInsertDocument(connectionId: string, database: string
}
export async function documentInsertDocument(connectionId: string, database: string, collection: string, docJson: string, routing?: string): Promise<string> {
- return invoke("document_insert_document", { connectionId, database, collection, docJson, routing });
+ return invoke("document_insert_document", {
+ connectionId,
+ database,
+ collection,
+ docJson,
+ routing,
+ });
}
export async function mongoInsertDocuments(connectionId: string, database: string, collection: string, docsJson: string): Promise<{ affected_rows: number }> {
- const affectedRows = await invoke<number>("mongo_insert_documents", { connectionId, database, collection, docsJson });
+ const affectedRows = await invoke<number>("mongo_insert_documents", {
+ connectionId,
+ database,
+ collection,
+ docsJson,
+ });
return { affected_rows: affectedRows };
}
@@ -2408,7 +2922,14 @@ export async function mongoUpdateDocument(connectionId: string, database: string
}
export async function documentUpdateDocument(connectionId: string, database: string, collection: string, id: string, docJson: string, routing?: string): Promise<number> {
- return invoke("document_update_document", { connectionId, database, collection, id, docJson, routing });
+ return invoke("document_update_document", {
+ connectionId,
+ database,
+ collection,
+ id,
+ docJson,
+ routing,
+ });
}
export async function mongoUpdateDocuments(connectionId: string, database: string, collection: string, filterJson: string, updateJson: string, many: boolean, optionsJson?: string): Promise<{ affected_rows: number }> {
@@ -2429,7 +2950,13 @@ export async function mongoDeleteDocument(connectionId: string, database: string
}
export async function documentDeleteDocument(connectionId: string, database: string, collection: string, id: string, routing?: string): Promise<number> {
- return invoke("document_delete_document", { connectionId, database, collection, id, routing });
+ return invoke("document_delete_document", {
+ connectionId,
+ database,
+ collection,
+ id,
+ routing,
+ });
}
export async function mongoDeleteDocuments(connectionId: string, database: string, collection: string, filterJson: string, many: boolean): Promise<{ affected_rows: number }> {
@@ -2444,15 +2971,35 @@ export async function mongoDeleteDocuments(connectionId: string, database: strin
}
export async function mongoFindOneAndUpdate(connectionId: string, database: string, collection: string, filterJson: string, updateJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_find_one_and_update", { connectionId, database, collection, filterJson, updateJson, optionsJson });
+ return invoke("mongo_find_one_and_update", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ updateJson,
+ optionsJson,
+ });
}
export async function mongoFindOneAndReplace(connectionId: string, database: string, collection: string, filterJson: string, replacementJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_find_one_and_replace", { connectionId, database, collection, filterJson, replacementJson, optionsJson });
+ return invoke("mongo_find_one_and_replace", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ replacementJson,
+ optionsJson,
+ });
}
export async function mongoFindOneAndDelete(connectionId: string, database: string, collection: string, filterJson: string, optionsJson?: string): Promise<MongoDocumentResult> {
- return invoke("mongo_find_one_and_delete", { connectionId, database, collection, filterJson, optionsJson });
+ return invoke("mongo_find_one_and_delete", {
+ connectionId,
+ database,
+ collection,
+ filterJson,
+ optionsJson,
+ });
}
// --- History ---
@@ -2515,7 +3062,11 @@ export async function saveHistory(entry: HistoryEntry): Promise<void> {
}
export async function loadHistory(limit: number, offset: number, activityKind?: string): Promise<HistoryEntry[]> {
- return invoke("load_history", { limit, offset, activityKind: activityKind ?? null });
+ return invoke("load_history", {
+ limit,
+ offset,
+ activityKind: activityKind ?? null,
+ });
}
export async function searchHistory(request: HistorySearchRequest): Promise<HistorySearchResult> {
@@ -2800,7 +3351,9 @@ export async function importTableFile(request: TableImportRequest, onProgress: (
}
});
try {
- const summary = await invoke<TableImportSummary>("import_table_file", { request });
+ const summary = await invoke<TableImportSummary>("import_table_file", {
+ request,
+ });
unlisten();
return summary;
} catch (e) {
@@ -3011,7 +3564,10 @@ export async function startQueryResultExport(request: QueryResultExportRequest,
}
export async function cancelQueryResultExport(exportId: string, executionId?: string): Promise<void> {
- return invoke("cancel_query_result_export", { exportId, executionId: executionId || null });
+ return invoke("cancel_query_result_export", {
+ exportId,
+ executionId: executionId || null,
+ });
}
export async function beginDatabaseBackupSnapshot(connectionId: string, database: string): Promise<DatabaseBackupSnapshot> {
@@ -3066,7 +3622,16 @@ export async function exportQueryResultXlsx(filePath: string, sheetName: string
});
}
-export async function exportQueryResultsXlsx(filePath: string, worksheets: readonly { sheetName?: string; columns: readonly string[]; columnTypes?: readonly string[]; rows: readonly (readonly XlsxCellValue[])[]; numericColumnRightAlign?: boolean }[]): Promise<void> {
+export async function exportQueryResultsXlsx(
+ filePath: string,
+ worksheets: readonly {
+ sheetName?: string;
+ columns: readonly string[];
+ columnTypes?: readonly string[];
+ rows: readonly (readonly XlsxCellValue[])[];
+ numericColumnRightAlign?: boolean;
+ }[],
+): Promise<void> {
return invoke("export_query_results_xlsx", {
request: {
filePath,
diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.ts
index 062158a202..d27902b200 100644
--- a/apps/desktop/src/stores/settingsStore.ts
+++ b/apps/desktop/src/stores/settingsStore.ts
@@ -393,7 +393,14 @@ export interface CustomTheme {
ddlColors: CustomThemeDdlColors;
}
-export const DEFAULT_CUSTOM_THEMES: CustomTheme[] = [{ id: "default", name: "Custom", colors: { ...DEFAULT_CUSTOM_THEME_COLORS }, ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS } }];
+export const DEFAULT_CUSTOM_THEMES: CustomTheme[] = [
+ {
+ id: "default",
+ name: "Custom",
+ colors: { ...DEFAULT_CUSTOM_THEME_COLORS },
+ ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS },
+ },
+];
export type SidebarObjectInfoMode = "comment-inline" | "comment-aligned" | "comment-right" | "size" | "hidden";
@@ -538,7 +545,11 @@ export function enforceRightSidebarPanelExclusivity(current: RightSidebarPanelSt
return transitionRightSidebarPanels(current, panelToKeep, true, true);
}
-export const EDITOR_THEMES: { value: EditorTheme; label: string; dark: boolean }[] = [
+export const EDITOR_THEMES: {
+ value: EditorTheme;
+ label: string;
+ dark: boolean;
+}[] = [
{ value: "app", label: "Follow app theme", dark: false },
{ value: "one-dark", label: "One Dark", dark: true },
{ value: "vscode-dark", label: "VS Dark+", dark: true },
@@ -790,7 +801,13 @@ function normalizeSqlSnippets(value: unknown, existing?: SqlSnippet[]): SqlSnipp
if (seenPrefixes.has(item.prefix)) continue;
seenPrefixes.add(item.prefix);
// Older settings do not have this field; only an explicit false disables a snippet.
- valid.push({ id: item.id, label: item.label, prefix: item.prefix, body: item.body, enabled: item.enabled !== false });
+ valid.push({
+ id: item.id,
+ label: item.label,
+ prefix: item.prefix,
+ body: item.body,
+ enabled: item.enabled !== false,
+ });
}
if (valid.length === 0) return existing ?? DEFAULT_SQL_SNIPPETS;
return valid;
@@ -845,7 +862,10 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
return {
...renamed,
colors: { ...DEFAULT_CUSTOM_THEME_COLORS, ...renamed.colors },
- ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS, ...(renamed as any).ddlColors },
+ ddlColors: {
+ ...DEFAULT_CUSTOM_THEME_DDL_COLORS,
+ ...(renamed as any).ddlColors,
+ },
};
});
}
@@ -854,7 +874,10 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
{
id: "migrated",
name: "Migrated",
- colors: { ...DEFAULT_CUSTOM_THEME_COLORS, ...settings.customThemeColors },
+ colors: {
+ ...DEFAULT_CUSTOM_THEME_COLORS,
+ ...settings.customThemeColors,
+ },
ddlColors: { ...DEFAULT_CUSTOM_THEME_DDL_COLORS },
},
]
@@ -915,17 +938,43 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
sidebarObjectDisplay: settings.sidebarObjectDisplay === "simple" || settings.sidebarObjectDisplay === "grouped" ? settings.sidebarObjectDisplay : DEFAULT_EDITOR_SETTINGS.sidebarObjectDisplay,
sidebarTableSearchEnabled: typeof settings.sidebarTableSearchEnabled === "boolean" ? settings.sidebarTableSearchEnabled : DEFAULT_EDITOR_SETTINGS.sidebarTableSearchEnabled,
autoSelectActiveSidebarNode: settings.autoSelectActiveSidebarNode ?? DEFAULT_EDITOR_SETTINGS.autoSelectActiveSidebarNode,
- openTabsRestoreMode: normalizeOpenTabsRestoreMode((settings as Partial<EditorSettings>).openTabsRestoreMode, (settings as Partial<EditorSettings> & { restoreOpenTabsOnLaunch?: boolean }).restoreOpenTabsOnLaunch),
- disconnectTabHandlingMode: normalizeDisconnectTabHandlingMode((settings as Partial<EditorSettings>).disconnectTabHandlingMode, (settings as Partial<EditorSettings> & { closeQueryTabsOnDisconnect?: boolean }).closeQueryTabsOnDisconnect),
+ openTabsRestoreMode: normalizeOpenTabsRestoreMode(
+ (settings as Partial<EditorSettings>).openTabsRestoreMode,
+ (
+ settings as Partial<EditorSettings> & {
+ restoreOpenTabsOnLaunch?: boolean;
+ }
+ ).restoreOpenTabsOnLaunch,
+ ),
+ disconnectTabHandlingMode: normalizeDisconnectTabHandlingMode(
+ (settings as Partial<EditorSettings>).disconnectTabHandlingMode,
+ (
+ settings as Partial<EditorSettings> & {
+ closeQueryTabsOnDisconnect?: boolean;
+ }
+ ).closeQueryTabsOnDisconnect,
+ ),
reuseDataTab: settings.reuseDataTab ?? DEFAULT_EDITOR_SETTINGS.reuseDataTab,
prefillNewQueryWithSelect: typeof settings.prefillNewQueryWithSelect === "boolean" ? settings.prefillNewQueryWithSelect : DEFAULT_EDITOR_SETTINGS.prefillNewQueryWithSelect,
updateNotificationsEnabled: settings.updateNotificationsEnabled ?? DEFAULT_EDITOR_SETTINGS.updateNotificationsEnabled,
sidebarHiddenTablePrefixes: normalizeSidebarHiddenTablePrefixes(settings.sidebarHiddenTablePrefixes),
sidebarObjectInfoMode: normalizeSidebarObjectInfoMode(
settings.sidebarObjectInfoMode,
- (settings as Partial<EditorSettings> & { sidebarTableCommentLayout?: string }).sidebarTableCommentLayout,
- (settings as Partial<EditorSettings> & { sidebarHideTableComments?: boolean }).sidebarHideTableComments,
- (settings as Partial<EditorSettings> & { sidebarShowDatabaseSizes?: boolean }).sidebarShowDatabaseSizes,
+ (
+ settings as Partial<EditorSettings> & {
+ sidebarTableCommentLayout?: string;
+ }
+ ).sidebarTableCommentLayout,
+ (
+ settings as Partial<EditorSettings> & {
+ sidebarHideTableComments?: boolean;
+ }
+ ).sidebarHideTableComments,
+ (
+ settings as Partial<EditorSettings> & {
+ sidebarShowDatabaseSizes?: boolean;
+ }
+ ).sidebarShowDatabaseSizes,
),
sidebarAllowHorizontalScroll: settings.sidebarAllowHorizontalScroll ?? DEFAULT_EDITOR_SETTINGS.sidebarAllowHorizontalScroll,
columnFormatters: normalizeColumnFormatters(settings.columnFormatters),
@@ -996,7 +1045,9 @@ export const useSettingsStore = defineStore("settings", () => {
const isAiConfigLoaded = ref(false);
const aiConfigs = ref<AiConfigItem[]>([]);
const desktopSettings = ref<DesktopSettings>({ ...DEFAULT_DESKTOP_SETTINGS });
- const mcpGlobalPolicy = ref<McpGlobalPolicy>({ ...DEFAULT_MCP_GLOBAL_POLICY });
+ const mcpGlobalPolicy = ref<McpGlobalPolicy>({
+ ...DEFAULT_MCP_GLOBAL_POLICY,
+ });
const isDesktopSettingsLoaded = ref(false);
const isMcpGlobalPolicyLoaded = ref(false);
const isEditorSettingsLoaded = ref(false);
@@ -1119,7 +1170,10 @@ export const useSettingsStore = defineStore("settings", () => {
const savedActive = savedSelection?.active;
const savedConfig = savedActive ? aiConfigs.value.find((config) => config.id === savedActive.configId) : undefined;
if (savedConfig && savedActive?.modelId.trim()) {
- activeModel.value = { configId: savedConfig.id, modelId: savedActive.modelId.trim() };
+ activeModel.value = {
+ configId: savedConfig.id,
+ modelId: savedActive.modelId.trim(),
+ };
} else {
const fallback = aiConfigs.value.find((config) => config.isDefault) || aiConfigs.value[0];
activeModel.value = fallback?.model.trim() ? { configId: fallback.id, modelId: fallback.model.trim() } : null;
@@ -1175,7 +1229,10 @@ export const useSettingsStore = defineStore("settings", () => {
await api.saveAiConfigItem(normalized);
aiConfigs.value.push(normalized);
if (aiConfigs.value.length === 1 && normalized.model.trim()) {
- activeModel.value = { configId: normalized.id, modelId: normalized.model };
+ activeModel.value = {
+ configId: normalized.id,
+ modelId: normalized.model,
+ };
persistAiChatSelection();
}
}
@@ -1214,7 +1271,10 @@ export const useSettingsStore = defineStore("settings", () => {
}
function updateActiveModel(model: { configId: string; modelId: string }) {
- activeModel.value = { configId: model.configId, modelId: model.modelId.trim() };
+ activeModel.value = {
+ configId: model.configId,
+ modelId: model.modelId.trim(),
+ };
persistAiChatSelection();
}
@@ -1412,7 +1472,9 @@ export const useSettingsStore = defineStore("settings", () => {
}
function deleteCustomColumnFormatter(id: string) {
- const customColumnFormatters = { ...editorSettings.value.customColumnFormatters };
+ const customColumnFormatters = {
+ ...editorSettings.value.customColumnFormatters,
+ };
delete customColumnFormatters[id];
const columnFormatters = Object.fromEntries(
Object.entries(editorSettings.value.columnFormatters).filter(([, formatter]) => {
diff --git a/crates/dbx-core/Cargo.toml b/crates/dbx-core/Cargo.toml
index cbd616e6a5..ad95113e43 100644
--- a/crates/dbx-core/Cargo.toml
+++ b/crates/dbx-core/Cargo.toml
@@ -57,6 +57,7 @@ tracing-subscriber = "0.3"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["compat"] }
chrono = { version = "0.4", features = ["serde"] }
+httpdate = "1"
rust_decimal = { version = "1", features = ["serde", "db-postgres"] }
anyhow = "1"
uuid = { version = "1", features = ["v4", "serde"] }
diff --git a/crates/dbx-core/src/ai.rs b/crates/dbx-core/src/ai.rs
index 6e21d23d10..4d5fa4697d 100644
--- a/crates/dbx-core/src/ai.rs
+++ b/crates/dbx-core/src/ai.rs
@@ -10,6 +10,17 @@ use std::sync::{Arc, LazyLock};
use tokio::sync::{Notify, RwLock};
use uuid::Uuid;
+/// Default number of automatic retries on transient API errors
+/// (rate limits, timeouts, network blips). Users can adjust the limit in
+/// Settings → AI. Set to 0 to disable automatic retries entirely.
+pub const DEFAULT_MAX_RETRIES: u32 = 2;
+pub const MAX_MAX_RETRIES: u32 = 10;
+
+/// Clamp a user-provided max-retries value into the supported range.
+pub fn clamp_max_retries(value: u32) -> u32 {
+ value.clamp(0, MAX_MAX_RETRIES)
+}
+
// ---------------------------------------------------------------------------
// Stream cancel registry
// ---------------------------------------------------------------------------
@@ -340,6 +351,11 @@ pub struct AiConfig {
pub runtime_effort: Option<AiEffortSelection>,
#[serde(default)]
pub context_window: Option<u32>,
+ /// Maximum number of automatic retries on transient API errors
+ /// (rate limits, timeouts, network blips). `None` uses the default (2).
+ /// Set to `Some(0)` to disable automatic retries entirely.
+ #[serde(default)]
+ pub max_retries: Option<u32>,
#[serde(default)]
pub codex_cli_path: Option<String>,
#[serde(default)]
@@ -358,6 +374,30 @@ fn default_enable_thinking() -> bool {
true
}
+/// Whether the provider is a CLI-based provider that goes through its own
+/// executable (claude-code, codex, pi) rather than through `with_retry` /
+/// `with_stream_retry`.
+pub fn is_cli_provider(provider: &AiProvider) -> bool {
+ matches!(provider, AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli)
+}
+
+/// Merge the global `max_retries` setting into an `AiConfig`.
+///
+/// Applied by all API-backed entry points at request time. CLI providers are
+/// skipped because they use their own retry logic and never reach the
+/// `with_retry` / `with_stream_retry` paths.
+///
+/// Some API-backed entry points (model listing, effort resolution) do not
+/// currently call `with_retry` and so the merged value is a no-op for them.
+/// The merge is still applied uniformly so that every API-backed command
+/// follows the same entry-point pattern — if retry logic is added to those
+/// functions later, the global setting takes effect automatically.
+pub fn merge_global_max_retries(config: &mut AiConfig, max_retries: u32) {
+ if !is_cli_provider(&config.provider) {
+ config.max_retries = Some(max_retries);
+ }
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AiMessage {
@@ -1778,6 +1818,7 @@ fn truncate_diagnostic(value: &str, max_chars: usize) -> String {
async fn categorized_http_error(response: reqwest::Response, provider: &str, api_key: &str) -> String {
let status = response.status();
+ let headers = response.headers().clone();
let body = response.text().await.unwrap_or_default();
let detail = serde_json::from_str::<serde_json::Value>(&body)
.ok()
@@ -1793,7 +1834,7 @@ async fn categorized_http_error(response: reqwest::Response, provider: &str, api
let detail = if api_key.is_empty() { detail } else { detail.replace(api_key, "***") };
let detail = truncate_diagnostic(&detail, 500);
let diagnostic = format!("HTTP {}: {detail}", status.as_u16());
- format!("[{}] {provider} API error ({diagnostic})", classify_error(&diagnostic))
+ maybe_tag_retry_after(&headers, format!("[{}] {provider} API error ({diagnostic})", classify_error(&diagnostic)))
}
fn format_transport_error(provider: &str, error: reqwest::Error) -> String {
@@ -1801,6 +1842,32 @@ fn format_transport_error(provider: &str, error: reqwest::Error) -> String {
format!("{provider} request failed: {}", error.without_url())
}
+/// Extract an error string from a non-2xx streaming response, preserving any
+/// `Retry-After` header so the retry helpers can honour server-requested delays.
+///
+/// Mirrors [`categorized_http_error`]: always embeds `HTTP <status>` in the
+/// diagnostic so that [`classify_error`] works correctly on empty-body or
+/// non-JSON responses (e.g. a bare 429 from a proxy).
+async fn stream_error(response: reqwest::Response, fallback: &str) -> String {
+ let status = response.status();
+ let headers = response.headers().clone();
+ // Read the body as text first so we still have it when JSON parsing fails.
+ let body_text = response.text().await.unwrap_or_default();
+ let detail = serde_json::from_str::<serde_json::Value>(&body_text)
+ .ok()
+ .and_then(|data| extract_error(&data))
+ .unwrap_or_else(|| {
+ let trimmed = body_text.trim();
+ if trimmed.is_empty() {
+ "empty response body".to_string()
+ } else {
+ trimmed.to_string()
+ }
+ });
+ let diagnostic = format!("HTTP {}: {detail}", status.as_u16());
+ maybe_tag_retry_after(&headers, format!("[{}] {fallback} API error ({diagnostic})", classify_error(&diagnostic)))
+}
+
async fn measure_first_stream_chunk(
mut byte_stream: impl futures::Stream<Item = Result<bytes::Bytes, reqwest::Error>> + Unpin,
start: std::time::Instant,
@@ -1872,124 +1939,141 @@ pub async fn test_connection_core(config: &AiConfig) -> Result<AiTestConnectionR
validate_config(config)?;
let client = build_ai_http_client(config, 15)?;
- let start = std::time::Instant::now();
-
+ let model = config.model.clone();
+ let provider = config.provider.clone();
let is_claude = uses_anthropic_messages_api(config);
let is_gemini = matches!(config.provider, AiProvider::Gemini);
- let model = config.model.clone();
-
- // Build the streaming request and get the byte stream
- let byte_stream = match config.provider {
- AiProvider::Claude => {
- let body = json!({
- "model": claude_http_model(&model),
- "max_tokens": 16,
- "system": CLAUDE_DEFAULT_SYSTEM,
- "messages": [{ "role": "user", "content": TEST_PROMPT }],
- "stream": true,
- });
- let res = client
- .post(resolve_endpoint(config))
- .headers(claude_headers(config)?)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("Claude request failed: {e}"))?;
- if !res.status().is_success() {
- return Err(categorized_http_error(res, "Claude", &config.api_key).await);
- }
- res.bytes_stream()
- }
- AiProvider::Gemini => {
- // Gemini only returns SSE from streamGenerateContent; generateContent
- // returns one JSON document even when alt=sse is supplied.
- let ep = resolve_gemini_stream_endpoint(config);
- let res = client
- .post(&ep)
- .header(CONTENT_TYPE, "application/json")
- .query(&[("key", normalized_api_key(config)), ("alt", "sse")])
- .json(&json!({
- "contents": [{ "parts": [{ "text": TEST_PROMPT }], "role": "user" }],
- "generationConfig": { "maxOutputTokens": 256 },
- }))
- .send()
- .await
- .map_err(|e| format_transport_error("Gemini", e))?;
- if !res.status().is_success() {
- return Err(categorized_http_error(res, "Gemini", &config.api_key).await);
- }
- res.bytes_stream()
- }
- AiProvider::Custom if uses_anthropic_messages_api(config) => {
- let body = json!({
- "model": claude_http_model(&model),
- "max_tokens": 16,
- "system": CLAUDE_DEFAULT_SYSTEM,
- "messages": [{ "role": "user", "content": TEST_PROMPT }],
- "stream": true,
- });
- let res = client
- .post(resolve_endpoint(config))
- .headers(claude_headers(config)?)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("Claude request failed: {e}"))?;
- if !res.status().is_success() {
- return Err(categorized_http_error(res, "Claude", &config.api_key).await);
- }
- res.bytes_stream()
- }
- _ => {
- // OpenAI-compatible providers
- let mut body_obj = if config.api_style == AiApiStyle::Responses {
- json!({
- "model": &model,
- "input": [{ "role": "user", "content": TEST_PROMPT }],
- "max_output_tokens": 16,
- "stream": true,
- })
- } else {
- let messages = vec![json!({ "role": "user", "content": TEST_PROMPT })];
- let mut body = json!({
- "model": &model,
- "messages": messages,
- "stream": true,
- });
- set_chat_completion_token_limit(&mut body, config, 16);
- body
+ let api_key = normalized_api_key(config).to_string();
+ let endpoint = resolve_endpoint(config);
+ let gemini_ep = resolve_gemini_stream_endpoint(config);
+ let api_style = config.api_style.clone();
+ let config_ref = config.clone();
+ let config_inner = config.clone();
+
+ with_retry(&config_ref, || {
+ let client = client.clone();
+ let model = model.clone();
+ let provider = provider.clone();
+ let api_key = api_key.clone();
+ let endpoint = endpoint.clone();
+ let gemini_ep = gemini_ep.clone();
+ let api_style = api_style.clone();
+ let config_inner = config_inner.clone();
+ async move {
+ let start = std::time::Instant::now();
+
+ let byte_stream = match provider {
+ AiProvider::Claude => {
+ let body = json!({
+ "model": claude_http_model(&model),
+ "max_tokens": 16,
+ "system": CLAUDE_DEFAULT_SYSTEM,
+ "messages": [{ "role": "user", "content": TEST_PROMPT }],
+ "stream": true,
+ });
+ let headers = claude_headers(&config_inner)?;
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("Claude request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(categorized_http_error(res, "Claude", &api_key).await);
+ }
+ res.bytes_stream()
+ }
+ AiProvider::Gemini => {
+ let res = client
+ .post(&gemini_ep)
+ .header(CONTENT_TYPE, "application/json")
+ .query(&[("key", api_key.as_str()), ("alt", "sse")])
+ .json(&json!({
+ "contents": [{ "parts": [{ "text": TEST_PROMPT }], "role": "user" }],
+ "generationConfig": { "maxOutputTokens": 256 },
+ }))
+ .send()
+ .await
+ .map_err(|e| format_transport_error("Gemini", e))?;
+ if !res.status().is_success() {
+ return Err(categorized_http_error(res, "Gemini", &api_key).await);
+ }
+ res.bytes_stream()
+ }
+ AiProvider::Custom if is_claude => {
+ let body = json!({
+ "model": claude_http_model(&model),
+ "max_tokens": 16,
+ "system": CLAUDE_DEFAULT_SYSTEM,
+ "messages": [{ "role": "user", "content": TEST_PROMPT }],
+ "stream": true,
+ });
+ let headers = claude_headers(&config_inner)?;
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("Claude request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(categorized_http_error(res, "Claude", &api_key).await);
+ }
+ res.bytes_stream()
+ }
+ _ => {
+ let mut body_obj = if api_style == AiApiStyle::Responses {
+ json!({
+ "model": &model,
+ "input": [{ "role": "user", "content": TEST_PROMPT }],
+ "max_output_tokens": 16,
+ "stream": true,
+ })
+ } else {
+ let messages = vec![json!({ "role": "user", "content": TEST_PROMPT })];
+ let mut body = json!({
+ "model": &model,
+ "messages": messages,
+ "stream": true,
+ });
+ set_chat_completion_token_limit(&mut body, &config_inner, 16);
+ body
+ };
+ if api_style != AiApiStyle::Responses {
+ apply_chat_completion_thinking_toggle(&mut body_obj, &config_inner);
+ }
+ let headers = maybe_bearer_headers(&config_inner)?;
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body_obj)
+ .send()
+ .await
+ .map_err(|e| format!("AI request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(categorized_http_error(res, "AI", &api_key).await);
+ }
+ res.bytes_stream()
+ }
};
- if config.api_style != AiApiStyle::Responses {
- apply_chat_completion_thinking_toggle(&mut body_obj, config);
- }
- let ep = resolve_endpoint(config);
- let res = client
- .post(&ep)
- .headers(maybe_bearer_headers(config)?)
- .json(&body_obj)
- .send()
- .await
- .map_err(|e| format!("AI request failed: {e}"))?;
- if !res.status().is_success() {
- return Err(categorized_http_error(res, "AI", &config.api_key).await);
- }
- res.bytes_stream()
- }
- };
- match measure_first_stream_chunk(byte_stream, start, is_claude, is_gemini).await {
- Ok((latency, _delta)) => Ok(AiTestConnectionResult {
- success: true,
- message: format!("OK — {}ms", latency),
- latency_ms: Some(latency),
- model_used: model,
- error_category: None,
- }),
- Err(e) => {
- let category = classify_error(&e);
- Err(format!("[{category}] {e}"))
+ match measure_first_stream_chunk(byte_stream, start, is_claude, is_gemini).await {
+ Ok((latency, _delta)) => Ok(AiTestConnectionResult {
+ success: true,
+ message: format!("OK — {}ms", latency),
+ latency_ms: Some(latency),
+ model_used: model,
+ error_category: None,
+ }),
+ Err(e) => {
+ let category = classify_error(&e);
+ Err(format!("[{category}] {e}"))
+ }
+ }
}
- }
+ })
+ .await
}
fn classify_error(msg: &str) -> &'static str {
@@ -2044,40 +2128,200 @@ fn classify_error(msg: &str) -> &'static str {
}
}
-pub async fn complete(request: &AiCompletionRequest) -> Result<String, String> {
- validate_config(&request.config)?;
+/// Whether an error is transient and worth retrying.
+/// Rate limits, timeouts, network blips, and empty responses are retryable;
+/// authentication failures, missing models, safety blocks, and token limits are not.
+fn is_retryable_error(error: &str) -> bool {
+ matches!(classify_error(error), "rateLimit" | "timeout" | "network" | "emptyResponse")
+}
- if matches!(request.config.provider, AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli) {
- return Err("CLI providers are only supported in DBX AI agent mode".to_string());
+/// Extract Retry-After seconds from HTTP response headers.
+///
+/// Supports both integer seconds and HTTP-date (RFC 9110 §10.2.3) formats.
+/// Returns `None` for missing or unparseable values, and 0 for dates in the past.
+fn parse_retry_after_secs(value: &str, now: std::time::SystemTime) -> Option<u64> {
+ if let Ok(secs) = value.parse::<u64>() {
+ return Some(secs);
}
- let client = build_ai_http_client(&request.config, 60)?;
+ let retry_at = httpdate::parse_http_date(value).ok()?;
+ match retry_at.duration_since(now) {
+ Ok(delay) => Some(delay.as_secs().saturating_add(u64::from(delay.subsec_nanos() > 0))),
+ Err(_) => Some(0),
+ }
+}
- match request.config.provider {
- AiProvider::Claude => call_claude(&client, request.clone()).await,
- AiProvider::Gemini => call_gemini(&client, request.clone()).await,
- AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli => unreachable!(),
- AiProvider::Openai
- | AiProvider::Deepseek
- | AiProvider::Qwen
- | AiProvider::Ollama
- | AiProvider::OpenaiCompatible => {
- if request.config.api_style == AiApiStyle::Responses {
- call_responses_api(&client, request.clone()).await
- } else {
- call_openai_compatible(&client, request.clone()).await
+fn retry_after_secs(headers: &reqwest::header::HeaderMap) -> Option<u64> {
+ let value = headers.get(reqwest::header::RETRY_AFTER)?.to_str().ok()?;
+ parse_retry_after_secs(value, std::time::SystemTime::now())
+}
+
+/// Parse a Retry-After duration from an error string.
+///
+/// Recognises the `[retry-after:N]` prefix (N in whole seconds) optionally
+/// embedded by [`categorized_http_error`] or stream error sites.
+fn parse_retry_after(error: &str) -> Option<std::time::Duration> {
+ let rest = error.strip_prefix("[retry-after:")?;
+ let end = rest.find(']')?;
+ let secs: u64 = rest[..end].parse().ok()?;
+ Some(std::time::Duration::from_secs(secs))
+}
+
+/// Prepend a `[retry-after:N]` tag to an error string if the headers include
+/// a Retry-After value.
+fn maybe_tag_retry_after(headers: &reqwest::header::HeaderMap, mut error: String) -> String {
+ if let Some(secs) = retry_after_secs(headers) {
+ error = format!("[retry-after:{secs}]{error}");
+ }
+ error
+}
+
+/// Execute an async operation with automatic retry on transient errors.
+///
+/// Uses the `max_retries` field from `config` (defaults to
+/// [`DEFAULT_MAX_RETRIES`] when `None`, capped at [`MAX_MAX_RETRIES`]).
+/// Exponential back-off starts at 500 ms and doubles each
+/// attempt, with a small jitter to spread retries across concurrent tasks.
+async fn with_retry<F, Fut, T>(config: &AiConfig, mut op: F) -> Result<T, String>
+where
+ F: FnMut() -> Fut,
+ Fut: std::future::Future<Output = Result<T, String>>,
+{
+ let max = config.max_retries.unwrap_or(DEFAULT_MAX_RETRIES).min(MAX_MAX_RETRIES);
+ let mut last_err: Option<String> = None;
+
+ for attempt in 0..=max {
+ if attempt > 0 {
+ // Exponential back-off: 500ms, 1s, 2s, 4s … with ±25 % jitter.
+ let base_ms = 2u64.pow(attempt.saturating_sub(1)) * 500;
+ // Honour Retry-After from the previous error response.
+ let server_delay_ms =
+ last_err.as_ref().and_then(|e| parse_retry_after(e)).map(|d| d.as_millis() as u64).unwrap_or(0);
+ let base_ms = base_ms.max(server_delay_ms);
+ let jitter = (base_ms as f64 * 0.25) as u64;
+ // We can't use thread_rng here (wasm compat), so rely on the OS
+ // scheduler to naturally jitter concurrent tasks. A tiny fixed
+ // offset per attempt avoids thundering-herd for a single caller.
+ let delay_ms = base_ms + (attempt as u64 * 37) % jitter.max(1);
+ tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
+ log::debug!("[ai][retry] attempt {attempt}/{} ({}ms back-off)", max, delay_ms);
+ }
+
+ match op().await {
+ Ok(result) => return Ok(result),
+ Err(err) if attempt < max && is_retryable_error(&err) => {
+ log::warn!("[ai][retry] transient error, will retry: {err}");
+ last_err = Some(err);
}
+ Err(err) => return Err(err),
}
- AiProvider::Custom => {
- if uses_anthropic_messages_api(&request.config) {
- call_claude(&client, request.clone()).await
- } else if request.config.api_style == AiApiStyle::Responses {
- call_responses_api(&client, request.clone()).await
+ }
+
+ Err(last_err.unwrap_or_else(|| "retry exhausted with no recorded error".to_string()))
+}
+
+/// Variant of [`with_retry`] for streaming operations.
+///
+/// Streaming requests are retried only when the `emitted` flag is still `false`
+/// — that is, no text, reasoning, or tool-call event has reached the frontend.
+/// Once content has been emitted, retrying would cause duplicate output, so the
+/// error is propagated immediately regardless of whether it is transient.
+///
+/// The closure rebuilds the full `send` + stream-consume each attempt.
+/// When `cancelled` is provided, back-off sleep yields to cancellation
+/// so the user's Stop button takes effect quickly.
+async fn with_stream_retry<F, Fut, T>(
+ config: &AiConfig,
+ emitted: &std::sync::Arc<std::sync::atomic::AtomicBool>,
+ cancelled: Option<&Notify>,
+ mut op: F,
+) -> Result<T, String>
+where
+ F: FnMut() -> Fut,
+ Fut: std::future::Future<Output = Result<T, String>>,
+{
+ let max = config.max_retries.unwrap_or(DEFAULT_MAX_RETRIES).min(MAX_MAX_RETRIES);
+ let mut last_err: Option<String> = None;
+
+ for attempt in 0..=max {
+ if attempt > 0 {
+ let base_ms = 2u64.pow(attempt.saturating_sub(1)) * 500;
+ // Honour Retry-After from the previous error response.
+ let server_delay_ms =
+ last_err.as_ref().and_then(|e| parse_retry_after(e)).map(|d| d.as_millis() as u64).unwrap_or(0);
+ let base_ms = base_ms.max(server_delay_ms);
+ let jitter = (base_ms as f64 * 0.25) as u64;
+ let delay_ms = base_ms + (attempt as u64 * 37) % jitter.max(1);
+ let delay = std::time::Duration::from_millis(delay_ms);
+ log::debug!("[ai][stream_retry] attempt {attempt}/{} ({}ms back-off)", max, delay_ms);
+ // Yield to cancellation during back-off so Stop is responsive.
+ if let Some(cancelled) = cancelled {
+ tokio::select! {
+ _ = tokio::time::sleep(delay) => {},
+ _ = cancelled.notified() => return Err(AGENT_CANCELLED_ERROR.to_string()),
+ }
} else {
- call_openai_compatible(&client, request.clone()).await
+ tokio::time::sleep(delay).await;
}
}
+
+ match op().await {
+ Ok(result) => return Ok(result),
+ Err(err)
+ if attempt < max && is_retryable_error(&err) && !emitted.load(std::sync::atomic::Ordering::Relaxed) =>
+ {
+ log::warn!("[ai][stream_retry] transient error before content, will retry: {err}");
+ last_err = Some(err);
+ }
+ Err(err) => return Err(err),
+ }
+ }
+
+ Err(last_err.unwrap_or_else(|| "stream retry exhausted with no recorded error".to_string()))
+}
+
+pub async fn complete(request: &AiCompletionRequest) -> Result<String, String> {
+ validate_config(&request.config)?;
+
+ if matches!(request.config.provider, AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli) {
+ return Err("CLI providers are only supported in DBX AI agent mode".to_string());
}
+
+ let config = request.config.clone();
+ let client = build_ai_http_client(&config, 60)?;
+
+ with_retry(&config, || {
+ let client = client.clone();
+ let request = request.clone();
+ async move {
+ match request.config.provider {
+ AiProvider::Claude => call_claude(&client, request).await,
+ AiProvider::Gemini => call_gemini(&client, request).await,
+ AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli => unreachable!(),
+ AiProvider::Openai
+ | AiProvider::Deepseek
+ | AiProvider::Qwen
+ | AiProvider::Ollama
+ | AiProvider::OpenaiCompatible => {
+ if request.config.api_style == AiApiStyle::Responses {
+ call_responses_api(&client, request).await
+ } else {
+ call_openai_compatible(&client, request).await
+ }
+ }
+ AiProvider::Custom => {
+ if uses_anthropic_messages_api(&request.config) {
+ call_claude(&client, request).await
+ } else if request.config.api_style == AiApiStyle::Responses {
+ call_responses_api(&client, request).await
+ } else {
+ call_openai_compatible(&client, request).await
+ }
+ }
+ }
+ }
+ })
+ .await
}
// ---------------------------------------------------------------------------
@@ -2142,63 +2386,77 @@ async fn stream_claude(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(claude_headers(&request.config)?)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("Claude request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "Claude API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
+ let headers = claude_headers(&request.config)?;
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("Claude request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "Claude API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- if let Some(text) = claude_stream_text(&event) {
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text.to_string(),
- reasoning_delta: None,
- done: false,
- });
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ if let Some(text) = claude_stream_text(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text.to_string(),
+ reasoning_delta: None,
+ done: false,
+ });
+ }
+ }
}
+
+ if finished { break; }
}
+ _ = cancelled.notified() => { break; }
}
-
- if finished { break; }
}
- _ = cancelled.notified() => { break; }
- }
- }
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: None,
- done: true,
- });
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: None,
+ done: true,
+ });
- Ok(())
+ Ok(())
+ }
+ })
+ .await
}
async fn stream_openai(
@@ -2222,82 +2480,96 @@ async fn stream_openai(
apply_chat_completion_thinking_toggle(&mut body_obj, &request.config);
crate::ai_effort::apply_runtime_effort(&mut body_obj, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(headers)
- .json(&body_obj)
- .send()
- .await
- .map_err(|e| format!("AI request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "API error".to_string()));
- }
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
- let mut finish_reason_deadline = None;
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body_obj = body_obj.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body_obj)
+ .send()
+ .await
+ .map_err(|e| format!("AI request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+ let mut finish_reason_deadline = None;
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- if let Some(reasoning) = openai_stream_reasoning(&event) {
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: Some(reasoning.to_string()),
- done: false,
- });
- }
- if let Some(text) = openai_stream_text(&event) {
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text,
- reasoning_delta: None,
- done: false,
- });
- }
- if finish_reason_deadline.is_none() && openai_stream_has_finish_reason(&event) {
- finish_reason_deadline =
- Some(tokio::time::Instant::now() + std::time::Duration::from_secs(1));
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ if let Some(reasoning) = openai_stream_reasoning(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: Some(reasoning.to_string()),
+ done: false,
+ });
+ }
+ if let Some(text) = openai_stream_text(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text,
+ reasoning_delta: None,
+ done: false,
+ });
+ }
+ if finish_reason_deadline.is_none() && openai_stream_has_finish_reason(&event) {
+ finish_reason_deadline =
+ Some(tokio::time::Instant::now() + std::time::Duration::from_secs(1));
+ }
+ }
}
+
+ if finished { break; }
}
+ _ = cancelled.notified() => { break; }
+ _ = async {
+ match finish_reason_deadline {
+ Some(deadline) => tokio::time::sleep_until(deadline).await,
+ None => std::future::pending().await,
+ }
+ } => { break; }
}
-
- if finished { break; }
}
- _ = cancelled.notified() => { break; }
- _ = async {
- match finish_reason_deadline {
- Some(deadline) => tokio::time::sleep_until(deadline).await,
- None => std::future::pending().await,
- }
- } => { break; }
- }
- }
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: None,
- done: true,
- });
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: None,
+ done: true,
+ });
- Ok(())
+ Ok(())
+ }
+ })
+ .await
}
async fn stream_responses_api(
@@ -2317,63 +2589,76 @@ async fn stream_responses_api(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(headers)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("AI request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "API error".to_string()));
- }
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("AI request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- if let Some(text) = responses_stream_text(&event) {
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text.to_string(),
- reasoning_delta: None,
- done: false,
- });
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ if let Some(text) = responses_stream_text(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text.to_string(),
+ reasoning_delta: None,
+ done: false,
+ });
+ }
+ }
}
+
+ if finished { break; }
}
+ _ = cancelled.notified() => { break; }
}
-
- if finished { break; }
}
- _ = cancelled.notified() => { break; }
- }
- }
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: None,
- done: true,
- });
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: None,
+ done: true,
+ });
- Ok(())
+ Ok(())
+ }
+ })
+ .await
}
async fn stream_gemini(
@@ -2403,57 +2688,71 @@ async fn stream_gemini(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_gemini_stream_endpoint(&request.config))
- .query(&[("key", normalized_api_key(&request.config)), ("alt", "sse")])
- .header(CONTENT_TYPE, "application/json")
- .json(&body)
- .send()
- .await
- .map_err(|e| format_transport_error("Gemini", e))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| format_transport_error("Gemini", e))?;
- return Err(extract_error(&data).unwrap_or_else(|| "Gemini API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
+ let endpoint = resolve_gemini_stream_endpoint(&request.config);
+ let api_key = normalized_api_key(&request.config).to_string();
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let endpoint = endpoint.clone();
+ let api_key = api_key.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .query(&[("key", api_key.as_str()), ("alt", "sse")])
+ .header(CONTENT_TYPE, "application/json")
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format_transport_error("Gemini", e))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "Gemini API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.without_url().to_string())?;
- buf.extend_from_slice(&chunk);
-
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- let text = gemini_text(&event);
- if !text.is_empty() {
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text,
- reasoning_delta: None,
- done: false,
- });
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.without_url().to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ let text = gemini_text(&event);
+ if !text.is_empty() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text,
+ reasoning_delta: None,
+ done: false,
+ });
+ }
+ }
}
}
+ _ = cancelled.notified() => { break; }
}
}
- _ = cancelled.notified() => { break; }
- }
- }
- on_chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: None,
- done: true,
- });
+ on_chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: None,
+ done: true,
+ });
- Ok(())
+ Ok(())
+ }
+ })
+ .await
}
// ---------------------------------------------------------------------------
@@ -2624,129 +2923,146 @@ async fn stream_claude_with_tools(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(claude_headers(&request.config)?)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("Claude request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "Claude API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
- // Track the current content block index and type for tool_use blocks
- let mut current_block_index: Option<u32> = None;
- let mut current_block_type: Option<String> = None;
- let mut token_usage: Option<TokenUsage> = None;
+ let headers = claude_headers(&request.config)?;
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("Claude request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "Claude API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+ // Track the current content block index and type for tool_use blocks
+ let mut current_block_index: Option<u32> = None;
+ let mut current_block_type: Option<String> = None;
+ let mut token_usage: Option<TokenUsage> = None;
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- let event_type = event["type"].as_str().unwrap_or("");
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ let event_type = event["type"].as_str().unwrap_or("");
- match event_type {
- // message_start carries input_tokens (prompt cost)
- "message_start" => {
- if let Some(i) = event["message"]["usage"]["input_tokens"].as_u64() {
- let existing_output = token_usage.as_ref().map(|u| u.output_tokens).unwrap_or(0);
- token_usage = Some(TokenUsage { input_tokens: i as u32, output_tokens: existing_output });
- }
- }
- // message_delta carries output_tokens (generation cost)
- "message_delta" => {
- if let Some(o) = event["usage"]["output_tokens"].as_u64() {
- let existing_input = token_usage.as_ref().map(|u| u.input_tokens).unwrap_or(0);
- token_usage = Some(TokenUsage { input_tokens: existing_input, output_tokens: o as u32 });
- }
- }
- "content_block_start" => {
- let idx = event["index"].as_u64().unwrap_or(0) as u32;
- let block_type = event["content_block"]["type"].as_str().unwrap_or("");
- current_block_index = Some(idx);
- current_block_type = Some(block_type.to_string());
-
- if block_type == "tool_use" {
- let id = event["content_block"]["id"].as_str().unwrap_or_default().to_string();
- let name = event["content_block"]["name"].as_str().unwrap_or_default().to_string();
- on_event(StreamToolEvent::ToolCallStart { index: idx, id, name });
- }
- }
- "content_block_delta" => {
- let idx = event["index"].as_u64().unwrap_or(0) as u32;
- let delta_type = event["delta"]["type"].as_str().unwrap_or("");
-
- match delta_type {
- "text_delta" => {
- if let Some(text) = event["delta"]["text"].as_str() {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text.to_string(),
- reasoning_delta: None,
- done: false,
- }));
+ match event_type {
+ // message_start carries input_tokens (prompt cost)
+ "message_start" => {
+ if let Some(i) = event["message"]["usage"]["input_tokens"].as_u64() {
+ let existing_output = token_usage.as_ref().map(|u| u.output_tokens).unwrap_or(0);
+ token_usage = Some(TokenUsage { input_tokens: i as u32, output_tokens: existing_output });
}
}
- "thinking_delta" => {
- if let Some(thinking) = event["delta"]["thinking"].as_str() {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: Some(thinking.to_string()),
- done: false,
- }));
+ // message_delta carries output_tokens (generation cost)
+ "message_delta" => {
+ if let Some(o) = event["usage"]["output_tokens"].as_u64() {
+ let existing_input = token_usage.as_ref().map(|u| u.input_tokens).unwrap_or(0);
+ token_usage = Some(TokenUsage { input_tokens: existing_input, output_tokens: o as u32 });
}
}
- "input_json_delta" => {
- if let Some(fragment) = event["delta"]["partial_json"].as_str() {
- on_event(StreamToolEvent::ToolCallDelta {
- index: idx,
- fragment: fragment.to_string(),
- });
+ "content_block_start" => {
+ let idx = event["index"].as_u64().unwrap_or(0) as u32;
+ let block_type = event["content_block"]["type"].as_str().unwrap_or("");
+ current_block_index = Some(idx);
+ current_block_type = Some(block_type.to_string());
+
+ if block_type == "tool_use" {
+ let id = event["content_block"]["id"].as_str().unwrap_or_default().to_string();
+ let name = event["content_block"]["name"].as_str().unwrap_or_default().to_string();
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::ToolCallStart { index: idx, id, name });
}
}
- _ => {}
- }
- }
- "content_block_stop" => {
- if let Some(idx) = current_block_index.take() {
- if current_block_type.as_deref() == Some("tool_use") {
- on_event(StreamToolEvent::ToolCallComplete { index: idx });
+ "content_block_delta" => {
+ let idx = event["index"].as_u64().unwrap_or(0) as u32;
+ let delta_type = event["delta"]["type"].as_str().unwrap_or("");
+
+ match delta_type {
+ "text_delta" => {
+ if let Some(text) = event["delta"]["text"].as_str() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text.to_string(),
+ reasoning_delta: None,
+ done: false,
+ }));
+ }
+ }
+ "thinking_delta" => {
+ if let Some(thinking) = event["delta"]["thinking"].as_str() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: Some(thinking.to_string()),
+ done: false,
+ }));
+ }
+ }
+ "input_json_delta" => {
+ if let Some(fragment) = event["delta"]["partial_json"].as_str() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::ToolCallDelta {
+ index: idx,
+ fragment: fragment.to_string(),
+ });
+ }
+ }
+ _ => {}
+ }
+ }
+ "content_block_stop" => {
+ if let Some(idx) = current_block_index.take() {
+ if current_block_type.as_deref() == Some("tool_use") {
+ on_event(StreamToolEvent::ToolCallComplete { index: idx });
+ }
+ }
+ current_block_type = None;
}
+ _ => {}
}
- current_block_type = None;
}
- _ => {}
}
+
+ if finished { break; }
+ }
+ _ = cancelled.notified() => {
+ return Err(AGENT_CANCELLED_ERROR.to_string());
}
}
-
- if finished { break; }
- }
- _ = cancelled.notified() => {
- return Err(AGENT_CANCELLED_ERROR.to_string());
}
- }
- }
- Ok(token_usage)
+ Ok(token_usage)
+ }
+ })
+ .await
}
/// Streaming OpenAI-compatible call with tool support.
@@ -2809,107 +3125,123 @@ async fn stream_openai_with_tools(
}
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(headers)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("AI request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
- let mut token_usage: Option<TokenUsage> = None;
- let mut finish_reason_deadline = None;
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("AI request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "API error").await);
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- // Token usage (final chunk from OpenAI with include_usage)
- if let Some(usage) = event.get("usage") {
- if let (Some(p), Some(c)) = (
- usage.get("prompt_tokens").and_then(|v| v.as_u64()),
- usage.get("completion_tokens").and_then(|v| v.as_u64()),
- ) {
- token_usage = Some(TokenUsage { input_tokens: p as u32, output_tokens: c as u32 });
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+ let mut token_usage: Option<TokenUsage> = None;
+ let mut finish_reason_deadline = None;
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
}
- }
- // Reasoning
- if let Some(reasoning) = openai_stream_reasoning(&event) {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: String::new(),
- reasoning_delta: Some(reasoning.to_string()),
- done: false,
- }));
- }
- // Text
- if let Some(text) = openai_stream_text(&event) {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text,
- reasoning_delta: None,
- done: false,
- }));
- }
- // Tool calls
- if let Some(tool_calls) = event["choices"].get(0).and_then(|c| c["delta"]["tool_calls"].as_array()) {
- for tc in tool_calls {
- let idx = tc["index"].as_u64().unwrap_or(0) as u32;
- // The first delta carries the tool call id and
- // function name. Some OpenAI-compatible providers
- // (e.g. GLM) send id="" on subsequent deltas, so
- // only a non-empty id marks a genuine start.
- if let Some(id) = tc["id"].as_str().filter(|s| !s.is_empty()) {
- let name = tc["function"]["name"].as_str().unwrap_or_default().to_string();
- on_event(StreamToolEvent::ToolCallStart { index: idx, id: id.to_string(), name });
+
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ // Token usage (final chunk from OpenAI with include_usage)
+ if let Some(usage) = event.get("usage") {
+ if let (Some(p), Some(c)) = (
+ usage.get("prompt_tokens").and_then(|v| v.as_u64()),
+ usage.get("completion_tokens").and_then(|v| v.as_u64()),
+ ) {
+ token_usage = Some(TokenUsage { input_tokens: p as u32, output_tokens: c as u32 });
+ }
+ }
+ // Reasoning
+ if let Some(reasoning) = openai_stream_reasoning(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: String::new(),
+ reasoning_delta: Some(reasoning.to_string()),
+ done: false,
+ }));
+ }
+ // Text
+ if let Some(text) = openai_stream_text(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text,
+ reasoning_delta: None,
+ done: false,
+ }));
+ }
+ // Tool calls
+ if let Some(tool_calls) = event["choices"].get(0).and_then(|c| c["delta"]["tool_calls"].as_array()) {
+ for tc in tool_calls {
+ let idx = tc["index"].as_u64().unwrap_or(0) as u32;
+ // The first delta carries the tool call id and
+ // function name. Some OpenAI-compatible providers
+ // (e.g. GLM) send id="" on subsequent deltas, so
+ // only a non-empty id marks a genuine start.
+ if let Some(id) = tc["id"].as_str().filter(|s| !s.is_empty()) {
+ let name = tc["function"]["name"].as_str().unwrap_or_default().to_string();
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::ToolCallStart { index: idx, id: id.to_string(), name });
+ }
+ // Argument fragments
+ if let Some(fragment) = tc["function"]["arguments"].as_str() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::ToolCallDelta { index: idx, fragment: fragment.to_string() });
+ }
+ }
}
- // Argument fragments
- if let Some(fragment) = tc["function"]["arguments"].as_str() {
- on_event(StreamToolEvent::ToolCallDelta { index: idx, fragment: fragment.to_string() });
+ if finish_reason_deadline.is_none() && openai_stream_has_finish_reason(&event) {
+ finish_reason_deadline =
+ Some(tokio::time::Instant::now() + std::time::Duration::from_secs(1));
}
}
}
- if finish_reason_deadline.is_none() && openai_stream_has_finish_reason(&event) {
- finish_reason_deadline =
- Some(tokio::time::Instant::now() + std::time::Duration::from_secs(1));
- }
+
+ if finished { break; }
+ }
+ _ = cancelled.notified() => {
+ return Err(AGENT_CANCELLED_ERROR.to_string());
}
+ _ = async {
+ match finish_reason_deadline {
+ Some(deadline) => tokio::time::sleep_until(deadline).await,
+ None => std::future::pending().await,
+ }
+ } => { break; }
}
-
- if finished { break; }
- }
- _ = cancelled.notified() => {
- return Err(AGENT_CANCELLED_ERROR.to_string());
}
- _ = async {
- match finish_reason_deadline {
- Some(deadline) => tokio::time::sleep_until(deadline).await,
- None => std::future::pending().await,
- }
- } => { break; }
- }
- }
- Ok(token_usage)
+ Ok(token_usage)
+ }
+ })
+ .await
}
async fn stream_responses_with_tools(
@@ -2933,112 +3265,128 @@ async fn stream_responses_with_tools(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_endpoint(&request.config))
- .headers(headers)
- .json(&body)
- .send()
- .await
- .map_err(|e| format!("AI request failed: {e}"))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
- return Err(extract_error(&data).unwrap_or_else(|| "API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
- let mut item_indices: HashMap<String, u32> = HashMap::new();
- let mut started_indices: HashSet<u32> = HashSet::new();
- let mut argument_indices: HashSet<u32> = HashSet::new();
- let mut next_index: u32 = 0;
- let mut token_usage: Option<TokenUsage> = None;
+ let endpoint = resolve_endpoint(&request.config);
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.to_string())?;
- buf.extend_from_slice(&chunk);
-
- let mut finished = false;
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if data == "[DONE]" {
- finished = true;
- break;
- }
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let headers = headers.clone();
+ let endpoint = endpoint.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .headers(headers)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("AI request failed: {e}"))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "API error").await);
+ }
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- if let Some(usage) = responses_token_usage(&event) {
- token_usage = Some(usage);
- }
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+ let mut item_indices: HashMap<String, u32> = HashMap::new();
+ let mut started_indices: HashSet<u32> = HashSet::new();
+ let mut argument_indices: HashSet<u32> = HashSet::new();
+ let mut next_index: u32 = 0;
+ let mut token_usage: Option<TokenUsage> = None;
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ let mut finished = false;
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if data == "[DONE]" {
+ finished = true;
+ break;
+ }
- if let Some(text) = responses_stream_text(&event) {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text.to_string(),
- reasoning_delta: None,
- done: false,
- }));
- }
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ if let Some(usage) = responses_token_usage(&event) {
+ token_usage = Some(usage);
+ }
- match event["type"].as_str().unwrap_or_default() {
- "response.output_item.added" => {
- emit_responses_function_call_item(
- &event,
- &mut item_indices,
- &mut started_indices,
- &mut argument_indices,
- &mut next_index,
- on_event,
- );
- }
- "response.output_item.done" => {
- if let Some(index) = emit_responses_function_call_item(
- &event,
- &mut item_indices,
- &mut started_indices,
- &mut argument_indices,
- &mut next_index,
- on_event,
- ) {
- on_event(StreamToolEvent::ToolCallComplete { index });
+ if let Some(text) = responses_stream_text(&event) {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text.to_string(),
+ reasoning_delta: None,
+ done: false,
+ }));
}
- }
- "response.function_call_arguments.delta" => {
- let index = event["item_id"]
- .as_str()
- .and_then(|id| item_indices.get(id).copied())
- .or_else(|| event["output_index"].as_u64().map(|i| i as u32))
- .unwrap_or(0);
- if let Some(fragment) = event["delta"].as_str() {
- argument_indices.insert(index);
- on_event(StreamToolEvent::ToolCallDelta { index, fragment: fragment.to_string() });
+
+ match event["type"].as_str().unwrap_or_default() {
+ "response.output_item.added" => {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ emit_responses_function_call_item(
+ &event,
+ &mut item_indices,
+ &mut started_indices,
+ &mut argument_indices,
+ &mut next_index,
+ on_event,
+ );
+ }
+ "response.output_item.done" => {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ if let Some(index) = emit_responses_function_call_item(
+ &event,
+ &mut item_indices,
+ &mut started_indices,
+ &mut argument_indices,
+ &mut next_index,
+ on_event,
+ ) {
+ on_event(StreamToolEvent::ToolCallComplete { index });
+ }
+ }
+ "response.function_call_arguments.delta" => {
+ let index = event["item_id"]
+ .as_str()
+ .and_then(|id| item_indices.get(id).copied())
+ .or_else(|| event["output_index"].as_u64().map(|i| i as u32))
+ .unwrap_or(0);
+ if let Some(fragment) = event["delta"].as_str() {
+ argument_indices.insert(index);
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::ToolCallDelta { index, fragment: fragment.to_string() });
+ }
+ }
+ "response.function_call_arguments.done" => {
+ let index = event["item_id"]
+ .as_str()
+ .and_then(|id| item_indices.get(id).copied())
+ .or_else(|| event["output_index"].as_u64().map(|i| i as u32))
+ .unwrap_or(0);
+ on_event(StreamToolEvent::ToolCallComplete { index });
+ }
+ _ => {}
}
}
- "response.function_call_arguments.done" => {
- let index = event["item_id"]
- .as_str()
- .and_then(|id| item_indices.get(id).copied())
- .or_else(|| event["output_index"].as_u64().map(|i| i as u32))
- .unwrap_or(0);
- on_event(StreamToolEvent::ToolCallComplete { index });
- }
- _ => {}
}
+
+ if finished { break; }
+ }
+ _ = cancelled.notified() => {
+ return Err(AGENT_CANCELLED_ERROR.to_string());
}
}
-
- if finished { break; }
- }
- _ = cancelled.notified() => {
- return Err(AGENT_CANCELLED_ERROR.to_string());
}
- }
- }
- Ok(token_usage)
+ Ok(token_usage)
+ }
+ })
+ .await
}
fn build_gemini_contents(messages: &[AiMessage]) -> Vec<serde_json::Value> {
@@ -3135,71 +3483,86 @@ async fn stream_gemini_with_tools(
});
crate::ai_effort::apply_runtime_effort(&mut body, &request.config);
- let res = client
- .post(resolve_gemini_stream_endpoint(&request.config))
- .query(&[("key", normalized_api_key(&request.config)), ("alt", "sse")])
- .header(CONTENT_TYPE, "application/json")
- .json(&body)
- .send()
- .await
- .map_err(|e| format_transport_error("Gemini", e))?;
-
- if !res.status().is_success() {
- let data: serde_json::Value = res.json().await.map_err(|e| format_transport_error("Gemini", e))?;
- return Err(extract_error(&data).unwrap_or_else(|| "Gemini API error".to_string()));
- }
-
- let mut byte_stream = res.bytes_stream();
- let mut buf = Vec::new();
- let mut tool_call_idx: u32 = 0;
- let mut token_usage: Option<TokenUsage> = None;
+ let endpoint = resolve_gemini_stream_endpoint(&request.config);
+ let api_key = normalized_api_key(&request.config).to_string();
+ let config = request.config.clone();
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+
+ with_stream_retry(&config, &emitted, Some(cancelled), || {
+ let body = body.clone();
+ let endpoint = endpoint.clone();
+ let api_key = api_key.clone();
+ let session_id = session_id.to_string();
+ let emitted = emitted.clone();
+ async move {
+ let res = client
+ .post(&endpoint)
+ .query(&[("key", api_key.as_str()), ("alt", "sse")])
+ .header(CONTENT_TYPE, "application/json")
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format_transport_error("Gemini", e))?;
+ if !res.status().is_success() {
+ return Err(stream_error(res, "Gemini API error").await);
+ }
- loop {
- tokio::select! {
- chunk = byte_stream.next() => {
- let Some(chunk) = chunk else { break };
- let chunk = chunk.map_err(|e| e.without_url().to_string())?;
- buf.extend_from_slice(&chunk);
-
- while let Some(line) = drain_next_stream_line(&mut buf)? {
- let Some(data) = stream_data_payload(&line) else { continue };
- if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
- // Token usage (overwrite each chunk, keep last value)
- if let (Some(p), Some(c)) = (
- event["usageMetadata"]["promptTokenCount"].as_u64(),
- event["usageMetadata"]["candidatesTokenCount"].as_u64(),
- ) {
- token_usage = Some(TokenUsage { input_tokens: p as u32, output_tokens: c as u32 });
- }
- if let Some(candidates) = event["candidates"].as_array() {
- if let Some(parts) = candidates[0]["content"]["parts"].as_array() {
- for part in parts {
- // Text
- if let Some(text) = part["text"].as_str() {
- on_event(StreamToolEvent::Chunk(AiStreamChunk {
- session_id: session_id.to_string(),
- delta: text.to_string(),
- reasoning_delta: None,
- done: false,
- }));
- }
- // Function call (Gemini sends complete objects, not deltas)
- if emit_gemini_tool_call_part(part, tool_call_idx, on_event) {
- tool_call_idx += 1;
+ let mut byte_stream = res.bytes_stream();
+ let mut buf = Vec::new();
+ let mut tool_call_idx: u32 = 0;
+ let mut token_usage: Option<TokenUsage> = None;
+
+ loop {
+ tokio::select! {
+ chunk = byte_stream.next() => {
+ let Some(chunk) = chunk else { break };
+ let chunk = chunk.map_err(|e| e.without_url().to_string())?;
+ buf.extend_from_slice(&chunk);
+
+ while let Some(line) = drain_next_stream_line(&mut buf)? {
+ let Some(data) = stream_data_payload(&line) else { continue };
+ if let Ok(event) = serde_json::from_str::<serde_json::Value>(data) {
+ // Token usage (overwrite each chunk, keep last value)
+ if let (Some(p), Some(c)) = (
+ event["usageMetadata"]["promptTokenCount"].as_u64(),
+ event["usageMetadata"]["candidatesTokenCount"].as_u64(),
+ ) {
+ token_usage = Some(TokenUsage { input_tokens: p as u32, output_tokens: c as u32 });
+ }
+ if let Some(candidates) = event["candidates"].as_array() {
+ if let Some(parts) = candidates[0]["content"]["parts"].as_array() {
+ for part in parts {
+ // Text
+ if let Some(text) = part["text"].as_str() {
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ on_event(StreamToolEvent::Chunk(AiStreamChunk {
+ session_id: session_id.clone(),
+ delta: text.to_string(),
+ reasoning_delta: None,
+ done: false,
+ }));
+ }
+ // Function call (Gemini sends complete objects, not deltas)
+ emitted.store(true, std::sync::atomic::Ordering::Relaxed);
+ if emit_gemini_tool_call_part(part, tool_call_idx, on_event) {
+ tool_call_idx += 1;
+ }
+ }
}
}
}
}
}
+ _ = cancelled.notified() => {
+ return Err(AGENT_CANCELLED_ERROR.to_string());
+ }
}
}
- _ = cancelled.notified() => {
- return Err(AGENT_CANCELLED_ERROR.to_string());
- }
- }
- }
- Ok(token_usage)
+ Ok(token_usage)
+ }
+ })
+ .await
}
/// Public entry point: stream an LLM call with tool support, accumulating tool calls.
@@ -3326,17 +3689,19 @@ mod tests {
apply_chat_completion_thinking_toggle, build_ai_http_client, build_gemini_contents,
build_responses_input_with_tools, call_claude, classify_error, claude_headers, claude_system_prompt,
drain_next_stream_line, emit_gemini_tool_call_part, emit_responses_function_call_item, format_transport_error,
- gemini_text, is_kimi_model, maybe_bearer_headers, measure_first_stream_chunk,
- ollama_selected_model_tool_support, openai_response_text, openai_stream_reasoning, openai_stream_text,
- parse_dynamic_effort_capability, parse_gemini_model_list_response, parse_model_list_response, resolve_endpoint,
+ gemini_text, is_kimi_model, is_retryable_error, maybe_bearer_headers, maybe_tag_retry_after,
+ measure_first_stream_chunk, merge_global_max_retries, ollama_selected_model_tool_support, openai_response_text,
+ openai_stream_reasoning, openai_stream_text, parse_dynamic_effort_capability, parse_gemini_model_list_response,
+ parse_model_list_response, parse_retry_after, parse_retry_after_secs, resolve_endpoint,
resolve_gemini_stream_endpoint, resolve_model_effort_core, resolve_model_list_endpoint,
resolve_ollama_show_endpoint, responses_function_tool, responses_max_output_tokens, responses_stream_text,
- responses_text, responses_token_usage, retain_ollama_completion_models, set_chat_completion_token_limit,
- stream_claude, stream_claude_with_tools, stream_data_payload, stream_openai_with_tools,
- uses_anthropic_messages_api, validate_config, validate_model_list_config, AiApiStyle, AiAuthMethod,
- AiCapabilitySource, AiCompletionRequest, AiConfig, AiEffortCapability, AiEffortOption, AiEffortSelection,
- AiMessage, AiModelInfo, AiProvider, AiReasoningLevel, StreamToolEvent, StreamingToolCallAccumulator,
- ToolCallRef, AUTHORIZATION, CLAUDE_DEFAULT_SYSTEM, TEST_PROMPT,
+ responses_text, responses_token_usage, retain_ollama_completion_models, retry_after_secs,
+ set_chat_completion_token_limit, stream_claude, stream_claude_with_tools, stream_data_payload, stream_error,
+ stream_openai_with_tools, test_connection_core, uses_anthropic_messages_api, validate_config,
+ validate_model_list_config, with_retry, with_stream_retry, AiApiStyle, AiAuthMethod, AiCapabilitySource,
+ AiCompletionRequest, AiConfig, AiEffortCapability, AiEffortOption, AiEffortSelection, AiMessage, AiModelInfo,
+ AiProvider, AiReasoningLevel, StreamToolEvent, StreamingToolCallAccumulator, ToolCallRef, AUTHORIZATION,
+ CLAUDE_DEFAULT_SYSTEM, TEST_PROMPT,
};
struct CapturedJsonRequest {
@@ -3389,6 +3754,37 @@ mod tests {
(format!("http://{address}/v1/messages"), server)
}
+ async fn spawn_error_server_with_body(
+ status: u16,
+ reason: &'static str,
+ body: &'static str,
+ retry_after_secs: Option<u64>,
+ ) -> (String, tokio::task::JoinHandle<()>) {
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
+
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let address = listener.local_addr().unwrap();
+ let server = tokio::spawn(async move {
+ let (mut socket, _) = listener.accept().await.unwrap();
+ let mut buf = vec![0u8; 4096];
+ let n = socket.read(&mut buf).await.unwrap();
+ assert!(n > 0, "server received no request");
+
+ let mut resp = format!(
+ "HTTP/1.1 {status} {reason}\r\nContent-Type: application/json\r\nContent-Length: {}\r\n",
+ body.len()
+ );
+ if let Some(secs) = retry_after_secs {
+ resp.push_str(&format!("Retry-After: {secs}\r\n"));
+ }
+ resp.push_str("Connection: close\r\n\r\n");
+ resp.push_str(body);
+ socket.write_all(resp.as_bytes()).await.unwrap();
+ });
+
+ (format!("http://{address}/test"), server)
+ }
+
fn claude_http_test_request(endpoint: String) -> AiCompletionRequest {
AiCompletionRequest {
config: AiConfig {
@@ -3405,6 +3801,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: Some(1_000_000),
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3723,6 +4120,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3752,6 +4150,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3779,6 +4178,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3806,6 +4206,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3837,6 +4238,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3865,6 +4267,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3905,6 +4308,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3928,6 +4332,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -3954,6 +4359,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4004,6 +4410,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4066,6 +4473,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4100,6 +4508,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4214,6 +4623,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4245,6 +4655,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4325,6 +4736,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4585,6 +4997,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4717,6 +5130,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4753,6 +5167,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4795,6 +5210,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4831,6 +5247,7 @@ mod tests {
reasoning_level: AiReasoningLevel::High,
runtime_effort: Some(AiEffortSelection::ProviderDefault),
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4894,6 +5311,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -4951,6 +5369,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -5077,4 +5496,468 @@ mod tests {
assert!(value.get("special_values").is_none());
assert_eq!(serde_json::from_value::<AiEffortCapability>(value).unwrap(), capability);
}
+
+ // ------------------------------------------------------------------
+ // with_retry / with_stream_retry unit tests
+ // ------------------------------------------------------------------
+
+ fn retry_config(max_retries: Option<u32>) -> AiConfig {
+ serde_json::from_value(serde_json::json!({
+ "provider": "openai",
+ "model": "gpt-4",
+ "maxRetries": max_retries,
+ }))
+ .unwrap()
+ }
+
+ #[tokio::test]
+ async fn retry_succeeds_on_first_attempt() {
+ let cfg = retry_config(Some(2));
+ let result = with_retry(&cfg, || async { Ok::<&str, String>("ok") }).await;
+ assert_eq!(result, Ok("ok"));
+ }
+
+ #[tokio::test]
+ async fn retry_succeeds_after_transient_error() {
+ let cfg = retry_config(Some(2));
+ let mut calls = 0;
+ let result = with_retry(&cfg, || {
+ calls += 1;
+ async move {
+ if calls == 1 {
+ Err("rate limit exceeded (429)".to_string())
+ } else {
+ Ok::<&str, String>("recovered")
+ }
+ }
+ })
+ .await;
+ assert_eq!(result, Ok("recovered"));
+ assert_eq!(calls, 2);
+ }
+
+ #[tokio::test]
+ async fn retry_exhausts_and_returns_last_error() {
+ let cfg = retry_config(Some(1)); // max 1 → 2 attempts total
+ let result = with_retry(&cfg, || async { Err::<(), _>("gateway timeout (504)".to_string()) }).await;
+ assert!(result.is_err());
+ assert!(result.unwrap_err().contains("504"));
+ }
+
+ #[tokio::test]
+ async fn retry_zero_means_no_retry() {
+ let cfg = retry_config(Some(0));
+ let mut calls = 0;
+ let result = with_retry(&cfg, || {
+ calls += 1;
+ async move { Err::<(), _>("rate limit exceeded (429)".to_string()) }
+ })
+ .await;
+ assert!(result.is_err());
+ assert_eq!(calls, 1, "maxRetries=0 should not retry");
+ }
+
+ #[tokio::test]
+ async fn retry_stops_on_non_retryable_error() {
+ let cfg = retry_config(Some(3));
+ let mut calls = 0;
+ let result = with_retry(&cfg, || {
+ calls += 1;
+ async move { Err::<(), _>("unauthorized (401)".to_string()) }
+ })
+ .await;
+ assert!(result.is_err());
+ assert_eq!(calls, 1, "auth errors are not retryable");
+ }
+
+ #[tokio::test]
+ async fn retry_honours_retry_after_from_error() {
+ // Verify that a [retry-after:N] tag in the error forces the delay
+ // to be at least N seconds. We use a tight timing assertion: the
+ // sleep call inside with_retry must take ≥ 1 second when the error
+ // carries [retry-after:1].
+ let cfg = retry_config(Some(2));
+ let start = std::time::Instant::now();
+ let mut calls = 0;
+ let result = with_retry(&cfg, || {
+ calls += 1;
+ async move {
+ if calls == 1 {
+ Err("[retry-after:1]rate limit exceeded (429)".to_string())
+ } else {
+ Ok::<&str, String>("ok")
+ }
+ }
+ })
+ .await;
+ let elapsed = start.elapsed();
+ assert_eq!(result, Ok("ok"));
+ assert_eq!(calls, 2);
+ assert!(elapsed.as_millis() >= 800, "expected ≥1s Retry-After delay, got {}ms", elapsed.as_millis());
+ }
+
+ #[tokio::test]
+ async fn stream_retry_succeeds_on_first_attempt() {
+ let cfg = retry_config(Some(2));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let result = with_stream_retry(&cfg, &emitted, None, || async { Ok::<&str, String>("ok") }).await;
+ assert_eq!(result, Ok("ok"));
+ }
+
+ #[tokio::test]
+ async fn stream_retry_does_not_retry_after_content_emitted() {
+ let cfg = retry_config(Some(3));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true)); // content already out
+ let mut calls = 0;
+ let result = with_stream_retry(&cfg, &emitted, None, || {
+ calls += 1;
+ async move { Err::<(), _>("rate limit exceeded (429)".to_string()) }
+ })
+ .await;
+ assert!(result.is_err());
+ assert_eq!(calls, 1, "should not retry once content has been emitted");
+ }
+
+ #[tokio::test]
+ async fn stream_retry_retries_before_content_emitted() {
+ let cfg = retry_config(Some(2));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let mut calls = 0;
+ let result = with_stream_retry(&cfg, &emitted, None, || {
+ calls += 1;
+ async move {
+ if calls == 1 {
+ Err("gateway timeout (504)".to_string())
+ } else {
+ Ok::<&str, String>("recovered")
+ }
+ }
+ })
+ .await;
+ assert_eq!(result, Ok("recovered"));
+ assert_eq!(calls, 2);
+ }
+
+ #[tokio::test]
+ async fn stream_retry_cancels_during_backoff() {
+ let cfg = retry_config(Some(2));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let cancel = tokio::sync::Notify::new();
+
+ // Cancel immediately — the retry loop should notice during its first
+ // back-off sleep and return the cancellation error.
+ cancel.notify_one();
+
+ let mut calls = 0;
+ let result = with_stream_retry(&cfg, &emitted, Some(&cancel), || {
+ calls += 1;
+ async move {
+ if calls == 1 {
+ Err("rate limit exceeded (429)".to_string())
+ } else {
+ Ok::<&str, String>("never")
+ }
+ }
+ })
+ .await;
+ assert!(result.is_err());
+ assert!(result.unwrap_err().contains("cancelled"));
+ assert_eq!(calls, 1);
+ }
+
+ // ------------------------------------------------------------------
+ // Retry-After / classify_error helpers
+ // ------------------------------------------------------------------
+
+ #[test]
+ fn test_parse_retry_after_from_error() {
+ assert_eq!(parse_retry_after("[retry-after:5]rate limit exceeded"), Some(std::time::Duration::from_secs(5)));
+ assert_eq!(parse_retry_after("[retry-after:120]gateway timeout"), Some(std::time::Duration::from_secs(120)));
+ assert_eq!(parse_retry_after("rate limit exceeded"), None);
+ assert_eq!(parse_retry_after("[retry-after:abc]error"), None);
+ assert_eq!(parse_retry_after(""), None);
+ }
+
+ #[test]
+ fn test_retry_after_secs_from_headers() {
+ let mut headers = reqwest::header::HeaderMap::new();
+ assert_eq!(retry_after_secs(&headers), None);
+
+ headers.insert(reqwest::header::RETRY_AFTER, reqwest::header::HeaderValue::from_static("42"));
+ assert_eq!(retry_after_secs(&headers), Some(42));
+
+ let now = std::time::UNIX_EPOCH
+ + std::time::Duration::from_secs(1_700_000_000)
+ + std::time::Duration::from_millis(250);
+ let future = std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_700_000_001);
+ assert_eq!(parse_retry_after_secs(&httpdate::fmt_http_date(future), now), Some(1));
+
+ let past = std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_699_999_999);
+ assert_eq!(parse_retry_after_secs(&httpdate::fmt_http_date(past), now), Some(0));
+ assert_eq!(parse_retry_after_secs("not-a-number", now), None);
+ }
+
+ #[test]
+ fn test_maybe_tag_retry_after() {
+ let mut headers = reqwest::header::HeaderMap::new();
+ assert_eq!(maybe_tag_retry_after(&headers, "err".to_string()), "err");
+
+ headers.insert(reqwest::header::RETRY_AFTER, reqwest::header::HeaderValue::from_static("30"));
+ assert_eq!(maybe_tag_retry_after(&headers, "err".to_string()), "[retry-after:30]err");
+ }
+
+ #[test]
+ fn test_is_retryable_error_covers_all_categories() {
+ assert!(is_retryable_error("rate limit exceeded (429)"));
+ assert!(is_retryable_error("gateway timeout (504)"));
+ assert!(is_retryable_error("connection refused"));
+ assert!(is_retryable_error("response body was empty"));
+ assert!(!is_retryable_error("unauthorized (401)"));
+ assert!(!is_retryable_error("model not found (404)"));
+ assert!(!is_retryable_error("safety filter blocked"));
+ assert!(!is_retryable_error("finishReason=MAX_TOKENS"));
+ }
+
+ /// `stream_error` embeds `HTTP <status>` in the diagnostic; verify that
+ /// classification works on the patterns it produces, including the
+ /// empty-body / non-JSON case that was previously classified as `unknown`.
+ #[test]
+ fn test_classify_error_from_stream_error_diagnostic() {
+ // JSON parse succeeded, server error text included.
+ assert_eq!(classify_error("HTTP 429: rate limit exceeded"), "rateLimit");
+ assert_eq!(classify_error("HTTP 504: gateway timeout"), "timeout");
+ assert_eq!(classify_error("HTTP 503: service unavailable"), "network");
+ assert_eq!(classify_error("HTTP 502: bad gateway"), "network");
+ // Empty body — the regression case: a bare 429 with no JSON payload.
+ assert_eq!(classify_error("HTTP 429: empty response body"), "rateLimit");
+ // Non-JSON body that still contains a rate-limit keyword.
+ assert_eq!(classify_error("HTTP 429: <html>Too Many Requests</html>"), "rateLimit");
+ // Auth failures must NOT be retryable.
+ assert_eq!(classify_error("HTTP 401: unauthorized"), "auth");
+ assert_eq!(classify_error("HTTP 403: forbidden"), "auth");
+ assert!(!is_retryable_error("[auth] Claude API error (HTTP 401: unauthorized)"));
+ assert!(!is_retryable_error("[auth] Claude API error (HTTP 403: forbidden)"));
+ }
+
+ // ------------------------------------------------------------------
+ // stream_error integration tests (real reqwest::Response)
+ // ------------------------------------------------------------------
+
+ /// Send a real HTTP request against a local server returning a specific
+ /// error status, then run the response through `stream_error` and verify
+ /// the output format, classification, and Retry-After encoding.
+ async fn call_stream_error(
+ status: u16,
+ reason: &'static str,
+ body: &'static str,
+ retry_after_secs: Option<u64>,
+ ) -> String {
+ let (url, _server) = spawn_error_server_with_body(status, reason, body, retry_after_secs).await;
+ let resp = reqwest::Client::new()
+ .post(&url)
+ .json(&serde_json::json!({"model": "test"}))
+ .send()
+ .await
+ .expect("request to test server failed");
+ stream_error(resp, "TestProvider").await
+ }
+
+ #[tokio::test]
+ async fn stream_error_empty_body_429_is_retryable() {
+ let err = call_stream_error(429, "Too Many Requests", "", None).await;
+ // Expected format: [{classify}] {fallback} API error (HTTP {status}: {detail})
+ assert!(err.contains("[rateLimit]"), "429 with empty body should classify as rateLimit, got: {err}");
+ assert!(err.contains("HTTP 429: empty response body"), "got: {err}");
+ assert!(is_retryable_error(&err), "stream_error 429 must be retryable, got: {err}");
+ }
+
+ #[tokio::test]
+ async fn stream_error_empty_body_429_triggers_retry() {
+ let (url, _server) = spawn_error_server_with_body(429, "Too Many Requests", "", None).await;
+
+ let cfg = retry_config(Some(2));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let mut calls = 0;
+
+ let result = with_stream_retry(&cfg, &emitted, None, || {
+ calls += 1;
+ let url = url.clone();
+ async move {
+ if calls == 1 {
+ let resp = reqwest::Client::new()
+ .post(&url)
+ .json(&serde_json::json!({"model": "test"}))
+ .send()
+ .await
+ .expect("request failed");
+ Err(stream_error(resp, "TestProvider").await)
+ } else {
+ Ok::<(), String>(())
+ }
+ }
+ })
+ .await;
+ assert!(result.is_ok(), "should retry after stream_error 429, got: {result:?}");
+ assert_eq!(calls, 2);
+ }
+
+ #[tokio::test]
+ async fn stream_error_preserves_retry_after_from_headers() {
+ let err = call_stream_error(429, "Too Many Requests", r#"{"error":{"message":"rate limit"}}"#, Some(5)).await;
+ // The Retry-After: 5 header should be encoded as [retry-after:5] prefix.
+ assert!(err.starts_with("[retry-after:5]"), "Retry-After should be prepended, got: {err}");
+ assert!(err.contains("[rateLimit]"), "got: {err}");
+ assert!(err.contains("rate limit"), "should include original error detail, got: {err}");
+ }
+
+ #[tokio::test]
+ async fn stream_error_retry_after_extends_backoff() {
+ // If the response says Retry-After: 1, the first retry must wait ≥ 800ms
+ // (after jitter) rather than the default 500ms.
+ let (url, _server) =
+ spawn_error_server_with_body(429, "Too Many Requests", r#"{"error":{"message":"rate limit"}}"#, Some(1))
+ .await;
+
+ let cfg = retry_config(Some(2));
+ let emitted = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let start = std::time::Instant::now();
+ let mut calls = 0;
+
+ let result = with_stream_retry(&cfg, &emitted, None, || {
+ calls += 1;
+ let url = url.clone();
+ async move {
+ if calls == 1 {
+ let resp = reqwest::Client::new()
+ .post(&url)
+ .json(&serde_json::json!({"model": "test"}))
+ .send()
+ .await
+ .expect("request failed");
+ Err(stream_error(resp, "TestProvider").await)
+ } else {
+ Ok::<(), String>(())
+ }
+ }
+ })
+ .await;
+ let elapsed = start.elapsed();
+ assert!(result.is_ok());
+ assert_eq!(calls, 2);
+ assert!(elapsed.as_millis() >= 800, "Retry-After: 1 should force ≥1s delay, got {}ms", elapsed.as_millis());
+ }
+
+ #[tokio::test]
+ async fn stream_error_non_json_429_body_is_retryable() {
+ // Some proxies return HTML or plain text for 429.
+ let err = call_stream_error(429, "Too Many Requests", "<html>Too Many Requests</html>", None).await;
+ assert!(
+ err.contains("[rateLimit]"),
+ "non-JSON body containing 'rate' keyword should classify as rateLimit, got: {err}"
+ );
+ assert!(err.contains("<html>"), "raw body should be preserved in detail, got: {err}");
+ assert!(is_retryable_error(&err));
+ }
+
+ #[tokio::test]
+ async fn stream_error_401_is_not_retryable() {
+ let err = call_stream_error(401, "Unauthorized", r#"{"error":{"message":"invalid api key"}}"#, None).await;
+ assert!(err.contains("[auth]"), "got: {err}");
+ assert!(err.contains("HTTP 401"), "got: {err}");
+ assert!(!is_retryable_error(&err), "401 must not be retryable");
+ }
+
+ // ------------------------------------------------------------------
+ // merge_global_max_retries unit tests
+ // ------------------------------------------------------------------
+
+ fn test_config(provider: AiProvider) -> AiConfig {
+ serde_json::from_value(serde_json::json!({
+ "provider": serde_json::to_string(&provider).unwrap().trim_matches('"'),
+ "model": "test-model",
+ }))
+ .unwrap()
+ }
+
+ #[test]
+ fn merge_global_max_retries_sets_for_api_providers() {
+ for provider in &[
+ AiProvider::Claude,
+ AiProvider::Openai,
+ AiProvider::OpenaiCompatible,
+ AiProvider::Custom,
+ AiProvider::Gemini,
+ AiProvider::Deepseek,
+ AiProvider::Qwen,
+ AiProvider::Ollama,
+ ] {
+ let mut config = test_config(provider.clone());
+ config.max_retries = None;
+ merge_global_max_retries(&mut config, 3);
+ assert_eq!(config.max_retries, Some(3), "merge should set max_retries for {provider:?}");
+ }
+ }
+
+ #[test]
+ fn merge_global_max_retries_skips_cli_providers() {
+ for provider in [AiProvider::CodexCli, AiProvider::ClaudeCodeCli, AiProvider::PiAgentCli] {
+ let mut config = test_config(provider.clone());
+ config.max_retries = None;
+ merge_global_max_retries(&mut config, 0);
+ assert_eq!(config.max_retries, None, "merge must not touch CLI provider {provider:?}");
+ }
+ }
+
+ // ------------------------------------------------------------------
+ // End-to-end: max_retries=0 prevents retry even against a real server
+ // ------------------------------------------------------------------
+
+ /// Spawn a TCP server that returns 429 for every connection and counts them.
+ /// Returns (url, count, handle). Abort the handle after the test.
+ async fn spawn_counting_429_server(
+ ) -> (String, std::sync::Arc<std::sync::atomic::AtomicU32>, tokio::task::JoinHandle<()>) {
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
+
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let addr = listener.local_addr().unwrap();
+ let url = format!("http://{addr}/v1/messages");
+ let count = std::sync::Arc::new(std::sync::atomic::AtomicU32::new(0));
+ let count2 = count.clone();
+
+ let handle = tokio::spawn(async move {
+ while let Ok((mut socket, _)) = listener.accept().await {
+ count2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ let mut buf = vec![0u8; 4096];
+ let _ = socket.read(&mut buf).await;
+ let resp = b"HTTP/1.1 429 Too Many Requests\r\n\
+ Content-Type: application/json\r\n\
+ Content-Length: 0\r\n\
+ Connection: close\r\n\r\n";
+ let _ = socket.write_all(resp).await;
+ }
+ });
+
+ (url, count, handle)
+ }
+
+ #[tokio::test]
+ async fn test_connection_core_no_retry_when_max_retries_zero() {
+ let (url, count, server) = spawn_counting_429_server().await;
+
+ let mut config: AiConfig = serde_json::from_value(serde_json::json!({
+ "provider": "claude",
+ "apiKey": "sk-test",
+ "model": "claude-sonnet-4",
+ "endpoint": url,
+ }))
+ .unwrap();
+ config.max_retries = Some(0);
+
+ let result = test_connection_core(&config).await;
+ assert!(result.is_err(), "429 should fail, got: {result:?}");
+
+ server.abort();
+ let requests = count.load(std::sync::atomic::Ordering::SeqCst);
+ assert_eq!(requests, 1, "max_retries=0 should mean exactly 1 request, got {requests}");
+ }
}
diff --git a/crates/dbx-core/src/ai_claude_code_cli.rs b/crates/dbx-core/src/ai_claude_code_cli.rs
index 385bc38e84..5234e2e2ef 100644
--- a/crates/dbx-core/src/ai_claude_code_cli.rs
+++ b/crates/dbx-core/src/ai_claude_code_cli.rs
@@ -573,6 +573,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
diff --git a/crates/dbx-core/src/ai_codex_cli.rs b/crates/dbx-core/src/ai_codex_cli.rs
index 526074719b..9f6e2c46e6 100644
--- a/crates/dbx-core/src/ai_codex_cli.rs
+++ b/crates/dbx-core/src/ai_codex_cli.rs
@@ -1029,6 +1029,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
diff --git a/crates/dbx-core/src/ai_effort.rs b/crates/dbx-core/src/ai_effort.rs
index 5bd29f6d27..d317a77f73 100644
--- a/crates/dbx-core/src/ai_effort.rs
+++ b/crates/dbx-core/src/ai_effort.rs
@@ -383,6 +383,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: HashMap::new(),
claude_code_cli_path: None,
diff --git a/crates/dbx-core/src/ai_pi_agent_cli.rs b/crates/dbx-core/src/ai_pi_agent_cli.rs
index 9c9ab0922a..28e4697331 100644
--- a/crates/dbx-core/src/ai_pi_agent_cli.rs
+++ b/crates/dbx-core/src/ai_pi_agent_cli.rs
@@ -748,6 +748,7 @@ mod tests {
reasoning_level: AiReasoningLevel::High,
runtime_effort: Some(AiEffortSelection::Enum("high".to_string())),
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: HashMap::new(),
claude_code_cli_path: None,
diff --git a/crates/dbx-core/src/cloud_sync.rs b/crates/dbx-core/src/cloud_sync.rs
index c144368a26..5976d3760c 100644
--- a/crates/dbx-core/src/cloud_sync.rs
+++ b/crates/dbx-core/src/cloud_sync.rs
@@ -1093,6 +1093,7 @@ mod tests {
reasoning_level: crate::ai::AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
diff --git a/crates/dbx-core/src/storage.rs b/crates/dbx-core/src/storage.rs
index 1a2db3769e..e869423dbe 100644
--- a/crates/dbx-core/src/storage.rs
+++ b/crates/dbx-core/src/storage.rs
@@ -29,6 +29,7 @@ const APP_STATE_EDITOR_SETTINGS_KEY: &str = "editor_settings";
const APP_STATE_OPEN_TABS_KEY: &str = "open_tabs";
const APP_STATE_SAVED_SQL_EDITOR_POSITIONS_KEY: &str = "saved_sql_editor_positions";
const MCP_GLOBAL_POLICY_KEY: &str = "mcp_global_policy";
+const MAX_RETRIES_KEY: &str = "max_retries";
const APP_STATE_AI_GLOBAL_INSTRUCTIONS_KEY: &str = "ai_global_custom_instructions";
const APP_STATE_AI_CHAT_SELECTION_KEY: &str = "ai_chat_selection_v1";
const USER_DATA_TABLES: &[&str] = &[
@@ -1387,18 +1388,23 @@ impl Storage {
) -> Result<(), String> {
let mut settings = settings.clone();
self.with_conn(move |conn| {
- // The dedicated policy writer is the only owner of this key. Keep
- // its latest value across overlapping legacy settings saves.
+ // Dedicated writers are the only owners of these keys. Keep their
+ // latest values across overlapping legacy settings saves.
let current: Option<String> = conn
.query_row("SELECT settings_json FROM app_settings WHERE id = 1", [], |row| row.get(0))
.optional()
.map_err(|e| e.to_string())?;
- settings.remove(MCP_GLOBAL_POLICY_KEY);
+ let dedicated_keys = [MCP_GLOBAL_POLICY_KEY, MAX_RETRIES_KEY];
+ for key in dedicated_keys {
+ settings.remove(key);
+ }
if let Some(current) = current {
let current = serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(&current)
.map_err(|e| format!("invalid app settings JSON: {e}"))?;
- if let Some(policy) = current.get(MCP_GLOBAL_POLICY_KEY) {
- settings.insert(MCP_GLOBAL_POLICY_KEY.to_string(), policy.clone());
+ for key in dedicated_keys {
+ if let Some(value) = current.get(key) {
+ settings.insert(key.to_string(), value.clone());
+ }
}
}
let json = serde_json::Value::Object(settings).to_string();
@@ -1809,6 +1815,37 @@ impl Storage {
.map(|value| crate::agent_loop::clamp_max_agent_turns(value.min(u32::MAX as u64) as u32))
.unwrap_or(crate::agent_loop::DEFAULT_MAX_AGENT_TURNS))
}
+
+ pub async fn save_max_retries(&self, max_retries: u32) -> Result<(), String> {
+ let max_retries = crate::ai::clamp_max_retries(max_retries);
+ self.with_conn(move |conn| {
+ let current: Option<String> = conn
+ .query_row("SELECT settings_json FROM app_settings WHERE id = 1", [], |row| row.get(0))
+ .optional()
+ .map_err(|e| e.to_string())?;
+ let mut settings = match current {
+ Some(json) => serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(&json)
+ .map_err(|e| format!("invalid app settings JSON: {e}"))?,
+ None => serde_json::Map::new(),
+ };
+ settings
+ .insert(MAX_RETRIES_KEY.to_string(), serde_json::Value::Number(serde_json::Number::from(max_retries)));
+ let json = serde_json::Value::Object(settings).to_string();
+ conn.execute("INSERT OR REPLACE INTO app_settings (id, settings_json) VALUES (1, ?1)", [json])
+ .map(|_| ())
+ .map_err(|e| e.to_string())
+ })
+ .await
+ }
+
+ pub async fn load_max_retries(&self) -> Result<u32, String> {
+ let settings = self.load_app_settings_json().await?;
+ Ok(settings
+ .get(MAX_RETRIES_KEY)
+ .and_then(serde_json::Value::as_u64)
+ .map(|value| crate::ai::clamp_max_retries(value.min(u32::MAX as u64) as u32))
+ .unwrap_or(crate::ai::DEFAULT_MAX_RETRIES))
+ }
}
// AI Conversations
@@ -4714,6 +4751,36 @@ mod tests {
assert_eq!(storage.load_max_agent_turns().await.unwrap(), crate::agent_loop::MAX_MAX_AGENT_TURNS);
}
+ #[tokio::test]
+ async fn max_retries_defaults_and_persists_clamped() {
+ let path = temp_db_path("max-retries");
+ let storage = Storage::open(&path).await.unwrap();
+
+ assert_eq!(storage.load_max_retries().await.unwrap(), crate::ai::DEFAULT_MAX_RETRIES);
+
+ storage.save_max_retries(5).await.unwrap();
+ assert_eq!(storage.load_max_retries().await.unwrap(), 5);
+
+ storage.save_max_retries(0).await.unwrap();
+ assert_eq!(storage.load_max_retries().await.unwrap(), 0);
+
+ // Values above the cap are clamped so raw DB edits cannot bypass the limit.
+ storage.save_max_retries(u32::MAX).await.unwrap();
+ assert_eq!(storage.load_max_retries().await.unwrap(), crate::ai::MAX_MAX_RETRIES);
+ }
+
+ #[tokio::test]
+ async fn max_retries_survives_stale_app_settings_save() {
+ let path = temp_db_path("max-retries-stale-save");
+ let storage = Storage::open(&path).await.unwrap();
+ let stale_settings = storage.load_app_settings_json().await.unwrap();
+
+ storage.save_max_retries(7).await.unwrap();
+ storage.save_app_settings_json(&stale_settings).await.unwrap();
+
+ assert_eq!(storage.load_max_retries().await.unwrap(), 7);
+ }
+
#[tokio::test]
async fn password_hash_preserves_existing_desktop_settings() {
let path = temp_db_path("password-preserve-desktop-settings");
@@ -5040,6 +5107,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: std::collections::HashMap::new(),
claude_code_cli_path: None,
diff --git a/crates/dbx-web/src/main.rs b/crates/dbx-web/src/main.rs
index 0e4e2db6a4..dc091e8197 100644
--- a/crates/dbx-web/src/main.rs
+++ b/crates/dbx-web/src/main.rs
@@ -719,6 +719,10 @@ async fn main() {
"/app-settings/max-agent-turns",
get(routes::app_settings::load_max_agent_turns).put(routes::app_settings::save_max_agent_turns),
)
+ .route(
+ "/app-settings/max-retries",
+ get(routes::app_settings::load_max_retries).put(routes::app_settings::save_max_retries),
+ )
.route("/app-settings/config/decrypt", post(routes::app_settings::decrypt_config))
// Cloud sync
.route("/cloud-sync/webdav/test", post(routes::cloud_sync::webdav_sync_test))
diff --git a/crates/dbx-web/src/routes/ai.rs b/crates/dbx-web/src/routes/ai.rs
index 8f8b82b751..8fd167ac9b 100644
--- a/crates/dbx-web/src/routes/ai.rs
+++ b/crates/dbx-web/src/routes/ai.rs
@@ -114,7 +114,7 @@ fn default_agent_mode() -> String {
}
fn reject_web_unsupported_ai_provider(config: &AiConfig) -> Result<(), AppError> {
- if matches!(config.provider, AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli) {
+ if dbx_core::ai::is_cli_provider(&config.provider) {
return Err(AppError::bad_request("CLI providers are only supported in DBX Desktop."));
}
Ok(())
@@ -269,9 +269,17 @@ pub async fn delete_ai_conversation(
// AI complete (non-streaming)
// ---------------------------------------------------------------------------
-pub async fn ai_complete(Json(body): Json<AiCompleteRequest>) -> Result<Json<String>, AppError> {
+pub async fn ai_complete(
+ State(state): State<Arc<WebState>>,
+ Json(body): Json<AiCompleteRequest>,
+) -> Result<Json<String>, AppError> {
reject_web_unsupported_ai_provider(&body.request.config)?;
- let result = dbx_core::ai::complete(&body.request).await.map_err(AppError::from)?;
+ let mut request = body.request;
+ dbx_core::ai::merge_global_max_retries(
+ &mut request.config,
+ state.app.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
+ let result = dbx_core::ai::complete(&request).await.map_err(AppError::from)?;
Ok(Json(result))
}
@@ -280,24 +288,44 @@ pub async fn ai_complete(Json(body): Json<AiCompleteRequest>) -> Result<Json<Str
// ---------------------------------------------------------------------------
pub async fn ai_test_connection(
+ State(state): State<Arc<WebState>>,
Json(body): Json<AiTestConnectionRequest>,
) -> Result<Json<AiTestConnectionResult>, AppError> {
- reject_web_unsupported_ai_provider(&body.config)?;
- let result = dbx_core::ai::test_connection_core(&body.config).await.map_err(AppError::from)?;
+ let mut config = body.config;
+ reject_web_unsupported_ai_provider(&config)?;
+ dbx_core::ai::merge_global_max_retries(
+ &mut config,
+ state.app.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
+ let result = dbx_core::ai::test_connection_core(&config).await.map_err(AppError::from)?;
Ok(Json(result))
}
-pub async fn ai_list_models(Json(body): Json<AiListModelsRequest>) -> Result<Json<Vec<AiModelInfo>>, AppError> {
- reject_web_unsupported_ai_provider(&body.config)?;
- let result = dbx_core::ai::list_models_core(&body.config).await.map_err(AppError::from)?;
+pub async fn ai_list_models(
+ State(state): State<Arc<WebState>>,
+ Json(body): Json<AiListModelsRequest>,
+) -> Result<Json<Vec<AiModelInfo>>, AppError> {
+ let mut config = body.config;
+ reject_web_unsupported_ai_provider(&config)?;
+ dbx_core::ai::merge_global_max_retries(
+ &mut config,
+ state.app.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
+ let result = dbx_core::ai::list_models_core(&config).await.map_err(AppError::from)?;
Ok(Json(result))
}
pub async fn ai_resolve_model_effort(
+ State(state): State<Arc<WebState>>,
Json(body): Json<AiResolveModelEffortRequest>,
) -> Result<Json<AiEffortCapability>, AppError> {
- reject_web_unsupported_ai_provider(&body.config)?;
- let result = dbx_core::ai::resolve_model_effort_core(&body.config, &body.model_id).await.map_err(AppError::from)?;
+ let mut config = body.config;
+ reject_web_unsupported_ai_provider(&config)?;
+ dbx_core::ai::merge_global_max_retries(
+ &mut config,
+ state.app.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
+ let result = dbx_core::ai::resolve_model_effort_core(&config, &body.model_id).await.map_err(AppError::from)?;
Ok(Json(result))
}
@@ -315,11 +343,16 @@ pub async fn ai_cancel_stream(Json(body): Json<AiCancelStreamRequest>) -> Result
// ---------------------------------------------------------------------------
pub async fn ai_stream(
+ State(state): State<Arc<WebState>>,
Json(body): Json<AiStreamRequest>,
) -> Result<Sse<impl Stream<Item = Result<Event, std::convert::Infallible>>>, AppError> {
let session_id = body.session_id;
- let request = body.request;
+ let mut request = body.request;
reject_web_unsupported_ai_provider(&request.config)?;
+ dbx_core::ai::merge_global_max_retries(
+ &mut request.config,
+ state.app.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
let cancelled = dbx_core::ai::register_stream(&session_id).await;
let (tx, rx) = tokio::sync::broadcast::channel::<String>(256);
@@ -380,6 +413,10 @@ pub async fn ai_agent_stream(
log::warn!("Failed to load max_agent_turns setting, using default: {err}");
dbx_core::agent_loop::DEFAULT_MAX_AGENT_TURNS
});
+ let max_retries = state.app.storage.load_max_retries().await.unwrap_or_else(|err| {
+ log::warn!("Failed to load max_retries setting, using default: {err}");
+ dbx_core::ai::DEFAULT_MAX_RETRIES
+ });
// Reject the confirmed-write grant when the connection or database changed
// between the user's confirmation and this backend request (defense-in-depth).
let (allow_write_sql, confirmed_write_sql) = dbx_core::agent_tools::verify_confirmed_target(
@@ -409,7 +446,8 @@ pub async fn ai_agent_stream(
};
let sid = session_id.clone();
- let req_config = request.config;
+ let mut req_config = request.config;
+ dbx_core::ai::merge_global_max_retries(&mut req_config, max_retries);
let req_system_prompt = request.system_prompt;
let req_messages = request.messages;
let req_task_contract = request.task_contract;
@@ -475,6 +513,7 @@ mod tests {
reasoning_level: AiReasoningLevel::Default,
runtime_effort: None,
context_window: None,
+ max_retries: None,
codex_cli_path: None,
codex_cli_env: Default::default(),
claude_code_cli_path: None,
@@ -508,4 +547,77 @@ mod tests {
assert!(reject_web_unsupported_ai_provider(&config).is_ok(), "provider {:?} should be allowed", provider);
}
}
+
+ /// Integration test: the `ai_test_connection` web handler applies global
+ /// max_retries=0 so that a 429 is not retried.
+ #[tokio::test]
+ async fn web_test_connection_respects_global_max_retries_zero() {
+ use std::sync::atomic::{AtomicU32, Ordering};
+ use std::sync::Arc;
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
+
+ use axum::extract::State;
+ use dbx_core::connection::AppState;
+
+ let dir = std::env::temp_dir().join(format!("dbx-web-intg-max-retries-{}", uuid::Uuid::new_v4()));
+ let _ = std::fs::create_dir_all(&dir);
+ let storage = dbx_core::storage::Storage::open(&dir.join("storage.db")).await.unwrap();
+ storage.save_max_retries(0).await.unwrap();
+ assert_eq!(storage.load_max_retries().await.unwrap(), 0);
+
+ let app = Arc::new(AppState::new_with_plugin_dir(storage, dir.join("plugins")));
+ let web_state = Arc::new(crate::state::WebState::for_tests(app, dir.clone()));
+
+ // Counting 429 server
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let addr = listener.local_addr().unwrap();
+ let url = format!("http://{addr}");
+ let count = Arc::new(AtomicU32::new(0));
+ let count2 = count.clone();
+ let srv = tokio::spawn(async move {
+ while let Ok((mut socket, _)) = listener.accept().await {
+ count2.fetch_add(1, Ordering::SeqCst);
+ let mut buf = vec![0u8; 4096];
+ let _ = socket.read(&mut buf).await;
+ let resp = b"HTTP/1.1 429 Too Many Requests\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
+ let _ = socket.write_all(resp).await;
+ }
+ });
+
+ let config = AiConfig {
+ provider: AiProvider::Claude,
+ api_key: "sk-test".to_string(),
+ auth_method: AiAuthMethod::ApiKey,
+ endpoint: url.clone(),
+ model: "claude-sonnet-4".to_string(),
+ models: vec![],
+ api_style: AiApiStyle::AnthropicMessages,
+ proxy_enabled: false,
+ proxy_url: String::new(),
+ enable_thinking: false,
+ reasoning_level: AiReasoningLevel::Default,
+ runtime_effort: None,
+ context_window: None,
+ max_retries: None,
+ codex_cli_path: None,
+ codex_cli_env: Default::default(),
+ claude_code_cli_path: None,
+ claude_code_cli_env: Default::default(),
+ pi_agent_cli_path: None,
+ pi_agent_cli_env: Default::default(),
+ };
+
+ let body = super::AiTestConnectionRequest { config };
+ let result = super::ai_test_connection(State(web_state), axum::Json(body)).await;
+
+ // 429 → should NOT succeed (no retry).
+ if let Ok(axum::Json(resp)) = result {
+ assert!(!resp.success, "429 with max_retries=0 must fail, got success");
+ }
+
+ srv.abort();
+ assert_eq!(count.load(Ordering::SeqCst), 1, "max_retries=0 must mean exactly 1 request");
+
+ let _ = std::fs::remove_dir_all(&dir);
+ }
}
diff --git a/crates/dbx-web/src/routes/app_settings.rs b/crates/dbx-web/src/routes/app_settings.rs
index cc4aff708f..bfc3244280 100644
--- a/crates/dbx-web/src/routes/app_settings.rs
+++ b/crates/dbx-web/src/routes/app_settings.rs
@@ -83,6 +83,24 @@ pub async fn save_max_agent_turns(
Ok(Json(()))
}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SaveMaxRetriesRequest {
+ pub max_retries: u32,
+}
+
+pub async fn load_max_retries(State(state): State<Arc<WebState>>) -> Result<Json<u32>, AppError> {
+ state.app.storage.load_max_retries().await.map(Json).map_err(AppError::from)
+}
+
+pub async fn save_max_retries(
+ State(state): State<Arc<WebState>>,
+ Json(body): Json<SaveMaxRetriesRequest>,
+) -> Result<Json<()>, AppError> {
+ state.app.storage.save_max_retries(body.max_retries).await.map_err(AppError::from)?;
+ Ok(Json(()))
+}
+
pub async fn decrypt_config(Json(body): Json<DecryptConfigRequest>) -> Result<Json<String>, AppError> {
decrypt_config_payload(&body.payload, &body.passphrase).map(Json).map_err(AppError::from)
}
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 51e814164a..7d8e69635c 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -67,6 +67,9 @@ font-kit = "0.14.3"
tauri-plugin-clipboard-manager = "2.3.2"
sys-locale = "0.3"
+[dev-dependencies]
+tauri = { version = "2.10.3", features = ["test"] }
+
[target.'cfg(target_os = "macos")'.dependencies]
objc2 = { version = "0.6.4", default-features = false, features = ["std"] }
objc2-app-kit = { version = "0.3.2", default-features = false, features = ["NSApplication", "NSButton", "NSControl", "NSDockTile", "NSImage", "NSResponder", "NSView", "NSWindow"] }
diff --git a/src-tauri/src/commands/ai.rs b/src-tauri/src/commands/ai.rs
index 31761a7d7f..8d74a34efb 100644
--- a/src-tauri/src/commands/ai.rs
+++ b/src-tauri/src/commands/ai.rs
@@ -6,20 +6,39 @@ use super::connection::AppState;
pub use dbx_core::ai::*;
#[tauri::command]
-pub async fn ai_test_connection(config: AiConfig) -> Result<AiTestConnectionResult, String> {
- let config = resolve_cli_provider_config(config);
+pub async fn ai_test_connection(
+ state: State<'_, Arc<AppState>>,
+ config: AiConfig,
+) -> Result<AiTestConnectionResult, String> {
+ let mut config = resolve_cli_provider_config(config);
+ merge_global_max_retries(
+ &mut config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
dbx_core::ai::test_connection_core(&config).await
}
#[tauri::command]
-pub async fn ai_list_models(config: AiConfig) -> Result<Vec<AiModelInfo>, String> {
- let config = resolve_cli_provider_config(config);
+pub async fn ai_list_models(state: State<'_, Arc<AppState>>, config: AiConfig) -> Result<Vec<AiModelInfo>, String> {
+ let mut config = resolve_cli_provider_config(config);
+ merge_global_max_retries(
+ &mut config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
dbx_core::ai::list_models_core(&config).await
}
#[tauri::command]
-pub async fn ai_resolve_model_effort(config: AiConfig, model_id: String) -> Result<AiEffortCapability, String> {
- let config = resolve_cli_provider_config(config);
+pub async fn ai_resolve_model_effort(
+ state: State<'_, Arc<AppState>>,
+ config: AiConfig,
+ model_id: String,
+) -> Result<AiEffortCapability, String> {
+ let mut config = resolve_cli_provider_config(config);
+ merge_global_max_retries(
+ &mut config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
dbx_core::ai::resolve_model_effort_core(&config, &model_id).await
}
@@ -67,12 +86,27 @@ pub async fn load_ai_chat_selection(state: State<'_, Arc<AppState>>) -> Result<O
}
#[tauri::command]
-pub async fn ai_complete(request: AiCompletionRequest) -> Result<String, String> {
+pub async fn ai_complete(state: State<'_, Arc<AppState>>, request: AiCompletionRequest) -> Result<String, String> {
+ let mut request = request;
+ merge_global_max_retries(
+ &mut request.config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
dbx_core::ai::complete(&request).await
}
#[tauri::command]
-pub async fn ai_stream(app: AppHandle, session_id: String, request: AiCompletionRequest) -> Result<(), String> {
+pub async fn ai_stream(
+ app: AppHandle,
+ state: State<'_, Arc<AppState>>,
+ session_id: String,
+ request: AiCompletionRequest,
+) -> Result<(), String> {
+ let mut request = request;
+ merge_global_max_retries(
+ &mut request.config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
let cancelled = dbx_core::ai::register_stream(&session_id).await;
let result = dbx_core::ai::stream(&session_id, &request, &cancelled, |chunk| {
@@ -110,7 +144,11 @@ pub async fn ai_agent_stream(
confirmed_connection_id: Option<String>,
confirmed_database: Option<String>,
) -> Result<String, String> {
- let request = resolve_cli_provider_request(request);
+ let mut request = resolve_cli_provider_request(request);
+ merge_global_max_retries(
+ &mut request.config,
+ state.storage.load_max_retries().await.unwrap_or(dbx_core::ai::DEFAULT_MAX_RETRIES),
+ );
let parsed_db_type: DatabaseType =
serde_json::from_str(&format!("\"{}\"", db_type)).map_err(|_| format!("Unknown database type: {db_type}"))?;
@@ -209,10 +247,6 @@ fn resolve_cli_provider_config(mut config: AiConfig) -> AiConfig {
config
}
-fn is_cli_provider(provider: &AiProvider) -> bool {
- matches!(provider, AiProvider::CodexCli | AiProvider::ClaudeCodeCli | AiProvider::PiAgentCli)
-}
-
fn is_explicit_cli_path(command: &str) -> bool {
let path = Path::new(command);
path.is_absolute() || command.contains('/') || command.contains('\\')
@@ -235,6 +269,58 @@ pub async fn delete_ai_conversation(state: State<'_, Arc<AppState>>, id: String)
#[cfg(test)]
mod tests {
+ use std::sync::atomic::{AtomicU32, Ordering};
+ use std::sync::Arc;
+
+ use tauri::Manager;
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
+
+ use super::super::connection::AppState;
+ use dbx_core::ai::{AiApiStyle, AiAuthMethod, AiConfig, AiProvider, AiReasoningLevel};
+
+ /// Spawn a TCP server that returns 429 and counts connections.
+ async fn counting_429_server() -> (String, Arc<AtomicU32>, tokio::task::JoinHandle<()>) {
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let addr = listener.local_addr().unwrap();
+ let url = format!("http://{addr}");
+ let count = Arc::new(AtomicU32::new(0));
+ let count2 = count.clone();
+ let srv = tokio::spawn(async move {
+ while let Ok((mut socket, _)) = listener.accept().await {
+ count2.fetch_add(1, Ordering::SeqCst);
+ let mut buf = vec![0u8; 4096];
+ let _ = socket.read(&mut buf).await;
+ let resp = b"HTTP/1.1 429 Too Many Requests\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
+ let _ = socket.write_all(resp).await;
+ }
+ });
+ (url, count, srv)
+ }
+
+ fn test_ai_config(endpoint: &str, model: &str) -> AiConfig {
+ AiConfig {
+ provider: AiProvider::Claude,
+ api_key: "sk-test".to_string(),
+ auth_method: AiAuthMethod::ApiKey,
+ endpoint: endpoint.to_string(),
+ model: model.to_string(),
+ models: vec![],
+ api_style: AiApiStyle::AnthropicMessages,
+ proxy_enabled: false,
+ proxy_url: String::new(),
+ enable_thinking: false,
+ reasoning_level: AiReasoningLevel::Default,
+ runtime_effort: None,
+ context_window: None,
+ max_retries: None,
+ codex_cli_path: None,
+ codex_cli_env: Default::default(),
+ claude_code_cli_path: None,
+ claude_code_cli_env: Default::default(),
+ pi_agent_cli_path: None,
+ pi_agent_cli_env: Default::default(),
+ }
+ }
#[test]
fn verify_confirmed_target_allows_matching_connection_and_database() {
@@ -310,4 +396,30 @@ mod tests {
assert_eq!(allow, Some(false));
assert_eq!(confirmed, None);
}
+
+ #[tokio::test]
+ async fn tauri_entry_respects_global_max_retries_zero() {
+ let dir = std::env::temp_dir().join(format!("dbx-tauri-mr-{}", uuid::Uuid::new_v4()));
+ let _ = std::fs::create_dir_all(&dir);
+ let storage = dbx_core::storage::Storage::open(&dir.join("storage.db")).await.unwrap();
+ storage.save_max_retries(0).await.unwrap();
+ assert_eq!(storage.load_max_retries().await.unwrap(), 0);
+
+ let (url, count, srv) = counting_429_server().await;
+
+ let app_state = Arc::new(AppState::new_with_plugin_dir(storage, dir.join("plugins")));
+ let app = tauri::test::mock_app();
+ app.manage(app_state);
+
+ let state: tauri::State<'_, Arc<AppState>> = app.state();
+ let config = test_ai_config(&url, "claude-sonnet-4");
+ let result = super::ai_test_connection(state, config).await;
+
+ assert!(result.is_err(), "429 with max_retries=0 must fail, got: {result:?}");
+ srv.abort();
+ assert_eq!(count.load(Ordering::SeqCst), 1, "max_retries=0 must mean exactly 1 request");
+
+ drop(app);
+ let _ = std::fs::remove_dir_all(&dir);
+ }
}
diff --git a/src-tauri/src/commands/app_settings.rs b/src-tauri/src/commands/app_settings.rs
index 66db69df54..53f060697f 100644
--- a/src-tauri/src/commands/app_settings.rs
+++ b/src-tauri/src/commands/app_settings.rs
@@ -69,6 +69,16 @@ pub async fn save_max_agent_turns(state: State<'_, Arc<AppState>>, max_agent_tur
state.storage.save_max_agent_turns(max_agent_turns).await
}
+#[tauri::command]
+pub async fn load_max_retries(state: State<'_, Arc<AppState>>) -> Result<u32, String> {
+ state.storage.load_max_retries().await
+}
+
+#[tauri::command]
+pub async fn save_max_retries(state: State<'_, Arc<AppState>>, max_retries: u32) -> Result<(), String> {
+ state.storage.save_max_retries(max_retries).await
+}
+
#[tauri::command]
pub async fn complete_app_close(app: AppHandle, window: Window, action: String) -> Result<(), String> {
match action.as_str() {
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index e8d37401fa..976c5abe3c 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1352,6 +1352,8 @@ pub fn run() {
commands::app_settings::save_desktop_settings,
commands::app_settings::load_max_agent_turns,
commands::app_settings::save_max_agent_turns,
+ commands::app_settings::load_max_retries,
+ commands::app_settings::save_max_retries,
commands::app_settings::set_app_locale,
commands::app_settings::complete_app_close,
commands::app_settings::mark_frontend_ready,