(
sessionId: string,
messageContent: RemoteMessageContent,
opts?: { uuid?: string },
)
| 453 | * @returns Promise<boolean> True if successful, false otherwise |
| 454 | */ |
| 455 | export async function sendEventToRemoteSession( |
| 456 | sessionId: string, |
| 457 | messageContent: RemoteMessageContent, |
| 458 | opts?: { uuid?: string }, |
| 459 | ): Promise<boolean> { |
| 460 | try { |
| 461 | const { accessToken, orgUUID } = await prepareApiRequest() |
| 462 | |
| 463 | const url = buildNoumenaPlatformUrl(`/v1/sessions/${sessionId}/events`) |
| 464 | const headers = { |
| 465 | ...getOAuthHeaders(accessToken), |
| 466 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 467 | 'x-organization-uuid': orgUUID, |
| 468 | } |
| 469 | |
| 470 | const userEvent = { |
| 471 | uuid: opts?.uuid ?? randomUUID(), |
| 472 | session_id: sessionId, |
| 473 | type: 'user', |
| 474 | parent_tool_use_id: null, |
| 475 | message: { |
| 476 | role: 'user', |
| 477 | content: messageContent, |
| 478 | }, |
| 479 | } |
| 480 | |
| 481 | const requestBody = { |
| 482 | events: [userEvent], |
| 483 | } |
| 484 | |
| 485 | logForDebugging( |
| 486 | `[sendEventToRemoteSession] Sending event to session ${sessionId}`, |
| 487 | ) |
| 488 | // The endpoint may block until the CCR worker is ready. Observed ~2.6s |
| 489 | // in normal cases; allow a generous margin for cold-start containers. |
| 490 | const response = await axios.post(url, requestBody, { |
| 491 | headers, |
| 492 | validateStatus: status => status < 500, |
| 493 | timeout: 30000, |
| 494 | }) |
| 495 | |
| 496 | if (response.status === 200 || response.status === 201) { |
| 497 | logForDebugging( |
| 498 | `[sendEventToRemoteSession] Successfully sent event to session ${sessionId}`, |
| 499 | ) |
| 500 | return true |
| 501 | } |
| 502 | |
| 503 | logForDebugging( |
| 504 | `[sendEventToRemoteSession] Failed with status ${response.status}: ${jsonStringify(response.data)}`, |
| 505 | ) |
| 506 | return false |
| 507 | } catch (error) { |
| 508 | logForDebugging(`[sendEventToRemoteSession] Error: ${errorMessage(error)}`) |
| 509 | return false |
| 510 | } |
| 511 | } |
| 512 |
no test coverage detected