@code-yeongyu/senpi 2026.6.3 → 2026.6.6-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1075) hide show
  1. package/CHANGELOG.md +52 -4
  2. package/README.md +21 -4
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js +1 -1
  5. package/dist/bun/cli.js.map +1 -1
  6. package/dist/bun/register-bedrock.d.ts.map +1 -1
  7. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  8. package/dist/bun/restore-sandbox-env.js.map +1 -1
  9. package/dist/cli/args.d.ts +1 -0
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js +14 -2
  12. package/dist/cli/args.js.map +1 -1
  13. package/dist/cli/config-selector.d.ts.map +1 -1
  14. package/dist/cli/config-selector.js.map +1 -1
  15. package/dist/cli/file-processor.d.ts.map +1 -1
  16. package/dist/cli/file-processor.js.map +1 -1
  17. package/dist/cli/initial-message.d.ts +1 -1
  18. package/dist/cli/initial-message.d.ts.map +1 -1
  19. package/dist/cli/initial-message.js.map +1 -1
  20. package/dist/cli/list-models.d.ts.map +1 -1
  21. package/dist/cli/list-models.js.map +1 -1
  22. package/dist/cli/session-picker.d.ts.map +1 -1
  23. package/dist/cli/session-picker.js.map +1 -1
  24. package/dist/cli-main.d.ts +3 -0
  25. package/dist/cli-main.d.ts.map +1 -0
  26. package/dist/cli-main.js +10 -0
  27. package/dist/cli-main.js.map +1 -0
  28. package/dist/cli.d.ts.map +1 -1
  29. package/dist/cli.js +46 -13
  30. package/dist/cli.js.map +1 -1
  31. package/dist/config.d.ts.map +1 -1
  32. package/dist/config.js.map +1 -1
  33. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  34. package/dist/core/agent-session-runtime.js +0 -8
  35. package/dist/core/agent-session-runtime.js.map +1 -1
  36. package/dist/core/agent-session-services.d.ts.map +1 -1
  37. package/dist/core/agent-session-services.js.map +1 -1
  38. package/dist/core/agent-session.d.ts +32 -0
  39. package/dist/core/agent-session.d.ts.map +1 -1
  40. package/dist/core/agent-session.js +51 -79
  41. package/dist/core/agent-session.js.map +1 -1
  42. package/dist/core/auth-guidance.d.ts.map +1 -1
  43. package/dist/core/auth-guidance.js.map +1 -1
  44. package/dist/core/auth-storage.d.ts +4 -0
  45. package/dist/core/auth-storage.d.ts.map +1 -1
  46. package/dist/core/auth-storage.js +8 -11
  47. package/dist/core/auth-storage.js.map +1 -1
  48. package/dist/core/bash-executor.d.ts.map +1 -1
  49. package/dist/core/bash-executor.js.map +1 -1
  50. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  51. package/dist/core/compaction/branch-summarization.js.map +1 -1
  52. package/dist/core/compaction/compaction.d.ts.map +1 -1
  53. package/dist/core/compaction/compaction.js.map +1 -1
  54. package/dist/core/compaction/index.d.ts.map +1 -1
  55. package/dist/core/compaction/utils.d.ts.map +1 -1
  56. package/dist/core/compaction/utils.js.map +1 -1
  57. package/dist/core/defaults.d.ts.map +1 -1
  58. package/dist/core/diagnostics.d.ts.map +1 -1
  59. package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
  60. package/dist/core/dynamic-prompt/build.js.map +1 -1
  61. package/dist/core/dynamic-prompt/exploration.d.ts.map +1 -1
  62. package/dist/core/dynamic-prompt/exploration.js.map +1 -1
  63. package/dist/core/dynamic-prompt/identity.d.ts.map +1 -1
  64. package/dist/core/dynamic-prompt/identity.js.map +1 -1
  65. package/dist/core/dynamic-prompt/index.d.ts.map +1 -1
  66. package/dist/core/dynamic-prompt/intent-gate.d.ts.map +1 -1
  67. package/dist/core/dynamic-prompt/intent-gate.js.map +1 -1
  68. package/dist/core/dynamic-prompt/parallel-tools.d.ts.map +1 -1
  69. package/dist/core/dynamic-prompt/parallel-tools.js.map +1 -1
  70. package/dist/core/dynamic-prompt/policies.d.ts.map +1 -1
  71. package/dist/core/dynamic-prompt/policies.js.map +1 -1
  72. package/dist/core/dynamic-prompt/style.d.ts.map +1 -1
  73. package/dist/core/dynamic-prompt/style.js.map +1 -1
  74. package/dist/core/dynamic-prompt/tool-categorization.d.ts.map +1 -1
  75. package/dist/core/dynamic-prompt/tool-categorization.js.map +1 -1
  76. package/dist/core/dynamic-prompt/tool-section.d.ts.map +1 -1
  77. package/dist/core/dynamic-prompt/tool-section.js.map +1 -1
  78. package/dist/core/dynamic-prompt/types.d.ts.map +1 -1
  79. package/dist/core/dynamic-prompt/verification.d.ts.map +1 -1
  80. package/dist/core/dynamic-prompt/verification.js.map +1 -1
  81. package/dist/core/event-bus.d.ts.map +1 -1
  82. package/dist/core/event-bus.js.map +1 -1
  83. package/dist/core/exec.d.ts.map +1 -1
  84. package/dist/core/exec.js.map +1 -1
  85. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  86. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  87. package/dist/core/export-html/index.d.ts.map +1 -1
  88. package/dist/core/export-html/index.js.map +1 -1
  89. package/dist/core/export-html/template.js +19 -6
  90. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  91. package/dist/core/export-html/tool-renderer.js.map +1 -1
  92. package/dist/core/extensions/builtin/anthropic-bash/index.d.ts.map +1 -1
  93. package/dist/core/extensions/builtin/anthropic-bash/index.js.map +1 -1
  94. package/dist/core/extensions/builtin/anthropic-web-search/index.d.ts.map +1 -1
  95. package/dist/core/extensions/builtin/anthropic-web-search/index.js.map +1 -1
  96. package/dist/core/extensions/builtin/bash-timeout/index.d.ts.map +1 -1
  97. package/dist/core/extensions/builtin/bash-timeout/index.js.map +1 -1
  98. package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts.map +1 -1
  99. package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
  100. package/dist/core/extensions/builtin/compaction/checkpoint-state.d.ts.map +1 -1
  101. package/dist/core/extensions/builtin/compaction/checkpoint-state.js.map +1 -1
  102. package/dist/core/extensions/builtin/compaction/circuit-breaker.d.ts.map +1 -1
  103. package/dist/core/extensions/builtin/compaction/circuit-breaker.js.map +1 -1
  104. package/dist/core/extensions/builtin/compaction/context-reduction.d.ts.map +1 -1
  105. package/dist/core/extensions/builtin/compaction/context-reduction.js +1 -1
  106. package/dist/core/extensions/builtin/compaction/context-reduction.js.map +1 -1
  107. package/dist/core/extensions/builtin/compaction/degradation-monitor.d.ts.map +1 -1
  108. package/dist/core/extensions/builtin/compaction/degradation-monitor.js.map +1 -1
  109. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  110. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  111. package/dist/core/extensions/builtin/compaction/openai-remote.d.ts.map +1 -1
  112. package/dist/core/extensions/builtin/compaction/openai-remote.js.map +1 -1
  113. package/dist/core/extensions/builtin/compaction/overflow-detection.d.ts.map +1 -1
  114. package/dist/core/extensions/builtin/compaction/overflow-detection.js.map +1 -1
  115. package/dist/core/extensions/builtin/compaction/per-turn-cap.d.ts.map +1 -1
  116. package/dist/core/extensions/builtin/compaction/per-turn-cap.js.map +1 -1
  117. package/dist/core/extensions/builtin/compaction/policy.d.ts.map +1 -1
  118. package/dist/core/extensions/builtin/compaction/policy.js.map +1 -1
  119. package/dist/core/extensions/builtin/compaction/prompts.d.ts.map +1 -1
  120. package/dist/core/extensions/builtin/compaction/prompts.js.map +1 -1
  121. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.d.ts.map +1 -1
  122. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.js.map +1 -1
  123. package/dist/core/extensions/builtin/compaction/restoration-tracker.d.ts.map +1 -1
  124. package/dist/core/extensions/builtin/compaction/restoration-tracker.js.map +1 -1
  125. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  126. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  127. package/dist/core/extensions/builtin/compaction/state.d.ts.map +1 -1
  128. package/dist/core/extensions/builtin/compaction/state.js.map +1 -1
  129. package/dist/core/extensions/builtin/compaction/todo-bridge.d.ts.map +1 -1
  130. package/dist/core/extensions/builtin/compaction/todo-bridge.js.map +1 -1
  131. package/dist/core/extensions/builtin/compaction/tool-truncation.d.ts.map +1 -1
  132. package/dist/core/extensions/builtin/compaction/tool-truncation.js.map +1 -1
  133. package/dist/core/extensions/builtin/diff.d.ts.map +1 -1
  134. package/dist/core/extensions/builtin/diff.js.map +1 -1
  135. package/dist/core/extensions/builtin/files.d.ts.map +1 -1
  136. package/dist/core/extensions/builtin/files.js.map +1 -1
  137. package/dist/core/extensions/builtin/gpt-apply-patch/apply.d.ts.map +1 -1
  138. package/dist/core/extensions/builtin/gpt-apply-patch/apply.js.map +1 -1
  139. package/dist/core/extensions/builtin/gpt-apply-patch/constants.d.ts.map +1 -1
  140. package/dist/core/extensions/builtin/gpt-apply-patch/constants.js.map +1 -1
  141. package/dist/core/extensions/builtin/gpt-apply-patch/errors.d.ts.map +1 -1
  142. package/dist/core/extensions/builtin/gpt-apply-patch/errors.js +0 -2
  143. package/dist/core/extensions/builtin/gpt-apply-patch/errors.js.map +1 -1
  144. package/dist/core/extensions/builtin/gpt-apply-patch/extension.d.ts.map +1 -1
  145. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js.map +1 -1
  146. package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts.map +1 -1
  147. package/dist/core/extensions/builtin/gpt-apply-patch/params.d.ts.map +1 -1
  148. package/dist/core/extensions/builtin/gpt-apply-patch/params.js.map +1 -1
  149. package/dist/core/extensions/builtin/gpt-apply-patch/parser.d.ts.map +1 -1
  150. package/dist/core/extensions/builtin/gpt-apply-patch/parser.js.map +1 -1
  151. package/dist/core/extensions/builtin/gpt-apply-patch/patch-diff.d.ts.map +1 -1
  152. package/dist/core/extensions/builtin/gpt-apply-patch/patch-diff.js.map +1 -1
  153. package/dist/core/extensions/builtin/gpt-apply-patch/patch-replace.d.ts.map +1 -1
  154. package/dist/core/extensions/builtin/gpt-apply-patch/patch-replace.js.map +1 -1
  155. package/dist/core/extensions/builtin/gpt-apply-patch/preview-format.d.ts.map +1 -1
  156. package/dist/core/extensions/builtin/gpt-apply-patch/preview-format.js.map +1 -1
  157. package/dist/core/extensions/builtin/gpt-apply-patch/preview.d.ts.map +1 -1
  158. package/dist/core/extensions/builtin/gpt-apply-patch/preview.js.map +1 -1
  159. package/dist/core/extensions/builtin/gpt-apply-patch/seek-sequence.d.ts.map +1 -1
  160. package/dist/core/extensions/builtin/gpt-apply-patch/seek-sequence.js.map +1 -1
  161. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-parser.d.ts.map +1 -1
  162. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-parser.js +7 -5
  163. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-parser.js.map +1 -1
  164. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-render.d.ts.map +1 -1
  165. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-render.js.map +1 -1
  166. package/dist/core/extensions/builtin/gpt-apply-patch/text.d.ts.map +1 -1
  167. package/dist/core/extensions/builtin/gpt-apply-patch/text.js.map +1 -1
  168. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts.map +1 -1
  169. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js.map +1 -1
  170. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts.map +1 -1
  171. package/dist/core/extensions/builtin/gpt-apply-patch/workspace.d.ts.map +1 -1
  172. package/dist/core/extensions/builtin/gpt-apply-patch/workspace.js.map +1 -1
  173. package/dist/core/extensions/builtin/history-search/filter.d.ts.map +1 -1
  174. package/dist/core/extensions/builtin/history-search/filter.js.map +1 -1
  175. package/dist/core/extensions/builtin/history-search/index.d.ts.map +1 -1
  176. package/dist/core/extensions/builtin/history-search/index.js.map +1 -1
  177. package/dist/core/extensions/builtin/history-search/indexer.d.ts.map +1 -1
  178. package/dist/core/extensions/builtin/history-search/indexer.js.map +1 -1
  179. package/dist/core/extensions/builtin/history-search/overlay.d.ts.map +1 -1
  180. package/dist/core/extensions/builtin/history-search/overlay.js +3 -6
  181. package/dist/core/extensions/builtin/history-search/overlay.js.map +1 -1
  182. package/dist/core/extensions/builtin/history-search/types.d.ts.map +1 -1
  183. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  184. package/dist/core/extensions/builtin/kimi-web-search/index.d.ts.map +1 -1
  185. package/dist/core/extensions/builtin/kimi-web-search/index.js.map +1 -1
  186. package/dist/core/extensions/builtin/openai-web-search/index.d.ts.map +1 -1
  187. package/dist/core/extensions/builtin/openai-web-search/index.js.map +1 -1
  188. package/dist/core/extensions/builtin/permission-system/arity.d.ts.map +1 -1
  189. package/dist/core/extensions/builtin/permission-system/arity.js.map +1 -1
  190. package/dist/core/extensions/builtin/permission-system/cli.d.ts.map +1 -1
  191. package/dist/core/extensions/builtin/permission-system/cli.js.map +1 -1
  192. package/dist/core/extensions/builtin/permission-system/config.d.ts.map +1 -1
  193. package/dist/core/extensions/builtin/permission-system/config.js.map +1 -1
  194. package/dist/core/extensions/builtin/permission-system/evaluate.d.ts.map +1 -1
  195. package/dist/core/extensions/builtin/permission-system/evaluate.js.map +1 -1
  196. package/dist/core/extensions/builtin/permission-system/events.d.ts.map +1 -1
  197. package/dist/core/extensions/builtin/permission-system/events.js.map +1 -1
  198. package/dist/core/extensions/builtin/permission-system/external-dir.d.ts.map +1 -1
  199. package/dist/core/extensions/builtin/permission-system/external-dir.js.map +1 -1
  200. package/dist/core/extensions/builtin/permission-system/index.d.ts.map +1 -1
  201. package/dist/core/extensions/builtin/permission-system/index.js.map +1 -1
  202. package/dist/core/extensions/builtin/permission-system/non-interactive.d.ts.map +1 -1
  203. package/dist/core/extensions/builtin/permission-system/non-interactive.js.map +1 -1
  204. package/dist/core/extensions/builtin/permission-system/parsers.d.ts.map +1 -1
  205. package/dist/core/extensions/builtin/permission-system/parsers.js +3 -1
  206. package/dist/core/extensions/builtin/permission-system/parsers.js.map +1 -1
  207. package/dist/core/extensions/builtin/permission-system/prompt.d.ts.map +1 -1
  208. package/dist/core/extensions/builtin/permission-system/prompt.js.map +1 -1
  209. package/dist/core/extensions/builtin/permission-system/service.d.ts.map +1 -1
  210. package/dist/core/extensions/builtin/permission-system/service.js +2 -5
  211. package/dist/core/extensions/builtin/permission-system/service.js.map +1 -1
  212. package/dist/core/extensions/builtin/permission-system/settings.d.ts.map +1 -1
  213. package/dist/core/extensions/builtin/permission-system/settings.js.map +1 -1
  214. package/dist/core/extensions/builtin/permission-system/storage.d.ts.map +1 -1
  215. package/dist/core/extensions/builtin/permission-system/storage.js.map +1 -1
  216. package/dist/core/extensions/builtin/permission-system/types.d.ts.map +1 -1
  217. package/dist/core/extensions/builtin/permission-system/types.js +3 -5
  218. package/dist/core/extensions/builtin/permission-system/types.js.map +1 -1
  219. package/dist/core/extensions/builtin/permission-system/wildcard.d.ts.map +1 -1
  220. package/dist/core/extensions/builtin/permission-system/wildcard.js.map +1 -1
  221. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
  222. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
  223. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
  224. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
  225. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
  226. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
  227. package/dist/core/extensions/builtin/prompt-preset/file-operations.d.ts.map +1 -1
  228. package/dist/core/extensions/builtin/prompt-preset/file-operations.js.map +1 -1
  229. package/dist/core/extensions/builtin/prompt-preset/gpt-5.2.d.ts.map +1 -1
  230. package/dist/core/extensions/builtin/prompt-preset/gpt-5.2.js.map +1 -1
  231. package/dist/core/extensions/builtin/prompt-preset/gpt-5.3-codex.d.ts.map +1 -1
  232. package/dist/core/extensions/builtin/prompt-preset/gpt-5.3-codex.js.map +1 -1
  233. package/dist/core/extensions/builtin/prompt-preset/gpt-5.4.d.ts.map +1 -1
  234. package/dist/core/extensions/builtin/prompt-preset/gpt-5.4.js.map +1 -1
  235. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.d.ts.map +1 -1
  236. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js.map +1 -1
  237. package/dist/core/extensions/builtin/prompt-preset/gpt-5.d.ts.map +1 -1
  238. package/dist/core/extensions/builtin/prompt-preset/gpt-5.js.map +1 -1
  239. package/dist/core/extensions/builtin/prompt-preset/index.d.ts.map +1 -1
  240. package/dist/core/extensions/builtin/prompt-preset/index.js.map +1 -1
  241. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.d.ts.map +1 -1
  242. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js.map +1 -1
  243. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  244. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  245. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  246. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  247. package/dist/core/extensions/builtin/prompt-url-widget.d.ts.map +1 -1
  248. package/dist/core/extensions/builtin/prompt-url-widget.js.map +1 -1
  249. package/dist/core/extensions/builtin/redraws.d.ts.map +1 -1
  250. package/dist/core/extensions/builtin/redraws.js.map +1 -1
  251. package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
  252. package/dist/core/extensions/builtin/service-tier.js.map +1 -1
  253. package/dist/core/extensions/builtin/session-observer/index.d.ts.map +1 -1
  254. package/dist/core/extensions/builtin/session-observer/index.js.map +1 -1
  255. package/dist/core/extensions/builtin/session-observer/loader.d.ts.map +1 -1
  256. package/dist/core/extensions/builtin/session-observer/loader.js.map +1 -1
  257. package/dist/core/extensions/builtin/session-observer/overlay-format.d.ts.map +1 -1
  258. package/dist/core/extensions/builtin/session-observer/overlay-format.js.map +1 -1
  259. package/dist/core/extensions/builtin/session-observer/overlay.d.ts.map +1 -1
  260. package/dist/core/extensions/builtin/session-observer/overlay.js +13 -18
  261. package/dist/core/extensions/builtin/session-observer/overlay.js.map +1 -1
  262. package/dist/core/extensions/builtin/session-observer/scanner.d.ts.map +1 -1
  263. package/dist/core/extensions/builtin/session-observer/scanner.js.map +1 -1
  264. package/dist/core/extensions/builtin/session-observer/text.d.ts.map +1 -1
  265. package/dist/core/extensions/builtin/session-observer/text.js.map +1 -1
  266. package/dist/core/extensions/builtin/session-observer/transcript-entries.d.ts.map +1 -1
  267. package/dist/core/extensions/builtin/session-observer/transcript-entries.js.map +1 -1
  268. package/dist/core/extensions/builtin/session-observer/transcript-format.d.ts.map +1 -1
  269. package/dist/core/extensions/builtin/session-observer/transcript-format.js.map +1 -1
  270. package/dist/core/extensions/builtin/session-observer/transcript.d.ts.map +1 -1
  271. package/dist/core/extensions/builtin/session-observer/transcript.js.map +1 -1
  272. package/dist/core/extensions/builtin/session-observer/types.d.ts.map +1 -1
  273. package/dist/core/extensions/builtin/system-messages.d.ts.map +1 -1
  274. package/dist/core/extensions/builtin/system-messages.js.map +1 -1
  275. package/dist/core/extensions/builtin/todotools/continuation/config.d.ts +1 -1
  276. package/dist/core/extensions/builtin/todotools/continuation/config.d.ts.map +1 -1
  277. package/dist/core/extensions/builtin/todotools/continuation/config.js.map +1 -1
  278. package/dist/core/extensions/builtin/todotools/continuation/index.d.ts.map +1 -1
  279. package/dist/core/extensions/builtin/todotools/continuation/prompt.d.ts.map +1 -1
  280. package/dist/core/extensions/builtin/todotools/continuation/prompt.js.map +1 -1
  281. package/dist/core/extensions/builtin/todotools/continuation/runtime.d.ts.map +1 -1
  282. package/dist/core/extensions/builtin/todotools/continuation/runtime.js.map +1 -1
  283. package/dist/core/extensions/builtin/todotools/index.d.ts.map +1 -1
  284. package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
  285. package/dist/core/extensions/builtin/todotools/prompt.d.ts.map +1 -1
  286. package/dist/core/extensions/builtin/todotools/settings.d.ts.map +1 -1
  287. package/dist/core/extensions/builtin/todotools/settings.js.map +1 -1
  288. package/dist/core/extensions/builtin/todotools/state.d.ts.map +1 -1
  289. package/dist/core/extensions/builtin/todotools/state.js.map +1 -1
  290. package/dist/core/extensions/builtin/todotools/system-messages.d.ts.map +1 -1
  291. package/dist/core/extensions/builtin/todotools/system-messages.js.map +1 -1
  292. package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts.map +1 -1
  293. package/dist/core/extensions/builtin/todotools/tools/todoread.js.map +1 -1
  294. package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts.map +1 -1
  295. package/dist/core/extensions/builtin/todotools/tools/todowrite.js.map +1 -1
  296. package/dist/core/extensions/builtin/tool-pair-guard/index.d.ts.map +1 -1
  297. package/dist/core/extensions/builtin/tool-pair-guard/index.js.map +1 -1
  298. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.d.ts.map +1 -1
  299. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-anthropic-payload.js.map +1 -1
  300. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-openai-chat-completions-payload.d.ts.map +1 -1
  301. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-openai-chat-completions-payload.js.map +1 -1
  302. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-openai-responses-payload.d.ts.map +1 -1
  303. package/dist/core/extensions/builtin/tool-pair-guard/sanitize-openai-responses-payload.js.map +1 -1
  304. package/dist/core/extensions/builtin/tps.d.ts.map +1 -1
  305. package/dist/core/extensions/builtin/tps.js.map +1 -1
  306. package/dist/core/extensions/index.d.ts.map +1 -1
  307. package/dist/core/extensions/loader.d.ts.map +1 -1
  308. package/dist/core/extensions/loader.js.map +1 -1
  309. package/dist/core/extensions/runner.d.ts.map +1 -1
  310. package/dist/core/extensions/runner.js +35 -43
  311. package/dist/core/extensions/runner.js.map +1 -1
  312. package/dist/core/extensions/types.d.ts +1 -1
  313. package/dist/core/extensions/types.d.ts.map +1 -1
  314. package/dist/core/extensions/types.js.map +1 -1
  315. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  316. package/dist/core/extensions/wrapper.js.map +1 -1
  317. package/dist/core/footer-data-provider.d.ts.map +1 -1
  318. package/dist/core/footer-data-provider.js +17 -18
  319. package/dist/core/footer-data-provider.js.map +1 -1
  320. package/dist/core/http-dispatcher.d.ts.map +1 -1
  321. package/dist/core/http-dispatcher.js.map +1 -1
  322. package/dist/core/index.d.ts.map +1 -1
  323. package/dist/core/keybindings.d.ts +1 -1
  324. package/dist/core/keybindings.d.ts.map +1 -1
  325. package/dist/core/keybindings.js +0 -1
  326. package/dist/core/keybindings.js.map +1 -1
  327. package/dist/core/messages.d.ts.map +1 -1
  328. package/dist/core/messages.js.map +1 -1
  329. package/dist/core/model-registry.d.ts.map +1 -1
  330. package/dist/core/model-registry.js +8 -10
  331. package/dist/core/model-registry.js.map +1 -1
  332. package/dist/core/model-resolver.d.ts.map +1 -1
  333. package/dist/core/model-resolver.js +2 -0
  334. package/dist/core/model-resolver.js.map +1 -1
  335. package/dist/core/output-guard.d.ts.map +1 -1
  336. package/dist/core/output-guard.js.map +1 -1
  337. package/dist/core/package-manager.d.ts +3 -0
  338. package/dist/core/package-manager.d.ts.map +1 -1
  339. package/dist/core/package-manager.js +47 -19
  340. package/dist/core/package-manager.js.map +1 -1
  341. package/dist/core/prompt-templates.d.ts.map +1 -1
  342. package/dist/core/prompt-templates.js.map +1 -1
  343. package/dist/core/provider-attribution.d.ts.map +1 -1
  344. package/dist/core/provider-attribution.js.map +1 -1
  345. package/dist/core/provider-display-names.d.ts.map +1 -1
  346. package/dist/core/provider-display-names.js +2 -0
  347. package/dist/core/provider-display-names.js.map +1 -1
  348. package/dist/core/resolve-config-value.d.ts.map +1 -1
  349. package/dist/core/resolve-config-value.js.map +1 -1
  350. package/dist/core/resource-loader.d.ts +1 -0
  351. package/dist/core/resource-loader.d.ts.map +1 -1
  352. package/dist/core/resource-loader.js +26 -53
  353. package/dist/core/resource-loader.js.map +1 -1
  354. package/dist/core/sdk.d.ts.map +1 -1
  355. package/dist/core/sdk.js.map +1 -1
  356. package/dist/core/session-cwd.d.ts.map +1 -1
  357. package/dist/core/session-cwd.js +0 -1
  358. package/dist/core/session-cwd.js.map +1 -1
  359. package/dist/core/session-manager.d.ts.map +1 -1
  360. package/dist/core/session-manager.js +7 -11
  361. package/dist/core/session-manager.js.map +1 -1
  362. package/dist/core/session-work-barrier.d.ts.map +1 -1
  363. package/dist/core/session-work-barrier.js +5 -3
  364. package/dist/core/session-work-barrier.js.map +1 -1
  365. package/dist/core/settings-manager.d.ts +10 -2
  366. package/dist/core/settings-manager.d.ts.map +1 -1
  367. package/dist/core/settings-manager.js +77 -46
  368. package/dist/core/settings-manager.js.map +1 -1
  369. package/dist/core/skills.d.ts.map +1 -1
  370. package/dist/core/skills.js.map +1 -1
  371. package/dist/core/slash-commands.d.ts.map +1 -1
  372. package/dist/core/slash-commands.js +1 -0
  373. package/dist/core/slash-commands.js.map +1 -1
  374. package/dist/core/source-info.d.ts.map +1 -1
  375. package/dist/core/source-info.js.map +1 -1
  376. package/dist/core/system-prompt.d.ts.map +1 -1
  377. package/dist/core/system-prompt.js.map +1 -1
  378. package/dist/core/telemetry.d.ts.map +1 -1
  379. package/dist/core/telemetry.js.map +1 -1
  380. package/dist/core/thinking-levels.d.ts.map +1 -1
  381. package/dist/core/thinking-levels.js.map +1 -1
  382. package/dist/core/timings.d.ts.map +1 -1
  383. package/dist/core/timings.js.map +1 -1
  384. package/dist/core/tools/bash.d.ts.map +1 -1
  385. package/dist/core/tools/bash.js +9 -6
  386. package/dist/core/tools/bash.js.map +1 -1
  387. package/dist/core/tools/diff-render.d.ts.map +1 -1
  388. package/dist/core/tools/diff-render.js.map +1 -1
  389. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  390. package/dist/core/tools/edit-diff.js.map +1 -1
  391. package/dist/core/tools/edit.d.ts.map +1 -1
  392. package/dist/core/tools/edit.js.map +1 -1
  393. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  394. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  395. package/dist/core/tools/find.d.ts.map +1 -1
  396. package/dist/core/tools/find.js +1 -1
  397. package/dist/core/tools/find.js.map +1 -1
  398. package/dist/core/tools/grep.d.ts.map +1 -1
  399. package/dist/core/tools/grep.js +1 -1
  400. package/dist/core/tools/grep.js.map +1 -1
  401. package/dist/core/tools/index.d.ts.map +1 -1
  402. package/dist/core/tools/index.js.map +1 -1
  403. package/dist/core/tools/ls.d.ts.map +1 -1
  404. package/dist/core/tools/ls.js +1 -1
  405. package/dist/core/tools/ls.js.map +1 -1
  406. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  407. package/dist/core/tools/output-accumulator.js +12 -18
  408. package/dist/core/tools/output-accumulator.js.map +1 -1
  409. package/dist/core/tools/path-utils.d.ts.map +1 -1
  410. package/dist/core/tools/path-utils.js.map +1 -1
  411. package/dist/core/tools/read.d.ts.map +1 -1
  412. package/dist/core/tools/read.js +1 -1
  413. package/dist/core/tools/read.js.map +1 -1
  414. package/dist/core/tools/render-utils.d.ts.map +1 -1
  415. package/dist/core/tools/render-utils.js.map +1 -1
  416. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  417. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  418. package/dist/core/tools/truncate.d.ts.map +1 -1
  419. package/dist/core/tools/truncate.js.map +1 -1
  420. package/dist/core/tools/write.d.ts.map +1 -1
  421. package/dist/core/tools/write.js +1 -2
  422. package/dist/core/tools/write.js.map +1 -1
  423. package/dist/core/trust-manager.d.ts +9 -0
  424. package/dist/core/trust-manager.d.ts.map +1 -0
  425. package/dist/core/trust-manager.js +133 -0
  426. package/dist/core/trust-manager.js.map +1 -0
  427. package/dist/index.d.ts +2 -1
  428. package/dist/index.d.ts.map +1 -1
  429. package/dist/index.js +1 -0
  430. package/dist/index.js.map +1 -1
  431. package/dist/main.d.ts.map +1 -1
  432. package/dist/main.js +54 -2
  433. package/dist/main.js.map +1 -1
  434. package/dist/migrations.d.ts.map +1 -1
  435. package/dist/migrations.js.map +1 -1
  436. package/dist/modes/index.d.ts.map +1 -1
  437. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/armin.js +6 -10
  439. package/dist/modes/interactive/components/armin.js.map +1 -1
  440. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  441. package/dist/modes/interactive/components/assistant-message.js +2 -11
  442. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  443. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  444. package/dist/modes/interactive/components/bash-execution.js +6 -11
  445. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  446. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  447. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  448. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  449. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  450. package/dist/modes/interactive/components/branch-summary-message.js +1 -3
  451. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  452. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  453. package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
  454. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  455. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  456. package/dist/modes/interactive/components/config-selector.js +5 -15
  457. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  458. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  460. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  461. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  462. package/dist/modes/interactive/components/custom-editor.js +1 -8
  463. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  464. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  465. package/dist/modes/interactive/components/custom-message.js +1 -6
  466. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  467. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  468. package/dist/modes/interactive/components/daxnuts.js +6 -8
  469. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  470. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  471. package/dist/modes/interactive/components/diff.js +2 -2
  472. package/dist/modes/interactive/components/diff.js.map +1 -1
  473. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  474. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  475. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  476. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  477. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  478. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  479. package/dist/modes/interactive/components/extension-editor.js +1 -6
  480. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  481. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  482. package/dist/modes/interactive/components/extension-input.js +2 -8
  483. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  484. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  485. package/dist/modes/interactive/components/extension-selector.js +1 -9
  486. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  487. package/dist/modes/interactive/components/favorite-models-selector.d.ts.map +1 -1
  488. package/dist/modes/interactive/components/favorite-models-selector.js +9 -15
  489. package/dist/modes/interactive/components/favorite-models-selector.js.map +1 -1
  490. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  491. package/dist/modes/interactive/components/footer.js +10 -3
  492. package/dist/modes/interactive/components/footer.js.map +1 -1
  493. package/dist/modes/interactive/components/index.d.ts +1 -0
  494. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  495. package/dist/modes/interactive/components/index.js +1 -0
  496. package/dist/modes/interactive/components/index.js.map +1 -1
  497. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  498. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  499. package/dist/modes/interactive/components/login-dialog.d.ts +0 -1
  500. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  501. package/dist/modes/interactive/components/login-dialog.js +6 -21
  502. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  503. package/dist/modes/interactive/components/model-favorites.d.ts.map +1 -1
  504. package/dist/modes/interactive/components/model-favorites.js.map +1 -1
  505. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  506. package/dist/modes/interactive/components/model-selector.js +9 -22
  507. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  508. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  509. package/dist/modes/interactive/components/oauth-selector.js +3 -12
  510. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  511. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  512. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  513. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  514. package/dist/modes/interactive/components/session-selector.js +33 -58
  515. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  516. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  517. package/dist/modes/interactive/components/settings-selector.js +0 -4
  518. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  519. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  520. package/dist/modes/interactive/components/show-images-selector.js +0 -1
  521. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  522. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  523. package/dist/modes/interactive/components/skill-invocation-message.js +1 -3
  524. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  525. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  526. package/dist/modes/interactive/components/theme-selector.js +0 -2
  527. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  528. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  529. package/dist/modes/interactive/components/thinking-selector.js +0 -1
  530. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  531. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  532. package/dist/modes/interactive/components/tool-execution.js +9 -28
  533. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  534. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  535. package/dist/modes/interactive/components/tree-selector.js +18 -32
  536. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  537. package/dist/modes/interactive/components/trust-selector.d.ts +20 -0
  538. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -0
  539. package/dist/modes/interactive/components/trust-selector.js +81 -0
  540. package/dist/modes/interactive/components/trust-selector.js.map +1 -0
  541. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  542. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  543. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  544. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  545. package/dist/modes/interactive/components/user-message.js +0 -1
  546. package/dist/modes/interactive/components/user-message.js.map +1 -1
  547. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  548. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  549. package/dist/modes/interactive/interactive-mode.d.ts +24 -0
  550. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  551. package/dist/modes/interactive/interactive-mode.js +112 -101
  552. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  553. package/dist/modes/interactive/session-info-format.d.ts.map +1 -1
  554. package/dist/modes/interactive/session-info-format.js.map +1 -1
  555. package/dist/modes/interactive/startup-tools.d.ts.map +1 -1
  556. package/dist/modes/interactive/startup-tools.js.map +1 -1
  557. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  558. package/dist/modes/interactive/theme/theme.js +0 -6
  559. package/dist/modes/interactive/theme/theme.js.map +1 -1
  560. package/dist/modes/interactive/working-status.d.ts.map +1 -1
  561. package/dist/modes/interactive/working-status.js.map +1 -1
  562. package/dist/modes/print-mode.d.ts.map +1 -1
  563. package/dist/modes/print-mode.js.map +1 -1
  564. package/dist/modes/provider-native-rendering.d.ts.map +1 -1
  565. package/dist/modes/provider-native-rendering.js.map +1 -1
  566. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  567. package/dist/modes/rpc/jsonl.js.map +1 -1
  568. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  569. package/dist/modes/rpc/rpc-client.js +7 -8
  570. package/dist/modes/rpc/rpc-client.js.map +1 -1
  571. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  572. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  573. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  574. package/dist/package-manager-cli.d.ts.map +1 -1
  575. package/dist/package-manager-cli.js +56 -9
  576. package/dist/package-manager-cli.js.map +1 -1
  577. package/dist/self-update-bootstrap.d.ts +19 -0
  578. package/dist/self-update-bootstrap.d.ts.map +1 -0
  579. package/dist/self-update-bootstrap.js +160 -0
  580. package/dist/self-update-bootstrap.js.map +1 -0
  581. package/dist/senpi +46 -13
  582. package/dist/utils/ansi.d.ts.map +1 -1
  583. package/dist/utils/ansi.js.map +1 -1
  584. package/dist/utils/changelog.d.ts.map +1 -1
  585. package/dist/utils/changelog.js.map +1 -1
  586. package/dist/utils/child-process.d.ts.map +1 -1
  587. package/dist/utils/child-process.js.map +1 -1
  588. package/dist/utils/clipboard-image.d.ts.map +1 -1
  589. package/dist/utils/clipboard-image.js.map +1 -1
  590. package/dist/utils/clipboard-native.d.ts.map +1 -1
  591. package/dist/utils/clipboard-native.js.map +1 -1
  592. package/dist/utils/clipboard.d.ts.map +1 -1
  593. package/dist/utils/clipboard.js.map +1 -1
  594. package/dist/utils/deprecation.d.ts.map +1 -1
  595. package/dist/utils/deprecation.js.map +1 -1
  596. package/dist/utils/exif-orientation.d.ts.map +1 -1
  597. package/dist/utils/exif-orientation.js.map +1 -1
  598. package/dist/utils/frontmatter.d.ts.map +1 -1
  599. package/dist/utils/frontmatter.js.map +1 -1
  600. package/dist/utils/fs-watch.d.ts.map +1 -1
  601. package/dist/utils/fs-watch.js.map +1 -1
  602. package/dist/utils/git.d.ts.map +1 -1
  603. package/dist/utils/git.js +54 -22
  604. package/dist/utils/git.js.map +1 -1
  605. package/dist/utils/html.d.ts.map +1 -1
  606. package/dist/utils/html.js.map +1 -1
  607. package/dist/utils/image-convert.d.ts.map +1 -1
  608. package/dist/utils/image-convert.js.map +1 -1
  609. package/dist/utils/image-resize-core.d.ts.map +1 -1
  610. package/dist/utils/image-resize-core.js.map +1 -1
  611. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  612. package/dist/utils/image-resize-worker.js.map +1 -1
  613. package/dist/utils/image-resize.d.ts.map +1 -1
  614. package/dist/utils/image-resize.js.map +1 -1
  615. package/dist/utils/json.d.ts.map +1 -1
  616. package/dist/utils/json.js.map +1 -1
  617. package/dist/utils/mime.d.ts.map +1 -1
  618. package/dist/utils/mime.js.map +1 -1
  619. package/dist/utils/open-browser.d.ts +9 -0
  620. package/dist/utils/open-browser.d.ts.map +1 -0
  621. package/dist/utils/open-browser.js +22 -0
  622. package/dist/utils/open-browser.js.map +1 -0
  623. package/dist/utils/paths.d.ts.map +1 -1
  624. package/dist/utils/paths.js.map +1 -1
  625. package/dist/utils/photon.d.ts.map +1 -1
  626. package/dist/utils/photon.js.map +1 -1
  627. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  628. package/dist/utils/pi-user-agent.js.map +1 -1
  629. package/dist/utils/shell.d.ts.map +1 -1
  630. package/dist/utils/shell.js.map +1 -1
  631. package/dist/utils/sleep.d.ts.map +1 -1
  632. package/dist/utils/sleep.js.map +1 -1
  633. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  634. package/dist/utils/syntax-highlight.js.map +1 -1
  635. package/dist/utils/tools-manager.d.ts.map +1 -1
  636. package/dist/utils/tools-manager.js.map +1 -1
  637. package/dist/utils/version-check.d.ts.map +1 -1
  638. package/dist/utils/version-check.js.map +1 -1
  639. package/dist/utils/windows-self-update.d.ts.map +1 -1
  640. package/dist/utils/windows-self-update.js.map +1 -1
  641. package/docs/containerization.md +111 -0
  642. package/docs/docs.json +4 -0
  643. package/docs/extensions.md +3 -1
  644. package/docs/index.md +1 -0
  645. package/docs/packages.md +3 -1
  646. package/docs/prompt-templates.md +1 -1
  647. package/docs/providers.md +3 -0
  648. package/docs/settings.md +10 -0
  649. package/docs/skills.md +3 -3
  650. package/docs/themes.md +1 -1
  651. package/docs/usage.md +15 -3
  652. package/examples/extensions/README.md +1 -0
  653. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  654. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  655. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  656. package/examples/extensions/gondolin/index.ts +531 -0
  657. package/examples/extensions/gondolin/package-lock.json +185 -0
  658. package/examples/extensions/gondolin/package.json +19 -0
  659. package/examples/extensions/minimal-mode.ts +6 -6
  660. package/examples/extensions/sandbox/package-lock.json +2 -2
  661. package/examples/extensions/sandbox/package.json +1 -1
  662. package/examples/extensions/with-deps/package-lock.json +2 -2
  663. package/examples/extensions/with-deps/package.json +1 -1
  664. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  665. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  666. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +7 -0
  667. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  668. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +2 -27
  669. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  670. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
  671. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +7 -20
  672. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
  673. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  674. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js.map +1 -1
  675. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts.map +1 -1
  676. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js.map +1 -1
  677. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts.map +1 -1
  678. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js.map +1 -1
  679. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -1
  680. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +0 -3
  681. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js.map +1 -1
  682. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts.map +1 -1
  683. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js.map +1 -1
  684. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts.map +1 -1
  685. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js.map +1 -1
  686. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts.map +1 -1
  687. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +0 -3
  688. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js.map +1 -1
  689. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts.map +1 -1
  690. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +0 -7
  691. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js.map +1 -1
  692. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts.map +1 -1
  693. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +3 -1
  694. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js.map +1 -1
  695. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts.map +1 -1
  696. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +0 -5
  697. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js.map +1 -1
  698. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts.map +1 -1
  699. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js.map +1 -1
  700. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts.map +1 -1
  701. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +0 -1
  702. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js.map +1 -1
  703. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.d.ts.map +1 -1
  704. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.js.map +1 -1
  705. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts.map +1 -1
  706. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js.map +1 -1
  707. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts.map +1 -1
  708. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js.map +1 -1
  709. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts.map +1 -1
  710. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +0 -16
  711. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js.map +1 -1
  712. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts.map +1 -1
  713. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js.map +1 -1
  714. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.d.ts.map +1 -1
  715. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js.map +1 -1
  716. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  717. package/node_modules/@earendil-works/pi-agent-core/dist/node.d.ts.map +1 -1
  718. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts.map +1 -1
  719. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js.map +1 -1
  720. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
  721. package/node_modules/@earendil-works/pi-agent-core/package.json +6 -6
  722. package/node_modules/@earendil-works/pi-ai/README.md +5 -1
  723. package/node_modules/@earendil-works/pi-ai/dist/api-registry.d.ts.map +1 -1
  724. package/node_modules/@earendil-works/pi-ai/dist/api-registry.js.map +1 -1
  725. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.d.ts.map +1 -1
  726. package/node_modules/@earendil-works/pi-ai/dist/cli.d.ts.map +1 -1
  727. package/node_modules/@earendil-works/pi-ai/dist/cli.js.map +1 -1
  728. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
  729. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +2 -0
  730. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
  731. package/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts.map +1 -1
  732. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +30 -0
  733. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  734. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +30 -0
  735. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  736. package/node_modules/@earendil-works/pi-ai/dist/image-models.js.map +1 -1
  737. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts.map +1 -1
  738. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js.map +1 -1
  739. package/node_modules/@earendil-works/pi-ai/dist/images.d.ts.map +1 -1
  740. package/node_modules/@earendil-works/pi-ai/dist/images.js.map +1 -1
  741. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  742. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
  743. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +413 -65
  744. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  745. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +385 -97
  746. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js.map +1 -1
  747. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
  748. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts.map +1 -1
  749. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -1
  750. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
  751. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  752. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js.map +1 -1
  753. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
  754. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
  755. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.d.ts.map +1 -1
  756. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.js.map +1 -1
  757. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
  758. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
  759. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.d.ts.map +1 -1
  760. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.js.map +1 -1
  761. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.d.ts.map +1 -1
  762. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.js.map +1 -1
  763. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts.map +1 -1
  764. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js.map +1 -1
  765. package/node_modules/@earendil-works/pi-ai/dist/providers/google.d.ts.map +1 -1
  766. package/node_modules/@earendil-works/pi-ai/dist/providers/google.js.map +1 -1
  767. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.d.ts.map +1 -1
  768. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js.map +1 -1
  769. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts.map +1 -1
  770. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js.map +1 -1
  771. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.d.ts.map +1 -1
  772. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.js +3 -3
  773. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.js.map +1 -1
  774. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  775. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +0 -7
  776. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  777. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  778. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +26 -9
  779. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js.map +1 -1
  780. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.d.ts.map +1 -1
  781. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.js.map +1 -1
  782. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.d.ts.map +1 -1
  783. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.js.map +1 -1
  784. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
  785. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js.map +1 -1
  786. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.d.ts.map +1 -1
  787. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.js.map +1 -1
  788. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  789. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.js.map +1 -1
  790. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.d.ts.map +1 -1
  791. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.js.map +1 -1
  792. package/node_modules/@earendil-works/pi-ai/dist/session-resources.d.ts.map +1 -1
  793. package/node_modules/@earendil-works/pi-ai/dist/session-resources.js.map +1 -1
  794. package/node_modules/@earendil-works/pi-ai/dist/stream.d.ts.map +1 -1
  795. package/node_modules/@earendil-works/pi-ai/dist/stream.js.map +1 -1
  796. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
  797. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
  798. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  799. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  800. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.d.ts.map +1 -1
  801. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js +10 -8
  802. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js.map +1 -1
  803. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.d.ts.map +1 -1
  804. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.js.map +1 -1
  805. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.d.ts.map +1 -1
  806. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.js.map +1 -1
  807. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.d.ts.map +1 -1
  808. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.js.map +1 -1
  809. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.d.ts.map +1 -1
  810. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.js.map +1 -1
  811. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.d.ts.map +1 -1
  812. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.js.map +1 -1
  813. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.d.ts.map +1 -1
  814. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.js.map +1 -1
  815. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
  816. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -4
  817. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  818. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  819. package/node_modules/@earendil-works/pi-ai/dist/utils/abort-signals.d.ts.map +1 -1
  820. package/node_modules/@earendil-works/pi-ai/dist/utils/abort-signals.js.map +1 -1
  821. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.d.ts.map +1 -1
  822. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.js.map +1 -1
  823. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts.map +1 -1
  824. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +3 -7
  825. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js.map +1 -1
  826. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.d.ts.map +1 -1
  827. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.js.map +1 -1
  828. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.d.ts.map +1 -1
  829. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js.map +1 -1
  830. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.d.ts.map +1 -1
  831. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js.map +1 -1
  832. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.d.ts.map +1 -1
  833. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.js.map +1 -1
  834. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts.map +1 -1
  835. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
  836. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts.map +1 -1
  837. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js.map +1 -1
  838. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -1
  839. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +13 -1
  840. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -1
  841. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts.map +1 -1
  842. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js.map +1 -1
  843. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.d.ts.map +1 -1
  844. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.js.map +1 -1
  845. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts.map +1 -1
  846. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js +4 -2
  847. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js.map +1 -1
  848. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.d.ts.map +1 -1
  849. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.js.map +1 -1
  850. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts.map +1 -1
  851. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  852. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  853. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.d.ts.map +1 -1
  854. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.js.map +1 -1
  855. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.d.ts.map +1 -1
  856. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.js.map +1 -1
  857. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.d.ts.map +1 -1
  858. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.js.map +1 -1
  859. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts.map +1 -1
  860. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js.map +1 -1
  861. package/node_modules/@earendil-works/pi-ai/package.json +5 -5
  862. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +1 -1
  863. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
  864. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +0 -3
  865. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
  866. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts.map +1 -1
  867. package/node_modules/@earendil-works/pi-tui/dist/components/box.js +1 -6
  868. package/node_modules/@earendil-works/pi-tui/dist/components/box.js.map +1 -1
  869. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts.map +1 -1
  870. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js +4 -3
  871. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js.map +1 -1
  872. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -1
  873. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +43 -54
  874. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -1
  875. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +1 -1
  876. package/node_modules/@earendil-works/pi-tui/dist/components/image.js +0 -8
  877. package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +1 -1
  878. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
  879. package/node_modules/@earendil-works/pi-tui/dist/components/input.js +14 -14
  880. package/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
  881. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts.map +1 -1
  882. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js +11 -13
  883. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js.map +1 -1
  884. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -1
  885. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +0 -11
  886. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -1
  887. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts.map +1 -1
  888. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +4 -9
  889. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js.map +1 -1
  890. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +1 -1
  891. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +4 -12
  892. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +1 -1
  893. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts.map +1 -1
  894. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js +0 -1
  895. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js.map +1 -1
  896. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts.map +1 -1
  897. package/node_modules/@earendil-works/pi-tui/dist/components/text.js +0 -8
  898. package/node_modules/@earendil-works/pi-tui/dist/components/text.js.map +1 -1
  899. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts.map +1 -1
  900. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js +0 -3
  901. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js.map +1 -1
  902. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts.map +1 -1
  903. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
  904. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
  905. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  906. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +1 -1
  907. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +2 -4
  908. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -1
  909. package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts.map +1 -1
  910. package/node_modules/@earendil-works/pi-tui/dist/keys.js.map +1 -1
  911. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts.map +1 -1
  912. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js +3 -1
  913. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js.map +1 -1
  914. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts.map +1 -1
  915. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js.map +1 -1
  916. package/node_modules/@earendil-works/pi-tui/dist/slash-command-autocomplete.d.ts.map +1 -1
  917. package/node_modules/@earendil-works/pi-tui/dist/slash-command-autocomplete.js.map +1 -1
  918. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts.map +1 -1
  919. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +4 -6
  920. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js.map +1 -1
  921. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +1 -1
  922. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +1 -1
  923. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  924. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +24 -29
  925. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  926. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  927. package/node_modules/@earendil-works/pi-tui/dist/tui.js +25 -27
  928. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  929. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts.map +1 -1
  930. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js +3 -1
  931. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js.map +1 -1
  932. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
  933. package/node_modules/@earendil-works/pi-tui/dist/utils.js +14 -12
  934. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
  935. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.d.ts.map +1 -1
  936. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.js.map +1 -1
  937. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  938. package/node_modules/@types/node/README.md +3 -3
  939. package/node_modules/@types/node/assert/strict.d.ts +3 -55
  940. package/node_modules/@types/node/assert.d.ts +49 -177
  941. package/node_modules/@types/node/async_hooks.d.ts +151 -43
  942. package/node_modules/@types/node/buffer.buffer.d.ts +2 -8
  943. package/node_modules/@types/node/buffer.d.ts +43 -212
  944. package/node_modules/@types/node/child_process.d.ts +23 -133
  945. package/node_modules/@types/node/cluster.d.ts +238 -384
  946. package/node_modules/@types/node/compatibility/iterators.d.ts +1 -0
  947. package/node_modules/@types/node/console.d.ts +45 -404
  948. package/node_modules/@types/node/constants.d.ts +3 -10
  949. package/node_modules/@types/node/crypto.d.ts +640 -1127
  950. package/node_modules/@types/node/dgram.d.ts +14 -77
  951. package/node_modules/@types/node/diagnostics_channel.d.ts +3 -29
  952. package/node_modules/@types/node/dns/promises.d.ts +4 -10
  953. package/node_modules/@types/node/dns.d.ts +130 -177
  954. package/node_modules/@types/node/domain.d.ts +12 -32
  955. package/node_modules/@types/node/events.d.ts +872 -840
  956. package/node_modules/@types/node/fs/promises.d.ts +193 -20
  957. package/node_modules/@types/node/fs.d.ts +754 -435
  958. package/node_modules/@types/node/globals.d.ts +8 -30
  959. package/node_modules/@types/node/globals.typedarray.d.ts +63 -0
  960. package/node_modules/@types/node/http.d.ts +363 -305
  961. package/node_modules/@types/node/http2.d.ts +545 -781
  962. package/node_modules/@types/node/https.d.ts +64 -243
  963. package/node_modules/@types/node/index.d.ts +26 -6
  964. package/node_modules/@types/node/inspector/promises.d.ts +35 -0
  965. package/node_modules/@types/node/inspector.d.ts +68 -57
  966. package/node_modules/@types/node/inspector.generated.d.ts +764 -410
  967. package/node_modules/@types/node/module.d.ts +53 -189
  968. package/node_modules/@types/node/net.d.ts +101 -207
  969. package/node_modules/@types/node/os.d.ts +11 -19
  970. package/node_modules/@types/node/package.json +13 -3
  971. package/node_modules/@types/node/path/posix.d.ts +8 -0
  972. package/node_modules/@types/node/path/win32.d.ts +8 -0
  973. package/node_modules/@types/node/path.d.ts +119 -141
  974. package/node_modules/@types/node/perf_hooks.d.ts +317 -673
  975. package/node_modules/@types/node/process.d.ts +277 -157
  976. package/node_modules/@types/node/punycode.d.ts +3 -31
  977. package/node_modules/@types/node/querystring.d.ts +3 -16
  978. package/node_modules/@types/node/quic.d.ts +897 -0
  979. package/node_modules/@types/node/readline/promises.d.ts +3 -6
  980. package/node_modules/@types/node/readline.d.ts +65 -152
  981. package/node_modules/@types/node/repl.d.ts +101 -109
  982. package/node_modules/@types/node/sea.d.ts +9 -115
  983. package/node_modules/@types/node/sqlite.d.ts +415 -68
  984. package/node_modules/@types/node/stream/consumers.d.ts +91 -15
  985. package/node_modules/@types/node/stream/iter.d.ts +301 -0
  986. package/node_modules/@types/node/stream/promises.d.ts +136 -15
  987. package/node_modules/@types/node/stream/web.d.ts +179 -501
  988. package/node_modules/@types/node/stream.d.ts +577 -490
  989. package/node_modules/@types/node/string_decoder.d.ts +3 -43
  990. package/node_modules/@types/node/test/reporters.d.ts +59 -0
  991. package/node_modules/@types/node/test.d.ts +402 -286
  992. package/node_modules/@types/node/timers/promises.d.ts +3 -18
  993. package/node_modules/@types/node/timers.d.ts +3 -141
  994. package/node_modules/@types/node/tls.d.ts +115 -241
  995. package/node_modules/@types/node/trace_events.d.ts +3 -97
  996. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +2 -8
  997. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  998. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +2 -0
  999. package/node_modules/@types/node/ts5.6/index.d.ts +28 -6
  1000. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  1001. package/node_modules/@types/node/ts5.7/index.d.ts +119 -0
  1002. package/node_modules/@types/node/tty.d.ts +57 -40
  1003. package/node_modules/@types/node/url.d.ts +156 -584
  1004. package/node_modules/@types/node/util/types.d.ts +558 -0
  1005. package/node_modules/@types/node/util.d.ts +167 -1096
  1006. package/node_modules/@types/node/v8.d.ts +75 -15
  1007. package/node_modules/@types/node/vm.d.ts +334 -198
  1008. package/node_modules/@types/node/wasi.d.ts +24 -74
  1009. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +27 -2
  1010. package/node_modules/@types/node/web-globals/blob.d.ts +23 -0
  1011. package/node_modules/@types/node/web-globals/console.d.ts +9 -0
  1012. package/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
  1013. package/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
  1014. package/node_modules/@types/node/web-globals/events.d.ts +9 -0
  1015. package/node_modules/@types/node/web-globals/fetch.d.ts +14 -0
  1016. package/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
  1017. package/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
  1018. package/node_modules/@types/node/web-globals/navigator.d.ts +3 -0
  1019. package/node_modules/@types/node/web-globals/performance.d.ts +45 -0
  1020. package/node_modules/@types/node/web-globals/streams.d.ts +115 -0
  1021. package/node_modules/@types/node/web-globals/timers.d.ts +44 -0
  1022. package/node_modules/@types/node/web-globals/url.d.ts +24 -0
  1023. package/node_modules/@types/node/worker_threads.d.ts +280 -393
  1024. package/node_modules/@types/node/zlib/iter.d.ts +131 -0
  1025. package/node_modules/@types/node/zlib.d.ts +7 -165
  1026. package/node_modules/undici-types/agent.d.ts +13 -12
  1027. package/node_modules/undici-types/api.d.ts +26 -26
  1028. package/node_modules/undici-types/balanced-pool.d.ts +13 -12
  1029. package/node_modules/undici-types/cache-interceptor.d.ts +179 -0
  1030. package/node_modules/undici-types/client-stats.d.ts +15 -0
  1031. package/node_modules/undici-types/client.d.ts +34 -19
  1032. package/node_modules/undici-types/connector.d.ts +4 -2
  1033. package/node_modules/undici-types/cookies.d.ts +2 -0
  1034. package/node_modules/undici-types/diagnostics-channel.d.ts +18 -10
  1035. package/node_modules/undici-types/dispatcher.d.ts +127 -104
  1036. package/node_modules/undici-types/env-http-proxy-agent.d.ts +4 -3
  1037. package/node_modules/undici-types/errors.d.ts +82 -54
  1038. package/node_modules/undici-types/eventsource.d.ts +9 -4
  1039. package/node_modules/undici-types/fetch.d.ts +22 -20
  1040. package/node_modules/undici-types/formdata.d.ts +7 -7
  1041. package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
  1042. package/node_modules/undici-types/global-origin.d.ts +5 -5
  1043. package/node_modules/undici-types/h2c-client.d.ts +73 -0
  1044. package/node_modules/undici-types/handlers.d.ts +8 -8
  1045. package/node_modules/undici-types/header.d.ts +157 -1
  1046. package/node_modules/undici-types/index.d.ts +67 -47
  1047. package/node_modules/undici-types/interceptors.d.ts +71 -8
  1048. package/node_modules/undici-types/mock-agent.d.ts +36 -18
  1049. package/node_modules/undici-types/mock-call-history.d.ts +111 -0
  1050. package/node_modules/undici-types/mock-client.d.ts +6 -4
  1051. package/node_modules/undici-types/mock-errors.d.ts +3 -3
  1052. package/node_modules/undici-types/mock-interceptor.d.ts +21 -20
  1053. package/node_modules/undici-types/mock-pool.d.ts +6 -4
  1054. package/node_modules/undici-types/package.json +1 -1
  1055. package/node_modules/undici-types/patch.d.ts +0 -4
  1056. package/node_modules/undici-types/pool-stats.d.ts +8 -8
  1057. package/node_modules/undici-types/pool.d.ts +15 -13
  1058. package/node_modules/undici-types/proxy-agent.d.ts +5 -4
  1059. package/node_modules/undici-types/readable.d.ts +19 -16
  1060. package/node_modules/undici-types/retry-agent.d.ts +1 -1
  1061. package/node_modules/undici-types/retry-handler.d.ts +19 -10
  1062. package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
  1063. package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  1064. package/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
  1065. package/node_modules/undici-types/util.d.ts +3 -3
  1066. package/node_modules/undici-types/utility.d.ts +7 -0
  1067. package/node_modules/undici-types/webidl.d.ts +148 -29
  1068. package/node_modules/undici-types/websocket.d.ts +48 -10
  1069. package/npm-shrinkwrap.json +21 -21
  1070. package/package.json +14 -8
  1071. package/node_modules/@types/node/compatibility/disposable.d.ts +0 -14
  1072. package/node_modules/@types/node/compatibility/index.d.ts +0 -9
  1073. package/node_modules/@types/node/compatibility/indexable.d.ts +0 -20
  1074. package/node_modules/undici-types/file.d.ts +0 -39
  1075. package/node_modules/undici-types/filereader.d.ts +0 -54
