@sentry/junior 0.246.0 → 0.247.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-Bh-MYw-j.js → admin-BGwaqDMs.js} +1 -1
- package/dist/{agent-hooks-DpklSWZg.js → agent-hooks-C72ByH0C.js} +11 -11
- package/dist/{agent-invocations-BO6ddZax.js → agent-invocations-D_YoNnAn.js} +8 -2
- package/dist/{agent-runner-DSKpHjHW.js → agent-runner-DsAFAKKs.js} +451 -2412
- package/dist/api/schema.js +2 -2
- package/dist/api.js +24 -21
- package/dist/{app-BYB7szGb.d.ts → app-4t4mPTdS.d.ts} +8 -1
- package/dist/app.d.ts +1 -1
- package/dist/app.js +30 -27
- package/dist/assistant-reply-ChOzcTBS.js +45 -0
- package/dist/{briefs-cZ5vWqP_.js → briefs-Dc7qZrhc.js} +4 -4
- package/dist/{catalog-runtime-CTaQXYqS.js → catalog-runtime-DS1k7fUG.js} +1 -1
- package/dist/cli/chat.js +22 -16
- 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--xtsAxKP.js → client-BVnfNd3D.js} +2 -2
- package/dist/{config-BK53Ip5C.js → config-CgWvImQL.js} +2 -2
- package/dist/{conversation-CvBG57Io.js → conversation-CYsbVFLx.js} +71 -1
- package/dist/{conversation-privacy-BDBFw6Ws.js → conversation-privacy-D3TdVM9H.js} +1 -1
- package/dist/{credential-sync-BiuhC9Ds.js → credential-sync-DLw3jkv-.js} +14 -14
- package/dist/{executor-bmmuRY-w.js → executor-DQazjeGA.js} +3 -3
- package/dist/{images-DZliDtSH.js → images-C3e5E-p_.js} +4 -21
- package/dist/instrumentation.js +2 -2
- package/dist/{job-queue-Cz3M7gg4.js → job-queue-BEUqRhjC.js} +1 -1
- package/dist/{logging-DVtMYOdD.js → logging-CZEc8_v4.js} +1 -1
- package/dist/message-BIJa7lKh.js +59 -0
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +3 -3
- package/dist/{oauth-authorization-By_MVRDC.js → oauth-authorization-BA4Dt6a7.js} +1 -45
- package/dist/{oauth-callback-server-BrUo6w1e.js → oauth-callback-server-R9OSdLP1.js} +2 -2
- package/dist/{pending-auth-BuQLZ6dK.js → pending-auth-Oo5AQhaf.js} +2 -2
- package/dist/{profile-BevMNSlr.js → profile-aVLDAirh.js} +4 -4
- package/dist/{prompt-C9Q9cjD3.js → prompt-ZG1UCxjF.js} +1 -1
- package/dist/{registry-C2rSEio1.js → registry-CtaDOOM5.js} +1 -1
- package/dist/{resolve-qPhrznTf.js → resolve-Bdw4hu7s.js} +2 -2
- package/dist/result-DNgmkASh.js +463 -0
- package/dist/{runner-CNh5eMWx.js → runner-BUSScEu5.js} +11 -10
- package/dist/{sandbox-egress-signals-BnDEKu8d.js → sandbox-egress-signals-E9r8bf9G.js} +1 -1
- package/dist/{schema-BWMRg8JS.js → schema-tyd6hALh.js} +2 -2
- package/dist/session-stop-CAhBfBUT.js +782 -0
- package/dist/{skills-C6zJbudq.js → skills-DQy-mmBC.js} +2 -2
- package/dist/{spawn-C3efZSx3.js → spawn-DQ_MVWZ6.js} +3 -2
- package/dist/store-DjLA8GKs.js +1417 -0
- package/dist/{task-queue-BX4vG6uA.js → task-queue-BT2h_t8I.js} +3 -3
- package/dist/{task-runner-T51kll0U.js → task-runner-CiPepjIB.js} +11 -11
- package/dist/{tasks-B9OIjl2K.js → tasks-DMmRrIVl.js} +9 -9
- package/dist/{thread-state-AGZtVyXp.js → thread-state-ehZYGpX9.js} +7 -7
- package/dist/{turn-failure-response-DJ8KU2bo.js → turn-failure-response-D7J10z7l.js} +9 -9
- package/dist/{turn-lifecycle-DZJkJ95q.js → turn-lifecycle-Buswqs90.js} +1 -1
- package/dist/{turn-session-routing-mRqLbMZW.js → turn-session-routing-Bw-yiSb4.js} +1 -1
- package/dist/{validation-Dg0Ihxzo.js → validation-DTguegIe.js} +1 -1
- package/dist/{version-Deub4try.js → version-BrZSE5du.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-D5hbx6TE.js → viewer-BlAozHer.js} +4 -4
- package/dist/{web-authorization-DCxixz5S.js → web-authorization-DwyTlkAg.js} +6 -6
- package/dist/{web-input-0sorYVLh.js → web-input-DSYxI7Wi.js} +43 -208
- package/dist/{work-rm2X7jj4.js → work-CRBXkJoU.js} +89 -13
- package/dist/{worker-bnGsAOP3.js → worker-BVJKM9Ja.js} +7 -7
- package/migrations/0053_conversation_stopped_at.sql +1 -0
- package/migrations/0054_flowery_rage.sql +1 -0
- package/migrations/meta/0053_snapshot.json +3771 -0
- package/migrations/meta/0054_snapshot.json +3777 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +6 -5
- package/dist/message-BSN-Ma5f.js +0 -317
|
@@ -372,6 +372,20 @@
|
|
|
372
372
|
"when": 1791940298241,
|
|
373
373
|
"tag": "0052_agent_invocation_title",
|
|
374
374
|
"breakpoints": true
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"idx": 53,
|
|
378
|
+
"version": "7",
|
|
379
|
+
"when": 1792012782650,
|
|
380
|
+
"tag": "0053_conversation_stopped_at",
|
|
381
|
+
"breakpoints": true
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
"idx": 54,
|
|
385
|
+
"version": "7",
|
|
386
|
+
"when": 1792027700779,
|
|
387
|
+
"tag": "0054_flowery_rage",
|
|
388
|
+
"breakpoints": true
|
|
375
389
|
}
|
|
376
390
|
]
|
|
377
391
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.247.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -85,9 +85,10 @@
|
|
|
85
85
|
"just-bash": "3.0.1",
|
|
86
86
|
"node-html-markdown": "^2.0.0",
|
|
87
87
|
"pg": "^8.16.3",
|
|
88
|
+
"sharp": "^0.35.3",
|
|
88
89
|
"yaml": "^2.9.0",
|
|
89
90
|
"zod": "^4.5.4",
|
|
90
|
-
"@sentry/junior-plugin-api": "0.
|
|
91
|
+
"@sentry/junior-plugin-api": "0.247.0"
|
|
91
92
|
},
|
|
92
93
|
"devDependencies": {
|
|
93
94
|
"@emnapi/core": "^1.10.0",
|
|
@@ -106,9 +107,9 @@
|
|
|
106
107
|
"typescript": "^6.0.3",
|
|
107
108
|
"vercel": "^54.4.0",
|
|
108
109
|
"vitest": "^4.1.7",
|
|
109
|
-
"@sentry/junior-github": "0.
|
|
110
|
-
"@sentry/junior-
|
|
111
|
-
"@sentry/junior-
|
|
110
|
+
"@sentry/junior-github": "0.247.0",
|
|
111
|
+
"@sentry/junior-memory": "0.247.0",
|
|
112
|
+
"@sentry/junior-testing": "0.0.0"
|
|
112
113
|
},
|
|
113
114
|
"scripts": {
|
|
114
115
|
"build": "tsdown",
|
package/dist/message-BSN-Ma5f.js
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
-
import { $ as getAgentInvocationIdForMessage, At as appendAndEnqueueInboundMessage, En as toolInvocationDestination, J as createAgentInvocationForMessage, Q as getAgentInvocation, Tn as actorFromRun, X as findChildAgentConversationId, Y as createAgentInvocationFromLatest, Z as getActiveAgentInvocationForConversation, at as getLatestAgentInvocationForConversation, bt as isEventMailboxMetadata, et as getAgentInvocationIdForResult, ht as PARENT_AGENT_TARGET, mt as AgentMessageTargetError, nt as getAgentInvocationResultMessageId, ot as isTerminalAgentInvocation, ut as markAgentInvocationParentMailboxAppended, yt as EVENT_WAIT_MS } from "./agent-runner-DSKpHjHW.js";
|
|
3
|
-
import { r as enqueueAgentInvocation } from "./work-rm2X7jj4.js";
|
|
4
|
-
//#region src/chat/agent-invocations/result.ts
|
|
5
|
-
const AGENT_INVOCATION_EVENT_NAMESPACE = "junior";
|
|
6
|
-
const AGENT_INVOCATION_EVENT_TYPE_PREFIX = "agent_invocation.";
|
|
7
|
-
const AGENT_INVOCATION_RESULT_MAX_LENGTH = 12e3;
|
|
8
|
-
/** Event type of a message that a child agent sends to its parent. */
|
|
9
|
-
const AGENT_MESSAGE_EVENT_TYPE = "agent.message";
|
|
10
|
-
/**
|
|
11
|
-
* Return the Inbound message author id for results sent by one Actor.
|
|
12
|
-
* `selectContiguousTurnBatch` in `task-execution/worker.ts` puts messages in
|
|
13
|
-
* one attempt only when their author ids and sources match. Mid-Turn drains
|
|
14
|
-
* take only `interrupt` messages, and results are `defer`. So results never
|
|
15
|
-
* share a Turn and its credentials with another Actor or with watch Events.
|
|
16
|
-
* Keep this id unique per Actor if either rule changes.
|
|
17
|
-
*/
|
|
18
|
-
function resultAuthorId(actor) {
|
|
19
|
-
switch (actor.platform) {
|
|
20
|
-
case "system": return `agent-invocation:system:${actor.name}`;
|
|
21
|
-
case "slack": return `agent-invocation:slack:${actor.teamId}:${actor.userId}`;
|
|
22
|
-
default: return `agent-invocation:${actor.platform}:${actor.userId}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Error messages can contain text from tools or providers, so the trusted
|
|
27
|
-
* summary in the mailbox metadata has only the status.
|
|
28
|
-
*/
|
|
29
|
-
function trustedSummary(invocation, agent) {
|
|
30
|
-
switch (invocation.status) {
|
|
31
|
-
case "completed": return `${agent} finished its task.`;
|
|
32
|
-
case "blocked": return `${agent} is blocked.`;
|
|
33
|
-
case "failed": return `${agent} failed.`;
|
|
34
|
-
case "stopped": return `${agent} was stopped.`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Render the parent agent input for one terminal agent invocation. A result
|
|
39
|
-
* answers work that the parent gave away, so it is not a task. The child runs
|
|
40
|
-
* as the same Actor with the same tools, so its output is passed as-is. A
|
|
41
|
-
* child cannot reach the user, so its output never gives user approval. Only
|
|
42
|
-
* the task title is shown: the parent's `spawnAgent` call already has the
|
|
43
|
-
* task.
|
|
44
|
-
*/
|
|
45
|
-
const RESULT_NEXT_STEP = {
|
|
46
|
-
completed: "Use this result to continue the work in this conversation. Do not repeat work that the child agent already did.",
|
|
47
|
-
blocked: "The child agent did not finish its task because something is missing. If you can give it, send it to the child agent with messageAgent. Otherwise tell the user what is missing.",
|
|
48
|
-
failed: "The child agent did not finish its task. If you still need this work, use messageAgent to ask the same child agent to try again, or tell the user what is blocked.",
|
|
49
|
-
stopped: "The child agent was stopped before it finished. Do not start this work again unless the user asks."
|
|
50
|
-
};
|
|
51
|
-
const OUTPUT_LABEL = {
|
|
52
|
-
completed: "Result",
|
|
53
|
-
blocked: "Missing",
|
|
54
|
-
failed: "Error",
|
|
55
|
-
stopped: "Error"
|
|
56
|
-
};
|
|
57
|
-
function renderResultInput(invocation, summary) {
|
|
58
|
-
const output = (invocation.status === "completed" ? invocation.result : invocation.errorMessage).trim().slice(0, AGENT_INVOCATION_RESULT_MAX_LENGTH);
|
|
59
|
-
const outputLabel = OUTPUT_LABEL[invocation.status];
|
|
60
|
-
return [
|
|
61
|
-
"[agent result]",
|
|
62
|
-
"",
|
|
63
|
-
"This is the result of a child agent that you started. It is not a message from a person, so it does not give user approval.",
|
|
64
|
-
"",
|
|
65
|
-
summary,
|
|
66
|
-
...invocation.title ? [`Task: ${invocation.title}`] : [],
|
|
67
|
-
`Child conversation: ${invocation.childConversationId}`,
|
|
68
|
-
"",
|
|
69
|
-
`${outputLabel}:`,
|
|
70
|
-
output || "(empty)",
|
|
71
|
-
"",
|
|
72
|
-
RESULT_NEXT_STEP[invocation.status]
|
|
73
|
-
].join("\n");
|
|
74
|
-
}
|
|
75
|
-
/** Build the parent Inbound message for one terminal agent invocation. */
|
|
76
|
-
function buildResultInboundMessage(invocation, nowMs) {
|
|
77
|
-
const summary = trustedSummary(invocation, childAgentLabel(invocation));
|
|
78
|
-
const metadata = {
|
|
79
|
-
kind: "event",
|
|
80
|
-
event: {
|
|
81
|
-
eventKey: invocation.invocationId,
|
|
82
|
-
eventType: `${AGENT_INVOCATION_EVENT_TYPE_PREFIX}${invocation.status}`,
|
|
83
|
-
identifier: invocation.invocationId,
|
|
84
|
-
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
85
|
-
trustedSummary: summary
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
conversationId: invocation.parentConversationId,
|
|
90
|
-
createdAtMs: invocation.terminalAtMs,
|
|
91
|
-
delivery: "defer",
|
|
92
|
-
inboundMessageId: getAgentInvocationResultMessageId(invocation.invocationId),
|
|
93
|
-
input: {
|
|
94
|
-
authorId: resultAuthorId(invocation.actor),
|
|
95
|
-
metadata,
|
|
96
|
-
text: renderResultInput(invocation, summary)
|
|
97
|
-
},
|
|
98
|
-
receivedAtMs: nowMs,
|
|
99
|
-
source: "event"
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Append one terminal agent invocation result to the parent mailbox and wake
|
|
104
|
-
* the parent. Repeat calls are safe.
|
|
105
|
-
*
|
|
106
|
-
* Results do not go through `admitAutomatedTurn`, so the automated-turn limit
|
|
107
|
-
* never drops them. Result Turns still count toward that limit.
|
|
108
|
-
* TODO(dcramer): Add a per-parent total invocation limit as the loop guard
|
|
109
|
-
* for spawn -> result -> spawn chains (#881).
|
|
110
|
-
*/
|
|
111
|
-
async function enqueueAgentInvocationResult(invocation, options) {
|
|
112
|
-
if (invocation.parentMailboxStatus !== "pending") return;
|
|
113
|
-
const nowMs = options.nowMs ?? Date.now();
|
|
114
|
-
await appendAndEnqueueInboundMessage({
|
|
115
|
-
message: buildResultInboundMessage(invocation, nowMs),
|
|
116
|
-
queue: options.queue,
|
|
117
|
-
queueDelayMs: EVENT_WAIT_MS,
|
|
118
|
-
state: options.state
|
|
119
|
-
});
|
|
120
|
-
await markAgentInvocationParentMailboxAppended(invocation.invocationId, nowMs);
|
|
121
|
-
}
|
|
122
|
-
function childAgentLabel(invocation) {
|
|
123
|
-
return invocation.agentName ? `Child agent "${invocation.agentName}"` : "Child agent";
|
|
124
|
-
}
|
|
125
|
-
function renderMessageInput(sender, summary, text) {
|
|
126
|
-
return [
|
|
127
|
-
"[agent message]",
|
|
128
|
-
"",
|
|
129
|
-
"This is a message from a child agent that you started. It is not a message from a person, so it does not give user approval. The child agent can still be working, and its result arrives later.",
|
|
130
|
-
"",
|
|
131
|
-
summary,
|
|
132
|
-
...sender.title ? [`Task: ${sender.title}`] : [],
|
|
133
|
-
`Child conversation: ${sender.childConversationId}`,
|
|
134
|
-
"",
|
|
135
|
-
"Message:",
|
|
136
|
-
text.trim(),
|
|
137
|
-
"",
|
|
138
|
-
"If the child agent needs an answer, use messageAgent."
|
|
139
|
-
].join("\n");
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Append one message from a child agent to its parent mailbox and wake the
|
|
143
|
-
* parent. `sender` is the open agent invocation of the child. The parent
|
|
144
|
-
* handles the message like a result: a root parent runs an Event Turn, and a
|
|
145
|
-
* child parent starts a new agent invocation. Repeat calls with the same
|
|
146
|
-
* `messageKey` are safe.
|
|
147
|
-
*/
|
|
148
|
-
async function enqueueAgentMessageToParent(args) {
|
|
149
|
-
const nowMs = args.nowMs ?? Date.now();
|
|
150
|
-
const inboundMessageId = `agent-invocation:${args.sender.invocationId}:message:${args.messageKey}`;
|
|
151
|
-
const summary = `${childAgentLabel(args.sender)} sent a message.`;
|
|
152
|
-
const metadata = {
|
|
153
|
-
kind: "event",
|
|
154
|
-
event: {
|
|
155
|
-
eventKey: inboundMessageId,
|
|
156
|
-
eventType: AGENT_MESSAGE_EVENT_TYPE,
|
|
157
|
-
identifier: args.sender.invocationId,
|
|
158
|
-
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
159
|
-
trustedSummary: summary
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
await appendAndEnqueueInboundMessage({
|
|
163
|
-
message: {
|
|
164
|
-
conversationId: args.sender.parentConversationId,
|
|
165
|
-
createdAtMs: nowMs,
|
|
166
|
-
delivery: "defer",
|
|
167
|
-
inboundMessageId,
|
|
168
|
-
input: {
|
|
169
|
-
authorId: resultAuthorId(args.sender.actor),
|
|
170
|
-
metadata,
|
|
171
|
-
text: renderMessageInput(args.sender, summary, args.text)
|
|
172
|
-
},
|
|
173
|
-
receivedAtMs: nowMs,
|
|
174
|
-
source: "event"
|
|
175
|
-
},
|
|
176
|
-
queue: args.queue,
|
|
177
|
-
queueDelayMs: EVENT_WAIT_MS,
|
|
178
|
-
state: args.state
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Read the agent invocation that one result or message Event refers to: the
|
|
183
|
-
* finished child work for a result, or the open sender work for a message.
|
|
184
|
-
*/
|
|
185
|
-
function childAgentInput(message) {
|
|
186
|
-
const metadata = message.input.metadata;
|
|
187
|
-
if (!isEventMailboxMetadata(metadata) || metadata.event.namespace !== AGENT_INVOCATION_EVENT_NAMESPACE) return;
|
|
188
|
-
if (metadata.event.eventType === AGENT_MESSAGE_EVENT_TYPE) return {
|
|
189
|
-
invocationId: metadata.event.identifier,
|
|
190
|
-
kind: "message"
|
|
191
|
-
};
|
|
192
|
-
return metadata.event.eventType.startsWith(AGENT_INVOCATION_EVENT_TYPE_PREFIX) ? {
|
|
193
|
-
invocationId: metadata.event.identifier,
|
|
194
|
-
kind: "result"
|
|
195
|
-
} : void 0;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Read the agent invocation of one result or message and check that it
|
|
199
|
-
* belongs to a child of the Conversation that received it.
|
|
200
|
-
*/
|
|
201
|
-
async function getChildAgentInputInvocation(message, input) {
|
|
202
|
-
const invocation = await getAgentInvocation(input.invocationId);
|
|
203
|
-
if (!invocation || input.kind === "result" && !isTerminalAgentInvocation(invocation) || invocation.parentConversationId !== message.conversationId) throw new Error(`Agent invocation ${input.kind} ${input.invocationId} does not belong to ${message.conversationId}`);
|
|
204
|
-
return invocation;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Give agent invocation results and messages that reach a child Conversation
|
|
208
|
-
* to that child. A child Conversation has no Location, so it cannot run an
|
|
209
|
-
* Event Turn. Each result or message starts a new agent invocation on the
|
|
210
|
-
* child instead, and that invocation reports to the child's parent. Returns
|
|
211
|
-
* undefined for work that is not a result or message for a child
|
|
212
|
-
* Conversation.
|
|
213
|
-
*/
|
|
214
|
-
async function startAgentInvocationsForChildResults(context, options) {
|
|
215
|
-
const messages = context.attempt.messages;
|
|
216
|
-
const inputs = messages.map(childAgentInput);
|
|
217
|
-
if (messages.length === 0 || inputs.some((input) => !input)) return;
|
|
218
|
-
const latest = await getLatestAgentInvocationForConversation(context.conversationId);
|
|
219
|
-
if (!latest) return;
|
|
220
|
-
if (latest.status === "stopped" || isTerminalAgentInvocation(latest) && latest.parentMailboxStatus === "skipped") {
|
|
221
|
-
await context.attempt.ack();
|
|
222
|
-
return { status: "completed" };
|
|
223
|
-
}
|
|
224
|
-
for (const [index, message] of messages.entries()) {
|
|
225
|
-
const input = inputs[index];
|
|
226
|
-
const source = await getChildAgentInputInvocation(message, input);
|
|
227
|
-
if (input.kind === "result" && isTerminalAgentInvocation(source) && source.parentMailboxStatus === "skipped") continue;
|
|
228
|
-
const invocation = await createAgentInvocationFromLatest({
|
|
229
|
-
input: message.input.text.trim(),
|
|
230
|
-
invocationId: input.kind === "result" ? getAgentInvocationIdForResult(source.invocationId) : getAgentInvocationIdForMessage(message.inboundMessageId),
|
|
231
|
-
latest
|
|
232
|
-
});
|
|
233
|
-
await enqueueAgentInvocation(invocation, options);
|
|
234
|
-
}
|
|
235
|
-
await context.attempt.ack();
|
|
236
|
-
return { status: "completed" };
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Run each agent invocation result or message as the Actor that triggered the
|
|
240
|
-
* child, user or system. This is on purpose: the result continues that
|
|
241
|
-
* Actor's work. The Actor comes from SQL, not from mailbox metadata, so the
|
|
242
|
-
* parent Turn has the same authority it had at spawn time.
|
|
243
|
-
*
|
|
244
|
-
* TODO(dcramer): Pass the delegated credential subject of a system Actor, such
|
|
245
|
-
* as a timer watch Turn, when system Turns can spawn children that need it.
|
|
246
|
-
*/
|
|
247
|
-
async function withAgentInvocationResultActors(work) {
|
|
248
|
-
if (work.kind !== "mailbox") return work;
|
|
249
|
-
return {
|
|
250
|
-
kind: "mailbox",
|
|
251
|
-
batch: await Promise.all(work.batch.map(async (entry) => {
|
|
252
|
-
const input = childAgentInput(entry.message);
|
|
253
|
-
if (!input) return entry;
|
|
254
|
-
const invocation = await getChildAgentInputInvocation(entry.message, input);
|
|
255
|
-
return {
|
|
256
|
-
...entry,
|
|
257
|
-
actor: invocation.actor
|
|
258
|
-
};
|
|
259
|
-
}))
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/chat/agent-invocations/message.ts
|
|
264
|
-
var message_exports = /* @__PURE__ */ __exportAll({ bindMessageAgent: () => bindMessageAgent });
|
|
265
|
-
/**
|
|
266
|
-
* Bind a Run's Actor and credentials to messages for its parent and child
|
|
267
|
-
* agents. A message to a child continues that child. A message to the parent
|
|
268
|
-
* wakes the parent like a result.
|
|
269
|
-
*/
|
|
270
|
-
function bindMessageAgent(run, options) {
|
|
271
|
-
const actor = actorFromRun(run);
|
|
272
|
-
if (!actor) return;
|
|
273
|
-
return async (input, call) => {
|
|
274
|
-
call.signal?.throwIfAborted();
|
|
275
|
-
const queue = typeof options.queue === "function" ? options.queue() : options.queue;
|
|
276
|
-
if (input.to === "parent") {
|
|
277
|
-
const sender = await getActiveAgentInvocationForConversation(run.conversationId);
|
|
278
|
-
if (!sender) throw new AgentMessageTargetError("This conversation has no parent agent");
|
|
279
|
-
await enqueueAgentMessageToParent({
|
|
280
|
-
messageKey: `${run.turnId}:${call.toolCallId}`,
|
|
281
|
-
queue,
|
|
282
|
-
sender,
|
|
283
|
-
state: options.state,
|
|
284
|
-
text: input.text
|
|
285
|
-
});
|
|
286
|
-
return {
|
|
287
|
-
conversationId: sender.parentConversationId,
|
|
288
|
-
delivery: "queued"
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const childConversationId = await findChildAgentConversationId({
|
|
292
|
-
parentConversationId: run.conversationId,
|
|
293
|
-
target: input.to
|
|
294
|
-
});
|
|
295
|
-
if (!childConversationId) throw new AgentMessageTargetError(`"${input.to}" is not "${PARENT_AGENT_TARGET}" or a child agent of this conversation`);
|
|
296
|
-
const { invocation, queued } = await createAgentInvocationForMessage({
|
|
297
|
-
actor,
|
|
298
|
-
childConversationId,
|
|
299
|
-
...run.credentialContext ? { credentialContext: run.credentialContext } : void 0,
|
|
300
|
-
destination: toolInvocationDestination(run),
|
|
301
|
-
idempotencyKey: `${run.turnId}:${call.toolCallId}`,
|
|
302
|
-
input: input.text,
|
|
303
|
-
parentConversationId: run.conversationId,
|
|
304
|
-
parentToolCallId: call.toolCallId
|
|
305
|
-
});
|
|
306
|
-
await enqueueAgentInvocation(invocation, {
|
|
307
|
-
...options,
|
|
308
|
-
queue
|
|
309
|
-
});
|
|
310
|
-
return {
|
|
311
|
-
conversationId: childConversationId,
|
|
312
|
-
delivery: queued ? "queued" : "started"
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
//#endregion
|
|
317
|
-
export { withAgentInvocationResultActors as a, startAgentInvocationsForChildResults as i, message_exports as n, enqueueAgentInvocationResult as r, bindMessageAgent as t };
|