@credal/actions 0.2.197 → 0.2.199

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.
Files changed (175) hide show
  1. package/dist/actions/actionMapper.js +8 -1
  2. package/dist/actions/autogen/templates.d.ts +1 -0
  3. package/dist/actions/autogen/templates.js +79 -18
  4. package/dist/actions/autogen/types.d.ts +39 -0
  5. package/dist/actions/autogen/types.js +43 -8
  6. package/dist/actions/groups.js +4 -1
  7. package/dist/actions/invoke.js +11 -22
  8. package/dist/actions/parse.js +231 -244
  9. package/dist/actions/providers/asana/commentAsanaTask.js +8 -15
  10. package/dist/actions/providers/asana/createAsanaTask.js +20 -21
  11. package/dist/actions/providers/asana/getTasksDetails.js +18 -34
  12. package/dist/actions/providers/asana/listAsanaTasksByProject.js +62 -79
  13. package/dist/actions/providers/asana/searchAsanaTasks.js +6 -16
  14. package/dist/actions/providers/asana/updateAsanaTask.js +16 -15
  15. package/dist/actions/providers/asana/utils.js +47 -64
  16. package/dist/actions/providers/bing/getTopNSearchResultUrls.js +4 -14
  17. package/dist/actions/providers/confluence/fetchPageContent.js +5 -15
  18. package/dist/actions/providers/confluence/overwritePage.js +5 -14
  19. package/dist/actions/providers/finnhub/getBasicFinancials.js +7 -19
  20. package/dist/actions/providers/finnhub/symbolLookup.js +3 -12
  21. package/dist/actions/providers/firecrawl/deepResearch.js +11 -21
  22. package/dist/actions/providers/firecrawl/getTopNSearchResultUrls.js +8 -21
  23. package/dist/actions/providers/firecrawl/scrapeTweetDataWithNitter.js +4 -13
  24. package/dist/actions/providers/firecrawl/scrapeUrl.js +16 -21
  25. package/dist/actions/providers/firecrawl/searchAndScrape.js +6 -17
  26. package/dist/actions/providers/generic/fillTemplate.js +2 -11
  27. package/dist/actions/providers/github/createBranch.js +9 -18
  28. package/dist/actions/providers/github/createOrUpdateFile.js +6 -15
  29. package/dist/actions/providers/github/createPullRequest.js +5 -14
  30. package/dist/actions/providers/github/fetchFile.d.ts +3 -0
  31. package/dist/actions/providers/github/fetchFile.js +131 -0
  32. package/dist/actions/providers/github/getBranch.js +4 -13
  33. package/dist/actions/providers/github/getContents.d.ts +3 -0
  34. package/dist/actions/providers/github/getContents.js +41 -0
  35. package/dist/actions/providers/github/getFileContent.js +6 -16
  36. package/dist/actions/providers/github/getPullRequestDetails.js +39 -18
  37. package/dist/actions/providers/github/listCommits.js +17 -15
  38. package/dist/actions/providers/github/listDirectory.js +13 -25
  39. package/dist/actions/providers/github/listPullRequests.js +4 -13
  40. package/dist/actions/providers/github/searchOrganization.js +29 -49
  41. package/dist/actions/providers/github/utils.js +5 -16
  42. package/dist/actions/providers/gitlab/getFileContent.js +13 -24
  43. package/dist/actions/providers/gitlab/getMergeRequest.js +18 -30
  44. package/dist/actions/providers/gitlab/listDirectory.js +15 -27
  45. package/dist/actions/providers/gitlab/searchGroup.js +45 -52
  46. package/dist/actions/providers/gitlab/utils.js +19 -32
  47. package/dist/actions/providers/google-oauth/addGroupMember.js +3 -12
  48. package/dist/actions/providers/google-oauth/addTextToTopOfDoc.js +3 -12
  49. package/dist/actions/providers/google-oauth/appendRowsToSpreadsheet.js +4 -13
  50. package/dist/actions/providers/google-oauth/createNewGoogleDoc.js +7 -17
  51. package/dist/actions/providers/google-oauth/createPresentation.js +7 -13
  52. package/dist/actions/providers/google-oauth/createSpreadsheet.js +7 -13
  53. package/dist/actions/providers/google-oauth/deleteCalendarEvent.js +3 -12
  54. package/dist/actions/providers/google-oauth/deleteGroupMember.js +3 -12
  55. package/dist/actions/providers/google-oauth/deleteRowFromSpreadsheet.js +3 -12
  56. package/dist/actions/providers/google-oauth/editAGoogleCalendarEvent.js +4 -14
  57. package/dist/actions/providers/google-oauth/getDriveFileContentById.js +23 -33
  58. package/dist/actions/providers/google-oauth/getGroup.js +3 -12
  59. package/dist/actions/providers/google-oauth/getPresentation.js +23 -37
  60. package/dist/actions/providers/google-oauth/hasGroupMember.js +3 -12
  61. package/dist/actions/providers/google-oauth/listCalendarEvents.js +27 -21
  62. package/dist/actions/providers/google-oauth/listCalendars.js +4 -14
  63. package/dist/actions/providers/google-oauth/listGroupMembers.js +4 -13
  64. package/dist/actions/providers/google-oauth/listGroups.js +4 -14
  65. package/dist/actions/providers/google-oauth/queryGoogleBigQuery.js +10 -21
  66. package/dist/actions/providers/google-oauth/scheduleCalendarMeeting.js +11 -14
  67. package/dist/actions/providers/google-oauth/searchDriveByKeywords.js +3 -12
  68. package/dist/actions/providers/google-oauth/searchDriveByKeywordsAndGetFileContent.js +12 -23
  69. package/dist/actions/providers/google-oauth/searchDriveByQuery.js +30 -42
  70. package/dist/actions/providers/google-oauth/searchDriveByQueryAndGetFileContent.js +9 -20
  71. package/dist/actions/providers/google-oauth/updateCalendarEvent.js +3 -12
  72. package/dist/actions/providers/google-oauth/updateDoc.js +3 -12
  73. package/dist/actions/providers/google-oauth/updatePresentation.js +3 -12
  74. package/dist/actions/providers/google-oauth/updateRowsInSpreadsheet.js +4 -13
  75. package/dist/actions/providers/google-oauth/updateSpreadsheet.js +3 -12
  76. package/dist/actions/providers/google-oauth/utils/decodeMessage.js +7 -8
  77. package/dist/actions/providers/googleSearch/customSearch.js +18 -36
  78. package/dist/actions/providers/googlemail/listGmailThreads.js +7 -16
  79. package/dist/actions/providers/googlemail/replyToGmail.d.ts +3 -0
  80. package/dist/actions/providers/googlemail/replyToGmail.js +89 -0
  81. package/dist/actions/providers/googlemail/searchGmailMessages.js +10 -20
  82. package/dist/actions/providers/googlemail/sendGmail.js +7 -17
  83. package/dist/actions/providers/googlemaps/nearbysearchRestaurants.js +13 -25
  84. package/dist/actions/providers/googlemaps/validateAddress.js +3 -12
  85. package/dist/actions/providers/hubspot/getCompanies.js +4 -14
  86. package/dist/actions/providers/hubspot/getCompanyDetails.js +3 -12
  87. package/dist/actions/providers/hubspot/getContactDetails.js +3 -12
  88. package/dist/actions/providers/hubspot/getContacts.js +4 -14
  89. package/dist/actions/providers/hubspot/getDealDetails.js +3 -12
  90. package/dist/actions/providers/hubspot/getDeals.js +3 -12
  91. package/dist/actions/providers/hubspot/getTicketDetails.js +3 -12
  92. package/dist/actions/providers/hubspot/getTickets.js +3 -12
  93. package/dist/actions/providers/jira/assignJiraTicket.js +4 -13
  94. package/dist/actions/providers/jira/commentJiraTicket.js +3 -12
  95. package/dist/actions/providers/jira/createJiraTicket.js +22 -18
  96. package/dist/actions/providers/jira/createServiceDeskRequest.js +3 -12
  97. package/dist/actions/providers/jira/getJiraDCIssuesByQuery.js +5 -14
  98. package/dist/actions/providers/jira/getJiraIssuesByQuery.js +19 -29
  99. package/dist/actions/providers/jira/getJiraTicketDetails.js +3 -12
  100. package/dist/actions/providers/jira/getJiraTicketHistory.js +3 -12
  101. package/dist/actions/providers/jira/moveJiraTicketToProject.js +11 -21
  102. package/dist/actions/providers/jira/publicCommentOnServiceDeskRequest.js +3 -12
  103. package/dist/actions/providers/jira/updateJiraTicketDetails.js +15 -15
  104. package/dist/actions/providers/jira/updateJiraTicketStatus.js +4 -13
  105. package/dist/actions/providers/jira/utils.js +104 -126
  106. package/dist/actions/providers/linear/getIssueDetails.js +10 -20
  107. package/dist/actions/providers/linear/getIssues.js +11 -21
  108. package/dist/actions/providers/linear/getProjectDetails.js +10 -20
  109. package/dist/actions/providers/linear/getProjects.js +6 -16
  110. package/dist/actions/providers/linear/getTeamDetails.js +7 -17
  111. package/dist/actions/providers/linear/getTeams.js +5 -15
  112. package/dist/actions/providers/looker/enableUserByEmail.js +5 -14
  113. package/dist/actions/providers/math/add.js +2 -11
  114. package/dist/actions/providers/microsoft/createDocument.js +4 -13
  115. package/dist/actions/providers/microsoft/getDocument.js +4 -13
  116. package/dist/actions/providers/microsoft/messageTeamsChannel.js +4 -13
  117. package/dist/actions/providers/microsoft/messageTeamsChat.js +4 -13
  118. package/dist/actions/providers/microsoft/updateDocument.js +4 -13
  119. package/dist/actions/providers/microsoft/updateSpreadsheet.js +4 -13
  120. package/dist/actions/providers/microsoft/utils.js +9 -20
  121. package/dist/actions/providers/mongodb/insertMongoDoc.js +5 -14
  122. package/dist/actions/providers/notion/searchByTitle.js +3 -12
  123. package/dist/actions/providers/nws/getForecastForLocation.js +4 -13
  124. package/dist/actions/providers/oktaOrg/getOktaUserByName.js +3 -12
  125. package/dist/actions/providers/openstreetmap/getLatitudeLongitudeFromLocation.js +3 -12
  126. package/dist/actions/providers/perplexity/perplexityDeepResearch.js +11 -21
  127. package/dist/actions/providers/resend/sendEmail.js +3 -12
  128. package/dist/actions/providers/resend/sendEmailHtml.js +3 -12
  129. package/dist/actions/providers/salesforce/createCase.js +10 -13
  130. package/dist/actions/providers/salesforce/createRecord.js +3 -12
  131. package/dist/actions/providers/salesforce/executeReport.js +3 -12
  132. package/dist/actions/providers/salesforce/generateSalesReport.js +3 -12
  133. package/dist/actions/providers/salesforce/getRecord.js +3 -12
  134. package/dist/actions/providers/salesforce/getReportMetadata.js +11 -21
  135. package/dist/actions/providers/salesforce/getSalesforceRecordsByQuery.js +7 -17
  136. package/dist/actions/providers/salesforce/listReports.js +3 -12
  137. package/dist/actions/providers/salesforce/searchAllSalesforceRecords.js +3 -12
  138. package/dist/actions/providers/salesforce/searchSalesforceRecords.js +3 -12
  139. package/dist/actions/providers/salesforce/updateRecord.js +3 -12
  140. package/dist/actions/providers/slack/archiveChannel.js +9 -2
  141. package/dist/actions/providers/slack/createChannel.js +7 -17
  142. package/dist/actions/providers/slack/getChannelMembers.js +8 -18
  143. package/dist/actions/providers/slack/getChannelMessages.js +8 -18
  144. package/dist/actions/providers/slack/helpers.js +16 -47
  145. package/dist/actions/providers/slack/messageTransformers.js +10 -13
  146. package/dist/actions/providers/slack/sendDmFromBot.js +9 -19
  147. package/dist/actions/providers/slack/sendMessage.js +7 -17
  148. package/dist/actions/providers/slackUser/searchSlack.js +179 -212
  149. package/dist/actions/providers/slackUser/searchSlackRTS.js +20 -33
  150. package/dist/actions/providers/slackUser/utils.js +1 -1
  151. package/dist/actions/providers/snowflake/auth/getSnowflakeConnection.js +23 -34
  152. package/dist/actions/providers/snowflake/getRowByFieldValue.js +4 -13
  153. package/dist/actions/providers/snowflake/runSnowflakeQuery.js +9 -19
  154. package/dist/actions/providers/zendesk/addCommentToTicket.js +5 -14
  155. package/dist/actions/providers/zendesk/assignTicket.js +3 -12
  156. package/dist/actions/providers/zendesk/createZendeskTicket.js +3 -12
  157. package/dist/actions/providers/zendesk/getTicketDetails.js +3 -12
  158. package/dist/actions/providers/zendesk/listTickets.js +3 -12
  159. package/dist/actions/providers/zendesk/searchZendeskByQuery.js +3 -12
  160. package/dist/actions/providers/zendesk/updateTicketStatus.js +3 -12
  161. package/dist/actions/util/axiosClient.js +5 -5
  162. package/dist/app.js +14 -25
  163. package/dist/utils/google.js +122 -143
  164. package/dist/utils/pdf.js +10 -21
  165. package/package.json +10 -9
  166. package/dist/actions/providers/credal/callCopilot.d.ts +0 -3
  167. package/dist/actions/providers/credal/callCopilot.js +0 -36
  168. package/dist/actions/providers/math/index.d.ts +0 -1
  169. package/dist/actions/providers/math/index.js +0 -37
  170. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.d.ts +0 -3
  171. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.js +0 -43
  172. package/dist/actions/providers/slack/index.d.ts +0 -1
  173. package/dist/actions/providers/slack/index.js +0 -37
  174. package/dist/actions/providers/slack/listConversations.d.ts +0 -3
  175. package/dist/actions/providers/slack/listConversations.js +0 -41
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { WebClient } from "@slack/web-api";
11
2
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
3
  import pLimit from "p-limit";
