@openclaw/ai 2026.9.5 → 2026.9.7

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 (102) hide show
  1. package/dist/{anthropic-COtDvgtt.mjs → anthropic-Cw2pgccz.mjs} +59 -88
  2. package/dist/{anthropic-payload-policy-5Erq1Nzy.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +8 -6
  3. package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +194 -247
  4. package/dist/{api-registry-Ba2Cv-ut.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
  5. package/dist/{azure-openai-responses-YrgnD583.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
  6. package/dist/{base64-BQOzsvUH.mjs → base64-C1PsYcRQ.mjs} +22 -16
  7. package/dist/{diagnostics-Dm4bisWG.mjs → diagnostics-CJaB6g8J.mjs} +55 -10
  8. package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
  9. package/dist/diagnostics.d.mts +11 -5
  10. package/dist/diagnostics.mjs +4 -4
  11. package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
  12. package/dist/event-stream-CMQfX_yr.d.mts +1 -0
  13. package/dist/{event-stream-CCoa-qSI.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
  14. package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
  15. package/dist/event-stream.d.mts +2 -2
  16. package/dist/event-stream.mjs +1 -1
  17. package/dist/{google-BuhpRO9r.mjs → google-BfapkS_K.mjs} +8 -11
  18. package/dist/google-interactions-DW3iXzjc.mjs +574 -0
  19. package/dist/{google-messages-CyWnYlh0.mjs → google-messages-CtjVtVot.mjs} +35 -71
  20. package/dist/{google-shared-BT5ZeNer.mjs → google-shared-Y2YfotEu.mjs} +43 -47
  21. package/dist/{google-vertex-C7EplRvt.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
  22. package/dist/{host-B4MeUNBc.mjs → host-CHi3X87F.mjs} +64 -189
  23. package/dist/{host-policy-DUnXSx0I.mjs → host-policy-BOAwRg_M.mjs} +2 -14
  24. package/dist/{host-FZ1RA_qD.d.mts → host-rxlNaBwm.d.mts} +9 -3
  25. package/dist/{index-DaF2QbwS.d.mts → index-D6KsSE74.d.mts} +57 -9
  26. package/dist/index.d.mts +7 -7
  27. package/dist/index.mjs +7 -7
  28. package/dist/internal/anthropic.d.mts +13 -8
  29. package/dist/internal/anthropic.mjs +5 -5
  30. package/dist/internal/openai-completions-compat.d.mts +1 -1
  31. package/dist/internal/openai-completions-compat.mjs +1 -1
  32. package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
  33. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  34. package/dist/internal/openai.d.mts +46 -9
  35. package/dist/internal/openai.mjs +13 -12
  36. package/dist/internal/runtime.d.mts +31 -70
  37. package/dist/internal/runtime.mjs +11 -66
  38. package/dist/internal/shared.d.mts +16 -13
  39. package/dist/internal/shared.mjs +6 -5
  40. package/dist/internal/tool-schema.d.mts +2 -2
  41. package/dist/internal/tool-schema.mjs +2 -2
  42. package/dist/{mistral-moA-mbwl.mjs → mistral-RS6mboC-.mjs} +46 -93
  43. package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
  44. package/dist/{openai-chatgpt-responses-DWID3EFO.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +118 -99
  45. package/dist/{openai-completions-DJ1Vm-CD.mjs → openai-completions-D14ihPYk.mjs} +14 -12
  46. package/dist/{openai-completions-compat-CkwdxTZx.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
  47. package/dist/{openai-completions-compat-JE7gqxb9.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
  48. package/dist/{openai-completions-stream-Bu98b0Hv.mjs → openai-completions-stream-CDCuw3DP.mjs} +124 -183
  49. package/dist/{openai-prompt-cache-CJ_xEevu.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
  50. package/dist/{openai-prompt-cache-1wfaIszn.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
  51. package/dist/{openai-provider-client-DPo0Hmak.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
  52. package/dist/{openai-reasoning-effort-NlFZmfEu.mjs → openai-reasoning-effort-ConhwkeX.mjs} +14 -5
  53. package/dist/{openai-responses-BejZzQCP.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
  54. package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
  55. package/dist/{openai-responses-compaction-window-D6P5oZP5.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
  56. package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
  57. package/dist/{openai-responses-contracts-Dflvrfa8.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
  58. package/dist/{openai-responses-prompt-observer-internal-C15_-OwV.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +16 -13
  59. package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +36 -0
  60. package/dist/{openai-responses-shared-CwsziD_m.mjs → openai-responses-shared-DL4ulQn7.mjs} +838 -577
  61. package/dist/{openai-responses-terminal-usage-Dl3J6zrf.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
  62. package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
  63. package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
  64. package/dist/{openai-tool-schema-BO8rwyAD.mjs → openai-tool-schema-vsl-cE-n.mjs} +365 -429
  65. package/dist/{openai-transport-params-DQeuAvBl.mjs → openai-transport-params-BwlpzX-2.mjs} +61 -106
  66. package/dist/{positive-integer-DtjCkbue.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
  67. package/dist/{provider-error-DDqw9Qda.mjs → provider-error-CwT_j2v0.mjs} +82 -10
  68. package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
  69. package/dist/{provider-options-DprLsWh9.d.mts → provider-options-Df7ov0K1.d.mts} +6 -4
  70. package/dist/{provider-replay-context-CnUSOwhr.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
  71. package/dist/{provider-transcript-transform-BsRAhuWJ.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
  72. package/dist/{provider-transport-turn-state-CkGToCD2.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
  73. package/dist/{provider-types-CAKRC7N5.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
  74. package/dist/provider-types.d.mts +6 -6
  75. package/dist/providers.d.mts +2 -2
  76. package/dist/providers.mjs +15 -11
  77. package/dist/{reasoning-tag-text-partitioner-Dy9IO8Dc.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +193 -98
  78. package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
  79. package/dist/simple-options-CGAkCwtM.mjs +349 -0
  80. package/dist/{src-DeKjbE8I.mjs → src-H4aXcFuX.mjs} +53 -26
  81. package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
  82. package/dist/{stream-first-event-timeout-C9ZadkJW.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
  83. package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
  84. package/dist/{transport-stream-shared-D-6FQSHm.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +63 -37
  85. package/dist/{transport-stream-shared-BbUkFaHi.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +13 -7
  86. package/dist/{transport-utils-1cyq5Y7x.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
  87. package/dist/transports.d.mts +37 -33
  88. package/dist/transports.mjs +208 -239
  89. package/dist/types-CB-_vNyI.d.mts +1 -0
  90. package/dist/{types-4_uVs5WH.d.mts → types-CLLR3eB4.d.mts} +5 -1
  91. package/dist/types.d.mts +6 -6
  92. package/dist/types.mjs +5 -5
  93. package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
  94. package/dist/{validation-Ctzu2DhF.d.mts → validation-Cat2wQsc.d.mts} +1 -1
  95. package/dist/validation.d.mts +1 -1
  96. package/dist/validation.mjs +1 -1
  97. package/package.json +6 -6
  98. package/dist/assistant-output-BsEkB-vU.mjs +0 -16
  99. package/dist/event-stream-DmSCpi1T.d.mts +0 -1
  100. package/dist/simple-options-C6cFWj_f.mjs +0 -175
  101. package/dist/types-DkJfb4W3.d.mts +0 -1
  102. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -1,6 +1,6 @@
1
- import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
2
- import { n as projectProviderError } from "./provider-error-DDqw9Qda.mjs";
3
- import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-1wfaIszn.mjs";
1
+ import { t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
2
+ import { n as projectProviderError } from "./provider-error-CwT_j2v0.mjs";
3
+ import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-D2V7MqR7.mjs";
4
4
  //#region packages/ai/src/providers/register-builtins.ts
5
5
  /** Source id used for built-in API provider registrations. */
6
6
  const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
@@ -62,35 +62,39 @@ function createLazyRegistration(api, importModule, select) {
62
62
  };
63
63
  }
64
64
  const registerBuiltIns = [
65
- createLazyRegistration("anthropic-messages", () => import("./anthropic-COtDvgtt.mjs").then((n) => n.t), (module) => ({
65
+ createLazyRegistration("anthropic-messages", () => import("./anthropic-Cw2pgccz.mjs").then((n) => n.t), (module) => ({
66
66
  stream: module.streamAnthropic,
67
67
  streamSimple: module.streamSimpleAnthropic
68
68
  })),
69
- createLazyRegistration("openai-completions", () => import("./openai-completions-DJ1Vm-CD.mjs").then((n) => n.t), (module) => ({
69
+ createLazyRegistration("openai-completions", () => import("./openai-completions-D14ihPYk.mjs").then((n) => n.t), (module) => ({
70
70
  stream: module.streamOpenAICompletions,
71
71
  streamSimple: module.streamSimpleOpenAICompletions
72
72
  })),
73
- createLazyRegistration("mistral-conversations", () => import("./mistral-moA-mbwl.mjs"), (module) => ({
73
+ createLazyRegistration("mistral-conversations", () => import("./mistral-RS6mboC-.mjs"), (module) => ({
74
74
  stream: module.streamMistral,
75
75
  streamSimple: module.streamSimpleMistral
76
76
  })),
77
- createLazyRegistration("openai-responses", () => import("./openai-responses-BejZzQCP.mjs").then((n) => n.t), (module) => ({
77
+ createLazyRegistration("openai-responses", () => import("./openai-responses-CKCBEc2W.mjs").then((n) => n.t), (module) => ({
78
78
  stream: module.streamOpenAIResponses,
79
79
  streamSimple: module.streamSimpleOpenAIResponses
80
80
  })),
81
- createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-YrgnD583.mjs"), (module) => ({
81
+ createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-BwT3-X8P.mjs"), (module) => ({
82
82
  stream: module.streamAzureOpenAIResponses,
83
83
  streamSimple: module.streamSimpleAzureOpenAIResponses
84
84
  })),
85
- createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-DWID3EFO.mjs"), (module) => ({
85
+ createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-CYbidtrn.mjs"), (module) => ({
86
86
  stream: module.streamOpenAICodexResponses,
87
87
  streamSimple: module.streamSimpleOpenAICodexResponses
88
88
  })),
89
- createLazyRegistration("google-generative-ai", () => import("./google-BuhpRO9r.mjs"), (module) => ({
89
+ createLazyRegistration("google-generative-ai", () => import("./google-BfapkS_K.mjs"), (module) => ({
90
90
  stream: module.streamGoogle,
91
91
  streamSimple: module.streamSimpleGoogle
92
92
  })),
93
- createLazyRegistration("google-vertex", () => import("./google-vertex-C7EplRvt.mjs"), (module) => ({
93
+ createLazyRegistration("google-interactions", () => import("./google-interactions-DW3iXzjc.mjs"), (module) => ({
94
+ stream: module.streamGoogleInteractions,
95
+ streamSimple: module.streamSimpleGoogleInteractions
96
+ })),
97
+ createLazyRegistration("google-vertex", () => import("./google-vertex-Dov4kBWu.mjs"), (module) => ({
94
98
  stream: module.streamGoogleVertex,
95
99
  streamSimple: module.streamSimpleGoogleVertex
96
100
  }))
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import "./provider-error-DDqw9Qda.mjs";
2
+ import "./provider-error-CwT_j2v0.mjs";
3
3
  import { t as expectDefined } from "./expect-lbe3Hgrh.mjs";
4
4
  //#region node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
5
5
  /**
@@ -10751,7 +10751,7 @@ function replace($0, $1) {
10751
10751
  return $1 === "|" ? $1 : $0;
10752
10752
  }
10753
10753
  //#endregion
10754
- //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/edit-map.js
10754
+ //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/edit-map.js
10755
10755
  /**
10756
10756
  * @import {Event} from 'micromark-util-types'
10757
10757
  */
@@ -10773,14 +10773,25 @@ var EditMap = class {
10773
10773
  * @type {Array<Change>}
10774
10774
  */
10775
10775
  this.map = [];
10776
+ /**
10777
+ * Changes by index, so `add` does not scan `map` (quadratic on
10778
+ * table-heavy documents).
10779
+ *
10780
+ * @type {Map<number, Change>}
10781
+ */
10782
+ this.index = /* @__PURE__ */ new Map();
10776
10783
  }
10777
10784
  /**
10778
10785
  * Create an edit: a remove and/or add at a certain place.
10779
10786
  *
10780
10787
  * @param {number} index
10788
+ * Index at which to apply the edit.
10781
10789
  * @param {number} remove
10790
+ * Count of items to remove at the index.
10782
10791
  * @param {Array<Event>} add
10792
+ * Items to add at the index.
10783
10793
  * @returns {undefined}
10794
+ * Nothing.
10784
10795
  */
10785
10796
  add(index, remove, add) {
10786
10797
  addImplementation(this, index, remove, add);
@@ -10789,7 +10800,9 @@ var EditMap = class {
10789
10800
  * Done, change the events.
10790
10801
  *
10791
10802
  * @param {Array<Event>} events
10803
+ * List of events to apply the edits to.
10792
10804
  * @returns {undefined}
10805
+ * Nothing.
10793
10806
  */
10794
10807
  consume(events) {
10795
10808
  this.map.sort(function(a, b) {
@@ -10813,37 +10826,43 @@ var EditMap = class {
10813
10826
  slice = vecs.pop();
10814
10827
  }
10815
10828
  this.map.length = 0;
10829
+ this.index.clear();
10816
10830
  }
10817
10831
  };
10818
10832
  /**
10819
10833
  * Create an edit.
10820
10834
  *
10821
10835
  * @param {EditMap} editMap
10836
+ * Edit map to apply to.
10822
10837
  * @param {number} at
10838
+ * Index at which to apply the edit.
10823
10839
  * @param {number} remove
10840
+ * Count of items to remove at the index.
10824
10841
  * @param {Array<Event>} add
10842
+ * Items to add at the index.
10825
10843
  * @returns {undefined}
10844
+ * Nothing.
10826
10845
  */
10827
10846
  function addImplementation(editMap, at, remove, add) {
10828
- let index = 0;
10829
10847
  /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */
10830
10848
  if (remove === 0 && add.length === 0) return;
10831
- while (index < editMap.map.length) {
10832
- if (editMap.map[index][0] === at) {
10833
- editMap.map[index][1] += remove;
10834
- editMap.map[index][2].push(...add);
10835
- return;
10836
- }
10837
- index += 1;
10838
- }
10839
- editMap.map.push([
10849
+ const existing = editMap.index.get(at);
10850
+ if (existing) {
10851
+ existing[1] += remove;
10852
+ existing[2].push(...add);
10853
+ return;
10854
+ }
10855
+ /** @type {Change} */
10856
+ const change = [
10840
10857
  at,
10841
10858
  remove,
10842
10859
  add
10843
- ]);
10860
+ ];
10861
+ editMap.map.push(change);
10862
+ editMap.index.set(at, change);
10844
10863
  }
10845
10864
  //#endregion
10846
- //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/infer.js
10865
+ //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/infer.js
10847
10866
  /**
10848
10867
  * @import {Event} from 'micromark-util-types'
10849
10868
  */
@@ -10881,7 +10900,7 @@ function gfmTableAlign(events, index) {
10881
10900
  return align;
10882
10901
  }
10883
10902
  //#endregion
10884
- //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.1/node_modules/micromark-extension-gfm-table/lib/syntax.js
10903
+ //#region node_modules/.pnpm/micromark-extension-gfm-table@2.1.2/node_modules/micromark-extension-gfm-table/lib/syntax.js
10885
10904
  /**
10886
10905
  * @import {Event, Extension, Point, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
10887
10906
  */
@@ -10907,6 +10926,8 @@ function gfmTable() {
10907
10926
  } } };
10908
10927
  }
10909
10928
  /**
10929
+ * Tokenizer for GFM tables.
10930
+ *
10910
10931
  * @this {TokenizeContext}
10911
10932
  * @type {Tokenizer}
10912
10933
  */
@@ -10936,7 +10957,7 @@ function tokenizeTable(effects, ok, nok) {
10936
10957
  function start(code) {
10937
10958
  let index = self.events.length - 1;
10938
10959
  while (index > -1) {
10939
- const type = self.events[index][1].type;
10960
+ const { type } = self.events[index][1];
10940
10961
  if (type === "lineEnding" || type === "linePrefix") index--;
10941
10962
  else break;
10942
10963
  }
@@ -11465,12 +11486,19 @@ function resolveTable(events, context) {
11465
11486
  * Generate a cell.
11466
11487
  *
11467
11488
  * @param {EditMap} map
11489
+ * Edit map to apply to.
11468
11490
  * @param {Readonly<TokenizeContext>} context
11491
+ * Tokenize context.
11469
11492
  * @param {Readonly<Range>} range
11493
+ * Range of the cell within events.
11470
11494
  * @param {RowKind} rowKind
11495
+ * Type of row.
11471
11496
  * @param {number | undefined} rowEnd
11497
+ * Index of the end of the row, if known.
11472
11498
  * @param {Token | undefined} previousCell
11499
+ * Previous cell token, if any.
11473
11500
  * @returns {Token | undefined}
11501
+ * Current cell token after flushing, if any.
11474
11502
  */
11475
11503
  function flushCell(map, context, range, rowKind, rowEnd, previousCell) {
11476
11504
  const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData";
@@ -11541,10 +11569,17 @@ function flushCell(map, context, range, rowKind, rowEnd, previousCell) {
11541
11569
  * Generate table end (and table body end).
11542
11570
  *
11543
11571
  * @param {Readonly<EditMap>} map
11572
+ * Edit map to apply to.
11544
11573
  * @param {Readonly<TokenizeContext>} context
11574
+ * Tokenize context.
11545
11575
  * @param {number} index
11576
+ * Index within the events where the table end should be inserted.
11546
11577
  * @param {Token} table
11578
+ * Table token.
11547
11579
  * @param {Token | undefined} tableBody
11580
+ * Table body token, if any.
11581
+ * @returns {undefined}
11582
+ * Nothing.
11548
11583
  */
11549
11584
  function flushTableEnd(map, context, index, table, tableBody) {
11550
11585
  /** @type {Array<Event>} */
@@ -11567,9 +11602,14 @@ function flushTableEnd(map, context, index, table, tableBody) {
11567
11602
  map.add(index + 1, 0, exits);
11568
11603
  }
11569
11604
  /**
11605
+ * Get the point (start or end) for a given event in the list of events.
11606
+ *
11570
11607
  * @param {Readonly<Array<Event>>} events
11608
+ * List of events.
11571
11609
  * @param {number} index
11610
+ * Index of the event to get the point for.
11572
11611
  * @returns {Readonly<Point>}
11612
+ * Start point for enter and end point for exit.
11573
11613
  */
11574
11614
  function getPoint(events, index) {
11575
11615
  const event = events[index];
@@ -11617,7 +11657,7 @@ function scanReasoningTags(text, final = true) {
11617
11657
  }
11618
11658
  return { tags };
11619
11659
  }
11620
- function parseReasoningTagAt(text, start, final) {
11660
+ function parseReasoningTagName(text, start) {
11621
11661
  let cursor = skipTagWhitespace(text, start + 1);
11622
11662
  let isClose = false;
11623
11663
  if (text.charAt(cursor) === "/") {
@@ -11627,17 +11667,27 @@ function parseReasoningTagAt(text, start, final) {
11627
11667
  const nameStart = cursor;
11628
11668
  while (cursor < text.length && isTagNameCharacter(text.charCodeAt(cursor))) cursor += 1;
11629
11669
  const partialName = text.slice(nameStart, cursor).toLowerCase();
11630
- if (!partialName) return cursor === text.length && !final ? { kind: "pending" } : invalidTag(text, start);
11670
+ if (!partialName) return { kind: cursor === text.length ? "pending" : "invalid" };
11631
11671
  if (!REASONING_TAG_NAME_SET.has(partialName)) {
11632
11672
  const canBecomeKnown = REASONING_TAG_NAMES.some((name) => name.startsWith(partialName));
11633
- return cursor === text.length && !final && canBecomeKnown ? { kind: "pending" } : invalidTag(text, start);
11673
+ return { kind: cursor === text.length && canBecomeKnown ? "pending" : "invalid" };
11634
11674
  }
11635
- if (cursor === text.length) return final ? invalidTag(text, start) : { kind: "pending" };
11675
+ if (cursor === text.length) return { kind: "pending" };
11636
11676
  const boundary = text.charAt(cursor);
11637
- if (!isTagWhitespace(boundary) && boundary !== "/" && boundary !== ">") return invalidTag(text, start);
11677
+ if (!isTagWhitespace(boundary) && boundary !== "/" && boundary !== ">") return { kind: "invalid" };
11678
+ return {
11679
+ kind: "name",
11680
+ end: cursor,
11681
+ isClose,
11682
+ isPrivate: partialName === "internal"
11683
+ };
11684
+ }
11685
+ function parseReasoningTagAt(text, start, final) {
11686
+ const name = parseReasoningTagName(text, start);
11687
+ if (name.kind !== "name") return name.kind === "pending" && !final ? { kind: "pending" } : invalidTag(text, start);
11638
11688
  let quote;
11639
11689
  let lastSignificant = "";
11640
- for (; cursor < text.length; cursor += 1) {
11690
+ for (let cursor = name.end; cursor < text.length; cursor += 1) {
11641
11691
  const char = text.charAt(cursor);
11642
11692
  if (quote) {
11643
11693
  if (char === quote) quote = void 0;
@@ -11655,9 +11705,9 @@ function parseReasoningTagAt(text, start, final) {
11655
11705
  tag: {
11656
11706
  index: start,
11657
11707
  text: text.slice(start, end),
11658
- isClose,
11659
- isSelfClosing: !isClose && lastSignificant === "/",
11660
- isPrivate: partialName === "internal"
11708
+ isClose: name.isClose,
11709
+ isSelfClosing: !name.isClose && lastSignificant === "/",
11710
+ isPrivate: name.isPrivate
11661
11711
  }
11662
11712
  };
11663
11713
  }
@@ -11689,6 +11739,14 @@ function findNextLineEnding(text, start) {
11689
11739
  if (carriageReturn === -1) return lineFeed;
11690
11740
  return lineFeed === -1 ? carriageReturn : Math.min(carriageReturn, lineFeed);
11691
11741
  }
11742
+ function appendMarkdownSource(source, start, token, value) {
11743
+ const extra = value.length - (token.end.offset - token.start.offset);
11744
+ for (let cursor = start + source.offsets.length; cursor < token.end.offset; cursor += 1) {
11745
+ const consumed = cursor - token.start.offset;
11746
+ source.offsets.push(source.value.length + (consumed > 0 ? consumed + extra : 0));
11747
+ }
11748
+ source.value += value;
11749
+ }
11692
11750
  function captureInlineSources(text, sources) {
11693
11751
  const observe = function(token) {
11694
11752
  const start = this.stack.findLast((entry) => entry.type === "inlineCode")?.position?.start.offset;
@@ -11713,13 +11771,7 @@ function captureInlineSources(text, sources) {
11713
11771
  };
11714
11772
  sources.set(start, source);
11715
11773
  }
11716
- const value = this.sliceSerialize(token);
11717
- const extra = value.length - (token.end.offset - token.start.offset);
11718
- for (let cursor = start + source.offsets.length; cursor < token.end.offset; cursor += 1) {
11719
- const consumed = cursor - token.start.offset;
11720
- source.offsets.push(source.value.length + (consumed > 0 ? consumed + extra : 0));
11721
- }
11722
- source.value += value;
11774
+ appendMarkdownSource(source, start, token, this.sliceSerialize(token));
11723
11775
  };
11724
11776
  return { enter: {
11725
11777
  codeTextData(token) {
@@ -11729,45 +11781,118 @@ function captureInlineSources(text, sources) {
11729
11781
  lineEnding: observe
11730
11782
  } };
11731
11783
  }
11784
+ function captureIndentedSources(text, sources, observeInlineLineEnding) {
11785
+ const observe = function(token) {
11786
+ if (!this.tokenStack.some(([parent]) => parent.type === "codeIndented")) return;
11787
+ const start = this.stack.findLast((entry) => entry.type === "code")?.position?.start.offset;
11788
+ if (start === void 0) return;
11789
+ let source = sources.get(start);
11790
+ if (!source) {
11791
+ const owner = this.stack.find((entry) => entry.type === "listItem" || entry.type === "blockquote");
11792
+ source = {
11793
+ value: "",
11794
+ offsets: [],
11795
+ context: text.slice(owner?.position?.start.offset ?? start, token.start.offset),
11796
+ ownerStart: owner?.position?.start.offset ?? start,
11797
+ nested: owner !== void 0
11798
+ };
11799
+ sources.set(start, source);
11800
+ }
11801
+ appendMarkdownSource(source, start, token, this.sliceSerialize(token));
11802
+ };
11803
+ return { enter: {
11804
+ codeFlowValue(token) {
11805
+ observe.call(this, token);
11806
+ expectDefined(this.config.enter.data, "Markdown data handler").call(this, token);
11807
+ },
11808
+ lineEnding(token) {
11809
+ observeInlineLineEnding?.call(this, token);
11810
+ observe.call(this, token);
11811
+ }
11812
+ } };
11813
+ }
11732
11814
  function parseMarkdownOwnership(text, options) {
11815
+ const paragraphs = options?.includeIndentedSource ? [] : void 0;
11733
11816
  if (!text) return {
11734
11817
  regions: [],
11735
11818
  codeSpans: [],
11736
11819
  textSpans: [],
11737
- retainStart: 0
11820
+ retainStart: 0,
11821
+ completedParagraphs: [],
11822
+ ...paragraphs ? { paragraphs } : {}
11738
11823
  };
11739
11824
  const sources = /* @__PURE__ */ new Map();
11825
+ const indentedSources = options?.includeIndentedSource ? /* @__PURE__ */ new Map() : void 0;
11826
+ const inlineSourceExtension = options?.includeSource ? captureInlineSources(text, sources) : void 0;
11740
11827
  const tables = options?.syntax !== "commonmark";
11741
11828
  const tree = fromMarkdown(text, {
11742
11829
  extensions: [DISABLE_HTML_MARKDOWN, ...tables ? [gfmTable()] : []],
11743
- mdastExtensions: [...tables ? [gfmTableFromMarkdown()] : [], ...options?.includeSource ? [captureInlineSources(text, sources)] : []]
11830
+ mdastExtensions: [
11831
+ ...tables ? [gfmTableFromMarkdown()] : [],
11832
+ ...inlineSourceExtension ? [inlineSourceExtension] : [],
11833
+ ...indentedSources ? [captureIndentedSources(text, indentedSources, inlineSourceExtension?.enter?.lineEnding)] : []
11834
+ ]
11744
11835
  });
11836
+ const completedParagraphs = [];
11745
11837
  const regions = [];
11746
11838
  const textSpans = [];
11747
- const pending = [tree];
11748
- while (pending.length > 0) {
11749
- const node = expectDefined(pending.pop(), "Markdown ownership node");
11750
- const start = node.position?.start?.offset;
11751
- const end = node.position?.end?.offset;
11752
- if (options?.includeText && node.type === "text" && start !== void 0 && end !== void 0) textSpans.push([start, end]);
11753
- if ((node.type === "code" || node.type === "inlineCode") && start !== void 0 && end !== void 0) {
11754
- const source = sources.get(start);
11755
- if (source) while (source.offsets.length <= end - start) source.offsets.push(source.value.length);
11756
- regions.push({
11757
- start,
11758
- end,
11759
- block: node.type === "code",
11760
- ...source ? { source } : {}
11761
- });
11839
+ const blocks = tree.children ?? [];
11840
+ for (let index = 0; index < blocks.length; index += 1) {
11841
+ const block = expectDefined(blocks[index], "Markdown block");
11842
+ const next = blocks[index + 1]?.position?.start;
11843
+ const blockStart = block.position?.start?.offset;
11844
+ const endLine = block.position?.end?.line;
11845
+ const blockEnd = block.position?.end?.offset;
11846
+ if (paragraphs && block.type === "paragraph" && blockStart !== void 0 && blockEnd !== void 0) paragraphs.push({
11847
+ start: blockStart,
11848
+ end: blockEnd
11849
+ });
11850
+ let paragraph;
11851
+ if (block.type === "paragraph" && blockStart !== void 0 && endLine !== void 0 && next?.offset !== void 0 && next.line !== void 0 && next.line > endLine + 1) {
11852
+ paragraph = {
11853
+ start: blockStart,
11854
+ end: next.offset,
11855
+ hasReferenceCandidate: false
11856
+ };
11857
+ completedParagraphs.push(paragraph);
11858
+ }
11859
+ const pending = [block];
11860
+ while (pending.length > 0) {
11861
+ const node = expectDefined(pending.pop(), "Markdown ownership node");
11862
+ if (paragraph && node.type === "text" && node.value?.includes("[")) paragraph.hasReferenceCandidate = true;
11863
+ const start = node.position?.start?.offset;
11864
+ const end = node.position?.end?.offset;
11865
+ if (options?.includeText && node.type === "text" && start !== void 0 && end !== void 0) textSpans.push([start, end]);
11866
+ if ((node.type === "code" || node.type === "inlineCode") && start !== void 0 && end !== void 0) {
11867
+ const source = sources.get(start);
11868
+ if (source) while (source.offsets.length <= end - start) source.offsets.push(source.value.length);
11869
+ const indentedSource = indentedSources?.get(start);
11870
+ if (indentedSource) {
11871
+ indentedSource.value = node.value ?? "";
11872
+ while (indentedSource.offsets.length <= end - start) indentedSource.offsets.push(indentedSource.value.length);
11873
+ indentedSource.offsets.forEach((offset, sourceIndex) => {
11874
+ indentedSource.offsets[sourceIndex] = Math.min(offset, indentedSource.value.length);
11875
+ });
11876
+ }
11877
+ regions.push({
11878
+ start,
11879
+ end,
11880
+ block: node.type === "code",
11881
+ ...source ? { source } : {},
11882
+ ...indentedSource ? { indentedSource } : {}
11883
+ });
11884
+ }
11885
+ for (const child of node.children?.toReversed() ?? []) pending.push(child);
11762
11886
  }
11763
- for (const child of node.children?.toReversed() ?? []) pending.push(child);
11764
11887
  }
11765
11888
  regions.sort((left, right) => left.start - right.start);
11766
11889
  return {
11767
11890
  regions,
11768
11891
  codeSpans: regions.map(({ start, end }) => [start, end]),
11769
11892
  textSpans,
11770
- retainStart: tree.children?.at(-1)?.position?.start?.offset ?? text.length
11893
+ retainStart: tree.children?.at(-1)?.position?.start?.offset ?? text.length,
11894
+ completedParagraphs,
11895
+ ...paragraphs ? { paragraphs } : {}
11771
11896
  };
11772
11897
  }
11773
11898
  function isInsideCode(index, spans) {
@@ -11901,18 +12026,6 @@ function endsBlankBlock(text) {
11901
12026
  while (text[cursor] === " " || text[cursor] === " ") cursor -= 1;
11902
12027
  return text[cursor] === "\n" || text[cursor] === "\r";
11903
12028
  }
11904
- function reasoningTagNameStatus(text) {
11905
- let cursor = skipTagWhitespace(text, 1);
11906
- if (text.charAt(cursor) === "/") cursor = skipTagWhitespace(text, cursor + 1);
11907
- const start = cursor;
11908
- while (cursor < text.length && isTagNameCharacter(text.charCodeAt(cursor))) cursor += 1;
11909
- const name = text.slice(start, cursor).toLowerCase();
11910
- if (!name) return cursor === text.length ? "partial" : "invalid";
11911
- if (!REASONING_TAG_NAME_SET.has(name)) return REASONING_TAG_NAMES.some((known) => known.startsWith(name)) && cursor === text.length ? "partial" : "invalid";
11912
- if (cursor === text.length) return "partial";
11913
- const boundary = text.charAt(cursor);
11914
- return isTagWhitespace(boundary) || boundary === "/" || boundary === ">" ? "resolved" : "invalid";
11915
- }
11916
12029
  function advancePendingTagProbe(probe, text) {
11917
12030
  for (const char of text) {
11918
12031
  if (probe.quote) {
@@ -11948,6 +12061,15 @@ function createReasoningTagTextPartitioner() {
11948
12061
  let nonFinalOpenEndedCode = false;
11949
12062
  let nonFinalRetainStart = 0;
11950
12063
  let nonFinalCloseReparseUsed = false;
12064
+ const startPendingTagProbe = (start, end) => {
12065
+ pendingTagProbe = {
12066
+ nameResolved: false,
12067
+ resolved: false,
12068
+ scannedThrough: end,
12069
+ start
12070
+ };
12071
+ advancePendingTagProbe(pendingTagProbe, source.slice(start + 1, end));
12072
+ };
11951
12073
  const compactCommittedSource = (retainStart) => {
11952
12074
  source = source.slice(retainStart);
11953
12075
  endedBlankBlock = endsBlankBlock(source);
@@ -11990,15 +12112,7 @@ function createReasoningTagTextPartitioner() {
11990
12112
  }));
11991
12113
  emitted = reduceEnd;
11992
12114
  fastPathCheckedThrough = reduceEnd;
11993
- if (scan.pendingStart !== void 0) {
11994
- pendingTagProbe = {
11995
- nameResolved: false,
11996
- resolved: false,
11997
- scannedThrough: limit,
11998
- start: reduceEnd
11999
- };
12000
- advancePendingTagProbe(pendingTagProbe, source.slice(reduceEnd + 1, limit));
12001
- }
12115
+ if (scan.pendingStart !== void 0) startPendingTagProbe(reduceEnd, limit);
12002
12116
  holdStart = reduction.depth > 0 || scan.pendingStart !== void 0 ? emitted : void 0;
12003
12117
  return;
12004
12118
  }
@@ -12032,8 +12146,7 @@ function createReasoningTagTextPartitioner() {
12032
12146
  emitted = end;
12033
12147
  }
12034
12148
  if (special === -1) return;
12035
- const tail = source.slice(special, limit);
12036
- const parsed = parseReasoningTagAt(tail, 0, false);
12149
+ const parsed = parseReasoningTagAt(source.slice(special, limit), 0, false);
12037
12150
  if (parsed.kind === "invalid") {
12038
12151
  merge(output, [{
12039
12152
  kind: "text",
@@ -12045,13 +12158,7 @@ function createReasoningTagTextPartitioner() {
12045
12158
  }
12046
12159
  holdStart = special;
12047
12160
  if (parsed.kind === "pending") {
12048
- pendingTagProbe = {
12049
- nameResolved: false,
12050
- resolved: false,
12051
- scannedThrough: limit,
12052
- start: special
12053
- };
12054
- advancePendingTagProbe(pendingTagProbe, tail.slice(1));
12161
+ startPendingTagProbe(special, limit);
12055
12162
  return;
12056
12163
  }
12057
12164
  if (/[\r\n]/u.test(source.slice(blockStart, special))) return;
@@ -12084,13 +12191,7 @@ function createReasoningTagTextPartitioner() {
12084
12191
  fastPathCheckedThrough = reduceEnd;
12085
12192
  if (pendingAt !== void 0) {
12086
12193
  holdStart = reduceEnd;
12087
- pendingTagProbe = {
12088
- nameResolved: false,
12089
- resolved: false,
12090
- scannedThrough: limit,
12091
- start: reduceEnd
12092
- };
12093
- advancePendingTagProbe(pendingTagProbe, source.slice(reduceEnd + 1, limit));
12194
+ startPendingTagProbe(reduceEnd, limit);
12094
12195
  } else holdStart = reduction.depth > 0 ? emitted : void 0;
12095
12196
  }
12096
12197
  };
@@ -12124,13 +12225,7 @@ function createReasoningTagTextPartitioner() {
12124
12225
  pendingTagProbe = void 0;
12125
12226
  const pendingStart = scanReasoningTags(held, false).pendingStart;
12126
12227
  if (pendingStart !== void 0) {
12127
- pendingTagProbe = {
12128
- nameResolved: false,
12129
- resolved: false,
12130
- scannedThrough: end,
12131
- start: holdStart + pendingStart
12132
- };
12133
- advancePendingTagProbe(pendingTagProbe, held.slice(pendingStart + 1));
12228
+ startPendingTagProbe(holdStart + pendingStart, end);
12134
12229
  return false;
12135
12230
  }
12136
12231
  }
@@ -12182,9 +12277,9 @@ function createReasoningTagTextPartitioner() {
12182
12277
  advancePendingTagProbe(pendingTagProbe, source.slice(pendingTagProbe.scannedThrough));
12183
12278
  pendingTagProbe.scannedThrough = source.length;
12184
12279
  if (!pendingTagProbe.nameResolved) {
12185
- const status = reasoningTagNameStatus(source.slice(pendingTagProbe.start));
12186
- pendingTagProbe.nameResolved = status === "resolved";
12187
- pendingTagProbe.resolved ||= status === "invalid";
12280
+ const name = parseReasoningTagName(source, pendingTagProbe.start);
12281
+ pendingTagProbe.nameResolved = name.kind === "name";
12282
+ pendingTagProbe.resolved ||= name.kind === "invalid";
12188
12283
  }
12189
12284
  }
12190
12285
  if (pendingTagProbe?.resolved && holdStart !== void 0) {
@@ -5,7 +5,7 @@ function isRecord(value) {
5
5
  }
6
6
  /** Coerces object-like values to records, falling back to an empty record. */
7
7
  function asRecord(value) {
8
- return typeof value === "object" && value !== null ? value : {};
8
+ return asOptionalObjectRecord(value) ?? {};
9
9
  }
10
10
  /** Reads a field only when it exists as a string. */
11
11
  function readStringField(record, key) {