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";
16
17import type { UploadedMobileAttachment } from "./attachmentUpload";
18
19export interface ProjectThreadStartTurnSpec {
20 readonly projectId: ProjectId;
21 readonly projectCwd: string;
22 readonly threadId: string;
23 readonly commandId: string;
24 readonly messageId: string;
25 readonly createdAt: string;
26 readonly text: string;
27 readonly titleText?: string;
28 readonly context?: OrchestrationMessageContext;
29 readonly uploadedAttachments: ReadonlyArray<UploadedMobileAttachment | ChatAttachment>;
30 readonly modelSelection: ModelSelection;
31 readonly runtimeMode: RuntimeMode;
32 readonly interactionMode: ProviderInteractionMode;
33 readonly workspaceMode: "local" | "worktree";
34 readonly branch: string | null;
35 readonly worktreePath: string | null;
36 readonly startFromOrigin: boolean;
37 readonly worktreeBranchName: string;
38}
39
40export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpec) {
41 const title = deriveThreadTitleSeed({
42 text: spec.titleText ?? spec.text,
43 attachments: spec.uploadedAttachments,
44 });
45 const isWorktree = spec.workspaceMode === "worktree";
46 return {
47 commandId: CommandId.make(spec.commandId),
48 creationSource: "mobile" as const,
49 threadId: ThreadId.make(spec.threadId),
50 message: {
51 messageId: MessageId.make(spec.messageId),
52 role: "user" as const,
53 text: spec.text,
54 ...(spec.context ? { context: spec.context } : {}),
55 attachments: spec.uploadedAttachments,
56 },
57 modelSelection: spec.modelSelection,
58 titleSeed: title,
59 runtimeMode: spec.runtimeMode,
60 interactionMode: spec.interactionMode,
61 bootstrap: {
62 createThread: {
63 projectId: spec.projectId,
64 title,
65 modelSelection: spec.modelSelection,
66 runtimeMode: spec.runtimeMode,
67 interactionMode: spec.interactionMode,
68 branch: spec.branch,
69 worktreePath: isWorktree ? null : spec.worktreePath,
70 createdAt: spec.createdAt,
71 },
72 ...(isWorktree
73 ? {
74 prepareWorktree: {
75 projectCwd: spec.projectCwd,
76 baseBranch: spec.branch!,
77 branch: spec.worktreeBranchName,
78 ...(spec.startFromOrigin ? { startFromOrigin: true } : {}),
79 },
80 runSetupScript: true,
81 }
82 : {}),
83 },
84 createdAt: spec.createdAt,
85 };
86}
87
88export function deriveThreadTitleFromPrompt(value: string): string {
89 const title = threadTitleTextFromPrompt(value) || "New thread";
90 return title.length <= 72 ? title : `${title.slice(0, 69).trimEnd()}...`;
91}