@sentry/junior 0.94.0 → 0.96.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 (127) hide show
  1. package/dist/{agent-hooks-ZG7IDOIN.js → agent-hooks-5URSMY3O.js} +10 -11
  2. package/dist/api/people/list.js +8 -8
  3. package/dist/api/people/profile.js +8 -8
  4. package/dist/api/people/shared.d.ts +2 -2
  5. package/dist/api-reference.d.ts +2 -2
  6. package/dist/app.js +434 -199
  7. package/dist/{catalog-runtime-NZHMSMYC.js → catalog-runtime-MSMAYYIK.js} +4 -4
  8. package/dist/chat/advisor-request.d.ts +4 -0
  9. package/dist/chat/agent/request.d.ts +2 -0
  10. package/dist/chat/agent/resume.d.ts +2 -0
  11. package/dist/chat/conversations/history.d.ts +128 -0
  12. package/dist/chat/conversations/legacy-import.d.ts +38 -0
  13. package/dist/chat/conversations/messages.d.ts +39 -0
  14. package/dist/chat/conversations/projection.d.ts +94 -0
  15. package/dist/chat/conversations/retention.d.ts +36 -0
  16. package/dist/chat/conversations/sql/conversation-row.d.ts +14 -0
  17. package/dist/chat/conversations/sql/history.d.ts +4 -0
  18. package/dist/chat/conversations/sql/legacy-history-import.d.ts +55 -0
  19. package/dist/chat/conversations/sql/messages.d.ts +4 -0
  20. package/dist/chat/conversations/sql/migrations.d.ts +14 -3
  21. package/dist/chat/conversations/sql/purge.d.ts +53 -0
  22. package/dist/chat/conversations/sql/store.d.ts +7 -2
  23. package/dist/chat/conversations/store.d.ts +19 -0
  24. package/dist/chat/conversations/visible-compactions.d.ts +11 -0
  25. package/dist/chat/conversations/visible-messages.d.ts +47 -0
  26. package/dist/chat/db.d.ts +12 -1
  27. package/dist/chat/identities/sql.d.ts +1 -1
  28. package/dist/chat/logging.d.ts +4 -3
  29. package/dist/chat/plugins/auth/oauth-request.d.ts +2 -0
  30. package/dist/chat/resource-events/notification.d.ts +2 -0
  31. package/dist/chat/resource-events/store.d.ts +2 -1
  32. package/dist/chat/runtime/agent-run-outcome.d.ts +3 -0
  33. package/dist/chat/runtime/reply-executor.d.ts +8 -0
  34. package/dist/chat/runtime/thread-state.d.ts +2 -0
  35. package/dist/chat/sandbox/resources.d.ts +4 -0
  36. package/dist/chat/sentry.d.ts +1 -1
  37. package/dist/chat/services/mcp-auth-orchestration.d.ts +8 -0
  38. package/dist/chat/services/plugin-auth-orchestration.d.ts +12 -0
  39. package/dist/chat/services/turn-session-record.d.ts +14 -2
  40. package/dist/chat/sleep.d.ts +2 -0
  41. package/dist/chat/state/conversation.d.ts +7 -4
  42. package/dist/chat/state/session-log.d.ts +23 -1
  43. package/dist/chat/state/turn-session.d.ts +9 -1
  44. package/dist/chat/tool-support/private-trace-result.d.ts +4 -0
  45. package/dist/chat/tool-support/zod-tool.d.ts +1 -0
  46. package/dist/chat/tools/advisor/tool.d.ts +9 -4
  47. package/dist/chat/tools/definition.d.ts +2 -0
  48. package/dist/chat/tools/execution/tool-error-handler.d.ts +2 -2
  49. package/dist/chat/tools/system-time.d.ts +8 -0
  50. package/dist/chat/usage.d.ts +27 -13
  51. package/dist/chat/xml.d.ts +2 -0
  52. package/dist/{chunk-TNUUATT7.js → chunk-2NAZZPPS.js} +2 -2
  53. package/dist/{chunk-NYWPISSO.js → chunk-2XXEKR44.js} +1 -1
  54. package/dist/chunk-5C6XTTFI.js +1037 -0
  55. package/dist/{chunk-3DA7X2U3.js → chunk-6GWA276C.js} +15 -0
  56. package/dist/{chunk-LFLTJQVR.js → chunk-7FBGKXPE.js} +4 -0
  57. package/dist/{chunk-LNCREA5Z.js → chunk-AAZXTVJT.js} +4 -128
  58. package/dist/{chunk-GHGPTPBL.js → chunk-B7PUBQQM.js} +1 -1
  59. package/dist/{chunk-6H4PP63X.js → chunk-BYZWPRJA.js} +24 -14
  60. package/dist/chunk-CM5EZD5F.js +17 -0
  61. package/dist/{chunk-G3E7SCME.js → chunk-CZEX6KIQ.js} +23 -0
  62. package/dist/{chunk-YJ4OPVNA.js → chunk-DZENG5ML.js} +1 -1
  63. package/dist/{chunk-QGEWC27H.js → chunk-GQ3GK22G.js} +5 -7
  64. package/dist/{chunk-YYBX2BD5.js → chunk-GY34VGP5.js} +1 -1
  65. package/dist/{chunk-S6QKIGRM.js → chunk-I35CTGPO.js} +71 -29
  66. package/dist/{chunk-KRMANDHI.js → chunk-IYM2SIVG.js} +1489 -355
  67. package/dist/{chunk-BTH37NCU.js → chunk-L7CDEIVJ.js} +12 -4
  68. package/dist/chunk-MNTINMWR.js +865 -0
  69. package/dist/{chunk-MAVOJ54A.js → chunk-P3YFQLEN.js} +25 -388
  70. package/dist/{chunk-YTNPU7I2.js → chunk-PMNN6ST4.js} +2 -2
  71. package/dist/{chunk-PFXC67GJ.js → chunk-RAIB6WSG.js} +6 -80
  72. package/dist/{chunk-NFXSLTYG.js → chunk-RITD7E5L.js} +864 -62
  73. package/dist/{chunk-UUB3D2XI.js → chunk-S5KZ5LPG.js} +8 -10
  74. package/dist/{chunk-HDNWZMUN.js → chunk-UKHVMPX5.js} +112 -103
  75. package/dist/chunk-WM6KHPBQ.js +48 -0
  76. package/dist/{chunk-MC4ZZE4Q.js → chunk-YDT7SNCN.js} +1 -1
  77. package/dist/{chunk-NAPITCZ6.js → chunk-YDVEH3SB.js} +251 -6
  78. package/dist/cli/chat.js +25 -24
  79. package/dist/cli/check.js +5 -5
  80. package/dist/cli/main.js +1 -1
  81. package/dist/cli/plugins.js +12 -13
  82. package/dist/cli/snapshot-warmup.js +8 -9
  83. package/dist/cli/upgrade.js +79 -18
  84. package/dist/db/schema/agent-steps.d.ts +134 -0
  85. package/dist/db/schema/conversation-messages.d.ts +153 -0
  86. package/dist/{chat/conversations/sql → db}/schema/conversations.d.ts +34 -0
  87. package/dist/{chat/conversations/sql → db}/schema.d.ts +319 -8
  88. package/dist/db-2D6RMG67.js +24 -0
  89. package/dist/deployment.d.ts +2 -0
  90. package/dist/handlers/retention.d.ts +6 -0
  91. package/dist/instrumentation.js +17 -4
  92. package/dist/legacy-import-VZ2MEGP7.js +17 -0
  93. package/dist/nitro.js +14 -4
  94. package/dist/reporting/conversations/activity.d.ts +40 -0
  95. package/dist/reporting/conversations/context.d.ts +8 -0
  96. package/dist/reporting/conversations/details.d.ts +6 -0
  97. package/dist/reporting/conversations/index.d.ts +4 -0
  98. package/dist/reporting/conversations/shared.d.ts +9 -0
  99. package/dist/reporting/conversations/statistics.d.ts +4 -0
  100. package/dist/reporting/conversations/summaries.d.ts +20 -0
  101. package/dist/reporting/conversations/transcript.d.ts +28 -0
  102. package/dist/reporting/conversations/types.d.ts +191 -0
  103. package/dist/reporting/conversations.d.ts +1 -178
  104. package/dist/reporting.d.ts +5 -4
  105. package/dist/reporting.js +703 -837
  106. package/dist/{runner-XAZPJNAQ.js → runner-JZBRQP4F.js} +36 -42
  107. package/dist/{sentry-EGFOV3DH.js → sentry-JMWTS32N.js} +11 -1
  108. package/dist/{validation-KYAWETI4.js → validation-6XOOQGME.js} +5 -5
  109. package/migrations/README.md +32 -0
  110. package/migrations/meta/0000_snapshot.json +978 -0
  111. package/migrations/meta/_journal.json +13 -0
  112. package/package.json +10 -7
  113. package/dist/chat/sql/schema.d.ts +0 -1049
  114. package/dist/chat/state/conversation-details.d.ts +0 -47
  115. package/dist/chunk-7STN2ZSK.js +0 -250
  116. package/dist/chunk-LE5ANBUZ.js +0 -1040
  117. package/dist/chunk-QL66APYJ.js +0 -1377
  118. package/dist/db-YDN6AFJH.js +0 -18
  119. /package/dist/{chat/sql → db}/db.d.ts +0 -0
  120. /package/dist/{chat/sql → db}/executor.d.ts +0 -0
  121. /package/dist/{chat/sql → db}/neon.d.ts +0 -0
  122. /package/dist/{chat/sql → db}/postgres.d.ts +0 -0
  123. /package/dist/{chat/conversations/sql → db}/schema/destinations.d.ts +0 -0
  124. /package/dist/{chat/conversations/sql → db}/schema/identities.d.ts +0 -0
  125. /package/dist/{chat/conversations/sql → db}/schema/migrations.d.ts +0 -0
  126. /package/dist/{chat/conversations/sql → db}/schema/timestamps.d.ts +0 -0
  127. /package/dist/{chat/conversations/sql → db}/schema/users.d.ts +0 -0
