@openclaw/ai 2026.10.10 → 2026.11.5-beta.1

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 (138) hide show
  1. package/README.md +11 -1
  2. package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
  3. package/dist/anthropic-CTND83W3.mjs +182 -0
  4. package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
  5. package/dist/{anthropic-stream-reducer-C__ByTq1.mjs → anthropic-stream-lifecycle-rJe4OH5H.mjs} +845 -649
  6. package/dist/{anthropic-tool-projection-JTvMo4KG.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
  7. package/dist/{anthropic-tool-projection-DA_KeluM.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
  8. package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
  9. package/dist/assistant-output-CD4kY9gu.mjs +16 -0
  10. package/dist/{azure-openai-responses-DHzTwi-y.mjs → azure-openai-responses-BhoLtP4Z.mjs} +46 -52
  11. package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
  12. package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
  13. package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
  14. package/dist/{diagnostics-Cv7cW3pS.mjs → diagnostics-CloVGQiK.mjs} +42 -19
  15. package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
  16. package/dist/diagnostics.d.mts +6 -7
  17. package/dist/diagnostics.mjs +4 -4
  18. package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
  19. package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
  20. package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
  21. package/dist/event-stream.d.mts +2 -2
  22. package/dist/event-stream.mjs +1 -2
  23. package/dist/expect-lbe3Hgrh.mjs +8 -0
  24. package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
  25. package/dist/{google-CZ6uGVkV.mjs → google-1uObh-eI.mjs} +7 -8
  26. package/dist/{google-interactions-qd4flmND.mjs → google-interactions-CY8Xb87S.mjs} +208 -233
  27. package/dist/{google-messages-B-svbJuN.mjs → google-messages-CwBqSoa4.mjs} +16 -13
  28. package/dist/{google-provider-stream-DlhaCvCf.mjs → google-provider-stream-D30s9EZp.mjs} +17 -10
  29. package/dist/{google-shared-Cif7nve-.mjs → google-shared-li0lmEZK.mjs} +70 -42
  30. package/dist/{google-vertex-BZTcYnWU.mjs → google-vertex-B5CHglca.mjs} +3 -3
  31. package/dist/{host-rCxf5Tjd.mjs → host-DX7ORpeH.mjs} +57 -46
  32. package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
  33. package/dist/{host-policy-Ci1cKluf.mjs → host-policy-jCZebuXx.mjs} +2 -2
  34. package/dist/index-Bczt0MnO.d.mts +17 -0
  35. package/dist/index.d.mts +8 -7
  36. package/dist/index.mjs +9 -7
  37. package/dist/internal/anthropic.d.mts +21 -26
  38. package/dist/internal/anthropic.mjs +6 -6
  39. package/dist/internal/google-model-family.mjs +1 -1
  40. package/dist/internal/google.d.mts +15 -0
  41. package/dist/internal/google.mjs +1 -0
  42. package/dist/internal/model-request-body.d.mts +37 -0
  43. package/dist/internal/model-request-body.mjs +106 -0
  44. package/dist/internal/openai-completions-compat.d.mts +5 -1
  45. package/dist/internal/openai-completions-compat.mjs +3 -2
  46. package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
  47. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  48. package/dist/internal/openai.d.mts +14 -12
  49. package/dist/internal/openai.mjs +11 -10
  50. package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
  51. package/dist/{reasoning-tag-text-partitioner-DzlRubwU.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -122
  52. package/dist/internal/retry-after.d.mts +2 -2
  53. package/dist/internal/retry-after.mjs +165 -27
  54. package/dist/internal/runtime.d.mts +15 -41
  55. package/dist/internal/runtime.mjs +9 -10
  56. package/dist/internal/shared.d.mts +21 -25
  57. package/dist/internal/shared.mjs +9 -98
  58. package/dist/internal/tool-schema.d.mts +10 -10
  59. package/dist/internal/tool-schema.mjs +4 -4
  60. package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
  61. package/dist/mistral-F5_asrmU.mjs +3741 -0
  62. package/dist/mistral.LICENSE +201 -0
  63. package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
  64. package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
  65. package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
  66. package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
  67. package/dist/{openai-chatgpt-responses-iGYDPbmc.mjs → openai-chatgpt-responses-BIK7HROH.mjs} +61 -80
  68. package/dist/{openai-completions-CDy5u1mv.mjs → openai-completions-ClJ7QHEB.mjs} +5 -5
  69. package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
  70. package/dist/{openai-completions-compat-CJ0OXZgi.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
  71. package/dist/openai-completions-reasoning-replay-BwT1xwRI.mjs +45 -0
  72. package/dist/{openai-completions-transport-DLrm5EWi.mjs → openai-completions-transport-C6J4_oGf.mjs} +501 -563
  73. package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
  74. package/dist/{openai-prompt-cache-h8vXRiaH.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
  75. package/dist/openai-responses-Beifmf1s.mjs +89 -0
  76. package/dist/{openai-responses-compaction-replay-DUBbsfku.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
  77. package/dist/{openai-responses-contracts-gnl6ZRs1.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
  78. package/dist/{openai-responses-contracts-DCG51Us0.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
  79. package/dist/{openai-responses-endpoint-JbBT8IDv.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
  80. package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
  81. package/dist/{openai-responses-request-lifecycle-DuMpdA6y.mjs → openai-responses-request-lifecycle-o-ODC_rF.mjs} +12 -26
  82. package/dist/{openai-responses-shared-CNfHudFg.mjs → openai-responses-shared-CrFDkZ0N.mjs} +637 -389
  83. package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
  84. package/dist/{openai-tool-schema-CGhEl7ao.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
  85. package/dist/otel-D-BkX8bB.mjs +766 -0
  86. package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
  87. package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
  88. package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
  89. package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
  90. package/dist/{provider-options-Bo8GzTGX.d.mts → provider-options-Mo8NM5d1.d.mts} +15 -4
  91. package/dist/{provider-replay-context-BC23HyZo.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
  92. package/dist/provider-transcript-transform-BHq3Q4nc.mjs +32 -0
  93. package/dist/{provider-transport-turn-state-B11rmZpv.mjs → provider-transport-turn-state-DQd9K4Pd.mjs} +3 -3
  94. package/dist/{provider-types-ODq57rG_.d.mts → provider-types-B1e98js5.d.mts} +6 -4
  95. package/dist/provider-types.d.mts +7 -6
  96. package/dist/provider-types.mjs +2 -1
  97. package/dist/providers.d.mts +2 -2
  98. package/dist/providers.mjs +26 -29
  99. package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
  100. package/dist/request-headers-DO4Mqhw1.mjs +10 -0
  101. package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
  102. package/dist/retry-after-DnHBlFS2.d.mts +45 -0
  103. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  104. package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
  105. package/dist/{simple-options-BdJJbzZk.mjs → simple-options-tLSeECry.mjs} +108 -82
  106. package/dist/src-BUsVkrNt.mjs +105 -0
  107. package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
  108. package/dist/stable-stringify-CchQEmeA.mjs +84 -0
  109. package/dist/{stream-DQqGjhbq.mjs → stream-DrtAWu7c.mjs} +2 -6
  110. package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
  111. package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
  112. package/dist/string-normalization-B8TDDBX_.mjs +32 -0
  113. package/dist/telemetry-B9f7K_Xe.mjs +582 -0
  114. package/dist/{tool-schema-json-projection-Cvq69Ajp.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
  115. package/dist/{transport-stream-shared-DdnJGEj0.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
  116. package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
  117. package/dist/{transport-utils-CcCAuFVS.mjs → transport-utils-Da_39MYi.mjs} +23 -38
  118. package/dist/transports.d.mts +39 -38
  119. package/dist/transports.mjs +214 -295
  120. package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
  121. package/dist/types-Cb3-5WM9.d.mts +1 -0
  122. package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
  123. package/dist/types.d.mts +7 -6
  124. package/dist/types.mjs +7 -5
  125. package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
  126. package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
  127. package/dist/validation.d.mts +1 -1
  128. package/dist/validation.mjs +1 -2
  129. package/package.json +40 -6
  130. package/dist/anthropic-B54Ts1tV.mjs +0 -221
  131. package/dist/assistant-output-DbgdWAhJ.mjs +0 -47
  132. package/dist/event-stream-CDpFza-M.d.mts +0 -1
  133. package/dist/index-DSprYWaz.d.mts +0 -185
  134. package/dist/mistral-C_ImzxlK.mjs +0 -512
  135. package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
  136. package/dist/openai-responses-Cp2QPq7K.mjs +0 -87
  137. package/dist/retry-after-sw-XX8aC.d.mts +0 -15
  138. package/dist/types-CBJthzJX.d.mts +0 -1
@@ -1,16 +1,6 @@
1
- import { l as expectDefined } from "./provider-error-qtZD2inE.mjs";
2
- //#region \0rolldown/runtime.js
3
- var __defProp = Object.defineProperty;
4
- var __exportAll = (all, no_symbols) => {
5
- let target = {};
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
- return target;
12
- };
13
- //#endregion
1
+ import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
2
+ import "../src-BUsVkrNt.mjs";
3
+ import { t as expectDefined } from "../expect-lbe3Hgrh.mjs";
14
4
  //#region node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
15
5
  /**
16
6
  * @typedef {import('mdast').Nodes} Nodes
@@ -11842,7 +11832,7 @@ function getPoint(events, index) {
11842
11832
  return event[1][side];
11843
11833
  }
11844
11834
  //#endregion
11845
- //#region packages/markdown-core/src/reasoning-tag-parser.ts
11835
+ //#region packages/markdown-core/src/reasoning-tag-syntax.ts
11846
11836
  const REASONING_TAG_NAMES = [
11847
11837
  "think",
11848
11838
  "thinking",
@@ -11860,7 +11850,6 @@ const REASONING_TAG_NAMES = [
11860
11850
  "mm:reasoning"
11861
11851
  ];
11862
11852
  const REASONING_TAG_NAME_SET = new Set(REASONING_TAG_NAMES);
11863
- const DISABLE_HTML_MARKDOWN = { disable: { null: ["htmlFlow", "htmlText"] } };
11864
11853
  /** Scans quote-aware provider reasoning tags with iterative malformed recovery. */
11865
11854
  function scanReasoningTags(text, final = true) {
11866
11855
  const tags = [];
@@ -11964,6 +11953,143 @@ function findNextLineEnding(text, start) {
11964
11953
  if (carriageReturn === -1) return lineFeed;
11965
11954
  return lineFeed === -1 ? carriageReturn : Math.min(carriageReturn, lineFeed);
11966
11955
  }
11956
+ function isInsideCode(index, spans) {
11957
+ let low = 0;
11958
+ let high = spans.length - 1;
11959
+ while (low <= high) {
11960
+ const middle = Math.floor((low + high) / 2);
11961
+ const span = spans[middle];
11962
+ if (!span) return false;
11963
+ if (index < span[0]) high = middle - 1;
11964
+ else if (index >= span[1]) low = middle + 1;
11965
+ else return true;
11966
+ }
11967
+ return false;
11968
+ }
11969
+ function reduceReasoningText(text, codeSpans, state, options) {
11970
+ const output = [];
11971
+ const checkpoint = options.checkpoint;
11972
+ let openStart;
11973
+ const emit = (kind, value) => {
11974
+ if (!value) return;
11975
+ const previous = output.at(-1);
11976
+ if (previous?.kind === kind) previous.text += value;
11977
+ else output.push({
11978
+ kind,
11979
+ text: value
11980
+ });
11981
+ if (kind === "text" && value.trim()) state.visibleEver = true;
11982
+ };
11983
+ const append = (value) => {
11984
+ if (!value) return;
11985
+ if (state.depth > 0 && state.pending) {
11986
+ state.pending.content += value;
11987
+ state.pending.protectedClose ||= scanReasoningTags(value).tags.some((tag) => tag.isClose);
11988
+ } else emit("text", value);
11989
+ };
11990
+ const start = options.start ?? 0;
11991
+ const scan = scanReasoningTags(text.slice(start), options.final);
11992
+ const tags = [];
11993
+ for (const scannedTag of scan.tags) {
11994
+ const index = scannedTag.index + start;
11995
+ if (!isInsideCode(index, codeSpans)) tags.push({
11996
+ ...scannedTag,
11997
+ index
11998
+ });
11999
+ }
12000
+ const mustParseRemainder = [];
12001
+ if (options.scope === "leading") {
12002
+ let mustParse = false;
12003
+ for (let index = tags.length - 1; index >= 0; index -= 1) {
12004
+ mustParse ||= tags[index]?.isPrivate === true;
12005
+ mustParseRemainder[index] = mustParse;
12006
+ mustParse ||= tags[index]?.isClose === true;
12007
+ }
12008
+ }
12009
+ let cursor = start;
12010
+ for (const [tagIndex, tag] of tags.entries()) {
12011
+ const beforeTag = text.slice(cursor, tag.index);
12012
+ append(beforeTag);
12013
+ const tagEnd = tag.index + tag.text.length;
12014
+ if (checkpoint && tag.index < checkpoint.boundary && tagEnd > checkpoint.boundary) checkpoint.holdStart = Math.min(checkpoint.holdStart, tag.index);
12015
+ if (tag.isSelfClosing) {
12016
+ if (checkpoint && state.depth === 0 && options.scope === "leading" && state.visibleEver) checkpoint.terminalLiteral = true;
12017
+ if (state.depth === 0 && options.scope === "leading" && state.visibleEver) {
12018
+ emit("text", text.slice(tag.index));
12019
+ cursor = text.length;
12020
+ break;
12021
+ }
12022
+ cursor = tagEnd;
12023
+ continue;
12024
+ }
12025
+ if (!tag.isClose) {
12026
+ if (state.depth === 0 && options.scope === "leading" && state.visibleEver && !mustParseRemainder[tagIndex]) {
12027
+ if (checkpoint) checkpoint.holdStart = Math.min(checkpoint.holdStart, tag.index);
12028
+ emit("text", text.slice(tag.index));
12029
+ cursor = text.length;
12030
+ break;
12031
+ }
12032
+ if (state.depth === 0) {
12033
+ openStart = tag.index;
12034
+ state.pending = {
12035
+ content: "",
12036
+ containsPrivate: tag.isPrivate,
12037
+ openTag: tag.text,
12038
+ protectedClose: false,
12039
+ visibleBefore: state.visibleEver
12040
+ };
12041
+ } else if (state.pending) state.pending.containsPrivate ||= tag.isPrivate;
12042
+ state.depth += 1;
12043
+ cursor = tagEnd;
12044
+ continue;
12045
+ }
12046
+ if (state.depth > 0) {
12047
+ state.depth -= 1;
12048
+ if (state.depth === 0 && state.pending) {
12049
+ if (checkpoint && openStart !== void 0 && openStart < checkpoint.boundary && tagEnd > checkpoint.boundary) checkpoint.holdStart = Math.min(checkpoint.holdStart, openStart);
12050
+ openStart = void 0;
12051
+ if (!state.pending.containsPrivate) emit("thinking", state.pending.content);
12052
+ state.pending = void 0;
12053
+ } else if (state.pending) state.pending.protectedClose = true;
12054
+ cursor = tagEnd;
12055
+ continue;
12056
+ }
12057
+ if (options.mode === "visible") append(tag.text);
12058
+ else {
12059
+ const after = text.slice(tagEnd);
12060
+ const rawBefore = Boolean(beforeTag.trim()) || cursor === start && checkpoint?.rawBefore;
12061
+ if (checkpoint && rawBefore && !after.trim()) checkpoint.holdStart = Math.min(checkpoint.holdStart, tag.index);
12062
+ if (rawBefore && after.trim()) {
12063
+ if (checkpoint) {
12064
+ checkpoint.reset = true;
12065
+ checkpoint.lastReset = tag.index;
12066
+ }
12067
+ const thinking = output.filter((delta) => delta.kind === "thinking");
12068
+ output.splice(0, output.length, ...thinking);
12069
+ state.visibleEver = false;
12070
+ }
12071
+ }
12072
+ cursor = tagEnd;
12073
+ }
12074
+ append(text.slice(cursor));
12075
+ if (checkpoint) {
12076
+ checkpoint.rawBefore = Boolean(text.slice(cursor).trim()) || cursor === start && checkpoint.rawBefore;
12077
+ if (openStart !== void 0) checkpoint.holdStart = Math.min(checkpoint.holdStart, openStart);
12078
+ }
12079
+ if (options.final && state.depth > 0 && state.pending) {
12080
+ const pending = state.pending;
12081
+ if (!pending.containsPrivate) {
12082
+ if ((options.mode === "static-preserve" || options.mode === "static-strict" && !pending.visibleBefore && !pending.protectedClose || options.mode === "visible" && !pending.protectedClose) && options.recoverUnclosed !== false) emit("text", options.mode === "visible" && pending.visibleBefore ? pending.openTag + pending.content : pending.content);
12083
+ else emit("thinking", pending.content);
12084
+ }
12085
+ state.depth = 0;
12086
+ state.pending = void 0;
12087
+ }
12088
+ return output;
12089
+ }
12090
+ //#endregion
12091
+ //#region packages/markdown-core/src/reasoning-tag-parser.ts
12092
+ const DISABLE_HTML_MARKDOWN = { disable: { null: ["htmlFlow", "htmlText"] } };
11967
12093
  function appendMarkdownSource(source, start, token, value) {
11968
12094
  const extra = value.length - (token.end.offset - token.start.offset);
11969
12095
  for (let cursor = start + source.offsets.length; cursor < token.end.offset; cursor += 1) {
@@ -12044,6 +12170,8 @@ function parseMarkdownOwnership(text, options) {
12044
12170
  textSpans: [],
12045
12171
  retainStart: 0,
12046
12172
  completedParagraphs: [],
12173
+ definitions: [],
12174
+ unsettledDefinitionStarts: [],
12047
12175
  ...paragraphs ? { paragraphs } : {}
12048
12176
  };
12049
12177
  const sources = /* @__PURE__ */ new Map();
@@ -12061,13 +12189,17 @@ function parseMarkdownOwnership(text, options) {
12061
12189
  const completedParagraphs = [];
12062
12190
  const regions = [];
12063
12191
  const textSpans = [];
12192
+ const definitions = [];
12193
+ let unresolvedImageCodeStart;
12064
12194
  const blocks = tree.children ?? [];
12195
+ let retainStart = findListItemRetentionStart(text, blocks);
12065
12196
  for (let index = 0; index < blocks.length; index += 1) {
12066
12197
  const block = expectDefined(blocks[index], "Markdown block");
12067
12198
  const next = blocks[index + 1]?.position?.start;
12068
12199
  const blockStart = block.position?.start?.offset;
12069
12200
  const endLine = block.position?.end?.line;
12070
12201
  const blockEnd = block.position?.end?.offset;
12202
+ retainStart = retainTableParagraph(retainStart, text.length, block, blocks[index - 1]);
12071
12203
  if (paragraphs && block.type === "paragraph" && blockStart !== void 0 && blockEnd !== void 0) paragraphs.push({
12072
12204
  start: blockStart,
12073
12205
  end: blockEnd
@@ -12082,11 +12214,23 @@ function parseMarkdownOwnership(text, options) {
12082
12214
  completedParagraphs.push(paragraph);
12083
12215
  }
12084
12216
  const pending = [block];
12217
+ const regionStart = regions.length;
12218
+ let hasReferenceCandidate = false;
12219
+ let hasInlineCode = false;
12085
12220
  while (pending.length > 0) {
12086
12221
  const node = expectDefined(pending.pop(), "Markdown ownership node");
12087
- if (paragraph && node.type === "text" && node.value?.includes("[")) paragraph.hasReferenceCandidate = true;
12222
+ if (node.type === "text" && node.value?.includes("[")) {
12223
+ hasReferenceCandidate = true;
12224
+ if (paragraph) paragraph.hasReferenceCandidate = true;
12225
+ }
12226
+ hasInlineCode ||= node.type === "inlineCode";
12088
12227
  const start = node.position?.start?.offset;
12089
12228
  const end = node.position?.end?.offset;
12229
+ if (node.type === "definition" && node.identifier !== void 0 && start !== void 0 && end !== void 0) definitions.push({
12230
+ identifier: node.identifier,
12231
+ start,
12232
+ end
12233
+ });
12090
12234
  if (options?.includeText && node.type === "text" && start !== void 0 && end !== void 0) textSpans.push([start, end]);
12091
12235
  if ((node.type === "code" || node.type === "inlineCode") && start !== void 0 && end !== void 0) {
12092
12236
  const source = sources.get(start);
@@ -12109,131 +12253,178 @@ function parseMarkdownOwnership(text, options) {
12109
12253
  }
12110
12254
  for (const child of node.children?.toReversed() ?? []) pending.push(child);
12111
12255
  }
12256
+ if (hasReferenceCandidate && hasInlineCode && blockStart !== void 0 && blockEnd !== void 0 && scanBracketOwnership(text, blockStart, blockEnd, regions, regionStart).hasImageCode) {
12257
+ unresolvedImageCodeStart = blockStart;
12258
+ retainStart = Math.min(retainStart, blockStart);
12259
+ }
12112
12260
  }
12261
+ const { unsettledDefinitionStarts, retainStart: referenceStart } = findReferenceDefinitionRetention(text, definitions);
12262
+ retainStart = findListItemRetentionStart(text, blocks, Math.min(retainStart, referenceStart));
12113
12263
  regions.sort((left, right) => left.start - right.start);
12264
+ const continuation = findContainerContinuation(text, blocks.at(-1), retainStart);
12114
12265
  return {
12115
12266
  regions,
12116
12267
  codeSpans: regions.map(({ start, end }) => [start, end]),
12117
12268
  textSpans,
12118
- retainStart: tree.children?.at(-1)?.position?.start?.offset ?? text.length,
12269
+ retainStart,
12270
+ ...continuation ? { continuation } : {},
12271
+ ...unresolvedImageCodeStart === void 0 ? {} : { unresolvedImageCodeStart },
12119
12272
  completedParagraphs,
12273
+ definitions,
12274
+ unsettledDefinitionStarts,
12120
12275
  ...paragraphs ? { paragraphs } : {}
12121
12276
  };
12122
12277
  }
12123
- function isInsideCode(index, spans) {
12124
- let low = 0;
12125
- let high = spans.length - 1;
12126
- while (low <= high) {
12127
- const middle = Math.floor((low + high) / 2);
12128
- const span = spans[middle];
12129
- if (!span) return false;
12130
- if (index < span[0]) high = middle - 1;
12131
- else if (index >= span[1]) low = middle + 1;
12132
- else return true;
12278
+ function scanBracketOwnership(text, start, end, regions, regionStart) {
12279
+ let regionIndex = regionStart;
12280
+ const brackets = [];
12281
+ let hasImageCode = false;
12282
+ for (let cursor = start; cursor < end; cursor += 1) {
12283
+ const region = regions[regionIndex];
12284
+ if (region?.start === cursor) {
12285
+ if (!region.block) for (const bracket of brackets) bracket.code ||= bracket.image;
12286
+ cursor = region.end - 1;
12287
+ regionIndex += 1;
12288
+ } else if (text[cursor] === "\\") cursor += 1;
12289
+ else if (text[cursor] === "!" && text[cursor + 1] === "[") {
12290
+ brackets.push({
12291
+ image: true,
12292
+ code: false
12293
+ });
12294
+ cursor += 1;
12295
+ } else if (text[cursor] === "[") brackets.push({
12296
+ image: false,
12297
+ code: false
12298
+ });
12299
+ else if (text[cursor] === "]" && brackets.pop()?.code) hasImageCode = true;
12133
12300
  }
12134
- return false;
12301
+ return {
12302
+ hasImageCode: hasImageCode || brackets.some((bracket) => bracket.image && bracket.code),
12303
+ hasOpenLabel: brackets.length > 0
12304
+ };
12135
12305
  }
12136
- function reduceReasoningText(text, codeSpans, state, options) {
12137
- const output = [];
12138
- const emit = (kind, value) => {
12139
- if (!value) return;
12140
- const previous = output.at(-1);
12141
- if (previous?.kind === kind) previous.text += value;
12142
- else output.push({
12143
- kind,
12144
- text: value
12145
- });
12146
- if (kind === "text" && value.trim()) state.visibleEver = true;
12306
+ /** Preserve an open container without retaining its already-stable literal lines. */
12307
+ function findContainerContinuation(text, block, retainStart) {
12308
+ const start = block?.position?.start?.offset;
12309
+ const end = block?.position?.end?.offset;
12310
+ if (start === void 0 || end === void 0 || retainStart < start || /\r(?!\n)/u.test(text)) return;
12311
+ const offset = text.lastIndexOf("\n", end - 1) + 1;
12312
+ if (offset <= start) return;
12313
+ if (block?.type === "code" && /^(?: {4}| {0,3}\t)/u.test(text.slice(start))) return {
12314
+ offset,
12315
+ context: " x\n"
12147
12316
  };
12148
- const append = (value) => {
12149
- if (!value) return;
12150
- if (state.depth > 0 && state.pending) {
12151
- state.pending.content += value;
12152
- state.pending.protectedClose ||= scanReasoningTags(value).tags.some((tag) => tag.isClose);
12153
- } else emit("text", value);
12317
+ const paragraph = block?.children?.length === 1 ? block.children[0] : void 0;
12318
+ const paragraphStart = paragraph?.position?.start?.offset;
12319
+ if (block?.type !== "blockquote" || paragraph?.type !== "paragraph" || paragraphStart === void 0) return;
12320
+ const prefix = text.slice(paragraphStart, offset);
12321
+ if (/[`|]|\][(:]/u.test(prefix) || scanBracketOwnership(text, paragraphStart, offset, [], 0).hasOpenLabel) return;
12322
+ return {
12323
+ offset,
12324
+ context: text.slice(start, paragraphStart) + "x\n"
12154
12325
  };
12155
- const start = options.start ?? 0;
12156
- const scan = scanReasoningTags(text.slice(start), options.final);
12157
- const tags = [];
12158
- for (const scannedTag of scan.tags) {
12159
- const index = scannedTag.index + start;
12160
- if (!isInsideCode(index, codeSpans)) tags.push({
12161
- ...scannedTag,
12162
- index
12163
- });
12164
- }
12165
- const mustParseRemainder = [];
12166
- if (options.scope === "leading") {
12167
- let mustParse = false;
12168
- for (let index = tags.length - 1; index >= 0; index -= 1) {
12169
- mustParse ||= tags[index]?.isPrivate === true;
12170
- mustParseRemainder[index] = mustParse;
12171
- mustParse ||= tags[index]?.isClose === true;
12172
- }
12173
- }
12326
+ }
12327
+ /** Retain the current item, including any container framing an earlier reference needs. */
12328
+ function findListItemRetentionStart(text, blocks, retainStart) {
12329
+ const offset = retainStart ?? blocks.at(-1)?.position?.start?.offset ?? text.length;
12330
+ const block = blocks.findLast((entry) => (entry.position?.start?.offset ?? Infinity) <= offset);
12331
+ if (block?.type !== "list") return offset;
12332
+ const completeLineEnd = Math.max(text.lastIndexOf("\n"), text.lastIndexOf("\r"));
12333
+ return block.children?.findLast((item) => {
12334
+ const start = item.position?.start?.offset;
12335
+ return start !== void 0 && start <= (retainStart ?? text.length) && start < completeLineEnd;
12336
+ })?.position?.start?.offset ?? offset;
12337
+ }
12338
+ function findReferenceDefinitionRetention(text, definitions) {
12339
+ const unsettledDefinitionStarts = definitions.filter((definition) => canStillHaveReferenceTitle(text, definition.end)).map(({ start }) => start);
12340
+ return {
12341
+ unsettledDefinitionStarts,
12342
+ retainStart: definitions.reduce((offset, { identifier, start }) => identifier.length > 999 ? Math.min(offset, start) : offset, Math.min(text.length, ...unsettledDefinitionStarts))
12343
+ };
12344
+ }
12345
+ function canStillHaveReferenceTitle(text, start) {
12174
12346
  let cursor = start;
12175
- for (const [tagIndex, tag] of tags.entries()) {
12176
- const beforeTag = text.slice(cursor, tag.index);
12177
- append(beforeTag);
12178
- const tagEnd = tag.index + tag.text.length;
12179
- if (tag.isSelfClosing) {
12180
- if (state.depth === 0 && options.scope === "leading" && state.visibleEver) {
12181
- emit("text", text.slice(tag.index));
12182
- cursor = text.length;
12183
- break;
12184
- }
12185
- cursor = tagEnd;
12347
+ while (text[cursor] === " " || text[cursor] === " ") cursor += 1;
12348
+ if (cursor === text.length) return true;
12349
+ const lineEndingWidth = getLineEndingWidth(text, cursor);
12350
+ if (lineEndingWidth > 0) {
12351
+ cursor += lineEndingWidth;
12352
+ if (cursor === text.length) return true;
12353
+ }
12354
+ const titleStart = findPossibleTitleStart(text, cursor);
12355
+ if (titleStart === void 0) return false;
12356
+ return hasUnclosedTitle(text, titleStart);
12357
+ }
12358
+ function findPossibleTitleStart(text, start) {
12359
+ let cursor = skipContainerPrefixes(text, start);
12360
+ while (text[cursor] === " " || text[cursor] === " ") cursor += 1;
12361
+ if (cursor === text.length) return cursor;
12362
+ const opening = text[cursor];
12363
+ return opening === "\"" || opening === "'" || opening === "(" ? cursor : void 0;
12364
+ }
12365
+ function skipContainerPrefixes(text, start) {
12366
+ let cursor = start;
12367
+ while (cursor < text.length) {
12368
+ let markerStart = cursor;
12369
+ while (text[markerStart] === " " || text[markerStart] === " ") markerStart += 1;
12370
+ if (text[markerStart] === ">") {
12371
+ cursor = markerStart + 1;
12372
+ if (text[cursor] === " " || text[cursor] === " ") cursor += 1;
12186
12373
  continue;
12187
12374
  }
12188
- if (!tag.isClose) {
12189
- if (state.depth === 0 && options.scope === "leading" && state.visibleEver && !mustParseRemainder[tagIndex]) {
12190
- emit("text", text.slice(tag.index));
12191
- cursor = text.length;
12192
- break;
12193
- }
12194
- if (state.depth === 0) state.pending = {
12195
- content: "",
12196
- containsPrivate: tag.isPrivate,
12197
- openTag: tag.text,
12198
- protectedClose: false,
12199
- visibleBefore: state.visibleEver
12200
- };
12201
- else if (state.pending) state.pending.containsPrivate ||= tag.isPrivate;
12202
- state.depth += 1;
12203
- cursor = tagEnd;
12375
+ const markerEnd = listMarkerEnd(text, markerStart);
12376
+ if (markerEnd > markerStart) {
12377
+ cursor = markerEnd;
12378
+ while (text[cursor] === " " || text[cursor] === " ") cursor += 1;
12204
12379
  continue;
12205
12380
  }
12206
- if (state.depth > 0) {
12207
- state.depth -= 1;
12208
- if (state.depth === 0 && state.pending) {
12209
- if (!state.pending.containsPrivate) emit("thinking", state.pending.content);
12210
- state.pending = void 0;
12211
- } else if (state.pending) state.pending.protectedClose = true;
12212
- cursor = tagEnd;
12213
- continue;
12214
- }
12215
- if (options.mode === "visible") append(tag.text);
12216
- else {
12217
- const after = text.slice(tagEnd);
12218
- if (beforeTag.trim() && after.trim()) {
12219
- const thinking = output.filter((delta) => delta.kind === "thinking");
12220
- output.splice(0, output.length, ...thinking);
12221
- state.visibleEver = false;
12222
- }
12223
- }
12224
- cursor = tagEnd;
12225
- }
12226
- append(text.slice(cursor));
12227
- if (options.final && state.depth > 0 && state.pending) {
12228
- const pending = state.pending;
12229
- if (!pending.containsPrivate) {
12230
- if ((options.mode === "static-preserve" || options.mode === "static-strict" && !pending.visibleBefore && !pending.protectedClose || options.mode === "visible" && !pending.protectedClose) && options.recoverUnclosed !== false) emit("text", options.mode === "visible" && pending.visibleBefore ? pending.openTag + pending.content : pending.content);
12231
- else emit("thinking", pending.content);
12232
- }
12233
- state.depth = 0;
12234
- state.pending = void 0;
12381
+ break;
12235
12382
  }
12236
- return output;
12383
+ return cursor;
12384
+ }
12385
+ function listMarkerEnd(text, start) {
12386
+ const first = text[start] ?? "";
12387
+ let markerEnd = start;
12388
+ if (first === "-" || first === "+" || first === "*") markerEnd += 1;
12389
+ else if (first >= "0" && first <= "9") {
12390
+ while ((text[markerEnd] ?? "") >= "0" && (text[markerEnd] ?? "") <= "9") markerEnd += 1;
12391
+ const delimiter = text[markerEnd] ?? "";
12392
+ if (markerEnd - start > 9 || delimiter !== "." && delimiter !== ")") return start;
12393
+ markerEnd += 1;
12394
+ } else return start;
12395
+ const trailingSpace = text[markerEnd];
12396
+ return trailingSpace === " " || trailingSpace === " " ? markerEnd : start;
12397
+ }
12398
+ function hasUnclosedTitle(text, start) {
12399
+ if (start === text.length) return true;
12400
+ const opening = text[start];
12401
+ if (opening !== "\"" && opening !== "'" && opening !== "(") return false;
12402
+ const closing = opening === "(" ? ")" : opening;
12403
+ let escaped = false;
12404
+ for (let cursor = start + 1; cursor < text.length; cursor += 1) {
12405
+ const character = text[cursor];
12406
+ if (escaped) escaped = false;
12407
+ else if (character === "\\") escaped = true;
12408
+ else if (character === closing) return false;
12409
+ const lineEndingWidth = getLineEndingWidth(text, cursor);
12410
+ if (lineEndingWidth > 0) {
12411
+ let nextLine = cursor + lineEndingWidth;
12412
+ while (text[nextLine] === " " || text[nextLine] === " ") nextLine += 1;
12413
+ if (getLineEndingWidth(text, nextLine) > 0) return false;
12414
+ cursor += lineEndingWidth - 1;
12415
+ }
12416
+ }
12417
+ return true;
12418
+ }
12419
+ function getLineEndingWidth(text, index) {
12420
+ if (text[index] === "\n") return 1;
12421
+ if (text[index] !== "\r") return 0;
12422
+ return text[index + 1] === "\n" ? 2 : 1;
12423
+ }
12424
+ /** An unfinished table delimiter can still rejoin its preceding paragraph. */
12425
+ function retainTableParagraph(retainStart, textLength, block, previous) {
12426
+ const startLine = block.position?.start?.line;
12427
+ return block.type === "table" && block.children?.length === 1 && block.position?.end?.offset === textLength && previous?.type === "paragraph" && startLine !== void 0 && previous.position?.end?.line === startLine - 1 ? Math.min(retainStart, previous.position?.start?.offset ?? retainStart) : retainStart;
12237
12428
  }
12238
12429
  //#endregion
12239
12430
  //#region packages/markdown-core/src/reasoning-tags.ts
@@ -12594,4 +12785,4 @@ function createReasoningTagTextPartitioner() {
12594
12785
  };
12595
12786
  }
12596
12787
  //#endregion
12597
- export { __exportAll as n, createReasoningTagTextPartitioner as t };
12788
+ export { createReasoningTagTextPartitioner };
@@ -1,2 +1,2 @@
1
- import { i as parseRetryAfterHttpDateMs, n as parseRetryAfterErrorSeconds, r as parseRetryAfterHeadersSeconds, t as parseHttpDateInstant } from "../retry-after-sw-XX8aC.mjs";
2
- export { parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterHeadersSeconds, parseRetryAfterHttpDateMs };
1
+ import { a as parseHttpDateInstant, c as parseRetryAfterHeadersSeconds, d as parseRetryAfterTextSeconds, f as resolveProviderErrorRetrySeconds, i as parseGoogleRetryDelaySeconds, l as parseRetryAfterHeadersTiming, n as RetryAfterTiming, o as parseRetryAfterErrorSeconds, r as hasExplicitRetryText, s as parseRetryAfterErrorTiming, t as RETRY_AFTER_TEXT_RE, u as parseRetryAfterHttpDateMs } from "../retry-after-DnHBlFS2.mjs";
2
+ export { RETRY_AFTER_TEXT_RE, RetryAfterTiming, hasExplicitRetryText, parseGoogleRetryDelaySeconds, parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterErrorTiming, parseRetryAfterHeadersSeconds, parseRetryAfterHeadersTiming, parseRetryAfterHttpDateMs, parseRetryAfterTextSeconds, resolveProviderErrorRetrySeconds };