enigma-memory 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "Enigma Local Memory Bridge",
4
+ "version": "0.1.0",
5
+ "description": "Explicit user-approved Enigma context insertion with local-only transfer and no browser sync storage.",
6
+ "permissions": ["nativeMessaging", "activeTab"],
7
+ "host_permissions": [
8
+ "https://chatgpt.com/*",
9
+ "https://chat.openai.com/*",
10
+ "https://claude.ai/*",
11
+ "https://kimi.com/*",
12
+ "https://www.kimi.com/*",
13
+ "https://kimi.moonshot.cn/*",
14
+ "https://perplexity.ai/*",
15
+ "https://www.perplexity.ai/*"
16
+ ],
17
+ "background": {
18
+ "service_worker": "src/background.js",
19
+ "type": "module"
20
+ },
21
+ "content_scripts": [
22
+ {
23
+ "matches": [
24
+ "https://chatgpt.com/*",
25
+ "https://chat.openai.com/*",
26
+ "https://claude.ai/*",
27
+ "https://kimi.com/*",
28
+ "https://www.kimi.com/*",
29
+ "https://kimi.moonshot.cn/*",
30
+ "https://perplexity.ai/*",
31
+ "https://www.perplexity.ai/*"
32
+ ],
33
+ "js": ["src/content-script.js"],
34
+ "run_at": "document_idle"
35
+ }
36
+ ],
37
+ "action": {
38
+ "default_title": "Enigma local memory"
39
+ },
40
+ "minimum_chrome_version": "116"
41
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ detectProviderFromUrl,
3
+ recordInsertionReceipt,
4
+ requestContextPack,
5
+ serializeError
6
+ } from './native-bridge.js';
7
+
8
+ const MESSAGE_SOURCE = 'enigma-browser-extension';
9
+ const CONTENT_SOURCE = 'enigma-content-script';
10
+
11
+ chrome.runtime.onInstalled.addListener(() => {
12
+ chrome.action.setBadgeText({ text: '' });
13
+ });
14
+
15
+ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
16
+ if (changeInfo.status !== 'complete') return;
17
+ const provider = detectProviderFromUrl(tab.url);
18
+ chrome.action.setBadgeText({ tabId, text: provider ? 'E' : '' });
19
+ chrome.action.setTitle({ tabId, title: provider ? `Enigma local memory for ${provider.label}` : 'Enigma local memory' });
20
+ });
21
+
22
+ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
23
+ if (!isContentMessage(message)) return false;
24
+
25
+ handleContentMessage(message, sender)
26
+ .then((result) => sendResponse({ ok: true, ...result }))
27
+ .catch((error) => {
28
+ const safeError = serializeError(error);
29
+ sendResponse({ ok: false, error: safeError.message });
30
+ });
31
+
32
+ return true;
33
+ });
34
+
35
+ async function handleContentMessage(message, sender) {
36
+ const tabUrl = sender.tab?.url || message.page?.url;
37
+ const provider = detectProviderFromUrl(tabUrl);
38
+ if (!provider) throw new Error('Unsupported or unknown AI provider page.');
39
+ if (message.provider !== provider.id) throw new Error('Message provider does not match the active page.');
40
+
41
+ if (message.kind === 'enigma.context.request') {
42
+ return {
43
+ kind: 'enigma.context.response',
44
+ provider: provider.id,
45
+ payload: await requestContextPack({
46
+ providerId: provider.id,
47
+ url: tabUrl,
48
+ title: sender.tab?.title || message.page?.title || '',
49
+ topLevel: sender.frameId === 0,
50
+ selection: message.selection
51
+ })
52
+ };
53
+ }
54
+
55
+ if (message.kind === 'enigma.insertion.record') {
56
+ return {
57
+ kind: 'enigma.insertion.recorded',
58
+ provider: provider.id,
59
+ payload: await recordInsertionReceipt({
60
+ providerId: provider.id,
61
+ url: tabUrl,
62
+ title: sender.tab?.title || message.page?.title || '',
63
+ topLevel: sender.frameId === 0,
64
+ receipt: message.receipt,
65
+ insertedCharCount: message.insertedCharCount,
66
+ mode: message.mode,
67
+ target: message.target,
68
+ insertedAt: new Date().toISOString()
69
+ })
70
+ };
71
+ }
72
+
73
+ if (message.kind === 'enigma.provider.detected') {
74
+ return { kind: 'enigma.provider.ack', provider: provider.id };
75
+ }
76
+
77
+ throw new Error('Unsupported Enigma extension message.');
78
+ }
79
+
80
+ function isContentMessage(message) {
81
+ return Boolean(
82
+ message &&
83
+ typeof message === 'object' &&
84
+ message.source === CONTENT_SOURCE &&
85
+ message.protocol === MESSAGE_SOURCE &&
86
+ typeof message.kind === 'string'
87
+ );
88
+ }