@@ -6,13 +6,18 @@ import {
6
6
  var sentry_exports = {};
7
7
  __export(sentry_exports, {
8
8
  captureException: () => captureException,
9
+ captureMessage: () => captureMessage,
9
10
  continueTrace: () => continueTrace,
10
11
  flush: () => flush,
12
+ getActiveSpan: () => getActiveSpan,
11
13
  getClient: () => getClient,
12
14
  getGlobalScope: () => getGlobalScope,
15
+ getTraceData: () => getTraceData,
13
16
  init: () => init,
17
+ logger: () => logger,
14
18
  setTag: () => setTag,
15
19
  setUser: () => setUser,
20
+ spanToJSON: () => spanToJSON,
16
21
  startInactiveSpan: () => startInactiveSpan,
17
22
  startSpan: () => startSpan,
18
23
  vercelAIIntegration: () => vercelAIIntegration,
@@ -22,13 +27,18 @@ __export(sentry_exports, {
22
27
  });
23
28
  import {
24
29
  captureException,
30
+ captureMessage,
25
31
  continueTrace,
26
32
  flush,
33
+ getActiveSpan,
27
34
  getClient,
28
35
  getGlobalScope,
36
+ getTraceData,
29
37
  init,
38
+ logger,
30
39
  setTag,
31
40
  setUser,
41
+ spanToJSON,
32
42
  startInactiveSpan,
33
43
  startSpan,
34
44
  vercelAIIntegration,
@@ -41,13 +51,18 @@ export * from "@sentry/node";
41
51
  export {
42
52
  sentry_exports,
43
53
  captureException,
54
+ captureMessage,
44
55
  continueTrace,
45
56
  flush,
57
+ getActiveSpan,
46
58
  getClient,
47
59
  getGlobalScope,
60
+ getTraceData,
48
61
  init,
62
+ logger,
49
63
  setTag,
50
64
  setUser,
65
+ spanToJSON,
51
66
  startInactiveSpan,
52
67
  startSpan,
53
68
  vercelAIIntegration,
@@ -1,6 +1,8 @@
1
1
  // src/deployment.ts
2
2
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
3
3
  var JUNIOR_HEARTBEAT_CRON_SCHEDULE = "* * * * *";
4
+ var JUNIOR_RETENTION_ROUTE = "/api/internal/retention";
5
+ var JUNIOR_RETENTION_CRON_SCHEDULE = "0 4 * * *";
4
6
  var JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE = "/api/internal/agent/continue";
5
7
  var JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE = "/api/internal/plugin/tasks";
6
8
  var LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION = "api/internal/agent/continue.ts";
@@ -77,6 +79,8 @@ function parseSlackUserId(value) {
77
79
  export {
78
80
  JUNIOR_HEARTBEAT_ROUTE,
79
81
  JUNIOR_HEARTBEAT_CRON_SCHEDULE,
82
+ JUNIOR_RETENTION_ROUTE,
83
+ JUNIOR_RETENTION_CRON_SCHEDULE,
80
84
  JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE,
81
85
  JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE,
82
86
  LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION,
@@ -1,22 +1,12 @@
1
1
  import {
2
2
  normalizeSlackConversationId
3
- } from "./chunk-UUB3D2XI.js";
4
- import {
5
- getStateAdapter
6
- } from "./chunk-7STN2ZSK.js";
3
+ } from "./chunk-S5KZ5LPG.js";
7
4
  import {
8
5
  parseSlackThreadId
9
- } from "./chunk-YYBX2BD5.js";
10
- import {
11
- parseStoredSlackActor
12
- } from "./chunk-S6QKIGRM.js";
13
- import {
14
- isRecord,
15
- toOptionalNumber
16
- } from "./chunk-OB42YVAE.js";
6
+ } from "./chunk-GY34VGP5.js";
17
7
  import {
18
8
  getClient
19
- } from "./chunk-3DA7X2U3.js";
9
+ } from "./chunk-6GWA276C.js";
20
10
 
21
11
  // src/handlers/health.ts
22
12
  function GET() {
@@ -164,116 +154,6 @@ function formatSlackConversationRedactedLabel(context) {
164
154
  return formatSlackConversationTypeLabel(context.type);
165
155
  }
166
156
 
167
- // src/chat/state/conversation-details.ts
168
- import { THREAD_STATE_TTL_MS } from "chat";
169
- var CONVERSATION_PREFIX = "junior:conversation";
170
- var CONVERSATION_DETAILS_TTL_MS = THREAD_STATE_TTL_MS;
171
- function conversationContextKey(conversationId) {
172
- return `${CONVERSATION_PREFIX}:${conversationId}:context`;
173
- }
174
- function conversationTitleKey(conversationId) {
175
- return `${CONVERSATION_PREFIX}:${conversationId}:title`;
176
- }
177
- function parseOriginActor(value) {
178
- return parseStoredSlackActor(value);
179
- }
180
- function parseOriginSurface(value) {
181
- if (value === "slack" || value === "api" || value === "scheduler" || value === "internal") {
182
- return value;
183
- }
184
- return void 0;
185
- }
186
- function storedContextFromInput(context) {
187
- return {
188
- ...context.channelName ? { channelName: context.channelName } : {},
189
- ...context.originSurface ? { originSurface: context.originSurface } : {},
190
- ...context.originActor ? { originActor: context.originActor } : {},
191
- startedAtMs: context.startedAtMs
192
- };
193
- }
194
- function parseContext(value) {
195
- if (!isRecord(value)) return void 0;
196
- const startedAtMs = toOptionalNumber(value.startedAtMs);
197
- if (startedAtMs === void 0) return void 0;
198
- return {
199
- ...typeof value.channelName === "string" && value.channelName.trim() ? { channelName: value.channelName.trim() } : {},
200
- ...parseOriginSurface(value.originSurface) ? { originSurface: parseOriginSurface(value.originSurface) } : {},
201
- ...parseOriginActor(value.originActor) ? { originActor: parseOriginActor(value.originActor) } : {},
202
- startedAtMs
203
- };
204
- }
205
- function parseTitle(value) {
206
- if (!isRecord(value)) return void 0;
207
- const displayTitle = typeof value.displayTitle === "string" && value.displayTitle.trim() ? value.displayTitle.trim() : void 0;
208
- if (!displayTitle) return void 0;
209
- return {
210
- displayTitle,
211
- ...typeof value.titleSourceMessageId === "string" ? { titleSourceMessageId: value.titleSourceMessageId } : {}
212
- };
213
- }
214
- async function initConversationContext(conversationId, context) {
215
- const stateAdapter = getStateAdapter();
216
- await stateAdapter.connect();
217
- const key = conversationContextKey(conversationId);
218
- const inserted = await stateAdapter.setIfNotExists(
219
- key,
220
- storedContextFromInput(context),
221
- CONVERSATION_DETAILS_TTL_MS
222
- );
223
- if (inserted) return;
224
- const existing = parseContext(await stateAdapter.get(key));
225
- if (!existing) {
226
- return;
227
- }
228
- await stateAdapter.set(key, existing, CONVERSATION_DETAILS_TTL_MS);
229
- }
230
- async function setConversationTitle(conversationId, title) {
231
- const stateAdapter = getStateAdapter();
232
- await stateAdapter.connect();
233
- await stateAdapter.set(
234
- conversationTitleKey(conversationId),
235
- {
236
- displayTitle: title.displayTitle,
237
- ...title.titleSourceMessageId ? { titleSourceMessageId: title.titleSourceMessageId } : {}
238
- },
239
- CONVERSATION_DETAILS_TTL_MS
240
- );
241
- }
242
- async function getConversationDetails(conversationId) {
243
- const stateAdapter = getStateAdapter();
244
- await stateAdapter.connect();
245
- const [rawContext, rawTitle] = await Promise.all([
246
- stateAdapter.get(conversationContextKey(conversationId)),
247
- stateAdapter.get(conversationTitleKey(conversationId))
248
- ]);
249
- const context = parseContext(rawContext);
250
- const title = parseTitle(rawTitle);
251
- if (!context && !title) return void 0;
252
- return {
253
- conversationId,
254
- ...title?.displayTitle ? { displayTitle: title.displayTitle } : {},
255
- ...title?.titleSourceMessageId ? { titleSourceMessageId: title.titleSourceMessageId } : {},
256
- ...context?.channelName ? { channelName: context.channelName } : {},
257
- ...context?.originSurface ? { originSurface: context.originSurface } : {},
258
- ...context?.originActor ? { originActor: context.originActor } : {},
259
- ...context?.startedAtMs !== void 0 ? { startedAtMs: context.startedAtMs } : {}
260
- };
261
- }
262
- async function getConversationDetailsForIds(conversationIds) {
263
- const uniqueIds = [...new Set(conversationIds)].filter(Boolean);
264
- const entries = await Promise.all(
265
- uniqueIds.map(async (id) => {
266
- const details = await getConversationDetails(id);
267
- return details ? [id, details] : void 0;
268
- })
269
- );
270
- const result = /* @__PURE__ */ new Map();
271
- for (const entry of entries) {
272
- if (entry) result.set(entry[0], entry[1]);
273
- }
274
- return result;
275
- }
276
-
277
157
  export {
278
158
  GET,
279
159
  buildSentryConversationUrl,
@@ -282,9 +162,5 @@ export {
282
162
  resolveSlackChannelTypeFromMessage,
283
163
  resolveSlackConversationContext,
284
164
  resolveSlackConversationContextFromThreadId,
285
- formatSlackConversationRedactedLabel,
286
- initConversationContext,
287
- setConversationTitle,
288
- getConversationDetails,
289
- getConversationDetailsForIds
165
+ formatSlackConversationRedactedLabel
290
166
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parseSlackChannelReferenceId,
3
3
  parseSlackTeamId
4
- } from "./chunk-LFLTJQVR.js";
4
+ } from "./chunk-7FBGKXPE.js";
5
5
 
6
6
  // src/chat/destination.ts
7
7
  import {
@@ -1,18 +1,17 @@
1
1
  import {
2
- SANDBOX_WORKSPACE_ROOT
3
- } from "./chunk-G3E7SCME.js";
4
- import {
5
- getStateAdapter
6
- } from "./chunk-7STN2ZSK.js";
2
+ SANDBOX_WORKSPACE_ROOT,
3
+ sleep
4
+ } from "./chunk-CZEX6KIQ.js";
7
5
  import {
6
+ getStateAdapter,
8
7
  toOptionalTrimmed
9
- } from "./chunk-NAPITCZ6.js";
8
+ } from "./chunk-YDVEH3SB.js";
10
9
  import {
11
10
  pluginCatalogRuntime
12
- } from "./chunk-BTH37NCU.js";
11
+ } from "./chunk-L7CDEIVJ.js";
13
12
  import {
14
13
  withSpan
15
- } from "./chunk-S6QKIGRM.js";
14
+ } from "./chunk-I35CTGPO.js";
16
15
 
17
16
  // src/chat/sandbox/runtime-dependency-snapshots.ts
18
17
  import { createHash } from "crypto";
@@ -134,6 +133,19 @@ function createSandboxInstance(sandbox) {
134
133
  };
135
134
  }
136
135
 
136
+ // src/chat/sandbox/resources.ts
137
+ function getSandboxResources() {
138
+ const value = process.env.SANDBOX_VCPUS?.trim();
139
+ if (!value || !/^\d+$/.test(value)) {
140
+ return void 0;
141
+ }
142
+ const vcpus = Number(value);
143
+ if (!Number.isSafeInteger(vcpus) || vcpus <= 0) {
144
+ return void 0;
145
+ }
146
+ return { vcpus };
147
+ }
148
+
137
149
  // src/chat/sandbox/runtime-dependency-snapshots.ts
138
150
  var SNAPSHOT_CACHE_PREFIX = "junior:sandbox_snapshot_profile";
139
151
  var SNAPSHOT_LOCK_PREFIX = "junior:sandbox_snapshot_lock";
@@ -142,11 +154,6 @@ var SNAPSHOT_CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
142
154
  var SNAPSHOT_BUILD_LOCK_TTL_MS = 10 * 60 * 1e3;
143
155
  var SNAPSHOT_WAIT_FOR_LOCK_MS = SNAPSHOT_BUILD_LOCK_TTL_MS + 30 * 1e3;
144
156
  var DEFAULT_FLOATING_DEP_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
145
- function sleep(ms) {
146
- return new Promise((resolve) => {
147
- setTimeout(resolve, ms);
148
- });
149
- }
150
157
  function profileCacheKey(profileHash) {
151
158
  return `${SNAPSHOT_CACHE_PREFIX}:${profileHash}`;
152
159
  }
@@ -461,11 +468,13 @@ async function createDependencySnapshot(profile, runtime, timeoutMs) {
461
468
  },
462
469
  async () => {
463
470
  const sandboxCredentials = getVercelSandboxCredentials();
471
+ const resources = getSandboxResources();
464
472
  const sandbox = createSandboxInstance(
465
473
  await Sandbox.create({
466
474
  timeout: timeoutMs,
467
475
  runtime,
468
- ...sandboxCredentials ?? {}
476
+ ...sandboxCredentials ?? {},
477
+ ...resources ? { resources } : {}
469
478
  })
470
479
  );
471
480
  try {
@@ -681,6 +690,7 @@ export {
681
690
  buildNonInteractiveShellScript,
682
691
  runNonInteractiveCommand,
683
692
  getVercelSandboxCredentials,
693
+ getSandboxResources,
684
694
  createSandboxInstance,
685
695
  getRuntimeDependencyProfileHash,
686
696
  resolveRuntimeDependencySnapshot,
@@ -0,0 +1,17 @@
1
+ // src/chat/tool-support/private-trace-result.ts
2
+ import { randomUUID } from "crypto";
3
+ var PRIVATE_TRACE_RESULT_ATTRIBUTE = "app.ai.tool.call.result.exposure";
4
+ var privateTraceResultToken = randomUUID();
5
+ function privateTraceResultAttributes() {
6
+ return { [PRIVATE_TRACE_RESULT_ATTRIBUTE]: privateTraceResultToken };
7
+ }
8
+ function consumePrivateTraceResultMarker(attributes) {
9
+ const projected = attributes[PRIVATE_TRACE_RESULT_ATTRIBUTE] === privateTraceResultToken;
10
+ delete attributes[PRIVATE_TRACE_RESULT_ATTRIBUTE];
11
+ return projected;
12
+ }
13
+
14
+ export {
15
+ privateTraceResultAttributes,
16
+ consumePrivateTraceResultMarker
17
+ };
@@ -1,3 +1,25 @@
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
+
1
23
  // src/chat/sandbox/paths.ts
2
24
  function normalizeWorkspaceRoot(input) {
3
25
  const candidate = (input ?? "").trim();
@@ -20,6 +42,7 @@ function sandboxSkillFile(skillName) {
20
42
  }
21
43
 
22
44
  export {
45
+ sleep,
23
46
  SANDBOX_WORKSPACE_ROOT,
24
47
  SANDBOX_SKILLS_ROOT,
25
48
  SANDBOX_DATA_ROOT,
@@ -4,7 +4,7 @@ import {
4
4
  juniorDestinations,
5
5
  juniorIdentities,
6
6
  juniorUsers
7
- } from "./chunk-NFXSLTYG.js";
7
+ } from "./chunk-RITD7E5L.js";
8
8
 
9
9
  // src/api/people/shared.ts
10
10
  import { and, asc, desc, eq, sql } from "drizzle-orm";
@@ -1,20 +1,18 @@
1
1
  import {
2
2
  JUNIOR_THREAD_STATE_TTL_MS
3
- } from "./chunk-PFXC67GJ.js";
3
+ } from "./chunk-5C6XTTFI.js";
4
4
  import {
5
+ getChatConfig,
5
6
  getDefaultRedisStateAdapterFor,
6
7
  getStateAdapter
7
- } from "./chunk-7STN2ZSK.js";
8
- import {
9
- getChatConfig
10
- } from "./chunk-NAPITCZ6.js";
8
+ } from "./chunk-YDVEH3SB.js";
11
9
  import {
12
10
  parseDestination,
13
11
  sameDestination
14
- } from "./chunk-GHGPTPBL.js";
12
+ } from "./chunk-B7PUBQQM.js";
15
13
  import {
16
14
  parseStoredSlackActor
17
- } from "./chunk-S6QKIGRM.js";
15
+ } from "./chunk-I35CTGPO.js";
18
16
  import {
19
17
  isRecord,
20
18
  toOptionalNumber,
@@ -5,7 +5,7 @@ import {
5
5
  parseSlackChannelId,
6
6
  parseSlackMessageTs,
7
7
  parseSlackTeamId
8
- } from "./chunk-LFLTJQVR.js";
8
+ } from "./chunk-7FBGKXPE.js";
9
9
 
10
10
  // src/chat/slack/context.ts
11
11
  import { z } from "zod";
@@ -4,16 +4,17 @@ import {
4
4
  } from "./chunk-OB42YVAE.js";
5
5
  import {
6
6
  captureException,
7
+ getActiveSpan,
7
8
  sentry_exports,
8
9
  setTag,
9
10
  setUser,
10
11
  startSpan,
11
12
  withScope
12
- } from "./chunk-3DA7X2U3.js";
13
+ } from "./chunk-6GWA276C.js";
13
14
  import {
14
15
  getDeploymentTelemetryAttributes,
15
16
  parseSlackTeamId
16
- } from "./chunk-LFLTJQVR.js";
17
+ } from "./chunk-7FBGKXPE.js";
17
18
 
