xkzoom 1.5.2 → 1.5.4

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 (188) hide show
  1. package/README.md +87 -43
  2. package/dist/{chunk-UANVP2AV.mjs → chunk-27BXVTXH.mjs} +1 -1
  3. package/dist/{chunk-PY7W2X6W.mjs → chunk-2DR5RT3I.mjs} +52 -45
  4. package/dist/{chunk-YILSXMZI.mjs → chunk-2IQAT3PE.mjs} +1 -1
  5. package/dist/{chunk-IXYH42YO.mjs → chunk-2VSERWT6.mjs} +1 -1
  6. package/dist/{chunk-BSQF7NF4.mjs → chunk-3KJHUTOO.mjs} +2 -2
  7. package/dist/{chunk-URF75O5Z.mjs → chunk-3VA3YDYL.mjs} +1 -1
  8. package/dist/{chunk-RTANSWHW.mjs → chunk-3ZH273T7.mjs} +27 -27
  9. package/dist/{chunk-EQNHKW6L.mjs → chunk-4JXTPCOE.mjs} +1 -1
  10. package/dist/{chunk-WJIY3BIA.mjs → chunk-5SE4JOKE.mjs} +38 -10
  11. package/dist/{chunk-JD5NPIMO.mjs → chunk-5YEFG7BF.mjs} +25 -25
  12. package/dist/{chunk-LTBQWMAJ.mjs → chunk-6W4W5JLG.mjs} +1 -1
  13. package/dist/{chunk-CDLS44GZ.mjs → chunk-76MFE24I.mjs} +1 -1
  14. package/dist/{chunk-IPIV4NGB.mjs → chunk-76TKUYY3.mjs} +2 -2
  15. package/dist/{chunk-T4LPE43H.mjs → chunk-7LEEVP5O.mjs} +1 -1
  16. package/dist/{chunk-A5DUSLHF.mjs → chunk-DCSERRXG.mjs} +1 -1
  17. package/dist/{chunk-ASIBETCT.mjs → chunk-E2TTUY6R.mjs} +2 -2
  18. package/dist/chunk-E5LABIPO.mjs +201 -0
  19. package/dist/{chunk-KYTJH3R3.mjs → chunk-EE3NRJLQ.mjs} +1 -1
  20. package/dist/{chunk-SIIEMWE3.mjs → chunk-F35EHL5U.mjs} +3 -3
  21. package/dist/{chunk-K4RHLREV.mjs → chunk-FG6QCRVN.mjs} +1 -1
  22. package/dist/{chunk-HJN232FK.mjs → chunk-FLVJABFP.mjs} +1 -1
  23. package/dist/{chunk-ZM23SMRO.mjs → chunk-GIC2RBVM.mjs} +1 -1
  24. package/dist/{chunk-HTU5W436.mjs → chunk-GZJMFCRG.mjs} +2 -2
  25. package/dist/{chunk-JG3EPJ32.mjs → chunk-HAI7DJD2.mjs} +3 -3
  26. package/dist/{chunk-OB4JJLDC.mjs → chunk-HYSOWPIC.mjs} +2 -2
  27. package/dist/{chunk-G5ZU7562.mjs → chunk-IDQ5B572.mjs} +6 -6
  28. package/dist/{chunk-GGWUDW5W.mjs → chunk-IGDJGBAI.mjs} +1 -1
  29. package/dist/{chunk-A23OTVH2.mjs → chunk-J5AXFEDQ.mjs} +18 -18
  30. package/dist/{chunk-4DYFM3EC.mjs → chunk-JBKRS62W.mjs} +3 -3
  31. package/dist/{chunk-OCQUSYRP.mjs → chunk-JFFBD5TV.mjs} +14 -14
  32. package/dist/{chunk-VPRVZWF3.mjs → chunk-JI67TW4E.mjs} +1 -1
  33. package/dist/{chunk-GBG4AJON.mjs → chunk-JJKRD5DL.mjs} +1 -1
  34. package/dist/{chunk-7AZVQS2H.mjs → chunk-JXDHNASC.mjs} +12 -12
  35. package/dist/{chunk-W4MKSQGZ.mjs → chunk-K7RZQIPZ.mjs} +1 -1
  36. package/dist/{chunk-J5HTLG3V.mjs → chunk-KPDVZFJY.mjs} +1 -1
  37. package/dist/{chunk-S7FQBXOO.mjs → chunk-L252ASZW.mjs} +1 -1
  38. package/dist/{chunk-Z7GTU7KF.mjs → chunk-LESS4N25.mjs} +1 -1
  39. package/dist/{chunk-5DMSAPS2.mjs → chunk-M3ISDSQP.mjs} +7 -7
  40. package/dist/{chunk-HR43WO4Q.mjs → chunk-M5IU6U3O.mjs} +2 -2
  41. package/dist/{chunk-BV76CMVR.mjs → chunk-MBOWNG3A.mjs} +1 -1
  42. package/dist/{chunk-CCCPWU2O.mjs → chunk-MDZUWIBH.mjs} +4 -4
  43. package/dist/{chunk-YAD4VG2K.mjs → chunk-MKYCBV3H.mjs} +36 -6
  44. package/dist/{chunk-CORUFGMR.mjs → chunk-MPGMU75K.mjs} +4 -4
  45. package/dist/{chunk-7FLALKSN.mjs → chunk-MQKREMOB.mjs} +2 -2
  46. package/dist/{chunk-H5TJYSTV.mjs → chunk-MRTQWCNC.mjs} +1 -1
  47. package/dist/{chunk-CNHOCDRM.mjs → chunk-NHICONJ3.mjs} +1 -1
  48. package/dist/{chunk-5JGUBBXN.mjs → chunk-NIU6GWKB.mjs} +2 -2
  49. package/dist/{chunk-Q6XX6X24.mjs → chunk-OBYPZT2S.mjs} +6 -6
  50. package/dist/{chunk-Y6SJUTY6.mjs → chunk-P262PAGZ.mjs} +15 -2
  51. package/dist/{chunk-YPAQRMUI.mjs → chunk-PETWGCGB.mjs} +1 -1
  52. package/dist/{chunk-Q4XUEIOE.mjs → chunk-PW3ULDNL.mjs} +1 -1
  53. package/dist/{chunk-EGWLJJY7.mjs → chunk-RKZ56GST.mjs} +2 -2
  54. package/dist/{chunk-QUXUHJZW.mjs → chunk-TADSGGK2.mjs} +7 -7
  55. package/dist/{chunk-ILROJZBI.mjs → chunk-TQBVFKCT.mjs} +37 -9
  56. package/dist/{chunk-M52HZV6R.mjs → chunk-TVH4LII3.mjs} +1 -1
  57. package/dist/{chunk-GUADF3KN.mjs → chunk-ULXTQSV6.mjs} +4 -0
  58. package/dist/{chunk-H5DIQHEQ.mjs → chunk-UXEZFEB3.mjs} +37 -8
  59. package/dist/{chunk-XHO73X2N.mjs → chunk-VNEPNUBZ.mjs} +13 -13
  60. package/dist/{chunk-NYG3IUXK.mjs → chunk-W75Z6CZR.mjs} +1 -1
  61. package/dist/{chunk-PG5CHH66.mjs → chunk-YPKHMAO4.mjs} +1 -1
  62. package/dist/index.js +336 -31
  63. package/dist/index.mjs +104 -103
  64. package/dist/mobile/action-planner.js +21 -1
  65. package/dist/mobile/action-planner.mjs +60 -59
  66. package/dist/mobile/agent-capabilities.js +21 -1
  67. package/dist/mobile/agent-capabilities.mjs +60 -59
  68. package/dist/mobile/anthropic-incremental-deliver.js +19 -0
  69. package/dist/mobile/anthropic-incremental-deliver.mjs +3 -2
  70. package/dist/mobile/anthropic-messages-turn-runner.js +224 -8
  71. package/dist/mobile/anthropic-messages-turn-runner.mjs +69 -68
  72. package/dist/mobile/anthropic-owned-tool-executor.js +21 -1
  73. package/dist/mobile/anthropic-owned-tool-executor.mjs +68 -67
  74. package/dist/mobile/api.mjs +31 -31
  75. package/dist/mobile/context-compact/compact-artifact-enrich.js +19 -0
  76. package/dist/mobile/context-compact/compact-artifact-enrich.mjs +8 -7
  77. package/dist/mobile/context-compact/compact-orchestrator.js +21 -1
  78. package/dist/mobile/context-compact/compact-orchestrator.mjs +12 -11
  79. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.js +19 -0
  80. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.mjs +8 -7
  81. package/dist/mobile/context-compact/compact-summarizer-llm-request.js +19 -0
  82. package/dist/mobile/context-compact/compact-summarizer-llm-request.mjs +5 -4
  83. package/dist/mobile/context-compact/compact-summarizer-llm.js +19 -0
  84. package/dist/mobile/context-compact/compact-summarizer-llm.mjs +6 -5
  85. package/dist/mobile/context-compact/compact-summarizer.js +19 -0
  86. package/dist/mobile/context-compact/compact-summarizer.mjs +7 -6
  87. package/dist/mobile/context-compact/context-budget-gate.js +14 -2
  88. package/dist/mobile/context-compact/context-budget-gate.mjs +2 -2
  89. package/dist/mobile/context-compact/runtime-compact-hook.js +33 -2
  90. package/dist/mobile/context-compact/runtime-compact-hook.mjs +64 -63
  91. package/dist/mobile/group/conductor-llm.js +19 -0
  92. package/dist/mobile/group/conductor-llm.mjs +7 -6
  93. package/dist/mobile/group/conductor-plan-llm.js +19 -0
  94. package/dist/mobile/group/conductor-plan-llm.mjs +7 -6
  95. package/dist/mobile/group/floor-scheduler.mjs +2 -2
  96. package/dist/mobile/group/group-api-handlers.mjs +21 -21
  97. package/dist/mobile/group/group-session.mjs +5 -5
  98. package/dist/mobile/group/index.mjs +16 -16
  99. package/dist/mobile/group/memory-supplement.mjs +4 -4
  100. package/dist/mobile/group/orchestrator.mjs +15 -15
  101. package/dist/mobile/group/plan-runtime.mjs +4 -4
  102. package/dist/mobile/group/relation-distill.mjs +3 -3
  103. package/dist/mobile/group/runtime-integration.mjs +19 -19
  104. package/dist/mobile/group/team-memory-runtime.mjs +3 -3
  105. package/dist/mobile/index.js +336 -31
  106. package/dist/mobile/index.mjs +101 -100
  107. package/dist/mobile/interrupted-turn.js +5 -0
  108. package/dist/mobile/interrupted-turn.mjs +3 -1
  109. package/dist/mobile/memory-contract-r1-prefetch.mjs +5 -5
  110. package/dist/mobile/memory-contract-r5-empty-result.mjs +6 -6
  111. package/dist/mobile/memory-runtime-v2/eval-runner.mjs +8 -8
  112. package/dist/mobile/memory-runtime-v2/evidence-plan.mjs +11 -11
  113. package/dist/mobile/memory-runtime-v2/index.mjs +31 -31
  114. package/dist/mobile/memory-runtime-v2/local-source-import.mjs +3 -3
  115. package/dist/mobile/memory-runtime-v2/memory-control-plane.mjs +11 -11
  116. package/dist/mobile/memory-runtime-v2/memory-readiness.mjs +11 -11
  117. package/dist/mobile/memory-runtime-v2/orchestrator.mjs +4 -4
  118. package/dist/mobile/memory-runtime-v2/project-tool-event.mjs +2 -2
  119. package/dist/mobile/memory-runtime-v2/public-api.mjs +12 -12
  120. package/dist/mobile/memory-runtime-v2/retrieval.mjs +2 -2
  121. package/dist/mobile/model-context-window-budget.js +16 -2
  122. package/dist/mobile/model-context-window-budget.mjs +3 -1
  123. package/dist/mobile/native-anthropic-messages-stream.js +223 -7
  124. package/dist/mobile/native-anthropic-messages-stream.mjs +4 -3
  125. package/dist/mobile/native-anthropic-turn-errors.mjs +2 -2
  126. package/dist/mobile/native-openai-text-stream.js +223 -6
  127. package/dist/mobile/native-openai-text-stream.mjs +2 -1
  128. package/dist/mobile/native-reply-route.js +19 -0
  129. package/dist/mobile/native-reply-route.mjs +5 -4
  130. package/dist/mobile/native-reply-system-prompt-layers.js +21 -1
  131. package/dist/mobile/native-reply-system-prompt-layers.mjs +61 -60
  132. package/dist/mobile/native-request-diagnostics.js +230 -0
  133. package/dist/mobile/native-request-diagnostics.mjs +17 -0
  134. package/dist/mobile/native-stream-block-emit.js +19 -0
  135. package/dist/mobile/native-stream-block-emit.mjs +2 -1
  136. package/dist/mobile/openai-completions-turn-runner.js +224 -8
  137. package/dist/mobile/openai-completions-turn-runner.mjs +69 -68
  138. package/dist/mobile/runtime.js +336 -31
  139. package/dist/mobile/runtime.mjs +100 -99
  140. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.mjs +4 -4
  141. package/dist/mobile/tool-use-input-normalize.js +21 -1
  142. package/dist/mobile/tool-use-input-normalize.mjs +63 -62
  143. package/dist/mobile/tools/mobile-compact-tool-bridge.js +21 -1
  144. package/dist/mobile/tools/mobile-compact-tool-bridge.mjs +63 -62
  145. package/dist/org/dept-context.mjs +2 -2
  146. package/dist/org/index.mjs +8 -8
  147. package/dist/owned-tools/ceo-confirm-requirements.mjs +3 -3
  148. package/dist/owned-tools/ceo-decision.mjs +4 -4
  149. package/dist/owned-tools/ceo-ops-brief.mjs +3 -3
  150. package/dist/owned-tools/ceo-redirect.mjs +20 -20
  151. package/dist/owned-tools/commit-stack-lesson.mjs +4 -4
  152. package/dist/owned-tools/compact/execute.js +21 -1
  153. package/dist/owned-tools/compact/execute.mjs +61 -60
  154. package/dist/owned-tools/compact/gateway-tool-factory.js +21 -1
  155. package/dist/owned-tools/compact/gateway-tool-factory.mjs +62 -61
  156. package/dist/owned-tools/compact/registry.js +21 -1
  157. package/dist/owned-tools/compact/registry.mjs +60 -59
  158. package/dist/owned-tools/context-compact.js +21 -1
  159. package/dist/owned-tools/context-compact.mjs +25 -24
  160. package/dist/owned-tools/handoff.mjs +3 -3
  161. package/dist/owned-tools/memory-control.mjs +13 -13
  162. package/dist/owned-tools/memory-runtime-eval.mjs +12 -12
  163. package/dist/owned-tools/register-owned-providers.mjs +3 -3
  164. package/dist/owned-tools/registry.js +21 -1
  165. package/dist/owned-tools/registry.mjs +59 -58
  166. package/dist/owned-tools/router.js +21 -1
  167. package/dist/owned-tools/router.mjs +60 -59
  168. package/dist/owned-tools/runtime-bridge.js +21 -1
  169. package/dist/owned-tools/runtime-bridge.mjs +61 -60
  170. package/dist/owned-tools/tool-contract-prompt.js +21 -1
  171. package/dist/owned-tools/tool-contract-prompt.mjs +60 -59
  172. package/dist/owned-tools/tool-result-envelope.js +21 -1
  173. package/dist/owned-tools/tool-result-envelope.mjs +62 -61
  174. package/dist/owned-tools/tool-usage-guide.js +21 -1
  175. package/dist/owned-tools/tool-usage-guide.mjs +59 -58
  176. package/dist/owned-tools/tts.mjs +2 -2
  177. package/dist/project-pipeline/handlers.mjs +20 -20
  178. package/dist/project-pipeline/index.mjs +20 -20
  179. package/dist/project-pipeline/post-close-skill-evolution.mjs +3 -3
  180. package/package.json +2 -2
  181. package/dist/{chunk-KCZIK3TH.mjs → chunk-2QCX6RPN.mjs} +3 -3
  182. package/dist/{chunk-2BGXTBZX.mjs → chunk-D3N7EHB2.mjs} +8 -8
  183. package/dist/{chunk-JIY7IOQ5.mjs → chunk-DRY7AJMM.mjs} +3 -3
  184. package/dist/{chunk-VS2URZFN.mjs → chunk-HWGRW6YP.mjs} +3 -3
  185. package/dist/{chunk-Q7NYATKS.mjs → chunk-UR6LPERL.mjs} +3 -3
  186. package/dist/{chunk-TAQQSDJN.mjs → chunk-WPMJCKI2.mjs} +3 -3
  187. package/dist/{chunk-2TBXT3PD.mjs → chunk-XNQJRIGR.mjs} +9 -9
  188. package/dist/{chunk-BHMWYAVS.mjs → chunk-YYDDQEY4.mjs} +3 -3
