@sentry/junior 0.285.0 → 0.286.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-DN5AB4VU.js → adapter-JQZaJ-B_.js} +1 -1
- package/dist/{admin-DOITMKnn.js → admin-Dm2bimJ-.js} +1 -1
- package/dist/{agent-runner-BsWhHe4N.js → agent-runner-DGCwOEyL.js} +1567 -1048
- package/dist/api/schema.d.ts +1 -1
- package/dist/api/schema.js +5 -5
- package/dist/api.d.ts +1 -1
- package/dist/api.js +70 -92
- package/dist/{app-DyMs9330.d.ts → app-BKq0JzWx.d.ts} +2 -3
- package/dist/app.d.ts +1 -1
- package/dist/app.js +37 -40
- package/dist/{assistant-reply-9Jip5bsr.js → assistant-reply-CAPafcUY.js} +1 -1
- package/dist/{automation-Mk8aaHzy.js → automation-B-jJN_gM.js} +1 -1
- package/dist/{background-compaction-queue-DXkLsWoH.js → background-compaction-queue-Btu2oab_.js} +137 -3
- package/dist/{briefs-Cl8-nK9B.js → briefs-UMeYehUe.js} +4 -4
- package/dist/{catalog-runtime-Bte6jRB2.js → catalog-runtime-Bym8GVdh.js} +1 -1
- package/dist/cli/chat.js +14 -14
- 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 +5 -6
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{client-DDbBucBw.js → client-B0aAs7wC.js} +2 -2
- package/dist/{config-DqFnykQT.js → config-B9f9Lqo5.js} +1 -1
- package/dist/{connections-DA4LT9LL.js → connections-CQ7p0aNJ.js} +16 -50
- package/dist/{conversation-D8kVoCrP.js → conversation-BusI2uzj.js} +15 -6
- package/dist/{conversation-pending-messages-BvROq1bq.js → conversation-pending-messages-DwehU0Fd.js} +1 -1
- package/dist/{conversation-privacy-D0j_h70R.js → conversation-privacy-Cd_nZZBM.js} +1 -1
- package/dist/{credential-sync-hcsYatw-.js → credential-sync-DmiJi_At.js} +13 -13
- package/dist/{db-BhHZSuFw.d.ts → db-C5zi4ecs.d.ts} +4 -4
- package/dist/{executor-BLEMIgIZ.js → executor-Dipi2Ixl.js} +11 -17
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-BfORLKoq.js → logging-CMFhLLj4.js} +1 -1
- package/dist/{media-Bu9C6lz0.js → media-B-BpXo41.js} +14 -2
- package/dist/{message-DqjuKzUx.js → message-D1xLljUF.js} +9 -9
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -3
- package/dist/{oauth-callback-server-CFSRzu1n.js → oauth-callback-server-DCAFIUQr.js} +2 -2
- package/dist/{projection-DliWYrnT.js → projection-CoeMNxJ4.js} +286 -212
- package/dist/{prompt-BvIUzY4y.js → prompt-C9OQEfan.js} +1 -1
- package/dist/{registry-rC7MCxu8.js → registry-u-sFYtx_.js} +1 -1
- package/dist/{resolve-Biu8Qw3u.js → resolve-DYqgL3Eo.js} +3 -3
- package/dist/{result-DxJMCX47.js → result-CescSwAw.js} +8 -8
- package/dist/{runner-BQJSFLKg.js → runner-Cr67a8TB.js} +16 -12
- package/dist/{sandbox-egress-signals-6aMxJSDn.js → sandbox-egress-signals-DLOazy5W.js} +1 -1
- package/dist/{schema-BasXTvi2.js → schema-BUSi3sgv.js} +5 -5
- package/dist/{schema-BUviRAs8.d.ts → schema-Ih60j59-.d.ts} +44 -7
- package/dist/{service-account-BI5Wgx22.js → service-account-CGEqz9wG.js} +3 -3
- package/dist/{service-account-CAE-_1dR.js → service-account-CsKxktLk.js} +3 -3
- package/dist/{session-stop-CA-jOJ84.js → session-stop-CGz5DByb.js} +22 -20
- package/dist/{skills-B22duVJU.js → skills-COCqf61f.js} +2 -2
- package/dist/{spawn-BB2_4VYn.js → spawn-C8F_iXWO.js} +13 -2
- package/dist/{stop-DioIcEAu.js → stop-GyFZkHuQ.js} +242 -952
- package/dist/{store-Dn4W7qgH.js → store-D0-8plWp.js} +3 -3
- package/dist/{turn-session-routing-CGMKrYOj.js → task-runner-xPuQmEot.js} +1439 -993
- package/dist/{store-B26LV6UP.js → turn-failure-response-BOviBdT-.js} +331 -5
- package/dist/{validation-TzhfQABF.js → validation-DZDKorGz.js} +1 -1
- package/dist/{version-DSk8CFvA.js → version-BTIz7fGi.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-1Ea81s0b.js → viewer-CH-ASQzh.js} +39 -36
- package/dist/{work-ybG4_q5C.js → work-C75_IM5e.js} +92 -87
- package/dist/{worker-ccSyZRNz.js → worker-Dl47I729.js} +6 -6
- package/migrations/0086_shared_archive.sql +31 -0
- package/migrations/0087_child_location.sql +64 -0
- package/migrations/meta/0086_snapshot.json +4366 -0
- package/migrations/meta/0087_snapshot.json +4366 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +5 -4
- package/dist/task-queue-Bt0IoR2i.js +0 -139
- package/dist/task-runner-D8lddjzp.js +0 -290
- package/dist/thread-state-CrFk3K_7.js +0 -173
- package/dist/turn-failure-response-DaJ04qVj.js +0 -224
- package/dist/turn-lifecycle-C2mXS7AZ.js +0 -58
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { n as botConfig } from "./config-
|
|
3
|
-
import { C as getSqlExecutor,
|
|
4
|
-
import { g as juniorAgentInvocations, h as juniorAgentBindings } from "./executor-
|
|
5
|
-
import { m as agentInstructionProvenance, v as sameActorIdentity } from "./media-
|
|
6
|
-
import { Ct as
|
|
7
|
-
import {
|
|
8
|
-
import { n as getAssistantReplyText } from "./assistant-reply-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { $ as pauseLostWorkerTurn, Q as lostWorkerBeforeFirstSave, Qt as getTerminalAssistantMessages, U as AuthorizationFlowDisabledError, et as saveTurnCheckpoint, go as loadForkHistory, hn as escapeClosingTags, it as getTurnRecord, qt as isTurnExecutionLimitExceededError, rt as failTurnRecord, s as openConversationProjection, tt as abandonTurnRecord, v as hydrateConversationMessages, vn as renderTag, z as PluginCredentialFailureError } from "./projection-CoeMNxJ4.js";
|
|
2
|
+
import { n as botConfig } from "./config-B9f9Lqo5.js";
|
|
3
|
+
import { C as getSqlExecutor, V as SYSTEM_IDENTITY_ID, x as getConversationStore, y as getConversationEventStore } from "./viewer-CH-ASQzh.js";
|
|
4
|
+
import { g as juniorAgentInvocations, h as juniorAgentBindings } from "./executor-Dipi2Ixl.js";
|
|
5
|
+
import { m as agentInstructionProvenance, v as sameActorIdentity } from "./media-B-BpXo41.js";
|
|
6
|
+
import { Ct as recordSubagentStarted, Dt as executeTurn, Et as AgentRunError, Ft as AgentInvocationLimitError, Lt as AgentMessageQueueFullError, Ot as finishTurn, St as recordSubagentEnded, Tt as supersedeOpenMailboxTurns, xt as stopChildAgentsOf, zt as AgentNameInUseError } from "./agent-runner-DGCwOEyL.js";
|
|
7
|
+
import { A as markAgentInvocationPaused, B as agentTypeInstructions, C as isTerminalAgentInvocation, I as agentBindingSchema, M as markAgentInvocationSteered, N as reportReplacedAgentInvocation, O as markAgentInvocationMailboxAppended, Q as getUnnamedAgentConversationId, R as createAgentInvocationSchema, T as listOpenAgentInvocations, U as getAgentInvocationId, V as agentTypeStartsWithParentHistory, X as getChildAgentLockName, Y as getAgentInvocationTurnId, Z as getNamedAgentConversationId, _ as completeAgentInvocation, f as ConversationTurnLifecycleService, g as NON_TERMINAL_AGENT_INVOCATION_STATUSES, h as ACTIVE_AGENT_INVOCATION_STATUSES, it as getConversationTurnBoundaryError, j as markAgentInvocationRunning, nt as TurnInputCommitLostError, ot as isTurnInputCommitLostError, q as getAgentInvocationMessageId, v as getActiveAgentInvocationForConversation, w as listAgentInvocationsForConversation, x as getLatestAgentInvocationForConversation, y as getAgentInvocation } from "./turn-failure-response-BOviBdT-.js";
|
|
8
|
+
import { n as getAssistantReplyText } from "./assistant-reply-CAPafcUY.js";
|
|
9
|
+
import { $ as withoutSavedSteeringMessages, B as maybePostAutomatedTurnLimitNotice, K as recordFinishedTurnForAutomatedLimit, X as buildSteeringPiMessage, Z as instructionForInputs, at as readBlockedReport, h as parseWebMessages, i as resumeStoppedConversationTree, p as listActiveMailboxTurns, q as resetAutomatedTurnLimit, u as getActiveConversationTurnId } from "./session-stop-CGz5DByb.js";
|
|
10
|
+
import { S as getTurnRequestDeadline } from "./background-compaction-queue-Btu2oab_.js";
|
|
11
|
+
import { r as appendAndEnqueueInboundMessage } from "./store-D0-8plWp.js";
|
|
12
|
+
import { _t as getPersistedThreadState, bt as coerceThreadConversationState, gt as getPersistedSandboxState, yt as persistThreadStateById } from "./task-runner-xPuQmEot.js";
|
|
13
13
|
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import * as z from "zod";
|
|
15
15
|
import { and, eq } from "drizzle-orm";
|
|
@@ -222,50 +222,49 @@ async function createAgentInvocationForMessage(input, nowMs = Date.now()) {
|
|
|
222
222
|
};
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
|
-
// src/chat/
|
|
226
|
-
/** An error thrown while the agent advances a Run. */
|
|
227
|
-
var AgentRunError = class extends Error {
|
|
228
|
-
constructor(cause) {
|
|
229
|
-
super(cause instanceof Error ? cause.message : "Agent Run failed", { cause });
|
|
230
|
-
this.name = "AgentRunError";
|
|
231
|
-
}
|
|
232
|
-
};
|
|
225
|
+
// src/chat/agent-invocations/thread-turn.ts
|
|
233
226
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
227
|
+
* A person's Turn in a Thread. People message a Thread like a root, but it
|
|
228
|
+
* stays a child: only a root delivers to its Location, so replies stay in
|
|
229
|
+
* Junior. Agent invocation input and watch Events keep the child worker. A
|
|
230
|
+
* person's Turn and an Agent invocation Turn are never open at the same time.
|
|
238
231
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
/** Record the terminal lifecycle event of a Turn from its saved result. */
|
|
252
|
-
async function finishTurn(conversationId, turnId, saved) {
|
|
253
|
-
const lifecycle = new ConversationTurnLifecycleService(getConversationEventStore());
|
|
254
|
-
const common = {
|
|
255
|
-
conversationId,
|
|
256
|
-
createdAtMs: saved.finishedAtMs ?? Date.now(),
|
|
257
|
-
turnId
|
|
232
|
+
/**
|
|
233
|
+
* Select the person's Turn work of a Thread, or undefined for Agent
|
|
234
|
+
* invocation work. A Thread has one open Turn at a time, like a root. Web
|
|
235
|
+
* Messages start a person's Turn, and an empty wake resumes the open person's
|
|
236
|
+
* Turn. Every other input and wake goes to the child worker.
|
|
237
|
+
*/
|
|
238
|
+
async function resolveThreadTurnWork(context) {
|
|
239
|
+
const batch = parseWebMessages(context.attempt.messages);
|
|
240
|
+
if (batch.length > 0) return {
|
|
241
|
+
kind: "mailbox",
|
|
242
|
+
batch
|
|
258
243
|
};
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
244
|
+
if (context.attempt.messages.length > 0) return;
|
|
245
|
+
const turnId = await getActiveConversationTurnId(context.conversationId);
|
|
246
|
+
return turnId ? {
|
|
247
|
+
kind: "resume",
|
|
248
|
+
turnId
|
|
249
|
+
} : void 0;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* End a person's open Turn in a Thread before an agent invocation starts, as
|
|
253
|
+
* new input does on a root. Only a Turn that waits for sign-in or lost its
|
|
254
|
+
* worker can be open here: a yielded Turn resumes before new input.
|
|
255
|
+
*/
|
|
256
|
+
async function supersedeOpenPersonTurn(conversationId) {
|
|
257
|
+
if ((await listActiveMailboxTurns(conversationId)).length === 0) return;
|
|
258
|
+
const conversation = coerceThreadConversationState(await getPersistedThreadState(conversationId));
|
|
259
|
+
await hydrateConversationMessages({
|
|
260
|
+
conversation,
|
|
261
|
+
conversationId
|
|
264
262
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
await supersedeOpenMailboxTurns({
|
|
264
|
+
conversation,
|
|
265
|
+
conversationId
|
|
268
266
|
});
|
|
267
|
+
await persistThreadStateById(conversationId, { conversation });
|
|
269
268
|
}
|
|
270
269
|
// src/chat/agent-invocations/work.ts
|
|
271
270
|
const agentInvocationMailboxMetadataSchema = z.object({
|
|
@@ -436,11 +435,17 @@ async function persistTerminalLifecycle(terminal) {
|
|
|
436
435
|
});
|
|
437
436
|
await finishTurn(terminal.childConversationId, turnId, agentInvocationTurnEnd(terminal));
|
|
438
437
|
}
|
|
439
|
-
/**
|
|
438
|
+
/**
|
|
439
|
+
* Stop an invocation whose worker died, or project its terminal turn result.
|
|
440
|
+
* With `resumeLostWorker`, a Turn whose worker died resumes once from its last
|
|
441
|
+
* save, as a root Turn does. A second loss stops it.
|
|
442
|
+
*/
|
|
440
443
|
async function projectTerminalTurn(invocation, options = {}) {
|
|
444
|
+
const { resumeLostWorker, ...completeOptions } = options;
|
|
441
445
|
let turn = await getTurnRecord(invocation.childConversationId, getAgentInvocationTurnId(invocation.invocationId));
|
|
442
446
|
if (!turn) return;
|
|
443
|
-
if (turn.state === "running")
|
|
447
|
+
if (resumeLostWorker && turn.state === "running" && await pauseLostWorkerTurn(turn)) return;
|
|
448
|
+
if (turn.state === "running" || resumeLostWorker && turn.state === "paused" && lostWorkerBeforeFirstSave(turn)) {
|
|
444
449
|
turn = await failTurnRecord({
|
|
445
450
|
conversationId: turn.conversationId,
|
|
446
451
|
expectedVersion: turn.version,
|
|
@@ -454,7 +459,7 @@ async function projectTerminalTurn(invocation, options = {}) {
|
|
|
454
459
|
const failed = turn.state !== "completed" || Boolean(turn.errorMessage);
|
|
455
460
|
const blocked = turn.turnStartMessageIndex === void 0 ? void 0 : readBlockedReport(turn.piMessages.slice(turn.turnStartMessageIndex));
|
|
456
461
|
return await completeAgentInvocation({
|
|
457
|
-
...
|
|
462
|
+
...completeOptions,
|
|
458
463
|
invocationId: invocation.invocationId,
|
|
459
464
|
...failed ? {
|
|
460
465
|
errorMessage: turn.errorMessage ?? "Agent invocation failed",
|
|
@@ -469,18 +474,26 @@ async function projectTerminalTurn(invocation, options = {}) {
|
|
|
469
474
|
});
|
|
470
475
|
}
|
|
471
476
|
/**
|
|
472
|
-
* End
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
477
|
+
* End every running or paused agent invocation of a child before other work
|
|
478
|
+
* opens a Turn there, so the child has one open Turn. A saved finished Turn
|
|
479
|
+
* gives its result. Every other one fails with `errorMessage`, because the
|
|
480
|
+
* newer work does not continue its task. Each reports on its own.
|
|
476
481
|
*/
|
|
477
|
-
async function
|
|
478
|
-
|
|
479
|
-
invocationId
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
482
|
+
async function endActiveAgentInvocations(conversationId, options) {
|
|
483
|
+
for (const active of await listAgentInvocationsForConversation(conversationId, ACTIVE_AGENT_INVOCATION_STATUSES)) {
|
|
484
|
+
if (active.invocationId === options.exceptInvocationId) continue;
|
|
485
|
+
const terminal = await projectTerminalTurn(active, { reportNow: true }) ?? await completeAgentInvocation({
|
|
486
|
+
invocationId: active.invocationId,
|
|
487
|
+
errorMessage: options.errorMessage,
|
|
488
|
+
reportNow: true,
|
|
489
|
+
status: "failed"
|
|
490
|
+
});
|
|
491
|
+
if (terminal && isTerminalAgentInvocation(terminal)) {
|
|
492
|
+
await persistTerminalLifecycle(terminal);
|
|
493
|
+
await recordSubagentEnded(terminal);
|
|
494
|
+
await options.enqueueResult?.(terminal);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
484
497
|
}
|
|
485
498
|
/**
|
|
486
499
|
* End every agent invocation of a child whose last attempt lost its worker and
|
|
@@ -556,19 +569,6 @@ async function saveAgentInvocationResult(args) {
|
|
|
556
569
|
return agentInvocationTurnEnd(terminal);
|
|
557
570
|
}
|
|
558
571
|
/**
|
|
559
|
-
* Read how many parents a child Conversation has and the root Conversation's
|
|
560
|
-
* Location. A child of the root has depth 1.
|
|
561
|
-
*/
|
|
562
|
-
async function readChildDepthAndRootLocation(conversationId) {
|
|
563
|
-
const lineage = await readConversationLineage(conversationId);
|
|
564
|
-
const root = lineage[0];
|
|
565
|
-
if (!root) return { depth: 0 };
|
|
566
|
-
return root.parentConversationId ? { depth: lineage.length } : {
|
|
567
|
-
depth: lineage.length - 1,
|
|
568
|
-
location: root.location
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
572
|
* Build the invocation consumer that advances work through the shared runner.
|
|
573
573
|
* `enqueueResult` sends each terminal result to the parent mailbox. Omit it
|
|
574
574
|
* only where the parent has no mailbox, such as the local CLI.
|
|
@@ -576,7 +576,7 @@ async function readChildDepthAndRootLocation(conversationId) {
|
|
|
576
576
|
* own child agents. The default, 0, lets only the root start child agents.
|
|
577
577
|
*/
|
|
578
578
|
function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
579
|
-
const
|
|
579
|
+
const canSpawn = (options.maxAgentDepth ?? 0) > 0;
|
|
580
580
|
return async (context, invocationId) => {
|
|
581
581
|
let invocation = await getAgentInvocation(invocationId);
|
|
582
582
|
if (!invocation) throw new Error(`Agent invocation is missing for ${invocationId}`);
|
|
@@ -615,7 +615,6 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
615
615
|
let sandboxRef;
|
|
616
616
|
let history;
|
|
617
617
|
let location;
|
|
618
|
-
let canSpawn = false;
|
|
619
618
|
try {
|
|
620
619
|
if (invocation.childConversationId !== context.conversationId) throw new Error(`Agent invocation ${invocationId} belongs to ${invocation.childConversationId}, not ${context.conversationId}`);
|
|
621
620
|
if (context.destination) throw new Error(`Agent invocation conversation ${context.conversationId} must not own a provider destination`);
|
|
@@ -624,13 +623,18 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
624
623
|
await acknowledge();
|
|
625
624
|
return { status: "completed" };
|
|
626
625
|
}
|
|
627
|
-
const projected = await projectTerminalTurn(invocation);
|
|
626
|
+
const projected = await projectTerminalTurn(invocation, { resumeLostWorker: true });
|
|
628
627
|
if (projected && isTerminalAgentInvocation(projected)) {
|
|
629
628
|
await finish(projected);
|
|
630
629
|
await acknowledge();
|
|
631
630
|
return { status: "completed" };
|
|
632
631
|
}
|
|
633
|
-
|
|
632
|
+
await endActiveAgentInvocations(invocation.childConversationId, {
|
|
633
|
+
enqueueResult: options.enqueueResult,
|
|
634
|
+
errorMessage: "This task was not resumed. Newer work for this child agent started, so this task ended without a result.",
|
|
635
|
+
exceptInvocationId: invocation.invocationId
|
|
636
|
+
});
|
|
637
|
+
await supersedeOpenPersonTurn(invocation.childConversationId);
|
|
634
638
|
invocation = await markAgentInvocationRunning(invocation.invocationId) ?? invocation;
|
|
635
639
|
if (isTerminalAgentInvocation(invocation)) {
|
|
636
640
|
await finish(invocation);
|
|
@@ -644,15 +648,14 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
644
648
|
surface: "internal",
|
|
645
649
|
turnId
|
|
646
650
|
});
|
|
647
|
-
const [persisted, projection,
|
|
651
|
+
const [persisted, projection, child] = await Promise.all([
|
|
648
652
|
getPersistedThreadState(invocation.childConversationId),
|
|
649
653
|
openConversationProjection({ conversationId: invocation.childConversationId }),
|
|
650
|
-
|
|
654
|
+
getConversationStore().get({ conversationId: invocation.childConversationId })
|
|
651
655
|
]);
|
|
652
656
|
sandboxRef = getPersistedSandboxState(persisted);
|
|
653
657
|
history = agentTypeStartsWithParentHistory(invocation.agentType) && projection.messages.length === 0 ? await loadForkHistory(invocation) : projection.messages;
|
|
654
|
-
location =
|
|
655
|
-
canSpawn = tree.depth <= maxAgentDepth;
|
|
658
|
+
location = child?.location;
|
|
656
659
|
} catch (error) {
|
|
657
660
|
if (isInvocationInputCommitLost(error)) return { status: "lost_lease" };
|
|
658
661
|
if (!context.attempt.isFinalAttempt) throw error;
|
|
@@ -683,6 +686,7 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
683
686
|
source: invocation.source,
|
|
684
687
|
...location ? { location } : void 0,
|
|
685
688
|
surface: "internal",
|
|
689
|
+
deadlineAtMs: getTurnRequestDeadline()?.deadlineAtMs,
|
|
686
690
|
...stopSignal ? { signal: stopSignal } : void 0,
|
|
687
691
|
...agentInvocationRunPolicy(invocation, canSpawn),
|
|
688
692
|
state: { sandboxRef },
|
|
@@ -690,6 +694,7 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
690
694
|
drainSteeringMessages: createAgentMessageSteeringDrain(context, invocation),
|
|
691
695
|
onInputCommitted: acknowledge,
|
|
692
696
|
shouldYield: context.shouldYield,
|
|
697
|
+
checkIn: context.checkIn,
|
|
693
698
|
onSandboxRefChanged: async (nextSandboxRef) => {
|
|
694
699
|
sandboxRef = nextSandboxRef;
|
|
695
700
|
await persistThreadStateById(invocation.childConversationId, { sandboxRef });
|
|
@@ -748,4 +753,4 @@ function createAgentInvocationWorker(agentRunner, options = {}) {
|
|
|
748
753
|
return { status: "completed" };
|
|
749
754
|
};
|
|
750
755
|
}
|
|
751
|
-
export {
|
|
756
|
+
export { enqueueAgentInvocation as a, createAgentInvocationForMessage as c, endAgentInvocationsOfStoppedWork as i, createAgentInvocationFromLatest as l, createAndEnqueueAgentInvocation as n, resolveAgentInvocationId as o, endActiveAgentInvocations as r, resolveThreadTurnWork as s, createAgentInvocationWorker as t, findChildAgentConversationId as u };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import {
|
|
3
|
-
import { x as isProviderRetryError } from "./client-
|
|
4
|
-
import { i as getChatConfig } from "./config-
|
|
5
|
-
import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-
|
|
6
|
-
import {
|
|
7
|
-
import { E as startConversationWork, S as releaseConversationWork, _ as getConversationWorkState, b as recordAttemptFailure, c as clearConsumedConversationWake, d as completeConversationWork, f as countPendingConversationMessages, h as ensureConversationWake, i as beginConversationResume, m as drainConversationMailbox, o as checkInConversationWork, p as deadLetterAttempt, t as ackMessages, u as completeConversationStop, w as requestAnotherSlice, x as recordConversationRetry } from "./store-
|
|
2
|
+
import { Dt as isInvalidConversationRecordError, Et as isFinalAttempt, wt as hasConversationStop } from "./projection-CoeMNxJ4.js";
|
|
3
|
+
import { x as isProviderRetryError } from "./client-B0aAs7wC.js";
|
|
4
|
+
import { i as getChatConfig } from "./config-B9f9Lqo5.js";
|
|
5
|
+
import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-CMFhLLj4.js";
|
|
6
|
+
import { C as ConversationQueueMessageRejectedError, S as getTurnRequestDeadline } from "./background-compaction-queue-Btu2oab_.js";
|
|
7
|
+
import { E as startConversationWork, S as releaseConversationWork, _ as getConversationWorkState, b as recordAttemptFailure, c as clearConsumedConversationWake, d as completeConversationWork, f as countPendingConversationMessages, h as ensureConversationWake, i as beginConversationResume, m as drainConversationMailbox, o as checkInConversationWork, p as deadLetterAttempt, t as ackMessages, u as completeConversationStop, w as requestAnotherSlice, x as recordConversationRetry } from "./store-D0-8plWp.js";
|
|
8
8
|
// src/chat/task-execution/attempt-selection.ts
|
|
9
9
|
function selectContiguousTurnBatch(messages) {
|
|
10
10
|
const first = messages[0];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
-- Archive now applies to everyone and lives on junior_conversations. Its
|
|
2
|
+
-- legacy archived_at values are stale, so clear them first.
|
|
3
|
+
UPDATE "junior_conversations" SET "archived_at" = NULL WHERE "archived_at" IS NOT NULL;--> statement-breakpoint
|
|
4
|
+
-- A root stays archived only when every member archived it. The root actor
|
|
5
|
+
-- is a member without a participant row, and an archive always wrote one, so
|
|
6
|
+
-- an actor with no row did not archive it.
|
|
7
|
+
UPDATE "junior_conversations" AS "c"
|
|
8
|
+
SET "archived_at" = "p"."archived_at"
|
|
9
|
+
FROM (
|
|
10
|
+
SELECT "root_conversation_id", max("archived_at") AS "archived_at"
|
|
11
|
+
FROM "junior_conversation_participants"
|
|
12
|
+
GROUP BY "root_conversation_id"
|
|
13
|
+
HAVING count(*) = count("archived_at")
|
|
14
|
+
) AS "p"
|
|
15
|
+
WHERE "c"."conversation_id" = "p"."root_conversation_id"
|
|
16
|
+
AND "c"."parent_conversation_id" IS NULL
|
|
17
|
+
AND NOT EXISTS (
|
|
18
|
+
SELECT 1 FROM "junior_identities" AS "i"
|
|
19
|
+
WHERE "i"."id" = "c"."actor_identity_id"
|
|
20
|
+
AND "i"."user_id" IS NOT NULL
|
|
21
|
+
AND NOT EXISTS (
|
|
22
|
+
SELECT 1 FROM "junior_conversation_participants" AS "ap"
|
|
23
|
+
WHERE "ap"."root_conversation_id" = "c"."conversation_id"
|
|
24
|
+
AND "ap"."user_id" = "i"."user_id"
|
|
25
|
+
)
|
|
26
|
+
);--> statement-breakpoint
|
|
27
|
+
-- A child archive was already shared.
|
|
28
|
+
UPDATE "junior_conversations" SET "archived_at" = "child_archived_at" WHERE "child_archived_at" IS NOT NULL;--> statement-breakpoint
|
|
29
|
+
DROP INDEX "junior_conversation_participants_unarchived_activity_idx";--> statement-breakpoint
|
|
30
|
+
DROP INDEX "junior_conversation_participants_auto_archive_idx";--> statement-breakpoint
|
|
31
|
+
CREATE INDEX "junior_conversation_participants_auto_archive_idx" ON "junior_conversation_participants" USING btree ("user_id") WHERE "junior_conversation_participants"."auto_archive";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
-- Give each existing child the Destination row and Location of its root, as
|
|
2
|
+
-- createChild now does for a new child. A child Run then reads visibility and
|
|
3
|
+
-- Location from its own row. A child whose chain is broken or has a cycle
|
|
4
|
+
-- never joins a root here, so it keeps no Destination row and its Runs are
|
|
5
|
+
-- private with no Location. The Location follows locationFromRow:
|
|
6
|
+
-- location_json, else a Slack destination row, with the session Source
|
|
7
|
+
-- threadTs when the Location has none.
|
|
8
|
+
WITH RECURSIVE "tree" ("conversation_id", "root_id", "depth", "path") AS (
|
|
9
|
+
SELECT "conversation_id", "conversation_id", 0, ARRAY["conversation_id"]
|
|
10
|
+
FROM "junior_conversations"
|
|
11
|
+
WHERE "parent_conversation_id" IS NULL
|
|
12
|
+
UNION ALL
|
|
13
|
+
SELECT "child"."conversation_id", "tree"."root_id", "tree"."depth" + 1, "tree"."path" || "child"."conversation_id"
|
|
14
|
+
FROM "junior_conversations" "child"
|
|
15
|
+
JOIN "tree" ON "child"."parent_conversation_id" = "tree"."conversation_id"
|
|
16
|
+
WHERE "child"."conversation_id" <> ALL ("tree"."path")
|
|
17
|
+
),
|
|
18
|
+
"root_place" AS (
|
|
19
|
+
SELECT
|
|
20
|
+
"root"."conversation_id" AS "root_id",
|
|
21
|
+
"root"."destination_id",
|
|
22
|
+
CASE
|
|
23
|
+
WHEN "root"."location_json" IS NOT NULL THEN "root"."location_json"
|
|
24
|
+
WHEN "destination"."provider" = 'slack' THEN jsonb_build_object(
|
|
25
|
+
'id', "destination"."id",
|
|
26
|
+
'provider', 'slack',
|
|
27
|
+
'teamId', "destination"."provider_tenant_id",
|
|
28
|
+
'channelId', "destination"."provider_destination_id"
|
|
29
|
+
)
|
|
30
|
+
END AS "location",
|
|
31
|
+
nullif(btrim("root"."source_json"->>'threadTs'), '') AS "source_thread_ts",
|
|
32
|
+
"root"."source_json"->>'kind' AS "source_kind",
|
|
33
|
+
"root"."source_json"->>'teamId' AS "source_team_id",
|
|
34
|
+
"root"."source_json"->>'channelId' AS "source_channel_id"
|
|
35
|
+
FROM "junior_conversations" "root"
|
|
36
|
+
LEFT JOIN "junior_destinations" "destination" ON "destination"."id" = "root"."destination_id"
|
|
37
|
+
WHERE "root"."parent_conversation_id" IS NULL
|
|
38
|
+
),
|
|
39
|
+
"root_facts" AS (
|
|
40
|
+
SELECT
|
|
41
|
+
"root_id",
|
|
42
|
+
"destination_id",
|
|
43
|
+
CASE
|
|
44
|
+
WHEN "location" IS NOT NULL
|
|
45
|
+
AND "location"->>'threadTs' IS NULL
|
|
46
|
+
AND "source_kind" = 'slack'
|
|
47
|
+
AND "source_team_id" = "location"->>'teamId'
|
|
48
|
+
AND "source_channel_id" = "location"->>'channelId'
|
|
49
|
+
AND "source_thread_ts" IS NOT NULL
|
|
50
|
+
THEN "location" || jsonb_build_object('threadTs', "source_thread_ts")
|
|
51
|
+
ELSE "location"
|
|
52
|
+
END AS "location"
|
|
53
|
+
FROM "root_place"
|
|
54
|
+
)
|
|
55
|
+
UPDATE "junior_conversations" "child"
|
|
56
|
+
SET
|
|
57
|
+
"destination_id" = "root_facts"."destination_id",
|
|
58
|
+
"location_json" = "root_facts"."location"
|
|
59
|
+
FROM "tree"
|
|
60
|
+
JOIN "root_facts" ON "root_facts"."root_id" = "tree"."root_id"
|
|
61
|
+
WHERE "child"."conversation_id" = "tree"."conversation_id"
|
|
62
|
+
AND "tree"."depth" > 0
|
|
63
|
+
AND "child"."destination_id" IS NULL
|
|
64
|
+
AND "child"."location_json" IS NULL;
|