






















@@ -574,39 +574,43 @@ export function createSessionStatusTool(opts?: {
574574if (isImplicitRunSessionStatus) {
575575requestedKeyRaw = opts?.runSessionKey;
576576}
577+let requestedKeyInput = requestedKeyRaw?.trim() ?? "";
577578578579// Track whether this is a semantic-current request (literal "current" or a
579580// current-client alias) BEFORE any rewrite, so visibility treats it as self.
580581const isSemanticCurrentRequest =
581-requestedKeyRaw === "current" ||
582+requestedKeyInput === "current" ||
582583isImplicitRunSessionStatus ||
583584Boolean(
584585resolveCurrentSessionClientAlias({
585-key: requestedKeyRaw ?? "",
586+key: requestedKeyInput,
586587requesterInternalKey: effectiveRequesterKey,
587588}),
588589);
589590590591// Resolve semantic "current" to the live run session key for lookup purposes (#76708).
591592// In sandboxed channel runs there may be no separate runSessionKey because the sandbox
592593// key already is the live requester; avoid probing literal "current" through the gateway.
593-if (requestedKeyRaw === "current" && (opts?.runSessionKey || opts?.sandboxed === true)) {
594+if (requestedKeyInput === "current" && (opts?.runSessionKey || opts?.sandboxed === true)) {
594595requestedKeyRaw = opts.runSessionKey ?? effectiveRequesterKey;
596+requestedKeyInput = requestedKeyRaw?.trim() ?? "";
595597}
596598597599const currentSessionAlias = resolveCurrentSessionClientAlias({
598-key: requestedKeyRaw ?? "",
600+key: requestedKeyInput,
599601requesterInternalKey: effectiveRequesterKey,
600602});
601603if (currentSessionAlias) {
602604requestedKeyRaw = opts?.runSessionKey ?? currentSessionAlias;
605+requestedKeyInput = requestedKeyRaw?.trim() ?? "";
603606}
604-const requestedKeyInput = requestedKeyRaw?.trim() ?? "";
607+const effectiveRequesterLookupKey = effectiveRequesterKey.trim();
605608let resolvedViaSessionId = false;
606609let resolvedViaImplicitCurrentFallback = false;
607-if (!requestedKeyRaw?.trim()) {
610+if (!requestedKeyInput) {
608611throw new Error("sessionKey required");
609612}
613+requestedKeyRaw = requestedKeyInput;
610614const ensureAgentAccess = (targetAgentId: string) => {
611615if (targetAgentId === requesterAgentId) {
612616return;
@@ -622,20 +626,20 @@ export function createSessionStatusTool(opts?: {
622626}
623627};
624628625-if (requestedKeyRaw.startsWith("agent:") && !isSemanticCurrentRequest) {
626-const requestedAgentId = resolveAgentIdFromSessionKey(requestedKeyRaw);
629+if (requestedKeyInput.startsWith("agent:") && !isSemanticCurrentRequest) {
630+const requestedAgentId = resolveAgentIdFromSessionKey(requestedKeyInput);
627631ensureAgentAccess(requestedAgentId);
628632const access = visibilityGuard.check(
629-normalizeVisibilityTargetSessionKey(requestedKeyRaw, requestedAgentId),
633+normalizeVisibilityTargetSessionKey(requestedKeyInput, requestedAgentId),
630634);
631635if (!access.allowed) {
632636throw new Error(access.error);
633637}
634638}
635639636-const isExplicitAgentKey = requestedKeyRaw.startsWith("agent:");
640+const isExplicitAgentKey = requestedKeyInput.startsWith("agent:");
637641let agentId = isExplicitAgentKey
638- ? resolveAgentIdFromSessionKey(requestedKeyRaw)
642+ ? resolveAgentIdFromSessionKey(requestedKeyInput)
639643 : requesterAgentId;
640644let storePath = resolveStorePath(cfg.session?.store, { agentId });
641645let store = loadSessionStore(storePath);
@@ -652,15 +656,15 @@ export function createSessionStatusTool(opts?: {
652656 alias,
653657 mainKey,
654658requesterInternalKey: storeScopedRequesterKey,
655-includeAliasFallback: requestedKeyRaw !== "current",
659+includeAliasFallback: requestedKeyInput !== "current",
656660});
657661658662if (
659663!resolved &&
660-(requestedKeyRaw === "current" || shouldResolveSessionIdInput(requestedKeyRaw))
664+(requestedKeyInput === "current" || shouldResolveSessionIdInput(requestedKeyInput))
661665) {
662666const resolvedSession = await resolveSessionReference({
663-sessionKey: requestedKeyRaw,
667+sessionKey: requestedKeyInput,
664668 alias,
665669 mainKey,
666670requesterInternalKey: effectiveRequesterKey,
@@ -671,7 +675,7 @@ export function createSessionStatusTool(opts?: {
671675 resolvedSession,
672676requesterSessionKey: effectiveRequesterKey,
673677restrictToSpawned: opts?.sandboxed === true,
674-visibilitySessionKey: requestedKeyRaw,
678+visibilitySessionKey: requestedKeyInput,
675679});
676680if (!visibleSession.ok) {
677681throw new Error("Session status visibility is restricted to the current session tree.");
@@ -680,6 +684,7 @@ export function createSessionStatusTool(opts?: {
680684ensureAgentAccess(resolveAgentIdFromSessionKey(visibleSession.key));
681685resolvedViaSessionId = true;
682686requestedKeyRaw = visibleSession.key;
687+requestedKeyInput = requestedKeyRaw.trim();
683688agentId = resolveAgentIdFromSessionKey(visibleSession.key);
684689storePath = resolveStorePath(cfg.session?.store, { agentId });
685690store = loadSessionStore(storePath);
@@ -700,7 +705,18 @@ export function createSessionStatusTool(opts?: {
700705}
701706}
702707703-if (!resolved && requestedKeyRaw === "current") {
708+if (!resolved && requestedKeyInput === "current" && effectiveRequesterLookupKey) {
709+resolved = resolveSessionEntry({
710+ store,
711+keyRaw: effectiveRequesterLookupKey,
712+ alias,
713+ mainKey,
714+requesterInternalKey: storeScopedRequesterKey,
715+includeAliasFallback: false,
716+});
717+}
718+719+if (!resolved && requestedKeyInput === "current") {
704720resolved = resolveSessionEntry({
705721 store,
706722keyRaw: requestedKeyRaw,
@@ -732,12 +748,15 @@ export function createSessionStatusTool(opts?: {
732748}
733749734750if (!resolved) {
751+const runSessionFallbackKey = opts?.runSessionKey?.trim();
735752const fallback = resolveImplicitCurrentSessionFallback({
736753allowFallback: isSemanticCurrentRequest || requestedKeyParam === undefined,
737754fallbackKey:
738-(isSemanticCurrentRequest || isImplicitRunSessionStatus) && opts?.runSessionKey
739- ? opts.runSessionKey
740- : storeScopedRequesterKey,
755+(isSemanticCurrentRequest || isImplicitRunSessionStatus) && runSessionFallbackKey
756+ ? runSessionFallbackKey
757+ : isSemanticCurrentRequest
758+ ? effectiveRequesterLookupKey
759+ : storeScopedRequesterKey,
741760});
742761if (fallback) {
743762resolved = fallback;
@@ -746,8 +765,8 @@ export function createSessionStatusTool(opts?: {
746765}
747766748767if (!resolved) {
749-const kind = shouldResolveSessionIdInput(requestedKeyRaw) ? "sessionId" : "sessionKey";
750-throw new Error(`Unknown ${kind}: ${requestedKeyRaw}`);
768+const kind = shouldResolveSessionIdInput(requestedKeyInput) ? "sessionId" : "sessionKey";
769+throw new Error(`Unknown ${kind}: ${requestedKeyInput}`);
751770}
752771753772// Preserve caller-scoped raw-key/current lookups as "self" for visibility checks.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。