create-interview-cockpit 0.13.0 → 0.15.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-interview-cockpit",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Scaffold a personal AI-powered interview prep cockpit",
5
5
  "type": "module",
6
6
  "bin": {
@@ -346,6 +346,7 @@ export async function saveCodeSnippet(
346
346
  | "user"
347
347
  | "ai"
348
348
  | "sandbox"
349
+ | "browser-security"
349
350
  | "infra"
350
351
  | "react"
351
352
  | "nextjs"
@@ -1084,6 +1085,44 @@ export async function readReactLabFile(
1084
1085
  return body.content ?? null;
1085
1086
  }
1086
1087
 
1088
+ export async function streamNextjsCommand(
1089
+ input: { id: string; command: string },
1090
+ onMessage: (message: ModuleFederationCommandStreamMessage) => void,
1091
+ ): Promise<void> {
1092
+ const res = await fetch(`${BASE}/nextjs/${input.id}/command-stream`, {
1093
+ method: "POST",
1094
+ headers: { "Content-Type": "application/json" },
1095
+ body: JSON.stringify({ command: input.command }),
1096
+ });
1097
+ if (!res.ok || !res.body) throw new Error(`Command failed: ${res.status}`);
1098
+
1099
+ const reader = res.body.getReader();
1100
+ const decoder = new TextDecoder();
1101
+ let buffer = "";
1102
+
1103
+ const flushBuffer = () => {
1104
+ const parts = buffer.split("\n\n");
1105
+ buffer = parts.pop() ?? "";
1106
+ for (const part of parts) {
1107
+ const line = part.trim();
1108
+ if (!line.startsWith("data:")) continue;
1109
+ const payload = line.slice(5).trim();
1110
+ if (!payload) continue;
1111
+ try {
1112
+ onMessage(JSON.parse(payload) as ModuleFederationCommandStreamMessage);
1113
+ } catch {}
1114
+ }
1115
+ };
1116
+
1117
+ while (true) {
1118
+ const { value, done } = await reader.read();
1119
+ buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });
1120
+ flushBuffer();
1121
+ if (done) break;
1122
+ }
1123
+ if (buffer.trim()) flushBuffer();
1124
+ }
1125
+
1087
1126
  export async function stopReactLabSandbox(id: string): Promise<void> {
1088
1127
  await fetch(`${BASE}/react-lab/${id}`, { method: "DELETE" });
1089
1128
  }