-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfind-event-id-caller.ts
More file actions
259 lines (224 loc) · 8.79 KB
/
find-event-id-caller.ts
File metadata and controls
259 lines (224 loc) · 8.79 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* Find where questionEventId is generated in Superhuman
*/
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function main() {
console.log("=== Finding Event ID Generator ===\n");
const conn = await connectToSuperhuman(9333);
if (!conn) {
console.error("Failed to connect");
process.exit(1);
}
const { Runtime, client } = conn;
// Search webpack chunks more thoroughly
console.log("1. Deep searching webpack modules...\n");
const deepSearch = await Runtime.evaluate({
expression: `
(() => {
const results = { found: [], eventIdGenerators: [] };
// Search all webpack modules
if (window.webpackChunk_superhuman_desktop_webapp) {
for (const chunk of window.webpackChunk_superhuman_desktop_webapp) {
if (Array.isArray(chunk) && chunk[1]) {
for (const [moduleId, moduleFunc] of Object.entries(chunk[1])) {
try {
const funcStr = moduleFunc.toString();
// Look for questionEventId generation
if (funcStr.includes('questionEventId')) {
const idx = funcStr.indexOf('questionEventId');
const context = funcStr.substring(
Math.max(0, idx - 100),
Math.min(funcStr.length, idx + 200)
);
results.found.push({
moduleId,
context
});
}
// Look for shortId usage
if (funcStr.includes('shortId')) {
const idx = funcStr.indexOf('shortId');
const context = funcStr.substring(
Math.max(0, idx - 50),
Math.min(funcStr.length, idx + 150)
);
results.eventIdGenerators.push({
moduleId,
type: 'shortId',
context
});
}
// Look for event ID assignment
if (funcStr.includes('event_id=') || funcStr.includes('event_id:') ||
funcStr.includes('eventId=') || funcStr.includes('eventId:')) {
const patterns = [
/event_id\s*[=:]\s*[^,;\n]+/g,
/eventId\s*[=:]\s*[^,;\n]+/g
];
for (const pattern of patterns) {
const matches = funcStr.match(pattern);
if (matches) {
results.eventIdGenerators.push({
moduleId,
type: 'assignment',
matches: matches.slice(0, 3)
});
}
}
}
} catch {}
}
}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("Deep search results:");
console.log(" Found questionEventId references:", deepSearch.result.value.found.length);
for (const f of (deepSearch.result.value.found || []).slice(0, 5)) {
console.log(`\n Module ${f.moduleId}:`);
console.log(` ${f.context.replace(/\n/g, ' ')}`);
}
console.log("\n Event ID generators:", deepSearch.result.value.eventIdGenerators.length);
for (const g of (deepSearch.result.value.eventIdGenerators || []).slice(0, 5)) {
console.log(`\n Module ${g.moduleId} (${g.type}):`);
console.log(` ${JSON.stringify(g.matches || g.context).substring(0, 200)}`);
}
// Look specifically for shortId definition
console.log("\n\n2. Searching for shortId function definition...\n");
const shortIdDef = await Runtime.evaluate({
expression: `
(() => {
const results = [];
if (window.webpackChunk_superhuman_desktop_webapp) {
for (const chunk of window.webpackChunk_superhuman_desktop_webapp) {
if (Array.isArray(chunk) && chunk[1]) {
for (const [moduleId, moduleFunc] of Object.entries(chunk[1])) {
try {
const funcStr = moduleFunc.toString();
// Look for shortId function definition patterns
const patterns = [
/function\s+shortId/,
/shortId\s*=\s*function/,
/shortId\s*=\s*\([^)]*\)\s*=>/,
/const\s+shortId\s*=/,
/let\s+shortId\s*=/,
/var\s+shortId\s*=/,
/exports\.shortId\s*=/
];
for (const pattern of patterns) {
if (pattern.test(funcStr)) {
const match = funcStr.match(pattern);
if (match) {
const idx = match.index;
const context = funcStr.substring(idx, Math.min(funcStr.length, idx + 300));
results.push({
moduleId,
pattern: pattern.toString(),
context
});
}
}
}
} catch {}
}
}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("shortId definitions found:", shortIdDef.result.value.length);
for (const def of (shortIdDef.result.value || []).slice(0, 10)) {
console.log(`\nModule ${def.moduleId}:`);
console.log(` Pattern: ${def.pattern}`);
console.log(` Context: ${def.context.substring(0, 200).replace(/\n/g, ' ')}`);
}
// Look for the askAI proxy call site
console.log("\n\n3. Finding askAIProxy call site...\n");
const askAICallSite = await Runtime.evaluate({
expression: `
(() => {
const results = [];
if (window.webpackChunk_superhuman_desktop_webapp) {
for (const chunk of window.webpackChunk_superhuman_desktop_webapp) {
if (Array.isArray(chunk) && chunk[1]) {
for (const [moduleId, moduleFunc] of Object.entries(chunk[1])) {
try {
const funcStr = moduleFunc.toString();
if (funcStr.includes('askAIProxy') || funcStr.includes('ai.askAIProxy')) {
const idx = funcStr.indexOf('askAIProxy');
const context = funcStr.substring(
Math.max(0, idx - 200),
Math.min(funcStr.length, idx + 400)
);
results.push({
moduleId,
context
});
}
} catch {}
}
}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("askAIProxy call sites found:", askAICallSite.result.value.length);
for (const site of (askAICallSite.result.value || []).slice(0, 5)) {
console.log(`\nModule ${site.moduleId}:`);
console.log(` ${site.context.replace(/\n/g, ' ').substring(0, 500)}`);
}
// Check if shortId is being called with specific parameters
console.log("\n\n4. Analyzing shortId usage patterns...\n");
const shortIdUsage = await Runtime.evaluate({
expression: `
(() => {
const results = [];
if (window.webpackChunk_superhuman_desktop_webapp) {
for (const chunk of window.webpackChunk_superhuman_desktop_webapp) {
if (Array.isArray(chunk) && chunk[1]) {
for (const [moduleId, moduleFunc] of Object.entries(chunk[1])) {
try {
const funcStr = moduleFunc.toString();
// Look for shortId being called
const callPatterns = [
/shortId\s*\(\s*["'][^"']*["']\s*\)/g, // shortId("prefix")
/shortId\s*\(\s*\)/g, // shortId()
/shortId\s*\(\s*\d+\s*\)/g, // shortId(17)
];
for (const pattern of callPatterns) {
const matches = funcStr.match(pattern);
if (matches) {
results.push({
moduleId,
calls: matches.slice(0, 5)
});
}
}
} catch {}
}
}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("shortId usage found:", shortIdUsage.result.value.length);
for (const usage of (shortIdUsage.result.value || []).slice(0, 10)) {
console.log(`\nModule ${usage.moduleId}:`);
console.log(` Calls: ${JSON.stringify(usage.calls)}`);
}
await disconnect(conn);
}
main().catch(console.error);