privateer-agent 0.15.4 → 0.15.6

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 (229) hide show
  1. package/README.md +11 -0
  2. package/bin/boot-bundle.d.mts +2 -0
  3. package/bin/boot-bundle.mjs +44 -0
  4. package/bin/fresh-supervisor.d.mts +5 -1
  5. package/bin/fresh-supervisor.mjs +47 -10
  6. package/bin/privateer-launch.mjs +27 -3
  7. package/bin/privateer-subagent.mjs +5 -2
  8. package/bin/privateer-verify.mjs +12 -0
  9. package/bin/session-recovery.d.mts +53 -0
  10. package/bin/session-recovery.mjs +240 -0
  11. package/bin/session-seal-preload.mjs +17 -0
  12. package/bin/session-seal.d.mts +25 -0
  13. package/bin/session-seal.mjs +242 -0
  14. package/dist-boot/boot.mjs +3 -0
  15. package/dist-boot/c-27JKSMWL.mjs +1460 -0
  16. package/dist-boot/c-2BMRFV24.mjs +269 -0
  17. package/dist-boot/c-2CTF6JA3.mjs +166 -0
  18. package/dist-boot/c-2G3BBHRJ.mjs +84 -0
  19. package/dist-boot/c-2IDLKXX6.mjs +250 -0
  20. package/dist-boot/c-2NJD5VYM.mjs +8 -0
  21. package/dist-boot/c-2S5EEQPW.mjs +1602 -0
  22. package/dist-boot/c-2WRDCUVI.mjs +25 -0
  23. package/dist-boot/c-2YN3M256.mjs +14 -0
  24. package/dist-boot/c-37GM3GMU.mjs +187 -0
  25. package/dist-boot/c-3STKRSVO.mjs +2480 -0
  26. package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
  27. package/dist-boot/c-3UVHLQDJ.mjs +225 -0
  28. package/dist-boot/c-42PUUZYC.mjs +697 -0
  29. package/dist-boot/c-4D5UMWVW.mjs +683 -0
  30. package/dist-boot/c-4ETZRMTA.mjs +46 -0
  31. package/dist-boot/c-4QT25BD5.mjs +1482 -0
  32. package/dist-boot/c-4WVR32AP.mjs +2579 -0
  33. package/dist-boot/c-5EMM567G.mjs +152 -0
  34. package/dist-boot/c-5FA4CV63.mjs +145 -0
  35. package/dist-boot/c-5GV3X3RB.mjs +14 -0
  36. package/dist-boot/c-5JCEPRIY.mjs +52 -0
  37. package/dist-boot/c-5NDKIIWT.mjs +16 -0
  38. package/dist-boot/c-5QL3AR26.mjs +4665 -0
  39. package/dist-boot/c-5XY6MFKN.mjs +5142 -0
  40. package/dist-boot/c-65UZIZC7.mjs +2897 -0
  41. package/dist-boot/c-6FUXKHOK.mjs +1969 -0
  42. package/dist-boot/c-6JHWQE4V.mjs +18242 -0
  43. package/dist-boot/c-6LOBR4I6.mjs +5280 -0
  44. package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
  45. package/dist-boot/c-6ZO2SADQ.mjs +178 -0
  46. package/dist-boot/c-6ZORVVZP.mjs +1449 -0
  47. package/dist-boot/c-76QH4UCP.mjs +2441 -0
  48. package/dist-boot/c-77GO5L5Y.mjs +20982 -0
  49. package/dist-boot/c-7M23XFTN.mjs +5052 -0
  50. package/dist-boot/c-7TC367E2.mjs +32 -0
  51. package/dist-boot/c-7UOG7POX.mjs +1524 -0
  52. package/dist-boot/c-7VHP3FLN.mjs +376 -0
  53. package/dist-boot/c-A73JHZP2.mjs +13207 -0
  54. package/dist-boot/c-ABXULAFL.mjs +71 -0
  55. package/dist-boot/c-ANDD2AQO.mjs +74 -0
  56. package/dist-boot/c-AOY77AZL.mjs +1430 -0
  57. package/dist-boot/c-AXEPZ22I.mjs +108 -0
  58. package/dist-boot/c-B2Y7VNHU.mjs +427 -0
  59. package/dist-boot/c-B7VJUH73.mjs +77 -0
  60. package/dist-boot/c-BFW6CDVL.mjs +24 -0
  61. package/dist-boot/c-BHNIF2AR.mjs +188 -0
  62. package/dist-boot/c-BKF2O6BL.mjs +23 -0
  63. package/dist-boot/c-BOZXFTZN.mjs +8 -0
  64. package/dist-boot/c-BRNYJWZL.mjs +28 -0
  65. package/dist-boot/c-C3N4Z2HO.mjs +93 -0
  66. package/dist-boot/c-C4IV7ZFG.mjs +717 -0
  67. package/dist-boot/c-C5NK6UYV.mjs +793 -0
  68. package/dist-boot/c-C67644MB.mjs +1659 -0
  69. package/dist-boot/c-C6S2YB53.mjs +620 -0
  70. package/dist-boot/c-CDBEJSBF.mjs +37 -0
  71. package/dist-boot/c-CG47HBKU.mjs +435 -0
  72. package/dist-boot/c-CKCTWCT5.mjs +51 -0
  73. package/dist-boot/c-CN77DCGF.mjs +60 -0
  74. package/dist-boot/c-CRBXNKFO.mjs +1795 -0
  75. package/dist-boot/c-CRIHASQ6.mjs +973 -0
  76. package/dist-boot/c-CU4NGAUO.mjs +3786 -0
  77. package/dist-boot/c-CWRFLGQU.mjs +1883 -0
  78. package/dist-boot/c-CYQB2USO.mjs +32 -0
  79. package/dist-boot/c-DEE67DJO.mjs +379 -0
  80. package/dist-boot/c-DIFDBYOP.mjs +1258 -0
  81. package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
  82. package/dist-boot/c-DR7XQI32.mjs +381 -0
  83. package/dist-boot/c-DTGPSB46.mjs +14666 -0
  84. package/dist-boot/c-DTHDNA4P.mjs +320 -0
  85. package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
  86. package/dist-boot/c-E66Z2TI7.mjs +203 -0
  87. package/dist-boot/c-EBU6RLRV.mjs +1527 -0
  88. package/dist-boot/c-EBZZNGSF.mjs +432 -0
  89. package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
  90. package/dist-boot/c-EQBKXWNX.mjs +15829 -0
  91. package/dist-boot/c-EUEPIW4S.mjs +574 -0
  92. package/dist-boot/c-EX4YVWAT.mjs +378 -0
  93. package/dist-boot/c-EYZGSAJU.mjs +98 -0
  94. package/dist-boot/c-F75VRKY4.mjs +172 -0
  95. package/dist-boot/c-FH4NXKHV.mjs +177 -0
  96. package/dist-boot/c-FHNUCTEM.mjs +140 -0
  97. package/dist-boot/c-FJ5T42DS.mjs +5349 -0
  98. package/dist-boot/c-FPCNRL7G.mjs +1728 -0
  99. package/dist-boot/c-G4DLN7Q4.mjs +8 -0
  100. package/dist-boot/c-G56GYQFZ.mjs +2507 -0
  101. package/dist-boot/c-GLIOERDQ.mjs +1200 -0
  102. package/dist-boot/c-GMJ5HUBM.mjs +14 -0
  103. package/dist-boot/c-H3HSGMAQ.mjs +461 -0
  104. package/dist-boot/c-HIKTO6P7.mjs +275 -0
  105. package/dist-boot/c-I2MCJ34O.mjs +464 -0
  106. package/dist-boot/c-I3C6LBW4.mjs +765 -0
  107. package/dist-boot/c-I54OKQHW.mjs +387 -0
  108. package/dist-boot/c-IFSP3R4D.mjs +80 -0
  109. package/dist-boot/c-IZK77VB7.mjs +171 -0
  110. package/dist-boot/c-J3Y25UGE.mjs +54 -0
  111. package/dist-boot/c-J5IESS7W.mjs +27750 -0
  112. package/dist-boot/c-JJWZBY7L.mjs +254 -0
  113. package/dist-boot/c-JKTFXTGF.mjs +463 -0
  114. package/dist-boot/c-JN57AXQ4.mjs +77 -0
  115. package/dist-boot/c-KFIO6LUW.mjs +1096 -0
  116. package/dist-boot/c-KIEMEFWW.mjs +478 -0
  117. package/dist-boot/c-KIVXWBYD.mjs +28 -0
  118. package/dist-boot/c-KP6CRIP4.mjs +580 -0
  119. package/dist-boot/c-L26VOJX4.mjs +11558 -0
  120. package/dist-boot/c-L5GHWG5G.mjs +5988 -0
  121. package/dist-boot/c-M7NSQAKK.mjs +353 -0
  122. package/dist-boot/c-MCEWOPBW.mjs +56 -0
  123. package/dist-boot/c-MGPIEG7I.mjs +20 -0
  124. package/dist-boot/c-NREXJV3M.mjs +393 -0
  125. package/dist-boot/c-O5PP6CTX.mjs +162 -0
  126. package/dist-boot/c-OBQDHSXM.mjs +1774 -0
  127. package/dist-boot/c-OLQHHDD4.mjs +21 -0
  128. package/dist-boot/c-OXW4JQQH.mjs +319 -0
  129. package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
  130. package/dist-boot/c-P4PQZVV5.mjs +948 -0
  131. package/dist-boot/c-P63T3XL2.mjs +26373 -0
  132. package/dist-boot/c-P6N5DQGZ.mjs +194 -0
  133. package/dist-boot/c-P7MLKQFC.mjs +58 -0
  134. package/dist-boot/c-PB3PZJL5.mjs +1276 -0
  135. package/dist-boot/c-PTN4S6G2.mjs +1259 -0
  136. package/dist-boot/c-PYCE5J7U.mjs +1083 -0
  137. package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
  138. package/dist-boot/c-QUXMETGG.mjs +68 -0
  139. package/dist-boot/c-RDMJZCOX.mjs +356 -0
  140. package/dist-boot/c-ROGJK76M.mjs +17 -0
  141. package/dist-boot/c-RQJJ26T4.mjs +708 -0
  142. package/dist-boot/c-RSKCUPJF.mjs +7559 -0
  143. package/dist-boot/c-RVJU4O6P.mjs +37 -0
  144. package/dist-boot/c-S2RVHR3M.mjs +165 -0
  145. package/dist-boot/c-SKMK3PEE.mjs +91120 -0
  146. package/dist-boot/c-TI7SM4EG.mjs +20 -0
  147. package/dist-boot/c-TILJ6GXD.mjs +1235 -0
  148. package/dist-boot/c-TT6BCUJD.mjs +114 -0
  149. package/dist-boot/c-U4ITOXAN.mjs +2107 -0
  150. package/dist-boot/c-UGERXVO2.mjs +7120 -0
  151. package/dist-boot/c-UPBH5AXY.mjs +1363 -0
  152. package/dist-boot/c-US2PUNZL.mjs +597 -0
  153. package/dist-boot/c-UU4WZPPE.mjs +20 -0
  154. package/dist-boot/c-UWVIYPQS.mjs +39 -0
  155. package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
  156. package/dist-boot/c-V5MRVK47.mjs +351 -0
  157. package/dist-boot/c-V6CL266R.mjs +1755 -0
  158. package/dist-boot/c-VJTMFKYE.mjs +14975 -0
  159. package/dist-boot/c-VJTRUKIB.mjs +773 -0
  160. package/dist-boot/c-W4IFSHPW.mjs +43 -0
  161. package/dist-boot/c-WETGB2CF.mjs +113 -0
  162. package/dist-boot/c-WO3QSZUU.mjs +1337 -0
  163. package/dist-boot/c-WQLH73TY.mjs +242 -0
  164. package/dist-boot/c-XL735JW5.mjs +500 -0
  165. package/dist-boot/c-Y7HADL5B.mjs +1107 -0
  166. package/dist-boot/c-YGQHSVSK.mjs +41 -0
  167. package/dist-boot/c-YMP2AMEB.mjs +10350 -0
  168. package/dist-boot/c-YRDO2WEF.mjs +12012 -0
  169. package/dist-boot/c-YUSTRATJ.mjs +8 -0
  170. package/dist-boot/c-Z2262R22.mjs +2697 -0
  171. package/dist-boot/c-Z4ALQMJC.mjs +709 -0
  172. package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
  173. package/dist-boot/c-ZDZUKXF7.mjs +874 -0
  174. package/dist-boot/c-ZJYLGIC3.mjs +32 -0
  175. package/dist-boot/c-ZNA5CDMI.mjs +77 -0
  176. package/dist-boot/c-ZSO6DI3M.mjs +204 -0
  177. package/dist-boot/c-ZWUVHKMK.mjs +100 -0
  178. package/dist-boot/c-ZY4MESEW.mjs +832 -0
  179. package/dist-boot/c-ZZ5REI4L.mjs +329 -0
  180. package/dist-boot/cli.mjs +51 -0
  181. package/dist-boot/ext-anthropic-attribution.mjs +207 -0
  182. package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
  183. package/dist-boot/ext-pi-subagents.mjs +37 -0
  184. package/dist-boot/ext-privateer-account.mjs +4426 -0
  185. package/dist-boot/ext-privateer-brand.mjs +5274 -0
  186. package/dist-boot/ext-privateer-codemode.mjs +37 -0
  187. package/dist-boot/ext-privateer-computer.mjs +626 -0
  188. package/dist-boot/ext-privateer-connect.mjs +1862 -0
  189. package/dist-boot/ext-privateer-context.mjs +323 -0
  190. package/dist-boot/ext-privateer-desktop.mjs +92 -0
  191. package/dist-boot/ext-privateer-final-audit.mjs +48 -0
  192. package/dist-boot/ext-privateer-fresh.mjs +81 -0
  193. package/dist-boot/ext-privateer-gate.mjs +5959 -0
  194. package/dist-boot/ext-privateer-hints.mjs +236 -0
  195. package/dist-boot/ext-privateer-media.mjs +2626 -0
  196. package/dist-boot/ext-privateer-models.mjs +3397 -0
  197. package/dist-boot/ext-privateer-posture.mjs +3006 -0
  198. package/dist-boot/ext-privateer-privacy.mjs +4578 -0
  199. package/dist-boot/ext-privateer-recovery.mjs +287 -0
  200. package/dist-boot/ext-privateer-speak.mjs +4754 -0
  201. package/dist-boot/ext-privateer-terminals.mjs +725 -0
  202. package/dist-boot/ext-privateer-tools.mjs +528 -0
  203. package/dist-boot/ext-privateer-truncation.mjs +74 -0
  204. package/dist-boot/ext-privateer-update.mjs +210 -0
  205. package/dist-boot/ext-privateer-vision.mjs +148 -0
  206. package/dist-boot/ext-privateer-web.mjs +543 -0
  207. package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
  208. package/dist-boot/manifest.json +9 -0
  209. package/extensions/privateer-brand.ts +3 -1
  210. package/extensions/privateer-context.ts +4 -2
  211. package/extensions/privateer-final-audit.ts +17 -0
  212. package/extensions/privateer-gate.ts +55 -9
  213. package/extensions/privateer-recovery.ts +175 -0
  214. package/extensions/privateer-web.ts +4 -4
  215. package/package.json +3 -1
  216. package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
  217. package/patches/pi-background-tasks+2.6.10.patch +91 -7
  218. package/src/cli/chat.ts +7 -1
  219. package/src/config/moatManifest.json +2 -0
  220. package/src/config/whatsNew.json +4 -4
  221. package/src/context.ts +33 -5
  222. package/src/engine/finalAudit.ts +38 -0
  223. package/src/engine/stallWatchdog.ts +8 -1
  224. package/src/providers/account.ts +34 -3
  225. package/src/remote/attentionPush.ts +40 -0
  226. package/src/remote/liveTaskSession.ts +7 -1
  227. package/src/remote/relayClient.ts +38 -4
  228. package/src/remote/remoteBridge.ts +17 -0
  229. package/src/remote/transcriptSnapshot.ts +104 -0