@@ -1,10 +1,16 @@
1
1
  import {
2
2
  AnthropicIncrementalDeliverer
3
- } from "./chunk-CDLS44GZ.mjs";
3
+ } from "./chunk-76MFE24I.mjs";
4
4
  import {
5
5
  init_native_provider_api_key,
6
6
  resolveNativeProviderApiKeySync
7
7
  } from "./chunk-NEDXMES6.mjs";
8
+ import {
9
+ applyConfiguredMaxTokens,
10
+ fetchNativeProviderWithRetry,
11
+ formatRequestShape,
12
+ stringifyJsonRequestBody
13
+ } from "./chunk-E5LABIPO.mjs";
8
14
  import {
9
15
  gatewayConfigStringProp,
10
16
  init_native_gateway_config,
@@ -138,7 +144,8 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
138
144
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
139
145
  params.log(formatProviderAccelerationApplication(providerAcceleration.application));
140
146
  }
141
- const thinkingForBody = selectAnthropicAdapterByBaseUrl(cfg.baseUrl).resolveThinkingForBody({
147
+ const adapter = selectAnthropicAdapterByBaseUrl(cfg.baseUrl);
148
+ const thinkingForBody = adapter.resolveThinkingForBody({
142
149
  reasoningMode: params.reasoningMode,
143
150
  model: cfg.model,
144
151
  configuredThinking: requestBody.thinking
@@ -146,12 +153,34 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
146
153
  if (thinkingForBody !== void 0) {
147
154
  requestBody.thinking = thinkingForBody;
148
155
  }
149
- const res = await fetch(url, {
150
- method: "POST",
151
- headers: buildNativeAnthropicRequestHeaders(cfg),
152
- body: JSON.stringify(requestBody),
153
- signal: params.signal
154
- });
156
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
157
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
158
+ params.log(
159
+ `[XKZOOM][native-reply][anthropic-messages] request_shape ${formatRequestShape({
160
+ bodyBytes,
161
+ messages: transcriptMessages,
162
+ maxTokens: requestBody.max_tokens
163
+ })}`
164
+ );
165
+ const res = await fetchNativeProviderWithRetry(
166
+ url,
167
+ {
168
+ method: "POST",
169
+ headers: buildNativeAnthropicRequestHeaders(cfg),
170
+ body: bodyText,
171
+ signal: params.signal
172
+ },
173
+ {
174
+ label: "anthropic-messages",
175
+ providerId: cfg.providerId,
176
+ model: cfg.model,
177
+ adapter: adapter.id,
178
+ bodyBytes,
179
+ messages: transcriptMessages,
180
+ maxTokens: requestBody.max_tokens,
181
+ log: params.log
182
+ }
183
+ );
155
184
  if (!res.ok) {
156
185
  const t = await res.text();
157
186
  throw new Error(`native anthropic-messages HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -13,7 +13,7 @@ import {
13
13
  handleMemoryProductControlPlaneRoute,
14
14
  readLastMemoryReadinessGate,
15
15
  readLastMemoryReadinessReport
16
- } from "./chunk-Q6XX6X24.mjs";
16
+ } from "./chunk-OBYPZT2S.mjs";
17
17
  import {
18
18
  buildMemorySoakEvidenceSummary,
19
19
  completeMemorySoakSession,
@@ -24,6 +24,11 @@ import {
24
24
  recordMemorySoakSessionEvent,
25
25
  startMemorySoakSession
26
26
  } from "./chunk-XQUKAHWK.mjs";
27
+ import {
28
+ exportMemoryPortabilitySnapshot,
29
+ importMemoryPortabilitySnapshot,
30
+ verifyMemoryPortabilitySnapshot
31
+ } from "./chunk-6SJTUWEO.mjs";
27
32
  import {
28
33
  buildMemoryProductAcceptanceSummary,
29
34
  listMemoryProductAcceptanceReports,
@@ -38,14 +43,9 @@ import {
38
43
  suppressMemoryRecords,
39
44
  updateMemoryRecordVisibility
40
45
  } from "./chunk-ZZLJUAEK.mjs";
41
- import {
42
- exportMemoryPortabilitySnapshot,
43
- importMemoryPortabilitySnapshot,
44
- verifyMemoryPortabilitySnapshot
45
- } from "./chunk-6SJTUWEO.mjs";
46
46
  import {
47
47
  buildContextPackForTurn
48
- } from "./chunk-CORUFGMR.mjs";
48
+ } from "./chunk-MPGMU75K.mjs";
49
49
  import {
50
50
  generateSkillEvolutionSuggestions
51
51
  } from "./chunk-J72V5GVI.mjs";
@@ -62,16 +62,13 @@ import {
62
62
  } from "./chunk-LWCO2YNI.mjs";
63
63
  import {
64
64
  importLocalMemorySources
65
- } from "./chunk-KCZIK3TH.mjs";
66
- import {
67
- executeRegisteredContextCompact
68
- } from "./chunk-UH6VXWMV.mjs";
65
+ } from "./chunk-2QCX6RPN.mjs";
69
66
  import {
70
67
  updateRunLedger
71
68
  } from "./chunk-4WWT6OC2.mjs";
72
69
  import {
73
- runMemoryConsolidation
74
- } from "./chunk-M2GS2K6H.mjs";
70
+ executeRegisteredContextCompact
71
+ } from "./chunk-UH6VXWMV.mjs";
75
72
  import {
76
73
  ingestMemoryEvent
77
74
  } from "./chunk-EZ2UKNOZ.mjs";
@@ -81,6 +78,9 @@ import {
81
78
  readMemoryWritePolicy,
82
79
  updateMemoryWritePolicy
83
80
  } from "./chunk-2NY5IEPV.mjs";
81
+ import {
82
+ runMemoryConsolidation
83
+ } from "./chunk-M2GS2K6H.mjs";
84
84
  import {
85
85
  buildMemoryProviderAccelerationPlan,
86
86
  readLastMemoryProviderAccelerationPlan,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseBatonHandoffFromText
3
- } from "./chunk-BHMWYAVS.mjs";
3
+ } from "./chunk-YYDDQEY4.mjs";
4
4
  import {
5
5
  buildGroupMemberAliases
6
6
  } from "./chunk-MXXTDG5V.mjs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  callCompactSummarizerRouteLlm,
3
3
  resolveConductorLlmRouteAsync
4
- } from "./chunk-JG3EPJ32.mjs";
4
+ } from "./chunk-HAI7DJD2.mjs";
5
5
  import {
6
6
  parsePostAgentIntentJson
7
7
  } from "./chunk-XEGXKEIR.mjs";
package/dist/index.js CHANGED
@@ -39902,6 +39902,199 @@ function parseOpenAiCompletionsSseDataLine(line) {
39902
39902
  }
39903
39903
  }
39904
39904
 
39905
+ // src/mobile/native-request-diagnostics.ts
39906
+ function compactLogValue(value, maxLen = 180) {
39907
+ const text2 = String(value ?? "").replace(/\s+/g, " ").trim();
39908
+ if (!text2) {
39909
+ return "";
39910
+ }
39911
+ return text2.length > maxLen ? `${text2.slice(0, maxLen)}...` : text2;
39912
+ }
39913
+ function readErrorProp(value, key2) {
39914
+ return value && typeof value === "object" ? value[key2] : void 0;
39915
+ }
39916
+ function positiveInteger2(value) {
39917
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
39918
+ return void 0;
39919
+ }
39920
+ return Math.trunc(value);
39921
+ }
39922
+ function formatNativeFetchErrorForLog(error) {
39923
+ const parts = [];
39924
+ let current = error;
39925
+ for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
39926
+ const prefix = depth === 0 ? "error" : `cause${depth}`;
39927
+ const name = compactLogValue(readErrorProp(current, "name"));
39928
+ const message = current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current);
39929
+ const code = compactLogValue(readErrorProp(current, "code"));
39930
+ const errno = compactLogValue(readErrorProp(current, "errno"));
39931
+ if (name) parts.push(`${prefix}Name=${name}`);
39932
+ if (message) parts.push(`${prefix}Message=${message}`);
39933
+ if (code) parts.push(`${prefix}Code=${code}`);
39934
+ if (errno) parts.push(`${prefix}Errno=${errno}`);
39935
+ current = readErrorProp(current, "cause");
39936
+ }
39937
+ return parts.join(" ") || "error=unknown";
39938
+ }
39939
+ function applyConfiguredMaxTokens(requestBody, maxTokens) {
39940
+ const configured = positiveInteger2(maxTokens);
39941
+ if (configured === void 0) {
39942
+ return;
39943
+ }
39944
+ const existing = positiveInteger2(requestBody.max_tokens);
39945
+ requestBody.max_tokens = existing === void 0 ? configured : Math.min(existing, configured);
39946
+ }
39947
+ function stringifyJsonRequestBody(requestBody) {
39948
+ const bodyText = JSON.stringify(requestBody);
39949
+ return {
39950
+ bodyText,
39951
+ bodyBytes: Buffer.byteLength(bodyText, "utf8")
39952
+ };
39953
+ }
39954
+ function formatRequestShape(input) {
39955
+ const messageCount = Array.isArray(input.messages) ? input.messages.length : 0;
39956
+ const toolCount = Array.isArray(input.tools) ? input.tools.length : 0;
39957
+ const maxTokens = positiveInteger2(input.maxTokens);
39958
+ return `bodyBytes=${input.bodyBytes} messages=${messageCount} tools=${toolCount} max_tokens=${maxTokens ?? "n/a"}`;
39959
+ }
39960
+ var DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS = 2;
39961
+ var HARD_PROVIDER_FETCH_MAX_ATTEMPTS = 4;
39962
+ var DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS = 350;
39963
+ var HARD_PROVIDER_FETCH_RETRY_BASE_MS = 5e3;
39964
+ var RETRYABLE_NATIVE_FETCH_RE = new RegExp(
39965
+ [
39966
+ "fetch failed",
39967
+ "UND_ERR_CONNECT_TIMEOUT",
39968
+ "UND_ERR_HEADERS_TIMEOUT",
39969
+ "UND_ERR_SOCKET",
39970
+ "ECONNRESET",
39971
+ "ETIMEDOUT",
39972
+ "ECONNREFUSED",
39973
+ "ENOTFOUND",
39974
+ "EAI_AGAIN",
39975
+ "socket hang up",
39976
+ "network connection lost",
39977
+ "network request failed"
39978
+ ].join("|"),
39979
+ "i"
39980
+ );
39981
+ function readClampedPositiveEnvInt(env, key2, fallback, max) {
39982
+ const raw = (env[key2] ?? "").trim();
39983
+ const n = Number.parseInt(raw, 10);
39984
+ if (!Number.isFinite(n) || n <= 0) {
39985
+ return fallback;
39986
+ }
39987
+ return Math.min(Math.trunc(n), max);
39988
+ }
39989
+ function readClampedNonNegativeEnvInt(env, key2, fallback, max) {
39990
+ const raw = (env[key2] ?? "").trim();
39991
+ const n = Number.parseInt(raw, 10);
39992
+ if (!Number.isFinite(n) || n < 0) {
39993
+ return fallback;
39994
+ }
39995
+ return Math.min(Math.trunc(n), max);
39996
+ }
39997
+ function readProviderFetchMaxAttempts(env) {
39998
+ return readClampedPositiveEnvInt(
39999
+ env,
40000
+ "XKZOOM_NATIVE_PROVIDER_FETCH_MAX_ATTEMPTS",
40001
+ DEFAULT_PROVIDER_FETCH_MAX_ATTEMPTS,
40002
+ HARD_PROVIDER_FETCH_MAX_ATTEMPTS
40003
+ );
40004
+ }
40005
+ function readProviderFetchRetryBaseMs(env) {
40006
+ return readClampedNonNegativeEnvInt(
40007
+ env,
40008
+ "XKZOOM_NATIVE_PROVIDER_FETCH_RETRY_BASE_MS",
40009
+ DEFAULT_PROVIDER_FETCH_RETRY_BASE_MS,
40010
+ HARD_PROVIDER_FETCH_RETRY_BASE_MS
40011
+ );
40012
+ }
40013
+ function isAbortLikeFetchError(error) {
40014
+ const name = compactLogValue(readErrorProp(error, "name"));
40015
+ return name === "AbortError";
40016
+ }
40017
+ function collectFetchErrorText(error) {
40018
+ const parts = [];
40019
+ let current = error;
40020
+ for (let depth = 0; depth < 4 && current !== null && current !== void 0; depth += 1) {
40021
+ parts.push(
40022
+ compactLogValue(readErrorProp(current, "name")),
40023
+ current instanceof Error ? compactLogValue(current.message) : compactLogValue(readErrorProp(current, "message") ?? current),
40024
+ compactLogValue(readErrorProp(current, "code")),
40025
+ compactLogValue(readErrorProp(current, "errno"))
40026
+ );
40027
+ current = readErrorProp(current, "cause");
40028
+ }
40029
+ return parts.filter(Boolean).join(" ");
40030
+ }
40031
+ function isRetryableNativeProviderFetchError(error) {
40032
+ return !isAbortLikeFetchError(error) && RETRYABLE_NATIVE_FETCH_RE.test(collectFetchErrorText(error));
40033
+ }
40034
+ function formatProviderRetryContext(context) {
40035
+ const parts = [
40036
+ `provider=${context.providerId}`,
40037
+ `model=${context.model}`,
40038
+ context.adapter ? `adapter=${context.adapter}` : "",
40039
+ typeof context.iteration === "number" ? `iteration=${context.iteration}` : ""
40040
+ ];
40041
+ return parts.filter(Boolean).join(" ");
40042
+ }
40043
+ function asAbortSignal(signal) {
40044
+ if (signal && typeof signal === "object" && "aborted" in signal) {
40045
+ return signal;
40046
+ }
40047
+ return void 0;
40048
+ }
40049
+ async function waitForProviderFetchRetryDelay(delayMs, signal) {
40050
+ if (delayMs <= 0) {
40051
+ return;
40052
+ }
40053
+ if (signal?.aborted) {
40054
+ throw new DOMException("Aborted", "AbortError");
40055
+ }
40056
+ await new Promise((resolve10, reject) => {
40057
+ const timer = setTimeout(() => {
40058
+ signal?.removeEventListener("abort", onAbort);
40059
+ resolve10();
40060
+ }, delayMs);
40061
+ const onAbort = () => {
40062
+ clearTimeout(timer);
40063
+ reject(new DOMException("Aborted", "AbortError"));
40064
+ };
40065
+ signal?.addEventListener("abort", onAbort, { once: true });
40066
+ });
40067
+ }
40068
+ async function fetchNativeProviderWithRetry(url, init, context, env = process.env) {
40069
+ const maxAttempts = readProviderFetchMaxAttempts(env);
40070
+ const retryBaseMs = readProviderFetchRetryBaseMs(env);
40071
+ const signal = asAbortSignal(init.signal);
40072
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
40073
+ try {
40074
+ return await fetch(url, init);
40075
+ } catch (error) {
40076
+ const retry = attempt < maxAttempts && !signal?.aborted && isRetryableNativeProviderFetchError(error);
40077
+ context.log(
40078
+ `[XKZOOM][native-reply][${context.label}] fetch_failed ${url} ${formatProviderRetryContext(context)} attempt=${attempt}/${maxAttempts} retry=${retry ? 1 : 0} ${formatRequestShape({
40079
+ bodyBytes: context.bodyBytes,
40080
+ messages: context.messages,
40081
+ tools: context.tools,
40082
+ maxTokens: context.maxTokens
40083
+ })} ${formatNativeFetchErrorForLog(error)}`
40084
+ );
40085
+ if (!retry) {
40086
+ throw error;
40087
+ }
40088
+ const delayMs = retryBaseMs * attempt;
40089
+ context.log(
40090
+ `[XKZOOM][native-reply][${context.label}] fetch_retry ${url} ${formatProviderRetryContext(context)} nextAttempt=${attempt + 1}/${maxAttempts} delayMs=${delayMs}`
40091
+ );
40092
+ await waitForProviderFetchRetryDelay(delayMs, signal);
40093
+ }
40094
+ }
40095
+ throw new Error(`native provider fetch retry exhausted: ${url}`);
40096
+ }
40097
+
39905
40098
  // src/mobile/native-openai-text-stream.ts
39906
40099
  var isRecord6 = isGatewayConfigRecord;
39907
40100
  function resolveOpenAiCompletionsBodyExtras(provider, baseUrl) {
@@ -40122,12 +40315,36 @@ async function runNativeOpenAiTextStreamToDispatcher(params) {
40122
40315
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
40123
40316
  params.log(formatProviderAccelerationApplication(providerAcceleration.application));
40124
40317
  }
40125
- const res = await fetch(url, {
40126
- method: "POST",
40127
- headers: buildBearerOpenAiHeaders(cfg),
40128
- body: JSON.stringify(requestBody),
40129
- signal: params.signal
40130
- });
40318
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
40319
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
40320
+ params.log(
40321
+ `[XKZOOM][native-reply][openai-completions] request_shape ${formatRequestShape({
40322
+ bodyBytes,
40323
+ messages: chatMessages,
40324
+ tools: toolsForRequest,
40325
+ maxTokens: requestBody.max_tokens
40326
+ })}`
40327
+ );
40328
+ const res = await fetchNativeProviderWithRetry(
40329
+ url,
40330
+ {
40331
+ method: "POST",
40332
+ headers: buildBearerOpenAiHeaders(cfg),
40333
+ body: bodyText,
40334
+ signal: params.signal
40335
+ },
40336
+ {
40337
+ label: "openai-completions",
40338
+ providerId: cfg.providerId,
40339
+ model: cfg.model,
40340
+ adapter: "openai-completions",
40341
+ bodyBytes,
40342
+ messages: chatMessages,
40343
+ tools: toolsForRequest,
40344
+ maxTokens: requestBody.max_tokens,
40345
+ log: params.log
40346
+ }
40347
+ );
40131
40348
  if (!res.ok) {
40132
40349
  const t = await res.text();
40133
40350
  throw new Error(`native OpenAI HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -41584,7 +41801,8 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
41584
41801
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
41585
41802
  params.log(formatProviderAccelerationApplication2(providerAcceleration.application));
41586
41803
  }
41587
- const thinkingForBody = selectAnthropicAdapterByBaseUrl(cfg.baseUrl).resolveThinkingForBody({
41804
+ const adapter = selectAnthropicAdapterByBaseUrl(cfg.baseUrl);
41805
+ const thinkingForBody = adapter.resolveThinkingForBody({
41588
41806
  reasoningMode: params.reasoningMode,
41589
41807
  model: cfg.model,
41590
41808
  configuredThinking: requestBody.thinking
@@ -41592,12 +41810,34 @@ async function runNativeAnthropicMessagesStreamToDispatcher(params) {
41592
41810
  if (thinkingForBody !== void 0) {
41593
41811
  requestBody.thinking = thinkingForBody;
41594
41812
  }
41595
- const res = await fetch(url, {
41596
- method: "POST",
41597
- headers: buildNativeAnthropicRequestHeaders(cfg),
41598
- body: JSON.stringify(requestBody),
41599
- signal: params.signal
41600
- });
41813
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
41814
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
41815
+ params.log(
41816
+ `[XKZOOM][native-reply][anthropic-messages] request_shape ${formatRequestShape({
41817
+ bodyBytes,
41818
+ messages: transcriptMessages,
41819
+ maxTokens: requestBody.max_tokens
41820
+ })}`
41821
+ );
41822
+ const res = await fetchNativeProviderWithRetry(
41823
+ url,
41824
+ {
41825
+ method: "POST",
41826
+ headers: buildNativeAnthropicRequestHeaders(cfg),
41827
+ body: bodyText,
41828
+ signal: params.signal
41829
+ },
41830
+ {
41831
+ label: "anthropic-messages",
41832
+ providerId: cfg.providerId,
41833
+ model: cfg.model,
41834
+ adapter: adapter.id,
41835
+ bodyBytes,
41836
+ messages: transcriptMessages,
41837
+ maxTokens: requestBody.max_tokens,
41838
+ log: params.log
41839
+ }
41840
+ );
41601
41841
  if (!res.ok) {
41602
41842
  const t = await res.text();
41603
41843
  throw new Error(`native anthropic-messages HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -43740,15 +43980,27 @@ function buildSessionTranscriptMeterFromMessages(messages) {
43740
43980
  var TRANSCRIPT_BUDGET_BYTES_PER_TOKEN = 4;
43741
43981
  var TRANSCRIPT_CONTEXT_WINDOW_RATIO = 0.35;
43742
43982
  var MIN_TRANSCRIPT_BUDGET_BYTES = 64 * 1024;
43743
- var MAX_TRANSCRIPT_BUDGET_BYTES = 4 * 1024 * 1024;
43744
- function positiveInteger2(value) {
43983
+ var DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES = 128 * 1024;
43984
+ var HARD_MAX_TRANSCRIPT_BUDGET_BYTES = 4 * 1024 * 1024;
43985
+ function positiveInteger3(value) {
43745
43986
  if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
43746
43987
  return void 0;
43747
43988
  }
43748
43989
  return Math.trunc(value);
43749
43990
  }
43991
+ function readMaxTranscriptBudgetBytes(env = process.env) {
43992
+ const raw = env.XKZOOM_NATIVE_TRANSCRIPT_MAX_REQUEST_BYTES?.trim();
43993
+ if (!raw) {
43994
+ return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
43995
+ }
43996
+ const parsed = Number.parseInt(raw, 10);
43997
+ if (!Number.isFinite(parsed) || parsed <= 0) {
43998
+ return DEFAULT_MAX_NATIVE_TRANSCRIPT_BUDGET_BYTES;
43999
+ }
44000
+ return Math.min(HARD_MAX_TRANSCRIPT_BUDGET_BYTES, Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, parsed));
44001
+ }
43750
44002
  function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
43751
- const tokens = positiveInteger2(contextWindowTokens);
44003
+ const tokens = positiveInteger3(contextWindowTokens);
43752
44004
  if (tokens === void 0) {
43753
44005
  return void 0;
43754
44006
  }
@@ -43756,7 +44008,7 @@ function resolveTranscriptBudgetBytesForContextWindow(contextWindowTokens) {
43756
44008
  tokens * TRANSCRIPT_CONTEXT_WINDOW_RATIO * TRANSCRIPT_BUDGET_BYTES_PER_TOKEN
43757
44009
  );
43758
44010
  return Math.min(
43759
- MAX_TRANSCRIPT_BUDGET_BYTES,
44011
+ readMaxTranscriptBudgetBytes(),
43760
44012
  Math.max(MIN_TRANSCRIPT_BUDGET_BYTES, estimated)
43761
44013
  );
43762
44014
  }
@@ -57545,15 +57797,37 @@ async function runNativeOpenAiCompletionsTurnToDispatcher(params) {
57545
57797
  if (params.providerAccelerationPlan || providerAcceleration.application.applied || providerAcceleration.application.warnings.length > 0) {
57546
57798
  params.log(formatProviderAccelerationApplication3(providerAcceleration.application));
57547
57799
  }
57800
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
57801
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
57548
57802
  params.log(
57549
- `[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}`
57803
+ `[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({
57804
+ bodyBytes,
57805
+ messages,
57806
+ tools: toolsForRequest,
57807
+ maxTokens: requestBody.max_tokens
57808
+ })
57809
+ );
57810
+ const res = await fetchNativeProviderWithRetry(
57811
+ url,
57812
+ {
57813
+ method: "POST",
57814
+ headers: adapter.buildHeaders(cfg),
57815
+ body: bodyText,
57816
+ signal: params.signal
57817
+ },
57818
+ {
57819
+ label: "openai-turn",
57820
+ providerId: cfg.providerId,
57821
+ model: cfg.model,
57822
+ adapter: adapter.id,
57823
+ iteration,
57824
+ bodyBytes,
57825
+ messages,
57826
+ tools: toolsForRequest,
57827
+ maxTokens: requestBody.max_tokens,
57828
+ log: params.log
57829
+ }
57550
57830
  );
57551
- const res = await fetch(url, {
57552
- method: "POST",
57553
- headers: adapter.buildHeaders(cfg),
57554
- body: JSON.stringify(requestBody),
57555
- signal: params.signal
57556
- });
57557
57831
  if (!res.ok) {
57558
57832
  const t = await res.text();
57559
57833
  if (policyToolChoiceApplied && requestAttempt === 0 && isOpenAiToolChoiceCompatibilityHttpError(res.status, t)) {
@@ -58384,15 +58658,37 @@ function createFetchAnthropicTurnStreamFn(cfg, log, providerAccelerationPlan, pr
58384
58658
  toolChoiceLog = `skipped(${policy.kind}:adapter-undefined)`;
58385
58659
  }
58386
58660
  }
58661
+ applyConfiguredMaxTokens(requestBody, cfg.maxTokens);
58662
+ const { bodyText, bodyBytes } = stringifyJsonRequestBody(requestBody);
58387
58663
  log(
58388
- `[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")
58664
+ `[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({
58665
+ bodyBytes,
58666
+ messages: req.messages,
58667
+ tools: req.tools,
58668
+ maxTokens: requestBody.max_tokens
58669
+ })}`
58670
+ );
58671
+ const res = await fetchNativeProviderWithRetry(
58672
+ url,
58673
+ {
58674
+ method: "POST",
58675
+ headers,
58676
+ body: bodyText,
58677
+ signal
58678
+ },
58679
+ {
58680
+ label: "anthropic-turn",
58681
+ providerId: cfg.providerId,
58682
+ model: cfg.model,
58683
+ adapter: adapter.id,
58684
+ iteration: req.iteration,
58685
+ bodyBytes,
58686
+ messages: req.messages,
58687
+ tools: req.tools,
58688
+ maxTokens: requestBody.max_tokens,
58689
+ log
58690
+ }
58389
58691
  );
58390
- const res = await fetch(url, {
58391
- method: "POST",
58392
- headers,
58393
- body: JSON.stringify(requestBody),
58394
- signal
58395
- });
58396
58692
  if (!res.ok) {
58397
58693
  const t = await res.text();
58398
58694
  throw new Error(`native anthropic-turn HTTP ${res.status}: ${t.slice(0, 500)}`);
@@ -58642,6 +58938,9 @@ function createInterruptedTurnSnapshot(params) {
58642
58938
  ...clipText(errMessage, MAX_PREVIEW_CHARS) ? { errorMessage: clipText(errMessage, MAX_PREVIEW_CHARS) } : {}
58643
58939
  };
58644
58940
  }
58941
+ function hasInterruptedTurnRecoveryEvidence(snapshot) {
58942
+ return snapshot.visibleTextLength > 0 || Boolean(snapshot.assistantPartialText?.trim()) || Boolean(snapshot.toolCallSummaries?.length);
58943
+ }
58645
58944
  function isInterruptedTurnResumeRequest(text2) {
58646
58945
  const raw = typeof text2 === "string" ? text2.trim() : "";
58647
58946
  if (!raw) {
@@ -62725,6 +63024,12 @@ ${inbound.bodyText}` : inbound.bodyText;
62725
63024
  lastToolName: params.lastToolName ?? lastToolNameForInterruptedTurn,
62726
63025
  error: params.error
62727
63026
  });
63027
+ if (!hasInterruptedTurnRecoveryEvidence(snapshot)) {
63028
+ this.logInfo(
63029
+ `[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}`
63030
+ );
63031
+ return null;
63032
+ }
62728
63033
  target.interruptedTurn = snapshot;
62729
63034
  this.store.persistMessage(session.id, target.id);
62730
63035
  this.logInfo(