@inspecto-dev/plugin 0.3.9 → 0.3.11

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/dist/astro.d.cts CHANGED
@@ -6,7 +6,7 @@ interface AstroConfigSetupContext {
6
6
  injectScript: (stage: 'page' | 'head-inline' | 'before-hydration' | 'page-ssr', content: string) => void;
7
7
  updateConfig: (newConfig: Record<string, unknown>) => unknown;
8
8
  }
9
- declare function getAstroInjectedScript(serverPort: number): string;
9
+ declare function getAstroInjectedScript(serverPort: number, publicServerUrl?: string): string;
10
10
  declare function astroIntegration(options?: UnpluginOptions): {
11
11
  name: string;
12
12
  hooks: {
package/dist/astro.d.ts CHANGED
@@ -6,7 +6,7 @@ interface AstroConfigSetupContext {
6
6
  injectScript: (stage: 'page' | 'head-inline' | 'before-hydration' | 'page-ssr', content: string) => void;
7
7
  updateConfig: (newConfig: Record<string, unknown>) => unknown;
8
8
  }
9
- declare function getAstroInjectedScript(serverPort: number): string;
9
+ declare function getAstroInjectedScript(serverPort: number, publicServerUrl?: string): string;
10
10
  declare function astroIntegration(options?: UnpluginOptions): {
11
11
  name: string;
12
12
  hooks: {
package/dist/astro.js CHANGED
@@ -130,7 +130,8 @@ import { createDefu } from "defu";
130
130
  import {
131
131
  DEFAULT_PROVIDER_MODE,
132
132
  VALID_MODES,
133
- DEFAULT_INTENTS
133
+ DEFAULT_INTENTS,
134
+ isWorkflowConfig
134
135
  } from "@inspecto-dev/types";
135
136
 
136
137
  // src/utils/logger.ts
@@ -378,13 +379,28 @@ function resolveIntents(serverPrompts) {
378
379
  );
379
380
  continue;
380
381
  }
381
- if (!item.aiIntent) {
382
- configLogger.warn(`Intent "${item.id}" is missing required "aiIntent".`);
383
- continue;
382
+ if (item.kind === "workflow") {
383
+ if (!item.prompt) {
384
+ configLogger.warn(`Workflow "${item.id}" missing required "prompt", skipping`);
385
+ continue;
386
+ }
387
+ result.push({
388
+ kind: "workflow",
389
+ id: item.id,
390
+ label: item.label ?? item.id,
391
+ prompt: item.prompt,
392
+ confirm: item.confirm ?? false,
393
+ enabled: item.enabled ?? true
394
+ });
395
+ } else {
396
+ if (!item.aiIntent) {
397
+ configLogger.warn(`Intent "${item.id}" is missing required "aiIntent".`);
398
+ continue;
399
+ }
400
+ result.push(
401
+ baseMap.has(item.id) ? { ...baseMap.get(item.id), ...item } : item
402
+ );
384
403
  }
385
- result.push(
386
- baseMap.has(item.id) ? { ...baseMap.get(item.id), ...item } : item
387
- );
388
404
  }
389
405
  }
390
406
  return result;
@@ -404,26 +420,61 @@ function resolveIntents(serverPrompts) {
404
420
  configLogger.warn('Intent object missing required "id" field, skipping.');
405
421
  continue;
406
422
  }
407
- if (!item.aiIntent) {
408
- configLogger.warn(`Intent "${item.id}" is missing required "aiIntent".`);
409
- continue;
410
- }
411
- const existingIdx = merged.findIndex((i2) => i2.id === item.id);
412
- if (existingIdx !== -1) {
413
- if (item.enabled === false) {
414
- merged.splice(existingIdx, 1);
423
+ if (item.kind === "workflow") {
424
+ if (!item.prompt) {
425
+ configLogger.warn(`Workflow "${item.id}" missing required "prompt", skipping`);
426
+ continue;
427
+ }
428
+ const wfConfig = {
429
+ kind: "workflow",
430
+ id: item.id,
431
+ label: item.label ?? item.id,
432
+ prompt: item.prompt,
433
+ confirm: item.confirm ?? false,
434
+ enabled: item.enabled ?? true
435
+ };
436
+ const existingIdx = merged.findIndex((i2) => i2.id === item.id);
437
+ if (existingIdx !== -1) {
438
+ if (item.enabled === false) {
439
+ merged.splice(existingIdx, 1);
440
+ } else {
441
+ merged[existingIdx] = wfConfig;
442
+ }
415
443
  } else {
416
- merged[existingIdx] = { ...merged[existingIdx], ...item };
444
+ if (item.enabled !== false) {
445
+ merged.push(wfConfig);
446
+ }
417
447
  }
418
448
  } else {
419
- if (item.enabled !== false) {
420
- merged.push(item);
449
+ if (!item.aiIntent) {
450
+ configLogger.warn(`Intent "${item.id}" is missing required "aiIntent".`);
451
+ continue;
452
+ }
453
+ const existingIdx = merged.findIndex((i2) => i2.id === item.id);
454
+ if (existingIdx !== -1) {
455
+ if (item.enabled === false) {
456
+ merged.splice(existingIdx, 1);
457
+ } else {
458
+ merged[existingIdx] = { ...merged[existingIdx], ...item };
459
+ }
460
+ } else {
461
+ if (item.enabled !== false) {
462
+ merged.push(item);
463
+ }
421
464
  }
422
465
  }
423
466
  }
424
467
  }
425
468
  return merged;
426
469
  }
470
+ function resolveWorkflowSlots(intents) {
471
+ return intents.filter(isWorkflowConfig).filter((w3) => w3.enabled !== false).map((w3) => ({
472
+ id: w3.id,
473
+ label: w3.label ?? w3.id,
474
+ prompt: w3.prompt,
475
+ confirm: w3.confirm ?? false
476
+ }));
477
+ }
427
478
  var watchers = [];
428
479
  function watchConfig(onReload, cwd = process.cwd(), gitRoot) {
429
480
  if (isWatching) return;
@@ -653,6 +704,10 @@ function assertPathWithinIdeOpenScope(file, projectRoot) {
653
704
  }
654
705
  }
655
706
 
707
+ // src/server/annotation-dispatch.ts
708
+ import { exec } from "child_process";
709
+ import { promisify } from "util";
710
+
656
711
  // src/server/session-store.ts
657
712
  var DEFAULT_STATUS = "pending";
658
713
  function createAnnotationSessionStore(options = {}) {
@@ -660,8 +715,12 @@ function createAnnotationSessionStore(options = {}) {
660
715
  const listeners = /* @__PURE__ */ new Set();
661
716
  const now = options.now ?? (() => Date.now());
662
717
  const createId = options.createId ?? createRandomId;
663
- function findNewestMatchingSession(statuses) {
664
- return [...sessions.values()].filter((session) => statuses ? statuses.has(session.status) : true).sort((left, right) => right.updatedAt - left.updatedAt)[0] ?? null;
718
+ function findNewestMatchingSession(statuses, source) {
719
+ return [...sessions.values()].filter((session) => {
720
+ if (statuses && !statuses.has(session.status)) return false;
721
+ if (source && session.source !== source) return false;
722
+ return true;
723
+ }).sort((left, right) => right.updatedAt - left.updatedAt)[0] ?? null;
665
724
  }
666
725
  function updateSessionStatus(id, status) {
667
726
  const session = sessions.get(id);
@@ -721,7 +780,7 @@ function createAnnotationSessionStore(options = {}) {
721
780
  },
722
781
  async claimNextSession(options2 = {}) {
723
782
  const statuses = normalizeStatuses(DEFAULT_STATUS);
724
- const existingSession = findNewestMatchingSession(statuses);
783
+ const existingSession = findNewestMatchingSession(statuses, options2.source);
725
784
  if (existingSession) {
726
785
  return {
727
786
  session: claimSession(existingSession.id, statuses),
@@ -836,6 +895,7 @@ function cloneValue(value) {
836
895
  }
837
896
 
838
897
  // src/server/annotation-dispatch.ts
898
+ var execAsync = promisify(exec);
839
899
  var AnnotationDispatchError = class extends Error {
840
900
  constructor(message, errorCode) {
841
901
  super(message);
@@ -847,9 +907,14 @@ async function dispatchAnnotationsToAi(req, state, store = annotationSessionStor
847
907
  try {
848
908
  validateAnnotationDispatchRequest(req, state);
849
909
  const batch = normalizeAnnotationBatch(req);
850
- const prompt = buildAnnotationBatchPrompt(batch);
910
+ let prompt = buildAnnotationBatchPrompt(batch);
911
+ if (req.source === "workflow") {
912
+ prompt = await appendProjectMetadata(prompt, state);
913
+ }
851
914
  const deliveryMode = normalizeDeliveryMode(req.deliveryMode);
852
915
  const session = store.createSession({
916
+ source: req.source || "annotation",
917
+ ...req.workflowId ? { workflowId: req.workflowId } : {},
853
918
  instruction: batch.instruction,
854
919
  annotations: toSessionAnnotations(batch.annotations),
855
920
  deliveryMode,
@@ -875,6 +940,33 @@ async function dispatchAnnotationsToAi(req, state, store = annotationSessionStor
875
940
  };
876
941
  }
877
942
  }
943
+ async function appendProjectMetadata(prompt, state) {
944
+ const lines = ["\n## Project"];
945
+ lines.push(`- Root: ${state.projectRoot}`);
946
+ try {
947
+ const options = {
948
+ cwd: state.projectRoot,
949
+ encoding: "utf-8",
950
+ timeout: 2e3
951
+ };
952
+ const { stdout: branchStdout } = await execAsync("git branch --show-current", options);
953
+ const branch = branchStdout.trim();
954
+ lines.push(`- Branch: ${branch}`);
955
+ const { stdout: statusStdout } = await execAsync("git status --porcelain", options);
956
+ const statusRaw = statusStdout.trim();
957
+ const entries = statusRaw ? statusRaw.split("\n") : [];
958
+ const staged = entries.filter((l) => l[0] !== " " && l[0] !== "?").length;
959
+ const unstaged = entries.filter((l) => l[1] !== " " && l[1] !== "?").length;
960
+ const untracked = entries.filter((l) => l[0] === "?").length;
961
+ lines.push(`- Status: ${staged} staged, ${unstaged} unstaged, ${untracked} untracked`);
962
+ } catch (err) {
963
+ console.warn("[inspecto] Failed to get git status for workflow:", err);
964
+ lines.push("- Git: unavailable or check timeout");
965
+ }
966
+ return `${prompt}
967
+
968
+ ${lines.join("\n")}`;
969
+ }
878
970
  function normalizeDeliveryMode(input) {
879
971
  return input === "agent" ? "agent" : "ide";
880
972
  }
@@ -911,7 +1003,7 @@ function toSessionSummary(session) {
911
1003
  };
912
1004
  }
913
1005
  function validateAnnotationDispatchRequest(req, state) {
914
- if (!req.annotations.length) {
1006
+ if (!req.annotations.length && req.source !== "workflow") {
915
1007
  throw new AnnotationDispatchError("At least one annotation is required.", "INVALID_REQUEST");
916
1008
  }
917
1009
  for (const annotation of req.annotations) {
@@ -1013,6 +1105,7 @@ function getAnnotationDispatchErrorCode(error) {
1013
1105
  }
1014
1106
 
1015
1107
  // src/server/client-config.ts
1108
+ import { isAiIntentConfig } from "@inspecto-dev/types";
1016
1109
  async function buildClientConfig(serverState2) {
1017
1110
  const userConfig = loadUserConfigSync(false, serverState2.cwd, serverState2.configRoot);
1018
1111
  const promptsConfig = await loadPromptsConfig(false, serverState2.cwd, serverState2.configRoot);
@@ -1024,11 +1117,13 @@ async function buildClientConfig(serverState2) {
1024
1117
  const { scheme: _scheme, ...rest } = serverState2.ideInfo;
1025
1118
  info = rest;
1026
1119
  }
1120
+ const allIntents = resolveIntents(promptsConfig);
1027
1121
  return {
1028
1122
  ...info,
1029
- prompts: resolveIntents(promptsConfig),
1123
+ prompts: allIntents.filter(isAiIntentConfig),
1124
+ workflows: resolveWorkflowSlots(allIntents),
1030
1125
  hotKeys: userConfig["inspector.hotKey"] ?? "alt",
1031
- annotateDeliveryMode: userConfig["annotate.deliveryMode"] ?? "both",
1126
+ annotateDeliveryMode: userConfig["annotate.deliveryMode"] ?? "agent",
1032
1127
  includeSnippet: userConfig["prompt.includeSnippet"] ?? false,
1033
1128
  runtimeContext: {
1034
1129
  enabled: true,
@@ -1125,33 +1220,70 @@ import fs4 from "fs";
1125
1220
  import path4 from "path";
1126
1221
  import { execSync } from "child_process";
1127
1222
  var serverLogger3 = createLogger("inspecto:server", { logLevel: getGlobalLogLevel() });
1128
- function resolveProjectRoot() {
1129
- const cwd = process.cwd();
1130
- let gitRoot;
1223
+ function resolveGitRoot(_cwd) {
1131
1224
  try {
1132
- gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
1225
+ const output = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" });
1226
+ return typeof output === "string" ? output.trim() : null;
1133
1227
  } catch (e) {
1134
1228
  serverLogger3.warn("Failed to resolve git root via git rev-parse:", e);
1135
- gitRoot = cwd;
1136
- }
1137
- const visited = /* @__PURE__ */ new Set();
1138
- const search = (start, stop) => {
1139
- let current = start;
1140
- while (!visited.has(current)) {
1141
- visited.add(current);
1142
- if (fs4.existsSync(path4.join(current, ".inspecto"))) return current;
1143
- if (current === stop) break;
1144
- const parent = path4.dirname(current);
1145
- if (parent === current) break;
1146
- current = parent;
1147
- }
1148
1229
  return null;
1149
- };
1150
- const cwdMatch = search(cwd, path4.parse(cwd).root);
1151
- if (cwdMatch) return cwdMatch;
1152
- const repoMatch = search(gitRoot, path4.parse(gitRoot).root);
1153
- if (repoMatch) return repoMatch;
1154
- return gitRoot;
1230
+ }
1231
+ }
1232
+ function findNearestAncestorWith(start, predicate) {
1233
+ let current = start;
1234
+ while (true) {
1235
+ if (predicate(current)) return current;
1236
+ const parent = path4.dirname(current);
1237
+ if (parent === current) break;
1238
+ current = parent;
1239
+ }
1240
+ return null;
1241
+ }
1242
+ function resolveWorkspaceRoot() {
1243
+ const cwd = process.cwd();
1244
+ const inspectoRoot = findNearestAncestorWith(
1245
+ cwd,
1246
+ (dir) => fs4.existsSync(path4.join(dir, ".inspecto"))
1247
+ );
1248
+ if (inspectoRoot) return inspectoRoot;
1249
+ const packageRoot = findNearestAncestorWith(
1250
+ cwd,
1251
+ (dir) => fs4.existsSync(path4.join(dir, "package.json"))
1252
+ );
1253
+ if (packageRoot) return packageRoot;
1254
+ return resolveGitRoot(cwd) ?? cwd;
1255
+ }
1256
+ function resolveProjectRoot() {
1257
+ const cwd = process.cwd();
1258
+ const packageRoot = findNearestAncestorWith(
1259
+ cwd,
1260
+ (dir) => fs4.existsSync(path4.join(dir, "package.json"))
1261
+ );
1262
+ if (packageRoot) return packageRoot;
1263
+ const inspectoRoot = findNearestAncestorWith(
1264
+ cwd,
1265
+ (dir) => fs4.existsSync(path4.join(dir, ".inspecto"))
1266
+ );
1267
+ if (inspectoRoot) return inspectoRoot;
1268
+ return resolveGitRoot(cwd) ?? cwd;
1269
+ }
1270
+
1271
+ // src/server/server-url.ts
1272
+ function resolveServerHost(cwd, configRoot) {
1273
+ if (process.env["VITEST"]) return "127.0.0.1";
1274
+ const userConfig = loadUserConfigSync(false, cwd, configRoot);
1275
+ const configuredHost = userConfig["server.host"]?.trim();
1276
+ if (configuredHost) return configuredHost;
1277
+ return "127.0.0.1";
1278
+ }
1279
+ function resolvePublicServerUrl(args) {
1280
+ const userConfig = loadUserConfigSync(false, args.cwd, args.configRoot);
1281
+ const configuredPublicUrl = userConfig["server.publicUrl"]?.trim();
1282
+ if (configuredPublicUrl) {
1283
+ return configuredPublicUrl.replace(/\/$/, "");
1284
+ }
1285
+ const host = resolveServerHost(args.cwd, args.configRoot);
1286
+ return `http://${host}:${args.port}`;
1155
1287
  }
1156
1288
 
1157
1289
  // src/server/index.ts
@@ -1206,8 +1338,9 @@ async function startServer() {
1206
1338
  return serverState.port;
1207
1339
  }
1208
1340
  serverState.projectRoot = resolveProjectRoot();
1209
- serverState.configRoot = serverState.projectRoot;
1341
+ serverState.configRoot = resolveWorkspaceRoot();
1210
1342
  serverState.cwd = process.cwd();
1343
+ const serverHost = resolveServerHost(serverState.cwd, serverState.configRoot);
1211
1344
  portfinder.basePort = 5678;
1212
1345
  const port = await portfinder.getPortPromise();
1213
1346
  watchConfig(
@@ -1234,7 +1367,7 @@ async function startServer() {
1234
1367
  });
1235
1368
  });
1236
1369
  await new Promise((resolve2, reject) => {
1237
- serverInstance.listen(port, "0.0.0.0", () => {
1370
+ serverInstance.listen(port, serverHost, () => {
1238
1371
  serverInstance.unref();
1239
1372
  resolve2();
1240
1373
  });
@@ -1256,7 +1389,7 @@ async function startServer() {
1256
1389
  } catch {
1257
1390
  }
1258
1391
  });
1259
- serverLogger4.info(`server running at http://0.0.0.0:${port}`);
1392
+ serverLogger4.info(`server running at http://${serverHost}:${port}`);
1260
1393
  return port;
1261
1394
  }
1262
1395
  async function readBody(req) {
@@ -1618,10 +1751,23 @@ data: ${JSON.stringify({ ok: true })}
1618
1751
  }
1619
1752
  async function dispatchToAi(req) {
1620
1753
  const { location, snippet, prompt } = req;
1621
- const formattedPrompt = prompt ?? `Please help me with this code from \`${location.file}\` (line ${location.line}):
1754
+ if (prompt?.trim()) {
1755
+ const runtime2 = resolvePromptDispatchRuntime(serverState);
1756
+ return dispatchPromptThroughIde(runtime2, {
1757
+ prompt: prompt.trim()
1758
+ });
1759
+ }
1760
+ if (!location) {
1761
+ return {
1762
+ success: false,
1763
+ error: "Source location is required when prompt is omitted.",
1764
+ errorCode: "INVALID_REQUEST"
1765
+ };
1766
+ }
1767
+ const formattedPrompt = `Please help me with this code from \`${location.file}\` (line ${location.line}):
1622
1768
 
1623
1769
  \`\`\`
1624
- ${snippet}
1770
+ ${snippet ?? ""}
1625
1771
  \`\`\`
1626
1772
  `;
1627
1773
  const runtime = resolvePromptDispatchRuntime(serverState);
@@ -1630,7 +1776,7 @@ ${snippet}
1630
1776
  filePath: location.file,
1631
1777
  line: location.line,
1632
1778
  column: location.column,
1633
- snippet
1779
+ ...snippet !== void 0 ? { snippet } : {}
1634
1780
  });
1635
1781
  }
1636
1782
  function getBatchDispatchStatusCode(errorCode, success) {
@@ -2380,26 +2526,28 @@ var resolveClientModule = () => {
2380
2526
  };
2381
2527
 
2382
2528
  // src/injectors/webpack.ts
2383
- function getWebpackHtmlScript(serverPort) {
2529
+ function getWebpackHtmlScript(serverPort, publicServerUrl) {
2384
2530
  return `
2385
2531
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2532
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2386
2533
  window.addEventListener('load', () => {
2387
2534
  if (window.InspectoClient) {
2388
2535
  window.InspectoClient.mountInspector({
2389
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2536
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2390
2537
  });
2391
2538
  }
2392
2539
  });
2393
2540
  `;
2394
2541
  }
2395
- function getWebpackAssetScript(serverPort) {
2542
+ function getWebpackAssetScript(serverPort, publicServerUrl) {
2396
2543
  return `
2397
2544
  if (typeof window !== 'undefined') {
2398
2545
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2546
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2399
2547
  const _initInspecto = () => {
2400
2548
  if (window.InspectoClient) {
2401
2549
  window.InspectoClient.mountInspector({
2402
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2550
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2403
2551
  });
2404
2552
  } else {
2405
2553
  setTimeout(_initInspecto, 100);
@@ -2413,7 +2561,7 @@ if (typeof window !== 'undefined') {
2413
2561
  }
2414
2562
  `;
2415
2563
  }
2416
- function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2564
+ function injectWebpack(compiler, serverPortFn, publicServerUrlFn, resolveClientModule2) {
2417
2565
  const inspectoClientPath = resolveClientModule2();
2418
2566
  if (compiler.webpack && compiler.webpack.EntryPlugin) {
2419
2567
  new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {
@@ -2428,11 +2576,12 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2428
2576
  const hooks = HtmlWebpackPlugin.constructor.getHooks(compilation);
2429
2577
  hooks.alterAssetTagGroups.tapPromise("inspecto-overlay", async (data) => {
2430
2578
  const port = await serverPortFn();
2579
+ const publicServerUrl = publicServerUrlFn(port);
2431
2580
  data.headTags.unshift({
2432
2581
  tagName: "script",
2433
2582
  voidTag: false,
2434
2583
  meta: { plugin: "inspecto-overlay" },
2435
- innerHTML: getWebpackHtmlScript(port)
2584
+ innerHTML: getWebpackHtmlScript(port, publicServerUrl)
2436
2585
  });
2437
2586
  return data;
2438
2587
  });
@@ -2445,13 +2594,14 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2445
2594
  },
2446
2595
  async (assets) => {
2447
2596
  const port = await serverPortFn();
2597
+ const publicServerUrl = publicServerUrlFn(port);
2448
2598
  const mainAssetKey = Object.keys(assets).find(
2449
2599
  (key) => key.endsWith(".js") && (key.includes("main") || key.includes("app") || key.includes("umi"))
2450
2600
  );
2451
2601
  if (!mainAssetKey) return;
2452
2602
  const originalSource = assets[mainAssetKey].source();
2453
2603
  assets[mainAssetKey] = new compiler.webpack.sources.RawSource(
2454
- getWebpackAssetScript(port) + "\n" + originalSource
2604
+ getWebpackAssetScript(port, publicServerUrl) + "\n" + originalSource
2455
2605
  );
2456
2606
  }
2457
2607
  );
@@ -2485,12 +2635,13 @@ function injectRspack(compiler, serverPortFn, resolveClientModule2) {
2485
2635
  }
2486
2636
 
2487
2637
  // src/injectors/vite.ts
2488
- function getViteVirtualModuleScript(serverPort) {
2638
+ function getViteVirtualModuleScript(serverPort, publicServerUrl) {
2489
2639
  return `
2490
2640
  import { mountInspector } from '@inspecto-dev/core';
2491
2641
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2642
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2492
2643
  mountInspector({
2493
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2644
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2494
2645
  });
2495
2646
  `;
2496
2647
  }
@@ -2523,6 +2674,11 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2523
2674
  }
2524
2675
  return serverPort;
2525
2676
  };
2677
+ const getPublicServerUrl = (port) => resolvePublicServerUrl({
2678
+ cwd: serverState.cwd || process.cwd(),
2679
+ configRoot: serverState.configRoot || projectRoot,
2680
+ port
2681
+ });
2526
2682
  return {
2527
2683
  name: "inspecto-overlay",
2528
2684
  enforce: "pre",
@@ -2535,7 +2691,7 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2535
2691
  },
2536
2692
  webpack: (compiler) => {
2537
2693
  if (isProduction) return;
2538
- injectWebpack(compiler, ensureServer, resolveClientModule);
2694
+ injectWebpack(compiler, ensureServer, getPublicServerUrl, resolveClientModule);
2539
2695
  },
2540
2696
  rspack: (compiler) => {
2541
2697
  if (isProduction) return;
@@ -2561,7 +2717,10 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2561
2717
  },
2562
2718
  load(id) {
2563
2719
  if (id === VITE_VIRTUAL_MODULE_ID) {
2564
- return getViteVirtualModuleScript(serverPort ?? DEFAULT_PORT);
2720
+ return getViteVirtualModuleScript(
2721
+ serverPort ?? DEFAULT_PORT,
2722
+ getPublicServerUrl(serverPort ?? DEFAULT_PORT)
2723
+ );
2565
2724
  }
2566
2725
  return null;
2567
2726
  },
@@ -2619,10 +2778,10 @@ var rollupPlugin = InspectoPlugin.rollup;
2619
2778
  var esbuildPlugin = InspectoPlugin.esbuild;
2620
2779
 
2621
2780
  // src/astro.ts
2622
- function getAstroInjectedScript(serverPort) {
2781
+ function getAstroInjectedScript(serverPort, publicServerUrl) {
2623
2782
  return `
2624
2783
  import { mountInspector } from '@inspecto-dev/core';
2625
- window.__AI_INSPECTOR_SERVER_URL__ = 'http://0.0.0.0:${serverPort}';
2784
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2626
2785
  mountInspector({
2627
2786
  serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2628
2787
  });
@@ -2642,7 +2801,17 @@ function astroIntegration(options) {
2642
2801
  return;
2643
2802
  }
2644
2803
  const serverPort = await startServer();
2645
- injectScript("page", getAstroInjectedScript(serverPort));
2804
+ injectScript(
2805
+ "page",
2806
+ getAstroInjectedScript(
2807
+ serverPort,
2808
+ resolvePublicServerUrl({
2809
+ cwd: serverState.cwd || process.cwd(),
2810
+ configRoot: serverState.configRoot || process.cwd(),
2811
+ port: serverPort
2812
+ })
2813
+ )
2814
+ );
2646
2815
  }
2647
2816
  }
2648
2817
  };