( params: ParamsOf<StartAgentRunFn>, )
| 300 | } |
| 301 | |
| 302 | export async function startAgentRun( |
| 303 | params: ParamsOf<StartAgentRunFn>, |
| 304 | ): ReturnType<StartAgentRunFn> { |
| 305 | const { apiKey, agentId, ancestorRunIds, logger } = params |
| 306 | |
| 307 | const url = new URL(`/api/v1/agent-runs`, WEBSITE_URL) |
| 308 | |
| 309 | try { |
| 310 | const response = await fetchWithRetry( |
| 311 | url, |
| 312 | { |
| 313 | method: 'POST', |
| 314 | headers: { |
| 315 | Authorization: `Bearer ${apiKey}`, |
| 316 | }, |
| 317 | body: JSON.stringify({ |
| 318 | action: 'START', |
| 319 | agentId, |
| 320 | ancestorRunIds, |
| 321 | }), |
| 322 | }, |
| 323 | logger, |
| 324 | ) |
| 325 | |
| 326 | if (!response.ok) { |
| 327 | logger.error({ response }, 'startAgentRun request failed') |
| 328 | return null |
| 329 | } |
| 330 | |
| 331 | const responseBody = await response.json() |
| 332 | if (!responseBody?.runId) { |
| 333 | logger.error( |
| 334 | { responseBody }, |
| 335 | 'no runId found from startAgentRun request', |
| 336 | ) |
| 337 | } |
| 338 | return responseBody?.runId ?? null |
| 339 | } catch (error) { |
| 340 | logger.error( |
| 341 | { error: getErrorObject(error), agentId }, |
| 342 | 'startAgentRun error', |
| 343 | ) |
| 344 | return null |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | export async function finishAgentRun( |
| 349 | params: ParamsOf<FinishAgentRunFn>, |
no test coverage detected