@vite-hub/runtime 0.4.1 → 0.5.0
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-BfUEli_0.d.ts +304 -0
- package/dist/core-DpLK9dQt.js +1105 -0
- package/dist/durability.d.ts +2 -2
- package/dist/durability.js +4 -1
- package/dist/hosted-console-ZfMo5MW4.d.ts +30 -0
- package/dist/index-DsisbCNa.d.ts +364 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +5 -4
- package/dist/internal/console.d.ts +7 -0
- package/dist/internal/console.js +2 -0
- package/dist/internal/context.d.ts +2 -0
- package/dist/internal/context.js +2 -0
- package/dist/internal/error-diagnostics.d.ts +2 -0
- package/dist/internal/error-diagnostics.js +2 -0
- package/dist/internal/execution-budget.d.ts +3 -2
- package/dist/internal/execution-budget.js +226 -1
- package/dist/internal/grant.js +1 -1
- package/dist/internal/h3.d.ts +2 -2
- package/dist/internal/h3.js +1 -7
- package/dist/internal/node.d.ts +1 -1
- package/dist/internal/public-url.d.ts +2 -2
- package/dist/internal/public-url.js +2 -2
- package/dist/internal/response.d.ts +2 -0
- package/dist/internal/response.js +2 -0
- package/dist/internal/run-failed.js +0 -1
- package/dist/internal/runtime-type.js +1 -1
- package/dist/internal/shutdown.js +17 -19
- package/dist/internal/test-mode-setup.js +0 -4
- package/dist/internal/trace.d.ts +6 -0
- package/dist/internal/trace.js +2 -0
- package/dist/operations.d.ts +8 -2
- package/dist/operations.js +6 -2
- package/dist/{public-url-1WeOw54Z.d.ts → public-url-BCFhTiTM.d.ts} +6 -1
- package/dist/{public-url-ByAmAjbP.js → public-url-DizC8CFs.js} +25 -17
- package/dist/request-context-Dmsliqan.js +687 -0
- package/dist/response-Be5M4WIn.js +432 -0
- package/dist/response-iONbTI0E.d.ts +33 -0
- package/dist/{runtime-type-BftydMAf.js → runtime-type-CHYQYwDx.js} +0 -7
- package/package.json +26 -1
- package/dist/index-C1DoYfCf.d.ts +0 -733
- package/dist/request-context-uRQpodgl.js +0 -2433
|
@@ -1,3 +1,228 @@
|
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
2
|
+
//#region 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
|
+
//#endregion
|
|
1
226
|
//#region src/internal/execution-budget.ts
|
|
2
227
|
const budgetHandledTools = /* @__PURE__ */ new WeakMap();
|
|
3
228
|
/** Internal context key used when a budget-owned tool is reused by another Invocation. */
|
|
@@ -14,4 +239,4 @@ function executionBudgetHandledBy(tool) {
|
|
|
14
239
|
return budgetHandledTools.get(tool);
|
|
15
240
|
}
|
|
16
241
|
//#endregion
|
|
17
|
-
export { executionBudgetCharged, executionBudgetHandledBy, executionBudgetOverride, isExecutionBudgetHandled, markExecutionBudgetHandled };
|
|
242
|
+
export { createExecutionBudget, executionBudgetCharged, executionBudgetHandledBy, executionBudgetOverride, isExecutionBudgetExceededError, isExecutionBudgetHandled, markExecutionBudgetHandled };
|
package/dist/internal/grant.js
CHANGED
package/dist/internal/h3.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dt as ViteHubContext, ft as ViteHubRuntime, pt as ViteHubStandardProps } from "../core-BfUEli_0.js";
|
|
2
|
+
import { a as RequestRuntimeContext, d as sendPreparedResponse, o as RuntimeContextOptions, u as installRequestStandardContext } from "../index-DsisbCNa.js";
|
|
2
3
|
import { EventHandlerRequest } from "h3";
|
|
3
4
|
//#region src/internal/h3.d.ts
|
|
4
5
|
declare module "h3" {
|
|
5
6
|
interface H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> {
|
|
6
|
-
/** Set by ViteHub for each request until H3 implements Standard Context. */
|
|
7
7
|
readonly "~standard": ViteHubStandardProps;
|
|
8
8
|
}
|
|
9
9
|
}
|
package/dist/internal/h3.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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-Dmsliqan.js";
|
|
2
2
|
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
//#region ../internal/dist/runtime/cloudflare-env.js
|
|
@@ -40,7 +40,6 @@ function resolveWaitUntil(event, options = {}) {
|
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/internal/h3.ts
|
|
43
|
-
/** H3 2 uses separate headers for returned error Responses. Mirror only Standard Context writes to both. */
|
|
44
43
|
function responseHeaders(target) {
|
|
45
44
|
const { headers, errHeaders } = target;
|
|
46
45
|
if (!errHeaders) return headers;
|
|
@@ -71,7 +70,6 @@ function responseHeaders(target) {
|
|
|
71
70
|
};
|
|
72
71
|
return Object.assign(view, methods);
|
|
73
72
|
}
|
|
74
|
-
/** Map Standard Context response fields to the response that H3 sends. H3 sends the value the handler returns as the body. */
|
|
75
73
|
function preparedResponse(target) {
|
|
76
74
|
const headers = responseHeaders(target);
|
|
77
75
|
return {
|
|
@@ -94,10 +92,6 @@ function preparedResponse(target) {
|
|
|
94
92
|
}
|
|
95
93
|
};
|
|
96
94
|
}
|
|
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
95
|
var H3StandardProps = class {
|
|
102
96
|
vendor = "h3";
|
|
103
97
|
#event;
|
package/dist/internal/node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
1
|
+
import { a as resetPublicUrlAgentNames, i as registerPublicUrlAgentName, n as configuredPublicOrigins } from "../public-url-BCFhTiTM.js";
|
|
2
|
+
export { configuredPublicOrigins, registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
1
|
+
import { i as resetPublicUrlAgentNames, r as registerPublicUrlAgentName, t as configuredPublicOrigins } from "../public-url-DizC8CFs.js";
|
|
2
|
+
export { configuredPublicOrigins, registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
@@ -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) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
2
|
-
import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-
|
|
2
|
+
import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-CHYQYwDx.js";
|
|
3
3
|
export { asUnknownBoundary, hasRuntimeType, isRuntimeObject, isRuntimeResponse, runtimeErrorDiagnostics };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
//#region 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,7 +192,7 @@ 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
|
}
|
|
@@ -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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { $ as emitTraceEvent, ct as traceEventsToOpenTelemetryLogRecords, lt as traceEventsToOpenTelemetrySpans } from "../core-BfUEli_0.js";
|
|
2
|
+
import "../index-DsisbCNa.js";
|
|
3
|
+
//#region src/internal/trace-attributes.d.ts
|
|
4
|
+
export declare function isTraceContentAttributeKey(key: string): boolean;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { emitTraceEvent, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as traceEventsToOpenTelemetrySpans, g as traceEventsToOpenTelemetryLogRecords, s as emitTraceEvent, y as isTraceContentAttributeKey } from "../core-DpLK9dQt.js";
|
|
2
|
+
export { emitTraceEvent, isTraceContentAttributeKey, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
//#region ../internal/dist/operation-definition-
|
|
2
|
+
//#region ../internal/dist/operation-definition-C0NDEa7Q.d.ts
|
|
3
3
|
//#region src/operation-definition.d.ts
|
|
4
4
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
5
5
|
type OperationKind = "read" | "write" | "destructive";
|
|
@@ -29,6 +29,11 @@ interface OperationAccess {
|
|
|
29
29
|
*/
|
|
30
30
|
readonly sections: "all" | readonly string[];
|
|
31
31
|
readonly user?: OperationUser;
|
|
32
|
+
/**
|
|
33
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
34
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
35
|
+
*/
|
|
36
|
+
readonly via?: "console" | "cli";
|
|
32
37
|
}
|
|
33
38
|
interface OperationContext {
|
|
34
39
|
/** The checked Console access of the call. */
|
|
@@ -91,7 +96,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
91
96
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
92
97
|
input: StandardSchemaV1<unknown, Input>;
|
|
93
98
|
output?: StandardSchemaV1<unknown, Output>;
|
|
94
|
-
|
|
99
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
100
|
+
cli?: false | {
|
|
95
101
|
/** Defaults: namespace = section, command = verb. */
|
|
96
102
|
namespace?: string;
|
|
97
103
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
package/dist/operations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
2
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
3
|
-
//#region ../internal/dist/error-diagnostics-
|
|
3
|
+
//#region ../internal/dist/error-diagnostics-B11Jh1zF.js
|
|
4
4
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
5
5
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
6
6
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
@@ -26,7 +26,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
26
26
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
27
27
|
},
|
|
28
28
|
INTERNAL_R0022: {
|
|
29
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
29
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
30
30
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
31
31
|
},
|
|
32
32
|
INTERNAL_R0024: {
|
|
@@ -245,6 +245,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
245
245
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
246
246
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
247
247
|
},
|
|
248
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
249
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
250
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
251
|
+
},
|
|
248
252
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
249
253
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
250
254
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -10,6 +10,11 @@ interface PublicUrlConfig {
|
|
|
10
10
|
declare function resetPublicUrlAgentNames(): void;
|
|
11
11
|
/** Associate an evaluated Agent name with the identity used by build-time URL configuration. */
|
|
12
12
|
declare function registerPublicUrlAgentName(name: string, discoveredName: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* The origins of `vitehub({ publicUrl })`: the one origin, or the origin of each Agent of the function form. Empty when
|
|
15
|
+
* `publicUrl` is not set, such as in `vite dev` without a signed Console.
|
|
16
|
+
*/
|
|
17
|
+
declare function configuredPublicOrigins(): string[];
|
|
13
18
|
/**
|
|
14
19
|
* Resolve the public origin of this deployment.
|
|
15
20
|
*
|
|
@@ -31,4 +36,4 @@ declare function resolvePublicUrl(options?: {
|
|
|
31
36
|
*/
|
|
32
37
|
declare function consoleInvocationUrl(origin: string, agentName: string, invocationId: string): string;
|
|
33
38
|
//#endregion
|
|
34
|
-
export {
|
|
39
|
+
export { resetPublicUrlAgentNames as a, registerPublicUrlAgentName as i, configuredPublicOrigins as n, resolvePublicUrl as o, consoleInvocationUrl as r, PublicUrlConfig as t };
|
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
|
|
2
|
-
//#region src/route-segment.ts
|
|
3
|
-
const plainSegment = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
-
function encodeRouteSegment(value) {
|
|
5
|
-
if (plainSegment.test(value)) return value;
|
|
6
|
-
let encoded = "~";
|
|
7
|
-
for (let index = 0; index < value.length; index++) encoded += value.charCodeAt(index).toString(16).padStart(4, "0");
|
|
8
|
-
return encoded;
|
|
9
|
-
}
|
|
10
|
-
function decodeRouteSegment(segment) {
|
|
11
|
-
if (plainSegment.test(segment)) return segment;
|
|
12
|
-
if (!/^~(?:[0-9a-f]{4})+$/.test(segment)) return;
|
|
13
|
-
let value = "";
|
|
14
|
-
for (let index = 1; index < segment.length; index += 4) value += String.fromCharCode(Number.parseInt(segment.slice(index, index + 4), 16));
|
|
15
|
-
return encodeRouteSegment(value) === segment ? value : void 0;
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
2
|
//#region src/hosted-console.ts
|
|
19
3
|
/** The origin of the hosted Console. */
|
|
20
4
|
const hostedConsoleOrigin = "https://console.vitehub.dev";
|
|
@@ -85,6 +69,22 @@ function hostedConsoleUrl(projectUrl, path, consoleOrigin = hostedConsoleOrigin)
|
|
|
85
69
|
return url.href;
|
|
86
70
|
}
|
|
87
71
|
//#endregion
|
|
72
|
+
//#region src/route-segment.ts
|
|
73
|
+
const plainSegment = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
74
|
+
function encodeRouteSegment(value) {
|
|
75
|
+
if (plainSegment.test(value)) return value;
|
|
76
|
+
let encoded = "~";
|
|
77
|
+
for (let index = 0; index < value.length; index++) encoded += value.charCodeAt(index).toString(16).padStart(4, "0");
|
|
78
|
+
return encoded;
|
|
79
|
+
}
|
|
80
|
+
function decodeRouteSegment(segment) {
|
|
81
|
+
if (plainSegment.test(segment)) return segment;
|
|
82
|
+
if (!/^~(?:[0-9a-f]{4})+$/.test(segment)) return;
|
|
83
|
+
let value = "";
|
|
84
|
+
for (let index = 1; index < segment.length; index += 4) value += String.fromCharCode(Number.parseInt(segment.slice(index, index + 4), 16));
|
|
85
|
+
return encodeRouteSegment(value) === segment ? value : void 0;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
88
|
//#region src/public-url.ts
|
|
89
89
|
const publicUrlAgentNames = /* @__PURE__ */ new Map();
|
|
90
90
|
/** Replace aliases when a generated Agent registry is installed. */
|
|
@@ -103,6 +103,14 @@ function applicationBasePath() {
|
|
|
103
103
|
const segments = (typeof __VITEHUB_APP_BASE_URL__ === "undefined" ? "/" : __VITEHUB_APP_BASE_URL__).split("/").filter(Boolean);
|
|
104
104
|
return segments.length ? `/${segments.join("/")}` : "";
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* The origins of `vitehub({ publicUrl })`: the one origin, or the origin of each Agent of the function form. Empty when
|
|
108
|
+
* `publicUrl` is not set, such as in `vite dev` without a signed Console.
|
|
109
|
+
*/
|
|
110
|
+
function configuredPublicOrigins() {
|
|
111
|
+
const config = publicUrlConfig();
|
|
112
|
+
return config.url ? [config.url] : [...new Set(Object.values(config.agents ?? {}))];
|
|
113
|
+
}
|
|
106
114
|
function configuredAgentUrl(config, name) {
|
|
107
115
|
return config.agents && Object.hasOwn(config.agents, name) ? config.agents[name] : void 0;
|
|
108
116
|
}
|
|
@@ -137,4 +145,4 @@ function consoleInvocationUrl(origin, agentName, invocationId) {
|
|
|
137
145
|
return `${hostedConsoleOrigin}/open?project=${encodeURIComponent(project)}&path=${encodeURIComponent(path)}`;
|
|
138
146
|
}
|
|
139
147
|
//#endregion
|
|
140
|
-
export {
|
|
148
|
+
export { resolvePublicUrl as a, hostedConsoleOrigin as c, normalizeConsoleProjectUrl as d, resetPublicUrlAgentNames as i, hostedConsoleUrl as l, consoleInvocationUrl as n, decodeRouteSegment as o, registerPublicUrlAgentName as r, encodeRouteSegment as s, configuredPublicOrigins as t, normalizeConsolePath as u };
|