( acc: RetoolAccount, agentId: string, runId: string, timeoutMs = 300_000, )
| 135 | return data.content.runId as string; |
| 136 | } |
| 137 | async function retoolGetMessage( |
| 138 | acc: RetoolAccount, |
| 139 | agentId: string, |
| 140 | runId: string, |
| 141 | timeoutMs = 300_000, |
| 142 | ) { |
| 143 | const url = `https://${acc.domain_name}/api/agents/${agentId}/logs/${runId}`; |
| 144 | const deadline = Date.now() + timeoutMs; |
| 145 | while (Date.now() < deadline) { |
| 146 | const resp = await fetch(url, { |
| 147 | headers: { |
| 148 | "x-xsrf-token": acc.x_xsrf_token, |
| 149 | "Cookie": `accessToken=${acc.accessToken}`, |
| 150 | "Accept": "application/json", |
| 151 | }, |
| 152 | }); |
| 153 | if (!resp.ok) throw new Error(`get log failed ${resp.status}`); |
| 154 | const data = await resp.json(); |
| 155 | if (data.status === "COMPLETED") { |
| 156 | const trace = data.trace; |
| 157 | const last = trace[trace.length - 1]; |
| 158 | // deep path: data.data.content |
| 159 | return last.data.data.content as string; |
| 160 | } |
| 161 | await new Promise((r) => setTimeout(r, 1_000)); |
| 162 | } |
| 163 | throw new Error("timeout waiting for completion"); |
| 164 | } |
| 165 | |
| 166 | // ---------------------------------------------------------------------------- |
| 167 | // Utility logic |
no test coverage detected