@sentry/junior 0.117.0 → 0.118.0

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 (66) hide show
  1. package/dist/{agent-hooks-5IK4LPLP.js → agent-hooks-J2FB7XD6.js} +8 -10
  2. package/dist/api/schema/stats.d.ts +22 -0
  3. package/dist/api/schema.d.ts +2 -0
  4. package/dist/api/schema.js +7 -3
  5. package/dist/api/stats.d.ts +16 -0
  6. package/dist/api/user-pages/routes.d.ts +4 -0
  7. package/dist/api.js +179 -18
  8. package/dist/app.js +40 -35
  9. package/dist/{catalog-runtime-MTUYW3AA.js → catalog-runtime-UHHLU53I.js} +5 -5
  10. package/dist/chat/agent/prompt.d.ts +4 -2
  11. package/dist/chat/plugins/user-pages.d.ts +15 -0
  12. package/dist/chat/plugins/viewer-actors.d.ts +6 -0
  13. package/dist/chat/prompt.d.ts +1 -2
  14. package/dist/chat/sandbox/paths.d.ts +2 -0
  15. package/dist/chat/sandbox/sandbox.d.ts +3 -1
  16. package/dist/chat/sandbox/workspace.d.ts +1 -0
  17. package/dist/chat/skills.d.ts +1 -2
  18. package/dist/chat/tools/index.d.ts +4 -1
  19. package/dist/chat/tools/sandbox/file-utils.d.ts +11 -0
  20. package/dist/chat/tools/sandbox/find-files.d.ts +2 -1
  21. package/dist/chat/tools/sandbox/grep.d.ts +2 -1
  22. package/dist/{chunk-5O3JDQDG.js → chunk-3LGCVRBQ.js} +1 -1
  23. package/dist/{chunk-WEK3V5RI.js → chunk-3MUSSFMP.js} +17 -19
  24. package/dist/{chunk-KU6ALEJC.js → chunk-3N3FMCKN.js} +30 -2
  25. package/dist/{chunk-FAWBONPC.js → chunk-4LPPH7Y6.js} +5 -7
  26. package/dist/{chunk-W5JEQQEA.js → chunk-4SOQPUF4.js} +1 -1
  27. package/dist/{chunk-LN765Y4N.js → chunk-6BGUAOYP.js} +8 -8
  28. package/dist/{chunk-NHZEUHKH.js → chunk-6K2QE2UI.js} +231 -94
  29. package/dist/{chunk-AKG4TZNH.js → chunk-7GADTCNS.js} +30 -9
  30. package/dist/{chunk-BFIRIZPH.js → chunk-7SM3P4XR.js} +19 -1
  31. package/dist/{chunk-WKU7TY22.js → chunk-FIANEE7Z.js} +3 -1
  32. package/dist/{chunk-RXRQJF7Y.js → chunk-GCGJGSQL.js} +21 -0
  33. package/dist/{chunk-STUI6NIL.js → chunk-GT2ZUALJ.js} +511 -14
  34. package/dist/{chunk-LUMEBOWC.js → chunk-HN6LFYG3.js} +1 -1
  35. package/dist/{chunk-3GE3F4LT.js → chunk-HWUBBHLK.js} +1 -1
  36. package/dist/{chunk-ZRQUQJUV.js → chunk-KC5EE27Y.js} +3 -3
  37. package/dist/chunk-L72GDKSN.js +37 -0
  38. package/dist/{chunk-72Z3HNTQ.js → chunk-MLZFK4KP.js} +1 -1
  39. package/dist/{chunk-27KWTFP6.js → chunk-PJPKHGLG.js} +5 -7
  40. package/dist/{chunk-DS27ZBSP.js → chunk-PWRFTDTY.js} +1 -1
  41. package/dist/{chunk-WUNPRM76.js → chunk-QWCF4RAC.js} +1 -1
  42. package/dist/{chunk-6G45D3YG.js → chunk-S6R23MFB.js} +12 -16
  43. package/dist/{chunk-CU7HTGNI.js → chunk-UXLYAVYL.js} +1 -1
  44. package/dist/cli/chat.js +23 -24
  45. package/dist/cli/check.js +6 -6
  46. package/dist/cli/plugins.js +12 -14
  47. package/dist/cli/snapshot-create.js +8 -9
  48. package/dist/cli/upgrade.js +7 -7
  49. package/dist/db/schema/stats.d.ts +93 -0
  50. package/dist/db/schema.d.ts +94 -1
  51. package/dist/{db-J2ITKS63.js → db-PMRHFSYL.js} +6 -6
  52. package/dist/instrumentation.js +2 -2
  53. package/dist/nitro.js +3 -3
  54. package/dist/{oauth-callback-server-NQYKBT24.js → oauth-callback-server-QJUC7S4X.js} +15 -17
  55. package/dist/{plugins-IUJA4VBU.js → plugins-HW4VWW6G.js} +1 -1
  56. package/dist/{runner-53V5GIQM.js → runner-PZMV6JQW.js} +10 -12
  57. package/dist/{skills-BU3ZMLVB.js → skills-W4JETYSV.js} +6 -6
  58. package/dist/stats.d.ts +18 -0
  59. package/dist/{validation-74EIKKE6.js → validation-IJLNHZSU.js} +6 -6
  60. package/dist/version.js +1 -1
  61. package/migrations/0011_sour_golden_guardian.sql +8 -0
  62. package/migrations/meta/0011_snapshot.json +1195 -0
  63. package/migrations/meta/_journal.json +8 -1
  64. package/package.json +5 -5
  65. package/dist/chunk-4ZNGQH7C.js +0 -25
  66. package/dist/chunk-YRWJ3KEU.js +0 -517
