@vib-rato/ai 0.16.0

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 (525) hide show
  1. package/CHANGELOG.md +3354 -0
  2. package/README.md +1194 -0
  3. package/dist/types/adapter-internals/provider-safety-stop.d.ts +45 -0
  4. package/dist/types/api-registry.d.ts +30 -0
  5. package/dist/types/auth-broker/client.d.ts +80 -0
  6. package/dist/types/auth-broker/index.d.ts +5 -0
  7. package/dist/types/auth-broker/redact.d.ts +7 -0
  8. package/dist/types/auth-broker/refresher.d.ts +25 -0
  9. package/dist/types/auth-broker/remote-store.d.ts +153 -0
  10. package/dist/types/auth-broker/server.d.ts +32 -0
  11. package/dist/types/auth-broker/types.d.ts +132 -0
  12. package/dist/types/auth-broker/wire-schemas.d.ts +555 -0
  13. package/dist/types/auth-gateway/http.d.ts +40 -0
  14. package/dist/types/auth-gateway/index.d.ts +3 -0
  15. package/dist/types/auth-gateway/server.d.ts +70 -0
  16. package/dist/types/auth-gateway/types.d.ts +129 -0
  17. package/dist/types/auth-storage.d.ts +1074 -0
  18. package/dist/types/cli.d.ts +2 -0
  19. package/dist/types/codex-tools.d.ts +4 -0
  20. package/dist/types/context-cap-policy.d.ts +68 -0
  21. package/dist/types/core.d.ts +35 -0
  22. package/dist/types/index.d.ts +55 -0
  23. package/dist/types/model-cache.d.ts +24 -0
  24. package/dist/types/model-manager.d.ts +77 -0
  25. package/dist/types/model-pricing.d.ts +3 -0
  26. package/dist/types/model-retirements.d.ts +6 -0
  27. package/dist/types/model-thinking.d.ts +100 -0
  28. package/dist/types/models.d.ts +21 -0
  29. package/dist/types/openai-completions-compat.d.ts +34 -0
  30. package/dist/types/provider-details.d.ts +24 -0
  31. package/dist/types/provider-models/bundled-references.d.ts +4 -0
  32. package/dist/types/provider-models/descriptors.d.ts +48 -0
  33. package/dist/types/provider-models/google.d.ts +20 -0
  34. package/dist/types/provider-models/index.d.ts +5 -0
  35. package/dist/types/provider-models/ollama.d.ts +7 -0
  36. package/dist/types/provider-models/openai-compat.d.ts +293 -0
  37. package/dist/types/provider-models/special.d.ts +29 -0
  38. package/dist/types/providers/amazon-bedrock.d.ts +60 -0
  39. package/dist/types/providers/anthropic-messages-server-schema.d.ts +450 -0
  40. package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
  41. package/dist/types/providers/anthropic.d.ts +280 -0
  42. package/dist/types/providers/aws-credential-config.d.ts +19 -0
  43. package/dist/types/providers/aws-credentials.d.ts +43 -0
  44. package/dist/types/providers/aws-eventstream.d.ts +38 -0
  45. package/dist/types/providers/aws-sigv4.d.ts +55 -0
  46. package/dist/types/providers/azure-openai-responses.d.ts +22 -0
  47. package/dist/types/providers/composer-discipline.d.ts +32 -0
  48. package/dist/types/providers/cursor/client-version.d.ts +10 -0
  49. package/dist/types/providers/cursor/exec-modern.d.ts +98 -0
  50. package/dist/types/providers/cursor/gen/agent_pb.d.ts +16769 -0
  51. package/dist/types/providers/cursor-pi-args.d.ts +119 -0
  52. package/dist/types/providers/cursor.d.ts +72 -0
  53. package/dist/types/providers/dashscope-token-plan-headers.d.ts +57 -0
  54. package/dist/types/providers/error-message.d.ts +27 -0
  55. package/dist/types/providers/github-copilot-headers.d.ts +40 -0
  56. package/dist/types/providers/gitlab-duo.d.ts +27 -0
  57. package/dist/types/providers/google-auth.d.ts +26 -0
  58. package/dist/types/providers/google-gemini-cli.d.ts +75 -0
  59. package/dist/types/providers/google-gemini-headers.d.ts +43 -0
  60. package/dist/types/providers/google-shared.d.ts +183 -0
  61. package/dist/types/providers/google-types.d.ts +138 -0
  62. package/dist/types/providers/google-vertex.d.ts +11 -0
  63. package/dist/types/providers/google.d.ts +4 -0
  64. package/dist/types/providers/grammar.d.ts +1 -0
  65. package/dist/types/providers/kimi.d.ts +27 -0
  66. package/dist/types/providers/kiro-api-key.d.ts +50 -0
  67. package/dist/types/providers/kiro-codewhisperer.d.ts +11 -0
  68. package/dist/types/providers/mock.d.ts +189 -0
  69. package/dist/types/providers/ollama.d.ts +41 -0
  70. package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
  71. package/dist/types/providers/openai-bounded-rate-limits.d.ts +3 -0
  72. package/dist/types/providers/openai-chat-server-schema.d.ts +1733 -0
  73. package/dist/types/providers/openai-chat-server.d.ts +16 -0
  74. package/dist/types/providers/openai-codex/constants.d.ts +26 -0
  75. package/dist/types/providers/openai-codex/request-transformer.d.ts +50 -0
  76. package/dist/types/providers/openai-codex/response-handler.d.ts +18 -0
  77. package/dist/types/providers/openai-codex-responses.d.ts +71 -0
  78. package/dist/types/providers/openai-completions-compat.d.ts +6 -0
  79. package/dist/types/providers/openai-completions.d.ts +35 -0
  80. package/dist/types/providers/openai-opencodex-responses.d.ts +10 -0
  81. package/dist/types/providers/openai-request-transform.d.ts +4 -0
  82. package/dist/types/providers/openai-responses-server-schema.d.ts +392 -0
  83. package/dist/types/providers/openai-responses-server.d.ts +17 -0
  84. package/dist/types/providers/openai-responses-shared.d.ts +106 -0
  85. package/dist/types/providers/openai-responses.d.ts +37 -0
  86. package/dist/types/providers/pi-native-client.d.ts +29 -0
  87. package/dist/types/providers/pi-native-server.d.ts +60 -0
  88. package/dist/types/providers/register-builtins.d.ts +59 -0
  89. package/dist/types/providers/synthetic.d.ts +26 -0
  90. package/dist/types/providers/transform-messages.d.ts +33 -0
  91. package/dist/types/providers/vision-guard.d.ts +8 -0
  92. package/dist/types/rate-limit-utils.d.ts +19 -0
  93. package/dist/types/stream.d.ts +45 -0
  94. package/dist/types/types.d.ts +1073 -0
  95. package/dist/types/usage/claude.d.ts +3 -0
  96. package/dist/types/usage/gemini.d.ts +2 -0
  97. package/dist/types/usage/github-copilot.d.ts +7 -0
  98. package/dist/types/usage/google-antigravity.d.ts +2 -0
  99. package/dist/types/usage/grok-cli.d.ts +17 -0
  100. package/dist/types/usage/kimi.d.ts +4 -0
  101. package/dist/types/usage/minimax-code.d.ts +2 -0
  102. package/dist/types/usage/openai-codex.d.ts +3 -0
  103. package/dist/types/usage/shared.d.ts +1 -0
  104. package/dist/types/usage/zai.d.ts +2 -0
  105. package/dist/types/usage.d.ts +264 -0
  106. package/dist/types/utils/abort.d.ts +19 -0
  107. package/dist/types/utils/anthropic-auth.d.ts +39 -0
  108. package/dist/types/utils/block-symbols.d.ts +6 -0
  109. package/dist/types/utils/discovery/antigravity.d.ts +67 -0
  110. package/dist/types/utils/discovery/codex.d.ts +38 -0
  111. package/dist/types/utils/discovery/cursor.d.ts +49 -0
  112. package/dist/types/utils/discovery/gemini.d.ts +25 -0
  113. package/dist/types/utils/discovery/index.d.ts +4 -0
  114. package/dist/types/utils/discovery/openai-compatible.d.ts +81 -0
  115. package/dist/types/utils/event-stream.d.ts +41 -0
  116. package/dist/types/utils/fallback-transport.d.ts +110 -0
  117. package/dist/types/utils/fireworks-model-id.d.ts +10 -0
  118. package/dist/types/utils/foundry.d.ts +11 -0
  119. package/dist/types/utils/h2-fetch.d.ts +22 -0
  120. package/dist/types/utils/http-inspector.d.ts +59 -0
  121. package/dist/types/utils/idle-iterator.d.ts +122 -0
  122. package/dist/types/utils/json-parse.d.ts +98 -0
  123. package/dist/types/utils/oauth/alibaba-token-plan.d.ts +19 -0
  124. package/dist/types/utils/oauth/anthropic.d.ts +41 -0
  125. package/dist/types/utils/oauth/api-key-login.d.ts +38 -0
  126. package/dist/types/utils/oauth/api-key-validation.d.ts +39 -0
  127. package/dist/types/utils/oauth/bizrouter.d.ts +1 -0
  128. package/dist/types/utils/oauth/callback-server.d.ts +80 -0
  129. package/dist/types/utils/oauth/cerebras.d.ts +1 -0
  130. package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +18 -0
  131. package/dist/types/utils/oauth/commandcode.d.ts +1 -0
  132. package/dist/types/utils/oauth/cursor.d.ts +15 -0
  133. package/dist/types/utils/oauth/deepinfra.d.ts +1 -0
  134. package/dist/types/utils/oauth/deepseek.d.ts +10 -0
  135. package/dist/types/utils/oauth/firepass.d.ts +1 -0
  136. package/dist/types/utils/oauth/fireworks.d.ts +1 -0
  137. package/dist/types/utils/oauth/fugu.d.ts +1 -0
  138. package/dist/types/utils/oauth/github-copilot.d.ts +38 -0
  139. package/dist/types/utils/oauth/gitlab-duo.d.ts +3 -0
  140. package/dist/types/utils/oauth/glm-zcode.d.ts +71 -0
  141. package/dist/types/utils/oauth/google-antigravity.d.ts +11 -0
  142. package/dist/types/utils/oauth/google-gemini-cli.d.ts +10 -0
  143. package/dist/types/utils/oauth/google-oauth-shared.d.ts +28 -0
  144. package/dist/types/utils/oauth/huggingface.d.ts +19 -0
  145. package/dist/types/utils/oauth/index.d.ts +39 -0
  146. package/dist/types/utils/oauth/kagi.d.ts +17 -0
  147. package/dist/types/utils/oauth/kilo.d.ts +5 -0
  148. package/dist/types/utils/oauth/kimi.d.ts +17 -0
  149. package/dist/types/utils/oauth/kiro.d.ts +71 -0
  150. package/dist/types/utils/oauth/litellm.d.ts +18 -0
  151. package/dist/types/utils/oauth/lm-studio.d.ts +17 -0
  152. package/dist/types/utils/oauth/mara.d.ts +1 -0
  153. package/dist/types/utils/oauth/minimax-code.d.ts +28 -0
  154. package/dist/types/utils/oauth/moonshot.d.ts +1 -0
  155. package/dist/types/utils/oauth/nanogpt.d.ts +1 -0
  156. package/dist/types/utils/oauth/nvidia.d.ts +18 -0
  157. package/dist/types/utils/oauth/ollama-cloud.d.ts +2 -0
  158. package/dist/types/utils/oauth/ollama.d.ts +18 -0
  159. package/dist/types/utils/oauth/openai-codex.d.ts +21 -0
  160. package/dist/types/utils/oauth/opencode.d.ts +18 -0
  161. package/dist/types/utils/oauth/opengateway.d.ts +1 -0
  162. package/dist/types/utils/oauth/openrouter.d.ts +1 -0
  163. package/dist/types/utils/oauth/parallel.d.ts +17 -0
  164. package/dist/types/utils/oauth/perplexity.d.ts +4 -0
  165. package/dist/types/utils/oauth/pkce.d.ts +8 -0
  166. package/dist/types/utils/oauth/qianfan.d.ts +17 -0
  167. package/dist/types/utils/oauth/qwen-portal.d.ts +19 -0
  168. package/dist/types/utils/oauth/sglang.d.ts +16 -0
  169. package/dist/types/utils/oauth/synthetic.d.ts +1 -0
  170. package/dist/types/utils/oauth/tavily.d.ts +17 -0
  171. package/dist/types/utils/oauth/together.d.ts +1 -0
  172. package/dist/types/utils/oauth/types.d.ts +56 -0
  173. package/dist/types/utils/oauth/venice.d.ts +18 -0
  174. package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +18 -0
  175. package/dist/types/utils/oauth/vllm.d.ts +16 -0
  176. package/dist/types/utils/oauth/xai.d.ts +30 -0
  177. package/dist/types/utils/oauth/xiaomi.d.ts +25 -0
  178. package/dist/types/utils/oauth/zai.d.ts +18 -0
  179. package/dist/types/utils/oauth/zenmux.d.ts +1 -0
  180. package/dist/types/utils/overflow.d.ts +14 -0
  181. package/dist/types/utils/parse-bind.d.ts +26 -0
  182. package/dist/types/utils/provider-response.d.ts +6 -0
  183. package/dist/types/utils/provider-safety-stop.d.ts +8 -0
  184. package/dist/types/utils/proxy.d.ts +7 -0
  185. package/dist/types/utils/retry-after.d.ts +3 -0
  186. package/dist/types/utils/retry-budget.d.ts +1 -0
  187. package/dist/types/utils/retry.d.ts +29 -0
  188. package/dist/types/utils/schema/adapt.d.ts +24 -0
  189. package/dist/types/utils/schema/compatibility.d.ts +30 -0
  190. package/dist/types/utils/schema/dereference.d.ts +11 -0
  191. package/dist/types/utils/schema/draft.d.ts +10 -0
  192. package/dist/types/utils/schema/equality.d.ts +4 -0
  193. package/dist/types/utils/schema/fields.d.ts +49 -0
  194. package/dist/types/utils/schema/index.d.ts +14 -0
  195. package/dist/types/utils/schema/json-schema-validator.d.ts +12 -0
  196. package/dist/types/utils/schema/meta-validator.d.ts +2 -0
  197. package/dist/types/utils/schema/normalize.d.ts +93 -0
  198. package/dist/types/utils/schema/root-combinator.d.ts +12 -0
  199. package/dist/types/utils/schema/spill.d.ts +8 -0
  200. package/dist/types/utils/schema/stamps.d.ts +25 -0
  201. package/dist/types/utils/schema/types.d.ts +4 -0
  202. package/dist/types/utils/schema/wire.d.ts +54 -0
  203. package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
  204. package/dist/types/utils/sse-debug.d.ts +10 -0
  205. package/dist/types/utils/tool-call-healing.d.ts +80 -0
  206. package/dist/types/utils/tool-choice-capability.d.ts +57 -0
  207. package/dist/types/utils/tool-choice.d.ts +50 -0
  208. package/dist/types/utils/validation.d.ts +17 -0
  209. package/dist/types/utils.d.ts +117 -0
  210. package/package.json +152 -0
  211. package/src/adapter-internals/provider-safety-stop.d.ts +45 -0
  212. package/src/adapter-internals/provider-safety-stop.ts +156 -0
  213. package/src/api-registry.d.ts +30 -0
  214. package/src/api-registry.ts +96 -0
  215. package/src/auth-broker/client.ts +444 -0
  216. package/src/auth-broker/index.ts +5 -0
  217. package/src/auth-broker/redact.ts +39 -0
  218. package/src/auth-broker/refresher.ts +130 -0
  219. package/src/auth-broker/remote-store.ts +1576 -0
  220. package/src/auth-broker/server.ts +764 -0
  221. package/src/auth-broker/types.ts +164 -0
  222. package/src/auth-broker/wire-schemas.ts +261 -0
  223. package/src/auth-gateway/http.ts +198 -0
  224. package/src/auth-gateway/index.ts +3 -0
  225. package/src/auth-gateway/server.ts +1315 -0
  226. package/src/auth-gateway/types.ts +160 -0
  227. package/src/auth-storage.ts +7312 -0
  228. package/src/cli.ts +269 -0
  229. package/src/codex-tools.d.ts +4 -0
  230. package/src/codex-tools.ts +24 -0
  231. package/src/context-cap-policy.d.ts +68 -0
  232. package/src/context-cap-policy.ts +123 -0
  233. package/src/core.ts +44 -0
  234. package/src/index.ts +61 -0
  235. package/src/model-cache.ts +236 -0
  236. package/src/model-manager.ts +744 -0
  237. package/src/model-pricing.d.ts +3 -0
  238. package/src/model-pricing.ts +68 -0
  239. package/src/model-retirements.d.ts +6 -0
  240. package/src/model-retirements.ts +19 -0
  241. package/src/model-thinking.d.ts +100 -0
  242. package/src/model-thinking.ts +1054 -0
  243. package/src/models.d.ts +21 -0
  244. package/src/models.json +94672 -0
  245. package/src/models.json.d.ts +9 -0
  246. package/src/models.ts +126 -0
  247. package/src/openai-completions-compat.d.ts +34 -0
  248. package/src/openai-completions-compat.ts +383 -0
  249. package/src/prompts/composer-bash-policy-recovery.md +1 -0
  250. package/src/prompts/cursor-composer-bash-policy-recovery.md +1 -0
  251. package/src/prompts/cursor-composer-edit-discipline.md +7 -0
  252. package/src/prompts/turn-aborted-guidance.md +4 -0
  253. package/src/provider-details.ts +90 -0
  254. package/src/provider-models/bundled-references.ts +38 -0
  255. package/src/provider-models/descriptors.ts +392 -0
  256. package/src/provider-models/google.ts +92 -0
  257. package/src/provider-models/index.ts +5 -0
  258. package/src/provider-models/ollama.ts +159 -0
  259. package/src/provider-models/openai-compat.ts +2920 -0
  260. package/src/provider-models/special.ts +185 -0
  261. package/src/providers/amazon-bedrock.d.ts +60 -0
  262. package/src/providers/amazon-bedrock.ts +939 -0
  263. package/src/providers/anthropic-messages-server-schema.ts +229 -0
  264. package/src/providers/anthropic-messages-server.ts +839 -0
  265. package/src/providers/anthropic.d.ts +280 -0
  266. package/src/providers/anthropic.ts +4421 -0
  267. package/src/providers/aws-credential-config.d.ts +19 -0
  268. package/src/providers/aws-credential-config.ts +179 -0
  269. package/src/providers/aws-credentials.d.ts +43 -0
  270. package/src/providers/aws-credentials.ts +457 -0
  271. package/src/providers/aws-eventstream.d.ts +38 -0
  272. package/src/providers/aws-eventstream.ts +185 -0
  273. package/src/providers/aws-sigv4.d.ts +55 -0
  274. package/src/providers/aws-sigv4.ts +218 -0
  275. package/src/providers/azure-openai-responses.d.ts +22 -0
  276. package/src/providers/azure-openai-responses.ts +447 -0
  277. package/src/providers/composer-discipline.d.ts +32 -0
  278. package/src/providers/composer-discipline.ts +95 -0
  279. package/src/providers/cursor/client-version.d.ts +10 -0
  280. package/src/providers/cursor/client-version.ts +10 -0
  281. package/src/providers/cursor/exec-modern.d.ts +98 -0
  282. package/src/providers/cursor/exec-modern.ts +497 -0
  283. package/src/providers/cursor/gen/agent_pb.d.ts +16769 -0
  284. package/src/providers/cursor/gen/agent_pb.ts +19780 -0
  285. package/src/providers/cursor/proto/agent.proto +4533 -0
  286. package/src/providers/cursor/proto/buf.gen.yaml +6 -0
  287. package/src/providers/cursor/proto/buf.yaml +17 -0
  288. package/src/providers/cursor-pi-args.d.ts +119 -0
  289. package/src/providers/cursor-pi-args.ts +187 -0
  290. package/src/providers/cursor.d.ts +72 -0
  291. package/src/providers/cursor.ts +3396 -0
  292. package/src/providers/dashscope-token-plan-headers.d.ts +57 -0
  293. package/src/providers/dashscope-token-plan-headers.ts +84 -0
  294. package/src/providers/error-message.d.ts +27 -0
  295. package/src/providers/error-message.ts +21 -0
  296. package/src/providers/github-copilot-headers.d.ts +40 -0
  297. package/src/providers/github-copilot-headers.ts +140 -0
  298. package/src/providers/gitlab-duo.d.ts +27 -0
  299. package/src/providers/gitlab-duo.ts +393 -0
  300. package/src/providers/google-auth.d.ts +26 -0
  301. package/src/providers/google-auth.ts +262 -0
  302. package/src/providers/google-gemini-cli.d.ts +75 -0
  303. package/src/providers/google-gemini-cli.ts +969 -0
  304. package/src/providers/google-gemini-headers.d.ts +43 -0
  305. package/src/providers/google-gemini-headers.ts +100 -0
  306. package/src/providers/google-shared.d.ts +183 -0
  307. package/src/providers/google-shared.ts +1105 -0
  308. package/src/providers/google-types.d.ts +138 -0
  309. package/src/providers/google-types.ts +167 -0
  310. package/src/providers/google-vertex.d.ts +11 -0
  311. package/src/providers/google-vertex.ts +124 -0
  312. package/src/providers/google.d.ts +4 -0
  313. package/src/providers/google.ts +41 -0
  314. package/src/providers/grammar.d.ts +1 -0
  315. package/src/providers/grammar.ts +70 -0
  316. package/src/providers/kimi.d.ts +27 -0
  317. package/src/providers/kimi.ts +52 -0
  318. package/src/providers/kiro-api-key.d.ts +50 -0
  319. package/src/providers/kiro-api-key.ts +786 -0
  320. package/src/providers/kiro-codewhisperer.d.ts +11 -0
  321. package/src/providers/kiro-codewhisperer.ts +600 -0
  322. package/src/providers/mock.ts +526 -0
  323. package/src/providers/ollama.d.ts +41 -0
  324. package/src/providers/ollama.ts +645 -0
  325. package/src/providers/openai-anthropic-shim.d.ts +31 -0
  326. package/src/providers/openai-anthropic-shim.ts +156 -0
  327. package/src/providers/openai-bounded-rate-limits.d.ts +3 -0
  328. package/src/providers/openai-bounded-rate-limits.ts +57 -0
  329. package/src/providers/openai-chat-server-schema.ts +254 -0
  330. package/src/providers/openai-chat-server.ts +724 -0
  331. package/src/providers/openai-codex/constants.d.ts +26 -0
  332. package/src/providers/openai-codex/constants.ts +43 -0
  333. package/src/providers/openai-codex/request-transformer.d.ts +50 -0
  334. package/src/providers/openai-codex/request-transformer.ts +219 -0
  335. package/src/providers/openai-codex/response-handler.d.ts +18 -0
  336. package/src/providers/openai-codex/response-handler.ts +111 -0
  337. package/src/providers/openai-codex-responses.d.ts +71 -0
  338. package/src/providers/openai-codex-responses.ts +3288 -0
  339. package/src/providers/openai-completions-compat.d.ts +6 -0
  340. package/src/providers/openai-completions-compat.ts +6 -0
  341. package/src/providers/openai-completions.d.ts +35 -0
  342. package/src/providers/openai-completions.ts +2294 -0
  343. package/src/providers/openai-opencodex-responses.ts +174 -0
  344. package/src/providers/openai-request-transform.d.ts +4 -0
  345. package/src/providers/openai-request-transform.ts +136 -0
  346. package/src/providers/openai-responses-server-schema.ts +290 -0
  347. package/src/providers/openai-responses-server.ts +1268 -0
  348. package/src/providers/openai-responses-shared.d.ts +106 -0
  349. package/src/providers/openai-responses-shared.ts +1253 -0
  350. package/src/providers/openai-responses.d.ts +37 -0
  351. package/src/providers/openai-responses.ts +989 -0
  352. package/src/providers/pi-native-client.d.ts +29 -0
  353. package/src/providers/pi-native-client.ts +243 -0
  354. package/src/providers/pi-native-server.ts +488 -0
  355. package/src/providers/register-builtins.d.ts +59 -0
  356. package/src/providers/register-builtins.ts +544 -0
  357. package/src/providers/synthetic.d.ts +26 -0
  358. package/src/providers/synthetic.ts +50 -0
  359. package/src/providers/transform-messages.d.ts +33 -0
  360. package/src/providers/transform-messages.ts +408 -0
  361. package/src/providers/vision-guard.d.ts +8 -0
  362. package/src/providers/vision-guard.ts +31 -0
  363. package/src/rate-limit-utils.d.ts +19 -0
  364. package/src/rate-limit-utils.ts +102 -0
  365. package/src/stream.d.ts +45 -0
  366. package/src/stream.ts +1306 -0
  367. package/src/types.d.ts +1073 -0
  368. package/src/types.ts +1305 -0
  369. package/src/usage/claude.ts +449 -0
  370. package/src/usage/gemini.ts +250 -0
  371. package/src/usage/github-copilot.ts +421 -0
  372. package/src/usage/google-antigravity.ts +201 -0
  373. package/src/usage/grok-cli.ts +259 -0
  374. package/src/usage/kimi.ts +285 -0
  375. package/src/usage/minimax-code.ts +31 -0
  376. package/src/usage/openai-codex.ts +503 -0
  377. package/src/usage/shared.ts +10 -0
  378. package/src/usage/zai.ts +247 -0
  379. package/src/usage.ts +190 -0
  380. package/src/utils/abort.d.ts +19 -0
  381. package/src/utils/abort.ts +51 -0
  382. package/src/utils/anthropic-auth.ts +95 -0
  383. package/src/utils/block-symbols.d.ts +6 -0
  384. package/src/utils/block-symbols.ts +11 -0
  385. package/src/utils/discovery/antigravity.ts +275 -0
  386. package/src/utils/discovery/codex.ts +362 -0
  387. package/src/utils/discovery/cursor.ts +388 -0
  388. package/src/utils/discovery/gemini.ts +248 -0
  389. package/src/utils/discovery/index.ts +4 -0
  390. package/src/utils/discovery/openai-compatible.ts +379 -0
  391. package/src/utils/event-stream.d.ts +41 -0
  392. package/src/utils/event-stream.ts +269 -0
  393. package/src/utils/fallback-transport.d.ts +110 -0
  394. package/src/utils/fallback-transport.ts +411 -0
  395. package/src/utils/fireworks-model-id.d.ts +10 -0
  396. package/src/utils/fireworks-model-id.ts +30 -0
  397. package/src/utils/foundry.d.ts +11 -0
  398. package/src/utils/foundry.ts +18 -0
  399. package/src/utils/h2-fetch.ts +60 -0
  400. package/src/utils/http-inspector.d.ts +59 -0
  401. package/src/utils/http-inspector.ts +380 -0
  402. package/src/utils/idle-iterator.d.ts +122 -0
  403. package/src/utils/idle-iterator.ts +410 -0
  404. package/src/utils/json-parse.d.ts +98 -0
  405. package/src/utils/json-parse.ts +607 -0
  406. package/src/utils/oauth/alibaba-token-plan.ts +60 -0
  407. package/src/utils/oauth/anthropic.ts +233 -0
  408. package/src/utils/oauth/api-key-login.ts +98 -0
  409. package/src/utils/oauth/api-key-validation.ts +344 -0
  410. package/src/utils/oauth/bizrouter.ts +15 -0
  411. package/src/utils/oauth/callback-server.d.ts +80 -0
  412. package/src/utils/oauth/callback-server.ts +359 -0
  413. package/src/utils/oauth/cerebras.ts +16 -0
  414. package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
  415. package/src/utils/oauth/commandcode.ts +17 -0
  416. package/src/utils/oauth/cursor.ts +157 -0
  417. package/src/utils/oauth/deepinfra.ts +15 -0
  418. package/src/utils/oauth/deepseek.ts +53 -0
  419. package/src/utils/oauth/firepass.ts +24 -0
  420. package/src/utils/oauth/fireworks.ts +15 -0
  421. package/src/utils/oauth/fugu.ts +15 -0
  422. package/src/utils/oauth/github-copilot.d.ts +38 -0
  423. package/src/utils/oauth/github-copilot.ts +362 -0
  424. package/src/utils/oauth/gitlab-duo.ts +123 -0
  425. package/src/utils/oauth/glm-zcode.d.ts +71 -0
  426. package/src/utils/oauth/glm-zcode.ts +433 -0
  427. package/src/utils/oauth/google-antigravity.ts +200 -0
  428. package/src/utils/oauth/google-gemini-cli.ts +256 -0
  429. package/src/utils/oauth/google-oauth-shared.ts +110 -0
  430. package/src/utils/oauth/huggingface.ts +62 -0
  431. package/src/utils/oauth/index.ts +558 -0
  432. package/src/utils/oauth/kagi.ts +47 -0
  433. package/src/utils/oauth/kilo.ts +87 -0
  434. package/src/utils/oauth/kimi.d.ts +17 -0
  435. package/src/utils/oauth/kimi.ts +275 -0
  436. package/src/utils/oauth/kiro.ts +448 -0
  437. package/src/utils/oauth/litellm.ts +47 -0
  438. package/src/utils/oauth/lm-studio.ts +38 -0
  439. package/src/utils/oauth/mara.ts +16 -0
  440. package/src/utils/oauth/minimax-code.ts +78 -0
  441. package/src/utils/oauth/moonshot.ts +16 -0
  442. package/src/utils/oauth/nanogpt.ts +15 -0
  443. package/src/utils/oauth/nvidia.ts +70 -0
  444. package/src/utils/oauth/oauth.html +199 -0
  445. package/src/utils/oauth/ollama-cloud.ts +28 -0
  446. package/src/utils/oauth/ollama.ts +47 -0
  447. package/src/utils/oauth/openai-codex.ts +299 -0
  448. package/src/utils/oauth/opencode.ts +49 -0
  449. package/src/utils/oauth/opengateway.ts +15 -0
  450. package/src/utils/oauth/openrouter.ts +16 -0
  451. package/src/utils/oauth/parallel.ts +46 -0
  452. package/src/utils/oauth/perplexity.ts +225 -0
  453. package/src/utils/oauth/pkce.ts +18 -0
  454. package/src/utils/oauth/qianfan.ts +58 -0
  455. package/src/utils/oauth/qwen-portal.ts +60 -0
  456. package/src/utils/oauth/sglang.ts +42 -0
  457. package/src/utils/oauth/synthetic.ts +15 -0
  458. package/src/utils/oauth/tavily.ts +46 -0
  459. package/src/utils/oauth/together.ts +16 -0
  460. package/src/utils/oauth/types.d.ts +56 -0
  461. package/src/utils/oauth/types.ts +122 -0
  462. package/src/utils/oauth/venice.ts +59 -0
  463. package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
  464. package/src/utils/oauth/vllm.ts +42 -0
  465. package/src/utils/oauth/xai.ts +246 -0
  466. package/src/utils/oauth/xiaomi.ts +199 -0
  467. package/src/utils/oauth/zai.ts +60 -0
  468. package/src/utils/oauth/zenmux.ts +15 -0
  469. package/src/utils/overflow.ts +275 -0
  470. package/src/utils/parse-bind.ts +81 -0
  471. package/src/utils/provider-response.d.ts +6 -0
  472. package/src/utils/provider-response.ts +30 -0
  473. package/src/utils/provider-safety-stop.ts +8 -0
  474. package/src/utils/proxy.d.ts +7 -0
  475. package/src/utils/proxy.ts +652 -0
  476. package/src/utils/retry-after.d.ts +3 -0
  477. package/src/utils/retry-after.ts +110 -0
  478. package/src/utils/retry-budget.d.ts +1 -0
  479. package/src/utils/retry-budget.ts +4 -0
  480. package/src/utils/retry.d.ts +29 -0
  481. package/src/utils/retry.ts +67 -0
  482. package/src/utils/schema/CONSTRAINTS.md +164 -0
  483. package/src/utils/schema/adapt.d.ts +24 -0
  484. package/src/utils/schema/adapt.ts +36 -0
  485. package/src/utils/schema/compatibility.d.ts +30 -0
  486. package/src/utils/schema/compatibility.ts +435 -0
  487. package/src/utils/schema/dereference.d.ts +11 -0
  488. package/src/utils/schema/dereference.ts +98 -0
  489. package/src/utils/schema/draft.d.ts +10 -0
  490. package/src/utils/schema/draft.ts +341 -0
  491. package/src/utils/schema/equality.d.ts +4 -0
  492. package/src/utils/schema/equality.ts +97 -0
  493. package/src/utils/schema/fields.d.ts +49 -0
  494. package/src/utils/schema/fields.ts +190 -0
  495. package/src/utils/schema/index.d.ts +14 -0
  496. package/src/utils/schema/index.ts +14 -0
  497. package/src/utils/schema/json-schema-validator.d.ts +12 -0
  498. package/src/utils/schema/json-schema-validator.ts +577 -0
  499. package/src/utils/schema/meta-validator.d.ts +2 -0
  500. package/src/utils/schema/meta-validator.ts +167 -0
  501. package/src/utils/schema/normalize.d.ts +93 -0
  502. package/src/utils/schema/normalize.ts +1588 -0
  503. package/src/utils/schema/root-combinator.d.ts +12 -0
  504. package/src/utils/schema/root-combinator.ts +143 -0
  505. package/src/utils/schema/spill.d.ts +8 -0
  506. package/src/utils/schema/spill.ts +43 -0
  507. package/src/utils/schema/stamps.d.ts +25 -0
  508. package/src/utils/schema/stamps.ts +97 -0
  509. package/src/utils/schema/types.d.ts +4 -0
  510. package/src/utils/schema/types.ts +11 -0
  511. package/src/utils/schema/wire.d.ts +54 -0
  512. package/src/utils/schema/wire.ts +213 -0
  513. package/src/utils/schema/zod-decontaminate.d.ts +31 -0
  514. package/src/utils/schema/zod-decontaminate.ts +331 -0
  515. package/src/utils/sse-debug.d.ts +10 -0
  516. package/src/utils/sse-debug.ts +289 -0
  517. package/src/utils/tool-call-healing.d.ts +80 -0
  518. package/src/utils/tool-call-healing.ts +298 -0
  519. package/src/utils/tool-choice-capability.d.ts +57 -0
  520. package/src/utils/tool-choice-capability.ts +633 -0
  521. package/src/utils/tool-choice.d.ts +50 -0
  522. package/src/utils/tool-choice.ts +99 -0
  523. package/src/utils/validation.ts +1080 -0
  524. package/src/utils.d.ts +117 -0
  525. package/src/utils.ts +523 -0
