@sentry/junior 0.95.0 → 0.97.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 (144) hide show
  1. package/dist/{agent-hooks-FTQ5EGPO.js → agent-hooks-XSUIVRQS.js} +10 -8
  2. package/dist/{reporting → api}/conversations/activity.d.ts +1 -1
  3. package/dist/api/conversations/detail-projection.d.ts +10 -0
  4. package/dist/api/conversations/detail.d.ts +3 -0
  5. package/dist/api/conversations/detail.query.d.ts +3 -0
  6. package/dist/api/conversations/list.d.ts +3 -0
  7. package/dist/api/conversations/list.query.d.ts +94 -0
  8. package/dist/api/conversations/projection.d.ts +14 -0
  9. package/dist/api/conversations/schema.d.ts +683 -0
  10. package/dist/{reporting → api}/conversations/shared.d.ts +1 -5
  11. package/dist/api/conversations/stats.d.ts +3 -0
  12. package/dist/api/conversations/stats.query.d.ts +3 -0
  13. package/dist/api/conversations/subagent.d.ts +3 -0
  14. package/dist/{reporting → api}/conversations/transcript.d.ts +4 -4
  15. package/dist/api/people/list.d.ts +1 -2
  16. package/dist/api/people/list.query.d.ts +3 -4
  17. package/dist/api/people/profile.d.ts +1 -2
  18. package/dist/api/people/profile.query.d.ts +3 -4
  19. package/dist/api/people/schema.d.ts +193 -0
  20. package/dist/api/people/shared.d.ts +31 -9
  21. package/dist/api/schema.d.ts +20 -0
  22. package/dist/api/schema.js +50 -0
  23. package/dist/api-reference.d.ts +4 -3
  24. package/dist/api.d.ts +3 -0
  25. package/dist/api.js +156 -0
  26. package/dist/app.d.ts +1 -4
  27. package/dist/app.js +108 -370
  28. package/dist/build/virtual-config.d.ts +2 -2
  29. package/dist/{catalog-runtime-2D7IVKUT.js → catalog-runtime-PFHVMHDR.js} +5 -4
  30. package/dist/chat/agent/resume.d.ts +3 -1
  31. package/dist/chat/agent/tools.d.ts +2 -1
  32. package/dist/chat/config.d.ts +1 -8
  33. package/dist/chat/conversations/history.d.ts +241 -27
  34. package/dist/chat/conversations/legacy-advisor-session.d.ts +7 -0
  35. package/dist/chat/conversations/legacy-import.d.ts +2 -2
  36. package/dist/chat/conversations/projection.d.ts +19 -3
  37. package/dist/chat/conversations/sql/legacy-history-import.d.ts +1 -1
  38. package/dist/chat/conversations/sql/store.d.ts +15 -9
  39. package/dist/chat/conversations/store.d.ts +9 -4
  40. package/dist/chat/logging.d.ts +2 -2
  41. package/dist/chat/model-profile.d.ts +14 -0
  42. package/dist/chat/pi/transcript.d.ts +5 -3
  43. package/dist/chat/plugins/auth/oauth-request.d.ts +2 -0
  44. package/dist/chat/resource-events/notification.d.ts +2 -0
  45. package/dist/chat/resource-events/store.d.ts +2 -2
  46. package/dist/chat/runtime/agent-run-outcome.d.ts +3 -0
  47. package/dist/chat/sentry.d.ts +1 -1
  48. package/dist/chat/services/context-compaction.d.ts +15 -0
  49. package/dist/chat/services/turn-result.d.ts +1 -0
  50. package/dist/chat/services/turn-session-record.d.ts +6 -6
  51. package/dist/chat/state/turn-session.d.ts +18 -5
  52. package/dist/chat/task-execution/store.d.ts +2 -2
  53. package/dist/chat/tools/handoff/tool.d.ts +45 -0
  54. package/dist/chat/tools/types.d.ts +7 -2
  55. package/dist/chat/usage.d.ts +27 -13
  56. package/dist/{chunk-6ONME5IG.js → chunk-35BNLDOJ.js} +339 -578
  57. package/dist/{chunk-HDTO3A74.js → chunk-3ECW2K2O.js} +8 -3
  58. package/dist/{chunk-CRRBJ3JP.js → chunk-3F4OPKGF.js} +90 -56
  59. package/dist/chunk-3V7OFJZC.js +264 -0
  60. package/dist/chunk-4ZNGQH7C.js +25 -0
  61. package/dist/{chunk-NSCHU54X.js → chunk-5HLDPVYS.js} +15 -448
  62. package/dist/{chunk-3DA7X2U3.js → chunk-6GWA276C.js} +15 -0
  63. package/dist/{chunk-HZNJLKKI.js → chunk-6U26PYI5.js} +24 -14
  64. package/dist/chunk-AUUCAFDE.js +546 -0
  65. package/dist/{chunk-6APU57E6.js → chunk-B3IT5END.js} +41 -260
  66. package/dist/chunk-CEA3A3UA.js +86 -0
  67. package/dist/{chunk-AYP4ERVZ.js → chunk-D5KZYS4T.js} +1 -1
  68. package/dist/{chunk-GUE7HTNR.js → chunk-EEZCY5WX.js} +79 -29
  69. package/dist/{chunk-E3E2XNCN.js → chunk-EOWXRY5E.js} +2 -2
  70. package/dist/{chunk-5XMNOD3S.js → chunk-FBHZJFHI.js} +3 -3
  71. package/dist/{chunk-CZEX6KIQ.js → chunk-G3E7SCME.js} +0 -23
  72. package/dist/chunk-GUAP3H7O.js +319 -0
  73. package/dist/{chunk-WCMQJE4F.js → chunk-H66UCBPW.js} +7 -5
  74. package/dist/{chunk-WPOJ443W.js → chunk-I35CTGPO.js} +58 -6
  75. package/dist/{chunk-GVOUCI2O.js → chunk-LMJPRYHP.js} +16 -6
  76. package/dist/chunk-LUAE4MGW.js +199 -0
  77. package/dist/{chunk-GY34VGP5.js → chunk-LVA4I4H7.js} +3 -1
  78. package/dist/chunk-LVUKF5CE.js +63 -0
  79. package/dist/{chunk-EKNJM5IG.js → chunk-NG2AV7IB.js} +2 -72
  80. package/dist/chunk-ON6YKIQ7.js +260 -0
  81. package/dist/chunk-PDO5BLNM.js +22 -0
  82. package/dist/chunk-QNVHH5PU.js +20 -0
  83. package/dist/{chunk-XX4N4E6C.js → chunk-T533JLM3.js} +9 -11
  84. package/dist/chunk-UAMKJPDF.js +11 -0
  85. package/dist/chunk-VFH4ZKZT.js +66 -0
  86. package/dist/{chunk-KDPCGVIT.js → chunk-WGXMTFNU.js} +17 -75
  87. package/dist/{chunk-WAGQ377B.js → chunk-WJOSZOON.js} +288 -263
  88. package/dist/chunk-WTYEKPXU.js +451 -0
  89. package/dist/{chunk-HCXXB35T.js → chunk-XIRPQQVE.js} +613 -369
  90. package/dist/cli/chat.js +26 -23
  91. package/dist/cli/check.js +6 -5
  92. package/dist/cli/init.js +12 -0
  93. package/dist/cli/main.js +1 -1
  94. package/dist/cli/plugins.js +14 -11
  95. package/dist/cli/snapshot-warmup.js +10 -8
  96. package/dist/cli/upgrade.js +267 -139
  97. package/dist/db/db.d.ts +4 -0
  98. package/dist/db/schema/conversations.d.ts +128 -0
  99. package/dist/db/schema.d.ts +129 -60
  100. package/dist/{db-W55B74OP.js → db-BWXYIKFQ.js} +5 -5
  101. package/dist/detail-GA6NXWQJ.js +43 -0
  102. package/dist/discovery-RMHYSRL7.js +43 -0
  103. package/dist/handlers/health.d.ts +3 -0
  104. package/dist/instrumentation.js +2 -2
  105. package/dist/{legacy-import-ZPLGLAFD.js → legacy-import-3NQJVGQL.js} +6 -6
  106. package/dist/{api/people/list.js → list-A3WFRIYX.js} +26 -16
  107. package/dist/list-UXJI5Q5X.js +27 -0
  108. package/dist/nitro.d.ts +1 -1
  109. package/dist/nitro.js +2 -1
  110. package/dist/plugin-conversations-DDNGC35A.js +36 -0
  111. package/dist/{api/people/profile.js → profile-4RYDXWTF.js} +33 -18
  112. package/dist/reporting/plugin-conversations.d.ts +3 -0
  113. package/dist/reporting-schema.d.ts +140 -0
  114. package/dist/reporting.d.ts +12 -81
  115. package/dist/{runner-OOSBDYRK.js → runner-JALSYH2P.js} +19 -14
  116. package/dist/{sentry-EGFOV3DH.js → sentry-JMWTS32N.js} +11 -1
  117. package/dist/skills-MAZXZ2KE.js +26 -0
  118. package/dist/stats-XKXH3PTY.js +217 -0
  119. package/dist/subagent-TZ55XY37.js +48 -0
  120. package/dist/usage-schema.d.ts +25 -0
  121. package/dist/{validation-QCGRFRFZ.js → validation-FMEAEKCY.js} +6 -5
  122. package/migrations/0000_initial.sql +115 -0
  123. package/migrations/0001_conversation_metrics.sql +4 -0
  124. package/migrations/README.md +12 -30
  125. package/migrations/meta/0000_snapshot.json +1 -33
  126. package/migrations/meta/0001_snapshot.json +972 -0
  127. package/migrations/meta/_journal.json +9 -2
  128. package/package.json +14 -18
  129. package/dist/api/people/types.d.ts +0 -85
  130. package/dist/chat/advisor-request.d.ts +0 -4
  131. package/dist/chat/conversations/sql/migrations.d.ts +0 -22
  132. package/dist/chat/tools/advisor/session-store.d.ts +0 -9
  133. package/dist/chat/tools/advisor/tool.d.ts +0 -72
  134. package/dist/chunk-N4RNJ32C.js +0 -48
  135. package/dist/chunk-RAIB6WSG.js +0 -142
  136. package/dist/db/schema/migrations.d.ts +0 -58
  137. package/dist/reporting/conversations/context.d.ts +0 -8
  138. package/dist/reporting/conversations/details.d.ts +0 -6
  139. package/dist/reporting/conversations/index.d.ts +0 -4
  140. package/dist/reporting/conversations/statistics.d.ts +0 -4
  141. package/dist/reporting/conversations/summaries.d.ts +0 -17
  142. package/dist/reporting/conversations/types.d.ts +0 -178
  143. package/dist/reporting/conversations.d.ts +0 -1
  144. package/dist/reporting.js +0 -1065
