@vibe-lark/larkpal 0.1.84 → 0.1.86

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 (106) hide show
  1. package/dist/account-id-BM1T6029-DYjVxojW.mjs +46 -0
  2. package/dist/activation-context--5yu1dPF-Bwsn3moT.mjs +172 -0
  3. package/dist/anthropic-TH8ERTXK.mjs +5962 -0
  4. package/dist/assistant-visible-text-DuFWokAt-CsbII5KS.mjs +596 -0
  5. package/dist/azure-openai-responses-Bt_Ag9Er.mjs +166 -0
  6. package/dist/boundary-file-read-BSd9MXPy--KThL5e6.mjs +594 -0
  7. package/dist/browser-lifecycle-cleanup-BdNsMhMD-O3tnAM4i.mjs +60 -0
  8. package/dist/build-DgTrEpge.mjs +3333 -0
  9. package/dist/bundled-compat-BpaDaAAu-D7oazKjD.mjs +5216 -0
  10. package/dist/bundled-dir-U738ay4K-DXK0q_TV.mjs +258 -0
  11. package/dist/call-DimWbpgJ-ColD4W-y.mjs +9993 -0
  12. package/dist/channel-bootstrap.runtime-BVclcGv1-DJv_Z-Kr.mjs +2 -0
  13. package/dist/channel-bootstrap.runtime-Cwcr38m2-VRfVCR-i.mjs +33 -0
  14. package/dist/chunk-D6SyT4dJ.mjs +36 -0
  15. package/dist/cli.mjs +6 -6
  16. package/dist/command-format-LSnUCVVF-BQ2SMKka.mjs +685 -0
  17. package/dist/config-Bim2pi8a-BQUdfiEi.mjs +9 -0
  18. package/dist/delivery-context.shared-j5hC5qb1-CI83RXXZ.mjs +72 -0
  19. package/dist/diagnostic-ClMwNnUA-D6nUtLnb.mjs +140 -0
  20. package/dist/dist-CEGw8-2W.mjs +429 -0
  21. package/dist/dist-DD2aJ2UL.mjs +125135 -0
  22. package/dist/env-api-keys-BVvSg7T2.mjs +68 -0
  23. package/dist/event-stream-xaQWmyas.mjs +15226 -0
  24. package/dist/facade-loader-DFzIYYt_-CIr4HKtE.mjs +194 -0
  25. package/dist/from-DF7cl2wz.mjs +3842 -0
  26. package/dist/gateway-method-policy-C7rf0SeV-CJQMEYIE.mjs +28 -0
  27. package/dist/github-copilot-headers-DjqWtUoP.mjs +22 -0
  28. package/dist/google-C2pVrgBZ.mjs +336 -0
  29. package/dist/google-gemini-cli-BBxgS5Ho.mjs +623 -0
  30. package/dist/google-shared-BsWgwEk1.mjs +22791 -0
  31. package/dist/google-vertex-BsVLJrrC.mjs +358 -0
  32. package/dist/hash-DAFtW_W7.mjs +16 -0
  33. package/dist/headers-R3HdCbAE.mjs +8 -0
  34. package/dist/home-dir-C44RaPME-CBRS4HLP.mjs +93 -0
  35. package/dist/ids-BPsM98Uu-CwuxvUai.mjs +77 -0
  36. package/dist/image-2w3cApg7-CxpHvoB5.mjs +207 -0
  37. package/dist/io-CH2g3vsv-BOGlLlB8.mjs +26218 -0
  38. package/dist/jiti-loader-cache-Bat69wam-D6hCxboy.mjs +5049 -0
  39. package/dist/json-file-BQRNuxmK-DhJM5NsG.mjs +108 -0
  40. package/dist/json-parse-v_HIJjjI.mjs +381 -0
  41. package/dist/jws-GFcTvvVT.mjs +2291 -0
  42. package/dist/{lark-cli-provider-7LvtOIF_.mjs → lark-cli-provider-BARgbbmo.mjs} +1 -1
  43. package/dist/{live-smoke-nvTUPtrv.mjs → live-smoke-BhkBOcH9.mjs} +3 -3
  44. package/dist/load-context-mb7uvLSn-B10MAi3I.mjs +29 -0
  45. package/dist/loader-708jrx4Y-BOswuvpe.mjs +5053 -0
  46. package/dist/main.mjs +56780 -476
  47. package/dist/manifest-registry-_hxKCS2K-CZdeyN0f.mjs +3512 -0
  48. package/dist/mcp-server.mjs +1 -1
  49. package/dist/message-channel-Bk_YHfQg-AeNrPPpp.mjs +50 -0
  50. package/dist/message-channel-core-DTA--Gjh-CY4Tkb7N.mjs +29 -0
  51. package/dist/message.config.runtime-K-k4XOyq-DZTmXomP.mjs +2 -0
  52. package/dist/message.gateway.runtime-DqHOHRTQ-DH4ml0YF.mjs +2 -0
  53. package/dist/mistral-CaR4DiLu.mjs +28657 -0
  54. package/dist/model-auth-env-oyg2Hexc-DU_rOUU5.mjs +1306 -0
  55. package/dist/models-config-BmpSQJQF-Gfvh1n3A.mjs +1282 -0
  56. package/dist/models-config.runtime-BsU_22xk.mjs +2 -0
  57. package/dist/multipart-parser-DedmaB5g.mjs +294 -0
  58. package/dist/oauth-DOJeGfcE.mjs +6392 -0
  59. package/dist/openai-BDtIh3Ja.mjs +6693 -0
  60. package/dist/openai-codex-responses-C5EORu31.mjs +664 -0
  61. package/dist/openai-completions-CR_cS6gX.mjs +669 -0
  62. package/dist/openai-responses-oGxwZyuC.mjs +184 -0
  63. package/dist/openai-responses-shared-BixMSDZE.mjs +398 -0
  64. package/dist/paths-D6msg0S1-C2lYuisN.mjs +189 -0
  65. package/dist/paths-D92DjaZ--CTOESW2b.mjs +192 -0
  66. package/dist/pi-model-discovery-Bd0TWzo8-BFsJmeMb.mjs +227 -0
  67. package/dist/pi-model-discovery-runtime-CCCZxkd8.mjs +2 -0
  68. package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-C5ewk8kK.mjs +399 -0
  69. package/dist/plugin-auto-enable-DdH3n9V8-DsA1isaF.mjs +1456 -0
  70. package/dist/process-scoped-map-B2cWkYET-CXwUZ8CZ.mjs +61 -0
  71. package/dist/provider-discovery.runtime-BPzz1PFj.mjs +58 -0
  72. package/dist/provider-model-compat-CFqcq0it-BDDuBI3A.mjs +118 -0
  73. package/dist/provider-runtime-C8rljsNs-CIT93zoy.mjs +2 -0
  74. package/dist/provider-runtime-CT50mNIX-BwEV6GyO.mjs +573 -0
  75. package/dist/provider-stream-COLujAAo-CbJPDngm.mjs +35449 -0
  76. package/dist/providers.runtime-Ba7tOlq7-CXkhkzU9.mjs +219 -0
  77. package/dist/public-surface-loader-BVl0NQAE-C0piXtsT.mjs +117 -0
  78. package/dist/resolve-C33B7eeu-BNvYTl6k.mjs +1041 -0
  79. package/dist/runtime-Cym-fqI8-DaSDMH-a.mjs +120 -0
  80. package/dist/runtime-channel-state-CohMybAh-hXR6y5Gx.mjs +19 -0
  81. package/dist/runtime-snapshot-C54O1-gI-40cbyi7P.mjs +677 -0
  82. package/dist/runtime-state-IBOIXKOx-Bf9tcLvc.mjs +10 -0
  83. package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BCVImm7a.mjs +39 -0
  84. package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-Cb4nJkRT.mjs +2 -0
  85. package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-BrQdXzOQ.mjs +2 -0
  86. package/dist/session-archive.runtime-B52_5vs4-BG-_IwNJ.mjs +2 -0
  87. package/dist/session-key-Cn2QoOyX-CuHbJMgR.mjs +82 -0
  88. package/dist/session-transcript-files.fs-DEeFXruQ-B1PF6nLy.mjs +147 -0
  89. package/dist/src-BgCX0MLG.mjs +813 -0
  90. package/dist/src-DYbqlAqf.mjs +1177 -0
  91. package/dist/subagent-announce-L5WsQatW-CQWI9GMd.mjs +344 -0
  92. package/dist/subagent-announce.registry.runtime-DiqZyeTs-BKuniyi3.mjs +28 -0
  93. package/dist/subagent-registry-steer-runtime-DFgZFC0j-BhBz0roy.mjs +211 -0
  94. package/dist/subagent-system-prompt-C1qnN--K-DpnTFP47.mjs +3061 -0
  95. package/dist/target-parsing-loaded-DKkb6jJY-BMD4CkpS.mjs +1002 -0
  96. package/dist/task-registry-delivery-runtime-Dd1CUkZF-C8U40a3O.mjs +2950 -0
  97. package/dist/task-registry-delivery-runtime-ragbeVx5-CNbFAkjD.mjs +2 -0
  98. package/dist/thinking-Bh-7MqXz-D3woGbO7.mjs +2 -0
  99. package/dist/transcript-E_-ISOkD-DWCfZP2p.mjs +2019 -0
  100. package/dist/transcript.runtime-BqhvZZdl-BPy42vBP.mjs +2 -0
  101. package/dist/transform-messages-DbhIzTxq.mjs +207 -0
  102. package/dist/web-provider-public-artifacts-BlpRwIUS-CGPSV4W2.mjs +295 -0
  103. package/dist/web-search-providers.runtime--0aUtC3b-DyuhC95V.mjs +200 -0
  104. package/package.json +3 -3
  105. package/dist/rolldown-runtime-wcPFST8Q.mjs +0 -13
  106. /package/dist/{interactive-init-B6j8j_Ap.mjs → interactive-init-BXQBalNr.mjs} +0 -0
