Skip to content

Commit fd26847

Browse files
badlogicnickchan2
andcommitted
feat(ai): Add Amazon Bedrock provider (#494)
Adds support for Amazon Bedrock with Claude models including: - Full streaming support via Converse API - Reasoning/thinking support for Claude models - Cross-region inference model ID handling - Multiple AWS credential sources (profile, IAM keys, API keys) - Image support in messages and tool results - Unicode surrogate sanitization Also adds 'Adding a New Provider' documentation to AGENTS.md and README. Co-authored-by: nickchan2 <nickchan2@users.noreply.github.com>
1 parent 4f216d3 commit fd26847

31 files changed

Lines changed: 4020 additions & 3063 deletions

AGENTS.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,46 @@ Use these sections under `## [Unreleased]`:
7575
- **Internal changes (from issues)**: `Fixed foo bar ([#123](https://github.com/badlogic/pi-mono/issues/123))`
7676
- **External contributions**: `Added feature X ([#456](https://github.com/badlogic/pi-mono/pull/456) by [@username](https://github.com/username))`
7777

78+
## Adding a New LLM Provider (packages/ai)
79+
80+
Adding a new provider requires changes across multiple files:
81+
82+
### 1. Core Types (`packages/ai/src/types.ts`)
83+
- Add API identifier to `Api` type union (e.g., `"bedrock-converse-stream"`)
84+
- Create options interface extending `StreamOptions`
85+
- Add mapping to `ApiOptionsMap`
86+
- Add provider name to `KnownProvider` type union
87+
88+
### 2. Provider Implementation (`packages/ai/src/providers/`)
89+
Create provider file exporting:
90+
- `stream<Provider>()` function returning `AssistantMessageEventStream`
91+
- Message/tool conversion functions
92+
- Response parsing emitting standardized events (`text`, `tool_call`, `thinking`, `usage`, `stop`)
93+
94+
### 3. Stream Integration (`packages/ai/src/stream.ts`)
95+
- Import provider's stream function and options type
96+
- Add credential detection in `getEnvApiKey()`
97+
- Add case in `mapOptionsForApi()` for `SimpleStreamOptions` mapping
98+
- Add provider to `streamFunctions` map
99+
100+
### 4. Model Generation (`packages/ai/scripts/generate-models.ts`)
101+
- Add logic to fetch/parse models from provider source
102+
- Map to standardized `Model` interface
103+
104+
### 5. Tests (`packages/ai/test/`)
105+
Add provider to: `stream.test.ts`, `tokens.test.ts`, `abort.test.ts`, `empty.test.ts`, `context-overflow.test.ts`, `image-limits.test.ts`, `unicode-surrogate.test.ts`, `tool-call-without-result.test.ts`, `image-tool-result.test.ts`, `total-tokens.test.ts`
106+
107+
For non-standard auth, create utility (e.g., `bedrock-utils.ts`) with credential detection.
108+
109+
### 6. Coding Agent (`packages/coding-agent/`)
110+
- `src/core/model-resolver.ts`: Add default model ID to `DEFAULT_MODELS`
111+
- `src/cli/args.ts`: Add env var documentation
112+
- `README.md`: Add provider setup instructions
113+
114+
### 7. Documentation
115+
- `packages/ai/README.md`: Add to providers table, document options/auth, add env vars
116+
- `packages/ai/CHANGELOG.md`: Add entry under `## [Unreleased]`
117+
78118
## Releasing
79119

80120
**Lockstep versioning**: All packages always share the same version number. Every release updates all packages together.

0 commit comments

Comments
 (0)