(method, params, id)
| 30 | let sessionId = null |
| 31 | |
| 32 | async function invoke(method, params, id) { |
| 33 | const payload = { jsonrpc: '2.0', method, id } |
| 34 | if (params) payload.params = params |
| 35 | |
| 36 | const command = new InvokeAgentRuntimeCommand({ |
| 37 | agentRuntimeArn: RUNTIME_ARN, |
| 38 | qualifier: 'DEFAULT', |
| 39 | ...(sessionId ? { runtimeSessionId: sessionId } : {}), |
| 40 | payload: Buffer.from(JSON.stringify(payload)), |
| 41 | contentType: 'application/json', |
| 42 | accept: 'application/json, text/event-stream', |
| 43 | }) |
| 44 | |
| 45 | const response = await client.send(command) |
| 46 | |
| 47 | // Capture session ID from first response |
| 48 | if (!sessionId && response.runtimeSessionId) { |
| 49 | sessionId = response.runtimeSessionId |
| 50 | } |
| 51 | |
| 52 | // Parse response body |
| 53 | const body = |
| 54 | typeof response.response === 'string' |
| 55 | ? response.response |
| 56 | : await streamToString(response.response) |
| 57 | |
| 58 | return JSON.parse(body) |
| 59 | } |
| 60 | |
| 61 | async function streamToString(stream) { |
| 62 | if (typeof stream === 'string') return stream |
no test coverage detected