@sentry/junior 0.284.0 → 0.285.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-CW5UW7vL.js → adapter-DN5AB4VU.js} +37 -3
- package/dist/{admin-DUWN8zZX.js → admin-DOITMKnn.js} +1 -1
- package/dist/{agent-runner-Cqr21pOU.js → agent-runner-BsWhHe4N.js} +579 -1653
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -6
- package/dist/api.d.ts +1 -1
- package/dist/api.js +141 -43
- package/dist/{app-CvGalMxi.d.ts → app-DyMs9330.d.ts} +2 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +226 -186
- package/dist/{assistant-reply-CFE-OZMS.js → assistant-reply-9Jip5bsr.js} +1 -1
- package/dist/{automation-Zvx_I9Z5.js → automation-Mk8aaHzy.js} +1 -1
- package/dist/{background-compaction-queue-CHFzrQbS.js → background-compaction-queue-DXkLsWoH.js} +2 -2
- package/dist/{briefs-Cx7mkfSk.js → briefs-Cl8-nK9B.js} +5 -5
- package/dist/{catalog-runtime-dKOVbR7l.js → catalog-runtime-Bte6jRB2.js} +1 -1
- package/dist/cli/chat.js +19 -16
- package/dist/cli/check.js +3 -3
- package/dist/cli/init.js +3 -0
- 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 +12 -17
- package/dist/{client-CMyH5rDz.js → client-DDbBucBw.js} +2 -2
- package/dist/{config-Dt3CpG17.js → config-DqFnykQT.js} +1 -1
- package/dist/{connections-CCHPybZP.js → connections-DA4LT9LL.js} +10 -10
- package/dist/{conversation-DdT7SNar.js → conversation-D8kVoCrP.js} +58 -6
- package/dist/{conversation-pending-messages-Dct5pheX.js → conversation-pending-messages-BvROq1bq.js} +1 -1
- package/dist/{conversation-privacy-BpHHhEVp.js → conversation-privacy-D0j_h70R.js} +1 -1
- package/dist/{credential-sync-BBPw8dam.js → credential-sync-hcsYatw-.js} +13 -13
- package/dist/{db-D7CCwAo8.d.ts → db-BhHZSuFw.d.ts} +18 -2
- package/dist/{executor-CyIwHz9r.js → executor-BLEMIgIZ.js} +11 -3
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-Qo-7xGp1.js → logging-BfORLKoq.js} +1 -1
- package/dist/{message-DFbtOWqv.js → message-DqjuKzUx.js} +13 -23
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +3 -3
- package/dist/{oauth-callback-server-BB1gixWo.js → oauth-callback-server-CFSRzu1n.js} +2 -2
- package/dist/{projection-0UcUeuzn.js → projection-DliWYrnT.js} +280 -71
- package/dist/{prompt-CCtaGgbI.js → prompt-BvIUzY4y.js} +8 -6
- package/dist/{registry-DOnPkI8g.js → registry-rC7MCxu8.js} +1 -1
- package/dist/{reporting-window-B-QP9zX1.js → reporting-window-B4TwyuJo.js} +14 -14
- package/dist/{resolve-Di3omymY.js → resolve-Biu8Qw3u.js} +3 -3
- package/dist/result-DxJMCX47.js +299 -0
- package/dist/result-event-type-DD6BAgT7.js +11 -0
- package/dist/{runner-CnX_dTKw.js → runner-BQJSFLKg.js} +11 -11
- package/dist/{sandbox-egress-signals-CtxLJmmg.js → sandbox-egress-signals-6aMxJSDn.js} +1 -1
- package/dist/{schema-B017enNE.d.ts → schema-BUviRAs8.d.ts} +157 -220
- package/dist/{schema-Bn3miEd_.js → schema-BasXTvi2.js} +63 -5
- package/dist/{service-account-KhZIqXRi.js → service-account-BI5Wgx22.js} +3 -3
- package/dist/{service-account-ewDAx4Mx.js → service-account-CAE-_1dR.js} +3 -3
- package/dist/session-stop-CA-jOJ84.js +2924 -0
- package/dist/{skills-CKyotM4g.js → skills-B22duVJU.js} +2 -2
- package/dist/{spawn-D5D2MQdz.js → spawn-BB2_4VYn.js} +2 -2
- package/dist/{stop-BSKRTaRS.js → stop-DioIcEAu.js} +4821 -4199
- package/dist/{store-G3S0kWSD.js → store-B26LV6UP.js} +78 -311
- package/dist/{store-ymkEUWe4.js → store-Dn4W7qgH.js} +30 -5
- package/dist/{task-queue-BcOHzXxe.js → task-queue-Bt0IoR2i.js} +3 -3
- package/dist/{task-runner-B65cDumh.js → task-runner-D8lddjzp.js} +7 -7
- package/dist/{thread-state-D6rNGQu9.js → thread-state-CrFk3K_7.js} +4 -4
- package/dist/{turn-failure-response-BlO4nuDJ.js → turn-failure-response-DaJ04qVj.js} +7 -7
- package/dist/{turn-lifecycle-BQ8ETk63.js → turn-lifecycle-C2mXS7AZ.js} +1 -1
- package/dist/{turn-session-routing-D_GXfcAG.js → turn-session-routing-CGMKrYOj.js} +10 -10
- package/dist/{validation-DJG_wrg2.js → validation-TzhfQABF.js} +1 -1
- package/dist/{version-i1An1eTS.js → version-DSk8CFvA.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-BlpnzZZa.js → viewer-1Ea81s0b.js} +190 -53
- package/dist/{work-BgCW3FDC.js → work-ybG4_q5C.js} +238 -32
- package/dist/{worker-BJz1mwYt.js → worker-ccSyZRNz.js} +6 -6
- package/migrations/0083_conversation_kind.sql +11 -0
- package/migrations/0084_read_position_backfill.sql +25 -0
- package/migrations/0085_child_archived_at.sql +1 -0
- package/migrations/meta/0083_snapshot.json +4388 -0
- package/migrations/meta/0084_snapshot.json +4388 -0
- package/migrations/meta/0085_snapshot.json +4394 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +4 -4
- package/dist/result-NvndYzCb.js +0 -483
- package/dist/session-stop-D_1SysjC.js +0 -1438
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { g as TURN_REASONING_LEVELS } from "./config-
|
|
2
|
-
import { C as getSqlExecutor
|
|
3
|
-
import { g as juniorAgentInvocations
|
|
4
|
-
import { p as credentialContextSchema } from "./registry-
|
|
5
|
-
import { S as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, x as AGENT_INVOCATION_MAILBOX_STATUSES } from "./reporting-window-
|
|
1
|
+
import { g as TURN_REASONING_LEVELS } from "./config-DqFnykQT.js";
|
|
2
|
+
import { C as getSqlExecutor } from "./viewer-1Ea81s0b.js";
|
|
3
|
+
import { g as juniorAgentInvocations } from "./executor-BLEMIgIZ.js";
|
|
4
|
+
import { p as credentialContextSchema } from "./registry-rC7MCxu8.js";
|
|
5
|
+
import { S as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, x as AGENT_INVOCATION_MAILBOX_STATUSES } from "./reporting-window-B4TwyuJo.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import * as z from "zod";
|
|
8
|
-
import { and, asc,
|
|
8
|
+
import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
|
|
9
9
|
import { actorSchema, destinationSchema, sourceSchema } from "@sentry/junior-plugin-api";
|
|
10
10
|
// src/chat/runtime/turn.ts
|
|
11
11
|
/** Classified Slack turn failure carrying the owning Sentry capture outward. */
|
|
@@ -98,6 +98,71 @@ function markTurnFailed(args) {
|
|
|
98
98
|
skippedReason: "reply failed"
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
// src/chat/agent-invocations/ids.ts
|
|
102
|
+
const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
|
|
103
|
+
/**
|
|
104
|
+
* Return the SQL lock that one parent Conversation takes to start, message,
|
|
105
|
+
* or stop its child agents.
|
|
106
|
+
*/
|
|
107
|
+
function getChildAgentLockName(parentConversationId) {
|
|
108
|
+
return `${CREATE_LOCK_PREFIX}:${parentConversationId}`;
|
|
109
|
+
}
|
|
110
|
+
function stableId(prefix, ...parts) {
|
|
111
|
+
return `${prefix}:${createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 32)}`;
|
|
112
|
+
}
|
|
113
|
+
/** Return the stable identity for one retry-safe delegated task. */
|
|
114
|
+
function getAgentInvocationId(parentConversationId, idempotencyKey) {
|
|
115
|
+
return stableId("agent-invocation", parentConversationId, idempotencyKey);
|
|
116
|
+
}
|
|
117
|
+
/** Return the stable child identity for one invocation without a named binding. */
|
|
118
|
+
function getUnnamedAgentConversationId(invocationId) {
|
|
119
|
+
return stableId("agent", invocationId);
|
|
120
|
+
}
|
|
121
|
+
/** Return the stable child identity for one named binding. */
|
|
122
|
+
function getNamedAgentConversationId(parentConversationId, name) {
|
|
123
|
+
return stableId("agent", parentConversationId, name);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Return the stable identity of the agent invocation that gives one child
|
|
127
|
+
* agent result to the child Conversation that started that child agent.
|
|
128
|
+
*/
|
|
129
|
+
function getAgentInvocationIdForResult(resultInvocationId) {
|
|
130
|
+
return stableId("agent-invocation", "result", resultInvocationId);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Return the stable identity of the agent invocation that gives one message
|
|
134
|
+
* from a child agent to the child Conversation that started that child agent.
|
|
135
|
+
*/
|
|
136
|
+
function getAgentInvocationIdForMessage(messageId) {
|
|
137
|
+
return stableId("agent-invocation", "message", messageId);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Return the stable identity of the agent invocation that gives one batch of
|
|
141
|
+
* watch events to a child Conversation. The first message of the batch names
|
|
142
|
+
* it.
|
|
143
|
+
*/
|
|
144
|
+
function getAgentInvocationIdForEvents(messageId) {
|
|
145
|
+
return stableId("agent-invocation", "events", messageId);
|
|
146
|
+
}
|
|
147
|
+
/** Return the stable turn identity advanced by one agent invocation. */
|
|
148
|
+
function getAgentInvocationTurnId(invocationId) {
|
|
149
|
+
return `agent-invocation:${invocationId}`;
|
|
150
|
+
}
|
|
151
|
+
/** Return the stable mailbox identity for one agent invocation. */
|
|
152
|
+
function getAgentInvocationMessageId(invocationId) {
|
|
153
|
+
return `agent-invocation:${invocationId}:input`;
|
|
154
|
+
}
|
|
155
|
+
const RESULT_MESSAGE_PREFIX = "agent-invocation:";
|
|
156
|
+
const RESULT_MESSAGE_SUFFIX = ":result";
|
|
157
|
+
/** Return the stable parent mailbox identity for one terminal result. */
|
|
158
|
+
function getAgentInvocationResultMessageId(invocationId) {
|
|
159
|
+
return `${RESULT_MESSAGE_PREFIX}${invocationId}${RESULT_MESSAGE_SUFFIX}`;
|
|
160
|
+
}
|
|
161
|
+
/** Read the invocation identity from one parent result mailbox identity. */
|
|
162
|
+
function parseAgentInvocationResultMessageId(messageId) {
|
|
163
|
+
if (!messageId.startsWith(RESULT_MESSAGE_PREFIX) || !messageId.endsWith(RESULT_MESSAGE_SUFFIX)) return;
|
|
164
|
+
return messageId.slice(17, -7) || void 0;
|
|
165
|
+
}
|
|
101
166
|
// src/chat/agent-invocations/agent-types.ts
|
|
102
167
|
/**
|
|
103
168
|
* Child agent types. A type is plain data: when to pick it, whether the child
|
|
@@ -225,76 +290,7 @@ const CHILD_AGENT_RESULTS = [
|
|
|
225
290
|
"blocked",
|
|
226
291
|
"failed"
|
|
227
292
|
];
|
|
228
|
-
// src/chat/agent-invocations/bindings.ts
|
|
229
|
-
function bindingFromRow(row) {
|
|
230
|
-
return agentBindingSchema.parse({
|
|
231
|
-
childConversationId: row.childConversationId,
|
|
232
|
-
name: row.name,
|
|
233
|
-
parentConversationId: row.parentConversationId
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
/** Read one named child binding in its parent-agent scope. */
|
|
237
|
-
async function getAgentBinding(args) {
|
|
238
|
-
const rows = await getSqlExecutor().db().select().from(juniorAgentBindings).where(and(eq(juniorAgentBindings.parentConversationId, args.parentConversationId), eq(juniorAgentBindings.name, args.name)));
|
|
239
|
-
return rows[0] ? bindingFromRow(rows[0]) : void 0;
|
|
240
|
-
}
|
|
241
|
-
/** Find a direct child agent of one parent by name or child Conversation id. */
|
|
242
|
-
async function findChildAgentConversationId(args) {
|
|
243
|
-
const binding = await getAgentBinding({
|
|
244
|
-
name: args.target,
|
|
245
|
-
parentConversationId: args.parentConversationId
|
|
246
|
-
});
|
|
247
|
-
if (binding) return binding.childConversationId;
|
|
248
|
-
return (await getSqlExecutor().db().select({ childConversationId: juniorAgentInvocations.childConversationId }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.parentConversationId, args.parentConversationId), eq(juniorAgentInvocations.childConversationId, args.target))).limit(1))[0]?.childConversationId;
|
|
249
|
-
}
|
|
250
|
-
// src/chat/agent-invocations/errors.ts
|
|
251
|
-
/** A child agent already uses this name in the parent Conversation. */
|
|
252
|
-
var AgentNameInUseError = class extends Error {
|
|
253
|
-
constructor(name) {
|
|
254
|
-
super(`A child agent named "${name}" already exists`);
|
|
255
|
-
this.name = "AgentNameInUseError";
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
/** Parent already has the maximum number of non-terminal child invocations. */
|
|
259
|
-
var AgentInvocationLimitError = class extends Error {
|
|
260
|
-
constructor(limit) {
|
|
261
|
-
super(`Parent already has ${limit} active child agent invocations (limit ${limit})`);
|
|
262
|
-
this.name = "AgentInvocationLimitError";
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
/** A child agent already has the maximum number of open tasks. */
|
|
266
|
-
var AgentMessageQueueFullError = class extends Error {
|
|
267
|
-
constructor(limit) {
|
|
268
|
-
super(`The child agent already has ${limit} open tasks`);
|
|
269
|
-
this.name = "AgentMessageQueueFullError";
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* A messageAgent target is not the parent, a child, or a top-level agent that
|
|
274
|
-
* the sender can message.
|
|
275
|
-
*/
|
|
276
|
-
var AgentMessageTargetError = class extends Error {
|
|
277
|
-
constructor(message) {
|
|
278
|
-
super(message);
|
|
279
|
-
this.name = "AgentMessageTargetError";
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
/** A top-level agent paused automated Turns, so it takes no agent message. */
|
|
283
|
-
var AgentMessagePausedError = class extends Error {
|
|
284
|
-
constructor(conversationId) {
|
|
285
|
-
super(`${conversationId} paused automated work until a person replies there`);
|
|
286
|
-
this.name = "AgentMessagePausedError";
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
293
|
// src/chat/agent-invocations/store.ts
|
|
290
|
-
const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
|
|
291
|
-
/**
|
|
292
|
-
* Return the SQL lock that one parent Conversation takes to start, message,
|
|
293
|
-
* or stop its child agents.
|
|
294
|
-
*/
|
|
295
|
-
function getChildAgentLockName(parentConversationId) {
|
|
296
|
-
return `${CREATE_LOCK_PREFIX}:${parentConversationId}`;
|
|
297
|
-
}
|
|
298
294
|
const TERMINAL_AGENT_INVOCATION_STATUSES = [
|
|
299
295
|
"blocked",
|
|
300
296
|
"completed",
|
|
@@ -309,62 +305,6 @@ const NON_TERMINAL_AGENT_INVOCATION_STATUSES = [
|
|
|
309
305
|
"running",
|
|
310
306
|
"paused"
|
|
311
307
|
];
|
|
312
|
-
function stableId(prefix, ...parts) {
|
|
313
|
-
return `${prefix}:${createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 32)}`;
|
|
314
|
-
}
|
|
315
|
-
/** Return the stable identity for one retry-safe delegated task. */
|
|
316
|
-
function getAgentInvocationId(parentConversationId, idempotencyKey) {
|
|
317
|
-
return stableId("agent-invocation", parentConversationId, idempotencyKey);
|
|
318
|
-
}
|
|
319
|
-
/** Return the stable child identity for one invocation without a named binding. */
|
|
320
|
-
function getUnnamedAgentConversationId(invocationId) {
|
|
321
|
-
return stableId("agent", invocationId);
|
|
322
|
-
}
|
|
323
|
-
/** Return the stable child identity for one named binding. */
|
|
324
|
-
function getNamedAgentConversationId(parentConversationId, name) {
|
|
325
|
-
return stableId("agent", parentConversationId, name);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Return the stable identity of the agent invocation that gives one child
|
|
329
|
-
* agent result to the child Conversation that started that child agent.
|
|
330
|
-
*/
|
|
331
|
-
function getAgentInvocationIdForResult(resultInvocationId) {
|
|
332
|
-
return stableId("agent-invocation", "result", resultInvocationId);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Return the stable identity of the agent invocation that gives one message
|
|
336
|
-
* from a child agent to the child Conversation that started that child agent.
|
|
337
|
-
*/
|
|
338
|
-
function getAgentInvocationIdForMessage(messageId) {
|
|
339
|
-
return stableId("agent-invocation", "message", messageId);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Return the stable identity of the agent invocation that gives one batch of
|
|
343
|
-
* watch events to a child Conversation. The first message of the batch names
|
|
344
|
-
* it.
|
|
345
|
-
*/
|
|
346
|
-
function getAgentInvocationIdForEvents(messageId) {
|
|
347
|
-
return stableId("agent-invocation", "events", messageId);
|
|
348
|
-
}
|
|
349
|
-
/** Return the stable turn identity advanced by one agent invocation. */
|
|
350
|
-
function getAgentInvocationTurnId(invocationId) {
|
|
351
|
-
return `agent-invocation:${invocationId}`;
|
|
352
|
-
}
|
|
353
|
-
/** Return the stable mailbox identity for one agent invocation. */
|
|
354
|
-
function getAgentInvocationMessageId(invocationId) {
|
|
355
|
-
return `agent-invocation:${invocationId}:input`;
|
|
356
|
-
}
|
|
357
|
-
const RESULT_MESSAGE_PREFIX = "agent-invocation:";
|
|
358
|
-
const RESULT_MESSAGE_SUFFIX = ":result";
|
|
359
|
-
/** Return the stable parent mailbox identity for one terminal result. */
|
|
360
|
-
function getAgentInvocationResultMessageId(invocationId) {
|
|
361
|
-
return `${RESULT_MESSAGE_PREFIX}${invocationId}${RESULT_MESSAGE_SUFFIX}`;
|
|
362
|
-
}
|
|
363
|
-
/** Read the invocation identity from one parent result mailbox identity. */
|
|
364
|
-
function parseAgentInvocationResultMessageId(messageId) {
|
|
365
|
-
if (!messageId.startsWith(RESULT_MESSAGE_PREFIX) || !messageId.endsWith(RESULT_MESSAGE_SUFFIX)) return;
|
|
366
|
-
return messageId.slice(17, -7) || void 0;
|
|
367
|
-
}
|
|
368
308
|
/** Parse one agent invocation row. */
|
|
369
309
|
function invocationFromRow(row) {
|
|
370
310
|
return agentInvocationSchema.parse({
|
|
@@ -391,14 +331,6 @@ function invocationFromRow(row) {
|
|
|
391
331
|
updatedAtMs: row.updatedAt.getTime()
|
|
392
332
|
});
|
|
393
333
|
}
|
|
394
|
-
/**
|
|
395
|
-
* Require every durable creation input to match before replaying one key.
|
|
396
|
-
* The title is not compared: a retry can generate a different one, and the
|
|
397
|
-
* stored title wins.
|
|
398
|
-
*/
|
|
399
|
-
function sameCreateInput(invocation, input) {
|
|
400
|
-
return invocation.parentConversationId === input.parentConversationId && invocation.agentName === input.agentName && invocation.input === input.input && invocation.agentType === input.agentType && invocation.reasoningLevel === input.reasoningLevel && JSON.stringify(invocation.actor) === JSON.stringify(input.actor) && JSON.stringify(invocation.credentialContext) === JSON.stringify(input.credentialContext) && JSON.stringify(invocation.destination) === JSON.stringify(input.destination);
|
|
401
|
-
}
|
|
402
334
|
/** Read one durable agent invocation. */
|
|
403
335
|
async function getAgentInvocation(invocationId) {
|
|
404
336
|
const rows = await getSqlExecutor().db().select().from(juniorAgentInvocations).where(eq(juniorAgentInvocations.invocationId, invocationId));
|
|
@@ -431,177 +363,12 @@ async function getChildAgentLabel(childConversationId) {
|
|
|
431
363
|
}).from(juniorAgentInvocations).where(eq(juniorAgentInvocations.childConversationId, childConversationId)).orderBy(sql`${juniorAgentInvocations.title} is null`, desc(juniorAgentInvocations.createdAt)).limit(1);
|
|
432
364
|
return row;
|
|
433
365
|
}
|
|
434
|
-
async function getNonTerminalAgentInvocationForConversation(childConversationId) {
|
|
435
|
-
const rows = await getSqlExecutor().db().select().from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.childConversationId, childConversationId), inArray(juniorAgentInvocations.status, NON_TERMINAL_AGENT_INVOCATION_STATUSES))).orderBy(asc(juniorAgentInvocations.createdAt)).limit(1);
|
|
436
|
-
return rows[0] ? invocationFromRow(rows[0]) : void 0;
|
|
437
|
-
}
|
|
438
|
-
async function countNonTerminalAgentInvocationsForChild(childConversationId) {
|
|
439
|
-
return (await getSqlExecutor().db().select({ value: count() }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.childConversationId, childConversationId), inArray(juniorAgentInvocations.status, NON_TERMINAL_AGENT_INVOCATION_STATUSES))))[0]?.value ?? 0;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* A child agent can only start or give work to child agents while it has
|
|
443
|
-
* open work. A stopped child has none. A root Conversation has no agent
|
|
444
|
-
* invocation, so it always passes.
|
|
445
|
-
*/
|
|
446
|
-
async function assertCanGiveChildWork(parentConversationId) {
|
|
447
|
-
if (await getLatestAgentInvocationForConversation(parentConversationId) && !await getNonTerminalAgentInvocationForConversation(parentConversationId)) throw new Error(`Agent conversation ${parentConversationId} has no open work and cannot give work to child agents`);
|
|
448
|
-
}
|
|
449
366
|
/**
|
|
450
|
-
*
|
|
451
|
-
*
|
|
367
|
+
* List the open agent invocations that run on one Conversation or on its
|
|
368
|
+
* child agents, oldest first. Open-work checks read this once and filter it.
|
|
452
369
|
*/
|
|
453
|
-
async function
|
|
454
|
-
return (await getSqlExecutor().db().select(
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Create or replay the first invocation of one new child agent. A name gives
|
|
458
|
-
* the child a stable Conversation id that later messages can address. A name
|
|
459
|
-
* that is already used throws: later work for that child goes through
|
|
460
|
-
* `createAgentInvocationForMessage`.
|
|
461
|
-
*/
|
|
462
|
-
async function createAgentInvocation(rawInput, nowMs = Date.now()) {
|
|
463
|
-
const input = createAgentInvocationSchema.parse(rawInput);
|
|
464
|
-
const invocationId = getAgentInvocationId(input.parentConversationId, input.idempotencyKey);
|
|
465
|
-
const childConversationId = input.agentName ? getNamedAgentConversationId(input.parentConversationId, input.agentName) : getUnnamedAgentConversationId(invocationId);
|
|
466
|
-
const lockName = getChildAgentLockName(input.parentConversationId);
|
|
467
|
-
return await getSqlExecutor().withLock(lockName, async () => {
|
|
468
|
-
const existing = await getAgentInvocation(invocationId);
|
|
469
|
-
if (existing) {
|
|
470
|
-
if (!sameCreateInput(existing, input)) throw new Error(`Agent invocation idempotency key was reused with different input for ${invocationId}`);
|
|
471
|
-
return existing;
|
|
472
|
-
}
|
|
473
|
-
await assertCanGiveChildWork(input.parentConversationId);
|
|
474
|
-
if (input.agentName && await getAgentBinding({
|
|
475
|
-
name: input.agentName,
|
|
476
|
-
parentConversationId: input.parentConversationId
|
|
477
|
-
})) throw new AgentNameInUseError(input.agentName);
|
|
478
|
-
if (await countActiveChildAgentsForParent(input.parentConversationId) >= 8) throw new AgentInvocationLimitError(8);
|
|
479
|
-
await getConversationStore().createChild({
|
|
480
|
-
childConversationId,
|
|
481
|
-
parentConversationId: input.parentConversationId,
|
|
482
|
-
nowMs,
|
|
483
|
-
source: "internal"
|
|
484
|
-
});
|
|
485
|
-
if (input.agentName) await getSqlExecutor().db().insert(juniorAgentBindings).values({
|
|
486
|
-
childConversationId,
|
|
487
|
-
name: input.agentName,
|
|
488
|
-
parentConversationId: input.parentConversationId
|
|
489
|
-
});
|
|
490
|
-
await getSqlExecutor().db().insert(juniorAgentInvocations).values({
|
|
491
|
-
invocationId,
|
|
492
|
-
parentConversationId: input.parentConversationId,
|
|
493
|
-
childConversationId,
|
|
494
|
-
agentName: input.agentName ?? null,
|
|
495
|
-
input: input.input,
|
|
496
|
-
title: input.title ?? null,
|
|
497
|
-
actor: input.actor,
|
|
498
|
-
credentialContext: input.credentialContext ?? null,
|
|
499
|
-
source: { kind: "agent_invocation" },
|
|
500
|
-
destination: input.destination,
|
|
501
|
-
agentType: input.agentType ?? null,
|
|
502
|
-
reasoningLevel: input.reasoningLevel ?? null,
|
|
503
|
-
parentToolCallId: input.parentToolCallId ?? null,
|
|
504
|
-
status: "pending",
|
|
505
|
-
mailboxStatus: "pending",
|
|
506
|
-
createdAt: new Date(nowMs),
|
|
507
|
-
updatedAt: new Date(nowMs),
|
|
508
|
-
terminalAt: null
|
|
509
|
-
}).onConflictDoNothing();
|
|
510
|
-
const invocation = await getAgentInvocation(invocationId);
|
|
511
|
-
if (!invocation || !sameCreateInput(invocation, input)) throw new Error(`Agent invocation creation raced for ${invocationId}`);
|
|
512
|
-
return invocation;
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Create or replay the agent invocation that gives one input to a child
|
|
517
|
-
* Conversation: a result or message from its own child agent, or its own
|
|
518
|
-
* watch events. It continues that Conversation for the same parent as
|
|
519
|
-
* `latest`, and for the same Actor and credentials unless `runAs` sets them.
|
|
520
|
-
* It skips the queue and active-count checks because it continues work that
|
|
521
|
-
* already passed them.
|
|
522
|
-
*/
|
|
523
|
-
async function createAgentInvocationFromLatest(args, nowMs = Date.now()) {
|
|
524
|
-
const { invocationId } = args;
|
|
525
|
-
await getSqlExecutor().db().insert(juniorAgentInvocations).values({
|
|
526
|
-
invocationId,
|
|
527
|
-
parentConversationId: args.latest.parentConversationId,
|
|
528
|
-
childConversationId: args.latest.childConversationId,
|
|
529
|
-
agentName: args.latest.agentName ?? null,
|
|
530
|
-
input: args.input,
|
|
531
|
-
actor: (args.runAs ?? args.latest).actor,
|
|
532
|
-
credentialContext: (args.runAs ?? args.latest).credentialContext ?? null,
|
|
533
|
-
source: args.runAs?.source ?? { kind: "agent_invocation" },
|
|
534
|
-
destination: args.latest.destination,
|
|
535
|
-
agentType: args.latest.agentType ?? null,
|
|
536
|
-
reasoningLevel: args.latest.reasoningLevel ?? null,
|
|
537
|
-
status: "pending",
|
|
538
|
-
mailboxStatus: "pending",
|
|
539
|
-
createdAt: new Date(nowMs),
|
|
540
|
-
updatedAt: new Date(nowMs),
|
|
541
|
-
terminalAt: null
|
|
542
|
-
}).onConflictDoNothing();
|
|
543
|
-
const invocation = await getAgentInvocation(invocationId);
|
|
544
|
-
if (!invocation || invocation.childConversationId !== args.latest.childConversationId) throw new Error(`Agent invocation creation raced for ${invocationId}`);
|
|
545
|
-
return invocation;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Return whether a pending agent invocation still waits for older open work
|
|
549
|
-
* on its child.
|
|
550
|
-
*/
|
|
551
|
-
async function isQueuedBehindOpenWork(invocation) {
|
|
552
|
-
if (invocation.status !== "pending") return false;
|
|
553
|
-
return (await getSqlExecutor().db().select({ invocationId: juniorAgentInvocations.invocationId }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.childConversationId, invocation.childConversationId), lt(juniorAgentInvocations.createdAt, new Date(invocation.createdAtMs)), inArray(juniorAgentInvocations.status, NON_TERMINAL_AGENT_INVOCATION_STATUSES))).limit(1)).length > 0;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Create or replay the agent invocation for one message from a parent to one
|
|
557
|
-
* of its child agents. The child continues its history. If the child already
|
|
558
|
-
* has open work, the new agent invocation waits for that work and the parent
|
|
559
|
-
* gets one report for both. A stopped child starts again.
|
|
560
|
-
*/
|
|
561
|
-
async function createAgentInvocationForMessage(input, nowMs = Date.now()) {
|
|
562
|
-
const invocationId = getAgentInvocationId(input.parentConversationId, input.idempotencyKey);
|
|
563
|
-
return await getSqlExecutor().withLock(getChildAgentLockName(input.parentConversationId), async () => {
|
|
564
|
-
const existing = await getAgentInvocation(invocationId);
|
|
565
|
-
if (existing) {
|
|
566
|
-
if (existing.childConversationId !== input.childConversationId || existing.input !== input.input) throw new Error(`Agent invocation idempotency key was reused with different input for ${invocationId}`);
|
|
567
|
-
return {
|
|
568
|
-
invocation: existing,
|
|
569
|
-
queued: await isQueuedBehindOpenWork(existing)
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
const latest = await getLatestAgentInvocationForConversation(input.childConversationId);
|
|
573
|
-
if (!latest || latest.parentConversationId !== input.parentConversationId) throw new Error(`${input.childConversationId} is not a child agent of ${input.parentConversationId}`);
|
|
574
|
-
await assertCanGiveChildWork(input.parentConversationId);
|
|
575
|
-
const openCount = await countNonTerminalAgentInvocationsForChild(input.childConversationId);
|
|
576
|
-
if (openCount >= 4) throw new AgentMessageQueueFullError(4);
|
|
577
|
-
if (openCount === 0 && await countActiveChildAgentsForParent(input.parentConversationId) >= 8) throw new AgentInvocationLimitError(8);
|
|
578
|
-
await getSqlExecutor().db().insert(juniorAgentInvocations).values({
|
|
579
|
-
invocationId,
|
|
580
|
-
parentConversationId: input.parentConversationId,
|
|
581
|
-
childConversationId: input.childConversationId,
|
|
582
|
-
agentName: latest.agentName ?? null,
|
|
583
|
-
input: input.input,
|
|
584
|
-
title: null,
|
|
585
|
-
actor: input.actor,
|
|
586
|
-
credentialContext: input.credentialContext ?? null,
|
|
587
|
-
source: { kind: "agent_invocation" },
|
|
588
|
-
destination: input.destination,
|
|
589
|
-
agentType: latest.agentType ?? null,
|
|
590
|
-
reasoningLevel: latest.reasoningLevel ?? null,
|
|
591
|
-
parentToolCallId: input.parentToolCallId,
|
|
592
|
-
status: "pending",
|
|
593
|
-
mailboxStatus: "pending",
|
|
594
|
-
createdAt: new Date(nowMs),
|
|
595
|
-
updatedAt: new Date(nowMs),
|
|
596
|
-
terminalAt: null
|
|
597
|
-
}).onConflictDoNothing();
|
|
598
|
-
const invocation = await getAgentInvocation(invocationId);
|
|
599
|
-
if (!invocation) throw new Error(`Agent invocation creation raced for ${invocationId}`);
|
|
600
|
-
return {
|
|
601
|
-
invocation,
|
|
602
|
-
queued: openCount > 0
|
|
603
|
-
};
|
|
604
|
-
});
|
|
370
|
+
async function listOpenAgentInvocations(conversationId) {
|
|
371
|
+
return (await getSqlExecutor().db().select().from(juniorAgentInvocations).where(and(or(eq(juniorAgentInvocations.childConversationId, conversationId), eq(juniorAgentInvocations.parentConversationId, conversationId)), inArray(juniorAgentInvocations.status, NON_TERMINAL_AGENT_INVOCATION_STATUSES))).orderBy(asc(juniorAgentInvocations.createdAt))).map(invocationFromRow);
|
|
605
372
|
}
|
|
606
373
|
/**
|
|
607
374
|
* Return whether a child Conversation has work that will start another agent
|
|
@@ -609,9 +376,9 @@ async function createAgentInvocationForMessage(input, nowMs = Date.now()) {
|
|
|
609
376
|
* sent child agent result that no agent invocation has received yet.
|
|
610
377
|
*/
|
|
611
378
|
async function hasOpenChildWork(invocation) {
|
|
612
|
-
const db = getSqlExecutor().db();
|
|
613
379
|
const conversationId = invocation.childConversationId;
|
|
614
|
-
if ((await
|
|
380
|
+
if ((await listOpenAgentInvocations(conversationId)).some((row) => row.invocationId !== invocation.invocationId)) return true;
|
|
381
|
+
const db = getSqlExecutor().db();
|
|
615
382
|
const sent = await db.select({ invocationId: juniorAgentInvocations.invocationId }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.parentConversationId, conversationId), inArray(juniorAgentInvocations.parentMailboxStatus, ["pending", "appended"])));
|
|
616
383
|
if (sent.length === 0) return false;
|
|
617
384
|
return (await db.select({ invocationId: juniorAgentInvocations.invocationId }).from(juniorAgentInvocations).where(inArray(juniorAgentInvocations.invocationId, sent.map((row) => getAgentInvocationIdForResult(row.invocationId))))).length < sent.length;
|
|
@@ -706,4 +473,4 @@ async function markAgentInvocationSteered(invocationId, nowMs = Date.now()) {
|
|
|
706
473
|
function isTerminalAgentInvocation(invocation) {
|
|
707
474
|
return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
|
|
708
475
|
}
|
|
709
|
-
export {
|
|
476
|
+
export { getAgentInvocationIdForEvents as A, ConversationTurnBoundaryError as B, agentNameSchema as C, agentTypeStartsWithParentHistory as D, agentTypeInstructions as E, getAgentInvocationTurnId as F, isCooperativeTurnYieldError as G, TurnInputCommitLostError as H, getChildAgentLockName as I, markTurnClosed as J, isTurnInputCommitLostError as K, getNamedAgentConversationId as L, getAgentInvocationIdForResult as M, getAgentInvocationMessageId as N, formatAgentTypes as O, getAgentInvocationResultMessageId as P, getUnnamedAgentConversationId as R, agentBindingSchema as S, AGENT_TYPES as T, TurnInputDeferredError as U, CooperativeTurnYieldError as V, getConversationTurnBoundaryError as W, markTurnFailed as X, markTurnCompleted as Y, startActiveTurn as Z, markAgentInvocationRunning as _, getAgentInvocation as a, CHILD_AGENT_RESULTS as b, invocationFromRow as c, listOpenAgentInvocations as d, listPendingAgentInvocationMailboxAppends as f, markAgentInvocationPaused as g, markAgentInvocationParentMailboxAppended as h, getActiveAgentInvocationForConversation as i, getAgentInvocationIdForMessage as j, getAgentInvocationId as k, isTerminalAgentInvocation as l, markAgentInvocationMailboxAppended as m, NON_TERMINAL_AGENT_INVOCATION_STATUSES as n, getChildAgentLabel as o, listPendingAgentInvocationResults as p, isTurnInputDeferredError as q, completeAgentInvocation as r, getLatestAgentInvocationForConversation as s, ACTIVE_AGENT_INVOCATION_STATUSES as t, listAgentInvocationsForConversation as u, markAgentInvocationSteered as v, createAgentInvocationSchema as w, PARENT_AGENT_TARGET as x, reportReplacedAgentInvocation as y, parseAgentInvocationResultMessageId as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { At as
|
|
2
|
-
import { x as getConversationStore } from "./viewer-
|
|
3
|
-
import "./background-compaction-queue-
|
|
1
|
+
import { At as recordConversationRetry$1, Dt as markConversationWorkEnqueued$1, Et as listActiveConversationIds$1, Ft as requestConversationWork$1, It as startConversationWork$1, Lt as steerWebPendingMessages$1, Mt as releaseInboundMessage, Nt as removeActiveConversation$1, Pt as requestAnotherSlice$1, Rt as stopConversationWork$1, _t as completeConversationWork$1, bt as getConversation$1, ct as appendExclusiveInboundMessage, dt as cancelHumanFacingPendingMessages$1, ft as checkInConversationWork$1, gt as completeConversationStop$1, ht as clearExpiredConversationLease$1, jt as releaseConversationWork$1, kt as recordAttemptFailure$1, lt as appendInboundMessage, mt as clearConsumedConversationWake$1, pt as claimInboundMessage$1, st as ackMessages$1, ut as beginConversationResume$1, vt as deadLetterAttempt$1, xt as getConversationWorkState$1, yt as drainConversationMailbox$1 } from "./projection-DliWYrnT.js";
|
|
2
|
+
import { x as getConversationStore } from "./viewer-1Ea81s0b.js";
|
|
3
|
+
import "./background-compaction-queue-DXkLsWoH.js";
|
|
4
4
|
// src/chat/task-execution/store.ts
|
|
5
5
|
function metadataStore(options) {
|
|
6
6
|
return options.conversationStore ?? getConversationStore();
|
|
@@ -97,6 +97,28 @@ async function ensureConversationWake(args) {
|
|
|
97
97
|
queueMessageId: queueResult?.messageId
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Record an inbound message id that skips the mailbox. When the claim is
|
|
102
|
+
* saved but its metadata write fails, this releases the claim, so a
|
|
103
|
+
* redelivery can claim it again.
|
|
104
|
+
*/
|
|
105
|
+
async function claimInboundMessage(args) {
|
|
106
|
+
const result = await claimInboundMessage$1(args);
|
|
107
|
+
if (result.status === "claimed") try {
|
|
108
|
+
await recordExecutionMetadata({
|
|
109
|
+
conversationId: args.message.conversationId,
|
|
110
|
+
conversationStore: args.conversationStore,
|
|
111
|
+
state: args.state
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
await releaseInboundMessage({
|
|
115
|
+
message: args.message,
|
|
116
|
+
state: args.state
|
|
117
|
+
});
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
100
122
|
async function enqueueAfterAppend(args) {
|
|
101
123
|
const nowMs = args.nowMs ?? now();
|
|
102
124
|
const appendResult = args.appendResult;
|
|
@@ -178,7 +200,10 @@ async function appendAndEnqueueExclusiveInboundMessage(args) {
|
|
|
178
200
|
/** Persist a stop request for the current Conversation run. */
|
|
179
201
|
async function stopConversationWork(args) {
|
|
180
202
|
const result = await stopConversationWork$1(args);
|
|
181
|
-
if (result.status === "requested")
|
|
203
|
+
if (result.status === "requested") {
|
|
204
|
+
args.onStopSaved?.();
|
|
205
|
+
await recordExecutionMetadata(args);
|
|
206
|
+
}
|
|
182
207
|
return result;
|
|
183
208
|
}
|
|
184
209
|
/** Finish an observed stop request under the current worker lease. */
|
|
@@ -292,4 +317,4 @@ async function removeActiveConversation(args) {
|
|
|
292
317
|
async function listActiveConversationIds(args = {}) {
|
|
293
318
|
return await listActiveConversationIds$1(args);
|
|
294
319
|
}
|
|
295
|
-
export {
|
|
320
|
+
export { removeActiveConversation as C, steerWebPendingMessages as D, startConversationWork as E, stopConversationWork as O, releaseConversationWork as S, requestConversationWork as T, getConversationWorkState as _, cancelHumanFacingPendingMessages as a, recordAttemptFailure as b, clearConsumedConversationWake as c, completeConversationWork as d, countPendingConversationMessages as f, getConversation as g, ensureConversationWake as h, beginConversationResume as i, clearExpiredConversationLease as l, drainConversationMailbox as m, appendAndEnqueueExclusiveInboundMessage as n, checkInConversationWork as o, deadLetterAttempt as p, appendAndEnqueueInboundMessage as r, claimInboundMessage as s, ackMessages as t, completeConversationStop as u, hasRunnableConversationWork as v, requestAnotherSlice as w, recordConversationRetry as x, listActiveConversationIds as y };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as logWarn } from "./logging-
|
|
2
|
-
import { _ as runWithTurnRequestDeadline, f as QUEUE_SIGNATURE_MAX_AGE_MS, h as getQueueProvider, m as verifyQueueMessage, p as signQueueMessage } from "./background-compaction-queue-
|
|
1
|
+
import { h as logWarn } from "./logging-BfORLKoq.js";
|
|
2
|
+
import { _ as runWithTurnRequestDeadline, f as QUEUE_SIGNATURE_MAX_AGE_MS, h as getQueueProvider, m as verifyQueueMessage, p as signQueueMessage } from "./background-compaction-queue-DXkLsWoH.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
// src/chat/queue/callback.ts
|
|
@@ -110,7 +110,7 @@ function pluginTaskCallback() {
|
|
|
110
110
|
maxDeliveries: PLUGIN_TASK_MAX_DELIVERIES,
|
|
111
111
|
onRejected: logPluginTaskQueueMessageRejected,
|
|
112
112
|
run: async (message) => {
|
|
113
|
-
const { processPluginTask } = await import("./task-runner-
|
|
113
|
+
const { processPluginTask } = await import("./task-runner-D8lddjzp.js").then((n) => n.r);
|
|
114
114
|
await processPluginTask(message);
|
|
115
115
|
},
|
|
116
116
|
topic: PLUGIN_TASK_QUEUE_TOPIC,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import {
|
|
3
|
-
import { E as withSpan } from "./logging-
|
|
2
|
+
import { Fa as createPluginEmbedder, Ia as createPluginModel, Ja as createPluginModelCostRecorder, Xn as coreTaskRegistrations, Ya as createPluginLogger, Yt as getPiMessageRole, an as isToolResultMessage, cn as stripRuntimeTurnContext, di as createPluginState, en as instructionTextForProjection, in as isToolResultError, jo as createPluginCache, nt as getTurnRecord, on as normalizeToolNameFromResult, qn as getPlugins, so as createPluginConversationEvents, v as hydrateConversationMessages } from "./projection-DliWYrnT.js";
|
|
3
|
+
import { E as withSpan } from "./logging-BfORLKoq.js";
|
|
4
4
|
import { h as parseSlackMessageTs } from "./actor-6jsm_v96.js";
|
|
5
|
-
import { S as getDb, i as readActorIdentity, x as getConversationStore } from "./viewer-
|
|
5
|
+
import { S as getDb, i as readActorIdentity, x as getConversationStore } from "./viewer-1Ea81s0b.js";
|
|
6
6
|
import { v as sameActorIdentity } from "./media-Bu9C6lz0.js";
|
|
7
|
-
import { r as getStateAdapter } from "./adapter-
|
|
8
|
-
import { t as resolveConversationRouting, u as getDispatchRecord } from "./turn-session-routing-
|
|
9
|
-
import { o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-
|
|
10
|
-
import { i as pluginTaskParamsSchema, r as pluginTaskId, s as sendVercelPluginTask } from "./task-queue-
|
|
7
|
+
import { r as getStateAdapter } from "./adapter-DN5AB4VU.js";
|
|
8
|
+
import { t as resolveConversationRouting, u as getDispatchRecord } from "./turn-session-routing-CGMKrYOj.js";
|
|
9
|
+
import { o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-CrFk3K_7.js";
|
|
10
|
+
import { i as pluginTaskParamsSchema, r as pluginTaskId, s as sendVercelPluginTask } from "./task-queue-Bt0IoR2i.js";
|
|
11
11
|
import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
|
|
12
12
|
// src/chat/plugins/task-runner.ts
|
|
13
13
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { G as toOptionalNumber, K as toOptionalString, W as isRecord } from "./logging-
|
|
3
|
-
import { S as getDb } from "./viewer-
|
|
4
|
-
import { r as getStateAdapter } from "./adapter-
|
|
1
|
+
import { Mo as createDurableLocationConfigurationService, ri as JUNIOR_THREAD_STATE_TTL_MS, y as persistConversationMessages } from "./projection-DliWYrnT.js";
|
|
2
|
+
import { G as toOptionalNumber, K as toOptionalString, W as isRecord } from "./logging-BfORLKoq.js";
|
|
3
|
+
import { S as getDb } from "./viewer-1Ea81s0b.js";
|
|
4
|
+
import { r as getStateAdapter } from "./adapter-DN5AB4VU.js";
|
|
5
5
|
// src/chat/state/conversation.ts
|
|
6
6
|
function defaultConversationState() {
|
|
7
7
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { b as getProviderErrorUserMessage, g as ProviderError, v as findProviderError, y as getProviderErrorAttributes } from "./client-
|
|
3
|
-
import { W as isRecord, t as buildTurnFailureResponse } from "./logging-
|
|
1
|
+
import { Eo as listConversationAnnotations, N as markConversationMessage, bn as buildDeterministicTurnId, q as clearPendingAuth, v as hydrateConversationMessages } from "./projection-DliWYrnT.js";
|
|
2
|
+
import { b as getProviderErrorUserMessage, g as ProviderError, v as findProviderError, y as getProviderErrorAttributes } from "./client-DDbBucBw.js";
|
|
3
|
+
import { W as isRecord, t as buildTurnFailureResponse } from "./logging-BfORLKoq.js";
|
|
4
4
|
import { h as parseSlackMessageTs } from "./actor-6jsm_v96.js";
|
|
5
|
-
import { S as getDb, y as getConversationEventStore } from "./viewer-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { a as persistThreadStateById, o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-
|
|
5
|
+
import { S as getDb, y as getConversationEventStore } from "./viewer-1Ea81s0b.js";
|
|
6
|
+
import { F as removedCardSchema, I as resolveMessageCards, P as readMessageCardRefs } from "./conversation-D8kVoCrP.js";
|
|
7
|
+
import { F as getAgentInvocationTurnId, J as markTurnClosed, Y as markTurnCompleted, a as getAgentInvocation, z as parseAgentInvocationResultMessageId } from "./store-B26LV6UP.js";
|
|
8
|
+
import { a as persistThreadStateById, o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-CrFk3K_7.js";
|
|
9
9
|
// src/chat/conversations/pending-cards.ts
|
|
10
10
|
/**
|
|
11
11
|
* Add the cards that tool results selected since the last visible assistant
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as getConversationEventStore } from "./viewer-
|
|
1
|
+
import { y as getConversationEventStore } from "./viewer-1Ea81s0b.js";
|
|
2
2
|
// src/chat/conversations/turn-lifecycle.ts
|
|
3
3
|
/** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
|
|
4
4
|
var ConversationTurnLifecycleService = class {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as botConfig } from "./config-
|
|
3
|
-
import { _ as runBestEffort, h as logWarn } from "./logging-
|
|
4
|
-
import {
|
|
5
|
-
import { d as juniorAutomationVersions, f as juniorAutomations, j as juniorConversations, u as juniorAutomationRuns } from "./executor-
|
|
6
|
-
import { h as credentialSubjectSchema } from "./registry-
|
|
7
|
-
import { r as getStateAdapter } from "./adapter-
|
|
8
|
-
import { O as eventAutomationSchema, S as automationVersionSchema, j as scheduledAutomationSchema } from "./automation-
|
|
1
|
+
import { Ki as openSlackDirectMessage, Li as escapeSlackMrkdwnText, Ri as formatSlackLink, T as fallbackShortTitle, Yi as postSlackMessage, ci as getDashboardTaskLink, ri as JUNIOR_THREAD_STATE_TTL_MS, ui as ToolInputError } from "./projection-DliWYrnT.js";
|
|
2
|
+
import { n as botConfig } from "./config-DqFnykQT.js";
|
|
3
|
+
import { _ as runBestEffort, h as logWarn } from "./logging-BfORLKoq.js";
|
|
4
|
+
import { S as getDb, at as agentTurnTotalTokens, it as agentTurnCostUsd } from "./viewer-1Ea81s0b.js";
|
|
5
|
+
import { d as juniorAutomationVersions, f as juniorAutomations, j as juniorConversations, u as juniorAutomationRuns } from "./executor-BLEMIgIZ.js";
|
|
6
|
+
import { h as credentialSubjectSchema } from "./registry-rC7MCxu8.js";
|
|
7
|
+
import { r as getStateAdapter } from "./adapter-DN5AB4VU.js";
|
|
8
|
+
import { O as eventAutomationSchema, S as automationVersionSchema, j as scheduledAutomationSchema } from "./automation-Mk8aaHzy.js";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import * as z from "zod";
|
|
11
11
|
import { and, asc, count, desc, eq, gte, inArray, isNotNull, isNull, lte, max, ne, or, sql } from "drizzle-orm";
|
|
@@ -815,7 +815,7 @@ function conversationAggregateColumns(sources) {
|
|
|
815
815
|
costUsd: sql`SUM(${costValue(metrics)})::double precision`,
|
|
816
816
|
durationMs: sql`COALESCE(SUM(${metrics.durationMs}), 0)::double precision`,
|
|
817
817
|
failed: sql`${conversationCount} FILTER (
|
|
818
|
-
WHERE ${roots.executionStatus} = 'failed'
|
|
818
|
+
WHERE ${roots.executionStatus} = 'failed' AND ${roots.stoppedAt} IS NULL
|
|
819
819
|
)::integer`,
|
|
820
820
|
inputTokens: sql`SUM(${usageTokenValue(metrics, "inputTokens")})::double precision`,
|
|
821
821
|
tokens: sql`SUM(${tokenValue(metrics)})::double precision`
|
|
@@ -1583,7 +1583,7 @@ function slackSourceForDestination(args) {
|
|
|
1583
1583
|
* Reads parent Conversations when this Conversation has no Destination.
|
|
1584
1584
|
*/
|
|
1585
1585
|
async function resolveConversationRouting(args) {
|
|
1586
|
-
const conversationStore = args.conversationStore ?? (await import("./viewer-
|
|
1586
|
+
const conversationStore = args.conversationStore ?? (await import("./viewer-1Ea81s0b.js").then((n) => n.v)).getConversationStore();
|
|
1587
1587
|
const chain = await loadConversationChain(args.conversationId, conversationStore);
|
|
1588
1588
|
let destination;
|
|
1589
1589
|
let source;
|