export type GetApiV1AgentsNameTurnsTurnEventsArgs = {name: string, turn: number, after?: number | undefined}; export type GetApiV1AgentsNameTurnsTurnEventsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream an agent turn's events. * * GET /v1/agents/{name}/turns/{turn}/events */ export const getApiV1AgentsNameTurnsTurnEvents = async (args: GetApiV1AgentsNameTurnsTurnEventsArgs, options?: GetApiV1AgentsNameTurnsTurnEventsOptions) => { const {baseUrl = "https://api.smolmachines.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.after != null) query.append("after", String(args.after)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/agents/${encodeURIComponent(String(args.name))}/turns/${encodeURIComponent(String(args.turn))}/events${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };