@innovatorved/code-lab 0.1.6 → 0.1.7

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/src/workbench.ts CHANGED
@@ -42,6 +42,10 @@
42
42
  const MONACO_BASE = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs';
43
43
  const STORAGE_PREFIX = 'sd-codelab-v1:';
44
44
 
45
+ // The bundler rewrites this literal from package.json at build time. Keeping
46
+ // the fallback in sync lets tests require src/workbench.js directly.
47
+ const CODELAB_VERSION = '0.1.7';
48
+
45
49
  // Ambient TypeScript declarations for Node.js built-ins inside Monaco
46
50
  const NODE_AMBIENT_DTS = `
47
51
  declare var require: (id: string) => any;
@@ -378,6 +382,33 @@ declare module 'bun:sqlite' {
378
382
  .replace(/'/g, ''');
379
383
  }
380
384
 
385
+ // Schemes that may appear in a rendered href. Everything else
386
+ // (javascript:, data:, vbscript:, blob:, file:, ...) becomes a dead link.
387
+ const SAFE_LINK_SCHEMES = new Set(['http', 'https', 'mailto']);
388
+
389
+ function sanitizeUrl(raw) {
390
+ if (raw === null || raw === undefined) return '#';
391
+ const trimmed = String(raw).trim();
392
+ if (!trimmed) return '#';
393
+
394
+ // Browsers ignore C0 controls and zero-width characters while resolving a
395
+ // scheme, so `java\nscript:` and `java\u200Bscript:` still execute. Strip
396
+ // them before deciding what the scheme is, but return the original value
397
+ // when it is safe.
398
+ const normalized = trimmed.replace(/[\u0000-\u0020\u007F\u200B-\u200D\uFEFF]/g, '');
399
+ const schemeMatch = normalized.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
400
+
401
+ if (!schemeMatch) {
402
+ // No scheme: a fragment, an absolute path, or a relative path.
403
+ // Backslashes are treated as slashes by the URL parser and can turn a
404
+ // "relative" URL into a protocol-relative one, so reject those.
405
+ if (/^[\\/]{2}/.test(normalized) && !normalized.startsWith('/')) return '#';
406
+ return trimmed;
407
+ }
408
+
409
+ return SAFE_LINK_SCHEMES.has(schemeMatch[1].toLowerCase()) ? trimmed : '#';
410
+ }
411
+
381
412
  function formatErrorText(err) {
382
413
  if (!err) return '';
383
414
  if (typeof err === 'string') return err;
@@ -571,14 +602,9 @@ declare module 'bun:sqlite' {
571
602
 
572
603
  // Markdown Links: [label](url "title") or [label](url)
573
604
  text = text.replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_, label, url, title) => {
574
- const cleanUrl = url.trim();
605
+ const cleanUrl = sanitizeUrl(url);
575
606
  const titleAttr = title ? ` title="${escapeHtml(title)}"` : '';
576
- return `<a href="${escapeHtml(cleanUrl)}" class="codelab-link" target="_blank" rel="noopener noreferrer"${titleAttr}>${label}</a>`;
577
- });
578
-
579
- // Autolinks: <https://...>
580
- text = text.replace(/<(https?:\/\/[^>]+)>/g, (_, url) => {
581
- return `<a href="${escapeHtml(url)}" class="codelab-link" target="_blank" rel="noopener noreferrer">${escapeHtml(url)}</a>`;
607
+ return `<a href="${escapeHtml(cleanUrl)}" class="codelab-link" target="_blank" rel="noopener noreferrer"${titleAttr}>${escapeHtml(label)}</a>`;
582
608
  });
583
609
 
584
610
  // Strikethrough: ~~del~~
@@ -773,8 +799,9 @@ declare module 'bun:sqlite' {
773
799
  // Normalize CRLF to LF
774
800
  text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
775
801
 
776
- // Prevent raw custom elements from executing within markdown previews
777
- text = text.replace(/<\/?code-lab(\s[^>]*)?>/gi, (m) => escapeHtml(m));
802
+ // NUL delimits internal placeholders. Strip author-supplied NULs so
803
+ // markdown cannot forge a code-block or autolink placeholder.
804
+ text = text.replace(/\u0000/g, '');
778
805
 
779
806
  // Phase 1: Fenced Code Block Extraction
780
807
  const codeBlocks = [];
@@ -797,6 +824,25 @@ declare module 'bun:sqlite' {
797
824
  return `\x00INLINECODE_${idx}\x00`;
798
825
  });
799
826
 
827
+ // Phase 2b: Autolinks are the only inline construct that uses angle
828
+ // brackets. Extract them before raw HTML is neutralized, then restore the
829
+ // anchors in Phase 7.
830
+ const autolinks = [];
831
+ text = text.replace(/<(https?:\/\/[^>\s]+)>/g, (_, url) => {
832
+ const idx = autolinks.length;
833
+ const safe = sanitizeUrl(url);
834
+ autolinks.push(
835
+ `<a href="${escapeHtml(safe)}" class="codelab-link" target="_blank" rel="noopener noreferrer">${escapeHtml(url)}</a>`
836
+ );
837
+ return `\x00AUTOLINK_${idx}\x00`;
838
+ });
839
+
840
+ // Phase 2c: Neutralize all remaining raw HTML. Every tag needs a `<`, so
841
+ // escaping that one character turns any author-supplied markup into text
842
+ // without disturbing `>` blockquote syntax. From here on, every real tag
843
+ // in the output is generated by this renderer.
844
+ text = text.replace(/</g, '&lt;');
845
+
800
846
  // Phase 3: GitHub Callout Alerts & Blockquotes
801
847
  const calloutBlocks = [];
802
848
  text = text.replace(/(?:^[ \t]*>.*(?:\n|$))+/gm, (match) => {
@@ -874,7 +920,8 @@ declare module 'bun:sqlite' {
874
920
  .replace(/\x00TABLE_(\d+)\x00/g, (_, i) => tableBlocks[Number(i)] || '')
875
921
  .replace(/\x00CALLOUT_(\d+)\x00/g, (_, i) => calloutBlocks[Number(i)] || '')
876
922
  .replace(/\x00CODEBLOCK_(\d+)\x00/g, (_, i) => codeBlocks[Number(i)] || '')
877
- .replace(/\x00INLINECODE_(\d+)\x00/g, (_, i) => inlineCodes[Number(i)] || '');
923
+ .replace(/\x00INLINECODE_(\d+)\x00/g, (_, i) => inlineCodes[Number(i)] || '')
924
+ .replace(/\x00AUTOLINK_(\d+)\x00/g, (_, i) => autolinks[Number(i)] || '');
878
925
 
879
926
  return finalHtml;
880
927
  }
@@ -1084,24 +1131,102 @@ declare module 'bun:sqlite' {
1084
1131
  let _workbenchInstanceCounter = 0;
1085
1132
  const _fallbackStorage = new Map();
1086
1133
 
1087
- function safeStorageGet(key) {
1134
+ // CSP for preview HTML assembled in the srcdoc fallback. Mirrors PREVIEW_CSP
1135
+ // in src/preview-sw.js — keep both copies in sync.
1136
+ const PREVIEW_CSP = [
1137
+ "default-src 'self' data: blob:",
1138
+ "base-uri 'self'",
1139
+ "object-src 'none'",
1140
+ "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:",
1141
+ "style-src 'self' 'unsafe-inline'",
1142
+ "img-src 'self' data: blob:",
1143
+ "font-src 'self' data:",
1144
+ "connect-src 'self' data: blob:",
1145
+ "media-src 'self' data: blob:",
1146
+ "worker-src 'self' blob:",
1147
+ "frame-src 'self' data: blob:",
1148
+ "form-action 'self'",
1149
+ "frame-ancestors 'self'"
1150
+ ].join('; ');
1151
+
1152
+ function normalizePreviewOrigin(raw) {
1153
+ if (raw === null || raw === undefined || raw === '') return null;
1154
+ try {
1155
+ const parsed = new URL(String(raw));
1156
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
1157
+ return parsed.origin;
1158
+ } catch (_) {
1159
+ return null;
1160
+ }
1161
+ }
1162
+
1163
+ const LOG_PREFIX = '[code-lab]';
1164
+
1165
+ // Small leveled logger. Hosts can pass `options.logger` to route diagnostics
1166
+ // into their own telemetry; `options.debug` enables verbose output. Errors
1167
+ // are never silently discarded.
1168
+ function createLogger(options = {}) {
1169
+ const sink = options.logger;
1170
+ const debugEnabled = options.debug === true;
1171
+
1172
+ const write = (level, args) => {
1173
+ if (level === 'debug' && !debugEnabled) return;
1174
+ if (sink && typeof sink[level] === 'function') {
1175
+ try {
1176
+ sink[level](...args);
1177
+ return;
1178
+ } catch (_) {
1179
+ // A broken host logger must not break the IDE; fall through.
1180
+ }
1181
+ }
1182
+ const fn = typeof console !== 'undefined' ? console[level] : null;
1183
+ if (typeof fn === 'function') fn(LOG_PREFIX, ...args);
1184
+ };
1185
+
1186
+ return {
1187
+ debug: (...args) => write('debug', args),
1188
+ info: (...args) => write('info', args),
1189
+ warn: (...args) => write('warn', args),
1190
+ error: (...args) => write('error', args)
1191
+ };
1192
+ }
1193
+
1194
+ const DEFAULT_LOGGER = createLogger();
1195
+
1196
+ function safeStorageGet(key, logger = DEFAULT_LOGGER) {
1088
1197
  try {
1089
1198
  if (typeof localStorage !== 'undefined' && localStorage !== null) {
1090
- return localStorage.getItem(key);
1199
+ const value = localStorage.getItem(key);
1200
+ if (value !== null && value !== undefined) return value;
1091
1201
  }
1092
- } catch (_) {}
1202
+ } catch (err) {
1203
+ logger.warn(
1204
+ `localStorage.getItem("${key}") failed; using in-memory state.`,
1205
+ err && err.message ? err.message : err
1206
+ );
1207
+ }
1093
1208
  return _fallbackStorage.has(key) ? _fallbackStorage.get(key) : null;
1094
1209
  }
1095
1210
 
1096
- function safeStorageSet(key, value) {
1211
+ function safeStorageSet(key, value, logger = DEFAULT_LOGGER) {
1097
1212
  const str = String(value);
1098
1213
  try {
1099
1214
  if (typeof localStorage !== 'undefined' && localStorage !== null) {
1100
1215
  localStorage.setItem(key, str);
1101
- return;
1216
+ return true;
1217
+ }
1218
+ } catch (err) {
1219
+ if (!safeStorageSet._warnedKeys) safeStorageSet._warnedKeys = new Set();
1220
+ if (!safeStorageSet._warnedKeys.has(key)) {
1221
+ safeStorageSet._warnedKeys.add(key);
1222
+ logger.warn(
1223
+ `localStorage.setItem("${key}") failed; keeping state in memory for this session.`,
1224
+ err && err.message ? err.message : err
1225
+ );
1102
1226
  }
1103
- } catch (_) {}
1227
+ }
1104
1228
  _fallbackStorage.set(key, str);
1229
+ return false;
1105
1230
  }
1106
1231
 
1107
1232
  // ── CodeLabWorkbench Instance Class ──────────────────────────────────────
@@ -1112,12 +1237,22 @@ declare module 'bun:sqlite' {
1112
1237
  throw new Error('CodeLabWorkbench requires a valid DOM container element.');
1113
1238
  }
1114
1239
  this.options = options || {};
1240
+ this.logger = createLogger({ logger: options.logger, debug: options.debug });
1241
+ this._persistenceFailureReported = false;
1115
1242
  this.instanceId = options.instanceId || (`cl-${++_workbenchInstanceCounter}`);
1116
1243
  this.labId = options.id || options.labId || options.buildId || 'custom-lab';
1117
1244
  this.title = options.title || this.labId;
1118
1245
  this.summary = options.summary || '';
1119
1246
  this.monacoUrl = options.monacoUrl || MONACO_BASE;
1120
1247
  this.themeOption = options.theme || 'auto'; // 'dark' | 'light' | 'auto'
1248
+ this.previewOrigin = normalizePreviewOrigin(options.previewOrigin);
1249
+ this._previewIsolationWarned = false;
1250
+ if (options.previewOrigin && !this.previewOrigin) {
1251
+ this.logger.warn(
1252
+ 'Ignoring invalid `previewOrigin`; expected an absolute http(s) origin ' +
1253
+ 'such as "https://preview.example.com".'
1254
+ );
1255
+ }
1121
1256
  this.explicitEntry = options.entry || null;
1122
1257
  this.explicitTestEntry = options.testEntry || options.testFile || null;
1123
1258
  this.backLabel = options.backLabel || 'Back to Build Guide';
@@ -1455,7 +1590,7 @@ declare module 'bun:sqlite' {
1455
1590
  const handlers = this._eventListeners.get(key);
1456
1591
  if (handlers) {
1457
1592
  for (const fn of Array.from(handlers)) {
1458
- try { fn(detail); } catch (_) {}
1593
+ try { fn(detail); } catch (err) { this.logger.error(`Listener for "${key}" threw.`, err); }
1459
1594
  }
1460
1595
  }
1461
1596
  }
@@ -1489,13 +1624,26 @@ declare module 'bun:sqlite' {
1489
1624
  return {};
1490
1625
  }
1491
1626
  try {
1492
- const raw = safeStorageGet(this._storageKey()) || safeStorageGet('sd_codelab_' + this.labId);
1627
+ const raw = safeStorageGet(this._storageKey(), this.logger) || safeStorageGet('sd_codelab_' + this.labId, this.logger);
1493
1628
  return raw ? JSON.parse(raw) : {};
1494
- } catch {
1629
+ } catch (err) {
1630
+ this.logger.warn(
1631
+ `Ignoring unreadable saved state for "${this.labId}".`,
1632
+ err && err.message ? err.message : err
1633
+ );
1495
1634
  return {};
1496
1635
  }
1497
1636
  }
1498
1637
 
1638
+ _reportPersistenceFailure() {
1639
+ if (this._persistenceFailureReported) return;
1640
+ this._persistenceFailureReported = true;
1641
+ this.logger.warn(
1642
+ 'Workbench state could not be persisted; changes are kept in memory. Export your workspace to keep them.'
1643
+ );
1644
+ this._emitEvent('persistence-error', { labId: this.labId });
1645
+ }
1646
+
1499
1647
  _saveState() {
1500
1648
  try {
1501
1649
  const key = `${this.mode}:${this.lang}`;
@@ -1520,11 +1668,20 @@ declare module 'bun:sqlite' {
1520
1668
  return;
1521
1669
  }
1522
1670
  const serialized = JSON.stringify(state);
1523
- safeStorageSet(this._storageKey(), serialized);
1524
- // Sync with host app sidebar & build overview progress trackers
1525
- safeStorageSet('codelab_progress_' + this.labId, JSON.stringify(completedArr));
1526
- safeStorageSet('sd_codelab_' + this.labId, serialized);
1527
- } catch {}
1671
+ const persisted = [
1672
+ safeStorageSet(this._storageKey(), serialized, this.logger),
1673
+ // Sync with host app sidebar & build overview progress trackers
1674
+ safeStorageSet('codelab_progress_' + this.labId, JSON.stringify(completedArr), this.logger),
1675
+ safeStorageSet('sd_codelab_' + this.labId, serialized, this.logger)
1676
+ ];
1677
+ if (persisted.includes(false)) this._reportPersistenceFailure();
1678
+ } catch (err) {
1679
+ this.logger.error(
1680
+ 'Failed to save workbench state.',
1681
+ err && err.message ? err.message : err
1682
+ );
1683
+ this._reportPersistenceFailure();
1684
+ }
1528
1685
  }
1529
1686
 
1530
1687
  _detectPackages() {
@@ -4089,8 +4246,44 @@ declare module 'bun:sqlite' {
4089
4246
  return `http://127.0.0.1:${port}${path}`;
