@sentry/junior 0.112.0 → 0.114.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/{agent-hooks-6MVTPKP4.js → agent-hooks-WNBUY4OB.js} +8 -8
- package/dist/api/conversations/cursor.d.ts +17 -0
- package/dist/api/conversations/detail.d.ts +40 -18
- package/dist/api/conversations/event-list.d.ts +115 -0
- package/dist/api/conversations/event-page.d.ts +18 -0
- package/dist/api/conversations/events.d.ts +6 -2
- package/dist/api/conversations/projection.d.ts +6 -1
- package/dist/api/schema/conversation.d.ts +228 -51
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -1
- package/dist/api.js +461 -139
- package/dist/app.d.ts +2 -0
- package/dist/app.js +33 -24
- package/dist/{catalog-runtime-UEO25P2J.js → catalog-runtime-6O4M6JGA.js} +5 -5
- package/dist/chat/config.d.ts +1 -1
- package/dist/chat/conversations/history.d.ts +86 -0
- package/dist/chat/conversations/projection.d.ts +20 -1
- package/dist/chat/pi/transcript.d.ts +2 -0
- package/dist/chat/services/context-budget.d.ts +7 -2
- package/dist/chat/services/context-compaction.d.ts +28 -1
- package/dist/chat/services/conversation-memory.d.ts +1 -0
- package/dist/chat/services/provider-error.d.ts +40 -0
- package/dist/chat/services/provider-retry.d.ts +3 -6
- package/dist/chat/services/turn-router.d.ts +1 -0
- package/dist/chat/task-execution/state.d.ts +2 -2
- package/dist/chat/task-execution/store.d.ts +1 -1
- package/dist/chat/tools/sandbox/edit-file.d.ts +1 -1
- package/dist/chat/tools/sandbox/text-edits.d.ts +1 -0
- package/dist/{chunk-CSS7JHEM.js → chunk-4FUEG3QY.js} +1 -1
- package/dist/{chunk-AU2JVUDF.js → chunk-5CZ7RETL.js} +1 -1
- package/dist/{chunk-SKEMI4IF.js → chunk-6QWPVTMO.js} +200 -52
- package/dist/{chunk-AWNDKI5K.js → chunk-ABPSDO6M.js} +20 -15
- package/dist/{chunk-QIALGHRN.js → chunk-FIGAF6KL.js} +34 -2
- package/dist/{chunk-TZU3R5OC.js → chunk-K2W4CK7K.js} +1 -1
- package/dist/{chunk-2FJ6WEYV.js → chunk-O4GT7LYB.js} +1 -1
- package/dist/{chunk-ZHP4KNF7.js → chunk-OSKEC4XU.js} +1 -1
- package/dist/{chunk-IV2O4HQJ.js → chunk-PM3PX42K.js} +1 -1
- package/dist/{chunk-NDQL4ESR.js → chunk-RD7EJI7H.js} +2 -2
- package/dist/{chunk-JE23YR3X.js → chunk-S4QDH23A.js} +75 -43
- package/dist/{chunk-GJG67YFS.js → chunk-TLGM5X2M.js} +2 -2
- package/dist/{chunk-VBSVNOLA.js → chunk-VNNBSKCO.js} +5 -5
- package/dist/{chunk-4EJO4HIC.js → chunk-W6RDUAO3.js} +1 -1
- package/dist/{chunk-GR4IB6OQ.js → chunk-WV4UJBAS.js} +431 -96
- package/dist/{chunk-66IP6WED.js → chunk-XLFBQJUO.js} +4 -4
- package/dist/{chunk-X3SP5RDW.js → chunk-YU6PO42Q.js} +1 -1
- package/dist/{chunk-PK4ETCUQ.js → chunk-ZGXH3REA.js} +226 -215
- package/dist/cli/chat.js +19 -19
- package/dist/cli/check.js +6 -6
- package/dist/cli/plugins.js +11 -11
- package/dist/cli/snapshot-warmup.js +8 -8
- package/dist/cli/upgrade.js +5 -5
- package/dist/{db-P5H5RVQV.js → db-4VLP7KBF.js} +5 -5
- package/dist/instrumentation.js +2 -2
- package/dist/nitro.js +2 -2
- package/dist/{runner-B4ZDUO3R.js → runner-IPXLWQOF.js} +12 -13
- package/dist/{skills-GWTOZ3XV.js → skills-QCNZISNF.js} +6 -6
- package/dist/{validation-QFIC6XH6.js → validation-I2BW3UHD.js} +6 -6
- package/dist/version.js +1 -1
- package/package.json +6 -6
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-MU6HHZEN.js";
|
|
5
5
|
import {
|
|
6
6
|
getStateAdapter
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YU6PO42Q.js";
|
|
8
8
|
import {
|
|
9
9
|
contextProvenance,
|
|
10
10
|
createSqlConversationEventStore,
|
|
@@ -15,20 +15,16 @@ import {
|
|
|
15
15
|
instructionProvenanceFor,
|
|
16
16
|
sanitizePostgresJson,
|
|
17
17
|
withConversationEventLock
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-FIGAF6KL.js";
|
|
19
19
|
import {
|
|
20
20
|
sleep
|
|
21
21
|
} from "./chunk-4ZNGQH7C.js";
|
|
22
22
|
import {
|
|
23
23
|
botConfig,
|
|
24
24
|
escapeXml,
|
|
25
|
-
getPiMessageRole,
|
|
26
25
|
resolveGatewayModel,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
stripRuntimeTurnContext,
|
|
30
|
-
trimTrailingAssistantMessages
|
|
31
|
-
} from "./chunk-PK4ETCUQ.js";
|
|
26
|
+
unwrapCurrentInstruction
|
|
27
|
+
} from "./chunk-ZGXH3REA.js";
|
|
32
28
|
import {
|
|
33
29
|
toStoredSlackActor
|
|
34
30
|
} from "./chunk-C4MZ3GP5.js";
|
|
@@ -37,7 +33,7 @@ import {
|
|
|
37
33
|
logException,
|
|
38
34
|
logWarn,
|
|
39
35
|
setSpanAttributes
|
|
40
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-4FUEG3QY.js";
|
|
41
37
|
import {
|
|
42
38
|
isRecord,
|
|
43
39
|
parseSlackMessageTs,
|
|
@@ -45,6 +41,111 @@ import {
|
|
|
45
41
|
toOptionalString
|
|
46
42
|
} from "./chunk-42WRQLJ6.js";
|
|
47
43
|
|
|
44
|
+
// src/chat/turn-context-tag.ts
|
|
45
|
+
var TURN_CONTEXT_TAG = "runtime-turn-context";
|
|
46
|
+
|
|
47
|
+
// src/chat/pi/transcript.ts
|
|
48
|
+
var RUNTIME_TURN_CONTEXT_START = `<${TURN_CONTEXT_TAG}>`;
|
|
49
|
+
function userMessageContent(message) {
|
|
50
|
+
const record = message;
|
|
51
|
+
return record.role === "user" && Array.isArray(record.content) ? record.content : void 0;
|
|
52
|
+
}
|
|
53
|
+
function isRuntimeTurnContextPart(part) {
|
|
54
|
+
return part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.text.startsWith(RUNTIME_TURN_CONTEXT_START);
|
|
55
|
+
}
|
|
56
|
+
var EMBEDDED_THREAD_CONTEXT_TAGS = [
|
|
57
|
+
"recent-thread-messages",
|
|
58
|
+
"thread-compactions",
|
|
59
|
+
"thread-transcript",
|
|
60
|
+
"thread-background"
|
|
61
|
+
];
|
|
62
|
+
var EMBEDDED_THREAD_CONTEXT_PATTERN = new RegExp(
|
|
63
|
+
`<(${EMBEDDED_THREAD_CONTEXT_TAGS.join("|")})(?:\\s[^>]*)?>[\\s\\S]*?</\\1>`,
|
|
64
|
+
"g"
|
|
65
|
+
);
|
|
66
|
+
function isAssistantMessage(value) {
|
|
67
|
+
return typeof value === "object" && value !== null && value.role === "assistant";
|
|
68
|
+
}
|
|
69
|
+
function isToolResultMessage(value) {
|
|
70
|
+
return typeof value === "object" && value !== null && value.role === "toolResult";
|
|
71
|
+
}
|
|
72
|
+
function isToolResultError(result) {
|
|
73
|
+
if (!result || typeof result !== "object") return false;
|
|
74
|
+
return Boolean(result.isError);
|
|
75
|
+
}
|
|
76
|
+
function normalizeToolNameFromResult(result) {
|
|
77
|
+
if (!result || typeof result !== "object") return void 0;
|
|
78
|
+
const record = result;
|
|
79
|
+
if (typeof record.toolName === "string" && record.toolName.length > 0) {
|
|
80
|
+
return record.toolName;
|
|
81
|
+
}
|
|
82
|
+
if (typeof record.name === "string" && record.name.length > 0) {
|
|
83
|
+
return record.name;
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function getPiMessageRole(value) {
|
|
88
|
+
if (!value || typeof value !== "object") {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
const role = value.role;
|
|
92
|
+
return typeof role === "string" ? role : void 0;
|
|
93
|
+
}
|
|
94
|
+
function isContinuablePiBoundary(messages) {
|
|
95
|
+
const lastRole = getPiMessageRole(messages.at(-1));
|
|
96
|
+
return lastRole === "user" || lastRole === "toolResult";
|
|
97
|
+
}
|
|
98
|
+
function extractAssistantText(message) {
|
|
99
|
+
const content = message.content ?? [];
|
|
100
|
+
return content.filter(
|
|
101
|
+
(part) => part.type === "text" && typeof part.text === "string"
|
|
102
|
+
).map((part) => part.text).join("\n");
|
|
103
|
+
}
|
|
104
|
+
function getTerminalAssistantMessages(messages) {
|
|
105
|
+
let lastNonAssistantIndex = -1;
|
|
106
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
107
|
+
if (!isAssistantMessage(messages[index])) {
|
|
108
|
+
lastNonAssistantIndex = index;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return messages.slice(lastNonAssistantIndex + 1).filter(isAssistantMessage);
|
|
113
|
+
}
|
|
114
|
+
function trimTrailingAssistantMessages(messages) {
|
|
115
|
+
let end = messages.length;
|
|
116
|
+
while (end > 0 && getPiMessageRole(messages[end - 1]) === "assistant") {
|
|
117
|
+
end -= 1;
|
|
118
|
+
}
|
|
119
|
+
return end === messages.length ? [...messages] : messages.slice(0, end);
|
|
120
|
+
}
|
|
121
|
+
function hasRuntimeTurnContext(messages) {
|
|
122
|
+
return messages.some(
|
|
123
|
+
(message) => userMessageContent(message)?.some(isRuntimeTurnContextPart)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function retainRuntimeTurnContext(messages) {
|
|
127
|
+
return messages.flatMap((message) => {
|
|
128
|
+
const runtimeContent = userMessageContent(message)?.filter(isRuntimeTurnContextPart) ?? [];
|
|
129
|
+
return runtimeContent.length > 0 ? [{ ...message, content: runtimeContent }] : [];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function instructionTextForProjection(text) {
|
|
133
|
+
const withoutContext = text.replace(EMBEDDED_THREAD_CONTEXT_PATTERN, "").trim();
|
|
134
|
+
return unwrapCurrentInstruction(withoutContext) ?? withoutContext;
|
|
135
|
+
}
|
|
136
|
+
function stripRuntimeTurnContext(messages) {
|
|
137
|
+
return messages.flatMap((message) => {
|
|
138
|
+
const content = userMessageContent(message);
|
|
139
|
+
if (!content) return [message];
|
|
140
|
+
const nextContent = content.filter(
|
|
141
|
+
(part) => !isRuntimeTurnContextPart(part)
|
|
142
|
+
);
|
|
143
|
+
if (nextContent.length === content.length) return [message];
|
|
144
|
+
if (nextContent.length === 0) return [];
|
|
145
|
+
return [{ ...message, content: nextContent }];
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
48
149
|
// src/chat/conversations/projection.ts
|
|
49
150
|
import { isDeepStrictEqual } from "util";
|
|
50
151
|
|
|
@@ -349,6 +450,36 @@ async function recordAuthorizationCompleted(args) {
|
|
|
349
450
|
}
|
|
350
451
|
]);
|
|
351
452
|
}
|
|
453
|
+
async function loadTurnRoute(args) {
|
|
454
|
+
const event = await getConversationEventStore().loadByIdempotencyKey(
|
|
455
|
+
args.conversationId,
|
|
456
|
+
`turn:${args.turnId}:routed`
|
|
457
|
+
);
|
|
458
|
+
if (!event) {
|
|
459
|
+
return void 0;
|
|
460
|
+
}
|
|
461
|
+
if (event.data.type !== "turn_routed" || event.data.turnId !== args.turnId) {
|
|
462
|
+
throw new Error(`Turn route key for "${args.turnId}" has invalid data`);
|
|
463
|
+
}
|
|
464
|
+
return event.data;
|
|
465
|
+
}
|
|
466
|
+
async function recordTurnRoute(args) {
|
|
467
|
+
await getConversationEventStore().append(args.conversationId, [
|
|
468
|
+
{
|
|
469
|
+
idempotencyKey: `turn:${args.turnId}:routed`,
|
|
470
|
+
createdAtMs: Date.now(),
|
|
471
|
+
data: {
|
|
472
|
+
type: "turn_routed",
|
|
473
|
+
turnId: args.turnId,
|
|
474
|
+
modelProfile: args.modelProfile,
|
|
475
|
+
modelId: args.modelId,
|
|
476
|
+
reasoningLevel: args.reasoningLevel,
|
|
477
|
+
...args.confidence !== void 0 ? { confidence: args.confidence } : {},
|
|
478
|
+
source: args.source
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
]);
|
|
482
|
+
}
|
|
352
483
|
async function recordToolExecutionStarted(args) {
|
|
353
484
|
await getConversationEventStore().append(args.conversationId, [
|
|
354
485
|
{
|
|
@@ -1033,13 +1164,9 @@ function addDurationMs(prior, current) {
|
|
|
1033
1164
|
}, void 0);
|
|
1034
1165
|
return total;
|
|
1035
1166
|
}
|
|
1036
|
-
function isContinuableBoundary(messages) {
|
|
1037
|
-
const lastRole = getPiMessageRole(messages.at(-1));
|
|
1038
|
-
return lastRole === "user" || lastRole === "toolResult";
|
|
1039
|
-
}
|
|
1040
1167
|
function resumableBoundary(messages, fallbackMessages) {
|
|
1041
1168
|
const current = trimTrailingAssistantMessages(messages);
|
|
1042
|
-
if (current.length > 0 &&
|
|
1169
|
+
if (current.length > 0 && isContinuablePiBoundary(current)) {
|
|
1043
1170
|
return current;
|
|
1044
1171
|
}
|
|
1045
1172
|
return trimTrailingAssistantMessages(fallbackMessages ?? []);
|
|
@@ -1059,7 +1186,7 @@ async function loadTurnSessionRecord(ctx) {
|
|
|
1059
1186
|
};
|
|
1060
1187
|
}
|
|
1061
1188
|
async function persistRunningSessionRecord(args) {
|
|
1062
|
-
if (args.messages.length === 0 || !
|
|
1189
|
+
if (args.messages.length === 0 || !isContinuablePiBoundary(args.messages)) {
|
|
1063
1190
|
return false;
|
|
1064
1191
|
}
|
|
1065
1192
|
try {
|
|
@@ -1184,7 +1311,7 @@ async function persistAuthPauseSessionRecord(args) {
|
|
|
1184
1311
|
args.messages,
|
|
1185
1312
|
latestSessionRecord?.piMessages
|
|
1186
1313
|
);
|
|
1187
|
-
if (piMessages.length > 0 && !
|
|
1314
|
+
if (piMessages.length > 0 && !isContinuablePiBoundary(piMessages)) {
|
|
1188
1315
|
return void 0;
|
|
1189
1316
|
}
|
|
1190
1317
|
return await upsertAgentTurnSessionRecord({
|
|
@@ -1241,7 +1368,7 @@ async function persistContinuationSessionRecord(args) {
|
|
|
1241
1368
|
args.messages,
|
|
1242
1369
|
latestSessionRecord?.piMessages
|
|
1243
1370
|
);
|
|
1244
|
-
if (piMessages.length === 0 || !
|
|
1371
|
+
if (piMessages.length === 0 || !isContinuablePiBoundary(piMessages)) {
|
|
1245
1372
|
return void 0;
|
|
1246
1373
|
}
|
|
1247
1374
|
const cumulativeDurationMs = addDurationMs(
|
|
@@ -1322,17 +1449,14 @@ async function persistContinuationSessionRecord(args) {
|
|
|
1322
1449
|
}
|
|
1323
1450
|
async function persistYieldSessionRecord(args) {
|
|
1324
1451
|
try {
|
|
1452
|
+
const piMessages = [...args.messages];
|
|
1453
|
+
if (piMessages.length === 0 || !isContinuablePiBoundary(piMessages)) {
|
|
1454
|
+
return void 0;
|
|
1455
|
+
}
|
|
1325
1456
|
const latestSessionRecord = await getAgentTurnSessionRecord(
|
|
1326
1457
|
args.conversationId,
|
|
1327
1458
|
args.sessionId
|
|
1328
1459
|
);
|
|
1329
|
-
const piMessages = resumableBoundary(
|
|
1330
|
-
args.messages,
|
|
1331
|
-
latestSessionRecord?.piMessages
|
|
1332
|
-
);
|
|
1333
|
-
if (piMessages.length === 0 || !isContinuableBoundary(piMessages)) {
|
|
1334
|
-
return void 0;
|
|
1335
|
-
}
|
|
1336
1460
|
return await upsertAgentTurnSessionRecord({
|
|
1337
1461
|
...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
|
|
1338
1462
|
conversationId: args.conversationId,
|
|
@@ -1493,11 +1617,10 @@ function buildConversationStatePatch(conversation) {
|
|
|
1493
1617
|
}
|
|
1494
1618
|
|
|
1495
1619
|
// src/chat/services/context-budget.ts
|
|
1496
|
-
var
|
|
1497
|
-
var
|
|
1620
|
+
var COMPACTION_TRIGGER_RATIO = 0.9;
|
|
1621
|
+
var CONTEXT_INPUT_LIMIT_RATIO = 0.95;
|
|
1498
1622
|
var COMPACTION_TARGET_RATIO = 0.8;
|
|
1499
1623
|
var FALLBACK_CONTEXT_WINDOW_TOKENS = 4e5;
|
|
1500
|
-
var FALLBACK_MAX_OUTPUT_TOKENS = 128e3;
|
|
1501
1624
|
function positiveInteger(value, fallback) {
|
|
1502
1625
|
return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
1503
1626
|
}
|
|
@@ -1509,36 +1632,43 @@ function calculateContextCompactionTriggerTokens(model) {
|
|
|
1509
1632
|
model.contextWindow,
|
|
1510
1633
|
FALLBACK_CONTEXT_WINDOW_TOKENS
|
|
1511
1634
|
);
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
Math.floor(contextWindow * COMPACTION_OUTPUT_RESERVE_RATIO)
|
|
1519
|
-
);
|
|
1520
|
-
const usableInputTokens = Math.max(1, contextWindow - outputReserve);
|
|
1521
|
-
return Math.max(
|
|
1522
|
-
1,
|
|
1523
|
-
Math.floor(usableInputTokens * COMPACTION_TRIGGER_INPUT_RATIO)
|
|
1635
|
+
return Math.max(1, Math.floor(contextWindow * COMPACTION_TRIGGER_RATIO));
|
|
1636
|
+
}
|
|
1637
|
+
function calculateContextInputLimitTokens(model) {
|
|
1638
|
+
const contextWindow = positiveInteger(
|
|
1639
|
+
model.contextWindow,
|
|
1640
|
+
FALLBACK_CONTEXT_WINDOW_TOKENS
|
|
1524
1641
|
);
|
|
1642
|
+
return Math.max(1, Math.floor(contextWindow * CONTEXT_INPUT_LIMIT_RATIO));
|
|
1525
1643
|
}
|
|
1526
1644
|
function calculateContextCompactionTargetTokens(triggerTokens) {
|
|
1527
1645
|
return Math.max(1, Math.floor(triggerTokens * COMPACTION_TARGET_RATIO));
|
|
1528
1646
|
}
|
|
1529
|
-
function
|
|
1530
|
-
const model = resolveGatewayModel(
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1647
|
+
function getModelContextBudget(modelId) {
|
|
1648
|
+
const model = resolveGatewayModel(modelId);
|
|
1649
|
+
const advertisedContextWindow = positiveInteger(
|
|
1650
|
+
model.contextWindow,
|
|
1651
|
+
FALLBACK_CONTEXT_WINDOW_TOKENS
|
|
1652
|
+
);
|
|
1653
|
+
return {
|
|
1654
|
+
contextWindow: Math.min(
|
|
1655
|
+
botConfig.contextWindowTokens,
|
|
1656
|
+
advertisedContextWindow
|
|
1657
|
+
)
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
function getAgentContextCompactionTriggerTokens(modelId) {
|
|
1661
|
+
return calculateContextCompactionTriggerTokens(
|
|
1662
|
+
getModelContextBudget(modelId)
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
function getAgentContextInputLimitTokens(modelId) {
|
|
1666
|
+
return calculateContextInputLimitTokens(getModelContextBudget(modelId));
|
|
1535
1667
|
}
|
|
1536
1668
|
function getConversationContextCompactionTriggerTokens() {
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
maxTokens: model.maxTokens
|
|
1541
|
-
});
|
|
1669
|
+
return calculateContextCompactionTriggerTokens(
|
|
1670
|
+
getModelContextBudget(botConfig.fastModelId)
|
|
1671
|
+
);
|
|
1542
1672
|
}
|
|
1543
1673
|
|
|
1544
1674
|
// src/chat/services/conversation-memory.ts
|
|
@@ -1551,7 +1681,7 @@ function generateConversationId(prefix) {
|
|
|
1551
1681
|
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
1552
1682
|
}
|
|
1553
1683
|
function normalizeConversationText(text) {
|
|
1554
|
-
return text.
|
|
1684
|
+
return text.replace(/\r\n?/g, "\n").trim();
|
|
1555
1685
|
}
|
|
1556
1686
|
function buildImageContextSuffix(message, conversation) {
|
|
1557
1687
|
const byFileId = conversation?.vision.byFileId;
|
|
@@ -1567,6 +1697,7 @@ function buildImageContextSuffix(message, conversation) {
|
|
|
1567
1697
|
}
|
|
1568
1698
|
function renderConversationMessageLine(message, conversation) {
|
|
1569
1699
|
const displayName = conversationAuthorDisplayName(message);
|
|
1700
|
+
const text = message.text.replace(/\s+/g, " ").slice(0, CONTEXT_MAX_MESSAGE_CHARS);
|
|
1570
1701
|
const markers = [];
|
|
1571
1702
|
if (message.meta?.replied === false) {
|
|
1572
1703
|
markers.push(
|
|
@@ -1578,7 +1709,7 @@ function renderConversationMessageLine(message, conversation) {
|
|
|
1578
1709
|
}
|
|
1579
1710
|
const markerSuffix = markers.length > 0 ? ` (${markers.join("; ")})` : "";
|
|
1580
1711
|
const imageContext = buildImageContextSuffix(message, conversation);
|
|
1581
|
-
return `[${message.role}] ${displayName}: ${
|
|
1712
|
+
return `[${message.role}] ${displayName}: ${text}${imageContext}${markerSuffix}`;
|
|
1582
1713
|
}
|
|
1583
1714
|
function conversationAuthorDisplayName(message) {
|
|
1584
1715
|
const author = message.author;
|
|
@@ -2533,6 +2664,20 @@ function isPendingAuthLatestRequest(conversation, pendingAuth) {
|
|
|
2533
2664
|
}
|
|
2534
2665
|
|
|
2535
2666
|
export {
|
|
2667
|
+
TURN_CONTEXT_TAG,
|
|
2668
|
+
isAssistantMessage,
|
|
2669
|
+
isToolResultMessage,
|
|
2670
|
+
isToolResultError,
|
|
2671
|
+
normalizeToolNameFromResult,
|
|
2672
|
+
getPiMessageRole,
|
|
2673
|
+
isContinuablePiBoundary,
|
|
2674
|
+
extractAssistantText,
|
|
2675
|
+
getTerminalAssistantMessages,
|
|
2676
|
+
trimTrailingAssistantMessages,
|
|
2677
|
+
hasRuntimeTurnContext,
|
|
2678
|
+
retainRuntimeTurnContext,
|
|
2679
|
+
instructionTextForProjection,
|
|
2680
|
+
stripRuntimeTurnContext,
|
|
2536
2681
|
loadProjection,
|
|
2537
2682
|
loadConversationProjection,
|
|
2538
2683
|
openConversationProjection,
|
|
@@ -2541,6 +2686,8 @@ export {
|
|
|
2541
2686
|
recordMcpProviderConnected,
|
|
2542
2687
|
recordAuthorizationRequested,
|
|
2543
2688
|
recordAuthorizationCompleted,
|
|
2689
|
+
loadTurnRoute,
|
|
2690
|
+
recordTurnRoute,
|
|
2544
2691
|
recordToolExecutionStarted,
|
|
2545
2692
|
buildDeterministicTurnId,
|
|
2546
2693
|
buildDeterministicAssistantMessageId,
|
|
@@ -2583,6 +2730,7 @@ export {
|
|
|
2583
2730
|
persistConversationMessageSummaries,
|
|
2584
2731
|
estimateTextTokens,
|
|
2585
2732
|
getAgentContextCompactionTriggerTokens,
|
|
2733
|
+
getAgentContextInputLimitTokens,
|
|
2586
2734
|
normalizeConversationText,
|
|
2587
2735
|
updateConversationStats,
|
|
2588
2736
|
upsertConversationMessage,
|
|
@@ -9,36 +9,39 @@ import {
|
|
|
9
9
|
getAgentTurnSessionRecord,
|
|
10
10
|
getInterruptionMarker,
|
|
11
11
|
getPersistedThreadState,
|
|
12
|
+
getPiMessageRole,
|
|
12
13
|
hydrateConversationMessages,
|
|
14
|
+
instructionTextForProjection,
|
|
15
|
+
isToolResultError,
|
|
16
|
+
isToolResultMessage,
|
|
13
17
|
markConversationMessage,
|
|
14
18
|
markTurnCompleted,
|
|
15
19
|
mergeArtifactsState,
|
|
20
|
+
normalizeToolNameFromResult,
|
|
21
|
+
stripRuntimeTurnContext,
|
|
16
22
|
updateConversationStats
|
|
17
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-6QWPVTMO.js";
|
|
18
24
|
import {
|
|
19
25
|
createPluginEmbedder,
|
|
20
26
|
createPluginLogger,
|
|
21
27
|
createPluginModel,
|
|
22
28
|
createPluginState,
|
|
23
29
|
getPlugins
|
|
24
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-VNNBSKCO.js";
|
|
25
31
|
import {
|
|
26
32
|
getStateAdapter
|
|
27
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-YU6PO42Q.js";
|
|
28
34
|
import {
|
|
29
35
|
getDb
|
|
30
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-FIGAF6KL.js";
|
|
31
37
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
normalizeToolNameFromResult,
|
|
37
|
-
stripRuntimeTurnContext
|
|
38
|
-
} from "./chunk-PK4ETCUQ.js";
|
|
38
|
+
ProviderError,
|
|
39
|
+
getProviderErrorAttributes,
|
|
40
|
+
getProviderErrorUserMessage
|
|
41
|
+
} from "./chunk-ZGXH3REA.js";
|
|
39
42
|
import {
|
|
40
43
|
buildTurnFailureResponse
|
|
41
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-4FUEG3QY.js";
|
|
42
45
|
import {
|
|
43
46
|
parseSlackMessageTs
|
|
44
47
|
} from "./chunk-42WRQLJ6.js";
|
|
@@ -70,7 +73,7 @@ function getFailureCapture(reply) {
|
|
|
70
73
|
error: reply.diagnostics.providerError ?? new Error(
|
|
71
74
|
reply.diagnostics.errorMessage ?? "Provider error without explicit message"
|
|
72
75
|
),
|
|
73
|
-
attributes: {},
|
|
76
|
+
attributes: reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorAttributes(reply.diagnostics.providerError) : {},
|
|
74
77
|
body: "Agent turn failed with provider error"
|
|
75
78
|
};
|
|
76
79
|
}
|
|
@@ -98,7 +101,7 @@ function getAgentTurnDiagnosticsAttributes(reply) {
|
|
|
98
101
|
...reply.diagnostics.stopReason ? {
|
|
99
102
|
"gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
|
|
100
103
|
} : {},
|
|
101
|
-
...reply.diagnostics.errorMessage ? { "exception.message": reply.diagnostics.errorMessage } : {}
|
|
104
|
+
...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : {}
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
107
|
function finalizeFailedTurnReplyWithEvent(args) {
|
|
@@ -121,11 +124,13 @@ function finalizeFailedTurnReplyWithEvent(args) {
|
|
|
121
124
|
capture.eventName
|
|
122
125
|
);
|
|
123
126
|
const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
|
|
127
|
+
const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
|
|
128
|
+
const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
|
|
124
129
|
return {
|
|
125
130
|
eventId,
|
|
126
131
|
reply: {
|
|
127
132
|
...args.reply,
|
|
128
|
-
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` :
|
|
133
|
+
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
|
|
129
134
|
}
|
|
130
135
|
};
|
|
131
136
|
}
|
|
@@ -6,15 +6,16 @@ import {
|
|
|
6
6
|
juniorUsers
|
|
7
7
|
} from "./chunk-JQFJO5WH.js";
|
|
8
8
|
import {
|
|
9
|
+
TURN_REASONING_LEVELS,
|
|
9
10
|
getChatConfig,
|
|
10
11
|
modelProfileSchema
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZGXH3REA.js";
|
|
12
13
|
import {
|
|
13
14
|
juniorDestinations
|
|
14
15
|
} from "./chunk-VFUK3X5B.js";
|
|
15
16
|
import {
|
|
16
17
|
normalizeIdentityEmail
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-4FUEG3QY.js";
|
|
18
19
|
import {
|
|
19
20
|
parseSlackChannelReferenceId,
|
|
20
21
|
parseSlackTeamId
|
|
@@ -809,6 +810,16 @@ var replacementHistoryMessageSchema = conversationMessageDataSchema.extend({
|
|
|
809
810
|
sourceEventSeq: z2.number().int().nonnegative().optional()
|
|
810
811
|
});
|
|
811
812
|
var replacementHistorySchema = z2.array(replacementHistoryMessageSchema);
|
|
813
|
+
var compactionDetailsSchema = z2.object({
|
|
814
|
+
reason: z2.literal("capacity"),
|
|
815
|
+
estimatedInputTokens: z2.number().int().nonnegative(),
|
|
816
|
+
replacementInputTokens: z2.number().int().nonnegative().optional(),
|
|
817
|
+
triggerTokens: z2.number().int().nonnegative(),
|
|
818
|
+
inputLimitTokens: z2.number().int().positive(),
|
|
819
|
+
inputMessageCount: z2.number().int().nonnegative(),
|
|
820
|
+
retainedMessageCount: z2.number().int().nonnegative(),
|
|
821
|
+
summaryChars: z2.number().int().nonnegative()
|
|
822
|
+
}).strict();
|
|
812
823
|
var historyReplacementEventDataSchema = z2.discriminatedUnion("type", [
|
|
813
824
|
z2.object({
|
|
814
825
|
type: z2.literal("handoff"),
|
|
@@ -822,6 +833,7 @@ var historyReplacementEventDataSchema = z2.discriminatedUnion("type", [
|
|
|
822
833
|
type: z2.literal("compaction"),
|
|
823
834
|
modelProfile: modelProfileSchema,
|
|
824
835
|
modelId: z2.string().min(1),
|
|
836
|
+
details: compactionDetailsSchema.optional(),
|
|
825
837
|
replacementHistory: replacementHistorySchema
|
|
826
838
|
}).strict()
|
|
827
839
|
]);
|
|
@@ -919,6 +931,15 @@ var turnStartedEventDataSchema = z2.object({
|
|
|
919
931
|
(data) => new Set(data.inputMessageIds).size === data.inputMessageIds.length,
|
|
920
932
|
"turn input message ids must be unique"
|
|
921
933
|
);
|
|
934
|
+
var turnRoutedEventDataSchema = z2.object({
|
|
935
|
+
type: z2.literal("turn_routed"),
|
|
936
|
+
turnId: z2.string().min(1),
|
|
937
|
+
modelProfile: modelProfileSchema,
|
|
938
|
+
modelId: z2.string().min(1),
|
|
939
|
+
reasoningLevel: z2.enum(TURN_REASONING_LEVELS),
|
|
940
|
+
confidence: z2.number().min(0).max(1).optional(),
|
|
941
|
+
source: z2.enum(["configured", "inherited", "router"])
|
|
942
|
+
}).strict();
|
|
922
943
|
var turnCompletedEventDataSchema = z2.object({
|
|
923
944
|
type: z2.literal("turn_completed"),
|
|
924
945
|
turnId: z2.string().min(1),
|
|
@@ -960,6 +981,7 @@ var appendableConversationEventDataSchema = z2.union([
|
|
|
960
981
|
messageHandledEventDataSchema,
|
|
961
982
|
messagesSummarizedEventDataSchema,
|
|
962
983
|
turnStartedEventDataSchema,
|
|
984
|
+
turnRoutedEventDataSchema,
|
|
963
985
|
turnCompletedEventDataSchema,
|
|
964
986
|
turnFailedEventDataSchema,
|
|
965
987
|
subagentStartedEventDataSchema,
|
|
@@ -981,6 +1003,7 @@ var knownConversationEventTypeSchema = z2.enum([
|
|
|
981
1003
|
"message_handled",
|
|
982
1004
|
"messages_summarized",
|
|
983
1005
|
"turn_started",
|
|
1006
|
+
"turn_routed",
|
|
984
1007
|
"turn_completed",
|
|
985
1008
|
"turn_failed",
|
|
986
1009
|
"subagent_started",
|
|
@@ -1219,6 +1242,15 @@ var SqlConversationEventStore = class {
|
|
|
1219
1242
|
).orderBy(asc2(juniorConversationEvents.seq));
|
|
1220
1243
|
return rows.map(eventFromRow);
|
|
1221
1244
|
}
|
|
1245
|
+
async loadByIdempotencyKey(conversationId, idempotencyKey) {
|
|
1246
|
+
const [row] = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1247
|
+
and3(
|
|
1248
|
+
eq3(juniorConversationEvents.conversationId, conversationId),
|
|
1249
|
+
eq3(juniorConversationEvents.idempotencyKey, idempotencyKey)
|
|
1250
|
+
)
|
|
1251
|
+
).limit(1);
|
|
1252
|
+
return row ? eventFromRow(row) : void 0;
|
|
1253
|
+
}
|
|
1222
1254
|
async loadHistoryContaining(conversationId, seq, throughSeq) {
|
|
1223
1255
|
const [boundary] = await this.executor.db().select({ historyVersion: juniorConversationEvents.historyVersion }).from(juniorConversationEvents).where(
|
|
1224
1256
|
and3(
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-4ZNGQH7C.js";
|
|
4
4
|
import {
|
|
5
5
|
getSlackBotToken
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZGXH3REA.js";
|
|
7
7
|
import {
|
|
8
8
|
logWarn,
|
|
9
9
|
setSpanAttributes,
|
|
10
10
|
setSpanStatus,
|
|
11
11
|
withSpan
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4FUEG3QY.js";
|
|
13
13
|
import {
|
|
14
14
|
parseSlackChannelReferenceId
|
|
15
15
|
} from "./chunk-42WRQLJ6.js";
|