@sentry/junior 0.302.0 → 0.304.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/{adapter-context-Cx9fn9B3.js → adapter-context-B1IpoELr.js} +2 -2
- package/dist/{admin-_poE5NKL.js → admin-BnVFGo_z.js} +5 -5
- package/dist/{agent-runner-CY9RvsTX.js → agent-runner-CoEeZSRh.js} +1461 -1248
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +6 -6
- package/dist/api.d.ts +13 -12
- package/dist/api.js +230 -105
- package/dist/{app-BpY3wtRP.d.ts → app-Cs157Zc5.d.ts} +17 -15
- package/dist/app.d.ts +1 -1
- package/dist/app.js +108 -96
- package/dist/{automation-Cva5ZOwW.js → automation-CuA3yEcD.js} +3 -1
- package/dist/{background-compaction-queue-CXFq1_Cz.js → background-compaction-queue-WLPNSF_b.js} +6 -6
- package/dist/{briefs-B3NG-pid.js → briefs-CagVVefw.js} +12 -9
- package/dist/{catalog-runtime-Dss0lSV6.js → catalog-runtime-B8ZXvXWm.js} +2 -2
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +21 -21
- package/dist/cli/check.js +10 -10
- package/dist/cli/env.d.ts +1 -0
- package/dist/cli/env.js +8 -7
- package/dist/cli/init.js +13 -4
- package/dist/cli/main.js +4 -4
- package/dist/cli/plugins.js +6 -6
- package/dist/cli/snapshot-create.js +7 -5
- package/dist/cli/upgrade.d.ts +2 -2
- package/dist/cli/upgrade.js +6 -6
- package/dist/{config-CzeZiMKs.js → config-DdO1BNcw.js} +142 -67
- package/dist/{connections-CDYhMfrs.js → connections-D20kp0j5.js} +6 -6
- package/dist/{continue-in-slack-7Uf05ndC.js → continue-in-slack-BKEVMBj1.js} +8 -8
- package/dist/{conversation-BNXfq6Lb.js → conversation-BOqdRtUx.js} +4 -12
- package/dist/{conversation-feed-Clf_cv0n.js → conversation-feed-CgpgP7yi.js} +35 -2
- package/dist/{conversation-privacy-D9xnM5mK.js → conversation-privacy-L1SK_v0V.js} +16 -8
- package/dist/{conversation-turn-D7SEZgTG.js → conversation-turn-BptVJylj.js} +20 -23
- package/dist/{credential-sync-DoD0gW-j.js → credential-sync-D1J1CGzL.js} +19 -19
- package/dist/{db-B-gtnNjr.js → db-EKJnkrIb.js} +180 -17
- package/dist/{db-BdsCzytP.d.ts → db-zbN5ZV_o.d.ts} +26 -26
- package/dist/{executor-DZg20EqU.js → executor-CoIZmFK8.js} +55 -15
- package/dist/{history-IjdmO_r6.js → history-m2-ceTTX.js} +21 -12
- package/dist/{install-t1KQyTUs.js → install-BT2Pf6HP.js} +3 -3
- package/dist/instrumentation.d.ts +4 -4
- package/dist/instrumentation.js +15 -11
- package/dist/{lineage-C79GjoQr.js → lineage-C5DGQCS_.js} +2 -2
- package/dist/{logging-C9oDAg4M.js → logging-QSZuMcvo.js} +19 -19
- package/dist/{message-BLUCzJXN.js → message-TtxftRHj.js} +9 -9
- package/dist/{model-input-5jwNC45G.js → model-input-BHXfA29g.js} +4 -9
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +8 -8
- package/dist/{oauth-callback-server-BBl66vCb.js → oauth-callback-server-B0enqHtZ.js} +5 -4
- package/dist/{oauth-relay-DRzq73b6.js → oauth-relay-DAmfVmJu.js} +3 -6
- package/dist/{package-discovery-DJhGdS4c.js → package-discovery-x4AvVhMj.js} +1 -1
- package/dist/{plugin-module-Cf5gVPWP.js → plugin-module-Cv2ETe8Y.js} +1 -1
- package/dist/{plugins-BBX07Jzt.js → plugins-Bkk0XRo2.js} +3 -3
- package/dist/{projection-CIBwgD3s.js → projection-CNKK7doO.js} +755 -221
- package/dist/{prompt-CRQbzp5e.js → prompt-DSjhoKu5.js} +185 -12
- package/dist/{queue-DtCDaIct.js → queue-CDxkit82.js} +4 -4
- package/dist/{queue-CZyYgPF0.d.ts → queue-CbEHUO0l.d.ts} +1 -1
- package/dist/{registry-DdFQHZ_d.js → registry-DBDNUUmz.js} +37 -37
- package/dist/{resolve-CdW4BdrK.js → resolve-CQLhMWSu.js} +3 -3
- package/dist/{result-oOMv1t4O.js → result-B-pauj42.js} +10 -15
- package/dist/rolldown-runtime-BKpuH2hG.js +26 -0
- package/dist/{runner-DqitLtm-.js → runner-B3KxKks5.js} +10 -10
- package/dist/{sandbox-egress-signals-Bw9I0yfJ.js → sandbox-egress-signals-DJJX9ClG.js} +1 -1
- package/dist/{schema-DnVQepWP.js → schema-Bx0Mlo32.js} +77 -13
- package/dist/{schema-BIFM-U1a.d.ts → schema-CKcu-IK6.d.ts} +562 -23
- package/dist/{secrets-DebYU866.js → secrets-DHaJ5TTn.js} +4 -4
- package/dist/{sentry-BRTJqumy.js → sentry-CPbZjomA.js} +3 -28
- package/dist/{sentry-route-name-BhwWnfqj.js → sentry-route-name-C6EIzAGP.js} +1 -1
- package/dist/{service-account-CrZftRTb.js → service-account-2HmlNPvy.js} +49 -48
- package/dist/{service-account-B6mKAPVo.js → service-account-DQLqkSVv.js} +5 -5
- package/dist/{session-stop-DW63Z3kj.js → session-stop-DEeZKqbX.js} +132 -74
- package/dist/{skills-C16fz60Z.js → skills-2UrD7JkN.js} +6 -9
- package/dist/{slack-conversation-unfurl-BHhefEb7.js → slack-conversation-unfurl-Dd129Uov.js} +14 -18
- package/dist/{spawn-D_RnFYfy.js → spawn-eMho9HDJ.js} +7 -7
- package/dist/{legacy-web-actor-id-C-cEeWqL.js → state-Bveuc4Zh.js} +32 -32
- package/dist/{stop-7p1i08CY.js → stop-D_ltJLDS.js} +359 -171
- package/dist/{store-C28I0CVW.js → store-COeYnPL_.js} +5 -5
- package/dist/{task-queue-BVUJbQ28.js → task-queue-CBIDXZpV.js} +3 -3
- package/dist/{task-runner-CWi8j7Z6.js → task-runner-CJF7zIJL.js} +15 -18
- package/dist/{thread-context-D3-yYUd0.js → thread-context-Cg0jt0aE.js} +12 -12
- package/dist/{turn-session-routing-BFMS9ATF.js → turn-session-routing-CaY3Tp8m.js} +32 -32
- package/dist/{turn-user-message-C3-O8Omt.js → turn-user-message-tcom1RYd.js} +3 -3
- package/dist/{validation-BSFKUIb4.js → validation-EU91JwIT.js} +2 -2
- package/dist/vercel.js +1 -1
- package/dist/{version-BHHXNi-0.js → version-BYRPhY5G.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-B1SO21Qa.js → viewer-Cf8ISkAc.js} +3 -3
- package/dist/{warmup-Bz9bzkzN.js → warmup-TgY4S1vx.js} +202 -577
- package/dist/{worker-BspReIIK.js → worker-C6Uq4OKD.js} +9 -12
- package/migrations/0109_user_preferences.sql +1 -0
- package/migrations/0110_code_change_repository_state_index.sql +1 -0
- package/migrations/0111_attachment_kinds.sql +14 -0
- package/migrations/0112_attachment_url_fill.sql +51 -0
- package/migrations/0113_attachment_url_index.sql +1 -0
- package/migrations/meta/0099_snapshot.json +102 -326
- package/migrations/meta/0109_snapshot.json +4925 -0
- package/migrations/meta/0110_snapshot.json +4952 -0
- package/migrations/meta/0111_snapshot.json +5011 -0
- package/migrations/meta/0112_snapshot.json +5011 -0
- package/migrations/meta/0113_snapshot.json +5033 -0
- package/migrations/meta/_journal.json +36 -1
- package/package.json +16 -19
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as loadTurnCheckpoint, $a as workspaceRepoCheckoutPath, $i as setWorkspaceSnapshotBuild, $r as EVERYONE_ASSIGNEE, Ba as isWorkspaceSnapshotNotReadyError, Br as
|
|
3
|
-
import {
|
|
4
|
-
import { E as withSpan, G as normalizeIdentityEmail, J as toOptionalString, h as logWarn,
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
+
import { $ as loadTurnCheckpoint, $a as workspaceRepoCheckoutPath, $i as setWorkspaceSnapshotBuild, $r as EVERYONE_ASSIGNEE, Ar as dismissOpenReviewItems, Ba as isWorkspaceSnapshotNotReadyError, Br as PLUGIN_REVIEW_ITEM_KEY_PREFIX, Ca as getSlackMessagePermalink, Cn as getTerminalAssistantMessages, Cs as defaultTimezone, Dr as closeReviewItem, Fi as getDashboardTaskLink, Ga as createSandboxEgressCredentialToken, Gi as getWorkspaceByName, Gn as renderTag, H as PluginCredentialFailureError, Hi as createWorkspace, Hr as canAgentChangeReviewItem, Ja as buildSandboxEgressNetworkPolicy, Ji as updateWorkspace, Jo as readLiveAttachment, Jr as requireReviewItemAssignees, K as AuthorizationFlowDisabledError, Ki as listWorkspaces, Lo as FORK_INSTRUCTIONS, Lr as searchReviewItems, Mr as getReviewItem, Nr as insertReviewItem, Pa as isAbortError, Qi as setWorkspaceSnapshot, Ra as WorkspaceSnapshotNotReadyError, Ro as loadForkHistory, T as resolveTaskTitle, Ui as deleteWorkspace, Ur as canReadReviewItem, Vn as escapeClosingTags, Vo as matchSlackAttachments, Wi as getWorkspace, X as clearPendingAuth, Xi as invalidateReadySnapshot, Xn as getOAuthAccountProviders, Yi as WorkspaceValidationError, Yo as recordUploadedAttachment, Yr as requireReviewItemLinks, Za as SANDBOX_RUNTIME, Zi as loadSnapshotsForProfile, _a as slackMention, _i as findMatchingWatches, _o as createPluginLogger, _s as searchConversations, as as isConversationScopedChannel, at as failTurnRecord, bs as createPluginAnnotations, ci as RESOURCE_SUBSCRIPTION_MAX_TTL_MS, cn as replyTextSchema, cr as getPlugins, cs as normalizeSlackConversationId, ds as withSlackRetries, ea as create, ei as activeParticipantUserIds, eo as ToolInputError, es as SlackActionError, et as lostWorkerBeforeFirstSave, fi as cancelWatch, fn as NO_REPLY_TOOL_NAME, fs as sleep, gi as deliverWatch, hi as createWatch, ia as getSandboxProvider, in as REPLY_TOOL_NAME, is as getSlackClient, j as markConversationMessage, jr as getOpenReviewItemByDedupeKey, ki as getDashboardConversationLink, ks as createPluginCache, li as RESOURCE_WATCH_TOOL_SOURCE, lo as SANDBOX_WORKSPACE_ROOT, lr as getStaticPluginToolDefinitions, mi as createTimerWatch, mn as isLegacyNoReplyMarker, na as isStale, ni as resolveAssignee, ns as getFilePermalink, nt as saveTurnCheckpoint, oi as getSlackToolContext, on as readTurnAnswer, pn as findLegacyNoReplyMarker, qr as readReviewItemAgentScope, ri as resolveAssignees, rn as isTurnExecutionLimitExceededError, rt as abandonTurnRecord, s as openConversationProjection, si as RESOURCE_SUBSCRIPTION_DEFAULT_TTL_MS, so as SANDBOX_REPOS_ROOT, st as getTurnRecord, ti as automationCreatorUserId, tr as createPluginHookRunner, ts as downloadPrivateSlackFile, tt as pauseLostWorkerTurn, ui as STOP_WATCHING_TOOL_NAME, un as getAssistantReplyText, v as hydrateConversationMessages, vi as getWatch, vn as REPORT_BLOCKED_TOOL_NAME, vo as canAccessConversation, w as fallbackShortTitle, wa as openSlackDirectMessage, xo as readConversationAccessFromSql, yi as listWatches, ys as saveObjectAnnotations, zr as updateReviewItemContent } from "./projection-CNKK7doO.js";
|
|
3
|
+
import { $ as bufferBody, X as isProviderRetryError, _ as TURN_REASONING_LEVELS, i as getChatConfig, k as resolveGatewayModel, n as botConfig } from "./config-DdO1BNcw.js";
|
|
4
|
+
import { E as withSpan, G as normalizeIdentityEmail, J as toOptionalString, h as logWarn, m as logInfo, o as getActiveTraceContext, p as logException, x as setSpanStatus, z as getDeploymentId } from "./logging-QSZuMcvo.js";
|
|
5
|
+
import { h as startSpan, n as captureMessage, u as sentry_exports } from "./sentry-CPbZjomA.js";
|
|
6
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-B8ZXvXWm.js";
|
|
7
|
+
import { A as enqueueEventNotification, B as resolveEventMentions, C as listActiveMailboxTurns, G as conversationSubtree, I as maybePostAutomatedTurnLimitNotice, J as isExperimentalFeatureEnabled, K as conversationSubtreeColumns, M as isEventMailboxMetadata, Q as requireSlackChannelMessageScope, S as listActiveMailboxTurnSources, U as recordFinishedTurnForAutomatedLimit, W as resetAutomatedTurnLimit, X as getEventCatalog, at as workspaceSnapshotFinishedEvent, b as getAuthPausedConversationTurnId, f as buildSteeringPiMessage, g as withoutSavedSteeringMessages, i as resumeStoppedConversationTree, it as WORKSPACE_SNAPSHOT_READY_EVENT, k as EVENT_WAIT_MS, m as instructionForInputs, n as isSkippedAfterConversationStop, nt as slackChannelMessageTrigger, ot as workspaceSnapshotWatch, r as markConversationsStopped, rt as WORKSPACE_SNAPSHOT_FAILED_EVENT, st as buildDeploymentSystemPrompt, t as getConversationStoppedAtMs, v as saveUserCustomization, y as addConversationNote } from "./session-stop-DEeZKqbX.js";
|
|
8
|
+
import { A as agentTypeSchema, H as removedCardSchema, O as AGENT_TYPES, X as briefLinkSchema, Z as briefOutcomeStatusSchema, j as formatAgentTypes, k as agentTypeInstructions } from "./conversation-BOqdRtUx.js";
|
|
9
|
+
import { A as eventAutomationTriggerSchema, F as compileScheduleIntent, H as automationTaskSchema, L as toolScheduleIntentSchema, P as ScheduleIntentError, R as weekdaySchema, U as automationTaskText, V as automationTaskDescription, l as automationListQuerySchema, z as automationSkillNameSchema } from "./automation-CuA3yEcD.js";
|
|
5
10
|
import { d as parseSlackChannelReferenceId, f as parseSlackTeamId, o as isUserActor, p as parseSlackUserId, u as parseSlackChannelId, v as parseSlackMessageTs } from "./actor-D2iXzvlN.js";
|
|
6
|
-
import {
|
|
7
|
-
import { A as
|
|
8
|
-
import {
|
|
9
|
-
import { f as credentialContextForActor, p as credentialContextSchema } from "./registry-DdFQHZ_d.js";
|
|
10
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-Dss0lSV6.js";
|
|
11
|
-
import { t as discoverSkills } from "./skills-C16fz60Z.js";
|
|
12
|
-
import { r as EVENT_AUTHOR_ID, u as completeText } from "./prompt-CRQbzp5e.js";
|
|
11
|
+
import { A as conversationKindFromRow, E as isTopLevelKind, I as resolveActorIdentityId, O as promptModeTurnTools, P as SYSTEM_IDENTITY_ID, T as isPersonInput, X as getStateAdapter, _ as readConversationTrees, a as getConversationStore, dt as resolveRootConversationId, ft as rootConversationIsArchived, g as conversationDescendants, h as conversationAncestors, i as getConversationMessageSearchStore, k as turnBehavior, mt as nextDetailVersion, nt as withLock, o as getDb, r as getConversationEventStore, s as getSqlExecutor, tt as fenceLock, v as setArchivedAt, x as userMessageQueries, yt as sameDestination } from "./db-EKJnkrIb.js";
|
|
12
|
+
import { $ as deleteEventAutomation, A as readAutomationExecutionStatusDays, Ct as hasEventCatalogEntries, D as emptyAutomationRunWindows, Dt as registeredResourceTypeSchema, Et as registeredEventTypeSchema, H as deleteScheduledAutomation, K as saveScheduledAutomation, M as readAutomationExecutionSummaries, N as readAutomationExecutions, Ot as requireEventIdentifier, P as readAutomationRuns, St as eventWatchUnavailable, Tt as registeredEventTriggerProblems, W as parseScheduledAutomationRow, _t as automationEventCatalog, a as getPersistedThreadState, at as setEventAutomationStatus, c as coerceThreadConversationState, ct as automationDefinition, dt as readAutomationVersion, ft as sameDefinitionValue, g as getDispatchRecord, h as getDispatchInputMessageId, ht as requireAutomationRevision, i as getPersistedSandboxState, it as saveEventAutomation, j as readAutomationExecutionStatusHours, k as readAutomationExecutionByConversationId, kt as requireValidEventTrigger, m as getDispatchIdForConversation, mt as automationRevision, n as resolveTurnSessionRouting, nt as listDeletedEventAutomationsCreatedBy, rt as parseEventAutomationRow, s as persistThreadStateById, ut as listAutomationVersions, vt as describeRegisteredEventTrigger, wt as registeredEventMatchSchema, xt as eventNamespaceSchema } from "./turn-session-routing-CaY3Tp8m.js";
|
|
13
|
+
import { A as juniorAttachmentUploads, F as juniorUsers, I as juniorDestinations, N as juniorConversations, P as juniorIdentities, T as juniorConversationEvents, _ as juniorConversationReadPositions, f as juniorAutomations, g as juniorAgentInvocations, h as juniorAgentBindings, j as juniorAttachments, p as juniorStats, u as juniorAutomationRuns, v as juniorConversationParticipants } from "./executor-CoIZmFK8.js";
|
|
13
14
|
import { i as getFirstRunAtMs, o as getZonedDateTimeParts, s as isValidTimeZone } from "./schedule-cP0AACm1.js";
|
|
14
|
-
import {
|
|
15
|
-
import { A as agentTypeInstructions, M as formatAgentTypes, Q as briefOutcomeStatusSchema, U as removedCardSchema, Z as briefLinkSchema, j as agentTypeSchema, k as AGENT_TYPES } from "./conversation-BNXfq6Lb.js";
|
|
16
|
-
import { A as enqueueEventNotification, B as resolveEventMentions, C as listActiveMailboxTurns, G as conversationSubtree, I as maybePostAutomatedTurnLimitNotice, J as isExperimentalFeatureEnabled, K as conversationSubtreeColumns, M as isEventMailboxMetadata, Q as requireSlackChannelMessageScope, S as listActiveMailboxTurnSources, U as recordFinishedTurnForAutomatedLimit, W as resetAutomatedTurnLimit, X as getEventCatalog, at as workspaceSnapshotFinishedEvent, b as getAuthPausedConversationTurnId, f as buildSteeringPiMessage, g as withoutSavedSteeringMessages, i as resumeStoppedConversationTree, it as WORKSPACE_SNAPSHOT_READY_EVENT, k as EVENT_WAIT_MS, m as instructionForInputs, n as isSkippedAfterConversationStop, nt as slackChannelMessageTrigger, ot as workspaceSnapshotWatch, r as markConversationsStopped, rt as WORKSPACE_SNAPSHOT_FAILED_EVENT, st as buildDeploymentSystemPrompt, t as getConversationStoppedAtMs, v as saveUserCustomization, y as addConversationNote } from "./session-stop-DW63Z3kj.js";
|
|
17
|
-
import { A as eventAutomationTriggerSchema, F as compileScheduleIntent, H as automationTaskSchema, L as toolScheduleIntentSchema, P as ScheduleIntentError, R as weekdaySchema, U as automationTaskText, V as automationTaskDescription, l as automationListQuerySchema, z as automationSkillNameSchema } from "./automation-Cva5ZOwW.js";
|
|
18
|
-
import { $ as deleteEventAutomation, A as readAutomationExecutionStatusDays, Ct as hasEventCatalogEntries, D as emptyAutomationRunWindows, Dt as registeredResourceTypeSchema, Et as registeredEventTypeSchema, H as deleteScheduledAutomation, K as saveScheduledAutomation, M as readAutomationExecutionSummaries, N as readAutomationExecutions, Ot as requireEventIdentifier, P as readAutomationRuns, St as eventWatchUnavailable, Tt as registeredEventTriggerProblems, W as parseScheduledAutomationRow, _t as automationEventCatalog, a as getPersistedThreadState, at as setEventAutomationStatus, c as coerceThreadConversationState, ct as automationDefinition, dt as readAutomationVersion, ft as sameDefinitionValue, g as getDispatchRecord, h as getDispatchInputMessageId, ht as requireAutomationRevision, i as getPersistedSandboxState, it as saveEventAutomation, j as readAutomationExecutionStatusHours, k as readAutomationExecutionByConversationId, kt as requireValidEventTrigger, m as getDispatchIdForConversation, mt as automationRevision, n as resolveTurnSessionRouting, nt as listDeletedEventAutomationsCreatedBy, rt as parseEventAutomationRow, s as persistThreadStateById, ut as listAutomationVersions, vt as describeRegisteredEventTrigger, wt as registeredEventMatchSchema, xt as eventNamespaceSchema } from "./turn-session-routing-BFMS9ATF.js";
|
|
15
|
+
import { t as discoverSkills } from "./skills-2UrD7JkN.js";
|
|
19
16
|
import { M as sumUtcHoursIntoSixHours, T as apiErrorSchema, c as formatUserInputAnswer, d as userInputRequestSchema, g as USER_CUSTOMIZATION_MAX_CHARS, h as isVisionImageMediaType, m as detectImageMediaType, n as AGENT_INVOCATION_MAILBOX_STATUSES, r as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, t as webMessageId, v as userCustomizationTextSchema, w as isAgentInvocationResultEventType, x as AGENT_PARENT_MESSAGE_EVENT_TYPE, y as AGENT_INVOCATION_EVENT_NAMESPACE } from "./web-message-id-lNodcCOI.js";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { D as stopConversationWork, _ as getConversationWorkState, h as ensureConversationWake, m as dropPendingMessages, n as appendAndEnqueueExclusiveInboundMessage, r as appendAndEnqueueInboundMessage, v as getConversationWorkStates, w as requestConversationWork } from "./store-
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
17
|
+
import { f as identityAvatarUrl, h as readUserAvatarUrls } from "./viewer-Cf8ISkAc.js";
|
|
18
|
+
import { A as getAgentInvocationResultMessageId, C as ownAgentInvocation, I as getUnnamedAgentConversationId, N as getChildAgentLockName, O as getAgentInvocationIdForResult, P as getNamedAgentConversationId, R as buildDeterministicTurnId, S as listChildMessages, T as getAgentInvocationId, _ as ConversationTurnLifecycleService, b as hasAgentInvocationReply, d as isTurnInputCommitLostError, j as getAgentInvocationTurnId, k as getAgentInvocationMessageId, l as getConversationTurnBoundaryError, p as markTurnClosed, s as TurnInputCommitLostError, t as getTurnUserMessage, w as readChildMessageSender } from "./turn-user-message-tcom1RYd.js";
|
|
19
|
+
import { D as stopConversationWork, _ as getConversationWorkState, h as ensureConversationWake, m as dropPendingMessages, n as appendAndEnqueueExclusiveInboundMessage, r as appendAndEnqueueInboundMessage, v as getConversationWorkStates, w as requestConversationWork } from "./store-COeYnPL_.js";
|
|
20
|
+
import { d as contextProvenance, m as sameActorIdentity, t as KNOWN_CONVERSATION_EVENT_TYPES, u as agentInstructionProvenance } from "./history-m2-ceTTX.js";
|
|
21
|
+
import { f as credentialContextForActor, p as credentialContextSchema } from "./registry-DBDNUUmz.js";
|
|
22
|
+
import { o as getVercelConversationWorkQueue, p as getTurnRequestDeadline } from "./background-compaction-queue-WLPNSF_b.js";
|
|
23
|
+
import { p as searchWeb, r as EVENT_AUTHOR_ID, u as completeText } from "./prompt-DSjhoKu5.js";
|
|
24
|
+
import { n as postinstall, o as getSandboxResources, t as dependencies } from "./install-BT2Pf6HP.js";
|
|
25
|
+
import { a as sendCacheWarmup, c as sendWorkspaceSnapshotJob, s as sendNextWorkspaceSnapshotJob } from "./queue-CDxkit82.js";
|
|
25
26
|
import * as z from "zod";
|
|
26
27
|
import { streamSimple } from "@earendil-works/pi-ai/compat";
|
|
27
|
-
import { createGatewayProvider } from "@ai-sdk/gateway";
|
|
28
|
-
import { generateText } from "ai";
|
|
29
28
|
import path from "node:path";
|
|
30
29
|
import { isDeepStrictEqual, promisify } from "node:util";
|
|
31
30
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -41,7 +40,7 @@ import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
|
41
40
|
import { structuredPatch } from "diff";
|
|
42
41
|
import { HTTPException } from "hono/http-exception";
|
|
43
42
|
import https from "node:https";
|
|
44
|
-
import { constants, zstdCompress, zstdDecompress } from "node:zlib";
|
|
43
|
+
import { constants, zstdCompress as zstdCompress$1, zstdDecompress as zstdDecompress$1 } from "node:zlib";
|
|
45
44
|
// src/chat/cache-warming/model.ts
|
|
46
45
|
/**
|
|
47
46
|
* Cost model for prompt cache warming.
|
|
@@ -75,7 +74,7 @@ const GAP_BIN_EDGES_MS = [
|
|
|
75
74
|
90 * MINUTE_MS$1,
|
|
76
75
|
120 * MINUTE_MS$1,
|
|
77
76
|
240 * MINUTE_MS$1,
|
|
78
|
-
|
|
77
|
+
1e400
|
|
79
78
|
];
|
|
80
79
|
const GAP_BIN_COUNT = GAP_BIN_EDGES_MS.length;
|
|
81
80
|
/**
|
|
@@ -383,29 +382,56 @@ function viewerAutomationCollection(viewer) {
|
|
|
383
382
|
task: sql`${automation.record}->'task'`.as("task")
|
|
384
383
|
}).from(automation).leftJoin(destination, and(eq(destination.provider, "slack"), eq(destination.providerTenantId, automation.teamId), eq(destination.providerDestinationId, automation.channelId))).where(and(ne(automation.status, "deleted"), or(owned, sharedToViewer))).as("accessible_automations");
|
|
385
384
|
}
|
|
385
|
+
function eventTriggerAvailable(catalog, trigger) {
|
|
386
|
+
const parsed = eventAutomationTriggerSchema.safeParse(trigger);
|
|
387
|
+
return parsed.success && registeredEventTriggerProblems(catalog, parsed.data).length === 0;
|
|
388
|
+
}
|
|
386
389
|
/**
|
|
387
390
|
* List the accessible event automations whose trigger cannot work with the
|
|
388
|
-
* enabled plugins.
|
|
389
|
-
* tools and the dashboard use, so SQL does not keep its own copy of the rules.
|
|
391
|
+
* enabled plugins.
|
|
390
392
|
*/
|
|
391
393
|
async function unavailableEventAutomationIds(collection) {
|
|
392
394
|
const catalog = automationEventCatalog(getEventCatalog());
|
|
393
395
|
return (await getDb().select({
|
|
394
396
|
id: collection.id,
|
|
395
397
|
trigger: collection.trigger
|
|
396
|
-
}).from(collection).where(eq(collection.kind, "event"))).flatMap((row) =>
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
}).from(collection).where(eq(collection.kind, "event"))).flatMap((row) => eventTriggerAvailable(catalog, row.trigger) ? [] : [row.id]);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Build the filters for Automations whose trigger cannot work and for those
|
|
402
|
+
* that need attention: blocked, an unavailable trigger, or a last run that
|
|
403
|
+
* failed or blocked. Paused and completed Automations never need attention.
|
|
404
|
+
*/
|
|
405
|
+
async function attentionFilters(collection) {
|
|
406
|
+
const unavailableIds = await unavailableEventAutomationIds(collection);
|
|
407
|
+
const unavailable = unavailableIds.length > 0 ? inArray(collection.id, unavailableIds) : sql`false`;
|
|
408
|
+
return {
|
|
409
|
+
attention: and(notInArray(collection.state, ["paused", "completed"]), or(eq(collection.state, "blocked"), unavailable, eq(collection.lastRunNeedsAttention, true))),
|
|
410
|
+
unavailable
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Count the viewer's own Automations that need attention, the rows that the
|
|
415
|
+
* Inbox lists from `scope=attention&owner=me`. One query reads the owned
|
|
416
|
+
* candidates, and the trigger check runs on the event ones.
|
|
417
|
+
*/
|
|
418
|
+
async function countOwnedAutomationsNeedingAttention(viewer) {
|
|
419
|
+
const collection = viewerAutomationCollection(viewer);
|
|
420
|
+
const rows = await getDb().select({
|
|
421
|
+
kind: collection.kind,
|
|
422
|
+
lastRunNeedsAttention: collection.lastRunNeedsAttention,
|
|
423
|
+
state: collection.state,
|
|
424
|
+
trigger: collection.trigger
|
|
425
|
+
}).from(collection).where(and(eq(collection.owned, true), notInArray(collection.state, ["paused", "completed"]), or(eq(collection.state, "blocked"), eq(collection.kind, "event"), eq(collection.lastRunNeedsAttention, true))));
|
|
426
|
+
const catalog = automationEventCatalog(getEventCatalog());
|
|
427
|
+
return rows.filter((row) => row.state === "blocked" || row.lastRunNeedsAttention || row.kind === "event" && !eventTriggerAvailable(catalog, row.trigger)).length;
|
|
400
428
|
}
|
|
401
429
|
/** Read an SQL page and complete, access-scoped counts and filter options. */
|
|
402
430
|
async function readAutomationCollection(viewer, input) {
|
|
403
431
|
const db = getDb();
|
|
404
432
|
const collection = viewerAutomationCollection(viewer);
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
const attention = and(notInArray(collection.state, ["paused", "completed"]), or(eq(collection.state, "blocked"), unavailable, eq(collection.lastRunNeedsAttention, true)));
|
|
408
|
-
const where = and(input.scope === "mine" ? eq(collection.owned, true) : input.scope === "public" ? eq(collection.isPublic, true) : input.scope === "attention" ? attention : void 0, input.type === "all" ? void 0 : eq(collection.kind, input.type), input.state === "all" ? void 0 : input.state === "unavailable" ? unavailable : eq(collection.state, input.state), input.creator ? eq(collection.creator, input.creator) : void 0, input.destination ? eq(collection.destination, input.destination) : void 0, input.skill ? eq(collection.skill, input.skill) : void 0, input.q ? sql`(strpos(lower(concat_ws(' ', ${collection.title}, ${collection.instruction}, ${collection.skill}, ${collection.resource})), ${input.q.toLowerCase()}) > 0 or strpos(${input.q.toLowerCase()}, lower(${collection.id})) > 0)` : void 0);
|
|
433
|
+
const { attention, unavailable } = await attentionFilters(collection);
|
|
434
|
+
const where = and(input.scope === "mine" ? eq(collection.owned, true) : input.scope === "public" ? eq(collection.isPublic, true) : input.scope === "attention" ? attention : void 0, input.type === "all" ? void 0 : eq(collection.kind, input.type), input.state === "all" ? void 0 : input.state === "unavailable" ? unavailable : eq(collection.state, input.state), input.creator ? eq(collection.creator, input.creator) : void 0, input.owner === "me" ? eq(collection.owned, true) : void 0, input.destination ? eq(collection.destination, input.destination) : void 0, input.skill ? eq(collection.skill, input.skill) : void 0, input.q ? sql`(strpos(lower(concat_ws(' ', ${collection.title}, ${collection.instruction}, ${collection.skill}, ${collection.resource})), ${input.q.toLowerCase()}) > 0 or strpos(${input.q.toLowerCase()}, lower(${collection.id})) > 0)` : void 0);
|
|
409
435
|
const [totals, counts, creators, destinations] = await Promise.all([
|
|
410
436
|
db.select({ total: count() }).from(collection).where(where),
|
|
411
437
|
db.select({
|
|
@@ -1879,11 +1905,11 @@ function isRecord(value) {
|
|
|
1879
1905
|
}
|
|
1880
1906
|
/** Bind continuation metadata to the exposed runtime tool name. */
|
|
1881
1907
|
function injectContinuationToolName(details, toolName) {
|
|
1882
|
-
if (!isRecord(details) || !isRecord(details
|
|
1908
|
+
if (!isRecord(details) || !isRecord(details["continuation"])) return details;
|
|
1883
1909
|
return {
|
|
1884
1910
|
...details,
|
|
1885
1911
|
continuation: juniorToolBoundContinuationSchema.parse({
|
|
1886
|
-
...details
|
|
1912
|
+
...details["continuation"],
|
|
1887
1913
|
tool_name: toolName
|
|
1888
1914
|
})
|
|
1889
1915
|
};
|
|
@@ -2585,32 +2611,32 @@ function firstChangedLine(oldLines, newLines) {
|
|
|
2585
2611
|
function prepareTextReplacementArguments(input) {
|
|
2586
2612
|
if (!input || typeof input !== "object") return input;
|
|
2587
2613
|
const raw = { ...input };
|
|
2588
|
-
if (typeof raw
|
|
2589
|
-
raw
|
|
2614
|
+
if (typeof raw["edits"] === "string") try {
|
|
2615
|
+
raw["edits"] = JSON.parse(raw["edits"]);
|
|
2590
2616
|
} catch {
|
|
2591
2617
|
return raw;
|
|
2592
2618
|
}
|
|
2593
|
-
const edits = Array.isArray(raw
|
|
2594
|
-
const oldText = raw
|
|
2595
|
-
const newText = raw
|
|
2619
|
+
const edits = Array.isArray(raw["edits"]) ? Array.from(raw["edits"]) : [];
|
|
2620
|
+
const oldText = raw["old_text"] ?? raw["oldText"];
|
|
2621
|
+
const newText = raw["new_text"] ?? raw["newText"];
|
|
2596
2622
|
if (typeof oldText === "string" && typeof newText === "string") edits.push({
|
|
2597
2623
|
old_text: oldText,
|
|
2598
2624
|
new_text: newText
|
|
2599
2625
|
});
|
|
2600
|
-
if (edits.length > 0) raw
|
|
2626
|
+
if (edits.length > 0) raw["edits"] = edits.map((edit) => {
|
|
2601
2627
|
if (!edit || typeof edit !== "object") return edit;
|
|
2602
2628
|
const record = edit;
|
|
2603
2629
|
const { oldText, newText, ...rest } = record;
|
|
2604
2630
|
return {
|
|
2605
2631
|
...rest,
|
|
2606
|
-
old_text: record
|
|
2607
|
-
new_text: record
|
|
2632
|
+
old_text: record["old_text"] ?? oldText,
|
|
2633
|
+
new_text: record["new_text"] ?? newText
|
|
2608
2634
|
};
|
|
2609
2635
|
});
|
|
2610
|
-
delete raw
|
|
2611
|
-
delete raw
|
|
2612
|
-
delete raw
|
|
2613
|
-
delete raw
|
|
2636
|
+
delete raw["oldText"];
|
|
2637
|
+
delete raw["old_text"];
|
|
2638
|
+
delete raw["newText"];
|
|
2639
|
+
delete raw["new_text"];
|
|
2614
2640
|
return raw;
|
|
2615
2641
|
}
|
|
2616
2642
|
/** Build a small line-oriented diff that gives agents enough context to review edits. */
|
|
@@ -3261,10 +3287,6 @@ function parseSlackThreadId(threadId) {
|
|
|
3261
3287
|
threadTs
|
|
3262
3288
|
};
|
|
3263
3289
|
}
|
|
3264
|
-
/** Resolve the Slack channel ID from a `slack:<channel>:<ts>` thread identifier. */
|
|
3265
|
-
function resolveSlackChannelIdFromThreadId(threadId) {
|
|
3266
|
-
return parseSlackThreadId(threadId)?.channelId;
|
|
3267
|
-
}
|
|
3268
3290
|
/** Best-effort channel ID extraction from a raw Slack message payload. */
|
|
3269
3291
|
function resolveSlackChannelIdFromMessage(message) {
|
|
3270
3292
|
const messageChannelId = parseSlackChannelId(message.channelId);
|
|
@@ -3274,7 +3296,6 @@ function resolveSlackChannelIdFromMessage(message) {
|
|
|
3274
3296
|
const rawChannel = parseSlackChannelId(raw.channel);
|
|
3275
3297
|
if (rawChannel) return rawChannel;
|
|
3276
3298
|
}
|
|
3277
|
-
return resolveSlackChannelIdFromThreadId(toTrimmedSlackString(message.threadId));
|
|
3278
3299
|
}
|
|
3279
3300
|
// src/chat/slack/timestamp-param.ts
|
|
3280
3301
|
/** Define a model-facing Slack timestamp, normalizing numeric model args to strings. */
|
|
@@ -4339,7 +4360,7 @@ function toText(value) {
|
|
|
4339
4360
|
function readText(value) {
|
|
4340
4361
|
if (typeof value === "string") return toText(value);
|
|
4341
4362
|
if (!value || typeof value !== "object") return void 0;
|
|
4342
|
-
return toText(value
|
|
4363
|
+
return toText(value["text"]);
|
|
4343
4364
|
}
|
|
4344
4365
|
function parseChildren(value, budget, depth) {
|
|
4345
4366
|
if (Array.isArray(value)) return value.slice(0, MAX_CHILDREN).flatMap((child) => parseChildren(child, budget, depth));
|
|
@@ -4349,49 +4370,49 @@ function parseElement(value, budget, depth) {
|
|
|
4349
4370
|
if (!value || typeof value !== "object" || depth > MAX_DEPTH || budget.remainingNodes <= 0) return [];
|
|
4350
4371
|
budget.remainingNodes -= 1;
|
|
4351
4372
|
const element = value;
|
|
4352
|
-
const type = toText(element
|
|
4353
|
-
const text = readText(element
|
|
4373
|
+
const type = toText(element["type"]);
|
|
4374
|
+
const text = readText(element["text"]);
|
|
4354
4375
|
if (type === "link") {
|
|
4355
|
-
const url = toText(element
|
|
4376
|
+
const url = toText(element["url"]);
|
|
4356
4377
|
return [text && url && text !== url ? `${text} (${url})` : text || url].filter((part) => Boolean(part));
|
|
4357
4378
|
}
|
|
4358
4379
|
if (type === "button") {
|
|
4359
|
-
const url = toText(element
|
|
4380
|
+
const url = toText(element["url"]);
|
|
4360
4381
|
return [text && url ? `${text} (${url})` : text].filter((part) => Boolean(part));
|
|
4361
4382
|
}
|
|
4362
4383
|
if (type === "emoji") {
|
|
4363
|
-
const name = toText(element
|
|
4384
|
+
const name = toText(element["name"]);
|
|
4364
4385
|
return name ? [`:${name}:`] : [];
|
|
4365
4386
|
}
|
|
4366
4387
|
if (type === "user") {
|
|
4367
|
-
const userId = toText(element
|
|
4388
|
+
const userId = toText(element["user_id"]);
|
|
4368
4389
|
return userId ? [`<@${userId}>`] : [];
|
|
4369
4390
|
}
|
|
4370
4391
|
if (type === "channel") {
|
|
4371
|
-
const channelId = toText(element
|
|
4392
|
+
const channelId = toText(element["channel_id"]);
|
|
4372
4393
|
return channelId ? [`<#${channelId}>`] : [];
|
|
4373
4394
|
}
|
|
4374
4395
|
if (type === "usergroup") {
|
|
4375
|
-
const usergroupId = toText(element
|
|
4396
|
+
const usergroupId = toText(element["usergroup_id"]);
|
|
4376
4397
|
return usergroupId ? [`<!subteam^${usergroupId}>`] : [];
|
|
4377
4398
|
}
|
|
4378
4399
|
if (type === "broadcast") {
|
|
4379
|
-
const range = toText(element
|
|
4400
|
+
const range = toText(element["range"]);
|
|
4380
4401
|
return range ? [`<!${range}>`] : [];
|
|
4381
4402
|
}
|
|
4382
4403
|
const parts = [
|
|
4383
4404
|
text,
|
|
4384
|
-
readText(element
|
|
4385
|
-
readText(element
|
|
4386
|
-
readText(element
|
|
4387
|
-
readText(element
|
|
4388
|
-
readText(element
|
|
4389
|
-
toText(element
|
|
4390
|
-
toText(element
|
|
4391
|
-
toText(element
|
|
4405
|
+
readText(element["title"]),
|
|
4406
|
+
readText(element["description"]),
|
|
4407
|
+
readText(element["label"]),
|
|
4408
|
+
readText(element["hint"]),
|
|
4409
|
+
readText(element["placeholder"]),
|
|
4410
|
+
toText(element["alt_text"]),
|
|
4411
|
+
toText(element["provider_name"]),
|
|
4412
|
+
toText(element["fallback"])
|
|
4392
4413
|
].filter((part) => Boolean(part));
|
|
4393
4414
|
for (const key of CHILD_KEYS) parts.push(...parseChildren(element[key], budget, depth + 1));
|
|
4394
|
-
if (type === "checkboxes" || type === "radio_buttons") parts.push(...parseChildren(element
|
|
4415
|
+
if (type === "checkboxes" || type === "radio_buttons") parts.push(...parseChildren(element["options"], budget, depth + 1));
|
|
4395
4416
|
return parts;
|
|
4396
4417
|
}
|
|
4397
4418
|
/** Render visible block text without exposing hidden interaction data. */
|
|
@@ -4414,15 +4435,15 @@ function toNum(value) {
|
|
|
4414
4435
|
function toFileRef(raw) {
|
|
4415
4436
|
if (!raw || typeof raw !== "object") return void 0;
|
|
4416
4437
|
const obj = raw;
|
|
4417
|
-
const id = toStr(obj
|
|
4438
|
+
const id = toStr(obj["id"]);
|
|
4418
4439
|
if (!id) return void 0;
|
|
4419
4440
|
return {
|
|
4420
4441
|
id,
|
|
4421
|
-
name: toStr(obj
|
|
4422
|
-
mimetype: toStr(obj
|
|
4423
|
-
size: toNum(obj
|
|
4424
|
-
url_private: toStr(obj
|
|
4425
|
-
url_private_download: toStr(obj
|
|
4442
|
+
name: toStr(obj["name"]),
|
|
4443
|
+
mimetype: toStr(obj["mimetype"]),
|
|
4444
|
+
size: toNum(obj["size"]),
|
|
4445
|
+
url_private: toStr(obj["url_private"]),
|
|
4446
|
+
url_private_download: toStr(obj["url_private_download"])
|
|
4426
4447
|
};
|
|
4427
4448
|
}
|
|
4428
4449
|
/**
|
|
@@ -4437,7 +4458,7 @@ function extractAttachmentFiles(input) {
|
|
|
4437
4458
|
const seen = /* @__PURE__ */ new Set();
|
|
4438
4459
|
for (const attachment of getAttachmentPayload(input)) {
|
|
4439
4460
|
if (!attachment || typeof attachment !== "object") continue;
|
|
4440
|
-
const rawFiles = attachment
|
|
4461
|
+
const rawFiles = attachment["files"];
|
|
4441
4462
|
if (!Array.isArray(rawFiles)) continue;
|
|
4442
4463
|
for (const rawFile of rawFiles) {
|
|
4443
4464
|
const fileRef = toFileRef(rawFile);
|
|
@@ -4451,14 +4472,14 @@ function extractAttachmentFiles(input) {
|
|
|
4451
4472
|
function getAttachmentPayload(input) {
|
|
4452
4473
|
if (Array.isArray(input)) return input;
|
|
4453
4474
|
if (!input || typeof input !== "object") return [];
|
|
4454
|
-
const attachments = input
|
|
4475
|
+
const attachments = input["attachments"];
|
|
4455
4476
|
return Array.isArray(attachments) ? attachments : [];
|
|
4456
4477
|
}
|
|
4457
4478
|
function renderField(raw) {
|
|
4458
4479
|
if (!raw || typeof raw !== "object") return void 0;
|
|
4459
4480
|
const obj = raw;
|
|
4460
|
-
const title = toStr(obj
|
|
4461
|
-
const value = toStr(obj
|
|
4481
|
+
const title = toStr(obj["title"]);
|
|
4482
|
+
const value = toStr(obj["value"])?.slice(0, MAX_FIELD_CHARS);
|
|
4462
4483
|
if (title && value) return `${title}: ${value}`;
|
|
4463
4484
|
return title || value;
|
|
4464
4485
|
}
|
|
@@ -4470,15 +4491,15 @@ function renderAttachment(raw) {
|
|
|
4470
4491
|
const obj = raw;
|
|
4471
4492
|
const parts = [];
|
|
4472
4493
|
const seen = /* @__PURE__ */ new Set();
|
|
4473
|
-
const fallback = toStr(obj
|
|
4474
|
-
const pretext = toStr(obj
|
|
4475
|
-
const authorName = toStr(obj
|
|
4476
|
-
const title = toStr(obj
|
|
4477
|
-
const titleLink = toStr(obj
|
|
4478
|
-
const text = toStr(obj
|
|
4479
|
-
const footer = toStr(obj
|
|
4480
|
-
const fields = Array.isArray(obj
|
|
4481
|
-
const blockText = renderBlockText(obj
|
|
4494
|
+
const fallback = toStr(obj["fallback"]);
|
|
4495
|
+
const pretext = toStr(obj["pretext"]);
|
|
4496
|
+
const authorName = toStr(obj["author_name"]);
|
|
4497
|
+
const title = toStr(obj["title"]);
|
|
4498
|
+
const titleLink = toStr(obj["title_link"]);
|
|
4499
|
+
const text = toStr(obj["text"]);
|
|
4500
|
+
const footer = toStr(obj["footer"]);
|
|
4501
|
+
const fields = Array.isArray(obj["fields"]) ? obj["fields"] : [];
|
|
4502
|
+
const blockText = renderBlockText(obj["blocks"]);
|
|
4482
4503
|
const add = (value) => {
|
|
4483
4504
|
if (!value) return;
|
|
4484
4505
|
const normalized = normalizeAttachmentText(value);
|
|
@@ -4852,7 +4873,7 @@ function createSetConversationSubscriptionTool(context) {
|
|
|
4852
4873
|
...setConversationSubscriptionToolDefinition,
|
|
4853
4874
|
async execute(input) {
|
|
4854
4875
|
const user = (await context.resolveActorIdentity?.())?.user;
|
|
4855
|
-
if (!user) throw new ToolInputError("This person has no linked
|
|
4876
|
+
if (!user) throw new ToolInputError("This person has no linked User, so their subscription cannot change.");
|
|
4856
4877
|
const result = await updateConversationSubscription(user, context.conversationId, input.subscribed);
|
|
4857
4878
|
if (!result) throw new ToolInputError("This person is not a participant of this conversation.");
|
|
4858
4879
|
return {
|
|
@@ -5390,8 +5411,9 @@ var AgentMessagePausedError = class extends Error {
|
|
|
5390
5411
|
}
|
|
5391
5412
|
};
|
|
5392
5413
|
/**
|
|
5393
|
-
* Cap the non-terminal
|
|
5394
|
-
* runs. Each message to a busy child queues one more.
|
|
5414
|
+
* Cap the non-terminal Agent invocations of one child, including the one that
|
|
5415
|
+
* runs. Each message to a busy child with a row queues one more. A child with
|
|
5416
|
+
* no row has no cap: its parent messages wait in its mailbox like any input.
|
|
5395
5417
|
*/
|
|
5396
5418
|
const MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD = 4;
|
|
5397
5419
|
/**
|
|
@@ -5562,12 +5584,13 @@ async function createAgentInvocationForMessage(input, nowMs = Date.now()) {
|
|
|
5562
5584
|
const agentConfig = latest ?? await readAgentConfig(input.childConversationId) ?? {};
|
|
5563
5585
|
const open = await listOpenAgentInvocations(input.parentConversationId);
|
|
5564
5586
|
await assertCanGiveChildWork(input.parentConversationId, open);
|
|
5565
|
-
const openCount = open.filter((row) => row.childConversationId === input.childConversationId).length
|
|
5566
|
-
if (openCount >= MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD) throw new AgentMessageQueueFullError(MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD);
|
|
5587
|
+
const openCount = open.filter((row) => row.childConversationId === input.childConversationId).length;
|
|
5588
|
+
if (latest && openCount >= MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD) throw new AgentMessageQueueFullError(MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD);
|
|
5567
5589
|
await assertChildAgentCapacity(open, {
|
|
5568
5590
|
childConversationId: input.childConversationId,
|
|
5569
5591
|
parentConversationId: input.parentConversationId
|
|
5570
5592
|
});
|
|
5593
|
+
const queued = openCount > 0 || !latest && (await listOpenChildAgentsWithoutAgentInvocations(input.parentConversationId)).includes(input.childConversationId);
|
|
5571
5594
|
const invocation = await insertAgentInvocation({
|
|
5572
5595
|
actor: input.actor,
|
|
5573
5596
|
agentName: child.agentName,
|
|
@@ -5584,7 +5607,7 @@ async function createAgentInvocationForMessage(input, nowMs = Date.now()) {
|
|
|
5584
5607
|
if (!invocation) throw new Error(`Agent invocation creation raced for ${invocationId}`);
|
|
5585
5608
|
return {
|
|
5586
5609
|
invocation,
|
|
5587
|
-
queued
|
|
5610
|
+
queued
|
|
5588
5611
|
};
|
|
5589
5612
|
});
|
|
5590
5613
|
}
|
|
@@ -7086,15 +7109,6 @@ async function listOpenChildAgentsWithoutAgentInvocations(parentConversationId)
|
|
|
7086
7109
|
return (await listChildAgentsWithoutAgentInvocations(parentConversationId)).filter((child) => NON_TERMINAL_AGENT_INVOCATION_STATUSES.includes(child.status)).map((child) => child.childConversationId);
|
|
7087
7110
|
}
|
|
7088
7111
|
/**
|
|
7089
|
-
* Count the open parent messages of one child that no Agent invocation
|
|
7090
|
-
* names: each one that waits in its mailbox, and each open Turn, which runs
|
|
7091
|
-
* one. This is the queue that `MAX_OPEN_AGENT_INVOCATIONS_PER_CHILD` caps.
|
|
7092
|
-
*/
|
|
7093
|
-
async function countOpenParentMessages(childConversationId) {
|
|
7094
|
-
const [turns, work] = await Promise.all([listActiveMailboxTurns(childConversationId), getConversationWorkState({ conversationId: childConversationId })]);
|
|
7095
|
-
return turns.length + (work?.messages ?? []).filter((message) => readParentMessage(message) !== void 0).length;
|
|
7096
|
-
}
|
|
7097
|
-
/**
|
|
7098
7112
|
* List the child agents of one parent that no agent invocation names. Each
|
|
7099
7113
|
* stores its agent config, so older children of a parent, such as ones
|
|
7100
7114
|
* that a removed feature created, are not listed. A child is `running` while
|
|
@@ -7530,8 +7544,8 @@ function createReadConversationEventTool(context) {
|
|
|
7530
7544
|
function toolResultFields(data) {
|
|
7531
7545
|
if (data.type !== "tool_result") return void 0;
|
|
7532
7546
|
return {
|
|
7533
|
-
...typeof data
|
|
7534
|
-
...typeof data
|
|
7547
|
+
...typeof data["toolName"] === "string" && data["toolName"] ? { tool_name: data["toolName"] } : void 0,
|
|
7548
|
+
...typeof data["isError"] === "boolean" ? { is_error: data["isError"] } : void 0
|
|
7535
7549
|
};
|
|
7536
7550
|
}
|
|
7537
7551
|
/**
|
|
@@ -7543,7 +7557,7 @@ function eventText(data) {
|
|
|
7543
7557
|
switch (data.type) {
|
|
7544
7558
|
case "user_message":
|
|
7545
7559
|
case "assistant_message":
|
|
7546
|
-
case "tool_result": return contentText(data
|
|
7560
|
+
case "tool_result": return contentText(data["content"]);
|
|
7547
7561
|
case "message":
|
|
7548
7562
|
case "message_updated": return data.text;
|
|
7549
7563
|
default: return JSON.stringify(stripReplacementHistory(data), null, 2);
|
|
@@ -7557,414 +7571,13 @@ function contentText(content) {
|
|
|
7557
7571
|
function contentPartText(part) {
|
|
7558
7572
|
if (!part || typeof part !== "object") return "";
|
|
7559
7573
|
const value = part;
|
|
7560
|
-
switch (value
|
|
7561
|
-
case "text": return typeof value
|
|
7562
|
-
case "image": return `[image: ${typeof value
|
|
7563
|
-
case "toolCall": return `[tool call: ${String(value
|
|
7574
|
+
switch (value["type"]) {
|
|
7575
|
+
case "text": return typeof value["text"] === "string" ? value["text"] : "";
|
|
7576
|
+
case "image": return `[image: ${typeof value["mimeType"] === "string" ? value["mimeType"] : "unknown type"}]`;
|
|
7577
|
+
case "toolCall": return `[tool call: ${String(value["name"])} ${JSON.stringify(value["arguments"] ?? {})}]`;
|
|
7564
7578
|
default: return "";
|
|
7565
7579
|
}
|
|
7566
7580
|
}
|
|
7567
|
-
// src/chat/attachments/store.ts
|
|
7568
|
-
const DAY_MS = 864e5;
|
|
7569
|
-
const ATTACHMENT_GC_BATCH_LIMIT = 200;
|
|
7570
|
-
/** Time that Junior keeps attachment bytes after the file is stored. */
|
|
7571
|
-
const ATTACHMENT_RETENTION_MS = 30 * DAY_MS;
|
|
7572
|
-
function attachmentIdentity(file) {
|
|
7573
|
-
if ("data" in file) return file.source ?? { sha256: createHash("sha256").update(file.data).digest("hex") };
|
|
7574
|
-
return file.source;
|
|
7575
|
-
}
|
|
7576
|
-
/** Stable conversation-owned id for one file and its presentation metadata. */
|
|
7577
|
-
function attachmentId(args) {
|
|
7578
|
-
const identity = "sha256" in args.identity ? [
|
|
7579
|
-
args.conversationId,
|
|
7580
|
-
args.storageProvider,
|
|
7581
|
-
args.identity.sha256,
|
|
7582
|
-
args.filename,
|
|
7583
|
-
args.contentType
|
|
7584
|
-
] : [
|
|
7585
|
-
args.conversationId,
|
|
7586
|
-
args.storageProvider,
|
|
7587
|
-
args.filename,
|
|
7588
|
-
args.contentType,
|
|
7589
|
-
args.identity.provider,
|
|
7590
|
-
args.identity.id
|
|
7591
|
-
];
|
|
7592
|
-
return createHash("sha256").update(identity.join("\0")).digest("hex");
|
|
7593
|
-
}
|
|
7594
|
-
/**
|
|
7595
|
-
* Object key for one write attempt.
|
|
7596
|
-
*
|
|
7597
|
-
* Attachment ids are content-stable. Object keys are not: each put gets a fresh
|
|
7598
|
-
* key so a failed-write cleanup or GC delete cannot remove another writer's
|
|
7599
|
-
* durable blob.
|
|
7600
|
-
*/
|
|
7601
|
-
function attachmentKey(args) {
|
|
7602
|
-
return `conversations/${args.conversationId}/attachments/${args.attachmentId}/${args.writeId}/${args.filename}`;
|
|
7603
|
-
}
|
|
7604
|
-
/** A source whose bytes do not match its declared size. A retry cannot fix it. */
|
|
7605
|
-
var AttachmentSizeError = class extends Error {
|
|
7606
|
-
constructor(bytes, expected, options) {
|
|
7607
|
-
super(`Attachment body does not match its declared ${expected} bytes (read ${bytes})`, options);
|
|
7608
|
-
this.name = "AttachmentSizeError";
|
|
7609
|
-
}
|
|
7610
|
-
};
|
|
7611
|
-
/** Tries for one object write, each with a freshly opened body. */
|
|
7612
|
-
const WRITE_ATTEMPTS = 3;
|
|
7613
|
-
async function bestEffortDelete(storage, key) {
|
|
7614
|
-
if (key === null) return;
|
|
7615
|
-
try {
|
|
7616
|
-
await storage.delete([key]);
|
|
7617
|
-
} catch {}
|
|
7618
|
-
}
|
|
7619
|
-
/**
|
|
7620
|
-
* Stream one file to a fresh key, and return its size and digest.
|
|
7621
|
-
*
|
|
7622
|
-
* The digest is taken while the bytes stream, so the body is never held
|
|
7623
|
-
* whole. A body that does not match its declared size is not kept.
|
|
7624
|
-
*/
|
|
7625
|
-
async function writeAttachmentObject(args) {
|
|
7626
|
-
for (let attempt = 1;; attempt += 1) try {
|
|
7627
|
-
return await writeAttachmentObjectOnce(args);
|
|
7628
|
-
} catch (error) {
|
|
7629
|
-
if (error instanceof AttachmentSizeError || attempt >= WRITE_ATTEMPTS) {
|
|
7630
|
-
await bestEffortDelete(args.storage, args.key);
|
|
7631
|
-
throw error;
|
|
7632
|
-
}
|
|
7633
|
-
}
|
|
7634
|
-
}
|
|
7635
|
-
async function writeAttachmentObjectOnce(args) {
|
|
7636
|
-
const { file } = args;
|
|
7637
|
-
const expected = "data" in file ? file.data.byteLength : file.bytes;
|
|
7638
|
-
const source = "data" in file ? bufferBody(file.data) : await file.open();
|
|
7639
|
-
const hash = createHash("sha256");
|
|
7640
|
-
let bytes = 0;
|
|
7641
|
-
const body = source.pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
7642
|
-
bytes += chunk.byteLength;
|
|
7643
|
-
if (bytes > expected) throw new AttachmentSizeError(bytes, expected);
|
|
7644
|
-
hash.update(chunk);
|
|
7645
|
-
controller.enqueue(chunk);
|
|
7646
|
-
} }));
|
|
7647
|
-
try {
|
|
7648
|
-
await args.storage.put({
|
|
7649
|
-
body,
|
|
7650
|
-
bytes: expected,
|
|
7651
|
-
contentType: file.mimeType,
|
|
7652
|
-
key: args.key
|
|
7653
|
-
});
|
|
7654
|
-
} catch (error) {
|
|
7655
|
-
if (bytes > expected) throw new AttachmentSizeError(bytes, expected, { cause: error });
|
|
7656
|
-
throw error;
|
|
7657
|
-
}
|
|
7658
|
-
if (bytes !== expected) throw new AttachmentSizeError(bytes, expected);
|
|
7659
|
-
return {
|
|
7660
|
-
bytes,
|
|
7661
|
-
sha256: hash.digest("hex")
|
|
7662
|
-
};
|
|
7663
|
-
}
|
|
7664
|
-
async function isConversationPurged(db, conversationId) {
|
|
7665
|
-
const [row] = await db.db().select({ transcriptPurgedAt: juniorConversations.transcriptPurgedAt }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId));
|
|
7666
|
-
return row?.transcriptPurgedAt != null;
|
|
7667
|
-
}
|
|
7668
|
-
function purgedConversationError(conversationId) {
|
|
7669
|
-
return /* @__PURE__ */ new Error(`Cannot store attachment for purged conversation ${conversationId}`);
|
|
7670
|
-
}
|
|
7671
|
-
async function assertConversationNotPurged(db, conversationId) {
|
|
7672
|
-
if (await isConversationPurged(db, conversationId)) throw purgedConversationError(conversationId);
|
|
7673
|
-
}
|
|
7674
|
-
/** Mark a just-written row for deletion and drop its unused object. */
|
|
7675
|
-
async function rejectPurgedAttachmentWrite(args) {
|
|
7676
|
-
const db = args.db.db();
|
|
7677
|
-
await db.with(conversationDetailTouch(db, [args.conversationId])).update(juniorAttachments).set({ deleteRequestedAt: args.now }).where(eq(juniorAttachments.id, args.id));
|
|
7678
|
-
await bestEffortDelete(args.storage, args.storageKey);
|
|
7679
|
-
throw purgedConversationError(args.conversationId);
|
|
7680
|
-
}
|
|
7681
|
-
/**
|
|
7682
|
-
* Return another writer's live row only when the conversation is still active.
|
|
7683
|
-
*
|
|
7684
|
-
* The caller already wrote a unique object for this attempt. Delete that unused
|
|
7685
|
-
* object either way. If the conversation is purged, do not report success for a
|
|
7686
|
-
* row that purge/GC is about to remove.
|
|
7687
|
-
*/
|
|
7688
|
-
async function reuseLiveAttachment(args) {
|
|
7689
|
-
await bestEffortDelete(args.storage, args.storageKey);
|
|
7690
|
-
await assertConversationNotPurged(args.db, args.conversationId);
|
|
7691
|
-
return { id: args.id };
|
|
7692
|
-
}
|
|
7693
|
-
/**
|
|
7694
|
-
* Persist one conversation-owned file.
|
|
7695
|
-
*
|
|
7696
|
-
* Identity is stable under the conversation: it comes from the file's source
|
|
7697
|
-
* when it has one, and from its digest otherwise. Object storage is written
|
|
7698
|
-
* first under a unique key; the SQL row is created only after that write
|
|
7699
|
-
* succeeds. A row means the attachment is durable. Retries reuse an existing
|
|
7700
|
-
* live row. A purge-marked row is revived by writing a new object and pointing
|
|
7701
|
-
* the row at it, unless the conversation is still purged. If the SQL write
|
|
7702
|
-
* fails after object storage accepts the bytes, this path deletes that unique
|
|
7703
|
-
* object. A process crash between those steps can leave an unreferenced unique
|
|
7704
|
-
* object with no SQL row.
|
|
7705
|
-
*/
|
|
7706
|
-
async function storeAttachment(args) {
|
|
7707
|
-
const now = new Date(args.nowMs ?? Date.now());
|
|
7708
|
-
const identity = attachmentIdentity(args.file);
|
|
7709
|
-
const source = args.file.source;
|
|
7710
|
-
const id = attachmentId({
|
|
7711
|
-
conversationId: args.conversationId,
|
|
7712
|
-
contentType: args.file.mimeType,
|
|
7713
|
-
filename: args.file.filename,
|
|
7714
|
-
identity,
|
|
7715
|
-
storageProvider: args.storage.provider
|
|
7716
|
-
});
|
|
7717
|
-
const [existing] = await args.db.db().select({
|
|
7718
|
-
contentType: juniorAttachments.contentType,
|
|
7719
|
-
conversationId: juniorAttachments.conversationId,
|
|
7720
|
-
deleteRequestedAt: juniorAttachments.deleteRequestedAt,
|
|
7721
|
-
filename: juniorAttachments.filename,
|
|
7722
|
-
id: juniorAttachments.id,
|
|
7723
|
-
provider: juniorAttachments.provider,
|
|
7724
|
-
providerId: juniorAttachments.providerId,
|
|
7725
|
-
storageProvider: juniorAttachments.storageProvider,
|
|
7726
|
-
sha256: juniorAttachments.sha256,
|
|
7727
|
-
storageKey: juniorAttachments.storageKey
|
|
7728
|
-
}).from(juniorAttachments).where(eq(juniorAttachments.id, id));
|
|
7729
|
-
if (existing) {
|
|
7730
|
-
if (existing.contentType !== args.file.mimeType || existing.conversationId !== args.conversationId || existing.filename !== args.file.filename || existing.provider !== (source?.provider ?? null) || existing.providerId !== (source?.id ?? null) || existing.storageProvider !== args.storage.provider || "sha256" in identity && existing.sha256 !== identity.sha256) throw new Error(`Attachment write conflicts with ${existing.id}`);
|
|
7731
|
-
if (existing.deleteRequestedAt === null) {
|
|
7732
|
-
await assertConversationNotPurged(args.db, args.conversationId);
|
|
7733
|
-
return { id: existing.id };
|
|
7734
|
-
}
|
|
7735
|
-
}
|
|
7736
|
-
await assertConversationNotPurged(args.db, args.conversationId);
|
|
7737
|
-
const { file } = args;
|
|
7738
|
-
let storageKey = null;
|
|
7739
|
-
let written;
|
|
7740
|
-
if ("deferred" in file) written = {
|
|
7741
|
-
bytes: file.bytes,
|
|
7742
|
-
sha256: null
|
|
7743
|
-
};
|
|
7744
|
-
else {
|
|
7745
|
-
storageKey = attachmentKey({
|
|
7746
|
-
attachmentId: id,
|
|
7747
|
-
conversationId: args.conversationId,
|
|
7748
|
-
filename: file.filename,
|
|
7749
|
-
writeId: randomUUID()
|
|
7750
|
-
});
|
|
7751
|
-
written = await writeAttachmentObject({
|
|
7752
|
-
file,
|
|
7753
|
-
key: storageKey,
|
|
7754
|
-
storage: args.storage
|
|
7755
|
-
});
|
|
7756
|
-
}
|
|
7757
|
-
if (existing?.deleteRequestedAt != null) {
|
|
7758
|
-
if (await isConversationPurged(args.db, args.conversationId)) {
|
|
7759
|
-
await bestEffortDelete(args.storage, storageKey);
|
|
7760
|
-
throw purgedConversationError(args.conversationId);
|
|
7761
|
-
}
|
|
7762
|
-
const oldStorageKey = existing.storageKey;
|
|
7763
|
-
if ((await args.db.db().with(conversationDetailTouch(args.db.db(), [args.conversationId])).update(juniorAttachments).set({
|
|
7764
|
-
...written,
|
|
7765
|
-
deleteRequestedAt: null,
|
|
7766
|
-
storageKey
|
|
7767
|
-
}).where(and(eq(juniorAttachments.id, id), isNotNull(juniorAttachments.deleteRequestedAt))).returning({ id: juniorAttachments.id })).length > 0) {
|
|
7768
|
-
if (await isConversationPurged(args.db, args.conversationId)) await rejectPurgedAttachmentWrite({
|
|
7769
|
-
conversationId: args.conversationId,
|
|
7770
|
-
db: args.db,
|
|
7771
|
-
id,
|
|
7772
|
-
now,
|
|
7773
|
-
storage: args.storage,
|
|
7774
|
-
storageKey
|
|
7775
|
-
});
|
|
7776
|
-
if (oldStorageKey !== storageKey) await bestEffortDelete(args.storage, oldStorageKey);
|
|
7777
|
-
return { id };
|
|
7778
|
-
}
|
|
7779
|
-
const [afterRace] = await args.db.db().select({
|
|
7780
|
-
deleteRequestedAt: juniorAttachments.deleteRequestedAt,
|
|
7781
|
-
id: juniorAttachments.id,
|
|
7782
|
-
storageKey: juniorAttachments.storageKey
|
|
7783
|
-
}).from(juniorAttachments).where(eq(juniorAttachments.id, id));
|
|
7784
|
-
if (afterRace?.deleteRequestedAt === null) return reuseLiveAttachment({
|
|
7785
|
-
conversationId: args.conversationId,
|
|
7786
|
-
db: args.db,
|
|
7787
|
-
id: afterRace.id,
|
|
7788
|
-
storage: args.storage,
|
|
7789
|
-
storageKey
|
|
7790
|
-
});
|
|
7791
|
-
}
|
|
7792
|
-
let inserted = [];
|
|
7793
|
-
try {
|
|
7794
|
-
inserted = await args.db.db().with(conversationDetailTouch(args.db.db(), [args.conversationId])).insert(juniorAttachments).values({
|
|
7795
|
-
id,
|
|
7796
|
-
conversationId: args.conversationId,
|
|
7797
|
-
storageProvider: args.storage.provider,
|
|
7798
|
-
storageKey,
|
|
7799
|
-
provider: source?.provider,
|
|
7800
|
-
providerId: source?.id,
|
|
7801
|
-
filename: args.file.filename,
|
|
7802
|
-
contentType: args.file.mimeType,
|
|
7803
|
-
...written,
|
|
7804
|
-
createdAt: now
|
|
7805
|
-
}).onConflictDoNothing({ target: juniorAttachments.id }).returning({ id: juniorAttachments.id });
|
|
7806
|
-
} catch (error) {
|
|
7807
|
-
await bestEffortDelete(args.storage, storageKey);
|
|
7808
|
-
throw error;
|
|
7809
|
-
}
|
|
7810
|
-
if (inserted.length > 0) {
|
|
7811
|
-
if (await isConversationPurged(args.db, args.conversationId)) await rejectPurgedAttachmentWrite({
|
|
7812
|
-
conversationId: args.conversationId,
|
|
7813
|
-
db: args.db,
|
|
7814
|
-
id,
|
|
7815
|
-
now,
|
|
7816
|
-
storage: args.storage,
|
|
7817
|
-
storageKey
|
|
7818
|
-
});
|
|
7819
|
-
return { id };
|
|
7820
|
-
}
|
|
7821
|
-
const [row] = await args.db.db().select({
|
|
7822
|
-
deleteRequestedAt: juniorAttachments.deleteRequestedAt,
|
|
7823
|
-
id: juniorAttachments.id,
|
|
7824
|
-
storageKey: juniorAttachments.storageKey
|
|
7825
|
-
}).from(juniorAttachments).where(eq(juniorAttachments.id, id));
|
|
7826
|
-
if (!row) {
|
|
7827
|
-
await bestEffortDelete(args.storage, storageKey);
|
|
7828
|
-
throw new Error(`Attachment row missing after write for ${id}`);
|
|
7829
|
-
}
|
|
7830
|
-
if (row.deleteRequestedAt === null) return reuseLiveAttachment({
|
|
7831
|
-
conversationId: args.conversationId,
|
|
7832
|
-
db: args.db,
|
|
7833
|
-
id: row.id,
|
|
7834
|
-
storage: args.storage,
|
|
7835
|
-
storageKey
|
|
7836
|
-
});
|
|
7837
|
-
if (await isConversationPurged(args.db, args.conversationId)) {
|
|
7838
|
-
await bestEffortDelete(args.storage, storageKey);
|
|
7839
|
-
throw purgedConversationError(args.conversationId);
|
|
7840
|
-
}
|
|
7841
|
-
if ((await args.db.db().with(conversationDetailTouch(args.db.db(), [args.conversationId])).update(juniorAttachments).set({
|
|
7842
|
-
...written,
|
|
7843
|
-
deleteRequestedAt: null,
|
|
7844
|
-
storageKey
|
|
7845
|
-
}).where(and(eq(juniorAttachments.id, id), isNotNull(juniorAttachments.deleteRequestedAt))).returning({ id: juniorAttachments.id })).length > 0) {
|
|
7846
|
-
if (await isConversationPurged(args.db, args.conversationId)) await rejectPurgedAttachmentWrite({
|
|
7847
|
-
conversationId: args.conversationId,
|
|
7848
|
-
db: args.db,
|
|
7849
|
-
id,
|
|
7850
|
-
now,
|
|
7851
|
-
storage: args.storage,
|
|
7852
|
-
storageKey
|
|
7853
|
-
});
|
|
7854
|
-
if (row.storageKey !== storageKey) await bestEffortDelete(args.storage, row.storageKey);
|
|
7855
|
-
return { id };
|
|
7856
|
-
}
|
|
7857
|
-
const [afterRace] = await args.db.db().select({
|
|
7858
|
-
deleteRequestedAt: juniorAttachments.deleteRequestedAt,
|
|
7859
|
-
id: juniorAttachments.id
|
|
7860
|
-
}).from(juniorAttachments).where(eq(juniorAttachments.id, id));
|
|
7861
|
-
if (afterRace?.deleteRequestedAt === null) return reuseLiveAttachment({
|
|
7862
|
-
conversationId: args.conversationId,
|
|
7863
|
-
db: args.db,
|
|
7864
|
-
id: afterRace.id,
|
|
7865
|
-
storage: args.storage,
|
|
7866
|
-
storageKey
|
|
7867
|
-
});
|
|
7868
|
-
await bestEffortDelete(args.storage, storageKey);
|
|
7869
|
-
throw new Error(`Attachment ${id} disappeared while reviving`);
|
|
7870
|
-
}
|
|
7871
|
-
/**
|
|
7872
|
-
* Record an object that a browser already wrote, under the upload's id.
|
|
7873
|
-
*
|
|
7874
|
-
* The row takes over the object key. A retry with the same id keeps the
|
|
7875
|
-
* first row. The caller checked the object's size, type, and digest.
|
|
7876
|
-
*/
|
|
7877
|
-
async function recordUploadedAttachment(args) {
|
|
7878
|
-
const { attachment } = args;
|
|
7879
|
-
const now = new Date(args.nowMs);
|
|
7880
|
-
await assertConversationNotPurged(args.db, attachment.conversationId);
|
|
7881
|
-
if ((await args.db.db().with(conversationDetailTouch(args.db.db(), [attachment.conversationId])).insert(juniorAttachments).values({
|
|
7882
|
-
...attachment,
|
|
7883
|
-
storageProvider: args.storage.provider,
|
|
7884
|
-
createdAt: now
|
|
7885
|
-
}).onConflictDoNothing({ target: juniorAttachments.id }).returning({ id: juniorAttachments.id })).length > 0 && await isConversationPurged(args.db, attachment.conversationId)) await rejectPurgedAttachmentWrite({
|
|
7886
|
-
conversationId: attachment.conversationId,
|
|
7887
|
-
db: args.db,
|
|
7888
|
-
id: attachment.id,
|
|
7889
|
-
now,
|
|
7890
|
-
storage: args.storage,
|
|
7891
|
-
storageKey: attachment.storageKey
|
|
7892
|
-
});
|
|
7893
|
-
}
|
|
7894
|
-
/** Load one live attachment owned by a conversation. */
|
|
7895
|
-
async function readLiveAttachment(args) {
|
|
7896
|
-
const [row] = await args.db.db().select({
|
|
7897
|
-
bytes: juniorAttachments.bytes,
|
|
7898
|
-
contentType: juniorAttachments.contentType,
|
|
7899
|
-
conversationId: juniorAttachments.conversationId,
|
|
7900
|
-
deleteRequestedAt: juniorAttachments.deleteRequestedAt,
|
|
7901
|
-
filename: juniorAttachments.filename,
|
|
7902
|
-
id: juniorAttachments.id,
|
|
7903
|
-
provider: juniorAttachments.provider,
|
|
7904
|
-
providerId: juniorAttachments.providerId,
|
|
7905
|
-
storageProvider: juniorAttachments.storageProvider,
|
|
7906
|
-
storageKey: juniorAttachments.storageKey
|
|
7907
|
-
}).from(juniorAttachments).where(and(eq(juniorAttachments.id, args.attachmentId), eq(juniorAttachments.conversationId, args.conversationId), isNull(juniorAttachments.deleteRequestedAt)));
|
|
7908
|
-
if (!row) return null;
|
|
7909
|
-
if (await isConversationPurged(args.db, args.conversationId)) return null;
|
|
7910
|
-
return {
|
|
7911
|
-
bytes: row.bytes,
|
|
7912
|
-
contentType: row.contentType,
|
|
7913
|
-
conversationId: row.conversationId,
|
|
7914
|
-
filename: row.filename,
|
|
7915
|
-
id: row.id,
|
|
7916
|
-
source: row.provider && row.providerId ? {
|
|
7917
|
-
id: row.providerId,
|
|
7918
|
-
provider: row.provider
|
|
7919
|
-
} : null,
|
|
7920
|
-
storageKey: row.storageKey,
|
|
7921
|
-
storageProvider: row.storageProvider
|
|
7922
|
-
};
|
|
7923
|
-
}
|
|
7924
|
-
/** Persist many conversation-owned files. */
|
|
7925
|
-
async function storeAttachments(args) {
|
|
7926
|
-
const stored = [];
|
|
7927
|
-
for (const file of args.files) stored.push(await storeAttachment({
|
|
7928
|
-
conversationId: args.conversationId,
|
|
7929
|
-
db: args.db,
|
|
7930
|
-
file: {
|
|
7931
|
-
data: file.data,
|
|
7932
|
-
filename: file.filename,
|
|
7933
|
-
mimeType: file.mimeType
|
|
7934
|
-
},
|
|
7935
|
-
...args.nowMs !== void 0 ? { nowMs: args.nowMs } : void 0,
|
|
7936
|
-
storage: args.storage
|
|
7937
|
-
}));
|
|
7938
|
-
return stored;
|
|
7939
|
-
}
|
|
7940
|
-
/** Mark attachments unavailable when their conversation content is purged. */
|
|
7941
|
-
async function requestAttachmentDeletion(db, conversationIds, nowMs) {
|
|
7942
|
-
if (conversationIds.length === 0) return;
|
|
7943
|
-
await db.db().with(conversationDetailTouch(db.db(), conversationIds)).update(juniorAttachments).set({ deleteRequestedAt: new Date(nowMs) }).where(and(inArray(juniorAttachments.conversationId, conversationIds), isNull(juniorAttachments.deleteRequestedAt)));
|
|
7944
|
-
}
|
|
7945
|
-
/**
|
|
7946
|
-
* Delete purged attachments in one bounded batch.
|
|
7947
|
-
*
|
|
7948
|
-
* Eligible rows are 30 days old, explicitly purge-marked, or owned by a
|
|
7949
|
-
* conversation whose transcript is already purged. Delete object keys first,
|
|
7950
|
-
* then remove rows that are still eligible so a failed blob delete remains
|
|
7951
|
-
* retryable.
|
|
7952
|
-
*/
|
|
7953
|
-
async function collectAttachmentGarbage(args) {
|
|
7954
|
-
const expiresBefore = /* @__PURE__ */ new Date(args.nowMs - ATTACHMENT_RETENTION_MS);
|
|
7955
|
-
const rows = await args.db.db().select({
|
|
7956
|
-
id: juniorAttachments.id,
|
|
7957
|
-
storageKey: juniorAttachments.storageKey
|
|
7958
|
-
}).from(juniorAttachments).innerJoin(juniorConversations, eq(juniorAttachments.conversationId, juniorConversations.conversationId)).where(and(eq(juniorAttachments.storageProvider, args.storage.provider), or(lte(juniorAttachments.createdAt, expiresBefore), isNotNull(juniorAttachments.deleteRequestedAt), isNotNull(juniorConversations.transcriptPurgedAt)))).orderBy(asc(juniorAttachments.createdAt), asc(juniorAttachments.id)).limit(args.limit ?? ATTACHMENT_GC_BATCH_LIMIT);
|
|
7959
|
-
if (rows.length === 0) return { deleted: 0 };
|
|
7960
|
-
const keys = rows.flatMap((row) => row.storageKey ? [row.storageKey] : []);
|
|
7961
|
-
if (keys.length > 0) await args.storage.delete(keys);
|
|
7962
|
-
const stillEligible = await args.db.db().select({ id: juniorAttachments.id }).from(juniorAttachments).innerJoin(juniorConversations, eq(juniorAttachments.conversationId, juniorConversations.conversationId)).where(and(inArray(juniorAttachments.id, rows.map((row) => row.id)), or(lte(juniorAttachments.createdAt, expiresBefore), isNotNull(juniorAttachments.deleteRequestedAt), isNotNull(juniorConversations.transcriptPurgedAt))));
|
|
7963
|
-
if (stillEligible.length === 0) return { deleted: 0 };
|
|
7964
|
-
const removed = await args.db.db().delete(juniorAttachments).where(inArray(juniorAttachments.id, stillEligible.map((row) => row.id))).returning({ conversationId: juniorAttachments.conversationId });
|
|
7965
|
-
await touchConversationDetail(args.db.db(), removed.map((row) => row.conversationId));
|
|
7966
|
-
return { deleted: removed.length };
|
|
7967
|
-
}
|
|
7968
7581
|
// src/chat/attachments/uploads.ts
|
|
7969
7582
|
const MINUTE_MS = 6e4;
|
|
7970
7583
|
/** Time that a browser has to write the bytes after it asks to upload. */
|
|
@@ -8715,7 +8328,7 @@ function createAddReviewItemTool(context, services) {
|
|
|
8715
8328
|
everyone: existing.assignedToEveryone,
|
|
8716
8329
|
userIds: existing.assignees.map((assignee) => assignee.userId)
|
|
8717
8330
|
} : await defaultAssignees(scope, context.conversationId);
|
|
8718
|
-
if (!assignees.everyone && assignees.userIds.length === 0 && !scope.actorIsPerson) throw new ToolInputError("No person would see this item: no default assignee has a
|
|
8331
|
+
if (!assignees.everyone && assignees.userIds.length === 0 && !scope.actorIsPerson) throw new ToolInputError("No person would see this item: no default assignee has a User, and this Turn has no person. Set `assignees`.");
|
|
8719
8332
|
await requireReviewItemAssignees({
|
|
8720
8333
|
assignees,
|
|
8721
8334
|
automationId: existing ? existing.automationId : scope.reader.automationId,
|
|
@@ -9685,6 +9298,9 @@ function createEditFileTool() {
|
|
|
9685
9298
|
}
|
|
9686
9299
|
});
|
|
9687
9300
|
}
|
|
9301
|
+
// src/chat/tool-support/result-cap.ts
|
|
9302
|
+
/** Default limit for the text that the model sees from one tool result. */
|
|
9303
|
+
const TOOL_RESULT_MAX_CHARS = 32e3;
|
|
9688
9304
|
const FULL_RESULT_DIR = "/tmp/jr";
|
|
9689
9305
|
function fullResultPath(toolCallId) {
|
|
9690
9306
|
const id = createHash("sha256").update(toolCallId).digest("hex").slice(0, 8);
|
|
@@ -9964,7 +9580,7 @@ const searchConversationsOutputSchema = juniorToolOutputSchema.extend({ conversa
|
|
|
9964
9580
|
function searchConversationsInputSchema(channels) {
|
|
9965
9581
|
return z.object({
|
|
9966
9582
|
query: z.string().trim().min(1).max(200).nullable().optional().describe("Words or meaning to match in the latest Brief, or words in the title."),
|
|
9967
|
-
annotation: z.string().trim().min(1).max(256).nullable().optional().describe("Linked resource key, such as owner/repo#123 for a pull request. Matches that key, or nested children that continue with #. Matches a conversation when it or one of its child agents created
|
|
9583
|
+
annotation: z.string().trim().min(1).max(256).nullable().optional().describe("Linked resource key, such as owner/repo#123 for a pull request. Matches that key, or nested children that continue with #. Matches a conversation when it or one of its child agents created or changed the resource."),
|
|
9968
9584
|
conversation_ids: z.array(z.string().trim().min(1)).min(1).max(CONVERSATION_IDS_MAX).nullable().optional().describe("Return only these conversation IDs."),
|
|
9969
9585
|
outcome: briefOutcomeStatusSchema.nullable().optional().describe("Outcome status of the latest Brief."),
|
|
9970
9586
|
after: z.string().datetime().nullable().optional().describe("Activity at or after this timestamp."),
|
|
@@ -10378,6 +9994,38 @@ function getTimeZoneOffsetMinutes(timestampMs, timezone) {
|
|
|
10378
9994
|
const asUtcMs = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
10379
9995
|
return Math.round((timestampMs - asUtcMs) / 6e4);
|
|
10380
9996
|
}
|
|
9997
|
+
const submitFeedbackToolDefinition = zodToolDefinition({
|
|
9998
|
+
annotations: {
|
|
9999
|
+
destructiveHint: false,
|
|
10000
|
+
idempotentHint: false,
|
|
10001
|
+
openWorldHint: true,
|
|
10002
|
+
readOnlyHint: false
|
|
10003
|
+
},
|
|
10004
|
+
description: "Report a problem with your own tools or runtime to the maintainers, not to the user. Use it once when a tool failed, timed out, was too slow, returned wrong data, or was missing, such as a Sandbox that did not start. Skip it when the work went fine, or when the cause is the user's input, access, or a permission they control. Returns the feedback id.",
|
|
10005
|
+
inputSchema: z.object({ message: z.string().trim().min(1).max(4096).describe("What you tried, the tool and its error or delay, and whether you finished. Do not quote message text, file contents, secrets, or personal data.") }),
|
|
10006
|
+
outputSchema: juniorToolOutputSchema.extend({ feedback_id: z.string().describe("Id of the feedback sent to maintainers.") })
|
|
10007
|
+
});
|
|
10008
|
+
/**
|
|
10009
|
+
* Send the agent's report of a tool or runtime problem to the maintainers as
|
|
10010
|
+
* Sentry user feedback, next to the dashboard Reply ratings.
|
|
10011
|
+
*/
|
|
10012
|
+
function createSubmitFeedbackTool(context) {
|
|
10013
|
+
return zodTool({
|
|
10014
|
+
...submitFeedbackToolDefinition,
|
|
10015
|
+
execute: async (input) => {
|
|
10016
|
+
return { feedback_id: sentry_exports.captureFeedback({
|
|
10017
|
+
message: input.message,
|
|
10018
|
+
name: `${botConfig.userName} agent`,
|
|
10019
|
+
source: "junior_agent",
|
|
10020
|
+
tags: {
|
|
10021
|
+
"gen_ai.conversation.id": context.conversationId,
|
|
10022
|
+
...context.conversationPrivacy ? { "app.conversation.privacy": context.conversationPrivacy } : void 0
|
|
10023
|
+
},
|
|
10024
|
+
url: getDashboardConversationLink(context.conversationId)
|
|
10025
|
+
}) };
|
|
10026
|
+
}
|
|
10027
|
+
});
|
|
10028
|
+
}
|
|
10381
10029
|
const updateUserCustomizationToolDefinition = zodToolDefinition({
|
|
10382
10030
|
exposure: "deferred",
|
|
10383
10031
|
source: {
|
|
@@ -10405,7 +10053,7 @@ function createUpdateUserCustomizationTool(context) {
|
|
|
10405
10053
|
...updateUserCustomizationToolDefinition,
|
|
10406
10054
|
async execute(input) {
|
|
10407
10055
|
const user = (await context.resolveActorIdentity?.())?.user;
|
|
10408
|
-
if (!user) throw new ToolInputError("This person has no linked
|
|
10056
|
+
if (!user) throw new ToolInputError("This person has no linked User, so customization cannot be saved.");
|
|
10409
10057
|
if (!await saveUserCustomization(user.id, input.customization)) throw new Error("User customization target user was not found.");
|
|
10410
10058
|
return { customization: input.customization };
|
|
10411
10059
|
}
|
|
@@ -11270,24 +10918,21 @@ function createWebFetchTool(hooks, options = {}) {
|
|
|
11270
10918
|
// src/chat/tools/web/search.ts
|
|
11271
10919
|
const SEARCH_TIMEOUT_MS = 6e4;
|
|
11272
10920
|
const MAX_RESULTS = 5;
|
|
11273
|
-
const SEARCH_TOOL_NAME = "parallelSearch";
|
|
11274
10921
|
function asString(value) {
|
|
11275
10922
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
11276
10923
|
}
|
|
11277
|
-
function parseSearchResults(
|
|
11278
|
-
const typedResults = Array.isArray(toolResults) ? toolResults : [];
|
|
10924
|
+
function parseSearchResults(outputs, maxResults) {
|
|
11279
10925
|
const parsedResults = [];
|
|
11280
|
-
for (const
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
const results = Array.isArray(output?.results) ? output.results : [];
|
|
10926
|
+
for (const output of outputs) {
|
|
10927
|
+
const results = output?.results;
|
|
10928
|
+
if (!Array.isArray(results)) continue;
|
|
11284
10929
|
for (const result of results) {
|
|
11285
|
-
const url = asString(result
|
|
10930
|
+
const url = asString(result["url"]);
|
|
11286
10931
|
if (!url) continue;
|
|
11287
10932
|
parsedResults.push({
|
|
11288
|
-
title: asString(result
|
|
10933
|
+
title: asString(result["title"]) ?? url,
|
|
11289
10934
|
url,
|
|
11290
|
-
snippet: asString(result
|
|
10935
|
+
snippet: asString(result["excerpt"]) ?? asString(result["snippet"]) ?? ""
|
|
11291
10936
|
});
|
|
11292
10937
|
if (parsedResults.length >= maxResults) return parsedResults;
|
|
11293
10938
|
}
|
|
@@ -11308,7 +10953,7 @@ const webSearchToolDefinition = zodToolDefinition({
|
|
|
11308
10953
|
}),
|
|
11309
10954
|
outputSchema: juniorToolOutputSchema
|
|
11310
10955
|
});
|
|
11311
|
-
function createWebSearchTool(modelId, override) {
|
|
10956
|
+
function createWebSearchTool(modelId, cost, override) {
|
|
11312
10957
|
return zodTool({
|
|
11313
10958
|
...webSearchToolDefinition,
|
|
11314
10959
|
execute: async ({ query, max_results }) => {
|
|
@@ -11318,35 +10963,15 @@ function createWebSearchTool(modelId, override) {
|
|
|
11318
10963
|
});
|
|
11319
10964
|
const maxResults = max_results ?? 3;
|
|
11320
10965
|
const controller = new AbortController();
|
|
11321
|
-
const
|
|
11322
|
-
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
}) },
|
|
11331
|
-
toolChoice: {
|
|
11332
|
-
type: "tool",
|
|
11333
|
-
toolName: SEARCH_TOOL_NAME
|
|
11334
|
-
},
|
|
11335
|
-
abortSignal: controller.signal
|
|
11336
|
-
}), SEARCH_TIMEOUT_MS, "webSearch", { onTimeout: () => controller.abort() });
|
|
11337
|
-
setSpanAttributes({
|
|
11338
|
-
"gen_ai.response.finish_reasons": [response.finishReason],
|
|
11339
|
-
...extractGenAiUsageAttributes(response.usage)
|
|
11340
|
-
});
|
|
11341
|
-
return response;
|
|
11342
|
-
}, {
|
|
11343
|
-
"gen_ai.provider.name": GEN_AI_PROVIDER_NAME,
|
|
11344
|
-
"gen_ai.operation.name": "chat",
|
|
11345
|
-
"gen_ai.request.model": modelId,
|
|
11346
|
-
"server.address": GEN_AI_SERVER_ADDRESS,
|
|
11347
|
-
"server.port": 443,
|
|
11348
|
-
"gen_ai.provider.auth_mode": credential.mode
|
|
11349
|
-
})).toolResults, maxResults);
|
|
10966
|
+
const { outputs } = await withTimeout(searchWeb({
|
|
10967
|
+
operation: "web_search",
|
|
10968
|
+
cost,
|
|
10969
|
+
modelId,
|
|
10970
|
+
query,
|
|
10971
|
+
maxResults,
|
|
10972
|
+
signal: controller.signal
|
|
10973
|
+
}), SEARCH_TIMEOUT_MS, "webSearch", { onTimeout: () => controller.abort() });
|
|
10974
|
+
const results = parseSearchResults(outputs, maxResults);
|
|
11350
10975
|
return {
|
|
11351
10976
|
model: modelId,
|
|
11352
10977
|
query,
|
|
@@ -12054,7 +11679,7 @@ const WORKSPACES_TOOL_SOURCE = {
|
|
|
12054
11679
|
};
|
|
12055
11680
|
/** Record optional reporting without changing the switchWorkspace outcome. */
|
|
12056
11681
|
async function tryRecordWorkspaceSwitchStat(workspace) {
|
|
12057
|
-
if (!process.env
|
|
11682
|
+
if (!process.env["DATABASE_URL"]) return;
|
|
12058
11683
|
try {
|
|
12059
11684
|
await incrementStat({
|
|
12060
11685
|
namespace: "junior",
|
|
@@ -12395,6 +12020,7 @@ const CORE_TOOLS = {
|
|
|
12395
12020
|
updatePlan: always(updatePlanToolDefinition),
|
|
12396
12021
|
reportProgress: always(reportProgressToolDefinition),
|
|
12397
12022
|
systemTime: always(systemTimeToolDefinition),
|
|
12023
|
+
submitFeedback: always(submitFeedbackToolDefinition),
|
|
12398
12024
|
bash: always(bashToolDefinition),
|
|
12399
12025
|
readFile: always(readFileToolDefinition),
|
|
12400
12026
|
editFile: always(editFileToolDefinition),
|
|
@@ -12447,6 +12073,7 @@ const CORE_TOOLS = {
|
|
|
12447
12073
|
loadAttachment: RUN_BUILT,
|
|
12448
12074
|
publishImage: RUN_BUILT,
|
|
12449
12075
|
unpublishImage: RUN_BUILT,
|
|
12076
|
+
transcribeAudio: RUN_BUILT,
|
|
12450
12077
|
spawnAgent: {
|
|
12451
12078
|
when: hasAgents,
|
|
12452
12079
|
definition: () => spawnAgentToolDefinition
|
|
@@ -12927,7 +12554,7 @@ function periodCounts(savings, warmed) {
|
|
|
12927
12554
|
};
|
|
12928
12555
|
}
|
|
12929
12556
|
async function addSavingsStats(modelId, counts) {
|
|
12930
|
-
if (!process.env
|
|
12557
|
+
if (!process.env["DATABASE_URL"]) return;
|
|
12931
12558
|
try {
|
|
12932
12559
|
await addStats(savingsStats(modelId, counts));
|
|
12933
12560
|
} catch (error) {
|
|
@@ -13024,8 +12651,8 @@ function savingsTotals(stats) {
|
|
|
13024
12651
|
* Conversation cannot keep an unbounded amount of image data in state.
|
|
13025
12652
|
* Removing its images would change the request, so it would miss the cache.
|
|
13026
12653
|
*/
|
|
13027
|
-
const zstdCompress
|
|
13028
|
-
const zstdDecompress
|
|
12654
|
+
const zstdCompress = promisify(zstdCompress$1);
|
|
12655
|
+
const zstdDecompress = promisify(zstdDecompress$1);
|
|
13029
12656
|
const SNAPSHOT_ZSTD_PARAMS = { params: { [constants.ZSTD_c_compressionLevel]: 1 } };
|
|
13030
12657
|
const MAX_SNAPSHOT_BYTES = 1048576;
|
|
13031
12658
|
const MAX_SNAPSHOT_IMAGE_BYTES = 33554432;
|
|
@@ -13068,7 +12695,7 @@ async function saveSnapshot(state, conversationId, key, context, ttlMs) {
|
|
|
13068
12695
|
data: `${IMAGE_REF_PREFIX}${sha256}`
|
|
13069
12696
|
};
|
|
13070
12697
|
};
|
|
13071
|
-
const snapshot = (await zstdCompress
|
|
12698
|
+
const snapshot = (await zstdCompress(JSON.stringify(snapshotContext(context, toRef)), SNAPSHOT_ZSTD_PARAMS)).toString("base64");
|
|
13072
12699
|
const size = {
|
|
13073
12700
|
bytes: snapshot.length,
|
|
13074
12701
|
imageCount: images.size,
|
|
@@ -13093,7 +12720,7 @@ async function saveSnapshot(state, conversationId, key, context, ttlMs) {
|
|
|
13093
12720
|
async function loadSnapshot(state, conversationId, key) {
|
|
13094
12721
|
const snapshot = await state.get(key);
|
|
13095
12722
|
if (!snapshot) return "stopped";
|
|
13096
|
-
const context = JSON.parse((await zstdDecompress
|
|
12723
|
+
const context = JSON.parse((await zstdDecompress(Buffer.from(snapshot, "base64"))).toString("utf8"));
|
|
13097
12724
|
for (const part of context.messages.flatMap(imageParts)) {
|
|
13098
12725
|
if (!part.data.startsWith(IMAGE_REF_PREFIX)) continue;
|
|
13099
12726
|
const sha256 = part.data.slice(7);
|
|
@@ -13286,14 +12913,14 @@ function createToolWaitWarmer(conversationId) {
|
|
|
13286
12913
|
stop();
|
|
13287
12914
|
if (waiting) returnedAtMs ??= Date.now();
|
|
13288
12915
|
},
|
|
13289
|
-
async end() {
|
|
12916
|
+
async end(turnEnded = false) {
|
|
13290
12917
|
stop();
|
|
13291
12918
|
const open = waiting;
|
|
13292
12919
|
const returned = returnedAtMs;
|
|
13293
12920
|
waiting = void 0;
|
|
13294
12921
|
returnedAtMs = void 0;
|
|
13295
12922
|
if (!open) return;
|
|
13296
|
-
await (await connectedState()).set(storedWaitKey(conversationId), storedWait(open), STORED_WAIT_TTL_MS);
|
|
12923
|
+
if (!turnEnded) await (await connectedState()).set(storedWaitKey(conversationId), storedWait(open), STORED_WAIT_TTL_MS);
|
|
13297
12924
|
if (returned !== void 0) {
|
|
13298
12925
|
await recordWait(returned - open.request.startedAtMs);
|
|
13299
12926
|
return;
|
|
@@ -13309,7 +12936,7 @@ function createToolWaitWarmer(conversationId) {
|
|
|
13309
12936
|
* changes nothing, so the idle period warms as without a timer.
|
|
13310
12937
|
*/
|
|
13311
12938
|
function earliestTimerDueIdleMs(watches, sinceMs, maxDueIdleMs) {
|
|
13312
|
-
const dueIdleMs = Math.min(...watches.map((watch) => watch.firesAtMs ??
|
|
12939
|
+
const dueIdleMs = Math.min(...watches.map((watch) => watch.firesAtMs ?? 1e400)) - sinceMs;
|
|
13313
12940
|
return dueIdleMs <= maxDueIdleMs ? dueIdleMs : void 0;
|
|
13314
12941
|
}
|
|
13315
12942
|
function askedReviewItem(messages, final) {
|
|
@@ -13487,14 +13114,7 @@ async function readSegmentState(conversationId, nowMs) {
|
|
|
13487
13114
|
* period (`generation`): the snapshot, the warmup count, and the gap claim.
|
|
13488
13115
|
* Work for an old idle period then cannot change a newer one.
|
|
13489
13116
|
*/
|
|
13490
|
-
var warmup_exports = /* @__PURE__ */ __exportAll({
|
|
13491
|
-
CONVERSATION_STATE_TTL_MS: () => CONVERSATION_STATE_TTL_MS,
|
|
13492
|
-
GLOBAL_GAPS_MAX: () => GLOBAL_GAPS_MAX,
|
|
13493
|
-
GLOBAL_GAPS_TTL_MS: () => GLOBAL_GAPS_TTL_MS,
|
|
13494
|
-
createCacheWarmingRecorder: () => createCacheWarmingRecorder,
|
|
13495
|
-
runCacheWarmup: () => runCacheWarmup,
|
|
13496
|
-
segmentGapsKey: () => segmentGapsKey
|
|
13497
|
-
});
|
|
13117
|
+
var warmup_exports = /* @__PURE__ */ __exportAll({ runCacheWarmup: () => runCacheWarmup });
|
|
13498
13118
|
/** Gaps kept in each segment list. */
|
|
13499
13119
|
const GLOBAL_GAPS_MAX = 2e3;
|
|
13500
13120
|
/** A segment list expires this long after its last gap. */
|
|
@@ -13502,6 +13122,11 @@ const GLOBAL_GAPS_TTL_MS = 43200 * MINUTE_MS$1;
|
|
|
13502
13122
|
const CONVERSATION_GAPS_MAX = 50;
|
|
13503
13123
|
/** The Turn count of a Conversation resets after this long with no call. */
|
|
13504
13124
|
const CONVERSATION_STATE_TTL_MS = 10080 * MINUTE_MS$1;
|
|
13125
|
+
/**
|
|
13126
|
+
* Answer tools that end the run without a final response. A child agent
|
|
13127
|
+
* answers its parent with `reply`. People often answer a Turn that posted
|
|
13128
|
+
* nothing or that ended blocked, so it warms like a reply.
|
|
13129
|
+
*/
|
|
13505
13130
|
const ANSWER_TOOL_ENDINGS = {
|
|
13506
13131
|
[REPLY_TOOL_NAME]: "reply",
|
|
13507
13132
|
[NO_REPLY_TOOL_NAME]: "no_reply",
|
|
@@ -13747,7 +13372,7 @@ function createCacheWarmingRecorder(conversationId, userActor, definitionsKey) {
|
|
|
13747
13372
|
},
|
|
13748
13373
|
stop: async () => {
|
|
13749
13374
|
try {
|
|
13750
|
-
await toolWait.end();
|
|
13375
|
+
await toolWait.end(answerToolEnding !== void 0);
|
|
13751
13376
|
} catch (error) {
|
|
13752
13377
|
logWarn("cache_warming.tool_wait.record_failed", { "exception.message": error instanceof Error ? error.message : String(error) });
|
|
13753
13378
|
}
|
|
@@ -13924,4 +13549,4 @@ async function runCacheWarmup(message) {
|
|
|
13924
13549
|
}, startedAtMs, warm);
|
|
13925
13550
|
}, attributes);
|
|
13926
13551
|
}
|
|
13927
|
-
export {
|
|
13552
|
+
export { createBashTool as $, createSlackPublicSearchTool as $n, requireToolCreator as $r, childAgentInput as $t, createWebSearchTool as A, MIN_WARMUP_PREFIX_TOKENS as Ai, createPausedTurns as An, createSearchAutomationsTool as Ar, collectAttachmentUploadGarbage as At, createSystemTimeTool as B, deleteWebAuthorization as Bn, automationTriggerChangesSchema as Br, NON_TERMINAL_AGENT_INVOCATION_STATUSES as Bt, incrementStat as C, missingAutomationSkillReason as Ci, AgentMessagePausedError as Cn, createSlackCanvasEditTool as Cr, conversationTurnIdForMessage as Ct, requireReadyWorkspaceSnapshot as D, countOwnedAutomationsNeedingAttention as Di, PARENT_AGENT_TARGET as Dn, resolveWorkspacePath as Dr, webActorFromUser as Dt, processWorkspaceSnapshotJob as E, resolveTaskOutcomes as Ei, getAgentBinding as En, positiveInteger$1 as Er, recordWebConversationActivity as Et, userLookupIdentityProviders as F, canJoinTurn as Fn, zodToolDefinition as Fr, createRunOperatorSqlTool as Ft, createWriteFileTool as G, setConversationSubscription as Gn, injectContinuationToolName as Gr, getLatestAgentInvocationForConversation as Gt, createSearchEventTypesTool as H, AgentRunError as Hn, editedAutomationTask as Hr, getActiveAgentInvocationForConversation as Ht, lookupSlackBot as I, canShareTurn as In, automationIdForToolCall as Ir, createListWatchesTool as It, sliceFileContent as J, throwApiError as Jn, getConversationAccess as Jr, listPendingAgentInvocationMailboxAppends as Jt, createReadFileTool as K, emptyResponse as Kn, juniorToolOutputSchema as Kr, isTerminalAgentInvocation as Kt, lookupSlackUserProfile as L, isAttemptInterrupt as Ln, automationSkillToolSchema as Lr, listOwnedWatches as Lt, createWatchTimerTool as M, gapSegment as Mi, wakeAuthorizedTurn as Mn, createDeleteAutomationTool as Mr, verifyAttachmentUploads as Mt, createWatchEventsTool as N, wakePausedTurn as Nn, AUTOMATIONS_TOOL_SOURCE as Nr, writeAttachmentUpload as Nt, prepareWorkspaceSnapshot as O, IDLE_HORIZON_MS as Oi, supersedeOpenMailboxTurns as On, createOperationKey as Or, resolveConversationDestination as Ot, createUserLookupTool as P, getTurnAuthorization as Pn, zodTool as Pr, createReadConversationEventTool as Pt, editFile as Q, parseSlackMessageReference as Qn, requireToolCaller as Qr, sendsResultToParent as Qt, createUpdateUserCustomizationTool as R, selectAttemptMessages as Rn, automationToolResult as Rr, listChildAgents as Rt, createWorkspaceTools as S, findAutomationSkill as Si, AgentDepthLimitError as Sn, createSlackCanvasReadTool as Sr, appendAndEnqueueWebMessage as St, ensureWorkspaceSnapshotBuild as T, moveTaskOutcomes as Ti, findChildAgentConversationId as Tn, isMissingPathError as Tr, createConversationId as Tt, createSearchConversationEventsTool as U, executeTurn as Un, newAutomationTask as Ur, getAgentInvocation as Ut, createStopWatchingResourcesTool as V, getWebAuthorization as Vn, automationTriggerSchema as Vr, TERMINAL_AGENT_INVOCATION_STATUSES as Vt, createSearchConversationsTool as W, createSetConversationSubscriptionTool as Wn, triggerKind as Wr, getChildAgentLabel as Wt, capToolResult as X, renderAttachmentText as Xn, automationToolsDisabledReason as Xr, markAgentInvocationParentMailboxAppended as Xt, TOOL_RESULT_MAX_CHARS as Y, createSlackThreadReadTool as Yn, automationToolContext as Yr, listPendingAgentInvocationResults as Yt, createEditFileTool as Z, renderBlockText as Zn, requireToolAutomation as Zr, reportReplacedWithoutOpenWork as Zt, closeBreaker as _, changedEventMatch as _i, cancelSignInWait as _n, isConversationMember as _r, createUpdateReviewItemTool as _t, createCacheWarmingRecorder as a, deleteViewerTask as ai, logDroppedParentMessage as an, createSlackConversationSearchChannelPort as ar, createReportBlockedTool as at, coreToolSlots as b, AutomationEditError as bi, createAgentInvocationForMessage as bn, listThreadReplies as br, reviewItemChangeRecord as bt, isConversationWorkDone as c, ViewerTaskNotFoundError as ci, createAgentInvocationWorker as cn, readSlackRawMessageContext as cr, createMessageAgentTool as ct, addHistoryPeriod as d, readViewerAutomationRuns as di, endAgentInvocationsOfStoppedWork as dn, resolveSlackChannelRef as dr, archiveConversation as dt, requireToolDestination as ei, getChildAgentInputSender as en, createSlackListUpdateItemTool as er, createUpdatePlanTool as et, firstLiveSavingsDate as f, readViewerAutomationSummary as fi, enqueueAgentInvocation as fn, slackChannelRefParam as fr, conversationReadPositionQuery as ft, breakerStates as g, editEventAutomation as gi, stopChildAgentsOf as gn, getConversationInfo as gr, createSearchReviewItemsTool as gt, savingsTotals as h, editScheduledAutomation as hi, stopChildAgentsBelow as hn, getChannelMessage as hr, createAddReviewItemTool as ht, GLOBAL_GAPS_TTL_MS as i, changeViewerAutomationLifecycle as ii, isParentMessageMeta as in, createSlackConversationMessageSearchTool as ir, createReportProgressTool as it, createWebFetchTool as j, NO_REPLY_GAP_MS as ji, getPausedTurnRequest as jn, createRunAutomationNowTool as jr, createAttachmentUpload as jt, ingestEvent as k, MINUTE_MS$1 as ki, supersedeTurnForInput as kn, createCanvas as kr, AttachmentUploadError as kt, listConversationWork as l, readConversationSourceTask as li, createAndEnqueueAgentInvocation as ln, resolveSlackChannelIdFromMessage as lr, createArchiveAgentTool as lt, replaceHistorySavings as m, readViewerAutomations as mi, dropOwnUnreadLoopReplies as mn, joinPublicChannelForRead as mr, reportConversationRead as mt, CONVERSATION_STATE_TTL_MS as n, automationEditor as ni, routeChildInput as nn, createSlackListCreateTool as nr, createSpawnAgentTool as nt, segmentGapsKey as o, readViewerAutomationEdit as oi, parentMessageText as on, createSlackChannelListMessagesTool as or, createReplyTool as ot, idlePeriodSavings as p, readViewerAutomationVersions as pi, resolveAgentInvocationId as pn, checkSlackChannelReadAccess as pr, markConversationRead as pt, missingFileResult as q, jsonResponse as qn, makeStructuredToolOutput as qr, listAgentInvocationsForConversation as qt, GLOBAL_GAPS_MAX as r, changeAutomationLifecycle as ri, childAgentTurnOptions as rn, createSlackListAddItemsTool as rr, createListAgentsTool as rt, warmup_exports as s, updateViewerAutomation as si, readParentMessage as sn, parseSlackThreadId as sr, createNoReplyTool as st, ANSWER_TOOL_ENDINGS as t, activateViewerAutomationVersion as ti, readChildConversationSender as tn, createSlackListGetItemsTool as tr, createStopAgentTool as tt, SAVINGS_NAMESPACE as u, readViewerAutomationExecutions as ui, endActiveAgentInvocations as un, createSlackChannelJoinTool as ur, readLastUserMessageAtByConversation as ut, connectedState as v, requireEventAutomationTrigger as vi, completeCancelledConversationTurn as vn, isPublicSlackChannel as vr, deliverReviewItemChange as vt, readStats as w, effectiveTaskOutcomes as wi, AgentMessageTargetError as wn, SLACK_TOOL_SOURCE as wr, createAndEnqueueConversation as wt, enabledMode as x, requireAutomationSkill as xi, createAgentInvocationFromLatest as xn, createSlackCanvasWriteTool as xr, acceptsWebMessages as xt, providerCacheTtlMs as y, requireAutomationTaskText as yi, recordSubagentEnded as yn, joinPublicChannel as yr, renderReviewItemMessage as yt, createSubmitFeedbackTool as z, createWebAuthorization as zn, automationToolResultSchema as zr, listUnreportedSiblingAgents as zt };
|