@credal/actions 0.2.127 → 0.2.129

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 (39) hide show
  1. package/dist/actions/autogen/templates.js +909 -584
  2. package/dist/actions/autogen/types.d.ts +865 -938
  3. package/dist/actions/autogen/types.js +365 -212
  4. package/dist/actions/groups.d.ts +6 -0
  5. package/dist/actions/groups.js +261 -0
  6. package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
  7. package/dist/actions/providers/confluence/updatePage.js +47 -0
  8. package/dist/actions/providers/credal/callCopilot.d.ts +3 -0
  9. package/dist/actions/providers/credal/callCopilot.js +36 -0
  10. package/dist/actions/providers/firecrawl/scrapeUrl.js +11 -4
  11. package/dist/actions/providers/github/getFileContent.js +13 -5
  12. package/dist/actions/providers/github/listDirectory.js +12 -11
  13. package/dist/actions/providers/github/listPullRequests.js +58 -30
  14. package/dist/actions/providers/github/searchOrganization.d.ts +1 -1
  15. package/dist/actions/providers/github/searchOrganization.js +26 -4
  16. package/dist/actions/providers/gitlab/getFileContent.js +15 -6
  17. package/dist/actions/providers/gitlab/listDirectory.js +10 -6
  18. package/dist/actions/providers/gitlab/searchGroup.js +84 -55
  19. package/dist/actions/providers/google-oauth/getDriveFileContentById.js +10 -1
  20. package/dist/actions/providers/google-oauth/searchDriveByKeywordsAndGetFileContent.js +12 -4
  21. package/dist/actions/providers/google-oauth/searchDriveByQueryAndGetFileContent.js +2 -1
  22. package/dist/actions/providers/jamf/types.d.ts +8 -0
  23. package/dist/actions/providers/jamf/types.js +7 -0
  24. package/dist/actions/providers/jira/getJiraIssuesByQuery.js +9 -7
  25. package/dist/actions/providers/jira/getJiraTicketDetails.js +8 -1
  26. package/dist/actions/providers/math/index.d.ts +1 -0
  27. package/dist/actions/providers/math/index.js +37 -0
  28. package/dist/actions/providers/salesforce/getSalesforceRecordsByQuery.js +10 -3
  29. package/dist/actions/providers/salesforce/searchSalesforceRecords.js +9 -7
  30. package/dist/actions/providers/slack/archiveChannel.d.ts +3 -0
  31. package/dist/actions/providers/slack/archiveChannel.js +42 -0
  32. package/dist/actions/providers/slack/index.d.ts +1 -0
  33. package/dist/actions/providers/slack/index.js +37 -0
  34. package/dist/actions/providers/slack/listConversations.d.ts +3 -0
  35. package/dist/actions/providers/slack/listConversations.js +41 -0
  36. package/dist/actions/providers/slackUser/searchSlack.js +81 -8
  37. package/package.json +1 -1
  38. package/dist/actions/providers/jira/updateServiceDeskRequest.d.ts +0 -3
  39. package/dist/actions/providers/jira/updateServiceDeskRequest.js +0 -72
@@ -12,6 +12,10 @@ import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  import pLimit from "p-limit";
13
13
  const HIT_ENRICH_POOL = 5;
14
14
  const limitHit = pLimit(HIT_ENRICH_POOL);
