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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/AUTHORING.md +537 -33
  2. package/CHANGELOG.md +201 -1
  3. package/README.md +83 -22
  4. package/SUBMISSION.md +2 -2
  5. package/bin/apifuse-check.ts +165 -11
  6. package/bin/apifuse-dev.ts +57 -13
  7. package/bin/apifuse-migrate-operation-declaration.ts +55 -0
  8. package/bin/apifuse-migrate-shape.ts +202 -0
  9. package/bin/apifuse-pack-check.ts +22 -2
  10. package/bin/apifuse-pack-smoke.ts +57 -2
  11. package/bin/apifuse-pack-types.ts +357 -38
  12. package/bin/apifuse-perf.ts +14 -13
  13. package/bin/apifuse-record.ts +709 -72
  14. package/bin/apifuse-submit-check.ts +2344 -324
  15. package/bin/apifuse-sync-assets.ts +117 -0
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/dist/auth-turn/index.d.ts +3 -3
  18. package/dist/auth-turn/index.js +1 -1
  19. package/dist/auth.d.ts +14 -0
  20. package/dist/auth.js +67 -0
  21. package/dist/ceremonies/index.d.ts +16 -0
  22. package/dist/ceremonies/index.js +141 -36
  23. package/dist/cli/commands.d.ts +1 -1
  24. package/dist/cli/commands.js +27 -0
  25. package/dist/cli/create.d.ts +4 -1
  26. package/dist/cli/create.js +42 -37
  27. package/dist/cli/migrate-operation-declaration.d.ts +59 -0
  28. package/dist/cli/migrate-operation-declaration.js +1178 -0
  29. package/dist/cli/migrate-operation-shape.d.ts +44 -0
  30. package/dist/cli/migrate-operation-shape.js +113 -0
  31. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  32. package/dist/cli/migrate-provider-shape.js +578 -0
  33. package/dist/cli/prompt-assets.d.ts +80 -0
  34. package/dist/cli/prompt-assets.js +743 -0
  35. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  36. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  37. package/dist/cli/templates/provider/README.md.tpl +5 -5
  38. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  39. package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
  40. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  41. package/dist/config/loader.d.ts +179 -16
  42. package/dist/config/loader.js +435 -127
  43. package/dist/contract-serialization.js +4 -8
  44. package/dist/contract-types.d.ts +12 -5
  45. package/dist/contract.js +24 -10
  46. package/dist/declaration-validation.d.ts +33 -0
  47. package/dist/declaration-validation.js +266 -0
  48. package/dist/define.d.ts +66 -29
  49. package/dist/define.js +778 -69
  50. package/dist/dev.d.ts +3 -0
  51. package/dist/dev.js +1 -1
  52. package/dist/engine.d.ts +78 -0
  53. package/dist/engine.js +133 -0
  54. package/dist/error-observability.d.ts +7 -0
  55. package/dist/error-observability.js +61 -0
  56. package/dist/error-resolution.d.ts +4 -0
  57. package/dist/error-resolution.js +122 -0
  58. package/dist/errors.d.ts +33 -0
  59. package/dist/errors.js +40 -0
  60. package/dist/fixture-sanitization.d.ts +28 -0
  61. package/dist/fixture-sanitization.js +227 -0
  62. package/dist/health-scenario.d.ts +1842 -0
  63. package/dist/health-scenario.js +624 -0
  64. package/dist/index.d.ts +21 -10
  65. package/dist/index.js +12 -7
  66. package/dist/lint.d.ts +23 -11
  67. package/dist/lint.js +572 -69
  68. package/dist/native-address.d.ts +43 -0
  69. package/dist/native-address.js +281 -0
  70. package/dist/native-egress-policy.d.ts +31 -0
  71. package/dist/native-egress-policy.js +288 -0
  72. package/dist/observability.d.ts +5 -2
  73. package/dist/observability.js +48 -1
  74. package/dist/provider.d.ts +10 -2
  75. package/dist/provider.js +4 -1
  76. package/dist/runtime/auth-flow.d.ts +5 -1
  77. package/dist/runtime/auth-flow.js +6 -0
  78. package/dist/runtime/browser.d.ts +1 -0
  79. package/dist/runtime/browser.js +492 -49
  80. package/dist/runtime/cache.d.ts +1 -0
  81. package/dist/runtime/cache.js +169 -15
  82. package/dist/runtime/choice-wordlist.d.ts +9 -0
  83. package/dist/runtime/choice-wordlist.js +138 -0
  84. package/dist/runtime/choice.d.ts +13 -1
  85. package/dist/runtime/choice.js +490 -102
  86. package/dist/runtime/chrome149-header-order.d.ts +58 -0
  87. package/dist/runtime/chrome149-header-order.js +289 -0
  88. package/dist/runtime/env.js +12 -0
  89. package/dist/runtime/executor.d.ts +3 -2
  90. package/dist/runtime/executor.js +26 -25
  91. package/dist/runtime/http.d.ts +1 -0
  92. package/dist/runtime/http.js +515 -53
  93. package/dist/runtime/insights.js +2 -2
  94. package/dist/runtime/instrumentation.d.ts +2 -2
  95. package/dist/runtime/instrumentation.js +366 -8
  96. package/dist/runtime/native-network-errors.d.ts +33 -0
  97. package/dist/runtime/native-network-errors.js +69 -0
  98. package/dist/runtime/native-network.d.ts +96 -0
  99. package/dist/runtime/native-network.js +1232 -0
  100. package/dist/runtime/ocr.d.ts +29 -0
  101. package/dist/runtime/ocr.js +440 -0
  102. package/dist/runtime/otlp.d.ts +71 -2
  103. package/dist/runtime/otlp.js +397 -16
  104. package/dist/runtime/proxy-errors.js +6 -2
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  108. package/dist/runtime/proxy-telemetry.js +154 -47
  109. package/dist/runtime/redirects.d.ts +29 -0
  110. package/dist/runtime/redirects.js +36 -0
  111. package/dist/runtime/redis.d.ts +1 -1
  112. package/dist/runtime/redis.js +4 -2
  113. package/dist/runtime/request-options.d.ts +68 -1
  114. package/dist/runtime/request-options.js +548 -0
  115. package/dist/runtime/resolver-config.d.ts +6 -0
  116. package/dist/runtime/resolver-config.js +6 -0
  117. package/dist/runtime/resolver-public.d.ts +1 -0
  118. package/dist/runtime/resolver-public.js +1 -0
  119. package/dist/runtime/resolver-shared.d.ts +14 -0
  120. package/dist/runtime/resolver-shared.js +12 -0
  121. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  122. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  123. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  124. package/dist/runtime/resolver-vendors/browser.js +377 -0
  125. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  126. package/dist/runtime/resolver-vendors/capsolver.js +531 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  132. package/dist/runtime/resolver-vendors/types.js +96 -0
  133. package/dist/runtime/resolver.d.ts +72 -0
  134. package/dist/runtime/resolver.js +771 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +3 -0
  138. package/dist/runtime/state.js +277 -71
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +41 -5
  142. package/dist/runtime/stealth.js +997 -291
  143. package/dist/runtime/stt.js +1 -12
  144. package/dist/runtime/timeout.d.ts +5 -0
  145. package/dist/runtime/timeout.js +12 -0
  146. package/dist/runtime/trace-config.d.ts +12 -0
  147. package/dist/runtime/trace-config.js +62 -0
  148. package/dist/runtime/trace.d.ts +5 -0
  149. package/dist/runtime/trace.js +43 -10
  150. package/dist/serve.d.ts +1 -1
  151. package/dist/serve.js +1 -1
  152. package/dist/server/error-observability.d.ts +1 -0
  153. package/dist/server/error-observability.js +1 -0
  154. package/dist/server/index.d.ts +5 -2
  155. package/dist/server/index.js +2 -2
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test.d.ts +14 -3
  159. package/dist/server/self-test.js +129 -58
  160. package/dist/server/serve-implementation.d.ts +230 -0
  161. package/dist/server/serve-implementation.js +2265 -0
  162. package/dist/server/serve.d.ts +1 -70
  163. package/dist/server/serve.js +1 -1131
  164. package/dist/server/trace-output.d.ts +6 -0
  165. package/dist/server/trace-output.js +79 -0
  166. package/dist/server/types.d.ts +30 -5
  167. package/dist/server/types.js +13 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +9 -4
  207. package/dist/stealth/profiles.js +160 -211
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.js +7 -1
  211. package/dist/testing/index.d.ts +2 -1
  212. package/dist/testing/index.js +2 -1
  213. package/dist/testing/run.d.ts +32 -2
  214. package/dist/testing/run.js +489 -21
  215. package/dist/trace-sanitization.d.ts +5 -0
  216. package/dist/trace-sanitization.js +45 -0
  217. package/dist/types.d.ts +673 -131
  218. package/dist/types.js +1 -0
  219. package/package.json +45 -5
  220. package/src/auth-turn/index.ts +1 -1
  221. package/src/auth.ts +118 -0
  222. package/src/ceremonies/index.ts +189 -46
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
  246. package/src/cli/commands.ts +33 -0
  247. package/src/cli/create.ts +50 -37
  248. package/src/cli/migrate-operation-declaration.ts +1654 -0
  249. package/src/cli/migrate-operation-shape.ts +184 -0
  250. package/src/cli/migrate-provider-shape.ts +772 -0
  251. package/src/cli/prompt-assets.ts +865 -0
  252. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  253. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  254. package/src/cli/templates/provider/README.md.tpl +5 -5
  255. package/src/cli/templates/provider/index.ts.tpl +6 -3
  256. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  257. package/src/cli/templates/provider/provider.json.tpl +6 -0
  258. package/src/config/loader.ts +690 -163
  259. package/src/contract-serialization.ts +5 -7
  260. package/src/contract-types.ts +12 -5
  261. package/src/contract.ts +24 -10
  262. package/src/declaration-validation.ts +330 -0
  263. package/src/define.ts +1048 -131
  264. package/src/dev.ts +4 -1
  265. package/src/engine.ts +279 -0
  266. package/src/error-observability.ts +64 -0
  267. package/src/error-resolution.ts +127 -0
  268. package/src/errors.ts +68 -0
  269. package/src/fixture-sanitization.ts +264 -0
  270. package/src/health-scenario.ts +875 -0
  271. package/src/index.ts +220 -13
  272. package/src/lint.ts +698 -90
  273. package/src/native-address.ts +340 -0
  274. package/src/native-egress-policy.ts +358 -0
  275. package/src/observability.ts +51 -1
  276. package/src/provider.ts +161 -3
  277. package/src/runtime/auth-flow.ts +12 -0
  278. package/src/runtime/browser.ts +661 -63
  279. package/src/runtime/cache.ts +189 -14
  280. package/src/runtime/choice-wordlist.ts +145 -0
  281. package/src/runtime/choice.ts +631 -120
  282. package/src/runtime/chrome149-header-order.ts +330 -0
  283. package/src/runtime/env.ts +13 -0
  284. package/src/runtime/executor.ts +43 -31
  285. package/src/runtime/http.ts +641 -61
  286. package/src/runtime/insights.ts +2 -2
  287. package/src/runtime/instrumentation.ts +520 -15
  288. package/src/runtime/native-network-errors.ts +99 -0
  289. package/src/runtime/native-network.ts +1605 -0
  290. package/src/runtime/ocr.ts +523 -0
  291. package/src/runtime/otlp.ts +467 -21
  292. package/src/runtime/proxy-errors.ts +12 -4
  293. package/src/runtime/proxy-nodemaven.ts +221 -0
  294. package/src/runtime/proxy-telemetry.ts +244 -75
  295. package/src/runtime/redirects.ts +66 -0
  296. package/src/runtime/redis.ts +7 -2
  297. package/src/runtime/request-options.ts +680 -1
  298. package/src/runtime/resolver-config.ts +6 -0
  299. package/src/runtime/resolver-public.ts +23 -0
  300. package/src/runtime/resolver-shared.ts +33 -0
  301. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  302. package/src/runtime/resolver-vendors/browser.ts +533 -0
  303. package/src/runtime/resolver-vendors/capsolver.ts +707 -0
  304. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  305. package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
  306. package/src/runtime/resolver-vendors/types.ts +212 -0
  307. package/src/runtime/resolver.ts +1157 -0
  308. package/src/runtime/secrets.ts +64 -0
  309. package/src/runtime/state.ts +394 -77
  310. package/src/runtime/stealth-cookies.ts +132 -0
  311. package/src/runtime/stealth.ts +1280 -336
  312. package/src/runtime/stt.ts +1 -19
  313. package/src/runtime/timeout.ts +18 -0
  314. package/src/runtime/trace-config.ts +78 -0
  315. package/src/runtime/trace.ts +57 -17
  316. package/src/serve.ts +6 -1
  317. package/src/server/error-observability.ts +1 -0
  318. package/src/server/index.ts +34 -2
  319. package/src/server/self-test-input-tokens.ts +29 -14
  320. package/src/server/self-test.ts +191 -68
  321. package/src/server/serve-implementation.ts +3378 -0
  322. package/src/server/serve.ts +1 -1632
  323. package/src/server/trace-output.ts +129 -0
  324. package/src/server/types.ts +13 -1
  325. package/src/stateful/README.md +146 -0
  326. package/src/stateful/errors.ts +35 -0
  327. package/src/stateful/http-provider-event-emitter.ts +314 -0
  328. package/src/stateful/http-session-owner-registry.ts +306 -0
  329. package/src/stateful/index.ts +18 -0
  330. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  331. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  332. package/src/stateful/provider-event-pipeline.ts +61 -0
  333. package/src/stateful/provider-events.ts +462 -0
  334. package/src/stateful/session-key.ts +111 -0
  335. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  336. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  337. package/src/stateful/stateful-provider-adapter.ts +562 -0
  338. package/src/stateful/stateful-provider-observability.ts +261 -0
  339. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  340. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  341. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  342. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  343. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  344. package/src/stateful-signing.ts +46 -0
  345. package/src/stealth/profiles.ts +202 -231
  346. package/src/stream-evidence.ts +988 -0
  347. package/src/stream.ts +8 -1
  348. package/src/testing/index.ts +10 -1
  349. package/src/testing/run.ts +658 -15
  350. package/src/trace-sanitization.ts +63 -0
  351. package/src/types.ts +788 -174
  352. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  353. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  354. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  355. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  356. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  357. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  358. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  359. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  360. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  361. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  362. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  363. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  364. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  365. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/dist/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type ms from "ms";
