@flytedesk/app-kit 16.1.0 → 16.3.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 +195 -0
- package/dist/chat/owed-replies/constants.d.ts +47 -0
- package/dist/chat/owed-replies/constants.js +71 -0
- package/dist/chat/owed-replies/constants.js.map +1 -0
- package/dist/chat/owed-replies/index.d.ts +16 -0
- package/dist/chat/owed-replies/index.js +12 -0
- package/dist/chat/owed-replies/index.js.map +1 -0
- package/dist/chat/owed-replies/plugin.d.ts +36 -0
- package/dist/chat/owed-replies/plugin.js +33 -0
- package/dist/chat/owed-replies/plugin.js.map +1 -0
- package/dist/chat/owed-replies/state.d.ts +56 -0
- package/dist/chat/owed-replies/state.js +33 -0
- package/dist/chat/owed-replies/state.js.map +1 -0
- package/dist/chat/owed-replies/store.d.ts +155 -0
- package/dist/chat/owed-replies/store.js +420 -0
- package/dist/chat/owed-replies/store.js.map +1 -0
- package/dist/chat/owed-replies/tool.d.ts +24 -0
- package/dist/chat/owed-replies/tool.js +77 -0
- package/dist/chat/owed-replies/tool.js.map +1 -0
- package/dist/chat/tools/index.d.ts +19 -0
- package/dist/chat/tools/index.js +16 -2
- package/dist/chat/tools/index.js.map +1 -1
- package/dist/cli/owed-reply-sync.d.ts +2 -0
- package/dist/cli/owed-reply-sync.js +28 -0
- package/dist/cli/owed-reply-sync.js.map +1 -0
- package/dist/flytebot/testing/fake.d.ts +33 -4
- package/dist/flytebot/testing/fake.js +100 -3
- package/dist/flytebot/testing/fake.js.map +1 -1
- package/dist/flytebot/testing/index.d.ts +1 -1
- package/package.json +8 -3
- package/prisma/fragments/owed-reply.meta.json +4 -0
- package/prisma/fragments/owed-reply.prisma +72 -0
- package/prisma/migrations/0006_app_kit_owed_reply_init/migration.sql +63 -0
- package/prisma/migrations/0007_app_kit_owed_reply_holds/migration.sql +39 -0
- package/prisma/migrations/manifest.json +14 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @flytedesk/app-kit/chat/owed-replies: canonical Prisma model fragment (AK-80).
|
|
2
|
+
//
|
|
3
|
+
// Installed into the *consumer's* own Prisma schema by `owed-reply-sync init` (see
|
|
4
|
+
// src/cli/owed-reply-sync.ts, a thin wrapper around src/cli/sync-engine.ts), exactly as
|
|
5
|
+
// the auth fragment is; this package never builds a client from it.
|
|
6
|
+
//
|
|
7
|
+
// What this models: a person's chat message is owed an answer. One OwedReply per message
|
|
8
|
+
// holds the agent's acknowledgement, its reply, or the fixed line shown when the run
|
|
9
|
+
// ended without answering, plus the revision the app's chat message projects. Which run
|
|
10
|
+
// took the message is the row in OwedReplyDispatch. A background job an app starts for an
|
|
11
|
+
// acknowledged message is a row in OwedReplyHold. The state (sent, taken, acked, answered,
|
|
12
|
+
// failed) and whether a message is held are never stored: they are derived on every read
|
|
13
|
+
// from these columns and rows (src/chat/owed-replies/state.ts).
|
|
14
|
+
//
|
|
15
|
+
// Design constraints (the same as every fragment): no `@relation`, since a package that
|
|
16
|
+
// ships models into a consumer's schema cannot see the consumer's own models; no enum;
|
|
17
|
+
// tables prefixed `app_kit_` through `@@map`. The CHECK constraints Prisma's schema
|
|
18
|
+
// language cannot express are in prisma/migrations/0006_app_kit_owed_reply_init and
|
|
19
|
+
// 0007_app_kit_owed_reply_holds.
|
|
20
|
+
|
|
21
|
+
/// One row per message of a person that is owed an answer. `messageRef` is the app's own id
|
|
22
|
+
/// for the message, so a resent message finds its row. `ackText` is replaced by a second
|
|
23
|
+
/// acknowledgement; `replyText` and `failure` are each written once and never together.
|
|
24
|
+
model OwedReply {
|
|
25
|
+
id String @id
|
|
26
|
+
messageRef String @unique @map("message_ref")
|
|
27
|
+
conversationRef String @map("conversation_ref")
|
|
28
|
+
personRef String @map("person_ref")
|
|
29
|
+
ackText String? @map("ack_text")
|
|
30
|
+
replyText String? @map("reply_text")
|
|
31
|
+
/// What the app's reply fields carried (AK-85), written with `replyText` and never without it.
|
|
32
|
+
replyPayload Json? @map("reply_payload")
|
|
33
|
+
failure String?
|
|
34
|
+
/// Raised on every write, so the app's projected chat message can tell a stale write.
|
|
35
|
+
revision Int @default(0)
|
|
36
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
37
|
+
ackedAt DateTime? @map("acked_at")
|
|
38
|
+
answeredAt DateTime? @map("answered_at")
|
|
39
|
+
failedAt DateTime? @map("failed_at")
|
|
40
|
+
|
|
41
|
+
@@index([conversationRef])
|
|
42
|
+
@@map("app_kit_owed_reply")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// The run (Flytebot dispatch) that took an owed reply. A row exists from the moment the
|
|
46
|
+
/// app binds the owed reply to the run it requested, so a message with no row is still
|
|
47
|
+
/// `sent`. The same dispatch id is never bound twice to one owed reply.
|
|
48
|
+
model OwedReplyDispatch {
|
|
49
|
+
owedReplyId String @map("owed_reply_id")
|
|
50
|
+
dispatchId String @map("dispatch_id")
|
|
51
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
52
|
+
|
|
53
|
+
@@id([owedReplyId, dispatchId])
|
|
54
|
+
@@index([dispatchId])
|
|
55
|
+
@@map("app_kit_owed_reply_dispatch")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// A background job the app started for an acknowledged, unanswered owed reply (AK-85): while a
|
|
59
|
+
/// hold is open, or ended and not yet reported to a wake run, the owed reply is held, and a run
|
|
60
|
+
/// that completes leaves it unanswered instead of failing it. `holdRef` is the app's own id for
|
|
61
|
+
/// the job. A hold is reported when a wake run takes the owed reply, or when the owed reply
|
|
62
|
+
/// fails; `reportedAt` is never set before `endedAt`.
|
|
63
|
+
model OwedReplyHold {
|
|
64
|
+
holdRef String @id @map("hold_ref")
|
|
65
|
+
owedReplyId String @map("owed_reply_id")
|
|
66
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
67
|
+
endedAt DateTime? @map("ended_at")
|
|
68
|
+
reportedAt DateTime? @map("reported_at")
|
|
69
|
+
|
|
70
|
+
@@index([owedReplyId])
|
|
71
|
+
@@map("app_kit_owed_reply_hold")
|
|
72
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
-- @flytedesk/app-kit/chat/owed-replies :: 0006_app_kit_owed_reply_init
|
|
2
|
+
--
|
|
3
|
+
-- The tables behind the owed-reply store: one row per message of a person that is owed an
|
|
4
|
+
-- answer, and the run that took it. Column names, types and defaults match
|
|
5
|
+
-- prisma/fragments/owed-reply.prisma (Prisma's own mapping: TEXT, INTEGER, TIMESTAMP(3)),
|
|
6
|
+
-- then the CHECK constraints Prisma's schema language cannot express. One DO block, so the
|
|
7
|
+
-- tables, indexes and checks apply together or not at all. For an app that does not use
|
|
8
|
+
-- Prisma migrate; an app that does writes its own migration from the fragment, and
|
|
9
|
+
-- `owed-reply-sync` prints the CHECK lines below for it to append (see sync-engine.ts).
|
|
10
|
+
|
|
11
|
+
DO $owed_reply$
|
|
12
|
+
BEGIN
|
|
13
|
+
SET LOCAL lock_timeout = '5s';
|
|
14
|
+
|
|
15
|
+
-- CreateTable
|
|
16
|
+
CREATE TABLE "app_kit_owed_reply" (
|
|
17
|
+
"id" TEXT NOT NULL,
|
|
18
|
+
"message_ref" TEXT NOT NULL,
|
|
19
|
+
"conversation_ref" TEXT NOT NULL,
|
|
20
|
+
"person_ref" TEXT NOT NULL,
|
|
21
|
+
"ack_text" TEXT,
|
|
22
|
+
"reply_text" TEXT,
|
|
23
|
+
"failure" TEXT,
|
|
24
|
+
"revision" INTEGER NOT NULL DEFAULT 0,
|
|
25
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
26
|
+
"acked_at" TIMESTAMP(3),
|
|
27
|
+
"answered_at" TIMESTAMP(3),
|
|
28
|
+
"failed_at" TIMESTAMP(3),
|
|
29
|
+
|
|
30
|
+
CONSTRAINT "app_kit_owed_reply_pkey" PRIMARY KEY ("id")
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
-- CreateTable
|
|
34
|
+
CREATE TABLE "app_kit_owed_reply_dispatch" (
|
|
35
|
+
"owed_reply_id" TEXT NOT NULL,
|
|
36
|
+
"dispatch_id" TEXT NOT NULL,
|
|
37
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
38
|
+
|
|
39
|
+
CONSTRAINT "app_kit_owed_reply_dispatch_pkey" PRIMARY KEY ("owed_reply_id","dispatch_id")
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
-- CreateIndex
|
|
43
|
+
CREATE UNIQUE INDEX "app_kit_owed_reply_message_ref_key" ON "app_kit_owed_reply"("message_ref");
|
|
44
|
+
|
|
45
|
+
-- CreateIndex
|
|
46
|
+
CREATE INDEX "app_kit_owed_reply_conversation_ref_idx" ON "app_kit_owed_reply"("conversation_ref");
|
|
47
|
+
|
|
48
|
+
-- CreateIndex
|
|
49
|
+
CREATE INDEX "app_kit_owed_reply_dispatch_dispatch_id_idx" ON "app_kit_owed_reply_dispatch"("dispatch_id");
|
|
50
|
+
|
|
51
|
+
-- AddCheck: an acknowledgement, a reply and a failure each carry the time they were written, and never one without the other.
|
|
52
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_ack_complete" CHECK (("ack_text" IS NULL) = ("acked_at" IS NULL));
|
|
53
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_answer_complete" CHECK (("reply_text" IS NULL) = ("answered_at" IS NULL));
|
|
54
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_failure_complete" CHECK (("failure" IS NULL) = ("failed_at" IS NULL));
|
|
55
|
+
|
|
56
|
+
-- AddCheck: an owed reply is answered or failed, never both, and none of its texts is blank.
|
|
57
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_settled_once" CHECK ("reply_text" IS NULL OR "failure" IS NULL);
|
|
58
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_text_not_blank" CHECK (("ack_text" IS NULL OR btrim("ack_text") <> '') AND ("reply_text" IS NULL OR btrim("reply_text") <> '') AND ("failure" IS NULL OR btrim("failure") <> ''));
|
|
59
|
+
|
|
60
|
+
-- AddCheck: the revision only ever counts up from zero.
|
|
61
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_revision_valid" CHECK ("revision" >= 0);
|
|
62
|
+
END
|
|
63
|
+
$owed_reply$;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- @flytedesk/app-kit/chat/owed-replies :: 0007_app_kit_owed_reply_holds
|
|
2
|
+
--
|
|
3
|
+
-- What an app's reply fields and background jobs add to the owed-reply tables (AK-85): the
|
|
4
|
+
-- payload a reply carries beside its text, and one row per background job that holds an
|
|
5
|
+
-- acknowledged owed reply open. Column names, types and defaults match
|
|
6
|
+
-- prisma/fragments/owed-reply.prisma (Prisma's own mapping: JSONB, TEXT, TIMESTAMP(3)), then
|
|
7
|
+
-- the CHECK constraints Prisma's schema language cannot express. One DO block, so the column,
|
|
8
|
+
-- the table, its index and the checks apply together or not at all. For an app that does not
|
|
9
|
+
-- use Prisma migrate; an app that does writes its own migration from the fragment, and
|
|
10
|
+
-- `owed-reply-sync` prints the CHECK lines below for it to append (see sync-engine.ts).
|
|
11
|
+
|
|
12
|
+
DO $owed_reply_holds$
|
|
13
|
+
BEGIN
|
|
14
|
+
SET LOCAL lock_timeout = '5s';
|
|
15
|
+
|
|
16
|
+
-- AlterTable
|
|
17
|
+
ALTER TABLE "app_kit_owed_reply" ADD COLUMN "reply_payload" JSONB;
|
|
18
|
+
|
|
19
|
+
-- CreateTable
|
|
20
|
+
CREATE TABLE "app_kit_owed_reply_hold" (
|
|
21
|
+
"hold_ref" TEXT NOT NULL,
|
|
22
|
+
"owed_reply_id" TEXT NOT NULL,
|
|
23
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
+
"ended_at" TIMESTAMP(3),
|
|
25
|
+
"reported_at" TIMESTAMP(3),
|
|
26
|
+
|
|
27
|
+
CONSTRAINT "app_kit_owed_reply_hold_pkey" PRIMARY KEY ("hold_ref")
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- CreateIndex
|
|
31
|
+
CREATE INDEX "app_kit_owed_reply_hold_owed_reply_id_idx" ON "app_kit_owed_reply_hold"("owed_reply_id");
|
|
32
|
+
|
|
33
|
+
-- AddCheck: a payload is part of a reply, so it never exists without the reply's text.
|
|
34
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_payload_needs_reply" CHECK ("reply_payload" IS NULL OR "reply_text" IS NOT NULL);
|
|
35
|
+
|
|
36
|
+
-- AddCheck: a hold is reported only after it ended.
|
|
37
|
+
ALTER TABLE "app_kit_owed_reply_hold" ADD CONSTRAINT "app_kit_owed_reply_hold_reported_after_end" CHECK ("reported_at" IS NULL OR "ended_at" IS NOT NULL);
|
|
38
|
+
END
|
|
39
|
+
$owed_reply_holds$;
|
|
@@ -33,5 +33,19 @@
|
|
|
33
33
|
"file": "0005_app_kit_signed_in_person/migration.sql",
|
|
34
34
|
"checksum": "sha256:1504c518ac0a0818a327cb4acc639373218896c115f604e25f605af42e0910bd",
|
|
35
35
|
"introducedInFragmentVersion": "1.1.0"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "0006_app_kit_owed_reply_init",
|
|
39
|
+
"fragment": "owed-reply",
|
|
40
|
+
"file": "0006_app_kit_owed_reply_init/migration.sql",
|
|
41
|
+
"checksum": "sha256:7e066dfa5a82cf212ac915a7861476ee6a67967ad94a1f1462480c9d4689a4aa",
|
|
42
|
+
"introducedInFragmentVersion": "1.0.0"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "0007_app_kit_owed_reply_holds",
|
|
46
|
+
"fragment": "owed-reply",
|
|
47
|
+
"file": "0007_app_kit_owed_reply_holds/migration.sql",
|
|
48
|
+
"checksum": "sha256:6dd6893a8591839e2c68aad6ac30191c9de84855dae834cdb1e557fb503ce818",
|
|
49
|
+
"introducedInFragmentVersion": "1.1.0"
|
|
36
50
|
}
|
|
37
51
|
]
|