@apifuse/provider-sdk 2.2.0-beta.48 → 2.2.0-beta.49
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 +91 -36
- package/CHANGELOG.md +4 -0
- package/README.md +11 -9
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-dev.ts +24 -13
- package/bin/apifuse-migrate-operation-declaration.ts +55 -0
- package/bin/apifuse-pack-smoke.ts +1 -1
- package/bin/apifuse-pack-types.ts +2 -1
- package/bin/apifuse-record.ts +30 -16
- package/bin/apifuse-submit-check.ts +20 -35
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/migrate-operation-declaration.d.ts +59 -0
- package/dist/cli/migrate-operation-declaration.js +1178 -0
- package/dist/cli/templates/provider/README.md.tpl +3 -3
- package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -0
- package/dist/config/loader.d.ts +2 -0
- package/dist/config/loader.js +18 -7
- package/dist/contract-types.d.ts +11 -5
- package/dist/contract.js +21 -10
- package/dist/define.d.ts +25 -22
- package/dist/define.js +49 -75
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +1 -1
- package/dist/engine.d.ts +78 -0
- package/dist/engine.js +133 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/lint.d.ts +7 -15
- package/dist/lint.js +45 -70
- package/dist/provider.d.ts +3 -1
- package/dist/provider.js +1 -0
- package/dist/runtime/chrome149-header-order.d.ts +58 -0
- package/dist/runtime/chrome149-header-order.js +289 -0
- package/dist/runtime/env.js +12 -0
- package/dist/runtime/executor.d.ts +2 -1
- package/dist/runtime/executor.js +3 -36
- package/dist/runtime/insights.js +2 -2
- package/dist/runtime/otlp.d.ts +71 -2
- package/dist/runtime/otlp.js +397 -16
- package/dist/runtime/resolver-vendors/capsolver.js +3 -3
- package/dist/runtime/resolver.js +3 -3
- package/dist/runtime/stealth.d.ts +13 -4
- package/dist/runtime/stealth.js +362 -85
- package/dist/runtime/trace-config.js +2 -1
- package/dist/runtime/trace.d.ts +5 -0
- package/dist/runtime/trace.js +43 -10
- package/dist/server/self-test.d.ts +1 -3
- package/dist/server/self-test.js +2 -12
- package/dist/server/serve-implementation.d.ts +6 -1
- package/dist/server/serve-implementation.js +55 -40
- package/dist/server/trace-output.d.ts +3 -1
- package/dist/server/trace-output.js +61 -2
- package/dist/stealth/profiles.d.ts +9 -8
- package/dist/stealth/profiles.js +123 -286
- package/dist/types.d.ts +111 -108
- package/package.json +2 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
- package/src/cli/commands.ts +13 -0
- package/src/cli/migrate-operation-declaration.ts +1654 -0
- package/src/cli/templates/provider/README.md.tpl +3 -3
- package/src/cli/templates/provider/operations/ping.ts.tpl +2 -0
- package/src/config/loader.ts +31 -6
- package/src/contract-types.ts +11 -5
- package/src/contract.ts +21 -10
- package/src/define.ts +107 -119
- package/src/dev.ts +4 -1
- package/src/engine.ts +279 -0
- package/src/index.ts +13 -5
- package/src/lint.ts +58 -92
- package/src/provider.ts +25 -3
- package/src/runtime/chrome149-header-order.ts +330 -0
- package/src/runtime/env.ts +13 -0
- package/src/runtime/executor.ts +7 -40
- package/src/runtime/insights.ts +2 -2
- package/src/runtime/otlp.ts +467 -21
- package/src/runtime/resolver-vendors/capsolver.ts +4 -3
- package/src/runtime/resolver.ts +3 -3
- package/src/runtime/stealth.ts +435 -103
- package/src/runtime/trace-config.ts +3 -2
- package/src/runtime/trace.ts +57 -17
- package/src/server/self-test.ts +2 -9
- package/src/server/serve-implementation.ts +89 -72
- package/src/server/trace-output.ts +99 -2
- package/src/stealth/profiles.ts +169 -327
- package/src/types.ts +109 -137
package/dist/types.d.ts
CHANGED
|
@@ -34,27 +34,13 @@ export declare namespace StandardSchemaV1 {
|
|
|
34
34
|
export type SchemaLike = ZodType | StandardSchemaV1;
|
|
35
35
|
/** Infer the validated output type produced by a Zod or Standard Schema. */
|
|
36
36
|
export type InferSchemaOutput<TSchema extends SchemaLike> = TSchema extends ZodType ? ZodInfer<TSchema> : TSchema extends StandardSchemaV1<unknown, infer Output> ? Output : unknown;
|
|
37
|
-
export interface
|
|
38
|
-
|
|
37
|
+
export interface OperationExample {
|
|
38
|
+
scenarioKey: ProviderLocaleKeyInput;
|
|
39
39
|
input: unknown;
|
|
40
|
-
|
|
40
|
+
rationaleKey?: ProviderLocaleKeyInput;
|
|
41
41
|
}
|
|
42
42
|
export type OperationRiskClass = "read" | "write" | "destructive" | "external-send";
|
|
43
43
|
export type OperationApprovalPolicy = "never" | "risk-based" | "always";
|
|
44
|
-
export interface OperationToolRouterMetadata {
|
|
45
|
-
/** Optional MCP-safe override. Defaults to providerId__operationId. */
|
|
46
|
-
name?: string;
|
|
47
|
-
/** Safety class exposed to Tool Router clients and approval policy. */
|
|
48
|
-
riskClass?: OperationRiskClass;
|
|
49
|
-
/** OpenAI remote-MCP approval hint. Defaults from riskClass. */
|
|
50
|
-
approval?: OperationApprovalPolicy;
|
|
51
|
-
/** Canonical operation-level connection requirement consumed by the registry and Gateway. */
|
|
52
|
-
connectionMode?: "none" | "optional" | "required";
|
|
53
|
-
/** Override connection requirement when provider auth + openWorld inference is insufficient. */
|
|
54
|
-
requiresConnection?: boolean;
|
|
55
|
-
/** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
|
|
56
|
-
connectionExternalRefParam?: string;
|
|
57
|
-
}
|
|
58
44
|
export type OperationSensitivePath = string;
|
|
59
45
|
export interface OperationObservabilitySensitiveConfig {
|
|
60
46
|
/**
|
|
@@ -76,37 +62,6 @@ export interface OperationObservabilityConfig {
|
|
|
76
62
|
*/
|
|
77
63
|
sensitive?: OperationObservabilitySensitiveConfig;
|
|
78
64
|
}
|
|
79
|
-
export interface OperationAnnotations {
|
|
80
|
-
readOnly?: boolean;
|
|
81
|
-
destructive?: boolean;
|
|
82
|
-
idempotent?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Marks the operation as callable without provider-level authentication.
|
|
85
|
-
*
|
|
86
|
-
* Provider-level `auth.mode` describes the **majority** auth model of a
|
|
87
|
-
* provider; individual operations can still opt out via `openWorld: true`
|
|
88
|
-
* when their handler does not consume `ctx.credential`. This is the
|
|
89
|
-
* canonical way to declare "this operation is public, even though the
|
|
90
|
-
* provider is `credentials`-mode" without splitting the provider into two.
|
|
91
|
-
*
|
|
92
|
-
* Health-check projections treat `openWorld: true` operations as
|
|
93
|
-
* connection-free probes (no `requiresConnection` required, no SA token
|
|
94
|
-
* lookup). Future gateway work MAY extend this annotation to bypass
|
|
95
|
-
* `X-ApiFuse-Connection-Id` enforcement at proxy time.
|
|
96
|
-
*
|
|
97
|
-
* Example: Naver Map's `search`, `geocode`, and directions operations
|
|
98
|
-
* call public Naver endpoints with no cookies, while `collections` and
|
|
99
|
-
* `export` consume the user's session cookie — the provider declares
|
|
100
|
-
* `auth.mode: "credentials"` (for the latter) and the former mark
|
|
101
|
-
* `openWorld: true`.
|
|
102
|
-
*/
|
|
103
|
-
openWorld?: boolean;
|
|
104
|
-
rateLimit?: {
|
|
105
|
-
calls: number;
|
|
106
|
-
window: "minute" | "hour" | "day";
|
|
107
|
-
};
|
|
108
|
-
timeoutMs?: number;
|
|
109
|
-
}
|
|
110
65
|
export declare const OPERATION_TIMEOUT_MS_MIN = 1;
|
|
111
66
|
export declare const OPERATION_TIMEOUT_MS_MAX = 60000;
|
|
112
67
|
export declare const STREAM_HEARTBEAT_MS_MIN = 1000;
|
|
@@ -791,17 +746,34 @@ export interface OperationErrorCode {
|
|
|
791
746
|
description: string;
|
|
792
747
|
retryable?: boolean;
|
|
793
748
|
}
|
|
794
|
-
export interface OperationDocMeta {
|
|
795
|
-
titleKey?: ProviderLocaleKeyInput;
|
|
796
|
-
descriptionKey?: ProviderLocaleKeyInput;
|
|
797
|
-
summaryKey?: ProviderLocaleKeyInput;
|
|
798
|
-
markdownKey?: ProviderLocaleKeyInput;
|
|
799
|
-
normalizationNotesKeys?: ProviderLocaleKeyInput[];
|
|
800
|
-
requestExample?: Record<string, unknown>;
|
|
801
|
-
responseExample?: unknown;
|
|
802
|
-
errorCodes?: OperationErrorCode[];
|
|
803
|
-
}
|
|
804
749
|
export type StealthPlatform = "macos" | "windows" | "linux" | "android" | "ios";
|
|
750
|
+
export type StealthBrowser = "chrome" | "firefox" | "safari";
|
|
751
|
+
export type StealthOS = "windows" | "macos" | "linux" | "ios";
|
|
752
|
+
/** A supported, fully resolved browser/OS fingerprint pair. */
|
|
753
|
+
export type StealthProfileDescriptor = {
|
|
754
|
+
browser: "chrome";
|
|
755
|
+
os: "windows" | "macos" | "linux";
|
|
756
|
+
} | {
|
|
757
|
+
browser: "firefox";
|
|
758
|
+
os: "windows" | "macos" | "linux";
|
|
759
|
+
} | {
|
|
760
|
+
browser: "safari";
|
|
761
|
+
os: "macos" | "ios";
|
|
762
|
+
};
|
|
763
|
+
/**
|
|
764
|
+
* Browser/OS fingerprint selection. Chrome and macOS are the named defaults
|
|
765
|
+
* when their respective axes are omitted.
|
|
766
|
+
*/
|
|
767
|
+
export type StealthProfileSelection = {
|
|
768
|
+
browser?: "chrome";
|
|
769
|
+
os?: "windows" | "macos" | "linux";
|
|
770
|
+
} | {
|
|
771
|
+
browser: "firefox";
|
|
772
|
+
os?: "windows" | "macos" | "linux";
|
|
773
|
+
} | {
|
|
774
|
+
browser: "safari";
|
|
775
|
+
os?: "macos" | "ios";
|
|
776
|
+
};
|
|
805
777
|
export type BrowserEngine = "playwright-stealth" | "nodriver" | "selenium-uc";
|
|
806
778
|
export interface BrowserOptions {
|
|
807
779
|
headless?: boolean;
|
|
@@ -810,9 +782,7 @@ export interface BrowserOptions {
|
|
|
810
782
|
engine?: BrowserEngine;
|
|
811
783
|
requireCdpPool?: boolean;
|
|
812
784
|
}
|
|
813
|
-
export
|
|
814
|
-
name: string;
|
|
815
|
-
platform: StealthPlatform;
|
|
785
|
+
export type StealthProfile = StealthProfileDescriptor & {
|
|
816
786
|
version: string;
|
|
817
787
|
userAgent: string;
|
|
818
788
|
tlsClientIdentifier?: string;
|
|
@@ -820,7 +790,7 @@ export interface StealthProfile {
|
|
|
820
790
|
ja4?: string;
|
|
821
791
|
h2Settings?: Record<string, unknown>;
|
|
822
792
|
headerOrder?: string[];
|
|
823
|
-
}
|
|
793
|
+
};
|
|
824
794
|
export type AuthMode = "none" | "platform-managed" | "credentials" | "oauth2" | "oauth2_proxied";
|
|
825
795
|
export type ConnectionMode = AuthMode;
|
|
826
796
|
export type ProviderReviewed = "first-party" | "community" | "staging";
|
|
@@ -895,8 +865,7 @@ export interface ProviderAccessConfig {
|
|
|
895
865
|
* active customer organization has a provider-level access grant.
|
|
896
866
|
*
|
|
897
867
|
* This is intentionally provider-level only. It does not alter auth mode,
|
|
898
|
-
* operation schemas, health-check authoring,
|
|
899
|
-
* requirements.
|
|
868
|
+
* operation schemas, health-check authoring, or Connection requirements.
|
|
900
869
|
*/
|
|
901
870
|
visibility?: ProviderAccessVisibility;
|
|
902
871
|
}
|
|
@@ -1057,7 +1026,12 @@ export interface HttpRedirectPolicy {
|
|
|
1057
1026
|
}
|
|
1058
1027
|
export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
|
|
1059
1028
|
export type HttpMethod = "HEAD" | "head" | "GET" | "get" | "POST" | "post" | "PUT" | "put" | "DELETE" | "delete" | "OPTIONS" | "options" | "TRACE" | "trace" | "PATCH" | "patch";
|
|
1060
|
-
export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy"> {
|
|
1029
|
+
export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy" | "headers"> {
|
|
1030
|
+
/**
|
|
1031
|
+
* Request headers. Array values and case-insensitive duplicate names are
|
|
1032
|
+
* combined in caller order using `", "`, matching Chrome's Fetch behavior.
|
|
1033
|
+
*/
|
|
1034
|
+
headers?: Record<string, string | string[]>;
|
|
1061
1035
|
method?: HttpMethod;
|
|
1062
1036
|
body?: string | Buffer;
|
|
1063
1037
|
redirect?: "follow" | "manual" | "error";
|
|
@@ -1074,14 +1048,18 @@ export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolic
|
|
|
1074
1048
|
* operation-affinity proxy.
|
|
1075
1049
|
*/
|
|
1076
1050
|
proxyAttemptOffset?: number;
|
|
1077
|
-
/** Override the configured browser-like stealth profile for this request. */
|
|
1078
|
-
profile?: string;
|
|
1079
1051
|
/**
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1082
|
-
* certificate chain.
|
|
1052
|
+
* SDK-specific stealth controls. Standard HTTP metadata such as language,
|
|
1053
|
+
* referrer, and content type belongs in `headers`.
|
|
1083
1054
|
*/
|
|
1084
|
-
stealth?: {
|
|
1055
|
+
stealth?: StealthProfileSelection & {
|
|
1056
|
+
/** Override the configured browser and/or OS for this request. */
|
|
1057
|
+
/** Declare the Chrome request class when it cannot be inferred from the method. */
|
|
1058
|
+
requestClass?: "navigation" | "xhr" | "post";
|
|
1059
|
+
/**
|
|
1060
|
+
* Use only for proxy products that terminate CONNECT with a private CA
|
|
1061
|
+
* instead of tunneling the origin certificate chain.
|
|
1062
|
+
*/
|
|
1085
1063
|
insecureSkipVerify?: boolean;
|
|
1086
1064
|
};
|
|
1087
1065
|
}
|
|
@@ -1254,6 +1232,8 @@ export interface ProviderFilesContext {
|
|
|
1254
1232
|
has(input: string | ProviderFileRef): boolean;
|
|
1255
1233
|
resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
|
|
1256
1234
|
}
|
|
1235
|
+
/** Where provider business logic executes relative to the capability engine. */
|
|
1236
|
+
export type ProviderRuntimeTarget = "vanilla" | "engine";
|
|
1257
1237
|
export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
|
|
1258
1238
|
export interface NativeTcpPortRange {
|
|
1259
1239
|
readonly start: number;
|
|
@@ -1426,7 +1406,7 @@ export interface ProviderCache {
|
|
|
1426
1406
|
export interface StealthClient {
|
|
1427
1407
|
fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
|
|
1428
1408
|
createSession(opts?: {
|
|
1429
|
-
|
|
1409
|
+
stealth?: StealthProfileSelection;
|
|
1430
1410
|
}): StealthSession;
|
|
1431
1411
|
close?(): void;
|
|
1432
1412
|
}
|
|
@@ -1557,7 +1537,7 @@ export interface TraceConfig {
|
|
|
1557
1537
|
exporter?: "console" | "json" | "otlp" | "none";
|
|
1558
1538
|
endpoint?: string;
|
|
1559
1539
|
otlp?: {
|
|
1560
|
-
endpoint
|
|
1540
|
+
endpoint?: string;
|
|
1561
1541
|
headers?: Record<string, string>;
|
|
1562
1542
|
timeout?: number;
|
|
1563
1543
|
};
|
|
@@ -1876,32 +1856,48 @@ export interface ProviderRuntimeState {
|
|
|
1876
1856
|
forConnection(connectionId: string | undefined): ProviderRuntimeState;
|
|
1877
1857
|
namespace(name: string, options: StateNamespaceOptions): ProviderStateNamespace;
|
|
1878
1858
|
}
|
|
1879
|
-
|
|
1859
|
+
/**
|
|
1860
|
+
* The operation context exposed for one provider declaration. Capability
|
|
1861
|
+
* bindings are present only when their corresponding declaration is present;
|
|
1862
|
+
* trace and request remain ambient runtime bindings. Omitting the type
|
|
1863
|
+
* parameter preserves the legacy full context shape for existing annotations.
|
|
1864
|
+
*/
|
|
1865
|
+
export type ProviderContext<TConfig = Record<string, unknown>> = {
|
|
1866
|
+
request?: ProviderRequestContext;
|
|
1867
|
+
trace: TraceContext;
|
|
1868
|
+
} & ("env" extends keyof TConfig ? {
|
|
1880
1869
|
env: EnvContext;
|
|
1870
|
+
} : Record<never, never>) & ("credential" extends keyof TConfig ? {
|
|
1881
1871
|
credential: CredentialContext;
|
|
1882
|
-
|
|
1872
|
+
} : Record<never, never>) & ("http" extends keyof TConfig ? {
|
|
1883
1873
|
http: HttpClient;
|
|
1884
|
-
|
|
1874
|
+
} : Record<never, never>) & ("files" extends keyof TConfig ? string extends keyof TConfig ? {
|
|
1885
1875
|
readonly files?: ProviderFilesContext;
|
|
1886
|
-
|
|
1876
|
+
} : {
|
|
1877
|
+
readonly files: ProviderFilesContext;
|
|
1878
|
+
} : Record<never, never>) & ("native" extends keyof TConfig ? {
|
|
1887
1879
|
readonly native: NativeContext;
|
|
1880
|
+
} : Record<never, never>) & ("cache" extends keyof TConfig ? {
|
|
1888
1881
|
cache: ProviderCache;
|
|
1882
|
+
} : Record<never, never>) & ("state" extends keyof TConfig ? {
|
|
1889
1883
|
state: ProviderRuntimeState;
|
|
1884
|
+
} : Record<never, never>) & ("stealth" extends keyof TConfig ? {
|
|
1890
1885
|
stealth: StealthClient;
|
|
1886
|
+
} : Record<never, never>) & ("browser" extends keyof TConfig ? {
|
|
1891
1887
|
browser: BrowserClient;
|
|
1892
|
-
|
|
1888
|
+
} : Record<never, never>) & ("auth" extends keyof TConfig ? {
|
|
1893
1889
|
auth: AuthContext;
|
|
1890
|
+
} : Record<never, never>) & ("ocr" extends keyof TConfig ? {
|
|
1894
1891
|
ocr: OcrContext;
|
|
1892
|
+
} : Record<never, never>) & ("stt" extends keyof TConfig ? {
|
|
1895
1893
|
stt: SttContext;
|
|
1894
|
+
} : Record<never, never>) & ("resolver" extends keyof TConfig ? {
|
|
1896
1895
|
resolver: ResolverContext;
|
|
1896
|
+
} : Record<never, never>) & ("choice" extends keyof TConfig ? {
|
|
1897
1897
|
choice: ProviderChoiceContext;
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
|
|
1901
|
-
* bindings are present only when their corresponding declaration is present;
|
|
1902
|
-
* trace and request remain ambient runtime bindings.
|
|
1903
|
-
*/
|
|
1904
|
-
export type ProviderContextFor<TConfig> = Pick<ProviderContext, "trace" | "request"> & ("env" extends keyof TConfig ? Pick<ProviderContext, "env"> : Record<never, never>) & ("credential" extends keyof TConfig ? Pick<ProviderContext, "credential"> : Record<never, never>) & ("http" extends keyof TConfig ? Pick<ProviderContext, "http"> : Record<never, never>) & ("files" extends keyof TConfig ? Pick<ProviderContext, "files"> : Record<never, never>) & ("native" extends keyof TConfig ? Pick<ProviderContext, "native"> : Record<never, never>) & ("cache" extends keyof TConfig ? Pick<ProviderContext, "cache"> : Record<never, never>) & ("state" extends keyof TConfig ? Pick<ProviderContext, "state"> : Record<never, never>) & ("stealth" extends keyof TConfig ? Pick<ProviderContext, "stealth"> : Record<never, never>) & ("browser" extends keyof TConfig ? Pick<ProviderContext, "browser"> : Record<never, never>) & ("auth" extends keyof TConfig ? Pick<ProviderContext, "auth"> : Record<never, never>) & ("ocr" extends keyof TConfig ? Pick<ProviderContext, "ocr"> : Record<never, never>) & ("stt" extends keyof TConfig ? Pick<ProviderContext, "stt"> : Record<never, never>) & ("resolver" extends keyof TConfig ? Pick<ProviderContext, "resolver"> : Record<never, never>) & ("choice" extends keyof TConfig ? Pick<ProviderContext, "choice"> : Record<never, never>);
|
|
1898
|
+
} : Record<never, never>);
|
|
1899
|
+
/** Backwards-compatible name for a declaration-derived provider context. */
|
|
1900
|
+
export type ProviderContextFor<TConfig> = ProviderContext<TConfig>;
|
|
1905
1901
|
export interface ProxiedOAuthConfig {
|
|
1906
1902
|
authorizeUrl: string;
|
|
1907
1903
|
tokenUrl: string;
|
|
@@ -1948,33 +1944,29 @@ export interface OperationContractMetadata {
|
|
|
1948
1944
|
deprecation?: OperationDeprecationMetadata;
|
|
1949
1945
|
}
|
|
1950
1946
|
export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike, TContext = ProviderContext> {
|
|
1951
|
-
/**
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
* provider lint rules for raw prose descriptions still apply.
|
|
1962
|
-
*/
|
|
1963
|
-
description?: string;
|
|
1947
|
+
/** Canonical operation-level connection requirement. */
|
|
1948
|
+
connectionMode?: "none" | "optional" | "required";
|
|
1949
|
+
/** Public argument used to resolve the tenant-owned connection. Defaults to externalRef. */
|
|
1950
|
+
connectionExternalRefParam?: string;
|
|
1951
|
+
/** Safety source of truth exposed to clients and approval policy. */
|
|
1952
|
+
riskClass: OperationRiskClass;
|
|
1953
|
+
/** Approval override. Omit when the risk-class default is correct. */
|
|
1954
|
+
approval?: OperationApprovalPolicy;
|
|
1955
|
+
timeoutMs?: number;
|
|
1956
|
+
titleKey?: ProviderLocaleKeyInput;
|
|
1964
1957
|
descriptionKey?: ProviderLocaleKeyInput;
|
|
1965
|
-
|
|
1958
|
+
summaryKey?: ProviderLocaleKeyInput;
|
|
1959
|
+
markdownKey?: ProviderLocaleKeyInput;
|
|
1966
1960
|
whenToUseKeys?: readonly ProviderLocaleKeyInput[];
|
|
1967
1961
|
whenNotToUseKeys?: readonly ProviderLocaleKeyInput[];
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1962
|
+
normalizationNotesKeys?: readonly ProviderLocaleKeyInput[];
|
|
1963
|
+
errorCodes?: readonly OperationErrorCode[];
|
|
1964
|
+
examples?: readonly OperationExample[];
|
|
1971
1965
|
contract?: OperationContractMetadata;
|
|
1972
1966
|
tags?: readonly string[];
|
|
1973
1967
|
relatedOperations?: OperationRelationships;
|
|
1974
|
-
toolRouter?: OperationToolRouterMetadata;
|
|
1975
1968
|
observability?: OperationObservabilityConfig;
|
|
1976
1969
|
transport?: OperationTransport;
|
|
1977
|
-
retryOnAuthRefresh?: boolean;
|
|
1978
1970
|
input: TInput;
|
|
1979
1971
|
output: TOutput;
|
|
1980
1972
|
handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
|
|
@@ -2037,18 +2029,24 @@ export interface ProviderDefinition<TContext = ProviderContext> {
|
|
|
2037
2029
|
id: string;
|
|
2038
2030
|
version: string;
|
|
2039
2031
|
runtime: "standard" | "shared" | "browser";
|
|
2032
|
+
/**
|
|
2033
|
+
* `vanilla` executes provider business logic outside the engine; `engine`
|
|
2034
|
+
* keeps session-bearing provider logic in the engine process.
|
|
2035
|
+
*
|
|
2036
|
+
* Omitted only for definitions authored before the engine migration. New
|
|
2037
|
+
* providers should declare the target explicitly.
|
|
2038
|
+
*/
|
|
2039
|
+
runtimeTarget?: ProviderRuntimeTarget;
|
|
2040
2040
|
/**
|
|
2041
2041
|
* Optional deployment overrides, passed through verbatim from
|
|
2042
2042
|
* `defineProvider({ deployment })`. Validation and profile resolution are
|
|
2043
2043
|
* owned by the APIFuse registry builder, not the SDK.
|
|
2044
2044
|
*/
|
|
2045
2045
|
deployment?: ProviderDeploymentOverrides;
|
|
2046
|
+
http?: Record<string, never> | true;
|
|
2046
2047
|
allowedHosts?: string[];
|
|
2047
2048
|
native?: NativeProviderConfig;
|
|
2048
|
-
stealth?:
|
|
2049
|
-
profile: string;
|
|
2050
|
-
platform: StealthPlatform;
|
|
2051
|
-
};
|
|
2049
|
+
stealth?: StealthProfileSelection;
|
|
2052
2050
|
proxy?: ProviderProxyConfig;
|
|
2053
2051
|
ocr?: ProviderOcrConfig;
|
|
2054
2052
|
stt?: ProviderSttConfig;
|
|
@@ -2057,11 +2055,16 @@ export interface ProviderDefinition<TContext = ProviderContext> {
|
|
|
2057
2055
|
engine: BrowserEngine;
|
|
2058
2056
|
};
|
|
2059
2057
|
auth?: AuthConfig;
|
|
2058
|
+
choice?: Record<string, never> | true;
|
|
2060
2059
|
reviewed?: ProviderReviewed;
|
|
2061
2060
|
access?: ProviderAccessConfig;
|
|
2062
2061
|
secrets?: ProviderSecretDeclaration[];
|
|
2062
|
+
env?: Record<string, never> | true;
|
|
2063
2063
|
credential?: CredentialDeclaration;
|
|
2064
2064
|
context?: ContextDeclaration;
|
|
2065
|
+
state?: Record<string, never> | true;
|
|
2066
|
+
cache?: Record<string, never> | true;
|
|
2067
|
+
files?: Record<string, never> | true;
|
|
2065
2068
|
meta: ProviderMeta;
|
|
2066
2069
|
operations: Record<string, OperationDefinition<SchemaLike, SchemaLike, TContext>>;
|
|
2067
2070
|
healthMonitor?: ProviderHealthMonitorConfig;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.2.0-beta.
|
|
2
|
+
"version": "2.2.0-beta.49",
|
|
3
3
|
"name": "@apifuse/provider-sdk",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
@@ -113,6 +113,7 @@
|
|
|
113
113
|
"check": "bun run lint && bun run type-check && bun run lint:deprecated && bun run lint:test-typesafety && bun run build",
|
|
114
114
|
"api:update": "bun run build && bun scripts/api-reports.ts update",
|
|
115
115
|
"api:check": "bun run build && bun scripts/api-reports.ts check",
|
|
116
|
+
"verify:chrome-headers": "bun scripts/verify-chrome-header-parity.ts",
|
|
116
117
|
"changeset:check": "bun scripts/check-changeset.ts",
|
|
117
118
|
"pack:check": "bun run build && bun bin/apifuse-pack-check.ts",
|
|
118
119
|
"pack:smoke": "bun run build && bun bin/apifuse-pack-smoke.ts",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const searchOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
annotations: { readOnly: true },
|
|
3
|
+
inputExamples: [
|
|
4
|
+
{
|
|
5
|
+
scenario: "Search by a precise phrase",
|
|
6
|
+
input: {
|
|
7
|
+
query: `京都
|
|
8
|
+
ホテル`,
|
|
9
|
+
},
|
|
10
|
+
rationale: "Shows whitespace preservation",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
input: InputSchema,
|
|
14
|
+
output: OutputSchema,
|
|
15
|
+
handler,
|
|
16
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const searchOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
annotations: {
|
|
3
|
+
readOnly: true,
|
|
4
|
+
openWorld: true,
|
|
5
|
+
idempotent: true,
|
|
6
|
+
rateLimit: { requests: 10 },
|
|
7
|
+
timeoutMs: 30_000,
|
|
8
|
+
},
|
|
9
|
+
toolRouter: {
|
|
10
|
+
name: "ignored",
|
|
11
|
+
requiresConnection: false,
|
|
12
|
+
connectionExternalRefParam: "accountId",
|
|
13
|
+
},
|
|
14
|
+
docs: {
|
|
15
|
+
titleKey: "operations.search.title",
|
|
16
|
+
descriptionKey: "operations.search.description",
|
|
17
|
+
summaryKey: "operations.search.summary",
|
|
18
|
+
markdownKey: "operations.search.markdown",
|
|
19
|
+
normalizationNotesKeys: ["operations.search.normalization.one"],
|
|
20
|
+
errorCodes: [{ code: "UPSTREAM" }],
|
|
21
|
+
requestExample: { query: "old" },
|
|
22
|
+
responseExample: { items: [] },
|
|
23
|
+
},
|
|
24
|
+
derivations: { value: "unused" } as unknown as Derivations,
|
|
25
|
+
retryOnAuthRefresh: true as unknown as boolean,
|
|
26
|
+
title: "Raw title" as unknown as string,
|
|
27
|
+
description: "Raw description" as unknown as string,
|
|
28
|
+
input: InputSchema,
|
|
29
|
+
output: OutputSchema,
|
|
30
|
+
handler,
|
|
31
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { toolRouterDefaults } from "./tool-router-defaults.js";
|
|
2
|
+
|
|
3
|
+
const importedSpreadOperation = defineOperation<ProviderContext>()({
|
|
4
|
+
annotations: { readOnly: true },
|
|
5
|
+
toolRouter: {
|
|
6
|
+
...toolRouterDefaults,
|
|
7
|
+
},
|
|
8
|
+
input: InputSchema,
|
|
9
|
+
output: OutputSchema,
|
|
10
|
+
handler,
|
|
11
|
+
});
|
package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const castTailOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
annotations: {
|
|
3
|
+
...({ timeoutMs: 15_000 as Milliseconds } as unknown as LegacyAnnotations),
|
|
4
|
+
},
|
|
5
|
+
toolRouter: {
|
|
6
|
+
...({
|
|
7
|
+
riskClass: "write" as const,
|
|
8
|
+
approval: "always" as ApprovalMode,
|
|
9
|
+
connectionMode: "none" as ConnectionMode,
|
|
10
|
+
} as unknown as LegacyToolRouter),
|
|
11
|
+
},
|
|
12
|
+
docs: {
|
|
13
|
+
...({
|
|
14
|
+
titleKey: "operations.castTail.title" as const,
|
|
15
|
+
descriptionKey: "operations.castTail.description" as LocaleKey,
|
|
16
|
+
} as unknown as LegacyDocs),
|
|
17
|
+
},
|
|
18
|
+
input: InputSchema,
|
|
19
|
+
output: OutputSchema,
|
|
20
|
+
handler,
|
|
21
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const getStationInfoOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
toolRouter: {
|
|
3
|
+
riskClass: "read",
|
|
4
|
+
approval: "never",
|
|
5
|
+
requiresConnection: false,
|
|
6
|
+
...{ connectionMode: "none" as const },
|
|
7
|
+
},
|
|
8
|
+
input: InputSchema,
|
|
9
|
+
output: OutputSchema,
|
|
10
|
+
handler,
|
|
11
|
+
});
|
package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const overrideOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
toolRouter: {
|
|
3
|
+
riskClass: "read",
|
|
4
|
+
connectionMode: "required" as const,
|
|
5
|
+
...{
|
|
6
|
+
connectionMode: "none" as const,
|
|
7
|
+
approval: "never" as const,
|
|
8
|
+
},
|
|
9
|
+
approval: "always" as const,
|
|
10
|
+
},
|
|
11
|
+
input: InputSchema,
|
|
12
|
+
output: OutputSchema,
|
|
13
|
+
handler,
|
|
14
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const requiredConnection = {
|
|
2
|
+
requiresConnection: true,
|
|
3
|
+
connectionExternalRefParam: "profileId",
|
|
4
|
+
} as const;
|
|
5
|
+
|
|
6
|
+
const updateOperation = defineOperation<ProviderContext>()({
|
|
7
|
+
annotations: { destructive: true },
|
|
8
|
+
toolRouter: {
|
|
9
|
+
...requiredConnection,
|
|
10
|
+
approval: "always",
|
|
11
|
+
},
|
|
12
|
+
input: InputSchema,
|
|
13
|
+
output: OutputSchema,
|
|
14
|
+
handler,
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const explainOperation = defineOperation<ProviderContext>()({
|
|
2
|
+
annotations: { readOnly: true },
|
|
3
|
+
docs: { descriptionKey: "operations.explain.description" },
|
|
4
|
+
input: InputSchema,
|
|
5
|
+
output: OutputSchema,
|
|
6
|
+
handler: async () => {
|
|
7
|
+
const message = `最初の行
|
|
8
|
+
${value}
|
|
9
|
+
最後の行`;
|
|
10
|
+
return { message };
|
|
11
|
+
},
|
|
12
|
+
});
|