@sentry/junior 0.295.0 → 0.297.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-ifgjyfpF.js → admin-tmGIw4KS.js} +2 -2
- package/dist/{agent-runner-DjMTPWEO.js → agent-runner-CneTquAE.js} +468 -1947
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -7
- package/dist/api.d.ts +1 -1
- package/dist/api.js +306 -569
- package/dist/{app-uiTzRbvq.d.ts → app-BJojZ7HL.d.ts} +7 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +64 -44
- package/dist/attempt-selection-ClP3MMPr.js +61 -0
- package/dist/{automation-yJX3C7i3.js → automation-BrP6ImrC.js} +1 -1
- package/dist/{background-compaction-queue-DUkHZjmL.js → background-compaction-queue-CwfJy3Cd.js} +4 -88
- package/dist/{briefs-CbNYM-q2.js → briefs-uFTuhMqA.js} +3 -3
- package/dist/{catalog-runtime-DgouZKZm.js → catalog-runtime-0kuQqYL4.js} +1 -1
- package/dist/cli/chat.js +19 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-DvnTPCfp.js → config-Dj9M_nqB.js} +18 -2
- package/dist/{connections-CWaIVl_1.js → connections-B96JUM5o.js} +6 -6
- package/dist/{conversation-CMkSmi02.js → conversation-CvcBU1z2.js} +2 -16
- package/dist/{conversation-feed-BVAOga0H.js → conversation-feed-BSMlGZnS.js} +1 -1
- package/dist/{conversation-privacy-DPjv4SnA.js → conversation-privacy-DI29jbZV.js} +1 -1
- package/dist/conversation-turn-CZWBr091.js +805 -0
- package/dist/{credential-sync-BhbaZfmO.js → credential-sync-Blhx4_xf.js} +14 -13
- package/dist/{db-Dts2XvLu.js → db-Br0tfAo7.js} +54 -32
- package/dist/{db-CCUqQe0E.d.ts → db-CrtyFRz7.d.ts} +13 -1
- package/dist/{executor-Ck73J0wP.js → executor-BMPipFVA.js} +19 -5
- package/dist/instrumentation.js +19 -2
- package/dist/{logging-9OAq-fdg.js → logging-CQjlDQYX.js} +1 -1
- package/dist/{message-CtaPzC7m.js → message-BOZEIuxy.js} +15 -13
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +3 -2
- package/dist/{session-stop-DkxI5vc3.js → notification-gusCgdQ6.js} +14 -933
- package/dist/{oauth-callback-server-C_LXY1d4.js → oauth-callback-server-V_DuMuNX.js} +2 -2
- package/dist/{projection-BzJQncZV.js → projection-B08mfi0u.js} +479 -145
- package/dist/{prompt-Cbq5b4SO.js → prompt-BlutWLNt.js} +4 -4
- package/dist/prompt-input-Dxn8cDC0.js +1424 -0
- package/dist/{registry-cbpOxO4M.js → registry-BDWgCJDf.js} +1 -1
- package/dist/reporting-window-DopzcOHh.js +137 -0
- package/dist/{resolve-t-pmRdwS.js → resolve-2Z_o_SsI.js} +3 -3
- package/dist/result-CAujiaci.js +463 -0
- package/dist/{runner-CHv9X9TH.js → runner-D2Chc02N.js} +9 -8
- package/dist/{sandbox-egress-signals-Yy3fSCbg.js → sandbox-egress-signals-CFoJduFj.js} +1 -1
- package/dist/{schema-BhneuGYv.js → schema-Bqa5NbcP.js} +22 -48
- package/dist/{schema-TSEisVJR.d.ts → schema-Ce2XCS7O.d.ts} +24 -107
- package/dist/{service-account-DjPIwCMj.js → service-account-C9kRQEb_.js} +3 -3
- package/dist/{service-account-C4rBP8ne.js → service-account-CERfXEVU.js} +3 -3
- package/dist/session-stop-B-I1rAS1.js +181 -0
- package/dist/{skills-BZE2DP8I.js → skills-B0m1nZ_j.js} +3 -3
- package/dist/{spawn-BvULxIiu.js → spawn-CwMjRRtn.js} +6 -5
- package/dist/{state-CO9ETDzk.js → state-DFnmLmfn.js} +2 -2
- package/dist/{stop-CL-rdtQb.js → stop-BCH9VNGf.js} +329 -382
- package/dist/{store-DgD78_NK.js → store-B59rOYbS.js} +11 -4
- package/dist/{task-runner-CKOj6xla.js → store-m5bmdmsP.js} +929 -1559
- package/dist/task-queue-N0kuCknH.js +89 -0
- package/dist/task-runner-COOwR8qm.js +291 -0
- package/dist/thread-context-Cd44z_W5.js +248 -0
- package/dist/turn-cancel-DDu8TOwt.js +201 -0
- package/dist/turn-session-routing-BlCtVFRN.js +380 -0
- package/dist/{turn-failure-response-BTSo6SMJ.js → turn-user-message-ygLG3ylQ.js} +183 -358
- package/dist/turn-wake-DmQec4AG.js +161 -0
- package/dist/{reporting-window-B3Ze-Qnt.js → user-input-request-CXNIov9n.js} +24 -143
- package/dist/{validation-CXeYgBzq.js → validation-Ba2OcUse.js} +1 -1
- package/dist/{version-AQa7Fr2H.js → version-KNDzIAh6.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-Bqkb678l.js → viewer-BPpuN2f9.js} +3 -3
- package/dist/warmup-Bskrwmk1.js +2697 -0
- package/dist/{worker-Hl7N292I.js → worker-B1skZlit.js} +20 -8
- package/migrations/0101_drop_legacy_columns.sql +12 -0
- package/migrations/0102_code_change_last_activity.sql +1 -0
- package/migrations/0103_agent_invocation_fork.sql +8 -0
- package/migrations/meta/0101_snapshot.json +4496 -0
- package/migrations/meta/0102_snapshot.json +4502 -0
- package/migrations/meta/0103_snapshot.json +4509 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +5 -4
- package/dist/result-DhgjR3nQ.js +0 -305
- package/dist/result-event-type-DD6BAgT7.js +0 -11
- package/dist/warmup-h6u1e9n0.js +0 -1869
- package/dist/work-yN_GAuXY.js +0 -768
|
@@ -708,6 +708,27 @@
|
|
|
708
708
|
"when": 1794360831303,
|
|
709
709
|
"tag": "0100_automation_task_kind_repair",
|
|
710
710
|
"breakpoints": true
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
"idx": 101,
|
|
714
|
+
"version": "7",
|
|
715
|
+
"when": 1794414686731,
|
|
716
|
+
"tag": "0101_drop_legacy_columns",
|
|
717
|
+
"breakpoints": true
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
"idx": 102,
|
|
721
|
+
"version": "7",
|
|
722
|
+
"when": 1794416510222,
|
|
723
|
+
"tag": "0102_code_change_last_activity",
|
|
724
|
+
"breakpoints": true
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
"idx": 103,
|
|
728
|
+
"version": "7",
|
|
729
|
+
"when": 1794424481991,
|
|
730
|
+
"tag": "0103_agent_invocation_fork",
|
|
731
|
+
"breakpoints": true
|
|
711
732
|
}
|
|
712
733
|
]
|
|
713
734
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.297.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"commander": "^14.0.3",
|
|
83
83
|
"diff": "^8.0.4",
|
|
84
84
|
"drizzle-orm": "^0.45.2",
|
|
85
|
+
"graphql": "^16.14.0",
|
|
85
86
|
"hono": "^4.13.11",
|
|
86
87
|
"jiti": "^2.7.0",
|
|
87
88
|
"jose": "^6.2.3",
|
|
@@ -94,7 +95,7 @@
|
|
|
94
95
|
"web-push": "^3.6.7",
|
|
95
96
|
"yaml": "^2.9.0",
|
|
96
97
|
"zod": "^4.5.4",
|
|
97
|
-
"@sentry/junior-plugin-api": "0.
|
|
98
|
+
"@sentry/junior-plugin-api": "0.297.0"
|
|
98
99
|
},
|
|
99
100
|
"peerDependencies": {
|
|
100
101
|
"bullmq": "^6.5.0",
|
|
@@ -130,8 +131,8 @@
|
|
|
130
131
|
"typescript": "^7.0.2",
|
|
131
132
|
"vercel": "^54.4.0",
|
|
132
133
|
"vitest": "^4.1.12",
|
|
133
|
-
"@sentry/junior-github": "0.
|
|
134
|
-
"@sentry/junior-memory": "0.
|
|
134
|
+
"@sentry/junior-github": "0.297.0",
|
|
135
|
+
"@sentry/junior-memory": "0.297.0",
|
|
135
136
|
"@sentry/junior-testing": "0.0.0"
|
|
136
137
|
},
|
|
137
138
|
"scripts": {
|
package/dist/result-DhgjR3nQ.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { Cn as renderUntrustedTag } from "./projection-BzJQncZV.js";
|
|
3
|
-
import { M as SYSTEM_IDENTITY_ID } from "./db-Dts2XvLu.js";
|
|
4
|
-
import { f as credentialContextForActor } from "./registry-cbpOxO4M.js";
|
|
5
|
-
import { cn as listUnreportedSiblingAgents } from "./agent-runner-DjMTPWEO.js";
|
|
6
|
-
import { C as isTerminalAgentInvocation, G as getAgentInvocationIdForEvents, K as getAgentInvocationIdForMessage, Y as getAgentInvocationResultMessageId, k as markAgentInvocationParentMailboxAppended, q as getAgentInvocationIdForResult, x as getLatestAgentInvocationForConversation, y as getAgentInvocation } from "./turn-failure-response-BTSo6SMJ.js";
|
|
7
|
-
import { D as timerWatchCredentialSubject, E as renderEventBatchInputs, S as EVENT_WAIT_MS, T as isEventMailboxMetadata, f as getEventBatchDelayMs, m as parseEventMessages, n as isWatchEvent, s as eventReviewItemInputs, w as eventBatchMessageMeta } from "./session-stop-DkxI5vc3.js";
|
|
8
|
-
import { r as appendAndEnqueueInboundMessage } from "./store-DgD78_NK.js";
|
|
9
|
-
import { a as enqueueAgentInvocation, l as createAgentInvocationFromLatest, o as resolveAgentInvocationId, t as createAgentInvocationWorker } from "./work-yN_GAuXY.js";
|
|
10
|
-
import { n as isAgentInvocationResultEventType, t as agentInvocationResultEventType } from "./result-event-type-DD6BAgT7.js";
|
|
11
|
-
// src/chat/agent-invocations/result.ts
|
|
12
|
-
var result_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
-
createChildConversationWorker: () => createChildConversationWorker,
|
|
14
|
-
enqueueAgentInvocationResult: () => enqueueAgentInvocationResult,
|
|
15
|
-
enqueueAgentMessageToParent: () => enqueueAgentMessageToParent,
|
|
16
|
-
withAgentInvocationResultActors: () => withAgentInvocationResultActors
|
|
17
|
-
});
|
|
18
|
-
const AGENT_INVOCATION_EVENT_NAMESPACE = "junior";
|
|
19
|
-
const AGENT_INVOCATION_RESULT_MAX_LENGTH = 12e3;
|
|
20
|
-
/** Event type of a message that a child agent sends to its parent. */
|
|
21
|
-
const AGENT_MESSAGE_EVENT_TYPE = "agent.message";
|
|
22
|
-
/**
|
|
23
|
-
* Return the Inbound message author id for results sent by one Actor.
|
|
24
|
-
* `selectContiguousTurnBatch` in `task-execution/worker.ts` puts messages in
|
|
25
|
-
* one attempt only when their author ids and sources match. Mid-Turn drains
|
|
26
|
-
* take only `interrupt` messages, and results are `defer`. So results never
|
|
27
|
-
* share a Turn and its credentials with another Actor or with watch Events.
|
|
28
|
-
* Keep this id unique per Actor if either rule changes.
|
|
29
|
-
*/
|
|
30
|
-
function resultAuthorId(actor) {
|
|
31
|
-
switch (actor.platform) {
|
|
32
|
-
case "system": return `agent-invocation:system:${actor.name}`;
|
|
33
|
-
case "slack": return `agent-invocation:slack:${actor.teamId}:${actor.userId}`;
|
|
34
|
-
default: return `agent-invocation:${actor.platform}:${actor.userId}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Error messages can contain text from tools or providers, so the trusted
|
|
39
|
-
* summary in the mailbox metadata has only the status.
|
|
40
|
-
*/
|
|
41
|
-
function trustedSummary(invocation, agent) {
|
|
42
|
-
switch (invocation.status) {
|
|
43
|
-
case "completed": return `${agent} finished its task.`;
|
|
44
|
-
case "blocked": return `${agent} is blocked.`;
|
|
45
|
-
case "failed": return `${agent} failed.`;
|
|
46
|
-
case "stopped": return `${agent} was stopped.`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Render the parent agent input for one terminal agent invocation as one
|
|
51
|
-
* `<agent-result>`. A child agent wrote the output, so it is escaped data.
|
|
52
|
-
* `status` and `waiting_on` are runtime facts. The system prompt says what to
|
|
53
|
-
* do for each status, so the input repeats no guidance.
|
|
54
|
-
*/
|
|
55
|
-
function renderResultInput(invocation, openSiblings) {
|
|
56
|
-
const output = (invocation.status === "completed" ? invocation.result : invocation.errorMessage).trim().slice(0, AGENT_INVOCATION_RESULT_MAX_LENGTH);
|
|
57
|
-
return renderUntrustedTag("agent-result", {
|
|
58
|
-
conversation_id: invocation.childConversationId,
|
|
59
|
-
name: invocation.agentName,
|
|
60
|
-
source: "child_agent",
|
|
61
|
-
status: invocation.status,
|
|
62
|
-
title: invocation.title,
|
|
63
|
-
waiting_on: openSiblings.length ? openSiblings.map(siblingLabel).join(", ") : void 0
|
|
64
|
-
}, "A child agent that you started", output || "(empty)");
|
|
65
|
-
}
|
|
66
|
-
function siblingLabel(sibling) {
|
|
67
|
-
return sibling.agentName ?? sibling.title ?? sibling.childConversationId;
|
|
68
|
-
}
|
|
69
|
-
/** Build the parent Inbound message for one terminal agent invocation. */
|
|
70
|
-
function buildResultInboundMessage(invocation, nowMs, openSiblings) {
|
|
71
|
-
const summary = trustedSummary(invocation, childAgentLabel(invocation));
|
|
72
|
-
const metadata = {
|
|
73
|
-
kind: "event",
|
|
74
|
-
event: {
|
|
75
|
-
eventKey: invocation.invocationId,
|
|
76
|
-
eventType: agentInvocationResultEventType(invocation.status),
|
|
77
|
-
identifier: invocation.invocationId,
|
|
78
|
-
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
79
|
-
trustedSummary: summary
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return {
|
|
83
|
-
conversationId: invocation.parentConversationId,
|
|
84
|
-
createdAtMs: invocation.terminalAtMs,
|
|
85
|
-
delivery: "defer",
|
|
86
|
-
inboundMessageId: getAgentInvocationResultMessageId(invocation.invocationId),
|
|
87
|
-
input: {
|
|
88
|
-
authorId: resultAuthorId(invocation.actor),
|
|
89
|
-
authorIdentityId: SYSTEM_IDENTITY_ID,
|
|
90
|
-
metadata,
|
|
91
|
-
text: renderResultInput(invocation, openSiblings)
|
|
92
|
-
},
|
|
93
|
-
receivedAtMs: nowMs,
|
|
94
|
-
source: "event"
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Append one terminal agent invocation result to the parent mailbox and wake
|
|
99
|
-
* the parent. Repeat calls are safe.
|
|
100
|
-
*
|
|
101
|
-
* Results do not go through `admitAutomatedTurn`, so the automated-turn limit
|
|
102
|
-
* never drops them. Result Turns still count toward that limit.
|
|
103
|
-
* TODO(dcramer): Add a per-parent total invocation limit as the loop guard
|
|
104
|
-
* for spawn -> result -> spawn chains (#881).
|
|
105
|
-
*/
|
|
106
|
-
async function enqueueAgentInvocationResult(invocation, options) {
|
|
107
|
-
if (invocation.parentMailboxStatus !== "pending") return;
|
|
108
|
-
const nowMs = options.nowMs ?? Date.now();
|
|
109
|
-
const openSiblings = await listUnreportedSiblingAgents(invocation.parentConversationId, invocation.childConversationId);
|
|
110
|
-
await appendAndEnqueueInboundMessage({
|
|
111
|
-
message: buildResultInboundMessage(invocation, nowMs, openSiblings),
|
|
112
|
-
queue: options.queue,
|
|
113
|
-
queueDelayMs: EVENT_WAIT_MS,
|
|
114
|
-
state: options.state
|
|
115
|
-
});
|
|
116
|
-
await markAgentInvocationParentMailboxAppended(invocation.invocationId, nowMs);
|
|
117
|
-
}
|
|
118
|
-
function childAgentLabel(invocation) {
|
|
119
|
-
return invocation.agentName ? `Child agent "${invocation.agentName}"` : "Child agent";
|
|
120
|
-
}
|
|
121
|
-
function renderMessageInput(sender, text) {
|
|
122
|
-
return renderUntrustedTag("agent-message", {
|
|
123
|
-
conversation_id: sender.childConversationId,
|
|
124
|
-
name: sender.agentName,
|
|
125
|
-
source: "child_agent",
|
|
126
|
-
title: sender.title
|
|
127
|
-
}, "A child agent that you started", text.trim());
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Append one message from a child agent to its parent mailbox and wake the
|
|
131
|
-
* parent. `sender` is the open agent invocation of the child. The parent
|
|
132
|
-
* handles the message like a result: a root parent runs an Event Turn, and a
|
|
133
|
-
* child parent starts a new agent invocation. Repeat calls with the same
|
|
134
|
-
* `messageKey` are safe.
|
|
135
|
-
*/
|
|
136
|
-
async function enqueueAgentMessageToParent(args) {
|
|
137
|
-
const nowMs = args.nowMs ?? Date.now();
|
|
138
|
-
const inboundMessageId = `agent-invocation:${args.sender.invocationId}:message:${args.messageKey}`;
|
|
139
|
-
const summary = `${childAgentLabel(args.sender)} sent a message.`;
|
|
140
|
-
const metadata = {
|
|
141
|
-
kind: "event",
|
|
142
|
-
event: {
|
|
143
|
-
eventKey: inboundMessageId,
|
|
144
|
-
eventType: AGENT_MESSAGE_EVENT_TYPE,
|
|
145
|
-
identifier: args.sender.invocationId,
|
|
146
|
-
namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
|
|
147
|
-
trustedSummary: summary
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
await appendAndEnqueueInboundMessage({
|
|
151
|
-
message: {
|
|
152
|
-
conversationId: args.sender.parentConversationId,
|
|
153
|
-
createdAtMs: nowMs,
|
|
154
|
-
delivery: "defer",
|
|
155
|
-
inboundMessageId,
|
|
156
|
-
input: {
|
|
157
|
-
authorId: resultAuthorId(args.sender.actor),
|
|
158
|
-
authorIdentityId: SYSTEM_IDENTITY_ID,
|
|
159
|
-
metadata,
|
|
160
|
-
text: renderMessageInput(args.sender, args.text)
|
|
161
|
-
},
|
|
162
|
-
receivedAtMs: nowMs,
|
|
163
|
-
source: "event"
|
|
164
|
-
},
|
|
165
|
-
queue: args.queue,
|
|
166
|
-
queueDelayMs: EVENT_WAIT_MS,
|
|
167
|
-
state: args.state
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Read the agent invocation that one result or message Event refers to: the
|
|
172
|
-
* finished child work for a result, or the open sender work for a message.
|
|
173
|
-
*/
|
|
174
|
-
function childAgentInput(message) {
|
|
175
|
-
const metadata = message.input.metadata;
|
|
176
|
-
if (!isEventMailboxMetadata(metadata) || metadata.event.namespace !== AGENT_INVOCATION_EVENT_NAMESPACE) return;
|
|
177
|
-
if (metadata.event.eventType === AGENT_MESSAGE_EVENT_TYPE) return {
|
|
178
|
-
invocationId: metadata.event.identifier,
|
|
179
|
-
kind: "message"
|
|
180
|
-
};
|
|
181
|
-
return isAgentInvocationResultEventType(metadata.event.eventType) ? {
|
|
182
|
-
invocationId: metadata.event.identifier,
|
|
183
|
-
kind: "result"
|
|
184
|
-
} : void 0;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Return whether a stop after this result was sent skipped it, so it starts no
|
|
188
|
-
* work. A message that a child sent before its stop is still delivered.
|
|
189
|
-
*/
|
|
190
|
-
function isSkippedAgentResult(input, invocation) {
|
|
191
|
-
return input.kind === "result" && isTerminalAgentInvocation(invocation) && invocation.parentMailboxStatus === "skipped";
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Read the agent invocation of one result or message and check that it
|
|
195
|
-
* belongs to a child of the Conversation that received it.
|
|
196
|
-
*/
|
|
197
|
-
async function getChildAgentInputInvocation(message, input) {
|
|
198
|
-
const invocation = await getAgentInvocation(input.invocationId);
|
|
199
|
-
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}`);
|
|
200
|
-
return invocation;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Give mailbox input that reaches a child Conversation to that child: results
|
|
204
|
-
* and messages from its own child agents, and its own watch events. A child
|
|
205
|
-
* Conversation has no Location, so it cannot run an Event Turn. Each input
|
|
206
|
-
* starts a new agent invocation on the child instead, and that invocation
|
|
207
|
-
* reports to the child's parent. Returns undefined for work that is not
|
|
208
|
-
* mailbox input for a child Conversation.
|
|
209
|
-
*/
|
|
210
|
-
async function startAgentInvocationsForChildInput(context, options) {
|
|
211
|
-
const messages = context.attempt.messages;
|
|
212
|
-
const inputs = messages.map(childAgentInput);
|
|
213
|
-
const isAgentInput = inputs.every((input) => input !== void 0);
|
|
214
|
-
const events = isAgentInput ? [] : parseEventMessages(messages);
|
|
215
|
-
if (messages.length === 0 || !isAgentInput && events.length === 0) return;
|
|
216
|
-
const latest = await getLatestAgentInvocationForConversation(context.conversationId);
|
|
217
|
-
if (!latest) return;
|
|
218
|
-
if ((latest.status === "stopped" || isTerminalAgentInvocation(latest) && latest.parentMailboxStatus === "skipped") && (isAgentInput || !messages.every(isWatchEvent))) {
|
|
219
|
-
await context.attempt.ack();
|
|
220
|
-
return { status: "completed" };
|
|
221
|
-
}
|
|
222
|
-
if (!isAgentInput) {
|
|
223
|
-
const delayMs = getEventBatchDelayMs(messages);
|
|
224
|
-
if (delayMs > 0) return {
|
|
225
|
-
status: "deferred",
|
|
226
|
-
delayMs
|
|
227
|
-
};
|
|
228
|
-
const { actor, source } = events[0];
|
|
229
|
-
const invocation = await createAgentInvocationFromLatest({
|
|
230
|
-
input: renderEventBatchInputs(messages, await eventReviewItemInputs(messages)).join("\n\n"),
|
|
231
|
-
invocationId: getAgentInvocationIdForEvents(messages[0].inboundMessageId),
|
|
232
|
-
latest,
|
|
233
|
-
runAs: {
|
|
234
|
-
actor,
|
|
235
|
-
credentialContext: credentialContextForActor(actor, timerWatchCredentialSubject(context.conversationId, messages)),
|
|
236
|
-
source
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
await enqueueAgentInvocation(invocation, {
|
|
240
|
-
...options,
|
|
241
|
-
eventMeta: eventBatchMessageMeta(messages)
|
|
242
|
-
});
|
|
243
|
-
await context.attempt.ack();
|
|
244
|
-
return { status: "completed" };
|
|
245
|
-
}
|
|
246
|
-
for (const [index, message] of messages.entries()) {
|
|
247
|
-
const input = inputs[index];
|
|
248
|
-
const source = await getChildAgentInputInvocation(message, input);
|
|
249
|
-
if (isSkippedAgentResult(input, source)) continue;
|
|
250
|
-
const invocation = await createAgentInvocationFromLatest({
|
|
251
|
-
input: message.input.text.trim(),
|
|
252
|
-
invocationId: input.kind === "result" ? getAgentInvocationIdForResult(source.invocationId) : getAgentInvocationIdForMessage(message.inboundMessageId),
|
|
253
|
-
latest
|
|
254
|
-
});
|
|
255
|
-
await enqueueAgentInvocation(invocation, {
|
|
256
|
-
...options,
|
|
257
|
-
eventMeta: eventBatchMessageMeta([message])
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
await context.attempt.ack();
|
|
261
|
-
return { status: "completed" };
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Build the worker for all work of a child Conversation. The caller selects
|
|
265
|
-
* it from the stored parent of the Conversation, never from a Turn Source. It
|
|
266
|
-
* starts agent invocations for child input, then runs the agent invocation
|
|
267
|
-
* that owns the work. Work that no agent invocation owns is an error.
|
|
268
|
-
*/
|
|
269
|
-
function createChildConversationWorker(agentRunner, options) {
|
|
270
|
-
const invocationWorker = createAgentInvocationWorker(agentRunner, options);
|
|
271
|
-
return async (context) => {
|
|
272
|
-
const started = await startAgentInvocationsForChildInput(context, options);
|
|
273
|
-
if (started) return started;
|
|
274
|
-
const invocationId = await resolveAgentInvocationId(context);
|
|
275
|
-
if (!invocationId) throw new Error(`Child conversation ${context.conversationId} has no agent invocation for this work`);
|
|
276
|
-
return await invocationWorker(context, invocationId);
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Run each agent invocation result or message as the Actor that triggered the
|
|
281
|
-
* child, user or system. This is on purpose: the result continues that
|
|
282
|
-
* Actor's work. The Actor comes from SQL, not from mailbox metadata, so the
|
|
283
|
-
* parent Turn has the same authority it had at spawn time. A result that a
|
|
284
|
-
* stop skipped is dropped. Returns undefined when no input is left.
|
|
285
|
-
*
|
|
286
|
-
* TODO(dcramer): Pass the delegated credential subject of a system Actor, such
|
|
287
|
-
* as a timer watch Turn, when system Turns can spawn children that need it.
|
|
288
|
-
*/
|
|
289
|
-
async function withAgentInvocationResultActors(work) {
|
|
290
|
-
if (work.kind !== "mailbox") return work;
|
|
291
|
-
const kept = (await Promise.all(work.batch.map(async (entry) => {
|
|
292
|
-
const input = childAgentInput(entry.message);
|
|
293
|
-
if (!input) return entry;
|
|
294
|
-
const invocation = await getChildAgentInputInvocation(entry.message, input);
|
|
295
|
-
return isSkippedAgentResult(input, invocation) ? void 0 : {
|
|
296
|
-
...entry,
|
|
297
|
-
actor: invocation.actor
|
|
298
|
-
};
|
|
299
|
-
}))).filter((entry) => entry !== void 0);
|
|
300
|
-
return kept.length > 0 ? {
|
|
301
|
-
kind: "mailbox",
|
|
302
|
-
batch: kept
|
|
303
|
-
} : void 0;
|
|
304
|
-
}
|
|
305
|
-
export { withAgentInvocationResultActors as a, result_exports as i, enqueueAgentInvocationResult as n, enqueueAgentMessageToParent as r, createChildConversationWorker as t };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/chat/agent-invocations/result-event-type.ts
|
|
2
|
-
const AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX = "agent_invocation.";
|
|
3
|
-
/** Build the Event type of the parent message for one agent invocation result. */
|
|
4
|
-
function agentInvocationResultEventType(status) {
|
|
5
|
-
return `${AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX}${status}`;
|
|
6
|
-
}
|
|
7
|
-
/** True when an Event type names an agent invocation result. */
|
|
8
|
-
function isAgentInvocationResultEventType(eventType) {
|
|
9
|
-
return eventType.startsWith(AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX);
|
|
10
|
-
}
|
|
11
|
-
export { isAgentInvocationResultEventType as n, agentInvocationResultEventType as t };
|