@sentry/junior 0.318.0 → 0.320.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/{context-BKF_5zzI.js → adapter-DlLLoJKj.js} +537 -537
- package/dist/{admin-UOHix_5P.js → admin-BzRXDVfh.js} +1 -1
- package/dist/{agent-runner-DeYymwh2.js → agent-DxZ7nHfD.js} +19866 -6720
- package/dist/{agent-status-BA5x3Xtp.js → agent-status-Bq_AIpyp.js} +105 -1
- package/dist/{agent-update-delivery-DH8bx7jU.js → agent-update-delivery-CO4FU5Gg.js} +4 -5
- package/dist/api/schema.d.ts +45 -23
- package/dist/api/schema.js +4 -4
- package/dist/api.js +79 -84
- package/dist/{app-DKAOuaoC.d.ts → app-CHCFIIDu.d.ts} +5 -4
- package/dist/app.d.ts +2 -2
- package/dist/app.js +119 -194
- package/dist/{change-record-BzJgLsv7.d.ts → change-record-K-KsqNhT.d.ts} +9 -5
- package/dist/{channel-access-A0de5lRv.js → channel-access-BghWqlXx.js} +1 -1
- package/dist/{chat-core-engine-D3Wd7f5n.js → chat-core-engine-BgfSLrDu.js} +31 -14
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +23 -23
- package/dist/cli/check.js +5 -5
- package/dist/cli/main.js +2 -2
- package/dist/cli/plugins.d.ts +1 -1
- package/dist/cli/plugins.js +8 -8
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -4
- package/dist/{continue-in-slack-YxwMQVeR.js → continue-in-slack-DBlQP4PC.js} +3 -3
- package/dist/{conversation-feed-Cj7IuBtM.js → conversation-feed-DEUdD7mb.js} +2 -106
- package/dist/{conversation-privacy-Cr_dNW1p.js → conversation-privacy-qoh95v90.js} +1 -1
- package/dist/{create-Btl1y1rq.js → create-jZSaDrCR.js} +115 -5
- package/dist/{credential-sync-DTarZ63K.js → credential-sync-Bj9-UlNE.js} +15 -18
- package/dist/{db-of6e3sGt.js → db-BacvswT0.js} +4602 -727
- package/dist/{deployment-C0qXa0FD.js → deployment-BoJkRPDt.js} +3 -3
- package/dist/{engine-context-C_QL_bMQ.js → engine-context-Bi3Ync5t.js} +521 -150
- package/dist/{html-9_pS9SjY.js → html-DW0pw5Pr.js} +6 -8
- package/dist/instrumentation.js +7 -23
- package/dist/list-Dz3CdP3g.js +5016 -0
- package/dist/{logging-BnOG0qz2.js → logging-DsTnMqyi.js} +8 -33
- package/dist/{mailbox-turn-Byrry9o1.js → markers-C33gNYNE.js} +1705 -1284
- package/dist/nitro.d.ts +2 -2
- package/dist/nitro.js +6 -7
- package/dist/{oauth-callback-server-CjnnUr4o.js → oauth-callback-server-C-pEhAQK.js} +2 -2
- package/dist/{oauth-relay-BvHFH0fV.js → oauth-relay-DIXdH-io.js} +1 -1
- package/dist/{plugins-fBrz8PCV.d.ts → plugins-DhGXZjlu.d.ts} +1 -0
- package/dist/{profile-iHw1uu32.js → profile-v9vA3RvH.js} +16 -18
- package/dist/{prompt-DEkStuxG.js → prompt-C5CW2wKO.js} +1 -1
- package/dist/{reports-C1d9azyV.js → reports-eBgrhPXS.js} +2 -2
- package/dist/{resolve-DC6zBuDV.js → resolve-HVXmbeCr.js} +5 -5
- package/dist/{result-DxewDuXb.js → result-BPNzgeTl.js} +20 -9
- package/dist/{runner-99YxVN_r.js → runner-aNSDTST6.js} +7 -8
- package/dist/{sandbox-egress-signals-CgoX5CTI.js → sandbox-egress-signals-nzp9Ykf7.js} +1 -1
- package/dist/{schema-BTojNBr5.js → schema-BlTO5M1d.js} +16 -8
- package/dist/{service-account-YDCPSByj.js → service-account-DWIf1t6p.js} +4 -5
- package/dist/{skills-CleC0Hze.js → skills-50izzzdK.js} +9 -9
- package/dist/{slack-conversation-unfurl-BNQLC12R.js → slack-conversation-unfurl-C6jXhVYg.js} +7 -7
- package/dist/storage-BtCxXiNt.js +273 -0
- package/dist/{system-prompt-table-Ci6Ck4gk.js → system-prompt-table-CIR1B44Z.js} +27 -85
- package/dist/topic-B2EWKKBT.js +6 -0
- package/dist/{package-discovery-DD9vencX.js → topics-DxuKurCX.js} +21 -1
- package/dist/{types-DCzTAA63.js → types-BNHkJrOP.js} +25 -11
- package/dist/{users-Cb9c1k9q.js → users-DOVo9sdU.js} +1 -1
- package/dist/{validation-BiUmWPhy.js → validation-CK0vuEHB.js} +4 -4
- package/dist/{version-VEXiEcZu.js → version-BuLVNlxB.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{worker-ChWYQdhm.js → worker-C82kHU1R.js} +4 -4
- package/migrations/20261127052408_space_name_nullable/migration.sql +5 -0
- package/migrations/20261127052408_space_name_nullable/snapshot.json +29 -0
- package/migrations/20261127060000_annotation_object_id_index/migration.sql +1 -0
- package/migrations/20261127060000_annotation_object_id_index/snapshot.json +69 -0
- package/migrations/20261127060001_annotation_subjects/migration.sql +78 -0
- package/migrations/20261127060001_annotation_subjects/snapshot.json +104 -0
- package/migrations/20261127060002_annotation_subject_index/migration.sql +1 -0
- package/migrations/20261127060002_annotation_subject_index/snapshot.json +70 -0
- package/migrations/20261127060003_annotation_title_url/migration.sql +84 -0
- package/migrations/20261127060003_annotation_title_url/snapshot.json +73 -0
- package/migrations/20261127150242_drop_space_members/migration.sql +9 -0
- package/migrations/20261127150242_drop_space_members/snapshot.json +53 -0
- package/package.json +9 -7
- package/dist/auth-pause-state-f9hJM_zO.js +0 -113
- package/dist/catalog-runtime-BfdAnztW.js +0 -6
- package/dist/child-message-peFWLcCZ.js +0 -15
- package/dist/conversation-turn-Bru4w_FD.js +0 -1250
- package/dist/job-runner-B2XEvpif.js +0 -1505
- package/dist/lineage-nh4z9iQN.js +0 -36
- package/dist/list-HRP3TIRl.js +0 -12631
- package/dist/markers-CTTtJqYn.js +0 -342
- package/dist/message-BRUuLgrY.js +0 -153
- package/dist/model-input-CFC62mf-.js +0 -82
- package/dist/registry-Cl7Labpe.js +0 -3279
- package/dist/run-conversation-Cz2ubZK-.js +0 -337
- package/dist/sender-actors-77zTQbSG.js +0 -84
- package/dist/spawn-DuZfodPa.js +0 -45
- package/dist/task-runner-BJ9Up3bG.js +0 -1529
- package/dist/topic-CRYYBYp-.js +0 -7
- package/dist/topics-BoCkoPJJ.js +0 -21
- package/dist/turn-membership-VT7XZh-L.js +0 -856
- package/dist/turn-wake-C7HeLHAM.js +0 -151
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import { Fa as linkAutomationRunConversation, Ut as appendAndEnqueueInboundMessage, ai as getDispatchIdForConversation, ci as getDispatchTurnId, ec as resolveActorIdentityId, fi as markDispatchAwaitingResume, gi as markDispatchRunning, hi as markDispatchFailed, i as getConversationStore, ii as getDispatchConversationId, mi as markDispatchCompleted, ni as confirmDispatchMailboxAppend, o as getSqlExecutor, oi as getDispatchInputMessageId, pi as markDispatchBlocked, si as getDispatchRecord, ti as claimDispatchMailboxAppend, ui as isTerminalDispatchStatus, uu as indexEndedTurnEvents } from "./db-of6e3sGt.js";
|
|
3
|
-
import { n as credentialContextForActor } from "./context-BKF_5zzI.js";
|
|
4
|
-
import { m as logWarn } from "./logging-BnOG0qz2.js";
|
|
5
|
-
import { Sr as recordTurnSummary, a as resolveMailboxTurnWork, at as isTurnInputCommitLostError, br as getTurnRecord, it as isCooperativeTurnYieldError, nr as PluginCredentialFailureError, or as AuthorizationFlowDisabledError, rt as getConversationTurnBoundaryError, tt as TurnInputCommitLostError, xr as listTurnSummaries } from "./mailbox-turn-Byrry9o1.js";
|
|
6
|
-
import { t as recordChildAgentEnded } from "./markers-CTTtJqYn.js";
|
|
7
|
-
import { n as withSenderActors } from "./sender-actors-77zTQbSG.js";
|
|
8
|
-
import * as z from "zod";
|
|
9
|
-
// src/chat/agent-dispatch/work.ts
|
|
10
|
-
const agentDispatchMailboxMetadataSchema = z.object({
|
|
11
|
-
dispatchId: z.string().min(1),
|
|
12
|
-
kind: z.literal("agent_dispatch")
|
|
13
|
-
}).strict();
|
|
14
|
-
const AGENT_DISPATCH_MAX_AGE_MS = 864e5;
|
|
15
|
-
/** Return whether a dispatch is a Scheduled or Event automation run. */
|
|
16
|
-
function isAutomationRun(dispatch) {
|
|
17
|
-
return dispatch.source.kind === "scheduled_automation" || dispatch.source.kind === "event_automation";
|
|
18
|
-
}
|
|
19
|
-
/** Restore the exact actor, credential, and dispatch routing for every slice. */
|
|
20
|
-
function buildDispatchRoutingContext(dispatch) {
|
|
21
|
-
return {
|
|
22
|
-
actor: dispatch.actor,
|
|
23
|
-
credentialContext: credentialContextForActor(dispatch.actor, dispatch.credentialSubject),
|
|
24
|
-
dispatch: {
|
|
25
|
-
actor: dispatch.actor,
|
|
26
|
-
id: dispatch.id,
|
|
27
|
-
metadata: dispatch.metadata,
|
|
28
|
-
plugin: dispatch.plugin,
|
|
29
|
-
replyAttribution: dispatch.replyAttribution,
|
|
30
|
-
outcomes: dispatch.outcomes,
|
|
31
|
-
...dispatch.skill ? { skill: dispatch.skill } : void 0,
|
|
32
|
-
...isAutomationRun(dispatch) ? { declaresResult: true } : void 0
|
|
33
|
-
},
|
|
34
|
-
surface: "api"
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/** Build the stable mailbox work item for one agent dispatch. */
|
|
38
|
-
function buildAgentDispatchInboundMessage(dispatch, nowMs = Date.now(), authorIdentityId) {
|
|
39
|
-
return {
|
|
40
|
-
conversationId: getDispatchConversationId(dispatch),
|
|
41
|
-
createdAtMs: dispatch.createdAtMs,
|
|
42
|
-
delivery: "defer",
|
|
43
|
-
destination: dispatch.destination,
|
|
44
|
-
inboundMessageId: getDispatchInputMessageId(dispatch.id),
|
|
45
|
-
input: {
|
|
46
|
-
text: "[plugin dispatch]",
|
|
47
|
-
...authorIdentityId ? { authorIdentityId } : void 0,
|
|
48
|
-
metadata: {
|
|
49
|
-
dispatchId: dispatch.id,
|
|
50
|
-
kind: "agent_dispatch"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
receivedAtMs: nowMs,
|
|
54
|
-
source: "plugin"
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/** Persist dispatch mailbox work before sending its conversation wake-up. */
|
|
58
|
-
async function enqueueAgentDispatch(dispatch, options) {
|
|
59
|
-
const nowMs = options.nowMs ?? Date.now();
|
|
60
|
-
const claimedDispatch = await claimDispatchMailboxAppend(dispatch.id);
|
|
61
|
-
if (!claimedDispatch) return;
|
|
62
|
-
const conversationStore = options.conversationStore ?? getConversationStore();
|
|
63
|
-
const conversationId = getDispatchConversationId(claimedDispatch);
|
|
64
|
-
const destination = claimedDispatch.destination;
|
|
65
|
-
await conversationStore.recordActivity({
|
|
66
|
-
activityAtMs: claimedDispatch.createdAtMs,
|
|
67
|
-
conversationId,
|
|
68
|
-
destination,
|
|
69
|
-
kind: isAutomationRun(claimedDispatch) ? "automation" : "thread",
|
|
70
|
-
nowMs,
|
|
71
|
-
source: "plugin",
|
|
72
|
-
sessionSource: claimedDispatch.source,
|
|
73
|
-
...claimedDispatch.title ? { title: claimedDispatch.title } : void 0
|
|
74
|
-
});
|
|
75
|
-
const source = claimedDispatch.source;
|
|
76
|
-
if ((source.kind === "scheduled_automation" || source.kind === "event_automation") && source.automationRunId) await linkAutomationRunConversation({
|
|
77
|
-
conversationId,
|
|
78
|
-
runId: source.automationRunId
|
|
79
|
-
});
|
|
80
|
-
if (destination.platform === "slack" && destination.threadTs) await conversationStore.claimProviderConversation({
|
|
81
|
-
atMs: nowMs,
|
|
82
|
-
conversationId,
|
|
83
|
-
provider: "slack",
|
|
84
|
-
providerDestinationId: destination.channelId,
|
|
85
|
-
providerTenantId: destination.teamId,
|
|
86
|
-
providerConversationId: destination.threadTs
|
|
87
|
-
});
|
|
88
|
-
await appendAndEnqueueInboundMessage({
|
|
89
|
-
message: buildAgentDispatchInboundMessage(claimedDispatch, nowMs, await resolveActorIdentityId(getSqlExecutor(), claimedDispatch.actor)),
|
|
90
|
-
conversationStore: options.conversationStore,
|
|
91
|
-
nowMs,
|
|
92
|
-
queue: options.queue,
|
|
93
|
-
state: options.state
|
|
94
|
-
});
|
|
95
|
-
await confirmDispatchMailboxAppend(claimedDispatch.id);
|
|
96
|
-
}
|
|
97
|
-
/** Parse dispatch routing metadata from a durable mailbox message. */
|
|
98
|
-
function dispatchIdFromMessages(messages) {
|
|
99
|
-
if (messages.length === 0) return;
|
|
100
|
-
const parsed = messages.map((message) => agentDispatchMailboxMetadataSchema.safeParse(message.input.metadata));
|
|
101
|
-
if (parsed.every((result) => !result.success)) return;
|
|
102
|
-
if (parsed.some((result) => !result.success)) throw new Error("Conversation mailbox mixes dispatch and provider input");
|
|
103
|
-
const ids = new Set(parsed.map((result) => {
|
|
104
|
-
if (!result.success) throw new Error("Dispatch mailbox metadata failed validation");
|
|
105
|
-
return result.data.dispatchId;
|
|
106
|
-
}));
|
|
107
|
-
if (ids.size !== 1) throw new Error("Conversation mailbox contains multiple dispatches");
|
|
108
|
-
return ids.values().next().value;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Resolve a dispatch from concrete mailbox metadata or the active turn.
|
|
112
|
-
*
|
|
113
|
-
* Provider source and conversation-id conventions are deliberately not
|
|
114
|
-
* execution routing authority.
|
|
115
|
-
*/
|
|
116
|
-
async function resolveAgentDispatchId(context) {
|
|
117
|
-
const mailboxDispatchId = dispatchIdFromMessages(context.attempt.messages);
|
|
118
|
-
if (mailboxDispatchId) return mailboxDispatchId;
|
|
119
|
-
if (context.attempt.messages.length > 0) return;
|
|
120
|
-
const summaries = await listTurnSummaries(context.conversationId);
|
|
121
|
-
const activeDispatchIds = new Set(summaries.filter((summary) => (summary.state === "paused" || summary.state === "running") && Boolean(summary.dispatchId)).map((summary) => summary.dispatchId).filter((id) => Boolean(id)));
|
|
122
|
-
if (activeDispatchIds.size > 1) throw new Error(`Conversation ${context.conversationId} has multiple active dispatches`);
|
|
123
|
-
const activeDispatchId = activeDispatchIds.values().next().value;
|
|
124
|
-
if (activeDispatchId) return activeDispatchId;
|
|
125
|
-
const durableDispatchIds = new Set(summaries.map((summary) => summary.dispatchId).filter((id) => Boolean(id)));
|
|
126
|
-
if (durableDispatchIds.size > 1) throw new Error(`Conversation ${context.conversationId} has multiple dispatch sessions`);
|
|
127
|
-
const durableDispatchId = durableDispatchIds.values().next().value;
|
|
128
|
-
if (!durableDispatchId) return;
|
|
129
|
-
const dispatch = await getDispatchRecord(durableDispatchId);
|
|
130
|
-
return dispatch && !isTerminalDispatchStatus(dispatch.status) ? durableDispatchId : void 0;
|
|
131
|
-
}
|
|
132
|
-
async function readDispatchTurnResult(dispatch) {
|
|
133
|
-
const conversationId = getDispatchConversationId(dispatch);
|
|
134
|
-
const turnId = getDispatchTurnId(dispatch.id);
|
|
135
|
-
const storedSession = await getTurnRecord(conversationId, turnId);
|
|
136
|
-
const summary = (await listTurnSummaries(conversationId)).find((candidate) => candidate.turnId === turnId);
|
|
137
|
-
const session = storedSession ?? summary;
|
|
138
|
-
const dispatchOutcome = summary?.dispatchOutcome ?? storedSession?.dispatchOutcome;
|
|
139
|
-
const resultMessageTs = summary?.resultMessageId ?? storedSession?.resultMessageId;
|
|
140
|
-
const errorMessage = storedSession?.errorMessage;
|
|
141
|
-
if (dispatchOutcome) return {
|
|
142
|
-
...errorMessage ? { errorMessage } : void 0,
|
|
143
|
-
outcome: dispatchOutcome,
|
|
144
|
-
...resultMessageTs ? { resultMessageTs } : void 0
|
|
145
|
-
};
|
|
146
|
-
if (resultMessageTs) return {
|
|
147
|
-
outcome: "completed",
|
|
148
|
-
resultMessageTs
|
|
149
|
-
};
|
|
150
|
-
if (!session) return { outcome: "not_started" };
|
|
151
|
-
switch (session.state) {
|
|
152
|
-
case "paused": return { outcome: "awaiting_resume" };
|
|
153
|
-
case "running": return { outcome: "still_running" };
|
|
154
|
-
case "completed": return { outcome: "completed" };
|
|
155
|
-
case "abandoned":
|
|
156
|
-
case "failed": return {
|
|
157
|
-
...errorMessage ? { errorMessage } : void 0,
|
|
158
|
-
outcome: "retryable"
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async function projectDispatchTurnResult(dispatchId, result) {
|
|
163
|
-
switch (result.outcome) {
|
|
164
|
-
case "awaiting_resume":
|
|
165
|
-
await markDispatchAwaitingResume(dispatchId);
|
|
166
|
-
break;
|
|
167
|
-
case "blocked":
|
|
168
|
-
await markDispatchBlocked(dispatchId, result.errorMessage ?? "Dispatch requires authorization that is unavailable for background work", result.resultMessageTs);
|
|
169
|
-
break;
|
|
170
|
-
case "failed":
|
|
171
|
-
await markDispatchFailed(dispatchId, result.errorMessage ?? "Agent turn failed", result.resultMessageTs);
|
|
172
|
-
break;
|
|
173
|
-
case "completed":
|
|
174
|
-
await markDispatchCompleted(dispatchId, result.resultMessageTs);
|
|
175
|
-
break;
|
|
176
|
-
case "not_started": await markDispatchFailed(dispatchId, "Dispatch turn record is missing");
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function getDispatchBlockingError(error) {
|
|
180
|
-
const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
|
|
181
|
-
return cause instanceof AuthorizationFlowDisabledError || cause instanceof PluginCredentialFailureError ? cause : void 0;
|
|
182
|
-
}
|
|
183
|
-
function missingAuthorizationReason(dispatch, provider) {
|
|
184
|
-
return dispatch.credentialSubject ? `This run needs a connected ${provider} account.` : `This run uses system credentials, which have no ${provider} access. Switch it to creator credentials and connect a ${provider} account.`;
|
|
185
|
-
}
|
|
186
|
-
async function persistBlockedDispatchTurn(dispatch, error) {
|
|
187
|
-
const conversationId = getDispatchConversationId(dispatch);
|
|
188
|
-
const sessionId = getDispatchTurnId(dispatch.id);
|
|
189
|
-
const session = await getTurnRecord(conversationId, sessionId);
|
|
190
|
-
await recordTurnSummary({
|
|
191
|
-
actor: dispatch.actor,
|
|
192
|
-
conversationId,
|
|
193
|
-
destination: dispatch.destination,
|
|
194
|
-
dispatchId: dispatch.id,
|
|
195
|
-
dispatchOutcome: "blocked",
|
|
196
|
-
turnId: sessionId,
|
|
197
|
-
sliceId: session?.sliceId ?? 1,
|
|
198
|
-
source: dispatch.source,
|
|
199
|
-
state: "failed",
|
|
200
|
-
surface: "api"
|
|
201
|
-
});
|
|
202
|
-
await markDispatchBlocked(dispatch.id, error instanceof AuthorizationFlowDisabledError ? missingAuthorizationReason(dispatch, error.provider) : error.message);
|
|
203
|
-
}
|
|
204
|
-
/** Run one dispatch start or resume under the owning conversation lease. */
|
|
205
|
-
function createAgentDispatchConversationWorker(options) {
|
|
206
|
-
return async (context, dispatchId) => {
|
|
207
|
-
const dispatch = await getDispatchRecord(dispatchId);
|
|
208
|
-
if (!dispatch) throw new Error(`Dispatch record is missing for ${dispatchId}`);
|
|
209
|
-
const expectedConversationId = getDispatchConversationId(dispatch);
|
|
210
|
-
if (context.conversationId !== expectedConversationId) throw new Error(`Dispatch ${dispatch.id} belongs to ${expectedConversationId}, not ${context.conversationId}`);
|
|
211
|
-
if (!context.destination || context.destination.platform !== dispatch.destination.platform || context.destination.teamId !== dispatch.destination.teamId || context.destination.channelId !== dispatch.destination.channelId) throw new Error(`Dispatch ${dispatch.id} destination does not match its conversation lease`);
|
|
212
|
-
let acknowledged = context.attempt.messages.length === 0;
|
|
213
|
-
const acknowledge = async () => {
|
|
214
|
-
if (acknowledged) return;
|
|
215
|
-
try {
|
|
216
|
-
await context.attempt.ack();
|
|
217
|
-
} catch {
|
|
218
|
-
throw new TurnInputCommitLostError(`Conversation work lease lost before dispatch inbox ack for ${context.conversationId}`);
|
|
219
|
-
}
|
|
220
|
-
acknowledged = true;
|
|
221
|
-
};
|
|
222
|
-
if (isTerminalDispatchStatus(dispatch.status)) {
|
|
223
|
-
await acknowledge();
|
|
224
|
-
return { status: "completed" };
|
|
225
|
-
}
|
|
226
|
-
const durableResult = await readDispatchTurnResult(dispatch);
|
|
227
|
-
if (durableResult.outcome === "blocked" || durableResult.outcome === "completed" || durableResult.outcome === "failed") {
|
|
228
|
-
await projectDispatchTurnResult(dispatch.id, durableResult);
|
|
229
|
-
await acknowledge();
|
|
230
|
-
return { status: "completed" };
|
|
231
|
-
}
|
|
232
|
-
if (Date.now() - dispatch.createdAtMs > 864e5) {
|
|
233
|
-
await markDispatchFailed(dispatch.id, "Dispatch exceeded its maximum processing age");
|
|
234
|
-
await acknowledge();
|
|
235
|
-
return { status: "completed" };
|
|
236
|
-
}
|
|
237
|
-
const runningDispatch = await markDispatchRunning(dispatch.id);
|
|
238
|
-
if (!runningDispatch) throw new Error(`Dispatch record disappeared for ${dispatch.id}`);
|
|
239
|
-
if (isTerminalDispatchStatus(runningDispatch.status)) {
|
|
240
|
-
await acknowledge();
|
|
241
|
-
return { status: "completed" };
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
const resumesDurableTurn = durableResult.outcome === "awaiting_resume" || durableResult.outcome === "still_running";
|
|
245
|
-
if (resumesDurableTurn && context.attempt.messages.length > 0) await acknowledge();
|
|
246
|
-
let result;
|
|
247
|
-
if (resumesDurableTurn) {
|
|
248
|
-
await options.resumeTurn(dispatch, {
|
|
249
|
-
shouldYield: context.shouldYield,
|
|
250
|
-
checkIn: context.checkIn
|
|
251
|
-
});
|
|
252
|
-
result = await readDispatchTurnResult(dispatch);
|
|
253
|
-
} else result = await options.runTurn(dispatch, {
|
|
254
|
-
ack: acknowledge,
|
|
255
|
-
shouldYield: context.shouldYield,
|
|
256
|
-
checkIn: context.checkIn
|
|
257
|
-
}) ?? await readDispatchTurnResult(dispatch);
|
|
258
|
-
if (result.outcome === "still_running") throw new Error(`Dispatch turn ${dispatch.id} is still running after its attempt`);
|
|
259
|
-
if (result.outcome === "retryable") throw new Error(result.errorMessage ?? `Dispatch turn ${dispatch.id} failed`);
|
|
260
|
-
await projectDispatchTurnResult(dispatch.id, result);
|
|
261
|
-
if (!acknowledged) await acknowledge();
|
|
262
|
-
return result.outcome === "awaiting_resume" && context.shouldYield() ? { status: "yielded" } : { status: "completed" };
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (isCooperativeTurnYieldError(error)) {
|
|
265
|
-
await markDispatchAwaitingResume(dispatch.id);
|
|
266
|
-
return { status: "yielded" };
|
|
267
|
-
}
|
|
268
|
-
if (isTurnInputCommitLostError(error)) {
|
|
269
|
-
logWarn("agent.dispatch.lost_lease", {
|
|
270
|
-
"app.dispatch.id": dispatch.id,
|
|
271
|
-
"error.type": error.name,
|
|
272
|
-
"exception.message": error.message
|
|
273
|
-
});
|
|
274
|
-
return { status: "lost_lease" };
|
|
275
|
-
}
|
|
276
|
-
const blockingError = getDispatchBlockingError(error);
|
|
277
|
-
if (blockingError) {
|
|
278
|
-
await persistBlockedDispatchTurn(dispatch, blockingError);
|
|
279
|
-
await indexEndedTurnEvents({
|
|
280
|
-
conversationId: context.conversationId,
|
|
281
|
-
turnId: getDispatchTurnId(dispatch.id)
|
|
282
|
-
});
|
|
283
|
-
await acknowledge();
|
|
284
|
-
return { status: "completed" };
|
|
285
|
-
}
|
|
286
|
-
if (!context.attempt.isFinalAttempt) throw error;
|
|
287
|
-
await markDispatchFailed(dispatch.id, error instanceof Error ? error.message : "Dispatch turn failed");
|
|
288
|
-
await indexEndedTurnEvents({
|
|
289
|
-
conversationId: context.conversationId,
|
|
290
|
-
turnId: getDispatchTurnId(dispatch.id)
|
|
291
|
-
});
|
|
292
|
-
await acknowledge();
|
|
293
|
-
return { status: "completed" };
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Fail the dispatch of stopped Conversation work, so the Automation run that
|
|
299
|
-
* waits on it settles instead of blocking later runs.
|
|
300
|
-
*/
|
|
301
|
-
async function failStoppedDispatch(conversationId) {
|
|
302
|
-
const dispatchId = getDispatchIdForConversation(conversationId);
|
|
303
|
-
if (dispatchId) await markDispatchFailed(dispatchId, "Dispatch work stopped after repeated failed attempts.");
|
|
304
|
-
}
|
|
305
|
-
// src/chat/task-execution/run-conversation.ts
|
|
306
|
-
var run_conversation_exports = /* @__PURE__ */ __exportAll({ runConversation: () => runConversation });
|
|
307
|
-
/**
|
|
308
|
-
* Run one attempt of any Conversation, root or child: its mailbox Turn,
|
|
309
|
-
* then its dispatch, then its Destination work. An attempt with none of
|
|
310
|
-
* them, such as an empty wake after a stop, completes.
|
|
311
|
-
*/
|
|
312
|
-
async function runConversation(context, workers) {
|
|
313
|
-
const mailboxTurn = await resolveMailboxTurnWork(context);
|
|
314
|
-
if (mailboxTurn) {
|
|
315
|
-
const work = await withSenderActors(mailboxTurn);
|
|
316
|
-
if (!work) {
|
|
317
|
-
await context.attempt.ack();
|
|
318
|
-
return { status: "completed" };
|
|
319
|
-
}
|
|
320
|
-
const result = await workers.runTurn(context, work);
|
|
321
|
-
if (result.status === "completed") await recordChildAgentEnded(context.conversationId, "success", { state: workers.state });
|
|
322
|
-
return result;
|
|
323
|
-
}
|
|
324
|
-
if (workers.runDispatch) {
|
|
325
|
-
const dispatchId = await resolveAgentDispatchId(context);
|
|
326
|
-
if (dispatchId) return await workers.runDispatch(context, dispatchId);
|
|
327
|
-
}
|
|
328
|
-
const destination = context.destination;
|
|
329
|
-
if (!destination) {
|
|
330
|
-
await context.attempt.ack();
|
|
331
|
-
return { status: "completed" };
|
|
332
|
-
}
|
|
333
|
-
const runDestination = workers.destinations?.[destination.platform];
|
|
334
|
-
if (!runDestination) throw new Error(`Conversation ${context.conversationId} has a ${destination.platform} destination but no matching conversation worker`);
|
|
335
|
-
return await runDestination(context);
|
|
336
|
-
}
|
|
337
|
-
export { createAgentDispatchConversationWorker as a, buildDispatchRoutingContext as i, run_conversation_exports as n, enqueueAgentDispatch as o, AGENT_DISPATCH_MAX_AGE_MS as r, failStoppedDispatch as s, runConversation as t };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { G as mapBounded } from "./prompt-DEkStuxG.js";
|
|
2
|
-
import { Hl as EVENT_SYSTEM_ACTOR, Pn as readParentMessage } from "./db-of6e3sGt.js";
|
|
3
|
-
import { c as childAgentInput, d as isDroppedChildInput, l as getChildAgentInputSender, m as readChildInputDropFacts } from "./markers-CTTtJqYn.js";
|
|
4
|
-
import { _ as parentMessageText, g as logDroppedParentMessage } from "./mailbox-turn-Byrry9o1.js";
|
|
5
|
-
import * as z from "zod";
|
|
6
|
-
import { actorSchema } from "@sentry/junior-plugin-api";
|
|
7
|
-
// src/chat/child-agents/sender-actors.ts
|
|
8
|
-
const senderActorMetadataSchema = z.object({ actor: actorSchema });
|
|
9
|
-
/**
|
|
10
|
-
* Return the Inbound message author id for results sent by one Actor.
|
|
11
|
-
* `selectContiguousTurnBatch` in `task-execution/worker.ts` puts messages in
|
|
12
|
-
* one attempt only when their author ids and sources match. Mid-Turn drains
|
|
13
|
-
* take only `interrupt` messages, and results are `defer`. So results never
|
|
14
|
-
* share a Turn and its credentials with another Actor or with watch Events.
|
|
15
|
-
* Keep this id unique per Actor if either rule changes. The id is opaque.
|
|
16
|
-
* It keeps the value that earlier releases wrote, because a queued result
|
|
17
|
-
* from before a deploy is checked against it.
|
|
18
|
-
*/
|
|
19
|
-
function resultAuthorId(actor) {
|
|
20
|
-
switch (actor.platform) {
|
|
21
|
-
case "system": return `agent-invocation:system:${actor.name}`;
|
|
22
|
-
case "slack": return `agent-invocation:slack:${actor.teamId}:${actor.userId}`;
|
|
23
|
-
default: return `agent-invocation:${actor.platform}:${actor.userId}`;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** Read the Actor of the child Turn that a reply or message carries. */
|
|
27
|
-
function senderActorFromMetadata(metadata) {
|
|
28
|
-
const parsed = senderActorMetadataSchema.safeParse(metadata);
|
|
29
|
-
return parsed.success ? parsed.data.actor : void 0;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Run each child reply or message as the Actor of the child Turn that sent
|
|
33
|
-
* it, which the input carries, so the parent never gets more authority than
|
|
34
|
-
* that Turn. A parent message from the stored parent runs as the Actor of the
|
|
35
|
-
* parent's Turn, with its grants and text. Input that a Turn with another
|
|
36
|
-
* Actor sent, or that names no child of this Conversation, runs as the Event
|
|
37
|
-
* system Actor. Input that `isDroppedChildInput` drops is left out. Returns
|
|
38
|
-
* undefined when no input is left.
|
|
39
|
-
*/
|
|
40
|
-
async function withSenderActors(work) {
|
|
41
|
-
if (work.kind !== "mailbox") return work;
|
|
42
|
-
const dropFacts = await readChildInputDropFacts(work.batch.map((entry) => entry.message));
|
|
43
|
-
const kept = (await mapBounded(work.batch, async (entry) => {
|
|
44
|
-
const parentMessage = readParentMessage(entry.message);
|
|
45
|
-
if (parentMessage) {
|
|
46
|
-
if (isDroppedChildInput(entry.message, dropFacts)) {
|
|
47
|
-
logDroppedParentMessage(entry.message, parentMessage);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const text = await parentMessageText(entry.message, parentMessage);
|
|
51
|
-
return {
|
|
52
|
-
...entry,
|
|
53
|
-
actor: parentMessage.actor,
|
|
54
|
-
requestText: entry.message.input.text.trim(),
|
|
55
|
-
...parentMessage.credentialContext ? { credentialContext: parentMessage.credentialContext } : void 0,
|
|
56
|
-
message: {
|
|
57
|
-
...entry.message,
|
|
58
|
-
input: {
|
|
59
|
-
...entry.message.input,
|
|
60
|
-
text
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const input = childAgentInput(entry.message);
|
|
66
|
-
if (!input) return entry;
|
|
67
|
-
if (isDroppedChildInput(entry.message, dropFacts)) return;
|
|
68
|
-
const sender = await getChildAgentInputSender(entry.message, input);
|
|
69
|
-
const actor = senderActorFromMetadata(entry.message.input.metadata);
|
|
70
|
-
if (!sender || !actor || entry.message.input.authorId !== resultAuthorId(actor)) return {
|
|
71
|
-
...entry,
|
|
72
|
-
actor: EVENT_SYSTEM_ACTOR
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
...entry,
|
|
76
|
-
actor
|
|
77
|
-
};
|
|
78
|
-
})).filter((entry) => entry !== void 0);
|
|
79
|
-
return kept.length > 0 ? {
|
|
80
|
-
kind: "mailbox",
|
|
81
|
-
batch: kept
|
|
82
|
-
} : void 0;
|
|
83
|
-
}
|
|
84
|
-
export { withSenderActors as n, resultAuthorId as t };
|
package/dist/spawn-DuZfodPa.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import { P as AgentDepthLimitError, b as actorFromRun } from "./agent-runner-DeYymwh2.js";
|
|
3
|
-
import { L as botConfig } from "./context-BKF_5zzI.js";
|
|
4
|
-
import { t as readConversationLineage } from "./lineage-nh4z9iQN.js";
|
|
5
|
-
import { n as spawnChildAgent } from "./create-Btl1y1rq.js";
|
|
6
|
-
// src/chat/child-agents/spawn.ts
|
|
7
|
-
var spawn_exports = /* @__PURE__ */ __exportAll({ bindSpawnAgent: () => bindSpawnAgent });
|
|
8
|
-
/**
|
|
9
|
-
* Count the parents of the Conversation that starts a child agent. A chain
|
|
10
|
-
* that does not end at a root, such as a cycle, cannot start one.
|
|
11
|
-
*/
|
|
12
|
-
async function assertCanStartChildAgent(conversationId, maxAgentDepth) {
|
|
13
|
-
const lineage = await readConversationLineage(conversationId);
|
|
14
|
-
const root = lineage[0];
|
|
15
|
-
if (!root || root.parentConversationId || lineage.length - 1 > maxAgentDepth) throw new AgentDepthLimitError(maxAgentDepth);
|
|
16
|
-
}
|
|
17
|
-
/** Bind a Run's Actor and credentials to new child agents. */
|
|
18
|
-
function bindSpawnAgent(run, options) {
|
|
19
|
-
const actor = actorFromRun(run);
|
|
20
|
-
if (!actor) return;
|
|
21
|
-
return async (input, call) => {
|
|
22
|
-
call.signal?.throwIfAborted();
|
|
23
|
-
await assertCanStartChildAgent(run.conversationId, options.maxAgentDepth ?? botConfig.maxAgentDepth);
|
|
24
|
-
const queue = typeof options.queue === "function" ? options.queue() : options.queue;
|
|
25
|
-
return await spawnChildAgent({
|
|
26
|
-
actor,
|
|
27
|
-
...input.name ? { agentName: input.name } : void 0,
|
|
28
|
-
...input.agentType ? { agentType: input.agentType } : void 0,
|
|
29
|
-
...input.fork ? { fork: true } : void 0,
|
|
30
|
-
...run.credentialContext ? { credentialContext: run.credentialContext } : void 0,
|
|
31
|
-
idempotencyKey: `${run.turnId}:${call.toolCallId}`,
|
|
32
|
-
input: input.task,
|
|
33
|
-
...input.kind ? { kind: input.kind } : void 0,
|
|
34
|
-
parentConversationId: run.conversationId,
|
|
35
|
-
parentToolCallId: call.toolCallId,
|
|
36
|
-
parentTurnId: run.turnId,
|
|
37
|
-
...input.reasoningLevel ? { reasoningLevel: input.reasoningLevel } : void 0,
|
|
38
|
-
...input.title ? { title: input.title } : void 0
|
|
39
|
-
}, {
|
|
40
|
-
...options,
|
|
41
|
-
queue
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export { spawn_exports as n, bindSpawnAgent as t };
|