agent-relay-codex 0.4.27 → 0.4.29
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/live-sidecar.ts +29 -9
- package/package.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
package/live-sidecar.ts
CHANGED
|
@@ -85,6 +85,7 @@ class CodexLiveSidecar {
|
|
|
85
85
|
private draining = false;
|
|
86
86
|
private drainDueAt = 0;
|
|
87
87
|
private reconnecting: Promise<void> | null = null;
|
|
88
|
+
private relayPrimerDelivered = false;
|
|
88
89
|
private readonly pendingMessages = new Map<number, RelayMessage>();
|
|
89
90
|
private readonly activeClaimedMessageIds = new Set<number>();
|
|
90
91
|
|
|
@@ -529,7 +530,7 @@ class CodexLiveSidecar {
|
|
|
529
530
|
}
|
|
530
531
|
|
|
531
532
|
const delivery = this.pickDeliveryMode(batch.messages);
|
|
532
|
-
const prompt = formatRelayPrompt(batch.messages);
|
|
533
|
+
const prompt = formatRelayPrompt(batch.messages, { includePrimer: !this.relayPrimerDelivered });
|
|
533
534
|
const ids = batch.messages.map((message) => message.id).join(", ");
|
|
534
535
|
this.log(`delivering message ${ids} via ${delivery}`);
|
|
535
536
|
|
|
@@ -548,6 +549,7 @@ class CodexLiveSidecar {
|
|
|
548
549
|
try {
|
|
549
550
|
await this.app.turnSteer(this.threadId, this.activeTurnId, prompt);
|
|
550
551
|
for (const id of claimedMessageIds) this.activeClaimedMessageIds.add(id);
|
|
552
|
+
this.relayPrimerDelivered = true;
|
|
551
553
|
await this.markBatchRead(batch.messages);
|
|
552
554
|
this.advanceCursor(batch.messages);
|
|
553
555
|
this.writeState();
|
|
@@ -559,6 +561,7 @@ class CodexLiveSidecar {
|
|
|
559
561
|
|
|
560
562
|
await this.app.turnStart(this.threadId, prompt);
|
|
561
563
|
for (const id of claimedMessageIds) this.activeClaimedMessageIds.add(id);
|
|
564
|
+
this.relayPrimerDelivered = true;
|
|
562
565
|
await this.markBatchRead(batch.messages);
|
|
563
566
|
this.advanceCursor(batch.messages);
|
|
564
567
|
this.writeState();
|
|
@@ -654,10 +657,25 @@ function shouldIsolateMessage(message: RelayMessage): boolean {
|
|
|
654
657
|
return delivery === "interrupt" || delivery === "start" || delivery === "steer" || priority === "urgent";
|
|
655
658
|
}
|
|
656
659
|
|
|
657
|
-
export function formatRelayPrompt(
|
|
660
|
+
export function formatRelayPrompt(
|
|
661
|
+
messages: RelayMessage[],
|
|
662
|
+
opts: { includePrimer?: boolean } = {},
|
|
663
|
+
): string {
|
|
664
|
+
const includePrimer = opts.includePrimer === true;
|
|
665
|
+
const relayUrl = process.env.AGENT_RELAY_URL || "http://127.0.0.1:4850";
|
|
666
|
+
const primer = [
|
|
667
|
+
"Agent Relay live-message primer:",
|
|
668
|
+
"Treat Agent Relay deliveries as live incoming messages from other agents. Respond or act on them as appropriate.",
|
|
669
|
+
"When calling the relay API, include AGENT_RELAY_TOKEN as the X-Agent-Relay-Token header if that environment variable is set.",
|
|
670
|
+
`For normal replies, POST JSON to ${relayUrl}/api/messages with from set to your Agent Relay ID, to set to the sender Agent Relay ID, body set to your response, and replyTo set to the incoming message id.`,
|
|
671
|
+
`For pair chat replies, POST JSON to ${relayUrl}/api/pairs/{pairId}/messages with from set to your Agent Relay ID and body set to your response.`,
|
|
672
|
+
"",
|
|
673
|
+
];
|
|
674
|
+
|
|
658
675
|
if (messages.length === 1) {
|
|
659
676
|
const message = messages[0]!;
|
|
660
677
|
const lines = [
|
|
678
|
+
...(includePrimer ? primer : []),
|
|
661
679
|
"Agent Relay message received.",
|
|
662
680
|
"",
|
|
663
681
|
formatMessageSummary(message),
|
|
@@ -678,16 +696,15 @@ export function formatRelayPrompt(messages: RelayMessage[]): string {
|
|
|
678
696
|
"Body:",
|
|
679
697
|
message.body,
|
|
680
698
|
"",
|
|
681
|
-
"Treat this as a live incoming message from another agent. Respond or act on it as appropriate.",
|
|
682
|
-
"If AGENT_RELAY_TOKEN is set, include it as the X-Agent-Relay-Token header when calling the relay API.",
|
|
683
699
|
typeof message.meta?.pairId === "string"
|
|
684
|
-
? `
|
|
685
|
-
: `
|
|
700
|
+
? `Reply routing: pairId=${JSON.stringify(message.meta.pairId)}.`
|
|
701
|
+
: `Reply routing: to=${JSON.stringify(message.from)}, replyTo=${message.id}.`,
|
|
686
702
|
);
|
|
687
703
|
return lines.join("\n");
|
|
688
704
|
}
|
|
689
705
|
|
|
690
706
|
const lines = [
|
|
707
|
+
...(includePrimer ? primer : []),
|
|
691
708
|
"Agent Relay message batch received.",
|
|
692
709
|
"",
|
|
693
710
|
`Count: ${messages.length}`,
|
|
@@ -705,13 +722,16 @@ export function formatRelayPrompt(messages: RelayMessage[]): string {
|
|
|
705
722
|
if (message.subject) lines.push(`Subject: ${message.subject}`);
|
|
706
723
|
if (message.replyTo) lines.push(`Reply To: ${message.replyTo}`);
|
|
707
724
|
if (typeof message.meta?.pairId === "string") lines.push(`Pair ID: ${message.meta.pairId}`);
|
|
725
|
+
lines.push(
|
|
726
|
+
typeof message.meta?.pairId === "string"
|
|
727
|
+
? `Reply routing: pairId=${JSON.stringify(message.meta.pairId)}.`
|
|
728
|
+
: `Reply routing: to=${JSON.stringify(message.from)}, replyTo=${message.id}.`,
|
|
729
|
+
);
|
|
708
730
|
lines.push("Body:", message.body, "", "---", "");
|
|
709
731
|
}
|
|
710
732
|
|
|
711
733
|
lines.push(
|
|
712
|
-
"
|
|
713
|
-
"If AGENT_RELAY_TOKEN is set, include it as the X-Agent-Relay-Token header when calling the relay API.",
|
|
714
|
-
`To reply, POST JSON to ${process.env.AGENT_RELAY_URL || "http://127.0.0.1:4850"}/api/messages with from set to your Agent Relay ID and replyTo set to the message you are answering.`,
|
|
734
|
+
"Synthesize these messages into one coherent response or action. Use each message's Reply routing line when replying.",
|
|
715
735
|
);
|
|
716
736
|
return lines.join("\n");
|
|
717
737
|
}
|
package/package.json
CHANGED