@apifuse/provider-sdk 2.2.0-beta.62 → 2.2.0-beta.64
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 +367 -9
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/bin/apifuse-check.ts +84 -2
- package/bin/apifuse-dev.ts +11 -31
- package/bin/apifuse-migrate-deployment.ts +200 -0
- package/bin/apifuse-pack-check.ts +11 -4
- package/bin/apifuse-pack-types.ts +187 -4
- package/bin/apifuse-record.ts +44 -32
- package/bin/apifuse-submit-check.ts +9 -5
- package/bin/apifuse-test.ts +3 -1
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/deployment-intent.d.ts +178 -0
- package/dist/cli/deployment-intent.js +277 -0
- package/dist/cli/migrate-deployment-intent.d.ts +132 -0
- package/dist/cli/migrate-deployment-intent.js +1552 -0
- package/dist/cli/migrate-provider-shape.d.ts +5 -1
- package/dist/cli/migrate-provider-shape.js +4 -2
- package/dist/cli/resolver-runtime.d.ts +21 -0
- package/dist/cli/resolver-runtime.js +31 -0
- package/dist/define.d.ts +3 -0
- package/dist/define.js +5 -0
- package/dist/dev.d.ts +3 -1
- package/dist/dev.js +6 -1
- package/dist/engine.d.ts +35 -1
- package/dist/engine.js +21 -2
- package/dist/error-resolution.d.ts +1 -0
- package/dist/error-resolution.js +54 -0
- package/dist/errors.d.ts +39 -1
- package/dist/errors.js +50 -0
- package/dist/handle-meta.d.ts +36 -1
- package/dist/handle-meta.js +16 -0
- package/dist/handle.d.ts +23 -5
- package/dist/handle.js +54 -8
- package/dist/health-scenario.d.ts +38 -0
- package/dist/i18n/error-messages.d.ts +86 -0
- package/dist/i18n/error-messages.js +192 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/keys.d.ts +12 -0
- package/dist/i18n/keys.js +76 -5
- package/dist/index.d.ts +11 -3
- package/dist/index.js +9 -1
- package/dist/lint.d.ts +15 -0
- package/dist/lint.js +469 -82
- package/dist/provider.d.ts +6 -6
- package/dist/provider.js +3 -3
- package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
- package/dist/runtime/browser-telemetry-binding.js +83 -0
- package/dist/runtime/browser-telemetry.d.ts +76 -0
- package/dist/runtime/browser-telemetry.js +165 -0
- package/dist/runtime/browser.d.ts +3 -0
- package/dist/runtime/browser.js +208 -47
- package/dist/runtime/cache-telemetry.d.ts +71 -0
- package/dist/runtime/cache-telemetry.js +177 -0
- package/dist/runtime/cache.js +67 -7
- package/dist/runtime/capability-response.d.ts +3 -0
- package/dist/runtime/capability-response.js +56 -0
- package/dist/runtime/capability-telemetry.d.ts +46 -0
- package/dist/runtime/capability-telemetry.js +68 -0
- package/dist/runtime/diagnostic-env.d.ts +3 -0
- package/dist/runtime/diagnostic-env.js +10 -1
- package/dist/runtime/engine-mode.d.ts +74 -0
- package/dist/runtime/engine-mode.js +152 -0
- package/dist/runtime/handle.js +9 -1
- package/dist/runtime/http-telemetry-guard.d.ts +10 -0
- package/dist/runtime/http-telemetry-guard.js +62 -10
- package/dist/runtime/http.js +141 -35
- package/dist/runtime/instrumentation.js +92 -13
- package/dist/runtime/ocr-telemetry.d.ts +82 -0
- package/dist/runtime/ocr-telemetry.js +192 -0
- package/dist/runtime/ocr.js +35 -8
- package/dist/runtime/request-telemetry.d.ts +2 -0
- package/dist/runtime/request-telemetry.js +2 -1
- package/dist/runtime/resolver-runtime-options.d.ts +14 -0
- package/dist/runtime/resolver-runtime-options.js +33 -0
- package/dist/runtime/resolver-shared.d.ts +3 -2
- package/dist/runtime/resolver-shared.js +4 -4
- package/dist/runtime/resolver-telemetry.d.ts +1 -0
- package/dist/runtime/resolver-telemetry.js +1 -1
- package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
- package/dist/runtime/resolver-vendors/browser.js +46 -0
- package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
- package/dist/runtime/resolver-vendors/hosts.js +35 -0
- package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
- package/dist/runtime/resolver-vendors/types.d.ts +5 -4
- package/dist/runtime/resolver.d.ts +4 -1
- package/dist/runtime/resolver.js +46 -13
- package/dist/runtime/state-telemetry.d.ts +79 -0
- package/dist/runtime/state-telemetry.js +194 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +26 -7
- package/dist/runtime/stealth-cookies.d.ts +5 -1
- package/dist/runtime/stealth-cookies.js +21 -1
- package/dist/runtime/stealth-owned-headers.d.ts +26 -0
- package/dist/runtime/stealth-owned-headers.js +37 -0
- package/dist/runtime/stealth-telemetry.d.ts +92 -0
- package/dist/runtime/stealth-telemetry.js +179 -0
- package/dist/runtime/stealth.d.ts +4 -1
- package/dist/runtime/stealth.js +228 -85
- package/dist/runtime/stt-telemetry.d.ts +77 -0
- package/dist/runtime/stt-telemetry.js +176 -0
- package/dist/runtime/stt.js +15 -6
- package/dist/runtime-boundary-lint.d.ts +132 -0
- package/dist/runtime-boundary-lint.js +586 -0
- package/dist/server/error-stack-frames.d.ts +35 -0
- package/dist/server/error-stack-frames.js +219 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +4 -0
- package/dist/server/sdk-version.d.ts +3 -0
- package/dist/server/sdk-version.js +19 -0
- package/dist/server/self-test.js +1 -18
- package/dist/server/sensitive-values.d.ts +1 -1
- package/dist/server/sensitive-values.js +9 -0
- package/dist/server/serve-implementation.d.ts +51 -2
- package/dist/server/serve-implementation.js +337 -90
- package/dist/server/types.d.ts +1 -0
- package/dist/server/types.js +7 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
- package/dist/stateful/stateful-provider-runtime-context.js +1 -0
- package/dist/types.d.ts +123 -1
- package/dist/typescript-module.d.ts +39 -0
- package/dist/typescript-module.js +72 -0
- package/package.json +6 -1
- package/src/cli/commands.ts +14 -0
- package/src/cli/deployment-intent.ts +364 -0
- package/src/cli/migrate-deployment-intent.ts +1908 -0
- package/src/cli/migrate-provider-shape.ts +10 -4
- package/src/cli/resolver-runtime.ts +72 -0
- package/src/define.ts +13 -0
- package/src/dev.ts +9 -2
- package/src/engine.ts +38 -2
- package/src/error-resolution.ts +58 -0
- package/src/errors.ts +77 -1
- package/src/handle-meta.ts +51 -1
- package/src/handle.ts +92 -10
- package/src/health-scenario.ts +38 -0
- package/src/i18n/error-messages.ts +255 -0
- package/src/i18n/index.ts +1 -0
- package/src/i18n/keys.ts +80 -6
- package/src/index.ts +86 -0
- package/src/lint.ts +604 -91
- package/src/provider.ts +12 -0
- package/src/runtime/browser-telemetry-binding.ts +92 -0
- package/src/runtime/browser-telemetry.ts +289 -0
- package/src/runtime/browser.ts +249 -65
- package/src/runtime/cache-telemetry.ts +247 -0
- package/src/runtime/cache.ts +68 -17
- package/src/runtime/capability-response.ts +53 -0
- package/src/runtime/capability-telemetry.ts +101 -0
- package/src/runtime/diagnostic-env.ts +11 -1
- package/src/runtime/engine-mode.ts +233 -0
- package/src/runtime/handle.ts +9 -1
- package/src/runtime/http-telemetry-guard.ts +66 -13
- package/src/runtime/http.ts +168 -37
- package/src/runtime/instrumentation.ts +105 -16
- package/src/runtime/ocr-telemetry.ts +308 -0
- package/src/runtime/ocr.ts +114 -74
- package/src/runtime/request-telemetry.ts +2 -1
- package/src/runtime/resolver-runtime-options.ts +50 -0
- package/src/runtime/resolver-shared.ts +9 -4
- package/src/runtime/resolver-telemetry.ts +1 -1
- package/src/runtime/resolver-vendors/browser.ts +65 -7
- package/src/runtime/resolver-vendors/hosts.ts +43 -0
- package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
- package/src/runtime/resolver-vendors/types.ts +5 -4
- package/src/runtime/resolver.ts +64 -21
- package/src/runtime/state-telemetry.ts +298 -0
- package/src/runtime/state.ts +46 -45
- package/src/runtime/stealth-cookies.ts +24 -1
- package/src/runtime/stealth-owned-headers.ts +41 -0
- package/src/runtime/stealth-telemetry.ts +304 -0
- package/src/runtime/stealth.ts +355 -150
- package/src/runtime/stt-telemetry.ts +282 -0
- package/src/runtime/stt.ts +93 -71
- package/src/runtime-boundary-lint.ts +703 -0
- package/src/server/error-stack-frames.ts +214 -0
- package/src/server/index.ts +53 -0
- package/src/server/sdk-version.ts +22 -0
- package/src/server/self-test.ts +1 -21
- package/src/server/sensitive-values.ts +14 -0
- package/src/server/serve-implementation.ts +569 -108
- package/src/server/types.ts +7 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
- package/src/stateful/stateful-provider-runtime-context.ts +4 -0
- package/src/types.ts +128 -1
- package/src/typescript-module.ts +100 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +0 -12
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { SttContext } from "../types.js";
|
|
2
|
+
import { type ClosedEnum, type SpanIndex, type TelemetryContributor } from "./request-telemetry.js";
|
|
3
|
+
export type SttTelemetryBackend = "cloudflare-workers-ai" | "custom" | "unavailable";
|
|
4
|
+
export type SttTelemetryEngine = "workers-ai" | "custom";
|
|
5
|
+
export type SttTelemetryErrorCode = "STT_UNAVAILABLE" | "UNSUPPORTED_STT_BACKEND" | "STT_UPSTREAM_FAILED" | "STT_AUDIO_TOO_LARGE" | "UNSUPPORTED_STT_OPTION" | "INVALID_STT_AUDIO" | "INVALID_STT_VERIFICATION_CODE_OPTIONS" | "NO_CODE_FOUND" | "AMBIGUOUS_CODE" | "transport_network_error" | "transport_timeout" | "other";
|
|
6
|
+
export type SttTelemetryModel = "whisper-large-v3-turbo";
|
|
7
|
+
export type SttTelemetryEvent = {
|
|
8
|
+
backend: SttTelemetryBackend;
|
|
9
|
+
engine: SttTelemetryEngine;
|
|
10
|
+
model?: string;
|
|
11
|
+
ms: number;
|
|
12
|
+
status?: number;
|
|
13
|
+
audioBytes?: number;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
usage?: number;
|
|
16
|
+
warnings?: number;
|
|
17
|
+
errorCode?: SttTelemetryErrorCode;
|
|
18
|
+
diagnostics?: string;
|
|
19
|
+
};
|
|
20
|
+
export interface SttTelemetrySink {
|
|
21
|
+
record(event: SttTelemetryEvent): void;
|
|
22
|
+
markTelemetryFailed?(): void;
|
|
23
|
+
}
|
|
24
|
+
export type SttTelemetryLogPayload = {
|
|
25
|
+
telemetryFailed?: true;
|
|
26
|
+
diagnostics?: string[];
|
|
27
|
+
backend: SttTelemetryBackend;
|
|
28
|
+
engine: SttTelemetryEngine;
|
|
29
|
+
model?: string;
|
|
30
|
+
ms: number;
|
|
31
|
+
status?: number;
|
|
32
|
+
audioBytes: number;
|
|
33
|
+
durationMs: number;
|
|
34
|
+
usage: number;
|
|
35
|
+
warnings: number;
|
|
36
|
+
lastErrorCode?: SttTelemetryErrorCode;
|
|
37
|
+
samples?: Array<Omit<SttTelemetryEvent, "backend" | "engine" | "model" | "diagnostics">>;
|
|
38
|
+
samplesDropped?: number;
|
|
39
|
+
};
|
|
40
|
+
export type SttTelemetryHeaderPayload = {
|
|
41
|
+
backend: ClosedEnum<SttTelemetryBackend>;
|
|
42
|
+
engine: ClosedEnum<SttTelemetryEngine>;
|
|
43
|
+
model?: ClosedEnum<SttTelemetryModel>;
|
|
44
|
+
ms: number;
|
|
45
|
+
status?: number;
|
|
46
|
+
audioBytes: number;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
usage: number;
|
|
49
|
+
warnings: number;
|
|
50
|
+
lastErrorCode?: ClosedEnum<SttTelemetryErrorCode>;
|
|
51
|
+
samples?: Array<{
|
|
52
|
+
ms: number;
|
|
53
|
+
status?: number;
|
|
54
|
+
audioBytes?: number;
|
|
55
|
+
durationMs?: number;
|
|
56
|
+
usage?: number;
|
|
57
|
+
warnings?: number;
|
|
58
|
+
errorCode?: ClosedEnum<SttTelemetryErrorCode>;
|
|
59
|
+
}>;
|
|
60
|
+
samplesDropped?: number;
|
|
61
|
+
};
|
|
62
|
+
export declare class SttTelemetryCollector implements SttTelemetrySink, TelemetryContributor<SttTelemetryLogPayload, SttTelemetryHeaderPayload> {
|
|
63
|
+
#private;
|
|
64
|
+
readonly key: "stt";
|
|
65
|
+
constructor(options?: {
|
|
66
|
+
redact?: (text: string) => string;
|
|
67
|
+
});
|
|
68
|
+
markTelemetryFailed(): void;
|
|
69
|
+
record(event: SttTelemetryEvent): void;
|
|
70
|
+
toLogPayload(_spans: SpanIndex): SttTelemetryLogPayload | undefined;
|
|
71
|
+
toHeaderPayload(log: SttTelemetryLogPayload): SttTelemetryHeaderPayload;
|
|
72
|
+
}
|
|
73
|
+
export declare function bindSttTelemetry(context: SttContext, sink: SttTelemetrySink, options?: {
|
|
74
|
+
backend?: SttTelemetryBackend;
|
|
75
|
+
engine?: SttTelemetryEngine;
|
|
76
|
+
model?: string;
|
|
77
|
+
}): SttContext;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { add, capabilityErrorText, capabilityFacts, capabilityMetadata, capabilityText, inputBytes, integer, observeCapability, registerCapabilityInput, } from "./capability-telemetry.js";
|
|
2
|
+
import { closedEnum, } from "./request-telemetry.js";
|
|
3
|
+
const ERROR_CODES = new Set([
|
|
4
|
+
"STT_UNAVAILABLE",
|
|
5
|
+
"UNSUPPORTED_STT_BACKEND",
|
|
6
|
+
"STT_UPSTREAM_FAILED",
|
|
7
|
+
"STT_AUDIO_TOO_LARGE",
|
|
8
|
+
"UNSUPPORTED_STT_OPTION",
|
|
9
|
+
"INVALID_STT_AUDIO",
|
|
10
|
+
"INVALID_STT_VERIFICATION_CODE_OPTIONS",
|
|
11
|
+
"NO_CODE_FOUND",
|
|
12
|
+
"AMBIGUOUS_CODE",
|
|
13
|
+
"transport_network_error",
|
|
14
|
+
"transport_timeout",
|
|
15
|
+
"other",
|
|
16
|
+
]);
|
|
17
|
+
const MODELS = new Map([
|
|
18
|
+
["@cf/openai/whisper-large-v3-turbo", "whisper-large-v3-turbo"],
|
|
19
|
+
]);
|
|
20
|
+
function errorCode(error) {
|
|
21
|
+
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
22
|
+
return typeof code === "string" && ERROR_CODES.has(code)
|
|
23
|
+
? code
|
|
24
|
+
: "other";
|
|
25
|
+
}
|
|
26
|
+
export class SttTelemetryCollector {
|
|
27
|
+
key = "stt";
|
|
28
|
+
#redact;
|
|
29
|
+
#samples = [];
|
|
30
|
+
#summary;
|
|
31
|
+
#diagnostics = [];
|
|
32
|
+
#dropped = 0;
|
|
33
|
+
#failed = false;
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.#redact = options.redact;
|
|
36
|
+
}
|
|
37
|
+
markTelemetryFailed() {
|
|
38
|
+
this.#failed = true;
|
|
39
|
+
this.#summary ??= {
|
|
40
|
+
backend: "custom",
|
|
41
|
+
engine: "custom",
|
|
42
|
+
ms: 0,
|
|
43
|
+
audioBytes: 0,
|
|
44
|
+
durationMs: 0,
|
|
45
|
+
usage: 0,
|
|
46
|
+
warnings: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
record(event) {
|
|
50
|
+
const sample = {
|
|
51
|
+
ms: integer(event.ms),
|
|
52
|
+
...(event.status === undefined ? {} : { status: integer(event.status) }),
|
|
53
|
+
...(event.audioBytes === undefined ? {} : { audioBytes: integer(event.audioBytes) }),
|
|
54
|
+
...(event.durationMs === undefined ? {} : { durationMs: integer(event.durationMs) }),
|
|
55
|
+
...(event.usage === undefined ? {} : { usage: integer(event.usage) }),
|
|
56
|
+
...(event.warnings === undefined ? {} : { warnings: integer(event.warnings) }),
|
|
57
|
+
...(event.errorCode ? { errorCode: event.errorCode } : {}),
|
|
58
|
+
...(event.diagnostics === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: { diagnostics: capabilityText(event.diagnostics, this.#redact, true) }),
|
|
61
|
+
};
|
|
62
|
+
const prior = this.#summary;
|
|
63
|
+
this.#summary = {
|
|
64
|
+
backend: event.backend,
|
|
65
|
+
engine: event.engine,
|
|
66
|
+
...(event.model === undefined ? {} : { model: capabilityText(event.model, this.#redact) }),
|
|
67
|
+
ms: add(prior?.ms ?? 0, sample.ms),
|
|
68
|
+
...(sample.status === undefined ? {} : { status: sample.status }),
|
|
69
|
+
audioBytes: add(prior?.audioBytes ?? 0, sample.audioBytes ?? 0),
|
|
70
|
+
durationMs: add(prior?.durationMs ?? 0, sample.durationMs ?? 0),
|
|
71
|
+
usage: add(prior?.usage ?? 0, sample.usage ?? 0),
|
|
72
|
+
warnings: add(prior?.warnings ?? 0, sample.warnings ?? 0),
|
|
73
|
+
...(event.errorCode ? { lastErrorCode: event.errorCode } : {}),
|
|
74
|
+
};
|
|
75
|
+
if (this.#samples.length < 24) {
|
|
76
|
+
const { diagnostics, ...closedSample } = sample;
|
|
77
|
+
this.#samples.push(closedSample);
|
|
78
|
+
if (diagnostics !== undefined)
|
|
79
|
+
this.#diagnostics.push(diagnostics);
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
this.#dropped = add(this.#dropped, 1);
|
|
83
|
+
}
|
|
84
|
+
toLogPayload(_spans) {
|
|
85
|
+
if (!this.#summary)
|
|
86
|
+
return undefined;
|
|
87
|
+
return {
|
|
88
|
+
...this.#summary,
|
|
89
|
+
...(this.#diagnostics.length ? { diagnostics: [...this.#diagnostics] } : {}),
|
|
90
|
+
...(this.#failed ? { telemetryFailed: true } : {}),
|
|
91
|
+
samples: this.#samples.map((s) => ({ ...s })),
|
|
92
|
+
...(this.#dropped ? { samplesDropped: this.#dropped } : {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
toHeaderPayload(log) {
|
|
96
|
+
return {
|
|
97
|
+
backend: closedEnum(log.backend),
|
|
98
|
+
engine: closedEnum(log.engine),
|
|
99
|
+
...(log.model && MODELS.has(log.model) ? { model: closedEnum(MODELS.get(log.model)) } : {}),
|
|
100
|
+
ms: log.ms,
|
|
101
|
+
...(log.status === undefined ? {} : { status: log.status }),
|
|
102
|
+
audioBytes: log.audioBytes,
|
|
103
|
+
durationMs: log.durationMs,
|
|
104
|
+
usage: log.usage,
|
|
105
|
+
warnings: log.warnings,
|
|
106
|
+
...(log.lastErrorCode ? { lastErrorCode: closedEnum(log.lastErrorCode) } : {}),
|
|
107
|
+
...(log.samples
|
|
108
|
+
? {
|
|
109
|
+
samples: log.samples.map((s) => ({
|
|
110
|
+
ms: s.ms,
|
|
111
|
+
...(s.status === undefined ? {} : { status: s.status }),
|
|
112
|
+
...(s.audioBytes === undefined ? {} : { audioBytes: s.audioBytes }),
|
|
113
|
+
...(s.durationMs === undefined ? {} : { durationMs: s.durationMs }),
|
|
114
|
+
...(s.usage === undefined ? {} : { usage: s.usage }),
|
|
115
|
+
...(s.warnings === undefined ? {} : { warnings: s.warnings }),
|
|
116
|
+
...(s.errorCode ? { errorCode: closedEnum(s.errorCode) } : {}),
|
|
117
|
+
})),
|
|
118
|
+
}
|
|
119
|
+
: {}),
|
|
120
|
+
...(log.samplesDropped ? { samplesDropped: log.samplesDropped } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export function bindSttTelemetry(context, sink, options = {}) {
|
|
125
|
+
const metadata = capabilityMetadata(context);
|
|
126
|
+
const backend = options.backend ?? metadata?.backend ?? "custom";
|
|
127
|
+
const engine = options.engine ?? metadata?.engine ?? "custom";
|
|
128
|
+
const model = options.model ?? metadata?.model;
|
|
129
|
+
async function run(input, operation) {
|
|
130
|
+
const started = performance.now();
|
|
131
|
+
const facts = {};
|
|
132
|
+
observeCapability(sink, () => registerCapabilityInput(input));
|
|
133
|
+
let result;
|
|
134
|
+
try {
|
|
135
|
+
result = await capabilityFacts.run(facts, operation);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
observeCapability(sink, () => {
|
|
139
|
+
const status = error &&
|
|
140
|
+
typeof error === "object" &&
|
|
141
|
+
"status" in error &&
|
|
142
|
+
typeof error.status === "number"
|
|
143
|
+
? error.status
|
|
144
|
+
: undefined;
|
|
145
|
+
return sink.record({
|
|
146
|
+
backend,
|
|
147
|
+
engine,
|
|
148
|
+
model,
|
|
149
|
+
ms: performance.now() - started,
|
|
150
|
+
status: facts.status ?? status,
|
|
151
|
+
audioBytes: inputBytes(input),
|
|
152
|
+
errorCode: errorCode(error),
|
|
153
|
+
diagnostics: `${capabilityErrorText(error)} ${facts.diagnostics ?? ""}`,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
observeCapability(sink, () => sink.record({
|
|
159
|
+
backend,
|
|
160
|
+
engine,
|
|
161
|
+
model: model,
|
|
162
|
+
ms: performance.now() - started,
|
|
163
|
+
status: facts.status,
|
|
164
|
+
audioBytes: result.usage?.audioBytes ?? inputBytes(input),
|
|
165
|
+
durationMs: result.durationMs,
|
|
166
|
+
usage: result.usage?.audioDurationMs,
|
|
167
|
+
warnings: result.warnings?.length ?? 0,
|
|
168
|
+
}));
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
...context,
|
|
173
|
+
transcribe: (request) => run(request.audio, () => context.transcribe(request)),
|
|
174
|
+
extractVerificationCode: (text, opts) => context.extractVerificationCode(text, opts),
|
|
175
|
+
};
|
|
176
|
+
}
|
package/dist/runtime/stt.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { readDiagnosticEnv } from "./diagnostic-env.js";
|
|
2
1
|
import { ProviderError, TransportError, ValidationError } from "../errors.js";
|
|
2
|
+
import { readCapabilityErrorBody } from "./capability-response.js";
|
|
3
|
+
import { captureCapability, registerCapabilityInput, tagCapability, } from "./capability-telemetry.js";
|
|
4
|
+
import { readDiagnosticEnv, registerDiagnosticValue } from "./diagnostic-env.js";
|
|
3
5
|
import { createTimeoutController, isTimeoutLikeError } from "./timeout.js";
|
|
4
6
|
export const APIFUSE__STT__BACKEND_ENV = "APIFUSE__STT__BACKEND";
|
|
5
7
|
export const APIFUSE__STT__MODEL_ENV = "APIFUSE__STT__MODEL";
|
|
@@ -15,7 +17,7 @@ function providerError(message, options) {
|
|
|
15
17
|
return new ProviderError(message, options);
|
|
16
18
|
}
|
|
17
19
|
function createErrorSttClient(options) {
|
|
18
|
-
return {
|
|
20
|
+
return tagCapability({
|
|
19
21
|
async transcribe() {
|
|
20
22
|
throw providerError(options.message, {
|
|
21
23
|
code: options.code,
|
|
@@ -23,7 +25,7 @@ function createErrorSttClient(options) {
|
|
|
23
25
|
});
|
|
24
26
|
},
|
|
25
27
|
extractVerificationCode,
|
|
26
|
-
};
|
|
28
|
+
}, { backend: "unavailable", engine: "custom" });
|
|
27
29
|
}
|
|
28
30
|
export function createUnsupportedSttClient(reason) {
|
|
29
31
|
return createErrorSttClient({
|
|
@@ -209,8 +211,11 @@ function toSttTranscript(payload, audioBytes) {
|
|
|
209
211
|
export function createCloudflareWorkersAiSttClient(options) {
|
|
210
212
|
const model = options.model ?? DEFAULT_CLOUDFLARE_WORKERS_AI_STT_MODEL;
|
|
211
213
|
const runFetch = options.fetch ?? fetch;
|
|
212
|
-
return {
|
|
214
|
+
return tagCapability({
|
|
213
215
|
async transcribe(request) {
|
|
216
|
+
registerCapabilityInput(request.audio);
|
|
217
|
+
registerDiagnosticValue(options.apiToken);
|
|
218
|
+
registerDiagnosticValue(`Bearer ${options.apiToken}`);
|
|
214
219
|
const warnings = [];
|
|
215
220
|
if (request.initialPrompt && effectivePromptPolicy(request) !== "custom-hint") {
|
|
216
221
|
const warning = warnOrThrowUnsupportedOption(request, "initialPrompt is honored only when promptPolicy is custom-hint");
|
|
@@ -235,16 +240,20 @@ export function createCloudflareWorkersAiSttClient(options) {
|
|
|
235
240
|
catch (error) {
|
|
236
241
|
throw toSttTransportError(error);
|
|
237
242
|
}
|
|
238
|
-
|
|
243
|
+
captureCapability({ status: response.status });
|
|
239
244
|
if (!response.ok) {
|
|
245
|
+
const echoed = await readCapabilityErrorBody(response, timeout.controller.signal);
|
|
246
|
+
captureCapability({ diagnostics: echoed });
|
|
240
247
|
throw new TransportError("STT upstream request failed", {
|
|
241
248
|
code: "STT_UPSTREAM_FAILED",
|
|
242
249
|
status: response.status,
|
|
243
250
|
upstreamStatus: response.status,
|
|
244
251
|
});
|
|
245
252
|
}
|
|
253
|
+
const payload = await response.json().catch(() => undefined);
|
|
246
254
|
const envelope = unknownRecord(payload);
|
|
247
255
|
if (envelope?.success === false) {
|
|
256
|
+
captureCapability({ diagnostics: JSON.stringify(payload) });
|
|
248
257
|
throw new TransportError("STT upstream returned an error", {
|
|
249
258
|
code: "STT_UPSTREAM_FAILED",
|
|
250
259
|
status: 502,
|
|
@@ -270,7 +279,7 @@ export function createCloudflareWorkersAiSttClient(options) {
|
|
|
270
279
|
}
|
|
271
280
|
},
|
|
272
281
|
extractVerificationCode,
|
|
273
|
-
};
|
|
282
|
+
}, { backend: "cloudflare-workers-ai", engine: "workers-ai", model });
|
|
274
283
|
}
|
|
275
284
|
const EN_DIGITS = {
|
|
276
285
|
zero: "0",
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime boundary lint: provider runtime source must reach the outside world
|
|
3
|
+
* through the SDK context (`ctx.http`, `ctx.stealth`, `ctx.env`,
|
|
4
|
+
* `ctx.credential`, `ctx.browser`), not through ambient Node/Bun globals.
|
|
5
|
+
*
|
|
6
|
+
* Three rules, all reported at `warn` level in this first release so the
|
|
7
|
+
* fleet can migrate before the level is raised:
|
|
8
|
+
*
|
|
9
|
+
* - `process-env-direct-read`: `process.env.X`, `process.env["X"]`, a bare
|
|
10
|
+
* `process.env` object use, and the `Bun.env` equivalents. Runtime bootstrap
|
|
11
|
+
* keys (`APIFUSE__RUNTIME__*`) are exempt everywhere because `serve()`
|
|
12
|
+
* callers read the port and pod identity before a context exists.
|
|
13
|
+
* - `node-runtime-module-import`: value imports of `fs`, `fs/promises`, `net`,
|
|
14
|
+
* `tls`, `dgram`, `http`, `https`, `http2`, `child_process` (with or without
|
|
15
|
+
* the `node:` prefix) via import/export declarations, `require()`, or dynamic
|
|
16
|
+
* `import()`, plus the Bun equivalents `Bun.spawn`, `Bun.spawnSync`, `Bun.$`,
|
|
17
|
+
* `Bun.file`, `Bun.write`. Type-only imports are not runtime reach and are
|
|
18
|
+
* ignored.
|
|
19
|
+
* - `direct-fetch-call`: a call to the global `fetch` (bare identifier, or
|
|
20
|
+
* `globalThis`/`window`/`self`/`global` member). A bare `fetch` call whose
|
|
21
|
+
* enclosing scope declares a `fetch` binding (parameter, variable, import,
|
|
22
|
+
* function, catch clause) is calling that binding, not the global, and is
|
|
23
|
+
* left alone; the check is lexical, so a wrapper that takes `fetch` as a
|
|
24
|
+
* parameter does not hide a global `fetch()` elsewhere in the same file.
|
|
25
|
+
* `ctx.stealth.fetch()` is a member call and never matches.
|
|
26
|
+
*
|
|
27
|
+
* Files are parsed with the script kind their extension implies (`.ts` as
|
|
28
|
+
* TypeScript, `.tsx` as TSX, …). Parsing everything as TSX would make a
|
|
29
|
+
* generic arrow (`<T>(value: T) => value`) or an angle-bracket assertion in an
|
|
30
|
+
* ordinary `.ts` file read as JSX, and everything after it would silently drop
|
|
31
|
+
* out of the AST.
|
|
32
|
+
*
|
|
33
|
+
* Scope is the provider *runtime* source: JavaScript/TypeScript files under
|
|
34
|
+
* `providerSourceFiles` minus tests, recorded fixtures, the root bootstrap
|
|
35
|
+
* entrypoints (`dev.ts`, `start.ts`, `deploy.ts`) and the operator tooling
|
|
36
|
+
* directories (`scripts/`, `tools/`, `bin/`). Tooling legitimately reads the
|
|
37
|
+
* ambient environment and the filesystem when a human runs it; the rule is
|
|
38
|
+
* about code the pod executes on behalf of a request.
|
|
39
|
+
*
|
|
40
|
+
* A deliberate exception is acknowledged with the same escape hatch the submit
|
|
41
|
+
* check uses: `// @apifuse-allow <rule>: <reason>` on the finding line or the
|
|
42
|
+
* line directly above it. Acknowledged findings are reported as information so
|
|
43
|
+
* `apifuse check` still lists them.
|
|
44
|
+
*/
|
|
45
|
+
import type { LintDiagnostic, ProviderLintInformation, ProviderLintResult } from "./lint.js";
|
|
46
|
+
import { type TypeScriptCompilerModuleLike, type TypeScriptModule } from "./typescript-module.js";
|
|
47
|
+
export declare const PROCESS_ENV_DIRECT_READ_RULE = "process-env-direct-read";
|
|
48
|
+
export declare const NODE_RUNTIME_MODULE_IMPORT_RULE = "node-runtime-module-import";
|
|
49
|
+
export declare const DIRECT_FETCH_CALL_RULE = "direct-fetch-call";
|
|
50
|
+
export declare const RUNTIME_BOUNDARY_RULES: readonly ["process-env-direct-read", "node-runtime-module-import", "direct-fetch-call"];
|
|
51
|
+
export type RuntimeBoundaryRule = (typeof RUNTIME_BOUNDARY_RULES)[number];
|
|
52
|
+
/**
|
|
53
|
+
* Environment names a provider may read from `process.env` directly. These
|
|
54
|
+
* are consumed before `serve()` builds a context (port, pod identity), so
|
|
55
|
+
* `ctx.env` cannot carry them. The whole `APIFUSE__RUNTIME__` family is the
|
|
56
|
+
* bootstrap contract; nothing else is exempt.
|
|
57
|
+
*/
|
|
58
|
+
export declare const BOOTSTRAP_ENV_NAME_PREFIX = "APIFUSE__RUNTIME__";
|
|
59
|
+
export declare function isBootstrapEnvName(name: string): boolean;
|
|
60
|
+
type RuntimeBoundaryFinding = {
|
|
61
|
+
rule: RuntimeBoundaryRule;
|
|
62
|
+
/** 1-based line. */
|
|
63
|
+
line: number;
|
|
64
|
+
/** What was reached: the env name, module specifier, or call text. */
|
|
65
|
+
subject: string;
|
|
66
|
+
};
|
|
67
|
+
type RuntimeBoundaryFileReport = {
|
|
68
|
+
findings: RuntimeBoundaryFinding[];
|
|
69
|
+
acknowledged: Array<RuntimeBoundaryFinding & {
|
|
70
|
+
reason: string;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
/** True for the files the runtime boundary rules look at. */
|
|
74
|
+
export declare function isRuntimeBoundarySourceFile(relativePath: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Script kind for a provider source file, from its extension. `.tsx`/`.jsx`
|
|
77
|
+
* enable JSX; everything else (`.ts`, `.mts`, `.cts`, `.js`, `.mjs`, `.cjs`,
|
|
78
|
+
* and the synthetic names used for in-memory sources) does not, so a generic
|
|
79
|
+
* arrow or `<T>value` assertion in a `.ts` file parses as TypeScript instead
|
|
80
|
+
* of swallowing the rest of the file as unterminated JSX.
|
|
81
|
+
*/
|
|
82
|
+
export declare function scriptKindForSourceFile(ts: TypeScriptModule, fileName: string): import("typescript").ScriptKind;
|
|
83
|
+
export declare function analyzeRuntimeBoundary(ts: TypeScriptModule, fileName: string, source: string): RuntimeBoundaryFileReport;
|
|
84
|
+
export type RuntimeBoundaryLintInput = {
|
|
85
|
+
authFlowSource?: string;
|
|
86
|
+
providerSourceFiles?: Record<string, string>;
|
|
87
|
+
operations?: Record<string, {
|
|
88
|
+
handler?: unknown;
|
|
89
|
+
source?: string;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Lint the provider runtime boundary. Returns warn-level diagnostics (one per
|
|
94
|
+
* file and rule, listing every line) and information entries for findings
|
|
95
|
+
* acknowledged with `@apifuse-allow`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function lintRuntimeBoundary(ts: TypeScriptModule, provider: RuntimeBoundaryLintInput, readOperationSource: (operation: {
|
|
98
|
+
handler?: unknown;
|
|
99
|
+
source?: string;
|
|
100
|
+
}) => string): {
|
|
101
|
+
diagnostics: LintDiagnostic[];
|
|
102
|
+
information: ProviderLintInformation[];
|
|
103
|
+
};
|
|
104
|
+
export type LintRuntimeBoundarySourcesOptions = {
|
|
105
|
+
/**
|
|
106
|
+
* A loaded TypeScript compiler API module to parse with (`typescript` 6.x
|
|
107
|
+
* or `@typescript/typescript6`). When omitted the SDK resolves one from its
|
|
108
|
+
* own install location, trying `typescript` first and falling back to
|
|
109
|
+
* `@typescript/typescript6` when `typescript` is the 7.x native shell
|
|
110
|
+
* without `createSourceFile`. A caller whose dependency tree pins its own
|
|
111
|
+
* compiler module (the APIFuse monorepo contract check) passes it here so
|
|
112
|
+
* the parse does not depend on what hoists next to the SDK.
|
|
113
|
+
*/
|
|
114
|
+
typescript?: TypeScriptCompilerModuleLike;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Lint provider runtime source files for the runtime boundary rules without a
|
|
118
|
+
* provider definition: `files` maps provider-root-relative paths to source
|
|
119
|
+
* text (the same shape `apifuse check` collects as `providerSourceFiles`).
|
|
120
|
+
* Out-of-scope paths (tests, recorded fixtures, `.d.ts`, the root
|
|
121
|
+
* `dev.ts`/`start.ts`/`deploy.ts`, `scripts/`, `tools/`, `bin/`) are skipped
|
|
122
|
+
* with `isRuntimeBoundarySourceFile`. Diagnostics carry
|
|
123
|
+
* `field: "sourceFiles.<path>"`; `@apifuse-allow` acknowledgements come back
|
|
124
|
+
* as `information`.
|
|
125
|
+
*
|
|
126
|
+
* Parses with `options.typescript` when given, otherwise with the compiler
|
|
127
|
+
* module resolved from the installed SDK (see `getTypeScript`). This is the
|
|
128
|
+
* entry point the platform contract check uses to apply the rules with the
|
|
129
|
+
* monorepo's SDK pin instead of each provider's own pin.
|
|
130
|
+
*/
|
|
131
|
+
export declare function lintRuntimeBoundarySources(files: Record<string, string>, options?: LintRuntimeBoundarySourcesOptions): ProviderLintResult;
|
|
132
|
+
export {};
|