@adhdev/daemon-core 0.9.8 → 0.9.10

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.mjs CHANGED
@@ -847,6 +847,18 @@ function validateRole(role, source, index) {
847
847
  }
848
848
  return role;
849
849
  }
850
+ function validateBubbleState(state, source, index) {
851
+ if (typeof state !== "string" || !VALID_BUBBLE_STATES.includes(state)) {
852
+ throw new Error(`${source}: messages[${index}].bubbleState must be one of ${VALID_BUBBLE_STATES.join(", ")}`);
853
+ }
854
+ return state;
855
+ }
856
+ function validateTurnStatus(turnStatus, source) {
857
+ if (typeof turnStatus !== "string" || !VALID_TURN_STATUSES.includes(turnStatus)) {
858
+ throw new Error(`${source}: turnStatus must be one of ${VALID_TURN_STATUSES.join(", ")}`);
859
+ }
860
+ return turnStatus;
861
+ }
850
862
  function validateMessageContent(content, source, index) {
851
863
  if (typeof content === "string") return content;
852
864
  if (Array.isArray(content)) return normalizeMessageParts(content);
@@ -862,6 +874,9 @@ function validateMessage(message, source, index) {
862
874
  };
863
875
  if (typeof message.kind === "string") normalized.kind = message.kind;
864
876
  if (typeof message.id === "string") normalized.id = message.id;
877
+ if (typeof message.bubbleId === "string") normalized.bubbleId = message.bubbleId;
878
+ if (typeof message.providerUnitKey === "string") normalized.providerUnitKey = message.providerUnitKey;
879
+ if (message.bubbleState !== void 0) normalized.bubbleState = validateBubbleState(message.bubbleState, source, index);
865
880
  if (isFiniteNumber(message.index)) normalized.index = message.index;
866
881
  if (isFiniteNumber(message.timestamp)) normalized.timestamp = message.timestamp;
867
882
  if (isFiniteNumber(message.receivedAt)) normalized.receivedAt = message.receivedAt;
@@ -929,6 +944,8 @@ function validateReadChatResultPayload(raw, source = "read_chat") {
929
944
  if (activeModal !== void 0) normalized.activeModal = activeModal;
930
945
  if (typeof raw.id === "string") normalized.id = raw.id;
931
946
  if (typeof raw.title === "string") normalized.title = raw.title;
947
+ if (typeof raw.currentTurnId === "string") normalized.currentTurnId = raw.currentTurnId;
948
+ if (raw.turnStatus !== void 0) normalized.turnStatus = validateTurnStatus(raw.turnStatus, source);
932
949
  if (typeof raw.agentType === "string") normalized.agentType = raw.agentType;
933
950
  if (typeof raw.agentName === "string") normalized.agentName = raw.agentName;
934
951
  if (typeof raw.extensionId === "string") normalized.extensionId = raw.extensionId;
@@ -941,13 +958,15 @@ function validateReadChatResultPayload(raw, source = "read_chat") {
941
958
  if (typeof raw.providerSessionId === "string") normalized.providerSessionId = raw.providerSessionId;
942
959
  return normalized;
943
960
  }
944
- var VALID_STATUSES, VALID_ROLES;
961
+ var VALID_STATUSES, VALID_ROLES, VALID_BUBBLE_STATES, VALID_TURN_STATUSES;
945
962
  var init_read_chat_contract = __esm({
946
963
  "src/providers/read-chat-contract.ts"() {
947
964
  "use strict";
948
965
  init_contracts();
949
966
  VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "streaming", "long_generating"];
950
967
  VALID_ROLES = ["user", "assistant", "system", "human"];
968
+ VALID_BUBBLE_STATES = ["draft", "streaming", "final", "removed"];
969
+ VALID_TURN_STATUSES = ["open", "waiting_approval", "complete", "error"];
951
970
  }
952
971
  });
953
972
 
@@ -2187,7 +2206,7 @@ var init_provider_cli_adapter = __esm({
2187
2206
  sendDelayMs;
2188
2207
  sendKey;
2189
2208
  submitStrategy;
2190
- static SCRIPT_STATUS_DEBOUNCE_MS = 1e3;
2209
+ static SCRIPT_STATUS_DEBOUNCE_MS = 3e3;
2191
2210
  /** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
2192
2211
  setCliScripts(scripts) {
2193
2212
  this.cliScripts = scripts;
@@ -9900,6 +9919,7 @@ function buildSessionModalDeliverySignature(payload) {
9900
9919
  // src/commands/chat-commands.ts
9901
9920
  init_chat_message_normalization();
9902
9921
  var RECENT_SEND_WINDOW_MS = 1200;
9922
+ var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
9903
9923
  var recentSendByTarget = /* @__PURE__ */ new Map();
9904
9924
  function getCurrentProviderType(h, fallback = "") {
9905
9925
  return h.currentSession?.providerType || h.currentProviderType || fallback;
@@ -10193,7 +10213,7 @@ function didProviderConfirmSend(result) {
10193
10213
  }
10194
10214
  async function readExtensionChatState(h) {
10195
10215
  try {
10196
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
10216
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
10197
10217
  if (!evalResult?.result) return null;
10198
10218
  const parsed = parseMaybeJson(evalResult.result);
10199
10219
  return parsed && typeof parsed === "object" ? parsed : null;
@@ -10281,7 +10301,7 @@ async function handleReadChat(h, args) {
10281
10301
  const title = typeof parsedRecord?.title === "string" ? parsedRecord.title : void 0;
10282
10302
  const providerSessionId = typeof parsedRecord?.providerSessionId === "string" ? parsedRecord.providerSessionId : void 0;
10283
10303
  if (status) {
10284
- LOG.info("Command", `[read_chat] cli-like resolved provider=${adapter.cliType} target=${String(args?.targetSessionId || "")} adapterStatus=${String(adapterStatus.status || "")} parsedStatus=${String(parsedRecord?.status || "")} shouldPreferAdapterMessages=${String(shouldPreferAdapterMessages)} adapterMsgCount=${Array.isArray(adapterStatus.messages) ? adapterStatus.messages.length : 0} parsedMsgCount=${Array.isArray(parsedRecord?.messages) ? parsedRecord.messages.length : 0} returnedMsgCount=${Array.isArray(status.messages) ? status.messages.length : 0}`);
10304
+ LOG.debug("Command", `[read_chat] cli-like resolved provider=${adapter.cliType} target=${String(args?.targetSessionId || "")} adapterStatus=${String(adapterStatus.status || "")} parsedStatus=${String(parsedRecord?.status || "")} shouldPreferAdapterMessages=${String(shouldPreferAdapterMessages)} adapterMsgCount=${Array.isArray(adapterStatus.messages) ? adapterStatus.messages.length : 0} parsedMsgCount=${Array.isArray(parsedRecord?.messages) ? parsedRecord.messages.length : 0} returnedMsgCount=${Array.isArray(status.messages) ? status.messages.length : 0}`);
10285
10305
  return buildReadChatCommandResult({
10286
10306
  messages: status.messages || [],
10287
10307
  status: status.status,
@@ -10306,7 +10326,7 @@ async function handleReadChat(h, args) {
10306
10326
  }
10307
10327
  if (isExtensionTransport(transport)) {
10308
10328
  try {
10309
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
10329
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
10310
10330
  if (evalResult?.result) {
10311
10331
  let parsed = evalResult.result;
10312
10332
  if (typeof parsed === "string") {
@@ -10410,7 +10430,7 @@ async function handleReadChat(h, args) {
10410
10430
  const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
10411
10431
  if (script) {
10412
10432
  try {
10413
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
10433
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
10414
10434
  if (evalResult?.result) {
10415
10435
  let parsed = evalResult.result;
10416
10436
  if (typeof parsed === "string") {
@@ -12992,7 +13012,7 @@ var CliProviderInstance = class {
12992
13012
  this.generatingDebouncePending = null;
12993
13013
  }
12994
13014
  this.generatingDebounceTimer = null;
12995
- }, 1e3);
13015
+ }, 3e3);
12996
13016
  } else if (newStatus === "waiting_approval") {
12997
13017
  this.suppressIdleHistoryReplay = false;
12998
13018
  if (this.generatingDebouncePending) {
@@ -13048,7 +13068,7 @@ var CliProviderInstance = class {
13048
13068
  this.generatingStartedAt = 0;
13049
13069
  }
13050
13070
  this.completedDebounceTimer = null;
13051
- }, 2e3);
13071
+ }, 3e3);
13052
13072
  }
13053
13073
  } else if (newStatus === "stopped") {
13054
13074
  if (this.generatingDebounceTimer) {