@sentry/junior 0.103.0 → 0.104.1

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 (77) hide show
  1. package/dist/{agent-hooks-NHIXBJW3.js → agent-hooks-EOFSY2PD.js} +3 -3
  2. package/dist/api/conversations/archive.d.ts +7 -0
  3. package/dist/api/conversations/detail.d.ts +7 -0
  4. package/dist/api/conversations/list.d.ts +109 -0
  5. package/dist/api/conversations/routes.d.ts +3 -0
  6. package/dist/api/conversations/schema.d.ts +72 -69
  7. package/dist/api/conversations/stats.d.ts +7 -0
  8. package/dist/api/conversations/subagent.d.ts +7 -0
  9. package/dist/api/http.d.ts +5 -0
  10. package/dist/api/locations/detail.d.ts +10 -2
  11. package/dist/api/locations/list.d.ts +7 -0
  12. package/dist/api/locations/routes.d.ts +3 -0
  13. package/dist/api/locations/schema.d.ts +4 -3
  14. package/dist/api/people/list.d.ts +7 -0
  15. package/dist/api/people/profile.d.ts +7 -0
  16. package/dist/api/people/routes.d.ts +3 -0
  17. package/dist/api/people/schema.d.ts +35 -33
  18. package/dist/api/people/shared.d.ts +3 -3
  19. package/dist/api/route.d.ts +7 -0
  20. package/dist/api/schema.js +11 -17
  21. package/dist/api.js +2184 -88
  22. package/dist/app.js +107 -101
  23. package/dist/chat/conversations/history.d.ts +6 -6
  24. package/dist/chat/conversations/store.d.ts +1 -0
  25. package/dist/chat/pi/messages.d.ts +2 -2
  26. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  27. package/dist/chat/resource-events/store.d.ts +2 -2
  28. package/dist/chat/slack/tools/conversation-search.d.ts +2 -2
  29. package/dist/chat/state/session-log.d.ts +2 -2
  30. package/dist/chat/task-execution/store.d.ts +2 -2
  31. package/dist/chat/tools/search-tools.d.ts +2 -2
  32. package/dist/chunk-AIRE7Q2W.js +362 -0
  33. package/dist/{chunk-HOBDQQJY.js → chunk-BCULHGZK.js} +23 -3
  34. package/dist/{chunk-DEQZ23O3.js → chunk-O7ILGCMJ.js} +77 -0
  35. package/dist/{chunk-C4BT2P2K.js → chunk-QDKRE3LS.js} +339 -8
  36. package/dist/{chunk-GY5ZRYPH.js → chunk-QVTVCJR4.js} +5 -5
  37. package/dist/{chunk-JXQWOCBE.js → chunk-RMZ65YAA.js} +2 -2
  38. package/dist/{chunk-E2VS47AZ.js → chunk-RYDF4GOX.js} +2 -2
  39. package/dist/{chunk-OE453VRG.js → chunk-TMWUGGSA.js} +26 -28
  40. package/dist/{chunk-JPXLAJUU.js → chunk-VDHMFCDY.js} +9 -10
  41. package/dist/cli/chat.js +10 -11
  42. package/dist/cli/plugins.js +4 -4
  43. package/dist/cli/upgrade.js +3 -4
  44. package/dist/db/schema/conversations.d.ts +17 -0
  45. package/dist/db/schema.d.ts +17 -0
  46. package/dist/{db-I343BSOM.js → db-PDMC67T3.js} +1 -1
  47. package/dist/{legacy-import-M7VBOQTK.js → legacy-import-G333RHJZ.js} +2 -2
  48. package/dist/reporting-schema.d.ts +4 -4
  49. package/dist/{runner-IEE5G4NV.js → runner-6A7MQRUE.js} +7 -8
  50. package/migrations/0004_useful_magus.sql +1 -0
  51. package/migrations/meta/0004_snapshot.json +1041 -0
  52. package/migrations/meta/_journal.json +7 -0
  53. package/package.json +6 -6
  54. package/dist/api/conversations/list.query.d.ts +0 -103
  55. package/dist/chunk-2RNOB32R.js +0 -17
  56. package/dist/chunk-6FPTHPXF.js +0 -77
  57. package/dist/chunk-6LBNXC4F.js +0 -66
  58. package/dist/chunk-7LLRS2OK.js +0 -215
  59. package/dist/chunk-B43K4C5K.js +0 -102
  60. package/dist/chunk-BQCPAIAB.js +0 -319
  61. package/dist/chunk-FW7DVHTL.js +0 -673
  62. package/dist/chunk-GCGRQJR5.js +0 -84
  63. package/dist/chunk-HRDWLE7Q.js +0 -273
  64. package/dist/chunk-LVUKF5CE.js +0 -63
  65. package/dist/chunk-QNVHH5PU.js +0 -20
  66. package/dist/chunk-QOZOJNSE.js +0 -96
  67. package/dist/chunk-VKFOVMZL.js +0 -331
  68. package/dist/detail-ENVV4HIY.js +0 -68
  69. package/dist/detail-UIOKVIET.js +0 -29
  70. package/dist/list-WR5U6JVM.js +0 -30
  71. package/dist/list-XZ4HKQ4R.js +0 -121
  72. package/dist/list-ZOUSMSEH.js +0 -30
  73. package/dist/plugin-conversations-DTUP4RH6.js +0 -37
  74. package/dist/profile-UO2N3XXG.js +0 -212
  75. package/dist/reporting/plugin-conversations.d.ts +0 -3
  76. package/dist/stats-NZIET4LT.js +0 -174
  77. package/dist/subagent-DY6XKTJ5.js +0 -49
