@sentry/junior 0.312.0 → 0.314.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-iIq7ihf7.js → adapter-JARQvoLw.js} +1 -2
- package/dist/{adapter-context-BRjEWRy1.js → adapter-context-B4BrJZuS.js} +2 -2
- package/dist/{admin-DhInw5K9.js → admin-BXGAySz0.js} +1 -1
- package/dist/{agent-runner-C9iDurwX.js → agent-runner-qZU5TR8i.js} +865 -138
- package/dist/agent-update-cS7Z9mnG.js +26 -0
- package/dist/agent-update-delivery-CZ5M8RDa.js +85 -0
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +6 -6
- package/dist/api.d.ts +1 -1
- package/dist/api.js +340 -106
- package/dist/{app-DRFrC8Mw.d.ts → app-D7tKnw9a.d.ts} +4 -21
- package/dist/app.d.ts +2 -2
- package/dist/app.js +80 -171
- package/dist/{background-compaction-queue-DrKi7w3d.js → background-compaction-queue-C_uIBUvS.js} +6 -17
- package/dist/{callback-mFlTUWWx.js → callback-C8SdXCwr.js} +4 -11
- package/dist/{catalog-runtime-D7xapBAX.js → catalog-runtime-BLKtnUL3.js} +1 -1
- package/dist/{channel-access-CJGfNTdn.js → channel-access-BOL29BG3.js} +6 -6
- package/dist/child-message--2G3Ft26.js +19 -0
- package/dist/cli/chat.js +18 -21
- package/dist/cli/check.js +4 -4
- package/dist/cli/main.js +2 -2
- package/dist/cli/plugins.js +5 -5
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +23 -4
- package/dist/{config-kXB2Y5tl.js → config-BIfHKNXN.js} +40 -35
- package/dist/{continue-in-slack-O6pV5004.js → continue-in-slack-fnmD2Ifb.js} +5 -7
- package/dist/{conversation-feed-uNOv_x68.js → conversation-feed-DdFQuQDR.js} +13 -2
- package/dist/{logging-dQ9ZRGQ8.js → conversation-privacy-DtZhI91r.js} +188 -2
- package/dist/{conversation-turn-CeLbHqdw.js → conversation-turn-DScuDYmN.js} +465 -62
- package/dist/create-CrNt4Ewu.js +212 -0
- package/dist/{credential-sync-I8VBGk05.js → credential-sync-CtqsGjj1.js} +14 -18
- package/dist/{credentialed-Cb6E2phL.js → credentialed-dWRA3-oJ.js} +911 -429
- package/dist/{db-LAyyX8tk.js → db-BTmLKZrp.js} +2245 -50
- package/dist/{db-BbC5stfa.d.ts → db-DcmzbA55.d.ts} +2 -2
- package/dist/{history-CYstOMKX.js → history-CneKY7_V.js} +19 -1
- package/dist/{html-BCZ3Xtb_.js → html-B8rBt7F4.js} +5 -7
- package/dist/{install-DCFJFkC0.js → install-OtFboxOM.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-B_m-4TJw.js → lineage-EULJkGO1.js} +1 -2
- package/dist/{list-CN2QA2R9.js → list-C5400AlJ.js} +284 -113
- package/dist/{thread-state-DhPndWi1.js → mailbox-turn-DL3Lvsm0.js} +4830 -485
- package/dist/markers-DUP8aBOp.js +323 -0
- package/dist/{media-CYm1QD8T.js → media-FYM-Bl3H.js} +42 -14
- package/dist/{message-DSXGj1hM.js → message-DuDelZFr.js} +16 -15
- package/dist/{model-input--TrP9hYV.js → model-input-0osF3pBS.js} +3 -3
- package/dist/nitro.d.ts +2 -4
- package/dist/nitro.js +340 -13
- package/dist/{oauth-callback-server-DHCZC6B4.js → oauth-callback-server-DX2fQ7Nq.js} +2 -2
- package/dist/{oauth-relay-pPMGnDZt.js → oauth-relay-PwPMdZJv.js} +1 -1
- package/dist/{plugins-Bkk0XRo2.js → plugins-BXMdNdyA.js} +1 -1
- package/dist/{registry-CZOzddwu.js → registry-D6kS6xYH.js} +1402 -64
- package/dist/{statuses-_cRJHXK7.js → reporting-window-C4dbzDiR.js} +1 -27
- package/dist/{resolve-cKOQ14Dh.js → resolve-D8CPJcNK.js} +3 -3
- package/dist/result-D090hxr5.js +402 -0
- package/dist/{runner-DBfUW44l.js → runner-BU7fgrm-.js} +7 -8
- package/dist/{sandbox-egress-signals-BVF_xAm1.js → sandbox-egress-signals-BUmVrsoG.js} +1 -1
- package/dist/{schema-Bk9Nm2E8.js → schema-7gW9vBpJ.js} +91 -10
- package/dist/{schema-BEHKxr4I.d.ts → schema-BB6E0wyV.d.ts} +2105 -2753
- package/dist/{service-account-CVYsFjty.js → service-account-plA-uzIB.js} +6 -5
- package/dist/{skills-VTnhAJWm.js → skills-CIosT6bS.js} +3 -3
- package/dist/{slack-conversation-unfurl-fuLnF1jE.js → slack-conversation-unfurl-CBgZqth6.js} +8 -10
- package/dist/spawn-DRjdzh3R.js +46 -0
- package/dist/{start-conversation-CEn2KH1A.js → start-conversation-a4NXH4X9.js} +13 -202
- package/dist/{store-DFZaN-Ix.js → store-BuhF1QDm.js} +2 -4
- package/dist/{task-queue-Cx4Lmjyk.js → task-queue-CrRjFzOh.js} +5 -16
- package/dist/{task-runner-CbTwFA6k.js → task-runner-C-pXsgHM.js} +105 -51
- package/dist/{thread-context-BkAZDTX2.js → thread-context-CDX4dSZd.js} +8 -10
- package/dist/turn-session-routing-CZTRU8IY.js +116 -0
- package/dist/turn-wake-Bzq1Efrm.js +154 -0
- package/dist/user-customization-B27StpVQ.js +9 -0
- package/dist/{validation-nIzMtAVJ.js → validation-bTq88sya.js} +1 -1
- package/dist/{vercel-queue-hW90XzbG.js → vercel-queue-nL0Hq3hr.js} +32 -147
- package/dist/{version-Brbtz4Qf.js → version-DGUa1dZK.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-BDA5myRK.js → warmup-CCOuIwAS.js} +831 -3254
- package/dist/{worker-D63RcaVD.js → worker-AkZg7Dg1.js} +5 -6
- package/migrations/0158_keep_legacy_archive_columns.sql +5 -0
- package/migrations/0159_conversation_embeddings_fk_validate.sql +5 -0
- package/migrations/0160_money_micro_usd_repair.sql +99 -0
- package/migrations/0161_agent_config_backfill.sql +34 -0
- package/migrations/0162_inbox_item_deliveries.sql +15 -0
- package/migrations/0163_pg_trgm.sql +2 -0
- package/migrations/0164_search_indexes.sql +4 -0
- package/migrations/0165_drop_legacy_archive_columns.sql +4 -0
- package/migrations/0166_memory_prefix_index.sql +1 -0
- package/migrations/0167_todo_search_indexes.sql +2 -0
- package/migrations/0168_todo_inbox_items.sql +4 -0
- package/migrations/0169_drop_code_urls.sql +2 -0
- package/migrations/meta/0158_snapshot.json +6515 -0
- package/migrations/meta/0159_snapshot.json +6515 -0
- package/migrations/meta/0160_snapshot.json +6515 -0
- package/migrations/meta/0161_snapshot.json +6278 -0
- package/migrations/meta/0162_snapshot.json +6404 -0
- package/migrations/meta/0163_snapshot.json +6404 -0
- package/migrations/meta/0164_snapshot.json +6466 -0
- package/migrations/meta/0165_snapshot.json +6466 -0
- package/migrations/meta/0166_snapshot.json +6494 -0
- package/migrations/meta/0167_snapshot.json +6525 -0
- package/migrations/meta/0168_snapshot.json +6525 -0
- package/migrations/meta/0169_snapshot.json +6513 -0
- package/migrations/meta/_journal.json +84 -0
- package/package.json +9 -18
- package/skills/design-automation-skill/SKILL.md +2 -3
- package/dist/actor-BsBdxDXQ.js +0 -208
- package/dist/child-message-DcsritGf.js +0 -179
- package/dist/conversation-privacy-L4ja1_W6.js +0 -189
- package/dist/executor-SCub-fAq.js +0 -1860
- package/dist/fan-out-Cod-yEHG.js +0 -10
- package/dist/ingest-BDf3D50j.js +0 -3836
- package/dist/result-DcvEOe1r.js +0 -574
- package/dist/result-event-type-BdIJuZxg.js +0 -48
- package/dist/service-account-Ts4ulcrV.js +0 -931
- package/dist/spawn-vxAarlX5.js +0 -73
- package/dist/state-C1P3_Ywk.js +0 -161
|
@@ -121,30 +121,4 @@ function sumUtcHoursIntoSixHours(args) {
|
|
|
121
121
|
rows: bySix
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
const AGENT_INVOCATION_STATUSES = [
|
|
126
|
-
"pending",
|
|
127
|
-
"running",
|
|
128
|
-
"paused",
|
|
129
|
-
"blocked",
|
|
130
|
-
"completed",
|
|
131
|
-
"failed",
|
|
132
|
-
"stopped"
|
|
133
|
-
];
|
|
134
|
-
const AGENT_INVOCATION_MAILBOX_STATUSES = ["pending", "appended"];
|
|
135
|
-
/**
|
|
136
|
-
* Parent mailbox append state. Only terminal invocations have a value.
|
|
137
|
-
* `replaced` means the child still had open work, so a later agent invocation
|
|
138
|
-
* on the same child sends the result instead. `skipped` means a stop ended
|
|
139
|
-
* the work, so the result is never used. `steered` means the agent invocation
|
|
140
|
-
* that was running read the input as a steering message, so its result covers
|
|
141
|
-
* this one.
|
|
142
|
-
*/
|
|
143
|
-
const AGENT_INVOCATION_PARENT_MAILBOX_STATUSES = [
|
|
144
|
-
"pending",
|
|
145
|
-
"appended",
|
|
146
|
-
"replaced",
|
|
147
|
-
"skipped",
|
|
148
|
-
"steered"
|
|
149
|
-
];
|
|
150
|
-
export { HOUR_MS as a, fillUtcSixHours as c, trailingUtcDayWindow as d, trailingUtcHourWindow as f, DAY_MS as i, startOfUtcHour as l, utcHourKey as m, AGENT_INVOCATION_PARENT_MAILBOX_STATUSES as n, fillUtcDays as o, trailingUtcSixHourWindow as p, AGENT_INVOCATION_STATUSES as r, fillUtcHours as s, AGENT_INVOCATION_MAILBOX_STATUSES as t, sumUtcHoursIntoSixHours as u };
|
|
124
|
+
export { fillUtcSixHours as a, trailingUtcDayWindow as c, utcHourKey as d, fillUtcHours as i, trailingUtcHourWindow as l, HOUR_MS as n, startOfUtcHour as o, fillUtcDays as r, sumUtcHoursIntoSixHours as s, DAY_MS as t, trailingUtcSixHourWindow as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as trace, n as postinstall, o as getSandboxResources, t as dependencies } from "./install-
|
|
2
|
-
import {
|
|
3
|
-
import { i as getStateAdapter } from "./adapter-
|
|
1
|
+
import { i as trace, n as postinstall, o as getSandboxResources, t as dependencies } from "./install-OtFboxOM.js";
|
|
2
|
+
import { an as create, is as sleep, ln as getSandboxProvider, sn as isStale } from "./credentialed-dWRA3-oJ.js";
|
|
3
|
+
import { i as getStateAdapter } from "./adapter-JARQvoLw.js";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
// src/chat/sandbox/snapshot/resolve.ts
|
|
6
6
|
const SNAPSHOT_CACHE_PREFIX = "junior:sandbox_snapshot_profile:v2";
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
+
import { W as turnBehavior, dn as SYSTEM_IDENTITY_ID, i as getConversationStore, o as getSqlExecutor } from "./db-BTmLKZrp.js";
|
|
3
|
+
import { Bt as getConversationWorkState, G as enqueueAutomatedInput, K as getConversationStoppedAtMs, On as buildDeterministicTurnId, Or as EVENT_SYSTEM_ACTOR, T as getTurnReplyKey, a as resolveMailboxTurnWork, b as readAgentConfig, bi as readParentMessage, fn as closeOpenTodosOfChild, g as parentMessageText, h as logDroppedParentMessage, hi as readInboundMessageSender, i as listActiveMailboxTurns, k as EVENT_WAIT_MS, x as getAgentReplyMessageId } from "./mailbox-turn-DL3Lvsm0.js";
|
|
4
|
+
import { Fo as listWatches } from "./credentialed-dWRA3-oJ.js";
|
|
5
|
+
import { _ as isDroppedChildInput, c as listUnreportedSiblingAgents, g as getChildAgentInputSender, h as childAgentInput, r as hasWaitingParentWork, s as listOpenChildAgents, t as recordChildAgentEnded, v as readChildConversationSender } from "./markers-DUP8aBOp.js";
|
|
6
|
+
import { n as listChildMessages, t as childMessageSenderMetadata } from "./child-message--2G3Ft26.js";
|
|
7
|
+
import { gt as mapBounded, nt as renderDataTag } from "./config-BIfHKNXN.js";
|
|
8
|
+
import { an as AGENT_UPDATE_EVENT_TYPE, in as AGENT_MESSAGE_EVENT_TYPE, rn as AGENT_INVOCATION_EVENT_NAMESPACE } from "./media-FYM-Bl3H.js";
|
|
9
|
+
import { t as renderAgentResult } from "./agent-update-cS7Z9mnG.js";
|
|
10
|
+
import * as z from "zod";
|
|
11
|
+
import { actorSchema } from "@sentry/junior-plugin-api";
|
|
12
|
+
// src/chat/agent-invocations/store.ts
|
|
13
|
+
/**
|
|
14
|
+
* Read the name, agent type, fork flag, and title of one child Conversation,
|
|
15
|
+
* for labels, from its binding, title, and agent config.
|
|
16
|
+
*/
|
|
17
|
+
async function getChildAgentLabel(childConversationId) {
|
|
18
|
+
const [sender, options] = await Promise.all([readChildConversationSender(childConversationId), readAgentConfig(childConversationId)]);
|
|
19
|
+
return sender && options ? {
|
|
20
|
+
agentName: sender.agentName ?? null,
|
|
21
|
+
agentType: options.agentType ?? null,
|
|
22
|
+
fork: options.fork ?? false,
|
|
23
|
+
title: sender.title ?? null
|
|
24
|
+
} : void 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return whether a child agent still works when its Turn sends a `reply`:
|
|
28
|
+
* one of its own child agents has open work, or a reply or message from one
|
|
29
|
+
* of them waits in its mailbox. That reply then goes to the parent as a
|
|
30
|
+
* message, not as the child's result.
|
|
31
|
+
*/
|
|
32
|
+
async function childAgentStillWorks(conversationId) {
|
|
33
|
+
if ((await listOpenChildAgents(conversationId)).length > 0) return true;
|
|
34
|
+
return ((await getConversationWorkState({ conversationId }))?.messages ?? []).some((message) => readInboundMessageSender(message) !== void 0);
|
|
35
|
+
}
|
|
36
|
+
// src/chat/agent-invocations/parent-result.ts
|
|
37
|
+
/**
|
|
38
|
+
* Return the Actor that a child Turn's result carries to its parent, whose
|
|
39
|
+
* Turn for it runs as that Actor. Only a Turn that agent work started, a
|
|
40
|
+
* parent message or an Event such as a child result, keeps its Actor. Any
|
|
41
|
+
* other Turn, such as a person's Turn in a Thread or a saved Turn with no
|
|
42
|
+
* Source, reports as the Event system Actor, so the parent never gets a
|
|
43
|
+
* person's access.
|
|
44
|
+
*/
|
|
45
|
+
function parentResultActor(actor, source) {
|
|
46
|
+
return source === "parent_message" || source === "event" ? actor : EVENT_SYSTEM_ACTOR;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return whether a child's work ended with its Turn `turnId`, which ended
|
|
50
|
+
* with no answer: none of its own child agents still works, it has no active
|
|
51
|
+
* Watch or Timer, no input waits to run a later Turn that answers, and the
|
|
52
|
+
* Turn sent its parent nothing. A Turn can send its `reply` and then lose
|
|
53
|
+
* its worker, so its retry already reported.
|
|
54
|
+
*/
|
|
55
|
+
async function childWorkEnded(conversationId, turnId) {
|
|
56
|
+
const [stillWorks, watches, waiting, sender] = await Promise.all([
|
|
57
|
+
childAgentStillWorks(conversationId),
|
|
58
|
+
listWatches({ conversationId }),
|
|
59
|
+
hasWaitingParentWork(conversationId),
|
|
60
|
+
readChildConversationSender(conversationId)
|
|
61
|
+
]);
|
|
62
|
+
if (stillWorks || watches.length > 0 || waiting || !sender) return false;
|
|
63
|
+
const parent = await getConversationWorkState({ conversationId: sender.parentConversationId });
|
|
64
|
+
return !listChildMessages(parent?.execution.inboundMessageIds ?? [], parent?.execution.messageSenders ?? {}).some((message) => message.sender.conversationId === conversationId && message.sender.turnId === turnId);
|
|
65
|
+
}
|
|
66
|
+
// src/chat/agent-invocations/result-actors.ts
|
|
67
|
+
const senderActorMetadataSchema = z.object({ actor: actorSchema });
|
|
68
|
+
/**
|
|
69
|
+
* Return the Inbound message author id for results sent by one Actor.
|
|
70
|
+
* `selectContiguousTurnBatch` in `task-execution/worker.ts` puts messages in
|
|
71
|
+
* one attempt only when their author ids and sources match. Mid-Turn drains
|
|
72
|
+
* take only `interrupt` messages, and results are `defer`. So results never
|
|
73
|
+
* share a Turn and its credentials with another Actor or with watch Events.
|
|
74
|
+
* Keep this id unique per Actor if either rule changes.
|
|
75
|
+
*/
|
|
76
|
+
function resultAuthorId(actor) {
|
|
77
|
+
switch (actor.platform) {
|
|
78
|
+
case "system": return `agent-invocation:system:${actor.name}`;
|
|
79
|
+
case "slack": return `agent-invocation:slack:${actor.teamId}:${actor.userId}`;
|
|
80
|
+
default: return `agent-invocation:${actor.platform}:${actor.userId}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Read the Actor of the child Turn that a reply or message carries. */
|
|
84
|
+
function senderActorFromMetadata(metadata) {
|
|
85
|
+
const parsed = senderActorMetadataSchema.safeParse(metadata);
|
|
86
|
+
return parsed.success ? parsed.data.actor : void 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Run each child reply or message as the Actor of the child Turn that sent
|
|
90
|
+
* it, which the input carries, so the parent never gets more authority than
|
|
91
|
+
* that Turn. A parent message from the stored parent runs as the Actor of the
|
|
92
|
+
* parent's Turn, with its grants and text. Input that a Turn with another
|
|
93
|
+
* Actor sent, or that names no child of this Conversation, runs as the Event
|
|
94
|
+
* system Actor. Input that `isDroppedChildInput` drops is left out. Returns
|
|
95
|
+
* undefined when no input is left.
|
|
96
|
+
*/
|
|
97
|
+
async function withAgentInvocationResultActors(work) {
|
|
98
|
+
if (work.kind !== "mailbox") return work;
|
|
99
|
+
const kept = (await mapBounded(work.batch, async (entry) => {
|
|
100
|
+
const parentMessage = readParentMessage(entry.message);
|
|
101
|
+
if (parentMessage) {
|
|
102
|
+
if (await isDroppedChildInput(entry.message)) {
|
|
103
|
+
logDroppedParentMessage(entry.message, parentMessage);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const text = await parentMessageText(entry.message, parentMessage);
|
|
107
|
+
return {
|
|
108
|
+
...entry,
|
|
109
|
+
actor: parentMessage.actor,
|
|
110
|
+
requestText: entry.message.input.text.trim(),
|
|
111
|
+
...parentMessage.credentialContext ? { credentialContext: parentMessage.credentialContext } : void 0,
|
|
112
|
+
message: {
|
|
113
|
+
...entry.message,
|
|
114
|
+
input: {
|
|
115
|
+
...entry.message.input,
|
|
116
|
+
text
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const input = childAgentInput(entry.message);
|
|
122
|
+
if (!input) return entry;
|
|
123
|
+
if (await isDroppedChildInput(entry.message)) return;
|
|
124
|
+
const sender = await getChildAgentInputSender(entry.message, input);
|
|
125
|
+
const actor = senderActorFromMetadata(entry.message.input.metadata);
|
|
126
|
+
if (!sender || !actor || entry.message.input.authorId !== resultAuthorId(actor)) return {
|
|
127
|
+
...entry,
|
|
128
|
+
actor: EVENT_SYSTEM_ACTOR
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
...entry,
|
|
132
|
+
actor
|
|
133
|
+
};
|
|
134
|
+
})).filter((entry) => entry !== void 0);
|
|
135
|
+
return kept.length > 0 ? {
|
|
136
|
+
kind: "mailbox",
|
|
137
|
+
batch: kept
|
|
138
|
+
} : void 0;
|
|
139
|
+
}
|
|
140
|
+
// src/chat/agent-invocations/result.ts
|
|
141
|
+
var result_exports = /* @__PURE__ */ __exportAll({
|
|
142
|
+
createChildConversationWorker: () => createChildConversationWorker,
|
|
143
|
+
createDeliverToParent: () => createDeliverToParent
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* Render the parent agent input for one child agent result as one
|
|
147
|
+
* `<agent-result>`, the agent update that a Watch on the child also gets.
|
|
148
|
+
* The system prompt says what to do for each status, so the input repeats no
|
|
149
|
+
* guidance.
|
|
150
|
+
*/
|
|
151
|
+
function renderResultInput(sender, result, openSiblings) {
|
|
152
|
+
return renderAgentResult({
|
|
153
|
+
conversationId: sender.childConversationId,
|
|
154
|
+
name: sender.agentName,
|
|
155
|
+
source: "child_agent",
|
|
156
|
+
title: sender.title,
|
|
157
|
+
update: {
|
|
158
|
+
status: result.status,
|
|
159
|
+
text: result.output
|
|
160
|
+
},
|
|
161
|
+
waitingOn: openSiblings.length ? openSiblings.map(siblingLabel).join(", ") : void 0
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function siblingLabel(sibling) {
|
|
165
|
+
return sibling.agentName ?? sibling.title ?? sibling.childConversationId;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Render one `<agent-result>` under the parent's mailbox lock. `waiting_on`
|
|
169
|
+
* then sees every `reply` that reached the parent, also one that a sibling
|
|
170
|
+
* sent at the same moment, so two siblings cannot each name the other.
|
|
171
|
+
*/
|
|
172
|
+
function renderResultUnderLock(sender, result) {
|
|
173
|
+
return async (parentInboundMessageIds, messageSenders) => renderResultInput(sender, result, await listUnreportedSiblingAgents(sender.parentConversationId, sender.childConversationId, listChildMessages(parentInboundMessageIds, messageSenders)));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Drop the child's open To-dos of the parent before the parent reads that
|
|
177
|
+
* the child was stopped.
|
|
178
|
+
*/
|
|
179
|
+
async function dropTodosOfStoppedChild(sender, nowMs) {
|
|
180
|
+
await closeOpenTodosOfChild(getSqlExecutor(), {
|
|
181
|
+
childConversationId: sender.childConversationId,
|
|
182
|
+
nowMs,
|
|
183
|
+
parentConversationId: sender.parentConversationId,
|
|
184
|
+
status: "dropped"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Read every child reply and result that reached the parent's mailbox. A
|
|
189
|
+
* sibling whose `reply` is among them has answered.
|
|
190
|
+
*/
|
|
191
|
+
async function readParentChildMessages(parentConversationId, state) {
|
|
192
|
+
const work = await getConversationWorkState({
|
|
193
|
+
conversationId: parentConversationId,
|
|
194
|
+
state
|
|
195
|
+
});
|
|
196
|
+
return listChildMessages(work?.execution.inboundMessageIds ?? [], work?.execution.messageSenders ?? {});
|
|
197
|
+
}
|
|
198
|
+
function childAgentLabel(sender) {
|
|
199
|
+
return sender.agentName ? `Child agent "${sender.agentName}"` : "Child agent";
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Mailbox metadata of a reply or message from a child. It carries the Actor
|
|
203
|
+
* of the child's Turn, so the parent runs with no more authority than that
|
|
204
|
+
* Turn. The author id must match it.
|
|
205
|
+
*/
|
|
206
|
+
function senderEventMetadata(actor, event) {
|
|
207
|
+
return {
|
|
208
|
+
kind: "event",
|
|
209
|
+
event,
|
|
210
|
+
actor
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function renderMessageInput(sender, text) {
|
|
214
|
+
return renderDataTag("agent-message", {
|
|
215
|
+
conversation_id: sender.childConversationId,
|
|
216
|
+
name: sender.agentName,
|
|
217
|
+
source: "child_agent",
|
|
218
|
+
title: sender.title
|
|
219
|
+
}, "A child agent that you started", text.trim());
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Append one message from a child agent to its parent mailbox and wake the
|
|
223
|
+
* parent. `sender` names the child, and `actor` is the Actor of the child's
|
|
224
|
+
* Turn. The parent handles the message like a result. Repeat calls with the
|
|
225
|
+
* same `messageKey` are safe.
|
|
226
|
+
*/
|
|
227
|
+
async function enqueueAgentMessageToParent(args) {
|
|
228
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
229
|
+
const senderId = args.sender.childConversationId;
|
|
230
|
+
const inboundMessageId = `agent-invocation:${senderId}:message:${args.messageKey}`;
|
|
231
|
+
const summary = `${childAgentLabel(args.sender)} sent a message.`;
|
|
232
|
+
const metadata = senderEventMetadata(args.actor, {
|
|
233
|
+
eventKey: inboundMessageId,
|
|
234
|
+
eventType: AGENT_MESSAGE_EVENT_TYPE,
|
|
235
|
+
identifier: senderId,
|
|
236
|
+
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
237
|
+
trustedSummary: summary
|
|
238
|
+
});
|
|
239
|
+
await enqueueAutomatedInput({
|
|
240
|
+
message: {
|
|
241
|
+
conversationId: args.sender.parentConversationId,
|
|
242
|
+
createdAtMs: nowMs,
|
|
243
|
+
delivery: "defer",
|
|
244
|
+
inboundMessageId,
|
|
245
|
+
input: {
|
|
246
|
+
authorId: resultAuthorId(args.actor),
|
|
247
|
+
authorIdentityId: SYSTEM_IDENTITY_ID,
|
|
248
|
+
metadata,
|
|
249
|
+
text: renderMessageInput(args.sender, args.text)
|
|
250
|
+
},
|
|
251
|
+
receivedAtMs: nowMs,
|
|
252
|
+
source: "event"
|
|
253
|
+
},
|
|
254
|
+
queue: args.queue,
|
|
255
|
+
queueDelayMs: EVENT_WAIT_MS,
|
|
256
|
+
state: args.state
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
const RESULT_SUMMARIES = {
|
|
260
|
+
blocked: "is blocked.",
|
|
261
|
+
completed: "finished.",
|
|
262
|
+
failed: "failed.",
|
|
263
|
+
reply: "replied.",
|
|
264
|
+
stopped: "was stopped."
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Append the result of one child agent Turn to its parent mailbox and wake
|
|
268
|
+
* the parent: a `reply`, which the parent reads as a completed
|
|
269
|
+
* `<agent-result>` or, while the child still works, as a message, or a
|
|
270
|
+
* completed, blocked, failed, or stopped result. `sender` names the child,
|
|
271
|
+
* and `actor` is the Actor of the child's Turn; the parent never runs with
|
|
272
|
+
* more authority than it. The key of the result, the `reply` tool call id or the
|
|
273
|
+
* Turn id, keys the message, so a repeat call is safe.
|
|
274
|
+
*/
|
|
275
|
+
async function enqueueChildResultToParent(args) {
|
|
276
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
277
|
+
const senderId = args.sender.childConversationId;
|
|
278
|
+
const inboundMessageId = getAgentReplyMessageId(senderId, args.messageKey);
|
|
279
|
+
const rendered = args.result.kind === "reply" ? {
|
|
280
|
+
output: args.result.reply.text,
|
|
281
|
+
status: "completed"
|
|
282
|
+
} : {
|
|
283
|
+
output: args.result.text,
|
|
284
|
+
status: args.result.kind
|
|
285
|
+
};
|
|
286
|
+
const stillWorks = (args.result.kind === "reply" || args.result.kind === "completed") && await childAgentStillWorks(senderId);
|
|
287
|
+
const text = stillWorks ? renderMessageInput(args.sender, rendered.output) : renderResultInput(args.sender, rendered, []);
|
|
288
|
+
const metadata = {
|
|
289
|
+
...senderEventMetadata(args.actor, {
|
|
290
|
+
eventKey: inboundMessageId,
|
|
291
|
+
eventType: AGENT_UPDATE_EVENT_TYPE,
|
|
292
|
+
identifier: senderId,
|
|
293
|
+
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
294
|
+
...stillWorks ? void 0 : { status: rendered.status },
|
|
295
|
+
trustedSummary: `${childAgentLabel(args.sender)} ${stillWorks ? "sent a message." : RESULT_SUMMARIES[args.result.kind]}`
|
|
296
|
+
}),
|
|
297
|
+
...childMessageSenderMetadata({
|
|
298
|
+
conversationId: senderId,
|
|
299
|
+
turnId: args.turnId
|
|
300
|
+
})
|
|
301
|
+
};
|
|
302
|
+
if (args.result.kind === "stopped" && !(await readParentChildMessages(args.sender.parentConversationId, args.state)).some((message) => message.inboundMessageId === inboundMessageId)) await dropTodosOfStoppedChild(args.sender, nowMs);
|
|
303
|
+
await enqueueAutomatedInput({
|
|
304
|
+
message: {
|
|
305
|
+
conversationId: args.sender.parentConversationId,
|
|
306
|
+
createdAtMs: nowMs,
|
|
307
|
+
delivery: "defer",
|
|
308
|
+
inboundMessageId,
|
|
309
|
+
input: {
|
|
310
|
+
authorId: resultAuthorId(args.actor),
|
|
311
|
+
authorIdentityId: SYSTEM_IDENTITY_ID,
|
|
312
|
+
metadata,
|
|
313
|
+
text
|
|
314
|
+
},
|
|
315
|
+
receivedAtMs: nowMs,
|
|
316
|
+
source: "event"
|
|
317
|
+
},
|
|
318
|
+
renderText: async (parentInboundMessageIds, messageSenders) => args.result.kind !== "stopped" && await getConversationStoppedAtMs(senderId) !== void 0 ? void 0 : stillWorks ? text : await renderResultUnderLock(args.sender, rendered)(parentInboundMessageIds, messageSenders),
|
|
319
|
+
queue: args.queue,
|
|
320
|
+
queueDelayMs: EVENT_WAIT_MS,
|
|
321
|
+
state: args.state
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const PARENT_RESULT_OUTCOMES = {
|
|
325
|
+
blocked: "blocked",
|
|
326
|
+
completed: "success",
|
|
327
|
+
failed: "error",
|
|
328
|
+
reply: "success",
|
|
329
|
+
stopped: "aborted"
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Build the parent delivery of child agent Turns. The child Conversation
|
|
333
|
+
* names the child for the parent.
|
|
334
|
+
*/
|
|
335
|
+
function createDeliverToParent(options) {
|
|
336
|
+
return async ({ actor, result, conversationId, turnId }) => {
|
|
337
|
+
const sender = await readChildConversationSender(conversationId);
|
|
338
|
+
if (!sender) throw new Error(`Conversation ${conversationId} has no parent agent`);
|
|
339
|
+
await recordChildAgentEnded(conversationId, PARENT_RESULT_OUTCOMES[result.kind], options);
|
|
340
|
+
await enqueueChildResultToParent({
|
|
341
|
+
actor,
|
|
342
|
+
result,
|
|
343
|
+
messageKey: result.kind === "reply" ? getTurnReplyKey(turnId, result.reply.toolCallId) : turnId,
|
|
344
|
+
queue: options.queue,
|
|
345
|
+
sender,
|
|
346
|
+
state: options.state,
|
|
347
|
+
turnId
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* End the work of a child Conversation whose last attempt lost its worker.
|
|
353
|
+
* Its open markers end with `error`. Then the child tells its parent that it
|
|
354
|
+
* failed, as a failed Turn does.
|
|
355
|
+
*/
|
|
356
|
+
function createEndStoppedChildWork(options) {
|
|
357
|
+
const deliverToParent = createDeliverToParent(options);
|
|
358
|
+
return async (conversationId, inboundMessageIds) => {
|
|
359
|
+
await recordChildAgentEnded(conversationId, "error", { includeWaiting: true });
|
|
360
|
+
const conversation = await getConversationStore().get({ conversationId });
|
|
361
|
+
if (!conversation || turnBehavior({
|
|
362
|
+
kind: conversation.kind,
|
|
363
|
+
personInput: false
|
|
364
|
+
}).failureNotice !== "parent") return;
|
|
365
|
+
const turns = await listActiveMailboxTurns(conversationId);
|
|
366
|
+
const pending = (await getConversationWorkState({ conversationId }))?.execution.pendingMessages ?? [];
|
|
367
|
+
const turnIds = /* @__PURE__ */ new Set([...turns.map((turn) => turn.turnId), ...pending.map((message) => buildDeterministicTurnId(message.inboundMessageId))]);
|
|
368
|
+
const sender = await readChildConversationSender(conversationId);
|
|
369
|
+
if (sender && (await readParentChildMessages(sender.parentConversationId, void 0)).some((message) => message.sender.conversationId === conversationId && turnIds.has(message.sender.turnId))) return;
|
|
370
|
+
const [turn] = turns;
|
|
371
|
+
await deliverToParent({
|
|
372
|
+
actor: parentResultActor(turn?.actor ?? EVENT_SYSTEM_ACTOR, turn?.source?.kind),
|
|
373
|
+
result: {
|
|
374
|
+
kind: "failed",
|
|
375
|
+
text: `This ${conversation.kind} stopped because its worker failed repeatedly.`
|
|
376
|
+
},
|
|
377
|
+
conversationId,
|
|
378
|
+
turnId: turn?.turnId ?? `lost:${inboundMessageIds.at(-1) ?? "input"}`
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Build the worker for all work of a child Conversation. The caller selects
|
|
384
|
+
* it from the stored kind of the Conversation, never from a Turn Source.
|
|
385
|
+
* Every input, such as a parent task or message, a person's Message in a
|
|
386
|
+
* Thread, a Watch Event, or a reply of the child's own child agent, runs on
|
|
387
|
+
* the Conversation loop, like input to a root.
|
|
388
|
+
*/
|
|
389
|
+
function createChildConversationWorker(options) {
|
|
390
|
+
return async (context) => {
|
|
391
|
+
const work = await resolveMailboxTurnWork(context);
|
|
392
|
+
const kept = work ? await withAgentInvocationResultActors(work) : void 0;
|
|
393
|
+
if (!kept) {
|
|
394
|
+
await context.attempt.ack();
|
|
395
|
+
return { status: "completed" };
|
|
396
|
+
}
|
|
397
|
+
const result = await options.runTurn(context, kept);
|
|
398
|
+
if (result.status === "completed") await recordChildAgentEnded(context.conversationId, "success", options);
|
|
399
|
+
return result;
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
export { result_exports as a, parentResultActor as c, enqueueAgentMessageToParent as i, getChildAgentLabel as l, createDeliverToParent as n, withAgentInvocationResultActors as o, createEndStoppedChildWork as r, childWorkEnded as s, createChildConversationWorker as t };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { xt as messageCardText } from "./media-
|
|
2
|
-
import { a as buildDeliveredTurnStatePatch, o as loadPendingMessageCards, r as completeAuthPauseTurn, t as buildTurnThreadContext } from "./thread-context-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Qt as SYSTEM_IDENTITY_ID, a as getConversationStore } from "./db-LAyyX8tk.js";
|
|
1
|
+
import { xt as messageCardText } from "./media-FYM-Bl3H.js";
|
|
2
|
+
import { a as buildDeliveredTurnStatePatch, o as loadPendingMessageCards, r as completeAuthPauseTurn, t as buildTurnThreadContext } from "./thread-context-CDX4dSZd.js";
|
|
3
|
+
import { Cr as recordDeliveredAssistantMessage, Er as upsertConversationMessage, Jn as commitAcceptedReply, Mi as finalizeFailedTurnReplyWithEvent, Rr as authorizationId, Sr as normalizeConversationText, Xr as saveTurnCheckpoint, Zi as getAssistantReplyText, Zn as loadConversationProjection, br as latestConversationMessageSeq, dr as hydrateConversationMessages, ft as markTurnFailed, gt as getPersistedThreadState, ht as getPersistedSandboxState, pr as persistConversationMessages, pt as startActiveTurn, rr as recordAuthorizationCompleted, sa as persistWithRetry, vt as persistThreadStateById, xi as getTurnLifecycle, xr as markConversationMessage, yt as coerceThreadConversationState } from "./mailbox-turn-DL3Lvsm0.js";
|
|
4
|
+
import { P as withLogContext, S as logException, j as setTags } from "./conversation-privacy-DtZhI91r.js";
|
|
5
|
+
import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-C-pXsgHM.js";
|
|
6
|
+
import { K as credentialContextForActor } from "./registry-D6kS6xYH.js";
|
|
7
|
+
import { dn as SYSTEM_IDENTITY_ID, i as getConversationStore } from "./db-BTmLKZrp.js";
|
|
9
8
|
import { randomUUID } from "node:crypto";
|
|
10
9
|
import { createLocalSource, localDestinationSchema } from "@sentry/junior-plugin-api";
|
|
11
10
|
// src/chat/local/runner.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Pn as sandboxEgressSignalsResponseSchema } from "./credentialed-dWRA3-oJ.js";
|
|
2
2
|
// src/chat/local/sandbox-egress-signals.ts
|
|
3
3
|
const SANDBOX_EGRESS_SIGNALS_PATH = "/api/internal/sandbox-egress/signals";
|
|
4
4
|
const LOCAL_DEV_SERVER_TIMEOUT_MS = 1e3;
|