refactor: extract shared types + safe chrome wrappers into src/lib
- src/lib/types.ts: message contract (both ANALYZE_TEXT shapes preserved), config/response types, storage-key constants. - src/lib/messaging.ts: single safeStorageGet/safeStorageSet/safeSendMessage/ isExtensionValid implementation replacing the three divergent copies in Options, Popup, and content. Content script keeps its refresh-toast behavior via an onContextInvalidated callback. - New '@lib' import alias (wxt force-overwrites '~' and '@' to srcDir, so those cannot point at ./src); wired in wxt.config, tsconfig, vitest. - tests/unit/messaging.test.ts: 14 unit tests over the wrappers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { defineBackground } from 'wxt/utils/define-background';
|
||||
import nacl from 'tweetnacl';
|
||||
import type { AnalyzePayload, LexAIConfig, LexAIResponse } from '@lib/types';
|
||||
|
||||
// ─── Fetch with timeout ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -13,27 +14,6 @@ async function fetchWithTimeout(url: string, options: RequestInit, timeoutMs = 3
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface AnalyzePayload {
|
||||
text: string;
|
||||
action: string;
|
||||
style?: string;
|
||||
}
|
||||
|
||||
interface LexAIConfig {
|
||||
provider?: string;
|
||||
apiKey?: string;
|
||||
apiKeyEnc?: string;
|
||||
encKey?: string;
|
||||
model?: string;
|
||||
}
|
||||
|
||||
interface LexAIResponse {
|
||||
result?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// ─── System prompts ───────────────────────────────────────────────────────────
|
||||
|
||||
function getSystemPrompt(action: string, style?: string): string {
|
||||
|
||||
Reference in New Issue
Block a user