@openclaw/ai 2026.8.1-beta.2 → 2026.8.1-beta.3

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 (65) hide show
  1. package/dist/{anthropic-B6dLpq5L.mjs → anthropic-B8KwTtlb.mjs} +37 -27
  2. package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
  3. package/dist/{anthropic-JsNA5KCu.mjs → anthropic-BQXQudmA.mjs} +0 -1
  4. package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-4Zx7-aCr.mjs} +14 -15
  5. package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-CSx7MoKH.d.mts} +2 -1
  6. package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-DFxSnFqG.d.mts} +1 -1
  7. package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Aa4mVcYG.mjs} +3 -3
  8. package/dist/diagnostics.mjs +1 -1
  9. package/dist/event-stream-BVVgDSdq.d.mts +1 -0
  10. package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-D91-ohD_.d.mts} +1 -1
  11. package/dist/event-stream.d.mts +1 -1
  12. package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-M1dl64nz.mjs} +12 -5
  13. package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-DCJHM_a5.mjs} +3 -3
  14. package/dist/{google-C7h2QzDX.mjs → google-yDRnipeq.mjs} +3 -3
  15. package/dist/headers-B_e4-1J0.mjs +9 -0
  16. package/dist/{host-DTqNc7ad.mjs → host-DF_yxOsA.mjs} +40 -29
  17. package/dist/{host-vWgMMhiJ.d.mts → host-DJq_FGcz.d.mts} +6 -6
  18. package/dist/index.d.mts +7 -7
  19. package/dist/index.mjs +2 -2
  20. package/dist/internal/anthropic.d.mts +11 -5
  21. package/dist/internal/anthropic.mjs +4 -4
  22. package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
  23. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  24. package/dist/internal/openai.d.mts +5 -5
  25. package/dist/internal/openai.mjs +9 -8
  26. package/dist/internal/runtime.d.mts +4 -2
  27. package/dist/internal/runtime.mjs +4 -3
  28. package/dist/internal/shared.d.mts +17 -3
  29. package/dist/internal/shared.mjs +4 -4
  30. package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
  31. package/dist/{mistral-CEWoQI_g.mjs → mistral-D6hRXI7A.mjs} +47 -33
  32. package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-C339VIfT.mjs} +23 -15
  33. package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-D88orSJ9.mjs} +71 -35
  34. package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-B0KTleXp.d.mts} +2 -2
  35. package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-BXEcr-Tp.mjs} +4 -4
  36. package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-CD75pQ0m.d.mts} +2 -2
  37. package/dist/{openai-responses-contracts-CyfIkQi5.mjs → openai-responses-contracts-DvILoqBk.mjs} +3 -9
  38. package/dist/{openai-responses-payload-policy-BDxV-W0c.mjs → openai-responses-payload-policy-BDo8CQsx.mjs} +4 -2
  39. package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-CNGFT9zr.d.mts} +1 -0
  40. package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-BG-1AsBI.mjs} +2 -3
  41. package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-Cvt5MgEm.mjs} +81 -136
  42. package/dist/{openai-stop-reason-BkFkqqK0.mjs → openai-stop-reason-9OONKyAm.mjs} +47 -31
  43. package/dist/{openai-tool-projection-CY04OcvQ.mjs → openai-tool-projection-CHGLt03m.mjs} +94 -6
  44. package/dist/{provider-error-BUwEnjXq.mjs → provider-error-C8mBRJDl.mjs} +19 -24
  45. package/dist/provider-options-AvldWZt8.mjs +21 -0
  46. package/dist/{provider-options-B96RdNpH.d.mts → provider-options-Cc5ZQ6Aa.d.mts} +12 -2
  47. package/dist/provider-transcript-transform--gtf0ZbR.mjs +32 -0
  48. package/dist/provider-types.d.mts +5 -5
  49. package/dist/providers.d.mts +1 -1
  50. package/dist/providers.mjs +9 -9
  51. package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +3 -0
  52. package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-BP7HLLZn.mjs} +1 -1
  53. package/dist/simple-options-oqsXB6U3.mjs +450 -0
  54. package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-FEr-jOoZ.mjs} +16 -7
  55. package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-Bv0FHkd0.mjs} +1 -1
  56. package/dist/transports.d.mts +77 -44
  57. package/dist/transports.mjs +207 -167
  58. package/dist/{types-BHNrPS1l.d.mts → types-DTAP49HF.d.mts} +17 -2
  59. package/dist/types.d.mts +5 -5
  60. package/dist/types.mjs +1 -1
  61. package/dist/{validation-DT9SrFn3.d.mts → validation-DYNNrU9u.d.mts} +1 -1
  62. package/dist/validation.d.mts +1 -1
  63. package/package.json +1 -1
  64. package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
  65. package/dist/simple-options-D58D5Kvw.mjs +0 -117
