({
environmentId,
title,
events,
gitRepoUrl,
branch,
signal,
baseUrl: baseUrlOverride,
getAccessToken,
permissionMode,
}: {
environmentId: string
title?: string
events: SessionEvent[]
gitRepoUrl: string | null
branch: string
signal: AbortSignal
baseUrl?: string
getAccessToken?: () => string | undefined
permissionMode?: string
})
| 56 | * Returns the session ID on success, or null if creation fails (non-fatal). |
| 57 | */ |
| 58 | export async function createBridgeSession({ |
| 59 | environmentId, |
| 60 | title, |
| 61 | events, |
| 62 | gitRepoUrl, |
| 63 | branch, |
| 64 | signal, |
| 65 | baseUrl: baseUrlOverride, |
| 66 | getAccessToken, |
| 67 | permissionMode, |
| 68 | }: { |
| 69 | environmentId: string |
| 70 | title?: string |
| 71 | events: SessionEvent[] |
| 72 | gitRepoUrl: string | null |
| 73 | branch: string |
| 74 | signal: AbortSignal |
| 75 | baseUrl?: string |
| 76 | getAccessToken?: () => string | undefined |
| 77 | permissionMode?: string |
| 78 | }): Promise<string | null> { |
| 79 | const { parseGitHubRepository } = await import('../utils/detectRepository.js') |
| 80 | const { getDefaultBranch } = await import('../utils/git.js') |
| 81 | const { getMainLoopModel } = await import('../utils/model/model.js') |
| 82 | const { default: axios } = await import('axios') |
| 83 | |
| 84 | const headers = await resolveBridgeSessionHeaders({ |
| 85 | accessTokenOverride: getAccessToken?.(), |
| 86 | operation: 'session creation', |
| 87 | }) |
| 88 | if (!headers) { |
| 89 | return null |
| 90 | } |
| 91 | |
| 92 | // Build git source and outcome context |
| 93 | let gitSource: GitSource | null = null |
| 94 | let gitOutcome: GitOutcome | null = null |
| 95 | const workspaceSource = |
| 96 | await detectCurrentCitcWorkspaceSource() |
| 97 | |
| 98 | if (gitRepoUrl) { |
| 99 | const { parseGitRemote } = await import('../utils/detectRepository.js') |
| 100 | const parsed = parseGitRemote(gitRepoUrl) |
| 101 | if (parsed) { |
| 102 | const { host, owner, name } = parsed |
| 103 | const revision = branch || (await getDefaultBranch()) || undefined |
| 104 | gitSource = { |
| 105 | type: 'git_repository', |
| 106 | url: `https://${host}/${owner}/${name}`, |
| 107 | revision, |
| 108 | } |
| 109 | gitOutcome = { |
| 110 | type: 'git_repository', |
| 111 | git_info: { |
| 112 | type: 'github', |
| 113 | repo: `${owner}/${name}`, |
| 114 | branches: [`claude/${branch || 'task'}`], |
| 115 | }, |
no test coverage detected