-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexplore-ai-service.ts
More file actions
301 lines (252 loc) · 9.28 KB
/
explore-ai-service.ts
File metadata and controls
301 lines (252 loc) · 9.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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/**
* Deep exploration of Ask AI service in Superhuman
*/
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function main() {
console.log("=== Ask AI Service Exploration ===\n");
const conn = await connectToSuperhuman(9333);
if (!conn) {
console.error("Failed to connect to Superhuman");
process.exit(1);
}
const { Runtime } = conn;
// First, list all AI-related services
console.log("1. Finding AI-related services...\n");
const services = await Runtime.evaluate({
expression: `
(() => {
const ga = window.GoogleAccount;
const di = ga?.di;
if (!di?._services) return { error: 'No DI services found' };
const aiServices = Object.keys(di._services).filter(k =>
k.toLowerCase().includes('ai') ||
k.toLowerCase().includes('ask') ||
k.toLowerCase().includes('agent') ||
k.toLowerCase().includes('sidebar')
);
return { aiServices };
})()
`,
returnByValue: true
});
console.log("AI-related services:", JSON.stringify(services.result.value, null, 2));
// Now explore each AI service
console.log("\n2. Exploring AI services...\n");
const exploration = await Runtime.evaluate({
expression: `
(async () => {
const ga = window.GoogleAccount;
const di = ga?.di;
const results = {};
const serviceNames = ['askAI', 'AIService', 'aiService', 'sidebarAI', 'sidebarAgent', 'SidebarAIAgent', 'ai', 'AIAgent'];
for (const name of serviceNames) {
try {
const svc = di.get(name);
if (svc) {
results[name] = {
type: typeof svc,
keys: Object.keys(svc).slice(0, 30),
proto: Object.getOwnPropertyNames(Object.getPrototypeOf(svc)).slice(0, 20)
};
}
} catch (e) {
// Service not found
}
}
// Look for any service with 'ask' in method names
const allServices = Object.keys(di._services);
for (const svcName of allServices.slice(0, 100)) {
try {
const svc = di.get(svcName);
if (svc && typeof svc === 'object') {
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(svc) || {});
const hasAskMethod = methods.some(m =>
m.toLowerCase().includes('ask') ||
m.toLowerCase().includes('query') ||
m.toLowerCase().includes('send')
);
if (hasAskMethod) {
results[svcName + '_hasAskMethods'] = methods.filter(m =>
m.toLowerCase().includes('ask') ||
m.toLowerCase().includes('query') ||
m.toLowerCase().includes('send')
);
}
}
} catch {}
}
return results;
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log("Service exploration:", JSON.stringify(exploration.result.value, null, 2));
// Look for the ask AI presenter or controller
console.log("\n3. Looking for Ask AI presenter/controller...\n");
const presenter = await Runtime.evaluate({
expression: `
(() => {
const ga = window.GoogleAccount;
const di = ga?.di;
const results = {};
// Look for presenter services
const presenterServices = Object.keys(di._services).filter(k =>
k.toLowerCase().includes('presenter') ||
k.toLowerCase().includes('controller')
);
for (const name of presenterServices) {
try {
const svc = di.get(name);
if (svc) {
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(svc) || {});
if (methods.some(m => m.toLowerCase().includes('ai') || m.toLowerCase().includes('ask'))) {
results[name] = methods;
}
}
} catch {}
}
// Check ViewState for any AI-related state
const viewState = window.ViewState;
if (viewState) {
const aiKeys = Object.keys(viewState).filter(k =>
k.toLowerCase().includes('ai') ||
k.toLowerCase().includes('ask') ||
k.toLowerCase().includes('sidebar')
);
results.viewStateAIKeys = aiKeys;
}
return results;
})()
`,
returnByValue: true
});
console.log("Presenter exploration:", JSON.stringify(presenter.result.value, null, 2));
// Look for analytics events that might reveal event ID format
console.log("\n4. Checking analytics service for event tracking...\n");
const analytics = await Runtime.evaluate({
expression: `
(() => {
const ga = window.GoogleAccount;
const di = ga?.di;
const results = {};
try {
const analytics = di.get('analytics');
if (analytics) {
results.analyticsKeys = Object.keys(analytics).slice(0, 30);
results.analyticsMethods = Object.getOwnPropertyNames(Object.getPrototypeOf(analytics) || {});
// Check if there's an event queue or history
if (analytics._events) {
results.recentEvents = analytics._events.slice(-5);
}
if (analytics.events) {
results.eventsQueue = analytics.events.slice?.(-5);
}
}
} catch (e) {
results.error = e.message;
}
return results;
})()
`,
returnByValue: true
});
console.log("Analytics exploration:", JSON.stringify(analytics.result.value, null, 2));
// Try to find the shortId generator
console.log("\n5. Looking for ID generation utilities...\n");
const idGen = await Runtime.evaluate({
expression: `
(() => {
const results = {};
// Check for common ID generation patterns
// Look in require/module system
if (window.require) {
try {
const nanoid = window.require('nanoid');
if (nanoid) results.nanoidAvailable = true;
} catch {}
try {
const cuid = window.require('cuid');
if (cuid) results.cuidAvailable = true;
} catch {}
}
// Check if there's a shortId function somewhere
const ga = window.GoogleAccount;
const di = ga?.di;
// Search through services for ID-related functions
if (di?._services) {
for (const [name, svc] of Object.entries(di._services)) {
try {
const instance = di.get(name);
if (instance) {
// Look for generate* methods
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(instance) || {});
const genMethods = methods.filter(m =>
m.toLowerCase().includes('generate') ||
m.toLowerCase().includes('create') && m.toLowerCase().includes('id')
);
if (genMethods.length > 0) {
results[name + '_methods'] = genMethods;
}
}
} catch {}
}
}
// Check the team ID format for clues
const teamId = ga?.accountStore?.state?.account?.settings?._cache?.pseudoTeamId;
if (teamId) {
const suffix = teamId.replace('team_', '');
results.teamId = teamId;
results.teamIdSuffix = suffix;
results.teamIdSuffixLength = suffix.length;
}
return results;
})()
`,
returnByValue: true
});
console.log("ID generation exploration:", JSON.stringify(idGen.result.value, null, 2));
// Check if there's an open Ask AI sidebar we can inspect
console.log("\n6. Checking for open Ask AI sidebar state...\n");
const sidebarState = await Runtime.evaluate({
expression: `
(() => {
const results = {};
// Look for sidebar elements in DOM
const sidebar = document.querySelector('[class*="sidebar"]');
if (sidebar) {
results.sidebarFound = true;
results.sidebarClasses = sidebar.className;
}
// Look for AI chat elements
const aiChat = document.querySelector('[class*="ai"]') || document.querySelector('[class*="Ask"]');
if (aiChat) {
results.aiChatFound = true;
results.aiChatClasses = aiChat.className;
}
// Check ViewState for sidebar state
const viewState = window.ViewState;
if (viewState) {
for (const [key, value] of Object.entries(viewState)) {
if (key.toLowerCase().includes('sidebar') || key.toLowerCase().includes('ai')) {
results['viewState.' + key] = typeof value === 'object' ? Object.keys(value || {}).slice(0, 10) : typeof value;
}
}
}
// Look for React components that might have Ask AI state
const root = document.getElementById('root');
if (root) {
const fiberKey = Object.keys(root).find(k => k.startsWith('__reactFiber'));
if (fiberKey) {
results.reactFiberFound = true;
}
}
return results;
})()
`,
returnByValue: true
});
console.log("Sidebar state:", JSON.stringify(sidebarState.result.value, null, 2));
await disconnect(conn);
}
main().catch(console.error);