@standardagents/builder 0.37.0 → 0.37.1
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/built-in-routes.js +1167 -904
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/{ApiKeysView-CTfDKe47.js → ApiKeysView-BhuT3pIF.js} +1 -1
- package/dist/client/{CenteredContentView-BrVntknT.js → CenteredContentView-CfgX3Ao3.js} +1 -1
- package/dist/client/{CompositionView-BT-1sFij.js → CompositionView-B9FfWMHd.js} +1 -1
- package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-yyjbXnqu.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-BqwwsXWJ.js} +1 -1
- package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-BWgZbcol.js → CopyButton.vue_vue_type_script_setup_true_lang-Cqm3Vt3E.js} +1 -1
- package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-DP_WTiEu.js → DataTable.vue_vue_type_script_setup_true_lang-CA5qgsty.js} +1 -1
- package/dist/client/{JsonViewer-DY4s92Td.js → JsonViewer-ByQKCShF.js} +1 -1
- package/dist/client/{LoginView-DHYLpkb0.js → LoginView-J4qtHbQK.js} +1 -1
- package/dist/client/{MarketplaceView-Bcil0ES3.js → MarketplaceView-CshdWDqp.js} +1 -1
- package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-BJgJZ56X.js → Modal.vue_vue_type_script_setup_true_lang-DKdB9A8Z.js} +1 -1
- package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-BXTP0K4Z.js → ModelModal.vue_vue_type_script_setup_true_lang-BAxaBZsx.js} +1 -1
- package/dist/client/{ModelsView-_RY4gQ79.js → ModelsView-B_n306yk.js} +1 -1
- package/dist/client/{PromptEditView-D8kyGi30.js → PromptEditView-C85qRgsE.js} +1 -1
- package/dist/client/{PromptModal-DSPIuleV.js → PromptModal-PNpoJfqD.js} +1 -1
- package/dist/client/{PromptsView-DPvBDPJf.js → PromptsView-BKnfThIF.js} +1 -1
- package/dist/client/{ProvidersView-PaPnME7I.js → ProvidersView-Df41VhHD.js} +1 -1
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-CtIBWHUR.js +22 -0
- package/dist/client/{ThreadsView-BW4SYvFN.js → ThreadsView-sjo5Rrcm.js} +1 -1
- package/dist/client/{ToolsView-xsIVTHh0.js → ToolsView-C0MH9x3N.js} +1 -1
- package/dist/client/{UsersView-CSXdBGA-.js → UsersView--TQiJYP7.js} +1 -1
- package/dist/client/{VariablesView-Bl5S2ZDn.js → VariablesView-BO3UljZu.js} +1 -1
- package/dist/client/assets/{ThreadInspectorPane-CnbmdCdH.css → ThreadInspectorPane-D9ZMzSTn.css} +1 -1
- package/dist/client/{index-Df4DTwgs.js → index-BgZnQr8X.js} +2 -2
- package/dist/client/index.html +1 -1
- package/dist/{index-yV9JL4r3.d.ts → index-DceFbLG9.d.ts} +45 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +957 -814
- package/dist/index.js.map +1 -1
- package/dist/packing.js +213 -161
- package/dist/packing.js.map +1 -1
- package/dist/plugin.js +535 -505
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +110 -38
- package/dist/runtime.js +173 -20
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-BAUlrnb6.js +0 -23
package/dist/packing.js
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as fs3 from 'fs';
|
|
2
|
+
import * as path3 from 'path';
|
|
3
3
|
import MagicString from 'magic-string';
|
|
4
4
|
|
|
5
5
|
// src/packing/packing-service.ts
|
|
6
|
+
|
|
7
|
+
// src/packing/package-identifier.ts
|
|
8
|
+
function assertSafePackageIdentifier(identifier) {
|
|
9
|
+
const value = identifier.trim();
|
|
10
|
+
if (!value || value.includes("\\") || value.includes("\0") || value.startsWith("/")) {
|
|
11
|
+
throw new Error("Invalid package identifier");
|
|
12
|
+
}
|
|
13
|
+
const parts = value.split("/");
|
|
14
|
+
const scoped = parts.length === 2 && parts[0].startsWith("@");
|
|
15
|
+
if (parts.length > 1 && !scoped) throw new Error("Invalid package identifier");
|
|
16
|
+
if (parts.some((part) => !part || part === "." || part === ".." || !/^@?[a-zA-Z0-9._-]+$/.test(part))) {
|
|
17
|
+
throw new Error("Invalid package identifier");
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/packing/path-safety.ts
|
|
23
|
+
function isWithin(base, candidate) {
|
|
24
|
+
const relative4 = path3.relative(base, candidate);
|
|
25
|
+
return relative4 === "" || !relative4.startsWith(`..${path3.sep}`) && relative4 !== ".." && !path3.isAbsolute(relative4);
|
|
26
|
+
}
|
|
27
|
+
function resolvePathWithin(base, ...segments) {
|
|
28
|
+
const resolvedBase = path3.resolve(base);
|
|
29
|
+
const candidate = path3.resolve(resolvedBase, ...segments);
|
|
30
|
+
if (!isWithin(resolvedBase, candidate)) {
|
|
31
|
+
throw new Error("Path must remain inside the configured AgentBuilder directory");
|
|
32
|
+
}
|
|
33
|
+
if (fs3.existsSync(resolvedBase)) {
|
|
34
|
+
const realBase = fs3.realpathSync(resolvedBase);
|
|
35
|
+
if (typeof realBase !== "string") return candidate;
|
|
36
|
+
let existing = candidate;
|
|
37
|
+
while (!fs3.existsSync(existing) && existing !== resolvedBase) {
|
|
38
|
+
existing = path3.dirname(existing);
|
|
39
|
+
}
|
|
40
|
+
if (fs3.existsSync(existing)) {
|
|
41
|
+
const realExisting = fs3.realpathSync(existing);
|
|
42
|
+
if (typeof realExisting === "string" && !isWithin(realBase, realExisting)) {
|
|
43
|
+
throw new Error("Path traverses a symlink outside the configured AgentBuilder directory");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return candidate;
|
|
48
|
+
}
|
|
6
49
|
var MetadataService = class {
|
|
7
50
|
metadataDir;
|
|
8
51
|
/**
|
|
@@ -11,7 +54,7 @@ var MetadataService = class {
|
|
|
11
54
|
* @param agentsDir - Path to the agents/ directory
|
|
12
55
|
*/
|
|
13
56
|
constructor(agentsDir) {
|
|
14
|
-
this.metadataDir =
|
|
57
|
+
this.metadataDir = path3.join(agentsDir, ".standardagent");
|
|
15
58
|
}
|
|
16
59
|
/**
|
|
17
60
|
* Read metadata for an agent.
|
|
@@ -21,11 +64,11 @@ var MetadataService = class {
|
|
|
21
64
|
*/
|
|
22
65
|
async read(agentName) {
|
|
23
66
|
const filePath = this.getMetadataPath(agentName);
|
|
24
|
-
if (!
|
|
67
|
+
if (!fs3.existsSync(filePath)) {
|
|
25
68
|
return null;
|
|
26
69
|
}
|
|
27
70
|
try {
|
|
28
|
-
const content =
|
|
71
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
29
72
|
return JSON.parse(content);
|
|
30
73
|
} catch {
|
|
31
74
|
return null;
|
|
@@ -38,11 +81,11 @@ var MetadataService = class {
|
|
|
38
81
|
* @param metadata - Metadata to write
|
|
39
82
|
*/
|
|
40
83
|
async write(agentName, metadata) {
|
|
41
|
-
if (!
|
|
42
|
-
|
|
84
|
+
if (!fs3.existsSync(this.metadataDir)) {
|
|
85
|
+
fs3.mkdirSync(this.metadataDir, { recursive: true });
|
|
43
86
|
}
|
|
44
87
|
const filePath = this.getMetadataPath(agentName);
|
|
45
|
-
|
|
88
|
+
fs3.writeFileSync(filePath, JSON.stringify(metadata, null, 2));
|
|
46
89
|
}
|
|
47
90
|
/**
|
|
48
91
|
* Delete metadata for an agent.
|
|
@@ -51,8 +94,8 @@ var MetadataService = class {
|
|
|
51
94
|
*/
|
|
52
95
|
async delete(agentName) {
|
|
53
96
|
const filePath = this.getMetadataPath(agentName);
|
|
54
|
-
if (
|
|
55
|
-
|
|
97
|
+
if (fs3.existsSync(filePath)) {
|
|
98
|
+
fs3.unlinkSync(filePath);
|
|
56
99
|
}
|
|
57
100
|
}
|
|
58
101
|
/**
|
|
@@ -133,7 +176,7 @@ var MetadataService = class {
|
|
|
133
176
|
* Get the file path for an agent's metadata.
|
|
134
177
|
*/
|
|
135
178
|
getMetadataPath(agentName) {
|
|
136
|
-
return
|
|
179
|
+
return path3.join(this.metadataDir, `${agentName}.json`);
|
|
137
180
|
}
|
|
138
181
|
};
|
|
139
182
|
var _ts;
|
|
@@ -505,9 +548,9 @@ var PackingService = class {
|
|
|
505
548
|
* @returns Version specifier (e.g., '^1.2.3') or '*' if not found
|
|
506
549
|
*/
|
|
507
550
|
resolvePackageVersion(pkgName, rootDir) {
|
|
508
|
-
const pkgJsonPath =
|
|
551
|
+
const pkgJsonPath = path3.join(rootDir, "node_modules", pkgName, "package.json");
|
|
509
552
|
try {
|
|
510
|
-
const pkgJson = JSON.parse(
|
|
553
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
511
554
|
return `^${pkgJson.version}`;
|
|
512
555
|
} catch {
|
|
513
556
|
return "*";
|
|
@@ -524,7 +567,7 @@ var PackingService = class {
|
|
|
524
567
|
* @returns Analysis result with all discovered constituents
|
|
525
568
|
*/
|
|
526
569
|
async analyzeAgent(agentName, rootDir) {
|
|
527
|
-
const agentsDir =
|
|
570
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
528
571
|
const analysis = {
|
|
529
572
|
agent: agentName,
|
|
530
573
|
primaryPrompt: "",
|
|
@@ -548,7 +591,7 @@ var PackingService = class {
|
|
|
548
591
|
warnings: [],
|
|
549
592
|
errors: []
|
|
550
593
|
};
|
|
551
|
-
const agentFilePath = await this.findFile(
|
|
594
|
+
const agentFilePath = await this.findFile(path3.join(agentsDir, "agents"), agentName);
|
|
552
595
|
if (!agentFilePath) {
|
|
553
596
|
analysis.errors.push(`Agent file not found: ${agentName}`);
|
|
554
597
|
return analysis;
|
|
@@ -559,7 +602,7 @@ var PackingService = class {
|
|
|
559
602
|
discoveredVia: "static",
|
|
560
603
|
sharedWith: []
|
|
561
604
|
});
|
|
562
|
-
const agentSource =
|
|
605
|
+
const agentSource = fs3.readFileSync(agentFilePath, "utf-8");
|
|
563
606
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
564
607
|
if (agentPrompts.sideA) {
|
|
565
608
|
analysis.primaryPrompt = agentPrompts.sideA;
|
|
@@ -584,13 +627,13 @@ var PackingService = class {
|
|
|
584
627
|
* @returns Object with generatedReadme and agentDescription
|
|
585
628
|
*/
|
|
586
629
|
async generateReadmeForAnalysis(analysis, rootDir) {
|
|
587
|
-
const agentsDir =
|
|
630
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
588
631
|
const metadataService = new MetadataService(agentsDir);
|
|
589
632
|
let agentDescription;
|
|
590
633
|
const agentItem = analysis.constituents.agents.find((a) => a.name === analysis.agent);
|
|
591
634
|
if (agentItem?.filePath) {
|
|
592
635
|
try {
|
|
593
|
-
const agentSource =
|
|
636
|
+
const agentSource = fs3.readFileSync(agentItem.filePath, "utf-8");
|
|
594
637
|
agentDescription = await extractAgentDescription(agentSource) || void 0;
|
|
595
638
|
} catch {
|
|
596
639
|
}
|
|
@@ -614,7 +657,7 @@ var PackingService = class {
|
|
|
614
657
|
* include all endpoint modules discovered under agents/api.
|
|
615
658
|
*/
|
|
616
659
|
async analyzeThreadEndpoints(agentsDir, analysis) {
|
|
617
|
-
const apiDir =
|
|
660
|
+
const apiDir = path3.join(agentsDir, "api");
|
|
618
661
|
const endpoints = this.scanThreadEndpointFiles(apiDir);
|
|
619
662
|
for (const endpoint of endpoints) {
|
|
620
663
|
if (analysis.constituents.threadEndpoints.some((item) => item.name === endpoint.name)) {
|
|
@@ -636,15 +679,15 @@ var PackingService = class {
|
|
|
636
679
|
* - `admin/users/[userId]/sync.post`
|
|
637
680
|
*/
|
|
638
681
|
scanThreadEndpointFiles(apiDir, relativeDir = "") {
|
|
639
|
-
if (!
|
|
682
|
+
if (!fs3.existsSync(apiDir)) {
|
|
640
683
|
return [];
|
|
641
684
|
}
|
|
642
685
|
const endpoints = [];
|
|
643
|
-
const currentDir = relativeDir ?
|
|
644
|
-
if (!
|
|
686
|
+
const currentDir = relativeDir ? path3.join(apiDir, relativeDir) : apiDir;
|
|
687
|
+
if (!fs3.existsSync(currentDir)) {
|
|
645
688
|
return endpoints;
|
|
646
689
|
}
|
|
647
|
-
const entries =
|
|
690
|
+
const entries = fs3.readdirSync(currentDir, { withFileTypes: true });
|
|
648
691
|
if (entries.length > 0 && typeof entries[0] === "string") {
|
|
649
692
|
return endpoints;
|
|
650
693
|
}
|
|
@@ -652,8 +695,8 @@ var PackingService = class {
|
|
|
652
695
|
const entryName = typeof entry === "string" ? entry : entry.name;
|
|
653
696
|
const isDirectory = typeof entry === "string" ? false : entry.isDirectory();
|
|
654
697
|
const isFile = typeof entry === "string" ? true : entry.isFile();
|
|
655
|
-
const entryRelative = relativeDir ?
|
|
656
|
-
const absolutePath =
|
|
698
|
+
const entryRelative = relativeDir ? path3.posix.join(relativeDir.replace(/\\/g, "/"), entryName) : entryName;
|
|
699
|
+
const absolutePath = path3.join(apiDir, entryRelative);
|
|
657
700
|
if (isDirectory) {
|
|
658
701
|
endpoints.push(...this.scanThreadEndpointFiles(apiDir, entryRelative));
|
|
659
702
|
continue;
|
|
@@ -680,7 +723,7 @@ var PackingService = class {
|
|
|
680
723
|
* include all effect modules discovered under agents/effects.
|
|
681
724
|
*/
|
|
682
725
|
async analyzeEffects(agentsDir, analysis) {
|
|
683
|
-
const effectsDir =
|
|
726
|
+
const effectsDir = path3.join(agentsDir, "effects");
|
|
684
727
|
const effects = this.scanEffectFiles(effectsDir);
|
|
685
728
|
for (const effect of effects) {
|
|
686
729
|
if (analysis.constituents.effects.some((item) => item.name === effect.name)) {
|
|
@@ -702,15 +745,15 @@ var PackingService = class {
|
|
|
702
745
|
* - `notifications/digest`
|
|
703
746
|
*/
|
|
704
747
|
scanEffectFiles(effectsDir, relativeDir = "") {
|
|
705
|
-
if (!
|
|
748
|
+
if (!fs3.existsSync(effectsDir)) {
|
|
706
749
|
return [];
|
|
707
750
|
}
|
|
708
751
|
const effects = [];
|
|
709
|
-
const currentDir = relativeDir ?
|
|
710
|
-
if (!
|
|
752
|
+
const currentDir = relativeDir ? path3.join(effectsDir, relativeDir) : effectsDir;
|
|
753
|
+
if (!fs3.existsSync(currentDir)) {
|
|
711
754
|
return effects;
|
|
712
755
|
}
|
|
713
|
-
const entries =
|
|
756
|
+
const entries = fs3.readdirSync(currentDir, { withFileTypes: true });
|
|
714
757
|
if (entries.length > 0 && typeof entries[0] === "string") {
|
|
715
758
|
return effects;
|
|
716
759
|
}
|
|
@@ -718,8 +761,8 @@ var PackingService = class {
|
|
|
718
761
|
const entryName = typeof entry === "string" ? entry : entry.name;
|
|
719
762
|
const isDirectory = typeof entry === "string" ? false : entry.isDirectory();
|
|
720
763
|
const isFile = typeof entry === "string" ? true : entry.isFile();
|
|
721
|
-
const entryRelative = relativeDir ?
|
|
722
|
-
const absolutePath =
|
|
764
|
+
const entryRelative = relativeDir ? path3.posix.join(relativeDir.replace(/\\/g, "/"), entryName) : entryName;
|
|
765
|
+
const absolutePath = path3.join(effectsDir, entryRelative);
|
|
723
766
|
if (isDirectory) {
|
|
724
767
|
effects.push(...this.scanEffectFiles(effectsDir, entryRelative));
|
|
725
768
|
continue;
|
|
@@ -743,7 +786,7 @@ var PackingService = class {
|
|
|
743
786
|
* Recursively analyze a prompt and its dependencies.
|
|
744
787
|
*/
|
|
745
788
|
async analyzePrompt(promptName, agentsDir, analysis, visited, parentKey) {
|
|
746
|
-
const promptFilePath = await this.findFile(
|
|
789
|
+
const promptFilePath = await this.findFile(path3.join(agentsDir, "prompts"), promptName);
|
|
747
790
|
if (!promptFilePath) {
|
|
748
791
|
analysis.warnings.push(`Prompt file not found: ${promptName}`);
|
|
749
792
|
return;
|
|
@@ -762,7 +805,7 @@ var PackingService = class {
|
|
|
762
805
|
return;
|
|
763
806
|
}
|
|
764
807
|
visited.add(`prompt:${promptName}`);
|
|
765
|
-
const promptSource =
|
|
808
|
+
const promptSource = fs3.readFileSync(promptFilePath, "utf-8");
|
|
766
809
|
const modelName = await extractPromptModel(promptSource);
|
|
767
810
|
if (modelName) {
|
|
768
811
|
await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
|
|
@@ -788,17 +831,17 @@ var PackingService = class {
|
|
|
788
831
|
*/
|
|
789
832
|
async analyzeTool(toolName, agentsDir, analysis, visited, discoveredVia, parentKey) {
|
|
790
833
|
const thisKey = `tool:${toolName}`;
|
|
791
|
-
const promptFilePath = await this.findFile(
|
|
834
|
+
const promptFilePath = await this.findFile(path3.join(agentsDir, "prompts"), toolName);
|
|
792
835
|
if (promptFilePath) {
|
|
793
836
|
await this.analyzePrompt(toolName, agentsDir, analysis, visited, parentKey);
|
|
794
837
|
return;
|
|
795
838
|
}
|
|
796
|
-
const agentFilePath = await this.findFile(
|
|
839
|
+
const agentFilePath = await this.findFile(path3.join(agentsDir, "agents"), toolName);
|
|
797
840
|
if (agentFilePath) {
|
|
798
841
|
await this.analyzeNestedAgent(toolName, agentsDir, analysis, visited, parentKey);
|
|
799
842
|
return;
|
|
800
843
|
}
|
|
801
|
-
const toolFilePath = await this.findFile(
|
|
844
|
+
const toolFilePath = await this.findFile(path3.join(agentsDir, "tools"), toolName);
|
|
802
845
|
if (!toolFilePath) {
|
|
803
846
|
analysis.warnings.push(`Tool file not found: ${toolName}`);
|
|
804
847
|
return;
|
|
@@ -816,7 +859,7 @@ var PackingService = class {
|
|
|
816
859
|
return;
|
|
817
860
|
}
|
|
818
861
|
visited.add(`tool:${toolName}`);
|
|
819
|
-
const toolSource =
|
|
862
|
+
const toolSource = fs3.readFileSync(toolFilePath, "utf-8");
|
|
820
863
|
const { uses } = await extractToolUses(toolSource);
|
|
821
864
|
for (const usedItem of uses) {
|
|
822
865
|
await this.analyzeTool(usedItem, agentsDir, analysis, visited, "uses", thisKey);
|
|
@@ -826,7 +869,7 @@ var PackingService = class {
|
|
|
826
869
|
* Analyze a nested agent (used as a handoff target).
|
|
827
870
|
*/
|
|
828
871
|
async analyzeNestedAgent(agentName, agentsDir, analysis, visited, parentKey) {
|
|
829
|
-
const agentFilePath = await this.findFile(
|
|
872
|
+
const agentFilePath = await this.findFile(path3.join(agentsDir, "agents"), agentName);
|
|
830
873
|
if (!agentFilePath) {
|
|
831
874
|
analysis.warnings.push(`Agent file not found: ${agentName}`);
|
|
832
875
|
return;
|
|
@@ -845,7 +888,7 @@ var PackingService = class {
|
|
|
845
888
|
return;
|
|
846
889
|
}
|
|
847
890
|
visited.add(`agent:${agentName}`);
|
|
848
|
-
const agentSource =
|
|
891
|
+
const agentSource = fs3.readFileSync(agentFilePath, "utf-8");
|
|
849
892
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
850
893
|
if (agentPrompts.sideA) {
|
|
851
894
|
await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
|
|
@@ -858,7 +901,7 @@ var PackingService = class {
|
|
|
858
901
|
* Analyze a model and its fallbacks.
|
|
859
902
|
*/
|
|
860
903
|
async analyzeModel(modelName, agentsDir, analysis, visited, parentKey) {
|
|
861
|
-
const modelFilePath = await this.findFile(
|
|
904
|
+
const modelFilePath = await this.findFile(path3.join(agentsDir, "models"), modelName);
|
|
862
905
|
if (!modelFilePath) {
|
|
863
906
|
analysis.warnings.push(`Model file not found: ${modelName}`);
|
|
864
907
|
return;
|
|
@@ -877,7 +920,7 @@ var PackingService = class {
|
|
|
877
920
|
return;
|
|
878
921
|
}
|
|
879
922
|
visited.add(`model:${modelName}`);
|
|
880
|
-
const modelSource =
|
|
923
|
+
const modelSource = fs3.readFileSync(modelFilePath, "utf-8");
|
|
881
924
|
const fallbacks = await extractModelFallbacks(modelSource);
|
|
882
925
|
for (const fallbackName of fallbacks) {
|
|
883
926
|
await this.analyzeModel(fallbackName, agentsDir, analysis, visited, thisKey);
|
|
@@ -887,13 +930,13 @@ var PackingService = class {
|
|
|
887
930
|
* Check which items are shared with other agents.
|
|
888
931
|
*/
|
|
889
932
|
async checkSharedItems(agentsDir, analysis) {
|
|
890
|
-
const agentsPath =
|
|
891
|
-
if (!
|
|
892
|
-
const agentFiles =
|
|
933
|
+
const agentsPath = path3.join(agentsDir, "agents");
|
|
934
|
+
if (!fs3.existsSync(agentsPath)) return;
|
|
935
|
+
const agentFiles = fs3.readdirSync(agentsPath).filter((f) => f.endsWith(".ts"));
|
|
893
936
|
for (const agentFile of agentFiles) {
|
|
894
937
|
const otherAgentName = agentFile.replace(".ts", "");
|
|
895
938
|
if (otherAgentName === analysis.agent) continue;
|
|
896
|
-
const otherAnalysis = await this.analyzeAgentLight(otherAgentName,
|
|
939
|
+
const otherAnalysis = await this.analyzeAgentLight(otherAgentName, path3.dirname(agentsDir));
|
|
897
940
|
for (const prompt of analysis.constituents.prompts) {
|
|
898
941
|
if (otherAnalysis.prompts.includes(prompt.name)) {
|
|
899
942
|
prompt.sharedWith.push(otherAgentName);
|
|
@@ -925,19 +968,19 @@ var PackingService = class {
|
|
|
925
968
|
*/
|
|
926
969
|
async analyzeAgentLight(agentName, rootDir) {
|
|
927
970
|
const result = { prompts: [], tools: [], models: [] };
|
|
928
|
-
const agentsDir =
|
|
971
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
929
972
|
const visited = /* @__PURE__ */ new Set();
|
|
930
|
-
const agentFilePath = await this.findFile(
|
|
973
|
+
const agentFilePath = await this.findFile(path3.join(agentsDir, "agents"), agentName);
|
|
931
974
|
if (!agentFilePath) return result;
|
|
932
|
-
const agentSource =
|
|
975
|
+
const agentSource = fs3.readFileSync(agentFilePath, "utf-8");
|
|
933
976
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
934
977
|
const analyzePromptLight = async (promptName) => {
|
|
935
978
|
if (visited.has(promptName)) return;
|
|
936
979
|
visited.add(promptName);
|
|
937
980
|
result.prompts.push(promptName);
|
|
938
|
-
const promptFilePath = await this.findFile(
|
|
981
|
+
const promptFilePath = await this.findFile(path3.join(agentsDir, "prompts"), promptName);
|
|
939
982
|
if (!promptFilePath) return;
|
|
940
|
-
const promptSource =
|
|
983
|
+
const promptSource = fs3.readFileSync(promptFilePath, "utf-8");
|
|
941
984
|
const modelName = await extractPromptModel(promptSource);
|
|
942
985
|
if (modelName && !result.models.includes(modelName)) {
|
|
943
986
|
result.models.push(modelName);
|
|
@@ -1010,14 +1053,15 @@ var PackingService = class {
|
|
|
1010
1053
|
return result;
|
|
1011
1054
|
}
|
|
1012
1055
|
result.warnings = analysis.warnings;
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1056
|
+
const safePackageId = assertSafePackageIdentifier(packageId);
|
|
1057
|
+
const pkgOutputDir = resolvePathWithin(outputDir, safePackageId);
|
|
1058
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "agents"), { recursive: true });
|
|
1059
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "prompts"), { recursive: true });
|
|
1060
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "tools"), { recursive: true });
|
|
1061
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "models"), { recursive: true });
|
|
1062
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "hooks"), { recursive: true });
|
|
1063
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "effects"), { recursive: true });
|
|
1064
|
+
fs3.mkdirSync(path3.join(pkgOutputDir, "dist", "thread-endpoints"), { recursive: true });
|
|
1021
1065
|
const seenItems = /* @__PURE__ */ new Set();
|
|
1022
1066
|
const allItems = [];
|
|
1023
1067
|
for (const a of analysis.constituents.agents) {
|
|
@@ -1071,13 +1115,13 @@ var PackingService = class {
|
|
|
1071
1115
|
}
|
|
1072
1116
|
const externalDeps = /* @__PURE__ */ new Map();
|
|
1073
1117
|
for (const item of allItems) {
|
|
1074
|
-
const outputPath =
|
|
1118
|
+
const outputPath = resolvePathWithin(
|
|
1075
1119
|
pkgOutputDir,
|
|
1076
1120
|
"dist",
|
|
1077
1121
|
this.getTypeDir(item.type),
|
|
1078
1122
|
`${item.name}.js`
|
|
1079
1123
|
);
|
|
1080
|
-
|
|
1124
|
+
fs3.mkdirSync(path3.dirname(outputPath), { recursive: true });
|
|
1081
1125
|
const deps = await this.bundleFile(item.filePath, outputPath, rootDir);
|
|
1082
1126
|
for (const [depName, depVersion] of deps) {
|
|
1083
1127
|
if (!externalDeps.has(depName)) {
|
|
@@ -1087,12 +1131,12 @@ var PackingService = class {
|
|
|
1087
1131
|
result.filesCreated.push(outputPath);
|
|
1088
1132
|
}
|
|
1089
1133
|
const indexJs = this.generateReExportIndex(analysis, meta);
|
|
1090
|
-
const indexJsPath =
|
|
1091
|
-
|
|
1134
|
+
const indexJsPath = resolvePathWithin(pkgOutputDir, "dist", "index.js");
|
|
1135
|
+
fs3.writeFileSync(indexJsPath, indexJs);
|
|
1092
1136
|
result.filesCreated.push(indexJsPath);
|
|
1093
1137
|
const indexDts = this.generateIndexDts(analysis);
|
|
1094
|
-
const indexDtsPath =
|
|
1095
|
-
|
|
1138
|
+
const indexDtsPath = resolvePathWithin(pkgOutputDir, "dist", "index.d.ts");
|
|
1139
|
+
fs3.writeFileSync(indexDtsPath, indexDts);
|
|
1096
1140
|
result.filesCreated.push(indexDtsPath);
|
|
1097
1141
|
const pkgJson = this.generatePackageJson(
|
|
1098
1142
|
finalPackageName,
|
|
@@ -1105,13 +1149,13 @@ var PackingService = class {
|
|
|
1105
1149
|
license,
|
|
1106
1150
|
licenseOwner
|
|
1107
1151
|
);
|
|
1108
|
-
const pkgJsonPath =
|
|
1109
|
-
|
|
1152
|
+
const pkgJsonPath = path3.join(pkgOutputDir, "package.json");
|
|
1153
|
+
fs3.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
1110
1154
|
result.filesCreated.push(pkgJsonPath);
|
|
1111
1155
|
if (license) {
|
|
1112
1156
|
const licenseContent = this.generateLicenseFile(license, licenseOwner);
|
|
1113
|
-
const licensePath =
|
|
1114
|
-
|
|
1157
|
+
const licensePath = path3.join(pkgOutputDir, "LICENSE");
|
|
1158
|
+
fs3.writeFileSync(licensePath, licenseContent);
|
|
1115
1159
|
result.filesCreated.push(licensePath);
|
|
1116
1160
|
}
|
|
1117
1161
|
let readmeContent = readme;
|
|
@@ -1119,7 +1163,7 @@ var PackingService = class {
|
|
|
1119
1163
|
const agentItem = analysis.constituents.agents.find((a) => a.name === agentName);
|
|
1120
1164
|
let agentDescription;
|
|
1121
1165
|
if (agentItem?.filePath) {
|
|
1122
|
-
const agentSource =
|
|
1166
|
+
const agentSource = fs3.readFileSync(agentItem.filePath, "utf-8");
|
|
1123
1167
|
agentDescription = await extractAgentDescription(agentSource) || void 0;
|
|
1124
1168
|
}
|
|
1125
1169
|
readmeContent = this.generateReadme(
|
|
@@ -1130,21 +1174,21 @@ var PackingService = class {
|
|
|
1130
1174
|
agentDescription
|
|
1131
1175
|
);
|
|
1132
1176
|
}
|
|
1133
|
-
const readmePath =
|
|
1134
|
-
|
|
1177
|
+
const readmePath = path3.join(pkgOutputDir, "README.md");
|
|
1178
|
+
fs3.writeFileSync(readmePath, readmeContent);
|
|
1135
1179
|
result.filesCreated.push(readmePath);
|
|
1136
1180
|
if (removeOriginals || itemSelections) {
|
|
1137
1181
|
result.filesRemoved = [];
|
|
1138
1182
|
for (const item of allItems) {
|
|
1139
1183
|
const selection = itemSelections?.find((s) => s.name === item.name && s.type === item.type);
|
|
1140
1184
|
const shouldRemove = selection ? selection.mode === "extract" : removeOriginals && item.sharedWith.length === 0 && item.type !== "thread-endpoint" && item.type !== "effect";
|
|
1141
|
-
if (shouldRemove &&
|
|
1142
|
-
|
|
1185
|
+
if (shouldRemove && fs3.existsSync(item.filePath)) {
|
|
1186
|
+
fs3.unlinkSync(item.filePath);
|
|
1143
1187
|
result.filesRemoved.push(item.filePath);
|
|
1144
1188
|
}
|
|
1145
1189
|
}
|
|
1146
1190
|
}
|
|
1147
|
-
const agentsDir =
|
|
1191
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
1148
1192
|
const metadataService = new MetadataService(agentsDir);
|
|
1149
1193
|
const metadata = {
|
|
1150
1194
|
packageName: finalPackageName,
|
|
@@ -1178,7 +1222,7 @@ var PackingService = class {
|
|
|
1178
1222
|
const commonjs = (await import('@rollup/plugin-commonjs')).default;
|
|
1179
1223
|
const esbuild = (await import('rollup-plugin-esbuild')).default;
|
|
1180
1224
|
const externalDeps = /* @__PURE__ */ new Map();
|
|
1181
|
-
const agentsDir =
|
|
1225
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
1182
1226
|
const resolveVersion = this.resolvePackageVersion.bind(this);
|
|
1183
1227
|
const trackExternalsPlugin = {
|
|
1184
1228
|
name: "track-externals",
|
|
@@ -1187,14 +1231,14 @@ var PackingService = class {
|
|
|
1187
1231
|
return null;
|
|
1188
1232
|
}
|
|
1189
1233
|
if (source.startsWith("./") || source.startsWith("../")) {
|
|
1190
|
-
const resolved =
|
|
1234
|
+
const resolved = path3.resolve(path3.dirname(importer), source);
|
|
1191
1235
|
let tsResolved = resolved;
|
|
1192
1236
|
if (!resolved.endsWith(".ts") && !resolved.endsWith(".js")) {
|
|
1193
|
-
if (
|
|
1237
|
+
if (fs3.existsSync(`${resolved}.ts`)) {
|
|
1194
1238
|
tsResolved = `${resolved}.ts`;
|
|
1195
|
-
} else if (
|
|
1239
|
+
} else if (fs3.existsSync(`${resolved}.js`)) {
|
|
1196
1240
|
tsResolved = `${resolved}.js`;
|
|
1197
|
-
} else if (
|
|
1241
|
+
} else if (fs3.existsSync(`${resolved}/index.ts`)) {
|
|
1198
1242
|
tsResolved = `${resolved}/index.ts`;
|
|
1199
1243
|
}
|
|
1200
1244
|
}
|
|
@@ -1243,11 +1287,11 @@ var PackingService = class {
|
|
|
1243
1287
|
exports: "named"
|
|
1244
1288
|
});
|
|
1245
1289
|
const bundledCode = output[0].code;
|
|
1246
|
-
const header = `// Bundled from: ${
|
|
1290
|
+
const header = `// Bundled from: ${path3.relative(rootDir, inputPath)}
|
|
1247
1291
|
// Local dependencies have been inlined
|
|
1248
1292
|
|
|
1249
1293
|
`;
|
|
1250
|
-
|
|
1294
|
+
fs3.writeFileSync(outputPath, header + bundledCode);
|
|
1251
1295
|
await bundle.close();
|
|
1252
1296
|
} catch (error) {
|
|
1253
1297
|
await bundle.close();
|
|
@@ -1672,30 +1716,31 @@ Copyright (c) ${year} ${copyrightHolder}
|
|
|
1672
1716
|
* @returns Package info or null if not found
|
|
1673
1717
|
*/
|
|
1674
1718
|
getPackedInfo(packageId, rootDir) {
|
|
1675
|
-
const packedDir =
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1719
|
+
const packedDir = path3.join(rootDir, "agents", "packed");
|
|
1720
|
+
const safePackageId = assertSafePackageIdentifier(packageId);
|
|
1721
|
+
let packageDir = resolvePathWithin(packedDir, safePackageId);
|
|
1722
|
+
if (!fs3.existsSync(packageDir)) {
|
|
1723
|
+
if (!fs3.existsSync(packedDir)) {
|
|
1679
1724
|
return null;
|
|
1680
1725
|
}
|
|
1681
|
-
const dirs =
|
|
1726
|
+
const dirs = fs3.readdirSync(packedDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
1682
1727
|
const matchingDir = dirs.find(
|
|
1683
1728
|
(d) => d === packageId || d === `standardagent-${packageId}` || d === `standardagent-${packageId.replace(/_/g, "-")}`
|
|
1684
1729
|
);
|
|
1685
1730
|
if (!matchingDir) {
|
|
1686
1731
|
return null;
|
|
1687
1732
|
}
|
|
1688
|
-
packageDir =
|
|
1733
|
+
packageDir = path3.join(packedDir, matchingDir);
|
|
1689
1734
|
}
|
|
1690
|
-
const pkgJsonPath =
|
|
1691
|
-
if (!
|
|
1735
|
+
const pkgJsonPath = path3.join(packageDir, "package.json");
|
|
1736
|
+
if (!fs3.existsSync(pkgJsonPath)) {
|
|
1692
1737
|
return null;
|
|
1693
1738
|
}
|
|
1694
|
-
const pkgJson = JSON.parse(
|
|
1739
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1695
1740
|
let readme;
|
|
1696
|
-
const readmePath =
|
|
1697
|
-
if (
|
|
1698
|
-
readme =
|
|
1741
|
+
const readmePath = path3.join(packageDir, "README.md");
|
|
1742
|
+
if (fs3.existsSync(readmePath)) {
|
|
1743
|
+
readme = fs3.readFileSync(readmePath, "utf-8");
|
|
1699
1744
|
}
|
|
1700
1745
|
return {
|
|
1701
1746
|
packageName: pkgJson.name,
|
|
@@ -1713,11 +1758,11 @@ Copyright (c) ${year} ${copyrightHolder}
|
|
|
1713
1758
|
* @returns Array of package directory names
|
|
1714
1759
|
*/
|
|
1715
1760
|
listPackedPackages(rootDir) {
|
|
1716
|
-
const packedDir =
|
|
1717
|
-
if (!
|
|
1761
|
+
const packedDir = path3.join(rootDir, "agents", "packed");
|
|
1762
|
+
if (!fs3.existsSync(packedDir)) {
|
|
1718
1763
|
return [];
|
|
1719
1764
|
}
|
|
1720
|
-
return
|
|
1765
|
+
return fs3.readdirSync(packedDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
1721
1766
|
}
|
|
1722
1767
|
/**
|
|
1723
1768
|
* Generate README.md content for a packed agent.
|
|
@@ -1764,17 +1809,17 @@ ${license || "See LICENSE file"}
|
|
|
1764
1809
|
* Find a file by name in a directory.
|
|
1765
1810
|
*/
|
|
1766
1811
|
async findFile(dir, name) {
|
|
1767
|
-
if (!
|
|
1812
|
+
if (!fs3.existsSync(dir)) {
|
|
1768
1813
|
return null;
|
|
1769
1814
|
}
|
|
1770
|
-
const exactPath =
|
|
1771
|
-
if (
|
|
1815
|
+
const exactPath = resolvePathWithin(dir, `${name}.ts`);
|
|
1816
|
+
if (fs3.existsSync(exactPath)) {
|
|
1772
1817
|
return exactPath;
|
|
1773
1818
|
}
|
|
1774
|
-
const files =
|
|
1819
|
+
const files = fs3.readdirSync(dir).filter((f) => f.endsWith(".ts"));
|
|
1775
1820
|
for (const file of files) {
|
|
1776
|
-
const filePath =
|
|
1777
|
-
const source =
|
|
1821
|
+
const filePath = path3.join(dir, file);
|
|
1822
|
+
const source = fs3.readFileSync(filePath, "utf-8");
|
|
1778
1823
|
const extractedName = await extractDefinitionName(source);
|
|
1779
1824
|
if (extractedName === name) {
|
|
1780
1825
|
return filePath;
|
|
@@ -1786,15 +1831,15 @@ ${license || "See LICENSE file"}
|
|
|
1786
1831
|
* List all agents in the workspace.
|
|
1787
1832
|
*/
|
|
1788
1833
|
async listAgents(rootDir) {
|
|
1789
|
-
const agentsDir =
|
|
1790
|
-
if (!
|
|
1834
|
+
const agentsDir = path3.join(rootDir, "agents", "agents");
|
|
1835
|
+
if (!fs3.existsSync(agentsDir)) {
|
|
1791
1836
|
return [];
|
|
1792
1837
|
}
|
|
1793
|
-
const files =
|
|
1838
|
+
const files = fs3.readdirSync(agentsDir).filter((f) => f.endsWith(".ts"));
|
|
1794
1839
|
const agents = [];
|
|
1795
1840
|
for (const file of files) {
|
|
1796
|
-
const filePath =
|
|
1797
|
-
const source =
|
|
1841
|
+
const filePath = path3.join(agentsDir, file);
|
|
1842
|
+
const source = fs3.readFileSync(filePath, "utf-8");
|
|
1798
1843
|
const name = await extractDefinitionName(source);
|
|
1799
1844
|
if (name) {
|
|
1800
1845
|
agents.push(name);
|
|
@@ -1810,7 +1855,7 @@ var PackageDiscoveryService = class {
|
|
|
1810
1855
|
constructor(config) {
|
|
1811
1856
|
this.config = {
|
|
1812
1857
|
rootDir: config.rootDir,
|
|
1813
|
-
packedDir: config.packedDir ??
|
|
1858
|
+
packedDir: config.packedDir ?? path3.join(config.rootDir, "agents", "packed"),
|
|
1814
1859
|
scanNpm: config.scanNpm ?? true,
|
|
1815
1860
|
scanLocal: config.scanLocal ?? true
|
|
1816
1861
|
};
|
|
@@ -1843,19 +1888,19 @@ var PackageDiscoveryService = class {
|
|
|
1843
1888
|
*/
|
|
1844
1889
|
async discoverNpmPackages() {
|
|
1845
1890
|
const packages = [];
|
|
1846
|
-
const nodeModulesDir =
|
|
1847
|
-
if (!
|
|
1891
|
+
const nodeModulesDir = path3.join(this.config.rootDir, "node_modules");
|
|
1892
|
+
if (!fs3.existsSync(nodeModulesDir)) {
|
|
1848
1893
|
return packages;
|
|
1849
1894
|
}
|
|
1850
1895
|
const rootEntries = await this.scanDirectory(nodeModulesDir);
|
|
1851
1896
|
for (const entry of rootEntries) {
|
|
1852
1897
|
if (entry.startsWith(".")) continue;
|
|
1853
1898
|
if (entry.startsWith("@")) {
|
|
1854
|
-
const scopeDir =
|
|
1899
|
+
const scopeDir = path3.join(nodeModulesDir, entry);
|
|
1855
1900
|
const scopeEntries = await this.scanDirectory(scopeDir);
|
|
1856
1901
|
for (const scopedPkg of scopeEntries) {
|
|
1857
1902
|
if (scopedPkg.startsWith(".")) continue;
|
|
1858
|
-
const pkgDir =
|
|
1903
|
+
const pkgDir = path3.join(scopeDir, scopedPkg);
|
|
1859
1904
|
const fullName = `${entry}/${scopedPkg}`;
|
|
1860
1905
|
const pkg = await this.checkNpmPackage(pkgDir, fullName);
|
|
1861
1906
|
if (pkg) {
|
|
@@ -1863,7 +1908,7 @@ var PackageDiscoveryService = class {
|
|
|
1863
1908
|
}
|
|
1864
1909
|
}
|
|
1865
1910
|
} else {
|
|
1866
|
-
const pkgDir =
|
|
1911
|
+
const pkgDir = path3.join(nodeModulesDir, entry);
|
|
1867
1912
|
const pkg = await this.checkNpmPackage(pkgDir, entry);
|
|
1868
1913
|
if (pkg) {
|
|
1869
1914
|
packages.push(pkg);
|
|
@@ -1879,12 +1924,12 @@ var PackageDiscoveryService = class {
|
|
|
1879
1924
|
* which must contain `entryAgents` array.
|
|
1880
1925
|
*/
|
|
1881
1926
|
async checkNpmPackage(pkgDir, pkgName) {
|
|
1882
|
-
const pkgJsonPath =
|
|
1883
|
-
if (!
|
|
1927
|
+
const pkgJsonPath = path3.join(pkgDir, "package.json");
|
|
1928
|
+
if (!fs3.existsSync(pkgJsonPath)) {
|
|
1884
1929
|
return null;
|
|
1885
1930
|
}
|
|
1886
1931
|
try {
|
|
1887
|
-
const pkgJson = JSON.parse(
|
|
1932
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1888
1933
|
const isStandardAgent = (
|
|
1889
1934
|
// Has "standardagent" keyword
|
|
1890
1935
|
pkgJson.keywords?.includes("standardagent") || // Has "standardagent-*" prefix
|
|
@@ -1921,21 +1966,21 @@ var PackageDiscoveryService = class {
|
|
|
1921
1966
|
*/
|
|
1922
1967
|
async discoverLocalPackages() {
|
|
1923
1968
|
const packages = [];
|
|
1924
|
-
if (!
|
|
1969
|
+
if (!fs3.existsSync(this.config.packedDir)) {
|
|
1925
1970
|
return packages;
|
|
1926
1971
|
}
|
|
1927
1972
|
const entries = await this.scanDirectory(this.config.packedDir);
|
|
1928
1973
|
for (const entry of entries) {
|
|
1929
1974
|
if (entry.startsWith(".")) continue;
|
|
1930
|
-
const pkgDir =
|
|
1931
|
-
const stat =
|
|
1975
|
+
const pkgDir = path3.join(this.config.packedDir, entry);
|
|
1976
|
+
const stat = fs3.statSync(pkgDir);
|
|
1932
1977
|
if (!stat.isDirectory()) continue;
|
|
1933
1978
|
if (entry.startsWith("@")) {
|
|
1934
1979
|
const scopeEntries = await this.scanDirectory(pkgDir);
|
|
1935
1980
|
for (const scopedPkg of scopeEntries) {
|
|
1936
1981
|
if (scopedPkg.startsWith(".")) continue;
|
|
1937
|
-
const scopedPkgDir =
|
|
1938
|
-
const scopedStat =
|
|
1982
|
+
const scopedPkgDir = path3.join(pkgDir, scopedPkg);
|
|
1983
|
+
const scopedStat = fs3.statSync(scopedPkgDir);
|
|
1939
1984
|
if (!scopedStat.isDirectory()) continue;
|
|
1940
1985
|
const fullName = `${entry}/${scopedPkg}`;
|
|
1941
1986
|
const pkg = await this.checkLocalPackage(scopedPkgDir, fullName);
|
|
@@ -1958,12 +2003,12 @@ var PackageDiscoveryService = class {
|
|
|
1958
2003
|
* Detection is based on the `standardagent` field in package.json.
|
|
1959
2004
|
*/
|
|
1960
2005
|
async checkLocalPackage(pkgDir, dirName) {
|
|
1961
|
-
const pkgJsonPath =
|
|
1962
|
-
if (!
|
|
2006
|
+
const pkgJsonPath = path3.join(pkgDir, "package.json");
|
|
2007
|
+
if (!fs3.existsSync(pkgJsonPath)) {
|
|
1963
2008
|
return null;
|
|
1964
2009
|
}
|
|
1965
2010
|
try {
|
|
1966
|
-
const pkgJson = JSON.parse(
|
|
2011
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1967
2012
|
if (!pkgJson.standardagent?.entryAgents) {
|
|
1968
2013
|
return null;
|
|
1969
2014
|
}
|
|
@@ -1988,10 +2033,10 @@ var PackageDiscoveryService = class {
|
|
|
1988
2033
|
* Scan a directory and return entry names.
|
|
1989
2034
|
*/
|
|
1990
2035
|
async scanDirectory(dir) {
|
|
1991
|
-
if (!
|
|
2036
|
+
if (!fs3.existsSync(dir)) {
|
|
1992
2037
|
return [];
|
|
1993
2038
|
}
|
|
1994
|
-
const entries =
|
|
2039
|
+
const entries = fs3.readdirSync(dir);
|
|
1995
2040
|
return entries;
|
|
1996
2041
|
}
|
|
1997
2042
|
/**
|
|
@@ -2088,29 +2133,29 @@ var UnpackingService = class {
|
|
|
2088
2133
|
}
|
|
2089
2134
|
analysis.version = pkg.version;
|
|
2090
2135
|
analysis.source = pkg.source;
|
|
2091
|
-
const indexPath =
|
|
2092
|
-
if (!
|
|
2136
|
+
const indexPath = path3.join(pkg.path, "dist", "index.js");
|
|
2137
|
+
if (!fs3.existsSync(indexPath)) {
|
|
2093
2138
|
analysis.errors.push(`Package index not found: ${indexPath}`);
|
|
2094
2139
|
return analysis;
|
|
2095
2140
|
}
|
|
2096
|
-
const indexContent =
|
|
2141
|
+
const indexContent = fs3.readFileSync(indexPath, "utf-8");
|
|
2097
2142
|
const registryItems = await this.parseIndexExports(indexContent);
|
|
2098
2143
|
const availableItems = /* @__PURE__ */ new Map();
|
|
2099
2144
|
for (const item of registryItems) {
|
|
2100
2145
|
availableItems.set(`${item.type}:${item.name}`, item);
|
|
2101
2146
|
}
|
|
2102
|
-
const agentsDir =
|
|
2147
|
+
const agentsDir = path3.join(rootDir, "agents");
|
|
2103
2148
|
const itemsWithRelations = [];
|
|
2104
2149
|
for (const item of registryItems) {
|
|
2105
|
-
const targetPath =
|
|
2106
|
-
const sourcePath =
|
|
2150
|
+
const targetPath = resolvePathWithin(agentsDir, TYPE_TO_TARGET_DIR[item.type], `${item.name}.ts`);
|
|
2151
|
+
const sourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
|
|
2107
2152
|
const existsGlobally = this.fileExists(targetPath);
|
|
2108
|
-
const sourceExists =
|
|
2153
|
+
const sourceExists = fs3.existsSync(sourcePath);
|
|
2109
2154
|
if (!sourceExists) {
|
|
2110
2155
|
analysis.warnings.push(`Source file not found for ${item.type} "${item.name}": ${sourcePath}`);
|
|
2111
2156
|
continue;
|
|
2112
2157
|
}
|
|
2113
|
-
const bundledCode =
|
|
2158
|
+
const bundledCode = fs3.readFileSync(sourcePath, "utf-8");
|
|
2114
2159
|
const children = await this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
|
|
2115
2160
|
itemsWithRelations.push({
|
|
2116
2161
|
name: item.name,
|
|
@@ -2120,10 +2165,10 @@ var UnpackingService = class {
|
|
|
2120
2165
|
action: existsGlobally ? "skip" : "generate"
|
|
2121
2166
|
});
|
|
2122
2167
|
for (const child of children) {
|
|
2123
|
-
const childTargetPath =
|
|
2124
|
-
const childSourcePath =
|
|
2168
|
+
const childTargetPath = resolvePathWithin(agentsDir, TYPE_TO_TARGET_DIR[child.type], `${child.name}.ts`);
|
|
2169
|
+
const childSourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[child.type], `${child.name}.js`);
|
|
2125
2170
|
const childExists = this.fileExists(childTargetPath);
|
|
2126
|
-
const childSourceExists =
|
|
2171
|
+
const childSourceExists = fs3.existsSync(childSourcePath);
|
|
2127
2172
|
if (!childSourceExists) {
|
|
2128
2173
|
continue;
|
|
2129
2174
|
}
|
|
@@ -2226,8 +2271,8 @@ var UnpackingService = class {
|
|
|
2226
2271
|
return result;
|
|
2227
2272
|
}
|
|
2228
2273
|
const itemsToProcess = this.applySelections(analysis.items, itemSelections);
|
|
2229
|
-
const pkgJsonPath =
|
|
2230
|
-
const pkgJson = JSON.parse(
|
|
2274
|
+
const pkgJsonPath = path3.join(pkg.path, "package.json");
|
|
2275
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
2231
2276
|
let author = "";
|
|
2232
2277
|
if (typeof pkgJson.author === "string") {
|
|
2233
2278
|
author = pkgJson.author;
|
|
@@ -2252,18 +2297,19 @@ var UnpackingService = class {
|
|
|
2252
2297
|
continue;
|
|
2253
2298
|
}
|
|
2254
2299
|
try {
|
|
2255
|
-
const sourcePath =
|
|
2256
|
-
const
|
|
2300
|
+
const sourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
|
|
2301
|
+
const targetPath = resolvePathWithin(path3.join(rootDir, "agents"), path3.relative(path3.join(rootDir, "agents"), item.targetPath));
|
|
2302
|
+
const bundledCode = fs3.readFileSync(sourcePath, "utf-8");
|
|
2257
2303
|
let tsCode = await transformBundledJs(bundledCode);
|
|
2258
2304
|
if (item.type === "agent") {
|
|
2259
2305
|
tsCode = await injectAgentMetadata(tsCode, agentMetadata);
|
|
2260
2306
|
}
|
|
2261
|
-
const dir =
|
|
2262
|
-
if (!
|
|
2263
|
-
|
|
2307
|
+
const dir = path3.dirname(targetPath);
|
|
2308
|
+
if (!fs3.existsSync(dir)) {
|
|
2309
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
2264
2310
|
}
|
|
2265
|
-
|
|
2266
|
-
result.filesGenerated.push(
|
|
2311
|
+
fs3.writeFileSync(targetPath, tsCode);
|
|
2312
|
+
result.filesGenerated.push(targetPath);
|
|
2267
2313
|
} catch (error) {
|
|
2268
2314
|
result.warnings.push(
|
|
2269
2315
|
`Failed to generate ${item.type} "${item.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -2272,7 +2318,12 @@ var UnpackingService = class {
|
|
|
2272
2318
|
}
|
|
2273
2319
|
if (deletePackage && pkg.source === "local") {
|
|
2274
2320
|
try {
|
|
2275
|
-
|
|
2321
|
+
const localPackedRoot = path3.join(rootDir, "agents", "packed");
|
|
2322
|
+
const safePackagePath = resolvePathWithin(
|
|
2323
|
+
localPackedRoot,
|
|
2324
|
+
path3.relative(localPackedRoot, pkg.path)
|
|
2325
|
+
);
|
|
2326
|
+
this.deleteDirectory(safePackagePath);
|
|
2276
2327
|
result.packageDeleted = true;
|
|
2277
2328
|
} catch (error) {
|
|
2278
2329
|
result.warnings.push(
|
|
@@ -2351,14 +2402,14 @@ var UnpackingService = class {
|
|
|
2351
2402
|
*/
|
|
2352
2403
|
async resolvePackage(pkgIdentifier, rootDir) {
|
|
2353
2404
|
if (pkgIdentifier.startsWith("/") || pkgIdentifier.startsWith("./")) {
|
|
2354
|
-
const absolutePath =
|
|
2355
|
-
const pkgJsonPath2 =
|
|
2356
|
-
if (
|
|
2405
|
+
const absolutePath = path3.isAbsolute(pkgIdentifier) ? pkgIdentifier : path3.join(rootDir, pkgIdentifier);
|
|
2406
|
+
const pkgJsonPath2 = path3.join(absolutePath, "package.json");
|
|
2407
|
+
if (fs3.existsSync(pkgJsonPath2)) {
|
|
2357
2408
|
try {
|
|
2358
|
-
const pkgJson = JSON.parse(
|
|
2409
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath2, "utf-8"));
|
|
2359
2410
|
if (pkgJson.standardagent?.entryAgents) {
|
|
2360
2411
|
return {
|
|
2361
|
-
packageId: pkgJson.name ||
|
|
2412
|
+
packageId: pkgJson.name || path3.basename(absolutePath),
|
|
2362
2413
|
version: pkgJson.version || "0.0.0",
|
|
2363
2414
|
source: "local",
|
|
2364
2415
|
path: absolutePath,
|
|
@@ -2370,11 +2421,12 @@ var UnpackingService = class {
|
|
|
2370
2421
|
}
|
|
2371
2422
|
return null;
|
|
2372
2423
|
}
|
|
2373
|
-
const
|
|
2374
|
-
const
|
|
2375
|
-
|
|
2424
|
+
const safeIdentifier = assertSafePackageIdentifier(pkgIdentifier);
|
|
2425
|
+
const packedDir = resolvePathWithin(path3.join(rootDir, "agents", "packed"), safeIdentifier);
|
|
2426
|
+
const pkgJsonPath = path3.join(packedDir, "package.json");
|
|
2427
|
+
if (fs3.existsSync(pkgJsonPath)) {
|
|
2376
2428
|
try {
|
|
2377
|
-
const pkgJson = JSON.parse(
|
|
2429
|
+
const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
2378
2430
|
if (pkgJson.standardagent?.entryAgents) {
|
|
2379
2431
|
return {
|
|
2380
2432
|
packageId: pkgJson.name || pkgIdentifier,
|
|
@@ -2415,18 +2467,18 @@ var UnpackingService = class {
|
|
|
2415
2467
|
* Check if a file exists.
|
|
2416
2468
|
*/
|
|
2417
2469
|
fileExists(filePath) {
|
|
2418
|
-
if (
|
|
2470
|
+
if (fs3.existsSync(filePath)) {
|
|
2419
2471
|
return true;
|
|
2420
2472
|
}
|
|
2421
2473
|
const withoutExt = filePath.replace(/\.(ts|js)$/, "");
|
|
2422
|
-
return
|
|
2474
|
+
return fs3.existsSync(`${withoutExt}.ts`) || fs3.existsSync(`${withoutExt}.js`);
|
|
2423
2475
|
}
|
|
2424
2476
|
/**
|
|
2425
2477
|
* Recursively delete a directory.
|
|
2426
2478
|
*/
|
|
2427
2479
|
deleteDirectory(dirPath) {
|
|
2428
|
-
if (
|
|
2429
|
-
|
|
2480
|
+
if (fs3.existsSync(dirPath)) {
|
|
2481
|
+
fs3.rmSync(dirPath, { recursive: true, force: true });
|
|
2430
2482
|
}
|
|
2431
2483
|
}
|
|
2432
2484
|
/**
|