@@ -78,6 +78,13 @@
78
78
  "when": 1785211716838,
79
79
  "tag": "0010_native_conversation_history",
80
80
  "breakpoints": true
81
+ },
82
+ {
83
+ "idx": 11,
84
+ "version": "7",
85
+ "when": 1785271740428,
86
+ "tag": "0011_sour_golden_guardian",
87
+ "breakpoints": true
81
88
  }
82
89
  ]
83
- }
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.117.0",
3
+ "version": "0.118.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -78,7 +78,7 @@
78
78
  "pg": "^8.16.3",
79
79
  "yaml": "^2.9.0",
80
80
  "zod": "^4.4.3",
81
- "@sentry/junior-plugin-api": "0.117.0"
81
+ "@sentry/junior-plugin-api": "0.118.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@emnapi/core": "^1.10.0",
@@ -95,9 +95,9 @@
95
95
  "typescript": "^6.0.3",
96
96
  "vercel": "^54.4.0",
97
97
  "vitest": "^4.1.7",
98
- "@sentry/junior-github": "0.117.0",
99
- "@sentry/junior-memory": "0.117.0",
100
- "@sentry/junior-scheduler": "0.117.0",
98
+ "@sentry/junior-github": "0.118.0",
99
+ "@sentry/junior-scheduler": "0.118.0",
100
+ "@sentry/junior-memory": "0.118.0",
101
101
  "@sentry/junior-testing": "0.0.0"
102
102
  },
