@vite-hub/runtime 0.1.0 → 0.3.1
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/README.md +151 -117
- package/dist/durability.d.ts +107 -0
- package/dist/durability.js +168 -0
- package/dist/error-diagnostics-BKICpwZp.js +85 -0
- package/dist/error-diagnostics-BsJr9VdW.d.ts +15 -0
- package/dist/{errors-CbqHQTvn.js → errors-BEomN3fX.js} +1 -1
- package/dist/{execution-budget-D8SwJE8_.d.ts → execution-budget-BPXbISEt.d.ts} +9 -6
- package/dist/index-Bcl-Hr-a.d.ts +678 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/internal/drain.d.ts +17 -0
- package/dist/internal/drain.js +75 -0
- package/dist/internal/execution-budget.d.ts +1 -1
- package/dist/internal/grant.js +2 -2
- package/dist/internal/h3.d.ts +42 -0
- package/dist/internal/h3.js +181 -0
- package/dist/{node.d.ts → internal/node.d.ts} +2 -2
- package/dist/{node.js → internal/node.js} +4 -4
- package/dist/internal/public-url.d.ts +2 -0
- package/dist/internal/public-url.js +2 -0
- package/dist/internal/run-scope.d.ts +11 -0
- package/dist/internal/run-scope.js +30 -0
- package/dist/internal/runtime-type.d.ts +9 -2
- package/dist/internal/runtime-type.js +3 -2
- package/dist/{shutdown.d.ts → internal/shutdown.d.ts} +1 -1
- package/dist/{shutdown.js → internal/shutdown.js} +1 -1
- package/dist/internal/test-mode-setup.d.ts +7 -0
- package/dist/internal/test-mode-setup.js +114 -0
- package/dist/internal/test-mode.d.ts +32 -0
- package/dist/internal/test-mode.js +9 -0
- package/dist/operations.d.ts +167 -0
- package/dist/operations.js +406 -0
- package/dist/public-url-1WeOw54Z.d.ts +34 -0
- package/dist/public-url-B6x0HMgY.js +140 -0
- package/dist/{src-jy-gyPPu.js → request-context-CP9NhgLL.js} +635 -551
- package/dist/runtime-type-BftydMAf.js +88 -0
- package/package.json +61 -26
- package/dist/drain.d.ts +0 -1
- package/dist/drain.js +0 -69
- package/dist/error-diagnostics-Bkym4e6y.d.ts +0 -12
- package/dist/h3.d.ts +0 -49
- package/dist/h3.js +0 -404
- package/dist/index-Rl4DbP8B.d.ts +0 -574
- package/dist/runtime-type-CgfU6SWl.js +0 -52
package/dist/index-Rl4DbP8B.d.ts
DELETED
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
import "./error-diagnostics-Bkym4e6y.js";
|
|
2
|
-
import { Diagnostic, DiagnosticDefinition, DiagnosticJSON, Diagnostics } from "nostics";
|
|
3
|
-
//#region src/preflight.d.ts
|
|
4
|
-
/** The small set of runtime facts that a preflight check can describe. */
|
|
5
|
-
type RuntimePreflightKind = "browser" | "command" | "file" | "mcp" | "tool" | (string & {});
|
|
6
|
-
type RuntimePreflightState = "available" | "missing" | "unknown";
|
|
7
|
-
type RuntimePreflightValue = string | number | boolean | null;
|
|
8
|
-
/** Safe, bounded details for a check. Do not put credentials or command output here. */
|
|
9
|
-
type RuntimePreflightDetails = Readonly<Record<string, RuntimePreflightValue>>;
|
|
10
|
-
interface RuntimePreflightCheckContext {
|
|
11
|
-
signal: AbortSignal;
|
|
12
|
-
}
|
|
13
|
-
interface RuntimePreflightCheckResult {
|
|
14
|
-
state: RuntimePreflightState;
|
|
15
|
-
details?: RuntimePreflightDetails;
|
|
16
|
-
reason?: string;
|
|
17
|
-
}
|
|
18
|
-
interface RuntimePreflightCheck {
|
|
19
|
-
/** Stable local identifier, for example `command:git` or `file:AGENTS.md`. */
|
|
20
|
-
id: string;
|
|
21
|
-
kind: RuntimePreflightKind;
|
|
22
|
-
/** Required only affects the diagnostic metadata. Missing optional checks never fail an invocation. */
|
|
23
|
-
required?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Return a result or a Promise. External process, filesystem, and network work
|
|
26
|
-
* must use non-blocking async APIs and honor `signal`; ViteHub cannot interrupt
|
|
27
|
-
* a synchronous callback, so an over-budget synchronous callback is marked
|
|
28
|
-
* unknown only after it returns.
|
|
29
|
-
*/
|
|
30
|
-
check: (context: RuntimePreflightCheckContext) => MaybePromise<RuntimePreflightCheckResult | RuntimePreflightState | boolean>;
|
|
31
|
-
}
|
|
32
|
-
type RuntimePreflightDiagnosticData = Record<string, unknown> & {
|
|
33
|
-
checkId: string;
|
|
34
|
-
kind: RuntimePreflightKind;
|
|
35
|
-
required: boolean;
|
|
36
|
-
state: RuntimePreflightState;
|
|
37
|
-
reason?: string;
|
|
38
|
-
};
|
|
39
|
-
interface RuntimePreflightIssue {
|
|
40
|
-
check: Pick<RuntimePreflightCheck, "id" | "kind" | "required">;
|
|
41
|
-
state: RuntimePreflightState;
|
|
42
|
-
diagnostic: Diagnostic<RuntimePreflightDiagnosticData>;
|
|
43
|
-
}
|
|
44
|
-
interface RuntimePreflightCheckSummary {
|
|
45
|
-
id: string;
|
|
46
|
-
kind: RuntimePreflightKind;
|
|
47
|
-
required: boolean;
|
|
48
|
-
state: RuntimePreflightState;
|
|
49
|
-
details?: RuntimePreflightDetails;
|
|
50
|
-
reason?: string;
|
|
51
|
-
diagnostic?: DiagnosticJSON<RuntimePreflightDiagnosticData>;
|
|
52
|
-
}
|
|
53
|
-
/** Compact, serializable result suitable for Agent inspection and telemetry. */
|
|
54
|
-
interface RuntimePreflightManifest {
|
|
55
|
-
version: 1;
|
|
56
|
-
checkedAt: string;
|
|
57
|
-
durationMs: number;
|
|
58
|
-
checks: readonly RuntimePreflightCheckSummary[];
|
|
59
|
-
capabilities: Readonly<Record<string, RuntimePreflightState>>;
|
|
60
|
-
diagnostics: readonly DiagnosticJSON<RuntimePreflightDiagnosticData>[];
|
|
61
|
-
}
|
|
62
|
-
interface RuntimePreflightOptions {
|
|
63
|
-
checks: readonly RuntimePreflightCheck[];
|
|
64
|
-
/** Maximum wait for one asynchronous check. Synchronous checks are measured after return. Defaults to 250ms. */
|
|
65
|
-
timeoutMs?: number;
|
|
66
|
-
/** Maximum checks run for one preflight. Defaults to 32. */
|
|
67
|
-
maxChecks?: number;
|
|
68
|
-
signal?: AbortSignal;
|
|
69
|
-
/** Best-effort callback. Its work never delays or fails the manifest. */
|
|
70
|
-
onDiagnostic?: (issue: RuntimePreflightIssue) => MaybePromise<void>;
|
|
71
|
-
}
|
|
72
|
-
interface RuntimePreflightHandle {
|
|
73
|
-
/** Resolves even when checks fail, time out, or the optional reporter fails. */
|
|
74
|
-
manifest: Promise<RuntimePreflightManifest>;
|
|
75
|
-
cancel: () => void;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Start bounded capability checks without making them part of the invocation's critical path.
|
|
79
|
-
* Checks run in parallel and settle to a manifest; failures are represented as diagnostics.
|
|
80
|
-
*/
|
|
81
|
-
declare function startRuntimePreflight(options: RuntimePreflightOptions): RuntimePreflightHandle;
|
|
82
|
-
declare function runRuntimePreflight(options: RuntimePreflightOptions): Promise<RuntimePreflightManifest>;
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/internal/trace-attributes.d.ts
|
|
85
|
-
declare function isTraceContentAttributeKey(key: string): boolean;
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/route-segment.d.ts
|
|
88
|
-
declare function encodeRouteSegment(value: string): string;
|
|
89
|
-
declare function decodeRouteSegment(segment: string): string | undefined;
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/public-url.d.ts
|
|
92
|
-
/** Public origins resolved from `vitehub({ publicUrl })` at build time. */
|
|
93
|
-
interface PublicUrlConfig {
|
|
94
|
-
/** One origin for the whole deployment. */
|
|
95
|
-
url?: string;
|
|
96
|
-
/** One origin per discovered Agent, from the function form. */
|
|
97
|
-
agents?: Record<string, string>;
|
|
98
|
-
}
|
|
99
|
-
/** Replace aliases when a generated Agent registry is installed. */
|
|
100
|
-
declare function resetPublicUrlAgentNames(): void;
|
|
101
|
-
/** Associate an evaluated Agent name with the identity used by build-time URL configuration. */
|
|
102
|
-
declare function registerPublicUrlAgentName(name: string, discoveredName: string): void;
|
|
103
|
-
/**
|
|
104
|
-
* Resolve the public origin of this deployment.
|
|
105
|
-
*
|
|
106
|
-
* Order: the Agent's origin from `vitehub({ publicUrl })`, the single configured
|
|
107
|
-
* origin, the configured origin with the same host as the request, the configured
|
|
108
|
-
* origin for an internal request host, and then the request origin.
|
|
109
|
-
*/
|
|
110
|
-
declare function resolvePublicUrl(options: {
|
|
111
|
-
agentName?: string;
|
|
112
|
-
request: Pick<Request, "url">;
|
|
113
|
-
}): string;
|
|
114
|
-
declare function resolvePublicUrl(options?: {
|
|
115
|
-
agentName?: string;
|
|
116
|
-
request?: Pick<Request, "url">;
|
|
117
|
-
}): string | undefined;
|
|
118
|
-
/** Build the Console URL of one Agent invocation. `origin` must not include the application base path. */
|
|
119
|
-
declare function consoleInvocationUrl(origin: string, agentName: string, invocationId: string): string;
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/result.d.ts
|
|
122
|
-
/**
|
|
123
|
-
* Error of a ViteHub operation. It is a Nostics diagnostic with a typed `code`.
|
|
124
|
-
*
|
|
125
|
-
* - `code` names the failure, for example `KV_INVALID_CURSOR`.
|
|
126
|
-
* - `why` tells what went wrong. `message` has the same text.
|
|
127
|
-
* - `fix` tells what to do next.
|
|
128
|
-
* - `docs` links to the code on vitehub.dev.
|
|
129
|
-
* - `cause` keeps the lower-level error, for example the provider error.
|
|
130
|
-
* - `data` keeps catalog metadata in memory. Its type is inferred by `defineErrors()`.
|
|
131
|
-
*/
|
|
132
|
-
interface ResultError<TCode extends string = string, TData = unknown> extends Diagnostic<TData> {
|
|
133
|
-
readonly code: TCode;
|
|
134
|
-
readonly name: TCode;
|
|
135
|
-
/** Retains the Nostics serializer type for compatibility; runtime JSON is redacted. */
|
|
136
|
-
toJSON(): DiagnosticJSON<TData> & {
|
|
137
|
-
code: TCode;
|
|
138
|
-
name: TCode;
|
|
139
|
-
why: string;
|
|
140
|
-
fix: string | undefined;
|
|
141
|
-
docs: string | undefined;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* `[error, data]` tuple that each ViteHub runtime operation returns.
|
|
146
|
-
* Check `error` first. When `error` is `undefined`, `data` has the value.
|
|
147
|
-
*/
|
|
148
|
-
type Result<TData, TCode extends string = string> = [error: ResultError<TCode>, data: undefined] | [error: undefined, data: TData];
|
|
149
|
-
/** Error catalog of one package. Each code creates a `ResultError` with that code. */
|
|
150
|
-
type ErrorCatalog<TCodes extends Record<string, DiagnosticDefinition>> = { [TCode in keyof TCodes & string]: (...args: Parameters<Diagnostics<TCodes, []>[TCode]>) => ResultError<TCode, ReturnType<Diagnostics<TCodes, []>[TCode]>["data"]>; };
|
|
151
|
-
interface DefineErrorsOptions<TCodes extends Record<string, DiagnosticDefinition>> {
|
|
152
|
-
/** Each code with a `why` and a `fix`. */
|
|
153
|
-
codes: TCodes;
|
|
154
|
-
/** Docs page that has one heading for each code. The `docs` URL of an error is `<page>#<code in lowercase>`. */
|
|
155
|
-
docs: string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Prepares a recognized diagnostic for a result, keeping its metadata in memory.
|
|
159
|
-
* Reuses mutable diagnostics; copies diagnostics whose name or serializer cannot be replaced.
|
|
160
|
-
* Sets name to code to match the result contract, including diagnostics renamed by their owner.
|
|
161
|
-
* The caller owns code allowlisting and the public text. JSON includes only the public fields.
|
|
162
|
-
*/
|
|
163
|
-
declare function toResultError<TCode extends string, TData>(error: (Diagnostic<TData> | ResultError<string, TData>) & {
|
|
164
|
-
readonly code: TCode;
|
|
165
|
-
}): ResultError<TCode, TData>;
|
|
166
|
-
/**
|
|
167
|
-
* Defines the error catalog of a package with Nostics.
|
|
168
|
-
* Return runtime errors as `[error, undefined]`. Throw definition and config errors.
|
|
169
|
-
*/
|
|
170
|
-
declare function defineErrors<const TCodes extends Record<string, DiagnosticDefinition>>(options: DefineErrorsOptions<TCodes>): ErrorCatalog<TCodes>;
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/diagnostics.d.ts
|
|
173
|
-
type RuntimeDiagnosticLevel = "debug" | "error" | "info" | "warn";
|
|
174
|
-
type RuntimeResourceScope = "container" | "host" | "process" | "service" | "workload";
|
|
175
|
-
type RuntimeResourceUnit = "bytes" | "count" | "microseconds" | "ratio";
|
|
176
|
-
interface RuntimeDiagnosticError {
|
|
177
|
-
cause?: RuntimeDiagnosticError;
|
|
178
|
-
code?: number | string;
|
|
179
|
-
details?: Readonly<Record<string, unknown>>;
|
|
180
|
-
docs?: string;
|
|
181
|
-
errors?: readonly RuntimeDiagnosticError[];
|
|
182
|
-
fix?: string;
|
|
183
|
-
message: string;
|
|
184
|
-
name?: string;
|
|
185
|
-
requestId?: string;
|
|
186
|
-
sources?: readonly string[];
|
|
187
|
-
stack?: string;
|
|
188
|
-
status?: number | string;
|
|
189
|
-
statusCode?: number | string;
|
|
190
|
-
}
|
|
191
|
-
interface RuntimeDiagnosticEvent {
|
|
192
|
-
attributes?: Readonly<Record<string, unknown>>;
|
|
193
|
-
component: string;
|
|
194
|
-
error?: RuntimeDiagnosticError;
|
|
195
|
-
level: RuntimeDiagnosticLevel;
|
|
196
|
-
name: string;
|
|
197
|
-
timestamp: string;
|
|
198
|
-
}
|
|
199
|
-
type RuntimeDiagnosticReporter = (event: RuntimeDiagnosticEvent) => MaybePromise<void>;
|
|
200
|
-
interface RuntimeResourceObservation {
|
|
201
|
-
name: string;
|
|
202
|
-
scope: RuntimeResourceScope;
|
|
203
|
-
source: string;
|
|
204
|
-
unit: RuntimeResourceUnit;
|
|
205
|
-
value: number;
|
|
206
|
-
}
|
|
207
|
-
interface RuntimeResourceSupport {
|
|
208
|
-
reason?: "collection-failed" | "not-isolated" | "permission-denied" | "unsupported-runtime" | (string & {});
|
|
209
|
-
scope: RuntimeResourceScope;
|
|
210
|
-
source: string;
|
|
211
|
-
supported: boolean;
|
|
212
|
-
}
|
|
213
|
-
interface RuntimeResourceSnapshot {
|
|
214
|
-
observedAt: string;
|
|
215
|
-
observations: readonly RuntimeResourceObservation[];
|
|
216
|
-
support?: readonly RuntimeResourceSupport[];
|
|
217
|
-
}
|
|
218
|
-
interface RuntimeResourceInspector {
|
|
219
|
-
inspect(options?: {
|
|
220
|
-
signal?: AbortSignal;
|
|
221
|
-
}): MaybePromise<RuntimeResourceSnapshot>;
|
|
222
|
-
}
|
|
223
|
-
interface RuntimeDiagnosticErrorOptions {
|
|
224
|
-
includeStack?: boolean;
|
|
225
|
-
maxDepth?: number;
|
|
226
|
-
maxErrors?: number;
|
|
227
|
-
maxStringLength?: number;
|
|
228
|
-
}
|
|
229
|
-
/** Recognizes a live Nostics error across bundled copies. This does not make its fields safe for public responses. */
|
|
230
|
-
declare function isRuntimeDiagnostic(error: unknown): error is Diagnostic<unknown> | ResultError;
|
|
231
|
-
/** Formats bounded developer diagnostics without exposing causes or stacks. */
|
|
232
|
-
declare function formatRuntimeDiagnosticError(error: unknown): string;
|
|
233
|
-
declare function normalizeRuntimeDiagnosticError(error: unknown, options?: RuntimeDiagnosticErrorOptions): RuntimeDiagnosticError;
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/errors.d.ts
|
|
236
|
-
type ViteHubErrorDetail = boolean | null | number | string | readonly ViteHubErrorDetail[] | {
|
|
237
|
-
readonly [key: string]: ViteHubErrorDetail | undefined;
|
|
238
|
-
};
|
|
239
|
-
type ViteHubErrorDetails = Readonly<Record<string, ViteHubErrorDetail | undefined>>;
|
|
240
|
-
interface ViteHubErrorShape<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> {
|
|
241
|
-
code: TCode;
|
|
242
|
-
details?: TDetails;
|
|
243
|
-
message: string;
|
|
244
|
-
name: "ViteHubError";
|
|
245
|
-
requestId?: string;
|
|
246
|
-
}
|
|
247
|
-
interface ViteHubErrorOptions<TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends ErrorOptions {
|
|
248
|
-
details?: TDetails;
|
|
249
|
-
requestId?: string;
|
|
250
|
-
}
|
|
251
|
-
declare class ViteHubError<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends Error {
|
|
252
|
-
readonly code: TCode;
|
|
253
|
-
readonly details?: TDetails;
|
|
254
|
-
readonly requestId?: string;
|
|
255
|
-
constructor(code: TCode, message: string, options?: ViteHubErrorOptions<TDetails>);
|
|
256
|
-
toJSON(): ViteHubErrorShape<TCode, TDetails>;
|
|
257
|
-
}
|
|
258
|
-
declare function getViteHubErrorShape(value: unknown): ViteHubErrorShape | undefined;
|
|
259
|
-
declare function isViteHubError(value: unknown): value is ViteHubErrorShape;
|
|
260
|
-
//#endregion
|
|
261
|
-
//#region src/work.d.ts
|
|
262
|
-
/** Durable completion state for one observed version of a work item. */
|
|
263
|
-
interface WorkCheckpoint {
|
|
264
|
-
version: 1;
|
|
265
|
-
fingerprint: string;
|
|
266
|
-
disposition: "park" | "retry";
|
|
267
|
-
attempt: number;
|
|
268
|
-
retryAt?: number;
|
|
269
|
-
}
|
|
270
|
-
interface WorkCheckpointStore {
|
|
271
|
-
get(key: string): Promise<unknown>;
|
|
272
|
-
set(key: string, value: WorkCheckpoint): Promise<void>;
|
|
273
|
-
}
|
|
274
|
-
interface WorkOutcome {
|
|
275
|
-
disposition: "park" | "retry";
|
|
276
|
-
/** Use the newly observed version when the run changed the work item. */
|
|
277
|
-
fingerprint?: string;
|
|
278
|
-
}
|
|
279
|
-
/** Single-process ownership with durable park/retry state. Shared hosts need an external lease. */
|
|
280
|
-
interface WorkTracker {
|
|
281
|
-
readonly active: number;
|
|
282
|
-
has(key: string): boolean;
|
|
283
|
-
eligible(key: string, fingerprint: string): Promise<boolean>;
|
|
284
|
-
run(key: string, fingerprint: string, run: () => Promise<WorkOutcome>): Promise<boolean>;
|
|
285
|
-
}
|
|
286
|
-
declare function createWorkTracker(options: {
|
|
287
|
-
store: WorkCheckpointStore;
|
|
288
|
-
retryMs?: number;
|
|
289
|
-
maxRetryMs?: number;
|
|
290
|
-
now?: () => number;
|
|
291
|
-
}): WorkTracker;
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/response.d.ts
|
|
294
|
-
/** A JSON-safe representation of a web Response for durable boundaries. */
|
|
295
|
-
interface SerializedResponse {
|
|
296
|
-
readonly body: {
|
|
297
|
-
readonly data: string;
|
|
298
|
-
readonly encoding: "base64";
|
|
299
|
-
readonly mediaType: string;
|
|
300
|
-
readonly isNull?: boolean;
|
|
301
|
-
};
|
|
302
|
-
/** Header entries are kept as pairs so repeated headers are preserved. */
|
|
303
|
-
readonly headers: readonly (readonly [string, string])[];
|
|
304
|
-
readonly status: number;
|
|
305
|
-
readonly statusText: string;
|
|
306
|
-
readonly url?: string;
|
|
307
|
-
readonly type?: "error" | "opaque" | "opaqueredirect";
|
|
308
|
-
}
|
|
309
|
-
/** Normalize a primitive value into the native Web Response contract. */
|
|
310
|
-
declare function toResponse(value: unknown): Response;
|
|
311
|
-
/** Convert a native Response into a JSON-safe record. The body is fully buffered. */
|
|
312
|
-
declare function serializeResponse(response: Response): Promise<SerializedResponse>;
|
|
313
|
-
/** Reconstruct a native Response from a durable response record. */
|
|
314
|
-
declare function deserializeResponse(value: SerializedResponse): Response;
|
|
315
|
-
declare function isSerializedResponse(value: unknown): value is SerializedResponse;
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region src/index.d.ts
|
|
318
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
319
|
-
interface AccessAuthorizationContext {
|
|
320
|
-
request: Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
321
|
-
session: Record<string, unknown>;
|
|
322
|
-
user: Record<string, unknown> & {
|
|
323
|
-
id: string;
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
type AccessAuthorizeResult = boolean | Response;
|
|
327
|
-
/** Decides whether a signed-in user can access one request. Return `false` for `403` or a custom `Response`. */
|
|
328
|
-
type AccessAuthorize = (context: AccessAuthorizationContext) => MaybePromise<AccessAuthorizeResult>;
|
|
329
|
-
/** `true` requires a signed-in session. A callback also decides each request after sign-in. */
|
|
330
|
-
type AccessAuthorizeOption = true | AccessAuthorize;
|
|
331
|
-
interface ExecutionAuthority {
|
|
332
|
-
readonly credentials: "ambient" | "none" | "provisioned" | "unknown";
|
|
333
|
-
readonly environment: "ambient" | "none" | "selected" | "unknown";
|
|
334
|
-
readonly filesystem: {
|
|
335
|
-
readonly access: "none" | "read-only" | "read-write" | "unknown";
|
|
336
|
-
readonly scope: "host" | "none" | "sandbox" | "unknown" | "workspace";
|
|
337
|
-
};
|
|
338
|
-
readonly isolation: "container" | "microvm" | "none" | "process" | "unknown";
|
|
339
|
-
readonly network: "none" | "restricted" | "unrestricted" | "unknown";
|
|
340
|
-
readonly processes: "arbitrary" | "none" | "restricted" | "unknown";
|
|
341
|
-
}
|
|
342
|
-
declare const noExecutionAuthority: ExecutionAuthority;
|
|
343
|
-
declare const unknownExecutionAuthority: ExecutionAuthority;
|
|
344
|
-
declare function isExecutionAuthority(value: unknown): value is ExecutionAuthority;
|
|
345
|
-
declare function normalizeExecutionAuthority(value: unknown): ExecutionAuthority;
|
|
346
|
-
type RuntimeWaitUntil = (task: Promise<unknown>) => void;
|
|
347
|
-
interface RuntimeWaitUntilController {
|
|
348
|
-
/**
|
|
349
|
-
* Drain registered work, including tasks added during the flush.
|
|
350
|
-
* Call from the operation owner. A registered task must not await its own
|
|
351
|
-
* controller's flush, because the flush waits for that task to finish.
|
|
352
|
-
*/
|
|
353
|
-
flushWaitUntil(): Promise<void>;
|
|
354
|
-
waitUntil: RuntimeWaitUntil;
|
|
355
|
-
}
|
|
356
|
-
interface TraceContext {
|
|
357
|
-
id: string;
|
|
358
|
-
parentId?: string;
|
|
359
|
-
sampled?: boolean;
|
|
360
|
-
}
|
|
361
|
-
type TraceActivityOwner = "agent" | "vitehub";
|
|
362
|
-
type TraceActivityPhase = "delivery" | "execution" | "setup" | "teardown";
|
|
363
|
-
interface TraceActivityContext {
|
|
364
|
-
owner: TraceActivityOwner;
|
|
365
|
-
phase: TraceActivityPhase;
|
|
366
|
-
}
|
|
367
|
-
type TracePayloadVisibility = "private" | "public" | "redacted" | "summary";
|
|
368
|
-
type TraceEventPayload = {
|
|
369
|
-
value: unknown;
|
|
370
|
-
visibility: "public";
|
|
371
|
-
} | {
|
|
372
|
-
summary: string;
|
|
373
|
-
visibility: "summary";
|
|
374
|
-
} | {
|
|
375
|
-
visibility: "redacted";
|
|
376
|
-
} | {
|
|
377
|
-
visibility: "private";
|
|
378
|
-
};
|
|
379
|
-
type TraceEventContentPolicy = "content" | "metadata";
|
|
380
|
-
type TraceRunStatus = "cancelled" | "completed" | "failed" | "running";
|
|
381
|
-
type TraceStepStatus = "completed" | "failed" | "running";
|
|
382
|
-
interface TraceEvent {
|
|
383
|
-
activity?: TraceActivityContext;
|
|
384
|
-
attributes?: Record<string, unknown>;
|
|
385
|
-
name: string;
|
|
386
|
-
payload?: TraceEventPayload;
|
|
387
|
-
timestamp?: Date | string;
|
|
388
|
-
trace?: TraceContext;
|
|
389
|
-
type: "approval" | "capability" | "error" | "lifecycle" | "policy" | "run";
|
|
390
|
-
}
|
|
391
|
-
interface TraceEventLogEntry extends TraceEvent {
|
|
392
|
-
sequence: number;
|
|
393
|
-
timestamp: string;
|
|
394
|
-
}
|
|
395
|
-
interface TraceEventLog {
|
|
396
|
-
append(event: TraceEvent): MaybePromise<TraceEventLogEntry>;
|
|
397
|
-
entries(): readonly TraceEventLogEntry[];
|
|
398
|
-
}
|
|
399
|
-
interface TraceEventLogOptions {
|
|
400
|
-
content?: TraceEventContentPolicy;
|
|
401
|
-
onEntry?: (entry: TraceEventLogEntry) => MaybePromise<void>;
|
|
402
|
-
}
|
|
403
|
-
interface TraceStepView {
|
|
404
|
-
attributes?: Record<string, unknown>;
|
|
405
|
-
durationMs?: number;
|
|
406
|
-
endTime?: string;
|
|
407
|
-
events: TraceEventLogEntry[];
|
|
408
|
-
id: string;
|
|
409
|
-
name: string;
|
|
410
|
-
startTime: string;
|
|
411
|
-
status: TraceStepStatus;
|
|
412
|
-
type: TraceEvent["type"];
|
|
413
|
-
}
|
|
414
|
-
interface TraceRunView {
|
|
415
|
-
durationMs?: number;
|
|
416
|
-
endTime?: string;
|
|
417
|
-
events: TraceEventLogEntry[];
|
|
418
|
-
id: string;
|
|
419
|
-
startTime: string;
|
|
420
|
-
status: TraceRunStatus;
|
|
421
|
-
steps: TraceStepView[];
|
|
422
|
-
}
|
|
423
|
-
interface OpenTelemetrySpanView {
|
|
424
|
-
attributes?: Record<string, unknown>;
|
|
425
|
-
endTime?: string;
|
|
426
|
-
events?: OpenTelemetrySpanEventView[];
|
|
427
|
-
name: string;
|
|
428
|
-
parentSpanId?: string;
|
|
429
|
-
spanId: string;
|
|
430
|
-
startTime: string;
|
|
431
|
-
status: {
|
|
432
|
-
code: "ERROR" | "OK" | "UNSET";
|
|
433
|
-
message?: string;
|
|
434
|
-
};
|
|
435
|
-
traceId: string;
|
|
436
|
-
}
|
|
437
|
-
interface OpenTelemetrySpanEventView {
|
|
438
|
-
attributes?: Record<string, unknown>;
|
|
439
|
-
name: string;
|
|
440
|
-
time: string;
|
|
441
|
-
}
|
|
442
|
-
interface OpenTelemetryLogRecordView {
|
|
443
|
-
attributes?: Record<string, unknown>;
|
|
444
|
-
eventName: string;
|
|
445
|
-
severityNumber?: number;
|
|
446
|
-
severityText?: string;
|
|
447
|
-
spanId: string;
|
|
448
|
-
time: string;
|
|
449
|
-
traceId: string;
|
|
450
|
-
}
|
|
451
|
-
interface OpenTelemetrySpanViewOptions {
|
|
452
|
-
content?: TraceEventContentPolicy;
|
|
453
|
-
}
|
|
454
|
-
interface RuntimeHostContext<TRuntimeConfig = Record<string, unknown>> {
|
|
455
|
-
capabilities?: RuntimeCapabilities;
|
|
456
|
-
cloudflare?: {
|
|
457
|
-
context?: unknown;
|
|
458
|
-
durableObjectStateName?: string;
|
|
459
|
-
env?: Record<string, unknown>;
|
|
460
|
-
};
|
|
461
|
-
event?: unknown;
|
|
462
|
-
memo<T>(key: string, create: () => T): T;
|
|
463
|
-
platform?: string;
|
|
464
|
-
request?: Request;
|
|
465
|
-
runtime: string;
|
|
466
|
-
runtimeConfig?: TRuntimeConfig;
|
|
467
|
-
trace?: TraceContext;
|
|
468
|
-
traceLog?: TraceEventLog;
|
|
469
|
-
vercel?: {
|
|
470
|
-
waitUntil?: RuntimeWaitUntil;
|
|
471
|
-
};
|
|
472
|
-
/** Drain from the operation owner, never from work registered with this context. */
|
|
473
|
-
flushWaitUntil?: () => Promise<void>;
|
|
474
|
-
waitUntil: RuntimeWaitUntil;
|
|
475
|
-
}
|
|
476
|
-
type ExecutionContext<TRuntimeConfig = Record<string, unknown>> = RuntimeHostContext<TRuntimeConfig> & {
|
|
477
|
-
capabilities: RuntimeCapabilities;
|
|
478
|
-
runtimeConfig: TRuntimeConfig;
|
|
479
|
-
};
|
|
480
|
-
interface CapabilityHandle<TKind extends string = string, TValue = unknown> {
|
|
481
|
-
kind: TKind;
|
|
482
|
-
name?: string;
|
|
483
|
-
value: TValue;
|
|
484
|
-
}
|
|
485
|
-
type RuntimeCapabilityHandle<TKind extends string = string, TValue = unknown> = CapabilityHandle<TKind, TValue>;
|
|
486
|
-
type RuntimeCapabilities = Record<string, CapabilityHandle | unknown>;
|
|
487
|
-
interface CapabilityDefinition<TKind extends string = string, TValue = unknown> {
|
|
488
|
-
handle: CapabilityHandle<TKind, TValue>;
|
|
489
|
-
resolve(context: ExecutionContext): MaybePromise<CapabilityHandle<TKind, TValue>>;
|
|
490
|
-
}
|
|
491
|
-
interface Resolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
|
|
492
|
-
resolve(context: TContext): MaybePromise<T>;
|
|
493
|
-
}
|
|
494
|
-
type MaybeResolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> = T | Resolvable<T, TContext> | ((context: TContext) => MaybePromise<T>);
|
|
495
|
-
interface PolicyContext {
|
|
496
|
-
capability?: string;
|
|
497
|
-
input?: unknown;
|
|
498
|
-
operation?: string;
|
|
499
|
-
runtime?: string;
|
|
500
|
-
subject?: unknown;
|
|
501
|
-
trace?: TraceContext;
|
|
502
|
-
}
|
|
503
|
-
type PolicyDecision = "allow" | "deny" | "require-approval" | "retryable-failure";
|
|
504
|
-
type CapabilityPolicy = PolicyDecision | ((context: PolicyContext) => MaybePromise<PolicyDecision>);
|
|
505
|
-
type ApprovalState = "proposed" | "awaiting-approval" | "approved" | "denied" | "executing" | "completed" | "failed";
|
|
506
|
-
interface ApprovalRequest<TInput = unknown> {
|
|
507
|
-
id: string;
|
|
508
|
-
capability?: string;
|
|
509
|
-
input?: TInput;
|
|
510
|
-
reason?: string;
|
|
511
|
-
state: Extract<ApprovalState, "awaiting-approval" | "proposed">;
|
|
512
|
-
trace?: TraceContext;
|
|
513
|
-
}
|
|
514
|
-
interface ApprovalDecision {
|
|
515
|
-
approved: boolean;
|
|
516
|
-
decidedAt?: Date | string;
|
|
517
|
-
reason?: string;
|
|
518
|
-
requestId: string;
|
|
519
|
-
state: Extract<ApprovalState, "approved" | "denied">;
|
|
520
|
-
}
|
|
521
|
-
interface RunLifecycleHooks<TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
|
|
522
|
-
approval?: (request: ApprovalRequest, context: TContext) => MaybePromise<void>;
|
|
523
|
-
error?: (error: unknown, context: TContext) => MaybePromise<void>;
|
|
524
|
-
finish?: (context: TContext) => MaybePromise<void>;
|
|
525
|
-
request?: (context: TContext) => MaybePromise<void>;
|
|
526
|
-
trace?: (event: TraceEvent, context: TContext) => MaybePromise<void>;
|
|
527
|
-
}
|
|
528
|
-
declare function emitTraceEvent<TContext extends RuntimeHostContext<any>>(context: TContext, event: TraceEvent): Promise<TraceEventLogEntry | undefined>;
|
|
529
|
-
declare function createTraceEventLog(options?: TraceEventLogOptions): TraceEventLog;
|
|
530
|
-
declare function deriveTraceRuns(events: Iterable<TraceEventLogEntry>): TraceRunView[];
|
|
531
|
-
declare function traceEventsToOpenTelemetryLogRecords(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetryLogRecordView[];
|
|
532
|
-
declare function traceEventsToOpenTelemetrySpans(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetrySpanView[];
|
|
533
|
-
interface Lease {
|
|
534
|
-
expiresAt?: Date | string;
|
|
535
|
-
id: string;
|
|
536
|
-
key: string;
|
|
537
|
-
release(): MaybePromise<void>;
|
|
538
|
-
}
|
|
539
|
-
interface LeaseStore {
|
|
540
|
-
acquire(key: string, options?: {
|
|
541
|
-
owner?: string;
|
|
542
|
-
ttl?: number;
|
|
543
|
-
}): MaybePromise<Lease>;
|
|
544
|
-
}
|
|
545
|
-
type NormalizedRuntimeConfig<TConfig> = Exclude<TConfig, null | undefined> extends Record<string, unknown> ? Record<string, unknown> : Exclude<TConfig, null | undefined> | Record<string, unknown>;
|
|
546
|
-
type RuntimeConfigOf<TContext extends RuntimeHostContext<any>> = "runtimeConfig" extends keyof TContext ? undefined extends TContext["runtimeConfig"] ? NormalizedRuntimeConfig<TContext["runtimeConfig"]> : null extends TContext["runtimeConfig"] ? NormalizedRuntimeConfig<TContext["runtimeConfig"]> : TContext["runtimeConfig"] : Record<string, unknown>;
|
|
547
|
-
type RuntimeCapabilitiesOf<TContext extends RuntimeHostContext<any>> = "capabilities" extends keyof TContext ? undefined extends TContext["capabilities"] ? RuntimeCapabilities : TContext["capabilities"] : RuntimeCapabilities;
|
|
548
|
-
type CreatedExecutionContext<TContext extends RuntimeHostContext<any>> = TContext extends unknown ? Omit<TContext, "capabilities" | "runtimeConfig"> & {
|
|
549
|
-
capabilities: RuntimeCapabilitiesOf<TContext>;
|
|
550
|
-
runtimeConfig: RuntimeConfigOf<TContext>;
|
|
551
|
-
} : never;
|
|
552
|
-
declare function createExecutionContext<TContext extends RuntimeHostContext<any>>(context: TContext): CreatedExecutionContext<TContext>;
|
|
553
|
-
type RuntimeContextInput = Omit<RuntimeHostContext<unknown>, "flushWaitUntil" | "memo" | "waitUntil"> & {
|
|
554
|
-
memo?: RuntimeHostContext["memo"];
|
|
555
|
-
waitUntil?: RuntimeWaitUntil;
|
|
556
|
-
};
|
|
557
|
-
type CreatedRuntimeContext<TContext extends RuntimeContextInput> = CreatedExecutionContext<TContext & RuntimeWaitUntilController & {
|
|
558
|
-
memo: RuntimeHostContext["memo"];
|
|
559
|
-
}>;
|
|
560
|
-
/** Create one operation's context. Without a host waitUntil, drain work before returning. */
|
|
561
|
-
declare function createRuntimeContext<const TContext extends RuntimeContextInput>(input: TContext): CreatedRuntimeContext<TContext>;
|
|
562
|
-
declare function defineCapability<TKind extends string, TValue>(kind: TKind, value: TValue, options?: {
|
|
563
|
-
name?: string;
|
|
564
|
-
}): CapabilityHandle<TKind, TValue>;
|
|
565
|
-
declare function createRuntimeWaitUntilController(options?: {
|
|
566
|
-
forward?: RuntimeWaitUntil;
|
|
567
|
-
}): RuntimeWaitUntilController;
|
|
568
|
-
declare function hasCapability(context: RuntimeHostContext, name: string): boolean;
|
|
569
|
-
declare function getCapability(context: RuntimeHostContext<any>, name: string): CapabilityHandle;
|
|
570
|
-
declare function isResolvable<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>): value is Resolvable<T, TContext>;
|
|
571
|
-
declare function resolveRuntimeValue<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>, context: TContext): Promise<T>;
|
|
572
|
-
declare function resolveCapabilityPolicy(policy: CapabilityPolicy | undefined, context: PolicyContext): Promise<PolicyDecision>;
|
|
573
|
-
//#endregion
|
|
574
|
-
export { emitTraceEvent as $, decodeRouteSegment as $t, RuntimeWaitUntil as A, RuntimeDiagnosticEvent as At, TraceEventLogOptions as B, isRuntimeDiagnostic as Bt, PolicyDecision as C, ViteHubErrorDetails as Ct, RuntimeCapabilityHandle as D, isViteHubError as Dt, RuntimeCapabilities as E, getViteHubErrorShape as Et, TraceContext as F, RuntimeResourceScope as Ft, TraceStepStatus as G, ResultError as Gt, TracePayloadVisibility as H, DefineErrorsOptions as Ht, TraceEvent as I, RuntimeResourceSnapshot as It, createRuntimeContext as J, PublicUrlConfig as Jt, TraceStepView as K, defineErrors as Kt, TraceEventContentPolicy as L, RuntimeResourceSupport as Lt, TraceActivityContext as M, RuntimeDiagnosticReporter as Mt, TraceActivityOwner as N, RuntimeResourceInspector as Nt, RuntimeContextInput as O, RuntimeDiagnosticError as Ot, TraceActivityPhase as P, RuntimeResourceObservation as Pt, deriveTraceRuns as Q, resolvePublicUrl as Qt, TraceEventLog as R, RuntimeResourceUnit as Rt, PolicyContext as S, ViteHubErrorDetail as St, RunLifecycleHooks as T, ViteHubErrorShape as Tt, TraceRunStatus as U, ErrorCatalog as Ut, TraceEventPayload as V, normalizeRuntimeDiagnosticError as Vt, TraceRunView as W, Result as Wt, createTraceEventLog as X, registerPublicUrlAgentName as Xt, createRuntimeWaitUntilController as Y, consoleInvocationUrl as Yt, defineCapability as Z, resetPublicUrlAgentNames as Zt, MaybeResolvable as _, WorkCheckpointStore as _t, ApprovalDecision as a, RuntimePreflightCheckSummary as an, normalizeExecutionAuthority as at, OpenTelemetrySpanView as b, createWorkTracker as bt, CapabilityDefinition as c, RuntimePreflightHandle as cn, traceEventsToOpenTelemetryLogRecords as ct, CreatedRuntimeContext as d, RuntimePreflightManifest as dn, SerializedResponse as dt, encodeRouteSegment as en, getCapability as et, ExecutionAuthority as f, RuntimePreflightOptions as fn, deserializeResponse as ft, MaybePromise as g, startRuntimePreflight as gn, WorkCheckpoint as gt, LeaseStore as h, runRuntimePreflight as hn, toResponse as ht, AccessAuthorizeResult as i, RuntimePreflightCheckResult as in, noExecutionAuthority as it, RuntimeWaitUntilController as j, RuntimeDiagnosticLevel as jt, RuntimeHostContext as k, RuntimeDiagnosticErrorOptions as kt, CapabilityHandle as l, RuntimePreflightIssue as ln, traceEventsToOpenTelemetrySpans as lt, Lease as m, RuntimePreflightValue as mn, serializeResponse as mt, AccessAuthorize as n, RuntimePreflightCheck as nn, isExecutionAuthority as nt, ApprovalRequest as o, RuntimePreflightDetails as on, resolveCapabilityPolicy as ot, ExecutionContext as p, RuntimePreflightState as pn, isSerializedResponse as pt, createExecutionContext as q, toResultError as qt, AccessAuthorizeOption as r, RuntimePreflightCheckContext as rn, isResolvable as rt, ApprovalState as s, RuntimePreflightDiagnosticData as sn, resolveRuntimeValue as st, AccessAuthorizationContext as t, isTraceContentAttributeKey as tn, hasCapability as tt, CapabilityPolicy as u, RuntimePreflightKind as un, unknownExecutionAuthority as ut, OpenTelemetryLogRecordView as v, WorkOutcome as vt, Resolvable as w, ViteHubErrorOptions as wt, OpenTelemetrySpanViewOptions as x, ViteHubError as xt, OpenTelemetrySpanEventView as y, WorkTracker as yt, TraceEventLogEntry as z, formatRuntimeDiagnosticError as zt };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineDiagnostics } from "nostics";
|
|
2
|
-
//#region src/error-diagnostics.ts
|
|
3
|
-
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
-
const runtimeErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
-
docsBase: () => "https://vitehub.dev/docs/reference/errors-diagnostics",
|
|
6
|
-
codes: {
|
|
7
|
-
RUNTIME_R0001: dynamicError,
|
|
8
|
-
RUNTIME_R0002: dynamicError,
|
|
9
|
-
RUNTIME_R0003: dynamicError,
|
|
10
|
-
RUNTIME_R0004: dynamicError,
|
|
11
|
-
RUNTIME_R0005: dynamicError,
|
|
12
|
-
RUNTIME_R0006: dynamicError,
|
|
13
|
-
RUNTIME_R0007: dynamicError,
|
|
14
|
-
RUNTIME_R0008: dynamicError,
|
|
15
|
-
RUNTIME_R0009: dynamicError,
|
|
16
|
-
RUNTIME_R0010: dynamicError,
|
|
17
|
-
RUNTIME_R0011: dynamicError,
|
|
18
|
-
RUNTIME_R0012: dynamicError,
|
|
19
|
-
RUNTIME_R0013: dynamicError,
|
|
20
|
-
RUNTIME_R0014: dynamicError,
|
|
21
|
-
RUNTIME_R0015: dynamicError,
|
|
22
|
-
RUNTIME_R0016: dynamicError
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/internal/runtime-type.ts
|
|
27
|
-
/** Narrows opaque inputs without reading their properties. */
|
|
28
|
-
function hasRuntimeType(value, expected) {
|
|
29
|
-
switch (expected) {
|
|
30
|
-
case "bigint":
|
|
31
|
-
case "boolean":
|
|
32
|
-
case "function":
|
|
33
|
-
case "number":
|
|
34
|
-
case "object":
|
|
35
|
-
case "string":
|
|
36
|
-
case "symbol":
|
|
37
|
-
case "undefined": {
|
|
38
|
-
const representation = typeof value;
|
|
39
|
-
return (representation === "undefined" && value !== void 0 ? "function" : representation) === expected;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw runtimeErrorDiagnostics.RUNTIME_R0008({ message: `Unsupported runtime type: ${expected}` });
|
|
43
|
-
}
|
|
44
|
-
/** Marks an intentional structural boundary that TypeScript cannot express. */
|
|
45
|
-
function asUnknownBoundary(value) {
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
function isRuntimeObject(value) {
|
|
49
|
-
return value !== null && Object(value) === value;
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
export { runtimeErrorDiagnostics as i, hasRuntimeType as n, isRuntimeObject as r, asUnknownBoundary as t };
|