@@ -1,18 +1,17 @@
1
1
  import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
2
2
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
3
- import { i as clampThinkingLevel } from "./sanitize-unicode-BYqrYtC_.mjs";
4
- import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
5
- import { n as projectProviderError } from "./provider-error-BUwEnjXq.mjs";
3
+ import { i as clampThinkingLevel } from "./sanitize-unicode-BP7HLLZn.mjs";
4
+ import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
5
+ import { n as projectProviderError } from "./provider-error-C8mBRJDl.mjs";
6
6
  import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
7
7
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
8
- import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-D58D5Kvw.mjs";
9
- import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as tagPendingCommentaryText, r as convertMessages, t as mapOpenAIStopReason, u as shouldOmitOllamaCompatResponseFormat } from "./openai-stop-reason-BkFkqqK0.mjs";
8
+ import { A as splitSystemPromptCacheBoundary, C as withProviderResponseHook, P as sortPromptCacheToolsByName, n as buildBaseOptions, x as transportAbortError } from "./simple-options-oqsXB6U3.mjs";
9
+ import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, h as tagUnresolvedTextAsCommentary, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, m as tagPendingCommentaryText, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as tagInterruptedTextPhases, r as convertMessages, t as mapOpenAIStopReason, u as shouldOmitOllamaCompatResponseFormat } from "./openai-stop-reason-9OONKyAm.mjs";
10
10
  import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
11
- import { n as notifyLlmRequestActivity } from "./headers-DdOQtGuU.mjs";
12
- import { f as transportAbortError, p as withProviderResponseHook } from "./provider-transcript-transform-ePx-Bbfr.mjs";
13
- import { d as readOpenAICompletionsContentDeltas, n as reconcileOpenAICompletionsToolChoice, o as createOpenAIResponseHook, s as isOpenAICompletionsThinkingEnabled, t as projectOpenAITools, u as parseOpenAICompletionsUsage } from "./openai-tool-projection-CY04OcvQ.mjs";
11
+ import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
12
+ import { c as isOpenAICompletionsThinkingEnabled, d as parseOpenAICompletionsUsage, f as readOpenAICompletionsContentDeltas, n as reconcileOpenAICompletionsToolChoice, o as createOpenAIProviderAcceptanceHook, p as readOpenAICompletionsReasoningBatch, t as projectOpenAITools } from "./openai-tool-projection-CHGLt03m.mjs";
14
13
  import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
15
- import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-rnPwX2pg.mjs";
14
+ import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-5ygO2rZc.mjs";
16
15
  import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
17
16
  import OpenAI from "openai";
18
17
  //#region packages/ai/src/providers/openai-completions.ts