@@ -22,44 +13,42 @@ const SUBTEAM_RE = /<!subteam\^([A-Z0-9]+)(?:\|[^>]+)?>/g;
22
13
  const MAX_LIMIT_PER_PAGE = 100;
23
14
  /* ===================== Cache ===================== */
24
15
  class SlackUserCache {
16
+ client;
17
+ cache = new Map();
18
+ pending = new Map();
25
19
  constructor(client) {
26
20
  this.client = client;
27
- this.cache = new Map();
28
- this.pending = new Map();
29
21
  }
30
22
  getSync(id) {
31
23
  return this.cache.get(id);
32
24
  }
33
- get(id) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const cached = this.cache.get(id);
36
- if (cached)
37
- return cached;
38
- const pending = this.pending.get(id);
39
- if (pending)
40
- return pending;
41
- // fallback to users.info only if we have to
42
- const promise = (() => __awaiter(this, void 0, void 0, function* () {
43
- var _a, _b, _c, _d, _e;
44
- try {
45
- const res = yield this.client.users.info({ user: id });
46
- if ((_a = res.user) === null || _a === void 0 ? void 0 : _a.id) {
47
- const u = {
48
- name: (_d = (_c = (_b = res.user.profile) === null || _b === void 0 ? void 0 : _b.display_name) !== null && _c !== void 0 ? _c : res.user.real_name) !== null && _d !== void 0 ? _d : res.user.name,
49
- email: (_e = res.user.profile) === null || _e === void 0 ? void 0 : _e.email,
50
- };
51
- this.cache.set(id, u);
52
- return u;
53
- }
54
- return undefined;
55
- }
56
- finally {
57
- this.pending.delete(id);
25
+ async get(id) {
26
+ const cached = this.cache.get(id);
27
+ if (cached)
28
+ return cached;
29
+ const pending = this.pending.get(id);
30
+ if (pending)
31
+ return pending;
32
+ // fallback to users.info only if we have to
33
+ const promise = (async () => {
34
+ try {
35
+ const res = await this.client.users.info({ user: id });
36
+ if (res.user?.id) {
37
+ const u = {
38
+ name: res.user.profile?.display_name ?? res.user.real_name ?? res.user.name,
39
+ email: res.user.profile?.email,
40
+ };
41
+ this.cache.set(id, u);
42
+ return u;
58
43
  }
59
- }))();
60
- this.pending.set(id, promise);
61
- return promise;
62
- });
44
+ return undefined;
45
+ }
46
+ finally {
47
+ this.pending.delete(id);
48
+ }
49
+ })();
50
+ this.pending.set(id, promise);
51
+ return promise;
63
52
  }
