weacpx 0.4.0-beta.0 → 0.4.0-beta.1

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/cli.js CHANGED
@@ -16774,7 +16774,7 @@ async function handleSessionRemove(context, chatKey, alias) {
16774
16774
  return { text: lines.join(`
16775
16775
  `) };
16776
16776
  }
16777
- async function promptWithSession(context, session, chatKey, text, reply, replyContextToken, accountId, media) {
16777
+ async function promptWithSession(context, session, chatKey, text, reply, replyContextToken, accountId, media, abortSignal) {
16778
16778
  const effectiveReplyMode = session.replyMode ?? context.config?.channel.replyMode ?? "verbose";
16779
16779
  const transportReply = effectiveReplyMode !== "final" ? reply : undefined;
16780
16780
  if (context.orchestration) {
@@ -16797,7 +16797,7 @@ async function promptWithSession(context, session, chatKey, text, reply, replyCo
16797
16797
  const { promptText, taskIds, groupIds, claimHumanReply } = await preparePromptWithFallback(context, session, chatKey, text, replyContextToken, accountId);
16798
16798
  try {
16799
16799
  const replyContext = transportReply && context.quota ? { chatKey, quota: context.quota } : undefined;
16800
- const result = await context.interaction.promptTransportSession(session, promptText, transportReply, replyContext, media);
16800
+ const result = await context.interaction.promptTransportSession(session, promptText, transportReply, replyContext, media, abortSignal);
16801
16801
  if (claimHumanReply) {
16802
16802
  try {
16803
16803
  await context.orchestration?.claimActiveHumanReply?.(claimHumanReply);
@@ -16817,17 +16817,17 @@ async function promptWithSession(context, session, chatKey, text, reply, replyCo
16817
16817
  throw error2;
16818
16818
  }
16819
16819
  }
16820
- async function handlePrompt(context, chatKey, text, reply, replyContextToken, accountId, media) {
16820
+ async function handlePrompt(context, chatKey, text, reply, replyContextToken, accountId, media, abortSignal) {
16821
16821
  const session = await context.sessions.getCurrentSession(chatKey);
16822
16822
  if (!session) {
16823
16823
  return { text: NO_CURRENT_SESSION_TEXT };
16824
16824
  }
16825
16825
  try {
16826
- return await promptWithSession(context, session, chatKey, text, reply, replyContextToken, accountId, media);
16826
+ return await promptWithSession(context, session, chatKey, text, reply, replyContextToken, accountId, media, abortSignal);
16827
16827
  } catch (error2) {
16828
16828
  const recovered = await context.recovery.tryRecoverMissingSession(session, error2);
16829
16829
  if (recovered) {
16830
- return await promptWithSession(context, recovered, chatKey, text, reply, replyContextToken, accountId, media);
16830
+ return await promptWithSession(context, recovered, chatKey, text, reply, replyContextToken, accountId, media, abortSignal);
16831
16831
  }
16832
16832
  return context.recovery.renderTransportError(session, error2);
16833
16833
  }
@@ -18148,7 +18148,7 @@ class CommandRouter {
18148
18148
  this.quota = quota;
18149
18149
  this.logger = logger2 ?? createNoopAppLogger();
18150
18150
  }
18151
- async handle(chatKey, input, reply, replyContextToken, accountId, media, metadata) {
18151
+ async handle(chatKey, input, reply, replyContextToken, accountId, media, metadata, abortSignal) {
18152
18152
  const startedAt = Date.now();
18153
18153
  const command = parseCommand(input);
18154
18154
  await this.logger.debug("command.parsed", "parsed inbound command", {
@@ -18262,7 +18262,7 @@ class CommandRouter {
18262
18262
  case "task.cancel":
18263
18263
  return await handleTaskCancel(this.createHandlerContext(), chatKey, command.taskId);
18264
18264
  case "prompt":
18265
- return await handlePrompt(this.createSessionHandlerContext(), chatKey, command.text, reply, replyContextToken, accountId, media);
18265
+ return await handlePrompt(this.createSessionHandlerContext(), chatKey, command.text, reply, replyContextToken, accountId, media, abortSignal);
18266
18266
  }
18267
18267
  });
18268
18268
  }
@@ -18314,7 +18314,7 @@ class CommandRouter {
18314
18314
  return {
18315
18315
  setModeTransportSession: (session, modeId) => this.setModeTransportSession(session, modeId),
18316
18316
  cancelTransportSession: (session) => this.cancelTransportSession(session),
18317
- promptTransportSession: (session, text, reply, replyContext, media) => this.promptTransportSession(session, text, reply, replyContext, media)
18317
+ promptTransportSession: (session, text, reply, replyContext, media, abortSignal) => this.promptTransportSession(session, text, reply, replyContext, media, abortSignal)
18318
18318
  };
18319
18319
  }
18320
18320
  createSessionRenderRecoveryOps() {
@@ -18477,9 +18477,50 @@ class CommandRouter {
18477
18477
  async checkTransportSession(session) {
18478
18478
  return await this.measureTransportCall("has_session", session, () => this.transport.hasSession(session));
18479
18479
  }
18480
- async promptTransportSession(session, text, reply, replyContext, media) {
18480
+ async promptTransportSession(session, text, reply, replyContext, media, abortSignal) {
18481
18481
  session.mcpCoordinatorSession ??= session.transportSession;
18482
- return await this.measureTransportCall("prompt", session, () => this.transport.prompt(session, text, reply, replyContext, media ? { media } : undefined));
18482
+ let done = false;
18483
+ let cancelOnAbort;
18484
+ const fireCancel = () => {
18485
+ if (done)
18486
+ return;
18487
+ try {
18488
+ const result = this.transport.cancel(session);
18489
+ if (result && typeof result.catch === "function") {
18490
+ result.catch(async (error2) => {
18491
+ await this.logger.error("transport.cancel_on_abort_failed", "transport cancel triggered by abort signal failed", {
18492
+ agent: session.agent,
18493
+ workspace: session.workspace,
18494
+ alias: session.alias,
18495
+ message: error2 instanceof Error ? error2.message : String(error2)
18496
+ });
18497
+ });
18498
+ }
18499
+ } catch (error2) {
18500
+ this.logger.error("transport.cancel_on_abort_failed", "transport cancel triggered by abort signal threw synchronously", {
18501
+ agent: session.agent,
18502
+ workspace: session.workspace,
18503
+ alias: session.alias,
18504
+ message: error2 instanceof Error ? error2.message : String(error2)
18505
+ });
18506
+ }
18507
+ };
18508
+ if (abortSignal) {
18509
+ if (abortSignal.aborted) {
18510
+ done = true;
18511
+ throw new DOMException("Aborted before prompt started", "AbortError");
18512
+ }
18513
+ cancelOnAbort = fireCancel;
18514
+ abortSignal.addEventListener("abort", cancelOnAbort, { once: true });
18515
+ }
18516
+ try {
18517
+ return await this.measureTransportCall("prompt", session, () => this.transport.prompt(session, text, reply, replyContext, media ? { media } : undefined));
18518
+ } finally {
18519
+ done = true;
18520
+ if (cancelOnAbort && abortSignal) {
18521
+ abortSignal.removeEventListener("abort", cancelOnAbort);
18522
+ }
18523
+ }
18483
18524
  }
18484
18525
  async setModeTransportSession(session, modeId) {
18485
18526
  return await this.measureTransportCall("set_mode", session, () => this.transport.setMode(session, modeId));
@@ -18624,7 +18665,7 @@ class ConsoleAgent {
18624
18665
  mimeType: m.mimeType,
18625
18666
  ...m.fileName ? { fileName: m.fileName } : {}
18626
18667
  })) : undefined;
18627
- return await this.router.handle(request.conversationId, request.text, request.reply, request.replyContextToken, request.accountId, promptMedia, request.metadata);
18668
+ return await this.router.handle(request.conversationId, request.text, request.reply, request.replyContextToken, request.accountId, promptMedia, request.metadata, request.abortSignal);
18628
18669
  }
18629
18670
  isKnownCommand(text) {
18630
18671
  return isKnownWeacpxCommandText(text);
@@ -29571,7 +29612,7 @@ function finalize(ctx, schema) {
29571
29612
  result.$schema = "http://json-schema.org/draft-07/schema#";
29572
29613
  } else if (ctx.target === "draft-04") {
29573
29614
  result.$schema = "http://json-schema.org/draft-04/schema#";
29574
- } else if (ctx.target === "openapi-3.0") {} else {}
29615
+ } else if (ctx.target === "openapi-3.0") {}
29575
29616
  if (ctx.external?.uri) {
29576
29617
  const id = ctx.external.registry.get(schema)?.id;
29577
29618
  if (!id)
@@ -29793,7 +29834,7 @@ var literalProcessor = (schema, ctx, json, _params) => {
29793
29834
  if (val === undefined) {
29794
29835
  if (ctx.unrepresentable === "throw") {
29795
29836
  throw new Error("Literal `undefined` cannot be represented in JSON Schema");
29796
- } else {}
29837
+ }
29797
29838
  } else if (typeof val === "bigint") {
29798
29839
  if (ctx.unrepresentable === "throw") {
29799
29840
  throw new Error("BigInt literals cannot be represented in JSON Schema");
@@ -34,6 +34,14 @@ export interface ChatRequest {
34
34
  replyContextToken?: string;
35
35
  /** Channel-provided facts for command authorization and routing policy. */
36
36
  metadata?: ChatRequestMetadata;
37
+ /**
38
+ * Signals that the channel has received an abort/stop request for this turn.
39
+ * Agents that can interrupt long-running work (e.g. cancel an in-flight acpx
40
+ * prompt) should observe this and bail out early. Optional; agents that don't
41
+ * support cancellation may ignore it — the channel will still suppress any
42
+ * output produced after abort.
43
+ */
44
+ abortSignal?: AbortSignal;
37
45
  }
38
46
  export interface ChatRequestMetadata {
39
47
  channel?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weacpx",
3
- "version": "0.4.0-beta.0",
3
+ "version": "0.4.0-beta.1",
4
4
  "description": "使用微信 ClawBot 随时随地通过 `acpx` 控制 Claude Code、Codex 等 Agents。",
5
5
  "keywords": [
6
6
  "acpx",