@flytedesk/app-kit 16.2.0 → 16.4.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/README.md +134 -19
- package/dist/chat/owed-replies/constants.d.ts +31 -5
- package/dist/chat/owed-replies/constants.js +41 -11
- package/dist/chat/owed-replies/constants.js.map +1 -1
- package/dist/chat/owed-replies/index.d.ts +5 -4
- package/dist/chat/owed-replies/index.js +1 -1
- package/dist/chat/owed-replies/index.js.map +1 -1
- package/dist/chat/owed-replies/plugin.d.ts +10 -5
- package/dist/chat/owed-replies/plugin.js +13 -5
- package/dist/chat/owed-replies/plugin.js.map +1 -1
- package/dist/chat/owed-replies/state.d.ts +25 -1
- package/dist/chat/owed-replies/state.js +8 -1
- package/dist/chat/owed-replies/state.js.map +1 -1
- package/dist/chat/owed-replies/store.d.ts +146 -9
- package/dist/chat/owed-replies/store.js +367 -64
- package/dist/chat/owed-replies/store.js.map +1 -1
- package/dist/chat/owed-replies/tool.d.ts +16 -4
- package/dist/chat/owed-replies/tool.js +22 -6
- package/dist/chat/owed-replies/tool.js.map +1 -1
- package/dist/chat/tools/index.d.ts +15 -9
- package/dist/chat/tools/index.js +11 -13
- package/dist/chat/tools/index.js.map +1 -1
- package/package.json +1 -1
- package/prisma/fragments/owed-reply.meta.json +1 -1
- package/prisma/fragments/owed-reply.prisma +24 -4
- package/prisma/migrations/0007_app_kit_owed_reply_holds/migration.sql +39 -0
- package/prisma/migrations/manifest.json +7 -0
|
@@ -4,18 +4,34 @@
|
|
|
4
4
|
* `owed-reply-sync init`).
|
|
5
5
|
*
|
|
6
6
|
* A person's message is owed an answer until the agent's run writes it through the reply
|
|
7
|
-
* tool. The store gives the app
|
|
7
|
+
* tool. The store gives the app these operations around a run:
|
|
8
8
|
* receiveMessage the message arrives; idempotent on its ref
|
|
9
9
|
* claimForDispatch the app asks Flytebot for a run; binds every `sent` owed reply of the
|
|
10
10
|
* conversation to that run's dispatch id
|
|
11
|
-
* settle the run ended (the terminal webhook
|
|
12
|
-
* unanswered fails with one fixed line
|
|
11
|
+
* settle the run ended (the terminal webhook, or a run that never started);
|
|
12
|
+
* every owed reply it left unanswered fails with one fixed line, except
|
|
13
|
+
* a held one when the run completed
|
|
14
|
+
* withdraw Flytebot would not start the run yet; the dispatch is taken back
|
|
15
|
+
* stop the person stopped the conversation; every unanswered reply fails
|
|
13
16
|
* and `writeReply`, which the reply tool calls (see tool.ts).
|
|
14
17
|
*
|
|
18
|
+
* An app never reads or writes the tables itself (AK-86): `ofMessages`, `ofConversation` and
|
|
19
|
+
* `hasWaiting` read (and take no lock), `discard` deletes the owed reply of a message no dispatch
|
|
20
|
+
* currently holds, and `deleteConversation` removes conversations' owed replies; both lock the
|
|
21
|
+
* rows they delete, as the writes above do.
|
|
22
|
+
*
|
|
23
|
+
* Held replies (AK-85, the rules of Flytebot's own core, `owedReplyStore.ts` and
|
|
24
|
+
* `replyDispatchStore.ts`). A background job the app starts for an acknowledged owed reply is a
|
|
25
|
+
* hold (`hold`, `endHold`): a run that completes leaves the owed reply unanswered, acked and
|
|
26
|
+
* held, instead of failing it. When the job ends, `claimWake` binds the released owed replies to
|
|
27
|
+
* a new dispatch, whose run answers them; `abandonWake` fails them when no wake can run. Held is
|
|
28
|
+
* derived on every read: a hold not yet reported to a wake (open, or ended and unreported).
|
|
29
|
+
*
|
|
15
30
|
* Every write runs in one transaction under the owed reply's row lock, raises `revision` and
|
|
16
31
|
* calls the app's projector (`project`, which writes its own chat message) in that same
|
|
17
32
|
* transaction. `settle` and a late reply therefore serialise on the same row: a reply to a
|
|
18
|
-
* failed owed reply is refused, and a settle after an answer changes nothing.
|
|
33
|
+
* failed owed reply is refused, and a settle after an answer changes nothing. Every operation
|
|
34
|
+
* that takes several rows locks them in id order, so none deadlocks another.
|
|
19
35
|
*
|
|
20
36
|
* The store talks to the app's own Prisma client through `OwedReplyClient`, a structural type
|
|
21
37
|
* (a generated client satisfies it, as for `PrismaAuthStore`): tagged-template raw SQL and an
|
|
@@ -23,7 +39,7 @@
|
|
|
23
39
|
* `SELECT ... FOR UPDATE`.
|
|
24
40
|
*/
|
|
25
41
|
import { randomUUID } from "node:crypto";
|
|
26
|
-
import { FAILURE_LINES, REFUSALS } from "./constants.js";
|
|
42
|
+
import { DISCARD_REFUSALS, FAILURE_LINES, HOLD_REFUSALS, REFUSALS, SIGNED_OUT_LINE } from "./constants.js";
|
|
27
43
|
import { owedReplyFromRow } from "./state.js";
|
|
28
44
|
/**
|
|
29
45
|
* Options of every transaction the store opens: `timeout` bounds the transaction's own work once
|
|
@@ -31,6 +47,14 @@ import { owedReplyFromRow } from "./state.js";
|
|
|
31
47
|
* contention fails fast (Prisma's P2028) instead of queueing writes behind a stuck holder.
|
|
32
48
|
*/
|
|
33
49
|
const TRANSACTION_OPTIONS = { timeout: 15_000, maxWait: 5_000 };
|
|
50
|
+
/** Thrown inside the write's transaction to roll it back when the app's `accept` refuses the reply. */
|
|
51
|
+
class ReplyRefused extends Error {
|
|
52
|
+
refusal;
|
|
53
|
+
constructor(refusal) {
|
|
54
|
+
super(refusal.message);
|
|
55
|
+
this.refusal = refusal;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
34
58
|
/** The ids a query found. */
|
|
35
59
|
async function idsOf(rows) {
|
|
36
60
|
return (await rows).map((row) => row.id);
|
|
@@ -45,9 +69,14 @@ export function createOwedReplyStore(options) {
|
|
|
45
69
|
const rows = await db.$queryRaw `
|
|
46
70
|
SELECT r."id", r."message_ref" AS "messageRef", r."conversation_ref" AS "conversationRef",
|
|
47
71
|
r."person_ref" AS "personRef", r."ack_text" AS "ackText", r."reply_text" AS "replyText",
|
|
48
|
-
r."
|
|
49
|
-
r."answered_at" AS "answeredAt", r."failed_at" AS "failedAt",
|
|
50
|
-
|
|
72
|
+
r."reply_payload" AS "replyPayload", r."failure", r."revision", r."created_at" AS "createdAt",
|
|
73
|
+
r."acked_at" AS "ackedAt", r."answered_at" AS "answeredAt", r."failed_at" AS "failedAt",
|
|
74
|
+
(SELECT COALESCE(json_agg(json_build_object('dispatchId', d."dispatch_id",
|
|
75
|
+
'boundAtMs', (extract(epoch FROM d."created_at") * 1000)::float8)
|
|
76
|
+
ORDER BY d."created_at", d."dispatch_id"), '[]'::json)
|
|
77
|
+
FROM "app_kit_owed_reply_dispatch" d WHERE d."owed_reply_id" = r."id") AS "bindings",
|
|
78
|
+
(r."reply_text" IS NULL AND r."failure" IS NULL AND EXISTS (SELECT 1 FROM "app_kit_owed_reply_hold" h
|
|
79
|
+
WHERE h."owed_reply_id" = r."id" AND h."reported_at" IS NULL)) AS "held"
|
|
51
80
|
FROM "app_kit_owed_reply" r
|
|
52
81
|
WHERE r."id" = ANY(${ids}::text[])`;
|
|
53
82
|
return rows.map(owedReplyFromRow).sort(byCreation);
|
|
@@ -58,14 +87,144 @@ export function createOwedReplyStore(options) {
|
|
|
58
87
|
throw new Error(`owed reply ${id} vanished inside its own transaction`);
|
|
59
88
|
return reply;
|
|
60
89
|
}
|
|
61
|
-
/** Counts the run's owed replies that are neither answered nor failed. */
|
|
62
|
-
async function
|
|
90
|
+
/** Counts the run's owed replies that are neither answered nor failed, and of those the ones no hold holds. */
|
|
91
|
+
async function owedState(db, dispatchId) {
|
|
63
92
|
const [row] = await db.$queryRaw `
|
|
64
|
-
SELECT count(*)::int AS "
|
|
93
|
+
SELECT count(*)::int AS "owed",
|
|
94
|
+
(count(*) FILTER (WHERE NOT EXISTS (SELECT 1 FROM "app_kit_owed_reply_hold" h
|
|
95
|
+
WHERE h."owed_reply_id" = r."id" AND h."reported_at" IS NULL)))::int AS "unheld"
|
|
65
96
|
FROM "app_kit_owed_reply_dispatch" d
|
|
66
97
|
JOIN "app_kit_owed_reply" r ON r."id" = d."owed_reply_id"
|
|
67
98
|
WHERE d."dispatch_id" = ${dispatchId} AND r."reply_text" IS NULL AND r."failure" IS NULL`;
|
|
68
|
-
return row?.
|
|
99
|
+
return { owed: row?.owed ?? 0, unheld: row?.unheld ?? 0 };
|
|
100
|
+
}
|
|
101
|
+
/** The ids of the conversations' `sent` owed replies: unanswered and not failed, no dispatch bound (the one SQL of "waiting for a run"). */
|
|
102
|
+
async function waitingIdsOf(db, conversationRefs) {
|
|
103
|
+
return idsOf(db.$queryRaw `
|
|
104
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
105
|
+
WHERE r."conversation_ref" = ANY(${conversationRefs}::text[]) AND r."reply_text" IS NULL AND r."failure" IS NULL
|
|
106
|
+
AND NOT EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d WHERE d."owed_reply_id" = r."id")`);
|
|
107
|
+
}
|
|
108
|
+
/** The refs of the open holds (job not ended) of these owed replies: the jobs an app must cancel. */
|
|
109
|
+
async function openHoldsOf(tx, ids) {
|
|
110
|
+
const rows = await tx.$queryRaw `
|
|
111
|
+
SELECT "hold_ref" AS "holdRef" FROM "app_kit_owed_reply_hold"
|
|
112
|
+
WHERE "owed_reply_id" = ANY(${ids}::text[]) AND "ended_at" IS NULL ORDER BY "hold_ref"`;
|
|
113
|
+
return rows.map((row) => row.holdRef);
|
|
114
|
+
}
|
|
115
|
+
/** Locks the conversation's unanswered owed replies, in id order, and answers their ids. */
|
|
116
|
+
async function lockOpenOfConversation(tx, conversationRef) {
|
|
117
|
+
return idsOf(tx.$queryRaw `
|
|
118
|
+
SELECT "id" FROM "app_kit_owed_reply"
|
|
119
|
+
WHERE "conversation_ref" = ${conversationRef} AND "reply_text" IS NULL AND "failure" IS NULL
|
|
120
|
+
ORDER BY "id" FOR UPDATE`);
|
|
121
|
+
}
|
|
122
|
+
/** The ids of a dispatch's bindings. */
|
|
123
|
+
async function boundTo(tx, dispatchId) {
|
|
124
|
+
return idsOf(tx.$queryRaw `
|
|
125
|
+
SELECT "owed_reply_id" AS "id" FROM "app_kit_owed_reply_dispatch" WHERE "dispatch_id" = ${dispatchId}`);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Of unanswered owed replies, the released held ones: acked, no open hold, an ended hold not yet
|
|
129
|
+
* reported. A caller that acts on the result holds the rows' locks (`claimWake`, `abandonWake`);
|
|
130
|
+
* `settle` reads without them, so what it reports is advisory and `claimWake` decides again under its own lock.
|
|
131
|
+
*/
|
|
132
|
+
async function releasedAmong(tx, ids) {
|
|
133
|
+
if (ids.length === 0)
|
|
134
|
+
return [];
|
|
135
|
+
return idsOf(tx.$queryRaw `
|
|
136
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
137
|
+
WHERE r."id" = ANY(${ids}::text[]) AND r."ack_text" IS NOT NULL
|
|
138
|
+
AND NOT EXISTS (SELECT 1 FROM "app_kit_owed_reply_hold" h
|
|
139
|
+
WHERE h."owed_reply_id" = r."id" AND h."ended_at" IS NULL)
|
|
140
|
+
AND EXISTS (SELECT 1 FROM "app_kit_owed_reply_hold" h
|
|
141
|
+
WHERE h."owed_reply_id" = r."id" AND h."ended_at" IS NOT NULL AND h."reported_at" IS NULL)
|
|
142
|
+
ORDER BY r."id"`);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Fails locked, unanswered owed replies with `line`: their holds end and are reported (an owed
|
|
146
|
+
* reply that is gone has nothing to wake), and each failure is projected. Answers the jobs that
|
|
147
|
+
* were still open, which the app must cancel.
|
|
148
|
+
*/
|
|
149
|
+
async function failLocked(tx, ids, line) {
|
|
150
|
+
if (ids.length === 0)
|
|
151
|
+
return { failed: [], cancelHolds: [] };
|
|
152
|
+
const open = await openHoldsOf(tx, ids);
|
|
153
|
+
await tx.$executeRaw `
|
|
154
|
+
UPDATE "app_kit_owed_reply_hold"
|
|
155
|
+
SET "ended_at" = COALESCE("ended_at", CURRENT_TIMESTAMP), "reported_at" = CURRENT_TIMESTAMP
|
|
156
|
+
WHERE "owed_reply_id" = ANY(${ids}::text[]) AND "reported_at" IS NULL`;
|
|
157
|
+
await tx.$executeRaw `
|
|
158
|
+
UPDATE "app_kit_owed_reply"
|
|
159
|
+
SET "failure" = ${line}, "failed_at" = CURRENT_TIMESTAMP, "revision" = "revision" + 1
|
|
160
|
+
WHERE "id" = ANY(${ids}::text[])`;
|
|
161
|
+
const failed = await load(tx, ids);
|
|
162
|
+
for (const reply of failed)
|
|
163
|
+
await project(tx, reply);
|
|
164
|
+
return { failed, cancelHolds: open };
|
|
165
|
+
}
|
|
166
|
+
async function writeReplyIn(input) {
|
|
167
|
+
return client.$transaction(async (tx) => {
|
|
168
|
+
const refuse = (message) => ({ ok: false, message, retryable: false });
|
|
169
|
+
const [locked] = await tx.$queryRaw `
|
|
170
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
171
|
+
WHERE r."id" = ${input.to}
|
|
172
|
+
AND EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d
|
|
173
|
+
WHERE d."owed_reply_id" = r."id" AND d."dispatch_id" = ${input.dispatchId})
|
|
174
|
+
FOR UPDATE OF r`;
|
|
175
|
+
if (locked === undefined)
|
|
176
|
+
return refuse(REFUSALS.notOwed);
|
|
177
|
+
const current = await loadOne(tx, locked.id);
|
|
178
|
+
if (current.state === "failed")
|
|
179
|
+
return refuse(REFUSALS.failed);
|
|
180
|
+
const sameText = input.phase === "ack" ? current.ackText : current.replyText;
|
|
181
|
+
if (sameText === input.text)
|
|
182
|
+
return { ok: true, ...(await owedState(tx, input.dispatchId)) };
|
|
183
|
+
if (current.state === "answered")
|
|
184
|
+
return refuse(REFUSALS.answered);
|
|
185
|
+
if (input.phase === "ack") {
|
|
186
|
+
await tx.$executeRaw `
|
|
187
|
+
UPDATE "app_kit_owed_reply"
|
|
188
|
+
SET "ack_text" = ${input.text}, "acked_at" = CURRENT_TIMESTAMP, "revision" = "revision" + 1
|
|
189
|
+
WHERE "id" = ${current.id}`;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// The app validates its own fields (and may write its own rows) here, in this transaction under
|
|
193
|
+
// the row lock: a refusal rolls everything back, what accept wrote included.
|
|
194
|
+
let payload = null;
|
|
195
|
+
if (input.fields !== undefined) {
|
|
196
|
+
const accepted = await input.fields.accept(tx, {
|
|
197
|
+
owedReply: current,
|
|
198
|
+
text: input.text,
|
|
199
|
+
fields: input.fields.values,
|
|
200
|
+
});
|
|
201
|
+
if (!accepted.ok)
|
|
202
|
+
throw new ReplyRefused({ ok: false, message: accepted.message, retryable: accepted.retryable });
|
|
203
|
+
payload = accepted.payload === null || accepted.payload === undefined ? null : JSON.stringify(accepted.payload);
|
|
204
|
+
}
|
|
205
|
+
await tx.$executeRaw `
|
|
206
|
+
UPDATE "app_kit_owed_reply"
|
|
207
|
+
SET "reply_text" = ${input.text}, "reply_payload" = ${payload}::jsonb,
|
|
208
|
+
"answered_at" = CURRENT_TIMESTAMP, "revision" = "revision" + 1
|
|
209
|
+
WHERE "id" = ${current.id}`;
|
|
210
|
+
}
|
|
211
|
+
await project(tx, await loadOne(tx, current.id));
|
|
212
|
+
return { ok: true, ...(await owedState(tx, input.dispatchId)) };
|
|
213
|
+
}, TRANSACTION_OPTIONS);
|
|
214
|
+
}
|
|
215
|
+
/** Locks the owed reply of a message and deletes it when no dispatch currently holds it. */
|
|
216
|
+
async function discardIn(tx, messageRef) {
|
|
217
|
+
const [locked] = await tx.$queryRaw `
|
|
218
|
+
SELECT "id" FROM "app_kit_owed_reply" WHERE "message_ref" = ${messageRef} FOR UPDATE`;
|
|
219
|
+
if (locked === undefined)
|
|
220
|
+
return { ok: true };
|
|
221
|
+
// A new statement after the lock: a claim that held the lock first has committed its binding, and this sees it.
|
|
222
|
+
const [taken] = await tx.$queryRaw `
|
|
223
|
+
SELECT 1 AS "one" FROM "app_kit_owed_reply_dispatch" WHERE "owed_reply_id" = ${locked.id} LIMIT 1`;
|
|
224
|
+
if (taken !== undefined)
|
|
225
|
+
return { ok: false, message: DISCARD_REFUSALS.taken };
|
|
226
|
+
await tx.$executeRaw `DELETE FROM "app_kit_owed_reply" WHERE "id" = ${locked.id}`;
|
|
227
|
+
return { ok: true };
|
|
69
228
|
}
|
|
70
229
|
return {
|
|
71
230
|
async receiveMessage(input) {
|
|
@@ -83,14 +242,12 @@ export function createOwedReplyStore(options) {
|
|
|
83
242
|
return client.$transaction(async (tx) => {
|
|
84
243
|
// Lock the conversation's open owed replies first: a second claim for another run waits here,
|
|
85
244
|
// then (a new statement, a new snapshot) sees the first claim's bindings and binds nothing twice.
|
|
86
|
-
const open = await
|
|
87
|
-
SELECT "id" FROM "app_kit_owed_reply"
|
|
88
|
-
WHERE "conversation_ref" = ${conversationRef} AND "reply_text" IS NULL AND "failure" IS NULL
|
|
89
|
-
ORDER BY "id" FOR UPDATE`);
|
|
245
|
+
const open = await lockOpenOfConversation(tx, conversationRef);
|
|
90
246
|
// A dispatch that already has bindings was claimed once: a retried request gets those back and binds
|
|
91
247
|
// nothing, so a message that arrived while the run works is never attached to a run that did not see it.
|
|
92
|
-
const [claimed] = await tx
|
|
93
|
-
|
|
248
|
+
const [claimed] = await boundTo(tx, dispatchId);
|
|
249
|
+
// Only owed replies no dispatch names are `sent`: a held one is acked, so it is bound already and is
|
|
250
|
+
// never taken here; its wake takes it (`claimWake`).
|
|
94
251
|
if (claimed === undefined && open.length > 0) {
|
|
95
252
|
await tx.$executeRaw `
|
|
96
253
|
INSERT INTO "app_kit_owed_reply_dispatch" ("owed_reply_id", "dispatch_id")
|
|
@@ -99,13 +256,24 @@ export function createOwedReplyStore(options) {
|
|
|
99
256
|
AND NOT EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d WHERE d."owed_reply_id" = r."id")
|
|
100
257
|
ON CONFLICT DO NOTHING`;
|
|
101
258
|
}
|
|
102
|
-
|
|
103
|
-
SELECT "owed_reply_id" AS "id" FROM "app_kit_owed_reply_dispatch" WHERE "dispatch_id" = ${dispatchId}`);
|
|
104
|
-
return load(tx, bound);
|
|
259
|
+
return load(tx, await boundTo(tx, dispatchId));
|
|
105
260
|
}, TRANSACTION_OPTIONS);
|
|
106
261
|
},
|
|
107
262
|
async writeReply(input) {
|
|
108
|
-
|
|
263
|
+
try {
|
|
264
|
+
return await writeReplyIn(input);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
// The app's `accept` refused: the throw rolled the transaction back, so nothing it wrote stays either.
|
|
268
|
+
if (error instanceof ReplyRefused)
|
|
269
|
+
return error.refusal;
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
async hold(tx, input) {
|
|
274
|
+
const refuse = (message) => ({ ok: false, message });
|
|
275
|
+
let target;
|
|
276
|
+
if (input.to !== undefined) {
|
|
109
277
|
const [locked] = await tx.$queryRaw `
|
|
110
278
|
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
111
279
|
WHERE r."id" = ${input.to}
|
|
@@ -113,57 +281,161 @@ export function createOwedReplyStore(options) {
|
|
|
113
281
|
WHERE d."owed_reply_id" = r."id" AND d."dispatch_id" = ${input.dispatchId})
|
|
114
282
|
FOR UPDATE OF r`;
|
|
115
283
|
if (locked === undefined)
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
284
|
+
return refuse(REFUSALS.notOwed);
|
|
285
|
+
target = await loadOne(tx, locked.id);
|
|
286
|
+
if (target.state === "failed")
|
|
287
|
+
return refuse(REFUSALS.failed);
|
|
288
|
+
if (target.state === "answered")
|
|
289
|
+
return refuse(REFUSALS.answered);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
const unanswered = await idsOf(tx.$queryRaw `
|
|
293
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
294
|
+
WHERE r."reply_text" IS NULL AND r."failure" IS NULL
|
|
295
|
+
AND EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d
|
|
296
|
+
WHERE d."owed_reply_id" = r."id" AND d."dispatch_id" = ${input.dispatchId})
|
|
297
|
+
ORDER BY r."id" FOR UPDATE OF r`);
|
|
298
|
+
if (unanswered.length === 0)
|
|
299
|
+
return refuse(HOLD_REFUSALS.nothingToHold);
|
|
300
|
+
if (unanswered.length > 1)
|
|
301
|
+
return refuse(HOLD_REFUSALS.ambiguous);
|
|
302
|
+
target = await loadOne(tx, unanswered[0]);
|
|
303
|
+
}
|
|
304
|
+
if (target.state !== "acked")
|
|
305
|
+
return refuse(HOLD_REFUSALS.notAcknowledged);
|
|
306
|
+
await tx.$executeRaw `
|
|
307
|
+
INSERT INTO "app_kit_owed_reply_hold" ("hold_ref", "owed_reply_id")
|
|
308
|
+
VALUES (${input.holdRef}, ${target.id})
|
|
309
|
+
ON CONFLICT ("hold_ref") DO NOTHING`;
|
|
310
|
+
const [existing] = await tx.$queryRaw `
|
|
311
|
+
SELECT "owed_reply_id" AS "owedReplyId" FROM "app_kit_owed_reply_hold" WHERE "hold_ref" = ${input.holdRef}`;
|
|
312
|
+
if (existing === undefined)
|
|
313
|
+
throw new Error(`hold ${input.holdRef} was not stored`);
|
|
314
|
+
return existing.owedReplyId === target.id ? { ok: true, owedReplyId: target.id } : refuse(HOLD_REFUSALS.refInUse);
|
|
315
|
+
},
|
|
316
|
+
async endHold(holdRef) {
|
|
317
|
+
return client.$transaction(async (tx) => {
|
|
318
|
+
const [row] = await tx.$queryRaw `
|
|
319
|
+
SELECT r."id", r."conversation_ref" AS "conversationRef"
|
|
320
|
+
FROM "app_kit_owed_reply_hold" h
|
|
321
|
+
JOIN "app_kit_owed_reply" r ON r."id" = h."owed_reply_id"
|
|
322
|
+
WHERE h."hold_ref" = ${holdRef}`;
|
|
323
|
+
if (row === undefined)
|
|
324
|
+
return null;
|
|
325
|
+
// The owed reply's row lock is what a wake's claim and a settle take: whichever comes second
|
|
326
|
+
// sees the other's outcome, so a wake never misses a job that has just ended.
|
|
327
|
+
await tx.$queryRaw `SELECT "id" FROM "app_kit_owed_reply" WHERE "id" = ${row.id} FOR UPDATE`;
|
|
328
|
+
await tx.$executeRaw `
|
|
329
|
+
UPDATE "app_kit_owed_reply_hold" SET "ended_at" = CURRENT_TIMESTAMP
|
|
330
|
+
WHERE "hold_ref" = ${holdRef} AND "ended_at" IS NULL`;
|
|
331
|
+
return { conversationRef: row.conversationRef };
|
|
139
332
|
}, TRANSACTION_OPTIONS);
|
|
140
333
|
},
|
|
141
|
-
async settle(dispatchId,
|
|
142
|
-
const
|
|
334
|
+
async settle(dispatchId, end) {
|
|
335
|
+
const line = FAILURE_LINES[end];
|
|
143
336
|
return client.$transaction(async (tx) => {
|
|
144
|
-
|
|
337
|
+
// Lock the owed replies bound to this dispatch first, then (a new statement, a new snapshot) keep
|
|
338
|
+
// the ones it still owns: one a later dispatch (a wake) took is that run's, so a terminal
|
|
339
|
+
// redelivered for the earlier run changes nothing, even when it waited on the wake's claim.
|
|
340
|
+
const lockedIds = await idsOf(tx.$queryRaw `
|
|
145
341
|
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
146
342
|
WHERE EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d
|
|
147
343
|
WHERE d."owed_reply_id" = r."id" AND d."dispatch_id" = ${dispatchId})
|
|
148
344
|
ORDER BY r."id" FOR UPDATE OF r`);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
345
|
+
const owned = lockedIds.length === 0 ? [] : await idsOf(tx.$queryRaw `
|
|
346
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
347
|
+
JOIN "app_kit_owed_reply_dispatch" d ON d."owed_reply_id" = r."id" AND d."dispatch_id" = ${dispatchId}
|
|
348
|
+
WHERE r."id" = ANY(${lockedIds}::text[])
|
|
349
|
+
AND NOT EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" later
|
|
350
|
+
WHERE later."owed_reply_id" = r."id" AND later."created_at" > d."created_at")`);
|
|
351
|
+
const bound = await load(tx, owned);
|
|
352
|
+
const unanswered = bound.filter((reply) => reply.state !== "answered" && reply.state !== "failed");
|
|
353
|
+
// A run that completed leaves an owed reply a background job holds for its wake; any other end
|
|
354
|
+
// means the agent that was to answer is gone, so held ones fail too.
|
|
355
|
+
const failing = end === "completed" ? unanswered.filter((reply) => !reply.held) : unanswered;
|
|
356
|
+
const { cancelHolds } = await failLocked(tx, failing.map((reply) => reply.id), line);
|
|
159
357
|
const conversations = [...new Set(bound.map((reply) => reply.conversationRef))];
|
|
160
358
|
if (conversations.length === 0)
|
|
161
|
-
return [];
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
AND r."reply_text" IS NULL AND r."failure" IS NULL
|
|
166
|
-
|
|
359
|
+
return { waiting: [], released: [], cancelHolds };
|
|
360
|
+
const waiting = await load(tx, await waitingIdsOf(tx, conversations));
|
|
361
|
+
const released = await load(tx, await releasedAmong(tx, await idsOf(tx.$queryRaw `
|
|
362
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
363
|
+
WHERE r."conversation_ref" = ANY(${conversations}::text[]) AND r."reply_text" IS NULL AND r."failure" IS NULL`)));
|
|
364
|
+
return { waiting, released, cancelHolds };
|
|
365
|
+
}, TRANSACTION_OPTIONS);
|
|
366
|
+
},
|
|
367
|
+
async claimWake(conversationRef, dispatchId) {
|
|
368
|
+
return client.$transaction(async (tx) => {
|
|
369
|
+
const open = await lockOpenOfConversation(tx, conversationRef);
|
|
370
|
+
const [claimed] = await boundTo(tx, dispatchId);
|
|
371
|
+
if (claimed === undefined) {
|
|
372
|
+
const released = await releasedAmong(tx, open);
|
|
373
|
+
if (released.length > 0) {
|
|
374
|
+
await tx.$executeRaw `
|
|
375
|
+
INSERT INTO "app_kit_owed_reply_dispatch" ("owed_reply_id", "dispatch_id")
|
|
376
|
+
SELECT r."id", ${dispatchId} FROM "app_kit_owed_reply" r WHERE r."id" = ANY(${released}::text[])
|
|
377
|
+
ON CONFLICT DO NOTHING`;
|
|
378
|
+
// Reported in the claim's own transaction, so a job is told to exactly one run.
|
|
379
|
+
await tx.$executeRaw `
|
|
380
|
+
UPDATE "app_kit_owed_reply_hold" SET "reported_at" = CURRENT_TIMESTAMP
|
|
381
|
+
WHERE "owed_reply_id" = ANY(${released}::text[]) AND "ended_at" IS NOT NULL AND "reported_at" IS NULL`;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const replies = await load(tx, await boundTo(tx, dispatchId));
|
|
385
|
+
// The holds this dispatch reported are the ones reported at its own binding time.
|
|
386
|
+
const holds = await tx.$queryRaw `
|
|
387
|
+
SELECT h."hold_ref" AS "holdRef", h."owed_reply_id" AS "owedReplyId"
|
|
388
|
+
FROM "app_kit_owed_reply_hold" h
|
|
389
|
+
JOIN "app_kit_owed_reply_dispatch" d ON d."owed_reply_id" = h."owed_reply_id" AND d."dispatch_id" = ${dispatchId}
|
|
390
|
+
WHERE h."reported_at" = d."created_at"
|
|
391
|
+
ORDER BY h."created_at", h."hold_ref"`;
|
|
392
|
+
return { replies, holds };
|
|
393
|
+
}, TRANSACTION_OPTIONS);
|
|
394
|
+
},
|
|
395
|
+
async abandonWake(conversationRef) {
|
|
396
|
+
return client.$transaction(async (tx) => {
|
|
397
|
+
const released = await releasedAmong(tx, await lockOpenOfConversation(tx, conversationRef));
|
|
398
|
+
return (await failLocked(tx, released, SIGNED_OUT_LINE)).failed;
|
|
399
|
+
}, TRANSACTION_OPTIONS);
|
|
400
|
+
},
|
|
401
|
+
async withdraw(dispatchId) {
|
|
402
|
+
return client.$transaction(async (tx) => {
|
|
403
|
+
const locked = await idsOf(tx.$queryRaw `
|
|
404
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
405
|
+
WHERE EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d
|
|
406
|
+
WHERE d."owed_reply_id" = r."id" AND d."dispatch_id" = ${dispatchId})
|
|
407
|
+
ORDER BY r."id" FOR UPDATE OF r`);
|
|
408
|
+
if (locked.length === 0)
|
|
409
|
+
return false;
|
|
410
|
+
// A write since the dispatch was bound (an ack, a reply or a failure) means its run started.
|
|
411
|
+
const [written] = await tx.$queryRaw `
|
|
412
|
+
SELECT 1 AS "one"
|
|
413
|
+
FROM "app_kit_owed_reply_dispatch" d
|
|
414
|
+
JOIN "app_kit_owed_reply" r ON r."id" = d."owed_reply_id"
|
|
415
|
+
WHERE d."dispatch_id" = ${dispatchId}
|
|
416
|
+
AND (r."acked_at" >= d."created_at" OR r."answered_at" >= d."created_at" OR r."failed_at" >= d."created_at")
|
|
417
|
+
LIMIT 1`;
|
|
418
|
+
if (written !== undefined)
|
|
419
|
+
return false;
|
|
420
|
+
// A wake's claim reported its holds at the binding's own time: they are untold again.
|
|
421
|
+
await tx.$executeRaw `
|
|
422
|
+
UPDATE "app_kit_owed_reply_hold" h SET "reported_at" = NULL
|
|
423
|
+
FROM "app_kit_owed_reply_dispatch" d
|
|
424
|
+
WHERE d."dispatch_id" = ${dispatchId} AND h."owed_reply_id" = d."owed_reply_id"
|
|
425
|
+
AND h."reported_at" = d."created_at"`;
|
|
426
|
+
await tx.$executeRaw `DELETE FROM "app_kit_owed_reply_dispatch" WHERE "dispatch_id" = ${dispatchId}`;
|
|
427
|
+
return true;
|
|
428
|
+
}, TRANSACTION_OPTIONS);
|
|
429
|
+
},
|
|
430
|
+
async stop(conversationRef) {
|
|
431
|
+
return client.$transaction(async (tx) => {
|
|
432
|
+
const taken = await idsOf(tx.$queryRaw `
|
|
433
|
+
SELECT r."id" FROM "app_kit_owed_reply" r
|
|
434
|
+
WHERE r."conversation_ref" = ${conversationRef} AND r."reply_text" IS NULL AND r."failure" IS NULL
|
|
435
|
+
AND EXISTS (SELECT 1 FROM "app_kit_owed_reply_dispatch" d WHERE d."owed_reply_id" = r."id")
|
|
436
|
+
ORDER BY r."id" FOR UPDATE OF r`);
|
|
437
|
+
const { failed, cancelHolds } = await failLocked(tx, taken, FAILURE_LINES.cancelled);
|
|
438
|
+
return { stopped: failed, cancelHolds };
|
|
167
439
|
}, TRANSACTION_OPTIONS);
|
|
168
440
|
},
|
|
169
441
|
async unansweredOf(dispatchId) {
|
|
@@ -173,6 +445,37 @@ export function createOwedReplyStore(options) {
|
|
|
173
445
|
JOIN "app_kit_owed_reply" r ON r."id" = d."owed_reply_id"
|
|
174
446
|
WHERE d."dispatch_id" = ${dispatchId} AND r."reply_text" IS NULL AND r."failure" IS NULL`));
|
|
175
447
|
},
|
|
448
|
+
async ofMessages(messageRefs) {
|
|
449
|
+
if (messageRefs.length === 0)
|
|
450
|
+
return [];
|
|
451
|
+
return load(client, await idsOf(client.$queryRaw `
|
|
452
|
+
SELECT "id" FROM "app_kit_owed_reply" WHERE "message_ref" = ANY(${messageRefs}::text[])`));
|
|
453
|
+
},
|
|
454
|
+
async ofConversation(conversationRef) {
|
|
455
|
+
return load(client, await idsOf(client.$queryRaw `
|
|
456
|
+
SELECT "id" FROM "app_kit_owed_reply" WHERE "conversation_ref" = ${conversationRef}`));
|
|
457
|
+
},
|
|
458
|
+
async hasWaiting(conversationRef) {
|
|
459
|
+
return (await waitingIdsOf(client, [conversationRef])).length > 0;
|
|
460
|
+
},
|
|
461
|
+
async discard(messageRef, tx) {
|
|
462
|
+
if (tx !== undefined)
|
|
463
|
+
return discardIn(tx, messageRef);
|
|
464
|
+
return client.$transaction((own) => discardIn(own, messageRef), TRANSACTION_OPTIONS);
|
|
465
|
+
},
|
|
466
|
+
async deleteConversation(tx, conversationRefs) {
|
|
467
|
+
if (conversationRefs.length === 0)
|
|
468
|
+
return { cancelHolds: [] };
|
|
469
|
+
const ids = await idsOf(tx.$queryRaw `
|
|
470
|
+
SELECT "id" FROM "app_kit_owed_reply" WHERE "conversation_ref" = ANY(${conversationRefs}::text[]) ORDER BY "id" FOR UPDATE`);
|
|
471
|
+
if (ids.length === 0)
|
|
472
|
+
return { cancelHolds: [] };
|
|
473
|
+
const cancelHolds = await openHoldsOf(tx, ids);
|
|
474
|
+
await tx.$executeRaw `DELETE FROM "app_kit_owed_reply_hold" WHERE "owed_reply_id" = ANY(${ids}::text[])`;
|
|
475
|
+
await tx.$executeRaw `DELETE FROM "app_kit_owed_reply_dispatch" WHERE "owed_reply_id" = ANY(${ids}::text[])`;
|
|
476
|
+
await tx.$executeRaw `DELETE FROM "app_kit_owed_reply" WHERE "id" = ANY(${ids}::text[])`;
|
|
477
|
+
return { cancelHolds };
|
|
478
|
+
},
|
|
176
479
|
};
|
|
177
480
|
}
|
|
178
481
|
//# sourceMappingURL=store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/chat/owed-replies/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAqC,MAAM,YAAY,CAAC;AAajF;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAW,CAAC;AA4CzE,6BAA6B;AAC7B,KAAK,UAAU,KAAK,CAAC,IAAsB;IACzC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAY,EAAE,CAAY,EAAU,EAAE,CACxD,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC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EAAE,CAAC,SAAS,CAAS;+EAC4B,gBAAgB,oCAAoC,CAAC,CAAC;YAC/H,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;YACjD,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC/C,MAAM,EAAE,CAAC,WAAW,CAAA,qEAAqE,GAAG,WAAW,CAAC;YACxG,MAAM,EAAE,CAAC,WAAW,CAAA,yEAAyE,GAAG,WAAW,CAAC;YAC5G,MAAM,EAAE,CAAC,WAAW,CAAA,qDAAqD,GAAG,WAAW,CAAC;YACxF,OAAO,EAAE,WAAW,EAAE,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type { AppRegisteredTool } from "../types.js";
|
|
2
|
-
import type { OwedReplyStore } from "./store.js";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { AcceptReply, OwedReplyStore, OwedReplyTransaction } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* The fields an app's own replies carry beside their text (an audience proposal, a plan packet):
|
|
5
|
+
* the packet is the app's to validate (AK-85). `properties` are JSON Schema properties that join
|
|
6
|
+
* the tool's input; they are allowed with phase `reply` only, because an acknowledgement is
|
|
7
|
+
* words alone. `accept` validates them in the write's transaction (see `AcceptReply`).
|
|
8
|
+
*/
|
|
9
|
+
export interface OwedReplyFields<Tx extends OwedReplyTransaction> {
|
|
10
|
+
properties: Record<string, unknown>;
|
|
11
|
+
accept: AcceptReply<Tx>;
|
|
12
|
+
}
|
|
13
|
+
export interface OwedReplyToolOptions<Tx extends OwedReplyTransaction = OwedReplyTransaction> {
|
|
14
|
+
store: OwedReplyStore<Tx>;
|
|
15
|
+
/** The app's reply fields; left out, the tool takes `{to, phase, text}` only. */
|
|
16
|
+
replyFields?: OwedReplyFields<Tx>;
|
|
5
17
|
/** The run this tool serves: the Idempotency-Key the app sent in `runs.create`. A reply to an owed reply this run did not take is refused. */
|
|
6
18
|
dispatchId: string;
|
|
7
19
|
/** Tool name advertised to the agent. Default `reply`. */
|
|
@@ -9,4 +21,4 @@ export interface OwedReplyToolOptions {
|
|
|
9
21
|
/** Full description shown to the model; write it in your own product's voice. */
|
|
10
22
|
description?: string;
|
|
11
23
|
}
|
|
12
|
-
export declare function createOwedReplyTool(options: OwedReplyToolOptions): AppRegisteredTool;
|
|
24
|
+
export declare function createOwedReplyTool<Tx extends OwedReplyTransaction = OwedReplyTransaction>(options: OwedReplyToolOptions<Tx>): AppRegisteredTool;
|