> ## 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.

# 型リファレンス

> Refrain SDK の全エクスポート型。

## 設定型

### RefrainConfig

`LocalConfig` のエイリアス。プロパティ一覧は[ローカル実行](/ja/sdk/local-execution)を参照。

```typescript theme={null}
interface RefrainConfig {
  ai: AIModelConfig;
  headless?: boolean;
  loggerFactory?: LoggerFactory;
  debug?: boolean;
  apiKey?: string;
  locale?: "en" | "ja";
  stealth?: boolean;
  proxy?: string | { server: string; username?: string; password?: string };
}
```

### AIModelConfig

```typescript theme={null}
interface AIModelConfig {
  modelId: string;
  provider: ModelProvider;
  apiKey?: string;
  baseURL?: string;
  azureResourceName?: string;
  azureApiVersion?: string;
  bedrockRegion?: string;
  bedrockAccessKeyId?: string;
  bedrockSecretAccessKey?: string;
  bedrockSessionToken?: string;
  vertexProject?: string;
  vertexLocation?: string;
  modelOverrides?: Partial<Record<ModelPurpose, string>>;
}
```

### ModelProvider

```typescript theme={null}
type ModelProvider =
  | "anthropic"
  | "openai"
  | "openai-compatible"
  | "google"
  | "azure"
  | "bedrock"
  | "vertex";
```

### ModelPurpose

```typescript theme={null}
type ModelPurpose =
  | "exploration"
  | "exploration-light"
  | "selector"
  | "extraction"
  | "review"
  | "fallback"
  | "vision";
```

### ExecuteOptions

