@zshuangmu/agenthub 0.1.0 → 0.1.2
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/package.json +1 -1
- package/src/api-server.js +22 -1
- package/src/cli.js +6 -3
- package/src/commands/install.js +20 -2
- package/src/lib/html.js +420 -347
- package/src/lib/install.js +52 -3
- package/src/lib/registry.js +38 -3
- package/src/server.js +36 -1
package/package.json
CHANGED
package/src/api-server.js
CHANGED
|
@@ -2,7 +2,7 @@ import http from "node:http";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { infoCommand, installCommand, publishCommand, searchCommand } from "./index.js";
|
|
5
|
-
import { publishUploadedBundle } from "./lib/bundle-transfer.js";
|
|
5
|
+
import { publishUploadedBundle, serializeBundleDir } from "./lib/bundle-transfer.js";
|
|
6
6
|
import { notFound, readJsonBody, sendJson } from "./lib/http.js";
|
|
7
7
|
import {
|
|
8
8
|
initDatabase,
|
|
@@ -106,6 +106,27 @@ export async function createApiServer({ registryDir, port = 3000 }) {
|
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// API: 下载 Agent Bundle(远程安装)
|
|
110
|
+
if (url.pathname.startsWith("/api/agents/") && url.pathname.endsWith("/download")) {
|
|
111
|
+
const slug = url.pathname.slice("/api/agents/".length, -"/download".length);
|
|
112
|
+
if (!isValidSlug(slug)) {
|
|
113
|
+
sendJson(response, 400, { error: "Invalid slug format" }, corsHeaders);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const version = url.searchParams.get("version") || undefined;
|
|
118
|
+
const manifest = await infoCommand(version ? `${slug}:${version}` : slug, { registry: registryDir });
|
|
119
|
+
const bundleDir = path.join(registryDir, "agents", manifest.slug, manifest.version);
|
|
120
|
+
const payload = await serializeBundleDir(bundleDir);
|
|
121
|
+
// 记录下载(包含元数据)
|
|
122
|
+
await incrementDownloads(registryDir, manifest.slug, {
|
|
123
|
+
ip: request.socket.remoteAddress,
|
|
124
|
+
userAgent: request.headers['user-agent']
|
|
125
|
+
});
|
|
126
|
+
sendJson(response, 200, payload, corsHeaders);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
109
130
|
// API: 获取单个 Agent 详情
|
|
110
131
|
if (url.pathname.startsWith("/api/agents/")) {
|
|
111
132
|
const slug = url.pathname.slice("/api/agents/".length);
|
package/src/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
/**
|
|
2
3
|
* AgentHub CLI
|
|
3
4
|
* AI Agent 打包与分发平台
|
|
@@ -95,16 +96,18 @@ agenthub publish - 发布 Agent
|
|
|
95
96
|
agenthub install - 安装 Agent
|
|
96
97
|
|
|
97
98
|
用法:
|
|
98
|
-
agenthub install <agent-slug>[:version] --registry <dir> --target-workspace <dir>
|
|
99
|
+
agenthub install <agent-slug>[:version] [--registry <dir> | --server <url>] --target-workspace <dir>
|
|
99
100
|
|
|
100
101
|
选项:
|
|
101
|
-
--registry <dir> Registry
|
|
102
|
+
--registry <dir> 本地 Registry 目录(与 --server 二选一)
|
|
103
|
+
--server <url> 远程服务器地址(默认: https://agenthub.cyou)
|
|
102
104
|
--target-workspace <dir> 目标工作区目录 (必需)
|
|
103
105
|
--force 强制覆盖
|
|
104
106
|
|
|
105
107
|
示例:
|
|
106
108
|
agenthub install code-review-assistant --registry ./.registry --target-workspace ./workspace
|
|
107
|
-
agenthub install my-agent:1.0.0 --
|
|
109
|
+
agenthub install my-agent:1.0.0 --server https://agenthub.cyou --target-workspace ./workspace
|
|
110
|
+
agenthub install meeting-minutes-assistant --target-workspace ./workspace
|
|
108
111
|
`,
|
|
109
112
|
search: `
|
|
110
113
|
agenthub search - 搜索 Agent
|
package/src/commands/install.js
CHANGED
|
@@ -2,9 +2,27 @@ import path from "node:path";
|
|
|
2
2
|
import { installBundle } from "../lib/install.js";
|
|
3
3
|
|
|
4
4
|
export async function installCommand(agentSpec, options) {
|
|
5
|
+
const targetWorkspace = path.resolve(options.targetWorkspace);
|
|
6
|
+
if (!targetWorkspace) {
|
|
7
|
+
throw new Error("--target-workspace is required");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 默认走远程服务器,提升网站复制命令可用性
|
|
11
|
+
if (!options.registry && !options.server) {
|
|
12
|
+
options.server = "https://agenthub.cyou";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (options.registry) {
|
|
16
|
+
return installBundle({
|
|
17
|
+
registryDir: path.resolve(options.registry),
|
|
18
|
+
agentSpec,
|
|
19
|
+
targetWorkspace,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
return installBundle({
|
|
6
|
-
|
|
24
|
+
serverUrl: options.server,
|
|
7
25
|
agentSpec,
|
|
8
|
-
targetWorkspace
|
|
26
|
+
targetWorkspace,
|
|
9
27
|
});
|
|
10
28
|
}
|