@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.50

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 (365) hide show
  1. package/AUTHORING.md +537 -33
  2. package/CHANGELOG.md +201 -1
  3. package/README.md +83 -22
  4. package/SUBMISSION.md +2 -2
  5. package/bin/apifuse-check.ts +165 -11
  6. package/bin/apifuse-dev.ts +57 -13
  7. package/bin/apifuse-migrate-operation-declaration.ts +55 -0
  8. package/bin/apifuse-migrate-shape.ts +202 -0
  9. package/bin/apifuse-pack-check.ts +22 -2
  10. package/bin/apifuse-pack-smoke.ts +57 -2
  11. package/bin/apifuse-pack-types.ts +357 -38
  12. package/bin/apifuse-perf.ts +14 -13
  13. package/bin/apifuse-record.ts +709 -72
  14. package/bin/apifuse-submit-check.ts +2344 -324
  15. package/bin/apifuse-sync-assets.ts +117 -0
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/dist/auth-turn/index.d.ts +3 -3
  18. package/dist/auth-turn/index.js +1 -1
  19. package/dist/auth.d.ts +14 -0
  20. package/dist/auth.js +67 -0
  21. package/dist/ceremonies/index.d.ts +16 -0
  22. package/dist/ceremonies/index.js +141 -36
  23. package/dist/cli/commands.d.ts +1 -1
  24. package/dist/cli/commands.js +27 -0
  25. package/dist/cli/create.d.ts +4 -1
  26. package/dist/cli/create.js +42 -37
  27. package/dist/cli/migrate-operation-declaration.d.ts +59 -0
  28. package/dist/cli/migrate-operation-declaration.js +1178 -0
  29. package/dist/cli/migrate-operation-shape.d.ts +44 -0
  30. package/dist/cli/migrate-operation-shape.js +113 -0
  31. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  32. package/dist/cli/migrate-provider-shape.js +578 -0
  33. package/dist/cli/prompt-assets.d.ts +80 -0
  34. package/dist/cli/prompt-assets.js +743 -0
  35. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  36. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  37. package/dist/cli/templates/provider/README.md.tpl +5 -5
  38. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  39. package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
  40. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  41. package/dist/config/loader.d.ts +179 -16
  42. package/dist/config/loader.js +435 -127
  43. package/dist/contract-serialization.js +4 -8
  44. package/dist/contract-types.d.ts +12 -5
  45. package/dist/contract.js +24 -10
  46. package/dist/declaration-validation.d.ts +33 -0
  47. package/dist/declaration-validation.js +266 -0
  48. package/dist/define.d.ts +66 -29
  49. package/dist/define.js +778 -69
  50. package/dist/dev.d.ts +3 -0
  51. package/dist/dev.js +1 -1
  52. package/dist/engine.d.ts +78 -0
  53. package/dist/engine.js +133 -0
  54. package/dist/error-observability.d.ts +7 -0
  55. package/dist/error-observability.js +61 -0
  56. package/dist/error-resolution.d.ts +4 -0
  57. package/dist/error-resolution.js +122 -0
  58. package/dist/errors.d.ts +33 -0
  59. package/dist/errors.js +40 -0
  60. package/dist/fixture-sanitization.d.ts +28 -0
  61. package/dist/fixture-sanitization.js +227 -0
  62. package/dist/health-scenario.d.ts +1842 -0
  63. package/dist/health-scenario.js +624 -0
  64. package/dist/index.d.ts +21 -10
  65. package/dist/index.js +12 -7
  66. package/dist/lint.d.ts +23 -11
  67. package/dist/lint.js +572 -69
  68. package/dist/native-address.d.ts +43 -0
  69. package/dist/native-address.js +281 -0
  70. package/dist/native-egress-policy.d.ts +31 -0
  71. package/dist/native-egress-policy.js +288 -0
  72. package/dist/observability.d.ts +5 -2
  73. package/dist/observability.js +48 -1
  74. package/dist/provider.d.ts +10 -2
  75. package/dist/provider.js +4 -1
  76. package/dist/runtime/auth-flow.d.ts +5 -1
  77. package/dist/runtime/auth-flow.js +6 -0
  78. package/dist/runtime/browser.d.ts +1 -0
  79. package/dist/runtime/browser.js +492 -49
  80. package/dist/runtime/cache.d.ts +1 -0
  81. package/dist/runtime/cache.js +169 -15
  82. package/dist/runtime/choice-wordlist.d.ts +9 -0
  83. package/dist/runtime/choice-wordlist.js +138 -0
  84. package/dist/runtime/choice.d.ts +13 -1
  85. package/dist/runtime/choice.js +490 -102
  86. package/dist/runtime/chrome149-header-order.d.ts +58 -0
  87. package/dist/runtime/chrome149-header-order.js +289 -0
  88. package/dist/runtime/env.js +12 -0
  89. package/dist/runtime/executor.d.ts +3 -2
  90. package/dist/runtime/executor.js +26 -25
  91. package/dist/runtime/http.d.ts +1 -0
  92. package/dist/runtime/http.js +515 -53
  93. package/dist/runtime/insights.js +2 -2
  94. package/dist/runtime/instrumentation.d.ts +2 -2
  95. package/dist/runtime/instrumentation.js +366 -8
  96. package/dist/runtime/native-network-errors.d.ts +33 -0
  97. package/dist/runtime/native-network-errors.js +69 -0
  98. package/dist/runtime/native-network.d.ts +96 -0
  99. package/dist/runtime/native-network.js +1232 -0
  100. package/dist/runtime/ocr.d.ts +29 -0
  101. package/dist/runtime/ocr.js +440 -0
  102. package/dist/runtime/otlp.d.ts +71 -2
  103. package/dist/runtime/otlp.js +397 -16
  104. package/dist/runtime/proxy-errors.js +6 -2
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  108. package/dist/runtime/proxy-telemetry.js +154 -47
  109. package/dist/runtime/redirects.d.ts +29 -0
  110. package/dist/runtime/redirects.js +36 -0
  111. package/dist/runtime/redis.d.ts +1 -1
  112. package/dist/runtime/redis.js +4 -2
  113. package/dist/runtime/request-options.d.ts +68 -1
  114. package/dist/runtime/request-options.js +548 -0
  115. package/dist/runtime/resolver-config.d.ts +6 -0
  116. package/dist/runtime/resolver-config.js +6 -0
  117. package/dist/runtime/resolver-public.d.ts +1 -0
  118. package/dist/runtime/resolver-public.js +1 -0
  119. package/dist/runtime/resolver-shared.d.ts +14 -0
  120. package/dist/runtime/resolver-shared.js +12 -0
  121. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  122. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  123. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  124. package/dist/runtime/resolver-vendors/browser.js +377 -0
  125. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  126. package/dist/runtime/resolver-vendors/capsolver.js +531 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  132. package/dist/runtime/resolver-vendors/types.js +96 -0
  133. package/dist/runtime/resolver.d.ts +72 -0
  134. package/dist/runtime/resolver.js +771 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +3 -0
  138. package/dist/runtime/state.js +277 -71
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +41 -5
  142. package/dist/runtime/stealth.js +997 -291
  143. package/dist/runtime/stt.js +1 -12
  144. package/dist/runtime/timeout.d.ts +5 -0
  145. package/dist/runtime/timeout.js +12 -0
  146. package/dist/runtime/trace-config.d.ts +12 -0
  147. package/dist/runtime/trace-config.js +62 -0
  148. package/dist/runtime/trace.d.ts +5 -0
  149. package/dist/runtime/trace.js +43 -10
  150. package/dist/serve.d.ts +1 -1
  151. package/dist/serve.js +1 -1
  152. package/dist/server/error-observability.d.ts +1 -0
  153. package/dist/server/error-observability.js +1 -0
  154. package/dist/server/index.d.ts +5 -2
  155. package/dist/server/index.js +2 -2
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test.d.ts +14 -3
  159. package/dist/server/self-test.js +129 -58
  160. package/dist/server/serve-implementation.d.ts +230 -0
  161. package/dist/server/serve-implementation.js +2265 -0
  162. package/dist/server/serve.d.ts +1 -70
  163. package/dist/server/serve.js +1 -1131
  164. package/dist/server/trace-output.d.ts +6 -0
  165. package/dist/server/trace-output.js +79 -0
  166. package/dist/server/types.d.ts +30 -5
  167. package/dist/server/types.js +13 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +9 -4
  207. package/dist/stealth/profiles.js +160 -211
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.js +7 -1
  211. package/dist/testing/index.d.ts +2 -1
  212. package/dist/testing/index.js +2 -1
  213. package/dist/testing/run.d.ts +32 -2
  214. package/dist/testing/run.js +489 -21
  215. package/dist/trace-sanitization.d.ts +5 -0
  216. package/dist/trace-sanitization.js +45 -0
  217. package/dist/types.d.ts +673 -131
  218. package/dist/types.js +1 -0
  219. package/package.json +45 -5
  220. package/src/auth-turn/index.ts +1 -1
  221. package/src/auth.ts +118 -0
  222. package/src/ceremonies/index.ts +189 -46
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
  246. package/src/cli/commands.ts +33 -0
  247. package/src/cli/create.ts +50 -37
  248. package/src/cli/migrate-operation-declaration.ts +1654 -0
  249. package/src/cli/migrate-operation-shape.ts +184 -0
  250. package/src/cli/migrate-provider-shape.ts +772 -0
  251. package/src/cli/prompt-assets.ts +865 -0
  252. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  253. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  254. package/src/cli/templates/provider/README.md.tpl +5 -5
  255. package/src/cli/templates/provider/index.ts.tpl +6 -3
  256. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  257. package/src/cli/templates/provider/provider.json.tpl +6 -0
  258. package/src/config/loader.ts +690 -163
  259. package/src/contract-serialization.ts +5 -7
  260. package/src/contract-types.ts +12 -5
  261. package/src/contract.ts +24 -10
  262. package/src/declaration-validation.ts +330 -0
  263. package/src/define.ts +1048 -131
  264. package/src/dev.ts +4 -1
  265. package/src/engine.ts +279 -0
  266. package/src/error-observability.ts +64 -0
  267. package/src/error-resolution.ts +127 -0
  268. package/src/errors.ts +68 -0
  269. package/src/fixture-sanitization.ts +264 -0
  270. package/src/health-scenario.ts +875 -0
  271. package/src/index.ts +220 -13
  272. package/src/lint.ts +698 -90
  273. package/src/native-address.ts +340 -0
  274. package/src/native-egress-policy.ts +358 -0
  275. package/src/observability.ts +51 -1
  276. package/src/provider.ts +161 -3
  277. package/src/runtime/auth-flow.ts +12 -0
  278. package/src/runtime/browser.ts +661 -63
  279. package/src/runtime/cache.ts +189 -14
  280. package/src/runtime/choice-wordlist.ts +145 -0
  281. package/src/runtime/choice.ts +631 -120
  282. package/src/runtime/chrome149-header-order.ts +330 -0
  283. package/src/runtime/env.ts +13 -0
  284. package/src/runtime/executor.ts +43 -31
  285. package/src/runtime/http.ts +641 -61
  286. package/src/runtime/insights.ts +2 -2
  287. package/src/runtime/instrumentation.ts +520 -15
  288. package/src/runtime/native-network-errors.ts +99 -0
  289. package/src/runtime/native-network.ts +1605 -0
  290. package/src/runtime/ocr.ts +523 -0
  291. package/src/runtime/otlp.ts +467 -21
  292. package/src/runtime/proxy-errors.ts +12 -4
  293. package/src/runtime/proxy-nodemaven.ts +221 -0
  294. package/src/runtime/proxy-telemetry.ts +244 -75
  295. package/src/runtime/redirects.ts +66 -0
  296. package/src/runtime/redis.ts +7 -2
  297. package/src/runtime/request-options.ts +680 -1
  298. package/src/runtime/resolver-config.ts +6 -0
  299. package/src/runtime/resolver-public.ts +23 -0
  300. package/src/runtime/resolver-shared.ts +33 -0
  301. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  302. package/src/runtime/resolver-vendors/browser.ts +533 -0
  303. package/src/runtime/resolver-vendors/capsolver.ts +707 -0
  304. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  305. package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
  306. package/src/runtime/resolver-vendors/types.ts +212 -0
  307. package/src/runtime/resolver.ts +1157 -0
  308. package/src/runtime/secrets.ts +64 -0
  309. package/src/runtime/state.ts +394 -77
  310. package/src/runtime/stealth-cookies.ts +132 -0
  311. package/src/runtime/stealth.ts +1280 -336
  312. package/src/runtime/stt.ts +1 -19
  313. package/src/runtime/timeout.ts +18 -0
  314. package/src/runtime/trace-config.ts +78 -0
  315. package/src/runtime/trace.ts +57 -17
  316. package/src/serve.ts +6 -1
  317. package/src/server/error-observability.ts +1 -0
  318. package/src/server/index.ts +34 -2
  319. package/src/server/self-test-input-tokens.ts +29 -14
  320. package/src/server/self-test.ts +191 -68
  321. package/src/server/serve-implementation.ts +3378 -0
  322. package/src/server/serve.ts +1 -1632
  323. package/src/server/trace-output.ts +129 -0
  324. package/src/server/types.ts +13 -1
  325. package/src/stateful/README.md +146 -0
  326. package/src/stateful/errors.ts +35 -0
  327. package/src/stateful/http-provider-event-emitter.ts +314 -0
  328. package/src/stateful/http-session-owner-registry.ts +306 -0
  329. package/src/stateful/index.ts +18 -0
  330. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  331. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  332. package/src/stateful/provider-event-pipeline.ts +61 -0
  333. package/src/stateful/provider-events.ts +462 -0
  334. package/src/stateful/session-key.ts +111 -0
  335. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  336. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  337. package/src/stateful/stateful-provider-adapter.ts +562 -0
  338. package/src/stateful/stateful-provider-observability.ts +261 -0
  339. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  340. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  341. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  342. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  343. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  344. package/src/stateful-signing.ts +46 -0
  345. package/src/stealth/profiles.ts +202 -231
  346. package/src/stream-evidence.ts +988 -0
  347. package/src/stream.ts +8 -1
  348. package/src/testing/index.ts +10 -1
  349. package/src/testing/run.ts +658 -15
  350. package/src/trace-sanitization.ts +63 -0
  351. package/src/types.ts +788 -174
  352. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  353. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  354. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  355. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  356. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  357. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  358. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  359. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  360. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  361. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  362. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  363. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  364. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  365. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type ms from "ms";
