@c4a/server-cli 0.4.12-beta.14 → 0.4.12-beta.16

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": "@c4a/server-cli",
3
- "version": "0.4.12-beta.14",
3
+ "version": "0.4.12-beta.16",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "c4a-server": "./index.js"
package/serve.js CHANGED
@@ -185359,6 +185359,16 @@ var mergeSubtreeIntoParent = (options) => {
185359
185359
 
185360
185360
  // ../api/src/routes/remoteImport.ts
185361
185361
  var getDaemonManager3 = (c) => c.get("daemonManager");
185362
+ var getWsBroadcast = (c) => c.get("wsBroadcast");
185363
+ var TASK_TTL_MS = 10 * 60 * 1000;
185364
+ var taskStore = new Map;
185365
+ function pruneExpiredTasks() {
185366
+ const now2 = Date.now();
185367
+ for (const [id2, entry] of taskStore) {
185368
+ if (now2 - entry.createdAt > TASK_TTL_MS)
185369
+ taskStore.delete(id2);
185370
+ }
185371
+ }
185362
185372
  var extractRepoName = (url2) => {
185363
185373
  try {
185364
185374
  const parsed = new URL(url2);
@@ -185466,20 +185476,55 @@ function createRemoteImportRouter(storageProvider) {
185466
185476
  if (!daemonManager) {
185467
185477
  throw new C4AError("STORAGE_FAILED" /* STORAGE_FAILED */, "DaemonManager unavailable", null);
185468
185478
  }
185469
- const response = await callLibraryRpc({
185479
+ const wsBroadcast = getWsBroadcast(c);
185480
+ const taskId = `task_${generateUUID()}`;
185481
+ pruneExpiredTasks();
185482
+ taskStore.set(taskId, { status: "running", createdAt: Date.now() });
185483
+ const url2 = input.url;
185484
+ callLibraryRpc({
185470
185485
  storageProvider,
185471
185486
  daemonManager,
185472
185487
  libraryId: input.library_id,
185473
185488
  method: "vcs/clone",
185474
185489
  params: {
185475
- url: input.url,
185490
+ url: url2,
185476
185491
  ref: input.ref,
185477
185492
  commit: input.commit,
185478
185493
  ...input.repo_name ? { repo_name: input.repo_name } : {}
185479
185494
  }
185495
+ }).then(async (response) => {
185496
+ try {
185497
+ const result = await unwrapRpcResult(response, url2);
185498
+ taskStore.set(taskId, { status: "done", result, createdAt: Date.now() });
185499
+ wsBroadcast?.({ event: "task/complete", payload: { task_id: taskId, status: "done", result }, timestamp: Date.now() });
185500
+ } catch (err) {
185501
+ const message2 = err instanceof Error ? err.message : "Clone failed";
185502
+ console.error(`[RemoteImport] clone task ${taskId} unwrap error:`, message2);
185503
+ taskStore.set(taskId, { status: "error", error: message2, createdAt: Date.now() });
185504
+ wsBroadcast?.({ event: "task/complete", payload: { task_id: taskId, status: "error", error: message2 }, timestamp: Date.now() });
185505
+ }
185506
+ }).catch((err) => {
185507
+ const message2 = err instanceof Error ? err.message : "Clone failed";
185508
+ console.error(`[RemoteImport] clone task ${taskId} RPC error:`, message2);
185509
+ taskStore.set(taskId, { status: "error", error: message2, createdAt: Date.now() });
185510
+ wsBroadcast?.({ event: "task/complete", payload: { task_id: taskId, status: "error", error: message2 }, timestamp: Date.now() });
185480
185511
  });
185481
- const result = await unwrapRpcResult(response, input.url);
185482
- return c.json(result, 200);
185512
+ return c.json({ task_id: taskId }, 202);
185513
+ });
185514
+ router.get("/remote/tasks/:taskId", async (c) => {
185515
+ requireUserId(c);
185516
+ const taskId = c.req.param("taskId");
185517
+ const entry = taskStore.get(taskId);
185518
+ if (!entry) {
185519
+ throw new C4AError("STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */, "Task not found", { task_id: taskId });
185520
+ }
185521
+ if (entry.status === "done") {
185522
+ return c.json({ task_id: taskId, status: "done", result: entry.result }, 200);
185523
+ }
185524
+ if (entry.status === "error") {
185525
+ return c.json({ task_id: taskId, status: "error", error: entry.error }, 200);
185526
+ }
185527
+ return c.json({ task_id: taskId, status: "running" }, 200);
185483
185528
  });
185484
185529
  router.post("/remote/scan", async (c) => {
185485
185530
  const userId = requireUserId(c);
@@ -188712,8 +188757,12 @@ function createWsEndpoint(app) {
188712
188757
  const broadcastToWebClients = (event) => {
188713
188758
  const payload = JSON.stringify(event);
188714
188759
  for (const client of webClients) {
188715
- if (client.readyState === WS_OPEN) {
188716
- client.send(payload);
188760
+ try {
188761
+ if (client.readyState === WS_OPEN) {
188762
+ client.send(payload);
188763
+ }
188764
+ } catch {
188765
+ webClients.delete(client);
188717
188766
  }
188718
188767
  }
188719
188768
  };
@@ -188769,17 +188818,29 @@ class DaemonManager {
188769
188818
  pending: new Map
188770
188819
  };
188771
188820
  }
188772
- await this.handleMessage(connection2, event.data);
188821
+ try {
188822
+ await this.handleMessage(connection2, event.data);
188823
+ } catch (err) {
188824
+ console.error("[DaemonManager] onMessage error:", err instanceof Error ? err.message : err);
188825
+ }
188773
188826
  },
188774
188827
  onClose: async () => {
188775
- if (connection2) {
188776
- await this.handleClose(connection2);
188828
+ try {
188829
+ if (connection2) {
188830
+ await this.handleClose(connection2);
188831
+ }
188832
+ } catch (err) {
188833
+ console.error("[DaemonManager] onClose error:", err instanceof Error ? err.message : err);
188777
188834
  }
188778
188835
  connection2 = null;
188779
188836
  },
188780
188837
  onError: async () => {
188781
- if (connection2) {
188782
- await this.handleClose(connection2);
188838
+ try {
188839
+ if (connection2) {
188840
+ await this.handleClose(connection2);
188841
+ }
188842
+ } catch (err) {
188843
+ console.error("[DaemonManager] onError error:", err instanceof Error ? err.message : err);
188783
188844
  }
188784
188845
  connection2 = null;
188785
188846
  }
@@ -188894,8 +188955,12 @@ class DaemonManager {
188894
188955
  return;
188895
188956
  }
188896
188957
  if (request.method === "task/progress") {
188958
+ const params = isPlainObject6(request.params) ? request.params : {};
188959
+ if (params.stage === "cloning") {
188960
+ console.log(`[DaemonManager] task/progress cloning: percent=${params.percent}`);
188961
+ }
188897
188962
  this.broadcastEvent("task/progress", {
188898
- ...isPlainObject6(request.params) ? request.params : {},
188963
+ ...params,
188899
188964
  machine_id: connection2.machineId,
188900
188965
  lib_id: connection2.libId
188901
188966
  });
@@ -189151,7 +189216,7 @@ function createServer(options = {}) {
189151
189216
  const apiApp = createApiApp({
189152
189217
  ...options,
189153
189218
  storageProvider,
189154
- contextVariables: { daemonManager }
189219
+ contextVariables: { daemonManager, wsBroadcast: broadcastToWebClients }
189155
189220
  });
189156
189221
  app.route("/api/v1", apiApp);
189157
189222
  app.get("/ws/daemon", upgradeWebSocket(() => daemonManager.createWsHandlers()));
@@ -189545,6 +189610,8 @@ async function startServer() {
189545
189610
  socket.destroy();
189546
189611
  }
189547
189612
  });
189613
+ gateway2.timeout = 300000;
189614
+ gateway2.requestTimeout = 300000;
189548
189615
  attachPortErrorHandler(gateway2, "Gateway");
189549
189616
  webProxy.on("error", (_err, _req, res) => {
189550
189617
  if (res instanceof ServerResponse && !res.headersSent) {
@@ -0,0 +1 @@
1
+ import{c as o,u as m,a as c,j as e,b as d,C as h}from"./index-Cg2XyLTU.js";const p=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],f=o("arrow-left",p);function j({icon:a,title:t,badges:s,meta:l}){const i=m(),{t:r}=c();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"shrink-0",children:a}),e.jsx("h1",{className:"min-w-0 break-all font-mono text-xl font-bold leading-none text-c4a-text-primary",children:t}),s&&s.length>0&&e.jsx("div",{className:"flex items-center gap-1.5 ml-2",children:s.map((n,x)=>e.jsx("span",{children:n},x))})]}),e.jsxs("button",{onClick:()=>i(-1),className:"flex items-center gap-1 text-c4a-text-muted hover:text-c4a-text-primary cursor-pointer transition-colors text-xs font-mono shrink-0 ml-4",children:[e.jsx(f,{size:14}),r("common.back")]})]}),l&&l.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-baseline gap-4 text-xs",children:l.map(n=>e.jsxs("span",{className:"text-c4a-text-muted",children:[n.label,":",e.jsx("span",{className:"text-c4a-text-secondary",children:n.value})]},n.label))})]})}function N(){const{t:a}=c(),{hashId:t}=d();if(!t)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:a("common.loading")})});const s=t.length>16?t.slice(0,16)+"…":t;return e.jsxs("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:[e.jsx(j,{icon:e.jsx("span",{children:"📄"}),title:`Content: ${s}`}),e.jsx(h,{hashId:t})]})}export{N as ContentDetail};
@@ -0,0 +1 @@
1
+ import{c as o,u as m,a as c,j as e,b as d,C as h}from"./index-CxvmfJRj.js";const p=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],f=o("arrow-left",p);function j({icon:a,title:t,badges:s,meta:l}){const i=m(),{t:r}=c();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"shrink-0",children:a}),e.jsx("h1",{className:"min-w-0 break-all font-mono text-xl font-bold leading-none text-c4a-text-primary",children:t}),s&&s.length>0&&e.jsx("div",{className:"flex items-center gap-1.5 ml-2",children:s.map((n,x)=>e.jsx("span",{children:n},x))})]}),e.jsxs("button",{onClick:()=>i(-1),className:"flex items-center gap-1 text-c4a-text-muted hover:text-c4a-text-primary cursor-pointer transition-colors text-xs font-mono shrink-0 ml-4",children:[e.jsx(f,{size:14}),r("common.back")]})]}),l&&l.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-baseline gap-4 text-xs",children:l.map(n=>e.jsxs("span",{className:"text-c4a-text-muted",children:[n.label,":",e.jsx("span",{className:"text-c4a-text-secondary",children:n.value})]},n.label))})]})}function N(){const{t:a}=c(),{hashId:t}=d();if(!t)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:a("common.loading")})});const s=t.length>16?t.slice(0,16)+"…":t;return e.jsxs("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:[e.jsx(j,{icon:e.jsx("span",{children:"📄"}),title:`Content: ${s}`}),e.jsx(h,{hashId:t})]})}export{N as ContentDetail};
@@ -0,0 +1 @@
1
+ import{c as o,u as m,a as c,j as e,b as d,C as h}from"./index-Bol5oT-i.js";const p=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],f=o("arrow-left",p);function j({icon:a,title:t,badges:s,meta:l}){const i=m(),{t:r}=c();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"shrink-0",children:a}),e.jsx("h1",{className:"min-w-0 break-all font-mono text-xl font-bold leading-none text-c4a-text-primary",children:t}),s&&s.length>0&&e.jsx("div",{className:"flex items-center gap-1.5 ml-2",children:s.map((n,x)=>e.jsx("span",{children:n},x))})]}),e.jsxs("button",{onClick:()=>i(-1),className:"flex items-center gap-1 text-c4a-text-muted hover:text-c4a-text-primary cursor-pointer transition-colors text-xs font-mono shrink-0 ml-4",children:[e.jsx(f,{size:14}),r("common.back")]})]}),l&&l.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-baseline gap-4 text-xs",children:l.map(n=>e.jsxs("span",{className:"text-c4a-text-muted",children:[n.label,":",e.jsx("span",{className:"text-c4a-text-secondary",children:n.value})]},n.label))})]})}function N(){const{t:a}=c(),{hashId:t}=d();if(!t)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:a("common.loading")})});const s=t.length>16?t.slice(0,16)+"…":t;return e.jsxs("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:[e.jsx(j,{icon:e.jsx("span",{children:"📄"}),title:`Content: ${s}`}),e.jsx(h,{hashId:t})]})}export{N as ContentDetail};
@@ -0,0 +1 @@
1
+ import{a as n,b as a,j as e,E as i}from"./index-Cg2XyLTU.js";function r(){const{t:s}=n(),{entityId:t}=a();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(i,{entityId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as EntityDetail};
@@ -0,0 +1 @@
1
+ import{a as n,b as a,j as e,E as i}from"./index-Bol5oT-i.js";function r(){const{t:s}=n(),{entityId:t}=a();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(i,{entityId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as EntityDetail};
@@ -0,0 +1 @@
1
+ import{a as n,b as a,j as e,E as i}from"./index-CxvmfJRj.js";function r(){const{t:s}=n(),{entityId:t}=a();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(i,{entityId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as EntityDetail};
@@ -0,0 +1 @@
1
+ import{a,b as n,j as e,R as l}from"./index-Bol5oT-i.js";function r(){const{t:s}=a(),{relationId:t}=n();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(l,{relationId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as RelationDetail};
@@ -0,0 +1 @@
1
+ import{a,b as n,j as e,R as l}from"./index-CxvmfJRj.js";function r(){const{t:s}=a(),{relationId:t}=n();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(l,{relationId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as RelationDetail};
@@ -0,0 +1 @@
1
+ import{a,b as n,j as e,R as l}from"./index-Cg2XyLTU.js";function r(){const{t:s}=a(),{relationId:t}=n();return t?e.jsx("div",{className:"flex flex-1 flex-col p-4 md:p-6",children:e.jsx(l,{relationId:t})}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:e.jsx("p",{className:"text-sm text-c4a-text-muted",children:s("common.loading")})})}export{r as RelationDetail};