@inupedia/spotlight-client 0.3.3 → 0.3.5
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/capabilities/channel.d.ts.map +1 -1
- package/dist/capabilities/channel.js +33 -5
- package/dist/capabilities/handshake.d.ts +2 -0
- package/dist/capabilities/handshake.d.ts.map +1 -1
- package/dist/capabilities/handshake.js +65 -5
- package/dist/vite/capabilityDevMiddleware.d.ts +1 -1
- package/dist/vite/capabilityDevMiddleware.d.ts.map +1 -1
- package/dist/vite/capabilityDevMiddleware.js +6 -4
- package/dist/vite/capabilityVirtualModule.d.ts.map +1 -1
- package/dist/vite/capabilityVirtualModule.js +4 -2
- package/dist/vite/spotlightCapabilities.d.ts.map +1 -1
- package/dist/vite/spotlightCapabilities.js +3 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/capabilities/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EAElC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAA4B,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAEpG,KAAK,iBAAiB,GAAG,OAAO,CAAC,2BAA2B,EAAE;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAEtF,MAAM,WAAW,mBAAmB;IAClC,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAC/C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,IAAI,QAAQ,CAAC,0BAA0B,CAAC,CAAC;CAC/C;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAA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,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC;IACxG,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC9C,GAAG,mBAAmB,CAyLtB"}
|
|
@@ -10,11 +10,14 @@ export function createCapabilityChannel(options) {
|
|
|
10
10
|
let heartbeat;
|
|
11
11
|
let renewal;
|
|
12
12
|
let renewalPendingGeneration;
|
|
13
|
+
let renewPending;
|
|
13
14
|
let reconnectTimer;
|
|
14
15
|
let reconnectAttempt = 0;
|
|
15
16
|
let generation = 0;
|
|
16
17
|
let reservationSerial = 0;
|
|
17
18
|
let closed = false;
|
|
19
|
+
let mutationTail = Promise.resolve();
|
|
20
|
+
const lifecycle = new AbortController();
|
|
18
21
|
let reserveAndOpen;
|
|
19
22
|
const scheduleReconnect = () => {
|
|
20
23
|
if (closed || reconnectTimer)
|
|
@@ -23,7 +26,14 @@ export function createCapabilityChannel(options) {
|
|
|
23
26
|
reconnectAttempt += 1;
|
|
24
27
|
reconnectTimer = setTimeout(() => {
|
|
25
28
|
reconnectTimer = undefined;
|
|
26
|
-
void reserveAndOpen().catch(
|
|
29
|
+
void reserveAndOpen().catch((error) => {
|
|
30
|
+
if (error instanceof SpotlightCapabilityError &&
|
|
31
|
+
["HOST_OFFLINE", "CAPABILITY_LEASE_REVOKED", "CAPABILITY_LEASE_FENCED"].includes(error.code)) {
|
|
32
|
+
close();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
scheduleReconnect();
|
|
36
|
+
});
|
|
27
37
|
}, delay);
|
|
28
38
|
};
|
|
29
39
|
const fence = () => Object.freeze({
|
|
@@ -39,6 +49,7 @@ export function createCapabilityChannel(options) {
|
|
|
39
49
|
const executor = createHostActionExecutor({ registry: options.registry, fence });
|
|
40
50
|
const close = () => {
|
|
41
51
|
closed = true;
|
|
52
|
+
lifecycle.abort(new DOMException("Capability channel closed.", "AbortError"));
|
|
42
53
|
if (heartbeat)
|
|
43
54
|
clearInterval(heartbeat);
|
|
44
55
|
if (renewal)
|
|
@@ -122,9 +133,14 @@ export function createCapabilityChannel(options) {
|
|
|
122
133
|
method: "POST",
|
|
123
134
|
headers: { "Content-Type": "application/json" },
|
|
124
135
|
body: JSON.stringify(body),
|
|
125
|
-
signal:
|
|
136
|
+
signal: lifecycle.signal,
|
|
126
137
|
}));
|
|
127
|
-
const
|
|
138
|
+
const mutate = (operation) => {
|
|
139
|
+
const task = mutationTail.then(operation, operation);
|
|
140
|
+
mutationTail = task.then(() => undefined, () => undefined);
|
|
141
|
+
return task;
|
|
142
|
+
};
|
|
143
|
+
const performRenew = () => mutate(async () => {
|
|
128
144
|
const current = fence();
|
|
129
145
|
const startedGeneration = generation;
|
|
130
146
|
const result = await post(`/v1/capabilities/leases/${encodeURIComponent(current.leaseId)}/renew`, { ...current, expectedLeaseVersion: current.leaseVersion, liveTools: options.registry.liveTools() });
|
|
@@ -136,8 +152,20 @@ export function createCapabilityChannel(options) {
|
|
|
136
152
|
}
|
|
137
153
|
leaseVersion = result.leaseVersion;
|
|
138
154
|
return result;
|
|
155
|
+
});
|
|
156
|
+
const renew = () => {
|
|
157
|
+
if (renewPending)
|
|
158
|
+
return renewPending;
|
|
159
|
+
const task = performRenew();
|
|
160
|
+
renewPending = task;
|
|
161
|
+
const clear = () => {
|
|
162
|
+
if (renewPending === task)
|
|
163
|
+
renewPending = undefined;
|
|
164
|
+
};
|
|
165
|
+
void task.then(clear, clear);
|
|
166
|
+
return task;
|
|
139
167
|
};
|
|
140
|
-
reserveAndOpen = async () => {
|
|
168
|
+
reserveAndOpen = () => mutate(async () => {
|
|
141
169
|
const current = fence();
|
|
142
170
|
const startedGeneration = generation;
|
|
143
171
|
const serial = ++reservationSerial;
|
|
@@ -155,7 +183,7 @@ export function createCapabilityChannel(options) {
|
|
|
155
183
|
connectionEpoch = reserved.connectionEpoch;
|
|
156
184
|
channelToken = reserved.capabilityChannelToken;
|
|
157
185
|
open();
|
|
158
|
-
};
|
|
186
|
+
});
|
|
159
187
|
return Object.freeze({
|
|
160
188
|
open,
|
|
161
189
|
close,
|
|
@@ -17,6 +17,8 @@ export interface CapabilityConnectResultV1 {
|
|
|
17
17
|
}
|
|
18
18
|
export interface CreateCapabilityClientOptionsV1 {
|
|
19
19
|
endpoint: string;
|
|
20
|
+
/** API key applied to all Capability HTTP requests. */
|
|
21
|
+
apiKey?: string;
|
|
20
22
|
project: SpotlightProjectV1;
|
|
21
23
|
registry: FrontendToolRegistryV1;
|
|
22
24
|
buildInfo: Readonly<CapabilityBuildInfoV1>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/capabilities/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAIjF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,OAAO,CAAC,2BAA2B,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACxE,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,kBAAkB,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D;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC3C,gBAAgB,EAAE,MAAM,OAAO,CAAC;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,kBAAkB,CAAC;QAChC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;KACpC,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC9C;AAiDD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,+BAA+B;mBA+BtD,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;GA+DrF"}
|
|
@@ -5,8 +5,60 @@ import { createRuntimeId } from "../runtimeId.js";
|
|
|
5
5
|
function endpoint(base, path) {
|
|
6
6
|
return `${base.replace(/\/$/, "")}${path}`;
|
|
7
7
|
}
|
|
8
|
+
async function readUploadBody(stream, byteLength, signal) {
|
|
9
|
+
if (!Number.isSafeInteger(byteLength) || byteLength < 0) {
|
|
10
|
+
throw new Error("Capability Artifact upload byte length is invalid.");
|
|
11
|
+
}
|
|
12
|
+
const body = new Uint8Array(byteLength);
|
|
13
|
+
const reader = stream.getReader();
|
|
14
|
+
let offset = 0;
|
|
15
|
+
const abortReason = () => signal?.reason instanceof Error
|
|
16
|
+
? signal.reason
|
|
17
|
+
: new DOMException("Capability upload aborted.", "AbortError");
|
|
18
|
+
const cancelReader = () => {
|
|
19
|
+
void reader.cancel(abortReason()).catch(() => undefined);
|
|
20
|
+
};
|
|
21
|
+
signal?.addEventListener("abort", cancelReader, { once: true });
|
|
22
|
+
if (signal?.aborted)
|
|
23
|
+
cancelReader();
|
|
24
|
+
try {
|
|
25
|
+
while (true) {
|
|
26
|
+
if (signal?.aborted) {
|
|
27
|
+
throw abortReason();
|
|
28
|
+
}
|
|
29
|
+
const { done, value } = await reader.read();
|
|
30
|
+
if (signal?.aborted)
|
|
31
|
+
throw abortReason();
|
|
32
|
+
if (done)
|
|
33
|
+
break;
|
|
34
|
+
if (offset + value.byteLength > byteLength) {
|
|
35
|
+
throw new Error("Capability Artifact upload exceeded its declared byte length.");
|
|
36
|
+
}
|
|
37
|
+
body.set(value, offset);
|
|
38
|
+
offset += value.byteLength;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
signal?.removeEventListener("abort", cancelReader);
|
|
43
|
+
reader.releaseLock();
|
|
44
|
+
}
|
|
45
|
+
if (offset !== byteLength) {
|
|
46
|
+
throw new Error("Capability Artifact upload did not match its declared byte length.");
|
|
47
|
+
}
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
8
50
|
export function createCapabilityClient(options) {
|
|
9
|
-
const
|
|
51
|
+
const rawFetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
52
|
+
const apiKey = options.apiKey?.trim();
|
|
53
|
+
const fetcher = apiKey
|
|
54
|
+
? (input, init = {}) => {
|
|
55
|
+
const headers = new Headers(init.headers);
|
|
56
|
+
if (!headers.has("X-Spotlight-Api-Key")) {
|
|
57
|
+
headers.set("X-Spotlight-Api-Key", apiKey);
|
|
58
|
+
}
|
|
59
|
+
return rawFetcher(input, { ...init, headers });
|
|
60
|
+
}
|
|
61
|
+
: rawFetcher;
|
|
10
62
|
const offerIds = new Map();
|
|
11
63
|
const offerIdFor = (key) => {
|
|
12
64
|
const existing = offerIds.get(key);
|
|
@@ -47,18 +99,26 @@ export function createCapabilityClient(options) {
|
|
|
47
99
|
let handshake = await post("/v1/capabilities/handshakes", offer, input.signal);
|
|
48
100
|
if (handshake.status === "upload_required") {
|
|
49
101
|
const upload = await options.openUploadStream();
|
|
102
|
+
const uploadBody = await readUploadBody(upload.stream, upload.byteLength, input.signal);
|
|
50
103
|
const uploadRequest = {
|
|
51
104
|
method: "PUT",
|
|
52
105
|
headers: {
|
|
53
106
|
Authorization: `Bearer ${handshake.uploadToken}`,
|
|
54
107
|
"Content-Type": upload.contentType,
|
|
55
|
-
"Content-Length": String(upload.byteLength),
|
|
56
108
|
},
|
|
57
|
-
body:
|
|
109
|
+
body: uploadBody,
|
|
58
110
|
signal: input.signal,
|
|
59
|
-
duplex: "half",
|
|
60
111
|
};
|
|
61
|
-
|
|
112
|
+
const uploadUrl = endpoint(options.endpoint, handshake.uploadUrl);
|
|
113
|
+
let uploadResponse;
|
|
114
|
+
try {
|
|
115
|
+
uploadResponse = await fetcher(uploadUrl, uploadRequest);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
119
|
+
throw new Error(`Capability Artifact upload request failed (${uploadUrl}): ${detail}`, { cause: error });
|
|
120
|
+
}
|
|
121
|
+
await capabilityResponseJson(uploadResponse);
|
|
62
122
|
handshake = await post(`/v1/capabilities/handshakes/${encodeURIComponent(handshake.handshakeId)}/resume`, { resumeToken: handshake.resumeToken }, input.signal);
|
|
63
123
|
}
|
|
64
124
|
if (handshake.status !== "accepted")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import type { CapabilityPluginBuildResultV1 } from "./capabilityBuildTypes.js";
|
|
3
3
|
export type CapabilityDevMiddlewareV1 = (request: IncomingMessage, response: ServerResponse, next: () => void) => void;
|
|
4
|
-
export declare function createCapabilityDevMiddlewareV1(currentResult: () => Readonly<CapabilityPluginBuildResultV1
|
|
4
|
+
export declare function createCapabilityDevMiddlewareV1(currentResult: () => Readonly<CapabilityPluginBuildResultV1>, base?: string): CapabilityDevMiddlewareV1;
|
|
5
5
|
//# sourceMappingURL=capabilityDevMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityDevMiddleware.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityDevMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAK/E,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,IAAI,KACb,IAAI,CAAC;AAEV,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,QAAQ,CAAC,6BAA6B,CAAC,
|
|
1
|
+
{"version":3,"file":"capabilityDevMiddleware.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityDevMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAK/E,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,IAAI,KACb,IAAI,CAAC;AAEV,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,QAAQ,CAAC,6BAA6B,CAAC,EAC5D,IAAI,SAAM,GACT,yBAAyB,CAkD3B"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ROUTE_SUFFIX = "@spotlight/capability-artifacts/";
|
|
2
2
|
const DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
3
|
-
export function createCapabilityDevMiddlewareV1(currentResult) {
|
|
3
|
+
export function createCapabilityDevMiddlewareV1(currentResult, base = "/") {
|
|
4
|
+
const normalizedBase = `/${base}`.replace(/\/+/g, "/").replace(/\/?$/, "/");
|
|
5
|
+
const routePrefix = `${normalizedBase}${ROUTE_SUFFIX}`;
|
|
4
6
|
return (request, response, next) => {
|
|
5
7
|
const url = request.url ?? "";
|
|
6
|
-
if (!url.startsWith(
|
|
8
|
+
if (!url.startsWith(routePrefix)) {
|
|
7
9
|
next();
|
|
8
10
|
return;
|
|
9
11
|
}
|
|
10
|
-
const requestedDigest = url.slice(
|
|
12
|
+
const requestedDigest = url.slice(routePrefix.length);
|
|
11
13
|
if (!DIGEST_PATTERN.test(requestedDigest)) {
|
|
12
14
|
response.statusCode = 404;
|
|
13
15
|
response.end();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityVirtualModule.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,eAAO,MAAM,gCAAgC,EAC3C,gCAAyC,CAAC;AAC5C,eAAO,MAAM,yCAAyC,EACpD,kCAA2C,CAAC;AAE9C,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"capabilityVirtualModule.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,eAAO,MAAM,gCAAgC,EAC3C,gCAAyC,CAAC;AAC5C,eAAO,MAAM,yCAAyC,EACpD,kCAA2C,CAAC;AAE9C,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AA2CD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC1C,OAAO,GAAE,QAAQ,CAAC;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAM,GAClD,QAAQ,CAAC,yBAAyB,CAAC,CAuBrC"}
|
|
@@ -13,9 +13,11 @@ function disabledProviderSource() {
|
|
|
13
13
|
}
|
|
14
14
|
function developmentProviderSource(buildInfo) {
|
|
15
15
|
const digest = JSON.stringify(buildInfo.artifactDigest);
|
|
16
|
-
const
|
|
16
|
+
const relativePath = JSON.stringify(`capability-artifacts/${buildInfo.artifactDigest}`);
|
|
17
17
|
return `export async function openUploadStream() {
|
|
18
|
-
const
|
|
18
|
+
const runtimeModuleUrl = import.meta.url;
|
|
19
|
+
const artifactUrl = new URL(${relativePath}, runtimeModuleUrl).href;
|
|
20
|
+
const response = await fetch(artifactUrl, {
|
|
19
21
|
method: "GET",
|
|
20
22
|
cache: "no-store",
|
|
21
23
|
credentials: "same-origin",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spotlightCapabilities.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAKlE,OAAO,EAGL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AA0B9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,
|
|
1
|
+
{"version":3,"file":"spotlightCapabilities.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAKlE,OAAO,EAGL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AA0B9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CA4LR"}
|
|
@@ -14,6 +14,7 @@ function isAtOrBelow(candidate, directory) {
|
|
|
14
14
|
export function spotlightCapabilities(project, options) {
|
|
15
15
|
let root;
|
|
16
16
|
let command;
|
|
17
|
+
let base = "/";
|
|
17
18
|
let state;
|
|
18
19
|
let server;
|
|
19
20
|
let rebuildChain = Promise.resolve();
|
|
@@ -92,6 +93,7 @@ export function spotlightCapabilities(project, options) {
|
|
|
92
93
|
configResolved(config) {
|
|
93
94
|
root = config.root;
|
|
94
95
|
command = config.command;
|
|
96
|
+
base = config.base || "/";
|
|
95
97
|
const roots = options?.skillRoots ?? project.skillRoots ?? DEFAULT_SKILL_ROOTS;
|
|
96
98
|
relevantRoots = Object.freeze(roots.map((entry) => {
|
|
97
99
|
const path = typeof entry === "string" ? entry : entry.path;
|
|
@@ -140,7 +142,7 @@ export function spotlightCapabilities(project, options) {
|
|
|
140
142
|
viteServer.httpServer?.once("close", cleanup);
|
|
141
143
|
if (options?.devRuntimeUpload === false)
|
|
142
144
|
return;
|
|
143
|
-
viteServer.middlewares.use(createCapabilityDevMiddlewareV1(() => currentState().result));
|
|
145
|
+
viteServer.middlewares.use(createCapabilityDevMiddlewareV1(() => currentState().result, base));
|
|
144
146
|
},
|
|
145
147
|
resolveId(id) {
|
|
146
148
|
return id === SPOTLIGHT_CAPABILITIES_MODULE_ID ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inupedia/spotlight-client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "HTTP/SSE helpers and host tool bridge for Inupedia Spotlight (monorepo workspace package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"fflate": "0.8.3",
|
|
48
48
|
"magic-string": "^0.30.21",
|
|
49
49
|
"yaml": "^2.8.4",
|
|
50
|
-
"@inupedia/spotlight-protocol": "0.3.
|
|
50
|
+
"@inupedia/spotlight-protocol": "0.3.5"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|