2
+ import type { HealthScenario } from "./health-scenario.js";
3
+ import type { SerializedCookieJar } from "tough-cookie";
2
4
 
3
5
  import type { infer as ZodInfer, ZodType } from "zod";
4
6
 
@@ -41,10 +43,10 @@ export type InferSchemaOutput<TSchema extends SchemaLike> =
41
43
  ? Output
42
44
  : unknown;
43
45
 
44
- export interface OperationInputExample {
45
- scenario: string;
46
+ export interface OperationExample {
47
+ scenarioKey: ProviderLocaleKeyInput;
46
48
  input: unknown;
47
- rationale?: string;
49
+ rationaleKey?: ProviderLocaleKeyInput;
48
50
  }
49
51
 
50
52
  export type OperationRiskClass =
@@ -55,19 +57,6 @@ export type OperationRiskClass =
55
57
 
56
58
  export type OperationApprovalPolicy = "never" | "risk-based" | "always";
57
59
 
58
- export interface OperationToolRouterMetadata {
59
- /** Optional MCP-safe override. Defaults to providerId__operationId. */
60
- name?: string;
61
- /** Safety class exposed to Tool Router clients and approval policy. */
62
- riskClass?: OperationRiskClass;
63
- /** OpenAI remote-MCP approval hint. Defaults from riskClass. */
64
- approval?: OperationApprovalPolicy;
65
- /** Override connection requirement when provider auth + openWorld inference is insufficient. */
66
- requiresConnection?: boolean;
67
- /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
68
- connectionExternalRefParam?: string;
69
- }
70
-
71
60
  export type OperationSensitivePath = string;
72
61
 
73
62
  export interface OperationObservabilitySensitiveConfig {
@@ -92,38 +81,6 @@ export interface OperationObservabilityConfig {
92
81
  sensitive?: OperationObservabilitySensitiveConfig;
93
82
  }
94
83
 
95
- export interface OperationAnnotations {
96
- readOnly?: boolean;
97
- destructive?: boolean;
98
- idempotent?: boolean;
99
- /**
100
- * Marks the operation as callable without provider-level authentication.
101
- *
102
- * Provider-level `auth.mode` describes the **majority** auth model of a
103
- * provider; individual operations can still opt out via `openWorld: true`
104
- * when their handler does not consume `ctx.credential`. This is the
105
- * canonical way to declare "this operation is public, even though the
106
- * provider is `credentials`-mode" without splitting the provider into two.
107
- *
108
- * Health-check projections treat `openWorld: true` operations as
109
- * connection-free probes (no `requiresConnection` required, no SA token
110
- * lookup). Future gateway work MAY extend this annotation to bypass
111
- * `X-ApiFuse-Connection-Id` enforcement at proxy time.
112
- *
113
- * Example: Naver Map's `search`, `geocode`, and directions operations
114
- * call public Naver endpoints with no cookies, while `collections` and
115
- * `export` consume the user's session cookie — the provider declares
116
- * `auth.mode: "credentials"` (for the latter) and the former mark
117
- * `openWorld: true`.
118
- */
119
- openWorld?: boolean;
120
- rateLimit?: {
121
- calls: number;
122
- window: "minute" | "hour" | "day";
123
- };
124
- timeoutMs?: number;
125
- }
126
-
127
84
  export const OPERATION_TIMEOUT_MS_MIN = 1;
128
85
  export const OPERATION_TIMEOUT_MS_MAX = 60_000;
129
86
 
@@ -210,14 +167,14 @@ export type SmsOrigin =
210
167
  kind: "e164";
211
168
  value: E164PhoneNumber;
212
169
  display?: string;
213
- }
170
+ }
214
171
  | {
215
172
  /** Country-local service sender, for example KR 1661-5270. */
216
173
  kind: "nationalServiceCode";
217
174
  country: Iso3166Alpha2CountryCode;
218
175
  value: string;
219
176
  display?: string;
220
- };
177
+ };
221
178
 