4090
4247
  }
4091
4248
 
4249
+ _previewFrameUrl(port, pathAndQuery = '/') {
4250
+ const p = Number(port) || 3000;
4251
+ const rawPath = pathAndQuery || '/';
4252
+ const path = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
4253
+ const base = this.previewOrigin || '';
4254
+ return `${base}/__preview/${p}${path}`;
4255
+ }
4256
+
4257
+ _warnPreviewIsolation() {
4258
+ if (this.previewOrigin || this._previewIsolationWarned) return;
4259
+ this._previewIsolationWarned = true;
4260
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
4261
+ console.warn(
4262
+ '[code-lab] Web Preview runs on the host origin and can read host storage. ' +
4263
+ 'Pass `previewOrigin: "https://preview.example.com"` to isolate untrusted previews.'
4264
+ );
4265
+ }
4266
+ }
4267
+
4268
+ _injectPreviewCsp(html, port) {
4269
+ if (typeof html !== 'string' || !html) return html;
4270
+ if (/<meta[^>]+http-equiv=["']?content-security-policy/i.test(html)) return html;
4271
+
4272
+ const tags = `<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">` +
4273
+ (/<base\b/i.test(html) ? '' : `<base href="/__preview/${Number(port) || 3000}/">`);
4274
+
4275
+ if (/<head\b[^>]*>/i.test(html)) {
4276
+ return html.replace(/<head\b[^>]*>/i, (match) => match + tags);
4277
+ }
4278
+ if (/<html\b[^>]*>/i.test(html)) {
4279
+ return html.replace(/<html\b[^>]*>/i, (match) => `${match}<head>${tags}</head>`);
4280
+ }
4281
+ return `<head>${tags}</head>${html}`;
4282
+ }
4283
+
4092
4284
  _openWebPreview(port, path = '/') {
4093
4285
  const p = Number(port) || this._firstListeningPort() || 3000;
4286
+ this._warnPreviewIsolation();
4094
4287
  this.previewState.port = p;
4095
4288
  this.previewState.path = path || '/';
4096
4289
  this.previewState.url = `http://127.0.0.1:${p}${this.previewState.path}`;
@@ -4269,10 +4462,10 @@ declare module 'bun:sqlite' {
4269
4462
 
4270
4463
  _popoutPreview() {
4271
4464
  const url = this._previewUrl();
4272
- let popout = '/__preview/';
4465
+ let popout = this._previewFrameUrl(this.previewState.port || 3000, '/');
4273
4466
  try {
4274
4467
  const u = new URL(url);
4275
- popout = `/__preview/${u.port}${u.pathname}${u.search || ''}`;
4468
+ popout = this._previewFrameUrl(u.port, `${u.pathname}${u.search || ''}`);
4276
4469
  } catch (_) {}
4277
4470
  if (typeof window !== 'undefined' && typeof window.open === 'function') {
4278
4471
  try { window.open(popout, '_blank', 'noopener'); } catch (_) {}
@@ -4282,6 +4475,7 @@ declare module 'bun:sqlite' {
4282
4475
 
4283
4476
  _renderWebPreview(bodyEl) {
4284
4477
  if (!bodyEl) return;
4478
+ this._warnPreviewIsolation();
4285
4479
  const renderKey = `${this.previewState.port}|${this.previewState.path}|${this.previewState.frameMode}|${this._previewSwReady}`;
4286
4480
  if (bodyEl.querySelector && bodyEl.querySelector('.codelab-preview') && this._previewRenderKey === renderKey) {
4287
4481
  this._renderWebPreviewControls();
@@ -4319,7 +4513,7 @@ declare module 'bun:sqlite' {
4319
4513
  <button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="preview-popout" title="Open in a new browser tab">${CL_ICONS.externalLink || '↗'} <span>Pop Out</span></button>
4320
4514
  </div>
4321
4515
  <div class="codelab-preview-viewport codelab-preview-viewport--${this.previewState.frameMode}" id="cl-preview-viewport">
4322
- <iframe class="codelab-preview-iframe" id="cl-preview-iframe" sandbox="allow-scripts allow-forms allow-same-origin allow-modals" title="Web Preview"></iframe>
4516
+ <iframe class="codelab-preview-iframe" id="cl-preview-iframe" sandbox="allow-scripts allow-forms allow-same-origin allow-modals" allow="camera 'none'; microphone 'none'; geolocation 'none'; payment 'none'; usb 'none'" referrerpolicy="same-origin" title="Web Preview"></iframe>
4323
4517
  </div>
4324
4518
  ${servers.length
4325
4519
  ? `<div class="codelab-preview-hint">Serving from the in-browser virtual runtime. Use Pop Out for a standalone tab.</div>`
@@ -4356,7 +4550,7 @@ declare module 'bun:sqlite' {
4356
4550
  try {
4357
4551
  const u = new URL(fullUrl);
4358
4552
  if (typeof iframe.removeAttribute === 'function') iframe.removeAttribute('srcdoc');
4359
- iframe.setAttribute('src', `/__preview/${u.port}${u.pathname}${u.search || ''}`);
4553
+ iframe.setAttribute('src', this._previewFrameUrl(u.port, u.pathname + (u.search || '')));
4360
4554
  this.previewState.loading = false;
4361
4555
  return Promise.resolve();
4362
4556
  } catch (_) {}
@@ -4368,8 +4562,8 @@ declare module 'bun:sqlite' {
4368
4562
  .then((res) => {
4369
4563
  let body = res.body || '';
4370
4564
  const contentType = res.headers['content-type'] || res.headers['Content-Type'] || '';
4371
- if (/text\/html/i.test(contentType) && /<head\b/i.test(body) && !/<base\b/i.test(body)) {
4372
- body = body.replace(/<head\b[^>]*>/i, (m) => `${m}<base href="/__preview/${port}/">`);
4565
+ if (/text\/html/i.test(contentType)) {
4566
+ body = this._injectPreviewCsp(body, port);
4373
4567
  }
4374
4568
  this.previewState.srcdoc = body;
4375
4569
  this.previewState.loading = false;
@@ -4381,7 +4575,7 @@ declare module 'bun:sqlite' {
4381
4575
  this.previewState.loading = false;
4382
4576
  this.previewState.error = String((err && err.message) || err);
4383
4577
  const msg = `<body style="font-family:system-ui;padding:24px;color:#888"><h2>Preview unavailable</h2><p>${escapeHtml(this.previewState.error)}</p></body>`;
4384
- iframe.setAttribute('srcdoc', msg);
4578
+ iframe.setAttribute('srcdoc', this._injectPreviewCsp(msg, port));
4385
4579
  });
4386
4580
  }
4387
4581
 
@@ -4736,7 +4930,7 @@ declare module 'bun:sqlite' {
4736
4930
 
4737
4931
  _notifyCodeChange(filename, code) {
4738
4932
  if (this.onCodeChange) {
4739
- try { this.onCodeChange(filename, code); } catch (_) {}
4933
+ try { this.onCodeChange(filename, code); } catch (err) { this.logger.error('onCodeChange callback threw.', err); }
4740
4934
  }
4741
4935
  const detail = { labId: this.labId, filename, path: filename, code, content: code };
4742
4936
  this._emitEvent('codelab:change', detail);
@@ -6375,7 +6569,7 @@ declare module 'bun:sqlite' {
6375
6569
  }
6376
6570
 
6377
6571
  if (this.onRun) {
6378
- try { this.onRun(res); } catch (_) {}
6572
+ try { this.onRun(res); } catch (err) { this.logger.error('onRun callback threw.', err); }
6379
6573
  }
6380
6574
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
6381
6575
  } catch (err) {
@@ -6450,10 +6644,10 @@ declare module 'bun:sqlite' {
6450
6644
  }
6451
6645
 
6452
6646
  if (this.onTestResult) {
6453
- try { this.onTestResult(res); } catch (_) {}
6647
+ try { this.onTestResult(res); } catch (err) { this.logger.error('onTestResult callback threw.', err); }
6454
6648
  }
6455
6649
  if (this.onRun) {
6456
- try { this.onRun(res); } catch (_) {}
6650
+ try { this.onRun(res); } catch (err) { this.logger.error('onRun callback threw.', err); }
6457
6651
  }
6458
6652
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'test', entry, result: res });
6459
6653
 
@@ -6467,7 +6661,7 @@ declare module 'bun:sqlite' {
6467
6661
  this.completedSteps.add(step.id);
6468
6662
  newlyCompleted = true;
6469
6663
  if (this.onStepComplete) {
6470
- try { this.onStepComplete(step, sIdx); } catch (_) {}
6664
+ try { this.onStepComplete(step, sIdx); } catch (err) { this.logger.error('onStepComplete callback threw.', err); }
6471
6665
  }
6472
6666
  const stepDetail = {
6473
6667
  labId: this.labId,
@@ -6486,7 +6680,7 @@ declare module 'bun:sqlite' {
6486
6680
  this._saveState();
6487
6681
  if (this.steps.length > 0 && this.completedSteps.size >= this.steps.length) {
6488
6682
  if (this.onLabComplete) {
6489
- try { this.onLabComplete(this.labId); } catch (_) {}
6683
+ try { this.onLabComplete(this.labId); } catch (err) { this.logger.error('onLabComplete callback threw.', err); }
6490
6684
  }
6491
6685
  this._emitEvent('codelab:lab-complete', {
6492
6686
  labId: this.labId,
@@ -6791,7 +6985,12 @@ declare module 'bun:sqlite' {
6791
6985
  a.click();
6792
6986
  setTimeout(() => URL.revokeObjectURL(url), 500);
6793
6987
  }
6794
- } catch (_) {}
6988
+ } catch (err) {
6989
+ this.logger.error(
6990
+ `Failed to start download for "${filename}".`,
6991
+ err && err.message ? err.message : err
6992
+ );
6993
+ }
6795
6994
  return content;
6796
6995
  }
6797
6996
 
@@ -6819,7 +7018,12 @@ declare module 'bun:sqlite' {
6819
7018
  a.click();
6820
7019
  setTimeout(() => URL.revokeObjectURL(url), 500);
6821
7020
  }
6822
- } catch (_) {}
7021
+ } catch (err) {
7022
+ this.logger.error(
7023
+ 'Failed to download workspace export.',
7024
+ err && err.message ? err.message : err
7025
+ );
7026
+ }
6823
7027
  }
6824
7028
  return snapshot;
6825
7029
  }
@@ -7315,7 +7519,7 @@ declare module 'bun:sqlite' {
7315
7519
  }
7316
7520
 
7317
7521
  const CodeLabSDK = {
7318
- version: '2.0.0',
7522
+ version: CODELAB_VERSION,
7319
7523
  Workbench: CodeLabWorkbench,
7320
7524
  CodeLabWorkbench,
7321
7525
  CodeLabElement: CodeLabElementClass,