@limecloud/agent-app-studio 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.
Files changed (3) hide show
  1. package/APP.md +1 -1
  2. package/package.json +3 -2
  3. package/src/server.mjs +33 -0
package/APP.md CHANGED
@@ -2,7 +2,7 @@
2
2
  manifestVersion: 0.7.0
3
3
  name: lime-agent-app-studio
4
4
  displayName: Lime Agent App Studio
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  status: preview
7
7
  appType: developer-tool
8
8
  description: 面向已认证开发者的 Agent App 可视化发布工作台和 npm CLI 入口。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limecloud/agent-app-studio",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Lime Agent App Studio CLI and visual publisher for Agent App packages.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -27,7 +27,8 @@
27
27
  "test": "node --test tests/*.test.mjs",
28
28
  "pack:dry-run": "npm pack --dry-run",
29
29
  "publish:dry-run": "npm publish --access public --dry-run",
30
- "publish:npm": "npm publish --access public"
30
+ "publish:npm": "npm publish --access public",
31
+ "dev": "node src/server.mjs"
31
32
  },
32
33
  "engines": {
33
34
  "node": ">=20.0.0"
package/src/server.mjs CHANGED
@@ -16,6 +16,13 @@ export async function startStudioServer(options = {}) {
16
16
  const port = Number(options.port ?? 4177);
17
17
  const server = createServer(async (req, res) => {
18
18
  try {
19
+ if (req.method === "GET" && req.url === "/api/bootstrap") {
20
+ return sendJson(res, {
21
+ appId: "lime-agent-app-studio",
22
+ status: "ok",
23
+ entry: "dashboard",
24
+ });
25
+ }
19
26
  if (req.method === "POST" && req.url === "/api/inspect") {
20
27
  const body = await readJson(req);
21
28
  return sendJson(res, await inspectProject(body.appDir || "."));
@@ -46,10 +53,22 @@ async function serveStatic(req, res) {
46
53
  content = await readFile(filePath);
47
54
  } catch (error) {
48
55
  if (error?.code === "ENOENT" || error?.code === "EISDIR") {
56
+ if (acceptsHtml(req)) {
57
+ return sendFile(res, join(appRoot, "index.html"));
58
+ }
49
59
  return sendNotFound(res);
50
60
  }
51
61
  throw error;
52
62
  }
63
+ return sendBuffer(res, filePath, content);
64
+ }
65
+
66
+ async function sendFile(res, filePath) {
67
+ const content = await readFile(filePath);
68
+ return sendBuffer(res, filePath, content);
69
+ }
70
+
71
+ function sendBuffer(res, filePath, content) {
53
72
  const type = contentType(filePath);
54
73
  res.writeHead(200, { "Content-Type": type });
55
74
  res.end(content);
@@ -89,3 +108,17 @@ function contentType(path) {
89
108
  return "application/octet-stream";
90
109
  }
91
110
  }
111
+
112
+ function acceptsHtml(req) {
113
+ const accept = req.headers.accept || "";
114
+ return accept.includes("text/html");
115
+ }
116
+
117
+ function isMainModule() {
118
+ return process.argv[1] && import.meta.url === new URL(process.argv[1], "file:").href;
119
+ }
120
+
121
+ if (isMainModule()) {
122
+ const { url } = await startStudioServer({ port: process.env.PORT });
123
+ console.log(`Lime Agent App Studio runtime 已启动:${url}`);
124
+ }