@@ -0,0 +1,1073 @@
1
+ import type { ZodType, z } from "zod/v4";
2
+ import type { BedrockOptions } from "./providers/amazon-bedrock";
3
+ import type { AnthropicOptions } from "./providers/anthropic";
4
+ import type { AzureOpenAIResponsesOptions } from "./providers/azure-openai-responses";
5
+ import type { CursorOptions } from "./providers/cursor";
6
+ import type { DeleteArgs, DeleteResult, DiagnosticsArgs, DiagnosticsResult, GrepArgs, GrepResult, LsArgs, LsResult, McpResult, PiBashExecArgs, PiBashExecResult, PiEditExecArgs, PiEditExecResult, PiFindExecArgs, PiFindExecResult, PiGrepExecArgs, PiGrepExecResult, PiLsExecArgs, PiLsExecResult, PiReadExecArgs, PiReadExecResult, PiWriteExecArgs, PiWriteExecResult, ReadArgs, ReadResult, ShellArgs, ShellResult, WriteArgs, WriteResult } from "./providers/cursor/gen/agent_pb";
7
+ import type { GoogleOptions } from "./providers/google";
8
+ import type { GoogleGeminiCliOptions } from "./providers/google-gemini-cli";
9
+ import type { GoogleVertexOptions } from "./providers/google-vertex";
10
+ import type { KiroCodeWhispererOptions } from "./providers/kiro-codewhisperer";
11
+ import type { OllamaChatOptions } from "./providers/ollama";
12
+ import type { OpenAICodexResponsesOptions } from "./providers/openai-codex-responses";
13
+ import type { OpenAICompletionsOptions } from "./providers/openai-completions";
14
+ import type { OpenAIResponsesOptions } from "./providers/openai-responses";
15
+ import type { AssistantMessageEventStream } from "./utils/event-stream";
16
+ import type { FallbackAttemptToken, TransportFailureFacts } from "./utils/fallback-transport";
17
+ import type { UnicodeEscapeEvidence } from "./utils/json-parse";
18
+ export type { AssistantMessageEventStream } from "./utils/event-stream";
19
+ export type KnownApi = "openai-completions" | "openai-responses" | "openai-codex-responses" | "azure-openai-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-gemini-cli" | "google-vertex" | "ollama-chat" | "cursor-agent" | "kiro-codewhisperer-stream";
20
+ export type Api = KnownApi | (string & {});
21
+ export interface ApiOptionsMap {
22
+ "anthropic-messages": AnthropicOptions;
23
+ "bedrock-converse-stream": BedrockOptions;
24
+ "openai-completions": OpenAICompletionsOptions;
25
+ "openai-responses": OpenAIResponsesOptions;
26
+ "openai-codex-responses": OpenAICodexResponsesOptions;
27
+ "azure-openai-responses": AzureOpenAIResponsesOptions;
28
+ "google-generative-ai": GoogleOptions;
29
+ "google-gemini-cli": GoogleGeminiCliOptions;
30
+ "google-vertex": GoogleVertexOptions;
31
+ "ollama-chat": OllamaChatOptions;
32
+ "cursor-agent": CursorOptions;
33
+ "kiro-codewhisperer-stream": KiroCodeWhispererOptions;
34
+ }
35
+ export type OptionsForApi<TApi extends Api> = StreamOptions | (TApi extends keyof ApiOptionsMap ? ApiOptionsMap[TApi] : never);
36
+ /** Canonical thinking transport used by a model. */
37
+ export type ThinkingControlMode = "effort" | "budget" | "google-level" | "anthropic-adaptive" | "anthropic-budget-effort";
38
+ /** Canonical runtime vocabulary for provider thinking transports. */
39
+ export declare const THINKING_CONTROL_MODES: readonly ["effort", "budget", "google-level", "anthropic-adaptive", "anthropic-budget-effort"];
40
+ /** Per-model thinking capabilities used to clamp and map user-facing effort levels. */
41
+ export interface ThinkingConfig {
42
+ /** Least intensive supported user-facing effort level. */
43
+ minLevel: Effort;
44
+ /** Most intensive supported user-facing effort level. */
45
+ maxLevel: Effort;
46
+ /**
47
+ * Optional explicit list of supported levels. When present, takes precedence over
48
+ * the `minLevel`..`maxLevel` range — used to encode discrete sets with gaps
49
+ * (e.g. Gemini 3 Pro supports `low` and `high` but not `medium`).
50
+ */
51
+ levels?: readonly Effort[];
52
+ /** Optional default effort applied when this model is selected. Falls back to global default if absent. */
53
+ defaultLevel?: Effort;
54
+ /** Provider-specific transport used to encode the selected effort. */
55
+ mode: ThinkingControlMode;
56
+ }
57
+ export declare const KNOWN_PROVIDERS: readonly ["alibaba-token-plan", "amazon-bedrock", "kiro", "azure-openai", "anthropic", "google", "google-gemini-cli", "google-antigravity", "google-vertex", "openai", "openai-codex", "opencodex", "kimi-code", "minimax-code", "minimax-code-cn", "github-copilot", "fireworks", "firepass", "fugu", "gitlab-duo", "cursor", "jetbrains-junie", "deepseek", "deepinfra", "xai", "groq", "cerebras", "openrouter", "kilo", "vercel-ai-gateway", "zai", "glm-zcode", "mistral", "minimax", "opencode-go", "commandcode-goat", "opencode-zen", "opengateway", "bizrouter", "mara", "synthetic", "cloudflare-ai-gateway", "huggingface", "litellm", "moonshot", "nvidia", "nanogpt", "ollama", "ollama-cloud", "qianfan", "qwen-portal", "sglang", "together", "venice", "vllm", "xiaomi", "xiaomi-token-plan-sgp", "xiaomi-token-plan-ams", "xiaomi-token-plan-cn", "zenmux", "lm-studio", "omlx"];
58
+ export type KnownProvider = (typeof KNOWN_PROVIDERS)[number];
59
+ export declare function isKnownProvider(provider: string): provider is KnownProvider;
60
+ export type Provider = KnownProvider | string;
61
+ import type { Effort } from "./model-thinking";
62
+ /** Token budgets for each thinking level (token-based providers only) */
63
+ export type ThinkingBudgets = {
64
+ [key in Effort]?: number;
65
+ };
66
+ export type MessageAttribution = "user" | "agent";
67
+ export type ToolChoice = "auto" | "none" | "any" | "required" | {
68
+ type: "function";
69
+ name: string;
70
+ } | {
71
+ type: "function";
72
+ function: {
73
+ name: string;
74
+ };
75
+ } | {
76
+ type: "tool";
77
+ name: string;
78
+ };
79
+ export type ToolChoiceSupport = "none" | "auto" | "required" | "named";
80
+ export type ToolChoiceSupportSource = "static" | "derived" | "runtime";
81
+ export interface ToolChoiceCompat {
82
+ /** Maximum supported tool_choice level. */
83
+ toolChoiceSupport?: ToolChoiceSupport;
84
+ /** Legacy flag for accepting the tool_choice parameter. */
85
+ supportsToolChoice?: boolean;
86
+ /** Legacy flag for forced tool_choice support. */
87
+ supportsForcedToolChoice?: boolean;
88
+ }
89
+ export type CacheRetention = "none" | "short" | "long";
90
+ /**
91
+ * Service tier hint for processing priority / cost control.
92
+ *
93
+ * The unscoped values (`"auto"`, `"default"`, `"flex"`, `"scale"`,
94
+ * `"priority"`) are passed through to providers that understand them
95
+ * (OpenAI and DeepInfra's `service_tier` field directly; Anthropic translates
96
+ * `"priority"` into `speed: "fast"` on supported Opus models).
97
+ *
98
+ * The scoped values target a specific provider family and behave as the
99
+ * unscoped value on the matching provider, or `undefined` everywhere else.
100
+ * They let users opt into priority on one family without paying premium
101
+ * costs on the other when switching models mid-session.
102
+ *
103
+ * - `"openai-only"` → `"priority"` on `openai` and `OpenAI code provider`; ignored elsewhere.
104
+ * - `"Anthropic model-only"` → `"priority"` on direct `anthropic` (not Bedrock/Vertex Anthropic model).
105
+ */
106
+ export type ServiceTier = "auto" | "default" | "flex" | "scale" | "priority" | "openai-only" | "claude-only";
107
+ /** Resolved tier — one of the values that providers actually consume on the wire. */
108
+ export type ResolvedServiceTier = Exclude<ServiceTier, "openai-only" | "claude-only">;
109
+ /**
110
+ * Resolves a possibly scoped `ServiceTier` to the effective tier for the
111
+ * given provider. Scoped values match their target family and otherwise
112
+ * collapse to `undefined`; unscoped values pass through unchanged.
113
+ */
114
+ export declare function resolveServiceTier(serviceTier: ServiceTier | null | undefined, provider: Provider | undefined): ResolvedServiceTier | undefined;
115
+ /**
116
+ * True when the (possibly scoped) tier should be sent as an OpenAI-compatible
117
+ * `service_tier` request field. Custom providers must explicitly opt in through
118
+ * `compat.supportsServiceTier`; unknown providers remain fail-closed.
119
+ */
120
+ export declare function shouldSendServiceTier(serviceTier: ServiceTier | null | undefined, provider: Provider | undefined, supportsServiceTier?: boolean): boolean;
121
+ /**
122
+ * True when a priority tier is realized as a fast-mode request on the provider's
123
+ * wire protocol. Custom OpenAI-compatible proxies opt in explicitly rather than
124
+ * inheriting support merely because their API shape resembles OpenAI.
125
+ */
126
+ export declare function isFastModeEffectiveForProvider(serviceTier: ServiceTier | null | undefined, provider: Provider | undefined, supportsServiceTier?: boolean): boolean;
127
+ /**
128
+ * Premium-request weight contributed by sending priority to a provider
129
+ * that supports it. Mirrors GitHub Copilot's `premiumRequests` accounting
130
+ * so the "premium requests" stat aggregates priority traffic across the
131
+ * OpenAI family and Anthropic fast-mode realizations.
132
+ *
133
+ * Returns 1 per resolved priority request, 0 otherwise.
134
+ */
135
+ export declare function getPriorityPremiumRequests(serviceTier: ServiceTier | null | undefined, provider: Provider | undefined): number;
136
+ export interface ProviderSessionState {
137
+ close(): void;
138
+ }
139
+ export interface ProviderResponseMetadata {
140
+ status: number;
141
+ headers: Record<string, string>;
142
+ requestId?: string | null;
143
+ metadata?: Record<string, unknown>;
144
+ }
145
+ export interface RawSseEvent {
146
+ event: string | null;
147
+ data: string;
148
+ raw: string[];
149
+ }
150
+ /**
151
+ * `fetch`-compatible function. Accepts any callable matching the standard
152
+ * fetch signature; `preconnect` is optional because non-Bun runtimes (browsers,
153
+ * test mocks) won't expose it.
154
+ */
155
+ export type FetchImpl = ((input: string | URL | Request, init?: RequestInit) => Promise<Response>) & {
156
+ preconnect?: typeof globalThis.fetch.preconnect;
157
+ };
158
+ /**
159
+ * Credential returned by an auth retry resolver.
160
+ *
161
+ * The optional admission callback lets an authority-bearing caller retain a
162
+ * credential lease until the replacement provider request is actually
163
+ * admitted. Ordinary callers can continue returning a string from
164
+ * {@link StreamOptions.onAuthError}.
165
+ */
166
+ export interface AuthRetryCredential {
167
+ apiKey: string;
168
+ onStreamCreated?: () => void;
169
+ }
170
+ export interface StreamOptions {
171
+ temperature?: number;
172
+ topP?: number;
173
+ topK?: number;
174
+ minP?: number;
175
+ presencePenalty?: number;
176
+ repetitionPenalty?: number;
177
+ /**
178
+ * Stop sequences. Anthropic encodes as `stop_sequences` (array, max 4);
179
+ * OpenAI chat-completions encodes as `stop` (string or array of up to 4);
180
+ * OpenAI Responses API has no `stop` field today (silently dropped by the
181
+ * provider when present).
182
+ */
183
+ stopSequences?: string[];
184
+ /**
185
+ * Frequency penalty (OpenAI). Penalizes new tokens based on existing frequency
186
+ * in the text so far. Range -2.0 to 2.0. Parallel to {@link presencePenalty}.
187
+ */
188
+ frequencyPenalty?: number;
189
+ maxTokens?: number;
190
+ signal?: AbortSignal;
191
+ apiKey?: string;
192
+ /** Disables all transport-level replay; the fallback controller owns retries. */
193
+ fallbackManaged?: boolean;
194
+ /** Opaque token returned by beginAttempt for a managed transport invocation. */
195
+ fallbackAttempt?: FallbackAttemptToken;
196
+ /**
197
+ * Called when a provider returns 401 before any replay-unsafe assistant
198
+ * event has been emitted. Returning a different key retries the provider
199
+ * request once.
200
+ */
201
+ onAuthError?: (provider: string, apiKey: string, error: unknown) => Promise<string | AuthRetryCredential | undefined>;
202
+ cacheRetention?: CacheRetention;
203
+ /**
204
+ * Additional headers to include in provider requests.
205
+ * These are merged on top of model-defined headers.
206
+ */
207
+ headers?: Record<string, string>;
208
+ /**
209
+ * Optional explicit request attribution override for providers that support it.
210
+ */
211
+ initiatorOverride?: MessageAttribution;
212
+ /**
213
+ * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.
214
+ * If the server's requested delay exceeds this value, the request fails immediately
215
+ * with an error containing the requested delay, allowing higher-level retry logic
216
+ * to handle it with user visibility.
217
+ * Default: 60000 (60 seconds). Set to 0 to disable the cap.
218
+ */
219
+ maxRetryDelayMs?: number;
220
+ /**
221
+ * Maximum provider request retries for transports/SDKs that retry before a stream is established.
222
+ * Counts retries only, not the initial attempt. Providers keep their built-in default when unset.
223
+ */
224
+ requestMaxRetries?: number;
225
+ /**
226
+ * Maximum provider stream replay retries after a replay-safe transient stream failure.
227
+ * Counts retries only, not the initial stream attempt. Providers keep their built-in default when unset.
228
+ */
229
+ streamMaxRetries?: number;
230
+ /**
231
+ * Optional metadata to include in API requests.
232
+ * Providers extract the fields they understand and ignore the rest.
233
+ * For example, Anthropic uses `user_id` for abuse tracking and rate limiting.
234
+ */
235
+ metadata?: Record<string, unknown>;
236
+ /**
237
+ * Optional session identifier for providers that support session-based caching.
238
+ * Providers can use this to enable prompt caching, request routing, or other
239
+ * session-aware features. Ignored by providers that don't support it.
240
+ */
241
+ sessionId?: string;
242
+ /**
243
+ * Provider-scoped mutable state store for this agent session.
244
+ * Providers can use this to persist transport/session state between turns.
245
+ */
246
+ providerSessionState?: Map<string, ProviderSessionState>;
247
+ /**
248
+ * Optional callback for inspecting or replacing provider payloads before sending.
249
+ * Return undefined to keep the payload unchanged.
250
+ * The `scope` parameter carries the per-attempt identity for execution attribution.
251
+ */
252
+ onPayload?: (payload: unknown, model?: Model<Api>, scope?: AttemptScopeRef) => unknown | undefined | Promise<unknown | undefined>;
253
+ /**
254
+ * Optional callback for provider response metadata after headers are received.
255
+ * The `scope` parameter carries the per-attempt identity for execution attribution.
256
+ */
257
+ onResponse?: (response: ProviderResponseMetadata, model?: Model<Api>, scope?: AttemptScopeRef) => void | Promise<void>;
258
+ /**
259
+ * Internal dispatch-admission hook. Providers invoke this immediately before
260
+ * submitting an outbound request; stream forwarding retains a first-response
261
+ * fallback for custom providers that do not expose a transport seam.
262
+ */
263
+ onStreamCreated?: () => void;
264
+ /** Internal authority policy: disable provider-owned retries and corrective replays. */
265
+ disableProviderRetries?: boolean;
266
+ /**
267
+ * Optional callback for raw Server-Sent Events as they arrive from HTTP streaming providers.
268
+ *
269
+ * Diagnostic only: provider implementations must ignore callback failures and must not
270
+ * let observers alter stream contents.
271
+ */
272
+ onSseEvent?: (event: RawSseEvent, model?: Model<Api>, scope?: AttemptScopeRef) => void;
273
+ /**
274
+ * Optional override for the first streamed event watchdog in milliseconds.
275
+ * Set to 0 to disable the first-event watchdog for this request.
276
+ */
277
+ streamFirstEventTimeoutMs?: number;
278
+ /**
279
+ * Optional override for the maximum idle gap between streamed events in milliseconds.
280
+ * Set to 0 to disable the inter-event idle watchdog for this request.
281
+ */
282
+ streamIdleTimeoutMs?: number;
283
+ /**
284
+ * Optional retry delay hook for tests and transports that need custom scheduling.
285
+ */
286
+ providerRetryWait?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
287
+ /**
288
+ * Optional `fetch` implementation override. Providers route every HTTP
289
+ * request — direct calls, SDK clients, and retry helpers — through this
290
+ * implementation when set. Defaults to `globalThis.fetch`. Providers that
291
+ * do not use `fetch` (Bedrock's AWS SDK transport, Cursor's HTTP/2
292
+ * channel) silently ignore the override.
293
+ */
294
+ fetch?: FetchImpl;
295
+ /**
296
+ * Authentication credential type selected for this request.
297
+ * Providers use this only when endpoint routing differs between API-key and OAuth credentials.
298
+ */
299
+ authCredentialType?: "api_key" | "oauth";
300
+ /** Cursor exec/MCP tool handlers (cursor-agent only). */
301
+ execHandlers?: CursorExecHandlers;
302
+ /** Per-attempt identity for execution attribution. Threaded into onPayload/onResponse calls. */
303
+ attemptScope?: AttemptScopeRef;
304
+ }
305
+ /**
306
+ * Low-level structural carrier for per-attempt identity attribution.
307
+ *
308
+ * Defined in `packages/ai` so that {@link SimpleStreamOptions} and provider
309
+ * hook signatures can carry an attempt identity without a reverse dependency
310
+ * on `packages/agent`. The concrete `AttemptScope` in `packages/agent` is
311
+ * structurally assignable to this interface (same `attemptId` + `generation`
312
+ * + `lineage` fields).
313
+ */
314
+ export interface AttemptScopeRef {
315
+ readonly attemptId: string;
316
+ readonly generation: number;
317
+ readonly lineage: string;
318
+ }
319
+ export interface SimpleStreamOptions extends StreamOptions {
320
+ reasoning?: Effort;
321
+ /**
322
+ * Force-disable reasoning for the request even when the model supports it.
323
+ * Takes precedence over `reasoning`. Useful for fast utility calls
324
+ * (e.g. title generation) where the model would otherwise burn the entire
325
+ * output budget on internal thinking. Provider support is format-specific:
326
+ * some transports can disable reasoning directly, while generic
327
+ * effort-based OpenAI-compatible endpoints use the lowest supported effort.
328
+ */
329
+ disableReasoning?: boolean;
330
+ /**
331
+ * If true, request that the provider omit thinking/reasoning summaries
332
+ * from the response (e.g. Anthropic `thinking.display = "omitted"`,
333
+ * OpenAI Responses `reasoning.summary` left unset). The model still
334
+ * reasons internally; only the human-readable summary stream is dropped.
335
+ * Useful when the UI hides thinking blocks anyway and the summary is wasted bandwidth.
336
+ */
337
+ hideThinkingSummary?: boolean;
338
+ /** Custom token budgets for thinking levels (token-based providers only) */
339
+ thinkingBudgets?: ThinkingBudgets;
340
+ /** Cursor exec handlers for local tool execution */
341
+ cursorExecHandlers?: CursorExecHandlers;
342
+ /** Hook to handle tool results from Cursor exec */
343
+ cursorOnToolResult?: CursorToolResultHandler;
344
+ /** Optional tool choice override for compatible providers */
345
+ toolChoice?: ToolChoice;
346
+ /** OpenAI service tier for processing priority/cost control. Ignored by non-OpenAI providers. */
347
+ serviceTier?: ServiceTier;
348
+ /** API format for Kimi Code provider: "openai" or "anthropic" (default: "anthropic") */
349
+ kimiApiFormat?: "openai" | "anthropic";
350
+ /** API format for Synthetic provider: "openai" or "anthropic" (default: "openai") */
351
+ syntheticApiFormat?: "openai" | "anthropic";
352
+ /** Hint that websocket transport should be preferred when supported by the provider implementation. */
353
+ preferWebsockets?: boolean;
354
+ }
355
+ export type StreamFunction<TApi extends Api> = (model: Model<TApi>, context: Context, options: OptionsForApi<TApi>) => AssistantMessageEventStream;
356
+ export interface TextSignatureV1 {
357
+ v: 1;
358
+ id: string;
359
+ phase?: "commentary" | "final_answer";
360
+ }
361
+ export interface TextContent {
362
+ type: "text";
363
+ text: string;
364
+ textSignature?: string;
365
+ }
366
+ export interface ThinkingContent {
367
+ type: "thinking";
368
+ thinking: string;
369
+ thinkingSignature?: string;
370
+ itemId?: string;
371
+ readonly provenance?: "summary" | "raw" | "mixed";
372
+ readonly summaryText?: string;
373
+ readonly rawText?: string;
374
+ }
375
+ export interface RedactedThinkingContent {
376
+ type: "redactedThinking";
377
+ data: string;
378
+ }
379
+ export interface ImageContent {
380
+ type: "image";
381
+ data: string;
382
+ mimeType: string;
383
+ }
384
+ export interface ToolCall {
385
+ type: "toolCall";
386
+ id: string;
387
+ name: string;
388
+ arguments: Record<string, any>;
389
+ thoughtSignature?: string;
390
+ intent?: string;
391
+ /**
392
+ * Original wire-level name when the tool was invoked via OpenAI's custom-tool
393
+ * mechanism (e.g., `apply_patch`). Set by `openai-responses` on receive so
394
+ * the history-replay path can re-emit the call as `custom_tool_call` with
395
+ * its paired tool-result as `custom_tool_call_output`. Absent for regular
396
+ * JSON function tools.
397
+ */
398
+ customWireName?: string;
399
+ /**
400
+ * Set when the provider detected the argument JSON was not safely executable —
401
+ * the model hit its output-token limit (or the response was otherwise cut short)
402
+ * before emitting a complete arguments object, the terminal payload was malformed,
403
+ * the streamed and terminal payloads conflicted, or the tool-call identity was
404
+ * ambiguous on the wire. The `arguments` field then holds a best-effort partial
405
+ * parse and must not be executed as-is; the agent loop rejects the call with a
406
+ * retryable, reason-specific error instead.
407
+ */
408
+ incompleteArguments?: boolean;
409
+ /**
410
+ * When `incompleteArguments` is set, the typed cause so the agent loop can give
411
+ * reason-specific recovery guidance:
412
+ * - `"truncated"`: the response was cut short mid-arguments (output-token limit).
413
+ * - `"malformed"`: the terminal arguments did not decode to a valid JSON object.
414
+ * - `"conflicting"`: the streamed and terminal argument payloads disagree.
415
+ * - `"ambiguous"`: the tool-call identity could not be unambiguously resolved
416
+ * (duplicate `call_id`, id/call_id collision, etc.), so attribution is unsafe.
417
+ * Absent when `incompleteArguments` is not set. Existing callers that read only
418
+ * `incompleteArguments` continue to work.
419
+ */
420
+ incompleteArgumentsReason?: "truncated" | "malformed" | "conflicting" | "ambiguous";
421
+ /**
422
+ * Set by current producers when raw argument JSON carries unsafe Unicode
423
+ * data, such as malformed escape evidence or a decoded unpaired surrogate.
424
+ * Valid JSON `\uXXXX` escapes are canonical spellings of the decoded string
425
+ * and current producers do not set this flag for them.
426
+ *
427
+ * Legacy producers may still set the flag for any escaped non-ASCII spelling.
428
+ * The agent loop keeps its bounded legacy resample/display-safe behavior for
429
+ * those calls while consuming the transient evidence below.
430
+ */
431
+ escapedNonAsciiArguments?: boolean;
432
+ /**
433
+ * Bounded, payload-free evidence for raw Unicode argument data. Current
434
+ * producers attach it only for unsafe data; legacy producers may attach
435
+ * non-malformed positional evidence used by the display-safe compatibility
436
+ * path. The agent consumes and removes this transient field before the
437
+ * tool-call message can become durable.
438
+ */
439
+ escapedUnicodeArgumentEvidence?: UnicodeEscapeEvidence;
440
+ }
441
+ export interface Usage {
442
+ /** Non-cached input tokens (matches the bucket the provider bills as new input). */
443
+ input: number;
444
+ /** Total output tokens for the turn, including thinking, assistant text, and tool-call argument tokens. */
445
+ output: number;
446
+ /** Tokens read from the prompt cache. */
447
+ cacheRead: number;
448
+ /** Tokens written to the prompt cache (cache creation). */
449
+ cacheWrite: number;
450
+ /** Sum of input + output + cacheRead + cacheWrite. */
451
+ totalTokens: number;
452
+ /** Copilot premium-request counter, when applicable. */
453
+ premiumRequests?: number;
454
+ /**
455
+ * Reasoning/thinking tokens included in `output`, when the provider reports them
456
+ * (OpenAI `output_tokens_details.reasoning_tokens`, Google `thoughtsTokenCount`).
457
+ * Always a subset of `output` — non-reasoning output is `output - reasoningTokens`.
458
+ *
459
+ * Providers that don't expose this leave it undefined rather than guessing;
460
+ * `undefined` means unknown, NOT zero.
461
+ */
462
+ reasoningTokens?: number;
463
+ /**
464
+ * Cache-write TTL breakdown (Anthropic only). When set, the components sum to
465
+ * `cacheWrite`. Absent providers do not populate this.
466
+ */
467
+ cttl?: {
468
+ ephemeral5m?: number;
469
+ ephemeral1h?: number;
470
+ };
471
+ /**
472
+ * Server-side tool invocations made during this turn (Anthropic web_search /
473
+ * web_fetch, OpenAI built-in tools when reported). Counts requests, not tokens.
474
+ */
475
+ server?: {
476
+ webSearch?: number;
477
+ webFetch?: number;
478
+ };
479
+ cost: {
480
+ input: number;
481
+ output: number;
482
+ cacheRead: number;
483
+ cacheWrite: number;
484
+ total: number;
485
+ };
486
+ }
487
+ export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
488
+ export type AssistantErrorKind = "provider_safety_stop" | "local_snapshot_failure" | "local_buffer_overflow";
489
+ /**
490
+ * Structured, shape-only staging-buffer overflow diagnostic carried on the
491
+ * terminal `AssistantMessage`. Attached only by the agent runtime from its own
492
+ * identity-checked overflow error; every field is a closed vocabulary literal
493
+ * or a locally synthesized number.
494
+ */
495
+ export interface AssistantBufferOverflowDiagnostic {
496
+ /** Rejecting stage from the closed managed-local-failure vocabulary. */
497
+ stage: string;
498
+ /** Which provisional cap tripped. */
499
+ exceeded: "events" | "bytes" | "both";
500
+ /** Events retained in the batch at rejection (post-compaction). */
501
+ stagedEventCount: number;
502
+ /** Bytes retained in the batch at rejection (post-compaction). */
503
+ stagedBytes: number;
504
+ /** Serialized size of the event that was rejected. */
505
+ incomingEventBytes: number;
506
+ maxStagedEvents: number;
507
+ maxStagedBytes: number;
508
+ }
509
+ export interface OpenAIResponsesHistoryPayload {
510
+ type: "openaiResponsesHistory";
511
+ provider?: string;
512
+ dt?: boolean;
513
+ items: Array<Record<string, unknown>>;
514
+ }
515
+ export type ProviderPayload = OpenAIResponsesHistoryPayload;
516
+ export interface UserMessage {
517
+ role: "user";
518
+ content: string | (TextContent | ImageContent)[];
519
+ /** True if the message was injected by the system (e.g., auto-continue). */
520
+ synthetic?: boolean;
521
+ /** Who initiated this message for billing/attribution semantics. */
522
+ attribution?: MessageAttribution;
523
+ /** Provider-specific opaque payload used to reconstruct transport-native history. */
524
+ providerPayload?: ProviderPayload;
525
+ timestamp: number;
526
+ }
527
+ export interface DeveloperMessage {
528
+ role: "developer";
529
+ content: string | (TextContent | ImageContent)[];
530
+ /** Who initiated this message for billing/attribution semantics. */
531
+ attribution?: MessageAttribution;
532
+ /** Provider-specific opaque payload used to reconstruct transport-native history. */
533
+ providerPayload?: ProviderPayload;
534
+ timestamp: number;
535
+ }
536
+ export interface AssistantMessage {
537
+ role: "assistant";
538
+ content: (TextContent | ThinkingContent | RedactedThinkingContent | ToolCall)[];
539
+ api: Api;
540
+ provider: Provider;
541
+ model: string;
542
+ responseId?: string;
543
+ usage: Usage;
544
+ stopReason: StopReason;
545
+ errorMessage?: string;
546
+ errorKind?: AssistantErrorKind;
547
+ /**
548
+ * Structured, shape-only diagnostic for a terminal local staging-buffer
549
+ * overflow (`errorKind: "local_buffer_overflow"`). Attached only by the
550
+ * agent runtime from its own identity-checked overflow error, so a
551
+ * foreign, self-labeled error cannot populate it. Every field is a closed
552
+ * vocabulary literal or a locally synthesized number — parent surfaces
553
+ * render this instead of trusting the free-form `errorMessage`.
554
+ */
555
+ bufferOverflow?: AssistantBufferOverflowDiagnostic;
556
+ /** HTTP status surfaced by the provider when the request failed. Populated by every provider's catch block alongside `errorMessage` so consumers (auth retry, telemetry, UI) can branch without regex-scraping the message. */
557
+ errorStatus?: number;
558
+ /** Typed upstream failure facts retained for retry classification without parsing errorMessage. */
559
+ transportFailure?: TransportFailureFacts;
560
+ /**
561
+ * Stable identifiers for request features the provider silently dropped
562
+ * during this turn (e.g. `"priority"`). Set when a server-side rejection
563
+ * triggered an in-provider fallback retry that succeeded without the
564
+ * feature. Callers can use this to sync user-facing toggles back to the
565
+ * server's actual state.
566
+ */
567
+ disabledFeatures?: string[];
568
+ /** Provider-specific opaque payload used to reconstruct transport-native history. */
569
+ providerPayload?: ProviderPayload;
570
+ timestamp: number;
571
+ duration?: number;
572
+ ttft?: number;
573
+ }
574
+ export interface ToolResultMessage<TDetails = any> {
575
+ role: "toolResult";
576
+ toolCallId: string;
577
+ toolName: string;
578
+ content: (TextContent | ImageContent)[];
579
+ details?: TDetails;
580
+ isError: boolean;
581
+ /** Who initiated this message for billing/attribution semantics. */
582
+ attribution?: MessageAttribution;
583
+ /** Timestamp when output was pruned (ms since epoch). Undefined if unpruned. */
584
+ prunedAt?: number;
585
+ timestamp: number;
586
+ }
587
+ export type Message = UserMessage | DeveloperMessage | AssistantMessage | ToolResultMessage;
588
+ export type CursorExecHandlerResult<T> = {
589
+ result: T;
590
+ toolResult?: ToolResultMessage;
591
+ } | T | ToolResultMessage;
592
+ export type CursorToolResultHandler = (result: ToolResultMessage) => ToolResultMessage | undefined | Promise<ToolResultMessage | undefined>;
593
+ export interface CursorMcpCall {
594
+ name: string;
595
+ providerIdentifier: string;
596
+ toolName: string;
597
+ toolCallId: string;
598
+ args: Record<string, unknown>;
599
+ rawArgs: Record<string, Uint8Array>;
600
+ }
601
+ export interface CursorShellStreamCallbacks {
602
+ onStdout(data: string): void;
603
+ onStderr(data: string): void;
604
+ }
605
+ export interface CursorPiCall<TArgs> {
606
+ args: TArgs;
607
+ toolCallId: string;
608
+ }
609
+ export interface CursorExecHandlers {
610
+ read?: (args: ReadArgs) => Promise<CursorExecHandlerResult<ReadResult>>;
611
+ ls?: (args: LsArgs) => Promise<CursorExecHandlerResult<LsResult>>;
612
+ grep?: (args: GrepArgs) => Promise<CursorExecHandlerResult<GrepResult>>;
613
+ write?: (args: WriteArgs) => Promise<CursorExecHandlerResult<WriteResult>>;
614
+ delete?: (args: DeleteArgs) => Promise<CursorExecHandlerResult<DeleteResult>>;
615
+ shell?: (args: ShellArgs) => Promise<CursorExecHandlerResult<ShellResult>>;
616
+ shellStream?: (args: ShellArgs, callbacks: CursorShellStreamCallbacks) => Promise<CursorExecHandlerResult<ShellResult>>;
617
+ diagnostics?: (args: DiagnosticsArgs) => Promise<CursorExecHandlerResult<DiagnosticsResult>>;
618
+ mcp?: (call: CursorMcpCall) => Promise<CursorExecHandlerResult<McpResult>>;
619
+ piRead?: (call: CursorPiCall<PiReadExecArgs>) => Promise<CursorExecHandlerResult<PiReadExecResult>>;
620
+ piBash?: (call: CursorPiCall<PiBashExecArgs>) => Promise<CursorExecHandlerResult<PiBashExecResult>>;
621
+ piEdit?: (call: CursorPiCall<PiEditExecArgs>) => Promise<CursorExecHandlerResult<PiEditExecResult>>;
622
+ piWrite?: (call: CursorPiCall<PiWriteExecArgs>) => Promise<CursorExecHandlerResult<PiWriteExecResult>>;
623
+ piGrep?: (call: CursorPiCall<PiGrepExecArgs>) => Promise<CursorExecHandlerResult<PiGrepExecResult>>;
624
+ piFind?: (call: CursorPiCall<PiFindExecArgs>) => Promise<CursorExecHandlerResult<PiFindExecResult>>;
625
+ piLs?: (call: CursorPiCall<PiLsExecArgs>) => Promise<CursorExecHandlerResult<PiLsExecResult>>;
626
+ onToolResult?: CursorToolResultHandler;
627
+ }
628
+ /**
629
+ * Plain JSON Schema document used by extension-authored tools (legacy TypeBox
630
+ * emits this shape). Distinguished from Zod at runtime via {@link isZodSchema}.
631
+ */
632
+ export type TJsonSchema = Record<string, unknown>;
633
+ /**
634
+ * Schema type accepted by the {@link Tool} interface.
635
+ *
636
+ * Canonical authoring uses Zod. Extension compat may supply a JSON Schema
637
+ * object (including TypeBox static schema objects).
638
+ */
639
+ export type TSchema = ZodType | TJsonSchema;
640
+ /** Resolve parameter types for tool execution / handlers. */
641
+ export type Static<S> = S extends ZodType ? z.infer<S> : S extends {
642
+ static: infer T;
643
+ } ? T : unknown;
644
+ export type RawArgumentRejectionCode = "ask-deep-interview-question-body-required" | "ask-intent-review-requires-positive-round" | "ask-intent-contract-requires-non-empty-authority" | "ask-deep-interview-metadata-requires-deep-interview-gate" | "ask-round-zero-metadata-requires-full-topology-fields" | "todo-write-unknown-root-key" | "todo-write-unknown-op-entry-key" | "todo-write-unknown-op-value" | "todo-write-done-drop-requires-target" | "todo-write-unknown-init-entry-key";
645
+ /**
646
+ * Optional structured detail attached to a raw-argument rejection. The fixed
647
+ * per-code guidance in `RAW_ARGUMENT_REJECTION_MESSAGES` explains the shape;
648
+ * this names what the caller actually sent that was wrong, so a retry can
649
+ * differ from the failed call.
650
+ */
651
+ export interface RawArgumentRejectionDetail {
652
+ /** Offending keys, or the offending value, in payload order. */
653
+ readonly rejectedKeys?: readonly string[];
654
+ /**
655
+ * Correction for a rejected key whose replacement is exact and
656
+ * unambiguous. Never populate this from fuzzy or edit-distance matching:
657
+ * a wrong suggestion costs more turns than no suggestion.
658
+ */
659
+ readonly hint?: string;
660
+ }
661
+ export type RawArgumentValidationResult = {
662
+ outcome: "passthrough";
663
+ } | {
664
+ outcome: "accept";
665
+ arguments: ToolCall["arguments"];
666
+ } | {
667
+ outcome: "reject";
668
+ code?: RawArgumentRejectionCode;
669
+ detail?: RawArgumentRejectionDetail;
670
+ };
671
+ export interface Tool<TParameters extends TSchema = TSchema> {
672
+ name: string;
673
+ description: string;
674
+ parameters: TParameters;
675
+ /** Optional pre-coercion adapter for narrowly scoped raw argument recovery or rejection. */
676
+ rawArgumentValidation?: (arguments_: ToolCall["arguments"]) => RawArgumentValidationResult;
677
+ /** If true, tool is strictly typed and validated against the parameters schema before execution */
678
+ strict?: boolean;
679
+ /**
680
+ * Optional grammar constraint for OpenAI custom-tool emission.
681
+ * When set, providers that support grammar-constrained tools (currently only
682
+ * `openai-responses` against models with the right capability flag) may emit
683
+ * this tool as `{type: "custom", format: {type: "grammar", …}}` instead of a
684
+ * JSON function tool. Other providers ignore the field.
685
+ */
686
+ customFormat?: {
687
+ syntax: "lark" | "regex";
688
+ definition: string;
689
+ };
690
+ /**
691
+ * Optional wire-level name used when this tool is emitted as a custom tool
692
+ * (e.g. OpenAI's `{type: "custom"}` shape). Models trained on specific tool
693
+ * names — like GPT-5 on `apply_patch` — need to see that exact name on the
694
+ * wire, but it may differ from the harness-internal `name`. The agent-loop
695
+ * dispatcher matches both `name` and `customWireName` so returned tool
696
+ * calls route correctly. Absent for regular JSON function tools.
697
+ */
698
+ customWireName?: string;
699
+ /**
700
+ * Optional safe projection for tool arguments or results. Extensions use this
701
+ * only for explicitly opt-in, display-safe summaries.
702
+ */
703
+ safeSummary?: (kind: "args" | "result", value: unknown) => string | undefined;
704
+ /** Allowlisted argument/result field names for a safe fallback summary. */
705
+ safeSummaryFields?: {
706
+ args?: string[];
707
+ result?: string[];
708
+ };
709
+ }
710
+ export interface Context {
711
+ systemPrompt?: string[];
712
+ messages: Message[];
713
+ tools?: Tool[];
714
+ }
715
+ export type AssistantMessageEvent = {
716
+ type: "start";
717
+ contentIndex?: undefined;
718
+ partial: AssistantMessage;
719
+ } | {
720
+ type: "text_start";
721
+ contentIndex: number;
722
+ partial: AssistantMessage;
723
+ } | {
724
+ type: "text_delta";
725
+ contentIndex: number;
726
+ delta: string;
727
+ partial: AssistantMessage;
728
+ } | {
729
+ type: "text_end";
730
+ contentIndex: number;
731
+ content: string;
732
+ partial: AssistantMessage;
733
+ } | {
734
+ type: "thinking_start";
735
+ contentIndex: number;
736
+ partial: AssistantMessage;
737
+ } | {
738
+ type: "thinking_delta";
739
+ contentIndex: number;
740
+ delta: string;
741
+ partial: AssistantMessage;
742
+ } | {
743
+ type: "thinking_end";
744
+ contentIndex: number;
745
+ content: string;
746
+ partial: AssistantMessage;
747
+ } | {
748
+ type: "reasoning_summary_start";
749
+ contentIndex: number;
750
+ partial: AssistantMessage;
751
+ } | {
752
+ type: "reasoning_summary_delta";
753
+ contentIndex: number;
754
+ delta: string;
755
+ partial: AssistantMessage;
756
+ } | {
757
+ type: "reasoning_summary_end";
758
+ contentIndex: number;
759
+ content: string;
760
+ partial: AssistantMessage;
761
+ } | {
762
+ type: "toolcall_start";
763
+ contentIndex: number;
764
+ partial: AssistantMessage;
765
+ } | {
766
+ type: "toolcall_delta";
767
+ contentIndex: number;
768
+ delta: string;
769
+ partial: AssistantMessage;
770
+ } | {
771
+ type: "toolcall_end";
772
+ contentIndex: number;
773
+ toolCall: ToolCall;
774
+ partial: AssistantMessage;
775
+ } | {
776
+ type: "done";
777
+ contentIndex?: undefined;
778
+ reason: Extract<StopReason, "stop" | "length" | "toolUse">;
779
+ message: AssistantMessage;
780
+ } | {
781
+ type: "error";
782
+ contentIndex?: undefined;
783
+ reason: Extract<StopReason, "aborted" | "error">;
784
+ error: AssistantMessage;
785
+ } | {
786
+ type: "toolChoiceIncapability";
787
+ contentIndex?: undefined;
788
+ api: string;
789
+ provider: string;
790
+ model: string;
791
+ requestedLevel: ToolChoiceSupport;
792
+ resolvedLevel: ToolChoiceSupport;
793
+ reason: string;
794
+ registryKey: string;
795
+ };
796
+ /**
797
+ * Compatibility settings for openai-completions API.
798
+ * Use this to override URL-based auto-detection for custom providers.
799
+ */
800
+ export interface OpenAICompat extends ToolChoiceCompat {
801
+ /** Whether the provider supports the `store` field. Default: auto-detected from URL. */
802
+ supportsStore?: boolean;
803
+ /** Whether the provider supports the `developer` role (vs `system`). Default: auto-detected from URL. */
804
+ supportsDeveloperRole?: boolean;
805
+ /**
806
+ * Whether to forward the agent session id as vendor-neutral session-identity
807
+ * headers (`session_id`, `x-session-id`) on every chat-completions request.
808
+ * Off by default. Opt in for OpenAI-compatible proxies/relays that route on
809
+ * session affinity or reuse a server-side prompt cache keyed by session.
810
+ * First-party OpenAI does not need this (it has its own gated injection in
811
+ * the openai-responses provider). Headers are only added when a non-empty
812
+ * session id is available and are never allowed to overwrite a header the
813
+ * caller already set via `headers`/`requestTransform`.
814
+ */
815
+ sendSessionHeaders?: boolean;
816
+ /**
817
+ * Whether an OpenAI Responses transport may forward the agent session id
818
+ * as `session_id` and `x-client-request-id` affinity headers for an
819
+ * explicitly configured custom relay. First-party OpenAI uses its canonical
820
+ * HTTPS origin automatically; known non-OpenAI providers remain excluded.
821
+ */
822
+ supportsResponsesSessionAffinity?: boolean;
823
+ /**
824
+ * Whether an OpenAI-compatible endpoint accepts the `service_tier` request
825
+ * field. Disabled by default for custom providers; opt in only when the proxy
826
+ * preserves or intentionally realizes OpenAI priority processing.
827
+ */
828
+ supportsServiceTier?: boolean;
829
+ /**
830
+ * Tool names the provider reserves for its own built-ins and refuses to
831
+ * accept as custom function declarations. A colliding tool is **dropped**
832
+ * from the declared tools array rather than renamed: a renamed function
833
+ * tool would come back as a `function_call` under the wire alias, and that
834
+ * path does not populate `Tool.customWireName`, leaving the agent-loop
835
+ * dispatcher unable to route it — trading a loud 400 for a silent
836
+ * unresolvable call. Dropping the declaration is intentionally a loss of
837
+ * capability, leaving the agent in the same state as any provider that
838
+ * simply has no such tool. The filter preserves declaration order and does
839
+ * not mutate the caller's array.
840
+ *
841
+ * Without this, one reserved name rejects the ENTIRE tools array with a
842
+ * single 400 and no tokens ever stream — every agent carrying that tool
843
+ * fails 100% of the time on that provider.
844
+ *
845
+ * Resolution precedence: an explicit array (including `[]`) on the model's
846
+ * `compat` replaces the built-in provider default, so `[]` opts a reserved
847
+ * provider out of the drop entirely.
848
+ */
849
+ reservedToolNames?: string[];
850
+ /**
851
+ * Whether the provider's chat-completions endpoint accepts multiple
852
+ * leading `system`/`developer` messages. When false, ordered system
853
+ * prompts are coalesced into a single message joined by `\n\n` so
854
+ * strict chat templates (e.g. Qwen-served via vLLM, MiniMax) accept
855
+ * the request. Default: detected per provider/baseUrl. Canonical
856
+ * OpenAI/Azure/OpenRouter/Cerebras/Together/Fireworks/Groq/DeepSeek/
857
+ * Mistral/xAI/Z.ai/GitHub Copilot/Zenmux are treated as `true`;
858
+ * unknown or strict-template hosts default to `false`. Setting this
859
+ * to `true` preserves separate blocks, which is preferred for
860
+ * KV-cache reuse when the trailing prompt changes between calls.
861
+ */
862
+ supportsMultipleSystemMessages?: boolean;
863
+ /** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */
864
+ supportsReasoningEffort?: boolean;
865
+ /** Optional mapping from pi-ai reasoning levels to provider/model-specific `reasoning_effort` values. */
866
+ reasoningEffortMap?: Partial<Record<Effort, string>>;
867
+ /** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */
868
+ supportsUsageInStreaming?: boolean;
869
+ /** Which field to use for max tokens. Default: auto-detected from URL. */
870
+ maxTokensField?: "max_completion_tokens" | "max_tokens";
871
+ /** Whether tool results require the `name` field. Default: auto-detected from URL. */
872
+ requiresToolResultName?: boolean;
873
+ /** Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL. */
874
+ requiresAssistantAfterToolResult?: boolean;
875
+ /** Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL. */
876
+ requiresThinkingAsText?: boolean;
877
+ /** Whether tool call IDs must be normalized to Mistral format (exactly 9 alphanumeric chars). Default: auto-detected from URL. */
878
+ requiresMistralToolIds?: boolean;
879
+ /** Format for reasoning/thinking parameter. "openai" uses reasoning_effort, "openrouter" uses reasoning: { effort }, "zai" uses thinking: { type: "enabled" | "disabled" } (also used by Moonshot Kimi), "qwen" uses top-level enable_thinking, and "qwen-chat-template" uses chat_template_kwargs.enable_thinking. Default: "openai". */
880
+ thinkingFormat?: "openai" | "openrouter" | "zai" | "qwen" | "qwen-chat-template";
881
+ /** Which reasoning content field to emit on assistant messages. Default: auto-detected. */
882
+ reasoningContentField?: "reasoning_content" | "reasoning" | "reasoning_text";
883
+ /** Whether assistant tool-call messages must include reasoning content. Default: false. */
884
+ requiresReasoningContentForToolCalls?: boolean;
885
+ /** Whether the provider accepts a synthetic placeholder (e.g. ".") for missing reasoning_content on tool-call turns. Default: true. Set to false for providers like DeepSeek that validate the exact reasoning_content value. */
886
+ allowsSyntheticReasoningContentForToolCalls?: boolean;
887
+ /** Whether assistant tool-call messages must include non-empty content. Default: false. */
888
+ requiresAssistantContentForToolCalls?: boolean;
889
+ /** Whether the provider supports the `tool_choice` parameter. Default: true. */
890
+ supportsToolChoice?: boolean;
891
+ /** Whether `tool_choice` may force a tool (`required` / named tool). Default: true. */
892
+ supportsForcedToolChoice?: boolean;
893
+ /**
894
+ * Drop reasoning fields (`reasoning_effort`, OpenRouter `reasoning`) for
895
+ * the request when `tool_choice` forces a tool call. Mirrors the Anthropic
896
+ * `disableThinkingIfToolChoiceForced` rule for backends like Kimi that
897
+ * 400 with `tool_choice 'specified' is incompatible with thinking
898
+ * enabled` whenever both are present. Default: auto-detected (Kimi).
899
+ */
900
+ disableReasoningOnForcedToolChoice?: boolean;
901
+ /**
902
+ * Drop reasoning fields (`reasoning_effort`, OpenRouter `reasoning`) for
903
+ * any request that sends `tool_choice`. Use for providers/models that accept
904
+ * tools and `tool_choice`, but reject `tool_choice` while thinking is enabled.
905
+ * Default: auto-detected (DeepSeek reasoning models).
906
+ */
907
+ disableReasoningOnToolChoice?: boolean;
908
+ /** OpenRouter-specific routing preferences. Only used when baseUrl points to OpenRouter. */
909
+ openRouterRouting?: OpenRouterRouting;
910
+ /** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */
911
+ vercelGatewayRouting?: VercelGatewayRouting;
912
+ /** Extra fields to include in request body (e.g. gateway routing hints for OpenClaw-style proxies). */
913
+ extraBody?: Record<string, unknown>;
914
+ /** Whether the provider supports the `strict` field in tool definitions. Default: auto-detected per provider/baseUrl (conservative for unknown providers). */
915
+ supportsStrictMode?: boolean;
916
+ /** Whether tool schemas must be sent either all strict or all non-strict. Undefined keeps the existing per-tool mixed behavior. */
917
+ toolStrictMode?: "all_strict" | "none";
918
+ }
919
+ /**
920
+ * Compatibility settings for anthropic-messages API.
921
+ * Use this to disable features that strict-by-default Anthropic accepts but
922
+ * that proxy gateways (Vertex AI, AWS Bedrock-style fronts, etc.) reject.
923
+ */
924
+ export interface AnthropicCompat extends ToolChoiceCompat {
925
+ /**
926
+ * Drop the top-level `strict: true` field on tool definitions. Vertex AI's
927
+ * Anthropic-compatible endpoint rejects unknown tool fields with
928
+ * `tools.<n>.custom.strict: Extra inputs are not permitted`.
929
+ */
930
+ disableStrictTools?: boolean;
931
+ /**
932
+ * Map adaptive thinking (`thinking: { type: "adaptive" }`) to
933
+ * `{ type: "enabled", budget_tokens }`. Vertex AI rejects the `adaptive`
934
+ * tag with `Input tag 'adaptive' ... does not match any of the expected
935
+ * tags: 'disabled', 'enabled'`.
936
+ */
937
+ disableAdaptiveThinking?: boolean;
938
+ /** Whether tools may include Anthropic's per-tool eager_input_streaming flag. Default: true. */
939
+ supportsEagerToolInputStreaming?: boolean;
940
+ /** Whether the provider accepts the `tool_choice` parameter at all. Default: true. */
941
+ supportsToolChoice?: boolean;
942
+ /** Whether `tool_choice` may force a tool (`any` / named `tool`). Default: true except known incompatible Anthropic models. */
943
+ supportsForcedToolChoice?: boolean;
944
+ /** Whether long prompt-cache retention (`ttl: "1h"`) is supported. Default: true for canonical Anthropic API. */
945
+ supportsLongCacheRetention?: boolean;
946
+ /**
947
+ * Prompt-cache transport accepted by this Anthropic-compatible endpoint.
948
+ * Canonical Anthropic defaults to `"automatic"`; Claude-family models on
949
+ * noncanonical compatible endpoints default to `"explicit"`; non-Claude
950
+ * compatible endpoints default to `"none"`. Set `"automatic"` to opt into
951
+ * top-level caching, `"none"` to opt out, or `"explicit"` for block markers.
952
+ */
953
+ promptCacheMode?: "none" | "explicit" | "automatic";
954
+ }
955
+ /**
956
+ * OpenRouter provider routing preferences.
957
+ * Controls which upstream providers OpenRouter routes requests to.
958
+ * @see https://openrouter.ai/docs/provider-routing
959
+ */
960
+ export interface OpenRouterRouting {
961
+ /** List of provider slugs to exclusively use for this request (e.g., ["amazon-bedrock", "anthropic"]). */
962
+ only?: string[];
963
+ /** List of provider slugs to try in order (e.g., ["anthropic", "openai"]). */
964
+ order?: string[];
965
+ }
966
+ /**
967
+ * Vercel AI Gateway routing preferences.
968
+ * Controls which upstream providers the gateway routes requests to.
969
+ * @see https://vercel.com/docs/ai-gateway/models-and-providers/provider-options
970
+ */
971
+ export interface VercelGatewayRouting {
972
+ /** List of provider slugs to exclusively use for this request (e.g., ["bedrock", "anthropic"]). */
973
+ only?: string[];
974
+ /** List of provider slugs to try in order (e.g., ["anthropic", "openai"]). */
975
+ order?: string[];
976
+ }
977
+ export interface ModelRequestTransform {
978
+ /** Named request-shaping preset. `openai-proxy` removes OpenAI SDK telemetry headers and uses a generic Vibrato User-Agent. */
979
+ profile?: "openai-proxy";
980
+ /** Header names to remove from the final outbound request. Case-insensitive. */
981
+ stripHeaders?: string[];
982
+ /** Headers to set after stripping; use null to remove a header explicitly. */
983
+ setHeaders?: Record<string, string | null>;
984
+ /** Extra request body fields merged after provider defaults; protected core request keys are ignored. */
985
+ extraBody?: Record<string, unknown>;
986
+ }
987
+ /** Provenance used when resolving a model's default request output budget. */
988
+ export type ModelMaxTokensSource = "configured" | "discovered";
989
+ export interface ModelCost {
990
+ input: number;
991
+ output: number;
992
+ cacheRead: number;
993
+ cacheWrite: number;
994
+ }
995
+ export interface LongContextPricing {
996
+ /** Input-token count above which the long-context rates apply to the full request. */
997
+ threshold: number;
998
+ cost: ModelCost;
999
+ }
1000
+ export interface Model<TApi extends Api = any> {
1001
+ id: string;
1002
+ name: string;
1003
+ api: TApi;
1004
+ provider: Provider;
1005
+ baseUrl: string;
1006
+ reasoning: boolean;
1007
+ input: ("text" | "image")[];
1008
+ /**
1009
+ * Output modalities the model can produce. Defaults to text-only when
1010
+ * unset. A model that lists `"image"` advertises image-generation support
1011
+ * (e.g. an OpenAI-compatible `gpt-image` model behind a proxy), which the
1012
+ * `generate_image` tool uses to route requests without first-party
1013
+ * provider/id heuristics.
1014
+ */
1015
+ output?: ("text" | "image")[];
1016
+ cost: ModelCost;
1017
+ /** Optional long-context rates selected from the request's total input-token count. */
1018
+ longContextPricing?: LongContextPricing;
1019
+ /** Premium Copilot requests charged per user-initiated request (defaults to 1). */
1020
+ premiumMultiplier?: number;
1021
+ contextWindow: number;
1022
+ maxTokens: number;
1023
+ /** Explicit models.yml/model-override authority; absent keeps the safe transport default. */
1024
+ maxTokensSource?: ModelMaxTokensSource;
1025
+ headers?: Record<string, string>;
1026
+ /**
1027
+ * Streaming transport override. When `"pi-native"`, `streamSimple` routes
1028
+ * the request to the model's `baseUrl` via the auth-gateway's
1029
+ * `POST /v1/pi/stream` endpoint instead of dispatching the per-API
1030
+ * provider client. The `baseUrl` must point at an `vib auth-gateway`
1031
+ * (or compatible) host; `headers.Authorization` (or `apiKey` resolved by
1032
+ * the registry) carries the gateway bearer.
1033
+ *
1034
+ * Used by containerized Vibrato installs to route every LLM call through a
1035
+ * sidecar gateway that holds the real provider credentials. The model's other
1036
+ * metadata (pricing, context window, thinking config, …) still resolves locally; only the streaming
1037
+ * dispatch is redirected.
1038
+ */
1039
+ transport?: "pi-native";
1040
+ /** Hint that websocket transport should be preferred when supported by the provider implementation. */
1041
+ preferWebsockets?: boolean;
1042
+ /** Preferred model to switch to when context promotion is triggered (model id or provider/id). */
1043
+ contextPromotionTarget?: string;
1044
+ /** Provider-facing model id when it differs from the local selector id. */
1045
+ wireModelId?: string;
1046
+ /** Declarative request shaping for OpenAI-compatible proxy providers. */
1047
+ requestTransform?: ModelRequestTransform;
1048
+ /** Default prompt-cache retention preference for this model when the request omits one. */
1049
+ cacheRetention?: CacheRetention;
1050
+ /** Provider-assigned priority value (lower = higher priority). */
1051
+ priority?: number;
1052
+ /** Canonical thinking capability metadata for this model. */
1053
+ thinking?: ThinkingConfig;
1054
+ /** Compatibility overrides per API. If not set, auto-detected from baseUrl. */
1055
+ compat?: TApi extends "openai-completions" | "openai-responses" ? OpenAICompat : TApi extends "anthropic-messages" ? AnthropicCompat : TApi extends "bedrock-converse-stream" | "google-generative-ai" | "google-gemini-cli" | "google-vertex" | "ollama-chat" | "azure-openai-responses" | "openai-codex-responses" ? ToolChoiceCompat : never;
1056
+ /**
1057
+ * Which shape to use when exposing the OpenAI code backend `apply_patch` tool to this model.
1058
+ * Generated catalog policy sets `"freeform"` for first-party GPT-5 Responses
1059
+ * models that support OpenAI custom tools with a Lark grammar. The freeform
1060
+ * variant sends a raw patch string with no JSON envelope.
1061
+ * - `"function"` or undefined: JSON function-tool with `{input: string}` (spec §1.2).
1062
+ */
1063
+ applyPatchToolType?: "freeform" | "function";
1064
+ /**
1065
+ * Force OAuth-style request shaping for providers whose API key prefix doesn't
1066
+ * match an OAuth token (e.g. routing Anthropic traffic through a proxy that
1067
+ * expects Anthropic Code framing). When true, the streaming layer sets
1068
+ * `options.isOAuth = true` for the underlying provider call.
1069
+ */
1070
+ isOAuth?: boolean;
1071
+ }
1072
+ /** True when a model explicitly opts into OpenAI-compatible `service_tier` forwarding. */
1073
+ export declare function modelSupportsServiceTier(model: Pick<Model, "compat"> | undefined): boolean;