@capybara-hq/kernel 0.1.0-rc.80 → 0.1.0-rc.82
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/bootstrap.json +29 -29
- package/dist/admin/outbox-dead.service.js +133 -120
- package/dist/background/store.js +78 -67
- package/dist/background/tasks.service.d.ts +6 -0
- package/dist/background/tasks.service.js +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-import.js +45 -40
- package/dist/catalog/scope-sync-workers.js +3 -0
- package/dist/channels/inbound.d.ts +6 -1
- package/dist/channels/inbound.js +18 -1
- package/dist/client/client-reports.service.js +9 -6
- package/dist/config/schema.d.ts +5 -0
- package/dist/config/schema.js +6 -0
- package/dist/conversations/attachments.service.js +101 -96
- package/dist/conversations/events.d.ts +7 -0
- package/dist/conversations/events.js +9 -0
- package/dist/ctx/bus.js +5 -3
- package/dist/ctx/queue.js +4 -2
- package/dist/db/pool.d.ts +6 -0
- package/dist/db/pool.js +3 -2
- package/dist/devices/legacy-cleanup.job.js +73 -70
- package/dist/dial-in/gateway.d.ts +8 -0
- package/dist/dial-in/gateway.js +22 -2
- package/dist/extensions/admin-ops.js +22 -19
- package/dist/extensions/lifecycle-hooks.js +3 -1
- package/dist/http/app.js +3 -1
- package/dist/http/plugin-dispatch.js +8 -0
- package/dist/identity/auth.guard.js +13 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/database/org-scope.d.ts +59 -0
- package/dist/infra/database/org-scope.js +68 -0
- package/dist/infra/database/rls-role.d.ts +11 -0
- package/dist/infra/database/rls-role.js +33 -0
- package/dist/infra/database/scoped-dialect.d.ts +18 -0
- package/dist/infra/database/scoped-dialect.js +245 -0
- package/dist/infra/outbox/outbox.dispatcher.js +98 -90
- package/dist/infra/outbox/outbox.service.js +29 -26
- package/dist/infra/queue/run-job.d.ts +8 -2
- package/dist/infra/queue/run-job.js +16 -3
- package/dist/infra/schedule/locked-tick.js +12 -4
- package/dist/infra/schedule/scheduled-runs.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.d.ts +1 -0
- package/dist/lifecycle/kernel-lifecycle.js +16 -1
- package/dist/orgs/org.guard.js +4 -0
- package/dist/platform/sealed-reveals.js +9 -6
- package/dist/runtime/maintenance.js +6 -1
- package/dist/runtime/run-execution.d.ts +1 -0
- package/dist/runtime/run-execution.js +5 -0
- package/dist/runtime/run-orphan-check.job.js +20 -15
- package/dist/sandbox/legacy-retirement.js +438 -397
- package/dist/sandbox/modes.d.ts +10 -0
- package/dist/sandbox/modes.js +23 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +14 -1
- package/dist/sandbox/operation-reconcile.job.js +35 -3
- package/dist/sandbox/permission-config-publication.js +83 -77
- package/dist/sandbox/sandbox.service.d.ts +24 -0
- package/dist/sandbox/sandbox.service.js +159 -62
- package/dist/schedules/store.js +17 -14
- package/dist/tools/builtins/sandbox/bash.js +16 -1
- package/dist/tools/drift.js +31 -24
- package/dist/tools/outputs.js +20 -17
- package/package.json +2 -2
- package/src/migrations/0182_rls_policies.sql +202 -0
package/bootstrap.json
CHANGED
|
@@ -3,103 +3,103 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"marketplace": {
|
|
5
5
|
"url": "https://github.com/capybara-hq/plugins.git",
|
|
6
|
-
"commit": "
|
|
6
|
+
"commit": "727f62bd821702a1b9d6ce0fb672d998dbb9d6d5"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
10
10
|
"name": "openai-compatible",
|
|
11
11
|
"source": "npm",
|
|
12
12
|
"npm": "@capybara-hq/plugin-openai-compatible",
|
|
13
|
-
"version": "0.1.0-rc.
|
|
14
|
-
"integrity": "sha512-
|
|
13
|
+
"version": "0.1.0-rc.12",
|
|
14
|
+
"integrity": "sha512-4bO5W4xw97s1SPCfgWunqNzCiCoUUE35YdGX9GX+0CJ8bBRLQDZi6XaYHvOt1qZ+zQdwh8gRl9ILavwn4prEEw==",
|
|
15
15
|
"required": false
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"name": "object-store-s3",
|
|
19
19
|
"source": "npm",
|
|
20
20
|
"npm": "@capybara-hq/plugin-object-store-s3",
|
|
21
|
-
"version": "0.1.0-rc.
|
|
22
|
-
"integrity": "sha512-
|
|
21
|
+
"version": "0.1.0-rc.12",
|
|
22
|
+
"integrity": "sha512-hPKfoH25RbEB8aA/Feqwfvbs2OR6B/MrXfj1DngBWEhSYvBoPfcezEC+LJDr35nRmfzsnqLc+Ho9Y4pT02tcyw==",
|
|
23
23
|
"required": true
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"name": "anthropic",
|
|
27
27
|
"source": "npm",
|
|
28
28
|
"npm": "@capybara-hq/plugin-anthropic",
|
|
29
|
-
"version": "0.1.0-rc.
|
|
30
|
-
"integrity": "sha512-
|
|
29
|
+
"version": "0.1.0-rc.10",
|
|
30
|
+
"integrity": "sha512-fOZuAzmJLRdHj/IwsVA71jyu45FmK3VSQYKlOZk6JYv6WbCX5cUrieduN+PGHwszFysQ4QxFj4XQ23QltQMh+g==",
|
|
31
31
|
"required": false
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
"name": "openai",
|
|
35
35
|
"source": "npm",
|
|
36
36
|
"npm": "@capybara-hq/plugin-openai",
|
|
37
|
-
"version": "0.1.0-rc.
|
|
38
|
-
"integrity": "sha512-
|
|
37
|
+
"version": "0.1.0-rc.12",
|
|
38
|
+
"integrity": "sha512-bh4ydAdf7cJwod2crmd6q9mbAFYULtoSXm/FAWf5xOUvwfYCo6OWY+JD5fQGNZQDuD+0MV3wQbvSpYBA2/poNQ==",
|
|
39
39
|
"required": false
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"name": "deepseek",
|
|
43
43
|
"source": "npm",
|
|
44
44
|
"npm": "@capybara-hq/plugin-deepseek",
|
|
45
|
-
"version": "0.1.0-rc.
|
|
46
|
-
"integrity": "sha512-
|
|
45
|
+
"version": "0.1.0-rc.11",
|
|
46
|
+
"integrity": "sha512-AUgib6r+8sdNEu9Fs8NvatbYTe/eihW3Zo6zILzTIUxgCHRkvIJ/QKoWcH4O32gaiyvlsmYBocIlD3m0ntUhyA==",
|
|
47
47
|
"required": false
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
"name": "bailian",
|
|
51
51
|
"source": "npm",
|
|
52
52
|
"npm": "@capybara-hq/plugin-bailian",
|
|
53
|
-
"version": "0.1.0-rc.
|
|
54
|
-
"integrity": "sha512-
|
|
53
|
+
"version": "0.1.0-rc.11",
|
|
54
|
+
"integrity": "sha512-3LYmVw1KQL6qXYgU7XeymBvnRRZy8PM5OIP5CeUtypqMkBXHo1wR8leuwucLLLpRR5EgTJOWMdZNx5D99fp+rw==",
|
|
55
55
|
"required": false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"name": "ark",
|
|
59
59
|
"source": "npm",
|
|
60
60
|
"npm": "@capybara-hq/plugin-ark",
|
|
61
|
-
"version": "0.1.0-rc.
|
|
62
|
-
"integrity": "sha512-
|
|
61
|
+
"version": "0.1.0-rc.12",
|
|
62
|
+
"integrity": "sha512-8yrnD2AKpsqT7RKrokyH95xW8z8un5z4c3rgsxtgW49kVZ9Y+rOpsf+mNGW/XM/rEATSvQTj3LMPDBGPPZdPyw==",
|
|
63
63
|
"required": false
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
"name": "connector-mcp",
|
|
67
67
|
"source": "npm",
|
|
68
68
|
"npm": "@capybara-hq/plugin-connector-mcp",
|
|
69
|
-
"version": "0.1.0-rc.
|
|
70
|
-
"integrity": "sha512-
|
|
69
|
+
"version": "0.1.0-rc.12",
|
|
70
|
+
"integrity": "sha512-AMUljGAoaFN8NZo5A6vkAz+PYF0QooqBPCz+OThLHjFZhej1qhYkwNqDkQU8DQKpVLhQ/Z0dUg8OprSnGMtGsw==",
|
|
71
71
|
"required": false
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
"name": "connector-openapi",
|
|
75
75
|
"source": "npm",
|
|
76
76
|
"npm": "@capybara-hq/plugin-connector-openapi",
|
|
77
|
-
"version": "0.1.0-rc.
|
|
78
|
-
"integrity": "sha512-
|
|
77
|
+
"version": "0.1.0-rc.13",
|
|
78
|
+
"integrity": "sha512-3kI76wL9WL8dPkjLxpXliRzQzI66Xs2fp/mYT6t5svCobJpoan/b6X72h46TeDO9SsXiT+5X9licvRxwSWf6Sw==",
|
|
79
79
|
"required": false
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"name": "jina",
|
|
83
83
|
"source": "npm",
|
|
84
84
|
"npm": "@capybara-hq/plugin-jina",
|
|
85
|
-
"version": "0.1.0-rc.
|
|
86
|
-
"integrity": "sha512-
|
|
85
|
+
"version": "0.1.0-rc.10",
|
|
86
|
+
"integrity": "sha512-Sxsg2qMz//QcZMqRCGvK7o8CqFDS5XMXpESmiyJasCoNYRE/cb/Q7v4XcSIc/WXccVTN9kWUBPJDU6c6gpiAjA==",
|
|
87
87
|
"required": false
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
90
|
"name": "device-docker",
|
|
91
91
|
"source": "npm",
|
|
92
92
|
"npm": "@capybara-hq/plugin-device-docker",
|
|
93
|
-
"version": "0.1.0-rc.
|
|
94
|
-
"integrity": "sha512-
|
|
93
|
+
"version": "0.1.0-rc.28",
|
|
94
|
+
"integrity": "sha512-AMmRgf+D8Aap5RKdrhNvPH+1ItvTtQohOCzr6B0xaSzOYD78BbYZxKniOZzEqphGxOymoZe+LCqfTSnKGdKRWg==",
|
|
95
95
|
"required": false
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
"name": "device-local",
|
|
99
99
|
"source": "npm",
|
|
100
100
|
"npm": "@capybara-hq/plugin-device-local",
|
|
101
|
-
"version": "0.1.0-rc.
|
|
102
|
-
"integrity": "sha512-
|
|
101
|
+
"version": "0.1.0-rc.8",
|
|
102
|
+
"integrity": "sha512-TA84YgBO3gpzZUumpR3ZdwFVa1Vytre9oaDWslFN9J3tE4ch3F1HdDKCstNgxhgogwHRLAyy6nwOIiGn7XXurw==",
|
|
103
103
|
"required": false,
|
|
104
104
|
"scope": "all"
|
|
105
105
|
},
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"name": "todo",
|
|
108
108
|
"source": "npm",
|
|
109
109
|
"npm": "@capybara-hq/plugin-todo",
|
|
110
|
-
"version": "0.1.0-rc.
|
|
111
|
-
"integrity": "sha512-
|
|
110
|
+
"version": "0.1.0-rc.13",
|
|
111
|
+
"integrity": "sha512-QApBFqo6PrFJlmR7Pokbkx6AmLZ8dIGApl+EneshGw6dpJbDYvyUaoRyvk2Os1pYyfQOTHnCc0FUEae5mrVj6g==",
|
|
112
112
|
"required": false
|
|
113
113
|
},
|
|
114
114
|
{
|
|
@@ -124,8 +124,8 @@
|
|
|
124
124
|
"name": "file-preview",
|
|
125
125
|
"source": "npm",
|
|
126
126
|
"npm": "@capybara-hq/plugin-file-preview",
|
|
127
|
-
"version": "0.1.0-rc.
|
|
128
|
-
"integrity": "sha512-
|
|
127
|
+
"version": "0.1.0-rc.4",
|
|
128
|
+
"integrity": "sha512-TBIUsqB2ZNpKPc8ddBh9e2KdT9SV/+ZNSBYqrDRv8SazVmN3q7lgbVk5QaiLioI2EPt5Kfs4DSY+YIrKlzwCcA==",
|
|
129
129
|
"required": false,
|
|
130
130
|
"builtin": true
|
|
131
131
|
}
|
|
@@ -14,6 +14,7 @@ import { audit } from "../identity/audit.js";
|
|
|
14
14
|
import { SuperAdminLock } from "../identity/super-admin.js";
|
|
15
15
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
16
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
17
18
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
18
19
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
20
|
import { OUTBOX_FAST_PATH } from "../infra/outbox/outbox.service.js";
|
|
@@ -48,62 +49,66 @@ let OutboxDeadService = class OutboxDeadService {
|
|
|
48
49
|
* first by `(dead_at, id)`; one extra row tells `next`. A malformed cursor is a validation error.
|
|
49
50
|
*/
|
|
50
51
|
async list(q = {}) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
52
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
53
|
+
const limit = Math.min(q.limit ?? OUTBOX_DEAD_LIST_MAX, OUTBOX_DEAD_LIST_MAX);
|
|
54
|
+
const cursor = q.after === undefined ? null : decodeOutboxDeadCursor(q.after);
|
|
55
|
+
if (q.after !== undefined && cursor === null) {
|
|
56
|
+
throw new ApiError("validation_failed", "after must be a cursor from a previous page");
|
|
57
|
+
}
|
|
58
|
+
let query = this.db.db
|
|
59
|
+
.selectFrom("outbox")
|
|
60
|
+
.select([
|
|
61
|
+
"id",
|
|
62
|
+
"queue",
|
|
63
|
+
"job_name",
|
|
64
|
+
"job_id",
|
|
65
|
+
"org_id",
|
|
66
|
+
"attempts",
|
|
67
|
+
"last_error",
|
|
68
|
+
"dead_at",
|
|
69
|
+
"created_at",
|
|
70
|
+
// PG's own text keeps the microseconds a JS Date would cut
|
|
71
|
+
sql `dead_at::text`.as("dead_at_text"),
|
|
72
|
+
])
|
|
73
|
+
.where("dead_at", "is not", null);
|
|
74
|
+
if (cursor !== null) {
|
|
75
|
+
query = query.where(sql `(dead_at, id) > (${cursor.deadAt}::timestamptz, ${cursor.id}::bigint)`);
|
|
76
|
+
}
|
|
77
|
+
const rows = await query
|
|
78
|
+
.orderBy("dead_at")
|
|
79
|
+
.orderBy("id")
|
|
80
|
+
.limit(limit + 1)
|
|
81
|
+
.execute();
|
|
82
|
+
const page = rows.slice(0, limit);
|
|
83
|
+
const last = page.at(-1);
|
|
84
|
+
return {
|
|
85
|
+
next: rows.length > limit && last !== undefined
|
|
86
|
+
? encodeOutboxDeadCursor({ deadAt: last.dead_at_text, id: String(last.id) })
|
|
87
|
+
: null,
|
|
88
|
+
items: page.map((r) => ({
|
|
89
|
+
id: String(r.id),
|
|
90
|
+
queue: r.queue,
|
|
91
|
+
jobName: r.job_name,
|
|
92
|
+
jobId: r.job_id,
|
|
93
|
+
orgId: r.org_id,
|
|
94
|
+
attempts: r.attempts,
|
|
95
|
+
lastError: r.last_error,
|
|
96
|
+
deadAt: r.dead_at.toISOString(),
|
|
97
|
+
createdAt: r.created_at.toISOString(),
|
|
98
|
+
})),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
98
101
|
}
|
|
99
102
|
/** How many rows are dead, and the oldest one's `dead_at`. */
|
|
100
103
|
async summary() {
|
|
101
|
-
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
105
|
+
const row = await this.db.db
|
|
106
|
+
.selectFrom("outbox")
|
|
107
|
+
.select([sql `count(*)`.as("count"), sql `min(dead_at)`.as("oldest")])
|
|
108
|
+
.where("dead_at", "is not", null)
|
|
109
|
+
.executeTakeFirstOrThrow();
|
|
110
|
+
return { count: Number(row.count), oldestAt: row.oldest };
|
|
111
|
+
});
|
|
107
112
|
}
|
|
108
113
|
/**
|
|
109
114
|
* Makes a dead row due again (`dead_at` cleared, no attempts, next attempt now) and hands it to
|
|
@@ -132,82 +137,90 @@ let OutboxDeadService = class OutboxDeadService {
|
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
async retryOnce(id, actor, detail) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
140
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
141
|
+
await this.adminLock.lockAndAuthorize(actor.accountId);
|
|
142
|
+
await this.lockRunRetryIn(id);
|
|
143
|
+
const row = await this.lockDead(id);
|
|
144
|
+
const owed = await this.db.db
|
|
145
|
+
.selectFrom("outbox")
|
|
146
|
+
.select("id")
|
|
147
|
+
.where("queue", "=", row.queue)
|
|
148
|
+
.where("job_id", "=", row.job_id)
|
|
149
|
+
.where("dead_at", "is", null)
|
|
150
|
+
.executeTakeFirst();
|
|
151
|
+
let outcome;
|
|
152
|
+
if (owed) {
|
|
153
|
+
await this.db.db.deleteFrom("outbox").where("id", "=", id).execute();
|
|
154
|
+
outcome = "already_owed";
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
await this.db.db
|
|
158
|
+
.updateTable("outbox")
|
|
159
|
+
.set({ dead_at: null, attempts: 0, next_attempt_at: sql `now()` })
|
|
160
|
+
.where("id", "=", id)
|
|
161
|
+
.execute();
|
|
162
|
+
outcome = "retried";
|
|
163
|
+
afterCommit(() => this.fastPath([id]));
|
|
164
|
+
}
|
|
165
|
+
await this.audit("outbox.retried", id, row, actor, { ...detail, outcome });
|
|
166
|
+
return { outcome };
|
|
167
|
+
});
|
|
161
168
|
}
|
|
162
169
|
/** A run-job retry is a new delivery generation, serialized with its terminal transition. */
|
|
163
170
|
async lockRunRetryIn(id) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
171
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
172
|
+
// Read before taking any outbox lock: the lock order is conversation, then outbox. The
|
|
173
|
+
// subsequent lockDead rechecks this row, so a concurrent discard/retry rolls this back.
|
|
174
|
+
const row = await this.db
|
|
175
|
+
.selectFrom("outbox")
|
|
176
|
+
.select(["job_name", "job_id", "data"])
|
|
177
|
+
.where("id", "=", id)
|
|
178
|
+
.where("dead_at", "is not", null)
|
|
179
|
+
.executeTakeFirst();
|
|
180
|
+
if (row?.job_name !== "run" || row.data === null || typeof row.data !== "object")
|
|
181
|
+
return;
|
|
182
|
+
const data = row.data;
|
|
183
|
+
if (typeof data.conversationId !== "string" || typeof data.runId !== "string")
|
|
184
|
+
return;
|
|
185
|
+
await this.db
|
|
186
|
+
.selectFrom("conversations")
|
|
187
|
+
.select("id")
|
|
188
|
+
.where("id", "=", data.conversationId)
|
|
189
|
+
.forUpdate()
|
|
190
|
+
.execute();
|
|
191
|
+
await this.db
|
|
192
|
+
.updateTable("runs")
|
|
193
|
+
.set({ queued_at: sql `clock_timestamp()` })
|
|
194
|
+
.where("id", "=", data.runId)
|
|
195
|
+
.where("conversation_id", "=", data.conversationId)
|
|
196
|
+
.where("status", "=", "queued")
|
|
197
|
+
.where(sql `COALESCE(job_id, 'run-' || conversation_id || '-' || trigger_seq::text) = ${row.job_id}`)
|
|
198
|
+
.execute();
|
|
199
|
+
});
|
|
191
200
|
}
|
|
192
201
|
/** Deletes a dead row: its job is never delivered. `outbox.not_found` (404) when none. */
|
|
193
202
|
async discard(id, actor, detail = {}) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
204
|
+
await this.adminLock.lockAndAuthorize(actor.accountId);
|
|
205
|
+
const row = await this.lockDead(id);
|
|
206
|
+
await this.db.db.deleteFrom("outbox").where("id", "=", id).execute();
|
|
207
|
+
await this.audit("outbox.discarded", id, row, actor, detail);
|
|
208
|
+
});
|
|
198
209
|
}
|
|
199
210
|
/** The dead row `id`, locked for the transaction; `outbox.not_found` when it is not dead. */
|
|
200
211
|
async lockDead(id) {
|
|
201
|
-
|
|
202
|
-
.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
return asPlatform("super admin: the dead outbox rows of every org", async () => {
|
|
213
|
+
const row = await this.db.db
|
|
214
|
+
.selectFrom("outbox")
|
|
215
|
+
.select(["queue", "job_name", "job_id", "org_id", "attempts", "last_error"])
|
|
216
|
+
.where("id", "=", id)
|
|
217
|
+
.where("dead_at", "is not", null)
|
|
218
|
+
.forUpdate()
|
|
219
|
+
.executeTakeFirst();
|
|
220
|
+
if (!row)
|
|
221
|
+
throw notFound(id);
|
|
222
|
+
return row;
|
|
223
|
+
});
|
|
211
224
|
}
|
|
212
225
|
/**
|
|
213
226
|
* A platform-level audit event (no org: the outbox is the deployment's), naming the job. The
|