@@ -0,0 +1,596 @@
1
+ import { o as normalizeLowercaseStringOrEmpty } from "./home-dir-C44RaPME-CBRS4HLP.mjs";
2
+ import { createRequire } from "node:module";
3
+ //#region node_modules/.pnpm/openclaw@2026.4.22_@napi-rs+canvas@0.1.99/node_modules/openclaw/dist/undici-runtime-D4jivTah.js
4
+ const TEST_UNDICI_RUNTIME_DEPS_KEY = "__OPENCLAW_TEST_UNDICI_RUNTIME_DEPS__";
5
+ const HTTP1_ONLY_DISPATCHER_OPTIONS = Object.freeze({ allowH2: false });
6
+ function isUndiciRuntimeDeps(value) {
7
+ return typeof value === "object" && value !== null && typeof value.Agent === "function" && typeof value.EnvHttpProxyAgent === "function" && typeof value.ProxyAgent === "function" && typeof value.fetch === "function";
8
+ }
9
+ function loadUndiciRuntimeDeps() {
10
+ const override = globalThis[TEST_UNDICI_RUNTIME_DEPS_KEY];
11
+ if (isUndiciRuntimeDeps(override)) return override;
12
+ const undici = createRequire(import.meta.url)("undici");
13
+ return {
14
+ Agent: undici.Agent,
15
+ EnvHttpProxyAgent: undici.EnvHttpProxyAgent,
16
+ FormData: undici.FormData,
17
+ ProxyAgent: undici.ProxyAgent,
18
+ fetch: undici.fetch
19
+ };
20
+ }
21
+ function withHttp1OnlyDispatcherOptions(options) {
22
+ if (!options) return { ...HTTP1_ONLY_DISPATCHER_OPTIONS };
23
+ return {
24
+ ...options,
25
+ ...HTTP1_ONLY_DISPATCHER_OPTIONS
26
+ };
27
+ }
28
+ function createHttp1Agent(options) {
29
+ const { Agent } = loadUndiciRuntimeDeps();
30
+ return new Agent(withHttp1OnlyDispatcherOptions(options));
31
+ }
32
+ function createHttp1EnvHttpProxyAgent(options) {
33
+ const { EnvHttpProxyAgent } = loadUndiciRuntimeDeps();
34
+ return new EnvHttpProxyAgent(withHttp1OnlyDispatcherOptions(options));
35
+ }
36
+ function createHttp1ProxyAgent(options) {
37
+ const { ProxyAgent } = loadUndiciRuntimeDeps();
38
+ if (typeof options === "string" || options instanceof URL) return new ProxyAgent(withHttp1OnlyDispatcherOptions({ uri: options.toString() }));
39
+ return new ProxyAgent(withHttp1OnlyDispatcherOptions(options));
40
+ }
41
+ //#endregion
42
+ //#region node_modules/.pnpm/openclaw@2026.4.22_@napi-rs+canvas@0.1.99/node_modules/openclaw/dist/chat-message-content-DgavZ6qy.js
43
+ function normalizeAssistantPhase(value) {
44
+ return value === "commentary" || value === "final_answer" ? value : void 0;
45
+ }
46
+ function parseAssistantTextSignature(value) {
47
+ if (typeof value !== "string" || value.trim().length === 0) return null;
48
+ if (!value.startsWith("{")) return { id: value };
49
+ try {
50
+ const parsed = JSON.parse(value);
51
+ if (parsed.v !== 1) return null;
52
+ return {
53
+ ...typeof parsed.id === "string" ? { id: parsed.id } : {},
54
+ ...normalizeAssistantPhase(parsed.phase) ? { phase: normalizeAssistantPhase(parsed.phase) } : {}
55
+ };
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+ function extractAssistantTextForPhase(message, options) {
61
+ if (!message || typeof message !== "object") return;
62
+ const entry = message;
63
+ const messagePhase = normalizeAssistantPhase(entry.phase);
64
+ const phase = options?.phase;
65
+ const shouldIncludeContent = (resolvedPhase) => {
66
+ if (phase) return resolvedPhase === phase;
67
+ return resolvedPhase === void 0;
68
+ };
69
+ const sanitizeText = options?.sanitizeText;
70
+ const joinWith = options?.joinWith ?? "\n";
71
+ const sanitizeBlockText = (text) => sanitizeText ? sanitizeText(text) : text;
72
+ const normalizeJoinedText = (text) => {
73
+ return text.trim() || void 0;
74
+ };
75
+ if (typeof entry.text === "string") {
76
+ if (!shouldIncludeContent(messagePhase)) return;
77
+ return normalizeJoinedText(sanitizeBlockText(entry.text));
78
+ }
79
+ if (typeof entry.content === "string") {
80
+ if (!shouldIncludeContent(messagePhase)) return;
81
+ return normalizeJoinedText(sanitizeBlockText(entry.content));
82
+ }
83
+ if (!Array.isArray(entry.content)) return;
84
+ const hasExplicitPhasedTextBlocks = entry.content.some((block) => {
85
+ if (!block || typeof block !== "object") return false;
86
+ const record = block;
87
+ if (record.type !== "text") return false;
88
+ return Boolean(parseAssistantTextSignature(record.textSignature)?.phase);
89
+ });
90
+ if (!phase && hasExplicitPhasedTextBlocks) return;
91
+ const parts = entry.content.map((block) => {
92
+ if (!block || typeof block !== "object") return null;
93
+ const record = block;
94
+ if (record.type !== "text" || typeof record.text !== "string") return null;
95
+ if (!shouldIncludeContent(parseAssistantTextSignature(record.textSignature)?.phase ?? (hasExplicitPhasedTextBlocks ? void 0 : messagePhase))) return null;
96
+ const sanitized = sanitizeBlockText(record.text);
97
+ return sanitized.trim() ? sanitized : null;
98
+ }).filter((value) => typeof value === "string");
99
+ if (parts.length === 0) return;
100
+ return normalizeJoinedText(parts.join(joinWith));
101
+ }
102
+ //#endregion
103
+ //#region node_modules/.pnpm/openclaw@2026.4.22_@napi-rs+canvas@0.1.99/node_modules/openclaw/dist/assistant-visible-text-DuFWokAt.js
104
+ function findCodeRegions(text) {
105
+ const regions = [];
106
+ for (const match of text.matchAll(/(^|\n)(```|~~~)[^\n]*\n[\s\S]*?(?:\n\2|$)/g)) {
107
+ const start = (match.index ?? 0) + match[1].length;
108
+ regions.push({
109
+ start,
110
+ end: start + match[0].length - match[1].length
111
+ });
112
+ }
113
+ for (const match of text.matchAll(/`+[^`]+`+/g)) {
114
+ const start = match.index ?? 0;
115
+ const end = start + match[0].length;
116
+ if (!regions.some((r) => start >= r.start && end <= r.end)) regions.push({
117
+ start,
118
+ end
119
+ });
120
+ }
121
+ regions.sort((a, b) => a.start - b.start);
122
+ return regions;
123
+ }
124
+ function isInsideCode(pos, regions) {
125
+ return regions.some((r) => pos >= r.start && pos < r.end);
126
+ }
127
+ /**
128
+ * Strip model control tokens leaked into assistant text output.
129
+ *
130
+ * Models like GLM-5 and DeepSeek sometimes emit internal delimiter tokens
131
+ * (e.g. `<|assistant|>`, `<|tool_call_result_begin|>`, `<|begin▁of▁sentence|>`)
132
+ * in their responses. These use the universal `<|...|>` convention (ASCII or
133
+ * full-width pipe variants) and should never reach end users.
134
+ *
135
+ * Matches inside fenced code blocks or inline code spans are preserved so
136
+ * that documentation / examples that reference these tokens are not corrupted.
137
+ *
138
+ * This is a provider bug — no upstream fix tracked yet.
139
+ * Remove this function when upstream providers stop leaking tokens.
140
+ * @see https://github.com/openclaw/openclaw/issues/40020
141
+ */
142
+ const MODEL_SPECIAL_TOKEN_RE = /<[||][^||]*[||]>/g;
143
+ function overlapsCodeRegion(start, end, codeRegions) {
144
+ return codeRegions.some((region) => start < region.end && end > region.start);
145
+ }
146
+ function shouldInsertSeparator(before, after) {
147
+ return Boolean(before && after && !/\s/.test(before) && !/\s/.test(after));
148
+ }
149
+ function stripModelSpecialTokens(text) {
150
+ if (!text) return text;
151
+ MODEL_SPECIAL_TOKEN_RE.lastIndex = 0;
152
+ if (!MODEL_SPECIAL_TOKEN_RE.test(text)) return text;
153
+ MODEL_SPECIAL_TOKEN_RE.lastIndex = 0;
154
+ const codeRegions = findCodeRegions(text);
155
+ let out = "";
156
+ let cursor = 0;
157
+ for (const match of text.matchAll(MODEL_SPECIAL_TOKEN_RE)) {
158
+ const matched = match[0];
159
+ const start = match.index ?? 0;
160
+ const end = start + matched.length;
161
+ out += text.slice(cursor, start);
162
+ if (isInsideCode(start, codeRegions) || overlapsCodeRegion(start, end, codeRegions)) out += matched;
163
+ else if (shouldInsertSeparator(text[start - 1], text[end])) out += " ";
164
+ cursor = end;
165
+ }
166
+ out += text.slice(cursor);
167
+ return out;
168
+ }
169
+ const QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i;
170
+ const FINAL_TAG_RE = /<\s*\/?\s*final\b[^<>]*>/gi;
171
+ const THINKING_TAG_RE = /<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\b[^<>]*>/gi;
172
+ function applyTrim(value, mode) {
173
+ if (mode === "none") return value;
174
+ if (mode === "start") return value.trimStart();
175
+ return value.trim();
176
+ }
177
+ function stripReasoningTagsFromText(text, options) {
178
+ if (!text) return text;
179
+ if (!QUICK_TAG_RE.test(text)) return text;
180
+ const mode = options?.mode ?? "strict";
181
+ const trimMode = options?.trim ?? "both";
182
+ let cleaned = text;
183
+ if (FINAL_TAG_RE.test(cleaned)) {
184
+ FINAL_TAG_RE.lastIndex = 0;
185
+ const finalMatches = [];
186
+ const preCodeRegions = findCodeRegions(cleaned);
187
+ for (const match of cleaned.matchAll(FINAL_TAG_RE)) {
188
+ const start = match.index ?? 0;
189
+ finalMatches.push({
190
+ start,
191
+ length: match[0].length,
192
+ inCode: isInsideCode(start, preCodeRegions)
193
+ });
194
+ }
195
+ for (let i = finalMatches.length - 1; i >= 0; i--) {
196
+ const m = finalMatches[i];
197
+ if (!m.inCode) cleaned = cleaned.slice(0, m.start) + cleaned.slice(m.start + m.length);
198
+ }
199
+ } else FINAL_TAG_RE.lastIndex = 0;
200
+ const codeRegions = findCodeRegions(cleaned);
201
+ THINKING_TAG_RE.lastIndex = 0;
202
+ let result = "";
203
+ let lastIndex = 0;
204
+ let inThinking = false;
205
+ for (const match of cleaned.matchAll(THINKING_TAG_RE)) {
206
+ const idx = match.index ?? 0;
207
+ const isClose = match[1] === "/";
208
+ if (isInsideCode(idx, codeRegions)) continue;
209
+ if (!inThinking) {
210
+ result += cleaned.slice(lastIndex, idx);
211
+ if (!isClose) inThinking = true;
212
+ } else if (isClose) inThinking = false;
213
+ lastIndex = idx + match[0].length;
214
+ }
215
+ if (!inThinking || mode === "preserve") result += cleaned.slice(lastIndex);
216
+ return applyTrim(result, trimMode);
217
+ }
218
+ const MEMORY_TAG_RE = /<\s*(\/?)\s*relevant[-_]memories\b[^<>]*>/gi;
219
+ const MEMORY_TAG_QUICK_RE = /<\s*\/?\s*relevant[-_]memories\b/i;
220
+ /**
221
+ * Strip XML-style tool call tags that models sometimes emit as plain text.
222
+ * This stateful pass hides content from an opening tag through the matching
223
+ * closing tag, or to end-of-string if the stream was truncated mid-tag.
224
+ */
225
+ const TOOL_CALL_QUICK_RE = /<\s*\/?\s*(?:tool_call|tool_result|function_calls?|function|tool_calls)\b/i;
226
+ const TOOL_CALL_TAG_NAMES = new Set([
227
+ "tool_call",
228
+ "tool_result",
229
+ "function_call",
230
+ "function_calls",
231
+ "function",
232
+ "tool_calls"
233
+ ]);
234
+ const TOOL_CALL_JSON_PAYLOAD_START_RE = /^(?:\s+[A-Za-z_:][-A-Za-z0-9_:.]*\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))*\s*(?:\r?\n\s*)?[[{]/;
235
+ const TOOL_CALL_XML_PAYLOAD_START_RE = /^\s*(?:\r?\n\s*)?<(?:function|invoke|parameters?|arguments?)\b/i;
236
+ function endsInsideQuotedString(text, start, end) {
237
+ let quoteChar = null;
238
+ let isEscaped = false;
239
+ for (let idx = start; idx < end; idx += 1) {
240
+ const char = text[idx];
241
+ if (quoteChar === null) {
242
+ if (char === "\"" || char === "'") quoteChar = char;
243
+ continue;
244
+ }
245
+ if (isEscaped) {
246
+ isEscaped = false;
247
+ continue;
248
+ }
249
+ if (char === "\\") {
250
+ isEscaped = true;
251
+ continue;
252
+ }
253
+ if (char === quoteChar) quoteChar = null;
254
+ }
255
+ return quoteChar !== null;
256
+ }
257
+ function isToolCallBoundary(char) {
258
+ return !char || /\s/.test(char) || char === "/" || char === ">";
259
+ }
260
+ function findTagCloseIndex(text, start) {
261
+ let quoteChar = null;
262
+ let isEscaped = false;
263
+ for (let idx = start; idx < text.length; idx += 1) {
264
+ const char = text[idx];
265
+ if (quoteChar !== null) {
266
+ if (isEscaped) {
267
+ isEscaped = false;
268
+ continue;
269
+ }
270
+ if (char === "\\") {
271
+ isEscaped = true;
272
+ continue;
273
+ }
274
+ if (char === quoteChar) quoteChar = null;
275
+ continue;
276
+ }
277
+ if (char === "\"" || char === "'") {
278
+ quoteChar = char;
279
+ continue;
280
+ }
281
+ if (char === "<") return -1;
282
+ if (char === ">") return idx;
283
+ }
284
+ return -1;
285
+ }
286
+ function detectToolCallPayloadKind(text, start) {
287
+ const rest = text.slice(start);
288
+ if (TOOL_CALL_JSON_PAYLOAD_START_RE.test(rest)) return "json";
289
+ if (TOOL_CALL_XML_PAYLOAD_START_RE.test(rest)) return "xml";
290
+ return null;
291
+ }
292
+ function isLikelyStandaloneFunctionToolCall(text, tagStart, tag) {
293
+ if (tag.tagName !== "function" || tag.isClose || tag.isSelfClosing || tag.isTruncated) return false;
294
+ if (!/\bname\s*=/.test(text.slice(tag.contentStart, tag.end))) return false;
295
+ let idx = tagStart - 1;
296
+ while (idx >= 0 && (text[idx] === " " || text[idx] === " ")) idx -= 1;
297
+ return idx < 0 || text[idx] === "\n" || text[idx] === "\r" || /[.!?:]/.test(text[idx]);
298
+ }
299
+ function parseToolCallTagAt(text, start) {
300
+ if (text[start] !== "<") return null;
301
+ let cursor = start + 1;
302
+ while (cursor < text.length && /\s/.test(text[cursor])) cursor += 1;
303
+ let isClose = false;
304
+ if (text[cursor] === "/") {
305
+ isClose = true;
306
+ cursor += 1;
307
+ while (cursor < text.length && /\s/.test(text[cursor])) cursor += 1;
308
+ }
309
+ const nameStart = cursor;
310
+ while (cursor < text.length && /[A-Za-z_]/.test(text[cursor])) cursor += 1;
311
+ const tagName = normalizeLowercaseStringOrEmpty(text.slice(nameStart, cursor));
312
+ if (!TOOL_CALL_TAG_NAMES.has(tagName) || !isToolCallBoundary(text[cursor])) return null;
313
+ const contentStart = cursor;
314
+ const closeIndex = findTagCloseIndex(text, cursor);
315
+ if (closeIndex === -1) return {
316
+ contentStart,
317
+ end: text.length,
318
+ isClose,
319
+ isSelfClosing: false,
320
+ tagName,
321
+ isTruncated: true
322
+ };
323
+ return {
324
+ contentStart,
325
+ end: closeIndex + 1,
326
+ isClose,
327
+ isSelfClosing: !isClose && /\/\s*$/.test(text.slice(cursor, closeIndex)),
328
+ tagName,
329
+ isTruncated: false
330
+ };
331
+ }
332
+ function stripToolCallXmlTags(text) {
333
+ if (!text || !TOOL_CALL_QUICK_RE.test(text)) return text;
334
+ const codeRegions = findCodeRegions(text);
335
+ let result = "";
336
+ let lastIndex = 0;
337
+ let inToolCallBlock = false;
338
+ let toolCallBlockContentStart = 0;
339
+ let toolCallBlockNeedsQuoteBalance = false;
340
+ let toolCallBlockStart = 0;
341
+ let toolCallBlockTagName = null;
342
+ const visibleTagBalance = /* @__PURE__ */ new Map();
343
+ for (let idx = 0; idx < text.length; idx += 1) {
344
+ if (text[idx] !== "<") continue;
345
+ if (!inToolCallBlock && isInsideCode(idx, codeRegions)) continue;
346
+ const tag = parseToolCallTagAt(text, idx);
347
+ if (!tag) continue;
348
+ if (!inToolCallBlock) {
349
+ result += text.slice(lastIndex, idx);
350
+ if (tag.isClose) {
351
+ if (tag.isTruncated) {
352
+ const preserveEnd = tag.contentStart;
353
+ result += text.slice(idx, preserveEnd);
354
+ lastIndex = preserveEnd;
355
+ idx = Math.max(idx, preserveEnd - 1);
356
+ continue;
357
+ }
358
+ const balance = visibleTagBalance.get(tag.tagName) ?? 0;
359
+ if (balance > 0) {
360
+ result += text.slice(idx, tag.end);
361
+ visibleTagBalance.set(tag.tagName, balance - 1);
362
+ }
363
+ lastIndex = tag.end;
364
+ idx = Math.max(idx, tag.end - 1);
365
+ continue;
366
+ }
367
+ if (tag.isSelfClosing) {
368
+ lastIndex = tag.end;
369
+ idx = Math.max(idx, tag.end - 1);
370
+ continue;
371
+ }
372
+ const payloadStart = tag.isTruncated ? tag.contentStart : tag.end;
373
+ const payloadKind = tag.tagName === "tool_call" || tag.tagName === "function" ? detectToolCallPayloadKind(text, payloadStart) : TOOL_CALL_JSON_PAYLOAD_START_RE.test(text.slice(payloadStart)) ? "json" : null;
374
+ const shouldStripStandaloneFunction = tag.tagName !== "function" || isLikelyStandaloneFunctionToolCall(text, idx, tag);
375
+ if (!tag.isClose && payloadKind && shouldStripStandaloneFunction) {
376
+ inToolCallBlock = true;
377
+ toolCallBlockContentStart = tag.end;
378
+ toolCallBlockNeedsQuoteBalance = payloadKind === "json";
379
+ toolCallBlockStart = idx;
380
+ toolCallBlockTagName = tag.tagName;
381
+ if (tag.isTruncated) {
382
+ lastIndex = text.length;
383
+ break;
384
+ }
385
+ } else {
386
+ const preserveEnd = tag.isTruncated ? tag.contentStart : tag.end;
387
+ result += text.slice(idx, preserveEnd);
388
+ if (!tag.isTruncated) visibleTagBalance.set(tag.tagName, (visibleTagBalance.get(tag.tagName) ?? 0) + 1);
389
+ lastIndex = preserveEnd;
390
+ idx = Math.max(idx, preserveEnd - 1);
391
+ continue;
392
+ }
393
+ } else if (tag.isClose && (tag.tagName === toolCallBlockTagName || toolCallBlockTagName === "tool_result" && tag.tagName === "tool_call") && (!toolCallBlockNeedsQuoteBalance || !endsInsideQuotedString(text, toolCallBlockContentStart, idx))) {
394
+ inToolCallBlock = false;
395
+ toolCallBlockNeedsQuoteBalance = false;
396
+ toolCallBlockTagName = null;
397
+ }
398
+ lastIndex = tag.end;
399
+ idx = Math.max(idx, tag.end - 1);
400
+ }
401
+ if (!inToolCallBlock) result += text.slice(lastIndex);
402
+ else if (toolCallBlockTagName === "function") result += text.slice(toolCallBlockStart);
403
+ return result;
404
+ }
405
+ /**
406
+ * Strip malformed Minimax tool invocations that leak into text content.
407
+ * Minimax sometimes embeds tool calls as XML in text blocks instead of
408
+ * proper structured tool calls.
409
+ */
410
+ function stripMinimaxToolCallXml(text) {
411
+ if (!text || !/minimax:tool_call/i.test(text)) return text;
412
+ let cleaned = text.replace(/<invoke\b[^>]*>[\s\S]*?<\/invoke>/gi, "");
413
+ cleaned = cleaned.replace(/<\/?minimax:tool_call>/gi, "");
414
+ return cleaned;
415
+ }
416
+ /**
417
+ * Strip downgraded tool call text representations that leak into user-visible
418
+ * text content when replaying history across providers.
419
+ */
420
+ function stripDowngradedToolCallText(text) {
421
+ if (!text) return text;
422
+ if (!/\[Tool (?:Call|Result)/i.test(text) && !/\[Historical context/i.test(text)) return text;
423
+ const consumeJsonish = (input, start, options) => {
424
+ const { allowLeadingNewlines = false } = options ?? {};
425
+ let index = start;
426
+ while (index < input.length) {
427
+ const ch = input[index];
428
+ if (ch === " " || ch === " ") {
429
+ index += 1;
430
+ continue;
431
+ }
432
+ if (allowLeadingNewlines && (ch === "\n" || ch === "\r")) {
433
+ index += 1;
434
+ continue;
435
+ }
436
+ break;
437
+ }
438
+ if (index >= input.length) return null;
439
+ const startChar = input[index];
440
+ if (startChar === "{" || startChar === "[") {
441
+ let depth = 0;
442
+ let inString = false;
443
+ let escape = false;
444
+ for (let idx = index; idx < input.length; idx += 1) {
445
+ const ch = input[idx];
446
+ if (inString) {
447
+ if (escape) escape = false;
448
+ else if (ch === "\\") escape = true;
449
+ else if (ch === "\"") inString = false;
450
+ continue;
451
+ }
452
+ if (ch === "\"") {
453
+ inString = true;
454
+ continue;
455
+ }
456
+ if (ch === "{" || ch === "[") depth += 1;
457
+ else if (ch === "}" || ch === "]") {
458
+ depth -= 1;
459
+ if (depth === 0) return idx + 1;
460
+ }
461
+ }
462
+ return null;
463
+ }
464
+ if (startChar === "\"") {
465
+ let escape = false;
466
+ for (let idx = index + 1; idx < input.length; idx += 1) {
467
+ const ch = input[idx];
468
+ if (escape) {
469
+ escape = false;
470
+ continue;
471
+ }
472
+ if (ch === "\\") {
473
+ escape = true;
474
+ continue;
475
+ }
476
+ if (ch === "\"") return idx + 1;
477
+ }
478
+ return null;
479
+ }
480
+ let end = index;
481
+ while (end < input.length && input[end] !== "\n" && input[end] !== "\r") end += 1;
482
+ return end;
483
+ };
484
+ const stripToolCalls = (input) => {
485
+ const toolCallRe = /\[Tool Call:[^\]]*\]/gi;
486
+ let result = "";
487
+ let cursor = 0;
488
+ for (const match of input.matchAll(toolCallRe)) {
489
+ const start = match.index ?? 0;
490
+ if (start < cursor) continue;
491
+ result += input.slice(cursor, start);
492
+ let index = start + match[0].length;
493
+ while (index < input.length && (input[index] === " " || input[index] === " ")) index += 1;
494
+ if (input[index] === "\r") {
495
+ index += 1;
496
+ if (input[index] === "\n") index += 1;
497
+ } else if (input[index] === "\n") index += 1;
498
+ while (index < input.length && (input[index] === " " || input[index] === " ")) index += 1;
499
+ if (normalizeLowercaseStringOrEmpty(input.slice(index, index + 9)) === "arguments") {
500
+ index += 9;
501
+ if (input[index] === ":") index += 1;
502
+ if (input[index] === " ") index += 1;
503
+ const end = consumeJsonish(input, index, { allowLeadingNewlines: true });
504
+ if (end !== null) index = end;
505
+ }
506
+ if ((input[index] === "\n" || input[index] === "\r") && (result.endsWith("\n") || result.endsWith("\r") || result.length === 0)) {
507
+ if (input[index] === "\r") index += 1;
508
+ if (input[index] === "\n") index += 1;
509
+ }
510
+ cursor = index;
511
+ }
512
+ result += input.slice(cursor);
513
+ return result;
514
+ };
515
+ let cleaned = stripToolCalls(text);
516
+ cleaned = cleaned.replace(/\[Tool Result for ID[^\]]*\]\n?[\s\S]*?(?=\n*\[Tool |\n*$)/gi, "");
517
+ cleaned = cleaned.replace(/\[Historical context:[^\]]*\]\n?/gi, "");
518
+ return cleaned.trim();
519
+ }
520
+ function stripRelevantMemoriesTags(text) {
521
+ if (!text || !MEMORY_TAG_QUICK_RE.test(text)) return text;
522
+ MEMORY_TAG_RE.lastIndex = 0;
523
+ const codeRegions = findCodeRegions(text);
524
+ let result = "";
525
+ let lastIndex = 0;
526
+ let inMemoryBlock = false;
527
+ for (const match of text.matchAll(MEMORY_TAG_RE)) {
528
+ const idx = match.index ?? 0;
529
+ if (isInsideCode(idx, codeRegions)) continue;
530
+ const isClose = match[1] === "/";
531
+ if (!inMemoryBlock) {
532
+ result += text.slice(lastIndex, idx);
533
+ if (!isClose) inMemoryBlock = true;
534
+ } else if (isClose) inMemoryBlock = false;
535
+ lastIndex = idx + match[0].length;
536
+ }
537
+ if (!inMemoryBlock) result += text.slice(lastIndex);
538
+ return result;
539
+ }
540
+ const ASSISTANT_VISIBLE_TEXT_PIPELINE_OPTIONS = {
541
+ delivery: {
542
+ finalTrim: "both",
543
+ reasoningMode: "strict",
544
+ reasoningTrim: "both",
545
+ stageOrder: "reasoning-last"
546
+ },
547
+ history: {
548
+ finalTrim: "none",
549
+ reasoningMode: "strict",
550
+ reasoningTrim: "none",
551
+ stageOrder: "reasoning-last"
552
+ },
553
+ "internal-scaffolding": {
554
+ finalTrim: "start",
555
+ preserveDowngradedToolText: true,
556
+ preserveMinimaxToolXml: true,
557
+ reasoningMode: "preserve",
558
+ reasoningTrim: "start",
559
+ stageOrder: "reasoning-first"
560
+ }
561
+ };
562
+ function applyAssistantVisibleTextStagePipeline(text, options) {
563
+ if (!text) return text;
564
+ const stripReasoning = (value) => stripReasoningTagsFromText(value, {
565
+ mode: options.reasoningMode,
566
+ trim: options.reasoningTrim
567
+ });
568
+ const applyFinalTrim = (value) => {
569
+ if (options.finalTrim === "none") return value;
570
+ if (options.finalTrim === "start") return value.trimStart();
571
+ return value.trim();
572
+ };
573
+ const stripNonReasoningStages = (value) => {
574
+ let cleaned = value;
575
+ if (!options.preserveMinimaxToolXml) cleaned = stripMinimaxToolCallXml(cleaned);
576
+ cleaned = stripModelSpecialTokens(cleaned);
577
+ cleaned = stripRelevantMemoriesTags(cleaned);
578
+ cleaned = stripToolCallXmlTags(cleaned);
579
+ if (!options.preserveDowngradedToolText) cleaned = stripDowngradedToolCallText(cleaned);
580
+ return cleaned;
581
+ };
582
+ if (options.stageOrder === "reasoning-first") return applyFinalTrim(stripNonReasoningStages(stripReasoning(text)));
583
+ return applyFinalTrim(stripReasoning(stripNonReasoningStages(text)));
584
+ }
585
+ function sanitizeAssistantVisibleTextWithProfile(text, profile = "delivery") {
586
+ return applyAssistantVisibleTextStagePipeline(text, ASSISTANT_VISIBLE_TEXT_PIPELINE_OPTIONS[profile]);
587
+ }
588
+ /**
589
+ * Canonical user-visible assistant text sanitizer for delivery and history
590
+ * extraction paths. Keeps prose, removes internal scaffolding.
591
+ */
592
+ function sanitizeAssistantVisibleText(text) {
593
+ return sanitizeAssistantVisibleTextWithProfile(text, "delivery");
594
+ }
595
+ //#endregion
596
+ export { createHttp1EnvHttpProxyAgent as a, createHttp1Agent as i, sanitizeAssistantVisibleTextWithProfile as n, createHttp1ProxyAgent as o, extractAssistantTextForPhase as r, loadUndiciRuntimeDeps as s, sanitizeAssistantVisibleText as t };