@apifuse/provider-sdk 2.2.0-beta.4 → 2.2.0-beta.41

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 (315) hide show
  1. package/AUTHORING.md +501 -13
  2. package/CHANGELOG.md +169 -1
  3. package/README.md +72 -14
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +150 -5
  6. package/bin/apifuse-dev.ts +38 -5
  7. package/bin/apifuse-migrate-shape.ts +84 -0
  8. package/bin/apifuse-pack-check.ts +22 -2
  9. package/bin/apifuse-pack-smoke.ts +57 -2
  10. package/bin/apifuse-pack-types.ts +356 -38
  11. package/bin/apifuse-perf.ts +14 -13
  12. package/bin/apifuse-record.ts +691 -68
  13. package/bin/apifuse-submit-check.ts +2301 -282
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/submit-check-delimited-text.ts +50 -0
  16. package/dist/auth-turn/index.d.ts +3 -3
  17. package/dist/auth-turn/index.js +1 -1
  18. package/dist/auth.d.ts +14 -0
  19. package/dist/auth.js +67 -0
  20. package/dist/ceremonies/index.d.ts +16 -0
  21. package/dist/ceremonies/index.js +141 -36
  22. package/dist/cli/commands.d.ts +1 -1
  23. package/dist/cli/commands.js +16 -0
  24. package/dist/cli/create.d.ts +3 -0
  25. package/dist/cli/create.js +40 -35
  26. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  27. package/dist/cli/migrate-provider-shape.js +515 -0
  28. package/dist/cli/prompt-assets.d.ts +80 -0
  29. package/dist/cli/prompt-assets.js +743 -0
  30. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  31. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  32. package/dist/cli/templates/provider/README.md.tpl +4 -4
  33. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  34. package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -1
  35. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  36. package/dist/config/loader.d.ts +177 -16
  37. package/dist/config/loader.js +424 -127
  38. package/dist/contract-serialization.js +4 -8
  39. package/dist/contract-types.d.ts +1 -0
  40. package/dist/contract.js +3 -0
  41. package/dist/declaration-validation.d.ts +32 -0
  42. package/dist/declaration-validation.js +207 -0
  43. package/dist/define.d.ts +51 -25
  44. package/dist/define.js +774 -39
  45. package/dist/error-observability.d.ts +7 -0
  46. package/dist/error-observability.js +61 -0
  47. package/dist/error-resolution.d.ts +4 -0
  48. package/dist/error-resolution.js +122 -0
  49. package/dist/errors.d.ts +33 -0
  50. package/dist/errors.js +40 -0
  51. package/dist/fixture-sanitization.d.ts +28 -0
  52. package/dist/fixture-sanitization.js +227 -0
  53. package/dist/health-scenario.d.ts +1842 -0
  54. package/dist/health-scenario.js +624 -0
  55. package/dist/index.d.ts +19 -9
  56. package/dist/index.js +10 -6
  57. package/dist/lint.d.ts +6 -1
  58. package/dist/lint.js +362 -3
  59. package/dist/native-address.d.ts +43 -0
  60. package/dist/native-address.js +281 -0
  61. package/dist/native-egress-policy.d.ts +31 -0
  62. package/dist/native-egress-policy.js +288 -0
  63. package/dist/observability.d.ts +5 -2
  64. package/dist/observability.js +48 -1
  65. package/dist/provider.d.ts +8 -2
  66. package/dist/provider.js +3 -1
  67. package/dist/runtime/auth-flow.d.ts +5 -1
  68. package/dist/runtime/auth-flow.js +6 -0
  69. package/dist/runtime/browser.d.ts +1 -0
  70. package/dist/runtime/browser.js +492 -49
  71. package/dist/runtime/cache.d.ts +1 -0
  72. package/dist/runtime/cache.js +169 -15
  73. package/dist/runtime/choice-wordlist.d.ts +9 -0
  74. package/dist/runtime/choice-wordlist.js +138 -0
  75. package/dist/runtime/choice.d.ts +13 -1
  76. package/dist/runtime/choice.js +490 -102
  77. package/dist/runtime/executor.d.ts +2 -2
  78. package/dist/runtime/executor.js +37 -3
  79. package/dist/runtime/http.d.ts +1 -0
  80. package/dist/runtime/http.js +515 -53
  81. package/dist/runtime/instrumentation.d.ts +2 -2
  82. package/dist/runtime/instrumentation.js +366 -8
  83. package/dist/runtime/native-network-errors.d.ts +33 -0
  84. package/dist/runtime/native-network-errors.js +69 -0
  85. package/dist/runtime/native-network.d.ts +96 -0
  86. package/dist/runtime/native-network.js +1232 -0
  87. package/dist/runtime/ocr.d.ts +29 -0
  88. package/dist/runtime/ocr.js +440 -0
  89. package/dist/runtime/proxy-errors.js +6 -2
  90. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  91. package/dist/runtime/proxy-nodemaven.js +146 -0
  92. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  93. package/dist/runtime/proxy-telemetry.js +154 -47
  94. package/dist/runtime/redirects.d.ts +29 -0
  95. package/dist/runtime/redirects.js +36 -0
  96. package/dist/runtime/redis.d.ts +1 -1
  97. package/dist/runtime/redis.js +4 -2
  98. package/dist/runtime/request-options.d.ts +68 -1
  99. package/dist/runtime/request-options.js +548 -0
  100. package/dist/runtime/resolver-config.d.ts +6 -0
  101. package/dist/runtime/resolver-config.js +6 -0
  102. package/dist/runtime/resolver-public.d.ts +1 -0
  103. package/dist/runtime/resolver-public.js +1 -0
  104. package/dist/runtime/resolver-shared.d.ts +3 -0
  105. package/dist/runtime/resolver-shared.js +12 -0
  106. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  107. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  108. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  109. package/dist/runtime/resolver-vendors/browser.js +377 -0
  110. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  111. package/dist/runtime/resolver-vendors/capsolver.js +526 -0
  112. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  113. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  114. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  115. package/dist/runtime/resolver-vendors/twocaptcha.js +407 -0
  116. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  117. package/dist/runtime/resolver-vendors/types.js +96 -0
  118. package/dist/runtime/resolver.d.ts +60 -0
  119. package/dist/runtime/resolver.js +737 -0
  120. package/dist/runtime/secrets.d.ts +27 -0
  121. package/dist/runtime/secrets.js +51 -0
  122. package/dist/runtime/state.d.ts +3 -0
  123. package/dist/runtime/state.js +277 -71
  124. package/dist/runtime/stealth-cookies.d.ts +20 -0
  125. package/dist/runtime/stealth-cookies.js +111 -0
  126. package/dist/runtime/stealth.d.ts +28 -3
  127. package/dist/runtime/stealth.js +519 -255
  128. package/dist/runtime/stt.js +1 -12
  129. package/dist/runtime/timeout.d.ts +5 -0
  130. package/dist/runtime/timeout.js +12 -0
  131. package/dist/runtime/trace-config.d.ts +12 -0
  132. package/dist/runtime/trace-config.js +61 -0
  133. package/dist/serve.d.ts +1 -1
  134. package/dist/serve.js +1 -1
  135. package/dist/server/error-observability.d.ts +1 -0
  136. package/dist/server/error-observability.js +1 -0
  137. package/dist/server/index.d.ts +6 -3
  138. package/dist/server/index.js +3 -3
  139. package/dist/server/self-test-input-tokens.d.ts +2 -1
  140. package/dist/server/self-test-input-tokens.js +18 -14
  141. package/dist/server/self-test.d.ts +114 -0
  142. package/dist/server/self-test.js +787 -148
  143. package/dist/server/serve-implementation.d.ts +225 -0
  144. package/dist/server/serve-implementation.js +2242 -0
  145. package/dist/server/serve.d.ts +1 -70
  146. package/dist/server/serve.js +1 -1130
  147. package/dist/server/trace-output.d.ts +4 -0
  148. package/dist/server/trace-output.js +20 -0
  149. package/dist/server/types.d.ts +30 -5
  150. package/dist/server/types.js +13 -1
  151. package/dist/stateful/errors.d.ts +19 -0
  152. package/dist/stateful/errors.js +24 -0
  153. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  154. package/dist/stateful/http-provider-event-emitter.js +237 -0
  155. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  156. package/dist/stateful/http-session-owner-registry.js +210 -0
  157. package/dist/stateful/index.d.ts +18 -0
  158. package/dist/stateful/index.js +18 -0
  159. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  160. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  161. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  162. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  163. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  164. package/dist/stateful/provider-event-pipeline.js +1 -0
  165. package/dist/stateful/provider-events.d.ts +101 -0
  166. package/dist/stateful/provider-events.js +289 -0
  167. package/dist/stateful/session-key.d.ts +15 -0
  168. package/dist/stateful/session-key.js +86 -0
  169. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  170. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  171. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  172. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  173. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  174. package/dist/stateful/stateful-provider-adapter.js +287 -0
  175. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  176. package/dist/stateful/stateful-provider-observability.js +161 -0
  177. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  178. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  179. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  180. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  181. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  182. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  183. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  184. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  185. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  186. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  187. package/dist/stateful-signing.d.ts +18 -0
  188. package/dist/stateful-signing.js +27 -0
  189. package/dist/stealth/profiles.js +16 -7
  190. package/dist/stream-evidence.d.ts +74 -0
  191. package/dist/stream-evidence.js +785 -0
  192. package/dist/stream.js +7 -1
  193. package/dist/testing/index.d.ts +2 -1
  194. package/dist/testing/index.js +2 -1
  195. package/dist/testing/run.d.ts +32 -2
  196. package/dist/testing/run.js +489 -21
  197. package/dist/trace-sanitization.d.ts +5 -0
  198. package/dist/trace-sanitization.js +45 -0
  199. package/dist/types.d.ts +563 -33
  200. package/dist/types.js +1 -0
  201. package/package.json +44 -5
  202. package/src/auth-turn/index.ts +1 -1
  203. package/src/auth.ts +118 -0
  204. package/src/ceremonies/index.ts +189 -46
  205. package/src/cli/commands.ts +20 -0
  206. package/src/cli/create.ts +48 -35
  207. package/src/cli/migrate-provider-shape.ts +701 -0
  208. package/src/cli/prompt-assets.ts +865 -0
  209. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  210. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  211. package/src/cli/templates/provider/README.md.tpl +4 -4
  212. package/src/cli/templates/provider/index.ts.tpl +6 -3
  213. package/src/cli/templates/provider/operations/ping.ts.tpl +2 -1
  214. package/src/cli/templates/provider/provider.json.tpl +6 -0
  215. package/src/config/loader.ts +665 -163
  216. package/src/contract-serialization.ts +5 -7
  217. package/src/contract-types.ts +1 -0
  218. package/src/contract.ts +3 -0
  219. package/src/declaration-validation.ts +266 -0
  220. package/src/define.ts +1003 -88
  221. package/src/error-observability.ts +64 -0
  222. package/src/error-resolution.ts +127 -0
  223. package/src/errors.ts +68 -0
  224. package/src/fixture-sanitization.ts +264 -0
  225. package/src/health-scenario.ts +875 -0
  226. package/src/index.ts +205 -8
  227. package/src/lint.ts +408 -4
  228. package/src/native-address.ts +340 -0
  229. package/src/native-egress-policy.ts +358 -0
  230. package/src/observability.ts +51 -1
  231. package/src/provider.ts +134 -0
  232. package/src/runtime/auth-flow.ts +12 -0
  233. package/src/runtime/browser.ts +661 -63
  234. package/src/runtime/cache.ts +189 -14
  235. package/src/runtime/choice-wordlist.ts +145 -0
  236. package/src/runtime/choice.ts +631 -120
  237. package/src/runtime/executor.ts +53 -8
  238. package/src/runtime/http.ts +641 -61
  239. package/src/runtime/instrumentation.ts +520 -15
  240. package/src/runtime/native-network-errors.ts +99 -0
  241. package/src/runtime/native-network.ts +1605 -0
  242. package/src/runtime/ocr.ts +523 -0
  243. package/src/runtime/proxy-errors.ts +12 -4
  244. package/src/runtime/proxy-nodemaven.ts +221 -0
  245. package/src/runtime/proxy-telemetry.ts +244 -75
  246. package/src/runtime/redirects.ts +66 -0
  247. package/src/runtime/redis.ts +7 -2
  248. package/src/runtime/request-options.ts +680 -1
  249. package/src/runtime/resolver-config.ts +6 -0
  250. package/src/runtime/resolver-public.ts +20 -0
  251. package/src/runtime/resolver-shared.ts +17 -0
  252. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  253. package/src/runtime/resolver-vendors/browser.ts +533 -0
  254. package/src/runtime/resolver-vendors/capsolver.ts +700 -0
  255. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  256. package/src/runtime/resolver-vendors/twocaptcha.ts +539 -0
  257. package/src/runtime/resolver-vendors/types.ts +212 -0
  258. package/src/runtime/resolver.ts +1103 -0
  259. package/src/runtime/secrets.ts +64 -0
  260. package/src/runtime/state.ts +394 -77
  261. package/src/runtime/stealth-cookies.ts +132 -0
  262. package/src/runtime/stealth.ts +675 -289
  263. package/src/runtime/stt.ts +1 -19
  264. package/src/runtime/timeout.ts +18 -0
  265. package/src/runtime/trace-config.ts +77 -0
  266. package/src/serve.ts +6 -1
  267. package/src/server/error-observability.ts +1 -0
  268. package/src/server/index.ts +39 -2
  269. package/src/server/self-test-input-tokens.ts +29 -14
  270. package/src/server/self-test.ts +1030 -175
  271. package/src/server/serve-implementation.ts +3338 -0
  272. package/src/server/serve.ts +1 -1626
  273. package/src/server/trace-output.ts +32 -0
  274. package/src/server/types.ts +13 -1
  275. package/src/stateful/README.md +146 -0
  276. package/src/stateful/errors.ts +35 -0
  277. package/src/stateful/http-provider-event-emitter.ts +314 -0
  278. package/src/stateful/http-session-owner-registry.ts +306 -0
  279. package/src/stateful/index.ts +18 -0
  280. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  281. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  282. package/src/stateful/provider-event-pipeline.ts +61 -0
  283. package/src/stateful/provider-events.ts +462 -0
  284. package/src/stateful/session-key.ts +111 -0
  285. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  286. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  287. package/src/stateful/stateful-provider-adapter.ts +562 -0
  288. package/src/stateful/stateful-provider-observability.ts +261 -0
  289. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  290. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  291. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  292. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  293. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  294. package/src/stateful-signing.ts +46 -0
  295. package/src/stealth/profiles.ts +17 -7
  296. package/src/stream-evidence.ts +988 -0
  297. package/src/stream.ts +8 -1
  298. package/src/testing/index.ts +10 -1
  299. package/src/testing/run.ts +658 -15
  300. package/src/trace-sanitization.ts +63 -0
  301. package/src/types.ts +698 -65
  302. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  303. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  304. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  305. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  306. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  307. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  308. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  309. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  310. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  311. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  312. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  313. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  314. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  315. /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> {
@@ -46,6 +48,8 @@ export interface OperationToolRouterMetadata {
46
48
  riskClass?: OperationRiskClass;
47
49
  /** OpenAI remote-MCP approval hint. Defaults from riskClass. */
48
50
  approval?: OperationApprovalPolicy;
51
+ /** Canonical operation-level connection requirement consumed by the registry and Gateway. */
52
+ connectionMode?: "none" | "optional" | "required";
49
53
  /** Override connection requirement when provider auth + openWorld inference is insufficient. */
50
54
  requiresConnection?: boolean;
51
55
  /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
@@ -193,6 +197,54 @@ export interface SmsOtpMatcherDefinition {
193
197
  /** Runtime/fixture helper. Not serialized into generated registry artifacts. */
194
198
  extractOtp(body: string): string | null;
195
199
  }
200
+ export interface ProviderOcrConfig {
201
+ readonly mode: "required" | "optional";
202
+ }
203
+ export type OcrImageInput = {
204
+ readonly kind: "base64";
205
+ readonly data: string;
206
+ readonly mediaType?: string;
207
+ } | {
208
+ readonly kind: "url";
209
+ readonly url: string;
210
+ };
211
+ export interface OcrRecognizeRequest {
212
+ readonly image: OcrImageInput;
213
+ readonly hint?: "captcha" | "document" | "generic";
214
+ readonly prompt?: string;
215
+ readonly maxTokens?: number;
216
+ readonly timeoutMs?: number;
217
+ }
218
+ export interface OcrWarning {
219
+ readonly code: string;
220
+ readonly message: string;
221
+ }
222
+ export interface OcrResult {
223
+ readonly text: string;
224
+ readonly model: string;
225
+ readonly warnings?: readonly OcrWarning[];
226
+ }
227
+ export interface OcrCaptchaOptions {
228
+ readonly length?: number;
229
+ /** Allowed characters. A RegExp is applied to each character, not to the whole text. */
230
+ readonly charset?: string | RegExp;
231
+ readonly caseSensitive?: boolean;
232
+ readonly maxCandidates?: number;
233
+ }
234
+ export interface OcrCaptchaCandidate {
235
+ readonly text: string;
236
+ readonly satisfiesConstraints: boolean;
237
+ }
238
+ export interface OcrCaptchaResult {
239
+ readonly text: string;
240
+ readonly candidates: readonly OcrCaptchaCandidate[];
241
+ readonly satisfiesConstraints: boolean;
242
+ readonly model: string;
243
+ }
244
+ export interface OcrContext {
245
+ recognize(request: OcrRecognizeRequest): Promise<OcrResult>;
246
+ extractCaptchaText(image: OcrImageInput, options?: OcrCaptchaOptions): Promise<OcrCaptchaResult>;
247
+ }
196
248
  export type SttTranscribeMode = "general" | "otp";
197
249
  export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
198
250
  export type SttUnsupportedOptionPolicy = "warn" | "error";
@@ -200,6 +252,106 @@ export type ProviderSttMode = "optional" | "required";
200
252
  export interface ProviderSttConfig {
201
253
  mode: ProviderSttMode;
202
254
  }
255
+ /**
256
+ * Union order is documentation only.
257
+ *
258
+ * The SDK owns the default hosted-vendor fallback policy and derives the chain
259
+ * from each provider's declared challenge kinds. Hosted solvers are preferred
260
+ * with `capsolver` ahead of `2captcha` in that policy.
261
+ *
262
+ * `browser` is the in-house CDP pool and remains opt-in; it is excluded from the
263
+ * default chain. `custom` is likewise reserved for provider-specific configuration.
264
+ *
265
+ * `ProviderResolverConfig.vendors` overrides the SDK policy when declared.
266
+ */
267
+ export type ProviderResolverVendor = "browser" | "capsolver" | "capmonster" | "2captcha" | "custom";
268
+ /**
269
+ * Token-family kinds resolve to `{ form: "token" }`. Cookie-family kinds resolve
270
+ * to `{ form: "cookies" }`; network-identity binding is defined per kind. `aws_waf`
271
+ * was measured portable across residential leases on buyee, while `cf_clearance`
272
+ * remains unmeasured here and is treated as identity-scoped because it is widely
273
+ * described as IP-bound.
274
+ */
275
+ export type ProviderChallenge = {
276
+ readonly kind: "turnstile";
277
+ readonly siteKey: string;
278
+ readonly pageUrl: string;
279
+ readonly action?: string;
280
+ readonly cdata?: string;
281
+ } | {
282
+ readonly kind: "recaptcha_v2";
283
+ readonly siteKey: string;
284
+ readonly pageUrl: string;
285
+ } | {
286
+ readonly kind: "recaptcha_v3";
287
+ readonly siteKey: string;
288
+ readonly pageUrl: string;
289
+ readonly action: string;
290
+ readonly minScore?: number;
291
+ } | {
292
+ readonly kind: "hcaptcha";
293
+ readonly siteKey: string;
294
+ readonly pageUrl: string;
295
+ } | {
296
+ readonly kind: "cloudflare_interstitial";
297
+ readonly pageUrl: string;
298
+ readonly blockedHtml?: string;
299
+ } | {
300
+ readonly kind: "aws_waf";
301
+ readonly pageUrl: string;
302
+ /** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
303
+ readonly siteKey?: string;
304
+ readonly captchaScript?: string;
305
+ readonly context?: string;
306
+ readonly iv?: string;
307
+ } | {
308
+ readonly kind: "akamai_sec_cpt";
309
+ readonly pageUrl: string;
310
+ /** The admitted challenge document, needed for tile/context extraction. */
311
+ readonly challengeHtml?: string;
312
+ } | {
313
+ readonly kind: "akamai_sensor";
314
+ readonly pageUrl: string;
315
+ /** Upstream sensor script URL the payload must be POSTed to. */
316
+ readonly scriptUrl: string;
317
+ /** Current `_abck` cookie value, rotates each round. */
318
+ readonly abck?: string;
319
+ /** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
320
+ readonly bmsz?: string;
321
+ /** Bot Manager major version when known ("3" measured on zozo.jp). */
322
+ readonly version?: string;
323
+ };
324
+ export type ProviderChallengeKind = ProviderChallenge["kind"];
325
+ /**
326
+ * Token solutions carry no network-identity binding. Cookie-solution binding is
327
+ * per challenge kind: `aws_waf` was measured portable across residential leases
328
+ * on buyee, while `cf_clearance` is unmeasured here and treated as scoped to the
329
+ * identity that produced it. The provider attaches the returned cookies to its
330
+ * own requests.
331
+ */
332
+ export type ChallengeSolution = {
333
+ readonly form: "token";
334
+ readonly token: string;
335
+ } | {
336
+ readonly form: "cookies";
337
+ readonly cookies: Readonly<Record<string, string>>;
338
+ readonly userAgent: string;
339
+ /** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
340
+ readonly expires?: number;
341
+ };
342
+ export interface ProviderResolverConfig {
343
+ /** Optional ordered override for the SDK-owned vendor fallback chain. */
344
+ readonly vendors?: readonly ProviderResolverVendor[];
345
+ /** Challenge kinds this provider is permitted to request. */
346
+ readonly kinds: readonly ProviderChallengeKind[];
347
+ /**
348
+ * Client fingerprint profile the SDK must use when reaching this upstream.
349
+ * Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
350
+ * challenge is served, while a Safari profile is admitted. Provider-declared
351
+ * because only the provider knows its upstream's admission rule.
352
+ */
353
+ readonly clientProfile?: string;
354
+ }
203
355
  export type SttAudioInput = {
204
356
  kind: "base64";
205
357
  data: string;
@@ -264,6 +416,9 @@ export interface SttContext {
264
416
  transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
265
417
  extractVerificationCode(text: string, options?: SttVerificationCodeOptions): VerificationCodeExtractionResult;
266
418
  }
419
+ export interface ResolverContext {
420
+ solve(challenge: ProviderChallenge, signal?: AbortSignal): Promise<ChallengeSolution>;
421
+ }
267
422
  export interface HealthJourneySchedule {
268
423
  kind: "interval";
269
424
  /** ISO 8601 duration, for example PT8H. */
@@ -395,7 +550,7 @@ export interface HealthJourneyRunResult {
395
550
  label?: string;
396
551
  metadata?: Record<string, unknown>;
397
552
  }
398
- export interface HealthJourneyDefinition {
553
+ interface HealthJourneyDefinitionBase {
399
554
  id: string;
400
555
  title?: string;
401
556
  description?: string;
@@ -407,8 +562,14 @@ export interface HealthJourneyDefinition {
407
562
  requiredSecrets?: readonly string[];
408
563
  manualTrigger?: HealthJourneyManualTriggerPolicy;
409
564
  steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
410
- run?: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
411
565
  }
566
+ export type HealthJourneyDefinition = HealthJourneyDefinitionBase & ({
567
+ run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
568
+ scenario?: never;
569
+ } | {
570
+ scenario: HealthScenario;
571
+ run?: never;
572
+ });
412
573
  /**
413
574
  * Health-check authoring surface owned by `@apifuse/provider-sdk`.
414
575
  *
@@ -479,13 +640,22 @@ export interface HealthCheckCaseResult {
479
640
  * so authors get IntelliSense and compile-time errors when accessing fields
480
641
  * that do not exist on the operation's declared output schema.
481
642
  */
482
- export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
643
+ export type HealthCheckCase<TInput = unknown, TOutput = unknown> = {
483
644
  /** Human-readable case name; unique within the suite. */
484
645
  name: string;
485
646
  /** Optional longer description shown on ops dashboards. */
486
647
  description?: string;
487
648
  /** Input passed to the operation handler for this case. */
488
649
  input: TInput;
650
+ /** Override per-case degradation threshold (ms); falls back to the suite default. */
651
+ degradedThresholdMs?: number;
652
+ /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
653
+ timeoutMs?: number;
654
+ /** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
655
+ expectedStatus?: "ok" | "degraded";
656
+ /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
657
+ enabled?: () => boolean;
658
+ } & ({
489
659
  /**
490
660
  * Optional runtime input preparation hook for volatile probes. Use this when
491
661
  * the durable probe input must be derived from a live read-only operation
@@ -503,15 +673,14 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
503
673
  * + lambda only.
504
674
  */
505
675
  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
- }
676
+ /** Declarative scenarios replace the imperative preparation and assertion hooks. */
677
+ scenario?: never;
678
+ } | {
679
+ /** Declarative scenario executed by the health-monitor runtime. */
680
+ scenario: HealthScenario;
681
+ prepareInput?: never;
682
+ assertions?: never;
683
+ });
515
684
  /**
516
685
  * Operation-level health-check suite. At least one case is required when
517
686
  * present. All cases share the suite's interval and default timeout.
@@ -609,9 +778,11 @@ export interface HealthMonitorProbeOverride {
609
778
  /** Optional degraded threshold override for generated registry probes. */
610
779
  degradedThresholdMs?: number;
611
780
  }
781
+ export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
782
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
612
783
  export interface OperationErrorCode {
613
784
  code: string;
614
- status?: number;
785
+ status?: ProviderErrorStatus;
615
786
  description: string;
616
787
  retryable?: boolean;
617
788
  }
@@ -645,12 +816,32 @@ export interface StealthProfile {
645
816
  h2Settings?: Record<string, unknown>;
646
817
  headerOrder?: string[];
647
818
  }
648
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
819
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
649
820
  export type ConnectionMode = AuthMode;
650
821
  export type ProviderReviewed = "first-party" | "community" | "staging";
651
822
  export type ProviderAccessVisibility = "public" | "early_access";
652
823
  export type ProviderProxyMode = "disabled" | "optional" | "required";
653
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
824
+ /**
825
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
826
+ * (a common mistake because the names collide with a well-known rebrand):
827
+ *
828
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
829
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
830
+ * endpoints). This is our own vendor. It is NOT the company formerly named
831
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
832
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
833
+ * credentials; geo/session encoded in the username, no allocation API.
834
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
835
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
836
+ * username params. A different company from `smartproxy` above.
837
+ * **@deprecated** — unused; no managed adapter. Declare a
838
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
839
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
840
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
841
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
842
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
843
+ */
844
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
654
845
  export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
655
846
  export interface ProviderProxyPolicy {
656
847
  /**
@@ -658,7 +849,18 @@ export interface ProviderProxyPolicy {
658
849
  * certificate verification, and vendor allocator endpoints are SDK-owned.
659
850
  */
660
851
  mode: ProviderProxyMode;
852
+ /**
853
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
854
+ * chain. A single-element `providers` list is equivalent to this field.
855
+ */
661
856
  provider?: ProviderProxyProvider;
857
+ /**
858
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
859
+ * fails over to the next when a vendor lacks credentials or its allocation /
860
+ * transport is exhausted. When omitted, `provider` (or the platform default)
861
+ * is used as a single-vendor chain.
862
+ */
863
+ providers?: ProviderProxyProvider[];
662
864
  geo?: {
663
865
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
664
866
  country?: Iso3166Alpha2CountryCode;
@@ -669,6 +871,12 @@ export interface ProviderProxyPolicy {
669
871
  affinity?: ProviderProxySessionAffinity;
670
872
  lifetimeMinutes?: number;
671
873
  poolSize?: number;
874
+ /**
875
+ * Seconds before hard sticky expiry at which native connections receive
876
+ * the `expiring` event so the provider can drain and reconnect cleanly.
877
+ * Declared by the provider; the SDK does not assume a default cut point.
878
+ */
879
+ drainLeadSeconds?: number;
672
880
  };
673
881
  }
674
882
  export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
@@ -677,9 +885,9 @@ export interface ProviderAccessConfig {
677
885
  * Provider-level rollout visibility.
678
886
  *
679
887
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
680
- * the existing provider policy stack.
888
+ * the existing provider policy stack.
681
889
  * - `early_access`: hidden from public discovery and callable only when the
682
- * active customer organization has a provider-level access grant.
890
+ * active customer organization has a provider-level access grant.
683
891
  *
684
892
  * This is intentionally provider-level only. It does not alter auth mode,
685
893
  * operation schemas, health-check authoring, `openWorld`, or Connection
@@ -810,6 +1018,11 @@ export interface HttpRetrySummary {
810
1018
  export interface RequestOptions {
811
1019
  headers?: Record<string, string>;
812
1020
  params?: RequestParams;
1021
+ /**
1022
+ * Query parameters whose values contain credentials or other secret material.
1023
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1024
+ */
1025
+ sensitiveParams?: Record<string, string>;
813
1026
  proxy?: string;
814
1027
  timeout?: number;
815
1028
  /**
@@ -818,12 +1031,33 @@ export interface RequestOptions {
818
1031
  */
819
1032
  throwOnHttpError?: boolean;
820
1033
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1034
+ /**
1035
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1036
+ * evaluated before the next request is issued. Existing callers that omit
1037
+ * this policy retain the native fetch redirect behavior.
1038
+ */
1039
+ redirectPolicy?: HttpRedirectPolicy;
821
1040
  }
1041
+ export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1042
+ export type HttpRedirectPolicyMode = "same-origin";
1043
+ export interface HttpRedirectPolicy {
1044
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1045
+ mode: HttpRedirectPolicyMode;
1046
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1047
+ maxHops: number;
1048
+ }
1049
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
822
1050
  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 {
1051
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy"> {
824
1052
  method?: HttpMethod;
825
1053
  body?: string | Buffer;
826
1054
  redirect?: "follow" | "manual" | "error";
1055
+ /**
1056
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1057
+ * transport aborts the response and throws `response_too_large` if the
1058
+ * declared or streamed body exceeds this limit.
1059
+ */
1060
+ maxBodyBytes?: number;
827
1061
  /**
828
1062
  * Offsets policy-managed proxy pool selection for caller-managed retries.
829
1063
  * Use when a request receives an upstream challenge page rather than a
@@ -843,17 +1077,42 @@ export interface StealthFetchOptions extends RequestOptions {
843
1077
  };
844
1078
  }
845
1079
  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;
1080
+ /** URL-less reads use the jar's response URL or session base URL. */
1081
+ get(name: string, url?: string): string | undefined;
1082
+ getAll(url?: string): Record<string, string>;
1083
+ toString(url?: string): string;
1084
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
850
1085
  }
1086
+ /**
1087
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1088
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1089
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1090
+ */
1091
+ export interface StealthCookieStoreV1 {
1092
+ readonly version: 1;
1093
+ readonly jar: SerializedCookieJar;
1094
+ }
1095
+ /** Cookie persistence formats understood by this SDK version. */
1096
+ export type StealthCookieStore = StealthCookieStoreV1;
851
1097
  export interface StealthSessionCookies extends CookieJar {
852
- has(name: string): boolean;
853
- setFromCookieStrings(cookieStrings: readonly string[]): void;
854
- toHeader(): string;
1098
+ has(name: string, url?: string): boolean;
1099
+ /** URL-less writes are scoped to the session base URL. */
1100
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1101
+ toHeader(url?: string): string;
1102
+ /**
1103
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1104
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1105
+ */
855
1106
  snapshot(): Record<string, string>;
1107
+ /**
1108
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1109
+ * @deprecated Use deserialize() with state produced by serialize().
1110
+ */
856
1111
  restore(cookies: Record<string, string>): void;
1112
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1113
+ serialize(): StealthCookieStoreV1;
1114
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1115
+ deserialize(state: StealthCookieStore): void;
857
1116
  clear(): void;
858
1117
  }
859
1118
  export interface DeclarativeStealthResponse {
@@ -895,8 +1154,14 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
895
1154
  export interface StealthRedirectRunResult {
896
1155
  final: StealthResponse;
897
1156
  hops: StealthRedirectHop[];
898
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1157
+ reason: RedirectRunReason;
1158
+ /**
1159
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1160
+ * @deprecated Use cookieStore for lossless persistence.
1161
+ */
899
1162
  cookies: Record<string, string>;
1163
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1164
+ cookieStore: StealthCookieStoreV1;
900
1165
  }
901
1166
  export interface StealthSession {
902
1167
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
@@ -959,11 +1224,157 @@ export interface HttpClient {
959
1224
  stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
960
1225
  sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
961
1226
  }
1227
+ /** Request-scoped file reference accepted by provider operation inputs. */
1228
+ export interface ProviderFileRef {
1229
+ readonly type: "request_file";
1230
+ readonly id: string;
1231
+ readonly filename: string;
1232
+ readonly mime_type?: string;
1233
+ readonly size: number;
1234
+ readonly sha256?: string;
1235
+ }
1236
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1237
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1238
+ readonly mimeType?: string;
1239
+ arrayBuffer(): Promise<ArrayBuffer>;
1240
+ bytes(): Promise<Uint8Array>;
1241
+ stream(): ReadableStream<Uint8Array>;
1242
+ };
1243
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1244
+ export interface ProviderFilesContext {
1245
+ has(input: string | ProviderFileRef): boolean;
1246
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1247
+ }
1248
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1249
+ export interface NativeTcpPortRange {
1250
+ readonly start: number;
1251
+ readonly end: number;
1252
+ }
1253
+ /** Static native TCP egress declared by a provider. */
1254
+ export interface NativeTcpEgressRule {
1255
+ readonly host: string;
1256
+ readonly ports: readonly number[];
1257
+ readonly tls: NativeTcpTlsMode;
1258
+ }
1259
+ /**
1260
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1261
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1262
+ * Dynamic rules must declare at least one target host selector through
1263
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1264
+ * sources and targets match only same-family selectors (except exact
1265
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1266
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1267
+ *
1268
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1269
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1270
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1271
+ * Every rule must declare a source host selector, source port list/range, and
1272
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1273
+ */
1274
+ export interface NativeTcpDynamicEgressRule {
1275
+ readonly sourceHost?: string;
1276
+ readonly sourceHostSuffixes?: readonly string[];
1277
+ readonly sourceIpv4Cidrs?: readonly string[];
1278
+ readonly sourceIpv6Cidrs?: readonly string[];
1279
+ readonly sourcePorts?: readonly number[];
1280
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1281
+ readonly targetHostSuffixes?: readonly string[];
1282
+ readonly targetIpv4Cidrs?: readonly string[];
1283
+ readonly targetIpv6Cidrs?: readonly string[];
1284
+ readonly targetPorts?: readonly number[];
1285
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1286
+ readonly tls: NativeTcpTlsMode;
1287
+ readonly ttlMs?: number;
1288
+ readonly maxGrants?: number;
1289
+ }
1290
+ /** Common TCP/TLS connection input supported by the native runtime. */
1291
+ export interface NativeNetworkConnectInput {
1292
+ readonly host: string;
1293
+ readonly port: number;
1294
+ readonly serverName?: string;
1295
+ readonly rejectUnauthorized?: boolean;
1296
+ /**
1297
+ * Maximum time without a successful socket read before the connection is
1298
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1299
+ */
1300
+ readonly idleTimeoutMs?: number;
1301
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1302
+ readonly timeoutMs?: number;
1303
+ readonly signal?: AbortSignal;
1304
+ /** Overrides the credential-derived sticky affinity key. */
1305
+ readonly affinityKey?: string;
1306
+ }
1307
+ export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
1308
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1309
+ export interface NativeNetworkDynamicGrantOptions {
1310
+ readonly sourceHost: string;
1311
+ readonly sourcePort: number;
1312
+ readonly host: string;
1313
+ readonly port: number;
1314
+ readonly tls: NativeTcpTlsMode;
1315
+ readonly ttlMs?: number;
1316
+ }
1317
+ export interface NativeNetworkEgressGrant {
1318
+ revoke(): void;
1319
+ }
1320
+ /** Consumer-facing alias used by native TCP providers. */
1321
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1322
+ /** Resolved egress identity for a native connection routed through a proxy. */
1323
+ export interface NativeProxyEgressInfo {
1324
+ readonly vendor: ProviderProxyProvider;
1325
+ readonly sticky: boolean;
1326
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1327
+ readonly sessionId?: string;
1328
+ /** Hard expiry of the sticky binding, ISO 8601. */
1329
+ readonly expiresAt?: string;
1330
+ }
1331
+ export type NativeProxyExpiringReason = "sticky_expiry";
1332
+ export interface NativeProxyExpiringEvent {
1333
+ readonly expiresAt: string;
1334
+ readonly leadSeconds: number;
1335
+ readonly reason: NativeProxyExpiringReason;
1336
+ }
1337
+ /**
1338
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1339
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1340
+ */
1341
+ export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
1342
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1343
+ export interface NativeNetworkCloseReason {
1344
+ readonly code: string;
1345
+ readonly message: string;
1346
+ }
1347
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1348
+ export interface NativeNetworkConnection {
1349
+ /** Present when the connection was routed through a proxy. */
1350
+ readonly proxy?: NativeProxyEgressInfo;
1351
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1352
+ readonly closeReason?: NativeNetworkCloseReason;
1353
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1354
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1355
+ read(): Promise<Uint8Array | null>;
1356
+ write(data: Uint8Array): Promise<void>;
1357
+ close(): Promise<void>;
1358
+ }
1359
+ export interface NativeNetworkClient {
1360
+ connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
1361
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1362
+ grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
1363
+ }
1364
+ export interface NativeContext {
1365
+ readonly network: NativeNetworkClient;
1366
+ }
1367
+ export interface NativeProviderConfig {
1368
+ readonly network?: {
1369
+ readonly tcp?: readonly NativeTcpEgressRule[];
1370
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1371
+ };
1372
+ }
962
1373
  export interface ProviderCacheKeyOptions {
963
1374
  /**
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.
1375
+ * Additional field names whose values are hashed in stable key material. The
1376
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1377
+ * authorization, cookie, token, password, and secret.
967
1378
  */
968
1379
  redactFields?: string[];
969
1380
  }
@@ -1036,7 +1447,18 @@ export interface BrowserFrame {
1036
1447
  evaluate<T>(fn: string | (() => T)): Promise<T>;
1037
1448
  locator(selector: string): BrowserLocator;
1038
1449
  }
1039
- export type BrowserResourceMethod = "GET" | "HEAD";
1450
+ export interface BrowserCookie {
1451
+ readonly name: string;
1452
+ readonly value: string;
1453
+ readonly domain: string;
1454
+ readonly path: string;
1455
+ /** Unix seconds. Absent for a session cookie. */
1456
+ readonly expires?: number;
1457
+ readonly httpOnly: boolean;
1458
+ readonly secure: boolean;
1459
+ readonly sameSite?: "Strict" | "Lax" | "None";
1460
+ }
1461
+ export type BrowserResourceMethod = "GET" | "HEAD" | "POST";
1040
1462
  export type BrowserResourceRequest = {
1041
1463
  readonly url: string;
1042
1464
  readonly method: BrowserResourceMethod;
@@ -1045,6 +1467,8 @@ export type BrowserResourceRequest = {
1045
1467
  };
1046
1468
  export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1047
1469
  export type BrowserResourceDecision = {
1470
+ readonly action: "continue";
1471
+ } | {
1048
1472
  readonly action: "fulfill";
1049
1473
  readonly status?: number;
1050
1474
  readonly headers?: Readonly<Record<string, string>>;
@@ -1060,12 +1484,29 @@ export type BrowserResourceRoute = {
1060
1484
  export type BrowserResourcePolicy = {
1061
1485
  readonly defaultAction?: "block";
1062
1486
  readonly allowedMethods?: readonly BrowserResourceMethod[];
1487
+ /**
1488
+ * Appends an enforcing CSP header to every renderable document response
1489
+ * while the policy is active. Existing CSP headers are retained, so this
1490
+ * can only further restrict the document.
1491
+ */
1492
+ readonly documentContentSecurityPolicy?: string;
1063
1493
  readonly routes: readonly BrowserResourceRoute[];
1064
1494
  };
1065
1495
  export interface BrowserPage extends BrowserFrame {
1066
1496
  close(): Promise<void>;
1497
+ /** Returns the user agent used by this page's browser context. */
1498
+ userAgent(): Promise<string>;
1499
+ /**
1500
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1501
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1502
+ */
1503
+ cookies(): Promise<readonly BrowserCookie[]>;
1067
1504
  fill(selector: string, text: string): Promise<void>;
1068
1505
  goto(url: string): Promise<void>;
1506
+ goto(url: string, options?: {
1507
+ readonly timeout?: number;
1508
+ readonly waitUntil?: "load" | "domcontentloaded";
1509
+ }): Promise<void>;
1069
1510
  pageId?: string;
1070
1511
  screenshot(options?: {
1071
1512
  fullPage?: boolean;
@@ -1138,6 +1579,26 @@ export interface ProviderChoiceBindingOptions {
1138
1579
  connection?: boolean;
1139
1580
  credentialKeys?: readonly string[];
1140
1581
  }
1582
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1583
+ export type ProviderChoiceConsumeResult = {
1584
+ readonly status: "consumed";
1585
+ } | {
1586
+ readonly status: "already-consumed";
1587
+ } | {
1588
+ readonly status: "unsupported";
1589
+ };
1590
+ export type ProviderChoiceExplicitParseResult = {
1591
+ readonly status: "active";
1592
+ readonly payload: Record<string, unknown>;
1593
+ /** Stable, opaque key for provider-owned idempotency records. */
1594
+ readonly replayKey: string;
1595
+ /** Atomically claims a word token. Inline tokens report unsupported. */
1596
+ consume(): Promise<ProviderChoiceConsumeResult>;
1597
+ } | {
1598
+ readonly status: "consumed";
1599
+ /** Use this key to read the provider-owned result before returning an error. */
1600
+ readonly replayKey: string;
1601
+ };
1141
1602
  export type ProviderChoiceStorageOptions = {
1142
1603
  readonly mode: "inline";
1143
1604
  } | {
@@ -1165,6 +1626,8 @@ export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unkn
1165
1626
  ttlMs: number;
1166
1627
  nowMs?: number;
1167
1628
  bind?: ProviderChoiceBindingOptions;
1629
+ /** Server storage only: standard emits four words; high emits five. */
1630
+ strength?: "standard" | "high";
1168
1631
  storage?: ProviderChoiceStorageOptions;
1169
1632
  }
1170
1633
  export interface ProviderChoiceParseOptions {
@@ -1176,6 +1639,8 @@ export interface ProviderChoiceParseOptions {
1176
1639
  futureToleranceMs?: number;
1177
1640
  bind?: ProviderChoiceBindingOptions;
1178
1641
  storage?: ProviderChoiceStorageOptions;
1642
+ /** Defaults to never, preserving reusable choice-token parse semantics. */
1643
+ consume?: ProviderChoiceConsumeMode;
1179
1644
  }
1180
1645
  export interface ProviderChoiceContext {
1181
1646
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
@@ -1194,6 +1659,9 @@ export interface ProviderChoiceContext {
1194
1659
  }>;
1195
1660
  }): string | Promise<string>;
1196
1661
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1662
+ parse(options: ProviderChoiceParseOptions & {
1663
+ readonly consume: "explicit";
1664
+ }): Promise<ProviderChoiceExplicitParseResult>;
1197
1665
  parse(options: ProviderChoiceParseOptions & {
1198
1666
  readonly storage?: {
1199
1667
  readonly mode: "inline";
@@ -1209,7 +1677,7 @@ export interface ProviderChoiceContext {
1209
1677
  readonly mode: "auto";
1210
1678
  }>;
1211
1679
  }): Record<string, unknown> | Promise<Record<string, unknown>>;
1212
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1680
+ parse(options: ProviderChoiceParseOptions): Record<string, unknown> | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1213
1681
  }
1214
1682
  export interface ContextScratchpad {
1215
1683
  get(key: string): unknown;
@@ -1285,16 +1753,34 @@ export interface AuthFlowTerminalContext {
1285
1753
  }): AuthTurn;
1286
1754
  }
1287
1755
  export interface FlowContext {
1756
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
1757
+ flowId?: string;
1288
1758
  connectionId?: string;
1289
1759
  externalRef?: string;
1290
1760
  tenantId: string;
1291
1761
  providerId: string;
1292
1762
  http: HttpClient;
1763
+ /** Durable connection-scoped runtime state. Present when the host runtime
1764
+ * supplies one; auth ceremonies must fail closed when absent rather than
1765
+ * fall back to bypassable in-process storage.
1766
+ *
1767
+ * Scoped via `ProviderRuntimeState.forConnection`: requests that resolve no
1768
+ * connection id (pre-connection ceremonies such as first-time logins) share
1769
+ * the documented isolated missing-connection scope. That sharing is the
1770
+ * intended semantic — it lets counters keyed by caller identity (e.g. a
1771
+ * login email) persist across separate ceremonies for the same caller.
1772
+ * Flows storing entries in that scope MUST key them by caller identity;
1773
+ * un-keyed entries would be shared across all connectionless ceremonies. */
1774
+ readonly state?: ProviderRuntimeState;
1775
+ /** Present when the selected runtime supplies native network capabilities. */
1776
+ readonly native?: NativeContext;
1293
1777
  stealth: StealthClient;
1294
1778
  env: EnvContext;
1295
1779
  credential?: CredentialContext;
1296
1780
  context: ContextScratchpad;
1781
+ ocr: OcrContext;
1297
1782
  stt: SttContext;
1783
+ resolver: ResolverContext;
1298
1784
  auth: AuthFlowTerminalContext;
1299
1785
  }
1300
1786
  export interface AuthTurn {
@@ -1326,7 +1812,13 @@ export interface AuthFlowDefinition {
1326
1812
  refresh?: AuthFlowInputHandler;
1327
1813
  }
1328
1814
  export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1815
+ export type StateNamespaceScope = "connection" | "provider";
1329
1816
  export interface StateNamespaceOptions {
1817
+ /**
1818
+ * State isolation boundary. Connection scope is the default; provider scope
1819
+ * must be selected explicitly for provider-wide coordination state.
1820
+ */
1821
+ scope?: StateNamespaceScope;
1330
1822
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1331
1823
  defaultTtl: ProviderStateDurationString;
1332
1824
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1368,6 +1860,11 @@ export interface ProviderStateNamespace {
1368
1860
  increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1369
1861
  }
1370
1862
  export interface ProviderRuntimeState {
1863
+ /**
1864
+ * Returns an immutable view bound to one request connection. An unresolved
1865
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
1866
+ */
1867
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1371
1868
  namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1372
1869
  }
1373
1870
  export interface ProviderContext {
@@ -1375,17 +1872,41 @@ export interface ProviderContext {
1375
1872
  credential: CredentialContext;
1376
1873
  request?: ProviderRequestContext;
1377
1874
  http: HttpClient;
1875
+ /** Present for requests carrying runtime-resolvable file references. */
1876
+ readonly files?: ProviderFilesContext;
1877
+ /** Native network capability selected by declaration-derived contexts. */
1878
+ readonly native: NativeContext;
1378
1879
  cache: ProviderCache;
1379
1880
  state: ProviderRuntimeState;
1380
1881
  stealth: StealthClient;
1381
1882
  browser: BrowserClient;
1382
1883
  trace: TraceContext;
1383
1884
  auth: AuthContext;
1885
+ ocr: OcrContext;
1384
1886
  stt: SttContext;
1887
+ resolver: ResolverContext;
1385
1888
  choice: ProviderChoiceContext;
1386
1889
  }
1890
+ /**
1891
+ * The operation context exposed for one provider declaration. Capability
1892
+ * bindings are present only when their corresponding declaration is present;
1893
+ * trace and request remain ambient runtime bindings.
1894
+ */
1895
+ export type ProviderContextFor<TConfig> = Pick<ProviderContext, "trace" | "request"> & ("env" extends keyof TConfig ? Pick<ProviderContext, "env"> : Record<never, never>) & ("credential" extends keyof TConfig ? Pick<ProviderContext, "credential"> : Record<never, never>) & ("http" extends keyof TConfig ? Pick<ProviderContext, "http"> : Record<never, never>) & ("files" extends keyof TConfig ? Pick<ProviderContext, "files"> : Record<never, never>) & ("native" extends keyof TConfig ? Pick<ProviderContext, "native"> : Record<never, never>) & ("cache" extends keyof TConfig ? Pick<ProviderContext, "cache"> : Record<never, never>) & ("state" extends keyof TConfig ? Pick<ProviderContext, "state"> : Record<never, never>) & ("stealth" extends keyof TConfig ? Pick<ProviderContext, "stealth"> : Record<never, never>) & ("browser" extends keyof TConfig ? Pick<ProviderContext, "browser"> : Record<never, never>) & ("auth" extends keyof TConfig ? Pick<ProviderContext, "auth"> : Record<never, never>) & ("ocr" extends keyof TConfig ? Pick<ProviderContext, "ocr"> : Record<never, never>) & ("stt" extends keyof TConfig ? Pick<ProviderContext, "stt"> : Record<never, never>) & ("resolver" extends keyof TConfig ? Pick<ProviderContext, "resolver"> : Record<never, never>) & ("choice" extends keyof TConfig ? Pick<ProviderContext, "choice"> : Record<never, never>);
1896
+ export interface ProxiedOAuthConfig {
1897
+ authorizeUrl: string;
1898
+ tokenUrl: string;
1899
+ customScheme: string;
1900
+ rewriteProfile: string;
1901
+ clientIdEnvKey: string;
1902
+ pkce?: "S256" | "none";
1903
+ authorizeParams?: Record<string, string>;
1904
+ tokenParams?: Record<string, string>;
1905
+ }
1387
1906
  export interface AuthConfig {
1388
1907
  mode: AuthMode;
1908
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
1909
+ proxied?: ProxiedOAuthConfig;
1389
1910
  flow?: AuthFlowDefinition;
1390
1911
  }
1391
1912
  export interface ProviderSecretDeclaration {
@@ -1417,7 +1938,7 @@ export interface OperationContractMetadata {
1417
1938
  lifecycle?: OperationLifecycle;
1418
1939
  deprecation?: OperationDeprecationMetadata;
1419
1940
  }
1420
- export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
1941
+ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike, TContext = ProviderContext> {
1421
1942
  /**
1422
1943
  * Short English display title for the operation. The SDK passes it through
1423
1944
  * verbatim; the APIFuse registry derives the operation's en locale title
@@ -1447,10 +1968,15 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
1447
1968
  retryOnAuthRefresh?: boolean;
1448
1969
  input: TInput;
1449
1970
  output: TOutput;
1450
- handler(ctx: ProviderContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1971
+ handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1451
1972
  fixtures?: {
1452
1973
  request: InferSchemaOutput<TInput>;
1453
1974
  response: InferSchemaOutput<TOutput>;
1975
+ /**
1976
+ * KST calendar date when `response` evidence was captured. Date fields in
1977
+ * the response align with this date, not a resolved relative request date.
1978
+ */
1979
+ recordedAt?: string;
1454
1980
  };
1455
1981
  upstream?: {
1456
1982
  baseUrl?: string;
@@ -1509,12 +2035,15 @@ export interface ProviderDefinition {
1509
2035
  */
1510
2036
  deployment?: ProviderDeploymentOverrides;
1511
2037
  allowedHosts?: string[];
2038
+ native?: NativeProviderConfig;
1512
2039
  stealth?: {
1513
2040
  profile: string;
1514
2041
  platform: StealthPlatform;
1515
2042
  };
1516
2043
  proxy?: ProviderProxyConfig;
2044
+ ocr?: ProviderOcrConfig;
1517
2045
  stt?: ProviderSttConfig;
2046
+ resolver?: ProviderResolverConfig;
1518
2047
  browser?: {
1519
2048
  engine: BrowserEngine;
1520
2049
  };
@@ -1531,3 +2060,4 @@ export interface ProviderDefinition {
1531
2060
  healthProbe?: ProviderHealthProbeConfig;
1532
2061
  healthJourneys?: readonly HealthJourneyDefinition[];
1533
2062
  }
2063
+ export {};