@overmap-ai/core 1.0.63-selector-standardization.9 → 1.0.63

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.
@@ -4514,8 +4514,9 @@ var __publicField = (obj, key, value) => {
4514
4514
  return objectsWithSha1.filter((object) => object.file_sha1 === sha1).length;
4515
4515
  }
4516
4516
  processPresignedUrls(presignedUrls) {
4517
+ const promisesBySha1 = {};
4517
4518
  for (const [sha1, presignedUrl] of Object.entries(presignedUrls)) {
4518
- void this.enqueueRequest({
4519
+ promisesBySha1[sha1] = this.enqueueRequest({
4519
4520
  url: presignedUrl.url,
4520
4521
  description: "Upload file to S3",
4521
4522
  method: HttpMethod.POST,
@@ -4528,6 +4529,7 @@ var __publicField = (obj, key, value) => {
4528
4529
  s3url: presignedUrl
4529
4530
  });
4530
4531
  }
4532
+ return promisesBySha1;
4531
4533
  }
4532
4534
  }
4533
4535
  const AttachmentModelMeta = {
@@ -6913,12 +6915,89 @@ var __publicField = (obj, key, value) => {
6913
6915
  document: data.modelId
6914
6916
  });
6915
6917
  }
6918
+ // NOTE: overriding the method from BaseAttachmentService since document attachments get vectorized
6916
6919
  async attachFilesToDocument(files, documentId) {
6917
- return this.attachFiles(files, documentId, this.buildOfflineAttachment.bind(this));
6920
+ const { store } = this.client;
6921
+ const currentUser = store.getState().userReducer.currentUser;
6922
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
6923
+ const offlineAttachments = [];
6924
+ const attachmentPayloads = [];
6925
+ const filePayloads = {};
6926
+ const sha1ToAttachmentIds = {};
6927
+ for (const file of files) {
6928
+ const sha1 = await hashFile(file);
6929
+ if (!(sha1 in filePayloads)) {
6930
+ filePayloads[sha1] = {
6931
+ sha1,
6932
+ file_type: file.type,
6933
+ extension: file.name.split(".").pop(),
6934
+ size: file.size
6935
+ };
6936
+ sha1ToAttachmentIds[sha1] = [];
6937
+ await this.client.files.addCache(file, sha1);
6938
+ }
6939
+ const offlineAttachment = this.buildOfflineAttachment({
6940
+ file,
6941
+ sha1,
6942
+ submittedAt,
6943
+ createdBy: currentUser.id,
6944
+ description: "",
6945
+ modelId: documentId
6946
+ });
6947
+ offlineAttachments.push(offlineAttachment);
6948
+ attachmentPayloads.push({
6949
+ offline_id: offlineAttachment.offline_id,
6950
+ name: offlineAttachment.file_name,
6951
+ sha1: offlineAttachment.file_sha1,
6952
+ description: offlineAttachment.description
6953
+ });
6954
+ sha1ToAttachmentIds[sha1].push(offlineAttachment.offline_id);
6955
+ }
6956
+ this.dispatch(this.addAttachments(offlineAttachments));
6957
+ const promise = this.enqueueRequest({
6958
+ description: "Attach files to document",
6959
+ method: HttpMethod.POST,
6960
+ url: `/documents/${documentId}/attach/`,
6961
+ payload: {
6962
+ submitted_at: submittedAt,
6963
+ attachments: attachmentPayloads,
6964
+ files: Object.values(filePayloads)
6965
+ },
6966
+ blocks: offlineAttachments.map((attachment) => attachment.offline_id),
6967
+ blockers: offlineAttachments.map((attachment) => attachment.file_sha1)
6968
+ });
6969
+ promise.then(({ attachments, presigned_urls }) => {
6970
+ this.dispatch(this.updateAttachments(attachments));
6971
+ const promisesBySha1 = this.processPresignedUrls(presigned_urls);
6972
+ for (const [sha1, promise2] of Object.entries(promisesBySha1)) {
6973
+ void promise2.then(() => {
6974
+ const attachmentIds = sha1ToAttachmentIds[sha1];
6975
+ for (const attachmentId of attachmentIds) {
6976
+ this.makeReadable(attachmentId);
6977
+ }
6978
+ });
6979
+ }
6980
+ }).catch(() => {
6981
+ this.dispatch(this.removeAttachments(offlineAttachments.map((attachment) => attachment.offline_id)));
6982
+ });
6983
+ return [offlineAttachments, promise.then(({ attachments }) => attachments)];
6918
6984
  }
6919
6985
  async deleteDocumentAttachment(attachmentId) {
6920
6986
  return this.deleteAttachment(attachmentId);
6921
6987
  }
6988
+ makeReadable(attachmnentId) {
6989
+ void this.enqueueRequest({
6990
+ description: "Add attachment to AI assistant",
6991
+ method: HttpMethod.PATCH,
6992
+ url: `/document-attachments/${attachmnentId}/`,
6993
+ payload: {
6994
+ readable_to_assistant: true
6995
+ },
6996
+ // passing through "index-document-attachment" so at most one document attachment being indexed at a time
6997
+ blockers: ["index-document-attachment", attachmnentId],
6998
+ blocks: ["index-document-attachment"]
6999
+ });
7000
+ }
6922
7001
  async refreshStore(projectId, organizationId) {
6923
7002
  const projectDocumentAttachments = await this.enqueueRequest({
6924
7003
  description: "Get document attachments",