@sentry/junior 0.96.0 → 0.97.1
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-5URSMY3O.js → agent-hooks-XSUIVRQS.js} +8 -6
- package/dist/{reporting → api}/conversations/activity.d.ts +1 -1
- package/dist/api/conversations/detail-projection.d.ts +10 -0
- package/dist/api/conversations/detail.d.ts +3 -0
- package/dist/api/conversations/detail.query.d.ts +3 -0
- package/dist/api/conversations/list.d.ts +3 -0
- package/dist/api/conversations/list.query.d.ts +94 -0
- package/dist/api/conversations/projection.d.ts +14 -0
- package/dist/api/conversations/schema.d.ts +683 -0
- package/dist/{reporting → api}/conversations/shared.d.ts +1 -5
- package/dist/api/conversations/stats.d.ts +3 -0
- package/dist/api/conversations/stats.query.d.ts +3 -0
- package/dist/api/conversations/subagent.d.ts +3 -0
- package/dist/{reporting → api}/conversations/transcript.d.ts +4 -4
- package/dist/api/people/list.d.ts +1 -2
- package/dist/api/people/list.query.d.ts +3 -4
- package/dist/api/people/profile.d.ts +1 -2
- package/dist/api/people/profile.query.d.ts +3 -4
- package/dist/api/people/schema.d.ts +193 -0
- package/dist/api/people/shared.d.ts +31 -9
- package/dist/api/schema.d.ts +20 -0
- package/dist/api/schema.js +50 -0
- package/dist/api-reference.d.ts +4 -3
- package/dist/api.d.ts +3 -0
- package/dist/api.js +156 -0
- package/dist/app.d.ts +1 -4
- package/dist/app.js +101 -367
- package/dist/build/virtual-config.d.ts +2 -2
- package/dist/{catalog-runtime-MSMAYYIK.js → catalog-runtime-PFHVMHDR.js} +3 -2
- package/dist/chat/agent/resume.d.ts +3 -1
- package/dist/chat/agent/tools.d.ts +2 -1
- package/dist/chat/config.d.ts +1 -8
- package/dist/chat/conversations/history.d.ts +241 -27
- package/dist/chat/conversations/legacy-advisor-session.d.ts +7 -0
- package/dist/chat/conversations/legacy-import.d.ts +2 -2
- package/dist/chat/conversations/projection.d.ts +19 -3
- package/dist/chat/conversations/sql/legacy-history-import.d.ts +1 -1
- package/dist/chat/conversations/sql/store.d.ts +15 -9
- package/dist/chat/conversations/store.d.ts +9 -4
- package/dist/chat/model-profile.d.ts +14 -0
- package/dist/chat/pi/transcript.d.ts +5 -3
- package/dist/chat/resource-events/store.d.ts +2 -2
- package/dist/chat/services/context-compaction.d.ts +15 -0
- package/dist/chat/services/turn-result.d.ts +1 -0
- package/dist/chat/services/turn-session-record.d.ts +6 -6
- package/dist/chat/state/turn-session.d.ts +16 -5
- package/dist/chat/task-execution/store.d.ts +2 -2
- package/dist/chat/tools/handoff/tool.d.ts +45 -0
- package/dist/chat/tools/types.d.ts +7 -2
- package/dist/chat/usage.d.ts +25 -25
- package/dist/{chunk-RITD7E5L.js → chunk-35BNLDOJ.js} +338 -577
- package/dist/{chunk-PMNN6ST4.js → chunk-3ECW2K2O.js} +7 -2
- package/dist/{chunk-5C6XTTFI.js → chunk-3F4OPKGF.js} +89 -55
- package/dist/chunk-3V7OFJZC.js +264 -0
- package/dist/chunk-4ZNGQH7C.js +25 -0
- package/dist/{chunk-S5KZ5LPG.js → chunk-5HLDPVYS.js} +14 -447
- package/dist/{chunk-DZENG5ML.js → chunk-6U26PYI5.js} +24 -14
- package/dist/chunk-AUUCAFDE.js +546 -0
- package/dist/{chunk-6APU57E6.js → chunk-B3IT5END.js} +41 -260
- package/dist/chunk-CEA3A3UA.js +86 -0
- package/dist/{chunk-YDT7SNCN.js → chunk-D5KZYS4T.js} +1 -1
- package/dist/{chunk-YDVEH3SB.js → chunk-EEZCY5WX.js} +78 -28
- package/dist/{chunk-2NAZZPPS.js → chunk-EOWXRY5E.js} +1 -1
- package/dist/{chunk-GQ3GK22G.js → chunk-FBHZJFHI.js} +2 -2
- package/dist/{chunk-CZEX6KIQ.js → chunk-G3E7SCME.js} +0 -23
- package/dist/chunk-GUAP3H7O.js +319 -0
- package/dist/{chunk-BYZWPRJA.js → chunk-H66UCBPW.js} +6 -4
- package/dist/{chunk-L7CDEIVJ.js → chunk-LMJPRYHP.js} +4 -2
- package/dist/chunk-LUAE4MGW.js +199 -0
- package/dist/{chunk-GY34VGP5.js → chunk-LVA4I4H7.js} +3 -1
- package/dist/chunk-LVUKF5CE.js +63 -0
- package/dist/{chunk-AAZXTVJT.js → chunk-NG2AV7IB.js} +2 -72
- package/dist/chunk-ON6YKIQ7.js +260 -0
- package/dist/chunk-PDO5BLNM.js +22 -0
- package/dist/chunk-QNVHH5PU.js +20 -0
- package/dist/{chunk-P3YFQLEN.js → chunk-T533JLM3.js} +8 -10
- package/dist/chunk-UAMKJPDF.js +11 -0
- package/dist/chunk-VFH4ZKZT.js +66 -0
- package/dist/{chunk-UKHVMPX5.js → chunk-WGXMTFNU.js} +15 -17
- package/dist/{chunk-MNTINMWR.js → chunk-WJOSZOON.js} +184 -300
- package/dist/chunk-WTYEKPXU.js +451 -0
- package/dist/{chunk-IYM2SIVG.js → chunk-XIRPQQVE.js} +605 -363
- package/dist/cli/chat.js +24 -21
- package/dist/cli/check.js +4 -3
- package/dist/cli/init.js +12 -0
- package/dist/cli/plugins.js +12 -9
- package/dist/cli/snapshot-warmup.js +8 -6
- package/dist/cli/upgrade.js +265 -137
- package/dist/db/db.d.ts +4 -0
- package/dist/db/schema/conversations.d.ts +128 -0
- package/dist/db/schema.d.ts +129 -60
- package/dist/{db-2D6RMG67.js → db-BWXYIKFQ.js} +3 -3
- package/dist/detail-GA6NXWQJ.js +43 -0
- package/dist/discovery-RMHYSRL7.js +43 -0
- package/dist/handlers/health.d.ts +3 -0
- package/dist/instrumentation.js +1 -1
- package/dist/{legacy-import-VZ2MEGP7.js → legacy-import-3NQJVGQL.js} +4 -4
- package/dist/{api/people/list.js → list-A3WFRIYX.js} +26 -16
- package/dist/list-UXJI5Q5X.js +27 -0
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -1
- package/dist/plugin-conversations-DDNGC35A.js +36 -0
- package/dist/{api/people/profile.js → profile-4RYDXWTF.js} +33 -18
- package/dist/reporting/plugin-conversations.d.ts +3 -0
- package/dist/reporting-schema.d.ts +140 -0
- package/dist/reporting.d.ts +12 -81
- package/dist/{runner-JZBRQP4F.js → runner-JALSYH2P.js} +17 -12
- package/dist/skills-MAZXZ2KE.js +26 -0
- package/dist/stats-XKXH3PTY.js +217 -0
- package/dist/subagent-TZ55XY37.js +48 -0
- package/dist/usage-schema.d.ts +25 -0
- package/dist/{validation-6XOOQGME.js → validation-FMEAEKCY.js} +4 -3
- package/migrations/0000_initial.sql +115 -0
- package/migrations/0001_conversation_metrics.sql +4 -0
- package/migrations/README.md +12 -30
- package/migrations/meta/0000_snapshot.json +1 -33
- package/migrations/meta/0001_snapshot.json +972 -0
- package/migrations/meta/_journal.json +9 -2
- package/package.json +13 -17
- package/dist/api/people/types.d.ts +0 -85
- package/dist/chat/advisor-request.d.ts +0 -4
- package/dist/chat/conversations/sql/migrations.d.ts +0 -22
- package/dist/chat/tools/advisor/session-store.d.ts +0 -9
- package/dist/chat/tools/advisor/tool.d.ts +0 -72
- package/dist/chunk-RAIB6WSG.js +0 -142
- package/dist/chunk-WM6KHPBQ.js +0 -48
- package/dist/db/schema/migrations.d.ts +0 -58
- package/dist/reporting/conversations/context.d.ts +0 -8
- package/dist/reporting/conversations/details.d.ts +0 -6
- package/dist/reporting/conversations/index.d.ts +0 -4
- package/dist/reporting/conversations/statistics.d.ts +0 -4
- package/dist/reporting/conversations/summaries.d.ts +0 -20
- package/dist/reporting/conversations/types.d.ts +0 -191
- package/dist/reporting/conversations.d.ts +0 -1
- package/dist/reporting.js +0 -1155
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
toGenAiMessageMetadata,
|
|
7
7
|
toGenAiMessagesTraceAttributes,
|
|
8
8
|
toGenAiTextMetadata
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LVA4I4H7.js";
|
|
10
10
|
import {
|
|
11
11
|
extractGenAiUsageAttributes,
|
|
12
12
|
logException,
|
|
@@ -152,6 +152,16 @@ function hasRuntimeTurnContext(messages) {
|
|
|
152
152
|
)
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
|
+
function retainRuntimeTurnContext(messages) {
|
|
156
|
+
return messages.flatMap((message) => {
|
|
157
|
+
const content = getUserMessageContent(message);
|
|
158
|
+
if (!content) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const runtimeContent = content.filter(isRuntimeTurnContextPart);
|
|
162
|
+
return runtimeContent.length > 0 ? [{ ...message, content: runtimeContent }] : [];
|
|
163
|
+
});
|
|
164
|
+
}
|
|
155
165
|
function instructionTextForProjection(text) {
|
|
156
166
|
const withoutContext = text.replace(EMBEDDED_THREAD_CONTEXT_PATTERN, "").trim();
|
|
157
167
|
return unwrapCurrentInstruction(withoutContext) ?? withoutContext;
|
|
@@ -531,6 +541,28 @@ function normalizeSlackEmojiName(value) {
|
|
|
531
541
|
return SLACK_EMOJI_NAME_RE.test(normalized) ? normalized : null;
|
|
532
542
|
}
|
|
533
543
|
|
|
544
|
+
// src/chat/model-profile.ts
|
|
545
|
+
import { z } from "zod";
|
|
546
|
+
var STANDARD_MODEL_PROFILE = "standard";
|
|
547
|
+
var DEFAULT_HANDOFF_MODEL_PROFILE = "handoff";
|
|
548
|
+
var modelProfileSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
|
|
549
|
+
var ModelProfileNotConfiguredError = class extends Error {
|
|
550
|
+
constructor(profile) {
|
|
551
|
+
super(`Model profile "${profile}" is not configured`);
|
|
552
|
+
this.name = "ModelProfileNotConfiguredError";
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
function modelIdForProfile(config, profile) {
|
|
556
|
+
if (profile === STANDARD_MODEL_PROFILE) {
|
|
557
|
+
return config.modelId;
|
|
558
|
+
}
|
|
559
|
+
const modelId = Object.hasOwn(config.modelProfiles, profile) ? config.modelProfiles[profile] : void 0;
|
|
560
|
+
if (!modelId) {
|
|
561
|
+
throw new ModelProfileNotConfiguredError(profile);
|
|
562
|
+
}
|
|
563
|
+
return modelId;
|
|
564
|
+
}
|
|
565
|
+
|
|
534
566
|
// src/chat/config.ts
|
|
535
567
|
var MIN_AGENT_TURN_TIMEOUT_MS = 10 * 1e3;
|
|
536
568
|
var DEFAULT_AGENT_TURN_TIMEOUT_MS = 12 * 60 * 1e3;
|
|
@@ -538,14 +570,6 @@ var DEFAULT_FUNCTION_MAX_DURATION_SECONDS = 300;
|
|
|
538
570
|
var DEFAULT_SLACK_SLASH_COMMAND = "/jr";
|
|
539
571
|
var DEFAULT_PROCESSING_REACTION_EMOJI = "eyes";
|
|
540
572
|
var DEFAULT_COMPLETED_REACTION_EMOJI = "white_check_mark";
|
|
541
|
-
var ADVISOR_THINKING_LEVELS = [
|
|
542
|
-
"minimal",
|
|
543
|
-
"low",
|
|
544
|
-
"medium",
|
|
545
|
-
"high",
|
|
546
|
-
"xhigh"
|
|
547
|
-
];
|
|
548
|
-
var DEFAULT_ADVISOR_THINKING_LEVEL = "xhigh";
|
|
549
573
|
var FUNCTION_TIMEOUT_BUFFER_SECONDS = 20;
|
|
550
574
|
var DEFAULT_ASSISTANT_LOADING_MESSAGES = [
|
|
551
575
|
"Consulting the orb",
|
|
@@ -604,18 +628,6 @@ function parseLoadingMessages(rawValue) {
|
|
|
604
628
|
return value.trim();
|
|
605
629
|
});
|
|
606
630
|
}
|
|
607
|
-
function parseAdvisorThinkingLevel(rawValue) {
|
|
608
|
-
const value = toOptionalTrimmed(rawValue);
|
|
609
|
-
if (!value) {
|
|
610
|
-
return DEFAULT_ADVISOR_THINKING_LEVEL;
|
|
611
|
-
}
|
|
612
|
-
if (ADVISOR_THINKING_LEVELS.includes(value)) {
|
|
613
|
-
return value;
|
|
614
|
-
}
|
|
615
|
-
throw new Error(
|
|
616
|
-
`AI_ADVISOR_THINKING_LEVEL must be one of: minimal, low, medium, high, xhigh`
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
631
|
function parseOptionalPositiveInteger(envName, rawValue) {
|
|
620
632
|
const trimmed = toOptionalTrimmed(rawValue);
|
|
621
633
|
if (trimmed === void 0) {
|
|
@@ -641,7 +653,7 @@ var DEFAULT_FAST_MODEL_ID = getModel(
|
|
|
641
653
|
"vercel-ai-gateway",
|
|
642
654
|
"openai/gpt-5.4-mini"
|
|
643
655
|
).id;
|
|
644
|
-
var
|
|
656
|
+
var DEFAULT_HANDOFF_MODEL_ID = getModel(
|
|
645
657
|
"vercel-ai-gateway",
|
|
646
658
|
"openai/gpt-5.6-sol"
|
|
647
659
|
).id;
|
|
@@ -655,11 +667,42 @@ function validateGatewayModelId(raw) {
|
|
|
655
667
|
function validateEmbeddingModelId(raw) {
|
|
656
668
|
return toOptionalTrimmed(raw);
|
|
657
669
|
}
|
|
658
|
-
function
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
thinkingLevel: parseAdvisorThinkingLevel(env.AI_ADVISOR_THINKING_LEVEL)
|
|
670
|
+
function parseModelProfiles(rawValue, handoffModelId) {
|
|
671
|
+
const profiles = {
|
|
672
|
+
[DEFAULT_HANDOFF_MODEL_PROFILE]: handoffModelId
|
|
662
673
|
};
|
|
674
|
+
const trimmed = toOptionalTrimmed(rawValue);
|
|
675
|
+
if (trimmed === void 0) {
|
|
676
|
+
return profiles;
|
|
677
|
+
}
|
|
678
|
+
let parsed;
|
|
679
|
+
try {
|
|
680
|
+
parsed = JSON.parse(trimmed);
|
|
681
|
+
} catch {
|
|
682
|
+
throw new Error("AI_MODEL_PROFILES must be a JSON object");
|
|
683
|
+
}
|
|
684
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
685
|
+
throw new Error("AI_MODEL_PROFILES must be a JSON object");
|
|
686
|
+
}
|
|
687
|
+
for (const [profile, rawModelId] of Object.entries(parsed)) {
|
|
688
|
+
if (!modelProfileSchema.safeParse(profile).success) {
|
|
689
|
+
throw new Error(
|
|
690
|
+
`AI_MODEL_PROFILES profile "${profile}" must match ^[a-z][a-z0-9_-]*$`
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
if (profile === STANDARD_MODEL_PROFILE || profile === DEFAULT_HANDOFF_MODEL_PROFILE) {
|
|
694
|
+
throw new Error(`AI_MODEL_PROFILES profile "${profile}" is reserved`);
|
|
695
|
+
}
|
|
696
|
+
if (typeof rawModelId !== "string") {
|
|
697
|
+
throw new Error(`AI_MODEL_PROFILES.${profile} must be a model id string`);
|
|
698
|
+
}
|
|
699
|
+
const modelId = validateGatewayModelId(rawModelId);
|
|
700
|
+
if (!modelId) {
|
|
701
|
+
throw new Error(`AI_MODEL_PROFILES.${profile} must not be empty`);
|
|
702
|
+
}
|
|
703
|
+
profiles[profile] = modelId;
|
|
704
|
+
}
|
|
705
|
+
return profiles;
|
|
663
706
|
}
|
|
664
707
|
function parseReactionEmoji(envName, rawValue, defaultEmoji) {
|
|
665
708
|
const trimmed = toOptionalTrimmed(rawValue);
|
|
@@ -679,9 +722,11 @@ function readBotConfig(env) {
|
|
|
679
722
|
const maxTurnTimeoutMs = resolveMaxTurnTimeoutMs(functionMaxDurationSeconds);
|
|
680
723
|
const modelId = validateGatewayModelId(env.AI_MODEL) ?? DEFAULT_MODEL_ID;
|
|
681
724
|
const fastModelId = validateGatewayModelId(env.AI_FAST_MODEL ?? env.AI_MODEL) ?? DEFAULT_FAST_MODEL_ID;
|
|
725
|
+
const handoffModelId = validateGatewayModelId(env.AI_HANDOFF_MODEL) ?? DEFAULT_HANDOFF_MODEL_ID;
|
|
682
726
|
return {
|
|
683
727
|
userName: toOptionalTrimmed(env.JUNIOR_BOT_NAME) ?? "junior",
|
|
684
728
|
modelId,
|
|
729
|
+
modelProfiles: parseModelProfiles(env.AI_MODEL_PROFILES, handoffModelId),
|
|
685
730
|
modelContextWindowTokens: parseOptionalPositiveInteger(
|
|
686
731
|
"AI_MODEL_CONTEXT_WINDOW_TOKENS",
|
|
687
732
|
env.AI_MODEL_CONTEXT_WINDOW_TOKENS
|
|
@@ -693,8 +738,7 @@ function readBotConfig(env) {
|
|
|
693
738
|
turnTimeoutMs: parseAgentTurnTimeoutMs(
|
|
694
739
|
env.AGENT_TURN_TIMEOUT_MS,
|
|
695
740
|
maxTurnTimeoutMs
|
|
696
|
-
)
|
|
697
|
-
advisor: readAdvisorConfig(env)
|
|
741
|
+
)
|
|
698
742
|
};
|
|
699
743
|
}
|
|
700
744
|
function readDatabaseUrl(env) {
|
|
@@ -1050,6 +1094,7 @@ export {
|
|
|
1050
1094
|
getTerminalAssistantMessages,
|
|
1051
1095
|
trimTrailingAssistantMessages,
|
|
1052
1096
|
hasRuntimeTurnContext,
|
|
1097
|
+
retainRuntimeTurnContext,
|
|
1053
1098
|
instructionTextForProjection,
|
|
1054
1099
|
stripRuntimeTurnContext,
|
|
1055
1100
|
isProviderRetryError,
|
|
@@ -1065,6 +1110,11 @@ export {
|
|
|
1065
1110
|
completeObject,
|
|
1066
1111
|
embedTexts,
|
|
1067
1112
|
normalizeSlackEmojiName,
|
|
1113
|
+
STANDARD_MODEL_PROFILE,
|
|
1114
|
+
DEFAULT_HANDOFF_MODEL_PROFILE,
|
|
1115
|
+
modelProfileSchema,
|
|
1116
|
+
ModelProfileNotConfiguredError,
|
|
1117
|
+
modelIdForProfile,
|
|
1068
1118
|
FUNCTION_TIMEOUT_BUFFER_SECONDS,
|
|
1069
1119
|
getChatConfig,
|
|
1070
1120
|
botConfig,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JUNIOR_THREAD_STATE_TTL_MS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WJOSZOON.js";
|
|
4
4
|
import {
|
|
5
5
|
getChatConfig,
|
|
6
6
|
getDefaultRedisStateAdapterFor,
|
|
7
7
|
getStateAdapter
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-EEZCY5WX.js";
|
|
9
9
|
import {
|
|
10
10
|
parseDestination,
|
|
11
11
|
sameDestination
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
// src/chat/sleep.ts
|
|
2
|
-
function sleep(ms, signal) {
|
|
3
|
-
if (!signal) {
|
|
4
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
-
}
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
if (signal.aborted) {
|
|
8
|
-
reject(signal.reason);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const timeoutId = setTimeout(() => {
|
|
12
|
-
signal.removeEventListener("abort", onAbort);
|
|
13
|
-
resolve();
|
|
14
|
-
}, ms);
|
|
15
|
-
const onAbort = () => {
|
|
16
|
-
clearTimeout(timeoutId);
|
|
17
|
-
reject(signal.reason);
|
|
18
|
-
};
|
|
19
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
1
|
// src/chat/sandbox/paths.ts
|
|
24
2
|
function normalizeWorkspaceRoot(input) {
|
|
25
3
|
const candidate = (input ?? "").trim();
|
|
@@ -42,7 +20,6 @@ function sandboxSkillFile(skillName) {
|
|
|
42
20
|
}
|
|
43
21
|
|
|
44
22
|
export {
|
|
45
|
-
sleep,
|
|
46
23
|
SANDBOX_WORKSPACE_ROOT,
|
|
47
24
|
SANDBOX_SKILLS_ROOT,
|
|
48
25
|
SANDBOX_DATA_ROOT,
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureLegacyConversationImport
|
|
3
|
+
} from "./chunk-3F4OPKGF.js";
|
|
4
|
+
import {
|
|
5
|
+
contextProvenance,
|
|
6
|
+
getAgentStepStore
|
|
7
|
+
} from "./chunk-35BNLDOJ.js";
|
|
8
|
+
|
|
9
|
+
// src/chat/conversations/projection.ts
|
|
10
|
+
import { isDeepStrictEqual } from "util";
|
|
11
|
+
function authorizationObservationMessage(entry, createdAtMs) {
|
|
12
|
+
const label = entry.kind === "mcp" ? "MCP authorization" : "Authorization";
|
|
13
|
+
return {
|
|
14
|
+
role: "user",
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: "text",
|
|
18
|
+
text: `${label} completed for provider "${entry.provider}". Continue the blocked request and retry the provider operation if needed.`
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
timestamp: createdAtMs
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function piEntryProvenance(entry) {
|
|
25
|
+
return entry.provenance ?? contextProvenance;
|
|
26
|
+
}
|
|
27
|
+
function projectSteps(steps, opts) {
|
|
28
|
+
const messages = [];
|
|
29
|
+
const provenance = [];
|
|
30
|
+
const seqs = [];
|
|
31
|
+
let modelProfile = "standard";
|
|
32
|
+
let modelId;
|
|
33
|
+
for (const step of steps) {
|
|
34
|
+
if (opts?.maxSeq !== void 0 && step.seq > opts.maxSeq) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (step.entry.type === "context_epoch_started") {
|
|
38
|
+
modelProfile = step.entry.modelProfile ?? "standard";
|
|
39
|
+
modelId = step.entry.modelId;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (step.entry.type === "pi_message") {
|
|
43
|
+
messages.push(step.entry.message);
|
|
44
|
+
provenance.push(piEntryProvenance(step.entry));
|
|
45
|
+
seqs.push(step.seq);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (step.entry.type === "authorization_completed") {
|
|
49
|
+
messages.push(
|
|
50
|
+
authorizationObservationMessage(step.entry, step.createdAtMs)
|
|
51
|
+
);
|
|
52
|
+
provenance.push(contextProvenance);
|
|
53
|
+
seqs.push(step.seq);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { messages, provenance, seqs, modelProfile, modelId };
|
|
57
|
+
}
|
|
58
|
+
function connectedMcpProvidersFromSteps(steps) {
|
|
59
|
+
const providers = /* @__PURE__ */ new Set();
|
|
60
|
+
for (const step of steps) {
|
|
61
|
+
if (step.entry.type === "mcp_provider_connected") {
|
|
62
|
+
providers.add(step.entry.provider);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return [...providers].sort((left, right) => left.localeCompare(right));
|
|
66
|
+
}
|
|
67
|
+
function isUserMessage(message) {
|
|
68
|
+
return message.role === "user";
|
|
69
|
+
}
|
|
70
|
+
function countMatchingPrefix(left, right) {
|
|
71
|
+
const limit = Math.min(left.length, right.length);
|
|
72
|
+
for (let index = 0; index < limit; index += 1) {
|
|
73
|
+
if (!isDeepStrictEqual(left[index], right[index])) {
|
|
74
|
+
return index;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return limit;
|
|
78
|
+
}
|
|
79
|
+
function resolveCommitProvenance(args) {
|
|
80
|
+
if (args.explicitProvenance) {
|
|
81
|
+
if (args.explicitProvenance.length !== args.nextMessages.length) {
|
|
82
|
+
throw new Error("commit provenance must align one-to-one with messages");
|
|
83
|
+
}
|
|
84
|
+
return args.explicitProvenance;
|
|
85
|
+
}
|
|
86
|
+
const matchingPrefix = args.matchingPrefix;
|
|
87
|
+
const provenance = args.nextMessages.map(
|
|
88
|
+
(_, index) => index < matchingPrefix ? args.existing.provenance[index] ?? contextProvenance : contextProvenance
|
|
89
|
+
);
|
|
90
|
+
if (args.newMessageProvenance) {
|
|
91
|
+
for (let index = args.nextMessages.length - 1; index >= matchingPrefix; index -= 1) {
|
|
92
|
+
if (isUserMessage(args.nextMessages[index])) {
|
|
93
|
+
provenance[index] = args.newMessageProvenance;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (args.trailingMessageProvenance) {
|
|
99
|
+
if (args.trailingMessageProvenance.length > provenance.length) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"trailing commit provenance cannot exceed committed messages"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const newMessageCount = args.nextMessages.length - matchingPrefix;
|
|
105
|
+
if (args.trailingMessageProvenance.length > newMessageCount) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
"trailing commit provenance must align to newly committed messages"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const start = provenance.length - args.trailingMessageProvenance.length;
|
|
111
|
+
args.trailingMessageProvenance.forEach((entry, offset) => {
|
|
112
|
+
provenance[start + offset] = entry;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return provenance;
|
|
116
|
+
}
|
|
117
|
+
async function importLegacyIfNeeded(args) {
|
|
118
|
+
await ensureLegacyConversationImport({ conversationId: args.conversationId });
|
|
119
|
+
}
|
|
120
|
+
async function loadProjection(args) {
|
|
121
|
+
await importLegacyIfNeeded(args);
|
|
122
|
+
const steps = await getAgentStepStore().loadCurrentEpoch(args.conversationId);
|
|
123
|
+
return projectSteps(steps).messages;
|
|
124
|
+
}
|
|
125
|
+
async function loadConversationProjection(args) {
|
|
126
|
+
await importLegacyIfNeeded(args);
|
|
127
|
+
const steps = await getAgentStepStore().loadCurrentEpoch(args.conversationId);
|
|
128
|
+
const { messages, provenance, modelProfile, modelId } = projectSteps(steps);
|
|
129
|
+
return { messages, provenance, modelProfile, modelId };
|
|
130
|
+
}
|
|
131
|
+
async function openConversationProjection(args) {
|
|
132
|
+
await importLegacyIfNeeded(args);
|
|
133
|
+
const stepStore = getAgentStepStore();
|
|
134
|
+
const steps = await stepStore.loadCurrentEpoch(args.conversationId);
|
|
135
|
+
const projection = projectSteps(steps);
|
|
136
|
+
if (steps.some(
|
|
137
|
+
(step) => step.entry.type === "context_epoch_started" || step.entry.type === "pi_message"
|
|
138
|
+
)) {
|
|
139
|
+
return projection;
|
|
140
|
+
}
|
|
141
|
+
await stepStore.startEpoch(args.conversationId, {
|
|
142
|
+
reason: "initial",
|
|
143
|
+
modelProfile: "standard",
|
|
144
|
+
modelId: args.modelId,
|
|
145
|
+
messages: []
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
messages: projection.messages,
|
|
149
|
+
provenance: projection.provenance,
|
|
150
|
+
modelProfile: "standard",
|
|
151
|
+
modelId: args.modelId
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async function loadTurnProjection(args) {
|
|
155
|
+
await importLegacyIfNeeded(args);
|
|
156
|
+
const stepStore = getAgentStepStore();
|
|
157
|
+
if (args.committedSeq < 0) {
|
|
158
|
+
return projectSteps(await stepStore.loadCurrentEpoch(args.conversationId));
|
|
159
|
+
}
|
|
160
|
+
const history = await stepStore.loadHistory(args.conversationId);
|
|
161
|
+
const committedStep = history.find((step) => step.seq === args.committedSeq);
|
|
162
|
+
if (!committedStep) {
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
const epochSteps = history.filter(
|
|
166
|
+
(step) => step.contextEpoch === committedStep.contextEpoch
|
|
167
|
+
);
|
|
168
|
+
return args.includeTail ? projectSteps(epochSteps) : projectSteps(epochSteps, { maxSeq: args.committedSeq });
|
|
169
|
+
}
|
|
170
|
+
async function loadConnectedMcpProviders(args) {
|
|
171
|
+
await importLegacyIfNeeded(args);
|
|
172
|
+
const steps = await getAgentStepStore().loadCurrentEpoch(args.conversationId);
|
|
173
|
+
return connectedMcpProvidersFromSteps(steps);
|
|
174
|
+
}
|
|
175
|
+
function messageTimestamp(message) {
|
|
176
|
+
const timestamp = message.timestamp;
|
|
177
|
+
return typeof timestamp === "number" ? timestamp : Date.now();
|
|
178
|
+
}
|
|
179
|
+
async function commitMessages(args) {
|
|
180
|
+
const stepStore = getAgentStepStore();
|
|
181
|
+
const currentSteps = await stepStore.loadCurrentEpoch(args.conversationId);
|
|
182
|
+
const existing = projectSteps(currentSteps);
|
|
183
|
+
const matchingPrefix = countMatchingPrefix(existing.messages, args.messages);
|
|
184
|
+
const nextProvenance = resolveCommitProvenance({
|
|
185
|
+
existing,
|
|
186
|
+
nextMessages: args.messages,
|
|
187
|
+
matchingPrefix,
|
|
188
|
+
...args.provenance ? { explicitProvenance: args.provenance } : {},
|
|
189
|
+
...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
|
|
190
|
+
...args.newMessageProvenance ? { newMessageProvenance: args.newMessageProvenance } : {}
|
|
191
|
+
});
|
|
192
|
+
if (currentSteps.length === 0) {
|
|
193
|
+
await stepStore.startEpoch(args.conversationId, {
|
|
194
|
+
reason: "initial",
|
|
195
|
+
modelProfile: "standard",
|
|
196
|
+
modelId: args.modelId,
|
|
197
|
+
messages: args.messages.map((message, index) => ({
|
|
198
|
+
message,
|
|
199
|
+
createdAtMs: messageTimestamp(message),
|
|
200
|
+
provenance: nextProvenance[index]
|
|
201
|
+
}))
|
|
202
|
+
});
|
|
203
|
+
} else if (matchingPrefix === existing.messages.length) {
|
|
204
|
+
const newMessages = args.messages.slice(matchingPrefix);
|
|
205
|
+
await stepStore.append(
|
|
206
|
+
args.conversationId,
|
|
207
|
+
newMessages.map((message, index) => ({
|
|
208
|
+
entry: {
|
|
209
|
+
type: "pi_message",
|
|
210
|
+
message,
|
|
211
|
+
provenance: nextProvenance[matchingPrefix + index]
|
|
212
|
+
},
|
|
213
|
+
createdAtMs: messageTimestamp(message)
|
|
214
|
+
}))
|
|
215
|
+
);
|
|
216
|
+
} else {
|
|
217
|
+
await stepStore.startEpoch(args.conversationId, {
|
|
218
|
+
reason: "rollback",
|
|
219
|
+
modelProfile: existing.modelProfile,
|
|
220
|
+
modelId: args.modelId,
|
|
221
|
+
messages: args.messages.map((message, index) => ({
|
|
222
|
+
message,
|
|
223
|
+
createdAtMs: messageTimestamp(message),
|
|
224
|
+
provenance: nextProvenance[index]
|
|
225
|
+
}))
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const committed = projectSteps(
|
|
229
|
+
await stepStore.loadCurrentEpoch(args.conversationId)
|
|
230
|
+
);
|
|
231
|
+
return {
|
|
232
|
+
committedSeq: committed.seqs.at(-1) ?? -1,
|
|
233
|
+
messageSeqs: committed.seqs,
|
|
234
|
+
provenance: nextProvenance
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
async function recordMcpProviderConnected(args) {
|
|
238
|
+
const stepStore = getAgentStepStore();
|
|
239
|
+
const steps = await stepStore.loadCurrentEpoch(args.conversationId);
|
|
240
|
+
if (connectedMcpProvidersFromSteps(steps).includes(args.provider)) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
await stepStore.append(args.conversationId, [
|
|
244
|
+
{
|
|
245
|
+
entry: { type: "mcp_provider_connected", provider: args.provider },
|
|
246
|
+
createdAtMs: Date.now()
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
async function recordAuthorizationRequested(args) {
|
|
251
|
+
const stepStore = getAgentStepStore();
|
|
252
|
+
const steps = await stepStore.loadCurrentEpoch(args.conversationId);
|
|
253
|
+
if (steps.some(
|
|
254
|
+
(step) => step.entry.type === "authorization_requested" && step.entry.authorizationId === args.authorizationId
|
|
255
|
+
)) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await stepStore.append(args.conversationId, [
|
|
259
|
+
{
|
|
260
|
+
entry: {
|
|
261
|
+
type: "authorization_requested",
|
|
262
|
+
kind: args.kind,
|
|
263
|
+
provider: args.provider,
|
|
264
|
+
actorId: args.actorId,
|
|
265
|
+
authorizationId: args.authorizationId,
|
|
266
|
+
delivery: args.delivery
|
|
267
|
+
},
|
|
268
|
+
createdAtMs: Date.now()
|
|
269
|
+
}
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
async function recordAuthorizationCompleted(args) {
|
|
273
|
+
const stepStore = getAgentStepStore();
|
|
274
|
+
const steps = await stepStore.loadCurrentEpoch(args.conversationId);
|
|
275
|
+
if (steps.some(
|
|
276
|
+
(step) => step.entry.type === "authorization_completed" && step.entry.authorizationId === args.authorizationId
|
|
277
|
+
)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
await stepStore.append(args.conversationId, [
|
|
281
|
+
{
|
|
282
|
+
entry: {
|
|
283
|
+
type: "authorization_completed",
|
|
284
|
+
kind: args.kind,
|
|
285
|
+
provider: args.provider,
|
|
286
|
+
actorId: args.actorId,
|
|
287
|
+
authorizationId: args.authorizationId
|
|
288
|
+
},
|
|
289
|
+
createdAtMs: Date.now()
|
|
290
|
+
}
|
|
291
|
+
]);
|
|
292
|
+
}
|
|
293
|
+
async function recordToolExecutionStarted(args) {
|
|
294
|
+
await getAgentStepStore().append(args.conversationId, [
|
|
295
|
+
{
|
|
296
|
+
entry: {
|
|
297
|
+
type: "tool_execution_started",
|
|
298
|
+
toolCallId: args.toolCallId,
|
|
299
|
+
toolName: args.toolName,
|
|
300
|
+
...args.args !== void 0 ? { args: args.args } : {}
|
|
301
|
+
},
|
|
302
|
+
createdAtMs: args.createdAtMs ?? Date.now()
|
|
303
|
+
}
|
|
304
|
+
]);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
projectSteps,
|
|
309
|
+
loadProjection,
|
|
310
|
+
loadConversationProjection,
|
|
311
|
+
openConversationProjection,
|
|
312
|
+
loadTurnProjection,
|
|
313
|
+
loadConnectedMcpProviders,
|
|
314
|
+
commitMessages,
|
|
315
|
+
recordMcpProviderConnected,
|
|
316
|
+
recordAuthorizationRequested,
|
|
317
|
+
recordAuthorizationCompleted,
|
|
318
|
+
recordToolExecutionStarted
|
|
319
|
+
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SANDBOX_WORKSPACE_ROOT
|
|
2
|
+
SANDBOX_WORKSPACE_ROOT
|
|
3
|
+
} from "./chunk-G3E7SCME.js";
|
|
4
|
+
import {
|
|
3
5
|
sleep
|
|
4
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4ZNGQH7C.js";
|
|
5
7
|
import {
|
|
6
8
|
getStateAdapter,
|
|
7
9
|
toOptionalTrimmed
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EEZCY5WX.js";
|
|
9
11
|
import {
|
|
10
12
|
pluginCatalogRuntime
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-LMJPRYHP.js";
|
|
12
14
|
import {
|
|
13
15
|
withSpan
|
|
14
16
|
} from "./chunk-I35CTGPO.js";
|
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
} from "./chunk-I35CTGPO.js";
|
|
7
7
|
import {
|
|
8
8
|
discoverInstalledPluginPackageContent,
|
|
9
|
-
normalizePluginPackageNames
|
|
9
|
+
normalizePluginPackageNames
|
|
10
|
+
} from "./chunk-B3IT5END.js";
|
|
11
|
+
import {
|
|
10
12
|
pluginRoots
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-3V7OFJZC.js";
|
|
12
14
|
|
|
13
15
|
// src/chat/plugins/registry.ts
|
|
14
16
|
import { readFileSync, readdirSync, statSync } from "fs";
|