weave-typescript 0.27.0 → 0.28.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/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +134 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +1620 -0
- package/dist/weaveapi/consolidation/v1/service.pb.d.ts +93 -0
- package/dist/weaveapi/consolidation/v1/service.pb.js +427 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +433 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5626 -0
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +181 -0
- package/dist/weaveapi/ingestion/v1/service.pb.js +917 -0
- package/dist/weaveapi/model/v1/model.pb.d.ts +10 -0
- package/dist/weaveapi/model/v1/model.pb.js +181 -1
- package/dist/weaveapi/model/v1/service.pb.d.ts +50 -1
- package/dist/weaveapi/model/v1/service.pb.js +464 -1
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +161 -0
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +1885 -0
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +51 -0
- package/dist/weaveapi/retrieval/v1/service.pb.js +164 -0
- package/dist/weavesql/weavedb/consolidation_sql.d.ts +212 -0
- package/dist/weavesql/weavedb/consolidation_sql.js +470 -0
- package/dist/weavesql/weavedb/document_security_sql.d.ts +128 -0
- package/dist/weavesql/weavedb/document_security_sql.js +284 -0
- package/dist/weavesql/weavedb/ingestion_sql.d.ts +1108 -0
- package/dist/weavesql/weavedb/ingestion_sql.js +2503 -0
- package/dist/weavesql/weavedb/retrieval_sql.d.ts +284 -0
- package/dist/weavesql/weavedb/retrieval_sql.js +769 -0
- package/package.json +2 -2
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearThreadClusterAssignmentsByOrganizationQuery = exports.assignThreadsToClusterQuery = exports.listApprovedThreadsForConsolidationQuery = exports.listConceptClustersByParentAndRealmQuery = exports.listConceptClustersByRealmQuery = exports.getConceptClusterByOrganizationRealmAndIDQuery = exports.upsertConceptClusterQuery = exports.listConsolidationRunsByOrganizationQuery = exports.updateConsolidationRunStateQuery = exports.getConsolidationRunByOrganizationAndIDQuery = exports.createConsolidationRunQuery = void 0;
|
|
4
|
+
exports.createConsolidationRun = createConsolidationRun;
|
|
5
|
+
exports.getConsolidationRunByOrganizationAndID = getConsolidationRunByOrganizationAndID;
|
|
6
|
+
exports.updateConsolidationRunState = updateConsolidationRunState;
|
|
7
|
+
exports.listConsolidationRunsByOrganization = listConsolidationRunsByOrganization;
|
|
8
|
+
exports.upsertConceptCluster = upsertConceptCluster;
|
|
9
|
+
exports.getConceptClusterByOrganizationRealmAndID = getConceptClusterByOrganizationRealmAndID;
|
|
10
|
+
exports.listConceptClustersByRealm = listConceptClustersByRealm;
|
|
11
|
+
exports.listConceptClustersByParentAndRealm = listConceptClustersByParentAndRealm;
|
|
12
|
+
exports.listApprovedThreadsForConsolidation = listApprovedThreadsForConsolidation;
|
|
13
|
+
exports.createConsolidationRunQuery = `-- name: CreateConsolidationRun :one
|
|
14
|
+
INSERT INTO weave.consolidation_runs (
|
|
15
|
+
id,
|
|
16
|
+
organization_id,
|
|
17
|
+
status
|
|
18
|
+
) VALUES (
|
|
19
|
+
$1,
|
|
20
|
+
$2,
|
|
21
|
+
$3
|
|
22
|
+
)
|
|
23
|
+
RETURNING
|
|
24
|
+
id,
|
|
25
|
+
organization_id,
|
|
26
|
+
status,
|
|
27
|
+
thread_count,
|
|
28
|
+
cluster_count,
|
|
29
|
+
hierarchy_depth,
|
|
30
|
+
error,
|
|
31
|
+
started_at,
|
|
32
|
+
completed_at`;
|
|
33
|
+
async function createConsolidationRun(client, args) {
|
|
34
|
+
const result = await client.query({
|
|
35
|
+
text: exports.createConsolidationRunQuery,
|
|
36
|
+
values: [args.id, args.organizationId, args.status],
|
|
37
|
+
rowMode: "array"
|
|
38
|
+
});
|
|
39
|
+
if (result.rows.length !== 1) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const row = result.rows[0];
|
|
43
|
+
return {
|
|
44
|
+
id: row[0],
|
|
45
|
+
organizationId: row[1],
|
|
46
|
+
status: row[2],
|
|
47
|
+
threadCount: row[3],
|
|
48
|
+
clusterCount: row[4],
|
|
49
|
+
hierarchyDepth: row[5],
|
|
50
|
+
error: row[6],
|
|
51
|
+
startedAt: row[7],
|
|
52
|
+
completedAt: row[8]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.getConsolidationRunByOrganizationAndIDQuery = `-- name: GetConsolidationRunByOrganizationAndID :one
|
|
56
|
+
SELECT
|
|
57
|
+
id,
|
|
58
|
+
organization_id,
|
|
59
|
+
status,
|
|
60
|
+
thread_count,
|
|
61
|
+
cluster_count,
|
|
62
|
+
hierarchy_depth,
|
|
63
|
+
error,
|
|
64
|
+
started_at,
|
|
65
|
+
completed_at
|
|
66
|
+
FROM weave.consolidation_runs
|
|
67
|
+
WHERE organization_id = $1
|
|
68
|
+
AND id = $2`;
|
|
69
|
+
async function getConsolidationRunByOrganizationAndID(client, args) {
|
|
70
|
+
const result = await client.query({
|
|
71
|
+
text: exports.getConsolidationRunByOrganizationAndIDQuery,
|
|
72
|
+
values: [args.organizationId, args.id],
|
|
73
|
+
rowMode: "array"
|
|
74
|
+
});
|
|
75
|
+
if (result.rows.length !== 1) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const row = result.rows[0];
|
|
79
|
+
return {
|
|
80
|
+
id: row[0],
|
|
81
|
+
organizationId: row[1],
|
|
82
|
+
status: row[2],
|
|
83
|
+
threadCount: row[3],
|
|
84
|
+
clusterCount: row[4],
|
|
85
|
+
hierarchyDepth: row[5],
|
|
86
|
+
error: row[6],
|
|
87
|
+
startedAt: row[7],
|
|
88
|
+
completedAt: row[8]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.updateConsolidationRunStateQuery = `-- name: UpdateConsolidationRunState :one
|
|
92
|
+
UPDATE weave.consolidation_runs
|
|
93
|
+
SET
|
|
94
|
+
status = $1,
|
|
95
|
+
thread_count = $2,
|
|
96
|
+
cluster_count = $3,
|
|
97
|
+
hierarchy_depth = $4,
|
|
98
|
+
error = $5,
|
|
99
|
+
completed_at = $6
|
|
100
|
+
WHERE id = $7
|
|
101
|
+
AND organization_id = $8
|
|
102
|
+
RETURNING
|
|
103
|
+
id,
|
|
104
|
+
organization_id,
|
|
105
|
+
status,
|
|
106
|
+
thread_count,
|
|
107
|
+
cluster_count,
|
|
108
|
+
hierarchy_depth,
|
|
109
|
+
error,
|
|
110
|
+
started_at,
|
|
111
|
+
completed_at`;
|
|
112
|
+
async function updateConsolidationRunState(client, args) {
|
|
113
|
+
const result = await client.query({
|
|
114
|
+
text: exports.updateConsolidationRunStateQuery,
|
|
115
|
+
values: [args.status, args.threadCount, args.clusterCount, args.hierarchyDepth, args.error, args.completedAt, args.id, args.organizationId],
|
|
116
|
+
rowMode: "array"
|
|
117
|
+
});
|
|
118
|
+
if (result.rows.length !== 1) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const row = result.rows[0];
|
|
122
|
+
return {
|
|
123
|
+
id: row[0],
|
|
124
|
+
organizationId: row[1],
|
|
125
|
+
status: row[2],
|
|
126
|
+
threadCount: row[3],
|
|
127
|
+
clusterCount: row[4],
|
|
128
|
+
hierarchyDepth: row[5],
|
|
129
|
+
error: row[6],
|
|
130
|
+
startedAt: row[7],
|
|
131
|
+
completedAt: row[8]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.listConsolidationRunsByOrganizationQuery = `-- name: ListConsolidationRunsByOrganization :many
|
|
135
|
+
SELECT
|
|
136
|
+
id,
|
|
137
|
+
organization_id,
|
|
138
|
+
status,
|
|
139
|
+
thread_count,
|
|
140
|
+
cluster_count,
|
|
141
|
+
hierarchy_depth,
|
|
142
|
+
error,
|
|
143
|
+
started_at,
|
|
144
|
+
completed_at
|
|
145
|
+
FROM weave.consolidation_runs
|
|
146
|
+
WHERE organization_id = $1
|
|
147
|
+
ORDER BY started_at DESC
|
|
148
|
+
LIMIT $3 OFFSET $2`;
|
|
149
|
+
async function listConsolidationRunsByOrganization(client, args) {
|
|
150
|
+
const result = await client.query({
|
|
151
|
+
text: exports.listConsolidationRunsByOrganizationQuery,
|
|
152
|
+
values: [args.organizationId, args.pageOffset, args.pageSize],
|
|
153
|
+
rowMode: "array"
|
|
154
|
+
});
|
|
155
|
+
return result.rows.map(row => {
|
|
156
|
+
return {
|
|
157
|
+
id: row[0],
|
|
158
|
+
organizationId: row[1],
|
|
159
|
+
status: row[2],
|
|
160
|
+
threadCount: row[3],
|
|
161
|
+
clusterCount: row[4],
|
|
162
|
+
hierarchyDepth: row[5],
|
|
163
|
+
error: row[6],
|
|
164
|
+
startedAt: row[7],
|
|
165
|
+
completedAt: row[8]
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
exports.upsertConceptClusterQuery = `-- name: UpsertConceptCluster :one
|
|
170
|
+
INSERT INTO weave.concept_clusters (
|
|
171
|
+
id,
|
|
172
|
+
organization_id,
|
|
173
|
+
realm_kind,
|
|
174
|
+
realm_key,
|
|
175
|
+
name,
|
|
176
|
+
description,
|
|
177
|
+
knowledge_type,
|
|
178
|
+
level,
|
|
179
|
+
parent_id,
|
|
180
|
+
embedding,
|
|
181
|
+
centroid,
|
|
182
|
+
thread_count,
|
|
183
|
+
consolidation_run_id
|
|
184
|
+
) VALUES (
|
|
185
|
+
$1,
|
|
186
|
+
$2,
|
|
187
|
+
$3,
|
|
188
|
+
$4,
|
|
189
|
+
$5,
|
|
190
|
+
$6,
|
|
191
|
+
$7,
|
|
192
|
+
$8,
|
|
193
|
+
$9,
|
|
194
|
+
$10::vector,
|
|
195
|
+
$11::vector,
|
|
196
|
+
$12,
|
|
197
|
+
$13
|
|
198
|
+
)
|
|
199
|
+
ON CONFLICT (id) DO UPDATE
|
|
200
|
+
SET
|
|
201
|
+
name = EXCLUDED.name,
|
|
202
|
+
description = EXCLUDED.description,
|
|
203
|
+
realm_kind = EXCLUDED.realm_kind,
|
|
204
|
+
realm_key = EXCLUDED.realm_key,
|
|
205
|
+
knowledge_type = EXCLUDED.knowledge_type,
|
|
206
|
+
level = EXCLUDED.level,
|
|
207
|
+
parent_id = EXCLUDED.parent_id,
|
|
208
|
+
embedding = EXCLUDED.embedding,
|
|
209
|
+
centroid = EXCLUDED.centroid,
|
|
210
|
+
thread_count = EXCLUDED.thread_count,
|
|
211
|
+
consolidation_run_id = EXCLUDED.consolidation_run_id,
|
|
212
|
+
updated_at = now()
|
|
213
|
+
RETURNING
|
|
214
|
+
id,
|
|
215
|
+
organization_id,
|
|
216
|
+
realm_kind,
|
|
217
|
+
realm_key,
|
|
218
|
+
name,
|
|
219
|
+
description,
|
|
220
|
+
knowledge_type,
|
|
221
|
+
level,
|
|
222
|
+
parent_id,
|
|
223
|
+
thread_count,
|
|
224
|
+
consolidation_run_id,
|
|
225
|
+
created_at,
|
|
226
|
+
updated_at`;
|
|
227
|
+
async function upsertConceptCluster(client, args) {
|
|
228
|
+
const result = await client.query({
|
|
229
|
+
text: exports.upsertConceptClusterQuery,
|
|
230
|
+
values: [args.id, args.organizationId, args.realmKind, args.realmKey, args.name, args.description, args.knowledgeType, args.level, args.parentId, args.embedding, args.centroid, args.threadCount, args.consolidationRunId],
|
|
231
|
+
rowMode: "array"
|
|
232
|
+
});
|
|
233
|
+
if (result.rows.length !== 1) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
const row = result.rows[0];
|
|
237
|
+
return {
|
|
238
|
+
id: row[0],
|
|
239
|
+
organizationId: row[1],
|
|
240
|
+
realmKind: row[2],
|
|
241
|
+
realmKey: row[3],
|
|
242
|
+
name: row[4],
|
|
243
|
+
description: row[5],
|
|
244
|
+
knowledgeType: row[6],
|
|
245
|
+
level: row[7],
|
|
246
|
+
parentId: row[8],
|
|
247
|
+
threadCount: row[9],
|
|
248
|
+
consolidationRunId: row[10],
|
|
249
|
+
createdAt: row[11],
|
|
250
|
+
updatedAt: row[12]
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
exports.getConceptClusterByOrganizationRealmAndIDQuery = `-- name: GetConceptClusterByOrganizationRealmAndID :one
|
|
254
|
+
SELECT
|
|
255
|
+
id,
|
|
256
|
+
organization_id,
|
|
257
|
+
realm_kind,
|
|
258
|
+
realm_key,
|
|
259
|
+
name,
|
|
260
|
+
description,
|
|
261
|
+
knowledge_type,
|
|
262
|
+
level,
|
|
263
|
+
parent_id,
|
|
264
|
+
thread_count,
|
|
265
|
+
consolidation_run_id,
|
|
266
|
+
created_at,
|
|
267
|
+
updated_at
|
|
268
|
+
FROM weave.concept_clusters
|
|
269
|
+
WHERE organization_id = $1
|
|
270
|
+
AND realm_kind = $2
|
|
271
|
+
AND realm_key = $3
|
|
272
|
+
AND id = $4`;
|
|
273
|
+
async function getConceptClusterByOrganizationRealmAndID(client, args) {
|
|
274
|
+
const result = await client.query({
|
|
275
|
+
text: exports.getConceptClusterByOrganizationRealmAndIDQuery,
|
|
276
|
+
values: [args.organizationId, args.realmKind, args.realmKey, args.id],
|
|
277
|
+
rowMode: "array"
|
|
278
|
+
});
|
|
279
|
+
if (result.rows.length !== 1) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const row = result.rows[0];
|
|
283
|
+
return {
|
|
284
|
+
id: row[0],
|
|
285
|
+
organizationId: row[1],
|
|
286
|
+
realmKind: row[2],
|
|
287
|
+
realmKey: row[3],
|
|
288
|
+
name: row[4],
|
|
289
|
+
description: row[5],
|
|
290
|
+
knowledgeType: row[6],
|
|
291
|
+
level: row[7],
|
|
292
|
+
parentId: row[8],
|
|
293
|
+
threadCount: row[9],
|
|
294
|
+
consolidationRunId: row[10],
|
|
295
|
+
createdAt: row[11],
|
|
296
|
+
updatedAt: row[12]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
exports.listConceptClustersByRealmQuery = `-- name: ListConceptClustersByRealm :many
|
|
300
|
+
SELECT
|
|
301
|
+
id,
|
|
302
|
+
organization_id,
|
|
303
|
+
realm_kind,
|
|
304
|
+
realm_key,
|
|
305
|
+
name,
|
|
306
|
+
description,
|
|
307
|
+
knowledge_type,
|
|
308
|
+
level,
|
|
309
|
+
parent_id,
|
|
310
|
+
thread_count,
|
|
311
|
+
consolidation_run_id,
|
|
312
|
+
created_at,
|
|
313
|
+
updated_at
|
|
314
|
+
FROM weave.concept_clusters
|
|
315
|
+
WHERE organization_id = $1
|
|
316
|
+
AND realm_kind = $2
|
|
317
|
+
AND realm_key = $3
|
|
318
|
+
AND ($4 = '' OR knowledge_type = $4)
|
|
319
|
+
AND ($5 <= 0 OR level <= $5)
|
|
320
|
+
ORDER BY level ASC, updated_at DESC, id ASC`;
|
|
321
|
+
async function listConceptClustersByRealm(client, args) {
|
|
322
|
+
const result = await client.query({
|
|
323
|
+
text: exports.listConceptClustersByRealmQuery,
|
|
324
|
+
values: [args.organizationId, args.realmKind, args.realmKey, args.knowledgeType, args.maxDepth],
|
|
325
|
+
rowMode: "array"
|
|
326
|
+
});
|
|
327
|
+
return result.rows.map(row => {
|
|
328
|
+
return {
|
|
329
|
+
id: row[0],
|
|
330
|
+
organizationId: row[1],
|
|
331
|
+
realmKind: row[2],
|
|
332
|
+
realmKey: row[3],
|
|
333
|
+
name: row[4],
|
|
334
|
+
description: row[5],
|
|
335
|
+
knowledgeType: row[6],
|
|
336
|
+
level: row[7],
|
|
337
|
+
parentId: row[8],
|
|
338
|
+
threadCount: row[9],
|
|
339
|
+
consolidationRunId: row[10],
|
|
340
|
+
createdAt: row[11],
|
|
341
|
+
updatedAt: row[12]
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
exports.listConceptClustersByParentAndRealmQuery = `-- name: ListConceptClustersByParentAndRealm :many
|
|
346
|
+
SELECT
|
|
347
|
+
id,
|
|
348
|
+
organization_id,
|
|
349
|
+
realm_kind,
|
|
350
|
+
realm_key,
|
|
351
|
+
name,
|
|
352
|
+
description,
|
|
353
|
+
knowledge_type,
|
|
354
|
+
level,
|
|
355
|
+
parent_id,
|
|
356
|
+
thread_count,
|
|
357
|
+
consolidation_run_id,
|
|
358
|
+
created_at,
|
|
359
|
+
updated_at
|
|
360
|
+
FROM weave.concept_clusters
|
|
361
|
+
WHERE organization_id = $1
|
|
362
|
+
AND realm_kind = $2
|
|
363
|
+
AND realm_key = $3
|
|
364
|
+
AND parent_id = $4
|
|
365
|
+
ORDER BY updated_at DESC, id ASC`;
|
|
366
|
+
async function listConceptClustersByParentAndRealm(client, args) {
|
|
367
|
+
const result = await client.query({
|
|
368
|
+
text: exports.listConceptClustersByParentAndRealmQuery,
|
|
369
|
+
values: [args.organizationId, args.realmKind, args.realmKey, args.parentId],
|
|
370
|
+
rowMode: "array"
|
|
371
|
+
});
|
|
372
|
+
return result.rows.map(row => {
|
|
373
|
+
return {
|
|
374
|
+
id: row[0],
|
|
375
|
+
organizationId: row[1],
|
|
376
|
+
realmKind: row[2],
|
|
377
|
+
realmKey: row[3],
|
|
378
|
+
name: row[4],
|
|
379
|
+
description: row[5],
|
|
380
|
+
knowledgeType: row[6],
|
|
381
|
+
level: row[7],
|
|
382
|
+
parentId: row[8],
|
|
383
|
+
threadCount: row[9],
|
|
384
|
+
consolidationRunId: row[10],
|
|
385
|
+
createdAt: row[11],
|
|
386
|
+
updatedAt: row[12]
|
|
387
|
+
};
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
exports.listApprovedThreadsForConsolidationQuery = `-- name: ListApprovedThreadsForConsolidation :many
|
|
391
|
+
SELECT
|
|
392
|
+
t.id,
|
|
393
|
+
t.organization_id,
|
|
394
|
+
t.document_id,
|
|
395
|
+
t.ingestion_run_id,
|
|
396
|
+
t.text,
|
|
397
|
+
t.knowledge_type,
|
|
398
|
+
t.embedding::text AS embedding_text,
|
|
399
|
+
t.approved_at,
|
|
400
|
+
CASE
|
|
401
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_ORG'
|
|
402
|
+
THEN 'KNOWLEDGE_REALM_KIND_ORG'::text
|
|
403
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
404
|
+
THEN 'KNOWLEDGE_REALM_KIND_TAG'::text
|
|
405
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
406
|
+
THEN 'KNOWLEDGE_REALM_KIND_USER'::text
|
|
407
|
+
END AS realm_kind,
|
|
408
|
+
CASE
|
|
409
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_ORG'
|
|
410
|
+
THEN ''::text
|
|
411
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
412
|
+
THEN COALESCE(d.sensitivity_tags[1], ''::text)
|
|
413
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
414
|
+
THEN d.uploaded_by_user_id::text
|
|
415
|
+
END AS realm_key
|
|
416
|
+
FROM weave.threads t
|
|
417
|
+
JOIN weave.documents d ON d.id = t.document_id
|
|
418
|
+
WHERE t.organization_id = $1
|
|
419
|
+
AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'
|
|
420
|
+
AND t.embedding IS NOT NULL
|
|
421
|
+
ORDER BY t.approved_at DESC, t.id ASC
|
|
422
|
+
LIMIT $3 OFFSET $2`;
|
|
423
|
+
async function listApprovedThreadsForConsolidation(client, args) {
|
|
424
|
+
const result = await client.query({
|
|
425
|
+
text: exports.listApprovedThreadsForConsolidationQuery,
|
|
426
|
+
values: [args.organizationId, args.pageOffset, args.pageSize],
|
|
427
|
+
rowMode: "array"
|
|
428
|
+
});
|
|
429
|
+
return result.rows.map(row => {
|
|
430
|
+
return {
|
|
431
|
+
id: row[0],
|
|
432
|
+
organizationId: row[1],
|
|
433
|
+
documentId: row[2],
|
|
434
|
+
ingestionRunId: row[3],
|
|
435
|
+
text: row[4],
|
|
436
|
+
knowledgeType: row[5],
|
|
437
|
+
embeddingText: row[6],
|
|
438
|
+
approvedAt: row[7],
|
|
439
|
+
realmKind: row[8],
|
|
440
|
+
realmKey: row[9]
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
exports.assignThreadsToClusterQuery = `-- name: AssignThreadsToCluster :execrows
|
|
445
|
+
UPDATE weave.threads AS t
|
|
446
|
+
SET cluster_id = cc.id
|
|
447
|
+
FROM weave.concept_clusters cc,
|
|
448
|
+
weave.documents d
|
|
449
|
+
WHERE t.organization_id = $1
|
|
450
|
+
AND t.id = ANY($2::uuid[])
|
|
451
|
+
AND cc.organization_id = t.organization_id
|
|
452
|
+
AND cc.id = $3
|
|
453
|
+
AND d.id = t.document_id
|
|
454
|
+
AND (
|
|
455
|
+
(cc.realm_kind = 'KNOWLEDGE_REALM_KIND_ORG'
|
|
456
|
+
AND cc.realm_key = ''
|
|
457
|
+
AND d.scope = 'DOCUMENT_SCOPE_ORG')
|
|
458
|
+
OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_TAG'
|
|
459
|
+
AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
460
|
+
AND cardinality(d.sensitivity_tags) = 1
|
|
461
|
+
AND cc.realm_key = d.sensitivity_tags[1])
|
|
462
|
+
OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_USER'
|
|
463
|
+
AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
464
|
+
AND cc.realm_key = d.uploaded_by_user_id::text)
|
|
465
|
+
)`;
|
|
466
|
+
exports.clearThreadClusterAssignmentsByOrganizationQuery = `-- name: ClearThreadClusterAssignmentsByOrganization :execrows
|
|
467
|
+
UPDATE weave.threads
|
|
468
|
+
SET cluster_id = NULL
|
|
469
|
+
WHERE organization_id = $1
|
|
470
|
+
AND cluster_id IS NOT NULL`;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const setDocumentSecurityQuery = "-- name: SetDocumentSecurity :one\nUPDATE weave.documents\nSET\n scope = $1,\n sensitivity_tags = $2,\n updated_at = now()\nWHERE organization_id = $3\n AND id = $4\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n sensitivity_tags,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata";
|
|
6
|
+
export interface SetDocumentSecurityArgs {
|
|
7
|
+
scope: string;
|
|
8
|
+
sensitivityTags: string[];
|
|
9
|
+
organizationId: string;
|
|
10
|
+
documentId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SetDocumentSecurityRow {
|
|
13
|
+
id: string;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
filename: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
parserName: string;
|
|
18
|
+
fingerprint: Buffer | null;
|
|
19
|
+
storageRef: string;
|
|
20
|
+
status: string;
|
|
21
|
+
scope: string;
|
|
22
|
+
sensitivityTags: string[];
|
|
23
|
+
uploadedByUserId: string;
|
|
24
|
+
uploadedAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
pageCount: number | null;
|
|
27
|
+
charCount: number | null;
|
|
28
|
+
metadata: any;
|
|
29
|
+
}
|
|
30
|
+
export declare function setDocumentSecurity(client: Client, args: SetDocumentSecurityArgs): Promise<SetDocumentSecurityRow | null>;
|
|
31
|
+
export declare const upsertOrganizationSensitivityTagQuery = "-- name: UpsertOrganizationSensitivityTag :one\nINSERT INTO weave.org_sensitivity_tags (\n organization_id,\n slug,\n label,\n description,\n extraction_hint,\n active\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)\nON CONFLICT (organization_id, slug) DO UPDATE\nSET\n label = EXCLUDED.label,\n description = EXCLUDED.description,\n extraction_hint = EXCLUDED.extraction_hint,\n active = EXCLUDED.active,\n updated_at = now()\nRETURNING\n organization_id,\n slug,\n label,\n description,\n extraction_hint,\n active,\n created_at,\n updated_at";
|
|
32
|
+
export interface UpsertOrganizationSensitivityTagArgs {
|
|
33
|
+
organizationId: string;
|
|
34
|
+
slug: string;
|
|
35
|
+
label: string;
|
|
36
|
+
description: string;
|
|
37
|
+
extractionHint: string;
|
|
38
|
+
active: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface UpsertOrganizationSensitivityTagRow {
|
|
41
|
+
organizationId: string;
|
|
42
|
+
slug: string;
|
|
43
|
+
label: string;
|
|
44
|
+
description: string;
|
|
45
|
+
extractionHint: string;
|
|
46
|
+
active: boolean;
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
updatedAt: Date;
|
|
49
|
+
}
|
|
50
|
+
export declare function upsertOrganizationSensitivityTag(client: Client, args: UpsertOrganizationSensitivityTagArgs): Promise<UpsertOrganizationSensitivityTagRow | null>;
|
|
51
|
+
export declare const listOrganizationSensitivityTagsQuery = "-- name: ListOrganizationSensitivityTags :many\nSELECT\n organization_id,\n slug,\n label,\n description,\n extraction_hint,\n active,\n created_at,\n updated_at\nFROM weave.org_sensitivity_tags\nWHERE organization_id = $1\nORDER BY slug ASC";
|
|
52
|
+
export interface ListOrganizationSensitivityTagsArgs {
|
|
53
|
+
organizationId: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ListOrganizationSensitivityTagsRow {
|
|
56
|
+
organizationId: string;
|
|
57
|
+
slug: string;
|
|
58
|
+
label: string;
|
|
59
|
+
description: string;
|
|
60
|
+
extractionHint: string;
|
|
61
|
+
active: boolean;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
updatedAt: Date;
|
|
64
|
+
}
|
|
65
|
+
export declare function listOrganizationSensitivityTags(client: Client, args: ListOrganizationSensitivityTagsArgs): Promise<ListOrganizationSensitivityTagsRow[]>;
|
|
66
|
+
export declare const listActiveOrganizationSensitivityTagsQuery = "-- name: ListActiveOrganizationSensitivityTags :many\nSELECT\n organization_id,\n slug,\n label,\n description,\n extraction_hint,\n active,\n created_at,\n updated_at\nFROM weave.org_sensitivity_tags\nWHERE organization_id = $1\n AND active = TRUE\nORDER BY slug ASC";
|
|
67
|
+
export interface ListActiveOrganizationSensitivityTagsArgs {
|
|
68
|
+
organizationId: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ListActiveOrganizationSensitivityTagsRow {
|
|
71
|
+
organizationId: string;
|
|
72
|
+
slug: string;
|
|
73
|
+
label: string;
|
|
74
|
+
description: string;
|
|
75
|
+
extractionHint: string;
|
|
76
|
+
active: boolean;
|
|
77
|
+
createdAt: Date;
|
|
78
|
+
updatedAt: Date;
|
|
79
|
+
}
|
|
80
|
+
export declare function listActiveOrganizationSensitivityTags(client: Client, args: ListActiveOrganizationSensitivityTagsArgs): Promise<ListActiveOrganizationSensitivityTagsRow[]>;
|
|
81
|
+
export declare const deactivateOrganizationSensitivityTagQuery = "-- name: DeactivateOrganizationSensitivityTag :one\nUPDATE weave.org_sensitivity_tags\nSET\n active = FALSE,\n updated_at = now()\nWHERE organization_id = $1\n AND slug = $2\nRETURNING\n organization_id,\n slug,\n label,\n description,\n extraction_hint,\n active,\n created_at,\n updated_at";
|
|
82
|
+
export interface DeactivateOrganizationSensitivityTagArgs {
|
|
83
|
+
organizationId: string;
|
|
84
|
+
slug: string;
|
|
85
|
+
}
|
|
86
|
+
export interface DeactivateOrganizationSensitivityTagRow {
|
|
87
|
+
organizationId: string;
|
|
88
|
+
slug: string;
|
|
89
|
+
label: string;
|
|
90
|
+
description: string;
|
|
91
|
+
extractionHint: string;
|
|
92
|
+
active: boolean;
|
|
93
|
+
createdAt: Date;
|
|
94
|
+
updatedAt: Date;
|
|
95
|
+
}
|
|
96
|
+
export declare function deactivateOrganizationSensitivityTag(client: Client, args: DeactivateOrganizationSensitivityTagArgs): Promise<DeactivateOrganizationSensitivityTagRow | null>;
|
|
97
|
+
export declare const grantUserSensitivityClearanceQuery = "-- name: GrantUserSensitivityClearance :one\nINSERT INTO weave.user_sensitivity_clearances (\n organization_id,\n user_id,\n sensitivity_tag_slug\n) VALUES (\n $1,\n $2,\n $3\n)\nON CONFLICT (organization_id, user_id, sensitivity_tag_slug) DO UPDATE\nSET\n sensitivity_tag_slug = EXCLUDED.sensitivity_tag_slug\nRETURNING\n organization_id,\n user_id,\n sensitivity_tag_slug,\n created_at";
|
|
98
|
+
export interface GrantUserSensitivityClearanceArgs {
|
|
99
|
+
organizationId: string;
|
|
100
|
+
userId: string;
|
|
101
|
+
sensitivityTagSlug: string;
|
|
102
|
+
}
|
|
103
|
+
export interface GrantUserSensitivityClearanceRow {
|
|
104
|
+
organizationId: string;
|
|
105
|
+
userId: string;
|
|
106
|
+
sensitivityTagSlug: string;
|
|
107
|
+
createdAt: Date;
|
|
108
|
+
}
|
|
109
|
+
export declare function grantUserSensitivityClearance(client: Client, args: GrantUserSensitivityClearanceArgs): Promise<GrantUserSensitivityClearanceRow | null>;
|
|
110
|
+
export declare const revokeUserSensitivityClearanceQuery = "-- name: RevokeUserSensitivityClearance :execrows\nDELETE FROM weave.user_sensitivity_clearances\nWHERE organization_id = $1\n AND user_id = $2\n AND sensitivity_tag_slug = $3";
|
|
111
|
+
export interface RevokeUserSensitivityClearanceArgs {
|
|
112
|
+
organizationId: string;
|
|
113
|
+
userId: string;
|
|
114
|
+
sensitivityTagSlug: string;
|
|
115
|
+
}
|
|
116
|
+
export declare const listUserSensitivityClearancesQuery = "-- name: ListUserSensitivityClearances :many\nSELECT\n organization_id,\n user_id,\n sensitivity_tag_slug,\n created_at\nFROM weave.user_sensitivity_clearances\nWHERE organization_id = $1\n AND user_id = $2\nORDER BY sensitivity_tag_slug ASC";
|
|
117
|
+
export interface ListUserSensitivityClearancesArgs {
|
|
118
|
+
organizationId: string;
|
|
119
|
+
userId: string;
|
|
120
|
+
}
|
|
121
|
+
export interface ListUserSensitivityClearancesRow {
|
|
122
|
+
organizationId: string;
|
|
123
|
+
userId: string;
|
|
124
|
+
sensitivityTagSlug: string;
|
|
125
|
+
createdAt: Date;
|
|
126
|
+
}
|
|
127
|
+
export declare function listUserSensitivityClearances(client: Client, args: ListUserSensitivityClearancesArgs): Promise<ListUserSensitivityClearancesRow[]>;
|
|
128
|
+
export {};
|