プロパティ一覧は[ローカル実行](/ja/sdk/local-execution#executeoptions)を参照。

### ExecutionStrategy

```typescript theme={null}
interface ExecutionStrategy {
  maxRetries: number;
  changeTimeouts: number[];
  finalRetryStabilizeMs: number;
  domStabilityMs: number;
}
```

## 結果型

### ExecutionReport

```typescript theme={null}
interface ExecutionReport {
  runbookTitle: string;
  startUrl: string;
  totalSteps: number;
  executed: number;
  succeeded: number;
  failed: number;
  skipped: number;
  aborted: boolean;
  steps: StepExecutionResult[];
  totalDurationMs: number;
  memoryCollections?: Record<string, number>;
  downloadedFiles?: string[];
  videoPaths?: string[];
  aiMetrics?: AIMetricsSummary;
}
```

### StepExecutionResult

```typescript theme={null}
interface StepExecutionResult {
  ordinal: number;
  description: string;
  status: StepStatus;
  durationMs: number;
  error?: string;
  capturedValues?: Record<string, string>;
  actionType?: string;

  // 条件・ループフィールド
  conditionSkipped?: boolean;
  loopIterations?: number;
  subStepResults?: StepExecutionResult[][];
  branchMatch?: string;
  forEachItemCount?: number;

  // 自己修復フィールド
  retryCount?: number;
  retryDetails?: StepRetryDetail[];
  failureCategory?: FailureCategory;

  // 出力フィールド
  extractedData?: string;
  downloadedFile?: string;
  exportedFile?: string;

  // 診断情報
  diagnostics?: StepDiagnostics;

  // テレメトリ
  resolveMethod?: "cache" | "deterministic" | "ai" | "scroll" | "vision" | "agent" | null;
  deterministicMatchType?: string;
  deterministicConfidence?: number;
  contextChunksUsed?: number;
  failureHintsProvided?: boolean;
  workingMemoryTokens?: number;
  snapshotElementCount?: number;
}
```

### StepStatus

```typescript theme={null}
type StepStatus = "success" | "failed" | "skipped";
```

### StepDiagnostics

失敗したステップに付与される詳細な失敗情報：

```typescript theme={null}
interface StepDiagnostics {
  lastSnapshotPreview?: string;
  failureHistory?: string[];
  lastAiResponseText?: string;
  recoveryHint?: string;
  deterministicResolveResult?: string;
  visionFallbackResult?: {
    annotationCount: number;
    reasoning: string;
    success: boolean;
  };
  agentFallbackResult?: {
    strategy: string;
    analysis: string;
    reasoning: string;
    success: boolean;
  };
  validationWarnings?: string[];
  validationErrors?: string[];
  executionStrategy?: ExecutionStrategy;
  stepAction?: { type: string; selector?: any; value?: string; url?: string };
  stepUrl?: string;
}
```

### BatchExecutionReport

```typescript theme={null}
interface BatchExecutionReport {
  runbookTitle: string;
  totalRows: number;
  succeeded: number;
  failed: number;
  rows: {
    rowIndex: number;
    rowLabel: string;
    report: ExecutionReport;
  }[];
  totalDurationMs: number;
}
```

## 手順書型

### ParsedRunbook

Zod スキーマから推論。フィールドの説明は[手順書 YAML](/ja/yaml/overview) を参照。

### ParsedStep / StepAction / Selector

[アクション](/ja/yaml/actions)、[セレクタ](/ja/yaml/selectors)を参照。

### ActionType

```typescript theme={null}
type ActionType =
  | "click" | "input" | "select" | "navigate"
  | "scroll" | "wait" | "hover" | "extract"
  | "download" | "export" | "memory" | "key";
```

### RiskLevel

```typescript theme={null}
type RiskLevel = "low" | "medium" | "high";
```

### VariableSource

```typescript theme={null}
type VariableSource = "prompt" | "fixed" | "context" | "env" | "expression" | "data";
```

### CaptureStrategy

```typescript theme={null}
type CaptureStrategy = "snapshot" | "url" | "ai" | "expression" | "evaluate";
```

## ロガー型

### Logger

```typescript theme={null}
interface Logger {
  step(message: string): void;
  success(message: string): void;
  error(message: string): void;
  warn(message: string): void;
  info(message: string): void;
  debug(message: string): void;
}
```

### LoggerFactory

```typescript theme={null}
interface LoggerFactory {
  createLogger(): Logger;
  createSpinner(): SpinnerLike;
}
```

### SpinnerLike

```typescript theme={null}
interface SpinnerLike {
  start(message: string): void;
  stop(message: string): void;
}
```

### CallbackLogger

全メッセージをコールバックに転送するカスタムロガー：

```typescript theme={null}
import { CallbackLogger } from "@refrainai/sdk";

const logger = new CallbackLogger((level, message) => {
  // level: "step" | "success" | "error" | "warn" | "info" | "debug"
  console.log(`[${level}] ${message}`);
});
```

### LogLevel

```typescript theme={null}
type LogLevel = "step" | "success" | "error" | "warn" | "info" | "debug";
```

## ユーティリティ型

### ResolveVariablesInput

```typescript theme={null}
interface ResolveVariablesInput {
  secrets?: Record<string, string>;
  contextMarkdown: string;
}
```

### ResolveVariablesResult

```typescript theme={null}
interface ResolveVariablesResult {
  variables: Record<string, string>;
  secrets: Record<string, string>;
}
```

## プラン型

### Plan

```typescript theme={null}
interface Plan {
  tier: PlanTier;
  limits: PlanLimits;
  features: PlanFeatures;
}
```

### PlanTier

```typescript theme={null}
type PlanTier = "community" | "pro" | "team" | "business" | "enterprise";
```

### PlanLimitError / PlanFeatureError

プラン制限またはフィーチャーゲートに到達した場合にスローされます：

```typescript theme={null}
try {
  await client.execute(runbook, options);
} catch (e) {
  if (e instanceof PlanLimitError) {
    console.error(`制限超過: ${e.limitType}`);
  }
  if (e instanceof PlanFeatureError) {
    console.error(`機能利用不可: ${e.message}`);
  }
}
```

## その他の型

| 型                       | 説明                                                                                      |
| ----------------------- | --------------------------------------------------------------------------------------- |
| `DataStore`             | メモリデータコレクションのインターフェース                                                                   |
| `DataAggregator`        | データ集約クエリのインターフェース                                                                       |
| `InMemoryDataStore`     | 組み込みインメモリデータストア                                                                         |
| `DownloadManager`       | ファイルダウンロードと CSV マージユーティリティ                                                              |
| `DownloadRecord`        | ダウンロードメタデータ                                                                             |
| `AggregateOperation`    | `"sum"` \| `"count"` \| `"concat"` \| `"min"` \| `"max"` \| `"avg"` \| `"unique_count"` |
| `Locale`                | `"en"` \| `"ja"`                                                                        |
| `MeteringCollector`     | 使用量メータリングインターフェース                                                                       |
| `NoopMeteringCollector` | No-op メータリング実装                                                                          |