@@ -0,0 +1,260 @@
1
+ import {
2
+ formatSlackConversationRedactedLabel,
3
+ resolveSlackConversationContextFromThreadId
4
+ } from "./chunk-NG2AV7IB.js";
5
+ import {
6
+ getDb,
7
+ juniorConversations,
8
+ juniorDestinations,
9
+ juniorIdentities
10
+ } from "./chunk-35BNLDOJ.js";
11
+ import {
12
+ parseSlackThreadId,
13
+ resolveConversationPrivacy
14
+ } from "./chunk-LVA4I4H7.js";
15
+
16
+ // src/api/conversations/list.query.ts
17
+ import { asc, desc, eq, isNull } from "drizzle-orm";
18
+
19
+ // src/api/conversations/shared.ts
20
+ function slackStatsLocationLabel(input) {
21
+ const channelId = input.channel;
22
+ if (!channelId) return void 0;
23
+ if (input.channelNameRedacted && input.channelName) {
24
+ return input.channelName;
25
+ }
26
+ const name = input.channelName?.replace(/^#/, "");
27
+ if (channelId.startsWith("D")) return "Direct Message";
28
+ if (channelId.startsWith("C")) return name ? `#${name}` : "Public Channel";
29
+ if (channelId.startsWith("G")) {
30
+ if (name?.startsWith("mpdm-")) return "Group DM";
31
+ return "Private Channel";
32
+ }
33
+ return name || channelId;
34
+ }
35
+ function surfaceFallbackLabel(surface) {
36
+ if (surface === "scheduler") return "Scheduler";
37
+ if (surface === "api") return "API";
38
+ if (surface === "internal") return "Internal";
39
+ return "Conversation";
40
+ }
41
+
42
+ // src/api/conversations/projection.ts
43
+ var HUNG_TURN_PROGRESS_MS = 5 * 60 * 1e3;
44
+ var PRIVATE_CONVERSATION_LABEL = "Private Conversation";
45
+ function privateConversationLabel(slackConversation) {
46
+ if (!slackConversation) {
47
+ return PRIVATE_CONVERSATION_LABEL;
48
+ }
49
+ return slackConversation.visibility === "private" ? formatSlackConversationRedactedLabel(slackConversation) ?? PRIVATE_CONVERSATION_LABEL : PRIVATE_CONVERSATION_LABEL;
50
+ }
51
+ function surfaceFromConversationId(conversationId) {
52
+ if (parseSlackThreadId(conversationId)) return "slack";
53
+ if (conversationId.startsWith("scheduler:")) return "scheduler";
54
+ if (conversationId.startsWith("api:")) return "api";
55
+ return "internal";
56
+ }
57
+ function surfaceFromSource(source, conversationId) {
58
+ if (source === "slack" || source === "api" || source === "scheduler") {
59
+ return source;
60
+ }
61
+ return surfaceFromConversationId(conversationId);
62
+ }
63
+ function actorIdentityReport(actor) {
64
+ if (!actor) return void 0;
65
+ const identity = {
66
+ ...actor.email !== void 0 ? { email: actor.email } : {},
67
+ ...actor.fullName !== void 0 ? { fullName: actor.fullName } : {},
68
+ ...actor.slackUserId !== void 0 ? { slackUserId: actor.slackUserId } : {},
69
+ ...actor.slackUserName !== void 0 ? { slackUserName: actor.slackUserName } : {}
70
+ };
71
+ return Object.keys(identity).length > 0 ? identity : void 0;
72
+ }
73
+ function statusFromConversation(conversation, nowMs) {
74
+ if (conversation.execution.status === "idle") {
75
+ return "completed";
76
+ }
77
+ if (conversation.execution.status === "failed") {
78
+ return "failed";
79
+ }
80
+ const updatedAtMs = conversation.execution.updatedAtMs ?? conversation.updatedAtMs;
81
+ if (conversation.execution.status === "running" && nowMs - updatedAtMs > HUNG_TURN_PROGRESS_MS) {
82
+ return "hung";
83
+ }
84
+ return "active";
85
+ }
86
+ function titleFromConversation(args) {
87
+ const slackThread = parseSlackThreadId(args.conversation.conversationId);
88
+ const effectiveChannelName = args.conversation.channelName;
89
+ const slackConversation = resolveSlackConversationContextFromThreadId({
90
+ threadId: args.conversation.conversationId,
91
+ channelName: effectiveChannelName
92
+ });
93
+ const privateLabel = resolveConversationPrivacy({
94
+ conversationId: args.conversation.conversationId,
95
+ visibility: args.conversation.visibility
96
+ }) !== "public" ? privateConversationLabel(slackConversation) : void 0;
97
+ return privateLabel ?? args.conversation.title ?? slackStatsLocationLabel({
98
+ channel: slackThread?.channelId,
99
+ channelName: effectiveChannelName
100
+ }) ?? surfaceFallbackLabel(args.surface);
101
+ }
102
+ function channelNameFromConversation(conversation) {
103
+ const effectiveChannelName = conversation.channelName;
104
+ const slackThread = parseSlackThreadId(conversation.conversationId);
105
+ if (!effectiveChannelName && !slackThread) {
106
+ return void 0;
107
+ }
108
+ const slackConversation = resolveSlackConversationContextFromThreadId({
109
+ threadId: conversation.conversationId,
110
+ channelName: effectiveChannelName
111
+ });
112
+ if (resolveConversationPrivacy({
113
+ conversationId: conversation.conversationId,
114
+ visibility: conversation.visibility
115
+ }) !== "public") {
116
+ return privateConversationLabel(slackConversation);
117
+ }
118
+ return effectiveChannelName;
119
+ }
120
+ function channelNameRedactedFromConversation(conversation) {
121
+ const effectiveChannelName = conversation.channelName;
122
+ const slackThread = parseSlackThreadId(conversation.conversationId);
123
+ if (!effectiveChannelName && !slackThread) {
124
+ return false;
125
+ }
126
+ return resolveConversationPrivacy({
127
+ conversationId: conversation.conversationId,
128
+ visibility: conversation.visibility
129
+ }) !== "public";
130
+ }
131
+ function conversationSummaryFromStoredConversation(args) {
132
+ const { conversation, durationMs, nowMs, usage } = args;
133
+ const surface = surfaceFromSource(
134
+ conversation.source,
135
+ conversation.conversationId
136
+ );
137
+ const actorIdentity = actorIdentityReport(conversation.actor);
138
+ const slackThread = parseSlackThreadId(conversation.conversationId);
139
+ const channelName = channelNameFromConversation(conversation);
140
+ const channelNameRedacted = channelNameRedactedFromConversation(conversation);
141
+ return {
142
+ conversationId: conversation.conversationId,
143
+ cumulativeDurationMs: durationMs,
144
+ displayTitle: titleFromConversation({ conversation, surface }),
145
+ lastProgressAt: new Date(
146
+ conversation.execution.updatedAtMs ?? conversation.updatedAtMs
147
+ ).toISOString(),
148
+ lastSeenAt: new Date(conversation.lastActivityAtMs).toISOString(),
149
+ startedAt: new Date(conversation.createdAtMs).toISOString(),
150
+ status: statusFromConversation(conversation, nowMs),
151
+ surface,
152
+ ...usage ? { cumulativeUsage: usage } : {},
153
+ ...actorIdentity ? { actorIdentity } : {},
154
+ ...slackThread ? { channel: slackThread.channelId } : {},
155
+ ...channelName ? { channelName } : {},
156
+ ...channelNameRedacted ? { channelNameRedacted: true } : {}
157
+ };
158
+ }
159
+
160
+ // src/api/conversations/list.query.ts
161
+ var CONVERSATION_FEED_LIMIT = 50;
162
+ async function conversationRows(db, limit) {
163
+ return db.select({
164
+ conversation: juniorConversations,
165
+ destinationVisibility: juniorDestinations.visibility,
166
+ identityDisplayName: juniorIdentities.displayName,
167
+ identityEmail: juniorIdentities.email,
168
+ identityHandle: juniorIdentities.handle,
169
+ identityProvider: juniorIdentities.provider,
170
+ identitySubjectId: juniorIdentities.providerSubjectId,
171
+ identityTenantId: juniorIdentities.providerTenantId
172
+ }).from(juniorConversations).leftJoin(
173
+ juniorDestinations,
174
+ eq(juniorDestinations.id, juniorConversations.destinationId)
175
+ ).leftJoin(
176
+ juniorIdentities,
177
+ eq(juniorIdentities.id, juniorConversations.actorIdentityId)
178
+ ).where(isNull(juniorConversations.parentConversationId)).orderBy(
179
+ desc(juniorConversations.lastActivityAt),
180
+ asc(juniorConversations.conversationId)
181
+ ).limit(limit);
182
+ }
183
+ function conversationFromRow(row) {
184
+ const value = row.conversation;
185
+ const actor = row.identityProvider === "slack" ? {
186
+ platform: "slack",
187
+ ...row.identityEmail ? { email: row.identityEmail } : {},
188
+ ...row.identityDisplayName ? { fullName: row.identityDisplayName } : {},
189
+ ...row.identitySubjectId ? { slackUserId: row.identitySubjectId } : {},
190
+ ...row.identityHandle ? { slackUserName: row.identityHandle } : {},
191
+ ...row.identityTenantId ? { teamId: row.identityTenantId } : {}
192
+ } : void 0;
193
+ return {
194
+ schemaVersion: 1,
195
+ conversationId: value.conversationId,
196
+ createdAtMs: value.createdAt.getTime(),
197
+ lastActivityAtMs: value.lastActivityAt.getTime(),
198
+ updatedAtMs: value.updatedAt.getTime(),
199
+ execution: {
200
+ status: value.executionStatus,
201
+ ...value.runId ? { runId: value.runId } : {},
202
+ ...value.executionUpdatedAt ? { updatedAtMs: value.executionUpdatedAt.getTime() } : {}
203
+ },
204
+ ...actor ? { actor } : {},
205
+ ...value.channelName ? { channelName: value.channelName } : {},
206
+ ...value.source ? { source: value.source } : {},
207
+ ...value.title ? { title: value.title } : {},
208
+ ...value.transcriptPurgedAt ? { transcriptPurgedAtMs: value.transcriptPurgedAt.getTime() } : {},
209
+ ...row.destinationVisibility ? {
210
+ visibility: row.destinationVisibility === "public" ? "public" : "private"
211
+ } : {}
212
+ };
213
+ }
214
+ async function readConversationRecordFromSql(conversationId) {
215
+ const db = getDb();
216
+ const rows = await db.select({
217
+ conversation: juniorConversations,
218
+ destinationVisibility: juniorDestinations.visibility,
219
+ identityDisplayName: juniorIdentities.displayName,
220
+ identityEmail: juniorIdentities.email,
221
+ identityHandle: juniorIdentities.handle,
222
+ identityProvider: juniorIdentities.provider,
223
+ identitySubjectId: juniorIdentities.providerSubjectId,
224
+ identityTenantId: juniorIdentities.providerTenantId
225
+ }).from(juniorConversations).leftJoin(
226
+ juniorDestinations,
227
+ eq(juniorDestinations.id, juniorConversations.destinationId)
228
+ ).leftJoin(
229
+ juniorIdentities,
230
+ eq(juniorIdentities.id, juniorConversations.actorIdentityId)
231
+ ).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
232
+ const row = rows[0];
233
+ return row ? {
234
+ conversation: conversationFromRow(row),
235
+ durationMs: row.conversation.durationMs,
236
+ usage: row.conversation.usage
237
+ } : void 0;
238
+ }
239
+ async function readConversationFeedFromSql(limit = CONVERSATION_FEED_LIMIT) {
240
+ const nowMs = Date.now();
241
+ const rows = await conversationRows(getDb(), limit);
242
+ return {
243
+ conversations: rows.map(
244
+ (row) => conversationSummaryFromStoredConversation({
245
+ conversation: conversationFromRow(row),
246
+ durationMs: row.conversation.durationMs,
247
+ nowMs,
248
+ usage: row.conversation.usage ?? void 0
249
+ })
250
+ ),
251
+ generatedAt: new Date(nowMs).toISOString(),
252
+ source: "conversation_index"
253
+ };
254
+ }
255
+
256
+ export {
257
+ conversationSummaryFromStoredConversation,
258
+ readConversationRecordFromSql,
259
+ readConversationFeedFromSql
260
+ };
@@ -0,0 +1,22 @@
1
+ // src/usage-schema.ts
2
+ import { z } from "zod";
3
+ var usageCostSchema = z.object({
4
+ input: z.number().finite().nonnegative().optional(),
5
+ output: z.number().finite().nonnegative().optional(),
6
+ cacheRead: z.number().finite().nonnegative().optional(),
7
+ cacheWrite: z.number().finite().nonnegative().optional(),
8
+ total: z.number().finite().nonnegative().optional()
9
+ }).strict();
10
+ var usageSchema = z.object({
11
+ inputTokens: z.number().int().nonnegative().optional(),
12
+ outputTokens: z.number().int().nonnegative().optional(),
13
+ cachedInputTokens: z.number().int().nonnegative().optional(),
14
+ cacheCreationTokens: z.number().int().nonnegative().optional(),
15
+ reasoningTokens: z.number().int().nonnegative().optional(),
16
+ totalTokens: z.number().int().nonnegative().optional(),
17
+ cost: usageCostSchema.optional()
18
+ }).strict();
19
+
20
+ export {
21
+ usageSchema
22
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ healthReportSchema
3
+ } from "./chunk-CEA3A3UA.js";
4
+
5
+ // src/handlers/health.ts
6
+ function readHealthReport() {
7
+ return healthReportSchema.parse({
8
+ status: "ok",
9
+ service: "junior",
10
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
11
+ });
12
+ }
13
+ function GET() {
14
+ return Response.json(readHealthReport());
15
+ }
16
+
17
+ export {
18
+ readHealthReport,
19
+ GET
20
+ };
@@ -9,13 +9,11 @@ import {
9
9
  getPersistedThreadState,
10
10
  markTurnCompleted,
11
11
  mergeArtifactsState
12
- } from "./chunk-KDPCGVIT.js";
13
- import {
14
- coerceThreadConversationState
15
- } from "./chunk-RAIB6WSG.js";
12
+ } from "./chunk-WGXMTFNU.js";
16
13
  import {
14
+ coerceThreadConversationState,
17
15
  getAgentTurnSessionRecord
18
- } from "./chunk-WAGQ377B.js";
16
+ } from "./chunk-WJOSZOON.js";
19
17
  import {
20
18
  generateConversationId,
21
19
  hydrateConversationMessages,
@@ -23,19 +21,19 @@ import {
23
21
  normalizeConversationText,
24
22
  updateConversationStats,
25
23
  upsertConversationMessage
26
- } from "./chunk-CRRBJ3JP.js";
24
+ } from "./chunk-3F4OPKGF.js";
27
25
  import {
28
26
  createPluginEmbedder,
29
27
  createPluginModel,
30
28
  getPlugins
31
- } from "./chunk-NSCHU54X.js";
29
+ } from "./chunk-5HLDPVYS.js";
32
30
  import {
33
31
  createPluginLogger,
34
32
  createPluginState
35
- } from "./chunk-E3E2XNCN.js";
33
+ } from "./chunk-EOWXRY5E.js";
36
34
  import {
37
35
  getDb
38
- } from "./chunk-6ONME5IG.js";
36
+ } from "./chunk-35BNLDOJ.js";
39
37
  import {
40
38
  GEN_AI_PROVIDER_NAME,
41
39
  botConfig,
@@ -46,10 +44,10 @@ import {
46
44
  isToolResultMessage,
47
45
  normalizeToolNameFromResult,
48
46
  stripRuntimeTurnContext
49
- } from "./chunk-GUE7HTNR.js";
47
+ } from "./chunk-EEZCY5WX.js";
50
48
  import {
51
49
  buildTurnFailureResponse
52
- } from "./chunk-WPOJ443W.js";
50
+ } from "./chunk-I35CTGPO.js";
53
51
  import {
54
52
  parseSlackMessageTs
55
53
  } from "./chunk-7FBGKXPE.js";
