MCPcopy Create free account
hub / github.com/pingdotgg/t3code / createDraftThreadState

Function createDraftThreadState

apps/web/src/composerDraftStore.ts:1311–1370  ·  view source on GitHub ↗
(
  projectRef: ScopedProjectRef,
  threadId: ThreadId,
  logicalProjectKey: string,
  existingThread: DraftThreadState | undefined,
  options?: {
    threadId?: ThreadId;
    branch?: string | null;
    worktreePath?: string | null;
    createdAt?: string;
    envMode?: DraftThreadEnvMode;
    startFromOrigin?: boolean;
    runtimeMode?: RuntimeMode;
    interactionMode?: ProviderInteractionMode;
  },
)

Source from the content-addressed store, hash-verified

1309}
1310
1311function createDraftThreadState(
1312 projectRef: ScopedProjectRef,
1313 threadId: ThreadId,
1314 logicalProjectKey: string,
1315 existingThread: DraftThreadState | undefined,
1316 options?: {
1317 threadId?: ThreadId;
1318 branch?: string | null;
1319 worktreePath?: string | null;
1320 createdAt?: string;
1321 envMode?: DraftThreadEnvMode;
1322 startFromOrigin?: boolean;
1323 runtimeMode?: RuntimeMode;
1324 interactionMode?: ProviderInteractionMode;
1325 },
1326): DraftThreadState {
1327 const projectChanged =
1328 existingThread !== undefined &&
1329 (existingThread.environmentId !== projectRef.environmentId ||
1330 existingThread.projectId !== projectRef.projectId);
1331 const nextWorktreePath =
1332 options?.worktreePath === undefined
1333 ? projectChanged
1334 ? null
1335 : (existingThread?.worktreePath ?? null)
1336 : (options.worktreePath ?? null);
1337 const nextBranch =
1338 options?.branch === undefined
1339 ? projectChanged
1340 ? null
1341 : (existingThread?.branch ?? null)
1342 : (options.branch ?? null);
1343 const nextStartFromOrigin =
1344 options?.startFromOrigin === undefined
1345 ? projectChanged
1346 ? false
1347 : (existingThread?.startFromOrigin ?? false)
1348 : options.startFromOrigin;
1349 return {
1350 threadId,
1351 environmentId: projectRef.environmentId,
1352 projectId: projectRef.projectId,
1353 logicalProjectKey,
1354 createdAt: options?.createdAt ?? existingThread?.createdAt ?? new Date().toISOString(),
1355 runtimeMode: options?.runtimeMode ?? existingThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE,
1356 interactionMode:
1357 options?.interactionMode ?? existingThread?.interactionMode ?? DEFAULT_INTERACTION_MODE,
1358 branch: nextBranch,
1359 worktreePath: nextWorktreePath,
1360 envMode:
1361 options?.envMode ??
1362 (nextWorktreePath
1363 ? "worktree"
1364 : projectChanged
1365 ? "local"
1366 : (existingThread?.envMode ?? "local")),
1367 startFromOrigin: nextStartFromOrigin,
1368 promotedTo: null,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected