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

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 (303) hide show
  1. package/AUTHORING.md +501 -13
  2. package/CHANGELOG.md +165 -1
  3. package/README.md +72 -14
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +88 -4
  6. package/bin/apifuse-dev.ts +38 -5
  7. package/bin/apifuse-pack-check.ts +22 -2
  8. package/bin/apifuse-pack-smoke.ts +57 -2
  9. package/bin/apifuse-pack-types.ts +356 -38
  10. package/bin/apifuse-perf.ts +14 -13
  11. package/bin/apifuse-record.ts +691 -68
  12. package/bin/apifuse-submit-check.ts +518 -37
  13. package/bin/apifuse-sync-assets.ts +117 -0
  14. package/bin/submit-check-delimited-text.ts +50 -0
  15. package/dist/auth-turn/index.d.ts +3 -3
  16. package/dist/auth-turn/index.js +1 -1
  17. package/dist/auth.d.ts +14 -0
  18. package/dist/auth.js +67 -0
  19. package/dist/ceremonies/index.d.ts +16 -0
  20. package/dist/ceremonies/index.js +141 -36
  21. package/dist/cli/commands.d.ts +1 -1
  22. package/dist/cli/commands.js +8 -0
  23. package/dist/cli/create.d.ts +3 -0
  24. package/dist/cli/create.js +34 -35
  25. package/dist/cli/prompt-assets.d.ts +80 -0
  26. package/dist/cli/prompt-assets.js +743 -0
  27. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  28. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  29. package/dist/cli/templates/provider/README.md.tpl +4 -4
  30. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  31. package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -1
  32. package/dist/config/loader.d.ts +177 -16
  33. package/dist/config/loader.js +424 -127
  34. package/dist/contract-serialization.js +4 -8
  35. package/dist/contract-types.d.ts +1 -0
  36. package/dist/contract.js +2 -0
  37. package/dist/declaration-validation.d.ts +32 -0
  38. package/dist/declaration-validation.js +207 -0
  39. package/dist/define.d.ts +51 -25
  40. package/dist/define.js +752 -38
  41. package/dist/error-resolution.d.ts +4 -0
  42. package/dist/error-resolution.js +122 -0
  43. package/dist/errors.d.ts +18 -0
  44. package/dist/errors.js +40 -0
  45. package/dist/fixture-sanitization.d.ts +28 -0
  46. package/dist/fixture-sanitization.js +217 -0
  47. package/dist/health-scenario.d.ts +1842 -0
  48. package/dist/health-scenario.js +624 -0
  49. package/dist/index.d.ts +19 -9
  50. package/dist/index.js +10 -6
  51. package/dist/lint.d.ts +6 -1
  52. package/dist/lint.js +362 -3
  53. package/dist/native-address.d.ts +43 -0
  54. package/dist/native-address.js +281 -0
  55. package/dist/native-egress-policy.d.ts +31 -0
  56. package/dist/native-egress-policy.js +288 -0
  57. package/dist/observability.d.ts +5 -2
  58. package/dist/observability.js +48 -1
  59. package/dist/provider.d.ts +8 -2
  60. package/dist/provider.js +3 -1
  61. package/dist/runtime/auth-flow.d.ts +5 -1
  62. package/dist/runtime/auth-flow.js +6 -0
  63. package/dist/runtime/browser.d.ts +1 -0
  64. package/dist/runtime/browser.js +492 -49
  65. package/dist/runtime/cache.d.ts +1 -0
  66. package/dist/runtime/cache.js +169 -15
  67. package/dist/runtime/choice-wordlist.d.ts +9 -0
  68. package/dist/runtime/choice-wordlist.js +138 -0
  69. package/dist/runtime/choice.d.ts +13 -1
  70. package/dist/runtime/choice.js +490 -102
  71. package/dist/runtime/executor.d.ts +2 -2
  72. package/dist/runtime/executor.js +26 -2
  73. package/dist/runtime/http.d.ts +1 -0
  74. package/dist/runtime/http.js +515 -53
  75. package/dist/runtime/instrumentation.d.ts +2 -2
  76. package/dist/runtime/instrumentation.js +366 -8
  77. package/dist/runtime/native-network-errors.d.ts +33 -0
  78. package/dist/runtime/native-network-errors.js +69 -0
  79. package/dist/runtime/native-network.d.ts +96 -0
  80. package/dist/runtime/native-network.js +1232 -0
  81. package/dist/runtime/ocr.d.ts +29 -0
  82. package/dist/runtime/ocr.js +440 -0
  83. package/dist/runtime/proxy-errors.js +6 -2
  84. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  85. package/dist/runtime/proxy-nodemaven.js +146 -0
  86. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  87. package/dist/runtime/proxy-telemetry.js +154 -47
  88. package/dist/runtime/redirects.d.ts +29 -0
  89. package/dist/runtime/redirects.js +36 -0
  90. package/dist/runtime/redis.d.ts +1 -1
  91. package/dist/runtime/redis.js +4 -2
  92. package/dist/runtime/request-options.d.ts +68 -1
  93. package/dist/runtime/request-options.js +548 -0
  94. package/dist/runtime/resolver-config.d.ts +6 -0
  95. package/dist/runtime/resolver-config.js +6 -0
  96. package/dist/runtime/resolver-public.d.ts +1 -0
  97. package/dist/runtime/resolver-public.js +1 -0
  98. package/dist/runtime/resolver-shared.d.ts +3 -0
  99. package/dist/runtime/resolver-shared.js +12 -0
  100. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  101. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  102. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  103. package/dist/runtime/resolver-vendors/browser.js +377 -0
  104. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  105. package/dist/runtime/resolver-vendors/capsolver.js +526 -0
  106. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  107. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  108. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  109. package/dist/runtime/resolver-vendors/twocaptcha.js +407 -0
  110. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  111. package/dist/runtime/resolver-vendors/types.js +96 -0
  112. package/dist/runtime/resolver.d.ts +60 -0
  113. package/dist/runtime/resolver.js +737 -0
  114. package/dist/runtime/secrets.d.ts +27 -0
  115. package/dist/runtime/secrets.js +51 -0
  116. package/dist/runtime/state.d.ts +3 -0
  117. package/dist/runtime/state.js +277 -71
  118. package/dist/runtime/stealth-cookies.d.ts +20 -0
  119. package/dist/runtime/stealth-cookies.js +111 -0
  120. package/dist/runtime/stealth.d.ts +28 -3
  121. package/dist/runtime/stealth.js +519 -255
  122. package/dist/runtime/stt.js +1 -12
  123. package/dist/runtime/timeout.d.ts +5 -0
  124. package/dist/runtime/timeout.js +12 -0
  125. package/dist/runtime/trace-config.d.ts +12 -0
  126. package/dist/runtime/trace-config.js +61 -0
  127. package/dist/serve.d.ts +1 -1
  128. package/dist/serve.js +1 -1
  129. package/dist/server/index.d.ts +5 -3
  130. package/dist/server/index.js +3 -3
  131. package/dist/server/self-test-input-tokens.d.ts +2 -1
  132. package/dist/server/self-test-input-tokens.js +18 -14
  133. package/dist/server/self-test.d.ts +114 -0
  134. package/dist/server/self-test.js +784 -148
  135. package/dist/server/serve-implementation.d.ts +213 -0
  136. package/dist/server/serve-implementation.js +2173 -0
  137. package/dist/server/serve.d.ts +1 -70
  138. package/dist/server/serve.js +1 -1130
  139. package/dist/server/trace-output.d.ts +4 -0
  140. package/dist/server/trace-output.js +20 -0
  141. package/dist/server/types.d.ts +30 -5
  142. package/dist/server/types.js +13 -1
  143. package/dist/stateful/errors.d.ts +19 -0
  144. package/dist/stateful/errors.js +24 -0
  145. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  146. package/dist/stateful/http-provider-event-emitter.js +237 -0
  147. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  148. package/dist/stateful/http-session-owner-registry.js +210 -0
  149. package/dist/stateful/index.d.ts +18 -0
  150. package/dist/stateful/index.js +18 -0
  151. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  152. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  153. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  154. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  155. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  156. package/dist/stateful/provider-event-pipeline.js +1 -0
  157. package/dist/stateful/provider-events.d.ts +101 -0
  158. package/dist/stateful/provider-events.js +289 -0
  159. package/dist/stateful/session-key.d.ts +15 -0
  160. package/dist/stateful/session-key.js +86 -0
  161. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  162. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  163. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  164. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  165. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  166. package/dist/stateful/stateful-provider-adapter.js +287 -0
  167. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  168. package/dist/stateful/stateful-provider-observability.js +161 -0
  169. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  170. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  171. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  172. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  173. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  174. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  175. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  176. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  177. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  178. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  179. package/dist/stateful-signing.d.ts +18 -0
  180. package/dist/stateful-signing.js +27 -0
  181. package/dist/stealth/profiles.js +16 -7
  182. package/dist/stream-evidence.d.ts +74 -0
  183. package/dist/stream-evidence.js +785 -0
  184. package/dist/stream.js +7 -1
  185. package/dist/testing/index.d.ts +2 -1
  186. package/dist/testing/index.js +2 -1
  187. package/dist/testing/run.d.ts +32 -2
  188. package/dist/testing/run.js +489 -21
  189. package/dist/trace-sanitization.d.ts +5 -0
  190. package/dist/trace-sanitization.js +45 -0
  191. package/dist/types.d.ts +545 -23
  192. package/dist/types.js +1 -0
  193. package/package.json +44 -5
  194. package/src/auth-turn/index.ts +1 -1
  195. package/src/auth.ts +118 -0
  196. package/src/ceremonies/index.ts +189 -46
  197. package/src/cli/commands.ts +10 -0
  198. package/src/cli/create.ts +42 -35
  199. package/src/cli/prompt-assets.ts +865 -0
  200. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  201. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  202. package/src/cli/templates/provider/README.md.tpl +4 -4
  203. package/src/cli/templates/provider/index.ts.tpl +6 -3
  204. package/src/cli/templates/provider/operations/ping.ts.tpl +2 -1
  205. package/src/config/loader.ts +665 -163
  206. package/src/contract-serialization.ts +5 -7
  207. package/src/contract-types.ts +1 -0
  208. package/src/contract.ts +2 -0
  209. package/src/declaration-validation.ts +266 -0
  210. package/src/define.ts +970 -87
  211. package/src/error-resolution.ts +127 -0
  212. package/src/errors.ts +52 -0
  213. package/src/fixture-sanitization.ts +248 -0
  214. package/src/health-scenario.ts +875 -0
  215. package/src/index.ts +204 -8
  216. package/src/lint.ts +408 -4
  217. package/src/native-address.ts +340 -0
  218. package/src/native-egress-policy.ts +358 -0
  219. package/src/observability.ts +51 -1
  220. package/src/provider.ts +133 -0
  221. package/src/runtime/auth-flow.ts +12 -0
  222. package/src/runtime/browser.ts +661 -63
  223. package/src/runtime/cache.ts +189 -14
  224. package/src/runtime/choice-wordlist.ts +145 -0
  225. package/src/runtime/choice.ts +631 -120
  226. package/src/runtime/executor.ts +40 -7
  227. package/src/runtime/http.ts +641 -61
  228. package/src/runtime/instrumentation.ts +520 -15
  229. package/src/runtime/native-network-errors.ts +99 -0
  230. package/src/runtime/native-network.ts +1605 -0
  231. package/src/runtime/ocr.ts +523 -0
  232. package/src/runtime/proxy-errors.ts +12 -4
  233. package/src/runtime/proxy-nodemaven.ts +221 -0
  234. package/src/runtime/proxy-telemetry.ts +244 -75
  235. package/src/runtime/redirects.ts +66 -0
  236. package/src/runtime/redis.ts +7 -2
  237. package/src/runtime/request-options.ts +680 -1
  238. package/src/runtime/resolver-config.ts +6 -0
  239. package/src/runtime/resolver-public.ts +20 -0
  240. package/src/runtime/resolver-shared.ts +17 -0
  241. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  242. package/src/runtime/resolver-vendors/browser.ts +533 -0
  243. package/src/runtime/resolver-vendors/capsolver.ts +700 -0
  244. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  245. package/src/runtime/resolver-vendors/twocaptcha.ts +539 -0
  246. package/src/runtime/resolver-vendors/types.ts +212 -0
  247. package/src/runtime/resolver.ts +1103 -0
  248. package/src/runtime/secrets.ts +64 -0
  249. package/src/runtime/state.ts +394 -77
  250. package/src/runtime/stealth-cookies.ts +132 -0
  251. package/src/runtime/stealth.ts +675 -289
  252. package/src/runtime/stt.ts +1 -19
  253. package/src/runtime/timeout.ts +18 -0
  254. package/src/runtime/trace-config.ts +77 -0
  255. package/src/serve.ts +6 -1
  256. package/src/server/index.ts +37 -2
  257. package/src/server/self-test-input-tokens.ts +29 -14
  258. package/src/server/self-test.ts +1025 -175
  259. package/src/server/serve-implementation.ts +3250 -0
  260. package/src/server/serve.ts +1 -1626
  261. package/src/server/trace-output.ts +32 -0
  262. package/src/server/types.ts +13 -1
  263. package/src/stateful/README.md +146 -0
  264. package/src/stateful/errors.ts +35 -0
  265. package/src/stateful/http-provider-event-emitter.ts +314 -0
  266. package/src/stateful/http-session-owner-registry.ts +306 -0
  267. package/src/stateful/index.ts +18 -0
  268. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  269. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  270. package/src/stateful/provider-event-pipeline.ts +61 -0
  271. package/src/stateful/provider-events.ts +462 -0
  272. package/src/stateful/session-key.ts +111 -0
  273. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  274. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  275. package/src/stateful/stateful-provider-adapter.ts +562 -0
  276. package/src/stateful/stateful-provider-observability.ts +261 -0
  277. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  278. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  279. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  280. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  281. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  282. package/src/stateful-signing.ts +46 -0
  283. package/src/stealth/profiles.ts +17 -7
  284. package/src/stream-evidence.ts +988 -0
  285. package/src/stream.ts +8 -1
  286. package/src/testing/index.ts +10 -1
  287. package/src/testing/run.ts +658 -15
  288. package/src/trace-sanitization.ts +63 -0
  289. package/src/types.ts +660 -38
  290. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  291. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  292. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  293. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  294. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  295. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  296. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  297. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  298. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  299. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  300. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  301. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  302. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  303. /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
  *
