@apifuse/provider-sdk 2.1.0-beta.2 → 2.1.0-beta.4
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.
- package/AUTHORING.md +172 -8
- package/CHANGELOG.md +15 -1
- package/README.md +29 -15
- package/SUBMISSION.md +86 -0
- package/bin/apifuse-dev.ts +12 -5
- package/bin/apifuse-pack-check.ts +17 -2
- package/bin/apifuse-pack-smoke.ts +133 -6
- package/bin/apifuse-perf.ts +19 -15
- package/bin/apifuse-record.ts +41 -53
- package/bin/apifuse-submit-check.ts +1052 -0
- package/bin/apifuse.ts +1 -1
- package/package.json +19 -9
- package/src/choice-token.ts +164 -0
- package/src/cli/commands.ts +24 -3
- package/src/cli/create.ts +166 -51
- package/src/cli/templates/provider/README.md.tpl +66 -7
- package/src/cli/templates/provider/dev.ts.tpl +1 -1
- package/src/cli/templates/provider/domain/README.md.tpl +3 -0
- package/src/cli/templates/provider/index.ts.tpl +5 -47
- package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/src/cli/templates/provider/meta.ts.tpl +7 -0
- package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/src/cli/templates/provider/operations/ping.ts.tpl +23 -0
- package/src/cli/templates/provider/schemas/ping.ts.tpl +16 -0
- package/src/cli/templates/provider/start.ts.tpl +1 -1
- package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/src/config/loader.ts +1206 -9
- package/src/define.ts +1648 -43
- package/src/errors.ts +12 -0
- package/src/i18n/catalog.ts +121 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/keys.ts +64 -0
- package/src/index.ts +152 -8
- package/src/lint.ts +297 -42
- package/src/observability.ts +41 -0
- package/src/provider.ts +60 -3
- package/src/public-schema-field-lint.ts +237 -0
- package/src/runtime/auth-flow.ts +7 -0
- package/src/runtime/browser.ts +77 -21
- package/src/runtime/cache.ts +582 -0
- package/src/runtime/executor.ts +13 -1
- package/src/runtime/http.ts +939 -195
- package/src/runtime/insights.ts +11 -11
- package/src/runtime/instrumentation.ts +12 -4
- package/src/runtime/key-derivation.ts +1 -1
- package/src/runtime/keyring.ts +4 -3
- package/src/runtime/proxy-errors.ts +132 -0
- package/src/runtime/proxy-telemetry.ts +253 -0
- package/src/runtime/request-options.ts +66 -0
- package/src/runtime/state.ts +76 -0
- package/src/runtime/stealth.ts +1145 -0
- package/src/runtime/stt.ts +629 -0
- package/src/schema.ts +363 -1
- package/src/server/serve.ts +827 -60
- package/src/server/types.ts +35 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +17 -4
- package/src/types.ts +889 -50
- package/src/runtime/tls.ts +0 -434
- package/src/types/playwright-stealth.d.ts +0 -9
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type ms from "ms";
|
|
2
|
+
|
|
1
3
|
import type { infer as ZodInfer, ZodType } from "zod";
|
|
2
4
|
|
|
3
5
|
/** Minimal Standard Schema v1 shape accepted by provider operations. */
|
|
@@ -45,6 +47,51 @@ export interface OperationInputExample {
|
|
|
45
47
|
rationale?: string;
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
export type OperationRiskClass =
|
|
51
|
+
| "read"
|
|
52
|
+
| "write"
|
|
53
|
+
| "destructive"
|
|
54
|
+
| "external-send";
|
|
55
|
+
|
|
56
|
+
export type OperationApprovalPolicy = "never" | "risk-based" | "always";
|
|
57
|
+
|
|
58
|
+
export interface OperationToolRouterMetadata {
|
|
59
|
+
/** Optional MCP-safe override. Defaults to providerId__operationId. */
|
|
60
|
+
name?: string;
|
|
61
|
+
/** Safety class exposed to Tool Router clients and approval policy. */
|
|
62
|
+
riskClass?: OperationRiskClass;
|
|
63
|
+
/** OpenAI remote-MCP approval hint. Defaults from riskClass. */
|
|
64
|
+
approval?: OperationApprovalPolicy;
|
|
65
|
+
/** Override connection requirement when provider auth + openWorld inference is insufficient. */
|
|
66
|
+
requiresConnection?: boolean;
|
|
67
|
+
/** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
|
|
68
|
+
connectionExternalRefParam?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type OperationSensitivePath = string;
|
|
72
|
+
|
|
73
|
+
export interface OperationObservabilitySensitiveConfig {
|
|
74
|
+
/**
|
|
75
|
+
* Additional dot paths to redact from captured invocation inputs. Use `*`
|
|
76
|
+
* for array elements, for example `items.*.phone`.
|
|
77
|
+
*/
|
|
78
|
+
input?: readonly OperationSensitivePath[];
|
|
79
|
+
/**
|
|
80
|
+
* Additional dot paths to redact from captured invocation outputs. Use `*`
|
|
81
|
+
* for array elements, for example `items.*.paymentUrl`.
|
|
82
|
+
*/
|
|
83
|
+
output?: readonly OperationSensitivePath[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface OperationObservabilityConfig {
|
|
87
|
+
/**
|
|
88
|
+
* Complements schema-level `fields.*()` / `sensitive()` metadata for values
|
|
89
|
+
* that are shape-dependent, provider-normalized, or otherwise easier to
|
|
90
|
+
* express as stable public paths.
|
|
91
|
+
*/
|
|
92
|
+
sensitive?: OperationObservabilitySensitiveConfig;
|
|
93
|
+
}
|
|
94
|
+
|
|
48
95
|
export interface OperationAnnotations {
|
|
49
96
|
readOnly?: boolean;
|
|
50
97
|
destructive?: boolean;
|
|
@@ -80,10 +127,351 @@ export interface OperationAnnotations {
|
|
|
80
127
|
export const OPERATION_TIMEOUT_MS_MIN = 1;
|
|
81
128
|
export const OPERATION_TIMEOUT_MS_MAX = 60_000;
|
|
82
129
|
|
|
130
|
+
export const STREAM_HEARTBEAT_MS_MIN = 1_000;
|
|
131
|
+
export const STREAM_HEARTBEAT_MS_MAX = 60_000;
|
|
132
|
+
export const STREAM_IDLE_TIMEOUT_MS_MIN = 1_000;
|
|
133
|
+
export const STREAM_IDLE_TIMEOUT_MS_MAX = 300_000;
|
|
134
|
+
export const STREAM_MAX_DURATION_MS_MIN = 1_000;
|
|
135
|
+
export const STREAM_MAX_DURATION_MS_MAX = 1_800_000;
|
|
136
|
+
export const STREAM_CHUNK_BYTES_MIN = 1;
|
|
137
|
+
export const STREAM_CHUNK_BYTES_MAX = 1_048_576;
|
|
138
|
+
|
|
139
|
+
export type OperationTransportKind =
|
|
140
|
+
| "json"
|
|
141
|
+
| "sse"
|
|
142
|
+
| "http-stream"
|
|
143
|
+
| "websocket";
|
|
144
|
+
|
|
145
|
+
export interface OperationJsonTransport {
|
|
146
|
+
kind: "json";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface OperationSseTransport {
|
|
150
|
+
kind: "sse";
|
|
151
|
+
heartbeatMs?: number;
|
|
152
|
+
idleTimeoutMs?: number;
|
|
153
|
+
maxDurationMs?: number;
|
|
154
|
+
maxEventBytes?: number;
|
|
155
|
+
resumable?: false | "last-event-id";
|
|
156
|
+
events: Record<string, SchemaLike>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface OperationHttpStreamTransport {
|
|
160
|
+
kind: "http-stream";
|
|
161
|
+
contentType?: string;
|
|
162
|
+
idleTimeoutMs?: number;
|
|
163
|
+
maxDurationMs?: number;
|
|
164
|
+
maxChunkBytes?: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface OperationWebSocketTransport {
|
|
168
|
+
kind: "websocket";
|
|
169
|
+
subprotocols?: readonly string[];
|
|
170
|
+
idleTimeoutMs?: number;
|
|
171
|
+
maxDurationMs?: number;
|
|
172
|
+
maxFrameBytes?: number;
|
|
173
|
+
/**
|
|
174
|
+
* WebSocket Operation metadata is future-ready. Gateway dispatch remains
|
|
175
|
+
* disabled until a gateway-managed session implementation is present.
|
|
176
|
+
*/
|
|
177
|
+
dispatch: "unsupported";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type OperationTransport =
|
|
181
|
+
| OperationJsonTransport
|
|
182
|
+
| OperationSseTransport
|
|
183
|
+
| OperationHttpStreamTransport
|
|
184
|
+
| OperationWebSocketTransport;
|
|
185
|
+
|
|
186
|
+
export const DEFAULT_OPERATION_TRANSPORT: OperationJsonTransport = {
|
|
187
|
+
kind: "json",
|
|
188
|
+
};
|
|
189
|
+
|
|
83
190
|
export interface OperationRelationships {
|
|
84
191
|
alternatives?: string[];
|
|
85
192
|
}
|
|
86
193
|
|
|
194
|
+
export type Iso3166Alpha2CountryCode = Uppercase<string>;
|
|
195
|
+
export type Bcp47Locale = string;
|
|
196
|
+
export type ProviderLocale = Bcp47Locale;
|
|
197
|
+
export type ProviderLocaleKey = string & {
|
|
198
|
+
readonly __brand: "ProviderLocaleKey";
|
|
199
|
+
};
|
|
200
|
+
export type ProviderLocaleKeyInput = ProviderLocaleKey | string;
|
|
201
|
+
export type Iso8601Duration = string;
|
|
202
|
+
export type Rfc3339Instant = string;
|
|
203
|
+
export type IanaTimeZone = string;
|
|
204
|
+
export type Iso4217CurrencyCode = Uppercase<string>;
|
|
205
|
+
export type E164PhoneNumber = `+${string}`;
|
|
206
|
+
|
|
207
|
+
export type SmsOrigin =
|
|
208
|
+
| {
|
|
209
|
+
/** Sender represented as an ITU-T E.164 phone number. */
|
|
210
|
+
kind: "e164";
|
|
211
|
+
value: E164PhoneNumber;
|
|
212
|
+
display?: string;
|
|
213
|
+
}
|
|
214
|
+
| {
|
|
215
|
+
/** Country-local service sender, for example KR 1661-5270. */
|
|
216
|
+
kind: "nationalServiceCode";
|
|
217
|
+
country: Iso3166Alpha2CountryCode;
|
|
218
|
+
value: string;
|
|
219
|
+
display?: string;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export interface SmsOtpExtractionPattern {
|
|
223
|
+
/** RegExp or source string containing exactly one usable OTP capture. */
|
|
224
|
+
pattern: RegExp | string;
|
|
225
|
+
/** Named capture key or one-based numeric capture index. Defaults to first capture. */
|
|
226
|
+
capture?: string | number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface SmsOtpMatcherDefinition {
|
|
230
|
+
id: string;
|
|
231
|
+
country: Iso3166Alpha2CountryCode;
|
|
232
|
+
locale?: Bcp47Locale;
|
|
233
|
+
phoneNumber?: E164PhoneNumber;
|
|
234
|
+
origins: readonly [SmsOrigin, ...SmsOrigin[]];
|
|
235
|
+
code: SmsOtpExtractionPattern;
|
|
236
|
+
maxAge: Iso8601Duration;
|
|
237
|
+
waitTimeout: Iso8601Duration;
|
|
238
|
+
clockSkew?: Iso8601Duration;
|
|
239
|
+
/** Runtime/fixture helper. Not serialized into generated registry artifacts. */
|
|
240
|
+
extractOtp(body: string): string | null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export type SttTranscribeMode = "general" | "otp";
|
|
244
|
+
export type SttPromptPolicy = "none" | "default-hint" | "custom-hint";
|
|
245
|
+
export type SttUnsupportedOptionPolicy = "warn" | "error";
|
|
246
|
+
export type ProviderSttMode = "optional" | "required";
|
|
247
|
+
|
|
248
|
+
export interface ProviderSttConfig {
|
|
249
|
+
mode: ProviderSttMode;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type SttAudioInput = {
|
|
253
|
+
kind: "base64";
|
|
254
|
+
data: string;
|
|
255
|
+
mediaType?: string;
|
|
256
|
+
durationMs?: number;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export interface SttVerificationCodeOptions {
|
|
260
|
+
locale?: Bcp47Locale;
|
|
261
|
+
codeLengths?: number | readonly number[] | { min: number; max: number };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface SttTranscribeRequest {
|
|
265
|
+
audio: SttAudioInput;
|
|
266
|
+
language?: Bcp47Locale;
|
|
267
|
+
mode?: SttTranscribeMode;
|
|
268
|
+
promptPolicy?: SttPromptPolicy;
|
|
269
|
+
initialPrompt?: string;
|
|
270
|
+
unsupportedOptionPolicy?: SttUnsupportedOptionPolicy;
|
|
271
|
+
verificationCode?: SttVerificationCodeOptions;
|
|
272
|
+
timeoutMs?: number;
|
|
273
|
+
maxAudioBytes?: number;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface SttSegment {
|
|
277
|
+
text: string;
|
|
278
|
+
startMs?: number;
|
|
279
|
+
endMs?: number;
|
|
280
|
+
confidence?: number;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface SttUsage {
|
|
284
|
+
audioDurationMs?: number;
|
|
285
|
+
audioBytes?: number;
|
|
286
|
+
billableUnits?: number;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface SttWarning {
|
|
290
|
+
code: "UNSUPPORTED_STT_OPTION" | "PROMPT_IGNORED" | "LOCALE_PARTIAL";
|
|
291
|
+
message: string;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface SttTranscript {
|
|
295
|
+
text: string;
|
|
296
|
+
language?: Bcp47Locale;
|
|
297
|
+
durationMs?: number;
|
|
298
|
+
segments?: readonly SttSegment[];
|
|
299
|
+
usage?: SttUsage;
|
|
300
|
+
warnings?: readonly SttWarning[];
|
|
301
|
+
verificationCode?: VerificationCodeExtractionResult;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export type VerificationCodeCandidateSource =
|
|
305
|
+
| "digits"
|
|
306
|
+
| "spoken_words"
|
|
307
|
+
| "mixed";
|
|
308
|
+
|
|
309
|
+
export interface VerificationCodeCandidate {
|
|
310
|
+
code: string;
|
|
311
|
+
source: VerificationCodeCandidateSource;
|
|
312
|
+
startIndex?: number;
|
|
313
|
+
endIndex?: number;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface VerificationCodeExtractionResult {
|
|
317
|
+
code: string;
|
|
318
|
+
candidates: readonly VerificationCodeCandidate[];
|
|
319
|
+
normalizedText: string;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface SttContext {
|
|
323
|
+
transcribe(request: SttTranscribeRequest): Promise<SttTranscript>;
|
|
324
|
+
extractVerificationCode(
|
|
325
|
+
text: string,
|
|
326
|
+
options?: SttVerificationCodeOptions,
|
|
327
|
+
): VerificationCodeExtractionResult;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface HealthJourneySchedule {
|
|
331
|
+
kind: "interval";
|
|
332
|
+
/** ISO 8601 duration, for example PT8H. */
|
|
333
|
+
interval: Iso8601Duration;
|
|
334
|
+
jitter?: Iso8601Duration;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface HealthJourneyStep {
|
|
338
|
+
id: string;
|
|
339
|
+
description?: string;
|
|
340
|
+
operationId?: string;
|
|
341
|
+
usesSmsMatcher?: string;
|
|
342
|
+
coversOperations?: readonly string[];
|
|
343
|
+
safeBoundary?: "paymentWebviewUrl" | "paymentUrl" | "none";
|
|
344
|
+
kind?: "operation" | "smsOtp" | "assertion" | "journal";
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface HealthJourneyGatewayContext {
|
|
348
|
+
connect?(options?: {
|
|
349
|
+
providerId?: string;
|
|
350
|
+
externalRef?: string;
|
|
351
|
+
authMode?: "credentials" | "oauth2";
|
|
352
|
+
input?: Record<string, unknown>;
|
|
353
|
+
metadata?: Record<string, unknown>;
|
|
354
|
+
}): Promise<{ connectionId: string; rowVersion: number }>;
|
|
355
|
+
disconnect?(connection: {
|
|
356
|
+
connectionId: string;
|
|
357
|
+
rowVersion: number;
|
|
358
|
+
}): Promise<void>;
|
|
359
|
+
execute(
|
|
360
|
+
providerId: string,
|
|
361
|
+
operationId: string,
|
|
362
|
+
input: unknown,
|
|
363
|
+
options?: {
|
|
364
|
+
connectionId?: string;
|
|
365
|
+
requestId?: string;
|
|
366
|
+
/**
|
|
367
|
+
* Set false when the journey will record the semantic operation
|
|
368
|
+
* outcome itself through `ctx.event.operation()`. Transport success
|
|
369
|
+
* must not become a competing public health sample in that case.
|
|
370
|
+
*/
|
|
371
|
+
recordOperationEvent?: boolean;
|
|
372
|
+
},
|
|
373
|
+
): Promise<{
|
|
374
|
+
data: unknown;
|
|
375
|
+
status: number;
|
|
376
|
+
duration: number;
|
|
377
|
+
meta?: Record<string, unknown>;
|
|
378
|
+
}>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface SmsPhoneIdentity {
|
|
382
|
+
id: string;
|
|
383
|
+
country: Iso3166Alpha2CountryCode | string;
|
|
384
|
+
e164: E164PhoneNumber | string;
|
|
385
|
+
nationalNumber: string;
|
|
386
|
+
displayName?: string;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface HealthJourneySmsContext {
|
|
390
|
+
resolvePhone(params?: { matcherId?: string }): Promise<SmsPhoneIdentity>;
|
|
391
|
+
waitForOtp(params: {
|
|
392
|
+
matcherId: string;
|
|
393
|
+
attemptId: string;
|
|
394
|
+
phoneId?: string;
|
|
395
|
+
phoneNumber?: string;
|
|
396
|
+
signal?: AbortSignal;
|
|
397
|
+
}): Promise<{ code: string; messageId: string; receivedAt: string }>;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface HealthJourneyJournalContext {
|
|
401
|
+
sideEffect<T>(params: {
|
|
402
|
+
stepId: string;
|
|
403
|
+
kind: string;
|
|
404
|
+
idempotencyKey: string;
|
|
405
|
+
run: () => Promise<T>;
|
|
406
|
+
}): Promise<T>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface HealthJourneyEventContext {
|
|
410
|
+
/**
|
|
411
|
+
* Record an operation-level health outcome that was proven by the journey but
|
|
412
|
+
* not emitted by a direct `ctx.gateway.execute()` call, such as a recovery or
|
|
413
|
+
* manual-review assertion. This is intentionally narrow; it is not a generic
|
|
414
|
+
* event bus.
|
|
415
|
+
*/
|
|
416
|
+
operation(params: {
|
|
417
|
+
operationId: string;
|
|
418
|
+
status: "ok" | "degraded" | "down" | "unknown" | "not_reached";
|
|
419
|
+
stepId?: string;
|
|
420
|
+
label?: string;
|
|
421
|
+
error?: string;
|
|
422
|
+
latencyMs?: number;
|
|
423
|
+
statusCode?: number;
|
|
424
|
+
metadata?: Record<string, unknown>;
|
|
425
|
+
}): Promise<void>;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface HealthJourneyRunContext {
|
|
429
|
+
attemptId: string;
|
|
430
|
+
providerId: string;
|
|
431
|
+
journeyId: string;
|
|
432
|
+
gateway: HealthJourneyGatewayContext;
|
|
433
|
+
sms: HealthJourneySmsContext;
|
|
434
|
+
journal: HealthJourneyJournalContext;
|
|
435
|
+
state: ProviderRuntimeState;
|
|
436
|
+
event: HealthJourneyEventContext;
|
|
437
|
+
signal: AbortSignal;
|
|
438
|
+
secrets: Record<string, string | undefined>;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export type HealthJourneyManualTriggerPolicy =
|
|
442
|
+
| { enabled: false; reason?: string }
|
|
443
|
+
| {
|
|
444
|
+
enabled: true;
|
|
445
|
+
requiresAcknowledgement: boolean;
|
|
446
|
+
risk: "read_only" | "writes_external_state" | "sms_or_payment";
|
|
447
|
+
/** ISO 8601 duration. Minimum time between manual executions. */
|
|
448
|
+
minManualInterval: Iso8601Duration;
|
|
449
|
+
publicRationale: string;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
export interface HealthJourneyRunResult {
|
|
453
|
+
status?: "ok" | "degraded" | "down" | "unknown";
|
|
454
|
+
label?: string;
|
|
455
|
+
metadata?: Record<string, unknown>;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface HealthJourneyDefinition {
|
|
459
|
+
id: string;
|
|
460
|
+
title?: string;
|
|
461
|
+
description?: string;
|
|
462
|
+
schedule: HealthJourneySchedule;
|
|
463
|
+
coversOperations: readonly [string, ...string[]];
|
|
464
|
+
timeout?: Iso8601Duration;
|
|
465
|
+
cooldown?: Iso8601Duration;
|
|
466
|
+
smsMatchers?: readonly SmsOtpMatcherDefinition[];
|
|
467
|
+
requiredSecrets?: readonly string[];
|
|
468
|
+
manualTrigger?: HealthJourneyManualTriggerPolicy;
|
|
469
|
+
steps: readonly [HealthJourneyStep, ...HealthJourneyStep[]];
|
|
470
|
+
run?: (
|
|
471
|
+
ctx: HealthJourneyRunContext,
|
|
472
|
+
) => Promise<HealthJourneyRunResult | undefined>;
|
|
473
|
+
}
|
|
474
|
+
|
|
87
475
|
/**
|
|
88
476
|
* Health-check authoring surface owned by `@apifuse/provider-sdk`.
|
|
89
477
|
*
|
|
@@ -95,17 +483,14 @@ export interface OperationRelationships {
|
|
|
95
483
|
* See `openspec/changes/enforce-sdk-operation-health-suite/design.md` §D1.
|
|
96
484
|
*/
|
|
97
485
|
|
|
98
|
-
/** Polling
|
|
99
|
-
export type ProbeInterval =
|
|
100
|
-
| "30s"
|
|
101
|
-
| "1m"
|
|
102
|
-
| "3m"
|
|
103
|
-
| "5m"
|
|
104
|
-
| "15m"
|
|
105
|
-
| "30m"
|
|
106
|
-
| "1h"
|
|
107
|
-
| "24h";
|
|
486
|
+
/** Polling interval duration accepted by the health-monitor runtime. */
|
|
487
|
+
export type ProbeInterval = ms.StringValue;
|
|
108
488
|
|
|
489
|
+
/**
|
|
490
|
+
* Common probe interval examples retained for discoverability/backwards
|
|
491
|
+
* compatibility. This list is not exhaustive; any positive `ms`-style duration
|
|
492
|
+
* string accepted by `@types/ms` (for example `2m`, `8h`, or `1 day`) is valid.
|
|
493
|
+
*/
|
|
109
494
|
export const PROBE_INTERVALS: readonly ProbeInterval[] = [
|
|
110
495
|
"30s",
|
|
111
496
|
"1m",
|
|
@@ -114,9 +499,16 @@ export const PROBE_INTERVALS: readonly ProbeInterval[] = [
|
|
|
114
499
|
"15m",
|
|
115
500
|
"30m",
|
|
116
501
|
"1h",
|
|
502
|
+
"2h",
|
|
503
|
+
"8h",
|
|
117
504
|
"24h",
|
|
118
505
|
] as const;
|
|
119
506
|
|
|
507
|
+
export const HEALTH_CHECK_TIMEOUT_MS_MIN = 1;
|
|
508
|
+
export const HEALTH_CHECK_TIMEOUT_MS_MAX = 60_000;
|
|
509
|
+
export const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MIN = 1;
|
|
510
|
+
export const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MAX = 60_000;
|
|
511
|
+
|
|
120
512
|
/**
|
|
121
513
|
* Context passed to a `HealthCheckCase.assertions` lambda.
|
|
122
514
|
* `data` is typed against the operation's declared output schema (TOutput).
|
|
@@ -128,6 +520,8 @@ export interface HealthCheckAssertionContext<TOutput = unknown> {
|
|
|
128
520
|
readonly status: number;
|
|
129
521
|
/** Wall-clock duration of the operation invocation, in milliseconds. */
|
|
130
522
|
readonly durationMs: number;
|
|
523
|
+
/** Optional provider response metadata such as cache hit/stale flags. */
|
|
524
|
+
readonly meta?: Record<string, unknown>;
|
|
131
525
|
}
|
|
132
526
|
|
|
133
527
|
/**
|
|
@@ -175,6 +569,8 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
|
|
|
175
569
|
| Promise<HealthCheckCaseResult>;
|
|
176
570
|
/** Override per-case degradation threshold (ms); falls back to the suite default. */
|
|
177
571
|
degradedThresholdMs?: number;
|
|
572
|
+
/** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
|
|
573
|
+
timeoutMs?: number;
|
|
178
574
|
/** Expected outcome for "negative" cases (e.g., expecting a degraded baseline). Default: `"ok"`. */
|
|
179
575
|
expectedStatus?: "ok" | "degraded";
|
|
180
576
|
/** Runtime gate (env-driven); if returns false the case is skipped & logged. */
|
|
@@ -190,6 +586,8 @@ export interface HealthCheckSuite<TInput = unknown, TOutput = unknown> {
|
|
|
190
586
|
interval: ProbeInterval;
|
|
191
587
|
/** Per-case timeout in milliseconds. Default: 30000. */
|
|
192
588
|
timeoutMs?: number;
|
|
589
|
+
/** Default degradation threshold for cases in this suite. Default: runtime threshold. */
|
|
590
|
+
degradedThresholdMs?: number;
|
|
193
591
|
/** Non-empty list of cases. Empty arrays are rejected at definition time. */
|
|
194
592
|
cases: [
|
|
195
593
|
HealthCheckCase<TInput, TOutput>,
|
|
@@ -225,28 +623,49 @@ export interface HealthCheckUnsupported {
|
|
|
225
623
|
*/
|
|
226
624
|
export interface ProviderHealthMonitorConfig {
|
|
227
625
|
/**
|
|
228
|
-
*
|
|
626
|
+
* Provider-wide default probe timeout in milliseconds. Individual
|
|
627
|
+
* `healthCheck.timeoutMs` and `healthCheck.cases[].timeoutMs` values take
|
|
628
|
+
* precedence. Defaults to the monitor runtime default.
|
|
629
|
+
*/
|
|
630
|
+
defaultProbeTimeoutMs?: number;
|
|
631
|
+
/**
|
|
632
|
+
* Provider-wide default latency threshold in milliseconds before an
|
|
633
|
+
* otherwise successful probe is marked degraded. Suite/case thresholds take
|
|
634
|
+
* precedence. Defaults to the monitor runtime default.
|
|
635
|
+
*/
|
|
636
|
+
defaultDegradedThresholdMs?: number;
|
|
637
|
+
/**
|
|
638
|
+
* Env-secret key names (e.g., "APIFUSE__HEALTH_MONITOR__CATCHTABLE_PHONE") the
|
|
229
639
|
* synthetic-monitor runtime needs to execute probes that declare
|
|
230
640
|
* `requiresConnection: true`.
|
|
231
641
|
*/
|
|
232
642
|
requiredSecrets?: string[];
|
|
233
643
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
|
|
644
|
+
* Mapping from provider auth ceremony input fields to runtime env-secret
|
|
645
|
+
* names. The health-monitor uses this to create a fresh connection for
|
|
646
|
+
* `requiresConnection: true` probes, then disconnects after execution.
|
|
647
|
+
*/
|
|
648
|
+
credentialInputs?: Record<string, string>;
|
|
649
|
+
/**
|
|
650
|
+
* Runtime probe overrides keyed by generated registry probe id. Use this for
|
|
651
|
+
* operation health checks that need a runtime-specific interval or threshold
|
|
652
|
+
* without changing the provider-authored default suite.
|
|
238
653
|
*/
|
|
239
654
|
probeOverrides?: Record<string, HealthMonitorProbeOverride>;
|
|
240
655
|
/**
|
|
241
656
|
* Override the default service account ID for this provider's probes.
|
|
242
|
-
* Defaults to the runtime's `
|
|
657
|
+
* Defaults to the runtime's `APIFUSE__HEALTH_MONITOR__SERVICE_ACCOUNT_ID` env var.
|
|
243
658
|
*/
|
|
244
659
|
serviceAccount?: string;
|
|
245
660
|
}
|
|
246
661
|
|
|
247
662
|
export interface HealthMonitorProbeOverride {
|
|
248
|
-
/** Optional runtime interval override
|
|
663
|
+
/** Optional runtime interval override as a positive `ms`-style duration string. */
|
|
249
664
|
interval?: ProbeInterval;
|
|
665
|
+
/** Optional timeout override for generated registry probes. */
|
|
666
|
+
timeoutMs?: number;
|
|
667
|
+
/** Optional degraded threshold override for generated registry probes. */
|
|
668
|
+
degradedThresholdMs?: number;
|
|
250
669
|
}
|
|
251
670
|
|
|
252
671
|
export interface OperationErrorCode {
|
|
@@ -257,10 +676,11 @@ export interface OperationErrorCode {
|
|
|
257
676
|
}
|
|
258
677
|
|
|
259
678
|
export interface OperationDocMeta {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
679
|
+
titleKey?: ProviderLocaleKeyInput;
|
|
680
|
+
descriptionKey?: ProviderLocaleKeyInput;
|
|
681
|
+
summaryKey?: ProviderLocaleKeyInput;
|
|
682
|
+
markdownKey?: ProviderLocaleKeyInput;
|
|
683
|
+
normalizationNotesKeys?: ProviderLocaleKeyInput[];
|
|
264
684
|
requestExample?: Record<string, unknown>;
|
|
265
685
|
responseExample?: unknown;
|
|
266
686
|
errorCodes?: OperationErrorCode[];
|
|
@@ -269,7 +689,6 @@ export interface OperationDocMeta {
|
|
|
269
689
|
export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
|
|
270
690
|
|
|
271
691
|
export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
|
|
272
|
-
|
|
273
692
|
export interface BrowserOptions {
|
|
274
693
|
headless?: boolean;
|
|
275
694
|
stealth?: boolean;
|
|
@@ -295,42 +714,252 @@ export type ConnectionMode = AuthMode;
|
|
|
295
714
|
|
|
296
715
|
export type ProviderReviewed = "first-party" | "community" | "staging";
|
|
297
716
|
|
|
717
|
+
export type ProviderAccessVisibility = "public" | "early_access";
|
|
718
|
+
|
|
719
|
+
export type ProviderProxyMode = "disabled" | "optional" | "required";
|
|
720
|
+
|
|
721
|
+
export type ProviderProxyProvider = "smartproxy" | "decodo" | "custom";
|
|
722
|
+
|
|
723
|
+
export type ProviderProxySessionAffinity =
|
|
724
|
+
| "request"
|
|
725
|
+
| "operation"
|
|
726
|
+
| "auth-flow"
|
|
727
|
+
| "connection";
|
|
728
|
+
|
|
729
|
+
export interface ProviderProxyPolicy {
|
|
730
|
+
/**
|
|
731
|
+
* Provider intent only. Transport details such as raw CONNECT, origin
|
|
732
|
+
* certificate verification, and vendor allocator endpoints are SDK-owned.
|
|
733
|
+
*/
|
|
734
|
+
mode: ProviderProxyMode;
|
|
735
|
+
provider?: ProviderProxyProvider;
|
|
736
|
+
geo?: {
|
|
737
|
+
/** ISO 3166-1 alpha-2 country code, for example KR or US. */
|
|
738
|
+
country?: Iso3166Alpha2CountryCode;
|
|
739
|
+
subdivision?: string;
|
|
740
|
+
city?: string;
|
|
741
|
+
};
|
|
742
|
+
session?: {
|
|
743
|
+
affinity?: ProviderProxySessionAffinity;
|
|
744
|
+
lifetimeMinutes?: number;
|
|
745
|
+
poolSize?: number;
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
|
|
750
|
+
|
|
751
|
+
export interface ProviderAccessConfig {
|
|
752
|
+
/**
|
|
753
|
+
* Provider-level rollout visibility.
|
|
754
|
+
*
|
|
755
|
+
* - `public`: visible in public docs/catalog/OpenAPI and callable through
|
|
756
|
+
* the existing provider policy stack.
|
|
757
|
+
* - `early_access`: hidden from public discovery and callable only when the
|
|
758
|
+
* active customer organization has a provider-level access grant.
|
|
759
|
+
*
|
|
760
|
+
* This is intentionally provider-level only. It does not alter auth mode,
|
|
761
|
+
* operation schemas, health-check authoring, `openWorld`, or Connection
|
|
762
|
+
* requirements.
|
|
763
|
+
*/
|
|
764
|
+
visibility?: ProviderAccessVisibility;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export type ProviderLogoSource = "asset" | "monogram" | "none";
|
|
768
|
+
|
|
769
|
+
export type ProviderLogoProfile =
|
|
770
|
+
| {
|
|
771
|
+
source: "asset";
|
|
772
|
+
path: string;
|
|
773
|
+
/**
|
|
774
|
+
* Absolute, customer-renderable URL emitted by discovery projections.
|
|
775
|
+
* Provider source definitions may omit this and let the registry projection
|
|
776
|
+
* derive it from the committed public asset path.
|
|
777
|
+
*/
|
|
778
|
+
url?: string;
|
|
779
|
+
background?: string;
|
|
780
|
+
}
|
|
781
|
+
| {
|
|
782
|
+
source: "monogram" | "none";
|
|
783
|
+
background?: string;
|
|
784
|
+
fallbackReason: string;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
export type ProviderPublicConnectionMode =
|
|
788
|
+
| "apifuse_managed"
|
|
789
|
+
| "workspace_enabled"
|
|
790
|
+
| "user_connected"
|
|
791
|
+
| "no_connection_required";
|
|
792
|
+
|
|
793
|
+
export type ProviderSupportLevel = "stable" | "beta" | "experimental";
|
|
794
|
+
|
|
795
|
+
export interface ProviderPublicProfile {
|
|
796
|
+
displayNameKey?: ProviderLocaleKeyInput;
|
|
797
|
+
shortDescriptionKey?: ProviderLocaleKeyInput;
|
|
798
|
+
longDescriptionKey?: ProviderLocaleKeyInput;
|
|
799
|
+
logo?: ProviderLogoProfile;
|
|
800
|
+
category?: string;
|
|
801
|
+
tags?: string[];
|
|
802
|
+
capabilityKeys?: ProviderLocaleKeyInput[];
|
|
803
|
+
examplePromptKeys?: ProviderLocaleKeyInput[];
|
|
804
|
+
setupSummaryKey?: ProviderLocaleKeyInput;
|
|
805
|
+
connectionMode?: ProviderPublicConnectionMode;
|
|
806
|
+
requirementKeys?: ProviderLocaleKeyInput[];
|
|
807
|
+
limitationKeys?: ProviderLocaleKeyInput[];
|
|
808
|
+
availability?: {
|
|
809
|
+
regions?: string[];
|
|
810
|
+
supportLevel?: ProviderSupportLevel;
|
|
811
|
+
};
|
|
812
|
+
/**
|
|
813
|
+
* Brand primary color as a 6-digit hex string (e.g. "#1a73e8").
|
|
814
|
+
* Single source of truth for all provider-specific color expressions
|
|
815
|
+
* (mood wash, monogram fallback, icon tint). The UI derives subtle washes
|
|
816
|
+
* via color-mix; provider definitions do not control mood percentages.
|
|
817
|
+
*/
|
|
818
|
+
primaryColor?: string;
|
|
819
|
+
}
|
|
820
|
+
|
|
298
821
|
export interface ProviderMeta {
|
|
299
822
|
displayName: string;
|
|
300
|
-
|
|
823
|
+
displayNameKey?: ProviderLocaleKeyInput;
|
|
824
|
+
descriptionKey: ProviderLocaleKeyInput;
|
|
301
825
|
category: string;
|
|
302
826
|
tags?: string[];
|
|
303
827
|
icon?: string;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
828
|
+
docTitleKey?: ProviderLocaleKeyInput;
|
|
829
|
+
docDescriptionKey?: ProviderLocaleKeyInput;
|
|
830
|
+
docSummaryKey?: ProviderLocaleKeyInput;
|
|
831
|
+
docMarkdownKey?: ProviderLocaleKeyInput;
|
|
832
|
+
normalizationNotesKeys?: ProviderLocaleKeyInput[];
|
|
308
833
|
environment?: "staging";
|
|
309
834
|
purpose?: string;
|
|
835
|
+
purposeKey?: ProviderLocaleKeyInput;
|
|
836
|
+
publicProfile?: ProviderPublicProfile;
|
|
837
|
+
contract?: {
|
|
838
|
+
publicSchemaFieldNames?: "normalized";
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
export type RequestParamPrimitive =
|
|
843
|
+
| string
|
|
844
|
+
| number
|
|
845
|
+
| boolean
|
|
846
|
+
| null
|
|
847
|
+
| undefined;
|
|
848
|
+
export type RequestParamValue =
|
|
849
|
+
| RequestParamPrimitive
|
|
850
|
+
| readonly RequestParamPrimitive[];
|
|
851
|
+
export type RequestParams = Record<string, RequestParamValue>;
|
|
852
|
+
|
|
853
|
+
export const HttpRetryPreset = {
|
|
854
|
+
Off: "off",
|
|
855
|
+
TransportTransient: "transport_transient",
|
|
856
|
+
SafeRead: "safe_read",
|
|
857
|
+
AggressiveRead: "aggressive_read",
|
|
858
|
+
RateLimitAware: "rate_limit_aware",
|
|
859
|
+
} as const;
|
|
860
|
+
export type HttpRetryPreset =
|
|
861
|
+
(typeof HttpRetryPreset)[keyof typeof HttpRetryPreset];
|
|
862
|
+
|
|
863
|
+
export const HttpRetryJitter = {
|
|
864
|
+
None: "none",
|
|
865
|
+
Full: "full",
|
|
866
|
+
Equal: "equal",
|
|
867
|
+
} as const;
|
|
868
|
+
export type HttpRetryJitter =
|
|
869
|
+
(typeof HttpRetryJitter)[keyof typeof HttpRetryJitter];
|
|
870
|
+
|
|
871
|
+
export const HttpRetryDelayStrategy = {
|
|
872
|
+
Fixed: "fixed",
|
|
873
|
+
Exponential: "exponential",
|
|
874
|
+
} as const;
|
|
875
|
+
export type HttpRetryDelayStrategy =
|
|
876
|
+
(typeof HttpRetryDelayStrategy)[keyof typeof HttpRetryDelayStrategy];
|
|
877
|
+
|
|
878
|
+
export const HttpRetryAfterPolicy = {
|
|
879
|
+
Ignore: "ignore",
|
|
880
|
+
/** Honor Retry-After up to maxDelayMs. */
|
|
881
|
+
Respect: "respect",
|
|
882
|
+
/** Honor Retry-After but also cap it to the SDK-computed backoff delay. */
|
|
883
|
+
Cap: "cap",
|
|
884
|
+
} as const;
|
|
885
|
+
export type HttpRetryAfterPolicy =
|
|
886
|
+
(typeof HttpRetryAfterPolicy)[keyof typeof HttpRetryAfterPolicy];
|
|
887
|
+
|
|
888
|
+
export const HttpRetryUnsafeMethodPolicy = {
|
|
889
|
+
Reject: "reject",
|
|
890
|
+
AllowExplicitUnsafe: "allow_explicit_unsafe",
|
|
891
|
+
} as const;
|
|
892
|
+
export type HttpRetryUnsafeMethodPolicy =
|
|
893
|
+
(typeof HttpRetryUnsafeMethodPolicy)[keyof typeof HttpRetryUnsafeMethodPolicy];
|
|
894
|
+
|
|
895
|
+
export interface HttpRetryOptions {
|
|
896
|
+
preset?: HttpRetryPreset;
|
|
897
|
+
/** Total logical ctx.http attempts, including the first attempt. */
|
|
898
|
+
attempts?: number;
|
|
899
|
+
methods?: readonly HttpMethod[];
|
|
900
|
+
statusCodes?: readonly number[];
|
|
901
|
+
errorCodes?: readonly string[];
|
|
902
|
+
delayStrategy?: HttpRetryDelayStrategy;
|
|
903
|
+
baseDelayMs?: number;
|
|
904
|
+
maxDelayMs?: number;
|
|
905
|
+
jitter?: HttpRetryJitter;
|
|
906
|
+
retryAfter?: HttpRetryAfterPolicy;
|
|
907
|
+
unsafeMethodPolicy?: HttpRetryUnsafeMethodPolicy;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
export interface HttpRetrySummary {
|
|
911
|
+
attempts: number;
|
|
912
|
+
retries: number;
|
|
913
|
+
preset?: HttpRetryPreset;
|
|
914
|
+
transport: "native";
|
|
915
|
+
lastErrorCode?: string;
|
|
916
|
+
lastStatus?: number;
|
|
310
917
|
}
|
|
311
918
|
|
|
312
919
|
export interface RequestOptions {
|
|
313
920
|
headers?: Record<string, string>;
|
|
314
|
-
params?:
|
|
921
|
+
params?: RequestParams;
|
|
315
922
|
proxy?: string;
|
|
316
923
|
timeout?: number;
|
|
924
|
+
/**
|
|
925
|
+
* Defaults to true. Set to false when callers need to inspect upstream
|
|
926
|
+
* non-2xx bodies themselves instead of converting them to TransportError.
|
|
927
|
+
*/
|
|
928
|
+
throwOnHttpError?: boolean;
|
|
929
|
+
retry?: boolean | HttpRetryPreset | HttpRetryOptions;
|
|
317
930
|
}
|
|
318
931
|
|
|
319
|
-
export
|
|
320
|
-
|
|
932
|
+
export type HttpMethod =
|
|
933
|
+
| "HEAD"
|
|
934
|
+
| "head"
|
|
935
|
+
| "GET"
|
|
936
|
+
| "get"
|
|
937
|
+
| "POST"
|
|
938
|
+
| "post"
|
|
939
|
+
| "PUT"
|
|
940
|
+
| "put"
|
|
941
|
+
| "DELETE"
|
|
942
|
+
| "delete"
|
|
943
|
+
| "OPTIONS"
|
|
944
|
+
| "options"
|
|
945
|
+
| "TRACE"
|
|
946
|
+
| "trace"
|
|
947
|
+
| "PATCH"
|
|
948
|
+
| "patch";
|
|
949
|
+
|
|
950
|
+
export interface StealthFetchOptions extends RequestOptions {
|
|
951
|
+
method?: HttpMethod;
|
|
321
952
|
body?: string | Buffer;
|
|
953
|
+
/** Override the configured browser-like stealth profile for this request. */
|
|
322
954
|
profile?: string;
|
|
323
955
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
956
|
+
* Stealth transport certificate controls. Use only for proxy products that
|
|
957
|
+
* terminate CONNECT with a private CA instead of tunneling the origin
|
|
958
|
+
* certificate chain.
|
|
326
959
|
*/
|
|
327
|
-
|
|
328
|
-
tls?: {
|
|
329
|
-
ja3?: string;
|
|
330
|
-
h2?: Record<string, unknown>;
|
|
960
|
+
stealth?: {
|
|
331
961
|
insecureSkipVerify?: boolean;
|
|
332
962
|
};
|
|
333
|
-
headerOrder?: string[];
|
|
334
963
|
}
|
|
335
964
|
|
|
336
965
|
export interface CookieJar {
|
|
@@ -340,7 +969,7 @@ export interface CookieJar {
|
|
|
340
969
|
find?(predicate: (cookie: string) => boolean): string | undefined;
|
|
341
970
|
}
|
|
342
971
|
|
|
343
|
-
export interface
|
|
972
|
+
export interface DeclarativeStealthResponse {
|
|
344
973
|
status: number;
|
|
345
974
|
ok: boolean;
|
|
346
975
|
headers: Record<string, string>;
|
|
@@ -352,14 +981,15 @@ export interface DeclarativeTlsResponse {
|
|
|
352
981
|
json<T>(): Promise<T>;
|
|
353
982
|
}
|
|
354
983
|
|
|
355
|
-
export type
|
|
984
|
+
export type StealthResponse = DeclarativeStealthResponse;
|
|
356
985
|
|
|
357
986
|
export type RequestWithMethodOptions = RequestOptions & {
|
|
358
987
|
method?: string;
|
|
988
|
+
body?: unknown;
|
|
359
989
|
};
|
|
360
990
|
|
|
361
|
-
export interface
|
|
362
|
-
fetch(url: string, options?:
|
|
991
|
+
export interface StealthSession {
|
|
992
|
+
fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
|
|
363
993
|
close(): void;
|
|
364
994
|
}
|
|
365
995
|
|
|
@@ -369,6 +999,9 @@ export interface ApiFuseResponse<T> {
|
|
|
369
999
|
requestId: string;
|
|
370
1000
|
duration: number;
|
|
371
1001
|
cached?: boolean;
|
|
1002
|
+
stale?: boolean;
|
|
1003
|
+
cache?: ProviderCacheResponseMeta;
|
|
1004
|
+
retry?: HttpRetrySummary;
|
|
372
1005
|
};
|
|
373
1006
|
}
|
|
374
1007
|
|
|
@@ -381,6 +1014,37 @@ export interface HttpResponse<T = unknown> {
|
|
|
381
1014
|
text(): Promise<string>;
|
|
382
1015
|
}
|
|
383
1016
|
|
|
1017
|
+
export interface HttpStreamResponse {
|
|
1018
|
+
status: number;
|
|
1019
|
+
ok: boolean;
|
|
1020
|
+
headers: Record<string, string>;
|
|
1021
|
+
body: ReadableStream<Uint8Array>;
|
|
1022
|
+
bytes(): AsyncIterable<Uint8Array>;
|
|
1023
|
+
textChunks(): AsyncIterable<string>;
|
|
1024
|
+
lines(): AsyncIterable<string>;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
export interface SseMessage {
|
|
1028
|
+
event: string;
|
|
1029
|
+
data: string;
|
|
1030
|
+
id?: string;
|
|
1031
|
+
retry?: number;
|
|
1032
|
+
json<T = unknown>(): T;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
export interface ProviderStreamEvent<TData = unknown> {
|
|
1036
|
+
event: string;
|
|
1037
|
+
data: TData;
|
|
1038
|
+
id?: string;
|
|
1039
|
+
retry?: number;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
export type OperationHandlerResult<TOutput> =
|
|
1043
|
+
| TOutput
|
|
1044
|
+
| Response
|
|
1045
|
+
| ReadableStream<Uint8Array>
|
|
1046
|
+
| AsyncIterable<ProviderStreamEvent>;
|
|
1047
|
+
|
|
384
1048
|
export interface HttpClient {
|
|
385
1049
|
request(url: string, opts?: RequestWithMethodOptions): Promise<HttpResponse>;
|
|
386
1050
|
get(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
@@ -395,11 +1059,82 @@ export interface HttpClient {
|
|
|
395
1059
|
options?: RequestOptions,
|
|
396
1060
|
): Promise<HttpResponse>;
|
|
397
1061
|
delete(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
1062
|
+
stream(
|
|
1063
|
+
url: string,
|
|
1064
|
+
options?: RequestWithMethodOptions,
|
|
1065
|
+
): Promise<HttpStreamResponse>;
|
|
1066
|
+
sse(
|
|
1067
|
+
url: string,
|
|
1068
|
+
options?: RequestWithMethodOptions,
|
|
1069
|
+
): Promise<AsyncIterable<SseMessage>>;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
export interface ProviderCacheKeyOptions {
|
|
1073
|
+
/**
|
|
1074
|
+
* Additional field names to omit from stable key material. The SDK always
|
|
1075
|
+
* omits known secret-bearing names such as serviceKey, authorization,
|
|
1076
|
+
* cookie, token, password, and secret.
|
|
1077
|
+
*/
|
|
1078
|
+
redactFields?: string[];
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
export interface ProviderCacheGetOrSetOptions {
|
|
1082
|
+
/** Freshness TTL. A fresh hit returns without calling the loader. */
|
|
1083
|
+
ttlMs: number;
|
|
1084
|
+
/**
|
|
1085
|
+
* Optional stale window after ttlMs. If the loader fails while the entry is
|
|
1086
|
+
* still inside this window, stale data is returned and marked stale.
|
|
1087
|
+
*/
|
|
1088
|
+
staleIfErrorMs?: number;
|
|
1089
|
+
/** Optional jitter applied to writes to avoid synchronized expiry. */
|
|
1090
|
+
jitterPct?: number;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
export interface ProviderCacheLookupMeta {
|
|
1094
|
+
key: string;
|
|
1095
|
+
hit: boolean;
|
|
1096
|
+
stale: boolean;
|
|
1097
|
+
ageMs?: number;
|
|
1098
|
+
source: "redis" | "memory" | "loader";
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
export interface ProviderCacheResult<T> {
|
|
1102
|
+
value: T;
|
|
1103
|
+
meta: ProviderCacheLookupMeta;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
export interface ProviderCacheResponseMeta {
|
|
1107
|
+
hit: boolean;
|
|
1108
|
+
stale: boolean;
|
|
1109
|
+
keys: string[];
|
|
1110
|
+
source?: "redis" | "memory" | "loader" | "mixed";
|
|
398
1111
|
}
|
|
399
1112
|
|
|
400
|
-
export interface
|
|
401
|
-
|
|
402
|
-
|
|
1113
|
+
export interface ProviderCache {
|
|
1114
|
+
key(
|
|
1115
|
+
namespace: string,
|
|
1116
|
+
parts: unknown,
|
|
1117
|
+
options?: ProviderCacheKeyOptions,
|
|
1118
|
+
): string;
|
|
1119
|
+
get<T = unknown>(key: string): Promise<ProviderCacheResult<T> | null>;
|
|
1120
|
+
set<T = unknown>(
|
|
1121
|
+
key: string,
|
|
1122
|
+
value: T,
|
|
1123
|
+
options: ProviderCacheGetOrSetOptions,
|
|
1124
|
+
): Promise<void>;
|
|
1125
|
+
delete(key: string): Promise<void>;
|
|
1126
|
+
getOrSet<T = unknown>(
|
|
1127
|
+
key: string,
|
|
1128
|
+
loader: () => Promise<T>,
|
|
1129
|
+
options: ProviderCacheGetOrSetOptions,
|
|
1130
|
+
): Promise<ProviderCacheResult<T>>;
|
|
1131
|
+
responseMeta(): ProviderCacheResponseMeta | undefined;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
export interface StealthClient {
|
|
1135
|
+
fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
|
|
1136
|
+
createSession(opts?: { profile?: string }): StealthSession;
|
|
1137
|
+
close?(): void;
|
|
403
1138
|
}
|
|
404
1139
|
|
|
405
1140
|
export interface BrowserClient {
|
|
@@ -476,8 +1211,10 @@ export interface FlowContext {
|
|
|
476
1211
|
tenantId: string;
|
|
477
1212
|
providerId: string;
|
|
478
1213
|
http: HttpClient;
|
|
1214
|
+
stealth: StealthClient;
|
|
479
1215
|
env: EnvContext;
|
|
480
1216
|
context: ContextScratchpad;
|
|
1217
|
+
stt: SttContext;
|
|
481
1218
|
}
|
|
482
1219
|
|
|
483
1220
|
export interface AuthTurn {
|
|
@@ -505,15 +1242,89 @@ export interface AuthFlowDefinition {
|
|
|
505
1242
|
abort?: AuthFlowHandler;
|
|
506
1243
|
}
|
|
507
1244
|
|
|
1245
|
+
export type ProviderStateDurationString =
|
|
1246
|
+
| `${number}${"ms" | "s" | "m" | "h" | "d"}`
|
|
1247
|
+
| `PT${string}`;
|
|
1248
|
+
|
|
1249
|
+
export interface StateNamespaceOptions {
|
|
1250
|
+
/** Default TTL used when a write omits ttl. Required to avoid unbounded state. */
|
|
1251
|
+
defaultTtl: ProviderStateDurationString;
|
|
1252
|
+
/** Maximum allowed TTL; writes are rejected when they exceed this policy. */
|
|
1253
|
+
maxTtl: ProviderStateDurationString;
|
|
1254
|
+
/** Maximum number of live entries in this namespace scope. */
|
|
1255
|
+
maxEntries: number;
|
|
1256
|
+
/** Maximum JSON-encoded value size in bytes. */
|
|
1257
|
+
maxValueBytes: number;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
export interface StateWriteOptions {
|
|
1261
|
+
ttl?: ProviderStateDurationString;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export interface StateValue<T = unknown> {
|
|
1265
|
+
key: string;
|
|
1266
|
+
value: T;
|
|
1267
|
+
version: number;
|
|
1268
|
+
expiresAt: string;
|
|
1269
|
+
createdAt: string;
|
|
1270
|
+
updatedAt: string;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
export type StateCasResult<T = unknown> =
|
|
1274
|
+
| { ok: true; value: StateValue<T> }
|
|
1275
|
+
| { ok: false; current: StateValue<T> | null };
|
|
1276
|
+
|
|
1277
|
+
export interface ProviderStateNamespace {
|
|
1278
|
+
list<T = unknown>(options?: {
|
|
1279
|
+
limit?: number;
|
|
1280
|
+
/** Optional literal key prefix used for scoped recovery scans. */
|
|
1281
|
+
prefix?: string;
|
|
1282
|
+
}): Promise<StateValue<T>[]>;
|
|
1283
|
+
get<T = unknown>(key: string): Promise<StateValue<T> | null>;
|
|
1284
|
+
set<T = unknown>(
|
|
1285
|
+
key: string,
|
|
1286
|
+
value: T,
|
|
1287
|
+
options?: StateWriteOptions,
|
|
1288
|
+
): Promise<StateValue<T>>;
|
|
1289
|
+
patch<T extends Record<string, unknown>>(
|
|
1290
|
+
key: string,
|
|
1291
|
+
partial: Partial<T>,
|
|
1292
|
+
options?: StateWriteOptions,
|
|
1293
|
+
): Promise<StateValue<T>>;
|
|
1294
|
+
compareAndSet<T = unknown>(
|
|
1295
|
+
key: string,
|
|
1296
|
+
expectedVersion: number,
|
|
1297
|
+
value: T,
|
|
1298
|
+
options?: StateWriteOptions,
|
|
1299
|
+
): Promise<StateCasResult<T>>;
|
|
1300
|
+
delete(key: string): Promise<void>;
|
|
1301
|
+
increment(
|
|
1302
|
+
key: string,
|
|
1303
|
+
field: string,
|
|
1304
|
+
delta?: number,
|
|
1305
|
+
options?: StateWriteOptions,
|
|
1306
|
+
): Promise<StateValue<Record<string, unknown>>>;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
export interface ProviderRuntimeState {
|
|
1310
|
+
namespace(
|
|
1311
|
+
name: string,
|
|
1312
|
+
options: StateNamespaceOptions,
|
|
1313
|
+
): ProviderStateNamespace;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
508
1316
|
export interface ProviderContext {
|
|
509
1317
|
env: EnvContext;
|
|
510
1318
|
credential: CredentialContext;
|
|
511
1319
|
request?: ProviderRequestContext;
|
|
512
1320
|
http: HttpClient;
|
|
513
|
-
|
|
1321
|
+
cache: ProviderCache;
|
|
1322
|
+
state: ProviderRuntimeState;
|
|
1323
|
+
stealth: StealthClient;
|
|
514
1324
|
browser: BrowserClient;
|
|
515
1325
|
trace: TraceContext;
|
|
516
1326
|
auth: AuthContext;
|
|
1327
|
+
stt: SttContext;
|
|
517
1328
|
}
|
|
518
1329
|
|
|
519
1330
|
export interface AuthConfig {
|
|
@@ -537,25 +1348,50 @@ export interface ContextDeclaration {
|
|
|
537
1348
|
keys: string[];
|
|
538
1349
|
}
|
|
539
1350
|
|
|
1351
|
+
export type OperationLifecycle = "stable" | "beta" | "deprecated" | "removed";
|
|
1352
|
+
|
|
1353
|
+
export interface OperationDeprecationMetadata {
|
|
1354
|
+
announcedAt: string;
|
|
1355
|
+
removalAfter: string;
|
|
1356
|
+
replacement?: string;
|
|
1357
|
+
migrationGuide: string;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
export interface OperationContractMetadata {
|
|
1361
|
+
/**
|
|
1362
|
+
* Callable operation contract version. Defaults to 1.0.0 for the clean
|
|
1363
|
+
* pre-GA baseline; it intentionally does not fall back to provider.version.
|
|
1364
|
+
*/
|
|
1365
|
+
version?: string;
|
|
1366
|
+
lifecycle?: OperationLifecycle;
|
|
1367
|
+
deprecation?: OperationDeprecationMetadata;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
540
1370
|
export interface OperationDefinition<
|
|
541
1371
|
TInput extends SchemaLike = SchemaLike,
|
|
542
1372
|
TOutput extends SchemaLike = SchemaLike,
|
|
543
1373
|
> {
|
|
544
|
-
|
|
1374
|
+
descriptionKey?: ProviderLocaleKeyInput;
|
|
545
1375
|
docs?: OperationDocMeta;
|
|
546
|
-
|
|
547
|
-
|
|
1376
|
+
whenToUseKeys?: ProviderLocaleKeyInput[];
|
|
1377
|
+
whenNotToUseKeys?: ProviderLocaleKeyInput[];
|
|
548
1378
|
derivations?: Record<string, string>;
|
|
549
1379
|
inputExamples?: OperationInputExample[];
|
|
550
1380
|
annotations?: OperationAnnotations;
|
|
1381
|
+
contract?: OperationContractMetadata;
|
|
551
1382
|
tags?: string[];
|
|
552
1383
|
relatedOperations?: OperationRelationships;
|
|
1384
|
+
toolRouter?: OperationToolRouterMetadata;
|
|
1385
|
+
observability?: OperationObservabilityConfig;
|
|
1386
|
+
transport?: OperationTransport;
|
|
553
1387
|
input: TInput;
|
|
554
1388
|
output: TOutput;
|
|
555
1389
|
handler(
|
|
556
1390
|
ctx: ProviderContext,
|
|
557
1391
|
input: InferSchemaOutput<TInput>,
|
|
558
|
-
):
|
|
1392
|
+
):
|
|
1393
|
+
| OperationHandlerResult<InferSchemaOutput<TOutput>>
|
|
1394
|
+
| Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
|
|
559
1395
|
fixtures?: {
|
|
560
1396
|
request: InferSchemaOutput<TInput>;
|
|
561
1397
|
response: InferSchemaOutput<TOutput>;
|
|
@@ -577,16 +1413,19 @@ export interface ProviderDefinition {
|
|
|
577
1413
|
profile: string;
|
|
578
1414
|
platform: StealthPlatform;
|
|
579
1415
|
};
|
|
580
|
-
proxy?:
|
|
1416
|
+
proxy?: ProviderProxyConfig;
|
|
1417
|
+
stt?: ProviderSttConfig;
|
|
581
1418
|
browser?: {
|
|
582
1419
|
engine: BrowserEngine;
|
|
583
1420
|
};
|
|
584
1421
|
auth?: AuthConfig;
|
|
585
1422
|
reviewed?: ProviderReviewed;
|
|
1423
|
+
access?: ProviderAccessConfig;
|
|
586
1424
|
secrets?: ProviderSecretDeclaration[];
|
|
587
1425
|
credential?: CredentialDeclaration;
|
|
588
1426
|
context?: ContextDeclaration;
|
|
589
1427
|
meta: ProviderMeta;
|
|
590
1428
|
operations: Record<string, OperationDefinition<SchemaLike, SchemaLike>>;
|
|
591
1429
|
healthMonitor?: ProviderHealthMonitorConfig;
|
|
1430
|
+
healthJourneys?: readonly HealthJourneyDefinition[];
|
|
592
1431
|
}
|