The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 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"; |
| 12 | import { |
| 13 | deriveThreadTitleSeed, |
| 14 | threadTitleTextFromPrompt, |
| 15 | } from "@t3tools/client-runtime/operations"; |
| 16 | import { msg } from "gt-react-native"; |
| 17 | |
| 18 | import { m } from "../i18n/messages"; |
| 19 | import type { UploadedMobileAttachment } from "./attachmentUpload"; |
| 20 | |
| 21 | export 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 | readonly worktreeBranchName: string; |
| 40 | } |
| 41 | |
| 42 | export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpec) { |
| 43 | const title = deriveThreadTitleSeed( |
| 44 | { text: spec.titleText ?? spec.text, attachments: spec.uploadedAttachments }, |
| 45 | m, |
| 46 | ); |
| 47 | const isWorktree = spec.workspaceMode === "worktree"; |
| 48 | return { |
| 49 | commandId: CommandId.make(spec.commandId), |
| 50 | creationSource: "mobile" as const, |
| 51 | threadId: ThreadId.make(spec.threadId), |
| 52 | message: { |
| 53 | messageId: MessageId.make(spec.messageId), |
| 54 | role: "user" as const, |
| 55 | text: spec.text, |
| 56 | ...(spec.context ? { context: spec.context } : {}), |
| 57 | attachments: spec.uploadedAttachments, |
| 58 | }, |
| 59 | modelSelection: spec.modelSelection, |
| 60 | titleSeed: title, |
| 61 | runtimeMode: spec.runtimeMode, |
| 62 | interactionMode: spec.interactionMode, |
| 63 | bootstrap: { |
| 64 | createThread: { |
| 65 | projectId: spec.projectId, |
| 66 | title, |
| 67 | modelSelection: spec.modelSelection, |
| 68 | runtimeMode: spec.runtimeMode, |
| 69 | interactionMode: spec.interactionMode, |
| 70 | branch: spec.branch, |
| 71 | worktreePath: isWorktree ? null : spec.worktreePath, |
| 72 | createdAt: spec.createdAt, |
| 73 | }, |
| 74 | ...(isWorktree |
| 75 | ? { |
| 76 | prepareWorktree: { |
| 77 | projectCwd: spec.projectCwd, |
| 78 | baseBranch: spec.branch!, |
| 79 | branch: spec.worktreeBranchName, |
| 80 | ...(spec.startFromOrigin ? { startFromOrigin: true } : {}), |
| 81 | }, |
| 82 | runSetupScript: true, |
| 83 | } |
| 84 | : {}), |
| 85 | }, |
| 86 | createdAt: spec.createdAt, |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | export function deriveThreadTitleFromPrompt(value: string): string { |
| 91 | const title = threadTitleTextFromPrompt(value, m) || m(msg("New thread")); |
| 92 | return title.length <= 72 ? title : `${title.slice(0, 69).trimEnd()}...`; |
| 93 | } |