18
19
  // src/chat/logging.ts
19
20
  import { AsyncLocalStorage } from "async_hooks";
@@ -1114,6 +1115,13 @@ function normalizeSpanAttributes(attributes) {
1114
1115
  }
1115
1116
  return normalized;
1116
1117
  }
1118
+ function setAttributesOnSpan(span, attributes) {
1119
+ for (const [key, value] of Object.entries(
1120
+ normalizeSpanAttributes(attributes)
1121
+ )) {
1122
+ span.setAttribute(key, value);
1123
+ }
1124
+ }
1117
1125
  function logInfo(eventName, context = {}, attributes = {}, body) {
1118
1126
  log.info(eventName, { ...toSpanAttributes(context), ...attributes }, body);
1119
1127
  }
@@ -1157,7 +1165,7 @@ async function withSpan(name, op, context, callback, attributes = {}) {
1157
1165
  ...normalizedAttributes
1158
1166
  }
1159
1167
  },
1160
- callback
1168
+ (span) => callback((attributes2) => setAttributesOnSpan(span, attributes2))
1161
1169
  );
1162
1170
  });
1163
1171
  }
@@ -1177,32 +1185,20 @@ function getTracePropagationHeaders() {
1177
1185
  return headers;
1178
1186
  }
1179
1187
  function setSpanAttributes(attributes) {
1180
- const sentry = sentry_exports;
1181
- const span = sentry.getActiveSpan?.();
1188
+ const span = getActiveSpan();
1182
1189
  if (!span) {
1183
1190
  return;
1184
1191
  }
1185
- const setAttribute = span.setAttribute;
1186
- if (typeof setAttribute !== "function") {
1187
- return;
1188
- }
1189
- for (const [key, value] of Object.entries(
1190
- normalizeSpanAttributes(attributes)
1191
- )) {
1192
- setAttribute.call(span, key, value);
1193
- }
1192
+ setAttributesOnSpan(span, attributes);
1194
1193
  }
