usebeeline 0.0.69 → 0.0.72
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/dist/usebeeline.mjs +34 -10
- package/package.json +1 -1
package/dist/usebeeline.mjs
CHANGED
|
@@ -18057,6 +18057,10 @@ async function runServerCommandIntake(options) {
|
|
|
18057
18057
|
throw new Error("server command protocol 1 is required; refusing intake");
|
|
18058
18058
|
let busy;
|
|
18059
18059
|
let wake;
|
|
18060
|
+
let pushIntakeAcknowledged = false;
|
|
18061
|
+
let reconciliation;
|
|
18062
|
+
let reconciliationError;
|
|
18063
|
+
let stopped = false;
|
|
18060
18064
|
const pending = new Map(first.commands.map((command) => [command.id, command]));
|
|
18061
18065
|
const claimed = /* @__PURE__ */ new Set();
|
|
18062
18066
|
const notify2 = (commands = []) => {
|
|
@@ -18065,13 +18069,35 @@ async function runServerCommandIntake(options) {
|
|
|
18065
18069
|
pending.set(command.id, command);
|
|
18066
18070
|
wake?.(false);
|
|
18067
18071
|
};
|
|
18072
|
+
const requestReconciliation = () => {
|
|
18073
|
+
if (reconciliation)
|
|
18074
|
+
return;
|
|
18075
|
+
reconciliation = api.execute("getAgentCommands", { roomId }).then((page) => {
|
|
18076
|
+
if (page.commandProtocol !== 1)
|
|
18077
|
+
throw new Error("server command protocol changed; refusing intake");
|
|
18078
|
+
if (!stopped)
|
|
18079
|
+
notify2(page.commands);
|
|
18080
|
+
}).catch((error) => {
|
|
18081
|
+
reconciliationError = error;
|
|
18082
|
+
wake?.(false);
|
|
18083
|
+
}).finally(() => {
|
|
18084
|
+
reconciliation = void 0;
|
|
18085
|
+
});
|
|
18086
|
+
};
|
|
18068
18087
|
options.onWake?.(notify2);
|
|
18069
|
-
const off = api.liveSubscribe?.(roomId, void 0, void 0, (connected) => {
|
|
18070
|
-
|
|
18088
|
+
const off = api.liveSubscribe?.(roomId, void 0, void 0, (connected, capabilities) => {
|
|
18089
|
+
const acknowledged = connected && capabilities?.pushIntake === true;
|
|
18090
|
+
if (pushIntakeAcknowledged !== acknowledged) {
|
|
18091
|
+
pushIntakeAcknowledged = acknowledged;
|
|
18092
|
+
wake?.(!connected);
|
|
18093
|
+
} else if (!connected) {
|
|
18071
18094
|
wake?.(true);
|
|
18095
|
+
}
|
|
18072
18096
|
}, options.presence, notify2);
|
|
18073
18097
|
try {
|
|
18074
18098
|
while (!signal?.aborted) {
|
|
18099
|
+
if (reconciliationError)
|
|
18100
|
+
throw reconciliationError;
|
|
18075
18101
|
if (options.closed && await options.closed())
|
|
18076
18102
|
return;
|
|
18077
18103
|
for (const command of [...pending.values()]) {
|
|
@@ -18079,6 +18105,7 @@ async function runServerCommandIntake(options) {
|
|
|
18079
18105
|
if (busy && command.action !== "stop")
|
|
18080
18106
|
continue;
|
|
18081
18107
|
pending.delete(command.id);
|
|
18108
|
+
claimed.add(command.id);
|
|
18082
18109
|
try {
|
|
18083
18110
|
await api.execute("claimAgentCommand", {
|
|
18084
18111
|
roomId,
|
|
@@ -18086,10 +18113,10 @@ async function runServerCommandIntake(options) {
|
|
|
18086
18113
|
generationId: context.generationId
|
|
18087
18114
|
});
|
|
18088
18115
|
} catch (error) {
|
|
18116
|
+
claimed.delete(command.id);
|
|
18089
18117
|
options.onError?.(error);
|
|
18090
18118
|
continue;
|
|
18091
18119
|
}
|
|
18092
|
-
claimed.add(command.id);
|
|
18093
18120
|
if (command.action === "stop") {
|
|
18094
18121
|
options.stop(command.turnRequestId);
|
|
18095
18122
|
await api.execute("acknowledgeAgentCommand", {
|
|
@@ -18120,21 +18147,18 @@ async function runServerCommandIntake(options) {
|
|
|
18120
18147
|
};
|
|
18121
18148
|
const aborted = () => done(false);
|
|
18122
18149
|
wake = done;
|
|
18123
|
-
const timer = setTimeout(() => done(true), options.pollMs ?? 1e3);
|
|
18150
|
+
const timer = setTimeout(() => done(true), pushIntakeAcknowledged ? 6e4 : options.pollMs ?? 1e3);
|
|
18124
18151
|
signal?.addEventListener("abort", aborted, { once: true });
|
|
18125
18152
|
if (pending.size && !busy)
|
|
18126
18153
|
done(false);
|
|
18127
18154
|
});
|
|
18128
18155
|
if (signal?.aborted)
|
|
18129
18156
|
break;
|
|
18130
|
-
if (reconcile)
|
|
18131
|
-
|
|
18132
|
-
if (page.commandProtocol !== 1)
|
|
18133
|
-
throw new Error("server command protocol changed; refusing intake");
|
|
18134
|
-
notify2(page.commands);
|
|
18135
|
-
}
|
|
18157
|
+
if (reconcile)
|
|
18158
|
+
requestReconciliation();
|
|
18136
18159
|
}
|
|
18137
18160
|
} finally {
|
|
18161
|
+
stopped = true;
|
|
18138
18162
|
off?.();
|
|
18139
18163
|
options.onWake?.(void 0);
|
|
18140
18164
|
if (context.current)
|