@oh-my-pi/pi-agent-core 11.5.2 → 11.6.0
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 +4 -4
- package/src/agent.ts +57 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-agent-core",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"test": "bun test"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@oh-my-pi/pi-ai": "11.
|
|
28
|
-
"@oh-my-pi/pi-tui": "11.
|
|
29
|
-
"@oh-my-pi/pi-utils": "11.
|
|
27
|
+
"@oh-my-pi/pi-ai": "11.6.0",
|
|
28
|
+
"@oh-my-pi/pi-tui": "11.6.0",
|
|
29
|
+
"@oh-my-pi/pi-utils": "11.6.0"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"ai",
|
package/src/agent.ts
CHANGED
|
@@ -356,6 +356,38 @@ export class Agent {
|
|
|
356
356
|
this.followUpQueue = [];
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
hasQueuedMessages(): boolean {
|
|
360
|
+
return this.steeringQueue.length > 0 || this.followUpQueue.length > 0;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private dequeueSteeringMessages(): AgentMessage[] {
|
|
364
|
+
if (this.steeringMode === "one-at-a-time") {
|
|
365
|
+
if (this.steeringQueue.length > 0) {
|
|
366
|
+
const first = this.steeringQueue[0];
|
|
367
|
+
this.steeringQueue = this.steeringQueue.slice(1);
|
|
368
|
+
return [first];
|
|
369
|
+
}
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
372
|
+
const steering = this.steeringQueue.slice();
|
|
373
|
+
this.steeringQueue = [];
|
|
374
|
+
return steering;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
private dequeueFollowUpMessages(): AgentMessage[] {
|
|
378
|
+
if (this.followUpMode === "one-at-a-time") {
|
|
379
|
+
if (this.followUpQueue.length > 0) {
|
|
380
|
+
const first = this.followUpQueue[0];
|
|
381
|
+
this.followUpQueue = this.followUpQueue.slice(1);
|
|
382
|
+
return [first];
|
|
383
|
+
}
|
|
384
|
+
return [];
|
|
385
|
+
}
|
|
386
|
+
const followUp = this.followUpQueue.slice();
|
|
387
|
+
this.followUpQueue = [];
|
|
388
|
+
return followUp;
|
|
389
|
+
}
|
|
390
|
+
|
|
359
391
|
/**
|
|
360
392
|
* Remove and return the last steering message from the queue (LIFO).
|
|
361
393
|
* Used by dequeue keybinding.
|
|
@@ -444,7 +476,9 @@ export class Agent {
|
|
|
444
476
|
await this._runLoop(msgs, promptOptions);
|
|
445
477
|
}
|
|
446
478
|
|
|
447
|
-
/**
|
|
479
|
+
/**
|
|
480
|
+
* Continue from current context (used for retries and resuming queued messages).
|
|
481
|
+
*/
|
|
448
482
|
async continue() {
|
|
449
483
|
if (this._state.isStreaming) {
|
|
450
484
|
throw new Error("Agent is already processing. Wait for completion before continuing.");
|
|
@@ -455,6 +489,18 @@ export class Agent {
|
|
|
455
489
|
throw new Error("No messages to continue from");
|
|
456
490
|
}
|
|
457
491
|
if (messages[messages.length - 1].role === "assistant") {
|
|
492
|
+
const queuedSteering = this.dequeueSteeringMessages();
|
|
493
|
+
if (queuedSteering.length > 0) {
|
|
494
|
+
await this._runLoop(queuedSteering, { skipInitialSteeringPoll: true });
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const queuedFollowUp = this.dequeueFollowUpMessages();
|
|
499
|
+
if (queuedFollowUp.length > 0) {
|
|
500
|
+
await this._runLoop(queuedFollowUp);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
458
504
|
throw new Error("Cannot continue from message role: assistant");
|
|
459
505
|
}
|
|
460
506
|
|
|
@@ -466,10 +512,15 @@ export class Agent {
|
|
|
466
512
|
* If messages are provided, starts a new conversation turn with those messages.
|
|
467
513
|
* Otherwise, continues from existing context.
|
|
468
514
|
*/
|
|
469
|
-
private async _runLoop(
|
|
515
|
+
private async _runLoop(
|
|
516
|
+
messages?: AgentMessage[],
|
|
517
|
+
options?: AgentPromptOptions & { skipInitialSteeringPoll?: boolean },
|
|
518
|
+
) {
|
|
470
519
|
const model = this._state.model;
|
|
471
520
|
if (!model) throw new Error("No model configured");
|
|
472
521
|
|
|
522
|
+
let skipInitialSteeringPoll = options?.skipInitialSteeringPoll === true;
|
|
523
|
+
|
|
473
524
|
this.runningPrompt = new Promise<void>(resolve => {
|
|
474
525
|
this.resolveRunningPrompt = resolve;
|
|
475
526
|
});
|
|
@@ -528,33 +579,13 @@ export class Agent {
|
|
|
528
579
|
cursorExecHandlers: this.cursorExecHandlers,
|
|
529
580
|
cursorOnToolResult,
|
|
530
581
|
getSteeringMessages: async () => {
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
const first = this.steeringQueue[0];
|
|
534
|
-
this.steeringQueue = this.steeringQueue.slice(1);
|
|
535
|
-
return [first];
|
|
536
|
-
}
|
|
582
|
+
if (skipInitialSteeringPoll) {
|
|
583
|
+
skipInitialSteeringPoll = false;
|
|
537
584
|
return [];
|
|
538
|
-
} else {
|
|
539
|
-
const steering = this.steeringQueue.slice();
|
|
540
|
-
this.steeringQueue = [];
|
|
541
|
-
return steering;
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
getFollowUpMessages: async () => {
|
|
545
|
-
if (this.followUpMode === "one-at-a-time") {
|
|
546
|
-
if (this.followUpQueue.length > 0) {
|
|
547
|
-
const first = this.followUpQueue[0];
|
|
548
|
-
this.followUpQueue = this.followUpQueue.slice(1);
|
|
549
|
-
return [first];
|
|
550
|
-
}
|
|
551
|
-
return [];
|
|
552
|
-
} else {
|
|
553
|
-
const followUp = this.followUpQueue.slice();
|
|
554
|
-
this.followUpQueue = [];
|
|
555
|
-
return followUp;
|
|
556
585
|
}
|
|
586
|
+
return this.dequeueSteeringMessages();
|
|
557
587
|
},
|
|
588
|
+
getFollowUpMessages: async () => this.dequeueFollowUpMessages(),
|
|
558
589
|
};
|
|
559
590
|
|
|
560
591
|
let partial: AgentMessage | null = null;
|