@apifuse/provider-sdk 2.2.0-beta.3 → 2.2.0-beta.31

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 (342) hide show
  1. package/AUTHORING.md +493 -5
  2. package/CHANGELOG.md +131 -1
  3. package/README.md +52 -6
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +106 -62
  6. package/bin/apifuse-create.ts +1 -1
  7. package/bin/apifuse-dev.ts +63 -55
  8. package/bin/apifuse-pack-check.ts +22 -2
  9. package/bin/apifuse-pack-smoke.ts +78 -82
  10. package/bin/apifuse-pack-types.ts +583 -0
  11. package/bin/apifuse-perf.ts +59 -140
  12. package/bin/apifuse-record.ts +698 -113
  13. package/bin/apifuse-submit-check.ts +517 -44
  14. package/bin/apifuse-sync-assets.ts +117 -0
  15. package/bin/apifuse.ts +1 -1
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/bin/submit-check-xml.ts +1 -1
  18. package/dist/auth-turn/index.d.ts +4 -4
  19. package/dist/auth-turn/index.js +1 -1
  20. package/dist/auth.d.ts +16 -2
  21. package/dist/auth.js +76 -18
  22. package/dist/ceremonies/index.d.ts +9 -1
  23. package/dist/ceremonies/index.js +117 -29
  24. package/dist/cli/commands.d.ts +1 -1
  25. package/dist/cli/commands.js +8 -0
  26. package/dist/cli/create.d.ts +3 -0
  27. package/dist/cli/create.js +34 -35
  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/README.md.tpl +4 -4
  32. package/dist/config/loader.d.ts +176 -17
  33. package/dist/config/loader.js +434 -161
  34. package/dist/contract-serialization.d.ts +2 -2
  35. package/dist/contract-serialization.js +7 -14
  36. package/dist/contract-types.d.ts +3 -2
  37. package/dist/contract.d.ts +3 -3
  38. package/dist/contract.js +6 -6
  39. package/dist/declaration-validation.d.ts +23 -0
  40. package/dist/declaration-validation.js +159 -0
  41. package/dist/define.d.ts +13 -1
  42. package/dist/define.js +391 -122
  43. package/dist/dev.d.ts +1 -1
  44. package/dist/dev.js +1 -1
  45. package/dist/error-resolution.d.ts +4 -0
  46. package/dist/error-resolution.js +123 -0
  47. package/dist/errors.d.ts +19 -1
  48. package/dist/errors.js +41 -3
  49. package/dist/fixture-sanitization.d.ts +26 -0
  50. package/dist/fixture-sanitization.js +216 -0
  51. package/dist/i18n/catalog.d.ts +2 -2
  52. package/dist/i18n/catalog.js +4 -10
  53. package/dist/i18n/index.d.ts +2 -2
  54. package/dist/i18n/index.js +2 -2
  55. package/dist/i18n/keys.d.ts +2 -2
  56. package/dist/index.d.ts +50 -42
  57. package/dist/index.js +41 -37
  58. package/dist/lint.d.ts +6 -1
  59. package/dist/lint.js +370 -18
  60. package/dist/native-address.d.ts +43 -0
  61. package/dist/native-address.js +281 -0
  62. package/dist/native-egress-policy.d.ts +31 -0
  63. package/dist/native-egress-policy.js +288 -0
  64. package/dist/observability.d.ts +5 -2
  65. package/dist/observability.js +48 -1
  66. package/dist/provider.d.ts +13 -11
  67. package/dist/provider.js +10 -9
  68. package/dist/public-schema-field-lint.d.ts +1 -1
  69. package/dist/recipes/gov-api.js +1 -1
  70. package/dist/runtime/auth-flow.d.ts +3 -1
  71. package/dist/runtime/auth-flow.js +8 -3
  72. package/dist/runtime/browser.d.ts +1 -1
  73. package/dist/runtime/browser.js +138 -40
  74. package/dist/runtime/cache.d.ts +2 -1
  75. package/dist/runtime/cache.js +173 -23
  76. package/dist/runtime/choice-wordlist.d.ts +9 -0
  77. package/dist/runtime/choice-wordlist.js +138 -0
  78. package/dist/runtime/choice.d.ts +14 -1
  79. package/dist/runtime/choice.js +566 -101
  80. package/dist/runtime/credential.d.ts +1 -1
  81. package/dist/runtime/credential.js +1 -1
  82. package/dist/runtime/env.d.ts +1 -1
  83. package/dist/runtime/executor.d.ts +1 -1
  84. package/dist/runtime/executor.js +25 -3
  85. package/dist/runtime/http.d.ts +3 -2
  86. package/dist/runtime/http.js +517 -55
  87. package/dist/runtime/insights.d.ts +1 -1
  88. package/dist/runtime/insights.js +6 -13
  89. package/dist/runtime/instrumentation.d.ts +2 -2
  90. package/dist/runtime/instrumentation.js +371 -23
  91. package/dist/runtime/keyring.js +1 -1
  92. package/dist/runtime/namespace.js +1 -1
  93. package/dist/runtime/native-network-errors.d.ts +33 -0
  94. package/dist/runtime/native-network-errors.js +69 -0
  95. package/dist/runtime/native-network.d.ts +96 -0
  96. package/dist/runtime/native-network.js +1232 -0
  97. package/dist/runtime/ocr.d.ts +29 -0
  98. package/dist/runtime/ocr.js +440 -0
  99. package/dist/runtime/otlp.d.ts +1 -1
  100. package/dist/runtime/perf.d.ts +1 -1
  101. package/dist/runtime/provider.d.ts +1 -1
  102. package/dist/runtime/provider.js +1 -2
  103. package/dist/runtime/proxy-errors.d.ts +1 -1
  104. package/dist/runtime/proxy-errors.js +9 -7
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-retry-policy.d.ts +2 -2
  108. package/dist/runtime/proxy-retry-policy.js +2 -2
  109. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  110. package/dist/runtime/proxy-telemetry.js +58 -52
  111. package/dist/runtime/redirects.d.ts +29 -0
  112. package/dist/runtime/redirects.js +36 -0
  113. package/dist/runtime/redis.d.ts +1 -1
  114. package/dist/runtime/redis.js +5 -5
  115. package/dist/runtime/request-options.d.ts +68 -1
  116. package/dist/runtime/request-options.js +548 -0
  117. package/dist/runtime/resolver-config.d.ts +6 -0
  118. package/dist/runtime/resolver-config.js +6 -0
  119. package/dist/runtime/resolver-public.d.ts +1 -0
  120. package/dist/runtime/resolver-public.js +1 -0
  121. package/dist/runtime/resolver-shared.d.ts +3 -0
  122. package/dist/runtime/resolver-shared.js +12 -0
  123. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  124. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  125. package/dist/runtime/resolver-vendors/browser.d.ts +20 -0
  126. package/dist/runtime/resolver-vendors/browser.js +282 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +368 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +83 -0
  132. package/dist/runtime/resolver-vendors/types.js +69 -0
  133. package/dist/runtime/resolver.d.ts +59 -0
  134. package/dist/runtime/resolver.js +705 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +5 -2
  138. package/dist/runtime/state.js +280 -74
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +30 -5
  142. package/dist/runtime/stealth.js +523 -259
  143. package/dist/runtime/stt.d.ts +1 -1
  144. package/dist/runtime/stt.js +12 -27
  145. package/dist/runtime/timeout.d.ts +5 -0
  146. package/dist/runtime/timeout.js +12 -0
  147. package/dist/runtime/trace.d.ts +2 -2
  148. package/dist/runtime/trace.js +2 -4
  149. package/dist/runtime/waterfall.d.ts +1 -1
  150. package/dist/schema.d.ts +1 -1
  151. package/dist/schema.js +7 -15
  152. package/dist/serve.d.ts +1 -1
  153. package/dist/serve.js +1 -1
  154. package/dist/server/index.d.ts +7 -7
  155. package/dist/server/index.js +6 -6
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test-redaction.d.ts +1 -1
  159. package/dist/server/self-test-redaction.js +1 -1
  160. package/dist/server/self-test.d.ts +117 -3
  161. package/dist/server/self-test.js +787 -151
  162. package/dist/server/serve-implementation.d.ts +210 -0
  163. package/dist/server/serve-implementation.js +2078 -0
  164. package/dist/server/serve.d.ts +1 -70
  165. package/dist/server/serve.js +1 -1143
  166. package/dist/server/types.d.ts +34 -9
  167. package/dist/server/types.js +8 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +1 -1
  207. package/dist/stealth/profiles.js +21 -21
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.d.ts +1 -1
  211. package/dist/stream.js +7 -1
  212. package/dist/testing/index.d.ts +3 -2
  213. package/dist/testing/index.js +3 -2
  214. package/dist/testing/run.d.ts +32 -2
  215. package/dist/testing/run.js +488 -28
  216. package/dist/types.d.ts +566 -19
  217. package/dist/types.js +1 -0
  218. package/dist/user-input.d.ts +30 -0
  219. package/dist/user-input.js +66 -0
  220. package/package.json +42 -7
  221. package/src/auth-turn/index.ts +2 -2
  222. package/src/auth.ts +146 -86
  223. package/src/ceremonies/index.ts +167 -92
  224. package/src/cli/commands.ts +10 -0
  225. package/src/cli/create.ts +42 -35
  226. package/src/cli/prompt-assets.ts +865 -0
  227. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  228. package/src/cli/templates/provider/README.md.tpl +4 -4
  229. package/src/config/loader.ts +667 -289
  230. package/src/contract-serialization.ts +10 -18
  231. package/src/contract-types.ts +3 -2
  232. package/src/contract.ts +14 -28
  233. package/src/declaration-validation.ts +202 -0
  234. package/src/define.ts +631 -495
  235. package/src/dev.ts +4 -9
  236. package/src/error-resolution.ts +128 -0
  237. package/src/errors.ts +56 -11
  238. package/src/fixture-sanitization.ts +247 -0
  239. package/src/i18n/catalog.ts +10 -32
  240. package/src/i18n/index.ts +2 -2
  241. package/src/i18n/keys.ts +5 -11
  242. package/src/index.ts +158 -44
  243. package/src/lint.ts +488 -154
  244. package/src/native-address.ts +340 -0
  245. package/src/native-egress-policy.ts +358 -0
  246. package/src/observability.ts +51 -1
  247. package/src/provider.ts +66 -11
  248. package/src/public-schema-field-lint.ts +7 -33
  249. package/src/recipes/gov-api.ts +2 -5
  250. package/src/runtime/auth-flow.ts +13 -7
  251. package/src/runtime/browser.ts +252 -207
  252. package/src/runtime/cache.ts +209 -81
  253. package/src/runtime/choice-wordlist.ts +145 -0
  254. package/src/runtime/choice.ts +758 -197
  255. package/src/runtime/credential.ts +2 -2
  256. package/src/runtime/env.ts +1 -1
  257. package/src/runtime/executor.ts +37 -19
  258. package/src/runtime/http.ts +645 -65
  259. package/src/runtime/insights.ts +15 -53
  260. package/src/runtime/instrumentation.ts +530 -67
  261. package/src/runtime/keyring.ts +7 -19
  262. package/src/runtime/namespace.ts +2 -7
  263. package/src/runtime/native-network-errors.ts +99 -0
  264. package/src/runtime/native-network.ts +1605 -0
  265. package/src/runtime/ocr.ts +523 -0
  266. package/src/runtime/otlp.ts +12 -23
  267. package/src/runtime/perf.ts +1 -1
  268. package/src/runtime/provider.ts +4 -9
  269. package/src/runtime/proxy-errors.ts +29 -42
  270. package/src/runtime/proxy-nodemaven.ts +221 -0
  271. package/src/runtime/proxy-retry-policy.ts +3 -3
  272. package/src/runtime/proxy-telemetry.ts +84 -77
  273. package/src/runtime/redirects.ts +66 -0
  274. package/src/runtime/redis.ts +10 -13
  275. package/src/runtime/request-options.ts +679 -9
  276. package/src/runtime/resolver-config.ts +6 -0
  277. package/src/runtime/resolver-public.ts +18 -0
  278. package/src/runtime/resolver-shared.ts +17 -0
  279. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  280. package/src/runtime/resolver-vendors/browser.ts +408 -0
  281. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  282. package/src/runtime/resolver-vendors/twocaptcha.ts +500 -0
  283. package/src/runtime/resolver-vendors/types.ts +173 -0
  284. package/src/runtime/resolver.ts +1060 -0
  285. package/src/runtime/secrets.ts +64 -0
  286. package/src/runtime/state.ts +399 -161
  287. package/src/runtime/stealth-cookies.ts +132 -0
  288. package/src/runtime/stealth.ts +681 -295
  289. package/src/runtime/stt.ts +39 -113
  290. package/src/runtime/timeout.ts +18 -0
  291. package/src/runtime/trace.ts +14 -44
  292. package/src/runtime/waterfall.ts +5 -18
  293. package/src/schema.ts +23 -84
  294. package/src/serve.ts +6 -1
  295. package/src/server/index.ts +30 -7
  296. package/src/server/self-test-input-tokens.ts +29 -14
  297. package/src/server/self-test-redaction.ts +2 -2
  298. package/src/server/self-test.ts +1030 -180
  299. package/src/server/serve-implementation.ts +3062 -0
  300. package/src/server/serve.ts +1 -1781
  301. package/src/server/types.ts +12 -13
  302. package/src/stateful/README.md +146 -0
  303. package/src/stateful/errors.ts +35 -0
  304. package/src/stateful/http-provider-event-emitter.ts +314 -0
  305. package/src/stateful/http-session-owner-registry.ts +306 -0
  306. package/src/stateful/index.ts +18 -0
  307. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  308. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  309. package/src/stateful/provider-event-pipeline.ts +61 -0
  310. package/src/stateful/provider-events.ts +462 -0
  311. package/src/stateful/session-key.ts +111 -0
  312. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  313. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  314. package/src/stateful/stateful-provider-adapter.ts +562 -0
  315. package/src/stateful/stateful-provider-observability.ts +261 -0
  316. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  317. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  318. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  319. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  320. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  321. package/src/stateful-signing.ts +46 -0
  322. package/src/stealth/profiles.ts +27 -33
  323. package/src/stream-evidence.ts +988 -0
  324. package/src/stream.ts +16 -20
  325. package/src/testing/index.ts +11 -2
  326. package/src/testing/run.ts +668 -74
  327. package/src/types.ts +665 -35
  328. package/src/user-input.ts +118 -0
  329. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  330. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  331. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  332. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  333. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  334. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  335. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  336. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  337. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  338. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  339. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  340. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  341. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  342. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type ms from "ms";
