fix(desktop): guard invoke calls with isTauriRuntime check
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Step 5 (embedding config) and Step 5b (summary driver) in App.tsx bootstrap called invoke() without checking if Tauri IPC is available. When accessing http://localhost:1420/ in a regular browser, this caused "Cannot read properties of undefined (reading 'transformCallback')". Also added __TAURI_INTERNALS__ guard in saasStore kernel config sync.
This commit is contained in:
@@ -261,63 +261,65 @@ function App() {
|
|||||||
// Non-critical, continue without heartbeat
|
// Non-critical, continue without heartbeat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: Restore embedding config to Rust backend
|
// Step 5: Restore embedding config to Rust backend (Tauri-only)
|
||||||
try {
|
if (isTauriRuntime()) {
|
||||||
// Migrate plaintext embedding apiKey to secure storage if present
|
|
||||||
try {
|
try {
|
||||||
const embStored = localStorage.getItem('zclaw-embedding-config');
|
// Migrate plaintext embedding apiKey to secure storage if present
|
||||||
if (embStored) {
|
try {
|
||||||
const embParsed = JSON.parse(embStored);
|
const embStored = localStorage.getItem('zclaw-embedding-config');
|
||||||
if (embParsed.apiKey && embParsed.apiKey.trim()) {
|
if (embStored) {
|
||||||
const { saveEmbeddingApiKey } = await import('./lib/embedding-client');
|
const embParsed = JSON.parse(embStored);
|
||||||
const { secureStorage } = await import('./lib/secure-storage');
|
if (embParsed.apiKey && embParsed.apiKey.trim()) {
|
||||||
// Only migrate if not already in secure storage
|
const { saveEmbeddingApiKey } = await import('./lib/embedding-client');
|
||||||
const existing = await secureStorage.get('zclaw-secure-embedding-apikey');
|
const { secureStorage } = await import('./lib/secure-storage');
|
||||||
if (!existing) {
|
// Only migrate if not already in secure storage
|
||||||
await saveEmbeddingApiKey(embParsed.apiKey);
|
const existing = await secureStorage.get('zclaw-secure-embedding-apikey');
|
||||||
|
if (!existing) {
|
||||||
|
await saveEmbeddingApiKey(embParsed.apiKey);
|
||||||
|
}
|
||||||
|
// Strip apiKey from localStorage
|
||||||
|
const { apiKey: _, ...stripped } = embParsed;
|
||||||
|
localStorage.setItem('zclaw-embedding-config', JSON.stringify(stripped));
|
||||||
}
|
}
|
||||||
// Strip apiKey from localStorage
|
|
||||||
const { apiKey: _, ...stripped } = embParsed;
|
|
||||||
localStorage.setItem('zclaw-embedding-config', JSON.stringify(stripped));
|
|
||||||
}
|
}
|
||||||
|
} catch { /* migration failure is non-critical */ }
|
||||||
|
|
||||||
|
const embConfig = loadEmbeddingConfig();
|
||||||
|
const embApiKey = await loadEmbeddingApiKey();
|
||||||
|
if (embConfig.enabled && embConfig.provider !== 'local' && embApiKey) {
|
||||||
|
setBootstrapStatus('Restoring embedding configuration...');
|
||||||
|
await invoke('viking_configure_embedding', {
|
||||||
|
provider: embConfig.provider,
|
||||||
|
apiKey: embApiKey,
|
||||||
|
model: embConfig.model || undefined,
|
||||||
|
endpoint: embConfig.endpoint || undefined,
|
||||||
|
});
|
||||||
|
log.debug('Embedding configuration restored to backend');
|
||||||
}
|
}
|
||||||
} catch { /* migration failure is non-critical */ }
|
} catch (embErr) {
|
||||||
|
log.warn('Failed to restore embedding config:', embErr);
|
||||||
const embConfig = loadEmbeddingConfig();
|
// Non-critical, semantic search will fall back to TF-IDF
|
||||||
const embApiKey = await loadEmbeddingApiKey();
|
|
||||||
if (embConfig.enabled && embConfig.provider !== 'local' && embApiKey) {
|
|
||||||
setBootstrapStatus('Restoring embedding configuration...');
|
|
||||||
await invoke('viking_configure_embedding', {
|
|
||||||
provider: embConfig.provider,
|
|
||||||
apiKey: embApiKey,
|
|
||||||
model: embConfig.model || undefined,
|
|
||||||
endpoint: embConfig.endpoint || undefined,
|
|
||||||
});
|
|
||||||
log.debug('Embedding configuration restored to backend');
|
|
||||||
}
|
}
|
||||||
} catch (embErr) {
|
|
||||||
log.warn('Failed to restore embedding config:', embErr);
|
|
||||||
// Non-critical, semantic search will fall back to TF-IDF
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 5b: Configure summary driver using active LLM (for L0/L1 generation)
|
// Step 5b: Configure summary driver using active LLM (for L0/L1 generation)
|
||||||
try {
|
try {
|
||||||
const { getDefaultModelConfigAsync, migrateModelApiKeysToSecureStorage } = await import('./store/connectionStore');
|
const { getDefaultModelConfigAsync, migrateModelApiKeysToSecureStorage } = await import('./store/connectionStore');
|
||||||
// Migrate any plaintext API keys to secure storage (idempotent)
|
// Migrate any plaintext API keys to secure storage (idempotent)
|
||||||
await migrateModelApiKeysToSecureStorage();
|
await migrateModelApiKeysToSecureStorage();
|
||||||
const modelConfig = await getDefaultModelConfigAsync();
|
const modelConfig = await getDefaultModelConfigAsync();
|
||||||
if (modelConfig && modelConfig.apiKey && modelConfig.baseUrl) {
|
if (modelConfig && modelConfig.apiKey && modelConfig.baseUrl) {
|
||||||
setBootstrapStatus('Configuring summary driver...');
|
setBootstrapStatus('Configuring summary driver...');
|
||||||
await invoke('viking_configure_summary_driver', {
|
await invoke('viking_configure_summary_driver', {
|
||||||
endpoint: modelConfig.baseUrl,
|
endpoint: modelConfig.baseUrl,
|
||||||
apiKey: modelConfig.apiKey,
|
apiKey: modelConfig.apiKey,
|
||||||
model: modelConfig.model || undefined,
|
model: modelConfig.model || undefined,
|
||||||
});
|
});
|
||||||
log.debug('Summary driver configured with active LLM');
|
log.debug('Summary driver configured with active LLM');
|
||||||
|
}
|
||||||
|
} catch (sumErr) {
|
||||||
|
log.warn('Failed to configure summary driver:', sumErr);
|
||||||
|
// Non-critical, summaries won't be auto-generated
|
||||||
}
|
}
|
||||||
} catch (sumErr) {
|
|
||||||
log.warn('Failed to configure summary driver:', sumErr);
|
|
||||||
// Non-critical, summaries won't be auto-generated
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6: Bootstrap complete
|
// Step 6: Bootstrap complete
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ export const useSaaSStore = create<SaaSStore>((set, get) => {
|
|||||||
const kernelConfigs = result.configs.filter(
|
const kernelConfigs = result.configs.filter(
|
||||||
(c) => kernelCategories.includes(c.category) && c.value !== null
|
(c) => kernelCategories.includes(c.category) && c.value !== null
|
||||||
);
|
);
|
||||||
if (kernelConfigs.length > 0) {
|
if (kernelConfigs.length > 0 && typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window) {
|
||||||
try {
|
try {
|
||||||
const { invoke } = await import('@tauri-apps/api/core');
|
const { invoke } = await import('@tauri-apps/api/core');
|
||||||
await invoke('kernel_apply_saas_config', {
|
await invoke('kernel_apply_saas_config', {
|
||||||
|
|||||||
Reference in New Issue
Block a user