-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcheck-library-snippets.ts
More file actions
89 lines (78 loc) · 2.73 KB
/
check-library-snippets.ts
File metadata and controls
89 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function main() {
const conn = await connectToSuperhuman(9333);
if (!conn) { console.log("No connection"); process.exit(1); }
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
const account = window.ViewState?.account;
const settings = account?.settings;
const cache = settings?._cache || {};
// Check library object
const library = cache.library;
// Try to load snippets from backend
let loadedSnippets = null;
try {
// settings.loadFromRemote might refresh the cache
if (settings?.loadFromRemote) {
await settings.loadFromRemote();
loadedSnippets = settings.get('snippets');
}
} catch (e) {
loadedSnippets = { error: e.message };
}
// Check if there's a snippets service in DI
let snippetService = null;
const di = account?.di;
if (di) {
try {
const keys = [...(di._bindings?.keys?.() || [])];
const snippetKeys = keys.filter(k =>
k.toLowerCase().includes('snippet')
);
snippetService = { keys: snippetKeys };
// Try to get the snippet service
for (const key of snippetKeys) {
try {
const svc = di.get(key);
if (svc) {
snippetService[key] = {
type: typeof svc,
methods: Object.getOwnPropertyNames(Object.getPrototypeOf(svc)).slice(0, 20)
};
}
} catch (e) {}
}
} catch (e) {
snippetService = { error: e.message };
}
}
// Try portal.invoke to get snippets directly from backend
let backendSnippets = null;
try {
const portal = account?.portal;
if (portal) {
backendSnippets = await portal.invoke("backgroundSettings", "get", ["snippets"]);
}
} catch (e) {
backendSnippets = { error: e.message };
}
return {
currentEmail: account?.emailAddress,
libraryKeys: library ? Object.keys(library) : null,
libraryPreview: library ? JSON.stringify(library).slice(0, 500) : null,
loadedSnippets,
snippetService,
backendSnippets,
cacheSnippetsAfterLoad: settings?.get?.('snippets')
};
})()
`,
awaitPromise: true,
returnByValue: true,
});
console.log("=== Deep Search for Snippets ===\n");
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
main().catch(console.error);