# Botruntime Client

HTTP client for TypeScript. Queries the botruntime API.

## Exact FileRef streaming

`client.downloadFileRef({ fileRef, signal? })` opens the complete immutable
`FileRef` generation through the authenticated raw endpoint and returns a Web
`ReadableStream<Uint8Array>`. The client does not decode base64 or materialize
the response as a `Buffer`/`ArrayBuffer`; pipe the stream directly to the
provider and use `AbortSignal` for cancellation. A stale generation fails
closed instead of silently reading a newer upload under the same file key.
Non-2xx responses throw `DownloadFileRefError` with the HTTP `status` and the
platform `errorCode` when one is present.

## Installation

```bash
npm install --save @holocronlab/botruntime-client # for npm
yarn add @holocronlab/botruntime-client # for yarn
pnpm add @holocronlab/botruntime-client # for pnpm
```

## Usage

```ts
import { Client, ClientInputs, ClientOutputs } from '@holocronlab/botruntime-client'

// 0. Type definitions for each operation's IO
type GetBotInput = ClientInputs['getBot']
type GetBotOutput = ClientOutputs['getBot']

const main = async () => {
  const token = 'your-token'
  const workspaceId = 'your-workspace-id'
  const botId = 'your-bot-id'
  const client = new Client({ token, workspaceId, botId })

  // 1. plain operations
  const { bot } = await client.getBot({ id: botId })
  console.log('### bot', bot)

  // 2. list utils with `.collect()` function
  const [latestConversation] = await client.list
    .conversations({ sortField: 'createdAt', sortDirection: 'desc', integrationName: 'telegram' })
    .collect({ limit: 1 })
  console.log('### latestConversation', latestConversation)

  // 3. list utils with async generator and `for await` syntax
  for await (const message of client.list.messages({ conversationId: latestConversation.id })) {
    console.log(`### [${message.userId}]`, message.payload)
  }
}

void main()
```
