@segmentstream/ontology 0.147.0 → 0.149.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 +39 -0
- package/README.md +24 -15
- package/dist/analyze.d.ts +11 -3
- package/dist/analyze.js +21 -4
- package/dist/connection.d.ts +20 -3
- package/dist/connection.js +36 -8
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +1 -0
- package/dist/files.d.ts +21 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/internal/diagnostics.js +3 -0
- package/dist/manifest.d.ts +125 -77
- package/dist/manifest.js +34 -2
- package/dist/migrate/model.d.ts +68 -56
- package/dist/migrate/plan.js +1 -1
- package/dist/migrate/preview.js +4 -1
- package/dist/migrate/storage.d.ts +15 -3
- package/dist/migrate/storage.js +86 -3
- package/dist/runtime/agents.js +2 -0
- package/dist/runtime/chat-messages.d.ts +233 -0
- package/dist/runtime/chat-messages.js +523 -0
- package/dist/runtime/pipeline.js +1 -0
- package/dist/service/agent/archive-routes.d.ts +2 -0
- package/dist/service/agent/archive-routes.js +2 -1
- package/dist/service/agent/chat-archive.d.ts +12 -3
- package/dist/service/agent/chat-archive.js +5 -1
- package/dist/service/agent/chat-message-routes.d.ts +124 -0
- package/dist/service/agent/chat-message-routes.js +235 -0
- package/dist/service/agent/server.d.ts +5 -1
- package/dist/service/agent/server.js +15 -0
- package/dist/service/chat/local-reads.d.ts +71 -0
- package/dist/service/chat/local-reads.js +148 -0
- package/dist/service/chat/reads.js +7 -0
- package/dist/service/chat/routes.js +4 -1
- package/dist/service/chat/schemas.d.ts +5 -0
- package/dist/service/chat/schemas.js +5 -0
- package/dist/service/connection-stream.d.ts +7 -0
- package/dist/service/connection-stream.js +9 -1
- package/dist/service/connections.js +56 -5
- package/dist/service/cron-secret.d.ts +6 -0
- package/dist/service/cron-secret.js +14 -0
- package/dist/service/discovery-search.d.ts +1 -1
- package/dist/service/mcp/server.js +4 -2
- package/dist/service/runtime-contract.d.ts +2 -0
- package/dist/service/schemas.d.ts +8 -2
- package/dist/service/service.js +4 -1
- package/dist/service/workflows.js +6 -12
- package/dist/storage/sessions.js +26 -0
- package/package.json +1 -1
package/dist/migrate/storage.js
CHANGED
|
@@ -614,6 +614,18 @@ export const CHANNEL_LIMITS_TABLE = "_channel_limits";
|
|
|
614
614
|
* other user, nor a queued sign-in email, which needs an existing user, holds these.
|
|
615
615
|
*/
|
|
616
616
|
export const AGENT_GUEST_LINKS_TABLE = "_agent_guest_links";
|
|
617
|
+
/**
|
|
618
|
+
* The chats' messages, one row per message: what people and staff saw, with what the agent did
|
|
619
|
+
* with each inbound message (`disposition`) and the latest delivery state of each outbound one.
|
|
620
|
+
* A system table beside `agent_chat`, which stays the chat's record: no entity, history,
|
|
621
|
+
* replication or generated tools. See docs/agent-chat-storage.md.
|
|
622
|
+
*/
|
|
623
|
+
export const CHAT_MESSAGES_TABLE = "_chat_messages";
|
|
624
|
+
/**
|
|
625
|
+
* Where a chat message's `revision` comes from: set on insert and on every change readers see, so
|
|
626
|
+
* that "what changed since my bookmark" is one indexed range of a chat.
|
|
627
|
+
*/
|
|
628
|
+
export const CHAT_MESSAGE_REVISIONS = "_chat_messages_revision";
|
|
617
629
|
/** The agent's tables, in the order they are created. */
|
|
618
630
|
export const AGENT_TABLES = [
|
|
619
631
|
AGENT_PAIRINGS_TABLE,
|
|
@@ -624,12 +636,82 @@ export const AGENT_TABLES = [
|
|
|
624
636
|
CONFIRMATION_TABLE,
|
|
625
637
|
IDENTITY_NOTICES_TABLE,
|
|
626
638
|
AGENT_GUEST_LINKS_TABLE,
|
|
639
|
+
CHAT_MESSAGES_TABLE,
|
|
640
|
+
];
|
|
641
|
+
/**
|
|
642
|
+
* The chat messages' table, its revision sequence, and their keys: one row per provider message
|
|
643
|
+
* and one per send's idempotency key. Ids are made in the service (UUIDv7), so nothing depends on
|
|
644
|
+
* a PostgreSQL version. Every statement is idempotent.
|
|
645
|
+
*/
|
|
646
|
+
const CHAT_MESSAGES_DDL = [
|
|
647
|
+
`CREATE SEQUENCE IF NOT EXISTS "${CHAT_MESSAGE_REVISIONS}" AS bigint`,
|
|
648
|
+
[
|
|
649
|
+
`CREATE TABLE IF NOT EXISTS "${CHAT_MESSAGES_TABLE}" (`,
|
|
650
|
+
` "id" uuid NOT NULL,`,
|
|
651
|
+
` "channel" text NOT NULL,`,
|
|
652
|
+
` "chat_id" text NOT NULL,`,
|
|
653
|
+
` "thread_id" text,`,
|
|
654
|
+
` "chat_type" text NOT NULL,`,
|
|
655
|
+
` "participants" uuid[] NOT NULL DEFAULT '{}',`,
|
|
656
|
+
` "direction" text NOT NULL,`,
|
|
657
|
+
` "author" text NOT NULL,`,
|
|
658
|
+
` "sender_id" text,`,
|
|
659
|
+
` "sender_name" text,`,
|
|
660
|
+
` "user_id" uuid,`,
|
|
661
|
+
` "message_id" text,`,
|
|
662
|
+
` "reply_to" text,`,
|
|
663
|
+
` "text" text,`,
|
|
664
|
+
` "parts" jsonb NOT NULL DEFAULT '[]',`,
|
|
665
|
+
` "files" jsonb NOT NULL DEFAULT '[]',`,
|
|
666
|
+
` "reactions" jsonb NOT NULL DEFAULT '[]',`,
|
|
667
|
+
` "at" timestamptz NOT NULL,`,
|
|
668
|
+
` "edited_at" timestamptz,`,
|
|
669
|
+
` "deleted_at" timestamptz,`,
|
|
670
|
+
` "status" text,`,
|
|
671
|
+
` "failure" text,`,
|
|
672
|
+
` "operation" text,`,
|
|
673
|
+
` "fingerprint" text,`,
|
|
674
|
+
` "disposition" text,`,
|
|
675
|
+
` "reason" text,`,
|
|
676
|
+
` "disposition_at" timestamptz,`,
|
|
677
|
+
` "session_id" text,`,
|
|
678
|
+
` "turn_id" text,`,
|
|
679
|
+
` "meta" jsonb,`,
|
|
680
|
+
` "imported_at" timestamptz,`,
|
|
681
|
+
` "revision" bigint NOT NULL DEFAULT nextval('"${CHAT_MESSAGE_REVISIONS}"'),`,
|
|
682
|
+
` "purged_at" timestamptz,`,
|
|
683
|
+
` "replaced_by" uuid,`,
|
|
684
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_pkey" PRIMARY KEY ("id"),`,
|
|
685
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_chat_type_check" ` +
|
|
686
|
+
`CHECK ("chat_type" IN ('private', 'group', 'channel')),`,
|
|
687
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_direction_check" ` +
|
|
688
|
+
`CHECK ("direction" IN ('inbound', 'outbound', 'internal')),`,
|
|
689
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_author_check" ` +
|
|
690
|
+
`CHECK ("author" IN ('human', 'agent', 'bot')),`,
|
|
691
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_status_check" ` +
|
|
692
|
+
`CHECK ("status" IN ('pending', 'sent', 'delivered', 'read', 'failed', 'uncertain')),`,
|
|
693
|
+
` CONSTRAINT "${CHAT_MESSAGES_TABLE}_disposition_check" ` +
|
|
694
|
+
`CHECK ("disposition" IN ('claimed', 'turn', 'skipped'))`,
|
|
695
|
+
`)`,
|
|
696
|
+
].join("\n"),
|
|
697
|
+
// One row per provider message: a redelivery, an echo or an import of it changes nothing.
|
|
698
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS "${CHAT_MESSAGES_TABLE}_message_key" ` +
|
|
699
|
+
`ON "${CHAT_MESSAGES_TABLE}" ("channel", "chat_id", "message_id") ` +
|
|
700
|
+
`WHERE "message_id" IS NOT NULL`,
|
|
701
|
+
// One send per idempotency key: a retry finds its row, and a tombstone keeps the key.
|
|
702
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS "${CHAT_MESSAGES_TABLE}_operation_key" ` +
|
|
703
|
+
`ON "${CHAT_MESSAGES_TABLE}" ("operation") WHERE "operation" IS NOT NULL`,
|
|
704
|
+
`CREATE INDEX IF NOT EXISTS "${CHAT_MESSAGES_TABLE}_chat_at_idx" ` +
|
|
705
|
+
`ON "${CHAT_MESSAGES_TABLE}" ("channel", "chat_id", "at", "id")`,
|
|
706
|
+
`CREATE INDEX IF NOT EXISTS "${CHAT_MESSAGES_TABLE}_chat_revision_idx" ` +
|
|
707
|
+
`ON "${CHAT_MESSAGES_TABLE}" ("channel", "chat_id", "revision")`,
|
|
708
|
+
`CREATE INDEX IF NOT EXISTS "${CHAT_MESSAGES_TABLE}_at_idx" ON "${CHAT_MESSAGES_TABLE}" ("at")`,
|
|
627
709
|
];
|
|
628
710
|
/**
|
|
629
711
|
* The tables of the app's agent: pairing codes, stored only as SHA-256 hashes, the legacy channel
|
|
630
|
-
* identities they create,
|
|
631
|
-
* account and a member each have at most one live identity per provider.
|
|
632
|
-
* idempotent.
|
|
712
|
+
* identities they create, the first-contact notices of `user_identity` channel accounts, and the
|
|
713
|
+
* chats' messages. An account and a member each have at most one live identity per provider.
|
|
714
|
+
* Every statement is idempotent.
|
|
633
715
|
*/
|
|
634
716
|
export const AGENT_TABLES_DDL = [
|
|
635
717
|
...CONFIRMATION_DDL,
|
|
@@ -723,6 +805,7 @@ export const AGENT_TABLES_DDL = [
|
|
|
723
805
|
)`,
|
|
724
806
|
`CREATE INDEX IF NOT EXISTS "${AGENT_GUEST_LINKS_TABLE}_created_idx" ` +
|
|
725
807
|
`ON "${AGENT_GUEST_LINKS_TABLE}" ("created_at")`,
|
|
808
|
+
...CHAT_MESSAGES_DDL,
|
|
726
809
|
];
|
|
727
810
|
/**
|
|
728
811
|
* The runtime's own tables beside the catalog. They are created with it, after the entity tables
|
package/dist/runtime/agents.js
CHANGED
|
@@ -17,6 +17,7 @@ import { resolveAgentIdentity } from "./resolve-agent-identity.js";
|
|
|
17
17
|
import { completeAgentLimitNotice } from "./agent-counters.js";
|
|
18
18
|
import { isMemberBlocked, setMemberBlocked, resolveMemberById } from "./principals.js";
|
|
19
19
|
import { sqlAgentWebStore } from "./agent-web.js";
|
|
20
|
+
import { sqlChatMessageStore } from "./chat-messages.js";
|
|
20
21
|
import { guestChat } from "./guests.js";
|
|
21
22
|
import { WEB_PROVIDER } from "../service/runtime-identity.js";
|
|
22
23
|
import { isRecordId } from "./records.js";
|
|
@@ -1012,6 +1013,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
1012
1013
|
: timestampText(record.decided_at),
|
|
1013
1014
|
}));
|
|
1014
1015
|
}).pipe(Effect.orDie),
|
|
1016
|
+
chatMessages: sqlChatMessageStore(sql),
|
|
1015
1017
|
web: sqlAgentWebStore(ontology, sql, {
|
|
1016
1018
|
signUp: (visitorId) => resolveChannelSignIn(ontology, sql, { provider: WEB_PROVIDER, externalId: visitorId }),
|
|
1017
1019
|
}),
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import type { SqlClient } from "effect/unstable/sql";
|
|
3
|
+
/**
|
|
4
|
+
* The workspace's chat store: one row per message in `_chat_messages` (docs/agent-chat-storage.md,
|
|
5
|
+
* "The workspace chat store"). A message's state is its latest state: edits, deletions, reactions,
|
|
6
|
+
* delivery statuses and what the agent did with it change its row and take a new `revision`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHAT_TYPES: readonly ["private", "group", "channel"];
|
|
9
|
+
export declare const CHAT_DIRECTIONS: readonly ["inbound", "outbound", "internal"];
|
|
10
|
+
export declare const CHAT_MESSAGE_AUTHORS: readonly ["human", "agent", "bot"];
|
|
11
|
+
export declare const CHAT_MESSAGE_STATUSES: readonly ["pending", "sent", "delivered", "read", "failed", "uncertain"];
|
|
12
|
+
export declare const CHAT_DISPOSITIONS: readonly ["claimed", "turn", "skipped"];
|
|
13
|
+
export type ChatType = (typeof CHAT_TYPES)[number];
|
|
14
|
+
export type ChatDirection = (typeof CHAT_DIRECTIONS)[number];
|
|
15
|
+
export type ChatMessageAuthor = (typeof CHAT_MESSAGE_AUTHORS)[number];
|
|
16
|
+
export type ChatMessageStatus = (typeof CHAT_MESSAGE_STATUSES)[number];
|
|
17
|
+
export type ChatDisposition = (typeof CHAT_DISPOSITIONS)[number];
|
|
18
|
+
/** How long a claim on an inbound message holds: an abandoned one is taken again after it. */
|
|
19
|
+
export declare const CHAT_CLAIM_MINUTES = 10;
|
|
20
|
+
/** The most rows one purge batch deletes or scrubs, and the most batches one purge runs. */
|
|
21
|
+
export declare const CHAT_PURGE_BATCH = 1000;
|
|
22
|
+
export declare const CHAT_PURGE_BATCHES = 20;
|
|
23
|
+
/** A stored file of a message, by its `_agent_attachments` row. */
|
|
24
|
+
export interface ChatMessageFile {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly name?: string;
|
|
27
|
+
readonly type?: string;
|
|
28
|
+
readonly size?: number;
|
|
29
|
+
}
|
|
30
|
+
/** A reaction a message carries now: one per sender. */
|
|
31
|
+
export interface ChatReaction {
|
|
32
|
+
readonly senderId: string;
|
|
33
|
+
readonly emoji: string;
|
|
34
|
+
}
|
|
35
|
+
/** One message as the store holds it. Times are ISO 8601; `revision` is a decimal. */
|
|
36
|
+
export interface ChatMessage {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly channel: string;
|
|
39
|
+
readonly chatId: string;
|
|
40
|
+
readonly threadId: string | null;
|
|
41
|
+
readonly chatType: ChatType;
|
|
42
|
+
readonly participants: ReadonlyArray<string>;
|
|
43
|
+
readonly direction: ChatDirection;
|
|
44
|
+
readonly author: ChatMessageAuthor;
|
|
45
|
+
readonly senderId: string | null;
|
|
46
|
+
readonly senderName: string | null;
|
|
47
|
+
readonly userId: string | null;
|
|
48
|
+
readonly messageId: string | null;
|
|
49
|
+
readonly replyTo: string | null;
|
|
50
|
+
readonly text: string | null;
|
|
51
|
+
readonly parts: ReadonlyArray<unknown>;
|
|
52
|
+
readonly files: ReadonlyArray<ChatMessageFile>;
|
|
53
|
+
readonly reactions: ReadonlyArray<ChatReaction>;
|
|
54
|
+
readonly at: string;
|
|
55
|
+
readonly editedAt: string | null;
|
|
56
|
+
readonly deletedAt: string | null;
|
|
57
|
+
readonly status: ChatMessageStatus | null;
|
|
58
|
+
readonly failure: string | null;
|
|
59
|
+
readonly operation: string | null;
|
|
60
|
+
readonly disposition: ChatDisposition | null;
|
|
61
|
+
readonly reason: string | null;
|
|
62
|
+
readonly dispositionAt: string | null;
|
|
63
|
+
readonly sessionId: string | null;
|
|
64
|
+
readonly turnId: string | null;
|
|
65
|
+
readonly meta: unknown;
|
|
66
|
+
readonly importedAt: string | null;
|
|
67
|
+
readonly revision: string;
|
|
68
|
+
/**
|
|
69
|
+
* The message this row became: a provider's echo the send's own row took over. Only reads after
|
|
70
|
+
* a revision return such a row, so a reader that kept it drops it.
|
|
71
|
+
*/
|
|
72
|
+
readonly replacedBy: string | null;
|
|
73
|
+
}
|
|
74
|
+
/** A message to record. */
|
|
75
|
+
export interface ChatMessageInput {
|
|
76
|
+
readonly channel: string;
|
|
77
|
+
readonly chatId: string;
|
|
78
|
+
readonly threadId?: string;
|
|
79
|
+
readonly chatType: ChatType;
|
|
80
|
+
readonly participants: ReadonlyArray<string>;
|
|
81
|
+
readonly direction: ChatDirection;
|
|
82
|
+
readonly author: ChatMessageAuthor;
|
|
83
|
+
readonly senderId?: string;
|
|
84
|
+
readonly senderName?: string;
|
|
85
|
+
readonly userId?: string;
|
|
86
|
+
readonly messageId?: string;
|
|
87
|
+
readonly replyTo?: string;
|
|
88
|
+
readonly text?: string;
|
|
89
|
+
readonly parts?: ReadonlyArray<unknown>;
|
|
90
|
+
readonly files?: ReadonlyArray<ChatMessageFile>;
|
|
91
|
+
readonly at?: string;
|
|
92
|
+
readonly status?: ChatMessageStatus;
|
|
93
|
+
readonly operation?: string;
|
|
94
|
+
readonly fingerprint?: string;
|
|
95
|
+
readonly sessionId?: string;
|
|
96
|
+
readonly turnId?: string;
|
|
97
|
+
readonly meta?: unknown;
|
|
98
|
+
}
|
|
99
|
+
/** The message a change is to, by the provider's id of it. */
|
|
100
|
+
interface Target {
|
|
101
|
+
readonly channel: string;
|
|
102
|
+
readonly chatId: string;
|
|
103
|
+
readonly messageId: string;
|
|
104
|
+
}
|
|
105
|
+
/** One change to a message. `sent` finds its message by the send's `operation` instead. */
|
|
106
|
+
export type ChatMessageChange = (Target & {
|
|
107
|
+
readonly change: "edit";
|
|
108
|
+
readonly text: string;
|
|
109
|
+
readonly at?: string;
|
|
110
|
+
}) | (Target & {
|
|
111
|
+
readonly change: "delete";
|
|
112
|
+
readonly at?: string;
|
|
113
|
+
}) | (Target & {
|
|
114
|
+
readonly change: "reaction";
|
|
115
|
+
readonly senderId: string;
|
|
116
|
+
readonly emoji: string;
|
|
117
|
+
}) | (Target & {
|
|
118
|
+
readonly change: "status";
|
|
119
|
+
readonly status: "sent" | "delivered" | "read" | "failed";
|
|
120
|
+
readonly failure?: string;
|
|
121
|
+
}) | (Target & {
|
|
122
|
+
readonly change: "disposition";
|
|
123
|
+
readonly disposition: ChatDisposition;
|
|
124
|
+
readonly reason?: string;
|
|
125
|
+
readonly sessionId?: string;
|
|
126
|
+
readonly turnId?: string;
|
|
127
|
+
}) | {
|
|
128
|
+
readonly change: "sent";
|
|
129
|
+
readonly channel: string;
|
|
130
|
+
readonly chatId: string;
|
|
131
|
+
readonly operation: string;
|
|
132
|
+
readonly status: "sent" | "failed" | "uncertain";
|
|
133
|
+
readonly providerMessageId?: string;
|
|
134
|
+
readonly failure?: string;
|
|
135
|
+
} | (Target & {
|
|
136
|
+
readonly change: "meta";
|
|
137
|
+
readonly meta: unknown;
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* A place in a chat, newest first: messages before `at`, and at `at` those whose id sorts before
|
|
141
|
+
* `id`. Written `<ISO time>~<id>`, or `<ISO time>` alone.
|
|
142
|
+
*/
|
|
143
|
+
export interface ChatCursor {
|
|
144
|
+
readonly at: string;
|
|
145
|
+
readonly id?: string;
|
|
146
|
+
}
|
|
147
|
+
/** The cursor a page continues at; `undefined` for text that is none. */
|
|
148
|
+
export declare function parseChatCursor(value: string): ChatCursor | undefined;
|
|
149
|
+
export declare function chatCursorOf(message: Pick<ChatMessage, "at" | "id">): string;
|
|
150
|
+
/** The runtime's reads of one chat, or with `pending` of every chat of a channel. */
|
|
151
|
+
export interface ChatMessageQuery {
|
|
152
|
+
readonly channel: string;
|
|
153
|
+
readonly chatId?: string;
|
|
154
|
+
/** A thread's messages; `null` for those in no thread; absent for every thread. */
|
|
155
|
+
readonly threadId?: string | null;
|
|
156
|
+
/** The messages changed after this revision, oldest change first. */
|
|
157
|
+
readonly after?: string;
|
|
158
|
+
readonly before?: ChatCursor;
|
|
159
|
+
readonly messageId?: string;
|
|
160
|
+
/** Outbound messages still `pending`: sends still to deliver. */
|
|
161
|
+
readonly pending?: boolean;
|
|
162
|
+
readonly limit: number;
|
|
163
|
+
}
|
|
164
|
+
/** A reader's search of one chat, as `chat_history` and `chat_search` ask it. */
|
|
165
|
+
export interface ChatMessageSearch {
|
|
166
|
+
readonly channel: string;
|
|
167
|
+
readonly chatId: string;
|
|
168
|
+
readonly threadId?: string;
|
|
169
|
+
readonly q?: string;
|
|
170
|
+
readonly senderId?: string;
|
|
171
|
+
readonly from?: string;
|
|
172
|
+
readonly to?: string;
|
|
173
|
+
readonly after?: string;
|
|
174
|
+
readonly before?: ChatCursor;
|
|
175
|
+
readonly limit: number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Who reads, as the chat archive's reader rule takes it: every group message (`groups`, from
|
|
179
|
+
* `agent_chat:read` or membership of the chat), this exact chat's messages, never its internal
|
|
180
|
+
* rows nor sends still unsent (`chat`, a chat the ontology checked the reader may read), and the
|
|
181
|
+
* private messages whose `participants` hold `participantId`, row by row.
|
|
182
|
+
*/
|
|
183
|
+
export interface ChatMessageReader {
|
|
184
|
+
readonly participantId: string | null;
|
|
185
|
+
readonly groups: boolean;
|
|
186
|
+
readonly chat: boolean;
|
|
187
|
+
}
|
|
188
|
+
export interface ChatMessagePage {
|
|
189
|
+
readonly messages: ReadonlyArray<ChatMessage>;
|
|
190
|
+
/** `after` mode: the revision to read after next; otherwise the cursor of the next page. */
|
|
191
|
+
readonly nextCursor: string | null;
|
|
192
|
+
}
|
|
193
|
+
declare const ChatMessageConflict_base: Schema.Class<ChatMessageConflict, Schema.TaggedStruct<"ChatMessageConflict", {
|
|
194
|
+
readonly code: Schema.Literals<readonly ["operation_conflict", "message_conflict"]>;
|
|
195
|
+
}>, import("effect/Cause").YieldableError>;
|
|
196
|
+
/** An operation replayed with another request, or a provider id another send holds. */
|
|
197
|
+
export declare class ChatMessageConflict extends ChatMessageConflict_base {
|
|
198
|
+
}
|
|
199
|
+
export interface ChatMessageStore {
|
|
200
|
+
/** Records a message once by `(channel, chatId, messageId)` and once by `operation`. */
|
|
201
|
+
readonly record: (input: ChatMessageInput) => Effect.Effect<{
|
|
202
|
+
readonly id: string;
|
|
203
|
+
readonly first: boolean;
|
|
204
|
+
}, ChatMessageConflict>;
|
|
205
|
+
/** Applies one change; `applied` is false when there was nothing to change. */
|
|
206
|
+
readonly change: (input: ChatMessageChange) => Effect.Effect<{
|
|
207
|
+
readonly applied: boolean;
|
|
208
|
+
}, ChatMessageConflict>;
|
|
209
|
+
readonly read: (input: ChatMessageQuery) => Effect.Effect<ChatMessagePage>;
|
|
210
|
+
/** Whether the store holds a message of the chat. */
|
|
211
|
+
readonly holds: (chat: {
|
|
212
|
+
readonly channel: string;
|
|
213
|
+
readonly chatId: string;
|
|
214
|
+
}) => Effect.Effect<boolean>;
|
|
215
|
+
/** One chat's messages as a reader may read them, row by row. */
|
|
216
|
+
readonly search: (search: ChatMessageSearch, reader: ChatMessageReader) => Effect.Effect<ChatMessagePage>;
|
|
217
|
+
/**
|
|
218
|
+
* Deletes the messages older than `retentionDays`, in bounded batches, and scrubs a send's row to
|
|
219
|
+
* its tombstone instead: content and coordinates go, its `operation` key and outcome stay, so a
|
|
220
|
+
* replay of the key never sends again. Kept files are not touched.
|
|
221
|
+
*/
|
|
222
|
+
readonly purge: (input: {
|
|
223
|
+
readonly retentionDays: number;
|
|
224
|
+
}) => Effect.Effect<{
|
|
225
|
+
readonly deleted: number;
|
|
226
|
+
readonly scrubbed: number;
|
|
227
|
+
/** The last batch was full: older messages may remain for the next run. */
|
|
228
|
+
readonly more: boolean;
|
|
229
|
+
}>;
|
|
230
|
+
}
|
|
231
|
+
/** The chat store on `_chat_messages`, as `ontology_app`. Failures are defects. */
|
|
232
|
+
export declare function sqlChatMessageStore(sql: SqlClient.SqlClient): ChatMessageStore;
|
|
233
|
+
export {};
|