weave-typescript 0.28.0 → 0.30.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.
@@ -1,7 +1,8 @@
1
- import { ExplainRetrievalRequest, ExplainRetrievalResponse, RetrieveRequest, RetrieveResponse } from "./retrieval.pb";
1
+ import { ExplainRetrievalRequest, ExplainRetrievalResponse, RetrieveRequest, RetrieveResponse, SearchDocumentsRequest, SearchDocumentsResponse } from "./retrieval.pb";
2
2
  export declare const protobufPackage = "weaveapi.retrieval.v1";
3
3
  export interface RetrievalService {
4
4
  Retrieve(request: RetrieveRequest): Promise<RetrieveResponse>;
5
+ SearchDocuments(request: SearchDocumentsRequest): Promise<SearchDocumentsResponse>;
5
6
  ExplainRetrieval(request: ExplainRetrievalRequest): Promise<ExplainRetrievalResponse>;
6
7
  }
7
8
  export declare const RetrievalServiceServiceName = "weaveapi.retrieval.v1.RetrievalService";
@@ -12,6 +13,7 @@ export declare class RetrievalServiceClientImpl implements RetrievalService {
12
13
  service?: string;
13
14
  });
14
15
  Retrieve(request: RetrieveRequest): Promise<RetrieveResponse>;
16
+ SearchDocuments(request: SearchDocumentsRequest): Promise<SearchDocumentsResponse>;
15
17
  ExplainRetrieval(request: ExplainRetrievalRequest): Promise<ExplainRetrievalResponse>;
16
18
  }
17
19
  export type RetrievalServiceDefinition = typeof RetrievalServiceDefinition;
@@ -31,6 +33,18 @@ export declare const RetrievalServiceDefinition: {
31
33
  };
32
34
  };
33
35
  };
