@miniaxolotl/grove-server 1.11.3 → 1.11.6
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/dist/bootstrap.js +801 -1
- package/dist/bootstrap.js.map +4 -4
- package/dist/migrate.js +801 -1
- package/dist/migrate.js.map +4 -4
- package/dist/server.js +5253 -1043
- package/dist/server.js.map +4 -4
- package/dist/telemetry-build.json +1 -1
- package/dist/worker.js +3802 -693
- package/dist/worker.js.map +4 -4
- package/package.json +4 -1
package/dist/bootstrap.js
CHANGED
|
@@ -4,6 +4,382 @@ import { createRequire as __groveCreateRequire } from "node:module"; const requi
|
|
|
4
4
|
import knex from "knex";
|
|
5
5
|
import { Model, knexSnakeCaseMappers } from "objection";
|
|
6
6
|
|
|
7
|
+
// lib/database/src/action-usage-migration.ts
|
|
8
|
+
var actionUsage = {
|
|
9
|
+
name: "20261025_028_action_usage",
|
|
10
|
+
async up(db2) {
|
|
11
|
+
await db2.raw(`
|
|
12
|
+
CREATE TABLE action_usage (
|
|
13
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), account_id uuid NOT NULL REFERENCES accounts(id),
|
|
14
|
+
metric text NOT NULL CHECK(metric IN ('recall','ask','organization','assistance')),
|
|
15
|
+
operation text NOT NULL CHECK(length(operation) BETWEEN 1 AND 256), period date NOT NULL,
|
|
16
|
+
status text NOT NULL CHECK(status IN ('reserved','completed','released')), worked boolean NOT NULL DEFAULT false,
|
|
17
|
+
lease_id uuid NOT NULL, lease_until timestamptz NOT NULL,
|
|
18
|
+
created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now(),
|
|
19
|
+
UNIQUE(account_id,metric,operation)
|
|
20
|
+
);
|
|
21
|
+
CREATE INDEX action_usage_period ON action_usage(account_id,period,metric,status);
|
|
22
|
+
CREATE TABLE ai_operation_leases (
|
|
23
|
+
id uuid PRIMARY KEY, account_id uuid NOT NULL REFERENCES accounts(id),
|
|
24
|
+
lease_until timestamptz NOT NULL, created_at timestamptz NOT NULL DEFAULT now()
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX ai_operation_leases_account ON ai_operation_leases(account_id,lease_until);
|
|
27
|
+
`);
|
|
28
|
+
for (const table of ["action_usage", "ai_operation_leases"]) {
|
|
29
|
+
await db2.raw("ALTER TABLE ?? ENABLE ROW LEVEL SECURITY", [table]);
|
|
30
|
+
await db2.raw("ALTER TABLE ?? FORCE ROW LEVEL SECURITY", [table]);
|
|
31
|
+
await db2.raw(
|
|
32
|
+
`CREATE POLICY tenant ON ?? USING(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid)
|
|
33
|
+
WITH CHECK(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid)`,
|
|
34
|
+
[table]
|
|
35
|
+
);
|
|
36
|
+
await db2.raw(
|
|
37
|
+
"GRANT SELECT,INSERT,UPDATE,DELETE ON ?? TO grove_runtime,grove_worker",
|
|
38
|
+
[table]
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async down() {
|
|
43
|
+
throw new Error("Use a forward migration");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// lib/database/src/conversation-context-migration.ts
|
|
48
|
+
var conversationContext = {
|
|
49
|
+
name: "20261025_030_conversation_context",
|
|
50
|
+
async up(db2) {
|
|
51
|
+
await db2.raw("ALTER TABLE conversation_turns ADD COLUMN context jsonb");
|
|
52
|
+
},
|
|
53
|
+
async down() {
|
|
54
|
+
throw new Error("Use a forward migration");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// lib/database/src/search-quality-migration.ts
|
|
59
|
+
var searchQuality = {
|
|
60
|
+
name: "20261025_029_search_quality",
|
|
61
|
+
async up(db2) {
|
|
62
|
+
await db2.raw(String.raw`
|
|
63
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
64
|
+
CREATE FUNCTION grove_search_title(note_content text, organized_title text)
|
|
65
|
+
RETURNS text LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE
|
|
66
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
67
|
+
DECLARE whitespace text := E' \t\n\r\v\f' || chr(160) || chr(5760) ||
|
|
68
|
+
chr(8192)||chr(8193)||chr(8194)||chr(8195)||chr(8196)||chr(8197)||
|
|
69
|
+
chr(8198)||chr(8199)||chr(8200)||chr(8201)||chr(8202)||chr(8232)||
|
|
70
|
+
chr(8233)||chr(8239)||chr(8287)||chr(12288)||chr(65279);
|
|
71
|
+
first_line text; heading text; value text; result text := '';
|
|
72
|
+
units integer := 0; c text; i integer;
|
|
73
|
+
BEGIN
|
|
74
|
+
first_line := split_part(btrim(note_content,whitespace), E'\n',1);
|
|
75
|
+
heading := btrim(substring(first_line FROM ('^#{1,6}['||whitespace||']+(.+)')),whitespace);
|
|
76
|
+
IF heading IS NOT NULL AND heading<>'' THEN value:=heading;
|
|
77
|
+
ELSIF organized_title IS NOT NULL AND organized_title<>'' THEN RETURN organized_title;
|
|
78
|
+
ELSE value:=first_line; END IF;
|
|
79
|
+
IF length(value)<=55 THEN RETURN value; END IF;
|
|
80
|
+
IF octet_length(value)=length(value) THEN RETURN left(value,110); END IF;
|
|
81
|
+
FOR i IN 1..least(length(value),110) LOOP
|
|
82
|
+
c:=substr(value,i,1);
|
|
83
|
+
units:=units+CASE WHEN ascii(c)>65535 THEN 2 ELSE 1 END;
|
|
84
|
+
EXIT WHEN units>110;
|
|
85
|
+
result:=result||c;
|
|
86
|
+
END LOOP;
|
|
87
|
+
RETURN result;
|
|
88
|
+
END $$;
|
|
89
|
+
REVOKE ALL ON FUNCTION grove_search_title(text,text) FROM PUBLIC;
|
|
90
|
+
GRANT EXECUTE ON FUNCTION grove_search_title(text,text) TO grove_runtime,grove_worker;
|
|
91
|
+
`);
|
|
92
|
+
},
|
|
93
|
+
async down() {
|
|
94
|
+
throw new Error("Use a forward migration");
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// lib/database/src/conversation-document-migration.ts
|
|
99
|
+
var conversationDocuments = {
|
|
100
|
+
name: "20261025_032_conversation_documents",
|
|
101
|
+
async up(db2) {
|
|
102
|
+
await db2.raw(`
|
|
103
|
+
ALTER TABLE conversations ADD COLUMN documents_version integer NOT NULL DEFAULT 0;
|
|
104
|
+
ALTER TABLE conversation_turns ADD COLUMN document_snapshot jsonb NOT NULL DEFAULT '[]',ADD COLUMN documents_version integer;
|
|
105
|
+
ALTER TABLE background_tasks DROP CONSTRAINT background_tasks_kind_check;
|
|
106
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_kind_check CHECK(kind IN
|
|
107
|
+
('export','account_cleanup','retention_cleanup','artifact_cleanup','model_backfill','import','connector_sync','speech_transcribe','speech_synthesize','document_prepare','document_import','conversation_document'));
|
|
108
|
+
CREATE TABLE conversation_documents (
|
|
109
|
+
account_id uuid NOT NULL,conversation_id uuid NOT NULL,id uuid NOT NULL,
|
|
110
|
+
filename text NOT NULL CHECK(length(filename) BETWEEN 1 AND 200),bytes integer NOT NULL CHECK(bytes BETWEEN 1 AND 3145728),
|
|
111
|
+
sha256 text NOT NULL CHECK(sha256 ~ '^[0-9a-f]{64}$'),staging bytea CHECK(octet_length(staging)<=3145728),
|
|
112
|
+
mime text,status text NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','ready','failed')),
|
|
113
|
+
version integer NOT NULL DEFAULT 1,task_id uuid NOT NULL,error text,pages integer,empty_pages jsonb NOT NULL DEFAULT '[]',
|
|
114
|
+
object_key text,accepted boolean NOT NULL DEFAULT false,accept_lease uuid,accept_until timestamptz,
|
|
115
|
+
created_at timestamptz NOT NULL DEFAULT now(),expires_at timestamptz NOT NULL DEFAULT now()+interval '1 day',removed_at timestamptz,
|
|
116
|
+
PRIMARY KEY(account_id,id),FOREIGN KEY(account_id,conversation_id) REFERENCES conversations(account_id,id),
|
|
117
|
+
FOREIGN KEY(account_id,task_id) REFERENCES background_tasks(account_id,id)
|
|
118
|
+
);
|
|
119
|
+
CREATE INDEX conversation_documents_chat ON conversation_documents(account_id,conversation_id,created_at,id);
|
|
120
|
+
CREATE TABLE conversation_document_chunks (
|
|
121
|
+
account_id uuid NOT NULL,document_id uuid NOT NULL,id uuid NOT NULL,ordinal integer NOT NULL,
|
|
122
|
+
content text NOT NULL CHECK(length(content) BETWEEN 1 AND 6000),page_start integer NOT NULL,page_end integer NOT NULL,
|
|
123
|
+
source_start integer NOT NULL,source_end integer NOT NULL,
|
|
124
|
+
search tsvector GENERATED ALWAYS AS(to_tsvector('english',content)) STORED,
|
|
125
|
+
PRIMARY KEY(account_id,id),UNIQUE(account_id,document_id,ordinal),
|
|
126
|
+
FOREIGN KEY(account_id,document_id) REFERENCES conversation_documents(account_id,id)
|
|
127
|
+
);
|
|
128
|
+
CREATE INDEX conversation_document_search ON conversation_document_chunks USING gin(search);
|
|
129
|
+
CREATE TABLE conversation_document_attempts (
|
|
130
|
+
account_id uuid NOT NULL,document_id uuid NOT NULL,id uuid NOT NULL,object_key text NOT NULL UNIQUE,
|
|
131
|
+
created_at timestamptz NOT NULL DEFAULT now(),PRIMARY KEY(account_id,id),
|
|
132
|
+
FOREIGN KEY(account_id,document_id) REFERENCES conversation_documents(account_id,id)
|
|
133
|
+
);
|
|
134
|
+
CREATE TABLE conversation_document_imports (
|
|
135
|
+
account_id uuid NOT NULL,id uuid NOT NULL,conversation_id uuid NOT NULL,version integer NOT NULL,batch_id uuid NOT NULL,
|
|
136
|
+
PRIMARY KEY(account_id,id),FOREIGN KEY(account_id,conversation_id) REFERENCES conversations(account_id,id),
|
|
137
|
+
FOREIGN KEY(account_id,batch_id) REFERENCES document_import_batches(account_id,id)
|
|
138
|
+
);
|
|
139
|
+
CREATE TABLE conversation_document_bindings (
|
|
140
|
+
account_id uuid NOT NULL,memory_id uuid NOT NULL,version integer NOT NULL,document_id uuid NOT NULL,
|
|
141
|
+
chunk_id uuid NOT NULL,quote text NOT NULL,
|
|
142
|
+
PRIMARY KEY(account_id,memory_id,version,chunk_id),
|
|
143
|
+
FOREIGN KEY(account_id,memory_id) REFERENCES memories(account_id,id),
|
|
144
|
+
FOREIGN KEY(account_id,document_id) REFERENCES conversation_documents(account_id,id),
|
|
145
|
+
FOREIGN KEY(account_id,chunk_id) REFERENCES conversation_document_chunks(account_id,id)
|
|
146
|
+
);
|
|
147
|
+
CREATE TABLE conversation_document_handoffs (
|
|
148
|
+
account_id uuid NOT NULL,id uuid NOT NULL,batch_id uuid NOT NULL,version integer NOT NULL,
|
|
149
|
+
PRIMARY KEY(account_id,id),FOREIGN KEY(account_id,id) REFERENCES conversations(account_id,id),
|
|
150
|
+
FOREIGN KEY(account_id,batch_id) REFERENCES document_import_batches(account_id,id)
|
|
151
|
+
);
|
|
152
|
+
`);
|
|
153
|
+
for (const table of [
|
|
154
|
+
"conversation_documents",
|
|
155
|
+
"conversation_document_chunks",
|
|
156
|
+
"conversation_document_attempts",
|
|
157
|
+
"conversation_document_imports",
|
|
158
|
+
"conversation_document_bindings",
|
|
159
|
+
"conversation_document_handoffs"
|
|
160
|
+
]) {
|
|
161
|
+
await db2.raw(
|
|
162
|
+
"ALTER TABLE ?? ENABLE ROW LEVEL SECURITY; ALTER TABLE ?? FORCE ROW LEVEL SECURITY",
|
|
163
|
+
[table, table]
|
|
164
|
+
);
|
|
165
|
+
await db2.raw(
|
|
166
|
+
`CREATE POLICY tenant ON ?? USING(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid) WITH CHECK(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid)`,
|
|
167
|
+
[table]
|
|
168
|
+
);
|
|
169
|
+
await db2.raw(
|
|
170
|
+
`CREATE POLICY active_owner ON ?? AS RESTRICTIVE USING(EXISTS(SELECT 1 FROM accounts a WHERE a.id=??.account_id AND a.status='active')) WITH CHECK(true)`,
|
|
171
|
+
[table, table]
|
|
172
|
+
);
|
|
173
|
+
await db2.raw(
|
|
174
|
+
"GRANT SELECT,INSERT,UPDATE ON ?? TO grove_runtime,grove_worker",
|
|
175
|
+
[table]
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
await db2.raw(`
|
|
179
|
+
CREATE POLICY visible_chat ON conversation_documents AS RESTRICTIVE USING
|
|
180
|
+
(EXISTS(SELECT 1 FROM conversations c WHERE c.account_id=conversation_documents.account_id AND c.id=conversation_documents.conversation_id AND c.deleted_at IS NULL)
|
|
181
|
+
OR EXISTS(SELECT 1 FROM conversation_document_bindings b JOIN memories m ON m.account_id=b.account_id AND m.id=b.memory_id
|
|
182
|
+
WHERE b.account_id=conversation_documents.account_id AND b.document_id=conversation_documents.id AND m.deleted_at IS NULL)) WITH CHECK(true);
|
|
183
|
+
CREATE POLICY visible_memory ON conversation_document_bindings AS RESTRICTIVE USING
|
|
184
|
+
(EXISTS(SELECT 1 FROM memories m WHERE m.account_id=conversation_document_bindings.account_id AND m.id=conversation_document_bindings.memory_id AND m.deleted_at IS NULL)) WITH CHECK(true);
|
|
185
|
+
CREATE POLICY visible_document ON conversation_document_chunks AS RESTRICTIVE USING
|
|
186
|
+
(EXISTS(SELECT 1 FROM conversation_documents d WHERE d.account_id=conversation_document_chunks.account_id AND d.id=conversation_document_chunks.document_id AND d.removed_at IS NULL)) WITH CHECK(true);
|
|
187
|
+
REVOKE UPDATE ON conversation_document_attempts,conversation_document_imports,conversation_document_bindings,conversation_document_handoffs FROM grove_runtime,grove_worker;
|
|
188
|
+
CREATE FUNCTION grove_immutable_chat_document() RETURNS trigger LANGUAGE plpgsql SET search_path=pg_catalog,public,pg_temp AS $$
|
|
189
|
+
BEGIN
|
|
190
|
+
IF (NEW.account_id,NEW.conversation_id,NEW.id,NEW.filename,NEW.bytes,NEW.sha256,NEW.version) IS DISTINCT FROM
|
|
191
|
+
(OLD.account_id,OLD.conversation_id,OLD.id,OLD.filename,OLD.bytes,OLD.sha256,OLD.version) THEN RAISE EXCEPTION 'document_identity_immutable'; END IF;
|
|
192
|
+
IF OLD.accepted AND (NEW.object_key,NEW.mime,NEW.pages,NEW.accepted,NEW.staging,NEW.status) IS DISTINCT FROM
|
|
193
|
+
(OLD.object_key,OLD.mime,OLD.pages,OLD.accepted,OLD.staging,OLD.status) THEN RAISE EXCEPTION 'document_source_immutable'; END IF;
|
|
194
|
+
RETURN NEW;
|
|
195
|
+
END $$;
|
|
196
|
+
REVOKE ALL ON FUNCTION grove_immutable_chat_document() FROM PUBLIC;
|
|
197
|
+
CREATE TRIGGER immutable_chat_document BEFORE UPDATE ON conversation_documents FOR EACH ROW EXECUTE FUNCTION grove_immutable_chat_document();
|
|
198
|
+
CREATE FUNCTION grove_chat_document_chunks_immutable() RETURNS trigger LANGUAGE plpgsql SET search_path=pg_catalog,public,pg_temp AS $$
|
|
199
|
+
BEGIN
|
|
200
|
+
IF TG_OP='UPDATE' AND (NEW.account_id,NEW.id,NEW.document_id,NEW.ordinal,NEW.page_start,NEW.page_end,NEW.source_start,NEW.source_end)
|
|
201
|
+
IS DISTINCT FROM (OLD.account_id,OLD.id,OLD.document_id,OLD.ordinal,OLD.page_start,OLD.page_end,OLD.source_start,OLD.source_end) THEN RAISE EXCEPTION 'document_identity_immutable'; END IF;
|
|
202
|
+
IF EXISTS(SELECT 1 FROM conversation_documents d WHERE d.account_id=NEW.account_id AND d.id=NEW.document_id AND d.accepted) THEN RAISE EXCEPTION 'document_source_immutable'; END IF;
|
|
203
|
+
RETURN NEW;
|
|
204
|
+
END $$;
|
|
205
|
+
REVOKE ALL ON FUNCTION grove_chat_document_chunks_immutable() FROM PUBLIC;
|
|
206
|
+
CREATE TRIGGER immutable_chat_chunks BEFORE INSERT OR UPDATE ON conversation_document_chunks FOR EACH ROW EXECUTE FUNCTION grove_chat_document_chunks_immutable();
|
|
207
|
+
CREATE FUNCTION grove_clear_chat_uploads() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
208
|
+
DECLARE previous_scope text; owner_id uuid; chat_id uuid;
|
|
209
|
+
BEGIN
|
|
210
|
+
previous_scope:=current_setting('grove.account_id',true);
|
|
211
|
+
IF TG_TABLE_NAME='accounts' THEN owner_id:=OLD.id;chat_id:=NULL;ELSE owner_id:=OLD.account_id;chat_id:=OLD.id;END IF;
|
|
212
|
+
PERFORM set_config('grove.account_id',owner_id::text,true);
|
|
213
|
+
UPDATE conversation_document_chunks SET content='[Upload unavailable]' WHERE account_id=owner_id AND document_id IN
|
|
214
|
+
(SELECT id FROM conversation_documents WHERE account_id=owner_id AND NOT accepted AND removed_at IS NULL AND (chat_id IS NULL OR conversation_id=chat_id));
|
|
215
|
+
UPDATE conversation_documents SET staging=NULL,removed_at=now(),accept_lease=NULL,accept_until=NULL WHERE account_id=owner_id AND NOT accepted AND (chat_id IS NULL OR conversation_id=chat_id);
|
|
216
|
+
PERFORM set_config('grove.account_id',coalesce(previous_scope,''),true);
|
|
217
|
+
RETURN NEW;
|
|
218
|
+
END $$;
|
|
219
|
+
REVOKE ALL ON FUNCTION grove_clear_chat_uploads() FROM PUBLIC;
|
|
220
|
+
CREATE TRIGGER clear_account_chat_uploads BEFORE UPDATE OF status ON accounts FOR EACH ROW WHEN(OLD.status='active' AND NEW.status<>'active') EXECUTE FUNCTION grove_clear_chat_uploads();
|
|
221
|
+
CREATE TRIGGER clear_deleted_chat_uploads BEFORE UPDATE OF deleted_at ON conversations FOR EACH ROW WHEN(OLD.deleted_at IS NULL AND NEW.deleted_at IS NOT NULL) EXECUTE FUNCTION grove_clear_chat_uploads();
|
|
222
|
+
`);
|
|
223
|
+
const { rows } = await db2.raw(
|
|
224
|
+
"SELECT pg_get_functiondef('grove_schedule_cleanup()'::regprocedure) AS definition"
|
|
225
|
+
);
|
|
226
|
+
await db2.raw(
|
|
227
|
+
rows[0].definition.replace(
|
|
228
|
+
"OR EXISTS(SELECT 1 FROM document_import_batches b",
|
|
229
|
+
"OR EXISTS(SELECT 1 FROM conversation_documents d WHERE d.account_id=a.id AND NOT d.accepted AND d.removed_at IS NULL AND d.expires_at<=now()) OR EXISTS(SELECT 1 FROM document_import_batches b"
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
},
|
|
233
|
+
async down() {
|
|
234
|
+
throw new Error("Use a forward migration");
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// lib/database/src/document-import-migration.ts
|
|
239
|
+
var documentImports = {
|
|
240
|
+
name: "20261025_031_document_imports",
|
|
241
|
+
async up(db2) {
|
|
242
|
+
await db2.raw(`
|
|
243
|
+
ALTER TABLE background_tasks DROP CONSTRAINT background_tasks_kind_check;
|
|
244
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_kind_check CHECK(kind IN
|
|
245
|
+
('export','account_cleanup','retention_cleanup','artifact_cleanup','model_backfill','import','connector_sync','speech_transcribe','speech_synthesize','document_prepare','document_import'));
|
|
246
|
+
CREATE TABLE document_import_batches (
|
|
247
|
+
account_id uuid NOT NULL REFERENCES accounts(id), id uuid NOT NULL,
|
|
248
|
+
version integer NOT NULL DEFAULT 1, status text NOT NULL DEFAULT 'uploading'
|
|
249
|
+
CHECK(status IN ('uploading','preparing','ready','applying','complete','cancelled')),
|
|
250
|
+
task_id uuid, confirm_id uuid, confirm_hash text, suggestion_id uuid, created_at timestamptz NOT NULL DEFAULT now(),
|
|
251
|
+
suggestion_request_id uuid, suggestion_hash text, suggestion_lease uuid, suggestion_until timestamptz,
|
|
252
|
+
expires_at timestamptz NOT NULL DEFAULT now()+interval '1 day',
|
|
253
|
+
drafts_cleared boolean NOT NULL DEFAULT false,
|
|
254
|
+
PRIMARY KEY(account_id,id), FOREIGN KEY(account_id,task_id) REFERENCES background_tasks(account_id,id)
|
|
255
|
+
);
|
|
256
|
+
CREATE TABLE document_import_files (
|
|
257
|
+
account_id uuid NOT NULL, batch_id uuid NOT NULL, id uuid NOT NULL,
|
|
258
|
+
filename text NOT NULL CHECK(length(filename) BETWEEN 1 AND 200),
|
|
259
|
+
bytes integer NOT NULL CHECK(bytes BETWEEN 1 AND 3145728), sha256 text NOT NULL,
|
|
260
|
+
staging bytea CHECK(octet_length(staging)<=3145728), mime text,
|
|
261
|
+
status text NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','ready','failed')),
|
|
262
|
+
error text, pages integer, empty_pages jsonb NOT NULL DEFAULT '[]',
|
|
263
|
+
object_key text, original_ready boolean NOT NULL DEFAULT false,
|
|
264
|
+
PRIMARY KEY(account_id,batch_id,id), UNIQUE(account_id,id),
|
|
265
|
+
FOREIGN KEY(account_id,batch_id) REFERENCES document_import_batches(account_id,id)
|
|
266
|
+
);
|
|
267
|
+
CREATE TABLE document_import_notes (
|
|
268
|
+
account_id uuid NOT NULL, batch_id uuid NOT NULL, id uuid NOT NULL,
|
|
269
|
+
file_id uuid NOT NULL, ordinal integer NOT NULL, content text NOT NULL CHECK(length(content) BETWEEN 1 AND 6000),
|
|
270
|
+
included boolean NOT NULL DEFAULT true, destination jsonb NOT NULL DEFAULT 'null', suggestion text,
|
|
271
|
+
page_start integer NOT NULL, page_end integer NOT NULL, source_start integer NOT NULL, source_end integer NOT NULL,
|
|
272
|
+
memory_id uuid, PRIMARY KEY(account_id,batch_id,id), UNIQUE(account_id,batch_id,file_id,ordinal),
|
|
273
|
+
FOREIGN KEY(account_id,batch_id,file_id) REFERENCES document_import_files(account_id,batch_id,id),
|
|
274
|
+
FOREIGN KEY(account_id,memory_id) REFERENCES memories(account_id,id)
|
|
275
|
+
);
|
|
276
|
+
CREATE INDEX document_import_expiry ON document_import_batches(account_id,expires_at);
|
|
277
|
+
CREATE INDEX document_import_note_page ON document_import_notes(account_id,batch_id,id);
|
|
278
|
+
CREATE INDEX document_import_sources ON document_import_notes(account_id,memory_id) WHERE memory_id IS NOT NULL;
|
|
279
|
+
CREATE TABLE document_import_attempts (
|
|
280
|
+
account_id uuid NOT NULL, batch_id uuid NOT NULL, file_id uuid NOT NULL, id uuid NOT NULL,
|
|
281
|
+
object_key text NOT NULL UNIQUE, created_at timestamptz NOT NULL DEFAULT now(),
|
|
282
|
+
PRIMARY KEY(account_id,id), FOREIGN KEY(account_id,batch_id,file_id) REFERENCES document_import_files(account_id,batch_id,id)
|
|
283
|
+
);
|
|
284
|
+
`);
|
|
285
|
+
for (const table of [
|
|
286
|
+
"document_import_batches",
|
|
287
|
+
"document_import_files",
|
|
288
|
+
"document_import_notes",
|
|
289
|
+
"document_import_attempts"
|
|
290
|
+
]) {
|
|
291
|
+
await db2.raw(
|
|
292
|
+
`ALTER TABLE ?? ENABLE ROW LEVEL SECURITY; ALTER TABLE ?? FORCE ROW LEVEL SECURITY`,
|
|
293
|
+
[table, table]
|
|
294
|
+
);
|
|
295
|
+
await db2.raw(
|
|
296
|
+
`CREATE POLICY tenant ON ?? USING(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid) WITH CHECK(account_id=NULLIF(current_setting('grove.account_id',true),'')::uuid)`,
|
|
297
|
+
[table]
|
|
298
|
+
);
|
|
299
|
+
await db2.raw(
|
|
300
|
+
`CREATE POLICY active_owner ON ?? AS RESTRICTIVE USING(EXISTS(SELECT 1 FROM accounts a WHERE a.id=??.account_id AND a.status='active')) WITH CHECK(true)`,
|
|
301
|
+
[table, table]
|
|
302
|
+
);
|
|
303
|
+
await db2.raw(
|
|
304
|
+
`GRANT SELECT,INSERT,UPDATE ON ?? TO grove_runtime,grove_worker`,
|
|
305
|
+
[table]
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
await db2.raw(`
|
|
309
|
+
REVOKE UPDATE ON document_import_attempts FROM grove_runtime,grove_worker;
|
|
310
|
+
CREATE FUNCTION grove_immutable_import_source() RETURNS trigger LANGUAGE plpgsql
|
|
311
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
312
|
+
BEGIN
|
|
313
|
+
IF OLD.original_ready AND NEW IS DISTINCT FROM OLD THEN RAISE EXCEPTION 'document_source_immutable'; END IF;
|
|
314
|
+
IF (NEW.account_id,NEW.batch_id,NEW.id,NEW.filename,NEW.bytes,NEW.sha256) IS DISTINCT FROM
|
|
315
|
+
(OLD.account_id,OLD.batch_id,OLD.id,OLD.filename,OLD.bytes,OLD.sha256) THEN RAISE EXCEPTION 'document_identity_immutable'; END IF;
|
|
316
|
+
RETURN NEW;
|
|
317
|
+
END $$;
|
|
318
|
+
REVOKE ALL ON FUNCTION grove_immutable_import_source() FROM PUBLIC;
|
|
319
|
+
CREATE TRIGGER immutable_import_source BEFORE UPDATE ON document_import_files
|
|
320
|
+
FOR EACH ROW EXECUTE FUNCTION grove_immutable_import_source();
|
|
321
|
+
CREATE FUNCTION grove_cancel_import_drafts() RETURNS trigger LANGUAGE plpgsql
|
|
322
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
323
|
+
BEGIN
|
|
324
|
+
UPDATE document_import_files SET staging=NULL WHERE account_id=NEW.account_id AND batch_id=NEW.id AND NOT original_ready;
|
|
325
|
+
UPDATE document_import_notes SET content='[Import draft unavailable]',included=false,suggestion=NULL WHERE account_id=NEW.account_id AND batch_id=NEW.id AND memory_id IS NULL;
|
|
326
|
+
RETURN NULL;
|
|
327
|
+
END $$;
|
|
328
|
+
REVOKE ALL ON FUNCTION grove_cancel_import_drafts() FROM PUBLIC;
|
|
329
|
+
CREATE TRIGGER cancel_import_drafts AFTER UPDATE OF status ON document_import_batches
|
|
330
|
+
FOR EACH ROW WHEN (NEW.status='cancelled' AND OLD.status<>'cancelled') EXECUTE FUNCTION grove_cancel_import_drafts();
|
|
331
|
+
CREATE FUNCTION grove_end_import_drafts() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER
|
|
332
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
333
|
+
DECLARE previous_scope text;
|
|
334
|
+
BEGIN
|
|
335
|
+
previous_scope:=current_setting('grove.account_id',true);
|
|
336
|
+
PERFORM set_config('grove.account_id',OLD.id::text,true);
|
|
337
|
+
UPDATE document_import_files SET staging=NULL WHERE account_id=OLD.id AND NOT original_ready;
|
|
338
|
+
UPDATE document_import_notes SET content='[Import draft unavailable]',included=false,suggestion=NULL WHERE account_id=OLD.id AND memory_id IS NULL;
|
|
339
|
+
UPDATE document_import_batches SET status='cancelled',version=version+1 WHERE account_id=OLD.id AND status NOT IN ('complete','cancelled');
|
|
340
|
+
PERFORM set_config('grove.account_id',coalesce(previous_scope,''),true);
|
|
341
|
+
RETURN NEW;
|
|
342
|
+
END $$;
|
|
343
|
+
REVOKE ALL ON FUNCTION grove_end_import_drafts() FROM PUBLIC;
|
|
344
|
+
CREATE TRIGGER end_import_drafts BEFORE UPDATE OF status ON accounts
|
|
345
|
+
FOR EACH ROW WHEN (OLD.status='active' AND NEW.status<>'active') EXECUTE FUNCTION grove_end_import_drafts();
|
|
346
|
+
CREATE FUNCTION grove_fence_import_suggestions() RETURNS trigger LANGUAGE plpgsql
|
|
347
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
348
|
+
BEGIN
|
|
349
|
+
UPDATE document_import_batches SET version=version+1,suggestion_id=NULL
|
|
350
|
+
WHERE account_id=NEW.id AND status='ready';
|
|
351
|
+
RETURN NULL;
|
|
352
|
+
END $$;
|
|
353
|
+
REVOKE ALL ON FUNCTION grove_fence_import_suggestions() FROM PUBLIC;
|
|
354
|
+
CREATE TRIGGER fence_import_suggestions AFTER UPDATE OF filing_enabled ON accounts
|
|
355
|
+
FOR EACH ROW WHEN (NEW.filing_enabled IS DISTINCT FROM OLD.filing_enabled) EXECUTE FUNCTION grove_fence_import_suggestions();
|
|
356
|
+
CREATE OR REPLACE FUNCTION grove_schedule_cleanup() RETURNS integer LANGUAGE plpgsql
|
|
357
|
+
SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
358
|
+
DECLARE added integer;
|
|
359
|
+
BEGIN
|
|
360
|
+
WITH due AS (
|
|
361
|
+
SELECT a.id,CASE WHEN a.status='deleting' THEN 'account_cleanup' ELSE 'retention_cleanup' END AS kind
|
|
362
|
+
FROM accounts a WHERE a.status='deleting' OR (a.status='active' AND (
|
|
363
|
+
EXISTS(SELECT 1 FROM memories m WHERE m.account_id=a.id AND m.deleted_at IS NULL AND m.purge_at<=now())
|
|
364
|
+
OR EXISTS(SELECT 1 FROM rate_buckets r WHERE r.account_id=a.id AND r.minute<now()-interval '1 day')
|
|
365
|
+
OR EXISTS(SELECT 1 FROM document_import_batches b WHERE b.account_id=a.id AND NOT b.drafts_cleared
|
|
366
|
+
AND b.expires_at<=now() AND b.status IN ('uploading','preparing','ready','cancelled'))))
|
|
367
|
+
ORDER BY a.work_claimed_at NULLS FIRST,a.id LIMIT 20
|
|
368
|
+
), inserted AS (
|
|
369
|
+
INSERT INTO background_tasks(account_id,kind,dedupe_key) SELECT id,kind,'lifecycle' FROM due
|
|
370
|
+
ON CONFLICT(account_id,kind,dedupe_key) DO UPDATE SET status='pending',due_at=now(),updated_at=now(),
|
|
371
|
+
finished_at=NULL,cursor='{}',processed=0,failures=0,error_code=NULL,dispatched_at=NULL,dispatch_id=NULL,dispatch_until=NULL
|
|
372
|
+
WHERE background_tasks.status='succeeded' RETURNING 1
|
|
373
|
+
) SELECT count(*) INTO added FROM inserted;
|
|
374
|
+
RETURN added;
|
|
375
|
+
END $$;
|
|
376
|
+
`);
|
|
377
|
+
},
|
|
378
|
+
async down() {
|
|
379
|
+
throw new Error("Use a forward migration");
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
7
383
|
// lib/database/src/billing-migration.ts
|
|
8
384
|
var billing = {
|
|
9
385
|
name: "20261024_023_billing",
|
|
@@ -59,6 +435,421 @@ var billing = {
|
|
|
59
435
|
}
|
|
60
436
|
};
|
|
61
437
|
|
|
438
|
+
// lib/database/src/system-admin-migration.ts
|
|
439
|
+
var systemAdministration = {
|
|
440
|
+
name: "20261025_025_system_administration",
|
|
441
|
+
async up(db2) {
|
|
442
|
+
await db2.raw(`
|
|
443
|
+
CREATE TABLE account_administration (
|
|
444
|
+
account_id uuid PRIMARY KEY REFERENCES public.accounts(id),
|
|
445
|
+
role text NOT NULL DEFAULT 'user' CHECK (role IN ('user','system_admin')),
|
|
446
|
+
access text NOT NULL DEFAULT 'default' CHECK (access IN ('default','pro','unlimited')),
|
|
447
|
+
version integer NOT NULL DEFAULT 0 CHECK (version >= 0)
|
|
448
|
+
);
|
|
449
|
+
ALTER TABLE account_administration ENABLE ROW LEVEL SECURITY;
|
|
450
|
+
CREATE POLICY tenant ON account_administration FOR SELECT
|
|
451
|
+
USING (account_id = NULLIF(current_setting('grove.account_id',true),'')::uuid);
|
|
452
|
+
CREATE TABLE system_admin_audit (
|
|
453
|
+
id uuid PRIMARY KEY, actor_id uuid REFERENCES public.accounts(id),
|
|
454
|
+
account_id uuid NOT NULL REFERENCES public.accounts(id),
|
|
455
|
+
kind text NOT NULL CHECK (kind IN ('change','bootstrap')),
|
|
456
|
+
reason text NOT NULL CHECK (length(reason) BETWEEN 3 AND 300),
|
|
457
|
+
before jsonb NOT NULL, after jsonb NOT NULL,
|
|
458
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
|
459
|
+
);
|
|
460
|
+
CREATE INDEX system_admin_audit_recent ON system_admin_audit(created_at DESC, id);
|
|
461
|
+
ALTER TABLE system_admin_audit ENABLE ROW LEVEL SECURITY;
|
|
462
|
+
REVOKE ALL ON account_administration,system_admin_audit FROM PUBLIC,grove_runtime,grove_worker;
|
|
463
|
+
GRANT SELECT ON account_administration TO grove_runtime,grove_worker;
|
|
464
|
+
|
|
465
|
+
CREATE FUNCTION grove_admin_state(target uuid) RETURNS jsonb
|
|
466
|
+
LANGUAGE sql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
467
|
+
SELECT jsonb_build_object('accountId',a.id,'subject',a.clerk_subject,
|
|
468
|
+
'status',a.status,'createdAt',a.created_at,
|
|
469
|
+
'role',COALESCE(s.role,'user'),'access',COALESCE(s.access,'default'),
|
|
470
|
+
'version',COALESCE(s.version,0))
|
|
471
|
+
FROM public.accounts a LEFT JOIN public.account_administration s ON s.account_id=a.id
|
|
472
|
+
WHERE a.id=target
|
|
473
|
+
$$;
|
|
474
|
+
CREATE FUNCTION grove_admin_guard() RETURNS uuid
|
|
475
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
476
|
+
DECLARE actor uuid := NULLIF(current_setting('grove.account_id',true),'')::uuid;
|
|
477
|
+
BEGIN
|
|
478
|
+
-- A fresh role snapshot after the lock wait fences concurrent revocation.
|
|
479
|
+
PERFORM pg_advisory_xact_lock(68142025);
|
|
480
|
+
IF NOT EXISTS(SELECT 1 FROM public.account_administration s
|
|
481
|
+
JOIN public.accounts a ON a.id=s.account_id
|
|
482
|
+
WHERE s.account_id=actor AND s.role='system_admin' AND a.status='active') THEN
|
|
483
|
+
RAISE EXCEPTION 'system_admin_required' USING ERRCODE='GA001';
|
|
484
|
+
END IF;
|
|
485
|
+
RETURN actor;
|
|
486
|
+
END $$;
|
|
487
|
+
CREATE FUNCTION grove_admin_accounts(wanted text[] DEFAULT NULL) RETURNS jsonb
|
|
488
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
489
|
+
DECLARE result jsonb;
|
|
490
|
+
BEGIN
|
|
491
|
+
PERFORM public.grove_admin_guard();
|
|
492
|
+
SELECT COALESCE(jsonb_agg(public.grove_admin_state(a.id) ORDER BY a.created_at DESC,a.id),'[]'::jsonb)
|
|
493
|
+
INTO result FROM (SELECT id,created_at FROM public.accounts
|
|
494
|
+
WHERE status IN ('active','disabled') AND (wanted IS NULL OR clerk_subject=ANY(wanted))
|
|
495
|
+
ORDER BY created_at DESC,id LIMIT 30) a;
|
|
496
|
+
RETURN result;
|
|
497
|
+
END $$;
|
|
498
|
+
CREATE FUNCTION grove_admin_change(target uuid, operation uuid, expected integer,
|
|
499
|
+
wanted_role text, wanted_access text, explanation text) RETURNS jsonb
|
|
500
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
501
|
+
DECLARE actor uuid; previous public.system_admin_audit; old jsonb; result jsonb;
|
|
502
|
+
BEGIN
|
|
503
|
+
actor := public.grove_admin_guard();
|
|
504
|
+
IF wanted_role NOT IN ('user','system_admin') OR wanted_role IS NULL
|
|
505
|
+
OR wanted_access NOT IN ('default','pro','unlimited') OR wanted_access IS NULL
|
|
506
|
+
OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300
|
|
507
|
+
OR expected IS NULL OR expected < 0 OR operation IS NULL THEN
|
|
508
|
+
RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
|
|
509
|
+
END IF;
|
|
510
|
+
SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
|
|
511
|
+
IF FOUND THEN
|
|
512
|
+
IF previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
|
|
513
|
+
OR previous.reason IS DISTINCT FROM explanation
|
|
514
|
+
OR previous.after->>'role' IS DISTINCT FROM wanted_role
|
|
515
|
+
OR previous.after->>'access' IS DISTINCT FROM wanted_access
|
|
516
|
+
OR (previous.before->>'version')::integer IS DISTINCT FROM expected THEN
|
|
517
|
+
RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
|
|
518
|
+
END IF;
|
|
519
|
+
RETURN previous.after;
|
|
520
|
+
END IF;
|
|
521
|
+
old := public.grove_admin_state(target);
|
|
522
|
+
IF old IS NULL OR old->>'status' <> 'active' THEN
|
|
523
|
+
RAISE EXCEPTION 'account_unavailable' USING ERRCODE='GA004';
|
|
524
|
+
END IF;
|
|
525
|
+
IF (old->>'version')::integer <> expected THEN
|
|
526
|
+
RAISE EXCEPTION 'admin_version_conflict' USING ERRCODE='GA005';
|
|
527
|
+
END IF;
|
|
528
|
+
IF old->>'role'='system_admin' AND wanted_role='user' AND NOT EXISTS(
|
|
529
|
+
SELECT 1 FROM public.account_administration s JOIN public.accounts a ON a.id=s.account_id
|
|
530
|
+
WHERE s.role='system_admin' AND a.status='active' AND s.account_id<>target) THEN
|
|
531
|
+
RAISE EXCEPTION 'last_system_admin' USING ERRCODE='GA006';
|
|
532
|
+
END IF;
|
|
533
|
+
INSERT INTO public.account_administration(account_id,role,access,version)
|
|
534
|
+
VALUES(target,wanted_role,wanted_access,expected+1)
|
|
535
|
+
ON CONFLICT(account_id) DO UPDATE SET role=EXCLUDED.role,access=EXCLUDED.access,version=EXCLUDED.version;
|
|
536
|
+
result := public.grove_admin_state(target);
|
|
537
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
538
|
+
VALUES(operation,actor,target,'change',explanation,old,result);
|
|
539
|
+
RETURN result;
|
|
540
|
+
END $$;
|
|
541
|
+
CREATE FUNCTION grove_admin_audit() RETURNS jsonb
|
|
542
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
543
|
+
DECLARE result jsonb;
|
|
544
|
+
BEGIN
|
|
545
|
+
PERFORM public.grove_admin_guard();
|
|
546
|
+
SELECT COALESCE(jsonb_agg(jsonb_build_object('id',id,'actorId',actor_id,
|
|
547
|
+
'accountId',account_id,'kind',kind,'reason',reason,'before',before,'after',after,
|
|
548
|
+
'createdAt',created_at) ORDER BY created_at DESC,id),'[]'::jsonb)
|
|
549
|
+
INTO result FROM (SELECT * FROM public.system_admin_audit ORDER BY created_at DESC,id LIMIT 50) recent;
|
|
550
|
+
RETURN result;
|
|
551
|
+
END $$;
|
|
552
|
+
CREATE FUNCTION grove_bootstrap_system_admin(subject text, explanation text) RETURNS uuid
|
|
553
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
554
|
+
DECLARE target uuid; old jsonb;
|
|
555
|
+
BEGIN
|
|
556
|
+
PERFORM pg_advisory_xact_lock(68142025);
|
|
557
|
+
SELECT id INTO target FROM public.accounts WHERE clerk_subject=subject AND status='active';
|
|
558
|
+
IF target IS NULL THEN RAISE EXCEPTION 'account_unavailable'; END IF;
|
|
559
|
+
IF explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300 THEN
|
|
560
|
+
RAISE EXCEPTION 'invalid_request';
|
|
561
|
+
END IF;
|
|
562
|
+
IF EXISTS(SELECT 1 FROM public.account_administration WHERE account_id=target AND role='system_admin') THEN RETURN target; END IF;
|
|
563
|
+
IF EXISTS(SELECT 1 FROM public.account_administration WHERE role='system_admin') THEN
|
|
564
|
+
RAISE EXCEPTION 'already_bootstrapped';
|
|
565
|
+
END IF;
|
|
566
|
+
old := public.grove_admin_state(target);
|
|
567
|
+
INSERT INTO public.account_administration(account_id,role,version) VALUES(target,'system_admin',1)
|
|
568
|
+
ON CONFLICT(account_id) DO UPDATE SET role='system_admin',version=public.account_administration.version+1;
|
|
569
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
570
|
+
VALUES(gen_random_uuid(),NULL,target,'bootstrap',explanation,old,public.grove_admin_state(target));
|
|
571
|
+
RETURN target;
|
|
572
|
+
END $$;
|
|
573
|
+
REVOKE ALL ON FUNCTION grove_admin_state(uuid),grove_admin_guard(),grove_admin_accounts(text[]),
|
|
574
|
+
grove_admin_change(uuid,uuid,integer,text,text,text),grove_admin_audit(),
|
|
575
|
+
grove_bootstrap_system_admin(text,text) FROM PUBLIC,grove_runtime,grove_worker;
|
|
576
|
+
GRANT EXECUTE ON FUNCTION grove_admin_accounts(text[]),grove_admin_change(uuid,uuid,integer,text,text,text),
|
|
577
|
+
grove_admin_audit() TO grove_runtime;
|
|
578
|
+
`);
|
|
579
|
+
},
|
|
580
|
+
async down() {
|
|
581
|
+
throw new Error("Use a forward migration");
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// lib/database/src/admin-support-migration.ts
|
|
586
|
+
var adminSupport = {
|
|
587
|
+
name: "20261025_027_admin_support",
|
|
588
|
+
async up(db2) {
|
|
589
|
+
await db2.raw(`
|
|
590
|
+
ALTER TABLE accounts ADD COLUMN admin_suspended boolean NOT NULL DEFAULT false;
|
|
591
|
+
ALTER TABLE account_administration ADD COLUMN support_note text NOT NULL DEFAULT '' CHECK(length(support_note)<=500);
|
|
592
|
+
ALTER TABLE system_admin_audit DROP CONSTRAINT system_admin_audit_kind_check;
|
|
593
|
+
ALTER TABLE system_admin_audit ADD CHECK(kind IN ('change','bootstrap','support'));
|
|
594
|
+
CREATE INDEX accounts_admin_page ON accounts(created_at DESC,id DESC) WHERE status IN ('active','disabled');
|
|
595
|
+
|
|
596
|
+
CREATE FUNCTION grove_admin_support_state(target uuid) RETURNS jsonb
|
|
597
|
+
LANGUAGE sql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
598
|
+
SELECT jsonb_build_object('account',public.grove_admin_state(a.id),'settings',
|
|
599
|
+
jsonb_build_object('captureEnabled',a.capture_enabled,'recallEnabled',a.recall_enabled,
|
|
600
|
+
'suspended',a.admin_suspended,'supportNote',COALESCE(s.support_note,'')))
|
|
601
|
+
FROM public.accounts a LEFT JOIN public.account_administration s ON s.account_id=a.id
|
|
602
|
+
WHERE a.id=target AND a.status IN ('active','disabled')
|
|
603
|
+
$$;
|
|
604
|
+
CREATE FUNCTION grove_admin_browse(after_id uuid DEFAULT NULL) RETURNS jsonb
|
|
605
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
606
|
+
DECLARE result jsonb; page jsonb; boundary timestamptz; total bigint;
|
|
607
|
+
BEGIN
|
|
608
|
+
PERFORM public.grove_admin_guard();
|
|
609
|
+
IF after_id IS NOT NULL THEN
|
|
610
|
+
SELECT created_at INTO boundary FROM public.accounts WHERE id=after_id;
|
|
611
|
+
IF NOT FOUND THEN RAISE EXCEPTION 'invalid_cursor' USING ERRCODE='GA002'; END IF;
|
|
612
|
+
END IF;
|
|
613
|
+
SELECT count(*) INTO total FROM public.accounts WHERE status IN ('active','disabled');
|
|
614
|
+
SELECT COALESCE(jsonb_agg(public.grove_admin_state(id) ORDER BY created_at DESC,id DESC),'[]'::jsonb)
|
|
615
|
+
INTO page FROM (SELECT id,created_at FROM public.accounts WHERE status IN ('active','disabled')
|
|
616
|
+
AND (after_id IS NULL OR (created_at,id)<(boundary,after_id))
|
|
617
|
+
ORDER BY created_at DESC,id DESC LIMIT 31) a;
|
|
618
|
+
SELECT COALESCE(jsonb_agg(value ORDER BY ordinality),'[]'::jsonb) INTO result
|
|
619
|
+
FROM jsonb_array_elements(page) WITH ORDINALITY WHERE ordinality<=30;
|
|
620
|
+
RETURN jsonb_build_object('accounts',result,'total',total,
|
|
621
|
+
'nextCursor',CASE WHEN jsonb_array_length(page)>30 THEN result->29->>'accountId' ELSE NULL END);
|
|
622
|
+
END $$;
|
|
623
|
+
|
|
624
|
+
CREATE FUNCTION grove_admin_details(target uuid) RETURNS jsonb
|
|
625
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
626
|
+
DECLARE result jsonb; original text; metrics jsonb; counts jsonb;
|
|
627
|
+
today date := (now() AT TIME ZONE 'UTC')::date;
|
|
628
|
+
month date := date_trunc('month',now() AT TIME ZONE 'UTC')::date;
|
|
629
|
+
BEGIN
|
|
630
|
+
PERFORM public.grove_admin_guard();
|
|
631
|
+
result := public.grove_admin_support_state(target);
|
|
632
|
+
IF result IS NULL THEN RAISE EXCEPTION 'account_unavailable' USING ERRCODE='GA004'; END IF;
|
|
633
|
+
-- Scope only these bounded aggregate queries to the target. Never expose
|
|
634
|
+
-- a general-purpose cross-tenant reader or broaden any RLS policy.
|
|
635
|
+
original := current_setting('grove.account_id',true);
|
|
636
|
+
PERFORM set_config('grove.account_id',target::text,true);
|
|
637
|
+
SELECT jsonb_object_agg(metric,jsonb_build_object('today',daily,'month',monthly)) INTO metrics FROM (
|
|
638
|
+
SELECT 'generation' AS metric,COALESCE(sum(requests) FILTER(WHERE day=today),0) AS daily,COALESCE(sum(requests),0) AS monthly
|
|
639
|
+
FROM public.inference_usage WHERE account_id=target AND role='generation' AND day BETWEEN month AND today
|
|
640
|
+
UNION ALL SELECT 'research',COALESCE(sum(calls) FILTER(WHERE day=today),0),COALESCE(sum(calls),0)
|
|
641
|
+
FROM public.research_account_usage WHERE account_id=target AND day BETWEEN month AND today
|
|
642
|
+
UNION ALL SELECT 'transcription',COALESCE(sum(units) FILTER(WHERE day=today),0),COALESCE(sum(units),0)
|
|
643
|
+
FROM public.speech_usage WHERE account_id=target AND kind='speech_transcribe' AND day BETWEEN month AND today
|
|
644
|
+
UNION ALL SELECT 'synthesis',COALESCE(sum(duration_ms) FILTER(WHERE day=today),0),COALESCE(sum(duration_ms),0)
|
|
645
|
+
FROM public.speech_usage WHERE account_id=target AND kind='speech_synthesize' AND day BETWEEN month AND today
|
|
646
|
+
) counters;
|
|
647
|
+
SELECT jsonb_build_object(
|
|
648
|
+
'notes',(SELECT count(*) FROM public.memories WHERE account_id=target AND deleted_at IS NULL AND (expires_at IS NULL OR expires_at>now())),
|
|
649
|
+
'notebooks',(SELECT count(*) FROM public.projects WHERE account_id=target AND deleted_at IS NULL),
|
|
650
|
+
'connections',(SELECT count(*) FROM public.connections WHERE account_id=target AND deleted_at IS NULL AND revoked_at IS NULL AND (expires_at IS NULL OR expires_at>now()))
|
|
651
|
+
) INTO counts;
|
|
652
|
+
PERFORM set_config('grove.account_id',original,true);
|
|
653
|
+
RETURN result || jsonb_build_object('counts',counts,'usage',jsonb_build_object('metrics',metrics,
|
|
654
|
+
'dailyResetAt',(today+interval '1 day') AT TIME ZONE 'UTC',
|
|
655
|
+
'monthlyResetAt',(month+interval '1 month') AT TIME ZONE 'UTC'));
|
|
656
|
+
EXCEPTION WHEN OTHERS THEN
|
|
657
|
+
IF original IS NOT NULL THEN PERFORM set_config('grove.account_id',original,true); END IF;
|
|
658
|
+
RAISE;
|
|
659
|
+
END $$;
|
|
660
|
+
|
|
661
|
+
CREATE FUNCTION grove_admin_support_change(target uuid,operation uuid,expected integer,
|
|
662
|
+
expected_settings jsonb,wanted jsonb,explanation text) RETURNS jsonb
|
|
663
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
664
|
+
DECLARE actor uuid; previous public.system_admin_audit; old jsonb; result jsonb;
|
|
665
|
+
BEGIN
|
|
666
|
+
actor := public.grove_admin_guard();
|
|
667
|
+
IF operation IS NULL OR expected IS NULL OR expected<0 OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300
|
|
668
|
+
OR wanted IS NULL OR expected_settings IS NULL OR jsonb_typeof(wanted)<>'object'
|
|
669
|
+
OR jsonb_typeof(wanted->'captureEnabled') IS DISTINCT FROM 'boolean'
|
|
670
|
+
OR jsonb_typeof(wanted->'recallEnabled') IS DISTINCT FROM 'boolean'
|
|
671
|
+
OR jsonb_typeof(wanted->'suspended') IS DISTINCT FROM 'boolean'
|
|
672
|
+
OR jsonb_typeof(wanted->'supportNote') IS DISTINCT FROM 'string'
|
|
673
|
+
OR length(wanted->>'supportNote')>500 OR (SELECT count(*) FROM jsonb_object_keys(wanted))<>4 THEN
|
|
674
|
+
RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
|
|
675
|
+
END IF;
|
|
676
|
+
SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
|
|
677
|
+
IF FOUND THEN
|
|
678
|
+
IF previous.kind<>'support' OR previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
|
|
679
|
+
OR previous.reason IS DISTINCT FROM explanation OR previous.after->'settings' IS DISTINCT FROM wanted
|
|
680
|
+
OR previous.before->'settings' IS DISTINCT FROM expected_settings
|
|
681
|
+
OR (previous.before->>'version')::integer IS DISTINCT FROM expected THEN
|
|
682
|
+
RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
|
|
683
|
+
END IF;
|
|
684
|
+
RETURN jsonb_build_object('account',previous.after-'settings','settings',previous.after->'settings');
|
|
685
|
+
END IF;
|
|
686
|
+
PERFORM 1 FROM public.accounts WHERE id=target FOR UPDATE;
|
|
687
|
+
old := public.grove_admin_support_state(target);
|
|
688
|
+
IF old IS NULL THEN RAISE EXCEPTION 'account_unavailable' USING ERRCODE='GA004'; END IF;
|
|
689
|
+
IF (old->'account'->>'version')::integer<>expected OR old->'settings' IS DISTINCT FROM expected_settings THEN
|
|
690
|
+
RAISE EXCEPTION 'admin_version_conflict' USING ERRCODE='GA005';
|
|
691
|
+
END IF;
|
|
692
|
+
IF (wanted->>'suspended')::boolean AND (target=actor OR (old->'account'->>'role'='system_admin' AND NOT EXISTS(
|
|
693
|
+
SELECT 1 FROM public.accounts a JOIN public.account_administration s ON s.account_id=a.id
|
|
694
|
+
WHERE a.status='active' AND s.role='system_admin' AND a.id<>target))) THEN
|
|
695
|
+
RAISE EXCEPTION 'last_system_admin' USING ERRCODE='GA006';
|
|
696
|
+
END IF;
|
|
697
|
+
UPDATE public.accounts SET capture_enabled=(wanted->>'captureEnabled')::boolean,
|
|
698
|
+
recall_enabled=(wanted->>'recallEnabled')::boolean,admin_suspended=(wanted->>'suspended')::boolean,
|
|
699
|
+
status=CASE WHEN (wanted->>'suspended')::boolean THEN 'disabled'
|
|
700
|
+
WHEN admin_suspended AND NOT EXISTS(SELECT 1 FROM public.subject_authority s WHERE s.subject=clerk_subject AND (s.disabled OR s.deleted)) THEN 'active'
|
|
701
|
+
ELSE status END WHERE id=target;
|
|
702
|
+
INSERT INTO public.account_administration(account_id,version,support_note) VALUES(target,expected+1,wanted->>'supportNote')
|
|
703
|
+
ON CONFLICT(account_id) DO UPDATE SET version=EXCLUDED.version,support_note=EXCLUDED.support_note;
|
|
704
|
+
result := public.grove_admin_support_state(target);
|
|
705
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
706
|
+
VALUES(operation,actor,target,'support',explanation,
|
|
707
|
+
old->'account'||jsonb_build_object('settings',old->'settings'),
|
|
708
|
+
result->'account'||jsonb_build_object('settings',result->'settings'));
|
|
709
|
+
RETURN result;
|
|
710
|
+
END $$;
|
|
711
|
+
CREATE OR REPLACE FUNCTION grove_user_state(subject text,event_at bigint,disabled boolean) RETURNS void
|
|
712
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
713
|
+
BEGIN
|
|
714
|
+
UPDATE public.subject_authority s SET disabled=grove_user_state.disabled
|
|
715
|
+
WHERE s.subject=grove_user_state.subject AND s.event_at=grove_user_state.event_at AND NOT s.deleted;
|
|
716
|
+
IF NOT FOUND THEN RETURN; END IF;
|
|
717
|
+
UPDATE public.accounts SET status=CASE WHEN disabled OR admin_suspended THEN 'disabled' ELSE 'active' END
|
|
718
|
+
WHERE clerk_subject=subject AND status IN ('active','disabled');
|
|
719
|
+
END $$;
|
|
720
|
+
CREATE OR REPLACE FUNCTION grove_admin_change(target uuid,operation uuid,expected integer,
|
|
721
|
+
wanted_role text,wanted_access text,explanation text) RETURNS jsonb
|
|
722
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
723
|
+
DECLARE actor uuid; previous public.system_admin_audit; old jsonb; result jsonb;
|
|
724
|
+
BEGIN
|
|
725
|
+
actor := public.grove_admin_guard();
|
|
726
|
+
IF wanted_role NOT IN ('user','system_admin') OR wanted_role IS NULL
|
|
727
|
+
OR wanted_access NOT IN ('default','pro','unlimited') OR wanted_access IS NULL
|
|
728
|
+
OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300
|
|
729
|
+
OR expected IS NULL OR expected<0 OR operation IS NULL THEN
|
|
730
|
+
RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
|
|
731
|
+
END IF;
|
|
732
|
+
SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
|
|
733
|
+
IF FOUND THEN
|
|
734
|
+
IF previous.kind<>'change' OR previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
|
|
735
|
+
OR previous.reason IS DISTINCT FROM explanation
|
|
736
|
+
OR previous.after->>'role' IS DISTINCT FROM wanted_role
|
|
737
|
+
OR previous.after->>'access' IS DISTINCT FROM wanted_access
|
|
738
|
+
OR (previous.before->>'version')::integer IS DISTINCT FROM expected THEN
|
|
739
|
+
RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
|
|
740
|
+
END IF;
|
|
741
|
+
RETURN previous.after;
|
|
742
|
+
END IF;
|
|
743
|
+
old := public.grove_admin_state(target);
|
|
744
|
+
IF old IS NULL OR old->>'status'<>'active' THEN
|
|
745
|
+
RAISE EXCEPTION 'account_unavailable' USING ERRCODE='GA004';
|
|
746
|
+
END IF;
|
|
747
|
+
IF (old->>'version')::integer<>expected THEN RAISE EXCEPTION 'admin_version_conflict' USING ERRCODE='GA005'; END IF;
|
|
748
|
+
IF old->>'role'='system_admin' AND wanted_role='user' AND NOT EXISTS(
|
|
749
|
+
SELECT 1 FROM public.account_administration s JOIN public.accounts a ON a.id=s.account_id
|
|
750
|
+
WHERE s.role='system_admin' AND a.status='active' AND s.account_id<>target) THEN
|
|
751
|
+
RAISE EXCEPTION 'last_system_admin' USING ERRCODE='GA006';
|
|
752
|
+
END IF;
|
|
753
|
+
INSERT INTO public.account_administration(account_id,role,access,version)
|
|
754
|
+
VALUES(target,wanted_role,wanted_access,expected+1)
|
|
755
|
+
ON CONFLICT(account_id) DO UPDATE SET role=EXCLUDED.role,access=EXCLUDED.access,version=EXCLUDED.version;
|
|
756
|
+
result := public.grove_admin_state(target);
|
|
757
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
758
|
+
VALUES(operation,actor,target,'change',explanation,old,result);
|
|
759
|
+
RETURN result;
|
|
760
|
+
END $$;
|
|
761
|
+
REVOKE ALL ON FUNCTION grove_admin_support_state(uuid),grove_admin_browse(uuid),grove_admin_details(uuid),
|
|
762
|
+
grove_admin_support_change(uuid,uuid,integer,jsonb,jsonb,text) FROM PUBLIC,grove_runtime,grove_worker;
|
|
763
|
+
GRANT EXECUTE ON FUNCTION grove_admin_browse(uuid),grove_admin_details(uuid),
|
|
764
|
+
grove_admin_support_change(uuid,uuid,integer,jsonb,jsonb,text) TO grove_runtime;
|
|
765
|
+
`);
|
|
766
|
+
},
|
|
767
|
+
async down() {
|
|
768
|
+
throw new Error("Use a forward migration");
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// lib/database/src/speech-cache-migration.ts
|
|
773
|
+
var speechCache = {
|
|
774
|
+
name: "20261024_024_speech_cache",
|
|
775
|
+
async up(db2) {
|
|
776
|
+
await db2.raw(`
|
|
777
|
+
-- Cache metadata belongs to the tracked object, not its short-lived request.
|
|
778
|
+
-- Existing speech/ objects retain their original deadlines and lifecycle.
|
|
779
|
+
ALTER TABLE export_objects
|
|
780
|
+
ADD COLUMN speech_memory_id uuid,
|
|
781
|
+
ADD COLUMN speech_text_hash text,
|
|
782
|
+
ADD COLUMN speech_cache_key text,
|
|
783
|
+
ADD COLUMN speech_sha256 text,
|
|
784
|
+
ADD CONSTRAINT export_objects_speech_memory FOREIGN KEY(account_id,speech_memory_id)
|
|
785
|
+
REFERENCES memories(account_id,id),
|
|
786
|
+
ADD CONSTRAINT export_objects_speech_metadata CHECK (
|
|
787
|
+
(speech_memory_id IS NULL AND speech_text_hash IS NULL AND speech_cache_key IS NULL AND speech_sha256 IS NULL)
|
|
788
|
+
OR (speech_memory_id IS NOT NULL AND speech_text_hash IS NOT NULL AND speech_cache_key IS NOT NULL AND speech_sha256 IS NOT NULL
|
|
789
|
+
AND speech_text_hash ~ '^[a-f0-9]{64}$' AND speech_cache_key ~ '^[a-f0-9]{64}$'
|
|
790
|
+
AND speech_sha256 ~ '^[a-f0-9]{64}$' AND object_key LIKE 'narration/%'));
|
|
791
|
+
CREATE INDEX export_objects_speech_cache ON export_objects(account_id,speech_cache_key)
|
|
792
|
+
WHERE speech_cache_key IS NOT NULL;
|
|
793
|
+
CREATE INDEX export_objects_speech_memory ON export_objects(account_id,speech_memory_id)
|
|
794
|
+
WHERE speech_memory_id IS NOT NULL;
|
|
795
|
+
|
|
796
|
+
-- Every write path (including Undo, imports and API edits) gets the same
|
|
797
|
+
-- retention transition. Expired objects can already be claimed for removal:
|
|
798
|
+
-- never revive one, even if its bytes have not been physically deleted yet.
|
|
799
|
+
CREATE FUNCTION grove_speech_cache_text() RETURNS trigger LANGUAGE plpgsql
|
|
800
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
801
|
+
BEGIN
|
|
802
|
+
UPDATE export_objects SET expires_at=CASE
|
|
803
|
+
WHEN NEW.status='active' AND NEW.deleted_at IS NULL
|
|
804
|
+
AND (NEW.expires_at IS NULL OR NEW.expires_at>now())
|
|
805
|
+
AND speech_text_hash=encode(sha256(convert_to(NEW.content,'UTF8')),'hex')
|
|
806
|
+
THEN coalesce(NEW.expires_at+interval '7 days','infinity'::timestamptz)
|
|
807
|
+
ELSE least(expires_at,now()+interval '7 days') END
|
|
808
|
+
WHERE account_id=NEW.account_id AND speech_memory_id=NEW.id AND expires_at>now();
|
|
809
|
+
RETURN NULL;
|
|
810
|
+
END $$;
|
|
811
|
+
REVOKE ALL ON FUNCTION grove_speech_cache_text() FROM PUBLIC;
|
|
812
|
+
CREATE TRIGGER speech_cache_text AFTER UPDATE OF content,status,deleted_at,expires_at ON memories
|
|
813
|
+
FOR EACH ROW EXECUTE FUNCTION grove_speech_cache_text();
|
|
814
|
+
`);
|
|
815
|
+
},
|
|
816
|
+
async down() {
|
|
817
|
+
throw new Error("Use a forward migration");
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// lib/database/src/speech-duration-migration.ts
|
|
822
|
+
var speechDuration = {
|
|
823
|
+
name: "20261025_026_speech_duration",
|
|
824
|
+
async up(db2) {
|
|
825
|
+
await db2.raw(`
|
|
826
|
+
ALTER TABLE speech_usage ADD COLUMN duration_ms bigint NOT NULL DEFAULT 0 CHECK(duration_ms>=0);
|
|
827
|
+
-- Retain character counters. Unknown historical audio/failed attempts get
|
|
828
|
+
-- a conservative bound: 3 MiB of MP3 at minimum 8 kbps plus one 72 ms frame.
|
|
829
|
+
-- Do not reset current-month usage or claim an exact conversion from text.
|
|
830
|
+
UPDATE speech_usage SET duration_ms=requests::bigint*3145800 WHERE kind='speech_synthesize';
|
|
831
|
+
CREATE FUNCTION grove_speech_legacy_duration() RETURNS trigger LANGUAGE plpgsql
|
|
832
|
+
SET search_path=pg_catalog,public,pg_temp AS $$
|
|
833
|
+
BEGIN
|
|
834
|
+
IF NEW.kind='speech_synthesize' THEN
|
|
835
|
+
IF TG_OP='INSERT' AND NEW.requests>0 AND NEW.duration_ms=0 THEN
|
|
836
|
+
NEW.duration_ms:=NEW.requests::bigint*3145800;
|
|
837
|
+
ELSIF TG_OP='UPDATE' AND NEW.requests>OLD.requests AND NEW.duration_ms=OLD.duration_ms THEN
|
|
838
|
+
NEW.duration_ms:=OLD.duration_ms+(NEW.requests-OLD.requests)::bigint*3145800;
|
|
839
|
+
END IF;
|
|
840
|
+
END IF;
|
|
841
|
+
RETURN NEW;
|
|
842
|
+
END $$;
|
|
843
|
+
REVOKE ALL ON FUNCTION grove_speech_legacy_duration() FROM PUBLIC;
|
|
844
|
+
CREATE TRIGGER speech_legacy_duration BEFORE INSERT OR UPDATE ON speech_usage
|
|
845
|
+
FOR EACH ROW EXECUTE FUNCTION grove_speech_legacy_duration();
|
|
846
|
+
`);
|
|
847
|
+
},
|
|
848
|
+
async down() {
|
|
849
|
+
throw new Error("Use a forward migration");
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
|
|
62
853
|
// lib/database/src/speech-voices-migration.ts
|
|
63
854
|
var speechVoices = {
|
|
64
855
|
name: "20261024_022_speech_voices",
|
|
@@ -2386,7 +3177,16 @@ var migrations = [
|
|
|
2386
3177
|
researchTools,
|
|
2387
3178
|
speechDefaults,
|
|
2388
3179
|
speechVoices,
|
|
2389
|
-
billing
|
|
3180
|
+
billing,
|
|
3181
|
+
speechCache,
|
|
3182
|
+
systemAdministration,
|
|
3183
|
+
speechDuration,
|
|
3184
|
+
adminSupport,
|
|
3185
|
+
actionUsage,
|
|
3186
|
+
searchQuality,
|
|
3187
|
+
conversationContext,
|
|
3188
|
+
documentImports,
|
|
3189
|
+
conversationDocuments
|
|
2390
3190
|
];
|
|
2391
3191
|
var migrationSource = {
|
|
2392
3192
|
getMigrations: async () => migrations,
|