@standardagents/builder 0.12.6 → 0.12.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.
@@ -5,7 +5,6 @@ import * as z124 from 'zod/v4';
5
5
  import z175 from 'zod/v3';
6
6
  import * as fs2 from 'fs';
7
7
  import * as path2 from 'path';
8
- import * as ts from 'typescript';
9
8
  import MagicString from 'magic-string';
10
9
  import { exec } from 'child_process';
11
10
  import { promisify } from 'util';
@@ -22114,7 +22113,12 @@ var init_metadata_service = __esm({
22114
22113
  };
22115
22114
  }
22116
22115
  });
22117
- function extractToolUses(sourceCode) {
22116
+ async function loadTypeScript() {
22117
+ if (!_ts) _ts = await import('typescript');
22118
+ return _ts;
22119
+ }
22120
+ async function extractToolUses(sourceCode) {
22121
+ const ts = await loadTypeScript();
22118
22122
  const sourceFile = ts.createSourceFile(
22119
22123
  "tool.ts",
22120
22124
  sourceCode,
@@ -22145,7 +22149,8 @@ function extractToolUses(sourceCode) {
22145
22149
  visit(sourceFile);
22146
22150
  return result;
22147
22151
  }
22148
- function extractPromptTools(sourceCode) {
22152
+ async function extractPromptTools(sourceCode) {
22153
+ const ts = await loadTypeScript();
22149
22154
  const sourceFile = ts.createSourceFile(
22150
22155
  "prompt.ts",
22151
22156
  sourceCode,
@@ -22181,7 +22186,8 @@ function extractPromptTools(sourceCode) {
22181
22186
  visit(sourceFile);
22182
22187
  return result;
22183
22188
  }
22184
- function extractPromptModel(sourceCode) {
22189
+ async function extractPromptModel(sourceCode) {
22190
+ const ts = await loadTypeScript();
22185
22191
  const sourceFile = ts.createSourceFile(
22186
22192
  "prompt.ts",
22187
22193
  sourceCode,
@@ -22203,7 +22209,8 @@ function extractPromptModel(sourceCode) {
22203
22209
  visit(sourceFile);
22204
22210
  return model;
22205
22211
  }
22206
- function extractPromptIncludes(sourceCode) {
22212
+ async function extractPromptIncludes(sourceCode) {
22213
+ const ts = await loadTypeScript();
22207
22214
  const sourceFile = ts.createSourceFile(
22208
22215
  "prompt.ts",
22209
22216
  sourceCode,
@@ -22255,7 +22262,8 @@ function extractPromptIncludes(sourceCode) {
22255
22262
  visit(sourceFile);
22256
22263
  return includes;
22257
22264
  }
22258
- function extractAgentPrompts(sourceCode) {
22265
+ async function extractAgentPrompts(sourceCode) {
22266
+ const ts = await loadTypeScript();
22259
22267
  const sourceFile = ts.createSourceFile(
22260
22268
  "agent.ts",
22261
22269
  sourceCode,
@@ -22290,7 +22298,8 @@ function extractAgentPrompts(sourceCode) {
22290
22298
  visit(sourceFile);
22291
22299
  return result;
22292
22300
  }
22293
- function extractAgentDescription(sourceCode) {
22301
+ async function extractAgentDescription(sourceCode) {
22302
+ const ts = await loadTypeScript();
22294
22303
  const sourceFile = ts.createSourceFile(
22295
22304
  "agent.ts",
22296
22305
  sourceCode,
@@ -22312,7 +22321,8 @@ function extractAgentDescription(sourceCode) {
22312
22321
  visit(sourceFile);
22313
22322
  return description;
22314
22323
  }
22315
- function extractDefinitionName(sourceCode) {
22324
+ async function extractDefinitionName(sourceCode) {
22325
+ const ts = await loadTypeScript();
22316
22326
  const sourceFile = ts.createSourceFile(
22317
22327
  "def.ts",
22318
22328
  sourceCode,
@@ -22334,7 +22344,8 @@ function extractDefinitionName(sourceCode) {
22334
22344
  visit(sourceFile);
22335
22345
  return name;
22336
22346
  }
22337
- function extractModelFallbacks(sourceCode) {
22347
+ async function extractModelFallbacks(sourceCode) {
22348
+ const ts = await loadTypeScript();
22338
22349
  const sourceFile = ts.createSourceFile(
22339
22350
  "model.ts",
22340
22351
  sourceCode,
@@ -22360,7 +22371,8 @@ function extractModelFallbacks(sourceCode) {
22360
22371
  visit(sourceFile);
22361
22372
  return fallbacks;
22362
22373
  }
22363
- function transformBundledJs(code) {
22374
+ async function transformBundledJs(code) {
22375
+ const ts = await loadTypeScript();
22364
22376
  const s = new MagicString(code);
22365
22377
  const sourceFile = ts.createSourceFile(
22366
22378
  "file.js",
@@ -22406,10 +22418,11 @@ function transformBundledJs(code) {
22406
22418
  }
22407
22419
  return s.toString().trim() + "\n";
22408
22420
  }
22409
- function injectAgentMetadata(tsCode, metadata) {
22421
+ async function injectAgentMetadata(tsCode, metadata) {
22410
22422
  if (!metadata.packageName && !metadata.version && !metadata.author && !metadata.license) {
22411
22423
  return tsCode;
22412
22424
  }
22425
+ const ts = await loadTypeScript();
22413
22426
  const s = new MagicString(tsCode);
22414
22427
  const sourceFile = ts.createSourceFile(
22415
22428
  "agent.ts",
@@ -22457,6 +22470,7 @@ function injectAgentMetadata(tsCode, metadata) {
22457
22470
  visit(sourceFile);
22458
22471
  return s.toString();
22459
22472
  }
22473
+ var _ts;
22460
22474
  var init_ast_utils = __esm({
22461
22475
  "src/packing/ast-utils.ts"() {
22462
22476
  }
@@ -22520,7 +22534,7 @@ var init_packing_service = __esm({
22520
22534
  warnings: [],
22521
22535
  errors: []
22522
22536
  };
22523
- const agentFilePath = this.findFile(path2.join(agentsDir, "agents"), agentName);
22537
+ const agentFilePath = await this.findFile(path2.join(agentsDir, "agents"), agentName);
22524
22538
  if (!agentFilePath) {
22525
22539
  analysis.errors.push(`Agent file not found: ${agentName}`);
22526
22540
  return analysis;
@@ -22532,7 +22546,7 @@ var init_packing_service = __esm({
22532
22546
  sharedWith: []
22533
22547
  });
22534
22548
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
22535
- const agentPrompts = extractAgentPrompts(agentSource);
22549
+ const agentPrompts = await extractAgentPrompts(agentSource);
22536
22550
  if (agentPrompts.sideA) {
22537
22551
  analysis.primaryPrompt = agentPrompts.sideA;
22538
22552
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, /* @__PURE__ */ new Set(), `agent:${agentName}`);
@@ -22553,7 +22567,7 @@ var init_packing_service = __esm({
22553
22567
  * @param rootDir - Root directory of the project
22554
22568
  * @returns Object with generatedReadme and agentDescription
22555
22569
  */
22556
- generateReadmeForAnalysis(analysis, rootDir) {
22570
+ async generateReadmeForAnalysis(analysis, rootDir) {
22557
22571
  const agentsDir = path2.join(rootDir, "agents");
22558
22572
  const metadataService = new MetadataService(agentsDir);
22559
22573
  let agentDescription;
@@ -22561,7 +22575,7 @@ var init_packing_service = __esm({
22561
22575
  if (agentItem?.filePath) {
22562
22576
  try {
22563
22577
  const agentSource = fs2.readFileSync(agentItem.filePath, "utf-8");
22564
- agentDescription = extractAgentDescription(agentSource) || void 0;
22578
+ agentDescription = await extractAgentDescription(agentSource) || void 0;
22565
22579
  } catch {
22566
22580
  }
22567
22581
  }
@@ -22581,7 +22595,7 @@ var init_packing_service = __esm({
22581
22595
  * Recursively analyze a prompt and its dependencies.
22582
22596
  */
22583
22597
  async analyzePrompt(promptName, agentsDir, analysis, visited, parentKey) {
22584
- const promptFilePath = this.findFile(path2.join(agentsDir, "prompts"), promptName);
22598
+ const promptFilePath = await this.findFile(path2.join(agentsDir, "prompts"), promptName);
22585
22599
  if (!promptFilePath) {
22586
22600
  analysis.warnings.push(`Prompt file not found: ${promptName}`);
22587
22601
  return;
@@ -22601,15 +22615,15 @@ var init_packing_service = __esm({
22601
22615
  }
22602
22616
  visited.add(`prompt:${promptName}`);
22603
22617
  const promptSource = fs2.readFileSync(promptFilePath, "utf-8");
22604
- const modelName = extractPromptModel(promptSource);
22618
+ const modelName = await extractPromptModel(promptSource);
22605
22619
  if (modelName) {
22606
22620
  await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
22607
22621
  }
22608
- const { tools: toolNames } = extractPromptTools(promptSource);
22622
+ const { tools: toolNames } = await extractPromptTools(promptSource);
22609
22623
  for (const toolName of toolNames) {
22610
22624
  await this.analyzeTool(toolName, agentsDir, analysis, visited, "prompt-tools", thisKey);
22611
22625
  }
22612
- const includedPrompts = extractPromptIncludes(promptSource);
22626
+ const includedPrompts = await extractPromptIncludes(promptSource);
22613
22627
  for (const includedPrompt of includedPrompts) {
22614
22628
  const item = analysis.constituents.prompts.find((p) => p.name === includedPrompt);
22615
22629
  if (item) {
@@ -22626,17 +22640,17 @@ var init_packing_service = __esm({
22626
22640
  */
22627
22641
  async analyzeTool(toolName, agentsDir, analysis, visited, discoveredVia, parentKey) {
22628
22642
  const thisKey = `tool:${toolName}`;
22629
- const promptFilePath = this.findFile(path2.join(agentsDir, "prompts"), toolName);
22643
+ const promptFilePath = await this.findFile(path2.join(agentsDir, "prompts"), toolName);
22630
22644
  if (promptFilePath) {
22631
22645
  await this.analyzePrompt(toolName, agentsDir, analysis, visited, parentKey);
22632
22646
  return;
22633
22647
  }
22634
- const agentFilePath = this.findFile(path2.join(agentsDir, "agents"), toolName);
22648
+ const agentFilePath = await this.findFile(path2.join(agentsDir, "agents"), toolName);
22635
22649
  if (agentFilePath) {
22636
22650
  await this.analyzeNestedAgent(toolName, agentsDir, analysis, visited, parentKey);
22637
22651
  return;
22638
22652
  }
22639
- const toolFilePath = this.findFile(path2.join(agentsDir, "tools"), toolName);
22653
+ const toolFilePath = await this.findFile(path2.join(agentsDir, "tools"), toolName);
22640
22654
  if (!toolFilePath) {
22641
22655
  analysis.warnings.push(`Tool file not found: ${toolName}`);
22642
22656
  return;
@@ -22655,7 +22669,7 @@ var init_packing_service = __esm({
22655
22669
  }
22656
22670
  visited.add(`tool:${toolName}`);
22657
22671
  const toolSource = fs2.readFileSync(toolFilePath, "utf-8");
22658
- const { uses } = extractToolUses(toolSource);
22672
+ const { uses } = await extractToolUses(toolSource);
22659
22673
  for (const usedItem of uses) {
22660
22674
  await this.analyzeTool(usedItem, agentsDir, analysis, visited, "uses", thisKey);
22661
22675
  }
@@ -22664,7 +22678,7 @@ var init_packing_service = __esm({
22664
22678
  * Analyze a nested agent (used as a handoff target).
22665
22679
  */
22666
22680
  async analyzeNestedAgent(agentName, agentsDir, analysis, visited, parentKey) {
22667
- const agentFilePath = this.findFile(path2.join(agentsDir, "agents"), agentName);
22681
+ const agentFilePath = await this.findFile(path2.join(agentsDir, "agents"), agentName);
22668
22682
  if (!agentFilePath) {
22669
22683
  analysis.warnings.push(`Agent file not found: ${agentName}`);
22670
22684
  return;
@@ -22684,7 +22698,7 @@ var init_packing_service = __esm({
22684
22698
  }
22685
22699
  visited.add(`agent:${agentName}`);
22686
22700
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
22687
- const agentPrompts = extractAgentPrompts(agentSource);
22701
+ const agentPrompts = await extractAgentPrompts(agentSource);
22688
22702
  if (agentPrompts.sideA) {
22689
22703
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
22690
22704
  }
@@ -22696,7 +22710,7 @@ var init_packing_service = __esm({
22696
22710
  * Analyze a model and its fallbacks.
22697
22711
  */
22698
22712
  async analyzeModel(modelName, agentsDir, analysis, visited, parentKey) {
22699
- const modelFilePath = this.findFile(path2.join(agentsDir, "models"), modelName);
22713
+ const modelFilePath = await this.findFile(path2.join(agentsDir, "models"), modelName);
22700
22714
  if (!modelFilePath) {
22701
22715
  analysis.warnings.push(`Model file not found: ${modelName}`);
22702
22716
  return;
@@ -22716,7 +22730,7 @@ var init_packing_service = __esm({
22716
22730
  }
22717
22731
  visited.add(`model:${modelName}`);
22718
22732
  const modelSource = fs2.readFileSync(modelFilePath, "utf-8");
22719
- const fallbacks = extractModelFallbacks(modelSource);
22733
+ const fallbacks = await extractModelFallbacks(modelSource);
22720
22734
  for (const fallbackName of fallbacks) {
22721
22735
  await this.analyzeModel(fallbackName, agentsDir, analysis, visited, thisKey);
22722
22736
  }
@@ -22765,34 +22779,34 @@ var init_packing_service = __esm({
22765
22779
  const result = { prompts: [], tools: [], models: [] };
22766
22780
  const agentsDir = path2.join(rootDir, "agents");
22767
22781
  const visited = /* @__PURE__ */ new Set();
22768
- const agentFilePath = this.findFile(path2.join(agentsDir, "agents"), agentName);
22782
+ const agentFilePath = await this.findFile(path2.join(agentsDir, "agents"), agentName);
22769
22783
  if (!agentFilePath) return result;
22770
22784
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
22771
- const agentPrompts = extractAgentPrompts(agentSource);
22772
- const analyzePromptLight = (promptName) => {
22785
+ const agentPrompts = await extractAgentPrompts(agentSource);
22786
+ const analyzePromptLight = async (promptName) => {
22773
22787
  if (visited.has(promptName)) return;
22774
22788
  visited.add(promptName);
22775
22789
  result.prompts.push(promptName);
22776
- const promptFilePath = this.findFile(path2.join(agentsDir, "prompts"), promptName);
22790
+ const promptFilePath = await this.findFile(path2.join(agentsDir, "prompts"), promptName);
22777
22791
  if (!promptFilePath) return;
22778
22792
  const promptSource = fs2.readFileSync(promptFilePath, "utf-8");
22779
- const modelName = extractPromptModel(promptSource);
22793
+ const modelName = await extractPromptModel(promptSource);
22780
22794
  if (modelName && !result.models.includes(modelName)) {
22781
22795
  result.models.push(modelName);
22782
22796
  }
22783
- const { tools } = extractPromptTools(promptSource);
22797
+ const { tools } = await extractPromptTools(promptSource);
22784
22798
  for (const tool2 of tools) {
22785
22799
  if (!result.tools.includes(tool2)) {
22786
22800
  result.tools.push(tool2);
22787
22801
  }
22788
22802
  }
22789
- const includes = extractPromptIncludes(promptSource);
22803
+ const includes = await extractPromptIncludes(promptSource);
22790
22804
  for (const inc of includes) {
22791
- analyzePromptLight(inc);
22805
+ await analyzePromptLight(inc);
22792
22806
  }
22793
22807
  };
22794
- if (agentPrompts.sideA) analyzePromptLight(agentPrompts.sideA);
22795
- if (agentPrompts.sideB) analyzePromptLight(agentPrompts.sideB);
22808
+ if (agentPrompts.sideA) await analyzePromptLight(agentPrompts.sideA);
22809
+ if (agentPrompts.sideB) await analyzePromptLight(agentPrompts.sideB);
22796
22810
  return result;
22797
22811
  }
22798
22812
  /**
@@ -22937,7 +22951,7 @@ var init_packing_service = __esm({
22937
22951
  let agentDescription;
22938
22952
  if (agentItem?.filePath) {
22939
22953
  const agentSource = fs2.readFileSync(agentItem.filePath, "utf-8");
22940
- agentDescription = extractAgentDescription(agentSource) || void 0;
22954
+ agentDescription = await extractAgentDescription(agentSource) || void 0;
22941
22955
  }
22942
22956
  readmeContent = this.generateReadme(
22943
22957
  finalPackageName,
@@ -23537,7 +23551,7 @@ ${license || "See LICENSE file"}
23537
23551
  /**
23538
23552
  * Find a file by name in a directory.
23539
23553
  */
23540
- findFile(dir, name) {
23554
+ async findFile(dir, name) {
23541
23555
  if (!fs2.existsSync(dir)) {
23542
23556
  return null;
23543
23557
  }
@@ -23549,7 +23563,7 @@ ${license || "See LICENSE file"}
23549
23563
  for (const file of files) {
23550
23564
  const filePath = path2.join(dir, file);
23551
23565
  const source = fs2.readFileSync(filePath, "utf-8");
23552
- const extractedName = extractDefinitionName(source);
23566
+ const extractedName = await extractDefinitionName(source);
23553
23567
  if (extractedName === name) {
23554
23568
  return filePath;
23555
23569
  }
@@ -23559,7 +23573,7 @@ ${license || "See LICENSE file"}
23559
23573
  /**
23560
23574
  * List all agents in the workspace.
23561
23575
  */
23562
- listAgents(rootDir) {
23576
+ async listAgents(rootDir) {
23563
23577
  const agentsDir = path2.join(rootDir, "agents", "agents");
23564
23578
  if (!fs2.existsSync(agentsDir)) {
23565
23579
  return [];
@@ -23569,7 +23583,7 @@ ${license || "See LICENSE file"}
23569
23583
  for (const file of files) {
23570
23584
  const filePath = path2.join(agentsDir, file);
23571
23585
  const source = fs2.readFileSync(filePath, "utf-8");
23572
- const name = extractDefinitionName(source);
23586
+ const name = await extractDefinitionName(source);
23573
23587
  if (name) {
23574
23588
  agents.push(name);
23575
23589
  } else {
@@ -23849,7 +23863,7 @@ var init_unpacking_service = __esm({
23849
23863
  return analysis;
23850
23864
  }
23851
23865
  const indexContent = fs2.readFileSync(indexPath, "utf-8");
23852
- const registryItems = this.parseIndexExports(indexContent);
23866
+ const registryItems = await this.parseIndexExports(indexContent);
23853
23867
  const availableItems = /* @__PURE__ */ new Map();
23854
23868
  for (const item of registryItems) {
23855
23869
  availableItems.set(`${item.type}:${item.name}`, item);
@@ -23866,7 +23880,7 @@ var init_unpacking_service = __esm({
23866
23880
  continue;
23867
23881
  }
23868
23882
  const bundledCode = fs2.readFileSync(sourcePath, "utf-8");
23869
- const children = this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
23883
+ const children = await this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
23870
23884
  itemsWithRelations.push({
23871
23885
  name: item.name,
23872
23886
  type: item.type,
@@ -23907,10 +23921,10 @@ var init_unpacking_service = __esm({
23907
23921
  * Discover relationships from a bundled file.
23908
23922
  * Returns child items that this item references.
23909
23923
  */
23910
- discoverRelationships(type, name, bundledCode, availableItems) {
23924
+ async discoverRelationships(type, name, bundledCode, availableItems) {
23911
23925
  const children = [];
23912
23926
  if (type === "agent") {
23913
- const prompts = extractAgentPrompts(bundledCode);
23927
+ const prompts = await extractAgentPrompts(bundledCode);
23914
23928
  if (prompts.sideA && availableItems.has(`prompt:${prompts.sideA}`)) {
23915
23929
  children.push({ type: "prompt", name: prompts.sideA });
23916
23930
  }
@@ -23918,7 +23932,7 @@ var init_unpacking_service = __esm({
23918
23932
  children.push({ type: "prompt", name: prompts.sideB });
23919
23933
  }
23920
23934
  } else if (type === "prompt") {
23921
- const toolsResult = extractPromptTools(bundledCode);
23935
+ const toolsResult = await extractPromptTools(bundledCode);
23922
23936
  for (const toolName of toolsResult.tools) {
23923
23937
  if (availableItems.has(`tool:${toolName}`)) {
23924
23938
  children.push({ type: "tool", name: toolName });
@@ -23926,12 +23940,12 @@ var init_unpacking_service = __esm({
23926
23940
  children.push({ type: "agent", name: toolName });
23927
23941
  }
23928
23942
  }
23929
- const model = extractPromptModel(bundledCode);
23943
+ const model = await extractPromptModel(bundledCode);
23930
23944
  if (model && availableItems.has(`model:${model}`)) {
23931
23945
  children.push({ type: "model", name: model });
23932
23946
  }
23933
23947
  } else if (type === "tool") {
23934
- const usesResult = extractToolUses(bundledCode);
23948
+ const usesResult = await extractToolUses(bundledCode);
23935
23949
  for (const useName of usesResult.uses) {
23936
23950
  const colonIndex = useName.indexOf(":");
23937
23951
  if (colonIndex > 0) {
@@ -24009,9 +24023,9 @@ var init_unpacking_service = __esm({
24009
24023
  try {
24010
24024
  const sourcePath = path2.join(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
24011
24025
  const bundledCode = fs2.readFileSync(sourcePath, "utf-8");
24012
- let tsCode = transformBundledJs(bundledCode);
24026
+ let tsCode = await transformBundledJs(bundledCode);
24013
24027
  if (item.type === "agent") {
24014
- tsCode = injectAgentMetadata(tsCode, agentMetadata);
24028
+ tsCode = await injectAgentMetadata(tsCode, agentMetadata);
24015
24029
  }
24016
24030
  const dir = path2.dirname(item.targetPath);
24017
24031
  if (!fs2.existsSync(dir)) {
@@ -24053,7 +24067,8 @@ var init_unpacking_service = __esm({
24053
24067
  * };
24054
24068
  * ```
24055
24069
  */
24056
- parseIndexExports(indexContent) {
24070
+ async parseIndexExports(indexContent) {
24071
+ const ts = await loadTypeScript();
24057
24072
  const sourceFile = ts.createSourceFile(
24058
24073
  "index.js",
24059
24074
  indexContent,
@@ -26874,7 +26889,7 @@ var analyze_get_default = defineController(async ({ req }) => {
26874
26889
  { status: 400 }
26875
26890
  );
26876
26891
  }
26877
- const { generatedReadme, agentDescription } = packingService.generateReadmeForAnalysis(
26892
+ const { generatedReadme, agentDescription } = await packingService.generateReadmeForAnalysis(
26878
26893
  analysis,
26879
26894
  rootDir
26880
26895
  );