@adhdev/daemon-core 0.8.20 → 0.8.22
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.js +26 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -32
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +33 -12
package/package.json
CHANGED
|
@@ -90,6 +90,31 @@ function isRecentDuplicateSend(key: string): boolean {
|
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
function parseMaybeJson(value: any): any {
|
|
94
|
+
if (typeof value !== 'string') return value;
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(value);
|
|
97
|
+
} catch {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function didProviderConfirmSend(result: any): boolean {
|
|
103
|
+
const parsed = parseMaybeJson(result);
|
|
104
|
+
if (parsed === true) return true;
|
|
105
|
+
if (typeof parsed === 'string') {
|
|
106
|
+
const normalized = parsed.trim().toLowerCase();
|
|
107
|
+
return normalized === 'ok' || normalized === 'sent' || normalized === 'success' || normalized === 'true';
|
|
108
|
+
}
|
|
109
|
+
if (!parsed || typeof parsed !== 'object') return false;
|
|
110
|
+
|
|
111
|
+
return parsed.sent === true
|
|
112
|
+
|| parsed.success === true
|
|
113
|
+
|| parsed.ok === true
|
|
114
|
+
|| parsed.submitted === true
|
|
115
|
+
|| parsed.dispatched === true;
|
|
116
|
+
}
|
|
117
|
+
|
|
93
118
|
export async function handleChatHistory(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
94
119
|
const { agentType, offset, limit } = args;
|
|
95
120
|
const historySessionId = getHistorySessionId(h, args);
|
|
@@ -280,9 +305,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
280
305
|
try {
|
|
281
306
|
const evalResult = await h.evaluateProviderScript('sendMessage', { MESSAGE: text }, 30000);
|
|
282
307
|
if (evalResult?.result) {
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
if (parsed?.sent) {
|
|
308
|
+
const parsed = parseMaybeJson(evalResult.result);
|
|
309
|
+
if (didProviderConfirmSend(parsed)) {
|
|
286
310
|
_log(`Extension script sent OK`);
|
|
287
311
|
return _logSendSuccess('extension-script');
|
|
288
312
|
}
|
|
@@ -318,9 +342,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
318
342
|
if (sendScript) {
|
|
319
343
|
try {
|
|
320
344
|
const result = await targetCdp.evaluate(sendScript, 30000);
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
if (parsed?.sent) {
|
|
345
|
+
const parsed: any = parseMaybeJson(result);
|
|
346
|
+
if (didProviderConfirmSend(parsed)) {
|
|
324
347
|
_log(`sendMessage script OK`);
|
|
325
348
|
return _logSendSuccess('script');
|
|
326
349
|
}
|
|
@@ -365,9 +388,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
365
388
|
const matchText = provider.webviewMatchText;
|
|
366
389
|
const matchFn = matchText ? (body: string) => body.includes(matchText) : undefined;
|
|
367
390
|
const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
|
|
368
|
-
|
|
369
|
-
if (
|
|
370
|
-
if (wvParsed?.sent) {
|
|
391
|
+
const wvParsed: any = parseMaybeJson(wvResult);
|
|
392
|
+
if (didProviderConfirmSend(wvParsed)) {
|
|
371
393
|
_log(`webviewSendMessage OK`);
|
|
372
394
|
return _logSendSuccess('webview-script');
|
|
373
395
|
}
|
|
@@ -390,9 +412,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
390
412
|
const matchText = provider.webviewMatchText;
|
|
391
413
|
const matchFn = matchText ? (body: string) => body.includes(matchText) : undefined;
|
|
392
414
|
const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
|
|
393
|
-
|
|
394
|
-
if (
|
|
395
|
-
if (wvParsed?.sent) {
|
|
415
|
+
const wvParsed: any = parseMaybeJson(wvResult);
|
|
416
|
+
if (didProviderConfirmSend(wvParsed)) {
|
|
396
417
|
_log(`webviewSendMessage OK`);
|
|
397
418
|
return _logSendSuccess('webview-script');
|
|
398
419
|
}
|