xkzoom 1.5.2 → 1.5.3

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.
Files changed (227) hide show
  1. package/README.md +57 -43
  2. package/dist/{chunk-VPRVZWF3.mjs → chunk-37LYF6K2.mjs} +1 -1
  3. package/dist/{chunk-OCQUSYRP.mjs → chunk-3EV63LAA.mjs} +12 -12
  4. package/dist/{chunk-W4MKSQGZ.mjs → chunk-3FF266OG.mjs} +1 -1
  5. package/dist/{chunk-J5HTLG3V.mjs → chunk-3LR4CLDE.mjs} +1 -1
  6. package/dist/{chunk-CDLS44GZ.mjs → chunk-3TTLV2GM.mjs} +1 -1
  7. package/dist/{chunk-JG3EPJ32.mjs → chunk-54GVKP6B.mjs} +6 -6
  8. package/dist/{chunk-M52HZV6R.mjs → chunk-5VR6UOGC.mjs} +1 -1
  9. package/dist/{chunk-GBG4AJON.mjs → chunk-6EI5MFLD.mjs} +4 -4
  10. package/dist/{chunk-A23OTVH2.mjs → chunk-6LKZYMIW.mjs} +30 -30
  11. package/dist/{chunk-TAQQSDJN.mjs → chunk-6SYECCCG.mjs} +6 -6
  12. package/dist/{chunk-24GJWXMG.mjs → chunk-7MOQ462O.mjs} +1 -1
  13. package/dist/{chunk-LFZAVCVW.mjs → chunk-AJNXWGX2.mjs} +1 -1
  14. package/dist/{chunk-5DMSAPS2.mjs → chunk-APQRVOZQ.mjs} +5 -5
  15. package/dist/{chunk-YAD4VG2K.mjs → chunk-BHT6B2TV.mjs} +36 -6
  16. package/dist/{chunk-BV76CMVR.mjs → chunk-BN273XTH.mjs} +1 -1
  17. package/dist/{chunk-IXYH42YO.mjs → chunk-C5VQPAOA.mjs} +1 -1
  18. package/dist/{chunk-PY7W2X6W.mjs → chunk-CQAQRU4P.mjs} +114 -107
  19. package/dist/{chunk-Q4XUEIOE.mjs → chunk-CVIZMDMZ.mjs} +1 -1
  20. package/dist/{chunk-SIIEMWE3.mjs → chunk-DB4XTPJF.mjs} +7 -7
  21. package/dist/{chunk-URF75O5Z.mjs → chunk-DBYEZK64.mjs} +1 -1
  22. package/dist/{chunk-GIAML5K5.mjs → chunk-DQ7J7RST.mjs} +1 -1
  23. package/dist/{chunk-BHMWYAVS.mjs → chunk-DXPZNBSQ.mjs} +3 -3
  24. package/dist/chunk-E5LABIPO.mjs +201 -0
  25. package/dist/{chunk-A5DUSLHF.mjs → chunk-ED4H2DM7.mjs} +1 -1
  26. package/dist/{chunk-KYTJH3R3.mjs → chunk-EE3NRJLQ.mjs} +1 -1
  27. package/dist/{chunk-T4LPE43H.mjs → chunk-ESYRDWFO.mjs} +11 -11
  28. package/dist/{chunk-CQUISJWG.mjs → chunk-EYK3W2NV.mjs} +1 -1
  29. package/dist/{chunk-Z7GTU7KF.mjs → chunk-FAJHYXNU.mjs} +5 -5
  30. package/dist/{chunk-XHO73X2N.mjs → chunk-FKCGJ3BF.mjs} +2 -2
  31. package/dist/{chunk-HJN232FK.mjs → chunk-FLVJABFP.mjs} +1 -1
  32. package/dist/{chunk-H5DIQHEQ.mjs → chunk-FZ7NLBVP.mjs} +45 -16
  33. package/dist/{chunk-HTU5W436.mjs → chunk-G5LQ2PQ6.mjs} +2 -2
  34. package/dist/{chunk-LTBQWMAJ.mjs → chunk-GSIZ5FR6.mjs} +2 -2
  35. package/dist/{chunk-UANVP2AV.mjs → chunk-H4BNL7XG.mjs} +1 -1
  36. package/dist/{chunk-Q6XX6X24.mjs → chunk-I4LMW3IM.mjs} +1 -1
  37. package/dist/{chunk-VIZQURO5.mjs → chunk-IGJFAE72.mjs} +9 -9
  38. package/dist/{chunk-7AZVQS2H.mjs → chunk-IVR74IXK.mjs} +7 -7
  39. package/dist/{chunk-YILSXMZI.mjs → chunk-KI7AMK7P.mjs} +3 -3
  40. package/dist/{chunk-EQNHKW6L.mjs → chunk-LJF6JSJB.mjs} +1 -1
  41. package/dist/{chunk-JD5NPIMO.mjs → chunk-LSQ47CLM.mjs} +27 -27
  42. package/dist/{chunk-IPIV4NGB.mjs → chunk-LXEKUNXI.mjs} +6 -6
  43. package/dist/{chunk-HR43WO4Q.mjs → chunk-M6VHS3HQ.mjs} +2 -2
  44. package/dist/{chunk-4DYFM3EC.mjs → chunk-MI6GFOCU.mjs} +4 -4
  45. package/dist/{chunk-CFZVBILR.mjs → chunk-MIXYB6BH.mjs} +1 -1
  46. package/dist/{chunk-K4RHLREV.mjs → chunk-MVKCMXBY.mjs} +1 -1
  47. package/dist/{chunk-JG3K4N5B.mjs → chunk-NIV5GVCE.mjs} +1 -1
  48. package/dist/{chunk-ZTKJR7OC.mjs → chunk-OWIXULFQ.mjs} +1 -1
  49. package/dist/{chunk-Y6SJUTY6.mjs → chunk-P262PAGZ.mjs} +15 -2
  50. package/dist/{chunk-5JGUBBXN.mjs → chunk-PBBRBETA.mjs} +4 -4
  51. package/dist/{chunk-EGWLJJY7.mjs → chunk-QSHIFD37.mjs} +2 -2
  52. package/dist/{chunk-WJIY3BIA.mjs → chunk-QSQ274C6.mjs} +44 -16
  53. package/dist/{chunk-H5TJYSTV.mjs → chunk-QSUD6TNR.mjs} +5 -5
  54. package/dist/{chunk-YPAQRMUI.mjs → chunk-QYXYVBTO.mjs} +2 -2
  55. package/dist/{chunk-OB4JJLDC.mjs → chunk-RVW5XO4A.mjs} +4 -4
  56. package/dist/{chunk-CNHOCDRM.mjs → chunk-RYSPXH7G.mjs} +2 -2
  57. package/dist/{chunk-CCCPWU2O.mjs → chunk-RZW4EEPW.mjs} +22 -22
  58. package/dist/{chunk-GGWUDW5W.mjs → chunk-S5ROBD7X.mjs} +2 -2
  59. package/dist/{chunk-QUXUHJZW.mjs → chunk-SQHTVHQ7.mjs} +7 -7
  60. package/dist/{chunk-ZM23SMRO.mjs → chunk-T5ZCLYLJ.mjs} +1 -1
  61. package/dist/{chunk-NYG3IUXK.mjs → chunk-TER7DFHP.mjs} +1 -1
  62. package/dist/{chunk-RTANSWHW.mjs → chunk-THN36GA5.mjs} +27 -27
  63. package/dist/{chunk-GUADF3KN.mjs → chunk-ULXTQSV6.mjs} +4 -0
  64. package/dist/{chunk-PG5CHH66.mjs → chunk-VHRFLCMY.mjs} +1 -1
  65. package/dist/{chunk-BSQF7NF4.mjs → chunk-W7OJPFTN.mjs} +2 -2
  66. package/dist/{chunk-S7FQBXOO.mjs → chunk-WGLYR2YT.mjs} +1 -1
  67. package/dist/{chunk-G5ZU7562.mjs → chunk-WNI5ZPQY.mjs} +7 -7
  68. package/dist/{chunk-7FLALKSN.mjs → chunk-WRRJFJ2N.mjs} +7 -7
  69. package/dist/{chunk-ILROJZBI.mjs → chunk-WV6OKJ4J.mjs} +37 -9
  70. package/dist/{chunk-ASIBETCT.mjs → chunk-X7P6B2LK.mjs} +10 -10
  71. package/dist/{chunk-MWRQORKQ.mjs → chunk-XF4EURDX.mjs} +1 -1
  72. package/dist/{chunk-ETD5LGJY.mjs → chunk-Z3COATFF.mjs} +1 -1
  73. package/dist/index.js +336 -31
  74. package/dist/index.mjs +169 -168
  75. package/dist/mobile/action-planner.js +21 -1
  76. package/dist/mobile/action-planner.mjs +95 -94
  77. package/dist/mobile/agent-capabilities.js +21 -1
  78. package/dist/mobile/agent-capabilities.mjs +96 -95
  79. package/dist/mobile/agent-shop/handlers.mjs +3 -3
  80. package/dist/mobile/anthropic-incremental-deliver.js +19 -0
  81. package/dist/mobile/anthropic-incremental-deliver.mjs +3 -2
  82. package/dist/mobile/anthropic-messages-turn-runner.js +224 -8
  83. package/dist/mobile/anthropic-messages-turn-runner.mjs +104 -103
  84. package/dist/mobile/anthropic-owned-tool-executor.js +21 -1
  85. package/dist/mobile/anthropic-owned-tool-executor.mjs +103 -102
  86. package/dist/mobile/api.mjs +49 -49
  87. package/dist/mobile/context-compact/compact-artifact-enrich.js +19 -0
  88. package/dist/mobile/context-compact/compact-artifact-enrich.mjs +16 -15
  89. package/dist/mobile/context-compact/compact-artifact-writer.mjs +4 -4
  90. package/dist/mobile/context-compact/compact-engine-artifacts.mjs +5 -5
  91. package/dist/mobile/context-compact/compact-memory-distill-job.mjs +3 -3
  92. package/dist/mobile/context-compact/compact-message-collector.mjs +2 -2
  93. package/dist/mobile/context-compact/compact-orchestrator.js +21 -1
  94. package/dist/mobile/context-compact/compact-orchestrator.mjs +34 -33
  95. package/dist/mobile/context-compact/compact-resume-prefetch.mjs +4 -4
  96. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.js +19 -0
  97. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.mjs +18 -17
  98. package/dist/mobile/context-compact/compact-summarizer-llm-request.js +19 -0
  99. package/dist/mobile/context-compact/compact-summarizer-llm-request.mjs +10 -9
  100. package/dist/mobile/context-compact/compact-summarizer-llm.js +19 -0
  101. package/dist/mobile/context-compact/compact-summarizer-llm.mjs +11 -10
  102. package/dist/mobile/context-compact/compact-summarizer.js +19 -0
  103. package/dist/mobile/context-compact/compact-summarizer.mjs +15 -14
  104. package/dist/mobile/context-compact/compact-write-verifier.mjs +2 -2
  105. package/dist/mobile/context-compact/context-budget-gate.js +14 -2
  106. package/dist/mobile/context-compact/context-budget-gate.mjs +2 -2
  107. package/dist/mobile/context-compact/runtime-compact-hook.js +33 -2
  108. package/dist/mobile/context-compact/runtime-compact-hook.mjs +99 -98
  109. package/dist/mobile/group/conductor-llm.js +19 -0
  110. package/dist/mobile/group/conductor-llm.mjs +13 -12
  111. package/dist/mobile/group/conductor-plan-llm.js +19 -0
  112. package/dist/mobile/group/conductor-plan-llm.mjs +19 -18
  113. package/dist/mobile/group/delivery-verification.mjs +4 -4
  114. package/dist/mobile/group/direct-chat-group-context.mjs +1 -1
  115. package/dist/mobile/group/execution-plan.mjs +5 -5
  116. package/dist/mobile/group/floor-scheduler.mjs +7 -7
  117. package/dist/mobile/group/floor-state-store.mjs +6 -6
  118. package/dist/mobile/group/group-api-handlers.mjs +38 -38
  119. package/dist/mobile/group/group-peer-private-context.mjs +1 -1
  120. package/dist/mobile/group/group-session.mjs +19 -19
  121. package/dist/mobile/group/index.mjs +32 -32
  122. package/dist/mobile/group/memory-supplement.mjs +10 -10
  123. package/dist/mobile/group/orchestrator.mjs +30 -30
  124. package/dist/mobile/group/pipeline-ceo-dept-mention-parse.mjs +3 -3
  125. package/dist/mobile/group/pipeline-handoff-verification.mjs +3 -3
  126. package/dist/mobile/group/pipeline-turn-outcome.mjs +2 -2
  127. package/dist/mobile/group/plan-runtime.mjs +18 -18
  128. package/dist/mobile/group/relation-distill.mjs +8 -8
  129. package/dist/mobile/group/runtime-integration.mjs +36 -36
  130. package/dist/mobile/index.js +336 -31
  131. package/dist/mobile/index.mjs +164 -163
  132. package/dist/mobile/interrupted-turn.js +5 -0
  133. package/dist/mobile/interrupted-turn.mjs +3 -1
  134. package/dist/mobile/memory-contract-r1-prefetch.mjs +11 -11
  135. package/dist/mobile/memory-contract-r5-empty-result.mjs +12 -12
  136. package/dist/mobile/memory-runtime-v2/eval-runner.mjs +4 -4
  137. package/dist/mobile/memory-runtime-v2/evidence-plan.mjs +5 -5
  138. package/dist/mobile/memory-runtime-v2/index.mjs +15 -15
  139. package/dist/mobile/memory-runtime-v2/memory-control-plane.mjs +5 -5
  140. package/dist/mobile/memory-runtime-v2/memory-readiness.mjs +5 -5
  141. package/dist/mobile/memory-runtime-v2/orchestrator.mjs +3 -3
  142. package/dist/mobile/memory-runtime-v2/public-api.mjs +6 -6
  143. package/dist/mobile/model-context-window-budget.js +16 -2
  144. package/dist/mobile/model-context-window-budget.mjs +3 -1
  145. package/dist/mobile/native-anthropic-messages-stream.js +223 -7
  146. package/dist/mobile/native-anthropic-messages-stream.mjs +11 -10
  147. package/dist/mobile/native-anthropic-turn-errors.mjs +2 -2
  148. package/dist/mobile/native-openai-text-stream.js +223 -6
  149. package/dist/mobile/native-openai-text-stream.mjs +2 -1
  150. package/dist/mobile/native-reply-route.js +19 -0
  151. package/dist/mobile/native-reply-route.mjs +10 -9
  152. package/dist/mobile/native-reply-system-prompt-layers.js +21 -1
  153. package/dist/mobile/native-reply-system-prompt-layers.mjs +96 -95
  154. package/dist/mobile/native-request-diagnostics.js +230 -0
  155. package/dist/mobile/native-request-diagnostics.mjs +17 -0
  156. package/dist/mobile/native-stream-block-emit.js +19 -0
  157. package/dist/mobile/native-stream-block-emit.mjs +2 -1
  158. package/dist/mobile/openai-completions-turn-runner.js +224 -8
  159. package/dist/mobile/openai-completions-turn-runner.mjs +104 -103
  160. package/dist/mobile/reply-dispatch-warmup.mjs +2 -2
  161. package/dist/mobile/runtime.js +336 -31
  162. package/dist/mobile/runtime.mjs +161 -160
  163. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.mjs +3 -3
  164. package/dist/mobile/tool-use-input-normalize.js +21 -1
  165. package/dist/mobile/tool-use-input-normalize.mjs +98 -97
  166. package/dist/mobile/tools/mobile-compact-tool-bridge.js +21 -1
  167. package/dist/mobile/tools/mobile-compact-tool-bridge.mjs +98 -97
  168. package/dist/org/dept-context.mjs +4 -4
  169. package/dist/org/index.mjs +14 -14
  170. package/dist/owned-tools/ceo-confirm-requirements.mjs +12 -12
  171. package/dist/owned-tools/ceo-decision.mjs +18 -18
  172. package/dist/owned-tools/ceo-ops-brief.mjs +12 -12
  173. package/dist/owned-tools/ceo-redirect.mjs +37 -37
  174. package/dist/owned-tools/commit-stack-lesson.mjs +13 -13
  175. package/dist/owned-tools/compact/execute.js +21 -1
  176. package/dist/owned-tools/compact/execute.mjs +96 -95
  177. package/dist/owned-tools/compact/gateway-tool-factory.js +21 -1
  178. package/dist/owned-tools/compact/gateway-tool-factory.mjs +97 -96
  179. package/dist/owned-tools/compact/registry.js +21 -1
  180. package/dist/owned-tools/compact/registry.mjs +95 -94
  181. package/dist/owned-tools/context-compact.js +21 -1
  182. package/dist/owned-tools/context-compact.mjs +42 -41
  183. package/dist/owned-tools/groups-history.mjs +1 -1
  184. package/dist/owned-tools/handoff.mjs +17 -17
  185. package/dist/owned-tools/memory-control.mjs +7 -7
  186. package/dist/owned-tools/memory-runtime-eval.mjs +6 -6
  187. package/dist/owned-tools/message.mjs +2 -2
  188. package/dist/owned-tools/models-list.mjs +2 -2
  189. package/dist/owned-tools/register-owned-providers.mjs +5 -5
  190. package/dist/owned-tools/registry.js +21 -1
  191. package/dist/owned-tools/registry.mjs +94 -93
  192. package/dist/owned-tools/router.js +21 -1
  193. package/dist/owned-tools/router.mjs +95 -94
  194. package/dist/owned-tools/runtime-bridge.js +21 -1
  195. package/dist/owned-tools/runtime-bridge.mjs +96 -95
  196. package/dist/owned-tools/session-status.mjs +1 -1
  197. package/dist/owned-tools/sessions-history-resolver.mjs +2 -2
  198. package/dist/owned-tools/sessions-history.mjs +1 -1
  199. package/dist/owned-tools/sessions-send.mjs +1 -1
  200. package/dist/owned-tools/subagents.mjs +1 -1
  201. package/dist/owned-tools/tool-contract-prompt.js +21 -1
  202. package/dist/owned-tools/tool-contract-prompt.mjs +95 -94
  203. package/dist/owned-tools/tool-result-envelope.js +21 -1
  204. package/dist/owned-tools/tool-result-envelope.mjs +97 -96
  205. package/dist/owned-tools/tool-usage-guide.js +21 -1
  206. package/dist/owned-tools/tool-usage-guide.mjs +94 -93
  207. package/dist/owned-tools/tts.mjs +4 -4
  208. package/dist/owned-tools/web-smoke.mjs +6 -6
  209. package/dist/project/file-tool-scope-default.mjs +6 -6
  210. package/dist/project-pipeline/handlers.mjs +37 -37
  211. package/dist/project-pipeline/index.mjs +40 -40
  212. package/dist/project-pipeline/pipeline-routing.mjs +2 -2
  213. package/dist/project-pipeline/post-close-skill-evolution.mjs +5 -5
  214. package/dist/project-pipeline/project-store.mjs +5 -5
  215. package/package.json +2 -2
  216. package/dist/{chunk-UNZ3D3B3.mjs → chunk-3OXBG4OP.mjs} +5 -5
  217. package/dist/{chunk-NRJWLPTI.mjs → chunk-6AY6OPO5.mjs} +3 -3
  218. package/dist/{chunk-JA65ZG3H.mjs → chunk-6ZWKLMY3.mjs} +4 -4
  219. package/dist/{chunk-T23H5D4O.mjs → chunk-AINHKBJW.mjs} +3 -3
  220. package/dist/{chunk-2BGXTBZX.mjs → chunk-D3N7EHB2.mjs} +8 -8
  221. package/dist/{chunk-JIY7IOQ5.mjs → chunk-DRY7AJMM.mjs} +3 -3
  222. package/dist/{chunk-QM7MTC5Q.mjs → chunk-H6LMX5G5.mjs} +3 -3
  223. package/dist/{chunk-2TBXT3PD.mjs → chunk-J74WVZGF.mjs} +6 -6
  224. package/dist/{chunk-WPLDZLAL.mjs → chunk-L7PMYQN5.mjs} +3 -3
  225. package/dist/{chunk-CORUFGMR.mjs → chunk-N3YQ5IL6.mjs} +7 -7
  226. package/dist/{chunk-5LUTMHVL.mjs → chunk-NXKHSX4M.mjs} +3 -3
  227. package/dist/{chunk-MGWYJD5Q.mjs → chunk-QCSNRVL2.mjs} +8 -8
