@sentry/junior 0.94.0 → 0.95.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-ZG7IDOIN.js → agent-hooks-FTQ5EGPO.js} +9 -10
- package/dist/api/people/list.js +7 -7
- package/dist/api/people/profile.js +7 -7
- package/dist/api/people/shared.d.ts +2 -2
- package/dist/api-reference.d.ts +1 -1
- package/dist/app.js +427 -196
- package/dist/{catalog-runtime-NZHMSMYC.js → catalog-runtime-2D7IVKUT.js} +3 -3
- package/dist/chat/advisor-request.d.ts +4 -0
- package/dist/chat/agent/request.d.ts +2 -0
- package/dist/chat/agent/resume.d.ts +2 -0
- package/dist/chat/conversations/history.d.ts +128 -0
- package/dist/chat/conversations/legacy-import.d.ts +38 -0
- package/dist/chat/conversations/messages.d.ts +39 -0
- package/dist/chat/conversations/projection.d.ts +94 -0
- package/dist/chat/conversations/retention.d.ts +36 -0
- package/dist/chat/conversations/sql/conversation-row.d.ts +14 -0
- package/dist/chat/conversations/sql/history.d.ts +4 -0
- package/dist/chat/conversations/sql/legacy-history-import.d.ts +55 -0
- package/dist/chat/conversations/sql/messages.d.ts +4 -0
- package/dist/chat/conversations/sql/migrations.d.ts +14 -3
- package/dist/chat/conversations/sql/purge.d.ts +53 -0
- package/dist/chat/conversations/sql/store.d.ts +7 -2
- package/dist/chat/conversations/store.d.ts +19 -0
- package/dist/chat/conversations/visible-compactions.d.ts +11 -0
- package/dist/chat/conversations/visible-messages.d.ts +47 -0
- package/dist/chat/db.d.ts +12 -1
- package/dist/chat/identities/sql.d.ts +1 -1
- package/dist/chat/logging.d.ts +2 -1
- package/dist/chat/resource-events/store.d.ts +2 -1
- package/dist/chat/runtime/reply-executor.d.ts +8 -0
- package/dist/chat/runtime/thread-state.d.ts +2 -0
- package/dist/chat/sandbox/resources.d.ts +4 -0
- package/dist/chat/services/mcp-auth-orchestration.d.ts +8 -0
- package/dist/chat/services/plugin-auth-orchestration.d.ts +12 -0
- package/dist/chat/services/turn-session-record.d.ts +14 -2
- package/dist/chat/sleep.d.ts +2 -0
- package/dist/chat/state/conversation.d.ts +7 -4
- package/dist/chat/state/session-log.d.ts +23 -1
- package/dist/chat/state/turn-session.d.ts +6 -0
- package/dist/chat/tool-support/private-trace-result.d.ts +4 -0
- package/dist/chat/tool-support/zod-tool.d.ts +1 -0
- package/dist/chat/tools/advisor/tool.d.ts +9 -4
- package/dist/chat/tools/definition.d.ts +2 -0
- package/dist/chat/tools/execution/tool-error-handler.d.ts +2 -2
- package/dist/chat/tools/system-time.d.ts +8 -0
- package/dist/chat/xml.d.ts +2 -0
- package/dist/{chunk-NYWPISSO.js → chunk-2XXEKR44.js} +1 -1
- package/dist/{chunk-QGEWC27H.js → chunk-5XMNOD3S.js} +5 -7
- package/dist/{chunk-NFXSLTYG.js → chunk-6ONME5IG.js} +864 -62
- package/dist/{chunk-LFLTJQVR.js → chunk-7FBGKXPE.js} +4 -0
- package/dist/{chunk-MC4ZZE4Q.js → chunk-AYP4ERVZ.js} +1 -1
- package/dist/{chunk-GHGPTPBL.js → chunk-B7PUBQQM.js} +1 -1
- package/dist/chunk-CM5EZD5F.js +17 -0
- package/dist/chunk-CRRBJ3JP.js +1037 -0
- package/dist/{chunk-G3E7SCME.js → chunk-CZEX6KIQ.js} +23 -0
- package/dist/{chunk-TNUUATT7.js → chunk-E3E2XNCN.js} +2 -2
- package/dist/{chunk-LNCREA5Z.js → chunk-EKNJM5IG.js} +3 -127
- package/dist/{chunk-NAPITCZ6.js → chunk-GUE7HTNR.js} +251 -6
- package/dist/{chunk-BTH37NCU.js → chunk-GVOUCI2O.js} +1 -1
- package/dist/{chunk-YYBX2BD5.js → chunk-GY34VGP5.js} +1 -1
- package/dist/{chunk-KRMANDHI.js → chunk-HCXXB35T.js} +1481 -349
- package/dist/{chunk-YTNPU7I2.js → chunk-HDTO3A74.js} +2 -2
- package/dist/{chunk-YJ4OPVNA.js → chunk-HZNJLKKI.js} +1 -1
- package/dist/{chunk-HDNWZMUN.js → chunk-KDPCGVIT.js} +116 -51
- package/dist/chunk-N4RNJ32C.js +48 -0
- package/dist/{chunk-UUB3D2XI.js → chunk-NSCHU54X.js} +8 -10
- package/dist/{chunk-PFXC67GJ.js → chunk-RAIB6WSG.js} +6 -80
- package/dist/chunk-WAGQ377B.js +724 -0
- package/dist/{chunk-6H4PP63X.js → chunk-WCMQJE4F.js} +24 -14
- package/dist/{chunk-S6QKIGRM.js → chunk-WPOJ443W.js} +15 -25
- package/dist/{chunk-MAVOJ54A.js → chunk-XX4N4E6C.js} +25 -388
- package/dist/cli/chat.js +24 -23
- package/dist/cli/check.js +4 -4
- package/dist/cli/plugins.js +11 -12
- package/dist/cli/snapshot-warmup.js +7 -8
- package/dist/cli/upgrade.js +78 -17
- package/dist/db/schema/agent-steps.d.ts +134 -0
- package/dist/db/schema/conversation-messages.d.ts +153 -0
- package/dist/{chat/conversations/sql → db}/schema/conversations.d.ts +34 -0
- package/dist/{chat/conversations/sql → db}/schema.d.ts +319 -8
- package/dist/db-W55B74OP.js +24 -0
- package/dist/deployment.d.ts +2 -0
- package/dist/handlers/retention.d.ts +6 -0
- package/dist/instrumentation.js +16 -3
- package/dist/legacy-import-ZPLGLAFD.js +17 -0
- package/dist/nitro.js +14 -4
- package/dist/reporting/conversations/activity.d.ts +40 -0
- package/dist/reporting/conversations/context.d.ts +8 -0
- package/dist/reporting/conversations/details.d.ts +6 -0
- package/dist/reporting/conversations/index.d.ts +4 -0
- package/dist/reporting/conversations/shared.d.ts +9 -0
- package/dist/reporting/conversations/statistics.d.ts +4 -0
- package/dist/reporting/conversations/summaries.d.ts +17 -0
- package/dist/reporting/conversations/transcript.d.ts +28 -0
- package/dist/reporting/conversations/types.d.ts +178 -0
- package/dist/reporting/conversations.d.ts +1 -178
- package/dist/reporting.d.ts +4 -3
- package/dist/reporting.js +603 -827
- package/dist/{runner-XAZPJNAQ.js → runner-OOSBDYRK.js} +35 -41
- package/dist/{validation-KYAWETI4.js → validation-QCGRFRFZ.js} +4 -4
- package/migrations/README.md +32 -0
- package/migrations/meta/0000_snapshot.json +978 -0
- package/migrations/meta/_journal.json +13 -0
- package/package.json +10 -7
- package/dist/chat/sql/schema.d.ts +0 -1049
- package/dist/chat/state/conversation-details.d.ts +0 -47
- package/dist/chunk-7STN2ZSK.js +0 -250
- package/dist/chunk-LE5ANBUZ.js +0 -1040
- package/dist/chunk-QL66APYJ.js +0 -1377
- package/dist/db-YDN6AFJH.js +0 -18
- /package/dist/{chat/sql → db}/db.d.ts +0 -0
- /package/dist/{chat/sql → db}/executor.d.ts +0 -0
- /package/dist/{chat/sql → db}/neon.d.ts +0 -0
- /package/dist/{chat/sql → db}/postgres.d.ts +0 -0
- /package/dist/{chat/conversations/sql → db}/schema/destinations.d.ts +0 -0
- /package/dist/{chat/conversations/sql → db}/schema/identities.d.ts +0 -0
- /package/dist/{chat/conversations/sql → db}/schema/migrations.d.ts +0 -0
- /package/dist/{chat/conversations/sql → db}/schema/timestamps.d.ts +0 -0
- /package/dist/{chat/conversations/sql → db}/schema/users.d.ts +0 -0
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
JUNIOR_THREAD_STATE_TTL_MS,
|
|
3
2
|
buildConversationStatePatch
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RAIB6WSG.js";
|
|
5
4
|
import {
|
|
6
5
|
abandonAgentTurnSessionRecord,
|
|
7
6
|
getAgentTurnSessionRecord,
|
|
8
7
|
upsertAgentTurnSessionRecord
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-WAGQ377B.js";
|
|
9
|
+
import {
|
|
10
|
+
JUNIOR_THREAD_STATE_TTL_MS,
|
|
11
|
+
persistConversationMessages
|
|
12
|
+
} from "./chunk-CRRBJ3JP.js";
|
|
10
13
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
sleep
|
|
15
|
+
} from "./chunk-CZEX6KIQ.js";
|
|
13
16
|
import {
|
|
14
17
|
getPiMessageRole,
|
|
18
|
+
getStateAdapter,
|
|
15
19
|
trimTrailingAssistantMessages
|
|
16
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-GUE7HTNR.js";
|
|
17
21
|
import {
|
|
18
22
|
getActiveTraceId,
|
|
19
23
|
logException
|
|
20
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-WPOJ443W.js";
|
|
21
25
|
import {
|
|
22
26
|
isRecord,
|
|
23
27
|
toOptionalString
|
|
@@ -144,6 +148,24 @@ function addAgentTurnUsage(...usages) {
|
|
|
144
148
|
return hasAgentTurnUsage(components) ? components : void 0;
|
|
145
149
|
}
|
|
146
150
|
|
|
151
|
+
// src/chat/services/persist-retry.ts
|
|
152
|
+
var PERSIST_ATTEMPTS = 3;
|
|
153
|
+
async function persistWithRetry(persist) {
|
|
154
|
+
let lastError;
|
|
155
|
+
for (let attempt = 1; attempt <= PERSIST_ATTEMPTS; attempt += 1) {
|
|
156
|
+
try {
|
|
157
|
+
await persist();
|
|
158
|
+
return;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
lastError = error;
|
|
161
|
+
if (attempt < PERSIST_ATTEMPTS) {
|
|
162
|
+
await sleep(attempt * 100);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
throw lastError;
|
|
167
|
+
}
|
|
168
|
+
|
|
147
169
|
// src/chat/services/turn-session-record.ts
|
|
148
170
|
var AGENT_CONTINUE_MAX_SLICES = 48;
|
|
149
171
|
function logSessionRecordError(error, eventName, args, attributes, message) {
|
|
@@ -222,6 +244,8 @@ async function persistRunningSessionRecord(args) {
|
|
|
222
244
|
...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
|
|
223
245
|
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
224
246
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
247
|
+
...args.modelId ? { modelId: args.modelId } : {},
|
|
248
|
+
...args.reasoningLevel ? { reasoningLevel: args.reasoningLevel } : {},
|
|
225
249
|
...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
|
|
226
250
|
...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
|
|
227
251
|
...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
|
|
@@ -243,55 +267,54 @@ async function persistRunningSessionRecord(args) {
|
|
|
243
267
|
}
|
|
244
268
|
}
|
|
245
269
|
async function persistCompletedSessionRecord(args) {
|
|
246
|
-
let
|
|
247
|
-
|
|
248
|
-
|
|
270
|
+
let latestSessionRecord;
|
|
271
|
+
await persistWithRetry(async () => {
|
|
272
|
+
latestSessionRecord = await getAgentTurnSessionRecord(
|
|
249
273
|
args.conversationId,
|
|
250
274
|
args.sessionId
|
|
251
275
|
);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
await upsertAgentTurnSessionRecord({
|
|
259
|
-
...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
|
|
260
|
-
conversationId: args.conversationId,
|
|
261
|
-
cumulativeDurationMs: addDurationMs(
|
|
262
|
-
latestSessionRecord?.cumulativeDurationMs,
|
|
263
|
-
args.currentDurationMs
|
|
264
|
-
),
|
|
265
|
-
cumulativeUsage: addAgentTurnUsage(
|
|
266
|
-
latestSessionRecord?.cumulativeUsage,
|
|
267
|
-
args.currentUsage
|
|
268
|
-
),
|
|
269
|
-
...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
|
|
270
|
-
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
271
|
-
...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
|
|
272
|
-
sessionId: args.sessionId,
|
|
273
|
-
sliceId,
|
|
274
|
-
state: "completed",
|
|
275
|
-
piMessages: args.allMessages,
|
|
276
|
-
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
277
|
-
...args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames ? {
|
|
278
|
-
loadedSkillNames: args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames
|
|
279
|
-
} : {},
|
|
280
|
-
...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
|
|
281
|
-
...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
|
|
282
|
-
...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
|
|
283
|
-
turnStartMessageIndex: args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex
|
|
284
|
-
} : {}
|
|
285
|
-
});
|
|
286
|
-
} catch (recordError) {
|
|
287
|
-
logSessionRecordError(
|
|
288
|
-
recordError,
|
|
289
|
-
"agent_turn_completed_session_record_failed",
|
|
290
|
-
args,
|
|
291
|
-
sliceId !== void 0 ? { "app.ai.resume_slice_id": sliceId } : {},
|
|
292
|
-
"Failed to persist completed turn session record"
|
|
276
|
+
});
|
|
277
|
+
const sliceId = args.sliceId ?? latestSessionRecord?.sliceId;
|
|
278
|
+
if (sliceId === void 0) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
"Completed session record requires a slice id from the caller or the latest stored record"
|
|
293
281
|
);
|
|
294
282
|
}
|
|
283
|
+
const modelId = latestSessionRecord?.modelId ?? args.modelId ?? args.logContext.modelId;
|
|
284
|
+
const reasoningLevel = args.reasoningLevel ?? latestSessionRecord?.reasoningLevel;
|
|
285
|
+
const target = {
|
|
286
|
+
...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
|
|
287
|
+
conversationId: args.conversationId,
|
|
288
|
+
cumulativeDurationMs: addDurationMs(
|
|
289
|
+
latestSessionRecord?.cumulativeDurationMs,
|
|
290
|
+
args.currentDurationMs
|
|
291
|
+
),
|
|
292
|
+
cumulativeUsage: addAgentTurnUsage(
|
|
293
|
+
latestSessionRecord?.cumulativeUsage,
|
|
294
|
+
args.currentUsage
|
|
295
|
+
),
|
|
296
|
+
...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
|
|
297
|
+
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
298
|
+
...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
|
|
299
|
+
sessionId: args.sessionId,
|
|
300
|
+
sliceId,
|
|
301
|
+
state: "completed",
|
|
302
|
+
piMessages: args.allMessages,
|
|
303
|
+
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
304
|
+
...args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames ? {
|
|
305
|
+
loadedSkillNames: args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames
|
|
306
|
+
} : {},
|
|
307
|
+
...modelId ? { modelId } : {},
|
|
308
|
+
...reasoningLevel ? { reasoningLevel } : {},
|
|
309
|
+
...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
|
|
310
|
+
...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
|
|
311
|
+
...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
|
|
312
|
+
turnStartMessageIndex: args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex
|
|
313
|
+
} : {}
|
|
314
|
+
};
|
|
315
|
+
await persistWithRetry(async () => {
|
|
316
|
+
await upsertAgentTurnSessionRecord(target);
|
|
317
|
+
});
|
|
295
318
|
}
|
|
296
319
|
async function completeDeliveredTurn(args) {
|
|
297
320
|
await persistCompletedSessionRecord({
|
|
@@ -307,7 +330,9 @@ async function completeDeliveredTurn(args) {
|
|
|
307
330
|
allMessages: args.messages,
|
|
308
331
|
loadedSkillNames: args.loadedSkillNames,
|
|
309
332
|
logContext: args.logContext,
|
|
333
|
+
modelId: args.logContext.modelId,
|
|
310
334
|
actor: args.actor,
|
|
335
|
+
reasoningLevel: args.reasoningLevel,
|
|
311
336
|
surface: args.surface,
|
|
312
337
|
turnStartMessageIndex: args.turnStartMessageIndex
|
|
313
338
|
});
|
|
@@ -345,6 +370,10 @@ async function persistAuthPauseSessionRecord(args) {
|
|
|
345
370
|
piMessages,
|
|
346
371
|
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
347
372
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
373
|
+
...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
|
|
374
|
+
...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
|
|
375
|
+
reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
|
|
376
|
+
} : {},
|
|
348
377
|
resumeReason: "auth",
|
|
349
378
|
resumedFromSliceId: args.currentSliceId,
|
|
350
379
|
errorMessage: args.errorMessage,
|
|
@@ -405,6 +434,10 @@ async function persistTimeoutSessionRecord(args) {
|
|
|
405
434
|
piMessages,
|
|
406
435
|
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
407
436
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
437
|
+
...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
|
|
438
|
+
...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
|
|
439
|
+
reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
|
|
440
|
+
} : {},
|
|
408
441
|
resumeReason: "timeout",
|
|
409
442
|
resumedFromSliceId: latestSessionRecord?.resumedFromSliceId,
|
|
410
443
|
errorMessage: `Agent continuation exceeded slice limit (${AGENT_CONTINUE_MAX_SLICES})`,
|
|
@@ -425,6 +458,10 @@ async function persistTimeoutSessionRecord(args) {
|
|
|
425
458
|
piMessages,
|
|
426
459
|
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
427
460
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
461
|
+
...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
|
|
462
|
+
...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
|
|
463
|
+
reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
|
|
464
|
+
} : {},
|
|
428
465
|
resumeReason: "timeout",
|
|
429
466
|
resumedFromSliceId: args.currentSliceId,
|
|
430
467
|
errorMessage: args.errorMessage,
|
|
@@ -477,6 +514,10 @@ async function persistYieldSessionRecord(args) {
|
|
|
477
514
|
piMessages,
|
|
478
515
|
...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
|
|
479
516
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
517
|
+
...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
|
|
518
|
+
...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
|
|
519
|
+
reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
|
|
520
|
+
} : {},
|
|
480
521
|
resumeReason: "yield",
|
|
481
522
|
resumedFromSliceId: latestSessionRecord?.resumedFromSliceId,
|
|
482
523
|
errorMessage: args.errorMessage,
|
|
@@ -791,6 +832,15 @@ function getPersistedSandboxState(state) {
|
|
|
791
832
|
};
|
|
792
833
|
}
|
|
793
834
|
async function persistThreadState(thread, patch) {
|
|
835
|
+
if (patch.conversation) {
|
|
836
|
+
await persistConversationMessages({
|
|
837
|
+
conversation: patch.conversation,
|
|
838
|
+
conversationId: toOptionalString(thread.id) ?? toOptionalString(thread.runId)
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
await persistThreadRuntimeState(thread, patch);
|
|
842
|
+
}
|
|
843
|
+
async function persistThreadRuntimeState(thread, patch) {
|
|
794
844
|
const payload = buildThreadStatePayload(patch);
|
|
795
845
|
if (Object.keys(payload).length === 0) {
|
|
796
846
|
return;
|
|
@@ -812,6 +862,12 @@ async function getPersistedChannelState(channelId) {
|
|
|
812
862
|
) ?? {};
|
|
813
863
|
}
|
|
814
864
|
async function persistThreadStateById(threadId, patch) {
|
|
865
|
+
if (patch.conversation) {
|
|
866
|
+
await persistConversationMessages({
|
|
867
|
+
conversation: patch.conversation,
|
|
868
|
+
conversationId: threadId
|
|
869
|
+
});
|
|
870
|
+
}
|
|
815
871
|
const payload = buildThreadStatePayload(patch);
|
|
816
872
|
if (Object.keys(payload).length === 0) {
|
|
817
873
|
return;
|
|
@@ -854,6 +910,12 @@ function getChannelConfigurationServiceById(channelId) {
|
|
|
854
910
|
});
|
|
855
911
|
}
|
|
856
912
|
|
|
913
|
+
// src/chat/interruption-marker.ts
|
|
914
|
+
var INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
|
|
915
|
+
function getInterruptionMarker() {
|
|
916
|
+
return INTERRUPTED_MARKER;
|
|
917
|
+
}
|
|
918
|
+
|
|
857
919
|
// src/chat/services/pending-auth.ts
|
|
858
920
|
var AUTH_LINK_REUSE_WINDOW_MS = 10 * 60 * 1e3;
|
|
859
921
|
var NON_REQUEST_SKIPPED_REASON_PREFIXES = [
|
|
@@ -933,6 +995,7 @@ export {
|
|
|
933
995
|
markTurnFailed,
|
|
934
996
|
hasAgentTurnUsage,
|
|
935
997
|
addAgentTurnUsage,
|
|
998
|
+
persistWithRetry,
|
|
936
999
|
loadTurnSessionRecord,
|
|
937
1000
|
persistRunningSessionRecord,
|
|
938
1001
|
persistCompletedSessionRecord,
|
|
@@ -940,6 +1003,7 @@ export {
|
|
|
940
1003
|
persistAuthPauseSessionRecord,
|
|
941
1004
|
persistTimeoutSessionRecord,
|
|
942
1005
|
persistYieldSessionRecord,
|
|
1006
|
+
getInterruptionMarker,
|
|
943
1007
|
canReusePendingAuthLink,
|
|
944
1008
|
getConversationPendingAuth,
|
|
945
1009
|
clearPendingAuth,
|
|
@@ -949,6 +1013,7 @@ export {
|
|
|
949
1013
|
mergeArtifactsState,
|
|
950
1014
|
getPersistedSandboxState,
|
|
951
1015
|
persistThreadState,
|
|
1016
|
+
persistThreadRuntimeState,
|
|
952
1017
|
getPersistedThreadState,
|
|
953
1018
|
persistThreadStateById,
|
|
954
1019
|
getChannelConfigurationService,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
escapeXml,
|
|
3
|
+
unescapeXml
|
|
4
|
+
} from "./chunk-GUE7HTNR.js";
|
|
5
|
+
|
|
6
|
+
// src/chat/advisor-request.ts
|
|
7
|
+
var TASK_OPEN = "<advisor-task>\n";
|
|
8
|
+
var TASK_CLOSE = "\n</advisor-task>";
|
|
9
|
+
var CONTEXT_OPEN = "<executor-context>\n";
|
|
10
|
+
var CONTEXT_CLOSE = "\n</executor-context>";
|
|
11
|
+
function renderAdvisorRequest(question, context) {
|
|
12
|
+
return [
|
|
13
|
+
TASK_OPEN,
|
|
14
|
+
escapeXml(question),
|
|
15
|
+
TASK_CLOSE,
|
|
16
|
+
"\n\n",
|
|
17
|
+
CONTEXT_OPEN,
|
|
18
|
+
escapeXml(context),
|
|
19
|
+
CONTEXT_CLOSE
|
|
20
|
+
].join("");
|
|
21
|
+
}
|
|
22
|
+
function unwrapAdvisorRequest(text) {
|
|
23
|
+
if (!text.startsWith(TASK_OPEN) || !text.endsWith(CONTEXT_CLOSE)) {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
const taskEnd = text.indexOf(TASK_CLOSE, TASK_OPEN.length);
|
|
27
|
+
if (taskEnd < 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const contextStart = taskEnd + TASK_CLOSE.length + 2;
|
|
31
|
+
if (!text.startsWith(CONTEXT_OPEN, contextStart)) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
const task = text.slice(TASK_OPEN.length, taskEnd);
|
|
35
|
+
const context = text.slice(
|
|
36
|
+
contextStart + CONTEXT_OPEN.length,
|
|
37
|
+
-CONTEXT_CLOSE.length
|
|
38
|
+
);
|
|
39
|
+
return `${unescapeXml(task)}
|
|
40
|
+
|
|
41
|
+
Executor context:
|
|
42
|
+
${unescapeXml(context)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
renderAdvisorRequest,
|
|
47
|
+
unwrapAdvisorRequest
|
|
48
|
+
};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPluginLogger,
|
|
3
3
|
createPluginState
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-E3E2XNCN.js";
|
|
5
5
|
import {
|
|
6
|
-
SANDBOX_WORKSPACE_ROOT
|
|
7
|
-
|
|
6
|
+
SANDBOX_WORKSPACE_ROOT,
|
|
7
|
+
sleep
|
|
8
|
+
} from "./chunk-CZEX6KIQ.js";
|
|
8
9
|
import {
|
|
9
10
|
getDb
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-6ONME5IG.js";
|
|
11
12
|
import {
|
|
12
13
|
botConfig,
|
|
13
14
|
completeObject,
|
|
14
15
|
embedTexts,
|
|
15
16
|
getSlackBotToken
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-GUE7HTNR.js";
|
|
17
18
|
import {
|
|
18
19
|
isActorUserId,
|
|
19
20
|
logInfo,
|
|
@@ -22,12 +23,12 @@ import {
|
|
|
22
23
|
setSpanAttributes,
|
|
23
24
|
setSpanStatus,
|
|
24
25
|
withSpan
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WPOJ443W.js";
|
|
26
27
|
import {
|
|
27
28
|
parseSlackChannelReferenceId,
|
|
28
29
|
parseSlackMessageTs,
|
|
29
30
|
parseSlackTeamId
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-7FBGKXPE.js";
|
|
31
32
|
|
|
32
33
|
// src/chat/plugins/agent-hooks.ts
|
|
33
34
|
import { promptMessageSchema } from "@sentry/junior-plugin-api";
|
|
@@ -314,9 +315,6 @@ function mapSlackError(error) {
|
|
|
314
315
|
}
|
|
315
316
|
return new SlackActionError(message, "internal_error", baseOptions);
|
|
316
317
|
}
|
|
317
|
-
function sleep(ms) {
|
|
318
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
319
|
-
}
|
|
320
318
|
var MAX_RETRY_DELAY_MS = 1e4;
|
|
321
319
|
var MAX_TOTAL_RETRY_DELAY_MS = 2e4;
|
|
322
320
|
var CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
@@ -5,69 +5,11 @@ import {
|
|
|
5
5
|
} from "./chunk-OB42YVAE.js";
|
|
6
6
|
|
|
7
7
|
// src/chat/state/conversation.ts
|
|
8
|
-
function coerceRole(value) {
|
|
9
|
-
return value === "assistant" || value === "system" || value === "user" ? value : "user";
|
|
10
|
-
}
|
|
11
|
-
function coerceAuthor(value) {
|
|
12
|
-
if (!isRecord(value)) return void 0;
|
|
13
|
-
const author = {
|
|
14
|
-
fullName: toOptionalString(value.fullName),
|
|
15
|
-
userId: toOptionalString(value.userId),
|
|
16
|
-
userName: toOptionalString(value.userName)
|
|
17
|
-
};
|
|
18
|
-
if (typeof value.isBot === "boolean") {
|
|
19
|
-
author.isBot = value.isBot;
|
|
20
|
-
}
|
|
21
|
-
if (!author.fullName && !author.userId && !author.userName && author.isBot === void 0) {
|
|
22
|
-
return void 0;
|
|
23
|
-
}
|
|
24
|
-
return author;
|
|
25
|
-
}
|
|
26
|
-
function coerceMessageMeta(value) {
|
|
27
|
-
if (!isRecord(value)) return void 0;
|
|
28
|
-
const meta = {};
|
|
29
|
-
const attachmentCount = toOptionalNumber(value.attachmentCount);
|
|
30
|
-
if (typeof attachmentCount === "number" && attachmentCount > 0) {
|
|
31
|
-
meta.attachmentCount = attachmentCount;
|
|
32
|
-
}
|
|
33
|
-
if (typeof value.explicitMention === "boolean") {
|
|
34
|
-
meta.explicitMention = value.explicitMention;
|
|
35
|
-
}
|
|
36
|
-
const imageAttachmentCount = toOptionalNumber(value.imageAttachmentCount);
|
|
37
|
-
if (typeof imageAttachmentCount === "number" && imageAttachmentCount > 0) {
|
|
38
|
-
meta.imageAttachmentCount = imageAttachmentCount;
|
|
39
|
-
}
|
|
40
|
-
if (typeof value.replied === "boolean") {
|
|
41
|
-
meta.replied = value.replied;
|
|
42
|
-
}
|
|
43
|
-
if (typeof value.skippedReason === "string" && value.skippedReason.trim().length > 0) {
|
|
44
|
-
meta.skippedReason = value.skippedReason;
|
|
45
|
-
}
|
|
46
|
-
if (typeof value.slackTs === "string" && value.slackTs.trim().length > 0) {
|
|
47
|
-
meta.slackTs = value.slackTs;
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(value.imageFileIds)) {
|
|
50
|
-
const imageFileIds = value.imageFileIds.filter(
|
|
51
|
-
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
52
|
-
);
|
|
53
|
-
if (imageFileIds.length > 0) {
|
|
54
|
-
meta.imageFileIds = imageFileIds;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (typeof value.imagesHydrated === "boolean") {
|
|
58
|
-
meta.imagesHydrated = value.imagesHydrated;
|
|
59
|
-
}
|
|
60
|
-
if (meta.attachmentCount === void 0 && meta.explicitMention === void 0 && meta.imageAttachmentCount === void 0 && meta.replied === void 0 && meta.skippedReason === void 0 && meta.slackTs === void 0 && meta.imageFileIds === void 0 && meta.imagesHydrated === void 0) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
return meta;
|
|
64
|
-
}
|
|
65
8
|
function defaultConversationState() {
|
|
66
9
|
const nowMs = Date.now();
|
|
67
10
|
return {
|
|
68
11
|
schemaVersion: 1,
|
|
69
12
|
messages: [],
|
|
70
|
-
piMessages: [],
|
|
71
13
|
compactions: [],
|
|
72
14
|
backfill: {},
|
|
73
15
|
processing: {},
|
|
@@ -111,23 +53,7 @@ function coerceThreadConversationState(value) {
|
|
|
111
53
|
const root = value;
|
|
112
54
|
const rawConversation = isRecord(root.conversation) ? root.conversation : {};
|
|
113
55
|
const base = defaultConversationState();
|
|
114
|
-
const rawMessages = Array.isArray(rawConversation.messages) ? rawConversation.messages : [];
|
|
115
56
|
const messages = [];
|
|
116
|
-
for (const item of rawMessages) {
|
|
117
|
-
if (!isRecord(item)) continue;
|
|
118
|
-
const id = toOptionalString(item.id);
|
|
119
|
-
const text = toOptionalString(item.text);
|
|
120
|
-
const createdAtMs = toOptionalNumber(item.createdAtMs);
|
|
121
|
-
if (!id || !text || !createdAtMs) continue;
|
|
122
|
-
messages.push({
|
|
123
|
-
id,
|
|
124
|
-
role: coerceRole(item.role),
|
|
125
|
-
text,
|
|
126
|
-
createdAtMs,
|
|
127
|
-
author: coerceAuthor(item.author),
|
|
128
|
-
meta: coerceMessageMeta(item.meta)
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
57
|
const rawCompactions = Array.isArray(rawConversation.compactions) ? rawConversation.compactions : [];
|
|
132
58
|
const compactions = [];
|
|
133
59
|
for (const item of rawCompactions) {
|
|
@@ -181,7 +107,6 @@ function coerceThreadConversationState(value) {
|
|
|
181
107
|
return {
|
|
182
108
|
schemaVersion: 1,
|
|
183
109
|
messages,
|
|
184
|
-
piMessages: Array.isArray(rawConversation.piMessages) ? rawConversation.piMessages : [],
|
|
185
110
|
compactions,
|
|
186
111
|
backfill,
|
|
187
112
|
processing,
|
|
@@ -193,9 +118,14 @@ function coerceThreadConversationState(value) {
|
|
|
193
118
|
};
|
|
194
119
|
}
|
|
195
120
|
function buildConversationStatePatch(conversation) {
|
|
121
|
+
const {
|
|
122
|
+
compactions: _compactions,
|
|
123
|
+
messages: _messages,
|
|
124
|
+
...scratch
|
|
125
|
+
} = conversation;
|
|
196
126
|
return {
|
|
197
127
|
conversation: {
|
|
198
|
-
...
|
|
128
|
+
...scratch,
|
|
199
129
|
schemaVersion: 1,
|
|
200
130
|
stats: {
|
|
201
131
|
...conversation.stats,
|
|
@@ -206,11 +136,7 @@ function buildConversationStatePatch(conversation) {
|
|
|
206
136
|
};
|
|
207
137
|
}
|
|
208
138
|
|
|
209
|
-
// src/chat/state/ttl.ts
|
|
210
|
-
var JUNIOR_THREAD_STATE_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
211
|
-
|
|
212
139
|
export {
|
|
213
|
-
JUNIOR_THREAD_STATE_TTL_MS,
|
|
214
140
|
coerceThreadConversationState,
|
|
215
141
|
buildConversationStatePatch
|
|
216
142
|
};
|