toolroll 0.9.129 → 0.9.131
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 +44 -0
- package/dist/agent-fence.js +0 -2
- package/dist/agent-state.js +1 -1
- package/dist/agents-board.js +0 -3
- package/dist/assignment.js +4 -3
- package/dist/backup-ui.js +6 -3
- package/dist/bounded-spawn.js +0 -1
- package/dist/browser/manifest.json +57 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
- package/dist/browser/{terminal.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz +0 -0
- package/dist/browser/{workspace.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +25 -25
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
- package/dist/browser/{workspace.css → workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css} +1 -1
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.br +0 -0
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.gz +0 -0
- package/dist/browser-shell.js +271 -25
- package/dist/builder-restart.js +13 -4
- package/dist/builder.js +4 -1
- package/dist/canvas-freshness.js +122 -0
- package/dist/canvas-fs.js +273 -0
- package/dist/canvas-reads.js +747 -0
- package/dist/canvas-state-key.js +45 -0
- package/dist/canvas-state-worker.js +12 -0
- package/dist/central-recovery-stage.js +3 -3
- package/dist/chat-actions.js +26 -0
- package/dist/chat-channel.js +4 -3
- package/dist/chat-follow.js +4 -0
- package/dist/chat-task-actions.js +1 -1
- package/dist/chat-warmth.js +0 -1
- package/dist/check-report.js +0 -6
- package/dist/commit-extract.js +79 -40
- package/dist/companion/access.js +1 -0
- package/dist/companion/actions.js +79 -16
- package/dist/companion/canvas.js +141 -0
- package/dist/companion/chat-origin.js +92 -0
- package/dist/companion/chat.js +571 -0
- package/dist/companion/daemon.js +46 -5
- package/dist/companion/finish.js +51 -0
- package/dist/companion/reads.js +5 -1
- package/dist/companion/schema.js +64 -0
- package/dist/companion/service.js +1 -0
- package/dist/companion/store.js +1 -0
- package/dist/companion/webauthn.js +11 -2
- package/dist/console-instance.js +0 -4
- package/dist/contracts/console-api.js +1 -1
- package/dist/converse.js +0 -1
- package/dist/coordinator.js +1 -1
- package/dist/db-tuning.js +16 -0
- package/dist/desktop-config.js +156 -0
- package/dist/desktop-host.js +6 -152
- package/dist/desktop-update.js +1 -1
- package/dist/discord.js +9 -3
- package/dist/dispatch.js +32 -4
- package/dist/doctor.js +30 -0
- package/dist/evidence.js +49 -3
- package/dist/exec.js +3 -0
- package/dist/finished-task-sql.js +14 -0
- package/dist/flexible-answers.js +0 -1
- package/dist/git-views.js +7 -1
- package/dist/github-read.js +41 -0
- package/dist/guides.js +4 -3
- package/dist/invoke.js +12 -2
- package/dist/lead-doors.js +50 -3
- package/dist/lead-queue-runtime.js +18 -6
- package/dist/lead-queue.js +25 -0
- package/dist/lead-status.js +3 -3
- package/dist/live-backup-change.js +93 -0
- package/dist/live-backup.js +75 -31
- package/dist/live-bus.js +3 -2
- package/dist/live-records.js +0 -1
- package/dist/local-owner.js +0 -1
- package/dist/loop-recovery.js +40 -0
- package/dist/maintenance.js +29 -1
- package/dist/model-choices.js +0 -11
- package/dist/needs-you.js +2 -0
- package/dist/nightly-check.js +0 -3
- package/dist/nightly-github.js +1 -2
- package/dist/notification-retention.js +119 -0
- package/dist/observations.js +0 -1
- package/dist/operate.js +393 -56
- package/dist/planner.js +4 -1
- package/dist/pull-request-flow.js +56 -15
- package/dist/qr.js +0 -25
- package/dist/query-index-schema.js +10 -0
- package/dist/read-executor-worker.js +9 -7
- package/dist/read-executor.js +18 -1
- package/dist/read-worker-connection.js +7 -0
- package/dist/release-adapters.js +63 -48
- package/dist/release-auto.js +17 -13
- package/dist/release-card.js +0 -4
- package/dist/release-cli.js +58 -10
- package/dist/release-next.js +1 -1
- package/dist/release-stops.js +71 -0
- package/dist/release-supersede.js +125 -0
- package/dist/release-supervise.js +90 -0
- package/dist/release.js +265 -42
- package/dist/restore-retirement.js +4 -1
- package/dist/result-review.js +0 -3
- package/dist/retention-ui.js +1 -1
- package/dist/retention.js +14 -21
- package/dist/review-context.js +0 -5
- package/dist/route-rules.js +1 -5
- package/dist/runner.js +36 -1
- package/dist/sandbox-runtime.js +0 -1
- package/dist/scope.js +1 -13
- package/dist/scout.js +4 -7
- package/dist/serve.js +122 -12
- package/dist/server/kit.js +1 -0
- package/dist/server/live.js +9 -2
- package/dist/server/pages.js +3 -2
- package/dist/server/phone-engine-api.js +22 -2
- package/dist/server/render-pages.js +1 -11
- package/dist/server/render-results.js +0 -1
- package/dist/server/render-tasks.js +0 -68
- package/dist/server/route-table.js +1 -1
- package/dist/server/settings-phone.js +32 -9
- package/dist/server/settings-scripts.js +1 -1
- package/dist/server/settings-section-table.js +0 -3
- package/dist/server/settings-sections.js +4 -2
- package/dist/server/settings.js +20 -5
- package/dist/server/terminals.js +2 -1
- package/dist/shutdown-proof.js +29 -0
- package/dist/slack.js +9 -3
- package/dist/sqlite-telemetry.js +26 -14
- package/dist/statement-cache.js +137 -0
- package/dist/store.js +86 -14
- package/dist/structured-output.js +0 -1
- package/dist/style-asset.js +20 -7
- package/dist/tailnet.js +0 -3
- package/dist/task-control.js +5 -0
- package/dist/task-sizing.js +0 -1
- package/dist/task-status.js +1 -1
- package/dist/teams.js +9 -3
- package/dist/teardown-git.js +10 -1
- package/dist/telegram.js +4 -1
- package/dist/toolroll-update-cli.js +19 -3
- package/dist/toolroll-update-ui.js +2 -2
- package/dist/toolroll-update.js +95 -15
- package/dist/up-processes.js +16 -1
- package/dist/up-role-child.js +2 -0
- package/dist/wake-hub.js +15 -6
- package/dist/work-index.js +101 -44
- package/dist/work-reads.js +53 -9
- package/dist/work-snapshots.js +185 -0
- package/dist/worker-statement-cache.js +83 -0
- package/dist/workspace-revision.js +145 -21
- package/package.json +1 -1
- package/dist/companion/webauthn-test-support.js +0 -44
- package/dist/contracts/contract-test.js +0 -55
- package/dist/unfenced-test-support.js +0 -6
- /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { hkdfSync } from "node:crypto";
|
|
2
|
+
import { MAX_LOGICAL_UNARY_RESPONSE_BYTES } from "./framing.js";
|
|
3
|
+
import { canvasImagePiece, canvasList, canvasPins, canvasProjects, CanvasReadError, canvasScreenThumb } from "../canvas-reads.js";
|
|
4
|
+
import { storedTaskStatus } from "../flow-card-task.js";
|
|
5
|
+
import { STATUS_OF_HEADLINE } from "../youiyoux-intake.js";
|
|
6
|
+
import { requestContext } from "../server/request-context.js";
|
|
7
|
+
import { deviceAccountStands, getPairedDevice, readCompanionHostKeys } from "./store.js";
|
|
8
|
+
export const CANVAS_LIMITS = { perDevice: 4, global: 8, burst: 120, perSecond: 4 };
|
|
9
|
+
const standingRevoked = () => Object.assign(new Error("This iPhone is no longer paired."), { code: "standing_revoked" });
|
|
10
|
+
const busy = () => new CanvasReadError("busy", "Your Mac is busy with Canvas reads. Try again in a moment.");
|
|
11
|
+
export class CanvasLimiter {
|
|
12
|
+
limits;
|
|
13
|
+
nowMs;
|
|
14
|
+
inFlight = new Map();
|
|
15
|
+
buckets = new Map();
|
|
16
|
+
total = 0;
|
|
17
|
+
constructor(limits = {}, nowMs = Date.now) {
|
|
18
|
+
this.limits = { ...CANVAS_LIMITS, ...limits };
|
|
19
|
+
this.nowMs = nowMs;
|
|
20
|
+
}
|
|
21
|
+
get running() { return this.total; }
|
|
22
|
+
enter(device) {
|
|
23
|
+
const now = this.nowMs();
|
|
24
|
+
const bucket = this.buckets.get(device) ?? { tokens: this.limits.burst, at: now };
|
|
25
|
+
bucket.tokens = Math.min(this.limits.burst, bucket.tokens + (Math.max(0, now - bucket.at) / 1000) * this.limits.perSecond);
|
|
26
|
+
bucket.at = now;
|
|
27
|
+
this.buckets.set(device, bucket);
|
|
28
|
+
if (this.buckets.size > 256)
|
|
29
|
+
this.buckets.delete(this.buckets.keys().next().value);
|
|
30
|
+
if (bucket.tokens < 1 || this.total >= this.limits.global || (this.inFlight.get(device) ?? 0) >= this.limits.perDevice)
|
|
31
|
+
throw busy();
|
|
32
|
+
bucket.tokens -= 1;
|
|
33
|
+
this.total += 1;
|
|
34
|
+
this.inFlight.set(device, (this.inFlight.get(device) ?? 0) + 1);
|
|
35
|
+
let released = false;
|
|
36
|
+
return () => {
|
|
37
|
+
if (released)
|
|
38
|
+
return;
|
|
39
|
+
released = true;
|
|
40
|
+
this.total -= 1;
|
|
41
|
+
const left = (this.inFlight.get(device) ?? 1) - 1;
|
|
42
|
+
if (left <= 0)
|
|
43
|
+
this.inFlight.delete(device);
|
|
44
|
+
else
|
|
45
|
+
this.inFlight.set(device, left);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function canvasIdKey(store) {
|
|
50
|
+
const keys = readCompanionHostKeys(store.handle);
|
|
51
|
+
if (keys === null)
|
|
52
|
+
throw new CanvasReadError("unavailable", "Phone access isn't set up on this Mac.");
|
|
53
|
+
return Buffer.from(hkdfSync("sha256", keys.noiseStaticPriv, Buffer.from("toolroll canvas"), Buffer.from("project ids v1"), 32));
|
|
54
|
+
}
|
|
55
|
+
export function createCompanionCanvas(deps) {
|
|
56
|
+
const { runtime } = deps;
|
|
57
|
+
const store = runtime.store;
|
|
58
|
+
const limiter = new CanvasLimiter(deps.limits, deps.nowMs);
|
|
59
|
+
function stands(principal) {
|
|
60
|
+
const device = getPairedDevice(store.handle, principal.deviceId);
|
|
61
|
+
const identity = store.workspaceIdentity();
|
|
62
|
+
if (device === null || device.revokedAt !== null || device.activatedAt === null || device.recoveryGeneration !== identity.recoveryGeneration
|
|
63
|
+
|| device.accountName !== principal.accountName || identity.recoveryGeneration !== principal.recoveryGeneration)
|
|
64
|
+
return false;
|
|
65
|
+
return deviceAccountStands(device, store.accountOf(principal.accountName));
|
|
66
|
+
}
|
|
67
|
+
function scopeOf(principal) {
|
|
68
|
+
return {
|
|
69
|
+
candidates: () => [...store.listProjects().map(one => one.path), ...runtime.managedRepos()],
|
|
70
|
+
canSee: repo => runtime.visible(repo) && store.accountCanAccess(principal.accountName, repo),
|
|
71
|
+
idKey: canvasIdKey(store),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function readDeps(principal) {
|
|
75
|
+
return {
|
|
76
|
+
...deps.reads,
|
|
77
|
+
owner: principal.deviceId,
|
|
78
|
+
task: taskId => {
|
|
79
|
+
const family = runtime.familyOf(taskId);
|
|
80
|
+
const repo = family?.current.repo ?? null;
|
|
81
|
+
if (family === null || family.problem !== null || repo === null || !runtime.visible(repo) || !runtime.visible(family.root.repo)
|
|
82
|
+
|| !store.accountCanAccess(principal.accountName, repo))
|
|
83
|
+
return null;
|
|
84
|
+
const status = storedTaskStatus(store, family.current.id, repo, runtime.clock());
|
|
85
|
+
return { id: family.root.id, title: family.current.title, status: status === null ? null : STATUS_OF_HEADLINE[status.status.headline] };
|
|
86
|
+
},
|
|
87
|
+
filed: (repo, request) => {
|
|
88
|
+
const row = store.handle.prepare("SELECT task_id, status FROM youiyoux_request WHERE repo = ? AND request = ?").get(repo, request);
|
|
89
|
+
return row === undefined ? null : { taskId: row["task_id"] === null ? null : String(row["task_id"]), status: row["status"] === null ? null : String(row["status"]) };
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function asDevice(principal, work) {
|
|
94
|
+
if (!stands(principal))
|
|
95
|
+
throw standingRevoked();
|
|
96
|
+
const result = await requestContext.run({ csrf: "", returnTo: "/", actor: principal.accountName }, work);
|
|
97
|
+
if (!stands(principal))
|
|
98
|
+
throw standingRevoked();
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
async function read(principal, method, params) {
|
|
102
|
+
const scope = scopeOf(principal), reads = readDeps(principal);
|
|
103
|
+
switch (method) {
|
|
104
|
+
case "canvas.projects":
|
|
105
|
+
return { projects: canvasProjects(reads, scope) };
|
|
106
|
+
case "canvas.list":
|
|
107
|
+
return canvasList(reads, scope, params["project"]);
|
|
108
|
+
case "canvas.pins":
|
|
109
|
+
return canvasPins(reads, scope, { project: params["project"], screen: params["screen"] });
|
|
110
|
+
case "canvas.screen.thumb": {
|
|
111
|
+
const thumb = await canvasScreenThumb(reads, scope, { project: params["project"], screen: params["screen"], variant: params["variant"], key: params["key"] });
|
|
112
|
+
return { key: thumb.key, digest: thumb.digest, mime: thumb.mime, bytes: thumb.bytes.length, data: thumb.bytes.toString("base64") };
|
|
113
|
+
}
|
|
114
|
+
case "canvas.screen.image": {
|
|
115
|
+
const piece = canvasImagePiece(reads, scope, { project: params["project"], screen: params["screen"], variant: params["variant"], key: params["key"],
|
|
116
|
+
offset: params["offset"], length: params["length"] });
|
|
117
|
+
return { key: piece.key, digest: piece.digest, mime: piece.mime, offset: piece.offset, length: piece.length, total: piece.total, data: piece.data.toString("base64") };
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
throw new CanvasReadError("invalid_params", "Unknown Canvas read.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
call: async (principal, method, params) => {
|
|
125
|
+
const release = limiter.enter(principal.deviceId);
|
|
126
|
+
try {
|
|
127
|
+
const result = await asDevice(principal, () => read(principal, method, params));
|
|
128
|
+
if (Buffer.byteLength(JSON.stringify({ ok: true, result })) > MAX_LOGICAL_UNARY_RESPONSE_BYTES) {
|
|
129
|
+
throw new CanvasReadError("too_large", "That is too much to send to your phone at once.");
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
release();
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function withCompanionCanvas(reads, deps) {
|
|
140
|
+
return Object.assign(reads, { canvas: createCompanionCanvas(deps) });
|
|
141
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { deviceAccountStands, getPairedDevice } from "./store.js";
|
|
2
|
+
const readOrigin = (row) => ({
|
|
3
|
+
message: Number(row["message"]), deviceId: String(row["device_id"]), account: String(row["account"]),
|
|
4
|
+
accountGeneration: Number(row["account_generation"]), workspaceId: String(row["workspace_id"]),
|
|
5
|
+
recoveryGeneration: String(row["recovery_generation"]), idempotencyKey: String(row["idempotency_key"]),
|
|
6
|
+
requestHash: String(row["request_hash"]), session: Number(row["session"]), thread: Number(row["thread"]),
|
|
7
|
+
threadKey: String(row["thread_key"]), createdAt: String(row["created_at"]),
|
|
8
|
+
});
|
|
9
|
+
export function chatOriginOf(db, message) {
|
|
10
|
+
const row = db.prepare("SELECT * FROM companion_chat_origin WHERE message = ?").get(message);
|
|
11
|
+
return row === undefined ? null : readOrigin(row);
|
|
12
|
+
}
|
|
13
|
+
export function chatReceiptOf(db, deviceId, idempotencyKey) {
|
|
14
|
+
const row = db.prepare("SELECT * FROM companion_chat_origin WHERE device_id = ? AND idempotency_key = ?").get(deviceId, idempotencyKey);
|
|
15
|
+
return row === undefined ? null : readOrigin(row);
|
|
16
|
+
}
|
|
17
|
+
export function insertChatOrigin(db, origin) {
|
|
18
|
+
db.prepare(`INSERT INTO companion_chat_origin (message, device_id, account, account_generation, workspace_id, recovery_generation,
|
|
19
|
+
idempotency_key, request_hash, session, thread, thread_key, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
20
|
+
.run(origin.message, origin.deviceId, origin.account, origin.accountGeneration, origin.workspaceId, origin.recoveryGeneration, origin.idempotencyKey, origin.requestHash, origin.session, origin.thread, origin.threadKey, origin.createdAt);
|
|
21
|
+
}
|
|
22
|
+
export function chatKeysOf(db, deviceId, thread) {
|
|
23
|
+
return new Map(db.prepare("SELECT message, idempotency_key FROM companion_chat_origin WHERE device_id = ? AND thread = ?").all(deviceId, thread)
|
|
24
|
+
.map(row => [Number(row["message"]), String(row["idempotency_key"])]));
|
|
25
|
+
}
|
|
26
|
+
export function phoneOriginStands(store, message) {
|
|
27
|
+
try {
|
|
28
|
+
const origin = chatOriginOf(store.handle, message);
|
|
29
|
+
if (origin === null)
|
|
30
|
+
return false;
|
|
31
|
+
const device = getPairedDevice(store.handle, origin.deviceId);
|
|
32
|
+
const identity = store.workspaceIdentity();
|
|
33
|
+
if (device === null || device.revokedAt !== null || device.activatedAt === null)
|
|
34
|
+
return false;
|
|
35
|
+
if (device.accountName !== origin.account || device.accountGeneration !== origin.accountGeneration)
|
|
36
|
+
return false;
|
|
37
|
+
if (device.recoveryGeneration !== origin.recoveryGeneration || identity.recoveryGeneration !== origin.recoveryGeneration || identity.id !== origin.workspaceId)
|
|
38
|
+
return false;
|
|
39
|
+
return deviceAccountStands(device, store.accountOf(origin.account));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const PHONE_ORIGIN_GONE = "Not sent: this iPhone was removed or signed out before it ran.";
|
|
46
|
+
export const PHONE_RESTORED = "Not sent: Toolroll was restored from a backup before it ran.";
|
|
47
|
+
export function cancelPhoneWork(store, which, why, now) {
|
|
48
|
+
return store.transact(() => {
|
|
49
|
+
const rows = "all" in which
|
|
50
|
+
? store.handle.prepare("SELECT message, turn_id FROM lead_queue WHERE origin = 'phone' AND status IN ('queued','running')").all()
|
|
51
|
+
: "message" in which
|
|
52
|
+
? store.handle.prepare("SELECT message, turn_id FROM lead_queue WHERE origin = 'phone' AND status IN ('queued','running') AND message = ?").all(which.message)
|
|
53
|
+
: store.handle.prepare(`SELECT q.message, q.turn_id FROM lead_queue q JOIN companion_chat_origin o ON o.message = q.message
|
|
54
|
+
WHERE q.origin = 'phone' AND q.status IN ('queued','running') AND o.device_id = ?`).all(which.deviceId);
|
|
55
|
+
let cancelled = 0, ended = 0;
|
|
56
|
+
const stamp = now.toISOString();
|
|
57
|
+
for (const row of rows) {
|
|
58
|
+
const message = Number(row["message"]);
|
|
59
|
+
const turn = row["turn_id"] === null || row["turn_id"] === undefined ? null : Number(row["turn_id"]);
|
|
60
|
+
if (turn === null) {
|
|
61
|
+
store.handle.prepare("UPDATE lead_queue SET status = 'cancelled', error = ?, revision = revision + 1, settled_at = ? WHERE message = ? AND status IN ('queued','running')")
|
|
62
|
+
.run(why, stamp, message);
|
|
63
|
+
store.forgetQueuedLeadMessage(message);
|
|
64
|
+
cancelled++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const live = store.handle.prepare("SELECT session, reserved_microusd AS reserved FROM mate_turn WHERE id = ? AND state IN ('queued','running')").get(turn);
|
|
68
|
+
if (live !== undefined) {
|
|
69
|
+
store.handle.prepare("UPDATE mate_turn SET state = 'failed', failure_reason = 'revoked', generation = generation + 1, settled_microusd = ?, finished_at = ? WHERE id = ?")
|
|
70
|
+
.run(Number(live["reserved"]), stamp, turn);
|
|
71
|
+
store.handle.prepare("UPDATE lead_session SET spent_microusd = spent_microusd + ? WHERE id = ?").run(Number(live["reserved"]), Number(live["session"]));
|
|
72
|
+
store.discardLeadProposals(turn);
|
|
73
|
+
store.discardLeadTurnEvidence(turn);
|
|
74
|
+
}
|
|
75
|
+
store.handle.prepare("UPDATE lead_queue SET status = 'failed', error = ?, revision = revision + 1, settled_at = ? WHERE message = ? AND status = 'running'")
|
|
76
|
+
.run(why, stamp, message);
|
|
77
|
+
ended++;
|
|
78
|
+
}
|
|
79
|
+
return { cancelled, ended };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export function cancelFallenPhoneWork(store, now) {
|
|
83
|
+
let ended = 0;
|
|
84
|
+
for (const row of store.handle.prepare("SELECT message FROM lead_queue WHERE origin = 'phone' AND status IN ('queued','running')").all()) {
|
|
85
|
+
const message = Number(row["message"]);
|
|
86
|
+
if (phoneOriginStands(store, message))
|
|
87
|
+
continue;
|
|
88
|
+
const done = cancelPhoneWork(store, { message }, PHONE_ORIGIN_GONE, now);
|
|
89
|
+
ended += done.cancelled + done.ended;
|
|
90
|
+
}
|
|
91
|
+
return ended;
|
|
92
|
+
}
|