@@ -609,9 +770,11 @@ export interface HealthMonitorProbeOverride {
609
770
  /** Optional degraded threshold override for generated registry probes. */
610
771
  degradedThresholdMs?: number;
611
772
  }
773
+ export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
774
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
612
775
  export interface OperationErrorCode {
613
776
  code: string;
614
- status?: number;
777
+ status?: ProviderErrorStatus;
615
778
  description: string;
616
779
  retryable?: boolean;
617
780
  }
@@ -645,12 +808,32 @@ export interface StealthProfile {
645
808
  h2Settings?: Record<string, unknown>;
646
809
  headerOrder?: string[];
647
810
  }
648
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
811
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
649
812
  export type ConnectionMode = AuthMode;
650
813
  export type ProviderReviewed = "first-party" | "community" | "staging";
651
814
  export type ProviderAccessVisibility = "public" | "early_access";
652
815
  export type ProviderProxyMode = "disabled" | "optional" | "required";
653
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
816
+ /**
817
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
818
+ * (a common mistake because the names collide with a well-known rebrand):
819
+ *
820
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
821
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
822
+ * endpoints). This is our own vendor. It is NOT the company formerly named
823
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
824
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
825
+ * credentials; geo/session encoded in the username, no allocation API.
826
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
827
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
828
+ * username params. A different company from `smartproxy` above.
829
+ * **@deprecated** — unused; no managed adapter. Declare a
830
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
831
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
832
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
833
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
834
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
835
+ */
836
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
654
837
  export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
