@aeye/aws 0.3.9 → 0.4.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.
- package/README.md +73 -1
- package/dist/aws.d.ts +41 -29
- package/dist/aws.d.ts.map +1 -1
- package/dist/aws.js +222 -374
- package/dist/aws.js.map +1 -1
- package/dist/converse.d.ts +143 -0
- package/dist/converse.d.ts.map +1 -0
- package/dist/converse.js +483 -0
- package/dist/converse.js.map +1 -0
- package/package.json +74 -74
package/README.md
CHANGED
|
@@ -7,6 +7,10 @@ AWS Bedrock integration for the [@aeye](https://github.com/ClickerMonkey/aeye) f
|
|
|
7
7
|
- 🤖 **Multi-Model Support** - Access to all AWS Bedrock foundation models
|
|
8
8
|
- 🔐 **Automatic Authentication** - Uses AWS SDK credential chain for seamless authentication
|
|
9
9
|
- 🌊 **Streaming** - Full streaming support for real-time responses
|
|
10
|
+
- 🧠 **Reasoning** - Claude adaptive and budgeted thinking, Nova and gpt-oss reasoning, with reasoning blocks replayed across turns
|
|
11
|
+
- 📐 **Structured Output** - Converse JSON-schema output and strict tools
|
|
12
|
+
- 💾 **Prompt Caching** - Cache points from `cacheBreakpoint`, with cache read/write usage
|
|
13
|
+
- 📄 **Documents, Images, Video** - Bytes or S3 locations
|
|
10
14
|
- 🎨 **Image Generation** - Stability AI models for image creation
|
|
11
15
|
- 📊 **Embeddings** - Amazon Titan embeddings for semantic search
|
|
12
16
|
- 🔧 **Type-Safe** - Full TypeScript support with type inference
|
|
@@ -15,7 +19,10 @@ AWS Bedrock integration for the [@aeye](https://github.com/ClickerMonkey/aeye) f
|
|
|
15
19
|
## Supported Models
|
|
16
20
|
|
|
17
21
|
### Chat Models
|
|
18
|
-
- **Anthropic Claude** - Claude 3
|
|
22
|
+
- **Anthropic Claude** - Claude 3.x through 5.x
|
|
23
|
+
- **Amazon Nova** - Nova and Nova 2
|
|
24
|
+
- **OpenAI** - gpt-oss
|
|
25
|
+
- **Open-weight models** - DeepSeek, Qwen, Kimi, MiniMax, and more
|
|
19
26
|
- **Meta Llama** - Llama 2, Llama 3, Llama 3.1, Llama 3.2
|
|
20
27
|
- **Mistral AI** - Mistral 7B, Mixtral 8x7B, Mistral Large
|
|
21
28
|
- **Cohere** - Command, Command Light, Command R, Command R+
|
|
@@ -157,6 +164,16 @@ const config: AWSBedrockConfig = {
|
|
|
157
164
|
sessionToken: process.env.AWS_SESSION_TOKEN, // Optional
|
|
158
165
|
},
|
|
159
166
|
|
|
167
|
+
// Optional: Inference profile prefix. Without one, models served only
|
|
168
|
+
// through inference profiles use the region's geography (or global) profile
|
|
169
|
+
modelPrefix: 'us.',
|
|
170
|
+
|
|
171
|
+
// Optional: Latency-optimized inference, where the model offers it
|
|
172
|
+
latency: 'optimized',
|
|
173
|
+
|
|
174
|
+
// Optional: Guardrail applied to every chat request
|
|
175
|
+
guardrail: { guardrailIdentifier: 'gr-abc123', guardrailVersion: '1' },
|
|
176
|
+
|
|
160
177
|
// Optional: Default models for different capabilities
|
|
161
178
|
defaultModels: {
|
|
162
179
|
chat: 'anthropic.claude-3-sonnet-20240229-v1:0',
|
|
@@ -289,6 +306,58 @@ const response = await ai.chat.get([
|
|
|
289
306
|
});
|
|
290
307
|
```
|
|
291
308
|
|
|
309
|
+
### Documents, Video, and S3
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
const response = await ai.chat.get([
|
|
313
|
+
{
|
|
314
|
+
role: 'user',
|
|
315
|
+
content: [
|
|
316
|
+
{ type: 'text', content: 'Summarize the report and the clip.' },
|
|
317
|
+
{ type: 'file', content: 's3://my-bucket/q3-report.pdf', name: 'Q3 report.pdf' },
|
|
318
|
+
{ type: 'video', content: 's3://my-bucket/clip.mp4' },
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
], {
|
|
322
|
+
model: 'amazon.nova-pro-v1:0',
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
`s3://` URIs are sent as S3 locations; other content is sent as bytes. The
|
|
327
|
+
format comes from `format`, the MIME type, or the file extension.
|
|
328
|
+
|
|
329
|
+
### Reasoning
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
const response = await ai.chat.get([
|
|
333
|
+
{ role: 'user', content: 'Prove that there are infinitely many primes.' },
|
|
334
|
+
], {
|
|
335
|
+
model: 'anthropic.claude-opus-4-7',
|
|
336
|
+
reason: { effort: 'high' },
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
console.log(response.reasoning?.content);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Claude 4.6+ thinks adaptively (`thinking.type: 'adaptive'` with
|
|
343
|
+
`outputConfig.effort`), earlier Claude takes a thinking budget, Nova 2 takes
|
|
344
|
+
`reasoningConfig`, and gpt-oss takes `reasoning_effort`. Reasoning blocks keep
|
|
345
|
+
their signatures and redacted content, and are sent back with the assistant
|
|
346
|
+
message on later turns, as Claude requires while it uses tools.
|
|
347
|
+
|
|
348
|
+
### Prompt Caching
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const response = await ai.chat.get([
|
|
352
|
+
{ role: 'system', content: [{ type: 'text', content: longInstructions, cacheBreakpoint: true }] },
|
|
353
|
+
{ role: 'user', content: 'First question' },
|
|
354
|
+
], {
|
|
355
|
+
model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
console.log(response.usage?.text?.cached, response.usage?.text?.cacheWrite);
|
|
359
|
+
```
|
|
360
|
+
|
|
292
361
|
### Custom Request Parameters
|
|
293
362
|
|
|
294
363
|
```typescript
|
|
@@ -300,6 +369,9 @@ const response = await ai.chat.get([
|
|
|
300
369
|
maxTokens: 2048,
|
|
301
370
|
topP: 0.9,
|
|
302
371
|
stop: ['Human:', 'Assistant:'],
|
|
372
|
+
serviceTier: 'flex', // Converse serviceTier (fast → priority)
|
|
373
|
+
metadata: { team: 'search' }, // Converse requestMetadata
|
|
374
|
+
extra: { top_k: 50 }, // additionalModelRequestFields
|
|
303
375
|
});
|
|
304
376
|
```
|
|
305
377
|
|
package/dist/aws.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { AIContextAny, AIMetadataAny, EmbeddingRequest, EmbeddingResponse, ImageGenerationRequest, ImageGenerationResponse, ModelInfo, Provider } from '@aeye/ai';
|
|
9
9
|
import { type DescriptorFamily, Executor, ModelInput, Request, Response, Streamer } from '@aeye/core';
|
|
10
|
-
import { ConverseCommand, ConverseStreamCommand, InvokeModelCommand } from '@aws-sdk/client-bedrock-runtime';
|
|
10
|
+
import { ConverseCommand, ConverseStreamCommand, type GuardrailStreamConfiguration, InvokeModelCommand, type PerformanceConfigLatency } from '@aws-sdk/client-bedrock-runtime';
|
|
11
11
|
import { type ModelFamilyConfig } from './types';
|
|
12
12
|
/**
|
|
13
13
|
* Hook called before a request is made to the provider.
|
|
@@ -83,6 +83,8 @@ export interface AWSBedrockConfig {
|
|
|
83
83
|
sessionToken?: string;
|
|
84
84
|
};
|
|
85
85
|
modelPrefix?: string;
|
|
86
|
+
latency?: PerformanceConfigLatency;
|
|
87
|
+
guardrail?: GuardrailStreamConfiguration;
|
|
86
88
|
modelFamilies?: Record<string, ModelFamilyConfig>;
|
|
87
89
|
defaultModels?: {
|
|
88
90
|
chat?: ModelInput;
|
|
@@ -128,6 +130,7 @@ export declare class AWSBedrockProvider implements Provider<AWSBedrockConfig> {
|
|
|
128
130
|
defaultMetadata?: Provider['defaultMetadata'];
|
|
129
131
|
private bedrockClient;
|
|
130
132
|
private bedrockRuntimeClient;
|
|
133
|
+
private profileOnly;
|
|
131
134
|
constructor(config: AWSBedrockConfig);
|
|
132
135
|
/**
|
|
133
136
|
* Convert AWSBedrockConfig to BedrockClientConfig
|
|
@@ -160,7 +163,22 @@ export declare class AWSBedrockProvider implements Provider<AWSBedrockConfig> {
|
|
|
160
163
|
*/
|
|
161
164
|
createStreamer(config?: AWSBedrockConfig): Streamer<AIContextAny, AIMetadataAny>;
|
|
162
165
|
/**
|
|
163
|
-
*
|
|
166
|
+
* The id to call a chat model by. A configured `modelPrefix` picks a
|
|
167
|
+
* cross-region inference profile; otherwise a model Bedrock serves only
|
|
168
|
+
* through inference profiles (per the registry, or as Bedrock answered an
|
|
169
|
+
* earlier call in this region) uses the profile for the client region's
|
|
170
|
+
* geography, or the global one when only that is listed.
|
|
171
|
+
*/
|
|
172
|
+
private resolveModelId;
|
|
173
|
+
/**
|
|
174
|
+
* Make a chat call, and when Bedrock answers that the model needs an
|
|
175
|
+
* inference profile in this region (the registry's `inRegion` holds for
|
|
176
|
+
* the region it was gathered in), make it again by profile.
|
|
177
|
+
*/
|
|
178
|
+
private byProfileWhenRequired;
|
|
179
|
+
/**
|
|
180
|
+
* Build the Converse input from a generic @aeye/core Request, without the
|
|
181
|
+
* guardrail, whose shape differs between Converse and ConverseStream.
|
|
164
182
|
*/
|
|
165
183
|
private convertRequestToConverse;
|
|
166
184
|
/**
|
|
@@ -171,31 +189,23 @@ export declare class AWSBedrockProvider implements Provider<AWSBedrockConfig> {
|
|
|
171
189
|
* Execute a streaming chat completion using the Converse Stream API.
|
|
172
190
|
*/
|
|
173
191
|
private streamWithConverse;
|
|
174
|
-
/**
|
|
175
|
-
* Convert system messages to the Converse API system format.
|
|
176
|
-
*/
|
|
177
|
-
private convertSystemToConverse;
|
|
178
192
|
/**
|
|
179
193
|
* Convert @aeye/core messages to AWS Bedrock Converse API message format.
|
|
180
|
-
* Filters out system messages (handled via
|
|
194
|
+
* Filters out system messages (handled via toSystemBlocks).
|
|
181
195
|
* Merges consecutive messages with the same role as required by the API.
|
|
182
196
|
*/
|
|
183
197
|
private convertMessagesToConverse;
|
|
184
|
-
/**
|
|
185
|
-
* Convert an image content value to a Converse API ContentBlock.
|
|
186
|
-
* Only base64 data URIs are natively supported; URL images are not supported
|
|
187
|
-
* by the Converse API without fetching the bytes first.
|
|
188
|
-
*/
|
|
189
|
-
private convertImageContent;
|
|
190
198
|
/**
|
|
191
199
|
* Convert @aeye/core tool definitions to AWS Bedrock Converse API tool format.
|
|
192
200
|
*
|
|
193
|
-
* Strict-tool support is best-effort and per-model: the
|
|
194
|
-
*
|
|
195
|
-
* `model.strictFormat` → `model.provider` → `id` prefix. Bedrock
|
|
201
|
+
* Strict-tool support is best-effort and per-model: the budget's
|
|
202
|
+
* descriptor comes from `buildSchemaBudget` (see `@aeye/ai`). Bedrock
|
|
196
203
|
* surfaces both Anthropic-family Claude models and (in some regions)
|
|
197
|
-
* OpenAI-shaped tools. Models without
|
|
198
|
-
*
|
|
204
|
+
* OpenAI-shaped tools. Models without strict support use their family's
|
|
205
|
+
* non-strict descriptor, and models without a family Bedrock speaks fall
|
|
206
|
+
* back to LENIENT — silent degradation. Tools with a strict descriptor are
|
|
207
|
+
* sent with Converse's `strict` flag, which constrains the model's calls to
|
|
208
|
+
* the schema. The chosen descriptor is pinned on each
|
|
199
209
|
* `ToolDefinition.descriptor` so the Prompt loop can apply the matching
|
|
200
210
|
* strictify when validating tool arguments.
|
|
201
211
|
*
|
|
@@ -203,8 +213,21 @@ export declare class AWSBedrockProvider implements Provider<AWSBedrockConfig> {
|
|
|
203
213
|
* params, 16 union types across the whole request) — those are tracked
|
|
204
214
|
* by the shared `SchemaBudget` so over-budget tools degrade to LENIENT
|
|
205
215
|
* silently rather than failing the API call.
|
|
216
|
+
*
|
|
217
|
+
* Converse has no free-text tools, so those go as their one-field function
|
|
218
|
+
* with any grammar in the description. It has no `none` choice either, so
|
|
219
|
+
* tools are left out then, unless the conversation already used them
|
|
220
|
+
* (Converse rejects tool blocks without a tool config).
|
|
206
221
|
*/
|
|
207
222
|
private convertToolsToConverse;
|
|
223
|
+
/**
|
|
224
|
+
* Convert a schema response format to Converse structured output. Converse
|
|
225
|
+
* rejects schemas outside its strict subset, so a schema goes only when the
|
|
226
|
+
* model's strict descriptor can shape it; the descriptor is pinned on the
|
|
227
|
+
* format so the Prompt validator can apply the matching strictify. Plain
|
|
228
|
+
* JSON has no Converse mode.
|
|
229
|
+
*/
|
|
230
|
+
private convertResponseFormat;
|
|
208
231
|
/**
|
|
209
232
|
* The set of strict descriptor families this provider can speak through
|
|
210
233
|
* Bedrock. Defaults to `['openai', 'anthropic', 'google']` — Bedrock
|
|
@@ -212,17 +235,6 @@ export declare class AWSBedrockProvider implements Provider<AWSBedrockConfig> {
|
|
|
212
235
|
* families.
|
|
213
236
|
*/
|
|
214
237
|
protected supportedStrictFamilies: ReadonlySet<DescriptorFamily>;
|
|
215
|
-
/**
|
|
216
|
-
* Build a SchemaBudget tuned to the resolved strict-format family.
|
|
217
|
-
* Bedrock surfaces multiple model families; the descriptor pick handles
|
|
218
|
-
* any in `supportedStrictFamilies`. Mismatched families fall back to
|
|
219
|
-
* LENIENT silently.
|
|
220
|
-
*/
|
|
221
|
-
private buildSchemaBudget;
|
|
222
|
-
/**
|
|
223
|
-
* Map a Bedrock Converse API stop reason to the @aeye/core FinishReason type.
|
|
224
|
-
*/
|
|
225
|
-
private mapStopReason;
|
|
226
238
|
generateImage: Provider['generateImage'];
|
|
227
239
|
embed: Provider['embed'];
|
|
228
240
|
private handleAWSError;
|
package/dist/aws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../src/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,SAAS,EACT,QAAQ,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../src/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,SAAS,EACT,QAAQ,EACT,MA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