-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdraft-check-final.ts
More file actions
77 lines (61 loc) · 2.28 KB
/
draft-check-final.ts
File metadata and controls
77 lines (61 loc) · 2.28 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
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function draftAndCheck() {
const conn = await connectToSuperhuman(9333, true);
if (!conn) return;
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
try {
const threadId = "19c1fddba41e2a6e";
const bodyText = "Hi Robert and Jon, drafting a test reply from the CLI to verify the draft key collision fix again.";
const tree = window.ViewState?.tree;
if (tree?.set) {
tree.set(['threadPane', 'threadId'], threadId);
tree.set(['threadListView', 'threadId'], threadId);
}
await new Promise(r => setTimeout(r, 500));
const rc = window.ViewState?.regionalCommands;
let replyCmd = null;
for (const region of rc) {
if (region?.commands) {
replyCmd = region.commands.find(c => c.id === "REPLY_POP_OUT");
if (replyCmd) break;
}
}
if (replyCmd) {
replyCmd.action({ preventDefault: () => {}, stopPropagation: () => {} });
} else {
return { error: "REPLY_POP_OUT not found" };
}
// Wait for compose
await new Promise(r => setTimeout(r, 2000));
const cfc = window.ViewState?._composeFormController;
const keys = Object.keys(cfc).filter(k => k.startsWith('draft'));
const newDraftKey = keys[keys.length - 1]; // Assume last created for debug
const ctrl = cfc[newDraftKey];
const html = "<p>" + bodyText + "</p>";
await ctrl._updateDraft({ body: html });
if (ctrl.state?.draft) {
ctrl.state.draft.body = html;
}
if (typeof ctrl._saveDraftAsync === 'function') {
await ctrl._saveDraftAsync();
}
return {
success: true,
keys,
newDraftKey,
body: ctrl.state?.draft?.body
};
} catch (e) {
return { error: e.message };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
draftAndCheck();