@@ -0,0 +1,11 @@
1
+ // src/api/schema.ts
2
+ import { z } from "zod";
3
+ var conversationParamsSchema = z.object({ conversationId: z.string().min(1) }).strict();
4
+ var subagentParamsSchema = conversationParamsSchema.extend({ subagentId: z.string().min(1) }).strict();
5
+ var personParamsSchema = z.object({ email: z.string().trim().min(1) }).strict();
6
+
7
+ export {
8
+ conversationParamsSchema,
9
+ subagentParamsSchema,
10
+ personParamsSchema
11
+ };
@@ -0,0 +1,66 @@
1
+ import {
2
+ actorIdentitySchema,
3
+ conversationStatsItemSchema,
4
+ conversationSummaryReportSchema
5
+ } from "./chunk-LUAE4MGW.js";
6
+
7
+ // src/api/people/schema.ts
8
+ import { z } from "zod";
9
+ var peopleConversationSummaryReportSchema = conversationSummaryReportSchema.omit({
10
+ cumulativeUsage: true,
11
+ sentryTraceUrl: true,
12
+ traceId: true
13
+ });
14
+ var peopleConversationStatsItemSchema = conversationStatsItemSchema.omit({ costUsd: true });
15
+ var actorActivityDayReportSchema = z.object({
16
+ active: z.number(),
17
+ conversations: z.number(),
18
+ date: z.string(),
19
+ durationMs: z.number(),
20
+ failed: z.number(),
21
+ hung: z.number(),
22
+ tokens: z.number().optional()
23
+ }).strict();
24
+ var actorTotalsReportSchema = z.object({
25
+ active: z.number(),
26
+ activeDays: z.number(),
27
+ conversations: z.number(),
28
+ durationMs: z.number(),
29
+ failed: z.number(),
30
+ hung: z.number(),
31
+ tokens: z.number().optional()
32
+ }).strict();
33
+ var identifiedActorSchema = actorIdentitySchema.extend({ email: z.string().min(1) }).strict();
34
+ var actorSummaryReportSchema = actorTotalsReportSchema.extend({
35
+ firstSeenAt: z.string(),
36
+ lastSeenAt: z.string(),
37
+ actor: identifiedActorSchema
38
+ }).strict();
39
+ var actorDirectoryReportSchema = z.object({
40
+ generatedAt: z.string(),
41
+ people: z.array(actorSummaryReportSchema),
42
+ sampleLimit: z.number(),
43
+ sampleSize: z.number(),
44
+ source: z.literal("conversation_index"),
45
+ truncated: z.boolean()
46
+ }).strict();
47
+ var actorProfileReportSchema = z.object({
48
+ activityDays: z.array(actorActivityDayReportSchema),
49
+ generatedAt: z.string(),
50
+ locations: z.array(peopleConversationStatsItemSchema),
51
+ recentConversations: z.array(peopleConversationSummaryReportSchema),
52
+ actor: identifiedActorSchema,
53
+ sampleLimit: z.number(),
54
+ sampleSize: z.number(),
55
+ source: z.literal("conversation_index"),
56
+ surfaces: z.array(peopleConversationStatsItemSchema),
57
+ totals: actorTotalsReportSchema,
58
+ truncated: z.boolean(),
59
+ windowEnd: z.string(),
60
+ windowStart: z.string()
61
+ }).strict();
62
+
63
+ export {
64
+ actorDirectoryReportSchema,
65
+ actorProfileReportSchema
66
+ };
@@ -1,27 +1,26 @@
1
1
  import {
2
- buildConversationStatePatch
3
- } from "./chunk-RAIB6WSG.js";
4
- import {
2
+ JUNIOR_THREAD_STATE_TTL_MS,
5
3
  abandonAgentTurnSessionRecord,
4
+ addAgentTurnUsage,
5
+ buildConversationStatePatch,
6
6
  getAgentTurnSessionRecord,
7
7
  upsertAgentTurnSessionRecord
8
- } from "./chunk-WAGQ377B.js";
8
+ } from "./chunk-WJOSZOON.js";
9
9
  import {
10
- JUNIOR_THREAD_STATE_TTL_MS,
11
10
  persistConversationMessages
12
- } from "./chunk-CRRBJ3JP.js";
11
+ } from "./chunk-3F4OPKGF.js";
13
12
  import {
14
13
  sleep
15
- } from "./chunk-CZEX6KIQ.js";
14
+ } from "./chunk-4ZNGQH7C.js";
16
15
  import {
17
16
  getPiMessageRole,
18
17
  getStateAdapter,
19
18
  trimTrailingAssistantMessages
20
- } from "./chunk-GUE7HTNR.js";
19
+ } from "./chunk-EEZCY5WX.js";
21
20
  import {
22
21
  getActiveTraceId,
23
22
  logException
24
- } from "./chunk-WPOJ443W.js";
23
+ } from "./chunk-I35CTGPO.js";
25
24
  import {
26
25
  isRecord,
27
26
  toOptionalString
@@ -93,61 +92,6 @@ function markTurnFailed(args) {
93
92
  args.updateConversationStats(args.conversation);
94
93
  }
95
94
 
96
- // src/chat/usage.ts
97
- var COMPONENT_USAGE_FIELDS = [
98
- "inputTokens",
99
- "outputTokens",
100
- "cachedInputTokens",
101
- "cacheCreationTokens"
102
- ];
103
- function hasAgentTurnUsage(usage) {
104
- return Boolean(
105
- usage && Object.values(usage).some(
106
- (value) => typeof value === "number" && Number.isFinite(value)
107
- )
108
- );
109
- }
110
- function getFiniteCount(value) {
111
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
112
- }
113
- function getComponentTotal(usage) {
114
- let total;
115
- for (const field of COMPONENT_USAGE_FIELDS) {
116
- const value = getFiniteCount(usage[field]);
117
- if (value === void 0) continue;
118
- total = (total ?? 0) + value;
119
- }
120
- return total;
121
- }
122
- function addAgentTurnUsage(...usages) {
123
- const components = {};
124
- let componentTotal;
125
- let totalOnlyTokens;
126
- for (const usage of usages) {
127
- if (!usage) continue;
128
- const usageComponentTotal = getComponentTotal(usage);
129
- if (usageComponentTotal !== void 0) {
130
- componentTotal = (componentTotal ?? 0) + usageComponentTotal;
131
- for (const field of COMPONENT_USAGE_FIELDS) {
132
- const value = getFiniteCount(usage[field]);
133
- if (value === void 0) continue;
134
- components[field] = (components[field] ?? 0) + value;
135
- }
136
- continue;
137
- }
138
- const totalTokens = getFiniteCount(usage.totalTokens);
139
- if (totalTokens !== void 0) {
140
- totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
141
- }
142
- }
143
- if (totalOnlyTokens !== void 0) {
144
- return {
145
- totalTokens: totalOnlyTokens + (componentTotal ?? 0)
146
- };
147
- }
148
- return hasAgentTurnUsage(components) ? components : void 0;
149
- }
150
-
151
95
  // src/chat/services/persist-retry.ts
152
96
  var PERSIST_ATTEMPTS = 3;
153
97
  async function persistWithRetry(persist) {
@@ -178,7 +122,7 @@ function logSessionRecordError(error, eventName, args, attributes, message) {
178
122
  slackChannelId: args.logContext.channelId,
179
123
  runId: args.logContext.runId,
180
124
  assistantUserName: args.logContext.assistantUserName,
181
- modelId: args.logContext.modelId
125
+ modelId: args.modelId
182
126
  },
183
127
  {
184
128
  "app.ai.resume_conversation_id": args.conversationId,
@@ -244,7 +188,7 @@ async function persistRunningSessionRecord(args) {
244
188
  ...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
245
189
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
246
190
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
247
- ...args.modelId ? { modelId: args.modelId } : {},
191
+ modelId: args.modelId,
248
192
  ...args.reasoningLevel ? { reasoningLevel: args.reasoningLevel } : {},
249
193
  ...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
250
194
  ...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
@@ -280,7 +224,7 @@ async function persistCompletedSessionRecord(args) {
280
224
  "Completed session record requires a slice id from the caller or the latest stored record"
281
225
  );
282
226
  }
283
- const modelId = latestSessionRecord?.modelId ?? args.modelId ?? args.logContext.modelId;
227
+ const modelId = args.modelId;
284
228
  const reasoningLevel = args.reasoningLevel ?? latestSessionRecord?.reasoningLevel;
285
229
  const target = {
286
230
  ...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
@@ -304,7 +248,7 @@ async function persistCompletedSessionRecord(args) {
304
248
  ...args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames ? {
305
249
  loadedSkillNames: args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames
306
250
  } : {},
307
- ...modelId ? { modelId } : {},
251
+ modelId,
308
252
  ...reasoningLevel ? { reasoningLevel } : {},
309
253
  ...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
310
254
  ...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
@@ -330,7 +274,7 @@ async function completeDeliveredTurn(args) {
330
274
  allMessages: args.messages,
331
275
  loadedSkillNames: args.loadedSkillNames,
332
276
  logContext: args.logContext,
333
- modelId: args.logContext.modelId,
277
+ modelId: args.modelId,
334
278
  actor: args.actor,
335
279
  reasoningLevel: args.reasoningLevel,
336
280
  surface: args.surface,
@@ -370,7 +314,7 @@ async function persistAuthPauseSessionRecord(args) {
370
314
  piMessages,
371
315
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
372
316
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
373
- ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
317
+ modelId: args.modelId,
374
318
  ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
375
319
  reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
376
320
  } : {},
@@ -434,7 +378,7 @@ async function persistTimeoutSessionRecord(args) {
434
378
  piMessages,
435
379
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
436
380
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
437
- ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
381
+ modelId: args.modelId,
438
382
  ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
439
383
  reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
440
384
  } : {},
@@ -458,7 +402,7 @@ async function persistTimeoutSessionRecord(args) {
458
402
  piMessages,
459
403
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
460
404
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
461
- ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
405
+ modelId: args.modelId,
462
406
  ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
463
407
  reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
464
408
  } : {},
@@ -514,7 +458,7 @@ async function persistYieldSessionRecord(args) {
514
458
  piMessages,
515
459
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
516
460
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
517
- ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
461
+ modelId: args.modelId,
518
462
  ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
519
463
  reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
520
464
  } : {},
@@ -993,8 +937,6 @@ export {
993
937
  markTurnClosed,
994
938
  markTurnCompleted,
995
939
  markTurnFailed,
996
- hasAgentTurnUsage,
997
- addAgentTurnUsage,
998
940
  persistWithRetry,
999
941
  loadTurnSessionRecord,
1000
942
  persistRunningSessionRecord,