@innovatorved/code-lab 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/ARCHITECTURE.md +114 -0
- package/LICENSE +21 -0
- package/README.md +156 -0
- package/dist/code-lab.css +4100 -0
- package/dist/code-lab.d.ts +348 -0
- package/dist/code-lab.esm.js +21954 -0
- package/dist/code-lab.js +21933 -0
- package/dist/extensions/guided-lab.d.ts +13 -0
- package/dist/extensions/guided-lab.esm.js +4218 -0
- package/dist/extensions/guided-lab.js +4236 -0
- package/dist/index.d.ts +11 -0
- package/dist/preview-sw.js +149 -0
- package/dist/runtime.d.ts +48 -0
- package/dist/runtime.esm.js +7510 -0
- package/dist/runtime.js +7491 -0
- package/dist/sample.html +304 -0
- package/dist/schemas.d.ts +514 -0
- package/dist/shell.d.ts +66 -0
- package/dist/shell.esm.js +6405 -0
- package/dist/shell.js +6384 -0
- package/dist/terminal.d.ts +102 -0
- package/dist/terminal.esm.js +1083 -0
- package/dist/terminal.js +1072 -0
- package/dist/workbench.d.ts +1 -0
- package/package.json +98 -0
- package/src/code-lab.css +4100 -0
- package/src/extensions/guided-lab.ts +54 -0
- package/src/index.ts +28 -0
- package/src/preview-sw.js +149 -0
- package/src/runtime.js +7465 -0
- package/src/runtime.ts +7512 -0
- package/src/sample.html +304 -0
- package/src/schemas.ts +177 -0
- package/src/shell.js +6358 -0
- package/src/shell.ts +6456 -0
- package/src/terminal.js +1046 -0
- package/src/terminal.ts +1097 -0
- package/src/workbench.js +6987 -0
- package/src/workbench.ts +6988 -0
package/src/sample.html
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" data-theme="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>@innovatorved/code-lab — Standalone IDE Workbench</title>
|
|
7
|
+
<link rel="stylesheet" href="./code-lab.css" />
|
|
8
|
+
<style>
|
|
9
|
+
*, *::before, *::after {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
}
|
|
12
|
+
html, body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
background: #000000;
|
|
19
|
+
color: #ffffff;
|
|
20
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
#app {
|
|
23
|
+
width: 100vw;
|
|
24
|
+
height: 100vh;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
}
|
|
28
|
+
#app .codelab {
|
|
29
|
+
height: 100%;
|
|
30
|
+
max-height: 100%;
|
|
31
|
+
border: none;
|
|
32
|
+
border-radius: 0;
|
|
33
|
+
}
|
|
34
|
+
#app .codelab,
|
|
35
|
+
#app .codelab-workbench {
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
min-height: 100%;
|
|
39
|
+
max-height: 100%;
|
|
40
|
+
border-radius: 0;
|
|
41
|
+
border: none;
|
|
42
|
+
}
|
|
43
|
+
</style>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<!-- Standalone sample UI embedding the <code-lab> workbench -->
|
|
47
|
+
<div id="app"></div>
|
|
48
|
+
|
|
49
|
+
<script src="./code-lab.js"></script>
|
|
50
|
+
<script>
|
|
51
|
+
(function () {
|
|
52
|
+
const limiterCode = [
|
|
53
|
+
"/**",
|
|
54
|
+
" * Sliding Window Log Rate Limiter",
|
|
55
|
+
" * Tracks request timestamps within a sliding time window.",
|
|
56
|
+
" */",
|
|
57
|
+
"class SlidingWindowLimiter {",
|
|
58
|
+
" constructor(limit = 5, windowMs = 10000) {",
|
|
59
|
+
" this.limit = limit;",
|
|
60
|
+
" this.windowMs = windowMs;",
|
|
61
|
+
" this.logs = [];",
|
|
62
|
+
" }",
|
|
63
|
+
"",
|
|
64
|
+
" allowRequest(now = Date.now()) {",
|
|
65
|
+
" const windowStart = now - this.windowMs;",
|
|
66
|
+
" // Evict timestamps outside the current sliding window",
|
|
67
|
+
" this.logs = this.logs.filter(timestamp => timestamp > windowStart);",
|
|
68
|
+
"",
|
|
69
|
+
" if (this.logs.length < this.limit) {",
|
|
70
|
+
" this.logs.push(now);",
|
|
71
|
+
" return {",
|
|
72
|
+
" allowed: true,",
|
|
73
|
+
" remaining: this.limit - this.logs.length,",
|
|
74
|
+
" limit: this.limit,",
|
|
75
|
+
" resetMs: this.logs.length > 0 ? Math.max(0, (this.logs[0] + this.windowMs) - now) : this.windowMs",
|
|
76
|
+
" };",
|
|
77
|
+
" }",
|
|
78
|
+
"",
|
|
79
|
+
" const oldest = this.logs[0];",
|
|
80
|
+
" const retryAfterMs = Math.max(0, (oldest + this.windowMs) - now);",
|
|
81
|
+
" return {",
|
|
82
|
+
" allowed: false,",
|
|
83
|
+
" remaining: 0,",
|
|
84
|
+
" limit: this.limit,",
|
|
85
|
+
" retryAfterMs",
|
|
86
|
+
" };",
|
|
87
|
+
" }",
|
|
88
|
+
"",
|
|
89
|
+
" reset() {",
|
|
90
|
+
" this.logs = [];",
|
|
91
|
+
" }",
|
|
92
|
+
"}",
|
|
93
|
+
"",
|
|
94
|
+
"module.exports = { SlidingWindowLimiter, RateLimiter: SlidingWindowLimiter };"
|
|
95
|
+
].join('\n');
|
|
96
|
+
|
|
97
|
+
const serverCode = [
|
|
98
|
+
"const http = require('node:http');",
|
|
99
|
+
"const { SlidingWindowLimiter } = require('./limiter');",
|
|
100
|
+
"",
|
|
101
|
+
"const limiters = new Map();",
|
|
102
|
+
"",
|
|
103
|
+
"function getLimiter(clientKey) {",
|
|
104
|
+
" if (!limiters.has(clientKey)) {",
|
|
105
|
+
" // 5 requests per 10-second sliding window",
|
|
106
|
+
" limiters.set(clientKey, new SlidingWindowLimiter(5, 10000));",
|
|
107
|
+
" }",
|
|
108
|
+
" return limiters.get(clientKey);",
|
|
109
|
+
"}",
|
|
110
|
+
"",
|
|
111
|
+
"const server = http.createServer((req, res) => {",
|
|
112
|
+
" const url = new URL(req.url, 'http://localhost:3000');",
|
|
113
|
+
" const clientKey = url.searchParams.get('client') || 'anonymous';",
|
|
114
|
+
" const limiter = getLimiter(clientKey);",
|
|
115
|
+
" const decision = limiter.allowRequest();",
|
|
116
|
+
"",
|
|
117
|
+
" if (url.pathname === '/health') {",
|
|
118
|
+
" res.writeHead(200, { 'Content-Type': 'application/json' });",
|
|
119
|
+
" res.end(JSON.stringify({ status: 'ok', uptime: process.uptime() }));",
|
|
120
|
+
" return;",
|
|
121
|
+
" }",
|
|
122
|
+
"",
|
|
123
|
+
" if (decision.allowed) {",
|
|
124
|
+
" res.writeHead(200, {",
|
|
125
|
+
" 'Content-Type': 'application/json',",
|
|
126
|
+
" 'X-RateLimit-Limit': String(decision.limit),",
|
|
127
|
+
" 'X-RateLimit-Remaining': String(decision.remaining)",
|
|
128
|
+
" });",
|
|
129
|
+
" res.end(JSON.stringify({",
|
|
130
|
+
" status: 'success',",
|
|
131
|
+
" client: clientKey,",
|
|
132
|
+
" message: 'Request allowed by sliding window limiter',",
|
|
133
|
+
" remaining: decision.remaining",
|
|
134
|
+
" }, null, 2));",
|
|
135
|
+
" } else {",
|
|
136
|
+
" res.writeHead(429, {",
|
|
137
|
+
" 'Content-Type': 'application/json',",
|
|
138
|
+
" 'Retry-After': String(Math.ceil(decision.retryAfterMs / 1000)),",
|
|
139
|
+
" 'X-RateLimit-Limit': String(decision.limit),",
|
|
140
|
+
" 'X-RateLimit-Remaining': '0'",
|
|
141
|
+
" });",
|
|
142
|
+
" res.end(JSON.stringify({",
|
|
143
|
+
" status: 'rate_limited',",
|
|
144
|
+
" client: clientKey,",
|
|
145
|
+
" error: 'Too Many Requests',",
|
|
146
|
+
" retryAfterMs: decision.retryAfterMs",
|
|
147
|
+
" }, null, 2));",
|
|
148
|
+
" }",
|
|
149
|
+
"});",
|
|
150
|
+
"",
|
|
151
|
+
"server.listen(3000, () => {",
|
|
152
|
+
" console.log('Sliding Window Rate Limiter HTTP Server listening on http://localhost:3000');",
|
|
153
|
+
" console.log('Available endpoints:');",
|
|
154
|
+
" console.log(' curl http://localhost:3000/');",
|
|
155
|
+
" console.log(' curl \"http://localhost:3000/?client=user_1\"');",
|
|
156
|
+
" console.log(' curl http://localhost:3000/health');",
|
|
157
|
+
"});"
|
|
158
|
+
].join('\n');
|
|
159
|
+
|
|
160
|
+
const demoCode = [
|
|
161
|
+
"const { SlidingWindowLimiter } = require('./limiter');",
|
|
162
|
+
"",
|
|
163
|
+
"console.log('=== Sliding Window Rate Limiter Demo ===\\n');",
|
|
164
|
+
"",
|
|
165
|
+
"const limiter = new SlidingWindowLimiter(3, 2000); // 3 requests per 2-second window",
|
|
166
|
+
"const baseTime = 10000;",
|
|
167
|
+
"",
|
|
168
|
+
"console.log('Configuration: Limit = 3 requests per 2000ms window\\n');",
|
|
169
|
+
"",
|
|
170
|
+
"for (let i = 1; i <= 5; i++) {",
|
|
171
|
+
" const now = baseTime + (i * 100);",
|
|
172
|
+
" const decision = limiter.allowRequest(now);",
|
|
173
|
+
" const status = decision.allowed",
|
|
174
|
+
" ? ('ALLOWED (remaining: ' + decision.remaining + ')')",
|
|
175
|
+
" : ('BLOCKED (retryAfter: ' + decision.retryAfterMs + 'ms)');",
|
|
176
|
+
" console.log('[Req #' + i + '] t = ' + now + 'ms -> ' + status);",
|
|
177
|
+
"}",
|
|
178
|
+
"",
|
|
179
|
+
"console.log('\\n--- Advancing time past window expiration (+2500ms) ---');",
|
|
180
|
+
"const afterExpiry = limiter.allowRequest(baseTime + 2500);",
|
|
181
|
+
"console.log('[Req #6] t = ' + (baseTime + 2500) + 'ms -> ' + (afterExpiry.allowed ? ('ALLOWED (remaining: ' + afterExpiry.remaining + ')') : 'BLOCKED'));",
|
|
182
|
+
"",
|
|
183
|
+
"console.log('\\nDemo completed successfully. Run unit tests with `npm test` or start HTTP server with `node server.js &`.');"
|
|
184
|
+
].join('\n');
|
|
185
|
+
|
|
186
|
+
const testCode = [
|
|
187
|
+
"const { test, describe } = require('node:test');",
|
|
188
|
+
"const assert = require('node:assert/strict');",
|
|
189
|
+
"const { SlidingWindowLimiter } = require('./limiter');",
|
|
190
|
+
"",
|
|
191
|
+
"describe('SlidingWindowLimiter', () => {",
|
|
192
|
+
" test('allows requests up to capacity limit', () => {",
|
|
193
|
+
" const limiter = new SlidingWindowLimiter(3, 5000);",
|
|
194
|
+
" const t0 = 1000;",
|
|
195
|
+
" assert.equal(limiter.allowRequest(t0).allowed, true);",
|
|
196
|
+
" assert.equal(limiter.allowRequest(t0 + 100).allowed, true);",
|
|
197
|
+
" assert.equal(limiter.allowRequest(t0 + 200).allowed, true);",
|
|
198
|
+
" });",
|
|
199
|
+
"",
|
|
200
|
+
" test('rejects requests when limit is exceeded within the same window', () => {",
|
|
201
|
+
" const limiter = new SlidingWindowLimiter(2, 5000);",
|
|
202
|
+
" const t0 = 1000;",
|
|
203
|
+
" assert.equal(limiter.allowRequest(t0).allowed, true);",
|
|
204
|
+
" assert.equal(limiter.allowRequest(t0 + 10).allowed, true);",
|
|
205
|
+
" const rejected = limiter.allowRequest(t0 + 20);",
|
|
206
|
+
" assert.equal(rejected.allowed, false);",
|
|
207
|
+
" assert.equal(rejected.remaining, 0);",
|
|
208
|
+
" assert.ok(rejected.retryAfterMs > 0);",
|
|
209
|
+
" });",
|
|
210
|
+
"",
|
|
211
|
+
" test('slides window and re-allows requests as oldest timestamps expire', () => {",
|
|
212
|
+
" const limiter = new SlidingWindowLimiter(2, 1000);",
|
|
213
|
+
" const t0 = 1000;",
|
|
214
|
+
" assert.equal(limiter.allowRequest(t0).allowed, true);",
|
|
215
|
+
" assert.equal(limiter.allowRequest(t0 + 200).allowed, true);",
|
|
216
|
+
" assert.equal(limiter.allowRequest(t0 + 400).allowed, false);",
|
|
217
|
+
"",
|
|
218
|
+
" // Oldest request at t0 expires at t0 + 1000 = 2000. At 2050, 1 slot is free.",
|
|
219
|
+
" const res = limiter.allowRequest(2050);",
|
|
220
|
+
" assert.equal(res.allowed, true);",
|
|
221
|
+
" assert.equal(res.remaining, 0);",
|
|
222
|
+
" });",
|
|
223
|
+
"",
|
|
224
|
+
" test('reset clears internal timestamp log', () => {",
|
|
225
|
+
" const limiter = new SlidingWindowLimiter(1, 5000);",
|
|
226
|
+
" limiter.allowRequest(1000);",
|
|
227
|
+
" assert.equal(limiter.allowRequest(1001).allowed, false);",
|
|
228
|
+
" limiter.reset();",
|
|
229
|
+
" assert.equal(limiter.allowRequest(1002).allowed, true);",
|
|
230
|
+
" });",
|
|
231
|
+
"});"
|
|
232
|
+
].join('\n');
|
|
233
|
+
|
|
234
|
+
const readmeContent = [
|
|
235
|
+
"# Sliding Window Rate Limiter & Virtual HTTP Gateway",
|
|
236
|
+
"",
|
|
237
|
+
"This standalone interactive IDE runs entirely inside your browser using `@innovatorved/code-lab` with zero remote asset dependencies.",
|
|
238
|
+
"",
|
|
239
|
+
"## Architecture",
|
|
240
|
+
"- **In-Memory POSIX Web Worker**: Full VFS and Node.js-compatible execution context.",
|
|
241
|
+
"- **PTY Terminal Emulator**: Interactive shell with ANSI colors, command history, and piping.",
|
|
242
|
+
"- **Virtual HTTP Loopback**: In-memory TCP/HTTP socket routing and real-time Port inspection.",
|
|
243
|
+
"",
|
|
244
|
+
"## Quick Start",
|
|
245
|
+
"1. Click **Run Demo** in the top toolbar or run:",
|
|
246
|
+
" ```bash",
|
|
247
|
+
" node demo.js",
|
|
248
|
+
" ```",
|
|
249
|
+
"2. Run automated unit tests with **Run Tests** or run:",
|
|
250
|
+
" ```bash",
|
|
251
|
+
" node test.js",
|
|
252
|
+
" ```",
|
|
253
|
+
"3. Start the virtual HTTP server in the background:",
|
|
254
|
+
" ```bash",
|
|
255
|
+
" node server.js &",
|
|
256
|
+
" ```",
|
|
257
|
+
"4. Query the server via curl or test rate limiting:",
|
|
258
|
+
" ```bash",
|
|
259
|
+
" curl http://localhost:3000/",
|
|
260
|
+
" curl \"http://localhost:3000/?client=alice\"",
|
|
261
|
+
" curl http://localhost:3000/health",
|
|
262
|
+
" ```",
|
|
263
|
+
"5. Switch to the **Ports** tab in the bottom drawer to view open listening ports and send requests using the built-in Mini HTTP Client."
|
|
264
|
+
].join('\n');
|
|
265
|
+
|
|
266
|
+
const packageJsonContent = JSON.stringify({
|
|
267
|
+
name: "sliding-window-rate-limiter",
|
|
268
|
+
version: "1.0.0",
|
|
269
|
+
description: "Sliding window rate limiter with virtual HTTP server",
|
|
270
|
+
main: "server.js",
|
|
271
|
+
scripts: {
|
|
272
|
+
start: "node server.js",
|
|
273
|
+
demo: "node demo.js",
|
|
274
|
+
test: "node --test test.js"
|
|
275
|
+
}
|
|
276
|
+
}, null, 2);
|
|
277
|
+
|
|
278
|
+
const workbench = CodeLab.mount('#app', {
|
|
279
|
+
id: 'code-lab-standalone-sample',
|
|
280
|
+
title: '@innovatorved/code-lab — Standalone IDE',
|
|
281
|
+
summary: 'Interactive in-browser IDE with virtual POSIX shell, Web Worker runtime, and HTTP loopback.',
|
|
282
|
+
mode: 'sandbox',
|
|
283
|
+
language: 'js',
|
|
284
|
+
entry: 'demo.js',
|
|
285
|
+
testEntry: 'test.js',
|
|
286
|
+
files: {
|
|
287
|
+
'limiter.js': limiterCode,
|
|
288
|
+
'server.js': serverCode,
|
|
289
|
+
'demo.js': demoCode,
|
|
290
|
+
'test.js': testCode,
|
|
291
|
+
'README.md': readmeContent,
|
|
292
|
+
'package.json': packageJsonContent
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
if (workbench && typeof workbench.switchDrawerTab === 'function') {
|
|
297
|
+
workbench.switchDrawerTab('terminal');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
window.workbench = workbench;
|
|
301
|
+
})();
|
|
302
|
+
</script>
|
|
303
|
+
</body>
|
|
304
|
+
</html>
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod Schemas and Inferred TypeScript Types for code-lab v2.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ── 1. Guided Step ──────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export const GuidedStepSchema = z.object({
|
|
10
|
+
id: z.string().min(1),
|
|
11
|
+
title: z.string().min(1),
|
|
12
|
+
concept: z.string().optional(),
|
|
13
|
+
targetFile: z.string().optional(),
|
|
14
|
+
targetSymbol: z.string().optional(),
|
|
15
|
+
symbol: z.string().optional(), // alias for targetSymbol
|
|
16
|
+
instructions: z.union([z.string(), z.array(z.string())]),
|
|
17
|
+
hint: z.string().optional(),
|
|
18
|
+
testNames: z.array(z.string()).optional()
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type GuidedStep = z.infer<typeof GuidedStepSchema>;
|
|
22
|
+
|
|
23
|
+
// ── 2. Language Bundle ──────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
export const LanguageBundleSchema = z.object({
|
|
26
|
+
language: z.enum(['js', 'ts']).default('js'),
|
|
27
|
+
files: z.record(z.string()).default({}),
|
|
28
|
+
starterFiles: z.record(z.string()).optional(),
|
|
29
|
+
solutionFiles: z.record(z.string()).optional(),
|
|
30
|
+
entry: z.string().optional(),
|
|
31
|
+
testEntry: z.string().optional()
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type LanguageBundle = z.infer<typeof LanguageBundleSchema>;
|
|
35
|
+
|
|
36
|
+
// ── 3. Guided Lab Extension Options ─────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
export const GuidedLabExtensionOptionsSchema = z.object({
|
|
39
|
+
steps: z.array(GuidedStepSchema).default([]),
|
|
40
|
+
stepIndex: z.number().int().nonnegative().default(0),
|
|
41
|
+
mode: z.enum(['guided', 'sandbox']).default('guided'),
|
|
42
|
+
language: z.enum(['js', 'ts']).optional(),
|
|
43
|
+
lang: z.enum(['js', 'ts']).optional(),
|
|
44
|
+
starterFiles: z.record(z.string()).optional(),
|
|
45
|
+
solutionFiles: z.record(z.string()).optional(),
|
|
46
|
+
tsStarterFiles: z.record(z.string()).optional(),
|
|
47
|
+
tsSolutionFiles: z.record(z.string()).optional(),
|
|
48
|
+
tsFiles: z.record(z.string()).optional(),
|
|
49
|
+
summary: z.string().optional(),
|
|
50
|
+
onStepComplete: z.function().args(GuidedStepSchema, z.number()).returns(z.void()).optional(),
|
|
51
|
+
onLabComplete: z.function().args(z.string()).returns(z.void()).optional()
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export type GuidedLabExtensionOptions = z.infer<typeof GuidedLabExtensionOptionsSchema>;
|
|
55
|
+
|
|
56
|
+
// ── 4. GitHub Clone Options & Progress ──────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export const CloneProgressPhaseSchema = z.enum([
|
|
59
|
+
'connecting',
|
|
60
|
+
'metadata',
|
|
61
|
+
'downloading',
|
|
62
|
+
'mounting',
|
|
63
|
+
'ready',
|
|
64
|
+
'error'
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
export type CloneProgressPhase = z.infer<typeof CloneProgressPhaseSchema>;
|
|
68
|
+
|
|
69
|
+
export const CloneProgressEventSchema = z.object({
|
|
70
|
+
phase: CloneProgressPhaseSchema,
|
|
71
|
+
message: z.string(),
|
|
72
|
+
loaded: z.number().optional(),
|
|
73
|
+
total: z.number().optional()
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export type CloneProgressEvent = z.infer<typeof CloneProgressEventSchema>;
|
|
77
|
+
|
|
78
|
+
export const GitHubCloneOptionsSchema = z.object({
|
|
79
|
+
intoRoot: z.boolean().default(true),
|
|
80
|
+
targetDir: z.string().default('/workspace'),
|
|
81
|
+
branch: z.string().optional(),
|
|
82
|
+
depth: z.number().int().positive().optional(),
|
|
83
|
+
maxFiles: z.number().int().positive().default(2000),
|
|
84
|
+
maxFileSize: z.number().int().positive().default(5 * 1024 * 1024),
|
|
85
|
+
concurrency: z.number().int().positive().default(8),
|
|
86
|
+
clearExisting: z.boolean().default(false),
|
|
87
|
+
onProgress: z.function().args(z.any()).returns(z.void()).optional(),
|
|
88
|
+
fetchImpl: z.any().optional()
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export type GitHubCloneOptions = z.infer<typeof GitHubCloneOptionsSchema>;
|
|
92
|
+
|
|
93
|
+
// ── 5. Runtime Execution Options ────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
export const RuntimeExecuteOptionsSchema = z.object({
|
|
96
|
+
files: z.record(z.string()).optional(),
|
|
97
|
+
entry: z.string().optional(),
|
|
98
|
+
mode: z.enum(['run', 'test', 'repl']).default('run'),
|
|
99
|
+
replCode: z.string().optional(),
|
|
100
|
+
printReplResult: z.boolean().optional(),
|
|
101
|
+
testFilter: z.union([z.string(), z.array(z.string()), z.null()]).optional(),
|
|
102
|
+
timeoutMs: z.number().positive().default(30000),
|
|
103
|
+
maxOutputBytes: z.number().positive().default(256 * 1024),
|
|
104
|
+
maxConsoleCalls: z.number().positive().default(5000),
|
|
105
|
+
instanceId: z.string().optional(),
|
|
106
|
+
concurrent: z.boolean().optional(),
|
|
107
|
+
argv: z.union([z.array(z.string()), z.null()]).optional(),
|
|
108
|
+
pid: z.number().int().optional(),
|
|
109
|
+
isBackground: z.boolean().optional(),
|
|
110
|
+
vfs: z.any().optional(),
|
|
111
|
+
activePortTable: z.any().optional(),
|
|
112
|
+
packages: z.record(z.any()).optional(),
|
|
113
|
+
npmModules: z.record(z.any()).optional(),
|
|
114
|
+
onStdout: z.function().args(z.string()).returns(z.void()).optional(),
|
|
115
|
+
onStderr: z.function().args(z.string()).returns(z.void()).optional(),
|
|
116
|
+
onTestResult: z.function().args(z.any()).returns(z.void()).optional()
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export type RuntimeExecuteOptions = z.infer<typeof RuntimeExecuteOptionsSchema>;
|
|
120
|
+
|
|
121
|
+
// ── 6. Workspace Snapshot ───────────────────────────────────────────────────
|
|
122
|
+
|
|
123
|
+
export const WorkspaceSnapshotSchema = z.object({
|
|
124
|
+
version: z.number().default(1),
|
|
125
|
+
timestamp: z.number().optional(),
|
|
126
|
+
files: z.record(z.string()),
|
|
127
|
+
openTabs: z.array(z.string()).default([]),
|
|
128
|
+
activeFile: z.string().nullable().optional(),
|
|
129
|
+
mode: z.enum(['guided', 'sandbox']).optional(),
|
|
130
|
+
lang: z.enum(['js', 'ts']).optional(),
|
|
131
|
+
labId: z.string().optional()
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export type WorkspaceSnapshot = z.infer<typeof WorkspaceSnapshotSchema>;
|
|
135
|
+
|
|
136
|
+
// ── 7. Workbench Options ────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
export const WorkbenchOptionsSchema = z.object({
|
|
139
|
+
id: z.string().optional(),
|
|
140
|
+
labId: z.string().optional(),
|
|
141
|
+
buildId: z.string().optional(),
|
|
142
|
+
title: z.string().default('code-lab'),
|
|
143
|
+
summary: z.string().optional(),
|
|
144
|
+
theme: z.enum(['dark', 'light', 'auto']).default('auto'),
|
|
145
|
+
persistState: z.boolean().default(true),
|
|
146
|
+
repo: z.string().optional(),
|
|
147
|
+
githubRepo: z.string().optional(),
|
|
148
|
+
branch: z.string().optional(),
|
|
149
|
+
files: z.record(z.string()).default({}),
|
|
150
|
+
entry: z.string().default('demo.js'),
|
|
151
|
+
testEntry: z.string().default('test.js'),
|
|
152
|
+
testFile: z.string().optional(),
|
|
153
|
+
backLabel: z.string().default('Back'),
|
|
154
|
+
monacoUrl: z.string().optional(),
|
|
155
|
+
onClose: z.function().returns(z.void()).optional(),
|
|
156
|
+
onRun: z.function().args(z.any()).returns(z.void()).optional(),
|
|
157
|
+
onTestResult: z.function().args(z.any()).returns(z.void()).optional(),
|
|
158
|
+
onCodeChange: z.function().args(z.string(), z.string()).returns(z.void()).optional(),
|
|
159
|
+
plugins: z.array(z.any()).optional(),
|
|
160
|
+
extensions: z.array(z.any()).optional(),
|
|
161
|
+
// Backward-compatible guided lab properties:
|
|
162
|
+
steps: z.array(GuidedStepSchema).optional(),
|
|
163
|
+
starterFiles: z.record(z.string()).optional(),
|
|
164
|
+
solutionFiles: z.record(z.string()).optional(),
|
|
165
|
+
tsFiles: z.record(z.string()).optional(),
|
|
166
|
+
tsStarterFiles: z.record(z.string()).optional(),
|
|
167
|
+
tsSolutionFiles: z.record(z.string()).optional(),
|
|
168
|
+
guided: z.any().optional(),
|
|
169
|
+
mode: z.enum(['guided', 'sandbox']).optional(),
|
|
170
|
+
language: z.enum(['js', 'ts']).optional(),
|
|
171
|
+
lang: z.enum(['js', 'ts']).optional(),
|
|
172
|
+
stepIndex: z.number().int().optional(),
|
|
173
|
+
onStepComplete: z.function().args(z.any(), z.number()).returns(z.void()).optional(),
|
|
174
|
+
onLabComplete: z.function().args(z.string()).returns(z.void()).optional()
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export type WorkbenchOptions = z.infer<typeof WorkbenchOptionsSchema>;
|