@opennous/cli 0.17.1 → 0.18.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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/index.js +7 -2
- package/src/runner.js +28 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @opennous/cli changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Changed: one command sets everything up, and the runner is quiet when idle
|
|
6
|
+
|
|
7
|
+
`runner install` is the only command you need: with no history read yet, the runner starts that read
|
|
8
|
+
itself (six months, on your plan), then keeps everything new current. Idle, it checks in about once a
|
|
9
|
+
minute and still picks up new work within seconds. `runner uninstall` tells Ownable this machine
|
|
10
|
+
stopped, so with no runner left your reading goes back to credits (GET-1307).
|
|
11
|
+
|
|
3
12
|
## 0.17.1
|
|
4
13
|
|
|
5
14
|
### Fixed: a sign-out or an outage no longer fails your reads
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -154,6 +154,7 @@ function apiClient(key) {
|
|
|
154
154
|
get: (path, query) => request("GET", path, { query }),
|
|
155
155
|
post: (path, body) => request("POST", path, { body }),
|
|
156
156
|
softPost: (path, body) => request("POST", path, { body, soft: true }),
|
|
157
|
+
softDelete: (path, body) => request("DELETE", path, { body, soft: true }),
|
|
157
158
|
};
|
|
158
159
|
}
|
|
159
160
|
|
|
@@ -673,6 +674,7 @@ const runnerCmd = program
|
|
|
673
674
|
api: {
|
|
674
675
|
poll: (body) => api.softPost("/v2/runner/poll", body),
|
|
675
676
|
answer: (id, body) => api.softPost(`/v2/runner/calls/${id}`, body),
|
|
677
|
+
startBackfill: (body) => api.softPost("/v2/backfill/own", body),
|
|
676
678
|
},
|
|
677
679
|
});
|
|
678
680
|
});
|
|
@@ -697,7 +699,7 @@ runnerCmd
|
|
|
697
699
|
}
|
|
698
700
|
try {
|
|
699
701
|
const where = installService({ agent, workspace: opts.workspace ?? null });
|
|
700
|
-
console.log(`Connected.
|
|
702
|
+
console.log(`Connected. Your calls and email are read on your ${agent} plan: your history first, then everything new. It starts every time you log in.`);
|
|
701
703
|
if (where.log) console.log(`Log: ${where.log}`);
|
|
702
704
|
console.log("Check on it with `npx @opennous/cli@latest runner status`. Stop it with `npx @opennous/cli@latest runner uninstall`.");
|
|
703
705
|
} catch (e) {
|
|
@@ -711,7 +713,10 @@ runnerCmd
|
|
|
711
713
|
.description("Stop the runner and stop it starting at login")
|
|
712
714
|
.action(async () => {
|
|
713
715
|
const { uninstallService } = await import("./runner.js");
|
|
714
|
-
|
|
716
|
+
const removed = uninstallService();
|
|
717
|
+
// The server stops waiting on this machine (GET-1307): with no runner left, your reading goes back to credits.
|
|
718
|
+
if (hasKey()) await apiClient().softDelete("/v2/runner", { host: hostname() }).catch(() => {});
|
|
719
|
+
console.log(removed ? "Stopped. It won't start at login any more, and your reading is back on credits unless another machine runs it." : "No runner is installed on this machine.");
|
|
715
720
|
});
|
|
716
721
|
|
|
717
722
|
runnerCmd
|
package/src/runner.js
CHANGED
|
@@ -11,10 +11,17 @@ import { dirname, join } from "node:path";
|
|
|
11
11
|
import { commandFor, parseAnswer, troubleOf, resetAt } from "./backfill.js";
|
|
12
12
|
|
|
13
13
|
export const WORKERS = 3;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* How long the server may hold a poll open waiting for a call (GET-1307). Idle, the runner checks in
|
|
16
|
+
* about once a minute and still picks up a new call within seconds.
|
|
17
|
+
*/
|
|
18
|
+
export const WAIT_MS = 45_000;
|
|
19
|
+
/** A server that answers at once (one without long polls): ask again after this. */
|
|
15
20
|
export const BUSY_MS = 2000;
|
|
16
|
-
/** Idle: nothing going. A heartbeat still has to land well inside the server's two minutes. */
|
|
17
21
|
export const IDLE_MS = 20_000;
|
|
22
|
+
/** A history read the runner started that the server could not start yet: try again after this. */
|
|
23
|
+
export const BACKFILL_RETRY_MS = 30 * 60_000;
|
|
24
|
+
export const BACKFILL_DAYS = 180;
|
|
18
25
|
/** At the plan's limit: take nothing, keep the heartbeat. */
|
|
19
26
|
export const LIMITED_POLL_MS = 60_000;
|
|
20
27
|
/** A limit whose message gives no reset time is tried again after this. */
|
|
@@ -53,7 +60,7 @@ export function pauseLine(agent, reason, until, now = Date.now()) {
|
|
|
53
60
|
*/
|
|
54
61
|
export async function runRunner({ api, agent, host = hostname(), version = null, run, sleep, log, now = Date.now,
|
|
55
62
|
workers = WORKERS, limitWaitMs = LIMIT_WAIT_MS, stop = () => false }) {
|
|
56
|
-
let limitedUntil = 0, limitReason = null, answered = 0, lastLine = null, lastError = null,
|
|
63
|
+
let limitedUntil = 0, limitReason = null, answered = 0, lastLine = null, lastError = null, backfillAt = -Infinity;
|
|
57
64
|
const answerOne = async (call, models) => {
|
|
58
65
|
for (let attempt = 0; ; attempt++) {
|
|
59
66
|
try {
|
|
@@ -80,8 +87,9 @@ export async function runRunner({ api, agent, host = hostname(), version = null,
|
|
|
80
87
|
};
|
|
81
88
|
while (!stop()) {
|
|
82
89
|
let page;
|
|
90
|
+
const asked = now();
|
|
83
91
|
try {
|
|
84
|
-
page = await api.poll({ agent, host, version, answered, limit: workers,
|
|
92
|
+
page = await api.poll({ agent, host, version, answered, limit: workers, wait_ms: WAIT_MS,
|
|
85
93
|
limited_until: limitedUntil > now() ? new Date(limitedUntil).toISOString() : null,
|
|
86
94
|
limit_reason: limitedUntil > now() ? limitReason : null });
|
|
87
95
|
if (lastError) { log("Back online."); lastError = null; }
|
|
@@ -91,15 +99,27 @@ export async function runRunner({ api, agent, host = hostname(), version = null,
|
|
|
91
99
|
await sleep(ERROR_BACKOFF_MS);
|
|
92
100
|
continue;
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
// One command sets everything up (GET-1307): with no history read yet, the runner starts that
|
|
103
|
+
// read itself, on this plan, and answers its calls like any other.
|
|
104
|
+
if (page.needs_backfill && api.startBackfill && now() - backfillAt >= BACKFILL_RETRY_MS) {
|
|
105
|
+
backfillAt = now();
|
|
106
|
+
try {
|
|
107
|
+
await api.startBackfill({ days: BACKFILL_DAYS, confirm: "yes" });
|
|
108
|
+
log(`Reading your last ${BACKFILL_DAYS / 30} months of calls and email on your plan. This can take a while; everything new is read after.`);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
log(`Your history read can't start yet (${err.message}). Trying again in ${BACKFILL_RETRY_MS / 60000} minutes.`);
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
113
|
const line = readingLine(page.reading);
|
|
99
114
|
if (line && line !== lastLine) { log(line); }
|
|
100
115
|
lastLine = line;
|
|
101
116
|
const calls = page.calls ?? [];
|
|
102
|
-
if (!calls.length) {
|
|
117
|
+
if (!calls.length) {
|
|
118
|
+
if (limitedUntil > now()) { await sleep(LIMITED_POLL_MS); continue; }
|
|
119
|
+
// The server held the poll open: ask again at once. One that answered at once: wait a little.
|
|
120
|
+
if (now() - asked < 5000) await sleep(page.reading ? BUSY_MS : IDLE_MS);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
103
123
|
await Promise.all(calls.map((c) => answerOne(c, page.models)));
|
|
104
124
|
}
|
|
105
125
|
return { answered };
|