aipeek 0.1.3 → 0.1.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.
@@ -248,7 +248,7 @@ function truncate(s, max) {
248
248
  }
249
249
 
250
250
  // src/detail.ts
251
- async function detail(raw, section, index, full) {
251
+ function detail(raw, section, index, full) {
252
252
  switch (section) {
253
253
  case "ui":
254
254
  return full ? raw.ui || null : compactUI(raw.ui) || null;
@@ -279,7 +279,7 @@ function detailConsole(logs, index, full) {
279
279
  }
280
280
  return `[${log.level}] ${truncate2(log.text, 200)}`;
281
281
  }
282
- async function detailNetwork(requests, index, full) {
282
+ function detailNetwork(requests, index, full) {
283
283
  const i = Number.parseInt(index ?? "");
284
284
  if (isNaN(i) || i < 0 || i >= requests.length)
285
285
  return null;
@@ -311,9 +311,9 @@ ${req.responseBody}`);
311
311
  if (req.requestBody) {
312
312
  lines.push(`request-body: ${byteSize(req.requestBody)}`);
313
313
  if (req.requestSample) {
314
- const ts = await quickTypeOrFallback(req.requestSample, "RequestBody");
315
- if (ts)
316
- lines.push(ts);
314
+ const schema = jsonSchema(req.requestSample);
315
+ if (schema)
316
+ lines.push(schema);
317
317
  }
318
318
  }
319
319
  if (req.responseBody) {
@@ -321,10 +321,10 @@ ${req.responseBody}`);
321
321
  lines.push(`response-body: ${byteSize(req.responseBody)} "${truncate2(req.responseBody, 100)}"`);
322
322
  } else {
323
323
  if (req.responseSample) {
324
- const ts = await quickTypeOrFallback(req.responseSample, "ResponseBody");
325
324
  lines.push(`response-body: ${byteSize(req.responseBody)}`);
326
- if (ts)
327
- lines.push(ts);
325
+ const schema = jsonSchema(req.responseSample);
326
+ if (schema)
327
+ lines.push(schema);
328
328
  } else {
329
329
  lines.push(`response-body: ${byteSize(req.responseBody)} ${truncate2(req.responseBody, 100)}`);
330
330
  }
@@ -333,23 +333,6 @@ ${req.responseBody}`);
333
333
  }
334
334
  return lines.join("\n");
335
335
  }
336
- async function quickTypeOrFallback(sample, typeName) {
337
- try {
338
- const { InputData, jsonInputForTargetLanguage, quicktype } = await import("quicktype-core");
339
- const jsonInput = jsonInputForTargetLanguage("typescript");
340
- await jsonInput.addSource({ name: typeName, samples: [sample] });
341
- const inputData = new InputData();
342
- inputData.addInput(jsonInput);
343
- const { lines } = await quicktype({
344
- inputData,
345
- lang: "typescript",
346
- rendererOptions: { "just-types": "true", "acronym-style": "original" }
347
- });
348
- return lines.join("\n");
349
- } catch {
350
- return jsonSchema(sample);
351
- }
352
- }
353
336
  function detailError(errors, index, full) {
354
337
  const i = Number.parseInt(index ?? "");
355
338
  if (isNaN(i) || i < 0 || i >= errors.length)
@@ -516,19 +499,28 @@ curl ${base}/state # registered store snapshots
516
499
  Append \`?full\` for untruncated output. Append \`/{index}\` for a specific item's detail.
517
500
  `;
518
501
  }
502
+ var AIPEEK_HEADING = "# aipeek \u2014 Runtime Browser Inspector";
519
503
  function injectClaudeMd(root, port) {
520
504
  const path = resolve(root, "CLAUDE.md");
521
505
  const snippet = aipeekSnippet(port);
522
506
  try {
523
- if (existsSync(path)) {
524
- const content = readFileSync(path, "utf-8");
525
- if (content.includes("__aipeek"))
526
- return;
507
+ if (!existsSync(path)) {
508
+ writeFileSync(path, snippet.trimStart());
509
+ return;
510
+ }
511
+ const content = readFileSync(path, "utf-8");
512
+ const start = content.indexOf(AIPEEK_HEADING);
513
+ if (start === -1) {
527
514
  writeFileSync(path, `${content.trimEnd()}
528
515
  ${snippet}`);
529
- } else {
530
- writeFileSync(path, snippet.trimStart());
516
+ return;
531
517
  }
518
+ const afterHeading = content.indexOf("\n", start);
519
+ const nextHeading = content.indexOf("\n# ", afterHeading);
520
+ const end = nextHeading === -1 ? content.length : nextHeading;
521
+ const before = content.slice(0, start).trimEnd();
522
+ const after = content.slice(end);
523
+ writeFileSync(path, before + (before ? "\n" : "") + snippet + after);
532
524
  } catch {
533
525
  }
534
526
  }
@@ -574,7 +566,7 @@ function aipeekPlugin() {
574
566
  if (parts.length >= 1) {
575
567
  if (!lastRaw)
576
568
  lastRaw = await collectFromClient();
577
- const result = await detail(lastRaw, parts[0], parts[1], full);
569
+ const result = detail(lastRaw, parts[0], parts[1], full);
578
570
  if (result !== null) {
579
571
  res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
580
572
  res.end(result);
@@ -600,13 +592,5 @@ function aipeekPlugin() {
600
592
  }
601
593
 
602
594
  export {
603
- compactUI,
604
- compactConsole,
605
- compactNetwork,
606
- compactErrors,
607
- compactState,
608
- compact,
609
- detail,
610
- emit,
611
595
  aipeekPlugin
612
596
  };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/plugin.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/plugin.ts
2
2
  var _fs = require('fs');
3
3
  var _path = require('path');
4
4
  var _url = require('url');
@@ -248,7 +248,7 @@ function truncate(s, max) {
248
248
  }
249
249
 
250
250
  // src/detail.ts
251
- async function detail(raw, section, index, full) {
251
+ function detail(raw, section, index, full) {
252
252
  switch (section) {
253
253
  case "ui":
254
254
  return full ? raw.ui || null : compactUI(raw.ui) || null;
@@ -279,7 +279,7 @@ function detailConsole(logs, index, full) {
279
279
  }
280
280
  return `[${log.level}] ${truncate2(log.text, 200)}`;
281
281
  }
282
- async function detailNetwork(requests, index, full) {
282
+ function detailNetwork(requests, index, full) {
283
283
  const i = Number.parseInt(_nullishCoalesce(index, () => ( "")));
284
284
  if (isNaN(i) || i < 0 || i >= requests.length)
285
285
  return null;
@@ -311,9 +311,9 @@ ${req.responseBody}`);
311
311
  if (req.requestBody) {
312
312
  lines.push(`request-body: ${byteSize(req.requestBody)}`);
313
313
  if (req.requestSample) {
314
- const ts = await quickTypeOrFallback(req.requestSample, "RequestBody");
315
- if (ts)
316
- lines.push(ts);
314
+ const schema = jsonSchema(req.requestSample);
315
+ if (schema)
316
+ lines.push(schema);
317
317
  }
318
318
  }
319
319
  if (req.responseBody) {
@@ -321,10 +321,10 @@ ${req.responseBody}`);
321
321
  lines.push(`response-body: ${byteSize(req.responseBody)} "${truncate2(req.responseBody, 100)}"`);
322
322
  } else {
323
323
  if (req.responseSample) {
324
- const ts = await quickTypeOrFallback(req.responseSample, "ResponseBody");
325
324
  lines.push(`response-body: ${byteSize(req.responseBody)}`);
326
- if (ts)
327
- lines.push(ts);
325
+ const schema = jsonSchema(req.responseSample);
326
+ if (schema)
327
+ lines.push(schema);
328
328
  } else {
329
329
  lines.push(`response-body: ${byteSize(req.responseBody)} ${truncate2(req.responseBody, 100)}`);
330
330
  }
@@ -333,23 +333,6 @@ ${req.responseBody}`);
333
333
  }
334
334
  return lines.join("\n");
335
335
  }
336
- async function quickTypeOrFallback(sample, typeName) {
337
- try {
338
- const { InputData, jsonInputForTargetLanguage, quicktype } = await Promise.resolve().then(() => _interopRequireWildcard(require("quicktype-core")));
339
- const jsonInput = jsonInputForTargetLanguage("typescript");
340
- await jsonInput.addSource({ name: typeName, samples: [sample] });
341
- const inputData = new InputData();
342
- inputData.addInput(jsonInput);
343
- const { lines } = await quicktype({
344
- inputData,
345
- lang: "typescript",
346
- rendererOptions: { "just-types": "true", "acronym-style": "original" }
347
- });
348
- return lines.join("\n");
349
- } catch (e3) {
350
- return jsonSchema(sample);
351
- }
352
- }
353
336
  function detailError(errors, index, full) {
354
337
  const i = Number.parseInt(_nullishCoalesce(index, () => ( "")));
355
338
  if (isNaN(i) || i < 0 || i >= errors.length)
@@ -385,7 +368,7 @@ function detailState(state, name, full) {
385
368
  if (full) {
386
369
  try {
387
370
  return JSON.stringify(value, null, 2);
388
- } catch (e4) {
371
+ } catch (e3) {
389
372
  return String(value);
390
373
  }
391
374
  }
@@ -416,7 +399,7 @@ function formatSummaryValue(v) {
416
399
  function jsonSchema(sample) {
417
400
  try {
418
401
  return schemaOf(JSON.parse(sample), 0);
419
- } catch (e5) {
402
+ } catch (e4) {
420
403
  return null;
421
404
  }
422
405
  }
@@ -516,20 +499,29 @@ curl ${base}/state # registered store snapshots
516
499
  Append \`?full\` for untruncated output. Append \`/{index}\` for a specific item's detail.
517
500
  `;
518
501
  }
502
+ var AIPEEK_HEADING = "# aipeek \u2014 Runtime Browser Inspector";
519
503
  function injectClaudeMd(root, port) {
520
504
  const path = _path.resolve.call(void 0, root, "CLAUDE.md");
521
505
  const snippet = aipeekSnippet(port);
522
506
  try {
523
- if (_fs.existsSync.call(void 0, path)) {
524
- const content = _fs.readFileSync.call(void 0, path, "utf-8");
525
- if (content.includes("__aipeek"))
526
- return;
507
+ if (!_fs.existsSync.call(void 0, path)) {
508
+ _fs.writeFileSync.call(void 0, path, snippet.trimStart());
509
+ return;
510
+ }
511
+ const content = _fs.readFileSync.call(void 0, path, "utf-8");
512
+ const start = content.indexOf(AIPEEK_HEADING);
513
+ if (start === -1) {
527
514
  _fs.writeFileSync.call(void 0, path, `${content.trimEnd()}
528
515
  ${snippet}`);
529
- } else {
530
- _fs.writeFileSync.call(void 0, path, snippet.trimStart());
516
+ return;
531
517
  }
532
- } catch (e6) {
518
+ const afterHeading = content.indexOf("\n", start);
519
+ const nextHeading = content.indexOf("\n# ", afterHeading);
520
+ const end = nextHeading === -1 ? content.length : nextHeading;
521
+ const before = content.slice(0, start).trimEnd();
522
+ const after = content.slice(end);
523
+ _fs.writeFileSync.call(void 0, path, before + (before ? "\n" : "") + snippet + after);
524
+ } catch (e5) {
533
525
  }
534
526
  }
535
527
  function aipeekPlugin() {
@@ -574,7 +566,7 @@ function aipeekPlugin() {
574
566
  if (parts.length >= 1) {
575
567
  if (!lastRaw)
576
568
  lastRaw = await collectFromClient();
577
- const result = await detail(lastRaw, parts[0], parts[1], full);
569
+ const result = detail(lastRaw, parts[0], parts[1], full);
578
570
  if (result !== null) {
579
571
  res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
580
572
  res.end(result);
@@ -601,12 +593,4 @@ function aipeekPlugin() {
601
593
 
602
594
 
603
595
 
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
- exports.compactUI = compactUI; exports.compactConsole = compactConsole; exports.compactNetwork = compactNetwork; exports.compactErrors = compactErrors; exports.compactState = compactState; exports.compact = compact; exports.detail = detail; exports.emit = emit; exports.aipeekPlugin = aipeekPlugin;
596
+ exports.aipeekPlugin = aipeekPlugin;
package/dist/cli.cjs CHANGED
@@ -13,11 +13,11 @@ async function main() {
13
13
  ${_picocolors2.default.bold("aipeek")} \u2014 runtime snapshot from Vite dev server
14
14
 
15
15
  ${_picocolors2.default.dim("Usage:")}
16
- aipeek Fetch from localhost:5195
16
+ aipeek Fetch from localhost:5173
17
17
  aipeek --port=3000 Fetch from localhost:3000
18
18
 
19
19
  ${_picocolors2.default.dim("Options:")}
20
- --port=<port> Dev server port (default: 5195)
20
+ --port=<port> Dev server port (default: 5173)
21
21
  --help Show this help
22
22
 
23
23
  ${_picocolors2.default.dim("Setup:")}
@@ -25,7 +25,7 @@ ${_picocolors2.default.dim("Setup:")}
25
25
  `);
26
26
  process.exit(0);
27
27
  }
28
- const port = flags.port || "5195";
28
+ const port = flags.port || "5173";
29
29
  const endpoint = `http://localhost:${port}/__aipeek`;
30
30
  const resp = await fetch(endpoint);
31
31
  if (!resp.ok) {
package/dist/cli.js CHANGED
@@ -13,11 +13,11 @@ async function main() {
13
13
  ${pc.bold("aipeek")} \u2014 runtime snapshot from Vite dev server
14
14
 
15
15
  ${pc.dim("Usage:")}
16
- aipeek Fetch from localhost:5195
16
+ aipeek Fetch from localhost:5173
17
17
  aipeek --port=3000 Fetch from localhost:3000
18
18
 
19
19
  ${pc.dim("Options:")}
20
- --port=<port> Dev server port (default: 5195)
20
+ --port=<port> Dev server port (default: 5173)
21
21
  --help Show this help
22
22
 
23
23
  ${pc.dim("Setup:")}
@@ -25,7 +25,7 @@ ${pc.dim("Setup:")}
25
25
  `);
26
26
  process.exit(0);
27
27
  }
28
- const port = flags.port || "5195";
28
+ const port = flags.port || "5173";
29
29
  const endpoint = `http://localhost:${port}/__aipeek`;
30
30
  const resp = await fetch(endpoint);
31
31
  if (!resp.ok) {
package/dist/index.cjs CHANGED
@@ -1,22 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
+ var _chunkP73WZQ2Rcjs = require('./chunk-P73WZQ2R.cjs');
3
4
 
4
5
 
5
-
6
-
7
-
8
-
9
-
10
-
11
- var _chunkKW232XW7cjs = require('./chunk-KW232XW7.cjs');
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
- exports.aipeekPlugin = _chunkKW232XW7cjs.aipeekPlugin; exports.compact = _chunkKW232XW7cjs.compact; exports.compactConsole = _chunkKW232XW7cjs.compactConsole; exports.compactErrors = _chunkKW232XW7cjs.compactErrors; exports.compactNetwork = _chunkKW232XW7cjs.compactNetwork; exports.compactState = _chunkKW232XW7cjs.compactState; exports.compactUI = _chunkKW232XW7cjs.compactUI; exports.detail = _chunkKW232XW7cjs.detail; exports.emit = _chunkKW232XW7cjs.emit;
6
+ exports.aipeekPlugin = _chunkP73WZQ2Rcjs.aipeekPlugin;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ declare function aipeekPlugin(): Plugin;
4
+
3
5
  interface LogEntry {
4
6
  level: 'error' | 'warn' | 'info' | 'debug' | 'log';
5
7
  text: string;
@@ -53,17 +55,4 @@ interface CompactState {
53
55
  };
54
56
  }
55
57
 
56
- declare function compactUI(tree: string): string;
57
- declare function compactConsole(logs: LogEntry[]): string;
58
- declare function compactNetwork(requests: NetworkRequest[]): string;
59
- declare function compactErrors(errors: ErrorEntry[]): string;
60
- declare function compactState(state: Record<string, unknown>): string;
61
- declare function compact(raw: RawState): CompactState;
62
-
63
- declare function detail(raw: RawState, section: string, index: string | undefined, full: boolean): Promise<string | null>;
64
-
65
- declare function emit(state: CompactState): string;
66
-
67
- declare function aipeekPlugin(): Plugin;
68
-
69
- export { type CompactState, type ErrorEntry, type LogEntry, type NetworkRequest, type RawState, aipeekPlugin, compact, compactConsole, compactErrors, compactNetwork, compactState, compactUI, detail, emit };
58
+ export { type CompactState, type RawState, aipeekPlugin };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ declare function aipeekPlugin(): Plugin;
4
+
3
5
  interface LogEntry {
4
6
  level: 'error' | 'warn' | 'info' | 'debug' | 'log';
5
7
  text: string;
@@ -53,17 +55,4 @@ interface CompactState {
53
55
  };
54
56
  }
55
57
 
56
- declare function compactUI(tree: string): string;
57
- declare function compactConsole(logs: LogEntry[]): string;
58
- declare function compactNetwork(requests: NetworkRequest[]): string;
59
- declare function compactErrors(errors: ErrorEntry[]): string;
60
- declare function compactState(state: Record<string, unknown>): string;
61
- declare function compact(raw: RawState): CompactState;
62
-
63
- declare function detail(raw: RawState, section: string, index: string | undefined, full: boolean): Promise<string | null>;
64
-
65
- declare function emit(state: CompactState): string;
66
-
67
- declare function aipeekPlugin(): Plugin;
68
-
69
- export { type CompactState, type ErrorEntry, type LogEntry, type NetworkRequest, type RawState, aipeekPlugin, compact, compactConsole, compactErrors, compactNetwork, compactState, compactUI, detail, emit };
58
+ export { type CompactState, type RawState, aipeekPlugin };
package/dist/index.js CHANGED
@@ -1,22 +1,6 @@
1
1
  import {
2
- aipeekPlugin,
3
- compact,
4
- compactConsole,
5
- compactErrors,
6
- compactNetwork,
7
- compactState,
8
- compactUI,
9
- detail,
10
- emit
11
- } from "./chunk-FI6MF54L.js";
2
+ aipeekPlugin
3
+ } from "./chunk-4PG5UWRS.js";
12
4
  export {
13
- aipeekPlugin,
14
- compact,
15
- compactConsole,
16
- compactErrors,
17
- compactNetwork,
18
- compactState,
19
- compactUI,
20
- detail,
21
- emit
5
+ aipeekPlugin
22
6
  };
package/dist/plugin.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkKW232XW7cjs = require('./chunk-KW232XW7.cjs');
3
+ var _chunkP73WZQ2Rcjs = require('./chunk-P73WZQ2R.cjs');
4
4
 
5
5
 
6
- exports.aipeekPlugin = _chunkKW232XW7cjs.aipeekPlugin;
6
+ exports.aipeekPlugin = _chunkP73WZQ2Rcjs.aipeekPlugin;
package/dist/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  aipeekPlugin
3
- } from "./chunk-FI6MF54L.js";
3
+ } from "./chunk-4PG5UWRS.js";
4
4
  export {
5
5
  aipeekPlugin
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipeek",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Gives AI a peek into your running browser app — UI tree, console, network, errors, state",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,8 +26,7 @@
26
26
  "test:watch": "vitest"
27
27
  },
28
28
  "dependencies": {
29
- "picocolors": "^1.1.1",
30
- "quicktype-core": "^23.2.6"
29
+ "picocolors": "^1.1.1"
31
30
  },
32
31
  "peerDependencies": {
33
32
  "vite": ">=5.0.0"