222
179
  export interface SmsOtpExtractionPattern {
223
180
  /** RegExp or source string containing exactly one usable OTP capture. */
@@ -240,6 +197,61 @@ export interface SmsOtpMatcherDefinition {
240
197
  extractOtp(body: string): string | null;
241
198
  }
242
199
 
200
+ export interface ProviderOcrConfig {
201
+ readonly mode: "required" | "optional";
202
+ }
203
+
204
+ export type OcrImageInput =
205
+ | { readonly kind: "base64"; readonly data: string; readonly mediaType?: string }
206
+ | { readonly kind: "url"; readonly url: string };
207
+
208
+ export interface OcrRecognizeRequest {
209
+ readonly image: OcrImageInput;
210
+ readonly hint?: "captcha" | "document" | "generic";
211
+ readonly prompt?: string;
212
+ readonly maxTokens?: number;
213
+ readonly timeoutMs?: number;
214
+ }
215
+
216
+ export interface OcrWarning {
217
+ readonly code: string;
218
+ readonly message: string;
219
+ }
220
+
221
+ export interface OcrResult {
222
+ readonly text: string;
223
+ readonly model: string;
224
+ readonly warnings?: readonly OcrWarning[];
225
+ }
226
+
227
+ export interface OcrCaptchaOptions {
228
+ readonly length?: number;
229
+ /** Allowed characters. A RegExp is applied to each character, not to the whole text. */
230
+ readonly charset?: string | RegExp;
231
+ readonly caseSensitive?: boolean;
232
+ readonly maxCandidates?: number;
233
+ }
234
+
235
+ export interface OcrCaptchaCandidate {
236
+ readonly text: string;
237
+ readonly satisfiesConstraints: boolean;
238
+ }
239
+
240
+ export interface OcrCaptchaResult {
241
+ readonly text: string;
242
+ readonly candidates: readonly OcrCaptchaCandidate[];
243
+ readonly satisfiesConstraints: boolean;
244
+ readonly model: string;
245
+ }
246
+
247
+ export interface OcrContext {
248
+ recognize(request: OcrRecognizeRequest): Promise<OcrResult>;
249
+ extractCaptchaText(
250
+ image: OcrImageInput,
251
+ options?: OcrCaptchaOptions,
252
+ ): Promise<OcrCaptchaResult>;
253
+ }
254
+
243
255
  export type SttTranscribeMode = "general" | "otp";
244
256
  export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
245
257
  export type SttUnsupportedOptionPolicy = "warn" | "error";
@@ -249,6 +261,128 @@ export interface ProviderSttConfig {
249
261
  mode: ProviderSttMode;
250
262
  }
251
263
 
264
+ /**
265
+ * Union order is documentation only.
266
+ *
267
+ * The SDK owns the default hosted-vendor fallback policy and derives the chain
268
+ * from each provider's declared challenge kinds. Hosted solvers are preferred
269
+ * with `capsolver` ahead of `2captcha` in that policy.
270
+ *
271
+ * `browser` is the in-house CDP pool and remains opt-in; it is excluded from the
272
+ * default chain. `custom` is likewise reserved for provider-specific configuration.
273
+ *
274
+ * `ProviderResolverConfig.vendors` overrides the SDK policy when declared.
275
+ */
276
+ export type ProviderResolverVendor =
277
+ | "browser"
278
+ | "capsolver"
279
+ | "capmonster"
280
+ | "2captcha"
281
+ | "custom";
282
+
283
+ /**
284
+ * Token-family kinds resolve to `{ form: "token" }`. Cookie-family kinds resolve
285
+ * to `{ form: "cookies" }`; network-identity binding is defined per kind. `aws_waf`
286
+ * was measured portable across residential leases on buyee, while `cf_clearance`
287
+ * remains unmeasured here and is treated as identity-scoped because it is widely
288
+ * described as IP-bound.
289
+ */
290
+ export type ProviderChallenge =
291
+ | {
292
+ readonly kind: "turnstile";
293
+ readonly siteKey: string;
294
+ readonly pageUrl: string;
295
+ readonly action?: string;
296
+ readonly cdata?: string;
297
+ }
298
+ | {
299
+ readonly kind: "recaptcha_v2";
300
+ readonly siteKey: string;
301
+ readonly pageUrl: string;
302
+ }
303
+ | {
304
+ readonly kind: "recaptcha_v3";
305
+ readonly siteKey: string;
306
+ readonly pageUrl: string;
307
+ readonly action: string;
308
+ readonly minScore?: number;
309
+ }
310
+ | {
311
+ readonly kind: "hcaptcha";
312
+ readonly siteKey: string;
313
+ readonly pageUrl: string;
314
+ }
315
+ | {
316
+ readonly kind: "cloudflare_interstitial";
317
+ readonly pageUrl: string;
318
+ readonly blockedHtml?: string;
319
+ }
320
+ | {
321
+ readonly kind: "aws_waf";
322
+ readonly pageUrl: string;
323
+ /** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
324
+ readonly siteKey?: string;
325
+ readonly captchaScript?: string;
326
+ readonly context?: string;
327
+ readonly iv?: string;
328
+ }
329
+ | {
330
+ readonly kind: "akamai_sec_cpt";
331
+ readonly pageUrl: string;
332
+ /** The admitted challenge document, needed for tile/context extraction. */
333
+ readonly challengeHtml?: string;
334
+ }
335
+ | {
336
+ readonly kind: "akamai_sensor";
337
+ readonly pageUrl: string;
338
+ /** Upstream sensor script URL the payload must be POSTed to. */
339
+ readonly scriptUrl: string;
340
+ /** Current `_abck` cookie value, rotates each round. */
341
+ readonly abck?: string;
342
+ /** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
343
+ readonly bmsz?: string;
344
+ /** Bot Manager major version when known ("3" measured on zozo.jp). */
345
+ readonly version?: string;
346
+ };
347
+
348
+ export type ProviderChallengeKind = ProviderChallenge["kind"];
349
+
350
+ /**
351
+ * Token solutions carry no network-identity binding. Cookie-solution binding is
352
+ * per challenge kind: `aws_waf` was measured portable across residential leases
353
+ * on buyee, while `cf_clearance` is unmeasured here and treated as scoped to the
354
+ * identity that produced it. The provider attaches the returned cookies to its
355
+ * own requests.
356
+ */
357
+ export type ChallengeSolution =
358
+ | { readonly form: "token"; readonly token: string }
359
+ | {
360
+ readonly form: "cookies";
361
+ readonly cookies: Readonly<Record<string, string>>;
362
+ readonly userAgent: string;
363
+ /** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
364
+ readonly expires?: number;
365
+ /**
366
+ * Epoch seconds conservatively estimated by the SDK when a resolver vendor omits
367
+ * the upstream cookie's expiry. `expires` takes precedence when both are present.
368
+ */
369
+ readonly sdkEstimatedExpires?: number;
370
+ };
371
+
372
+ export interface ProviderResolverConfig {
373
+ /** Optional ordered override for the SDK-owned vendor fallback chain. */
374
+ readonly vendors?: readonly ProviderResolverVendor[];
375
+ /** Challenge kinds this provider is permitted to request. */
376
+ readonly kinds: readonly ProviderChallengeKind[];
377
+ /**
378
+ * Client fingerprint profile the SDK must use when reaching this upstream.
379
+ * Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
380
+ * challenge is served, while a Safari profile is admitted. Provider-declared
381
+ * because only the provider knows its upstream's admission rule.
382
+ */
383
+ readonly clientProfile?: string;
384
+ }
385
+
252
386
  export type SttAudioInput = {
253
387
  kind: "base64";
254
388
  data: string;
@@ -327,6 +461,10 @@ export interface SttContext {
327
461
  ): VerificationCodeExtractionResult;
328
462
  }
329
463
 
464
+ export interface ResolverContext {
465
+ solve(challenge: ProviderChallenge, signal?: AbortSignal): Promise<ChallengeSolution>;
466
+ }
467
+
330
468
  export interface HealthJourneySchedule {
331
469
  kind: "interval";
332
470
  /** ISO 8601 duration, for example PT8H. */
@@ -339,11 +477,11 @@ export type HealthScheduleRandomization =
339
477
  | {
340
478
  mode: "centered";
341
479
  maxOffset: Iso8601Duration;
342
- }
480
+ }
343
481
  | {
344
482
  mode: "delayed";
345
483
  maxDelay: Iso8601Duration;
346
- };
484
+ };
347
485
 
348
486
  export interface HealthJourneyStep {
349
487
  id: string;
@@ -458,7 +596,7 @@ export type HealthJourneyManualTriggerPolicy =
458
596
  /** ISO 8601 duration. Minimum time between manual executions. */
459
597
  minManualInterval: Iso8601Duration;
460
598
  publicRationale: string;
461
- };
599
+ };
462
600
 
