(
controlPlane: Fetcher,
headers: Record<string, string>,
params: {
repoOwner: string;
repoName: string;
title: string;
model: string;
reasoningEffort?: string | null;
scmLogin: string;
scmUserId: string;
scmAvatarUrl: string;
}
)
| 36 | params: { |
| 37 | target: SessionTargetFields; |
| 38 | title: string; |
| 39 | model: string; |
| 40 | reasoningEffort?: string | null; |
| 41 | scmLogin: string; |
| 42 | scmUserId: string; |
| 43 | scmAvatarUrl: string; |
| 44 | } |
| 45 | ): Promise<string> { |
| 46 | const body: Record<string, unknown> = { |
| 47 | ...params.target, |
| 48 | title: params.title, |
| 49 | model: params.model, |
| 50 | scmLogin: params.scmLogin, |
| 51 | scmAvatarUrl: params.scmAvatarUrl, |
| 52 | }; |
| 53 | if (params.reasoningEffort) { |
| 54 | body.reasoningEffort = params.reasoningEffort; |
| 55 | } |
| 56 | const url = "https://internal/sessions"; |
| 57 | const bodyText = JSON.stringify(body); |
| 58 | const response = await signedControlPlaneFetch(env, { |
| 59 | method: "POST", |
| 60 | url, |
| 61 | body: bodyText, |
| 62 | actor: `github:${params.scmUserId}`, |
| 63 | traceId, |
| 64 | }); |
| 65 | if (!response.ok) { |
| 66 | const body = await response.text(); |
| 67 | throw new Error(`Session creation failed: ${response.status} ${body}`); |
| 68 | } |
| 69 | const result = createSessionResponseSchema.safeParse(await response.json()); |
| 70 | if (!result.success) { |
| 71 | throw new Error("Session creation failed: invalid response"); |
| 72 | } |
| 73 | return result.data.sessionId; |
| 74 | } |
| 75 | |
| 76 | async function sendPrompt( |
| 77 | env: Env, |
| 78 | traceId: string, |
| 79 | sessionId: string, |
| 80 | params: { content: string; authorId: string } |
| 81 | ): Promise<string> { |
| 82 | const url = `https://internal/sessions/${sessionId}/prompt`; |
no test coverage detected