@credal/actions 0.2.110 → 0.2.111
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.
|
@@ -9,6 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { WebClient } from "@slack/web-api";
|
|
11
11
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
12
|
+
import pLimit from "p-limit";
|
|
13
|
+
const HIT_ENRICH_POOL = 10;
|
|
14
|
+
const limitHit = pLimit(HIT_ENRICH_POOL);
|
|
12
15
|
/* ===================== Helpers ===================== */
|
|
13
16
|
function normalizeChannelOperand(ch) {
|
|
14
17
|
const s = ch.trim();
|
|
@@ -32,17 +35,22 @@ function timeFilter(range) {
|
|
|
32
35
|
}
|
|
33
36
|
function lookupUserIdsByEmail(client, emails) {
|
|
34
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
var _a;
|
|
36
38
|
const ids = [];
|
|
37
|
-
|
|
39
|
+
const tasks = emails.map((raw) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
38
41
|
const email = raw.trim();
|
|
39
42
|
if (!email)
|
|
40
|
-
|
|
43
|
+
return null;
|
|
41
44
|
const res = yield client.users.lookupByEmail({ email });
|
|
42
45
|
const id = (_a = res.user) === null || _a === void 0 ? void 0 : _a.id;
|
|
43
46
|
if (id)
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
return id;
|
|
48
|
+
return null;
|
|
49
|
+
}));
|
|
50
|
+
const settled = yield Promise.allSettled(tasks);
|
|
51
|
+
for (const r of settled)
|
|
52
|
+
if (r.status === "fulfilled" && r.value)
|
|
53
|
+
ids.push(r.value);
|
|
46
54
|
return ids;
|
|
47
55
|
});
|
|
48
56
|
}
|
|
@@ -119,7 +127,7 @@ function fetchContextWindow(client, channel, ts) {
|
|
|
119
127
|
}
|
|
120
128
|
/* ===================== Main Export ===================== */
|
|
121
129
|
const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
122
|
-
var _b, _c
|
|
130
|
+
var _b, _c;
|
|
123
131
|
if (!authParams.authToken) {
|
|
124
132
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
125
133
|
}
|
|
@@ -128,13 +136,17 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
128
136
|
const parts = [];
|
|
129
137
|
if (emails === null || emails === void 0 ? void 0 : emails.length) {
|
|
130
138
|
const userIds = yield lookupUserIdsByEmail(client, emails);
|
|
131
|
-
|
|
139
|
+
const { user_id: myUserId } = yield client.auth.test();
|
|
140
|
+
if (!myUserId)
|
|
141
|
+
throw new Error("Failed to get my user ID.");
|
|
142
|
+
const userIdsWithoutMe = userIds.filter(id => id !== myUserId);
|
|
143
|
+
if (userIdsWithoutMe.length === 0)
|
|
132
144
|
throw new Error("No users resolved from emails.");
|
|
133
|
-
if (
|
|
134
|
-
parts.push(`in:<@${
|
|
145
|
+
if (userIdsWithoutMe.length == 1) {
|
|
146
|
+
parts.push(`in:<@${userIdsWithoutMe[0]}>`);
|
|
135
147
|
}
|
|
136
148
|
else {
|
|
137
|
-
const convoName = yield getMPIMName(client,
|
|
149
|
+
const convoName = yield getMPIMName(client, userIdsWithoutMe);
|
|
138
150
|
parts.push(`in:${convoName}`);
|
|
139
151
|
}
|
|
140
152
|
}
|
|
@@ -161,58 +173,62 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
161
173
|
userId: m.user,
|
|
162
174
|
});
|
|
163
175
|
});
|
|
164
|
-
const
|
|
165
|
-
|
|
176
|
+
const tasks = hits.map(h => limitHit(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
var _a, _b, _c, _d;
|
|
166
178
|
if (!h.ts)
|
|
167
|
-
|
|
179
|
+
return null;
|
|
168
180
|
try {
|
|
169
181
|
const anchor = yield fetchOneMessage(client, h.channelId, h.ts);
|
|
170
182
|
const rootTs = (anchor === null || anchor === void 0 ? void 0 : anchor.thread_ts) || h.ts;
|
|
171
183
|
if (anchor === null || anchor === void 0 ? void 0 : anchor.thread_ts) {
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
results.push({
|
|
184
|
+
// thread: fetch thread + permalink concurrently
|
|
185
|
+
const [thread, permalink] = yield Promise.all([
|
|
186
|
+
fetchThread(client, h.channelId, rootTs),
|
|
187
|
+
getPermalink(client, h.channelId, rootTs),
|
|
188
|
+
]);
|
|
189
|
+
const context = thread.filter(t => t.ts).map(t => ({ ts: t.ts, text: t.text, userId: t.user }));
|
|
190
|
+
return {
|
|
180
191
|
channelId: h.channelId,
|
|
181
192
|
ts: rootTs,
|
|
182
|
-
text: (
|
|
183
|
-
userId: (
|
|
184
|
-
context
|
|
185
|
-
permalink
|
|
186
|
-
}
|
|
193
|
+
text: (_a = anchor.text) !== null && _a !== void 0 ? _a : h.text,
|
|
194
|
+
userId: (_b = anchor.user) !== null && _b !== void 0 ? _b : h.userId,
|
|
195
|
+
context,
|
|
196
|
+
permalink,
|
|
197
|
+
};
|
|
187
198
|
}
|
|
188
199
|
else {
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
results.push({
|
|
200
|
+
// not a thread: fetch context window + permalink concurrently
|
|
201
|
+
const [ctx, permalink] = yield Promise.all([
|
|
202
|
+
fetchContextWindow(client, h.channelId, h.ts),
|
|
203
|
+
getPermalink(client, h.channelId, h.ts),
|
|
204
|
+
]);
|
|
205
|
+
const context = ctx.filter(t => t.ts).map(t => ({ ts: t.ts, text: t.text, userId: t.user }));
|
|
206
|
+
return {
|
|
197
207
|
channelId: h.channelId,
|
|
198
208
|
ts: h.ts,
|
|
199
|
-
text: (
|
|
200
|
-
userId: (
|
|
201
|
-
context
|
|
202
|
-
permalink
|
|
203
|
-
}
|
|
209
|
+
text: (_c = anchor === null || anchor === void 0 ? void 0 : anchor.text) !== null && _c !== void 0 ? _c : h.text,
|
|
210
|
+
userId: (_d = anchor === null || anchor === void 0 ? void 0 : anchor.user) !== null && _d !== void 0 ? _d : h.userId,
|
|
211
|
+
context,
|
|
212
|
+
permalink,
|
|
213
|
+
};
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
|
-
catch (
|
|
207
|
-
|
|
216
|
+
catch (_e) {
|
|
217
|
+
// fallback minimal object; still in parallel
|
|
218
|
+
return {
|
|
208
219
|
channelId: h.channelId,
|
|
209
220
|
ts: h.ts,
|
|
210
221
|
text: h.text,
|
|
211
222
|
userId: h.userId,
|
|
212
223
|
permalink: yield getPermalink(client, h.channelId, h.ts),
|
|
213
|
-
}
|
|
224
|
+
};
|
|
214
225
|
}
|
|
215
|
-
}
|
|
226
|
+
})));
|
|
227
|
+
const settled = yield Promise.allSettled(tasks);
|
|
228
|
+
const results = [];
|
|
229
|
+
for (const r of settled)
|
|
230
|
+
if (r.status === "fulfilled" && r.value)
|
|
231
|
+
results.push(r.value);
|
|
216
232
|
results.sort((a, b) => Number(b.ts) - Number(a.ts));
|
|
217
233
|
return { query, results };
|
|
218
234
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credal/actions",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.111",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI Actions by Credal AI",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"mammoth": "^1.4.27",
|
|
67
67
|
"mongodb": "^6.13.1",
|
|
68
68
|
"node-forge": "^1.3.1",
|
|
69
|
+
"p-limit": "^7.1.1",
|
|
69
70
|
"pdf2json": "^3.1.6",
|
|
70
71
|
"resend": "^4.7.0",
|
|
71
72
|
"snowflake-sdk": "^2.0.2",
|