@yinaoxiong/paseo-plugin 0.18.1-personal.1 → 0.18.2-personal.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/build-info.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "upstreamVersion": "0.18.1",
4
- "revision": 1,
5
- "version": "0.18.1-personal.1",
6
- "appVersion": "0.18.1",
7
- "androidVersionCode": 18001001,
8
- "iosBuildNumber": "18001999",
9
- "sourceSha": "f6e15fa35cd10a2085be6332162da785f8f61afe",
10
- "lockSha256": "310805506bd816ba907a25e64b8a2de43ff0d07fbab91b56cafcb2c4f29c3a12",
3
+ "upstreamVersion": "0.18.2",
4
+ "revision": 2,
5
+ "version": "0.18.2-personal.2",
6
+ "appVersion": "0.18.2",
7
+ "androidVersionCode": 18002002,
8
+ "iosBuildNumber": "18002002",
9
+ "sourceSha": "96a72e49e867e89043fe70bbac4afe6921d1f477",
10
+ "lockSha256": "8bcf4983ccfa57cfa444ec7ecbad301c8fef0fcc2c495df5176758cf1e2f2faa",
11
11
  "nodeVersion": "v24.21.0",
12
12
  "npmVersion": "11.19.0",
13
13
  "platform": "linux",
14
14
  "arch": "x64",
15
15
  "signature": "unsigned",
16
16
  "packageName": "@yinaoxiong/paseo-plugin",
17
- "desktopVersion": "0.18.1+personal.1"
17
+ "desktopVersion": "0.18.2+personal.2"
18
18
  }
@@ -194,6 +194,8 @@ interface PluginClientContextAliases {
194
194
  }
195
195
  export interface PluginClientContext extends PluginCommandCapabilities, PluginClientContextAliases {
196
196
  readonly i18n: import("./translations.js").PluginI18n;
197
+ /** In-memory plugin state retained across transport replacement for an unchanged bundle. */
198
+ readonly transientState?: Map<string, unknown>;
197
199
  /** Play a base64-encoded audio file on this client; resolves when playback ends. */
198
200
  playAudio(source: {
199
201
  base64: string;
@@ -235,9 +237,12 @@ export type PluginWorkspacePanelContribution<Text extends PluginText = string> =
235
237
  /** @deprecated Register with `addAgentPanel`. */
236
238
  context: "agent";
237
239
  Component: ComponentType<PluginAgentPanelProps>;
240
+ onClose?(agentId: string): boolean | Promise<boolean>;
238
241
  });
239
242
  export interface PluginAgentPanelContribution<Text extends PluginText = string> extends PluginWorkspacePanelBase<Text> {
240
243
  Component: ComponentType<PluginAgentPanelProps>;
244
+ /** Called when the user closes this panel. Return false to keep the tab. */
245
+ onClose?(agentId: string): boolean | Promise<boolean>;
241
246
  }
242
247
  export interface PluginSettingsScreenContribution<Text extends PluginText = string> {
243
248
  id: string;
@@ -343,6 +348,8 @@ export type PluginClientSlashCommandContribution<Text extends PluginText = strin
343
348
  }): void | Promise<void>;