2
+ import type { SerializedCookieJar } from "tough-cookie";
2
3
  import type { infer as ZodInfer, ZodType } from "zod";
3
4
  /** Minimal Standard Schema v1 shape accepted by provider operations. */
4
5
  export interface StandardSchemaV1<Input = unknown, Output = Input> {
@@ -46,6 +47,8 @@ export interface OperationToolRouterMetadata {
46
47
  riskClass?: OperationRiskClass;
47
48
  /** OpenAI remote-MCP approval hint. Defaults from riskClass. */
48
49
  approval?: OperationApprovalPolicy;
50
+ /** Canonical operation-level connection requirement consumed by the registry and Gateway. */
51
+ connectionMode?: "none" | "optional" | "required";
49
52
  /** Override connection requirement when provider auth + openWorld inference is insufficient. */
50
53
  requiresConnection?: boolean;
51
54
  /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
@@ -193,6 +196,54 @@ export interface SmsOtpMatcherDefinition {
193
196
  /** Runtime/fixture helper. Not serialized into generated registry artifacts. */
194
197
  extractOtp(body: string): string | null;
195
198
  }
199
+ export interface ProviderOcrConfig {
200
+ readonly mode: "required" | "optional";
201
+ }
202
+ export type OcrImageInput = {
203
+ readonly kind: "base64";
204
+ readonly data: string;
205
+ readonly mediaType?: string;
206
+ } | {
207
+ readonly kind: "url";
208
+ readonly url: string;
209
+ };
210
+ export interface OcrRecognizeRequest {
211
+ readonly image: OcrImageInput;
212
+ readonly hint?: "captcha" | "document" | "generic";
213
+ readonly prompt?: string;
214
+ readonly maxTokens?: number;
215
+ readonly timeoutMs?: number;
216
+ }
217
+ export interface OcrWarning {
218
+ readonly code: string;
219
+ readonly message: string;
220
+ }
221
+ export interface OcrResult {
222
+ readonly text: string;
223
+ readonly model: string;
224
+ readonly warnings?: readonly OcrWarning[];
225
+ }
226
+ export interface OcrCaptchaOptions {
227
+ readonly length?: number;
228
+ /** Allowed characters. A RegExp is applied to each character, not to the whole text. */
229
+ readonly charset?: string | RegExp;
230
+ readonly caseSensitive?: boolean;
231
+ readonly maxCandidates?: number;
232
+ }
233
+ export interface OcrCaptchaCandidate {
234
+ readonly text: string;
235
+ readonly satisfiesConstraints: boolean;
236
+ }
237
+ export interface OcrCaptchaResult {
238
+ readonly text: string;
239
+ readonly candidates: readonly OcrCaptchaCandidate[];
240
+ readonly satisfiesConstraints: boolean;
241
+ readonly model: string;
242
+ }
243
+ export interface OcrContext {
244
+ recognize(request: OcrRecognizeRequest): Promise<OcrResult>;
245
+ extractCaptchaText(image: OcrImageInput, options?: OcrCaptchaOptions): Promise<OcrCaptchaResult>;
246
+ }
196
247
  export type SttTranscribeMode = "general" | "otp";
197
248
  export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
198
249
  export type SttUnsupportedOptionPolicy = "warn" | "error";
@@ -200,6 +251,106 @@ export type ProviderSttMode = "optional" | "required";
200
251
  export interface ProviderSttConfig {
201
252
  mode: ProviderSttMode;
202
253
  }
254
+ /**
255
+ * `browser` is the in-house CDP pool (`apps/cdp-pool`, reached through
256
+ * `createBrowserClient`) and is a first-class vendor rather than an escape hatch:
257
+ * for fingerprint-family kinds, it was measured faster than a paid vendor
258
+ * (4.5 s vs 17.5 s) at zero marginal cost.
259
+ *
260
+ * `2captcha` is the vendor already carrying production traffic in
261
+ * `apifuse-provider-tabelog`.
262
+ *
263
+ * Union order is documentation only; the effective fallback order is whatever
264
+ * `ProviderResolverConfig.vendors` declares.
265
+ */
266
+ export type ProviderResolverVendor = "browser" | "capsolver" | "capmonster" | "2captcha" | "custom";
267
+ /**
268
+ * Token-family kinds resolve to `{ form: "token" }`. Cookie-family kinds resolve
269
+ * to `{ form: "cookies" }`; network-identity binding is defined per kind. `aws_waf`
270
+ * was measured portable across residential leases on buyee, while `cf_clearance`
271
+ * remains unmeasured here and is treated as identity-scoped because it is widely
272
+ * described as IP-bound.
273
+ */
274
+ export type ProviderChallenge = {
275
+ readonly kind: "turnstile";
276
+ readonly siteKey: string;
277
+ readonly pageUrl: string;
278
+ readonly action?: string;
279
+ readonly cdata?: string;
280
+ } | {
281
+ readonly kind: "recaptcha_v2";
282
+ readonly siteKey: string;
283
+ readonly pageUrl: string;
284
+ } | {
285
+ readonly kind: "recaptcha_v3";
286
+ readonly siteKey: string;
287
+ readonly pageUrl: string;
288
+ readonly action: string;
289
+ readonly minScore?: number;
290
+ } | {
291
+ readonly kind: "hcaptcha";
292
+ readonly siteKey: string;
293
+ readonly pageUrl: string;
294
+ } | {
295
+ readonly kind: "cloudflare_interstitial";
296
+ readonly pageUrl: string;
297
+ readonly blockedHtml?: string;
298
+ } | {
299
+ readonly kind: "aws_waf";
300
+ readonly pageUrl: string;
301
+ /** `window.gokuProps.key`; solver vendors require it, while `"browser"` does not. */
302
+ readonly siteKey?: string;
303
+ readonly captchaScript?: string;
304
+ readonly context?: string;
305
+ readonly iv?: string;
306
+ } | {
307
+ readonly kind: "akamai_sec_cpt";
308
+ readonly pageUrl: string;
309
+ /** The admitted challenge document, needed for tile/context extraction. */
310
+ readonly challengeHtml?: string;
311
+ } | {
312
+ readonly kind: "akamai_sensor";
313
+ readonly pageUrl: string;
314
+ /** Upstream sensor script URL the payload must be POSTed to. */
315
+ readonly scriptUrl: string;
316
+ /** Current `_abck` cookie value, rotates each round. */
317
+ readonly abck?: string;
318
+ /** Current `bm_sz` / `ak_bmsc` value when the upstream set one. */
319
+ readonly bmsz?: string;
320
+ /** Bot Manager major version when known ("3" measured on zozo.jp). */
321
+ readonly version?: string;
322
+ };
323
+ export type ProviderChallengeKind = ProviderChallenge["kind"];
324
+ /**
325
+ * Token solutions carry no network-identity binding. Cookie-solution binding is
326
+ * per challenge kind: `aws_waf` was measured portable across residential leases
327
+ * on buyee, while `cf_clearance` is unmeasured here and treated as scoped to the
328
+ * identity that produced it. The provider attaches the returned cookies to its
329
+ * own requests.
330
+ */
331
+ export type ChallengeSolution = {
332
+ readonly form: "token";
333
+ readonly token: string;
334
+ } | {
335
+ readonly form: "cookies";
336
+ readonly cookies: Readonly<Record<string, string>>;
337
+ readonly userAgent: string;
338
+ /** Epoch seconds copied from the upstream cookie's own expiry attribute; never a constant. */
339
+ readonly expires?: number;
340
+ };
341
+ export interface ProviderResolverConfig {
342
+ /** Ordered vendor fallback chain, tried first to last. */
343
+ readonly vendors: readonly ProviderResolverVendor[];
344
+ /** Challenge kinds this provider is permitted to request. */
345
+ readonly kinds: readonly ProviderChallengeKind[];
346
+ /**
347
+ * Client fingerprint profile the SDK must use when reaching this upstream.
348
+ * Measured on zozo.jp: Chrome/Firefox profiles are refused 403 before any
349
+ * challenge is served, while a Safari profile is admitted. Provider-declared
350
+ * because only the provider knows its upstream's admission rule.
351
+ */
352
+ readonly clientProfile?: string;
353
+ }
203
354
  export type SttAudioInput = {
204
355
  kind: "base64";
205
356
  data: string;
@@ -264,6 +415,9 @@ export interface SttContext {
264
415
  transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
265
416
  extractVerificationCode(text: string, options?: SttVerificationCodeOptions): VerificationCodeExtractionResult;
266
417
  }
418
+ export interface ResolverContext {
419
+ solve(challenge: ProviderChallenge, signal?: AbortSignal): Promise<ChallengeSolution>;
420
+ }
267
421
  export interface HealthJourneySchedule {
268
422
  kind: "interval";
269
423
  /** ISO 8601 duration, for example PT8H. */
@@ -407,7 +561,13 @@ export interface HealthJourneyDefinition {
407
561
  requiredSecrets?: readonly string[];
408
562
  manualTrigger?: HealthJourneyManualTriggerPolicy;
409
563
  steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
410
- run?: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
564
+ /**
565
+ * Required: a journey always declares `coversOperations`, and the health
566
+ * monitor reports a run-less journey as `journey_run_missing`. Declaration
567
+ * validation rejects a missing `run` (`health-journey-executable`), so this
568
+ * is typed required to fail at compile time rather than at boot.
569
+ */
570
+ run: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
411
571
  }
412
572
  /**
413
573
  * Health-check authoring surface owned by `@apifuse/provider-sdk`.
@@ -609,9 +769,11 @@ export interface HealthMonitorProbeOverride {
609
769
  /** Optional degraded threshold override for generated registry probes. */
610
770
  degradedThresholdMs?: number;
611
771
  }
772
+ export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
773
+ export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
612
774
  export interface OperationErrorCode {
613
775
  code: string;
614
- status?: number;
776
+ status?: ProviderErrorStatus;
615
777
  description: string;
616
778
  retryable?: boolean;
617
779
  }
@@ -645,12 +807,32 @@ export interface StealthProfile {
645
807
  h2Settings?: Record<string, unknown>;
646
808
  headerOrder?: string[];
647
809
  }
648
- export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
810
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
649
811
  export type ConnectionMode = AuthMode;
650
812
  export type ProviderReviewed = "first-party" | "community" | "staging";
651
813
  export type ProviderAccessVisibility = "public" | "early_access";
652
814
  export type ProviderProxyMode = "disabled" | "optional" | "required";
653
- export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
815
+ /**
816
+ * Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
817
+ * (a common mistake because the names collide with a well-known rebrand):
818
+ *
819
+ * - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
820
+ * *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
821
+ * endpoints). This is our own vendor. It is NOT the company formerly named
822
+ * "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
823
+ * - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
824
+ * credentials; geo/session encoded in the username, no allocation API.
825
+ * - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
826
+ * (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
827
+ * username params. A different company from `smartproxy` above.
828
+ * **@deprecated** — unused; no managed adapter. Declare a
829
+ * `ProviderProxyPolicy` using `smartproxy` or `nodemaven` instead; the
830
+ * `smartproxy` allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
831
+ * - `custom` — **@deprecated** static proxy marker with no managed adapter.
832
+ * Use `ProviderProxyPolicy` with `smartproxy`/`nodemaven`; the `smartproxy`
833
+ * allocator requires `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
834
+ */
835
+ export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
654
836
  export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
655
837
  export interface ProviderProxyPolicy {
656
838
  /**
@@ -658,7 +840,18 @@ export interface ProviderProxyPolicy {
658
840
  * certificate verification, and vendor allocator endpoints are SDK-owned.
659
841
  */
660
842
  mode: ProviderProxyMode;
843
+ /**
844
+ * @deprecated Use `providers: [...]` to declare an ordered vendor fallback
845
+ * chain. A single-element `providers` list is equivalent to this field.
846
+ */
661
847
  provider?: ProviderProxyProvider;
848
+ /**
849
+ * Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
850
+ * fails over to the next when a vendor lacks credentials or its allocation /
851
+ * transport is exhausted. When omitted, `provider` (or the platform default)
852
+ * is used as a single-vendor chain.
853
+ */
854
+ providers?: ProviderProxyProvider[];
662
855
  geo?: {
663
856
  /** ISO 3166-1 alpha-2 country code, for example KR or US. */
664
857
  country?: Iso3166Alpha2CountryCode;
@@ -669,6 +862,12 @@ export interface ProviderProxyPolicy {
669
862
  affinity?: ProviderProxySessionAffinity;
670
863
  lifetimeMinutes?: number;
671
864
  poolSize?: number;
865
+ /**
866
+ * Seconds before hard sticky expiry at which native connections receive
867
+ * the `expiring` event so the provider can drain and reconnect cleanly.
868
+ * Declared by the provider; the SDK does not assume a default cut point.
869
+ */
870
+ drainLeadSeconds?: number;
672
871
  };
673
872
  }
674
873
  export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
@@ -677,9 +876,9 @@ export interface ProviderAccessConfig {
677
876
  * Provider-level rollout visibility.
678
877
  *
679
878
  * - `public`: visible in public docs/catalog/OpenAPI and callable through
680
- * the existing provider policy stack.
879
+ * the existing provider policy stack.
681
880
  * - `early_access`: hidden from public discovery and callable only when the
682
- * active customer organization has a provider-level access grant.
881
+ * active customer organization has a provider-level access grant.
683
882
  *
684
883
  * This is intentionally provider-level only. It does not alter auth mode,
685
884
  * operation schemas, health-check authoring, `openWorld`, or Connection
@@ -810,6 +1009,11 @@ export interface HttpRetrySummary {
810
1009
  export interface RequestOptions {
811
1010
  headers?: Record<string, string>;
812
1011
  params?: RequestParams;
1012
+ /**
1013
+ * Query parameters whose values contain credentials or other secret material.
1014
+ * They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
1015
+ */
1016
+ sensitiveParams?: Record<string, string>;
813
1017
  proxy?: string;
814
1018
  timeout?: number;
815
1019
  /**
@@ -818,12 +1022,33 @@ export interface RequestOptions {
818
1022
  */
819
1023
  throwOnHttpError?: boolean;
820
1024
  retry?: boolean | HttpRetryPreset | HttpRetryOptions;
1025
+ /**
1026
+ * Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
1027
+ * evaluated before the next request is issued. Existing callers that omit
1028
+ * this policy retain the native fetch redirect behavior.
1029
+ */
1030
+ redirectPolicy?: HttpRedirectPolicy;
1031
+ }
1032
+ export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1033
+ export type HttpRedirectPolicyMode = "same-origin";
1034
+ export interface HttpRedirectPolicy {
1035
+ /** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
1036
+ mode: HttpRedirectPolicyMode;
1037
+ /** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
1038
+ maxHops: number;
821
1039
  }
1040
+ export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
822
1041
  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 {
1042
+ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy"> {
824
1043
  method?: HttpMethod;
825
1044
  body?: string | Buffer;
826
1045
  redirect?: "follow" | "manual" | "error";
1046
+ /**
1047
+ * Maximum decoded response-body bytes to buffer. When set, the stealth
1048
+ * transport aborts the response and throws `response_too_large` if the
1049
+ * declared or streamed body exceeds this limit.
1050
+ */
1051
+ maxBodyBytes?: number;
827
1052
  /**
828
1053
  * Offsets policy-managed proxy pool selection for caller-managed retries.
829
1054
  * Use when a request receives an upstream challenge page rather than a
@@ -843,17 +1068,42 @@ export interface StealthFetchOptions extends RequestOptions {
843
1068
  };
844
1069
  }
845
1070
  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;
1071
+ /** URL-less reads use the jar's response URL or session base URL. */
1072
+ get(name: string, url?: string): string | undefined;
1073
+ getAll(url?: string): Record<string, string>;
1074
+ toString(url?: string): string;
1075
+ find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
850
1076
  }
1077
+ /**
1078
+ * Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
1079
+ * The nested jar is tough-cookie's serialized form and retains cookie origin,
1080
+ * Path, Secure, expiry, host-only, and other RFC attributes.
1081
+ */
1082
+ export interface StealthCookieStoreV1 {
1083
+ readonly version: 1;
1084
+ readonly jar: SerializedCookieJar;
1085
+ }
1086
+ /** Cookie persistence formats understood by this SDK version. */
1087
+ export type StealthCookieStore = StealthCookieStoreV1;
851
1088
  export interface StealthSessionCookies extends CookieJar {
852
- has(name: string): boolean;
853
- setFromCookieStrings(cookieStrings: readonly string[]): void;
854
- toHeader(): string;
1089
+ has(name: string, url?: string): boolean;
1090
+ /** URL-less writes are scoped to the session base URL. */
1091
+ setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
1092
+ toHeader(url?: string): string;
1093
+ /**
1094
+ * Returns every cookie as a flat name/value map, collapsing duplicate names.
1095
+ * @deprecated Use serialize() for lossless, attribute-preserving persistence.
1096
+ */
855
1097
  snapshot(): Record<string, string>;
1098
+ /**
1099
+ * Restores flat values as host-only, Path=/ cookies on the session base URL.
1100
+ * @deprecated Use deserialize() with state produced by serialize().
1101
+ */
856
1102
  restore(cookies: Record<string, string>): void;
1103
+ /** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
1104
+ serialize(): StealthCookieStoreV1;
1105
+ /** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
1106
+ deserialize(state: StealthCookieStore): void;
857
1107
  clear(): void;
858
1108
  }
859
1109
  export interface DeclarativeStealthResponse {
@@ -895,8 +1145,14 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
895
1145
  export interface StealthRedirectRunResult {
896
1146
  final: StealthResponse;
897
1147
  hops: StealthRedirectHop[];
898
- reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
1148
+ reason: RedirectRunReason;
1149
+ /**
1150
+ * Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
1151
+ * @deprecated Use cookieStore for lossless persistence.
1152
+ */
899
1153
  cookies: Record<string, string>;
1154
+ /** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
1155
+ cookieStore: StealthCookieStoreV1;
900
1156
  }
901
1157
  export interface StealthSession {
902
1158
  fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
@@ -959,11 +1215,159 @@ export interface HttpClient {
959
1215
  stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
960
1216
  sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
961
1217
  }
1218
+ /** Request-scoped file reference accepted by provider operation inputs. */
1219
+ export interface ProviderFileRef {
1220
+ readonly type: "request_file";
1221
+ readonly id: string;
1222
+ readonly filename: string;
1223
+ readonly mime_type?: string;
1224
+ readonly size: number;
1225
+ readonly sha256?: string;
1226
+ }
1227
+ /** File body resolved from a request-scoped {@link ProviderFileRef}. */
1228
+ export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
1229
+ readonly mimeType?: string;
1230
+ arrayBuffer(): Promise<ArrayBuffer>;
1231
+ bytes(): Promise<Uint8Array>;
1232
+ stream(): ReadableStream<Uint8Array>;
1233
+ };
1234
+ /** Resolver supplied by runtimes that accept request-scoped file inputs. */
1235
+ export interface ProviderFilesContext {
1236
+ has(input: string | ProviderFileRef): boolean;
1237
+ resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
1238
+ }
1239
+ export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
1240
+ export interface NativeTcpPortRange {
1241
+ readonly start: number;
1242
+ readonly end: number;
1243
+ }
1244
+ /** Static native TCP egress declared by a provider. */
1245
+ export interface NativeTcpEgressRule {
1246
+ readonly host: string;
1247
+ readonly ports: readonly number[];
1248
+ readonly tls: NativeTcpTlsMode;
1249
+ }
1250
+ /**
1251
+ * Bounded native TCP egress discovered through a declared bootstrap endpoint.
1252
+ * Host suffixes are exact DNS suffixes, not wildcard patterns.
1253
+ * Dynamic rules must declare at least one target host selector through
1254
+ * targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
1255
+ * sources and targets match only same-family selectors (except exact
1256
+ * sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
1257
+ * IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
1258
+ *
1259
+ * Dynamic rules are ordered. The first rule whose source, target, port, and TLS
1260
+ * selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
1261
+ * apply, and an exhausted/shorter rule never falls through to a later overlap.
1262
+ * Every rule must declare a source host selector, source port list/range, and
1263
+ * target port list/range; omitted ttlMs/maxGrants remain unbounded.
1264
+ */
1265
+ export interface NativeTcpDynamicEgressRule {
1266
+ readonly sourceHost?: string;
1267
+ readonly sourceHostSuffixes?: readonly string[];
1268
+ readonly sourceIpv4Cidrs?: readonly string[];
1269
+ readonly sourceIpv6Cidrs?: readonly string[];
1270
+ readonly sourcePorts?: readonly number[];
1271
+ readonly sourcePortRanges?: readonly NativeTcpPortRange[];
1272
+ readonly targetHostSuffixes?: readonly string[];
1273
+ readonly targetIpv4Cidrs?: readonly string[];
1274
+ readonly targetIpv6Cidrs?: readonly string[];
1275
+ readonly targetPorts?: readonly number[];
1276
+ readonly targetPortRanges?: readonly NativeTcpPortRange[];
1277
+ readonly tls: NativeTcpTlsMode;
1278
+ readonly ttlMs?: number;
1279
+ readonly maxGrants?: number;
1280
+ }
1281
+ /** Common TCP/TLS connection input supported by the native runtime. */
1282
+ export interface NativeNetworkConnectInput {
1283
+ readonly host: string;
1284
+ readonly port: number;
1285
+ readonly serverName?: string;
1286
+ readonly rejectUnauthorized?: boolean;
1287
+ /**
1288
+ * Maximum time without a successful socket read before the connection is
1289
+ * closed. Opt-in; when absent, reads can remain pending indefinitely.
1290
+ */
1291
+ readonly idleTimeoutMs?: number;
1292
+ /** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
1293
+ readonly timeoutMs?: number;
1294
+ readonly signal?: AbortSignal;
1295
+ /** Overrides the credential-derived sticky affinity key. */
1296
+ readonly affinityKey?: string;
1297
+ }
1298
+ export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
1299
+ export type NativeTlsConnectOptions = NativeNetworkConnectInput;
1300
+ export interface NativeNetworkDynamicGrantOptions {
1301
+ readonly sourceHost: string;
1302
+ readonly sourcePort: number;
1303
+ readonly host: string;
1304
+ readonly port: number;
1305
+ readonly tls: NativeTcpTlsMode;
1306
+ readonly ttlMs?: number;
1307
+ }
1308
+ export interface NativeNetworkEgressGrant {
1309
+ revoke(): void;
1310
+ }
1311
+ /** Consumer-facing alias used by native TCP providers. */
1312
+ export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
1313
+ /** Resolved egress identity for a native connection routed through a proxy. */
1314
+ export interface NativeProxyEgressInfo {
1315
+ readonly vendor: ProviderProxyProvider;
1316
+ readonly sticky: boolean;
1317
+ /** Vendor sticky session id (sid). Absent for rotating sessions. */
1318
+ readonly sessionId?: string;
1319
+ /** Hard expiry of the sticky binding, ISO 8601. */
1320
+ readonly expiresAt?: string;
1321
+ }
1322
+ export type NativeProxyExpiringReason = "sticky_expiry";
1323
+ export interface NativeProxyExpiringEvent {
1324
+ readonly expiresAt: string;
1325
+ readonly leadSeconds: number;
1326
+ readonly reason: NativeProxyExpiringReason;
1327
+ }
1328
+ /**
1329
+ * Cooperative drain handler. The SDK awaits this before closing a socket whose
1330
+ * sticky proxy binding is about to expire, then force-closes at hard expiry.
1331
+ */
1332
+ export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
1333
+ /** Typed reason recorded when the SDK closes a native connection intentionally. */
1334
+ export interface NativeNetworkCloseReason {
1335
+ readonly code: string;
1336
+ readonly message: string;
1337
+ }
1338
+ /** Byte-oriented connection returned by the native TCP/TLS runtime. */
1339
+ export interface NativeNetworkConnection {
1340
+ /** Present when the connection was routed through a proxy. */
1341
+ readonly proxy?: NativeProxyEgressInfo;
1342
+ /** Present after an SDK-planned close, such as sticky proxy expiry. */
1343
+ readonly closeReason?: NativeNetworkCloseReason;
1344
+ /** Register a cooperative drain handler for sticky-expiry reconnects. */
1345
+ onExpiring?(handler: NativeProxyDrainHandler): void;
1346
+ read(): Promise<Uint8Array | null>;
1347
+ write(data: Uint8Array): Promise<void>;
1348
+ close(): Promise<void>;
1349
+ }
1350
+ export interface NativeNetworkClient {
1351
+ connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
1352
+ connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
1353
+ grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
1354
+ }
1355
+ export interface NativeContext {
1356
+ readonly network: NativeNetworkClient;
1357
+ }
1358
+ /** Consumer-facing alias for the native capability on provider contexts. */
1359
+ export type NativeProviderContext = NativeContext;
1360
+ export interface NativeProviderConfig {
1361
+ readonly network?: {
1362
+ readonly tcp?: readonly NativeTcpEgressRule[];
1363
+ readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
1364
+ };
1365
+ }
962
1366
  export interface ProviderCacheKeyOptions {
963
1367
  /**
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.
1368
+ * Additional field names whose values are hashed in stable key material. The
1369
+ * SDK always hashes values under known secret-bearing names such as serviceKey,
1370
+ * authorization, cookie, token, password, and secret.
967
1371
  */
968
1372
  redactFields?: string[];
969
1373
  }
@@ -1036,6 +1440,17 @@ export interface BrowserFrame {
1036
1440
  evaluate<T>(fn: string | (() => T)): Promise<T>;
1037
1441
  locator(selector: string): BrowserLocator;
1038
1442
  }
1443
+ export interface BrowserCookie {
1444
+ readonly name: string;
1445
+ readonly value: string;
1446
+ readonly domain: string;
1447
+ readonly path: string;
1448
+ /** Unix seconds. Absent for a session cookie. */
1449
+ readonly expires?: number;
1450
+ readonly httpOnly: boolean;
1451
+ readonly secure: boolean;
1452
+ readonly sameSite?: "Strict" | "Lax" | "None";
1453
+ }
1039
1454
  export type BrowserResourceMethod = "GET" | "HEAD";
1040
1455
  export type BrowserResourceRequest = {
1041
1456
  readonly url: string;
@@ -1064,6 +1479,11 @@ export type BrowserResourcePolicy = {
1064
1479
  };
1065
1480
  export interface BrowserPage extends BrowserFrame {
1066
1481
  close(): Promise<void>;
1482
+ /**
1483
+ * Reads the browser context's cookie jar, including httpOnly cookies.
1484
+ * Cookie expiry values are Unix seconds and are absent for session cookies.
1485
+ */
1486
+ cookies(): Promise<readonly BrowserCookie[]>;
1067
1487
  fill(selector: string, text: string): Promise<void>;
1068
1488
  goto(url: string): Promise<void>;
1069
1489
  pageId?: string;
@@ -1138,6 +1558,26 @@ export interface ProviderChoiceBindingOptions {
1138
1558
  connection?: boolean;
1139
1559
  credentialKeys?: readonly string[];
1140
1560
  }
1561
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1562
+ export type ProviderChoiceConsumeResult = {
1563
+ readonly status: "consumed";
1564
+ } | {
1565
+ readonly status: "already-consumed";
1566
+ } | {
1567
+ readonly status: "unsupported";
1568
+ };
1569
+ export type ProviderChoiceExplicitParseResult = {
1570
+ readonly status: "active";
1571
+ readonly payload: Record<string, unknown>;
1572
+ /** Stable, opaque key for provider-owned idempotency records. */
1573
+ readonly replayKey: string;
1574
+ /** Atomically claims a word token. Legacy managed tokens report unsupported. */
1575
+ consume(): Promise<ProviderChoiceConsumeResult>;
1576
+ } | {
1577
+ readonly status: "consumed";
1578
+ /** Use this key to read the provider-owned result before returning an error. */
1579
+ readonly replayKey: string;
1580
+ };
1141
1581
  export type ProviderChoiceStorageOptions = {
1142
1582
  readonly mode: "inline";
1143
1583
  } | {
@@ -1165,6 +1605,8 @@ export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unkn
1165
1605
  ttlMs: number;
1166
1606
  nowMs?: number;
1167
1607
  bind?: ProviderChoiceBindingOptions;
1608
+ /** Server storage only: standard emits four words; high emits five. */
1609
+ strength?: "standard" | "high";
1168
1610
  storage?: ProviderChoiceStorageOptions;
1169
1611
  }
1170
1612
  export interface ProviderChoiceParseOptions {
@@ -1176,6 +1618,8 @@ export interface ProviderChoiceParseOptions {
1176
1618
  futureToleranceMs?: number;
1177
1619
  bind?: ProviderChoiceBindingOptions;
1178
1620
  storage?: ProviderChoiceStorageOptions;
1621
+ /** Defaults to never, matching legacy managed-token parse semantics. */
1622
+ consume?: ProviderChoiceConsumeMode;
1179
1623
  }
1180
1624
  export interface ProviderChoiceContext {
1181
1625
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
@@ -1194,6 +1638,9 @@ export interface ProviderChoiceContext {
1194
1638
  }>;
1195
1639
  }): string | Promise<string>;
1196
1640
  issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1641
+ parse(options: ProviderChoiceParseOptions & {
1642
+ readonly consume: "explicit";
1643
+ }): Promise<ProviderChoiceExplicitParseResult>;
1197
1644
  parse(options: ProviderChoiceParseOptions & {
1198
1645
  readonly storage?: {
1199
1646
  readonly mode: "inline";
@@ -1209,7 +1656,7 @@ export interface ProviderChoiceContext {
1209
1656
  readonly mode: "auto";
1210
1657
  }>;
1211
1658
  }): Record<string, unknown> | Promise<Record<string, unknown>>;
1212
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1659
+ parse(options: ProviderChoiceParseOptions): Record<string, unknown> | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1213
1660
  }
1214
1661
  export interface ContextScratchpad {
1215
1662
  get(key: string): unknown;
@@ -1285,16 +1732,22 @@ export interface AuthFlowTerminalContext {
1285
1732
  }): AuthTurn;
1286
1733
  }
1287
1734
  export interface FlowContext {
1735
+ /** Gateway auth-flow id. Required by flow-scoped auth ceremonies. */
1736
+ flowId?: string;
1288
1737
  connectionId?: string;
1289
1738
  externalRef?: string;
1290
1739
  tenantId: string;
1291
1740
  providerId: string;
1292
1741
  http: HttpClient;
1742
+ /** Present when the selected runtime supplies native network capabilities. */
1743
+ readonly native?: NativeProviderContext;
1293
1744
  stealth: StealthClient;
1294
1745
  env: EnvContext;
1295
1746
  credential?: CredentialContext;
1296
1747
  context: ContextScratchpad;
1748
+ ocr: OcrContext;
1297
1749
  stt: SttContext;
1750
+ resolver: ResolverContext;
1298
1751
  auth: AuthFlowTerminalContext;
1299
1752
  }
1300
1753
  export interface AuthTurn {
@@ -1326,7 +1779,13 @@ export interface AuthFlowDefinition {
1326
1779
  refresh?: AuthFlowInputHandler;
1327
1780
  }
1328
1781
  export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1782
+ export type StateNamespaceScope = "connection" | "provider";
1329
1783
  export interface StateNamespaceOptions {
1784
+ /**
1785
+ * State isolation boundary. Connection scope is the default; provider scope
1786
+ * must be selected explicitly for provider-wide coordination state.
1787
+ */
1788
+ scope?: StateNamespaceScope;
1330
1789
  /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1331
1790
  defaultTtl: ProviderStateDurationString;
1332
1791
  /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
@@ -1368,6 +1827,11 @@ export interface ProviderStateNamespace {
1368
1827
  increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1369
1828
  }
1370
1829
  export interface ProviderRuntimeState {
1830
+ /**
1831
+ * Returns an immutable view bound to one request connection. An unresolved
1832
+ * connection uses an isolated reserved sentinel, never the provider-global scope.
1833
+ */
1834
+ forConnection(connectionId: string | undefined): ProviderRuntimeState;
1371
1835
  namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1372
1836
  }
1373
1837
  export interface ProviderContext {
@@ -1375,17 +1839,35 @@ export interface ProviderContext {
1375
1839
  credential: CredentialContext;
1376
1840
  request?: ProviderRequestContext;
1377
1841
  http: HttpClient;
1842
+ /** Present for requests carrying runtime-resolvable file references. */
1843
+ readonly files?: ProviderFilesContext;
1844
+ /** Present when the selected runtime supplies native network capabilities. */
1845
+ readonly native?: NativeProviderContext;
1378
1846
  cache: ProviderCache;
1379
1847
  state: ProviderRuntimeState;
1380
1848
  stealth: StealthClient;
1381
1849
  browser: BrowserClient;
1382
1850
  trace: TraceContext;
1383
1851
  auth: AuthContext;
1852
+ ocr: OcrContext;
1384
1853
  stt: SttContext;
1854
+ resolver: ResolverContext;
1385
1855
  choice: ProviderChoiceContext;
1386
1856
  }
1857
+ export interface ProxiedOAuthConfig {
1858
+ authorizeUrl: string;
1859
+ tokenUrl: string;
1860
+ customScheme: string;
1861
+ rewriteProfile: string;
1862
+ clientIdEnvKey: string;
1863
+ pkce?: "S256" | "none";
1864
+ authorizeParams?: Record<string, string>;
1865
+ tokenParams?: Record<string, string>;
1866
+ }
1387
1867
  export interface AuthConfig {
1388
1868
  mode: AuthMode;
1869
+ /** Browser reverse-proxy contract for providers with custom-scheme OAuth callbacks. */
1870
+ proxied?: ProxiedOAuthConfig;
1389
1871
  flow?: AuthFlowDefinition;
1390
1872
  }
1391
1873
  export interface ProviderSecretDeclaration {
@@ -1418,6 +1900,19 @@ export interface OperationContractMetadata {
1418
1900
  deprecation?: OperationDeprecationMetadata;
1419
1901
  }
1420
1902
  export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
1903
+ /**
1904
+ * Short English display title for the operation. The SDK passes it through
1905
+ * verbatim; the APIFuse registry derives the operation's en locale title
1906
+ * baseline from it (`docs.titleKey` remains available as an explicit key
1907
+ * override).
1908
+ */
1909
+ title?: string;
1910
+ /**
1911
+ * Raw English operation description. The SDK passes it through verbatim;
1912
+ * keyed descriptions via `descriptionKey` remain the primary flow, and
1913
+ * provider lint rules for raw prose descriptions still apply.
1914
+ */
1915
+ description?: string;
1421
1916
  descriptionKey?: ProviderLocaleKeyInput;
1422
1917
  docs?: OperationDocMeta;
1423
1918
  whenToUseKeys?: readonly ProviderLocaleKeyInput[];
@@ -1438,6 +1933,11 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
1438
1933
  fixtures?: {
1439
1934
  request: InferSchemaOutput<TInput>;
1440
1935
  response: InferSchemaOutput<TOutput>;
1936
+ /**
1937
+ * KST calendar date when `response` evidence was captured. Date fields in
1938
+ * the response align with this date, not a resolved relative request date.
1939
+ */
1940
+ recordedAt?: string;
1441
1941
  };
1442
1942
  upstream?: {
1443
1943
  baseUrl?: string;
@@ -1447,17 +1947,64 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
1447
1947
  healthCheck?: HealthCheckSuite<InferSchemaOutput<TInput>, InferSchemaOutput<TOutput>>;
1448
1948
  healthCheckUnsupported?: HealthCheckUnsupported;
1449
1949
  }
1950
+ /**
1951
+ * Author-declared deployment overrides accepted as the optional top-level
1952
+ * `deployment` key on `defineProvider()`.
1953
+ *
1954
+ * The SDK passes this object through VERBATIM onto the returned provider
1955
+ * definition — it is typed here but deliberately not deep-validated: the
1956
+ * APIFuse registry builder owns deployment validation and resolves omitted
1957
+ * fields against the runtime deployment profiles. The shape mirrors the
1958
+ * registry's `ProviderDeploymentOverrides` contract; every field is
1959
+ * optional. Note that the deployment `runtime` axis
1960
+ * (`shared`/`dedicated`/`browser`) is distinct from the provider execution
1961
+ * `runtime` (`standard`/`shared`/`browser`).
1962
+ */
1963
+ export interface ProviderDeploymentOverrides {
1964
+ runtime?: "shared" | "dedicated" | "browser";
1965
+ language?: "typescript" | "python";
1966
+ replicas?: number;
1967
+ hpa?: {
1968
+ enabled: boolean;
1969
+ minReplicas?: number;
1970
+ maxReplicas?: number;
1971
+ targetCPUUtilizationPercentage?: number;
1972
+ };
1973
+ resources?: {
1974
+ cpu: string;
1975
+ memory: string;
1976
+ };
1977
+ cache?: {
1978
+ redis?: {
1979
+ enabled: boolean;
1980
+ url?: string;
1981
+ };
1982
+ };
1983
+ network?: {
1984
+ additionalTcpPorts?: number[];
1985
+ };
1986
+ buildContext?: string;
1987
+ }
1450
1988
  export interface ProviderDefinition {
1451
1989
  id: string;
1452
1990
  version: string;
1453
1991
  runtime: "standard" | "shared" | "browser";
1992
+ /**
1993
+ * Optional deployment overrides, passed through verbatim from
1994
+ * `defineProvider({ deployment })`. Validation and profile resolution are
1995
+ * owned by the APIFuse registry builder, not the SDK.
1996
+ */
1997
+ deployment?: ProviderDeploymentOverrides;
1454
1998
  allowedHosts?: string[];
1999
+ native?: NativeProviderConfig;
1455
2000
  stealth?: {
1456
2001
  profile: string;
1457
2002
  platform: StealthPlatform;
1458
2003
  };
1459
2004
  proxy?: ProviderProxyConfig;
2005
+ ocr?: ProviderOcrConfig;
1460
2006
  stt?: ProviderSttConfig;
2007
+ resolver?: ProviderResolverConfig;
1461
2008
  browser?: {
1462
2009
  engine: BrowserEngine;
1463
2010
  };