create-interview-cockpit 0.10.0 → 0.12.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/package.json
CHANGED
|
@@ -968,3 +968,100 @@ export async function fetchModuleFederationGeneratedFile(
|
|
|
968
968
|
export async function stopModuleFederationSandbox(id: string): Promise<void> {
|
|
969
969
|
await fetch(`${BASE}/module-federation/${id}`, { method: "DELETE" });
|
|
970
970
|
}
|
|
971
|
+
|
|
972
|
+
// ── React Lab (Vite) ─────────────────────────────────────────────────────────
|
|
973
|
+
|
|
974
|
+
export interface ReactLabSandboxInfo {
|
|
975
|
+
id: string;
|
|
976
|
+
port: number;
|
|
977
|
+
url: string;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
export async function startReactLabSandbox(
|
|
981
|
+
files: Record<string, string>,
|
|
982
|
+
): Promise<ReactLabSandboxInfo> {
|
|
983
|
+
const res = await fetch(`${BASE}/react-lab/start`, {
|
|
984
|
+
method: "POST",
|
|
985
|
+
headers: { "Content-Type": "application/json" },
|
|
986
|
+
body: JSON.stringify({ files }),
|
|
987
|
+
});
|
|
988
|
+
if (!res.ok) {
|
|
989
|
+
const body = await res.json().catch(() => ({}));
|
|
990
|
+
throw new Error(
|
|
991
|
+
(body as any).error || `Failed to start React lab (${res.status})`,
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
return res.json();
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export async function updateReactLabFiles(
|
|
998
|
+
id: string,
|
|
999
|
+
files: Record<string, string>,
|
|
1000
|
+
): Promise<void> {
|
|
1001
|
+
await fetch(`${BASE}/react-lab/${id}/update-files`, {
|
|
1002
|
+
method: "POST",
|
|
1003
|
+
headers: { "Content-Type": "application/json" },
|
|
1004
|
+
body: JSON.stringify({ files }),
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
export async function streamReactLabCommand(
|
|
1009
|
+
input: { id: string; command: string },
|
|
1010
|
+
onMessage: (message: ModuleFederationCommandStreamMessage) => void,
|
|
1011
|
+
): Promise<void> {
|
|
1012
|
+
const res = await fetch(`${BASE}/react-lab/${input.id}/command-stream`, {
|
|
1013
|
+
method: "POST",
|
|
1014
|
+
headers: { "Content-Type": "application/json" },
|
|
1015
|
+
body: JSON.stringify({ command: input.command }),
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
if (!res.ok || !res.body) {
|
|
1019
|
+
const error = await res.text().catch(() => "React lab command failed");
|
|
1020
|
+
throw new Error(error || "React lab command failed");
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const reader = res.body.getReader();
|
|
1024
|
+
const decoder = new TextDecoder();
|
|
1025
|
+
let buffer = "";
|
|
1026
|
+
|
|
1027
|
+
const flushBuffer = () => {
|
|
1028
|
+
const parts = buffer.split("\n\n");
|
|
1029
|
+
buffer = parts.pop() ?? "";
|
|
1030
|
+
for (const part of parts) {
|
|
1031
|
+
const dataLine = part.split("\n").find((l) => l.startsWith("data:"));
|
|
1032
|
+
if (!dataLine) continue;
|
|
1033
|
+
try {
|
|
1034
|
+
const payload = JSON.parse(dataLine.slice(5).trim());
|
|
1035
|
+
onMessage(payload as ModuleFederationCommandStreamMessage);
|
|
1036
|
+
} catch {}
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
|
|
1040
|
+
while (true) {
|
|
1041
|
+
const { value, done } = await reader.read();
|
|
1042
|
+
buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });
|
|
1043
|
+
flushBuffer();
|
|
1044
|
+
if (done) break;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
if (buffer.trim()) {
|
|
1048
|
+
flushBuffer();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
export async function readReactLabFile(
|
|
1053
|
+
id: string,
|
|
1054
|
+
filePath: string,
|
|
1055
|
+
): Promise<string | null> {
|
|
1056
|
+
const res = await fetch(
|
|
1057
|
+
`${BASE}/react-lab/${id}/read-file?path=${encodeURIComponent(filePath)}`,
|
|
1058
|
+
{ cache: "no-store" },
|
|
1059
|
+
);
|
|
1060
|
+
if (!res.ok) return null;
|
|
1061
|
+
const body = (await res.json()) as { content?: string };
|
|
1062
|
+
return body.content ?? null;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
export async function stopReactLabSandbox(id: string): Promise<void> {
|
|
1066
|
+
await fetch(`${BASE}/react-lab/${id}`, { method: "DELETE" });
|
|
1067
|
+
}
|