@sentry/warden 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/agents.lock +59 -0
  2. package/dist/cli/args.d.ts +6 -0
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +7 -1
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/commands/add.js +1 -1
  7. package/dist/cli/commands/add.js.map +1 -1
  8. package/dist/cli/commands/init.d.ts.map +1 -1
  9. package/dist/cli/commands/init.js +16 -8
  10. package/dist/cli/commands/init.js.map +1 -1
  11. package/dist/cli/commands/sync.d.ts.map +1 -1
  12. package/dist/cli/commands/sync.js +16 -4
  13. package/dist/cli/commands/sync.js.map +1 -1
  14. package/dist/cli/fix.d.ts.map +1 -1
  15. package/dist/cli/fix.js +6 -1
  16. package/dist/cli/fix.js.map +1 -1
  17. package/dist/cli/log-cleanup.d.ts +6 -5
  18. package/dist/cli/log-cleanup.d.ts.map +1 -1
  19. package/dist/cli/log-cleanup.js +11 -10
  20. package/dist/cli/log-cleanup.js.map +1 -1
  21. package/dist/cli/main.d.ts.map +1 -1
  22. package/dist/cli/main.js +44 -19
  23. package/dist/cli/main.js.map +1 -1
  24. package/dist/cli/output/formatters.d.ts +6 -1
  25. package/dist/cli/output/formatters.d.ts.map +1 -1
  26. package/dist/cli/output/formatters.js +18 -0
  27. package/dist/cli/output/formatters.js.map +1 -1
  28. package/dist/cli/output/index.d.ts +1 -1
  29. package/dist/cli/output/index.d.ts.map +1 -1
  30. package/dist/cli/output/index.js +1 -1
  31. package/dist/cli/output/index.js.map +1 -1
  32. package/dist/cli/output/jsonl.d.ts +2 -1
  33. package/dist/cli/output/jsonl.d.ts.map +1 -1
  34. package/dist/cli/output/jsonl.js +3 -3
  35. package/dist/cli/output/jsonl.js.map +1 -1
  36. package/dist/cli/output/reporter.d.ts +4 -0
  37. package/dist/cli/output/reporter.d.ts.map +1 -1
  38. package/dist/cli/output/reporter.js +14 -0
  39. package/dist/cli/output/reporter.js.map +1 -1
  40. package/dist/cli/output/tasks.d.ts +3 -1
  41. package/dist/cli/output/tasks.d.ts.map +1 -1
  42. package/dist/cli/output/tasks.js +28 -4
  43. package/dist/cli/output/tasks.js.map +1 -1
  44. package/dist/cli/terminal.d.ts +4 -3
  45. package/dist/cli/terminal.d.ts.map +1 -1
  46. package/dist/cli/terminal.js +22 -9
  47. package/dist/cli/terminal.js.map +1 -1
  48. package/dist/config/loader.d.ts +3 -1
  49. package/dist/config/loader.d.ts.map +1 -1
  50. package/dist/config/loader.js +2 -0
  51. package/dist/config/loader.js.map +1 -1
  52. package/dist/config/schema.d.ts +63 -0
  53. package/dist/config/schema.d.ts.map +1 -1
  54. package/dist/config/schema.js +19 -1
  55. package/dist/config/schema.js.map +1 -1
  56. package/dist/evals/runner.d.ts.map +1 -1
  57. package/dist/evals/runner.js +1 -0
  58. package/dist/evals/runner.js.map +1 -1
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +2 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/output/dedup.d.ts +14 -10
  64. package/dist/output/dedup.d.ts.map +1 -1
  65. package/dist/output/dedup.js +39 -17
  66. package/dist/output/dedup.js.map +1 -1
  67. package/dist/output/github-checks.d.ts +4 -2
  68. package/dist/output/github-checks.d.ts.map +1 -1
  69. package/dist/output/github-checks.js +12 -10
  70. package/dist/output/github-checks.js.map +1 -1
  71. package/dist/output/renderer.d.ts.map +1 -1
  72. package/dist/output/renderer.js +11 -7
  73. package/dist/output/renderer.js.map +1 -1
  74. package/dist/output/types.d.ts +3 -1
  75. package/dist/output/types.d.ts.map +1 -1
  76. package/dist/sdk/analyze.d.ts.map +1 -1
  77. package/dist/sdk/analyze.js +21 -1
  78. package/dist/sdk/analyze.js.map +1 -1
  79. package/dist/sdk/prompt.d.ts.map +1 -1
  80. package/dist/sdk/prompt.js +2 -0
  81. package/dist/sdk/prompt.js.map +1 -1
  82. package/dist/sdk/session.d.ts +43 -0
  83. package/dist/sdk/session.d.ts.map +1 -0
  84. package/dist/sdk/session.js +105 -0
  85. package/dist/sdk/session.js.map +1 -0
  86. package/dist/sdk/types.d.ts +3 -0
  87. package/dist/sdk/types.d.ts.map +1 -1
  88. package/dist/sdk/types.js.map +1 -1
  89. package/dist/skills/remote.d.ts +4 -0
  90. package/dist/skills/remote.d.ts.map +1 -1
  91. package/dist/skills/remote.js +47 -27
  92. package/dist/skills/remote.js.map +1 -1
  93. package/dist/types/index.d.ts +21 -0
  94. package/dist/types/index.d.ts.map +1 -1
  95. package/dist/types/index.js +26 -0
  96. package/dist/types/index.js.map +1 -1
  97. package/package.json +1 -1
  98. package/.claude-plugin/marketplace.json +0 -20
  99. package/.mcp.json +0 -8
  100. package/agents.toml +0 -7
  101. package/conductor.json +0 -8
  102. package/evals/README.md +0 -154
  103. package/evals/bug-detection.yaml +0 -56
  104. package/evals/fixtures/ignores-style-issues/utils.ts +0 -48
  105. package/evals/fixtures/missing-await/cache.ts +0 -45
  106. package/evals/fixtures/null-property-access/handler.ts +0 -36
  107. package/evals/fixtures/off-by-one/paginator.ts +0 -38
  108. package/evals/fixtures/sql-injection/api.ts +0 -59
  109. package/evals/fixtures/stale-closure/counter.tsx +0 -33
  110. package/evals/fixtures/wrong-comparison/validator.ts +0 -52
  111. package/evals/fixtures/xss-reflected/server.ts +0 -55
  112. package/evals/precision.yaml +0 -15
  113. package/evals/security-scanning.yaml +0 -24
  114. package/evals/skills/bug-detection.md +0 -33
  115. package/evals/skills/precision.md +0 -18
  116. package/evals/skills/security-scanning.md +0 -32
  117. package/plugins/.claude-plugin/marketplace.json +0 -14
  118. package/plugins/warden/.claude-plugin/plugin.json +0 -7
  119. package/plugins/warden/skills/warden/SKILL.md +0 -78
  120. package/plugins/warden/skills/warden/references/cli-reference.md +0 -144
  121. package/plugins/warden/skills/warden/references/config-schema.md +0 -113
  122. package/plugins/warden/skills/warden/references/configuration.md +0 -108
  123. package/plugins/warden/skills/warden/references/creating-skills.md +0 -84
  124. package/scripts/update-pricing.ts +0 -88
