mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-20 00:17:44 +00:00
fix(ai): use current form config for connection tests
This commit is contained in:
@@ -50,6 +50,7 @@ import {
|
||||
} from "@/stores/settingsStore";
|
||||
import { createRunStatementButtonDom, loadEditorTheme, editorFontTheme } from "@/lib/editor/editorThemes";
|
||||
import { orderAiConfigsForDisplay } from "@/lib/ai/aiConfigOrdering";
|
||||
import { isAiConnectionTestConfigCurrent } from "@/lib/ai/aiConnectionTest";
|
||||
import { MAX_AGENT_TURNS_DEFAULT, MAX_AGENT_TURNS_MAX, MAX_AGENT_TURNS_MIN, maxAgentTurnsOutOfRange, normalizeMaxAgentTurns } from "@/lib/ai/maxAgentTurns";
|
||||
import ThemeCustomizerDialog from "./ThemeCustomizerDialog.vue";
|
||||
import TunnelProfileManager from "@/components/connection/TunnelProfileManager.vue";
|
||||
@@ -2712,6 +2713,7 @@ const aiTestResult = ref<"" | "success" | "error">("");
|
||||
const aiTestError = ref("");
|
||||
const aiTestLatency = ref<number | null>(null);
|
||||
const aiTestErrorCopied = ref(false);
|
||||
let aiTestRequestId = 0;
|
||||
const aiTestErrorCategoryKeys: Record<string, string> = {
|
||||
auth: "ai.testErrorAuth",
|
||||
modelNotFound: "ai.testErrorModelNotFound",
|
||||
@@ -2944,6 +2946,8 @@ function currentAiEditConfig() {
|
||||
}
|
||||
|
||||
function syncAiEditState() {
|
||||
aiTestRequestId += 1;
|
||||
aiTesting.value = false;
|
||||
aiTestResult.value = "";
|
||||
aiTestError.value = "";
|
||||
aiTestLatency.value = null;
|
||||
@@ -3126,20 +3130,19 @@ async function aiTestConn() {
|
||||
aiTestError.value = "";
|
||||
aiTestLatency.value = null;
|
||||
aiTestErrorCopied.value = false;
|
||||
const requestId = ++aiTestRequestId;
|
||||
const config = currentAiEditConfig();
|
||||
try {
|
||||
const config = currentAiEditConfig();
|
||||
const activeModel = settingsStore.activeModel;
|
||||
if (aiEditConfigId.value && activeModel?.configId === aiEditConfigId.value) {
|
||||
config.model = activeModel.modelId;
|
||||
}
|
||||
const result = await aiTestConnection(config);
|
||||
if (requestId !== aiTestRequestId || !isAiConnectionTestConfigCurrent(config, currentAiEditConfig())) return;
|
||||
aiTestLatency.value = result.latencyMs ?? null;
|
||||
aiTestResult.value = "success";
|
||||
} catch (e: any) {
|
||||
if (requestId !== aiTestRequestId || !isAiConnectionTestConfigCurrent(config, currentAiEditConfig())) return;
|
||||
aiTestResult.value = "error";
|
||||
aiTestError.value = translateBackendError(t, e);
|
||||
} finally {
|
||||
aiTesting.value = false;
|
||||
if (requestId === aiTestRequestId) aiTesting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AiConfig } from "@/types/ai";
|
||||
import { isAiConnectionTestConfigCurrent } from "../aiConnectionTest";
|
||||
|
||||
function config(overrides: Partial<AiConfig> = {}): AiConfig {
|
||||
return {
|
||||
provider: "openai-compatible",
|
||||
apiKey: "key",
|
||||
authMethod: "bearer",
|
||||
endpoint: "https://example.com/v1",
|
||||
model: "model-a",
|
||||
apiStyle: "completions",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("AI connection test configuration", () => {
|
||||
it("accepts a result only while the tested form values remain current", () => {
|
||||
const tested = config();
|
||||
|
||||
expect(isAiConnectionTestConfigCurrent(tested, config())).toBe(true);
|
||||
expect(isAiConnectionTestConfigCurrent(tested, config({ model: "model-b" }))).toBe(false);
|
||||
expect(isAiConnectionTestConfigCurrent(tested, config({ endpoint: "https://other.example/v1" }))).toBe(false);
|
||||
expect(isAiConnectionTestConfigCurrent(tested, config({ apiKey: "new-key" }))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { AiConfig } from "@/types/ai";
|
||||
|
||||
export function isAiConnectionTestConfigCurrent(testedConfig: AiConfig, currentConfig: AiConfig): boolean {
|
||||
return JSON.stringify(testedConfig) === JSON.stringify(currentConfig);
|
||||
}
|
||||
+12
@@ -648,6 +648,18 @@ test("API AI provider settings expose and persist a default model ID", () => {
|
||||
assert.match(source, /model:\s*aiEditModel\.value/);
|
||||
});
|
||||
|
||||
test("AI connection test uses the model currently entered in the config form", () => {
|
||||
const source = readFileSync("apps/desktop/src/components/editor/EditorSettingsDialog.vue", "utf8");
|
||||
const testConnectionStart = source.indexOf("async function aiTestConn()");
|
||||
const testConnectionEnd = source.indexOf("async function copyAiTestError()", testConnectionStart);
|
||||
const testConnection = source.slice(testConnectionStart, testConnectionEnd);
|
||||
|
||||
assert.notEqual(testConnectionStart, -1);
|
||||
assert.notEqual(testConnectionEnd, -1);
|
||||
assert.match(testConnection, /const config = currentAiEditConfig\(\);[\s\S]*aiTestConnection\(config\)/);
|
||||
assert.doesNotMatch(testConnection, /activeModel|config\.model\s*=/);
|
||||
});
|
||||
|
||||
test("normalizes legacy AI config and fills provider defaults", () => {
|
||||
const legacy = normalizeAiConfig({
|
||||
provider: "openai",
|
||||
|
||||
Reference in New Issue
Block a user