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,393 @@
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
+ GoogleGenAI,
4
+ convertMessages,
5
+ convertTools,
6
+ getDisabledGoogleThinkingConfig,
7
+ isThinkingPart,
8
+ mapStopReason,
9
+ resolveGoogleFunctionCallingMode,
10
+ resolveGoogleThinkingLevel,
11
+ retainThoughtSignature,
12
+ retryGoogleRequest,
13
+ supportsGoogleStrictToolSampling,
14
+ toGoogleSdkThinkingLevel,
15
+ toGoogleThinkingLevel,
16
+ usesGoogleThinkingLevel
17
+ } from "./c-DOSGVXDZ.mjs";
18
+ import {
19
+ formatProviderError,
20
+ normalizeProviderError
21
+ } from "./c-ZWUVHKMK.mjs";
22
+ import {
23
+ buildBaseOptions,
24
+ getPiUserAgent
25
+ } from "./c-C6S2YB53.mjs";
26
+ import {
27
+ sanitizeSurrogates
28
+ } from "./c-5GV3X3RB.mjs";
29
+ import "./c-EYZGSAJU.mjs";
30
+ import {
31
+ providerHeadersToRecord
32
+ } from "./c-ZJYLGIC3.mjs";
33
+ import "./c-CU4NGAUO.mjs";
34
+ import {
35
+ calculateCost,
36
+ clampThinkingLevel,
37
+ collapseSystemMessages,
38
+ getCurrentTools,
39
+ getInitialSystemMessage,
40
+ getSystemMessageText
41
+ } from "./c-WO3QSZUU.mjs";
42
+ import {
43
+ AssistantMessageEventStream
44
+ } from "./c-S2RVHR3M.mjs";
45
+ import {
46
+ __name
47
+ } from "./c-CN77DCGF.mjs";
48
+
49
+ // node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js
50
+ var toolCallCounter = 0;
51
+ var stream = /* @__PURE__ */ __name((model, context, options) => {
52
+ const stream2 = new AssistantMessageEventStream();
53
+ const normalizedContext = collapseSystemMessages(context);
54
+ (async () => {
55
+ const output = {
56
+ role: "assistant",
57
+ content: [],
58
+ api: "google-generative-ai",
59
+ provider: model.provider,
60
+ model: model.id,
61
+ usage: {
62
+ input: 0,
63
+ output: 0,
64
+ cacheRead: 0,
65
+ cacheWrite: 0,
66
+ totalTokens: 0,
67
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
68
+ },
69
+ stopReason: "pending",
70
+ timestamp: Date.now()
71
+ };
72
+ try {
73
+ if (options?.fetch && options.fetch !== globalThis.fetch) {
74
+ throw new Error("Custom fetch is not supported by the Google Generative AI adapter");
75
+ }
76
+ const apiKey = options?.apiKey;
77
+ if (!apiKey) {
78
+ throw new Error(`No API key for provider: ${model.provider}`);
79
+ }
80
+ const client = createClient(model, apiKey, options?.headers);
81
+ let params = buildParams(model, normalizedContext, options);
82
+ const nextParams = await options?.onPayload?.(params, model);
83
+ if (nextParams !== void 0) {
84
+ params = nextParams;
85
+ }
86
+ const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);
87
+ stream2.push({ type: "start", partial: output });
88
+ let currentBlock = null;
89
+ const blocks = output.content;
90
+ const blockIndex = /* @__PURE__ */ __name(() => blocks.length - 1, "blockIndex");
91
+ for await (const chunk of googleStream) {
92
+ await options?.onProviderStreamEvent?.(chunk, model);
93
+ output.responseId ||= chunk.responseId;
94
+ const candidate = chunk.candidates?.[0];
95
+ if (candidate?.content?.parts) {
96
+ for (const part of candidate.content.parts) {
97
+ if (part.text !== void 0) {
98
+ const isThinking = isThinkingPart(part);
99
+ if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
100
+ if (currentBlock) {
101
+ if (currentBlock.type === "text") {
102
+ stream2.push({
103
+ type: "text_end",
104
+ contentIndex: blocks.length - 1,
105
+ content: currentBlock.text,
106
+ partial: output
107
+ });
108
+ } else {
109
+ stream2.push({
110
+ type: "thinking_end",
111
+ contentIndex: blockIndex(),
112
+ content: currentBlock.thinking,
113
+ partial: output
114
+ });
115
+ }
116
+ }
117
+ if (isThinking) {
118
+ currentBlock = { type: "thinking", thinking: "", thinkingSignature: void 0 };
119
+ output.content.push(currentBlock);
120
+ stream2.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
121
+ } else {
122
+ currentBlock = { type: "text", text: "" };
123
+ output.content.push(currentBlock);
124
+ stream2.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
125
+ }
126
+ }
127
+ if (currentBlock.type === "thinking") {
128
+ currentBlock.thinking += part.text;
129
+ currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
130
+ stream2.push({
131
+ type: "thinking_delta",
132
+ contentIndex: blockIndex(),
133
+ delta: part.text,
134
+ partial: output
135
+ });
136
+ } else {
137
+ currentBlock.text += part.text;
138
+ currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
139
+ stream2.push({
140
+ type: "text_delta",
141
+ contentIndex: blockIndex(),
142
+ delta: part.text,
143
+ partial: output
144
+ });
145
+ }
146
+ }
147
+ if (part.functionCall) {
148
+ if (currentBlock) {
149
+ if (currentBlock.type === "text") {
150
+ stream2.push({
151
+ type: "text_end",
152
+ contentIndex: blockIndex(),
153
+ content: currentBlock.text,
154
+ partial: output
155
+ });
156
+ } else {
157
+ stream2.push({
158
+ type: "thinking_end",
159
+ contentIndex: blockIndex(),
160
+ content: currentBlock.thinking,
161
+ partial: output
162
+ });
163
+ }
164
+ currentBlock = null;
165
+ }
166
+ const providedId = part.functionCall.id;
167
+ const needsNewId = !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
168
+ const toolCallId = needsNewId ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId;
169
+ const toolCall = {
170
+ type: "toolCall",
171
+ id: toolCallId,
172
+ name: part.functionCall.name || "",
173
+ arguments: part.functionCall.args ?? {},
174
+ ...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
175
+ };
176
+ output.content.push(toolCall);
177
+ stream2.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
178
+ stream2.push({
179
+ type: "toolcall_delta",
180
+ contentIndex: blockIndex(),
181
+ delta: JSON.stringify(toolCall.arguments),
182
+ partial: output
183
+ });
184
+ stream2.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
185
+ }
186
+ }
187
+ }
188
+ if (candidate?.finishReason) {
189
+ output.rawStopReason = candidate.finishReason;
190
+ output.stopReason = mapStopReason(candidate.finishReason);
191
+ if (output.content.some((b) => b.type === "toolCall") && output.stopReason === "stop") {
192
+ output.stopReason = "toolUse";
193
+ }
194
+ }
195
+ if (chunk.usageMetadata) {
196
+ output.usage = {
197
+ input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
198
+ output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
199
+ cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
200
+ cacheWrite: 0,
201
+ reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,
202
+ totalTokens: chunk.usageMetadata.totalTokenCount || 0,
203
+ cost: {
204
+ input: 0,
205
+ output: 0,
206
+ cacheRead: 0,
207
+ cacheWrite: 0,
208
+ total: 0
209
+ }
210
+ };
211
+ calculateCost(model, output.usage);
212
+ }
213
+ }
214
+ if (currentBlock) {
215
+ if (currentBlock.type === "text") {
216
+ stream2.push({
217
+ type: "text_end",
218
+ contentIndex: blockIndex(),
219
+ content: currentBlock.text,
220
+ partial: output
221
+ });
222
+ } else {
223
+ stream2.push({
224
+ type: "thinking_end",
225
+ contentIndex: blockIndex(),
226
+ content: currentBlock.thinking,
227
+ partial: output
228
+ });
229
+ }
230
+ }
231
+ if (options?.signal?.aborted) {
232
+ throw new Error("Request was aborted");
233
+ }
234
+ if (output.stopReason === "pending") {
235
+ throw new Error("Google stream ended without a finish reason");
236
+ }
237
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
238
+ const errorMessage = output.rawStopReason ? `Provider stopped with: ${output.rawStopReason}` : "An unknown error occurred";
239
+ throw new Error(errorMessage);
240
+ }
241
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
242
+ stream2.end();
243
+ } catch (error) {
244
+ for (const block of output.content) {
245
+ if ("index" in block) {
246
+ delete block.index;
247
+ }
248
+ }
249
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
250
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
251
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
252
+ stream2.end();
253
+ }
254
+ })();
255
+ return stream2;
256
+ }, "stream");
257
+ var streamSimple = /* @__PURE__ */ __name((model, context, options) => {
258
+ const apiKey = options?.apiKey;
259
+ if (!apiKey) {
260
+ throw new Error(`No API key for provider: ${model.provider}`);
261
+ }
262
+ const base = {
263
+ ...buildBaseOptions(model, context, options, apiKey),
264
+ toolChoice: options?.toolChoice
265
+ };
266
+ if (!options?.reasoning) {
267
+ return stream(model, context, { ...base, thinking: { enabled: false } });
268
+ }
269
+ const clampedReasoning = clampThinkingLevel(model, options.reasoning);
270
+ if (clampedReasoning === "off") {
271
+ return stream(model, context, { ...base, thinking: { enabled: false } });
272
+ }
273
+ const resolvedLevel = resolveGoogleThinkingLevel(model, clampedReasoning);
274
+ if (usesGoogleThinkingLevel(model)) {
275
+ return stream(model, context, {
276
+ ...base,
277
+ thinking: {
278
+ enabled: true,
279
+ level: toGoogleThinkingLevel(resolvedLevel)
280
+ }
281
+ });
282
+ }
283
+ return stream(model, context, {
284
+ ...base,
285
+ thinking: {
286
+ enabled: true,
287
+ budgetTokens: getGoogleBudget(model, resolvedLevel, options.thinkingBudgets)
288
+ }
289
+ });
290
+ }, "streamSimple");
291
+ function createClient(model, apiKey, optionsHeaders) {
292
+ const httpOptions = {};
293
+ if (model.baseUrl) {
294
+ httpOptions.baseUrl = model.baseUrl;
295
+ httpOptions.apiVersion = "";
296
+ }
297
+ const headers = providerHeadersToRecord({ "User-Agent": getPiUserAgent(), ...model.headers, ...optionsHeaders });
298
+ if (headers) {
299
+ httpOptions.headers = headers;
300
+ }
301
+ return new GoogleGenAI({
302
+ apiKey,
303
+ httpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : void 0
304
+ });
305
+ }
306
+ __name(createClient, "createClient");
307
+ function buildParams(model, context, options = {}) {
308
+ const contents = convertMessages(model, context);
309
+ const initialSystemMessage = getInitialSystemMessage(context.messages);
310
+ const currentTools = getCurrentTools(context.messages);
311
+ const generationConfig = {};
312
+ if (options.temperature !== void 0) {
313
+ generationConfig.temperature = options.temperature;
314
+ }
315
+ if (options.maxTokens !== void 0) {
316
+ generationConfig.maxOutputTokens = options.maxTokens;
317
+ }
318
+ const supportsStrictMode = supportsGoogleStrictToolSampling(model.id);
319
+ const functionCallingMode = currentTools.length > 0 ? resolveGoogleFunctionCallingMode(currentTools, options.toolChoice, supportsStrictMode) : void 0;
320
+ const systemInstruction = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : "";
321
+ const config = {
322
+ ...Object.keys(generationConfig).length > 0 && generationConfig,
323
+ ...systemInstruction && { systemInstruction: sanitizeSurrogates(systemInstruction) },
324
+ ...currentTools.length > 0 && {
325
+ tools: convertTools(currentTools, false, supportsStrictMode)
326
+ },
327
+ ...functionCallingMode !== void 0 && {
328
+ toolConfig: { functionCallingConfig: { mode: functionCallingMode } }
329
+ }
330
+ };
331
+ if (options.thinking?.enabled && model.reasoning) {
332
+ const thinkingConfig = { includeThoughts: true };
333
+ if (options.thinking.level !== void 0) {
334
+ thinkingConfig.thinkingLevel = toGoogleSdkThinkingLevel(options.thinking.level);
335
+ } else if (options.thinking.budgetTokens !== void 0) {
336
+ thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
337
+ }
338
+ config.thinkingConfig = thinkingConfig;
339
+ } else if (model.reasoning && options.thinking && !options.thinking.enabled) {
340
+ config.thinkingConfig = getDisabledGoogleThinkingConfig(model);
341
+ }
342
+ if (options.signal) {
343
+ if (options.signal.aborted) {
344
+ throw new Error("Request aborted");
345
+ }
346
+ config.abortSignal = options.signal;
347
+ }
348
+ const params = {
349
+ model: model.id,
350
+ contents,
351
+ config
352
+ };
353
+ return params;
354
+ }
355
+ __name(buildParams, "buildParams");
356
+ function getGoogleBudget(model, level, customBudgets) {
357
+ if (customBudgets?.[level] !== void 0) {
358
+ return customBudgets[level];
359
+ }
360
+ if (model.id.includes("2.5-pro")) {
361
+ const budgets = {
362
+ minimal: 128,
363
+ low: 2048,
364
+ medium: 8192,
365
+ high: 32768
366
+ };
367
+ return budgets[level];
368
+ }
369
+ if (model.id.includes("2.5-flash-lite")) {
370
+ const budgets = {
371
+ minimal: 512,
372
+ low: 2048,
373
+ medium: 8192,
374
+ high: 24576
375
+ };
376
+ return budgets[level];
377
+ }
378
+ if (model.id.includes("2.5-flash")) {
379
+ const budgets = {
380
+ minimal: 128,
381
+ low: 2048,
382
+ medium: 8192,
383
+ high: 24576
384
+ };
385
+ return budgets[level];
386
+ }
387
+ return -1;
388
+ }
389
+ __name(getGoogleBudget, "getGoogleBudget");
390
+ export {
391
+ stream,
392
+ streamSimple
393
+ };
@@ -0,0 +1,162 @@
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
+ getProviderEnvValue
4
+ } from "./c-CDBEJSBF.mjs";
5
+ import {
6
+ __name
7
+ } from "./c-CN77DCGF.mjs";
8
+
9
+ // node_modules/@earendil-works/pi-ai/dist/env-api-keys.js
10
+ var __rewriteRelativeImportExtension = function(path, preserveJsx) {
11
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
12
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
13
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
14
+ });
15
+ }
16
+ return path;
17
+ };
18
+ var _existsSync = null;
19
+ var _homedir = null;
20
+ var _join = null;
21
+ var dynamicImport = /* @__PURE__ */ __name((specifier) => import(__rewriteRelativeImportExtension(specifier)), "dynamicImport");
22
+ var NODE_FS_SPECIFIER = "node:fs";
23
+ var NODE_OS_SPECIFIER = "node:os";
24
+ var NODE_PATH_SPECIFIER = "node:path";
25
+ if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
26
+ dynamicImport(NODE_FS_SPECIFIER).then((m) => {
27
+ _existsSync = m.existsSync;
28
+ });
29
+ dynamicImport(NODE_OS_SPECIFIER).then((m) => {
30
+ _homedir = m.homedir;
31
+ });
32
+ dynamicImport(NODE_PATH_SPECIFIER).then((m) => {
33
+ _join = m.join;
34
+ });
35
+ }
36
+ var ANTHROPIC_AUTH_TOKEN_ENV = "ANTHROPIC_AUTH_TOKEN";
37
+ var ANTHROPIC_OAUTH_TOKEN_ENV = "ANTHROPIC_OAUTH_TOKEN";
38
+ var ANTHROPIC_API_KEY_ENV = "ANTHROPIC_API_KEY";
39
+ var ANTHROPIC_FEDERATION_RULE_ID_ENV = "ANTHROPIC_FEDERATION_RULE_ID";
40
+ var ANTHROPIC_ORGANIZATION_ID_ENV = "ANTHROPIC_ORGANIZATION_ID";
41
+ var ANTHROPIC_SERVICE_ACCOUNT_ID_ENV = "ANTHROPIC_SERVICE_ACCOUNT_ID";
42
+ var ANTHROPIC_IDENTITY_TOKEN_FILE_ENV = "ANTHROPIC_IDENTITY_TOKEN_FILE";
43
+ var ANTHROPIC_WORKSPACE_ID_ENV = "ANTHROPIC_WORKSPACE_ID";
44
+ var cachedVertexAdcCredentialsExists = null;
45
+ function hasVertexAdcCredentials(env) {
46
+ const explicitCredentialsPath = env?.GOOGLE_APPLICATION_CREDENTIALS;
47
+ if (explicitCredentialsPath) {
48
+ return _existsSync ? _existsSync(explicitCredentialsPath) : false;
49
+ }
50
+ if (cachedVertexAdcCredentialsExists === null) {
51
+ if (!_existsSync || !_homedir || !_join) {
52
+ const isNode = typeof process !== "undefined" && (process.versions?.node || process.versions?.bun);
53
+ if (!isNode) {
54
+ cachedVertexAdcCredentialsExists = false;
55
+ }
56
+ return false;
57
+ }
58
+ const gacPath = getProviderEnvValue("GOOGLE_APPLICATION_CREDENTIALS", env);
59
+ if (gacPath) {
60
+ cachedVertexAdcCredentialsExists = _existsSync(gacPath);
61
+ } else {
62
+ cachedVertexAdcCredentialsExists = _existsSync(_join(_homedir(), ".config", "gcloud", "application_default_credentials.json"));
63
+ }
64
+ }
65
+ return cachedVertexAdcCredentialsExists;
66
+ }
67
+ __name(hasVertexAdcCredentials, "hasVertexAdcCredentials");
68
+ function getApiKeyEnvVars(provider) {
69
+ if (provider === "github-copilot") {
70
+ return ["COPILOT_GITHUB_TOKEN"];
71
+ }
72
+ if (provider === "anthropic") {
73
+ return [ANTHROPIC_AUTH_TOKEN_ENV, ANTHROPIC_OAUTH_TOKEN_ENV, ANTHROPIC_API_KEY_ENV];
74
+ }
75
+ const envMap = {
76
+ "ant-ling": "ANT_LING_API_KEY",
77
+ "qwen-token-plan": "QWEN_TOKEN_PLAN_API_KEY",
78
+ "qwen-token-plan-cn": "QWEN_TOKEN_PLAN_CN_API_KEY",
79
+ "qwen-token-plan-individual": "QWEN_TOKEN_PLAN_API_KEY",
80
+ openai: "OPENAI_API_KEY",
81
+ azure: "AZURE_OPENAI_API_KEY",
82
+ nvidia: "NVIDIA_API_KEY",
83
+ deepseek: "DEEPSEEK_API_KEY",
84
+ google: "GEMINI_API_KEY",
85
+ "google-vertex": "GOOGLE_CLOUD_API_KEY",
86
+ groq: "GROQ_API_KEY",
87
+ cerebras: "CEREBRAS_API_KEY",
88
+ xai: "XAI_API_KEY",
89
+ typesafe: "TYPESAFE_API_KEY",
90
+ radius: "RADIUS_API_KEY",
91
+ openrouter: "OPENROUTER_API_KEY",
92
+ "vercel-ai-gateway": "AI_GATEWAY_API_KEY",
93
+ zai: "ZAI_API_KEY",
94
+ "zai-coding-cn": "ZAI_CODING_CN_API_KEY",
95
+ mistral: "MISTRAL_API_KEY",
96
+ minimax: "MINIMAX_API_KEY",
97
+ "minimax-cn": "MINIMAX_CN_API_KEY",
98
+ moonshotai: "MOONSHOT_API_KEY",
99
+ "moonshotai-cn": "MOONSHOT_API_KEY",
100
+ huggingface: "HF_TOKEN",
101
+ fireworks: "FIREWORKS_API_KEY",
102
+ together: "TOGETHER_API_KEY",
103
+ baseten: "BASETEN_API_KEY",
104
+ opencode: "OPENCODE_API_KEY",
105
+ "opencode-go": "OPENCODE_API_KEY",
106
+ "kimi-coding": "KIMI_API_KEY",
107
+ meta: "META_API_KEY",
108
+ "cloudflare-workers-ai": "CLOUDFLARE_API_KEY",
109
+ "cloudflare-ai-gateway": "CLOUDFLARE_API_KEY",
110
+ xiaomi: "XIAOMI_API_KEY",
111
+ "xiaomi-token-plan-cn": "XIAOMI_TOKEN_PLAN_CN_API_KEY",
112
+ "xiaomi-token-plan-ams": "XIAOMI_TOKEN_PLAN_AMS_API_KEY",
113
+ "xiaomi-token-plan-sgp": "XIAOMI_TOKEN_PLAN_SGP_API_KEY"
114
+ };
115
+ const envVar = envMap[provider];
116
+ return envVar ? [envVar] : void 0;
117
+ }
118
+ __name(getApiKeyEnvVars, "getApiKeyEnvVars");
119
+ function findEnvKeys(provider, env) {
120
+ const envVars = getApiKeyEnvVars(provider);
121
+ if (!envVars)
122
+ return void 0;
123
+ const found = envVars.filter((envVar) => !!getProviderEnvValue(envVar, env));
124
+ return found.length > 0 ? found : void 0;
125
+ }
126
+ __name(findEnvKeys, "findEnvKeys");
127
+ function getEnvApiKey(provider, env) {
128
+ const envKeys = findEnvKeys(provider, env);
129
+ if (envKeys?.[0]) {
130
+ const apiKeyEnv = provider === "anthropic" ? envKeys.find((key) => key !== ANTHROPIC_AUTH_TOKEN_ENV) : envKeys[0];
131
+ if (apiKeyEnv)
132
+ return getProviderEnvValue(apiKeyEnv, env);
133
+ }
134
+ if (provider === "google-vertex") {
135
+ const hasCredentials = hasVertexAdcCredentials(env);
136
+ const hasProject = !!(getProviderEnvValue("GOOGLE_CLOUD_PROJECT", env) || getProviderEnvValue("GCLOUD_PROJECT", env));
137
+ const hasLocation = !!getProviderEnvValue("GOOGLE_CLOUD_LOCATION", env);
138
+ if (hasCredentials && hasProject && hasLocation) {
139
+ return "<authenticated>";
140
+ }
141
+ }
142
+ if (provider === "amazon-bedrock") {
143
+ if (getProviderEnvValue("AWS_PROFILE", env) || getProviderEnvValue("AWS_ACCESS_KEY_ID", env) && getProviderEnvValue("AWS_SECRET_ACCESS_KEY", env) || getProviderEnvValue("AWS_BEARER_TOKEN_BEDROCK", env) || getProviderEnvValue("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", env) || getProviderEnvValue("AWS_CONTAINER_CREDENTIALS_FULL_URI", env) || getProviderEnvValue("AWS_WEB_IDENTITY_TOKEN_FILE", env)) {
144
+ return "<authenticated>";
145
+ }
146
+ }
147
+ return void 0;
148
+ }
149
+ __name(getEnvApiKey, "getEnvApiKey");
150
+
151
+ export {
152
+ ANTHROPIC_AUTH_TOKEN_ENV,
153
+ ANTHROPIC_OAUTH_TOKEN_ENV,
154
+ ANTHROPIC_API_KEY_ENV,
155
+ ANTHROPIC_FEDERATION_RULE_ID_ENV,
156
+ ANTHROPIC_ORGANIZATION_ID_ENV,
157
+ ANTHROPIC_SERVICE_ACCOUNT_ID_ENV,
158
+ ANTHROPIC_IDENTITY_TOKEN_FILE_ENV,
159
+ ANTHROPIC_WORKSPACE_ID_ENV,
160
+ findEnvKeys,
161
+ getEnvApiKey
162
+ };