






















@@ -1482,18 +1482,8 @@ async function persistExpectedSessionTranscriptTurn(
14821482export async function resolveSessionTranscriptRuntimeTarget(
14831483scope: SessionTranscriptRuntimeScope,
14841484): Promise<SessionTranscriptRuntimeTarget> {
1485-const agentId = scope.agentId ?? resolveAgentIdFromSessionKey(scope.sessionKey);
1486-if (!agentId) {
1487-throw new Error(`Cannot resolve transcript scope without an agent id: ${scope.sessionKey}`);
1488-}
1489-const sessionStore = scope.storePath
1490- ? loadSessionStore(scope.storePath, { skipCache: true })
1491- : undefined;
1492-const resolvedStoreEntry = sessionStore
1493- ? resolveSessionStoreEntry({ store: sessionStore, sessionKey: scope.sessionKey })
1494- : undefined;
1495-const sessionEntry = resolvedStoreEntry?.existing ?? loadSessionEntry(scope);
1496-const sessionKey = resolvedStoreEntry?.normalizedKey ?? scope.sessionKey;
1485+const { agentId, sessionEntry, sessionKey, sessionStore } =
1486+resolveSessionTranscriptRuntimeContext(scope);
14971487if (scope.sessionFile?.trim()) {
14981488return {
14991489 agentId,
@@ -1552,18 +1542,8 @@ export async function resolveSessionTranscriptRuntimeTarget(
15521542export async function resolveSessionTranscriptRuntimeReadTarget(
15531543scope: SessionTranscriptRuntimeScope,
15541544): Promise<SessionTranscriptRuntimeTarget> {
1555-const agentId = scope.agentId ?? resolveAgentIdFromSessionKey(scope.sessionKey);
1556-if (!agentId) {
1557-throw new Error(`Cannot resolve transcript scope without an agent id: ${scope.sessionKey}`);
1558-}
1559-const sessionStore = scope.storePath
1560- ? loadSessionStore(scope.storePath, { skipCache: true })
1561- : undefined;
1562-const resolvedStoreEntry = sessionStore
1563- ? resolveSessionStoreEntry({ store: sessionStore, sessionKey: scope.sessionKey })
1564- : undefined;
1565-const sessionEntry = resolvedStoreEntry?.existing ?? loadSessionEntry(scope);
1566-const sessionKey = resolvedStoreEntry?.normalizedKey ?? scope.sessionKey;
1545+const { agentId, sessionEntry, sessionKey, sessionStore } =
1546+resolveSessionTranscriptRuntimeContext(scope);
15671547if (scope.sessionFile?.trim()) {
15681548return {
15691549 agentId,
@@ -1599,6 +1579,36 @@ export async function resolveSessionTranscriptRuntimeReadTarget(
15991579};
16001580}
160115811582+type SessionTranscriptRuntimeContext = {
1583+agentId: string;
1584+sessionEntry: SessionEntry | undefined;
1585+sessionKey: string;
1586+sessionStore: Record<string, SessionEntry> | undefined;
1587+};
1588+1589+function resolveSessionTranscriptRuntimeContext(
1590+scope: SessionTranscriptRuntimeScope,
1591+): SessionTranscriptRuntimeContext {
1592+const agentId = scope.agentId ?? resolveAgentIdFromSessionKey(scope.sessionKey);
1593+if (!agentId) {
1594+throw new Error(`Cannot resolve transcript scope without an agent id: ${scope.sessionKey}`);
1595+}
1596+const sessionStore = scope.storePath
1597+ ? loadSessionStore(scope.storePath, { skipCache: true })
1598+ : undefined;
1599+const resolvedStoreEntry = sessionStore
1600+ ? resolveSessionStoreEntry({ store: sessionStore, sessionKey: scope.sessionKey })
1601+ : undefined;
1602+const sessionEntry = resolvedStoreEntry?.existing ?? loadSessionEntry(scope);
1603+const sessionKey = resolvedStoreEntry?.normalizedKey ?? scope.sessionKey;
1604+return {
1605+ agentId,
1606+ sessionKey,
1607+ sessionStore,
1608+ sessionEntry,
1609+};
1610+}
1611+16021612/**
16031613 * Resolves the current file-backed target for read-only transcript callers.
16041614 * Unlike writer/runtime resolution, this does not persist missing sessionFile
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。