@apifuse/provider-sdk 2.1.0-beta.2 → 2.1.0-beta.21

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 (231) hide show
  1. package/AUTHORING.md +330 -8
  2. package/CHANGELOG.md +89 -1
  3. package/README.md +64 -17
  4. package/SUBMISSION.md +86 -0
  5. package/bin/apifuse-check.ts +60 -6
  6. package/bin/apifuse-dev.ts +58 -8
  7. package/bin/apifuse-pack-check.ts +32 -2
  8. package/bin/apifuse-pack-smoke.ts +133 -6
  9. package/bin/apifuse-perf.ts +142 -49
  10. package/bin/apifuse-record.ts +182 -104
  11. package/bin/apifuse-submit-check.ts +3243 -0
  12. package/bin/apifuse.ts +1 -1
  13. package/dist/auth.d.ts +76 -0
  14. package/dist/auth.js +436 -0
  15. package/dist/ceremonies/index.d.ts +41 -0
  16. package/dist/ceremonies/index.js +490 -0
  17. package/dist/choice-token.d.ts +24 -0
  18. package/dist/choice-token.js +74 -0
  19. package/dist/cli/commands.d.ts +10 -0
  20. package/dist/cli/commands.js +80 -0
  21. package/dist/cli/create.d.ts +47 -0
  22. package/dist/cli/create.js +777 -0
  23. package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
  24. package/dist/cli/templates/provider/.gitignore.tpl +22 -0
  25. package/dist/cli/templates/provider/AGENTS.md.tpl +87 -0
  26. package/dist/cli/templates/provider/CLAUDE.md.tpl +1 -0
  27. package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
  28. package/dist/cli/templates/provider/README.md.tpl +163 -0
  29. package/dist/cli/templates/provider/dev.ts.tpl +5 -0
  30. package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
  31. package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
  32. package/dist/cli/templates/provider/index.ts.tpl +15 -0
  33. package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
  34. package/dist/cli/templates/provider/meta.ts.tpl +7 -0
  35. package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
  36. package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
  37. package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  38. package/dist/cli/templates/provider/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  39. package/dist/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  40. package/dist/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
  41. package/dist/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  42. package/dist/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  43. package/dist/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
  44. package/dist/cli/templates/provider/start.ts.tpl +5 -0
  45. package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
  46. package/dist/config/loader.d.ts +107 -0
  47. package/dist/config/loader.js +935 -0
  48. package/dist/contract-json.d.ts +9 -0
  49. package/dist/contract-json.js +51 -0
  50. package/dist/contract-serialization.d.ts +4 -0
  51. package/dist/contract-serialization.js +78 -0
  52. package/dist/contract-types.d.ts +49 -0
  53. package/dist/contract-types.js +1 -0
  54. package/dist/contract.d.ts +6 -0
  55. package/dist/contract.js +156 -0
  56. package/dist/define.d.ts +100 -0
  57. package/dist/define.js +1383 -0
  58. package/dist/dev.d.ts +9 -0
  59. package/dist/dev.js +15 -0
  60. package/dist/errors.d.ts +59 -0
  61. package/dist/errors.js +97 -0
  62. package/dist/i18n/catalog.d.ts +29 -0
  63. package/dist/i18n/catalog.js +159 -0
  64. package/dist/i18n/index.d.ts +2 -0
  65. package/dist/i18n/index.js +2 -0
  66. package/dist/i18n/keys.d.ts +10 -0
  67. package/dist/i18n/keys.js +34 -0
  68. package/dist/index.d.ts +42 -0
  69. package/dist/index.js +38 -0
  70. package/dist/lint.d.ts +74 -0
  71. package/dist/lint.js +729 -0
  72. package/dist/observability.d.ts +5 -0
  73. package/dist/observability.js +39 -0
  74. package/dist/provider.d.ts +11 -0
  75. package/dist/provider.js +9 -0
  76. package/dist/public-schema-field-lint.d.ts +2 -0
  77. package/dist/public-schema-field-lint.js +158 -0
  78. package/dist/recipes/gov-api.d.ts +19 -0
  79. package/dist/recipes/gov-api.js +72 -0
  80. package/dist/recipes/rest-api.d.ts +21 -0
  81. package/dist/recipes/rest-api.js +115 -0
  82. package/dist/runtime/auth-flow.d.ts +14 -0
  83. package/dist/runtime/auth-flow.js +46 -0
  84. package/dist/runtime/browser.d.ts +25 -0
  85. package/dist/runtime/browser.js +1237 -0
  86. package/dist/runtime/cache.d.ts +10 -0
  87. package/dist/runtime/cache.js +372 -0
  88. package/dist/runtime/choice.d.ts +15 -0
  89. package/dist/runtime/choice.js +435 -0
  90. package/dist/runtime/credential.d.ts +8 -0
  91. package/dist/runtime/credential.js +61 -0
  92. package/dist/runtime/env.d.ts +2 -0
  93. package/dist/runtime/env.js +10 -0
  94. package/dist/runtime/executor.d.ts +16 -0
  95. package/dist/runtime/executor.js +51 -0
  96. package/dist/runtime/http.d.ts +8 -0
  97. package/dist/runtime/http.js +726 -0
  98. package/dist/runtime/insights.d.ts +9 -0
  99. package/dist/runtime/insights.js +324 -0
  100. package/dist/runtime/instrumentation.d.ts +8 -0
  101. package/dist/runtime/instrumentation.js +269 -0
  102. package/dist/runtime/key-derivation.d.ts +24 -0
  103. package/dist/runtime/key-derivation.js +73 -0
  104. package/dist/runtime/keyring.d.ts +25 -0
  105. package/dist/runtime/keyring.js +93 -0
  106. package/dist/runtime/namespace.d.ts +9 -0
  107. package/dist/runtime/namespace.js +19 -0
  108. package/dist/runtime/otlp.d.ts +39 -0
  109. package/dist/runtime/otlp.js +103 -0
  110. package/dist/runtime/perf.d.ts +12 -0
  111. package/dist/runtime/perf.js +52 -0
  112. package/dist/runtime/prevalidate.d.ts +12 -0
  113. package/dist/runtime/prevalidate.js +173 -0
  114. package/dist/runtime/provider.d.ts +2 -0
  115. package/dist/runtime/provider.js +11 -0
  116. package/dist/runtime/proxy-errors.d.ts +21 -0
  117. package/dist/runtime/proxy-errors.js +83 -0
  118. package/dist/runtime/proxy-telemetry.d.ts +8 -0
  119. package/dist/runtime/proxy-telemetry.js +174 -0
  120. package/dist/runtime/redis.d.ts +17 -0
  121. package/dist/runtime/redis.js +82 -0
  122. package/dist/runtime/request-options.d.ts +3 -0
  123. package/dist/runtime/request-options.js +42 -0
  124. package/dist/runtime/state.d.ts +17 -0
  125. package/dist/runtime/state.js +344 -0
  126. package/dist/runtime/stealth.d.ts +21 -0
  127. package/dist/runtime/stealth.js +980 -0
  128. package/dist/runtime/stt.d.ts +22 -0
  129. package/dist/runtime/stt.js +480 -0
  130. package/dist/runtime/trace.d.ts +26 -0
  131. package/dist/runtime/trace.js +142 -0
  132. package/dist/runtime/waterfall.d.ts +12 -0
  133. package/dist/runtime/waterfall.js +147 -0
  134. package/dist/schema.d.ts +74 -0
  135. package/dist/schema.js +243 -0
  136. package/dist/serve.d.ts +1 -0
  137. package/dist/serve.js +1 -0
  138. package/dist/server/index.d.ts +3 -0
  139. package/dist/server/index.js +2 -0
  140. package/dist/server/serve.d.ts +64 -0
  141. package/dist/server/serve.js +1118 -0
  142. package/dist/server/types.d.ts +136 -0
  143. package/dist/server/types.js +86 -0
  144. package/dist/stealth/profiles.d.ts +4 -0
  145. package/dist/stealth/profiles.js +259 -0
  146. package/dist/stream.d.ts +44 -0
  147. package/dist/stream.js +151 -0
  148. package/dist/testing/helpers.d.ts +23 -0
  149. package/dist/testing/helpers.js +95 -0
  150. package/dist/testing/index.d.ts +2 -0
  151. package/dist/testing/index.js +2 -0
  152. package/dist/testing/run.d.ts +34 -0
  153. package/dist/testing/run.js +307 -0
  154. package/dist/types.d.ts +1467 -0
  155. package/dist/types.js +61 -0
  156. package/dist/utils/date.d.ts +6 -0
  157. package/dist/utils/date.js +101 -0
  158. package/dist/utils/parse.d.ts +16 -0
  159. package/dist/utils/parse.js +51 -0
  160. package/dist/utils/text.d.ts +4 -0
  161. package/dist/utils/text.js +14 -0
  162. package/dist/utils/transform.d.ts +8 -0
  163. package/dist/utils/transform.js +48 -0
  164. package/package.json +57 -29
  165. package/src/auth.ts +786 -0
  166. package/src/ceremonies/index.ts +8 -2
  167. package/src/choice-token.ts +165 -0
  168. package/src/cli/commands.ts +34 -11
  169. package/src/cli/create.ts +254 -128
  170. package/src/cli/templates/provider/.dockerignore.tpl +22 -0
  171. package/src/cli/templates/provider/.gitignore.tpl +22 -0
  172. package/src/cli/templates/provider/AGENTS.md.tpl +87 -0
  173. package/src/cli/templates/provider/CLAUDE.md.tpl +1 -0
  174. package/src/cli/templates/provider/README.md.tpl +87 -7
  175. package/src/cli/templates/provider/dev.ts.tpl +1 -1
  176. package/src/cli/templates/provider/domain/README.md.tpl +3 -0
  177. package/src/cli/templates/provider/index.ts.tpl +5 -47
  178. package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
  179. package/src/cli/templates/provider/meta.ts.tpl +7 -0
  180. package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
  181. package/src/cli/templates/provider/operations/ping.ts.tpl +24 -0
  182. package/src/cli/templates/provider/schemas/ping.ts.tpl +24 -0
  183. package/src/cli/templates/provider/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
  184. package/src/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
  185. package/src/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
  186. package/src/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
  187. package/src/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
  188. package/src/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
  189. package/src/cli/templates/provider/start.ts.tpl +1 -1
  190. package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
  191. package/src/config/loader.ts +1224 -9
  192. package/src/contract-json.ts +75 -0
  193. package/src/contract-serialization.ts +89 -0
  194. package/src/contract-types.ts +52 -0
  195. package/src/contract.ts +216 -0
  196. package/src/define.ts +1820 -70
  197. package/src/errors.ts +27 -0
  198. package/src/i18n/catalog.ts +277 -0
  199. package/src/i18n/index.ts +2 -0
  200. package/src/i18n/keys.ts +64 -0
  201. package/src/index.ts +189 -9
  202. package/src/lint.ts +580 -73
  203. package/src/observability.ts +41 -0
  204. package/src/provider.ts +131 -4
  205. package/src/public-schema-field-lint.ts +237 -0
  206. package/src/runtime/auth-flow.ts +9 -0
  207. package/src/runtime/browser.ts +1054 -51
  208. package/src/runtime/cache.ts +528 -0
  209. package/src/runtime/choice.ts +760 -0
  210. package/src/runtime/executor.ts +32 -3
  211. package/src/runtime/http.ts +980 -195
  212. package/src/runtime/insights.ts +11 -11
  213. package/src/runtime/instrumentation.ts +12 -4
  214. package/src/runtime/key-derivation.ts +1 -1
  215. package/src/runtime/keyring.ts +4 -3
  216. package/src/runtime/proxy-errors.ts +132 -0
  217. package/src/runtime/proxy-telemetry.ts +253 -0
  218. package/src/runtime/redis.ts +116 -0
  219. package/src/runtime/request-options.ts +66 -0
  220. package/src/runtime/state.ts +563 -0
  221. package/src/runtime/stealth.ts +1336 -0
  222. package/src/runtime/stt.ts +629 -0
  223. package/src/runtime/trace.ts +1 -1
  224. package/src/schema.ts +363 -1
  225. package/src/server/serve.ts +1192 -75
  226. package/src/server/types.ts +37 -0
  227. package/src/stream.ts +210 -0
  228. package/src/testing/run.ts +40 -6
  229. package/src/types.ts +1283 -59
  230. package/src/runtime/tls.ts +0 -434
  231. package/src/types/playwright-stealth.d.ts +0 -9
