agentcn 0.1.0

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.
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getExecErrorOutput = getExecErrorOutput;
37
+ exports.detectPackageManager = detectPackageManager;
38
+ exports.installDependencies = installDependencies;
39
+ const path = __importStar(require("path"));
40
+ const child_process_1 = require("child_process");
41
+ const path_exists_1 = require("path-exists");
42
+ const logger_js_1 = require("../utils/logger.js");
43
+ function getExecErrorOutput(error) {
44
+ if (!error || typeof error !== "object") {
45
+ return String(error ?? "");
46
+ }
47
+ const execError = error;
48
+ const message = String(execError.message ?? "");
49
+ const stdout = String(execError.stdout ?? "");
50
+ const stderr = String(execError.stderr ?? "");
51
+ return [message, stdout, stderr].filter(Boolean).join("\n");
52
+ }
53
+ function detectPackageManager(cwd) {
54
+ if ((0, path_exists_1.pathExistsSync)(path.join(cwd, "pnpm-lock.yaml")))
55
+ return "pnpm";
56
+ if ((0, path_exists_1.pathExistsSync)(path.join(cwd, "yarn.lock")))
57
+ return "yarn";
58
+ return "npm";
59
+ }
60
+ function installDependencies(cwd, dependencies, options) {
61
+ const deps = dependencies ?? [];
62
+ if (deps.length === 0)
63
+ return [];
64
+ if (options.dryRun)
65
+ return deps;
66
+ const pm = detectPackageManager(cwd);
67
+ const depString = deps.join(" ");
68
+ const cmd = pm === "pnpm"
69
+ ? `pnpm add ${depString}`
70
+ : pm === "yarn"
71
+ ? `yarn add ${depString}`
72
+ : `npm install ${depString}`;
73
+ const runInstall = (installCmd) => (0, child_process_1.execSync)(installCmd, {
74
+ cwd,
75
+ stdio: options.verbose ? "inherit" : "pipe",
76
+ encoding: options.verbose ? undefined : "utf-8",
77
+ });
78
+ try {
79
+ runInstall(cmd);
80
+ }
81
+ catch (error) {
82
+ const message = getExecErrorOutput(error);
83
+ if (pm === "pnpm" && message.includes("ERR_PNPM_ADDING_TO_ROOT")) {
84
+ // When target cwd is a workspace root, pnpm requires explicit -w.
85
+ try {
86
+ runInstall(`pnpm add -w ${depString}`);
87
+ }
88
+ catch (fallbackError) {
89
+ if (!options.verbose) {
90
+ const fallbackMsg = getExecErrorOutput(fallbackError);
91
+ if (fallbackMsg.trim().length > 0)
92
+ logger_js_1.logger.error(fallbackMsg);
93
+ }
94
+ throw fallbackError;
95
+ }
96
+ }
97
+ else {
98
+ if (!options.verbose && message.trim().length > 0) {
99
+ logger_js_1.logger.error(message);
100
+ }
101
+ throw error;
102
+ }
103
+ }
104
+ return deps;
105
+ }
@@ -0,0 +1,9 @@
1
+ import type { PlannedFileAction, RegistryItem } from "../types.js";
2
+ export declare function planInstall(item: RegistryItem, cwd: string, options: {
3
+ overwrite: boolean;
4
+ }): PlannedFileAction[];
5
+ export declare function applyInstallPlan(actions: PlannedFileAction[]): {
6
+ created: string[];
7
+ updated: string[];
8
+ skipped: string[];
9
+ };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.planInstall = planInstall;
37
+ exports.applyInstallPlan = applyInstallPlan;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ function planInstall(item, cwd, options) {
41
+ return item.files.map((file) => {
42
+ const targetPath = file.target ?? file.path;
43
+ const absoluteTargetPath = path.join(cwd, targetPath);
44
+ const exists = fs.existsSync(absoluteTargetPath);
45
+ const action = exists
46
+ ? options.overwrite
47
+ ? "update"
48
+ : "skip"
49
+ : "create";
50
+ return {
51
+ sourcePath: file.path,
52
+ targetPath,
53
+ absoluteTargetPath,
54
+ content: file.content,
55
+ action,
56
+ };
57
+ });
58
+ }
59
+ function applyInstallPlan(actions) {
60
+ const created = [];
61
+ const updated = [];
62
+ const skipped = [];
63
+ for (const action of actions) {
64
+ if (action.action === "skip") {
65
+ skipped.push(action.targetPath);
66
+ continue;
67
+ }
68
+ fs.mkdirSync(path.dirname(action.absoluteTargetPath), { recursive: true });
69
+ fs.writeFileSync(action.absoluteTargetPath, action.content, "utf-8");
70
+ if (action.action === "create")
71
+ created.push(action.targetPath);
72
+ if (action.action === "update")
73
+ updated.push(action.targetPath);
74
+ }
75
+ return { created, updated, skipped };
76
+ }
@@ -0,0 +1,5 @@
1
+ import type { AddOptions, AddOptionsInput, RegistryIndex, RegistryItem } from "../types.js";
2
+ export declare function parseAddOptions(input: AddOptionsInput, cwd: string): AddOptions;
3
+ export declare function resolveRegistrySource(registryPath: string | undefined, cwd: string): string;
4
+ export declare function loadRegistryItem(agentName: string, registryBase: string): Promise<RegistryItem>;
5
+ export declare function loadRegistryIndex(registryBase: string): Promise<RegistryIndex>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseAddOptions = parseAddOptions;
37
+ exports.resolveRegistrySource = resolveRegistrySource;
38
+ exports.loadRegistryItem = loadRegistryItem;
39
+ exports.loadRegistryIndex = loadRegistryIndex;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const path_exists_1 = require("path-exists");
43
+ const schemas_js_1 = require("../schemas.js");
44
+ const constants_js_1 = require("../constants.js");
45
+ function isHttpUrl(value) {
46
+ return value.startsWith("http://") || value.startsWith("https://");
47
+ }
48
+ function parseAddOptions(input, cwd) {
49
+ const parsed = schemas_js_1.addOptionsSchema.parse(input);
50
+ return {
51
+ registry: parsed.registry,
52
+ dryRun: parsed.dryRun,
53
+ overwrite: parsed.overwrite,
54
+ yes: parsed.yes,
55
+ verbose: parsed.verbose,
56
+ cwd: parsed.cwd ? path.resolve(cwd, parsed.cwd) : cwd,
57
+ };
58
+ }
59
+ function resolveRegistrySource(registryPath, cwd) {
60
+ if (registryPath) {
61
+ if (isHttpUrl(registryPath))
62
+ return registryPath;
63
+ const resolved = path.resolve(cwd, registryPath);
64
+ if ((0, path_exists_1.pathExistsSync)(resolved))
65
+ return resolved;
66
+ }
67
+ const envRegistry = process.env.AGENTCN_REGISTRY_URL?.trim();
68
+ if (envRegistry) {
69
+ if (isHttpUrl(envRegistry))
70
+ return envRegistry;
71
+ const resolved = path.resolve(cwd, envRegistry);
72
+ if ((0, path_exists_1.pathExistsSync)(resolved))
73
+ return resolved;
74
+ }
75
+ const scriptDir = path.dirname(process.argv[1] || cwd);
76
+ const localRegistry = path.resolve(scriptDir, "../../../../apps/web/public/r");
77
+ if ((0, path_exists_1.pathExistsSync)(localRegistry))
78
+ return localRegistry;
79
+ return "https://agentcn.dev/r";
80
+ }
81
+ async function loadJson(source) {
82
+ if (isHttpUrl(source)) {
83
+ const res = await fetch(source);
84
+ if (!res.ok) {
85
+ throw new Error(`Failed to fetch ${source} (${res.status})`);
86
+ }
87
+ return res.json();
88
+ }
89
+ if (!(0, path_exists_1.pathExistsSync)(source)) {
90
+ throw new Error(`File not found: ${source}`);
91
+ }
92
+ return JSON.parse(fs.readFileSync(source, "utf-8"));
93
+ }
94
+ function assertSchemaVersion(schemaVersion) {
95
+ if (schemaVersion !== constants_js_1.REGISTRY_SCHEMA_VERSION) {
96
+ throw new Error(`Registry schema mismatch. Expected ${constants_js_1.REGISTRY_SCHEMA_VERSION}, got ${schemaVersion}.`);
97
+ }
98
+ }
99
+ async function loadRegistryItem(agentName, registryBase) {
100
+ const source = isHttpUrl(registryBase)
101
+ ? `${registryBase.replace(/\/$/, "")}/${agentName}.json`
102
+ : path.join(registryBase, `${agentName}.json`);
103
+ const json = await loadJson(source);
104
+ const item = schemas_js_1.registryItemSchema.parse(json);
105
+ assertSchemaVersion(item.schemaVersion);
106
+ return item;
107
+ }
108
+ async function loadRegistryIndex(registryBase) {
109
+ const source = isHttpUrl(registryBase)
110
+ ? `${registryBase.replace(/\/$/, "")}/index.json`
111
+ : path.join(registryBase, "index.json");
112
+ const json = await loadJson(source);
113
+ const index = schemas_js_1.registryIndexSchema.parse(json);
114
+ assertSchemaVersion(index.schemaVersion);
115
+ return index;
116
+ }
@@ -0,0 +1,144 @@
1
+ import { z } from "zod";
2
+ export declare const registryFileSchema: z.ZodObject<{
3
+ path: z.ZodString;
4
+ type: z.ZodString;
5
+ target: z.ZodOptional<z.ZodString>;
6
+ content: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ content: string;
9
+ path: string;
10
+ type: string;
11
+ target?: string | undefined;
12
+ }, {
13
+ content: string;
14
+ path: string;
15
+ type: string;
16
+ target?: string | undefined;
17
+ }>;
18
+ export declare const registryItemSchema: z.ZodObject<{
19
+ schemaVersion: z.ZodNumber;
20
+ name: z.ZodString;
21
+ type: z.ZodString;
22
+ description: z.ZodString;
23
+ title: z.ZodOptional<z.ZodString>;
24
+ categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
25
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
26
+ envVars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
27
+ files: z.ZodArray<z.ZodObject<{
28
+ path: z.ZodString;
29
+ type: z.ZodString;
30
+ target: z.ZodOptional<z.ZodString>;
31
+ content: z.ZodString;
32
+ }, "strip", z.ZodTypeAny, {
33
+ content: string;
34
+ path: string;
35
+ type: string;
36
+ target?: string | undefined;
37
+ }, {
38
+ content: string;
39
+ path: string;
40
+ type: string;
41
+ target?: string | undefined;
42
+ }>, "many">;
43
+ }, "strip", z.ZodTypeAny, {
44
+ type: string;
45
+ schemaVersion: number;
46
+ name: string;
47
+ description: string;
48
+ files: {
49
+ content: string;
50
+ path: string;
51
+ type: string;
52
+ target?: string | undefined;
53
+ }[];
54
+ title?: string | undefined;
55
+ categories?: string[] | undefined;
56
+ dependencies?: string[] | undefined;
57
+ envVars?: Record<string, string> | undefined;
58
+ }, {
59
+ type: string;
60
+ schemaVersion: number;
61
+ name: string;
62
+ description: string;
63
+ files: {
64
+ content: string;
65
+ path: string;
66
+ type: string;
67
+ target?: string | undefined;
68
+ }[];
69
+ title?: string | undefined;
70
+ categories?: string[] | undefined;
71
+ dependencies?: string[] | undefined;
72
+ envVars?: Record<string, string> | undefined;
73
+ }>;
74
+ export declare const registryIndexItemSchema: z.ZodObject<{
75
+ name: z.ZodString;
76
+ description: z.ZodString;
77
+ categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
78
+ }, "strip", z.ZodTypeAny, {
79
+ name: string;
80
+ description: string;
81
+ categories?: string[] | undefined;
82
+ }, {
83
+ name: string;
84
+ description: string;
85
+ categories?: string[] | undefined;
86
+ }>;
87
+ export declare const registryIndexSchema: z.ZodObject<{
88
+ schemaVersion: z.ZodNumber;
89
+ name: z.ZodString;
90
+ homepage: z.ZodOptional<z.ZodString>;
91
+ items: z.ZodArray<z.ZodObject<{
92
+ name: z.ZodString;
93
+ description: z.ZodString;
94
+ categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
95
+ }, "strip", z.ZodTypeAny, {
96
+ name: string;
97
+ description: string;
98
+ categories?: string[] | undefined;
99
+ }, {
100
+ name: string;
101
+ description: string;
102
+ categories?: string[] | undefined;
103
+ }>, "many">;
104
+ }, "strip", z.ZodTypeAny, {
105
+ schemaVersion: number;
106
+ name: string;
107
+ items: {
108
+ name: string;
109
+ description: string;
110
+ categories?: string[] | undefined;
111
+ }[];
112
+ homepage?: string | undefined;
113
+ }, {
114
+ schemaVersion: number;
115
+ name: string;
116
+ items: {
117
+ name: string;
118
+ description: string;
119
+ categories?: string[] | undefined;
120
+ }[];
121
+ homepage?: string | undefined;
122
+ }>;
123
+ export declare const addOptionsSchema: z.ZodObject<{
124
+ registry: z.ZodOptional<z.ZodString>;
125
+ dryRun: z.ZodDefault<z.ZodBoolean>;
126
+ overwrite: z.ZodDefault<z.ZodBoolean>;
127
+ yes: z.ZodDefault<z.ZodBoolean>;
128
+ verbose: z.ZodDefault<z.ZodBoolean>;
129
+ cwd: z.ZodOptional<z.ZodString>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ dryRun: boolean;
132
+ overwrite: boolean;
133
+ yes: boolean;
134
+ verbose: boolean;
135
+ cwd?: string | undefined;
136
+ registry?: string | undefined;
137
+ }, {
138
+ cwd?: string | undefined;
139
+ registry?: string | undefined;
140
+ dryRun?: boolean | undefined;
141
+ overwrite?: boolean | undefined;
142
+ yes?: boolean | undefined;
143
+ verbose?: boolean | undefined;
144
+ }>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addOptionsSchema = exports.registryIndexSchema = exports.registryIndexItemSchema = exports.registryItemSchema = exports.registryFileSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.registryFileSchema = zod_1.z.object({
6
+ path: zod_1.z.string().min(1),
7
+ type: zod_1.z.string().min(1),
8
+ target: zod_1.z.string().min(1).optional(),
9
+ content: zod_1.z.string(),
10
+ });
11
+ exports.registryItemSchema = zod_1.z.object({
12
+ schemaVersion: zod_1.z.number().int(),
13
+ name: zod_1.z.string().min(1),
14
+ type: zod_1.z.string().min(1),
15
+ description: zod_1.z.string().min(1),
16
+ title: zod_1.z.string().optional(),
17
+ categories: zod_1.z.array(zod_1.z.string()).optional(),
18
+ dependencies: zod_1.z.array(zod_1.z.string()).optional(),
19
+ envVars: zod_1.z.record(zod_1.z.string()).optional(),
20
+ files: zod_1.z.array(exports.registryFileSchema),
21
+ });
22
+ exports.registryIndexItemSchema = zod_1.z.object({
23
+ name: zod_1.z.string().min(1),
24
+ description: zod_1.z.string().min(1),
25
+ categories: zod_1.z.array(zod_1.z.string()).optional(),
26
+ });
27
+ exports.registryIndexSchema = zod_1.z.object({
28
+ schemaVersion: zod_1.z.number().int(),
29
+ name: zod_1.z.string().min(1),
30
+ homepage: zod_1.z.string().optional(),
31
+ items: zod_1.z.array(exports.registryIndexItemSchema),
32
+ });
33
+ exports.addOptionsSchema = zod_1.z.object({
34
+ registry: zod_1.z.string().optional(),
35
+ dryRun: zod_1.z.boolean().default(false),
36
+ overwrite: zod_1.z.boolean().default(false),
37
+ yes: zod_1.z.boolean().default(false),
38
+ verbose: zod_1.z.boolean().default(false),
39
+ cwd: zod_1.z.string().optional(),
40
+ });
@@ -0,0 +1 @@
1
+ export {};