463
601
  export interface HealthJourneyRunResult {
464
602
  status?: "ok" | "degraded" | "down" | "unknown";
@@ -466,7 +604,7 @@ export interface HealthJourneyRunResult {
466
604
  metadata?: Record<string, unknown>;
467
605
  }
468
606
 
469
- export interface HealthJourneyDefinition {
607
+ interface HealthJourneyDefinitionBase {
470
608
  id: string;
471
609
  title?: string;
472
610
  description?: string;
@@ -478,11 +616,17 @@ export interface HealthJourneyDefinition {
478
616
  requiredSecrets?: readonly string[];
479
617
  manualTrigger?: HealthJourneyManualTriggerPolicy;
480
618
  steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
481
- run?: (
482
- ctx: HealthJourneyRunContext,
483
- ) => Promise<HealthJourneyRunResult | undefined>;
484
619
  }
485
620
 
621
+ export type HealthJourneyDefinition = HealthJourneyDefinitionBase &
622
+ (
623
+ | {
624
+ run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
625
+ scenario?: never;
626
+ }
627
+ | { scenario: HealthScenario; run?: never }
628
+ );
629
+
486
630
  /**
487
631
  * Health-check authoring surface owned by `@apifuse/provider-sdk`.
488
632
  *
@@ -574,38 +718,13 @@ export interface HealthCheckCaseResult {
574
718
  * so authors get IntelliSense and compile-time errors when accessing fields
575
719
  * that do not exist on the operation's declared output schema.
576
720
  */
577
- export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
721
+ export type HealthCheckCase<TInput = unknown, TOutput = unknown> = {
578
722
  /** Human-readable case name; unique within the suite. */
579
723
  name: string;
580
724
  /** Optional longer description shown on ops dashboards. */
581
725
  description?: string;
582
726
  /** Input passed to the operation handler for this case. */
583
727
  input: TInput;
584
- /**
585
- * Optional runtime input preparation hook for volatile probes. Use this when
586
- * the durable probe input must be derived from a live read-only operation
587
- * immediately before the checked operation executes.
588
- */
589
- prepareInput?: (
590
- ctx: HealthCheckInputPreparationContext<TInput>,
591
- ) => TInput | Promise<TInput>;
592
- /**
593
- * Assertion executed against the operation's response and timing.
594
- *
595
- * - Throw to fail the case (recorded as `down`).
596
- * - Return `{ status: "degraded", label }` to flag without failing.
597
- * - Return `void` (implicit) for `ok`.
598
- *
599
- * MUST NOT access scheduler, recorder, or any runtime type — pure data
600
- * + lambda only.
601
- */
602
- assertions: (
603
- ctx: HealthCheckAssertionContext<TOutput>,
604
- ) =>
605
- | void
606
- | Promise<void>
607
- | HealthCheckCaseResult
608
- | Promise<HealthCheckCaseResult>;
609
728
  /** Override per-case degradation threshold (ms); falls back to the suite default. */
610
729
  degradedThresholdMs?: number;
611
730
  /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
@@ -614,7 +733,43 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
614
733
  expectedStatus?: "ok" | "degraded";
615
734
  /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
616
735
  enabled?: () => boolean;
617
- }
736
+ } & (
737
+ | {
738
+ /**
739
+ * Optional runtime input preparation hook for volatile probes. Use this when
740
+ * the durable probe input must be derived from a live read-only operation
741
+ * immediately before the checked operation executes.
742
+ */
743
+ prepareInput?: (
744
+ ctx: HealthCheckInputPreparationContext<TInput>,
745
+ ) => TInput | Promise<TInput>;
746
+ /**
747
+ * Assertion executed against the operation's response and timing.
748
+ *
749
+ * - Throw to fail the case (recorded as `down`).
750
+ * - Return `{ status: "degraded", label }` to flag without failing.
751
+ * - Return `void` (implicit) for `ok`.
752
+ *
753
+ * MUST NOT access scheduler, recorder, or any runtime type — pure data
754
+ * + lambda only.
755
+ */
756
+ assertions: (
757
+ ctx: HealthCheckAssertionContext<TOutput>,
758
+ ) =>
759
+ | void
760
+ | Promise<void>
761
+ | HealthCheckCaseResult
762
+ | Promise<HealthCheckCaseResult>;
763
+ /** Declarative scenarios replace the imperative preparation and assertion hooks. */
764
+ scenario?: never;
765
+ }
766
+ | {
767
+ /** Declarative scenario executed by the health-monitor runtime. */
768
+ scenario: HealthScenario;
769
+ prepareInput?: never;
770
+ assertions?: never;
771
+ }
772
+ );
618
773
 
619
774
  /**
620
775
  * Operation-level health-check suite. At least one case is required when
@@ -718,26 +873,38 @@ export interface HealthMonitorProbeOverride {
718
873
  degradedThresholdMs?: number;
719
874
  }
720
875
 
876
+ export const VALID_OPERATION_ERROR_STATUSES = [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504] as const;
877
+
878
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
879
+
721
880
  export interface OperationErrorCode {
722
881
  code: string;
723
- status?: number;
882
+ status?: ProviderErrorStatus;
724
883
  description: string;
725
884
  retryable?: boolean;
726
885
  }
727
886
 
728
- export interface OperationDocMeta {
729
- titleKey?: ProviderLocaleKeyInput;
730
- descriptionKey?: ProviderLocaleKeyInput;
731
- summaryKey?: ProviderLocaleKeyInput;
732
- markdownKey?: ProviderLocaleKeyInput;
733
- normalizationNotesKeys?: ProviderLocaleKeyInput[];
734
- requestExample?: Record<string, unknown>;
735
- responseExample?: unknown;
736
- errorCodes?: OperationErrorCode[];
737
- }
738
-
739
887
  export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
740
888
 
889
+ export type StealthBrowser = "chrome" | "firefox" | "safari";
890
+
891
+ export type StealthOS = "windows" | "macos" | "linux" | "ios";
892
+
893
+ /** A supported, fully resolved browser/OS fingerprint pair. */
894
+ export type StealthProfileDescriptor =
895
+ | { browser: "chrome"; os: "windows" | "macos" | "linux" }
896
+ | { browser: "firefox"; os: "windows" | "macos" | "linux" }
897
+ | { browser: "safari"; os: "macos" | "ios" };
898
+
899
+ /**
900
+ * Browser/OS fingerprint selection. Chrome and macOS are the named defaults
901
+ * when their respective axes are omitted.
902
+ */
903
+ export type StealthProfileSelection =
904
+ | { browser?: "chrome"; os?: "windows" | "macos" | "linux" }
905
+ | { browser: "firefox"; os?: "windows" | "macos" | "linux" }
906
+ | { browser: "safari"; os?: "macos" | "ios" };
907
+
741
908
  export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
742
909
  export interface BrowserOptions {
743
910
  headless?: boolean;
@@ -747,9 +914,7 @@ export interface BrowserOptions {
747
914
  requireCdpPool?: boolean;
748
915
  }
749
916
 
750
- export interface StealthProfile {
751
- name: string;
752
- platform: StealthPlatform;
917
+ export type StealthProfile = StealthProfileDescriptor & {
753
918
  version: string;
754
919
  userAgent: string;
755
920
  tlsClientIdentifier?: string;
@@ -757,9 +922,14 @@ export interface StealthProfile {
757
922
  ja4?: string;
758
923
  h2Settings?: Record<string, unknown>;
759
924
  headerOrder?: string[];
760
- }
925
+ };
761
926
 
762
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
927
+ export type AuthMode =
928
+ | "none"
929
+ | "platform-managed"
930
+ | "credentials"
931
+ | "oauth2"
932
+ | "oauth2_proxied";
763
933
 
764
934
  export type ConnectionMode = AuthMode;
765
935
 
@@ -769,7 +939,27 @@ export type ProviderAccessVisibility = "public" | "early_access";
769
939
 
770
940
  export type ProviderProxyMode = "disabled" | "optional" | "required";
771
941
 
772
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
942
+ /**
943
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
944
+ * (a common mistake because the names collide with a well-known rebrand):
945
+ *
946
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
947
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
948
+ * endpoints). This is our own vendor. It is NOT the company formerly named
949
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
950
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
951
+ * credentials; geo/session encoded in the username, no allocation API.
952
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
953
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
954
+ * username params. A different company from `smartproxy` above.
955
+ * **@deprecated** — unused; no managed adapter. Declare a
956
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
957
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
958
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
959
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
960
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
961
+ */
962
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
773
963
 
774
964
  export type ProviderProxySessionAffinity =
775
965
  | "request"
@@ -783,7 +973,18 @@ export interface ProviderProxyPolicy {
783
973
  * certificate verification, and vendor allocator endpoints are SDK-owned.
784
974
  */
785
975
  mode: ProviderProxyMode;
976
+ /**
977
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
978
+ * chain. A single-element `providers` list is equivalent to this field.
979
+ */
786
980
  provider?: ProviderProxyProvider;
981
+ /**
982
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
983
+ * fails over to the next when a vendor lacks credentials or its allocation /
984
+ * transport is exhausted. When omitted, `provider` (or the platform default)
985
+ * is used as a single-vendor chain.
986
+ */
987
+ providers?: ProviderProxyProvider[];
787
988
  geo?: {
788
989
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
789
990
  country?: Iso3166Alpha2CountryCode;
@@ -794,6 +995,12 @@ export interface ProviderProxyPolicy {
794
995
  affinity?: ProviderProxySessionAffinity;
795
996
  lifetimeMinutes?: number;
796
997
  poolSize?: number;
998
+ /**
999
+ * Seconds before hard sticky expiry at which native connections receive
1000
+ * the `expiring` event so the provider can drain and reconnect cleanly.
1001
+ * Declared by the provider; the SDK does not assume a default cut point.
1002
+ */
1003
+ drainLeadSeconds?: number;
797
1004
  };
798
1005
  }
799
1006
 
@@ -804,13 +1011,12 @@ export interface ProviderAccessConfig {
804
1011
  * Provider-level rollout visibility.
805
1012
  *
806
1013
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
807
- * the existing provider policy stack.
1014
+ * the existing provider policy stack.
808
1015
  * - `early_access`: hidden from public discovery and callable only when the
809
- * active customer organization has a provider-level access grant.
1016
+ * active customer organization has a provider-level access grant.
810
1017
  *
811
1018
  * This is intentionally provider-level only. It does not alter auth mode,
812
- * operation schemas, health-check authoring, `openWorld`, or Connection
813
- * requirements.
1019
+ * operation schemas, health-check authoring, or Connection requirements.
814
1020
  */
815
1021
  visibility?: ProviderAccessVisibility;
816
1022
  }
@@ -828,12 +1034,12 @@ export type ProviderLogoProfile =
828
1034
  */
829
1035
  url?: string;
830
1036
  background?: string;
831
- }
1037
+ }
832
1038
  | {
833
1039
  source: "monogram" | "none";
834
1040
  background?: string;
835
1041
  fallbackReason: string;
836
- };
1042
+ };
837
1043
 
838
1044
  export type ProviderPublicConnectionMode =
839
1045
  | "apifuse_managed"
@@ -887,6 +1093,10 @@ export interface ProviderMeta {
887
1093
  publicProfile?: ProviderPublicProfile;
888
1094
  contract?: {
889
1095
  publicSchemaFieldNames?: "normalized";
1096
+ readonly pinnedWireFieldPaths?: readonly {
1097
+ readonly path: string;
1098
+ readonly reason: string;
1099
+ }[];
890
1100
  };
891
1101
  }
892
1102
 
@@ -970,6 +1180,11 @@ export interface HttpRetrySummary {
970
1180
  export interface RequestOptions {
971
1181
  headers?: Record<string, string>;
972
1182
  params?: RequestParams;
1183
+ /**
1184
+ * Query parameters whose values contain credentials or other secret material.
1185
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1186
+ */
1187
+ sensitiveParams?: Record<string, string>;
973
1188
  proxy?: string;
974
1189
  timeout?: number;
975
1190
  /**
@@ -978,8 +1193,32 @@ export interface RequestOptions {
978
1193
  */
979
1194
  throwOnHttpError?: boolean;
980
1195
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1196
+ /**
1197
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1198
+ * evaluated before the next request is issued. Existing callers that omit
1199
+ * this policy retain the native fetch redirect behavior.
1200
+ */
1201
+ redirectPolicy?: HttpRedirectPolicy;
1202
+ }
1203
+
1204
+ export type RedirectRunReason =
1205
+ | "completed"
1206
+ | "stopped"
1207
+ | "max_hops"
1208
+ | "missing_location"
1209
+ | "loop";
1210
+
1211
+ export type HttpRedirectPolicyMode = "same-origin";
1212
+
1213
+ export interface HttpRedirectPolicy {
1214
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1215
+ mode: HttpRedirectPolicyMode;
1216
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1217
+ maxHops: number;
981
1218
  }
982
1219
 
1220
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
1221
+
983
1222
  export type HttpMethod =
984
1223
  | "HEAD"
985
1224
  | "head"
@@ -998,10 +1237,21 @@ export type HttpMethod =
998
1237
  | "PATCH"
999
1238
  | "patch";
1000
1239
 
1001
- export interface StealthFetchOptions extends RequestOptions {
1240
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy" | "headers"> {
1241
+ /**
1242
+ * Request headers. Array values and case-insensitive duplicate names are
1243
+ * combined in caller order using `", "`, matching Chrome's Fetch behavior.
1244
+ */
1245
+ headers?: Record<string, string | string[]>;
1002
1246
  method?: HttpMethod;
1003
1247
  body?: string | Buffer;
1004
1248
  redirect?: "follow" | "manual" | "error";
1249
+ /**
1250
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1251
+ * transport aborts the response and throws `response_too_large` if the
1252
+ * declared or streamed body exceeds this limit.
1253
+ */
1254
+ maxBodyBytes?: number;
1005
1255
  /**
1006
1256
  * Offsets policy-managed proxy pool selection for caller-managed retries.
1007
1257
  * Use when a request receives an upstream challenge page rather than a
@@ -1009,31 +1259,62 @@ export interface StealthFetchOptions extends RequestOptions {
1009
1259
  * operation-affinity proxy.
1010
1260
  */
1011
1261
  proxyAttemptOffset?: number;
1012
- /** Override the configured browser-like stealth profile for this request. */
1013
- profile?: string;
1014
1262
  /**
1015
- * Stealth transport certificate controls. Use only for proxy products that
1016
- * terminate CONNECT with a private CA instead of tunneling the origin
1017
- * certificate chain.
1263
+ * SDK-specific stealth controls. Standard HTTP metadata such as language,
1264
+ * referrer, and content type belongs in `headers`.
1018
1265
  */
1019
- stealth?: {
1266
+ stealth?: StealthProfileSelection & {
1267
+ /** Override the configured browser and/or OS for this request. */
1268
+ /** Declare the Chrome request class when it cannot be inferred from the method. */
1269
+ requestClass?: "navigation" | "xhr" | "post";
1270
+ /**
1271
+ * Use only for proxy products that terminate CONNECT with a private CA
1272
+ * instead of tunneling the origin certificate chain.
1273
+ */
1020
1274
  insecureSkipVerify?: boolean;
1021
1275
  };
1022
1276
  }
1023
1277
 
1024
1278
  export interface CookieJar {
1025
- get(name: string): string | undefined;
1026
- getAll(): Record<string, string>;
1027
- toString(): string;
1028
- find?(predicate: (cookie: string) => boolean): string | undefined;
1279
+ /** URL-less reads use the jar's response URL or session base URL. */
1280
+ get(name: string, url?: string): string | undefined;
1281
+ getAll(url?: string): Record<string, string>;
1282
+ toString(url?: string): string;
1283
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
1284
+ }
1285
+
1286
+ /**
1287
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1288
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1289
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1290
+ */
1291
+ export interface StealthCookieStoreV1 {
1292
+ readonly version: 1;
1293
+ readonly jar: SerializedCookieJar;
1029
1294
  }
1030
1295
 
1296
+ /** Cookie persistence formats understood by this SDK version. */
1297
+ export type StealthCookieStore = StealthCookieStoreV1;
1298
+
1031
1299
  export interface StealthSessionCookies extends CookieJar {
1032
- has(name: string): boolean;
1033
- setFromCookieStrings(cookieStrings: readonly string[]): void;
1034
- toHeader(): string;
1300
+ has(name: string, url?: string): boolean;
1301
+ /** URL-less writes are scoped to the session base URL. */
1302
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1303
+ toHeader(url?: string): string;
1304
+ /**
1305
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1306
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1307
+ */
1035
1308
  snapshot(): Record<string, string>;
1309
+ /**
1310
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1311
+ * @deprecated Use deserialize() with state produced by serialize().
1312
+ */
1036
1313
  restore(cookies: Record<string, string>): void;
1314
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1315
+ serialize(): StealthCookieStoreV1;
1316
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1317
+ deserialize(state: StealthCookieStore): void;
1037
1318
  clear(): void;
1038
1319
  }
1039
1320
 
@@ -1078,8 +1359,14 @@ export interface StealthRedirectRunOptions
1078
1359
  export interface StealthRedirectRunResult {
1079
1360
  final: StealthResponse;
1080
1361
  hops: StealthRedirectHop[];
1081
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1362
+ reason: RedirectRunReason;
1363
+ /**
1364
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1365
+ * @deprecated Use cookieStore for lossless persistence.
1366
+ */
1082
1367
  cookies: Record<string, string>;
1368
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1369
+ cookieStore: StealthCookieStoreV1;
1083
1370
  }
1084
1371
 
1085
1372
  export interface StealthSession {
@@ -1169,11 +1456,191 @@ export interface HttpClient {
1169
1456
  ): Promise<AsyncIterable<SseMessage>>;
1170
1457
  }
1171
1458
 
1459
+ /** Request-scoped file reference accepted by provider operation inputs. */
1460
+ export interface ProviderFileRef {
1461
+ readonly type: "request_file";
1462
+ readonly id: string;
1463
+ readonly filename: string;
1464
+ readonly mime_type?: string;
1465
+ readonly size: number;
1466
+ readonly sha256?: string;
1467
+ }
1468
+
1469
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1470
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1471
+ readonly mimeType?: string;
1472
+ arrayBuffer(): Promise<ArrayBuffer>;
1473
+ bytes(): Promise<Uint8Array>;
1474
+ stream(): ReadableStream<Uint8Array>;
1475
+ };
1476
+
1477
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1478
+ export interface ProviderFilesContext {
1479
+ has(input: string | ProviderFileRef): boolean;
1480
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1481
+ }
1482
+
1483
+ /** Where provider business logic executes relative to the capability engine. */
1484
+ export type ProviderRuntimeTarget = "vanilla" | "engine";
1485
+
1486
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1487
+
1488
+ export interface NativeTcpPortRange {
1489
+ readonly start: number;
1490
+ readonly end: number;
1491
+ }
1492
+
1493
+ /** Static native TCP egress declared by a provider. */
1494
+ export interface NativeTcpEgressRule {
1495
+ readonly host: string;
1496
+ readonly ports: readonly number[];
1497
+ readonly tls: NativeTcpTlsMode;
1498
+ }
1499
+
1500
+ /**
1501
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1502
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1503
+ * Dynamic rules must declare at least one target host selector through
1504
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1505
+ * sources and targets match only same-family selectors (except exact
1506
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1507
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1508
+ *
1509
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1510
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1511
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1512
+ * Every rule must declare a source host selector, source port list/range, and
1513
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1514
+ */
1515
+ export interface NativeTcpDynamicEgressRule {
1516
+ readonly sourceHost?: string;
1517
+ readonly sourceHostSuffixes?: readonly string[];
1518
+ readonly sourceIpv4Cidrs?: readonly string[];
1519
+ readonly sourceIpv6Cidrs?: readonly string[];
1520
+ readonly sourcePorts?: readonly number[];
1521
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1522
+ readonly targetHostSuffixes?: readonly string[];
1523
+ readonly targetIpv4Cidrs?: readonly string[];
1524
+ readonly targetIpv6Cidrs?: readonly string[];
1525
+ readonly targetPorts?: readonly number[];
1526
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1527
+ readonly tls: NativeTcpTlsMode;
1528
+ readonly ttlMs?: number;
1529
+ readonly maxGrants?: number;
1530
+ }
1531
+
1532
+ /** Common TCP/TLS connection input supported by the native runtime. */
1533
+ export interface NativeNetworkConnectInput {
1534
+ readonly host: string;
1535
+ readonly port: number;
1536
+ readonly serverName?: string;
1537
+ readonly rejectUnauthorized?: boolean;
1538
+ /**
1539
+ * Maximum time without a successful socket read before the connection is
1540
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1541
+ */
1542
+ readonly idleTimeoutMs?: number;
1543
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1544
+ readonly timeoutMs?: number;
1545
+ readonly signal?: AbortSignal;
1546
+ /** Overrides the credential-derived sticky affinity key. */
1547
+ readonly affinityKey?: string;
1548
+ }
1549
+
1550
+ export type NativeNetworkConnectOptions = Omit<
1551
+ NativeNetworkConnectInput,
1552
+ "serverName" | "rejectUnauthorized"
1553
+ >;
1554
+
1555
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1556
+
1557
+ export interface NativeNetworkDynamicGrantOptions {
1558
+ readonly sourceHost: string;
1559
+ readonly sourcePort: number;
1560
+ readonly host: string;
1561
+ readonly port: number;
1562
+ readonly tls: NativeTcpTlsMode;
1563
+ readonly ttlMs?: number;
1564
+ }
1565
+
1566
+ export interface NativeNetworkEgressGrant {
1567
+ revoke(): void;
1568
+ }
1569
+
1570
+ /** Consumer-facing alias used by native TCP providers. */
1571
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1572
+
1573
+ /** Resolved egress identity for a native connection routed through a proxy. */
1574
+ export interface NativeProxyEgressInfo {
1575
+ readonly vendor: ProviderProxyProvider;
1576
+ readonly sticky: boolean;
1577
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1578
+ readonly sessionId?: string;
1579
+ /** Hard expiry of the sticky binding, ISO 8601. */
1580
+ readonly expiresAt?: string;
1581
+ }
1582
+
1583
+ export type NativeProxyExpiringReason = "sticky_expiry";
1584
+
1585
+ export interface NativeProxyExpiringEvent {
1586
+ readonly expiresAt: string;
1587
+ readonly leadSeconds: number;
1588
+ readonly reason: NativeProxyExpiringReason;
1589
+ }
1590
+
1591
+ /**
1592
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1593
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1594
+ */
1595
+ export type NativeProxyDrainHandler = (
1596
+ event: NativeProxyExpiringEvent,
1597
+ ) => void | Promise<void>;
1598
+
1599
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1600
+ export interface NativeNetworkCloseReason {
1601
+ readonly code: string;
1602
+ readonly message: string;
1603
+ }
1604
+
1605
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1606
+ export interface NativeNetworkConnection {
1607
+ /** Present when the connection was routed through a proxy. */
1608
+ readonly proxy?: NativeProxyEgressInfo;
1609
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1610
+ readonly closeReason?: NativeNetworkCloseReason;
1611
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1612
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1613
+ read(): Promise<Uint8Array | null>;
1614
+ write(data: Uint8Array): Promise<void>;
1615
+ close(): Promise<void>;
1616
+ }
1617
+
1618
+ export interface NativeNetworkClient {
1619
+ connectTcp(
1620
+ input: NativeNetworkConnectOptions,
1621
+ ): Promise<NativeNetworkConnection>;
1622
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1623
+ grantTcpEgress(
1624
+ input: NativeNetworkDynamicGrantOptions,
1625
+ ): NativeNetworkEgressGrant;
1626
+ }
1627
+
1628
+ export interface NativeContext {
1629
+ readonly network: NativeNetworkClient;
1630
+ }
1631
+
1632
+ export interface NativeProviderConfig {
1633
+ readonly network?: {
1634
+ readonly tcp?: readonly NativeTcpEgressRule[];
1635
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1636
+ };
1637
+ }
1638
+
1172
1639
  export interface ProviderCacheKeyOptions {
1173
1640
  /**
1174
- * Additional field names to omit from stable key material. The SDK always
1175
- * omits known secret-bearing names such as serviceKey, authorization,
1176
- * cookie, token, password, and secret.
1641
+ * Additional field names whose values are hashed in stable key material. The
1642
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1643
+ * authorization, cookie, token, password, and secret.
1177
1644
  */
1178
1645
  redactFields?: string[];
1179
1646
  }
@@ -1233,7 +1700,7 @@ export interface ProviderCache {
1233
1700
 
1234
1701
  export interface StealthClient {
1235
1702
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
1236
- createSession(opts?: { profile?: string }): StealthSession;
1703
+ createSession(opts?: { stealth?: StealthProfileSelection }): StealthSession;
1237
1704
  close?(): void;
1238
1705
  }
1239
1706
 
@@ -1268,7 +1735,19 @@ export interface BrowserFrame {
1268
1735
  locator(selector: string): BrowserLocator;
1269
1736
  }
1270
1737
 
1271
- export type BrowserResourceMethod = "GET" | "HEAD";
1738
+ export interface BrowserCookie {
1739
+ readonly name: string;
1740
+ readonly value: string;
1741
+ readonly domain: string;
1742
+ readonly path: string;
1743
+ /** Unix seconds. Absent for a session cookie. */
1744
+ readonly expires?: number;
1745
+ readonly httpOnly: boolean;
1746
+ readonly secure: boolean;
1747
+ readonly sameSite?: "Strict" | "Lax" | "None";
1748
+ }
1749
+
1750
+ export type BrowserResourceMethod = "GET" | "HEAD" | "POST";
1272
1751
 
1273
1752
  export type BrowserResourceRequest = {
1274
1753
  readonly url: string;
@@ -1280,16 +1759,19 @@ export type BrowserResourceRequest = {
1280
1759
  export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1281
1760
 
1282
1761
  export type BrowserResourceDecision =
1762
+ | {
1763
+ readonly action: "continue";
1764
+ }
1283
1765
  | {
1284
1766
  readonly action: "fulfill";
1285
1767
  readonly status?: number;
1286
1768
  readonly headers?: Readonly<Record<string, string>>;
1287
1769
  readonly body?: BrowserResourceBody;
1288
- }
1770
+ }
1289
1771
  | {
1290
1772
  readonly action: "block";
1291
1773
  readonly reason?: string;
1292
- };
1774
+ };
1293
1775
 
1294
1776
  export type BrowserResourceRoute = {
1295
1777
  readonly match:
@@ -1304,13 +1786,30 @@ export type BrowserResourceRoute = {
1304
1786
  export type BrowserResourcePolicy = {
1305
1787
  readonly defaultAction?: "block";
1306
1788
  readonly allowedMethods?: readonly BrowserResourceMethod[];
1789
+ /**
1790
+ * Appends an enforcing CSP header to every renderable document response
1791
+ * while the policy is active. Existing CSP headers are retained, so this
1792
+ * can only further restrict the document.
1793
+ */
1794
+ readonly documentContentSecurityPolicy?: string;
1307
1795
  readonly routes: readonly BrowserResourceRoute[];
1308
1796
  };
1309
1797
 
1310
1798
  export interface BrowserPage extends BrowserFrame {
1311
1799
  close(): Promise<void>;
1800
+ /** Returns the user agent used by this page's browser context. */
1801
+ userAgent(): Promise<string>;
1802
+ /**
1803
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1804
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1805
+ */
1806
+ cookies(): Promise<readonly BrowserCookie[]>;
1312
1807
  fill(selector: string, text: string): Promise<void>;
1313
1808
  goto(url: string): Promise<void>;
1809
+ goto(
1810
+ url: string,
1811
+ options?: { readonly timeout?: number; readonly waitUntil?: "load" | "domcontentloaded" },
1812
+ ): Promise<void>;
1314
1813
  pageId?: string;
1315
1814
  screenshot(options?: { fullPage?: boolean }): Promise<Buffer>;
1316
1815
  click(selector: string): Promise<void>;
@@ -1359,7 +1858,7 @@ export interface TraceConfig {
1359
1858
  exporter?: "console" | "json" | "otlp" | "none";
1360
1859
  endpoint?: string;
1361
1860
  otlp?: {
1362
- endpoint: string;
1861
+ endpoint?: string;
1363
1862
  headers?: Record<string, string>;
1364
1863
  timeout?: number;
1365
1864
  };
@@ -1398,10 +1897,32 @@ export interface ProviderChoiceBindingOptions {
1398
1897
  credentialKeys?: readonly string[];
1399
1898
  }
1400
1899
 
1900
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1901
+
1902
+ export type ProviderChoiceConsumeResult =
1903
+ | { readonly status: "consumed" }
1904
+ | { readonly status: "already-consumed" }
1905
+ | { readonly status: "unsupported" };
1906
+
1907
+ export type ProviderChoiceExplicitParseResult =
1908
+ | {
1909
+ readonly status: "active";
1910
+ readonly payload: Record<string, unknown>;
1911
+ /** Stable, opaque key for provider-owned idempotency records. */
1912
+ readonly replayKey: string;
1913
+ /** Atomically claims a word token. Inline tokens report unsupported. */
1914
+ consume(): Promise<ProviderChoiceConsumeResult>;
1915
+ }
1916
+ | {
1917
+ readonly status: "consumed";
1918
+ /** Use this key to read the provider-owned result before returning an error. */
1919
+ readonly replayKey: string;
1920
+ };
1921
+
1401
1922
  export type ProviderChoiceStorageOptions =
1402
1923
  | {
1403
1924
  readonly mode: "inline";
1404
- }
1925
+ }
1405
1926
  | {
1406
1927
  readonly mode: "server";
1407
1928
  readonly namespace: string;
@@ -1410,7 +1931,7 @@ export type ProviderChoiceStorageOptions =
1410
1931
  readonly maxEntries: number;
1411
1932
  readonly maxValueBytes: number;
1412
1933
  readonly unavailable?: "reject";
1413
- }
1934
+ }
1414
1935
  | {
1415
1936
  readonly mode: "auto";
1416
1937
  readonly namespace: string;
@@ -1420,7 +1941,7 @@ export type ProviderChoiceStorageOptions =
1420
1941
  readonly maxEntries: number;
1421
1942
  readonly maxValueBytes: number;
1422
1943
  readonly unavailable?: "reject";
1423
- };
1944
+ };
1424
1945
 
1425
1946
  export interface ProviderChoiceIssueOptions<
1426
1947
  TPayload extends Record<string, unknown>,
@@ -1431,6 +1952,8 @@ export interface ProviderChoiceIssueOptions<
1431
1952
  ttlMs: number;
1432
1953
  nowMs?: number;
1433
1954
  bind?: ProviderChoiceBindingOptions;
1955
+ /** Server storage only: standard emits four words; high emits five. */
1956
+ strength?: "standard" | "high";
1434
1957
  storage?: ProviderChoiceStorageOptions;
1435
1958
  }
1436
1959
 
@@ -1443,6 +1966,8 @@ export interface ProviderChoiceParseOptions {
1443
1966
  futureToleranceMs?: number;
1444
1967
  bind?: ProviderChoiceBindingOptions;
1445
1968
  storage?: ProviderChoiceStorageOptions;
1969
+ /** Defaults to never, preserving reusable choice-token parse semantics. */
1970
+ consume?: ProviderChoiceConsumeMode;
1446
1971
  }
1447
1972
 
1448
1973
  export interface ProviderChoiceContext {
@@ -1470,6 +1995,9 @@ export interface ProviderChoiceContext {
1470
1995
  issue<TPayload extends Record<string, unknown>>(
1471
1996
  options: ProviderChoiceIssueOptions<TPayload>,
1472
1997
  ): string | Promise<string>;
1998
+ parse(
1999
+ options: ProviderChoiceParseOptions & { readonly consume: "explicit" },
2000
+ ): Promise<ProviderChoiceExplicitParseResult>;
1473
2001
  parse(
1474
2002
  options: ProviderChoiceParseOptions & {
1475
2003
  readonly storage?: { readonly mode: "inline" };
@@ -1491,7 +2019,11 @@ export interface ProviderChoiceContext {
1491
2019
  >;
1492
2020
  },
1493
2021
  ): Record<string, unknown> | Promise<Record<string, unknown>>;
1494
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
2022
+ parse(
2023
+ options: ProviderChoiceParseOptions,
2024
+ ):
2025
+ | Record<string, unknown>
2026
+ | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1495
2027
  }
1496
2028
 
1497
2029
  export interface ContextScratchpad {
@@ -1564,11 +2096,11 @@ export interface AuthFlowTerminalContext {
1564
2096
  }
1565
2097
  >;
1566
2098
  readonly expectedInput?: never;
1567
- }
2099
+ }
1568
2100
  | {
1569
2101
  readonly expectedInput: Record<string, unknown>;
1570
2102
  readonly fields?: never;
1571
- }
2103
+ }
1572
2104
  ),
1573
2105
  ): AuthTurn;
1574
2106
  nextPoll(options?: {
@@ -1581,16 +2113,34 @@ export interface AuthFlowTerminalContext {
1581
2113
  }
1582
2114
 
1583
2115
  export interface FlowContext {
2116
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
2117
+ flowId?: string;
1584
2118
  connectionId?: string;
1585
2119
  externalRef?: string;
1586
2120
  tenantId: string;
1587
2121
  providerId: string;
1588
2122
  http: HttpClient;
2123
+ /** Durable connection-scoped runtime state. Present when the host runtime
2124
+ * supplies one; auth ceremonies must fail closed when absent rather than
2125
+ * fall back to bypassable in-process storage.
2126
+ *
2127
+ * Scoped via `ProviderRuntimeState.forConnection`: requests that resolve no
2128
+ * connection id (pre-connection ceremonies such as first-time logins) share
2129
+ * the documented isolated missing-connection scope. That sharing is the
2130
+ * intended semantic — it lets counters keyed by caller identity (e.g. a
2131
+ * login email) persist across separate ceremonies for the same caller.
2132
+ * Flows storing entries in that scope MUST key them by caller identity;
2133
+ * un-keyed entries would be shared across all connectionless ceremonies. */
2134
+ readonly state?: ProviderRuntimeState;
2135
+ /** Present when the selected runtime supplies native network capabilities. */
2136
+ readonly native?: NativeContext;
1589
2137
  stealth: StealthClient;
1590
2138
  env: EnvContext;
1591
2139
  credential?: CredentialContext;
1592
2140
  context: ContextScratchpad;
2141
+ ocr: OcrContext;
1593
2142
  stt: SttContext;
2143
+ resolver: ResolverContext;
1594
2144
  auth: AuthFlowTerminalContext;
1595
2145
  }
1596
2146
 
@@ -1633,7 +2183,14 @@ export type ProviderStateDurationString =
1633
2183
  | `${number}${"ms" | "s" | "m" | "h" | "d"}`
1634
2184
  | `PT${string}`;
1635
2185
 
2186
+ export type StateNamespaceScope = "connection" | "provider";
2187
+
1636
2188
  export interface StateNamespaceOptions {
2189
+ /**
2190
+ * State isolation boundary. Connection scope is the default; provider scope
2191
+ * must be selected explicitly for provider-wide coordination state.
2192
+ */
2193
+ scope?: StateNamespaceScope;
1637
2194
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1638
2195
  defaultTtl: ProviderStateDurationString;
1639
2196
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1694,29 +2251,70 @@ export interface ProviderStateNamespace {
1694
2251
  }
1695
2252
 
1696
2253
  export interface ProviderRuntimeState {
2254
+ /**
2255
+ * Returns an immutable view bound to one request connection. An unresolved
2256
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
2257
+ */
2258
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1697
2259
  namespace(
1698
2260
  name: string,
1699
2261
  options: StateNamespaceOptions,
1700
2262
  ): ProviderStateNamespace;
1701
2263
  }
1702
2264
 
1703
- export interface ProviderContext {
1704
- env: EnvContext;
1705
- credential: CredentialContext;
2265
+ /**
2266
+ * The operation context exposed for one provider declaration. Capability
2267
+ * bindings are present only when their corresponding declaration is present;
2268
+ * trace and request remain ambient runtime bindings. Omitting the type
2269
+ * parameter preserves the legacy full context shape for existing annotations.
2270
+ */
2271
+ export type ProviderContext<TConfig = Record<string, unknown>> = {
1706
2272
  request?: ProviderRequestContext;
1707
- http: HttpClient;
1708
- cache: ProviderCache;
1709
- state: ProviderRuntimeState;
1710
- stealth: StealthClient;
1711
- browser: BrowserClient;
1712
2273
  trace: TraceContext;
1713
- auth: AuthContext;
1714
- stt: SttContext;
1715
- choice: ProviderChoiceContext;
2274
+ }
2275
+ & ("env" extends keyof TConfig ? { env: EnvContext } : Record<never, never>)
2276
+ & ("credential" extends keyof TConfig
2277
+ ? { credential: CredentialContext }
2278
+ : Record<never, never>)
2279
+ & ("http" extends keyof TConfig ? { http: HttpClient } : Record<never, never>)
2280
+ & ("files" extends keyof TConfig
2281
+ ? string extends keyof TConfig
2282
+ ? { readonly files?: ProviderFilesContext }
2283
+ : { readonly files: ProviderFilesContext }
2284
+ : Record<never, never>)
2285
+ & ("native" extends keyof TConfig
2286
+ ? { readonly native: NativeContext }
2287
+ : Record<never, never>)
2288
+ & ("cache" extends keyof TConfig ? { cache: ProviderCache } : Record<never, never>)
2289
+ & ("state" extends keyof TConfig ? { state: ProviderRuntimeState } : Record<never, never>)
2290
+ & ("stealth" extends keyof TConfig ? { stealth: StealthClient } : Record<never, never>)
2291
+ & ("browser" extends keyof TConfig ? { browser: BrowserClient } : Record<never, never>)
2292
+ & ("auth" extends keyof TConfig ? { auth: AuthContext } : Record<never, never>)
2293
+ & ("ocr" extends keyof TConfig ? { ocr: OcrContext } : Record<never, never>)
2294
+ & ("stt" extends keyof TConfig ? { stt: SttContext } : Record<never, never>)
2295
+ & ("resolver" extends keyof TConfig ? { resolver: ResolverContext } : Record<never, never>)
2296
+ & ("choice" extends keyof TConfig
2297
+ ? { choice: ProviderChoiceContext }
2298
+ : Record<never, never>);
2299
+
2300
+ /** Backwards-compatible name for a declaration-derived provider context. */
2301
+ export type ProviderContextFor<TConfig> = ProviderContext<TConfig>;
2302
+
2303
+ export interface ProxiedOAuthConfig {
2304
+ authorizeUrl: string;
2305
+ tokenUrl: string;
2306
+ customScheme: string;
2307
+ rewriteProfile: string;
2308
+ clientIdEnvKey: string;
2309
+ pkce?: "S256" | "none";
2310
+ authorizeParams?: Record<string, string>;
2311
+ tokenParams?: Record<string, string>;
1716
2312
  }
1717
2313
 
1718
2314
  export interface AuthConfig {
1719
2315
  mode: AuthMode;
2316
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
2317
+ proxied?: ProxiedOAuthConfig;
1720
2318
  flow?: AuthFlowDefinition;
1721
2319
  }
1722
2320
 
@@ -1758,38 +2356,35 @@ export interface OperationContractMetadata {
1758
2356
  export interface OperationDefinition<
1759
2357
  TInput extends SchemaLike = SchemaLike,
1760
2358
  TOutput extends SchemaLike = SchemaLike,
2359
+ TContext = ProviderContext,
1761
2360
  > {
1762
- /**
1763
- * Short English display title for the operation. The SDK passes it through
1764
- * verbatim; the APIFuse registry derives the operation's en locale title
1765
- * baseline from it (`docs.titleKey` remains available as an explicit key
1766
- * override).
1767
- */
1768
- title?: string;
1769
- /**
1770
- * Raw English operation description. The SDK passes it through verbatim;
1771
- * keyed descriptions via `descriptionKey` remain the primary flow, and
1772
- * provider lint rules for raw prose descriptions still apply.
1773
- */
1774
- description?: string;
2361
+ /** Canonical operation-level connection requirement. */
2362
+ connectionMode?: "none" | "optional" | "required";
2363
+ /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
2364
+ connectionExternalRefParam?: string;
2365
+ /** Safety source of truth exposed to clients and approval policy. */
2366
+ riskClass: OperationRiskClass;
2367
+ /** Approval override. Omit when the risk-class default is correct. */
2368
+ approval?: OperationApprovalPolicy;
2369
+ timeoutMs?: number;
2370
+ titleKey?: ProviderLocaleKeyInput;
1775
2371
  descriptionKey?: ProviderLocaleKeyInput;
1776
- docs?: OperationDocMeta;
2372
+ summaryKey?: ProviderLocaleKeyInput;
2373
+ markdownKey?: ProviderLocaleKeyInput;
1777
2374
  whenToUseKeys?: readonly ProviderLocaleKeyInput[];
1778
2375
  whenNotToUseKeys?: readonly ProviderLocaleKeyInput[];
1779
- derivations?: Record<string, string>;
1780
- inputExamples?: readonly OperationInputExample[];
1781
- annotations?: OperationAnnotations;
2376
+ normalizationNotesKeys?: readonly ProviderLocaleKeyInput[];
2377
+ errorCodes?: readonly OperationErrorCode[];
2378
+ examples?: readonly OperationExample[];
1782
2379
  contract?: OperationContractMetadata;
1783
2380
  tags?: readonly string[];
1784
2381
  relatedOperations?: OperationRelationships;
1785
- toolRouter?: OperationToolRouterMetadata;
1786
2382
  observability?: OperationObservabilityConfig;
1787
2383
  transport?: OperationTransport;
1788
- retryOnAuthRefresh?: boolean;
1789
2384
  input: TInput;
1790
2385
  output: TOutput;
1791
2386
  handler(
1792
- ctx: ProviderContext,
2387
+ ctx: TContext,
1793
2388
  input: InferSchemaOutput<TInput>,
1794
2389
  ):
1795
2390
  | OperationHandlerResult<InferSchemaOutput<TOutput>>
@@ -1797,6 +2392,11 @@ export interface OperationDefinition<
1797
2392
  fixtures?: {
1798
2393
  request: InferSchemaOutput<TInput>;
1799
2394
  response: InferSchemaOutput<TOutput>;
2395
+ /**
2396
+ * KST calendar date when `response` evidence was captured. Date fields in
2397
+ * the response align with this date, not a resolved relative request date.
2398
+ */
2399
+ recordedAt?: string;
1800
2400
  };
1801
2401
  upstream?: {
1802
2402
  baseUrl?: string;
@@ -1849,34 +2449,48 @@ export interface ProviderDeploymentOverrides {
1849
2449
  buildContext?: string;
1850
2450
  }
1851
2451
 
1852
- export interface ProviderDefinition {
2452
+ export interface ProviderDefinition<TContext = ProviderContext> {
1853
2453
  id: string;
1854
2454
  version: string;
1855
2455
  runtime: "standard" | "shared" | "browser";
2456
+ /**
2457
+ * `vanilla` executes provider business logic outside the engine; `engine`
2458
+ * keeps session-bearing provider logic in the engine process.
2459
+ *
2460
+ * Omitted only for definitions authored before the engine migration. New
2461
+ * providers should declare the target explicitly.
2462
+ */
2463
+ runtimeTarget?: ProviderRuntimeTarget;
1856
2464
  /**
1857
2465
  * Optional deployment overrides, passed through verbatim from
1858
2466
  * `defineProvider({ deployment })`. Validation and profile resolution are
1859
2467
  * owned by the APIFuse registry builder, not the SDK.
1860
2468
  */
1861
2469
  deployment?: ProviderDeploymentOverrides;
2470
+ http?: Record<string, never> | true;
1862
2471
  allowedHosts?: string[];
1863
- stealth?: {
1864
- profile: string;
1865
- platform: StealthPlatform;
1866
- };
2472
+ native?: NativeProviderConfig;
2473
+ stealth?: StealthProfileSelection;
1867
2474
  proxy?: ProviderProxyConfig;
2475
+ ocr?: ProviderOcrConfig;
1868
2476
  stt?: ProviderSttConfig;
2477
+ resolver?: ProviderResolverConfig;
1869
2478
  browser?: {
1870
2479
  engine: BrowserEngine;
1871
2480
  };
1872
2481
  auth?: AuthConfig;
2482
+ choice?: Record<string, never> | true;
1873
2483
  reviewed?: ProviderReviewed;
1874
2484
  access?: ProviderAccessConfig;
1875
2485
  secrets?: ProviderSecretDeclaration[];
2486
+ env?: Record<string, never> | true;
1876
2487
  credential?: CredentialDeclaration;
1877
2488
  context?: ContextDeclaration;
2489
+ state?: Record<string, never> | true;
2490
+ cache?: Record<string, never> | true;
2491
+ files?: Record<string, never> | true;
1878
2492
  meta: ProviderMeta;
1879
- operations: Record<string, OperationDefinition<SchemaLike, SchemaLike>>;
2493
+ operations: Record<string, OperationDefinition<SchemaLike, SchemaLike, TContext>>;
1880
2494
  healthMonitor?: ProviderHealthMonitorConfig;
1881
2495
  /** Transitional alias for `healthMonitor`; `defineProvider` mirrors both. */
1882
2496
  healthProbe?: ProviderHealthProbeConfig;