655
838
  export interface ProviderProxyPolicy {
656
839
  /**
@@ -658,7 +841,18 @@ export interface ProviderProxyPolicy {
658
841
  * certificate verification, and vendor allocator endpoints are SDK-owned.
659
842
  */
660
843
  mode: ProviderProxyMode;
844
+ /**
845
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
846
+ * chain. A single-element `providers` list is equivalent to this field.
847
+ */
661
848
  provider?: ProviderProxyProvider;
849
+ /**
850
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
851
+ * fails over to the next when a vendor lacks credentials or its allocation /
852
+ * transport is exhausted. When omitted, `provider` (or the platform default)
853
+ * is used as a single-vendor chain.
854
+ */
855
+ providers?: ProviderProxyProvider[];
662
856
  geo?: {
663
857
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
664
858
  country?: Iso3166Alpha2CountryCode;
@@ -669,6 +863,12 @@ export interface ProviderProxyPolicy {
669
863
  affinity?: ProviderProxySessionAffinity;
670
864
  lifetimeMinutes?: number;
671
865
  poolSize?: number;
866
+ /**
867
+ * Seconds before hard sticky expiry at which native connections receive
868
+ * the `expiring` event so the provider can drain and reconnect cleanly.
869
+ * Declared by the provider; the SDK does not assume a default cut point.
870
+ */
871
+ drainLeadSeconds?: number;
672
872
  };
673
873
  }
674
874
  export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
@@ -677,9 +877,9 @@ export interface ProviderAccessConfig {
677
877
  * Provider-level rollout visibility.
678
878
  *
679
879
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
680
- * the existing provider policy stack.
880
+ * the existing provider policy stack.
681
881
  * - `early_access`: hidden from public discovery and callable only when the
682
- * active customer organization has a provider-level access grant.
882
+ * active customer organization has a provider-level access grant.
683
883
  *
684
884
  * This is intentionally provider-level only. It does not alter auth mode,
685
885
  * operation schemas, health-check authoring, `openWorld`, or Connection
@@ -810,6 +1010,11 @@ export interface HttpRetrySummary {
810
1010
  export interface RequestOptions {
811
1011
  headers?: Record<string, string>;
812
1012
  params?: RequestParams;
1013
+ /**
1014
+ * Query parameters whose values contain credentials or other secret material.
1015
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1016
+ */
1017
+ sensitiveParams?: Record<string, string>;
813
1018
  proxy?: string;
814
1019
  timeout?: number;
815
1020
  /**
@@ -818,12 +1023,33 @@ export interface RequestOptions {
818
1023
  */
819
1024
  throwOnHttpError?: boolean;
820
1025
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1026
+ /**
1027
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1028
+ * evaluated before the next request is issued. Existing callers that omit
1029
+ * this policy retain the native fetch redirect behavior.
1030
+ */
1031
+ redirectPolicy?: HttpRedirectPolicy;
1032
+ }
1033
+ export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1034
+ export type HttpRedirectPolicyMode = "same-origin";
1035
+ export interface HttpRedirectPolicy {
1036
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1037
+ mode: HttpRedirectPolicyMode;
1038
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1039
+ maxHops: number;
821
1040
  }
1041
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
822
1042
  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 {
1043
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy"> {
824
1044
  method?: HttpMethod;
825
1045
  body?: string | Buffer;
826
1046
  redirect?: "follow" | "manual" | "error";
1047
+ /**
1048
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1049
+ * transport aborts the response and throws `response_too_large` if the
1050
+ * declared or streamed body exceeds this limit.
1051
+ */
1052
+ maxBodyBytes?: number;
827
1053
  /**
828
1054
  * Offsets policy-managed proxy pool selection for caller-managed retries.
829
1055
  * Use when a request receives an upstream challenge page rather than a
@@ -843,17 +1069,42 @@ export interface StealthFetchOptions extends RequestOptions {
843
1069
  };
844
1070
  }
845
1071
  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;
1072
+ /** URL-less reads use the jar's response URL or session base URL. */
1073
+ get(name: string, url?: string): string | undefined;
1074
+ getAll(url?: string): Record<string, string>;
1075
+ toString(url?: string): string;
1076
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
1077
+ }
1078
+ /**
1079
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1080
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1081
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1082
+ */
1083
+ export interface StealthCookieStoreV1 {
1084
+ readonly version: 1;
1085
+ readonly jar: SerializedCookieJar;
850
1086
  }
1087
+ /** Cookie persistence formats understood by this SDK version. */
1088
+ export type StealthCookieStore = StealthCookieStoreV1;
851
1089
  export interface StealthSessionCookies extends CookieJar {
852
- has(name: string): boolean;
853
- setFromCookieStrings(cookieStrings: readonly string[]): void;
854
- toHeader(): string;
1090
+ has(name: string, url?: string): boolean;
1091
+ /** URL-less writes are scoped to the session base URL. */
1092
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1093
+ toHeader(url?: string): string;
1094
+ /**
1095
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1096
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1097
+ */
855
1098
  snapshot(): Record<string, string>;
1099
+ /**
1100
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1101
+ * @deprecated Use deserialize() with state produced by serialize().
1102
+ */
856
1103
  restore(cookies: Record<string, string>): void;
1104
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1105
+ serialize(): StealthCookieStoreV1;
1106
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1107
+ deserialize(state: StealthCookieStore): void;
857
1108
  clear(): void;
858
1109
  }
859
1110
  export interface DeclarativeStealthResponse {
@@ -895,8 +1146,14 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
895
1146
  export interface StealthRedirectRunResult {
896
1147
  final: StealthResponse;
897
1148
  hops: StealthRedirectHop[];
898
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1149
+ reason: RedirectRunReason;
1150
+ /**
1151
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1152
+ * @deprecated Use cookieStore for lossless persistence.
1153
+ */
899
1154
  cookies: Record<string, string>;
1155
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1156
+ cookieStore: StealthCookieStoreV1;
900
1157
  }
901
1158
  export interface StealthSession {
902
1159
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
@@ -959,11 +1216,157 @@ export interface HttpClient {
959
1216
  stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
960
1217
  sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
961
1218
  }
1219
+ /** Request-scoped file reference accepted by provider operation inputs. */
1220
+ export interface ProviderFileRef {
1221
+ readonly type: "request_file";
1222
+ readonly id: string;
1223
+ readonly filename: string;
1224
+ readonly mime_type?: string;
1225
+ readonly size: number;
1226
+ readonly sha256?: string;
1227
+ }
1228
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1229
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1230
+ readonly mimeType?: string;
1231
+ arrayBuffer(): Promise<ArrayBuffer>;
1232
+ bytes(): Promise<Uint8Array>;
1233
+ stream(): ReadableStream<Uint8Array>;
1234
+ };
1235
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1236
+ export interface ProviderFilesContext {
1237
+ has(input: string | ProviderFileRef): boolean;
1238
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1239
+ }
1240
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1241
+ export interface NativeTcpPortRange {
1242
+ readonly start: number;
1243
+ readonly end: number;
1244
+ }
1245
+ /** Static native TCP egress declared by a provider. */
1246
+ export interface NativeTcpEgressRule {
1247
+ readonly host: string;
1248
+ readonly ports: readonly number[];
1249
+ readonly tls: NativeTcpTlsMode;
1250
+ }
1251
+ /**
1252
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1253
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1254
+ * Dynamic rules must declare at least one target host selector through
1255
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1256
+ * sources and targets match only same-family selectors (except exact
1257
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1258
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1259
+ *
1260
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1261
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1262
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1263
+ * Every rule must declare a source host selector, source port list/range, and
1264
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1265
+ */
1266
+ export interface NativeTcpDynamicEgressRule {
1267
+ readonly sourceHost?: string;
1268
+ readonly sourceHostSuffixes?: readonly string[];
1269
+ readonly sourceIpv4Cidrs?: readonly string[];
1270
+ readonly sourceIpv6Cidrs?: readonly string[];
1271
+ readonly sourcePorts?: readonly number[];
1272
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1273
+ readonly targetHostSuffixes?: readonly string[];
1274
+ readonly targetIpv4Cidrs?: readonly string[];
1275
+ readonly targetIpv6Cidrs?: readonly string[];
1276
+ readonly targetPorts?: readonly number[];
1277
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1278
+ readonly tls: NativeTcpTlsMode;
1279
+ readonly ttlMs?: number;
1280
+ readonly maxGrants?: number;
1281
+ }
1282
+ /** Common TCP/TLS connection input supported by the native runtime. */
1283
+ export interface NativeNetworkConnectInput {
1284
+ readonly host: string;
1285
+ readonly port: number;
1286
+ readonly serverName?: string;
1287
+ readonly rejectUnauthorized?: boolean;
1288
+ /**
1289
+ * Maximum time without a successful socket read before the connection is
1290
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1291
+ */
1292
+ readonly idleTimeoutMs?: number;
1293
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1294
+ readonly timeoutMs?: number;
1295
+ readonly signal?: AbortSignal;
1296
+ /** Overrides the credential-derived sticky affinity key. */
1297
+ readonly affinityKey?: string;
1298
+ }
1299
+ export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
1300
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1301
+ export interface NativeNetworkDynamicGrantOptions {
1302
+ readonly sourceHost: string;
1303
+ readonly sourcePort: number;
1304
+ readonly host: string;
1305
+ readonly port: number;
1306
+ readonly tls: NativeTcpTlsMode;
1307
+ readonly ttlMs?: number;
1308
+ }
1309
+ export interface NativeNetworkEgressGrant {
1310
+ revoke(): void;
1311
+ }
1312
+ /** Consumer-facing alias used by native TCP providers. */
1313
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1314
+ /** Resolved egress identity for a native connection routed through a proxy. */
1315
+ export interface NativeProxyEgressInfo {
1316
+ readonly vendor: ProviderProxyProvider;
1317
+ readonly sticky: boolean;
1318
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1319
+ readonly sessionId?: string;
1320
+ /** Hard expiry of the sticky binding, ISO 8601. */
1321
+ readonly expiresAt?: string;
1322
+ }
1323
+ export type NativeProxyExpiringReason = "sticky_expiry";
1324
+ export interface NativeProxyExpiringEvent {
1325
+ readonly expiresAt: string;
1326
+ readonly leadSeconds: number;
1327
+ readonly reason: NativeProxyExpiringReason;
1328
+ }
1329
+ /**
1330
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1331
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1332
+ */
1333
+ export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
1334
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1335
+ export interface NativeNetworkCloseReason {
1336
+ readonly code: string;
1337
+ readonly message: string;
1338
+ }
1339
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1340
+ export interface NativeNetworkConnection {
1341
+ /** Present when the connection was routed through a proxy. */
1342
+ readonly proxy?: NativeProxyEgressInfo;
1343
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1344
+ readonly closeReason?: NativeNetworkCloseReason;
1345
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1346
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1347
+ read(): Promise<Uint8Array | null>;
1348
+ write(data: Uint8Array): Promise<void>;
1349
+ close(): Promise<void>;
1350
+ }
1351
+ export interface NativeNetworkClient {
1352
+ connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
1353
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1354
+ grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
1355
+ }
1356
+ export interface NativeContext {
1357
+ readonly network: NativeNetworkClient;
1358
+ }
1359
+ export interface NativeProviderConfig {
1360
+ readonly network?: {
1361
+ readonly tcp?: readonly NativeTcpEgressRule[];
1362
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1363
+ };
1364
+ }
962
1365
  export interface ProviderCacheKeyOptions {
963
1366
  /**
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.
1367
+ * Additional field names whose values are hashed in stable key material. The
1368
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1369
+ * authorization, cookie, token, password, and secret.
967
1370
  */
968
1371
  redactFields?: string[];
969
1372
  }
@@ -1036,7 +1439,18 @@ export interface BrowserFrame {
1036
1439
  evaluate<T>(fn: string | (() => T)): Promise<T>;
1037
1440
  locator(selector: string): BrowserLocator;
1038
1441
  }
1039
- export type BrowserResourceMethod = "GET" | "HEAD";
1442
+ export interface BrowserCookie {
1443
+ readonly name: string;
1444
+ readonly value: string;
1445
+ readonly domain: string;
1446
+ readonly path: string;
1447
+ /** Unix seconds. Absent for a session cookie. */
1448
+ readonly expires?: number;
1449
+ readonly httpOnly: boolean;
1450
+ readonly secure: boolean;
1451
+ readonly sameSite?: "Strict" | "Lax" | "None";
1452
+ }
1453
+ export type BrowserResourceMethod = "GET" | "HEAD" | "POST";
1040
1454
  export type BrowserResourceRequest = {
1041
1455
  readonly url: string;
1042
1456
  readonly method: BrowserResourceMethod;
@@ -1045,6 +1459,8 @@ export type BrowserResourceRequest = {
1045
1459
  };
1046
1460
  export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1047
1461
  export type BrowserResourceDecision = {
1462
+ readonly action: "continue";
1463
+ } | {
1048
1464
  readonly action: "fulfill";
1049
1465
  readonly status?: number;
1050
1466
  readonly headers?: Readonly<Record<string, string>>;
@@ -1060,12 +1476,29 @@ export type BrowserResourceRoute = {
1060
1476
  export type BrowserResourcePolicy = {
1061
1477
  readonly defaultAction?: "block";
1062
1478
  readonly allowedMethods?: readonly BrowserResourceMethod[];
1479
+ /**
1480
+ * Appends an enforcing CSP header to every renderable document response
1481
+ * while the policy is active. Existing CSP headers are retained, so this
1482
+ * can only further restrict the document.
1483
+ */
1484
+ readonly documentContentSecurityPolicy?: string;
1063
1485
  readonly routes: readonly BrowserResourceRoute[];
1064
1486
  };
1065
1487
  export interface BrowserPage extends BrowserFrame {
1066
1488
  close(): Promise<void>;
1489
+ /** Returns the user agent used by this page's browser context. */
1490
+ userAgent(): Promise<string>;
1491
+ /**
1492
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1493
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1494
+ */
1495
+ cookies(): Promise<readonly BrowserCookie[]>;
1067
1496
  fill(selector: string, text: string): Promise<void>;
1068
1497
  goto(url: string): Promise<void>;
1498
+ goto(url: string, options?: {
1499
+ readonly timeout?: number;
1500
+ readonly waitUntil?: "load" | "domcontentloaded";
1501
+ }): Promise<void>;
1069
1502
  pageId?: string;
1070
1503
  screenshot(options?: {
1071
1504
  fullPage?: boolean;
@@ -1138,6 +1571,26 @@ export interface ProviderChoiceBindingOptions {
1138
1571
  connection?: boolean;
1139
1572
  credentialKeys?: readonly string[];
1140
1573
  }
1574
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1575
+ export type ProviderChoiceConsumeResult = {
1576
+ readonly status: "consumed";
1577
+ } | {
1578
+ readonly status: "already-consumed";
1579
+ } | {
1580
+ readonly status: "unsupported";
1581
+ };
1582
+ export type ProviderChoiceExplicitParseResult = {
1583
+ readonly status: "active";
1584
+ readonly payload: Record<string, unknown>;
1585
+ /** Stable, opaque key for provider-owned idempotency records. */
1586
+ readonly replayKey: string;
1587
+ /** Atomically claims a word token. Inline tokens report unsupported. */
1588
+ consume(): Promise<ProviderChoiceConsumeResult>;
1589
+ } | {
1590
+ readonly status: "consumed";
1591
+ /** Use this key to read the provider-owned result before returning an error. */
1592
+ readonly replayKey: string;
1593
+ };
1141
1594
  export type ProviderChoiceStorageOptions = {
1142
1595
  readonly mode: "inline";
1143
1596
  } | {
@@ -1165,6 +1618,8 @@ export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unkn
1165
1618
  ttlMs: number;
1166
1619
  nowMs?: number;
1167
1620
  bind?: ProviderChoiceBindingOptions;
1621
+ /** Server storage only: standard emits four words; high emits five. */
1622
+ strength?: "standard" | "high";
1168
1623
  storage?: ProviderChoiceStorageOptions;
1169
1624
  }
1170
1625
  export interface ProviderChoiceParseOptions {
@@ -1176,6 +1631,8 @@ export interface ProviderChoiceParseOptions {
1176
1631
  futureToleranceMs?: number;
1177
1632
  bind?: ProviderChoiceBindingOptions;
1178
1633
  storage?: ProviderChoiceStorageOptions;
1634
+ /** Defaults to never, preserving reusable choice-token parse semantics. */
1635
+ consume?: ProviderChoiceConsumeMode;
1179
1636
  }
1180
1637
  export interface ProviderChoiceContext {
1181
1638
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
@@ -1194,6 +1651,9 @@ export interface ProviderChoiceContext {
1194
1651
  }>;
1195
1652
  }): string | Promise<string>;
1196
1653
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1654
+ parse(options: ProviderChoiceParseOptions & {
1655
+ readonly consume: "explicit";
1656
+ }): Promise<ProviderChoiceExplicitParseResult>;
1197
1657
  parse(options: ProviderChoiceParseOptions & {
1198
1658
  readonly storage?: {
1199
1659
  readonly mode: "inline";
@@ -1209,7 +1669,7 @@ export interface ProviderChoiceContext {
1209
1669
  readonly mode: "auto";
1210
1670
  }>;
1211
1671
  }): Record<string, unknown> | Promise<Record<string, unknown>>;
1212
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1672
+ parse(options: ProviderChoiceParseOptions): Record<string, unknown> | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1213
1673
  }
1214
1674
  export interface ContextScratchpad {
1215
1675
  get(key: string): unknown;
@@ -1285,16 +1745,34 @@ export interface AuthFlowTerminalContext {
1285
1745
  }): AuthTurn;
1286
1746
  }
1287
1747
  export interface FlowContext {
1748
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
1749
+ flowId?: string;
1288
1750
  connectionId?: string;
1289
1751
  externalRef?: string;
1290
1752
  tenantId: string;
1291
1753
  providerId: string;
1292
1754
  http: HttpClient;
1755
+ /** Durable connection-scoped runtime state. Present when the host runtime
1756
+ * supplies one; auth ceremonies must fail closed when absent rather than
1757
+ * fall back to bypassable in-process storage.
1758
+ *
1759
+ * Scoped via `ProviderRuntimeState.forConnection`: requests that resolve no
1760
+ * connection id (pre-connection ceremonies such as first-time logins) share
1761
+ * the documented isolated missing-connection scope. That sharing is the
1762
+ * intended semantic — it lets counters keyed by caller identity (e.g. a
1763
+ * login email) persist across separate ceremonies for the same caller.
1764
+ * Flows storing entries in that scope MUST key them by caller identity;
1765
+ * un-keyed entries would be shared across all connectionless ceremonies. */
1766
+ readonly state?: ProviderRuntimeState;
1767
+ /** Present when the selected runtime supplies native network capabilities. */
1768
+ readonly native?: NativeContext;
1293
1769
  stealth: StealthClient;
1294
1770
  env: EnvContext;
1295
1771
  credential?: CredentialContext;
1296
1772
  context: ContextScratchpad;
1773
+ ocr: OcrContext;
1297
1774
  stt: SttContext;
1775
+ resolver: ResolverContext;
1298
1776
  auth: AuthFlowTerminalContext;
1299
1777
  }
1300
1778
  export interface AuthTurn {
@@ -1326,7 +1804,13 @@ export interface AuthFlowDefinition {
1326
1804
  refresh?: AuthFlowInputHandler;
1327
1805
  }
1328
1806
  export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1807
+ export type StateNamespaceScope = "connection" | "provider";
1329
1808
  export interface StateNamespaceOptions {
1809
+ /**
1810
+ * State isolation boundary. Connection scope is the default; provider scope
1811
+ * must be selected explicitly for provider-wide coordination state.
1812
+ */
1813
+ scope?: StateNamespaceScope;
1330
1814
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1331
1815
  defaultTtl: ProviderStateDurationString;
1332
1816
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1368,6 +1852,11 @@ export interface ProviderStateNamespace {
1368
1852
  increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1369
1853
  }
1370
1854
  export interface ProviderRuntimeState {
1855
+ /**
1856
+ * Returns an immutable view bound to one request connection. An unresolved
1857
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
1858
+ */
1859
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1371
1860
  namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1372
1861
  }
1373
1862
  export interface ProviderContext {
@@ -1375,17 +1864,41 @@ export interface ProviderContext {
1375
1864
  credential: CredentialContext;
1376
1865
  request?: ProviderRequestContext;
1377
1866
  http: HttpClient;
1867
+ /** Present for requests carrying runtime-resolvable file references. */
1868
+ readonly files?: ProviderFilesContext;
1869
+ /** Native network capability selected by declaration-derived contexts. */
1870
+ readonly native: NativeContext;
1378
1871
  cache: ProviderCache;
1379
1872
  state: ProviderRuntimeState;
1380
1873
  stealth: StealthClient;
1381
1874
  browser: BrowserClient;
1382
1875
  trace: TraceContext;
1383
1876
  auth: AuthContext;
1877
+ ocr: OcrContext;
1384
1878
  stt: SttContext;
1879
+ resolver: ResolverContext;
1385
1880
  choice: ProviderChoiceContext;
1386
1881
  }
1882
+ /**
1883
+ * The operation context exposed for one provider declaration. Capability
1884
+ * bindings are present only when their corresponding declaration is present;
1885
+ * trace and request remain ambient runtime bindings.
1886
+ */
1887
+ 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>);
1888
+ export interface ProxiedOAuthConfig {
1889
+ authorizeUrl: string;
1890
+ tokenUrl: string;
1891
+ customScheme: string;
1892
+ rewriteProfile: string;
1893
+ clientIdEnvKey: string;
1894
+ pkce?: "S256" | "none";
1895
+ authorizeParams?: Record<string, string>;
1896
+ tokenParams?: Record<string, string>;
1897
+ }
1387
1898
  export interface AuthConfig {
1388
1899
  mode: AuthMode;
1900
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
1901
+ proxied?: ProxiedOAuthConfig;
1389
1902
  flow?: AuthFlowDefinition;
1390
1903
  }
1391
1904
  export interface ProviderSecretDeclaration {
@@ -1417,7 +1930,7 @@ export interface OperationContractMetadata {
1417
1930
  lifecycle?: OperationLifecycle;
1418
1931
  deprecation?: OperationDeprecationMetadata;
1419
1932
  }
1420
- export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
1933
+ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike, TContext = ProviderContext> {
1421
1934
  /**
1422
1935
  * Short English display title for the operation. The SDK passes it through
1423
1936
  * verbatim; the APIFuse registry derives the operation's en locale title
@@ -1447,10 +1960,15 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
1447
1960
  retryOnAuthRefresh?: boolean;
1448
1961
  input: TInput;
1449
1962
  output: TOutput;
1450
- handler(ctx: ProviderContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1963
+ handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1451
1964
  fixtures?: {
1452
1965
  request: InferSchemaOutput<TInput>;
1453
1966
  response: InferSchemaOutput<TOutput>;
1967
+ /**
1968
+ * KST calendar date when `response` evidence was captured. Date fields in
1969
+ * the response align with this date, not a resolved relative request date.
1970
+ */
1971
+ recordedAt?: string;
1454
1972
  };
1455
1973
  upstream?: {
1456
1974
  baseUrl?: string;
@@ -1509,12 +2027,15 @@ export interface ProviderDefinition {
1509
2027
  */
1510
2028
  deployment?: ProviderDeploymentOverrides;
1511
2029
  allowedHosts?: string[];
2030
+ native?: NativeProviderConfig;
1512
2031
  stealth?: {
1513
2032
  profile: string;
1514
2033
  platform: StealthPlatform;
1515
2034
  };
1516
2035
  proxy?: ProviderProxyConfig;
2036
+ ocr?: ProviderOcrConfig;
1517
2037
  stt?: ProviderSttConfig;
2038
+ resolver?: ProviderResolverConfig;
1518
2039
  browser?: {
1519
2040
  engine: BrowserEngine;
1520
2041
  };
@@ -1531,3 +2052,4 @@ export interface ProviderDefinition {
1531
2052
  healthProbe?: ProviderHealthProbeConfig;
1532
2053
  healthJourneys?: readonly HealthJourneyDefinition[];
1533
2054
  }
2055
+ export {};