@apifuse/provider-sdk 2.2.0-beta.7 → 2.2.0-beta.70

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 (478) hide show
  1. package/AUTHORING.md +943 -51
  2. package/CHANGELOG.md +273 -1
  3. package/LICENSE +21 -0
  4. package/README.md +117 -29
  5. package/SUBMISSION.md +3 -2
  6. package/bin/apifuse-check.ts +293 -13
  7. package/bin/apifuse-dev.ts +42 -19
  8. package/bin/apifuse-migrate-deployment.ts +200 -0
  9. package/bin/apifuse-migrate-operation-declaration.ts +55 -0
  10. package/bin/apifuse-migrate-shape.ts +202 -0
  11. package/bin/apifuse-pack-check.ts +19 -6
  12. package/bin/apifuse-pack-smoke.ts +57 -2
  13. package/bin/apifuse-pack-types.ts +736 -38
  14. package/bin/apifuse-perf.ts +59 -23
  15. package/bin/apifuse-record.ts +923 -94
  16. package/bin/apifuse-submit-check.ts +2313 -281
  17. package/bin/apifuse-test.ts +3 -1
  18. package/bin/submit-check-delimited-text.ts +50 -0
  19. package/dist/auth-turn/index.d.ts +3 -3
  20. package/dist/auth-turn/index.js +1 -1
  21. package/dist/auth.d.ts +14 -0
  22. package/dist/auth.js +67 -0
  23. package/dist/ceremonies/index.d.ts +16 -0
  24. package/dist/ceremonies/index.js +141 -36
  25. package/dist/cli/commands.d.ts +1 -1
  26. package/dist/cli/commands.js +30 -0
  27. package/dist/cli/create.d.ts +1 -1
  28. package/dist/cli/create.js +8 -2
  29. package/dist/cli/deployment-intent.d.ts +178 -0
  30. package/dist/cli/deployment-intent.js +277 -0
  31. package/dist/cli/local-connection.d.ts +111 -0
  32. package/dist/cli/local-connection.js +151 -0
  33. package/dist/cli/migrate-deployment-intent.d.ts +132 -0
  34. package/dist/cli/migrate-deployment-intent.js +1552 -0
  35. package/dist/cli/migrate-operation-declaration.d.ts +70 -0
  36. package/dist/cli/migrate-operation-declaration.js +2206 -0
  37. package/dist/cli/migrate-operation-shape.d.ts +44 -0
  38. package/dist/cli/migrate-operation-shape.js +113 -0
  39. package/dist/cli/migrate-provider-shape.d.ts +56 -0
  40. package/dist/cli/migrate-provider-shape.js +580 -0
  41. package/dist/cli/resolver-runtime.d.ts +21 -0
  42. package/dist/cli/resolver-runtime.js +31 -0
  43. package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +141 -23
  44. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  45. package/dist/cli/templates/provider/README.md.tpl +41 -19
  46. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  47. package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
  48. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  49. package/dist/config/loader.d.ts +202 -16
  50. package/dist/config/loader.js +491 -141
  51. package/dist/contract-serialization.js +4 -8
  52. package/dist/contract-types.d.ts +12 -5
  53. package/dist/contract.js +24 -10
  54. package/dist/declaration-validation.d.ts +34 -0
  55. package/dist/declaration-validation.js +305 -0
  56. package/dist/define.d.ts +71 -29
  57. package/dist/define.js +807 -69
  58. package/dist/dev.d.ts +5 -0
  59. package/dist/dev.js +8 -1
  60. package/dist/engine.d.ts +129 -0
  61. package/dist/engine.js +209 -0
  62. package/dist/error-observability.d.ts +7 -0
  63. package/dist/error-observability.js +61 -0
  64. package/dist/error-resolution.d.ts +18 -0
  65. package/dist/error-resolution.js +243 -0
  66. package/dist/errors.d.ts +74 -0
  67. package/dist/errors.js +99 -0
  68. package/dist/fixture-sanitization.d.ts +28 -0
  69. package/dist/fixture-sanitization.js +371 -0
  70. package/dist/handle-meta.d.ts +90 -0
  71. package/dist/handle-meta.js +73 -0
  72. package/dist/handle.d.ts +226 -0
  73. package/dist/handle.js +345 -0
  74. package/dist/health-scenario.d.ts +1901 -0
  75. package/dist/health-scenario.js +653 -0
  76. package/dist/i18n/catalog.js +21 -1
  77. package/dist/i18n/error-messages.d.ts +86 -0
  78. package/dist/i18n/error-messages.js +192 -0
  79. package/dist/i18n/index.d.ts +1 -0
  80. package/dist/i18n/index.js +1 -0
  81. package/dist/i18n/keys.d.ts +12 -0
  82. package/dist/i18n/keys.js +76 -5
  83. package/dist/i18n/operation-locale-namespace.d.ts +2 -0
  84. package/dist/i18n/operation-locale-namespace.js +7 -0
  85. package/dist/index.d.ts +40 -15
  86. package/dist/index.js +29 -11
  87. package/dist/lint.d.ts +43 -11
  88. package/dist/lint.js +2512 -177
  89. package/dist/native-address.d.ts +43 -0
  90. package/dist/native-address.js +281 -0
  91. package/dist/native-egress-policy.d.ts +31 -0
  92. package/dist/native-egress-policy.js +288 -0
  93. package/dist/observability.d.ts +5 -2
  94. package/dist/observability.js +48 -1
  95. package/dist/provider.d.ts +18 -8
  96. package/dist/provider.js +11 -6
  97. package/dist/runtime/auth-flow.d.ts +6 -1
  98. package/dist/runtime/auth-flow.js +8 -0
  99. package/dist/runtime/bounded-expiring-map.d.ts +21 -0
  100. package/dist/runtime/bounded-expiring-map.js +64 -0
  101. package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
  102. package/dist/runtime/browser-telemetry-binding.js +83 -0
  103. package/dist/runtime/browser-telemetry.d.ts +76 -0
  104. package/dist/runtime/browser-telemetry.js +165 -0
  105. package/dist/runtime/browser.d.ts +4 -0
  106. package/dist/runtime/browser.js +688 -83
  107. package/dist/runtime/cache-telemetry.d.ts +71 -0
  108. package/dist/runtime/cache-telemetry.js +177 -0
  109. package/dist/runtime/cache.d.ts +3 -0
  110. package/dist/runtime/cache.js +245 -23
  111. package/dist/runtime/capability-response.d.ts +3 -0
  112. package/dist/runtime/capability-response.js +56 -0
  113. package/dist/runtime/capability-telemetry.d.ts +46 -0
  114. package/dist/runtime/capability-telemetry.js +68 -0
  115. package/dist/runtime/chrome149-header-order.d.ts +58 -0
  116. package/dist/runtime/chrome149-header-order.js +289 -0
  117. package/dist/runtime/diagnostic-env-values.d.ts +5 -0
  118. package/dist/runtime/diagnostic-env-values.js +57 -0
  119. package/dist/runtime/diagnostic-env.d.ts +14 -0
  120. package/dist/runtime/diagnostic-env.js +44 -0
  121. package/dist/runtime/diagnostic-redactor.d.ts +54 -0
  122. package/dist/runtime/diagnostic-redactor.js +571 -0
  123. package/dist/runtime/egress-lease.d.ts +65 -0
  124. package/dist/runtime/egress-lease.js +236 -0
  125. package/dist/runtime/engine-mode.d.ts +74 -0
  126. package/dist/runtime/engine-mode.js +152 -0
  127. package/dist/runtime/env.js +14 -1
  128. package/dist/runtime/executor.d.ts +3 -2
  129. package/dist/runtime/executor.js +23 -26
  130. package/dist/runtime/handle-wordlist.d.ts +43 -0
  131. package/dist/runtime/handle-wordlist.js +256 -0
  132. package/dist/runtime/handle.d.ts +71 -0
  133. package/dist/runtime/handle.js +908 -0
  134. package/dist/runtime/http-telemetry-binding.d.ts +10 -0
  135. package/dist/runtime/http-telemetry-binding.js +152 -0
  136. package/dist/runtime/http-telemetry-guard.d.ts +16 -0
  137. package/dist/runtime/http-telemetry-guard.js +202 -0
  138. package/dist/runtime/http-telemetry.d.ts +104 -0
  139. package/dist/runtime/http-telemetry.js +190 -0
  140. package/dist/runtime/http.d.ts +34 -0
  141. package/dist/runtime/http.js +680 -121
  142. package/dist/runtime/insights.js +2 -2
  143. package/dist/runtime/instrumentation.d.ts +2 -2
  144. package/dist/runtime/instrumentation.js +462 -19
  145. package/dist/runtime/native-network-errors.d.ts +33 -0
  146. package/dist/runtime/native-network-errors.js +69 -0
  147. package/dist/runtime/native-network.d.ts +105 -0
  148. package/dist/runtime/native-network.js +1433 -0
  149. package/dist/runtime/native-telemetry.d.ts +142 -0
  150. package/dist/runtime/native-telemetry.js +231 -0
  151. package/dist/runtime/ocr-telemetry.d.ts +82 -0
  152. package/dist/runtime/ocr-telemetry.js +192 -0
  153. package/dist/runtime/ocr.d.ts +29 -0
  154. package/dist/runtime/ocr.js +468 -0
  155. package/dist/runtime/otlp.d.ts +71 -2
  156. package/dist/runtime/otlp.js +398 -16
  157. package/dist/runtime/provider.d.ts +7 -0
  158. package/dist/runtime/provider.js +14 -0
  159. package/dist/runtime/proxy-errors.js +6 -2
  160. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  161. package/dist/runtime/proxy-nodemaven.js +147 -0
  162. package/dist/runtime/proxy-retry-policy.d.ts +4 -1
  163. package/dist/runtime/proxy-retry-policy.js +11 -2
  164. package/dist/runtime/proxy-telemetry.d.ts +133 -3
  165. package/dist/runtime/proxy-telemetry.js +218 -70
  166. package/dist/runtime/redirect-hop-headers.d.ts +19 -0
  167. package/dist/runtime/redirect-hop-headers.js +58 -0
  168. package/dist/runtime/redirects.d.ts +61 -0
  169. package/dist/runtime/redirects.js +149 -0
  170. package/dist/runtime/redis.d.ts +1 -1
  171. package/dist/runtime/redis.js +4 -2
  172. package/dist/runtime/request-options.d.ts +75 -1
  173. package/dist/runtime/request-options.js +588 -0
  174. package/dist/runtime/request-telemetry.d.ts +70 -0
  175. package/dist/runtime/request-telemetry.js +229 -0
  176. package/dist/runtime/resolver-config.d.ts +13 -0
  177. package/dist/runtime/resolver-config.js +14 -0
  178. package/dist/runtime/resolver-public.d.ts +3 -0
  179. package/dist/runtime/resolver-public.js +1 -0
  180. package/dist/runtime/resolver-runtime-options.d.ts +14 -0
  181. package/dist/runtime/resolver-runtime-options.js +33 -0
  182. package/dist/runtime/resolver-shared.d.ts +24 -0
  183. package/dist/runtime/resolver-shared.js +69 -0
  184. package/dist/runtime/resolver-span-attributes.d.ts +34 -0
  185. package/dist/runtime/resolver-span-attributes.js +93 -0
  186. package/dist/runtime/resolver-telemetry.d.ts +135 -0
  187. package/dist/runtime/resolver-telemetry.js +204 -0
  188. package/dist/runtime/resolver-usage.d.ts +32 -0
  189. package/dist/runtime/resolver-usage.js +54 -0
  190. package/dist/runtime/resolver-vendors/bindings.d.ts +53 -0
  191. package/dist/runtime/resolver-vendors/bindings.js +45 -0
  192. package/dist/runtime/resolver-vendors/browser.d.ts +24 -0
  193. package/dist/runtime/resolver-vendors/browser.js +423 -0
  194. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  195. package/dist/runtime/resolver-vendors/capsolver.js +544 -0
  196. package/dist/runtime/resolver-vendors/hosts.d.ts +23 -0
  197. package/dist/runtime/resolver-vendors/hosts.js +68 -0
  198. package/dist/runtime/resolver-vendors/hypersolutions.d.ts +27 -0
  199. package/dist/runtime/resolver-vendors/hypersolutions.js +369 -0
  200. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  201. package/dist/runtime/resolver-vendors/twocaptcha.js +425 -0
  202. package/dist/runtime/resolver-vendors/types.d.ts +125 -0
  203. package/dist/runtime/resolver-vendors/types.js +106 -0
  204. package/dist/runtime/resolver.d.ts +79 -0
  205. package/dist/runtime/resolver.js +1094 -0
  206. package/dist/runtime/state-telemetry.d.ts +79 -0
  207. package/dist/runtime/state-telemetry.js +194 -0
  208. package/dist/runtime/state.d.ts +10 -1
  209. package/dist/runtime/state.js +322 -82
  210. package/dist/runtime/stealth-akamai-sbsd.d.ts +54 -0
  211. package/dist/runtime/stealth-akamai-sbsd.js +142 -0
  212. package/dist/runtime/stealth-cookies.d.ts +24 -0
  213. package/dist/runtime/stealth-cookies.js +131 -0
  214. package/dist/runtime/stealth-owned-headers.d.ts +39 -0
  215. package/dist/runtime/stealth-owned-headers.js +57 -0
  216. package/dist/runtime/stealth-telemetry.d.ts +92 -0
  217. package/dist/runtime/stealth-telemetry.js +179 -0
  218. package/dist/runtime/stealth.d.ts +45 -6
  219. package/dist/runtime/stealth.js +1775 -320
  220. package/dist/runtime/stt-telemetry.d.ts +77 -0
  221. package/dist/runtime/stt-telemetry.js +176 -0
  222. package/dist/runtime/stt.js +18 -19
  223. package/dist/runtime/timeout.d.ts +5 -0
  224. package/dist/runtime/timeout.js +12 -0
  225. package/dist/runtime/trace-config.d.ts +12 -0
  226. package/dist/runtime/trace-config.js +62 -0
  227. package/dist/runtime/trace.d.ts +17 -0
  228. package/dist/runtime/trace.js +176 -25
  229. package/dist/runtime-boundary-lint.d.ts +137 -0
  230. package/dist/runtime-boundary-lint.js +590 -0
  231. package/dist/schema.d.ts +20 -0
  232. package/dist/schema.js +72 -2
  233. package/dist/serve.d.ts +1 -1
  234. package/dist/serve.js +1 -1
  235. package/dist/server/error-observability.d.ts +1 -0
  236. package/dist/server/error-observability.js +1 -0
  237. package/dist/server/error-stack-frames.d.ts +35 -0
  238. package/dist/server/error-stack-frames.js +219 -0
  239. package/dist/server/index.d.ts +21 -2
  240. package/dist/server/index.js +11 -2
  241. package/dist/server/runtime-diagnostics.d.ts +165 -0
  242. package/dist/server/runtime-diagnostics.js +360 -0
  243. package/dist/server/sdk-version.d.ts +3 -0
  244. package/dist/server/sdk-version.js +19 -0
  245. package/dist/server/self-test-input-tokens.d.ts +2 -1
  246. package/dist/server/self-test-input-tokens.js +18 -14
  247. package/dist/server/self-test-redaction.js +8 -33
  248. package/dist/server/self-test.d.ts +18 -3
  249. package/dist/server/self-test.js +139 -76
  250. package/dist/server/sensitive-values.d.ts +26 -0
  251. package/dist/server/sensitive-values.js +137 -0
  252. package/dist/server/serve-implementation.d.ts +285 -0
  253. package/dist/server/serve-implementation.js +3172 -0
  254. package/dist/server/serve.d.ts +1 -75
  255. package/dist/server/serve.js +1 -1170
  256. package/dist/server/state-backend-report.d.ts +70 -0
  257. package/dist/server/state-backend-report.js +113 -0
  258. package/dist/server/trace-output.d.ts +7 -0
  259. package/dist/server/trace-output.js +111 -0
  260. package/dist/server/types.d.ts +37 -5
  261. package/dist/server/types.js +34 -1
  262. package/dist/stateful/errors.d.ts +19 -0
  263. package/dist/stateful/errors.js +24 -0
  264. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  265. package/dist/stateful/http-provider-event-emitter.js +237 -0
  266. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  267. package/dist/stateful/http-session-owner-registry.js +210 -0
  268. package/dist/stateful/index.d.ts +18 -0
  269. package/dist/stateful/index.js +18 -0
  270. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  271. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  272. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  273. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  274. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  275. package/dist/stateful/provider-event-pipeline.js +1 -0
  276. package/dist/stateful/provider-events.d.ts +101 -0
  277. package/dist/stateful/provider-events.js +289 -0
  278. package/dist/stateful/session-key.d.ts +15 -0
  279. package/dist/stateful/session-key.js +86 -0
  280. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  281. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  282. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  283. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  284. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  285. package/dist/stateful/stateful-provider-adapter.js +287 -0
  286. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  287. package/dist/stateful/stateful-provider-observability.js +161 -0
  288. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  289. package/dist/stateful/stateful-provider-owner-forwarder.js +237 -0
  290. package/dist/stateful/stateful-provider-runtime-context.d.ts +35 -0
  291. package/dist/stateful/stateful-provider-runtime-context.js +61 -0
  292. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  293. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  294. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  295. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  296. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  297. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  298. package/dist/stateful-signing.d.ts +18 -0
  299. package/dist/stateful-signing.js +27 -0
  300. package/dist/stealth/profiles.d.ts +15 -4
  301. package/dist/stealth/profiles.js +169 -211
  302. package/dist/stream-evidence.d.ts +74 -0
  303. package/dist/stream-evidence.js +785 -0
  304. package/dist/stream.js +7 -1
  305. package/dist/testing/index.d.ts +2 -1
  306. package/dist/testing/index.js +2 -1
  307. package/dist/testing/run.d.ts +32 -2
  308. package/dist/testing/run.js +509 -25
  309. package/dist/trace-sanitization.d.ts +6 -0
  310. package/dist/trace-sanitization.js +68 -0
  311. package/dist/types.d.ts +899 -210
  312. package/dist/types.js +1 -0
  313. package/dist/typescript-module.d.ts +39 -0
  314. package/dist/typescript-module.js +72 -0
  315. package/package.json +52 -6
  316. package/src/auth-turn/index.ts +1 -1
  317. package/src/auth.ts +118 -0
  318. package/src/ceremonies/index.ts +189 -46
  319. package/src/cli/commands.ts +37 -0
  320. package/src/cli/create.ts +8 -2
  321. package/src/cli/deployment-intent.ts +364 -0
  322. package/src/cli/local-connection.ts +221 -0
  323. package/src/cli/migrate-deployment-intent.ts +1908 -0
  324. package/src/cli/migrate-operation-declaration.ts +3026 -0
  325. package/src/cli/migrate-operation-shape.ts +184 -0
  326. package/src/cli/migrate-provider-shape.ts +778 -0
  327. package/src/cli/resolver-runtime.ts +72 -0
  328. package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +141 -23
  329. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  330. package/src/cli/templates/provider/README.md.tpl +41 -19
  331. package/src/cli/templates/provider/index.ts.tpl +6 -3
  332. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  333. package/src/cli/templates/provider/provider.json.tpl +6 -0
  334. package/src/config/loader.ts +774 -181
  335. package/src/contract-serialization.ts +5 -7
  336. package/src/contract-types.ts +12 -5
  337. package/src/contract.ts +24 -10
  338. package/src/declaration-validation.ts +376 -0
  339. package/src/define.ts +1105 -131
  340. package/src/dev.ts +13 -1
  341. package/src/engine.ts +390 -0
  342. package/src/error-observability.ts +64 -0
  343. package/src/error-resolution.ts +269 -0
  344. package/src/errors.ts +157 -0
  345. package/src/fixture-sanitization.ts +422 -0
  346. package/src/handle-meta.ts +143 -0
  347. package/src/handle.ts +694 -0
  348. package/src/health-scenario.ts +960 -0
  349. package/src/i18n/catalog.ts +23 -1
  350. package/src/i18n/error-messages.ts +255 -0
  351. package/src/i18n/index.ts +1 -0
  352. package/src/i18n/keys.ts +80 -6
  353. package/src/i18n/operation-locale-namespace.ts +10 -0
  354. package/src/index.ts +390 -23
  355. package/src/lint.ts +2975 -234
  356. package/src/native-address.ts +340 -0
  357. package/src/native-egress-policy.ts +358 -0
  358. package/src/observability.ts +51 -1
  359. package/src/provider.ts +207 -27
  360. package/src/runtime/auth-flow.ts +15 -0
  361. package/src/runtime/bounded-expiring-map.ts +67 -0
  362. package/src/runtime/browser-telemetry-binding.ts +92 -0
  363. package/src/runtime/browser-telemetry.ts +289 -0
  364. package/src/runtime/browser.ts +882 -99
  365. package/src/runtime/cache-telemetry.ts +247 -0
  366. package/src/runtime/cache.ts +258 -22
  367. package/src/runtime/capability-response.ts +53 -0
  368. package/src/runtime/capability-telemetry.ts +101 -0
  369. package/src/runtime/chrome149-header-order.ts +330 -0
  370. package/src/runtime/diagnostic-env-values.ts +56 -0
  371. package/src/runtime/diagnostic-env.ts +65 -0
  372. package/src/runtime/diagnostic-redactor.ts +668 -0
  373. package/src/runtime/egress-lease.ts +341 -0
  374. package/src/runtime/engine-mode.ts +233 -0
  375. package/src/runtime/env.ts +15 -1
  376. package/src/runtime/executor.ts +39 -32
  377. package/src/runtime/handle-wordlist.ts +266 -0
  378. package/src/runtime/handle.ts +1180 -0
  379. package/src/runtime/http-telemetry-binding.ts +162 -0
  380. package/src/runtime/http-telemetry-guard.ts +208 -0
  381. package/src/runtime/http-telemetry.ts +292 -0
  382. package/src/runtime/http.ts +896 -150
  383. package/src/runtime/insights.ts +2 -2
  384. package/src/runtime/instrumentation.ts +628 -28
  385. package/src/runtime/native-network-errors.ts +99 -0
  386. package/src/runtime/native-network.ts +1853 -0
  387. package/src/runtime/native-telemetry.ts +366 -0
  388. package/src/runtime/ocr-telemetry.ts +308 -0
  389. package/src/runtime/ocr.ts +564 -0
  390. package/src/runtime/otlp.ts +468 -21
  391. package/src/runtime/provider.ts +15 -0
  392. package/src/runtime/proxy-errors.ts +12 -4
  393. package/src/runtime/proxy-nodemaven.ts +222 -0
  394. package/src/runtime/proxy-retry-policy.ts +12 -1
  395. package/src/runtime/proxy-telemetry.ts +358 -103
  396. package/src/runtime/redirect-hop-headers.ts +71 -0
  397. package/src/runtime/redirects.ts +215 -0
  398. package/src/runtime/redis.ts +7 -2
  399. package/src/runtime/request-options.ts +728 -1
  400. package/src/runtime/request-telemetry.ts +375 -0
  401. package/src/runtime/resolver-config.ts +18 -0
  402. package/src/runtime/resolver-public.ts +44 -0
  403. package/src/runtime/resolver-runtime-options.ts +50 -0
  404. package/src/runtime/resolver-shared.ts +113 -0
  405. package/src/runtime/resolver-span-attributes.ts +139 -0
  406. package/src/runtime/resolver-telemetry.ts +362 -0
  407. package/src/runtime/resolver-usage.ts +99 -0
  408. package/src/runtime/resolver-vendors/bindings.ts +61 -0
  409. package/src/runtime/resolver-vendors/browser.ts +591 -0
  410. package/src/runtime/resolver-vendors/capsolver.ts +727 -0
  411. package/src/runtime/resolver-vendors/hosts.ts +81 -0
  412. package/src/runtime/resolver-vendors/hypersolutions.ts +480 -0
  413. package/src/runtime/resolver-vendors/twocaptcha.ts +555 -0
  414. package/src/runtime/resolver-vendors/types.ts +261 -0
  415. package/src/runtime/resolver.ts +1543 -0
  416. package/src/runtime/state-telemetry.ts +298 -0
  417. package/src/runtime/state.ts +435 -89
  418. package/src/runtime/stealth-akamai-sbsd.ts +207 -0
  419. package/src/runtime/stealth-cookies.ts +155 -0
  420. package/src/runtime/stealth-owned-headers.ts +67 -0
  421. package/src/runtime/stealth-telemetry.ts +309 -0
  422. package/src/runtime/stealth.ts +2275 -372
  423. package/src/runtime/stt-telemetry.ts +282 -0
  424. package/src/runtime/stt.ts +96 -91
  425. package/src/runtime/timeout.ts +18 -0
  426. package/src/runtime/trace-config.ts +78 -0
  427. package/src/runtime/trace.ts +257 -35
  428. package/src/runtime-boundary-lint.ts +707 -0
  429. package/src/schema.ts +80 -2
  430. package/src/serve.ts +6 -1
  431. package/src/server/error-observability.ts +1 -0
  432. package/src/server/error-stack-frames.ts +214 -0
  433. package/src/server/index.ts +184 -2
  434. package/src/server/runtime-diagnostics.ts +522 -0
  435. package/src/server/sdk-version.ts +22 -0
  436. package/src/server/self-test-input-tokens.ts +29 -14
  437. package/src/server/self-test-redaction.ts +10 -40
  438. package/src/server/self-test.ts +205 -89
  439. package/src/server/sensitive-values.ts +211 -0
  440. package/src/server/serve-implementation.ts +4596 -0
  441. package/src/server/serve.ts +1 -1685
  442. package/src/server/state-backend-report.ts +185 -0
  443. package/src/server/trace-output.ts +189 -0
  444. package/src/server/types.ts +34 -1
  445. package/src/stateful/README.md +146 -0
  446. package/src/stateful/errors.ts +35 -0
  447. package/src/stateful/http-provider-event-emitter.ts +314 -0
  448. package/src/stateful/http-session-owner-registry.ts +306 -0
  449. package/src/stateful/index.ts +18 -0
  450. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  451. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  452. package/src/stateful/provider-event-pipeline.ts +61 -0
  453. package/src/stateful/provider-events.ts +462 -0
  454. package/src/stateful/session-key.ts +111 -0
  455. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  456. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  457. package/src/stateful/stateful-provider-adapter.ts +562 -0
  458. package/src/stateful/stateful-provider-observability.ts +261 -0
  459. package/src/stateful/stateful-provider-owner-forwarder.ts +310 -0
  460. package/src/stateful/stateful-provider-runtime-context.ts +96 -0
  461. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  462. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  463. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  464. package/src/stateful-signing.ts +46 -0
  465. package/src/stealth/profiles.ts +212 -231
  466. package/src/stream-evidence.ts +988 -0
  467. package/src/stream.ts +8 -1
  468. package/src/testing/index.ts +10 -1
  469. package/src/testing/run.ts +685 -19
  470. package/src/trace-sanitization.ts +110 -0
  471. package/src/types.ts +1014 -273
  472. package/src/typescript-module.ts +100 -0
  473. package/dist/choice-token.d.ts +0 -24
  474. package/dist/choice-token.js +0 -74
  475. package/dist/runtime/choice.d.ts +0 -15
  476. package/dist/runtime/choice.js +0 -413
  477. package/src/choice-token.ts +0 -165
  478. package/src/runtime/choice.ts +0 -686
