@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,219 @@
|
|
|
1
|
+
import { redactDiagnosticText } from "../runtime/diagnostic-redactor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Bounded, whitelist-shaped stack frames for masked (>=500) provider failures.
|
|
4
|
+
*
|
|
5
|
+
* `sanitizeDiagnosticText` is a blacklist scrubber for free text: a V8/Bun
|
|
6
|
+
* frame such as `at inner (/srv/app/probe.ts:3:30)` comes out as
|
|
7
|
+
* `at inner ([REDACTED])`, and even a bare `serve-implementation.ts:2039:12`
|
|
8
|
+
* trips the opaque-token heuristics. Stack frames therefore never go through
|
|
9
|
+
* it. Instead each frame is parsed against a strict grammar and re-emitted
|
|
10
|
+
* from its parts only: an optional `async`/`new` marker, the function name
|
|
11
|
+
* (identifier characters only), the file *basename* (never a filesystem
|
|
12
|
+
* directory, URL, or drive letter) and the numeric line:column. The sole
|
|
13
|
+
* exception is an engine-internal location (`native`, or a `node:` module id
|
|
14
|
+
* of identifier-shaped segments), which is kept verbatim because it names no
|
|
15
|
+
* deployment path. Frames that do not fit the grammar (eval frames, frames
|
|
16
|
+
* without a location, oversized lines) are dropped rather than passed
|
|
17
|
+
* through.
|
|
18
|
+
*/
|
|
19
|
+
export const MAX_PROVIDER_ERROR_STACK_FRAMES = 5;
|
|
20
|
+
const MAX_STACK_SCAN_CHARS = 16 * 1024;
|
|
21
|
+
const MAX_STACK_SCAN_LINES = 64;
|
|
22
|
+
const MAX_STACK_LINE_CHARS = 1024;
|
|
23
|
+
const FRAME_LINE = /^\s+at\s+(\S.*)$/;
|
|
24
|
+
const FRAME_MODIFIER = /^(async|new)\s+(.*)$/;
|
|
25
|
+
const FRAME_FUNCTION_NAME = /^[\w$.<>[\] #]{1,80}$/;
|
|
26
|
+
const FRAME_LOCATION = /^(.*):(\d{1,7}):(\d{1,7})$/;
|
|
27
|
+
const MAX_NODE_MODULE_ID_CHARS = 128;
|
|
28
|
+
// Engine-internal module ids only: `node:` plus `/`-separated identifier-shaped
|
|
29
|
+
// segments (`node:async_hooks`, `node:internal/process/task_queues`). Every
|
|
30
|
+
// segment must start with a letter or `_`, so `..` traversal and dotfile
|
|
31
|
+
// segments cannot ride through this branch.
|
|
32
|
+
const FRAME_NODE_MODULE = /^node:[A-Za-z_][\w.-]{0,40}(?:\/[A-Za-z_][\w.-]{0,40}){0,7}$/;
|
|
33
|
+
const FRAME_BASENAME = /^[\w.$-]{1,120}$/;
|
|
34
|
+
// A basename of dots only (`.`, `..`, `...`) names no file.
|
|
35
|
+
const FRAME_BASENAME_HAS_NAME = /[^.]/;
|
|
36
|
+
function parseFunctionName(raw) {
|
|
37
|
+
let rest = raw.trim();
|
|
38
|
+
let modifier;
|
|
39
|
+
const modified = FRAME_MODIFIER.exec(rest);
|
|
40
|
+
if (modified) {
|
|
41
|
+
modifier = modified[1];
|
|
42
|
+
rest = modified[2].trim();
|
|
43
|
+
}
|
|
44
|
+
if (rest.length === 0)
|
|
45
|
+
return { modifier };
|
|
46
|
+
if (!FRAME_FUNCTION_NAME.test(rest))
|
|
47
|
+
return undefined;
|
|
48
|
+
return { modifier, name: rest };
|
|
49
|
+
}
|
|
50
|
+
function parseLocation(raw) {
|
|
51
|
+
if (/[\s()]/.test(raw))
|
|
52
|
+
return undefined;
|
|
53
|
+
const located = FRAME_LOCATION.exec(raw);
|
|
54
|
+
if (!located)
|
|
55
|
+
return undefined;
|
|
56
|
+
const [, path, line, column] = located;
|
|
57
|
+
let file;
|
|
58
|
+
if (path === "native" ||
|
|
59
|
+
(path.length <= MAX_NODE_MODULE_ID_CHARS && FRAME_NODE_MODULE.test(path))) {
|
|
60
|
+
// Not filesystem paths: engine-internal module ids carry no deployment
|
|
61
|
+
// information. This is the one branch that keeps a `/`, and the grammar
|
|
62
|
+
// above bounds it to identifier segments.
|
|
63
|
+
file = path;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const separator = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
67
|
+
const basename = separator >= 0 ? path.slice(separator + 1) : path;
|
|
68
|
+
if (!FRAME_BASENAME.test(basename))
|
|
69
|
+
return undefined;
|
|
70
|
+
// `.` and `..` pass the basename character class but name no file: they
|
|
71
|
+
// are the traversal tokens the grammar exists to exclude, so a path such
|
|
72
|
+
// as `/srv/app/..:1:1` must not be emitted as `..:1:1`.
|
|
73
|
+
if (!FRAME_BASENAME_HAS_NAME.test(basename))
|
|
74
|
+
return undefined;
|
|
75
|
+
file = basename;
|
|
76
|
+
}
|
|
77
|
+
return `${file}:${line}:${column}`;
|
|
78
|
+
}
|
|
79
|
+
/** Parses one `at ...` line into `[async |new ][fn ](basename:line:col)`, or undefined. */
|
|
80
|
+
export function parseProviderErrorStackFrame(line) {
|
|
81
|
+
if (line.length > MAX_STACK_LINE_CHARS)
|
|
82
|
+
return undefined;
|
|
83
|
+
const frame = FRAME_LINE.exec(line);
|
|
84
|
+
if (!frame)
|
|
85
|
+
return undefined;
|
|
86
|
+
const rest = frame[1].trimEnd();
|
|
87
|
+
let functionPart;
|
|
88
|
+
let locationPart;
|
|
89
|
+
if (rest.endsWith(")")) {
|
|
90
|
+
const open = rest.lastIndexOf("(");
|
|
91
|
+
if (open < 0)
|
|
92
|
+
return undefined;
|
|
93
|
+
functionPart = rest.slice(0, open);
|
|
94
|
+
locationPart = rest.slice(open + 1, -1);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// A frame with no parenthesized location still carries its `async`/`new`
|
|
98
|
+
// modifier inline (`at async file:///app/index.mjs:12:3`, emitted by V8
|
|
99
|
+
// for an anonymous async frame such as a module's top-level await).
|
|
100
|
+
// Split it off here: `parseLocation` rejects anything containing
|
|
101
|
+
// whitespace, so leaving it attached dropped the whole frame.
|
|
102
|
+
const modified = FRAME_MODIFIER.exec(rest);
|
|
103
|
+
functionPart = modified ? modified[1] : "";
|
|
104
|
+
locationPart = modified ? modified[2].trim() : rest;
|
|
105
|
+
}
|
|
106
|
+
// Eval frames nest parentheses inside the function part; never pass them through.
|
|
107
|
+
if (/[()]/.test(functionPart))
|
|
108
|
+
return undefined;
|
|
109
|
+
const location = parseLocation(locationPart);
|
|
110
|
+
if (!location)
|
|
111
|
+
return undefined;
|
|
112
|
+
const fn = parseFunctionName(functionPart);
|
|
113
|
+
if (!fn)
|
|
114
|
+
return undefined;
|
|
115
|
+
const prefix = [fn.modifier, fn.name].filter((part) => part !== undefined).join(" ");
|
|
116
|
+
return prefix.length > 0 ? `${prefix} (${location})` : `(${location})`;
|
|
117
|
+
}
|
|
118
|
+
// V8 (Node >= 21) installs `stack` as a shared native accessor pair on every
|
|
119
|
+
// Error instance; JSC (Bun) installs a data property. Capture the engine's own
|
|
120
|
+
// accessor once so a provider-defined accessor (a different function object) is
|
|
121
|
+
// still rejected while the engine's is trusted. The engine accessor itself can
|
|
122
|
+
// call a process-global `Error.prepareStackTrace` hook, a process-wide trust
|
|
123
|
+
// boundary this module cannot narrow: a provider that installs one already
|
|
124
|
+
// reshapes `stack` for every consumer, and the whitelist grammar below still
|
|
125
|
+
// bounds what the resulting text can carry.
|
|
126
|
+
const NATIVE_STACK_GETTER = Object.getOwnPropertyDescriptor(new Error(), "stack")?.get;
|
|
127
|
+
function readOwnStackString(error) {
|
|
128
|
+
// Only engine-captured stacks: a thrown plain object is provider-authored text.
|
|
129
|
+
if (!(error instanceof Error))
|
|
130
|
+
return undefined;
|
|
131
|
+
try {
|
|
132
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, "stack");
|
|
133
|
+
if (descriptor === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
let stack;
|
|
136
|
+
if (Object.hasOwn(descriptor, "value")) {
|
|
137
|
+
stack = descriptor.value;
|
|
138
|
+
}
|
|
139
|
+
else if (typeof NATIVE_STACK_GETTER === "function" &&
|
|
140
|
+
descriptor.get === NATIVE_STACK_GETTER) {
|
|
141
|
+
stack = Reflect.apply(NATIVE_STACK_GETTER, error, []);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// A provider-defined accessor must never run inside the logger.
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return typeof stack === "string" ? stack : undefined;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Header shapes ahead of the frame block: `Name: message` (V8/JSC),
|
|
154
|
+
// `Name [CODE]: message` (node:assert), `Name` (empty message), or the bare
|
|
155
|
+
// message (Playwright rewrites `stack` as message-first). The message itself
|
|
156
|
+
// is matched verbatim, so anything before it must be a short name-like prefix.
|
|
157
|
+
const HEADER_NAME_PREFIX = /^(?:[\w$][\w$ .[\]-]{0,119}: )?$/;
|
|
158
|
+
const HEADER_NAME_ONLY = /^[\w$][\w$ .[\]-]{0,119}$/;
|
|
159
|
+
/**
|
|
160
|
+
* The frame block that follows the header, or undefined when the header does
|
|
161
|
+
* not embed the current `message` followed by a newline. Fail closed there: if
|
|
162
|
+
* `message` was mutated after the stack was formatted, the original message
|
|
163
|
+
* lines are still in the string and could be parsed as forged frames. (A
|
|
164
|
+
* mutation that truncates exactly at one of the message's own newlines is
|
|
165
|
+
* indistinguishable from the string alone; the whitelist grammar and the
|
|
166
|
+
* redactor still bound what such a line can carry.)
|
|
167
|
+
*/
|
|
168
|
+
function frameBlock(stack, error) {
|
|
169
|
+
let message;
|
|
170
|
+
try {
|
|
171
|
+
message = error.message;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
if (typeof message !== "string")
|
|
177
|
+
return undefined;
|
|
178
|
+
if (message.length === 0) {
|
|
179
|
+
const newline = stack.indexOf("\n");
|
|
180
|
+
if (newline < 0 || !HEADER_NAME_ONLY.test(stack.slice(0, newline)))
|
|
181
|
+
return undefined;
|
|
182
|
+
return stack.slice(newline + 1);
|
|
183
|
+
}
|
|
184
|
+
const at = stack.indexOf(`${message}\n`);
|
|
185
|
+
if (at < 0 || !HEADER_NAME_PREFIX.test(stack.slice(0, at)))
|
|
186
|
+
return undefined;
|
|
187
|
+
return stack.slice(at + message.length + 1);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Up to {@link MAX_PROVIDER_ERROR_STACK_FRAMES} whitelist-shaped frames from
|
|
191
|
+
* `error.stack`, or undefined when nothing parses. For an engine-formatted
|
|
192
|
+
* stack the header (which embeds the current `message`) is located and
|
|
193
|
+
* stripped first, so a provider-controlled *message* containing newlines
|
|
194
|
+
* cannot inject frame-shaped text (no header match, no frames). A provider
|
|
195
|
+
* that overwrites `stack` or `name` outright can still put grammar-shaped
|
|
196
|
+
* frames in the record: the field is a diagnostic hint, not an attested
|
|
197
|
+
* location, and the whitelist plus the redactor bound what it can carry.
|
|
198
|
+
* Each emitted frame still passes
|
|
199
|
+
* through the request redactor so a registered secret that happens to appear
|
|
200
|
+
* in a function or file name is masked (fail-closed to `[REDACTION_FAILED]`).
|
|
201
|
+
*/
|
|
202
|
+
export function providerErrorStackFrames(error, redact) {
|
|
203
|
+
const stack = readOwnStackString(error);
|
|
204
|
+
if (stack === undefined)
|
|
205
|
+
return undefined;
|
|
206
|
+
const body = frameBlock(stack, error);
|
|
207
|
+
if (body === undefined)
|
|
208
|
+
return undefined;
|
|
209
|
+
const frames = [];
|
|
210
|
+
const lines = body.slice(0, MAX_STACK_SCAN_CHARS).split("\n", MAX_STACK_SCAN_LINES);
|
|
211
|
+
for (const line of lines) {
|
|
212
|
+
if (frames.length >= MAX_PROVIDER_ERROR_STACK_FRAMES)
|
|
213
|
+
break;
|
|
214
|
+
const frame = parseProviderErrorStackFrame(line);
|
|
215
|
+
if (frame !== undefined)
|
|
216
|
+
frames.push(redactDiagnosticText(frame, redact));
|
|
217
|
+
}
|
|
218
|
+
return frames.length > 0 ? frames : undefined;
|
|
219
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
export type { ProviderLocaleCatalogMap } from "../i18n/catalog.js";
|
|
2
|
+
export type { ProviderLocale, ProviderLocaleCatalog } from "../i18n/keys.js";
|
|
1
3
|
export type { ProxyCacheStatus, ProxyProtocol, ProxyUserAgentSource, ProxyVendorName, SmartproxyAllocatorBodyClass, } from "../config/loader.js";
|
|
2
4
|
export type { ProxyTelemetryHeaderPayload, ProxyHash, ProxyTelemetryLogPayload, ProxyTelemetryResolvedPayload, ProxyTelemetryUnresolvedPayload, } from "../runtime/proxy-telemetry.js";
|
|
3
5
|
export { RequestTelemetry, closedEnum, type ClosedEnum, type GatewayIngestible, type RequestTelemetryLogPayload, type SpanIndex, type TelemetryContributor, type TelemetryKey, type TenantNeutral, } from "../runtime/request-telemetry.js";
|
|
6
|
+
export { OcrTelemetryCollector, bindOcrTelemetry, type OcrTelemetryBackend, type OcrTelemetryEngine, type OcrTelemetryErrorCode, type OcrTelemetryEvent, type OcrTelemetryModel, type OcrTelemetryFinishReason, type OcrTelemetryHeaderPayload, type OcrTelemetryLogPayload, type OcrTelemetrySink, } from "../runtime/ocr-telemetry.js";
|
|
4
7
|
export { ResolverTelemetryCollector, type ResolverAttemptSample, type ResolverCacheReadTelemetryEvent, type ResolverCacheWriteTelemetryEvent, type ResolverFailoverTelemetryEvent, type ResolverIdentityTelemetryEvent, type ResolverOutcomeTelemetryEvent, type ResolverTelemetryAttemptOutcome, type ResolverTelemetryCacheStatus, type ResolverTelemetryCacheWriteReason, type ResolverTelemetryErrorClass, type ResolverTelemetryHeaderPayload, type ResolverTelemetryIdentitySource, type ResolverTelemetryLogPayload, type ResolverTelemetryOutcome, type ResolverTelemetryPhase, type ResolverTelemetrySink, type ResolverVendorAttemptTelemetryEvent, } from "../runtime/resolver-telemetry.js";
|
|
8
|
+
export { StealthTelemetryCollector, type StealthTelemetryAttemptEvent, type StealthTelemetryAttemptKind, type StealthTelemetryAttemptSample, type StealthTelemetryDiagnostics, type StealthTelemetryErrorCode, type StealthTelemetryHeaderPayload, type StealthTelemetryLogPayload, type StealthTelemetryRequestClass, type StealthTelemetrySbsdEvent, type StealthTelemetrySbsdOutcome, type StealthTelemetrySink, } from "../runtime/stealth-telemetry.js";
|
|
9
|
+
export { SttTelemetryCollector, bindSttTelemetry, type SttTelemetryBackend, type SttTelemetryEngine, type SttTelemetryErrorCode, type SttTelemetryEvent, type SttTelemetryModel, type SttTelemetryHeaderPayload, type SttTelemetryLogPayload, type SttTelemetrySink, } from "../runtime/stt-telemetry.js";
|
|
10
|
+
export { BrowserTelemetryCollector, type BrowserTelemetryErrorCode, type BrowserTelemetryHeaderPayload, type BrowserTelemetryLogPayload, type BrowserTelemetryPoolAcquireOutcome, type BrowserTelemetrySink, type BrowserTelemetrySampleName, type BrowserTelemetryEngine, } from "../runtime/browser-telemetry.js";
|
|
5
11
|
export type { ResolverVendorUnavailableReason } from "../runtime/resolver-vendors/types.js";
|
|
6
12
|
export type { Span, TraceContext } from "../runtime/trace.js";
|
|
13
|
+
export type { StealthBrowser, StealthOS, StealthProfileDescriptor } from "../types.js";
|
|
7
14
|
export { createServerApp, createServerAppAsync, ERROR_OBSERVABILITY_HEADER, type ErrorObservabilityDetails, type ProviderServerCloseOptions, type ProviderServerHandle, type ProviderErrorCauseFrame, type ProviderServerLogEvent, type ProviderServerLogger, type ProviderServerOperationExecutor, type ProviderServerOperationExecutorInput, type ProviderServerOptions, type ProviderServerStatefulForwardEnvelope, type ServeOptions, serve, } from "./serve.js";
|
|
8
15
|
export type { ProviderErrorObservability } from "../errors.js";
|
|
9
16
|
export { computeSelfTestPlanDigest, createSelfTestApp, createSelfTestAuthFlowInvoke, createSelfTestInvoke, DEFAULT_SELF_TEST_REQUEST_BUDGET_MS, isSelfTestReadOnlyOperation, PROVIDER_RUNTIME_SELF_TEST_REQUEST_BUDGET_MS_ENV, resolveSelfTestPort, SELF_TEST_AUTH_FLOW_MULTI_TURN_SKIP_REASON, SELF_TEST_AUTH_FLOW_REJECTED_SKIP_REASON, SELF_TEST_HEALTHZ_PATH, SELF_TEST_PATH, SELF_TEST_SCHEMA_VERSION, type SelfTestAppOptions, type SelfTestAuthFlowInvoke, type SelfTestAuthFlowRoute, type SelfTestCaseResult, type SelfTestCaseStatus, type SelfTestOperationInvoke, type SelfTestRequest, SelfTestRequestSchema, type SelfTestResponse, } from "./self-test.js";
|
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { RequestTelemetry, closedEnum, } from "../runtime/request-telemetry.js";
|
|
2
|
+
export { OcrTelemetryCollector, bindOcrTelemetry, } from "../runtime/ocr-telemetry.js";
|
|
2
3
|
export { ResolverTelemetryCollector, } from "../runtime/resolver-telemetry.js";
|
|
4
|
+
export { StealthTelemetryCollector, } from "../runtime/stealth-telemetry.js";
|
|
5
|
+
export { SttTelemetryCollector, bindSttTelemetry, } from "../runtime/stt-telemetry.js";
|
|
6
|
+
export { BrowserTelemetryCollector, } from "../runtime/browser-telemetry.js";
|
|
3
7
|
export { createServerApp, createServerAppAsync, ERROR_OBSERVABILITY_HEADER, serve, } from "./serve.js";
|
|
4
8
|
export { computeSelfTestPlanDigest, createSelfTestApp, createSelfTestAuthFlowInvoke, createSelfTestInvoke, DEFAULT_SELF_TEST_REQUEST_BUDGET_MS, isSelfTestReadOnlyOperation, PROVIDER_RUNTIME_SELF_TEST_REQUEST_BUDGET_MS_ENV, resolveSelfTestPort, SELF_TEST_AUTH_FLOW_MULTI_TURN_SKIP_REASON, SELF_TEST_AUTH_FLOW_REJECTED_SKIP_REASON, SELF_TEST_HEALTHZ_PATH, SELF_TEST_PATH, SELF_TEST_SCHEMA_VERSION, SelfTestRequestSchema, } from "./self-test.js";
|
|
5
9
|
export { resolveHealthCheckInputDateTokens, } from "./self-test-input-tokens.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/** Published @apifuse/provider-sdk version, read from the package manifest; "unknown" when unreadable. */
|
|
3
|
+
export function resolveSdkVersion() {
|
|
4
|
+
try {
|
|
5
|
+
const packageJsonUrl = new URL("../../package.json", import.meta.url);
|
|
6
|
+
const parsed = JSON.parse(readFileSync(packageJsonUrl, "utf8"));
|
|
7
|
+
if (parsed &&
|
|
8
|
+
typeof parsed === "object" &&
|
|
9
|
+
"version" in parsed &&
|
|
10
|
+
typeof parsed.version === "string") {
|
|
11
|
+
return parsed.version;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// fall through to unknown
|
|
16
|
+
}
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
export const SDK_VERSION = resolveSdkVersion();
|
package/dist/server/self-test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
2
|
import { TURN_KINDS } from "../auth-turn/index.js";
|
|
3
|
+
import { SDK_VERSION } from "./sdk-version.js";
|
|
4
4
|
import { Hono } from "hono";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { resolveHealthCheckInputDateTokens } from "./self-test-input-tokens.js";
|
|
@@ -58,23 +58,6 @@ export const SELF_TEST_AUTH_FLOW_REJECTED_SKIP_REASON = "auth_flow_rejected";
|
|
|
58
58
|
*/
|
|
59
59
|
const AUTH_REJECTION_HTTP_STATUSES = new Set([401, 403]);
|
|
60
60
|
const INTERACTIVE_TURN_KIND_SET = new Set(TURN_KINDS.filter((descriptor) => descriptor.rendering !== "terminal" && descriptor.kind !== "retry").map((descriptor) => descriptor.kind));
|
|
61
|
-
function resolveSdkVersion() {
|
|
62
|
-
try {
|
|
63
|
-
const packageJsonUrl = new URL("../../package.json", import.meta.url);
|
|
64
|
-
const parsed = JSON.parse(readFileSync(packageJsonUrl, "utf8"));
|
|
65
|
-
if (parsed &&
|
|
66
|
-
typeof parsed === "object" &&
|
|
67
|
-
"version" in parsed &&
|
|
68
|
-
typeof parsed.version === "string") {
|
|
69
|
-
return parsed.version;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
// fall through to unknown
|
|
74
|
-
}
|
|
75
|
-
return "unknown";
|
|
76
|
-
}
|
|
77
|
-
const SDK_VERSION = resolveSdkVersion();
|
|
78
61
|
function healthCheckSuite(operation) {
|
|
79
62
|
return operation.healthCheck;
|
|
80
63
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ProviderDefinition } from "../types.js";
|
|
2
2
|
export declare const SELF_TEST_SENSITIVE_SOURCE_KINDS: readonly ["selfTestMasterSecrets", "providerSecrets", "healthProbeSecrets", "requestCredentials"];
|
|
3
3
|
/** Explicit source allowlist: no environment-name or payload-shape secret sweep. */
|
|
4
|
-
export declare const DIAGNOSTIC_SENSITIVE_SOURCE_KINDS: readonly ["selfTestMasterSecrets", "providerSecrets", "healthProbeSecrets", "requestCredentials", "engineProxyCredentials", "engineSolverKeys", "engineCeremonyLeaseCredentials", "ocrCredentials", "sttCredentials", "cdpCredentials", "statefulForwardingSecret", "redisCredentials", "otlpHeaders", "cacheKeyPepper", "sensitiveParams"];
|
|
4
|
+
export declare const DIAGNOSTIC_SENSITIVE_SOURCE_KINDS: readonly ["selfTestMasterSecrets", "providerSecrets", "healthProbeSecrets", "requestCredentials", "engineProxyCredentials", "engineSolverKeys", "engineCeremonyLeaseCredentials", "engineClientCredentials", "ocrCredentials", "sttCredentials", "cdpCredentials", "statefulForwardingSecret", "redisCredentials", "otlpHeaders", "cacheKeyPepper", "sensitiveParams"];
|
|
5
5
|
export type DiagnosticSensitiveSourceKind = (typeof DIAGNOSTIC_SENSITIVE_SOURCE_KINDS)[number];
|
|
6
6
|
/**
|
|
7
7
|
* Startup inventory; request-scoped readers additionally register live values on access.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolvedStringVariants, urlCredentialComponents, otlpHeaderCredentialValues, } from "../runtime/diagnostic-env-values.js";
|
|
2
2
|
import { PROVIDER_CACHE_REDIS_URL_ENV, PROVIDER_STATE_REDIS_URL_ENV, REDIS_URL_ENV, } from "../config/loader.js";
|
|
3
3
|
import { ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, } from "../engine.js";
|
|
4
|
+
import { REMOTE_ENGINE_CLIENT_API_KEY_ENV, REMOTE_ENGINE_CLIENT_URL_ENV, } from "../runtime/engine-mode.js";
|
|
4
5
|
import { APIFUSE__CACHE__KEY_PEPPER_ENV } from "../runtime/cache.js";
|
|
5
6
|
import { APIFUSE__ENGINE__CEREMONY_LEASE_KEY } from "../runtime/egress-lease.js";
|
|
6
7
|
import { APIFUSE__OCR__API_KEY_ENV, APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, } from "../runtime/ocr.js";
|
|
@@ -20,6 +21,7 @@ export const DIAGNOSTIC_SENSITIVE_SOURCE_KINDS = [
|
|
|
20
21
|
"engineProxyCredentials",
|
|
21
22
|
"engineSolverKeys",
|
|
22
23
|
"engineCeremonyLeaseCredentials",
|
|
24
|
+
"engineClientCredentials",
|
|
23
25
|
"ocrCredentials",
|
|
24
26
|
"sttCredentials",
|
|
25
27
|
"cdpCredentials",
|
|
@@ -66,6 +68,13 @@ export function collectDiagnosticSensitiveValues(provider, options = {}) {
|
|
|
66
68
|
// These are the resolver-config API keys after #251's engine credential projection.
|
|
67
69
|
engineSolverKeys: () => resolvedEnvValues(ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES),
|
|
68
70
|
engineCeremonyLeaseCredentials: () => resolvedEnvValues([APIFUSE__ENGINE__CEREMONY_LEASE_KEY]),
|
|
71
|
+
// Remote engine client credential (projected before the ADR-0011 flip). The
|
|
72
|
+
// endpoint itself is an internal service URL, so only credentials embedded
|
|
73
|
+
// in it are inventoried, not the whole URL.
|
|
74
|
+
engineClientCredentials: () => [
|
|
75
|
+
...resolvedEnvValues([REMOTE_ENGINE_CLIENT_API_KEY_ENV]),
|
|
76
|
+
...resolvedStringVariants(env[REMOTE_ENGINE_CLIENT_URL_ENV]).flatMap((url) => urlCredentialComponents(url, { includePathAndQuery: false })),
|
|
77
|
+
],
|
|
69
78
|
ocrCredentials: () => resolvedEnvValues([APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__OCR__API_KEY_ENV]),
|
|
70
79
|
sttCredentials: () => resolvedEnvValues([APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV]),
|
|
71
80
|
cdpCredentials: () => resolvedStringVariants(env[APIFUSE__CDP_POOL__URL]).flatMap((url) => [
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { type ProviderEngine } from "../engine.js";
|
|
3
|
+
import { type ProviderEngine, type ProviderEngineMode } from "../engine.js";
|
|
4
4
|
import { type ProviderErrorObservability } from "../errors.js";
|
|
5
|
+
import { type ProviderLocaleCatalogMap } from "../i18n/catalog.js";
|
|
5
6
|
import { type ProviderErrorCategory } from "../observability.js";
|
|
6
7
|
import type { HandleTelemetryEvent } from "../handle.js";
|
|
7
8
|
import { type HttpTelemetryLogPayload } from "../runtime/http-telemetry.js";
|
|
8
9
|
import { type ProxyTelemetryLogPayload } from "../runtime/proxy-telemetry.js";
|
|
9
10
|
import { type ResolverTelemetryLogPayload } from "../runtime/resolver-telemetry.js";
|
|
10
|
-
import type { OcrContext, ProviderContext, ProviderDefinition, ProviderFilesContext, ProviderRuntimeState, ResolverContext, SttContext } from "../types.js";
|
|
11
|
+
import type { OcrContext, ProviderContext, ProviderDefinition, ProviderFilesContext, ProviderRuntimeState, ProviderRuntimeTarget, ResolverContext, SttContext } from "../types.js";
|
|
11
12
|
import type { SelfTestCancellationLogEvent } from "./self-test.js";
|
|
12
13
|
import { type AuthFlowRequest, type OperationRequest } from "./types.js";
|
|
13
14
|
/** Compact SDK-owned error classification emitted separately from the public response body. */
|
|
@@ -36,6 +37,7 @@ export declare const ProviderServerStatefulForwardEnvelopeSchema: z.ZodObject<{
|
|
|
36
37
|
requestId: z.ZodString;
|
|
37
38
|
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
38
39
|
connectionId: z.ZodOptional<z.ZodString>;
|
|
40
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
39
41
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
40
42
|
trace: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
41
43
|
connection: z.ZodOptional<z.ZodObject<{
|
|
@@ -106,6 +108,7 @@ export type ProviderServerLogEvent = (ProviderServerLogEventBase & {
|
|
|
106
108
|
retryable?: boolean;
|
|
107
109
|
providerObservability?: ProviderErrorObservability;
|
|
108
110
|
causeChain?: ProviderErrorCauseFrame[];
|
|
111
|
+
stack?: string[];
|
|
109
112
|
signal?: "unregistered_provider_error_code";
|
|
110
113
|
signalFix?: string;
|
|
111
114
|
issues?: Array<{
|
|
@@ -118,6 +121,12 @@ export type ProviderServerLogEvent = (ProviderServerLogEventBase & {
|
|
|
118
121
|
event: "provider_secrets_missing";
|
|
119
122
|
providerId: string;
|
|
120
123
|
missingSecrets: string[];
|
|
124
|
+
} | {
|
|
125
|
+
/** Emitted once at boot when `locales/en.json` exists but cannot be read. */
|
|
126
|
+
level: "warn";
|
|
127
|
+
event: "provider_locale_catalogs_unavailable";
|
|
128
|
+
providerId: string;
|
|
129
|
+
reason: string;
|
|
121
130
|
} | ({
|
|
122
131
|
level: "info";
|
|
123
132
|
event: "provider_handle";
|
|
@@ -138,12 +147,43 @@ export type ProviderServerLogEvent = (ProviderServerLogEventBase & {
|
|
|
138
147
|
hookIndex: number;
|
|
139
148
|
errorClass: string;
|
|
140
149
|
message: string;
|
|
150
|
+
} | {
|
|
151
|
+
/** `warn` when the requested attachment could not be honoured, otherwise `info`. */
|
|
152
|
+
level: "info" | "warn";
|
|
153
|
+
event: "provider_engine_mode";
|
|
154
|
+
providerId: string;
|
|
155
|
+
/** Resolved attachment; `custom` for an opaque host engine. */
|
|
156
|
+
mode: ProviderEngineMode | "custom";
|
|
157
|
+
source: "engine" | "env" | "option" | "default";
|
|
158
|
+
/** True for every non-remote attachment, whose removal is scheduled by ADR-0011. */
|
|
159
|
+
deprecated: boolean;
|
|
160
|
+
/** False when the engine refuses to attach; `/readyz` reports 503. */
|
|
161
|
+
attached: boolean;
|
|
162
|
+
sdkVersion: string;
|
|
163
|
+
runtimeTarget?: ProviderRuntimeTarget;
|
|
164
|
+
/**
|
|
165
|
+
* Non-fatal selection findings, e.g. `invalid_env_value`,
|
|
166
|
+
* `env_overrode_option`, `engine_object_overrode_requested_mode`,
|
|
167
|
+
* `engine_env_ignored`. Absent when the selection was unambiguous.
|
|
168
|
+
*/
|
|
169
|
+
warnings?: readonly string[];
|
|
141
170
|
} | SelfTestCancellationLogEvent;
|
|
142
171
|
export type ProviderServerLogger = (event: ProviderServerLogEvent) => void;
|
|
143
172
|
export type ProviderServerOptions<TContext extends Partial<ProviderContext> = ProviderContext> = {
|
|
144
173
|
logger?: ProviderServerLogger;
|
|
145
174
|
/** Capability attachment boundary. Defaults to the local in-process engine. */
|
|
146
175
|
engine?: ProviderEngine;
|
|
176
|
+
/**
|
|
177
|
+
* Explicit engine attachment mode. Lowest precedence of the three inputs:
|
|
178
|
+
* an explicit `engine` object wins, then `APIFUSE__ENGINE__MODE` (the
|
|
179
|
+
* deployment outranks provider code), then this option, then the in-process
|
|
180
|
+
* default. Disagreement is never fatal — it is reported on the
|
|
181
|
+
* `provider_engine_mode` boot event (`env_overrode_option`,
|
|
182
|
+
* `engine_object_overrode_requested_mode`), which only `serve` emits. A value
|
|
183
|
+
* that is not a known mode throws `ValidationError`, because unlike the env it
|
|
184
|
+
* can only come from calling code.
|
|
185
|
+
*/
|
|
186
|
+
engineMode?: ProviderEngineMode;
|
|
147
187
|
/** Request-file resolver supplied by the engine host when `files` is declared. */
|
|
148
188
|
files?: ProviderFilesContext;
|
|
149
189
|
/** Optional provider-specific operation executor. Stateful providers use this to preserve provider-local runtime semantics. */
|
|
@@ -167,6 +207,15 @@ export type ProviderServerOptions<TContext extends Partial<ProviderContext> = Pr
|
|
|
167
207
|
* resolver is reported as one custom invocation; its internal vendor work is not exposed.
|
|
168
208
|
*/
|
|
169
209
|
resolver?: ResolverContext;
|
|
210
|
+
/**
|
|
211
|
+
* Pre-loaded provider locale catalogs used to localize auth turns and the
|
|
212
|
+
* client-facing `message`/`fix` of provider errors.
|
|
213
|
+
*
|
|
214
|
+
* Defaults to reading `locales/{en,ko,ja}.json` from the provider directory
|
|
215
|
+
* once at server construction. Supply this to bundle catalogs instead of
|
|
216
|
+
* probing the filesystem, or to pin catalogs in tests.
|
|
217
|
+
*/
|
|
218
|
+
localeCatalogs?: ProviderLocaleCatalogMap;
|
|
170
219
|
/** Optional runtime state override for tests or custom hosts. Production resolves Redis from env and fails closed when unavailable. */
|
|
171
220
|
state?: ProviderRuntimeState;
|
|
172
221
|
/** Allow process-local runtime state only for local development and tests. */
|