feat(ai): add generic AI configuration deep links
This commit is contained in:
13 files changed
+503
-13
No files matched your search
@@ -65,7 +65,8 @@ import TunnelProfileManager from "@/components/connection/TunnelProfileManager.v
|
||||
import DangerConfirmDialog from "./DangerConfirmDialog.vue";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { copyToClipboard, readTextFromClipboard } from "@/lib/common/clipboard";
|
||||
import { importClipboardApiKeyAfterConfirmation, type AiConfigDeepLinkDraft } from "@/lib/ai/aiConfigDeepLink";
|
||||
import { clearDebugLogs as clearStoredDebugLogs, downloadDebugLogs, getDebugLogBundleText } from "@/lib/backend/debugLog";
|
||||
import {
|
||||
aiTestConnection,
|
||||
@@ -205,6 +206,8 @@ const props = defineProps<{
|
||||
initialTab?: string;
|
||||
initialSection?: string;
|
||||
navigationRequestId?: number;
|
||||
aiConfigDraft?: AiConfigDeepLinkDraft | null;
|
||||
aiConfigRequestId?: number;
|
||||
appVersion?: string;
|
||||
checkingUpdates?: boolean;
|
||||
}>();
|
||||
@@ -2420,6 +2423,7 @@ async function scrollToInitialSettingsSection() {
|
||||
const aiConfigListMode = ref<"list" | "edit">("list");
|
||||
const aiEditConfigName = ref("");
|
||||
const aiEditConfigId = ref<string | null>(null);
|
||||
let handledAiConfigRequestId = 0;
|
||||
const displayedAiConfigs = computed(() => orderAiConfigsForDisplay(settingsStore.aiConfigs));
|
||||
|
||||
watch(
|
||||
@@ -2479,6 +2483,7 @@ watch(
|
||||
await refreshSnippetTokenStatus();
|
||||
await refreshSnippetSyncSettings();
|
||||
syncAiEditState();
|
||||
await applyPendingAiConfigDeepLinkDraft();
|
||||
if (!isWeb && activeSettingsTab.value === "mcp") void refreshMcpStatus();
|
||||
if (!isWeb && activeSettingsTab.value === "ai" && aiIsCliProvider.value) void ensureCliMcpStatus();
|
||||
if (activeSettingsTab.value === "about") void refreshAppSupportInfo();
|
||||
@@ -2515,6 +2520,13 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.aiConfigRequestId,
|
||||
() => {
|
||||
if (settingsVisible.value) void applyPendingAiConfigDeepLinkDraft();
|
||||
},
|
||||
);
|
||||
|
||||
watch([webdavEndpoint, webdavUsername], () => {
|
||||
void refreshWebDavPasswordStatus();
|
||||
});
|
||||
@@ -3220,6 +3232,46 @@ function aiEnterEditMode(configId?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPendingAiConfigDeepLinkDraft() {
|
||||
const requestId = props.aiConfigRequestId ?? 0;
|
||||
const draft = props.aiConfigDraft;
|
||||
if (!settingsVisible.value || !requestId || requestId === handledAiConfigRequestId || !draft) return;
|
||||
|
||||
handledAiConfigRequestId = requestId;
|
||||
activeSettingsTab.value = "ai";
|
||||
aiEnterEditMode();
|
||||
aiEditConfigName.value = draft.name;
|
||||
aiEditProvider.value = draft.provider;
|
||||
aiEditApiKey.value = "";
|
||||
aiEditAuthMethod.value = draft.authMethod;
|
||||
aiEditEndpoint.value = draft.endpoint;
|
||||
aiEditModel.value = draft.model;
|
||||
aiEditLegacyModels.value = [];
|
||||
aiEditApiStyle.value = draft.apiStyle;
|
||||
|
||||
if (!draft.promptForClipboardApiKey) return;
|
||||
|
||||
try {
|
||||
const result = await importClipboardApiKeyAfterConfirmation(async () => {
|
||||
const { ask } = await import("@tauri-apps/plugin-dialog");
|
||||
return ask(t("ai.deepLinkClipboardPrompt"), {
|
||||
title: t("ai.deepLinkClipboardTitle"),
|
||||
kind: "info",
|
||||
});
|
||||
}, readTextFromClipboard);
|
||||
if (result.kind === "accepted") aiEditApiKey.value = result.apiKey;
|
||||
else if (result.kind === "empty") toast(t("ai.deepLinkClipboardEmpty"), 4000);
|
||||
else if (result.kind === "invalid") toast(t("ai.deepLinkClipboardInvalid"), 4000);
|
||||
} catch (e: any) {
|
||||
toast(
|
||||
t("ai.deepLinkClipboardReadFailed", {
|
||||
message: e?.message || String(e),
|
||||
}),
|
||||
5000,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function aiSaveConfig() {
|
||||
const validationResult: ConfigNameValidationResult = validateConfigName(aiEditConfigName.value, settingsStore.aiConfigs, aiEditConfigId.value || undefined);
|
||||
if (validationResult === "empty") {
|
||||
|
||||
Reference in new issue
Block a user