@@ -35742,6 +35742,199 @@ function parseOpenAiCompletionsSseDataLine(line) {
35742
35742
  }
35743
35743
  }
35744
35744
 
35745
+ // src/mobile/native-request-diagnostics.ts
35746
+ function compactLogValue(value, maxLen = 180) {
35747
+ const text2 = String(value ?? "").replace(/\s+/g, " ").trim();
35748
+ if (!text2) {
35749
+ return "";
35750
+ }
35751
+ return text2.length > maxLen ? `${text2.slice(0, maxLen)}...` : text2;
35752
+ }
35753
+ function readErrorProp(value, key2) {
35754
+ return value && typeof value === "object" ? value[key2] : void 0;
35755
+ }
35756
+ function positiveInteger2(value) {
35757
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
35758
+ return void 0;
35759
+ }
35760
+ return Math.trunc(value);
35761
+ }
35762
+ function formatNativeFetchErrorForLog(error) {
35763
+ const parts = [];
35764
+ let current = error;
35765
+ for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
35766
+ const prefix = depth === 0 ? "error" : `cause${depth}`;
35767
+ const name = compactLogValue(readErrorProp(current, "name"));
35768
+ const message = current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current);
35769
+ const code = compactLogValue(readErrorProp(current, "code"));
35770
+ const errno = compactLogValue(readErrorProp(current, "errno"));
35771
+ if (name) parts.push(`${prefix}Name=${name}`);
35772
+ if (message) parts.push(`${prefix}Message=${message}`);
35773
+ if (code) parts.push(`${prefix}Code=${code}`);
35774
+ if (errno) parts.push(`${prefix}Errno=${errno}`);
35775
+ current = readErrorProp(current, "cause");
35776
+ }
35777
+ return parts.join(" ") || "error=unknown";
35778
+ }
35779
+ function applyConfiguredMaxTokens(requestBody, maxTokens) {
35780
+ const configured = positiveInteger2(maxTokens);
35781
+ if (configured === void 0) {
35782
+ return;
35783
+ }
35784
+ const existing = positiveInteger2(requestBody.max_tokens);
35785
+ requestBody.max_tokens = existing === void 0 ? configured : Math.min(existing, configured);
35786
+ }
35787
+ function stringifyJsonRequestBody(requestBody) {
35788
+ const bodyText = JSON.stringify(requestBody);
35789
+ return {
35790
+ bodyText,
35791
+ bodyBytes: Buffer.byteLength(bodyText, "utf8")
35792
+ };
35793
+ }
35794
+ function formatRequestShape(input) {
35795
+ const messageCount = Array.isArray(input.messages) ? input.messages.length : 0;
35796
+ const toolCount = Array.isArray(input.tools) ? input.tools.length : 0;
35797
+ const maxTokens = positiveInteger2(input.maxTokens);
35798
+ return `bodyBytes=${input.bodyBytes} messages=${messageCount} tools=${toolCount} max_tokens=${maxTokens ?? "n/a"}`;
35799
+ }
35800
+ var DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS = 2;
35801
+ var HARD_PROVIDER_FETCH_MAX_ATTEMPTS = 4;
35802
+ var DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS = 350;
35803
+ var HARD_PROVIDER_FETCH_RETRY_BASE_MS = 5e3;
35804
+ var RETRYABLE_NATIVE_FETCH_RE = new RegExp(
35805
+ [
35806
+ "fetch failed",
35807
+ "UND_ERR_CONNECT_TIMEOUT",
35808
+ "UND_ERR_HEADERS_TIMEOUT",
35809
+ "UND_ERR_SOCKET",
35810
+ "ECONNRESET",
35811
+ "ETIMEDOUT",
35812
+ "ECONNREFUSED",
35813
+ "ENOTFOUND",
35814
+ "EAI_AGAIN",
35815
+ "socket hang up",
35816
+ "network connection lost",
35817
+ "network request failed"
35818
+ ].join("|"),
35819
+ "i"
35820
+ );
35821
+ function readClampedPositiveEnvInt(env, key2, fallback, max) {
35822
+ const raw = (env[key2] ?? "").trim();
35823
+ const n = Number.parseInt(raw, 10);
35824
+ if (!Number.isFinite(n) || n <= 0) {
35825
+ return fallback;
35826
+ }
35827
+ return Math.min(Math.trunc(n), max);
35828
+ }
35829
+ function readClampedNonNegativeEnvInt(env, key2, fallback, max) {
35830
+ const raw = (env[key2] ?? "").trim();
35831
+ const n = Number.parseInt(raw, 10);
35832
+ if (!Number.isFinite(n) || n < 0) {
35833
+ return fallback;
35834
+ }
35835
+ return Math.min(Math.trunc(n), max);
35836
+ }
35837
+ function readProviderFetchMaxAttempts(env) {
35838
+ return readClampedPositiveEnvInt(
35839
+ env,
35840
+ "XKZOOM_NATIVE_PROVIDER_FETCH_MAX_ATTEMPTS",
35841
+ DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS,
35842
+ HARD_PROVIDER_FETCH_MAX_ATTEMPTS
35843
+ );
35844
+ }
35845
+ function readProviderFetchRetryBaseMs(env) {
35846
+ return readClampedNonNegativeEnvInt(
35847
+ env,
35848
+ "XKZOOM_NATIVE_PROVIDER_FETCH_RETRY_BASE_MS",
35849
+ DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS,
35850
+ HARD_PROVIDER_FETCH_RETRY_BASE_MS
35851
+ );
35852
+ }
35853
+ function isAbortLikeFetchError(error) {
35854
+ const name = compactLogValue(readErrorProp(error, "name"));
35855
+ return name === "AbortError";
35856
+ }
35857
+ function collectFetchErrorText(error) {
35858
+ const parts = [];
35859
+ let current = error;
35860
+ for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
35861
+ parts.push(
35862
+ compactLogValue(readErrorProp(current, "name")),
35863
+ current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current),
35864
+ compactLogValue(readErrorProp(current, "code")),
35865
+ compactLogValue(readErrorProp(current, "errno"))
35866
+ );
35867
+ current = readErrorProp(current, "cause");
35868
+ }
35869
+ return parts.filter(Boolean).join(" ");
35870
+ }
35871
+ function isRetryableNativeProviderFetchError(error) {
35872
+ return !isAbortLikeFetchError(error) && RETRYABLE_NATIVE_FETCH_RE.test(collectFetchErrorText(error));
35873
+ }
35874
+ function formatProviderRetryContext(context) {
35875
+ const parts = [
35876
+ `provider=${context.providerId}`,
35877
+ `model=${context.model}`,
35878
+ context.adapter ? `adapter=${context.adapter}` : "",
35879
+ typeof context.iteration === "number" ? `iteration=${context.iteration}` : ""
35880
+ ];
35881
+ return parts.filter(Boolean).join(" ");
35882
+ }
35883
+ function asAbortSignal(signal) {
35884
+ if (signal && typeof signal === "object" && "aborted" in signal) {
35885
+ return signal;
35886
+ }
35887
+ return void 0;
35888
+ }
35889
+ async function waitForProviderFetchRetryDelay(delayMs, signal) {
35890
+ if (delayMs <= 0) {
35891
+ return;
35892
+ }
35893
+ if (signal?.aborted) {
35894
+ throw new DOMException("Aborted", "AbortError");
35895
+ }
35896
+ await new Promise((resolve10, reject) => {
35897
+ const timer = setTimeout(() => {
35898
+ signal?.removeEventListener("abort", onAbort);
35899
+ resolve10();
35900
+ }, delayMs);
35901
+ const onAbort = () => {
35902
+ clearTimeout(timer);
35903
+ reject(new DOMException("Aborted", "AbortError"));
35904
+ };
35905
+ signal?.addEventListener("abort", onAbort, { once: true });
35906
+ });
35907
+ }
35908
+ async function fetchNativeProviderWithRetry(url, init, context, env = process.env) {
35909
+ const maxAttempts = readProviderFetchMaxAttempts(env);
35910
+ const retryBaseMs = readProviderFetchRetryBaseMs(env);
35911
+ const signal = asAbortSignal(init.signal);
35912
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
35913
+ try {
35914
+ return await fetch(url, init);
35915
+ } catch (error) {
35916
+ const retry = attempt < maxAttempts && !signal?.aborted && isRetryableNativeProviderFetchError(error);
35917
+ context.log(
35918
+ `[XKZOOM][native-reply][${context.label}] fetch_failed ${url} ${formatProviderRetryContext(context)} attempt=${attempt}/${maxAttempts} retry=${retry ? 1 : 0} ${formatRequestShape({
35919
+ bodyBytes: context.bodyBytes,
35920
+ messages: context.messages,
35921
+ tools: context.tools,
35922
+ maxTokens: context.maxTokens
35923
+ })} ${formatNativeFetchErrorForLog(error)}`
35924
+ );
35925
+ if (!retry) {
35926
+ throw error;
35927
+ }
35928
+ const delayMs = retryBaseMs * attempt;
35929
+ context.log(
35930
+ `[XKZOOM][native-reply][${context.label}] fetch_retry ${url} ${formatProviderRetryContext(context)} nextAttempt=${attempt + 1}/${maxAttempts} delayMs=${delayMs}`
35931
+ );
35932
+ await waitForProviderFetchRetryDelay(delayMs, signal);
35933
+ }
35934
+ }
35935
+ throw new Error(`native provider fetch retry exhausted: ${url}`);
35936
+ }
35937
+
35745
35938
  // src/mobile/native-openai-text-stream.ts
