Skip to content
Merged
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
1 change: 0 additions & 1 deletion apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,6 @@ export default function ChatView(props: ChatViewProps) {
interactionMode,
phase,
activeProject,
activeProjectRef,
activeThreadBranch,
settings,
messageDraftActions,
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/components/ComposerPromptEditorTiptap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import type {
AssistantCitation,
ComposerContextClipboardFragment,
EnvironmentId,
ModelSelection,
ProjectId,
ServerProviderSkill,
ThreadId,
} from "@t3tools/contracts";
Expand Down Expand Up @@ -200,6 +202,8 @@ export interface ComposerPromptEditorProps {
export type ComposerCitationDestinations = {
environmentId: EnvironmentId;
threadId: ThreadId;
projectId: ProjectId;
modelSelection: ModelSelection;
followUpBehavior: "queue" | "steer";
onSubmit: (
destination: Exclude<CitationDestination, { kind: "here" }>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {
ASSISTANT_CITATION_MAX_COMMENT_LENGTH,
EnvironmentId,
MessageId,
ProjectId,
ProviderInstanceId,
ThreadId,
} from "@t3tools/contracts";
import { useState, type ReactNode } from "react";
import { describe, expect, it, vi } from "vite-plus/test";
import { userEvent } from "vite-plus/test/browser";
import { page, userEvent } from "vite-plus/test/browser";

import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
import "~/index.css";
Expand All @@ -16,10 +18,11 @@ const mocks = vi.hoisted(() => ({
observeSource: vi.fn(),
dispose: vi.fn(),
threads: [] as unknown[],
projects: [] as unknown[],
}));
vi.mock(import("~/state/entities"), async (importOriginal) => ({
...(await importOriginal()),
useProjects: () => [],
useProjects: () => mocks.projects as never,
useThreadShells: () => mocks.threads as never,
useThreadShell: (ref) =>
(ref
Expand Down Expand Up @@ -56,6 +59,7 @@ function setup() {
mocks.observeSource.mockReset().mockReturnValue(mocks.dispose);
mocks.dispose.mockClear();
mocks.threads = [];
mocks.projects = [];
const source = document.createElement("p");
source.textContent = "hello";
document.body.append(source);
Expand Down Expand Up @@ -205,7 +209,80 @@ describe("citation comment Enter", () => {
});
});

const destinationDefaults = {
environmentId: citation.environmentId,
threadId: citation.threadId,
projectId: ProjectId.make("current-project"),
modelSelection: {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5.4",
options: [{ id: "reasoningEffort", value: "high" }],
},
};

function project(id: string, title: string) {
return {
environmentId: citation.environmentId,
id: ProjectId.make(id),
title,
workspaceRoot: `/repo/${id}`,
faviconPath: null,
projectIcon: { kind: "monogram", text: title[0], color: "blue" },
};
}

async function clickItem(text: string) {
const item = await vi.waitFor(() => {
const match = [...document.querySelectorAll("[data-slot=command-item]")].find((element) =>
element.textContent?.includes(text),
);
expect(match, `item ${text}`).toBeDefined();
return match as HTMLElement;
});
await act(async () => item.click());
}

describe("citation comment destinations", () => {
it("starts a new thread in the picked project with this thread's model", async () => {
localStorage.clear();
using source = setup();
mocks.projects = [project("current-project", "t3code"), project("website", "website")];
const onSubmit = vi.fn(() => true);
await using _screen = await mount(
source.sourceAnchor,
vi.fn(() => true),
vi.fn(() => true),
{
...destinationDefaults,
followUpBehavior: "queue",
onSubmit,
},
);
await typeComment("try it there");

await act(async () =>
document
.querySelector<HTMLButtonElement>('button[aria-label="Send citation to: This thread"]')!
.click(),
);
await clickItem("New thread");
await clickItem("website");

await expect
.element(page.getByRole("button", { name: /^Send citation to: New thread in website with/ }))
.toBeInTheDocument();
await clickButton("Start thread");
expect(onSubmit).toHaveBeenCalledWith(
{
kind: "new-thread",
projectId: "website",
modelSelection: destinationDefaults.modelSelection,
},
"send",
"try it there",
);
});

it("sends the quote to the chosen thread, queueing behind its running turn", async () => {
localStorage.clear();
using source = setup();
Expand All @@ -225,8 +302,7 @@ describe("citation comment destinations", () => {
const onSaveAndSend = vi.fn(() => true);
const onSubmit = vi.fn(() => true);
await using _screen = await mount(source.sourceAnchor, onSave, onSaveAndSend, {
environmentId: citation.environmentId,
threadId: citation.threadId,
...destinationDefaults,
followUpBehavior: "queue",
onSubmit,
});
Expand Down
16 changes: 13 additions & 3 deletions apps/web/src/components/chat/AssistantCitationCommentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
ASSISTANT_CITATION_MAX_COMMENT_LENGTH,
type AssistantCitation,
type EnvironmentId,
type ModelSelection,
type ProjectId,
type ThreadId,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { ChevronDownIcon } from "lucide-react";
import { useState, type MouseEvent, type Ref } from "react";
import { useRef, useState, type MouseEvent, type RefObject } from "react";

import { useLocalStorage } from "~/hooks/useLocalStorage";
import { readLocalApi } from "~/localApi";
Expand Down Expand Up @@ -55,6 +57,9 @@ type DraftChoice = { label: string; description: string };
export interface AssistantCitationDestinations {
environmentId: EnvironmentId;
threadId: ThreadId;
/** A new thread starts in this project with this model until the reader picks others. */
projectId: ProjectId;
modelSelection: ModelSelection;
followUpBehavior: "queue" | "steer";
onSubmit: (
destination: Exclude<CitationDestination, { kind: "here" }>,
Expand Down Expand Up @@ -108,7 +113,7 @@ export function AssistantCitationCommentEditor({
destinations,
}: {
citation: AssistantCitation;
inputRef?: Ref<HTMLTextAreaElement>;
inputRef?: RefObject<HTMLTextAreaElement | null>;
onSubmit: (comment: string) => boolean;
onSubmitAndSend?: (comment: string) => boolean;
/** Saves the comment into the prompt, then keeps the whole message as a thread draft. */
Expand All @@ -119,6 +124,8 @@ export function AssistantCitationCommentEditor({
destinations?: AssistantCitationDestinations | undefined;
}) {
const [comment, setComment] = useState(citation.comment ?? "");
const ownTextareaRef = useRef<HTMLTextAreaElement>(null);
const textareaRef = inputRef ?? ownTextareaRef;
const [choice, setChoice] = useLocalStorage(
SUBMIT_CHOICE_STORAGE_KEY,
"send",
Expand Down Expand Up @@ -185,7 +192,7 @@ export function AssistantCitationCommentEditor({
}}
>
<textarea
ref={inputRef}
ref={textareaRef}
aria-label="Comment on selected text"
aria-description={
enterChoice === "send"
Expand Down Expand Up @@ -227,8 +234,11 @@ export function AssistantCitationCommentEditor({
<CitationDestinationPicker
environmentId={destinations.environmentId}
currentThreadId={destinations.threadId}
defaultProjectId={destinations.projectId}
defaultModelSelection={destinations.modelSelection}
destination={destination}
onChange={setDestination}
onModelPicked={() => textareaRef.current?.focus()}
/>
</div>
) : null}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4932,10 +4932,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
}
citationSendQueues={citationSendDispatchMode === "queue"}
citationDestinations={
onSendCitationElsewhere && activeThreadId
onSendCitationElsewhere && activeThreadId && activeProjectId
? {
environmentId,
threadId: activeThreadId,
projectId: activeProjectId,
modelSelection: selectedModelSelection,
followUpBehavior: settings.followUpBehavior,
onSubmit: onSendCitationElsewhere,
}
Expand Down
Loading