Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ describe("TangentChatPane", () => {
`${window.location.origin}/tangent/p?session=s&message=m`,
);
expect(agentLink).toBe(`${primeLink}&agent=a`);
const getMessageLink = Reflect.get(agent, "getMessageLink");
const otherPrime = `${window.location.origin}/tangent/p?session=other&message=mention`;
expect(getMessageLink("mention", { sessionId: "other" })).toBe(otherPrime);
expect(
getMessageLink("mention", { sessionId: "other", agentId: "research" }),
).toBe(`${otherPrime}&agent=research`);

rerender(
<TangentChatPane
Expand Down
12 changes: 9 additions & 3 deletions src/routes/v2/pages/Tangent/components/TangentChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export function TangentChatPane({
}

interface MessageLinkChatElement extends HTMLElement {
getMessageLink?: (messageId: string) => string | undefined;
getMessageLink?: (
messageId: string,
target?: { sessionId?: string; agentId?: string },
) => string | undefined;
targetMessageId?: string;
targetAgentId?: string;
}
Expand All @@ -149,8 +152,11 @@ function ChatPanel({
panel.current?.querySelector<MessageLinkChatElement>("tangent-chat");
if (!chat) return;
chat.getMessageLink = projectId
? (messageId) =>
getProjectUrl(projectId, sessionId, { messageId, agentId })
? (messageId, target) =>
getProjectUrl(projectId, target?.sessionId ?? sessionId, {
messageId,
agentId: target ? target.agentId : agentId,
})
: undefined;
chat.targetAgentId = targetAgentId;
chat.targetMessageId = targetMessageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vi.mock("@/routes/v2/pages/Tangent/context/TangentProjectContext", () => ({
useTangentProject: () => ({
openWorkareaTarget,
activeSessionId: "session-1",
projectId: "project-1",
}),
}));

Expand All @@ -36,6 +37,39 @@ function anchorProps(
};
}

describe("message sources", () => {
const Message = tangentAnchorProtocols.message;

it("links to the original message in the current project", () => {
render(
<Message
{...anchorProps({
path: "old-session/original%20message",
label: "Earlier decision",
})}
/>,
);
const url = new URL(
screen
.getByRole("link", { name: "Earlier decision" })
.getAttribute("href")!,
);
expect(url.pathname).toBe("/tangent/project-1");
expect(url.searchParams.get("session")).toBe("old-session");
expect(url.searchParams.get("message")).toBe("original message");
});

it("leaves an incomplete source as text", () => {
render(
<Message
{...anchorProps({ path: "old-session", label: "Earlier decision" })}
/>,
);
expect(screen.queryByRole("link")).toBeNull();
expect(screen.getByText("Earlier decision")).toBeInTheDocument();
});
});

describe("tangentAnchorProtocols run anchor", () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {
AnchorProtocolProps,
} from "@tangent/embed-react";

import { Link } from "@/components/ui/link";
import { useTangentProject } from "@/routes/v2/pages/Tangent/context/TangentProjectContext";
import { useOpenWorkareaTarget } from "@/routes/v2/pages/Tangent/hooks/useOpenWorkareaTarget";
import { chatAnchorProtocols } from "@/routes/v2/shared/components/AiChat/components/chatAnchorProtocols";
import { ChatEntityChip } from "@/routes/v2/shared/components/AiChat/components/ChatEntityChip";
Expand All @@ -14,6 +16,7 @@ import {
isWorkareaTargetString,
parseWorkareaTarget,
} from "@/services/projects/resourceTarget";
import { getProjectUrl } from "@/utils/URL";

function runTarget(path: string): WorkareaTarget | undefined {
const candidate = `run://${path}`;
Expand Down Expand Up @@ -57,6 +60,20 @@ function decodedLinkAddress(href: string): string {
});
}

function MessageAnchor({ path, label }: AnchorProtocolProps) {
const { projectId } = useTangentProject();
const [session, message, extra] = path.split("/");
if (!session || !message || extra !== undefined) return label;
const href = getProjectUrl(projectId, decodedLinkAddress(session), {
messageId: decodedLinkAddress(message),
});
return (
<Link href={href} size="sm">
{label}
</Link>
);
}

function WorkareaTargetAnchor({ href, protocol, label }: AnchorProtocolProps) {
const open = useOpenWorkareaTarget({ fromChat: true });
const address = decodedLinkAddress(href);
Expand All @@ -81,6 +98,7 @@ function WorkareaTargetAnchor({ href, protocol, label }: AnchorProtocolProps) {
export const tangentAnchorProtocols: AnchorProtocolMap = {
...chatAnchorProtocols,
run: RunAnchor,
message: MessageAnchor,
pipeline: WorkareaTargetAnchor,
document: WorkareaTargetAnchor,
};
Loading