@@ -57,6 +56,8 @@ const streamOpenAICompletions = (model, context, options) => {
57
56
  try {
58
57
  const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
59
58
  const compat = resolveOpenAICompletionsCompat(model);
59
+ const visibleReasoningDetailTypes = new Set(compat.visibleReasoningDetailTypes);
60
+ const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
60
61
  const cacheRetention = resolveCacheRetention(options?.cacheRetention);
61
62
  const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
62
63
  const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
@@ -74,14 +75,17 @@ const streamOpenAICompletions = (model, context, options) => {
74
75
  stream: openaiStream,
75
76
  signal: firstEventAbort.signal,
76
77
  abort: firstEventAbort.abort,
77
- hook: createOpenAIResponseHook(options?.onResponse, response, model),
78
+ hook: createOpenAIProviderAcceptanceHook(options, response, model),
78
79
  onReady: () => stream.push({
79
80
  type: "start",
80
81
  partial: output
81
82
  })
82
83
  });
83
84
  let textBlock = null;
85
+ let textBlockSource;
84
86
  let thinkingBlock = null;
87
+ let pendingInterruptedTextBlock = null;
88
+ let confirmedInterruptedTextBlock = null;
85
89
  let hasFinishReason = false;
86
90
  const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
87
91
  const toolCallBlocksById = /* @__PURE__ */ new Map();
@@ -91,6 +95,7 @@ const streamOpenAICompletions = (model, context, options) => {
91
95
  const blocks = output.content;
92
96
  const finishedBlocks = /* @__PURE__ */ new Set();
93
97
  const contentIndices = /* @__PURE__ */ new WeakMap();
98
+ let explicitVisibleTextBlocks;
94
99
  const appendBlock = (block) => {
95
100
  contentIndices.set(block, blocks.length);
96
101
  blocks.push(block);
@@ -128,12 +133,21 @@ const streamOpenAICompletions = (model, context, options) => {
128
133
  partial: output
129
134
  });
130
135
  };
131
- const ensureTextBlock = () => {
136
+ const finishTextBlock = () => {
137
+ if (!textBlock) return;
138
+ finishBlock(textBlock);
139
+ textBlock = null;
140
+ textBlockSource = void 0;
141
+ };
142
+ const ensureTextBlock = (source) => {
143
+ if (textBlock && textBlockSource !== source) finishTextBlock();
132
144
  if (!textBlock) {
133
145
  textBlock = {
134
146
  type: "text",
135
147
  text: ""
136
148
  };
149
+ textBlockSource = source;
150
+ if (source === "reasoning_detail") (explicitVisibleTextBlocks ??= /* @__PURE__ */ new Set()).add(textBlock);
137
151
  appendBlock(textBlock);
138
152
  stream.push({
139
153
  type: "text_start",
@@ -165,10 +179,14 @@ const streamOpenAICompletions = (model, context, options) => {
165
179
  thinkingBlock = null;
166
180
  }
167
181
  };
168
- const appendTextDelta = (delta) => {
182
+ const appendTextDelta = (delta, source) => {
169
183
  sealNativeReasoningBeforeText();
170
- const block = ensureTextBlock();
184
+ const block = ensureTextBlock(source);
171
185
  block.text += delta;
186
+ if (pendingInterruptedTextBlock && delta.trim()) {
187
+ confirmedInterruptedTextBlock = pendingInterruptedTextBlock;
188
+ pendingInterruptedTextBlock = null;
189
+ }
172
190
  stream.push({
173
191
  type: "text_delta",
174
192
  contentIndex: getContentIndex(block),
@@ -186,6 +204,15 @@ const streamOpenAICompletions = (model, context, options) => {
186
204
  partial: output
187
205
  });
188
206
  };
207
+ const appendReasoningDeltas = (reasoningDeltas) => {
208
+ for (const reasoningDelta of reasoningDeltas) if (reasoningDelta.kind === "thinking") {
209
+ if (!shouldEmitReasoning) continue;
210
+ finishTextBlock();
211
+ const signature = reasoningDelta.signature;
212
+ const thinkingSignature = model.provider === "opencode-go" && signature === "reasoning" ? "reasoning_content" : signature;
213
+ appendThinkingDelta(thinkingSignature, reasoningDelta.text);
214
+ } else appendTextDelta(reasoningDelta.text, reasoningDelta.source);
215
+ };
189
216
  const ensureToolCallBlock = (toolCall) => {
190
217
  const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
191
218
  let block = streamIndex !== void 0 ? toolCallBlocksByIndex.get(streamIndex) : void 0;
@@ -226,6 +253,21 @@ const streamOpenAICompletions = (model, context, options) => {
226
253
  const flushPartitionedContent = () => {
227
254
  for (const delta of reasoningTagTextPartitioner.flush()) if (delta.kind === "text") appendTextDelta(delta.text);
228
255
  };
256
+ const sealTextBeforeReasoning = () => {
257
+ if (!textBlock && !reasoningTagTextPartitioner.hasPending()) return;
258
+ flushPartitionedContent();
259
+ if (!textBlock) return;
260
+ if (textBlockSource !== "reasoning_detail" && textBlock.text.trim()) pendingInterruptedTextBlock = textBlock;
261
+ finishTextBlock();
262
+ };
263
+ const beginReasoning = (hasFollowingVisibleText, forceStrict = false) => {
264
+ if (!output.openclawDelivery?.textPhaseRequiresTerminal) output.openclawDelivery = {
265
+ ...output.openclawDelivery,
266
+ textPhaseRequiresTerminal: true
267
+ };
268
+ if (forceStrict || reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
269
+ if (!hasFollowingVisibleText || !reasoningTagTextPartitioner.hasPendingSyntax()) sealTextBeforeReasoning();
270
+ };
229
271
  const guardedOpenaiStream = withFirstStreamEventTimeout(hookedOpenAIStream, {
230
272
  provider: model.provider,
231
273
  api: model.api,
@@ -255,30 +297,21 @@ const streamOpenAICompletions = (model, context, options) => {
255
297
  const rawChoiceDelta = choice.delta ?? choice.message;
256
298
  if (rawChoiceDelta) for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
257
299
  const choiceDelta = normalizedDelta.delta;
258
- const reasoningFields = [
259
- "reasoning_content",
260
- "reasoning",
261
- "reasoning_text"
262
- ];
263
- const deltaFields = choiceDelta;
264
- const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
265
- let foundReasoningField = null;
266
- for (const field of reasoningFields) {
267
- const value = deltaFields[field];
268
- if (typeof value === "string" && value.length > 0) {
269
- foundReasoningField = field;
270
- break;
271
- }
272
- }
273
- if (foundReasoningField) reasoningTagTextPartitioner.markStrict();
274
- if (shouldEmitReasoning && foundReasoningField) {
275
- const delta = deltaFields[foundReasoningField];
276
- if (typeof delta === "string" && delta.length > 0) appendThinkingDelta(model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField, delta);
300
+ const reasoningBatch = readOpenAICompletionsReasoningBatch(choiceDelta, visibleReasoningDetailTypes);
301
+ const reasoningDeltas = reasoningBatch.deltas;
302
+ const hasReasoningThinking = reasoningBatch.hasThinking;
303
+ const contentDeltas = readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal, reasoningBatch.mirroredThinking);
304
+ const lastVisibleTextIndex = contentDeltas.findLastIndex((delta) => delta.kind === "text");
305
+ const hasSameChunkVisibleText = reasoningBatch.hasVisibleText || lastVisibleTextIndex !== -1;
306
+ if (hasReasoningThinking) {
307
+ beginReasoning(hasSameChunkVisibleText, true);
308
+ appendReasoningDeltas(reasoningDeltas);
277
309
  }
278
- for (const contentDelta of readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal, foundReasoningField ? [deltaFields[foundReasoningField]] : [])) if (contentDelta.kind === "thinking") {
279
- if (reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
310
+ for (const [contentDeltaIndex, contentDelta] of contentDeltas.entries()) if (contentDelta.kind === "thinking") {
311
+ beginReasoning(contentDeltaIndex < lastVisibleTextIndex);
280
312
  if (shouldEmitReasoning) appendThinkingDelta(contentDelta.signature, contentDelta.text);
281
- } else appendPartitionedContent(contentDelta.text, Boolean(foundReasoningField));
313
+ } else appendPartitionedContent(contentDelta.text, hasReasoningThinking);
314
+ if (!hasReasoningThinking) appendReasoningDeltas(reasoningDeltas);
282
315
  const toolCallDeltas = normalizedDelta.toolCalls;
283
316
  if (toolCallDeltas.length > 0) {
284
317
  flushPartitionedContent();
@@ -332,6 +365,7 @@ const streamOpenAICompletions = (model, context, options) => {
332
365
  for (const block of blocks) if (block.type !== "toolCall") finishBlock(block);
333
366
  throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
334
367
  }
368
+ if (output.stopReason !== "toolUse" && confirmedInterruptedTextBlock) tagInterruptedTextPhases(output.content, confirmedInterruptedTextBlock, explicitVisibleTextBlocks);
335
369
  for (const block of blocks) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
336
370
  if (output.stopReason !== "toolUse") clearPendingCommentaryText(provisionalCommentaryTags);
337
371
  if (output.stopReason === "toolUse") tagPendingCommentaryText(output.content);
@@ -345,6 +379,8 @@ const streamOpenAICompletions = (model, context, options) => {
345
379
  const terminal = projectProviderError(error, options?.signal);
346
380
  Object.assign(output, terminal);
347
381
  finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
382
+ clearPendingCommentaryText(provisionalCommentaryTags);
383
+ tagUnresolvedTextAsCommentary(output);
348
384
  for (const block of output.content) {
349
385
  delete block.index;
350
386
  delete block.partialArgs;
@@ -1,5 +1,5 @@
1
- import { E as Model, O as OpenAICompletionsCompat } from "./types-BHNrPS1l.mjs";
2
- import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-vWgMMhiJ.mjs";
1
+ import { D as Model, k as OpenAICompletionsCompat } from "./types-DTAP49HF.mjs";
2
+ import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DJq_FGcz.mjs";
3
3
 
4
4
  //#region packages/ai/src/transports/openai-completions-compat.d.ts
5
5
  type ProviderRequestCapabilities = AiProviderRequestCapabilities;
@@ -1,11 +1,11 @@
1
1
  import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
2
2
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
3
- import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
4
- import { S as supportsOpenAITemperature } from "./openai-responses-contracts-CyfIkQi5.mjs";
3
+ import { n as getAiTransportHost } from "./host-DF_yxOsA.mjs";
4
+ import { S as supportsOpenAITemperature } from "./openai-responses-contracts-DvILoqBk.mjs";
5
5
  import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
6
6
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
7
- import { n as buildBaseOptions } from "./simple-options-D58D5Kvw.mjs";
8
- import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-DXIt3iY5.mjs";
7
+ import { n as buildBaseOptions } from "./simple-options-oqsXB6U3.mjs";
8
+ import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-Cvt5MgEm.mjs";
9
9
  import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
10
10
  import OpenAI from "openai";
11
11
  //#region packages/ai/src/providers/openai-responses.ts
@@ -1,5 +1,5 @@
1
- import { n as Api } from "./types-BHNrPS1l.mjs";
2
- import { f as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions, p as OpenAIReasoningEffort } from "./provider-options-B96RdNpH.mjs";
1
+ import { n as Api } from "./types-DTAP49HF.mjs";
2
+ import { h as OpenAIReasoningEffort, i as BaseOpenAIStreamOptions, m as OpenAIApiReasoningEffort } from "./provider-options-Cc5ZQ6Aa.mjs";
3
3
  import { FunctionTool, ResponseCompactionItem, ResponseCreateParamsStreaming, ResponseInput } from "openai/resources/responses/responses.js";
4
4
 
5
5
  //#region packages/ai/src/transports/openai-responses-contracts.d.ts
@@ -1,4 +1,4 @@
1
- import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, t as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE } from "./types-BDdaOVi2.mjs";
1
+ import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE } from "./types-BDdaOVi2.mjs";
2
2
  import "./src-D2H6yKkH.mjs";
3
3
  import { a as normalizeOptionalString, n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
4
4
  import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
@@ -177,6 +177,7 @@ const RESPONSE_FAILED_NO_DETAILS_MESSAGE = "Unknown error (no error details in r
177
177
  const OPENAI_RESPONSES_REASONING_REPLAY_META_KEY = "__openclaw_replay";
178
178
  const OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY = "openclawReasoningReplay";
179
179
  const OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE = "openai-responses-compaction";
180
+ const OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE = "openai-responses-retained-compaction";
180
181
  const OPENAI_RESPONSES_APIS = /* @__PURE__ */ new Set([
181
182
  "openai-responses",
182
183
  "azure-openai-responses",
@@ -185,13 +186,6 @@ const OPENAI_RESPONSES_APIS = /* @__PURE__ */ new Set([
185
186
  "openclaw-openai-chatgpt-responses-transport",
186
187
  "openclaw-azure-openai-responses-transport"
187
188
  ]);
188
- var OpenAIResponsesWebSocketResponseFailedError = class extends Error {
189
- constructor(hasOutput) {
190
- super("OpenAI Responses WebSocket returned response.failed");
191
- this.name = "OpenAIResponsesWebSocketResponseFailedError";
192
- this.code = hasOutput ? PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE : PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE;
193
- }
194
- };
195
189
  var OpenAIResponsesWebSocketPreDispatchError = class extends Error {
196
190
  constructor(cause) {
197
191
  super("OpenAI Responses WebSocket failed before request dispatch", { cause });
@@ -250,4 +244,4 @@ const responsesPromptObserver = {
250
244
  }
251
245
  };
252
246
  //#endregion
253
- export { normalizeStringEntries as C, supportsOpenAITemperature as S, uniqueValues as T, isOpenAIGpt56Model as _, OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE as a, resolveOpenAISupportedReasoningEfforts as b, OpenAIResponsesWebSocketPostDispatchError as c, OpenAIResponsesWebSocketSafeRetryError as d, RESPONSE_FAILED_NO_DETAILS_MESSAGE as f, isOpenAIGpt55Model as g, isOpenAIGpt54MiniModel as h, OPENAI_RESPONSES_APIS as i, OpenAIResponsesWebSocketPreDispatchError as l, responsesPromptObserver as m, DEFAULT_AZURE_OPENAI_API_VERSION as n, OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY as o, parseOpenAIResponsesWebSocketServerError as p, OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS as r, OPENAI_RESPONSES_REASONING_REPLAY_META_KEY as s, AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS as t, OpenAIResponsesWebSocketResponseFailedError as u, normalizeOpenAIReasoningEffort as v, uniqueStrings as w, supportsOpenAIReasoningEffort as x, resolveOpenAIReasoningEffortForModel as y };
247
+ export { normalizeStringEntries as C, supportsOpenAITemperature as S, uniqueValues as T, isOpenAIGpt56Model as _, OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE as a, resolveOpenAISupportedReasoningEfforts as b, OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE as c, OpenAIResponsesWebSocketSafeRetryError as d, RESPONSE_FAILED_NO_DETAILS_MESSAGE as f, isOpenAIGpt55Model as g, isOpenAIGpt54MiniModel as h, OPENAI_RESPONSES_APIS as i, OpenAIResponsesWebSocketPostDispatchError as l, responsesPromptObserver as m, DEFAULT_AZURE_OPENAI_API_VERSION as n, OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY as o, parseOpenAIResponsesWebSocketServerError as p, OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS as r, OPENAI_RESPONSES_REASONING_REPLAY_META_KEY as s, AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS as t, OpenAIResponsesWebSocketPreDispatchError as u, normalizeOpenAIReasoningEffort as v, uniqueStrings as w, supportsOpenAIReasoningEffort as x, resolveOpenAIReasoningEffortForModel as y };
@@ -1,6 +1,6 @@
1
1
  import { i as normalizeOptionalLowercaseString, n as normalizeLowercaseStringOrEmpty, s as readStringValue } from "./string-coerce-fsri9iCu.mjs";
2
2
  import { s as parseStrictPositiveInteger } from "./number-coercion-H9qHik3g.mjs";
3
- import { i as OPENAI_RESPONSES_APIS, x as supportsOpenAIReasoningEffort } from "./openai-responses-contracts-CyfIkQi5.mjs";
3
+ import { i as OPENAI_RESPONSES_APIS, x as supportsOpenAIReasoningEffort } from "./openai-responses-contracts-DvILoqBk.mjs";
4
4
  //#region packages/model-catalog-core/src/provider-id.ts
5
5
  function normalizeProviderId(provider) {
6
6
  return normalizeLowercaseStringOrEmpty(provider);
@@ -132,8 +132,10 @@ function parsePositiveInteger(value) {
132
132
  if (typeof value === "string") return parseStrictPositiveInteger(value);
133
133
  }
134
134
  function resolveOpenAIResponsesCompactThreshold(model) {
135
+ const contextTokens = parsePositiveInteger(model.contextTokens);
135
136
  const contextWindow = parsePositiveInteger(model.contextWindow);
136
- if (contextWindow) return Math.max(1e3, Math.floor(contextWindow * .7));
137
+ const effectiveBudget = contextTokens && contextWindow ? Math.min(contextTokens, contextWindow) : contextTokens || contextWindow;
138
+ if (effectiveBudget) return Math.max(1e3, Math.floor(effectiveBudget * .7));
137
139
  return 8e4;
138
140
  }
139
141
  /** Resolve the server-compaction gate and effective threshold for a Responses route. */
@@ -4,6 +4,7 @@ type OpenAIResponsesPayloadModel = {
4
4
  baseUrl?: unknown;
5
5
  id?: unknown;
6
6
  provider?: unknown;
7
+ contextTokens?: unknown;
7
8
  contextWindow?: unknown;
8
9
  compat?: unknown;
9
10
  };
@@ -1,6 +1,5 @@
1
- import { m as responsesPromptObserver } from "./openai-responses-contracts-CyfIkQi5.mjs";
2
- import { l as stripSystemPromptCacheBoundary } from "./simple-options-D58D5Kvw.mjs";
3
- import { d as sanitizeTransportPayloadText } from "./provider-transcript-transform-ePx-Bbfr.mjs";
1
+ import { m as responsesPromptObserver } from "./openai-responses-contracts-DvILoqBk.mjs";
2
+ import { b as sanitizeTransportPayloadText, j as stripSystemPromptCacheBoundary } from "./simple-options-oqsXB6U3.mjs";
4
3
  //#region packages/normalization-core/src/error-coercion.ts
5
4
  /**
6
5
  * Normalizes an unknown thrown value into an Error. Non-Error objects become