35746
35939
  var isRecord6 = isGatewayConfigRecord;
35747
35940
  function resolveOpenAiCompletionsBodyExtras(provider, baseUrl) {
@@ -35962,12 +36155,36 @@ async function runNativeOpenAiTextStreamToDispatcher(params) {
35962
36155
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
35963
36156
  params.log(formatProviderAccelerationApplication(providerAcceleration.application));
35964
36157
  }
35965
- const res = await fetch(url, {
35966
- method: "POST",
35967
- headers: buildBearerOpenAiHeaders(cfg),
35968
- body: JSON.stringify(requestBody),
35969
- signal: params.signal
35970
- });
36158
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
36159
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
36160
+ params.log(
36161
+ `[XKZOOM][native-reply][openai-completions] request_shape ${formatRequestShape({
36162
+ bodyBytes,
36163
+ messages: chatMessages,
36164
+ tools: toolsForRequest,
36165
+ maxTokens: requestBody.max_tokens
36166
+ })}`
36167
+ );
36168
+ const res = await fetchNativeProviderWithRetry(
36169
+ url,
36170
+ {
36171
+ method: "POST",
36172
+ headers: buildBearerOpenAiHeaders(cfg),
36173
+ body: bodyText,
36174
+ signal: params.signal
36175
+ },
36176
+ {
36177
+ label: "openai-completions",
36178
+ providerId: cfg.providerId,
36179
+ model: cfg.model,
36180
+ adapter: "openai-completions",
36181
+ bodyBytes,
36182
+ messages: chatMessages,
36183
+ tools: toolsForRequest,
36184
+ maxTokens: requestBody.max_tokens,
36185
+ log: params.log
36186
+ }
36187
+ );
35971
36188
  if (!res.ok) {
35972
36189
  const t = await res.text();
35973
36190
  throw new Error(`native OpenAI HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -37424,7 +37641,8 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
37424
37641
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
37425
37642
  params.log(formatProviderAccelerationApplication2(providerAcceleration.application));
37426
37643
  }
37427
- const thinkingForBody = selectAnthropicAdapterByBaseUrl(cfg.baseUrl).resolveThinkingForBody({
37644
+ const adapter = selectAnthropicAdapterByBaseUrl(cfg.baseUrl);
37645
+ const thinkingForBody = adapter.resolveThinkingForBody({
37428
37646
  reasoningMode: params.reasoningMode,
37429
37647
  model: cfg.model,
37430
37648
  configuredThinking: requestBody.thinking
@@ -37432,12 +37650,34 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
37432
37650
  if (thinkingForBody !== void 0) {
37433
37651
  requestBody.thinking = thinkingForBody;
37434
37652
  }
37435
- const res = await fetch(url, {
37436
- method: "POST",
37437
- headers: buildNativeAnthropicRequestHeaders(cfg),
37438
- body: JSON.stringify(requestBody),
37439
- signal: params.signal
37440
- });
37653
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
37654
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
37655
+ params.log(
37656
+ `[XKZOOM][native-reply][anthropic-messages] request_shape ${formatRequestShape({
37657
+ bodyBytes,
37658
+ messages: transcriptMessages,
37659
+ maxTokens: requestBody.max_tokens
37660
+ })}`
37661
+ );
37662
+ const res = await fetchNativeProviderWithRetry(
37663
+ url,
37664
+ {
37665
+ method: "POST",
37666
+ headers: buildNativeAnthropicRequestHeaders(cfg),
37667
+ body: bodyText,
37668
+ signal: params.signal
37669
+ },
37670
+ {
37671
+ label: "anthropic-messages",
37672
+ providerId: cfg.providerId,
37673
+ model: cfg.model,
37674
+ adapter: adapter.id,
37675
+ bodyBytes,
37676
+ messages: transcriptMessages,
37677
+ maxTokens: requestBody.max_tokens,
37678
+ log: params.log
37679
+ }
37680
+ );
37441
37681
  if (!res.ok) {
37442
37682
  const t = await res.text();
37443
37683
  throw new Error(`native anthropic-messages HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -39579,15 +39819,27 @@ function buildSessionTranscriptMeterFromMessages(messages) {
39579
39819
  var TRANSCRIPT_BUDGET_BYTES_PER_TOKEN = 4;
39580
39820
  var TRANSCRIPT_CONTEXT_WINDOW_RATIO = 0.35;
39581
39821
  var MIN_TRANSCRIPT_BUDGET_BYTES = 64 * 1024;
39582
- var MAX_TRANSCRIPT_BUDGET_BYTES = 4 * 1024 * 1024;
39583
- function positiveInteger2(value) {
39822
+ var DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES = 128 * 1024;
39823
+ var HARD_MAX_TRANSCRIPT_BUDGET_BYTES = 4 * 1024 * 1024;
39824
+ function positiveInteger3(value) {
39584
39825
  if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
39585
39826
  return void 0;
39586
39827
  }
39587
39828
  return Math.trunc(value);
39588
39829
  }
39830
+ function readMaxTranscriptBudgetBytes(env = process.env) {
39831
+ const raw = env.XKZOOM_NATIVE_TRANSCRIPT_MAX_REQUEST_BYTES?.trim();
39832
+ if (!raw) {
39833
+ return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
39834
+ }
39835
+ const parsed = Number.parseInt(raw, 10);
39836
+ if (!Number.isFinite(parsed) || parsed <= 0) {
39837
+ return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
39838
+ }
39839
+ return Math.min(HARD_MAX_TRANSCRIPT_BUDGET_BYTES, Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, parsed));
39840
+ }
39589
39841
  function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
39590
- const tokens = positiveInteger2(contextWindowTokens);
39842
+ const tokens = positiveInteger3(contextWindowTokens);
39591
39843
  if (tokens === void 0) {
39592
39844
  return void 0;
39593
39845
  }
@@ -39595,7 +39847,7 @@ function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
39595
39847
  tokens * TRANSCRIPT_CONTEXT_WINDOW_RATIO * TRANSCRIPT_BUDGET_BYTES_PER_TOKEN
39596
39848
  );
39597
39849
  return Math.min(
39598
- MAX_TRANSCRIPT_BUDGET_BYTES,
39850
+ readMaxTranscriptBudgetBytes(),
39599
39851
  Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, estimated)
39600
39852
  );
39601
39853
  }
