@agentvault/openai-bridge 0.1.15 → 0.1.16
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/README.md +2 -1
- package/dist/bridge.d.ts +23 -2
- package/dist/cli.d.ts +1 -1
- package/dist/index.js +103 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,8 @@ The bridge log (`agentvault-openai-bridge logs`) writes one line per event:
|
|
|
73
73
|
| `turn_failed code=<code> exit=<n or none>` | Codex did not produce a verified reply. The code is the cause the bridge assigned, and `exit` is the Codex exit status, or `none` when there is no exit status to report. A notice follows. |
|
|
74
74
|
| `reply_failed code=<code>` | Codex answered, but the reply could not be delivered to the chat. |
|
|
75
75
|
| `notice_failed code=<code>` | The turn failed, and the failure notice could not be delivered either. The failure is still recorded under Health. |
|
|
76
|
-
| `turn_cancelled reason=<
|
|
76
|
+
| `turn_cancelled reason=shutdown notice=<sent, failed, timeout or none>` | The bridge was stopped or restarted (for example during an update) while it owed this message an answer. Nothing replays the message, so the chat gets the plain sentence "Aster couldn't answer this message." It never names a cause. `notice` says whether that sentence was sent. `late=true` marks a message that arrived while the bridge was stopping. `notice=none delivered=true` means the answer was already being sent and it arrived, so nothing more is posted. The bridge waits at most 10 seconds for it, so a stuck send cannot hold up the restart. Nothing is recorded under Health, because the model did not fail. |
|
|
77
|
+
| `turn_cancelled reason=<reason>` | The turn was cut short on purpose, so no reply or notice is posted. Reasons: `auth_failed` (the agent's credentials were refused, which is how a revoked device shows up, followed by `channel_state`), `channel_state` (the encrypted channel dropped or reconnected), `delivery_timeout` (sending took too long), `hushed` (the room was hushed), `device_changed` (the agent's device ID changed), and `unknown`. |
|
|
77
78
|
| `turn_recovered code=session_resume_failed` | The saved Codex session for this chat was gone, so the bridge started a fresh one and its reply passed the final-answer check. Delivery is then logged as usual. See below. |
|
|
78
79
|
| `dm_dropped reason=unmapped_conversation` | A 1:1 message arrived that the agent cannot yet match to a conversation. That message got no answer and no notice yet. |
|
|
79
80
|
|
package/dist/bridge.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export interface TurnDriver {
|
|
|
44
44
|
freshContext?: string;
|
|
45
45
|
}): Promise<TurnResult>;
|
|
46
46
|
}
|
|
47
|
+
/** Why a turn was dropped on purpose (#1560): logged, never shown as a failure.
|
|
48
|
+
* #1583: `shutdown` is our own stop or restart (SIGTERM, a fleet roll), the one
|
|
49
|
+
* cancel the owner is told about. Every other reason stays silent. */
|
|
50
|
+
export type CancelReason = "shutdown" | "auth_failed" | "revoked" | "channel_state" | "delivery_timeout" | "hushed" | "device_changed" | "unknown";
|
|
47
51
|
/** Serial inference AND delivery; every queued entry owns its authenticated target. */
|
|
48
52
|
export declare class OpenAIBridge {
|
|
49
53
|
private channel;
|
|
@@ -52,6 +56,7 @@ export declare class OpenAIBridge {
|
|
|
52
56
|
private report;
|
|
53
57
|
private maxQueue;
|
|
54
58
|
private deliveryTimeoutMs;
|
|
59
|
+
private noticeTimeoutMs;
|
|
55
60
|
private tail;
|
|
56
61
|
private pending;
|
|
57
62
|
private generation;
|
|
@@ -63,8 +68,13 @@ export declare class OpenAIBridge {
|
|
|
63
68
|
private stopped;
|
|
64
69
|
private active?;
|
|
65
70
|
private hush;
|
|
71
|
+
/** #1583: armed by stop("shutdown"): one deadline shared by every notice. */
|
|
72
|
+
private noticeCap?;
|
|
73
|
+
/** True once that cap has run out: a notice is no longer worth starting. */
|
|
74
|
+
private capExpired;
|
|
75
|
+
private notices;
|
|
66
76
|
private listeners;
|
|
67
|
-
constructor(channel: BridgeChannel, driver: TurnDriver, name: string, report?: (event: string) => void, maxQueue?: number, deliveryTimeoutMs?: number);
|
|
77
|
+
constructor(channel: BridgeChannel, driver: TurnDriver, name: string, report?: (event: string) => void, maxQueue?: number, deliveryTimeoutMs?: number, noticeTimeoutMs?: number);
|
|
68
78
|
private listen;
|
|
69
79
|
private hushed;
|
|
70
80
|
/** Ends the current generation. Its reason is recorded BEFORE the bump, under
|
|
@@ -91,7 +101,18 @@ export declare class OpenAIBridge {
|
|
|
91
101
|
private reportReply;
|
|
92
102
|
private deliver;
|
|
93
103
|
private deliverOnce;
|
|
104
|
+
/** #1583: an owed turn our own shutdown cancelled is never answered or
|
|
105
|
+
* replayed, so its chat gets the BARE sentence: a shutdown has no cause to
|
|
106
|
+
* tell, and it is not a model failure (no span). Sent straight to the
|
|
107
|
+
* channel, not through deliverOnce, whose timeout would invalidate and
|
|
108
|
+
* report a delivery problem. Raced against stop()'s shared cap. Never
|
|
109
|
+
* rejects; logs the outcome only, never an error's text. */
|
|
110
|
+
private shutdownNotice;
|
|
94
111
|
idle(): Promise<void>;
|
|
95
|
-
|
|
112
|
+
/** `reason` says why. Only `shutdown` (the default: our own stop or restart)
|
|
113
|
+
* tells the owed turns it strands (#1583); every other reason is silent.
|
|
114
|
+
* Resolves once every turn has ended and every notice has settled, inside
|
|
115
|
+
* the notice cap, so a caller stops the channel AFTER this, never alongside. */
|
|
116
|
+
stop(reason?: CancelReason): Promise<void>;
|
|
96
117
|
}
|
|
97
118
|
//# sourceMappingURL=bridge.d.ts.map
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HistoryRecoveryCommandInput } from "@agentvault/agentvault";
|
|
2
2
|
import { type Layout } from "./driver.js";
|
|
3
|
-
export declare const VERSION = "0.1.
|
|
3
|
+
export declare const VERSION = "0.1.16";
|
|
4
4
|
export interface RunConfig {
|
|
5
5
|
name: string;
|
|
6
6
|
apiUrl: string;
|
package/dist/index.js
CHANGED
|
@@ -11849,7 +11849,7 @@ function ownIdentity() {
|
|
|
11849
11849
|
return `${PACKAGE}@${v2}`;
|
|
11850
11850
|
}
|
|
11851
11851
|
function buildSha() {
|
|
11852
|
-
const raw = true ? "
|
|
11852
|
+
const raw = true ? "8b76eb4" : "";
|
|
11853
11853
|
const cleaned = (raw ?? "").trim();
|
|
11854
11854
|
return !cleaned || cleaned === "unknown" ? null : cleaned;
|
|
11855
11855
|
}
|
|
@@ -104141,7 +104141,7 @@ var init_cli = __esm({
|
|
|
104141
104141
|
"use strict";
|
|
104142
104142
|
await init_dist();
|
|
104143
104143
|
await init_driver();
|
|
104144
|
-
VERSION2 = "0.1.
|
|
104144
|
+
VERSION2 = "0.1.16";
|
|
104145
104145
|
HELP = `AgentVault OpenAI Bridge ${VERSION2}
|
|
104146
104146
|
Usage: AV_AGENT_NAME=<name> agentvault-openai-bridge <command>
|
|
104147
104147
|
|
|
@@ -104157,20 +104157,22 @@ Read-only conversational mode; filesystem, shell, web and integration tools are
|
|
|
104157
104157
|
});
|
|
104158
104158
|
|
|
104159
104159
|
// src/bridge.ts
|
|
104160
|
-
var OpenAIBridge;
|
|
104160
|
+
var SHUTDOWN_NOTICE_MS, OpenAIBridge;
|
|
104161
104161
|
var init_bridge = __esm({
|
|
104162
104162
|
async "src/bridge.ts"() {
|
|
104163
104163
|
"use strict";
|
|
104164
104164
|
await init_dist();
|
|
104165
|
+
SHUTDOWN_NOTICE_MS = 1e4;
|
|
104165
104166
|
OpenAIBridge = class {
|
|
104166
104167
|
constructor(channel, driver, name, report = () => {
|
|
104167
|
-
}, maxQueue = 16, deliveryTimeoutMs = 3e4) {
|
|
104168
|
+
}, maxQueue = 16, deliveryTimeoutMs = 3e4, noticeTimeoutMs = SHUTDOWN_NOTICE_MS) {
|
|
104168
104169
|
this.channel = channel;
|
|
104169
104170
|
this.driver = driver;
|
|
104170
104171
|
this.name = name;
|
|
104171
104172
|
this.report = report;
|
|
104172
104173
|
this.maxQueue = maxQueue;
|
|
104173
104174
|
this.deliveryTimeoutMs = deliveryTimeoutMs;
|
|
104175
|
+
this.noticeTimeoutMs = noticeTimeoutMs;
|
|
104174
104176
|
this.listen("ready", () => {
|
|
104175
104177
|
if (this.stopped)
|
|
104176
104178
|
return;
|
|
@@ -104229,6 +104231,7 @@ ${e.plaintext}` : e.plaintext);
|
|
|
104229
104231
|
report;
|
|
104230
104232
|
maxQueue;
|
|
104231
104233
|
deliveryTimeoutMs;
|
|
104234
|
+
noticeTimeoutMs;
|
|
104232
104235
|
tail = Promise.resolve();
|
|
104233
104236
|
pending = 0;
|
|
104234
104237
|
generation = 0;
|
|
@@ -104240,6 +104243,11 @@ ${e.plaintext}` : e.plaintext);
|
|
|
104240
104243
|
stopped = false;
|
|
104241
104244
|
active;
|
|
104242
104245
|
hush = /* @__PURE__ */ new Map();
|
|
104246
|
+
/** #1583: armed by stop("shutdown"): one deadline shared by every notice. */
|
|
104247
|
+
noticeCap;
|
|
104248
|
+
/** True once that cap has run out: a notice is no longer worth starting. */
|
|
104249
|
+
capExpired = false;
|
|
104250
|
+
notices = [];
|
|
104243
104251
|
listeners = [];
|
|
104244
104252
|
listen(event, listener) {
|
|
104245
104253
|
this.listeners.push([event, listener]);
|
|
@@ -104263,8 +104271,14 @@ ${e.plaintext}` : e.plaintext);
|
|
|
104263
104271
|
this.active?.abort();
|
|
104264
104272
|
}
|
|
104265
104273
|
cancelReason(entryGeneration, target, kind, id) {
|
|
104266
|
-
if (entryGeneration !== this.generation)
|
|
104267
|
-
|
|
104274
|
+
if (entryGeneration !== this.generation) {
|
|
104275
|
+
const reason = this.cancelReasons.get(entryGeneration) ?? "unknown";
|
|
104276
|
+
if (reason === "shutdown" && target.deviceId !== this.channel.deviceId)
|
|
104277
|
+
return "device_changed";
|
|
104278
|
+
if (reason === "shutdown" && kind === "room" && this.hushed(id))
|
|
104279
|
+
return "hushed";
|
|
104280
|
+
return reason;
|
|
104281
|
+
}
|
|
104268
104282
|
if (target.deviceId !== this.channel.deviceId)
|
|
104269
104283
|
return "device_changed";
|
|
104270
104284
|
if (kind === "room" && this.hushed(id))
|
|
@@ -104282,7 +104296,14 @@ ${last.text}`)))
|
|
|
104282
104296
|
return kept.map((entry) => `${entry.sender}: ${entry.text}`).join("\n").slice(-8192);
|
|
104283
104297
|
}
|
|
104284
104298
|
enqueue(kind, id, text, groupId) {
|
|
104285
|
-
if (!
|
|
104299
|
+
if (!id || !this.channel.deviceId || typeof text !== "string" || !text.trim() || Buffer.byteLength(text) > 96 * 1024)
|
|
104300
|
+
return;
|
|
104301
|
+
if (this.stopped) {
|
|
104302
|
+
if (this.noticeCap && this.cancelReasons.get(this.generation - 1) === "shutdown")
|
|
104303
|
+
this.notices.push(this.shutdownNotice({ kind, id, deviceId: this.channel.deviceId }, this.noticeCap, "late=true "));
|
|
104304
|
+
return;
|
|
104305
|
+
}
|
|
104306
|
+
if (!this.accepting)
|
|
104286
104307
|
return;
|
|
104287
104308
|
if (this.pending + this.waiting.length >= this.maxQueue) {
|
|
104288
104309
|
this.report("queue_full");
|
|
@@ -104299,7 +104320,13 @@ ${seed}` : void 0;
|
|
|
104299
104320
|
const target = { kind, id, deviceId: this.channel.deviceId };
|
|
104300
104321
|
const generation = this.generation;
|
|
104301
104322
|
const valid = () => this.ready && !this.stopped && generation === this.generation && target.deviceId === this.channel.deviceId && !(kind === "room" && this.hushed(id));
|
|
104302
|
-
const cancelled = () =>
|
|
104323
|
+
const cancelled = () => {
|
|
104324
|
+
const reason = this.cancelReason(generation, target, kind, id);
|
|
104325
|
+
if (reason === "shutdown" && this.noticeCap)
|
|
104326
|
+
this.notices.push(this.shutdownNotice(target, this.noticeCap));
|
|
104327
|
+
else
|
|
104328
|
+
this.report(`turn_cancelled reason=${reason}`);
|
|
104329
|
+
};
|
|
104303
104330
|
this.pending++;
|
|
104304
104331
|
this.tail = this.tail.then(async () => {
|
|
104305
104332
|
if (!valid()) {
|
|
@@ -104345,6 +104372,8 @@ ${text}`, controller.signal, { freshContext });
|
|
|
104345
104372
|
}
|
|
104346
104373
|
if (valid() && !controller.signal.aborted)
|
|
104347
104374
|
this.report("delivered");
|
|
104375
|
+
else if (this.cancelReason(generation, target, kind, id) === "shutdown")
|
|
104376
|
+
this.report("turn_cancelled reason=shutdown notice=none delivered=true");
|
|
104348
104377
|
} finally {
|
|
104349
104378
|
this.active = void 0;
|
|
104350
104379
|
}
|
|
@@ -104440,7 +104469,13 @@ ${text}`, controller.signal, { freshContext });
|
|
|
104440
104469
|
signal.removeEventListener("abort", abort);
|
|
104441
104470
|
error2 ? reject(error2) : resolve4();
|
|
104442
104471
|
};
|
|
104443
|
-
const abort = () =>
|
|
104472
|
+
const abort = () => {
|
|
104473
|
+
const cap = this.noticeCap;
|
|
104474
|
+
if (cap && this.cancelReasons.get(this.generation - 1) === "shutdown")
|
|
104475
|
+
void cap.then(() => finish(new Error("Delivery cancelled")));
|
|
104476
|
+
else
|
|
104477
|
+
finish(new Error("Delivery cancelled"));
|
|
104478
|
+
};
|
|
104444
104479
|
const timer = setTimeout(() => {
|
|
104445
104480
|
finish(new Error("Delivery timed out"));
|
|
104446
104481
|
this.stopped = true;
|
|
@@ -104456,16 +104491,50 @@ ${text}`, controller.signal, { freshContext });
|
|
|
104456
104491
|
});
|
|
104457
104492
|
});
|
|
104458
104493
|
}
|
|
104494
|
+
/** #1583: an owed turn our own shutdown cancelled is never answered or
|
|
104495
|
+
* replayed, so its chat gets the BARE sentence: a shutdown has no cause to
|
|
104496
|
+
* tell, and it is not a model failure (no span). Sent straight to the
|
|
104497
|
+
* channel, not through deliverOnce, whose timeout would invalidate and
|
|
104498
|
+
* report a delivery problem. Raced against stop()'s shared cap. Never
|
|
104499
|
+
* rejects; logs the outcome only, never an error's text. */
|
|
104500
|
+
async shutdownNotice(target, cap, tag = "") {
|
|
104501
|
+
if (this.capExpired) {
|
|
104502
|
+
this.report(`turn_cancelled reason=shutdown ${tag}notice=timeout`);
|
|
104503
|
+
return;
|
|
104504
|
+
}
|
|
104505
|
+
const notice = ownerNoticeFor("model_error", { agentName: this.channel.ownDisplayName?.trim() || this.name, provider: "OpenAI" });
|
|
104506
|
+
const sent = Promise.resolve().then(() => target.kind === "room" ? this.channel.sendToRoom(target.id, notice) : this.channel.send(notice, { conversationId: target.id })).then(() => "sent", () => "failed");
|
|
104507
|
+
const outcome = await Promise.race([sent, cap]);
|
|
104508
|
+
this.report(`turn_cancelled reason=shutdown ${tag}notice=${outcome}`);
|
|
104509
|
+
}
|
|
104459
104510
|
async idle() {
|
|
104460
104511
|
await this.tail;
|
|
104461
104512
|
}
|
|
104462
|
-
|
|
104513
|
+
/** `reason` says why. Only `shutdown` (the default: our own stop or restart)
|
|
104514
|
+
* tells the owed turns it strands (#1583); every other reason is silent.
|
|
104515
|
+
* Resolves once every turn has ended and every notice has settled, inside
|
|
104516
|
+
* the notice cap, so a caller stops the channel AFTER this, never alongside. */
|
|
104517
|
+
async stop(reason = "shutdown") {
|
|
104518
|
+
let timer;
|
|
104519
|
+
if (reason === "shutdown" && !this.noticeCap)
|
|
104520
|
+
this.noticeCap = new Promise((resolve4) => {
|
|
104521
|
+
timer = setTimeout(() => {
|
|
104522
|
+
this.capExpired = true;
|
|
104523
|
+
resolve4("timeout");
|
|
104524
|
+
}, this.noticeTimeoutMs);
|
|
104525
|
+
});
|
|
104463
104526
|
this.stopped = true;
|
|
104464
|
-
this.invalidate(
|
|
104465
|
-
|
|
104466
|
-
this.
|
|
104467
|
-
|
|
104468
|
-
|
|
104527
|
+
this.invalidate(reason);
|
|
104528
|
+
try {
|
|
104529
|
+
await this.tail;
|
|
104530
|
+
while (this.notices.length)
|
|
104531
|
+
await Promise.all(this.notices.splice(0));
|
|
104532
|
+
} finally {
|
|
104533
|
+
for (const [event, fn] of this.listeners)
|
|
104534
|
+
this.channel.off(event, fn);
|
|
104535
|
+
this.listeners = [];
|
|
104536
|
+
clearTimeout(timer);
|
|
104537
|
+
}
|
|
104469
104538
|
}
|
|
104470
104539
|
};
|
|
104471
104540
|
}
|
|
@@ -104557,14 +104626,25 @@ async function startBridge(config2, injected) {
|
|
|
104557
104626
|
const ended = new Promise((resolve4) => {
|
|
104558
104627
|
finish = resolve4;
|
|
104559
104628
|
});
|
|
104560
|
-
const stop = () => {
|
|
104629
|
+
const stop = (reason = "shutdown") => {
|
|
104561
104630
|
shutdown ??= Promise.resolve().then(async () => {
|
|
104562
104631
|
try {
|
|
104563
104632
|
let timeout;
|
|
104633
|
+
let bridgeBound;
|
|
104634
|
+
const bridgeStop = Promise.race([
|
|
104635
|
+
bridge?.stop(reason),
|
|
104636
|
+
new Promise((_2, reject) => {
|
|
104637
|
+
bridgeBound = setTimeout(() => reject(new Error("bridge stop timed out")), BRIDGE_STOP_MS);
|
|
104638
|
+
})
|
|
104639
|
+
]).finally(() => clearTimeout(bridgeBound));
|
|
104640
|
+
const stopBoth = async () => [
|
|
104641
|
+
...await Promise.allSettled([bridgeStop]),
|
|
104642
|
+
...await Promise.allSettled([channel?.stop()])
|
|
104643
|
+
];
|
|
104564
104644
|
const results = await Promise.race([
|
|
104565
|
-
|
|
104645
|
+
stopBoth(),
|
|
104566
104646
|
new Promise((resolve4) => {
|
|
104567
|
-
timeout = setTimeout(() => resolve4(null), injected?.shutdownMs ??
|
|
104647
|
+
timeout = setTimeout(() => resolve4(null), injected?.shutdownMs ?? 15e3);
|
|
104568
104648
|
})
|
|
104569
104649
|
]);
|
|
104570
104650
|
clearTimeout(timeout);
|
|
@@ -104610,7 +104690,7 @@ async function startBridge(config2, injected) {
|
|
|
104610
104690
|
report(event);
|
|
104611
104691
|
if (event === "delivery_timeout") {
|
|
104612
104692
|
deliveryFailed = true;
|
|
104613
|
-
void stop();
|
|
104693
|
+
void stop("delivery_timeout");
|
|
104614
104694
|
}
|
|
104615
104695
|
}, 16, injected?.deliveryTimeoutMs ?? 3e4);
|
|
104616
104696
|
signals.once("SIGINT", signal);
|
|
@@ -104627,12 +104707,12 @@ async function startBridge(config2, injected) {
|
|
|
104627
104707
|
});
|
|
104628
104708
|
channel.on("auth_failed", () => {
|
|
104629
104709
|
report("authentication_failed");
|
|
104630
|
-
void stop();
|
|
104710
|
+
void stop("auth_failed");
|
|
104631
104711
|
});
|
|
104632
104712
|
channel.on("state", (state) => {
|
|
104633
104713
|
report("channel_state_changed");
|
|
104634
104714
|
if (state === "error")
|
|
104635
|
-
void stop();
|
|
104715
|
+
void stop("channel_state");
|
|
104636
104716
|
});
|
|
104637
104717
|
channel.on("state", (state) => {
|
|
104638
104718
|
const fingerprint = channel?.fingerprint;
|
|
@@ -104661,6 +104741,7 @@ async function startBridge(config2, injected) {
|
|
|
104661
104741
|
if (deliveryFailed)
|
|
104662
104742
|
throw new Error("Bridge delivery timed out");
|
|
104663
104743
|
}
|
|
104744
|
+
var BRIDGE_STOP_MS;
|
|
104664
104745
|
var init_runtime = __esm({
|
|
104665
104746
|
async "src/runtime.ts"() {
|
|
104666
104747
|
"use strict";
|
|
@@ -104668,6 +104749,7 @@ var init_runtime = __esm({
|
|
|
104668
104749
|
await init_bridge();
|
|
104669
104750
|
await init_cli();
|
|
104670
104751
|
init_lock();
|
|
104752
|
+
BRIDGE_STOP_MS = 11e3;
|
|
104671
104753
|
}
|
|
104672
104754
|
});
|
|
104673
104755
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@agentvault/openai-bridge", "version": "0.1.
|
|
2
|
+
"name": "@agentvault/openai-bridge", "version": "0.1.16", "type": "module",
|
|
3
3
|
"description": "AgentVault OpenAI Codex bridge for encrypted owner messages and rooms",
|
|
4
4
|
"main": "dist/index.js", "types": "dist/index.d.ts",
|
|
5
5
|
"bin": { "agentvault-openai-bridge": "dist/index.js" },
|