@sentry/junior 0.251.0 → 0.253.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/{admin-Dth5-1lw.js → admin-CZnlnlg9.js} +1 -1
- package/dist/{agent-hooks-Ctw_jKaS.js → agent-hooks-CvcbAtJH.js} +8 -8
- package/dist/{agent-runner-dgQdPoGH.js → agent-runner-B4FMVbCs.js} +20 -20
- package/dist/api/schema.d.ts +32 -32
- package/dist/api.js +22 -22
- package/dist/app.js +122 -84
- package/dist/{assistant-reply-DBFRnZRx.js → assistant-reply-BU05IECs.js} +1 -1
- package/dist/{briefs-SDwPKduW.js → briefs-DyspoG90.js} +2 -2
- package/dist/{catalog-runtime-ulFceOA-.js → catalog-runtime-Br8s-TYx.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +2 -2
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +3 -3
- package/dist/cli/upgrade.js +3 -3
- package/dist/{client-DMt9kArs.js → client-CRVXpEWi.js} +2 -2
- package/dist/{config-iEOq080E.js → config-B7joRWt7.js} +2 -2
- package/dist/{connections-BFU6GarA.js → connections-CGPYNw2B.js} +9 -9
- package/dist/{conversation-privacy-yZhQHnBe.js → conversation-privacy-0JuTT_OJ.js} +1 -1
- package/dist/{credential-sync-GW0Rj57H.js → credential-sync-C-k3fnY5.js} +14 -14
- package/dist/{executor-BeH9LDKI.js → executor-YL577nNt.js} +88 -20
- package/dist/{images-hIXWwpRg.js → images-DopOctPc.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{job-queue-Bxlao6zL.js → job-queue-CIhKXUE3.js} +1 -1
- package/dist/{logging-BkI10z0D.js → logging-B0QxCh3D.js} +1 -1
- package/dist/{message-BUcVfXmK.js → message-DQvor8lM.js} +3 -3
- package/dist/nitro.js +3 -3
- package/dist/{oauth-callback-server-CYSEV35l.js → oauth-callback-server-BT7cSxBm.js} +2 -2
- package/dist/{pending-auth-h0B3FQEo.js → pending-auth-CwA1uLA9.js} +2 -2
- package/dist/{profile-AsD2uz0m.js → profile-p1oiViVs.js} +4 -4
- package/dist/{registry-CN2Nie72.js → registry-BO2LM2oW.js} +1 -1
- package/dist/{resolve-CrgwPWTS.js → resolve-CtWKGuKE.js} +2 -2
- package/dist/{result-Cokw_MYC.js → result-DR5JTBcb.js} +6 -6
- package/dist/{runner-D-VZlBb_.js → runner-BIxTJF9a.js} +9 -9
- package/dist/{sandbox-egress-signals-Sie51RW0.js → sandbox-egress-signals-DF3Pu813.js} +1 -1
- package/dist/{session-stop-DD0k0BXI.js → session-stop-BRq8Vxrr.js} +10 -10
- package/dist/{skills-CpyJJyqH.js → skills-DitcC3Vw.js} +2 -2
- package/dist/{spawn-DX3YjDtm.js → spawn-CHQ42PAo.js} +2 -2
- package/dist/{store-D-n2b2cI.js → store-DIFp9K52.js} +6 -6
- package/dist/{task-queue-Bj2hFpjr.js → task-queue-UAeJGLYM.js} +3 -3
- package/dist/{task-runner-B3g16wjr.js → task-runner-DwD-i2ta.js} +147 -131
- package/dist/{tasks-DDzBxMio.js → tasks-DThIG7F-.js} +136 -218
- package/dist/{thread-state-BlD6loX7.js → thread-state-BQxkL7Xm.js} +6 -6
- package/dist/{turn-failure-response-BRlfATgu.js → turn-failure-response-OAIxgzNh.js} +7 -7
- package/dist/{turn-lifecycle-hMCbr_Ah.js → turn-lifecycle-BAEJpjDI.js} +1 -1
- package/dist/{turn-session-routing-DLb6eQMT.js → turn-session-routing-F5s728f0.js} +1 -1
- package/dist/{validation-C2lG6yVH.js → validation-DFM4-vDr.js} +1 -1
- package/dist/{version-CyJ_kMe8.js → version-B80CD9sN.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-C8u1HAdN.js → viewer-CPxNfHWa.js} +3 -3
- package/dist/{web-input-DHgIfSwj.js → web-input-DIO177R0.js} +80 -121
- package/dist/{work-hoPN8qjl.js → work-Dl5KPKjW.js} +9 -9
- package/dist/{worker-CavJZxi8.js → worker-CJkE86Co.js} +5 -5
- package/migrations/0055_automations.sql +125 -0
- package/migrations/0056_automation_runs.sql +69 -0
- package/migrations/meta/0055_snapshot.json +3948 -0
- package/migrations/meta/0056_snapshot.json +4280 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +4 -4
|
@@ -1,44 +1,43 @@
|
|
|
1
|
-
import { A as resolveSlackChannelIdFromMessage, B as effectiveTaskOutcomes, Bt as RetryableDeliveryError, C as renderBlockText, D as storeAttachment, Gt as shouldEmitDevAgentTrace, Lt as createUserTokenStore, M as getConversationInfo, N as listThreadReplies, O as parseSlackThreadId, Rt as buildSteeringPiMessage, S as renderAttachmentText, Ut as AuthorizationFlowDisabledError, a as buildAuthPauseResponse, h as latestProgressStatus, j as resolveSlackChannelIdFromThreadId, k as readSlackRawMessageContext, m as PluginCredentialFailureError, n as executeAgentRun, r as createContextCompactor, t as createAgentRunner, z as eventAutomationTriggerAvailable, zt as withoutSavedSteeringMessages } from "./agent-runner-
|
|
2
|
-
import { f as escapeXml, i as completeText, r as completeObject, v as isProviderRetryError } from "./client-
|
|
3
|
-
import { C as withLogContext, I as isRecord, L as toOptionalNumber, R as toOptionalString, _ as setSentryUser, b as setTags, d as logException, f as logInfo, n as createChatSdkLogger, o as getActiveTraceId, p as logWarn, t as buildTurnFailureResponse, u as logError, v as setSpanAttributes, w as withSpan } from "./logging-
|
|
4
|
-
import { c as getSlackClientSecret, i as getChatConfig, l as getSlackSigningSecret, n as botConfig, o as getSlackBotToken, s as getSlackClientId, v as normalizeSlackEmojiName } from "./config-
|
|
1
|
+
import { A as resolveSlackChannelIdFromMessage, B as effectiveTaskOutcomes, Bt as RetryableDeliveryError, C as renderBlockText, D as storeAttachment, Gt as shouldEmitDevAgentTrace, Lt as createUserTokenStore, M as getConversationInfo, N as listThreadReplies, O as parseSlackThreadId, Rt as buildSteeringPiMessage, S as renderAttachmentText, Ut as AuthorizationFlowDisabledError, a as buildAuthPauseResponse, h as latestProgressStatus, j as resolveSlackChannelIdFromThreadId, k as readSlackRawMessageContext, m as PluginCredentialFailureError, n as executeAgentRun, r as createContextCompactor, t as createAgentRunner, z as eventAutomationTriggerAvailable, zt as withoutSavedSteeringMessages } from "./agent-runner-B4FMVbCs.js";
|
|
2
|
+
import { f as escapeXml, i as completeText, r as completeObject, v as isProviderRetryError } from "./client-CRVXpEWi.js";
|
|
3
|
+
import { C as withLogContext, I as isRecord, L as toOptionalNumber, R as toOptionalString, _ as setSentryUser, b as setTags, d as logException, f as logInfo, n as createChatSdkLogger, o as getActiveTraceId, p as logWarn, t as buildTurnFailureResponse, u as logError, v as setSpanAttributes, w as withSpan } from "./logging-B0QxCh3D.js";
|
|
4
|
+
import { c as getSlackClientSecret, i as getChatConfig, l as getSlackSigningSecret, n as botConfig, o as getSlackBotToken, s as getSlackClientId, v as normalizeSlackEmojiName } from "./config-B7joRWt7.js";
|
|
5
5
|
import { o as modelIdForProfile, r as defaultModelId } from "./model-profile-BwU8mqwD.js";
|
|
6
6
|
import { a as isUserActor, g as parseSlackMessageTs, i as isActorUserId, l as parseSlackChannelId, n as createSlackActor, o as parseActorUserId, r as createSlackResumeActor, t as createActor } from "./actor-BTtLaeWy.js";
|
|
7
|
-
import { M as createSlackDestination, P as requireSlackDestination, c as getConversationEventStore, d as getDb, f as getSqlExecutor, u as getConversationStore } from "./viewer-
|
|
7
|
+
import { M as createSlackDestination, P as requireSlackDestination, c as getConversationEventStore, d as getDb, f as getSqlExecutor, u as getConversationStore } from "./viewer-CPxNfHWa.js";
|
|
8
8
|
import { c as juniorIdentities, d as juniorDestinations, l as juniorUsers } from "./agent-invocations-D_YoNnAn.js";
|
|
9
|
-
import {
|
|
9
|
+
import { o as juniorAutomationRuns, s as juniorAutomations } from "./executor-YL577nNt.js";
|
|
10
10
|
import { p as instructionProvenanceFor } from "./history-9pO1Zd4Y.js";
|
|
11
|
-
import { d as credentialContextForActor } from "./registry-
|
|
12
|
-
import { $ as listTurnSummaries, $t as appendThreadContextMessages, At as loadProjection, D as sameDefinitionValue, Et as commitMessages, Gt as hydrateConversationMessages, H as removeReactionFromMessage, I as truncateStatusText, J as saveTurnCheckpoint, Jt as persistConversationMessageSummaries, Kt as persistConversationMessages, L as addReactionToMessage, Lt as recordAuthorizationCompleted, M as formatSlackLink, N as normalizeSlackReplyMarkdown, Ot as loadConversationProjection, P as normalizeSlackStatusText, Q as getTurnRecord, St as trimTrailingAssistantMessages, T as listAutomationVersions, Tt as commitAcceptedReply, V as postSlackMessage, Vt as recordSubscribedReplyRoute, X as completeTurnRecord, Y as abandonTurnRecord, Yt as resolveConversationTitle, Z as failTurnRecord, Zt as fallbackShortTitle, _ as listDeletedEventAutomationsCreatedBy, a as readScheduledAutomation, an as markConversationMessage, cn as turnHasReply, en as buildConversationContext, et as recordTurnSummary, g as getEventAutomation, i as parseScheduledAutomationRow, in as isHumanConversationMessage, j as escapeSlackMrkdwnText, l as withScheduledAutomationLock, ln as upsertConversationMessage, m as eventAutomationBelongsToUser, nn as estimateConversationContextTokens, on as normalizeConversationText, ot as buildTurnErrorResponse, p as deleteEventAutomation, q as loadTurnCheckpoint, rn as getConversationMessageSlackTs, s as saveScheduledAutomationInLock, sn as recordDeliveredAssistantMessage, tn as createConversationMemoryService, tt as persistWithRetry, w as automationDefinition, y as parseEventAutomationRow } from "./tasks-
|
|
13
|
-
import { Et as getSlackFileId, Gt as normalizeSlackConversationId, Ht as getSlackClient, Kt as runWithSlackInstallationToken, Lt as lookupSlackUser, Ot as readAttachmentVisionSummary, Rt as SlackActionError, Tt as buildSentryConversationUrl, V as cancelSubscriptions, Vt as getHeaderString, Wt as isDmChannel, at as getDashboardConversationLink, it as JUNIOR_THREAD_STATE_TTL_MS, kt as recordSlackAttachment, o as getPluginSlackConversationLink, ot as getDashboardObjectIconLink, rt as verifyTimerWatchCredentialSubject, zt as downloadPrivateSlackFile } from "./agent-hooks-
|
|
11
|
+
import { d as credentialContextForActor } from "./registry-BO2LM2oW.js";
|
|
12
|
+
import { $ as listTurnSummaries, $t as appendThreadContextMessages, At as loadProjection, D as sameDefinitionValue, Et as commitMessages, Gt as hydrateConversationMessages, H as removeReactionFromMessage, I as truncateStatusText, J as saveTurnCheckpoint, Jt as persistConversationMessageSummaries, Kt as persistConversationMessages, L as addReactionToMessage, Lt as recordAuthorizationCompleted, M as formatSlackLink, N as normalizeSlackReplyMarkdown, Ot as loadConversationProjection, P as normalizeSlackStatusText, Q as getTurnRecord, St as trimTrailingAssistantMessages, T as listAutomationVersions, Tt as commitAcceptedReply, V as postSlackMessage, Vt as recordSubscribedReplyRoute, X as completeTurnRecord, Y as abandonTurnRecord, Yt as resolveConversationTitle, Z as failTurnRecord, Zt as fallbackShortTitle, _ as listDeletedEventAutomationsCreatedBy, a as readScheduledAutomation, an as markConversationMessage, cn as turnHasReply, en as buildConversationContext, et as recordTurnSummary, g as getEventAutomation, i as parseScheduledAutomationRow, in as isHumanConversationMessage, j as escapeSlackMrkdwnText, l as withScheduledAutomationLock, ln as upsertConversationMessage, m as eventAutomationBelongsToUser, nn as estimateConversationContextTokens, on as normalizeConversationText, ot as buildTurnErrorResponse, p as deleteEventAutomation, q as loadTurnCheckpoint, rn as getConversationMessageSlackTs, s as saveScheduledAutomationInLock, sn as recordDeliveredAssistantMessage, tn as createConversationMemoryService, tt as persistWithRetry, w as automationDefinition, y as parseEventAutomationRow } from "./tasks-DThIG7F-.js";
|
|
13
|
+
import { Et as getSlackFileId, Gt as normalizeSlackConversationId, Ht as getSlackClient, Kt as runWithSlackInstallationToken, Lt as lookupSlackUser, Ot as readAttachmentVisionSummary, Rt as SlackActionError, Tt as buildSentryConversationUrl, V as cancelSubscriptions, Vt as getHeaderString, Wt as isDmChannel, at as getDashboardConversationLink, it as JUNIOR_THREAD_STATE_TTL_MS, kt as recordSlackAttachment, o as getPluginSlackConversationLink, ot as getDashboardObjectIconLink, rt as verifyTimerWatchCredentialSubject, zt as downloadPrivateSlackFile } from "./agent-hooks-CvcbAtJH.js";
|
|
14
14
|
import { F as readMessageAttachments, R as isVisionImageMediaType } from "./conversation-T18Xlkx9.js";
|
|
15
|
-
import { E as acquireActiveLock, O as withLock, T as MUTATION_LOCK_TTL_MS, w as getStateAdapter } from "./profile-
|
|
16
|
-
import { a as wasPendingAuthStopped, c as getThreadStopDecision, l as buildDeterministicAssistantMessageId, o as decideSubscribedThreadReply, r as clearPendingAuth, s as getSubscribedReplyPreflightDecision, u as buildDeterministicTurnId } from "./pending-auth-
|
|
15
|
+
import { E as acquireActiveLock, O as withLock, T as MUTATION_LOCK_TTL_MS, w as getStateAdapter } from "./profile-p1oiViVs.js";
|
|
16
|
+
import { a as wasPendingAuthStopped, c as getThreadStopDecision, l as buildDeterministicAssistantMessageId, o as decideSubscribedThreadReply, r as clearPendingAuth, s as getSubscribedReplyPreflightDecision, u as buildDeterministicTurnId } from "./pending-auth-CwA1uLA9.js";
|
|
17
17
|
import { a as TurnInputDeferredError, c as isTurnInputCommitLostError, d as markTurnCompleted, f as markTurnFailed, i as TurnInputCommitLostError, l as isTurnInputDeferredError, n as ConversationTurnBoundaryError, o as getConversationTurnBoundaryError, p as startActiveTurn, r as CooperativeTurnYieldError, s as isCooperativeTurnYieldError, u as markTurnClosed } from "./oauth-authorization-BA4Dt6a7.js";
|
|
18
|
-
import { n as getAssistantReplyText } from "./assistant-reply-
|
|
19
|
-
import { A as recordFinishedTurnForAutomatedLimit, F as finishedRunReply, P as deliversFinalText, R as runDispatchOutcome, c as timerWatchCredentialSubject, i as skipInputBeforeConversationStop, k as maybePostAutomatedTurnLimitNotice, l as getEventCatalog, s as isEventMailboxMetadata, v as automationEventCatalog } from "./session-stop-
|
|
18
|
+
import { n as getAssistantReplyText } from "./assistant-reply-BU05IECs.js";
|
|
19
|
+
import { A as recordFinishedTurnForAutomatedLimit, F as finishedRunReply, P as deliversFinalText, R as runDispatchOutcome, c as timerWatchCredentialSubject, i as skipInputBeforeConversationStop, k as maybePostAutomatedTurnLimitNotice, l as getEventCatalog, s as isEventMailboxMetadata, v as automationEventCatalog } from "./session-stop-BRq8Vxrr.js";
|
|
20
20
|
import { a as EVENT_SYSTEM_ACTOR, o as isEventConversationMessage } from "./prompt-C04mP1hu.js";
|
|
21
|
-
import { a as getVercelConversationWorkQueue, f as getTurnRequestDeadline } from "./job-queue-
|
|
22
|
-
import { E as stopConversationWork, g as getConversationWorkState, h as getConversation, m as ensureConversationWake, n as appendAndEnqueueExclusiveInboundMessage, r as appendAndEnqueueInboundMessage, w as requestConversationWork } from "./store-
|
|
21
|
+
import { a as getVercelConversationWorkQueue, f as getTurnRequestDeadline } from "./job-queue-CIhKXUE3.js";
|
|
22
|
+
import { E as stopConversationWork, g as getConversationWorkState, h as getConversation, m as ensureConversationWake, n as appendAndEnqueueExclusiveInboundMessage, r as appendAndEnqueueInboundMessage, w as requestConversationWork } from "./store-DIFp9K52.js";
|
|
23
23
|
import { l as automationListQuerySchema } from "./automation-gznOMaQ2.js";
|
|
24
24
|
import { r as isExperimentalFeatureEnabled } from "./experimental-Qn9rKLgx.js";
|
|
25
25
|
import { c as sumUtcHoursIntoSixHours, m as healthReportSchema, t as webMessageId } from "./web-message-id-xPI_EFSC.js";
|
|
26
|
-
import {
|
|
27
|
-
import { a as withAgentInvocationResultActors, c as resolveMailboxTurnWork, f as joinMailboxText, i as startAgentInvocationsForChildInput, l as sourceFromTurnInput, o as getAuthPausedConversationTurnId, s as getEventBatchDelayMs, t as enqueueAgentInvocationResult, u as turnInputFactsFromConversationMessage } from "./result-
|
|
28
|
-
import { n as getTurnLifecycle, t as ConversationTurnLifecycleService } from "./turn-lifecycle-
|
|
29
|
-
import { i as resolveAgentInvocationId, o as AgentRunError, s as executeTurn, t as createAgentInvocationWorker } from "./work-
|
|
30
|
-
import { a as persistThreadState, c as configValueSchema, i as persistThreadRuntimeState, n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState, s as coerceThreadConversationState, t as getLocationConfigurationService } from "./thread-state-
|
|
31
|
-
import { c as deleteWebAuthorization, d as getPausedTurnRequest, m as getTurnAuthorization, p as wakePausedTurn, s as createWebAuthorization, u as createPausedTurns } from "./connections-
|
|
32
|
-
import { n as resolveTurnSessionRouting } from "./turn-session-routing-
|
|
33
|
-
import { t as bindMessageAgent } from "./message-
|
|
34
|
-
import { t as bindSpawnAgent } from "./spawn-
|
|
35
|
-
import { a as persistAuthPauseTurnState, c as getTurnUserSlackMessageTs, d as loadPendingMessageCards, i as completeAuthPauseTurn, l as buildDeliveredTurnStatePatch, n as getAgentTurnDiagnosticsAttributes, o as getTurnUserMessage, r as requireTurnFailureEventId, s as getTurnUserReplyAttachmentContext, t as finalizeFailedTurnReplyWithEvent, u as getInterruptionMarker } from "./turn-failure-response-
|
|
36
|
-
import { r as storeInputImages } from "./images-
|
|
26
|
+
import { A as readAutomationRuns, C as readAutomationExecutionByConversationId, D as readAutomationExecutionStatusHours, E as readAutomationExecutionStatusDays, O as readAutomationExecutionSummaries, T as readAutomationExecutionHours, _ as markDispatchCompleted, a as confirmDispatchMailboxAppend, c as getDispatchIdForConversation, d as getDispatchTurnId, g as markDispatchBlocked, h as markDispatchAwaitingResume, i as claimDispatchMailboxAppend, k as readAutomationExecutions, l as getDispatchInputMessageId, n as scheduleSessionCompletedPluginTasks, p as isTerminalDispatchStatus, s as getDispatchConversationId, t as processPluginTask, u as getDispatchRecord, v as markDispatchFailed, w as readAutomationExecutionDays, x as emptyAutomationRunWindows, y as markDispatchRunning } from "./task-runner-DwD-i2ta.js";
|
|
27
|
+
import { a as withAgentInvocationResultActors, c as resolveMailboxTurnWork, f as joinMailboxText, i as startAgentInvocationsForChildInput, l as sourceFromTurnInput, o as getAuthPausedConversationTurnId, s as getEventBatchDelayMs, t as enqueueAgentInvocationResult, u as turnInputFactsFromConversationMessage } from "./result-DR5JTBcb.js";
|
|
28
|
+
import { n as getTurnLifecycle, t as ConversationTurnLifecycleService } from "./turn-lifecycle-BAEJpjDI.js";
|
|
29
|
+
import { i as resolveAgentInvocationId, o as AgentRunError, s as executeTurn, t as createAgentInvocationWorker } from "./work-Dl5KPKjW.js";
|
|
30
|
+
import { a as persistThreadState, c as configValueSchema, i as persistThreadRuntimeState, n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState, s as coerceThreadConversationState, t as getLocationConfigurationService } from "./thread-state-BQxkL7Xm.js";
|
|
31
|
+
import { c as deleteWebAuthorization, d as getPausedTurnRequest, m as getTurnAuthorization, p as wakePausedTurn, s as createWebAuthorization, u as createPausedTurns } from "./connections-CGPYNw2B.js";
|
|
32
|
+
import { n as resolveTurnSessionRouting } from "./turn-session-routing-F5s728f0.js";
|
|
33
|
+
import { t as bindMessageAgent } from "./message-DQvor8lM.js";
|
|
34
|
+
import { t as bindSpawnAgent } from "./spawn-CHQ42PAo.js";
|
|
35
|
+
import { a as persistAuthPauseTurnState, c as getTurnUserSlackMessageTs, d as loadPendingMessageCards, i as completeAuthPauseTurn, l as buildDeliveredTurnStatePatch, n as getAgentTurnDiagnosticsAttributes, o as getTurnUserMessage, r as requireTurnFailureEventId, s as getTurnUserReplyAttachmentContext, t as finalizeFailedTurnReplyWithEvent, u as getInterruptionMarker } from "./turn-failure-response-OAIxgzNh.js";
|
|
36
|
+
import { r as storeInputImages } from "./images-DopOctPc.js";
|
|
37
37
|
import { z } from "zod";
|
|
38
38
|
import { createHash } from "node:crypto";
|
|
39
39
|
import { and, asc, count, desc, eq, exists, inArray, ne, or, sql } from "drizzle-orm";
|
|
40
40
|
import { createSlackSource, createWebSource, localDestinationSchema, objectFactFields, objectPresentation, objectTypeSchema } from "@sentry/junior-plugin-api";
|
|
41
|
-
import { unionAll } from "drizzle-orm/pg-core";
|
|
42
41
|
import { del, get, put } from "@vercel/blob";
|
|
43
42
|
import { Message, ThreadImpl, stringifyMarkdown } from "chat";
|
|
44
43
|
import { SlackFormatConverter, createSlackAdapter } from "@chat-adapter/slack";
|
|
@@ -2741,65 +2740,37 @@ function viewerAutomationCollection(user) {
|
|
|
2741
2740
|
const db = getDb();
|
|
2742
2741
|
const identities = user.identities.filter((identity) => identity.provider === "slack");
|
|
2743
2742
|
const teamIds = identities.flatMap((identity) => identity.providerTenantId ? [identity.providerTenantId] : []);
|
|
2744
|
-
const
|
|
2745
|
-
const event = juniorEventAutomations;
|
|
2743
|
+
const automation = juniorAutomations;
|
|
2746
2744
|
const destination = juniorDestinations;
|
|
2747
|
-
const
|
|
2748
|
-
const
|
|
2745
|
+
const isScheduled = eq(automation.kind, "scheduled");
|
|
2746
|
+
const owned = or(and(isScheduled, inArray(automation.creatorIdentityId, user.identities.map((identity) => identity.id))), ...identities.map((identity) => and(eq(automation.kind, "event"), eq(automation.teamId, identity.providerTenantId ?? ""), eq(automation.creatorSlackUserId, identity.providerSubjectId)))) ?? sql`false`;
|
|
2749
2747
|
const publicDestination = sql`coalesce(${destination.visibility} = 'public', false)`;
|
|
2750
|
-
const
|
|
2751
|
-
const
|
|
2752
|
-
function fields(record, teamId) {
|
|
2753
|
-
return {
|
|
2754
|
-
creator: sql`${teamId} || ':' || (${record}->'createdBy'->>'slackUserId')`.as("creator"),
|
|
2755
|
-
creatorLabel: sql`coalesce(nullif(trim(${record}->'createdBy'->>'fullName'), ''), nullif(trim(${record}->'createdBy'->>'userName'), ''), ${record}->'createdBy'->>'slackUserId')`.as("creator_label"),
|
|
2756
|
-
destination: sql`${teamId} || ':' || (${record}->'destination'->>'channelId')`.as("destination"),
|
|
2757
|
-
destinationLabel: sql`coalesce(nullif(${destination.displayName}, ''), ${record}->'destination'->>'channelId')`.as("destination_label"),
|
|
2758
|
-
isPublic: publicDestination.as("is_public"),
|
|
2759
|
-
instruction: sql`${record}->'task'->>'text'`.as("instruction")
|
|
2760
|
-
};
|
|
2761
|
-
}
|
|
2762
|
-
function destinationJoin(record, teamId) {
|
|
2763
|
-
return and(eq(destination.provider, "slack"), sql`${destination.providerTenantId} = ${teamId}`, sql`${destination.providerDestinationId} = ${record}->'destination'->>'channelId'`);
|
|
2764
|
-
}
|
|
2765
|
-
const available = or(...Object.entries(automationEventCatalog(getEventCatalog())).map(([namespace, registration]) => {
|
|
2748
|
+
const publicToViewer = and(inArray(automation.teamId, teamIds), publicDestination, ne(automation.status, "completed"));
|
|
2749
|
+
const available = or(isScheduled, ...Object.entries(automationEventCatalog(getEventCatalog())).map(([namespace, registration]) => {
|
|
2766
2750
|
const events = registration.resourceTypes.flatMap((resource) => resource.supportedEvents);
|
|
2767
|
-
return and(eq(
|
|
2751
|
+
return and(eq(automation.namespace, namespace), sql`${automation.record}->'trigger'->'events' <@ ${JSON.stringify(events)}::jsonb`);
|
|
2768
2752
|
})) ?? sql`false`;
|
|
2769
|
-
const
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
createdAtMs: scheduled.createdAtMs,
|
|
2780
|
-
state: sql`${scheduled.status}`.as("state"),
|
|
2781
|
-
unavailable: sql`false`.as("unavailable"),
|
|
2782
|
-
attention: sql`${scheduled.status} not in ('paused', 'completed') and (${scheduled.status} = 'blocked' or ${lastRunNeedsAttention("scheduled", scheduled.id)})`.as("attention"),
|
|
2783
|
-
owned: sql`${scheduledOwned}`.as("owned"),
|
|
2784
|
-
resource: sql`''`.as("resource"),
|
|
2785
|
-
...fields(scheduled.record, scheduled.teamId)
|
|
2786
|
-
}).from(scheduled).leftJoin(destination, destinationJoin(scheduled.record, scheduled.teamId)).where(and(inArray(scheduled.status, [
|
|
2787
|
-
"active",
|
|
2788
|
-
"blocked",
|
|
2789
|
-
"paused",
|
|
2790
|
-
"completed"
|
|
2791
|
-
]), or(scheduledOwned, scheduledPublic))), db.select({
|
|
2792
|
-
kind: sql`'event'`.as("kind"),
|
|
2793
|
-
id: event.id,
|
|
2794
|
-
title: sql`${event.title}`.as("title"),
|
|
2795
|
-
createdAtMs: event.createdAtMs,
|
|
2796
|
-
state: sql`${event.status}`.as("state"),
|
|
2753
|
+
const runs = juniorAutomationRuns;
|
|
2754
|
+
const lastRunNeedsAttention = sql`coalesce((select ${runs.status} in ('failed', 'blocked') from ${runs}
|
|
2755
|
+
where ${runs.automationId} = ${automation.id} and ${runs.status} in ('blocked', 'completed', 'failed') and ${runs.completedAtMs} is not null
|
|
2756
|
+
order by ${runs.completedAtMs} desc, ${runs.id} desc limit 1), false)`;
|
|
2757
|
+
return db.select({
|
|
2758
|
+
kind: automation.kind,
|
|
2759
|
+
id: automation.id,
|
|
2760
|
+
title: automation.title,
|
|
2761
|
+
createdAtMs: automation.createdAtMs,
|
|
2762
|
+
state: sql`${automation.status}`.as("state"),
|
|
2797
2763
|
unavailable: sql`not (${available})`.as("unavailable"),
|
|
2798
|
-
attention: sql`${
|
|
2799
|
-
owned: sql`${
|
|
2800
|
-
resource: sql`concat_ws(' ', ${
|
|
2801
|
-
|
|
2802
|
-
|
|
2764
|
+
attention: sql`${automation.status} not in ('paused', 'completed') and (${automation.status} = 'blocked' or not (${available}) or ${lastRunNeedsAttention})`.as("attention"),
|
|
2765
|
+
owned: sql`${owned}`.as("owned"),
|
|
2766
|
+
resource: sql`case when ${isScheduled} then '' else concat_ws(' ', ${automation.identifier}, ${automation.record}->'trigger'->>'label', ${automation.namespace}) end`.as("resource"),
|
|
2767
|
+
creator: sql`${automation.teamId} || ':' || ${automation.creatorSlackUserId}`.as("creator"),
|
|
2768
|
+
creatorLabel: sql`coalesce(nullif(trim(${automation.record}->'createdBy'->>'fullName'), ''), nullif(trim(${automation.record}->'createdBy'->>'userName'), ''), ${automation.creatorSlackUserId})`.as("creator_label"),
|
|
2769
|
+
destination: sql`${automation.teamId} || ':' || ${automation.channelId}`.as("destination"),
|
|
2770
|
+
destinationLabel: sql`coalesce(nullif(${destination.displayName}, ''), ${automation.channelId})`.as("destination_label"),
|
|
2771
|
+
isPublic: publicDestination.as("is_public"),
|
|
2772
|
+
instruction: automation.instruction
|
|
2773
|
+
}).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, publicToViewer))).as("accessible_automations");
|
|
2803
2774
|
}
|
|
2804
2775
|
/** Read an SQL page and complete, access-scoped counts and filter options. */
|
|
2805
2776
|
async function readAutomationCollection(user, input) {
|
|
@@ -3040,7 +3011,7 @@ async function automationSummaryForCandidate(candidate) {
|
|
|
3040
3011
|
const [destinations, creators, stats] = await Promise.all([
|
|
3041
3012
|
destinationDetails([candidate.task.destination]),
|
|
3042
3013
|
creatorProfiles([candidate]),
|
|
3043
|
-
readAutomationExecutionSummaries(
|
|
3014
|
+
readAutomationExecutionSummaries([candidate.task.id])
|
|
3044
3015
|
]);
|
|
3045
3016
|
const destination = destinations.get(destinationKey(candidate.task.destination)) ?? {
|
|
3046
3017
|
label: `Channel ${candidate.task.destination.channelId}`,
|
|
@@ -3085,38 +3056,38 @@ async function readViewerAutomations(user, input = automationListQuerySchema.par
|
|
|
3085
3056
|
const { rows, ...page } = await readAutomationCollection(user, input);
|
|
3086
3057
|
const db = getDb();
|
|
3087
3058
|
const ids = rows.map((row) => row.id);
|
|
3088
|
-
const
|
|
3059
|
+
const stored = ids.length ? await db.select().from(juniorAutomations).where(inArray(juniorAutomations.id, ids)) : [];
|
|
3089
3060
|
const identityIds = new Set(user.identities.map((identity) => identity.id));
|
|
3090
3061
|
const candidates = /* @__PURE__ */ new Map();
|
|
3091
|
-
for (const row of
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3062
|
+
for (const row of stored) {
|
|
3063
|
+
if (row.kind === "scheduled") {
|
|
3064
|
+
const task = parseScheduledAutomationRow(row);
|
|
3065
|
+
if (task && task.status !== "deleted") candidates.set(task.id, {
|
|
3066
|
+
kind: "scheduled",
|
|
3067
|
+
task,
|
|
3068
|
+
ownedByViewer: identityIds.has(task.creatorIdentityId)
|
|
3069
|
+
});
|
|
3070
|
+
continue;
|
|
3071
|
+
}
|
|
3100
3072
|
const task = parseEventAutomationRow(row);
|
|
3101
|
-
if (task.status !== "deleted") candidates.set(
|
|
3073
|
+
if (task.status !== "deleted") candidates.set(task.id, {
|
|
3102
3074
|
kind: "event",
|
|
3103
3075
|
task,
|
|
3104
3076
|
ownedByViewer: eventAutomationBelongsToUser(task, user)
|
|
3105
3077
|
});
|
|
3106
3078
|
}
|
|
3107
3079
|
const selected = rows.flatMap((row) => {
|
|
3108
|
-
const candidate = candidates.get(
|
|
3080
|
+
const candidate = candidates.get(row.id);
|
|
3109
3081
|
return candidate ? [candidate] : [];
|
|
3110
3082
|
});
|
|
3111
3083
|
const [destinations, creators] = await Promise.all([destinationDetails(selected.map(({ task }) => task.destination)), creatorProfiles(selected)]);
|
|
3112
3084
|
const visible = selected.filter((candidate) => candidate.ownedByViewer || destinations.get(destinationKey(candidate.task.destination))?.visibility === "public");
|
|
3113
3085
|
const collection = viewerAutomationCollection(user);
|
|
3114
|
-
const access = exists(getDb().select({ id: collection.id }).from(collection).where(
|
|
3115
|
-
const [executionDays, executionHours,
|
|
3086
|
+
const access = exists(getDb().select({ id: collection.id }).from(collection).where(eq(collection.id, juniorAutomationRuns.automationId)));
|
|
3087
|
+
const [executionDays, executionHours, stats] = await Promise.all([
|
|
3116
3088
|
readAutomationExecutionDays(90, { access }),
|
|
3117
3089
|
readAutomationExecutionHours(168, { access }),
|
|
3118
|
-
readAutomationExecutionSummaries(
|
|
3119
|
-
readAutomationExecutionSummaries("event", "junior", { automationIds: ids })
|
|
3090
|
+
readAutomationExecutionSummaries(ids)
|
|
3120
3091
|
]);
|
|
3121
3092
|
const automations = visible.map((candidate) => {
|
|
3122
3093
|
const destination = destinations.get(destinationKey(candidate.task.destination)) ?? {
|
|
@@ -3124,8 +3095,8 @@ async function readViewerAutomations(user, input = automationListQuerySchema.par
|
|
|
3124
3095
|
visibility: "private"
|
|
3125
3096
|
};
|
|
3126
3097
|
const creator = creators.get(creatorKey(candidate.task.destination.teamId, candidate.task.createdBy.slackUserId));
|
|
3127
|
-
if (candidate.kind === "scheduled") return scheduledAutomationSummary(candidate.task, candidate.ownedByViewer, destination,
|
|
3128
|
-
return eventAutomationSummary(candidate.task, candidate.ownedByViewer, destination,
|
|
3098
|
+
if (candidate.kind === "scheduled") return scheduledAutomationSummary(candidate.task, candidate.ownedByViewer, destination, stats.get(candidate.task.id), creator);
|
|
3099
|
+
return eventAutomationSummary(candidate.task, candidate.ownedByViewer, destination, stats.get(candidate.task.id), creator);
|
|
3129
3100
|
});
|
|
3130
3101
|
return {
|
|
3131
3102
|
executionDays,
|
|
@@ -3139,12 +3110,7 @@ async function readViewerAutomations(user, input = automationListQuerySchema.par
|
|
|
3139
3110
|
async function readDeletedOwnedScheduledAutomations(user) {
|
|
3140
3111
|
const identityIds = user.identities.map((identity) => identity.id);
|
|
3141
3112
|
if (identityIds.length === 0) return [];
|
|
3142
|
-
return (await getDb().select(
|
|
3143
|
-
creatorIdentityId: juniorSchedulerTasks.creatorIdentityId,
|
|
3144
|
-
id: juniorSchedulerTasks.id,
|
|
3145
|
-
record: juniorSchedulerTasks.record,
|
|
3146
|
-
title: juniorSchedulerTasks.title
|
|
3147
|
-
}).from(juniorSchedulerTasks).where(and(eq(juniorSchedulerTasks.status, "deleted"), inArray(juniorSchedulerTasks.creatorIdentityId, identityIds))).orderBy(desc(juniorSchedulerTasks.createdAtMs), desc(juniorSchedulerTasks.id)).limit(TASK_EXECUTION_LIST_LIMIT)).map(parseScheduledAutomationRow).filter((task) => task?.status === "deleted");
|
|
3113
|
+
return (await getDb().select().from(juniorAutomations).where(and(eq(juniorAutomations.kind, "scheduled"), eq(juniorAutomations.status, "deleted"), inArray(juniorAutomations.creatorIdentityId, identityIds))).orderBy(desc(juniorAutomations.createdAtMs), desc(juniorAutomations.id)).limit(TASK_EXECUTION_LIST_LIMIT)).map(parseScheduledAutomationRow).filter((task) => task?.status === "deleted");
|
|
3148
3114
|
}
|
|
3149
3115
|
/** Load deleted event automations the viewer still owns, newest first. */
|
|
3150
3116
|
async function readDeletedOwnedEventAutomations(user) {
|
|
@@ -3199,8 +3165,8 @@ async function readViewerAutomationRuns(user) {
|
|
|
3199
3165
|
}, automationTitles, automations);
|
|
3200
3166
|
}
|
|
3201
3167
|
const runs = await readAutomationRuns({
|
|
3202
|
-
|
|
3203
|
-
|
|
3168
|
+
automationIds: automations.map((automation) => automation.automationId),
|
|
3169
|
+
limit: 101
|
|
3204
3170
|
});
|
|
3205
3171
|
return {
|
|
3206
3172
|
runs: runs.slice(0, TASK_EXECUTION_LIST_LIMIT).map((run) => ({
|
|
@@ -3223,18 +3189,11 @@ async function readViewerAutomationExecutions(user, kind, id) {
|
|
|
3223
3189
|
const [automation, executions, executionDays, executionHours] = await Promise.all([
|
|
3224
3190
|
automationSummaryForCandidate(candidate),
|
|
3225
3191
|
readAutomationExecutions({
|
|
3226
|
-
|
|
3227
|
-
limit: 101
|
|
3228
|
-
automationId: id
|
|
3229
|
-
}),
|
|
3230
|
-
readAutomationExecutionStatusDays({
|
|
3231
|
-
kind,
|
|
3232
|
-
automationId: id
|
|
3192
|
+
automationId: id,
|
|
3193
|
+
limit: 101
|
|
3233
3194
|
}),
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
automationId: id
|
|
3237
|
-
})
|
|
3195
|
+
readAutomationExecutionStatusDays({ automationId: id }),
|
|
3196
|
+
readAutomationExecutionStatusHours({ automationId: id })
|
|
3238
3197
|
]);
|
|
3239
3198
|
return {
|
|
3240
3199
|
executionDays,
|
|
@@ -3249,7 +3208,7 @@ async function readViewerAutomationExecutions(user, kind, id) {
|
|
|
3249
3208
|
async function readViewerAutomationVersions(user, kind, id) {
|
|
3250
3209
|
const candidate = await resolveViewerTaskCandidate(user, kind, id);
|
|
3251
3210
|
if (!candidate) throw new ViewerTaskNotFoundError();
|
|
3252
|
-
const versions = await listAutomationVersions(getDb(),
|
|
3211
|
+
const versions = await listAutomationVersions(getDb(), id, 101);
|
|
3253
3212
|
const current = automationDefinition(candidate.task);
|
|
3254
3213
|
const listed = versions.slice(0, AUTOMATION_VERSION_LIST_LIMIT);
|
|
3255
3214
|
return {
|
|
@@ -3278,7 +3237,7 @@ async function readRunCredential(dispatchId, creator) {
|
|
|
3278
3237
|
credentialUser: subject.userId === creator.slackUserId ? creatorLabel(creator) : subject.userId
|
|
3279
3238
|
};
|
|
3280
3239
|
}
|
|
3281
|
-
/** Resolve the source task for one conversation when
|
|
3240
|
+
/** Resolve the source task for one conversation when an Automation run links it. */
|
|
3282
3241
|
async function readConversationSourceTask(args) {
|
|
3283
3242
|
const execution = await readAutomationExecutionByConversationId({ conversationId: args.conversationId });
|
|
3284
3243
|
if (!execution) return void 0;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
-
import { $ as getAgentInvocation, G as recordSubagentStarted, H as stopChildAgentsOf, J as createAgentInvocation, Q as getActiveAgentInvocationForConversation, Rt as buildSteeringPiMessage, Ut as AuthorizationFlowDisabledError, W as recordSubagentEnded, Wt as readBlockedReport, at as getAgentInvocationTurnId, ct as isTerminalAgentInvocation, dt as markAgentInvocationMailboxAppended, gt as reportReplacedAgentInvocation, ht as markAgentInvocationSteered, m as PluginCredentialFailureError, mt as markAgentInvocationRunning, pt as markAgentInvocationPaused, q as completeAgentInvocation, rt as getAgentInvocationMessageId, st as getLatestAgentInvocationForConversation, zt as withoutSavedSteeringMessages } from "./agent-runner-
|
|
3
|
-
import { n as botConfig } from "./config-
|
|
4
|
-
import { c as getConversationEventStore, u as getConversationStore } from "./viewer-
|
|
2
|
+
import { $ as getAgentInvocation, G as recordSubagentStarted, H as stopChildAgentsOf, J as createAgentInvocation, Q as getActiveAgentInvocationForConversation, Rt as buildSteeringPiMessage, Ut as AuthorizationFlowDisabledError, W as recordSubagentEnded, Wt as readBlockedReport, at as getAgentInvocationTurnId, ct as isTerminalAgentInvocation, dt as markAgentInvocationMailboxAppended, gt as reportReplacedAgentInvocation, ht as markAgentInvocationSteered, m as PluginCredentialFailureError, mt as markAgentInvocationRunning, pt as markAgentInvocationPaused, q as completeAgentInvocation, rt as getAgentInvocationMessageId, st as getLatestAgentInvocationForConversation, zt as withoutSavedSteeringMessages } from "./agent-runner-B4FMVbCs.js";
|
|
3
|
+
import { n as botConfig } from "./config-B7joRWt7.js";
|
|
4
|
+
import { c as getConversationEventStore, u as getConversationStore } from "./viewer-CPxNfHWa.js";
|
|
5
5
|
import { m as sameActorIdentity, u as agentInstructionProvenance } from "./history-9pO1Zd4Y.js";
|
|
6
|
-
import { J as saveTurnCheckpoint, Nt as openConversationProjection, Q as getTurnRecord, Y as abandonTurnRecord, Z as failTurnRecord, ct as isTurnExecutionLimitExceededError, dt as getTerminalAssistantMessages } from "./tasks-
|
|
6
|
+
import { J as saveTurnCheckpoint, Nt as openConversationProjection, Q as getTurnRecord, Y as abandonTurnRecord, Z as failTurnRecord, ct as isTurnExecutionLimitExceededError, dt as getTerminalAssistantMessages } from "./tasks-DThIG7F-.js";
|
|
7
7
|
import { c as isTurnInputCommitLostError, i as TurnInputCommitLostError, o as getConversationTurnBoundaryError } from "./oauth-authorization-BA4Dt6a7.js";
|
|
8
|
-
import { n as getAssistantReplyText } from "./assistant-reply-
|
|
9
|
-
import { A as recordFinishedTurnForAutomatedLimit, j as resetAutomatedTurnLimit, k as maybePostAutomatedTurnLimitNotice } from "./session-stop-
|
|
10
|
-
import { r as appendAndEnqueueInboundMessage } from "./store-
|
|
11
|
-
import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-
|
|
12
|
-
import { n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState } from "./thread-state-
|
|
8
|
+
import { n as getAssistantReplyText } from "./assistant-reply-BU05IECs.js";
|
|
9
|
+
import { A as recordFinishedTurnForAutomatedLimit, j as resetAutomatedTurnLimit, k as maybePostAutomatedTurnLimitNotice } from "./session-stop-BRq8Vxrr.js";
|
|
10
|
+
import { r as appendAndEnqueueInboundMessage } from "./store-DIFp9K52.js";
|
|
11
|
+
import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-BAEJpjDI.js";
|
|
12
|
+
import { n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState } from "./thread-state-BQxkL7Xm.js";
|
|
13
13
|
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
//#region src/chat/runtime/turn-execution.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
-
import { v as isProviderRetryError } from "./client-
|
|
3
|
-
import { C as withLogContext, d as logException, f as logInfo, p as logWarn } from "./logging-
|
|
4
|
-
import { i as getChatConfig } from "./config-
|
|
5
|
-
import { f as getTurnRequestDeadline, m as ConversationQueueMessageRejectedError } from "./job-queue-
|
|
6
|
-
import { C as requestAnotherSlice, M as isInvalidConversationRecordError, T as startConversationWork, b as recordConversationRetry, d as countPendingConversationMessages, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, j as isFinalAttempt, k as hasConversationStop, l as completeConversationStop, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, s as clearConsumedConversationWake, t as ackMessages, u as completeConversationWork, x as releaseConversationWork, y as recordAttemptFailure } from "./store-
|
|
2
|
+
import { v as isProviderRetryError } from "./client-CRVXpEWi.js";
|
|
3
|
+
import { C as withLogContext, d as logException, f as logInfo, p as logWarn } from "./logging-B0QxCh3D.js";
|
|
4
|
+
import { i as getChatConfig } from "./config-B7joRWt7.js";
|
|
5
|
+
import { f as getTurnRequestDeadline, m as ConversationQueueMessageRejectedError } from "./job-queue-CIhKXUE3.js";
|
|
6
|
+
import { C as requestAnotherSlice, M as isInvalidConversationRecordError, T as startConversationWork, b as recordConversationRetry, d as countPendingConversationMessages, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, j as isFinalAttempt, k as hasConversationStop, l as completeConversationStop, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, s as clearConsumedConversationWake, t as ackMessages, u as completeConversationWork, x as releaseConversationWork, y as recordAttemptFailure } from "./store-DIFp9K52.js";
|
|
7
7
|
//#region src/chat/task-execution/worker.ts
|
|
8
8
|
var worker_exports = /* @__PURE__ */ __exportAll({
|
|
9
9
|
CONVERSATION_WORK_DEFER_DELAY_MS: () => CONVERSATION_WORK_DEFER_DELAY_MS,
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
CREATE TABLE "junior_automations" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"kind" text NOT NULL,
|
|
4
|
+
"team_id" text NOT NULL,
|
|
5
|
+
"channel_id" text NOT NULL,
|
|
6
|
+
"creator_slack_user_id" text NOT NULL,
|
|
7
|
+
"creator_identity_id" text,
|
|
8
|
+
"status" text NOT NULL,
|
|
9
|
+
"status_reason" text,
|
|
10
|
+
"title" text,
|
|
11
|
+
"instruction" text NOT NULL,
|
|
12
|
+
"created_at_ms" bigint NOT NULL,
|
|
13
|
+
"next_run_at_ms" bigint,
|
|
14
|
+
"run_now_at_ms" bigint,
|
|
15
|
+
"namespace" text,
|
|
16
|
+
"identifier" text,
|
|
17
|
+
"record" jsonb NOT NULL,
|
|
18
|
+
CONSTRAINT "junior_automations_kind_check" CHECK ("junior_automations"."kind" in ('scheduled', 'event')),
|
|
19
|
+
CONSTRAINT "junior_automations_status_check" CHECK ("junior_automations"."status" in ('active', 'blocked', 'paused', 'completed', 'deleted')),
|
|
20
|
+
CONSTRAINT "junior_automations_record_check" CHECK (jsonb_typeof("junior_automations"."record") = 'object'),
|
|
21
|
+
CONSTRAINT "junior_automations_trigger_check" CHECK (("junior_automations"."kind" = 'scheduled' and "junior_automations"."namespace" is null and "junior_automations"."identifier" is null) or ("junior_automations"."kind" = 'event' and "junior_automations"."namespace" is not null and "junior_automations"."identifier" is not null and "junior_automations"."next_run_at_ms" is null and "junior_automations"."run_now_at_ms" is null and "junior_automations"."status" <> 'completed'))
|
|
22
|
+
);
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
-- Stop before the copy if a Scheduled automation and an event automation
|
|
25
|
+
-- have the same id.
|
|
26
|
+
DO $$
|
|
27
|
+
BEGIN
|
|
28
|
+
IF EXISTS (
|
|
29
|
+
SELECT 1
|
|
30
|
+
FROM "junior_scheduler_tasks" AS "scheduled"
|
|
31
|
+
JOIN "junior_event_tasks" AS "event" ON "event"."id" = "scheduled"."id"
|
|
32
|
+
) THEN
|
|
33
|
+
RAISE EXCEPTION 'junior_scheduler_tasks and junior_event_tasks share an Automation id';
|
|
34
|
+
END IF;
|
|
35
|
+
END
|
|
36
|
+
$$;
|
|
37
|
+
--> statement-breakpoint
|
|
38
|
+
-- Copy both old tables. Old workers still use them during the deploy, so they
|
|
39
|
+
-- stay. The copy keeps what the old readers read:
|
|
40
|
+
-- - A Scheduled automation takes its status and status reason from its JSON.
|
|
41
|
+
-- - A title and a creator identity come from the column, or else from the
|
|
42
|
+
-- legacy JSON key.
|
|
43
|
+
-- - A status that the new check does not allow becomes "deleted".
|
|
44
|
+
-- JSON keys that now have a column are removed from the record.
|
|
45
|
+
INSERT INTO "junior_automations" (
|
|
46
|
+
"id", "kind", "team_id", "channel_id", "creator_slack_user_id",
|
|
47
|
+
"creator_identity_id", "status", "status_reason", "title", "instruction",
|
|
48
|
+
"created_at_ms", "next_run_at_ms", "run_now_at_ms", "namespace",
|
|
49
|
+
"identifier", "record"
|
|
50
|
+
)
|
|
51
|
+
SELECT
|
|
52
|
+
"id",
|
|
53
|
+
"kind",
|
|
54
|
+
"team_id",
|
|
55
|
+
coalesce("record"->'destination'->>'channelId', ''),
|
|
56
|
+
coalesce("record"->'createdBy'->>'slackUserId', ''),
|
|
57
|
+
"creator_identity_id",
|
|
58
|
+
CASE
|
|
59
|
+
WHEN "status" IN ('active', 'blocked', 'paused', 'completed', 'deleted') THEN "status"
|
|
60
|
+
ELSE 'deleted'
|
|
61
|
+
END,
|
|
62
|
+
"status_reason",
|
|
63
|
+
nullif(btrim(coalesce("title", "record"->>'title')), ''),
|
|
64
|
+
coalesce("record"->'task'->>'text', ''),
|
|
65
|
+
"created_at_ms",
|
|
66
|
+
"next_run_at_ms",
|
|
67
|
+
"run_now_at_ms",
|
|
68
|
+
"namespace",
|
|
69
|
+
"identifier",
|
|
70
|
+
"record" - ARRAY['createdAtMs', 'creatorIdentityId', 'id', 'nextRunAtMs', 'runNowAtMs', 'status', 'statusReason', 'title', 'version']
|
|
71
|
+
FROM (
|
|
72
|
+
SELECT
|
|
73
|
+
'scheduled' AS "kind",
|
|
74
|
+
"id",
|
|
75
|
+
"team_id",
|
|
76
|
+
coalesce("creator_identity_id", "record"->>'creatorIdentityId') AS "creator_identity_id",
|
|
77
|
+
"record"->>'status' AS "status",
|
|
78
|
+
"record"->>'statusReason' AS "status_reason",
|
|
79
|
+
"title",
|
|
80
|
+
"created_at_ms",
|
|
81
|
+
"next_run_at_ms",
|
|
82
|
+
"run_now_at_ms",
|
|
83
|
+
NULL AS "namespace",
|
|
84
|
+
NULL AS "identifier",
|
|
85
|
+
"record"
|
|
86
|
+
FROM "junior_scheduler_tasks"
|
|
87
|
+
UNION ALL
|
|
88
|
+
SELECT
|
|
89
|
+
'event',
|
|
90
|
+
"id",
|
|
91
|
+
"team_id",
|
|
92
|
+
NULL,
|
|
93
|
+
"status",
|
|
94
|
+
"status_reason",
|
|
95
|
+
"title",
|
|
96
|
+
"created_at_ms",
|
|
97
|
+
NULL,
|
|
98
|
+
NULL,
|
|
99
|
+
"namespace",
|
|
100
|
+
"identifier",
|
|
101
|
+
"task_json"
|
|
102
|
+
FROM "junior_event_tasks"
|
|
103
|
+
) AS "source";
|
|
104
|
+
--> statement-breakpoint
|
|
105
|
+
CREATE INDEX "junior_automations_team_idx" ON "junior_automations" USING btree ("team_id","created_at_ms","id") WHERE "junior_automations"."status" <> 'deleted';
|
|
106
|
+
--> statement-breakpoint
|
|
107
|
+
CREATE INDEX "junior_automations_creator_idx" ON "junior_automations" USING btree ("team_id","creator_slack_user_id","created_at_ms","id");
|
|
108
|
+
--> statement-breakpoint
|
|
109
|
+
CREATE INDEX "junior_automations_creator_identity_idx" ON "junior_automations" USING btree ("creator_identity_id","created_at_ms","id") WHERE "junior_automations"."creator_identity_id" IS NOT NULL;
|
|
110
|
+
--> statement-breakpoint
|
|
111
|
+
CREATE INDEX "junior_automations_run_now_due_idx" ON "junior_automations" USING btree ("run_now_at_ms","created_at_ms","id") WHERE "junior_automations"."status" = 'active' AND "junior_automations"."run_now_at_ms" IS NOT NULL;
|
|
112
|
+
--> statement-breakpoint
|
|
113
|
+
CREATE INDEX "junior_automations_next_run_due_idx" ON "junior_automations" USING btree ("next_run_at_ms","created_at_ms","id") WHERE "junior_automations"."status" = 'active' AND "junior_automations"."next_run_at_ms" IS NOT NULL;
|
|
114
|
+
--> statement-breakpoint
|
|
115
|
+
CREATE INDEX "junior_automations_match_idx" ON "junior_automations" USING btree ("namespace","identifier","created_at_ms","id") WHERE "junior_automations"."status" <> 'deleted';
|
|
116
|
+
--> statement-breakpoint
|
|
117
|
+
-- Versions now key on the Automation id. Old workers still write kind during
|
|
118
|
+
-- the deploy, so kind stays as a nullable column until PR 3 of #2176.
|
|
119
|
+
ALTER TABLE "junior_automation_versions" DROP CONSTRAINT "junior_automation_versions_pk";
|
|
120
|
+
--> statement-breakpoint
|
|
121
|
+
ALTER TABLE "junior_automation_versions" ADD CONSTRAINT "junior_automation_versions_pk" PRIMARY KEY("automation_id","version");
|
|
122
|
+
--> statement-breakpoint
|
|
123
|
+
ALTER TABLE "junior_automation_versions" ALTER COLUMN "kind" DROP NOT NULL;
|
|
124
|
+
--> statement-breakpoint
|
|
125
|
+
ALTER TABLE "junior_automation_versions" ADD CONSTRAINT "junior_automation_versions_automation_id_fk" FOREIGN KEY ("automation_id") REFERENCES "public"."junior_automations"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
CREATE TABLE "junior_automation_runs" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"automation_id" text NOT NULL,
|
|
4
|
+
"conversation_id" text,
|
|
5
|
+
"status" text NOT NULL,
|
|
6
|
+
"scheduled_for_ms" bigint,
|
|
7
|
+
"attempt" integer,
|
|
8
|
+
"claimed_at_ms" bigint,
|
|
9
|
+
"dispatch_id" text,
|
|
10
|
+
"started_at_ms" bigint,
|
|
11
|
+
"completed_at_ms" bigint,
|
|
12
|
+
"error_message" text,
|
|
13
|
+
"result_message_ts" text,
|
|
14
|
+
CONSTRAINT "junior_automation_runs_conversation_id_unique" UNIQUE("conversation_id"),
|
|
15
|
+
CONSTRAINT "junior_automation_runs_status_check" CHECK ("junior_automation_runs"."status" in ('pending', 'running', 'completed', 'failed', 'blocked', 'skipped'))
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
ALTER TABLE "junior_automation_runs" ADD CONSTRAINT "junior_automation_runs_automation_id_junior_automations_id_fk" FOREIGN KEY ("automation_id") REFERENCES "public"."junior_automations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
19
|
+
ALTER TABLE "junior_automation_runs" ADD CONSTRAINT "junior_automation_runs_conversation_id_junior_conversations_conversation_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."junior_conversations"("conversation_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
20
|
+
CREATE INDEX "junior_automation_runs_automation_idx" ON "junior_automation_runs" USING btree ("automation_id","completed_at_ms");--> statement-breakpoint
|
|
21
|
+
CREATE INDEX "junior_automation_runs_completed_idx" ON "junior_automation_runs" USING btree ("completed_at_ms");--> statement-breakpoint
|
|
22
|
+
CREATE INDEX "junior_automation_runs_incomplete_idx" ON "junior_automation_runs" USING btree ("automation_id","scheduled_for_ms") WHERE "junior_automation_runs"."status" in ('pending', 'running');--> statement-breakpoint
|
|
23
|
+
-- Copy run history from both old tables. They stay for old workers during the
|
|
24
|
+
-- deploy. Copy junior_scheduler_runs first, because its rows have the full
|
|
25
|
+
-- run state. Then copy the junior_task_executions rows that are still missing.
|
|
26
|
+
-- A run keeps its Conversation link only when that Conversation exists. A run
|
|
27
|
+
-- of an Automation that no longer exists is not copied.
|
|
28
|
+
INSERT INTO "junior_automation_runs" (
|
|
29
|
+
"id", "automation_id", "conversation_id", "status", "scheduled_for_ms",
|
|
30
|
+
"attempt", "claimed_at_ms", "dispatch_id", "started_at_ms",
|
|
31
|
+
"completed_at_ms", "error_message", "result_message_ts"
|
|
32
|
+
)
|
|
33
|
+
SELECT
|
|
34
|
+
r."id",
|
|
35
|
+
r."task_id",
|
|
36
|
+
c."conversation_id",
|
|
37
|
+
r."status",
|
|
38
|
+
r."scheduled_for_ms",
|
|
39
|
+
(r."record"->>'attempt')::integer,
|
|
40
|
+
(r."record"->>'claimedAtMs')::bigint,
|
|
41
|
+
r."record"->>'dispatchId',
|
|
42
|
+
(r."record"->>'startedAtMs')::bigint,
|
|
43
|
+
(r."record"->>'completedAtMs')::bigint,
|
|
44
|
+
r."record"->>'errorMessage',
|
|
45
|
+
r."record"->>'resultMessageTs'
|
|
46
|
+
FROM "junior_scheduler_runs" r
|
|
47
|
+
JOIN "junior_automations" a ON a."id" = r."task_id" AND a."kind" = 'scheduled'
|
|
48
|
+
LEFT JOIN "junior_conversations" c
|
|
49
|
+
ON c."conversation_id" = 'agent-dispatch:' || (r."record"->>'dispatchId')
|
|
50
|
+
WHERE r."status" IN ('pending', 'running', 'completed', 'failed', 'blocked', 'skipped')
|
|
51
|
+
ON CONFLICT DO NOTHING;
|
|
52
|
+
--> statement-breakpoint
|
|
53
|
+
-- An event run id is its dispatch id, so its Conversation id follows from it.
|
|
54
|
+
INSERT INTO "junior_automation_runs" (
|
|
55
|
+
"id", "automation_id", "conversation_id", "status", "completed_at_ms"
|
|
56
|
+
)
|
|
57
|
+
SELECT
|
|
58
|
+
e."execution_id",
|
|
59
|
+
e."task_id",
|
|
60
|
+
coalesce(e."conversation_id", c."conversation_id"),
|
|
61
|
+
e."status",
|
|
62
|
+
e."executed_at_ms"
|
|
63
|
+
FROM "junior_task_executions" e
|
|
64
|
+
JOIN "junior_automations" a ON a."id" = e."task_id" AND a."kind" = e."kind"
|
|
65
|
+
LEFT JOIN "junior_conversations" c
|
|
66
|
+
ON e."kind" = 'event'
|
|
67
|
+
AND c."conversation_id" = 'agent-dispatch:' || e."execution_id"
|
|
68
|
+
WHERE e."namespace" = 'junior'
|
|
69
|
+
ON CONFLICT DO NOTHING;
|