1195
1194
  function setSpanStatus(status) {
1196
- const sentry = sentry_exports;
1197
- const span = sentry.getActiveSpan?.();
1195
+ const span = getActiveSpan();
1198
1196
  if (!span) {
1199
1197
  return;
1200
1198
  }
1201
- const setStatus = span.setStatus;
1202
- if (typeof setStatus !== "function") {
1203
- return;
1204
- }
1205
- setStatus.call(span, status === "ok" ? "ok" : "internal_error");
1199
+ span.setStatus(
1200
+ status === "ok" ? { code: 1 } : { code: 2, message: "internal_error" }
1201
+ );
1206
1202
  }
1207
1203
  function getActiveTraceId() {
1208
1204
  const sentry = sentry_exports;
@@ -1293,6 +1289,12 @@ function toFiniteTokenCount(value) {
1293
1289
  const rounded = Math.floor(value);
1294
1290
  return rounded >= 0 ? rounded : void 0;
1295
1291
  }
1292
+ function toFiniteCost(value) {
1293
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
1294
+ }
1295
+ function addCost(left, right) {
1296
+ return Math.round(((left ?? 0) + right) * 1e12) / 1e12;
1297
+ }
1296
1298
  function sumTokenCounts(...values) {
1297
1299
  let total = 0;
1298
1300
  let hasValue = false;
@@ -1310,8 +1312,16 @@ var PI_USAGE_FIELDS = [
1310
1312
  ["output", "outputTokens"],
1311
1313
  ["cacheRead", "cachedInputTokens"],
1312
1314
  ["cacheWrite", "cacheCreationTokens"],
1315
+ ["reasoning", "reasoningTokens"],
1313
1316
  ["totalTokens", "totalTokens"]
1314
1317
  ];
1318
+ var PI_COST_FIELDS = [
1319
+ "input",
1320
+ "output",
1321
+ "cacheRead",
1322
+ "cacheWrite",
1323
+ "total"
1324
+ ];
1315
1325
  function readPiUsage(source) {
1316
1326
  const record = asRecord(source);
1317
1327
  if (!record) {
@@ -1325,17 +1335,46 @@ function readPiUsage(source) {
1325
1335
  summary[ourKey] = value;
1326
1336
  }
1327
1337
  }
1338
+ const piCost = asRecord(usage.cost);
1339
+ if (piCost) {
1340
+ const cost = {};
1341
+ for (const field of PI_COST_FIELDS) {
1342
+ const value = toFiniteCost(piCost[field]);
1343
+ if (value !== void 0) {
1344
+ cost[field] = value;
1345
+ }
1346
+ }
1347
+ if (Object.keys(cost).length > 0) {
1348
+ summary.cost = cost;
1349
+ }
1350
+ }
1328
1351
  return summary;
1329
1352
  }
1330
1353
  function extractGenAiUsageSummary(...sources) {
1331
1354
  const summary = {};
1355
+ const cost = {};
1332
1356
  for (const source of sources) {
1333
1357
  const single = readPiUsage(source);
1334
- for (const field of Object.keys(single)) {
1358
+ for (const field of [
1359
+ "inputTokens",
1360
+ "outputTokens",
1361
+ "cachedInputTokens",
1362
+ "cacheCreationTokens",
1363
+ "reasoningTokens",
1364
+ "totalTokens"
1365
+ ]) {
1335
1366
  const value = single[field];
1336
1367
  if (value === void 0) continue;
1337
1368
  summary[field] = (summary[field] ?? 0) + value;
1338
1369
  }
1370
+ for (const field of PI_COST_FIELDS) {
1371
+ const value = single.cost?.[field];
1372
+ if (value === void 0) continue;
1373
+ cost[field] = addCost(cost[field], value);
1374
+ }
1375
+ }
1376
+ if (Object.keys(cost).length > 0) {
1377
+ summary.cost = cost;
1339
1378
  }
1340
1379
  return summary;
1341
1380
  }
@@ -1345,7 +1384,9 @@ function extractGenAiUsageAttributes(...sources) {
1345
1384
  outputTokens,
1346
1385
  cachedInputTokens,
1347
1386
  cacheCreationTokens,
1348
- totalTokens
1387
+ reasoningTokens,
1388
+ totalTokens,
1389
+ cost
1349
1390
  } = extractGenAiUsageSummary(...sources);
1350
1391
  const semanticInputTokens = sumTokenCounts(
1351
1392
  inputTokens,
@@ -1358,7 +1399,13 @@ function extractGenAiUsageAttributes(...sources) {
1358
1399
  ...outputTokens !== void 0 ? { "gen_ai.usage.output_tokens": outputTokens } : {},
1359
1400
  ...semanticTotalTokens !== void 0 ? { "gen_ai.usage.total_tokens": semanticTotalTokens } : {},
1360
1401
  ...cachedInputTokens !== void 0 ? { "gen_ai.usage.input_tokens.cached": cachedInputTokens } : {},
1361
- ...cacheCreationTokens !== void 0 ? { "gen_ai.usage.input_tokens.cache_write": cacheCreationTokens } : {}
1402
+ ...cacheCreationTokens !== void 0 ? { "gen_ai.usage.input_tokens.cache_write": cacheCreationTokens } : {},
1403
+ ...reasoningTokens !== void 0 ? { "app.ai.reasoning_tokens": reasoningTokens } : {},
1404
+ ...cost?.input !== void 0 ? { "app.ai.cost.input_usd": cost.input } : {},
1405
+ ...cost?.output !== void 0 ? { "app.ai.cost.output_usd": cost.output } : {},
1406
+ ...cost?.cacheRead !== void 0 ? { "app.ai.cost.cache_read_usd": cost.cacheRead } : {},
1407
+ ...cost?.cacheWrite !== void 0 ? { "app.ai.cost.cache_write_usd": cost.cacheWrite } : {},
1408
+ ...cost?.total !== void 0 ? { "app.ai.cost.total_usd": cost.total } : {}
1362
1409
  };
1363
1410
  }
1364
1411
 
@@ -1376,10 +1423,6 @@ var storedSlackActorSchema = z.object({
1376
1423
  slackUserName: exactStoredStringSchema.optional(),
1377
1424
  teamId: exactStoredStringSchema.optional()
1378
1425
  }).strict();
1379
- function parseActor(value) {
1380
- const result = actorSchema.safeParse(value);
1381
- return result.success ? result.data : void 0;
1382
- }
1383
1426
  function isUserActor(actor) {
1384
1427
  return Boolean(actor && "userId" in actor);
1385
1428
  }
@@ -1557,7 +1600,6 @@ export {
1557
1600
  extractGenAiUsageSummary,
1558
1601
  extractGenAiUsageAttributes,
1559
1602
  storedSlackActorSchema,
1560
- parseActor,
1561
1603
  isUserActor,
1562
1604
  parseActorUserId,
1563
1605
  isActorUserId,