@openclaw/ai 2026.11.3 → 2026.11.5-beta.2

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 (140) hide show
  1. package/README.md +11 -8
  2. package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
  3. package/dist/anthropic-DEKgalVg.mjs +182 -0
  4. package/dist/{anthropic-payload-policy-C0ki72BT.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
  5. package/dist/{anthropic-stream-reducer-yWDb5Cct.mjs → anthropic-stream-lifecycle-DF2qVvg1.mjs} +845 -649
  6. package/dist/{anthropic-tool-projection-C2-d1eZ3.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
  7. package/dist/{anthropic-tool-projection-DZOKfAmL.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-BvvXzZbi.mjs → azure-openai-responses-DbQV5RTx.mjs} +47 -53
  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-v7oVEW59.mjs → diagnostics-CloVGQiK.mjs} +27 -20
  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-Cpi_cLKZ.mjs → google-B1g82bn4.mjs} +7 -8
  26. package/dist/{google-interactions-CGINbsjO.mjs → google-interactions-Ckr0Z99Z.mjs} +243 -269
  27. package/dist/{google-messages-DQMgG5yG.mjs → google-messages-A-9d3y5V.mjs} +52 -18
  28. package/dist/{google-provider-stream-BHd0cST9.mjs → google-provider-stream-CNVh4gpm.mjs} +19 -11
  29. package/dist/{google-shared-vtag8bj5.mjs → google-shared-WNM86ZcW.mjs} +72 -42
  30. package/dist/{google-vertex-eKoUnW7N.mjs → google-vertex-CXjleC6g.mjs} +3 -3
  31. package/dist/{google-video-slots-D8tPH8wX.mjs → google-video-slots-Bxt-OXO8.mjs} +1 -1
  32. package/dist/{host-CWt55nnF.mjs → host-DX7ORpeH.mjs} +46 -39
  33. package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
  34. package/dist/{host-policy-Dm7PM6AD.mjs → host-policy-jCZebuXx.mjs} +2 -2
  35. package/dist/index-Bczt0MnO.d.mts +17 -0
  36. package/dist/index.d.mts +8 -7
  37. package/dist/index.mjs +9 -7
  38. package/dist/internal/anthropic.d.mts +21 -26
  39. package/dist/internal/anthropic.mjs +6 -6
  40. package/dist/internal/google-model-family.mjs +1 -1
  41. package/dist/internal/google.d.mts +15 -0
  42. package/dist/internal/google.mjs +1 -0
  43. package/dist/internal/model-request-body.d.mts +37 -0
  44. package/dist/internal/model-request-body.mjs +106 -0
  45. package/dist/internal/openai-completions-compat.d.mts +1 -1
  46. package/dist/internal/openai-completions-compat.mjs +1 -1
  47. package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
  48. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  49. package/dist/internal/openai.d.mts +14 -12
  50. package/dist/internal/openai.mjs +11 -10
  51. package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
  52. package/dist/{reasoning-tag-text-partitioner-CU9A4Lg8.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -111
  53. package/dist/internal/retry-after.d.mts +2 -2
  54. package/dist/internal/retry-after.mjs +96 -32
  55. package/dist/internal/runtime.d.mts +15 -41
  56. package/dist/internal/runtime.mjs +9 -10
  57. package/dist/internal/shared.d.mts +21 -25
  58. package/dist/internal/shared.mjs +9 -98
  59. package/dist/internal/tool-schema.d.mts +10 -10
  60. package/dist/internal/tool-schema.mjs +4 -4
  61. package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
  62. package/dist/mistral-CjHkvsqR.mjs +3741 -0
  63. package/dist/{openai.LICENSE → mistral.LICENSE} +1 -1
  64. package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
  65. package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
  66. package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
  67. package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
  68. package/dist/{openai-chatgpt-responses-BZa3SySh.mjs → openai-chatgpt-responses-CwS5JP7A.mjs} +61 -80
  69. package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
  70. package/dist/{openai-completions-compat-bNQXF1y9.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
  71. package/dist/{openai-completions-CCZ_UHCk.mjs → openai-completions-sj4S-RXQ.mjs} +5 -5
  72. package/dist/openai-completions-transport-BDAIA0_P.mjs +3406 -0
  73. package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
  74. package/dist/{openai-prompt-cache-B9AvdoEo.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
  75. package/dist/{openai-responses-compaction-replay-_sUXtcwU.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
  76. package/dist/{openai-responses-contracts-B1nkeLL6.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
  77. package/dist/{openai-responses-contracts-B5mGAbR6.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
  78. package/dist/{openai-responses-endpoint-CfKR6N5f.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
  79. package/dist/openai-responses-ev_c6oTy.mjs +89 -0
  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-CTqHc02t.mjs → openai-responses-request-lifecycle-BuOs0mwI.mjs} +12 -26
  82. package/dist/{openai-responses-shared-wx9v1MCn.mjs → openai-responses-shared-BmRQnUPP.mjs} +633 -1493
  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-BTEU2xmN.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
  85. package/dist/otel-Buswj0Mf.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-DAzsyi49.d.mts → provider-options-Mo8NM5d1.d.mts} +16 -5
  91. package/dist/{provider-replay-context-4vxI7p4V.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
  92. package/dist/provider-transcript-transform-DtaxNcC1.mjs +32 -0
  93. package/dist/{provider-transport-turn-state-D_GjPJHe.mjs → provider-transport-turn-state-BIS8maBK.mjs} +4 -4
  94. package/dist/{provider-types-CWl4VXvE.d.mts → provider-types-B1e98js5.d.mts} +3 -3
  95. package/dist/provider-types.d.mts +7 -6
  96. package/dist/providers.d.mts +2 -2
  97. package/dist/providers.mjs +26 -29
  98. package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
  99. package/dist/request-headers-DO4Mqhw1.mjs +10 -0
  100. package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
  101. package/dist/{retry-after-BrmTv0jL.d.mts → retry-after-DnHBlFS2.d.mts} +21 -1
  102. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  103. package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
  104. package/dist/{simple-options-xJkqrG_E.mjs → simple-options-tLSeECry.mjs} +108 -82
  105. package/dist/src-BUsVkrNt.mjs +105 -0
  106. package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
  107. package/dist/stable-stringify-CchQEmeA.mjs +84 -0
  108. package/dist/{stream-C4YDqhFj.mjs → stream-DrtAWu7c.mjs} +2 -6
  109. package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
  110. package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
  111. package/dist/string-normalization-B8TDDBX_.mjs +32 -0
  112. package/dist/telemetry-CvK1yQg7.mjs +582 -0
  113. package/dist/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
  114. package/dist/{transport-stream-shared-lhgkTOz3.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
  115. package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
  116. package/dist/{transport-utils-DwOpuTjL.mjs → transport-utils-Da_39MYi.mjs} +23 -38
  117. package/dist/transports.d.mts +42 -39
  118. package/dist/transports.mjs +215 -296
  119. package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
  120. package/dist/types-Cb3-5WM9.d.mts +1 -0
  121. package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
  122. package/dist/types.d.mts +7 -6
  123. package/dist/types.mjs +7 -5
  124. package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
  125. package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
  126. package/dist/validation.d.mts +1 -1
  127. package/dist/validation.mjs +1 -2
  128. package/package.json +40 -6
  129. package/dist/anthropic-lueA8LUg.mjs +0 -221
  130. package/dist/assistant-output-BnQm3fov.mjs +0 -47
  131. package/dist/event-stream-CDpFza-M.d.mts +0 -1
  132. package/dist/index-DSprYWaz.d.mts +0 -185
  133. package/dist/mistral-CQ7aoWg2.mjs +0 -512
  134. package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
  135. package/dist/openai-CiRi-nVE.mjs +0 -20077
  136. package/dist/openai-completions-transport-DFvSBbUT.mjs +0 -10881
  137. package/dist/openai-responses-DQsZKUoI.mjs +0 -87
  138. package/dist/rolldown-runtime-B4iAMlE-.mjs +0 -35
  139. package/dist/types-CBJthzJX.d.mts +0 -1
  140. package/dist/ws.LICENSE +0 -20
@@ -1,5 +1,6 @@
1
- import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.mjs";
2
- import { l as expectDefined } from "./provider-error-qtZD2inE.mjs";
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";
3
4
  //#region node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
4
5
  /**
5
6
  * @typedef {import('mdast').Nodes} Nodes
@@ -11831,7 +11832,7 @@ function getPoint(events, index) {
11831
11832
  return event[1][side];
11832
11833
  }
11833
11834
  //#endregion
11834
- //#region packages/markdown-core/src/reasoning-tag-parser.ts
11835
+ //#region packages/markdown-core/src/reasoning-tag-syntax.ts
11835
11836
  const REASONING_TAG_NAMES = [
11836
11837
  "think",
11837
11838
  "thinking",
@@ -11849,7 +11850,6 @@ const REASONING_TAG_NAMES = [
11849
11850
  "mm:reasoning"
11850
11851
  ];
11851
11852
  const REASONING_TAG_NAME_SET = new Set(REASONING_TAG_NAMES);
11852
- const DISABLE_HTML_MARKDOWN = { disable: { null: ["htmlFlow", "htmlText"] } };
11853
11853
  /** Scans quote-aware provider reasoning tags with iterative malformed recovery. */
11854
11854
  function scanReasoningTags(text, final = true) {
11855
11855
  const tags = [];
@@ -11953,6 +11953,143 @@ function findNextLineEnding(text, start) {
11953
11953
  if (carriageReturn === -1) return lineFeed;
11954
11954
  return lineFeed === -1 ? carriageReturn : Math.min(carriageReturn, lineFeed);
11955
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"] } };
11956
12093
  function appendMarkdownSource(source, start, token, value) {
11957
12094
  const extra = value.length - (token.end.offset - token.start.offset);
11958
12095
  for (let cursor = start + source.offsets.length; cursor < token.end.offset; cursor += 1) {
@@ -12033,6 +12170,8 @@ function parseMarkdownOwnership(text, options) {
12033
12170
  textSpans: [],
12034
12171
  retainStart: 0,
12035
12172
  completedParagraphs: [],
12173
+ definitions: [],
12174
+ unsettledDefinitionStarts: [],
12036
12175
  ...paragraphs ? { paragraphs } : {}
12037
12176
  };
12038
12177
  const sources = /* @__PURE__ */ new Map();
@@ -12050,13 +12189,17 @@ function parseMarkdownOwnership(text, options) {
12050
12189
  const completedParagraphs = [];
12051
12190
  const regions = [];
12052
12191
  const textSpans = [];
12192
+ const definitions = [];
12193
+ let unresolvedImageCodeStart;
12053
12194
  const blocks = tree.children ?? [];
12195
+ let retainStart = findListItemRetentionStart(text, blocks);
12054
12196
  for (let index = 0; index < blocks.length; index += 1) {
12055
12197
  const block = expectDefined(blocks[index], "Markdown block");
12056
12198
  const next = blocks[index + 1]?.position?.start;
12057
12199
  const blockStart = block.position?.start?.offset;
12058
12200
  const endLine = block.position?.end?.line;
12059
12201
  const blockEnd = block.position?.end?.offset;
12202
+ retainStart = retainTableParagraph(retainStart, text.length, block, blocks[index - 1]);
12060
12203
  if (paragraphs && block.type === "paragraph" && blockStart !== void 0 && blockEnd !== void 0) paragraphs.push({
12061
12204
  start: blockStart,
12062
12205
  end: blockEnd
@@ -12071,11 +12214,23 @@ function parseMarkdownOwnership(text, options) {
12071
12214
  completedParagraphs.push(paragraph);
12072
12215
  }
12073
12216
  const pending = [block];
12217
+ const regionStart = regions.length;
12218
+ let hasReferenceCandidate = false;
12219
+ let hasInlineCode = false;
12074
12220
  while (pending.length > 0) {
12075
12221
  const node = expectDefined(pending.pop(), "Markdown ownership node");
12076
- 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";
12077
12227
  const start = node.position?.start?.offset;
12078
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
+ });
12079
12234
  if (options?.includeText && node.type === "text" && start !== void 0 && end !== void 0) textSpans.push([start, end]);
12080
12235
  if ((node.type === "code" || node.type === "inlineCode") && start !== void 0 && end !== void 0) {
12081
12236
  const source = sources.get(start);
@@ -12098,131 +12253,178 @@ function parseMarkdownOwnership(text, options) {
12098
12253
  }
12099
12254
  for (const child of node.children?.toReversed() ?? []) pending.push(child);
12100
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
+ }
12101
12260
  }
12261
+ const { unsettledDefinitionStarts, retainStart: referenceStart } = findReferenceDefinitionRetention(text, definitions);
12262
+ retainStart = findListItemRetentionStart(text, blocks, Math.min(retainStart, referenceStart));
12102
12263
  regions.sort((left, right) => left.start - right.start);
12264
+ const continuation = findContainerContinuation(text, blocks.at(-1), retainStart);
12103
12265
  return {
12104
12266
  regions,
12105
12267
  codeSpans: regions.map(({ start, end }) => [start, end]),
12106
12268
  textSpans,
12107
- retainStart: tree.children?.at(-1)?.position?.start?.offset ?? text.length,
12269
+ retainStart,
12270
+ ...continuation ? { continuation } : {},
12271
+ ...unresolvedImageCodeStart === void 0 ? {} : { unresolvedImageCodeStart },
12108
12272
  completedParagraphs,
12273
+ definitions,
12274
+ unsettledDefinitionStarts,
12109
12275
  ...paragraphs ? { paragraphs } : {}
12110
12276
  };
12111
12277
  }
12112
- function isInsideCode(index, spans) {
12113
- let low = 0;
12114
- let high = spans.length - 1;
12115
- while (low <= high) {
12116
- const middle = Math.floor((low + high) / 2);
12117
- const span = spans[middle];
12118
- if (!span) return false;
12119
- if (index < span[0]) high = middle - 1;
12120
- else if (index >= span[1]) low = middle + 1;
12121
- 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;
12122
12300
  }
12123
- return false;
12301
+ return {
12302
+ hasImageCode: hasImageCode || brackets.some((bracket) => bracket.image && bracket.code),
12303
+ hasOpenLabel: brackets.length > 0
12304
+ };
12124
12305
  }
12125
- function reduceReasoningText(text, codeSpans, state, options) {
12126
- const output = [];
12127
- const emit = (kind, value) => {
12128
- if (!value) return;
12129
- const previous = output.at(-1);
12130
- if (previous?.kind === kind) previous.text += value;
12131
- else output.push({
12132
- kind,
12133
- text: value
12134
- });
12135
- 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"
12136
12316
  };
12137
- const append = (value) => {
12138
- if (!value) return;
12139
- if (state.depth > 0 && state.pending) {
12140
- state.pending.content += value;
12141
- state.pending.protectedClose ||= scanReasoningTags(value).tags.some((tag) => tag.isClose);
12142
- } 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"
12143
12325
  };
12144
- const start = options.start ?? 0;
12145
- const scan = scanReasoningTags(text.slice(start), options.final);
12146
- const tags = [];
12147
- for (const scannedTag of scan.tags) {
12148
- const index = scannedTag.index + start;
12149
- if (!isInsideCode(index, codeSpans)) tags.push({
12150
- ...scannedTag,
12151
- index
12152
- });
12153
- }
12154
- const mustParseRemainder = [];
12155
- if (options.scope === "leading") {
12156
- let mustParse = false;
12157
- for (let index = tags.length - 1; index >= 0; index -= 1) {
12158
- mustParse ||= tags[index]?.isPrivate === true;
12159
- mustParseRemainder[index] = mustParse;
12160
- mustParse ||= tags[index]?.isClose === true;
12161
- }
12162
- }
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) {
12163
12346
  let cursor = start;
12164
- for (const [tagIndex, tag] of tags.entries()) {
12165
- const beforeTag = text.slice(cursor, tag.index);
12166
- append(beforeTag);
12167
- const tagEnd = tag.index + tag.text.length;
12168
- if (tag.isSelfClosing) {
12169
- if (state.depth === 0 && options.scope === "leading" && state.visibleEver) {
12170
- emit("text", text.slice(tag.index));
12171
- cursor = text.length;
12172
- break;
12173
- }
12174
- cursor = tagEnd;
12175
- continue;
12176
- }
12177
- if (!tag.isClose) {
12178
- if (state.depth === 0 && options.scope === "leading" && state.visibleEver && !mustParseRemainder[tagIndex]) {
12179
- emit("text", text.slice(tag.index));
12180
- cursor = text.length;
12181
- break;
12182
- }
12183
- if (state.depth === 0) state.pending = {
12184
- content: "",
12185
- containsPrivate: tag.isPrivate,
12186
- openTag: tag.text,
12187
- protectedClose: false,
12188
- visibleBefore: state.visibleEver
12189
- };
12190
- else if (state.pending) state.pending.containsPrivate ||= tag.isPrivate;
12191
- state.depth += 1;
12192
- 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;
12193
12373
  continue;
12194
12374
  }
12195
- if (state.depth > 0) {
12196
- state.depth -= 1;
12197
- if (state.depth === 0 && state.pending) {
12198
- if (!state.pending.containsPrivate) emit("thinking", state.pending.content);
12199
- state.pending = void 0;
12200
- } else if (state.pending) state.pending.protectedClose = true;
12201
- cursor = tagEnd;
12375
+ const markerEnd = listMarkerEnd(text, markerStart);
12376
+ if (markerEnd > markerStart) {
12377
+ cursor = markerEnd;
12378
+ while (text[cursor] === " " || text[cursor] === " ") cursor += 1;
12202
12379
  continue;
12203
12380
  }
12204
- if (options.mode === "visible") append(tag.text);
12205
- else {
12206
- const after = text.slice(tagEnd);
12207
- if (beforeTag.trim() && after.trim()) {
12208
- const thinking = output.filter((delta) => delta.kind === "thinking");
12209
- output.splice(0, output.length, ...thinking);
12210
- state.visibleEver = false;
12211
- }
12212
- }
12213
- cursor = tagEnd;
12214
- }
12215
- append(text.slice(cursor));
12216
- if (options.final && state.depth > 0 && state.pending) {
12217
- const pending = state.pending;
12218
- if (!pending.containsPrivate) {
12219
- 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);
12220
- else emit("thinking", pending.content);
12221
- }
12222
- state.depth = 0;
12223
- state.pending = void 0;
12381
+ break;
12224
12382
  }
12225
- 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;
12226
12428
  }
12227
12429
  //#endregion
12228
12430
  //#region packages/markdown-core/src/reasoning-tags.ts
@@ -12583,4 +12785,4 @@ function createReasoningTagTextPartitioner() {
12583
12785
  };
12584
12786
  }
12585
12787
  //#endregion
12586
- export { createReasoningTagTextPartitioner as t };
12788
+ export { createReasoningTagTextPartitioner };
@@ -1,2 +1,2 @@
1
- import { a as parseRetryAfterHeadersSeconds, i as parseRetryAfterErrorSeconds, n as parseGoogleRetryDelaySeconds, o as parseRetryAfterHttpDateMs, r as parseHttpDateInstant, s as parseRetryAfterTextSeconds, t as RETRY_AFTER_TEXT_RE } from "../retry-after-BrmTv0jL.mjs";
2
- export { RETRY_AFTER_TEXT_RE, parseGoogleRetryDelaySeconds, parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterHeadersSeconds, parseRetryAfterHttpDateMs, parseRetryAfterTextSeconds };
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 };