@sentry/junior 0.9.3 → 0.9.4

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.
@@ -1,13 +1,3 @@
1
- import {
2
- discoverSkills,
3
- findSkillByName,
4
- getCapabilityProvider,
5
- listCapabilityProviders,
6
- loadSkillsByName,
7
- logCapabilityCatalogLoadedOnce,
8
- parseSkillInvocation,
9
- stripFrontmatter
10
- } from "./chunk-VM3CPAZF.js";
11
1
  import {
12
2
  SANDBOX_SKILLS_ROOT,
13
3
  SANDBOX_WORKSPACE_ROOT,
@@ -27,28 +17,31 @@ import {
27
17
  runNonInteractiveCommand,
28
18
  sandboxSkillDir,
29
19
  toOptionalTrimmed
30
- } from "./chunk-HRA2FXYH.js";
20
+ } from "./chunk-FS5Y4CF2.js";
21
+ import {
22
+ discoverSkills,
23
+ findSkillByName,
24
+ getCapabilityProvider,
25
+ listCapabilityProviders,
26
+ loadSkillsByName,
27
+ logCapabilityCatalogLoadedOnce,
28
+ parseSkillInvocation,
29
+ stripFrontmatter
30
+ } from "./chunk-WM66QDLA.js";
31
31
  import {
32
32
  CredentialUnavailableError,
33
33
  createPluginBroker,
34
+ extractGenAiUsageAttributes,
34
35
  getPluginDefinition,
35
36
  getPluginMcpProviders,
36
37
  getPluginOAuthConfig,
37
38
  getPluginProviders,
38
39
  isPluginProvider,
39
- resolveAuthTokenPlaceholder
40
- } from "./chunk-ZBWWHP6Q.js";
41
- import {
42
- aboutPathCandidates,
43
- homeDir,
44
- soulPathCandidates
45
- } from "./chunk-KCLEEKYX.js";
46
- import {
47
- extractGenAiUsageAttributes,
48
40
  logError,
49
41
  logException,
50
42
  logInfo,
51
43
  logWarn,
44
+ resolveAuthTokenPlaceholder,
52
45
  resolveErrorReference,
53
46
  serializeGenAiAttribute,
54
47
  setSpanAttributes,
@@ -57,7 +50,109 @@ import {
57
50
  toOptionalString,
58
51
  withContext,
59
52
  withSpan
60
- } from "./chunk-ZW4OVKF5.js";
53
+ } from "./chunk-MY7JNCS2.js";
54
+ import {
55
+ aboutPathCandidates,
56
+ homeDir,
57
+ soulPathCandidates
58
+ } from "./chunk-KCLEEKYX.js";
59
+
60
+ // src/chat/queue/errors.ts
61
+ var DeferredThreadMessageError = class extends Error {
62
+ code = "deferred_thread_message";
63
+ reason;
64
+ constructor(reason, threadId, details) {
65
+ if (reason === "thread_locked") {
66
+ super(
67
+ `Queue message deferred because thread ${threadId} is already locked`
68
+ );
69
+ } else {
70
+ super(
71
+ `Queue message deferred for thread ${threadId} because activeTurnId=${details?.activeTurnId ?? "unknown"} is still in progress for currentTurnId=${details?.currentTurnId ?? "unknown"}`
72
+ );
73
+ }
74
+ this.name = "DeferredThreadMessageError";
75
+ this.reason = reason;
76
+ }
77
+ };
78
+ function isDeferredThreadMessageError(error, reason) {
79
+ if (!(error instanceof DeferredThreadMessageError)) {
80
+ return false;
81
+ }
82
+ if (!reason) {
83
+ return true;
84
+ }
85
+ return error.reason === reason;
86
+ }
87
+
88
+ // src/chat/queue/transport.ts
89
+ import { handleCallback, send } from "@vercel/queue";
90
+ async function sendQueueMessage(topicName, payload, options) {
91
+ const result = await send(topicName, payload, {
92
+ ...options?.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}
93
+ });
94
+ return result.messageId ?? void 0;
95
+ }
96
+ function createTransportCallbackHandler(handler, options) {
97
+ return handleCallback(
98
+ async (message, metadata) => {
99
+ await handler(message, {
100
+ messageId: metadata.messageId,
101
+ deliveryCount: metadata.deliveryCount,
102
+ topicName: metadata.topicName
103
+ });
104
+ },
105
+ options ? {
106
+ retry: options.retry ? (error, metadata) => options.retry?.(error, {
107
+ messageId: metadata.messageId,
108
+ deliveryCount: metadata.deliveryCount,
109
+ topicName: metadata.topicName
110
+ }) : void 0
111
+ } : void 0
112
+ );
113
+ }
114
+
115
+ // src/chat/queue/client.ts
116
+ var THREAD_MESSAGE_TOPIC = "junior-thread-message";
117
+ var MAX_DELIVERY_ATTEMPTS = 10;
118
+ var THREAD_LOCK_RETRY_MAX_SECONDS = 30;
119
+ var ACTIVE_TURN_RETRY_MAX_SECONDS = 300;
120
+ function getThreadMessageTopic() {
121
+ return THREAD_MESSAGE_TOPIC;
122
+ }
123
+ async function enqueueThreadMessage(payload, options) {
124
+ return await sendQueueMessage(getThreadMessageTopic(), payload, options);
125
+ }
126
+ function createQueueCallbackHandler(handler) {
127
+ return createTransportCallbackHandler(handler, {
128
+ retry: (error, metadata) => {
129
+ if (isDeferredThreadMessageError(error, "thread_locked")) {
130
+ return {
131
+ afterSeconds: Math.min(
132
+ THREAD_LOCK_RETRY_MAX_SECONDS,
133
+ Math.max(5, metadata.deliveryCount * 5)
134
+ )
135
+ };
136
+ }
137
+ if (isDeferredThreadMessageError(error, "active_turn")) {
138
+ return {
139
+ afterSeconds: Math.min(
140
+ ACTIVE_TURN_RETRY_MAX_SECONDS,
141
+ Math.max(30, metadata.deliveryCount * 30)
142
+ )
143
+ };
144
+ }
145
+ if (metadata.deliveryCount >= MAX_DELIVERY_ATTEMPTS) {
146
+ return { acknowledge: true };
147
+ }
148
+ const backoffSeconds = Math.min(
149
+ 300,
150
+ Math.max(5, metadata.deliveryCount * 5)
151
+ );
152
+ return { afterSeconds: backoffSeconds };
153
+ }
154
+ });
155
+ }
61
156
 