@@ -0,0 +1,1467 @@
1
+ import type ms from "ms";
2
+ import type { infer as ZodInfer, ZodType } from "zod";
3
+ /** Minimal Standard Schema v1 shape accepted by provider operations. */
4
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
5
+ readonly "~standard": {
6
+ readonly version: 1;
7
+ readonly vendor: string;
8
+ readonly validate: (value: unknown) => StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>>;
9
+ readonly types?: {
10
+ readonly input: Input;
11
+ readonly output: Output;
12
+ };
13
+ };
14
+ }
15
+ export declare namespace StandardSchemaV1 {
16
+ interface Issue {
17
+ readonly message: string;
18
+ readonly path?: readonly (PropertyKey | PathSegment)[];
19
+ }
20
+ interface PathSegment {
21
+ readonly key: PropertyKey;
22
+ }
23
+ interface SuccessResult<Output> {
24
+ readonly value: Output;
25
+ }
26
+ interface FailureResult {
27
+ readonly issues: readonly Issue[];
28
+ }
29
+ type Result<Output> = SuccessResult<Output> | FailureResult;
30
+ }
31
+ /** Schema formats supported by provider operations. */
32
+ export type SchemaLike = ZodType | StandardSchemaV1;
33
+ /** Infer the validated output type produced by a Zod or Standard Schema. */
34
+ export type InferSchemaOutput<TSchema extends SchemaLike> = TSchema extends ZodType ? ZodInfer<TSchema> : TSchema extends StandardSchemaV1<unknown, infer Output> ? Output : unknown;
35
+ export interface OperationInputExample {
36
+ scenario: string;
37
+ input: unknown;
38
+ rationale?: string;
39
+ }
40
+ export type OperationRiskClass = "read" | "write" | "destructive" | "external-send";
41
+ export type OperationApprovalPolicy = "never" | "risk-based" | "always";
42
+ export interface OperationToolRouterMetadata {
43
+ /** Optional MCP-safe override. Defaults to providerId__operationId. */
44
+ name?: string;
45
+ /** Safety class exposed to Tool Router clients and approval policy. */
46
+ riskClass?: OperationRiskClass;
47
+ /** OpenAI remote-MCP approval hint. Defaults from riskClass. */
48
+ approval?: OperationApprovalPolicy;
49
+ /** Override connection requirement when provider auth + openWorld inference is insufficient. */
50
+ requiresConnection?: boolean;
51
+ /** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
52
+ connectionExternalRefParam?: string;
53
+ }
54
+ export type OperationSensitivePath = string;
55
+ export interface OperationObservabilitySensitiveConfig {
56
+ /**
57
+ * Additional dot paths to redact from captured invocation inputs. Use `*`
58
+ * for array elements, for example `items.*.phone`.
59
+ */
60
+ input?: readonly OperationSensitivePath[];
61
+ /**
62
+ * Additional dot paths to redact from captured invocation outputs. Use `*`
63
+ * for array elements, for example `items.*.paymentUrl`.
64
+ */
65
+ output?: readonly OperationSensitivePath[];
66
+ }
67
+ export interface OperationObservabilityConfig {
68
+ /**
69
+ * Complements schema-level `fields.*()` / `sensitive()` metadata for values
70
+ * that are shape-dependent, provider-normalized, or otherwise easier to
71
+ * express as stable public paths.
72
+ */
73
+ sensitive?: OperationObservabilitySensitiveConfig;
74
+ }
75
+ export interface OperationAnnotations {
76
+ readOnly?: boolean;
77
+ destructive?: boolean;
78
+ idempotent?: boolean;
79
+ /**
80
+ * Marks the operation as callable without provider-level authentication.
81
+ *
82
+ * Provider-level `auth.mode` describes the **majority** auth model of a
83
+ * provider; individual operations can still opt out via `openWorld: true`
84
+ * when their handler does not consume `ctx.credential`. This is the
85
+ * canonical way to declare "this operation is public, even though the
86
+ * provider is `credentials`-mode" without splitting the provider into two.
87
+ *
88
+ * Health-check projections treat `openWorld: true` operations as
89
+ * connection-free probes (no `requiresConnection` required, no SA token
90
+ * lookup). Future gateway work MAY extend this annotation to bypass
91
+ * `X-ApiFuse-Connection-Id` enforcement at proxy time.
92
+ *
93
+ * Example: Naver Map's `search`, `geocode`, and directions operations
94
+ * call public Naver endpoints with no cookies, while `collections` and
95
+ * `export` consume the user's session cookie — the provider declares
96
+ * `auth.mode: "credentials"` (for the latter) and the former mark
97
+ * `openWorld: true`.
98
+ */
99
+ openWorld?: boolean;
100
+ rateLimit?: {
101
+ calls: number;
102
+ window: "minute" | "hour" | "day";
103
+ };
104
+ timeoutMs?: number;
105
+ }
106
+ export declare const OPERATION_TIMEOUT_MS_MIN = 1;
107
+ export declare const OPERATION_TIMEOUT_MS_MAX = 60000;
108
+ export declare const STREAM_HEARTBEAT_MS_MIN = 1000;
109
+ export declare const STREAM_HEARTBEAT_MS_MAX = 60000;
110
+ export declare const STREAM_IDLE_TIMEOUT_MS_MIN = 1000;
111
+ export declare const STREAM_IDLE_TIMEOUT_MS_MAX = 300000;
112
+ export declare const STREAM_MAX_DURATION_MS_MIN = 1000;
113
+ export declare const STREAM_MAX_DURATION_MS_MAX = 1800000;
114
+ export declare const STREAM_CHUNK_BYTES_MIN = 1;
115
+ export declare const STREAM_CHUNK_BYTES_MAX = 1048576;
116
+ export type OperationTransportKind = "json" | "sse" | "http-stream" | "websocket";
117
+ export interface OperationJsonTransport {
118
+ kind: "json";
119
+ }
120
+ export interface OperationSseTransport {
121
+ kind: "sse";
122
+ heartbeatMs?: number;
123
+ idleTimeoutMs?: number;
124
+ maxDurationMs?: number;
125
+ maxEventBytes?: number;
126
+ resumable?: false | "last-event-id";
127
+ events: Record<string, SchemaLike>;
128
+ }
129
+ export interface OperationHttpStreamTransport {
130
+ kind: "http-stream";
131
+ contentType?: string;
132
+ idleTimeoutMs?: number;
133
+ maxDurationMs?: number;
134
+ maxChunkBytes?: number;
135
+ }
136
+ export interface OperationWebSocketTransport {
137
+ kind: "websocket";
138
+ subprotocols?: readonly string[];
139
+ idleTimeoutMs?: number;
140
+ maxDurationMs?: number;
141
+ maxFrameBytes?: number;
142
+ /**
143
+ * WebSocket Operation metadata is future-ready. Gateway dispatch remains
144
+ * disabled until a gateway-managed session implementation is present.
145
+ */
146
+ dispatch: "unsupported";
147
+ }
148
+ export type OperationTransport = OperationJsonTransport | OperationSseTransport | OperationHttpStreamTransport | OperationWebSocketTransport;
149
+ export declare const DEFAULT_OPERATION_TRANSPORT: OperationJsonTransport;
150
+ export interface OperationRelationships {
151
+ alternatives?: string[];
152
+ }
153
+ export type Iso3166Alpha2CountryCode = Uppercase<string>;
154
+ export type Bcp47Locale = string;
155
+ export type ProviderLocale = Bcp47Locale;
156
+ export type ProviderLocaleKey = string & {
157
+ readonly __brand: "ProviderLocaleKey";
158
+ };
159
+ export type ProviderLocaleKeyInput = ProviderLocaleKey | string;
160
+ export type Iso8601Duration = string;
161
+ export type Rfc3339Instant = string;
162
+ export type IanaTimeZone = string;
163
+ export type Iso4217CurrencyCode = Uppercase<string>;
164
+ export type E164PhoneNumber = `+${string}`;
165
+ export type SmsOrigin = {
166
+ /** Sender represented as an ITU-T E.164 phone number. */
167
+ kind: "e164";
168
+ value: E164PhoneNumber;
169
+ display?: string;
170
+ } | {
171
+ /** Country-local service sender, for example KR 1661-5270. */
172
+ kind: "nationalServiceCode";
173
+ country: Iso3166Alpha2CountryCode;
174
+ value: string;
175
+ display?: string;
176
+ };
177
+ export interface SmsOtpExtractionPattern {
178
+ /** RegExp or source string containing exactly one usable OTP capture. */
179
+ pattern: RegExp | string;
180
+ /** Named capture key or one-based numeric capture index. Defaults to first capture. */
181
+ capture?: string | number;
182
+ }
183
+ export interface SmsOtpMatcherDefinition {
184
+ id: string;
185
+ country: Iso3166Alpha2CountryCode;
186
+ locale?: Bcp47Locale;
187
+ phoneNumber?: E164PhoneNumber;
188
+ origins: readonly [SmsOrigin, ...SmsOrigin[]];
189
+ code: SmsOtpExtractionPattern;
190
+ maxAge: Iso8601Duration;
191
+ waitTimeout: Iso8601Duration;
192
+ clockSkew?: Iso8601Duration;
193
+ /** Runtime/fixture helper. Not serialized into generated registry artifacts. */
194
+ extractOtp(body: string): string | null;
195
+ }
196
+ export type SttTranscribeMode = "general" | "otp";
197
+ export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
198
+ export type SttUnsupportedOptionPolicy = "warn" | "error";
199
+ export type ProviderSttMode = "optional" | "required";
200
+ export interface ProviderSttConfig {
201
+ mode: ProviderSttMode;
202
+ }
203
+ export type SttAudioInput = {
204
+ kind: "base64";
205
+ data: string;
206
+ mediaType?: string;
207
+ durationMs?: number;
208
+ };
209
+ export interface SttVerificationCodeOptions {
210
+ locale?: Bcp47Locale;
211
+ codeLengths?: number | readonly number[] | {
212
+ min: number;
213
+ max: number;
214
+ };
215
+ }
216
+ export interface SttTranscribeRequest {
217
+ audio: SttAudioInput;
218
+ language?: Bcp47Locale;
219
+ mode?: SttTranscribeMode;
220
+ promptPolicy?: SttPromptPolicy;
221
+ initialPrompt?: string;
222
+ unsupportedOptionPolicy?: SttUnsupportedOptionPolicy;
223
+ verificationCode?: SttVerificationCodeOptions;
224
+ timeoutMs?: number;
225
+ maxAudioBytes?: number;
226
+ }
227
+ export interface SttSegment {
228
+ text: string;
229
+ startMs?: number;
230
+ endMs?: number;
231
+ confidence?: number;
232
+ }
233
+ export interface SttUsage {
234
+ audioDurationMs?: number;
235
+ audioBytes?: number;
236
+ billableUnits?: number;
237
+ }
238
+ export interface SttWarning {
239
+ code: "UNSUPPORTED_STT_OPTION" | "PROMPT_IGNORED" | "LOCALE_PARTIAL";
240
+ message: string;
241
+ }
242
+ export interface SttTranscript {
243
+ text: string;
244
+ language?: Bcp47Locale;
245
+ durationMs?: number;
246
+ segments?: readonly SttSegment[];
247
+ usage?: SttUsage;
248
+ warnings?: readonly SttWarning[];
249
+ verificationCode?: VerificationCodeExtractionResult;
250
+ }
251
+ export type VerificationCodeCandidateSource = "digits" | "spoken_words" | "mixed";
252
+ export interface VerificationCodeCandidate {
253
+ code: string;
254
+ source: VerificationCodeCandidateSource;
255
+ startIndex?: number;
256
+ endIndex?: number;
257
+ }
258
+ export interface VerificationCodeExtractionResult {
259
+ code: string;
260
+ candidates: readonly VerificationCodeCandidate[];
261
+ normalizedText: string;
262
+ }
263
+ export interface SttContext {
264
+ transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
265
+ extractVerificationCode(text: string, options?: SttVerificationCodeOptions): VerificationCodeExtractionResult;
266
+ }
267
+ export interface HealthJourneySchedule {
268
+ kind: "interval";
269
+ /** ISO 8601 duration, for example PT8H. */
270
+ interval: Iso8601Duration;
271
+ randomize?: HealthScheduleRandomization;
272
+ jitter?: Iso8601Duration;
273
+ }
274
+ export type HealthScheduleRandomization = {
275
+ mode: "centered";
276
+ maxOffset: Iso8601Duration;
277
+ } | {
278
+ mode: "delayed";
279
+ maxDelay: Iso8601Duration;
280
+ };
281
+ export interface HealthJourneyStep {
282
+ id: string;
283
+ description?: string;
284
+ operationId?: string;
285
+ usesSmsMatcher?: string;
286
+ coversOperations?: readonly string[];
287
+ safeBoundary?: "paymentWebviewUrl" | "paymentUrl" | "none";
288
+ kind?: "operation" | "smsOtp" | "assertion" | "journal";
289
+ }
290
+ export interface HealthJourneyGatewayContext {
291
+ connect?(options?: {
292
+ providerId?: string;
293
+ externalRef?: string;
294
+ authMode?: "credentials" | "oauth2";
295
+ input?: Record<string, unknown>;
296
+ metadata?: Record<string, unknown>;
297
+ }): Promise<{
298
+ connectionId: string;
299
+ rowVersion: number;
300
+ }>;
301
+ disconnect?(connection: {
302
+ connectionId: string;
303
+ rowVersion: number;
304
+ }): Promise<void>;
305
+ execute(providerId: string, operationId: string, input: unknown, options?: {
306
+ connectionId?: string;
307
+ requestId?: string;
308
+ /**
309
+ * Set false when the journey will record the semantic operation
310
+ * outcome itself through `ctx.event.operation()`. Transport success
311
+ * must not become a competing public health sample in that case.
312
+ */
313
+ recordOperationEvent?: boolean;
314
+ }): Promise<{
315
+ data: unknown;
316
+ status: number;
317
+ duration: number;
318
+ meta?: Record<string, unknown>;
319
+ }>;
320
+ }
321
+ export interface SmsPhoneIdentity {
322
+ id: string;
323
+ country: Iso3166Alpha2CountryCode | string;
324
+ e164: E164PhoneNumber | string;
325
+ nationalNumber: string;
326
+ displayName?: string;
327
+ }
328
+ export interface HealthJourneySmsContext {
329
+ resolvePhone(params?: {
330
+ matcherId?: string;
331
+ }): Promise<SmsPhoneIdentity>;
332
+ waitForOtp(params: {
333
+ matcherId: string;
334
+ attemptId: string;
335
+ phoneId?: string;
336
+ phoneNumber?: string;
337
+ signal?: AbortSignal;
338
+ }): Promise<{
339
+ code: string;
340
+ messageId: string;
341
+ receivedAt: string;
342
+ }>;
343
+ }
344
+ export interface HealthJourneyJournalContext {
345
+ sideEffect<T>(params: {
346
+ stepId: string;
347
+ kind: string;
348
+ idempotencyKey: string;
349
+ run: () => Promise<T>;
350
+ }): Promise<T>;
351
+ }
352
+ export interface HealthJourneyEventContext {
353
+ /**
354
+ * Record an operation-level health outcome that was proven by the journey but
355
+ * not emitted by a direct `ctx.gateway.execute()` call, such as a recovery or
356
+ * manual-review assertion. This is intentionally narrow; it is not a generic
357
+ * event bus.
358
+ */
359
+ operation(params: {
360
+ operationId: string;
361
+ status: "ok" | "degraded" | "down" | "unknown" | "not_reached";
362
+ stepId?: string;
363
+ label?: string;
364
+ error?: string;
365
+ latencyMs?: number;
366
+ statusCode?: number;
367
+ metadata?: Record<string, unknown>;
368
+ }): Promise<void>;
369
+ }
370
+ export interface HealthJourneyRunContext {
371
+ attemptId: string;
372
+ providerId: string;
373
+ journeyId: string;
374
+ gateway: HealthJourneyGatewayContext;
375
+ sms: HealthJourneySmsContext;
376
+ journal: HealthJourneyJournalContext;
377
+ state: ProviderRuntimeState;
378
+ event: HealthJourneyEventContext;
379
+ signal: AbortSignal;
380
+ secrets: Record<string, string | undefined>;
381
+ }
382
+ export type HealthJourneyManualTriggerPolicy = {
383
+ enabled: false;
384
+ reason?: string;
385
+ } | {
386
+ enabled: true;
387
+ requiresAcknowledgement: boolean;
388
+ risk: "read_only" | "writes_external_state" | "sms_or_payment";
389
+ /** ISO 8601 duration. Minimum time between manual executions. */
390
+ minManualInterval: Iso8601Duration;
391
+ publicRationale: string;
392
+ };
393
+ export interface HealthJourneyRunResult {
394
+ status?: "ok" | "degraded" | "down" | "unknown";
395
+ label?: string;
396
+ metadata?: Record<string, unknown>;
397
+ }
398
+ export interface HealthJourneyDefinition {
399
+ id: string;
400
+ title?: string;
401
+ description?: string;
402
+ schedule: HealthJourneySchedule;
403
+ coversOperations: readonly [string, ...string[]];
404
+ timeout?: Iso8601Duration;
405
+ cooldown?: Iso8601Duration;
406
+ smsMatchers?: readonly SmsOtpMatcherDefinition[];
407
+ requiredSecrets?: readonly string[];
408
+ manualTrigger?: HealthJourneyManualTriggerPolicy;
409
+ steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
410
+ run?: (ctx: HealthJourneyRunContext) => Promise<HealthJourneyRunResult | undefined>;
411
+ }
412
+ /**
413
+ * Health-check authoring surface owned by `@apifuse/provider-sdk`.
414
+ *
415
+ * IMPORTANT (architectural invariant): These types are PURE DATA + assertion
416
+ * lambdas. They MUST NOT import or reference any health-monitor runtime
417
+ * surface (scheduler, recorder, gateway client, registry projection types).
418
+ * Provider declarations remain runtime-agnostic at build time.
419
+ *
420
+ * See `openspec/changes/enforce-sdk-operation-health-suite/design.md` §D1.
421
+ */
422
+ /** Polling interval duration accepted by the health-monitor runtime. */
423
+ export type ProbeInterval = ms.StringValue;
424
+ /**
425
+ * Common probe interval examples retained for discoverability/backwards
426
+ * compatibility. This list is not exhaustive; any positive `ms`-style duration
427
+ * string accepted by `@types/ms` (for example `2m`, `8h`, or `1 day`) is valid.
428
+ */
429
+ export declare const PROBE_INTERVALS: readonly ProbeInterval[];
430
+ export declare const HEALTH_CHECK_TIMEOUT_MS_MIN = 1;
431
+ export declare const HEALTH_CHECK_TIMEOUT_MS_MAX = 60000;
432
+ export declare const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MIN = 1;
433
+ export declare const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MAX = 60000;
434
+ /**
435
+ * Context passed to a `HealthCheckCase.assertions` lambda.
436
+ * `data` is typed against the operation's declared output schema (TOutput).
437
+ */
438
+ export interface HealthCheckAssertionContext<TOutput = unknown> {
439
+ /** Parsed response body (already validated against operation.output). */
440
+ readonly data: TOutput;
441
+ /** HTTP status code returned by the gateway. */
442
+ readonly status: number;
443
+ /** Wall-clock duration of the operation invocation, in milliseconds. */
444
+ readonly durationMs: number;
445
+ /** Optional provider response metadata such as cache hit/stale flags. */
446
+ readonly meta?: Record<string, unknown>;
447
+ }
448
+ export interface HealthCheckInputPreparationContext<TInput = unknown> {
449
+ readonly providerId: string;
450
+ readonly operationId: string;
451
+ readonly input: TInput;
452
+ readonly connectionId?: string;
453
+ readonly gateway: {
454
+ execute: (providerId: string, operationId: string, input: unknown, options?: {
455
+ connectionId?: string;
456
+ }) => Promise<{
457
+ status: number;
458
+ duration: number;
459
+ data: unknown;
460
+ meta?: Record<string, unknown>;
461
+ }>;
462
+ };
463
+ }
464
+ /**
465
+ * Optional return value from an assertions lambda. Allows the case to
466
+ * downgrade to "degraded" without throwing, and to attach a human-friendly
467
+ * label that surfaces on the status page (e.g., "BTC 95,000,000원").
468
+ */
469
+ export interface HealthCheckCaseResult {
470
+ /** Override final status; if omitted, "ok" unless assertion threw. */
471
+ status?: "ok" | "degraded";
472
+ /** Optional human-readable label surfaced on the status page. */
473
+ label?: string;
474
+ }
475
+ /**
476
+ * A single test-case-style verification scenario for an operation.
477
+ *
478
+ * Type parameters flow from the OperationDefinition's input/output schemas
479
+ * so authors get IntelliSense and compile-time errors when accessing fields
480
+ * that do not exist on the operation's declared output schema.
481
+ */
482
+ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
483
+ /** Human-readable case name; unique within the suite. */
484
+ name: string;
485
+ /** Optional longer description shown on ops dashboards. */
486
+ description?: string;
487
+ /** Input passed to the operation handler for this case. */
488
+ input: TInput;
489
+ /**
490
+ * Optional runtime input preparation hook for volatile probes. Use this when
491
+ * the durable probe input must be derived from a live read-only operation
492
+ * immediately before the checked operation executes.
493
+ */
494
+ prepareInput?: (ctx: HealthCheckInputPreparationContext<TInput>) => TInput | Promise<TInput>;
495
+ /**
496
+ * Assertion executed against the operation's response and timing.
497
+ *
498
+ * - Throw to fail the case (recorded as `down`).
499
+ * - Return `{ status: "degraded", label }` to flag without failing.
500
+ * - Return `void` (implicit) for `ok`.
501
+ *
502
+ * MUST NOT access scheduler, recorder, or any runtime type — pure data
503
+ * + lambda only.
504
+ */
505
+ assertions: (ctx: HealthCheckAssertionContext<TOutput>) => void | Promise<void> | HealthCheckCaseResult | Promise<HealthCheckCaseResult>;
506
+ /** Override per-case degradation threshold (ms); falls back to the suite default. */
507
+ degradedThresholdMs?: number;
508
+ /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
509
+ timeoutMs?: number;
510
+ /** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
511
+ expectedStatus?: "ok" | "degraded";
512
+ /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
513
+ enabled?: () => boolean;
514
+ }
515
+ /**
516
+ * Operation-level health-check suite. At least one case is required when
517
+ * present. All cases share the suite's interval and default timeout.
518
+ */
519
+ export interface HealthCheckSuite<TInput = unknown, TOutput = unknown> {
520
+ /** Polling interval for the suite. All cases share this cadence. */
521
+ interval: ProbeInterval;
522
+ schedule?: {
523
+ randomize?: HealthScheduleRandomization;
524
+ };
525
+ /** Per-case timeout in milliseconds. Default: 30000. */
526
+ timeoutMs?: number;
527
+ /** Default degradation threshold for cases in this suite. Default: runtime threshold. */
528
+ degradedThresholdMs?: number;
529
+ /** Non-empty list of cases. Empty arrays are rejected at definition time. */
530
+ cases: [
531
+ HealthCheckCase<TInput, TOutput>,
532
+ ...HealthCheckCase<TInput, TOutput>[]
533
+ ];
534
+ /**
535
+ * If true, the runtime SHALL invoke `connect()` before `execute()` and
536
+ * `disconnect()` after, using the service-account token. The provider
537
+ * MUST also declare `healthMonitor.requiredSecrets` for the env values
538
+ * the connect ceremony will consume.
539
+ */
540
+ requiresConnection?: boolean;
541
+ }
542
+ /**
543
+ * Explicit, audited opt-out for operations that genuinely cannot be probed
544
+ * (e.g., destructive mutations, paid-per-call flows). Either `healthCheck`
545
+ * or `healthCheckUnsupported` SHALL be present on every operation; missing
546
+ * both is a registry-build error.
547
+ */
548
+ export interface HealthCheckUnsupported {
549
+ /** Human-readable explanation. Required, non-empty. */
550
+ reason: string;
551
+ /** Optional issue/PR url that revisits the decision. */
552
+ trackedIn?: string;
553
+ }
554
+ /**
555
+ * Provider-level monitoring metadata for credential-bearing health checks.
556
+ * Describes ONLY env-secret keys the runtime needs and the service account
557
+ * to use; SHALL NOT carry probe schedules, sample inputs, or assertion
558
+ * logic (those remain on `OperationDefinition.healthCheck`).
559
+ */
560
+ export interface ProviderHealthMonitorConfig {
561
+ /**
562
+ * Provider-wide default probe timeout in milliseconds. Individual
563
+ * `healthCheck.timeoutMs` and `healthCheck.cases[].timeoutMs` values take
564
+ * precedence. Defaults to the monitor runtime default.
565
+ */
566
+ defaultProbeTimeoutMs?: number;
567
+ /**
568
+ * Provider-wide default latency threshold in milliseconds before an
569
+ * otherwise successful probe is marked degraded. Suite/case thresholds take
570
+ * precedence. Defaults to the monitor runtime default.
571
+ */
572
+ defaultDegradedThresholdMs?: number;
573
+ /**
574
+ * Env-secret key names (e.g., "APIFUSE__HEALTH_MONITOR__CATCHTABLE_PHONE") the
575
+ * synthetic-monitor runtime needs to execute probes that declare
576
+ * `requiresConnection: true`.
577
+ */
578
+ requiredSecrets?: string[];
579
+ /**
580
+ * Mapping from provider auth ceremony input fields to runtime env-secret
581
+ * names. The health-monitor uses this to create a fresh connection for
582
+ * `requiresConnection: true` probes, then disconnects after execution.
583
+ */
584
+ credentialInputs?: Record<string, string>;
585
+ /**
586
+ * Runtime probe overrides keyed by generated registry probe id. Use this for
587
+ * operation health checks that need a runtime-specific interval or threshold
588
+ * without changing the provider-authored default suite.
589
+ */
590
+ probeOverrides?: Record<string, HealthMonitorProbeOverride>;
591
+ /**
592
+ * Override the default service account ID for this provider's probes.
593
+ * Defaults to the runtime's `APIFUSE__HEALTH_MONITOR__SERVICE_ACCOUNT_ID` env var.
594
+ */
595
+ serviceAccount?: string;
596
+ }
597
+ export interface HealthMonitorProbeOverride {
598
+ /** Optional runtime interval override as a positive `ms`-style duration string. */
599
+ interval?: ProbeInterval;
600
+ /** Optional timeout override for generated registry probes. */
601
+ timeoutMs?: number;
602
+ /** Optional degraded threshold override for generated registry probes. */
603
+ degradedThresholdMs?: number;
604
+ }
605
+ export interface OperationErrorCode {
606
+ code: string;
607
+ status?: number;
608
+ description: string;
609
+ retryable?: boolean;
610
+ }
611
+ export interface OperationDocMeta {
612
+ titleKey?: ProviderLocaleKeyInput;
613
+ descriptionKey?: ProviderLocaleKeyInput;
614
+ summaryKey?: ProviderLocaleKeyInput;
615
+ markdownKey?: ProviderLocaleKeyInput;
616
+ normalizationNotesKeys?: ProviderLocaleKeyInput[];
617
+ requestExample?: Record<string, unknown>;
618
+ responseExample?: unknown;
619
+ errorCodes?: OperationErrorCode[];
620
+ }
621
+ export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
622
+ export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
623
+ export interface BrowserOptions {
624
+ headless?: boolean;
625
+ stealth?: boolean;
626
+ proxy?: string;
627
+ engine?: BrowserEngine;
628
+ requireCdpPool?: boolean;
629
+ }
630
+ export interface StealthProfile {
631
+ name: string;
632
+ platform: StealthPlatform;
633
+ version: string;
634
+ userAgent: string;
635
+ tlsClientIdentifier?: string;
636
+ ja3?: string;
637
+ ja4?: string;
638
+ h2Settings?: Record<string, unknown>;
639
+ headerOrder?: string[];
640
+ }
641
+ export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2";
642
+ export type ConnectionMode = AuthMode;
643
+ export type ProviderReviewed = "first-party" | "community" | "staging";
644
+ export type ProviderAccessVisibility = "public" | "early_access";
645
+ export type ProviderProxyMode = "disabled" | "optional" | "required";
646
+ export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
647
+ export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
648
+ export interface ProviderProxyPolicy {
649
+ /**
650
+ * Provider intent only. Transport details such as raw CONNECT, origin
651
+ * certificate verification, and vendor allocator endpoints are SDK-owned.
652
+ */
653
+ mode: ProviderProxyMode;
654
+ provider?: ProviderProxyProvider;
655
+ geo?: {
656
+ /** ISO 3166-1 alpha-2 country code, for example KR or US. */
657
+ country?: Iso3166Alpha2CountryCode;
658
+ subdivision?: string;
659
+ city?: string;
660
+ };
661
+ session?: {
662
+ affinity?: ProviderProxySessionAffinity;
663
+ lifetimeMinutes?: number;
664
+ poolSize?: number;
665
+ };
666
+ }
667
+ export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
668
+ export interface ProviderAccessConfig {
669
+ /**
670
+ * Provider-level rollout visibility.
671
+ *
672
+ * - `public`: visible in public docs/catalog/OpenAPI and callable through
673
+ * the existing provider policy stack.
674
+ * - `early_access`: hidden from public discovery and callable only when the
675
+ * active customer organization has a provider-level access grant.
676
+ *
677
+ * This is intentionally provider-level only. It does not alter auth mode,
678
+ * operation schemas, health-check authoring, `openWorld`, or Connection
679
+ * requirements.
680
+ */
681
+ visibility?: ProviderAccessVisibility;
682
+ }
683
+ export type ProviderLogoSource = "asset" | "monogram" | "none";
684
+ export type ProviderLogoProfile = {
685
+ source: "asset";
686
+ path: string;
687
+ /**
688
+ * Absolute, customer-renderable URL emitted by discovery projections.
689
+ * Provider source definitions may omit this and let the registry projection
690
+ * derive it from the committed public asset path.
691
+ */
692
+ url?: string;
693
+ background?: string;
694
+ } | {
695
+ source: "monogram" | "none";
696
+ background?: string;
697
+ fallbackReason: string;
698
+ };
699
+ export type ProviderPublicConnectionMode = "apifuse_managed" | "workspace_enabled" | "user_connected" | "no_connection_required";
700
+ export type ProviderSupportLevel = "stable" | "beta" | "experimental";
701
+ export interface ProviderPublicProfile {
702
+ displayNameKey?: ProviderLocaleKeyInput;
703
+ shortDescriptionKey?: ProviderLocaleKeyInput;
704
+ longDescriptionKey?: ProviderLocaleKeyInput;
705
+ logo?: ProviderLogoProfile;
706
+ category?: string;
707
+ tags?: readonly string[];
708
+ capabilityKeys?: readonly ProviderLocaleKeyInput[];
709
+ examplePromptKeys?: readonly ProviderLocaleKeyInput[];
710
+ setupSummaryKey?: ProviderLocaleKeyInput;
711
+ connectionMode?: ProviderPublicConnectionMode;
712
+ requirementKeys?: readonly ProviderLocaleKeyInput[];
713
+ limitationKeys?: readonly ProviderLocaleKeyInput[];
714
+ availability?: {
715
+ regions?: readonly string[];
716
+ supportLevel?: ProviderSupportLevel;
717
+ };
718
+ /**
719
+ * Brand primary color as a 6-digit hex string (e.g. "#1a73e8").
720
+ * Single source of truth for all provider-specific color expressions
721
+ * (mood wash, monogram fallback, icon tint). The UI derives subtle washes
722
+ * via color-mix; provider definitions do not control mood percentages.
723
+ */
724
+ primaryColor?: string;
725
+ }
726
+ export interface ProviderMeta {
727
+ displayName: string;
728
+ displayNameKey?: ProviderLocaleKeyInput;
729
+ descriptionKey: ProviderLocaleKeyInput;
730
+ category: string;
731
+ tags?: readonly string[];
732
+ icon?: string;
733
+ docTitleKey?: ProviderLocaleKeyInput;
734
+ docDescriptionKey?: ProviderLocaleKeyInput;
735
+ docSummaryKey?: ProviderLocaleKeyInput;
736
+ docMarkdownKey?: ProviderLocaleKeyInput;
737
+ normalizationNotesKeys?: readonly ProviderLocaleKeyInput[];
738
+ environment?: "staging";
739
+ purpose?: string;
740
+ purposeKey?: ProviderLocaleKeyInput;
741
+ publicProfile?: ProviderPublicProfile;
742
+ contract?: {
743
+ publicSchemaFieldNames?: "normalized";
744
+ };
745
+ }
746
+ export type RequestParamPrimitive = string | number | boolean | null | undefined;
747
+ export type RequestParamValue = RequestParamPrimitive | readonly RequestParamPrimitive[];
748
+ export type RequestParams = Record<string, RequestParamValue>;
749
+ export declare const HttpRetryPreset: {
750
+ readonly Off: "off";
751
+ readonly TransportTransient: "transport_transient";
752
+ readonly SafeRead: "safe_read";
753
+ readonly AggressiveRead: "aggressive_read";
754
+ readonly RateLimitAware: "rate_limit_aware";
755
+ };
756
+ export type HttpRetryPreset = (typeof HttpRetryPreset)[keyof typeof HttpRetryPreset];
757
+ export declare const HttpRetryJitter: {
758
+ readonly None: "none";
759
+ readonly Full: "full";
760
+ readonly Equal: "equal";
761
+ };
762
+ export type HttpRetryJitter = (typeof HttpRetryJitter)[keyof typeof HttpRetryJitter];
763
+ export declare const HttpRetryDelayStrategy: {
764
+ readonly Fixed: "fixed";
765
+ readonly Exponential: "exponential";
766
+ };
767
+ export type HttpRetryDelayStrategy = (typeof HttpRetryDelayStrategy)[keyof typeof HttpRetryDelayStrategy];
768
+ export declare const HttpRetryAfterPolicy: {
769
+ readonly Ignore: "ignore";
770
+ /** Honor Retry-After up to maxDelayMs. */
771
+ readonly Respect: "respect";
772
+ /** Honor Retry-After but also cap it to the SDK-computed backoff delay. */
773
+ readonly Cap: "cap";
774
+ };
775
+ export type HttpRetryAfterPolicy = (typeof HttpRetryAfterPolicy)[keyof typeof HttpRetryAfterPolicy];
776
+ export declare const HttpRetryUnsafeMethodPolicy: {
777
+ readonly Reject: "reject";
778
+ readonly AllowExplicitUnsafe: "allow_explicit_unsafe";
779
+ };
780
+ export type HttpRetryUnsafeMethodPolicy = (typeof HttpRetryUnsafeMethodPolicy)[keyof typeof HttpRetryUnsafeMethodPolicy];
781
+ export interface HttpRetryOptions {
782
+ preset?: HttpRetryPreset;
783
+ /** Total logical ctx.http attempts, including the first attempt. */
784
+ attempts?: number;
785
+ methods?: readonly HttpMethod[];
786
+ statusCodes?: readonly number[];
787
+ errorCodes?: readonly string[];
788
+ delayStrategy?: HttpRetryDelayStrategy;
789
+ baseDelayMs?: number;
790
+ maxDelayMs?: number;
791
+ jitter?: HttpRetryJitter;
792
+ retryAfter?: HttpRetryAfterPolicy;
793
+ unsafeMethodPolicy?: HttpRetryUnsafeMethodPolicy;
794
+ }
795
+ export interface HttpRetrySummary {
796
+ attempts: number;
797
+ retries: number;
798
+ preset?: HttpRetryPreset;
799
+ transport: "native";
800
+ lastErrorCode?: string;
801
+ lastStatus?: number;
802
+ }
803
+ export interface RequestOptions {
804
+ headers?: Record<string, string>;
805
+ params?: RequestParams;
806
+ proxy?: string;
807
+ timeout?: number;
808
+ /**
809
+ * Defaults to true. Set to false when callers need to inspect upstream
810
+ * non-2xx bodies themselves instead of converting them to TransportError.
811
+ */
812
+ throwOnHttpError?: boolean;
813
+ retry?: boolean | HttpRetryPreset | HttpRetryOptions;
814
+ }
815
+ export type HttpMethod = "HEAD" | "head" | "GET" | "get" | "POST" | "post" | "PUT" | "put" | "DELETE" | "delete" | "OPTIONS" | "options" | "TRACE" | "trace" | "PATCH" | "patch";
816
+ export interface StealthFetchOptions extends RequestOptions {
817
+ method?: HttpMethod;
818
+ body?: string | Buffer;
819
+ redirect?: "follow" | "manual" | "error";
820
+ /**
821
+ * Offsets policy-managed proxy pool selection for caller-managed retries.
822
+ * Use when a request receives an upstream challenge page rather than a
823
+ * transport error, so the next logical retry does not restart at the same
824
+ * operation-affinity proxy.
825
+ */
826
+ proxyAttemptOffset?: number;
827
+ /** Override the configured browser-like stealth profile for this request. */
828
+ profile?: string;
829
+ /**
830
+ * Stealth transport certificate controls. Use only for proxy products that
831
+ * terminate CONNECT with a private CA instead of tunneling the origin
832
+ * certificate chain.
833
+ */
834
+ stealth?: {
835
+ insecureSkipVerify?: boolean;
836
+ };
837
+ }
838
+ export interface CookieJar {
839
+ get(name: string): string | undefined;
840
+ getAll(): Record<string, string>;
841
+ toString(): string;
842
+ find?(predicate: (cookie: string) => boolean): string | undefined;
843
+ }
844
+ export interface StealthSessionCookies extends CookieJar {
845
+ has(name: string): boolean;
846
+ setFromCookieStrings(cookieStrings: readonly string[]): void;
847
+ toHeader(): string;
848
+ snapshot(): Record<string, string>;
849
+ restore(cookies: Record<string, string>): void;
850
+ clear(): void;
851
+ }
852
+ export interface DeclarativeStealthResponse {
853
+ status: number;
854
+ ok: boolean;
855
+ url?: string;
856
+ redirected?: boolean;
857
+ headers: Record<string, string>;
858
+ rawHeaders: [string, string][];
859
+ body: string;
860
+ httpVersion?: string;
861
+ tlsInfo?: {
862
+ protocol?: string;
863
+ cipher?: string;
864
+ [key: string]: unknown;
865
+ };
866
+ cookies: CookieJar;
867
+ json<T>(): Promise<T>;
868
+ arrayBuffer(): Promise<ArrayBuffer>;
869
+ bytes(): Promise<Uint8Array>;
870
+ }
871
+ export type StealthResponse = DeclarativeStealthResponse;
872
+ export type RequestWithMethodOptions = RequestOptions & {
873
+ method?: string;
874
+ body?: unknown;
875
+ };
876
+ export interface StealthRedirectHop {
877
+ url: string;
878
+ status: number;
879
+ method: string;
880
+ location?: string;
881
+ nextUrl?: string;
882
+ }
883
+ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "redirect"> {
884
+ url: string;
885
+ maxHops?: number;
886
+ stopWhen?: (hop: StealthRedirectHop) => boolean | Promise<boolean>;
887
+ }
888
+ export interface StealthRedirectRunResult {
889
+ final: StealthResponse;
890
+ hops: StealthRedirectHop[];
891
+ reason: "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
892
+ cookies: Record<string, string>;
893
+ }
894
+ export interface StealthSession {
895
+ fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
896
+ cookies: StealthSessionCookies;
897
+ redirects: {
898
+ run(options: StealthRedirectRunOptions): Promise<StealthRedirectRunResult>;
899
+ };
900
+ close(): void;
901
+ }
902
+ export interface ApiFuseResponse<T> {
903
+ data: T;
904
+ meta: {
905
+ requestId: string;
906
+ duration: number;
907
+ cached?: boolean;
908
+ stale?: boolean;
909
+ cache?: ProviderCacheResponseMeta;
910
+ retry?: HttpRetrySummary;
911
+ };
912
+ }
913
+ export interface HttpResponse<T = unknown> {
914
+ status: number;
915
+ ok: boolean;
916
+ headers: Record<string, string>;
917
+ data: T;
918
+ json<U = T>(): Promise<U>;
919
+ text(): Promise<string>;
920
+ arrayBuffer(): Promise<ArrayBuffer>;
921
+ bytes(): Promise<Uint8Array>;
922
+ }
923
+ export interface HttpStreamResponse {
924
+ status: number;
925
+ ok: boolean;
926
+ headers: Record<string, string>;
927
+ body: ReadableStream<Uint8Array>;
928
+ bytes(): AsyncIterable<Uint8Array>;
929
+ textChunks(): AsyncIterable<string>;
930
+ lines(): AsyncIterable<string>;
931
+ }
932
+ export interface SseMessage {
933
+ event: string;
934
+ data: string;
935
+ id?: string;
936
+ retry?: number;
937
+ json<T = unknown>(): T;
938
+ }
939
+ export interface ProviderStreamEvent<TData = unknown> {
940
+ event: string;
941
+ data: TData;
942
+ id?: string;
943
+ retry?: number;
944
+ }
945
+ export type OperationHandlerResult<TOutput> = TOutput | Response | ReadableStream<Uint8Array> | AsyncIterable<ProviderStreamEvent>;
946
+ export interface HttpClient {
947
+ request(url: string, opts?: RequestWithMethodOptions): Promise<HttpResponse>;
948
+ get(url: string, options?: RequestOptions): Promise<HttpResponse>;
949
+ post(url: string, body: unknown, options?: RequestOptions): Promise<HttpResponse>;
950
+ put(url: string, body: unknown, options?: RequestOptions): Promise<HttpResponse>;
951
+ delete(url: string, options?: RequestOptions): Promise<HttpResponse>;
952
+ stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
953
+ sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
954
+ }
955
+ export interface ProviderCacheKeyOptions {
956
+ /**
957
+ * Additional field names to omit from stable key material. The SDK always
958
+ * omits known secret-bearing names such as serviceKey, authorization,
959
+ * cookie, token, password, and secret.
960
+ */
961
+ redactFields?: string[];
962
+ }
963
+ export interface ProviderCacheGetOrSetOptions {
964
+ /** Freshness TTL. A fresh hit returns without calling the loader. */
965
+ ttlMs: number;
966
+ /**
967
+ * Optional stale window after ttlMs. If the loader fails while the entry is
968
+ * still inside this window, stale data is returned and marked stale.
969
+ */
970
+ staleIfErrorMs?: number;
971
+ /** Optional jitter applied to writes to avoid synchronized expiry. */
972
+ jitterPct?: number;
973
+ }
974
+ export interface ProviderCacheLookupMeta {
975
+ key: string;
976
+ hit: boolean;
977
+ stale: boolean;
978
+ ageMs?: number;
979
+ source: "redis" | "memory" | "loader";
980
+ }
981
+ export interface ProviderCacheResult<T> {
982
+ value: T;
983
+ meta: ProviderCacheLookupMeta;
984
+ }
985
+ export interface ProviderCacheResponseMeta {
986
+ hit: boolean;
987
+ stale: boolean;
988
+ keys: string[];
989
+ source?: "redis" | "memory" | "loader" | "mixed";
990
+ }
991
+ export interface ProviderCache {
992
+ key(namespace: string, parts: unknown, options?: ProviderCacheKeyOptions): string;
993
+ get<T = unknown>(key: string): Promise<ProviderCacheResult<T> | null>;
994
+ set<T = unknown>(key: string, value: T, options: ProviderCacheGetOrSetOptions): Promise<void>;
995
+ delete(key: string): Promise<void>;
996
+ getOrSet<T = unknown>(key: string, loader: () => Promise<T>, options: ProviderCacheGetOrSetOptions): Promise<ProviderCacheResult<T>>;
997
+ responseMeta(): ProviderCacheResponseMeta | undefined;
998
+ }
999
+ export interface StealthClient {
1000
+ fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
1001
+ createSession(opts?: {
1002
+ profile?: string;
1003
+ }): StealthSession;
1004
+ close?(): void;
1005
+ }
1006
+ export interface BrowserClient {
1007
+ readonly engine: BrowserEngine;
1008
+ close?(): Promise<void>;
1009
+ newPage(): Promise<BrowserPage>;
1010
+ rawPage(): Promise<BrowserPage>;
1011
+ withIsolatedContext<T>(handler: (page: BrowserPage) => Promise<T>): Promise<T>;
1012
+ solveChallenge(request: BrowserChallengeRequest): Promise<BrowserChallengeResult>;
1013
+ }
1014
+ export interface BrowserLocator {
1015
+ click(): Promise<void>;
1016
+ fill(text: string): Promise<void>;
1017
+ textContent(): Promise<string | null>;
1018
+ waitFor(options?: {
1019
+ timeout?: number;
1020
+ }): Promise<void>;
1021
+ }
1022
+ export interface BrowserFrame {
1023
+ id: string;
1024
+ name?: string;
1025
+ parentId?: string;
1026
+ url(): Promise<string>;
1027
+ title(): Promise<string>;
1028
+ content(): Promise<string>;
1029
+ evaluate<T>(fn: string | (() => T)): Promise<T>;
1030
+ locator(selector: string): BrowserLocator;
1031
+ }
1032
+ export type BrowserResourceMethod = "GET" | "HEAD";
1033
+ export type BrowserResourceRequest = {
1034
+ readonly url: string;
1035
+ readonly method: BrowserResourceMethod;
1036
+ readonly resourceType?: string;
1037
+ readonly headers: Readonly<Record<string, string>>;
1038
+ };
1039
+ export type BrowserResourceBody = Buffer | Uint8Array | ArrayBuffer | string;
1040
+ export type BrowserResourceDecision = {
1041
+ readonly action: "fulfill";
1042
+ readonly status?: number;
1043
+ readonly headers?: Readonly<Record<string, string>>;
1044
+ readonly body?: BrowserResourceBody;
1045
+ } | {
1046
+ readonly action: "block";
1047
+ readonly reason?: string;
1048
+ };
1049
+ export type BrowserResourceRoute = {
1050
+ readonly match: string | RegExp | ((request: BrowserResourceRequest) => boolean);
1051
+ readonly handle: (request: BrowserResourceRequest) => Promise<BrowserResourceDecision> | BrowserResourceDecision;
1052
+ };
1053
+ export type BrowserResourcePolicy = {
1054
+ readonly defaultAction?: "block";
1055
+ readonly allowedMethods?: readonly BrowserResourceMethod[];
1056
+ readonly routes: readonly BrowserResourceRoute[];
1057
+ };
1058
+ export interface BrowserPage extends BrowserFrame {
1059
+ close(): Promise<void>;
1060
+ fill(selector: string, text: string): Promise<void>;
1061
+ goto(url: string): Promise<void>;
1062
+ pageId?: string;
1063
+ screenshot(options?: {
1064
+ fullPage?: boolean;
1065
+ }): Promise<Buffer>;
1066
+ click(selector: string): Promise<void>;
1067
+ type(selector: string, text: string): Promise<void>;
1068
+ waitForSelector(selector: string, options?: {
1069
+ timeout?: number;
1070
+ }): Promise<void>;
1071
+ frames(): Promise<BrowserFrame[]>;
1072
+ withResourcePolicy<T>(policy: BrowserResourcePolicy, run: () => Promise<T>): Promise<T>;
1073
+ }
1074
+ export type BrowserChallengeRequest = {
1075
+ type: "recaptcha";
1076
+ siteKey?: string;
1077
+ timeout?: number;
1078
+ };
1079
+ export type BrowserChallengeResult = {
1080
+ type: BrowserChallengeRequest["type"];
1081
+ solved: boolean;
1082
+ frameUrl?: string;
1083
+ };
1084
+ export type TraceAttributeValue = string | number | boolean;
1085
+ export interface TraceSpan {
1086
+ id: string;
1087
+ name: string;
1088
+ startedAt: number;
1089
+ endedAt: number;
1090
+ duration_ms: number;
1091
+ status: "ok" | "error";
1092
+ error?: string;
1093
+ attributes: Record<string, TraceAttributeValue>;
1094
+ parentId?: string;
1095
+ }
1096
+ export interface TraceConfig {
1097
+ enabled?: boolean;
1098
+ maxSpans?: number;
1099
+ onSpan?: (span: TraceSpan) => void;
1100
+ exporter?: "console" | "json" | "otlp" | "none";
1101
+ endpoint?: string;
1102
+ otlp?: {
1103
+ endpoint: string;
1104
+ headers?: Record<string, string>;
1105
+ timeout?: number;
1106
+ };
1107
+ }
1108
+ export interface TraceContext {
1109
+ span<T>(name: string, fn: () => Promise<T>): Promise<T>;
1110
+ }
1111
+ export interface AuthContext {
1112
+ requestField(name: string, options?: {
1113
+ type?: "otp" | "text";
1114
+ }): Promise<string>;
1115
+ }
1116
+ export interface EnvContext {
1117
+ get(key: string): string | undefined;
1118
+ }
1119
+ export interface CredentialContext {
1120
+ mode: AuthMode;
1121
+ get(key: string): string | undefined;
1122
+ getAll(): Record<string, string>;
1123
+ getAccessToken(): string | undefined;
1124
+ getScopes(): string[];
1125
+ }
1126
+ export interface ProviderRequestContext {
1127
+ connectionId?: string;
1128
+ headers: Record<string, string>;
1129
+ }
1130
+ export interface ProviderChoiceBindingOptions {
1131
+ connection?: boolean;
1132
+ credentialKeys?: readonly string[];
1133
+ }
1134
+ export type ProviderChoiceStorageOptions = {
1135
+ readonly mode: "inline";
1136
+ } | {
1137
+ readonly mode: "server";
1138
+ readonly namespace: string;
1139
+ readonly state?: ProviderRuntimeState;
1140
+ readonly ttl?: ProviderStateDurationString;
1141
+ readonly maxEntries: number;
1142
+ readonly maxValueBytes: number;
1143
+ readonly unavailable?: "reject";
1144
+ } | {
1145
+ readonly mode: "auto";
1146
+ readonly namespace: string;
1147
+ readonly state?: ProviderRuntimeState;
1148
+ readonly ttl?: ProviderStateDurationString;
1149
+ readonly maxInlineBytes: number;
1150
+ readonly maxEntries: number;
1151
+ readonly maxValueBytes: number;
1152
+ readonly unavailable?: "reject";
1153
+ };
1154
+ export interface ProviderChoiceIssueOptions<TPayload extends Record<string, unknown>> {
1155
+ prefix: string;
1156
+ purpose: string;
1157
+ payload: TPayload;
1158
+ ttlMs: number;
1159
+ nowMs?: number;
1160
+ bind?: ProviderChoiceBindingOptions;
1161
+ storage?: ProviderChoiceStorageOptions;
1162
+ }
1163
+ export interface ProviderChoiceParseOptions {
1164
+ token: string;
1165
+ prefix: string;
1166
+ purpose: string;
1167
+ ttlMs?: number;
1168
+ nowMs?: number;
1169
+ futureToleranceMs?: number;
1170
+ bind?: ProviderChoiceBindingOptions;
1171
+ storage?: ProviderChoiceStorageOptions;
1172
+ }
1173
+ export interface ProviderChoiceContext {
1174
+ issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1175
+ readonly storage?: {
1176
+ readonly mode: "inline";
1177
+ };
1178
+ }): string;
1179
+ issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1180
+ readonly storage: Extract<ProviderChoiceStorageOptions, {
1181
+ readonly mode: "server";
1182
+ }>;
1183
+ }): Promise<string>;
1184
+ issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload> & {
1185
+ readonly storage: Extract<ProviderChoiceStorageOptions, {
1186
+ readonly mode: "auto";
1187
+ }>;
1188
+ }): string | Promise<string>;
1189
+ issue<TPayload extends Record<string, unknown>>(options: ProviderChoiceIssueOptions<TPayload>): string | Promise<string>;
1190
+ parse(options: ProviderChoiceParseOptions & {
1191
+ readonly storage?: {
1192
+ readonly mode: "inline";
1193
+ };
1194
+ }): Record<string, unknown>;
1195
+ parse(options: ProviderChoiceParseOptions & {
1196
+ readonly storage: Extract<ProviderChoiceStorageOptions, {
1197
+ readonly mode: "server";
1198
+ }>;
1199
+ }): Promise<Record<string, unknown>>;
1200
+ parse(options: ProviderChoiceParseOptions & {
1201
+ readonly storage: Extract<ProviderChoiceStorageOptions, {
1202
+ readonly mode: "auto";
1203
+ }>;
1204
+ }): Record<string, unknown> | Promise<Record<string, unknown>>;
1205
+ parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
1206
+ }
1207
+ export interface ContextScratchpad {
1208
+ get(key: string): unknown;
1209
+ set(key: string, value: unknown): void;
1210
+ toJSON(): Record<string, unknown>;
1211
+ }
1212
+ export type FlowContextStore = ContextScratchpad;
1213
+ export type AuthSafeJson = string | number | boolean | null | readonly AuthSafeJson[] | {
1214
+ readonly [key: string]: AuthSafeJson;
1215
+ };
1216
+ export type AuthSafeData = {
1217
+ readonly [key: string]: AuthSafeJson;
1218
+ };
1219
+ export type AuthAbortRetry = "never" | "retry" | "after_user_action";
1220
+ export type AuthAbortData = Record<string, unknown> & {
1221
+ readonly code: string;
1222
+ readonly message?: string;
1223
+ readonly retry?: AuthAbortRetry;
1224
+ readonly actionHint?: AuthSafeJson;
1225
+ readonly fieldErrors?: {
1226
+ readonly [field: string]: string;
1227
+ };
1228
+ readonly details?: AuthSafeData;
1229
+ };
1230
+ export interface AuthFlowTerminalContext {
1231
+ readonly signal?: AbortSignal;
1232
+ readonly deadline?: string;
1233
+ complete<TCredential extends Record<string, string>>(options: {
1234
+ readonly credential: TCredential;
1235
+ readonly metadata?: AuthSafeData;
1236
+ readonly data?: AuthSafeData;
1237
+ readonly turnId?: string;
1238
+ readonly expiresAt?: string;
1239
+ }): AuthTurn;
1240
+ abort(options: {
1241
+ readonly code: string;
1242
+ readonly message?: string;
1243
+ readonly retry?: AuthAbortRetry;
1244
+ readonly actionHint?: AuthSafeJson;
1245
+ readonly fieldErrors?: {
1246
+ readonly [field: string]: string;
1247
+ };
1248
+ readonly data?: AuthSafeData;
1249
+ readonly turnId?: string;
1250
+ readonly expiresAt?: string;
1251
+ }): AuthTurn;
1252
+ nextForm(options: {
1253
+ readonly hintKey?: ProviderLocaleKeyInput;
1254
+ readonly data?: AuthSafeData;
1255
+ readonly turnId?: string;
1256
+ readonly expiresAt?: string;
1257
+ readonly timing?: AuthTurn["timing"];
1258
+ } & ({
1259
+ readonly fields: Record<string, {
1260
+ readonly type?: "string" | "email" | "password" | "otp";
1261
+ readonly labelKey?: ProviderLocaleKeyInput;
1262
+ readonly descriptionKey?: ProviderLocaleKeyInput;
1263
+ readonly placeholderKey?: ProviderLocaleKeyInput;
1264
+ readonly required?: boolean;
1265
+ readonly sensitive?: boolean;
1266
+ }>;
1267
+ readonly expectedInput?: never;
1268
+ } | {
1269
+ readonly expectedInput: Record<string, unknown>;
1270
+ readonly fields?: never;
1271
+ })): AuthTurn;
1272
+ nextPoll(options?: {
1273
+ readonly hintKey?: ProviderLocaleKeyInput;
1274
+ readonly data?: AuthSafeData;
1275
+ readonly turnId?: string;
1276
+ readonly expiresAt?: string;
1277
+ readonly timing?: AuthTurn["timing"];
1278
+ }): AuthTurn;
1279
+ }
1280
+ export interface FlowContext {
1281
+ connectionId?: string;
1282
+ externalRef?: string;
1283
+ tenantId: string;
1284
+ providerId: string;
1285
+ http: HttpClient;
1286
+ stealth: StealthClient;
1287
+ env: EnvContext;
1288
+ credential?: CredentialContext;
1289
+ context: ContextScratchpad;
1290
+ stt: SttContext;
1291
+ auth: AuthFlowTerminalContext;
1292
+ }
1293
+ export interface AuthTurn {
1294
+ kind: string;
1295
+ turnId: string;
1296
+ expiresAt?: string;
1297
+ data?: Record<string, unknown>;
1298
+ expectedInput?: Record<string, unknown>;
1299
+ /**
1300
+ * @deprecated Compatibility-only materialized provider auth hint.
1301
+ * Provider source must emit hintKey; SDK/server boundaries may materialize
1302
+ * this field from provider locale catalogs for legacy clients.
1303
+ */
1304
+ hint?: string;
1305
+ /** Provider locale catalog key for the auth turn hint. */
1306
+ hintKey?: ProviderLocaleKeyInput;
1307
+ timing?: {
1308
+ suggestedPollIntervalMs?: number;
1309
+ maxWaitMs?: number;
1310
+ };
1311
+ }
1312
+ export type AuthFlowStartHandler = (ctx: FlowContext) => Promise<AuthTurn>;
1313
+ export type AuthFlowInputHandler = (ctx: FlowContext, input?: Record<string, unknown>) => Promise<AuthTurn>;
1314
+ export interface AuthFlowDefinition {
1315
+ start: AuthFlowStartHandler;
1316
+ continue: AuthFlowInputHandler;
1317
+ poll?: AuthFlowStartHandler;
1318
+ abort?: AuthFlowStartHandler;
1319
+ refresh?: AuthFlowInputHandler;
1320
+ }
1321
+ export type ProviderStateDurationString = `${number}${"ms" | "s" | "m" | "h" | "d"}` | `PT${string}`;
1322
+ export interface StateNamespaceOptions {
1323
+ /** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
1324
+ defaultTtl: ProviderStateDurationString;
1325
+ /** Maximum allowed TTL; writes are rejected when they exceed this policy. */
1326
+ maxTtl: ProviderStateDurationString;
1327
+ /** Maximum number of live entries in this namespace scope. */
1328
+ maxEntries: number;
1329
+ /** Maximum JSON-encoded value size in bytes. */
1330
+ maxValueBytes: number;
1331
+ }
1332
+ export interface StateWriteOptions {
1333
+ ttl?: ProviderStateDurationString;
1334
+ }
1335
+ export interface StateValue<T = unknown> {
1336
+ key: string;
1337
+ value: T;
1338
+ version: number;
1339
+ expiresAt: string;
1340
+ createdAt: string;
1341
+ updatedAt: string;
1342
+ }
1343
+ export type StateCasResult<T = unknown> = {
1344
+ ok: true;
1345
+ value: StateValue<T>;
1346
+ } | {
1347
+ ok: false;
1348
+ current: StateValue<T> | null;
1349
+ };
1350
+ export interface ProviderStateNamespace {
1351
+ list<T = unknown>(options?: {
1352
+ limit?: number;
1353
+ /** Optional literal key prefix used for scoped recovery scans. */
1354
+ prefix?: string;
1355
+ }): Promise<StateValue<T>[]>;
1356
+ get<T = unknown>(key: string): Promise<StateValue<T> | null>;
1357
+ set<T = unknown>(key: string, value: T, options?: StateWriteOptions): Promise<StateValue<T>>;
1358
+ patch<T extends Record<string, unknown>>(key: string, partial: Partial<T>, options?: StateWriteOptions): Promise<StateValue<T>>;
1359
+ compareAndSet<T = unknown>(key: string, expectedVersion: number, value: T, options?: StateWriteOptions): Promise<StateCasResult<T>>;
1360
+ delete(key: string): Promise<void>;
1361
+ increment(key: string, field: string, delta?: number, options?: StateWriteOptions): Promise<StateValue<Record<string, unknown>>>;
1362
+ }
1363
+ export interface ProviderRuntimeState {
1364
+ namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
1365
+ }
1366
+ export interface ProviderContext {
1367
+ env: EnvContext;
1368
+ credential: CredentialContext;
1369
+ request?: ProviderRequestContext;
1370
+ http: HttpClient;
1371
+ cache: ProviderCache;
1372
+ state: ProviderRuntimeState;
1373
+ stealth: StealthClient;
1374
+ browser: BrowserClient;
1375
+ trace: TraceContext;
1376
+ auth: AuthContext;
1377
+ stt: SttContext;
1378
+ choice: ProviderChoiceContext;
1379
+ }
1380
+ export interface AuthConfig {
1381
+ mode: AuthMode;
1382
+ flow?: AuthFlowDefinition;
1383
+ }
1384
+ export interface ProviderSecretDeclaration {
1385
+ name: string;
1386
+ description?: string;
1387
+ required?: boolean;
1388
+ }
1389
+ export interface CredentialDeclaration {
1390
+ keys: string[];
1391
+ storesReusableSecret?: boolean;
1392
+ justification?: string;
1393
+ }
1394
+ export interface ContextDeclaration {
1395
+ keys: string[];
1396
+ }
1397
+ export type OperationLifecycle = "stable" | "beta" | "deprecated" | "removed";
1398
+ export interface OperationDeprecationMetadata {
1399
+ announcedAt: string;
1400
+ removalAfter: string;
1401
+ replacement?: string;
1402
+ migrationGuide: string;
1403
+ }
1404
+ export interface OperationContractMetadata {
1405
+ /**
1406
+ * Callable operation contract version. Defaults to 1.0.0 for the clean
1407
+ * pre-GA baseline; it intentionally does not fall back to provider.version.
1408
+ */
1409
+ version?: string;
1410
+ lifecycle?: OperationLifecycle;
1411
+ deprecation?: OperationDeprecationMetadata;
1412
+ }
1413
+ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
1414
+ descriptionKey?: ProviderLocaleKeyInput;
1415
+ docs?: OperationDocMeta;
1416
+ whenToUseKeys?: readonly ProviderLocaleKeyInput[];
1417
+ whenNotToUseKeys?: readonly ProviderLocaleKeyInput[];
1418
+ derivations?: Record<string, string>;
1419
+ inputExamples?: readonly OperationInputExample[];
1420
+ annotations?: OperationAnnotations;
1421
+ contract?: OperationContractMetadata;
1422
+ tags?: readonly string[];
1423
+ relatedOperations?: OperationRelationships;
1424
+ toolRouter?: OperationToolRouterMetadata;
1425
+ observability?: OperationObservabilityConfig;
1426
+ transport?: OperationTransport;
1427
+ retryOnAuthRefresh?: boolean;
1428
+ input: TInput;
1429
+ output: TOutput;
1430
+ handler(ctx: ProviderContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
1431
+ fixtures?: {
1432
+ request: InferSchemaOutput<TInput>;
1433
+ response: InferSchemaOutput<TOutput>;
1434
+ };
1435
+ upstream?: {
1436
+ baseUrl?: string;
1437
+ proxy?: boolean | ProviderProxyPolicy;
1438
+ };
1439
+ hints?: Record<string, string>;
1440
+ healthCheck?: HealthCheckSuite<InferSchemaOutput<TInput>, InferSchemaOutput<TOutput>>;
1441
+ healthCheckUnsupported?: HealthCheckUnsupported;
1442
+ }
1443
+ export interface ProviderDefinition {
1444
+ id: string;
1445
+ version: string;
1446
+ runtime: "standard" | "shared" | "browser";
1447
+ allowedHosts?: string[];
1448
+ stealth?: {
1449
+ profile: string;
1450
+ platform: StealthPlatform;
1451
+ };
1452
+ proxy?: ProviderProxyConfig;
1453
+ stt?: ProviderSttConfig;
1454
+ browser?: {
1455
+ engine: BrowserEngine;
1456
+ };
1457
+ auth?: AuthConfig;
1458
+ reviewed?: ProviderReviewed;
1459
+ access?: ProviderAccessConfig;
1460
+ secrets?: ProviderSecretDeclaration[];
1461
+ credential?: CredentialDeclaration;
1462
+ context?: ContextDeclaration;
1463
+ meta: ProviderMeta;
1464
+ operations: Record<string, OperationDefinition<SchemaLike, SchemaLike>>;
1465
+ healthMonitor?: ProviderHealthMonitorConfig;
1466
+ healthJourneys?: readonly HealthJourneyDefinition[];
1467
+ }