64
53
  set(id, { email, name }) {
65
54
  this.cache.set(id, { email, name });
@@ -91,147 +80,122 @@ function timeFilter(range) {
91
80
  return "";
92
81
  }
93
82
  }
94
- function lookupUserIdsByEmail(client, emails, cache) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const ids = [];
97
- const settled = yield Promise.allSettled(emails.map((raw) => __awaiter(this, void 0, void 0, function* () {
98
- var _a, _b, _c, _d, _e;
99
- const email = raw.trim();
100
- if (!email)
101
- return null;
102
- const res = yield client.users.lookupByEmail({ email });
103
- const id = (_a = res.user) === null || _a === void 0 ? void 0 : _a.id;
104
- if (id && res.user) {
105
- cache.set(id, {
106
- name: (_d = (_c = (_b = res.user.profile) === null || _b === void 0 ? void 0 : _b.display_name) !== null && _c !== void 0 ? _c : res.user.real_name) !== null && _d !== void 0 ? _d : res.user.name,
107
- email: (_e = res.user.profile) === null || _e === void 0 ? void 0 : _e.email,
108
- });
109
- }
110
- return id !== null && id !== void 0 ? id : null;
111
- })));
112
- for (const r of settled)
113
- if (r.status === "fulfilled" && r.value)
114
- ids.push(r.value);
115
- return ids;
116
- });
117
- }
118
- function tryGetMPIMName(client, userIds) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- var _a, _b, _c;
121
- try {
122
- const res = yield client.conversations.open({ users: userIds.join(",") });
123
- const id = (_a = res.channel) === null || _a === void 0 ? void 0 : _a.id;
124
- if (!id)
125
- return null;
126
- const info = yield client.conversations.info({ channel: id });
127
- return (_c = (_b = info.channel) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : null;
128
- }
129
- catch (_d) {
83
+ async function lookupUserIdsByEmail(client, emails, cache) {
84
+ const ids = [];
85
+ const settled = await Promise.allSettled(emails.map(async (raw) => {
86
+ const email = raw.trim();
87
+ if (!email)
130
88
  return null;
89
+ const res = await client.users.lookupByEmail({ email });
90
+ const id = res.user?.id;
91
+ if (id && res.user) {
92
+ cache.set(id, {
93
+ name: res.user.profile?.display_name ?? res.user.real_name ?? res.user.name,
94
+ email: res.user.profile?.email,
95
+ });
131
96
  }
132
- });
97
+ return id ?? null;
98
+ }));
99
+ for (const r of settled)
100
+ if (r.status === "fulfilled" && r.value)
101
+ ids.push(r.value);
102
+ return ids;
133
103
  }
