Open History to see the last commit
1import {
2 CommandId,
3 MessageId,
4 ThreadId,
5 type ChatAttachment,
6 type ModelSelection,
7 type OrchestrationMessageContext,
8 type ProjectId,
9 type ProviderInteractionMode,
10 type RuntimeMode,
11} from "@t3tools/contracts";
12import {
13 deriveThreadTitleSeed,
14 threadTitleTextFromPrompt,
15} from "@t3tools/client-runtime/operations";
16import { msg } from "gt-react-native";
17
18import { m } from "../i18n/messages";
19import type { UploadedMobileAttachment } from "./attachmentUpload";
20
21export interface ProjectThreadStartTurnSpec {
22 readonly projectId: ProjectId;
23 readonly projectCwd: string;
24 readonly threadId: string;
25 readonly commandId: string;
26 readonly messageId: string;
27 readonly createdAt: string;
28 readonly text: string;
29 readonly titleText?: string;
30 readonly context?: OrchestrationMessageContext;
31 readonly uploadedAttachments: ReadonlyArray<UploadedMobileAttachment | ChatAttachment>;
32 readonly modelSelection: ModelSelection;
33 readonly runtimeMode: RuntimeMode;
34 readonly interactionMode: ProviderInteractionMode;
35 readonly workspaceMode: "local" | "worktree";
36 readonly branch: string | null;
37 readonly worktreePath: string | null;
38 readonly startFromOrigin: boolean;
39 /** Tracked repositories a new worktree takes, by path; absent leaves the choice to the server. */
40 readonly worktreeRepositories?: ReadonlyArray<string>;
41 readonly worktreeBranchName: string;
42}
43
44export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpec) {
45 const title = deriveThreadTitleSeed(
46 { text: spec.titleText ?? spec.text, attachments: spec.uploadedAttachments },
47 m,
48 );
49 const isWorktree = spec.workspaceMode === "worktree";
50 return {
51 commandId: CommandId.make(spec.commandId),
52 creationSource: "mobile" as const,
53 threadId: ThreadId.make(spec.threadId),
54 message: {
55 messageId: MessageId.make(spec.messageId),
56 role: "user" as const,
57 text: spec.text,
58 ...(spec.context ? { context: spec.context } : {}),
59 attachments: spec.uploadedAttachments,
60 },
61 modelSelection: spec.modelSelection,
62 titleSeed: title,
63 runtimeMode: spec.runtimeMode,
64 interactionMode: spec.interactionMode,
65 bootstrap: {
66 createThread: {
67 projectId: spec.projectId,
68 title,
69 modelSelection: spec.modelSelection,
70 runtimeMode: spec.runtimeMode,
71 interactionMode: spec.interactionMode,
72 branch: spec.branch,
73 worktreePath: isWorktree ? null : spec.worktreePath,
74 createdAt: spec.createdAt,
75 },
76 ...(isWorktree
77 ? {
78 prepareWorktree: {
79 projectCwd: spec.projectCwd,
80 // The launch needs a base ref; the server ignores it for a plain project folder.
81 baseBranch: spec.branch ?? "HEAD",
82 branch: spec.worktreeBranchName,
83 ...(spec.startFromOrigin ? { startFromOrigin: true } : {}),
84 ...(spec.worktreeRepositories === undefined
85 ? {}
86 : { repositories: spec.worktreeRepositories.map((path) => ({ path })) }),
87 },
88 runSetupScript: true,
89 }
90 : {}),
91 },
92 createdAt: spec.createdAt,
93 };
94}
95
96export function deriveThreadTitleFromPrompt(value: string): string {
97 const title = threadTitleTextFromPrompt(value, m) || m(msg("New thread"));
98 return title.length <= 72 ? title : `${title.slice(0, 69).trimEnd()}...`;
99}