@@ -54568,15 +54820,37 @@ async function runNativeOpenAiCompletionsTurnToDispatcher(params) {
54568
54820
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
54569
54821
  params.log(formatProviderAccelerationApplication3(providerAcceleration.application));
54570
54822
  }
54823
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
54824
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
54571
54825
  params.log(
54572
- `[XKZOOM][native-reply][openai-turn] POST ${url} provider=${cfg.providerId} model=${cfg.model} adapter=${adapter.id} iteration=${iteration} tools=${toolsForRequest ? toolsForRequest.length : 0} tool_choice=${toolChoiceLog} transcriptTurns=${messages.filter((m) => m.role !== "system").length}`
54826
+ `[XKZOOM][native-reply][openai-turn] POST ${url} provider=${cfg.providerId} model=${cfg.model} adapter=${adapter.id} iteration=${iteration} tools=${toolsForRequest ? toolsForRequest.length : 0} tool_choice=${toolChoiceLog} transcriptTurns=${messages.filter((m) => m.role !== "system").length} ` + formatRequestShape({
54827
+ bodyBytes,
54828
+ messages,
54829
+ tools: toolsForRequest,
54830
+ maxTokens: requestBody.max_tokens
54831
+ })
54832
+ );
54833
+ const res = await fetchNativeProviderWithRetry(
54834
+ url,
54835
+ {
54836
+ method: "POST",
54837
+ headers: adapter.buildHeaders(cfg),
54838
+ body: bodyText,
54839
+ signal: params.signal
54840
+ },
54841
+ {
54842
+ label: "openai-turn",
54843
+ providerId: cfg.providerId,
54844
+ model: cfg.model,
54845
+ adapter: adapter.id,
54846
+ iteration,
54847
+ bodyBytes,
54848
+ messages,
54849
+ tools: toolsForRequest,
54850
+ maxTokens: requestBody.max_tokens,
54851
+ log: params.log
54852
+ }
54573
54853
  );