@@ -0,0 +1,1235 @@
1
+ import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
2
+ import {
3
+ clampOpenAIPromptCacheKey
4
+ } from "./c-UU4WZPPE.mjs";
5
+ import {
6
+ shortHash
7
+ } from "./c-BKF2O6BL.mjs";
8
+ import {
9
+ OpenAI
10
+ } from "./c-Q4HYCRLB.mjs";
11
+ import {
12
+ formatProviderError,
13
+ normalizeProviderError
14
+ } from "./c-ZWUVHKMK.mjs";
15
+ import {
16
+ buildCopilotDynamicHeaders,
17
+ hasCopilotVisionInput
18
+ } from "./c-UWVIYPQS.mjs";
19
+ import {
20
+ appendGrammarToolInputJsonDelta,
21
+ buildBaseOptions,
22
+ clampThinkingBudgetToAnswerRoom,
23
+ createGrammarToolInputProperties,
24
+ getGrammarToolInput,
25
+ getJsonSchemaToolParameters,
26
+ getPiUserAgent,
27
+ resolveGrammarConstrainedSampling,
28
+ resolveJsonSchemaStrictSampling,
29
+ resolveSamplingParams,
30
+ thinkingBudgetForLevel,
31
+ transformMessages
32
+ } from "./c-C6S2YB53.mjs";
33
+ import {
34
+ sanitizeSurrogates
35
+ } from "./c-5GV3X3RB.mjs";
36
+ import {
37
+ retryProviderRequest
38
+ } from "./c-EYZGSAJU.mjs";
39
+ import {
40
+ headersToRecord
41
+ } from "./c-ZJYLGIC3.mjs";
42
+ import {
43
+ getProviderEnvValue
44
+ } from "./c-CDBEJSBF.mjs";
45
+ import {
46
+ parseStreamingJson,
47
+ parseToolCallArguments
48
+ } from "./c-DEE67DJO.mjs";
49
+ import {
50
+ calculateCost,
51
+ clampThinkingLevel,
52
+ getDeclaredTools,
53
+ getSystemMessageText,
54
+ renderSystemMessageUpdate,
55
+ resolveTranscript,
56
+ resolveTranscriptTools
57
+ } from "./c-WO3QSZUU.mjs";
58
+ import {
59
+ AssistantMessageEventStream
60
+ } from "./c-S2RVHR3M.mjs";
61
+ import {
62
+ __name
63
+ } from "./c-CN77DCGF.mjs";
64
+
65
+ // node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js
66
+ function hasHeader(headers, name) {
67
+ if (!headers)
68
+ return false;
69
+ const expected = name.toLowerCase();
70
+ for (const [key, value] of Object.entries(headers)) {
71
+ if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+ __name(hasHeader, "hasHeader");
77
+ function getClientApiKey(provider, apiKey, headers) {
78
+ if (apiKey)
79
+ return apiKey;
80
+ if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization"))
81
+ return "unused";
82
+ throw new Error(`No API key for provider: ${provider}`);
83
+ }
84
+ __name(getClientApiKey, "getClientApiKey");
85
+ function hasToolHistory(messages) {
86
+ for (const msg of messages) {
87
+ if (msg.role === "toolResult") {
88
+ return true;
89
+ }
90
+ if (msg.role === "assistant") {
91
+ if (msg.content.some((block) => block.type === "toolCall")) {
92
+ return true;
93
+ }
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+ __name(hasToolHistory, "hasToolHistory");
99
+ function isTextContentBlock(block) {
100
+ return block.type === "text";
101
+ }
102
+ __name(isTextContentBlock, "isTextContentBlock");
103
+ function isThinkingContentBlock(block) {
104
+ return block.type === "thinking";
105
+ }
106
+ __name(isThinkingContentBlock, "isThinkingContentBlock");
107
+ function isToolCallBlock(block) {
108
+ return block.type === "toolCall";
109
+ }
110
+ __name(isToolCallBlock, "isToolCallBlock");
111
+ function isImageContentBlock(block) {
112
+ return block.type === "image";
113
+ }
114
+ __name(isImageContentBlock, "isImageContentBlock");
115
+ function isReasoningDetailObject(detail) {
116
+ return typeof detail === "object" && detail !== null && !Array.isArray(detail);
117
+ }
118
+ __name(isReasoningDetailObject, "isReasoningDetailObject");
119
+ function hasValidCommonReasoningDetailFields(candidate) {
120
+ return (candidate.id === void 0 || candidate.id === null || typeof candidate.id === "string") && (candidate.format === void 0 || typeof candidate.format === "string") && (candidate.index === void 0 || typeof candidate.index === "number");
121
+ }
122
+ __name(hasValidCommonReasoningDetailFields, "hasValidCommonReasoningDetailFields");
123
+ function isOpenAIReasoningDetail(detail) {
124
+ if (!isReasoningDetailObject(detail) || !hasValidCommonReasoningDetailFields(detail)) {
125
+ return false;
126
+ }
127
+ switch (detail.type) {
128
+ case "reasoning.summary":
129
+ return typeof detail.summary === "string";
130
+ case "reasoning.encrypted":
131
+ return typeof detail.data === "string";
132
+ case "reasoning.text":
133
+ return typeof detail.text === "string" && (detail.signature === void 0 || detail.signature === null || typeof detail.signature === "string");
134
+ default:
135
+ return false;
136
+ }
137
+ }
138
+ __name(isOpenAIReasoningDetail, "isOpenAIReasoningDetail");
139
+ function parseOpenAIReasoningDetails(signature) {
140
+ if (!signature)
141
+ return void 0;
142
+ try {
143
+ const parsed = JSON.parse(signature);
144
+ return Array.isArray(parsed) && parsed.length > 0 && parsed.every(isOpenAIReasoningDetail) ? parsed : void 0;
145
+ } catch {
146
+ return void 0;
147
+ }
148
+ }
149
+ __name(parseOpenAIReasoningDetails, "parseOpenAIReasoningDetails");
150
+ function parseLegacyEncryptedReasoningDetail(signature) {
151
+ if (!signature)
152
+ return void 0;
153
+ try {
154
+ const parsed = JSON.parse(signature);
155
+ return isOpenAIReasoningDetail(parsed) && parsed.type === "reasoning.encrypted" && typeof parsed.id === "string" && parsed.id.length > 0 && parsed.data.length > 0 ? parsed : void 0;
156
+ } catch {
157
+ return void 0;
158
+ }
159
+ }
160
+ __name(parseLegacyEncryptedReasoningDetail, "parseLegacyEncryptedReasoningDetail");
161
+ function fillMissingCommonReasoningDetailFields(target, source) {
162
+ target.id ??= source.id;
163
+ target.format ||= source.format;
164
+ target.index ??= source.index;
165
+ }
166
+ __name(fillMissingCommonReasoningDetailFields, "fillMissingCommonReasoningDetailFields");
167
+ function appendOpenAIReasoningDetail(details, detail) {
168
+ const lastDetail = details[details.length - 1];
169
+ if (detail.type === "reasoning.text" && lastDetail?.type === "reasoning.text") {
170
+ lastDetail.text += detail.text;
171
+ lastDetail.signature ||= detail.signature;
172
+ fillMissingCommonReasoningDetailFields(lastDetail, detail);
173
+ return;
174
+ }
175
+ if (detail.type === "reasoning.summary" && lastDetail?.type === "reasoning.summary") {
176
+ lastDetail.summary += detail.summary;
177
+ fillMissingCommonReasoningDetailFields(lastDetail, detail);
178
+ return;
179
+ }
180
+ details.push({ ...detail });
181
+ }
182
+ __name(appendOpenAIReasoningDetail, "appendOpenAIReasoningDetail");
183
+ var OPENAI_COMPLETIONS_REASONING_FIELDS = ["reasoning", "reasoning_content", "reasoning_text"];
184
+ function isOpenAICompletionsReasoningField(field) {
185
+ return OPENAI_COMPLETIONS_REASONING_FIELDS.includes(field);
186
+ }
187
+ __name(isOpenAICompletionsReasoningField, "isOpenAICompletionsReasoningField");
188
+ function resolveCacheRetention(cacheRetention, env) {
189
+ if (cacheRetention) {
190
+ return cacheRetention;
191
+ }
192
+ if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") {
193
+ return "long";
194
+ }
195
+ return "short";
196
+ }
197
+ __name(resolveCacheRetention, "resolveCacheRetention");
198
+ var stream = /* @__PURE__ */ __name((model, context, options) => {
199
+ const stream2 = new AssistantMessageEventStream();
200
+ const normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
201
+ (async () => {
202
+ const output = {
203
+ role: "assistant",
204
+ content: [],
205
+ api: model.api,
206
+ provider: model.provider,
207
+ model: model.id,
208
+ usage: {
209
+ input: 0,
210
+ output: 0,
211
+ cacheRead: 0,
212
+ cacheWrite: 0,
213
+ totalTokens: 0,
214
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
215
+ },
216
+ stopReason: "pending",
217
+ timestamp: Date.now()
218
+ };
219
+ let streamedReasoningDetails;
220
+ const applyStreamedReasoningDetails = /* @__PURE__ */ __name((block) => {
221
+ if (streamedReasoningDetails !== void 0) {
222
+ block.thinkingSignature = JSON.stringify(streamedReasoningDetails);
223
+ }
224
+ }, "applyStreamedReasoningDetails");
225
+ try {
226
+ const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
227
+ const compat = getCompat(model);
228
+ const grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(normalizedContext.messages), compat.supportsOpenAIGrammarTools);
229
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
230
+ const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
231
+ const client = createClient(model, normalizedContext, apiKey, options?.headers, options?.fetch, cacheSessionId, compat);
232
+ let params = buildParams(model, normalizedContext, options, compat, cacheRetention, grammarToolInputProperties);
233
+ const nextParams = await options?.onPayload?.(params, model);
234
+ if (nextParams !== void 0) {
235
+ params = nextParams;
236
+ }
237
+ const requestOptions = {
238
+ ...options?.signal ? { signal: options.signal } : {},
239
+ ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
240
+ maxRetries: 0
241
+ };
242
+ const { data: openaiStream, response } = await retryProviderRequest(() => client.chat.completions.create(params, requestOptions).withResponse(), {
243
+ maxRetries: options?.maxRetries,
244
+ maxRetryDelayMs: options?.maxRetryDelayMs,
245
+ signal: options?.signal
246
+ });
247
+ await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
248
+ stream2.push({ type: "start", partial: output });
249
+ let textBlock = null;
250
+ let thinkingBlock = null;
251
+ let hasFinishReason = false;
252
+ const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
253
+ const toolCallBlocksById = /* @__PURE__ */ new Map();
254
+ const blocks = output.content;
255
+ const getContentIndex = /* @__PURE__ */ __name((block) => blocks.indexOf(block), "getContentIndex");
256
+ const getCustomToolCallInput = /* @__PURE__ */ __name((block) => {
257
+ const property = block.customInput?.property;
258
+ if (property === void 0)
259
+ return "";
260
+ const value = block.arguments[property];
261
+ return typeof value === "string" ? value : "";
262
+ }, "getCustomToolCallInput");
263
+ const appendCustomToolCallInput = /* @__PURE__ */ __name((block, nextInput, close) => {
264
+ const customInput = block.customInput;
265
+ if (!customInput)
266
+ return void 0;
267
+ const delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);
268
+ block.arguments = { [customInput.property]: nextInput };
269
+ return delta;
270
+ }, "appendCustomToolCallInput");
271
+ const finishBlock = /* @__PURE__ */ __name((block) => {
272
+ const contentIndex = getContentIndex(block);
273
+ if (contentIndex === -1) {
274
+ return;
275
+ }
276
+ if (block.type === "text") {
277
+ stream2.push({
278
+ type: "text_end",
279
+ contentIndex,
280
+ content: block.text,
281
+ partial: output
282
+ });
283
+ } else if (block.type === "thinking") {
284
+ applyStreamedReasoningDetails(block);
285
+ stream2.push({
286
+ type: "thinking_end",
287
+ contentIndex,
288
+ content: block.thinking,
289
+ partial: output
290
+ });
291
+ } else if (block.type === "toolCall") {
292
+ if (block.customInput) {
293
+ const delta = appendCustomToolCallInput(block, getCustomToolCallInput(block), true);
294
+ if (delta !== void 0) {
295
+ stream2.push({
296
+ type: "toolcall_delta",
297
+ contentIndex,
298
+ delta,
299
+ partial: output
300
+ });
301
+ }
302
+ } else {
303
+ Object.assign(block, parseToolCallArguments(block.partialArgs));
304
+ }
305
+ delete block.partialArgs;
306
+ delete block.customInput;
307
+ delete block.streamIndex;
308
+ stream2.push({
309
+ type: "toolcall_end",
310
+ contentIndex,
311
+ toolCall: block,
312
+ partial: output
313
+ });
314
+ }
315
+ }, "finishBlock");
316
+ const ensureTextBlock = /* @__PURE__ */ __name(() => {
317
+ if (!textBlock) {
318
+ textBlock = { type: "text", text: "" };
319
+ blocks.push(textBlock);
320
+ stream2.push({ type: "text_start", contentIndex: getContentIndex(textBlock), partial: output });
321
+ }
322
+ return textBlock;
323
+ }, "ensureTextBlock");
324
+ const ensureThinkingBlock = /* @__PURE__ */ __name((thinkingSignature) => {
325
+ if (!thinkingBlock) {
326
+ thinkingBlock = {
327
+ type: "thinking",
328
+ thinking: "",
329
+ thinkingSignature
330
+ };
331
+ blocks.push(thinkingBlock);
332
+ stream2.push({ type: "thinking_start", contentIndex: getContentIndex(thinkingBlock), partial: output });
333
+ }
334
+ return thinkingBlock;
335
+ }, "ensureThinkingBlock");
336
+ const ensureToolCallBlock = /* @__PURE__ */ __name((toolCall) => {
337
+ const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
338
+ const name = toolCall.function?.name ?? toolCall.custom?.name ?? "";
339
+ let block = streamIndex !== void 0 ? toolCallBlocksByIndex.get(streamIndex) : void 0;
340
+ if (!block && toolCall.id) {
341
+ block = toolCallBlocksById.get(toolCall.id);
342
+ }
343
+ if (!block) {
344
+ const customInputProperty = toolCall.custom && !toolCall.function ? grammarToolInputProperties.get(name) ?? "input" : void 0;
345
+ const hasCustomInput = customInputProperty !== void 0;
346
+ block = {
347
+ type: "toolCall",
348
+ id: toolCall.id || "",
349
+ name,
350
+ arguments: hasCustomInput ? { [customInputProperty]: "" } : {},
351
+ partialArgs: hasCustomInput ? void 0 : "",
352
+ customInput: hasCustomInput ? { property: customInputProperty, jsonBuffer: { input: "", started: false, closed: false } } : void 0,
353
+ streamIndex
354
+ };
355
+ if (streamIndex !== void 0) {
356
+ toolCallBlocksByIndex.set(streamIndex, block);
357
+ }
358
+ if (toolCall.id) {
359
+ toolCallBlocksById.set(toolCall.id, block);
360
+ }
361
+ blocks.push(block);
362
+ stream2.push({
363
+ type: "toolcall_start",
364
+ contentIndex: getContentIndex(block),
365
+ partial: output
366
+ });
367
+ }
368
+ if (streamIndex !== void 0 && block.streamIndex === void 0) {
369
+ block.streamIndex = streamIndex;
370
+ toolCallBlocksByIndex.set(streamIndex, block);
371
+ }
372
+ if (toolCall.id) {
373
+ toolCallBlocksById.set(toolCall.id, block);
374
+ }
375
+ if (!block.name && name) {
376
+ block.name = name;
377
+ }
378
+ if (toolCall.custom && !toolCall.function && !block.customInput) {
379
+ const customInputProperty = grammarToolInputProperties.get(block.name) ?? "input";
380
+ block.arguments = { [customInputProperty]: "" };
381
+ block.customInput = {
382
+ property: customInputProperty,
383
+ jsonBuffer: { input: "", started: false, closed: false }
384
+ };
385
+ delete block.partialArgs;
386
+ }
387
+ return block;
388
+ }, "ensureToolCallBlock");
389
+ for await (const chunk of openaiStream) {
390
+ await options?.onProviderStreamEvent?.(chunk, model);
391
+ if (!chunk || typeof chunk !== "object")
392
+ continue;
393
+ output.responseId ||= chunk.id;
394
+ if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) {
395
+ output.responseModel ||= chunk.model;
396
+ }
397
+ if (chunk.usage) {
398
+ output.usage = parseChunkUsage(chunk.usage, model);
399
+ }
400
+ const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
401
+ if (!choice)
402
+ continue;
403
+ if (!chunk.usage && choice.usage) {
404
+ output.usage = parseChunkUsage(choice.usage, model);
405
+ }
406
+ if (choice.finish_reason) {
407
+ output.rawStopReason = choice.finish_reason;
408
+ const finishReasonResult = mapStopReason(choice.finish_reason);
409
+ output.stopReason = finishReasonResult.stopReason;
410
+ if (finishReasonResult.errorMessage) {
411
+ output.errorMessage = finishReasonResult.errorMessage;
412
+ }
413
+ hasFinishReason = true;
414
+ }
415
+ if (choice.delta) {
416
+ const reasoningFields = ["reasoning_content", "reasoning", "reasoning_text"];
417
+ const deltaFields = choice.delta;
418
+ let foundReasoningField = null;
419
+ for (const field of reasoningFields) {
420
+ const value = deltaFields[field];
421
+ if (typeof value === "string" && value.length > 0) {
422
+ foundReasoningField = field;
423
+ break;
424
+ }
425
+ }
426
+ if (foundReasoningField) {
427
+ const delta = deltaFields[foundReasoningField];
428
+ if (typeof delta === "string" && delta.length > 0) {
429
+ const thinkingSignature = model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField;
430
+ const block = ensureThinkingBlock(thinkingSignature);
431
+ block.thinking += delta;
432
+ stream2.push({
433
+ type: "thinking_delta",
434
+ contentIndex: getContentIndex(block),
435
+ delta,
436
+ partial: output
437
+ });
438
+ }
439
+ }
440
+ const reasoningDetails = choice.delta.reasoning_details;
441
+ if (Array.isArray(reasoningDetails)) {
442
+ for (const detail of reasoningDetails) {
443
+ if (!isOpenAIReasoningDetail(detail))
444
+ continue;
445
+ ensureThinkingBlock("");
446
+ streamedReasoningDetails ??= [];
447
+ appendOpenAIReasoningDetail(streamedReasoningDetails, detail);
448
+ }
449
+ }
450
+ if (choice.delta.content !== null && choice.delta.content !== void 0 && choice.delta.content.length > 0) {
451
+ const block = ensureTextBlock();
452
+ block.text += choice.delta.content;
453
+ stream2.push({
454
+ type: "text_delta",
455
+ contentIndex: getContentIndex(block),
456
+ delta: choice.delta.content,
457
+ partial: output
458
+ });
459
+ }
460
+ if (choice?.delta?.tool_calls) {
461
+ for (const toolCall of choice.delta.tool_calls) {
462
+ const block = ensureToolCallBlock(toolCall);
463
+ if (!block.id && toolCall.id) {
464
+ block.id = toolCall.id;
465
+ toolCallBlocksById.set(toolCall.id, block);
466
+ }
467
+ const name = toolCall.function?.name ?? toolCall.custom?.name;
468
+ if (!block.name && name) {
469
+ block.name = name;
470
+ }
471
+ let delta = "";
472
+ if (toolCall.function?.arguments) {
473
+ delta = toolCall.function.arguments;
474
+ block.partialArgs = (block.partialArgs ?? "") + toolCall.function.arguments;
475
+ block.arguments = parseStreamingJson(block.partialArgs);
476
+ } else if (toolCall.custom?.input) {
477
+ const nextInput = getCustomToolCallInput(block) + toolCall.custom.input;
478
+ delta = appendCustomToolCallInput(block, nextInput, false) ?? "";
479
+ }
480
+ stream2.push({
481
+ type: "toolcall_delta",
482
+ contentIndex: getContentIndex(block),
483
+ delta,
484
+ partial: output
485
+ });
486
+ }
487
+ }
488
+ }
489
+ }
490
+ for (const block of blocks) {
491
+ finishBlock(block);
492
+ }
493
+ if (options?.signal?.aborted) {
494
+ throw new Error("Request was aborted");
495
+ }
496
+ if (output.stopReason === "aborted") {
497
+ throw new Error("Request was aborted");
498
+ }
499
+ if (!hasFinishReason && !compat.supportsFinishReason) {
500
+ output.stopReason = output.content.some((block) => block.type === "toolCall") ? "toolUse" : "stop";
501
+ }
502
+ if (output.stopReason === "error") {
503
+ throw new Error(output.errorMessage || "Provider returned an error stop reason");
504
+ }
505
+ if (compat.supportsFinishReason && !hasFinishReason || output.stopReason === "pending") {
506
+ throw new Error("Stream ended without finish_reason");
507
+ }
508
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
509
+ stream2.end();
510
+ } catch (error) {
511
+ for (const block of output.content) {
512
+ if (block.type === "thinking") {
513
+ applyStreamedReasoningDetails(block);
514
+ }
515
+ delete block.index;
516
+ delete block.partialArgs;
517
+ delete block.customInput;
518
+ delete block.streamIndex;
519
+ }
520
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
521
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
522
+ const rawMetadata = error?.error?.metadata?.raw;
523
+ if (rawMetadata && !output.errorMessage.includes(String(rawMetadata))) {
524
+ output.errorMessage += `
525
+ ${rawMetadata}`;
526
+ }
527
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
528
+ stream2.end();
529
+ }
530
+ })();
531
+ return stream2;
532
+ }, "stream");
533
+ var streamSimple = /* @__PURE__ */ __name((model, context, options) => {
534
+ getClientApiKey(model.provider, options?.apiKey, options?.headers);
535
+ const base = {
536
+ ...buildBaseOptions(model, context, options, options?.apiKey),
537
+ toolChoice: options?.toolChoice
538
+ };
539
+ const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
540
+ const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
541
+ return stream(model, context, {
542
+ ...base,
543
+ reasoningEffort,
544
+ thinkingBudgets: options?.thinkingBudgets
545
+ });
546
+ }, "streamSimple");
547
+ function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId, compat = getCompat(model)) {
548
+ const headers = { "User-Agent": getPiUserAgent(), ...model.headers };
549
+ if (model.provider === "github-copilot") {
550
+ const hasImages = hasCopilotVisionInput(context.messages);
551
+ const copilotHeaders = buildCopilotDynamicHeaders({
552
+ messages: context.messages,
553
+ hasImages
554
+ });
555
+ Object.assign(headers, copilotHeaders);
556
+ }
557
+ if (sessionId && compat.sendSessionAffinityHeaders) {
558
+ if (compat.sessionAffinityFormat === "openrouter") {
559
+ headers["x-session-id"] = sessionId;
560
+ } else {
561
+ if (compat.sessionAffinityFormat === "openai") {
562
+ headers.session_id = sessionId;
563
+ }
564
+ headers["x-client-request-id"] = sessionId;
565
+ headers["x-session-affinity"] = sessionId;
566
+ }
567
+ }
568
+ if (optionsHeaders) {
569
+ Object.assign(headers, optionsHeaders);
570
+ }
571
+ return new OpenAI({
572
+ apiKey,
573
+ baseURL: model.baseUrl,
574
+ dangerouslyAllowBrowser: true,
575
+ fetch,
576
+ defaultHeaders: headers
577
+ });
578
+ }
579
+ __name(createClient, "createClient");
580
+ function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env), grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(context.messages), compat.supportsOpenAIGrammarTools)) {
581
+ const transcriptTools = resolveTranscriptTools(context.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true);
582
+ const messages = convertMessages(model, context, compat, {
583
+ grammarToolInputProperties
584
+ });
585
+ const cacheControl = getCompatCacheControl(compat, cacheRetention);
586
+ const params = {
587
+ model: model.id,
588
+ messages,
589
+ stream: true,
590
+ prompt_cache_key: model.baseUrl.includes("api.openai.com") && cacheRetention !== "none" || cacheRetention === "long" && compat.supportsLongCacheRetention ? clampOpenAIPromptCacheKey(options?.sessionId) : void 0,
591
+ prompt_cache_retention: cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
592
+ };
593
+ if (compat.supportsUsageInStreaming !== false) {
594
+ params.stream_options = { include_usage: true };
595
+ }
596
+ if (compat.supportsStore) {
597
+ params.store = false;
598
+ }
599
+ if (options?.maxTokens) {
600
+ if (compat.maxTokensField === "max_tokens") {
601
+ params.max_tokens = options.maxTokens;
602
+ } else {
603
+ params.max_completion_tokens = options.maxTokens;
604
+ }
605
+ }
606
+ if (options?.temperature !== void 0) {
607
+ params.temperature = options.temperature;
608
+ }
609
+ if (transcriptTools.requestTools.length > 0) {
610
+ params.tools = convertTools(transcriptTools.requestTools, compat);
611
+ if (compat.zaiToolStream) {
612
+ params.tool_stream = true;
613
+ }
614
+ } else if (hasToolHistory(context.messages)) {
615
+ params.tools = [];
616
+ }
617
+ if (cacheControl) {
618
+ applyAnthropicCacheControl(messages, params.tools, cacheControl);
619
+ }
620
+ if (options?.toolChoice) {
621
+ params.tool_choice = options.toolChoice;
622
+ }
623
+ if (compat.vllmPriority !== void 0) {
624
+ params.priority = compat.vllmPriority;
625
+ }
626
+ const thinkingTokenBudgetField = resolveThinkingTokenBudgetField(compat);
627
+ const thinkingBudget = resolveClampedThinkingBudget(model, options, params);
628
+ if (compat.thinkingFormat === "zai" && model.reasoning) {
629
+ const zaiParams = params;
630
+ zaiParams.thinking = options?.reasoningEffort ? { type: "enabled", clear_thinking: false } : { type: "disabled" };
631
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
632
+ const mappedEffort = model.thinkingLevelMap?.[options.reasoningEffort];
633
+ const effort = mappedEffort === void 0 ? options.reasoningEffort : mappedEffort;
634
+ if (typeof effort === "string") {
635
+ zaiParams.reasoning_effort = effort;
636
+ }
637
+ }
638
+ } else if (compat.thinkingFormat === "qwen" && model.reasoning) {
639
+ params.enable_thinking = !!options?.reasoningEffort;
640
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
641
+ const effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
642
+ if (typeof effort === "string") {
643
+ params.reasoning_effort = effort;
644
+ }
645
+ }
646
+ } else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) {
647
+ params.chat_template_kwargs = {
648
+ enable_thinking: !!options?.reasoningEffort,
649
+ preserve_thinking: true
650
+ };
651
+ } else if (compat.thinkingFormat === "chat-template" && model.reasoning) {
652
+ const chatTemplateKwargs = buildChatTemplateValues(model, options, compat.chatTemplateKwargs, thinkingBudget);
653
+ if (chatTemplateKwargs) {
654
+ params.chat_template_kwargs = chatTemplateKwargs;
655
+ }
656
+ } else if (compat.thinkingFormat === "baseten" && model.reasoning) {
657
+ const basetenParams = params;
658
+ const chatTemplateArgs = buildChatTemplateValues(model, options, compat.chatTemplateArgs, thinkingBudget);
659
+ if (chatTemplateArgs) {
660
+ basetenParams.chat_template_args = chatTemplateArgs;
661
+ }
662
+ if (compat.supportsReasoningEffort) {
663
+ const requestedEffort = options?.reasoningEffort;
664
+ const mappedEffort = requestedEffort ? model.thinkingLevelMap?.[requestedEffort] : model.thinkingLevelMap?.off;
665
+ const effort = mappedEffort === void 0 ? requestedEffort : mappedEffort;
666
+ if (typeof effort === "string") {
667
+ basetenParams.reasoning_effort = effort;
668
+ }
669
+ }
670
+ } else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
671
+ if (options?.reasoningEffort) {
672
+ params.thinking = { type: "enabled" };
673
+ } else if (model.thinkingLevelMap?.off !== null) {
674
+ params.thinking = { type: "disabled" };
675
+ }
676
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
677
+ params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
678
+ }
679
+ } else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
680
+ const openRouterParams = params;
681
+ if (options?.reasoningEffort) {
682
+ openRouterParams.reasoning = {
683
+ effort: model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort
684
+ };
685
+ } else if (model.thinkingLevelMap?.off !== null) {
686
+ openRouterParams.reasoning = { effort: model.thinkingLevelMap?.off ?? "none" };
687
+ }
688
+ } else if (compat.thinkingFormat === "ant-ling" && model.reasoning && options?.reasoningEffort) {
689
+ const effort = model.thinkingLevelMap?.[options.reasoningEffort];
690
+ if (typeof effort === "string") {
691
+ params.reasoning = { effort };
692
+ }
693
+ } else if (compat.thinkingFormat === "together" && model.reasoning) {
694
+ const togetherParams = params;
695
+ togetherParams.reasoning = { enabled: !!options?.reasoningEffort };
696
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
697
+ togetherParams.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
698
+ }
699
+ } else if (compat.thinkingFormat === "string-thinking" && model.reasoning) {
700
+ const stringThinkingParams = params;
701
+ if (options?.reasoningEffort) {
702
+ stringThinkingParams.thinking = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
703
+ } else if (model.thinkingLevelMap?.off !== null) {
704
+ stringThinkingParams.thinking = model.thinkingLevelMap?.off ?? "none";
705
+ }
706
+ } else if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
707
+ params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
708
+ } else if (!options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
709
+ const offValue = model.thinkingLevelMap?.off;
710
+ if (typeof offValue === "string") {
711
+ params.reasoning_effort = offValue;
712
+ }
713
+ }
714
+ if (thinkingTokenBudgetField && thinkingBudget !== void 0) {
715
+ Object.assign(params, { [thinkingTokenBudgetField]: thinkingBudget });
716
+ }
717
+ if (model.compat?.openRouterRouting) {
718
+ params.provider = model.compat.openRouterRouting;
719
+ }
720
+ if (model.compat?.vercelGatewayRouting) {
721
+ const routing = model.compat.vercelGatewayRouting;
722
+ if (routing.only || routing.order) {
723
+ const gatewayOptions = {};
724
+ if (routing.only)
725
+ gatewayOptions.only = routing.only;
726
+ if (routing.order)
727
+ gatewayOptions.order = routing.order;
728
+ params.providerOptions = { gateway: gatewayOptions };
729
+ }
730
+ }
731
+ const samplingParams = resolveSamplingParams(model, options?.reasoningEffort ?? "off", options?.samplingParams);
732
+ if (samplingParams) {
733
+ Object.assign(params, samplingParams);
734
+ }
735
+ return params;
736
+ }
737
+ __name(buildParams, "buildParams");
738
+ function resolveThinkingTokenBudgetField(compat) {
739
+ if (compat.thinkingTokenBudgetField)
740
+ return compat.thinkingTokenBudgetField;
741
+ if (compat.supportsThinkingTokenBudget)
742
+ return "thinking_token_budget";
743
+ return void 0;
744
+ }
745
+ __name(resolveThinkingTokenBudgetField, "resolveThinkingTokenBudgetField");
746
+ function resolveClampedThinkingBudget(model, options, params) {
747
+ if (!options?.reasoningEffort || !model.reasoning)
748
+ return void 0;
749
+ const ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;
750
+ const budget = clampThinkingBudgetToAnswerRoom(thinkingBudgetForLevel(options.reasoningEffort, options.thinkingBudgets), ceiling);
751
+ return budget > 0 ? budget : void 0;
752
+ }
753
+ __name(resolveClampedThinkingBudget, "resolveClampedThinkingBudget");
754
+ function buildChatTemplateValues(model, options, values, thinkingBudget) {
755
+ const resolvedValues = {};
756
+ for (const [key, value] of Object.entries(values)) {
757
+ const resolved = resolveChatTemplateKwargValue(model, options, value, thinkingBudget);
758
+ if (resolved !== void 0) {
759
+ resolvedValues[key] = resolved;
760
+ }
761
+ }
762
+ return Object.keys(resolvedValues).length > 0 ? resolvedValues : void 0;
763
+ }
764
+ __name(buildChatTemplateValues, "buildChatTemplateValues");
765
+ function resolveChatTemplateKwargValue(model, options, value, thinkingBudget) {
766
+ if (typeof value !== "object" || value === null) {
767
+ return value;
768
+ }
769
+ const reasoningEffort = options?.reasoningEffort;
770
+ if (!reasoningEffort && value.omitWhenOff) {
771
+ return void 0;
772
+ }
773
+ if (value.$var === "thinking.enabled") {
774
+ return !!reasoningEffort;
775
+ }
776
+ if (value.$var === "thinking.budget") {
777
+ return thinkingBudget;
778
+ }
779
+ const mappedValue = reasoningEffort ? model.thinkingLevelMap?.[reasoningEffort] : model.thinkingLevelMap?.off;
780
+ return mappedValue === void 0 ? reasoningEffort : typeof mappedValue === "string" ? mappedValue : void 0;
781
+ }
782
+ __name(resolveChatTemplateKwargValue, "resolveChatTemplateKwargValue");
783
+ function getCompatCacheControl(compat, cacheRetention) {
784
+ if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") {
785
+ return void 0;
786
+ }
787
+ const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : void 0;
788
+ return { type: "ephemeral", ...ttl ? { ttl } : {} };
789
+ }
790
+ __name(getCompatCacheControl, "getCompatCacheControl");
791
+ function applyAnthropicCacheControl(messages, tools, cacheControl) {
792
+ addCacheControlToSystemPrompt(messages, cacheControl);
793
+ addCacheControlToLastTool(tools, cacheControl);
794
+ addCacheControlToLastConversationMessage(messages, cacheControl);
795
+ }
796
+ __name(applyAnthropicCacheControl, "applyAnthropicCacheControl");
797
+ function addCacheControlToSystemPrompt(messages, cacheControl) {
798
+ for (const message of messages) {
799
+ if (message.role === "system" || message.role === "developer") {
800
+ addCacheControlToInstructionMessage(message, cacheControl);
801
+ return;
802
+ }
803
+ }
804
+ }
805
+ __name(addCacheControlToSystemPrompt, "addCacheControlToSystemPrompt");
806
+ function addCacheControlToLastConversationMessage(messages, cacheControl) {
807
+ for (let i = messages.length - 1; i >= 0; i--) {
808
+ const message = messages[i];
809
+ if (message.role === "user" || message.role === "assistant" || message.role === "tool") {
810
+ if (addCacheControlToMessage(message, cacheControl)) {
811
+ return;
812
+ }
813
+ }
814
+ }
815
+ }
816
+ __name(addCacheControlToLastConversationMessage, "addCacheControlToLastConversationMessage");
817
+ function addCacheControlToLastTool(tools, cacheControl) {
818
+ if (!tools || tools.length === 0) {
819
+ return;
820
+ }
821
+ const lastTool = tools[tools.length - 1];
822
+ lastTool.cache_control = cacheControl;
823
+ }
824
+ __name(addCacheControlToLastTool, "addCacheControlToLastTool");
825
+ function addCacheControlToInstructionMessage(message, cacheControl) {
826
+ return addCacheControlToTextContent(message, cacheControl);
827
+ }
828
+ __name(addCacheControlToInstructionMessage, "addCacheControlToInstructionMessage");
829
+ function addCacheControlToMessage(message, cacheControl) {
830
+ if (message.role === "user" || message.role === "assistant" || message.role === "tool") {
831
+ return addCacheControlToTextContent(message, cacheControl);
832
+ }
833
+ return false;
834
+ }
835
+ __name(addCacheControlToMessage, "addCacheControlToMessage");
836
+ function addCacheControlToTextContent(message, cacheControl) {
837
+ const content = message.content;
838
+ if (typeof content === "string") {
839
+ if (content.length === 0) {
840
+ return false;
841
+ }
842
+ message.content = [
843
+ {
844
+ type: "text",
845
+ text: content,
846
+ cache_control: cacheControl
847
+ }
848
+ ];
849
+ return true;
850
+ }
851
+ if (!Array.isArray(content)) {
852
+ return false;
853
+ }
854
+ for (let i = content.length - 1; i >= 0; i--) {
855
+ const part = content[i];
856
+ if (part?.type === "text") {
857
+ const textPart = part;
858
+ textPart.cache_control = cacheControl;
859
+ return true;
860
+ }
861
+ }
862
+ return false;
863
+ }
864
+ __name(addCacheControlToTextContent, "addCacheControlToTextContent");
865
+ function convertMessages(model, context, compat, options) {
866
+ const normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);
867
+ const params = [];
868
+ const normalizeToolCallId = /* @__PURE__ */ __name((id) => {
869
+ if (id.includes("|")) {
870
+ const separatorIndex = id.indexOf("|");
871
+ const callId = id.slice(0, separatorIndex).replace(/[^a-zA-Z0-9_-]/g, "_");
872
+ const itemId = id.slice(separatorIndex + 1).replace(/[^a-zA-Z0-9_-]/g, "_");
873
+ const combinedId = itemId.length > 0 ? `${callId}_${itemId}` : callId;
874
+ if (combinedId.length <= 40) {
875
+ return combinedId;
876
+ }
877
+ const hash = shortHash(id).slice(0, 8);
878
+ const prefix = callId.slice(0, Math.max(1, 40 - hash.length - 1));
879
+ return `${prefix}_${hash}`;
880
+ }
881
+ if (model.provider === "openai")
882
+ return id.length > 40 ? id.slice(0, 40) : id;
883
+ return id;
884
+ }, "normalizeToolCallId");
885
+ const transformedMessages = transformMessages(normalizedContext.messages, model, (id) => normalizeToolCallId(id));
886
+ const transcriptTools = resolveTranscriptTools(normalizedContext.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true);
887
+ const instructionRole = model.reasoning && compat.supportsDeveloperRole ? "developer" : "system";
888
+ let lastRole = null;
889
+ for (let i = 0; i < transformedMessages.length; i++) {
890
+ const msg = transformedMessages[i];
891
+ if (compat.requiresAssistantAfterToolResult && lastRole === "toolResult" && msg.role === "user") {
892
+ params.push({
893
+ role: "assistant",
894
+ content: "I have processed the tool results."
895
+ });
896
+ }
897
+ if (msg.role === "system") {
898
+ const addedTools = i > 0 && transcriptTools.anchorsAdditions ? msg.toolsAdded ?? [] : [];
899
+ if (addedTools.length > 0) {
900
+ const kimiToolMessage = {
901
+ role: "system",
902
+ tools: convertTools(addedTools, compat)
903
+ };
904
+ params.push(kimiToolMessage);
905
+ }
906
+ const text = i === 0 ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);
907
+ if (text.length > 0) {
908
+ params.push({ role: instructionRole, content: sanitizeSurrogates(text) });
909
+ }
910
+ } else if (msg.role === "user") {
911
+ if (typeof msg.content === "string") {
912
+ params.push({
913
+ role: "user",
914
+ content: sanitizeSurrogates(msg.content)
915
+ });
916
+ } else {
917
+ const content = msg.content.filter((item) => item.type !== "text" || item.text.length > 0).map((item) => {
918
+ if (item.type === "text") {
919
+ return {
920
+ type: "text",
921
+ text: sanitizeSurrogates(item.text)
922
+ };
923
+ } else {
924
+ return {
925
+ type: "image_url",
926
+ image_url: {
927
+ url: `data:${item.mimeType};base64,${item.data}`
928
+ }
929
+ };
930
+ }
931
+ });
932
+ if (content.length === 0)
933
+ continue;
934
+ params.push({
935
+ role: "user",
936
+ content
937
+ });
938
+ }
939
+ } else if (msg.role === "assistant") {
940
+ const assistantMsg = {
941
+ role: "assistant",
942
+ content: compat.requiresAssistantAfterToolResult ? "" : null
943
+ };
944
+ const assistantTextParts = msg.content.filter(isTextContentBlock).filter((block) => block.text.trim().length > 0).map((block) => ({
945
+ type: "text",
946
+ text: sanitizeSurrogates(block.text)
947
+ }));
948
+ const assistantText = assistantTextParts.map((part) => part.text).join("");
949
+ const thinkingBlocks = msg.content.filter(isThinkingContentBlock);
950
+ const toolCalls = msg.content.filter(isToolCallBlock);
951
+ const signedReasoningDetails = thinkingBlocks.map((block) => parseOpenAIReasoningDetails(block.thinkingSignature)).find((details) => details !== void 0);
952
+ const legacyReasoningDetails = toolCalls.map((toolCall) => parseLegacyEncryptedReasoningDetail(toolCall.thoughtSignature)).filter((detail) => detail !== void 0);
953
+ const preservedReasoningDetails = signedReasoningDetails ?? (legacyReasoningDetails.length > 0 ? legacyReasoningDetails : void 0);
954
+ const nonEmptyThinkingBlocks = thinkingBlocks.filter((block) => block.thinking.trim().length > 0);
955
+ if (nonEmptyThinkingBlocks.length > 0) {
956
+ if (compat.requiresThinkingAsText) {
957
+ const thinkingText = nonEmptyThinkingBlocks.map((block) => sanitizeSurrogates(block.thinking)).join("\n\n");
958
+ assistantMsg.content = [{ type: "text", text: thinkingText }, ...assistantTextParts];
959
+ } else {
960
+ if (assistantText.length > 0) {
961
+ assistantMsg.content = assistantText;
962
+ }
963
+ if (!preservedReasoningDetails) {
964
+ let signature = nonEmptyThinkingBlocks[0].thinkingSignature;
965
+ if (model.provider === "opencode-go" && signature === "reasoning") {
966
+ signature = "reasoning_content";
967
+ }
968
+ if (signature && isOpenAICompletionsReasoningField(signature)) {
969
+ assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
970
+ }
971
+ }
972
+ }
973
+ } else if (assistantText.length > 0) {
974
+ assistantMsg.content = assistantText;
975
+ }
976
+ if (toolCalls.length > 0) {
977
+ assistantMsg.tool_calls = toolCalls.map((tc) => {
978
+ const customInputProperty = options?.grammarToolInputProperties?.get(tc.name);
979
+ if (customInputProperty !== void 0) {
980
+ return {
981
+ id: tc.id,
982
+ type: "custom",
983
+ custom: {
984
+ name: tc.name,
985
+ input: sanitizeSurrogates(getGrammarToolInput(tc.name, tc.arguments, customInputProperty))
986
+ }
987
+ };
988
+ }
989
+ return {
990
+ id: tc.id,
991
+ type: "function",
992
+ function: {
993
+ name: tc.name,
994
+ arguments: JSON.stringify(tc.arguments)
995
+ }
996
+ };
997
+ });
998
+ }
999
+ if (preservedReasoningDetails) {
1000
+ assistantMsg.reasoning_details = preservedReasoningDetails;
1001
+ }
1002
+ if (compat.requiresReasoningContentOnAssistantMessages && model.reasoning && assistantMsg.reasoning_content === void 0) {
1003
+ assistantMsg.reasoning_content = "";
1004
+ }
1005
+ const content = assistantMsg.content;
1006
+ const hasContent = content !== null && content !== void 0 && (typeof content === "string" ? content.length > 0 : content.length > 0);
1007
+ if (!hasContent && !assistantMsg.tool_calls) {
1008
+ continue;
1009
+ }
1010
+ params.push(assistantMsg);
1011
+ } else if (msg.role === "toolResult") {
1012
+ const imageBlocks = [];
1013
+ let j = i;
1014
+ for (; j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
1015
+ const toolMsg = transformedMessages[j];
1016
+ const textResult = toolMsg.content.filter(isTextContentBlock).map((block) => block.text).join("\n");
1017
+ const hasImages = toolMsg.content.some((c) => c.type === "image");
1018
+ const hasText = textResult.length > 0;
1019
+ const toolResultText = hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)";
1020
+ const toolResultMsg = {
1021
+ role: "tool",
1022
+ content: sanitizeSurrogates(toolResultText),
1023
+ tool_call_id: toolMsg.toolCallId
1024
+ };
1025
+ if (compat.requiresToolResultName && toolMsg.toolName) {
1026
+ toolResultMsg.name = toolMsg.toolName;
1027
+ }
1028
+ params.push(toolResultMsg);
1029
+ if (hasImages && model.input.includes("image")) {
1030
+ for (const block of toolMsg.content) {
1031
+ if (isImageContentBlock(block)) {
1032
+ imageBlocks.push({
1033
+ type: "image_url",
1034
+ image_url: {
1035
+ url: `data:${block.mimeType};base64,${block.data}`
1036
+ }
1037
+ });
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ i = j - 1;
1043
+ if (imageBlocks.length > 0) {
1044
+ if (compat.requiresAssistantAfterToolResult) {
1045
+ params.push({
1046
+ role: "assistant",
1047
+ content: "I have processed the tool results."
1048
+ });
1049
+ }
1050
+ params.push({
1051
+ role: "user",
1052
+ content: [
1053
+ {
1054
+ type: "text",
1055
+ text: "Attached image(s) from tool result:"
1056
+ },
1057
+ ...imageBlocks
1058
+ ]
1059
+ });
1060
+ lastRole = "user";
1061
+ } else {
1062
+ lastRole = "toolResult";
1063
+ }
1064
+ continue;
1065
+ }
1066
+ lastRole = msg.role;
1067
+ }
1068
+ return params;
1069
+ }
1070
+ __name(convertMessages, "convertMessages");
1071
+ function convertTools(tools, compat) {
1072
+ return tools.map((tool) => {
1073
+ const grammar = resolveGrammarConstrainedSampling(tool, compat.supportsOpenAIGrammarTools);
1074
+ if (grammar) {
1075
+ return {
1076
+ type: "custom",
1077
+ custom: {
1078
+ name: tool.name,
1079
+ description: tool.description,
1080
+ format: {
1081
+ type: "grammar",
1082
+ grammar: {
1083
+ syntax: grammar.format,
1084
+ definition: grammar.definition
1085
+ }
1086
+ }
1087
+ }
1088
+ };
1089
+ }
1090
+ const strict = resolveJsonSchemaStrictSampling(tool, compat.supportsStrictMode !== false);
1091
+ return {
1092
+ type: "function",
1093
+ function: {
1094
+ name: tool.name,
1095
+ description: tool.description,
1096
+ parameters: getJsonSchemaToolParameters(tool, strict),
1097
+ // Only include strict if provider supports it. Some reject unknown fields.
1098
+ ...compat.supportsStrictMode !== false && { strict: strict ?? false }
1099
+ }
1100
+ };
1101
+ });
1102
+ }
1103
+ __name(convertTools, "convertTools");
1104
+ function parseChunkUsage(rawUsage, model) {
1105
+ const promptTokens = rawUsage.prompt_tokens || 0;
1106
+ const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? 0;
1107
+ const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
1108
+ const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
1109
+ const outputTokens = rawUsage.completion_tokens || 0;
1110
+ const usage = {
1111
+ input,
1112
+ output: outputTokens,
1113
+ cacheRead: cacheReadTokens,
1114
+ cacheWrite: cacheWriteTokens,
1115
+ reasoning: rawUsage.completion_tokens_details?.reasoning_tokens || 0,
1116
+ totalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,
1117
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
1118
+ };
1119
+ calculateCost(model, usage);
1120
+ return usage;
1121
+ }
1122
+ __name(parseChunkUsage, "parseChunkUsage");
1123
+ function mapStopReason(reason) {
1124
+ if (reason === null)
1125
+ return { stopReason: "stop" };
1126
+ switch (reason) {
1127
+ case "stop":
1128
+ case "end":
1129
+ return { stopReason: "stop" };
1130
+ case "length":
1131
+ return { stopReason: "length" };
1132
+ case "function_call":
1133
+ case "tool_calls":
1134
+ return { stopReason: "toolUse" };
1135
+ case "content_filter":
1136
+ return { stopReason: "error", errorMessage: "Provider finish_reason: content_filter" };
1137
+ case "network_error":
1138
+ return { stopReason: "error", errorMessage: "Provider finish_reason: network_error" };
1139
+ default:
1140
+ return {
1141
+ stopReason: "error",
1142
+ errorMessage: `Provider finish_reason: ${reason}`
1143
+ };
1144
+ }
1145
+ }
1146
+ __name(mapStopReason, "mapStopReason");
1147
+ function detectCompat(model) {
1148
+ const provider = model.provider;
1149
+ const baseUrl = model.baseUrl;
1150
+ const isZai = provider === "zai" || provider === "zai-coding-cn" || baseUrl.includes("api.z.ai") || baseUrl.includes("open.bigmodel.cn");
1151
+ const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
1152
+ const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
1153
+ const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
1154
+ const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
1155
+ const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
1156
+ const isNvidia = provider === "nvidia" || baseUrl.includes("integrate.api.nvidia.com");
1157
+ const isAntLing = provider === "ant-ling" || baseUrl.includes("api.ant-ling.com");
1158
+ const isCerebras = provider === "cerebras" || baseUrl.includes("cerebras.ai");
1159
+ const isDeepSeek = provider === "deepseek" || baseUrl.toLowerCase().includes("deepseek.com");
1160
+ const isNonStandard = isNvidia || isCerebras || provider === "xai" || baseUrl.includes("api.x.ai") || isTogether || baseUrl.includes("chutes.ai") || isDeepSeek || isZai || isMoonshot || provider === "opencode" || baseUrl.includes("opencode.ai") || isCloudflareWorkersAI || isCloudflareAiGateway || isAntLing;
1161
+ const useMaxTokens = baseUrl.includes("chutes.ai") || isDeepSeek || isMoonshot || isCloudflareAiGateway || isTogether || isNvidia || isAntLing || isZai;
1162
+ const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
1163
+ const isOpenRouterDeveloperRoleModel = isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
1164
+ const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : void 0;
1165
+ return {
1166
+ supportsStore: !isNonStandard,
1167
+ supportsDeveloperRole: isOpenRouterDeveloperRoleModel || !isNonStandard && !isOpenRouter,
1168
+ supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
1169
+ supportsUsageInStreaming: true,
1170
+ supportsFinishReason: true,
1171
+ maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
1172
+ requiresToolResultName: false,
1173
+ requiresAssistantAfterToolResult: false,
1174
+ requiresThinkingAsText: false,
1175
+ requiresReasoningContentOnAssistantMessages: isDeepSeek,
1176
+ thinkingFormat: isDeepSeek ? "deepseek" : isZai ? "zai" : isTogether ? "together" : isAntLing ? "ant-ling" : isOpenRouter ? "openrouter" : "openai",
1177
+ openRouterRouting: {},
1178
+ vercelGatewayRouting: {},
1179
+ chatTemplateKwargs: {},
1180
+ chatTemplateArgs: {},
1181
+ zaiToolStream: false,
1182
+ supportsThinkingTokenBudget: false,
1183
+ thinkingTokenBudgetField: void 0,
1184
+ // OpenAI compatibility alone does not imply strict JSON-schema tool support.
1185
+ supportsStrictMode: false,
1186
+ supportsOpenAIGrammarTools: false,
1187
+ supportsMidConvoSystemMessages: false,
1188
+ supportsMidConvoToolAdditions: false,
1189
+ cacheControlFormat,
1190
+ sendSessionAffinityHeaders: isOpenRouter,
1191
+ sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
1192
+ supportsLongCacheRetention: !(isTogether || isCloudflareWorkersAI || isCloudflareAiGateway || isNvidia || isAntLing)
1193
+ };
1194
+ }
1195
+ __name(detectCompat, "detectCompat");
1196
+ function getCompat(model) {
1197
+ const detected = detectCompat(model);
1198
+ if (!model.compat)
1199
+ return detected;
1200
+ return {
1201
+ supportsStore: model.compat.supportsStore ?? detected.supportsStore,
1202
+ supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
1203
+ supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
1204
+ supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
1205
+ supportsFinishReason: model.compat.supportsFinishReason ?? detected.supportsFinishReason,
1206
+ maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
1207
+ requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
1208
+ requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
1209
+ requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
1210
+ requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ?? detected.requiresReasoningContentOnAssistantMessages,
1211
+ thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
1212
+ openRouterRouting: model.compat.openRouterRouting ?? {},
1213
+ vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
1214
+ chatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,
1215
+ chatTemplateArgs: model.compat.chatTemplateArgs ?? detected.chatTemplateArgs,
1216
+ zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
1217
+ supportsThinkingTokenBudget: model.compat.supportsThinkingTokenBudget ?? detected.supportsThinkingTokenBudget,
1218
+ thinkingTokenBudgetField: model.compat.thinkingTokenBudgetField ?? detected.thinkingTokenBudgetField,
1219
+ supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
1220
+ supportsOpenAIGrammarTools: model.compat.supportsOpenAIGrammarTools ?? detected.supportsOpenAIGrammarTools,
1221
+ supportsMidConvoSystemMessages: model.compat.supportsMidConvoSystemMessages ?? detected.supportsMidConvoSystemMessages,
1222
+ supportsMidConvoToolAdditions: model.compat.supportsMidConvoToolAdditions ?? detected.supportsMidConvoToolAdditions,
1223
+ cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
1224
+ sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
1225
+ sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
1226
+ supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
1227
+ vllmPriority: model.compat.vllmPriority
1228
+ };
1229
+ }
1230
+ __name(getCompat, "getCompat");
1231
+ export {
1232
+ convertMessages,
1233
+ stream,
1234
+ streamSimple
1235
+ };