@sentry/junior 0.298.0 → 0.300.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/{actor-6jsm_v96.js → actor-D2iXzvlN.js} +2 -1
- package/dist/{state-CSuA2J1V.js → adapter-S5UkjNK3.js} +53 -136
- package/dist/{admin-BF3DbYGf.js → admin-UrTniSPO.js} +2 -2
- package/dist/{agent-runner-Q9GkoerG.js → agent-runner-bY4_0UPm.js} +1444 -1478
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -7
- package/dist/api.d.ts +1 -1
- package/dist/api.js +382 -68
- package/dist/{app-DOg_mCtV.d.ts → app-D-AcIcCV.d.ts} +17 -4
- package/dist/app.d.ts +1 -1
- package/dist/app.js +148 -483
- package/dist/{automation-Cn8qmbdr.js → automation-Dw82oQ-h.js} +2 -2
- package/dist/{background-compaction-queue-BZhGFOK6.js → background-compaction-queue-B6U3060-.js} +9 -5
- package/dist/{briefs-CQrCRF6-.js → briefs-DqiwWu-n.js} +4 -4
- package/dist/{catalog-runtime-DZeD2WbL.js → catalog-runtime-D1oYNv04.js} +1 -1
- package/dist/cli/chat.js +17 -17
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +5 -5
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +4 -4
- package/dist/{config-BOByVnxe.js → config-9nHoFiJP.js} +117 -12
- package/dist/{connections-BNN5cJam.js → connections-DZjTN3JC.js} +6 -6
- package/dist/continue-in-slack-Dtv7_U42.js +176 -0
- package/dist/{conversation-DCkzvxqB.js → conversation-Dyjq2CZ8.js} +36 -13
- package/dist/{conversation-feed-CMA12Rjs.js → conversation-feed-CcDxlrlQ.js} +109 -3
- package/dist/{conversation-privacy-C0eRxsgb.js → conversation-privacy-D-5HTXjS.js} +1 -1
- package/dist/{conversation-turn-D9qvcDX6.js → conversation-turn-Cxl8WZD7.js} +85 -68
- package/dist/{credential-sync-B_iUpxGL.js → credential-sync-C49ClwDX.js} +18 -18
- package/dist/{db-DoMcnYol.d.ts → db-2resqBh1.d.ts} +1 -1
- package/dist/{db-CoMNr2Zm.js → db-BJNo6fK5.js} +176 -12
- package/dist/{executor-C-m8VrzX.js → executor-DBIaOeJ_.js} +47 -13
- package/dist/{media-BepyEUNm.js → history-IjdmO_r6.js} +1 -85
- package/dist/instrumentation.js +14 -5
- package/dist/lineage-0dereG7H.js +37 -0
- package/dist/{logging-CJTi5niy.js → logging-BIclibct.js} +1 -1
- package/dist/{message-Q6_5DAWR.js → message-dkOl-Iii.js} +9 -10
- package/dist/model-input-CLo9TaUd.js +82 -0
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +17 -9
- package/dist/{oauth-callback-server-CH5XAyo-.js → oauth-callback-server-WmpjfJgQ.js} +2 -2
- package/dist/{plugins-HYh_JOdw.js → plugins-BBX07Jzt.js} +1 -1
- package/dist/{projection-BgwEE36_.js → projection-w_X-zi7v.js} +1035 -692
- package/dist/{prompt-DXc9DYT9.js → prompt-B1Xw46-S.js} +4 -4
- package/dist/{registry-9XwqSnM-.js → registry-BmP5vnlj.js} +4 -4
- package/dist/{resolve-DUIAbcRL.js → resolve-goo34bJK.js} +3 -3
- package/dist/{result-C2Vn8QGn.js → result-PVBeU0Wf.js} +158 -69
- package/dist/{runner-CXGtw-Mc.js → runner-DKrfvNV6.js} +9 -9
- package/dist/{sandbox-egress-signals-Di3S_dO7.js → sandbox-egress-signals-DsUcqrI0.js} +1 -1
- package/dist/{schema-Dyp7racy.js → schema-C9iNFz5n.js} +51 -7
- package/dist/{schema-BnbZ-rKv.d.ts → schema-Dns-sTas.d.ts} +1285 -761
- package/dist/{service-account-DM3KBBeG.js → service-account-CMAAloAL.js} +3 -3
- package/dist/{service-account-GzAMUQ8a.js → service-account-CmowamcB.js} +4 -4
- package/dist/session-stop-BcAXze8a.js +3330 -0
- package/dist/{skills-DCK9SD_l.js → skills-DfsazET6.js} +3 -3
- package/dist/slack-conversation-unfurl-CzQonuWz.js +370 -0
- package/dist/spawn-C7o0FDDp.js +73 -0
- package/dist/state-zSilNpbi.js +132 -0
- package/dist/{user-input-request-CXNIov9n.js → statuses-Hn-HsOph.js} +115 -26
- package/dist/{stop-Dh2DfwpK.js → stop-CFOujp8C.js} +9105 -6007
- package/dist/{store-DrA17Fbz.js → store-Dkeis_8o.js} +10 -10
- package/dist/{store-B1zepKG8.js → store-E3x2Fg_F.js} +24 -4
- package/dist/{task-queue-D1rXWfFN.js → task-queue-D-hCqdZW.js} +4 -4
- package/dist/{task-runner-CT4M8oDz.js → task-runner-vohUPLHe.js} +10 -10
- package/dist/{thread-context-DnqUkbzN.js → thread-context-BzvdkgI9.js} +18 -18
- package/dist/{turn-session-routing-VXDVXLRl.js → turn-session-routing-Bo_LxFum.js} +5 -5
- package/dist/turn-user-message-D5RnVmxQ.js +355 -0
- package/dist/users-2bggndVg.js +424 -0
- package/dist/{validation-zxAJBDDy.js → validation-BbWikeSa.js} +1 -1
- package/dist/{version-DcZ40a0g.js → version-GVBMW2jA.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-CgiGjW10.js → viewer-BpxRliyO.js} +36 -163
- package/dist/{warmup-CwKbxQLl.js → warmup-BW2qwnal.js} +1140 -145
- package/dist/{worker-CbDUzaBA.js → worker-Cbd-iuwZ.js} +25 -20
- package/migrations/0104_code_change_draft.sql +1 -0
- package/migrations/0105_attachment_uploads.sql +14 -0
- package/migrations/0106_conversation_agent_config.sql +1 -0
- package/migrations/0107_attachment_deferred_download.sql +2 -0
- package/migrations/meta/0104_snapshot.json +4516 -0
- package/migrations/meta/0105_snapshot.json +4611 -0
- package/migrations/meta/0106_snapshot.json +4617 -0
- package/migrations/meta/0107_snapshot.json +4617 -0
- package/migrations/meta/_journal.json +28 -0
- package/package.json +10 -8
- package/dist/attempt-selection-ClP3MMPr.js +0 -61
- package/dist/locks-D-0h111u.js +0 -48
- package/dist/notification-Bv25xbj0.js +0 -1284
- package/dist/prompt-input-BUr4J9RO.js +0 -1424
- package/dist/session-stop-D4i7e6iT.js +0 -181
- package/dist/spawn-6cX6xE9G.js +0 -80
- package/dist/turn-cancel-l460pfGW.js +0 -201
- package/dist/turn-user-message-BSPmkm7X.js +0 -608
- package/dist/turn-wake-DVFVXyhX.js +0 -161
- package/dist/{oauth-relay-CsfIazeF.js → oauth-relay-DRzq73b6.js} +1 -1
package/dist/api.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { m as logInfo, p as logException } from "./logging-
|
|
4
|
-
import { f as parseSlackTeamId, u as parseSlackChannelId } from "./actor-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
9
|
-
import {
|
|
10
|
-
import { n as briefEntriesFromReportEvents, u as completeText } from "./prompt-
|
|
11
|
-
import { c as readViewerAvatarUrl, d as updateViewerDisplayName, l as resolveViewerUser, m as readAvatarImage, t as findUserByEmail } from "./viewer-CgiGjW10.js";
|
|
12
|
-
import { a as getStateAdapter } from "./state-CSuA2J1V.js";
|
|
1
|
+
import { $i as create, Cr as saveNotificationSchedule, Do as readConversationBriefThrough, Fr as listWaitingConversations, Gi as listWorkspaces, Gr as isOnlyAssignee, Hi as deleteWorkspace, Ir as reviewItemsNeedingUserVersionQuery, Ji as WorkspaceValidationError, Ki as listWorkspacesByRepository, Lr as searchReviewItems, Ni as getDashboardSettingsLink, Sr as readNotificationSchedule, Tr as isPausedBySlack, Ui as getWorkspace, Vi as createWorkspace, Vo as readSlackAttachmentSource, Vr as canActOnReviewItem, Xr as reviewItemReaderForUser, Ya as SANDBOX_RUNTIME, Za as workspaceRepoCheckoutPath, Zn as createUserTokenStore, Zr as reviewItemReaderForUserInConversation, _r as readWebPushConfig, _s as createPluginCache, br as deletePushSubscription, cs as createPluginAnnotations, dr as getPlugins, ea as hash, ho as createPluginLogger, ko as readConversationEventPage, kr as countReviewItemsNeedingUser, ls as listConversationAnnotations, qi as updateWorkspace, vo as createConversationAccessReader, vr as sendPushNotificationToUser, wr as savePushSubscription, xr as listPushSubscriptions, yo as readConversationAccessFromSql, yr as resolveNotificationTimezone } from "./projection-w_X-zi7v.js";
|
|
2
|
+
import { R as escapeXml, Z as getAttachmentStorage, n as botConfig } from "./config-9nHoFiJP.js";
|
|
3
|
+
import { h as logWarn, m as logInfo, p as logException } from "./logging-BIclibct.js";
|
|
4
|
+
import { f as parseSlackTeamId, u as parseSlackChannelId } from "./actor-D2iXzvlN.js";
|
|
5
|
+
import { D as conversationKindFromRow, W as createCache, _ as loadConversationSlackTenantIds, a as getConversationStore, nt as nextDetailVersion, o as getDb, s as getSqlExecutor, x as withConversationMutationLock } from "./db-BJNo6fK5.js";
|
|
6
|
+
import { D as juniorCodeChanges, M as juniorIdentities, N as juniorUsers, O as juniorCodeRepositories, P as juniorDestinations, S as juniorConversationMetrics, T as juniorApiTokens, b as juniorConversationBriefs, j as juniorConversations, w as juniorConversationEvents } from "./executor-DBIaOeJ_.js";
|
|
7
|
+
import { r as getStateAdapter } from "./adapter-S5UkjNK3.js";
|
|
8
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-D1oYNv04.js";
|
|
9
|
+
import { B as activateViewerAutomationVersion, Dt as throwApiError, Et as jsonResponse, G as ViewerTaskNotFoundError, H as deleteViewerTask, J as readViewerAutomationRuns, Ot as previewOriginBelongsTo, Q as AutomationEditError, T as createSlackReviewItemShow, Tt as emptyResponse, U as readViewerAutomationEdit, V as changeViewerAutomationLifecycle, W as updateViewerAutomation, X as readViewerAutomationVersions, Y as readViewerAutomationSummary, Z as readViewerAutomations, _ as readAttachmentContent, et as listOwnedWatches, ft as AttachmentUploadError, g as AttachmentDownloadError, gt as writeAttachmentUpload, h as readStats, it as acceptsWebMessages, mt as createAttachmentUpload, q as readViewerAutomationExecutions, ut as webActorFromUser, vt as readLiveAttachment, wt as reportConversationRead, x as setConversationSubscription, xt as archiveConversation } from "./agent-runner-bY4_0UPm.js";
|
|
10
|
+
import { n as briefEntriesFromReportEvents, u as completeText } from "./prompt-B1Xw46-S.js";
|
|
13
11
|
import { r as notificationScheduleSchema } from "./schedule-cP0AACm1.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { u as automationEventCatalog } from "./turn-session-routing-
|
|
20
|
-
import {
|
|
21
|
-
import { s as getSandboxResources, t as getCachedSnapshot } from "./resolve-
|
|
22
|
-
import { n as finishServiceAccountSignIn, o as serviceAccountPlugins, r as getServiceAccountStatus, s as startServiceAccountSignIn, t as disconnectServiceAccount } from "./service-account-
|
|
12
|
+
import { c as readViewerAvatarUrl, d as updateViewerDisplayName, l as resolveViewerUser, m as readAvatarFetch, t as findUserByEmail } from "./viewer-BpxRliyO.js";
|
|
13
|
+
import { C as createConversationBodySchema, E as forkConversationResponseSchema, F as renameConversationBodySchema, G as MAX_ATTACHMENT_BYTES, I as renameConversationResponseSchema, L as conversationReadPositionSchema, T as forkConversationBodySchema, f as conversationEventPageSchema, h as conversationParamsSchema, l as conversationDetailQuerySchema, m as conversationFeedQuerySchema, 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 createConversationMessageBodySchema } from "./conversation-Dyjq2CZ8.js";
|
|
14
|
+
import { R as getEventCatalog, S as addConversationNote, _ as readUserCustomization, b as isExperimentalFeatureEnabled, v as saveUserCustomization } from "./session-stop-BcAXze8a.js";
|
|
15
|
+
import { Dt as GAP_SEGMENTS, Mt as gapHistogramReport, a as segmentGapsKey, d as listChildAgents } from "./warmup-BW2qwnal.js";
|
|
16
|
+
import { l as getVercelConversationWorkQueue } from "./background-compaction-queue-B6U3060-.js";
|
|
17
|
+
import { u as automationEventCatalog } from "./turn-session-routing-Bo_LxFum.js";
|
|
18
|
+
import { d as INLINE_VIDEO_TYPES, f as INPUT_IMAGE_TYPES, g as userCustomizationSchema, p as detectImageMediaType } from "./statuses-Hn-HsOph.js";
|
|
19
|
+
import { s as getSandboxResources, t as getCachedSnapshot } from "./resolve-goo34bJK.js";
|
|
20
|
+
import { n as finishServiceAccountSignIn, o as serviceAccountPlugins, r as getServiceAccountStatus, s as startServiceAccountSignIn, t as disconnectServiceAccount } from "./service-account-CmowamcB.js";
|
|
23
21
|
import { a as fillUtcSixHours, c as trailingUtcDayWindow, d as utcDayKey, f as utcHourKey, i as fillUtcHours, l as trailingUtcHourWindow, m as apiErrorSchema, n as HOUR_MS$1, o as startOfUtcHour, r as fillUtcDays, s as sumUtcHoursIntoSixHours, t as DAY_MS$1, u as trailingUtcSixHourWindow } from "./reporting-window-DopzcOHh.js";
|
|
24
|
-
import { F as compileScheduleIntent, P as ScheduleIntentError, U as automationTaskText, _ as automationSummarySchema, b as automationVersionListSchema, c as automationLifecycleSchema, d as automationParamsSchema, f as automationRunListSchema, g as automationSchedulePreviewSchema, h as automationScheduleIntentSchema, i as automationExecutionListSchema, l as automationListQuerySchema, n as automationEditSchema, r as automationEventCatalogSchema, t as automationEditErrorSchema, u as automationListSchema, v as automationUpdateSchema, x as automationVersionParamsSchema, y as automationVersionActivateSchema } from "./automation-
|
|
25
|
-
import { A as conversationRangeColumns, D as readAutomationTitlesByConversationId, at as AutomationConflictError, j as conversationUsageCostExpr, k as conversationAggregateColumns } from "./store-
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { a as
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
22
|
+
import { F as compileScheduleIntent, P as ScheduleIntentError, U as automationTaskText, _ as automationSummarySchema, b as automationVersionListSchema, c as automationLifecycleSchema, d as automationParamsSchema, f as automationRunListSchema, g as automationSchedulePreviewSchema, h as automationScheduleIntentSchema, i as automationExecutionListSchema, l as automationListQuerySchema, n as automationEditSchema, r as automationEventCatalogSchema, t as automationEditErrorSchema, u as automationListSchema, v as automationUpdateSchema, x as automationVersionParamsSchema, y as automationVersionActivateSchema } from "./automation-Dw82oQ-h.js";
|
|
23
|
+
import { A as conversationRangeColumns, D as readAutomationTitlesByConversationId, at as AutomationConflictError, j as conversationUsageCostExpr, k as conversationAggregateColumns } from "./store-Dkeis_8o.js";
|
|
24
|
+
import { a as runWithSlackInstallation } from "./users-2bggndVg.js";
|
|
25
|
+
import { $ as decodeImageId, F as readReviewItemForUser, G as OBJECT_LINK_TTL_MS, H as updateUserAutoArchiveSettings, J as resolveObjectLinks, L as DEFAULT_AUTO_ARCHIVE_SETTINGS, M as ReviewItemActionError, N as actOnReviewItem, O as isAllowedSignInEmail, Q as IMAGE_WIDTHS, R as archiveViewerDoneConversations, S as cancelConversationPendingMessagesForViewer, T as resolveMentions, V as setConversationAutoArchive, W as readHealthReport, Y as guardedFetch, _ as appendConversationMessageForViewer, a as pinConversation, bt as readFirstHumanMessageTexts, c as readConversationAuxiliaryCostsFromSql, d as conversationVersionQuery, f as readConversationDetailEtag, h as readConversationEvents, i as readConversationFeed, l as childAgentTotalsReport, m as keepQuickQuestionForViewer, n as steerConversationPendingMessagesForViewer, nt as getProductionSlackAdapter, o as reorderPinnedConversations, p as forkConversationForViewer, q as resolveObjectLinkNow, r as conversationFeedVersionQuery, s as readConversationDetail, t as stopConversationTurnForViewer, u as readConversationTreeMetricsFromSql, v as createConversationForViewer, w as requireConversationPendingMessages, y as requireWebMessageConversation, yt as conversationSummaryFromStoredConversation, z as readUserAutoArchiveSettings } from "./stop-CFOujp8C.js";
|
|
26
|
+
import { C as skillReportsSchema, a as conversationDetailWithMailboxReportSchema, b as runtimeInfoReportSchema, d as steerConversationPendingMessagesBodySchema, f as steerConversationPendingMessagesResponseSchema, i as cancelConversationPendingMessagesResponseSchema, l as conversationPendingMessagesReportSchema, m as pluginOperationalReportFeedSchema, n as conversationFeedSchema, p as healthReportSchema, r as cancelConversationPendingMessagesBodySchema, u as conversationUnchangedDetailWithMailboxSchema, x as skillDetailReportSchema, y as pluginsSchema } from "./conversation-feed-CcDxlrlQ.js";
|
|
27
|
+
import { a as resumeConversationDelivery, i as pauseConversationDelivery, r as canPauseConversationDelivery } from "./conversation-turn-Cxl8WZD7.js";
|
|
28
|
+
import { a as startConnection, n as isConnectableProvider, r as listConnections, s as htmlCallbackResponse, t as disconnectConnection } from "./connections-DZjTN3JC.js";
|
|
29
|
+
import { i as continueConversationInSlack, r as canContinueInSlack, t as BUSY } from "./continue-in-slack-Dtv7_U42.js";
|
|
30
|
+
import { A as revokePersonalTokenResponseSchema, At as pinConversationBodySchema, B as activityDays$1, Ct as archiveConversationResponseSchema, D as personalTokenListSchema, Dt as conversationSubscriptionResponseSchema, E as createdPersonalTokenSchema, Et as conversationSubscriptionBodySchema, F as personalSpendReportSchema, Ft as conversationCatchUpSchema, G as pushSubscriptionBodySchema, H as activitySixHours$1, It as attachmentUploadParamsSchema, J as connectionListSchema, K as pushSubscriptionDeleteBodySchema, L as locationDetailReportSchema, Lt as attachmentUploadSchema, M as actorProfileReportSchema, Mt as reorderPinnedConversationsBodySchema, N as avatarParamsSchema, Nt as reorderPinnedConversationsResponseSchema, Ot as conversationDeliveryBodySchema, P as personParamsSchema, Pt as conversationCatchUpBodySchema, Q as startConnectionResponseSchema, R as locationDirectoryReportSchema, Rt as createAttachmentUploadBodySchema, S as serviceAccountParamsSchema, St as archiveConversationBodySchema, T as createPersonalTokenBodySchema, Tt as conversationAutoArchiveSchema, V as activityHours$1, W as notificationSettingsSchema, Y as connectionParamsSchema, Z as disconnectConnectionResponseSchema, _ as reviewItemParamsSchema, _t as objectLinksReportSchema, a as replyTimeSegmentsReportSchema, at as codeRepositoryReportSchema, b as disconnectServiceAccountResponseSchema, c as workspaceBodySchema, ct as conversationWatchesReportSchema, dt as continueConversationInSlackBodySchema, f as workspaceSchema, ft as continueConversationInSlackResponseSchema, g as reviewItemListSchema, gt as objectLinksQuerySchema, h as reviewItemListQuerySchema, ht as attachObjectLinkResponseSchema, i as statsReportSchema, it as codeRepositoryParamsSchema, j as actorDirectoryReportSchema, jt as pinConversationResponseSchema, k as personalTokenParamsSchema, kt as conversationDeliveryResponseSchema, l as workspaceListSchema, m as reviewItemCountSchema, mt as attachObjectLinkBodySchema, n as versionsSchema, nt as codeOverviewReportSchema, p as reviewItemActionSchema, q as testNotificationResponseSchema, rt as codePersonReportSchema, s as deleteWorkspaceResponseSchema, t as versionsQuerySchema, u as workspaceParamsSchema, ut as conversationChildAgentsReportSchema, v as reviewItemSchema, vt as stopConversationTurnResponseSchema, w as startServiceAccountSignInResponseSchema, wt as archiveDoneConversationsResponseSchema, x as serviceAccountListSchema, xt as conversationOutlineSchema, y as reviewItemWaitingConversationsSchema, yt as conversationStatsReportSchema, z as locationParamsSchema } from "./schema-C9iNFz5n.js";
|
|
31
31
|
import { Hono } from "hono";
|
|
32
|
+
import * as z from "zod";
|
|
32
33
|
import path from "node:path";
|
|
33
34
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
34
|
-
import * as z from "zod";
|
|
35
35
|
import { and, asc, countDistinct, desc, eq, gt, gte, inArray, isNull, lte, notExists, or, sql } from "drizzle-orm";
|
|
36
|
-
import { pluginUserPageContentSchema, pluginUserPageCursorSchema, pluginUserPageFilterSchema, pluginUserPageLinksSchema, pluginUserPageQuerySchema } from "@sentry/junior-plugin-api";
|
|
36
|
+
import { objectPresentation, pluginUserPageContentSchema, pluginUserPageCursorSchema, pluginUserPageFilterSchema, pluginUserPageLinksSchema, pluginUserPageQuerySchema } from "@sentry/junior-plugin-api";
|
|
37
37
|
import { alias } from "drizzle-orm/pg-core";
|
|
38
38
|
import fs from "node:fs/promises";
|
|
39
39
|
import { readFileSync } from "node:fs";
|
|
@@ -41,6 +41,52 @@ import { HTTPException } from "hono/http-exception";
|
|
|
41
41
|
import { bodyLimit } from "hono/body-limit";
|
|
42
42
|
import { zValidator } from "@hono/zod-validator";
|
|
43
43
|
import { createMiddleware } from "hono/factory";
|
|
44
|
+
// src/api/objects/attach.ts
|
|
45
|
+
function sameLink(left, right) {
|
|
46
|
+
const key = (url) => url.replace(/\/+$/, "");
|
|
47
|
+
return key(left) === key(right);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Attach a linked object to a Conversation for one participant. The
|
|
51
|
+
* Annotation and the Conversation note save no title. The note tells the
|
|
52
|
+
* next Turn the type and the read tool of the object, so the agent reads it
|
|
53
|
+
* live. Nothing is attached when the viewer cannot write to the
|
|
54
|
+
* Conversation, the Conversation takes no web input from people (a Task),
|
|
55
|
+
* or the viewer cannot see the object now.
|
|
56
|
+
*/
|
|
57
|
+
async function attachObjectLink(viewer, conversationId, url) {
|
|
58
|
+
const db = getDb();
|
|
59
|
+
if (!(await readConversationAccessFromSql(db, [conversationId], viewer)).get(conversationId)?.isParticipant) throwApiError(404, "Conversation not found.");
|
|
60
|
+
const conversation = await getConversationStore().get({ conversationId });
|
|
61
|
+
if (!conversation || !acceptsWebMessages(conversation)) throwApiError(409, "Conversation does not accept attached objects.");
|
|
62
|
+
const parsed = URL.canParse(url) ? new URL(url) : void 0;
|
|
63
|
+
const resolved = parsed && await resolveObjectLinkNow(viewer, parsed);
|
|
64
|
+
if (!parsed || !resolved || resolved.object.objectType === "person") throwApiError(404, "Object not found.");
|
|
65
|
+
const { linkType, object } = resolved;
|
|
66
|
+
const link = object.url ?? parsed.href;
|
|
67
|
+
if ((await listConversationAnnotations(db, conversationId)).some((annotation) => annotation.url && sameLink(annotation.url, link) || annotation.plugin === linkType.owner && annotation.key === object.key)) return { status: "unchanged" };
|
|
68
|
+
const type = object.displayType ?? objectPresentation(object).label;
|
|
69
|
+
const article = /^[aeiou]/i.test(type) ? "an" : "a";
|
|
70
|
+
const { readTool } = linkType;
|
|
71
|
+
await addConversationNote({
|
|
72
|
+
conversationId,
|
|
73
|
+
createdAtMs: Date.now(),
|
|
74
|
+
key: `object_attached:${linkType.owner}:${object.key}`,
|
|
75
|
+
text: [`${viewer.displayName ?? viewer.email} attached ${article} ${type} (${link}) to this Conversation.`, readTool ? `Read it live with \`${readTool}\` when the work needs its content.` : ""].filter(Boolean).join(" ")
|
|
76
|
+
});
|
|
77
|
+
await createPluginAnnotations({
|
|
78
|
+
conversationId,
|
|
79
|
+
db,
|
|
80
|
+
plugin: linkType.owner
|
|
81
|
+
}).upsert({
|
|
82
|
+
kind: "resource_link",
|
|
83
|
+
key: object.key,
|
|
84
|
+
label: link.slice(0, 256),
|
|
85
|
+
objectType: object.objectType,
|
|
86
|
+
url: link
|
|
87
|
+
});
|
|
88
|
+
return { status: "attached" };
|
|
89
|
+
}
|
|
44
90
|
// src/api/validation.ts
|
|
45
91
|
/** Validate one request input and use Junior's stable JSON error contract. */
|
|
46
92
|
function validateRequest(target, schema, message) {
|
|
@@ -320,6 +366,7 @@ async function continueConversationInSlackForViewer(viewer, conversationId, body
|
|
|
320
366
|
conversation
|
|
321
367
|
})
|
|
322
368
|
});
|
|
369
|
+
if (result.status === "busy") throwApiError(409, BUSY);
|
|
323
370
|
if (result.status === "refused") throwApiError(409, result.message);
|
|
324
371
|
return {
|
|
325
372
|
conversationId,
|
|
@@ -329,8 +376,8 @@ async function continueConversationInSlackForViewer(viewer, conversationId, body
|
|
|
329
376
|
}
|
|
330
377
|
// src/api/conversations/attachments.ts
|
|
331
378
|
const INLINE_TYPES = [...INPUT_IMAGE_TYPES, ...INLINE_VIDEO_TYPES];
|
|
332
|
-
function contentDisposition(filename, contentType) {
|
|
333
|
-
return `${INLINE_TYPES.includes(contentType) ? "inline" : "attachment"}; filename="${filename.replace(/[^\x20-\x7e]|["\\]/g, "_")}"; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
379
|
+
function contentDisposition(filename, contentType, download) {
|
|
380
|
+
return `${!download && INLINE_TYPES.includes(contentType) ? "inline" : "attachment"}; filename="${filename.replace(/[^\x20-\x7e]|["\\]/g, "_")}"; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
334
381
|
}
|
|
335
382
|
/**
|
|
336
383
|
* Read one `Range` request header against an object size.
|
|
@@ -361,20 +408,71 @@ function parseRangeHeader(header, size) {
|
|
|
361
408
|
};
|
|
362
409
|
}
|
|
363
410
|
/**
|
|
411
|
+
* Stream a large Slack file that Junior never stored, from Slack through the
|
|
412
|
+
* host, with the conversation's Slack installation. A HEAD request checks
|
|
413
|
+
* that Slack still has the file without downloading it. Ranges are not
|
|
414
|
+
* supported, so media players cannot seek in these files.
|
|
415
|
+
*/
|
|
416
|
+
async function slackFileResponse(args) {
|
|
417
|
+
const { attachment, teamId } = args;
|
|
418
|
+
const read = async () => {
|
|
419
|
+
const content = await readAttachmentContent({
|
|
420
|
+
attachment,
|
|
421
|
+
...teamId ? { readAttachmentSource: readSlackAttachmentSource } : void 0,
|
|
422
|
+
storage: args.storage
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
body: args.headOnly ? null : await content.open(),
|
|
426
|
+
bytes: content.bytes
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
let file;
|
|
430
|
+
try {
|
|
431
|
+
file = teamId ? await runWithSlackInstallation({
|
|
432
|
+
adapter: getProductionSlackAdapter(),
|
|
433
|
+
installation: { teamId },
|
|
434
|
+
task: read
|
|
435
|
+
}) : await read();
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (error instanceof AttachmentDownloadError) throwApiError(409, error.message, error);
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
return new Response(file.body, { headers: {
|
|
441
|
+
"cache-control": "private, no-store",
|
|
442
|
+
"content-disposition": contentDisposition(attachment.filename, attachment.contentType, args.download),
|
|
443
|
+
"content-length": String(file.bytes),
|
|
444
|
+
"content-type": attachment.contentType,
|
|
445
|
+
"x-content-type-options": "nosniff"
|
|
446
|
+
} });
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
364
449
|
* Answer one attachment read for an authorized viewer, with one byte range
|
|
365
450
|
* when the request asks for it. Media players need ranges to play and seek.
|
|
366
451
|
*
|
|
367
452
|
* Missing conversations, missing attachments, purge-marked rows, and viewers
|
|
368
|
-
* without private-content access all answer 404.
|
|
453
|
+
* without private-content access all answer 404. A large Slack file that
|
|
454
|
+
* Junior never stored also needs a signed-in viewer. The row lookup is scoped to
|
|
455
|
+
* the conversation, so a Slack download only ever starts from a row that
|
|
456
|
+
* ingest created there.
|
|
369
457
|
*/
|
|
370
458
|
async function conversationAttachmentResponse(args) {
|
|
371
|
-
|
|
459
|
+
const access = await requireAttachmentAccess(args.conversationId, args.viewer);
|
|
372
460
|
const attachment = await readLiveAttachment({
|
|
373
461
|
attachmentId: args.attachmentId,
|
|
374
462
|
conversationId: args.conversationId,
|
|
375
463
|
db: getSqlExecutor()
|
|
376
464
|
});
|
|
377
465
|
if (!attachment || attachment.storageProvider !== args.storage.provider) notFound();
|
|
466
|
+
if (attachment.storageKey === null) {
|
|
467
|
+
if (!args.viewer) throwApiError(401, "Authentication required.");
|
|
468
|
+
return await slackFileResponse({
|
|
469
|
+
attachment,
|
|
470
|
+
download: args.download,
|
|
471
|
+
headOnly: args.headOnly,
|
|
472
|
+
storage: args.storage,
|
|
473
|
+
teamId: access.tenant?.provider === "slack" ? parseSlackTeamId(access.tenant.providerTenantId) : void 0
|
|
474
|
+
});
|
|
475
|
+
}
|
|
378
476
|
const headers = new Headers({
|
|
379
477
|
"accept-ranges": "bytes",
|
|
380
478
|
"cache-control": "private, no-store",
|
|
@@ -390,7 +488,7 @@ async function conversationAttachmentResponse(args) {
|
|
|
390
488
|
}
|
|
391
489
|
const body = await args.storage.get(attachment.storageKey, range);
|
|
392
490
|
if (!body) notFound();
|
|
393
|
-
headers.set("content-disposition", contentDisposition(attachment.filename, attachment.contentType));
|
|
491
|
+
headers.set("content-disposition", contentDisposition(attachment.filename, attachment.contentType, args.download));
|
|
394
492
|
headers.set("content-type", attachment.contentType);
|
|
395
493
|
if (!range) {
|
|
396
494
|
headers.set("content-length", String(attachment.bytes));
|
|
@@ -403,9 +501,67 @@ async function conversationAttachmentResponse(args) {
|
|
|
403
501
|
status: 206
|
|
404
502
|
});
|
|
405
503
|
}
|
|
504
|
+
async function requireAttachmentAccess(conversationId, viewer) {
|
|
505
|
+
const access = (await readConversationAccessFromSql(getDb(), [conversationId], viewer)).get(conversationId);
|
|
506
|
+
if (!access?.canViewPrivateContent) notFound();
|
|
507
|
+
return access;
|
|
508
|
+
}
|
|
406
509
|
function notFound() {
|
|
407
510
|
throwApiError(404, "Attachment not found.");
|
|
408
511
|
}
|
|
512
|
+
// src/api/conversations/attachment-uploads.ts
|
|
513
|
+
/** API path that takes upload bytes when storage cannot sign browser writes. */
|
|
514
|
+
function apiUploadPath(uploadId) {
|
|
515
|
+
return `/api/conversations/attachment-uploads/${encodeURIComponent(uploadId)}`;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Reserve one upload for a viewer's next web Message.
|
|
519
|
+
*
|
|
520
|
+
* The upload is bound to the viewer, the target Conversation, and the Message
|
|
521
|
+
* idempotency key. The send checks all three.
|
|
522
|
+
*/
|
|
523
|
+
async function createAttachmentUploadForViewer(viewer, body, storage) {
|
|
524
|
+
const conversationId = await requireWebMessageConversation(viewer, body.conversationId, body.idempotencyKey);
|
|
525
|
+
const upload = await createAttachmentUpload({
|
|
526
|
+
db: getSqlExecutor(),
|
|
527
|
+
file: {
|
|
528
|
+
bytes: body.bytes,
|
|
529
|
+
contentType: body.contentType,
|
|
530
|
+
filename: body.filename
|
|
531
|
+
},
|
|
532
|
+
scope: {
|
|
533
|
+
conversationId,
|
|
534
|
+
idempotencyKey: body.idempotencyKey,
|
|
535
|
+
userId: viewer.id
|
|
536
|
+
},
|
|
537
|
+
storage
|
|
538
|
+
});
|
|
539
|
+
return {
|
|
540
|
+
uploadId: upload.id,
|
|
541
|
+
target: upload.target ?? {
|
|
542
|
+
headers: { "content-type": body.contentType },
|
|
543
|
+
method: "PUT",
|
|
544
|
+
url: apiUploadPath(upload.id)
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
/** Take upload bytes for storage that cannot sign browser writes. */
|
|
549
|
+
async function writeAttachmentUploadForViewer(args) {
|
|
550
|
+
if (args.storage.createUploadTarget) throwApiError(404, "Upload not found.");
|
|
551
|
+
const body = Buffer.from(await args.readBody());
|
|
552
|
+
try {
|
|
553
|
+
await writeAttachmentUpload({
|
|
554
|
+
body,
|
|
555
|
+
db: getSqlExecutor(),
|
|
556
|
+
storage: args.storage,
|
|
557
|
+
uploadId: args.uploadId,
|
|
558
|
+
userId: args.viewer.id
|
|
559
|
+
});
|
|
560
|
+
} catch (error) {
|
|
561
|
+
if (error instanceof AttachmentUploadError) throwApiError(400, error.message);
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
409
565
|
// src/api/conversations/outline.ts
|
|
410
566
|
const payload = juniorConversationEvents.payload;
|
|
411
567
|
/**
|
|
@@ -984,18 +1140,14 @@ async function requireConversationWatches(conversationId, options = {}) {
|
|
|
984
1140
|
/** Create the HTTP routes owned by the conversations API. */
|
|
985
1141
|
function createConversationRoutes(options) {
|
|
986
1142
|
const app = new Hono();
|
|
987
|
-
const messageBodyLimit = bodyLimit({
|
|
988
|
-
maxSize: 445e4,
|
|
989
|
-
onError: () => {
|
|
990
|
-
throwApiError(413, "Images must total 3 MB or less.");
|
|
991
|
-
}
|
|
992
|
-
});
|
|
1143
|
+
const messageBodyLimit = bodyLimit({ maxSize: 262144 });
|
|
993
1144
|
app.get("/", validateRequest("query", conversationFeedQuerySchema, "Invalid query parameters."), async (context) => {
|
|
994
|
-
const { actorEmail, codeRepositoryId, q, status } = context.req.valid("query");
|
|
1145
|
+
const { actorEmail, codeRepositoryId, cursor, q, status } = context.req.valid("query");
|
|
995
1146
|
const viewer = context.get("viewer");
|
|
996
1147
|
return jsonResponse(conversationFeedSchema, await readConversationFeed({
|
|
997
1148
|
...actorEmail ? { actorEmail } : void 0,
|
|
998
1149
|
...codeRepositoryId ? { codeRepositoryId } : void 0,
|
|
1150
|
+
...cursor ? { cursor } : void 0,
|
|
999
1151
|
...q ? { q } : void 0,
|
|
1000
1152
|
status,
|
|
1001
1153
|
...viewer ? { viewer } : void 0
|
|
@@ -1007,6 +1159,21 @@ function createConversationRoutes(options) {
|
|
|
1007
1159
|
const body = context.req.valid("json");
|
|
1008
1160
|
return jsonResponse(acceptedConversationMessageSchema, await createConversationForViewer(viewer, body, options));
|
|
1009
1161
|
});
|
|
1162
|
+
app.post("/attachment-uploads", requireViewer, bodyLimit({ maxSize: 8192 }), validateRequest("json", createAttachmentUploadBodySchema, "Invalid request body."), async (context) => jsonResponse(attachmentUploadSchema, await createAttachmentUploadForViewer(context.get("viewer"), context.req.valid("json"), options.attachmentStorage)));
|
|
1163
|
+
app.put("/attachment-uploads/:uploadId", requireViewer, bodyLimit({
|
|
1164
|
+
maxSize: MAX_ATTACHMENT_BYTES,
|
|
1165
|
+
onError: () => {
|
|
1166
|
+
throwApiError(413, `Files must be ${MAX_ATTACHMENT_BYTES / 1024 / 1024} MB or less.`);
|
|
1167
|
+
}
|
|
1168
|
+
}), validateRequest("param", attachmentUploadParamsSchema, "Invalid route parameters."), async (context) => {
|
|
1169
|
+
await writeAttachmentUploadForViewer({
|
|
1170
|
+
readBody: () => context.req.arrayBuffer(),
|
|
1171
|
+
storage: options.attachmentStorage,
|
|
1172
|
+
uploadId: context.req.valid("param").uploadId,
|
|
1173
|
+
viewer: context.get("viewer")
|
|
1174
|
+
});
|
|
1175
|
+
return context.body(null, 204);
|
|
1176
|
+
});
|
|
1010
1177
|
app.post("/:conversationId/messages", requireViewer, messageBodyLimit, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", createConversationMessageBodySchema, "Invalid request body."), async (context) => {
|
|
1011
1178
|
const viewer = context.get("viewer");
|
|
1012
1179
|
const { conversationId } = context.req.valid("param");
|
|
@@ -1031,6 +1198,7 @@ function createConversationRoutes(options) {
|
|
|
1031
1198
|
app.patch("/:conversationId/delivery", requireViewer, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", conversationDeliveryBodySchema, "Invalid request body."), async (context) => jsonResponse(conversationDeliveryResponseSchema, await setConversationDeliveryForViewer(context.get("viewer"), context.req.valid("param").conversationId, context.req.valid("json"))));
|
|
1032
1199
|
app.patch("/:conversationId/subscription", requireViewer, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", conversationSubscriptionBodySchema, "Invalid request body."), async (context) => jsonResponse(conversationSubscriptionResponseSchema, await setConversationSubscription(context.get("viewer"), context.req.valid("param").conversationId, context.req.valid("json"))));
|
|
1033
1200
|
app.patch("/:conversationId/title", requireViewer, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", renameConversationBodySchema, "Invalid request body."), async (context) => jsonResponse(renameConversationResponseSchema, await renameConversation(context.get("viewer"), context.req.valid("param").conversationId, context.req.valid("json"))));
|
|
1201
|
+
app.post("/:conversationId/annotations", requireViewer, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", attachObjectLinkBodySchema, "Invalid request body."), async (context) => jsonResponse(attachObjectLinkResponseSchema, await attachObjectLink(context.get("viewer"), context.req.valid("param").conversationId, context.req.valid("json").url)));
|
|
1034
1202
|
app.put("/:conversationId/read-position", requireViewer, validateRequest("param", conversationParamsSchema, "Invalid route parameters."), validateRequest("json", conversationReadPositionSchema, "Invalid request body."), async (context) => {
|
|
1035
1203
|
const viewer = context.get("viewer");
|
|
1036
1204
|
const { conversationId } = context.req.valid("param");
|
|
@@ -1091,12 +1259,15 @@ function createConversationRoutes(options) {
|
|
|
1091
1259
|
const body = context.req.valid("json");
|
|
1092
1260
|
return jsonResponse(cancelConversationPendingMessagesResponseSchema, await cancelConversationPendingMessagesForViewer(viewer, conversationId, body));
|
|
1093
1261
|
});
|
|
1094
|
-
app.get("/:conversationId/attachments/:attachmentId", validateRequest("param", conversationAttachmentParamsSchema, "Invalid route parameters."), async (context) => {
|
|
1262
|
+
app.get("/:conversationId/attachments/:attachmentId", validateRequest("param", conversationAttachmentParamsSchema, "Invalid route parameters."), validateRequest("query", conversationAttachmentQuerySchema, "Invalid query parameters."), async (context) => {
|
|
1095
1263
|
const { attachmentId, conversationId } = context.req.valid("param");
|
|
1264
|
+
const { download } = context.req.valid("query");
|
|
1096
1265
|
const viewer = context.get("viewer");
|
|
1097
1266
|
return await conversationAttachmentResponse({
|
|
1098
1267
|
attachmentId,
|
|
1099
1268
|
conversationId,
|
|
1269
|
+
download: download === true,
|
|
1270
|
+
headOnly: context.req.method === "HEAD",
|
|
1100
1271
|
range: context.req.header("range"),
|
|
1101
1272
|
storage: options.attachmentStorage,
|
|
1102
1273
|
...viewer ? { viewer } : void 0
|
|
@@ -1309,6 +1480,7 @@ async function readCodeWindows(args) {
|
|
|
1309
1480
|
/** Columns read for one code change report row. */
|
|
1310
1481
|
const codeChangeReportColumns = {
|
|
1311
1482
|
closedAt: juniorCodeChanges.closedAt,
|
|
1483
|
+
draft: juniorCodeChanges.draft,
|
|
1312
1484
|
id: juniorCodeChanges.id,
|
|
1313
1485
|
lastActivityAt: juniorCodeChanges.lastActivityAt,
|
|
1314
1486
|
mergedAt: juniorCodeChanges.mergedAt,
|
|
@@ -1392,7 +1564,7 @@ async function readPersonCodeOverview(args) {
|
|
|
1392
1564
|
const [windows, changes] = await Promise.all([readCodeWindows({
|
|
1393
1565
|
nowMs,
|
|
1394
1566
|
userId: args.userId
|
|
1395
|
-
}), db.select(codeChangeReportColumns).from(juniorCodeChanges).innerJoin(juniorCodeRepositories, eq(juniorCodeChanges.repositoryId, juniorCodeRepositories.id)).where(changeScopeFilter({ userId: args.userId })).orderBy(desc(sql`${juniorCodeChanges.state} = 'open'`), desc(juniorCodeChanges.updatedAt)).limit(PERSON_CHANGE_LIMIT)]);
|
|
1567
|
+
}), db.select(codeChangeReportColumns).from(juniorCodeChanges).innerJoin(juniorCodeRepositories, eq(juniorCodeChanges.repositoryId, juniorCodeRepositories.id)).where(changeScopeFilter({ userId: args.userId })).orderBy(desc(sql`${juniorCodeChanges.state} = 'open'`), asc(sql`CASE WHEN ${juniorCodeChanges.state} = 'open' THEN coalesce(${juniorCodeChanges.lastActivityAt}, ${juniorCodeChanges.openedAt}) END`), desc(juniorCodeChanges.updatedAt)).limit(PERSON_CHANGE_LIMIT)]);
|
|
1396
1568
|
return codePersonReportSchema.parse({
|
|
1397
1569
|
activityDays: windows.activityDays,
|
|
1398
1570
|
activityHours: windows.activityHours,
|
|
@@ -1563,6 +1735,16 @@ function createNotificationRoutes() {
|
|
|
1563
1735
|
});
|
|
1564
1736
|
return app;
|
|
1565
1737
|
}
|
|
1738
|
+
// src/api/objects/routes.ts
|
|
1739
|
+
/** Create the viewer-scoped route that resolves links to object cards. */
|
|
1740
|
+
function createObjectRoutes() {
|
|
1741
|
+
const app = new Hono();
|
|
1742
|
+
app.get("/", requireViewer, validateRequest("query", objectLinksQuerySchema, "Invalid object links."), async (context) => jsonResponse(objectLinksReportSchema, { objects: await resolveObjectLinks(context.get("viewer"), context.req.valid("query").url) }, { headers: {
|
|
1743
|
+
"cache-control": `private, max-age=${OBJECT_LINK_TTL_MS / 1e3}`,
|
|
1744
|
+
vary: "Authorization, Cookie"
|
|
1745
|
+
} }));
|
|
1746
|
+
return app;
|
|
1747
|
+
}
|
|
1566
1748
|
// src/api/conversations/reporting.ts
|
|
1567
1749
|
/** Return the dashboard label for a conversation surface. */
|
|
1568
1750
|
function surfaceLabel(surface) {
|
|
@@ -1973,6 +2155,144 @@ function createLocationRoutes() {
|
|
|
1973
2155
|
});
|
|
1974
2156
|
return app;
|
|
1975
2157
|
}
|
|
2158
|
+
// src/chat/images/fetch.ts
|
|
2159
|
+
/** The largest image that Junior fetches. */
|
|
2160
|
+
const MAX_IMAGE_BYTES = 5242880;
|
|
2161
|
+
const FETCH_TIMEOUT_MS = 5e3;
|
|
2162
|
+
/**
|
|
2163
|
+
* Fetch one image through the address guard. Accept only bytes of a known
|
|
2164
|
+
* image format.
|
|
2165
|
+
*/
|
|
2166
|
+
async function fetchImage(image) {
|
|
2167
|
+
const fetched = await guardedFetch({
|
|
2168
|
+
...image,
|
|
2169
|
+
accept: "image/*",
|
|
2170
|
+
maxBytes: MAX_IMAGE_BYTES,
|
|
2171
|
+
timeoutMs: FETCH_TIMEOUT_MS
|
|
2172
|
+
});
|
|
2173
|
+
if ("failure" in fetched) return fetched;
|
|
2174
|
+
const contentType = detectImageMediaType(fetched.bytes);
|
|
2175
|
+
return contentType ? {
|
|
2176
|
+
bytes: fetched.bytes,
|
|
2177
|
+
contentType
|
|
2178
|
+
} : { failure: "not_an_image" };
|
|
2179
|
+
}
|
|
2180
|
+
// src/chat/images/read.ts
|
|
2181
|
+
/**
|
|
2182
|
+
* Serve external images from Junior. Each source checks that the viewer may
|
|
2183
|
+
* see an image and names its address. Junior fetches the image once, scales
|
|
2184
|
+
* it to the asked width as WebP, and keeps each width in the state cache.
|
|
2185
|
+
*/
|
|
2186
|
+
const IMAGE_CACHE_TTL_MS = 864e5;
|
|
2187
|
+
const IMAGE_FAILURE_TTL_MS = 3e5;
|
|
2188
|
+
const CORE_SOURCES = {
|
|
2189
|
+
avatar: (_viewer, identityId) => readAvatarFetch(getDb(), identityId),
|
|
2190
|
+
public: async (_viewer, url) => ({ url })
|
|
2191
|
+
};
|
|
2192
|
+
function pluginSource(plugin) {
|
|
2193
|
+
const images = plugin.images;
|
|
2194
|
+
if (!images) return void 0;
|
|
2195
|
+
const name = plugin.manifest.name;
|
|
2196
|
+
return (viewer, ref) => images.resolve({
|
|
2197
|
+
cache: createPluginCache(name),
|
|
2198
|
+
db: getDb(),
|
|
2199
|
+
log: createPluginLogger(name),
|
|
2200
|
+
plugin: { name },
|
|
2201
|
+
viewer
|
|
2202
|
+
}, ref);
|
|
2203
|
+
}
|
|
2204
|
+
function findSource(source) {
|
|
2205
|
+
if (Object.hasOwn(CORE_SOURCES, source)) return CORE_SOURCES[source];
|
|
2206
|
+
const plugin = getPlugins().find((candidate) => candidate.manifest.name === source);
|
|
2207
|
+
return plugin && pluginSource(plugin);
|
|
2208
|
+
}
|
|
2209
|
+
async function scaleImage(bytes, contentType, width, host) {
|
|
2210
|
+
try {
|
|
2211
|
+
const { default: sharp } = await import("sharp");
|
|
2212
|
+
return {
|
|
2213
|
+
contentType: "image/webp",
|
|
2214
|
+
data: (await sharp(bytes).rotate().resize({
|
|
2215
|
+
width,
|
|
2216
|
+
withoutEnlargement: true
|
|
2217
|
+
}).webp({ quality: 80 }).toBuffer()).toString("base64")
|
|
2218
|
+
};
|
|
2219
|
+
} catch (error) {
|
|
2220
|
+
logWarn("image.resize.failed", {
|
|
2221
|
+
"server.address": host,
|
|
2222
|
+
"exception.message": error instanceof Error ? error.message : String(error)
|
|
2223
|
+
});
|
|
2224
|
+
return {
|
|
2225
|
+
contentType,
|
|
2226
|
+
data: bytes.toString("base64")
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Read one image at one width for a viewer. Return nothing when the source
|
|
2232
|
+
* is unknown, the viewer may not see the image, or the fetch fails.
|
|
2233
|
+
*/
|
|
2234
|
+
async function readImage(viewer, image, width) {
|
|
2235
|
+
const source = findSource(image.source);
|
|
2236
|
+
const request = source && await source(viewer, image.ref);
|
|
2237
|
+
if (!request || !URL.canParse(request.url)) return void 0;
|
|
2238
|
+
const host = new URL(request.url).hostname;
|
|
2239
|
+
const key = `image:${image.source}:${width}:${createHash("sha256").update(request.url).digest("hex")}`;
|
|
2240
|
+
return await createCache(getStateAdapter(), "core").getOrLoad(key, async () => {
|
|
2241
|
+
const fetched = await fetchImage(request);
|
|
2242
|
+
if ("failure" in fetched) {
|
|
2243
|
+
logWarn("image.fetch.failed", {
|
|
2244
|
+
"app.reason": fetched.failure,
|
|
2245
|
+
"server.address": host
|
|
2246
|
+
});
|
|
2247
|
+
return {
|
|
2248
|
+
value: null,
|
|
2249
|
+
ttlMs: IMAGE_FAILURE_TTL_MS
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
return {
|
|
2253
|
+
value: await scaleImage(fetched.bytes, fetched.contentType, width, host),
|
|
2254
|
+
ttlMs: IMAGE_CACHE_TTL_MS
|
|
2255
|
+
};
|
|
2256
|
+
}) ?? void 0;
|
|
2257
|
+
}
|
|
2258
|
+
// src/api/images/response.ts
|
|
2259
|
+
const VERSIONED_CACHE_CONTROL = "private, max-age=31536000, immutable";
|
|
2260
|
+
const UNVERSIONED_CACHE_CONTROL = "private, max-age=86400";
|
|
2261
|
+
/** Send one served image with the headers of every Junior image route. */
|
|
2262
|
+
function imageResponse(served, versioned) {
|
|
2263
|
+
return new Response(Buffer.from(served.data, "base64"), { headers: {
|
|
2264
|
+
"cache-control": versioned ? VERSIONED_CACHE_CONTROL : UNVERSIONED_CACHE_CONTROL,
|
|
2265
|
+
"content-security-policy": "default-src 'none'; sandbox",
|
|
2266
|
+
"content-type": served.contentType,
|
|
2267
|
+
vary: "Authorization, Cookie",
|
|
2268
|
+
"x-content-type-options": "nosniff"
|
|
2269
|
+
} });
|
|
2270
|
+
}
|
|
2271
|
+
// src/api/schema/image.ts
|
|
2272
|
+
/** Route parameters for one image. */
|
|
2273
|
+
const imageParamsSchema = z.object({ id: z.string().min(1).max(4e3) }).strict();
|
|
2274
|
+
/** The width of one image, from the fixed set, and its optional version. */
|
|
2275
|
+
const imageQuerySchema = z.object({
|
|
2276
|
+
v: z.string().min(1).max(64).optional(),
|
|
2277
|
+
w: z.string().transform(Number).refine((width) => IMAGE_WIDTHS.some((allowed) => allowed === width))
|
|
2278
|
+
}).strict();
|
|
2279
|
+
// src/api/images/routes.ts
|
|
2280
|
+
/**
|
|
2281
|
+
* Create the route that serves external images from Junior, so browsers
|
|
2282
|
+
* never load them from another host. The path has a signed id, never the
|
|
2283
|
+
* address of the image.
|
|
2284
|
+
*/
|
|
2285
|
+
function createImageRoutes() {
|
|
2286
|
+
const app = new Hono();
|
|
2287
|
+
app.get("/:id", requireViewer, validateRequest("param", imageParamsSchema, "Invalid route parameters."), validateRequest("query", imageQuerySchema, "Invalid image width."), async (context) => {
|
|
2288
|
+
const image = decodeImageId(context.req.valid("param").id);
|
|
2289
|
+
const { v, w } = context.req.valid("query");
|
|
2290
|
+
const served = image && await readImage(context.get("viewer"), image, w);
|
|
2291
|
+
if (!served) throwApiError(404, "Image not found.");
|
|
2292
|
+
return imageResponse(served, Boolean(v));
|
|
2293
|
+
});
|
|
2294
|
+
return app;
|
|
2295
|
+
}
|
|
1976
2296
|
// src/api/people/code.ts
|
|
1977
2297
|
/** Read person-scoped native code activity for one People profile. */
|
|
1978
2298
|
async function readPeopleCode(email) {
|
|
@@ -2405,7 +2725,7 @@ async function readPeoplePluginReports(args) {
|
|
|
2405
2725
|
reports: [],
|
|
2406
2726
|
source: "plugins"
|
|
2407
2727
|
});
|
|
2408
|
-
const { getPluginProfileReports } = await import("./projection-
|
|
2728
|
+
const { getPluginProfileReports } = await import("./projection-w_X-zi7v.js").then((n) => n.nr);
|
|
2409
2729
|
return pluginOperationalReportFeedSchema.parse({
|
|
2410
2730
|
generatedAt: new Date(nowMs).toISOString(),
|
|
2411
2731
|
reports: await getPluginProfileReports({
|
|
@@ -2655,29 +2975,17 @@ async function readPersonalSpendFromSql(email, nowMs = Date.now()) {
|
|
|
2655
2975
|
};
|
|
2656
2976
|
}
|
|
2657
2977
|
// src/api/people/routes.ts
|
|
2658
|
-
const AVATAR_IMMUTABLE_CACHE_CONTROL = "private, max-age=31536000, immutable";
|
|
2659
2978
|
/** Create the HTTP routes owned by the People API. */
|
|
2660
2979
|
function createPeopleRoutes() {
|
|
2661
2980
|
const app = new Hono();
|
|
2662
2981
|
app.get("/avatars/:identityId", requireViewer, validateRequest("param", avatarParamsSchema, "Invalid route parameters."), async (context) => {
|
|
2663
2982
|
const { identityId } = context.req.valid("param");
|
|
2664
|
-
const
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
};
|
|
2671
|
-
if (context.req.header("if-none-match") === etag) return new Response(null, {
|
|
2672
|
-
headers,
|
|
2673
|
-
status: 304
|
|
2674
|
-
});
|
|
2675
|
-
return new Response(Buffer.from(avatar.image.data, "base64"), { headers: {
|
|
2676
|
-
...headers,
|
|
2677
|
-
"content-security-policy": "default-src 'none'; sandbox",
|
|
2678
|
-
"content-type": avatar.image.contentType,
|
|
2679
|
-
"x-content-type-options": "nosniff"
|
|
2680
|
-
} });
|
|
2983
|
+
const served = await readImage(context.get("viewer"), {
|
|
2984
|
+
ref: identityId,
|
|
2985
|
+
source: "avatar"
|
|
2986
|
+
}, 128);
|
|
2987
|
+
if (!served) throwApiError(404, "Avatar not found.");
|
|
2988
|
+
return imageResponse(served, context.req.query("v") !== void 0);
|
|
2681
2989
|
});
|
|
2682
2990
|
app.get("/me/spend", requireViewer, async (context) => {
|
|
2683
2991
|
const viewer = context.get("viewer");
|
|
@@ -2775,6 +3083,10 @@ function createPersonalTokenRoutes() {
|
|
|
2775
3083
|
app.post("/", requireViewer, validateRequest("json", createPersonalTokenBodySchema, "Invalid request body."), async (context) => {
|
|
2776
3084
|
const viewer = context.get("viewer");
|
|
2777
3085
|
const body = context.req.valid("json");
|
|
3086
|
+
if (body.previewOrigin && !await previewOriginBelongsTo({
|
|
3087
|
+
email: viewer.email,
|
|
3088
|
+
origin: body.previewOrigin
|
|
3089
|
+
})) throwApiError(403, "Junior did not make this Preview for you.");
|
|
2778
3090
|
return jsonResponse(createdPersonalTokenSchema, await createPersonalToken({
|
|
2779
3091
|
email: viewer.email,
|
|
2780
3092
|
name: body.name
|
|
@@ -3434,7 +3746,7 @@ function readDescriptionText(home) {
|
|
|
3434
3746
|
}
|
|
3435
3747
|
/** Read discovered skills for runtime diagnostics and the Automation editor. */
|
|
3436
3748
|
async function readSkillReports() {
|
|
3437
|
-
const { discoverSkills } = await import("./skills-
|
|
3749
|
+
const { discoverSkills } = await import("./skills-DfsazET6.js").then((n) => n.o);
|
|
3438
3750
|
const skills = await discoverSkills();
|
|
3439
3751
|
return skillReportsSchema.parse(skills.map((skill) => ({
|
|
3440
3752
|
name: skill.name,
|
|
@@ -3448,7 +3760,7 @@ async function readSkillReports() {
|
|
|
3448
3760
|
* what the skill tells Junior. Returns null when no skill has that name.
|
|
3449
3761
|
*/
|
|
3450
3762
|
async function readSkillDetailReport(name) {
|
|
3451
|
-
const { discoverSkills, findSkillByName, parseSkillFile } = await import("./skills-
|
|
3763
|
+
const { discoverSkills, findSkillByName, parseSkillFile } = await import("./skills-DfsazET6.js").then((n) => n.o);
|
|
3452
3764
|
const skill = findSkillByName(name, await discoverSkills());
|
|
3453
3765
|
if (!skill) return null;
|
|
3454
3766
|
const parsed = parseSkillFile(await fs.readFile(path.join(skill.skillPath, "SKILL.md"), "utf8"), skill.name);
|
|
@@ -3463,7 +3775,7 @@ async function readSkillDetailReport(name) {
|
|
|
3463
3775
|
}
|
|
3464
3776
|
/** Read safe configured plugin metadata for authenticated runtime diagnostics. */
|
|
3465
3777
|
async function readPlugins() {
|
|
3466
|
-
const { pluginCatalogRuntime } = await import("./catalog-runtime-
|
|
3778
|
+
const { pluginCatalogRuntime } = await import("./catalog-runtime-D1oYNv04.js").then((n) => n.t);
|
|
3467
3779
|
return pluginsSchema.parse(pluginCatalogRuntime.getProviders().map((plugin) => ({
|
|
3468
3780
|
configKeys: plugin.manifest.configKeys ?? [],
|
|
3469
3781
|
description: plugin.manifest.description,
|
|
@@ -3475,7 +3787,7 @@ async function readPlugins() {
|
|
|
3475
3787
|
async function readRuntimeInfoReport() {
|
|
3476
3788
|
const [{ homeDir }, { pluginCatalogRuntime }, plugins, skills] = await Promise.all([
|
|
3477
3789
|
import("./package-discovery-DJhGdS4c.js").then((n) => n.r),
|
|
3478
|
-
import("./catalog-runtime-
|
|
3790
|
+
import("./catalog-runtime-D1oYNv04.js").then((n) => n.t),
|
|
3479
3791
|
readPlugins(),
|
|
3480
3792
|
readSkillReports()
|
|
3481
3793
|
]);
|
|
@@ -3492,7 +3804,7 @@ async function readRuntimeInfoReport() {
|
|
|
3492
3804
|
/** Read sanitized operational summaries contributed by plugins. */
|
|
3493
3805
|
async function readPluginOperationalReportFeed() {
|
|
3494
3806
|
const nowMs = Date.now();
|
|
3495
|
-
const { getPluginOperationalReports } = await import("./projection-
|
|
3807
|
+
const { getPluginOperationalReports } = await import("./projection-w_X-zi7v.js").then((n) => n.nr);
|
|
3496
3808
|
return pluginOperationalReportFeedSchema.parse({
|
|
3497
3809
|
source: "plugins",
|
|
3498
3810
|
generatedAt: new Date(nowMs).toISOString(),
|
|
@@ -3530,6 +3842,8 @@ function createJuniorApi(options = {}) {
|
|
|
3530
3842
|
app.route("/api/notifications", createNotificationRoutes());
|
|
3531
3843
|
app.route("/api/personal-tokens", createPersonalTokenRoutes());
|
|
3532
3844
|
app.route("/api/service-accounts", createServiceAccountRoutes());
|
|
3845
|
+
app.route("/api/images", createImageRoutes());
|
|
3846
|
+
app.route("/api/objects", createObjectRoutes());
|
|
3533
3847
|
app.route("/api/people", createPeopleRoutes());
|
|
3534
3848
|
app.route("/api/locations", createLocationRoutes());
|
|
3535
3849
|
app.route("/api/user-pages", createUserPageRoutes());
|