2
+ import type { HealthScenario } from "./health-scenario.js";
3
+ import type { SerializedCookieJar } from "tough-cookie";
2
4
  import type { infer as ZodInfer, ZodType } from "zod";
3
5
  /** Minimal Standard Schema v1 shape accepted by provider operations. */
4
6
  export interface StandardSchemaV1<Input = unknown, Output = Input> {
@@ -32,25 +34,13 @@ export declare namespace StandardSchemaV1 {
32
34
  export type SchemaLike = ZodType | StandardSchemaV1;
33
35
  /** Infer the validated output type produced by a Zod or Standard Schema. */
34
36
  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;
37
+ export interface OperationExample {
38
+ scenarioKey: ProviderLocaleKeyInput;
37
39
  input: unknown;
38
- rationale?: string;
40
+ rationaleKey?: ProviderLocaleKeyInput;
39
41
  }
40
42
  export type OperationRiskClass = "read" | "write" | "destructive" | "external-send";
41
43
  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
44
  export type OperationSensitivePath = string;
55
45
  export interface OperationObservabilitySensitiveConfig {
56
46
  /**
@@ -72,37 +62,6 @@ export interface OperationObservabilityConfig {
72
62
  */
73
63
  sensitive?: OperationObservabilitySensitiveConfig;
74
64
  }
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
65
  export declare const OPERATION_TIMEOUT_MS_MIN = 1;
107
66
  export declare const OPERATION_TIMEOUT_MS_MAX = 60000;
108
67
  export declare const STREAM_HEARTBEAT_MS_MIN = 1000;
@@ -193,6 +152,54 @@ export interface SmsOtpMatcherDefinition {
193
152
  /** Runtime/fixture helper. Not serialized into generated registry artifacts. */
194
153
  extractOtp(body: string): string | null;
195
154
  }
155
+ export interface ProviderOcrConfig {
156
+ readonly mode: "required" | "optional";
157
+ }
158
+ export type OcrImageInput = {
159
+ readonly kind: "base64";
160
+ readonly data: string;
161
+ readonly mediaType?: string;
162
+ } | {
163
+ readonly kind: "url";
164
+ readonly url: string;
165
+ };
166
+ export interface OcrRecognizeRequest {
167
+ readonly image: OcrImageInput;
168
+ readonly hint?: "captcha" | "document" | "generic";
169
+ readonly prompt?: string;
170
+ readonly maxTokens?: number;
171
+ readonly timeoutMs?: number;
172
+ }
173
+ export interface OcrWarning {
174
+ readonly code: string;
175
+ readonly message: string;
176
+ }
177
+ export interface OcrResult {
178
+ readonly text: string;
179
+ readonly model: string;
180
+ readonly warnings?: readonly OcrWarning[];
181
+ }
182
+ export interface OcrCaptchaOptions {
183
+ readonly length?: number;
184
+ /** Allowed characters. A RegExp is applied to each character, not to the whole text. */
185
+ readonly charset?: string | RegExp;
186
+ readonly caseSensitive?: boolean;
187
+ readonly maxCandidates?: number;
188
+ }
189
+ export interface OcrCaptchaCandidate {
190
+ readonly text: string;
191
+ readonly satisfiesConstraints: boolean;
192
+ }
193
+ export interface OcrCaptchaResult {
194
+ readonly text: string;
195
+ readonly candidates: readonly OcrCaptchaCandidate[];
196
+ readonly satisfiesConstraints: boolean;
197
+ readonly model: string;
198
+ }
199
+ export interface OcrContext {
200
+ recognize(request: OcrRecognizeRequest): Promise<OcrResult>;
201
+ extractCaptchaText(image: OcrImageInput, options?: OcrCaptchaOptions): Promise<OcrCaptchaResult>;
202
+ }
196
203
  export type SttTranscribeMode = "general" | "otp";
197
204
  export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
198
205
  export type SttUnsupportedOptionPolicy = "warn" | "error";
@@ -200,6 +207,111 @@ export type ProviderSttMode = "optional" | "required";
200
207
  export interface ProviderSttConfig {
201
208
  mode: ProviderSttMode;
202
209
  }
210
+ /**
211
+ * Union order is documentation only.
212
+ *
213
+ * The SDK owns the default hosted-vendor fallback policy and derives the chain
214
+ * from each provider's declared challenge kinds. Hosted solvers are preferred
215
+ * with `capsolver` ahead of `2captcha` in that policy.
216
+ *
217
+ * `browser` is the in-house CDP pool and remains opt-in; it is excluded from the
218
+ * default chain. `custom` is likewise reserved for provider-specific configuration.
219
+ *
220
+ * `ProviderResolverConfig.vendors` overrides the SDK policy when declared.
221
+ */
222
+ export type ProviderResolverVendor = "browser" | "capsolver" | "capmonster" | "2captcha" | "custom";
223
+ /**
224
+ * Token-family kinds resolve to `{ form: "token" }`. Cookie-family kinds resolve
225
+ * to `{ form: "cookies" }`; network-identity binding is defined per kind. `aws_waf`
226
+ * was measured portable across residential leases on buyee, while `cf_clearance`
227
+ * remains unmeasured here and is treated as identity-scoped because it is widely
228
+ * described as IP-bound.
229
+ */
230
+ export type ProviderChallenge = {
231
+ readonly kind: "turnstile";
232
+ readonly siteKey: string;
233
+ readonly pageUrl: string;
234
+ readonly action?: string;
235
+ readonly cdata?: string;
236
+ } | {
237
+ readonly kind: "recaptcha_v2";
238
+ readonly siteKey: string;
239
+ readonly pageUrl: string;
240
+ } | {
241
+ readonly kind: "recaptcha_v3";
242
+ readonly siteKey: string;
243
+ readonly pageUrl: string;
244
+ readonly action: string;
245
+ readonly minScore?: number;
246
+ } | {
247
+ readonly kind: "hcaptcha";
248
+ readonly siteKey: string;
249
+ readonly pageUrl: string;
250
+ } | {
251
+ readonly kind: "cloudflare_interstitial";
252
+ readonly pageUrl: string;
253
+ readonly blockedHtml?: string;
254
+ } | {
255
+ readonly kind: "aws_waf";
256
+ readonly pageUrl: string;
257
+ /** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
258
+ readonly siteKey?: string;
259
+ readonly captchaScript?: string;
260
+ readonly context?: string;
261
+ readonly iv?: string;
262
+ } | {
263
+ readonly kind: "akamai_sec_cpt";
264
+ readonly pageUrl: string;
265
+ /** The admitted challenge document, needed for tile/context extraction. */
266
+ readonly challengeHtml?: string;
267
+ } | {
268
+ readonly kind: "akamai_sensor";
269
+ readonly pageUrl: string;
270
+ /** Upstream sensor script URL the payload must be POSTed to. */
271
+ readonly scriptUrl: string;
272
+ /** Current `_abck` cookie value, rotates each round. */
273
+ readonly abck?: string;
274
+ /** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
275
+ readonly bmsz?: string;
276
+ /** Bot Manager major version when known ("3" measured on zozo.jp). */
277
+ readonly version?: string;
278
+ };
279
+ export type ProviderChallengeKind = ProviderChallenge["kind"];
280
+ /**
281
+ * Token solutions carry no network-identity binding. Cookie-solution binding is
282
+ * per challenge kind: `aws_waf` was measured portable across residential leases
283
+ * on buyee, while `cf_clearance` is unmeasured here and treated as scoped to the
284
+ * identity that produced it. The provider attaches the returned cookies to its
285
+ * own requests.
286
+ */
287
+ export type ChallengeSolution = {
288
+ readonly form: "token";
289
+ readonly token: string;
290
+ } | {
291
+ readonly form: "cookies";
292
+ readonly cookies: Readonly<Record<string, string>>;
293
+ readonly userAgent: string;
294
+ /** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
295
+ readonly expires?: number;
296
+ /**
297
+ * Epoch seconds conservatively estimated by the SDK when a resolver vendor omits
298
+ * the upstream cookie's expiry. `expires` takes precedence when both are present.
299
+ */
300
+ readonly sdkEstimatedExpires?: number;
301
+ };
302
+ export interface ProviderResolverConfig {
303
+ /** Optional ordered override for the SDK-owned vendor fallback chain. */
304
+ readonly vendors?: readonly ProviderResolverVendor[];
305
+ /** Challenge kinds this provider is permitted to request. */
306
+ readonly kinds: readonly ProviderChallengeKind[];
307
+ /**
308
+ * Client fingerprint profile the SDK must use when reaching this upstream.
309
+ * Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
310
+ * challenge is served, while a Safari profile is admitted. Provider-declared
311
+ * because only the provider knows its upstream's admission rule.
312
+ */
313
+ readonly clientProfile?: string;
314
+ }
203
315
  export type SttAudioInput = {
204
316
  kind: "base64";
205
317
  data: string;
@@ -264,6 +376,9 @@ export interface SttContext {
264
376
  transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
265
377
  extractVerificationCode(text: string, options?: SttVerificationCodeOptions): VerificationCodeExtractionResult;
266
378
  }
379
+ export interface ResolverContext {
380
+ solve(challenge: ProviderChallenge, signal?: AbortSignal): Promise<ChallengeSolution>;
381
+ }
267
382
  export interface HealthJourneySchedule {
268
383
  kind: "interval";
269
384
  /** ISO 8601 duration, for example PT8H. */
@@ -395,7 +510,7 @@ export interface HealthJourneyRunResult {
395
510
  label?: string;
396
511
  metadata?: Record<string, unknown>;
397
512
  }
398
- export interface HealthJourneyDefinition {
513
+ interface HealthJourneyDefinitionBase {
399
514
  id: string;
400
515
  title?: string;
401
516
  description?: string;
@@ -407,8 +522,14 @@ export interface HealthJourneyDefinition {
407
522
  requiredSecrets?: readonly string[];
408
523
  manualTrigger?: HealthJourneyManualTriggerPolicy;
409
524
  steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
410
- run?: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
411
525
  }
526
+ export type HealthJourneyDefinition = HealthJourneyDefinitionBase & ({
527
+ run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
528
+ scenario?: never;
529
+ } | {
530
+ scenario: HealthScenario;
531
+ run?: never;
532
+ });
412
533
  /**
413
534
  * Health-check authoring surface owned by `@apifuse/provider-sdk`.
414
535
  *
@@ -479,13 +600,22 @@ export interface HealthCheckCaseResult {
479
600
  * so authors get IntelliSense and compile-time errors when accessing fields
480
601
  * that do not exist on the operation's declared output schema.
481
602
  */
482
- export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
603
+ export type HealthCheckCase<TInput = unknown, TOutput = unknown> = {
483
604
  /** Human-readable case name; unique within the suite. */
484
605
  name: string;
485
606
  /** Optional longer description shown on ops dashboards. */
486
607
  description?: string;
487
608
  /** Input passed to the operation handler for this case. */
488
609
  input: TInput;
610
+ /** Override per-case degradation threshold (ms); falls back to the suite default. */
611
+ degradedThresholdMs?: number;
612
+ /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
613
+ timeoutMs?: number;
614
+ /** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
615
+ expectedStatus?: "ok" | "degraded";
616
+ /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
617
+ enabled?: () => boolean;
618
+ } & ({
489
619
  /**
490
620
  * Optional runtime input preparation hook for volatile probes. Use this when
491
621
  * the durable probe input must be derived from a live read-only operation
@@ -503,15 +633,14 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
503
633
  * + lambda only.
504
634
  */
505
635
  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
- }
636
+ /** Declarative scenarios replace the imperative preparation and assertion hooks. */
637
+ scenario?: never;
638
+ } | {
639
+ /** Declarative scenario executed by the health-monitor runtime. */
640
+ scenario: HealthScenario;
641
+ prepareInput?: never;
642
+ assertions?: never;
643
+ });
515
644
  /**
516
645
  * Operation-level health-check suite. At least one case is required when
517
646
  * present. All cases share the suite's interval and default timeout.
@@ -609,23 +738,42 @@ export interface HealthMonitorProbeOverride {
609
738
  /** Optional degraded threshold override for generated registry probes. */
610
739
  degradedThresholdMs?: number;
611
740
  }
741
+ export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
742
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
612
743
  export interface OperationErrorCode {
613
744
  code: string;
614
- status?: number;
745
+ status?: ProviderErrorStatus;
615
746
  description: string;
616
747
  retryable?: boolean;
617
748
  }
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[];
627
- }
628
749
  export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
750
+ export type StealthBrowser = "chrome" | "firefox" | "safari";
751
+ export type StealthOS = "windows" | "macos" | "linux" | "ios";
752
+ /** A supported, fully resolved browser/OS fingerprint pair. */
753
+ export type StealthProfileDescriptor = {
754
+ browser: "chrome";
755
+ os: "windows" | "macos" | "linux";
756
+ } | {
757
+ browser: "firefox";
758
+ os: "windows" | "macos" | "linux";
759
+ } | {
760
+ browser: "safari";
761
+ os: "macos" | "ios";
762
+ };
763
+ /**
764
+ * Browser/OS fingerprint selection. Chrome and macOS are the named defaults
765
+ * when their respective axes are omitted.
766
+ */
767
+ export type StealthProfileSelection = {
768
+ browser?: "chrome";
769
+ os?: "windows" | "macos" | "linux";
770
+ } | {
771
+ browser: "firefox";
772
+ os?: "windows" | "macos" | "linux";
773
+ } | {
774
+ browser: "safari";
775
+ os?: "macos" | "ios";
776
+ };
629
777
  export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
630
778
  export interface BrowserOptions {
631
779
  headless?: boolean;
@@ -634,9 +782,7 @@ export interface BrowserOptions {
634
782
  engine?: BrowserEngine;
635
783
  requireCdpPool?: boolean;
636
784
  }
637
- export interface StealthProfile {
638
- name: string;
639
- platform: StealthPlatform;
785
+ export type StealthProfile = StealthProfileDescriptor & {
640
786
  version: string;
641
787
  userAgent: string;
642
788
  tlsClientIdentifier?: string;
@@ -644,13 +790,33 @@ export interface StealthProfile {
644
790
  ja4?: string;
645
791
  h2Settings?: Record<string, unknown>;
646
792
  headerOrder?: string[];
647
- }
648
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
793
+ };
794
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
649
795
  export type ConnectionMode = AuthMode;
650
796
  export type ProviderReviewed = "first-party" | "community" | "staging";
651
797
  export type ProviderAccessVisibility = "public" | "early_access";
652
798
  export type ProviderProxyMode = "disabled" | "optional" | "required";
653
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
799
+ /**
800
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
801
+ * (a common mistake because the names collide with a well-known rebrand):
802
+ *
803
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
804
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
805
+ * endpoints). This is our own vendor. It is NOT the company formerly named
806
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
807
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
808
+ * credentials; geo/session encoded in the username, no allocation API.
809
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
810
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
811
+ * username params. A different company from `smartproxy` above.
812
+ * **@deprecated** — unused; no managed adapter. Declare a
813
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
814
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
815
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
816
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
817
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
818
+ */
819
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
654
820
  export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
655
821
  export interface ProviderProxyPolicy {
656
822
  /**
@@ -658,7 +824,18 @@ export interface ProviderProxyPolicy {
658
824
  * certificate verification, and vendor allocator endpoints are SDK-owned.
659
825
  */
660
826
  mode: ProviderProxyMode;
827
+ /**
828
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
829
+ * chain. A single-element `providers` list is equivalent to this field.
830
+ */
661
831
  provider?: ProviderProxyProvider;
832
+ /**
833
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
834
+ * fails over to the next when a vendor lacks credentials or its allocation /
835
+ * transport is exhausted. When omitted, `provider` (or the platform default)
836
+ * is used as a single-vendor chain.
837
+ */
838
+ providers?: ProviderProxyProvider[];
662
839
  geo?: {
663
840
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
664
841
  country?: Iso3166Alpha2CountryCode;
@@ -669,6 +846,12 @@ export interface ProviderProxyPolicy {
669
846
  affinity?: ProviderProxySessionAffinity;
670
847
  lifetimeMinutes?: number;
671
848
  poolSize?: number;
849
+ /**
850
+ * Seconds before hard sticky expiry at which native connections receive
851
+ * the `expiring` event so the provider can drain and reconnect cleanly.
852
+ * Declared by the provider; the SDK does not assume a default cut point.
853
+ */
854
+ drainLeadSeconds?: number;
672
855
  };
673
856
  }
674
857
  export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
@@ -677,13 +860,12 @@ export interface ProviderAccessConfig {
677
860
  * Provider-level rollout visibility.
678
861
  *
679
862
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
680
- * the existing provider policy stack.
863
+ * the existing provider policy stack.
681
864
  * - `early_access`: hidden from public discovery and callable only when the
682
- * active customer organization has a provider-level access grant.
865
+ * active customer organization has a provider-level access grant.
683
866
  *
684
867
  * This is intentionally provider-level only. It does not alter auth mode,
685
- * operation schemas, health-check authoring, `openWorld`, or Connection
686
- * requirements.
868
+ * operation schemas, health-check authoring, or Connection requirements.
687
869
  */
688
870
  visibility?: ProviderAccessVisibility;
689
871
  }
@@ -748,6 +930,10 @@ export interface ProviderMeta {
748
930
  publicProfile?: ProviderPublicProfile;
749
931
  contract?: {
750
932
  publicSchemaFieldNames?: "normalized";
933
+ readonly pinnedWireFieldPaths?: readonly {
934
+ readonly path: string;
935
+ readonly reason: string;
936
+ }[];
751
937
  };
752
938
  }
753
939
  export type RequestParamPrimitive = string | number | boolean | null | undefined;
@@ -810,6 +996,11 @@ export interface HttpRetrySummary {
810
996
  export interface RequestOptions {
811
997
  headers?: Record<string, string>;
812
998
  params?: RequestParams;
999
+ /**
1000
+ * Query parameters whose values contain credentials or other secret material.
1001
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1002
+ */
1003
+ sensitiveParams?: Record<string, string>;
813
1004
  proxy?: string;
814
1005
  timeout?: number;
815
1006
  /**
@@ -818,12 +1009,38 @@ export interface RequestOptions {
818
1009
  */
819
1010
  throwOnHttpError?: boolean;
820
1011
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1012
+ /**
1013
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1014
+ * evaluated before the next request is issued. Existing callers that omit
1015
+ * this policy retain the native fetch redirect behavior.
1016
+ */
1017
+ redirectPolicy?: HttpRedirectPolicy;
821
1018
  }
1019
+ export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1020
+ export type HttpRedirectPolicyMode = "same-origin";
1021
+ export interface HttpRedirectPolicy {
1022
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1023
+ mode: HttpRedirectPolicyMode;
1024
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1025
+ maxHops: number;
1026
+ }
1027
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
822
1028
  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 {
1029
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy" | "headers"> {
1030
+ /**
1031
+ * Request headers. Array values and case-insensitive duplicate names are
1032
+ * combined in caller order using `", "`, matching Chrome's Fetch behavior.
1033
+ */
1034
+ headers?: Record<string, string | string[]>;
824
1035
  method?: HttpMethod;
825
1036
  body?: string | Buffer;
826
1037
  redirect?: "follow" | "manual" | "error";
1038
+ /**
1039
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1040
+ * transport aborts the response and throws `response_too_large` if the
1041
+ * declared or streamed body exceeds this limit.
1042
+ */
1043
+ maxBodyBytes?: number;
827
1044
  /**
828
1045
  * Offsets policy-managed proxy pool selection for caller-managed retries.
829
1046
  * Use when a request receives an upstream challenge page rather than a
@@ -831,29 +1048,58 @@ export interface StealthFetchOptions extends RequestOptions {
831
1048
  * operation-affinity proxy.
832
1049
  */
833
1050
  proxyAttemptOffset?: number;
834
- /** Override the configured browser-like stealth profile for this request. */
835
- profile?: string;
836
1051
  /**
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.
1052
+ * SDK-specific stealth controls. Standard HTTP metadata such as language,
1053
+ * referrer, and content type belongs in `headers`.
840
1054
  */
841
- stealth?: {
1055
+ stealth?: StealthProfileSelection & {
1056
+ /** Override the configured browser and/or OS for this request. */
1057
+ /** Declare the Chrome request class when it cannot be inferred from the method. */
1058
+ requestClass?: "navigation" | "xhr" | "post";
1059
+ /**
1060
+ * Use only for proxy products that terminate CONNECT with a private CA
1061
+ * instead of tunneling the origin certificate chain.
1062
+ */
842
1063
  insecureSkipVerify?: boolean;
843
1064
  };
844
1065
  }
845
1066
  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;
1067
+ /** URL-less reads use the jar's response URL or session base URL. */
1068
+ get(name: string, url?: string): string | undefined;
1069
+ getAll(url?: string): Record<string, string>;
1070
+ toString(url?: string): string;
1071
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
1072
+ }
1073
+ /**
1074
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1075
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1076
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1077
+ */
1078
+ export interface StealthCookieStoreV1 {
1079
+ readonly version: 1;
1080
+ readonly jar: SerializedCookieJar;
850
1081
  }
1082
+ /** Cookie persistence formats understood by this SDK version. */
1083
+ export type StealthCookieStore = StealthCookieStoreV1;
851
1084
  export interface StealthSessionCookies extends CookieJar {
852
- has(name: string): boolean;
853
- setFromCookieStrings(cookieStrings: readonly string[]): void;
854
- toHeader(): string;
1085
+ has(name: string, url?: string): boolean;
1086
+ /** URL-less writes are scoped to the session base URL. */
1087
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1088
+ toHeader(url?: string): string;
1089
+ /**
1090
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1091
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1092
+ */
855
1093
  snapshot(): Record<string, string>;
1094
+ /**
1095
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1096
+ * @deprecated Use deserialize() with state produced by serialize().
1097
+ */
856
1098
  restore(cookies: Record<string, string>): void;
1099
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1100
+ serialize(): StealthCookieStoreV1;
1101
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1102
+ deserialize(state: StealthCookieStore): void;
857
1103
  clear(): void;
858
1104
  }
859
1105
  export interface DeclarativeStealthResponse {
@@ -895,8 +1141,14 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
895
1141
  export interface StealthRedirectRunResult {
896
1142
  final: StealthResponse;
897
1143
  hops: StealthRedirectHop[];
898
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1144
+ reason: RedirectRunReason;
1145
+ /**
1146
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1147
+ * @deprecated Use cookieStore for lossless persistence.
1148
+ */
899
1149
  cookies: Record<string, string>;
1150
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1151
+ cookieStore: StealthCookieStoreV1;
900
1152
  }
901
1153
  export interface StealthSession {
902
1154
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
@@ -959,11 +1211,159 @@ export interface HttpClient {
959
1211
  stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
960
1212
  sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
961
1213
  }
1214
+ /** Request-scoped file reference accepted by provider operation inputs. */
1215
+ export interface ProviderFileRef {
1216
+ readonly type: "request_file";
1217
+ readonly id: string;
1218
+ readonly filename: string;
1219
+ readonly mime_type?: string;
1220
+ readonly size: number;
1221
+ readonly sha256?: string;
1222
+ }
1223
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1224
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1225
+ readonly mimeType?: string;
1226
+ arrayBuffer(): Promise<ArrayBuffer>;
1227
+ bytes(): Promise<Uint8Array>;
1228
+ stream(): ReadableStream<Uint8Array>;
1229
+ };
1230
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1231
+ export interface ProviderFilesContext {
1232
+ has(input: string | ProviderFileRef): boolean;
1233
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1234
+ }
1235
+ /** Where provider business logic executes relative to the capability engine. */
1236
+ export type ProviderRuntimeTarget = "vanilla" | "engine";
1237
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1238
+ export interface NativeTcpPortRange {
1239
+ readonly start: number;
1240
+ readonly end: number;
1241
+ }
1242
+ /** Static native TCP egress declared by a provider. */
1243
+ export interface NativeTcpEgressRule {
1244
+ readonly host: string;
1245
+ readonly ports: readonly number[];
1246
+ readonly tls: NativeTcpTlsMode;
1247
+ }
1248
+ /**
1249
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1250
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1251
+ * Dynamic rules must declare at least one target host selector through
1252
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1253
+ * sources and targets match only same-family selectors (except exact
1254
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1255
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1256
+ *
1257
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1258
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1259
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1260
+ * Every rule must declare a source host selector, source port list/range, and
1261
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1262
+ */
1263
+ export interface NativeTcpDynamicEgressRule {
1264
+ readonly sourceHost?: string;
1265
+ readonly sourceHostSuffixes?: readonly string[];
1266
+ readonly sourceIpv4Cidrs?: readonly string[];
1267
+ readonly sourceIpv6Cidrs?: readonly string[];
1268
+ readonly sourcePorts?: readonly number[];
1269
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1270
+ readonly targetHostSuffixes?: readonly string[];
1271
+ readonly targetIpv4Cidrs?: readonly string[];
1272
+ readonly targetIpv6Cidrs?: readonly string[];
1273
+ readonly targetPorts?: readonly number[];
1274
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1275
+ readonly tls: NativeTcpTlsMode;
1276
+ readonly ttlMs?: number;
1277
+ readonly maxGrants?: number;
1278
+ }
1279
+ /** Common TCP/TLS connection input supported by the native runtime. */
1280
+ export interface NativeNetworkConnectInput {
1281
+ readonly host: string;
1282
+ readonly port: number;
1283
+ readonly serverName?: string;
1284
+ readonly rejectUnauthorized?: boolean;
1285
+ /**
1286
+ * Maximum time without a successful socket read before the connection is
1287
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1288
+ */
1289
+ readonly idleTimeoutMs?: number;
1290
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1291
+ readonly timeoutMs?: number;
1292
+ readonly signal?: AbortSignal;
1293
+ /** Overrides the credential-derived sticky affinity key. */
1294
+ readonly affinityKey?: string;
1295
+ }
1296
+ export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
1297
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1298
+ export interface NativeNetworkDynamicGrantOptions {
1299
+ readonly sourceHost: string;
1300
+ readonly sourcePort: number;
1301
+ readonly host: string;
1302
+ readonly port: number;
1303
+ readonly tls: NativeTcpTlsMode;
1304
+ readonly ttlMs?: number;
1305
+ }
1306
+ export interface NativeNetworkEgressGrant {
1307
+ revoke(): void;
1308
+ }
1309
+ /** Consumer-facing alias used by native TCP providers. */
1310
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1311
+ /** Resolved egress identity for a native connection routed through a proxy. */
1312
+ export interface NativeProxyEgressInfo {
1313
+ readonly vendor: ProviderProxyProvider;
1314
+ readonly sticky: boolean;
1315
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1316
+ readonly sessionId?: string;
1317
+ /** Hard expiry of the sticky binding, ISO 8601. */
1318
+ readonly expiresAt?: string;
1319
+ }
1320
+ export type NativeProxyExpiringReason = "sticky_expiry";
1321
+ export interface NativeProxyExpiringEvent {
1322
+ readonly expiresAt: string;
1323
+ readonly leadSeconds: number;
1324
+ readonly reason: NativeProxyExpiringReason;
1325
+ }
1326
+ /**
1327
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1328
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1329
+ */
1330
+ export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
1331
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1332
+ export interface NativeNetworkCloseReason {
1333
+ readonly code: string;
1334
+ readonly message: string;
1335
+ }
1336
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1337
+ export interface NativeNetworkConnection {
1338
+ /** Present when the connection was routed through a proxy. */
1339
+ readonly proxy?: NativeProxyEgressInfo;
1340
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1341
+ readonly closeReason?: NativeNetworkCloseReason;
1342
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1343
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1344
+ read(): Promise<Uint8Array | null>;
1345
+ write(data: Uint8Array): Promise<void>;
1346
+ close(): Promise<void>;
1347
+ }
1348
+ export interface NativeNetworkClient {
1349
+ connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
1350
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1351
+ grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
1352
+ }
1353
+ export interface NativeContext {
1354
+ readonly network: NativeNetworkClient;
1355
+ }
1356
+ export interface NativeProviderConfig {
1357
+ readonly network?: {
1358
+ readonly tcp?: readonly NativeTcpEgressRule[];
1359
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1360
+ };
1361
+ }
962
1362
  export interface ProviderCacheKeyOptions {
963
1363
  /**
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.
1364
+ * Additional field names whose values are hashed in stable key material. The
1365
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1366
+ * authorization, cookie, token, password, and secret.
967
1367
  */
968
1368
  redactFields?: string[];
969
1369
  }
@@ -1006,7 +1406,7 @@ export interface ProviderCache {
1006
1406
  export interface StealthClient {
1007
1407
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
1008
1408
  createSession(opts?: {
1009
- profile?: string;
1409
+ stealth?: StealthProfileSelection;
1010
1410
  }): StealthSession;
1011
1411
  close?(): void;
1012
1412
  }
@@ -1036,7 +1436,18 @@ export interface BrowserFrame {
1036
1436
  evaluate<T>(fn: string | (() => T)): Promise<T>;
1037
1437
  locator(selector: string): BrowserLocator;
1038
1438
  }
1039
- export type BrowserResourceMethod = "GET" | "HEAD";
1439
+ export interface BrowserCookie {
1440
+ readonly name: string;
1441
+ readonly value: string;
1442
+ readonly domain: string;
1443
+ readonly path: string;
1444
+ /** Unix seconds. Absent for a session cookie. */
1445
+ readonly expires?: number;
1446
+ readonly httpOnly: boolean;
1447
+ readonly secure: boolean;
1448
+ readonly sameSite?: "Strict" | "Lax" | "None";
1449
+ }
1450
+ export type BrowserResourceMethod = "GET" | "HEAD" | "POST";
1040
1451
  export type BrowserResourceRequest = {
1041
1452
  readonly url: string;
1042
1453
  readonly method: BrowserResourceMethod;
@@ -1045,6 +1456,8 @@ export type BrowserResourceRequest = {
1045
1456
  };
1046
1457
  export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1047
1458
  export type BrowserResourceDecision = {
1459
+ readonly action: "continue";
1460
+ } | {
1048
1461
  readonly action: "fulfill";
1049
1462
  readonly status?: number;
1050
1463
  readonly headers?: Readonly<Record<string, string>>;
@@ -1060,12 +1473,29 @@ export type BrowserResourceRoute = {
1060
1473
  export type BrowserResourcePolicy = {
1061
1474
  readonly defaultAction?: "block";
1062
1475
  readonly allowedMethods?: readonly BrowserResourceMethod[];
1476
+ /**
1477
+ * Appends an enforcing CSP header to every renderable document response
1478
+ * while the policy is active. Existing CSP headers are retained, so this
1479
+ * can only further restrict the document.
1480
+ */
1481
+ readonly documentContentSecurityPolicy?: string;
1063
1482
  readonly routes: readonly BrowserResourceRoute[];
1064
1483
  };
1065
1484
  export interface BrowserPage extends BrowserFrame {
1066
1485
  close(): Promise<void>;
1486
+ /** Returns the user agent used by this page's browser context. */
1487
+ userAgent(): Promise<string>;
1488
+ /**
1489
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1490
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1491
+ */
1492
+ cookies(): Promise<readonly BrowserCookie[]>;
1067
1493
  fill(selector: string, text: string): Promise<void>;
1068
1494
  goto(url: string): Promise<void>;
1495
+ goto(url: string, options?: {
1496
+ readonly timeout?: number;
1497
+ readonly waitUntil?: "load" | "domcontentloaded";
1498
+ }): Promise<void>;
1069
1499
  pageId?: string;
1070
1500
  screenshot(options?: {
1071
1501
  fullPage?: boolean;
@@ -1107,7 +1537,7 @@ export interface TraceConfig {
1107
1537
  exporter?: "console" | "json" | "otlp" | "none";
1108
1538
  endpoint?: string;
1109
1539
  otlp?: {
1110
- endpoint: string;
1540
+ endpoint?: string;
1111
1541
  headers?: Record<string, string>;
1112
1542
  timeout?: number;
1113
1543
  };
@@ -1138,6 +1568,26 @@ export interface ProviderChoiceBindingOptions {
1138
1568
  connection?: boolean;
1139
1569
  credentialKeys?: readonly string[];
1140
1570
  }
1571
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1572
+ export type ProviderChoiceConsumeResult = {
1573
+ readonly status: "consumed";
1574
+ } | {
1575
+ readonly status: "already-consumed";
1576
+ } | {
1577
+ readonly status: "unsupported";
1578
+ };
1579
+ export type ProviderChoiceExplicitParseResult = {
1580
+ readonly status: "active";
1581
+ readonly payload: Record<string, unknown>;
1582
+ /** Stable, opaque key for provider-owned idempotency records. */
1583
+ readonly replayKey: string;
1584
+ /** Atomically claims a word token. Inline tokens report unsupported. */
1585
+ consume(): Promise<ProviderChoiceConsumeResult>;
1586
+ } | {
1587
+ readonly status: "consumed";
1588
+ /** Use this key to read the provider-owned result before returning an error. */
1589
+ readonly replayKey: string;
1590
+ };
1141
1591
  export type ProviderChoiceStorageOptions = {
1142
1592
  readonly mode: "inline";
1143
1593
  } | {
@@ -1165,6 +1615,8 @@ export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unkn
1165
1615
  ttlMs: number;
1166
1616
  nowMs?: number;
1167
1617
  bind?: ProviderChoiceBindingOptions;
1618
+ /** Server storage only: standard emits four words; high emits five. */
1619
+ strength?: "standard" | "high";
1168
1620
  storage?: ProviderChoiceStorageOptions;
1169
1621
  }
1170
1622
  export interface ProviderChoiceParseOptions {
@@ -1176,6 +1628,8 @@ export interface ProviderChoiceParseOptions {
1176
1628
  futureToleranceMs?: number;
1177
1629
  bind?: ProviderChoiceBindingOptions;
1178
1630
  storage?: ProviderChoiceStorageOptions;
1631
+ /** Defaults to never, preserving reusable choice-token parse semantics. */
1632
+ consume?: ProviderChoiceConsumeMode;
1179
1633
  }
1180
1634
  export interface ProviderChoiceContext {
1181
1635
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
@@ -1194,6 +1648,9 @@ export interface ProviderChoiceContext {
1194
1648
  }>;
1195
1649
  }): string | Promise<string>;
1196
1650
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1651
+ parse(options: ProviderChoiceParseOptions & {
1652
+ readonly consume: "explicit";
1653
+ }): Promise<ProviderChoiceExplicitParseResult>;
1197
1654
  parse(options: ProviderChoiceParseOptions & {
1198
1655
  readonly storage?: {
1199
1656
  readonly mode: "inline";
@@ -1209,7 +1666,7 @@ export interface ProviderChoiceContext {
1209
1666
  readonly mode: "auto";
1210
1667
  }>;
1211
1668
  }): Record<string, unknown> | Promise<Record<string, unknown>>;
1212
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1669
+ parse(options: ProviderChoiceParseOptions): Record<string, unknown> | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1213
1670
  }
1214
1671
  export interface ContextScratchpad {
1215
1672
  get(key: string): unknown;
@@ -1285,16 +1742,34 @@ export interface AuthFlowTerminalContext {
1285
1742
  }): AuthTurn;
1286
1743
  }
1287
1744
  export interface FlowContext {
1745
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
1746
+ flowId?: string;
1288
1747
  connectionId?: string;
1289
1748
  externalRef?: string;
1290
1749
  tenantId: string;
1291
1750
  providerId: string;
1292
1751
  http: HttpClient;
1752
+ /** Durable connection-scoped runtime state. Present when the host runtime
1753
+ * supplies one; auth ceremonies must fail closed when absent rather than
1754
+ * fall back to bypassable in-process storage.
1755
+ *
1756
+ * Scoped via `ProviderRuntimeState.forConnection`: requests that resolve no
1757
+ * connection id (pre-connection ceremonies such as first-time logins) share
1758
+ * the documented isolated missing-connection scope. That sharing is the
1759
+ * intended semantic — it lets counters keyed by caller identity (e.g. a
1760
+ * login email) persist across separate ceremonies for the same caller.
1761
+ * Flows storing entries in that scope MUST key them by caller identity;
1762
+ * un-keyed entries would be shared across all connectionless ceremonies. */
1763
+ readonly state?: ProviderRuntimeState;
1764
+ /** Present when the selected runtime supplies native network capabilities. */
1765
+ readonly native?: NativeContext;
1293
1766
  stealth: StealthClient;
1294
1767
  env: EnvContext;
1295
1768
  credential?: CredentialContext;
1296
1769
  context: ContextScratchpad;
1770
+ ocr: OcrContext;
1297
1771
  stt: SttContext;
1772
+ resolver: ResolverContext;
1298
1773
  auth: AuthFlowTerminalContext;
1299
1774
  }
1300
1775
  export interface AuthTurn {
@@ -1326,7 +1801,13 @@ export interface AuthFlowDefinition {
1326
1801
  refresh?: AuthFlowInputHandler;
1327
1802
  }
1328
1803
  export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1804
+ export type StateNamespaceScope = "connection" | "provider";
1329
1805
  export interface StateNamespaceOptions {
1806
+ /**
1807
+ * State isolation boundary. Connection scope is the default; provider scope
1808
+ * must be selected explicitly for provider-wide coordination state.
1809
+ */
1810
+ scope?: StateNamespaceScope;
1330
1811
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1331
1812
  defaultTtl: ProviderStateDurationString;
1332
1813
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1368,24 +1849,69 @@ export interface ProviderStateNamespace {
1368
1849
  increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1369
1850
  }
1370
1851
  export interface ProviderRuntimeState {
1852
+ /**
1853
+ * Returns an immutable view bound to one request connection. An unresolved
1854
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
1855
+ */
1856
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1371
1857
  namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1372
1858
  }
1373
- export interface ProviderContext {
1859
+ /**
1860
+ * The operation context exposed for one provider declaration. Capability
1861
+ * bindings are present only when their corresponding declaration is present;
1862
+ * trace and request remain ambient runtime bindings. Omitting the type
1863
+ * parameter preserves the legacy full context shape for existing annotations.
1864
+ */
1865
+ export type ProviderContext<TConfig = Record<string, unknown>> = {
1866
+ request?: ProviderRequestContext;
1867
+ trace: TraceContext;
1868
+ } & ("env" extends keyof TConfig ? {
1374
1869
  env: EnvContext;
1870
+ } : Record<never, never>) & ("credential" extends keyof TConfig ? {
1375
1871
  credential: CredentialContext;
1376
- request?: ProviderRequestContext;
1872
+ } : Record<never, never>) & ("http" extends keyof TConfig ? {
1377
1873
  http: HttpClient;
1874
+ } : Record<never, never>) & ("files" extends keyof TConfig ? string extends keyof TConfig ? {
1875
+ readonly files?: ProviderFilesContext;
1876
+ } : {
1877
+ readonly files: ProviderFilesContext;
1878
+ } : Record<never, never>) & ("native" extends keyof TConfig ? {
1879
+ readonly native: NativeContext;
1880
+ } : Record<never, never>) & ("cache" extends keyof TConfig ? {
1378
1881
  cache: ProviderCache;
1882
+ } : Record<never, never>) & ("state" extends keyof TConfig ? {
1379
1883
  state: ProviderRuntimeState;
1884
+ } : Record<never, never>) & ("stealth" extends keyof TConfig ? {
1380
1885
  stealth: StealthClient;
1886
+ } : Record<never, never>) & ("browser" extends keyof TConfig ? {
1381
1887
  browser: BrowserClient;
1382
- trace: TraceContext;
1888
+ } : Record<never, never>) & ("auth" extends keyof TConfig ? {
1383
1889
  auth: AuthContext;
1890
+ } : Record<never, never>) & ("ocr" extends keyof TConfig ? {
1891
+ ocr: OcrContext;
1892
+ } : Record<never, never>) & ("stt" extends keyof TConfig ? {
1384
1893
  stt: SttContext;
1894
+ } : Record<never, never>) & ("resolver" extends keyof TConfig ? {
1895
+ resolver: ResolverContext;
1896
+ } : Record<never, never>) & ("choice" extends keyof TConfig ? {
1385
1897
  choice: ProviderChoiceContext;
1898
+ } : Record<never, never>);
1899
+ /** Backwards-compatible name for a declaration-derived provider context. */
1900
+ export type ProviderContextFor<TConfig> = ProviderContext<TConfig>;
1901
+ export interface ProxiedOAuthConfig {
1902
+ authorizeUrl: string;
1903
+ tokenUrl: string;
1904
+ customScheme: string;
1905
+ rewriteProfile: string;
1906
+ clientIdEnvKey: string;
1907
+ pkce?: "S256" | "none";
1908
+ authorizeParams?: Record<string, string>;
1909
+ tokenParams?: Record<string, string>;
1386
1910
  }
1387
1911
  export interface AuthConfig {
1388
1912
  mode: AuthMode;
1913
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
1914
+ proxied?: ProxiedOAuthConfig;
1389
1915
  flow?: AuthFlowDefinition;
1390
1916
  }
1391
1917
  export interface ProviderSecretDeclaration {
@@ -1417,40 +1943,41 @@ export interface OperationContractMetadata {
1417
1943
  lifecycle?: OperationLifecycle;
1418
1944
  deprecation?: OperationDeprecationMetadata;
1419
1945
  }
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;
1946
+ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike, TContext = ProviderContext> {
1947
+ /** Canonical operation-level connection requirement. */
1948
+ connectionMode?: "none" | "optional" | "required";
1949
+ /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
1950
+ connectionExternalRefParam?: string;
1951
+ /** Safety source of truth exposed to clients and approval policy. */
1952
+ riskClass: OperationRiskClass;
1953
+ /** Approval override. Omit when the risk-class default is correct. */
1954
+ approval?: OperationApprovalPolicy;
1955
+ timeoutMs?: number;
1956
+ titleKey?: ProviderLocaleKeyInput;
1434
1957
  descriptionKey?: ProviderLocaleKeyInput;
1435
- docs?: OperationDocMeta;
1958
+ summaryKey?: ProviderLocaleKeyInput;
1959
+ markdownKey?: ProviderLocaleKeyInput;
1436
1960
  whenToUseKeys?: readonly ProviderLocaleKeyInput[];
1437
1961
  whenNotToUseKeys?: readonly ProviderLocaleKeyInput[];
1438
- derivations?: Record<string, string>;
1439
- inputExamples?: readonly OperationInputExample[];
1440
- annotations?: OperationAnnotations;
1962
+ normalizationNotesKeys?: readonly ProviderLocaleKeyInput[];
1963
+ errorCodes?: readonly OperationErrorCode[];
1964
+ examples?: readonly OperationExample[];
1441
1965
  contract?: OperationContractMetadata;
1442
1966
  tags?: readonly string[];
1443
1967
  relatedOperations?: OperationRelationships;
1444
- toolRouter?: OperationToolRouterMetadata;
1445
1968
  observability?: OperationObservabilityConfig;
1446
1969
  transport?: OperationTransport;
1447
- retryOnAuthRefresh?: boolean;
1448
1970
  input: TInput;
1449
1971
  output: TOutput;
1450
- handler(ctx: ProviderContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1972
+ handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1451
1973
  fixtures?: {
1452
1974
  request: InferSchemaOutput<TInput>;
1453
1975
  response: InferSchemaOutput<TOutput>;
1976
+ /**
1977
+ * KST calendar date when `response` evidence was captured. Date fields in
1978
+ * the response align with this date, not a resolved relative request date.
1979
+ */
1980
+ recordedAt?: string;
1454
1981
  };
1455
1982
  upstream?: {
1456
1983
  baseUrl?: string;
@@ -1498,36 +2025,51 @@ export interface ProviderDeploymentOverrides {
1498
2025
  };
1499
2026
  buildContext?: string;
1500
2027
  }
1501
- export interface ProviderDefinition {
2028
+ export interface ProviderDefinition<TContext = ProviderContext> {
1502
2029
  id: string;
1503
2030
  version: string;
1504
2031
  runtime: "standard" | "shared" | "browser";
2032
+ /**
2033
+ * `vanilla` executes provider business logic outside the engine; `engine`
2034
+ * keeps session-bearing provider logic in the engine process.
2035
+ *
2036
+ * Omitted only for definitions authored before the engine migration. New
2037
+ * providers should declare the target explicitly.
2038
+ */
2039
+ runtimeTarget?: ProviderRuntimeTarget;
1505
2040
  /**
1506
2041
  * Optional deployment overrides, passed through verbatim from
1507
2042
  * `defineProvider({ deployment })`. Validation and profile resolution are
1508
2043
  * owned by the APIFuse registry builder, not the SDK.
1509
2044
  */
1510
2045
  deployment?: ProviderDeploymentOverrides;
2046
+ http?: Record<string, never> | true;
1511
2047
  allowedHosts?: string[];
1512
- stealth?: {
1513
- profile: string;
1514
- platform: StealthPlatform;
1515
- };
2048
+ native?: NativeProviderConfig;
2049
+ stealth?: StealthProfileSelection;
1516
2050
  proxy?: ProviderProxyConfig;
2051
+ ocr?: ProviderOcrConfig;
1517
2052
  stt?: ProviderSttConfig;
2053
+ resolver?: ProviderResolverConfig;
1518
2054
  browser?: {
1519
2055
  engine: BrowserEngine;
1520
2056
  };
1521
2057
  auth?: AuthConfig;
2058
+ choice?: Record<string, never> | true;
1522
2059
  reviewed?: ProviderReviewed;
1523
2060
  access?: ProviderAccessConfig;
1524
2061
  secrets?: ProviderSecretDeclaration[];
2062
+ env?: Record<string, never> | true;
1525
2063
  credential?: CredentialDeclaration;
1526
2064
  context?: ContextDeclaration;
2065
+ state?: Record<string, never> | true;
2066
+ cache?: Record<string, never> | true;
2067
+ files?: Record<string, never> | true;
1527
2068
  meta: ProviderMeta;
1528
- operations: Record<string, OperationDefinition<SchemaLike, SchemaLike>>;
2069
+ operations: Record<string, OperationDefinition<SchemaLike, SchemaLike, TContext>>;
1529
2070
  healthMonitor?: ProviderHealthMonitorConfig;
1530
2071
  /** Transitional alias for `healthMonitor`; `defineProvider` mirrors both. */
1531
2072
  healthProbe?: ProviderHealthProbeConfig;
1532
2073
  healthJourneys?: readonly HealthJourneyDefinition[];
1533
2074
  }
2075
+ export {};