@lobehub/cli 0.0.91 → 0.0.93

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/dist/index.js CHANGED
@@ -9431,6 +9431,10 @@ var init_chunk$1 = __esmMin((() => {
9431
9431
  init_document$1();
9432
9432
  }));
9433
9433
 
9434
+ //#endregion
9435
+ //#region ../../packages/types/src/contact.ts
9436
+ var init_contact = __esmMin((() => {}));
9437
+
9434
9438
  //#endregion
9435
9439
  //#region ../../packages/types/src/conversation.ts
9436
9440
  var init_conversation = __esmMin((() => {}));
@@ -11339,7 +11343,8 @@ var init_preference = __esmMin((() => {
11339
11343
  ]).optional(),
11340
11344
  topicIncludeCompleted: boolean().optional(),
11341
11345
  topicSortBy: _enum(["createdAt", "updatedAt"]).optional(),
11342
- useCmdEnterToSend: boolean().optional()
11346
+ useCmdEnterToSend: boolean().optional(),
11347
+ workspace: object$1({ order: array(string()).optional() }).optional()
11343
11348
  }).partial();
11344
11349
  }));
11345
11350
 
@@ -12108,6 +12113,7 @@ var init_src$2 = __esmMin((() => {
12108
12113
  init_brief();
12109
12114
  init_channel();
12110
12115
  init_chunk$1();
12116
+ init_contact();
12111
12117
  init_conversation();
12112
12118
  init_creds();
12113
12119
  init_dashboard();
@@ -16847,6 +16853,7 @@ const MAX_MISSED_HEARTBEATS$1 = 3;
16847
16853
  */
16848
16854
  const CONNECT_TIMEOUT = 15e3;
16849
16855
  const METRICS_ACK_TIMEOUT_MS = 15e3;
16856
+ const COMPLETION_ACK_TIMEOUT_MS = 3e4;
16850
16857
  /**
16851
16858
  * Close reason the gateway sends when a newer socket with the same
16852
16859
  * `connectionId` takes over. `connectionId` is persisted per install, so this
@@ -16854,6 +16861,7 @@ const METRICS_ACK_TIMEOUT_MS = 15e3;
16854
16861
  * home) shows up.
16855
16862
  */
16856
16863
  const REPLACED_CLOSE_REASON = "Replaced by new connection";
16864
+ const completionAckKey = (operationId, toolCallId) => `${operationId}:${toolCallId}`;
16857
16865
  const noopLogger$1 = {
16858
16866
  debug: () => {},
16859
16867
  error: () => {},
@@ -16870,6 +16878,7 @@ var GatewayClient = class extends EventEmitter {
16870
16878
  missedHeartbeats = 0;
16871
16879
  status = "disconnected";
16872
16880
  pendingMetricAcks = /* @__PURE__ */ new Map();
16881
+ pendingCompletionAcks = /* @__PURE__ */ new Map();
16873
16882
  intentionalDisconnect = false;
16874
16883
  /**
16875
16884
  * When each socket abandoned mid-handshake was abandoned. Only such a socket
@@ -17004,6 +17013,37 @@ var GatewayClient = class extends EventEmitter {
17004
17013
  });
17005
17014
  });
17006
17015
  }
17016
+ /**
17017
+ * Send the late result of a call the device kept watching, and resolve with
17018
+ * the gateway's verdict. Rejects when not connected, when the connection drops
17019
+ * mid-flight, or when no ack arrives in time — the caller keeps the result and
17020
+ * sends it again, which is safe because the server applies it at most once.
17021
+ */
17022
+ reportToolCallCompletion(completion) {
17023
+ if (this.status !== "connected" || this.ws?.readyState !== wrapper_default.OPEN) return Promise.reject(/* @__PURE__ */ new Error("Gateway not connected"));
17024
+ const key = completionAckKey(completion.operationId, completion.toolCallId);
17025
+ this.pendingCompletionAcks.get(key)?.reject(/* @__PURE__ */ new Error("Superseded by a newer send"));
17026
+ return new Promise((resolve, reject) => {
17027
+ const timer = setTimeout(() => {
17028
+ this.pendingCompletionAcks.delete(key);
17029
+ reject(/* @__PURE__ */ new Error("Timed out waiting for tool_call_completion_ack"));
17030
+ }, COMPLETION_ACK_TIMEOUT_MS);
17031
+ this.pendingCompletionAcks.set(key, {
17032
+ reject: (error) => {
17033
+ clearTimeout(timer);
17034
+ reject(error);
17035
+ },
17036
+ resolve: (ack) => {
17037
+ clearTimeout(timer);
17038
+ resolve(ack);
17039
+ }
17040
+ });
17041
+ this.sendMessage({
17042
+ ...completion,
17043
+ type: "tool_call_completion"
17044
+ });
17045
+ });
17046
+ }
17007
17047
  sendSystemInfoResponse(response) {
17008
17048
  this.sendMessage({
17009
17049
  ...response,
@@ -17128,6 +17168,14 @@ var GatewayClient = class extends EventEmitter {
17128
17168
  this.logger.warn("Received auth_expired from gateway");
17129
17169
  this.emit("auth_expired");
17130
17170
  break;
17171
+ case "tool_call_completion_ack": {
17172
+ const { type: _type, ...ack } = message;
17173
+ const key = completionAckKey(ack.operationId, ack.toolCallId);
17174
+ const pending = this.pendingCompletionAcks.get(key);
17175
+ this.pendingCompletionAcks.delete(key);
17176
+ pending?.resolve(ack);
17177
+ break;
17178
+ }
17131
17179
  case "device_metrics_ack": {
17132
17180
  const pending = this.pendingMetricAcks.get(message.batchId);
17133
17181
  this.pendingMetricAcks.delete(message.batchId);
@@ -17266,6 +17314,8 @@ var GatewayClient = class extends EventEmitter {
17266
17314
  rejectPendingMetricAcks() {
17267
17315
  for (const pending of this.pendingMetricAcks.values()) pending.reject(/* @__PURE__ */ new Error("Gateway connection closed"));
17268
17316
  this.pendingMetricAcks.clear();
17317
+ for (const pending of this.pendingCompletionAcks.values()) pending.reject(/* @__PURE__ */ new Error("Gateway connection closed"));
17318
+ this.pendingCompletionAcks.clear();
17269
17319
  }
17270
17320
  closeWebSocket() {
17271
17321
  this.tunnelHost?.closeAll("DEVICE_DISCONNECTED");
@@ -17302,6 +17352,102 @@ var GatewayClient = class extends EventEmitter {
17302
17352
  }
17303
17353
  };
17304
17354
 
17355
+ //#endregion
17356
+ //#region ../../packages/device-gateway-client/src/completionWatch.ts
17357
+ const LOCAL_SYSTEM_IDENTIFIER = "lobe-local-system";
17358
+ /** Longest a device keeps a finished result it could not deliver. */
17359
+ const DEFAULT_COMPLETION_MAX_AGE_MS = 7200 * 1e3;
17360
+ const INITIAL_RETRY_DELAY_MS = 5e3;
17361
+ const MAX_RETRY_DELAY_MS = 6e4;
17362
+ /**
17363
+ * The shell a `runCommand` reply left running, when the server asked for a
17364
+ * late result. Mirrors the server's park predicate: a background spawn or a
17365
+ * foreground call that outlived its wait window, never a command that already
17366
+ * has an exit code or failed to start.
17367
+ */
17368
+ const resolveWatchableShell = (request, result) => {
17369
+ if (!request.completion?.toolCallId || !request.operationId) return void 0;
17370
+ if (request.toolCall.type === "mcp") return void 0;
17371
+ if (request.toolCall.identifier !== LOCAL_SYSTEM_IDENTIFIER) return void 0;
17372
+ if (request.toolCall.apiName !== "runCommand") return void 0;
17373
+ if (result.success === false) return void 0;
17374
+ const state = result.state;
17375
+ if (!state || typeof state !== "object") return void 0;
17376
+ if (typeof state.commandId !== "string" || !state.commandId) return void 0;
17377
+ if (state.error) return void 0;
17378
+ if (state.exitCode !== void 0 && state.exitCode !== null) return void 0;
17379
+ if (state.isBackground === true || state.running === true) return state.commandId;
17380
+ };
17381
+ /** Mark a reply so the server knows a late result will follow and may park. */
17382
+ const withCompletionWatch = (result) => ({
17383
+ ...result,
17384
+ state: {
17385
+ ...result.state,
17386
+ completionWatch: true
17387
+ }
17388
+ });
17389
+ const defaultSleep = (ms, wake) => Promise.race([new Promise((resolve) => setTimeout(resolve, ms)), wake]);
17390
+ /**
17391
+ * Watch a command the device left running and deliver its final result.
17392
+ *
17393
+ * Observation is local (the device waits on its own process), so the wait costs
17394
+ * the server nothing. Delivery retries with backoff — sooner when the gateway
17395
+ * reconnects — until the gateway answers `delivered` or `rejected`, or the
17396
+ * result is older than `maxAgeMs` (the server has timed the call out by then).
17397
+ */
17398
+ const watchToolCallCompletion = async ({ getReporter, logger, maxAgeMs = DEFAULT_COMPLETION_MAX_AGE_MS, observe, operationId, sleep = defaultSleep, toolCallId }) => {
17399
+ const startedAt = Date.now();
17400
+ let result;
17401
+ for (;;) {
17402
+ let observed;
17403
+ try {
17404
+ observed = await observe();
17405
+ } catch (error) {
17406
+ const message = error instanceof Error ? error.message : String(error);
17407
+ observed = {
17408
+ done: true,
17409
+ result: {
17410
+ content: `Failed to observe the command: ${message}`,
17411
+ error: message,
17412
+ success: false
17413
+ }
17414
+ };
17415
+ }
17416
+ if (observed.done) {
17417
+ result = observed.result;
17418
+ break;
17419
+ }
17420
+ if (Date.now() - startedAt > maxAgeMs) return "expired";
17421
+ }
17422
+ let delay = INITIAL_RETRY_DELAY_MS;
17423
+ for (;;) {
17424
+ const reporter = getReporter();
17425
+ if (reporter) try {
17426
+ const ack = await reporter.reportToolCallCompletion({
17427
+ operationId,
17428
+ result,
17429
+ toolCallId
17430
+ });
17431
+ if (ack.status !== "retry") {
17432
+ logger?.info(`Completion for ${toolCallId} ${ack.status}`, ack.reason ?? "");
17433
+ return ack.status;
17434
+ }
17435
+ logger?.warn(`Completion for ${toolCallId} not taken yet`, ack.reason ?? "");
17436
+ } catch (error) {
17437
+ logger?.warn(`Completion for ${toolCallId} not sent`, error instanceof Error ? error.message : String(error));
17438
+ }
17439
+ if (Date.now() - startedAt > maxAgeMs) return "expired";
17440
+ let onConnected;
17441
+ const wake = new Promise((resolve) => {
17442
+ onConnected = resolve;
17443
+ reporter?.on("connected", resolve);
17444
+ });
17445
+ await sleep(delay, wake);
17446
+ if (onConnected) reporter?.off("connected", onConnected);
17447
+ delay = Math.min(delay * 2, MAX_RETRY_DELAY_MS);
17448
+ }
17449
+ };
17450
+
17305
17451
  //#endregion
17306
17452
  //#region ../../packages/const/src/agentDocument.ts
17307
17453
  const MARKDOWN_MIME_TYPES = ["text/markdown", "text/x-markdown"];
@@ -17884,6 +18030,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
17884
18030
  canvas: "blocked",
17885
18031
  changelog: "open",
17886
18032
  channel: "blocked",
18033
+ contact: "blocked",
17887
18034
  chunk: rw("knowledge:read", "knowledge:write"),
17888
18035
  comfyui: rw("model:read", "model:write"),
17889
18036
  composio: "blocked",
@@ -28120,6 +28267,107 @@ function attachCriterionCommands(parent) {
28120
28267
  return criterion;
28121
28268
  }
28122
28269
 
28270
+ //#endregion
28271
+ //#region src/commands/acceptance/delete.ts
28272
+ /** Mirrors the server's `removeBatch` / `purgePreview` input caps. */
28273
+ const REMOVE_BATCH_LIMIT = 200;
28274
+ const PURGE_PREVIEW_LIMIT = 20;
28275
+ const formatBytes$1 = (bytes) => {
28276
+ if (bytes < 1024) return `${bytes} B`;
28277
+ const units = [
28278
+ "KB",
28279
+ "MB",
28280
+ "GB",
28281
+ "TB"
28282
+ ];
28283
+ let value = bytes / 1024;
28284
+ let unit = 0;
28285
+ while (value >= 1024 && unit < units.length - 1) {
28286
+ value /= 1024;
28287
+ unit += 1;
28288
+ }
28289
+ return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unit]}`;
28290
+ };
28291
+ const describePurge = (preview) => `${preview.rounds} round(s), ${preview.fileCount} evidence file(s) (screenshots ${preview.files.images} · recordings ${preview.files.videos} · other ${preview.files.other}), ${formatBytes$1(preview.bytes)} freed`;
28292
+ /**
28293
+ * The purge preview only answers up to its cap and fails on an id the caller
28294
+ * cannot read; a missing preview never blocks the delete, the prompt just
28295
+ * says less.
28296
+ */
28297
+ async function loadPurgePreview(client, ids) {
28298
+ if (ids.length > PURGE_PREVIEW_LIMIT) return;
28299
+ try {
28300
+ return await client.acceptance.purgePreview.query({ ids });
28301
+ } catch {
28302
+ return;
28303
+ }
28304
+ }
28305
+ async function confirmDelete(client, ids, purge) {
28306
+ const target = ids.length === 1 ? `acceptance ${import_picocolors.default.bold(ids[0])}` : `${ids.length} acceptances`;
28307
+ if (!purge) return confirm(`Delete ${target}? Its verification rounds are kept as standalone reports (use --purge to remove them too).`);
28308
+ const preview = await loadPurgePreview(client, ids);
28309
+ return confirm(`Permanently delete ${target} with every round, report and evidence file?${preview ? ` This removes ${describePurge(preview)}.` : ""} This cannot be undone.`);
28310
+ }
28311
+ async function removeAll(client, ids, purge) {
28312
+ if (ids.length === 1) {
28313
+ await client.acceptance.remove.mutate({
28314
+ id: ids[0],
28315
+ purge
28316
+ });
28317
+ return {
28318
+ deleted: 1,
28319
+ failedIds: []
28320
+ };
28321
+ }
28322
+ let deleted = 0;
28323
+ const failedIds = [];
28324
+ for (let i = 0; i < ids.length; i += REMOVE_BATCH_LIMIT) {
28325
+ const result = await client.acceptance.removeBatch.mutate({
28326
+ ids: ids.slice(i, i + REMOVE_BATCH_LIMIT),
28327
+ purge
28328
+ });
28329
+ deleted += result.deleted;
28330
+ failedIds.push(...result.failedIds);
28331
+ }
28332
+ return {
28333
+ deleted,
28334
+ failedIds
28335
+ };
28336
+ }
28337
+ /**
28338
+ * `lh acceptance delete` — remove the acceptance aggregate (the review shell
28339
+ * around its rounds). By default the rounds detach and stay reachable as
28340
+ * standalone reports; `--purge` also deletes the rounds and the evidence files
28341
+ * only they referenced, matching the Web delete dialog.
28342
+ */
28343
+ function attachDeleteCommand(acceptance, resolveAcceptanceId) {
28344
+ acceptance.command("delete <idOrSubject...>").alias("rm").description("Delete acceptances (uuid or type:id); rounds are kept as standalone reports unless --purge").option("--purge", "Also permanently delete every round, report and evidence file").option("-y, --yes", "Skip the confirmation prompt").option("--json [fields]", "Output JSON").action(async (refs, options) => {
28345
+ const ids = [];
28346
+ for (const ref of refs) ids.push(await resolveAcceptanceId(ref));
28347
+ const uniqueIds = [...new Set(ids)];
28348
+ const purge = Boolean(options.purge);
28349
+ const client = await getTrpcClient();
28350
+ if (!options.yes && !await confirmDelete(client, uniqueIds, purge)) {
28351
+ console.log("Aborted.");
28352
+ return;
28353
+ }
28354
+ const result = await removeAll(client, uniqueIds, purge);
28355
+ if (result.failedIds.length > 0) process.exitCode = 1;
28356
+ if (options.json !== void 0) {
28357
+ outputJson({
28358
+ ...result,
28359
+ purged: purge
28360
+ }, typeof options.json === "string" ? options.json : void 0);
28361
+ return;
28362
+ }
28363
+ if (result.deleted > 0) {
28364
+ const what = uniqueIds.length === 1 ? `acceptance ${uniqueIds[0]}` : `${result.deleted} acceptance(s)`;
28365
+ console.log(`${import_picocolors.default.green("✓")} Deleted ${what}${purge ? " with rounds and evidence" : " — rounds kept as standalone reports"}`);
28366
+ }
28367
+ for (const id of result.failedIds) log$13.error(`Could not delete ${id}`);
28368
+ });
28369
+ }
28370
+
28123
28371
  //#endregion
28124
28372
  //#region src/commands/acceptance/language.ts
28125
28373
  const HAN = {
@@ -39405,6 +39653,7 @@ function registerAcceptanceCommands(parent, options) {
39405
39653
  }
39406
39654
  });
39407
39655
  if (options?.deprecated) return;
39656
+ attachDeleteCommand(acceptance, resolveAcceptanceId);
39408
39657
  attachAcceptanceRunCommands(acceptance);
39409
39658
  attachPlanCommands(acceptance);
39410
39659
  attachCriterionCommands(acceptance);
@@ -552434,6 +552683,7 @@ var ComputerRuntime = class {
552434
552683
  isBackground: args.background || false,
552435
552684
  output: r.output,
552436
552685
  outputFiles,
552686
+ running: r.running,
552437
552687
  sandboxed: r.sandboxed,
552438
552688
  stderr: r.stderr,
552439
552689
  stdout: r.stdout,
@@ -553552,6 +553802,52 @@ async function executeToolCall(apiName, argsStr, timeout, auth) {
553552
553802
  }
553553
553803
  }
553554
553804
 
553805
+ //#endregion
553806
+ //#region src/commands/connect/completionWatch.ts
553807
+ /** The longest single local wait for a watched command (the shell's own cap). */
553808
+ const COMPLETION_OBSERVATION_TIMEOUT_MS = 6e5;
553809
+ /**
553810
+ * The reply for a finished tool call. When the server asked for a late result
553811
+ * and the command is still running, the reply says this device keeps watching
553812
+ * (`state.completionWatch`) and the final `getCommandOutput` answer is reported
553813
+ * once the process exits — the server parks the run instead of the model
553814
+ * polling.
553815
+ *
553816
+ * The watch runs outside `maintenance.run` on purpose: a command can run for
553817
+ * hours, and a CLI restart must not wait on it. A restart loses the watch; the
553818
+ * server's own deadline then closes the call.
553819
+ */
553820
+ const prepareCompletionReply = (request, result, { getReporter, getToolAuth, logger }) => {
553821
+ const shellId = resolveWatchableShell(request, result);
553822
+ if (!shellId || !request.operationId || !request.completion) return result;
553823
+ watchToolCallCompletion({
553824
+ getReporter,
553825
+ logger,
553826
+ observe: async () => {
553827
+ const output = await executeToolCall("getCommandOutput", JSON.stringify({
553828
+ shell_id: shellId,
553829
+ timeout: COMPLETION_OBSERVATION_TIMEOUT_MS
553830
+ }), COMPLETION_OBSERVATION_TIMEOUT_MS, getToolAuth());
553831
+ const running = output.state?.running === true;
553832
+ const final = {
553833
+ content: output.content,
553834
+ success: output.success
553835
+ };
553836
+ if (output.error !== void 0) final.error = output.error;
553837
+ if (output.state !== void 0) final.state = output.state;
553838
+ return {
553839
+ done: output.success === false || !running,
553840
+ result: final
553841
+ };
553842
+ },
553843
+ operationId: request.operationId,
553844
+ toolCallId: request.completion.toolCallId
553845
+ }).catch((err) => {
553846
+ logger.error(`Completion watch for ${shellId} failed: ${err instanceof Error ? err.message : err}`);
553847
+ });
553848
+ return withCompletionWatch(result);
553849
+ };
553850
+
553555
553851
  //#endregion
553556
553852
  //#region src/commands/connect/handlers.ts
553557
553853
  /**
@@ -553623,15 +553919,24 @@ function bindGatewayClientHandlers(client, ctx, connectionWorkspaceId) {
553623
553919
  const executionTimeMs = Math.round(performance.now() - startedAt);
553624
553920
  if (isDaemonChild) appendLog(`[RESULT] ${result.success ? "OK" : "FAIL"} ${executionTimeMs}ms${operationId ? ` op=${operationId}` : ""} (${requestId})`);
553625
553921
  else log$13.toolResult(requestId, result.success, result.content, operationId);
553922
+ const reply = prepareCompletionReply(request, {
553923
+ content: result.content,
553924
+ error: result.error,
553925
+ executionTimeMs,
553926
+ state: result.state,
553927
+ success: result.success
553928
+ }, {
553929
+ getReporter: () => client,
553930
+ getToolAuth,
553931
+ logger: {
553932
+ error: (...args) => error(args.join(" ")),
553933
+ info: (...args) => isDaemonChild ? appendLog(`[COMPLETION] ${args.join(" ")}`) : info(args.join(" ")),
553934
+ warn: (...args) => error(args.join(" "))
553935
+ }
553936
+ });
553626
553937
  client.sendToolCallResponse({
553627
553938
  requestId,
553628
- result: {
553629
- content: result.content,
553630
- error: result.error,
553631
- executionTimeMs,
553632
- state: result.state,
553633
- success: result.success
553634
- }
553939
+ result: reply
553635
553940
  });
553636
553941
  });
553637
553942
  client.on("rpc_request", async (request) => {
package/man/man1/lh.1 CHANGED
@@ -1,6 +1,6 @@
1
1
  .\" Code generated by `npm run man:generate`; DO NOT EDIT.
2
2
  .\" Manual command details come from the Commander command tree.
3
- .TH LH 1 "" "@lobehub/cli 0.0.91" "User Commands"
3
+ .TH LH 1 "" "@lobehub/cli 0.0.93" "User Commands"
4
4
  .SH NAME
5
5
  lh \- LobeHub CLI \- manage and connect to LobeHub services
6
6
  .SH SYNOPSIS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/cli",
3
- "version": "0.0.91",
3
+ "version": "0.0.93",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/lobehub/lobehub",
@@ -83,5 +83,5 @@
83
83
  "access": "public",
84
84
  "registry": "https://registry.npmjs.org"
85
85
  },
86
- "gitHead": "a8b501bf87ba0e48281e36c23bf8b247eecef5fe"
86
+ "gitHead": "e0724291bf29d429da630f0505b53b40a5e11b89"
87
87
  }