weave-typescript 0.51.3 → 0.52.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/google/protobuf/duration.pb.d.ts +99 -0
- package/dist/google/protobuf/duration.pb.js +93 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/weave/authz/v1/index.d.ts +1 -0
- package/dist/weave/authz/v1/index.js +38 -0
- package/dist/weave/authz/v1/options.pb.d.ts +52 -0
- package/dist/weave/authz/v1/options.pb.js +403 -0
- package/dist/weave/filter/v1/index.d.ts +1 -0
- package/dist/weave/filter/v1/index.js +38 -0
- package/dist/{weaveapi/atc/v1/message.pb.d.ts → weave/filter/v1/options.pb.d.ts} +33 -21
- package/dist/weave/filter/v1/options.pb.js +417 -0
- package/dist/weave/index.d.ts +2 -0
- package/dist/weave/index.js +39 -0
- package/dist/weaveapi/agent/v1/agent.pb.d.ts +137 -188
- package/dist/weaveapi/agent/v1/agent.pb.js +891 -2151
- package/dist/weaveapi/agent/v1/index.d.ts +1 -1
- package/dist/weaveapi/agent/v1/index.js +2 -2
- package/dist/weaveapi/agent/v1/run.pb.d.ts +289 -0
- package/dist/weaveapi/agent/v1/run.pb.js +2763 -0
- package/dist/weaveapi/auth/v1/auth.pb.d.ts +67 -14
- package/dist/weaveapi/auth/v1/auth.pb.js +829 -89
- package/dist/weaveapi/auth/v1/index.d.ts +4 -1
- package/dist/weaveapi/auth/v1/index.js +5 -2
- package/dist/weaveapi/auth/v1/{service.pb.d.ts → organization_admin.pb.d.ts} +39 -530
- package/dist/weaveapi/auth/v1/{service.pb.js → organization_admin.pb.js} +2978 -5812
- package/dist/weaveapi/auth/v1/personal_access_token.pb.d.ts +114 -0
- package/dist/weaveapi/auth/v1/personal_access_token.pb.js +750 -0
- package/dist/weaveapi/auth/v1/profile.pb.d.ts +161 -0
- package/dist/weaveapi/auth/v1/profile.pb.js +1007 -0
- package/dist/weaveapi/auth/v1/session.pb.d.ts +460 -0
- package/dist/weaveapi/auth/v1/session.pb.js +3544 -0
- package/dist/weaveapi/chat/v1/chat.pb.d.ts +377 -149
- package/dist/weaveapi/chat/v1/chat.pb.js +3492 -1614
- package/dist/weaveapi/chat/v1/index.d.ts +0 -1
- package/dist/weaveapi/chat/v1/index.js +1 -2
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +95 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +770 -1
- package/dist/weaveapi/consolidation/v1/index.d.ts +0 -1
- package/dist/weaveapi/consolidation/v1/index.js +1 -2
- package/dist/weaveapi/content/v1/content.pb.d.ts +63 -0
- package/dist/weaveapi/content/v1/content.pb.js +470 -0
- package/dist/weaveapi/content/v1/index.d.ts +1 -0
- package/dist/weaveapi/content/v1/index.js +38 -0
- package/dist/weaveapi/gateway/v1/gateway.pb.d.ts +247 -523
- package/dist/weaveapi/gateway/v1/gateway.pb.js +1648 -5783
- package/dist/weaveapi/gateway/v1/index.d.ts +0 -1
- package/dist/weaveapi/gateway/v1/index.js +1 -2
- package/dist/weaveapi/index.d.ts +5 -5
- package/dist/weaveapi/index.js +6 -6
- package/dist/weaveapi/inference/v1/generate.pb.d.ts +120 -0
- package/dist/weaveapi/inference/v1/generate.pb.js +1159 -0
- package/dist/weaveapi/inference/v1/index.d.ts +4 -0
- package/dist/weaveapi/{provider → inference}/v1/index.js +4 -2
- package/dist/weaveapi/{model → inference}/v1/model.pb.d.ts +52 -15
- package/dist/weaveapi/{model → inference}/v1/model.pb.js +529 -116
- package/dist/weaveapi/{model/v1/service.pb.d.ts → inference/v1/model_route.pb.d.ts} +182 -110
- package/dist/weaveapi/{model/v1/service.pb.js → inference/v1/model_route.pb.js} +2197 -1061
- package/dist/weaveapi/inference/v1/provider.pb.d.ts +264 -0
- package/dist/weaveapi/inference/v1/provider.pb.js +2590 -0
- package/dist/weaveapi/ingestion/v1/index.d.ts +0 -2
- package/dist/weaveapi/ingestion/v1/index.js +1 -3
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +543 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5550 -16
- package/dist/weaveapi/initialization/v1/index.d.ts +1 -0
- package/dist/weaveapi/initialization/v1/index.js +38 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.d.ts +99 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.js +510 -0
- package/dist/weaveapi/organization/v1/index.d.ts +0 -1
- package/dist/weaveapi/organization/v1/index.js +1 -2
- package/dist/weaveapi/organization/v1/organization.pb.d.ts +241 -0
- package/dist/weaveapi/organization/v1/organization.pb.js +1838 -1
- package/dist/weaveapi/reporting/index.d.ts +1 -0
- package/dist/weaveapi/reporting/index.js +38 -0
- package/dist/weaveapi/{task → reporting}/v1/index.d.ts +1 -1
- package/dist/weaveapi/{model → reporting}/v1/index.js +2 -2
- package/dist/weaveapi/reporting/v1/service.pb.d.ts +38 -0
- package/dist/weaveapi/reporting/v1/service.pb.js +167 -0
- package/dist/weaveapi/reporting/v1/usage.pb.d.ts +150 -0
- package/dist/weaveapi/reporting/v1/usage.pb.js +1837 -0
- package/dist/weaveapi/retrieval/v1/index.d.ts +0 -1
- package/dist/weaveapi/retrieval/v1/index.js +1 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +96 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +690 -10
- package/dist/weaveapi/tool/index.d.ts +1 -0
- package/dist/weaveapi/tool/index.js +38 -0
- package/dist/weaveapi/tool/v1/index.d.ts +1 -0
- package/dist/weaveapi/tool/v1/index.js +38 -0
- package/dist/weaveapi/tool/v1/tool.pb.d.ts +370 -0
- package/dist/weaveapi/tool/v1/tool.pb.js +2717 -0
- package/dist/weaveapi/workflow/v1/index.d.ts +1 -1
- package/dist/weaveapi/workflow/v1/index.js +2 -2
- package/dist/weaveapi/workflow/v1/run.pb.d.ts +244 -0
- package/dist/weaveapi/workflow/v1/run.pb.js +2084 -0
- package/dist/weaveapi/workflow/v1/workflow.pb.d.ts +122 -275
- package/dist/weaveapi/workflow/v1/workflow.pb.js +790 -3261
- package/dist/weavesql/weavedb/agent_sql.d.ts +173 -477
- package/dist/weavesql/weavedb/agent_sql.js +281 -758
- package/dist/weavesql/weavedb/authorization_outbox_sql.d.ts +261 -0
- package/dist/weavesql/weavedb/authorization_outbox_sql.js +445 -0
- package/dist/weavesql/weavedb/chat_sql.d.ts +103 -345
- package/dist/weavesql/weavedb/chat_sql.js +312 -597
- package/dist/weavesql/weavedb/document_consolidation_sql.d.ts +217 -0
- package/dist/weavesql/weavedb/document_consolidation_sql.js +486 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.d.ts +1433 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.js +3488 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.d.ts +314 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.js +965 -0
- package/dist/weavesql/weavedb/document_table_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/document_table_sql.js +12 -12
- package/dist/weavesql/weavedb/identity_sql.d.ts +1014 -0
- package/dist/weavesql/weavedb/identity_sql.js +1811 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.d.ts +161 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.js +408 -0
- package/dist/weavesql/weavedb/inference_provider_sql.d.ts +125 -0
- package/dist/weavesql/weavedb/inference_provider_sql.js +228 -0
- package/dist/weavesql/weavedb/initialization_sql.d.ts +15 -0
- package/dist/weavesql/weavedb/initialization_sql.js +33 -0
- package/dist/weavesql/weavedb/model_catalog_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/model_catalog_sql.js +6 -6
- package/dist/weavesql/weavedb/organization_sql.d.ts +22 -102
- package/dist/weavesql/weavedb/organization_sql.js +54 -262
- package/dist/weavesql/weavedb/tool_sql.d.ts +209 -0
- package/dist/weavesql/weavedb/tool_sql.js +407 -0
- package/dist/weavesql/weavedb/usage_sql.d.ts +356 -0
- package/dist/weavesql/weavedb/usage_sql.js +568 -0
- package/dist/weavesql/weavedb/workflow_sql.d.ts +159 -546
- package/dist/weavesql/weavedb/workflow_sql.js +281 -909
- package/package.json +1 -1
- package/dist/weaveapi/agent/v1/service.pb.d.ts +0 -397
- package/dist/weaveapi/agent/v1/service.pb.js +0 -3152
- package/dist/weaveapi/atc/v1/event.pb.d.ts +0 -134
- package/dist/weaveapi/atc/v1/event.pb.js +0 -1124
- package/dist/weaveapi/atc/v1/index.d.ts +0 -5
- package/dist/weaveapi/atc/v1/index.js +0 -42
- package/dist/weaveapi/atc/v1/message.pb.js +0 -287
- package/dist/weaveapi/atc/v1/process.pb.d.ts +0 -91
- package/dist/weaveapi/atc/v1/process.pb.js +0 -658
- package/dist/weaveapi/atc/v1/run.pb.d.ts +0 -71
- package/dist/weaveapi/atc/v1/run.pb.js +0 -525
- package/dist/weaveapi/atc/v1/service.pb.d.ts +0 -472
- package/dist/weaveapi/atc/v1/service.pb.js +0 -3093
- package/dist/weaveapi/chat/v1/service.pb.d.ts +0 -345
- package/dist/weaveapi/chat/v1/service.pb.js +0 -2545
- package/dist/weaveapi/consolidation/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/consolidation/v1/service.pb.js +0 -427
- package/dist/weaveapi/gateway/v1/service.pb.d.ts +0 -235
- package/dist/weaveapi/gateway/v1/service.pb.js +0 -651
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +0 -420
- package/dist/weaveapi/ingestion/v1/service.pb.js +0 -2311
- package/dist/weaveapi/ingestion/v1/table.pb.d.ts +0 -121
- package/dist/weaveapi/ingestion/v1/table.pb.js +0 -1478
- package/dist/weaveapi/model/v1/index.d.ts +0 -2
- package/dist/weaveapi/organization/v1/service.pb.d.ts +0 -261
- package/dist/weaveapi/organization/v1/service.pb.js +0 -1561
- package/dist/weaveapi/project/v1/index.d.ts +0 -2
- package/dist/weaveapi/project/v1/index.js +0 -39
- package/dist/weaveapi/project/v1/project.pb.d.ts +0 -105
- package/dist/weaveapi/project/v1/project.pb.js +0 -1004
- package/dist/weaveapi/project/v1/service.pb.d.ts +0 -247
- package/dist/weaveapi/project/v1/service.pb.js +0 -1994
- package/dist/weaveapi/provider/v1/index.d.ts +0 -2
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +0 -137
- package/dist/weaveapi/provider/v1/provider.pb.js +0 -1000
- package/dist/weaveapi/provider/v1/service.pb.d.ts +0 -223
- package/dist/weaveapi/provider/v1/service.pb.js +0 -1888
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/retrieval/v1/service.pb.js +0 -385
- package/dist/weaveapi/task/v1/index.js +0 -39
- package/dist/weaveapi/task/v1/service.pb.d.ts +0 -172
- package/dist/weaveapi/task/v1/service.pb.js +0 -1436
- package/dist/weaveapi/task/v1/task.pb.d.ts +0 -85
- package/dist/weaveapi/task/v1/task.pb.js +0 -802
- package/dist/weaveapi/workflow/v1/service.pb.d.ts +0 -392
- package/dist/weaveapi/workflow/v1/service.pb.js +0 -3146
- /package/dist/{weaveapi/atc → weave/authz}/index.d.ts +0 -0
- /package/dist/{weaveapi/atc → weave/authz}/index.js +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.d.ts +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.js +0 -0
- /package/dist/weaveapi/{project → content}/index.d.ts +0 -0
- /package/dist/weaveapi/{project → content}/index.js +0 -0
- /package/dist/weaveapi/{provider → inference}/index.d.ts +0 -0
- /package/dist/weaveapi/{provider → inference}/index.js +0 -0
- /package/dist/weaveapi/{task → initialization}/index.d.ts +0 -0
- /package/dist/weaveapi/{task → initialization}/index.js +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const createConsolidationRunQuery = "-- name: CreateConsolidationRun :one\nINSERT INTO weave.consolidation_runs (\n id,\n organization_id,\n status\n) VALUES (\n $1,\n $2,\n $3\n)\nRETURNING\n id,\n organization_id,\n status,\n thread_count,\n cluster_count,\n hierarchy_depth,\n error,\n started_at,\n completed_at";
|
|
6
|
+
export interface CreateConsolidationRunArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
organizationId: string;
|
|
9
|
+
status: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateConsolidationRunRow {
|
|
12
|
+
id: string;
|
|
13
|
+
organizationId: string;
|
|
14
|
+
status: string;
|
|
15
|
+
threadCount: number;
|
|
16
|
+
clusterCount: number;
|
|
17
|
+
hierarchyDepth: number;
|
|
18
|
+
error: string;
|
|
19
|
+
startedAt: Date;
|
|
20
|
+
completedAt: Date | null;
|
|
21
|
+
}
|
|
22
|
+
export declare function createConsolidationRun(client: Client, args: CreateConsolidationRunArgs): Promise<CreateConsolidationRunRow | null>;
|
|
23
|
+
export declare const getConsolidationRunByOrganizationAndIDQuery = "-- name: GetConsolidationRunByOrganizationAndID :one\nSELECT\n id,\n organization_id,\n status,\n thread_count,\n cluster_count,\n hierarchy_depth,\n error,\n started_at,\n completed_at\nFROM weave.consolidation_runs\nWHERE organization_id = $1\n AND id = $2";
|
|
24
|
+
export interface GetConsolidationRunByOrganizationAndIDArgs {
|
|
25
|
+
organizationId: string;
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
export interface GetConsolidationRunByOrganizationAndIDRow {
|
|
29
|
+
id: string;
|
|
30
|
+
organizationId: string;
|
|
31
|
+
status: string;
|
|
32
|
+
threadCount: number;
|
|
33
|
+
clusterCount: number;
|
|
34
|
+
hierarchyDepth: number;
|
|
35
|
+
error: string;
|
|
36
|
+
startedAt: Date;
|
|
37
|
+
completedAt: Date | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function getConsolidationRunByOrganizationAndID(client: Client, args: GetConsolidationRunByOrganizationAndIDArgs): Promise<GetConsolidationRunByOrganizationAndIDRow | null>;
|
|
40
|
+
export declare const updateConsolidationRunStateQuery = "-- name: UpdateConsolidationRunState :one\nUPDATE weave.consolidation_runs\nSET\n status = $1,\n thread_count = $2,\n cluster_count = $3,\n hierarchy_depth = $4,\n error = $5,\n completed_at = $6\nWHERE id = $7\n AND organization_id = $8\nRETURNING\n id,\n organization_id,\n status,\n thread_count,\n cluster_count,\n hierarchy_depth,\n error,\n started_at,\n completed_at";
|
|
41
|
+
export interface UpdateConsolidationRunStateArgs {
|
|
42
|
+
status: string;
|
|
43
|
+
threadCount: number;
|
|
44
|
+
clusterCount: number;
|
|
45
|
+
hierarchyDepth: number;
|
|
46
|
+
error: string;
|
|
47
|
+
completedAt: Date | null;
|
|
48
|
+
id: string;
|
|
49
|
+
organizationId: string;
|
|
50
|
+
}
|
|
51
|
+
export interface UpdateConsolidationRunStateRow {
|
|
52
|
+
id: string;
|
|
53
|
+
organizationId: string;
|
|
54
|
+
status: string;
|
|
55
|
+
threadCount: number;
|
|
56
|
+
clusterCount: number;
|
|
57
|
+
hierarchyDepth: number;
|
|
58
|
+
error: string;
|
|
59
|
+
startedAt: Date;
|
|
60
|
+
completedAt: Date | null;
|
|
61
|
+
}
|
|
62
|
+
export declare function updateConsolidationRunState(client: Client, args: UpdateConsolidationRunStateArgs): Promise<UpdateConsolidationRunStateRow | null>;
|
|
63
|
+
export declare const listConsolidationRunsByOrganizationQuery = "-- name: ListConsolidationRunsByOrganization :many\nSELECT\n id,\n organization_id,\n status,\n thread_count,\n cluster_count,\n hierarchy_depth,\n error,\n started_at,\n completed_at\nFROM weave.consolidation_runs\nWHERE organization_id = $1\nORDER BY started_at DESC\nLIMIT $3 OFFSET $2";
|
|
64
|
+
export interface ListConsolidationRunsByOrganizationArgs {
|
|
65
|
+
organizationId: string;
|
|
66
|
+
pageOffset: string;
|
|
67
|
+
pageSize: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ListConsolidationRunsByOrganizationRow {
|
|
70
|
+
id: string;
|
|
71
|
+
organizationId: string;
|
|
72
|
+
status: string;
|
|
73
|
+
threadCount: number;
|
|
74
|
+
clusterCount: number;
|
|
75
|
+
hierarchyDepth: number;
|
|
76
|
+
error: string;
|
|
77
|
+
startedAt: Date;
|
|
78
|
+
completedAt: Date | null;
|
|
79
|
+
}
|
|
80
|
+
export declare function listConsolidationRunsByOrganization(client: Client, args: ListConsolidationRunsByOrganizationArgs): Promise<ListConsolidationRunsByOrganizationRow[]>;
|
|
81
|
+
export declare const upsertConceptClusterQuery = "-- name: UpsertConceptCluster :one\nINSERT INTO weave.concept_clusters (\n id,\n organization_id,\n scope_kind,\n scope_key,\n name,\n description,\n knowledge_type,\n level,\n parent_id,\n embedding,\n centroid,\n thread_count,\n consolidation_run_id\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10::vector,\n $11::vector,\n $12,\n $13\n)\nON CONFLICT (id) DO UPDATE\nSET\n name = EXCLUDED.name,\n description = EXCLUDED.description,\n scope_kind = EXCLUDED.scope_kind,\n scope_key = EXCLUDED.scope_key,\n knowledge_type = EXCLUDED.knowledge_type,\n level = EXCLUDED.level,\n parent_id = EXCLUDED.parent_id,\n embedding = EXCLUDED.embedding,\n centroid = EXCLUDED.centroid,\n thread_count = EXCLUDED.thread_count,\n consolidation_run_id = EXCLUDED.consolidation_run_id,\n updated_at = now()\nRETURNING\n id,\n organization_id,\n scope_kind,\n scope_key,\n name,\n description,\n knowledge_type,\n level,\n parent_id,\n thread_count,\n consolidation_run_id,\n created_at,\n updated_at";
|
|
82
|
+
export interface UpsertConceptClusterArgs {
|
|
83
|
+
id: string;
|
|
84
|
+
organizationId: string;
|
|
85
|
+
scopeKind: string;
|
|
86
|
+
scopeKey: string;
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
knowledgeType: string;
|
|
90
|
+
level: number;
|
|
91
|
+
parentId: string | null;
|
|
92
|
+
embedding: string;
|
|
93
|
+
centroid: string;
|
|
94
|
+
threadCount: number;
|
|
95
|
+
consolidationRunId: string;
|
|
96
|
+
}
|
|
97
|
+
export interface UpsertConceptClusterRow {
|
|
98
|
+
id: string;
|
|
99
|
+
organizationId: string;
|
|
100
|
+
scopeKind: string;
|
|
101
|
+
scopeKey: string;
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
knowledgeType: string;
|
|
105
|
+
level: number;
|
|
106
|
+
parentId: string | null;
|
|
107
|
+
threadCount: number;
|
|
108
|
+
consolidationRunId: string;
|
|
109
|
+
createdAt: Date;
|
|
110
|
+
updatedAt: Date;
|
|
111
|
+
}
|
|
112
|
+
export declare function upsertConceptCluster(client: Client, args: UpsertConceptClusterArgs): Promise<UpsertConceptClusterRow | null>;
|
|
113
|
+
export declare const getConceptClusterByOrganizationScopeAndIDQuery = "-- name: GetConceptClusterByOrganizationScopeAndID :one\nSELECT\n id,\n organization_id,\n scope_kind,\n scope_key,\n name,\n description,\n knowledge_type,\n level,\n parent_id,\n thread_count,\n consolidation_run_id,\n created_at,\n updated_at\nFROM weave.concept_clusters\nWHERE organization_id = $1\n AND scope_kind = $2\n AND scope_key = $3\n AND id = $4";
|
|
114
|
+
export interface GetConceptClusterByOrganizationScopeAndIDArgs {
|
|
115
|
+
organizationId: string;
|
|
116
|
+
scopeKind: string;
|
|
117
|
+
scopeKey: string;
|
|
118
|
+
id: string;
|
|
119
|
+
}
|
|
120
|
+
export interface GetConceptClusterByOrganizationScopeAndIDRow {
|
|
121
|
+
id: string;
|
|
122
|
+
organizationId: string;
|
|
123
|
+
scopeKind: string;
|
|
124
|
+
scopeKey: string;
|
|
125
|
+
name: string;
|
|
126
|
+
description: string;
|
|
127
|
+
knowledgeType: string;
|
|
128
|
+
level: number;
|
|
129
|
+
parentId: string | null;
|
|
130
|
+
threadCount: number;
|
|
131
|
+
consolidationRunId: string;
|
|
132
|
+
createdAt: Date;
|
|
133
|
+
updatedAt: Date;
|
|
134
|
+
}
|
|
135
|
+
export declare function getConceptClusterByOrganizationScopeAndID(client: Client, args: GetConceptClusterByOrganizationScopeAndIDArgs): Promise<GetConceptClusterByOrganizationScopeAndIDRow | null>;
|
|
136
|
+
export declare const listConceptClustersByScopeQuery = "-- name: ListConceptClustersByScope :many\nSELECT\n id,\n organization_id,\n scope_kind,\n scope_key,\n name,\n description,\n knowledge_type,\n level,\n parent_id,\n thread_count,\n consolidation_run_id,\n created_at,\n updated_at\nFROM weave.concept_clusters\nWHERE organization_id = $1\n AND scope_kind = $2\n AND scope_key = $3\n AND ($4 = '' OR knowledge_type = $4)\n AND ($5 <= 0 OR level <= $5)\nORDER BY level ASC, updated_at DESC, id ASC";
|
|
137
|
+
export interface ListConceptClustersByScopeArgs {
|
|
138
|
+
organizationId: string;
|
|
139
|
+
scopeKind: string;
|
|
140
|
+
scopeKey: string;
|
|
141
|
+
knowledgeType: string | null;
|
|
142
|
+
maxDepth: string | null;
|
|
143
|
+
}
|
|
144
|
+
export interface ListConceptClustersByScopeRow {
|
|
145
|
+
id: string;
|
|
146
|
+
organizationId: string;
|
|
147
|
+
scopeKind: string;
|
|
148
|
+
scopeKey: string;
|
|
149
|
+
name: string;
|
|
150
|
+
description: string;
|
|
151
|
+
knowledgeType: string;
|
|
152
|
+
level: number;
|
|
153
|
+
parentId: string | null;
|
|
154
|
+
threadCount: number;
|
|
155
|
+
consolidationRunId: string;
|
|
156
|
+
createdAt: Date;
|
|
157
|
+
updatedAt: Date;
|
|
158
|
+
}
|
|
159
|
+
export declare function listConceptClustersByScope(client: Client, args: ListConceptClustersByScopeArgs): Promise<ListConceptClustersByScopeRow[]>;
|
|
160
|
+
export declare const listConceptClustersByParentAndScopeQuery = "-- name: ListConceptClustersByParentAndScope :many\nSELECT\n id,\n organization_id,\n scope_kind,\n scope_key,\n name,\n description,\n knowledge_type,\n level,\n parent_id,\n thread_count,\n consolidation_run_id,\n created_at,\n updated_at\nFROM weave.concept_clusters\nWHERE organization_id = $1\n AND scope_kind = $2\n AND scope_key = $3\n AND parent_id = $4\nORDER BY updated_at DESC, id ASC";
|
|
161
|
+
export interface ListConceptClustersByParentAndScopeArgs {
|
|
162
|
+
organizationId: string;
|
|
163
|
+
scopeKind: string;
|
|
164
|
+
scopeKey: string;
|
|
165
|
+
parentId: string | null;
|
|
166
|
+
}
|
|
167
|
+
export interface ListConceptClustersByParentAndScopeRow {
|
|
168
|
+
id: string;
|
|
169
|
+
organizationId: string;
|
|
170
|
+
scopeKind: string;
|
|
171
|
+
scopeKey: string;
|
|
172
|
+
name: string;
|
|
173
|
+
description: string;
|
|
174
|
+
knowledgeType: string;
|
|
175
|
+
level: number;
|
|
176
|
+
parentId: string | null;
|
|
177
|
+
threadCount: number;
|
|
178
|
+
consolidationRunId: string;
|
|
179
|
+
createdAt: Date;
|
|
180
|
+
updatedAt: Date;
|
|
181
|
+
}
|
|
182
|
+
export declare function listConceptClustersByParentAndScope(client: Client, args: ListConceptClustersByParentAndScopeArgs): Promise<ListConceptClustersByParentAndScopeRow[]>;
|
|
183
|
+
export declare const listApprovedThreadsForConsolidationQuery = "-- name: ListApprovedThreadsForConsolidation :many\nSELECT\n t.id,\n t.organization_id,\n t.document_id,\n t.ingestion_run_id,\n t.text,\n t.knowledge_type,\n t.embedding::text AS embedding_text,\n t.approved_at,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN 'SCOPE_KIND_ORG'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN 'SCOPE_KIND_RESTRICTED_GROUP'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN 'SCOPE_KIND_USER'::text\n END AS scope_kind,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN ''::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN drg.restricted_group_id::text\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN d.uploaded_by_user_id::text\n END AS scope_key\nFROM weave.threads t\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.document_restricted_groups drg\n ON drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\nWHERE t.organization_id = $1\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n AND t.embedding IS NOT NULL\n AND (d.scope <> 'DOCUMENT_SCOPE_RESTRICTED' OR drg.restricted_group_id IS NOT NULL)\nORDER BY t.approved_at DESC, t.id ASC\nLIMIT $3 OFFSET $2";
|
|
184
|
+
export interface ListApprovedThreadsForConsolidationArgs {
|
|
185
|
+
organizationId: string;
|
|
186
|
+
pageOffset: string;
|
|
187
|
+
pageSize: string;
|
|
188
|
+
}
|
|
189
|
+
export interface ListApprovedThreadsForConsolidationRow {
|
|
190
|
+
id: string;
|
|
191
|
+
organizationId: string;
|
|
192
|
+
documentId: string;
|
|
193
|
+
ingestionRunId: string;
|
|
194
|
+
text: string;
|
|
195
|
+
knowledgeType: string;
|
|
196
|
+
embeddingText: string;
|
|
197
|
+
approvedAt: Date | null;
|
|
198
|
+
scopeKind: string | null;
|
|
199
|
+
scopeKey: string | null;
|
|
200
|
+
}
|
|
201
|
+
export declare function listApprovedThreadsForConsolidation(client: Client, args: ListApprovedThreadsForConsolidationArgs): Promise<ListApprovedThreadsForConsolidationRow[]>;
|
|
202
|
+
export declare const assignThreadsToClusterQuery = "-- name: AssignThreadsToCluster :execrows\nUPDATE weave.threads AS t\nSET cluster_id = cc.id\nFROM weave.concept_clusters cc,\n weave.documents d\nWHERE t.organization_id = $1\n AND t.id = ANY($2::uuid[])\n AND cc.organization_id = t.organization_id\n AND cc.id = $3\n AND d.id = t.document_id\n AND (\n (cc.scope_kind = 'SCOPE_KIND_ORG'\n AND cc.scope_key = ''\n AND d.scope = 'DOCUMENT_SCOPE_ORG')\n OR (cc.scope_kind = 'SCOPE_KIND_RESTRICTED_GROUP'\n AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n AND drg.restricted_group_id::text = cc.scope_key\n ))\n OR (cc.scope_kind = 'SCOPE_KIND_USER'\n AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND cc.scope_key = d.uploaded_by_user_id::text)\n )";
|
|
203
|
+
export interface AssignThreadsToClusterArgs {
|
|
204
|
+
organizationId: string;
|
|
205
|
+
threadIds: string[];
|
|
206
|
+
clusterId: string;
|
|
207
|
+
}
|
|
208
|
+
export declare const clearThreadClusterAssignmentsByOrganizationQuery = "-- name: ClearThreadClusterAssignmentsByOrganization :execrows\nUPDATE weave.threads\nSET cluster_id = NULL\nWHERE organization_id = $1\n AND cluster_id IS NOT NULL";
|
|
209
|
+
export interface ClearThreadClusterAssignmentsByOrganizationArgs {
|
|
210
|
+
organizationId: string;
|
|
211
|
+
}
|
|
212
|
+
export declare const clearThreadClusterAssignmentsByDocumentQuery = "-- name: ClearThreadClusterAssignmentsByDocument :execrows\nUPDATE weave.threads\nSET cluster_id = NULL\nWHERE organization_id = $1\n AND document_id = $2\n AND cluster_id IS NOT NULL";
|
|
213
|
+
export interface ClearThreadClusterAssignmentsByDocumentArgs {
|
|
214
|
+
organizationId: string;
|
|
215
|
+
documentId: string;
|
|
216
|
+
}
|
|
217
|
+
export {};
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearThreadClusterAssignmentsByDocumentQuery = exports.clearThreadClusterAssignmentsByOrganizationQuery = exports.assignThreadsToClusterQuery = exports.listApprovedThreadsForConsolidationQuery = exports.listConceptClustersByParentAndScopeQuery = exports.listConceptClustersByScopeQuery = exports.getConceptClusterByOrganizationScopeAndIDQuery = 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.getConceptClusterByOrganizationScopeAndID = getConceptClusterByOrganizationScopeAndID;
|
|
10
|
+
exports.listConceptClustersByScope = listConceptClustersByScope;
|
|
11
|
+
exports.listConceptClustersByParentAndScope = listConceptClustersByParentAndScope;
|
|
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
|
+
scope_kind,
|
|
174
|
+
scope_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
|
+
scope_kind = EXCLUDED.scope_kind,
|
|
204
|
+
scope_key = EXCLUDED.scope_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
|
+
scope_kind,
|
|
217
|
+
scope_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.scopeKind, args.scopeKey, 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
|
+
scopeKind: row[2],
|
|
241
|
+
scopeKey: 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.getConceptClusterByOrganizationScopeAndIDQuery = `-- name: GetConceptClusterByOrganizationScopeAndID :one
|
|
254
|
+
SELECT
|
|
255
|
+
id,
|
|
256
|
+
organization_id,
|
|
257
|
+
scope_kind,
|
|
258
|
+
scope_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 scope_kind = $2
|
|
271
|
+
AND scope_key = $3
|
|
272
|
+
AND id = $4`;
|
|
273
|
+
async function getConceptClusterByOrganizationScopeAndID(client, args) {
|
|
274
|
+
const result = await client.query({
|
|
275
|
+
text: exports.getConceptClusterByOrganizationScopeAndIDQuery,
|
|
276
|
+
values: [args.organizationId, args.scopeKind, args.scopeKey, 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
|
+
scopeKind: row[2],
|
|
287
|
+
scopeKey: 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.listConceptClustersByScopeQuery = `-- name: ListConceptClustersByScope :many
|
|
300
|
+
SELECT
|
|
301
|
+
id,
|
|
302
|
+
organization_id,
|
|
303
|
+
scope_kind,
|
|
304
|
+
scope_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 scope_kind = $2
|
|
317
|
+
AND scope_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 listConceptClustersByScope(client, args) {
|
|
322
|
+
const result = await client.query({
|
|
323
|
+
text: exports.listConceptClustersByScopeQuery,
|
|
324
|
+
values: [args.organizationId, args.scopeKind, args.scopeKey, 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
|
+
scopeKind: row[2],
|
|
332
|
+
scopeKey: 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.listConceptClustersByParentAndScopeQuery = `-- name: ListConceptClustersByParentAndScope :many
|
|
346
|
+
SELECT
|
|
347
|
+
id,
|
|
348
|
+
organization_id,
|
|
349
|
+
scope_kind,
|
|
350
|
+
scope_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 scope_kind = $2
|
|
363
|
+
AND scope_key = $3
|
|
364
|
+
AND parent_id = $4
|
|
365
|
+
ORDER BY updated_at DESC, id ASC`;
|
|
366
|
+
async function listConceptClustersByParentAndScope(client, args) {
|
|
367
|
+
const result = await client.query({
|
|
368
|
+
text: exports.listConceptClustersByParentAndScopeQuery,
|
|
369
|
+
values: [args.organizationId, args.scopeKind, args.scopeKey, args.parentId],
|
|
370
|
+
rowMode: "array"
|
|
371
|
+
});
|
|
372
|
+
return result.rows.map(row => {
|
|
373
|
+
return {
|
|
374
|
+
id: row[0],
|
|
375
|
+
organizationId: row[1],
|
|
376
|
+
scopeKind: row[2],
|
|
377
|
+
scopeKey: 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 'SCOPE_KIND_ORG'::text
|
|
403
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
404
|
+
THEN 'SCOPE_KIND_RESTRICTED_GROUP'::text
|
|
405
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
406
|
+
THEN 'SCOPE_KIND_USER'::text
|
|
407
|
+
END AS scope_kind,
|
|
408
|
+
CASE
|
|
409
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_ORG'
|
|
410
|
+
THEN ''::text
|
|
411
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
412
|
+
THEN drg.restricted_group_id::text
|
|
413
|
+
WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
414
|
+
THEN d.uploaded_by_user_id::text
|
|
415
|
+
END AS scope_key
|
|
416
|
+
FROM weave.threads t
|
|
417
|
+
JOIN weave.documents d ON d.id = t.document_id
|
|
418
|
+
LEFT JOIN weave.document_restricted_groups drg
|
|
419
|
+
ON drg.organization_id = d.organization_id
|
|
420
|
+
AND drg.document_id = d.id
|
|
421
|
+
AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
422
|
+
WHERE t.organization_id = $1
|
|
423
|
+
AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'
|
|
424
|
+
AND t.embedding IS NOT NULL
|
|
425
|
+
AND (d.scope <> 'DOCUMENT_SCOPE_RESTRICTED' OR drg.restricted_group_id IS NOT NULL)
|
|
426
|
+
ORDER BY t.approved_at DESC, t.id ASC
|
|
427
|
+
LIMIT $3 OFFSET $2`;
|
|
428
|
+
async function listApprovedThreadsForConsolidation(client, args) {
|
|
429
|
+
const result = await client.query({
|
|
430
|
+
text: exports.listApprovedThreadsForConsolidationQuery,
|
|
431
|
+
values: [args.organizationId, args.pageOffset, args.pageSize],
|
|
432
|
+
rowMode: "array"
|
|
433
|
+
});
|
|
434
|
+
return result.rows.map(row => {
|
|
435
|
+
return {
|
|
436
|
+
id: row[0],
|
|
437
|
+
organizationId: row[1],
|
|
438
|
+
documentId: row[2],
|
|
439
|
+
ingestionRunId: row[3],
|
|
440
|
+
text: row[4],
|
|
441
|
+
knowledgeType: row[5],
|
|
442
|
+
embeddingText: row[6],
|
|
443
|
+
approvedAt: row[7],
|
|
444
|
+
scopeKind: row[8],
|
|
445
|
+
scopeKey: row[9]
|
|
446
|
+
};
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
exports.assignThreadsToClusterQuery = `-- name: AssignThreadsToCluster :execrows
|
|
450
|
+
UPDATE weave.threads AS t
|
|
451
|
+
SET cluster_id = cc.id
|
|
452
|
+
FROM weave.concept_clusters cc,
|
|
453
|
+
weave.documents d
|
|
454
|
+
WHERE t.organization_id = $1
|
|
455
|
+
AND t.id = ANY($2::uuid[])
|
|
456
|
+
AND cc.organization_id = t.organization_id
|
|
457
|
+
AND cc.id = $3
|
|
458
|
+
AND d.id = t.document_id
|
|
459
|
+
AND (
|
|
460
|
+
(cc.scope_kind = 'SCOPE_KIND_ORG'
|
|
461
|
+
AND cc.scope_key = ''
|
|
462
|
+
AND d.scope = 'DOCUMENT_SCOPE_ORG')
|
|
463
|
+
OR (cc.scope_kind = 'SCOPE_KIND_RESTRICTED_GROUP'
|
|
464
|
+
AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
465
|
+
AND EXISTS (
|
|
466
|
+
SELECT 1
|
|
467
|
+
FROM weave.document_restricted_groups drg
|
|
468
|
+
WHERE drg.organization_id = d.organization_id
|
|
469
|
+
AND drg.document_id = d.id
|
|
470
|
+
AND drg.restricted_group_id::text = cc.scope_key
|
|
471
|
+
))
|
|
472
|
+
OR (cc.scope_kind = 'SCOPE_KIND_USER'
|
|
473
|
+
AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
474
|
+
AND cc.scope_key = d.uploaded_by_user_id::text)
|
|
475
|
+
)`;
|
|
476
|
+
exports.clearThreadClusterAssignmentsByOrganizationQuery = `-- name: ClearThreadClusterAssignmentsByOrganization :execrows
|
|
477
|
+
UPDATE weave.threads
|
|
478
|
+
SET cluster_id = NULL
|
|
479
|
+
WHERE organization_id = $1
|
|
480
|
+
AND cluster_id IS NOT NULL`;
|
|
481
|
+
exports.clearThreadClusterAssignmentsByDocumentQuery = `-- name: ClearThreadClusterAssignmentsByDocument :execrows
|
|
482
|
+
UPDATE weave.threads
|
|
483
|
+
SET cluster_id = NULL
|
|
484
|
+
WHERE organization_id = $1
|
|
485
|
+
AND document_id = $2
|
|
486
|
+
AND cluster_id IS NOT NULL`;
|