> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archetype.ing/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK

> Conéctate a un host de Archetype desde tu propio código.

```bash theme={null}
npm i @pairful/archetype-sdk
```

El SDK se conecta a un host; no lo inicia y no tiene E/S propia, así que también funciona en navegadores.

## Conectar, preguntar, responder

```ts theme={null}
import {
  ClientConnectionService,
  ConnectorAdapter,
} from "@pairful/archetype-sdk";

const client = await ClientConnectionService.connect(
  ConnectorAdapter.webSocketConnector(url),
  { client: "my-app" },
);
const turn = await client.startTurn("main", "run the tests");
for await (const { event } of client.events(turn)) {
  if (event.type === "approval.requested")
    await client.respond(turn, event.requestId, { action: "allow" });
}
```

Los eventos de un turno llegan en orden, de `turn.started` a `turn.finished`. `events(turnId, after)` retoma donde lo dejaste tras una reconexión.

## Conectores

| Conector | Para |
| - | - |
| `ConnectorAdapter.webSocketConnector(url)` | Un host que escucha por WebSocket, como `archetype --serve --listen` |
| `ConnectorAdapter.inProcess(server)` | Un host en el mismo proceso |
| `ConnectorAdapter.lineConnector({ lines, write })` | JSON delimitado por saltos de línea, como el stdio de un subproceso |

## Consultar al modelo de decisión

```ts theme={null}
const { answers } = await client.decide(ticket, {
  urgent: { type: "yes_no", instructions: "Does this need attention now?" },
});
if (answers.urgent.probability > 0.8) notify(ticket);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.