# @standardagents/sip

Standalone stream-first image processing for Cloudflare Workers

## Overview

`@standardagents/sip` is now a standalone package published from the
`standardagents/sip` repository. Standard Agents Builder consumes it as an external
dependency rather than shipping its image pipeline from inside the monorepo.

Canonical package docs live at:

- <https://sip.standardagents.ai>
- <https://github.com/standardagents/sip>

## Installation

```bash pnpm
pnpm add @standardagents/sip
```

## Quick Start

```typescript
import { collect, inspect, ready, transform } from "@standardagents/sip"

await ready()

const { source } = await inspect(imageBuffer)
const image = transform(source, {
  width: 2048,
  height: 2048,
  quality: 85,
})

const { data, info, stats } = await collect(image)

console.log(info)
// { width, height, mimeType: "image/jpeg", originalFormat }

console.log(stats)
// { peakPipelineBytes, peakCodecBytes, bytesIn, bytesOut, ... }
```

## Worker Response Example

```typescript
import { inspect, ready, toResponse, transform } from "@standardagents/sip"

export default {
  async fetch(request: Request) {
    await ready()
    const { source } = await inspect(request)
    return toResponse(transform(source, {
      width: 1600,
      height: 1600,
      quality: 82,
    }))
  },
}
```

## Notes

- The new API is stream-first. The main primitives are `ready`, `inspect`,
  `transform`, `collect`, `toReadableStream`, and `toResponse`.
- `transform()` constrains width and height while preserving aspect ratio and
  never upscales.
- A streamed input source can be opened once.
- For a byte budget, retry `collect(transform(...))` with lower quality or smaller dimensions. Use retained bytes or a fresh input stream for each attempt. Check the final output size.
- Use the standalone SIP docs for full API reference, examples, and release
  notes instead of treating Standard Agents Builder docs as the source of truth.