134
- function getPermalink(client, channel, ts) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- try {
137
- const res = yield client.chat.getPermalink({ channel, message_ts: ts });
138
- return res.permalink;
139
- }
140
- catch (_a) {
141
- return undefined;
142
- }
143
- });
104
+ async function tryGetMPIMName(client, userIds) {
105
+ try {
106
+ const res = await client.conversations.open({ users: userIds.join(",") });
107
+ const id = res.channel?.id;
108
+ if (!id)
109
+ return null;
110
+ const info = await client.conversations.info({ channel: id });
111
+ return info.channel?.name ?? null;
112
+ }
113
+ catch {
114
+ return null;
115
+ }
144
116
  }
145
- function fetchOneMessage(client, channel, ts) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- var _a;
148
- const r = yield client.conversations.history({ channel, latest: ts, inclusive: true, limit: 1 });
149
- const message = (_a = r.messages) === null || _a === void 0 ? void 0 : _a[0];
150
- if (!message)
151
- return undefined;
152
- return transformToSlackMessage(message);
153
- });
117
+ async function getPermalink(client, channel, ts) {
118
+ try {
119
+ const res = await client.chat.getPermalink({ channel, message_ts: ts });
120
+ return res.permalink;
121
+ }
122
+ catch {
123
+ return undefined;
124
+ }
154
125
  }
155
- function fetchThread(client, channel, threadTs) {
156
- return __awaiter(this, void 0, void 0, function* () {
157
- var _a, _b;
158
- const r = yield client.conversations.replies({ channel, ts: threadTs, limit: 20 });
159
- return (_b = (_a = r.messages) === null || _a === void 0 ? void 0 : _a.map(transformToSlackMessage)) !== null && _b !== void 0 ? _b : [];
160
- });
126
+ async function fetchOneMessage(client, channel, ts) {
127
+ const r = await client.conversations.history({ channel, latest: ts, inclusive: true, limit: 1 });
128
+ const message = r.messages?.[0];
129
+ if (!message)
130
+ return undefined;
131
+ return transformToSlackMessage(message);
132
+ }
133
+ async function fetchThread(client, channel, threadTs) {
134
+ const r = await client.conversations.replies({ channel, ts: threadTs, limit: 20 });
135
+ return r.messages?.map(transformToSlackMessage) ?? [];
161
136
  }
162
- function fetchContextWindow(client, channel, ts) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- var _a, _b;
165
- const out = [];
166
- const anchor = yield fetchOneMessage(client, channel, ts);
167
- if (!anchor)
168
- return out;
169
- const before = yield client.conversations.history({ channel, latest: ts, inclusive: false, limit: 3 });
170
- const beforeMessages = (_a = before.messages) === null || _a === void 0 ? void 0 : _a.map(transformToSlackMessage);
171
- out.push(...(beforeMessages !== null && beforeMessages !== void 0 ? beforeMessages : []).reverse());
172
- out.push(anchor);
173
- const after = yield client.conversations.history({ channel, oldest: ts, inclusive: false, limit: 3 });
174
- const afterMessages = (_b = after.messages) === null || _b === void 0 ? void 0 : _b.map(transformToSlackMessage);
175
- out.push(...(afterMessages !== null && afterMessages !== void 0 ? afterMessages : []));
137
+ async function fetchContextWindow(client, channel, ts) {
138
+ const out = [];
139
+ const anchor = await fetchOneMessage(client, channel, ts);
140
+ if (!anchor)
176
141
  return out;
177
- });
142
+ const before = await client.conversations.history({ channel, latest: ts, inclusive: false, limit: 3 });
143
+ const beforeMessages = before.messages?.map(transformToSlackMessage);
144
+ out.push(...(beforeMessages ?? []).reverse());
145
+ out.push(anchor);
146
+ const after = await client.conversations.history({ channel, oldest: ts, inclusive: false, limit: 3 });
147
+ const afterMessages = after.messages?.map(transformToSlackMessage);
148
+ out.push(...(afterMessages ?? []));
149
+ return out;
178
150
  }