@@ -1,84 +0,0 @@
1
- import {
2
- actorIdentitySchema,
3
- conversationStatsItemSchema,
4
- conversationSummaryReportSchema
5
- } from "./chunk-7LLRS2OK.js";
6
- import {
7
- juniorDestinationKindSchema
8
- } from "./chunk-FXFQNHRU.js";
9
-
10
- // src/api/activity.ts
11
- import { z } from "zod";
12
- var dailyConversationActivitySchema = z.object({
13
- active: z.number(),
14
- conversations: z.number(),
15
- date: z.string(),
16
- durationMs: z.number(),
17
- failed: z.number(),
18
- tokens: z.number().optional()
19
- }).strict();
20
- function emptyActivityDay(date) {
21
- return {
22
- active: 0,
23
- conversations: 0,
24
- date,
25
- durationMs: 0,
26
- failed: 0
27
- };
28
- }
29
- function activityDays(days, nowMs, count) {
30
- const items = [];
31
- const end = new Date(nowMs);
32
- end.setUTCHours(0, 0, 0, 0);
33
- const start = new Date(end);
34
- start.setUTCDate(start.getUTCDate() - (count - 1));
35
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setUTCDate(cursor.getUTCDate() + 1)) {
36
- const date = cursor.toISOString().slice(0, 10);
37
- items.push(days.get(date) ?? emptyActivityDay(date));
38
- }
39
- return items;
40
- }
41
-
42
- // src/api/locations/schema.ts
43
- import { z as z2 } from "zod";
44
- var locationSummaryReportSchema = conversationStatsItemSchema.extend({
45
- id: z2.string(),
46
- firstSeenAt: z2.string(),
47
- kind: juniorDestinationKindSchema,
48
- lastSeenAt: z2.string(),
49
- provider: z2.string(),
50
- providerDestinationId: z2.string(),
51
- visibility: z2.literal("public")
52
- }).strict();
53
- var locationActorSummaryReportSchema = conversationStatsItemSchema.extend({ actor: actorIdentitySchema }).strict();
54
- var locationActivityDayReportSchema = z2.object({
55
- date: z2.string(),
56
- privateConversations: z2.number(),
57
- publicConversations: z2.number()
58
- }).strict();
59
- var locationDirectoryReportSchema = z2.object({
60
- activityDays: z2.array(locationActivityDayReportSchema),
61
- generatedAt: z2.string(),
62
- locations: z2.array(locationSummaryReportSchema),
63
- privateActivity: conversationStatsItemSchema,
64
- source: z2.literal("conversation_index"),
65
- windowEnd: z2.string(),
66
- windowStart: z2.string()
67
- }).strict();
68
- var locationDetailReportSchema = locationSummaryReportSchema.extend({
69
- activityDays: z2.array(dailyConversationActivitySchema),
70
- actors: z2.array(locationActorSummaryReportSchema),
71
- generatedAt: z2.string(),
72
- recentConversations: z2.array(conversationSummaryReportSchema),
73
- source: z2.literal("conversation_index"),
74
- windowEnd: z2.string(),
75
- windowStart: z2.string()
76
- }).strict();
77
-
78
- export {
79
- dailyConversationActivitySchema,
80
- activityDays,
81
- locationActivityDayReportSchema,
82
- locationDirectoryReportSchema,
83
- locationDetailReportSchema
84
- };
@@ -1,273 +0,0 @@
1
- import {
2
- formatSlackConversationRedactedLabel,
3
- resolveSlackConversationContextFromThreadId
4
- } from "./chunk-DEQZ23O3.js";
5
- import {
6
- getDb,
7
- juniorConversations,
8
- juniorIdentities
9
- } from "./chunk-HOBDQQJY.js";
10
- import {
11
- juniorDestinations
12
- } from "./chunk-FXFQNHRU.js";
13
- import {
14
- parseSlackThreadId,
15
- resolveConversationPrivacy
16
- } from "./chunk-RT5BUHR5.js";
17
-
18
- // src/api/conversations/list.query.ts
19
- import { and, asc, desc, eq, isNull } from "drizzle-orm";
20
-
21
- // src/api/conversations/shared.ts
22
- function slackStatsLocationLabel(input) {
23
- const channelId = input.channel;
24
- if (!channelId) return void 0;
25
- if (input.channelNameRedacted && input.channelName) {
26
- return input.channelName;
27
- }
28
- const name = input.channelName?.replace(/^#/, "");
29
- if (channelId.startsWith("D")) return "Direct Message";
30
- if (channelId.startsWith("C")) return name ? `#${name}` : "Public Channel";
31
- if (channelId.startsWith("G")) {
32
- if (name?.startsWith("mpdm-")) return "Group DM";
33
- return "Private Channel";
34
- }
35
- return name || channelId;
36
- }
37
- function surfaceFallbackLabel(surface) {
38
- if (surface === "scheduler") return "Scheduler";
39
- if (surface === "api") return "API";
40
- if (surface === "internal") return "Internal";
41
- return "Conversation";
42
- }
43
-
44
- // src/api/conversations/projection.ts
45
- var PRIVATE_CONVERSATION_LABEL = "Private Conversation";
46
- function privateConversationLabel(slackConversation) {
47
- if (!slackConversation) {
48
- return PRIVATE_CONVERSATION_LABEL;
49
- }
50
- return slackConversation.visibility === "private" ? formatSlackConversationRedactedLabel(slackConversation) ?? PRIVATE_CONVERSATION_LABEL : PRIVATE_CONVERSATION_LABEL;
51
- }
52
- function surfaceFromConversationId(conversationId) {
53
- if (parseSlackThreadId(conversationId)) return "slack";
54
- if (conversationId.startsWith("scheduler:")) return "scheduler";
55
- if (conversationId.startsWith("api:")) return "api";
56
- return "internal";
57
- }
58
- function surfaceFromSource(source, conversationId) {
59
- if (source === "slack" || source === "api" || source === "scheduler") {
60
- return source;
61
- }
62
- return surfaceFromConversationId(conversationId);
63
- }
64
- function actorIdentityReport(actor) {
65
- if (!actor) return void 0;
66
- const identity = {
67
- ...actor.email !== void 0 ? { email: actor.email } : {},
68
- ...actor.fullName !== void 0 ? { fullName: actor.fullName } : {},
69
- ...actor.slackUserId !== void 0 ? { slackUserId: actor.slackUserId } : {},
70
- ...actor.slackUserName !== void 0 ? { slackUserName: actor.slackUserName } : {}
71
- };
72
- return Object.keys(identity).length > 0 ? identity : void 0;
73
- }
74
- function statusFromConversation(conversation) {
75
- if (conversation.execution.status === "idle") {
76
- return "completed";
77
- }
78
- if (conversation.execution.status === "failed") {
79
- return "failed";
80
- }
81
- return "active";
82
- }
83
- function titleFromConversation(args) {
84
- const slackThread = parseSlackThreadId(args.conversation.conversationId);
85
- const effectiveChannelName = args.conversation.channelName;
86
- const slackConversation = resolveSlackConversationContextFromThreadId({
87
- threadId: args.conversation.conversationId,
88
- channelName: effectiveChannelName
89
- });
90
- const privateLabel = resolveConversationPrivacy({
91
- conversationId: args.conversation.conversationId,
92
- visibility: args.conversation.visibility
93
- }) !== "public" ? privateConversationLabel(slackConversation) : void 0;
94
- return privateLabel ?? args.conversation.title ?? slackStatsLocationLabel({
95
- channel: slackThread?.channelId,
96
- channelName: effectiveChannelName
97
- }) ?? surfaceFallbackLabel(args.surface);
98
- }
99
- function channelNameFromConversation(conversation) {
100
- const effectiveChannelName = conversation.channelName;
101
- const slackThread = parseSlackThreadId(conversation.conversationId);
102
- if (!effectiveChannelName && !slackThread) {
103
- return void 0;
104
- }
105
- const slackConversation = resolveSlackConversationContextFromThreadId({
106
- threadId: conversation.conversationId,
107
- channelName: effectiveChannelName
108
- });
109
- if (resolveConversationPrivacy({
110
- conversationId: conversation.conversationId,
111
- visibility: conversation.visibility
112
- }) !== "public") {
113
- return privateConversationLabel(slackConversation);
114
- }
115
- return effectiveChannelName;
116
- }
117
- function channelNameRedactedFromConversation(conversation) {
118
- const effectiveChannelName = conversation.channelName;
119
- const slackThread = parseSlackThreadId(conversation.conversationId);
120
- if (!effectiveChannelName && !slackThread) {
121
- return false;
122
- }
123
- return resolveConversationPrivacy({
124
- conversationId: conversation.conversationId,
125
- visibility: conversation.visibility
126
- }) !== "public";
127
- }
128
- function conversationSummaryFromStoredConversation(args) {
129
- const { conversation, durationMs, usage } = args;
130
- const surface = surfaceFromSource(
131
- conversation.source,
132
- conversation.conversationId
133
- );
134
- const actorIdentity = actorIdentityReport(conversation.actor);
135
- const slackThread = parseSlackThreadId(conversation.conversationId);
136
- const channelName = channelNameFromConversation(conversation);
137
- const channelNameRedacted = channelNameRedactedFromConversation(conversation);
138
- return {
139
- conversationId: conversation.conversationId,
140
- cumulativeDurationMs: durationMs,
141
- displayTitle: titleFromConversation({ conversation, surface }),
142
- lastProgressAt: new Date(
143
- conversation.execution.updatedAtMs ?? conversation.updatedAtMs
144
- ).toISOString(),
145
- lastSeenAt: new Date(conversation.lastActivityAtMs).toISOString(),
146
- startedAt: new Date(conversation.createdAtMs).toISOString(),
147
- status: statusFromConversation(conversation),
148
- surface,
149
- ...usage ? { cumulativeUsage: usage } : {},
150
- ...actorIdentity ? { actorIdentity } : {},
151
- ...slackThread ? { channel: slackThread.channelId } : {},
152
- ...channelName ? { channelName } : {},
153
- ...channelNameRedacted ? { channelNameRedacted: true } : {},
154
- ...args.locationId && !channelNameRedacted ? { locationId: args.locationId } : {}
155
- };
156
- }
157
-
158
- // src/api/conversations/list.query.ts
159
- var CONVERSATION_FEED_LIMIT = 50;
160
- async function conversationRows(db, limit, actorEmail) {
161
- return db.select({
162
- conversation: juniorConversations,
163
- destinationId: juniorDestinations.id,
164
- destinationVisibility: juniorDestinations.visibility,
165
- identityDisplayName: juniorIdentities.displayName,
166
- identityEmail: juniorIdentities.email,
167
- identityHandle: juniorIdentities.handle,
168
- identityProvider: juniorIdentities.provider,
169
- identitySubjectId: juniorIdentities.providerSubjectId,
170
- identityTenantId: juniorIdentities.providerTenantId
171
- }).from(juniorConversations).leftJoin(
172
- juniorDestinations,
173
- eq(juniorDestinations.id, juniorConversations.destinationId)
174
- ).leftJoin(
175
- juniorIdentities,
176
- eq(juniorIdentities.id, juniorConversations.actorIdentityId)
177
- ).where(
178
- and(
179
- isNull(juniorConversations.parentConversationId),
180
- actorEmail ? and(
181
- eq(juniorIdentities.emailNormalized, actorEmail),
182
- eq(juniorIdentities.emailVerified, true)
183
- ) : void 0
184
- )
185
- ).orderBy(
186
- desc(juniorConversations.lastActivityAt),
187
- asc(juniorConversations.conversationId)
188
- ).limit(limit);
189
- }
190
- function conversationFromRow(row) {
191
- const value = row.conversation;
192
- const actor = row.identityProvider === "slack" ? {
193
- platform: "slack",
194
- ...row.identityEmail ? { email: row.identityEmail } : {},
195
- ...row.identityDisplayName ? { fullName: row.identityDisplayName } : {},
196
- ...row.identitySubjectId ? { slackUserId: row.identitySubjectId } : {},
197
- ...row.identityHandle ? { slackUserName: row.identityHandle } : {},
198
- ...row.identityTenantId ? { teamId: row.identityTenantId } : {}
199
- } : void 0;
200
- return {
201
- schemaVersion: 1,
202
- conversationId: value.conversationId,
203
- createdAtMs: value.createdAt.getTime(),
204
- lastActivityAtMs: value.lastActivityAt.getTime(),
205
- updatedAtMs: value.updatedAt.getTime(),
206
- execution: {
207
- status: value.executionStatus,
208
- ...value.runId ? { runId: value.runId } : {},
209
- ...value.executionUpdatedAt ? { updatedAtMs: value.executionUpdatedAt.getTime() } : {}
210
- },
211
- ...actor ? { actor } : {},
212
- ...value.channelName ? { channelName: value.channelName } : {},
213
- ...value.source ? { source: value.source } : {},
214
- ...value.title ? { title: value.title } : {},
215
- ...value.transcriptPurgedAt ? { transcriptPurgedAtMs: value.transcriptPurgedAt.getTime() } : {},
216
- ...row.destinationVisibility ? {
217
- visibility: row.destinationVisibility === "public" ? "public" : "private"
218
- } : {}
219
- };
220
- }
221
- async function readConversationRecordFromSql(conversationId) {
222
- const db = getDb();
223
- const rows = await db.select({
224
- conversation: juniorConversations,
225
- destinationId: juniorDestinations.id,
226
- destinationVisibility: juniorDestinations.visibility,
227
- identityDisplayName: juniorIdentities.displayName,
228
- identityEmail: juniorIdentities.email,
229
- identityHandle: juniorIdentities.handle,
230
- identityProvider: juniorIdentities.provider,
231
- identitySubjectId: juniorIdentities.providerSubjectId,
232
- identityTenantId: juniorIdentities.providerTenantId
233
- }).from(juniorConversations).leftJoin(
234
- juniorDestinations,
235
- eq(juniorDestinations.id, juniorConversations.destinationId)
236
- ).leftJoin(
237
- juniorIdentities,
238
- eq(juniorIdentities.id, juniorConversations.actorIdentityId)
239
- ).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
240
- const row = rows[0];
241
- return row ? {
242
- conversation: conversationFromRow(row),
243
- durationMs: row.conversation.durationMs,
244
- ...row.destinationVisibility === "public" && row.destinationId ? { locationId: row.destinationId } : {},
245
- usage: row.conversation.usage
246
- } : void 0;
247
- }
248
- async function readConversationFeedFromSql(options = {}) {
249
- const nowMs = Date.now();
250
- const rows = await conversationRows(
251
- getDb(),
252
- options.limit ?? CONVERSATION_FEED_LIMIT,
253
- options.actorEmail
254
- );
255
- return {
256
- conversations: rows.map(
257
- (row) => conversationSummaryFromStoredConversation({
258
- conversation: conversationFromRow(row),
259
- durationMs: row.conversation.durationMs,
260
- ...row.destinationVisibility === "public" && row.destinationId ? { locationId: row.destinationId } : {},
261
- usage: row.conversation.usage ?? void 0
262
- })
263
- ),
264
- generatedAt: new Date(nowMs).toISOString(),
265
- source: "conversation_index"
266
- };
267
- }
268
-
269
- export {
270
- conversationSummaryFromStoredConversation,
271
- readConversationRecordFromSql,
272
- readConversationFeedFromSql
273
- };
@@ -1,63 +0,0 @@
1
- import {
2
- getClient
3
- } from "./chunk-6GWA276C.js";
4
-
5
- // src/chat/sentry-links.ts
6
- function getSentryOrgSlug() {
7
- const slug = process.env.SENTRY_ORG_SLUG?.trim();
8
- return slug || void 0;
9
- }
10
- function isSentrySaasDsnHost(host) {
11
- return host === "sentry.io" || host.endsWith(".sentry.io");
12
- }
13
- function buildSentryWebBaseUrl(dsn) {
14
- if (isSentrySaasDsnHost(dsn.host)) {
15
- return "https://sentry.io";
16
- }
17
- const port = dsn.port ? `:${dsn.port}` : "";
18
- const path = dsn.path ? `/${dsn.path}` : "";
19
- return `${dsn.protocol}://${dsn.host}${port}${path}`;
20
- }
21
- function buildSentryConversationUrl(conversationId) {
22
- const client = getClient();
23
- const dsn = client?.getDsn();
24
- if (!dsn?.host || !dsn.projectId) {
25
- return void 0;
26
- }
27
- const orgSlug = getSentryOrgSlug();
28
- if (!orgSlug) {
29
- return void 0;
30
- }
31
- const encodedId = encodeURIComponent(conversationId);
32
- const params = new URLSearchParams();
33
- params.set("project", dsn.projectId);
34
- const path = `explore/conversations/${encodedId}/?${params.toString()}`;
35
- if (isSentrySaasDsnHost(dsn.host)) {
36
- return `https://${orgSlug}.sentry.io/${path}`;
37
- }
38
- return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
39
- }
40
- function buildSentryTraceUrl(traceId) {
41
- const client = getClient();
42
- const dsn = client?.getDsn();
43
- if (!dsn?.host || !dsn.projectId) {
44
- return void 0;
45
- }
46
- const orgSlug = getSentryOrgSlug();
47
- if (!orgSlug) {
48
- return void 0;
49
- }
50
- const encodedTraceId = encodeURIComponent(traceId);
51
- const params = new URLSearchParams();
52
- params.set("project", dsn.projectId);
53
- const path = `performance/trace/${encodedTraceId}/?${params.toString()}`;
54
- if (isSentrySaasDsnHost(dsn.host)) {
55
- return `https://${orgSlug}.sentry.io/${path}`;
56
- }
57
- return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
58
- }
59
-
60
- export {
61
- buildSentryConversationUrl,
62
- buildSentryTraceUrl
63
- };
@@ -1,20 +0,0 @@
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
- };
@@ -1,96 +0,0 @@
1
- // src/api/conversations/reporting.ts
2
- var PRIVATE_CONVERSATION_LABEL = "Private Conversation";
3
- function channelFromConversationId(conversationId) {
4
- const [provider, channel] = conversationId.split(":");
5
- return provider === "slack" && channel ? channel : void 0;
6
- }
7
- function surfaceFromRow(row) {
8
- if (row.source === "api" || row.source === "scheduler" || row.source === "slack") {
9
- return row.source;
10
- }
11
- if (row.conversationId.startsWith("slack:")) return "slack";
12
- if (row.conversationId.startsWith("scheduler:")) return "scheduler";
13
- if (row.conversationId.startsWith("api:")) return "api";
14
- return "internal";
15
- }
16
- function statusFromRow(row) {
17
- if (row.executionStatus === "failed") return "failed";
18
- if (row.executionStatus === "idle") return "completed";
19
- return "active";
20
- }
21
- function surfaceLabel(surface) {
22
- if (surface === "scheduler") return "Scheduler";
23
- if (surface === "api") return "API";
24
- if (surface === "internal") return "Internal";
25
- return "Conversation";
26
- }
27
- function slackLocationLabel(args) {
28
- const channelId = args.channel;
29
- if (!channelId) return void 0;
30
- if (args.channelNameRedacted && args.channelName) return args.channelName;
31
- const name = args.channelName?.replace(/^#/, "");
32
- if (channelId.startsWith("D")) return "Direct Message";
33
- if (channelId.startsWith("C")) {
34
- return name ? `#${name}` : "Public Channel";
35
- }
36
- if (channelId.startsWith("G")) {
37
- if (name?.startsWith("mpdm-")) return "Group DM";
38
- return "Private Channel";
39
- }
40
- return name || channelId;
41
- }
42
- function channelNameFromRow(row) {
43
- if (row.destinationVisibility !== "public") {
44
- return PRIVATE_CONVERSATION_LABEL;
45
- }
46
- return row.channelName ?? void 0;
47
- }
48
- function titleFromRow(row, surface) {
49
- if (row.destinationVisibility !== "public") {
50
- return PRIVATE_CONVERSATION_LABEL;
51
- }
52
- const channel = channelFromConversationId(row.conversationId);
53
- return row.title ?? slackLocationLabel({
54
- channel,
55
- channelName: row.channelName ?? void 0
56
- }) ?? surfaceLabel(surface);
57
- }
58
- function actorFromRow(row) {
59
- const actor = {
60
- ...row.email ? { email: row.email } : {},
61
- ...row.fullName ? { fullName: row.fullName } : {},
62
- ...row.providerSubjectId ? { slackUserId: row.providerSubjectId } : {},
63
- ...row.handle ? { slackUserName: row.handle } : {}
64
- };
65
- return Object.keys(actor).length ? actor : void 0;
66
- }
67
- function summaryFromRow(row) {
68
- const surface = surfaceFromRow(row);
69
- const channel = channelFromConversationId(row.conversationId);
70
- const channelName = channelNameFromRow(row);
71
- const channelNameRedacted = row.destinationVisibility !== "public";
72
- const actorIdentity = actorFromRow(row);
73
- return {
74
- conversationId: row.conversationId,
75
- cumulativeDurationMs: row.durationMs,
76
- displayTitle: titleFromRow(row, surface),
77
- lastProgressAt: new Date(
78
- row.executionUpdatedAt ?? row.updatedAt
79
- ).toISOString(),
80
- lastSeenAt: row.lastActivityAt.toISOString(),
81
- startedAt: row.createdAt.toISOString(),
82
- status: statusFromRow(row),
83
- surface,
84
- ...actorIdentity ? { actorIdentity } : {},
85
- ...channel ? { channel } : {},
86
- ...channelName ? { channelName } : {},
87
- ...channelNameRedacted ? { channelNameRedacted: true } : {},
88
- ...row.destinationVisibility === "public" && row.destinationId ? { locationId: row.destinationId } : {}
89
- };
90
- }
91
-
92
- export {
93
- surfaceLabel,
94
- slackLocationLabel,
95
- summaryFromRow
96
- };