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 エージェントをアプリケーションやスクリプトに組み込めます。
前提条件
インストール
npm install @qoder-ai/qoder-agent-sdk
SDK は Personal Access Token (PAT) で認証を行います。スクリプト、CI パイプライン、サードパーティ連携のシナリオに適しています。
qoder.com/account/integrations で PAT を生成してください(生成後すぐにコピーしてください — ページを閉じると値を再表示できません)。詳細な手順、カスタム環境変数、ローカル qodercli ログイン状態の再利用については SDK 認証 を参照してください。
PAT を取得したら、まず環境変数を設定することを推奨します:
export QODER_PERSONAL_ACCESS_TOKEN="<your-qoder-personal-access-token>"
node agent.mjs
次に accessTokenFromEnv() で認証を設定します:
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 をコードリポジトリにハードコードしないでください。環境変数またはシークレット管理サービスを通じて注入することを推奨します。
使用例
agent.mjs を作成します:
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
}
}
エージェントは自律的にプロジェクトを探索し、テストカバレッジが不足している関数を見つけ、テストファイルを生成して検証を実行します。
次のステップ