agentdev 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.
@@ -4804,8 +4804,10 @@ function generateViewerHtml(port) {
4804
4804
  return '/template/agentdev/' + mapped + '.render.js';
4805
4805
  }
4806
4806
 
4807
- // 3. \u515C\u5E95\uFF1A\u4F7F\u7528 /template/agentdev/{template}.render.js
4808
- return '/template/agentdev/' + templateName + '.render.js';
4807
+ // 3. \u515C\u5E95\uFF1A\u8FD4\u56DE null\uFF0C\u8BA9\u8C03\u7528\u8005\u7B49\u5F85\u6216\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F
4808
+ // \u4E0D\u518D\u76F2\u76EE\u751F\u6210\u9519\u8BEF\u7684URL\uFF0C\u800C\u662F\u7B49\u5F85 FEATURE_TEMPLATE_MAP \u52A0\u8F7D\u5B8C\u6210
4809
+ console.warn('[Viewer] Template "' + templateName + '" not found in FEATURE_TEMPLATE_MAP or SYSTEM_TEMPLATE_MAP, waiting...');
4810
+ return null;
4809
4811
  }
4810
4812
 
4811
4813
  /**
@@ -4813,7 +4815,7 @@ function generateViewerHtml(port) {
4813
4815
  * \u652F\u6301\u4ECE Feature \u76EE\u5F55\u6216\u7CFB\u7EDF\u76EE\u5F55\u52A0\u8F7D
4814
4816
  * \u5982\u679C\u52A0\u8F7D\u5931\u8D25\uFF0C\u56DE\u9000\u5230\u5185\u7F6E\u6A21\u677F
4815
4817
  */
4816
- async function loadTemplate(templateName) {
4818
+ async function loadTemplate(templateName, retryCount = 0) {
4817
4819
  if (templateCache.has(templateName)) {
4818
4820
  return templateCache.get(templateName);
4819
4821
  }
@@ -4827,6 +4829,24 @@ function generateViewerHtml(port) {
4827
4829
  try {
4828
4830
  const path = resolveTemplatePath(templateName);
4829
4831
 
4832
+ // \u5982\u679C path \u4E3A null\uFF0C\u8BF4\u660E FEATURE_TEMPLATE_MAP \u8FD8\u672A\u52A0\u8F7D\u5B8C\u6210
4833
+ if (!path) {
4834
+ // \u6700\u591A\u91CD\u8BD5 3 \u6B21\uFF0C\u6BCF\u6B21\u7B49\u5F85 500ms
4835
+ if (retryCount < 3) {
4836
+ console.log('[Viewer] Waiting for FEATURE_TEMPLATE_MAP to load... (attempt ' + (retryCount + 1) + ')');
4837
+ await new Promise(resolve => setTimeout(resolve, 500));
4838
+ // \u91CD\u65B0\u52A0\u8F7D\u6A21\u677F\u6620\u5C04
4839
+ await loadFeatureTemplateMap();
4840
+ return loadTemplate(templateName, retryCount + 1);
4841
+ }
4842
+ console.warn('[Viewer] Template "' + templateName + '" not found after retries');
4843
+ // \u56DE\u9000\u5230\u5185\u7F6E json \u6A21\u677F
4844
+ if (RENDER_TEMPLATES['json']) {
4845
+ return RENDER_TEMPLATES['json'];
4846
+ }
4847
+ return null;
4848
+ }
4849
+
4830
4850
  // \u7EDF\u4E00\u4F7F\u7528 URL \u65B9\u5F0F\u52A0\u8F7D\u6A21\u677F
4831
4851
  // Feature \u6A21\u677F: /template/agentdev/shell/bash.render.js
4832
4852
  const module = await import(path);
@@ -6258,6 +6278,10 @@ var ViewerWorker = class {
6258
6278
  this.handleNpmFeatureTemplate(req, res, url);
6259
6279
  return;
6260
6280
  }
6281
+ if (/^\/(chunk-|BasicAgent-|ExplorerAgent-|notification-|resolver-|types-|index\.js).*$/.test(url)) {
6282
+ this.handleStaticAsset(req, res, url);
6283
+ return;
6284
+ }
6261
6285
  res.writeHead(404);
6262
6286
  res.end("Not Found");
6263
6287
  }
@@ -7502,6 +7526,28 @@ var ViewerWorker = class {
7502
7526
  res.end("Internal server error");
7503
7527
  }
7504
7528
  }
7529
+ /**
7530
+ * 处理静态资源文件(chunk、js、css 等)
7531
+ * 支持 agentdev npm 包中的共享模块
7532
+ */
7533
+ handleStaticAsset(req, res, url) {
7534
+ try {
7535
+ const session = this.currentAgentId ? this.agentSessions.get(this.currentAgentId) : void 0;
7536
+ const projectRoot = session?.projectRoot || process.cwd();
7537
+ const fileName = url.substring(1);
7538
+ const searchPaths = [
7539
+ // npm 包模式:node_modules/agentdev/dist/{file}
7540
+ join(projectRoot, "node_modules", "agentdev", "dist", fileName),
7541
+ // 开发模式:项目根目录 dist/{file}
7542
+ join(projectRoot, "dist", fileName)
7543
+ ];
7544
+ this.tryReadFile(searchPaths, 0, res, url);
7545
+ } catch (err) {
7546
+ console.error("[Viewer Worker] \u9759\u6001\u8D44\u6E90\u5904\u7406\u9519\u8BEF:", err.message);
7547
+ res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
7548
+ res.end("Internal server error");
7549
+ }
7550
+ }
7505
7551
  // ========== HTML 生成(复用原有代码)==========
7506
7552
  getHtml() {
7507
7553
  return generateViewerHtml(this.port);
@@ -7575,4 +7621,4 @@ if (isMainModule(import.meta.url)) {
7575
7621
  export {
7576
7622
  ViewerWorker
7577
7623
  };
7578
- //# sourceMappingURL=chunk-FZGM6EMW.js.map
7624
+ //# sourceMappingURL=chunk-LLV3W326.js.map