-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-snippet-create.ts
More file actions
150 lines (125 loc) · 4.27 KB
/
test-snippet-create.ts
File metadata and controls
150 lines (125 loc) · 4.27 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function main() {
const conn = await connectToSuperhuman(9333);
if (!conn) { console.log("No connection"); process.exit(1); }
// First, let's see the current snippets state
const currentState = await conn.Runtime.evaluate({
expression: `
(() => {
const ga = window.GoogleAccount;
const settings = ga?.settings;
return {
snippets: settings?.get?.('snippets'),
snippetsLastUsed: settings?.get?.('snippetsLastUsed')
};
})()
`,
returnByValue: true,
});
console.log("=== Current State ===\n");
console.log(JSON.stringify(currentState.result.value, null, 2));
// Try to create a test snippet using settings.set
// First, let's understand the structure by looking at how applySnippet works
const snippetStructure = await conn.Runtime.evaluate({
expression: `
(() => {
// Look for Snippet class or constructor
const ga = window.GoogleAccount;
// Check if there's a Snippet model
const classes = [];
for (const key of Object.keys(window)) {
if (key.includes('Snippet') && typeof window[key] === 'function') {
classes.push(key);
}
}
// Check the compose controller for snippet structure hints
const vs = window.ViewState;
// Look for any cached snippet type definitions
let snippetTypeHint = null;
try {
// Check if we can find snippet references in the code
const settings = ga?.settings;
const proto = Object.getPrototypeOf(settings);
const setSource = settings.set?.toString?.();
snippetTypeHint = setSource?.slice(0, 500);
} catch (e) {}
return {
snippetClasses: classes,
snippetTypeHint
};
})()
`,
returnByValue: true,
});
console.log("\n=== Snippet Structure Hints ===\n");
console.log(JSON.stringify(snippetStructure.result.value, null, 2));
// Now let's try to set a snippet and observe what happens
console.log("\n=== Attempting to Create Test Snippet ===\n");
// Generate a unique ID (similar to how Superhuman might generate IDs)
const testSnippetId = 'test_' + Date.now().toString(36);
const createResult = await conn.Runtime.evaluate({
expression: `
(async () => {
const ga = window.GoogleAccount;
const settings = ga?.settings;
if (!settings) return { error: "no settings" };
// Get current snippets
const currentSnippets = settings.get('snippets') || {};
// Create a test snippet - guessing the structure based on common patterns
const testSnippet = {
shortcut: 'test1',
body: 'This is a test snippet body.',
subject: 'Test Subject',
to: [],
cc: [],
bcc: []
};
const testId = '${testSnippetId}';
// Add to snippets
const newSnippets = {
...currentSnippets,
[testId]: testSnippet
};
try {
// Try setting the snippets
await settings.set('snippets', newSnippets);
// Verify it was saved
const afterSnippets = settings.get('snippets');
return {
success: true,
testId,
afterSnippets: JSON.stringify(afterSnippets)
};
} catch (e) {
return {
success: false,
error: e.message,
stack: e.stack?.slice(0, 500)
};
}
})()
`,
awaitPromise: true,
returnByValue: true,
});
console.log(JSON.stringify(createResult.result.value, null, 2));
// Check if the snippet was persisted
await new Promise(r => setTimeout(r, 1000));
const verifyResult = await conn.Runtime.evaluate({
expression: `
(() => {
const ga = window.GoogleAccount;
const settings = ga?.settings;
return {
snippets: settings?.get?.('snippets'),
cacheSnippets: settings?._cache?.snippets
};
})()
`,
returnByValue: true,
});
console.log("\n=== Verification After 1 Second ===\n");
console.log(JSON.stringify(verifyResult.result.value, null, 2));
await disconnect(conn);
}
main().catch(console.error);