@adhdev/daemon-core 0.5.21 → 0.5.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +66 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/agent-stream/manager.ts +7 -7
- package/src/cdp/devtools.ts +3 -3
- package/src/cdp/manager.ts +66 -0
- package/src/commands/handler.ts +1 -1
- package/src/commands/stream-commands.ts +1 -1
package/package.json
CHANGED
|
@@ -145,7 +145,7 @@ export class DaemonAgentStreamManager {
|
|
|
145
145
|
} else {
|
|
146
146
|
try {
|
|
147
147
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
148
|
-
cdp.
|
|
148
|
+
cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
|
|
149
149
|
const state = await agent.adapter.readChat(evaluate);
|
|
150
150
|
agent.lastState = state;
|
|
151
151
|
agent.lastError = null;
|
|
@@ -183,7 +183,7 @@ export class DaemonAgentStreamManager {
|
|
|
183
183
|
if (!agent) return false;
|
|
184
184
|
try {
|
|
185
185
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
186
|
-
cdp.
|
|
186
|
+
cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
|
|
187
187
|
await agent.adapter.sendMessage(evaluate, text);
|
|
188
188
|
return true;
|
|
189
189
|
} catch (e) {
|
|
@@ -198,7 +198,7 @@ export class DaemonAgentStreamManager {
|
|
|
198
198
|
if (!agent) return false;
|
|
199
199
|
try {
|
|
200
200
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
201
|
-
cdp.
|
|
201
|
+
cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
|
|
202
202
|
return await agent.adapter.resolveAction(evaluate, action);
|
|
203
203
|
} catch (e) {
|
|
204
204
|
this.logFn(`[AgentStream] resolveAction(${agentType}) error: ${(e as Error).message}`);
|
|
@@ -212,7 +212,7 @@ export class DaemonAgentStreamManager {
|
|
|
212
212
|
if (!agent) return false;
|
|
213
213
|
try {
|
|
214
214
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
215
|
-
cdp.
|
|
215
|
+
cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
|
|
216
216
|
await agent.adapter.newSession(evaluate);
|
|
217
217
|
return true;
|
|
218
218
|
} catch (e) {
|
|
@@ -233,7 +233,7 @@ export class DaemonAgentStreamManager {
|
|
|
233
233
|
if (!agent || typeof agent.adapter.listChats !== 'function') return [];
|
|
234
234
|
try {
|
|
235
235
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
236
|
-
cdp.
|
|
236
|
+
cdp.evaluateInSessionFrame(agent!.sessionId, expr, timeout);
|
|
237
237
|
return await agent.adapter.listChats(evaluate);
|
|
238
238
|
} catch (e) {
|
|
239
239
|
this.logFn(`[AgentStream] listChats(${agentType}) error: ${(e as Error).message}`);
|
|
@@ -252,7 +252,7 @@ export class DaemonAgentStreamManager {
|
|
|
252
252
|
if (!agent || typeof agent.adapter.switchSession !== 'function') return false;
|
|
253
253
|
try {
|
|
254
254
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
255
|
-
cdp.
|
|
255
|
+
cdp.evaluateInSessionFrame(agent!.sessionId, expr, timeout);
|
|
256
256
|
return await agent.adapter.switchSession(evaluate, sessionId);
|
|
257
257
|
} catch (e) {
|
|
258
258
|
this.logFn(`[AgentStream] switchSession(${agentType}) error: ${(e as Error).message}`);
|
|
@@ -265,7 +265,7 @@ export class DaemonAgentStreamManager {
|
|
|
265
265
|
if (!agent || typeof agent.adapter.focusEditor !== 'function') return false;
|
|
266
266
|
try {
|
|
267
267
|
const evaluate: AgentEvaluateFn = (expr, timeout) =>
|
|
268
|
-
cdp.
|
|
268
|
+
cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
|
|
269
269
|
await agent.adapter.focusEditor(evaluate);
|
|
270
270
|
return true;
|
|
271
271
|
} catch (e) {
|
package/src/cdp/devtools.ts
CHANGED
|
@@ -115,7 +115,7 @@ export class CdpDomHandlers {
|
|
|
115
115
|
|
|
116
116
|
let result;
|
|
117
117
|
if (sessionId) {
|
|
118
|
-
result = await this.getCdp()!.
|
|
118
|
+
result = await this.getCdp()!.evaluateInSessionFrame(sessionId, expression);
|
|
119
119
|
} else {
|
|
120
120
|
result = await this.getCdp()!.evaluate(expression, 30000);
|
|
121
121
|
}
|
|
@@ -182,7 +182,7 @@ export class CdpDomHandlers {
|
|
|
182
182
|
try {
|
|
183
183
|
let raw;
|
|
184
184
|
if (sessionId) {
|
|
185
|
-
raw = await this.getCdp()!.
|
|
185
|
+
raw = await this.getCdp()!.evaluateInSessionFrame(sessionId, expression);
|
|
186
186
|
} else {
|
|
187
187
|
raw = await this.getCdp()!.evaluate(expression, 15000);
|
|
188
188
|
}
|
|
@@ -321,7 +321,7 @@ export class CdpDomHandlers {
|
|
|
321
321
|
try {
|
|
322
322
|
let raw;
|
|
323
323
|
if (sessionId) {
|
|
324
|
-
raw = await this.getCdp()!.
|
|
324
|
+
raw = await this.getCdp()!.evaluateInSessionFrame(sessionId, expression);
|
|
325
325
|
} else {
|
|
326
326
|
raw = await this.getCdp()!.evaluate(expression, 30000);
|
|
327
327
|
}
|
package/src/cdp/manager.ts
CHANGED
|
@@ -839,6 +839,72 @@ export class DaemonCdpManager {
|
|
|
839
839
|
});
|
|
840
840
|
}
|
|
841
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Evaluate inside the child frame of an attached session.
|
|
844
|
+
* Extension webviews have a nested iframe structure:
|
|
845
|
+
* outer (vscode-webview://) → inner (extension React app)
|
|
846
|
+
* This method navigates into the inner frame using CDP Page.getFrameTree.
|
|
847
|
+
* Falls back to evaluateInSession if no child frame is found.
|
|
848
|
+
*/
|
|
849
|
+
async evaluateInSessionFrame(sessionId: string, expression: string, timeoutMs = 15000): Promise<unknown> {
|
|
850
|
+
const ws = this._browserConnected ? this.browserWs : this.ws;
|
|
851
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
852
|
+
throw new Error('CDP not connected');
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const sendViaSession = (method: string, params: Record<string, unknown> = {}): Promise<any> => {
|
|
856
|
+
return new Promise((resolve, reject) => {
|
|
857
|
+
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
858
|
+
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
859
|
+
pendingMap.set(id, { resolve, reject });
|
|
860
|
+
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
861
|
+
setTimeout(() => {
|
|
862
|
+
if (pendingMap.has(id)) {
|
|
863
|
+
pendingMap.delete(id);
|
|
864
|
+
reject(new Error(`CDP session timeout: ${method}`));
|
|
865
|
+
}
|
|
866
|
+
}, timeoutMs);
|
|
867
|
+
});
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
try {
|
|
871
|
+
// 1. Get frame tree to find child frame
|
|
872
|
+
const { frameTree } = await sendViaSession('Page.getFrameTree');
|
|
873
|
+
const childFrame = frameTree?.childFrames?.[0]?.frame;
|
|
874
|
+
|
|
875
|
+
if (!childFrame) {
|
|
876
|
+
// No child frame — fall back to outer frame evaluation
|
|
877
|
+
return this.evaluateInSession(sessionId, expression, timeoutMs);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// 2. Create isolated world in the child frame
|
|
881
|
+
const { executionContextId } = await sendViaSession('Page.createIsolatedWorld', {
|
|
882
|
+
frameId: childFrame.id,
|
|
883
|
+
worldName: 'adhdev-agent-eval',
|
|
884
|
+
grantUniveralAccess: true,
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// 3. Evaluate expression in isolated world
|
|
888
|
+
const result = await sendViaSession('Runtime.evaluate', {
|
|
889
|
+
expression,
|
|
890
|
+
returnByValue: true,
|
|
891
|
+
awaitPromise: true,
|
|
892
|
+
contextId: executionContextId,
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
if (result?.result?.subtype === 'error') {
|
|
896
|
+
throw new Error(result.result.description);
|
|
897
|
+
}
|
|
898
|
+
return result?.result?.value;
|
|
899
|
+
} catch (e) {
|
|
900
|
+
// On Page.getFrameTree failure, fall back to direct session evaluation
|
|
901
|
+
if ((e as Error).message?.includes('getFrameTree')) {
|
|
902
|
+
return this.evaluateInSession(sessionId, expression, timeoutMs);
|
|
903
|
+
}
|
|
904
|
+
throw e;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
842
908
|
async detachAgent(sessionId: string): Promise<void> {
|
|
843
909
|
try {
|
|
844
910
|
const sendFn = this._browserConnected ? this.sendBrowser.bind(this) : this.sendInternal.bind(this);
|
package/src/commands/handler.ts
CHANGED
|
@@ -155,7 +155,7 @@ export class DaemonCommandHandler implements CommandHelpers {
|
|
|
155
155
|
sessionId = this.getExtensionSessionId(provider);
|
|
156
156
|
}
|
|
157
157
|
if (!sessionId) return null;
|
|
158
|
-
const result = await cdp.
|
|
158
|
+
const result = await cdp.evaluateInSessionFrame(sessionId, script, timeout);
|
|
159
159
|
return { result, category: 'extension' };
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -252,7 +252,7 @@ export async function handleExtensionScript(h: CommandHelpers, args: any, script
|
|
|
252
252
|
if (!targetSessionId) {
|
|
253
253
|
return { success: false, error: `No active session found for ${agentType}` };
|
|
254
254
|
}
|
|
255
|
-
result = await cdp.
|
|
255
|
+
result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
|
|
256
256
|
} else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
|
|
257
257
|
const matchText = provider.webviewMatchText;
|
|
258
258
|
const matchFn = matchText ? (body: string) => body.includes(matchText) : undefined;
|