103
103
  "scripts": {
@@ -1,25 +0,0 @@
1
- // src/chat/sleep.ts
2
- function sleep(ms, signal) {
3
- if (!signal) {
4
- return new Promise((resolve) => setTimeout(resolve, ms));
5
- }
6
- return new Promise((resolve, reject) => {
7
- if (signal.aborted) {
8
- reject(signal.reason);
9
- return;
10
- }
11
- const timeoutId = setTimeout(() => {
12
- signal.removeEventListener("abort", onAbort);
13
- resolve();
14
- }, ms);
15
- const onAbort = () => {
16
- clearTimeout(timeoutId);
17
- reject(signal.reason);
18
- };
19
- signal.addEventListener("abort", onAbort, { once: true });
20
- });
21
- }
22
-
23
- export {
24
- sleep
25
- };
@@ -1,517 +0,0 @@
1
- import {
2
- juniorConversationAnnotations
3
- } from "./chunk-RXRQJF7Y.js";
4
- import {
5
- sleep
6
- } from "./chunk-4ZNGQH7C.js";
7
- import {
8
- getSlackBotToken
9
- } from "./chunk-DS27ZBSP.js";
10
- import {
11
- logWarn,
12
- setSpanAttributes,
13
- setSpanStatus,
14
- withSpan
15
- } from "./chunk-72Z3HNTQ.js";
16
- import {
17
- parseSlackChannelReferenceId
18
- } from "./chunk-F3B2YJ76.js";
19
-
20
- // src/chat/plugins/annotations.ts
21
- import { and, desc, eq } from "drizzle-orm";
22
- import {
23
- conversationAnnotationInputSchema
24
- } from "@sentry/junior-plugin-api";
25
- function createPluginAnnotations(args) {
26
- return {
27
- async upsert(input) {
28
- const annotation = conversationAnnotationInputSchema.parse(input);
29
- const now = /* @__PURE__ */ new Date();
30
- await args.db.insert(juniorConversationAnnotations).values({
31
- annotation,
32
- conversationId: args.conversationId,
33
- createdAt: now,
34
- key: annotation.key,
35
- kind: annotation.kind,
36
- plugin: args.plugin,
37
- updatedAt: now
38
- }).onConflictDoUpdate({
39
- target: [
40
- juniorConversationAnnotations.conversationId,
41
- juniorConversationAnnotations.plugin,
42
- juniorConversationAnnotations.kind,
43
- juniorConversationAnnotations.key
44
- ],
45
- set: { annotation, updatedAt: now }
46
- });
47
- },
48
- async remove(kind, key) {
49
- await args.db.delete(juniorConversationAnnotations).where(
50
- and(
51
- eq(
52
- juniorConversationAnnotations.conversationId,
53
- args.conversationId
54
- ),
55
- eq(juniorConversationAnnotations.plugin, args.plugin),
56
- eq(juniorConversationAnnotations.kind, kind),
57
- eq(juniorConversationAnnotations.key, key)
58
- )
59
- );
60
- },
61
- async list() {
62
- return (await listConversationAnnotations(args.db, args.conversationId)).filter((a) => a.plugin === args.plugin);
63
- }
64
- };
65
- }
66
- async function listConversationAnnotations(db, conversationId) {
67
- const rows = await db.select().from(juniorConversationAnnotations).where(eq(juniorConversationAnnotations.conversationId, conversationId)).orderBy(desc(juniorConversationAnnotations.updatedAt));
68
- return rows.flatMap((row) => {
69
- const parsed = conversationAnnotationInputSchema.safeParse(row.annotation);
70
- return parsed.success ? [
71
- {
72
- ...parsed.data,
73
- plugin: row.plugin,
74
- createdAt: row.createdAt.toISOString(),
75
- updatedAt: row.updatedAt.toISOString()
76
- }
77
- ] : [];
78
- });
79
- }
80
-
81
- // src/chat/slack/client.ts
82
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
83
- import { WebClient } from "@slack/web-api";
84
-
85
- // src/chat/slack/workspace-context.ts
86
- import { AsyncLocalStorage } from "async_hooks";
87
- var workspaceTeamIdStorage = new AsyncLocalStorage();
88
- function runWithWorkspaceTeamId(teamId, fn) {
89
- if (!teamId) return fn();
90
- return workspaceTeamIdStorage.run(teamId, fn);
91
- }
92
- function getWorkspaceTeamId() {
93
- return workspaceTeamIdStorage.getStore();
94
- }
95
-
96
- // src/chat/slack/client.ts
97
- var SlackActionError = class extends Error {
98
- code;
99
- apiError;
100
- needed;
101
- provided;
102
- statusCode;
103
- requestId;
104
- errorData;
105
- retryAfterSeconds;
106
- detail;
107
- detailLine;
108
- detailRule;
109
- constructor(message, code, options = {}) {
110
- super(message);
111
- this.name = "SlackActionError";
112
- this.code = code;
113
- this.apiError = options.apiError;
114
- this.needed = options.needed;
115
- this.provided = options.provided;
116
- this.statusCode = options.statusCode;
117
- this.requestId = options.requestId;
118
- this.errorData = options.errorData;
119
- this.retryAfterSeconds = options.retryAfterSeconds;
120
- this.detail = options.detail;
121
- this.detailLine = options.detailLine;
122
- this.detailRule = options.detailRule;
123
- }
124
- };
125
- function serializeSlackErrorData(data) {
126
- if (!data || typeof data !== "object") {
127
- return void 0;
128
- }
129
- const filtered = Object.fromEntries(
130
- Object.entries(data).filter(
131
- ([key]) => key !== "error"
132
- )
133
- );
134
- if (Object.keys(filtered).length === 0) {
135
- return void 0;
136
- }
137
- try {
138
- const serialized = JSON.stringify(filtered);
139
- return serialized.length <= 600 ? serialized : `${serialized.slice(0, 597)}...`;
140
- } catch {
141
- return void 0;
142
- }
143
- }
144
- function getHeaderString(headers, name) {
145
- if (!headers || typeof headers !== "object") {
146
- return void 0;
147
- }
148
- const key = name.toLowerCase();
149
- const entries = headers;
150
- for (const [entryKey, value] of Object.entries(entries)) {
151
- if (entryKey.toLowerCase() !== key) continue;
152
- if (typeof value === "string") return value;
153
- if (Array.isArray(value)) {
154
- const first = value.find((entry) => typeof entry === "string");
155
- return typeof first === "string" ? first : void 0;
156
- }
157
- }
158
- return void 0;
159
- }
160
- function parseSlackCanvasDetail(detail) {
161
- if (typeof detail !== "string") {
162
- return {};
163
- }
164
- const trimmed = detail.trim();
165
- if (!trimmed) {
166
- return {};
167
- }
168
- const parsed = {
169
- detail: trimmed
170
- };
171
- const lineMatch = trimmed.match(/line\s+(\d+):/i);
172
- if (lineMatch) {
173
- const line = Number.parseInt(lineMatch[1] ?? "", 10);
174
- if (Number.isFinite(line)) {
175
- parsed.detailLine = line;
176
- }
177
- }
178
- if (/unsupported heading depth/i.test(trimmed)) {
179
- parsed.detailRule = "unsupported_heading_depth";
180
- }
181
- return parsed;
182
- }
183
- var installationTokenStorage = new AsyncLocalStorage2();
184
- var clientsByToken = /* @__PURE__ */ new Map();
185
- function runWithSlackInstallationToken(token, fn) {
186
- const trimmed = token.trim();
187
- if (!trimmed) {
188
- throw new SlackActionError(
189
- "Slack installation token binding requires a non-empty token",
190
- "missing_token"
191
- );
192
- }
193
- return installationTokenStorage.run({ token: trimmed }, fn);
194
- }
195
- function resolveSlackToken() {
196
- const ambientToken = installationTokenStorage.getStore()?.token;
197
- if (ambientToken) {
198
- return ambientToken;
199
- }
200
- const envToken = getSlackBotToken();
201
- if (envToken) {
202
- return envToken;
203
- }
204
- const teamId = getWorkspaceTeamId();
205
- if (teamId) {
206
- throw new SlackActionError(
207
- `Slack call is scoped to workspace ${teamId} but no installation token is bound and no default bot token is configured`,
208
- "missing_token"
209
- );
210
- }
211
- throw new SlackActionError(
212
- "SLACK_BOT_TOKEN (or SLACK_BOT_USER_TOKEN) is required for Slack Web API actions in this service",
213
- "missing_token"
214
- );
215
- }
216
- function normalizeSlackConversationId(channelId) {
217
- return parseSlackChannelReferenceId(channelId);
218
- }
219
- function getClient() {
220
- const token = resolveSlackToken();
221
- let cached = clientsByToken.get(token);
222
- if (!cached) {
223
- cached = new WebClient(token, {
224
- retryConfig: { retries: 0 },
225
- rejectRateLimitedCalls: true
226
- });
227
- clientsByToken.set(token, cached);
228
- }
229
- return cached;
230
- }
231
- function mapSlackError(error) {
232
- if (error instanceof SlackActionError) {
233
- return error;
234
- }
235
- const candidate = error;
236
- const apiError = candidate.data?.error;
237
- const message = candidate.message ?? "Slack action failed";
238
- const baseOptions = {
239
- apiError,
240
- statusCode: candidate.statusCode,
241
- requestId: getHeaderString(candidate.headers, "x-slack-req-id"),
242
- errorData: serializeSlackErrorData(candidate.data),
243
- ...parseSlackCanvasDetail(candidate.data?.detail)
244
- };
245
- if (apiError === "missing_scope") {
246
- return new SlackActionError(message, "missing_scope", {
247
- ...baseOptions,
248
- needed: candidate.data?.needed,
249
- provided: candidate.data?.provided
250
- });
251
- }
252
- if (apiError === "not_in_channel") {
253
- return new SlackActionError(message, "not_in_channel", baseOptions);
254
- }
255
- if (apiError === "restricted_action_read_only_channel") {
256
- return new SlackActionError(message, "read_only_channel", baseOptions);
257
- }
258
- if (apiError === "already_reacted") {
259
- return new SlackActionError(message, "already_reacted", baseOptions);
260
- }
261
- if (apiError === "no_reaction") {
262
- return new SlackActionError(message, "no_reaction", baseOptions);
263
- }
264
- if (apiError === "invalid_arguments") {
265
- return new SlackActionError(message, "invalid_arguments", baseOptions);
266
- }
267
- if (apiError === "invalid_cursor") {
268
- return new SlackActionError(message, "invalid_arguments", baseOptions);
269
- }
270
- if (apiError === "invalid_name") {
271
- return new SlackActionError(message, "invalid_arguments", baseOptions);
272
- }
273
- if (apiError === "not_found" || apiError === "channel_not_found" || apiError === "message_not_found") {
274
- return new SlackActionError(message, "not_found", baseOptions);
275
- }
276
- if (apiError === "feature_not_enabled" || apiError === "not_allowed_token_type") {
277
- return new SlackActionError(message, "feature_unavailable", baseOptions);
278
- }
279
- if (apiError === "canvas_creation_failed") {
280
- return new SlackActionError(message, "canvas_creation_failed", baseOptions);
281
- }
282
- if (apiError === "canvas_editing_failed") {
283
- return new SlackActionError(message, "canvas_editing_failed", baseOptions);
284
- }
285
- if (candidate.code === "slack_webapi_rate_limited_error" || candidate.statusCode === 429) {
286
- return new SlackActionError(message, "rate_limited", {
287
- ...baseOptions,
288
- retryAfterSeconds: candidate.retryAfter
289
- });
290
- }
291
- return new SlackActionError(message, "internal_error", baseOptions);
292
- }
293
- var MAX_RETRY_DELAY_MS = 1e4;
294
- var MAX_TOTAL_RETRY_DELAY_MS = 2e4;
295
- var CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
296
- "ECONNREFUSED",
297
- "ECONNRESET",
298
- "ENOTFOUND",
299
- "EAI_AGAIN"
300
- ]);
301
- var TIMEOUT_ERROR_CODES = /* @__PURE__ */ new Set([
302
- "ETIMEDOUT",
303
- "ECONNABORTED",
304
- "ESOCKETTIMEDOUT"
305
- ]);
306
- function findNetworkErrorCode(error, depth = 0) {
307
- if (!error || typeof error !== "object" || depth > 4) {
308
- return void 0;
309
- }
310
- const candidate = error;
311
- if (typeof candidate.code === "string" && (CONNECTION_ERROR_CODES.has(candidate.code) || TIMEOUT_ERROR_CODES.has(candidate.code))) {
312
- return candidate.code;
313
- }
314
- return findNetworkErrorCode(candidate.original, depth + 1) ?? findNetworkErrorCode(candidate.cause, depth + 1);
315
- }
316
- function hasSocketHangUpMessage(error) {
317
- return error instanceof Error && error.message.toLowerCase().includes("socket hang up");
318
- }
319
- function classifySlackRetry(raw, mapped) {
320
- if (mapped.code === "rate_limited") {
321
- return "rate_limited";
322
- }
323
- if (mapped.statusCode !== void 0 && mapped.statusCode >= 500) {
324
- return "server_error";
325
- }
326
- const networkCode = findNetworkErrorCode(raw);
327
- if (networkCode && CONNECTION_ERROR_CODES.has(networkCode)) {
328
- return "connection";
329
- }
330
- if (networkCode && TIMEOUT_ERROR_CODES.has(networkCode)) {
331
- return "timeout";
332
- }
333
- if (hasSocketHangUpMessage(raw)) {
334
- return "connection";
335
- }
336
- return "none";
337
- }
338
- async function withSlackRetries(task, maxAttempts = 3, context = {}) {
339
- let attempt = 0;
340
- let totalDelayMs = 0;
341
- const action = context.action ?? "unknown";
342
- while (attempt < maxAttempts) {
343
- attempt += 1;
344
- const attemptNumber = attempt;
345
- try {
346
- return await withSpan(
347
- `POST slack.com/api/${action}`,
348
- "http.client",
349
- {},
350
- async () => {
351
- try {
352
- return await task();
353
- } catch (error) {
354
- const mapped = mapSlackError(error);
355
- const errorAttrs = {
356
- "error.type": mapped.code
357
- };
358
- if (mapped.apiError) {
359
- errorAttrs["app.slack.api_error_code"] = mapped.apiError;
360
- }
361
- if (mapped.code === "rate_limited") {
362
- errorAttrs["http.response.status_code"] = 429;
363
- if (mapped.retryAfterSeconds) {
364
- errorAttrs["app.slack.retry_after_ms"] = mapped.retryAfterSeconds * 1e3;
365
- }
366
- } else if (mapped.statusCode != null) {
367
- errorAttrs["http.response.status_code"] = mapped.statusCode;
368
- }
369
- setSpanAttributes(errorAttrs);
370
- setSpanStatus("error");
371
- throw error;
372
- }
373
- },
374
- {
375
- "http.request.method": "POST",
376
- "server.address": "slack.com",
377
- "url.scheme": "https",
378
- "url.path": `/api/${action}`,
379
- "app.slack.method": action,
380
- "app.retry.max_attempts": maxAttempts,
381
- ...attemptNumber > 1 ? { "http.resend_count": attemptNumber - 1 } : {},
382
- ...context.attributes ?? {},
383
- ...context.spanAttributes ?? {}
384
- }
385
- );
386
- } catch (error) {
387
- const mapped = mapSlackError(error);
388
- const retryClass = classifySlackRetry(error, mapped);
389
- const isRetryable = retryClass === "rate_limited" || retryClass === "connection" || retryClass === "server_error" || retryClass === "timeout" && context.idempotent === true;
390
- const remainingDelayBudgetMs = MAX_TOTAL_RETRY_DELAY_MS - totalDelayMs;
391
- const baseLogAttributes = {
392
- "app.slack.action": action,
393
- "app.slack.error_code": mapped.code,
394
- ...mapped.apiError ? { "app.slack.api_error": mapped.apiError } : {},
395
- ...mapped.detail ? { "app.slack.detail": mapped.detail } : {},
396
- ...mapped.detailLine !== void 0 ? { "app.slack.detail_line": mapped.detailLine } : {},
397
- ...mapped.detailRule ? { "app.slack.detail_rule": mapped.detailRule } : {},
398
- ...mapped.requestId ? { "app.slack.request_id": mapped.requestId } : {},
399
- ...mapped.statusCode !== void 0 ? { "http.response.status_code": mapped.statusCode } : {},
400
- ...context.attributes ?? {}
401
- };
402
- if (!isRetryable || attempt >= maxAttempts || remainingDelayBudgetMs <= 0) {
403
- logWarn(
404
- "slack_action_failed",
405
- {},
406
- {
407
- ...baseLogAttributes,
408
- ...mapped.errorData ? { "app.slack.error_data": mapped.errorData } : {}
409
- },
410
- "Slack action failed"
411
- );
412
- throw mapped;
413
- }
414
- logWarn(
415
- "slack_action_retrying",
416
- {},
417
- {
418
- ...baseLogAttributes,
419
- "app.slack.retry_attempt": attempt,
420
- "app.slack.retry_class": retryClass
421
- },
422
- "Retrying Slack action after transient failure"
423
- );
424
- const retryAfterMs = retryClass === "rate_limited" && mapped.retryAfterSeconds && mapped.retryAfterSeconds > 0 ? mapped.retryAfterSeconds * 1e3 : void 0;
425
- const backoffMs = Math.min(2e3, 250 * 2 ** (attempt - 1));
426
- const delayMs = Math.min(
427
- retryAfterMs ?? backoffMs,
428
- MAX_RETRY_DELAY_MS,
429
- remainingDelayBudgetMs
430
- );
431
- totalDelayMs += delayMs;
432
- await sleep(delayMs);
433
- }
434
- }
435
- throw new SlackActionError(
436
- "Slack action exhausted retries",
437
- "internal_error"
438
- );
439
- }
440
- function getSlackClient() {
441
- return getClient();
442
- }
443
- function isDmChannel(channelId) {
444
- const normalized = normalizeSlackConversationId(channelId);
445
- return Boolean(normalized && normalized.startsWith("D"));
446
- }
447
- function isConversationScopedChannel(channelId) {
448
- const normalized = normalizeSlackConversationId(channelId);
449
- if (!normalized) return false;
450
- return normalized.startsWith("C") || normalized.startsWith("G") || normalized.startsWith("D");
451
- }
452
- function isConversationChannel(channelId) {
453
- const normalized = normalizeSlackConversationId(channelId);
454
- if (!normalized) return false;
455
- return normalized.startsWith("C") || normalized.startsWith("G");
456
- }
457
- async function getFilePermalink(fileId) {
458
- const client = getClient();
459
- const response = await withSlackRetries(
460
- () => client.files.info({
461
- file: fileId
462
- }),
463
- 3,
464
- {
465
- action: "files.info",
466
- idempotent: true,
467
- spanAttributes: { "app.slack.file_id": fileId }
468
- }
469
- );
470
- return response.file?.permalink;
471
- }
472
- async function downloadPrivateSlackFile(url) {
473
- const token = resolveSlackToken();
474
- return withSpan(
475
- "GET files.slack.com",
476
- "http.client",
477
- {},
478
- async () => {
479
- const response = await fetch(url, {
480
- headers: {
481
- Authorization: `Bearer ${token}`
482
- }
483
- });
484
- setSpanAttributes({ "http.response.status_code": response.status });
485
- if (!response.ok) {
486
- setSpanAttributes({ "error.type": String(response.status) });
487
- setSpanStatus("error");
488
- throw new Error(`Slack file download failed: ${response.status}`);
489
- }
490
- return Buffer.from(await response.arrayBuffer());
491
- },
492
- {
493
- "http.request.method": "GET",
494
- "server.address": "files.slack.com",
495
- "url.scheme": "https",
496
- "app.slack.method": "files.download"
497
- }
498
- );
499
- }
500
-
501
- export {
502
- createPluginAnnotations,
503
- listConversationAnnotations,
504
- runWithWorkspaceTeamId,
505
- getWorkspaceTeamId,
506
- SlackActionError,
507
- getHeaderString,
508
- runWithSlackInstallationToken,
509
- normalizeSlackConversationId,
510
- withSlackRetries,
511
- getSlackClient,
512
- isDmChannel,
513
- isConversationScopedChannel,
514
- isConversationChannel,
515
- getFilePermalink,
516
- downloadPrivateSlackFile
517
- };