( params: ParamsOf<AddAgentStepFn>, )
| 393 | } |
| 394 | |
| 395 | export async function addAgentStep( |
| 396 | params: ParamsOf<AddAgentStepFn>, |
| 397 | ): ReturnType<AddAgentStepFn> { |
| 398 | const { |
| 399 | apiKey, |
| 400 | agentRunId, |
| 401 | stepNumber, |
| 402 | credits, |
| 403 | childRunIds, |
| 404 | messageId, |
| 405 | status = 'completed', |
| 406 | errorMessage, |
| 407 | startTime, |
| 408 | logger, |
| 409 | } = params |
| 410 | |
| 411 | const url = new URL(`/api/v1/agent-runs/${agentRunId}/steps`, WEBSITE_URL) |
| 412 | |
| 413 | try { |
| 414 | const response = await fetchWithRetry( |
| 415 | url, |
| 416 | { |
| 417 | method: 'POST', |
| 418 | headers: { |
| 419 | Authorization: `Bearer ${apiKey}`, |
| 420 | }, |
| 421 | body: JSON.stringify({ |
| 422 | stepNumber, |
| 423 | credits, |
| 424 | childRunIds, |
| 425 | messageId, |
| 426 | status, |
| 427 | errorMessage, |
| 428 | startTime, |
| 429 | }), |
| 430 | }, |
| 431 | logger, |
| 432 | ) |
| 433 | |
| 434 | const responseBody = await response.json() |
| 435 | if (!response.ok) { |
| 436 | logger.error({ responseBody }, 'addAgentStep request failed') |
| 437 | return null |
| 438 | } |
| 439 | |
| 440 | if (!responseBody?.stepId) { |
| 441 | logger.error( |
| 442 | { responseBody }, |
| 443 | 'no stepId found from addAgentStep request', |
| 444 | ) |
| 445 | } |
| 446 | return responseBody.stepId ?? null |
| 447 | } catch (error) { |
| 448 | logger.error( |
| 449 | { |
| 450 | error: getErrorObject(error), |
| 451 | agentRunId, |
| 452 | stepNumber, |
no test coverage detected