62
157
  // src/chat/app/production.ts
63
158
  import { createSlackAdapter } from "@chat-adapter/slack";
@@ -11415,103 +11510,6 @@ import {
11415
11510
  Chat
11416
11511
  } from "chat";
11417
11512
 
11418
- // src/chat/queue/errors.ts
11419
- var DeferredThreadMessageError = class extends Error {
11420
- code = "deferred_thread_message";
11421
- reason;
11422
- constructor(reason, threadId, details) {
11423
- if (reason === "thread_locked") {
11424
- super(
11425
- `Queue message deferred because thread ${threadId} is already locked`
11426
- );
11427
- } else {
11428
- super(
11429
- `Queue message deferred for thread ${threadId} because activeTurnId=${details?.activeTurnId ?? "unknown"} is still in progress for currentTurnId=${details?.currentTurnId ?? "unknown"}`
11430
- );
11431
- }
11432
- this.name = "DeferredThreadMessageError";
11433
- this.reason = reason;
11434
- }
11435
- };
11436
- function isDeferredThreadMessageError(error, reason) {
11437
- if (!(error instanceof DeferredThreadMessageError)) {
11438
- return false;
11439
- }
11440
- if (!reason) {
11441
- return true;
11442
- }
11443
- return error.reason === reason;
11444
- }
11445
-
11446
- // src/chat/queue/transport.ts
11447
- import { handleCallback, send } from "@vercel/queue";
11448
- async function sendQueueMessage(topicName, payload, options) {
11449
- const result = await send(topicName, payload, {
11450
- ...options?.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}
11451
- });
11452
- return result.messageId ?? void 0;
11453
- }
11454
- function createTransportCallbackHandler(handler, options) {
11455
- return handleCallback(
11456
- async (message, metadata) => {
11457
- await handler(message, {
11458
- messageId: metadata.messageId,
11459
- deliveryCount: metadata.deliveryCount,
11460
- topicName: metadata.topicName
11461
- });
11462
- },
11463
- options ? {
11464
- retry: options.retry ? (error, metadata) => options.retry?.(error, {
11465
- messageId: metadata.messageId,
11466
- deliveryCount: metadata.deliveryCount,
11467
- topicName: metadata.topicName
11468
- }) : void 0
11469
- } : void 0
11470
- );
11471
- }
11472
-
11473
- // src/chat/queue/client.ts
11474
- var THREAD_MESSAGE_TOPIC = "junior-thread-message";
11475
- var MAX_DELIVERY_ATTEMPTS = 10;
11476
- var THREAD_LOCK_RETRY_MAX_SECONDS = 30;
11477
- var ACTIVE_TURN_RETRY_MAX_SECONDS = 300;
11478
- function getThreadMessageTopic() {
11479
- return THREAD_MESSAGE_TOPIC;
11480
- }
11481
- async function enqueueThreadMessage(payload, options) {
11482
- return await sendQueueMessage(getThreadMessageTopic(), payload, options);
11483
- }
11484
- function createQueueCallbackHandler(handler) {
11485
- return createTransportCallbackHandler(handler, {
11486
- retry: (error, metadata) => {
11487
- if (isDeferredThreadMessageError(error, "thread_locked")) {
11488
- return {
11489
- afterSeconds: Math.min(
11490
- THREAD_LOCK_RETRY_MAX_SECONDS,
11491
- Math.max(5, metadata.deliveryCount * 5)
11492
- )
11493
- };
11494
- }
11495
- if (isDeferredThreadMessageError(error, "active_turn")) {
11496
- return {
11497
- afterSeconds: Math.min(
11498
- ACTIVE_TURN_RETRY_MAX_SECONDS,
11499
- Math.max(30, metadata.deliveryCount * 30)
11500
- )
11501
- };
11502
- }
11503
- if (metadata.deliveryCount >= MAX_DELIVERY_ATTEMPTS) {
11504
- return { acknowledge: true };
11505
- }
11506
- const backoffSeconds = Math.min(
11507
- 300,
11508
- Math.max(5, metadata.deliveryCount * 5)
11509
- );
11510
- return { afterSeconds: backoffSeconds };
11511
- }
11512
- });
11513
- }
11514
-
11515
11513
  // src/chat/state/queue-ingress-store.ts
