@sentry/junior 0.306.0 → 0.307.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-context-CnY-i32r.js → adapter-context-HrBTD8rJ.js} +2 -2
- package/dist/{admin-BLLdLnXh.js → admin-B78_KmfR.js} +2 -2
- package/dist/{agent-runner-BaLjEjPR.js → agent-runner-DxivxUYd.js} +226 -137
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +4 -4
- package/dist/api.d.ts +1 -1
- package/dist/api.js +328 -298
- package/dist/{app-DvYbM9UD.d.ts → app-EZur8cVC.d.ts} +12 -3
- package/dist/app.d.ts +2 -2
- package/dist/app.js +84 -44
- package/dist/background-compaction-queue-HlljT9ql.js +231 -0
- package/dist/{briefs-DvyzXfrF.js → briefs-DR8mp-TK.js} +2 -2
- package/dist/{catalog-runtime-B1R-nHd3.js → catalog-runtime-Se9idiDR.js} +1 -1
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +17 -16
- package/dist/cli/check.js +58 -48
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.d.ts +1 -1
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +2 -2
- package/dist/cli/upgrade.js +3 -8
- package/dist/{config-DUD-zMvp.js → config-DY5c1E0l.js} +74 -38
- package/dist/{connections-CDhsqPcC.js → connections-C-SqzubG.js} +10 -8
- package/dist/{continue-in-slack-BXQizz9o.js → continue-in-slack-DNkrrWuQ.js} +5 -5
- package/dist/{conversation-privacy-YE54gMN8.js → conversation-privacy-CVj9vSrP.js} +1 -1
- package/dist/{conversation-turn-BzdmrHb0.js → conversation-turn-CkzrIfJ2.js} +19 -47
- package/dist/{credential-sync-Cdm-e1vJ.js → credential-sync-B9CIkgOT.js} +28 -28
- package/dist/{db-DV2ZUb1Y.js → db-C21CyyTE.js} +140 -11
- package/dist/{db-pH357Dkt.d.ts → db-C41UgdBj.d.ts} +1 -1
- package/dist/{executor-CjNhwwnj.js → executor-DfNoVVGd.js} +93 -32
- package/dist/{install-DbD7C5td.js → install-lYZs8UCL.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-BFdIPb3o.js → lineage-BJTSY53A.js} +2 -2
- package/dist/{logging-oYpJYr-S.js → logging-DjW7LjgJ.js} +1 -1
- package/dist/{message-BBPcMKJY.js → message-BPPZpdoZ.js} +8 -8
- package/dist/{model-input-DYYF3a8B.js → model-input-DKqiLFGa.js} +3 -3
- package/dist/nitro.d.ts +2 -2
- package/dist/nitro.js +12 -5
- package/dist/{oauth-callback-server-C7Q987su.js → oauth-callback-server-OJP8Y4Ca.js} +2 -2
- package/dist/{oauth-relay-DAmfVmJu.js → oauth-relay-KwDz41Z3.js} +1 -1
- package/dist/{plugins-B_0Cr0MO.d.ts → plugins-fBrz8PCV.d.ts} +2 -0
- package/dist/{projection-CWXDE0f6.js → projection-D47mlszd.js} +1112 -693
- package/dist/{prompt-P3eRqO8C.js → prompt-DuWH_YIb.js} +3 -3
- package/dist/{registry-1pzXmplY.js → registry-yht0oxq6.js} +19 -9
- package/dist/{resolve-n87oXY-d.js → resolve-gZ-hVMYl.js} +3 -3
- package/dist/{result-BmF9v9bv.js → result-CP99Ok0_.js} +13 -11
- package/dist/{runner-4j7ZsxP5.js → runner-eVlnUkY7.js} +9 -9
- package/dist/{sandbox-egress-signals-BRQI8HvT.js → sandbox-egress-signals-DZL_0lnG.js} +1 -1
- package/dist/{schedule-CHPWQn-x.js → schedule-BG1tEbRF.js} +34 -4
- package/dist/{schema-CVbIjrF3.d.ts → schema-CRXcj4fj.d.ts} +350 -143
- package/dist/{schema-D7iIEh6t.js → schema-D4jdesIu.js} +12 -4
- package/dist/{service-account-DzQiOmqa.js → service-account-CZneZHh7.js} +8 -6
- package/dist/{service-account-BDQ9xzta.js → service-account-tI3LBg2_.js} +3 -3
- package/dist/{session-stop-BQxgHR4X.js → session-stop-D3S7mSkX.js} +36 -23
- package/dist/{skills-CPf4vNuC.js → skills-Bm6uSO9V.js} +32 -28
- package/dist/{slack-conversation-unfurl-B1KEptUg.js → slack-conversation-unfurl-BeBvg3xU.js} +10 -10
- package/dist/{spawn-CjGddiAU.js → spawn-vhMAmLuh.js} +6 -6
- package/dist/{state-9wfj6aSD.js → state-3Yiy2FvP.js} +4 -4
- package/dist/{stop-CsQGuN5n.js → stop-Bh53GUoX.js} +146 -158
- package/dist/{store-Dz3YZ7gQ.js → store-BZJdHYR7.js} +5 -5
- package/dist/{background-compaction-queue-D2wzxtGU.js → task-queue-BEl5G38v.js} +164 -180
- package/dist/{task-runner-frzlUvFD.js → task-runner-C6Bujc6h.js} +11 -8
- package/dist/{thread-context-C4QuZlM8.js → thread-context-DxMQGGd_.js} +6 -6
- package/dist/{turn-session-routing-BXaubz2w.js → turn-session-routing-CmQY0T60.js} +24 -5
- package/dist/{turn-user-message-DNC0eRZ7.js → turn-user-message-Dfbr3Ud9.js} +3 -3
- package/dist/{users-XCCKn3xW.js → users-6rSdqXXk.js} +1 -1
- package/dist/{validation-L5fdjmFX.js → validation--hsjOLRL.js} +1 -1
- package/dist/{version-BFmuwgxP.js → version-9iMT25Hq.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-DKOeHpv3.js → viewer-De1vmuEA.js} +3 -3
- package/dist/{warmup-mTMIatCV.js → warmup-C0IblNtf.js} +596 -281
- package/dist/{web-message-id-CUaSiGme.js → web-message-id-BT8Mg8LL.js} +1 -1
- package/dist/{worker-Bz4KNxjI.js → worker-CiyRr2q7.js} +8 -7
- package/migrations/0115_automation_creator_slack_index.sql +1 -0
- package/migrations/0116_conversation_event_search.sql +25 -0
- package/migrations/0117_automation_last_run.sql +46 -0
- package/migrations/0118_automation_last_run_index.sql +1 -0
- package/migrations/0119_money_micro_usd.sql +29 -0
- package/migrations/0120_conversation_cost_micro_usd.sql +8 -0
- package/migrations/meta/0115_snapshot.json +5225 -0
- package/migrations/meta/0116_snapshot.json +5388 -0
- package/migrations/meta/0117_snapshot.json +5413 -0
- package/migrations/meta/0118_snapshot.json +5428 -0
- package/migrations/meta/0119_snapshot.json +5441 -0
- package/migrations/meta/0120_snapshot.json +5441 -0
- package/migrations/meta/_journal.json +42 -0
- package/package.json +10 -9
- package/dist/queue-7FSijgqG.js +0 -115
- package/dist/secrets-DHaJ5TTn.js +0 -18
- package/dist/task-queue-CFlrJguF.js +0 -89
package/dist/api.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import { V as escapeXml, n as botConfig, ut as getAttachmentStorage } from "./config-
|
|
2
|
-
import { $ as getStateAdapter, A as conversationKindFromRow, C as withConversationMutationLock, X as createCache,
|
|
3
|
-
import { Dt as AttachmentUploadError,
|
|
1
|
+
import { V as escapeXml, n as botConfig, ut as getAttachmentStorage } from "./config-DY5c1E0l.js";
|
|
2
|
+
import { $ as getStateAdapter, A as conversationKindFromRow, C as withConversationMutationLock, X as createCache, a as getConversationStore, dt as microUsdToUsd, ht as conversationUsageCostExpr, mt as conversationRangeColumns, o as getDb, pt as conversationAggregateColumns, s as getSqlExecutor, ut as microUsdSql, wt as nextDetailVersion, y as loadConversationSlackTenantIds } from "./db-C21CyyTE.js";
|
|
3
|
+
import { Dt as AttachmentUploadError, Ft as listOwnedWatches, Gn as emptyResponse, It as listChildAgents, Kn as jsonResponse, Oi as countOwnedAutomationsNeedingAttention, Tt as webActorFromUser, Wn as setConversationSubscription, _ as closeBreaker, ai as deleteViewerTask, ci as ViewerTaskNotFoundError, di as readViewerAutomationRuns, fi as readViewerAutomationSummary, ft as reportConversationRead, g as breakerStates, h as savingsTotals, ii as changeViewerAutomationLifecycle, jt as writeAttachmentUpload, kt as createAttachmentUpload, lt as archiveConversation, mi as readViewerAutomations, oi as readViewerAutomationEdit, pi as readViewerAutomationVersions, qn as throwApiError, si as updateViewerAutomation, ti as activateViewerAutomationVersion, u as SAVINGS_NAMESPACE, ui as readViewerAutomationExecutions, v as connectedState, w as readStats, xi as AutomationEditError, yt as acceptsWebMessages } from "./warmup-C0IblNtf.js";
|
|
4
4
|
import { C as createConversationMessageBodySchema, H as renameConversationResponseSchema, S as createConversationBodySchema, T as forkConversationResponseSchema, U as conversationReadPositionSchema, V as renameConversationBodySchema, Z as MAX_ATTACHMENT_BYTES, f as conversationEventPageSchema, l as conversationDetailQuerySchema, m as conversationParamsSchema, n as CONVERSATION_VERSION_HEADER, o as conversationAttachmentParamsSchema, p as conversationEventsQuerySchema, r as acceptedConversationMessageSchema, s as conversationAttachmentQuerySchema, t as CONVERSATION_DETAIL_VERSION_HEADER, u as conversationDetailReportSchema, w as forkConversationBodySchema } from "./conversation--f85g4zL.js";
|
|
5
|
-
import { $ as testNotificationResponseSchema, A as startServiceAccountSignInResponseSchema, At as objectLinksReportSchema, B as personParamsSchema, Bt as conversationSubscriptionResponseSchema, C as cacheWarmingSavingsRefillResponseSchema, Ct as conversationChildAgentsReportSchema, D as serviceAccountListSchema, Dt as attachObjectLinkBodySchema, E as disconnectServiceAccountResponseSchema, F as personalTokenParamsSchema, Ft as archiveConversationBodySchema, G as locationParamsSchema, Gt as reorderPinnedConversationsBodySchema, Ht as conversationDeliveryResponseSchema, I as revokePersonalTokenResponseSchema, It as archiveConversationResponseSchema, J as activitySixHours$1, Jt as conversationCatchUpSchema, K as activityDays$1, Kt as reorderPinnedConversationsResponseSchema, L as actorDirectoryReportSchema, Lt as archiveDoneConversationsResponseSchema, M as createdPersonalTokenSchema, Mt as conversationStatsReportSchema, N as personalTokenListSchema, O as serviceAccountParamsSchema, Ot as attachObjectLinkResponseSchema, Pt as conversationOutlineSchema, Q as pushSubscriptionDeleteBodySchema, R as actorProfileReportSchema, Rt as conversationAutoArchiveSchema, S as cacheWarmingSavingsQuerySchema, T as closeCacheWarmingBreakerResponseSchema, Tt as continueConversationInSlackResponseSchema, U as locationDetailReportSchema, Ut as pinConversationBodySchema, V as personalSpendReportSchema, Vt as conversationDeliveryBodySchema, W as locationDirectoryReportSchema, Wt as pinConversationResponseSchema, X as notificationSettingsSchema, Xt as attachmentUploadSchema, Yt as attachmentUploadParamsSchema, Z as pushSubscriptionBodySchema, Zt as createAttachmentUploadBodySchema, _ as reviewItemParamsSchema, _t as conversationPlanReportSchema, b as cacheWarmingBreakerListSchema, c as workspaceListSchema, d as workspaceSchema, dt as codeRepositoryParamsSchema, et as connectionListSchema, f as reviewItemActionSchema, ft as codeRepositoryQuerySchema, g as reviewItemListSchema, gt as conversationPlanItemSchema, h as reviewItemListQuerySchema, ht as personCodeQuerySchema, i as statsReportSchema, it as startConnectionResponseSchema, j as createPersonalTokenBodySchema, jt as stopConversationTurnResponseSchema, kt as objectLinksQuerySchema, l as workspaceParamsSchema, lt as codeOverviewReportSchema, m as reviewItemCountSchema, n as versionsSchema, o as deleteWorkspaceResponseSchema, p as reviewItemCountQuerySchema, pt as codeRepositoryReportSchema, q as activityHours$1, qt as conversationCatchUpBodySchema, rt as disconnectConnectionResponseSchema, s as workspaceBodySchema, t as versionsQuerySchema, tt as connectionParamsSchema, ut as codePersonReportSchema, v as reviewItemSchema, vt as planItemParamsSchema, w as cacheWarmingSavingsReportSchema, wt as continueConversationInSlackBodySchema, x as cacheWarmingBreakerParamsSchema, xt as conversationWatchesReportSchema, y as reviewItemWaitingConversationsSchema, yt as planItemStatusBodySchema, z as avatarParamsSchema, zt as conversationSubscriptionBodySchema } from "./schema-
|
|
5
|
+
import { $ as testNotificationResponseSchema, A as startServiceAccountSignInResponseSchema, At as objectLinksReportSchema, B as personParamsSchema, Bt as conversationSubscriptionResponseSchema, C as cacheWarmingSavingsRefillResponseSchema, Ct as conversationChildAgentsReportSchema, D as serviceAccountListSchema, Dt as attachObjectLinkBodySchema, E as disconnectServiceAccountResponseSchema, F as personalTokenParamsSchema, Ft as archiveConversationBodySchema, G as locationParamsSchema, Gt as reorderPinnedConversationsBodySchema, Ht as conversationDeliveryResponseSchema, I as revokePersonalTokenResponseSchema, It as archiveConversationResponseSchema, J as activitySixHours$1, Jt as conversationCatchUpSchema, K as activityDays$1, Kt as reorderPinnedConversationsResponseSchema, L as actorDirectoryReportSchema, Lt as archiveDoneConversationsResponseSchema, M as createdPersonalTokenSchema, Mt as conversationStatsReportSchema, N as personalTokenListSchema, O as serviceAccountParamsSchema, Ot as attachObjectLinkResponseSchema, Pt as conversationOutlineSchema, Q as pushSubscriptionDeleteBodySchema, R as actorProfileReportSchema, Rt as conversationAutoArchiveSchema, S as cacheWarmingSavingsQuerySchema, T as closeCacheWarmingBreakerResponseSchema, Tt as continueConversationInSlackResponseSchema, U as locationDetailReportSchema, Ut as pinConversationBodySchema, V as personalSpendReportSchema, Vt as conversationDeliveryBodySchema, W as locationDirectoryReportSchema, Wt as pinConversationResponseSchema, X as notificationSettingsSchema, Xt as attachmentUploadSchema, Yt as attachmentUploadParamsSchema, Z as pushSubscriptionBodySchema, Zt as createAttachmentUploadBodySchema, _ as reviewItemParamsSchema, _t as conversationPlanReportSchema, b as cacheWarmingBreakerListSchema, c as workspaceListSchema, d as workspaceSchema, dt as codeRepositoryParamsSchema, et as connectionListSchema, f as reviewItemActionSchema, ft as codeRepositoryQuerySchema, g as reviewItemListSchema, gt as conversationPlanItemSchema, h as reviewItemListQuerySchema, ht as personCodeQuerySchema, i as statsReportSchema, it as startConnectionResponseSchema, j as createPersonalTokenBodySchema, jt as stopConversationTurnResponseSchema, kt as objectLinksQuerySchema, l as workspaceParamsSchema, lt as codeOverviewReportSchema, m as reviewItemCountSchema, n as versionsSchema, o as deleteWorkspaceResponseSchema, p as reviewItemCountQuerySchema, pt as codeRepositoryReportSchema, q as activityHours$1, qt as conversationCatchUpBodySchema, rt as disconnectConnectionResponseSchema, s as workspaceBodySchema, t as versionsQuerySchema, tt as connectionParamsSchema, ut as codePersonReportSchema, v as reviewItemSchema, vt as planItemParamsSchema, w as cacheWarmingSavingsReportSchema, wt as continueConversationInSlackBodySchema, x as cacheWarmingBreakerParamsSchema, xt as conversationWatchesReportSchema, y as reviewItemWaitingConversationsSchema, yt as planItemStatusBodySchema, z as avatarParamsSchema, zt as conversationSubscriptionBodySchema } from "./schema-D4jdesIu.js";
|
|
6
6
|
import { S as skillDetailReportSchema, a as cancelConversationPendingMessagesResponseSchema, b as pluginsSchema, d as conversationUnchangedDetailWithMailboxSchema, f as steerConversationPendingMessagesBodySchema, h as pluginOperationalReportFeedSchema, i as cancelConversationPendingMessagesBodySchema, m as healthReportSchema, n as conversationFeedQuerySchema, o as conversationDetailWithMailboxReportSchema, p as steerConversationPendingMessagesResponseSchema, r as conversationFeedSchema, u as conversationPendingMessagesReportSchema, w as skillReportsSchema, x as runtimeInfoReportSchema } from "./conversation-feed-BNs9KiqC.js";
|
|
7
|
-
import { G as isAllowedDomain, H as addConversationNote, S as setPlanItemStatusByUser, _ as readUserCustomization, ft as isExperimentalFeatureEnabled, mt as getEventCatalog, q as parseEmail, v as saveUserCustomization, x as listPlanItems } from "./session-stop-
|
|
8
|
-
import { $
|
|
9
|
-
import { A as actOnReviewItem, B as readSavingsRefill, Ct as decodeImageId, D as resolveMentions, E as requireConversationPendingMessages, G as readHealthReport, H as startSavingsRefill, I as setConversationAutoArchive, J as readObjectLinkTypes, K as OBJECT_LINK_TTL_MS, L as DEFAULT_USER_SETTINGS, M as readReviewItemForUser, P as archiveViewerDoneConversations, R as readUserSettings, St as IMAGE_WIDTHS, X as resolveObjectLinks, Y as resolveObjectLinkNow, Z as guardedFetch, _ as readConversationEvents, a as decodePageCursor, b as createConversationForViewer, bt as readFirstHumanMessageTexts, c as reorderPinnedConversations, d as childAgentTotalsReport, f as readConversationTreeMetricsFromSql, g as keepQuickQuestionForViewer, h as forkConversationForViewer, i as readConversationFeed, k as ReviewItemActionError, l as readConversationDetail, m as readConversationDetailEtag, n as steerConversationPendingMessagesForViewer, nt as getProductionSlackAdapter, o as encodePageCursor, p as conversationVersionQuery, q as readLinkObjectType, r as conversationFeedVersionQuery, s as pinConversation, t as stopConversationTurnForViewer, u as readConversationAuxiliaryCostsFromSql, w as cancelConversationPendingMessagesForViewer, x as requireWebMessageConversation, xt as createViewerMcp, y as appendConversationMessageForViewer, yt as conversationSummaryFromStoredConversation, z as updateUserSettings } from "./stop-
|
|
10
|
-
import { d as completeText, n as briefEntriesFromReportEvents } from "./prompt-
|
|
11
|
-
import {
|
|
12
|
-
import { _ as runBestEffort, h as logWarn, m as logInfo, p as logException } from "./logging-
|
|
13
|
-
import { t as runWithSlackInstallation } from "./adapter-context-
|
|
14
|
-
import { A as
|
|
15
|
-
import { i as continueConversationInSlack, r as canContinueInSlack, t as BUSY } from "./continue-in-slack-
|
|
7
|
+
import { G as isAllowedDomain, H as addConversationNote, S as setPlanItemStatusByUser, _ as readUserCustomization, ft as isExperimentalFeatureEnabled, mt as getEventCatalog, q as parseEmail, v as saveUserCustomization, x as listPlanItems } from "./session-stop-D3S7mSkX.js";
|
|
8
|
+
import { $r as reviewItemReaderForUser, Ar as countOpenReviewItemsForUser, Bi as updateWorkspace, Cr as saveNotificationSchedule, Ea as workspaceRepoCheckoutPath, Fi as deleteWorkspace, Hc as AutomationConflictError, Ii as getWorkspace, Is as escapeSlackMrkdwnText, Jr as itemNeedsUser, Ka as createConversationAccessReader, Ki as create, Lr as listWaitingConversations, Ls as formatSlackLink, Nn as getPlugins, No as createPluginAnnotations, Pi as createWorkspace, Po as listConversationAnnotations, Ri as listWorkspaces, Rr as reviewItemsNeedingUserVersionQuery, Sr as readNotificationSchedule, Tr as isPausedBySlack, Ua as createPluginLogger, Ur as canActOnReviewItem, Vi as WorkspaceValidationError, _r as readWebPushConfig, ac as getDashboardSettingsLink, bn as createUserTokenStore, bo as readLiveAttachment, br as deletePushSubscription, ec as getDashboardConversationLink, ei as reviewItemReaderForUserInConversation, fs as postSlackMessage, ho as readSlackAttachmentSource, jr as countReviewItemsNeedingUserBySubject, nl as readAutomationTitlesByConversationId, qa as readConversationAccessFromSql, qi as hash, qr as isOnlyAssignee, ro as readConversationEventPage, to as readConversationBriefThrough, ul as createPluginCache, vr as sendPushNotificationToUser, wa as SANDBOX_RUNTIME, wc as automationEventCatalog, wr as savePushSubscription, xr as listPushSubscriptions, yr as resolveNotificationTimezone, z as createPluginEgress, zi as listWorkspacesByRepository, zr as searchReviewItems } from "./projection-D47mlszd.js";
|
|
9
|
+
import { A as actOnReviewItem, B as readSavingsRefill, Ct as decodeImageId, D as resolveMentions, E as requireConversationPendingMessages, G as readHealthReport, H as startSavingsRefill, I as setConversationAutoArchive, J as readObjectLinkTypes, K as OBJECT_LINK_TTL_MS, L as DEFAULT_USER_SETTINGS, M as readReviewItemForUser, P as archiveViewerDoneConversations, R as readUserSettings, St as IMAGE_WIDTHS, X as resolveObjectLinks, Y as resolveObjectLinkNow, Z as guardedFetch, _ as readConversationEvents, a as decodePageCursor, b as createConversationForViewer, bt as readFirstHumanMessageTexts, c as reorderPinnedConversations, d as childAgentTotalsReport, f as readConversationTreeMetricsFromSql, g as keepQuickQuestionForViewer, h as forkConversationForViewer, i as readConversationFeed, k as ReviewItemActionError, l as readConversationDetail, m as readConversationDetailEtag, n as steerConversationPendingMessagesForViewer, nt as getProductionSlackAdapter, o as encodePageCursor, p as conversationVersionQuery, q as readLinkObjectType, r as conversationFeedVersionQuery, s as pinConversation, t as stopConversationTurnForViewer, u as readConversationAuxiliaryCostsFromSql, w as cancelConversationPendingMessagesForViewer, x as requireWebMessageConversation, xt as createViewerMcp, y as appendConversationMessageForViewer, yt as conversationSummaryFromStoredConversation, z as updateUserSettings } from "./stop-Bh53GUoX.js";
|
|
10
|
+
import { d as completeText, n as briefEntriesFromReportEvents } from "./prompt-DuWH_YIb.js";
|
|
11
|
+
import { A as resumeConversationDelivery, D as canPauseConversationDelivery, M as readAttachmentContent, N as previewOriginBelongsTo, _ as createSlackReviewItemShow, j as AttachmentDownloadError, k as pauseConversationDelivery } from "./agent-runner-DxivxUYd.js";
|
|
12
|
+
import { _ as runBestEffort, h as logWarn, m as logInfo, p as logException } from "./logging-DjW7LjgJ.js";
|
|
13
|
+
import { t as runWithSlackInstallation } from "./adapter-context-HrBTD8rJ.js";
|
|
14
|
+
import { A as juniorConversationEvents, B as juniorUsers, E as juniorConversationBriefs, N as juniorCodeChanges, O as juniorConversationMetrics, P as juniorCodeRepositories, R as juniorConversations, V as juniorDestinations, j as juniorApiTokens, z as juniorIdentities } from "./executor-DfNoVVGd.js";
|
|
15
|
+
import { i as continueConversationInSlack, r as canContinueInSlack, t as BUSY } from "./continue-in-slack-DNkrrWuQ.js";
|
|
16
16
|
import { f as parseSlackTeamId, u as parseSlackChannelId } from "./actor-D2iXzvlN.js";
|
|
17
|
-
import { A as HOUR_MS$1,
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { n as
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { o as getVercelConversationWorkQueue } from "./background-compaction-queue-D2wzxtGU.js";
|
|
17
|
+
import { A as HOUR_MS$1, F as sumUtcHoursIntoSixHours, I as trailingUtcDayWindow, L as trailingUtcHourWindow, M as fillUtcHours, N as fillUtcSixHours, O as apiErrorSchema, P as startOfUtcHour, R as trailingUtcSixHourWindow, _ as userCustomizationSchema, f as INLINE_VIDEO_TYPES, j as fillUtcDays, k as DAY_MS$2, m as detectImageMediaType, p as INPUT_IMAGE_TYPES, x as isOpenPlanItemStatus, z as utcHourKey } from "./web-message-id-BT8Mg8LL.js";
|
|
18
|
+
import { a as startConnection, n as isConnectableProvider, r as listConnections, s as htmlCallbackResponse, t as disconnectConnection } from "./connections-C-SqzubG.js";
|
|
19
|
+
import { p as credentialContextForActor } from "./registry-yht0oxq6.js";
|
|
20
|
+
import { c as readViewerAvatarUrl, d as updateViewerDisplayName, l as resolveViewerUser, m as readAvatarFetch, t as findUserByEmail } from "./viewer-De1vmuEA.js";
|
|
21
|
+
import { n as finishServiceAccountSignIn, o as serviceAccountPlugins, r as getServiceAccountStatus, s as startServiceAccountSignIn, t as disconnectServiceAccount } from "./service-account-CZneZHh7.js";
|
|
22
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-Se9idiDR.js";
|
|
23
|
+
import { B as compileScheduleIntent, C as automationUpdateSchema, E as automationVersionParamsSchema, Q as automationTaskText, S as automationSummarySchema, T as automationVersionListSchema, _ as automationRunListSchema, a as automationEditSchema, b as automationScheduleIntentSchema, d as automationLifecycleSchema, g as automationParamsSchema, i as automationEditErrorSchema, m as automationListQuerySchema, o as automationEventCatalogSchema, p as automationListPageSchema, r as notificationScheduleSchema, s as automationExecutionListSchema, w as automationVersionActivateSchema, x as automationSchedulePreviewSchema, z as ScheduleIntentError } from "./schedule-BG1tEbRF.js";
|
|
24
|
+
import { o as getSandboxResources } from "./install-lYZs8UCL.js";
|
|
25
|
+
import { t as getCachedSnapshot } from "./resolve-gZ-hVMYl.js";
|
|
26
|
+
import { m as getVercelConversationWorkQueue } from "./background-compaction-queue-HlljT9ql.js";
|
|
28
27
|
import { Hono } from "hono";
|
|
29
28
|
import * as z from "zod";
|
|
30
29
|
import path from "node:path";
|
|
@@ -594,33 +593,41 @@ async function writeAttachmentUploadForViewer(args) {
|
|
|
594
593
|
// src/api/conversations/outline.ts
|
|
595
594
|
const payload = juniorConversationEvents.payload;
|
|
596
595
|
/**
|
|
597
|
-
* List the person messages of a whole Conversation
|
|
598
|
-
*
|
|
599
|
-
* outline cannot build its items from the
|
|
596
|
+
* List the person messages of a whole Conversation, each with its author and
|
|
597
|
+
* the start of Junior's reply, for the dashboard outline. The dashboard transcript loads
|
|
598
|
+
* only the latest pages, so the outline cannot build its items from the
|
|
599
|
+
* loaded rows alone.
|
|
600
600
|
*
|
|
601
601
|
* It uses the same rules as the transcript: Event messages are not person
|
|
602
602
|
* messages, and a message that does not mention Junior is thread context.
|
|
603
|
-
* The
|
|
604
|
-
* messages, so the cost grows with the person messages, not all events.
|
|
603
|
+
* The cost grows with the messages, not all events.
|
|
605
604
|
*/
|
|
606
605
|
async function readConversationOutline(conversationId, options = {}) {
|
|
607
606
|
const access = (await readConversationAccessFromSql(getDb(), [conversationId], options.viewer)).get(conversationId);
|
|
608
607
|
if (!access) return void 0;
|
|
609
608
|
if (!access.canViewPrivateContent) return { items: [] };
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
text: sql`left(${payload}->>'text', ${200})`
|
|
613
|
-
}).from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, conversationId), sql`${juniorConversationEvents.type} = 'message'`, sql`${payload}->>'role' = 'user'`, sql`${payload}->'meta'->>'eventType' is null`, sql`coalesce(${payload}->'meta'->>'explicitMention', 'true') <> 'false'`)).orderBy(asc(juniorConversationEvents.seq))).flatMap((row) => {
|
|
609
|
+
const [rows, replies] = await Promise.all([readMessages(conversationId, "user", sql`${payload}->'meta'->>'eventType' is null`, sql`coalesce(${payload}->'meta'->>'explicitMention', 'true') <> 'false'`), readMessages(conversationId, "assistant")]);
|
|
610
|
+
const items = rows.flatMap((row) => {
|
|
614
611
|
const text = withoutCutToken(row.text).trim();
|
|
615
|
-
|
|
612
|
+
if (!text) return [];
|
|
613
|
+
return [{
|
|
614
|
+
createdAt: row.createdAt.toISOString(),
|
|
616
615
|
seq: row.seq,
|
|
617
|
-
text
|
|
618
|
-
|
|
616
|
+
text,
|
|
617
|
+
...row.authorIdentityId && row.authorIdentityId !== "system" ? { actorIdentityId: row.authorIdentityId } : void 0,
|
|
618
|
+
...row.agentInvocationId ? { agentInvocationId: row.agentInvocationId } : void 0
|
|
619
|
+
}];
|
|
619
620
|
});
|
|
621
|
+
let itemIndex = -1;
|
|
622
|
+
for (const reply of replies) {
|
|
623
|
+
while (items[itemIndex + 1] && items[itemIndex + 1].seq < reply.seq) itemIndex += 1;
|
|
624
|
+
const text = withoutCutToken(reply.text).trim();
|
|
625
|
+
if (itemIndex >= 0 && text) items[itemIndex].reply = text;
|
|
626
|
+
}
|
|
620
627
|
const tenantId = (await loadConversationSlackTenantIds(getSqlExecutor(), [conversationId])).get(conversationId);
|
|
621
628
|
const mentions = await resolveMentions(getSqlExecutor(), items.map((item) => ({
|
|
622
629
|
tenantId,
|
|
623
|
-
texts: [item.text]
|
|
630
|
+
texts: [item.text, item.reply]
|
|
624
631
|
})));
|
|
625
632
|
return { items: items.map((item, index) => mentions[index].length > 0 ? {
|
|
626
633
|
...item,
|
|
@@ -628,6 +635,19 @@ async function readConversationOutline(conversationId, options = {}) {
|
|
|
628
635
|
} : item) };
|
|
629
636
|
}
|
|
630
637
|
/**
|
|
638
|
+
* Read the cut text of one role's messages in seq order. The
|
|
639
|
+
* `message_role_idx` index reads only these messages, not all events.
|
|
640
|
+
*/
|
|
641
|
+
function readMessages(conversationId, role, ...filters) {
|
|
642
|
+
return getDb().select({
|
|
643
|
+
agentInvocationId: sql`${payload}->'meta'->>'agentInvocationId'`,
|
|
644
|
+
authorIdentityId: sql`coalesce(${payload}->>'authorIdentityId', ${juniorConversationEvents.actorIdentityId})`,
|
|
645
|
+
createdAt: juniorConversationEvents.createdAt,
|
|
646
|
+
seq: juniorConversationEvents.seq,
|
|
647
|
+
text: sql`coalesce(left(${payload}->>'text', ${200}), '')`
|
|
648
|
+
}).from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, conversationId), sql`${juniorConversationEvents.type} = 'message'`, sql`${payload}->>'role' = ${role}`, ...filters)).orderBy(asc(juniorConversationEvents.seq));
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
631
651
|
* Repair a Slack token that the length cut split. A cut mention, such as
|
|
632
652
|
* `<@U12`, cannot resolve, so it is dropped. A cut link keeps its URL text,
|
|
633
653
|
* so a message that is only a long link still has a title.
|
|
@@ -765,7 +785,7 @@ function emptyStatsItem(label) {
|
|
|
765
785
|
label
|
|
766
786
|
};
|
|
767
787
|
}
|
|
768
|
-
function addUsd
|
|
788
|
+
function addUsd(current, next) {
|
|
769
789
|
return Math.round(((current ?? 0) + next) * 0xe8d4a51000) / 0xe8d4a51000;
|
|
770
790
|
}
|
|
771
791
|
function actorLabel$1(row) {
|
|
@@ -792,7 +812,7 @@ function addAggregate$1(map, label, row) {
|
|
|
792
812
|
item.durationMs += row.durationMs;
|
|
793
813
|
item.failed += row.failed;
|
|
794
814
|
if (row.tokens !== null) item.tokens = (item.tokens ?? 0) + row.tokens;
|
|
795
|
-
if (row.costUsd !== null) item.costUsd = addUsd
|
|
815
|
+
if (row.costUsd !== null) item.costUsd = addUsd(item.costUsd, row.costUsd);
|
|
796
816
|
map.set(label, item);
|
|
797
817
|
}
|
|
798
818
|
function statsItems$1(map) {
|
|
@@ -847,7 +867,7 @@ function applyMetricBuckets(rows, metrics, outcomes) {
|
|
|
847
867
|
const row = byDate.get(metric.date) ?? emptyMetricRow(metric.date);
|
|
848
868
|
if (metric.metric === "cached_input_tokens") row.cachedInputTokens = metric.value;
|
|
849
869
|
else if (metric.metric === "cache_creation_tokens") row.cacheCreationTokens = metric.value;
|
|
850
|
-
else if (metric.metric === "
|
|
870
|
+
else if (metric.metric === "cost_micro_usd") row.costUsd = microUsdToUsd(metric.value);
|
|
851
871
|
else if (metric.metric === "duration_ms") row.durationMs = metric.value;
|
|
852
872
|
else if (metric.metric === "input_tokens") row.inputTokens = metric.value;
|
|
853
873
|
else if (metric.metric === "total_tokens") row.tokens = metric.value;
|
|
@@ -862,12 +882,12 @@ function metricPoint(date, row) {
|
|
|
862
882
|
durationMs: row?.durationMs ?? 0,
|
|
863
883
|
...row?.cachedInputTokens !== null && row?.cachedInputTokens !== void 0 ? { cachedInputTokens: row.cachedInputTokens } : void 0,
|
|
864
884
|
...row?.cacheCreationTokens !== null && row?.cacheCreationTokens !== void 0 ? { cacheCreationTokens: row.cacheCreationTokens } : void 0,
|
|
865
|
-
...row?.costUsd !== null && row?.costUsd !== void 0 ? { costUsd:
|
|
885
|
+
...row?.costUsd !== null && row?.costUsd !== void 0 ? { costUsd: row.costUsd } : void 0,
|
|
866
886
|
...row?.inputTokens !== null && row?.inputTokens !== void 0 ? { inputTokens: row.inputTokens } : void 0,
|
|
867
887
|
...row?.outcomes !== null && row?.outcomes !== void 0 ? {
|
|
868
|
-
mergedCodeChangeCostUsd: addUsd
|
|
888
|
+
mergedCodeChangeCostUsd: addUsd(void 0, row.mergedCodeChangeCostUsd ?? 0),
|
|
869
889
|
mergedCodeChanges: row.mergedCodeChanges ?? 0,
|
|
870
|
-
outcomeCostUsd: addUsd
|
|
890
|
+
outcomeCostUsd: addUsd(void 0, row.outcomeCostUsd ?? 0),
|
|
871
891
|
outcomes: row.outcomes
|
|
872
892
|
} : void 0,
|
|
873
893
|
...row?.tokens !== null && row?.tokens !== void 0 ? { tokens: row.tokens } : void 0
|
|
@@ -956,7 +976,7 @@ function guardianStats(dayRows, hourRows, endMs) {
|
|
|
956
976
|
ask += row?.ask ?? 0;
|
|
957
977
|
deny += row?.deny ?? 0;
|
|
958
978
|
requests += row?.requests ?? 0;
|
|
959
|
-
if (row?.costUsd !== null && row?.costUsd !== void 0) costUsd = addUsd
|
|
979
|
+
if (row?.costUsd !== null && row?.costUsd !== void 0) costUsd = addUsd(costUsd, row.costUsd);
|
|
960
980
|
metricDays.push(guardianPoint(date, row));
|
|
961
981
|
}
|
|
962
982
|
const byHour = new Map(hourRows.map((row) => [row.date, row]));
|
|
@@ -1112,7 +1132,7 @@ async function readConversationStatsFromSql() {
|
|
|
1112
1132
|
locations: statsItems$1(locations),
|
|
1113
1133
|
actors: statsItems$1(actors),
|
|
1114
1134
|
source: "conversation_index",
|
|
1115
|
-
...totals?.costUsd !== null && totals?.costUsd !== void 0 ? { costUsd: addUsd
|
|
1135
|
+
...totals?.costUsd !== null && totals?.costUsd !== void 0 ? { costUsd: addUsd(void 0, totals.costUsd) } : void 0,
|
|
1116
1136
|
...totals?.inputTokens !== null && totals?.inputTokens !== void 0 ? { inputTokens: totals.inputTokens } : void 0,
|
|
1117
1137
|
...totals?.tokens !== null && totals?.tokens !== void 0 ? { tokens: totals.tokens } : void 0,
|
|
1118
1138
|
windowEnd: end.toISOString(),
|
|
@@ -2487,93 +2507,96 @@ async function readPeopleCode(email, cursor) {
|
|
|
2487
2507
|
userId: subject.id
|
|
2488
2508
|
});
|
|
2489
2509
|
}
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2510
|
+
const metrics$1 = juniorConversationMetrics;
|
|
2511
|
+
/** Sum the values of one metric among grouped metric rows. */
|
|
2512
|
+
function metricSum(metric) {
|
|
2513
|
+
return sql`sum(${metrics$1.value}) FILTER (WHERE ${metrics$1.metric} = ${metric})`;
|
|
2494
2514
|
}
|
|
2495
2515
|
/** Sum the spend of Turn metric rows read straight from their table. */
|
|
2496
|
-
const turnMetricColumns = {
|
|
2516
|
+
const turnMetricColumns = { costMicroUsd: microUsdSql(metricSum("cost_micro_usd")) };
|
|
2497
2517
|
/** Root Conversation of a person's Turn, for status, location, and surface. */
|
|
2498
2518
|
const turnRoot = alias(juniorConversations, "person_turn_root");
|
|
2519
|
+
/** Root of a Conversation row: itself when it has no root. */
|
|
2520
|
+
const conversationRootId = sql`coalesce(
|
|
2521
|
+
${juniorConversations.rootConversationId},
|
|
2522
|
+
${juniorConversations.conversationId}
|
|
2523
|
+
)`;
|
|
2499
2524
|
/**
|
|
2500
|
-
* Read one row per
|
|
2501
|
-
*
|
|
2525
|
+
* Read one row per verified person and root Conversation where they ran a
|
|
2526
|
+
* Turn, over all time: the Turn range and the duration and token totals.
|
|
2502
2527
|
*
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2528
|
+
* The person and metric filters apply to the metric rows, and the rows are
|
|
2529
|
+
* grouped before any join. Every Run writes a `duration_ms` row, so these
|
|
2530
|
+
* two metrics mark every Turn.
|
|
2505
2531
|
*/
|
|
2506
|
-
function
|
|
2532
|
+
function personRoots(email) {
|
|
2533
|
+
const verifiedIdentities = getDb().select({ id: juniorIdentities.id }).from(juniorIdentities).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(verifiedActorWhere(email));
|
|
2534
|
+
const conversations = getDb().select({
|
|
2535
|
+
identityId: sql`${metrics$1.actorIdentityId}`.as("turn_identity_id"),
|
|
2536
|
+
conversationId: sql`${metrics$1.conversationId}`.as("turn_conversation_id"),
|
|
2537
|
+
firstAt: sql`min(${metrics$1.occurredAt})`.as("turn_first_at"),
|
|
2538
|
+
lastAt: sql`max(${metrics$1.occurredAt})`.as("turn_last_at"),
|
|
2539
|
+
durationMs: metricSum("duration_ms").as("turn_duration_ms"),
|
|
2540
|
+
tokens: metricSum("total_tokens").as("turn_tokens")
|
|
2541
|
+
}).from(metrics$1).where(and(inArray(metrics$1.actorIdentityId, verifiedIdentities), inArray(metrics$1.metric, ["duration_ms", "total_tokens"]))).groupBy(metrics$1.actorIdentityId, metrics$1.conversationId).as("person_conversation_turns");
|
|
2507
2542
|
return getDb().select({
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
)
|
|
2522
|
-
)`.as("last_root_turn_at"),
|
|
2523
|
-
slackUserId: sql`CASE WHEN ${juniorIdentities.provider} = 'slack' THEN ${juniorIdentities.providerSubjectId} END`.as("slack_user_id"),
|
|
2524
|
-
slackUserName: sql`CASE WHEN ${juniorIdentities.provider} = 'slack' THEN ${juniorIdentities.handle} END`.as("slack_user_name"),
|
|
2525
|
-
userId: sql`${juniorUsers.id}`.as("user_id"),
|
|
2526
|
-
value: juniorConversationMetrics.value
|
|
2527
|
-
}).from(juniorConversationMetrics).innerJoin(juniorConversations, eq(juniorConversations.conversationId, juniorConversationMetrics.conversationId)).innerJoin(juniorIdentities, eq(juniorIdentities.id, juniorConversationMetrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(verifiedActorWhere(email)).as("person_turns");
|
|
2528
|
-
}
|
|
2529
|
-
/** Join a person's Turn rows to the root Conversation of each Turn. */
|
|
2530
|
-
function turnRootJoin(turns) {
|
|
2531
|
-
return eq(turnRoot.conversationId, turns.rootConversationId);
|
|
2532
|
-
}
|
|
2533
|
-
function turnSum(turns, metric) {
|
|
2534
|
-
return sql`SUM(${turns.value}) FILTER (WHERE ${turns.metric} = ${metric})`;
|
|
2543
|
+
userId: sql`${juniorIdentities.userId}`.as("root_user_id"),
|
|
2544
|
+
rootConversationId: conversationRootId.as("person_root_id"),
|
|
2545
|
+
firstAt: sql`min(${conversations.firstAt})`.as("root_first_at"),
|
|
2546
|
+
lastAt: sql`max(${conversations.lastAt})`.as("root_last_at"),
|
|
2547
|
+
durationMs: sql`sum(${conversations.durationMs})`.as("root_duration_ms"),
|
|
2548
|
+
tokens: sql`sum(${conversations.tokens})`.as("root_tokens"),
|
|
2549
|
+
slackUserId: sql`max(CASE WHEN ${juniorIdentities.provider} = 'slack' THEN ${juniorIdentities.providerSubjectId} END)`.as("root_slack_user_id"),
|
|
2550
|
+
slackUserName: sql`max(CASE WHEN ${juniorIdentities.provider} = 'slack' THEN ${juniorIdentities.handle} END)`.as("root_slack_user_name")
|
|
2551
|
+
}).from(conversations).innerJoin(juniorIdentities, eq(juniorIdentities.id, conversations.identityId)).innerJoin(juniorConversations, eq(juniorConversations.conversationId, conversations.conversationId)).groupBy(juniorIdentities.userId, conversationRootId).as("person_roots");
|
|
2552
|
+
}
|
|
2553
|
+
/** Join a person's roots to the root Conversation rows. */
|
|
2554
|
+
function personRootJoin(roots) {
|
|
2555
|
+
return eq(turnRoot.conversationId, roots.rootConversationId);
|
|
2535
2556
|
}
|
|
2536
2557
|
/**
|
|
2537
|
-
* Aggregate
|
|
2538
|
-
* who ran a Turn in it
|
|
2539
|
-
*
|
|
2540
|
-
* Active and failed read the root's current
|
|
2541
|
-
*
|
|
2542
|
-
* mark every past day.
|
|
2558
|
+
* Aggregate rows from {@link personRoots} joined to {@link turnRoot}. A
|
|
2559
|
+
* Conversation counts once for each person who ran a Turn in it, and child
|
|
2560
|
+
* Conversation Turns count for the root. Each row is one root of one person,
|
|
2561
|
+
* so plain counts need no DISTINCT. Active and failed read the root's current
|
|
2562
|
+
* status.
|
|
2543
2563
|
*/
|
|
2544
|
-
function
|
|
2545
|
-
const roots = sql`COUNT(DISTINCT ${turns.rootConversationId})`;
|
|
2546
|
-
const lastTurn = sql`${turns.occurredAt} = ${turns.lastRootTurnAt}`;
|
|
2564
|
+
function rootAggregateColumns(roots) {
|
|
2547
2565
|
return {
|
|
2548
|
-
active: sql
|
|
2549
|
-
WHERE ${
|
|
2550
|
-
)::integer`,
|
|
2551
|
-
conversations: sql
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
AND ${turnRoot.stoppedAt} IS NULL
|
|
2558
|
-
)::integer`,
|
|
2559
|
-
tokens: sql`${turnSum(turns, "total_tokens")}::double precision`
|
|
2566
|
+
active: sql`(count(*) FILTER (
|
|
2567
|
+
WHERE ${turnRoot.executionStatus} NOT IN ('idle', 'failed')
|
|
2568
|
+
))::integer`,
|
|
2569
|
+
conversations: sql`count(*)::integer`,
|
|
2570
|
+
durationMs: sql`COALESCE(sum(${roots.durationMs}), 0)::double precision`,
|
|
2571
|
+
failed: sql`(count(*) FILTER (
|
|
2572
|
+
WHERE ${turnRoot.executionStatus} = 'failed' AND ${turnRoot.stoppedAt} IS NULL
|
|
2573
|
+
))::integer`,
|
|
2574
|
+
tokens: sql`sum(${roots.tokens})::double precision`
|
|
2560
2575
|
};
|
|
2561
2576
|
}
|
|
2562
|
-
/**
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2577
|
+
/**
|
|
2578
|
+
* Count the UTC days on which the grouped person ran a Turn. A correlated
|
|
2579
|
+
* subquery runs once per person through the actor index, so a bad row
|
|
2580
|
+
* estimate cannot make Postgres repeat it once per root.
|
|
2581
|
+
*/
|
|
2582
|
+
function personActiveDays() {
|
|
2583
|
+
const days = getDb().selectDistinct({ day: sql`(${metrics$1.occurredAt} AT TIME ZONE 'UTC')::date`.as("turn_day") }).from(metrics$1).innerJoin(juniorIdentities, eq(juniorIdentities.id, metrics$1.actorIdentityId)).where(and(eq(juniorIdentities.userId, juniorUsers.id), eq(juniorIdentities.kind, "user"), eq(juniorIdentities.emailVerified, true))).as("person_turn_days");
|
|
2584
|
+
return sql`(${getDb().select({ days: sql`count(*)` }).from(days)})::integer`;
|
|
2566
2585
|
}
|
|
2567
|
-
/**
|
|
2568
|
-
|
|
2586
|
+
/**
|
|
2587
|
+
* Select the identity, Turn range, and totals of one person from roots
|
|
2588
|
+
* grouped by person and joined to {@link juniorUsers}.
|
|
2589
|
+
*/
|
|
2590
|
+
function personTotalColumns(roots) {
|
|
2569
2591
|
return {
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2592
|
+
...rootAggregateColumns(roots),
|
|
2593
|
+
activeDays: personActiveDays(),
|
|
2594
|
+
email: sql`${juniorUsers.primaryEmailNormalized}`,
|
|
2595
|
+
firstSeenAt: sql`min(${roots.firstAt})`.mapWith(metrics$1.occurredAt),
|
|
2596
|
+
fullName: juniorUsers.displayName,
|
|
2597
|
+
lastSeenAt: sql`max(${roots.lastAt})`.mapWith(metrics$1.occurredAt),
|
|
2598
|
+
slackUserId: sql`max(${roots.slackUserId})`,
|
|
2599
|
+
slackUserName: sql`max(${roots.slackUserName})`
|
|
2577
2600
|
};
|
|
2578
2601
|
}
|
|
2579
2602
|
/** Normalize emails before matching people API rows. */
|
|
@@ -2650,11 +2673,10 @@ function verifiedActorWhere(email) {
|
|
|
2650
2673
|
}
|
|
2651
2674
|
/** Read the Conversations where a person ran a Turn, by their last Turn. */
|
|
2652
2675
|
async function recentActorRows(email) {
|
|
2653
|
-
const turns = personTurns(email);
|
|
2654
2676
|
const lastTurns = getDb().select({
|
|
2655
|
-
conversationId:
|
|
2656
|
-
lastTurnAt: sql`max(${
|
|
2657
|
-
}).from(
|
|
2677
|
+
conversationId: sql`${metrics$1.conversationId}`.as("turn_conversation_id"),
|
|
2678
|
+
lastTurnAt: sql`max(${metrics$1.occurredAt})`.as("last_turn_at")
|
|
2679
|
+
}).from(metrics$1).innerJoin(juniorIdentities, eq(juniorIdentities.id, metrics$1.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(and(verifiedActorWhere(email), eq(metrics$1.metric, "duration_ms"))).groupBy(metrics$1.conversationId).as("person_last_turns");
|
|
2658
2680
|
return getDb().select({
|
|
2659
2681
|
channelName: juniorConversations.channelName,
|
|
2660
2682
|
conversationId: juniorConversations.conversationId,
|
|
@@ -2682,8 +2704,7 @@ async function recentActorRows(email) {
|
|
|
2682
2704
|
const DIRECTORY_ACTIVITY_DAYS = 90;
|
|
2683
2705
|
/** Day ranges need the prior equal period too (90d + prior 90d). */
|
|
2684
2706
|
const DAY_METRIC_LOOKBACK = 180;
|
|
2685
|
-
|
|
2686
|
-
const HOUR_METRIC_LOOKBACK = 48;
|
|
2707
|
+
const metrics = juniorConversationMetrics;
|
|
2687
2708
|
function emptyDirectoryDay(date) {
|
|
2688
2709
|
return {
|
|
2689
2710
|
activePeople: 0,
|
|
@@ -2691,15 +2712,6 @@ function emptyDirectoryDay(date) {
|
|
|
2691
2712
|
date
|
|
2692
2713
|
};
|
|
2693
2714
|
}
|
|
2694
|
-
function emptyBucket() {
|
|
2695
|
-
return {
|
|
2696
|
-
costUsd: 0,
|
|
2697
|
-
durationMs: 0
|
|
2698
|
-
};
|
|
2699
|
-
}
|
|
2700
|
-
function addUsd$1(current, next) {
|
|
2701
|
-
return Math.round((current + next) * 0xe8d4a51000) / 0xe8d4a51000;
|
|
2702
|
-
}
|
|
2703
2715
|
function directoryActivityDays(rows, nowMs) {
|
|
2704
2716
|
return fillUtcDays({
|
|
2705
2717
|
count: DIRECTORY_ACTIVITY_DAYS,
|
|
@@ -2723,66 +2735,53 @@ function directoryActivitySixHours(rows, nowMs) {
|
|
|
2723
2735
|
rows: new Map(rows.map((row) => [row.date, row]))
|
|
2724
2736
|
});
|
|
2725
2737
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
const currentTotals = sumBuckets(buckets, current.start.getTime(), current.end.getTime(), utcHourKey, HOUR_MS$1);
|
|
2742
|
-
const priorTotals = sumBuckets(buckets, priorStartMs, priorEndMs, utcHourKey, HOUR_MS$1);
|
|
2743
|
-
return {
|
|
2744
|
-
conversations,
|
|
2745
|
-
costUsd: currentTotals.costUsd,
|
|
2746
|
-
durationMs: currentTotals.durationMs,
|
|
2747
|
-
priorCostUsd: priorTotals.costUsd
|
|
2748
|
-
};
|
|
2749
|
-
}
|
|
2750
|
-
const current = trailingUtcDayWindow(nowMs, range);
|
|
2751
|
-
const priorEndMs = current.start.getTime() - DAY_MS$2;
|
|
2752
|
-
const priorStartMs = priorEndMs - (range - 1) * DAY_MS$2;
|
|
2753
|
-
const currentTotals = sumBuckets(buckets, current.start.getTime(), current.end.getTime(), utcDayKey, DAY_MS$2);
|
|
2754
|
-
const priorTotals = sumBuckets(buckets, priorStartMs, priorEndMs, utcDayKey, DAY_MS$2);
|
|
2738
|
+
/** Start of the current period of each directory range. */
|
|
2739
|
+
function rangeStart(nowMs, range) {
|
|
2740
|
+
return range === 1 ? trailingUtcHourWindow(nowMs, 24).start : trailingUtcDayWindow(nowMs, range).start;
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* Sum one range of a person's spend: the current period, and the prior
|
|
2744
|
+
* period of equal length that ends where the current one starts.
|
|
2745
|
+
*/
|
|
2746
|
+
function rangeSpendColumns(nowMs, range) {
|
|
2747
|
+
const start = rangeStart(nowMs, range);
|
|
2748
|
+
const priorStart = new Date(start.getTime() - (range === 1 ? 24 * HOUR_MS$1 : range * DAY_MS$2));
|
|
2749
|
+
const current = sql`${metrics.occurredAt} >= ${start.toISOString()}::timestamptz`;
|
|
2750
|
+
const prior = sql`${metrics.occurredAt} >= ${priorStart.toISOString()}::timestamptz
|
|
2751
|
+
AND ${metrics.occurredAt} < ${start.toISOString()}::timestamptz`;
|
|
2752
|
+
const sum = (metric, when) => sql`sum(${metrics.value}) FILTER (WHERE ${metrics.metric} = ${metric} AND ${when})`;
|
|
2755
2753
|
return {
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
priorCostUsd: priorTotals.costUsd
|
|
2754
|
+
costMicroUsd: microUsdSql(sum("cost_micro_usd", current)),
|
|
2755
|
+
durationMs: sql`COALESCE(${sum("duration_ms", current)}, 0)::double precision`,
|
|
2756
|
+
priorCostMicroUsd: microUsdSql(sum("cost_micro_usd", prior))
|
|
2760
2757
|
};
|
|
2761
2758
|
}
|
|
2762
|
-
function
|
|
2763
|
-
const { conversations, dayBuckets, hourBuckets, nowMs } = args;
|
|
2759
|
+
function rangeWindow(spend, conversations) {
|
|
2764
2760
|
return {
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2761
|
+
conversations,
|
|
2762
|
+
costUsd: microUsdToUsd(spend?.costMicroUsd ?? 0),
|
|
2763
|
+
durationMs: spend?.durationMs ?? 0,
|
|
2764
|
+
priorCostUsd: microUsdToUsd(spend?.priorCostMicroUsd ?? 0)
|
|
2769
2765
|
};
|
|
2770
2766
|
}
|
|
2771
|
-
/**
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
function
|
|
2776
|
-
const
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2767
|
+
/**
|
|
2768
|
+
* Count active people and root Conversations in each bucket from one row per
|
|
2769
|
+
* Turn. The time bound applies to the metric rows before any join.
|
|
2770
|
+
*/
|
|
2771
|
+
function activityRows(since, unit) {
|
|
2772
|
+
const utc = sql`(${metrics.occurredAt} AT TIME ZONE 'UTC')`;
|
|
2773
|
+
const bucket = unit === "six_hour" ? sql`date_trunc('day', ${utc}) + FLOOR(EXTRACT(HOUR FROM ${utc}) / 6) * INTERVAL '6 hours'` : sql`date_trunc(${sql.raw(`'${unit}'`)}, ${utc})`;
|
|
2774
|
+
const format = unit === "day" ? "YYYY-MM-DD" : "YYYY-MM-DD\"T\"HH24";
|
|
2775
|
+
const turns = getDb().select({
|
|
2776
|
+
bucket: bucket.as("activity_bucket"),
|
|
2777
|
+
userId: sql`${juniorUsers.id}`.as("activity_user_id"),
|
|
2778
|
+
rootConversationId: conversationRootId.as("activity_root_id")
|
|
2779
|
+
}).from(metrics).innerJoin(juniorIdentities, eq(juniorIdentities.id, metrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).innerJoin(juniorConversations, eq(juniorConversations.conversationId, metrics.conversationId)).where(and(verifiedActorWhere(), eq(metrics.metric, "duration_ms"), gte(metrics.occurredAt, since))).groupBy(bucket, juniorUsers.id, conversationRootId).as("activity_turns");
|
|
2780
|
+
return getDb().select({
|
|
2781
|
+
activePeople: sql`COUNT(DISTINCT ${turns.userId})::int`,
|
|
2782
|
+
conversations: sql`COUNT(DISTINCT ${turns.rootConversationId})::int`,
|
|
2783
|
+
date: sql`TO_CHAR(${turns.bucket}, ${sql.raw(`'${format}'`)})`
|
|
2784
|
+
}).from(turns).groupBy(turns.bucket);
|
|
2786
2785
|
}
|
|
2787
2786
|
/**
|
|
2788
2787
|
* Load the complete People directory with grouping and metrics owned by SQL.
|
|
@@ -2795,52 +2794,30 @@ async function readPeopleListFromSql() {
|
|
|
2795
2794
|
const { end, start } = trailingUtcDayWindow(nowMs, DIRECTORY_ACTIVITY_DAYS);
|
|
2796
2795
|
const hourWindow = trailingUtcHourWindow(nowMs, 168);
|
|
2797
2796
|
const sixHourWindow = trailingUtcSixHourWindow(nowMs);
|
|
2798
|
-
const
|
|
2799
|
-
const
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
const
|
|
2803
|
-
const hour = turnBucket(turns, "hour");
|
|
2804
|
-
const sixHour = sql`TO_CHAR(
|
|
2805
|
-
date_trunc('day', ${turns.occurredAt} AT TIME ZONE 'UTC')
|
|
2806
|
-
+ (FLOOR(EXTRACT(HOUR FROM ${turns.occurredAt} AT TIME ZONE 'UTC') / 6) * INTERVAL '6 hours'),
|
|
2807
|
-
'YYYY-MM-DD"T"HH24'
|
|
2808
|
-
)`;
|
|
2809
|
-
const rangeConversations = (range) => sql`COUNT(DISTINCT ${turns.rootConversationId}) FILTER (
|
|
2810
|
-
WHERE ${turns.occurredAt} >= ${rangeStart(nowMs, range).toISOString()}::timestamptz
|
|
2811
|
-
)::integer`;
|
|
2812
|
-
const spendRows = (since, bucket) => getDb().select({
|
|
2813
|
-
email: turns.email,
|
|
2814
|
-
date: bucket,
|
|
2815
|
-
costUsd,
|
|
2816
|
-
durationMs
|
|
2817
|
-
}).from(turns).where(gte(turns.occurredAt, since)).groupBy(turns.email, bucket);
|
|
2818
|
-
const activityRows = (since, bucket) => getDb().select({
|
|
2819
|
-
activePeople: sql`COUNT(DISTINCT ${turns.userId})::int`,
|
|
2820
|
-
conversations,
|
|
2821
|
-
date: bucket
|
|
2822
|
-
}).from(turns).where(gte(turns.occurredAt, since)).groupBy(bucket);
|
|
2823
|
-
const [rows, activityDayRows, activityHourRows, activitySixHourRows, daySpendRows, hourSpendRows] = await Promise.all([
|
|
2797
|
+
const roots = personRoots();
|
|
2798
|
+
const rangeConversations = (range) => sql`(count(*) FILTER (
|
|
2799
|
+
WHERE ${roots.lastAt} >= ${rangeStart(nowMs, range).toISOString()}::timestamptz
|
|
2800
|
+
))::integer`;
|
|
2801
|
+
const [rows, activityDayRows, activityHourRows, activitySixHourRows, spend] = await Promise.all([
|
|
2824
2802
|
getDb().select({
|
|
2825
|
-
...
|
|
2826
|
-
active,
|
|
2827
|
-
conversations,
|
|
2828
|
-
durationMs,
|
|
2829
|
-
failed,
|
|
2830
|
-
tokens,
|
|
2803
|
+
...personTotalColumns(roots),
|
|
2831
2804
|
conversations1: rangeConversations(1),
|
|
2832
2805
|
conversations7: rangeConversations(7),
|
|
2833
2806
|
conversations30: rangeConversations(30),
|
|
2834
2807
|
conversations90: rangeConversations(90)
|
|
2835
|
-
}).from(
|
|
2836
|
-
activityRows(start, day),
|
|
2837
|
-
activityRows(hourWindow.start, hour),
|
|
2838
|
-
activityRows(sixHourWindow.start,
|
|
2839
|
-
|
|
2840
|
-
|
|
2808
|
+
}).from(roots).innerJoin(juniorUsers, eq(juniorUsers.id, roots.userId)).innerJoin(turnRoot, personRootJoin(roots)).groupBy(juniorUsers.id),
|
|
2809
|
+
activityRows(start, "day"),
|
|
2810
|
+
activityRows(hourWindow.start, "hour"),
|
|
2811
|
+
activityRows(sixHourWindow.start, "six_hour"),
|
|
2812
|
+
getDb().select({
|
|
2813
|
+
email: sql`${juniorUsers.primaryEmailNormalized}`,
|
|
2814
|
+
1: rangeSpendColumns(nowMs, 1),
|
|
2815
|
+
7: rangeSpendColumns(nowMs, 7),
|
|
2816
|
+
30: rangeSpendColumns(nowMs, 30),
|
|
2817
|
+
90: rangeSpendColumns(nowMs, 90)
|
|
2818
|
+
}).from(metrics).innerJoin(juniorIdentities, eq(juniorIdentities.id, metrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(and(verifiedActorWhere(), inArray(metrics.metric, ["cost_micro_usd", "duration_ms"]), gte(metrics.occurredAt, trailingUtcDayWindow(nowMs, DAY_METRIC_LOOKBACK).start))).groupBy(juniorUsers.id)
|
|
2841
2819
|
]);
|
|
2842
|
-
const
|
|
2843
|
-
const hourBucketsByEmail = metricBuckets(hourSpendRows);
|
|
2820
|
+
const spendByEmail = new Map(spend.map((row) => [row.email, row]));
|
|
2844
2821
|
const people = rows.map((row) => {
|
|
2845
2822
|
const actor = {
|
|
2846
2823
|
email: row.email,
|
|
@@ -2848,6 +2825,7 @@ async function readPeopleListFromSql() {
|
|
|
2848
2825
|
...row.slackUserId ? { slackUserId: row.slackUserId } : void 0,
|
|
2849
2826
|
...row.slackUserName ? { slackUserName: row.slackUserName } : void 0
|
|
2850
2827
|
};
|
|
2828
|
+
const personSpend = spendByEmail.get(row.email);
|
|
2851
2829
|
return {
|
|
2852
2830
|
active: row.active,
|
|
2853
2831
|
activeDays: row.activeDays,
|
|
@@ -2857,17 +2835,12 @@ async function readPeopleListFromSql() {
|
|
|
2857
2835
|
firstSeenAt: row.firstSeenAt.toISOString(),
|
|
2858
2836
|
lastSeenAt: row.lastSeenAt.toISOString(),
|
|
2859
2837
|
actor,
|
|
2860
|
-
windows:
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
},
|
|
2867
|
-
dayBuckets: dayBucketsByEmail.get(row.email) ?? /* @__PURE__ */ new Map(),
|
|
2868
|
-
hourBuckets: hourBucketsByEmail.get(row.email) ?? /* @__PURE__ */ new Map(),
|
|
2869
|
-
nowMs
|
|
2870
|
-
}),
|
|
2838
|
+
windows: {
|
|
2839
|
+
1: rangeWindow(personSpend?.[1], row.conversations1),
|
|
2840
|
+
7: rangeWindow(personSpend?.[7], row.conversations7),
|
|
2841
|
+
30: rangeWindow(personSpend?.[30], row.conversations30),
|
|
2842
|
+
90: rangeWindow(personSpend?.[90], row.conversations90)
|
|
2843
|
+
},
|
|
2871
2844
|
...row.tokens !== null ? { tokens: row.tokens } : void 0
|
|
2872
2845
|
};
|
|
2873
2846
|
});
|
|
@@ -2897,7 +2870,7 @@ async function readPeoplePluginReports(args) {
|
|
|
2897
2870
|
reports: [],
|
|
2898
2871
|
source: "plugins"
|
|
2899
2872
|
});
|
|
2900
|
-
const { getPluginProfileReports } = await import("./projection-
|
|
2873
|
+
const { getPluginProfileReports } = await import("./projection-D47mlszd.js").then((n) => n.Cn);
|
|
2901
2874
|
return pluginOperationalReportFeedSchema.parse({
|
|
2902
2875
|
generatedAt: new Date(nowMs).toISOString(),
|
|
2903
2876
|
reports: await getPluginProfileReports({
|
|
@@ -2968,13 +2941,62 @@ function locationLabel(row) {
|
|
|
2968
2941
|
}) ?? "Conversation";
|
|
2969
2942
|
}
|
|
2970
2943
|
function activityBuckets(rows) {
|
|
2971
|
-
return new Map(rows.map(({
|
|
2944
|
+
return new Map(rows.map(({ costMicroUsd, tokens, ...row }) => [row.date, {
|
|
2972
2945
|
...emptyActivityDay(row.date),
|
|
2973
2946
|
...row,
|
|
2974
|
-
...
|
|
2947
|
+
...costMicroUsd !== null ? { costUsd: microUsdToUsd(costMicroUsd) } : void 0,
|
|
2975
2948
|
...tokens !== null ? { tokens } : void 0
|
|
2976
2949
|
}]));
|
|
2977
2950
|
}
|
|
2951
|
+
/**
|
|
2952
|
+
* Sum one person's Turns into UTC day or hour buckets since `since`. A root
|
|
2953
|
+
* counts once in each bucket where the person ran a Turn in it. Its current
|
|
2954
|
+
* status counts only in the bucket of their last Turn in that root, so a
|
|
2955
|
+
* status change does not mark every past bucket.
|
|
2956
|
+
*/
|
|
2957
|
+
function rootBucketRows(args) {
|
|
2958
|
+
const metrics = juniorConversationMetrics;
|
|
2959
|
+
const unit = sql.raw(`'${args.unit}'`);
|
|
2960
|
+
const bucket = sql`date_trunc(${unit}, ${metrics.occurredAt} AT TIME ZONE 'UTC')`;
|
|
2961
|
+
const format = args.unit === "day" ? "YYYY-MM-DD" : "YYYY-MM-DD\"T\"HH24";
|
|
2962
|
+
const rootBuckets = getDb().select({
|
|
2963
|
+
bucket: bucket.as("bucket_start"),
|
|
2964
|
+
rootConversationId: conversationRootId.as("bucket_root_id"),
|
|
2965
|
+
lastAt: sql`max(${metrics.occurredAt})`.as("bucket_last_at"),
|
|
2966
|
+
costMicroUsd: metricSum("cost_micro_usd").as("bucket_cost_micro_usd"),
|
|
2967
|
+
durationMs: metricSum("duration_ms").as("bucket_duration_ms"),
|
|
2968
|
+
tokens: metricSum("total_tokens").as("bucket_tokens")
|
|
2969
|
+
}).from(metrics).innerJoin(juniorIdentities, eq(juniorIdentities.id, metrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).innerJoin(juniorConversations, eq(juniorConversations.conversationId, metrics.conversationId)).where(and(verifiedActorWhere(args.email), inArray(metrics.metric, [
|
|
2970
|
+
"cost_micro_usd",
|
|
2971
|
+
"duration_ms",
|
|
2972
|
+
"total_tokens"
|
|
2973
|
+
]))).groupBy(bucket, conversationRootId).as("person_root_buckets");
|
|
2974
|
+
const buckets = getDb().select({
|
|
2975
|
+
bucket: rootBuckets.bucket,
|
|
2976
|
+
rootConversationId: rootBuckets.rootConversationId,
|
|
2977
|
+
isLastTurn: sql`${rootBuckets.lastAt} = max(${rootBuckets.lastAt}) OVER (
|
|
2978
|
+
PARTITION BY ${rootBuckets.rootConversationId}
|
|
2979
|
+
)`.as("bucket_has_last_turn"),
|
|
2980
|
+
costMicroUsd: rootBuckets.costMicroUsd,
|
|
2981
|
+
durationMs: rootBuckets.durationMs,
|
|
2982
|
+
tokens: rootBuckets.tokens
|
|
2983
|
+
}).from(rootBuckets).as("person_buckets");
|
|
2984
|
+
return getDb().select({
|
|
2985
|
+
active: sql`(count(*) FILTER (
|
|
2986
|
+
WHERE ${buckets.isLastTurn} AND ${turnRoot.executionStatus} NOT IN ('idle', 'failed')
|
|
2987
|
+
))::integer`,
|
|
2988
|
+
conversations: sql`count(*)::integer`,
|
|
2989
|
+
costMicroUsd: microUsdSql(sql`sum(${buckets.costMicroUsd})`),
|
|
2990
|
+
date: sql`TO_CHAR(${buckets.bucket}, ${sql.raw(`'${format}'`)})`,
|
|
2991
|
+
durationMs: sql`COALESCE(sum(${buckets.durationMs}), 0)::double precision`,
|
|
2992
|
+
failed: sql`(count(*) FILTER (
|
|
2993
|
+
WHERE ${buckets.isLastTurn}
|
|
2994
|
+
AND ${turnRoot.executionStatus} = 'failed'
|
|
2995
|
+
AND ${turnRoot.stoppedAt} IS NULL
|
|
2996
|
+
))::integer`,
|
|
2997
|
+
tokens: sql`sum(${buckets.tokens})::double precision`
|
|
2998
|
+
}).from(buckets).innerJoin(turnRoot, eq(turnRoot.conversationId, buckets.rootConversationId)).where(sql`${buckets.bucket} >= (${args.since.toISOString()}::timestamptz AT TIME ZONE 'UTC')`).groupBy(buckets.bucket);
|
|
2999
|
+
}
|
|
2978
3000
|
/** Load one complete person profile while bounding only its recent-conversation list. */
|
|
2979
3001
|
async function readPeopleProfileFromSql(email, options = {}) {
|
|
2980
3002
|
const nowMs = Date.now();
|
|
@@ -2984,37 +3006,34 @@ async function readPeopleProfileFromSql(email, options = {}) {
|
|
|
2984
3006
|
end.setUTCHours(0, 0, 0, 0);
|
|
2985
3007
|
const start = new Date(end);
|
|
2986
3008
|
start.setUTCDate(start.getUTCDate() - 364);
|
|
2987
|
-
const
|
|
2988
|
-
const aggregate =
|
|
3009
|
+
const roots = personRoots(normalizedEmail);
|
|
3010
|
+
const aggregate = rootAggregateColumns(roots);
|
|
2989
3011
|
const surface = surfaceExpression(turnRoot);
|
|
2990
3012
|
const channel = channelExpression(turnRoot);
|
|
2991
|
-
const day = turnBucket(turns, "day");
|
|
2992
|
-
const hour = turnBucket(turns, "hour");
|
|
2993
3013
|
const hourWindow = trailingUtcHourWindow(nowMs, 168);
|
|
2994
3014
|
const [totalsRows, dayRows, hourRows, locationRows, surfaceRows, recentRows] = await Promise.all([
|
|
2995
|
-
getDb().select(
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
}).from(turns).innerJoin(turnRoot, turnRootJoin(turns)).where(gte(turns.occurredAt, hourWindow.start)).groupBy(hour),
|
|
3015
|
+
getDb().select(personTotalColumns(roots)).from(roots).innerJoin(juniorUsers, eq(juniorUsers.id, roots.userId)).innerJoin(turnRoot, personRootJoin(roots)).groupBy(juniorUsers.id),
|
|
3016
|
+
rootBucketRows({
|
|
3017
|
+
email: normalizedEmail,
|
|
3018
|
+
since: start,
|
|
3019
|
+
unit: "day"
|
|
3020
|
+
}),
|
|
3021
|
+
rootBucketRows({
|
|
3022
|
+
email: normalizedEmail,
|
|
3023
|
+
since: hourWindow.start,
|
|
3024
|
+
unit: "hour"
|
|
3025
|
+
}),
|
|
3007
3026
|
getDb().select({
|
|
3008
3027
|
channel,
|
|
3009
3028
|
channelName: turnRoot.channelName,
|
|
3010
3029
|
destinationVisibility: juniorDestinations.visibility,
|
|
3011
3030
|
surface,
|
|
3012
3031
|
...aggregate
|
|
3013
|
-
}).from(
|
|
3032
|
+
}).from(roots).innerJoin(turnRoot, personRootJoin(roots)).leftJoin(juniorDestinations, eq(juniorDestinations.id, turnRoot.destinationId)).groupBy(channel, turnRoot.channelName, juniorDestinations.visibility, surface),
|
|
3014
3033
|
getDb().select({
|
|
3015
3034
|
surface,
|
|
3016
3035
|
...aggregate
|
|
3017
|
-
}).from(
|
|
3036
|
+
}).from(roots).innerJoin(turnRoot, personRootJoin(roots)).groupBy(surface),
|
|
3018
3037
|
recentActorRows(normalizedEmail)
|
|
3019
3038
|
]);
|
|
3020
3039
|
const person = totalsRows[0];
|
|
@@ -3073,9 +3092,6 @@ async function readPeopleProfile(email, options = {}) {
|
|
|
3073
3092
|
// src/api/people/spend.query.ts
|
|
3074
3093
|
const SEVEN_DAY_OFFSET = 6;
|
|
3075
3094
|
const THIRTY_DAY_OFFSET = 29;
|
|
3076
|
-
function addUsd(current, next) {
|
|
3077
|
-
return Math.round((current + next) * 0xe8d4a51000) / 0xe8d4a51000;
|
|
3078
|
-
}
|
|
3079
3095
|
function spendWindow(nowMs) {
|
|
3080
3096
|
const end = new Date(nowMs);
|
|
3081
3097
|
const currentDay = new Date(end);
|
|
@@ -3094,7 +3110,7 @@ function spendWindow(nowMs) {
|
|
|
3094
3110
|
function viewerWindowWhere(email, nowMs) {
|
|
3095
3111
|
const normalizedEmail = normalizeEmail$1(email);
|
|
3096
3112
|
const { end, thirtyDayStart } = spendWindow(nowMs);
|
|
3097
|
-
return normalizedEmail ? and(verifiedActorWhere(normalizedEmail), eq(juniorConversationMetrics.metric, "
|
|
3113
|
+
return normalizedEmail ? and(verifiedActorWhere(normalizedEmail), eq(juniorConversationMetrics.metric, "cost_micro_usd"), gte(juniorConversationMetrics.occurredAt, thirtyDayStart), lte(juniorConversationMetrics.occurredAt, end)) : sql`false`;
|
|
3098
3114
|
}
|
|
3099
3115
|
/** Return a query for one viewer's model spend for each UTC day in the window. */
|
|
3100
3116
|
function personalSpendDaysQuery(email, nowMs) {
|
|
@@ -3103,7 +3119,7 @@ function personalSpendDaysQuery(email, nowMs) {
|
|
|
3103
3119
|
'YYYY-MM-DD'
|
|
3104
3120
|
)`;
|
|
3105
3121
|
return getDb().select({
|
|
3106
|
-
|
|
3122
|
+
costMicroUsd: turnMetricColumns.costMicroUsd,
|
|
3107
3123
|
date
|
|
3108
3124
|
}).from(juniorConversationMetrics).innerJoin(juniorIdentities, eq(juniorIdentities.id, juniorConversationMetrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(viewerWindowWhere(email, nowMs)).groupBy(date);
|
|
3109
3125
|
}
|
|
@@ -3119,10 +3135,10 @@ function personalSpendVersionQuery(db, email, nowMs) {
|
|
|
3119
3135
|
const { sevenDayStart, thirtyDayStart } = spendWindow(nowMs);
|
|
3120
3136
|
return db.select({ version: sql`concat_ws(':',
|
|
3121
3137
|
${thirtyDayStart.toISOString().slice(0, 10)}::text,
|
|
3122
|
-
|
|
3123
|
-
|
|
3138
|
+
sum(${juniorConversationMetrics.value})::bigint,
|
|
3139
|
+
(sum(${juniorConversationMetrics.value}) filter (
|
|
3124
3140
|
where ${juniorConversationMetrics.occurredAt} >= ${sevenDayStart}
|
|
3125
|
-
))::
|
|
3141
|
+
))::bigint
|
|
3126
3142
|
)` }).from(juniorConversationMetrics).innerJoin(juniorIdentities, eq(juniorIdentities.id, juniorConversationMetrics.actorIdentityId)).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(viewerWindowWhere(email, nowMs));
|
|
3127
3143
|
}
|
|
3128
3144
|
/** Read one viewer's rolling model spend with one bounded aggregate query. */
|
|
@@ -3130,18 +3146,18 @@ async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
|
3130
3146
|
const { end, sevenDayStart, thirtyDayStart } = spendWindow(nowMs);
|
|
3131
3147
|
const rows = await personalSpendDaysQuery(email, nowMs);
|
|
3132
3148
|
const sevenDayStartDate = sevenDayStart.toISOString().slice(0, 10);
|
|
3133
|
-
let
|
|
3134
|
-
let
|
|
3149
|
+
let sevenDaysMicroUsd = 0;
|
|
3150
|
+
let thirtyDaysMicroUsd = 0;
|
|
3135
3151
|
for (const row of rows) {
|
|
3136
|
-
if (row.
|
|
3137
|
-
|
|
3138
|
-
if (row.date >= sevenDayStartDate)
|
|
3152
|
+
if (row.costMicroUsd === null) continue;
|
|
3153
|
+
thirtyDaysMicroUsd += row.costMicroUsd;
|
|
3154
|
+
if (row.date >= sevenDayStartDate) sevenDaysMicroUsd += row.costMicroUsd;
|
|
3139
3155
|
}
|
|
3140
3156
|
return {
|
|
3141
3157
|
generatedAt: new Date(nowMs).toISOString(),
|
|
3142
|
-
sevenDaysUsd,
|
|
3158
|
+
sevenDaysUsd: microUsdToUsd(sevenDaysMicroUsd),
|
|
3143
3159
|
source: "conversation_index",
|
|
3144
|
-
thirtyDaysUsd,
|
|
3160
|
+
thirtyDaysUsd: microUsdToUsd(thirtyDaysMicroUsd),
|
|
3145
3161
|
windowEnd: end.toISOString(),
|
|
3146
3162
|
windowStart: thirtyDayStart.toISOString()
|
|
3147
3163
|
};
|
|
@@ -3338,9 +3354,19 @@ function createServiceAccountRoutes() {
|
|
|
3338
3354
|
}
|
|
3339
3355
|
// src/api/cache-warming/savings.ts
|
|
3340
3356
|
const DAY_MS = 864e5;
|
|
3341
|
-
function
|
|
3342
|
-
|
|
3343
|
-
|
|
3357
|
+
function savingsUsd(totals) {
|
|
3358
|
+
return {
|
|
3359
|
+
hits: totals.hits,
|
|
3360
|
+
idlePeriods: totals.idlePeriods,
|
|
3361
|
+
oracleSavingsUsd: microUsdToUsd(totals.oracleSavingsMicroUsd),
|
|
3362
|
+
savedUsd: microUsdToUsd(totals.savedMicroUsd),
|
|
3363
|
+
unwarmedIdlePeriods: totals.unwarmedIdlePeriods,
|
|
3364
|
+
unwarmedOracleSavingsUsd: microUsdToUsd(totals.unwarmedOracleSavingsMicroUsd),
|
|
3365
|
+
warmupCostUsd: microUsdToUsd(totals.warmupCostMicroUsd)
|
|
3366
|
+
};
|
|
3367
|
+
}
|
|
3368
|
+
function netSavingsUsd(totals) {
|
|
3369
|
+
return microUsdToUsd(totals.savedMicroUsd - totals.warmupCostMicroUsd);
|
|
3344
3370
|
}
|
|
3345
3371
|
/**
|
|
3346
3372
|
* Read what cache warming saved on each of the last `days` UTC days, today
|
|
@@ -3351,22 +3377,23 @@ async function readCacheWarmingSavings(days, nowMs = Date.now()) {
|
|
|
3351
3377
|
const dates = Array.from({ length: days }, (_, index) => (/* @__PURE__ */ new Date(nowMs - (days - 1 - index) * DAY_MS)).toISOString().slice(0, 10));
|
|
3352
3378
|
const stats = (await readStats(dates[0], dates.at(-1))).filter((stat) => stat.namespace === SAVINGS_NAMESPACE);
|
|
3353
3379
|
const unknownCostDates = new Set(dates.filter((date) => savingsTotals(stats.filter((stat) => stat.date === date)).historyDays > 0));
|
|
3354
|
-
const known =
|
|
3355
|
-
const
|
|
3380
|
+
const known = savingsTotals(stats.filter((stat) => !unknownCostDates.has(stat.date)));
|
|
3381
|
+
const knownNetSavingsUsd = netSavingsUsd(known);
|
|
3382
|
+
const knownOracleSavingsUsd = microUsdToUsd(known.oracleSavingsMicroUsd);
|
|
3356
3383
|
return cacheWarmingSavingsReportSchema.parse({
|
|
3357
3384
|
days: dates.map((date) => {
|
|
3358
|
-
const day =
|
|
3385
|
+
const day = savingsTotals(stats.filter((stat) => stat.date === date));
|
|
3359
3386
|
return {
|
|
3360
3387
|
date,
|
|
3361
|
-
...day,
|
|
3362
|
-
netSavingsUsd: unknownCostDates.has(date) ? null : day
|
|
3388
|
+
...savingsUsd(day),
|
|
3389
|
+
netSavingsUsd: unknownCostDates.has(date) ? null : netSavingsUsd(day)
|
|
3363
3390
|
};
|
|
3364
3391
|
}),
|
|
3365
3392
|
totals: {
|
|
3366
|
-
...
|
|
3367
|
-
netSavingsUsd,
|
|
3368
|
-
knownCostOracleSavingsUsd:
|
|
3369
|
-
effectiveness:
|
|
3393
|
+
...savingsUsd(savingsTotals(stats)),
|
|
3394
|
+
netSavingsUsd: knownNetSavingsUsd,
|
|
3395
|
+
knownCostOracleSavingsUsd: knownOracleSavingsUsd,
|
|
3396
|
+
effectiveness: knownOracleSavingsUsd > 0 ? knownNetSavingsUsd / knownOracleSavingsUsd : null,
|
|
3370
3397
|
unknownCostDays: unknownCostDates.size
|
|
3371
3398
|
}
|
|
3372
3399
|
});
|
|
@@ -3530,16 +3557,24 @@ function editErrorResponse(error) {
|
|
|
3530
3557
|
}, { status: 400 });
|
|
3531
3558
|
throw error;
|
|
3532
3559
|
}
|
|
3560
|
+
/** Position after the last row of a `sort=activity` page. */
|
|
3561
|
+
const automationListCursorSchema = z.object({
|
|
3562
|
+
activityAtMs: z.number().int().nonnegative(),
|
|
3563
|
+
id: z.string().min(1)
|
|
3564
|
+
}).strict();
|
|
3533
3565
|
/** Create authenticated native task list and action routes. */
|
|
3534
3566
|
function createAutomationRoutes() {
|
|
3535
3567
|
const app = new Hono();
|
|
3536
3568
|
app.get("/", requireViewer, validateRequest("query", automationListQuerySchema, "Invalid task list query."), async (context) => {
|
|
3537
3569
|
const user = context.get("viewer");
|
|
3538
3570
|
const query = context.req.valid("query");
|
|
3539
|
-
|
|
3540
|
-
|
|
3571
|
+
if (query.cursor && query.sort !== "activity") throwApiError(400, "A cursor pages only sort=activity.");
|
|
3572
|
+
const after = query.cursor ? decodePageCursor(automationListCursorSchema, query.cursor, "Invalid Automation list cursor.") : void 0;
|
|
3573
|
+
const { next, ...list } = await readViewerAutomations(user, query, after);
|
|
3574
|
+
return jsonResponse(automationListPageSchema, {
|
|
3541
3575
|
...list,
|
|
3542
|
-
automations: await attachAutomationMentions(getSqlExecutor(), list.automations)
|
|
3576
|
+
automations: await attachAutomationMentions(getSqlExecutor(), list.automations),
|
|
3577
|
+
...next ? { nextCursor: encodePageCursor(automationListCursorSchema, next) } : void 0
|
|
3543
3578
|
});
|
|
3544
3579
|
});
|
|
3545
3580
|
app.get("/event-catalog", requireViewer, () => {
|
|
@@ -3560,12 +3595,7 @@ function createAutomationRoutes() {
|
|
|
3560
3595
|
const user = context.get("viewer");
|
|
3561
3596
|
const params = context.req.valid("param");
|
|
3562
3597
|
try {
|
|
3563
|
-
|
|
3564
|
-
const [automation] = await attachAutomationMentions(getSqlExecutor(), [list.automation]);
|
|
3565
|
-
return jsonResponse(automationExecutionListSchema, {
|
|
3566
|
-
...list,
|
|
3567
|
-
automation
|
|
3568
|
-
});
|
|
3598
|
+
return jsonResponse(automationExecutionListSchema, await readViewerAutomationExecutions(user, params.id));
|
|
3569
3599
|
} catch (error) {
|
|
3570
3600
|
if (error instanceof ViewerTaskNotFoundError) return jsonResponse(apiErrorSchema, { error: error.message }, { status: 404 });
|
|
3571
3601
|
throw error;
|
|
@@ -4025,7 +4055,7 @@ function readDescriptionText(home) {
|
|
|
4025
4055
|
}
|
|
4026
4056
|
/** Read discovered skills for runtime diagnostics and the Automation editor. */
|
|
4027
4057
|
async function readSkillReports() {
|
|
4028
|
-
const { discoverSkills } = await import("./skills-
|
|
4058
|
+
const { discoverSkills } = await import("./skills-Bm6uSO9V.js").then((n) => n.o);
|
|
4029
4059
|
const skills = await discoverSkills();
|
|
4030
4060
|
return skillReportsSchema.parse(skills.map((skill) => ({
|
|
4031
4061
|
name: skill.name,
|
|
@@ -4039,7 +4069,7 @@ async function readSkillReports() {
|
|
|
4039
4069
|
* what the skill tells Junior. Returns null when no skill has that name.
|
|
4040
4070
|
*/
|
|
4041
4071
|
async function readSkillDetailReport(name) {
|
|
4042
|
-
const { discoverSkills, findSkillByName, parseSkillFile } = await import("./skills-
|
|
4072
|
+
const { discoverSkills, findSkillByName, parseSkillFile } = await import("./skills-Bm6uSO9V.js").then((n) => n.o);
|
|
4043
4073
|
const skill = findSkillByName(name, await discoverSkills());
|
|
4044
4074
|
if (!skill) return null;
|
|
4045
4075
|
const parsed = parseSkillFile(await fs.readFile(path.join(skill.skillPath, "SKILL.md"), "utf8"), skill.name);
|
|
@@ -4054,7 +4084,7 @@ async function readSkillDetailReport(name) {
|
|
|
4054
4084
|
}
|
|
4055
4085
|
/** Read safe configured plugin metadata for authenticated runtime diagnostics. */
|
|
4056
4086
|
async function readPlugins() {
|
|
4057
|
-
const { pluginCatalogRuntime } = await import("./catalog-runtime-
|
|
4087
|
+
const { pluginCatalogRuntime } = await import("./catalog-runtime-Se9idiDR.js").then((n) => n.t);
|
|
4058
4088
|
return pluginsSchema.parse(pluginCatalogRuntime.getProviders().map((plugin) => ({
|
|
4059
4089
|
configKeys: plugin.manifest.configKeys ?? [],
|
|
4060
4090
|
description: plugin.manifest.description,
|
|
@@ -4066,7 +4096,7 @@ async function readPlugins() {
|
|
|
4066
4096
|
async function readRuntimeInfoReport() {
|
|
4067
4097
|
const [{ homeDir }, { pluginCatalogRuntime }, plugins, skills] = await Promise.all([
|
|
4068
4098
|
import("./package-discovery-x4AvVhMj.js").then((n) => n.r),
|
|
4069
|
-
import("./catalog-runtime-
|
|
4099
|
+
import("./catalog-runtime-Se9idiDR.js").then((n) => n.t),
|
|
4070
4100
|
readPlugins(),
|
|
4071
4101
|
readSkillReports()
|
|
4072
4102
|
]);
|
|
@@ -4083,7 +4113,7 @@ async function readRuntimeInfoReport() {
|
|
|
4083
4113
|
/** Read sanitized operational summaries contributed by plugins. */
|
|
4084
4114
|
async function readPluginOperationalReportFeed() {
|
|
4085
4115
|
const nowMs = Date.now();
|
|
4086
|
-
const { getPluginOperationalReports } = await import("./projection-
|
|
4116
|
+
const { getPluginOperationalReports } = await import("./projection-D47mlszd.js").then((n) => n.Cn);
|
|
4087
4117
|
return pluginOperationalReportFeedSchema.parse({
|
|
4088
4118
|
source: "plugins",
|
|
4089
4119
|
generatedAt: new Date(nowMs).toISOString(),
|