-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexplore-ai-compose.ts
More file actions
244 lines (196 loc) · 7.22 KB
/
explore-ai-compose.ts
File metadata and controls
244 lines (196 loc) · 7.22 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
/**
* Explore the aiCompose and related backend methods
*/
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function main() {
console.log("=== Exploring AI Compose Methods ===\n");
const conn = await connectToSuperhuman(9333);
if (!conn) {
console.error("Failed to connect");
process.exit(1);
}
const { Runtime } = conn;
// Inspect the backend's AI methods
console.log("1. Inspecting backend AI methods...\n");
const backendInspect = await Runtime.evaluate({
expression: `
(() => {
const results = {};
const ga = window.GoogleAccount;
const backend = ga?.backend;
if (!backend) return { error: 'No backend found' };
// Get the prototype to see method signatures
const proto = Object.getPrototypeOf(backend);
const aiMethods = ['aiCompose', 'aiComposeEdit', 'aiComposeAgentic', 'getAICalendarDetails'];
for (const method of aiMethods) {
if (proto[method]) {
results[method] = {
exists: true,
signature: proto[method].toString().substring(0, 500)
};
}
}
return results;
})()
`,
returnByValue: true
});
console.log("Backend AI methods:", JSON.stringify(backendInspect.result.value, null, 2));
// Look for the AI service that handles Ask AI
console.log("\n2. Looking for AI sidebar/service...\n");
const aiServiceSearch = await Runtime.evaluate({
expression: `
(() => {
const results = {};
const ga = window.GoogleAccount;
// Search for any property that contains 'ai' or 'ask'
function searchObj(obj, path, depth = 0) {
if (depth > 4 || !obj || typeof obj !== 'object') return;
try {
const keys = Object.keys(obj);
for (const key of keys) {
if (key.toLowerCase().includes('askai') ||
key.toLowerCase().includes('sidebar') && key.toLowerCase().includes('ai')) {
results[path + '.' + key] = {
type: typeof obj[key],
keys: typeof obj[key] === 'object' ? Object.keys(obj[key] || {}).slice(0, 20) : null
};
}
}
} catch {}
}
searchObj(ga, 'GoogleAccount');
searchObj(window.ViewState, 'ViewState');
return results;
})()
`,
returnByValue: true
});
console.log("AI service search:", JSON.stringify(aiServiceSearch.result.value, null, 2));
// Look for the shortId implementation in the backend source
console.log("\n3. Searching backend source for shortId...\n");
const shortIdSource = await Runtime.evaluate({
expression: `
(() => {
const results = {};
const ga = window.GoogleAccount;
const backend = ga?.backend;
if (backend) {
// Search through all methods
const proto = Object.getPrototypeOf(backend);
for (const methodName of Object.getOwnPropertyNames(proto)) {
try {
const method = proto[methodName];
if (typeof method === 'function') {
const str = method.toString();
if (str.includes('shortId') || str.includes('event_') || str.includes('generateId')) {
results[methodName] = str.substring(0, 300);
}
}
} catch {}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("shortId in backend:", JSON.stringify(shortIdSource.result.value, null, 2));
// Check if there's a separate shortId module/utility
console.log("\n4. Looking for shortId utility...\n");
const utilitySearch = await Runtime.evaluate({
expression: `
(() => {
const results = {};
// Check if there's a global shortId function
if (typeof shortId === 'function') {
results.globalShortId = shortId.toString();
}
// Look in common utility locations
const ga = window.GoogleAccount;
// Check if backend has a shortId generator we can call
if (ga?.backend?.shortId) {
results.backendShortId = ga.backend.shortId.toString();
}
// Look for a static method
if (ga?.Backend?.shortId) {
results.BackendStaticShortId = ga.Backend.shortId.toString();
}
// Check constructors
if (ga?.backend?.constructor?.shortId) {
results.constructorShortId = ga.backend.constructor.shortId.toString();
}
// Try to find it in the prototype chain
let proto = ga?.backend;
let depth = 0;
while (proto && depth < 5) {
if (proto.shortId) {
results['proto' + depth + '.shortId'] = proto.shortId.toString().substring(0, 200);
}
proto = Object.getPrototypeOf(proto);
depth++;
}
return results;
})()
`,
returnByValue: true
});
console.log("Utility search:", JSON.stringify(utilitySearch.result.value, null, 2));
// Try calling the aiCompose method to see how it generates IDs
console.log("\n5. Inspecting AI compose call flow...\n");
const aiComposeInspect = await Runtime.evaluate({
expression: `
(() => {
const results = {};
const ga = window.GoogleAccount;
const backend = ga?.backend;
// Find the aiCompose method and trace its dependencies
const aiCompose = Object.getPrototypeOf(backend)?.aiCompose;
if (aiCompose) {
const source = aiCompose.toString();
results.aiComposeSource = source;
// Look for any ID-related calls in the source
const idPatterns = source.match(/[a-zA-Z_]+[Ii]d[^a-zA-Z]/g);
results.idPatterns = [...new Set(idPatterns || [])];
}
return results;
})()
`,
returnByValue: true
});
console.log("AI compose inspection:", JSON.stringify(aiComposeInspect.result.value, null, 2));
// Look for the actual network call implementation
console.log("\n6. Tracing network request generation...\n");
const networkTrace = await Runtime.evaluate({
expression: `
(() => {
const results = {};
// Look for the API client that makes the actual requests
const ga = window.GoogleAccount;
// Check for a fetcher or API client
if (ga?.fetcher) {
const fetcherProto = Object.getPrototypeOf(ga.fetcher);
const methods = Object.getOwnPropertyNames(fetcherProto);
results.fetcherMethods = methods;
// Look for methods that might generate event IDs
for (const method of methods) {
try {
const fn = fetcherProto[method];
if (typeof fn === 'function') {
const str = fn.toString();
if (str.includes('event_') || str.includes('eventId') || str.includes('question')) {
results[method + '_source'] = str.substring(0, 400);
}
}
} catch {}
}
}
return results;
})()
`,
returnByValue: true
});
console.log("Network trace:", JSON.stringify(networkTrace.result.value, null, 2));
await disconnect(conn);
}
main().catch(console.error);