11516
11514
  var QUEUE_INGRESS_DEDUP_PREFIX = "junior:queue_ingress";
11517
11515
  function queueIngressDedupKey(rawKey) {
@@ -12245,112 +12243,132 @@ async function handleSlashCommand(event) {
12245
12243
  }
12246
12244
 
12247
12245
  // src/chat/app/production.ts
12248
- var bot = new JuniorChat({
12249
- userName: botConfig.userName,
12250
- adapters: {
12251
- slack: (() => {
12252
- const signingSecret = getSlackSigningSecret();
12253
- const botToken = getSlackBotToken();
12254
- const clientId = getSlackClientId();
12255
- const clientSecret = getSlackClientSecret();
12256
- if (!signingSecret) {
12257
- throw new Error("SLACK_SIGNING_SECRET is required");
12258
- }
12259
- return createSlackAdapter({
12260
- signingSecret,
12261
- ...botToken ? { botToken } : {},
12262
- ...clientId ? { clientId } : {},
12263
- ...clientSecret ? { clientSecret } : {}
12264
- });
12265
- })()
12266
- },
12267
- state: getStateAdapter()
12268
- });
12269
- var registerSingleton = bot.registerSingleton;
12270
- if (typeof registerSingleton === "function") {
12271
- registerSingleton.call(bot);
12272
- }
12273
- function getSlackAdapter() {
12274
- return bot.getAdapter("slack");
12275
- }
12276
- var slackRuntime = createSlackRuntime({
12277
- getSlackAdapter
12278
- });
12279
- bot.onNewMention(slackRuntime.handleNewMention);
12280
- bot.onSubscribedMessage(slackRuntime.handleSubscribedMessage);
12281
- bot.onAssistantThreadStarted(
12282
- (event) => slackRuntime.handleAssistantThreadStarted(event)
12283
- );
12284
- bot.onAssistantContextChanged(
12285
- (event) => slackRuntime.handleAssistantContextChanged(event)
12286
- );
12287
- bot.onSlashCommand(
12288
- "/jr",
12289
- (event) => withSpan(
12290
- "chat.slash_command",
12291
- "chat.slash_command",
12292
- { slackUserId: event.user.userId },
12293
- async () => {
12294
- try {
12295
- await handleSlashCommand(event);
12296
- } catch (error) {
12297
- logException(error, "slash_command_failed", {
12298
- slackUserId: event.user.userId
12299
- });
12300
- throw error;
12301
- }
12302
- }
12303
- )
12304
- );
12305
- bot.onAppHomeOpened(
12306
- (event) => withSpan(
12307
- "chat.app_home_opened",
12308
- "chat.app_home_opened",
12309
- { slackUserId: event.userId },
12310
- async () => {
12311
- try {
12312
- await publishAppHomeView(
12313
- getSlackClient(),
12314
- event.userId,
12315
- createUserTokenStore()
12316
- );
12317
- } catch (error) {
12318
- logException(error, "app_home_opened_failed", {
12319
- slackUserId: event.userId
12246
+ var productionBot;
12247
+ var productionSlackRuntime;
12248
+ function createProductionBot() {
12249
+ return new JuniorChat({
12250
+ userName: botConfig.userName,
12251
+ adapters: {
12252
+ slack: (() => {
12253
+ const signingSecret = getSlackSigningSecret();
12254
+ const botToken = getSlackBotToken();
12255
+ const clientId = getSlackClientId();
12256
+ const clientSecret = getSlackClientSecret();
12257
+ if (!signingSecret) {
12258
+ throw new Error("SLACK_SIGNING_SECRET is required");
12259
+ }
12260
+ return createSlackAdapter({
12261
+ signingSecret,
12262
+ ...botToken ? { botToken } : {},
12263
+ ...clientId ? { clientId } : {},
12264
+ ...clientSecret ? { clientSecret } : {}
12320
12265
  });
12266
+ })()
12267
+ },
12268
+ state: getStateAdapter()
12269
+ });
12270
+ }
12271
+ function registerProductionHandlers(bot, slackRuntime) {
12272
+ bot.onNewMention(slackRuntime.handleNewMention);
12273
+ bot.onSubscribedMessage(slackRuntime.handleSubscribedMessage);
12274
+ bot.onAssistantThreadStarted(
12275
+ (event) => slackRuntime.handleAssistantThreadStarted(event)
12276
+ );
12277
+ bot.onAssistantContextChanged(
12278
+ (event) => slackRuntime.handleAssistantContextChanged(event)
12279
+ );
12280
+ bot.onSlashCommand(
12281
+ "/jr",
12282
+ (event) => withSpan(
12283
+ "chat.slash_command",
12284
+ "chat.slash_command",
12285
+ { slackUserId: event.user.userId },
12286
+ async () => {
12287
+ try {
12288
+ await handleSlashCommand(event);
12289
+ } catch (error) {
12290
+ logException(error, "slash_command_failed", {
12291
+ slackUserId: event.user.userId
12292
+ });
12293
+ throw error;
12294
+ }
12321
12295
  }
12322
- }
12323
- )
12324
- );
12325
- bot.onAction("app_home_disconnect", async (event) => {
12326
- const provider = event.value;
12327
- if (!provider) return;
12328
- const userId = event.user.userId;
12329
- await withSpan(
12330
- "chat.app_home_disconnect",
12331
- "chat.app_home_disconnect",
12332
- { slackUserId: userId },
12333
- async () => {
12334
- try {
12335
- await unlinkProvider(userId, provider, createUserTokenStore());
12336
- await publishAppHomeView(
12337
- getSlackClient(),
12338
- userId,
12339
- createUserTokenStore()
12340
- );
12341
- } catch (error) {
12342
- logException(
12343
- error,
12344
- "app_home_disconnect_failed",
12345
- { slackUserId: userId },
12346
- {
12347
- "app.credential.provider": provider
12348
- }
12349
- );
12296
+ )
12297
+ );
12298
+ bot.onAppHomeOpened(
12299
+ (event) => withSpan(
12300
+ "chat.app_home_opened",
12301
+ "chat.app_home_opened",
12302
+ { slackUserId: event.userId },
12303
+ async () => {
12304
+ try {
12305
+ await publishAppHomeView(
12306
+ getSlackClient(),
12307
+ event.userId,
12308
+ createUserTokenStore()
12309
+ );
12310
+ } catch (error) {
12311
+ logException(error, "app_home_opened_failed", {
12312
+ slackUserId: event.userId
12313
+ });
12314
+ }
12350
12315
  }
12351
- }
12316
+ )
12352
12317
  );
12353
- });
12318
+ bot.onAction("app_home_disconnect", async (event) => {
12319
+ const provider = event.value;
12320
+ if (!provider) return;
12321
+ const userId = event.user.userId;
12322
+ await withSpan(
12323
+ "chat.app_home_disconnect",
12324
+ "chat.app_home_disconnect",
12325
+ { slackUserId: userId },
12326
+ async () => {
12327
+ try {
12328
+ await unlinkProvider(userId, provider, createUserTokenStore());
12329
+ await publishAppHomeView(
12330
+ getSlackClient(),
12331
+ userId,
12332
+ createUserTokenStore()
12333
+ );
12334
+ } catch (error) {
12335
+ logException(
12336
+ error,
12337
+ "app_home_disconnect_failed",
12338
+ { slackUserId: userId },
12339
+ {
12340
+ "app.credential.provider": provider
12341
+ }
12342
+ );
12343
+ }
12344
+ }
12345
+ );
12346
+ });
12347
+ }
12348
+ function initializeProductionApp() {
12349
+ if (productionBot && productionSlackRuntime) {
12350
+ return;
12351
+ }
12352
+ const bot = createProductionBot();
12353
+ const registerSingleton = bot.registerSingleton;
12354
+ if (typeof registerSingleton === "function") {
12355
+ registerSingleton.call(bot);
12356
+ }
12357
+ const slackRuntime = createSlackRuntime({
12358
+ getSlackAdapter: () => bot.getAdapter("slack")
12359
+ });
12360
+ registerProductionHandlers(bot, slackRuntime);
12361
+ productionBot = bot;
12362
+ productionSlackRuntime = slackRuntime;
12363
+ }
12364
+ function getProductionBot() {
12365
+ initializeProductionApp();
12366
+ return productionBot;
12367
+ }
12368
+ function getProductionSlackRuntime() {
12369
+ initializeProductionApp();
12370
+ return productionSlackRuntime;
12371
+ }
12354
12372
 
12355
12373
  export {
12356
12374
  coerceThreadConversationState,
@@ -12382,10 +12400,9 @@ export {
12382
12400
  resolveReplyDelivery,
12383
12401
  generateAssistantReply,
12384
12402
  publishAppHomeView,
12385
- createNormalizingStream,
12386
12403
  DeferredThreadMessageError,
12387
12404
  getThreadMessageTopic,
12388
12405
  createQueueCallbackHandler,
12389
- bot,
12390
- slackRuntime
12406
+ getProductionBot,
12407
+ getProductionSlackRuntime
12391
12408
  };
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  getPluginRuntimeDependencies,
3
- getPluginRuntimePostinstall
4
- } from "./chunk-ZBWWHP6Q.js";
5
- import {
3
+ getPluginRuntimePostinstall,
6
4
  withSpan
7
- } from "./chunk-ZW4OVKF5.js";
5
+ } from "./chunk-MY7JNCS2.js";
6
+
7
+ // src/chat/state/adapter.ts
8
+ import { createMemoryState } from "@chat-adapter/state-memory";
9
+ import { createRedisState } from "@chat-adapter/state-redis";
8
10
 
9
11
  // src/chat/optional-string.ts
10
12
  function toOptionalTrimmed(value) {
@@ -101,8 +103,6 @@ function getRuntimeMetadata() {
101
103
  }
102
104
 
103
105
  // src/chat/state/adapter.ts
104
- import { createMemoryState } from "@chat-adapter/state-memory";
105
- import { createRedisState } from "@chat-adapter/state-redis";
106
106
  var MIN_LOCK_TTL_MS = 1e3 * 60 * 5;
107
107
  var stateAdapter;
108
108
  var redisStateAdapter;