fix(ai): use current form config for connection tests
This commit is contained in:
4 files changed
+52
-6
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user