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

# SDK 概要

> Refrain TypeScript SDK のインストールと使い方。

## 概要

**Refrain SDK** は、TypeScript/JavaScript アプリケーションから手順書を実行するためのプログラマティックアクセスを提供します。`process.env` を一切読まず、全ての設定を明示的に受け取ります。

## インストール

<CodeGroup>
  ```bash npm theme={null}
  npm install @refrainai/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @refrainai/sdk
  ```
</CodeGroup>

## クイックスタート

```typescript theme={null}
import { Refrain, loadRunbook } from "@refrainai/sdk";

// 1. クライアントを作成
const client = new Refrain({
  ai: {
    modelId: "claude-sonnet-4-6",
    provider: "anthropic",
    apiKey: "sk-ant-...",
  },
  headless: true,
});

// 2. 手順書を読み込み
const runbook = await loadRunbook("./runbooks/login-flow.yaml");

// 3. 実行
const report = await client.execute(runbook, {
  contextMarkdown: "# ログイン情報\n- ステージング環境の認証情報を使用",
  variables: { username: "user@example.com" },
  secrets: { password: "secret123" },
});

// 4. 結果を確認
console.log(`${report.succeeded}/${report.totalSteps} ステップ成功`);

// 5. クリーンアップ
await client.dispose();
```

## 主なエクスポート

| エクスポート        | 型        | 説明                     |
| ------------- | -------- | ---------------------- |
| `Refrain`     | class    | ローカル実行用メインクライアント       |
| `loadRunbook` | function | 手順書 YAML ファイルの読み込みとパース |

## 設計原則

* **`process.env` 不使用** — 全設定をコンストラクタとメソッド引数で明示的に渡す
* **非対話型** — ユーザープロンプトなし。未解決の必須変数はエラー
* **プラン対応** — プランティアで利用できない機能はサイレントに無効化
* **包括的な診断情報** — ステップ結果にリトライ回数、解決方法、失敗カテゴリを含む

## 次のステップ

<CardGroup cols={2}>
  <Card title="ローカル実行" icon="laptop" href="/ja/sdk/local-execution">
    Refrain クラス、設定、実行オプション。
  </Card>

  <Card title="型リファレンス" icon="code" href="/ja/sdk/types">
    全エクスポート型のカテゴリ別一覧。
  </Card>

  <Card title="使用例" icon="book" href="/ja/sdk/examples">
    よくあるユースケースの実践例。
  </Card>
</CardGroup>