15
+ const MENTION_USER_RE = /<@([UW][A-Z0-9]+)(?:\|[^>]+)?>/g;
16
+ const MENTION_CHANNEL_RE = /<#(C[A-Z0-9]+)(?:\|[^>]+)?>/g;
17
+ const SPECIAL_RE = /<!(channel|here|everyone)>/g;
18
+ const SUBTEAM_RE = /<!subteam\^([A-Z0-9]+)(?:\|[^>]+)?>/g; // user group
15
19
  class SlackUserCache {
16
20
  constructor(client) {
17
21
  this.client = client;
@@ -171,11 +175,17 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
171
175
  const slackUserCache = new SlackUserCache(client);
172
176
  const { emails, channel, topic, timeRange, limit } = params;
173
177
  const parts = [];
178
+ const { user_id: myUserId } = yield client.auth.test();
179
+ if (!myUserId)
180
+ throw new Error("Failed to get my user ID.");
181
+ const me = yield slackUserCache.get(myUserId);
182
+ const currentUser = {
183
+ userId: myUserId,
184
+ userName: me === null || me === void 0 ? void 0 : me.name,
185
+ userEmail: me === null || me === void 0 ? void 0 : me.email,
186
+ };
174
187
  if (emails === null || emails === void 0 ? void 0 : emails.length) {
175
188
  const userIds = yield lookupUserIdsByEmail(client, emails, slackUserCache);
176
- const { user_id: myUserId } = yield client.auth.test();
177
- if (!myUserId)
178
- throw new Error("Failed to get my user ID.");
179
189
  const userIdsWithoutMe = userIds.filter(id => id !== myUserId);
180
190
  if (userIdsWithoutMe.length === 0)
181
191
  throw new Error("No users resolved from emails.");
@@ -204,10 +214,11 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
204
214
  const hitsPromises = matches.slice(0, limit).map((m) => __awaiter(void 0, void 0, void 0, function* () {
205
215
  var _a, _b, _c, _d;
206
216
  const user = m.user ? yield slackUserCache.get(m.user) : undefined;
217
+ const prettyText = m.text ? yield expandSlackEntities(client, slackUserCache, m.text) : undefined;
207
218
  return {
208
219
  channelId: ((_a = m.channel) === null || _a === void 0 ? void 0 : _a.id) || ((_b = m.channel) === null || _b === void 0 ? void 0 : _b.name) || "",
209
220
  ts: m.ts,
210
- text: m.text,
221
+ text: prettyText,
211
222
  userEmail: (_c = user === null || user === void 0 ? void 0 : user.email) !== null && _c !== void 0 ? _c : undefined,
212
223
  userName: (_d = user === null || user === void 0 ? void 0 : user.name) !== null && _d !== void 0 ? _d : undefined,
213
224
  };
@@ -231,19 +242,22 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
231
242
  .map((t) => __awaiter(void 0, void 0, void 0, function* () {
232
243
  var _a, _b;
233
244
  const user = t.user ? yield slackUserCache.get(t.user) : undefined;
245
+ const prettyText = t.text ? yield expandSlackEntities(client, slackUserCache, t.text) : undefined;
234
246
  return {
235
247
  ts: t.ts,
236
- text: t.text,
248
+ text: prettyText,
237
249
  userEmail: (_a = user === null || user === void 0 ? void 0 : user.email) !== null && _a !== void 0 ? _a : undefined,
238
250
  userName: (_b = user === null || user === void 0 ? void 0 : user.name) !== null && _b !== void 0 ? _b : undefined,
239
251
  };
240
252
  }));
241
253
  const context = yield Promise.all(contextPromises);
242
254
  const user = anchor.user ? yield slackUserCache.get(anchor.user) : undefined;
255
+ const textResponse = (_a = anchor.text) !== null && _a !== void 0 ? _a : h.text;
256
+ const prettyText = textResponse ? yield expandSlackEntities(client, slackUserCache, textResponse) : undefined;
243
257
  return {
244
258
  channelId: h.channelId,
245
259
  ts: rootTs,
246
- text: (_a = anchor.text) !== null && _a !== void 0 ? _a : h.text,
260
+ text: prettyText,
247
261
  userEmail: (_b = user === null || user === void 0 ? void 0 : user.email) !== null && _b !== void 0 ? _b : h.userEmail,
248
262
  userName: (_c = user === null || user === void 0 ? void 0 : user.name) !== null && _c !== void 0 ? _c : h.userName,
249
263
  context,
@@ -286,7 +300,7 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
286
300
  return {
287
301
  channelId: h.channelId,
288
302
  ts: h.ts,
289
- text: h.text,
303
+ text: h.text ? yield expandSlackEntities(client, slackUserCache, h.text) : undefined,
290
304
  userEmail: h.userEmail,
291
305
  userName: h.userName,
292
306
  permalink: yield getPermalink(client, h.channelId, h.ts),
@@ -299,6 +313,65 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
299
313
  if (r.status === "fulfilled" && r.value)
300
314
  results.push(r.value);
301
315
  results.sort((a, b) => Number(b.ts) - Number(a.ts));
302
- return { query, results };
316
+ return {
317
+ query,
318
+ results: results.map(r => ({
319
+ name: r.text || "Untitled",
320
+ url: r.permalink || "",
321
+ contents: r,
322
+ })),
323
+ currentUser,
324
+ };
303
325
  });
326
+ function expandSlackEntities(client_1, cache_1, raw_1) {
327
+ return __awaiter(this, arguments, void 0, function* (client, cache, raw, { includeEmail = false } = {}) {
328
+ let text = raw;
329
+ // 1) Users: <@U12345> -> @Name (or @Name <email>)
330
+ const userIds = new Set();
331
+ for (const m of raw.matchAll(MENTION_USER_RE))
332
+ userIds.add(m[1]);
333
+ const idToUser = {};
334
+ yield Promise.all([...userIds].map((id) => __awaiter(this, void 0, void 0, function* () {
335
+ try {
336
+ const u = yield cache.get(id);
337
+ idToUser[id] = { name: u === null || u === void 0 ? void 0 : u.name, email: u === null || u === void 0 ? void 0 : u.email };
338
+ }
339
+ catch (_a) {
340
+ idToUser[id] = {};
341
+ }
342
+ })));
343
+ text = text.replace(MENTION_USER_RE, (_, id) => {
344
+ const u = idToUser[id];
345
+ if (u === null || u === void 0 ? void 0 : u.name) {
346
+ return includeEmail && u.email ? `@${u.name} <${u.email}>` : `@${u.name}`;
347
+ }
348
+ // fallback: keep original token if we can't resolve
349
+ return `@${id}`;
350
+ });
351
+ // 2) Channels: <#C12345|name> -> #name (fallback to #C12345)
352
+ const channelIds = new Set();
353
+ for (const m of raw.matchAll(MENTION_CHANNEL_RE))
354
+ channelIds.add(m[1]);
355
+ const idToChannel = {};
356
+ yield Promise.all([...channelIds].map((id) => __awaiter(this, void 0, void 0, function* () {
357
+ var _a, _b;
358
+ try {
359
+ const info = yield client.conversations.info({ channel: id });
360
+ idToChannel[id] = (_b = (_a = info.channel) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : undefined;
361
+ }
362
+ catch (_c) {
363
+ idToChannel[id] = undefined;
364
+ }
365
+ })));
366
+ text = text.replace(MENTION_CHANNEL_RE, (_, id) => { var _a; return `#${(_a = idToChannel[id]) !== null && _a !== void 0 ? _a : id}`; });
367
+ // 3) Special mentions: <!here>, <!channel>, <!everyone>
368
+ text = text.replace(SPECIAL_RE, (_, kind) => `@${kind}`);
369
+ // 4) User groups: <!subteam^S123|@group> -> @group (fallback to @S123)
370
+ text = text.replace(SUBTEAM_RE, (_m, sid) => `@${sid}`);
371
+ // 5) Slack links: <https://x|label> -> label (or the URL)
372
+ text = text.replace(/<([^>|]+)\|([^>]+)>/g, (_m, _url, label) => label); // keep label
373
+ text = text.replace(/<([^>|]+)>/g, (_m, url) => url); // bare <https://…>
374
+ return text;
375
+ });
376
+ }
304
377
  export default searchSlack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.127",
3
+ "version": "0.2.129",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -1,3 +0,0 @@
1
- import type { jiraUpdateServiceDeskRequestFunction } from "../../autogen/types.js";
2
- declare const updateServiceDeskRequest: jiraUpdateServiceDeskRequestFunction;
3
- export default updateServiceDeskRequest;
@@ -1,72 +0,0 @@
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
- import { axiosClient } from "../../util/axiosClient.js";
11
- const updateServiceDeskRequest = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
12
- const { issueId, requestTypeId, summary, description, priority, customFields } = params;
13
- const { authToken, cloudId, baseUrl } = authParams;
14
- if (!cloudId || !authToken) {
15
- throw new Error("Valid Cloud ID and auth token are required to update service desk request");
16
- }
17
- // Use the regular Jira API for updating service desk requests as they are still Jira issues
18
- const apiUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${issueId}`;
19
- const formattedDescription = description
20
- ? {
21
- type: "doc",
22
- version: 1,
23
- content: [
24
- {
25
- type: "paragraph",
26
- content: [
27
- {
28
- type: "text",
29
- text: description,
30
- },
31
- ],
32
- },
33
- ],
34
- }
35
- : undefined;
36
- const payload = {
37
- fields: Object.assign(Object.assign(Object.assign(Object.assign({}, (summary && { summary })), (formattedDescription && { description: formattedDescription })), (priority && { priority: { name: priority } })), (customFields && Object.assign({}, customFields))),
38
- };
39
- try {
40
- yield axiosClient.put(apiUrl, payload, {
41
- headers: {
42
- Authorization: `Bearer ${authToken}`,
43
- Accept: "application/json",
44
- "Content-Type": "application/json",
45
- },
46
- });
47
- // Get the updated issue details to return current status and web link
48
- const getResponse = yield axiosClient.get(apiUrl, {
49
- headers: {
50
- Authorization: `Bearer ${authToken}`,
51
- Accept: "application/json",
52
- },
53
- });
54
- const issueKey = getResponse.data.key;
55
- const currentStatus = getResponse.data.fields.status.name;
56
- const webLink = `${baseUrl}/browse/${issueKey}`;
57
- return {
58
- success: true,
59
- issueKey,
60
- webLink,
61
- currentStatus,
62
- };
63
- }
64
- catch (error) {
65
- console.error("Error updating service desk request:", error);
66
- return {
67
- success: false,
68
- error: error instanceof Error ? error.message : "Unknown error",
69
- };
70
- }
71
- });
72
- export default updateServiceDeskRequest;