179
151
  function hasOverlap(messages, ids, minOverlap) {
180
152
  const participants = new Set(messages.map(m => m.user).filter(Boolean));
181
153
  const overlap = ids.filter(id => participants.has(id)).length;
182
154
  return overlap >= minOverlap;
183
155
  }
184
- function expandSlackEntities(cache, raw) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- let text = raw;
187
- const userIds = [...raw.matchAll(MENTION_USER_RE)].map(m => m[1]);
188
- // resolve all in parallel: prefer cache, else users.info
189
- const idToName = {};
190
- yield Promise.all(userIds.map((id) => __awaiter(this, void 0, void 0, function* () {
191
- const u = yield cache.get(id); // get() will call users.info if missing
192
- if (u === null || u === void 0 ? void 0 : u.name)
193
- idToName[id] = u.name;
194
- })));
195
- text = text.replace(MENTION_USER_RE, (_, id) => { var _a; return `@${(_a = idToName[id]) !== null && _a !== void 0 ? _a : id}`; });
196
- text = text.replace(MENTION_CHANNEL_RE, (_, id) => `#${id}`);
197
- text = text.replace(SPECIAL_RE, (_, kind) => `@${kind}`);
198
- text = text.replace(SUBTEAM_RE, (_m, sid) => `@${sid}`);
199
- text = text.replace(/<([^>|]+)\|([^>]+)>/g, (_m, _url, label) => label);
200
- text = text.replace(/<([^>|]+)>/g, (_m, url) => url);
201
- return text;
202
- });
156
+ async function expandSlackEntities(cache, raw) {
157
+ let text = raw;
158
+ const userIds = [...raw.matchAll(MENTION_USER_RE)].map(m => m[1]);
159
+ // resolve all in parallel: prefer cache, else users.info
160
+ const idToName = {};
161
+ await Promise.all(userIds.map(async (id) => {
162
+ const u = await cache.get(id); // get() will call users.info if missing
163
+ if (u?.name)
164
+ idToName[id] = u.name;
165
+ }));
166
+ text = text.replace(MENTION_USER_RE, (_, id) => `@${idToName[id] ?? id}`);
167
+ text = text.replace(MENTION_CHANNEL_RE, (_, id) => `#${id}`);
168
+ text = text.replace(SPECIAL_RE, (_, kind) => `@${kind}`);
169
+ text = text.replace(SUBTEAM_RE, (_m, sid) => `@${sid}`);
170
+ text = text.replace(/<([^>|]+)\|([^>]+)>/g, (_m, _url, label) => label);
171
+ text = text.replace(/<([^>|]+)>/g, (_m, url) => url);
172
+ return text;
203
173
  }
204
- function searchScoped(input) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- var _a, _b;
207
- const { client, scope, topic, timeRange } = input;
208
- const parts = [];
209
- if (scope)
210
- parts.push(`in:${scope}`);
211
- if (topic === null || topic === void 0 ? void 0 : topic.trim())
212
- parts.push(topic.trim());
213
- const tf = timeFilter(timeRange);
214
- if (tf)
215
- parts.push(tf);
216
- const query = parts.join(" ");
217
- const searchRes = yield client.search.messages({ query, count: MAX_LIMIT_PER_PAGE, highlight: true });
218
- return (_b = (_a = searchRes.messages) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : [];
219
- });
174
+ async function searchScoped(input) {
175
+ const { client, scope, topic, timeRange } = input;
176
+ const parts = [];
177
+ if (scope)
178
+ parts.push(`in:${scope}`);
179
+ if (topic?.trim())
180
+ parts.push(topic.trim());
181
+ const tf = timeFilter(timeRange);
182
+ if (tf)
183
+ parts.push(tf);
184
+ const query = parts.join(" ");
185
+ const searchRes = await client.search.messages({ query, count: MAX_LIMIT_PER_PAGE, highlight: true });
186
+ return searchRes.messages?.matches ?? [];
220
187
  }
221
- function searchByTopic(input) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- var _a, _b;
224
- const { client, topic, timeRange } = input;
225
- const parts = [];
226
- if (topic === null || topic === void 0 ? void 0 : topic.trim())
227
- parts.push(topic.trim());
228
- const tf = timeFilter(timeRange);
229
- if (tf)
230
- parts.push(tf);
231
- const query = parts.join(" ");
232
- const searchRes = yield client.search.messages({ query, count: MAX_LIMIT_PER_PAGE, highlight: true });
233
- return (_b = (_a = searchRes.messages) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : [];
234
- });
188
+ async function searchByTopic(input) {
189
+ const { client, topic, timeRange } = input;
190
+ const parts = [];
191
+ if (topic?.trim())
192
+ parts.push(topic.trim());
193
+ const tf = timeFilter(timeRange);
194
+ if (tf)
195
+ parts.push(tf);
196
+ const query = parts.join(" ");
197
+ const searchRes = await client.search.messages({ query, count: MAX_LIMIT_PER_PAGE, highlight: true });
198
+ return searchRes.messages?.matches ?? [];
235
199
  }
236
200
  /**
237
201
  * Deduplicates and merges Slack threads.
@@ -239,7 +203,6 @@ function searchByTopic(input) {
239
203
  * we merge them into a single result with all unique messages in context.
240
204
  */
