





























@@ -617,6 +617,165 @@ describe("session_status tool", () => {
617617expect(details.statusText).toContain("OpenClaw");
618618});
619619620+it("reports origin, active, and persisted delivery route metadata for semantic current", async () => {
621+const sessionKey = "agent:main:discord:channel:1489550370136129537";
622+resetSessionStore({
623+[sessionKey]: {
624+sessionId: "s-discord-origin-webchat-active",
625+updatedAt: 10,
626+origin: { provider: "discord", accountId: "bot-primary" },
627+deliveryContext: {
628+channel: "discord",
629+to: "channel:1489550370136129537",
630+accountId: "bot-primary",
631+threadId: "thread-origin",
632+},
633+},
634+});
635+636+const tool = createSessionStatusTool({
637+agentSessionKey: sessionKey,
638+runSessionKey: sessionKey,
639+activeDeliveryContext: {
640+channel: "webchat",
641+to: "control-ui-conversation",
642+accountId: "browser",
643+threadId: "webchat-thread",
644+},
645+config: mockConfig as never,
646+});
647+648+const result = await tool.execute("call-current-route-context", { sessionKey: "current" });
649+const details = result.details as {
650+ok?: boolean;
651+sessionKey?: string;
652+statusText?: string;
653+origin?: { provider?: string; accountId?: string };
654+active?: { channel?: string; to?: string; accountId?: string; threadId?: string };
655+deliveryContext?: {
656+channel?: string;
657+to?: string;
658+accountId?: string;
659+threadId?: string;
660+};
661+};
662+expect(details.ok).toBe(true);
663+expect(details.sessionKey).toBe(sessionKey);
664+expect(details.origin).toEqual({ provider: "discord", accountId: "bot-primary" });
665+expect(details.active).toEqual({
666+channel: "webchat",
667+to: "control-ui-conversation",
668+accountId: "browser",
669+threadId: "webchat-thread",
670+});
671+expect(details.deliveryContext).toEqual({
672+channel: "discord",
673+to: "channel:1489550370136129537",
674+accountId: "bot-primary",
675+threadId: "thread-origin",
676+});
677+const text =
678+result.content.find((item): item is { type: "text"; text: string } => item.type === "text")
679+?.text ?? "";
680+expect(text).toContain("Route context:");
681+expect(text).toContain('"origin"');
682+expect(text).toContain('"active"');
683+expect(text).toContain('"deliveryContext"');
684+expect(details.statusText).toContain('"active"');
685+});
686+687+it("does not report an active route for explicit non-live session lookups", async () => {
688+const currentKey = "agent:main:main";
689+const targetKey = "agent:main:discord:channel:1489550370136129537";
690+resetSessionStore({
691+[currentKey]: {
692+sessionId: "s-main",
693+updatedAt: 5,
694+},
695+[targetKey]: {
696+sessionId: "s-target",
697+updatedAt: 10,
698+deliveryContext: {
699+channel: "discord",
700+to: "channel:1489550370136129537",
701+},
702+},
703+});
704+mockConfig = {
705+ ...mockConfig,
706+tools: { sessions: { visibility: "all" }, agentToAgent: { enabled: true, allow: ["*"] } },
707+};
708+709+const tool = createSessionStatusTool({
710+agentSessionKey: currentKey,
711+runSessionKey: currentKey,
712+activeDeliveryContext: {
713+channel: "webchat",
714+to: "control-ui-conversation",
715+},
716+config: mockConfig as never,
717+});
718+719+const result = await tool.execute("call-explicit-non-live-route-context", {
720+sessionKey: targetKey,
721+});
722+const details = result.details as {
723+origin?: { provider?: string };
724+active?: { channel?: string };
725+deliveryContext?: { channel?: string; to?: string };
726+};
727+expect(details.origin).toEqual({ provider: "discord" });
728+expect(details.active).toBeUndefined();
729+expect(details.deliveryContext).toEqual({
730+channel: "discord",
731+to: "channel:1489550370136129537",
732+});
733+});
734+735+it("does not report an active route for an explicit stale policy-key lookup", async () => {
736+const policyKey = "agent:main:telegram:default:direct:1234";
737+const runKey = "agent:main:main";
738+resetSessionStore({
739+[policyKey]: {
740+sessionId: "s-policy",
741+updatedAt: 5,
742+deliveryContext: {
743+channel: "telegram",
744+to: "telegram:direct:1234",
745+},
746+},
747+[runKey]: {
748+sessionId: "s-run",
749+updatedAt: 10,
750+},
751+});
752+753+const tool = createSessionStatusTool({
754+agentSessionKey: policyKey,
755+runSessionKey: runKey,
756+activeDeliveryContext: {
757+channel: "webchat",
758+to: "control-ui-conversation",
759+},
760+config: mockConfig as never,
761+});
762+763+const result = await tool.execute("call-explicit-stale-policy-key-route-context", {
764+sessionKey: policyKey,
765+});
766+const details = result.details as {
767+sessionKey?: string;
768+active?: { channel?: string };
769+deliveryContext?: { channel?: string; to?: string };
770+};
771+expect(details.sessionKey).toBe(policyKey);
772+expect(details.active).toBeUndefined();
773+expect(details.deliveryContext).toEqual({
774+channel: "telegram",
775+to: "telegram:direct:1234",
776+});
777+});
778+620779it("rejects explicit cross-session key under tree visibility even when it equals runSessionKey (#76708)", async () => {
621780resetSessionStore({
622781"agent:main:telegram:default:direct:1234": {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。