# @alexeiled/pi-provider-compat

[![npm version](https://img.shields.io/npm/v/%40alexeiled%2Fpi-provider-compat?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@alexeiled/pi-provider-compat)
[![CI](https://img.shields.io/github/actions/workflow/status/alexei-led/pi-provider-compat/ci.yml?branch=main&style=flat-square&label=ci)](https://github.com/alexei-led/pi-provider-compat/actions/workflows/ci.yml?query=branch%3Amain)
[![license](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](./LICENSE)

Temporary compatibility bridge for Pi extensions that call the legacy `pi-ai` dispatcher.

## Problem

Pi `>=0.80.8` keeps custom provider handlers registered through
`pi.registerProvider()` inside their provider runtime. The legacy global
`@earendil-works/pi-ai/compat` registry no longer receives those handlers.

Directly selecting a custom-provider model still works. An extension that calls
`stream()` or `streamSimple()` from `pi-ai/compat` for that model fails instead:

```text
No API provider registered for api: <custom-api>
```

## Solution

This extension mirrors registered custom providers with `streamSimple` into the
legacy compat registry. It routes each request by `model.provider` to the
matching provider-scoped handler.

It does not use provider-specific names or allowlists. It never replaces an
existing compat provider, and removes only registrations it created.

## Install

```bash
pi install npm:@alexeiled/pi-provider-compat
```

Then reload Pi:

```text
/reload
```

## Temporary migration bridge

This package is a workaround, not the durable design. Affected extensions should
use the selected provider's registered `streamSimple` handler from Pi's model
registry, with the legacy compat dispatcher only as a fallback for built-in APIs.

Migration is tracked here:

| Extension | Issue |
| --- | --- |
| `@yeliu84/pi-model-router` | [#19: Custom provider targets fail on Pi >= 0.80.8](https://github.com/yeliu84/pi-model-router/issues/19) |
| `pi-subagents` | [#527: Watchdog review fails with custom providers on Pi >= 0.80.8](https://github.com/nicobailon/pi-subagents/issues/527) |

Remove this bridge once the extensions you use have released those migrations.

## Requirements

- Pi `>=0.80.8`
- A custom provider registered with `pi.registerProvider(..., { streamSimple })`

This package does not provide credentials, implement a provider, or change Pi's
normal model routing. It cannot help when the selected provider has no registered
`streamSimple` handler.

## Development

```bash
npm install
npm run test:all
```

## License

MIT
