@adhdev/daemon-standalone 0.8.21 → 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 CHANGED
@@ -34009,6 +34009,24 @@ ${data.message || ""}`.trim();
34009
34009
  recentSendByTarget.set(key, now);
34010
34010
  return false;
34011
34011
  }
34012
+ function parseMaybeJson(value) {
34013
+ if (typeof value !== "string") return value;
34014
+ try {
34015
+ return JSON.parse(value);
34016
+ } catch {
34017
+ return value;
34018
+ }
34019
+ }
34020
+ function didProviderConfirmSend(result) {
34021
+ const parsed = parseMaybeJson(result);
34022
+ if (parsed === true) return true;
34023
+ if (typeof parsed === "string") {
34024
+ const normalized = parsed.trim().toLowerCase();
34025
+ return normalized === "ok" || normalized === "sent" || normalized === "success" || normalized === "true";
34026
+ }
34027
+ if (!parsed || typeof parsed !== "object") return false;
34028
+ return parsed.sent === true || parsed.success === true || parsed.ok === true || parsed.submitted === true || parsed.dispatched === true;
34029
+ }
34012
34030
  async function handleChatHistory(h, args) {
34013
34031
  const { agentType, offset, limit } = args;
34014
34032
  const historySessionId = getHistorySessionId(h, args);
@@ -34191,14 +34209,8 @@ ${data.message || ""}`.trim();
34191
34209
  try {
34192
34210
  const evalResult = await h.evaluateProviderScript("sendMessage", { MESSAGE: text }, 3e4);
34193
34211
  if (evalResult?.result) {
34194
- let parsed = evalResult.result;
34195
- if (typeof parsed === "string") {
34196
- try {
34197
- parsed = JSON.parse(parsed);
34198
- } catch {
34199
- }
34200
- }
34201
- if (parsed?.sent) {
34212
+ const parsed = parseMaybeJson(evalResult.result);
34213
+ if (didProviderConfirmSend(parsed)) {
34202
34214
  _log(`Extension script sent OK`);
34203
34215
  return _logSendSuccess("extension-script");
34204
34216
  }
@@ -34230,14 +34242,8 @@ ${data.message || ""}`.trim();
34230
34242
  if (sendScript) {
34231
34243
  try {
34232
34244
  const result = await targetCdp.evaluate(sendScript, 3e4);
34233
- let parsed = result;
34234
- if (typeof result === "string") {
34235
- try {
34236
- parsed = JSON.parse(result);
34237
- } catch {
34238
- }
34239
- }
34240
- if (parsed?.sent) {
34245
+ const parsed = parseMaybeJson(result);
34246
+ if (didProviderConfirmSend(parsed)) {
34241
34247
  _log(`sendMessage script OK`);
34242
34248
  return _logSendSuccess("script");
34243
34249
  }
@@ -34282,14 +34288,8 @@ ${data.message || ""}`.trim();
34282
34288
  const matchText = provider.webviewMatchText;
34283
34289
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
34284
34290
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
34285
- let wvParsed = wvResult;
34286
- if (typeof wvResult === "string") {
34287
- try {
34288
- wvParsed = JSON.parse(wvResult);
34289
- } catch {
34290
- }
34291
- }
34292
- if (wvParsed?.sent) {
34291
+ const wvParsed = parseMaybeJson(wvResult);
34292
+ if (didProviderConfirmSend(wvParsed)) {
34293
34293
  _log(`webviewSendMessage OK`);
34294
34294
  return _logSendSuccess("webview-script");
34295
34295
  }
@@ -34311,14 +34311,8 @@ ${data.message || ""}`.trim();
34311
34311
  const matchText = provider.webviewMatchText;
34312
34312
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
34313
34313
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
34314
- let wvParsed = wvResult;
34315
- if (typeof wvResult === "string") {
34316
- try {
34317
- wvParsed = JSON.parse(wvResult);
34318
- } catch {
34319
- }
34320
- }
34321
- if (wvParsed?.sent) {
34314
+ const wvParsed = parseMaybeJson(wvResult);
34315
+ if (didProviderConfirmSend(wvParsed)) {
34322
34316
  _log(`webviewSendMessage OK`);
34323
34317
  return _logSendSuccess("webview-script");
34324
34318
  }