(
sessionId: string,
messageContent: RemoteMessageContent,
opts?: { uuid?: string },
)
| 359 | * @returns Promise<boolean> True if successful, false otherwise |
| 360 | */ |
| 361 | export async function sendEventToRemoteSession( |
| 362 | sessionId: string, |
| 363 | messageContent: RemoteMessageContent, |
| 364 | opts?: { uuid?: string }, |
| 365 | ): Promise<boolean> { |
| 366 | try { |
| 367 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 368 | |
| 369 | const url = `${getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}/events` |
| 370 | const headers = { |
| 371 | ...getOAuthHeaders(accessToken), |
| 372 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 373 | 'x-organization-uuid': orgUUID, |
| 374 | } |
| 375 | |
| 376 | const userEvent = { |
| 377 | uuid: opts?.uuid ?? randomUUID(), |
| 378 | session_id: sessionId, |
| 379 | type: 'user', |
| 380 | parent_tool_use_id: null, |
| 381 | message: { |
| 382 | role: 'user', |
| 383 | content: messageContent, |
| 384 | }, |
| 385 | } |
| 386 | |
| 387 | const requestBody = { |
| 388 | events: [userEvent], |
| 389 | } |
| 390 | |
| 391 | logForDebugging( |
| 392 | `[sendEventToRemoteSession] Sending event to session ${sessionId}`, |
| 393 | ) |
| 394 | // The endpoint may block until the CCR worker is ready. Observed ~2.6s |
| 395 | // in normal cases; allow a generous margin for cold-start containers. |
| 396 | const response = await axios.post(url, requestBody, { |
| 397 | headers, |
| 398 | validateStatus: status => status < 500, |
| 399 | timeout: 30000, |
| 400 | }) |
| 401 | |
| 402 | if (response.status === 200 || response.status === 201) { |
| 403 | logForDebugging( |
| 404 | `[sendEventToRemoteSession] Successfully sent event to session ${sessionId}`, |
| 405 | ) |
| 406 | return true |
| 407 | } |
| 408 | |
| 409 | logForDebugging( |
| 410 | `[sendEventToRemoteSession] Failed with status ${response.status}: ${jsonStringify(response.data)}`, |
| 411 | ) |
| 412 | return false |
| 413 | } catch (error) { |
| 414 | logForDebugging(`[sendEventToRemoteSession] Error: ${errorMessage(error)}`) |
| 415 | return false |
| 416 | } |
| 417 | } |
| 418 |
no test coverage detected