@sentry/junior 0.157.0 → 0.159.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.
- package/dist/{agent-hooks-QI5EPOKQ.js → agent-hooks-IAD3AANZ.js} +10 -10
- package/dist/api/conversations/cancel-pending-messages.d.ts +4 -0
- package/dist/api/conversations/priority.d.ts +2 -1
- package/dist/api/conversations/user-message-activity.d.ts +3 -0
- package/dist/api/schema/conversation.d.ts +13 -0
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +5 -1
- package/dist/api.js +280 -175
- package/dist/app.js +32 -32
- package/dist/{catalog-runtime-HUGHAFUN.js → catalog-runtime-6VANKLH5.js} +5 -5
- package/dist/chat/conversations/history.d.ts +4 -1
- package/dist/chat/slack/mrkdwn.d.ts +2 -1
- package/dist/chat/task-execution/state.d.ts +10 -0
- package/dist/chat/task-execution/store.d.ts +11 -0
- package/dist/{chunk-7J65DOBL.js → chunk-27UQ7UB3.js} +6 -6
- package/dist/{chunk-GEY6IFXH.js → chunk-54O6IKUS.js} +4 -4
- package/dist/{chunk-XRERMHPN.js → chunk-6IADZQJR.js} +1 -1
- package/dist/{chunk-VIBHFGQC.js → chunk-AIQKUJKK.js} +4 -4
- package/dist/{chunk-AFQ47JQ7.js → chunk-AZW5HKC5.js} +8 -8
- package/dist/{chunk-6MI43QZO.js → chunk-CNHELV2P.js} +1 -1
- package/dist/{chunk-VDAEXEBB.js → chunk-DJZPA72K.js} +35 -6
- package/dist/{chunk-TA5R6BME.js → chunk-DXSZJAVZ.js} +18 -18
- package/dist/{chunk-MGJW3SW4.js → chunk-EBP6IS66.js} +6 -6
- package/dist/{chunk-CZCMFRUQ.js → chunk-EQXVKNLM.js} +11 -0
- package/dist/{chunk-BLCVTEE7.js → chunk-FWDN67U3.js} +55 -4
- package/dist/{chunk-VYDM7HUF.js → chunk-IJ6KWS3V.js} +1 -1
- package/dist/{chunk-MDZQ62PB.js → chunk-K2LAI7RW.js} +2 -2
- package/dist/{chunk-UJYA75N5.js → chunk-L2PEQ2PY.js} +2 -2
- package/dist/{chunk-46ADYIPE.js → chunk-LUIKMY35.js} +1 -1
- package/dist/{chunk-PP4UQTH3.js → chunk-NCJV265M.js} +9 -9
- package/dist/{chunk-HJ3EZHIX.js → chunk-NT6V5WEE.js} +5 -5
- package/dist/{chunk-3GS7O66Z.js → chunk-O2DZWUPQ.js} +1 -1
- package/dist/{chunk-F7VOY4VQ.js → chunk-OGMHLKNO.js} +1 -1
- package/dist/{chunk-GO2W3VZY.js → chunk-PQWWCKNB.js} +4 -4
- package/dist/{chunk-D7BNWRYL.js → chunk-PT7B6A3O.js} +1 -1
- package/dist/{chunk-I3OQVVMV.js → chunk-Q5X37U6G.js} +1 -1
- package/dist/{chunk-G2FN3I66.js → chunk-QODFNKQS.js} +27 -10
- package/dist/{chunk-OWASYHHV.js → chunk-SQOVZSWF.js} +20 -18
- package/dist/{chunk-MKA3T2R6.js → chunk-TD7ZQZ5W.js} +1 -1
- package/dist/{chunk-RQBRGPUF.js → chunk-U7D4VLUF.js} +2 -2
- package/dist/{chunk-4M25PSFB.js → chunk-UG673UVL.js} +1 -1
- package/dist/{chunk-5TIH5GOE.js → chunk-UKKOKMRE.js} +5 -5
- package/dist/{chunk-MXO6VFB3.js → chunk-UP6KQVF5.js} +1 -1
- package/dist/{chunk-S4PFOWRA.js → chunk-WTQ3CKC3.js} +1 -1
- package/dist/{chunk-WNNYOPXX.js → chunk-X7AIXRVJ.js} +5 -5
- package/dist/{chunk-77QB5FNI.js → chunk-YCBZ47LC.js} +1 -1
- package/dist/{chunk-VBKFO65J.js → chunk-YSMAMSOU.js} +10 -10
- package/dist/cli/chat.js +30 -30
- package/dist/cli/check.js +6 -6
- package/dist/cli/plugins.js +13 -13
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +7 -7
- package/dist/{db-VQAV4PJ3.js → db-BIIMAPFB.js} +7 -7
- package/dist/instrumentation.js +4 -4
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-K5KQAAAX.js → oauth-callback-server-4BENCPP3.js} +23 -23
- package/dist/{runner-U7QI7P4S.js → runner-TUBJLEYO.js} +13 -13
- package/dist/{skills-ENKRBZ7K.js → skills-MBRLNBRV.js} +6 -6
- package/dist/spawn-ZWIXA46E.js +37 -0
- package/dist/{validation-VKCDVGA6.js → validation-YTJGRJYT.js} +6 -6
- package/dist/version.js +1 -1
- package/dist/{work-IBD6PWP2.js → work-5MRHKA54.js} +17 -17
- package/dist/worker-S2V7HZJ4.js +24 -0
- package/package.json +4 -4
- package/dist/spawn-4XGNONLS.js +0 -37
- package/dist/worker-TJFXOZRC.js +0 -24
package/dist/api.js
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
apiErrorSchema,
|
|
7
7
|
archiveConversationBodySchema,
|
|
8
8
|
archiveConversationResponseSchema,
|
|
9
|
+
cancelConversationPendingMessagesBodySchema,
|
|
10
|
+
cancelConversationPendingMessagesResponseSchema,
|
|
9
11
|
conversationAttachmentParamsSchema,
|
|
10
12
|
conversationDetailQuerySchema,
|
|
11
13
|
conversationDetailReportSchema,
|
|
@@ -34,7 +36,7 @@ import {
|
|
|
34
36
|
taskListSchema,
|
|
35
37
|
taskParamsSchema,
|
|
36
38
|
taskRunListSchema
|
|
37
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-EQXVKNLM.js";
|
|
38
40
|
import {
|
|
39
41
|
appendAndEnqueueApiConversationMessage,
|
|
40
42
|
createAndEnqueueApiConversation,
|
|
@@ -44,14 +46,15 @@ import {
|
|
|
44
46
|
readHealthReport,
|
|
45
47
|
resolveSlackConversationContextFromThreadId,
|
|
46
48
|
webActorFromEmail
|
|
47
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-YSMAMSOU.js";
|
|
48
50
|
import {
|
|
49
51
|
buildSentryConversationUrl,
|
|
50
52
|
getWebAuthorization
|
|
51
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-UG673UVL.js";
|
|
52
54
|
import {
|
|
55
|
+
cancelHumanFacingPendingMessages,
|
|
53
56
|
getConversation
|
|
54
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-FWDN67U3.js";
|
|
55
58
|
import {
|
|
56
59
|
readTaskExecutionByConversationId,
|
|
57
60
|
readTaskExecutionDays,
|
|
@@ -59,8 +62,8 @@ import {
|
|
|
59
62
|
readTaskExecutionSummaries,
|
|
60
63
|
readTaskExecutions,
|
|
61
64
|
readTaskRuns
|
|
62
|
-
} from "./chunk-
|
|
63
|
-
import "./chunk-
|
|
65
|
+
} from "./chunk-NCJV265M.js";
|
|
66
|
+
import "./chunk-UKKOKMRE.js";
|
|
64
67
|
import {
|
|
65
68
|
healthReportSchema,
|
|
66
69
|
pluginOperationalReportFeedSchema,
|
|
@@ -85,16 +88,16 @@ import {
|
|
|
85
88
|
listPublicScheduledTasksForTeams,
|
|
86
89
|
readLiveAttachment,
|
|
87
90
|
readStats
|
|
88
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-NT6V5WEE.js";
|
|
89
92
|
import {
|
|
90
93
|
parseSlackThreadId
|
|
91
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-IJ6KWS3V.js";
|
|
92
95
|
import {
|
|
93
96
|
agentTurnUsageSchema,
|
|
94
97
|
fallbackShortTitle,
|
|
95
98
|
hasAgentTurnUsage,
|
|
96
99
|
renderJuniorNativeConversationEvent
|
|
97
|
-
} from "./chunk-
|
|
100
|
+
} from "./chunk-54O6IKUS.js";
|
|
98
101
|
import "./chunk-3Y47VMHV.js";
|
|
99
102
|
import "./chunk-PDO5BLNM.js";
|
|
100
103
|
import {
|
|
@@ -104,11 +107,11 @@ import {
|
|
|
104
107
|
renderPluginConversationEvent,
|
|
105
108
|
resolveViewerUser,
|
|
106
109
|
updateViewerDisplayName
|
|
107
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-EBP6IS66.js";
|
|
108
111
|
import {
|
|
109
112
|
getSlackClient,
|
|
110
113
|
withSlackRetries
|
|
111
|
-
} from "./chunk-
|
|
114
|
+
} from "./chunk-K2LAI7RW.js";
|
|
112
115
|
import {
|
|
113
116
|
decodeStoredConversationEvent,
|
|
114
117
|
getConversationStore,
|
|
@@ -116,7 +119,7 @@ import {
|
|
|
116
119
|
getSqlExecutor,
|
|
117
120
|
locationFromRow,
|
|
118
121
|
parseSessionSource
|
|
119
|
-
} from "./chunk-
|
|
122
|
+
} from "./chunk-QODFNKQS.js";
|
|
120
123
|
import {
|
|
121
124
|
juniorApiTokens,
|
|
122
125
|
juniorConversationEvents,
|
|
@@ -124,16 +127,16 @@ import {
|
|
|
124
127
|
juniorConversations,
|
|
125
128
|
juniorIdentities,
|
|
126
129
|
juniorUsers
|
|
127
|
-
} from "./chunk-
|
|
130
|
+
} from "./chunk-O2DZWUPQ.js";
|
|
128
131
|
import "./chunk-EM225ITJ.js";
|
|
129
|
-
import "./chunk-
|
|
130
|
-
import "./chunk-
|
|
132
|
+
import "./chunk-Q5X37U6G.js";
|
|
133
|
+
import "./chunk-L2PEQ2PY.js";
|
|
131
134
|
import {
|
|
132
135
|
juniorDestinations
|
|
133
136
|
} from "./chunk-VFUK3X5B.js";
|
|
134
137
|
import {
|
|
135
138
|
canExposeConversationPayload
|
|
136
|
-
} from "./chunk-
|
|
139
|
+
} from "./chunk-PT7B6A3O.js";
|
|
137
140
|
import "./chunk-BDUENQD3.js";
|
|
138
141
|
import {
|
|
139
142
|
parseSlackChannelId,
|
|
@@ -143,10 +146,10 @@ import {
|
|
|
143
146
|
import {
|
|
144
147
|
logException,
|
|
145
148
|
logWarn
|
|
146
|
-
} from "./chunk-
|
|
149
|
+
} from "./chunk-TD7ZQZ5W.js";
|
|
147
150
|
import "./chunk-6GWA276C.js";
|
|
148
|
-
import "./chunk-
|
|
149
|
-
import "./chunk-
|
|
151
|
+
import "./chunk-OGMHLKNO.js";
|
|
152
|
+
import "./chunk-LUIKMY35.js";
|
|
150
153
|
import "./chunk-MLKGABMK.js";
|
|
151
154
|
|
|
152
155
|
// src/api.ts
|
|
@@ -1254,7 +1257,7 @@ async function readConversationEventPage(executor, args) {
|
|
|
1254
1257
|
}
|
|
1255
1258
|
|
|
1256
1259
|
// src/api/conversations/list.ts
|
|
1257
|
-
import { and as
|
|
1260
|
+
import { and as and8, asc as asc2, desc as desc2, eq as eq9, isNull as isNull3 } from "drizzle-orm";
|
|
1258
1261
|
|
|
1259
1262
|
// src/api/conversations/shared.ts
|
|
1260
1263
|
function slackStatsLocationLabel(input) {
|
|
@@ -1720,23 +1723,59 @@ function isConversationPriority(conversation, nowMs) {
|
|
|
1720
1723
|
}
|
|
1721
1724
|
if (conversation.assignedWork) {
|
|
1722
1725
|
const finishedAt = Date.parse(conversation.finishedWorkAt ?? "");
|
|
1723
|
-
|
|
1726
|
+
const lastUserMessageAt = Date.parse(conversation.lastUserMessageAt ?? "");
|
|
1727
|
+
return Number.isFinite(finishedAt) && Number.isFinite(lastUserMessageAt) && lastUserMessageAt > finishedAt;
|
|
1724
1728
|
}
|
|
1725
1729
|
return nowMs - lastSeenAt <= UNASSIGNED_PRIORITY_WINDOW_MS;
|
|
1726
1730
|
}
|
|
1727
1731
|
|
|
1732
|
+
// src/api/conversations/user-message-activity.ts
|
|
1733
|
+
import { and as and7, eq as eq8, inArray as inArray6, isNotNull as isNotNull3, or as or3, sql as sql5 } from "drizzle-orm";
|
|
1734
|
+
async function readLastUserMessageAtByConversation(db, conversationIds) {
|
|
1735
|
+
if (conversationIds.length === 0) return /* @__PURE__ */ new Map();
|
|
1736
|
+
const authority = sql5`${juniorConversationEvents.payload}->'provenance'->>'authority'`;
|
|
1737
|
+
const actorPlatform = sql5`${juniorConversationEvents.payload}->'provenance'->'actor'->>'platform'`;
|
|
1738
|
+
const role = sql5`${juniorConversationEvents.payload}->>'role'`;
|
|
1739
|
+
const rows = await db.select({
|
|
1740
|
+
conversationId: juniorConversationEvents.conversationId,
|
|
1741
|
+
lastUserMessageAt: sql5`max(${juniorConversationEvents.createdAt})`
|
|
1742
|
+
}).from(juniorConversationEvents).where(
|
|
1743
|
+
and7(
|
|
1744
|
+
inArray6(juniorConversationEvents.conversationId, conversationIds),
|
|
1745
|
+
or3(
|
|
1746
|
+
and7(
|
|
1747
|
+
eq8(juniorConversationEvents.type, "user_message"),
|
|
1748
|
+
eq8(authority, "instruction"),
|
|
1749
|
+
sql5`${actorPlatform} in ('slack', 'local', 'web')`
|
|
1750
|
+
),
|
|
1751
|
+
and7(
|
|
1752
|
+
eq8(juniorConversationEvents.type, "message"),
|
|
1753
|
+
eq8(role, "user"),
|
|
1754
|
+
isNotNull3(juniorConversationEvents.actorIdentityId)
|
|
1755
|
+
)
|
|
1756
|
+
)
|
|
1757
|
+
)
|
|
1758
|
+
).groupBy(juniorConversationEvents.conversationId);
|
|
1759
|
+
return new Map(
|
|
1760
|
+
rows.map((row) => [
|
|
1761
|
+
row.conversationId,
|
|
1762
|
+
new Date(row.lastUserMessageAt).toISOString()
|
|
1763
|
+
])
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1728
1767
|
// src/api/conversations/list.ts
|
|
1729
1768
|
var CONVERSATION_FEED_LIMIT = 50;
|
|
1730
1769
|
function conversationFeedMembershipFilter(filter) {
|
|
1731
1770
|
if (!filter) return void 0;
|
|
1732
1771
|
if (filter.kind === "viewer") {
|
|
1733
1772
|
return viewerConversationMembership({
|
|
1734
|
-
actorMatch:
|
|
1773
|
+
actorMatch: eq9(juniorIdentities.userId, filter.userId),
|
|
1735
1774
|
participantMatch: conversationHasParticipantUser(filter.userId)
|
|
1736
1775
|
});
|
|
1737
1776
|
}
|
|
1738
1777
|
return viewerConversationMembership({
|
|
1739
|
-
actorMatch:
|
|
1778
|
+
actorMatch: eq9(juniorUsers.primaryEmailNormalized, filter.email),
|
|
1740
1779
|
participantMatch: conversationHasParticipantEmail(filter.email)
|
|
1741
1780
|
});
|
|
1742
1781
|
}
|
|
@@ -1753,12 +1792,12 @@ async function conversationRows(db, limit, filter) {
|
|
|
1753
1792
|
userDisplayName: juniorUsers.displayName
|
|
1754
1793
|
}).from(juniorConversations).leftJoin(
|
|
1755
1794
|
juniorDestinations,
|
|
1756
|
-
|
|
1795
|
+
eq9(juniorDestinations.id, juniorConversations.destinationId)
|
|
1757
1796
|
).leftJoin(
|
|
1758
1797
|
juniorIdentities,
|
|
1759
|
-
|
|
1760
|
-
).leftJoin(juniorUsers,
|
|
1761
|
-
|
|
1798
|
+
eq9(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
1799
|
+
).leftJoin(juniorUsers, eq9(juniorUsers.id, juniorIdentities.userId)).where(
|
|
1800
|
+
and8(
|
|
1762
1801
|
isNull3(juniorConversations.parentConversationId),
|
|
1763
1802
|
isNull3(juniorConversations.archivedAt),
|
|
1764
1803
|
conversationFeedMembershipFilter(filter)
|
|
@@ -1819,11 +1858,11 @@ async function readConversationRecordFromSql(conversationId) {
|
|
|
1819
1858
|
userDisplayName: juniorUsers.displayName
|
|
1820
1859
|
}).from(juniorConversations).leftJoin(
|
|
1821
1860
|
juniorDestinations,
|
|
1822
|
-
|
|
1861
|
+
eq9(juniorDestinations.id, juniorConversations.destinationId)
|
|
1823
1862
|
).leftJoin(
|
|
1824
1863
|
juniorIdentities,
|
|
1825
|
-
|
|
1826
|
-
).leftJoin(juniorUsers,
|
|
1864
|
+
eq9(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
1865
|
+
).leftJoin(juniorUsers, eq9(juniorUsers.id, juniorIdentities.userId)).where(eq9(juniorConversations.conversationId, conversationId)).limit(1);
|
|
1827
1866
|
const row = rows[0];
|
|
1828
1867
|
return row ? {
|
|
1829
1868
|
conversation: conversationFromRow(row),
|
|
@@ -1865,7 +1904,8 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1865
1904
|
auxiliaryCostsByRoot,
|
|
1866
1905
|
metricsByRoot,
|
|
1867
1906
|
teamDomainByTeamId,
|
|
1868
|
-
conversationWork
|
|
1907
|
+
conversationWork,
|
|
1908
|
+
lastUserMessageAtByConversation
|
|
1869
1909
|
] = await Promise.all([
|
|
1870
1910
|
readConversationAccessFromSql(db, conversationIds, options.viewer),
|
|
1871
1911
|
readConversationAuxiliaryCostsFromSql(db, conversationIds, {
|
|
@@ -1877,7 +1917,8 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1877
1917
|
(conversation) => conversation.sessionSource?.platform === "slack" ? [conversation.sessionSource.teamId] : []
|
|
1878
1918
|
)
|
|
1879
1919
|
),
|
|
1880
|
-
listConversationWork(conversationIds)
|
|
1920
|
+
listConversationWork(conversationIds),
|
|
1921
|
+
readLastUserMessageAtByConversation(db, conversationIds)
|
|
1881
1922
|
]);
|
|
1882
1923
|
const assignedWork = new Set(conversationWork.assignedIds);
|
|
1883
1924
|
const unfinishedWork = new Set(conversationWork.unfinishedIds);
|
|
@@ -1907,6 +1948,9 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1907
1948
|
isPriority: isConversationPriority(
|
|
1908
1949
|
{
|
|
1909
1950
|
lastSeenAt: summary.lastSeenAt,
|
|
1951
|
+
lastUserMessageAt: lastUserMessageAtByConversation.get(
|
|
1952
|
+
conversation.conversationId
|
|
1953
|
+
),
|
|
1910
1954
|
...work
|
|
1911
1955
|
},
|
|
1912
1956
|
nowMs
|
|
@@ -1924,7 +1968,7 @@ async function readConversationFeed(options = {}) {
|
|
|
1924
1968
|
}
|
|
1925
1969
|
|
|
1926
1970
|
// src/chat/tasks/read.ts
|
|
1927
|
-
import { and as
|
|
1971
|
+
import { and as and9, eq as eq10, or as or4 } from "drizzle-orm";
|
|
1928
1972
|
|
|
1929
1973
|
// src/chat/scheduled-tasks/personal.ts
|
|
1930
1974
|
import { z as z3 } from "zod";
|
|
@@ -2034,16 +2078,16 @@ async function creatorProfileEmails(candidates) {
|
|
|
2034
2078
|
email: juniorUsers.primaryEmailNormalized,
|
|
2035
2079
|
slackUserId: juniorIdentities.providerSubjectId,
|
|
2036
2080
|
teamId: juniorIdentities.providerTenantId
|
|
2037
|
-
}).from(juniorIdentities).innerJoin(juniorUsers,
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2081
|
+
}).from(juniorIdentities).innerJoin(juniorUsers, eq10(juniorUsers.id, juniorIdentities.userId)).where(
|
|
2082
|
+
and9(
|
|
2083
|
+
eq10(juniorIdentities.kind, "user"),
|
|
2084
|
+
eq10(juniorIdentities.provider, "slack"),
|
|
2085
|
+
eq10(juniorIdentities.emailVerified, true),
|
|
2086
|
+
or4(
|
|
2043
2087
|
...[...selectors.values()].map(
|
|
2044
|
-
(selector) =>
|
|
2045
|
-
|
|
2046
|
-
|
|
2088
|
+
(selector) => and9(
|
|
2089
|
+
eq10(juniorIdentities.providerTenantId, selector.teamId),
|
|
2090
|
+
eq10(juniorIdentities.providerSubjectId, selector.slackUserId)
|
|
2047
2091
|
)
|
|
2048
2092
|
)
|
|
2049
2093
|
)
|
|
@@ -2079,12 +2123,12 @@ async function destinationDetails(destinations) {
|
|
|
2079
2123
|
providerTenantId: juniorDestinations.providerTenantId,
|
|
2080
2124
|
visibility: juniorDestinations.visibility
|
|
2081
2125
|
}).from(juniorDestinations).where(
|
|
2082
|
-
|
|
2126
|
+
or4(
|
|
2083
2127
|
...[...selectors.values()].map(
|
|
2084
|
-
(destination) =>
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2128
|
+
(destination) => and9(
|
|
2129
|
+
eq10(juniorDestinations.provider, "slack"),
|
|
2130
|
+
eq10(juniorDestinations.providerTenantId, destination.teamId),
|
|
2131
|
+
eq10(juniorDestinations.providerDestinationId, destination.channelId)
|
|
2088
2132
|
)
|
|
2089
2133
|
)
|
|
2090
2134
|
)
|
|
@@ -2588,6 +2632,40 @@ async function readConversationEvents(conversationId, beforeValue, options = {})
|
|
|
2588
2632
|
});
|
|
2589
2633
|
}
|
|
2590
2634
|
|
|
2635
|
+
// src/api/conversations/cancel-pending-messages.ts
|
|
2636
|
+
async function cancelConversationPendingMessagesForViewer(viewer, conversationId, body = {}) {
|
|
2637
|
+
const conversation = await getConversationStore().get({ conversationId });
|
|
2638
|
+
if (!conversation) {
|
|
2639
|
+
throwApiError(404, "Conversation not found.");
|
|
2640
|
+
}
|
|
2641
|
+
const access = await readConversationAccessFromSql(
|
|
2642
|
+
getDb(),
|
|
2643
|
+
[conversationId],
|
|
2644
|
+
viewer
|
|
2645
|
+
);
|
|
2646
|
+
if (!access.get(conversationId)?.isParticipant) {
|
|
2647
|
+
throwApiError(
|
|
2648
|
+
403,
|
|
2649
|
+
"Only conversation participants can cancel queued messages."
|
|
2650
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
try {
|
|
2653
|
+
const result = await cancelHumanFacingPendingMessages({
|
|
2654
|
+
conversationId,
|
|
2655
|
+
...body.inboundMessageIds ? { inboundMessageIds: body.inboundMessageIds } : {},
|
|
2656
|
+
...body.receivedBefore ? { receivedBeforeMs: Date.parse(body.receivedBefore) } : {},
|
|
2657
|
+
conversationStore: getConversationStore()
|
|
2658
|
+
});
|
|
2659
|
+
return {
|
|
2660
|
+
cancelledCount: result.cancelledInboundMessageIds.length,
|
|
2661
|
+
cancelledInboundMessageIds: result.cancelledInboundMessageIds,
|
|
2662
|
+
conversationId
|
|
2663
|
+
};
|
|
2664
|
+
} catch (error) {
|
|
2665
|
+
throwApiError(500, "Unable to cancel queued messages.", error);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2591
2669
|
// src/api/conversations/pending-messages.ts
|
|
2592
2670
|
import { z as z4 } from "zod";
|
|
2593
2671
|
var apiTurnMailboxMetadataSchema = z4.object({
|
|
@@ -2737,20 +2815,20 @@ async function requireConversationPendingMessages(conversationId, options = {})
|
|
|
2737
2815
|
}
|
|
2738
2816
|
|
|
2739
2817
|
// src/api/conversations/stats.query.ts
|
|
2740
|
-
import { and as
|
|
2818
|
+
import { and as and10, eq as eq11, gte, isNull as isNull4, lte, sql as sql7 } from "drizzle-orm";
|
|
2741
2819
|
import { alias as alias4 } from "drizzle-orm/pg-core";
|
|
2742
2820
|
|
|
2743
2821
|
// src/api/conversations/aggregate.ts
|
|
2744
|
-
import { sql as
|
|
2822
|
+
import { sql as sql6 } from "drizzle-orm";
|
|
2745
2823
|
function usageTokenValue(source, field) {
|
|
2746
|
-
return
|
|
2824
|
+
return sql6`CASE
|
|
2747
2825
|
WHEN ${source.usage}->>${field} IS NOT NULL
|
|
2748
2826
|
THEN (${source.usage}->>${field})::double precision
|
|
2749
2827
|
ELSE NULL
|
|
2750
2828
|
END`;
|
|
2751
2829
|
}
|
|
2752
2830
|
function tokenValue(source) {
|
|
2753
|
-
return
|
|
2831
|
+
return sql6`
|
|
2754
2832
|
CASE
|
|
2755
2833
|
WHEN COALESCE(
|
|
2756
2834
|
${source.usage}->>'inputTokens',
|
|
@@ -2769,7 +2847,7 @@ function tokenValue(source) {
|
|
|
2769
2847
|
`;
|
|
2770
2848
|
}
|
|
2771
2849
|
function costValue(source) {
|
|
2772
|
-
return
|
|
2850
|
+
return sql6`
|
|
2773
2851
|
CASE
|
|
2774
2852
|
WHEN ${source.usage}->'cost'->>'total' IS NOT NULL
|
|
2775
2853
|
THEN (${source.usage}->'cost'->>'total')::double precision
|
|
@@ -2790,34 +2868,34 @@ function costValue(source) {
|
|
|
2790
2868
|
function conversationAggregateColumns(sources) {
|
|
2791
2869
|
const metrics = sources?.metrics ?? juniorConversations;
|
|
2792
2870
|
const roots = sources?.roots ?? juniorConversations;
|
|
2793
|
-
const conversationCount = sources ?
|
|
2871
|
+
const conversationCount = sources ? sql6`COUNT(DISTINCT ${roots.conversationId})` : sql6`COUNT(*)`;
|
|
2794
2872
|
return {
|
|
2795
|
-
active:
|
|
2873
|
+
active: sql6`${conversationCount} FILTER (
|
|
2796
2874
|
WHERE ${roots.executionStatus} NOT IN ('idle', 'failed')
|
|
2797
2875
|
)::integer`,
|
|
2798
|
-
conversations:
|
|
2799
|
-
cachedInputTokens:
|
|
2800
|
-
costUsd:
|
|
2801
|
-
durationMs:
|
|
2802
|
-
failed:
|
|
2876
|
+
conversations: sql6`${conversationCount}::integer`,
|
|
2877
|
+
cachedInputTokens: sql6`SUM(${usageTokenValue(metrics, "cachedInputTokens")})::double precision`,
|
|
2878
|
+
costUsd: sql6`SUM(${costValue(metrics)})::double precision`,
|
|
2879
|
+
durationMs: sql6`COALESCE(SUM(${metrics.durationMs}), 0)::double precision`,
|
|
2880
|
+
failed: sql6`${conversationCount} FILTER (
|
|
2803
2881
|
WHERE ${roots.executionStatus} = 'failed'
|
|
2804
2882
|
)::integer`,
|
|
2805
|
-
inputTokens:
|
|
2806
|
-
tokens:
|
|
2883
|
+
inputTokens: sql6`SUM(${usageTokenValue(metrics, "inputTokens")})::double precision`,
|
|
2884
|
+
tokens: sql6`SUM(${tokenValue(metrics)})::double precision`
|
|
2807
2885
|
};
|
|
2808
2886
|
}
|
|
2809
2887
|
function conversationRangeColumns() {
|
|
2810
2888
|
return {
|
|
2811
|
-
firstSeenAt:
|
|
2889
|
+
firstSeenAt: sql6`MIN(${juniorConversations.createdAt})`.mapWith(
|
|
2812
2890
|
juniorConversations.createdAt
|
|
2813
2891
|
),
|
|
2814
|
-
lastSeenAt:
|
|
2892
|
+
lastSeenAt: sql6`MAX(${juniorConversations.lastActivityAt})`.mapWith(
|
|
2815
2893
|
juniorConversations.lastActivityAt
|
|
2816
2894
|
)
|
|
2817
2895
|
};
|
|
2818
2896
|
}
|
|
2819
2897
|
function conversationActiveDaysColumn() {
|
|
2820
|
-
return
|
|
2898
|
+
return sql6`COUNT(DISTINCT (${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC')::date)::integer`;
|
|
2821
2899
|
}
|
|
2822
2900
|
|
|
2823
2901
|
// src/api/conversations/stats.query.ts
|
|
@@ -2881,7 +2959,7 @@ function statsItems(map) {
|
|
|
2881
2959
|
);
|
|
2882
2960
|
}
|
|
2883
2961
|
function statsWhere(start, end) {
|
|
2884
|
-
return
|
|
2962
|
+
return and10(
|
|
2885
2963
|
isNull4(juniorConversations.parentConversationId),
|
|
2886
2964
|
gte(juniorConversations.lastActivityAt, start),
|
|
2887
2965
|
lte(juniorConversations.lastActivityAt, end)
|
|
@@ -2958,14 +3036,14 @@ function guardianStats(rows, endMs) {
|
|
|
2958
3036
|
}
|
|
2959
3037
|
async function aggregateStats(db, start, end) {
|
|
2960
3038
|
const where = statsWhere(start, end);
|
|
2961
|
-
const activityDate =
|
|
3039
|
+
const activityDate = sql7`TO_CHAR(
|
|
2962
3040
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
2963
3041
|
'YYYY-MM-DD'
|
|
2964
3042
|
)`;
|
|
2965
3043
|
const [totalsRows, actorRows, locationRows, metricRows] = await Promise.all([
|
|
2966
3044
|
db.select(treeAggregateColumns).from(juniorConversations).innerJoin(
|
|
2967
3045
|
treeConversation,
|
|
2968
|
-
|
|
3046
|
+
eq11(
|
|
2969
3047
|
treeConversation.rootConversationId,
|
|
2970
3048
|
juniorConversations.conversationId
|
|
2971
3049
|
)
|
|
@@ -2980,14 +3058,14 @@ async function aggregateStats(db, start, end) {
|
|
|
2980
3058
|
...treeAggregateColumns
|
|
2981
3059
|
}).from(juniorConversations).innerJoin(
|
|
2982
3060
|
treeConversation,
|
|
2983
|
-
|
|
3061
|
+
eq11(
|
|
2984
3062
|
treeConversation.rootConversationId,
|
|
2985
3063
|
juniorConversations.conversationId
|
|
2986
3064
|
)
|
|
2987
3065
|
).leftJoin(
|
|
2988
3066
|
juniorIdentities,
|
|
2989
|
-
|
|
2990
|
-
).leftJoin(juniorUsers,
|
|
3067
|
+
eq11(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3068
|
+
).leftJoin(juniorUsers, eq11(juniorUsers.id, juniorIdentities.userId)).where(where).groupBy(
|
|
2991
3069
|
juniorIdentities.displayName,
|
|
2992
3070
|
juniorIdentities.emailNormalized,
|
|
2993
3071
|
juniorIdentities.handle,
|
|
@@ -3005,13 +3083,13 @@ async function aggregateStats(db, start, end) {
|
|
|
3005
3083
|
...treeAggregateColumns
|
|
3006
3084
|
}).from(juniorConversations).innerJoin(
|
|
3007
3085
|
treeConversation,
|
|
3008
|
-
|
|
3086
|
+
eq11(
|
|
3009
3087
|
treeConversation.rootConversationId,
|
|
3010
3088
|
juniorConversations.conversationId
|
|
3011
3089
|
)
|
|
3012
3090
|
).leftJoin(
|
|
3013
3091
|
juniorDestinations,
|
|
3014
|
-
|
|
3092
|
+
eq11(juniorDestinations.id, juniorConversations.destinationId)
|
|
3015
3093
|
).where(where).groupBy(
|
|
3016
3094
|
juniorConversations.channelName,
|
|
3017
3095
|
juniorConversations.source,
|
|
@@ -3030,7 +3108,7 @@ async function aggregateStats(db, start, end) {
|
|
|
3030
3108
|
tokens: treeAggregateColumns.tokens
|
|
3031
3109
|
}).from(juniorConversations).innerJoin(
|
|
3032
3110
|
treeConversation,
|
|
3033
|
-
|
|
3111
|
+
eq11(
|
|
3034
3112
|
treeConversation.rootConversationId,
|
|
3035
3113
|
juniorConversations.conversationId
|
|
3036
3114
|
)
|
|
@@ -3039,26 +3117,26 @@ async function aggregateStats(db, start, end) {
|
|
|
3039
3117
|
return { actorRows, locationRows, metricRows, totals: totalsRows[0] };
|
|
3040
3118
|
}
|
|
3041
3119
|
async function aggregateGuardianStats(db, start, end) {
|
|
3042
|
-
const date =
|
|
3120
|
+
const date = sql7`TO_CHAR(
|
|
3043
3121
|
${juniorConversationEvents.createdAt} AT TIME ZONE 'UTC',
|
|
3044
3122
|
'YYYY-MM-DD'
|
|
3045
3123
|
)`;
|
|
3046
|
-
const decision =
|
|
3047
|
-
const cost2 =
|
|
3124
|
+
const decision = sql7`${juniorConversationEvents.payload}->>'decision'`;
|
|
3125
|
+
const cost2 = sql7`CASE
|
|
3048
3126
|
WHEN jsonb_typeof(${juniorConversationEvents.payload}->'costUsd') = 'number'
|
|
3049
3127
|
THEN (${juniorConversationEvents.payload}->>'costUsd')::double precision
|
|
3050
3128
|
ELSE NULL
|
|
3051
3129
|
END`;
|
|
3052
3130
|
return await db.select({
|
|
3053
|
-
allow:
|
|
3054
|
-
ask:
|
|
3055
|
-
costUsd:
|
|
3131
|
+
allow: sql7`COUNT(*) FILTER (WHERE ${decision} = 'allow')::integer`,
|
|
3132
|
+
ask: sql7`COUNT(*) FILTER (WHERE ${decision} = 'ask')::integer`,
|
|
3133
|
+
costUsd: sql7`SUM(${cost2})::double precision`,
|
|
3056
3134
|
date,
|
|
3057
|
-
deny:
|
|
3058
|
-
requests:
|
|
3135
|
+
deny: sql7`COUNT(*) FILTER (WHERE ${decision} = 'deny')::integer`,
|
|
3136
|
+
requests: sql7`COUNT(*)::integer`
|
|
3059
3137
|
}).from(juniorConversationEvents).where(
|
|
3060
|
-
|
|
3061
|
-
|
|
3138
|
+
and10(
|
|
3139
|
+
eq11(juniorConversationEvents.type, "guardian_action_reviewed"),
|
|
3062
3140
|
gte(juniorConversationEvents.createdAt, start),
|
|
3063
3141
|
lte(juniorConversationEvents.createdAt, end)
|
|
3064
3142
|
)
|
|
@@ -3236,6 +3314,33 @@ function createConversationRoutes(options) {
|
|
|
3236
3314
|
);
|
|
3237
3315
|
}
|
|
3238
3316
|
);
|
|
3317
|
+
app.delete(
|
|
3318
|
+
"/:conversationId/pending-messages",
|
|
3319
|
+
requireViewer,
|
|
3320
|
+
validateRequest(
|
|
3321
|
+
"param",
|
|
3322
|
+
conversationParamsSchema,
|
|
3323
|
+
"Invalid route parameters."
|
|
3324
|
+
),
|
|
3325
|
+
validateRequest(
|
|
3326
|
+
"json",
|
|
3327
|
+
cancelConversationPendingMessagesBodySchema,
|
|
3328
|
+
"Invalid request body."
|
|
3329
|
+
),
|
|
3330
|
+
async (context) => {
|
|
3331
|
+
const viewer = context.get("viewer");
|
|
3332
|
+
const { conversationId } = context.req.valid("param");
|
|
3333
|
+
const body = context.req.valid("json");
|
|
3334
|
+
return jsonResponse(
|
|
3335
|
+
cancelConversationPendingMessagesResponseSchema,
|
|
3336
|
+
await cancelConversationPendingMessagesForViewer(
|
|
3337
|
+
viewer,
|
|
3338
|
+
conversationId,
|
|
3339
|
+
body
|
|
3340
|
+
)
|
|
3341
|
+
);
|
|
3342
|
+
}
|
|
3343
|
+
);
|
|
3239
3344
|
app.get(
|
|
3240
3345
|
"/:conversationId/attachments/:attachmentId",
|
|
3241
3346
|
validateRequest(
|
|
@@ -3292,7 +3397,7 @@ function createConversationRoutes(options) {
|
|
|
3292
3397
|
import { Hono as Hono2 } from "hono";
|
|
3293
3398
|
|
|
3294
3399
|
// src/api/locations/query.ts
|
|
3295
|
-
import { and as
|
|
3400
|
+
import { and as and11, asc as asc3, desc as desc3, eq as eq12, gte as gte2, isNull as isNull5, sql as sql8 } from "drizzle-orm";
|
|
3296
3401
|
import { alias as alias5 } from "drizzle-orm/pg-core";
|
|
3297
3402
|
|
|
3298
3403
|
// src/api/conversations/reporting.ts
|
|
@@ -3400,10 +3505,10 @@ function topLevelWhere() {
|
|
|
3400
3505
|
return isNull5(juniorConversations.parentConversationId);
|
|
3401
3506
|
}
|
|
3402
3507
|
function publicLocationWhere(destinationId) {
|
|
3403
|
-
return
|
|
3508
|
+
return and11(
|
|
3404
3509
|
topLevelWhere(),
|
|
3405
|
-
|
|
3406
|
-
|
|
3510
|
+
eq12(juniorDestinations.id, destinationId),
|
|
3511
|
+
eq12(juniorDestinations.visibility, "public")
|
|
3407
3512
|
);
|
|
3408
3513
|
}
|
|
3409
3514
|
function locationColumns() {
|
|
@@ -3454,28 +3559,28 @@ async function directoryRows(db) {
|
|
|
3454
3559
|
...conversationRangeColumns()
|
|
3455
3560
|
}).from(juniorConversations).innerJoin(
|
|
3456
3561
|
treeConversation2,
|
|
3457
|
-
|
|
3562
|
+
eq12(
|
|
3458
3563
|
treeConversation2.rootConversationId,
|
|
3459
3564
|
juniorConversations.conversationId
|
|
3460
3565
|
)
|
|
3461
3566
|
).leftJoin(
|
|
3462
3567
|
juniorDestinations,
|
|
3463
|
-
|
|
3568
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3464
3569
|
).where(topLevelWhere()).groupBy(...locationGroupBy());
|
|
3465
3570
|
}
|
|
3466
3571
|
async function directoryActivityRows(db, start) {
|
|
3467
|
-
const date =
|
|
3572
|
+
const date = sql8`TO_CHAR(
|
|
3468
3573
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3469
3574
|
'YYYY-MM-DD'
|
|
3470
3575
|
)`;
|
|
3471
3576
|
return db.select({
|
|
3472
|
-
conversations:
|
|
3577
|
+
conversations: sql8`COUNT(*)::integer`,
|
|
3473
3578
|
date,
|
|
3474
3579
|
visibility: juniorDestinations.visibility
|
|
3475
3580
|
}).from(juniorConversations).leftJoin(
|
|
3476
3581
|
juniorDestinations,
|
|
3477
|
-
|
|
3478
|
-
).where(
|
|
3582
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3583
|
+
).where(and11(topLevelWhere(), gte2(juniorConversations.lastActivityAt, start))).groupBy(date, juniorDestinations.visibility);
|
|
3479
3584
|
}
|
|
3480
3585
|
function directoryActivityDays(rows, nowMs) {
|
|
3481
3586
|
const days = /* @__PURE__ */ new Map();
|
|
@@ -3548,7 +3653,7 @@ async function recentLocationRows(db, locationId) {
|
|
|
3548
3653
|
createdAt: juniorConversations.createdAt,
|
|
3549
3654
|
destinationId: juniorDestinations.id,
|
|
3550
3655
|
durationMs: juniorConversations.durationMs,
|
|
3551
|
-
email:
|
|
3656
|
+
email: sql8`COALESCE(
|
|
3552
3657
|
${juniorUsers.primaryEmailNormalized},
|
|
3553
3658
|
${juniorIdentities.email}
|
|
3554
3659
|
)`,
|
|
@@ -3557,7 +3662,7 @@ async function recentLocationRows(db, locationId) {
|
|
|
3557
3662
|
fullName: juniorUsers.displayName,
|
|
3558
3663
|
handle: juniorIdentities.handle,
|
|
3559
3664
|
lastActivityAt: juniorConversations.lastActivityAt,
|
|
3560
|
-
providerSubjectId:
|
|
3665
|
+
providerSubjectId: sql8`CASE
|
|
3561
3666
|
WHEN ${juniorIdentities.provider} = 'slack'
|
|
3562
3667
|
THEN ${juniorIdentities.providerSubjectId}
|
|
3563
3668
|
ELSE NULL
|
|
@@ -3568,12 +3673,12 @@ async function recentLocationRows(db, locationId) {
|
|
|
3568
3673
|
usage: juniorConversations.usage
|
|
3569
3674
|
}).from(juniorConversations).innerJoin(
|
|
3570
3675
|
juniorDestinations,
|
|
3571
|
-
|
|
3676
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3572
3677
|
).leftJoin(
|
|
3573
3678
|
juniorIdentities,
|
|
3574
|
-
|
|
3575
|
-
).leftJoin(juniorUsers,
|
|
3576
|
-
|
|
3679
|
+
eq12(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3680
|
+
).leftJoin(juniorUsers, eq12(juniorUsers.id, juniorIdentities.userId)).where(
|
|
3681
|
+
and11(
|
|
3577
3682
|
publicLocationWhere(locationId),
|
|
3578
3683
|
isNull5(juniorConversations.archivedAt)
|
|
3579
3684
|
)
|
|
@@ -3589,7 +3694,7 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3589
3694
|
const start = new Date(end);
|
|
3590
3695
|
start.setUTCDate(start.getUTCDate() - (ACTIVITY_DAYS - 1));
|
|
3591
3696
|
const where = publicLocationWhere(locationId);
|
|
3592
|
-
const activityDate =
|
|
3697
|
+
const activityDate = sql8`TO_CHAR(
|
|
3593
3698
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3594
3699
|
'YYYY-MM-DD'
|
|
3595
3700
|
)`;
|
|
@@ -3600,27 +3705,27 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3600
3705
|
...conversationRangeColumns()
|
|
3601
3706
|
}).from(juniorConversations).innerJoin(
|
|
3602
3707
|
treeConversation2,
|
|
3603
|
-
|
|
3708
|
+
eq12(
|
|
3604
3709
|
treeConversation2.rootConversationId,
|
|
3605
3710
|
juniorConversations.conversationId
|
|
3606
3711
|
)
|
|
3607
3712
|
).innerJoin(
|
|
3608
3713
|
juniorDestinations,
|
|
3609
|
-
|
|
3714
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3610
3715
|
).where(where).groupBy(...locationGroupBy()),
|
|
3611
3716
|
getDb().select({
|
|
3612
3717
|
date: activityDate,
|
|
3613
3718
|
...treeAggregateColumns2
|
|
3614
3719
|
}).from(juniorConversations).innerJoin(
|
|
3615
3720
|
treeConversation2,
|
|
3616
|
-
|
|
3721
|
+
eq12(
|
|
3617
3722
|
treeConversation2.rootConversationId,
|
|
3618
3723
|
juniorConversations.conversationId
|
|
3619
3724
|
)
|
|
3620
3725
|
).innerJoin(
|
|
3621
3726
|
juniorDestinations,
|
|
3622
|
-
|
|
3623
|
-
).where(
|
|
3727
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3728
|
+
).where(and11(where, gte2(juniorConversations.lastActivityAt, start))).groupBy(activityDate),
|
|
3624
3729
|
getDb().select({
|
|
3625
3730
|
actorIdentityId: juniorConversations.actorIdentityId,
|
|
3626
3731
|
email: juniorUsers.primaryEmailNormalized,
|
|
@@ -3632,17 +3737,17 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3632
3737
|
...treeAggregateColumns2
|
|
3633
3738
|
}).from(juniorConversations).innerJoin(
|
|
3634
3739
|
treeConversation2,
|
|
3635
|
-
|
|
3740
|
+
eq12(
|
|
3636
3741
|
treeConversation2.rootConversationId,
|
|
3637
3742
|
juniorConversations.conversationId
|
|
3638
3743
|
)
|
|
3639
3744
|
).innerJoin(
|
|
3640
3745
|
juniorDestinations,
|
|
3641
|
-
|
|
3746
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3642
3747
|
).leftJoin(
|
|
3643
3748
|
juniorIdentities,
|
|
3644
|
-
|
|
3645
|
-
).leftJoin(juniorUsers,
|
|
3749
|
+
eq12(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3750
|
+
).leftJoin(juniorUsers, eq12(juniorUsers.id, juniorIdentities.userId)).where(where).groupBy(
|
|
3646
3751
|
juniorConversations.actorIdentityId,
|
|
3647
3752
|
juniorUsers.primaryEmailNormalized,
|
|
3648
3753
|
juniorUsers.displayName,
|
|
@@ -3755,10 +3860,10 @@ function createLocationRoutes() {
|
|
|
3755
3860
|
import { Hono as Hono3 } from "hono";
|
|
3756
3861
|
|
|
3757
3862
|
// src/api/people/list.query.ts
|
|
3758
|
-
import { and as
|
|
3863
|
+
import { and as and13, eq as eq14, gte as gte3, sql as sql10 } from "drizzle-orm";
|
|
3759
3864
|
|
|
3760
3865
|
// src/api/people/shared.ts
|
|
3761
|
-
import { and as
|
|
3866
|
+
import { and as and12, asc as asc4, desc as desc4, eq as eq13, isNull as isNull6, notExists, or as or5, sql as sql9 } from "drizzle-orm";
|
|
3762
3867
|
import { alias as alias6 } from "drizzle-orm/pg-core";
|
|
3763
3868
|
var RECENT_LIMIT2 = 25;
|
|
3764
3869
|
var ACTIVITY_DAYS2 = 365;
|
|
@@ -3778,37 +3883,37 @@ var peopleTreeAggregateColumns = conversationAggregateColumns({
|
|
|
3778
3883
|
function peopleTreeMetricsJoin() {
|
|
3779
3884
|
const rootOwnedByActor = getDb().select({ conversationId: peopleRootConversation.conversationId }).from(peopleRootConversation).innerJoin(
|
|
3780
3885
|
peopleRootIdentity,
|
|
3781
|
-
|
|
3886
|
+
eq13(peopleRootIdentity.id, peopleRootConversation.actorIdentityId)
|
|
3782
3887
|
).where(
|
|
3783
|
-
|
|
3784
|
-
|
|
3888
|
+
and12(
|
|
3889
|
+
eq13(
|
|
3785
3890
|
peopleRootConversation.conversationId,
|
|
3786
3891
|
juniorConversations.rootConversationId
|
|
3787
3892
|
),
|
|
3788
3893
|
isNull6(peopleRootConversation.parentConversationId),
|
|
3789
|
-
|
|
3894
|
+
eq13(
|
|
3790
3895
|
peopleRootConversation.rootConversationId,
|
|
3791
3896
|
peopleRootConversation.conversationId
|
|
3792
3897
|
),
|
|
3793
|
-
|
|
3898
|
+
eq13(
|
|
3794
3899
|
peopleRootIdentity.emailNormalized,
|
|
3795
3900
|
juniorUsers.primaryEmailNormalized
|
|
3796
3901
|
),
|
|
3797
|
-
|
|
3902
|
+
eq13(peopleRootIdentity.emailVerified, true)
|
|
3798
3903
|
)
|
|
3799
3904
|
);
|
|
3800
|
-
return
|
|
3801
|
-
|
|
3905
|
+
return and12(
|
|
3906
|
+
eq13(
|
|
3802
3907
|
peopleTreeConversation.rootConversationId,
|
|
3803
3908
|
juniorConversations.rootConversationId
|
|
3804
3909
|
),
|
|
3805
|
-
|
|
3806
|
-
|
|
3910
|
+
or5(
|
|
3911
|
+
eq13(
|
|
3807
3912
|
juniorConversations.rootConversationId,
|
|
3808
3913
|
juniorConversations.conversationId
|
|
3809
3914
|
),
|
|
3810
|
-
|
|
3811
|
-
|
|
3915
|
+
and12(
|
|
3916
|
+
eq13(
|
|
3812
3917
|
peopleTreeConversation.conversationId,
|
|
3813
3918
|
juniorConversations.conversationId
|
|
3814
3919
|
),
|
|
@@ -3858,11 +3963,11 @@ function statsItems2(map) {
|
|
|
3858
3963
|
}
|
|
3859
3964
|
function verifiedActorWhere(email) {
|
|
3860
3965
|
const normalizedEmail = normalizeEmail(email);
|
|
3861
|
-
return
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
normalizedEmail ?
|
|
3966
|
+
return and12(
|
|
3967
|
+
eq13(juniorIdentities.provider, "slack"),
|
|
3968
|
+
eq13(juniorIdentities.emailVerified, true),
|
|
3969
|
+
sql9`${juniorUsers.primaryEmailNormalized} IS NOT NULL`,
|
|
3970
|
+
normalizedEmail ? eq13(juniorUsers.primaryEmailNormalized, normalizedEmail) : void 0
|
|
3866
3971
|
);
|
|
3867
3972
|
}
|
|
3868
3973
|
async function recentActorRows(email) {
|
|
@@ -3885,12 +3990,12 @@ async function recentActorRows(email) {
|
|
|
3885
3990
|
usage: juniorConversations.usage
|
|
3886
3991
|
}).from(juniorConversations).innerJoin(
|
|
3887
3992
|
juniorIdentities,
|
|
3888
|
-
|
|
3889
|
-
).innerJoin(juniorUsers,
|
|
3993
|
+
eq13(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3994
|
+
).innerJoin(juniorUsers, eq13(juniorUsers.id, juniorIdentities.userId)).leftJoin(
|
|
3890
3995
|
juniorDestinations,
|
|
3891
|
-
|
|
3996
|
+
eq13(juniorDestinations.id, juniorConversations.destinationId)
|
|
3892
3997
|
).where(
|
|
3893
|
-
|
|
3998
|
+
and12(verifiedActorWhere(email), isNull6(juniorConversations.archivedAt))
|
|
3894
3999
|
).orderBy(
|
|
3895
4000
|
desc4(juniorConversations.lastActivityAt),
|
|
3896
4001
|
asc4(juniorConversations.conversationId)
|
|
@@ -3919,7 +4024,7 @@ function directoryActivityDays2(rows, nowMs) {
|
|
|
3919
4024
|
async function readPeopleListFromSql() {
|
|
3920
4025
|
const nowMs = Date.now();
|
|
3921
4026
|
const { end, start } = activityWindow(nowMs);
|
|
3922
|
-
const activityDate =
|
|
4027
|
+
const activityDate = sql10`TO_CHAR(
|
|
3923
4028
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3924
4029
|
'YYYY-MM-DD'
|
|
3925
4030
|
)`;
|
|
@@ -3927,24 +4032,24 @@ async function readPeopleListFromSql() {
|
|
|
3927
4032
|
getDb().select({
|
|
3928
4033
|
email: juniorUsers.primaryEmailNormalized,
|
|
3929
4034
|
fullName: juniorUsers.displayName,
|
|
3930
|
-
slackUserId:
|
|
3931
|
-
slackUserName:
|
|
4035
|
+
slackUserId: sql10`MAX(${juniorIdentities.providerSubjectId})`,
|
|
4036
|
+
slackUserName: sql10`MAX(${juniorIdentities.handle})`,
|
|
3932
4037
|
activeDays: conversationActiveDaysColumn(),
|
|
3933
4038
|
...peopleTreeAggregateColumns,
|
|
3934
4039
|
...conversationRangeColumns()
|
|
3935
4040
|
}).from(juniorConversations).innerJoin(
|
|
3936
4041
|
juniorIdentities,
|
|
3937
|
-
|
|
3938
|
-
).innerJoin(juniorUsers,
|
|
4042
|
+
eq14(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4043
|
+
).innerJoin(juniorUsers, eq14(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, peopleTreeMetricsJoin()).where(verifiedActorWhere()).groupBy(juniorUsers.primaryEmailNormalized, juniorUsers.displayName),
|
|
3939
4044
|
getDb().select({
|
|
3940
|
-
activePeople:
|
|
3941
|
-
conversations:
|
|
4045
|
+
activePeople: sql10`COUNT(DISTINCT ${juniorUsers.id})::int`,
|
|
4046
|
+
conversations: sql10`COUNT(*)::int`,
|
|
3942
4047
|
date: activityDate
|
|
3943
4048
|
}).from(juniorConversations).innerJoin(
|
|
3944
4049
|
juniorIdentities,
|
|
3945
|
-
|
|
3946
|
-
).innerJoin(juniorUsers,
|
|
3947
|
-
|
|
4050
|
+
eq14(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4051
|
+
).innerJoin(juniorUsers, eq14(juniorUsers.id, juniorIdentities.userId)).where(
|
|
4052
|
+
and13(
|
|
3948
4053
|
verifiedActorWhere(),
|
|
3949
4054
|
gte3(juniorConversations.lastActivityAt, start)
|
|
3950
4055
|
)
|
|
@@ -3987,7 +4092,7 @@ async function readPeopleList() {
|
|
|
3987
4092
|
}
|
|
3988
4093
|
|
|
3989
4094
|
// src/api/people/profile.query.ts
|
|
3990
|
-
import { and as
|
|
4095
|
+
import { and as and14, eq as eq15, gte as gte4, sql as sql11 } from "drizzle-orm";
|
|
3991
4096
|
function emptyProfile(email, nowMs) {
|
|
3992
4097
|
const end = new Date(nowMs);
|
|
3993
4098
|
end.setUTCHours(0, 0, 0, 0);
|
|
@@ -4022,7 +4127,7 @@ function addAggregate2(map, label, row) {
|
|
|
4022
4127
|
map.set(label, item);
|
|
4023
4128
|
}
|
|
4024
4129
|
function surfaceExpression() {
|
|
4025
|
-
return
|
|
4130
|
+
return sql11`CASE
|
|
4026
4131
|
WHEN ${juniorConversations.source} IN ('api', 'scheduler', 'slack')
|
|
4027
4132
|
THEN ${juniorConversations.source}
|
|
4028
4133
|
WHEN ${juniorConversations.conversationId} LIKE 'slack:%' THEN 'slack'
|
|
@@ -4051,30 +4156,30 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4051
4156
|
const where = verifiedActorWhere(normalizedEmail);
|
|
4052
4157
|
const metricsJoin = peopleTreeMetricsJoin();
|
|
4053
4158
|
const surface = surfaceExpression();
|
|
4054
|
-
const activityDate =
|
|
4159
|
+
const activityDate = sql11`TO_CHAR(
|
|
4055
4160
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
4056
4161
|
'YYYY-MM-DD'
|
|
4057
4162
|
)`;
|
|
4058
|
-
const channel =
|
|
4163
|
+
const channel = sql11`SPLIT_PART(${juniorConversations.conversationId}, ':', 2)`;
|
|
4059
4164
|
const [totalsRows, dayRows, locationRows, surfaceRows, recentRows] = await Promise.all([
|
|
4060
4165
|
getDb().select({
|
|
4061
4166
|
email: juniorUsers.primaryEmailNormalized,
|
|
4062
4167
|
fullName: juniorUsers.displayName,
|
|
4063
|
-
slackUserId:
|
|
4064
|
-
slackUserName:
|
|
4168
|
+
slackUserId: sql11`MAX(${juniorIdentities.providerSubjectId})`,
|
|
4169
|
+
slackUserName: sql11`MAX(${juniorIdentities.handle})`,
|
|
4065
4170
|
activeDays: conversationActiveDaysColumn(),
|
|
4066
4171
|
...peopleTreeAggregateColumns
|
|
4067
4172
|
}).from(juniorConversations).innerJoin(
|
|
4068
4173
|
juniorIdentities,
|
|
4069
|
-
|
|
4070
|
-
).innerJoin(juniorUsers,
|
|
4174
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4175
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(where).groupBy(juniorUsers.primaryEmailNormalized, juniorUsers.displayName),
|
|
4071
4176
|
getDb().select({
|
|
4072
4177
|
date: activityDate,
|
|
4073
4178
|
...peopleTreeAggregateColumns
|
|
4074
4179
|
}).from(juniorConversations).innerJoin(
|
|
4075
4180
|
juniorIdentities,
|
|
4076
|
-
|
|
4077
|
-
).innerJoin(juniorUsers,
|
|
4181
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4182
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(and14(where, gte4(juniorConversations.lastActivityAt, start))).groupBy(activityDate),
|
|
4078
4183
|
getDb().select({
|
|
4079
4184
|
channel,
|
|
4080
4185
|
channelName: juniorConversations.channelName,
|
|
@@ -4083,10 +4188,10 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4083
4188
|
...peopleTreeAggregateColumns
|
|
4084
4189
|
}).from(juniorConversations).innerJoin(
|
|
4085
4190
|
juniorIdentities,
|
|
4086
|
-
|
|
4087
|
-
).innerJoin(juniorUsers,
|
|
4191
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4192
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).leftJoin(
|
|
4088
4193
|
juniorDestinations,
|
|
4089
|
-
|
|
4194
|
+
eq15(juniorDestinations.id, juniorConversations.destinationId)
|
|
4090
4195
|
).where(where).groupBy(
|
|
4091
4196
|
channel,
|
|
4092
4197
|
juniorConversations.channelName,
|
|
@@ -4095,8 +4200,8 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4095
4200
|
),
|
|
4096
4201
|
getDb().select({ surface, ...peopleTreeAggregateColumns }).from(juniorConversations).innerJoin(
|
|
4097
4202
|
juniorIdentities,
|
|
4098
|
-
|
|
4099
|
-
).innerJoin(juniorUsers,
|
|
4203
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4204
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(where).groupBy(surface),
|
|
4100
4205
|
recentActorRows(normalizedEmail)
|
|
4101
4206
|
]);
|
|
4102
4207
|
const totalsRow = totalsRows[0];
|
|
@@ -4174,7 +4279,7 @@ async function readPeopleProfile(email, options = {}) {
|
|
|
4174
4279
|
}
|
|
4175
4280
|
|
|
4176
4281
|
// src/api/people/spend.query.ts
|
|
4177
|
-
import { and as
|
|
4282
|
+
import { and as and15, eq as eq16, gte as gte5, lte as lte2, sql as sql12 } from "drizzle-orm";
|
|
4178
4283
|
var SEVEN_DAY_OFFSET = 6;
|
|
4179
4284
|
var THIRTY_DAY_OFFSET = 29;
|
|
4180
4285
|
function addUsd2(current, next) {
|
|
@@ -4193,7 +4298,7 @@ function spendWindow(nowMs) {
|
|
|
4193
4298
|
async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
4194
4299
|
const normalizedEmail = normalizeEmail(email);
|
|
4195
4300
|
const { end, sevenDayStart, thirtyDayStart } = spendWindow(nowMs);
|
|
4196
|
-
const activityDate =
|
|
4301
|
+
const activityDate = sql12`TO_CHAR(
|
|
4197
4302
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
4198
4303
|
'YYYY-MM-DD'
|
|
4199
4304
|
)`;
|
|
@@ -4203,9 +4308,9 @@ async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
|
4203
4308
|
date: activityDate
|
|
4204
4309
|
}).from(juniorConversations).innerJoin(
|
|
4205
4310
|
juniorIdentities,
|
|
4206
|
-
|
|
4207
|
-
).innerJoin(juniorUsers,
|
|
4208
|
-
|
|
4311
|
+
eq16(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4312
|
+
).innerJoin(juniorUsers, eq16(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(
|
|
4313
|
+
and15(
|
|
4209
4314
|
verifiedActorWhere(normalizedEmail),
|
|
4210
4315
|
gte5(juniorConversations.lastActivityAt, thirtyDayStart),
|
|
4211
4316
|
lte2(juniorConversations.lastActivityAt, end)
|
|
@@ -4293,7 +4398,7 @@ import { Hono as Hono4 } from "hono";
|
|
|
4293
4398
|
|
|
4294
4399
|
// src/personal-tokens/store.ts
|
|
4295
4400
|
import { createHash, randomBytes, randomUUID } from "crypto";
|
|
4296
|
-
import { and as
|
|
4401
|
+
import { and as and16, desc as desc5, eq as eq17, gt, isNull as isNull7 } from "drizzle-orm";
|
|
4297
4402
|
var TOKEN_PREFIX = "jr_pat_";
|
|
4298
4403
|
var TOKEN_SUFFIX_LENGTH = 8;
|
|
4299
4404
|
var DEFAULT_TOKEN_LIFETIME_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
@@ -4330,8 +4435,8 @@ async function createPersonalToken(args) {
|
|
|
4330
4435
|
}
|
|
4331
4436
|
async function listPersonalTokens(email, now = /* @__PURE__ */ new Date()) {
|
|
4332
4437
|
const rows = await getDb().select().from(juniorApiTokens).where(
|
|
4333
|
-
|
|
4334
|
-
|
|
4438
|
+
and16(
|
|
4439
|
+
eq17(juniorApiTokens.ownerEmailNormalized, normalizeEmail2(email)),
|
|
4335
4440
|
isNull7(juniorApiTokens.revokedAt),
|
|
4336
4441
|
gt(juniorApiTokens.expiresAt, now)
|
|
4337
4442
|
)
|
|
@@ -4340,9 +4445,9 @@ async function listPersonalTokens(email, now = /* @__PURE__ */ new Date()) {
|
|
|
4340
4445
|
}
|
|
4341
4446
|
async function revokePersonalToken(args) {
|
|
4342
4447
|
const rows = await getDb().update(juniorApiTokens).set({ revokedAt: args.now ?? /* @__PURE__ */ new Date() }).where(
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4448
|
+
and16(
|
|
4449
|
+
eq17(juniorApiTokens.id, args.id),
|
|
4450
|
+
eq17(juniorApiTokens.ownerEmailNormalized, normalizeEmail2(args.email)),
|
|
4346
4451
|
isNull7(juniorApiTokens.revokedAt)
|
|
4347
4452
|
)
|
|
4348
4453
|
).returning({ id: juniorApiTokens.id });
|
|
@@ -4354,15 +4459,15 @@ async function authenticatePersonalToken(token2, now = /* @__PURE__ */ new Date(
|
|
|
4354
4459
|
id: juniorApiTokens.id,
|
|
4355
4460
|
ownerEmailNormalized: juniorApiTokens.ownerEmailNormalized
|
|
4356
4461
|
}).from(juniorApiTokens).where(
|
|
4357
|
-
|
|
4358
|
-
|
|
4462
|
+
and16(
|
|
4463
|
+
eq17(juniorApiTokens.tokenHash, hashToken(token2)),
|
|
4359
4464
|
isNull7(juniorApiTokens.revokedAt),
|
|
4360
4465
|
gt(juniorApiTokens.expiresAt, now)
|
|
4361
4466
|
)
|
|
4362
4467
|
).limit(1);
|
|
4363
4468
|
const match = rows[0];
|
|
4364
4469
|
if (!match) return void 0;
|
|
4365
|
-
await getDb().update(juniorApiTokens).set({ lastUsedAt: now }).where(
|
|
4470
|
+
await getDb().update(juniorApiTokens).set({ lastUsedAt: now }).where(eq17(juniorApiTokens.id, match.id));
|
|
4366
4471
|
return match.ownerEmailNormalized;
|
|
4367
4472
|
}
|
|
4368
4473
|
|
|
@@ -4619,7 +4724,7 @@ function readDescriptionText(home) {
|
|
|
4619
4724
|
}
|
|
4620
4725
|
}
|
|
4621
4726
|
async function readSkillReports() {
|
|
4622
|
-
const { discoverSkills } = await import("./skills-
|
|
4727
|
+
const { discoverSkills } = await import("./skills-MBRLNBRV.js");
|
|
4623
4728
|
const skills = await discoverSkills();
|
|
4624
4729
|
return skillReportsSchema.parse(
|
|
4625
4730
|
skills.map((skill) => ({
|
|
@@ -4629,7 +4734,7 @@ async function readSkillReports() {
|
|
|
4629
4734
|
);
|
|
4630
4735
|
}
|
|
4631
4736
|
async function readPlugins() {
|
|
4632
|
-
const { pluginCatalogRuntime } = await import("./catalog-runtime-
|
|
4737
|
+
const { pluginCatalogRuntime } = await import("./catalog-runtime-6VANKLH5.js");
|
|
4633
4738
|
return pluginsSchema.parse(
|
|
4634
4739
|
pluginCatalogRuntime.getProviders().map((plugin) => ({
|
|
4635
4740
|
configKeys: plugin.manifest.configKeys ?? [],
|
|
@@ -4642,7 +4747,7 @@ async function readPlugins() {
|
|
|
4642
4747
|
async function readRuntimeInfoReport() {
|
|
4643
4748
|
const [{ homeDir }, { pluginCatalogRuntime }, plugins, skills] = await Promise.all([
|
|
4644
4749
|
import("./discovery-GUFTFBTL.js"),
|
|
4645
|
-
import("./catalog-runtime-
|
|
4750
|
+
import("./catalog-runtime-6VANKLH5.js"),
|
|
4646
4751
|
readPlugins(),
|
|
4647
4752
|
readSkillReports()
|
|
4648
4753
|
]);
|
|
@@ -4658,7 +4763,7 @@ async function readRuntimeInfoReport() {
|
|
|
4658
4763
|
}
|
|
4659
4764
|
async function readPluginOperationalReportFeed() {
|
|
4660
4765
|
const nowMs = Date.now();
|
|
4661
|
-
const { getPluginOperationalReports } = await import("./agent-hooks-
|
|
4766
|
+
const { getPluginOperationalReports } = await import("./agent-hooks-IAD3AANZ.js");
|
|
4662
4767
|
return pluginOperationalReportFeedSchema.parse({
|
|
4663
4768
|
source: "plugins",
|
|
4664
4769
|
generatedAt: new Date(nowMs).toISOString(),
|