@sentry/junior 0.157.0 → 0.158.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-BOWFTDE5.js} +10 -10
- package/dist/api/conversations/priority.d.ts +2 -1
- package/dist/api/conversations/user-message-activity.d.ts +3 -0
- package/dist/api.js +215 -174
- package/dist/app.js +32 -32
- package/dist/{catalog-runtime-HUGHAFUN.js → catalog-runtime-7GZ25WTR.js} +5 -5
- package/dist/{chunk-AFQ47JQ7.js → chunk-3A7VXSPJ.js} +8 -8
- package/dist/{chunk-VDAEXEBB.js → chunk-4JAOLUDB.js} +6 -6
- package/dist/{chunk-HJ3EZHIX.js → chunk-4Q6QVTKA.js} +5 -5
- package/dist/{chunk-5TIH5GOE.js → chunk-4XJ2WSTI.js} +5 -5
- package/dist/{chunk-F7VOY4VQ.js → chunk-6GJCOUTA.js} +1 -1
- package/dist/{chunk-BLCVTEE7.js → chunk-A7EDLNGU.js} +4 -4
- package/dist/{chunk-G2FN3I66.js → chunk-AF4PHIP6.js} +3 -3
- package/dist/{chunk-MXO6VFB3.js → chunk-BNFGY66A.js} +1 -1
- package/dist/{chunk-GEY6IFXH.js → chunk-C3FYJZSA.js} +4 -4
- package/dist/{chunk-VYDM7HUF.js → chunk-DTVTBZNP.js} +1 -1
- package/dist/{chunk-77QB5FNI.js → chunk-EQ6Y37MD.js} +1 -1
- package/dist/{chunk-OWASYHHV.js → chunk-EXITAVHO.js} +18 -18
- package/dist/{chunk-WNNYOPXX.js → chunk-FA32YRZ3.js} +5 -5
- package/dist/{chunk-UJYA75N5.js → chunk-FAJ6SMEE.js} +2 -2
- package/dist/{chunk-PP4UQTH3.js → chunk-IEM3GFXL.js} +9 -9
- package/dist/{chunk-46ADYIPE.js → chunk-IXYGGJRA.js} +1 -1
- package/dist/{chunk-TA5R6BME.js → chunk-JEXQQLEC.js} +18 -18
- package/dist/{chunk-VBKFO65J.js → chunk-KAFYW3O6.js} +10 -10
- package/dist/{chunk-MKA3T2R6.js → chunk-KSZXVR5G.js} +1 -1
- package/dist/{chunk-RQBRGPUF.js → chunk-LUSAAJJA.js} +2 -2
- package/dist/{chunk-MGJW3SW4.js → chunk-NOEERHHR.js} +6 -6
- package/dist/{chunk-I3OQVVMV.js → chunk-PHQDXC27.js} +1 -1
- package/dist/{chunk-S4PFOWRA.js → chunk-RCIKTZZF.js} +1 -1
- package/dist/{chunk-MDZQ62PB.js → chunk-ROOTB7J7.js} +2 -2
- package/dist/{chunk-XRERMHPN.js → chunk-SAJPQLTY.js} +1 -1
- package/dist/{chunk-4M25PSFB.js → chunk-SSU65ZTZ.js} +1 -1
- package/dist/{chunk-GO2W3VZY.js → chunk-UJ6N32ZM.js} +4 -4
- package/dist/{chunk-D7BNWRYL.js → chunk-UPPU3FQU.js} +1 -1
- package/dist/{chunk-VIBHFGQC.js → chunk-UQJO35BP.js} +4 -4
- package/dist/{chunk-3GS7O66Z.js → chunk-VURJ2NSF.js} +1 -1
- package/dist/{chunk-7J65DOBL.js → chunk-X4BLYIMV.js} +6 -6
- package/dist/{chunk-6MI43QZO.js → chunk-YEZS4TEY.js} +1 -1
- 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-HFWTPYT7.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-J3NW4QL5.js} +23 -23
- package/dist/{runner-U7QI7P4S.js → runner-CL6QHML5.js} +13 -13
- package/dist/{skills-ENKRBZ7K.js → skills-WZWKZIFQ.js} +6 -6
- package/dist/spawn-TQJWADG4.js +37 -0
- package/dist/{validation-VKCDVGA6.js → validation-4HVSSLJV.js} +6 -6
- package/dist/version.js +1 -1
- package/dist/{work-IBD6PWP2.js → work-UF4KXPVG.js} +17 -17
- package/dist/worker-HI7I2W2U.js +24 -0
- package/package.json +5 -5
- package/dist/spawn-4XGNONLS.js +0 -37
- package/dist/worker-TJFXOZRC.js +0 -24
package/dist/api.js
CHANGED
|
@@ -44,14 +44,14 @@ import {
|
|
|
44
44
|
readHealthReport,
|
|
45
45
|
resolveSlackConversationContextFromThreadId,
|
|
46
46
|
webActorFromEmail
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-KAFYW3O6.js";
|
|
48
48
|
import {
|
|
49
49
|
buildSentryConversationUrl,
|
|
50
50
|
getWebAuthorization
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-SSU65ZTZ.js";
|
|
52
52
|
import {
|
|
53
53
|
getConversation
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-A7EDLNGU.js";
|
|
55
55
|
import {
|
|
56
56
|
readTaskExecutionByConversationId,
|
|
57
57
|
readTaskExecutionDays,
|
|
@@ -59,8 +59,8 @@ import {
|
|
|
59
59
|
readTaskExecutionSummaries,
|
|
60
60
|
readTaskExecutions,
|
|
61
61
|
readTaskRuns
|
|
62
|
-
} from "./chunk-
|
|
63
|
-
import "./chunk-
|
|
62
|
+
} from "./chunk-IEM3GFXL.js";
|
|
63
|
+
import "./chunk-4XJ2WSTI.js";
|
|
64
64
|
import {
|
|
65
65
|
healthReportSchema,
|
|
66
66
|
pluginOperationalReportFeedSchema,
|
|
@@ -85,16 +85,16 @@ import {
|
|
|
85
85
|
listPublicScheduledTasksForTeams,
|
|
86
86
|
readLiveAttachment,
|
|
87
87
|
readStats
|
|
88
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-4Q6QVTKA.js";
|
|
89
89
|
import {
|
|
90
90
|
parseSlackThreadId
|
|
91
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-DTVTBZNP.js";
|
|
92
92
|
import {
|
|
93
93
|
agentTurnUsageSchema,
|
|
94
94
|
fallbackShortTitle,
|
|
95
95
|
hasAgentTurnUsage,
|
|
96
96
|
renderJuniorNativeConversationEvent
|
|
97
|
-
} from "./chunk-
|
|
97
|
+
} from "./chunk-C3FYJZSA.js";
|
|
98
98
|
import "./chunk-3Y47VMHV.js";
|
|
99
99
|
import "./chunk-PDO5BLNM.js";
|
|
100
100
|
import {
|
|
@@ -104,11 +104,11 @@ import {
|
|
|
104
104
|
renderPluginConversationEvent,
|
|
105
105
|
resolveViewerUser,
|
|
106
106
|
updateViewerDisplayName
|
|
107
|
-
} from "./chunk-
|
|
107
|
+
} from "./chunk-NOEERHHR.js";
|
|
108
108
|
import {
|
|
109
109
|
getSlackClient,
|
|
110
110
|
withSlackRetries
|
|
111
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-ROOTB7J7.js";
|
|
112
112
|
import {
|
|
113
113
|
decodeStoredConversationEvent,
|
|
114
114
|
getConversationStore,
|
|
@@ -116,7 +116,7 @@ import {
|
|
|
116
116
|
getSqlExecutor,
|
|
117
117
|
locationFromRow,
|
|
118
118
|
parseSessionSource
|
|
119
|
-
} from "./chunk-
|
|
119
|
+
} from "./chunk-AF4PHIP6.js";
|
|
120
120
|
import {
|
|
121
121
|
juniorApiTokens,
|
|
122
122
|
juniorConversationEvents,
|
|
@@ -124,16 +124,16 @@ import {
|
|
|
124
124
|
juniorConversations,
|
|
125
125
|
juniorIdentities,
|
|
126
126
|
juniorUsers
|
|
127
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-VURJ2NSF.js";
|
|
128
128
|
import "./chunk-EM225ITJ.js";
|
|
129
|
-
import "./chunk-
|
|
130
|
-
import "./chunk-
|
|
129
|
+
import "./chunk-PHQDXC27.js";
|
|
130
|
+
import "./chunk-FAJ6SMEE.js";
|
|
131
131
|
import {
|
|
132
132
|
juniorDestinations
|
|
133
133
|
} from "./chunk-VFUK3X5B.js";
|
|
134
134
|
import {
|
|
135
135
|
canExposeConversationPayload
|
|
136
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-UPPU3FQU.js";
|
|
137
137
|
import "./chunk-BDUENQD3.js";
|
|
138
138
|
import {
|
|
139
139
|
parseSlackChannelId,
|
|
@@ -143,10 +143,10 @@ import {
|
|
|
143
143
|
import {
|
|
144
144
|
logException,
|
|
145
145
|
logWarn
|
|
146
|
-
} from "./chunk-
|
|
146
|
+
} from "./chunk-KSZXVR5G.js";
|
|
147
147
|
import "./chunk-6GWA276C.js";
|
|
148
|
-
import "./chunk-
|
|
149
|
-
import "./chunk-
|
|
148
|
+
import "./chunk-6GJCOUTA.js";
|
|
149
|
+
import "./chunk-IXYGGJRA.js";
|
|
150
150
|
import "./chunk-MLKGABMK.js";
|
|
151
151
|
|
|
152
152
|
// src/api.ts
|
|
@@ -1254,7 +1254,7 @@ async function readConversationEventPage(executor, args) {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
|
|
1256
1256
|
// src/api/conversations/list.ts
|
|
1257
|
-
import { and as
|
|
1257
|
+
import { and as and8, asc as asc2, desc as desc2, eq as eq9, isNull as isNull3 } from "drizzle-orm";
|
|
1258
1258
|
|
|
1259
1259
|
// src/api/conversations/shared.ts
|
|
1260
1260
|
function slackStatsLocationLabel(input) {
|
|
@@ -1720,23 +1720,59 @@ function isConversationPriority(conversation, nowMs) {
|
|
|
1720
1720
|
}
|
|
1721
1721
|
if (conversation.assignedWork) {
|
|
1722
1722
|
const finishedAt = Date.parse(conversation.finishedWorkAt ?? "");
|
|
1723
|
-
|
|
1723
|
+
const lastUserMessageAt = Date.parse(conversation.lastUserMessageAt ?? "");
|
|
1724
|
+
return Number.isFinite(finishedAt) && Number.isFinite(lastUserMessageAt) && lastUserMessageAt > finishedAt;
|
|
1724
1725
|
}
|
|
1725
1726
|
return nowMs - lastSeenAt <= UNASSIGNED_PRIORITY_WINDOW_MS;
|
|
1726
1727
|
}
|
|
1727
1728
|
|
|
1729
|
+
// src/api/conversations/user-message-activity.ts
|
|
1730
|
+
import { and as and7, eq as eq8, inArray as inArray6, isNotNull as isNotNull3, or as or3, sql as sql5 } from "drizzle-orm";
|
|
1731
|
+
async function readLastUserMessageAtByConversation(db, conversationIds) {
|
|
1732
|
+
if (conversationIds.length === 0) return /* @__PURE__ */ new Map();
|
|
1733
|
+
const authority = sql5`${juniorConversationEvents.payload}->'provenance'->>'authority'`;
|
|
1734
|
+
const actorPlatform = sql5`${juniorConversationEvents.payload}->'provenance'->'actor'->>'platform'`;
|
|
1735
|
+
const role = sql5`${juniorConversationEvents.payload}->>'role'`;
|
|
1736
|
+
const rows = await db.select({
|
|
1737
|
+
conversationId: juniorConversationEvents.conversationId,
|
|
1738
|
+
lastUserMessageAt: sql5`max(${juniorConversationEvents.createdAt})`
|
|
1739
|
+
}).from(juniorConversationEvents).where(
|
|
1740
|
+
and7(
|
|
1741
|
+
inArray6(juniorConversationEvents.conversationId, conversationIds),
|
|
1742
|
+
or3(
|
|
1743
|
+
and7(
|
|
1744
|
+
eq8(juniorConversationEvents.type, "user_message"),
|
|
1745
|
+
eq8(authority, "instruction"),
|
|
1746
|
+
sql5`${actorPlatform} in ('slack', 'local', 'web')`
|
|
1747
|
+
),
|
|
1748
|
+
and7(
|
|
1749
|
+
eq8(juniorConversationEvents.type, "message"),
|
|
1750
|
+
eq8(role, "user"),
|
|
1751
|
+
isNotNull3(juniorConversationEvents.actorIdentityId)
|
|
1752
|
+
)
|
|
1753
|
+
)
|
|
1754
|
+
)
|
|
1755
|
+
).groupBy(juniorConversationEvents.conversationId);
|
|
1756
|
+
return new Map(
|
|
1757
|
+
rows.map((row) => [
|
|
1758
|
+
row.conversationId,
|
|
1759
|
+
new Date(row.lastUserMessageAt).toISOString()
|
|
1760
|
+
])
|
|
1761
|
+
);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1728
1764
|
// src/api/conversations/list.ts
|
|
1729
1765
|
var CONVERSATION_FEED_LIMIT = 50;
|
|
1730
1766
|
function conversationFeedMembershipFilter(filter) {
|
|
1731
1767
|
if (!filter) return void 0;
|
|
1732
1768
|
if (filter.kind === "viewer") {
|
|
1733
1769
|
return viewerConversationMembership({
|
|
1734
|
-
actorMatch:
|
|
1770
|
+
actorMatch: eq9(juniorIdentities.userId, filter.userId),
|
|
1735
1771
|
participantMatch: conversationHasParticipantUser(filter.userId)
|
|
1736
1772
|
});
|
|
1737
1773
|
}
|
|
1738
1774
|
return viewerConversationMembership({
|
|
1739
|
-
actorMatch:
|
|
1775
|
+
actorMatch: eq9(juniorUsers.primaryEmailNormalized, filter.email),
|
|
1740
1776
|
participantMatch: conversationHasParticipantEmail(filter.email)
|
|
1741
1777
|
});
|
|
1742
1778
|
}
|
|
@@ -1753,12 +1789,12 @@ async function conversationRows(db, limit, filter) {
|
|
|
1753
1789
|
userDisplayName: juniorUsers.displayName
|
|
1754
1790
|
}).from(juniorConversations).leftJoin(
|
|
1755
1791
|
juniorDestinations,
|
|
1756
|
-
|
|
1792
|
+
eq9(juniorDestinations.id, juniorConversations.destinationId)
|
|
1757
1793
|
).leftJoin(
|
|
1758
1794
|
juniorIdentities,
|
|
1759
|
-
|
|
1760
|
-
).leftJoin(juniorUsers,
|
|
1761
|
-
|
|
1795
|
+
eq9(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
1796
|
+
).leftJoin(juniorUsers, eq9(juniorUsers.id, juniorIdentities.userId)).where(
|
|
1797
|
+
and8(
|
|
1762
1798
|
isNull3(juniorConversations.parentConversationId),
|
|
1763
1799
|
isNull3(juniorConversations.archivedAt),
|
|
1764
1800
|
conversationFeedMembershipFilter(filter)
|
|
@@ -1819,11 +1855,11 @@ async function readConversationRecordFromSql(conversationId) {
|
|
|
1819
1855
|
userDisplayName: juniorUsers.displayName
|
|
1820
1856
|
}).from(juniorConversations).leftJoin(
|
|
1821
1857
|
juniorDestinations,
|
|
1822
|
-
|
|
1858
|
+
eq9(juniorDestinations.id, juniorConversations.destinationId)
|
|
1823
1859
|
).leftJoin(
|
|
1824
1860
|
juniorIdentities,
|
|
1825
|
-
|
|
1826
|
-
).leftJoin(juniorUsers,
|
|
1861
|
+
eq9(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
1862
|
+
).leftJoin(juniorUsers, eq9(juniorUsers.id, juniorIdentities.userId)).where(eq9(juniorConversations.conversationId, conversationId)).limit(1);
|
|
1827
1863
|
const row = rows[0];
|
|
1828
1864
|
return row ? {
|
|
1829
1865
|
conversation: conversationFromRow(row),
|
|
@@ -1865,7 +1901,8 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1865
1901
|
auxiliaryCostsByRoot,
|
|
1866
1902
|
metricsByRoot,
|
|
1867
1903
|
teamDomainByTeamId,
|
|
1868
|
-
conversationWork
|
|
1904
|
+
conversationWork,
|
|
1905
|
+
lastUserMessageAtByConversation
|
|
1869
1906
|
] = await Promise.all([
|
|
1870
1907
|
readConversationAccessFromSql(db, conversationIds, options.viewer),
|
|
1871
1908
|
readConversationAuxiliaryCostsFromSql(db, conversationIds, {
|
|
@@ -1877,7 +1914,8 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1877
1914
|
(conversation) => conversation.sessionSource?.platform === "slack" ? [conversation.sessionSource.teamId] : []
|
|
1878
1915
|
)
|
|
1879
1916
|
),
|
|
1880
|
-
listConversationWork(conversationIds)
|
|
1917
|
+
listConversationWork(conversationIds),
|
|
1918
|
+
readLastUserMessageAtByConversation(db, conversationIds)
|
|
1881
1919
|
]);
|
|
1882
1920
|
const assignedWork = new Set(conversationWork.assignedIds);
|
|
1883
1921
|
const unfinishedWork = new Set(conversationWork.unfinishedIds);
|
|
@@ -1907,6 +1945,9 @@ async function readConversationFeedFromSql(options = {}) {
|
|
|
1907
1945
|
isPriority: isConversationPriority(
|
|
1908
1946
|
{
|
|
1909
1947
|
lastSeenAt: summary.lastSeenAt,
|
|
1948
|
+
lastUserMessageAt: lastUserMessageAtByConversation.get(
|
|
1949
|
+
conversation.conversationId
|
|
1950
|
+
),
|
|
1910
1951
|
...work
|
|
1911
1952
|
},
|
|
1912
1953
|
nowMs
|
|
@@ -1924,7 +1965,7 @@ async function readConversationFeed(options = {}) {
|
|
|
1924
1965
|
}
|
|
1925
1966
|
|
|
1926
1967
|
// src/chat/tasks/read.ts
|
|
1927
|
-
import { and as
|
|
1968
|
+
import { and as and9, eq as eq10, or as or4 } from "drizzle-orm";
|
|
1928
1969
|
|
|
1929
1970
|
// src/chat/scheduled-tasks/personal.ts
|
|
1930
1971
|
import { z as z3 } from "zod";
|
|
@@ -2034,16 +2075,16 @@ async function creatorProfileEmails(candidates) {
|
|
|
2034
2075
|
email: juniorUsers.primaryEmailNormalized,
|
|
2035
2076
|
slackUserId: juniorIdentities.providerSubjectId,
|
|
2036
2077
|
teamId: juniorIdentities.providerTenantId
|
|
2037
|
-
}).from(juniorIdentities).innerJoin(juniorUsers,
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2078
|
+
}).from(juniorIdentities).innerJoin(juniorUsers, eq10(juniorUsers.id, juniorIdentities.userId)).where(
|
|
2079
|
+
and9(
|
|
2080
|
+
eq10(juniorIdentities.kind, "user"),
|
|
2081
|
+
eq10(juniorIdentities.provider, "slack"),
|
|
2082
|
+
eq10(juniorIdentities.emailVerified, true),
|
|
2083
|
+
or4(
|
|
2043
2084
|
...[...selectors.values()].map(
|
|
2044
|
-
(selector) =>
|
|
2045
|
-
|
|
2046
|
-
|
|
2085
|
+
(selector) => and9(
|
|
2086
|
+
eq10(juniorIdentities.providerTenantId, selector.teamId),
|
|
2087
|
+
eq10(juniorIdentities.providerSubjectId, selector.slackUserId)
|
|
2047
2088
|
)
|
|
2048
2089
|
)
|
|
2049
2090
|
)
|
|
@@ -2079,12 +2120,12 @@ async function destinationDetails(destinations) {
|
|
|
2079
2120
|
providerTenantId: juniorDestinations.providerTenantId,
|
|
2080
2121
|
visibility: juniorDestinations.visibility
|
|
2081
2122
|
}).from(juniorDestinations).where(
|
|
2082
|
-
|
|
2123
|
+
or4(
|
|
2083
2124
|
...[...selectors.values()].map(
|
|
2084
|
-
(destination) =>
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2125
|
+
(destination) => and9(
|
|
2126
|
+
eq10(juniorDestinations.provider, "slack"),
|
|
2127
|
+
eq10(juniorDestinations.providerTenantId, destination.teamId),
|
|
2128
|
+
eq10(juniorDestinations.providerDestinationId, destination.channelId)
|
|
2088
2129
|
)
|
|
2089
2130
|
)
|
|
2090
2131
|
)
|
|
@@ -2737,20 +2778,20 @@ async function requireConversationPendingMessages(conversationId, options = {})
|
|
|
2737
2778
|
}
|
|
2738
2779
|
|
|
2739
2780
|
// src/api/conversations/stats.query.ts
|
|
2740
|
-
import { and as
|
|
2781
|
+
import { and as and10, eq as eq11, gte, isNull as isNull4, lte, sql as sql7 } from "drizzle-orm";
|
|
2741
2782
|
import { alias as alias4 } from "drizzle-orm/pg-core";
|
|
2742
2783
|
|
|
2743
2784
|
// src/api/conversations/aggregate.ts
|
|
2744
|
-
import { sql as
|
|
2785
|
+
import { sql as sql6 } from "drizzle-orm";
|
|
2745
2786
|
function usageTokenValue(source, field) {
|
|
2746
|
-
return
|
|
2787
|
+
return sql6`CASE
|
|
2747
2788
|
WHEN ${source.usage}->>${field} IS NOT NULL
|
|
2748
2789
|
THEN (${source.usage}->>${field})::double precision
|
|
2749
2790
|
ELSE NULL
|
|
2750
2791
|
END`;
|
|
2751
2792
|
}
|
|
2752
2793
|
function tokenValue(source) {
|
|
2753
|
-
return
|
|
2794
|
+
return sql6`
|
|
2754
2795
|
CASE
|
|
2755
2796
|
WHEN COALESCE(
|
|
2756
2797
|
${source.usage}->>'inputTokens',
|
|
@@ -2769,7 +2810,7 @@ function tokenValue(source) {
|
|
|
2769
2810
|
`;
|
|
2770
2811
|
}
|
|
2771
2812
|
function costValue(source) {
|
|
2772
|
-
return
|
|
2813
|
+
return sql6`
|
|
2773
2814
|
CASE
|
|
2774
2815
|
WHEN ${source.usage}->'cost'->>'total' IS NOT NULL
|
|
2775
2816
|
THEN (${source.usage}->'cost'->>'total')::double precision
|
|
@@ -2790,34 +2831,34 @@ function costValue(source) {
|
|
|
2790
2831
|
function conversationAggregateColumns(sources) {
|
|
2791
2832
|
const metrics = sources?.metrics ?? juniorConversations;
|
|
2792
2833
|
const roots = sources?.roots ?? juniorConversations;
|
|
2793
|
-
const conversationCount = sources ?
|
|
2834
|
+
const conversationCount = sources ? sql6`COUNT(DISTINCT ${roots.conversationId})` : sql6`COUNT(*)`;
|
|
2794
2835
|
return {
|
|
2795
|
-
active:
|
|
2836
|
+
active: sql6`${conversationCount} FILTER (
|
|
2796
2837
|
WHERE ${roots.executionStatus} NOT IN ('idle', 'failed')
|
|
2797
2838
|
)::integer`,
|
|
2798
|
-
conversations:
|
|
2799
|
-
cachedInputTokens:
|
|
2800
|
-
costUsd:
|
|
2801
|
-
durationMs:
|
|
2802
|
-
failed:
|
|
2839
|
+
conversations: sql6`${conversationCount}::integer`,
|
|
2840
|
+
cachedInputTokens: sql6`SUM(${usageTokenValue(metrics, "cachedInputTokens")})::double precision`,
|
|
2841
|
+
costUsd: sql6`SUM(${costValue(metrics)})::double precision`,
|
|
2842
|
+
durationMs: sql6`COALESCE(SUM(${metrics.durationMs}), 0)::double precision`,
|
|
2843
|
+
failed: sql6`${conversationCount} FILTER (
|
|
2803
2844
|
WHERE ${roots.executionStatus} = 'failed'
|
|
2804
2845
|
)::integer`,
|
|
2805
|
-
inputTokens:
|
|
2806
|
-
tokens:
|
|
2846
|
+
inputTokens: sql6`SUM(${usageTokenValue(metrics, "inputTokens")})::double precision`,
|
|
2847
|
+
tokens: sql6`SUM(${tokenValue(metrics)})::double precision`
|
|
2807
2848
|
};
|
|
2808
2849
|
}
|
|
2809
2850
|
function conversationRangeColumns() {
|
|
2810
2851
|
return {
|
|
2811
|
-
firstSeenAt:
|
|
2852
|
+
firstSeenAt: sql6`MIN(${juniorConversations.createdAt})`.mapWith(
|
|
2812
2853
|
juniorConversations.createdAt
|
|
2813
2854
|
),
|
|
2814
|
-
lastSeenAt:
|
|
2855
|
+
lastSeenAt: sql6`MAX(${juniorConversations.lastActivityAt})`.mapWith(
|
|
2815
2856
|
juniorConversations.lastActivityAt
|
|
2816
2857
|
)
|
|
2817
2858
|
};
|
|
2818
2859
|
}
|
|
2819
2860
|
function conversationActiveDaysColumn() {
|
|
2820
|
-
return
|
|
2861
|
+
return sql6`COUNT(DISTINCT (${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC')::date)::integer`;
|
|
2821
2862
|
}
|
|
2822
2863
|
|
|
2823
2864
|
// src/api/conversations/stats.query.ts
|
|
@@ -2881,7 +2922,7 @@ function statsItems(map) {
|
|
|
2881
2922
|
);
|
|
2882
2923
|
}
|
|
2883
2924
|
function statsWhere(start, end) {
|
|
2884
|
-
return
|
|
2925
|
+
return and10(
|
|
2885
2926
|
isNull4(juniorConversations.parentConversationId),
|
|
2886
2927
|
gte(juniorConversations.lastActivityAt, start),
|
|
2887
2928
|
lte(juniorConversations.lastActivityAt, end)
|
|
@@ -2958,14 +2999,14 @@ function guardianStats(rows, endMs) {
|
|
|
2958
2999
|
}
|
|
2959
3000
|
async function aggregateStats(db, start, end) {
|
|
2960
3001
|
const where = statsWhere(start, end);
|
|
2961
|
-
const activityDate =
|
|
3002
|
+
const activityDate = sql7`TO_CHAR(
|
|
2962
3003
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
2963
3004
|
'YYYY-MM-DD'
|
|
2964
3005
|
)`;
|
|
2965
3006
|
const [totalsRows, actorRows, locationRows, metricRows] = await Promise.all([
|
|
2966
3007
|
db.select(treeAggregateColumns).from(juniorConversations).innerJoin(
|
|
2967
3008
|
treeConversation,
|
|
2968
|
-
|
|
3009
|
+
eq11(
|
|
2969
3010
|
treeConversation.rootConversationId,
|
|
2970
3011
|
juniorConversations.conversationId
|
|
2971
3012
|
)
|
|
@@ -2980,14 +3021,14 @@ async function aggregateStats(db, start, end) {
|
|
|
2980
3021
|
...treeAggregateColumns
|
|
2981
3022
|
}).from(juniorConversations).innerJoin(
|
|
2982
3023
|
treeConversation,
|
|
2983
|
-
|
|
3024
|
+
eq11(
|
|
2984
3025
|
treeConversation.rootConversationId,
|
|
2985
3026
|
juniorConversations.conversationId
|
|
2986
3027
|
)
|
|
2987
3028
|
).leftJoin(
|
|
2988
3029
|
juniorIdentities,
|
|
2989
|
-
|
|
2990
|
-
).leftJoin(juniorUsers,
|
|
3030
|
+
eq11(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3031
|
+
).leftJoin(juniorUsers, eq11(juniorUsers.id, juniorIdentities.userId)).where(where).groupBy(
|
|
2991
3032
|
juniorIdentities.displayName,
|
|
2992
3033
|
juniorIdentities.emailNormalized,
|
|
2993
3034
|
juniorIdentities.handle,
|
|
@@ -3005,13 +3046,13 @@ async function aggregateStats(db, start, end) {
|
|
|
3005
3046
|
...treeAggregateColumns
|
|
3006
3047
|
}).from(juniorConversations).innerJoin(
|
|
3007
3048
|
treeConversation,
|
|
3008
|
-
|
|
3049
|
+
eq11(
|
|
3009
3050
|
treeConversation.rootConversationId,
|
|
3010
3051
|
juniorConversations.conversationId
|
|
3011
3052
|
)
|
|
3012
3053
|
).leftJoin(
|
|
3013
3054
|
juniorDestinations,
|
|
3014
|
-
|
|
3055
|
+
eq11(juniorDestinations.id, juniorConversations.destinationId)
|
|
3015
3056
|
).where(where).groupBy(
|
|
3016
3057
|
juniorConversations.channelName,
|
|
3017
3058
|
juniorConversations.source,
|
|
@@ -3030,7 +3071,7 @@ async function aggregateStats(db, start, end) {
|
|
|
3030
3071
|
tokens: treeAggregateColumns.tokens
|
|
3031
3072
|
}).from(juniorConversations).innerJoin(
|
|
3032
3073
|
treeConversation,
|
|
3033
|
-
|
|
3074
|
+
eq11(
|
|
3034
3075
|
treeConversation.rootConversationId,
|
|
3035
3076
|
juniorConversations.conversationId
|
|
3036
3077
|
)
|
|
@@ -3039,26 +3080,26 @@ async function aggregateStats(db, start, end) {
|
|
|
3039
3080
|
return { actorRows, locationRows, metricRows, totals: totalsRows[0] };
|
|
3040
3081
|
}
|
|
3041
3082
|
async function aggregateGuardianStats(db, start, end) {
|
|
3042
|
-
const date =
|
|
3083
|
+
const date = sql7`TO_CHAR(
|
|
3043
3084
|
${juniorConversationEvents.createdAt} AT TIME ZONE 'UTC',
|
|
3044
3085
|
'YYYY-MM-DD'
|
|
3045
3086
|
)`;
|
|
3046
|
-
const decision =
|
|
3047
|
-
const cost2 =
|
|
3087
|
+
const decision = sql7`${juniorConversationEvents.payload}->>'decision'`;
|
|
3088
|
+
const cost2 = sql7`CASE
|
|
3048
3089
|
WHEN jsonb_typeof(${juniorConversationEvents.payload}->'costUsd') = 'number'
|
|
3049
3090
|
THEN (${juniorConversationEvents.payload}->>'costUsd')::double precision
|
|
3050
3091
|
ELSE NULL
|
|
3051
3092
|
END`;
|
|
3052
3093
|
return await db.select({
|
|
3053
|
-
allow:
|
|
3054
|
-
ask:
|
|
3055
|
-
costUsd:
|
|
3094
|
+
allow: sql7`COUNT(*) FILTER (WHERE ${decision} = 'allow')::integer`,
|
|
3095
|
+
ask: sql7`COUNT(*) FILTER (WHERE ${decision} = 'ask')::integer`,
|
|
3096
|
+
costUsd: sql7`SUM(${cost2})::double precision`,
|
|
3056
3097
|
date,
|
|
3057
|
-
deny:
|
|
3058
|
-
requests:
|
|
3098
|
+
deny: sql7`COUNT(*) FILTER (WHERE ${decision} = 'deny')::integer`,
|
|
3099
|
+
requests: sql7`COUNT(*)::integer`
|
|
3059
3100
|
}).from(juniorConversationEvents).where(
|
|
3060
|
-
|
|
3061
|
-
|
|
3101
|
+
and10(
|
|
3102
|
+
eq11(juniorConversationEvents.type, "guardian_action_reviewed"),
|
|
3062
3103
|
gte(juniorConversationEvents.createdAt, start),
|
|
3063
3104
|
lte(juniorConversationEvents.createdAt, end)
|
|
3064
3105
|
)
|
|
@@ -3292,7 +3333,7 @@ function createConversationRoutes(options) {
|
|
|
3292
3333
|
import { Hono as Hono2 } from "hono";
|
|
3293
3334
|
|
|
3294
3335
|
// src/api/locations/query.ts
|
|
3295
|
-
import { and as
|
|
3336
|
+
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
3337
|
import { alias as alias5 } from "drizzle-orm/pg-core";
|
|
3297
3338
|
|
|
3298
3339
|
// src/api/conversations/reporting.ts
|
|
@@ -3400,10 +3441,10 @@ function topLevelWhere() {
|
|
|
3400
3441
|
return isNull5(juniorConversations.parentConversationId);
|
|
3401
3442
|
}
|
|
3402
3443
|
function publicLocationWhere(destinationId) {
|
|
3403
|
-
return
|
|
3444
|
+
return and11(
|
|
3404
3445
|
topLevelWhere(),
|
|
3405
|
-
|
|
3406
|
-
|
|
3446
|
+
eq12(juniorDestinations.id, destinationId),
|
|
3447
|
+
eq12(juniorDestinations.visibility, "public")
|
|
3407
3448
|
);
|
|
3408
3449
|
}
|
|
3409
3450
|
function locationColumns() {
|
|
@@ -3454,28 +3495,28 @@ async function directoryRows(db) {
|
|
|
3454
3495
|
...conversationRangeColumns()
|
|
3455
3496
|
}).from(juniorConversations).innerJoin(
|
|
3456
3497
|
treeConversation2,
|
|
3457
|
-
|
|
3498
|
+
eq12(
|
|
3458
3499
|
treeConversation2.rootConversationId,
|
|
3459
3500
|
juniorConversations.conversationId
|
|
3460
3501
|
)
|
|
3461
3502
|
).leftJoin(
|
|
3462
3503
|
juniorDestinations,
|
|
3463
|
-
|
|
3504
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3464
3505
|
).where(topLevelWhere()).groupBy(...locationGroupBy());
|
|
3465
3506
|
}
|
|
3466
3507
|
async function directoryActivityRows(db, start) {
|
|
3467
|
-
const date =
|
|
3508
|
+
const date = sql8`TO_CHAR(
|
|
3468
3509
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3469
3510
|
'YYYY-MM-DD'
|
|
3470
3511
|
)`;
|
|
3471
3512
|
return db.select({
|
|
3472
|
-
conversations:
|
|
3513
|
+
conversations: sql8`COUNT(*)::integer`,
|
|
3473
3514
|
date,
|
|
3474
3515
|
visibility: juniorDestinations.visibility
|
|
3475
3516
|
}).from(juniorConversations).leftJoin(
|
|
3476
3517
|
juniorDestinations,
|
|
3477
|
-
|
|
3478
|
-
).where(
|
|
3518
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3519
|
+
).where(and11(topLevelWhere(), gte2(juniorConversations.lastActivityAt, start))).groupBy(date, juniorDestinations.visibility);
|
|
3479
3520
|
}
|
|
3480
3521
|
function directoryActivityDays(rows, nowMs) {
|
|
3481
3522
|
const days = /* @__PURE__ */ new Map();
|
|
@@ -3548,7 +3589,7 @@ async function recentLocationRows(db, locationId) {
|
|
|
3548
3589
|
createdAt: juniorConversations.createdAt,
|
|
3549
3590
|
destinationId: juniorDestinations.id,
|
|
3550
3591
|
durationMs: juniorConversations.durationMs,
|
|
3551
|
-
email:
|
|
3592
|
+
email: sql8`COALESCE(
|
|
3552
3593
|
${juniorUsers.primaryEmailNormalized},
|
|
3553
3594
|
${juniorIdentities.email}
|
|
3554
3595
|
)`,
|
|
@@ -3557,7 +3598,7 @@ async function recentLocationRows(db, locationId) {
|
|
|
3557
3598
|
fullName: juniorUsers.displayName,
|
|
3558
3599
|
handle: juniorIdentities.handle,
|
|
3559
3600
|
lastActivityAt: juniorConversations.lastActivityAt,
|
|
3560
|
-
providerSubjectId:
|
|
3601
|
+
providerSubjectId: sql8`CASE
|
|
3561
3602
|
WHEN ${juniorIdentities.provider} = 'slack'
|
|
3562
3603
|
THEN ${juniorIdentities.providerSubjectId}
|
|
3563
3604
|
ELSE NULL
|
|
@@ -3568,12 +3609,12 @@ async function recentLocationRows(db, locationId) {
|
|
|
3568
3609
|
usage: juniorConversations.usage
|
|
3569
3610
|
}).from(juniorConversations).innerJoin(
|
|
3570
3611
|
juniorDestinations,
|
|
3571
|
-
|
|
3612
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3572
3613
|
).leftJoin(
|
|
3573
3614
|
juniorIdentities,
|
|
3574
|
-
|
|
3575
|
-
).leftJoin(juniorUsers,
|
|
3576
|
-
|
|
3615
|
+
eq12(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3616
|
+
).leftJoin(juniorUsers, eq12(juniorUsers.id, juniorIdentities.userId)).where(
|
|
3617
|
+
and11(
|
|
3577
3618
|
publicLocationWhere(locationId),
|
|
3578
3619
|
isNull5(juniorConversations.archivedAt)
|
|
3579
3620
|
)
|
|
@@ -3589,7 +3630,7 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3589
3630
|
const start = new Date(end);
|
|
3590
3631
|
start.setUTCDate(start.getUTCDate() - (ACTIVITY_DAYS - 1));
|
|
3591
3632
|
const where = publicLocationWhere(locationId);
|
|
3592
|
-
const activityDate =
|
|
3633
|
+
const activityDate = sql8`TO_CHAR(
|
|
3593
3634
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3594
3635
|
'YYYY-MM-DD'
|
|
3595
3636
|
)`;
|
|
@@ -3600,27 +3641,27 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3600
3641
|
...conversationRangeColumns()
|
|
3601
3642
|
}).from(juniorConversations).innerJoin(
|
|
3602
3643
|
treeConversation2,
|
|
3603
|
-
|
|
3644
|
+
eq12(
|
|
3604
3645
|
treeConversation2.rootConversationId,
|
|
3605
3646
|
juniorConversations.conversationId
|
|
3606
3647
|
)
|
|
3607
3648
|
).innerJoin(
|
|
3608
3649
|
juniorDestinations,
|
|
3609
|
-
|
|
3650
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3610
3651
|
).where(where).groupBy(...locationGroupBy()),
|
|
3611
3652
|
getDb().select({
|
|
3612
3653
|
date: activityDate,
|
|
3613
3654
|
...treeAggregateColumns2
|
|
3614
3655
|
}).from(juniorConversations).innerJoin(
|
|
3615
3656
|
treeConversation2,
|
|
3616
|
-
|
|
3657
|
+
eq12(
|
|
3617
3658
|
treeConversation2.rootConversationId,
|
|
3618
3659
|
juniorConversations.conversationId
|
|
3619
3660
|
)
|
|
3620
3661
|
).innerJoin(
|
|
3621
3662
|
juniorDestinations,
|
|
3622
|
-
|
|
3623
|
-
).where(
|
|
3663
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3664
|
+
).where(and11(where, gte2(juniorConversations.lastActivityAt, start))).groupBy(activityDate),
|
|
3624
3665
|
getDb().select({
|
|
3625
3666
|
actorIdentityId: juniorConversations.actorIdentityId,
|
|
3626
3667
|
email: juniorUsers.primaryEmailNormalized,
|
|
@@ -3632,17 +3673,17 @@ async function readLocationDetailFromSql(locationId, options = {}) {
|
|
|
3632
3673
|
...treeAggregateColumns2
|
|
3633
3674
|
}).from(juniorConversations).innerJoin(
|
|
3634
3675
|
treeConversation2,
|
|
3635
|
-
|
|
3676
|
+
eq12(
|
|
3636
3677
|
treeConversation2.rootConversationId,
|
|
3637
3678
|
juniorConversations.conversationId
|
|
3638
3679
|
)
|
|
3639
3680
|
).innerJoin(
|
|
3640
3681
|
juniorDestinations,
|
|
3641
|
-
|
|
3682
|
+
eq12(juniorDestinations.id, juniorConversations.destinationId)
|
|
3642
3683
|
).leftJoin(
|
|
3643
3684
|
juniorIdentities,
|
|
3644
|
-
|
|
3645
|
-
).leftJoin(juniorUsers,
|
|
3685
|
+
eq12(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3686
|
+
).leftJoin(juniorUsers, eq12(juniorUsers.id, juniorIdentities.userId)).where(where).groupBy(
|
|
3646
3687
|
juniorConversations.actorIdentityId,
|
|
3647
3688
|
juniorUsers.primaryEmailNormalized,
|
|
3648
3689
|
juniorUsers.displayName,
|
|
@@ -3755,10 +3796,10 @@ function createLocationRoutes() {
|
|
|
3755
3796
|
import { Hono as Hono3 } from "hono";
|
|
3756
3797
|
|
|
3757
3798
|
// src/api/people/list.query.ts
|
|
3758
|
-
import { and as
|
|
3799
|
+
import { and as and13, eq as eq14, gte as gte3, sql as sql10 } from "drizzle-orm";
|
|
3759
3800
|
|
|
3760
3801
|
// src/api/people/shared.ts
|
|
3761
|
-
import { and as
|
|
3802
|
+
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
3803
|
import { alias as alias6 } from "drizzle-orm/pg-core";
|
|
3763
3804
|
var RECENT_LIMIT2 = 25;
|
|
3764
3805
|
var ACTIVITY_DAYS2 = 365;
|
|
@@ -3778,37 +3819,37 @@ var peopleTreeAggregateColumns = conversationAggregateColumns({
|
|
|
3778
3819
|
function peopleTreeMetricsJoin() {
|
|
3779
3820
|
const rootOwnedByActor = getDb().select({ conversationId: peopleRootConversation.conversationId }).from(peopleRootConversation).innerJoin(
|
|
3780
3821
|
peopleRootIdentity,
|
|
3781
|
-
|
|
3822
|
+
eq13(peopleRootIdentity.id, peopleRootConversation.actorIdentityId)
|
|
3782
3823
|
).where(
|
|
3783
|
-
|
|
3784
|
-
|
|
3824
|
+
and12(
|
|
3825
|
+
eq13(
|
|
3785
3826
|
peopleRootConversation.conversationId,
|
|
3786
3827
|
juniorConversations.rootConversationId
|
|
3787
3828
|
),
|
|
3788
3829
|
isNull6(peopleRootConversation.parentConversationId),
|
|
3789
|
-
|
|
3830
|
+
eq13(
|
|
3790
3831
|
peopleRootConversation.rootConversationId,
|
|
3791
3832
|
peopleRootConversation.conversationId
|
|
3792
3833
|
),
|
|
3793
|
-
|
|
3834
|
+
eq13(
|
|
3794
3835
|
peopleRootIdentity.emailNormalized,
|
|
3795
3836
|
juniorUsers.primaryEmailNormalized
|
|
3796
3837
|
),
|
|
3797
|
-
|
|
3838
|
+
eq13(peopleRootIdentity.emailVerified, true)
|
|
3798
3839
|
)
|
|
3799
3840
|
);
|
|
3800
|
-
return
|
|
3801
|
-
|
|
3841
|
+
return and12(
|
|
3842
|
+
eq13(
|
|
3802
3843
|
peopleTreeConversation.rootConversationId,
|
|
3803
3844
|
juniorConversations.rootConversationId
|
|
3804
3845
|
),
|
|
3805
|
-
|
|
3806
|
-
|
|
3846
|
+
or5(
|
|
3847
|
+
eq13(
|
|
3807
3848
|
juniorConversations.rootConversationId,
|
|
3808
3849
|
juniorConversations.conversationId
|
|
3809
3850
|
),
|
|
3810
|
-
|
|
3811
|
-
|
|
3851
|
+
and12(
|
|
3852
|
+
eq13(
|
|
3812
3853
|
peopleTreeConversation.conversationId,
|
|
3813
3854
|
juniorConversations.conversationId
|
|
3814
3855
|
),
|
|
@@ -3858,11 +3899,11 @@ function statsItems2(map) {
|
|
|
3858
3899
|
}
|
|
3859
3900
|
function verifiedActorWhere(email) {
|
|
3860
3901
|
const normalizedEmail = normalizeEmail(email);
|
|
3861
|
-
return
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
normalizedEmail ?
|
|
3902
|
+
return and12(
|
|
3903
|
+
eq13(juniorIdentities.provider, "slack"),
|
|
3904
|
+
eq13(juniorIdentities.emailVerified, true),
|
|
3905
|
+
sql9`${juniorUsers.primaryEmailNormalized} IS NOT NULL`,
|
|
3906
|
+
normalizedEmail ? eq13(juniorUsers.primaryEmailNormalized, normalizedEmail) : void 0
|
|
3866
3907
|
);
|
|
3867
3908
|
}
|
|
3868
3909
|
async function recentActorRows(email) {
|
|
@@ -3885,12 +3926,12 @@ async function recentActorRows(email) {
|
|
|
3885
3926
|
usage: juniorConversations.usage
|
|
3886
3927
|
}).from(juniorConversations).innerJoin(
|
|
3887
3928
|
juniorIdentities,
|
|
3888
|
-
|
|
3889
|
-
).innerJoin(juniorUsers,
|
|
3929
|
+
eq13(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3930
|
+
).innerJoin(juniorUsers, eq13(juniorUsers.id, juniorIdentities.userId)).leftJoin(
|
|
3890
3931
|
juniorDestinations,
|
|
3891
|
-
|
|
3932
|
+
eq13(juniorDestinations.id, juniorConversations.destinationId)
|
|
3892
3933
|
).where(
|
|
3893
|
-
|
|
3934
|
+
and12(verifiedActorWhere(email), isNull6(juniorConversations.archivedAt))
|
|
3894
3935
|
).orderBy(
|
|
3895
3936
|
desc4(juniorConversations.lastActivityAt),
|
|
3896
3937
|
asc4(juniorConversations.conversationId)
|
|
@@ -3919,7 +3960,7 @@ function directoryActivityDays2(rows, nowMs) {
|
|
|
3919
3960
|
async function readPeopleListFromSql() {
|
|
3920
3961
|
const nowMs = Date.now();
|
|
3921
3962
|
const { end, start } = activityWindow(nowMs);
|
|
3922
|
-
const activityDate =
|
|
3963
|
+
const activityDate = sql10`TO_CHAR(
|
|
3923
3964
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
3924
3965
|
'YYYY-MM-DD'
|
|
3925
3966
|
)`;
|
|
@@ -3927,24 +3968,24 @@ async function readPeopleListFromSql() {
|
|
|
3927
3968
|
getDb().select({
|
|
3928
3969
|
email: juniorUsers.primaryEmailNormalized,
|
|
3929
3970
|
fullName: juniorUsers.displayName,
|
|
3930
|
-
slackUserId:
|
|
3931
|
-
slackUserName:
|
|
3971
|
+
slackUserId: sql10`MAX(${juniorIdentities.providerSubjectId})`,
|
|
3972
|
+
slackUserName: sql10`MAX(${juniorIdentities.handle})`,
|
|
3932
3973
|
activeDays: conversationActiveDaysColumn(),
|
|
3933
3974
|
...peopleTreeAggregateColumns,
|
|
3934
3975
|
...conversationRangeColumns()
|
|
3935
3976
|
}).from(juniorConversations).innerJoin(
|
|
3936
3977
|
juniorIdentities,
|
|
3937
|
-
|
|
3938
|
-
).innerJoin(juniorUsers,
|
|
3978
|
+
eq14(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3979
|
+
).innerJoin(juniorUsers, eq14(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, peopleTreeMetricsJoin()).where(verifiedActorWhere()).groupBy(juniorUsers.primaryEmailNormalized, juniorUsers.displayName),
|
|
3939
3980
|
getDb().select({
|
|
3940
|
-
activePeople:
|
|
3941
|
-
conversations:
|
|
3981
|
+
activePeople: sql10`COUNT(DISTINCT ${juniorUsers.id})::int`,
|
|
3982
|
+
conversations: sql10`COUNT(*)::int`,
|
|
3942
3983
|
date: activityDate
|
|
3943
3984
|
}).from(juniorConversations).innerJoin(
|
|
3944
3985
|
juniorIdentities,
|
|
3945
|
-
|
|
3946
|
-
).innerJoin(juniorUsers,
|
|
3947
|
-
|
|
3986
|
+
eq14(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
3987
|
+
).innerJoin(juniorUsers, eq14(juniorUsers.id, juniorIdentities.userId)).where(
|
|
3988
|
+
and13(
|
|
3948
3989
|
verifiedActorWhere(),
|
|
3949
3990
|
gte3(juniorConversations.lastActivityAt, start)
|
|
3950
3991
|
)
|
|
@@ -3987,7 +4028,7 @@ async function readPeopleList() {
|
|
|
3987
4028
|
}
|
|
3988
4029
|
|
|
3989
4030
|
// src/api/people/profile.query.ts
|
|
3990
|
-
import { and as
|
|
4031
|
+
import { and as and14, eq as eq15, gte as gte4, sql as sql11 } from "drizzle-orm";
|
|
3991
4032
|
function emptyProfile(email, nowMs) {
|
|
3992
4033
|
const end = new Date(nowMs);
|
|
3993
4034
|
end.setUTCHours(0, 0, 0, 0);
|
|
@@ -4022,7 +4063,7 @@ function addAggregate2(map, label, row) {
|
|
|
4022
4063
|
map.set(label, item);
|
|
4023
4064
|
}
|
|
4024
4065
|
function surfaceExpression() {
|
|
4025
|
-
return
|
|
4066
|
+
return sql11`CASE
|
|
4026
4067
|
WHEN ${juniorConversations.source} IN ('api', 'scheduler', 'slack')
|
|
4027
4068
|
THEN ${juniorConversations.source}
|
|
4028
4069
|
WHEN ${juniorConversations.conversationId} LIKE 'slack:%' THEN 'slack'
|
|
@@ -4051,30 +4092,30 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4051
4092
|
const where = verifiedActorWhere(normalizedEmail);
|
|
4052
4093
|
const metricsJoin = peopleTreeMetricsJoin();
|
|
4053
4094
|
const surface = surfaceExpression();
|
|
4054
|
-
const activityDate =
|
|
4095
|
+
const activityDate = sql11`TO_CHAR(
|
|
4055
4096
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
4056
4097
|
'YYYY-MM-DD'
|
|
4057
4098
|
)`;
|
|
4058
|
-
const channel =
|
|
4099
|
+
const channel = sql11`SPLIT_PART(${juniorConversations.conversationId}, ':', 2)`;
|
|
4059
4100
|
const [totalsRows, dayRows, locationRows, surfaceRows, recentRows] = await Promise.all([
|
|
4060
4101
|
getDb().select({
|
|
4061
4102
|
email: juniorUsers.primaryEmailNormalized,
|
|
4062
4103
|
fullName: juniorUsers.displayName,
|
|
4063
|
-
slackUserId:
|
|
4064
|
-
slackUserName:
|
|
4104
|
+
slackUserId: sql11`MAX(${juniorIdentities.providerSubjectId})`,
|
|
4105
|
+
slackUserName: sql11`MAX(${juniorIdentities.handle})`,
|
|
4065
4106
|
activeDays: conversationActiveDaysColumn(),
|
|
4066
4107
|
...peopleTreeAggregateColumns
|
|
4067
4108
|
}).from(juniorConversations).innerJoin(
|
|
4068
4109
|
juniorIdentities,
|
|
4069
|
-
|
|
4070
|
-
).innerJoin(juniorUsers,
|
|
4110
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4111
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(where).groupBy(juniorUsers.primaryEmailNormalized, juniorUsers.displayName),
|
|
4071
4112
|
getDb().select({
|
|
4072
4113
|
date: activityDate,
|
|
4073
4114
|
...peopleTreeAggregateColumns
|
|
4074
4115
|
}).from(juniorConversations).innerJoin(
|
|
4075
4116
|
juniorIdentities,
|
|
4076
|
-
|
|
4077
|
-
).innerJoin(juniorUsers,
|
|
4117
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4118
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(and14(where, gte4(juniorConversations.lastActivityAt, start))).groupBy(activityDate),
|
|
4078
4119
|
getDb().select({
|
|
4079
4120
|
channel,
|
|
4080
4121
|
channelName: juniorConversations.channelName,
|
|
@@ -4083,10 +4124,10 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4083
4124
|
...peopleTreeAggregateColumns
|
|
4084
4125
|
}).from(juniorConversations).innerJoin(
|
|
4085
4126
|
juniorIdentities,
|
|
4086
|
-
|
|
4087
|
-
).innerJoin(juniorUsers,
|
|
4127
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4128
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).leftJoin(
|
|
4088
4129
|
juniorDestinations,
|
|
4089
|
-
|
|
4130
|
+
eq15(juniorDestinations.id, juniorConversations.destinationId)
|
|
4090
4131
|
).where(where).groupBy(
|
|
4091
4132
|
channel,
|
|
4092
4133
|
juniorConversations.channelName,
|
|
@@ -4095,8 +4136,8 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
4095
4136
|
),
|
|
4096
4137
|
getDb().select({ surface, ...peopleTreeAggregateColumns }).from(juniorConversations).innerJoin(
|
|
4097
4138
|
juniorIdentities,
|
|
4098
|
-
|
|
4099
|
-
).innerJoin(juniorUsers,
|
|
4139
|
+
eq15(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4140
|
+
).innerJoin(juniorUsers, eq15(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(where).groupBy(surface),
|
|
4100
4141
|
recentActorRows(normalizedEmail)
|
|
4101
4142
|
]);
|
|
4102
4143
|
const totalsRow = totalsRows[0];
|
|
@@ -4174,7 +4215,7 @@ async function readPeopleProfile(email, options = {}) {
|
|
|
4174
4215
|
}
|
|
4175
4216
|
|
|
4176
4217
|
// src/api/people/spend.query.ts
|
|
4177
|
-
import { and as
|
|
4218
|
+
import { and as and15, eq as eq16, gte as gte5, lte as lte2, sql as sql12 } from "drizzle-orm";
|
|
4178
4219
|
var SEVEN_DAY_OFFSET = 6;
|
|
4179
4220
|
var THIRTY_DAY_OFFSET = 29;
|
|
4180
4221
|
function addUsd2(current, next) {
|
|
@@ -4193,7 +4234,7 @@ function spendWindow(nowMs) {
|
|
|
4193
4234
|
async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
4194
4235
|
const normalizedEmail = normalizeEmail(email);
|
|
4195
4236
|
const { end, sevenDayStart, thirtyDayStart } = spendWindow(nowMs);
|
|
4196
|
-
const activityDate =
|
|
4237
|
+
const activityDate = sql12`TO_CHAR(
|
|
4197
4238
|
${juniorConversations.lastActivityAt} AT TIME ZONE 'UTC',
|
|
4198
4239
|
'YYYY-MM-DD'
|
|
4199
4240
|
)`;
|
|
@@ -4203,9 +4244,9 @@ async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
|
4203
4244
|
date: activityDate
|
|
4204
4245
|
}).from(juniorConversations).innerJoin(
|
|
4205
4246
|
juniorIdentities,
|
|
4206
|
-
|
|
4207
|
-
).innerJoin(juniorUsers,
|
|
4208
|
-
|
|
4247
|
+
eq16(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
4248
|
+
).innerJoin(juniorUsers, eq16(juniorUsers.id, juniorIdentities.userId)).leftJoin(peopleTreeConversation, metricsJoin).where(
|
|
4249
|
+
and15(
|
|
4209
4250
|
verifiedActorWhere(normalizedEmail),
|
|
4210
4251
|
gte5(juniorConversations.lastActivityAt, thirtyDayStart),
|
|
4211
4252
|
lte2(juniorConversations.lastActivityAt, end)
|
|
@@ -4293,7 +4334,7 @@ import { Hono as Hono4 } from "hono";
|
|
|
4293
4334
|
|
|
4294
4335
|
// src/personal-tokens/store.ts
|
|
4295
4336
|
import { createHash, randomBytes, randomUUID } from "crypto";
|
|
4296
|
-
import { and as
|
|
4337
|
+
import { and as and16, desc as desc5, eq as eq17, gt, isNull as isNull7 } from "drizzle-orm";
|
|
4297
4338
|
var TOKEN_PREFIX = "jr_pat_";
|
|
4298
4339
|
var TOKEN_SUFFIX_LENGTH = 8;
|
|
4299
4340
|
var DEFAULT_TOKEN_LIFETIME_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
@@ -4330,8 +4371,8 @@ async function createPersonalToken(args) {
|
|
|
4330
4371
|
}
|
|
4331
4372
|
async function listPersonalTokens(email, now = /* @__PURE__ */ new Date()) {
|
|
4332
4373
|
const rows = await getDb().select().from(juniorApiTokens).where(
|
|
4333
|
-
|
|
4334
|
-
|
|
4374
|
+
and16(
|
|
4375
|
+
eq17(juniorApiTokens.ownerEmailNormalized, normalizeEmail2(email)),
|
|
4335
4376
|
isNull7(juniorApiTokens.revokedAt),
|
|
4336
4377
|
gt(juniorApiTokens.expiresAt, now)
|
|
4337
4378
|
)
|
|
@@ -4340,9 +4381,9 @@ async function listPersonalTokens(email, now = /* @__PURE__ */ new Date()) {
|
|
|
4340
4381
|
}
|
|
4341
4382
|
async function revokePersonalToken(args) {
|
|
4342
4383
|
const rows = await getDb().update(juniorApiTokens).set({ revokedAt: args.now ?? /* @__PURE__ */ new Date() }).where(
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4384
|
+
and16(
|
|
4385
|
+
eq17(juniorApiTokens.id, args.id),
|
|
4386
|
+
eq17(juniorApiTokens.ownerEmailNormalized, normalizeEmail2(args.email)),
|
|
4346
4387
|
isNull7(juniorApiTokens.revokedAt)
|
|
4347
4388
|
)
|
|
4348
4389
|
).returning({ id: juniorApiTokens.id });
|
|
@@ -4354,15 +4395,15 @@ async function authenticatePersonalToken(token2, now = /* @__PURE__ */ new Date(
|
|
|
4354
4395
|
id: juniorApiTokens.id,
|
|
4355
4396
|
ownerEmailNormalized: juniorApiTokens.ownerEmailNormalized
|
|
4356
4397
|
}).from(juniorApiTokens).where(
|
|
4357
|
-
|
|
4358
|
-
|
|
4398
|
+
and16(
|
|
4399
|
+
eq17(juniorApiTokens.tokenHash, hashToken(token2)),
|
|
4359
4400
|
isNull7(juniorApiTokens.revokedAt),
|
|
4360
4401
|
gt(juniorApiTokens.expiresAt, now)
|
|
4361
4402
|
)
|
|
4362
4403
|
).limit(1);
|
|
4363
4404
|
const match = rows[0];
|
|
4364
4405
|
if (!match) return void 0;
|
|
4365
|
-
await getDb().update(juniorApiTokens).set({ lastUsedAt: now }).where(
|
|
4406
|
+
await getDb().update(juniorApiTokens).set({ lastUsedAt: now }).where(eq17(juniorApiTokens.id, match.id));
|
|
4366
4407
|
return match.ownerEmailNormalized;
|
|
4367
4408
|
}
|
|
4368
4409
|
|
|
@@ -4619,7 +4660,7 @@ function readDescriptionText(home) {
|
|
|
4619
4660
|
}
|
|
4620
4661
|
}
|
|
4621
4662
|
async function readSkillReports() {
|
|
4622
|
-
const { discoverSkills } = await import("./skills-
|
|
4663
|
+
const { discoverSkills } = await import("./skills-WZWKZIFQ.js");
|
|
4623
4664
|
const skills = await discoverSkills();
|
|
4624
4665
|
return skillReportsSchema.parse(
|
|
4625
4666
|
skills.map((skill) => ({
|
|
@@ -4629,7 +4670,7 @@ async function readSkillReports() {
|
|
|
4629
4670
|
);
|
|
4630
4671
|
}
|
|
4631
4672
|
async function readPlugins() {
|
|
4632
|
-
const { pluginCatalogRuntime } = await import("./catalog-runtime-
|
|
4673
|
+
const { pluginCatalogRuntime } = await import("./catalog-runtime-7GZ25WTR.js");
|
|
4633
4674
|
return pluginsSchema.parse(
|
|
4634
4675
|
pluginCatalogRuntime.getProviders().map((plugin) => ({
|
|
4635
4676
|
configKeys: plugin.manifest.configKeys ?? [],
|
|
@@ -4642,7 +4683,7 @@ async function readPlugins() {
|
|
|
4642
4683
|
async function readRuntimeInfoReport() {
|
|
4643
4684
|
const [{ homeDir }, { pluginCatalogRuntime }, plugins, skills] = await Promise.all([
|
|
4644
4685
|
import("./discovery-GUFTFBTL.js"),
|
|
4645
|
-
import("./catalog-runtime-
|
|
4686
|
+
import("./catalog-runtime-7GZ25WTR.js"),
|
|
4646
4687
|
readPlugins(),
|
|
4647
4688
|
readSkillReports()
|
|
4648
4689
|
]);
|
|
@@ -4658,7 +4699,7 @@ async function readRuntimeInfoReport() {
|
|
|
4658
4699
|
}
|
|
4659
4700
|
async function readPluginOperationalReportFeed() {
|
|
4660
4701
|
const nowMs = Date.now();
|
|
4661
|
-
const { getPluginOperationalReports } = await import("./agent-hooks-
|
|
4702
|
+
const { getPluginOperationalReports } = await import("./agent-hooks-BOWFTDE5.js");
|
|
4662
4703
|
return pluginOperationalReportFeedSchema.parse({
|
|
4663
4704
|
source: "plugins",
|
|
4664
4705
|
generatedAt: new Date(nowMs).toISOString(),
|