36
+ readonly searchDocuments: {
37
+ readonly name: "SearchDocuments";
38
+ readonly requestType: typeof SearchDocumentsRequest;
39
+ readonly requestStream: false;
40
+ readonly responseType: typeof SearchDocumentsResponse;
41
+ readonly responseStream: false;
42
+ readonly options: {
43
+ readonly _unknownFields: {
44
+ readonly 578365826: readonly [Uint8Array];
45
+ };
46
+ };
47
+ };
34
48
  readonly explainRetrieval: {
35
49
  readonly name: "ExplainRetrieval";
36
50
  readonly requestType: typeof ExplainRetrievalRequest;
@@ -16,6 +16,7 @@ class RetrievalServiceClientImpl {
16
16
  this.service = (opts === null || opts === void 0 ? void 0 : opts.service) || exports.RetrievalServiceServiceName;
17
17
  this.rpc = rpc;
18
18
  this.Retrieve = this.Retrieve.bind(this);
19
+ this.SearchDocuments = this.SearchDocuments.bind(this);
19
20
  this.ExplainRetrieval = this.ExplainRetrieval.bind(this);
20
21
  }
21
22
  Retrieve(request) {
@@ -23,6 +24,11 @@ class RetrievalServiceClientImpl {
23
24
  const promise = this.rpc.request(this.service, "Retrieve", data);
24
25
  return promise.then((data) => retrieval_pb_1.RetrieveResponse.decode(new wire_1.BinaryReader(data)));
25
26
  }
27
+ SearchDocuments(request) {
28
+ const data = retrieval_pb_1.SearchDocumentsRequest.encode(request).finish();
29
+ const promise = this.rpc.request(this.service, "SearchDocuments", data);
30
+ return promise.then((data) => retrieval_pb_1.SearchDocumentsResponse.decode(new wire_1.BinaryReader(data)));
31
+ }
26
32
  ExplainRetrieval(request) {
27
33
  const data = retrieval_pb_1.ExplainRetrievalRequest.encode(request).finish();
28
34
  const promise = this.rpc.request(this.service, "ExplainRetrieval", data);
@@ -96,6 +102,79 @@ exports.RetrievalServiceDefinition = {
96
102
  },
97
103
  },
98
104
  },
105
+ searchDocuments: {
106
+ name: "SearchDocuments",
107
+ requestType: retrieval_pb_1.SearchDocumentsRequest,
108
+ requestStream: false,
109
+ responseType: retrieval_pb_1.SearchDocumentsResponse,
110
+ responseStream: false,
111
+ options: {
112
+ _unknownFields: {
113
+ 578365826: [
114
+ new Uint8Array([
115
+ 57,
116
+ 58,
117
+ 1,
118
+ 42,
119
+ 34,
120
+ 52,
121
+ 47,
122
+ 118,
123
+ 49,
124
+ 47,
125
+ 111,
126
+ 114,
127
+ 103,
128
+ 47,
129
+ 123,
130
+ 111,
131
+ 114,
132
+ 103,
133
+ 97,
134
+ 110,
135
+ 105,
136
+ 122,
137
+ 97,
138
+ 116,
139
+ 105,
140
+ 111,
141
+ 110,
142
+ 95,
143
+ 105,
144
+ 100,
145
+ 125,
146
+ 47,
147
+ 114,
148
+ 101,
149
+ 116,
150
+ 114,
151
+ 105,
152
+ 101,
153
+ 118,
154
+ 97,
155
+ 108,
156
+ 47,
157
+ 100,
158
+ 111,
159
+ 99,
160
+ 117,
161
+ 109,
162
+ 101,
163
+ 110,
164
+ 116,
165
+ 115,
166
+ 47,
167
+ 115,
168
+ 101,
169
+ 97,
170
+ 114,
171
+ 99,
172
+ 104,
173
+ ]),
174
+ ],
175
+ },
176
+ },
177
+ },
99
178
  explainRetrieval: {
100
179
  name: "ExplainRetrieval",
101
180
  requestType: retrieval_pb_1.ExplainRetrievalRequest,
@@ -424,7 +424,7 @@ export interface GetChatArtifactRow {
424
424
  updatedAt: Date;
425
425
  }
426
426
  export declare function getChatArtifact(client: Client, args: GetChatArtifactArgs): Promise<GetChatArtifactRow | null>;
427
- export declare const insertChatArtifactVersionQuery = "-- name: InsertChatArtifactVersion :one\nINSERT INTO weave.chat_artifact_versions (\n id, artifact_id, version, content, created_by_message_id\n) VALUES ($1, $2, $3, $4, $5)\nRETURNING id, artifact_id, version, content, created_by_message_id, created_at";
427
+ export declare const insertChatArtifactVersionQuery = "-- name: InsertChatArtifactVersion :one\nINSERT INTO weave.chat_artifact_versions (\n id, artifact_id, version, content, created_by_message_id\n) VALUES ($1, $2, $3, $4, $5)\nRETURNING id, artifact_id, version, content, created_by_message_id, created_at, document_references";
428
428
  export interface InsertChatArtifactVersionArgs {
429
429
  id: string;
430
430
  artifactId: string;
@@ -439,9 +439,29 @@ export interface InsertChatArtifactVersionRow {
439
439
  content: string;
440
440
  createdByMessageId: string;
441
441
  createdAt: Date;
442
+ documentReferences: any;
442
443
  }
443
444
  export declare function insertChatArtifactVersion(client: Client, args: InsertChatArtifactVersionArgs): Promise<InsertChatArtifactVersionRow | null>;
444
- export declare const getChatArtifactVersionQuery = "-- name: GetChatArtifactVersion :one\nSELECT id, artifact_id, version, content, created_by_message_id, created_at FROM weave.chat_artifact_versions\nWHERE artifact_id = $1 AND version = $2";
445
+ export declare const insertChatArtifactVersionWithDocumentReferencesQuery = "-- name: InsertChatArtifactVersionWithDocumentReferences :one\nINSERT INTO weave.chat_artifact_versions (\n id, artifact_id, version, content, created_by_message_id, document_references\n) VALUES ($1, $2, $3, $4, $5, $6)\nRETURNING id, artifact_id, version, content, created_by_message_id, created_at, document_references";
446
+ export interface InsertChatArtifactVersionWithDocumentReferencesArgs {
447
+ id: string;
448
+ artifactId: string;
449
+ version: number;
450
+ content: string;
451
+ createdByMessageId: string;
452
+ documentReferences: any;
453
+ }
454
+ export interface InsertChatArtifactVersionWithDocumentReferencesRow {
455
+ id: string;
456
+ artifactId: string;
457
+ version: number;
458
+ content: string;
459
+ createdByMessageId: string;
460
+ createdAt: Date;
461
+ documentReferences: any;
462
+ }
463
+ export declare function insertChatArtifactVersionWithDocumentReferences(client: Client, args: InsertChatArtifactVersionWithDocumentReferencesArgs): Promise<InsertChatArtifactVersionWithDocumentReferencesRow | null>;
464
+ export declare const getChatArtifactVersionQuery = "-- name: GetChatArtifactVersion :one\nSELECT id, artifact_id, version, content, created_by_message_id, created_at, document_references FROM weave.chat_artifact_versions\nWHERE artifact_id = $1 AND version = $2";
445
465
  export interface GetChatArtifactVersionArgs {
446
466
  artifactId: string;
447
467
  version: number;
@@ -453,9 +473,10 @@ export interface GetChatArtifactVersionRow {
453
473
  content: string;
454
474
  createdByMessageId: string;
455
475
  createdAt: Date;
476
+ documentReferences: any;
456
477
  }
457
478
  export declare function getChatArtifactVersion(client: Client, args: GetChatArtifactVersionArgs): Promise<GetChatArtifactVersionRow | null>;
458
- export declare const listChatArtifactVersionsQuery = "-- name: ListChatArtifactVersions :many\nSELECT id, artifact_id, version, content, created_by_message_id, created_at FROM weave.chat_artifact_versions\nWHERE artifact_id = $1\nORDER BY version";
479
+ export declare const listChatArtifactVersionsQuery = "-- name: ListChatArtifactVersions :many\nSELECT id, artifact_id, version, content, created_by_message_id, created_at, document_references FROM weave.chat_artifact_versions\nWHERE artifact_id = $1\nORDER BY version";
459
480
  export interface ListChatArtifactVersionsArgs {
460
481
  artifactId: string;
461
482
  }
@@ -466,6 +487,7 @@ export interface ListChatArtifactVersionsRow {
466
487
  content: string;
467
488
  createdByMessageId: string;
468
489
  createdAt: Date;
490
+ documentReferences: any;
469
491
  }
470
492
  export declare function listChatArtifactVersions(client: Client, args: ListChatArtifactVersionsArgs): Promise<ListChatArtifactVersionsRow[]>;
471
493
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listChatArtifactVersionsQuery = exports.getChatArtifactVersionQuery = exports.insertChatArtifactVersionQuery = exports.getChatArtifactQuery = exports.listChatArtifactsForSessionQuery = exports.bumpChatArtifactVersionQuery = exports.createChatArtifactQuery = exports.clearOrganizationChatSettingsDefaultIfMatchesQuery = exports.getOrganizationChatSettingsQuery = exports.upsertOrganizationChatSettingsQuery = exports.getOrganizationApprovedModelQuery = exports.listOrganizationApprovedModelsQuery = exports.deleteOrganizationApprovedModelQuery = exports.createOrganizationApprovedModelQuery = exports.completeChatMessageQuery = exports.updateChatMessageToolCallStateQuery = exports.listChatMessagesForSessionQuery = exports.getChatMessageQuery = exports.insertChatMessageQuery = exports.listProjectsForChatSessionQuery = exports.detachProjectFromChatSessionQuery = exports.attachProjectToChatSessionQuery = exports.softDeleteChatSessionQuery = exports.touchChatSessionLastMessageQuery = exports.updateChatSessionTitleQuery = exports.updateChatSessionModelQuery = exports.listChatSessionsForUserByProjectQuery = exports.listChatSessionsForUserQuery = exports.getChatSessionQuery = exports.createChatSessionQuery = void 0;
3
+ exports.listChatArtifactVersionsQuery = exports.getChatArtifactVersionQuery = exports.insertChatArtifactVersionWithDocumentReferencesQuery = exports.insertChatArtifactVersionQuery = exports.getChatArtifactQuery = exports.listChatArtifactsForSessionQuery = exports.bumpChatArtifactVersionQuery = exports.createChatArtifactQuery = exports.clearOrganizationChatSettingsDefaultIfMatchesQuery = exports.getOrganizationChatSettingsQuery = exports.upsertOrganizationChatSettingsQuery = exports.getOrganizationApprovedModelQuery = exports.listOrganizationApprovedModelsQuery = exports.deleteOrganizationApprovedModelQuery = exports.createOrganizationApprovedModelQuery = exports.completeChatMessageQuery = exports.updateChatMessageToolCallStateQuery = exports.listChatMessagesForSessionQuery = exports.getChatMessageQuery = exports.insertChatMessageQuery = exports.listProjectsForChatSessionQuery = exports.detachProjectFromChatSessionQuery = exports.attachProjectToChatSessionQuery = exports.softDeleteChatSessionQuery = exports.touchChatSessionLastMessageQuery = exports.updateChatSessionTitleQuery = exports.updateChatSessionModelQuery = exports.listChatSessionsForUserByProjectQuery = exports.listChatSessionsForUserQuery = exports.getChatSessionQuery = exports.createChatSessionQuery = void 0;
4
4
  exports.createChatSession = createChatSession;
5
5
  exports.getChatSession = getChatSession;
6
6
  exports.listChatSessionsForUser = listChatSessionsForUser;
@@ -29,6 +29,7 @@ exports.bumpChatArtifactVersion = bumpChatArtifactVersion;
29
29
  exports.listChatArtifactsForSession = listChatArtifactsForSession;
30
30
  exports.getChatArtifact = getChatArtifact;
31
31
  exports.insertChatArtifactVersion = insertChatArtifactVersion;
32
+ exports.insertChatArtifactVersionWithDocumentReferences = insertChatArtifactVersionWithDocumentReferences;
32
33
  exports.getChatArtifactVersion = getChatArtifactVersion;
33
34
  exports.listChatArtifactVersions = listChatArtifactVersions;
34
35
  exports.createChatSessionQuery = `-- name: CreateChatSession :one
@@ -677,7 +678,7 @@ exports.insertChatArtifactVersionQuery = `-- name: InsertChatArtifactVersion :on
677
678
  INSERT INTO weave.chat_artifact_versions (
678
679
  id, artifact_id, version, content, created_by_message_id
679
680
  ) VALUES ($1, $2, $3, $4, $5)
680
- RETURNING id, artifact_id, version, content, created_by_message_id, created_at`;
681
+ RETURNING id, artifact_id, version, content, created_by_message_id, created_at, document_references`;
681
682
  async function insertChatArtifactVersion(client, args) {
682
683
  const result = await client.query({
683
684
  text: exports.insertChatArtifactVersionQuery,
@@ -694,11 +695,37 @@ async function insertChatArtifactVersion(client, args) {
694
695
  version: row[2],
695
696
  content: row[3],
696
697
  createdByMessageId: row[4],
697
- createdAt: row[5]
698
+ createdAt: row[5],
699
+ documentReferences: row[6]
700
+ };
701
+ }
702
+ exports.insertChatArtifactVersionWithDocumentReferencesQuery = `-- name: InsertChatArtifactVersionWithDocumentReferences :one
703
+ INSERT INTO weave.chat_artifact_versions (
704
+ id, artifact_id, version, content, created_by_message_id, document_references
705
+ ) VALUES ($1, $2, $3, $4, $5, $6)
706
+ RETURNING id, artifact_id, version, content, created_by_message_id, created_at, document_references`;
707
+ async function insertChatArtifactVersionWithDocumentReferences(client, args) {
708
+ const result = await client.query({
709
+ text: exports.insertChatArtifactVersionWithDocumentReferencesQuery,
710
+ values: [args.id, args.artifactId, args.version, args.content, args.createdByMessageId, args.documentReferences],
711
+ rowMode: "array"
712
+ });
713
+ if (result.rows.length !== 1) {
714
+ return null;
715
+ }
716
+ const row = result.rows[0];
717
+ return {
718
+ id: row[0],
719
+ artifactId: row[1],
720
+ version: row[2],
721
+ content: row[3],
722
+ createdByMessageId: row[4],
723
+ createdAt: row[5],
724
+ documentReferences: row[6]
698
725
  };
699
726
  }
700
727
  exports.getChatArtifactVersionQuery = `-- name: GetChatArtifactVersion :one
701
- SELECT id, artifact_id, version, content, created_by_message_id, created_at FROM weave.chat_artifact_versions
728
+ SELECT id, artifact_id, version, content, created_by_message_id, created_at, document_references FROM weave.chat_artifact_versions
702
729
  WHERE artifact_id = $1 AND version = $2`;
703
730
  async function getChatArtifactVersion(client, args) {
704
731
  const result = await client.query({
@@ -716,11 +743,12 @@ async function getChatArtifactVersion(client, args) {
716
743
  version: row[2],
717
744
  content: row[3],
718
745
  createdByMessageId: row[4],
719
- createdAt: row[5]
746
+ createdAt: row[5],
747
+ documentReferences: row[6]
720
748
  };
721
749
  }
722
750
  exports.listChatArtifactVersionsQuery = `-- name: ListChatArtifactVersions :many
723
- SELECT id, artifact_id, version, content, created_by_message_id, created_at FROM weave.chat_artifact_versions
751
+ SELECT id, artifact_id, version, content, created_by_message_id, created_at, document_references FROM weave.chat_artifact_versions
724
752
  WHERE artifact_id = $1
725
753
  ORDER BY version`;
726
754
  async function listChatArtifactVersions(client, args) {
@@ -736,7 +764,8 @@ async function listChatArtifactVersions(client, args) {
736
764
  version: row[2],
737
765
  content: row[3],
738
766
  createdByMessageId: row[4],
739
- createdAt: row[5]
767
+ createdAt: row[5],
768
+ documentReferences: row[6]
740
769
  };
741
770
  });
742
771
  }
@@ -161,6 +161,76 @@ export interface ListDocumentsByOrganizationRow {
161
161
  metadata: any;
162
162
  }
163
163
  export declare function listDocumentsByOrganization(client: Client, args: ListDocumentsByOrganizationArgs): Promise<ListDocumentsByOrganizationRow[]>;
164
+ export declare const listAccessibleDocumentSummariesQuery = "-- name: ListAccessibleDocumentSummaries :many\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n d.sensitivity_tags,\n COALESCE(tag_data.tags, '{}'::text[]) AS tags,\n COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,\n d.uploaded_by_user_id,\n d.uploaded_at,\n d.updated_at,\n d.page_count,\n d.char_count,\n d.metadata,\n COALESCE(latest_runs.latest_ingestion_run_id, '00000000-0000-0000-0000-000000000000'::uuid) AS latest_ingestion_run_id,\n COALESCE(latest_runs.latest_ingestion_status, 'INGESTION_RUN_STATUS_UNSPECIFIED') AS latest_ingestion_status,\n COALESCE(thread_counts.thread_count, 0)::int AS thread_count,\n COALESCE(thread_counts.pending_count, 0)::int AS pending_count,\n COALESCE(thread_counts.approved_count, 0)::int AS approved_count,\n COALESCE(thread_counts.rejected_count, 0)::int AS rejected_count\nFROM weave.documents d\nLEFT JOIN latest_runs ON latest_runs.document_id = d.id\nLEFT JOIN thread_counts ON thread_counts.document_id = d.id\nLEFT JOIN tag_data ON tag_data.document_id = d.id\nWHERE d.organization_id = $1\n AND (\n d.scope = 'DOCUMENT_SCOPE_ORG'\n OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND d.uploaded_by_user_id = $2)\n OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND EXISTS (\n SELECT 1\n FROM weave.user_sensitivity_clearances c\n WHERE c.organization_id = $1\n AND c.user_id = $2\n AND cardinality(d.sensitivity_tags) = 1\n AND c.sensitivity_tag_slug = d.sensitivity_tags[1]\n ))\n )\n AND (cardinality($3::text[]) = 0 OR d.status = ANY($3::text[]))\n AND (cardinality($4::text[]) = 0 OR latest_runs.latest_ingestion_status = ANY($4::text[]))\n AND (cardinality($5::text[]) = 0 OR d.scope = ANY($5::text[]))\n AND (cardinality($6::text[]) = 0 OR tag_data.tags && $6::text[] OR d.sensitivity_tags && $6::text[])\n AND (cardinality($7::text[]) = 0 OR d.sensitivity_tags && $7::text[])\n AND ($8::timestamptz IS NULL OR d.uploaded_at >= $8::timestamptz)\n AND ($9::timestamptz IS NULL OR d.uploaded_at <= $9::timestamptz)\nORDER BY d.uploaded_at DESC, d.id DESC\nLIMIT $11 OFFSET $10";
165
+ export interface ListAccessibleDocumentSummariesArgs {
166
+ organizationId: string;
167
+ actingUserId: string;
168
+ documentStatuses: string[];
169
+ ingestionStatuses: string[];
170
+ scopes: string[];
171
+ tags: string[];
172
+ restrictedTags: string[];
173
+ uploadedAfter: Date | null;
174
+ uploadedBefore: Date | null;
175
+ pageOffset: string;
176
+ pageSize: string;
177
+ }
178
+ export interface ListAccessibleDocumentSummariesRow {
179
+ id: string;
180
+ organizationId: string;
181
+ filename: string;
182
+ mimeType: string;
183
+ parserName: string;
184
+ status: string;
185
+ scope: string;
186
+ sensitivityTags: string[];
187
+ tags: string;
188
+ tagConfidences: string;
189
+ uploadedByUserId: string;
190
+ uploadedAt: Date;
191
+ updatedAt: Date;
192
+ pageCount: number | null;
193
+ charCount: number | null;
194
+ metadata: any;
195
+ latestIngestionRunId: string;
196
+ latestIngestionStatus: string;
197
+ threadCount: number;
198
+ pendingCount: number;
199
+ approvedCount: number;
200
+ rejectedCount: number;
201
+ }
202
+ export declare function listAccessibleDocumentSummaries(client: Client, args: ListAccessibleDocumentSummariesArgs): Promise<ListAccessibleDocumentSummariesRow[]>;
203
+ export declare const getAccessibleDocumentSummaryQuery = "-- name: GetAccessibleDocumentSummary :one\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n AND r.document_id = $2\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n AND t.document_id = $2\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n AND dt.document_id = $2\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n d.sensitivity_tags,\n COALESCE(tag_data.tags, '{}'::text[]) AS tags,\n COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,\n d.uploaded_by_user_id,\n d.uploaded_at,\n d.updated_at,\n d.page_count,\n d.char_count,\n d.metadata,\n COALESCE(latest_runs.latest_ingestion_run_id, '00000000-0000-0000-0000-000000000000'::uuid) AS latest_ingestion_run_id,\n COALESCE(latest_runs.latest_ingestion_status, 'INGESTION_RUN_STATUS_UNSPECIFIED') AS latest_ingestion_status,\n COALESCE(thread_counts.thread_count, 0)::int AS thread_count,\n COALESCE(thread_counts.pending_count, 0)::int AS pending_count,\n COALESCE(thread_counts.approved_count, 0)::int AS approved_count,\n COALESCE(thread_counts.rejected_count, 0)::int AS rejected_count\nFROM weave.documents d\nLEFT JOIN latest_runs ON latest_runs.document_id = d.id\nLEFT JOIN thread_counts ON thread_counts.document_id = d.id\nLEFT JOIN tag_data ON tag_data.document_id = d.id\nWHERE d.organization_id = $1\n AND d.id = $2\n AND (\n d.scope = 'DOCUMENT_SCOPE_ORG'\n OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND d.uploaded_by_user_id = $3)\n OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND EXISTS (\n SELECT 1\n FROM weave.user_sensitivity_clearances c\n WHERE c.organization_id = $1\n AND c.user_id = $3\n AND cardinality(d.sensitivity_tags) = 1\n AND c.sensitivity_tag_slug = d.sensitivity_tags[1]\n ))\n )";
204
+ export interface GetAccessibleDocumentSummaryArgs {
205
+ organizationId: string;
206
+ documentId: string;
207
+ actingUserId: string;
208
+ }
209
+ export interface GetAccessibleDocumentSummaryRow {
210
+ id: string;
211
+ organizationId: string;
212
+ filename: string;
213
+ mimeType: string;
214
+ parserName: string;
215
+ status: string;
216
+ scope: string;
217
+ sensitivityTags: string[];
218
+ tags: string;
219
+ tagConfidences: string;
220
+ uploadedByUserId: string;
221
+ uploadedAt: Date;
222
+ updatedAt: Date;
223
+ pageCount: number | null;
224
+ charCount: number | null;
225
+ metadata: any;
226
+ latestIngestionRunId: string;
227
+ latestIngestionStatus: string;
228
+ threadCount: number;
229
+ pendingCount: number;
230
+ approvedCount: number;
231
+ rejectedCount: number;
232
+ }
233
+ export declare function getAccessibleDocumentSummary(client: Client, args: GetAccessibleDocumentSummaryArgs): Promise<GetAccessibleDocumentSummaryRow | null>;
164
234
  export declare const getDatabaseConfigQuery = "-- name: GetDatabaseConfig :one\nSELECT\n id,\n embedding_dimension,\n deployment_mode,\n created_at,\n updated_at\nFROM weave.database_config\nWHERE id = 1";
165
235
  export interface GetDatabaseConfigRow {
166
236
  id: number;
@@ -345,6 +415,12 @@ export interface DeleteDocumentTagsByDocumentIDArgs {
345
415
  documentId: string;
346
416
  }
347
417
  export declare function deleteDocumentTagsByDocumentID(client: Client, args: DeleteDocumentTagsByDocumentIDArgs): Promise<void>;
418
+ export declare const deleteDocumentTagByDocumentIDAndTagQuery = "-- name: DeleteDocumentTagByDocumentIDAndTag :execrows\nDELETE FROM weave.document_tags dt\nUSING weave.documents d\nWHERE dt.document_id = d.id\n AND d.organization_id = $1\n AND dt.document_id = $2\n AND dt.tag = $3";
419
+ export interface DeleteDocumentTagByDocumentIDAndTagArgs {
420
+ organizationId: string;
421
+ documentId: string;
422
+ tag: string;
423
+ }
348
424
  export declare const createDocumentTagQuery = "-- name: CreateDocumentTag :one\nINSERT INTO weave.document_tags (\n document_id,\n tag,\n confidence\n) VALUES (\n $1,\n $2,\n $3\n)\nRETURNING document_id, tag, confidence";
349
425
  export interface CreateDocumentTagArgs {
350
426
  documentId: string;
@@ -368,6 +444,11 @@ export interface ListDocumentTagsByDocumentIDRow {
368
444
  confidence: number;
369
445
  }
370
446
  export declare function listDocumentTagsByDocumentID(client: Client, args: ListDocumentTagsByDocumentIDArgs): Promise<ListDocumentTagsByDocumentIDRow[]>;
447
+ export declare const deleteDocumentByOrganizationAndIDQuery = "-- name: DeleteDocumentByOrganizationAndID :execrows\nDELETE FROM weave.documents\nWHERE organization_id = $1\n AND id = $2";
448
+ export interface DeleteDocumentByOrganizationAndIDArgs {
449
+ organizationId: string;
450
+ documentId: string;
451
+ }
371
452
  export declare const createThreadQuery = "-- name: CreateThread :one\nINSERT INTO weave.threads (\n id,\n organization_id,\n document_id,\n ingestion_run_id,\n text,\n knowledge_type,\n facet_fields,\n confidence,\n temporal_validity,\n classification,\n retrieval_status,\n source_location,\n metadata\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13\n)\nRETURNING\n id,\n organization_id,\n document_id,\n ingestion_run_id,\n text,\n text_original,\n knowledge_type,\n facet_fields,\n confidence,\n temporal_validity,\n classification,\n retrieval_status,\n source_location,\n superseded_by,\n supersedes,\n cluster_id,\n extracted_at,\n approved_at,\n approved_by_user_id,\n edited,\n metadata";
372
453
  export interface CreateThreadArgs {
373
454
  id: string;
@@ -468,6 +549,36 @@ export interface ListThreadsByIngestionRunRow {
468
549
  metadata: any;
469
550
  }
470
551
  export declare function listThreadsByIngestionRun(client: Client, args: ListThreadsByIngestionRunArgs): Promise<ListThreadsByIngestionRunRow[]>;
552
+ export declare const listThreadsByDocumentQuery = "-- name: ListThreadsByDocument :many\nSELECT\n t.id,\n t.organization_id,\n t.document_id,\n d.filename AS document_name,\n t.ingestion_run_id,\n t.text,\n t.text_original,\n t.knowledge_type,\n t.facet_fields,\n t.confidence,\n t.temporal_validity,\n t.classification,\n t.retrieval_status,\n t.source_location,\n t.superseded_by,\n t.supersedes,\n t.cluster_id,\n t.extracted_at,\n t.approved_at,\n t.approved_by_user_id,\n t.edited,\n t.metadata\nFROM weave.threads t\nJOIN weave.documents d ON d.id = t.document_id\nWHERE t.organization_id = $1\n AND t.document_id = $2\nORDER BY t.extracted_at ASC, t.id ASC";
553
+ export interface ListThreadsByDocumentArgs {
554
+ organizationId: string;
555
+ documentId: string;
556
+ }
557
+ export interface ListThreadsByDocumentRow {
558
+ id: string;
559
+ organizationId: string;
560
+ documentId: string;
561
+ documentName: string;
562
+ ingestionRunId: string;
563
+ text: string;
564
+ textOriginal: string | null;
565
+ knowledgeType: string;
566
+ facetFields: any;
567
+ confidence: number;
568
+ temporalValidity: any | null;
569
+ classification: string;
570
+ retrievalStatus: string;
571
+ sourceLocation: any;
572
+ supersededBy: string | null;
573
+ supersedes: string[];
574
+ clusterId: string | null;
575
+ extractedAt: Date;
576
+ approvedAt: Date | null;
577
+ approvedByUserId: string | null;
578
+ edited: boolean;
579
+ metadata: any;
580
+ }
581
+ export declare function listThreadsByDocument(client: Client, args: ListThreadsByDocumentArgs): Promise<ListThreadsByDocumentRow[]>;
471
582
  export declare const listPendingThreadsByRunQuery = "-- name: ListPendingThreadsByRun :many\nSELECT\n id,\n organization_id,\n document_id,\n ingestion_run_id,\n text,\n text_original,\n knowledge_type,\n facet_fields,\n confidence,\n temporal_validity,\n classification,\n retrieval_status,\n source_location,\n superseded_by,\n supersedes,\n cluster_id,\n extracted_at,\n approved_at,\n approved_by_user_id,\n edited,\n metadata\nFROM weave.threads\nWHERE organization_id = $1\n AND ingestion_run_id = $2\n AND retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\nORDER BY extracted_at ASC, id ASC";
472
583
  export interface ListPendingThreadsByRunArgs {
473
584
  organizationId: string;
@@ -653,6 +764,46 @@ export interface EditPendingThreadRow {
653
764
  metadata: any;
654
765
  }
655
766
  export declare function editPendingThread(client: Client, args: EditPendingThreadArgs): Promise<EditPendingThreadRow | null>;
767
+ export declare const editDocumentThreadQuery = "-- name: EditDocumentThread :one\nWITH updated AS (\n UPDATE weave.threads AS t\n SET\n text_original = CASE\n WHEN t.text_original IS NULL OR t.text_original = '' THEN t.text\n ELSE t.text_original\n END,\n text = $1,\n source_location = COALESCE($2::jsonb, t.source_location),\n metadata = t.metadata || COALESCE($3::jsonb, '{}'::jsonb),\n edited = TRUE\n WHERE t.id = $4\n AND t.organization_id = $5\n AND t.document_id = $6\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n RETURNING\n id,\n organization_id,\n document_id,\n ingestion_run_id,\n text,\n text_original,\n knowledge_type,\n facet_fields,\n confidence,\n temporal_validity,\n classification,\n retrieval_status,\n source_location,\n superseded_by,\n supersedes,\n cluster_id,\n extracted_at,\n approved_at,\n approved_by_user_id,\n edited,\n metadata\n)\nSELECT\n updated.id,\n updated.organization_id,\n updated.document_id,\n d.filename AS document_name,\n updated.ingestion_run_id,\n updated.text,\n updated.text_original,\n updated.knowledge_type,\n updated.facet_fields,\n updated.confidence,\n updated.temporal_validity,\n updated.classification,\n updated.retrieval_status,\n updated.source_location,\n updated.superseded_by,\n updated.supersedes,\n updated.cluster_id,\n updated.extracted_at,\n updated.approved_at,\n updated.approved_by_user_id,\n updated.edited,\n updated.metadata\nFROM updated\nJOIN weave.documents d ON d.id = updated.document_id";
768
+ export interface EditDocumentThreadArgs {
769
+ text: string;
770
+ sourceLocation: any | null;
771
+ metadata: any | null;
772
+ id: string;
773
+ organizationId: string;
774
+ documentId: string;
775
+ }
776
+ export interface EditDocumentThreadRow {
777
+ id: string;
778
+ organizationId: string;
779
+ documentId: string;
780
+ documentName: string;
781
+ ingestionRunId: string;
782
+ text: string;
783
+ textOriginal: string | null;
784
+ knowledgeType: string;
785
+ facetFields: any;
786
+ confidence: number;
787
+ temporalValidity: any | null;
788
+ classification: string;
789
+ retrievalStatus: string;
790
+ sourceLocation: any;
791
+ supersededBy: string | null;
792
+ supersedes: string[];
793
+ clusterId: string | null;
794
+ extractedAt: Date;
795
+ approvedAt: Date | null;
796
+ approvedByUserId: string | null;
797
+ edited: boolean;
798
+ metadata: any;
799
+ }
800
+ export declare function editDocumentThread(client: Client, args: EditDocumentThreadArgs): Promise<EditDocumentThreadRow | null>;
801
+ export declare const deleteDocumentThreadByOrganizationAndIDQuery = "-- name: DeleteDocumentThreadByOrganizationAndID :execrows\nDELETE FROM weave.threads\nWHERE organization_id = $1\n AND document_id = $2\n AND id = $3\n AND retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'";
802
+ export interface DeleteDocumentThreadByOrganizationAndIDArgs {
803
+ organizationId: string;
804
+ documentId: string;
805
+ id: string;
806
+ }
656
807
  export declare const approveThreadQuery = "-- name: ApproveThread :one\nUPDATE weave.threads\nSET\n retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED',\n approved_at = now(),\n approved_by_user_id = $1,\n embedding = COALESCE($2::vector, embedding),\n embedding_next = NULL\nWHERE id = $3\n AND organization_id = $4\n AND retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\nRETURNING\n id,\n organization_id,\n document_id,\n ingestion_run_id,\n text,\n text_original,\n knowledge_type,\n facet_fields,\n confidence,\n temporal_validity,\n classification,\n retrieval_status,\n source_location,\n superseded_by,\n supersedes,\n cluster_id,\n extracted_at,\n approved_at,\n approved_by_user_id,\n edited,\n metadata";
657
808
  export interface ApproveThreadArgs {
658
809
  approvedByUserId: string | null;