241
205
  function dedupeAndSort(results) {
242
- var _a, _b, _c, _d, _e, _f, _g;
243
206
  // Group by thread: channelId + ts (where ts is the root thread_ts)
244
207
  const threadMap = new Map();
245
208
  for (const result of results) {
@@ -251,10 +214,10 @@ function dedupeAndSort(results) {
251
214
  }
252
215
  else {
253
216
  // Merge: dedupe context messages by ts
254
- const existingTsSet = new Set((_b = (_a = existing.context) === null || _a === void 0 ? void 0 : _a.map(m => m.ts)) !== null && _b !== void 0 ? _b : []);
255
- const newMessages = ((_c = result.context) !== null && _c !== void 0 ? _c : []).filter(m => !existingTsSet.has(m.ts));
217
+ const existingTsSet = new Set(existing.context?.map(m => m.ts) ?? []);
218
+ const newMessages = (result.context ?? []).filter(m => !existingTsSet.has(m.ts));
256
219
  if (newMessages.length > 0) {
257
- existing.context = [...((_d = existing.context) !== null && _d !== void 0 ? _d : []), ...newMessages].sort((a, b) => Number(a.ts) - Number(b.ts));
220
+ existing.context = [...(existing.context ?? []), ...newMessages].sort((a, b) => Number(a.ts) - Number(b.ts));
258
221
  }
259
222
  // Update permalink if missing
260
223
  if (!existing.permalink && result.permalink) {
@@ -262,10 +225,10 @@ function dedupeAndSort(results) {
262
225
  }
263
226
  // Merge members if needed (for DMs/MPIMs)
264
227
  if (result.members && result.members.length > 0) {
265
- const existingMemberIds = new Set((_f = (_e = existing.members) === null || _e === void 0 ? void 0 : _e.map(m => m.userId)) !== null && _f !== void 0 ? _f : []);
228
+ const existingMemberIds = new Set(existing.members?.map(m => m.userId) ?? []);
266
229
  const newMembers = result.members.filter(m => !existingMemberIds.has(m.userId));
267
230
  if (newMembers.length > 0) {
268
- existing.members = [...((_g = existing.members) !== null && _g !== void 0 ? _g : []), ...newMembers];
231
+ existing.members = [...(existing.members ?? []), ...newMembers];
269
232
  }
270
233
  }
271
234
  }
@@ -274,20 +237,20 @@ function dedupeAndSort(results) {
274
237
  return Array.from(threadMap.values()).sort((a, b) => Number(b.ts) - Number(a.ts));
275
238
  }
276
239
  /* ===================== MAIN EXPORT ===================== */
277
- const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
240
+ const searchSlack = async ({ params, authParams, }) => {
278
241
  if (!authParams.authToken)
279
242
  throw new Error(MISSING_AUTH_TOKEN);
280
243
  const client = new WebClient(authParams.authToken);
281
244
  const cache = new SlackUserCache(client);
282
245
  const { emails, topic, timeRange, limit = 20, channel, fetchAdjacentMessages = true, messageType } = params;
283
246
  const messageTypeFilter = getMessageTypeFilter(messageType);
284
- const { user_id: myUserId } = yield client.auth.test();
247
+ const { user_id: myUserId } = await client.auth.test();
285
248
  if (!myUserId)
286
249
  throw new Error("Failed to get my user ID.");
287
250
  // preload myself
288
- const meInfo = yield cache.get(myUserId);
251
+ const meInfo = await cache.get(myUserId);
289
252
  // resolve targets by email
290
- const targetIds = (emails === null || emails === void 0 ? void 0 : emails.length) ? yield lookupUserIdsByEmail(client, emails, cache) : [];
253
+ const targetIds = emails?.length ? await lookupUserIdsByEmail(client, emails, cache) : [];
291
254
  const filteredTargetIds = targetIds.filter(id => id !== myUserId);
292
255
  const allMatches = [];
293
256
  const searchPromises = [];
@@ -295,10 +258,10 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
295
258
  searchPromises.push(searchScoped({ client, scope: `<@${filteredTargetIds[0]}>`, topic, timeRange }));
296
259
  }
297
260
  else if (filteredTargetIds.length >= 2) {
298
- const searchMPIM = () => __awaiter(void 0, void 0, void 0, function* () {
299
- const mpimName = yield tryGetMPIMName(client, filteredTargetIds);
261
+ const searchMPIM = async () => {
262
+ const mpimName = await tryGetMPIMName(client, filteredTargetIds);
300
263
  return mpimName ? searchScoped({ client, scope: mpimName, topic, timeRange }) : [];
301
- });
264
+ };
302
265
  searchPromises.push(searchMPIM());
303
266
  searchPromises.push(...filteredTargetIds.map(id => searchScoped({
304
267
  client,
@@ -329,7 +292,7 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
329
292
  timeRange,
330
293
  }));
331
294
  }
332
- const searchResults = yield Promise.all(searchPromises);
295
+ const searchResults = await Promise.all(searchPromises);
333
296
  const searchResultsFilteredByTypeAndLimit = searchResults.map(matches => {
334
297
  return matches
335
298
  .filter(m => {
@@ -342,38 +305,37 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
342
305
  });
343
306
  searchResultsFilteredByTypeAndLimit.forEach(matches => allMatches.push(...matches));
344
307
  const channelInfoCache = new Map();
345
- const expanded = yield Promise.all(allMatches.map(m => limitHit(() => __awaiter(void 0, void 0, void 0, function* () {
346
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _o;
347
- if (!m.ts || !((_a = m.channel) === null || _a === void 0 ? void 0 : _a.id))
308
+ const expanded = await Promise.all(allMatches.map(m => limitHit(async () => {
309
+ if (!m.ts || !m.channel?.id)
348
310
  return null;
349
- const anchor = yield fetchOneMessage(client, m.channel.id, m.ts);
350
- const rootTs = (anchor === null || anchor === void 0 ? void 0 : anchor.thread_ts) || m.ts;
311
+ const anchor = await fetchOneMessage(client, m.channel.id, m.ts);
312
+ const rootTs = anchor?.thread_ts || m.ts;
351
313
  // channel info
352
314
  let channelInfo = channelInfoCache.get(m.channel.id);
353
315
  if (!channelInfo) {
354
- const convoInfo = yield client.conversations.info({ channel: m.channel.id });
355
- const isIm = (_c = (_b = convoInfo.channel) === null || _b === void 0 ? void 0 : _b.is_im) !== null && _c !== void 0 ? _c : false;
356
- const isMpim = (_e = (_d = convoInfo.channel) === null || _d === void 0 ? void 0 : _d.is_mpim) !== null && _e !== void 0 ? _e : false;
316
+ const convoInfo = await client.conversations.info({ channel: m.channel.id });
317
+ const isIm = convoInfo.channel?.is_im ?? false;
318
+ const isMpim = convoInfo.channel?.is_mpim ?? false;
357
319
  let members = [];
358
320
  if (isIm || isMpim) {
359
- const res = yield client.conversations.members({ channel: m.channel.id });
360
- members = (_f = res.members) !== null && _f !== void 0 ? _f : [];
321
+ const res = await client.conversations.members({ channel: m.channel.id });
322
+ members = res.members ?? [];
361
323
  }
362
324
  channelInfo = { isIm, isMpim, members };
363
325
  channelInfoCache.set(m.channel.id, channelInfo);
364
326
  }
365
327
  // context + permalink
366
- const [contextMsgs, permalink] = (anchor === null || anchor === void 0 ? void 0 : anchor.thread_ts)
328
+ const [contextMsgs, permalink] = anchor?.thread_ts
367
329
  ? [
368
- yield fetchThread(client, m.channel.id, rootTs),
369
- (_g = m.permalink) !== null && _g !== void 0 ? _g : (yield getPermalink(client, m.channel.id, rootTs)),
330
+ await fetchThread(client, m.channel.id, rootTs),
331
+ m.permalink ?? (await getPermalink(client, m.channel.id, rootTs)),
370
332
  ]
371
333
  : fetchAdjacentMessages
372
334
  ? [
373
- yield fetchContextWindow(client, m.channel.id, m.ts),
374
- (_h = m.permalink) !== null && _h !== void 0 ? _h : (yield getPermalink(client, m.channel.id, m.ts)),
335
+ await fetchContextWindow(client, m.channel.id, m.ts),
336
+ m.permalink ?? (await getPermalink(client, m.channel.id, m.ts)),
375
337
  ]
376
- : [[], (_j = m.permalink) !== null && _j !== void 0 ? _j : (yield getPermalink(client, m.channel.id, m.ts))];
338
+ : [[], m.permalink ?? (await getPermalink(client, m.channel.id, m.ts))];
377
339
  // filter logic
378
340
  let passesFilter = false;
379
341
  if (channelInfo.isIm || channelInfo.isMpim) {
@@ -385,9 +347,8 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
385
347
  }
386
348
  if (filteredTargetIds.length && !passesFilter)
387
349
  return null;
388
- const allContext = yield Promise.all(contextMsgs.map((t) => __awaiter(void 0, void 0, void 0, function* () {
389
- var _a;
390
- const u = t.user ? yield cache.get(t.user) : undefined;
350
+ const allContext = await Promise.all(contextMsgs.map(async (t) => {
351
+ const u = t.user ? await cache.get(t.user) : undefined;
391
352
  const rawText = extractMessageText(t);
392
353
  // Simplify files to only include highest quality thumbnail
393
354
  if (t.files && Array.isArray(t.files)) {
@@ -401,8 +362,14 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
401
362
  if (t.files && t.files.length > 0) {
402
363
  interactions.push(`Files: ${t.files.map(f => f.title || f.name || "Untitled").join(", ")}`);
403
364
  }
404
- return Object.assign({ ts: t.ts, text: rawText ? yield expandSlackEntities(cache, rawText) : undefined, userEmail: u === null || u === void 0 ? void 0 : u.email, userName: (_a = u === null || u === void 0 ? void 0 : u.name) !== null && _a !== void 0 ? _a : t.username }, (interactions.length > 0 ? { interactions: interactions.join(" | ") } : {}));
405
- })));
365
+ return {
366
+ ts: t.ts,
367
+ text: rawText ? await expandSlackEntities(cache, rawText) : undefined,
368
+ userEmail: u?.email,
369
+ userName: u?.name ?? t.username,
370
+ ...(interactions.length > 0 ? { interactions: interactions.join(" | ") } : {}),
371
+ };
372
+ }));
406
373
  // Deduplicate by timestamp - appears the the context array returned can have duplicates
407
374
  const seenTs = new Set();
408
375
  const context = allContext.filter(msg => {
@@ -411,31 +378,31 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
411
378
  seenTs.add(msg.ts);
412
379
  return true;
413
380
  });
414
- const anchorUser = (anchor === null || anchor === void 0 ? void 0 : anchor.user) ? yield cache.get(anchor.user) : undefined;
381
+ const anchorUser = anchor?.user ? await cache.get(anchor.user) : undefined;
415
382
  const anchorText = extractMessageText(anchor);
416
383
  return {
417
384
  channelId: m.channel.id,
418
385
  ts: rootTs,
419
- text: anchorText ? yield expandSlackEntities(cache, anchorText) : undefined,
420
- userEmail: anchorUser === null || anchorUser === void 0 ? void 0 : anchorUser.email,
421
- userName: (_k = anchorUser === null || anchorUser === void 0 ? void 0 : anchorUser.name) !== null && _k !== void 0 ? _k : anchor === null || anchor === void 0 ? void 0 : anchor.username,
386
+ text: anchorText ? await expandSlackEntities(cache, anchorText) : undefined,
387
+ userEmail: anchorUser?.email,
388
+ userName: anchorUser?.name ?? anchor?.username,
422
389
  context,
423
- permalink: (_l = m.permalink) !== null && _l !== void 0 ? _l : permalink,
424
- members: ((_o = channelInfo.members) !== null && _o !== void 0 ? _o : []).map(uid => {
390
+ permalink: m.permalink ?? permalink,
391
+ members: (channelInfo.members ?? []).map(uid => {
425
392
  const u = cache.getSync(uid);
426
- return { userId: uid, userEmail: u === null || u === void 0 ? void 0 : u.email, userName: u === null || u === void 0 ? void 0 : u.name };
393
+ return { userId: uid, userEmail: u?.email, userName: u?.name };
427
394
  }),
428
395
  };
429
- }))));
396
+ })));
430
397
  const results = dedupeAndSort(expanded.filter(Boolean));
431
398
  return {
432
- query: topic !== null && topic !== void 0 ? topic : "",
399
+ query: topic ?? "",
433
400
  results: results.map(r => ({
434
401
  name: r.text || "Untitled",
435
402
  url: r.permalink || "",
436
403
  contents: r,
437
404
  })),
438
- currentUser: { userId: myUserId, userName: meInfo === null || meInfo === void 0 ? void 0 : meInfo.name, userEmail: meInfo === null || meInfo === void 0 ? void 0 : meInfo.email },
405
+ currentUser: { userId: myUserId, userName: meInfo?.name, userEmail: meInfo?.email },
439
406
  };
440
- });
407
+ };
441
408
  export default searchSlack;
@@ -1,32 +1,20 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { WebClient } from "@slack/web-api";
11
2
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
3
  import { normalizeChannelOperand } from "./utils.js";
13
4
  /* ===================== Types ===================== */
14
- function resolveSlackUserId(client, raw) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- var _a;
17
- const s = raw.trim();
18
- if (!s)
19
- return null;
20
- try {
21
- const res = yield client.users.lookupByEmail({ email: s });
22
- if ((_a = res.user) === null || _a === void 0 ? void 0 : _a.id)
23
- return res.user.id;
24
- }
25
- catch (_b) {
26
- // ignore and fall back
27
- }
5
+ async function resolveSlackUserId(client, raw) {
6
+ const s = raw.trim();
7
+ if (!s)
28
8
  return null;
29
- });
9
+ try {
10
+ const res = await client.users.lookupByEmail({ email: s });
11
+ if (res.user?.id)
12
+ return res.user.id;
13
+ }
14
+ catch {
15
+ // ignore and fall back
16
+ }
17
+ return null;
30
18
  }
31
19
  function appendToQuery(query, suffix) {
32
20
  const q = query.trim();
@@ -48,8 +36,7 @@ function normalizeUnixSecondsInput(value) {
48
36
  return String(Math.floor(date.getTime() / 1000));
49
37
  }
50
38
  /* ===================== MAIN EXPORT ===================== */
51
- const searchSlackRTS = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
52
- var _b, _c;
39
+ const searchSlackRTS = async ({ params, authParams, }) => {
53
40
  if (!authParams.authToken)
54
41
  throw new Error(MISSING_AUTH_TOKEN);
55
42
  const client = new WebClient(authParams.authToken);
@@ -59,9 +46,9 @@ const searchSlackRTS = (_a) => __awaiter(void 0, [_a], void 0, function* ({ para
59
46
  (!channelIds || channelIds.length === 0)) {
60
47
  throw new Error("If query is left blank, you must provide at least one userEmail or channelId to filter by.");
61
48
  }
62
- let finalQuery = query !== null && query !== void 0 ? query : "";
49
+ let finalQuery = query ?? "";
63
50
  if (userEmails != undefined && userEmails.length > 0) {
64
- const settled = yield Promise.allSettled(userEmails.map((u) => resolveSlackUserId(client, u)));
51
+ const settled = await Promise.allSettled(userEmails.map((u) => resolveSlackUserId(client, u)));
65
52
  const fulfilled = settled.filter((r) => r.status === "fulfilled");
66
53
  const ids = fulfilled.map(r => r.value).filter((id) => Boolean(id));
67
54
  if (ids.length > 0) {
@@ -111,7 +98,7 @@ const searchSlackRTS = (_a) => __awaiter(void 0, [_a], void 0, function* ({ para
111
98
  }
112
99
  try {
113
100
  // Call the assistant.search.context API
114
- const response = (yield client.apiCall("assistant.search.context", requestParams));
101
+ const response = (await client.apiCall("assistant.search.context", requestParams));
115
102
  if (!response.ok) {
116
103
  throw new Error(`Slack API error: ${response.error || "Unknown error"}`);
117
104
  }
@@ -119,15 +106,15 @@ const searchSlackRTS = (_a) => __awaiter(void 0, [_a], void 0, function* ({ para
119
106
  return {
120
107
  ok: response.ok,
121
108
  results: {
122
- messages: ((_b = response.results) === null || _b === void 0 ? void 0 : _b.messages) || [],
123
- files: ((_c = response.results) === null || _c === void 0 ? void 0 : _c.files) || [],
109
+ messages: response.results?.messages || [],
110
+ files: response.results?.files || [],
124
111
  },
125
112
  };
126
113
  }
127
114
  catch (error) {
128
115
  // Handle errors gracefully
129
116
  const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
130
- throw new Error(`Failed to search Slack using RTS API: ${errorMessage}`);
117
+ throw new Error(`Failed to search Slack using RTS API: ${errorMessage}`, { cause: error });
131
118
  }
132
- });
119
+ };
133
120
  export default searchSlackRTS;