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

# クイックスタート

Qoder Agent SDK を使えば、TypeScript で Qoder AI の機能（ファイルの読み書き、コード検索、コマンド実行など）を呼び出すことができます。わずか数行のコードで AI エージェントをアプリケーションやスクリプトに組み込めます。

<div id="前提条件" />

## 前提条件

* Node.js 18+

<div id="インストール" />

## インストール

```bash theme={null}
npm install @qoder-ai/qoder-agent-sdk
```

<div id="認証" />

## 認証

SDK は Personal Access Token (PAT) で認証を行います。スクリプト、CI パイプライン、サードパーティ連携のシナリオに適しています。

[qoder.com/account/integrations](https://qoder.com/account/integrations) で PAT を生成してください（生成後すぐにコピーしてください — ページを閉じると値を再表示できません）。詳細な手順、カスタム環境変数、ローカル `qodercli` ログイン状態の再利用については [SDK 認証](/ja/cli/sdk/authentication) を参照してください。

PAT を取得したら、まず環境変数を設定することを推奨します：

```bash theme={null}
export QODER_PERSONAL_ACCESS_TOKEN="<your-qoder-personal-access-token>"
node agent.mjs
```

次に `accessTokenFromEnv()` で認証を設定します：

```js theme={null}
import { accessTokenFromEnv, query } from '@qoder-ai/qoder-agent-sdk';

const stream = query({
  prompt: 'Hello',
  options: {
    auth: accessTokenFromEnv(),
  },
});
```

SDK は qodercli を起動する前にこの環境変数を読み取り、解析済みのアクセストークンを一回限りの auth payload に書き込みます。通常、`env` オプションで PAT を渡す必要はありません。`options.env` を明示的に指定した場合、SDK はそちらから同名の変数を優先的に読み取ります。

> **セキュリティに関する注意**：PAT をコードリポジトリにハードコードしないでください。環境変数またはシークレット管理サービスを通じて注入することを推奨します。

<div id="使用例" />

## 使用例

`agent.mjs` を作成します：

```js theme={null}
import { accessTokenFromEnv, query } from '@qoder-ai/qoder-agent-sdk';

for await (const message of query({
  prompt: 'Analyze the codebase, find functions without test coverage, and write unit tests for them.',
  options: {
    auth: accessTokenFromEnv(),
    allowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'],
    permissionMode: 'acceptEdits',  // Auto-approve file edits
  },
})) {
  if (message.type === 'assistant') {
    for (const block of message.message.content) {
      if (block.type === 'text') {
        console.log(block.text);              // AI text response
      } else if (block.type === 'tool_use') {
        console.log(`Tool: ${block.name}`);   // Tool being called
      }
    }
  } else if (message.type === 'result') {
    console.log(`Done: ${message.subtype}`);  // Final result
  }
}
```

```bash theme={null}
node agent.mjs
```

エージェントは自律的にプロジェクトを探索し、テストカバレッジが不足している関数を見つけ、テストファイルを生成して検証を実行します。

<div id="次のステップ" />

## 次のステップ

* [SDK 認証](/ja/cli/sdk/authentication) — PAT、環境変数、認証エラーハンドリング
* [マルチターン会話](/ja/cli/sdk/multi-turn-conversation) — マルチメッセージセッション、セッションライフサイクルの管理
* [ストリーミング出力](/ja/cli/sdk/streaming-output) — 増分コンテンツのリアルタイム受信、タイプライター効果
* [SDK References](/ja/cli/sdk/references) — 完全な SDK リファレンス
