@overmap-ai/core 1.0.48-activity-history.1 → 1.0.48-activity-history.3

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.
@@ -2135,20 +2135,55 @@ var __publicField = (obj, key, value) => {
2135
2135
  setVisibleUserIds: (state, action) => {
2136
2136
  state.visibleUserIds = [...new Set(action.payload)];
2137
2137
  },
2138
- setIssueComments: (state, action) => {
2138
+ // Comments
2139
+ addIssueComment: (state, action) => {
2140
+ if (action.payload.offline_id in state.comments) {
2141
+ throw new Error(
2142
+ `Tried to add issue comment with offline_id: ${action.payload.offline_id} that already exists`
2143
+ );
2144
+ }
2145
+ state.comments[action.payload.offline_id] = action.payload;
2146
+ },
2147
+ addIssueComments: (state, action) => {
2148
+ for (const comment of action.payload) {
2149
+ if (comment.offline_id in state.comments) {
2150
+ throw new Error(
2151
+ `Tried to add issue comment with offline_id: ${comment.offline_id} that already exists`
2152
+ );
2153
+ }
2154
+ }
2139
2155
  for (const comment of action.payload) {
2140
2156
  state.comments[comment.offline_id] = comment;
2141
2157
  }
2142
2158
  },
2159
+ setIssueComment: (state, action) => {
2160
+ state.comments[action.payload.offline_id] = action.payload;
2161
+ },
2162
+ setIssueComments: (state, action) => {
2163
+ const newComments = {};
2164
+ for (const comment of action.payload) {
2165
+ newComments[comment.offline_id] = comment;
2166
+ }
2167
+ state.comments = newComments;
2168
+ },
2143
2169
  addOrReplaceIssueComment: (state, action) => {
2144
2170
  state.comments[action.payload.offline_id] = action.payload;
2145
2171
  },
2146
2172
  removeIssueComment: (state, action) => {
2147
- if (action.payload in state.comments) {
2148
- delete state.comments[action.payload];
2149
- } else {
2173
+ if (!(action.payload in state.comments)) {
2150
2174
  throw new Error(`Failed to remove issue comment because ID doesn't exist: ${action.payload}`);
2151
2175
  }
2176
+ delete state.comments[action.payload];
2177
+ },
2178
+ removeIssueComments: (state, action) => {
2179
+ for (const commentId of action.payload) {
2180
+ if (!(commentId in state.comments)) {
2181
+ throw new Error(`Failed to remove issue comment because ID doesn't exist: ${commentId}`);
2182
+ }
2183
+ }
2184
+ for (const commentId of action.payload) {
2185
+ delete state.comments[commentId];
2186
+ }
2152
2187
  },
2153
2188
  cleanRecentIssues: (state) => {
2154
2189
  state.recentIssueIds = state.recentIssueIds.filter((recentIssue) => state.issues[recentIssue.offlineId]);
@@ -2187,20 +2222,25 @@ var __publicField = (obj, key, value) => {
2187
2222
  removeIssueAttachment,
2188
2223
  removeAttachmentsOfIssue,
2189
2224
  removeIssue,
2190
- removeIssueComment,
2191
2225
  removeIssueUpdate,
2192
2226
  removeIssueUpdates,
2193
2227
  removeRecentIssue,
2194
2228
  resetRecentIssues,
2195
2229
  setActiveIssueId,
2196
2230
  setIssueAttachments,
2197
- setIssueComments,
2198
2231
  setIssueUpdates,
2199
2232
  setIssues,
2200
2233
  setVisibleStatuses,
2201
2234
  setVisibleUserIds,
2202
2235
  updateIssueAttachment,
2203
- updateIssue
2236
+ updateIssue,
2237
+ // Commments
2238
+ addIssueComment,
2239
+ addIssueComments,
2240
+ setIssueComment,
2241
+ setIssueComments,
2242
+ removeIssueComment,
2243
+ removeIssueComments
2204
2244
  } = issueSlice.actions;
2205
2245
  const selectIssueMapping = (state) => state.issueReducer.issues;
2206
2246
  const selectRecentIssueIds = (state) => state.issueReducer.recentIssueIds;
@@ -4216,7 +4256,7 @@ var __publicField = (obj, key, value) => {
4216
4256
  const errorResponse = extractResponseFromError(error2);
4217
4257
  const status = errorResponse == null ? void 0 : errorResponse.status;
4218
4258
  if (status === 401) {
4219
- if (url.endsWith("auth/token/refresh/")) {
4259
+ if (url.endsWith("/token/refresh/")) {
4220
4260
  if (state.authReducer.isLoggedIn) {
4221
4261
  console.warn("No signed-in user to sign out.");
4222
4262
  }
@@ -5056,6 +5096,10 @@ var __publicField = (obj, key, value) => {
5056
5096
  checkAuth: false,
5057
5097
  // Don't wait for other requests to finish, or we might end up in a deadlock.
5058
5098
  immediate: true
5099
+ }).catch((e) => {
5100
+ console.error("Could not renew tokens; logging out due to error:", e);
5101
+ void this.logout();
5102
+ return void 0;
5059
5103
  });
5060
5104
  let response = void 0;
5061
5105
  try {
@@ -5064,7 +5108,7 @@ var __publicField = (obj, key, value) => {
5064
5108
  await this.logout();
5065
5109
  }
5066
5110
  if (!response)
5067
- throw new Error("No response");
5111
+ return void 0;
5068
5112
  if (!response.access)
5069
5113
  throw new Error("Missing access token");
5070
5114
  if (!response.refresh)
@@ -5136,7 +5180,11 @@ var __publicField = (obj, key, value) => {
5136
5180
  throw new Error("No refresh token found");
5137
5181
  }
5138
5182
  try {
5139
- const { accessToken, refreshToken } = await this._getRenewedTokens(dyingRefreshToken);
5183
+ const tokens = await this._getRenewedTokens(dyingRefreshToken);
5184
+ if (!tokens) {
5185
+ return void 0;
5186
+ }
5187
+ const { accessToken, refreshToken } = tokens;
5140
5188
  console.log("Got renewed tokens");
5141
5189
  store.dispatch(setTokens({ accessToken, refreshToken }));
5142
5190
  } catch (e) {
@@ -5749,49 +5797,36 @@ var __publicField = (obj, key, value) => {
5749
5797
  }
5750
5798
  }
5751
5799
  class IssueCommentService extends BaseApiService {
5800
+ // Omit author and submitted_at since these will always be set internally
5752
5801
  add(comment) {
5753
- const offlinePayload = offline(comment);
5754
- const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5755
5802
  const { store } = this.client;
5756
- const offlineComment = {
5757
- ...offlinePayload,
5803
+ const offlineComment = offline({
5804
+ ...comment,
5758
5805
  author: store.getState().userReducer.currentUser.id,
5759
- created_at: submittedAt
5760
- };
5761
- store.dispatch(addOrReplaceIssueComment(offlineComment));
5806
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5807
+ resolved: false
5808
+ });
5809
+ store.dispatch(addIssueComment(offlineComment));
5762
5810
  const promise = this.enqueueRequest({
5763
5811
  description: `${truncate(comment.content, 80)}`,
5764
5812
  method: HttpMethod.POST,
5765
5813
  url: `/issues/${comment.issue}/comment/`,
5766
- payload: { ...offlinePayload, submitted_at: submittedAt },
5814
+ payload: offlineComment,
5767
5815
  blockers: [comment.issue],
5768
- blocks: [offlinePayload.offline_id]
5816
+ blocks: [offlineComment.offline_id]
5817
+ });
5818
+ promise.catch(() => {
5819
+ store.dispatch(removeIssueComment(offlineComment.offline_id));
5769
5820
  });
5770
5821
  return [offlineComment, promise];
5771
5822
  }
5772
- async refreshStore() {
5823
+ update(comment) {
5773
5824
  const { store } = this.client;
5774
- const result = await this.enqueueRequest({
5775
- description: "Get comments",
5776
- method: HttpMethod.GET,
5777
- // TODO: Choose between /issues/comments/in-project/${projectId}/ and /projects/${projectId}/issue-comments/
5778
- url: `/projects/${store.getState().projectReducer.activeProjectId}/comments/`,
5779
- blockers: [],
5780
- blocks: []
5781
- });
5782
- let filteredResult = result.filter(onlyUniqueOfflineIds);
5783
- filteredResult = filteredResult.map((comment) => {
5784
- return { ...comment };
5785
- });
5786
- if (result.length !== filteredResult.length) {
5787
- console.error(
5788
- `Received duplicate comments from the API (new length ${filteredResult.length}); filtered in browser.`
5789
- );
5825
+ const commentToUpdate = store.getState().issueReducer.comments[comment.offline_id];
5826
+ if (!commentToUpdate) {
5827
+ throw new Error(`Comment with offline_id ${comment.offline_id} not found in store`);
5790
5828
  }
5791
- store.dispatch(setIssueComments(filteredResult));
5792
- }
5793
- update(comment) {
5794
- this.client.store.dispatch(addOrReplaceIssueComment(comment));
5829
+ store.dispatch(setIssueComment(comment));
5795
5830
  const promise = this.enqueueRequest({
5796
5831
  description: `Edit comment: ${truncate(comment.content, 80)}`,
5797
5832
  method: HttpMethod.PATCH,
@@ -5800,17 +5835,40 @@ var __publicField = (obj, key, value) => {
5800
5835
  blockers: [comment.issue],
5801
5836
  blocks: [comment.offline_id]
5802
5837
  });
5838
+ promise.catch(() => {
5839
+ store.dispatch(setIssueComment(commentToUpdate));
5840
+ });
5803
5841
  return [comment, promise];
5804
5842
  }
5805
5843
  remove(offline_id) {
5844
+ const commentToRemove = this.client.store.getState().issueReducer.comments[offline_id];
5845
+ if (!commentToRemove) {
5846
+ throw new Error(`Comment with offline_id ${offline_id} not found in store`);
5847
+ }
5806
5848
  this.client.store.dispatch(removeIssueComment(offline_id));
5807
- return this.enqueueRequest({
5849
+ const promise = this.enqueueRequest({
5808
5850
  description: "Delete comment",
5809
5851
  method: HttpMethod.DELETE,
5810
5852
  url: `/issues/comments/${offline_id}/`,
5811
5853
  blockers: [offline_id],
5812
5854
  blocks: []
5813
5855
  });
5856
+ promise.catch(() => {
5857
+ this.client.store.dispatch(addIssueComment(commentToRemove));
5858
+ });
5859
+ return promise;
5860
+ }
5861
+ async refreshStore() {
5862
+ const { store } = this.client;
5863
+ const result = await this.enqueueRequest({
5864
+ description: "Get comments",
5865
+ method: HttpMethod.GET,
5866
+ // TODO: Choose between /issues/comments/in-project/${projectId}/ and /projects/${projectId}/issue-comments/
5867
+ url: `/projects/${store.getState().projectReducer.activeProjectId}/comments/`,
5868
+ blockers: [],
5869
+ blocks: []
5870
+ });
5871
+ store.dispatch(setIssueComments(result));
5814
5872
  }
5815
5873
  }
5816
5874
  class IssueUpdateService extends BaseApiService {
@@ -7638,10 +7696,33 @@ var __publicField = (obj, key, value) => {
7638
7696
  store.dispatch(setDocuments(result));
7639
7697
  }
7640
7698
  }
7699
+ class AgentService extends BaseApiService {
7700
+ /**
7701
+ * Prompt the agent with a message.
7702
+ * @param request The message to prompt the agent with.
7703
+ * @param conversationId If continuing an existing message, the UUID of that conversation.
7704
+ */
7705
+ prompt(request2, conversationId) {
7706
+ const activeProjectId = this.client.store.getState().projectReducer.activeProjectId;
7707
+ return this.enqueueRequest({
7708
+ description: "Prompt agent",
7709
+ method: HttpMethod.POST,
7710
+ url: "/agents/prompt/",
7711
+ payload: {
7712
+ prompt: request2,
7713
+ active_project: activeProjectId
7714
+ },
7715
+ blockers: ["prompt"],
7716
+ blocks: ["prompt"],
7717
+ queryParams: conversationId ? { conversation_id: conversationId } : {}
7718
+ });
7719
+ }
7720
+ }
7641
7721
  class OvermapSDK {
7642
7722
  constructor(apiUrl, store) {
7643
7723
  __publicField(this, "API_URL");
7644
7724
  __publicField(this, "store");
7725
+ __publicField(this, "agent", new AgentService(this));
7645
7726
  __publicField(this, "files", new FileService(this));
7646
7727
  __publicField(this, "attachments", new AttachmentService(this));
7647
7728
  __publicField(this, "auth", new AuthService(this));
@@ -15330,6 +15411,7 @@ var __publicField = (obj, key, value) => {
15330
15411
  valueIsFile
15331
15412
  }, Symbol.toStringTag, { value: "Module" }));
15332
15413
  exports2.APIError = APIError;
15414
+ exports2.AgentService = AgentService;
15333
15415
  exports2.AttachmentService = AttachmentService;
15334
15416
  exports2.AuthService = AuthService;
15335
15417
  exports2.BaseApiService = BaseApiService;
@@ -15442,6 +15524,8 @@ var __publicField = (obj, key, value) => {
15442
15524
  exports2.addIssue = addIssue;
15443
15525
  exports2.addIssueAttachment = addIssueAttachment;
15444
15526
  exports2.addIssueAttachments = addIssueAttachments;
15527
+ exports2.addIssueComment = addIssueComment;
15528
+ exports2.addIssueComments = addIssueComments;
15445
15529
  exports2.addIssueUpdate = addIssueUpdate;
15446
15530
  exports2.addIssueUpdates = addIssueUpdates;
15447
15531
  exports2.addLicenses = addLicenses;
@@ -15603,6 +15687,7 @@ var __publicField = (obj, key, value) => {
15603
15687
  exports2.removeIssue = removeIssue;
15604
15688
  exports2.removeIssueAttachment = removeIssueAttachment;
15605
15689
  exports2.removeIssueComment = removeIssueComment;
15690
+ exports2.removeIssueComments = removeIssueComments;
15606
15691
  exports2.removeIssueUpdate = removeIssueUpdate;
15607
15692
  exports2.removeIssueUpdates = removeIssueUpdates;
15608
15693
  exports2.removeOrganizationAccess = removeOrganizationAccess;
@@ -15803,6 +15888,7 @@ var __publicField = (obj, key, value) => {
15803
15888
  exports2.setIsImportingProjectFile = setIsImportingProjectFile;
15804
15889
  exports2.setIsLoading = setIsLoading;
15805
15890
  exports2.setIssueAttachments = setIssueAttachments;
15891
+ exports2.setIssueComment = setIssueComment;
15806
15892
  exports2.setIssueComments = setIssueComments;
15807
15893
  exports2.setIssueUpdates = setIssueUpdates;
15808
15894
  exports2.setIssues = setIssues;