@vite-hub/runtime 0.4.1 → 0.5.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/dist/core-Crv8CV_r.js +1103 -0
- package/dist/core-auTkK4iZ.d.ts +298 -0
- package/dist/durability.d.ts +3 -5
- package/dist/durability.js +5 -3
- package/dist/{error-diagnostics-BM9W4pBg.js → error-diagnostics-Dj98U7ch.js} +1 -2
- package/dist/{error-diagnostics-0sYgKTT8.d.ts → error-diagnostics-DuusexaK.d.ts} +0 -2
- package/dist/{errors-BQ0ofIL4.js → errors-D2ixvqv3.js} +2 -3
- package/dist/{execution-budget-BPXbISEt.d.ts → execution-budget-Bv7h0-5V.d.ts} +0 -2
- package/dist/hosted-console-DTh9zwNz.d.ts +28 -0
- package/dist/index-hFKl7B_y.d.ts +345 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +6 -5
- package/dist/internal/console.d.ts +5 -0
- package/dist/internal/console.js +1 -0
- package/dist/internal/context.d.ts +2 -0
- package/dist/internal/context.js +1 -0
- package/dist/internal/drain.d.ts +1 -3
- package/dist/internal/drain.js +3 -5
- package/dist/internal/error-diagnostics.d.ts +2 -0
- package/dist/internal/error-diagnostics.js +1 -0
- package/dist/internal/execution-budget.d.ts +2 -3
- package/dist/internal/execution-budget.js +226 -3
- package/dist/internal/grant.d.ts +1 -2
- package/dist/internal/grant.js +3 -4
- package/dist/internal/h3.d.ts +2 -4
- package/dist/internal/h3.js +4 -12
- package/dist/internal/node.d.ts +2 -3
- package/dist/internal/node.js +2 -3
- package/dist/internal/public-url.d.ts +2 -2
- package/dist/internal/public-url.js +1 -2
- package/dist/internal/response.d.ts +2 -0
- package/dist/internal/response.js +1 -0
- package/dist/internal/run-failed.d.ts +1 -3
- package/dist/internal/run-failed.js +1 -3
- package/dist/internal/run-scope.d.ts +1 -3
- package/dist/internal/run-scope.js +1 -2
- package/dist/internal/runtime-type.d.ts +1 -3
- package/dist/internal/runtime-type.js +2 -2
- package/dist/internal/shutdown.d.ts +1 -3
- package/dist/internal/shutdown.js +18 -21
- package/dist/internal/test-mode-setup.d.ts +1 -3
- package/dist/internal/test-mode-setup.js +1 -6
- package/dist/internal/test-mode.d.ts +1 -3
- package/dist/internal/test-mode.js +1 -2
- package/dist/internal/trace.d.ts +4 -0
- package/dist/internal/trace.js +1 -0
- package/dist/operations.d.ts +7 -4
- package/dist/operations.js +14 -11
- package/dist/{public-url-1WeOw54Z.d.ts → public-url-B4p8EOqr.d.ts} +6 -3
- package/dist/{public-url-ByAmAjbP.js → public-url-DDh_BHz3.js} +27 -22
- package/dist/request-context-Ci5FjuUY.js +680 -0
- package/dist/response-ClQ9ZSS_.d.ts +31 -0
- package/dist/response-DEyMvEBF.js +430 -0
- package/dist/{runtime-type-BftydMAf.js → runtime-type-EgaBGoVU.js} +2 -11
- package/package.json +29 -4
- package/dist/index-C1DoYfCf.d.ts +0 -733
- package/dist/request-context-uRQpodgl.js +0 -2433
|
@@ -1,4 +1,228 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
|
|
2
|
+
// src/execution-budget.ts
|
|
3
|
+
function executionBudgetExceededError(counter, limit) {
|
|
4
|
+
return Object.assign(runtimeErrorDiagnostics.RUNTIME_EXECUTION_BUDGET_EXCEEDED({ counter }), {
|
|
5
|
+
counter,
|
|
6
|
+
limit
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** Whether `error` is the error of an execution budget that ran out. */
|
|
10
|
+
function isExecutionBudgetExceededError(error) {
|
|
11
|
+
return error instanceof Error && Reflect.get(error, "code") === "RUNTIME_EXECUTION_BUDGET_EXCEEDED";
|
|
12
|
+
}
|
|
13
|
+
function createBudgetNode(parent) {
|
|
14
|
+
const node = {
|
|
15
|
+
cleanups: /* @__PURE__ */ new Set(),
|
|
16
|
+
children: /* @__PURE__ */ new Set(),
|
|
17
|
+
...parent ? { parent } : {},
|
|
18
|
+
disposed: parent?.disposed ?? false
|
|
19
|
+
};
|
|
20
|
+
if (!parent?.disposed) parent?.children.add(node);
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
function registerBudgetCleanup(node, cleanup) {
|
|
24
|
+
if (node.disposed) {
|
|
25
|
+
cleanup();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
node.cleanups.add(cleanup);
|
|
29
|
+
}
|
|
30
|
+
function disposeBudgetNode(node) {
|
|
31
|
+
if (node.disposed) return;
|
|
32
|
+
node.disposed = true;
|
|
33
|
+
for (const child of [...node.children]) disposeBudgetNode(child);
|
|
34
|
+
node.children.clear();
|
|
35
|
+
for (const cleanup of [...node.cleanups]) cleanup();
|
|
36
|
+
node.cleanups.clear();
|
|
37
|
+
node.parent?.children.delete(node);
|
|
38
|
+
}
|
|
39
|
+
function listenUntilReleased(signal, onAbort, node, releaseSignals) {
|
|
40
|
+
if (node.disposed) return;
|
|
41
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
42
|
+
const release = () => signal.removeEventListener("abort", onAbort);
|
|
43
|
+
for (const releaseSignal of releaseSignals) {
|
|
44
|
+
if (releaseSignal === signal) continue;
|
|
45
|
+
releaseSignal.addEventListener("abort", release, { once: true });
|
|
46
|
+
registerBudgetCleanup(node, () => releaseSignal.removeEventListener("abort", release));
|
|
47
|
+
}
|
|
48
|
+
registerBudgetCleanup(node, release);
|
|
49
|
+
}
|
|
50
|
+
function createExecutionBudget(options = {}) {
|
|
51
|
+
const limits = normalizeLimits(options);
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
const state = {
|
|
54
|
+
controller,
|
|
55
|
+
sharedController: new AbortController(),
|
|
56
|
+
limits,
|
|
57
|
+
usage: {
|
|
58
|
+
inputBytes: 0,
|
|
59
|
+
outputBytes: 0,
|
|
60
|
+
retries: 0,
|
|
61
|
+
toolCalls: 0
|
|
62
|
+
},
|
|
63
|
+
node: createBudgetNode()
|
|
64
|
+
};
|
|
65
|
+
const abortFromExternal = () => controller.abort(options.signal?.reason);
|
|
66
|
+
if (options.signal) {
|
|
67
|
+
if (options.signal.aborted) abortFromExternal();
|
|
68
|
+
else listenUntilReleased(options.signal, abortFromExternal, state.node, [controller.signal, state.sharedController.signal]);
|
|
69
|
+
}
|
|
70
|
+
if (limits.deadlineAt !== void 0) scheduleDeadline(controller, limits.deadlineAt, state.node, state.sharedController.signal);
|
|
71
|
+
return createBudget(state, limits, controller, state.node, options.signal);
|
|
72
|
+
}
|
|
73
|
+
function scheduleDeadline(controller, deadlineAt, node, sharedSignal) {
|
|
74
|
+
if (node.disposed) return;
|
|
75
|
+
let timer;
|
|
76
|
+
const schedule = () => {
|
|
77
|
+
if (node.disposed || controller.signal.aborted) return;
|
|
78
|
+
const remaining = deadlineAt - Date.now();
|
|
79
|
+
if (remaining <= 0) controller.abort(new DOMException("Execution budget timed out: deadline exceeded.", "TimeoutError"));
|
|
80
|
+
else {
|
|
81
|
+
timer = setTimeout(schedule, Math.min(remaining, 2147483647));
|
|
82
|
+
if (typeof timer === "object" && timer !== null && "unref" in timer && typeof timer.unref === "function") timer.unref();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const clear = () => clearTimeout(timer);
|
|
86
|
+
controller.signal.addEventListener("abort", clear, { once: true });
|
|
87
|
+
sharedSignal.addEventListener("abort", clear, { once: true });
|
|
88
|
+
registerBudgetCleanup(node, () => {
|
|
89
|
+
clear();
|
|
90
|
+
controller.signal.removeEventListener("abort", clear);
|
|
91
|
+
sharedSignal.removeEventListener("abort", clear);
|
|
92
|
+
});
|
|
93
|
+
schedule();
|
|
94
|
+
}
|
|
95
|
+
function createBudget(state, limits, controller, node, externalSignal, deadlineController = controller) {
|
|
96
|
+
function assertAvailable(counter, amount) {
|
|
97
|
+
const stateReason = state.controller.signal.reason;
|
|
98
|
+
const controllerReason = controller.signal.reason;
|
|
99
|
+
const sharedReason = state.sharedController.signal.reason;
|
|
100
|
+
if (state.controller.signal.aborted && !isExecutionBudgetExceededError(stateReason)) state.controller.signal.throwIfAborted();
|
|
101
|
+
if (controller.signal.aborted && !isExecutionBudgetExceededError(controllerReason)) controller.signal.throwIfAborted();
|
|
102
|
+
if (!node.disposed && externalSignal?.aborted && !isExecutionBudgetExceededError(externalSignal.reason)) externalSignal.throwIfAborted();
|
|
103
|
+
if (state.sharedController.signal.aborted) {
|
|
104
|
+
if (isExecutionBudgetExceededError(sharedReason)) throw sharedReason;
|
|
105
|
+
state.sharedController.signal.throwIfAborted();
|
|
106
|
+
}
|
|
107
|
+
if (!node.disposed && limits.deadlineAt !== void 0 && Date.now() >= limits.deadlineAt) {
|
|
108
|
+
deadlineController.abort(new DOMException("Execution budget timed out: deadline exceeded.", "TimeoutError"));
|
|
109
|
+
deadlineController.signal.throwIfAborted();
|
|
110
|
+
}
|
|
111
|
+
if (!Number.isFinite(amount) || amount < 0) throw runtimeErrorDiagnostics.RUNTIME_EXECUTION_BUDGET_AMOUNT_INVALID({ counter });
|
|
112
|
+
const next = state.usage[counter] + amount;
|
|
113
|
+
const limit = limitFor(counter, limits);
|
|
114
|
+
if (limit !== void 0 && next > limit) {
|
|
115
|
+
const error = executionBudgetExceededError(counter, limit);
|
|
116
|
+
state.sharedController.abort(error);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
if (isExecutionBudgetExceededError(stateReason)) throw stateReason;
|
|
120
|
+
if (isExecutionBudgetExceededError(controllerReason)) throw controllerReason;
|
|
121
|
+
}
|
|
122
|
+
function consume(counter, amount = 1) {
|
|
123
|
+
assertAvailable(counter, amount);
|
|
124
|
+
state.usage[counter] += amount;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
signal: AbortSignal.any([controller.signal, state.sharedController.signal]),
|
|
128
|
+
cancel(reason) {
|
|
129
|
+
controller.abort(reason);
|
|
130
|
+
},
|
|
131
|
+
dispose() {
|
|
132
|
+
disposeBudgetNode(node);
|
|
133
|
+
},
|
|
134
|
+
child(options = {}) {
|
|
135
|
+
const childLimits = normalizeLimits(options);
|
|
136
|
+
const childController = new AbortController();
|
|
137
|
+
const childNode = createBudgetNode(node);
|
|
138
|
+
const abortChild = (reason) => childController.abort(reason);
|
|
139
|
+
const releaseSignals = [childController.signal, state.sharedController.signal];
|
|
140
|
+
if (state.sharedController.signal.aborted) abortChild(state.sharedController.signal.reason);
|
|
141
|
+
else if (controller.signal.aborted) abortChild(controller.signal.reason);
|
|
142
|
+
else {
|
|
143
|
+
listenUntilReleased(controller.signal, () => abortChild(controller.signal.reason), childNode, releaseSignals);
|
|
144
|
+
listenUntilReleased(state.sharedController.signal, () => abortChild(state.sharedController.signal.reason), childNode, releaseSignals);
|
|
145
|
+
}
|
|
146
|
+
if (options.signal) {
|
|
147
|
+
if (options.signal.aborted) abortChild(options.signal.reason);
|
|
148
|
+
else if (!childController.signal.aborted) listenUntilReleased(options.signal, () => abortChild(options.signal?.reason), childNode, releaseSignals);
|
|
149
|
+
}
|
|
150
|
+
const deadlineAt = minDefined(limits.deadlineAt, childLimits.deadlineAt);
|
|
151
|
+
const childDeadlineController = deadlineAt === limits.deadlineAt ? deadlineController : childController;
|
|
152
|
+
if (deadlineAt !== void 0) scheduleDeadline(childController, deadlineAt, childNode, state.sharedController.signal);
|
|
153
|
+
return createBudget(state, {
|
|
154
|
+
deadlineAt,
|
|
155
|
+
maxInputBytes: minDefined(limits.maxInputBytes, childLimits.maxInputBytes),
|
|
156
|
+
maxOutputBytes: minDefined(limits.maxOutputBytes, childLimits.maxOutputBytes),
|
|
157
|
+
maxRetries: minDefined(limits.maxRetries, childLimits.maxRetries),
|
|
158
|
+
maxToolCalls: minDefined(limits.maxToolCalls, childLimits.maxToolCalls)
|
|
159
|
+
}, childController, childNode, options.signal, childDeadlineController);
|
|
160
|
+
},
|
|
161
|
+
consume(counter, amount = 1) {
|
|
162
|
+
consume(counter, amount);
|
|
163
|
+
},
|
|
164
|
+
recordInputBytes(amount) {
|
|
165
|
+
assertAvailable("inputBytes", amount);
|
|
166
|
+
state.usage.inputBytes += amount;
|
|
167
|
+
},
|
|
168
|
+
recordOutputBytes(amount) {
|
|
169
|
+
assertAvailable("outputBytes", amount);
|
|
170
|
+
state.usage.outputBytes += amount;
|
|
171
|
+
},
|
|
172
|
+
recordRetry() {
|
|
173
|
+
assertAvailable("retries", 1);
|
|
174
|
+
state.usage.retries += 1;
|
|
175
|
+
},
|
|
176
|
+
recordToolCall(inputBytes = 0) {
|
|
177
|
+
assertAvailable("toolCalls", 1);
|
|
178
|
+
if (inputBytes !== 0) assertAvailable("inputBytes", inputBytes);
|
|
179
|
+
state.usage.toolCalls += 1;
|
|
180
|
+
if (inputBytes !== 0) state.usage.inputBytes += inputBytes;
|
|
181
|
+
},
|
|
182
|
+
snapshot() {
|
|
183
|
+
const remainingTime = limits.deadlineAt === void 0 ? void 0 : Math.max(0, limits.deadlineAt - Date.now());
|
|
184
|
+
return {
|
|
185
|
+
cancelled: state.controller.signal.aborted || controller.signal.aborted || state.sharedController.signal.aborted,
|
|
186
|
+
...limits.deadlineAt === void 0 ? {} : { deadlineAt: limits.deadlineAt },
|
|
187
|
+
limits: { ...limits },
|
|
188
|
+
remaining: {
|
|
189
|
+
...limits.maxInputBytes === void 0 ? {} : { inputBytes: Math.max(0, limits.maxInputBytes - state.usage.inputBytes) },
|
|
190
|
+
...limits.maxOutputBytes === void 0 ? {} : { outputBytes: Math.max(0, limits.maxOutputBytes - state.usage.outputBytes) },
|
|
191
|
+
...limits.maxRetries === void 0 ? {} : { retries: Math.max(0, limits.maxRetries - state.usage.retries) },
|
|
192
|
+
...limits.maxToolCalls === void 0 ? {} : { toolCalls: Math.max(0, limits.maxToolCalls - state.usage.toolCalls) },
|
|
193
|
+
...remainingTime === void 0 ? {} : { timeMs: remainingTime }
|
|
194
|
+
},
|
|
195
|
+
usage: { ...state.usage }
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function limitFor(counter, limits) {
|
|
201
|
+
if (counter === "inputBytes") return limits.maxInputBytes;
|
|
202
|
+
if (counter === "outputBytes") return limits.maxOutputBytes;
|
|
203
|
+
if (counter === "retries") return limits.maxRetries;
|
|
204
|
+
return limits.maxToolCalls;
|
|
205
|
+
}
|
|
206
|
+
function minDefined(left, right) {
|
|
207
|
+
if (left === void 0) return right;
|
|
208
|
+
if (right === void 0) return left;
|
|
209
|
+
return Math.min(left, right);
|
|
210
|
+
}
|
|
211
|
+
function normalizeLimits(options) {
|
|
212
|
+
const normalize = (value) => {
|
|
213
|
+
if (value === void 0) return void 0;
|
|
214
|
+
if (!Number.isFinite(value) || value < 0) throw runtimeErrorDiagnostics.RUNTIME_EXECUTION_BUDGET_LIMIT_INVALID();
|
|
215
|
+
return Math.floor(value);
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
deadlineAt: normalize(options.deadlineAt),
|
|
219
|
+
maxInputBytes: normalize(options.maxInputBytes),
|
|
220
|
+
maxOutputBytes: normalize(options.maxOutputBytes),
|
|
221
|
+
maxRetries: normalize(options.maxRetries),
|
|
222
|
+
maxToolCalls: normalize(options.maxToolCalls)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// src/internal/execution-budget.ts
|
|
2
226
|
const budgetHandledTools = /* @__PURE__ */ new WeakMap();
|
|
3
227
|
/** Internal context key used when a budget-owned tool is reused by another Invocation. */
|
|
4
228
|
const executionBudgetOverride = Symbol("vitehub.execution-budget-override");
|
|
@@ -13,5 +237,4 @@ function isExecutionBudgetHandled(tool, budget) {
|
|
|
13
237
|
function executionBudgetHandledBy(tool) {
|
|
14
238
|
return budgetHandledTools.get(tool);
|
|
15
239
|
}
|
|
16
|
-
|
|
17
|
-
export { executionBudgetCharged, executionBudgetHandledBy, executionBudgetOverride, isExecutionBudgetHandled, markExecutionBudgetHandled };
|
|
240
|
+
export { createExecutionBudget, executionBudgetCharged, executionBudgetHandledBy, executionBudgetOverride, isExecutionBudgetExceededError, isExecutionBudgetHandled, markExecutionBudgetHandled };
|
package/dist/internal/grant.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/internal/grant.d.ts
|
|
2
1
|
declare const grantKind: unique symbol;
|
|
3
2
|
/**
|
|
4
3
|
* Proof that one check passed. Only the definition that issued it can verify it.
|
|
@@ -33,4 +32,4 @@ export interface GrantDefinition<Kind extends string, Input, Value> {
|
|
|
33
32
|
* another bundled copy, or a forged object fails closed. Grants are request-scoped. Never persist one.
|
|
34
33
|
*/
|
|
35
34
|
export declare function defineGrant<const Kind extends string, Input, Value>(kind: Kind, bind: (input: Input) => Value): GrantDefinition<Kind, Input, Value>;
|
|
36
|
-
|
|
35
|
+
export {};
|
package/dist/internal/grant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as ViteHubError } from "../errors-D2ixvqv3.js";
|
|
2
|
+
import { r as isRuntimeObject } from "../runtime-type-EgaBGoVU.js";
|
|
3
|
+
// src/internal/grant.ts
|
|
4
4
|
/**
|
|
5
5
|
* Define one kind of grant. Keep the definition module-private: the module that owns the check issues grants,
|
|
6
6
|
* and the sensitive action verifies them. Each definition has its own registry, so a grant from another definition,
|
|
@@ -40,5 +40,4 @@ function defineGrant(kind, bind) {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
//#endregion
|
|
44
43
|
export { defineGrant };
|
package/dist/internal/h3.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as RequestRuntimeContext, d as sendPreparedResponse, o as RuntimeContextOptions, u as installRequestStandardContext } from "../index-hFKl7B_y.js";
|
|
2
|
+
import { dt as ViteHubContext, ft as ViteHubRuntime, pt as ViteHubStandardProps } from "../core-auTkK4iZ.js";
|
|
2
3
|
import { EventHandlerRequest } from "h3";
|
|
3
|
-
//#region src/internal/h3.d.ts
|
|
4
4
|
declare module "h3" {
|
|
5
5
|
interface H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> {
|
|
6
|
-
/** Set by ViteHub for each request until H3 implements Standard Context. */
|
|
7
6
|
readonly "~standard": ViteHubStandardProps;
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -38,5 +37,4 @@ export declare function getStandardContext(value: Request | ViteHubContext): Vit
|
|
|
38
37
|
/** Adapt one request. Pass an H3 event or a web Request. Await flushWaitUntil when the host has no lifetime API. */
|
|
39
38
|
export declare function getRuntimeContext(value: Request | ViteHubContext): H3RuntimeContext;
|
|
40
39
|
export declare function getRuntimeContext<const TOptions extends H3RuntimeContextOptions>(value: Request | ViteHubContext, options: TOptions): H3RuntimeContext<TOptions>;
|
|
41
|
-
//#endregion
|
|
42
40
|
export { type ViteHubContext, type ViteHubRuntime, type ViteHubStandardProps, installRequestStandardContext, sendPreparedResponse };
|
package/dist/internal/h3.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { S as ownValue, a as installRequestStandardContext, b as getCloudflareEnv, c as sendPreparedResponse, i as getStandardContext$1, n as firstAddress, o as isHostRequest, s as requestAddressPaths, t as createStandardRuntimeContext, v as activeEnvStorageKey, x as ownObject, y as cloudflareOwners } from "../request-context-Ci5FjuUY.js";
|
|
2
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
|
|
4
|
+
// ../internal/dist/runtime/cloudflare-env.js
|
|
5
5
|
const runtimeGlobal = globalThis;
|
|
6
6
|
runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
7
7
|
/** Return the Cloudflare Worker execution context of a request event, if the host provides one. */
|
|
@@ -38,9 +38,7 @@ function resolveWaitUntil(event, options = {}) {
|
|
|
38
38
|
if (typeof waitUntil === "function") return waitUntil.bind(owner);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
//#region src/internal/h3.ts
|
|
43
|
-
/** H3 2 uses separate headers for returned error Responses. Mirror only Standard Context writes to both. */
|
|
41
|
+
// src/internal/h3.ts
|
|
44
42
|
function responseHeaders(target) {
|
|
45
43
|
const { headers, errHeaders } = target;
|
|
46
44
|
if (!errHeaders) return headers;
|
|
@@ -71,7 +69,6 @@ function responseHeaders(target) {
|
|
|
71
69
|
};
|
|
72
70
|
return Object.assign(view, methods);
|
|
73
71
|
}
|
|
74
|
-
/** Map Standard Context response fields to the response that H3 sends. H3 sends the value the handler returns as the body. */
|
|
75
72
|
function preparedResponse(target) {
|
|
76
73
|
const headers = responseHeaders(target);
|
|
77
74
|
return {
|
|
@@ -94,10 +91,6 @@ function preparedResponse(target) {
|
|
|
94
91
|
}
|
|
95
92
|
};
|
|
96
93
|
}
|
|
97
|
-
/**
|
|
98
|
-
* The `~standard` properties of one H3 event. Each property reads the event on first access and keeps the value,
|
|
99
|
-
* because most requests never read Standard Context and ViteHub sets it on every request.
|
|
100
|
-
*/
|
|
101
94
|
var H3StandardProps = class {
|
|
102
95
|
vendor = "h3";
|
|
103
96
|
#event;
|
|
@@ -177,5 +170,4 @@ function getRuntimeContext(value, options = {}) {
|
|
|
177
170
|
}
|
|
178
171
|
return createStandardRuntimeContext(value, value["~standard"], options);
|
|
179
172
|
}
|
|
180
|
-
//#endregion
|
|
181
173
|
export { getRuntimeContext, getStandardContext, installRequestStandardContext, installStandardContext, sendPreparedResponse };
|
package/dist/internal/node.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/internal/node.d.ts
|
|
1
|
+
import { w as RuntimeResourceInspector } from "../index-hFKl7B_y.js";
|
|
3
2
|
type ReadText = (path: string, options?: {
|
|
4
3
|
signal?: AbortSignal;
|
|
5
4
|
}) => Promise<string>;
|
|
@@ -30,4 +29,4 @@ export interface ProcessReconciler extends ProcessReconcilerRunContext {
|
|
|
30
29
|
wake: (reason: string) => void;
|
|
31
30
|
}
|
|
32
31
|
export declare function createProcessReconciler(options: ProcessReconcilerOptions): ProcessReconciler;
|
|
33
|
-
|
|
32
|
+
export {};
|
package/dist/internal/node.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { availableMemory, memoryUsage, resourceUsage } from "node:process";
|
|
6
|
-
|
|
6
|
+
// src/internal/node.ts
|
|
7
7
|
function observation(name, value, scope, source, unit) {
|
|
8
8
|
return value === void 0 || !Number.isFinite(value) ? [] : [{
|
|
9
9
|
name,
|
|
@@ -395,5 +395,4 @@ function createProcessReconciler(options) {
|
|
|
395
395
|
wake
|
|
396
396
|
};
|
|
397
397
|
}
|
|
398
|
-
//#endregion
|
|
399
398
|
export { createProcessReconciler, nodeRuntimeResources, resolveLinuxCgroupV2Path };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
1
|
+
import { a as resetPublicUrlAgentNames, i as registerPublicUrlAgentName, n as configuredPublicOrigins } from "../public-url-B4p8EOqr.js";
|
|
2
|
+
export { configuredPublicOrigins, registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
1
|
+
export { t as configuredPublicOrigins, r as registerPublicUrlAgentName, i as resetPublicUrlAgentNames } from "../public-url-DDh_BHz3.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as deserializeResponse, n as isResponse, r as isSerializedResponse, i as serializeResponse, a as toResponse } from "../response-DEyMvEBF.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/internal/run-failed.d.ts
|
|
2
1
|
/** The error of a failed run: its message and, for a ViteHub error, its code. */
|
|
3
2
|
export interface RunFailedError {
|
|
4
3
|
message: string;
|
|
@@ -36,5 +35,4 @@ export declare function toRunFailedError(error: unknown): RunFailedError;
|
|
|
36
35
|
* serverless host keeps the work alive, and it never throws: an alert that fails must not change the run.
|
|
37
36
|
*/
|
|
38
37
|
export declare function emitRunFailed(event: RunFailedEvent): Promise<void>;
|
|
39
|
-
export declare function hasRunFailedListeners(): boolean;
|
|
40
|
-
//#endregion
|
|
38
|
+
export declare function hasRunFailedListeners(): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/run-failed.ts
|
|
2
2
|
const runFailedEventNames = [
|
|
3
3
|
"invocation.failed",
|
|
4
4
|
"schedule.failed",
|
|
@@ -16,7 +16,6 @@ function onRunFailed(listener) {
|
|
|
16
16
|
listeners().delete(listener);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
/** Long messages, such as a stack in a message, are cut to this many characters. */
|
|
20
19
|
const maxMessageLength = 2e3;
|
|
21
20
|
/** The message and code of a thrown value. */
|
|
22
21
|
function toRunFailedError(error) {
|
|
@@ -52,5 +51,4 @@ async function emitRunFailed(event) {
|
|
|
52
51
|
function hasRunFailedListeners() {
|
|
53
52
|
return listeners().size > 0;
|
|
54
53
|
}
|
|
55
|
-
//#endregion
|
|
56
54
|
export { emitRunFailed, hasRunFailedListeners, onRunFailed, runFailedEventNames, toRunFailedError };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/internal/run-scope.d.ts
|
|
2
1
|
/** Wraps one unit of work, such as a Schedule run or a Queue job. It calls `run` once and passes on its error. */
|
|
3
2
|
export type RunScope = (run: () => Promise<void>) => Promise<unknown>;
|
|
4
3
|
/**
|
|
@@ -7,5 +6,4 @@ export type RunScope = (run: () => Promise<void>) => Promise<unknown>;
|
|
|
7
6
|
*/
|
|
8
7
|
export declare function registerRunScope(scope: RunScope): void;
|
|
9
8
|
/** Runs one Schedule run or Queue job inside every registered scope. A Nitro request gets its scopes from middleware. */
|
|
10
|
-
export declare function runInRunScopes<T>(run: () => T | Promise<T>): Promise<T>;
|
|
11
|
-
//#endregion
|
|
9
|
+
export declare function runInRunScopes<T>(run: () => T | Promise<T>): Promise<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/run-scope.ts
|
|
2
2
|
const scopesKey = Symbol.for("vitehub.runtime.runScopes");
|
|
3
3
|
function scopes() {
|
|
4
4
|
const runtimeGlobal = globalThis;
|
|
@@ -26,5 +26,4 @@ async function runInRunScopes(run) {
|
|
|
26
26
|
await next();
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
|
-
//#endregion
|
|
30
29
|
export { registerRunScope, runInRunScopes };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
//#region src/internal/runtime-type.d.ts
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-DuusexaK.js";
|
|
3
2
|
type RuntimeTypeMap = {
|
|
4
3
|
bigint: bigint;
|
|
5
4
|
boolean: boolean;
|
|
@@ -22,5 +21,4 @@ export declare function isRuntimeObject(value: unknown): value is object;
|
|
|
22
21
|
* and a Response from another Fetch implementation all fail. A proxy fails too. The check reads no property of `value`.
|
|
23
22
|
*/
|
|
24
23
|
export declare function isRuntimeResponse(value: unknown): value is Response;
|
|
25
|
-
//#endregion
|
|
26
24
|
export { runtimeErrorDiagnostics };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
|
|
2
|
+
import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-EgaBGoVU.js";
|
|
3
3
|
export { asUnknownBoundary, hasRuntimeType, isRuntimeObject, isRuntimeResponse, runtimeErrorDiagnostics };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/internal/shutdown.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Graceful shutdown that ViteHub owns.
|
|
4
3
|
*
|
|
@@ -80,5 +79,4 @@ export declare function runShutdownDrains(app?: ShutdownApp, runtime?: ShutdownR
|
|
|
80
79
|
* The drain runs when a server that owns stop signals gets SIGTERM or SIGINT, or when the
|
|
81
80
|
* Nitro app closes. All drains share the budget in `VITEHUB_SHUTDOWN_DRAIN_MS`.
|
|
82
81
|
*/
|
|
83
|
-
export declare function onShutdown(app: ShutdownApp, name: string, drain: ShutdownDrain, runtime?: ShutdownRuntime | undefined): void;
|
|
84
|
-
//#endregion
|
|
82
|
+
export declare function onShutdown(app: ShutdownApp, name: string, drain: ShutdownDrain, runtime?: ShutdownRuntime | undefined): void;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/shutdown.ts
|
|
2
2
|
/** Name of the variable that sets the shared drain budget in milliseconds. The default is 0. */
|
|
3
3
|
const shutdownDrainEnv = "VITEHUB_SHUTDOWN_DRAIN_MS";
|
|
4
|
-
/** Time that a drain gets after the budget ends to finish its abort, such as a restart notice. */
|
|
5
4
|
const settleMs = 15e3;
|
|
6
|
-
/** Time that the server gets to close HTTP and run Nitro `close` hooks after the drains. */
|
|
7
5
|
const closeMs = 1e4;
|
|
8
6
|
const signals = ["SIGTERM", "SIGINT"];
|
|
9
7
|
function currentProcess() {
|
|
@@ -11,7 +9,6 @@ function currentProcess() {
|
|
|
11
9
|
if (!candidate || typeof candidate.on !== "function" || typeof candidate.listeners !== "function") return void 0;
|
|
12
10
|
return candidate;
|
|
13
11
|
}
|
|
14
|
-
/** State for a host without `process`, such as a Cloudflare Worker without Node compatibility. */
|
|
15
12
|
let isolateState;
|
|
16
13
|
/** Returns the shutdown state of this process. */
|
|
17
14
|
function shutdownState(runtime = currentProcess()) {
|
|
@@ -82,10 +79,14 @@ function runShutdownDrains(app, runtime = currentProcess()) {
|
|
|
82
79
|
if (state.status === "running") state.entries.delete(entry);
|
|
83
80
|
})));
|
|
84
81
|
}
|
|
85
|
-
function
|
|
82
|
+
function isSrvxShutdown(listener) {
|
|
83
|
+
if (typeof listener !== "function") return false;
|
|
84
|
+
const source = Function.prototype.toString.call(listener);
|
|
85
|
+
return source.includes("Stopping server gracefully (") && source.includes("Graceful shutdown timed out.");
|
|
86
|
+
}
|
|
87
|
+
function installSignalTrap(runtime, state) {
|
|
86
88
|
state.trap = "pending";
|
|
87
|
-
|
|
88
|
-
const serverListeners = [];
|
|
89
|
+
let serverShutdown;
|
|
89
90
|
let resolveSetup;
|
|
90
91
|
const setup = new Promise((resolve) => {
|
|
91
92
|
resolveSetup = resolve;
|
|
@@ -105,7 +106,8 @@ function installSignalTrap(app, runtime, state) {
|
|
|
105
106
|
}));
|
|
106
107
|
(async () => {
|
|
107
108
|
await setup;
|
|
108
|
-
|
|
109
|
+
const shutdown = serverShutdown;
|
|
110
|
+
if (!shutdown) {
|
|
109
111
|
state.status = "running";
|
|
110
112
|
if (runtime.kill && typeof process !== "undefined" && typeof process.pid === "number") runtime.kill(process.pid, signal);
|
|
111
113
|
return;
|
|
@@ -118,8 +120,7 @@ function installSignalTrap(app, runtime, state) {
|
|
|
118
120
|
signal,
|
|
119
121
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
120
122
|
}));
|
|
121
|
-
const
|
|
122
|
-
const closeServer = Promise.all(listeners.map(([, listener]) => Promise.resolve().then(() => listener(signal)))).then(() => void 0, (error) => console.error("[vitehub] Server shutdown failed.", error));
|
|
123
|
+
const closeServer = Promise.resolve().then(() => shutdown(signal)).then(() => void 0, (error) => console.error("[vitehub] Server shutdown failed.", error));
|
|
123
124
|
await Promise.race([closeServer, new Promise((resolve) => {
|
|
124
125
|
setTimeout(resolve, closeMs).unref?.();
|
|
125
126
|
})]);
|
|
@@ -157,15 +158,12 @@ function installSignalTrap(app, runtime, state) {
|
|
|
157
158
|
};
|
|
158
159
|
for (const signal of signals) runtime.on(signal, stop);
|
|
159
160
|
setTimeout(() => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (serverListeners.length) {
|
|
161
|
+
const interrupts = new Set(runtime.listeners("SIGINT"));
|
|
162
|
+
const candidates = runtime.listeners("SIGTERM").filter((listener) => interrupts.has(listener)).filter(isSrvxShutdown);
|
|
163
|
+
const [server] = candidates;
|
|
164
|
+
if (server && candidates.length === 1) {
|
|
165
|
+
serverShutdown = server;
|
|
166
|
+
for (const signal of signals) runtime.off(signal, server);
|
|
169
167
|
state.trap = "installed";
|
|
170
168
|
state.signals = true;
|
|
171
169
|
resolveSetup();
|
|
@@ -194,9 +192,8 @@ function onShutdown(app, name, drain, runtime = currentProcess()) {
|
|
|
194
192
|
app.hooks.hook("close", () => runShutdownDrains(app, runtime));
|
|
195
193
|
}
|
|
196
194
|
if (runtime && !state.trap) {
|
|
197
|
-
if ((runtime.release?.name === "node" || runtime.release?.name === "bun") && globalThis.navigator?.userAgent !== "Cloudflare-Workers") installSignalTrap(
|
|
195
|
+
if ((runtime.release?.name === "node" || runtime.release?.name === "bun") && globalThis.navigator?.userAgent !== "Cloudflare-Workers") installSignalTrap(runtime, state);
|
|
198
196
|
else state.trap = "skipped";
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
|
-
//#endregion
|
|
202
199
|
export { onShutdown, runShutdownDrains, shutdownDrainEnv, shutdownState };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ViteHubTestMode } from "./test-mode.js";
|
|
2
|
-
//#region src/internal/test-mode-setup.d.ts
|
|
3
2
|
/** Turns test mode on for this process, or returns the active one. */
|
|
4
3
|
export declare function enableViteHubTestMode(options?: {
|
|
5
4
|
root?: string;
|
|
6
|
-
}): ViteHubTestMode;
|
|
7
|
-
//#endregion
|
|
5
|
+
}): ViteHubTestMode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { viteHubTestModeKey } from "./test-mode.js";
|
|
2
|
-
|
|
2
|
+
// src/internal/test-mode-setup.ts
|
|
3
3
|
const processRoots = /* @__PURE__ */ new Map();
|
|
4
4
|
function isRunning(pid) {
|
|
5
5
|
try {
|
|
@@ -9,10 +9,6 @@ function isRunning(pid) {
|
|
|
9
9
|
return error.code === "EPERM";
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* One folder per test process under `<root>/.vitehub/test`. A test runner can stop its workers without an exit event,
|
|
14
|
-
* so each process also deletes the folders of processes that no longer run.
|
|
15
|
-
*/
|
|
16
12
|
function processTemporaryRoot(root) {
|
|
17
13
|
const existing = processRoots.get(root);
|
|
18
14
|
if (existing) return existing;
|
|
@@ -110,5 +106,4 @@ function enableViteHubTestMode(options = {}) {
|
|
|
110
106
|
target[viteHubTestModeKey] = mode;
|
|
111
107
|
return mode;
|
|
112
108
|
}
|
|
113
|
-
//#endregion
|
|
114
109
|
export { enableViteHubTestMode };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/internal/test-mode.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Test mode for app tests. `vite-hub/test` turns it on, and each Server Primitive then uses a local backend that lives
|
|
4
3
|
* until the next reset, instead of its configured driver. The state is on `globalThis`, so every package copy in the
|
|
@@ -28,5 +27,4 @@ export type ViteHubTestModeGlobal = typeof globalThis & {
|
|
|
28
27
|
[viteHubTestModeKey]?: ViteHubTestMode;
|
|
29
28
|
};
|
|
30
29
|
/** The active test mode, or `undefined` outside tests. */
|
|
31
|
-
export declare function getViteHubTestMode(): ViteHubTestMode | undefined;
|
|
32
|
-
//#endregion
|
|
30
|
+
export declare function getViteHubTestMode(): ViteHubTestMode | undefined;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/test-mode.ts
|
|
2
2
|
/** The `globalThis` key of the active test mode. */
|
|
3
3
|
const viteHubTestModeKey = Symbol.for("vitehub.test");
|
|
4
4
|
/** The active test mode, or `undefined` outside tests. */
|
|
5
5
|
function getViteHubTestMode() {
|
|
6
6
|
return globalThis[viteHubTestModeKey];
|
|
7
7
|
}
|
|
8
|
-
//#endregion
|
|
9
8
|
export { getViteHubTestMode, viteHubTestModeKey };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { $ as emitTraceEvent, ct as traceEventsToOpenTelemetryLogRecords, lt as traceEventsToOpenTelemetrySpans } from "../core-auTkK4iZ.js";
|
|
2
|
+
import "../index-hFKl7B_y.js";
|
|
3
|
+
export declare function isTraceContentAttributeKey(key: string): boolean;
|
|
4
|
+
export { emitTraceEvent, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { s as emitTraceEvent, y as isTraceContentAttributeKey, g as traceEventsToOpenTelemetryLogRecords, _ as traceEventsToOpenTelemetrySpans } from "../core-Crv8CV_r.js";
|