@sentry/junior 0.292.0 → 0.293.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-Cigb1MTr.js → adapter-CMJfmHso.js} +1 -1
- package/dist/{admin-BO9V7vnn.js → admin-uuecrKuD.js} +2 -2
- package/dist/{agent-runner-BuH7EHrX.js → agent-runner-DHq1pjUg.js} +272 -151
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +3 -3
- package/dist/api.d.ts +1 -1
- package/dist/api.js +42 -37
- package/dist/{app-C47PT68y.d.ts → app-fWzCHFIb.d.ts} +2 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +422 -394
- package/dist/{assistant-reply-ZjLRGHm2.js → assistant-reply-CIApSfor.js} +1 -1
- package/dist/{automation-CrsYnvdV.js → automation-BE3z19VN.js} +71 -22
- package/dist/{background-compaction-queue-CqZBPe9g.js → background-compaction-queue-D7ncdEa6.js} +4 -4
- package/dist/{briefs-DZrhXJss.js → briefs-NpgMEFh1.js} +2 -2
- package/dist/{catalog-runtime-Cj9I0dco.js → catalog-runtime-DwbTyNRD.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-BerMjSVL.js → config-B4b-NXH5.js} +2 -2
- package/dist/{connections-BWmTOVPB.js → connections-Dz_AQg5p.js} +6 -6
- package/dist/{conversation-pending-messages-Cd7ShwBs.js → conversation-pending-messages-1Kad1Mif.js} +4 -1
- package/dist/{conversation-privacy-BMfbOUCo.js → conversation-privacy-DRsSgLGO.js} +1 -1
- package/dist/{credential-sync-DZDij2CU.js → credential-sync-ClCnnGVj.js} +13 -13
- package/dist/{db-7glZCI18.d.ts → db-BbpttyKH.d.ts} +1 -1
- package/dist/{db-BlfjuqzW.js → db-CoA7_Xqu.js} +3 -3
- package/dist/{executor-ikZvFaMD.js → executor-SWyHhit0.js} +31 -14
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-CTCH5jOy.js → logging-BN5drSEZ.js} +1 -1
- package/dist/{message-C1ID1tKi.js → message-D4qjpW1C.js} +9 -9
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-CStBgDU7.js → oauth-callback-server-Xi-mTLOV.js} +2 -2
- package/dist/{projection-DY93nCfX.js → projection-DXl4ftyL.js} +140 -50
- package/dist/{prompt-exicBZeb.js → prompt-Dmx6IfWZ.js} +3 -3
- package/dist/{registry-X_xdFY9L.js → registry-DosVt9f9.js} +1 -1
- package/dist/{resolve-B9dYN-nS.js → resolve-BDjWJC9s.js} +3 -3
- package/dist/{result-CC8bV8Fl.js → result-CaAFpf4B.js} +8 -8
- package/dist/{runner-D44qp4rc.js → runner-h96Mkss6.js} +7 -7
- package/dist/{sandbox-egress-signals-BrH6DWkt.js → sandbox-egress-signals-rK91BW7i.js} +1 -1
- package/dist/{schema-CC2RxDAV.d.ts → schema-CHsBmXIj.d.ts} +246 -45
- package/dist/{schema-CVV5r-qP.js → schema-C_v8wb80.js} +2 -2
- package/dist/{service-account-89JZHWCE.js → service-account-BpGpScaT.js} +3 -3
- package/dist/{service-account-DoNZuJb-.js → service-account-WUMVuqVL.js} +3 -3
- package/dist/{session-stop-DNucbmPf.js → session-stop-xYK15HUu.js} +20 -41
- package/dist/{skills-BeUfmYXL.js → skills-DHApyCjj.js} +10 -9
- package/dist/{spawn-CIAcfcvZ.js → spawn-BQQrwGNe.js} +5 -5
- package/dist/{stop-Ckd3735h.js → stop-CBeD6_Gs.js} +32 -26
- package/dist/{store-CS0xoqXW.js → store-xtibD98L.js} +3 -3
- package/dist/{task-runner-DjjHCX_m.js → task-runner-BYPN4BEO.js} +65 -90
- package/dist/{turn-failure-response-D0bwI462.js → turn-failure-response-jNVl00MD.js} +7 -7
- package/dist/{validation-Cvx_AupF.js → validation-DGeB_moV.js} +1 -1
- package/dist/{version-BrDx4Fzc.js → version-C6nqU3Qc.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-4CxdwLLQ.js → viewer-9KLQibjn.js} +3 -3
- package/dist/{warmup-B62hd4lD.js → warmup-7S6z068f.js} +56 -24
- package/dist/{work-Cu315oJl.js → work-xwX6unUE.js} +11 -11
- package/dist/{worker-4ClZu6ry.js → worker-CiCCfwd4.js} +6 -6
- package/migrations/0096_automation_task_kind.sql +75 -0
- package/migrations/meta/0096_snapshot.json +4490 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +5 -5
package/dist/app.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { i as getActiveSpan, n as captureMessage, u as sentry_exports } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { $
|
|
3
|
-
import { d as restoreRuntimeConfig, f as setBotModelConfig, h as snapshotRuntimeConfig, i as getChatConfig, m as setSlackReactionConfig, n as botConfig, o as getSlackBotToken, p as setRuntimeLimits, q as getAttachmentStorage, u as resetRuntimeConfig } from "./config-
|
|
4
|
-
import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, E as withSpan, H as GOOGLE_IDENTITY_PROVIDER, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, T as withLogContext, W as normalizeIdentityEmail, b as setSpanAttributes, h as logWarn, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, m as logInfo, p as logException, r as createRequestContext, w as withContext } from "./logging-
|
|
5
|
-
import { t as JUNIOR_VERSION } from "./version-
|
|
2
|
+
import { $r as bindEventAutomationCredentialSubject, Aa as parseSandboxEgressCredentialToken, An as createUserTokenStore, Ao as listConversationAnnotations, Ar as reviewItemReaderForUser, At as isInvalidConversationRecordError, Ba as createPluginEmbedder, C as settleConversationTitleWork, Da as consumeSandboxEgressAuthRequiredSignal, Do as resolveRootVisibility, Ea as clearSandboxEgressSignals, Fi as proxyVercelSandboxEgressRequest, Gi as slackMention, Gn as setPlugins, Gr as collectEventMatchKeys, Hi as formatSlackLink, Ho as getConfigDefaults, In as createPluginEventPublisher, Io as createPluginCache, Kn as validatePlugins, Oa as consumeSandboxEgressPermissionDeniedSignal, Ot as hasRunnableConversationWork, Pa as normalizeSandboxEgressTracePropagationDomains, Pi as isVercelSandboxEgressRequest, Pt as pruneActiveConversation, Qi as postSlackEphemeralMessage, Qr as takeDueTimerWatches, Rn as getPluginApiRoutes, Uo as setConfigDefaults, Vi as escapeSlackMrkdwnText, Wn as getPlugins, Yn as setBriefsConfig, Yr as findMatchingWatches, Zi as openSlackModal, _ as appendConversationMessages, _a as runWithWorkspaceTeamId, _o as readConversationLastEventSeq, aa as slackExternalRefIdSchema, ar as projectConversationMessages, br as canActOnReviewItem, di as getDashboardTaskLink, ei as bindScheduledAutomationCredentialSubject, eo as createPluginLogger, fa as isDmChannel, fi as parseDashboardConversationLink, ga as getWorkspaceTeamId, gr as searchReviewItems, hi as createPluginState, ho as readConversationEventPageAfter, ia as slackEntitySchema, ii as verifySlackDirectCredentialSubject, io as readConversationAccessFromSql, jr as reviewItemReaderForUserInConversation, li as getDashboardReviewItemLink, lr as dismissOpenReviewItems, mo as readConversationEventPage, ni as verifyEventAutomationCredentialSubject, pi as setDashboardConversationLinkOptions, po as readLatestConversationBrief, ri as verifyScheduledAutomationCredentialSubject, si as getDashboardConversationLink, ta as unfurlSlackLinks, ti as bindSlackDirectCredentialSubject, ua as getSlackClient, ut as CONVERSATION_WORK_STALE_ENQUEUE_MS, vo as readConversationMessageEventSeq, zi as resolveBaseUrl, zn as getPluginRoutes } from "./projection-DXl4ftyL.js";
|
|
3
|
+
import { d as restoreRuntimeConfig, f as setBotModelConfig, h as snapshotRuntimeConfig, i as getChatConfig, m as setSlackReactionConfig, n as botConfig, o as getSlackBotToken, p as setRuntimeLimits, q as getAttachmentStorage, u as resetRuntimeConfig } from "./config-B4b-NXH5.js";
|
|
4
|
+
import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, E as withSpan, H as GOOGLE_IDENTITY_PROVIDER, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, T as withLogContext, W as normalizeIdentityEmail, b as setSpanAttributes, h as logWarn, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, m as logInfo, p as logException, r as createRequestContext, w as withContext } from "./logging-BN5drSEZ.js";
|
|
5
|
+
import { t as JUNIOR_VERSION } from "./version-C6nqU3Qc.js";
|
|
6
6
|
import { _ as slackMessageTsSchema, f as parseSlackTeamId, g as slackMessageTsFromMs, h as parseSlackMessageTs, m as slackChannelIdSchema, n as createSlackActor, p as parseSlackUserId, s as parseActorUserId, u as parseSlackChannelId } from "./actor-6jsm_v96.js";
|
|
7
|
-
import { D as resolveActorIdentityId, N as recordGoogleSignIn, R as getConversationIdByProviderConversation, X as createSlackDestination, Y as touchConversationDetail, a as getConversationStore, b as withConversationMutationLock, o as getDb, p as withConversationEventLock, r as getConversationEventStore, s as getSqlExecutor, t as closeDb, x as conversationKindFromRow } from "./db-
|
|
8
|
-
import { A as juniorConversations, N as juniorDestinations, b as juniorConversationBriefs, f as juniorAutomations, g as juniorAgentInvocations, h as juniorAgentBindings, l as juniorReviewItems, u as juniorAutomationRuns, w as juniorConversationEvents } from "./executor-
|
|
9
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
10
|
-
import { $ as readViewerAutomationSummary, $t as resumeConversationDelivery, A as runWithSlackInstallation, C as readSlackReviewItemCardConversationId, D as parseSlackReviewItemClick, E as buildSlackReviewItemModal, H as logScheduledAutomationRunSkipped, I as checkSlackChannelReadAccess, M as parseSlackThreadId, O as parseSlackReviewItemFormTarget, Ot as recordSubagentEnded, S as createSlackReviewItemShow, St as markConversationRead, U as scheduledAutomationRunAttributes, Y as ViewerTaskNotFoundError, Z as readViewerAutomationExecutions, _ as unpublishedArtifactHeaders, at as deliverReviewItemChange, bt as archiveConversation, g as readPublicArtifact, gt as collectAttachmentGarbage, h as publicArtifactHeaders, j as verifySlackSignature, k as parseSlackUserInputSubmission, ln as processWorkspaceSnapshotJob, lt as appendAndEnqueueWebMessage, mt as webActorFromUser, n as executeAgentRun, ot as renderReviewItemMessage, pt as recordWebConversationActivity, r as processBackgroundCompaction, rt as effectiveTaskOutcomes, st as reviewItemChangeRecord, t as createAgentRunner, tt as readViewerAutomations, un as ingestEvent, ut as conversationTurnIdForMessage, v as setConversationSubscription, vt as requestAttachmentDeletion, w as syncReviewItemSlackCards, y as lookupSlackUserProfile, z as joinPublicChannel } from "./agent-runner-
|
|
7
|
+
import { D as resolveActorIdentityId, N as recordGoogleSignIn, R as getConversationIdByProviderConversation, X as createSlackDestination, Y as touchConversationDetail, a as getConversationStore, b as withConversationMutationLock, o as getDb, p as withConversationEventLock, r as getConversationEventStore, s as getSqlExecutor, t as closeDb, x as conversationKindFromRow } from "./db-CoA7_Xqu.js";
|
|
8
|
+
import { A as juniorConversations, N as juniorDestinations, b as juniorConversationBriefs, f as juniorAutomations, g as juniorAgentInvocations, h as juniorAgentBindings, l as juniorReviewItems, u as juniorAutomationRuns, w as juniorConversationEvents } from "./executor-SWyHhit0.js";
|
|
9
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-DwbTyNRD.js";
|
|
10
|
+
import { $ as readViewerAutomationSummary, $t as resumeConversationDelivery, A as runWithSlackInstallation, C as readSlackReviewItemCardConversationId, D as parseSlackReviewItemClick, E as buildSlackReviewItemModal, H as logScheduledAutomationRunSkipped, I as checkSlackChannelReadAccess, M as parseSlackThreadId, O as parseSlackReviewItemFormTarget, Ot as recordSubagentEnded, S as createSlackReviewItemShow, St as markConversationRead, U as scheduledAutomationRunAttributes, Y as ViewerTaskNotFoundError, Z as readViewerAutomationExecutions, _ as unpublishedArtifactHeaders, at as deliverReviewItemChange, bt as archiveConversation, dn as findAutomationSkill, fn as missingAutomationSkillReason, g as readPublicArtifact, gt as collectAttachmentGarbage, h as publicArtifactHeaders, j as verifySlackSignature, k as parseSlackUserInputSubmission, ln as processWorkspaceSnapshotJob, lt as appendAndEnqueueWebMessage, mt as webActorFromUser, n as executeAgentRun, ot as renderReviewItemMessage, pt as recordWebConversationActivity, r as processBackgroundCompaction, rt as effectiveTaskOutcomes, st as reviewItemChangeRecord, t as createAgentRunner, tt as readViewerAutomations, un as ingestEvent, ut as conversationTurnIdForMessage, v as setConversationSubscription, vt as requestAttachmentDeletion, w as syncReviewItemSlackCards, y as lookupSlackUserProfile, z as joinPublicChannel } from "./agent-runner-DHq1pjUg.js";
|
|
11
11
|
import { a as withLock, i as fenceLock, n as MUTATION_LOCK_TTL_MS } from "./locks-D-0h111u.js";
|
|
12
|
-
import { g as createCache, i as readActorIdentity, l as resolveViewerUser, p as parseAvatarUrl } from "./viewer-
|
|
13
|
-
import { r as getStateAdapter, t as disconnectStateAdapter } from "./adapter-
|
|
12
|
+
import { g as createCache, i as readActorIdentity, l as resolveViewerUser, p as parseAvatarUrl } from "./viewer-9KLQibjn.js";
|
|
13
|
+
import { r as getStateAdapter, t as disconnectStateAdapter } from "./adapter-CMJfmHso.js";
|
|
14
14
|
import { a as getNextRunAtMs } from "./schedule-cP0AACm1.js";
|
|
15
15
|
import { F as annotationCard, Y as conversationBriefSchema, k as conversationTitleSchema, p as conversationFeedQuerySchema, x as conversationSurfaceSchema, y as conversationReportStatusSchema } from "./conversation-CtjR1Zcx.js";
|
|
16
16
|
import { t as SANDBOX_EGRESS_PROXY_PATH } from "./proxy-path-BHYoKZdq.js";
|
|
17
|
-
import { a as segmentGapsKey, d as MINUTE_MS, f as MIN_WARMUP_PREFIX_TOKENS, m as gapSegment, n as GLOBAL_GAPS_MAX, p as NO_REPLY_GAP_MS, r as GLOBAL_GAPS_TTL_MS, t as CONVERSATION_STATE_TTL_MS } from "./warmup-
|
|
18
|
-
import { A as getQueueProvider, C as cacheWarmupQueueConsumer, O as queueCallback, T as registerVercelCacheWarmupDevConsumer, _ as resolveConversationWorkQueueTopic, b as conversationQueueMessageSchema, f as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, g as getVercelConversationWorkQueue, h as verifyWorkspaceSnapshotJobMessage, i as verifyBackgroundCompactionMessage, l as pluginTaskQueueConsumer, o as createVercelPluginTaskCallback, r as vercelBackgroundCompactionQueue, t as BACKGROUND_COMPACTION_QUEUE_TOPIC, u as registerVercelPluginTaskDevConsumer, v as verifyConversationQueueMessage, w as createVercelCacheWarmupCallback, x as isConversationQueueMessageRejectedError } from "./background-compaction-queue-
|
|
19
|
-
import { D as listPendingAgentInvocationResults, E as listPendingAgentInvocationMailboxAppends } from "./turn-failure-response-
|
|
20
|
-
import { M as slackChannelMessageReplyThreadTs, N as slackChannelMessageRunsAutomation, O as getEventCatalog, W as renderSlackObjectCard, d as getAuthPausedConversationTurnId, it as setExperimentalFeatures, j as slackChannelMessageEvent, k as SLACK_EVENT_NAMESPACE, nt as getExperimentalFeatures, rt as isExperimentalFeatureEnabled, z as renderTaskInput } from "./session-stop-
|
|
17
|
+
import { a as segmentGapsKey, d as MINUTE_MS, f as MIN_WARMUP_PREFIX_TOKENS, m as gapSegment, n as GLOBAL_GAPS_MAX, p as NO_REPLY_GAP_MS, r as GLOBAL_GAPS_TTL_MS, t as CONVERSATION_STATE_TTL_MS } from "./warmup-7S6z068f.js";
|
|
18
|
+
import { A as getQueueProvider, C as cacheWarmupQueueConsumer, O as queueCallback, T as registerVercelCacheWarmupDevConsumer, _ as resolveConversationWorkQueueTopic, b as conversationQueueMessageSchema, f as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, g as getVercelConversationWorkQueue, h as verifyWorkspaceSnapshotJobMessage, i as verifyBackgroundCompactionMessage, l as pluginTaskQueueConsumer, o as createVercelPluginTaskCallback, r as vercelBackgroundCompactionQueue, t as BACKGROUND_COMPACTION_QUEUE_TOPIC, u as registerVercelPluginTaskDevConsumer, v as verifyConversationQueueMessage, w as createVercelCacheWarmupCallback, x as isConversationQueueMessageRejectedError } from "./background-compaction-queue-D7ncdEa6.js";
|
|
19
|
+
import { D as listPendingAgentInvocationResults, E as listPendingAgentInvocationMailboxAppends } from "./turn-failure-response-jNVl00MD.js";
|
|
20
|
+
import { M as slackChannelMessageReplyThreadTs, N as slackChannelMessageRunsAutomation, O as getEventCatalog, W as renderSlackObjectCard, d as getAuthPausedConversationTurnId, it as setExperimentalFeatures, j as slackChannelMessageEvent, k as SLACK_EVENT_NAMESPACE, nt as getExperimentalFeatures, rt as isExperimentalFeatureEnabled, z as renderTaskInput } from "./session-stop-xYK15HUu.js";
|
|
21
21
|
import { _ as buttonUserInputField } from "./reporting-window-B3Ze-Qnt.js";
|
|
22
|
-
import { c as setSandboxResourceConfig, o as getSandboxResourceConfig } from "./resolve-
|
|
23
|
-
import { _ as listActiveConversationIds, g as getConversationWorkState, h as getConversation, l as clearExpiredConversationLease, m as ensureConversationWake, r as appendAndEnqueueInboundMessage } from "./store-
|
|
24
|
-
import { A as withScheduledAutomationLock,
|
|
25
|
-
import {
|
|
26
|
-
import { n as validatePluginRegistrations, t as validatePluginEgressCredentialHooks } from "./validation-
|
|
22
|
+
import { c as setSandboxResourceConfig, o as getSandboxResourceConfig } from "./resolve-BDjWJC9s.js";
|
|
23
|
+
import { _ as listActiveConversationIds, g as getConversationWorkState, h as getConversation, l as clearExpiredConversationLease, m as ensureConversationWake, r as appendAndEnqueueInboundMessage } from "./store-xtibD98L.js";
|
|
24
|
+
import { A as withScheduledAutomationLock, E as readScheduledAutomation, F as findMatchingEventAutomations, H as eventAutomationRunLimitReason, M as collectEventAutomationMatchKeys, O as saveScheduledAutomationInLock, Q as existingConversationId, V as admitEventAutomationRun, W as automationVersionOf, c as getDispatchConversationId, d as getDispatchRecord, gt as coerceThreadConversationState, h as listPendingDispatchMailboxAppends, i as buildDispatchId, j as blockEventAutomation, k as scheduledRunId, m as isTerminalDispatchStatus, o as confirmDispatchMailboxAppend, ot as recordAutomationExecution, p as getPluginDispatchProjection, s as createOrGetDispatch, t as processPluginTask, w as listScheduledAutomationsForTeam, x as notifyAutomationBlocked, xt as eventGuidance, y as markDispatchFailed } from "./task-runner-BYPN4BEO.js";
|
|
25
|
+
import { H as automationTaskSchema, N as scheduledRunSchema, U as automationTaskText, l as automationListQuerySchema, s as automationExecutionStatusSchema } from "./automation-BE3z19VN.js";
|
|
26
|
+
import { n as validatePluginRegistrations, t as validatePluginEgressCredentialHooks } from "./validation-DGeB_moV.js";
|
|
27
27
|
import { a as pluginRuntimeRegistrationsFromPluginSet, n as pluginCatalogConfigFromEnv, r as pluginCatalogConfigFromPluginSet, t as defineJuniorPlugins } from "./plugins-HYh_JOdw.js";
|
|
28
|
-
import { a as conversationPendingMessageDeliverySchema } from "./conversation-pending-messages-
|
|
29
|
-
import { $ as actOnReviewItem, A as createProductionConversationWorkOptions, B as clearSlackPendingReactions, C as createConversationForViewer, D as readConversationPendingMessages, E as cancelConversationPendingMessagesForViewer, F as isAllowedSignInEmail, G as createSlackWebApiStatusSender, H as stripLeadingBotMention, I as readEnvList, J as stopConversation, K as SubscribedReplyReason, L as resolveAllowedDomains, M as getProductionSlackAdapter, N as assertNoLegacyAllowedDomains, P as isAllowedDomain, Q as ReviewItemActionError, R as startProcessingReaction, S as appendConversationMessageForViewer, T as encodeConversationCursor, U as normalizeIncomingSlackThreadId, V as slackInboundMessageId, W as withNormalizedThreadId, X as recordSkippedConversationMessage, Y as parseContent, Z as bindMessageAuthorIdentityId, a as pinConversation, at as continueConversationInSlack, b as readConversationRecordFromSql, ct as archiveViewerDoneConversations, dt as setConversationAutoArchive, et as closeReviewItemsAnsweredByReply, ht as GET$4, i as readConversationFeed, it as canContinueInSlack, j as createProductionSlackWebhookServices, mt as enqueueAgentDispatch, n as steerConversationPendingMessagesForViewer, nt as reviewItemChange, ot as isMovableToSlack, q as getThreadStopDecision, rt as alreadyContinuesInSlackMessage, s as readConversationDetail, t as stopConversationTurnForViewer, tt as readReviewItemForUser, ut as runAutoArchiveSweep, w as decodeConversationCursor, z as buildSlackInboundMessage } from "./stop-
|
|
30
|
-
import { a as enqueueAgentInvocation, i as endAgentInvocationsOfStoppedWork } from "./work-
|
|
31
|
-
import { n as enqueueAgentInvocationResult } from "./result-
|
|
32
|
-
import { o as unlinkProvider } from "./connections-
|
|
33
|
-
import { a as GET$5, i as publishAppHomeView, r as GET$6, t as receiveLocalOAuthCredential } from "./credential-sync-
|
|
28
|
+
import { a as conversationPendingMessageDeliverySchema } from "./conversation-pending-messages-1Kad1Mif.js";
|
|
29
|
+
import { $ as actOnReviewItem, A as createProductionConversationWorkOptions, B as clearSlackPendingReactions, C as createConversationForViewer, D as readConversationPendingMessages, E as cancelConversationPendingMessagesForViewer, F as isAllowedSignInEmail, G as createSlackWebApiStatusSender, H as stripLeadingBotMention, I as readEnvList, J as stopConversation, K as SubscribedReplyReason, L as resolveAllowedDomains, M as getProductionSlackAdapter, N as assertNoLegacyAllowedDomains, P as isAllowedDomain, Q as ReviewItemActionError, R as startProcessingReaction, S as appendConversationMessageForViewer, T as encodeConversationCursor, U as normalizeIncomingSlackThreadId, V as slackInboundMessageId, W as withNormalizedThreadId, X as recordSkippedConversationMessage, Y as parseContent, Z as bindMessageAuthorIdentityId, a as pinConversation, at as continueConversationInSlack, b as readConversationRecordFromSql, ct as archiveViewerDoneConversations, dt as setConversationAutoArchive, et as closeReviewItemsAnsweredByReply, ht as GET$4, i as readConversationFeed, it as canContinueInSlack, j as createProductionSlackWebhookServices, mt as enqueueAgentDispatch, n as steerConversationPendingMessagesForViewer, nt as reviewItemChange, ot as isMovableToSlack, q as getThreadStopDecision, rt as alreadyContinuesInSlackMessage, s as readConversationDetail, t as stopConversationTurnForViewer, tt as readReviewItemForUser, ut as runAutoArchiveSweep, w as decodeConversationCursor, z as buildSlackInboundMessage } from "./stop-CBeD6_Gs.js";
|
|
30
|
+
import { a as enqueueAgentInvocation, i as endAgentInvocationsOfStoppedWork } from "./work-xwX6unUE.js";
|
|
31
|
+
import { n as enqueueAgentInvocationResult } from "./result-CaAFpf4B.js";
|
|
32
|
+
import { o as unlinkProvider } from "./connections-Dz_AQg5p.js";
|
|
33
|
+
import { a as GET$5, i as publishAppHomeView, r as GET$6, t as receiveLocalOAuthCredential } from "./credential-sync-ClCnnGVj.js";
|
|
34
34
|
import { t as nameRequestRoute } from "./sentry-route-name-BhwWnfqj.js";
|
|
35
|
-
import { t as processConversationWork } from "./worker-
|
|
36
|
-
import { t as bindMessageAgent } from "./message-
|
|
37
|
-
import { t as bindSpawnAgent } from "./spawn-
|
|
35
|
+
import { t as processConversationWork } from "./worker-CiCCfwd4.js";
|
|
36
|
+
import { t as bindMessageAgent } from "./message-D4qjpW1C.js";
|
|
37
|
+
import { t as bindSpawnAgent } from "./spawn-BQQrwGNe.js";
|
|
38
38
|
import { createRequire } from "node:module";
|
|
39
39
|
import { Hono } from "hono";
|
|
40
40
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -77,10 +77,10 @@ import { betterAuth } from "better-auth/minimal";
|
|
|
77
77
|
* Conversation had when an idle period started. So it fills only the
|
|
78
78
|
* segments of Conversations that are not archived and have work state
|
|
79
79
|
* `none`, which most Conversations have. The `open` and `done` segments and
|
|
80
|
-
* the `archived:*` segments stay empty until live gaps arrive.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
80
|
+
* the `archived:*` segments stay empty until live gaps arrive. Until then,
|
|
81
|
+
* `decideWarmup` leans on their `parentGapSegment`, a `none` segment that
|
|
82
|
+
* this fills. Each idle period still records its gap, so the segment fills
|
|
83
|
+
* from live idle periods.
|
|
84
84
|
*/
|
|
85
85
|
const BACKFILL_KEY = "junior:cache_warming:backfill:work_state";
|
|
86
86
|
const BACKFILL_CLAIM_TTL_MS = 60 * MINUTE_MS;
|
|
@@ -330,99 +330,6 @@ async function runTimerWatchHeartbeat(args) {
|
|
|
330
330
|
}
|
|
331
331
|
if (errors.length) throw new AggregateError(errors, "Timer Watch delivery failed");
|
|
332
332
|
}
|
|
333
|
-
// src/chat/task-execution/heartbeat.ts
|
|
334
|
-
const DEFAULT_RECOVERY_LIMIT = 25;
|
|
335
|
-
function heartbeatIdempotencyKey(reason, conversationId, nowMs) {
|
|
336
|
-
return `heartbeat:${reason}:${conversationId}:${nowMs}`;
|
|
337
|
-
}
|
|
338
|
-
/** Requeue expired leases and stranded mailbox work without running the agent. */
|
|
339
|
-
async function recoverConversationWork(args) {
|
|
340
|
-
if (!getChatConfig().conversationWorkEnabled) {
|
|
341
|
-
logWarn("conversation.work.recovery.disabled");
|
|
342
|
-
return {
|
|
343
|
-
expiredLeaseCount: 0,
|
|
344
|
-
pendingCount: 0
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
const result = {
|
|
348
|
-
expiredLeaseCount: 0,
|
|
349
|
-
pendingCount: 0
|
|
350
|
-
};
|
|
351
|
-
const staleBeforeMs = args.nowMs - CONVERSATION_WORK_STALE_ENQUEUE_MS;
|
|
352
|
-
const ids = await listActiveConversationIds({
|
|
353
|
-
limit: args.limit ?? DEFAULT_RECOVERY_LIMIT,
|
|
354
|
-
staleBeforeMs,
|
|
355
|
-
state: args.state
|
|
356
|
-
});
|
|
357
|
-
for (const conversationId of ids) await withLogContext({ conversationId }, async () => {
|
|
358
|
-
let work;
|
|
359
|
-
try {
|
|
360
|
-
work = await getConversationWorkState({
|
|
361
|
-
conversationId,
|
|
362
|
-
state: args.state
|
|
363
|
-
});
|
|
364
|
-
} catch (error) {
|
|
365
|
-
logException(error, "conversation.work.recovery.failed");
|
|
366
|
-
if (isInvalidConversationRecordError(error)) await pruneActiveConversation({
|
|
367
|
-
conversationId,
|
|
368
|
-
state: args.state
|
|
369
|
-
});
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
try {
|
|
373
|
-
if (!work || !hasRunnableConversationWork(work)) {
|
|
374
|
-
await pruneActiveConversation({
|
|
375
|
-
conversationId,
|
|
376
|
-
state: args.state
|
|
377
|
-
});
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (work.execution.lease && work.execution.lease.expiresAtMs <= args.nowMs) {
|
|
381
|
-
const recovery = await clearExpiredConversationLease({
|
|
382
|
-
beforeWorkStops: args.beforeWorkStops,
|
|
383
|
-
conversationId,
|
|
384
|
-
nowMs: args.nowMs,
|
|
385
|
-
state: args.state
|
|
386
|
-
});
|
|
387
|
-
if (recovery === "not_expired") return;
|
|
388
|
-
if (recovery === "stopped") {
|
|
389
|
-
logException(/* @__PURE__ */ new Error("Conversation work stopped after repeated failed attempts"), "conversation.work.retry.exhausted", {
|
|
390
|
-
"app.run.id": work.execution.runId ?? "unknown",
|
|
391
|
-
"app.worker.last_progress_at_ms": work.execution.lastProgressAtMs ?? work.createdAtMs,
|
|
392
|
-
"app.worker.retry_count": (work.execution.retryCount ?? 0) + 1
|
|
393
|
-
});
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
if ((await ensureConversationWake({
|
|
397
|
-
conversationId,
|
|
398
|
-
idempotencyKey: heartbeatIdempotencyKey("lease", conversationId, args.nowMs),
|
|
399
|
-
nowMs: args.nowMs,
|
|
400
|
-
queue: args.queue,
|
|
401
|
-
replaceExistingWake: true,
|
|
402
|
-
state: args.state
|
|
403
|
-
})).status === "enqueued") {
|
|
404
|
-
result.expiredLeaseCount += 1;
|
|
405
|
-
logInfo("conversation.work.lease_expired.requeued");
|
|
406
|
-
}
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
if (work.execution.lease) return;
|
|
410
|
-
if ((await ensureConversationWake({
|
|
411
|
-
conversationId,
|
|
412
|
-
idempotencyKey: heartbeatIdempotencyKey("pending", conversationId, args.nowMs),
|
|
413
|
-
nowMs: args.nowMs,
|
|
414
|
-
queue: args.queue,
|
|
415
|
-
state: args.state
|
|
416
|
-
})).status === "enqueued") {
|
|
417
|
-
result.pendingCount += 1;
|
|
418
|
-
logInfo("conversation.work.pending.requeued");
|
|
419
|
-
}
|
|
420
|
-
} catch (error) {
|
|
421
|
-
logException(error, "conversation.work.recovery.failed");
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
return result;
|
|
425
|
-
}
|
|
426
333
|
// src/chat/agent-dispatch/validation.ts
|
|
427
334
|
function hasIssueAtPath(issues, path) {
|
|
428
335
|
return issues.some((issue) => issue.path.length === path.length && issue.path.every((value, index) => value === path[index]));
|
|
@@ -524,6 +431,7 @@ function createHeartbeatContext(args) {
|
|
|
524
431
|
nowMs: args.nowMs,
|
|
525
432
|
db: getDb(),
|
|
526
433
|
embedder: createPluginEmbedder(pluginName),
|
|
434
|
+
events: args.events,
|
|
527
435
|
state: createPluginState(pluginName),
|
|
528
436
|
log: createPluginLogger(pluginName),
|
|
529
437
|
agent: {
|
|
@@ -552,7 +460,7 @@ function createHeartbeatContext(args) {
|
|
|
552
460
|
/** Create and enqueue one core-owned event automation dispatch. */
|
|
553
461
|
async function dispatchEventAutomation(args) {
|
|
554
462
|
const plugin = "junior";
|
|
555
|
-
const { credentialSubject, outcomes, ...unboundOptions } = args.options;
|
|
463
|
+
const { credentialSubject, outcomes, skill, ...unboundOptions } = args.options;
|
|
556
464
|
validateDispatchOptions({ ...unboundOptions });
|
|
557
465
|
const boundSubject = credentialSubject ? bindEventAutomationCredentialSubject({
|
|
558
466
|
plugin,
|
|
@@ -562,6 +470,7 @@ async function dispatchEventAutomation(args) {
|
|
|
562
470
|
const options = {
|
|
563
471
|
...unboundOptions,
|
|
564
472
|
...outcomes !== void 0 ? { outcomes } : void 0,
|
|
473
|
+
...skill ? { skill } : void 0,
|
|
565
474
|
...boundSubject ? { credentialSubject: boundSubject } : void 0,
|
|
566
475
|
source: {
|
|
567
476
|
kind: "event_automation",
|
|
@@ -579,7 +488,7 @@ async function dispatchEventAutomation(args) {
|
|
|
579
488
|
/** Create and enqueue one core-owned scheduled automation dispatch. */
|
|
580
489
|
async function dispatchScheduledAutomation(args) {
|
|
581
490
|
const plugin = "scheduler";
|
|
582
|
-
const { credentialSubject, outcomes, ...unboundOptions } = args.options;
|
|
491
|
+
const { credentialSubject, outcomes, skill, ...unboundOptions } = args.options;
|
|
583
492
|
validateDispatchOptions({ ...unboundOptions });
|
|
584
493
|
const boundSubject = credentialSubject ? bindScheduledAutomationCredentialSubject({
|
|
585
494
|
plugin,
|
|
@@ -589,6 +498,7 @@ async function dispatchScheduledAutomation(args) {
|
|
|
589
498
|
const options = {
|
|
590
499
|
...unboundOptions,
|
|
591
500
|
...outcomes !== void 0 ? { outcomes } : void 0,
|
|
501
|
+
...skill ? { skill } : void 0,
|
|
592
502
|
...boundSubject ? { credentialSubject: boundSubject } : void 0,
|
|
593
503
|
source: {
|
|
594
504
|
kind: "scheduled_automation",
|
|
@@ -609,54 +519,356 @@ async function getScheduledAutomationDispatch(id) {
|
|
|
609
519
|
plugin: "scheduler",
|
|
610
520
|
id
|
|
611
521
|
});
|
|
612
|
-
}
|
|
613
|
-
// src/chat/
|
|
614
|
-
/**
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
522
|
+
}
|
|
523
|
+
// src/chat/automations/reply-attribution.ts
|
|
524
|
+
/** Name the Automation in the footer of the replies that its runs post. */
|
|
525
|
+
function automationReplyAttribution(title) {
|
|
526
|
+
const detail = (title ?? "").replace(/\s+/g, " ").trim().slice(0, 128).trim();
|
|
527
|
+
return detail ? {
|
|
528
|
+
label: "Automation",
|
|
529
|
+
detail
|
|
530
|
+
} : { label: "Automation" };
|
|
531
|
+
}
|
|
532
|
+
// src/chat/event-automations/runs.ts
|
|
533
|
+
/**
|
|
534
|
+
* Record a dispatched event automation run with the Automation version it ran,
|
|
535
|
+
* and link its Conversation when it exists. The dispatch can finish before
|
|
536
|
+
* this write, so a stored run, or a retry of the same Event, keeps the row it
|
|
537
|
+
* has.
|
|
538
|
+
*/
|
|
539
|
+
async function recordEventAutomationRunStarted(db, args) {
|
|
540
|
+
await db.insert(juniorAutomationRuns).values({
|
|
541
|
+
id: args.dispatchId,
|
|
542
|
+
automationId: args.automation.id,
|
|
543
|
+
automationVersion: automationVersionOf(args.automation),
|
|
544
|
+
conversationId: existingConversationId(getDispatchConversationId({ id: args.dispatchId })),
|
|
545
|
+
startedAtMs: args.nowMs,
|
|
546
|
+
status: "running"
|
|
547
|
+
}).onConflictDoNothing({ target: juniorAutomationRuns.id });
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Settle running event automation runs whose dispatch has ended. A run whose
|
|
551
|
+
* dispatch record is gone fails.
|
|
552
|
+
*/
|
|
553
|
+
async function settleEventAutomationRuns(db, nowMs) {
|
|
554
|
+
const runs = await db.select({
|
|
555
|
+
automationId: juniorAutomationRuns.automationId,
|
|
556
|
+
id: juniorAutomationRuns.id
|
|
557
|
+
}).from(juniorAutomationRuns).innerJoin(juniorAutomations, eq(juniorAutomations.id, juniorAutomationRuns.automationId)).where(and(eq(juniorAutomations.kind, "event"), eq(juniorAutomationRuns.status, "running")));
|
|
558
|
+
for (const run of runs) {
|
|
559
|
+
const dispatch = await getDispatchRecord(run.id);
|
|
560
|
+
const status = dispatch?.status ?? "failed";
|
|
561
|
+
if (status !== "blocked" && status !== "completed" && status !== "failed") continue;
|
|
562
|
+
await recordAutomationExecution(run.automationId, {
|
|
563
|
+
conversationId: getDispatchConversationId({ id: run.id }),
|
|
564
|
+
errorMessage: dispatch ? dispatch.errorMessage : "Event automation dispatch record is missing.",
|
|
565
|
+
executionId: run.id,
|
|
566
|
+
nowMs: dispatch?.updatedAtMs ?? nowMs,
|
|
567
|
+
status
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// src/chat/event-automations/ingest.ts
|
|
572
|
+
/**
|
|
573
|
+
* Owns event matching and durable event-automation dispatch.
|
|
574
|
+
*
|
|
575
|
+
* Each matching automation is independently idempotent. Aggregate failures propagate
|
|
576
|
+
* so the provider can retry the original delivery.
|
|
577
|
+
*/
|
|
578
|
+
/** Bind provider delivery identity to one automation's durable dispatch. */
|
|
579
|
+
function eventAutomationDispatchKey(taskId, namespace, eventKey) {
|
|
580
|
+
return `event-automation:${createHash("sha256").update(`${taskId}\0${namespace}\0${eventKey}`).digest("hex").slice(0, 32)}`;
|
|
581
|
+
}
|
|
582
|
+
/** Render plain agent input for one matching event automation. */
|
|
583
|
+
function eventInput(task, event, outcomes, catalog) {
|
|
584
|
+
const guidance = eventGuidance(catalog, event.namespace, event.eventType);
|
|
585
|
+
return renderTaskInput({
|
|
586
|
+
about: task.trigger.label,
|
|
587
|
+
event: event.eventType,
|
|
588
|
+
source: event.namespace,
|
|
589
|
+
creator: slackMention(task.createdBy.slackUserId),
|
|
590
|
+
instructions: automationTaskText(task.task),
|
|
591
|
+
...task.task.kind === "skill" ? { skill: task.task.skill } : void 0,
|
|
592
|
+
outcomes,
|
|
593
|
+
guidance,
|
|
594
|
+
trustedSummary: event.trustedSummary,
|
|
595
|
+
trustedSummaryMaxLength: EVENT_SUMMARY_MAX_LENGTH,
|
|
596
|
+
verifiedDetails: event.data,
|
|
597
|
+
externalText: event.untrustedText,
|
|
598
|
+
externalTextMaxLength: EVENT_TEXT_MAX_LENGTH
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Match a normalized event and dispatch every matching automation.
|
|
603
|
+
*
|
|
604
|
+
* Plugins publish one copy of an occurrence for each scope, such as a pull
|
|
605
|
+
* request and its repository. All copies share one event key. An automation
|
|
606
|
+
* with no identifier matches every copy, and the dispatch key and the run
|
|
607
|
+
* limit both use the event key, so it runs and counts once.
|
|
608
|
+
*/
|
|
609
|
+
async function ingestEventAutomations(input, options) {
|
|
610
|
+
const event = eventSchema.parse(input);
|
|
611
|
+
const db = getDb();
|
|
612
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
613
|
+
const catalog = getEventCatalog();
|
|
614
|
+
const [matches = []] = await findMatchingEventAutomations(db, [event], options.teamId, catalog);
|
|
615
|
+
const tasks = matches.filter((task) => slackChannelMessageRunsAutomation(event, task));
|
|
616
|
+
let dispatched = 0;
|
|
617
|
+
const errors = [];
|
|
618
|
+
for (const task of tasks) try {
|
|
619
|
+
const skill = task.task.kind === "skill" ? task.task.skill : void 0;
|
|
620
|
+
if (skill && !await findAutomationSkill(skill)) {
|
|
621
|
+
const reason = missingAutomationSkillReason(skill);
|
|
622
|
+
if (await blockEventAutomation(db, task.id, reason)) await notifyAutomationBlocked({
|
|
623
|
+
automationId: task.id,
|
|
624
|
+
kind: "event",
|
|
625
|
+
reason
|
|
626
|
+
});
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
const idempotencyKey = eventAutomationDispatchKey(task.id, event.namespace, event.eventKey);
|
|
630
|
+
if (await admitEventAutomationRun({
|
|
631
|
+
automationId: task.id,
|
|
632
|
+
nowMs,
|
|
633
|
+
runKey: idempotencyKey
|
|
634
|
+
}) === "limited") {
|
|
635
|
+
const reason = eventAutomationRunLimitReason();
|
|
636
|
+
logWarn("event_automation.run_limit.exceeded", {
|
|
637
|
+
"app.task.id": task.id,
|
|
638
|
+
"app.task.type": "event"
|
|
639
|
+
});
|
|
640
|
+
if (await blockEventAutomation(db, task.id, reason)) {
|
|
641
|
+
captureMessage("Event automation blocked by run limit", {
|
|
642
|
+
level: "warning",
|
|
643
|
+
fingerprint: ["event_automation.run_limit.blocked"],
|
|
644
|
+
tags: {
|
|
645
|
+
"app.event.namespace": event.namespace,
|
|
646
|
+
"app.task.type": "event"
|
|
647
|
+
},
|
|
648
|
+
extra: {
|
|
649
|
+
"app.event.event_type": event.eventType,
|
|
650
|
+
"app.event_automation.max_runs": botConfig.maxEventAutomationRuns,
|
|
651
|
+
"app.event_automation.run_window_ms": botConfig.eventAutomationRunWindowMs,
|
|
652
|
+
"app.event_automation.resource_type": task.trigger.resourceType ?? "any",
|
|
653
|
+
"app.task.id": task.id
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
await notifyAutomationBlocked({
|
|
657
|
+
automationId: task.id,
|
|
658
|
+
kind: "event",
|
|
659
|
+
reason
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const replyThreadTs = slackChannelMessageReplyThreadTs(event);
|
|
665
|
+
const destination = replyThreadTs ? {
|
|
666
|
+
...task.destination,
|
|
667
|
+
threadTs: replyThreadTs
|
|
668
|
+
} : task.destination;
|
|
669
|
+
const outcomes = effectiveTaskOutcomes(task.outcomes, destination);
|
|
670
|
+
const credentialSubject = task.credentialMode === "creator" ? {
|
|
671
|
+
type: "user",
|
|
672
|
+
userId: task.createdBy.slackUserId,
|
|
673
|
+
allowedWhen: "event-automation",
|
|
674
|
+
taskId: task.id
|
|
675
|
+
} : void 0;
|
|
676
|
+
const dispatch = await dispatchEventAutomation({
|
|
677
|
+
automationId: task.id,
|
|
678
|
+
conversationWorkQueue: options.queue,
|
|
679
|
+
nowMs,
|
|
680
|
+
options: {
|
|
681
|
+
idempotencyKey,
|
|
682
|
+
...credentialSubject ? { credentialSubject } : void 0,
|
|
683
|
+
destination,
|
|
684
|
+
destinationVisibility: task.destinationVisibility,
|
|
685
|
+
input: eventInput(task, event, outcomes, catalog),
|
|
686
|
+
...skill ? { skill } : void 0,
|
|
687
|
+
metadata: { eventAutomationId: task.id },
|
|
688
|
+
replyAttribution: automationReplyAttribution(task.title),
|
|
689
|
+
outcomes
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
await recordEventAutomationRunStarted(db, {
|
|
693
|
+
automation: task,
|
|
694
|
+
dispatchId: dispatch.id,
|
|
695
|
+
nowMs
|
|
696
|
+
});
|
|
697
|
+
if (dispatch.status === "created") dispatched += 1;
|
|
698
|
+
} catch (error) {
|
|
699
|
+
errors.push(error);
|
|
700
|
+
}
|
|
701
|
+
if (errors.length > 0) throw new AggregateError(errors, "Failed to dispatch one or more event automations");
|
|
702
|
+
return { dispatched };
|
|
703
|
+
}
|
|
704
|
+
// src/chat/events/workspace.ts
|
|
705
|
+
/**
|
|
706
|
+
* Resolve the single-bot Slack team id for event-automation indexing and
|
|
707
|
+
* Event people mentions.
|
|
708
|
+
*
|
|
709
|
+
* Watch matching does not use this. Event automations still key by
|
|
710
|
+
* destination team until that store is conversation-owned. Event delivery
|
|
711
|
+
* itself is not gated on Slack.
|
|
712
|
+
*/
|
|
713
|
+
function createEventTeamIdResolver() {
|
|
714
|
+
let pending;
|
|
715
|
+
return async () => {
|
|
716
|
+
if (!getSlackBotToken()) return void 0;
|
|
717
|
+
pending ??= getSlackClient().auth.test().then((result) => {
|
|
718
|
+
const teamId = result.team_id?.trim();
|
|
719
|
+
if (!teamId) throw new Error("Slack auth.test did not return a team id");
|
|
720
|
+
return teamId;
|
|
721
|
+
}).catch((error) => {
|
|
722
|
+
pending = void 0;
|
|
723
|
+
throw error;
|
|
724
|
+
});
|
|
725
|
+
return await pending;
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
// src/chat/events/app-publisher.ts
|
|
729
|
+
const WATCH_MATCH_CONCURRENCY = 4;
|
|
730
|
+
/** Build the core event publisher used by plugin routes. */
|
|
731
|
+
function createEventAppPublisher(args) {
|
|
732
|
+
const resolveEventAutomationTeamId = createEventTeamIdResolver();
|
|
733
|
+
return {
|
|
734
|
+
async hasMatch(events) {
|
|
735
|
+
const work = args.conversationWork();
|
|
736
|
+
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
737
|
+
const limit = pLimit(WATCH_MATCH_CONCURRENCY);
|
|
738
|
+
const [subscriptions, tasks] = await Promise.all([Promise.all(events.map((event) => limit(() => findMatchingWatches({
|
|
739
|
+
data: event.data,
|
|
740
|
+
eventType: event.eventType,
|
|
741
|
+
namespace: event.namespace,
|
|
742
|
+
identifier: event.identifier,
|
|
743
|
+
state: work.state
|
|
744
|
+
})))), eventAutomationTeamId ? findMatchingEventAutomations(getDb(), events, eventAutomationTeamId, getEventCatalog()) : Promise.resolve([])]);
|
|
745
|
+
return [...subscriptions, ...tasks].some((matched) => matched.length > 0);
|
|
746
|
+
},
|
|
747
|
+
async neededMatchKeys(input) {
|
|
748
|
+
const work = args.conversationWork();
|
|
749
|
+
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
750
|
+
const [watchKeys, taskKeys] = await Promise.all([collectEventMatchKeys({
|
|
751
|
+
eventTypes: input.eventTypes,
|
|
752
|
+
identifiers: input.identifiers,
|
|
753
|
+
namespace: input.namespace,
|
|
754
|
+
state: work.state
|
|
755
|
+
}), eventAutomationTeamId ? collectEventAutomationMatchKeys(getDb(), {
|
|
756
|
+
catalog: getEventCatalog(),
|
|
757
|
+
...input.data ? { data: input.data } : void 0,
|
|
758
|
+
eventTypes: input.eventTypes,
|
|
759
|
+
identifiers: input.identifiers,
|
|
760
|
+
namespace: input.namespace,
|
|
761
|
+
teamId: eventAutomationTeamId
|
|
762
|
+
}) : Promise.resolve([])]);
|
|
763
|
+
return [.../* @__PURE__ */ new Set([...watchKeys, ...taskKeys])].sort();
|
|
764
|
+
},
|
|
765
|
+
async publish(event) {
|
|
766
|
+
const work = args.conversationWork();
|
|
767
|
+
const queue = work.queue ?? getVercelConversationWorkQueue();
|
|
768
|
+
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
769
|
+
await Promise.all([ingestEvent(event, {
|
|
770
|
+
queue,
|
|
771
|
+
slackTeamId: eventAutomationTeamId,
|
|
772
|
+
state: work.state
|
|
773
|
+
}), eventAutomationTeamId ? ingestEventAutomations(event, {
|
|
774
|
+
queue,
|
|
775
|
+
teamId: eventAutomationTeamId
|
|
776
|
+
}) : Promise.resolve()]);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
// src/chat/task-execution/heartbeat.ts
|
|
781
|
+
const DEFAULT_RECOVERY_LIMIT = 25;
|
|
782
|
+
function heartbeatIdempotencyKey(reason, conversationId, nowMs) {
|
|
783
|
+
return `heartbeat:${reason}:${conversationId}:${nowMs}`;
|
|
784
|
+
}
|
|
785
|
+
/** Requeue expired leases and stranded mailbox work without running the agent. */
|
|
786
|
+
async function recoverConversationWork(args) {
|
|
787
|
+
if (!getChatConfig().conversationWorkEnabled) {
|
|
788
|
+
logWarn("conversation.work.recovery.disabled");
|
|
789
|
+
return {
|
|
790
|
+
expiredLeaseCount: 0,
|
|
791
|
+
pendingCount: 0
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
const result = {
|
|
795
|
+
expiredLeaseCount: 0,
|
|
796
|
+
pendingCount: 0
|
|
797
|
+
};
|
|
798
|
+
const staleBeforeMs = args.nowMs - CONVERSATION_WORK_STALE_ENQUEUE_MS;
|
|
799
|
+
const ids = await listActiveConversationIds({
|
|
800
|
+
limit: args.limit ?? DEFAULT_RECOVERY_LIMIT,
|
|
801
|
+
staleBeforeMs,
|
|
802
|
+
state: args.state
|
|
803
|
+
});
|
|
804
|
+
for (const conversationId of ids) await withLogContext({ conversationId }, async () => {
|
|
805
|
+
let work;
|
|
806
|
+
try {
|
|
807
|
+
work = await getConversationWorkState({
|
|
808
|
+
conversationId,
|
|
809
|
+
state: args.state
|
|
810
|
+
});
|
|
811
|
+
} catch (error) {
|
|
812
|
+
logException(error, "conversation.work.recovery.failed");
|
|
813
|
+
if (isInvalidConversationRecordError(error)) await pruneActiveConversation({
|
|
814
|
+
conversationId,
|
|
815
|
+
state: args.state
|
|
816
|
+
});
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
if (!work || !hasRunnableConversationWork(work)) {
|
|
821
|
+
await pruneActiveConversation({
|
|
822
|
+
conversationId,
|
|
823
|
+
state: args.state
|
|
824
|
+
});
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (work.execution.lease && work.execution.lease.expiresAtMs <= args.nowMs) {
|
|
828
|
+
const recovery = await clearExpiredConversationLease({
|
|
829
|
+
beforeWorkStops: args.beforeWorkStops,
|
|
830
|
+
conversationId,
|
|
831
|
+
nowMs: args.nowMs,
|
|
832
|
+
state: args.state
|
|
833
|
+
});
|
|
834
|
+
if (recovery === "not_expired") return;
|
|
835
|
+
if (recovery === "stopped") {
|
|
836
|
+
logException(/* @__PURE__ */ new Error("Conversation work stopped after repeated failed attempts"), "conversation.work.retry.exhausted", {
|
|
837
|
+
"app.run.id": work.execution.runId ?? "unknown",
|
|
838
|
+
"app.worker.last_progress_at_ms": work.execution.lastProgressAtMs ?? work.createdAtMs,
|
|
839
|
+
"app.worker.retry_count": (work.execution.retryCount ?? 0) + 1
|
|
840
|
+
});
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
if ((await ensureConversationWake({
|
|
844
|
+
conversationId,
|
|
845
|
+
idempotencyKey: heartbeatIdempotencyKey("lease", conversationId, args.nowMs),
|
|
846
|
+
nowMs: args.nowMs,
|
|
847
|
+
queue: args.queue,
|
|
848
|
+
replaceExistingWake: true,
|
|
849
|
+
state: args.state
|
|
850
|
+
})).status === "enqueued") {
|
|
851
|
+
result.expiredLeaseCount += 1;
|
|
852
|
+
logInfo("conversation.work.lease_expired.requeued");
|
|
853
|
+
}
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (work.execution.lease) return;
|
|
857
|
+
if ((await ensureConversationWake({
|
|
858
|
+
conversationId,
|
|
859
|
+
idempotencyKey: heartbeatIdempotencyKey("pending", conversationId, args.nowMs),
|
|
860
|
+
nowMs: args.nowMs,
|
|
861
|
+
queue: args.queue,
|
|
862
|
+
state: args.state
|
|
863
|
+
})).status === "enqueued") {
|
|
864
|
+
result.pendingCount += 1;
|
|
865
|
+
logInfo("conversation.work.pending.requeued");
|
|
866
|
+
}
|
|
867
|
+
} catch (error) {
|
|
868
|
+
logException(error, "conversation.work.recovery.failed");
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
return result;
|
|
660
872
|
}
|
|
661
873
|
// src/chat/scheduled-automations/runs.ts
|
|
662
874
|
const PENDING_CLAIM_STALE_MS = 6e4;
|
|
@@ -751,7 +963,8 @@ function taskDedupeFingerprint(task) {
|
|
|
751
963
|
} : null,
|
|
752
964
|
timezone: task.schedule.timezone
|
|
753
965
|
},
|
|
754
|
-
task: normalizedText(task.task
|
|
966
|
+
task: normalizedText(automationTaskText(task.task)),
|
|
967
|
+
skill: task.task.kind === "skill" ? task.task.skill : null
|
|
755
968
|
});
|
|
756
969
|
}
|
|
757
970
|
async function findStaleRecoveryCanonicalTask(db, task) {
|
|
@@ -992,12 +1205,12 @@ function singleLineMetadataValue(value) {
|
|
|
992
1205
|
function buildDispatchInput(task) {
|
|
993
1206
|
return renderTaskInput({
|
|
994
1207
|
creator: slackMention(task.createdBy.slackUserId),
|
|
995
|
-
instructions: task.task
|
|
1208
|
+
instructions: automationTaskText(task.task),
|
|
1209
|
+
...task.task.kind === "skill" ? { skill: task.task.skill } : void 0,
|
|
996
1210
|
outcomes: effectiveTaskOutcomes(task.outcomes, task.destination)
|
|
997
1211
|
});
|
|
998
1212
|
}
|
|
999
1213
|
function buildDispatchMetadata(args) {
|
|
1000
|
-
if (!args.task.task.text?.trim()) throw new Error("Scheduled automation text is required");
|
|
1001
1214
|
return {
|
|
1002
1215
|
runId: args.run.id,
|
|
1003
1216
|
schedule: singleLineMetadataValue(args.task.schedule.description),
|
|
@@ -1194,17 +1407,11 @@ async function runScheduledAutomationHeartbeat(args) {
|
|
|
1194
1407
|
if (skipped) logScheduledAutomationRunSkipped(task, skipped, { "app.task.run.error": skippedReason });
|
|
1195
1408
|
continue;
|
|
1196
1409
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
metadata = buildDispatchMetadata({
|
|
1200
|
-
nowMs: args.nowMs,
|
|
1201
|
-
run,
|
|
1202
|
-
task
|
|
1203
|
-
});
|
|
1204
|
-
} catch (error) {
|
|
1410
|
+
const skill = task.task.kind === "skill" ? task.task.skill : void 0;
|
|
1411
|
+
if (skill && !await findAutomationSkill(skill)) {
|
|
1205
1412
|
await finishClaimedRun({
|
|
1206
1413
|
db,
|
|
1207
|
-
errorMessage:
|
|
1414
|
+
errorMessage: missingAutomationSkillReason(skill),
|
|
1208
1415
|
nowMs: args.nowMs,
|
|
1209
1416
|
run,
|
|
1210
1417
|
status: "blocked"
|
|
@@ -1228,7 +1435,12 @@ async function runScheduledAutomationHeartbeat(args) {
|
|
|
1228
1435
|
destination: task.destination,
|
|
1229
1436
|
destinationVisibility: task.conversationAccess.visibility,
|
|
1230
1437
|
input: buildDispatchInput(task),
|
|
1231
|
-
|
|
1438
|
+
...skill ? { skill } : void 0,
|
|
1439
|
+
metadata: buildDispatchMetadata({
|
|
1440
|
+
nowMs: args.nowMs,
|
|
1441
|
+
run,
|
|
1442
|
+
task
|
|
1443
|
+
}),
|
|
1232
1444
|
replyAttribution: automationReplyAttribution(task.title),
|
|
1233
1445
|
outcomes: effectiveTaskOutcomes(task.outcomes, task.destination)
|
|
1234
1446
|
}
|
|
@@ -1287,6 +1499,7 @@ async function runPluginHeartbeats(args) {
|
|
|
1287
1499
|
try {
|
|
1288
1500
|
const result = await runWithTimeout(Promise.resolve(heartbeat(createHeartbeatContext({
|
|
1289
1501
|
conversationWorkQueue: args.conversationWorkQueue,
|
|
1502
|
+
events: createPluginEventPublisher(plugin, args.events),
|
|
1290
1503
|
plugin,
|
|
1291
1504
|
nowMs: args.nowMs
|
|
1292
1505
|
}))), PLUGIN_HEARTBEAT_TIMEOUT_MS);
|
|
@@ -1354,6 +1567,7 @@ async function recoverPendingAgentInvocationResults(args) {
|
|
|
1354
1567
|
/** Run the core heartbeat phases. */
|
|
1355
1568
|
async function runHeartbeat(args) {
|
|
1356
1569
|
const queue = args.conversationWorkQueue ?? getVercelConversationWorkQueue();
|
|
1570
|
+
const events = args.events ?? createEventAppPublisher({ conversationWork: () => ({ queue }) });
|
|
1357
1571
|
await recoverConversationWork({
|
|
1358
1572
|
beforeWorkStops: endAgentInvocationsOfStoppedWork,
|
|
1359
1573
|
nowMs: args.nowMs,
|
|
@@ -1390,6 +1604,7 @@ async function runHeartbeat(args) {
|
|
|
1390
1604
|
}
|
|
1391
1605
|
await runPluginHeartbeats({
|
|
1392
1606
|
conversationWorkQueue: queue,
|
|
1607
|
+
events,
|
|
1393
1608
|
nowMs: args.nowMs
|
|
1394
1609
|
});
|
|
1395
1610
|
try {
|
|
@@ -1419,6 +1634,7 @@ async function GET$3(request, waitUntil, options = {}) {
|
|
|
1419
1634
|
const nowMs = Date.now();
|
|
1420
1635
|
waitUntil(() => runHeartbeat({
|
|
1421
1636
|
conversationWorkQueue: options.conversationWorkQueue,
|
|
1637
|
+
events: options.events,
|
|
1422
1638
|
nowMs
|
|
1423
1639
|
}).catch((error) => {
|
|
1424
1640
|
logException(error, "heartbeat.failed", { "app.heartbeat.now_ms": nowMs });
|
|
@@ -2759,127 +2975,6 @@ function textMentionsBot(text, botUserId) {
|
|
|
2759
2975
|
const id = escapeRegExp(botUserId);
|
|
2760
2976
|
return new RegExp(`<@${id}(?:\\|[^>]+)?>`).test(outside);
|
|
2761
2977
|
}
|
|
2762
|
-
// src/chat/event-automations/ingest.ts
|
|
2763
|
-
/**
|
|
2764
|
-
* Owns event matching and durable event-automation dispatch.
|
|
2765
|
-
*
|
|
2766
|
-
* Each matching automation is independently idempotent. Aggregate failures propagate
|
|
2767
|
-
* so the provider can retry the original delivery.
|
|
2768
|
-
*/
|
|
2769
|
-
/** Bind provider delivery identity to one automation's durable dispatch. */
|
|
2770
|
-
function eventAutomationDispatchKey(taskId, namespace, eventKey) {
|
|
2771
|
-
return `event-automation:${createHash("sha256").update(`${taskId}\0${namespace}\0${eventKey}`).digest("hex").slice(0, 32)}`;
|
|
2772
|
-
}
|
|
2773
|
-
/** Render plain agent input for one matching event automation. */
|
|
2774
|
-
function eventInput(task, event, outcomes, catalog) {
|
|
2775
|
-
const guidance = eventGuidance(catalog, event.namespace, event.eventType);
|
|
2776
|
-
return renderTaskInput({
|
|
2777
|
-
about: task.trigger.label,
|
|
2778
|
-
event: event.eventType,
|
|
2779
|
-
source: event.namespace,
|
|
2780
|
-
creator: slackMention(task.createdBy.slackUserId),
|
|
2781
|
-
instructions: task.task.text,
|
|
2782
|
-
outcomes,
|
|
2783
|
-
guidance,
|
|
2784
|
-
trustedSummary: event.trustedSummary,
|
|
2785
|
-
trustedSummaryMaxLength: EVENT_SUMMARY_MAX_LENGTH,
|
|
2786
|
-
verifiedDetails: event.data,
|
|
2787
|
-
externalText: event.untrustedText,
|
|
2788
|
-
externalTextMaxLength: EVENT_TEXT_MAX_LENGTH
|
|
2789
|
-
});
|
|
2790
|
-
}
|
|
2791
|
-
/**
|
|
2792
|
-
* Match a normalized event and dispatch every matching automation.
|
|
2793
|
-
*
|
|
2794
|
-
* Plugins publish one copy of an occurrence for each scope, such as a pull
|
|
2795
|
-
* request and its repository. All copies share one event key. An automation
|
|
2796
|
-
* with no identifier matches every copy, and the dispatch key and the run
|
|
2797
|
-
* limit both use the event key, so it runs and counts once.
|
|
2798
|
-
*/
|
|
2799
|
-
async function ingestEventAutomations(input, options) {
|
|
2800
|
-
const event = eventSchema.parse(input);
|
|
2801
|
-
const db = getDb();
|
|
2802
|
-
const nowMs = options.nowMs ?? Date.now();
|
|
2803
|
-
const catalog = getEventCatalog();
|
|
2804
|
-
const [matches = []] = await findMatchingEventAutomations(db, [event], options.teamId, catalog);
|
|
2805
|
-
const tasks = matches.filter((task) => slackChannelMessageRunsAutomation(event, task));
|
|
2806
|
-
let dispatched = 0;
|
|
2807
|
-
const errors = [];
|
|
2808
|
-
for (const task of tasks) try {
|
|
2809
|
-
const idempotencyKey = eventAutomationDispatchKey(task.id, event.namespace, event.eventKey);
|
|
2810
|
-
if (await admitEventAutomationRun({
|
|
2811
|
-
automationId: task.id,
|
|
2812
|
-
nowMs,
|
|
2813
|
-
runKey: idempotencyKey
|
|
2814
|
-
}) === "limited") {
|
|
2815
|
-
const reason = eventAutomationRunLimitReason();
|
|
2816
|
-
logWarn("event_automation.run_limit.exceeded", {
|
|
2817
|
-
"app.task.id": task.id,
|
|
2818
|
-
"app.task.type": "event"
|
|
2819
|
-
});
|
|
2820
|
-
if (await blockEventAutomation(db, task.id, reason)) {
|
|
2821
|
-
captureMessage("Event automation blocked by run limit", {
|
|
2822
|
-
level: "warning",
|
|
2823
|
-
fingerprint: ["event_automation.run_limit.blocked"],
|
|
2824
|
-
tags: {
|
|
2825
|
-
"app.event.namespace": event.namespace,
|
|
2826
|
-
"app.task.type": "event"
|
|
2827
|
-
},
|
|
2828
|
-
extra: {
|
|
2829
|
-
"app.event.event_type": event.eventType,
|
|
2830
|
-
"app.event_automation.max_runs": botConfig.maxEventAutomationRuns,
|
|
2831
|
-
"app.event_automation.run_window_ms": botConfig.eventAutomationRunWindowMs,
|
|
2832
|
-
"app.event_automation.resource_type": task.trigger.resourceType ?? "any",
|
|
2833
|
-
"app.task.id": task.id
|
|
2834
|
-
}
|
|
2835
|
-
});
|
|
2836
|
-
await notifyAutomationBlocked({
|
|
2837
|
-
automationId: task.id,
|
|
2838
|
-
kind: "event",
|
|
2839
|
-
reason
|
|
2840
|
-
});
|
|
2841
|
-
}
|
|
2842
|
-
continue;
|
|
2843
|
-
}
|
|
2844
|
-
const replyThreadTs = slackChannelMessageReplyThreadTs(event);
|
|
2845
|
-
const destination = replyThreadTs ? {
|
|
2846
|
-
...task.destination,
|
|
2847
|
-
threadTs: replyThreadTs
|
|
2848
|
-
} : task.destination;
|
|
2849
|
-
const outcomes = effectiveTaskOutcomes(task.outcomes, destination);
|
|
2850
|
-
const credentialSubject = task.credentialMode === "creator" ? {
|
|
2851
|
-
type: "user",
|
|
2852
|
-
userId: task.createdBy.slackUserId,
|
|
2853
|
-
allowedWhen: "event-automation",
|
|
2854
|
-
taskId: task.id
|
|
2855
|
-
} : void 0;
|
|
2856
|
-
const dispatch = await dispatchEventAutomation({
|
|
2857
|
-
automationId: task.id,
|
|
2858
|
-
conversationWorkQueue: options.queue,
|
|
2859
|
-
nowMs,
|
|
2860
|
-
options: {
|
|
2861
|
-
idempotencyKey,
|
|
2862
|
-
...credentialSubject ? { credentialSubject } : void 0,
|
|
2863
|
-
destination,
|
|
2864
|
-
destinationVisibility: task.destinationVisibility,
|
|
2865
|
-
input: eventInput(task, event, outcomes, catalog),
|
|
2866
|
-
metadata: { eventAutomationId: task.id },
|
|
2867
|
-
replyAttribution: automationReplyAttribution(task.title),
|
|
2868
|
-
outcomes
|
|
2869
|
-
}
|
|
2870
|
-
});
|
|
2871
|
-
await recordEventAutomationRunStarted(db, {
|
|
2872
|
-
automation: task,
|
|
2873
|
-
dispatchId: dispatch.id,
|
|
2874
|
-
nowMs
|
|
2875
|
-
});
|
|
2876
|
-
if (dispatch.status === "created") dispatched += 1;
|
|
2877
|
-
} catch (error) {
|
|
2878
|
-
errors.push(error);
|
|
2879
|
-
}
|
|
2880
|
-
if (errors.length > 0) throw new AggregateError(errors, "Failed to dispatch one or more event automations");
|
|
2881
|
-
return { dispatched };
|
|
2882
|
-
}
|
|
2883
2978
|
// src/chat/ingress/slack-allowed-domain.ts
|
|
2884
2979
|
const ALLOWED_TTL_MS = 3e5;
|
|
2885
2980
|
const NOT_ALLOWED_TTL_MS = 3e4;
|
|
@@ -2964,11 +3059,15 @@ function dateField(key, label, value, empty) {
|
|
|
2964
3059
|
function renderAutomationDetails(automation) {
|
|
2965
3060
|
const url = getDashboardTaskLink(automation.id);
|
|
2966
3061
|
if (!url) return void 0;
|
|
2967
|
-
const fields = [textField("status", "Status", automation.kind === "scheduled" ? automation.status : automation.trigger.problems.length === 0 ? "ready" : "unavailable")
|
|
2968
|
-
|
|
3062
|
+
const fields = [textField("status", "Status", automation.kind === "scheduled" ? automation.status : automation.trigger.problems.length === 0 ? "ready" : "unavailable")];
|
|
3063
|
+
const { task } = automation;
|
|
3064
|
+
if (task.kind === "skill") fields.push(textField("skill", "Skill", task.skill));
|
|
3065
|
+
const text = automationTaskText(task);
|
|
3066
|
+
if (text) fields.push({
|
|
3067
|
+
...textField("description", task.kind === "skill" ? "Context" : "Instruction", text),
|
|
2969
3068
|
format: "markdown",
|
|
2970
3069
|
long: true
|
|
2971
|
-
}
|
|
3070
|
+
});
|
|
2972
3071
|
if (automation.kind === "scheduled") fields.push({
|
|
2973
3072
|
...textField("trigger", "Schedule", automation.schedule),
|
|
2974
3073
|
long: true
|
|
@@ -3798,82 +3897,6 @@ async function publicArtifactGET(args) {
|
|
|
3798
3897
|
return new Response("Internal Server Error", { status: 500 });
|
|
3799
3898
|
}
|
|
3800
3899
|
}
|
|
3801
|
-
// src/chat/events/workspace.ts
|
|
3802
|
-
/**
|
|
3803
|
-
* Resolve the single-bot Slack team id for event-automation indexing and
|
|
3804
|
-
* Event people mentions.
|
|
3805
|
-
*
|
|
3806
|
-
* Watch matching does not use this. Event automations still key by
|
|
3807
|
-
* destination team until that store is conversation-owned. Event delivery
|
|
3808
|
-
* itself is not gated on Slack.
|
|
3809
|
-
*/
|
|
3810
|
-
function createEventTeamIdResolver() {
|
|
3811
|
-
let pending;
|
|
3812
|
-
return async () => {
|
|
3813
|
-
if (!getSlackBotToken()) return void 0;
|
|
3814
|
-
pending ??= getSlackClient().auth.test().then((result) => {
|
|
3815
|
-
const teamId = result.team_id?.trim();
|
|
3816
|
-
if (!teamId) throw new Error("Slack auth.test did not return a team id");
|
|
3817
|
-
return teamId;
|
|
3818
|
-
}).catch((error) => {
|
|
3819
|
-
pending = void 0;
|
|
3820
|
-
throw error;
|
|
3821
|
-
});
|
|
3822
|
-
return await pending;
|
|
3823
|
-
};
|
|
3824
|
-
}
|
|
3825
|
-
// src/chat/events/app-publisher.ts
|
|
3826
|
-
const WATCH_MATCH_CONCURRENCY = 4;
|
|
3827
|
-
/** Build the core event publisher used by plugin routes. */
|
|
3828
|
-
function createEventAppPublisher(args) {
|
|
3829
|
-
const resolveEventAutomationTeamId = createEventTeamIdResolver();
|
|
3830
|
-
return {
|
|
3831
|
-
async hasMatch(events) {
|
|
3832
|
-
const work = args.conversationWork();
|
|
3833
|
-
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
3834
|
-
const limit = pLimit(WATCH_MATCH_CONCURRENCY);
|
|
3835
|
-
const [subscriptions, tasks] = await Promise.all([Promise.all(events.map((event) => limit(() => findMatchingWatches({
|
|
3836
|
-
data: event.data,
|
|
3837
|
-
eventType: event.eventType,
|
|
3838
|
-
namespace: event.namespace,
|
|
3839
|
-
identifier: event.identifier,
|
|
3840
|
-
state: work.state
|
|
3841
|
-
})))), eventAutomationTeamId ? findMatchingEventAutomations(getDb(), events, eventAutomationTeamId, getEventCatalog()) : Promise.resolve([])]);
|
|
3842
|
-
return [...subscriptions, ...tasks].some((matched) => matched.length > 0);
|
|
3843
|
-
},
|
|
3844
|
-
async neededMatchKeys(input) {
|
|
3845
|
-
const work = args.conversationWork();
|
|
3846
|
-
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
3847
|
-
const [watchKeys, taskKeys] = await Promise.all([collectEventMatchKeys({
|
|
3848
|
-
eventTypes: input.eventTypes,
|
|
3849
|
-
identifiers: input.identifiers,
|
|
3850
|
-
namespace: input.namespace,
|
|
3851
|
-
state: work.state
|
|
3852
|
-
}), eventAutomationTeamId ? collectEventAutomationMatchKeys(getDb(), {
|
|
3853
|
-
catalog: getEventCatalog(),
|
|
3854
|
-
...input.data ? { data: input.data } : void 0,
|
|
3855
|
-
eventTypes: input.eventTypes,
|
|
3856
|
-
identifiers: input.identifiers,
|
|
3857
|
-
namespace: input.namespace,
|
|
3858
|
-
teamId: eventAutomationTeamId
|
|
3859
|
-
}) : Promise.resolve([])]);
|
|
3860
|
-
return [.../* @__PURE__ */ new Set([...watchKeys, ...taskKeys])].sort();
|
|
3861
|
-
},
|
|
3862
|
-
async publish(event) {
|
|
3863
|
-
const work = args.conversationWork();
|
|
3864
|
-
const queue = work.queue ?? getVercelConversationWorkQueue();
|
|
3865
|
-
const eventAutomationTeamId = await resolveEventAutomationTeamId();
|
|
3866
|
-
await Promise.all([ingestEvent(event, {
|
|
3867
|
-
queue,
|
|
3868
|
-
slackTeamId: eventAutomationTeamId,
|
|
3869
|
-
state: work.state
|
|
3870
|
-
}), eventAutomationTeamId ? ingestEventAutomations(event, {
|
|
3871
|
-
queue,
|
|
3872
|
-
teamId: eventAutomationTeamId
|
|
3873
|
-
}) : Promise.resolve()]);
|
|
3874
|
-
}
|
|
3875
|
-
};
|
|
3876
|
-
}
|
|
3877
3900
|
// src/api/acp/conversations.ts
|
|
3878
3901
|
const EVENT_PAGE_SIZE = 50;
|
|
3879
3902
|
async function hasConversationAccess(conversationId, user) {
|
|
@@ -6827,7 +6850,7 @@ const mcpAutomationSchema = z.object({
|
|
|
6827
6850
|
id: z.string(),
|
|
6828
6851
|
kind: z.enum(["scheduled", "event"]),
|
|
6829
6852
|
title: z.string(),
|
|
6830
|
-
|
|
6853
|
+
task: automationTaskSchema,
|
|
6831
6854
|
status: z.enum([
|
|
6832
6855
|
"active",
|
|
6833
6856
|
"blocked",
|
|
@@ -6861,7 +6884,7 @@ function mcpAutomation(automation) {
|
|
|
6861
6884
|
id: automation.id,
|
|
6862
6885
|
kind: automation.kind,
|
|
6863
6886
|
title: automation.title,
|
|
6864
|
-
|
|
6887
|
+
task: automation.task,
|
|
6865
6888
|
status: automation.status,
|
|
6866
6889
|
...automation.statusReason ? { statusReason: automation.statusReason } : void 0,
|
|
6867
6890
|
trigger: triggerText(automation),
|
|
@@ -7099,15 +7122,16 @@ function registerSearchAutomationsTool(server, { user }) {
|
|
|
7099
7122
|
const listQuery = automationListQuerySchema.shape;
|
|
7100
7123
|
server.registerTool("searchAutomations", {
|
|
7101
7124
|
title: "Search automations",
|
|
7102
|
-
description: "Search the automations that you can see, newest first. An automation is a saved instruction that runs on a schedule or on events.",
|
|
7125
|
+
description: "Search the automations that you can see, newest first. An automation is a saved instruction or skill that runs on a schedule or on events.",
|
|
7103
7126
|
inputSchema: {
|
|
7104
|
-
q: listQuery.q.describe("Text to search for in titles and
|
|
7127
|
+
q: listQuery.q.describe("Text to search for in titles, instructions, and skill names."),
|
|
7105
7128
|
scope: z.enum([
|
|
7106
7129
|
"all",
|
|
7107
7130
|
"mine",
|
|
7108
7131
|
"attention"
|
|
7109
7132
|
]).default("all").describe("`mine` lists the ones you created. `attention` lists the ones that are blocked, cannot run, or had a problem in their last run."),
|
|
7110
7133
|
state: listQuery.state.describe("Filter by state."),
|
|
7134
|
+
skill: listQuery.skill.describe("Only automations that run this skill, by exact name."),
|
|
7111
7135
|
page: listQuery.page.describe("Page number, from 1.")
|
|
7112
7136
|
},
|
|
7113
7137
|
outputSchema: {
|
|
@@ -7120,11 +7144,12 @@ function registerSearchAutomationsTool(server, { user }) {
|
|
|
7120
7144
|
openWorldHint: false,
|
|
7121
7145
|
readOnlyHint: true
|
|
7122
7146
|
}
|
|
7123
|
-
}, async ({ page, q, scope, state }) => {
|
|
7147
|
+
}, async ({ page, q, scope, skill, state }) => {
|
|
7124
7148
|
const list = await readViewerAutomations(user, automationListQuerySchema.parse({
|
|
7125
7149
|
page,
|
|
7126
7150
|
q,
|
|
7127
7151
|
scope,
|
|
7152
|
+
skill,
|
|
7128
7153
|
state
|
|
7129
7154
|
}));
|
|
7130
7155
|
return mcpToolResult({
|
|
@@ -8451,7 +8476,10 @@ async function createApp(options) {
|
|
|
8451
8476
|
return backgroundCompactionPOST(c.req.raw);
|
|
8452
8477
|
});
|
|
8453
8478
|
app.get("/api/internal/heartbeat", (c) => {
|
|
8454
|
-
return GET$3(c.req.raw, waitUntil, {
|
|
8479
|
+
return GET$3(c.req.raw, waitUntil, {
|
|
8480
|
+
conversationWorkQueue,
|
|
8481
|
+
events
|
|
8482
|
+
});
|
|
8455
8483
|
});
|
|
8456
8484
|
app.get("/api/internal/retention", (c) => {
|
|
8457
8485
|
return GET$2(c.req.raw);
|