package/dist/types.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import type ms from "ms";
2
+ import type { HandleContext, HandleKind } from "./handle.js";
3
+ import type { HealthScenario } from "./health-scenario.js";
4
+ import type { SerializedCookieJar } from "tough-cookie";
2
5
  import type { infer as ZodInfer, ZodType } from "zod";
3
6
  /** Minimal Standard Schema v1 shape accepted by provider operations. */
4
7
  export interface StandardSchemaV1<Input = unknown, Output = Input> {
@@ -32,25 +35,13 @@ export declare namespace StandardSchemaV1 {
32
35
  export type SchemaLike = ZodType | StandardSchemaV1;
33
36
  /** Infer the validated output type produced by a Zod or Standard Schema. */
34
37
  export type InferSchemaOutput<TSchema extends SchemaLike> = TSchema extends ZodType ? ZodInfer<TSchema> : TSchema extends StandardSchemaV1<unknown, infer Output> ? Output : unknown;
35
- export interface OperationInputExample {
36
- scenario: string;
38
+ export interface OperationExample {
39
+ scenarioKey: ProviderLocaleKeyInput;
37
40
  input: unknown;
38
- rationale?: string;
41
+ rationaleKey?: ProviderLocaleKeyInput;
39
42
  }
40
43
  export type OperationRiskClass = "read" | "write" | "destructive" | "external-send";
41
44
  export type OperationApprovalPolicy = "never" | "risk-based" | "always";
42
- export interface OperationToolRouterMetadata {
43
- /** Optional MCP-safe override. Defaults to providerId__operationId. */
44
- name?: string;
45
- /** Safety class exposed to Tool Router clients and approval policy. */
46
- riskClass?: OperationRiskClass;
47
- /** OpenAI remote-MCP approval hint. Defaults from riskClass. */
48
- approval?: OperationApprovalPolicy;
49
- /** Override connection requirement when provider auth + openWorld inference is insufficient. */
50
- requiresConnection?: boolean;
51
- /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
52
- connectionExternalRefParam?: string;
53
- }
54
45
  export type OperationSensitivePath = string;
55
46
  export interface OperationObservabilitySensitiveConfig {
56
47
  /**
@@ -72,37 +63,6 @@ export interface OperationObservabilityConfig {
72
63
  */
73
64
  sensitive?: OperationObservabilitySensitiveConfig;
74
65
  }
75
- export interface OperationAnnotations {
76
- readOnly?: boolean;
77
- destructive?: boolean;
78
- idempotent?: boolean;
79
- /**
80
- * Marks the operation as callable without provider-level authentication.
81
- *
82
- * Provider-level `auth.mode` describes the **majority** auth model of a
83
- * provider; individual operations can still opt out via `openWorld: true`
84
- * when their handler does not consume `ctx.credential`. This is the
85
- * canonical way to declare "this operation is public, even though the
86
- * provider is `credentials`-mode" without splitting the provider into two.
87
- *
88
- * Health-check projections treat `openWorld: true` operations as
89
- * connection-free probes (no `requiresConnection` required, no SA token
90
- * lookup). Future gateway work MAY extend this annotation to bypass
91
- * `X-ApiFuse-Connection-Id` enforcement at proxy time.
92
- *
93
- * Example: Naver Map's `search`, `geocode`, and directions operations
94
- * call public Naver endpoints with no cookies, while `collections` and
95
- * `export` consume the user's session cookie — the provider declares
96
- * `auth.mode: "credentials"` (for the latter) and the former mark
97
- * `openWorld: true`.
98
- */
99
- openWorld?: boolean;
100
- rateLimit?: {
101
- calls: number;
102
- window: "minute" | "hour" | "day";
103
- };
104
- timeoutMs?: number;
105
- }
106
66
  export declare const OPERATION_TIMEOUT_MS_MIN = 1;
107
67
  export declare const OPERATION_TIMEOUT_MS_MAX = 60000;
108
68
  export declare const STREAM_HEARTBEAT_MS_MIN = 1000;
@@ -193,6 +153,73 @@ export interface SmsOtpMatcherDefinition {
193
153
  /** Runtime/fixture helper. Not serialized into generated registry artifacts. */
194
154
  extractOtp(body: string): string | null;
195
155
  }
156
+ export interface ProviderOcrConfig {
157
+ readonly mode: "required" | "optional";
158
+ }
159
+ export type OcrImageInput = {
160
+ readonly kind: "base64";
161
+ readonly data: string;
162
+ readonly mediaType?: string;
163
+ } | {
164
+ readonly kind: "url";
165
+ readonly url: string;
166
+ };
167
+ export interface OcrRecognizeRequest {
168
+ readonly image: OcrImageInput;
169
+ readonly hint?: "captcha" | "document" | "generic";
170
+ readonly prompt?: string;
171
+ readonly maxTokens?: number;
172
+ readonly timeoutMs?: number;
173
+ }
174
+ export interface OcrWarning {
175
+ readonly code: string;
176
+ readonly message: string;
177
+ }
178
+ export interface OcrResult {
179
+ readonly text: string;
180
+ readonly model: string;
181
+ readonly warnings?: readonly OcrWarning[];
182
+ }
183
+ export interface OcrCaptchaOptions {
184
+ readonly length?: number;
185
+ /** Allowed characters. A RegExp is applied to each character, not to the whole text. */
186
+ readonly charset?: string | RegExp;
187
+ readonly caseSensitive?: boolean;
188
+ readonly maxCandidates?: number;
189
+ }
190
+ export interface OcrCaptchaCandidate {
191
+ readonly text: string;
192
+ readonly satisfiesConstraints: boolean;
193
+ }
194
+ export interface OcrCaptchaResult {
195
+ readonly text: string;
196
+ readonly candidates: readonly OcrCaptchaCandidate[];
197
+ readonly satisfiesConstraints: boolean;
198
+ readonly model: string;
199
+ }
200
+ export interface OcrContext {
201
+ /**
202
+ * Whether this context is backed by a configured OCR backend.
203
+ *
204
+ * The SDK owns this verdict: clients built by `createOcrClientFromEnv` for a
205
+ * configured backend report `true`; the unsupported/error clients handed to
206
+ * undeclared or misconfigured providers report `false`. Providers branch on
207
+ * this flag (for example, "require manual CAPTCHA input") instead of probing
208
+ * the engine-owned `APIFUSE__OCR__*` environment names themselves.
209
+ *
210
+ * `true` promises a configured backend, not a successful call: upstream
211
+ * failures still surface as errors from `recognize` / `extractCaptchaText`.
212
+ *
213
+ * Implementations must expose this as an own enumerable data property (not a
214
+ * getter or prototype member) so that wrappers which spread the context, such
215
+ * as `bindOcrTelemetry`, preserve it. Custom `OcrContext` overrides passed to
216
+ * `serve({ ocr })`, `createFlowContext({ ocr })`, or test contexts must set it
217
+ * explicitly.
218
+ */
219
+ readonly available: boolean;
220
+ recognize(request: OcrRecognizeRequest): Promise<OcrResult>;
221
+ extractCaptchaText(image: OcrImageInput, options?: OcrCaptchaOptions): Promise<OcrCaptchaResult>;
222
+ }
196
223
  export type SttTranscribeMode = "general" | "otp";
197
224
  export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
198
225
  export type SttUnsupportedOptionPolicy = "warn" | "error";
@@ -200,6 +227,149 @@ export type ProviderSttMode = "optional" | "required";
200
227
  export interface ProviderSttConfig {
201
228
  mode: ProviderSttMode;
202
229
  }
230
+ /**
231
+ * Union order is documentation only.
232
+ *
233
+ * The SDK owns the default hosted-vendor fallback policy and derives the chain
234
+ * from each provider's declared challenge kinds. Hosted solvers are preferred
235
+ * with `capsolver` ahead of `2captcha` in that policy.
236
+ *
237
+ * `browser` is the in-house CDP pool and remains opt-in; it is excluded from the
238
+ * default chain. `custom` is likewise reserved for provider-specific configuration.
239
+ *
240
+ * `ProviderResolverConfig.vendors` overrides the SDK policy when declared.
241
+ */
242
+ export type ProviderResolverVendor = "browser" | "capsolver" | "capmonster" | "2captcha" | "hypersolutions" | "custom";
243
+ /**
244
+ * Token-family kinds resolve to `{ form: "token" }`. Cookie-family kinds resolve
245
+ * to `{ form: "cookies" }`; network-identity binding is defined per kind. `aws_waf`
246
+ * was measured portable across residential leases on buyee, while `cf_clearance`
247
+ * remains unmeasured here and is treated as identity-scoped because it is widely
248
+ * described as IP-bound.
249
+ */
250
+ export type ProviderChallenge = {
251
+ readonly kind: "turnstile";
252
+ readonly siteKey: string;
253
+ readonly pageUrl: string;
254
+ readonly action?: string;
255
+ readonly cdata?: string;
256
+ } | {
257
+ readonly kind: "recaptcha_v2";
258
+ readonly siteKey: string;
259
+ readonly pageUrl: string;
260
+ } | {
261
+ readonly kind: "recaptcha_v3";
262
+ readonly siteKey: string;
263
+ readonly pageUrl: string;
264
+ readonly action: string;
265
+ readonly minScore?: number;
266
+ } | {
267
+ readonly kind: "hcaptcha";
268
+ readonly siteKey: string;
269
+ readonly pageUrl: string;
270
+ } | {
271
+ readonly kind: "cloudflare_interstitial";
272
+ readonly pageUrl: string;
273
+ readonly blockedHtml?: string;
274
+ } | {
275
+ readonly kind: "aws_waf";
276
+ readonly pageUrl: string;
277
+ /** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
278
+ readonly siteKey?: string;
279
+ readonly captchaScript?: string;
280
+ readonly context?: string;
281
+ readonly iv?: string;
282
+ } | {
283
+ readonly kind: "akamai_sec_cpt";
284
+ readonly pageUrl: string;
285
+ /** The admitted challenge document, needed for tile/context extraction. */
286
+ readonly challengeHtml?: string;
287
+ } | {
288
+ readonly kind: "akamai_sensor";
289
+ readonly pageUrl: string;
290
+ /** Upstream sensor script URL the payload must be POSTed to. */
291
+ readonly scriptUrl: string;
292
+ /** Current `_abck` cookie value, rotates each round. */
293
+ readonly abck?: string;
294
+ /** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
295
+ readonly bmsz?: string;
296
+ /** Bot Manager major version when known ("3" measured on zozo.jp). */
297
+ readonly version?: string;
298
+ } | {
299
+ readonly kind: "akamai_sbsd";
300
+ readonly pageUrl: string;
301
+ /**
302
+ * Discovered SBSD script URL. `?v=&t=` is a hard challenge and `?v=`
303
+ * is passive or a remembered script. A later challenge token never
304
+ * changes this URL.
305
+ */
306
+ readonly scriptUrl: string;
307
+ readonly stateCookieName: "sbsd_o" | "bm_so";
308
+ /**
309
+ * Token returned by a later `cpr_chlge` response. When present with a
310
+ * remembered v-only script, it selects index 0 and is appended only to
311
+ * the payload POST URL.
312
+ */
313
+ readonly challengeToken?: string;
314
+ };
315
+ export type ProviderChallengeKind = ProviderChallenge["kind"];
316
+ /**
317
+ * Token solutions carry no network-identity binding. Cookie-solution binding is
318
+ * per challenge kind: `aws_waf` was measured portable across residential leases
319
+ * on buyee, while `cf_clearance` is unmeasured here and treated as scoped to the
320
+ * identity that produced it. The provider attaches the returned cookies to its
321
+ * own requests. `cookie_state` solutions carry no values: SBSD state lives only
322
+ * in the engine-owned bound jar, and a 2xx payload POST is not proof of a solve;
323
+ * only the next protected GET can verify it (the safe refetch is Phase 2).
324
+ */
325
+ export type ChallengeSolution = {
326
+ readonly form: "token";
327
+ readonly token: string;
328
+ } | {
329
+ readonly form: "cookies";
330
+ readonly cookies: Readonly<Record<string, string>>;
331
+ readonly userAgent: string;
332
+ /** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
333
+ readonly expires?: number;
334
+ /**
335
+ * Epoch seconds conservatively estimated by the SDK when a resolver vendor omits
336
+ * the upstream cookie's expiry. `expires` takes precedence when both are present.
337
+ */
338
+ readonly sdkEstimatedExpires?: number;
339
+ } | {
340
+ readonly form: "cookie_state";
341
+ readonly kind: "akamai_sbsd";
342
+ readonly outcome: "payload_accepted";
343
+ /** Always false until a later protected GET verifies the bound jar (Phase 2). */
344
+ readonly verified: false;
345
+ /** Name only; the identity-bound cookie value remains in the engine-owned jar. */
346
+ readonly stateCookieName: "sbsd_o" | "bm_so";
347
+ /** Epoch seconds observed on the updated state cookie, when supplied upstream. */
348
+ readonly expires?: number;
349
+ };
350
+ /**
351
+ * `akamai_sbsd` declarations require a transport-owned client profile because the
352
+ * solve runs on the provider's admitted session. Other kinds may omit it.
353
+ */
354
+ export type ProviderResolverConfig = {
355
+ /** Optional ordered override for the SDK-owned vendor fallback chain. */
356
+ readonly vendors?: readonly ProviderResolverVendor[];
357
+ /** Challenge kinds this provider is permitted to request. */
358
+ readonly kinds: readonly Exclude<ProviderChallengeKind, "akamai_sbsd">[];
359
+ readonly clientProfile?: string;
360
+ } | {
361
+ /** Optional ordered override for the SDK-owned vendor fallback chain. */
362
+ readonly vendors?: readonly ProviderResolverVendor[];
363
+ /** Challenge kinds this provider is permitted to request. */
364
+ readonly kinds: readonly ProviderChallengeKind[];
365
+ /**
366
+ * Client fingerprint profile the SDK must use when reaching this upstream.
367
+ * Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
368
+ * challenge is served, while a Safari profile is admitted. Provider-declared
369
+ * because only the provider knows its upstream's admission rule.
370
+ */
371
+ readonly clientProfile: string;
372
+ };
203
373
  export type SttAudioInput = {
204
374
  kind: "base64";
205
375
  data: string;
@@ -264,6 +434,9 @@ export interface SttContext {
264
434
  transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
265
435
  extractVerificationCode(text: string, options?: SttVerificationCodeOptions): VerificationCodeExtractionResult;
266
436
  }
437
+ export interface ResolverContext {
438
+ solve(challenge: ProviderChallenge, signal?: AbortSignal): Promise<ChallengeSolution>;
439
+ }
267
440
  export interface HealthJourneySchedule {
268
441
  kind: "interval";
269
442
  /** ISO 8601 duration, for example PT8H. */
@@ -395,7 +568,7 @@ export interface HealthJourneyRunResult {
395
568
  label?: string;
396
569
  metadata?: Record<string, unknown>;
397
570
  }
398
- export interface HealthJourneyDefinition {
571
+ interface HealthJourneyDefinitionBase {
399
572
  id: string;
400
573
  title?: string;
401
574
  description?: string;
@@ -407,8 +580,14 @@ export interface HealthJourneyDefinition {
407
580
  requiredSecrets?: readonly string[];
408
581
  manualTrigger?: HealthJourneyManualTriggerPolicy;
409
582
  steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
410
- run?: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
411
583
  }
584
+ export type HealthJourneyDefinition = HealthJourneyDefinitionBase & ({
585
+ run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
586
+ scenario?: never;
587
+ } | {
588
+ scenario: HealthScenario;
589
+ run?: never;
590
+ });
412
591
  /**
413
592
  * Health-check authoring surface owned by `@apifuse/provider-sdk`.
414
593
  *
@@ -479,13 +658,22 @@ export interface HealthCheckCaseResult {
479
658
  * so authors get IntelliSense and compile-time errors when accessing fields
480
659
  * that do not exist on the operation's declared output schema.
481
660
  */
482
- export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
661
+ export type HealthCheckCase<TInput = unknown, TOutput = unknown> = {
483
662
  /** Human-readable case name; unique within the suite. */
484
663
  name: string;
485
664
  /** Optional longer description shown on ops dashboards. */
486
665
  description?: string;
487
666
  /** Input passed to the operation handler for this case. */
488
667
  input: TInput;
668
+ /** Override per-case degradation threshold (ms); falls back to the suite default. */
669
+ degradedThresholdMs?: number;
670
+ /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
671
+ timeoutMs?: number;
672
+ /** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
673
+ expectedStatus?: "ok" | "degraded";
674
+ /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
675
+ enabled?: () => boolean;
676
+ } & ({
489
677
  /**
490
678
  * Optional runtime input preparation hook for volatile probes. Use this when
491
679
  * the durable probe input must be derived from a live read-only operation
@@ -501,17 +689,26 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
501
689
  *
502
690
  * MUST NOT access scheduler, recorder, or any runtime type — pure data
503
691
  * + lambda only.
692
+ *
693
+ * NOTE: a closure cannot cross the registry's serialization boundary, so
694
+ * the platform health monitor cannot execute this hook — it runs a case's
695
+ * serialized `scenario` and nothing else. A case that carries only
696
+ * `assertions` is still published as a probe, but its outcome is
697
+ * permanently `unknown` / `monitoring_unavailable`, so the operation
698
+ * reads as monitored while nothing is being checked. This hook runs only
699
+ * in the provider runtime's own self-test
700
+ * (`/internal/health/self-test`). Express anything that must be
701
+ * monitored in production as a `scenario`.
504
702
  */
505
703
  assertions: (ctx: HealthCheckAssertionContext<TOutput>) => void | Promise<void> | HealthCheckCaseResult | Promise<HealthCheckCaseResult>;
506
- /** Override per-case degradation threshold (ms); falls back to the suite default. */
507
- degradedThresholdMs?: number;
508
- /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
509
- timeoutMs?: number;
510
- /** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
511
- expectedStatus?: "ok" | "degraded";
512
- /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
513
- enabled?: () => boolean;
514
- }
704
+ /** Declarative scenarios replace the imperative preparation and assertion hooks. */
705
+ scenario?: never;
706
+ } | {
707
+ /** Declarative scenario executed by the health-monitor runtime. */
708
+ scenario: HealthScenario;
709
+ prepareInput?: never;
710
+ assertions?: never;
711
+ });
515
712
  /**
516
713
  * Operation-level health-check suite. At least one case is required when
517
714
  * present. All cases share the suite's interval and default timeout.
@@ -609,23 +806,58 @@ export interface HealthMonitorProbeOverride {
609
806
  /** Optional degraded threshold override for generated registry probes. */
610
807
  degradedThresholdMs?: number;
611
808
  }
809
+ export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
810
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
612
811
  export interface OperationErrorCode {
613
812
  code: string;
614
- status?: number;
813
+ status?: ProviderErrorStatus;
814
+ /** Developer-facing English prose for docs and MCP tool text. Never localized. */
615
815
  description: string;
616
816
  retryable?: boolean;
617
- }
618
- export interface OperationDocMeta {
619
- titleKey?: ProviderLocaleKeyInput;
620
- descriptionKey?: ProviderLocaleKeyInput;
621
- summaryKey?: ProviderLocaleKeyInput;
622
- markdownKey?: ProviderLocaleKeyInput;
623
- normalizationNotesKeys?: ProviderLocaleKeyInput[];
624
- requestExample?: Record<string, unknown>;
625
- responseExample?: unknown;
626
- errorCodes?: OperationErrorCode[];
817
+ /**
818
+ * Locale catalog key for the client-facing `message` of every error thrown
819
+ * with this `code`. A throw site's own `messageKey` wins; when neither is
820
+ * present the SDK derives `errors.<code>.message`.
821
+ */
822
+ messageKey?: ProviderLocaleKeyInput;
823
+ /** Locale catalog key for the client-facing `fix`. Derived default: `errors.<code>.fix`. */
824
+ fixKey?: ProviderLocaleKeyInput;
627
825
  }
628
826
  export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
827
+ export type StealthBrowser = "chrome" | "firefox" | "safari";
828
+ export type StealthOS = "windows" | "macos" | "linux" | "ios";
829
+ /** A supported, fully resolved browser/OS fingerprint pair. */
830
+ export type StealthProfileDescriptor = {
831
+ browser: "chrome";
832
+ os: "windows" | "macos" | "linux";
833
+ } | {
834
+ browser: "firefox";
835
+ os: "windows" | "macos" | "linux";
836
+ } | {
837
+ browser: "safari";
838
+ os: "macos" | "ios";
839
+ };
840
+ /**
841
+ * Browser/OS fingerprint selection. Chrome and macOS are the named defaults
842
+ * when their respective axes are omitted.
843
+ */
844
+ export type StealthProfileSelection = {
845
+ browser?: "chrome";
846
+ os?: "windows" | "macos" | "linux";
847
+ } | {
848
+ browser: "firefox";
849
+ os?: "windows" | "macos" | "linux";
850
+ } | {
851
+ browser: "safari";
852
+ os?: "macos" | "ios";
853
+ };
854
+ /** Provider-owned opt-ins layered onto the transport-owned browser/OS profile. */
855
+ export type ProviderStealthConfig = StealthProfileSelection & {
856
+ readonly challengeDetection?: {
857
+ /** Classify SBSD responses even when no resolver is declared (detect/report mode). */
858
+ readonly akamaiSbsd?: boolean;
859
+ };
860
+ };
629
861
  export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
630
862
  export interface BrowserOptions {
631
863
  headless?: boolean;
@@ -634,9 +866,7 @@ export interface BrowserOptions {
634
866
  engine?: BrowserEngine;
635
867
  requireCdpPool?: boolean;
636
868
  }
637
- export interface StealthProfile {
638
- name: string;
639
- platform: StealthPlatform;
869
+ export type StealthProfile = StealthProfileDescriptor & {
640
870
  version: string;
641
871
  userAgent: string;
642
872
  tlsClientIdentifier?: string;
@@ -644,13 +874,33 @@ export interface StealthProfile {
644
874
  ja4?: string;
645
875
  h2Settings?: Record<string, unknown>;
646
876
  headerOrder?: string[];
647
- }
648
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
877
+ };
878
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
649
879
  export type ConnectionMode = AuthMode;
650
880
  export type ProviderReviewed = "first-party" | "community" | "staging";
651
881
  export type ProviderAccessVisibility = "public" | "early_access";
652
882
  export type ProviderProxyMode = "disabled" | "optional" | "required";
653
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
883
+ /**
884
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
885
+ * (a common mistake because the names collide with a well-known rebrand):
886
+ *
887
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
888
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
889
+ * endpoints). This is our own vendor. It is NOT the company formerly named
890
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
891
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
892
+ * credentials; geo/session encoded in the username, no allocation API.
893
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
894
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
895
+ * username params. A different company from `smartproxy` above.
896
+ * **@deprecated** — unused; no managed adapter. Declare a
897
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
898
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
899
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
900
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
901
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
902
+ */
903
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
654
904
  export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
655
905
  export interface ProviderProxyPolicy {
656
906
  /**
@@ -658,7 +908,18 @@ export interface ProviderProxyPolicy {
658
908
  * certificate verification, and vendor allocator endpoints are SDK-owned.
659
909
  */
660
910
  mode: ProviderProxyMode;
911
+ /**
912
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
913
+ * chain. A single-element `providers` list is equivalent to this field.
914
+ */
661
915
  provider?: ProviderProxyProvider;
916
+ /**
917
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
918
+ * fails over to the next when a vendor lacks credentials or its allocation /
919
+ * transport is exhausted. When omitted, `provider` (or the platform default)
920
+ * is used as a single-vendor chain.
921
+ */
922
+ providers?: ProviderProxyProvider[];
662
923
  geo?: {
663
924
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
664
925
  country?: Iso3166Alpha2CountryCode;
@@ -669,6 +930,12 @@ export interface ProviderProxyPolicy {
669
930
  affinity?: ProviderProxySessionAffinity;
670
931
  lifetimeMinutes?: number;
671
932
  poolSize?: number;
933
+ /**
934
+ * Seconds before hard sticky expiry at which native connections receive
935
+ * the `expiring` event so the provider can drain and reconnect cleanly.
936
+ * Declared by the provider; the SDK does not assume a default cut point.
937
+ */
938
+ drainLeadSeconds?: number;
672
939
  };
673
940
  }
674
941
  export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
@@ -677,13 +944,12 @@ export interface ProviderAccessConfig {
677
944
  * Provider-level rollout visibility.
678
945
  *
679
946
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
680
- * the existing provider policy stack.
947
+ * the existing provider policy stack.
681
948
  * - `early_access`: hidden from public discovery and callable only when the
682
- * active customer organization has a provider-level access grant.
949
+ * active customer organization has a provider-level access grant.
683
950
  *
684
951
  * This is intentionally provider-level only. It does not alter auth mode,
685
- * operation schemas, health-check authoring, `openWorld`, or Connection
686
- * requirements.
952
+ * operation schemas, health-check authoring, or Connection requirements.
687
953
  */
688
954
  visibility?: ProviderAccessVisibility;
689
955
  }
@@ -748,6 +1014,10 @@ export interface ProviderMeta {
748
1014
  publicProfile?: ProviderPublicProfile;
749
1015
  contract?: {
750
1016
  publicSchemaFieldNames?: "normalized";
1017
+ readonly pinnedWireFieldPaths?: readonly {
1018
+ readonly path: string;
1019
+ readonly reason: string;
1020
+ }[];
751
1021
  };
752
1022
  }
753
1023
  export type RequestParamPrimitive = string | number | boolean | null | undefined;
@@ -807,23 +1077,145 @@ export interface HttpRetrySummary {
807
1077
  lastErrorCode?: string;
808
1078
  lastStatus?: number;
809
1079
  }
1080
+ /** Per-attempt input for a `RequestOptions.headers` factory. */
1081
+ export interface HttpAttemptContext {
1082
+ /**
1083
+ * 1-based number of this request build: the first request is `1`, its first
1084
+ * retry `2`. Only attempts that reach header resolution count; a failed
1085
+ * proxy allocation or a skipped duplicate proxy offset builds no request
1086
+ * and is not numbered.
1087
+ */
1088
+ attempt: number;
1089
+ /**
1090
+ * Resolved request URL: `baseUrl` + path + `params` + `sensitiveParams`.
1091
+ * It is the exact URL the attempt is issued against, so bind signature
1092
+ * targets to it rather than to a URL the caller rebuilds. Strip the query
1093
+ * and fragment for fields that are defined without them — RFC 9449 §4.2
1094
+ * requires that of DPoP `htu`. It carries any sensitive query values, so
1095
+ * never log it and never copy it verbatim into a signed field that a
1096
+ * verifier logs.
1097
+ */
1098
+ url: string;
1099
+ /** Normalized upper-case HTTP method of the request. */
1100
+ method: Uppercase<HttpMethod>;
1101
+ }
1102
+ /**
1103
+ * Builds the request headers for one issued attempt. Managed retry calls it
1104
+ * again for every retry, so request-bound single-use proofs (DPoP `jti`,
1105
+ * HTTP message signatures, HMAC nonces) can be re-minted instead of replayed.
1106
+ * A throw is raised as a non-retryable `TransportError` with code
1107
+ * `http_header_factory_failed`.
1108
+ */
1109
+ export type HttpHeadersFactory = (attempt: HttpAttemptContext) => Record<string, string> | Promise<Record<string, string>>;
810
1110
  export interface RequestOptions {
811
- headers?: Record<string, string>;
1111
+ /**
1112
+ * Request headers, or a factory resolved once per issued attempt (see
1113
+ * `HttpHeadersFactory`). The factory runs after proxy resolution, before the
1114
+ * first redirect hop of that attempt; redirect hops reuse the attempt's
1115
+ * headers. `ctx.stealth` declares its own header option and is not affected.
1116
+ */
1117
+ headers?: Record<string, string> | HttpHeadersFactory;
812
1118
  params?: RequestParams;
1119
+ /**
1120
+ * Query parameters whose values contain credentials or other secret material.
1121
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1122
+ */
1123
+ sensitiveParams?: Record<string, string>;
813
1124
  proxy?: string;
1125
+ /**
1126
+ * Per-attempt timeout for the response-header phase. It is disarmed once a
1127
+ * successful response's headers arrive, so it never bounds consumption of
1128
+ * that body — on the buffered path as well as on streams; use `signal` for
1129
+ * that. A non-2xx body the transport discards on the caller's behalf is
1130
+ * still drained under this deadline, so a wedged error body cannot hang the
1131
+ * attempt.
1132
+ */
814
1133
  timeout?: number;
1134
+ /**
1135
+ * Cancels this request only — its retries, its backoff sleep and its
1136
+ * response-body consumption — leaving the client's other in-flight requests
1137
+ * untouched. Merged with the client-level `signal`, so a rejection reads as
1138
+ * `transport_cancelled` either way; inspect `signal.reason` to tell a
1139
+ * per-request abort from a fleet-wide one.
1140
+ */
1141
+ signal?: AbortSignal;
815
1142
  /**
816
1143
  * Defaults to true. Set to false when callers need to inspect upstream
817
1144
  * non-2xx bodies themselves instead of converting them to TransportError.
818
1145
  */
819
1146
  throwOnHttpError?: boolean;
820
1147
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1148
+ /**
1149
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1150
+ * evaluated before the next request is issued. Existing callers that omit
1151
+ * this policy retain the native fetch redirect behavior.
1152
+ */
1153
+ redirectPolicy?: HttpRedirectPolicy;
821
1154
  }
1155
+ export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1156
+ export type HttpRedirectPolicyMode = "same-origin";
1157
+ export interface HttpRedirectPolicy {
1158
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1159
+ mode: HttpRedirectPolicyMode;
1160
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1161
+ maxHops: number;
1162
+ }
1163
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
822
1164
  export type HttpMethod = "HEAD" | "head" | "GET" | "get" | "POST" | "post" | "PUT" | "put" | "DELETE" | "delete" | "OPTIONS" | "options" | "TRACE" | "trace" | "PATCH" | "patch";
823
- export interface StealthFetchOptions extends RequestOptions {
1165
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy" | "headers"> {
1166
+ /**
1167
+ * Not supported by the stealth transport, which observes only the
1168
+ * client-level `signal` passed to `createStealthClient`. Typed as `never` so
1169
+ * a per-request signal fails to compile instead of being silently ignored;
1170
+ * threading one through the stealth session is a separate change.
1171
+ */
1172
+ signal?: never;
1173
+ /**
1174
+ * Defaults to true. Set to false when callers need to inspect upstream
1175
+ * non-2xx bodies themselves instead of converting them to TransportError.
1176
+ *
1177
+ * Documented exception: a non-2xx response that an opted-in SDK challenge
1178
+ * detector classified (`response.challenge` is set) is returned, not thrown,
1179
+ * whatever this flag says, so the classification stays observable. Callers
1180
+ * that need the failure semantics check `response.challenge` first.
1181
+ */
1182
+ throwOnHttpError?: boolean;
1183
+ /**
1184
+ * Request headers. Array values and case-insensitive duplicate names are
1185
+ * combined in caller order using `", "`, matching Chrome's Fetch behavior.
1186
+ *
1187
+ * The stealth transport owns `host`, `connection`, `user-agent`, `sec-ch-ua`,
1188
+ * `sec-ch-ua-mobile`, `sec-ch-ua-platform`, `accept-encoding`, and every
1189
+ * `sec-fetch-*` header. Supplying any of them throws
1190
+ * `STEALTH_HEADER_OVERRIDE_UNSUPPORTED` at request time; declare the request
1191
+ * shape with `stealth.requestClass` instead.
1192
+ */
1193
+ headers?: Record<string, string | string[]>;
824
1194
  method?: HttpMethod;
825
1195
  body?: string | Buffer;
1196
+ /**
1197
+ * Defaults to `"follow"`. Every followed hop drops the request-body headers
1198
+ * when the method changes, `Authorization` and `Proxy-Authorization` when it
1199
+ * leaves the current origin, and an explicit `Cookie` when it leaves the
1200
+ * current site (scheme plus registrable domain); after that the session
1201
+ * cookie jar supplies cookies for the new site.
1202
+ */
826
1203
  redirect?: "follow" | "manual" | "error";
1204
+ /**
1205
+ * Opt-in same-origin redirect enforcement, the ctx.http `redirectPolicy`
1206
+ * for the stealth transport. A redirect whose target leaves the initial
1207
+ * origin, exceeds `maxHops` (at most 10, the stealth redirect limit),
1208
+ * loops, or has no usable `Location` throws `HttpRedirectError` before any
1209
+ * request is sent to that target. Requires the default
1210
+ * `redirect: "follow"`.
1211
+ */
1212
+ redirectPolicy?: HttpRedirectPolicy;
1213
+ /**
1214
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1215
+ * transport aborts the response and throws `response_too_large` if the
1216
+ * declared or streamed body exceeds this limit.
1217
+ */
1218
+ maxBodyBytes?: number;
827
1219
  /**
828
1220
  * Offsets policy-managed proxy pool selection for caller-managed retries.
829
1221
  * Use when a request receives an upstream challenge page rather than a
@@ -831,29 +1223,79 @@ export interface StealthFetchOptions extends RequestOptions {
831
1223
  * operation-affinity proxy.
832
1224
  */
833
1225
  proxyAttemptOffset?: number;
834
- /** Override the configured browser-like stealth profile for this request. */
835
- profile?: string;
836
1226
  /**
837
- * Stealth transport certificate controls. Use only for proxy products that
838
- * terminate CONNECT with a private CA instead of tunneling the origin
839
- * certificate chain.
1227
+ * SDK-specific stealth controls, including a per-request browser and/or OS
1228
+ * override. Standard HTTP metadata such as language, referrer, and content
1229
+ * type belongs in `headers`.
840
1230
  */
841
- stealth?: {
1231
+ stealth?: StealthProfileSelection & {
1232
+ /**
1233
+ * Declare the Chrome request class when it cannot be inferred from the
1234
+ * method (`POST` infers `post`, everything else `navigation`). This is the
1235
+ * replacement for hand-set `Sec-Fetch-*` headers, which the transport
1236
+ * rejects; it drives `Sec-Fetch-Mode`/`Dest`/`User`, `Accept`, `Priority`,
1237
+ * and `Upgrade-Insecure-Requests`.
1238
+ *
1239
+ * `form-post` is an HTML `<form method="post">` submission: a navigation
1240
+ * (`navigate`/`document`, the document `Accept`, `Upgrade-Insecure-Requests`)
1241
+ * that carries a body, in the header order Chrome uses for it, with
1242
+ * `Cache-Control: max-age=0` and the caller's `Content-Type`, `Origin` and
1243
+ * `Referer` in place. It is never inferred, since a form submission and a
1244
+ * script `fetch()` POST look the same to the transport.
1245
+ */
1246
+ requestClass?: "navigation" | "form-post" | "xhr" | "post";
1247
+ /**
1248
+ * Whether a `navigation` or `form-post` request carries a user gesture and
1249
+ * therefore `Sec-Fetch-User: ?1` (default `true`). Set `false` for
1250
+ * script-driven navigations such as `location.replace` or
1251
+ * `form.submit()`, which Chrome sends without it. Ignored for the `xhr` and
1252
+ * `post` request classes.
1253
+ */
1254
+ userActivation?: boolean;
1255
+ /**
1256
+ * Use only for proxy products that terminate CONNECT with a private CA
1257
+ * instead of tunneling the origin certificate chain.
1258
+ */
842
1259
  insecureSkipVerify?: boolean;
843
1260
  };
844
1261
  }
845
1262
  export interface CookieJar {
846
- get(name: string): string | undefined;
847
- getAll(): Record<string, string>;
848
- toString(): string;
849
- find?(predicate: (cookie: string) => boolean): string | undefined;
1263
+ /** URL-less reads use the jar's response URL or session base URL. */
1264
+ get(name: string, url?: string): string | undefined;
1265
+ getAll(url?: string): Record<string, string>;
1266
+ toString(url?: string): string;
1267
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
850
1268
  }
1269
+ /**
1270
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1271
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1272
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1273
+ */
1274
+ export interface StealthCookieStoreV1 {
1275
+ readonly version: 1;
1276
+ readonly jar: SerializedCookieJar;
1277
+ }
1278
+ /** Cookie persistence formats understood by this SDK version. */
1279
+ export type StealthCookieStore = StealthCookieStoreV1;
851
1280
  export interface StealthSessionCookies extends CookieJar {
852
- has(name: string): boolean;
853
- setFromCookieStrings(cookieStrings: readonly string[]): void;
854
- toHeader(): string;
1281
+ has(name: string, url?: string): boolean;
1282
+ /** URL-less writes are scoped to the session base URL. */
1283
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1284
+ toHeader(url?: string): string;
1285
+ /**
1286
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1287
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1288
+ */
855
1289
  snapshot(): Record<string, string>;
1290
+ /**
1291
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1292
+ * @deprecated Use deserialize() with state produced by serialize().
1293
+ */
856
1294
  restore(cookies: Record<string, string>): void;
1295
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1296
+ serialize(): StealthCookieStoreV1;
1297
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1298
+ deserialize(state: StealthCookieStore): void;
857
1299
  clear(): void;
858
1300
  }
859
1301
  export interface DeclarativeStealthResponse {
@@ -864,6 +1306,8 @@ export interface DeclarativeStealthResponse {
864
1306
  headers: Record<string, string>;
865
1307
  rawHeaders: [string, string][];
866
1308
  body: string;
1309
+ /** Present only when an opted-in SDK detector returned an unresolved challenge response. */
1310
+ challenge?: StealthChallengeClassification;
867
1311
  httpVersion?: string;
868
1312
  tlsInfo?: {
869
1313
  protocol?: string;
@@ -876,6 +1320,20 @@ export interface DeclarativeStealthResponse {
876
1320
  bytes(): Promise<Uint8Array>;
877
1321
  }
878
1322
  export type StealthResponse = DeclarativeStealthResponse;
1323
+ /** Why a detected challenge response was returned to the caller instead of being solved and refetched. */
1324
+ export type StealthChallengeClassification = {
1325
+ readonly challenge: Extract<ProviderChallenge, {
1326
+ readonly kind: "akamai_sbsd";
1327
+ }>;
1328
+ /**
1329
+ * `resolver_unavailable`: detect-only provider or no solver configured.
1330
+ * `replay_required`: the request is not a plain GET, so it is never solved or replayed
1331
+ * automatically. `solve_failed`: a concurrent request on the same session owned the
1332
+ * solve and it rejected (that owner receives the error). `challenge_persisted`: the
1333
+ * single refetch after a solve was challenged again.
1334
+ */
1335
+ readonly outcome: "resolver_unavailable" | "replay_required" | "solve_failed" | "challenge_persisted";
1336
+ };
879
1337
  export type RequestWithMethodOptions = RequestOptions & {
880
1338
  method?: string;
881
1339
  body?: unknown;
@@ -887,7 +1345,7 @@ export interface StealthRedirectHop {
887
1345
  location?: string;
888
1346
  nextUrl?: string;
889
1347
  }
890
- export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "redirect"> {
1348
+ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "redirect" | "redirectPolicy"> {
891
1349
  url: string;
892
1350
  maxHops?: number;
893
1351
  stopWhen?: (hop: StealthRedirectHop) => boolean | Promise<boolean>;
@@ -895,11 +1353,23 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
895
1353
  export interface StealthRedirectRunResult {
896
1354
  final: StealthResponse;
897
1355
  hops: StealthRedirectHop[];
898
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1356
+ reason: RedirectRunReason;
1357
+ /**
1358
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1359
+ * @deprecated Use cookieStore for lossless persistence.
1360
+ */
899
1361
  cookies: Record<string, string>;
1362
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1363
+ cookieStore: StealthCookieStoreV1;
900
1364
  }
901
1365
  export interface StealthSession {
902
1366
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
1367
+ /**
1368
+ * Explicitly solve and replay one unsafe request previously classified as
1369
+ * `replay_required`. The original method, URL, headers, and body bytes are
1370
+ * retained by this session and may be replayed exactly once.
1371
+ */
1372
+ replayChallenged(response: StealthResponse): Promise<StealthResponse>;
903
1373
  cookies: StealthSessionCookies;
904
1374
  redirects: {
905
1375
  run(options: StealthRedirectRunOptions): Promise<StealthRedirectRunResult>;
@@ -959,11 +1429,159 @@ export interface HttpClient {
959
1429
  stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
960
1430
  sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
961
1431
  }
1432
+ /** Request-scoped file reference accepted by provider operation inputs. */
1433
+ export interface ProviderFileRef {
1434
+ readonly type: "request_file";
1435
+ readonly id: string;
1436
+ readonly filename: string;
1437
+ readonly mime_type?: string;
1438
+ readonly size: number;
1439
+ readonly sha256?: string;
1440
+ }
1441
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1442
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1443
+ readonly mimeType?: string;
1444
+ arrayBuffer(): Promise<ArrayBuffer>;
1445
+ bytes(): Promise<Uint8Array>;
1446
+ stream(): ReadableStream<Uint8Array>;
1447
+ };
1448
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1449
+ export interface ProviderFilesContext {
1450
+ has(input: string | ProviderFileRef): boolean;
1451
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1452
+ }
1453
+ /** Where provider business logic executes relative to the capability engine. */
1454
+ export type ProviderRuntimeTarget = "vanilla" | "engine";
1455
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1456
+ export interface NativeTcpPortRange {
1457
+ readonly start: number;
1458
+ readonly end: number;
1459
+ }
1460
+ /** Static native TCP egress declared by a provider. */
1461
+ export interface NativeTcpEgressRule {
1462
+ readonly host: string;
1463
+ readonly ports: readonly number[];
1464
+ readonly tls: NativeTcpTlsMode;
1465
+ }
1466
+ /**
1467
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1468
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1469
+ * Dynamic rules must declare at least one target host selector through
1470
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1471
+ * sources and targets match only same-family selectors (except exact
1472
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1473
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1474
+ *
1475
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1476
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1477
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1478
+ * Every rule must declare a source host selector, source port list/range, and
1479
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1480
+ */
1481
+ export interface NativeTcpDynamicEgressRule {
1482
+ readonly sourceHost?: string;
1483
+ readonly sourceHostSuffixes?: readonly string[];
1484
+ readonly sourceIpv4Cidrs?: readonly string[];
1485
+ readonly sourceIpv6Cidrs?: readonly string[];
1486
+ readonly sourcePorts?: readonly number[];
1487
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1488
+ readonly targetHostSuffixes?: readonly string[];
1489
+ readonly targetIpv4Cidrs?: readonly string[];
1490
+ readonly targetIpv6Cidrs?: readonly string[];
1491
+ readonly targetPorts?: readonly number[];
1492
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1493
+ readonly tls: NativeTcpTlsMode;
1494
+ readonly ttlMs?: number;
1495
+ readonly maxGrants?: number;
1496
+ }
1497
+ /** Common TCP/TLS connection input supported by the native runtime. */
1498
+ export interface NativeNetworkConnectInput {
1499
+ readonly host: string;
1500
+ readonly port: number;
1501
+ readonly serverName?: string;
1502
+ readonly rejectUnauthorized?: boolean;
1503
+ /**
1504
+ * Maximum time without a successful socket read before the connection is
1505
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1506
+ */
1507
+ readonly idleTimeoutMs?: number;
1508
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1509
+ readonly timeoutMs?: number;
1510
+ readonly signal?: AbortSignal;
1511
+ /** Overrides the credential-derived sticky affinity key. */
1512
+ readonly affinityKey?: string;
1513
+ }
1514
+ export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
1515
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1516
+ export interface NativeNetworkDynamicGrantOptions {
1517
+ readonly sourceHost: string;
1518
+ readonly sourcePort: number;
1519
+ readonly host: string;
1520
+ readonly port: number;
1521
+ readonly tls: NativeTcpTlsMode;
1522
+ readonly ttlMs?: number;
1523
+ }
1524
+ export interface NativeNetworkEgressGrant {
1525
+ revoke(): void;
1526
+ }
1527
+ /** Consumer-facing alias used by native TCP providers. */
1528
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1529
+ /** Resolved egress identity for a native connection routed through a proxy. */
1530
+ export interface NativeProxyEgressInfo {
1531
+ readonly vendor: ProviderProxyProvider;
1532
+ readonly sticky: boolean;
1533
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1534
+ readonly sessionId?: string;
1535
+ /** Hard expiry of the sticky binding, ISO 8601. */
1536
+ readonly expiresAt?: string;
1537
+ }
1538
+ export type NativeProxyExpiringReason = "sticky_expiry";
1539
+ export interface NativeProxyExpiringEvent {
1540
+ readonly expiresAt: string;
1541
+ readonly leadSeconds: number;
1542
+ readonly reason: NativeProxyExpiringReason;
1543
+ }
1544
+ /**
1545
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1546
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1547
+ */
1548
+ export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
1549
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1550
+ export interface NativeNetworkCloseReason {
1551
+ readonly code: string;
1552
+ readonly message: string;
1553
+ }
1554
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1555
+ export interface NativeNetworkConnection {
1556
+ /** Present when the connection was routed through a proxy. */
1557
+ readonly proxy?: NativeProxyEgressInfo;
1558
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1559
+ readonly closeReason?: NativeNetworkCloseReason;
1560
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1561
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1562
+ read(): Promise<Uint8Array | null>;
1563
+ write(data: Uint8Array): Promise<void>;
1564
+ close(): Promise<void>;
1565
+ }
1566
+ export interface NativeNetworkClient {
1567
+ connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
1568
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1569
+ grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
1570
+ }
1571
+ export interface NativeContext {
1572
+ readonly network: NativeNetworkClient;
1573
+ }
1574
+ export interface NativeProviderConfig {
1575
+ readonly network?: {
1576
+ readonly tcp?: readonly NativeTcpEgressRule[];
1577
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1578
+ };
1579
+ }
962
1580
  export interface ProviderCacheKeyOptions {
963
1581
  /**
964
- * Additional field names to omit from stable key material. The SDK always
965
- * omits known secret-bearing names such as serviceKey, authorization,
966
- * cookie, token, password, and secret.
1582
+ * Additional field names whose values are hashed in stable key material. The
1583
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1584
+ * authorization, cookie, token, password, and secret.
967
1585
  */
968
1586
  redactFields?: string[];
969
1587
  }
@@ -1006,7 +1624,7 @@ export interface ProviderCache {
1006
1624
  export interface StealthClient {
1007
1625
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
1008
1626
  createSession(opts?: {
1009
- profile?: string;
1627
+ stealth?: StealthProfileSelection;
1010
1628
  }): StealthSession;
1011
1629
  close?(): void;
1012
1630
  }
@@ -1036,7 +1654,18 @@ export interface BrowserFrame {
1036
1654
  evaluate<T>(fn: string | (() => T)): Promise<T>;
1037
1655
  locator(selector: string): BrowserLocator;
1038
1656
  }
1039
- export type BrowserResourceMethod = "GET" | "HEAD";
1657
+ export interface BrowserCookie {
1658
+ readonly name: string;
1659
+ readonly value: string;
1660
+ readonly domain: string;
1661
+ readonly path: string;
1662
+ /** Unix seconds. Absent for a session cookie. */
1663
+ readonly expires?: number;
1664
+ readonly httpOnly: boolean;
1665
+ readonly secure: boolean;
1666
+ readonly sameSite?: "Strict" | "Lax" | "None";
1667
+ }
1668
+ export type BrowserResourceMethod = "GET" | "HEAD" | "POST";
1040
1669
  export type BrowserResourceRequest = {
1041
1670
  readonly url: string;
1042
1671
  readonly method: BrowserResourceMethod;
@@ -1045,6 +1674,8 @@ export type BrowserResourceRequest = {
1045
1674
  };
1046
1675
  export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1047
1676
  export type BrowserResourceDecision = {
1677
+ readonly action: "continue";
1678
+ } | {
1048
1679
  readonly action: "fulfill";
1049
1680
  readonly status?: number;
1050
1681
  readonly headers?: Readonly<Record<string, string>>;
@@ -1060,12 +1691,29 @@ export type BrowserResourceRoute = {
1060
1691
  export type BrowserResourcePolicy = {
1061
1692
  readonly defaultAction?: "block";
1062
1693
  readonly allowedMethods?: readonly BrowserResourceMethod[];
1694
+ /**
1695
+ * Appends an enforcing CSP header to every renderable document response
1696
+ * while the policy is active. Existing CSP headers are retained, so this
1697
+ * can only further restrict the document.
1698
+ */
1699
+ readonly documentContentSecurityPolicy?: string;
1063
1700
  readonly routes: readonly BrowserResourceRoute[];
1064
1701
  };
1065
1702
  export interface BrowserPage extends BrowserFrame {
1066
1703
  close(): Promise<void>;
1704
+ /** Returns the user agent used by this page's browser context. */
1705
+ userAgent(): Promise<string>;
1706
+ /**
1707
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1708
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1709
+ */
1710
+ cookies(): Promise<readonly BrowserCookie[]>;
1067
1711
  fill(selector: string, text: string): Promise<void>;
1068
1712
  goto(url: string): Promise<void>;
1713
+ goto(url: string, options?: {
1714
+ readonly timeout?: number;
1715
+ readonly waitUntil?: "load" | "domcontentloaded";
1716
+ }): Promise<void>;
1069
1717
  pageId?: string;
1070
1718
  screenshot(options?: {
1071
1719
  fullPage?: boolean;
@@ -1107,7 +1755,7 @@ export interface TraceConfig {
1107
1755
  exporter?: "console" | "json" | "otlp" | "none";
1108
1756
  endpoint?: string;
1109
1757
  otlp?: {
1110
- endpoint: string;
1758
+ endpoint?: string;
1111
1759
  headers?: Record<string, string>;
1112
1760
  timeout?: number;
1113
1761
  };
@@ -1132,85 +1780,18 @@ export interface CredentialContext {
1132
1780
  }
1133
1781
  export interface ProviderRequestContext {
1134
1782
  connectionId?: string;
1783
+ /**
1784
+ * Gateway-asserted principal scope of the operation request: the
1785
+ * organization id for customer subjects, the service-account id for
1786
+ * platform service accounts. `undefined` on direct calls and self-test
1787
+ * (unlike `FlowContext.tenantId`, which is coerced to `""`); an empty
1788
+ * string on the wire is normalised to `undefined` like `connectionId`.
1789
+ * Key per-principal policy (quota, fairness, correlation) for
1790
+ * connectionless operations on it. It does not scope `ctx.state`.
1791
+ */
1792
+ tenantId?: string;
1135
1793
  headers: Record<string, string>;
1136
1794
  }
1137
- export interface ProviderChoiceBindingOptions {
1138
- connection?: boolean;
1139
- credentialKeys?: readonly string[];
1140
- }
1141
- export type ProviderChoiceStorageOptions = {
1142
- readonly mode: "inline";
1143
- } | {
1144
- readonly mode: "server";
1145
- readonly namespace: string;
1146
- readonly state?: ProviderRuntimeState;
1147
- readonly ttl?: ProviderStateDurationString;
1148
- readonly maxEntries: number;
1149
- readonly maxValueBytes: number;
1150
- readonly unavailable?: "reject";
1151
- } | {
1152
- readonly mode: "auto";
1153
- readonly namespace: string;
1154
- readonly state?: ProviderRuntimeState;
1155
- readonly ttl?: ProviderStateDurationString;
1156
- readonly maxInlineBytes: number;
1157
- readonly maxEntries: number;
1158
- readonly maxValueBytes: number;
1159
- readonly unavailable?: "reject";
1160
- };
1161
- export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unknown>> {
1162
- prefix: string;
1163
- purpose: string;
1164
- payload: TPayload;
1165
- ttlMs: number;
1166
- nowMs?: number;
1167
- bind?: ProviderChoiceBindingOptions;
1168
- storage?: ProviderChoiceStorageOptions;
1169
- }
1170
- export interface ProviderChoiceParseOptions {
1171
- token: string;
1172
- prefix: string;
1173
- purpose: string;
1174
- ttlMs?: number;
1175
- nowMs?: number;
1176
- futureToleranceMs?: number;
1177
- bind?: ProviderChoiceBindingOptions;
1178
- storage?: ProviderChoiceStorageOptions;
1179
- }
1180
- export interface ProviderChoiceContext {
1181
- issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1182
- readonly storage?: {
1183
- readonly mode: "inline";
1184
- };
1185
- }): string;
1186
- issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1187
- readonly storage: Extract<ProviderChoiceStorageOptions, {
1188
- readonly mode: "server";
1189
- }>;
1190
- }): Promise<string>;
1191
- issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1192
- readonly storage: Extract<ProviderChoiceStorageOptions, {
1193
- readonly mode: "auto";
1194
- }>;
1195
- }): string | Promise<string>;
1196
- issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1197
- parse(options: ProviderChoiceParseOptions & {
1198
- readonly storage?: {
1199
- readonly mode: "inline";
1200
- };
1201
- }): Record<string, unknown>;
1202
- parse(options: ProviderChoiceParseOptions & {
1203
- readonly storage: Extract<ProviderChoiceStorageOptions, {
1204
- readonly mode: "server";
1205
- }>;
1206
- }): Promise<Record<string, unknown>>;
1207
- parse(options: ProviderChoiceParseOptions & {
1208
- readonly storage: Extract<ProviderChoiceStorageOptions, {
1209
- readonly mode: "auto";
1210
- }>;
1211
- }): Record<string, unknown> | Promise<Record<string, unknown>>;
1212
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1213
- }
1214
1795
  export interface ContextScratchpad {
1215
1796
  get(key: string): unknown;
1216
1797
  set(key: string, value: unknown): void;
@@ -1285,16 +1866,35 @@ export interface AuthFlowTerminalContext {
1285
1866
  }): AuthTurn;
1286
1867
  }
1287
1868
  export interface FlowContext {
1869
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
1870
+ flowId?: string;
1288
1871
  connectionId?: string;
1289
1872
  externalRef?: string;
1290
1873
  tenantId: string;
1291
1874
  providerId: string;
1875
+ trace: TraceContext;
1292
1876
  http: HttpClient;
1877
+ /** Durable connection-scoped runtime state. Present when the host runtime
1878
+ * supplies one; auth ceremonies must fail closed when absent rather than
1879
+ * fall back to bypassable in-process storage.
1880
+ *
1881
+ * Scoped via `ProviderRuntimeState.forConnection`: requests that resolve no
1882
+ * connection id (pre-connection ceremonies such as first-time logins) share
1883
+ * the documented isolated missing-connection scope. That sharing is the
1884
+ * intended semantic — it lets counters keyed by caller identity (e.g. a
1885
+ * login email) persist across separate ceremonies for the same caller.
1886
+ * Flows storing entries in that scope MUST key them by caller identity;
1887
+ * un-keyed entries would be shared across all connectionless ceremonies. */
1888
+ readonly state?: ProviderRuntimeState;
1889
+ /** Present when the selected runtime supplies native network capabilities. */
1890
+ readonly native?: NativeContext;
1293
1891
  stealth: StealthClient;
1294
1892
  env: EnvContext;
1295
1893
  credential?: CredentialContext;
1296
1894
  context: ContextScratchpad;
1895
+ ocr: OcrContext;
1297
1896
  stt: SttContext;
1897
+ resolver: ResolverContext;
1298
1898
  auth: AuthFlowTerminalContext;
1299
1899
  }
1300
1900
  export interface AuthTurn {
@@ -1326,7 +1926,13 @@ export interface AuthFlowDefinition {
1326
1926
  refresh?: AuthFlowInputHandler;
1327
1927
  }
1328
1928
  export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1929
+ export type StateNamespaceScope = "connection" | "provider";
1329
1930
  export interface StateNamespaceOptions {
1931
+ /**
1932
+ * State isolation boundary. Connection scope is the default; provider scope
1933
+ * must be selected explicitly for provider-wide coordination state.
1934
+ */
1935
+ scope?: StateNamespaceScope;
1330
1936
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1331
1937
  defaultTtl: ProviderStateDurationString;
1332
1938
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1368,30 +1974,89 @@ export interface ProviderStateNamespace {
1368
1974
  increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1369
1975
  }
1370
1976
  export interface ProviderRuntimeState {
1977
+ /**
1978
+ * Returns an immutable view bound to one request connection. An unresolved
1979
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
1980
+ */
1981
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1371
1982
  namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1372
1983
  }
1373
- export interface ProviderContext {
1984
+ /**
1985
+ * The operation context exposed for one provider declaration. Capability
1986
+ * bindings are present only when their corresponding declaration is present;
1987
+ * platform-managed auth itself declares the credential binding. Trace and
1988
+ * request remain ambient runtime bindings. Omitting the type parameter
1989
+ * preserves the legacy full context shape for existing annotations.
1990
+ */
1991
+ export type ProviderContext<TConfig = Record<string, unknown>> = {
1992
+ request?: ProviderRequestContext;
1993
+ trace: TraceContext;
1994
+ } & ("env" extends keyof TConfig ? {
1374
1995
  env: EnvContext;
1996
+ } : Record<never, never>) & ("credential" extends keyof TConfig ? {
1375
1997
  credential: CredentialContext;
1376
- request?: ProviderRequestContext;
1998
+ } : TConfig extends {
1999
+ auth: {
2000
+ mode: "platform-managed";
2001
+ };
2002
+ } ? {
2003
+ credential: CredentialContext;
2004
+ } : Record<never, never>) & ("http" extends keyof TConfig ? {
1377
2005
  http: HttpClient;
2006
+ } : Record<never, never>) & ("files" extends keyof TConfig ? string extends keyof TConfig ? {
2007
+ readonly files?: ProviderFilesContext;
2008
+ } : {
2009
+ readonly files: ProviderFilesContext;
2010
+ } : Record<never, never>) & ("native" extends keyof TConfig ? {
2011
+ readonly native: NativeContext;
2012
+ } : Record<never, never>) & ("cache" extends keyof TConfig ? {
1378
2013
  cache: ProviderCache;
2014
+ } : Record<never, never>) & ("state" extends keyof TConfig ? {
1379
2015
  state: ProviderRuntimeState;
2016
+ } : Record<never, never>) & ("stealth" extends keyof TConfig ? {
1380
2017
  stealth: StealthClient;
2018
+ } : Record<never, never>) & ("browser" extends keyof TConfig ? {
1381
2019
  browser: BrowserClient;
1382
- trace: TraceContext;
2020
+ } : Record<never, never>) & ("auth" extends keyof TConfig ? {
1383
2021
  auth: AuthContext;
2022
+ } : Record<never, never>) & ("ocr" extends keyof TConfig ? {
2023
+ ocr: OcrContext;
2024
+ } : Record<never, never>) & ("stt" extends keyof TConfig ? {
1384
2025
  stt: SttContext;
1385
- choice: ProviderChoiceContext;
2026
+ } : Record<never, never>) & ("resolver" extends keyof TConfig ? {
2027
+ resolver: ResolverContext;
2028
+ } : Record<never, never>) & ("handle" extends keyof TConfig ? {
2029
+ handle: HandleContext;
2030
+ } : Record<never, never>);
2031
+ /** Backwards-compatible name for a declaration-derived provider context. */
2032
+ export type ProviderContextFor<TConfig> = ProviderContext<TConfig>;
2033
+ export interface ProxiedOAuthConfig {
2034
+ authorizeUrl: string;
2035
+ tokenUrl: string;
2036
+ customScheme: string;
2037
+ rewriteProfile: string;
2038
+ clientIdEnvKey: string;
2039
+ pkce?: "S256" | "none";
2040
+ authorizeParams?: Record<string, string>;
2041
+ tokenParams?: Record<string, string>;
1386
2042
  }
1387
2043
  export interface AuthConfig {
1388
2044
  mode: AuthMode;
2045
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
2046
+ proxied?: ProxiedOAuthConfig;
1389
2047
  flow?: AuthFlowDefinition;
1390
2048
  }
2049
+ /** Who provisions a declared secret: the platform (`apifuse`) or the provider author (`contributor`). */
2050
+ export type ProviderSecretIssuer = "apifuse" | "contributor";
1391
2051
  export interface ProviderSecretDeclaration {
1392
2052
  name: string;
1393
2053
  description?: string;
1394
2054
  required?: boolean;
2055
+ /**
2056
+ * Optional today; ADR-0011 D3 makes it required once every deployed provider
2057
+ * declares it. Metadata only: it does not change which secrets are projected.
2058
+ */
2059
+ issuer?: ProviderSecretIssuer;
1395
2060
  }
1396
2061
  export interface CredentialDeclaration {
1397
2062
  keys: string[];
@@ -1417,40 +2082,41 @@ export interface OperationContractMetadata {
1417
2082
  lifecycle?: OperationLifecycle;
1418
2083
  deprecation?: OperationDeprecationMetadata;
1419
2084
  }
1420
- export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
1421
- /**
1422
- * Short English display title for the operation. The SDK passes it through
1423
- * verbatim; the APIFuse registry derives the operation's en locale title
1424
- * baseline from it (`docs.titleKey` remains available as an explicit key
1425
- * override).
1426
- */
1427
- title?: string;
1428
- /**
1429
- * Raw English operation description. The SDK passes it through verbatim;
1430
- * keyed descriptions via `descriptionKey` remain the primary flow, and
1431
- * provider lint rules for raw prose descriptions still apply.
1432
- */
1433
- description?: string;
2085
+ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike, TContext = ProviderContext> {
2086
+ /** Canonical operation-level connection requirement. */
2087
+ connectionMode?: "none" | "optional" | "required";
2088
+ /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
2089
+ connectionExternalRefParam?: string;
2090
+ /** Safety source of truth exposed to clients and approval policy. */
2091
+ riskClass: OperationRiskClass;
2092
+ /** Approval override. Omit when the risk-class default is correct. */
2093
+ approval?: OperationApprovalPolicy;
2094
+ timeoutMs?: number;
2095
+ titleKey?: ProviderLocaleKeyInput;
1434
2096
  descriptionKey?: ProviderLocaleKeyInput;
1435
- docs?: OperationDocMeta;
2097
+ summaryKey?: ProviderLocaleKeyInput;
2098
+ markdownKey?: ProviderLocaleKeyInput;
1436
2099
  whenToUseKeys?: readonly ProviderLocaleKeyInput[];
1437
2100
  whenNotToUseKeys?: readonly ProviderLocaleKeyInput[];
1438
- derivations?: Record<string, string>;
1439
- inputExamples?: readonly OperationInputExample[];
1440
- annotations?: OperationAnnotations;
2101
+ normalizationNotesKeys?: readonly ProviderLocaleKeyInput[];
2102
+ errorCodes?: readonly OperationErrorCode[];
2103
+ examples?: readonly OperationExample[];
1441
2104
  contract?: OperationContractMetadata;
1442
2105
  tags?: readonly string[];
1443
2106
  relatedOperations?: OperationRelationships;
1444
- toolRouter?: OperationToolRouterMetadata;
1445
2107
  observability?: OperationObservabilityConfig;
1446
2108
  transport?: OperationTransport;
1447
- retryOnAuthRefresh?: boolean;
1448
2109
  input: TInput;
1449
2110
  output: TOutput;
1450
- handler(ctx: ProviderContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
2111
+ handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1451
2112
  fixtures?: {
1452
2113
  request: InferSchemaOutput<TInput>;
1453
2114
  response: InferSchemaOutput<TOutput>;
2115
+ /**
2116
+ * KST calendar date when `response` evidence was captured. Date fields in
2117
+ * the response align with this date, not a resolved relative request date.
2118
+ */
2119
+ recordedAt?: string;
1454
2120
  };
1455
2121
  upstream?: {
1456
2122
  baseUrl?: string;
@@ -1472,6 +2138,14 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
1472
2138
  * optional. Note that the deployment `runtime` axis
1473
2139
  * (`shared`/`dedicated`/`browser`) is distinct from the provider execution
1474
2140
  * `runtime` (`standard`/`shared`/`browser`).
2141
+ *
2142
+ * This key is the ONLY authored deployment surface. Declare it inside the
2143
+ * `defineProvider({...})` literal, not on a spread default export and not
2144
+ * in a standalone `deploy.ts` (legacy; `apifuse migrate-deployment` hoists
2145
+ * and deletes it). Write only what differs from the runtime profile —
2146
+ * shared `25m/128Mi`, browser `200m/256Mi`, `language: "typescript"`,
2147
+ * `replicas: 1`, HPA enabled 1-1 at 70% CPU — so most providers declare
2148
+ * nothing and `apifuse check` warns on restated defaults.
1475
2149
  */
1476
2150
  export interface ProviderDeploymentOverrides {
1477
2151
  runtime?: "shared" | "dedicated" | "browser";
@@ -1498,36 +2172,51 @@ export interface ProviderDeploymentOverrides {
1498
2172
  };
1499
2173
  buildContext?: string;
1500
2174
  }
1501
- export interface ProviderDefinition {
2175
+ export interface ProviderDefinition<TContext = ProviderContext> {
1502
2176
  id: string;
1503
2177
  version: string;
1504
2178
  runtime: "standard" | "shared" | "browser";
2179
+ /**
2180
+ * `vanilla` executes provider business logic outside the engine; `engine`
2181
+ * keeps session-bearing provider logic in the engine process.
2182
+ *
2183
+ * Omitted only for definitions authored before the engine migration. New
2184
+ * providers should declare the target explicitly.
2185
+ */
2186
+ runtimeTarget?: ProviderRuntimeTarget;
1505
2187
  /**
1506
2188
  * Optional deployment overrides, passed through verbatim from
1507
2189
  * `defineProvider({ deployment })`. Validation and profile resolution are
1508
2190
  * owned by the APIFuse registry builder, not the SDK.
1509
2191
  */
1510
2192
  deployment?: ProviderDeploymentOverrides;
2193
+ http?: Record<string, never> | true;
1511
2194
  allowedHosts?: string[];
1512
- stealth?: {
1513
- profile: string;
1514
- platform: StealthPlatform;
1515
- };
2195
+ native?: NativeProviderConfig;
2196
+ stealth?: ProviderStealthConfig;
1516
2197
  proxy?: ProviderProxyConfig;
2198
+ ocr?: ProviderOcrConfig;
1517
2199
  stt?: ProviderSttConfig;
2200
+ resolver?: ProviderResolverConfig;
1518
2201
  browser?: {
1519
2202
  engine: BrowserEngine;
1520
2203
  };
1521
2204
  auth?: AuthConfig;
2205
+ handle?: readonly HandleKind[];
1522
2206
  reviewed?: ProviderReviewed;
1523
2207
  access?: ProviderAccessConfig;
1524
2208
  secrets?: ProviderSecretDeclaration[];
2209
+ env?: Record<string, never> | true;
1525
2210
  credential?: CredentialDeclaration;
1526
2211
  context?: ContextDeclaration;
2212
+ state?: Record<string, never> | true;
2213
+ cache?: Record<string, never> | true;
2214
+ files?: Record<string, never> | true;
1527
2215
  meta: ProviderMeta;
1528
- operations: Record<string, OperationDefinition<SchemaLike, SchemaLike>>;
2216
+ operations: Record<string, OperationDefinition<SchemaLike, SchemaLike, TContext>>;
1529
2217
  healthMonitor?: ProviderHealthMonitorConfig;
1530
2218
  /** Transitional alias for `healthMonitor`; `defineProvider` mirrors both. */
1531
2219
  healthProbe?: ProviderHealthProbeConfig;
1532
2220
  healthJourneys?: readonly HealthJourneyDefinition[];
1533
2221
  }
2222
+ export {};