@vite-hub/workspace 0.0.4 → 0.1.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/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
|
@@ -0,0 +1,1112 @@
|
|
|
1
|
+
import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
+
import { i as decodeFile, o as isWorkspaceBytes } from "./path-CNAwN7pw.js";
|
|
3
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-A_8Kp-48.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
5
|
+
import { posix } from "node:path";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { Diagnostic } from "nostics";
|
|
8
|
+
import { sourceIgnores } from "@vite-hub/source";
|
|
9
|
+
//#region ../internal/src/abort.ts
|
|
10
|
+
/**
|
|
11
|
+
* Runs `task` and rejects as soon as `signal` aborts, without waiting for the task.
|
|
12
|
+
*
|
|
13
|
+
* The rejection is `signal.reason`. When the reason is absent, it is an `AbortError` with `message`.
|
|
14
|
+
* When `signal` is already aborted, `task` does not run. The task should stop its own work
|
|
15
|
+
* through the same signal.
|
|
16
|
+
*/
|
|
17
|
+
function abortable(signal, message, task) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
if (signal?.aborted) {
|
|
20
|
+
reject(abortReason(signal, message));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const onAbort = () => reject(abortReason(signal, message));
|
|
24
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
25
|
+
const settle = () => signal?.removeEventListener("abort", onAbort);
|
|
26
|
+
new Promise((resolveTask) => resolveTask(task())).then((value) => {
|
|
27
|
+
settle();
|
|
28
|
+
resolve(value);
|
|
29
|
+
}, (error) => {
|
|
30
|
+
settle();
|
|
31
|
+
reject(error);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function abortReason(signal, message) {
|
|
36
|
+
if (signal?.reason !== void 0) return signal.reason;
|
|
37
|
+
const error = internalErrorDiagnostics.INTERNAL_R0003({ message });
|
|
38
|
+
error.name = "AbortError";
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
const maximumHttpMaxResponseBytes = 26214400;
|
|
42
|
+
function primitiveRuntimeTag(value) {
|
|
43
|
+
return value !== null && value !== void 0 && Object(value) !== value ? Object.prototype.toString.call(value) : void 0;
|
|
44
|
+
}
|
|
45
|
+
const blobPrototype = Blob.prototype;
|
|
46
|
+
const blobSizeGetter = Object.getOwnPropertyDescriptor(blobPrototype, "size")?.get;
|
|
47
|
+
const blobTypeGetter = Object.getOwnPropertyDescriptor(blobPrototype, "type")?.get;
|
|
48
|
+
const blobSliceMethod = Object.getOwnPropertyDescriptor(blobPrototype, "slice")?.value;
|
|
49
|
+
function isBlobLike(value) {
|
|
50
|
+
if (value === null || typeof value !== "object" || !blobSizeGetter || !blobTypeGetter) return false;
|
|
51
|
+
try {
|
|
52
|
+
Reflect.apply(blobSizeGetter, value, []);
|
|
53
|
+
Reflect.apply(blobTypeGetter, value, []);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength")?.get;
|
|
60
|
+
function isArrayBuffer(value) {
|
|
61
|
+
try {
|
|
62
|
+
if (!arrayBufferByteLengthGetter) return false;
|
|
63
|
+
arrayBufferByteLengthGetter.call(value);
|
|
64
|
+
return true;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function normalizeForeignBlob(value) {
|
|
70
|
+
if (!blobSizeGetter || !blobTypeGetter || !blobSliceMethod) return void 0;
|
|
71
|
+
try {
|
|
72
|
+
const type = Reflect.apply(blobTypeGetter, value, []);
|
|
73
|
+
Reflect.apply(blobSizeGetter, value, []);
|
|
74
|
+
return Reflect.apply(blobSliceMethod, value, [
|
|
75
|
+
0,
|
|
76
|
+
void 0,
|
|
77
|
+
type
|
|
78
|
+
]);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const httpInterruptedMessage = "[vitehub] HTTP request was interrupted.";
|
|
84
|
+
var HttpStatusError = class HttpStatusError extends Diagnostic {
|
|
85
|
+
status;
|
|
86
|
+
constructor(status) {
|
|
87
|
+
super({
|
|
88
|
+
code: "INTERNAL_R0012",
|
|
89
|
+
docs: "https://vitehub.dev/docs/reference/diagnostics",
|
|
90
|
+
why: `[vitehub] HTTP request failed with status ${status}.`
|
|
91
|
+
}, HttpStatusError);
|
|
92
|
+
this.status = status;
|
|
93
|
+
this.name = "HttpStatusError";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
async function executeHttpRequest(definition, options = {}) {
|
|
97
|
+
const normalized = normalizeHttpRequest(definition);
|
|
98
|
+
const responseType = options.responseType || "json";
|
|
99
|
+
const { data, response } = await fetchWithRetry(normalized, responseType, options.schema, options.fetch ?? ((input, init) => fetch(input, init)), options.retryFetchError ?? (() => true), options.signal);
|
|
100
|
+
return {
|
|
101
|
+
data,
|
|
102
|
+
mediaType: response.headers.get("content-type") || void 0,
|
|
103
|
+
status: response.status,
|
|
104
|
+
summary: redactedHttpRequestSummary(normalized, responseType)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function fetchWithRetry(definition, responseType, schema, send, retryFetchError, signal) {
|
|
108
|
+
const attempts = definition.method === "GET" || definition.method === "HEAD" ? 2 : 1;
|
|
109
|
+
for (let attempt = 1;; attempt++) {
|
|
110
|
+
const result = await fetchOnce(definition, responseType, send, retryFetchError, signal);
|
|
111
|
+
if (result.failure) {
|
|
112
|
+
if (result.failure.retryable && attempt < attempts) continue;
|
|
113
|
+
throw result.failure.cause;
|
|
114
|
+
}
|
|
115
|
+
if (!schema) return result;
|
|
116
|
+
const { response } = result;
|
|
117
|
+
return await abortable(signal, httpInterruptedMessage, async () => ({
|
|
118
|
+
data: await parseStandardSchema(schema, result.data, "HTTP response"),
|
|
119
|
+
response
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sends one request and reads its body inside the request timeout.
|
|
125
|
+
* A timeout or a caller abort stops the attempt at once, aborts the fetch, and cancels the body.
|
|
126
|
+
*/
|
|
127
|
+
async function fetchOnce(definition, responseType, send, retryFetchError, signal) {
|
|
128
|
+
const controller = new AbortController();
|
|
129
|
+
const timeout = new AbortController();
|
|
130
|
+
const timedOut = { failure: {
|
|
131
|
+
cause: new DOMException("This operation was aborted", "AbortError"),
|
|
132
|
+
retryable: true
|
|
133
|
+
} };
|
|
134
|
+
const timer = setTimeout(() => timeout.abort(timedOut), definition.timeout);
|
|
135
|
+
const stop = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;
|
|
136
|
+
let response;
|
|
137
|
+
try {
|
|
138
|
+
return await abortable(stop, httpInterruptedMessage, async () => {
|
|
139
|
+
try {
|
|
140
|
+
const headers = new Headers(definition.headers);
|
|
141
|
+
applyCookies(headers, definition.cookies);
|
|
142
|
+
const body = serializeRequestBody(definition.body, headers);
|
|
143
|
+
response = await send(urlWithQuery(definition).toString(), {
|
|
144
|
+
body,
|
|
145
|
+
...body instanceof ReadableStream ? { duplex: "half" } : {},
|
|
146
|
+
headers,
|
|
147
|
+
method: definition.method,
|
|
148
|
+
signal: controller.signal
|
|
149
|
+
});
|
|
150
|
+
if (controller.signal.aborted) {
|
|
151
|
+
cancelResponseBody(response);
|
|
152
|
+
controller.signal.throwIfAborted();
|
|
153
|
+
}
|
|
154
|
+
} catch (cause) {
|
|
155
|
+
return { failure: {
|
|
156
|
+
cause,
|
|
157
|
+
retryable: retryFetchError(cause)
|
|
158
|
+
} };
|
|
159
|
+
}
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
const cause = new HttpStatusError(response.status);
|
|
162
|
+
cancelResponseBody(response);
|
|
163
|
+
return { failure: {
|
|
164
|
+
cause,
|
|
165
|
+
retryable: cause.status === 408 || cause.status === 429 || cause.status >= 500
|
|
166
|
+
} };
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
return {
|
|
170
|
+
data: await decodeResponse(response, responseType, definition.maxResponseBytes, controller.signal),
|
|
171
|
+
response
|
|
172
|
+
};
|
|
173
|
+
} catch (cause) {
|
|
174
|
+
return { failure: {
|
|
175
|
+
cause,
|
|
176
|
+
retryable: false
|
|
177
|
+
} };
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (response) cancelResponseBody(response);
|
|
182
|
+
if (error === timedOut) return timedOut;
|
|
183
|
+
throw error;
|
|
184
|
+
} finally {
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
controller.abort();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function cancelResponseBody(response) {
|
|
190
|
+
response.body?.cancel().catch(() => {});
|
|
191
|
+
}
|
|
192
|
+
function applyCookies(headers, cookies) {
|
|
193
|
+
if (!cookies || !Object.keys(cookies).length) return;
|
|
194
|
+
const value = Object.entries(cookies).map(([name, cookieValue]) => `${name}=${cookieValue}`).join("; ");
|
|
195
|
+
const existing = headers.get("cookie");
|
|
196
|
+
headers.set("cookie", existing ? `${existing}; ${value}` : value);
|
|
197
|
+
}
|
|
198
|
+
function serializeRequestBody(body, headers) {
|
|
199
|
+
if (body === void 0) return void 0;
|
|
200
|
+
if (isBlobLike(body) && !(body instanceof Blob)) {
|
|
201
|
+
const normalized = normalizeForeignBlob(body);
|
|
202
|
+
if (normalized) return normalized;
|
|
203
|
+
}
|
|
204
|
+
if (primitiveRuntimeTag(body) === "[object String]" || body instanceof Uint8Array || isArrayBuffer(body) || ArrayBuffer.isView(body) || body instanceof Blob || body instanceof FormData || body instanceof URLSearchParams || body instanceof ReadableStream) return body;
|
|
205
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
206
|
+
return JSON.stringify(body);
|
|
207
|
+
}
|
|
208
|
+
function urlWithQuery(definition) {
|
|
209
|
+
const url = new URL(definition.url);
|
|
210
|
+
if (!definition.query) return url;
|
|
211
|
+
for (const [key, value] of Object.entries(definition.query)) {
|
|
212
|
+
if (value === void 0) continue;
|
|
213
|
+
if (Array.isArray(value)) {
|
|
214
|
+
for (const item of value) if (item !== void 0) url.searchParams.append(key, queryValue(item));
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
url.searchParams.set(key, queryValue(value));
|
|
218
|
+
}
|
|
219
|
+
return url;
|
|
220
|
+
}
|
|
221
|
+
function queryValue(value) {
|
|
222
|
+
if (value === null) return "";
|
|
223
|
+
const tag = primitiveRuntimeTag(value);
|
|
224
|
+
if (tag === "[object String]" || tag === "[object Number]" || tag === "[object Boolean]" || tag === "[object BigInt]") return String(value);
|
|
225
|
+
return JSON.stringify(value);
|
|
226
|
+
}
|
|
227
|
+
async function decodeResponse(response, responseType, maxResponseBytes, signal) {
|
|
228
|
+
const bytes = await readResponseBytes(response, maxResponseBytes, signal);
|
|
229
|
+
if (responseType === "arrayBuffer") return bytes.slice().buffer;
|
|
230
|
+
if (responseType === "blob") return new Blob([bytes.slice()], { type: response.headers.get("content-type") || "" });
|
|
231
|
+
const text = new TextDecoder().decode(bytes);
|
|
232
|
+
if (responseType === "text") return text;
|
|
233
|
+
return text ? JSON.parse(text) : void 0;
|
|
234
|
+
}
|
|
235
|
+
async function readResponseBytes(response, maxResponseBytes, signal) {
|
|
236
|
+
const declaredLength = response.headers.get("content-length")?.trim();
|
|
237
|
+
if (response.body && !response.headers.has("content-encoding") && declaredLength && /^\d+$/.test(declaredLength) && BigInt(declaredLength) > BigInt(maxResponseBytes)) {
|
|
238
|
+
const error = responseSizeError(maxResponseBytes);
|
|
239
|
+
response.body.cancel(error).catch(() => {});
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
const body = response.body;
|
|
243
|
+
if (!body) return /* @__PURE__ */ new Uint8Array();
|
|
244
|
+
const reader = body.getReader();
|
|
245
|
+
const cancelReader = () => {
|
|
246
|
+
reader.cancel(signal.reason).catch(() => {});
|
|
247
|
+
};
|
|
248
|
+
signal.addEventListener("abort", cancelReader, { once: true });
|
|
249
|
+
const chunks = [];
|
|
250
|
+
let totalBytes = 0;
|
|
251
|
+
try {
|
|
252
|
+
while (true) {
|
|
253
|
+
const chunk = await reader.read();
|
|
254
|
+
if (chunk.done) break;
|
|
255
|
+
totalBytes += chunk.value.byteLength;
|
|
256
|
+
if (totalBytes > maxResponseBytes) {
|
|
257
|
+
const error = responseSizeError(maxResponseBytes);
|
|
258
|
+
reader.cancel(error).catch(() => {});
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
chunks.push(chunk.value);
|
|
262
|
+
}
|
|
263
|
+
} finally {
|
|
264
|
+
signal.removeEventListener("abort", cancelReader);
|
|
265
|
+
reader.releaseLock();
|
|
266
|
+
}
|
|
267
|
+
const bytes = new Uint8Array(totalBytes);
|
|
268
|
+
let offset = 0;
|
|
269
|
+
for (const chunk of chunks) {
|
|
270
|
+
bytes.set(chunk, offset);
|
|
271
|
+
offset += chunk.byteLength;
|
|
272
|
+
}
|
|
273
|
+
return bytes;
|
|
274
|
+
}
|
|
275
|
+
function responseSizeError(maxResponseBytes) {
|
|
276
|
+
return internalErrorDiagnostics.INTERNAL_R0004({ message: `[vitehub] HTTP response exceeds the configured ${maxResponseBytes}-byte limit.` });
|
|
277
|
+
}
|
|
278
|
+
function normalizeHttpRequest(definition) {
|
|
279
|
+
const method = ((Object.hasOwn(definition, "method") ? definition.method : void 0) || "GET").toUpperCase();
|
|
280
|
+
if (method !== "GET" && method !== "HEAD" && method !== "POST") throw internalErrorDiagnostics.INTERNAL_R0005({ message: `[vitehub] HTTP request method "${method}" is not supported. Use GET, HEAD, or POST.` });
|
|
281
|
+
const timeout = Object.hasOwn(definition, "timeout") ? definition.timeout : void 0;
|
|
282
|
+
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647)) throw internalErrorDiagnostics.INTERNAL_R0006({ message: "[vitehub] HTTP request timeout must be a positive finite number no greater than 2147483647." });
|
|
283
|
+
const maxResponseBytes = Object.hasOwn(definition, "maxResponseBytes") ? definition.maxResponseBytes : void 0;
|
|
284
|
+
if (maxResponseBytes !== void 0 && (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes <= 0 || maxResponseBytes > 26214400)) throw internalErrorDiagnostics.INTERNAL_R0007({ message: `[vitehub] HTTP request maxResponseBytes must be a positive safe integer no greater than ${maximumHttpMaxResponseBytes}.` });
|
|
285
|
+
return {
|
|
286
|
+
...definition,
|
|
287
|
+
maxResponseBytes: maxResponseBytes ?? 5242880,
|
|
288
|
+
method,
|
|
289
|
+
timeout: timeout ?? 3e4,
|
|
290
|
+
url: definition.url instanceof URL ? definition.url : new URL(definition.url)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async function parseStandardSchema(schema, value, label) {
|
|
294
|
+
const result = await schema["~standard"].validate(value);
|
|
295
|
+
if ("issues" in result && result.issues && result.issues.length > 0) throw internalErrorDiagnostics.INTERNAL_R0008({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
|
|
296
|
+
if (!("value" in result)) throw internalErrorDiagnostics.INTERNAL_R0009({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
|
|
297
|
+
return result.value;
|
|
298
|
+
}
|
|
299
|
+
function redactedHttpRequestSummary(definition, responseType) {
|
|
300
|
+
return {
|
|
301
|
+
cookies: definition.cookies && Object.keys(definition.cookies).length ? "redacted" : "none",
|
|
302
|
+
hasBody: definition.body !== void 0,
|
|
303
|
+
hasQuery: Boolean(definition.query && Object.keys(definition.query).length),
|
|
304
|
+
headers: definition.headers && Object.keys(definition.headers).length ? "redacted" : "none",
|
|
305
|
+
method: definition.method,
|
|
306
|
+
responseType,
|
|
307
|
+
url: `${definition.url.origin}${definition.url.pathname}`
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function formatIssues(issues) {
|
|
311
|
+
if (Array.isArray(issues)) return issues.map((issue) => primitiveRuntimeTag(issue) === "[object String]" ? String(issue) : JSON.stringify(issue)).join("; ");
|
|
312
|
+
return primitiveRuntimeTag(issues) === "[object String]" ? String(issues) : JSON.stringify(issues);
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/sources/live.ts
|
|
316
|
+
const liveSourcePaths = /* @__PURE__ */ new WeakMap();
|
|
317
|
+
function markLiveWorkspaceSource(source, paths) {
|
|
318
|
+
liveSourcePaths.set(source, paths);
|
|
319
|
+
return source;
|
|
320
|
+
}
|
|
321
|
+
function getLiveWorkspaceSourcePaths(source) {
|
|
322
|
+
return liveSourcePaths.get(source);
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/sources/request-json.ts
|
|
326
|
+
function requestJsonEqual(left, right) {
|
|
327
|
+
return JSON.stringify(sortJson(left)) === JSON.stringify(sortJson(right));
|
|
328
|
+
}
|
|
329
|
+
function sortJson(value) {
|
|
330
|
+
if (Array.isArray(value)) return value.map(sortJson);
|
|
331
|
+
if (!value || typeof value !== "object") return value;
|
|
332
|
+
const prototype = Object.getPrototypeOf(value);
|
|
333
|
+
if (prototype !== Object.prototype && prototype !== null) return value;
|
|
334
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, sortJson(item)]));
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/sources/request-metadata.ts
|
|
338
|
+
const requestSourceDescriptors = /* @__PURE__ */ new WeakMap();
|
|
339
|
+
const requestSourceExecutors = /* @__PURE__ */ new WeakMap();
|
|
340
|
+
const requestOnlySources = /* @__PURE__ */ new WeakSet();
|
|
341
|
+
function markWorkspaceSourceRequestDescriptor(source, descriptor, options = {}) {
|
|
342
|
+
requestSourceDescriptors.set(source, descriptor);
|
|
343
|
+
if (options.requestOnly) requestOnlySources.add(source);
|
|
344
|
+
return source;
|
|
345
|
+
}
|
|
346
|
+
function markWorkspaceSourceRequestExecutor(source, executor) {
|
|
347
|
+
requestSourceExecutors.set(source, executor);
|
|
348
|
+
return source;
|
|
349
|
+
}
|
|
350
|
+
function copyWorkspaceSourceRequestMetadata(source, target) {
|
|
351
|
+
const requestDescriptor = requestSourceDescriptors.get(source);
|
|
352
|
+
if (requestDescriptor) requestSourceDescriptors.set(target, requestDescriptor);
|
|
353
|
+
const requestExecutor = requestSourceExecutors.get(source);
|
|
354
|
+
if (requestExecutor) requestSourceExecutors.set(target, requestExecutor);
|
|
355
|
+
if (requestOnlySources.has(source)) requestOnlySources.add(target);
|
|
356
|
+
}
|
|
357
|
+
function getWorkspaceSourceRequestDescriptor(source) {
|
|
358
|
+
return requestSourceDescriptors.get(source);
|
|
359
|
+
}
|
|
360
|
+
function getWorkspaceSourceRequestExecutor(source) {
|
|
361
|
+
return requestSourceExecutors.get(source);
|
|
362
|
+
}
|
|
363
|
+
function isWorkspaceSourceRequestOnly(source) {
|
|
364
|
+
return requestOnlySources.has(source);
|
|
365
|
+
}
|
|
366
|
+
function assertWorkspaceSourceRequestDescriptorKey(sourceKey) {
|
|
367
|
+
const normalized = sourceKey.replace(/\\/g, "/");
|
|
368
|
+
if (!normalized || normalized.includes("/") || normalized === "." || normalized === ".." || normalized === ".git" || normalized === ".vitehub" || normalized.endsWith(".json")) throw workspaceError(`[vitehub] Workspace Source Request descriptor key must be a single safe file stem: ${sourceKey}.`);
|
|
369
|
+
}
|
|
370
|
+
function workspaceSourceRequestDescriptorPath(sourceKey) {
|
|
371
|
+
assertWorkspaceSourceRequestDescriptorKey(sourceKey);
|
|
372
|
+
return `.vitehub/sources/${sourceKey}.json`;
|
|
373
|
+
}
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/sources/fetch.ts
|
|
376
|
+
function fetch$1(input) {
|
|
377
|
+
if (typeof input === "function") return resolvableFetchSource(input);
|
|
378
|
+
return createFetchSource(input);
|
|
379
|
+
}
|
|
380
|
+
function createFetchSource(options) {
|
|
381
|
+
const callbackReceiver = options;
|
|
382
|
+
options = normalizeFetchSourceOptions(options);
|
|
383
|
+
const responseType = normalizePublicResponseType(options.responseType || "json");
|
|
384
|
+
const method = normalizeMethod(options.method);
|
|
385
|
+
assertRequestShape(options, method);
|
|
386
|
+
const workspacePath = normalizeFetchWorkspacePath(options);
|
|
387
|
+
const mountPath = workspacePath ? posix.dirname(workspacePath) === "." ? "" : posix.dirname(workspacePath) : "";
|
|
388
|
+
const key = workspacePath ? mountPath ? workspacePath.slice(mountPath.length + 1) : workspacePath : "";
|
|
389
|
+
const descriptor = createFetchRequestDescriptor(options, method, responseType, workspacePath);
|
|
390
|
+
const source = markWorkspaceSourceRequestExecutor(markWorkspaceSourceRequestDescriptor({
|
|
391
|
+
cache: options.cache ?? false,
|
|
392
|
+
fingerprint: {
|
|
393
|
+
body: descriptor.request?.body,
|
|
394
|
+
bodySchema: descriptor.request?.bodySchema,
|
|
395
|
+
credentials: descriptor.credentials,
|
|
396
|
+
method,
|
|
397
|
+
path: workspacePath,
|
|
398
|
+
query: descriptor.request?.query,
|
|
399
|
+
querySchema: descriptor.request?.querySchema,
|
|
400
|
+
responseType,
|
|
401
|
+
url: String(options.url)
|
|
402
|
+
},
|
|
403
|
+
materialize: options.materialize || (options.sync ? "none" : "lazy"),
|
|
404
|
+
mount: mountPath,
|
|
405
|
+
name: "fetch",
|
|
406
|
+
probeKeys: options.probeKeys || (key ? [key] : void 0),
|
|
407
|
+
sync: options.sync,
|
|
408
|
+
async getKeys() {
|
|
409
|
+
if (!workspacePath) return [];
|
|
410
|
+
return [key];
|
|
411
|
+
},
|
|
412
|
+
async getItem(sourcePath, ctx) {
|
|
413
|
+
if (!workspacePath) throw workspaceErrorDiagnostics.WORKSPACE_R0046({ message: "[vitehub] Request-only fetch source does not expose a default Source-Backed Path." });
|
|
414
|
+
if (sourcePath !== key) throw workspaceErrorDiagnostics.WORKSPACE_R0047({ message: `[vitehub] Fetch source item does not exist: ${sourcePath}.` });
|
|
415
|
+
const result = await executeHttpRequest({
|
|
416
|
+
...await defaultFetchSourceRequest(options, method, ctx, void 0, callbackReceiver),
|
|
417
|
+
method,
|
|
418
|
+
url: requestBaseUrl(options.url)
|
|
419
|
+
}, {
|
|
420
|
+
responseType,
|
|
421
|
+
signal: ctx.abortSignal
|
|
422
|
+
});
|
|
423
|
+
const transformed = options.transform ? await Reflect.apply(options.transform, callbackReceiver, [result.data]) : result.data;
|
|
424
|
+
return {
|
|
425
|
+
key,
|
|
426
|
+
path: key,
|
|
427
|
+
content: serializeFetchSourceContent(transformed, responseType),
|
|
428
|
+
mediaType: result.mediaType ?? mediaTypeFor(responseType),
|
|
429
|
+
metadata: {
|
|
430
|
+
request: result.summary,
|
|
431
|
+
status: result.status
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
},
|
|
435
|
+
async getMeta(sourcePath) {
|
|
436
|
+
if (!workspacePath) return void 0;
|
|
437
|
+
if (sourcePath !== key) return void 0;
|
|
438
|
+
return {
|
|
439
|
+
mediaType: mediaTypeFor(responseType),
|
|
440
|
+
request: {
|
|
441
|
+
method,
|
|
442
|
+
responseType,
|
|
443
|
+
url: redactedUrl(options.url)
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
}, descriptor, { requestOnly: !workspacePath }), async (input, ctx) => {
|
|
448
|
+
return await executeFetchSourceRequest(options, method, responseType, input, ctx, callbackReceiver);
|
|
449
|
+
});
|
|
450
|
+
return workspacePath ? markLiveWorkspaceSource(source, { [workspacePath]: key }) : source;
|
|
451
|
+
}
|
|
452
|
+
const fetchRuntimeOptionKeys = [
|
|
453
|
+
"cache",
|
|
454
|
+
"materialize",
|
|
455
|
+
"probeKeys",
|
|
456
|
+
"sync"
|
|
457
|
+
];
|
|
458
|
+
function normalizeFetchSourceOptions(options) {
|
|
459
|
+
const normalized = Object.create(Object.getPrototypeOf(options));
|
|
460
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(options))) {
|
|
461
|
+
if ("value" in descriptor) {
|
|
462
|
+
Object.defineProperty(normalized, key, descriptor);
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
Object.defineProperty(normalized, key, {
|
|
466
|
+
configurable: descriptor.configurable,
|
|
467
|
+
enumerable: descriptor.enumerable,
|
|
468
|
+
get: descriptor.get ? () => Reflect.get(options, key, options) : void 0,
|
|
469
|
+
set: descriptor.set ? (value) => Reflect.set(options, key, value, options) : void 0
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
for (const key of fetchRuntimeOptionKeys) if (!Object.hasOwn(options, key)) Object.defineProperty(normalized, key, {
|
|
473
|
+
configurable: true,
|
|
474
|
+
enumerable: true,
|
|
475
|
+
value: void 0,
|
|
476
|
+
writable: true
|
|
477
|
+
});
|
|
478
|
+
return normalized;
|
|
479
|
+
}
|
|
480
|
+
function resolvableFetchSource(resolve) {
|
|
481
|
+
return {
|
|
482
|
+
fingerprint: { sourceResolution: "fetch" },
|
|
483
|
+
materialize: "lazy",
|
|
484
|
+
name: "fetch",
|
|
485
|
+
async getKeys() {
|
|
486
|
+
return [];
|
|
487
|
+
},
|
|
488
|
+
async getItem(key) {
|
|
489
|
+
throw workspaceErrorDiagnostics.WORKSPACE_R0048({ message: `[vitehub] fetch() resolver did not resolve before reading ${JSON.stringify(key)}.` });
|
|
490
|
+
},
|
|
491
|
+
async getItems() {
|
|
492
|
+
return [];
|
|
493
|
+
},
|
|
494
|
+
async resolve(ctx) {
|
|
495
|
+
const options = await resolve(ctx);
|
|
496
|
+
return options ? createFetchSource(options) : false;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function normalizePublicResponseType(responseType) {
|
|
501
|
+
if (responseType !== "json" && responseType !== "text") throw workspaceErrorDiagnostics.WORKSPACE_R0049({ message: `[vitehub] fetch() responseType "${responseType}" is not supported in v1. Use json or text.` });
|
|
502
|
+
return responseType;
|
|
503
|
+
}
|
|
504
|
+
function normalizeMethod(method) {
|
|
505
|
+
const normalized = method === void 0 ? "GET" : typeof method === "string" ? method.toUpperCase() : "";
|
|
506
|
+
if (normalized !== "GET" && normalized !== "HEAD" && normalized !== "POST") {
|
|
507
|
+
const label = typeof method === "string" ? method : typeof method;
|
|
508
|
+
throw workspaceErrorDiagnostics.WORKSPACE_R0050({ message: `[vitehub] fetch() method "${label}" is not supported in v1. Use GET, HEAD, or POST.` });
|
|
509
|
+
}
|
|
510
|
+
return normalized;
|
|
511
|
+
}
|
|
512
|
+
function normalizeFetchWorkspacePath(options) {
|
|
513
|
+
return options.workspacePath ? normalizeSafeWorkspacePath(options.workspacePath, { allowEmpty: false }) : void 0;
|
|
514
|
+
}
|
|
515
|
+
function assertRequestShape(options, method) {
|
|
516
|
+
if ((options.query !== void 0 || urlHasQuery(options.url)) && options.querySchema !== void 0) throw workspaceErrorDiagnostics.WORKSPACE_R0051({ message: "[vitehub] fetch() accepts either query or querySchema, not both." });
|
|
517
|
+
if (options.body !== void 0 && options.bodySchema !== void 0) throw workspaceErrorDiagnostics.WORKSPACE_R0052({ message: "[vitehub] fetch() accepts either body or bodySchema, not both." });
|
|
518
|
+
if ((method === "GET" || method === "HEAD") && (options.body !== void 0 || options.bodySchema !== void 0)) throw workspaceErrorDiagnostics.WORKSPACE_R0053({ message: `[vitehub] fetch() ${method} requests cannot declare body or bodySchema.` });
|
|
519
|
+
}
|
|
520
|
+
function urlHasQuery(url) {
|
|
521
|
+
const parsed = url instanceof URL ? url : new URL(url);
|
|
522
|
+
return Boolean(parsed.search);
|
|
523
|
+
}
|
|
524
|
+
function createFetchRequestDescriptor(options, method, responseType, workspacePath) {
|
|
525
|
+
const request = {};
|
|
526
|
+
const query = concreteQueryFromOptions(options);
|
|
527
|
+
if (query && Object.keys(query).length) request.query = query;
|
|
528
|
+
if (options.querySchema) request.querySchema = schemaProjection(options.querySchema, "querySchema");
|
|
529
|
+
if (options.body !== void 0) request.body = options.body;
|
|
530
|
+
if (options.bodySchema) request.bodySchema = schemaProjection(options.bodySchema, "bodySchema");
|
|
531
|
+
return {
|
|
532
|
+
cache: options.cache,
|
|
533
|
+
credentials: descriptorCredentials(options),
|
|
534
|
+
method,
|
|
535
|
+
...Object.keys(request).length ? { request } : {},
|
|
536
|
+
responseType,
|
|
537
|
+
url: redactedUrl(options.url),
|
|
538
|
+
...workspacePath ? { workspacePath } : {}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function descriptorCredentials(options) {
|
|
542
|
+
if (typeof options.request === "function") return {
|
|
543
|
+
cookies: "dynamic",
|
|
544
|
+
headers: "dynamic"
|
|
545
|
+
};
|
|
546
|
+
const request = options.request;
|
|
547
|
+
const cookies = {
|
|
548
|
+
...options.cookies,
|
|
549
|
+
...request?.cookies
|
|
550
|
+
};
|
|
551
|
+
const headers = {
|
|
552
|
+
...options.headers,
|
|
553
|
+
...request?.headers
|
|
554
|
+
};
|
|
555
|
+
const credentials = {
|
|
556
|
+
...Object.keys(cookies).length ? { cookies: Object.keys(cookies).sort() } : {},
|
|
557
|
+
...Object.keys(headers).length ? { headers: Object.keys(headers).sort() } : {}
|
|
558
|
+
};
|
|
559
|
+
return Object.keys(credentials).length ? credentials : void 0;
|
|
560
|
+
}
|
|
561
|
+
function schemaProjection(schema, option) {
|
|
562
|
+
const project = schema["~standard"].jsonSchema?.input;
|
|
563
|
+
if (typeof project !== "function") throw workspaceErrorDiagnostics.WORKSPACE_R0054({ message: `[vitehub] fetch() ${option} must expose a Standard JSON Schema-compatible input projection.` });
|
|
564
|
+
return project({ target: "draft-2020-12" });
|
|
565
|
+
}
|
|
566
|
+
function concreteQueryFromOptions(options) {
|
|
567
|
+
const query = queryFromUrl(options.url instanceof URL ? options.url : new URL(options.url));
|
|
568
|
+
return query || options.query ? {
|
|
569
|
+
...query,
|
|
570
|
+
...options.query
|
|
571
|
+
} : void 0;
|
|
572
|
+
}
|
|
573
|
+
async function defaultFetchSourceRequest(options, method, ctx, overrides = {}, callbackReceiver = options) {
|
|
574
|
+
const defaultQuery = overrides.query !== void 0 ? void 0 : options.query !== void 0 || concreteQueryFromOptions(options) ? concreteQueryFromOptions(options) : options.querySchema ? await parseStandardSchema(options.querySchema, {}, "fetch() query default") : void 0;
|
|
575
|
+
const defaultBody = overrides.body !== void 0 ? void 0 : options.body !== void 0 ? options.body : options.bodySchema ? await parseStandardSchema(options.bodySchema, {}, "fetch() body default") : void 0;
|
|
576
|
+
const query = overrides.query ?? defaultQuery;
|
|
577
|
+
const body = typeof overrides.body === "undefined" ? defaultBody : overrides.body;
|
|
578
|
+
const context = sourceRequestContext(options, method, {
|
|
579
|
+
body,
|
|
580
|
+
query
|
|
581
|
+
}, ctx);
|
|
582
|
+
const additions = typeof options.request === "function" ? await Reflect.apply(options.request, callbackReceiver, [context]) : options.request;
|
|
583
|
+
return {
|
|
584
|
+
body,
|
|
585
|
+
cookies: {
|
|
586
|
+
...options.cookies,
|
|
587
|
+
...additions?.cookies
|
|
588
|
+
},
|
|
589
|
+
headers: {
|
|
590
|
+
...options.headers,
|
|
591
|
+
...additions?.headers
|
|
592
|
+
},
|
|
593
|
+
method,
|
|
594
|
+
maxResponseBytes: additions?.maxResponseBytes ?? options.maxResponseBytes,
|
|
595
|
+
query,
|
|
596
|
+
timeout: additions?.timeout ?? options.timeout
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
function sourceRequestContext(options, method, request, ctx) {
|
|
600
|
+
return {
|
|
601
|
+
request: {
|
|
602
|
+
body: request.body,
|
|
603
|
+
hasBody: typeof request.body !== "undefined",
|
|
604
|
+
hasQuery: Boolean(request.query && Object.keys(request.query).length),
|
|
605
|
+
method,
|
|
606
|
+
query: request.query,
|
|
607
|
+
url: redactedUrl(options.url)
|
|
608
|
+
},
|
|
609
|
+
selectedWorkspaceScope: ctx.selectedWorkspaceScope,
|
|
610
|
+
source: { key: ctx.source },
|
|
611
|
+
workspace: { name: ctx.workspace }
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
async function executeFetchSourceRequest(options, method, responseType, input, ctx, callbackReceiver = options) {
|
|
615
|
+
if (input.method !== method) throw workspaceErrorDiagnostics.WORKSPACE_R0055({ message: `[vitehub] Source request method ${input.method} does not match declared method ${method}.` });
|
|
616
|
+
const query = await validateFetchRequestQuery(options, input.url);
|
|
617
|
+
const result = await executeHttpRequest({
|
|
618
|
+
...await defaultFetchSourceRequest(options, method, ctx, {
|
|
619
|
+
body: await validateFetchRequestBody(options, input.body),
|
|
620
|
+
query
|
|
621
|
+
}, callbackReceiver),
|
|
622
|
+
method,
|
|
623
|
+
url: requestBaseUrl(options.url)
|
|
624
|
+
}, {
|
|
625
|
+
responseType,
|
|
626
|
+
signal: ctx.abortSignal
|
|
627
|
+
});
|
|
628
|
+
return {
|
|
629
|
+
content: serializeFetchSourceContent(options.transform ? await Reflect.apply(options.transform, callbackReceiver, [result.data]) : result.data, responseType),
|
|
630
|
+
mediaType: result.mediaType ?? mediaTypeFor(responseType),
|
|
631
|
+
metadata: {
|
|
632
|
+
request: result.summary,
|
|
633
|
+
status: result.status
|
|
634
|
+
},
|
|
635
|
+
status: result.status
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
async function validateFetchRequestQuery(options, inputUrl) {
|
|
639
|
+
const declared = requestBaseUrl(options.url);
|
|
640
|
+
const requested = new URL(inputUrl);
|
|
641
|
+
if (requested.origin !== declared.origin || requested.pathname !== declared.pathname) throw workspaceErrorDiagnostics.WORKSPACE_R0056({ message: "[vitehub] Source request URL does not match the declared Source target." });
|
|
642
|
+
const requestedQuery = queryFromUrl(requested);
|
|
643
|
+
if (options.querySchema) return await parseStandardSchema(options.querySchema, requestedQuery ?? {}, "HTTP request query");
|
|
644
|
+
const expectedQuery = concreteQueryFromOptions(options);
|
|
645
|
+
if (!requestJsonEqual(requestedQuery || {}, serializedQuery(expectedQuery) || {})) throw workspaceErrorDiagnostics.WORKSPACE_R0057({ message: "[vitehub] Source request query does not match the declared Source request shape." });
|
|
646
|
+
return expectedQuery;
|
|
647
|
+
}
|
|
648
|
+
async function validateFetchRequestBody(options, body) {
|
|
649
|
+
if (options.bodySchema) return await parseStandardSchema(options.bodySchema, typeof body === "undefined" ? {} : body, "HTTP request body");
|
|
650
|
+
if (typeof options.body !== "undefined") {
|
|
651
|
+
if (typeof body !== "undefined" && !requestJsonEqual(body, options.body)) throw workspaceErrorDiagnostics.WORKSPACE_R0058({ message: "[vitehub] Source request body does not match the declared Source request shape." });
|
|
652
|
+
return options.body;
|
|
653
|
+
}
|
|
654
|
+
if (typeof body !== "undefined") throw workspaceErrorDiagnostics.WORKSPACE_R0059({ message: "[vitehub] Source request does not declare a body." });
|
|
655
|
+
}
|
|
656
|
+
function requestBaseUrl(url) {
|
|
657
|
+
const parsed = url instanceof URL ? new URL(url) : new URL(url);
|
|
658
|
+
parsed.search = "";
|
|
659
|
+
parsed.hash = "";
|
|
660
|
+
return parsed;
|
|
661
|
+
}
|
|
662
|
+
function queryFromUrl(url) {
|
|
663
|
+
const query = Object.fromEntries([...new Set(url.searchParams.keys())].map((key) => {
|
|
664
|
+
const values = url.searchParams.getAll(key);
|
|
665
|
+
return [key, values.length > 1 ? values : values[0]];
|
|
666
|
+
}));
|
|
667
|
+
return Object.keys(query).length ? query : void 0;
|
|
668
|
+
}
|
|
669
|
+
function serializedQuery(query) {
|
|
670
|
+
if (!query) return void 0;
|
|
671
|
+
const params = new URLSearchParams();
|
|
672
|
+
for (const [key, value] of Object.entries(query)) {
|
|
673
|
+
const values = Array.isArray(value) ? value : [value];
|
|
674
|
+
for (const item of values) params.append(key, String(item));
|
|
675
|
+
}
|
|
676
|
+
return queryFromUrl(new URL(`https://vitehub.local/?${params}`));
|
|
677
|
+
}
|
|
678
|
+
function serializeFetchSourceContent(value, responseType) {
|
|
679
|
+
if (isWorkspaceBytes(value)) return value instanceof Uint8Array ? value : Uint8Array.from(value);
|
|
680
|
+
if (responseType === "json") return JSON.stringify(value, null, 2) ?? "null";
|
|
681
|
+
if (typeof value === "string") return value;
|
|
682
|
+
return typeof value === "undefined" ? "" : String(value);
|
|
683
|
+
}
|
|
684
|
+
function mediaTypeFor(responseType) {
|
|
685
|
+
return responseType === "json" ? "application/json" : "text/plain";
|
|
686
|
+
}
|
|
687
|
+
function redactedUrl(url) {
|
|
688
|
+
const parsed = url instanceof URL ? url : new URL(url);
|
|
689
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
690
|
+
}
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/sources/github-ignore.ts
|
|
693
|
+
function resolveGitHubIgnore(ignore) {
|
|
694
|
+
if (ignore === false) return;
|
|
695
|
+
if (ignore === void 0) return [...sourceIgnores.defaults];
|
|
696
|
+
const single = runtimeString(ignore);
|
|
697
|
+
if (single !== void 0) return [...sourceIgnores.defaults, single];
|
|
698
|
+
if (!Array.isArray(ignore)) throw invalidGitHubIgnore();
|
|
699
|
+
const parsed = [];
|
|
700
|
+
for (const value of ignore) {
|
|
701
|
+
const item = runtimeString(value);
|
|
702
|
+
if (item === void 0) throw invalidGitHubIgnore();
|
|
703
|
+
parsed.push(item);
|
|
704
|
+
}
|
|
705
|
+
return [...sourceIgnores.defaults, ...parsed];
|
|
706
|
+
}
|
|
707
|
+
function runtimeString(value) {
|
|
708
|
+
return Object.prototype.toString.call(value) === "[object String]" ? String(value) : void 0;
|
|
709
|
+
}
|
|
710
|
+
function invalidGitHubIgnore() {
|
|
711
|
+
return workspaceError("[vitehub] GitHub Source ignore must be false, a string, or an array of strings.");
|
|
712
|
+
}
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/sources/preparation.ts
|
|
715
|
+
const revisionResolutionByContext = /* @__PURE__ */ new WeakMap();
|
|
716
|
+
async function prepareWorkspaceSource(source, ctx, options = {}) {
|
|
717
|
+
if (options.refreshRevision) {
|
|
718
|
+
revisionResolutionByContext.delete(ctx);
|
|
719
|
+
ctx.revision = void 0;
|
|
720
|
+
}
|
|
721
|
+
let revisionResolution = revisionResolutionByContext.get(ctx);
|
|
722
|
+
if (!revisionResolution) {
|
|
723
|
+
revisionResolution = ctx.revision ? Promise.resolve() : (async () => {
|
|
724
|
+
const revision = await source.resolveRevision?.(ctx);
|
|
725
|
+
if (revision) ctx.revision = revision;
|
|
726
|
+
})();
|
|
727
|
+
revisionResolutionByContext.set(ctx, revisionResolution);
|
|
728
|
+
}
|
|
729
|
+
await revisionResolution;
|
|
730
|
+
await source.prepare?.(ctx);
|
|
731
|
+
}
|
|
732
|
+
//#endregion
|
|
733
|
+
//#region src/sources/runtime-options.ts
|
|
734
|
+
function ownSourceOption(options, key) {
|
|
735
|
+
return Object.hasOwn(options, key) ? options[key] : void 0;
|
|
736
|
+
}
|
|
737
|
+
function withWorkspaceRuntimeOptions(source, options) {
|
|
738
|
+
return {
|
|
739
|
+
...source,
|
|
740
|
+
cache: ownSourceOption(options, "cache"),
|
|
741
|
+
materialize: ownSourceOption(options, "materialize"),
|
|
742
|
+
mount: ownSourceOption(options, "mount"),
|
|
743
|
+
sync: ownSourceOption(options, "sync"),
|
|
744
|
+
validate: ownSourceOption(options, "validate")
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/sources/config.ts
|
|
749
|
+
function copyWorkspaceSourceMetadata(source, target) {
|
|
750
|
+
const livePaths = getLiveWorkspaceSourcePaths(source);
|
|
751
|
+
if (livePaths) markLiveWorkspaceSource(target, livePaths);
|
|
752
|
+
copyWorkspaceSourceRequestMetadata(source, target);
|
|
753
|
+
return target;
|
|
754
|
+
}
|
|
755
|
+
function createSourceContext(definition, source, store, options = {}) {
|
|
756
|
+
return {
|
|
757
|
+
abortSignal: options.abortSignal,
|
|
758
|
+
mountPath: source?.mountPath,
|
|
759
|
+
rootDir: definition.rootDir || process.cwd(),
|
|
760
|
+
selectedWorkspaceScope: options.selectedWorkspaceScope,
|
|
761
|
+
source: source?.key,
|
|
762
|
+
sourceRootDir: definition.sourceRootDir,
|
|
763
|
+
workspace: definition.name,
|
|
764
|
+
workspaceFiles: store ? createSourceContextWorkspaceFiles(store) : void 0
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function createSourceContextWorkspaceFiles(store) {
|
|
768
|
+
async function readFile(path, options) {
|
|
769
|
+
const workspacePath = normalizeSafeWorkspacePath(path);
|
|
770
|
+
const file = await store.readFile(workspacePath);
|
|
771
|
+
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
772
|
+
return decodeFile(file.content, options);
|
|
773
|
+
}
|
|
774
|
+
async function stat(path) {
|
|
775
|
+
return await store.stat(normalizeSafeWorkspacePath(path, { allowEmpty: true }));
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
readFile,
|
|
779
|
+
stat,
|
|
780
|
+
async exists(path) {
|
|
781
|
+
return Boolean(await stat(path));
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function normalizeWorkspaceSources(sources) {
|
|
786
|
+
if (!sources) return [];
|
|
787
|
+
return Object.entries(sources).map(([key, source]) => normalizeWorkspaceSource(key, source)).sort((left, right) => right.mountPath.length - left.mountPath.length || left.key.localeCompare(right.key));
|
|
788
|
+
}
|
|
789
|
+
function normalizeWorkspaceSource(key, input) {
|
|
790
|
+
const source = toWorkspaceSource(input);
|
|
791
|
+
const mount = normalizeSourceMount(source);
|
|
792
|
+
const cache = ownSourceOption(mount, "cache") ?? normalizeSourceCache(source) ?? false;
|
|
793
|
+
const sync = normalizeSourceSync(ownSourceOption(source, "sync"));
|
|
794
|
+
const mountPath = typeof ownSourceOption(mount, "path") === "string" ? ownSourceOption(mount, "path") : defaultSourceMountPath(key, source);
|
|
795
|
+
const requestDescriptor = getWorkspaceSourceRequestDescriptor(source);
|
|
796
|
+
if (requestDescriptor) assertWorkspaceSourceRequestDescriptorKey(key);
|
|
797
|
+
return {
|
|
798
|
+
key,
|
|
799
|
+
source,
|
|
800
|
+
mountPath: normalizeSafeWorkspacePath(mountPath, { allowEmpty: true }),
|
|
801
|
+
materialize: ownSourceOption(mount, "materialize") || ownSourceOption(source, "materialize") || (cache ? "lazy" : sync ? "none" : "build"),
|
|
802
|
+
cache,
|
|
803
|
+
sync,
|
|
804
|
+
validate: ownSourceOption(mount, "validate") ?? ownSourceOption(source, "validate") ?? false,
|
|
805
|
+
livePaths: getLiveWorkspaceSourcePaths(source),
|
|
806
|
+
...ownSourceOption(source, "probeKeys")?.length ? { probeKeys: ownSourceOption(source, "probeKeys") } : {},
|
|
807
|
+
readonly: true,
|
|
808
|
+
requestDescriptor,
|
|
809
|
+
requestOnly: isWorkspaceSourceRequestOnly(source)
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
function normalizeWorkspaceSourcesMetadata(sources) {
|
|
813
|
+
return normalizeWorkspaceSources(sources).map(toWorkspaceSourceMetadata);
|
|
814
|
+
}
|
|
815
|
+
function normalizeWorkspaceSourceMetadata(key, input) {
|
|
816
|
+
return toWorkspaceSourceMetadata(normalizeWorkspaceSource(key, input));
|
|
817
|
+
}
|
|
818
|
+
function workspaceSourceGrantPaths(key, input) {
|
|
819
|
+
const source = normalizeWorkspaceSourceMetadata(key, input);
|
|
820
|
+
const descriptorPath = safeWorkspaceSourceRequestDescriptorPath(key);
|
|
821
|
+
if (source.requestOnly) {
|
|
822
|
+
if (!descriptorPath) throw workspaceErrorDiagnostics.WORKSPACE_C0003({ message: `[vitehub] Workspace Scope source grant "${key}" is request-only without a Source Request descriptor.` });
|
|
823
|
+
return [descriptorPath];
|
|
824
|
+
}
|
|
825
|
+
const probePaths = source.probeKeys?.map((sourcePath) => joinSourcePath(source.mountPath, sourcePath)).filter(Boolean) || [];
|
|
826
|
+
const paths = probePaths.length ? probePaths : source.mountPath ? [source.mountPath] : [];
|
|
827
|
+
if (!paths.length) throw workspaceErrorDiagnostics.WORKSPACE_C0004({ message: `[vitehub] Workspace Scope source grant "${key}" is root-mounted; grant explicit paths instead.` });
|
|
828
|
+
return descriptorPath ? [...paths, descriptorPath] : paths;
|
|
829
|
+
}
|
|
830
|
+
function toWorkspaceSourceMetadata(source) {
|
|
831
|
+
return {
|
|
832
|
+
cache: source.cache,
|
|
833
|
+
key: source.key,
|
|
834
|
+
materialize: source.materialize,
|
|
835
|
+
mountPath: source.mountPath,
|
|
836
|
+
...source.probeKeys?.length ? { probeKeys: source.probeKeys } : {},
|
|
837
|
+
requestOnly: source.requestOnly,
|
|
838
|
+
source: source.source,
|
|
839
|
+
sync: source.sync
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function safeWorkspaceSourceRequestDescriptorPath(key) {
|
|
843
|
+
try {
|
|
844
|
+
return workspaceSourceRequestDescriptorPath(key);
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function joinSourcePath(mountPath, sourcePath) {
|
|
850
|
+
return [mountPath, sourcePath].filter(Boolean).join("/");
|
|
851
|
+
}
|
|
852
|
+
function sourceMountContainsPath(source, workspacePath) {
|
|
853
|
+
return workspacePath === source.mountPath || !!source.mountPath && workspacePath.startsWith(`${source.mountPath}/`);
|
|
854
|
+
}
|
|
855
|
+
function sourceMountIntersectsPath(source, workspacePath) {
|
|
856
|
+
return !workspacePath || !source.mountPath || sourceMountContainsPath(source, workspacePath) || source.mountPath.startsWith(`${workspacePath}/`);
|
|
857
|
+
}
|
|
858
|
+
function normalizeSourceMount(source) {
|
|
859
|
+
const mount = ownSourceOption(source, "mount");
|
|
860
|
+
if (typeof mount === "string") return { path: mount };
|
|
861
|
+
return mount || {};
|
|
862
|
+
}
|
|
863
|
+
function normalizeSourceCache(source) {
|
|
864
|
+
const cache = ownSourceOption(source, "cache");
|
|
865
|
+
if (cache === false) return false;
|
|
866
|
+
if (cache) {
|
|
867
|
+
const normalized = {};
|
|
868
|
+
if (Object.hasOwn(cache, "maxAge")) normalized.maxAge = cache.maxAge;
|
|
869
|
+
return normalized;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function normalizeSourceSync(sync) {
|
|
873
|
+
if (!sync) return false;
|
|
874
|
+
if (sync === true) return { stale: "keep" };
|
|
875
|
+
return {
|
|
876
|
+
concurrency: ownSourceOption(sync, "concurrency"),
|
|
877
|
+
stale: ownSourceOption(sync, "stale") || "keep"
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
function toWorkspaceSource(input) {
|
|
881
|
+
if (typeof input === "string") return createInferredWorkspaceSource("file", input);
|
|
882
|
+
if (isExplicitSourceBinding(input)) return applyWorkspaceBinding(toWorkspaceSource(input.source), input);
|
|
883
|
+
const inferred = inferWorkspaceSource(input);
|
|
884
|
+
if (inferred !== input) return applyWorkspaceBinding(inferred, input);
|
|
885
|
+
return input;
|
|
886
|
+
}
|
|
887
|
+
function inferWorkspaceSource(input) {
|
|
888
|
+
if (!isPlainRecord(input)) return input;
|
|
889
|
+
if (hasSourceMethods(input)) return input;
|
|
890
|
+
const providerFamilies = [];
|
|
891
|
+
if (hasOwn(input, "repo")) providerFamilies.push("github");
|
|
892
|
+
if (hasOwn(input, "url")) providerFamilies.push("fetch");
|
|
893
|
+
if (hasOwn(input, "server")) providerFamilies.push("mcpResources");
|
|
894
|
+
if (providerFamilies.length > 1) throw ambiguousSourceConfiguration(providerFamilies);
|
|
895
|
+
if (providerFamilies[0]) {
|
|
896
|
+
if (providerFamilies[0] === "github" && (hasOwn(input, "path") || hasOwn(input, "workspacePath") || hasOwn(input, "content"))) throw ambiguousSourceConfiguration(["github", "file"]);
|
|
897
|
+
if (providerFamilies[0] === "fetch") return createInferredFetchSource(input);
|
|
898
|
+
return createInferredWorkspaceSource(providerFamilies[0], input);
|
|
899
|
+
}
|
|
900
|
+
const localFamilies = [];
|
|
901
|
+
if (hasOwn(input, "include")) localFamilies.push("glob");
|
|
902
|
+
if (hasOwn(input, "path") || hasOwn(input, "workspacePath") || hasOwn(input, "content")) localFamilies.push("file");
|
|
903
|
+
if (localFamilies.length === 0) return input;
|
|
904
|
+
if (localFamilies.length > 1) throw ambiguousSourceConfiguration(localFamilies);
|
|
905
|
+
const family = localFamilies[0];
|
|
906
|
+
if (family) return createInferredWorkspaceSource(family, input);
|
|
907
|
+
return input;
|
|
908
|
+
}
|
|
909
|
+
function ambiguousSourceConfiguration(families) {
|
|
910
|
+
return workspaceErrorDiagnostics.WORKSPACE_C0005({ message: `[vitehub] Workspace source configuration is ambiguous. Matched ${families.join(", ")}. A { source: ... } wrapper or custom(...) call makes the source kind explicit.` });
|
|
911
|
+
}
|
|
912
|
+
function createInferredFetchSource(input) {
|
|
913
|
+
if (!isPlainRecord(input)) return fetch$1(input);
|
|
914
|
+
const record = input;
|
|
915
|
+
const workspacePath = typeof record.workspacePath === "string" ? record.workspacePath : inferFetchWorkspacePath(record);
|
|
916
|
+
return fetch$1({
|
|
917
|
+
...input,
|
|
918
|
+
workspacePath
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
function createInferredWorkspaceSource(family, input) {
|
|
922
|
+
let sourcePromise;
|
|
923
|
+
const livePaths = inferredLivePaths(family, input);
|
|
924
|
+
async function loadSource() {
|
|
925
|
+
sourcePromise ||= loadInferredWorkspaceSource(family, input);
|
|
926
|
+
return await sourcePromise;
|
|
927
|
+
}
|
|
928
|
+
const source = {
|
|
929
|
+
...inferredSourceDefaults(family, input),
|
|
930
|
+
name: family,
|
|
931
|
+
fingerprint: {
|
|
932
|
+
inferredSource: family,
|
|
933
|
+
options: inferredSourceFingerprintOptions(family, input)
|
|
934
|
+
},
|
|
935
|
+
async prepare(ctx) {
|
|
936
|
+
const loaded = await loadSource();
|
|
937
|
+
await prepareWorkspaceSource(loaded, ctx);
|
|
938
|
+
copyLivePaths(livePaths, getLiveWorkspaceSourcePaths(loaded));
|
|
939
|
+
},
|
|
940
|
+
async getKeys(ctx) {
|
|
941
|
+
return await (await loadSource()).getKeys(ctx);
|
|
942
|
+
},
|
|
943
|
+
async getItem(key, ctx) {
|
|
944
|
+
return await (await loadSource()).getItem(key, ctx);
|
|
945
|
+
},
|
|
946
|
+
async getItems(ctx) {
|
|
947
|
+
const source = await loadSource();
|
|
948
|
+
if (source.getItems) return await source.getItems(ctx);
|
|
949
|
+
return await Promise.all((await source.getKeys(ctx)).map(async (key) => {
|
|
950
|
+
const [item, metadata] = await Promise.all([source.getItem(key, ctx), source.getMeta?.(key, ctx)]);
|
|
951
|
+
return metadata ? {
|
|
952
|
+
...item,
|
|
953
|
+
metadata: {
|
|
954
|
+
...metadata,
|
|
955
|
+
...item.metadata
|
|
956
|
+
}
|
|
957
|
+
} : item;
|
|
958
|
+
}));
|
|
959
|
+
},
|
|
960
|
+
async getMeta(key, ctx) {
|
|
961
|
+
return await (await loadSource()).getMeta?.(key, ctx);
|
|
962
|
+
},
|
|
963
|
+
async resolveRevision(ctx) {
|
|
964
|
+
return await (await loadSource()).resolveRevision?.(ctx);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
return livePaths ? markLiveWorkspaceSource(source, livePaths) : source;
|
|
968
|
+
}
|
|
969
|
+
function inferredSourceFingerprintOptions(family, input) {
|
|
970
|
+
if (family === "file" && isPlainRecord(input)) {
|
|
971
|
+
const options = input;
|
|
972
|
+
if (hasOwn(options, "content") && isWorkspaceBytes(options.content)) return {
|
|
973
|
+
...options,
|
|
974
|
+
get content() {
|
|
975
|
+
const content = options.content;
|
|
976
|
+
return isWorkspaceBytes(content) ? { sha256: createHash("sha256").update(content).digest("hex") } : content;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
if (family !== "github" || !isPlainRecord(input)) return input;
|
|
981
|
+
return {
|
|
982
|
+
...input,
|
|
983
|
+
ignore: resolveGitHubIgnore(input.ignore)
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
async function loadInferredWorkspaceSource(family, input) {
|
|
987
|
+
if (family === "fetch" && isPlainRecord(input)) return createInferredFetchSource(input);
|
|
988
|
+
if (family === "fetch") return createInferredFetchSource(input);
|
|
989
|
+
if (family === "file") return (await import("./file-C0_aPWSS.js").then((n) => n.n)).file(input);
|
|
990
|
+
if (family === "github") return (await import("./github-CPxHtFB7.js").then((n) => n.n)).github(input);
|
|
991
|
+
if (family === "glob") return (await import("./glob--XcLlcml.js").then((n) => n.n)).glob(input);
|
|
992
|
+
return (await import("./mcp-resources-BREFCmtn.js").then((n) => n.n)).mcpResources(input);
|
|
993
|
+
}
|
|
994
|
+
function inferredSourceDefaults(family, input) {
|
|
995
|
+
if (!isPlainRecord(input)) return family === "file" ? {
|
|
996
|
+
mount: "",
|
|
997
|
+
probeKeys: [inferredFileSourceKey(input)]
|
|
998
|
+
} : {};
|
|
999
|
+
if (family === "file") {
|
|
1000
|
+
const declaredMount = ownSourceOption(input, "mount");
|
|
1001
|
+
return copySourceRuntimeOptions(input, {
|
|
1002
|
+
mount: typeof declaredMount === "object" && declaredMount && !Object.hasOwn(declaredMount, "path") ? {
|
|
1003
|
+
...declaredMount,
|
|
1004
|
+
path: ""
|
|
1005
|
+
} : declaredMount ?? "",
|
|
1006
|
+
probeKeys: [inferredFileSourceKey(input)]
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
if (family === "fetch") {
|
|
1010
|
+
const mountPath = dirname$1(inferFetchWorkspacePath(input));
|
|
1011
|
+
return copySourceRuntimeOptions(input, {
|
|
1012
|
+
cache: ownSourceOption(input, "cache") ?? false,
|
|
1013
|
+
materialize: ownSourceOption(input, "materialize") || (ownSourceOption(input, "sync") ? "none" : "lazy"),
|
|
1014
|
+
mount: mountPath
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
if (family === "github") return copySourceRuntimeOptions(input);
|
|
1018
|
+
if (family === "mcpResources") return copySourceRuntimeOptions(input, { materialize: ownSourceOption(input, "materialize") || (ownSourceOption(input, "sync") ? "none" : "lazy") });
|
|
1019
|
+
return copySourceRuntimeOptions(input);
|
|
1020
|
+
}
|
|
1021
|
+
function copySourceRuntimeOptions(input, defaults = {}) {
|
|
1022
|
+
return {
|
|
1023
|
+
...defaults,
|
|
1024
|
+
cache: ownSourceOption(input, "cache") ?? defaults.cache,
|
|
1025
|
+
materialize: ownSourceOption(input, "materialize") ?? defaults.materialize,
|
|
1026
|
+
mount: ownSourceOption(input, "mount") ?? defaults.mount,
|
|
1027
|
+
probeKeys: ownSourceOption(input, "probeKeys") ?? defaults.probeKeys,
|
|
1028
|
+
sync: ownSourceOption(input, "sync") ?? defaults.sync,
|
|
1029
|
+
validate: ownSourceOption(input, "validate") ?? defaults.validate
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function inferredFileSourceKey(input) {
|
|
1033
|
+
if (typeof input === "string") return normalizeSafeWorkspacePath(input);
|
|
1034
|
+
const options = input;
|
|
1035
|
+
if (hasOwn(options, "workspacePath") && typeof options.workspacePath === "string") return normalizeSafeWorkspacePath(options.workspacePath);
|
|
1036
|
+
if (hasOwn(options, "path") && typeof options.path === "string") return normalizeSafeWorkspacePath(options.path);
|
|
1037
|
+
throw workspaceErrorDiagnostics.WORKSPACE_C0006({ message: "[vitehub] file requires a path or workspacePath." });
|
|
1038
|
+
}
|
|
1039
|
+
function inferredLivePaths(family, input) {
|
|
1040
|
+
if (family === "mcpResources") return {};
|
|
1041
|
+
if (family !== "fetch" || !isPlainRecord(input)) return void 0;
|
|
1042
|
+
const workspacePath = inferFetchWorkspacePath(input);
|
|
1043
|
+
const mountPath = dirname$1(workspacePath);
|
|
1044
|
+
const key = mountPath ? workspacePath.slice(mountPath.length + 1) : workspacePath;
|
|
1045
|
+
return { [workspacePath]: key };
|
|
1046
|
+
}
|
|
1047
|
+
function copyLivePaths(target, source) {
|
|
1048
|
+
if (!target || !source) return;
|
|
1049
|
+
for (const key of Object.keys(target)) delete target[key];
|
|
1050
|
+
for (const [key, value] of Object.entries(source)) target[key] = value;
|
|
1051
|
+
}
|
|
1052
|
+
function inferFetchWorkspacePath(input) {
|
|
1053
|
+
const responseType = input.responseType === "text" ? "text" : "json";
|
|
1054
|
+
const explicitPath = typeof input.path === "string" ? input.path : void 0;
|
|
1055
|
+
if (explicitPath) return normalizeSafeWorkspacePath(explicitPath, { allowEmpty: false });
|
|
1056
|
+
const url = input.url instanceof URL ? input.url : new URL(String(input.url));
|
|
1057
|
+
if (url.search) throw workspaceErrorDiagnostics.WORKSPACE_C0007({ message: "[vitehub] fetch() requires an explicit path when the URL includes query parameters." });
|
|
1058
|
+
let path = normalizeSafeWorkspacePath(decodeURI(url.pathname).replace(/^\/+/, ""), { allowEmpty: false });
|
|
1059
|
+
if (!basename$1(path).includes(".")) path = `${path}.${responseType === "json" ? "json" : "txt"}`;
|
|
1060
|
+
return path;
|
|
1061
|
+
}
|
|
1062
|
+
function inferRepositoryMount(repo) {
|
|
1063
|
+
return typeof repo === "string" ? repo.split("/").filter(Boolean).at(-1) : void 0;
|
|
1064
|
+
}
|
|
1065
|
+
function defaultSourceMountPath(key, source) {
|
|
1066
|
+
if (key && !/^\d+$/.test(key)) return key;
|
|
1067
|
+
return inferRepositoryMount(sourceFingerprintRepo(source)) ?? key;
|
|
1068
|
+
}
|
|
1069
|
+
function sourceFingerprintRepo(source) {
|
|
1070
|
+
const fingerprint = source.fingerprint;
|
|
1071
|
+
if (!isPlainRecord(fingerprint)) return;
|
|
1072
|
+
if (typeof fingerprint.repo === "string") return fingerprint.repo;
|
|
1073
|
+
const options = fingerprint.options;
|
|
1074
|
+
if (isPlainRecord(options) && typeof options.repo === "string") return options.repo;
|
|
1075
|
+
}
|
|
1076
|
+
function dirname$1(path) {
|
|
1077
|
+
const parts = path.split("/").filter(Boolean);
|
|
1078
|
+
parts.pop();
|
|
1079
|
+
return parts.join("/");
|
|
1080
|
+
}
|
|
1081
|
+
function basename$1(path) {
|
|
1082
|
+
return path.split("/").filter(Boolean).at(-1) || "";
|
|
1083
|
+
}
|
|
1084
|
+
function applyWorkspaceBinding(source, input) {
|
|
1085
|
+
if (!isPlainRecord(input)) return source;
|
|
1086
|
+
const next = { ...source };
|
|
1087
|
+
copyWorkspaceSourceMetadata(source, next);
|
|
1088
|
+
copyDefinedWorkspaceBindingOption(next, input, "cache");
|
|
1089
|
+
copyDefinedWorkspaceBindingOption(next, input, "materialize");
|
|
1090
|
+
copyDefinedWorkspaceBindingOption(next, input, "mount");
|
|
1091
|
+
copyDefinedWorkspaceBindingOption(next, input, "probeKeys");
|
|
1092
|
+
copyDefinedWorkspaceBindingOption(next, input, "sync");
|
|
1093
|
+
copyDefinedWorkspaceBindingOption(next, input, "validate");
|
|
1094
|
+
return next;
|
|
1095
|
+
}
|
|
1096
|
+
function copyDefinedWorkspaceBindingOption(target, input, key) {
|
|
1097
|
+
if (Object.hasOwn(input, key) && input[key] !== void 0) target[key] = input[key];
|
|
1098
|
+
}
|
|
1099
|
+
function isExplicitSourceBinding(input) {
|
|
1100
|
+
return isPlainRecord(input) && hasOwn(input, "source");
|
|
1101
|
+
}
|
|
1102
|
+
function hasSourceMethods(input) {
|
|
1103
|
+
return typeof input.getKeys === "function" && typeof input.getItem === "function";
|
|
1104
|
+
}
|
|
1105
|
+
function isPlainRecord(input) {
|
|
1106
|
+
return !!input && typeof input === "object" && !Array.isArray(input);
|
|
1107
|
+
}
|
|
1108
|
+
function hasOwn(input, key) {
|
|
1109
|
+
return Object.prototype.hasOwnProperty.call(input, key);
|
|
1110
|
+
}
|
|
1111
|
+
//#endregion
|
|
1112
|
+
export { isWorkspaceSourceRequestOnly as _, normalizeWorkspaceSources as a, markLiveWorkspaceSource as b, sourceMountIntersectsPath as c, withWorkspaceRuntimeOptions as d, prepareWorkspaceSource as f, getWorkspaceSourceRequestExecutor as g, getWorkspaceSourceRequestDescriptor as h, normalizeWorkspaceSourceMetadata as i, workspaceSourceGrantPaths as l, fetch$1 as m, createSourceContext as n, normalizeWorkspaceSourcesMetadata as o, resolveGitHubIgnore as p, normalizeWorkspaceSource as r, sourceMountContainsPath as s, copyWorkspaceSourceMetadata as t, ownSourceOption as u, workspaceSourceRequestDescriptorPath as v, requestJsonEqual as y };
|