54574
- const res = await fetch(url, {
54575
- method: "POST",
54576
- headers: adapter.buildHeaders(cfg),
54577
- body: JSON.stringify(requestBody),
54578
- signal: params.signal
54579
- });
54580
54854
  if (!res.ok) {
54581
54855
  const t = await res.text();
54582
54856
  if (policyToolChoiceApplied && requestAttempt === 0 && isOpenAiToolChoiceCompatibilityHttpError(res.status, t)) {
@@ -55407,15 +55681,37 @@ function createFetchAnthropicTurnStreamFn(cfg, log, providerAccelerationPlan, pr
55407
55681
  toolChoiceLog = `skipped(${policy.kind}:adapter-undefined)`;
55408
55682
  }
55409
55683
  }
55684
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
55685
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
55410
55686
  log(
55411
- `[XKZOOM][native-reply][anthropic-turn] POST ${url} adapter=${adapter.id} provider=${cfg.providerId} model=${cfg.model} iteration=${req.iteration} tools=${Array.isArray(req.tools) ? req.tools.length : 0} tool_choice=${toolChoiceLog}` + (requestBody.thinking !== void 0 && requestBody.thinking !== null ? ` thinking=${requestBody.thinking.type ?? "1"}` : " thinking=0")
55687
+ `[XKZOOM][native-reply][anthropic-turn] POST ${url} adapter=${adapter.id} provider=${cfg.providerId} model=${cfg.model} iteration=${req.iteration} tools=${Array.isArray(req.tools) ? req.tools.length : 0} tool_choice=${toolChoiceLog}` + (requestBody.thinking !== void 0 && requestBody.thinking !== null ? ` thinking=${requestBody.thinking.type ?? "1"}` : " thinking=0") + ` ${formatRequestShape({
55688
+ bodyBytes,
55689
+ messages: req.messages,
55690
+ tools: req.tools,
55691
+ maxTokens: requestBody.max_tokens
55692
+ })}`
55693
+ );
55694
+ const res = await fetchNativeProviderWithRetry(
55695
+ url,
55696
+ {
55697
+ method: "POST",
55698
+ headers,
55699
+ body: bodyText,
55700
+ signal
55701
+ },
55702
+ {
55703
+ label: "anthropic-turn",
55704
+ providerId: cfg.providerId,
55705
+ model: cfg.model,
55706
+ adapter: adapter.id,
55707
+ iteration: req.iteration,
55708
+ bodyBytes,
55709
+ messages: req.messages,
55710
+ tools: req.tools,
55711
+ maxTokens: requestBody.max_tokens,
55712
+ log
55713
+ }
55412
55714
  );
55413
- const res = await fetch(url, {
55414
- method: "POST",
55415
- headers,
55416
- body: JSON.stringify(requestBody),
55417
- signal
55418
- });
55419
55715
  if (!res.ok) {
55420
55716
  const t = await res.text();
55421
55717
  throw new Error(`native anthropic-turn HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -55665,6 +55961,9 @@ function createInterruptedTurnSnapshot(params) {
55665
55961
  ...clipText(errMessage, MAX_PREVIEW_CHARS) ? { errorMessage: clipText(errMessage, MAX_PREVIEW_CHARS) } : {}
55666
55962
  };
55667
55963
  }
55964
+ function hasInterruptedTurnRecoveryEvidence(snapshot) {
55965
+ return snapshot.visibleTextLength > 0 || Boolean(snapshot.assistantPartialText?.trim()) || Boolean(snapshot.toolCallSummaries?.length);
55966
+ }
55668
55967
  function isInterruptedTurnResumeRequest(text2) {
55669
55968
  const raw = typeof text2 === "string" ? text2.trim() : "";
55670
55969
  if (!raw) {
@@ -59742,6 +60041,12 @@ ${inbound.bodyText}` : inbound.bodyText;
59742
60041
  lastToolName: params.lastToolName ?? lastToolNameForInterruptedTurn,
59743
60042
  error: params.error
59744
60043
  });
60044
+ if (!hasInterruptedTurnRecoveryEvidence(snapshot)) {
60045
+ this.logInfo(
60046
+ `[XKZOOM][turn-timeout][snapshot] skipped session=${session.id} conversationId=${identity.conversationId ?? "none"} userMessage=${userMessage.id} targetMessage=${target.id} assistantMessage=${assistantMessage?.id ?? "none"} turn_timeout_kind=${snapshot.turn_timeout_kind} recoverableEvidence=0 visibleTextLength=${snapshot.visibleTextLength}`
60047
+ );
60048
+ return null;
60049
+ }
59745
60050
  target.interruptedTurn = snapshot;
59746
60051
  this.store.persistMessage(session.id, target.id);
59747
60052
  this.logInfo(