344
349
  }) | (PluginClientSlashCommandBase<Text> & {
345
350
  context: "agent";
351
+ /** Restrict the command to agents with this provider id. */
352
+ provider?: string;
346
353
  onSubmit(context: PluginAgentCommandContext & {
347
354
  args: string;
348
355
  }): void | Promise<void>;
@@ -55,6 +55,8 @@ export interface PluginWorkspaceSnapshot {
55
55
  readonly additions: number;
56
56
  readonly deletions: number;
57
57
  } | null;
58
+ /** Structured data stored on the workspace. */
59
+ readonly metadata: Readonly<Record<string, JsonValue>>;
58
60
  }
59
61
  export interface PluginAgentSnapshot {
60
62
  readonly ref: AgentRef;
@@ -3,8 +3,9 @@ import { spawnProcess, terminateProcess } from "../process.js";
3
3
  import { Readable, Writable } from "node:stream";
4
4
  import { ClientSideConnection, CLIENT_METHODS, PROTOCOL_VERSION, ndJsonStream, } from "@agentclientprotocol/sdk";
5
5
  import { z } from "zod";
6
+ import { AcpFormElicitation } from "./elicitation.js";
6
7
  import { standardToolCallDetail } from "./tool-call-detail.js";
7
- import { PROVIDER_PROTOCOL_VERSION, ProviderEventSchema, ProviderInputSchema, negotiateProviderCapabilities, requireProviderCapabilities, } from "../provider.js";
8
+ import { PROVIDER_PROTOCOL_VERSION, ProviderEventSchema, negotiateProviderCapabilities, parseProviderInput, requireProviderCapabilities, } from "../provider.js";
8
9
  const ADAPTER_CAPABILITIES = [
9
10
  "prompt.message",
10
11
  "prompt.command",
@@ -123,7 +124,7 @@ export async function createAcpProviderConnection(options, request) {
123
124
  async send(input) {
124
125
  if (closed)
125
126
  throw new Error("ACP provider connection is closed");
126
- input = ProviderInputSchema.parse(input);
127
+ input = parseProviderInput(input);
127
128
  validateAdmission(input, { capabilities, sessions });
128
129
  if (input.type === "request.cancel") {
129
130
  cancellable.get(input.requestId)?.abort(new Error("Paseo canceled the request"));
@@ -230,10 +231,10 @@ async function dispatch(input, state, signal) {
230
231
  }
231
232
  case "session.interrupt": {
232
233
  const session = requireSession(state, input.sessionId);
233
- const retired = await session.runtime.interrupt();
234
+ const result = await session.runtime.interrupt();
234
235
  state.emit({ type: "request.completed", requestId: input.requestId });
235
- if (retired)
236
- retireSession(state, input.sessionId);
236
+ if (result.retired)
237
+ retireSession(state, input.sessionId, result.error);
237
238
  return;
238
239
  }
239
240
  case "session.permission":
@@ -348,9 +349,9 @@ async function listSessions(input, state, signal) {
348
349
  },
349
350
  });
350
351
  }
351
- function retireSession(state, sessionId) {
352
+ function retireSession(state, sessionId, error) {
352
353
  if (state.sessions.delete(sessionId)) {
353
- state.emit({ type: "session.closed", sessionId });
354
+ state.emit({ type: "session.closed", sessionId, ...(error ? { error } : {}) });
354
355
  }
355
356
  }
356
357
  async function openSession(input, state) {
@@ -366,7 +367,7 @@ async function openSession(input, state) {
366
367
  env: input.config.env,
367
368
  wrap: input.config.wrap,
368
369
  emit: state.emit,
369
- onRetired: () => retireSession(state, input.sessionId),
370
+ onRetired: (error) => retireSession(state, input.sessionId, error),
370
371
  });
371
372
  try {
372
373
  const capabilities = await runtime.open(input, state.capabilities, state.isClosed);
@@ -398,6 +399,8 @@ function requireSession(state, sessionId) {
398
399
  return session;
399
400
  }
400
401
  const DEFAULT_DEFERRED_SETTLE_DELAY_MS = 500;
402
+ const DEFAULT_INTERRUPT_GRACE_MS = 10000;
403
+ const DEFAULT_INTERRUPT_KILL_GRACE_MS = 2000;
401
404
  const SESSION_SCAN_LIMIT = 500;
402
405
  // COMPAT(acpAutoAccept): added in v0.17.4, remove after 2027-05-23. The generic ACP adapter saves
403
406
  // its Auto Accept toggle as this setting on agents that later moved to a bundled ACP provider.
@@ -449,7 +452,7 @@ class AcpRuntime {
449
452
  try {
450
453
  const initialize = withTimeout(runtime.call(runtime.connection.initialize({
451
454
  protocolVersion: PROTOCOL_VERSION,
452
- clientCapabilities: {},
455
+ clientCapabilities: { elicitation: { form: {} } },
453
456
  clientInfo: options.clientInfo ?? DEFAULT_CLIENT_INFO,
454
457
  })), options.options.acpOptions?.startupTimeoutMs ?? 10000, `ACP provider ${options.options.id} did not initialize`);
455
458
  const initialized = spawnFailure
@@ -481,6 +484,7 @@ class AcpRuntime {
481
484
  this.vendorToolCalls = new Map();
482
485
  this.pendingCompactions = new Set();
483
486
  this.permissions = new Map();
487
+ this.elicitationSequence = 0;
484
488
  this.configOptions = [];
485
489
  this.modes = null;
486
490
  this.commandWaiter = null;
@@ -502,8 +506,9 @@ class AcpRuntime {
502
506
  this.lastPartialWireAt = 0;
503
507
  this.closing = false;
504
508
  this.closePromise = null;
505
- this.deferredRetirement = null;
506
- this.deferredFinalized = false;
509
+ this.activeInterrupt = null;
510
+ this.activeRetirement = null;
511
+ this.retirementFinalized = false;
507
512
  this.processFailed = false;
508
513
  this.processFailureMessage = null;
509
514
  this.configTransaction = false;
@@ -522,6 +527,7 @@ class AcpRuntime {
522
527
  this.transformers = options.options.transformers ?? [];
523
528
  const client = {
524
529
  requestPermission: (request) => this.requestPermission(request),
530
+ createElicitation: (request) => this.createElicitation(request),
525
531
  sessionUpdate: (notification) => {
526
532
  const wireSeq = this.sessionUpdateWireSeqs.shift() ?? ++this.incomingWireSeq;
527
533
  return this.enqueueNotification(() => this.sessionUpdate(notification, wireSeq));
@@ -689,7 +695,7 @@ class AcpRuntime {
689
695
  await this.applyNativeConfigChange({ target: "model", value: model });
690
696
  }
691
697
  async prompt(input) {
692
- if (this.closing || this.processFailed || this.deferredRetirement) {
698
+ if (this.closing || this.processFailed || this.activeRetirement) {
693
699
  throw new Error("ACP session is closed");
694
700
  }
695
701
  if (input.prompt.delivery === "steer") {
@@ -704,15 +710,15 @@ class AcpRuntime {
704
710
  this.finishDeferredTurn(active, { type: "complete", terminalizeTools: false });
705
711
  }
706
712
  else {
707
- const retired = await this.interrupt();
708
- if (retired) {
713
+ const result = await this.interrupt();
714
+ if (result.retired) {
709
715
  // Notify caller that the session closed before failing the replacement prompt.
710
- this.options.onRetired?.();
711
- throw new Error("ACP session retired after stopping deferred background work");
716
+ this.options.onRetired?.(result.error);
717
+ throw new Error(result.error?.message ?? "ACP session retired after stopping unresponsive turn");
712
718
  }
713
719
  }
714
720
  await active.settled;
715
- if (this.closing || this.processFailed || this.deferredRetirement) {
721
+ if (this.closing || this.processFailed || this.activeRetirement) {
716
722
  throw new Error("ACP session is closed");
717
723
  }
718
724
  }
@@ -749,6 +755,7 @@ class AcpRuntime {
749
755
  turnId,
750
756
  settled: Promise.resolve(),
751
757
  cancelling: false,
758
+ retired: false,
752
759
  wirePromptsInFlight: 1,
753
760
  wirePromptLane: Promise.resolve(),
754
761
  lastPromptResponseWireSeq: null,
@@ -761,6 +768,8 @@ class AcpRuntime {
761
768
  const settled = this.call(this.connection.prompt({ sessionId: this.nativeSessionId, prompt })).then(async (response) => {
762
769
  await this.drainNotifications();
763
770
  activePrompt.wirePromptsInFlight -= 1;
771
+ if (activePrompt.retired)
772
+ return undefined;
764
773
  if (response.usage) {
765
774
  this.lastUsage = {
766
775
  ...this.lastUsage,
@@ -785,6 +794,8 @@ class AcpRuntime {
785
794
  }, async (error) => {
786
795
  await this.drainNotifications();
787
796
  activePrompt.wirePromptsInFlight -= 1;
797
+ if (activePrompt.retired)
798
+ return undefined;
788
799
  this.finishPromptTurn(turnId, "failed", { message: describeError(error) });
789
800
  return undefined;
790
801
  });
@@ -796,44 +807,93 @@ class AcpRuntime {
796
807
  });
797
808
  }
798
809
  async interrupt() {
799
- if (this.deferredRetirement)
800
- return this.deferredRetirement;
810
+ if (this.activeRetirement)
811
+ return this.activeRetirement;
812
+ if (this.activeInterrupt)
813
+ return this.activeInterrupt;
801
814
  const active = this.activePrompt;
802
815
  const deferredTurnId = active?.deferred ? active.turnId : null;
803
816
  if (active && deferredTurnId) {
804
817
  const retirement = this.retireDeferredTurn(active, deferredTurnId).catch((error) => {
805
- if (this.deferredRetirement === retirement)
806
- this.deferredRetirement = null;
818
+ if (this.activeRetirement === retirement)
819
+ this.activeRetirement = null;
807
820
  throw error;
808
821
  });
809
- this.deferredRetirement = retirement;
822
+ this.activeRetirement = retirement;
810
823
  return retirement;
811
824
  }
812
- if (active)
813
- active.cancelling = true;
814
- try {
825
+ if (!active) {
815
826
  await this.call(this.connection.cancel({ sessionId: this.nativeSessionId }));
827
+ return { retired: false };
816
828
  }
817
- finally {
818
- // An agent may wait for its outstanding permission replies before ending the prompt.
819
- if (active) {
820
- this.finishTurnPermissions(active.turnId);
821
- }
829
+ const interrupting = this.interruptActivePrompt(active).finally(() => {
830
+ if (this.activeInterrupt === interrupting)
831
+ this.activeInterrupt = null;
832
+ });
833
+ this.activeInterrupt = interrupting;
834
+ return interrupting;
835
+ }
836
+ async interruptActivePrompt(active) {
837
+ active.cancelling = true;
838
+ // An agent may wait for its outstanding permission replies before ending the prompt.
839
+ this.finishTurnPermissions(active.turnId);
840
+ let cancelWriteSettled = false;
841
+ const cancelWrite = this.call(this.connection.cancel({ sessionId: this.nativeSessionId }))
842
+ .catch(() => undefined)
843
+ .finally(() => {
844
+ cancelWriteSettled = true;
845
+ });
846
+ const graceMs = this.options.options.acpOptions?.interruptGraceMs ?? DEFAULT_INTERRUPT_GRACE_MS;
847
+ if (await settlesWithin(active.settled, graceMs)) {
848
+ await settlesWithin(cancelWrite, 50);
849
+ return { retired: false };
822
850
  }
823
- return false;
851
+ if (this.closing || this.activePrompt !== active) {
852
+ return { retired: false };
853
+ }
854
+ const retirement = this.retireUnresponsivePrompt(active, !cancelWriteSettled).catch((error) => {
855
+ if (this.activeRetirement === retirement)
856
+ this.activeRetirement = null;
857
+ throw error;
858
+ });
859
+ this.activeRetirement = retirement;
860
+ return retirement;
824
861
  }
825
- finalizeDeferredTurn(deferredTurnId, emitRetired) {
826
- if (this.deferredFinalized)
862
+ finalizeRetiredTurn(turnId, emitRetired, error) {
863
+ if (this.retirementFinalized)
827
864
  return;
828
- this.deferredFinalized = true;
829
- this.finishPromptTurn(deferredTurnId, "canceled", undefined, {
865
+ this.retirementFinalized = true;
866
+ if (this.activePrompt?.turnId === turnId)
867
+ this.activePrompt = null;
868
+ this.finishPromptTurn(turnId, "canceled", undefined, {
830
869
  suppressTrailingToolEcho: true,
831
870
  });
832
871
  if (emitRetired)
833
- this.options.onRetired?.();
872
+ this.options.onRetired?.(error);
873
+ }
874
+ async retireUnresponsivePrompt(active, forceClose) {
875
+ active.retired = true;
876
+ for (const id of this.liveOpenToolIds)
877
+ this.canceledToolCallIds.add(id);
878
+ const killGraceMs = this.options.options.acpOptions?.interruptKillGraceMs ?? DEFAULT_INTERRUPT_KILL_GRACE_MS;
879
+ const error = this.agentCapabilities.loadSession
880
+ ? undefined
881
+ : {
882
+ message: `Stopped unresponsive ${this.options.options.id} process after cancel timed out. This provider does not support session resume; start a new agent or reload to continue.`,
883
+ };
884
+ try {
885
+ await this.close({ force: forceClose, timeoutMs: killGraceMs, killGraceMs });
886
+ }
887
+ catch (closeError) {
888
+ void this.whenConnectorClosed()?.then(() => this.finalizeRetiredTurn(active.turnId, true, error), () => undefined);
889
+ throw closeError;
890
+ }
891
+ this.finalizeRetiredTurn(active.turnId, false, error);
892
+ return { retired: true, ...(error ? { error } : {}) };
834
893
  }
835
894
  async retireDeferredTurn(active, deferredTurnId) {
836
895
  active.cancelling = true;
896
+ active.retired = true;
837
897
  // Record open tools owned by Stop before writing session/cancel so any failure
838
898
  // update arriving during cancel preserves their canceled state.
839
899
  for (const id of this.liveOpenToolIds)
@@ -859,11 +919,11 @@ class AcpRuntime {
859
919
  await this.close({ force: cancelTimedOut, timeoutMs: 1000 });
860
920
  }
861
921
  catch (error) {
862
- void this.whenConnectorClosed()?.then(() => this.finalizeDeferredTurn(deferredTurnId, true), () => undefined);
922
+ void this.whenConnectorClosed()?.then(() => this.finalizeRetiredTurn(deferredTurnId, true), () => undefined);
863
923
  throw error;
864
924
  }
865
- this.finalizeDeferredTurn(deferredTurnId, false);
866
- return true;
925
+ this.finalizeRetiredTurn(deferredTurnId, false);
926
+ return { retired: true };
867
927
  }
868
928
  /** Follows `nextCursor` until `limit` sessions, the last page, or the scan cap. */
869
929
  async listSessions({ cwd, limit }) {
@@ -888,6 +948,10 @@ class AcpRuntime {
888
948
  const active = this.activePrompt;
889
949
  if (active?.cancelling && pending.turnId === active.turnId)
890
950
  return;
951
+ if (pending.kind === "elicitation") {
952
+ this.resolveElicitation(permissionId, pending, pending.form.respond(response));
953
+ return;
954
+ }
891
955
  const selected = selectPermissionOption(pending.request.options, response);
892
956
  if (response.selectedActionId !== undefined && !selected) {
893
957
  throw new Error(`ACP permission action '${response.selectedActionId}' does not exist or does not match '${response.behavior}' behavior`);
@@ -900,7 +964,12 @@ class AcpRuntime {
900
964
  }
901
965
  finishTurnPermissions(turnId) {
902
966
  for (const [permissionId, pending] of this.permissions) {
903
- if (pending.turnId === turnId) {
967
+ if (pending.turnId !== turnId)
968
+ continue;
969
+ if (pending.kind === "elicitation") {
970
+ this.resolveElicitation(permissionId, pending, { action: "cancel" });
971
+ }
972
+ else {
904
973
  this.resolvePermission(permissionId, pending, { outcome: { outcome: "cancelled" } });
905
974
  }
906
975
  }
@@ -916,6 +985,17 @@ class AcpRuntime {
916
985
  if (this.activePrompt?.deferred)
917
986
  this.scheduleDeferredSettle();
918
987
  }
988
+ resolveElicitation(permissionId, pending, response) {
989
+ this.permissions.delete(permissionId);
990
+ pending.resolve(response);
991
+ this.emit({
992
+ type: "session.permission_resolved",
993
+ sessionId: this.options.boundarySessionId,
994
+ permissionId,
995
+ });
996
+ if (this.activePrompt?.deferred)
997
+ this.scheduleDeferredSettle();
998
+ }
919
999
  async configure(changes) {
920
1000
  const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
921
1001
  if (autoAcceptMode &&
@@ -975,6 +1055,10 @@ class AcpRuntime {
975
1055
  this.emitConfigSnapshot(committedConfig);
976
1056
  }
977
1057
  async closeSession() {
1058
+ if (this.cancelPendingPermissions()) {
1059
+ // Let the ACP SDK flush the cancel response on the wire before closing the session/stream.
1060
+ await new Promise((resolve) => setImmediate(resolve));
1061
+ }
978
1062
  if (this.nativeSessionId) {
979
1063
  await withTimeout(this.call(this.connection.closeSession({ sessionId: this.nativeSessionId })), 1000, `ACP session ${this.nativeSessionId} did not close`).catch(() => undefined);
980
1064
  }
@@ -1001,8 +1085,9 @@ class AcpRuntime {
1001
1085
  if (child.exitCode !== null || child.signalCode !== null)
1002
1086
  return;
1003
1087
  const closed = new Promise((resolve) => child.once("close", () => resolve()));
1088
+ const killGraceMs = options?.killGraceMs ?? 1000;
1004
1089
  await terminateProcess(child, "SIGTERM");
1005
- if (await settlesWithin(closed, 1000))
1090
+ if (await settlesWithin(closed, killGraceMs))
1006
1091
  return;
1007
1092
  await terminateProcess(child);
1008
1093
  if (!(await settlesWithin(closed, 1000))) {
@@ -1214,7 +1299,12 @@ class AcpRuntime {
1214
1299
  const permissionId = `permission:${request.toolCall.toolCallId}`;
1215
1300
  const { presentation } = this.presentToolCall(request.toolCall);
1216
1301
  return new Promise((resolve) => {
1217
- this.permissions.set(permissionId, { request, resolve, turnId: this.activePrompt?.turnId });
1302
+ this.permissions.set(permissionId, {
1303
+ kind: "tool",
1304
+ request,
1305
+ resolve,
1306
+ turnId: this.activePrompt?.turnId,
1307
+ });
1218
1308
  if (this.activePrompt?.deferred)
1219
1309
  this.scheduleDeferredSettle();
1220
1310
  this.emit({
@@ -1236,6 +1326,49 @@ class AcpRuntime {
1236
1326
  });
1237
1327
  });
1238
1328
  }
1329
+ async createElicitation(request) {
1330
+ await this.notificationLane;
1331
+ if (this.closing || this.processFailed || this.activePrompt?.cancelling) {
1332
+ return { action: "cancel" };
1333
+ }
1334
+ // Forms are only answerable during an active turn of this session; declining out-of-turn
1335
+ // or mismatched requests avoids hanging session open, discovery, or idle connections.
1336
+ if (!this.activePrompt ||
1337
+ request.mode !== "form" ||
1338
+ !("sessionId" in request) ||
1339
+ typeof request.sessionId !== "string" ||
1340
+ !this.nativeSessionId ||
1341
+ request.sessionId !== this.nativeSessionId) {
1342
+ return { action: "decline" };
1343
+ }
1344
+ const toolCallId = "toolCallId" in request && typeof request.toolCallId === "string"
1345
+ ? request.toolCallId
1346
+ : undefined;
1347
+ const toolName = toolCallId ? this.toolCalls.get(toolCallId)?.presentation.name : undefined;
1348
+ const form = AcpFormElicitation.parse(request, { toolName });
1349
+ if (!form) {
1350
+ return { action: "decline" };
1351
+ }
1352
+ const permissionId = toolCallId
1353
+ ? `elicitation:${toolCallId}:${++this.elicitationSequence}`
1354
+ : `elicitation:${++this.elicitationSequence}`;
1355
+ const turnId = this.activePrompt.turnId;
1356
+ return new Promise((resolve) => {
1357
+ this.permissions.set(permissionId, {
1358
+ kind: "elicitation",
1359
+ form,
1360
+ resolve,
1361
+ turnId,
1362
+ });
1363
+ if (this.activePrompt?.deferred)
1364
+ this.scheduleDeferredSettle();
1365
+ this.emit({
1366
+ type: "session.permission",
1367
+ sessionId: this.options.boundarySessionId,
1368
+ request: { id: permissionId, ...form.request },
1369
+ });
1370
+ });
1371
+ }
1239
1372
  observeWireMessage(message) {
1240
1373
  if (typeof message !== "object" || message === null)
1241
1374
  return;
@@ -1603,11 +1736,22 @@ class AcpRuntime {
1603
1736
  error: { message },
1604
1737
  });
1605
1738
  }
1606
- settlePendingWork(failureMessage) {
1739
+ cancelPendingPermissions() {
1740
+ if (this.permissions.size === 0)
1741
+ return false;
1607
1742
  for (const permission of this.permissions.values()) {
1608
- permission.resolve({ outcome: { outcome: "cancelled" } });
1743
+ if (permission.kind === "elicitation") {
1744
+ permission.resolve({ action: "cancel" });
1745
+ }
1746
+ else {
1747
+ permission.resolve({ outcome: { outcome: "cancelled" } });
1748
+ }
1609
1749
  }
1610
1750
  this.permissions.clear();
1751
+ return true;
1752
+ }
1753
+ settlePendingWork(failureMessage) {
1754
+ this.cancelPendingPermissions();
1611
1755
  if (this.activePrompt?.deferred) {
1612
1756
  this.finishDeferredTurn(this.activePrompt, failureMessage ? { type: "fail", error: { message: failureMessage } } : { type: "cancel" });
1613
1757
  }
@@ -1693,7 +1837,7 @@ class AcpRuntime {
1693
1837
  active.replyState = "idle";
1694
1838
  const response = await this.call(this.connection.prompt({ sessionId: this.nativeSessionId, prompt }));
1695
1839
  await this.drainNotifications();
1696
- if (this.closing || this.deferredRetirement || active.deferred !== deferred)
1840
+ if (this.closing || this.activeRetirement || active.deferred !== deferred)
1697
1841
  return;
1698
1842
  if (response.usage) {
1699
1843
  this.lastUsage = {
@@ -1719,7 +1863,7 @@ class AcpRuntime {
1719
1863
  }
1720
1864
  catch (error) {
1721
1865
  await this.drainNotifications();
1722
- if (this.closing || this.deferredRetirement || active.deferred !== deferred)
1866
+ if (this.closing || this.activeRetirement || active.deferred !== deferred)
1723
1867
  return;
1724
1868
  if (this.processFailed) {
1725
1869
  this.finishDeferredTurn(active, {
@@ -1756,7 +1900,7 @@ class AcpRuntime {
1756
1900
  active.deferred = { timer: null, resolve };
1757
1901
  this.scheduleDeferredSettle();
1758
1902
  });
1759
- if (this.closing || this.deferredRetirement)
1903
+ if (this.closing || this.activeRetirement)
1760
1904
  return;
1761
1905
  if (outcome.type === "fail") {
1762
1906
  this.finishPromptTurn(active.turnId, "failed", outcome.error);
@@ -1812,8 +1956,12 @@ class AcpRuntime {
1812
1956
  if (!active.deferred && wasOpenQualifying && !isOpen && this.toolKeepsTurnOpen(snapshot)) {
1813
1957
  active.crossedEndTurn = true;
1814
1958
  }
1815
- if (isOpenQualifying)
1959
+ if (isOpenQualifying ||
1960
+ (!isOpen &&
1961
+ this.toolKeepsTurnOpen(snapshot) &&
1962
+ active.replyState === "settled_with_open_tools")) {
1816
1963
  active.replyState = "idle";
1964
+ }
1817
1965
  if (active.deferred)
1818
1966
  this.scheduleDeferredSettle();
1819
1967
  }
@@ -2244,9 +2392,18 @@ function withTimeout(promise, timeoutMs, message) {
2244
2392
  });
2245
2393
  }
2246
2394
  async function settlesWithin(promise, timeoutMs) {
2247
- return Promise.race([
2248
- promise.then(() => true),
2249
- new Promise((resolve) => setTimeout(() => resolve(false), timeoutMs)),
2250
- ]);
2395
+ let timer = null;
2396
+ try {
2397
+ return await Promise.race([
2398
+ promise.then(() => true),
2399
+ new Promise((resolve) => {
2400
+ timer = setTimeout(() => resolve(false), timeoutMs);
2401
+ }),
2402
+ ]);
2403
+ }
2404
+ finally {
2405
+ if (timer !== null)
2406
+ clearTimeout(timer);
2407
+ }
2251
2408
  }
2252
2409
  //# sourceMappingURL=connection.js.map
@@ -0,0 +1,17 @@
1
+ import type { CreateElicitationRequest, CreateElicitationResponse } from "@agentclientprotocol/sdk";
2
+ import type { ProviderPermissionRequest, ProviderPermissionResponse } from "../provider.js";
3
+ /**
4
+ * Translates an ACP 1.x form elicitation request (`elicitation/create`, mode `"form"`)
5
+ * into a Paseo `kind: "question"` permission request and maps the user's answer back to
6
+ * an ACP `CreateElicitationResponse` without throwing.
7
+ */
8
+ export declare class AcpFormElicitation {
9
+ readonly request: Omit<ProviderPermissionRequest, "id">;
10
+ private readonly fields;
11
+ private constructor();
12
+ static parse(request: CreateElicitationRequest, options?: {
13
+ toolName?: string;
14
+ }): AcpFormElicitation | null;
15
+ respond(response: ProviderPermissionResponse): CreateElicitationResponse;
16
+ }
17
+ //# sourceMappingURL=elicitation.d.ts.map