@getpaseo/plugin 0.16.1 → 0.17.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.
|
@@ -135,9 +135,11 @@ async function dispatch(input, state) {
|
|
|
135
135
|
case "session.open":
|
|
136
136
|
await openSession(input, state);
|
|
137
137
|
return;
|
|
138
|
-
case "session.prompt":
|
|
139
|
-
|
|
138
|
+
case "session.prompt": {
|
|
139
|
+
const session = requireSession(state, input.sessionId);
|
|
140
|
+
await mutateSession(session, () => session.runtime.prompt(input));
|
|
140
141
|
return;
|
|
142
|
+
}
|
|
141
143
|
case "session.interrupt":
|
|
142
144
|
await requireSession(state, input.sessionId).runtime.interrupt();
|
|
143
145
|
state.emit({ type: "request.completed", requestId: input.requestId });
|
|
@@ -174,6 +176,7 @@ async function discover(input, state) {
|
|
|
174
176
|
options: state.options,
|
|
175
177
|
launch: state.launch,
|
|
176
178
|
boundarySessionId: "catalog",
|
|
179
|
+
cwd: input.cwd,
|
|
177
180
|
env: {},
|
|
178
181
|
emit: state.emit,
|
|
179
182
|
});
|
|
@@ -224,6 +227,7 @@ async function openSession(input, state) {
|
|
|
224
227
|
options: state.options,
|
|
225
228
|
launch: state.launch,
|
|
226
229
|
boundarySessionId: input.sessionId,
|
|
230
|
+
cwd: input.config.cwd,
|
|
227
231
|
env: input.config.env,
|
|
228
232
|
emit: state.emit,
|
|
229
233
|
});
|
|
@@ -238,6 +242,7 @@ async function openSession(input, state) {
|
|
|
238
242
|
capabilities,
|
|
239
243
|
mutationLane: Promise.resolve(),
|
|
240
244
|
});
|
|
245
|
+
state.emit({ type: "session.ready", requestId: input.requestId, sessionId: input.sessionId });
|
|
241
246
|
}
|
|
242
247
|
catch (error) {
|
|
243
248
|
await runtime.close();
|
|
@@ -270,6 +275,7 @@ class AcpRuntime {
|
|
|
270
275
|
env: process.env,
|
|
271
276
|
};
|
|
272
277
|
child = spawnProcess(launch.command, launch.args, {
|
|
278
|
+
cwd: options.cwd,
|
|
273
279
|
env: { ...launch.env, ...options.env },
|
|
274
280
|
stdio: "pipe",
|
|
275
281
|
});
|
|
@@ -315,6 +321,7 @@ class AcpRuntime {
|
|
|
315
321
|
this.configOptions = [];
|
|
316
322
|
this.modes = null;
|
|
317
323
|
this.commandWaiter = null;
|
|
324
|
+
this.receivedInitialCommands = false;
|
|
318
325
|
this.messageSequence = 0;
|
|
319
326
|
/**
|
|
320
327
|
* Fallback ids for streamed chunks that carry no `messageId`, one per
|
|
@@ -324,17 +331,17 @@ class AcpRuntime {
|
|
|
324
331
|
*/
|
|
325
332
|
this.fallbackChunkIds = new Map();
|
|
326
333
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* open request's history contract.
|
|
334
|
+
* Replay updates count as history until the session reports ready.
|
|
335
|
+
* Once ready, suppress late replay rows until the first prompt.
|
|
330
336
|
*/
|
|
331
337
|
this.replayWindow = null;
|
|
338
|
+
this.lastLoadUpdateAt = 0;
|
|
332
339
|
this.closing = false;
|
|
333
340
|
this.processFailed = false;
|
|
334
341
|
this.configTransaction = false;
|
|
335
342
|
this.stagedTransformerConfig = null;
|
|
336
343
|
this.notificationLane = Promise.resolve();
|
|
337
|
-
this.
|
|
344
|
+
this.autoAccept = false;
|
|
338
345
|
this.activePrompt = null;
|
|
339
346
|
this.lastUsage = {};
|
|
340
347
|
this.child = child;
|
|
@@ -373,7 +380,7 @@ class AcpRuntime {
|
|
|
373
380
|
}
|
|
374
381
|
async open(input, connectionCapabilities) {
|
|
375
382
|
const mcpServers = toAcpMcpServers(input.config);
|
|
376
|
-
|
|
383
|
+
let nativeSessionId = readNativeSessionId(input.persistence);
|
|
377
384
|
const metadata = {
|
|
378
385
|
_paseo: {
|
|
379
386
|
systemPrompt: input.config.systemPrompt,
|
|
@@ -382,24 +389,30 @@ class AcpRuntime {
|
|
|
382
389
|
persist: input.config.persist,
|
|
383
390
|
},
|
|
384
391
|
};
|
|
392
|
+
for (const transformer of this.transformers) {
|
|
393
|
+
const prepared = transformer.sessionOpen?.({
|
|
394
|
+
persistence: input.persistence,
|
|
395
|
+
systemPrompt: input.config.systemPrompt,
|
|
396
|
+
agentMetadata: jsonValue(this.agentCapabilities._meta ?? null),
|
|
397
|
+
});
|
|
398
|
+
nativeSessionId ?? (nativeSessionId = prepared?.sessionId ?? null);
|
|
399
|
+
Object.assign(metadata, prepared?.metadata);
|
|
400
|
+
}
|
|
385
401
|
let response;
|
|
386
402
|
if (nativeSessionId) {
|
|
387
403
|
// ACP agents replay the loaded session's updates before session/load resolves,
|
|
388
404
|
// so the native id must be registered first for them to pass the session filter.
|
|
389
405
|
this.nativeSessionId = nativeSessionId;
|
|
390
406
|
this.replayWindow = input.history === "replay" ? "replay" : "skip";
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
finally {
|
|
407
|
+
response = await this.call(this.connection.loadSession({
|
|
408
|
+
sessionId: nativeSessionId,
|
|
409
|
+
cwd: input.config.cwd,
|
|
410
|
+
mcpServers,
|
|
411
|
+
_meta: metadata,
|
|
412
|
+
}));
|
|
413
|
+
await this.drainNotifications();
|
|
414
|
+
if (!this.options.options.acpOptions?.loadReplayQuietPeriodMs)
|
|
401
415
|
this.replayWindow = null;
|
|
402
|
-
}
|
|
403
416
|
}
|
|
404
417
|
else {
|
|
405
418
|
const newSession = await this.call(this.connection.newSession({
|
|
@@ -410,10 +423,11 @@ class AcpRuntime {
|
|
|
410
423
|
response = newSession;
|
|
411
424
|
this.nativeSessionId = newSession.sessionId;
|
|
412
425
|
}
|
|
413
|
-
this.modes = response.modes;
|
|
426
|
+
this.modes = response.modes ?? null;
|
|
414
427
|
this.configOptions = response.configOptions ?? [];
|
|
415
428
|
await this.applyInitialConfig(input.config);
|
|
416
429
|
const sessionCapabilities = connectionCapabilities.filter((capability) => capability !== "session.configure" ||
|
|
430
|
+
this.options.options.acpOptions?.autoAcceptMode !== undefined ||
|
|
417
431
|
this.modes !== null ||
|
|
418
432
|
this.configOptions.length > 0 ||
|
|
419
433
|
this.transformers.some((transformer) => transformer.configure !== undefined));
|
|
@@ -431,7 +445,11 @@ class AcpRuntime {
|
|
|
431
445
|
if (this.options.options.acpOptions?.waitForInitialCommands) {
|
|
432
446
|
await this.waitForInitialCommands();
|
|
433
447
|
}
|
|
434
|
-
|
|
448
|
+
const quietPeriod = this.options.options.acpOptions?.loadReplayQuietPeriodMs;
|
|
449
|
+
if (this.replayWindow && quietPeriod && quietPeriod > 0) {
|
|
450
|
+
await this.waitForLoadReplay(quietPeriod);
|
|
451
|
+
this.replayWindow = "skip";
|
|
452
|
+
}
|
|
435
453
|
return sessionCapabilities;
|
|
436
454
|
}
|
|
437
455
|
async discover(cwd) {
|
|
@@ -440,22 +458,26 @@ class AcpRuntime {
|
|
|
440
458
|
}
|
|
441
459
|
const response = await this.call(this.connection.newSession({ cwd: cwd ?? process.cwd(), mcpServers: [] }));
|
|
442
460
|
this.nativeSessionId = response.sessionId;
|
|
443
|
-
this.modes = response.modes;
|
|
461
|
+
this.modes = response.modes ?? null;
|
|
444
462
|
this.configOptions = response.configOptions ?? [];
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
463
|
+
const catalog = toProviderCatalog(this.modes, this.configOptions);
|
|
464
|
+
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
|
465
|
+
if (!autoAcceptMode)
|
|
466
|
+
return catalog;
|
|
467
|
+
return {
|
|
468
|
+
...catalog,
|
|
469
|
+
modes: [...catalog.modes, { ...autoAcceptMode.mode, isUnattended: true }],
|
|
470
|
+
defaultMode: autoAcceptMode.default ? autoAcceptMode.mode.id : catalog.defaultMode,
|
|
471
|
+
};
|
|
451
472
|
}
|
|
452
|
-
async
|
|
473
|
+
async prompt(input) {
|
|
453
474
|
const active = this.activePrompt;
|
|
454
475
|
if (active) {
|
|
455
476
|
await this.interrupt();
|
|
456
477
|
await active.settled;
|
|
457
478
|
}
|
|
458
479
|
const prompt = toAcpPrompt(input.prompt);
|
|
480
|
+
this.replayWindow = null;
|
|
459
481
|
const turnId = `acp:${input.prompt.clientMessageId}`;
|
|
460
482
|
this.fallbackChunkIds.clear();
|
|
461
483
|
this.emit({
|
|
@@ -504,6 +526,7 @@ class AcpRuntime {
|
|
|
504
526
|
const state = response.stopReason === "cancelled" ? "canceled" : "completed";
|
|
505
527
|
this.fallbackChunkIds.clear();
|
|
506
528
|
this.terminalizeTransientItems(state);
|
|
529
|
+
this.finishTurnPermissions(turnId);
|
|
507
530
|
this.emit({
|
|
508
531
|
type: "session.turn",
|
|
509
532
|
sessionId: this.options.boundarySessionId,
|
|
@@ -515,6 +538,7 @@ class AcpRuntime {
|
|
|
515
538
|
await this.drainNotifications();
|
|
516
539
|
this.fallbackChunkIds.clear();
|
|
517
540
|
this.terminalizeTransientItems("failed");
|
|
541
|
+
this.finishTurnPermissions(turnId);
|
|
518
542
|
this.emit({
|
|
519
543
|
type: "session.turn",
|
|
520
544
|
sessionId: this.options.boundarySessionId,
|
|
@@ -524,14 +548,24 @@ class AcpRuntime {
|
|
|
524
548
|
});
|
|
525
549
|
return undefined;
|
|
526
550
|
});
|
|
527
|
-
this.activePrompt = { turnId, settled };
|
|
551
|
+
this.activePrompt = { turnId, settled, cancelling: false };
|
|
528
552
|
void settled.finally(() => {
|
|
529
553
|
if (this.activePrompt?.turnId === turnId)
|
|
530
554
|
this.activePrompt = null;
|
|
531
555
|
});
|
|
532
556
|
}
|
|
533
|
-
interrupt() {
|
|
534
|
-
|
|
557
|
+
async interrupt() {
|
|
558
|
+
const active = this.activePrompt;
|
|
559
|
+
if (active)
|
|
560
|
+
active.cancelling = true;
|
|
561
|
+
try {
|
|
562
|
+
await this.call(this.connection.cancel({ sessionId: this.nativeSessionId }));
|
|
563
|
+
}
|
|
564
|
+
finally {
|
|
565
|
+
// An agent may wait for its outstanding permission replies before ending the prompt.
|
|
566
|
+
if (active)
|
|
567
|
+
this.finishTurnPermissions(active.turnId);
|
|
568
|
+
}
|
|
535
569
|
}
|
|
536
570
|
listSessions(cwd) {
|
|
537
571
|
return this.call(this.connection.listSessions({ cwd }));
|
|
@@ -543,17 +577,30 @@ class AcpRuntime {
|
|
|
543
577
|
respondToPermission(permissionId, response) {
|
|
544
578
|
const pending = this.permissions.get(permissionId);
|
|
545
579
|
if (!pending)
|
|
546
|
-
|
|
580
|
+
return;
|
|
581
|
+
const active = this.activePrompt;
|
|
582
|
+
if (active?.cancelling && pending.turnId === active.turnId)
|
|
583
|
+
return;
|
|
547
584
|
const selected = selectPermissionOption(pending.request.options, response);
|
|
548
585
|
if (response.selectedActionId !== undefined && !selected) {
|
|
549
586
|
throw new Error(`ACP permission action '${response.selectedActionId}' does not exist or does not match '${response.behavior}' behavior`);
|
|
550
587
|
}
|
|
551
|
-
this.
|
|
552
|
-
pending.resolve({
|
|
588
|
+
this.resolvePermission(permissionId, pending, {
|
|
553
589
|
outcome: selected
|
|
554
590
|
? { outcome: "selected", optionId: selected.optionId }
|
|
555
591
|
: { outcome: "cancelled" },
|
|
556
592
|
});
|
|
593
|
+
}
|
|
594
|
+
finishTurnPermissions(turnId) {
|
|
595
|
+
for (const [permissionId, pending] of this.permissions) {
|
|
596
|
+
if (pending.turnId === turnId) {
|
|
597
|
+
this.resolvePermission(permissionId, pending, { outcome: { outcome: "cancelled" } });
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
resolvePermission(permissionId, pending, response) {
|
|
602
|
+
this.permissions.delete(permissionId);
|
|
603
|
+
pending.resolve(response);
|
|
557
604
|
this.emit({
|
|
558
605
|
type: "session.permission_resolved",
|
|
559
606
|
sessionId: this.options.boundarySessionId,
|
|
@@ -561,6 +608,13 @@ class AcpRuntime {
|
|
|
561
608
|
});
|
|
562
609
|
}
|
|
563
610
|
async configure(changes) {
|
|
611
|
+
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
|
612
|
+
if (autoAcceptMode &&
|
|
613
|
+
changes.mode !== undefined &&
|
|
614
|
+
(changes.mode === autoAcceptMode.mode.id) !== this.autoAccept &&
|
|
615
|
+
(this.activePrompt || this.permissions.size > 0)) {
|
|
616
|
+
throw new Error(`Finish or stop the current turn before switching to or from ${autoAcceptMode.mode.label}.`);
|
|
617
|
+
}
|
|
564
618
|
const requested = [];
|
|
565
619
|
if (changes.model !== undefined)
|
|
566
620
|
requested.push({ target: "model", value: changes.model });
|
|
@@ -573,6 +627,7 @@ class AcpRuntime {
|
|
|
573
627
|
requested.push({ target: "setting", id, value });
|
|
574
628
|
}
|
|
575
629
|
const ordered = this.inAgentOrder(requested);
|
|
630
|
+
const previousAutoAccept = this.autoAccept;
|
|
576
631
|
const previousModes = this.modes ? structuredClone(this.modes) : null;
|
|
577
632
|
const previousOptions = structuredClone(this.configOptions);
|
|
578
633
|
this.configTransaction = true;
|
|
@@ -598,6 +653,7 @@ class AcpRuntime {
|
|
|
598
653
|
await this.close();
|
|
599
654
|
throw failure;
|
|
600
655
|
}
|
|
656
|
+
this.autoAccept = previousAutoAccept;
|
|
601
657
|
this.modes = previousModes;
|
|
602
658
|
this.configOptions = previousOptions;
|
|
603
659
|
this.stagedTransformerConfig = null;
|
|
@@ -639,8 +695,10 @@ class AcpRuntime {
|
|
|
639
695
|
const requested = [];
|
|
640
696
|
if (config.model)
|
|
641
697
|
requested.push({ target: "model", value: config.model });
|
|
642
|
-
|
|
643
|
-
|
|
698
|
+
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
|
699
|
+
const mode = config.mode ?? (autoAcceptMode?.default ? autoAcceptMode.mode.id : undefined);
|
|
700
|
+
if (mode)
|
|
701
|
+
requested.push({ target: "mode", value: mode });
|
|
644
702
|
if (config.thinkingOption) {
|
|
645
703
|
requested.push({ target: "thinking", value: config.thinkingOption });
|
|
646
704
|
}
|
|
@@ -668,20 +726,41 @@ class AcpRuntime {
|
|
|
668
726
|
if (change.target === "thinking") {
|
|
669
727
|
return this.configOptions.find((option) => option.category === "thought_level")?.id;
|
|
670
728
|
}
|
|
671
|
-
return this.configOptions
|
|
729
|
+
return modeOption(this.configOptions)?.id;
|
|
672
730
|
}
|
|
673
731
|
async applyConfigChange(change) {
|
|
732
|
+
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
|
733
|
+
if (change.target === "mode" &&
|
|
734
|
+
autoAcceptMode &&
|
|
735
|
+
(this.autoAccept || change.value === autoAcceptMode.mode.id)) {
|
|
736
|
+
const enableAutoAccept = change.value === autoAcceptMode.mode.id;
|
|
737
|
+
const nativeMode = enableAutoAccept ? autoAcceptMode.nativeMode : change.value;
|
|
738
|
+
this.autoAccept = false;
|
|
739
|
+
if (nativeMode !== this.nativeModeId()) {
|
|
740
|
+
await this.applyNativeConfigChange({ target: "mode", value: nativeMode });
|
|
741
|
+
}
|
|
742
|
+
if (nativeMode !== this.nativeModeId()) {
|
|
743
|
+
throw new Error(`ACP agent did not switch to mode '${nativeMode}'`);
|
|
744
|
+
}
|
|
745
|
+
this.autoAccept = enableAutoAccept;
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
674
748
|
const access = this.configAccess();
|
|
675
749
|
for (const transformer of this.transformers) {
|
|
676
750
|
if ((await transformer.configure?.(change, {
|
|
677
751
|
sessionId: this.options.boundarySessionId,
|
|
678
752
|
config: access,
|
|
753
|
+
catalog: () => toProviderCatalog(this.modes, this.configOptions),
|
|
754
|
+
apply: (nativeChange) => this.applyNativeConfigChange(nativeChange),
|
|
679
755
|
})) === "handled") {
|
|
680
756
|
return;
|
|
681
757
|
}
|
|
682
758
|
}
|
|
683
|
-
|
|
684
|
-
|
|
759
|
+
await this.applyNativeConfigChange(change);
|
|
760
|
+
}
|
|
761
|
+
async applyNativeConfigChange(change) {
|
|
762
|
+
if (change.target === "mode" && this.modes && !modeOption(this.configOptions)) {
|
|
763
|
+
if (!change.value) {
|
|
685
764
|
throw new Error("ACP session does not expose mode configuration");
|
|
686
765
|
}
|
|
687
766
|
await this.call(this.connection.setSessionMode({
|
|
@@ -728,7 +807,20 @@ class AcpRuntime {
|
|
|
728
807
|
return;
|
|
729
808
|
this.emitConfigSnapshot(toProviderConfigState(this.modes, this.configOptions));
|
|
730
809
|
}
|
|
810
|
+
nativeModeId() {
|
|
811
|
+
return selectedValue(modeOption(this.configOptions)) ?? this.modes?.currentModeId;
|
|
812
|
+
}
|
|
731
813
|
emitConfigSnapshot(config) {
|
|
814
|
+
const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode;
|
|
815
|
+
if (autoAcceptMode) {
|
|
816
|
+
if (this.nativeModeId() !== autoAcceptMode.nativeMode)
|
|
817
|
+
this.autoAccept = false;
|
|
818
|
+
config = {
|
|
819
|
+
...config,
|
|
820
|
+
mode: this.autoAccept ? autoAcceptMode.mode.id : config.mode,
|
|
821
|
+
modes: [...config.modes, { ...autoAcceptMode.mode, isUnattended: true }],
|
|
822
|
+
};
|
|
823
|
+
}
|
|
732
824
|
this.emit({
|
|
733
825
|
type: "session.config",
|
|
734
826
|
sessionId: this.options.boundarySessionId,
|
|
@@ -736,7 +828,9 @@ class AcpRuntime {
|
|
|
736
828
|
});
|
|
737
829
|
}
|
|
738
830
|
async restoreConfig(modes, options) {
|
|
739
|
-
if (
|
|
831
|
+
if (!modeOption(options) &&
|
|
832
|
+
modes?.currentModeId &&
|
|
833
|
+
this.modes?.currentModeId !== modes.currentModeId) {
|
|
740
834
|
await this.call(this.connection.setSessionMode({
|
|
741
835
|
sessionId: this.nativeSessionId,
|
|
742
836
|
modeId: modes.currentModeId,
|
|
@@ -754,10 +848,24 @@ class AcpRuntime {
|
|
|
754
848
|
}));
|
|
755
849
|
}
|
|
756
850
|
}
|
|
757
|
-
requestPermission(request) {
|
|
851
|
+
async requestPermission(request) {
|
|
852
|
+
await this.notificationLane;
|
|
853
|
+
if (this.closing || this.processFailed || this.activePrompt?.cancelling) {
|
|
854
|
+
return { outcome: { outcome: "cancelled" } };
|
|
855
|
+
}
|
|
856
|
+
if (this.autoAccept &&
|
|
857
|
+
request.sessionId === this.nativeSessionId &&
|
|
858
|
+
this.nativeModeId() === this.options.options.acpOptions?.autoAcceptMode?.nativeMode) {
|
|
859
|
+
const allowOptions = request.options.filter((option) => option.kind.startsWith("allow"));
|
|
860
|
+
const allowOnce = allowOptions.find((option) => option.kind === "allow_once");
|
|
861
|
+
if (allowOnce &&
|
|
862
|
+
new Set(allowOptions.map((option) => option.kind)).size === allowOptions.length) {
|
|
863
|
+
return { outcome: { outcome: "selected", optionId: allowOnce.optionId } };
|
|
864
|
+
}
|
|
865
|
+
}
|
|
758
866
|
const permissionId = `permission:${request.toolCall.toolCallId}`;
|
|
759
867
|
return new Promise((resolve) => {
|
|
760
|
-
this.permissions.set(permissionId, { request, resolve });
|
|
868
|
+
this.permissions.set(permissionId, { request, resolve, turnId: this.activePrompt?.turnId });
|
|
761
869
|
this.emit({
|
|
762
870
|
type: "session.permission",
|
|
763
871
|
sessionId: this.options.boundarySessionId,
|
|
@@ -779,8 +887,18 @@ class AcpRuntime {
|
|
|
779
887
|
sessionUpdate(notification) {
|
|
780
888
|
if (notification.sessionId !== this.nativeSessionId)
|
|
781
889
|
return;
|
|
782
|
-
if (this.replayWindow
|
|
890
|
+
if (this.replayWindow)
|
|
891
|
+
this.lastLoadUpdateAt = performance.now();
|
|
892
|
+
if (this.replayWindow === "skip") {
|
|
893
|
+
const update = notification.update;
|
|
894
|
+
if (update.sessionUpdate === "available_commands_update" ||
|
|
895
|
+
update.sessionUpdate === "config_option_update" ||
|
|
896
|
+
update.sessionUpdate === "current_mode_update" ||
|
|
897
|
+
update.sessionUpdate === "usage_update") {
|
|
898
|
+
this.reduceStateUpdate(update);
|
|
899
|
+
}
|
|
783
900
|
return;
|
|
901
|
+
}
|
|
784
902
|
if (this.replayWindow === "replay" &&
|
|
785
903
|
notification.update.sessionUpdate === "user_message_chunk") {
|
|
786
904
|
this.reduceUserMessageChunk(notification.update);
|
|
@@ -891,11 +1009,15 @@ class AcpRuntime {
|
|
|
891
1009
|
argumentHint: command.input?.hint,
|
|
892
1010
|
}));
|
|
893
1011
|
this.emit({ type: "session.commands", sessionId: this.options.boundarySessionId, commands });
|
|
1012
|
+
this.receivedInitialCommands = true;
|
|
894
1013
|
this.commandWaiter?.();
|
|
895
|
-
this.commandWaiter = null;
|
|
896
1014
|
return;
|
|
897
1015
|
}
|
|
898
1016
|
if (update.sessionUpdate === "current_mode_update") {
|
|
1017
|
+
const option = modeOption(this.configOptions);
|
|
1018
|
+
if (option?.type === "select") {
|
|
1019
|
+
this.configOptions = this.configOptions.map((candidate) => candidate === option ? { ...option, currentValue: update.currentModeId } : candidate);
|
|
1020
|
+
}
|
|
899
1021
|
if (this.modes)
|
|
900
1022
|
this.modes = { ...this.modes, currentModeId: update.currentModeId };
|
|
901
1023
|
this.emitConfig();
|
|
@@ -1066,17 +1188,30 @@ class AcpRuntime {
|
|
|
1066
1188
|
this.commandWaiter = null;
|
|
1067
1189
|
}
|
|
1068
1190
|
waitForInitialCommands() {
|
|
1191
|
+
if (this.receivedInitialCommands)
|
|
1192
|
+
return Promise.resolve();
|
|
1069
1193
|
const timeoutMs = this.options.options.acpOptions?.initialCommandsTimeoutMs ?? 1000;
|
|
1070
1194
|
const commands = new Promise((resolve) => {
|
|
1071
1195
|
this.commandWaiter = resolve;
|
|
1072
1196
|
});
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
return Promise.race([commands, timeout]).finally(() => {
|
|
1197
|
+
return withTimeout(commands, timeoutMs, "ACP agent did not publish initial commands")
|
|
1198
|
+
.catch(() => undefined)
|
|
1199
|
+
.finally(() => {
|
|
1077
1200
|
this.commandWaiter = null;
|
|
1078
1201
|
});
|
|
1079
1202
|
}
|
|
1203
|
+
async waitForLoadReplay(quietPeriod) {
|
|
1204
|
+
const start = performance.now();
|
|
1205
|
+
const deadline = start + 5 * quietPeriod;
|
|
1206
|
+
while (!this.closing && !this.processFailed) {
|
|
1207
|
+
const idleAt = Math.max(start, this.lastLoadUpdateAt) + quietPeriod;
|
|
1208
|
+
const remaining = Math.min(deadline, idleAt) - performance.now();
|
|
1209
|
+
if (remaining <= 0)
|
|
1210
|
+
return;
|
|
1211
|
+
await new Promise((resolve) => setTimeout(resolve, remaining));
|
|
1212
|
+
await this.notificationLane;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1080
1215
|
}
|
|
1081
1216
|
function routeVendorNotifications(stream, receive) {
|
|
1082
1217
|
const clientMethods = new Set(Object.values(CLIENT_METHODS));
|
|
@@ -1210,24 +1345,29 @@ function readNativeSessionId(persistence) {
|
|
|
1210
1345
|
function toProviderConfigState(modes, options) {
|
|
1211
1346
|
const model = modelOption(options);
|
|
1212
1347
|
const thinking = options.find((option) => option.category === "thought_level");
|
|
1348
|
+
const modeConfig = modeOption(options);
|
|
1213
1349
|
return {
|
|
1214
1350
|
model: selectedValue(model),
|
|
1215
|
-
mode: modes?.currentModeId,
|
|
1351
|
+
mode: selectedValue(modeConfig) ?? modes?.currentModeId,
|
|
1216
1352
|
thinkingOption: selectedValue(thinking),
|
|
1217
1353
|
models: selectOptions(model).map((option) => ({ id: option.value, label: option.label })),
|
|
1218
|
-
modes:
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1354
|
+
modes: modeConfig
|
|
1355
|
+
? selectOptions(modeConfig).map((option) => ({
|
|
1356
|
+
id: option.value,
|
|
1357
|
+
label: option.label,
|
|
1358
|
+
description: option.description,
|
|
1359
|
+
}))
|
|
1360
|
+
: (modes?.availableModes.map((mode) => ({
|
|
1361
|
+
id: mode.id,
|
|
1362
|
+
label: mode.name,
|
|
1363
|
+
description: mode.description ?? undefined,
|
|
1364
|
+
})) ?? []),
|
|
1223
1365
|
thinkingOptions: selectOptions(thinking).map((option) => ({
|
|
1224
1366
|
id: option.value,
|
|
1225
1367
|
label: option.label,
|
|
1226
1368
|
})),
|
|
1227
1369
|
settings: options
|
|
1228
|
-
.filter((option) => option !== model &&
|
|
1229
|
-
option.category !== "thought_level" &&
|
|
1230
|
-
!(modes && option.category === "mode"))
|
|
1370
|
+
.filter((option) => option !== model && option.category !== "thought_level" && option !== modeConfig)
|
|
1231
1371
|
.map(toProviderSetting),
|
|
1232
1372
|
};
|
|
1233
1373
|
}
|
|
@@ -1237,6 +1377,9 @@ function modelOption(options) {
|
|
|
1237
1377
|
const candidates = options.filter((option) => option.category === "model");
|
|
1238
1378
|
return candidates.find((option) => option.id === "model") ?? candidates[0];
|
|
1239
1379
|
}
|
|
1380
|
+
function modeOption(options) {
|
|
1381
|
+
return options.find((option) => option.category === "mode" && option.type === "select");
|
|
1382
|
+
}
|
|
1240
1383
|
function toProviderCatalog(modes, options) {
|
|
1241
1384
|
const state = toProviderConfigState(modes, options);
|
|
1242
1385
|
return {
|
|
@@ -1264,15 +1407,25 @@ function toProviderSetting(option) {
|
|
|
1264
1407
|
label: option.name,
|
|
1265
1408
|
description: option.description ?? undefined,
|
|
1266
1409
|
value: option.currentValue,
|
|
1267
|
-
options: selectOptions(option),
|
|
1410
|
+
options: selectOptions(option).map(({ label, value }) => ({ label, value })),
|
|
1268
1411
|
};
|
|
1269
1412
|
}
|
|
1270
1413
|
function selectOptions(option) {
|
|
1271
1414
|
if (!option || option.type === "boolean")
|
|
1272
1415
|
return [];
|
|
1273
1416
|
return option.options.flatMap((candidate) => "group" in candidate
|
|
1274
|
-
? candidate.options.map((nested) => ({
|
|
1275
|
-
|
|
1417
|
+
? candidate.options.map((nested) => ({
|
|
1418
|
+
label: nested.name,
|
|
1419
|
+
value: nested.value,
|
|
1420
|
+
description: nested.description ?? undefined,
|
|
1421
|
+
}))
|
|
1422
|
+
: [
|
|
1423
|
+
{
|
|
1424
|
+
label: candidate.name,
|
|
1425
|
+
value: candidate.value,
|
|
1426
|
+
description: candidate.description ?? undefined,
|
|
1427
|
+
},
|
|
1428
|
+
]);
|
|
1276
1429
|
}
|
|
1277
1430
|
function selectedValue(option) {
|
|
1278
1431
|
return option && option.type !== "boolean" ? option.currentValue : undefined;
|
|
@@ -1283,15 +1436,16 @@ function configValues(options) {
|
|
|
1283
1436
|
function toolTimelineItem(snapshot) {
|
|
1284
1437
|
const input = jsonRecord(snapshot.input);
|
|
1285
1438
|
const isEdit = snapshot.kind === "edit" || snapshot.name?.toLowerCase().includes("edit") === true;
|
|
1286
|
-
const detail =
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1439
|
+
const detail = snapshot.detail ??
|
|
1440
|
+
(isEdit
|
|
1441
|
+
? {
|
|
1442
|
+
type: "edit",
|
|
1443
|
+
filePath: typeof input.filePath === "string" ? input.filePath : (snapshot.locations[0] ?? ""),
|
|
1444
|
+
oldString: typeof input.oldString === "string" ? input.oldString : undefined,
|
|
1445
|
+
newString: typeof input.newString === "string" ? input.newString : undefined,
|
|
1446
|
+
unifiedDiff: typeof input.unifiedDiff === "string" ? input.unifiedDiff : undefined,
|
|
1447
|
+
}
|
|
1448
|
+
: { type: "unknown", input: snapshot.input, output: snapshot.output });
|
|
1295
1449
|
const status = snapshot.status === "in_progress" || snapshot.status === "pending"
|
|
1296
1450
|
? "running"
|
|
1297
1451
|
: snapshot.status;
|
package/dist/server/acp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonValue } from "@getpaseo/protocol/agent-types";
|
|
2
|
-
import type { ProviderCatalog, ProviderCommand, ProviderConfigState, ProviderNotice, ProviderRegistration, ProviderTimelineItem } from "./provider.js";
|
|
2
|
+
import type { ProviderCatalog, ProviderCommand, ProviderConfigState, ProviderMode, ProviderNotice, ProviderPersistence, ProviderRegistration, ProviderTimelineItem, ProviderToolCallDetail } from "./provider.js";
|
|
3
3
|
interface RunAcpProviderBaseOptions {
|
|
4
4
|
id: string;
|
|
5
5
|
label: string;
|
|
@@ -49,6 +49,14 @@ export interface AcpOptions {
|
|
|
49
49
|
workspaceOnlyCatalog?: boolean;
|
|
50
50
|
waitForInitialCommands?: boolean;
|
|
51
51
|
initialCommandsTimeoutMs?: number;
|
|
52
|
+
/** Allow delayed session/load updates before publishing the session as ready. */
|
|
53
|
+
loadReplayQuietPeriodMs?: number;
|
|
54
|
+
/** An unattended mode that approves ACP allow-once requests in the specified native mode. */
|
|
55
|
+
autoAcceptMode?: {
|
|
56
|
+
mode: Omit<ProviderMode, "isUnattended">;
|
|
57
|
+
nativeMode: string;
|
|
58
|
+
default?: boolean;
|
|
59
|
+
};
|
|
52
60
|
}
|
|
53
61
|
export interface AcpContext {
|
|
54
62
|
sessionId: string;
|
|
@@ -62,6 +70,8 @@ export interface AcpDiscoveryContext extends AcpContext {
|
|
|
62
70
|
}
|
|
63
71
|
export interface AcpConfigureContext extends AcpContext {
|
|
64
72
|
config: AcpConfigAccess;
|
|
73
|
+
catalog(): ProviderCatalog;
|
|
74
|
+
apply(change: AcpConfigChange): Promise<void>;
|
|
65
75
|
}
|
|
66
76
|
export type AcpConfigChange = {
|
|
67
77
|
target: "model";
|
|
@@ -86,6 +96,7 @@ export interface AcpToolCallSnapshot {
|
|
|
86
96
|
input: JsonValue;
|
|
87
97
|
output: JsonValue;
|
|
88
98
|
locations: readonly string[];
|
|
99
|
+
detail?: ProviderToolCallDetail;
|
|
89
100
|
}
|
|
90
101
|
export type AcpVendorUpdate = {
|
|
91
102
|
type: "commands";
|
|
@@ -101,6 +112,15 @@ export type AcpVendorUpdate = {
|
|
|
101
112
|
notice: ProviderNotice;
|
|
102
113
|
};
|
|
103
114
|
export interface AcpTransformer {
|
|
115
|
+
/** Decode an older saved session and supply extension metadata for session/new or session/load. */
|
|
116
|
+
sessionOpen?(context: {
|
|
117
|
+
persistence?: ProviderPersistence;
|
|
118
|
+
systemPrompt?: string;
|
|
119
|
+
agentMetadata: JsonValue;
|
|
120
|
+
}): {
|
|
121
|
+
sessionId?: string;
|
|
122
|
+
metadata?: Readonly<Record<string, JsonValue>>;
|
|
123
|
+
};
|
|
104
124
|
discover?(catalog: ProviderCatalog, context: AcpDiscoveryContext): Promise<ProviderCatalog> | ProviderCatalog;
|
|
105
125
|
configure?(change: AcpConfigChange, context: AcpConfigureContext): Promise<"handled" | "pass">;
|
|
106
126
|
notification?(notification: {
|
|
@@ -83,6 +83,8 @@ export interface PluginSessionOpenRequest {
|
|
|
83
83
|
readonly background: boolean;
|
|
84
84
|
readonly labels: Readonly<Record<string, string>>;
|
|
85
85
|
readonly metadata: Readonly<Record<string, JsonValue>>;
|
|
86
|
+
/** Instructions appended for this open; not saved on the agent. */
|
|
87
|
+
appendSystemPrompt?: string[];
|
|
86
88
|
tools: AgentToolDefinition[];
|
|
87
89
|
env: Record<string, string>;
|
|
88
90
|
mcpServers: NonNullable<AgentSessionConfig["mcpServers"]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpaseo/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0-beta.1",
|
|
4
4
|
"description": "Paseo plugin SDK package",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"files": [
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"use-sync-external-store": "^1.6.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@getpaseo/client": "0.
|
|
82
|
-
"@getpaseo/protocol": "0.
|
|
81
|
+
"@getpaseo/client": "0.17.0-beta.1",
|
|
82
|
+
"@getpaseo/protocol": "0.17.0-beta.1",
|
|
83
83
|
"@types/node": "^20.9.0",
|
|
84
84
|
"@types/react": "~19.2.0",
|
|
85
85
|
"react": "19.2.3",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"zod": "^4.4.3"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
|
-
"@getpaseo/client": "0.
|
|
93
|
-
"@getpaseo/protocol": "0.
|
|
92
|
+
"@getpaseo/client": "0.17.0-beta.1",
|
|
93
|
+
"@getpaseo/protocol": "0.17.0-beta.1",
|
|
94
94
|
"react": ">=19.1.0 <20",
|
|
95
95
|
"react-native": ">=0.81.5",
|
|
96
96
|
"zod": "^4.4.3"
|