@@ -1,144 +0,0 @@
1
- # CLI Reference
2
-
3
- ## Usage
4
-
5
- ```
6
- warden [command] [targets...] [options]
7
- ```
8
-
9
- Analyze code for security issues and code quality.
10
-
11
- ## Commands
12
-
13
- | Command | Description |
14
- |---------|-------------|
15
- | `(default)` | Run analysis on targets or using warden.toml skills |
16
- | `init` | Initialize warden.toml and GitHub workflow |
17
- | `add [skill]` | Add a skill to warden.toml |
18
- | `sync [remote]` | Update cached remote skills to latest |
19
- | `setup-app` | Create a GitHub App for Warden via manifest flow |
20
-
21
- ## Targets
22
-
23
- | Target | Description |
24
- |--------|-------------|
25
- | `<files>` | Analyze specific files (e.g., `src/auth.ts`) |
26
- | `<glob>` | Analyze files matching pattern (e.g., `"src/**/*.ts"`) |
27
- | `<git-ref>` | Analyze changes from git ref (e.g., `HEAD~3`, `main..feature`) |
28
- | `(none)` | Analyze uncommitted changes using warden.toml skills |
29
-
30
- Ambiguous targets (no path separator, no extension) are resolved by checking if a file exists at the path. Use `--git` to force git ref interpretation.
31
-
32
- ## Options
33
-
34
- | Option | Description |
35
- |--------|-------------|
36
- | `--skill <name>` | Run only this skill (default: run all built-in skills) |
37
- | `--config <path>` | Path to warden.toml (default: `./warden.toml`) |
38
- | `-m, --model <model>` | Model to use (fallback when not set in config) |
39
- | `--json` | Output results as JSON |
40
- | `-o, --output <path>` | Write full run output to a JSONL file |
41
- | `--fail-on <severity>` | Exit with code 1 if findings >= severity |
42
- | `--report-on <severity>` | Only show findings >= severity in output |
43
- | `--fix` | Automatically apply all suggested fixes |
44
- | `--parallel <n>` | Max concurrent skill executions (default: 4) |
45
- | `--git` | Force ambiguous targets to be treated as git refs |
46
- | `--offline` | Use cached remote skills without network access |
47
- | `-q, --quiet` | Errors and final summary only |
48
- | `-v, --verbose` | Show real-time findings and hunk details |
49
- | `-vv` | Show debug info (token counts, latencies) |
50
- | `--debug` | Enable debug output (equivalent to `-vv`) |
51
- | `--log` | Use log output (no animations, timestamped) |
52
- | `--color / --no-color` | Override color detection |
53
- | `-h, --help` | Show help message |
54
- | `-V, --version` | Show version number |
55
-
56
- ## Per-Command Options
57
-
58
- **Init:**
59
- | Option | Description |
60
- |--------|-------------|
61
- | `-f, --force` | Overwrite existing files |
62
-
63
- **Add:**
64
- | Option | Description |
65
- |--------|-------------|
66
- | `--list` | List available skills |
67
- | `--remote <ref>` | Remote repository (`owner/repo`, URL, or with `@sha`) |
68
- | `--force` | Bypass skill cache and fetch latest |
69
-
70
- **Sync:**
71
- | Option | Description |
72
- |--------|-------------|
73
- | `--remote <ref>` | Specific remote to sync (default: all) |
74
-
75
- **Setup-app:**
76
- | Option | Description |
77
- |--------|-------------|
78
- | `--org <name>` | Create under organization (default: personal) |
79
- | `--port <number>` | Local server port (default: 3000) |
80
- | `--timeout <sec>` | Callback timeout in seconds (default: 300) |
81
- | `--name <string>` | Custom app name (default: Warden) |
82
- | `--no-open` | Print URL instead of opening browser |
83
-
84
- ## Severity Levels
85
-
86
- Used in `--fail-on` and `--report-on`:
87
-
88
- | Level | Meaning |
89
- |-------|---------|
90
- | `critical` | Must fix before merge |
91
- | `high` | Should fix before merge |
92
- | `medium` | Worth reviewing |
93
- | `low` | Minor improvement |
94
- | `info` | Informational only |
95
- | `off` | Disable the threshold |
96
-
97
- ## Exit Codes
98
-
99
- | Code | Meaning |
100
- |------|---------|
101
- | `0` | No findings at or above `--fail-on` threshold |
102
- | `1` | Findings at or above `--fail-on` threshold |
103
-
104
- ## Examples
105
-
106
- ```bash
107
- # Initialize
108
- warden init
109
-
110
- # Interactive skill selection
111
- warden add
112
- warden add security-review
113
- warden add --list
114
-
115
- # Remote skills
116
- warden add --remote getsentry/skills --skill security-review
117
- warden add --remote https://github.com/getsentry/skills --skill security-review
118
- warden add --remote getsentry/skills@abc123 --skill security-review
119
-
120
- # Run analysis
121
- warden # Skills from warden.toml
122
- warden src/auth.ts # Specific file
123
- warden src/auth.ts --skill security-review
124
- warden "src/**/*.ts" # Glob pattern
125
- warden HEAD~3 # Git changes
126
- warden HEAD~3 --skill security-review
127
- warden main..HEAD # Branch diff
128
-
129
- # Output control
130
- warden --json
131
- warden --fail-on high
132
- warden -o results.jsonl
133
-
134
- # Fix mode
135
- warden --fix
136
-
137
- # Cached skills only
138
- warden --offline
139
- warden sync # Update all unpinned remote skills
140
-
141
- # GitHub App setup
142
- warden setup-app
143
- warden setup-app --org myorg
144
- ```
@@ -1,113 +0,0 @@
1
- # warden.toml Configuration Schema
2
-
3
- ## Top-Level Structure
4
-
5
- ```toml
6
- version = 1 # Required, must be 1
7
-
8
- [defaults] # Optional, inherited by all skills
9
- [[skills]] # Required, array of skill configs
10
- ```
11
-
12
- ## Defaults Section
13
-
14
- ```toml
15
- [defaults]
16
- model = "claude-sonnet-4-20250514" # Default model
17
- maxTurns = 50 # Max agentic turns per hunk
18
- defaultBranch = "main" # Base branch for comparisons
19
- failOn = "high" # Exit 1 if findings >= this severity
20
- reportOn = "medium" # Show findings >= this severity
21
- maxFindings = 50 # Max findings to report (0 = unlimited)
22
- reportOnSuccess = false # Post report even with no findings
23
- paths = ["src/**/*.ts"] # Include only matching files
24
- ignorePaths = ["*.test.ts"] # Exclude matching files
25
-
26
- [defaults.chunking]
27
- enabled = true # Enable hunk-based chunking
28
-
29
- [defaults.chunking.coalesce]
30
- enabled = true # Merge nearby hunks
31
- maxGapLines = 30 # Lines between hunks to merge
32
- maxChunkSize = 8000 # Max chars per chunk
33
-
34
- [[defaults.chunking.filePatterns]]
35
- pattern = "*.config.*" # Glob pattern
36
- mode = "whole-file" # per-hunk | whole-file | skip
37
- ```
38
-
39
- ## Skills Section
40
-
41
- ```toml
42
- [[skills]]
43
- name = "skill-name" # Required, unique identifier
44
- remote = "owner/repo@sha" # Optional, fetch skill from GitHub repo
45
- paths = ["src/**"] # Include only matching files
46
- ignorePaths = ["**/*.test.ts"] # Exclude matching files
47
-
48
- # Optional overrides (inherit from defaults if not set)
49
- model = "claude-opus-4-20250514"
50
- maxTurns = 100
51
- failOn = "critical"
52
- reportOn = "high"
53
- maxFindings = 20
54
- reportOnSuccess = true
55
-
56
- [[skills.triggers]]
57
- type = "pull_request" # Required: pull_request | local | schedule
58
- actions = ["opened", "synchronize"] # Required for pull_request
59
-
60
- # Schedule-specific (only for type = "schedule")
61
- [[skills.triggers]]
62
- type = "schedule"
63
-
64
- [skills.triggers.schedule]
65
- issueTitle = "Daily Security Review" # GitHub issue title for tracking
66
- createFixPR = true # Create PR with fixes
67
- fixBranchPrefix = "security-fix" # Branch name prefix
68
- ```
69
-
70
- **Trigger types:**
71
- - `pull_request` - Triggers on PR events
72
- - `local` - Local CLI only (will not run in CI)
73
- - `schedule` - Cron schedule (GitHub Action only)
74
-
75
- All skills run locally regardless of trigger type. Skills with no triggers run everywhere (wildcard). Use `type = "local"` for skills that should *only* run locally.
76
-
77
- **Actions (for pull_request):**
78
- - `opened`, `synchronize`, `reopened`, `closed`
79
-
80
- ## Severity Values
81
-
82
- Used in `failOn` and `reportOn`:
83
- - `critical` - Most severe
84
- - `high`
85
- - `medium`
86
- - `low`
87
- - `info` - Least severe
88
- - `off` - Disable threshold
89
-
90
- ## Built-in Skip Patterns
91
-
92
- Always skipped (cannot be overridden):
93
- - Package locks: `pnpm-lock.yaml`, `package-lock.json`, `yarn.lock`, `Cargo.lock`, etc.
94
- - Minified files: `**/*.min.js`, `**/*.min.css`
95
- - Build artifacts: `dist/`, `build/`, `node_modules/`, `.next/`, `__pycache__/`
96
- - Generated code: `*.generated.*`, `*.g.ts`, `__generated__/`
97
-
98
- ## Environment Variables
99
-
100
- | Variable | Purpose |
101
- |----------|---------|
102
- | `WARDEN_ANTHROPIC_API_KEY` | Claude API key (required) |
103
- | `WARDEN_MODEL` | Default model (lowest priority) |
104
- | `WARDEN_STATE_DIR` | Override cache location (default: `~/.local/warden`) |
105
- | `WARDEN_SKILL_CACHE_TTL` | Cache TTL in seconds for unpinned remotes (default: 86400) |
106
-
107
- ## Model Precedence (highest to lowest)
108
-
109
- 1. Skill-level `model`
110
- 2. `[defaults]` `model`
111
- 3. CLI `--model` flag
112
- 4. `WARDEN_MODEL` env var
113
- 5. SDK default
@@ -1,108 +0,0 @@
1
- # Configuration (warden.toml)
2
-
3
- See [config-schema.md](config-schema.md) for the complete schema reference.
4
-
5
- ## Minimal Example
6
-
7
- ```toml
8
- version = 1
9
-
10
- [defaults]
11
- model = "claude-sonnet-4-20250514"
12
-
13
- [[skills]]
14
- name = "find-bugs"
15
- paths = ["src/**/*.ts"]
16
-
17
- [[skills.triggers]]
18
- type = "pull_request"
19
- actions = ["opened", "synchronize"]
20
- ```
21
-
22
- ## Skill Configuration
23
-
24
- Skills define what to analyze and when. Each skill requires a name. Triggers are optional — skills with no triggers run everywhere (PR, local, schedule). All skills run locally regardless of trigger type.
25
-
26
- ```toml
27
- [[skills]]
28
- name = "security-review"
29
- paths = ["src/auth/**", "src/payments/**"]
30
- failOn = "critical"
31
- reportOn = "high"
32
- maxFindings = 20
33
-
34
- [[skills.triggers]]
35
- type = "pull_request"
36
- actions = ["opened", "synchronize"]
37
- ```
38
-
39
- **Trigger types:** `pull_request`, `local` (local-only), `schedule` (CI-only)
40
-
41
- **Actions (pull_request):** `opened`, `synchronize`, `reopened`, `closed`
42
-
43
- ## Common Patterns
44
-
45
- **Strict security on critical files:**
46
- ```toml
47
- [[skills]]
48
- name = "security-review"
49
- model = "claude-opus-4-20250514"
50
- maxTurns = 100
51
- paths = ["src/auth/**", "src/payments/**"]
52
- failOn = "critical"
53
-
54
- [[skills.triggers]]
55
- type = "pull_request"
56
- actions = ["opened", "synchronize"]
57
- ```
58
-
59
- **Skip test files:**
60
- ```toml
61
- [[skills]]
62
- name = "find-bugs"
63
- paths = ["src/**/*.ts"]
64
- ignorePaths = ["**/*.test.ts", "**/*.spec.ts"]
65
- ```
66
-
67
- **Whole-file analysis for configs:**
68
- ```toml
69
- [defaults.chunking.filePatterns]
70
- pattern = "*.config.*"
71
- mode = "whole-file"
72
- ```
73
-
74
- ## Model Precedence
75
-
76
- From highest to lowest priority:
77
-
78
- 1. Skill-level `model`
79
- 2. `[defaults]` `model`
80
- 3. CLI `--model` flag
81
- 4. `WARDEN_MODEL` env var
82
- 5. SDK default
83
-
84
- ## Environment Variables
85
-
86
- | Variable | Purpose |
87
- |----------|---------|
88
- | `WARDEN_ANTHROPIC_API_KEY` | Claude API key (required unless using Claude Code subscription) |
89
- | `WARDEN_MODEL` | Default model (lowest priority) |
90
- | `WARDEN_STATE_DIR` | Override cache location (default: `~/.local/warden`) |
91
- | `WARDEN_SKILL_CACHE_TTL` | Cache TTL in seconds for unpinned remotes (default: 86400) |
92
-
93
- ## Troubleshooting
94
-
95
- **No findings reported:**
96
- - Check `--report-on` threshold (default shows all)
97
- - Verify skill matches file types in `paths`
98
- - Use `-v` to see which files are being analyzed
99
-
100
- **Files being skipped:**
101
- - Built-in skip patterns: lock files, minified, `node_modules/`, `dist/`
102
- - Check `ignorePaths` in config
103
- - Use `-vv` to see skip reasons
104
-
105
- **Token/cost issues:**
106
- - Reduce `maxTurns` (default: 50)
107
- - Use chunking settings to control chunk size
108
- - Filter to relevant files with `paths`
@@ -1,84 +0,0 @@
1
- # Creating Skills
2
-
3
- Skills are markdown files that tell Warden what to look for. They follow the [agentskills.io](https://agentskills.io) specification.
4
-
5
- ## Skill Discovery
6
-
7
- Warden searches these directories in order (first match wins):
8
-
9
- ```
10
- .agents/skills/{name}/SKILL.md # Primary (recommended)
11
- .claude/skills/{name}/SKILL.md # Backup (Claude Code convention)
12
- ```
13
-
14
- ## SKILL.md Format
15
-
16
- ```markdown
17
- ---
18
- name: my-skill
19
- description: What this skill analyzes
20
- allowed-tools: Read Grep Glob
21
- ---
22
-
23
- [Analysis instructions for the agent]
24
-
25
- ## What to Look For
26
- - Specific issue type 1
27
- - Specific issue type 2
28
-
29
- ## Output Format
30
- Report findings with severity, location, and suggested fix.
31
- ```
32
-
33
- ## Available Tools
34
-
35
- `Read`, `Glob`, `Grep`, `WebFetch`, `WebSearch`, `Bash`, `Write`, `Edit`
36
-
37
- Most review skills only need `Read`, `Grep`, and `Glob` for exploring context.
38
-
39
- ## Writing Checklist
40
-
41
- - One skill, one concern ("security review" not "code quality")
42
- - Clear criteria for what counts as an issue and at what severity
43
- - Actionable findings that include how to fix
44
- - Examples of good and bad code where helpful
45
-
46
- ## Remote Skills
47
-
48
- Skills can be fetched from GitHub repositories:
49
-
50
- ```bash
51
- # Add a remote skill
52
- warden add --remote getsentry/skills --skill security-review
53
-
54
- # Add with version pinning (recommended for reproducibility)
55
- warden add --remote getsentry/skills@abc123 --skill security-review
56
-
57
- # List skills in a remote repo
58
- warden add --remote getsentry/skills --list
59
-
60
- # Update all unpinned remote skills
61
- warden sync
62
-
63
- # Update specific repo
64
- warden sync getsentry/skills
65
-
66
- # Run with cached skills only (no network)
67
- warden --offline
68
- ```
69
-
70
- **Remote skill in warden.toml:**
71
-
72
- ```toml
73
- [[skills]]
74
- name = "security-review"
75
- remote = "getsentry/skills@abc123"
76
-
77
- [[skills.triggers]]
78
- type = "pull_request"
79
- actions = ["opened", "synchronize"]
80
- ```
81
-
82
- **Cache location:** `~/.local/warden/skills/` (override with `WARDEN_STATE_DIR`)
83
-
84
- **Cache TTL:** 24 hours for unpinned refs (override with `WARDEN_SKILL_CACHE_TTL` in seconds)
@@ -1,88 +0,0 @@
1
- /**
2
- * Fetches Anthropic model pricing from pydantic/genai-prices and writes
3
- * src/sdk/model-pricing.json. Rerun whenever prices change.
4
- *
5
- * Usage: pnpm update-pricing
6
- */
7
-
8
- const SOURCE_URL =
9
- 'https://raw.githubusercontent.com/pydantic/genai-prices/main/prices/data.json';
10
- const OUTPUT_PATH = new URL('../src/sdk/model-pricing.json', import.meta.url);
11
-
12
- type PriceValue = number | { base: number; tiers: unknown[] };
13
-
14
- interface PriceEntry {
15
- input_mtok?: PriceValue;
16
- output_mtok?: PriceValue;
17
- cache_read_mtok?: PriceValue;
18
- cache_write_mtok?: PriceValue;
19
- }
20
-
21
- /** Extract the base price from a flat number or tiered pricing object. */
22
- function basePrice(v: PriceValue | undefined): number {
23
- if (v == null) return 0;
24
- if (typeof v === 'number') return v;
25
- return v.base;
26
- }
27
-
28
- interface ModelEntry {
29
- id: string;
30
- name: string;
31
- prices: PriceEntry;
32
- }
33
-
34
- interface ProviderEntry {
35
- id: string;
36
- models: ModelEntry[];
37
- }
38
-
39
- interface ModelPricingRecord {
40
- inputPerMTok: number;
41
- outputPerMTok: number;
42
- cacheReadPerMTok: number;
43
- cacheWritePerMTok: number;
44
- }
45
-
46
- async function main() {
47
- const res = await fetch(SOURCE_URL);
48
- if (!res.ok) {
49
- throw new Error(`Failed to fetch pricing data: ${res.status} ${res.statusText}`);
50
- }
51
-
52
- const providers: ProviderEntry[] = await res.json();
53
- const anthropic = providers.find((p) => p.id === 'anthropic');
54
- if (!anthropic) {
55
- throw new Error('Anthropic provider not found in pricing data');
56
- }
57
-
58
- const pricing: Record<string, ModelPricingRecord> = {};
59
-
60
- if (!anthropic.models || !Array.isArray(anthropic.models)) {
61
- throw new Error('Anthropic provider has invalid or missing models array');
62
- }
63
-
64
- for (const model of anthropic.models) {
65
- const p = model.prices;
66
- if (!p || typeof p !== 'object') {
67
- continue;
68
- }
69
- pricing[model.id] = {
70
- inputPerMTok: basePrice(p.input_mtok),
71
- outputPerMTok: basePrice(p.output_mtok),
72
- cacheReadPerMTok: basePrice(p.cache_read_mtok),
73
- cacheWritePerMTok: basePrice(p.cache_write_mtok),
74
- };
75
- }
76
-
77
- const { writeFileSync } = await import('node:fs');
78
- const { fileURLToPath } = await import('node:url');
79
- writeFileSync(fileURLToPath(OUTPUT_PATH), JSON.stringify(pricing, null, 2) + '\n');
80
-
81
- const count = Object.keys(pricing).length;
82
- console.log(`Wrote ${count} model(s) to src/sdk/model-pricing.json`);
83
- }
84
-
85
- main().catch((err) => {
86
- console.error(err);
87
- process.exit(1);
88
- });