@zshuangmu/agenthub 0.1.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zshuangmu/agenthub",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI Agent 打包与分发平台 - 一句话打包上传,一键下载获得能力",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/api-server.js CHANGED
@@ -118,6 +118,11 @@ export async function createApiServer({ registryDir, port = 3000 }) {
118
118
  const manifest = await infoCommand(version ? `${slug}:${version}` : slug, { registry: registryDir });
119
119
  const bundleDir = path.join(registryDir, "agents", manifest.slug, manifest.version);
120
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
+ });
121
126
  sendJson(response, 200, payload, corsHeaders);
122
127
  return;
123
128
  }
@@ -13,8 +13,28 @@ async function applyBundleDir({ bundleDir, targetWorkspace }) {
13
13
  return { manifest, appliedPath };
14
14
  }
15
15
 
16
- async function installFromRemote({ serverUrl, agentSpec, targetWorkspace }) {
16
+ /**
17
+ * 解析 agentSpec,支持两种格式:
18
+ * - 短名格式:slug 或 slug:version
19
+ * - URI 格式:agenthub://owner/slug@version
20
+ */
21
+ function parseAgentSpec(agentSpec) {
22
+ // URI 格式:agenthub://owner/slug@version
23
+ if (agentSpec.startsWith("agenthub://")) {
24
+ const uri = agentSpec.slice("agenthub://".length);
25
+ // owner/slug@version -> slug@version
26
+ const parts = uri.split("/");
27
+ const lastPart = parts[parts.length - 1] || parts[parts.length - 2];
28
+ const [slug, version] = lastPart.split("@");
29
+ return { slug, version: version || undefined };
30
+ }
31
+ // 短名格式:slug 或 slug:version
17
32
  const [slug, version] = agentSpec.split(":");
33
+ return { slug, version: version || undefined };
34
+ }
35
+
36
+ async function installFromRemote({ serverUrl, agentSpec, targetWorkspace }) {
37
+ const { slug, version } = parseAgentSpec(agentSpec);
18
38
  const url = new URL(`/api/agents/${slug}/download`, serverUrl);
19
39
  if (version) {
20
40
  url.searchParams.set("version", version);
@@ -1,9 +1,23 @@
1
1
  import path from "node:path";
2
2
  import { copyDir, ensureDir, pathExists, readJson, writeJson } from "./fs-utils.js";
3
3
 
4
+ /**
5
+ * 解析 agentSpec,支持两种格式:
6
+ * - 短名格式:slug 或 slug:version
7
+ * - URI 格式:agenthub://owner/slug@version
8
+ */
4
9
  function parseSpec(agentSpec) {
10
+ // URI 格式:agenthub://owner/slug@version
11
+ if (agentSpec.startsWith("agenthub://")) {
12
+ const uri = agentSpec.slice("agenthub://".length);
13
+ const parts = uri.split("/");
14
+ const lastPart = parts[parts.length - 1] || parts[parts.length - 2];
15
+ const [slug, version] = lastPart.split("@");
16
+ return { slug, version: version || undefined };
17
+ }
18
+ // 短名格式:slug 或 slug:version
5
19
  const [slug, version] = agentSpec.split(":");
6
- return { slug, version };
20
+ return { slug, version: version || undefined };
7
21
  }
8
22
 
9
23
  export async function publishBundle(bundleDir, registryDir) {
package/src/server.js CHANGED
@@ -115,6 +115,11 @@ export async function createServer({ registryDir, port = 3000, host = "0.0.0.0"
115
115
  const manifest = await infoCommand(version ? `${slug}:${version}` : slug, { registry: registryDir });
116
116
  const bundleDir = path.join(registryDir, "agents", manifest.slug, manifest.version);
117
117
  const payload = await serializeBundleDir(bundleDir);
118
+ // 记录下载(包含元数据)
119
+ await incrementDownloads(registryDir, manifest.slug, {
120
+ ip: request.socket.remoteAddress,
121
+ userAgent: request.headers['user-agent']
122
+ });
118
123
  sendJson(response, 200, payload);
119
124
  return;
120
125
  }