@@ -1 +1 @@
1
- {"version":3,"file":"google-vertex.d.ts","sourceRoot":"","sources":["../../src/providers/google-vertex.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAMX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAKb,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAY9D,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACzD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACrC,QAAQ,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,mBAAmB,CAAC;KAC5B,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAgBD,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,eAAe,EAAE,mBAAmB,CAiQnF,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,eAAe,EAAE,mBAAmB,CAiCzF,CAAC","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\ttype HttpOptions,\n\tResourceScope,\n\ttype ThinkingConfig,\n\tThinkingLevel,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tThinkingLevel as PiThinkingLevel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nexport interface GoogleVertexOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n\tproject?: string;\n\tlocation?: string;\n}\n\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, ThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: ThinkingLevel.MINIMAL,\n\tLOW: ThinkingLevel.LOW,\n\tMEDIUM: ThinkingLevel.MEDIUM,\n\tHIGH: ThinkingLevel.HIGH,\n};\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogleVertex: StreamFunction<\"google-vertex\", GoogleVertexOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: GoogleVertexOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-vertex\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = resolveApiKey(options);\n\t\t\t// Create the client using either a Vertex API key, if provided, or ADC with project and location\n\t\t\tconst client = apiKey\n\t\t\t\t? createClientWithApiKey(model, apiKey, options?.headers)\n\t\t\t\t: createClient(model, resolveProject(options), resolveLocation(options), options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n\t\t\t\t// responseId is documented there as an output-only identifier for each response.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogleVertex: StreamFunction<\"google-vertex\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst base = buildBaseOptions(model, options, undefined);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: { enabled: false },\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\n\tif (isGemini3ProModel(model) || isGemini3FlashModel(model)) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getGemini3ThinkingLevel(effort, model),\n\t\t\t},\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\treturn streamGoogleVertex(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(model, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleVertexOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-vertex\">,\n\tproject: string,\n\tlocation: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tproject,\n\t\tlocation,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction createClientWithApiKey(\n\tmodel: Model<\"google-vertex\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tapiKey,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction buildHttpOptions(\n\tmodel: Model<\"google-vertex\">,\n\toptionsHeaders?: Record<string, string>,\n): HttpOptions | undefined {\n\tconst httpOptions: HttpOptions = {};\n\tconst baseUrl = resolveCustomBaseUrl(model.baseUrl);\n\tif (baseUrl) {\n\t\thttpOptions.baseUrl = baseUrl;\n\t\thttpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n\t\tif (baseUrlIncludesApiVersion(baseUrl)) {\n\t\t\thttpOptions.apiVersion = \"\";\n\t\t}\n\t}\n\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\n\nfunction resolveCustomBaseUrl(baseUrl: string): string | undefined {\n\tconst trimmed = baseUrl.trim();\n\tif (!trimmed || trimmed.includes(\"{location}\")) {\n\t\treturn undefined;\n\t}\n\treturn trimmed;\n}\n\nfunction baseUrlIncludesApiVersion(baseUrl: string): boolean {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\treturn url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n\t} catch {\n\t\treturn /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n\t}\n}\n\nfunction resolveApiKey(options?: GoogleVertexOptions): string | undefined {\n\tconst apiKey = options?.apiKey?.trim();\n\tif (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n\t\treturn undefined;\n\t}\n\treturn apiKey;\n}\n\nfunction isPlaceholderApiKey(apiKey: string): boolean {\n\treturn /^<[^>]+>$/.test(apiKey);\n}\n\nfunction resolveProject(options?: GoogleVertexOptions): string {\n\tconst project = options?.project || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT;\n\tif (!project) {\n\t\tthrow new Error(\n\t\t\t\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\",\n\t\t);\n\t}\n\treturn project;\n}\n\nfunction resolveLocation(options?: GoogleVertexOptions): string {\n\tconst location = options?.location || process.env.GOOGLE_CLOUD_LOCATION;\n\tif (!location) {\n\t\tthrow new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n\t}\n\treturn location;\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions: GoogleVertexOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<PiThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemini3ProModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-vertex\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getGemini3ThinkingLevel(effort: ClampedThinkingLevel, model: Pick<Model<Api>, \"id\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Pick<Model<Api>, \"id\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
1
+ {"version":3,"file":"google-vertex.d.ts","sourceRoot":"","sources":["../../src/providers/google-vertex.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAMX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAKb,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK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B;IACT,IAAI,aAAa,EAAE,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,aAAa,CAAC,MAAM,CAAE,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AAAA,CACV","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\ttype HttpOptions,\n\tResourceScope,\n\ttype ThinkingConfig,\n\tThinkingLevel,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tThinkingLevel as PiThinkingLevel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nexport interface GoogleVertexOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n\tproject?: string;\n\tlocation?: string;\n}\n\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, ThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: ThinkingLevel.MINIMAL,\n\tLOW: ThinkingLevel.LOW,\n\tMEDIUM: ThinkingLevel.MEDIUM,\n\tHIGH: ThinkingLevel.HIGH,\n};\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogleVertex: StreamFunction<\"google-vertex\", GoogleVertexOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: GoogleVertexOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-vertex\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = resolveApiKey(options);\n\t\t\t// Create the client using either a Vertex API key, if provided, or ADC with project and location\n\t\t\tconst client = apiKey\n\t\t\t\t? createClientWithApiKey(model, apiKey, options?.headers)\n\t\t\t\t: createClient(model, resolveProject(options), resolveLocation(options), options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n\t\t\t\t// responseId is documented there as an output-only identifier for each response.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogleVertex: StreamFunction<\"google-vertex\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst base = buildBaseOptions(model, options, undefined);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: { enabled: false },\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\n\tif (isGemini3ProModel(model) || isGemini3FlashModel(model)) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getGemini3ThinkingLevel(effort, model),\n\t\t\t},\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\treturn streamGoogleVertex(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(model, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleVertexOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-vertex\">,\n\tproject: string,\n\tlocation: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tproject,\n\t\tlocation,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction createClientWithApiKey(\n\tmodel: Model<\"google-vertex\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tapiKey,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction buildHttpOptions(\n\tmodel: Model<\"google-vertex\">,\n\toptionsHeaders?: Record<string, string>,\n): HttpOptions | undefined {\n\tconst httpOptions: HttpOptions = {};\n\tconst baseUrl = resolveCustomBaseUrl(model.baseUrl);\n\tif (baseUrl) {\n\t\thttpOptions.baseUrl = baseUrl;\n\t\thttpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n\t\tif (baseUrlIncludesApiVersion(baseUrl)) {\n\t\t\thttpOptions.apiVersion = \"\";\n\t\t}\n\t}\n\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\n\nfunction resolveCustomBaseUrl(baseUrl: string): string | undefined {\n\tconst trimmed = baseUrl.trim();\n\tif (!trimmed || trimmed.includes(\"{location}\")) {\n\t\treturn undefined;\n\t}\n\treturn trimmed;\n}\n\nfunction baseUrlIncludesApiVersion(baseUrl: string): boolean {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\treturn url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n\t} catch {\n\t\treturn /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n\t}\n}\n\nfunction resolveApiKey(options?: GoogleVertexOptions): string | undefined {\n\tconst apiKey = options?.apiKey?.trim();\n\tif (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n\t\treturn undefined;\n\t}\n\treturn apiKey;\n}\n\nfunction isPlaceholderApiKey(apiKey: string): boolean {\n\treturn /^<[^>]+>$/.test(apiKey);\n}\n\nfunction resolveProject(options?: GoogleVertexOptions): string {\n\tconst project = options?.project || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT;\n\tif (!project) {\n\t\tthrow new Error(\n\t\t\t\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\",\n\t\t);\n\t}\n\treturn project;\n}\n\nfunction resolveLocation(options?: GoogleVertexOptions): string {\n\tconst location = options?.location || process.env.GOOGLE_CLOUD_LOCATION;\n\tif (!location) {\n\t\tthrow new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n\t}\n\treturn location;\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions: GoogleVertexOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<PiThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemini3ProModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-vertex\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getGemini3ThinkingLevel(effort: ClampedThinkingLevel, model: Pick<Model<Api>, \"id\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Pick<Model<Api>, \"id\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
1
+ {"version":3,"file":"google-vertex.js","sourceRoot":"","sources":["../../src/providers/google-vertex.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EAEX,aAAa,EAEb,aAAa,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAejE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EACN,eAAe,EACf,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,uBAAuB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAalG,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;AAE/D,MAAM,kBAAkB,GAA+C;IACtE,0BAA0B,EAAE,aAAa,CAAC,0BAA0B;IACpE,OAAO,EAAE,aAAa,CAAC,OAAO;IAC9B,GAAG,EAAE,aAAa,CAAC,GAAG;IACtB,MAAM,EAAE,aAAa,CAAC,MAAM;IAC5B,IAAI,EAAE,aAAa,CAAC,IAAI;CACxB,CAAC;AAEF,8CAA8C;AAC9C,IAAI,eAAe,GAAG,CAAC,CAAC;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAyD,CACvF,KAA6B,EAC7B,OAAgB,EAChB,OAA6B,EACC,EAAE;IAChC,MAAM,MAAM,GAAG,IAAI,2BAA2B,EAAE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AAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\ttype HttpOptions,\n\tResourceScope,\n\ttype ThinkingConfig,\n\tThinkingLevel,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tThinkingLevel as PiThinkingLevel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nexport interface GoogleVertexOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n\tproject?: string;\n\tlocation?: string;\n}\n\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, ThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: ThinkingLevel.MINIMAL,\n\tLOW: ThinkingLevel.LOW,\n\tMEDIUM: ThinkingLevel.MEDIUM,\n\tHIGH: ThinkingLevel.HIGH,\n};\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogleVertex: StreamFunction<\"google-vertex\", GoogleVertexOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: GoogleVertexOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-vertex\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = resolveApiKey(options);\n\t\t\t// Create the client using either a Vertex API key, if provided, or ADC with project and location\n\t\t\tconst client = apiKey\n\t\t\t\t? createClientWithApiKey(model, apiKey, options?.headers)\n\t\t\t\t: createClient(model, resolveProject(options), resolveLocation(options), options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n\t\t\t\t// responseId is documented there as an output-only identifier for each response.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogleVertex: StreamFunction<\"google-vertex\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst base = buildBaseOptions(model, options, undefined);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: { enabled: false },\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\n\tif (isGemini3ProModel(model) || isGemini3FlashModel(model)) {\n\t\treturn streamGoogleVertex(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getGemini3ThinkingLevel(effort, model),\n\t\t\t},\n\t\t} satisfies GoogleVertexOptions);\n\t}\n\n\treturn streamGoogleVertex(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(model, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleVertexOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-vertex\">,\n\tproject: string,\n\tlocation: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tproject,\n\t\tlocation,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction createClientWithApiKey(\n\tmodel: Model<\"google-vertex\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\treturn new GoogleGenAI({\n\t\tvertexai: true,\n\t\tapiKey,\n\t\tapiVersion: API_VERSION,\n\t\thttpOptions: buildHttpOptions(model, optionsHeaders),\n\t});\n}\n\nfunction buildHttpOptions(\n\tmodel: Model<\"google-vertex\">,\n\toptionsHeaders?: Record<string, string>,\n): HttpOptions | undefined {\n\tconst httpOptions: HttpOptions = {};\n\tconst baseUrl = resolveCustomBaseUrl(model.baseUrl);\n\tif (baseUrl) {\n\t\thttpOptions.baseUrl = baseUrl;\n\t\thttpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n\t\tif (baseUrlIncludesApiVersion(baseUrl)) {\n\t\t\thttpOptions.apiVersion = \"\";\n\t\t}\n\t}\n\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\n\nfunction resolveCustomBaseUrl(baseUrl: string): string | undefined {\n\tconst trimmed = baseUrl.trim();\n\tif (!trimmed || trimmed.includes(\"{location}\")) {\n\t\treturn undefined;\n\t}\n\treturn trimmed;\n}\n\nfunction baseUrlIncludesApiVersion(baseUrl: string): boolean {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\treturn url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n\t} catch {\n\t\treturn /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n\t}\n}\n\nfunction resolveApiKey(options?: GoogleVertexOptions): string | undefined {\n\tconst apiKey = options?.apiKey?.trim();\n\tif (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n\t\treturn undefined;\n\t}\n\treturn apiKey;\n}\n\nfunction isPlaceholderApiKey(apiKey: string): boolean {\n\treturn /^<[^>]+>$/.test(apiKey);\n}\n\nfunction resolveProject(options?: GoogleVertexOptions): string {\n\tconst project = options?.project || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT;\n\tif (!project) {\n\t\tthrow new Error(\n\t\t\t\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\",\n\t\t);\n\t}\n\treturn project;\n}\n\nfunction resolveLocation(options?: GoogleVertexOptions): string {\n\tconst location = options?.location || process.env.GOOGLE_CLOUD_LOCATION;\n\tif (!location) {\n\t\tthrow new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n\t}\n\treturn location;\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-vertex\">,\n\tcontext: Context,\n\toptions: GoogleVertexOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<PiThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemini3ProModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-vertex\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: ThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getGemini3ThinkingLevel(effort: ClampedThinkingLevel, model: Pick<Model<Api>, \"id\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Pick<Model<Api>, \"id\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAKX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAoB9D,MAAM,WAAW,aAAc,SAAQ,aAAa;IACnD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACrC,QAAQ,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,mBAAmB,CAAC;KAC5B,CAAC;CACF;AAKD,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,sBAAsB,EAAE,aAAa,CAkQ9E,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,sBAAsB,EAAE,mBAAmB,CAoC1F,CAAC","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\tThinkingLevel as GoogleGenAIThinkingLevel,\n\ttype ThinkingConfig,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingLevel,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, GoogleGenAIThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: GoogleGenAIThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: GoogleGenAIThinkingLevel.MINIMAL,\n\tLOW: GoogleGenAIThinkingLevel.LOW,\n\tMEDIUM: GoogleGenAIThinkingLevel.MEDIUM,\n\tHIGH: GoogleGenAIThinkingLevel.HIGH,\n};\n\nexport interface GoogleOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n}\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogle: StreamFunction<\"google-generative-ai\", GoogleOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: GoogleOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-generative-ai\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// @google/genai documents GenerateContentResponse.responseId as an output-only field\n\t\t\t\t// used to identify each response. Keep the first non-empty one from the stream.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Generate unique ID if not provided or if it's a duplicate\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogle: StreamFunction<\"google-generative-ai\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogle(model, context, { ...base, thinking: { enabled: false } } satisfies GoogleOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\tconst googleModel = model as Model<\"google-generative-ai\">;\n\n\tif (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {\n\t\treturn streamGoogle(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getThinkingLevel(effort, googleModel),\n\t\t\t},\n\t\t} satisfies GoogleOptions);\n\t}\n\n\treturn streamGoogle(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-generative-ai\">,\n\tapiKey?: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\tconst httpOptions: { baseUrl?: string; apiVersion?: string; headers?: Record<string, string> } = {};\n\tif (model.baseUrl) {\n\t\thttpOptions.baseUrl = model.baseUrl;\n\t\thttpOptions.apiVersion = \"\"; // baseUrl already includes version path, don't append\n\t}\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn new GoogleGenAI({\n\t\tapiKey,\n\t\thttpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : undefined,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions: GoogleOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<ThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemma4Model(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemma-?4/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3ProModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-generative-ai\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\tif (isGemma4Model(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getThinkingLevel(effort: ClampedThinkingLevel, model: Model<\"google-generative-ai\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tif (isGemma4Model(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"MINIMAL\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Model<\"google-generative-ai\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash-lite\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 512,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAKX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAoB9D,MAAM,WAAW,aAAc,SAAQ,aAAa;IACnD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACrC,QAAQ,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,mBAAmB,CAAC;KAC5B,CAAC;CACF;AAKD,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,sBAAsB,EAAE,aAAa,CAkQ9E,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,sBAAsB,EAAE,mBAAmB,CAoC1F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EACX,aAAa,IAAI,wBAAwB,GAEzC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAejE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EACN,eAAe,EACf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AAA,CACD;AAED,SAAS,eAAe,CACvB,KAAoC,EACpC,MAA4B,EAC5B,aAA+B,EACtB;IACT,IAAI,aAAa,EAAE,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,aAAa,CAAC,MAAM,CAAE,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACzC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AAAA,CACV","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\tThinkingLevel as GoogleGenAIThinkingLevel,\n\ttype ThinkingConfig,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingLevel,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, GoogleGenAIThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: GoogleGenAIThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: GoogleGenAIThinkingLevel.MINIMAL,\n\tLOW: GoogleGenAIThinkingLevel.LOW,\n\tMEDIUM: GoogleGenAIThinkingLevel.MEDIUM,\n\tHIGH: GoogleGenAIThinkingLevel.HIGH,\n};\n\nexport interface GoogleOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n}\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogle: StreamFunction<\"google-generative-ai\", GoogleOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: GoogleOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-generative-ai\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// @google/genai documents GenerateContentResponse.responseId as an output-only field\n\t\t\t\t// used to identify each response. Keep the first non-empty one from the stream.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Generate unique ID if not provided or if it's a duplicate\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogle: StreamFunction<\"google-generative-ai\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogle(model, context, { ...base, thinking: { enabled: false } } satisfies GoogleOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\tconst googleModel = model as Model<\"google-generative-ai\">;\n\n\tif (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {\n\t\treturn streamGoogle(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getThinkingLevel(effort, googleModel),\n\t\t\t},\n\t\t} satisfies GoogleOptions);\n\t}\n\n\treturn streamGoogle(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-generative-ai\">,\n\tapiKey?: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\tconst httpOptions: { baseUrl?: string; apiVersion?: string; headers?: Record<string, string> } = {};\n\tif (model.baseUrl) {\n\t\thttpOptions.baseUrl = model.baseUrl;\n\t\thttpOptions.apiVersion = \"\"; // baseUrl already includes version path, don't append\n\t}\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn new GoogleGenAI({\n\t\tapiKey,\n\t\thttpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : undefined,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions: GoogleOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<ThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemma4Model(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemma-?4/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3ProModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-generative-ai\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\tif (isGemma4Model(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getThinkingLevel(effort: ClampedThinkingLevel, model: Model<\"google-generative-ai\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tif (isGemma4Model(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"MINIMAL\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Model<\"google-generative-ai\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash-lite\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 512,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EACX,aAAa,IAAI,wBAAwB,GAEzC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAejE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EACN,eAAe,EACf,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,u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S,EAAE,CAAC;QAC3C,OAAO,aAAa,CAAC,MAAM,CAAE,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACzC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,MAAM,OAAO,GAAyC;YACrD,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["import {\n\ttype GenerateContentConfig,\n\ttype GenerateContentParameters,\n\tGoogleGenAI,\n\tThinkingLevel as GoogleGenAIThinkingLevel,\n\ttype ThinkingConfig,\n} from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingLevel,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport type { GoogleThinkingLevel } from \"./google-shared.ts\";\nimport {\n\tconvertMessages,\n\tconvertTools,\n\tisThinkingPart,\n\tmapStopReason,\n\tmapToolChoice,\n\tretainThoughtSignature,\n\ttoProviderNativeContent,\n} from \"./google-shared.ts\";\nimport { applyExtraBody, buildBaseOptions, GOOGLE_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\n\nconst THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, GoogleGenAIThinkingLevel> = {\n\tTHINKING_LEVEL_UNSPECIFIED: GoogleGenAIThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n\tMINIMAL: GoogleGenAIThinkingLevel.MINIMAL,\n\tLOW: GoogleGenAIThinkingLevel.LOW,\n\tMEDIUM: GoogleGenAIThinkingLevel.MEDIUM,\n\tHIGH: GoogleGenAIThinkingLevel.HIGH,\n};\n\nexport interface GoogleOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\";\n\tthinking?: {\n\t\tenabled: boolean;\n\t\tbudgetTokens?: number; // -1 for dynamic, 0 to disable\n\t\tlevel?: GoogleThinkingLevel;\n\t};\n}\n\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\n\nexport const streamGoogle: StreamFunction<\"google-generative-ai\", GoogleOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: GoogleOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"google-generative-ai\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\t\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\t\tlet params = buildParams(model, context, options);\n\t\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\t\tif (nextParams !== undefined) {\n\t\t\t\tparams = nextParams as GenerateContentParameters;\n\t\t\t}\n\t\t\tconst googleStream = await client.models.generateContentStream(params);\n\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\t\t\tlet groundingMetadataEmitted = false;\n\t\t\tlet urlContextMetadataEmitted = false;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\t\t\tfor await (const chunk of googleStream) {\n\t\t\t\t// @google/genai documents GenerateContentResponse.responseId as an output-only field\n\t\t\t\t// used to identify each response. Keep the first non-empty one from the stream.\n\t\t\t\toutput.responseId ||= chunk.responseId;\n\t\t\t\tconst candidate = chunk.candidates?.[0];\n\t\t\t\tif (candidate?.content?.parts) {\n\t\t\t\t\tfor (const part of candidate.content.parts) {\n\t\t\t\t\t\tlet handledAsKnownPart = false;\n\t\t\t\t\t\tif (part.text !== undefined) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tconst isThinking = isThinkingPart(part);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!currentBlock ||\n\t\t\t\t\t\t\t\t(isThinking && currentBlock.type !== \"thinking\") ||\n\t\t\t\t\t\t\t\t(!isThinking && currentBlock.type !== \"text\")\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blocks.length - 1,\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (isThinking) {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (currentBlock.type === \"thinking\") {\n\t\t\t\t\t\t\t\tcurrentBlock.thinking += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.thinkingSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentBlock.text += part.text;\n\t\t\t\t\t\t\t\tcurrentBlock.textSignature = retainThoughtSignature(\n\t\t\t\t\t\t\t\t\tcurrentBlock.textSignature,\n\t\t\t\t\t\t\t\t\tpart.thoughtSignature,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\tdelta: part.text,\n\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (part.functionCall) {\n\t\t\t\t\t\t\thandledAsKnownPart = true;\n\t\t\t\t\t\t\tif (currentBlock) {\n\t\t\t\t\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Generate unique ID if not provided or if it's a duplicate\n\t\t\t\t\t\t\tconst providedId = part.functionCall.id;\n\t\t\t\t\t\t\tconst needsNewId =\n\t\t\t\t\t\t\t\t!providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n\t\t\t\t\t\t\tconst toolCallId = needsNewId\n\t\t\t\t\t\t\t\t? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n\t\t\t\t\t\t\t\t: providedId;\n\n\t\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\tname: part.functionCall.name || \"\",\n\t\t\t\t\t\t\t\targuments: (part.functionCall.args as Record<string, any>) ?? {},\n\t\t\t\t\t\t\t\t...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!handledAsKnownPart) {\n\t\t\t\t\t\t\toutput.content.push(toProviderNativeContent(part));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.groundingMetadata && !groundingMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"groundingMetadata\",\n\t\t\t\t\t\traw: candidate.groundingMetadata,\n\t\t\t\t\t});\n\t\t\t\t\tgroundingMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.urlContextMetadata && !urlContextMetadataEmitted) {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"providerNative\",\n\t\t\t\t\t\tsubtype: \"urlContextMetadata\",\n\t\t\t\t\t\traw: candidate.urlContextMetadata,\n\t\t\t\t\t});\n\t\t\t\t\turlContextMetadataEmitted = true;\n\t\t\t\t}\n\n\t\t\t\tif (candidate?.finishReason) {\n\t\t\t\t\toutput.stopReason = mapStopReason(candidate.finishReason);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\")) {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (chunk.usageMetadata) {\n\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\tinput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n\t\t\t\t\t\toutput:\n\t\t\t\t\t\t\t(chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n\t\t\t\t\t\tcacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\ttotalTokens: chunk.usageMetadata.totalTokenCount || 0,\n\t\t\t\t\t\tcost: {\n\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentBlock) {\n\t\t\t\tif (currentBlock.type === \"text\") {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\t// Remove internal index property used during streaming\n\t\t\tfor (const block of output.content) {\n\t\t\t\tif (\"index\" in block) {\n\t\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleGoogle: StreamFunction<\"google-generative-ai\", SimpleStreamOptions> = (\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn streamGoogle(model, context, { ...base, thinking: { enabled: false } } satisfies GoogleOptions);\n\t}\n\n\tconst clampedReasoning = clampThinkingLevel(model, options.reasoning);\n\tconst effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning) as ClampedThinkingLevel;\n\tconst googleModel = model as Model<\"google-generative-ai\">;\n\n\tif (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {\n\t\treturn streamGoogle(model, context, {\n\t\t\t...base,\n\t\t\tthinking: {\n\t\t\t\tenabled: true,\n\t\t\t\tlevel: getThinkingLevel(effort, googleModel),\n\t\t\t},\n\t\t} satisfies GoogleOptions);\n\t}\n\n\treturn streamGoogle(model, context, {\n\t\t...base,\n\t\tthinking: {\n\t\t\tenabled: true,\n\t\t\tbudgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets),\n\t\t},\n\t} satisfies GoogleOptions);\n};\n\nfunction createClient(\n\tmodel: Model<\"google-generative-ai\">,\n\tapiKey?: string,\n\toptionsHeaders?: Record<string, string>,\n): GoogleGenAI {\n\tconst httpOptions: { baseUrl?: string; apiVersion?: string; headers?: Record<string, string> } = {};\n\tif (model.baseUrl) {\n\t\thttpOptions.baseUrl = model.baseUrl;\n\t\thttpOptions.apiVersion = \"\"; // baseUrl already includes version path, don't append\n\t}\n\tif (model.headers || optionsHeaders) {\n\t\thttpOptions.headers = { ...model.headers, ...optionsHeaders };\n\t}\n\n\treturn new GoogleGenAI({\n\t\tapiKey,\n\t\thttpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : undefined,\n\t});\n}\n\nfunction buildParams(\n\tmodel: Model<\"google-generative-ai\">,\n\tcontext: Context,\n\toptions: GoogleOptions = {},\n): GenerateContentParameters {\n\tconst contents = convertMessages(model, context, { preserveThinking: options.thinking?.enabled === true });\n\n\tconst generationConfig: GenerateContentConfig = {};\n\tif (options.temperature !== undefined) {\n\t\tgenerationConfig.temperature = options.temperature;\n\t}\n\tif (options.maxTokens !== undefined) {\n\t\tgenerationConfig.maxOutputTokens = options.maxTokens;\n\t}\n\n\tconst config: GenerateContentConfig = {\n\t\t...(Object.keys(generationConfig).length > 0 && generationConfig),\n\t\t...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n\t\t...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n\t};\n\n\tif (context.tools && context.tools.length > 0 && options.toolChoice) {\n\t\tconfig.toolConfig = {\n\t\t\tfunctionCallingConfig: {\n\t\t\t\tmode: mapToolChoice(options.toolChoice),\n\t\t\t},\n\t\t};\n\t} else {\n\t\tconfig.toolConfig = undefined;\n\t}\n\n\tif (options.thinking?.enabled && model.reasoning) {\n\t\tconst thinkingConfig: ThinkingConfig = { includeThoughts: true };\n\t\tif (options.thinking.level !== undefined) {\n\t\t\tthinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n\t\t} else if (options.thinking.budgetTokens !== undefined) {\n\t\t\tthinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n\t\t}\n\t\tconfig.thinkingConfig = thinkingConfig;\n\t} else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n\t\tconfig.thinkingConfig = getDisabledThinkingConfig(model);\n\t}\n\n\tif (options.signal) {\n\t\tif (options.signal.aborted) {\n\t\t\tthrow new Error(\"Request aborted\");\n\t\t}\n\t\tconfig.abortSignal = options.signal;\n\t}\n\n\tapplyExtraBody(config, options?.extraBody, GOOGLE_RESERVED_BODY_KEYS);\n\n\tconst params: GenerateContentParameters = {\n\t\tmodel: model.id,\n\t\tcontents,\n\t\tconfig,\n\t};\n\n\treturn params;\n}\n\ntype ClampedThinkingLevel = Exclude<ThinkingLevel, \"xhigh\" | \"max\">;\n\nfunction isGemma4Model(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemma-?4/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3ProModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\n\nfunction isGemini3FlashModel(model: Model<\"google-generative-ai\">): boolean {\n\treturn /gemini-3(?:\\.\\d+)?-flash/.test(model.id.toLowerCase());\n}\n\nfunction getDisabledThinkingConfig(model: Model<\"google-generative-ai\">): ThinkingConfig {\n\t// Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n\t// do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n\t// thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n\tif (isGemini3ProModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.LOW };\n\t}\n\tif (isGemini3FlashModel(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\tif (isGemma4Model(model)) {\n\t\treturn { thinkingLevel: GoogleGenAIThinkingLevel.MINIMAL };\n\t}\n\n\t// Gemini 2.x supports disabling via thinkingBudget = 0.\n\treturn { thinkingBudget: 0 };\n}\n\nfunction getThinkingLevel(effort: ClampedThinkingLevel, model: Model<\"google-generative-ai\">): GoogleThinkingLevel {\n\tif (isGemini3ProModel(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"LOW\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tif (isGemma4Model(model)) {\n\t\tswitch (effort) {\n\t\t\tcase \"minimal\":\n\t\t\tcase \"low\":\n\t\t\t\treturn \"MINIMAL\";\n\t\t\tcase \"medium\":\n\t\t\tcase \"high\":\n\t\t\t\treturn \"HIGH\";\n\t\t}\n\t}\n\tswitch (effort) {\n\t\tcase \"minimal\":\n\t\t\treturn \"MINIMAL\";\n\t\tcase \"low\":\n\t\t\treturn \"LOW\";\n\t\tcase \"medium\":\n\t\t\treturn \"MEDIUM\";\n\t\tcase \"high\":\n\t\t\treturn \"HIGH\";\n\t}\n}\n\nfunction getGoogleBudget(\n\tmodel: Model<\"google-generative-ai\">,\n\teffort: ClampedThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): number {\n\tif (customBudgets?.[effort] !== undefined) {\n\t\treturn customBudgets[effort]!;\n\t}\n\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash-lite\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 512,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\tconst budgets: Record<ClampedThinkingLevel, number> = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\treturn -1;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../src/providers/images/openrouter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAIX,cAAc,EAEd,aAAa,EAEb,MAAM,gBAAgB,CAAC;AAoBxB,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,mBAAmB,EAAE,aAAa,CAmEvF,CAAC","sourcesContent":["import OpenAI from \"openai\";\nimport type {\n\tChatCompletion,\n\tChatCompletionContentPart,\n\tChatCompletionContentPartImage,\n\tChatCompletionContentPartText,\n\tChatCompletionCreateParamsNonStreaming,\n} from \"openai/resources/chat/completions.js\";\nimport type {\n\tAssistantImages,\n\tImageContent,\n\tImagesContext,\n\tImagesFunction,\n\tImagesModel,\n\tImagesOptions,\n\tTextContent,\n} from \"../../types.ts\";\nimport { headersToRecord } from \"../../utils/headers.ts\";\nimport { sanitizeSurrogates } from \"../../utils/sanitize-unicode.ts\";\n\ninterface OpenRouterGeneratedImage {\n\timage_url?: string | { url?: string };\n}\n\ntype OpenRouterImageGenerationMessage = ChatCompletion[\"choices\"][number][\"message\"] & {\n\timages?: OpenRouterGeneratedImage[];\n};\n\ntype OpenRouterImageGenerationChoice = ChatCompletion[\"choices\"][number] & {\n\tmessage: OpenRouterImageGenerationMessage;\n};\n\ntype OpenRouterImageGenerationResponse = ChatCompletion & {\n\tchoices: OpenRouterImageGenerationChoice[];\n};\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tconst apiKey = options?.apiKey;\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t}\n\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\tlet params = buildParams(model, context);\n\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\tif (nextParams !== undefined) {\n\t\t\tparams = nextParams as typeof params;\n\t\t}\n\t\tconst requestOptions = {\n\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\tmaxRetries: options?.maxRetries ?? 0,\n\t\t};\n\t\tconst { data: response, response: rawResponse } = await client.chat.completions\n\t\t\t.create(params as unknown as ChatCompletionCreateParamsNonStreaming, requestOptions)\n\t\t\t.withResponse();\n\t\tawait options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);\n\n\t\tconst imageResponse = response as OpenRouterImageGenerationResponse;\n\t\toutput.responseId = imageResponse.id;\n\t\tif (imageResponse.usage) {\n\t\t\toutput.usage = parseUsage(imageResponse.usage, model);\n\t\t}\n\n\t\tconst choice = imageResponse.choices[0];\n\t\tif (choice) {\n\t\t\tconst content = choice.message.content;\n\t\t\tif (typeof content === \"string\" && content.length > 0) {\n\t\t\t\toutput.output.push({ type: \"text\", text: content } satisfies TextContent);\n\t\t\t}\n\n\t\t\tfor (const image of choice.message.images ?? []) {\n\t\t\t\tconst imageUrl = typeof image.image_url === \"string\" ? image.image_url : image.image_url?.url;\n\t\t\t\tif (!imageUrl?.startsWith(\"data:\")) continue;\n\t\t\t\tconst matches = imageUrl.match(/^data:([^;]+);base64,(.+)$/);\n\t\t\t\tif (!matches) continue;\n\t\t\t\toutput.output.push({\n\t\t\t\t\ttype: \"image\",\n\t\t\t\t\tmimeType: matches[1],\n\t\t\t\t\tdata: matches[2],\n\t\t\t\t} satisfies ImageContent);\n\t\t\t}\n\t\t}\n\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\treturn output;\n\t}\n};\n\nfunction createClient(\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): OpenAI {\n\treturn new OpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tdefaultHeaders: {\n\t\t\t...model.headers,\n\t\t\t...optionsHeaders,\n\t\t},\n\t});\n}\n\ntype OpenRouterImagesCreateParams = Omit<ChatCompletionCreateParamsNonStreaming, \"modalities\"> & {\n\tmodalities: Array<\"image\" | \"text\">;\n};\n\nfunction buildParams(model: ImagesModel<\"openrouter-images\">, context: ImagesContext): OpenRouterImagesCreateParams {\n\tconst content: ChatCompletionContentPart[] = context.input.map((item): ChatCompletionContentPart => {\n\t\tif (item.type === \"text\") {\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t} satisfies ChatCompletionContentPartText;\n\t\t}\n\t\treturn {\n\t\t\ttype: \"image_url\",\n\t\t\timage_url: {\n\t\t\t\turl: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t},\n\t\t} satisfies ChatCompletionContentPartImage;\n\t});\n\n\treturn {\n\t\tmodel: model.id,\n\t\tmessages: [\n\t\t\t{\n\t\t\t\trole: \"user\" as const,\n\t\t\t\tcontent,\n\t\t\t},\n\t\t],\n\t\tstream: false,\n\t\tmodalities: model.output.includes(\"text\") ? [\"image\", \"text\"] : [\"image\"],\n\t};\n}\n\nfunction parseUsage(\n\trawUsage: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\tprompt_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number };\n\t},\n\tmodel: ImagesModel<\"openrouter-images\">,\n) {\n\tconst promptTokens = rawUsage.prompt_tokens || 0;\n\tconst reportedCachedTokens = rawUsage.prompt_tokens_details?.cached_tokens || 0;\n\tconst cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;\n\tconst cacheReadTokens =\n\t\tcacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;\n\tconst input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);\n\tconst output = rawUsage.completion_tokens || 0;\n\tconst usage = {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead: cacheReadTokens,\n\t\tcacheWrite: cacheWriteTokens,\n\t\ttotalTokens: input + output + cacheReadTokens + cacheWriteTokens,\n\t\tcost: {\n\t\t\tinput: (model.cost.input / 1000000) * input,\n\t\t\toutput: (model.cost.output / 1000000) * output,\n\t\t\tcacheRead: (model.cost.cacheRead / 1000000) * cacheReadTokens,\n\t\t\tcacheWrite: (model.cost.cacheWrite / 1000000) * cacheWriteTokens,\n\t\t\ttotal: 0,\n\t\t},\n\t};\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\treturn usage;\n}\n"]}
1
+ {"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../src/providers/images/openrouter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAIX,cAAc,EAEd,aAAa,EAEb,MAAM,gBAAgB,CAAC;AAoBxB,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,mBAAmB,EAAE,aAAa,CAmEvF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../../../src/providers/images/openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAiB5B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAkBrE,MAAM,CAAC,MAAM,wBAAwB,GAAuD,KAAK,EAChG,KAAuC,EACvC,OAAsB,EACtB,OAAuB,EACtB,EAAE,CAAC;IACJ,MAAM,MAAM,GAAoB;QAC/B,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;IAEF,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,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import type {\n\tChatCompletion,\n\tChatCompletionContentPart,\n\tChatCompletionContentPartImage,\n\tChatCompletionContentPartText,\n\tChatCompletionCreateParamsNonStreaming,\n} from \"openai/resources/chat/completions.js\";\nimport type {\n\tAssistantImages,\n\tImageContent,\n\tImagesContext,\n\tImagesFunction,\n\tImagesModel,\n\tImagesOptions,\n\tTextContent,\n} from \"../../types.ts\";\nimport { headersToRecord } from \"../../utils/headers.ts\";\nimport { sanitizeSurrogates } from \"../../utils/sanitize-unicode.ts\";\n\ninterface OpenRouterGeneratedImage {\n\timage_url?: string | { url?: string };\n}\n\ntype OpenRouterImageGenerationMessage = ChatCompletion[\"choices\"][number][\"message\"] & {\n\timages?: OpenRouterGeneratedImage[];\n};\n\ntype OpenRouterImageGenerationChoice = ChatCompletion[\"choices\"][number] & {\n\tmessage: OpenRouterImageGenerationMessage;\n};\n\ntype OpenRouterImageGenerationResponse = ChatCompletion & {\n\tchoices: OpenRouterImageGenerationChoice[];\n};\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tconst apiKey = options?.apiKey;\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t}\n\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\tlet params = buildParams(model, context);\n\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\tif (nextParams !== undefined) {\n\t\t\tparams = nextParams as typeof params;\n\t\t}\n\t\tconst requestOptions = {\n\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\tmaxRetries: options?.maxRetries ?? 0,\n\t\t};\n\t\tconst { data: response, response: rawResponse } = await client.chat.completions\n\t\t\t.create(params as unknown as ChatCompletionCreateParamsNonStreaming, requestOptions)\n\t\t\t.withResponse();\n\t\tawait options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);\n\n\t\tconst imageResponse = response as OpenRouterImageGenerationResponse;\n\t\toutput.responseId = imageResponse.id;\n\t\tif (imageResponse.usage) {\n\t\t\toutput.usage = parseUsage(imageResponse.usage, model);\n\t\t}\n\n\t\tconst choice = imageResponse.choices[0];\n\t\tif (choice) {\n\t\t\tconst content = choice.message.content;\n\t\t\tif (typeof content === \"string\" && content.length > 0) {\n\t\t\t\toutput.output.push({ type: \"text\", text: content } satisfies TextContent);\n\t\t\t}\n\n\t\t\tfor (const image of choice.message.images ?? []) {\n\t\t\t\tconst imageUrl = typeof image.image_url === \"string\" ? image.image_url : image.image_url?.url;\n\t\t\t\tif (!imageUrl?.startsWith(\"data:\")) continue;\n\t\t\t\tconst matches = imageUrl.match(/^data:([^;]+);base64,(.+)$/);\n\t\t\t\tif (!matches) continue;\n\t\t\t\toutput.output.push({\n\t\t\t\t\ttype: \"image\",\n\t\t\t\t\tmimeType: matches[1],\n\t\t\t\t\tdata: matches[2],\n\t\t\t\t} satisfies ImageContent);\n\t\t\t}\n\t\t}\n\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\treturn output;\n\t}\n};\n\nfunction createClient(\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): OpenAI {\n\treturn new OpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tdefaultHeaders: {\n\t\t\t...model.headers,\n\t\t\t...optionsHeaders,\n\t\t},\n\t});\n}\n\ntype OpenRouterImagesCreateParams = Omit<ChatCompletionCreateParamsNonStreaming, \"modalities\"> & {\n\tmodalities: Array<\"image\" | \"text\">;\n};\n\nfunction buildParams(model: ImagesModel<\"openrouter-images\">, context: ImagesContext): OpenRouterImagesCreateParams {\n\tconst content: ChatCompletionContentPart[] = context.input.map((item): ChatCompletionContentPart => {\n\t\tif (item.type === \"text\") {\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t} satisfies ChatCompletionContentPartText;\n\t\t}\n\t\treturn {\n\t\t\ttype: \"image_url\",\n\t\t\timage_url: {\n\t\t\t\turl: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t},\n\t\t} satisfies ChatCompletionContentPartImage;\n\t});\n\n\treturn {\n\t\tmodel: model.id,\n\t\tmessages: [\n\t\t\t{\n\t\t\t\trole: \"user\" as const,\n\t\t\t\tcontent,\n\t\t\t},\n\t\t],\n\t\tstream: false,\n\t\tmodalities: model.output.includes(\"text\") ? [\"image\", \"text\"] : [\"image\"],\n\t};\n}\n\nfunction parseUsage(\n\trawUsage: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\tprompt_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number };\n\t},\n\tmodel: ImagesModel<\"openrouter-images\">,\n) {\n\tconst promptTokens = rawUsage.prompt_tokens || 0;\n\tconst reportedCachedTokens = rawUsage.prompt_tokens_details?.cached_tokens || 0;\n\tconst cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;\n\tconst cacheReadTokens =\n\t\tcacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;\n\tconst input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);\n\tconst output = rawUsage.completion_tokens || 0;\n\tconst usage = {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead: cacheReadTokens,\n\t\tcacheWrite: cacheWriteTokens,\n\t\ttotalTokens: input + output + cacheReadTokens + cacheWriteTokens,\n\t\tcost: {\n\t\t\tinput: (model.cost.input / 1000000) * input,\n\t\t\toutput: (model.cost.output / 1000000) * output,\n\t\t\tcacheRead: (model.cost.cacheRead / 1000000) * cacheReadTokens,\n\t\t\tcacheWrite: (model.cost.cacheWrite / 1000000) * cacheWriteTokens,\n\t\t\ttotal: 0,\n\t\t},\n\t};\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\treturn usage;\n}\n"]}
1
+ {"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../../../src/providers/images/openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAiB5B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAkBrE,MAAM,CAAC,MAAM,wBAAwB,GAAuD,KAAK,EAChG,KAAuC,EACvC,OAAsB,EACtB,OAAuB,EACtB,EAAE;IACH,MAAM,MAAM,GAAoB;QAC/B,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;IAEF,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC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CompletionContentPart,\n\tChatCompletionContentPartImage,\n\tChatCompletionContentPartText,\n\tChatCompletionCreateParamsNonStreaming,\n} from \"openai/resources/chat/completions.js\";\nimport type {\n\tAssistantImages,\n\tImageContent,\n\tImagesContext,\n\tImagesFunction,\n\tImagesModel,\n\tImagesOptions,\n\tTextContent,\n} from \"../../types.ts\";\nimport { headersToRecord } from \"../../utils/headers.ts\";\nimport { sanitizeSurrogates } from \"../../utils/sanitize-unicode.ts\";\n\ninterface OpenRouterGeneratedImage {\n\timage_url?: string | { url?: string };\n}\n\ntype OpenRouterImageGenerationMessage = ChatCompletion[\"choices\"][number][\"message\"] & {\n\timages?: OpenRouterGeneratedImage[];\n};\n\ntype OpenRouterImageGenerationChoice = ChatCompletion[\"choices\"][number] & {\n\tmessage: OpenRouterImageGenerationMessage;\n};\n\ntype OpenRouterImageGenerationResponse = ChatCompletion & {\n\tchoices: OpenRouterImageGenerationChoice[];\n};\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tconst apiKey = options?.apiKey;\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t}\n\t\tconst client = createClient(model, apiKey, options?.headers);\n\t\tlet params = buildParams(model, context);\n\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\tif (nextParams !== undefined) {\n\t\t\tparams = nextParams as typeof params;\n\t\t}\n\t\tconst requestOptions = {\n\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\tmaxRetries: options?.maxRetries ?? 0,\n\t\t};\n\t\tconst { data: response, response: rawResponse } = await client.chat.completions\n\t\t\t.create(params as unknown as ChatCompletionCreateParamsNonStreaming, requestOptions)\n\t\t\t.withResponse();\n\t\tawait options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);\n\n\t\tconst imageResponse = response as OpenRouterImageGenerationResponse;\n\t\toutput.responseId = imageResponse.id;\n\t\tif (imageResponse.usage) {\n\t\t\toutput.usage = parseUsage(imageResponse.usage, model);\n\t\t}\n\n\t\tconst choice = imageResponse.choices[0];\n\t\tif (choice) {\n\t\t\tconst content = choice.message.content;\n\t\t\tif (typeof content === \"string\" && content.length > 0) {\n\t\t\t\toutput.output.push({ type: \"text\", text: content } satisfies TextContent);\n\t\t\t}\n\n\t\t\tfor (const image of choice.message.images ?? []) {\n\t\t\t\tconst imageUrl = typeof image.image_url === \"string\" ? image.image_url : image.image_url?.url;\n\t\t\t\tif (!imageUrl?.startsWith(\"data:\")) continue;\n\t\t\t\tconst matches = imageUrl.match(/^data:([^;]+);base64,(.+)$/);\n\t\t\t\tif (!matches) continue;\n\t\t\t\toutput.output.push({\n\t\t\t\t\ttype: \"image\",\n\t\t\t\t\tmimeType: matches[1],\n\t\t\t\t\tdata: matches[2],\n\t\t\t\t} satisfies ImageContent);\n\t\t\t}\n\t\t}\n\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\treturn output;\n\t}\n};\n\nfunction createClient(\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tapiKey: string,\n\toptionsHeaders?: Record<string, string>,\n): OpenAI {\n\treturn new OpenAI({\n\t\tapiKey,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tdefaultHeaders: {\n\t\t\t...model.headers,\n\t\t\t...optionsHeaders,\n\t\t},\n\t});\n}\n\ntype OpenRouterImagesCreateParams = Omit<ChatCompletionCreateParamsNonStreaming, \"modalities\"> & {\n\tmodalities: Array<\"image\" | \"text\">;\n};\n\nfunction buildParams(model: ImagesModel<\"openrouter-images\">, context: ImagesContext): OpenRouterImagesCreateParams {\n\tconst content: ChatCompletionContentPart[] = context.input.map((item): ChatCompletionContentPart => {\n\t\tif (item.type === \"text\") {\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t} satisfies ChatCompletionContentPartText;\n\t\t}\n\t\treturn {\n\t\t\ttype: \"image_url\",\n\t\t\timage_url: {\n\t\t\t\turl: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t},\n\t\t} satisfies ChatCompletionContentPartImage;\n\t});\n\n\treturn {\n\t\tmodel: model.id,\n\t\tmessages: [\n\t\t\t{\n\t\t\t\trole: \"user\" as const,\n\t\t\t\tcontent,\n\t\t\t},\n\t\t],\n\t\tstream: false,\n\t\tmodalities: model.output.includes(\"text\") ? [\"image\", \"text\"] : [\"image\"],\n\t};\n}\n\nfunction parseUsage(\n\trawUsage: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\tprompt_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number };\n\t},\n\tmodel: ImagesModel<\"openrouter-images\">,\n) {\n\tconst promptTokens = rawUsage.prompt_tokens || 0;\n\tconst reportedCachedTokens = rawUsage.prompt_tokens_details?.cached_tokens || 0;\n\tconst cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;\n\tconst cacheReadTokens =\n\t\tcacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;\n\tconst input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);\n\tconst output = rawUsage.completion_tokens || 0;\n\tconst usage = {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead: cacheReadTokens,\n\t\tcacheWrite: cacheWriteTokens,\n\t\ttotalTokens: input + output + cacheReadTokens + cacheWriteTokens,\n\t\tcost: {\n\t\t\tinput: (model.cost.input / 1000000) * input,\n\t\t\toutput: (model.cost.output / 1000000) * output,\n\t\t\tcacheRead: (model.cost.cacheRead / 1000000) * cacheReadTokens,\n\t\t\tcacheWrite: (model.cost.cacheWrite / 1000000) * cacheWriteTokens,\n\t\t\ttotal: 0,\n\t\t},\n\t};\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\treturn usage;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register-builtins.d.ts","sourceRoot":"","sources":["../../../src/providers/images/register-builtins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkC,cAAc,EAAe,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA4BjH,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,mBAAmB,EAAE,aAAa,CAWvF,CAAC;AAEF,wBAAgB,iCAAiC,IAAI,IAAI,CAKxD","sourcesContent":["import { registerImagesApiProvider } from \"../../images-api-registry.ts\";\nimport type { AssistantImages, ImagesContext, ImagesFunction, ImagesModel, ImagesOptions } from \"../../types.ts\";\nimport type { generateImagesOpenRouter as generateImagesOpenRouterFunction } from \"./openrouter.ts\";\n\ninterface OpenRouterImagesProviderModule {\n\tgenerateImagesOpenRouter: typeof generateImagesOpenRouterFunction;\n}\n\nlet openRouterImagesProviderModulePromise: Promise<OpenRouterImagesProviderModule> | undefined;\n\nfunction createLazyLoadErrorImages(model: ImagesModel<\"openrouter-images\">, error: unknown): AssistantImages {\n\treturn {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction loadOpenRouterImagesProviderModule(): Promise<OpenRouterImagesProviderModule> {\n\topenRouterImagesProviderModulePromise ||= import(\"./openrouter.ts\").then(\n\t\t(module) => module as OpenRouterImagesProviderModule,\n\t);\n\treturn openRouterImagesProviderModulePromise;\n}\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\ttry {\n\t\tconst module = await loadOpenRouterImagesProviderModule();\n\t\treturn await module.generateImagesOpenRouter(model, context, options);\n\t} catch (error) {\n\t\treturn createLazyLoadErrorImages(model, error);\n\t}\n};\n\nexport function registerBuiltInImagesApiProviders(): void {\n\tregisterImagesApiProvider({\n\t\tapi: \"openrouter-images\",\n\t\tgenerateImages: generateImagesOpenRouter,\n\t});\n}\n\nregisterBuiltInImagesApiProviders();\n"]}
1
+ {"version":3,"file":"register-builtins.d.ts","sourceRoot":"","sources":["../../../src/providers/images/register-builtins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkC,cAAc,EAAe,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA4BjH,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,mBAAmB,EAAE,aAAa,CAWvF,CAAC;AAEF,wBAAgB,iCAAiC,IAAI,IAAI,CAKxD"}
@@ -1 +1 @@
1
- {"version":3,"file":"register-builtins.js","sourceRoot":"","sources":["../../../src/providers/images/register-builtins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAQzE,IAAI,qCAA0F,CAAC;AAE/F,SAAS,yBAAyB,CAAC,KAAuC,EAAE,KAAc,EAAmB;IAC5G,OAAO;QACN,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,OAAO;QACnB,YAAY,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACpE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;AAAA,CACF;AAED,SAAS,kCAAkC,GAA4C;IACtF,qCAAqC,KAAK,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAwC,CACpD,CAAC;IACF,OAAO,qCAAqC,CAAC;AAAA,CAC7C;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAuD,KAAK,EAChG,KAAuC,EACvC,OAAsB,EACtB,OAAuB,EACtB,EAAE,CAAC;IACJ,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,kCAAkC,EAAE,CAAC;QAC1D,OAAO,MAAM,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;AAAA,CACD,CAAC;AAEF,MAAM,UAAU,iCAAiC,GAAS;IACzD,yBAAyB,CAAC;QACzB,GAAG,EAAE,mBAAmB;QACxB,cAAc,EAAE,wBAAwB;KACxC,CAAC,CAAC;AAAA,CACH;AAED,iCAAiC,EAAE,CAAC","sourcesContent":["import { registerImagesApiProvider } from \"../../images-api-registry.ts\";\nimport type { AssistantImages, ImagesContext, ImagesFunction, ImagesModel, ImagesOptions } from \"../../types.ts\";\nimport type { generateImagesOpenRouter as generateImagesOpenRouterFunction } from \"./openrouter.ts\";\n\ninterface OpenRouterImagesProviderModule {\n\tgenerateImagesOpenRouter: typeof generateImagesOpenRouterFunction;\n}\n\nlet openRouterImagesProviderModulePromise: Promise<OpenRouterImagesProviderModule> | undefined;\n\nfunction createLazyLoadErrorImages(model: ImagesModel<\"openrouter-images\">, error: unknown): AssistantImages {\n\treturn {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction loadOpenRouterImagesProviderModule(): Promise<OpenRouterImagesProviderModule> {\n\topenRouterImagesProviderModulePromise ||= import(\"./openrouter.ts\").then(\n\t\t(module) => module as OpenRouterImagesProviderModule,\n\t);\n\treturn openRouterImagesProviderModulePromise;\n}\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\ttry {\n\t\tconst module = await loadOpenRouterImagesProviderModule();\n\t\treturn await module.generateImagesOpenRouter(model, context, options);\n\t} catch (error) {\n\t\treturn createLazyLoadErrorImages(model, error);\n\t}\n};\n\nexport function registerBuiltInImagesApiProviders(): void {\n\tregisterImagesApiProvider({\n\t\tapi: \"openrouter-images\",\n\t\tgenerateImages: generateImagesOpenRouter,\n\t});\n}\n\nregisterBuiltInImagesApiProviders();\n"]}
1
+ {"version":3,"file":"register-builtins.js","sourceRoot":"","sources":["../../../src/providers/images/register-builtins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAQzE,IAAI,qCAA0F,CAAC;AAE/F,SAAS,yBAAyB,CAAC,KAAuC,EAAE,KAAc;IACzF,OAAO;QACN,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,OAAO;QACnB,YAAY,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACpE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;AACH,CAAC;AAED,SAAS,kCAAkC;IAC1C,qCAAqC,KAAK,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAwC,CACpD,CAAC;IACF,OAAO,qCAAqC,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAuD,KAAK,EAChG,KAAuC,EACvC,OAAsB,EACtB,OAAuB,EACtB,EAAE;IACH,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,kCAAkC,EAAE,CAAC;QAC1D,OAAO,MAAM,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,UAAU,iCAAiC;IAChD,yBAAyB,CAAC;QACzB,GAAG,EAAE,mBAAmB;QACxB,cAAc,EAAE,wBAAwB;KACxC,CAAC,CAAC;AACJ,CAAC;AAED,iCAAiC,EAAE,CAAC","sourcesContent":["import { registerImagesApiProvider } from \"../../images-api-registry.ts\";\nimport type { AssistantImages, ImagesContext, ImagesFunction, ImagesModel, ImagesOptions } from \"../../types.ts\";\nimport type { generateImagesOpenRouter as generateImagesOpenRouterFunction } from \"./openrouter.ts\";\n\ninterface OpenRouterImagesProviderModule {\n\tgenerateImagesOpenRouter: typeof generateImagesOpenRouterFunction;\n}\n\nlet openRouterImagesProviderModulePromise: Promise<OpenRouterImagesProviderModule> | undefined;\n\nfunction createLazyLoadErrorImages(model: ImagesModel<\"openrouter-images\">, error: unknown): AssistantImages {\n\treturn {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction loadOpenRouterImagesProviderModule(): Promise<OpenRouterImagesProviderModule> {\n\topenRouterImagesProviderModulePromise ||= import(\"./openrouter.ts\").then(\n\t\t(module) => module as OpenRouterImagesProviderModule,\n\t);\n\treturn openRouterImagesProviderModulePromise;\n}\n\nexport const generateImagesOpenRouter: ImagesFunction<\"openrouter-images\", ImagesOptions> = async (\n\tmodel: ImagesModel<\"openrouter-images\">,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\ttry {\n\t\tconst module = await loadOpenRouterImagesProviderModule();\n\t\treturn await module.generateImagesOpenRouter(model, context, options);\n\t} catch (error) {\n\t\treturn createLazyLoadErrorImages(model, error);\n\t}\n};\n\nexport function registerBuiltInImagesApiProviders(): void {\n\tregisterImagesApiProvider({\n\t\tapi: \"openrouter-images\",\n\t\tgenerateImages: generateImagesOpenRouter,\n\t});\n}\n\nregisterBuiltInImagesApiProviders();\n"]}