@namzu/bedrock 1.0.1 → 1.0.3
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/CHANGELOG.md +54 -0
- package/dist/__tests__/bedrock.test.js +6 -1
- package/dist/__tests__/bedrock.test.js.map +1 -1
- package/dist/__tests__/error-taxonomy.test.d.ts +17 -0
- package/dist/__tests__/error-taxonomy.test.d.ts.map +1 -0
- package/dist/__tests__/error-taxonomy.test.js +192 -0
- package/dist/__tests__/error-taxonomy.test.js.map +1 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +125 -70
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/bedrock.test.ts +7 -1
- package/src/__tests__/error-taxonomy.test.ts +236 -0
- package/src/client.ts +129 -70
- package/src/index.ts +3 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3fd2524: Normalize request-start and mid-stream failures across all seven provider
|
|
8
|
+
drivers with the new public `ProviderRequestError` taxonomy. Errors expose
|
|
9
|
+
`kind` (`throttle`, `network`, `auth`, `context_overflow`, `bad_request`, or
|
|
10
|
+
`server`), `providerId`, and optional `status` / `retryAfterMs`, with
|
|
11
|
+
`isProviderRequestError` available for structural narrowing across package
|
|
12
|
+
copies.
|
|
13
|
+
|
|
14
|
+
Provider error messages and metadata deliberately omit vendor response bodies,
|
|
15
|
+
URLs, messages, and causes because upstream errors can echo credentials. HTTP
|
|
16
|
+
dialect-mismatch diagnostics now keep only the endpoint origin and status.
|
|
17
|
+
Caller-owned aborts remain unchanged instead of being reclassified.
|
|
18
|
+
|
|
19
|
+
The runtime preserves the classified error through streaming and publishes its
|
|
20
|
+
safe metadata as `Run.lastProviderError` and
|
|
21
|
+
`run_failed.providerError`. Bedrock stream-exception events and provider
|
|
22
|
+
iterator/SSE failures no longer appear as clean end-of-stream.
|
|
23
|
+
|
|
24
|
+
`retryAfterMs` is metadata only; this change does not add retries or alter vendor
|
|
25
|
+
SDK retry settings. Provider packages now require `@namzu/sdk >=1.3.0`, the
|
|
26
|
+
first SDK release containing these runtime helpers and types.
|
|
27
|
+
|
|
28
|
+
Ollama now maps `done_reason: "length"` truthfully so runtime continuation can
|
|
29
|
+
run. LM Studio treats content-free `contextLengthReached` as context overflow,
|
|
30
|
+
while preserving `"length"` after partial content, and creates its WebSocket
|
|
31
|
+
client lazily on first use.
|
|
32
|
+
|
|
33
|
+
## 1.0.2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- f1f000c: Declare honest driver capabilities on each provider instance.
|
|
38
|
+
|
|
39
|
+
Every shipped driver now exposes `readonly capabilities` (and
|
|
40
|
+
re-exports its `*_CAPABILITIES` constant from the client module)
|
|
41
|
+
describing what the DRIVER does — not what the vendor API could do —
|
|
42
|
+
so the SDK's capability negotiation can warn instead of silently
|
|
43
|
+
degrading:
|
|
44
|
+
|
|
45
|
+
- `@namzu/ollama`: `supportsTools: false`, `supportsVision: false`
|
|
46
|
+
(the driver never sends tool schemas and drops image attachments).
|
|
47
|
+
- `@namzu/lmstudio`: `supportsTools` corrected `true` → `false` and
|
|
48
|
+
`supportsFunctionCalling` `true` → `false` — the driver folds tool
|
|
49
|
+
messages into user text and never sends tool schemas;
|
|
50
|
+
`supportsVision: false`.
|
|
51
|
+
- `@namzu/anthropic`: full (`supportsVision: true` — image attachments
|
|
52
|
+
already mapped).
|
|
53
|
+
- `@namzu/bedrock`, `@namzu/openrouter`, `@namzu/http`: tools pass
|
|
54
|
+
through (`supportsTools: true`) but `supportsVision: false` until
|
|
55
|
+
their message translation maps attachments.
|
|
56
|
+
|
|
3
57
|
## 1.0.1
|
|
4
58
|
|
|
5
59
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk';
|
|
2
2
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { BEDROCK_CAPABILITIES, registerBedrock } from '../index.js';
|
|
3
|
+
import { BEDROCK_CAPABILITIES, BedrockProvider, registerBedrock } from '../index.js';
|
|
4
4
|
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
5
5
|
// via its sideEffects whitelist; we only need to clear 'bedrock' to make
|
|
6
6
|
// re-registration deterministic across tests.
|
|
@@ -38,8 +38,13 @@ describe('@namzu/bedrock', () => {
|
|
|
38
38
|
supportsTools: true,
|
|
39
39
|
supportsStreaming: true,
|
|
40
40
|
supportsFunctionCalling: true,
|
|
41
|
+
supportsVision: false,
|
|
41
42
|
});
|
|
42
43
|
});
|
|
44
|
+
it('is exposed on the provider instance for runtime negotiation', () => {
|
|
45
|
+
const provider = new BedrockProvider({ region: 'us-east-1' });
|
|
46
|
+
expect(provider.capabilities).toEqual(BEDROCK_CAPABILITIES);
|
|
47
|
+
});
|
|
43
48
|
});
|
|
44
49
|
});
|
|
45
50
|
//# sourceMappingURL=bedrock.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock.test.js","sourceRoot":"","sources":["../../src/__tests__/bedrock.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"bedrock.test.js","sourceRoot":"","sources":["../../src/__tests__/bedrock.test.ts"],"names":[],"mappings":"AAAA,OAAO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E,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;YAC9D,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC3D,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;YACvE,eAAe,EAAE,CAAA;YACjB,MAAM,IAAI,GAAG,gBAAgB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;YACxD,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;YACjD,MAAM,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;gBACpC,aAAa,EAAE,IAAI;gBACnB,iBAAiB,EAAE,IAAI;gBACvB,uBAAuB,EAAE,IAAI;gBAC7B,cAAc,EAAE,KAAK;aACrB,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;YACtE,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;YAC7D,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider error taxonomy — Bedrock driver.
|
|
3
|
+
*
|
|
4
|
+
* `chatStream` awaits `this.client.send(command)` with no catch, so an AWS
|
|
5
|
+
* `BedrockRuntimeServiceException` (`ThrottlingException`,
|
|
6
|
+
* `ValidationException`, `ServiceUnavailableException`, …) escapes verbatim.
|
|
7
|
+
* A caller cannot classify it without importing `@aws-sdk/client-bedrock-runtime`.
|
|
8
|
+
*
|
|
9
|
+
* Transport seam: `BedrockConfig` exposes no `requestHandler`/`endpoint`, so
|
|
10
|
+
* unlike the fetch-based drivers there is nothing to inject at the HTTP
|
|
11
|
+
* layer. The tests substitute the `BedrockRuntimeClient`'s `send` and reject
|
|
12
|
+
* with the REAL AWS exception classes — which is exactly what the driver
|
|
13
|
+
* sees from a live call, and the only surface the driver's (currently
|
|
14
|
+
* absent) error mapping would act on.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=error-taxonomy.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-taxonomy.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/error-taxonomy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider error taxonomy — Bedrock driver.
|
|
3
|
+
*
|
|
4
|
+
* `chatStream` awaits `this.client.send(command)` with no catch, so an AWS
|
|
5
|
+
* `BedrockRuntimeServiceException` (`ThrottlingException`,
|
|
6
|
+
* `ValidationException`, `ServiceUnavailableException`, …) escapes verbatim.
|
|
7
|
+
* A caller cannot classify it without importing `@aws-sdk/client-bedrock-runtime`.
|
|
8
|
+
*
|
|
9
|
+
* Transport seam: `BedrockConfig` exposes no `requestHandler`/`endpoint`, so
|
|
10
|
+
* unlike the fetch-based drivers there is nothing to inject at the HTTP
|
|
11
|
+
* layer. The tests substitute the `BedrockRuntimeClient`'s `send` and reject
|
|
12
|
+
* with the REAL AWS exception classes — which is exactly what the driver
|
|
13
|
+
* sees from a live call, and the only surface the driver's (currently
|
|
14
|
+
* absent) error mapping would act on.
|
|
15
|
+
*/
|
|
16
|
+
import { AccessDeniedException, ModelErrorException, ServiceQuotaExceededException, ServiceUnavailableException, ThrottlingException, ValidationException, } from '@aws-sdk/client-bedrock-runtime';
|
|
17
|
+
import { describe, expect, it } from 'vitest';
|
|
18
|
+
import { BedrockProvider } from '../client.js';
|
|
19
|
+
/** Replace the AWS client's `send` so it rejects with `err`. */
|
|
20
|
+
function providerRejectingWith(err) {
|
|
21
|
+
const provider = new BedrockProvider({ region: 'eu-west-1' });
|
|
22
|
+
provider.client = {
|
|
23
|
+
send: () => Promise.reject(err),
|
|
24
|
+
};
|
|
25
|
+
return provider;
|
|
26
|
+
}
|
|
27
|
+
function providerStreaming(...events) {
|
|
28
|
+
const provider = new BedrockProvider({ region: 'eu-west-1' });
|
|
29
|
+
provider.client = {
|
|
30
|
+
send: async () => ({
|
|
31
|
+
$metadata: { requestId: 'bedrock-test' },
|
|
32
|
+
stream: (async function* () {
|
|
33
|
+
yield* events;
|
|
34
|
+
})(),
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
return provider;
|
|
38
|
+
}
|
|
39
|
+
async function captureChatStreamError(provider, signal) {
|
|
40
|
+
try {
|
|
41
|
+
for await (const _chunk of provider.chatStream({
|
|
42
|
+
model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
43
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
44
|
+
signal,
|
|
45
|
+
})) {
|
|
46
|
+
// drain
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
return err;
|
|
51
|
+
}
|
|
52
|
+
throw new Error('expected chatStream to throw');
|
|
53
|
+
}
|
|
54
|
+
describe('@namzu/bedrock — provider error taxonomy', () => {
|
|
55
|
+
it('(a) ThrottlingException with `retry-after: 2` becomes a throttle-classified error carrying retryAfterMs', async () => {
|
|
56
|
+
const aws = new ThrottlingException({
|
|
57
|
+
message: 'Too many requests, please wait before trying again.',
|
|
58
|
+
$metadata: { httpStatusCode: 429 },
|
|
59
|
+
});
|
|
60
|
+
aws.$response = {
|
|
61
|
+
statusCode: 429,
|
|
62
|
+
headers: { 'retry-after': '2' },
|
|
63
|
+
};
|
|
64
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
65
|
+
expect(err).toMatchObject({
|
|
66
|
+
name: 'ProviderRequestError',
|
|
67
|
+
kind: 'throttle',
|
|
68
|
+
status: 429,
|
|
69
|
+
retryAfterMs: 2000,
|
|
70
|
+
providerId: 'bedrock',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it("(c) a ValidationException reporting too many input tokens classifies as 'context_overflow'", async () => {
|
|
74
|
+
const aws = new ValidationException({
|
|
75
|
+
message: 'Input is too long for requested model. The input token count exceeds the maximum for this model.',
|
|
76
|
+
$metadata: { httpStatusCode: 400 },
|
|
77
|
+
});
|
|
78
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
79
|
+
expect(err).toMatchObject({
|
|
80
|
+
name: 'ProviderRequestError',
|
|
81
|
+
kind: 'context_overflow',
|
|
82
|
+
status: 400,
|
|
83
|
+
providerId: 'bedrock',
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it("(c) a ValidationException that is not an overflow classifies as 'bad_request'", async () => {
|
|
87
|
+
const aws = new ValidationException({
|
|
88
|
+
message: 'The value at toolConfig.tools failed to satisfy constraint.',
|
|
89
|
+
$metadata: { httpStatusCode: 400 },
|
|
90
|
+
});
|
|
91
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
92
|
+
expect(err).toMatchObject({
|
|
93
|
+
name: 'ProviderRequestError',
|
|
94
|
+
kind: 'bad_request',
|
|
95
|
+
status: 400,
|
|
96
|
+
providerId: 'bedrock',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it("an AccessDeniedException classifies as 'auth'", async () => {
|
|
100
|
+
const aws = new AccessDeniedException({
|
|
101
|
+
message: 'You do not have access to the model with the specified model ID.',
|
|
102
|
+
$metadata: { httpStatusCode: 403 },
|
|
103
|
+
});
|
|
104
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
105
|
+
expect(err).toMatchObject({
|
|
106
|
+
name: 'ProviderRequestError',
|
|
107
|
+
kind: 'auth',
|
|
108
|
+
status: 403,
|
|
109
|
+
providerId: 'bedrock',
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it("a ServiceUnavailableException classifies as 'server'", async () => {
|
|
113
|
+
const aws = new ServiceUnavailableException({
|
|
114
|
+
message: 'The service is unavailable, try again later.',
|
|
115
|
+
$metadata: { httpStatusCode: 503 },
|
|
116
|
+
});
|
|
117
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
118
|
+
expect(err).toMatchObject({
|
|
119
|
+
name: 'ProviderRequestError',
|
|
120
|
+
kind: 'server',
|
|
121
|
+
status: 503,
|
|
122
|
+
providerId: 'bedrock',
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
it("a ModelErrorException with HTTP 424 still classifies as 'server'", async () => {
|
|
126
|
+
const aws = new ModelErrorException({
|
|
127
|
+
message: 'The model failed while processing the request.',
|
|
128
|
+
originalStatusCode: 500,
|
|
129
|
+
$metadata: { httpStatusCode: 424 },
|
|
130
|
+
});
|
|
131
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
132
|
+
expect(err).toMatchObject({
|
|
133
|
+
name: 'ProviderRequestError',
|
|
134
|
+
kind: 'server',
|
|
135
|
+
status: 424,
|
|
136
|
+
providerId: 'bedrock',
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it("a ServiceQuotaExceededException classifies as 'throttle'", async () => {
|
|
140
|
+
const aws = new ServiceQuotaExceededException({
|
|
141
|
+
message: 'Account inference quota exceeded.',
|
|
142
|
+
$metadata: { httpStatusCode: 400 },
|
|
143
|
+
});
|
|
144
|
+
const err = await captureChatStreamError(providerRejectingWith(aws));
|
|
145
|
+
expect(err).toMatchObject({
|
|
146
|
+
name: 'ProviderRequestError',
|
|
147
|
+
kind: 'throttle',
|
|
148
|
+
status: 400,
|
|
149
|
+
providerId: 'bedrock',
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
it('classifies a throttling exception delivered as a stream union event', async () => {
|
|
153
|
+
const aws = new ThrottlingException({
|
|
154
|
+
message: 'stream quota exceeded',
|
|
155
|
+
$metadata: { httpStatusCode: 429 },
|
|
156
|
+
});
|
|
157
|
+
const err = await captureChatStreamError(providerStreaming({ throttlingException: aws }));
|
|
158
|
+
expect(err).toMatchObject({
|
|
159
|
+
name: 'ProviderRequestError',
|
|
160
|
+
kind: 'throttle',
|
|
161
|
+
status: 429,
|
|
162
|
+
providerId: 'bedrock',
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
it('drops a secret-bearing validation stream event without retaining cause', async () => {
|
|
166
|
+
const secret = 'aws-secret-FAKE-DO-NOT-LOG';
|
|
167
|
+
const aws = new ValidationException({
|
|
168
|
+
message: `invalid request echoed ${secret}`,
|
|
169
|
+
$metadata: { httpStatusCode: 400 },
|
|
170
|
+
});
|
|
171
|
+
const err = await captureChatStreamError(providerStreaming({ validationException: aws }));
|
|
172
|
+
expect(err).toMatchObject({
|
|
173
|
+
name: 'ProviderRequestError',
|
|
174
|
+
kind: 'bad_request',
|
|
175
|
+
providerId: 'bedrock',
|
|
176
|
+
});
|
|
177
|
+
expect(err.message).not.toContain(secret);
|
|
178
|
+
expect('cause' in err).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
it('preserves the caller abort reason when the SDK replaces the error object', async () => {
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
const reason = new Error('user stopped');
|
|
183
|
+
const sdkAbort = Object.assign(new Error('request aborted'), {
|
|
184
|
+
name: 'AbortError',
|
|
185
|
+
});
|
|
186
|
+
controller.abort(reason);
|
|
187
|
+
const err = await captureChatStreamError(providerRejectingWith(sdkAbort), controller.signal);
|
|
188
|
+
expect(sdkAbort).not.toBe(reason);
|
|
189
|
+
expect(err).toBe(reason);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
//# sourceMappingURL=error-taxonomy.test.js.map
|
|
@@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AE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;QACzF,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;QACxC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;QACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE;YAC5D,IAAI,EAAE,YAAY;SAClB,CAAC,CAAA;QACF,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAExB,MAAM,GAAG,GAAG,MAAM,sBAAsB,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;QAE5F,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import type { ChatCompletionParams, LLMProvider, ModelInfo, StreamChunk } from '@namzu/sdk';
|
|
1
|
+
import type { ChatCompletionParams, LLMProvider, ModelInfo, ProviderCapabilities, StreamChunk } from '@namzu/sdk';
|
|
2
2
|
import type { BedrockConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* What this DRIVER does, not what Bedrock could do: tools are mapped
|
|
5
|
+
* to the Converse toolConfig, but user-message image `attachments`
|
|
6
|
+
* are not mapped into image content blocks — `supportsVision` stays
|
|
7
|
+
* false until the message translation handles them.
|
|
8
|
+
*/
|
|
9
|
+
export declare const BEDROCK_CAPABILITIES: ProviderCapabilities;
|
|
3
10
|
export declare class BedrockProvider implements LLMProvider {
|
|
4
11
|
readonly id = "bedrock";
|
|
5
12
|
readonly name = "AWS Bedrock";
|
|
13
|
+
readonly capabilities: ProviderCapabilities;
|
|
6
14
|
private client;
|
|
7
15
|
private config;
|
|
8
16
|
constructor(config: BedrockConfig);
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAGX,MAAM,YAAY,CAAA;AAOnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAqM/C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBAKlC,CAAA;AAED,qBAAa,eAAgB,YAAW,WAAW;IAClD,QAAQ,CAAC,EAAE,aAAY;IACvB,QAAQ,CAAC,IAAI,iBAAgB;IAC7B,QAAQ,CAAC,YAAY,uBAAuB;IAE5C,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,aAAa;IAoB1B,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IAkKrE,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAmClC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAerC"}
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, } from '@aws-sdk/client-bedrock-runtime';
|
|
2
|
+
import { ProviderRequestError, isCallerAbortError, isProviderRequestError, providerVendorError, } from '@namzu/sdk';
|
|
2
3
|
function extractSystemBlocks(messages) {
|
|
3
4
|
return messages
|
|
4
5
|
.filter((m) => m.role === 'system')
|
|
@@ -159,9 +160,22 @@ function mapStopReason(reason) {
|
|
|
159
160
|
return 'stop';
|
|
160
161
|
}
|
|
161
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* What this DRIVER does, not what Bedrock could do: tools are mapped
|
|
165
|
+
* to the Converse toolConfig, but user-message image `attachments`
|
|
166
|
+
* are not mapped into image content blocks — `supportsVision` stays
|
|
167
|
+
* false until the message translation handles them.
|
|
168
|
+
*/
|
|
169
|
+
export const BEDROCK_CAPABILITIES = {
|
|
170
|
+
supportsTools: true,
|
|
171
|
+
supportsStreaming: true,
|
|
172
|
+
supportsFunctionCalling: true,
|
|
173
|
+
supportsVision: false,
|
|
174
|
+
};
|
|
162
175
|
export class BedrockProvider {
|
|
163
176
|
id = 'bedrock';
|
|
164
177
|
name = 'AWS Bedrock';
|
|
178
|
+
capabilities = BEDROCK_CAPABILITIES;
|
|
165
179
|
client;
|
|
166
180
|
config;
|
|
167
181
|
constructor(config) {
|
|
@@ -199,101 +213,142 @@ export class BedrockProvider {
|
|
|
199
213
|
toolConfig,
|
|
200
214
|
inferenceConfig,
|
|
201
215
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
216
|
+
// AWS models failures as distinct exception CLASSES rather than status
|
|
217
|
+
// codes (ThrottlingException, ValidationException, AccessDeniedException),
|
|
218
|
+
// and lets them escape verbatim. Classify from the class name, then drop
|
|
219
|
+
// the AWS error — no re-throw, no `cause`.
|
|
220
|
+
let response;
|
|
221
|
+
try {
|
|
222
|
+
response = await this.client.send(command, {
|
|
223
|
+
requestTimeout: this.config.timeout ?? 120_000,
|
|
224
|
+
// Per-request abort: a Stop tears the in-flight Converse stream down.
|
|
225
|
+
abortSignal: params.signal,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
if (isCallerAbortError(err, params.signal))
|
|
230
|
+
throw params.signal?.reason ?? err;
|
|
231
|
+
if (isProviderRequestError(err))
|
|
232
|
+
throw err;
|
|
233
|
+
throw providerVendorError({ providerId: 'bedrock', error: err });
|
|
234
|
+
}
|
|
207
235
|
if (!response.stream) {
|
|
208
|
-
throw new
|
|
236
|
+
throw new ProviderRequestError({
|
|
237
|
+
kind: 'server',
|
|
238
|
+
providerId: 'bedrock',
|
|
239
|
+
detail: 'the response contained no stream body',
|
|
240
|
+
});
|
|
209
241
|
}
|
|
210
242
|
const requestId = response.$metadata.requestId ?? `bedrock-${Date.now()}`;
|
|
211
243
|
const activeToolCalls = new Map();
|
|
212
244
|
let toolCallIndex = 0;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
245
|
+
try {
|
|
246
|
+
for await (const event of response.stream) {
|
|
247
|
+
// Stop pulling promptly on abort; `for await` calls the stream's
|
|
248
|
+
// `.return()` on this throw, releasing the connection.
|
|
249
|
+
params.signal?.throwIfAborted();
|
|
250
|
+
// Bedrock reports several post-handshake failures as UNION
|
|
251
|
+
// EVENTS, not thrown exceptions. Ignoring these members makes a
|
|
252
|
+
// throttled or failed stream look like a clean EOF.
|
|
253
|
+
const streamFailure = ('internalServerException' in event ? event.internalServerException : undefined) ??
|
|
254
|
+
('modelStreamErrorException' in event ? event.modelStreamErrorException : undefined) ??
|
|
255
|
+
('validationException' in event ? event.validationException : undefined) ??
|
|
256
|
+
('throttlingException' in event ? event.throttlingException : undefined) ??
|
|
257
|
+
('serviceUnavailableException' in event ? event.serviceUnavailableException : undefined);
|
|
258
|
+
if (streamFailure) {
|
|
259
|
+
throw providerVendorError({
|
|
260
|
+
providerId: 'bedrock',
|
|
261
|
+
error: streamFailure,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
if ('contentBlockDelta' in event && event.contentBlockDelta?.delta) {
|
|
266
|
+
const delta = event.contentBlockDelta.delta;
|
|
267
|
+
if ('text' in delta && delta.text) {
|
|
268
|
+
yield {
|
|
269
|
+
id: requestId,
|
|
270
|
+
delta: { content: delta.text },
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if ('toolUse' in delta && delta.toolUse) {
|
|
274
|
+
const idx = event.contentBlockDelta.contentBlockIndex ?? toolCallIndex;
|
|
275
|
+
const active = activeToolCalls.get(idx);
|
|
276
|
+
if (active) {
|
|
277
|
+
active.args += delta.toolUse.input ?? '';
|
|
278
|
+
yield {
|
|
279
|
+
id: requestId,
|
|
280
|
+
delta: {
|
|
281
|
+
toolCalls: [
|
|
282
|
+
{
|
|
283
|
+
index: idx,
|
|
284
|
+
function: { arguments: delta.toolUse.input ?? '' },
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
225
291
|
}
|
|
226
|
-
if ('
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
292
|
+
if ('contentBlockStart' in event && event.contentBlockStart?.start) {
|
|
293
|
+
const start = event.contentBlockStart.start;
|
|
294
|
+
if ('toolUse' in start && start.toolUse) {
|
|
295
|
+
const idx = event.contentBlockStart.contentBlockIndex ?? toolCallIndex;
|
|
296
|
+
activeToolCalls.set(idx, {
|
|
297
|
+
id: start.toolUse.toolUseId ?? `tool-${Date.now()}`,
|
|
298
|
+
name: start.toolUse.name ?? '',
|
|
299
|
+
args: '',
|
|
300
|
+
});
|
|
231
301
|
yield {
|
|
232
302
|
id: requestId,
|
|
233
303
|
delta: {
|
|
234
304
|
toolCalls: [
|
|
235
305
|
{
|
|
236
306
|
index: idx,
|
|
237
|
-
|
|
307
|
+
id: start.toolUse.toolUseId,
|
|
308
|
+
type: 'function',
|
|
309
|
+
function: { name: start.toolUse.name ?? '' },
|
|
238
310
|
},
|
|
239
311
|
],
|
|
240
312
|
},
|
|
241
313
|
};
|
|
314
|
+
toolCallIndex = idx + 1;
|
|
242
315
|
}
|
|
243
316
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if ('toolUse' in start && start.toolUse) {
|
|
248
|
-
const idx = event.contentBlockStart.contentBlockIndex ?? toolCallIndex;
|
|
249
|
-
activeToolCalls.set(idx, {
|
|
250
|
-
id: start.toolUse.toolUseId ?? `tool-${Date.now()}`,
|
|
251
|
-
name: start.toolUse.name ?? '',
|
|
252
|
-
args: '',
|
|
253
|
-
});
|
|
317
|
+
if ('contentBlockStop' in event) {
|
|
318
|
+
}
|
|
319
|
+
if ('messageStop' in event && event.messageStop) {
|
|
254
320
|
yield {
|
|
255
321
|
id: requestId,
|
|
256
|
-
delta: {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
322
|
+
delta: {},
|
|
323
|
+
finishReason: mapStopReason(event.messageStop.stopReason),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
if ('metadata' in event && event.metadata?.usage) {
|
|
327
|
+
const usage = parseUsage(event.metadata.usage);
|
|
328
|
+
yield {
|
|
329
|
+
id: requestId,
|
|
330
|
+
delta: {},
|
|
331
|
+
usage,
|
|
266
332
|
};
|
|
267
|
-
toolCallIndex = idx + 1;
|
|
268
333
|
}
|
|
269
334
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
if ('metadata' in event && event.metadata?.usage) {
|
|
280
|
-
const usage = parseUsage(event.metadata.usage);
|
|
281
|
-
yield {
|
|
282
|
-
id: requestId,
|
|
283
|
-
delta: {},
|
|
284
|
-
usage,
|
|
285
|
-
};
|
|
335
|
+
catch (parseErr) {
|
|
336
|
+
if (isProviderRequestError(parseErr))
|
|
337
|
+
throw parseErr;
|
|
338
|
+
throw new ProviderRequestError({
|
|
339
|
+
kind: 'server',
|
|
340
|
+
providerId: 'bedrock',
|
|
341
|
+
detail: 'the provider stream returned malformed data',
|
|
342
|
+
});
|
|
286
343
|
}
|
|
287
344
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
}
|
|
345
|
+
}
|
|
346
|
+
catch (err) {
|
|
347
|
+
if (isCallerAbortError(err, params.signal))
|
|
348
|
+
throw params.signal?.reason ?? err;
|
|
349
|
+
if (isProviderRequestError(err))
|
|
350
|
+
throw err;
|
|
351
|
+
throw providerVendorError({ providerId: 'bedrock', error: err });
|
|
297
352
|
}
|
|
298
353
|
}
|
|
299
354
|
async listModels() {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACrB,MAAM,iCAAiC,CAAA;AAsBxC,SAAS,mBAAmB,CAAC,QAA0C;IACtE,OAAO,QAAQ;SACb,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;SAClC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACzE,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAA;AACnD,CAAC;AAED,SAAS,iBAAiB,CAAC,QAA0C;IACpE,MAAM,GAAG,GAAqB,EAAE,CAAA;IAEhC,IAAI,kBAAkB,GAAmB,EAAE,CAAA;IAE3C,MAAM,gBAAgB,GAAG,GAAG,EAAE;QAC7B,IAAI,kBAAkB,CAAC,MAAM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b,CAAC;IACF,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RegisterOptions } from '@namzu/sdk';
|
|
2
2
|
import type { BedrockProviderConfig } from './types.js';
|
|
3
3
|
declare module '@namzu/sdk' {
|
|
4
4
|
interface ProviderConfigRegistry {
|
|
5
5
|
bedrock: BedrockProviderConfig;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
export declare const BEDROCK_CAPABILITIES: ProviderCapabilities;
|
|
9
8
|
/**
|
|
10
9
|
* Register `BedrockProvider` under the `'bedrock'` type in `@namzu/sdk`'s
|
|
11
10
|
* `ProviderRegistry`. Call once at app startup before
|
|
@@ -15,6 +14,6 @@ export declare const BEDROCK_CAPABILITIES: ProviderCapabilities;
|
|
|
15
14
|
* Pass `{ replace: true }` to override.
|
|
16
15
|
*/
|
|
17
16
|
export declare function registerBedrock(options?: RegisterOptions): void;
|
|
18
|
-
export { BedrockProvider } from './client.js';
|
|
17
|
+
export { BEDROCK_CAPABILITIES, BedrockProvider } from './client.js';
|
|
19
18
|
export type { BedrockConfig, BedrockProviderConfig } from './types.js';
|
|
20
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAEnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAIvD,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAU,sBAAsB;QAC/B,OAAO,EAAE,qBAAqB,CAAA;KAC9B;CACD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAE/D;AAED,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACnE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { ProviderRegistry } from '@namzu/sdk';
|
|
2
|
-
import { BedrockProvider } from './client.js';
|
|
3
|
-
export const BEDROCK_CAPABILITIES = {
|
|
4
|
-
supportsTools: true,
|
|
5
|
-
supportsStreaming: true,
|
|
6
|
-
supportsFunctionCalling: true,
|
|
7
|
-
};
|
|
2
|
+
import { BEDROCK_CAPABILITIES, BedrockProvider } from './client.js';
|
|
8
3
|
/**
|
|
9
4
|
* Register `BedrockProvider` under the `'bedrock'` type in `@namzu/sdk`'s
|
|
10
5
|
* `ProviderRegistry`. Call once at app startup before
|
|
@@ -16,5 +11,5 @@ export const BEDROCK_CAPABILITIES = {
|
|
|
16
11
|
export function registerBedrock(options) {
|
|
17
12
|
ProviderRegistry.register('bedrock', BedrockProvider, BEDROCK_CAPABILITIES, options);
|
|
18
13
|
}
|
|
19
|
-
export { BedrockProvider } from './client.js';
|
|
14
|
+
export { BEDROCK_CAPABILITIES, BedrockProvider } from './client.js';
|
|
20
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAWnE;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,OAAyB;IACxD,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;AACrF,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/bedrock",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "AWS Bedrock LLM provider for @namzu/sdk. Provides Converse API (chat + streaming) with full tool-use support.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"@aws-sdk/client-bedrock-runtime": "^3.700.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@namzu/sdk": ">=1.
|
|
40
|
+
"@namzu/sdk": ">=1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "^1.9.4",
|
|
44
44
|
"@types/node": "^22.19.17",
|
|
45
45
|
"typescript": "^5.5.0",
|
|
46
46
|
"vitest": "^2.0.0",
|
|
47
|
-
"@namzu/sdk": "^1.
|
|
47
|
+
"@namzu/sdk": "^1.4.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc --build",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk'
|
|
2
2
|
import { beforeEach, describe, expect, it } from 'vitest'
|
|
3
|
-
import { BEDROCK_CAPABILITIES, registerBedrock } from '../index.js'
|
|
3
|
+
import { BEDROCK_CAPABILITIES, BedrockProvider, registerBedrock } from '../index.js'
|
|
4
4
|
|
|
5
5
|
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
6
6
|
// via its sideEffects whitelist; we only need to clear 'bedrock' to make
|
|
@@ -44,7 +44,13 @@ describe('@namzu/bedrock', () => {
|
|
|
44
44
|
supportsTools: true,
|
|
45
45
|
supportsStreaming: true,
|
|
46
46
|
supportsFunctionCalling: true,
|
|
47
|
+
supportsVision: false,
|
|
47
48
|
})
|
|
48
49
|
})
|
|
50
|
+
|
|
51
|
+
it('is exposed on the provider instance for runtime negotiation', () => {
|
|
52
|
+
const provider = new BedrockProvider({ region: 'us-east-1' })
|
|
53
|
+
expect(provider.capabilities).toEqual(BEDROCK_CAPABILITIES)
|
|
54
|
+
})
|
|
49
55
|
})
|
|
50
56
|
})
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider error taxonomy — Bedrock driver.
|
|
3
|
+
*
|
|
4
|
+
* `chatStream` awaits `this.client.send(command)` with no catch, so an AWS
|
|
5
|
+
* `BedrockRuntimeServiceException` (`ThrottlingException`,
|
|
6
|
+
* `ValidationException`, `ServiceUnavailableException`, …) escapes verbatim.
|
|
7
|
+
* A caller cannot classify it without importing `@aws-sdk/client-bedrock-runtime`.
|
|
8
|
+
*
|
|
9
|
+
* Transport seam: `BedrockConfig` exposes no `requestHandler`/`endpoint`, so
|
|
10
|
+
* unlike the fetch-based drivers there is nothing to inject at the HTTP
|
|
11
|
+
* layer. The tests substitute the `BedrockRuntimeClient`'s `send` and reject
|
|
12
|
+
* with the REAL AWS exception classes — which is exactly what the driver
|
|
13
|
+
* sees from a live call, and the only surface the driver's (currently
|
|
14
|
+
* absent) error mapping would act on.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
AccessDeniedException,
|
|
19
|
+
ModelErrorException,
|
|
20
|
+
ServiceQuotaExceededException,
|
|
21
|
+
ServiceUnavailableException,
|
|
22
|
+
ThrottlingException,
|
|
23
|
+
ValidationException,
|
|
24
|
+
} from '@aws-sdk/client-bedrock-runtime'
|
|
25
|
+
import type { ConverseStreamOutput } from '@aws-sdk/client-bedrock-runtime'
|
|
26
|
+
import { describe, expect, it } from 'vitest'
|
|
27
|
+
import { BedrockProvider } from '../client.js'
|
|
28
|
+
|
|
29
|
+
/** Replace the AWS client's `send` so it rejects with `err`. */
|
|
30
|
+
function providerRejectingWith(err: unknown): BedrockProvider {
|
|
31
|
+
const provider = new BedrockProvider({ region: 'eu-west-1' })
|
|
32
|
+
;(provider as unknown as { client: { send: () => Promise<never> } }).client = {
|
|
33
|
+
send: () => Promise.reject(err),
|
|
34
|
+
}
|
|
35
|
+
return provider
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function providerStreaming(...events: ConverseStreamOutput[]): BedrockProvider {
|
|
39
|
+
const provider = new BedrockProvider({ region: 'eu-west-1' })
|
|
40
|
+
;(provider as unknown as { client: { send: () => Promise<unknown> } }).client = {
|
|
41
|
+
send: async () => ({
|
|
42
|
+
$metadata: { requestId: 'bedrock-test' },
|
|
43
|
+
stream: (async function* () {
|
|
44
|
+
yield* events
|
|
45
|
+
})(),
|
|
46
|
+
}),
|
|
47
|
+
}
|
|
48
|
+
return provider
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function captureChatStreamError(
|
|
52
|
+
provider: BedrockProvider,
|
|
53
|
+
signal?: AbortSignal,
|
|
54
|
+
): Promise<unknown> {
|
|
55
|
+
try {
|
|
56
|
+
for await (const _chunk of provider.chatStream({
|
|
57
|
+
model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
58
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
59
|
+
signal,
|
|
60
|
+
})) {
|
|
61
|
+
// drain
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
return err
|
|
65
|
+
}
|
|
66
|
+
throw new Error('expected chatStream to throw')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('@namzu/bedrock — provider error taxonomy', () => {
|
|
70
|
+
it('(a) ThrottlingException with `retry-after: 2` becomes a throttle-classified error carrying retryAfterMs', async () => {
|
|
71
|
+
const aws = new ThrottlingException({
|
|
72
|
+
message: 'Too many requests, please wait before trying again.',
|
|
73
|
+
$metadata: { httpStatusCode: 429 },
|
|
74
|
+
})
|
|
75
|
+
;(aws as unknown as { $response: unknown }).$response = {
|
|
76
|
+
statusCode: 429,
|
|
77
|
+
headers: { 'retry-after': '2' },
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
81
|
+
|
|
82
|
+
expect(err).toMatchObject({
|
|
83
|
+
name: 'ProviderRequestError',
|
|
84
|
+
kind: 'throttle',
|
|
85
|
+
status: 429,
|
|
86
|
+
retryAfterMs: 2000,
|
|
87
|
+
providerId: 'bedrock',
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("(c) a ValidationException reporting too many input tokens classifies as 'context_overflow'", async () => {
|
|
92
|
+
const aws = new ValidationException({
|
|
93
|
+
message:
|
|
94
|
+
'Input is too long for requested model. The input token count exceeds the maximum for this model.',
|
|
95
|
+
$metadata: { httpStatusCode: 400 },
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
99
|
+
|
|
100
|
+
expect(err).toMatchObject({
|
|
101
|
+
name: 'ProviderRequestError',
|
|
102
|
+
kind: 'context_overflow',
|
|
103
|
+
status: 400,
|
|
104
|
+
providerId: 'bedrock',
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("(c) a ValidationException that is not an overflow classifies as 'bad_request'", async () => {
|
|
109
|
+
const aws = new ValidationException({
|
|
110
|
+
message: 'The value at toolConfig.tools failed to satisfy constraint.',
|
|
111
|
+
$metadata: { httpStatusCode: 400 },
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
115
|
+
|
|
116
|
+
expect(err).toMatchObject({
|
|
117
|
+
name: 'ProviderRequestError',
|
|
118
|
+
kind: 'bad_request',
|
|
119
|
+
status: 400,
|
|
120
|
+
providerId: 'bedrock',
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it("an AccessDeniedException classifies as 'auth'", async () => {
|
|
125
|
+
const aws = new AccessDeniedException({
|
|
126
|
+
message: 'You do not have access to the model with the specified model ID.',
|
|
127
|
+
$metadata: { httpStatusCode: 403 },
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
131
|
+
|
|
132
|
+
expect(err).toMatchObject({
|
|
133
|
+
name: 'ProviderRequestError',
|
|
134
|
+
kind: 'auth',
|
|
135
|
+
status: 403,
|
|
136
|
+
providerId: 'bedrock',
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it("a ServiceUnavailableException classifies as 'server'", async () => {
|
|
141
|
+
const aws = new ServiceUnavailableException({
|
|
142
|
+
message: 'The service is unavailable, try again later.',
|
|
143
|
+
$metadata: { httpStatusCode: 503 },
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
147
|
+
|
|
148
|
+
expect(err).toMatchObject({
|
|
149
|
+
name: 'ProviderRequestError',
|
|
150
|
+
kind: 'server',
|
|
151
|
+
status: 503,
|
|
152
|
+
providerId: 'bedrock',
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it("a ModelErrorException with HTTP 424 still classifies as 'server'", async () => {
|
|
157
|
+
const aws = new ModelErrorException({
|
|
158
|
+
message: 'The model failed while processing the request.',
|
|
159
|
+
originalStatusCode: 500,
|
|
160
|
+
$metadata: { httpStatusCode: 424 },
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
164
|
+
|
|
165
|
+
expect(err).toMatchObject({
|
|
166
|
+
name: 'ProviderRequestError',
|
|
167
|
+
kind: 'server',
|
|
168
|
+
status: 424,
|
|
169
|
+
providerId: 'bedrock',
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it("a ServiceQuotaExceededException classifies as 'throttle'", async () => {
|
|
174
|
+
const aws = new ServiceQuotaExceededException({
|
|
175
|
+
message: 'Account inference quota exceeded.',
|
|
176
|
+
$metadata: { httpStatusCode: 400 },
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
const err = await captureChatStreamError(providerRejectingWith(aws))
|
|
180
|
+
|
|
181
|
+
expect(err).toMatchObject({
|
|
182
|
+
name: 'ProviderRequestError',
|
|
183
|
+
kind: 'throttle',
|
|
184
|
+
status: 400,
|
|
185
|
+
providerId: 'bedrock',
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('classifies a throttling exception delivered as a stream union event', async () => {
|
|
190
|
+
const aws = new ThrottlingException({
|
|
191
|
+
message: 'stream quota exceeded',
|
|
192
|
+
$metadata: { httpStatusCode: 429 },
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const err = await captureChatStreamError(providerStreaming({ throttlingException: aws }))
|
|
196
|
+
|
|
197
|
+
expect(err).toMatchObject({
|
|
198
|
+
name: 'ProviderRequestError',
|
|
199
|
+
kind: 'throttle',
|
|
200
|
+
status: 429,
|
|
201
|
+
providerId: 'bedrock',
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('drops a secret-bearing validation stream event without retaining cause', async () => {
|
|
206
|
+
const secret = 'aws-secret-FAKE-DO-NOT-LOG'
|
|
207
|
+
const aws = new ValidationException({
|
|
208
|
+
message: `invalid request echoed ${secret}`,
|
|
209
|
+
$metadata: { httpStatusCode: 400 },
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
const err = await captureChatStreamError(providerStreaming({ validationException: aws }))
|
|
213
|
+
|
|
214
|
+
expect(err).toMatchObject({
|
|
215
|
+
name: 'ProviderRequestError',
|
|
216
|
+
kind: 'bad_request',
|
|
217
|
+
providerId: 'bedrock',
|
|
218
|
+
})
|
|
219
|
+
expect((err as Error).message).not.toContain(secret)
|
|
220
|
+
expect('cause' in (err as object)).toBe(false)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('preserves the caller abort reason when the SDK replaces the error object', async () => {
|
|
224
|
+
const controller = new AbortController()
|
|
225
|
+
const reason = new Error('user stopped')
|
|
226
|
+
const sdkAbort = Object.assign(new Error('request aborted'), {
|
|
227
|
+
name: 'AbortError',
|
|
228
|
+
})
|
|
229
|
+
controller.abort(reason)
|
|
230
|
+
|
|
231
|
+
const err = await captureChatStreamError(providerRejectingWith(sdkAbort), controller.signal)
|
|
232
|
+
|
|
233
|
+
expect(sdkAbort).not.toBe(reason)
|
|
234
|
+
expect(err).toBe(reason)
|
|
235
|
+
})
|
|
236
|
+
})
|
package/src/client.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
Message as BedrockMessage,
|
|
8
8
|
ContentBlock,
|
|
9
9
|
ConversationRole,
|
|
10
|
+
ConverseStreamCommandOutput,
|
|
10
11
|
ConverseStreamOutput,
|
|
11
12
|
SystemContentBlock,
|
|
12
13
|
Tool,
|
|
@@ -18,10 +19,17 @@ import type {
|
|
|
18
19
|
ChatCompletionResponse,
|
|
19
20
|
LLMProvider,
|
|
20
21
|
ModelInfo,
|
|
22
|
+
ProviderCapabilities,
|
|
21
23
|
StreamChunk,
|
|
22
24
|
TokenUsage,
|
|
23
25
|
ToolChoice,
|
|
24
26
|
} from '@namzu/sdk'
|
|
27
|
+
import {
|
|
28
|
+
ProviderRequestError,
|
|
29
|
+
isCallerAbortError,
|
|
30
|
+
isProviderRequestError,
|
|
31
|
+
providerVendorError,
|
|
32
|
+
} from '@namzu/sdk'
|
|
25
33
|
import type { BedrockConfig } from './types.js'
|
|
26
34
|
|
|
27
35
|
function extractSystemBlocks(messages: ChatCompletionParams['messages']): SystemContentBlock[] {
|
|
@@ -219,9 +227,23 @@ function mapStopReason(reason?: string): NamzuFinishReason {
|
|
|
219
227
|
}
|
|
220
228
|
}
|
|
221
229
|
|
|
230
|
+
/**
|
|
231
|
+
* What this DRIVER does, not what Bedrock could do: tools are mapped
|
|
232
|
+
* to the Converse toolConfig, but user-message image `attachments`
|
|
233
|
+
* are not mapped into image content blocks — `supportsVision` stays
|
|
234
|
+
* false until the message translation handles them.
|
|
235
|
+
*/
|
|
236
|
+
export const BEDROCK_CAPABILITIES: ProviderCapabilities = {
|
|
237
|
+
supportsTools: true,
|
|
238
|
+
supportsStreaming: true,
|
|
239
|
+
supportsFunctionCalling: true,
|
|
240
|
+
supportsVision: false,
|
|
241
|
+
}
|
|
242
|
+
|
|
222
243
|
export class BedrockProvider implements LLMProvider {
|
|
223
244
|
readonly id = 'bedrock'
|
|
224
245
|
readonly name = 'AWS Bedrock'
|
|
246
|
+
readonly capabilities = BEDROCK_CAPABILITIES
|
|
225
247
|
|
|
226
248
|
private client: BedrockRuntimeClient
|
|
227
249
|
private config: BedrockConfig
|
|
@@ -265,14 +287,29 @@ export class BedrockProvider implements LLMProvider {
|
|
|
265
287
|
inferenceConfig,
|
|
266
288
|
})
|
|
267
289
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
290
|
+
// AWS models failures as distinct exception CLASSES rather than status
|
|
291
|
+
// codes (ThrottlingException, ValidationException, AccessDeniedException),
|
|
292
|
+
// and lets them escape verbatim. Classify from the class name, then drop
|
|
293
|
+
// the AWS error — no re-throw, no `cause`.
|
|
294
|
+
let response: ConverseStreamCommandOutput
|
|
295
|
+
try {
|
|
296
|
+
response = await this.client.send(command, {
|
|
297
|
+
requestTimeout: this.config.timeout ?? 120_000,
|
|
298
|
+
// Per-request abort: a Stop tears the in-flight Converse stream down.
|
|
299
|
+
abortSignal: params.signal,
|
|
300
|
+
})
|
|
301
|
+
} catch (err) {
|
|
302
|
+
if (isCallerAbortError(err, params.signal)) throw params.signal?.reason ?? err
|
|
303
|
+
if (isProviderRequestError(err)) throw err
|
|
304
|
+
throw providerVendorError({ providerId: 'bedrock', error: err })
|
|
305
|
+
}
|
|
273
306
|
|
|
274
307
|
if (!response.stream) {
|
|
275
|
-
throw new
|
|
308
|
+
throw new ProviderRequestError({
|
|
309
|
+
kind: 'server',
|
|
310
|
+
providerId: 'bedrock',
|
|
311
|
+
detail: 'the response contained no stream body',
|
|
312
|
+
})
|
|
276
313
|
}
|
|
277
314
|
|
|
278
315
|
const requestId = response.$metadata.requestId ?? `bedrock-${Date.now()}`
|
|
@@ -280,94 +317,116 @@ export class BedrockProvider implements LLMProvider {
|
|
|
280
317
|
const activeToolCalls = new Map<number, { id: string; name: string; args: string }>()
|
|
281
318
|
let toolCallIndex = 0
|
|
282
319
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
320
|
+
try {
|
|
321
|
+
for await (const event of response.stream as AsyncIterable<ConverseStreamOutput>) {
|
|
322
|
+
// Stop pulling promptly on abort; `for await` calls the stream's
|
|
323
|
+
// `.return()` on this throw, releasing the connection.
|
|
324
|
+
params.signal?.throwIfAborted()
|
|
325
|
+
|
|
326
|
+
// Bedrock reports several post-handshake failures as UNION
|
|
327
|
+
// EVENTS, not thrown exceptions. Ignoring these members makes a
|
|
328
|
+
// throttled or failed stream look like a clean EOF.
|
|
329
|
+
const streamFailure =
|
|
330
|
+
('internalServerException' in event ? event.internalServerException : undefined) ??
|
|
331
|
+
('modelStreamErrorException' in event ? event.modelStreamErrorException : undefined) ??
|
|
332
|
+
('validationException' in event ? event.validationException : undefined) ??
|
|
333
|
+
('throttlingException' in event ? event.throttlingException : undefined) ??
|
|
334
|
+
('serviceUnavailableException' in event ? event.serviceUnavailableException : undefined)
|
|
335
|
+
if (streamFailure) {
|
|
336
|
+
throw providerVendorError({
|
|
337
|
+
providerId: 'bedrock',
|
|
338
|
+
error: streamFailure,
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
if ('contentBlockDelta' in event && event.contentBlockDelta?.delta) {
|
|
344
|
+
const delta = event.contentBlockDelta.delta
|
|
345
|
+
if ('text' in delta && delta.text) {
|
|
346
|
+
yield {
|
|
347
|
+
id: requestId,
|
|
348
|
+
delta: { content: delta.text },
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if ('toolUse' in delta && delta.toolUse) {
|
|
353
|
+
const idx = event.contentBlockDelta.contentBlockIndex ?? toolCallIndex
|
|
354
|
+
const active = activeToolCalls.get(idx)
|
|
355
|
+
if (active) {
|
|
356
|
+
active.args += delta.toolUse.input ?? ''
|
|
357
|
+
yield {
|
|
358
|
+
id: requestId,
|
|
359
|
+
delta: {
|
|
360
|
+
toolCalls: [
|
|
361
|
+
{
|
|
362
|
+
index: idx,
|
|
363
|
+
function: { arguments: delta.toolUse.input ?? '' },
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
}
|
|
294
369
|
}
|
|
295
370
|
}
|
|
296
371
|
|
|
297
|
-
if ('
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
372
|
+
if ('contentBlockStart' in event && event.contentBlockStart?.start) {
|
|
373
|
+
const start = event.contentBlockStart.start
|
|
374
|
+
if ('toolUse' in start && start.toolUse) {
|
|
375
|
+
const idx = event.contentBlockStart.contentBlockIndex ?? toolCallIndex
|
|
376
|
+
activeToolCalls.set(idx, {
|
|
377
|
+
id: start.toolUse.toolUseId ?? `tool-${Date.now()}`,
|
|
378
|
+
name: start.toolUse.name ?? '',
|
|
379
|
+
args: '',
|
|
380
|
+
})
|
|
302
381
|
yield {
|
|
303
382
|
id: requestId,
|
|
304
383
|
delta: {
|
|
305
384
|
toolCalls: [
|
|
306
385
|
{
|
|
307
386
|
index: idx,
|
|
308
|
-
|
|
387
|
+
id: start.toolUse.toolUseId,
|
|
388
|
+
type: 'function',
|
|
389
|
+
function: { name: start.toolUse.name ?? '' },
|
|
309
390
|
},
|
|
310
391
|
],
|
|
311
392
|
},
|
|
312
393
|
}
|
|
394
|
+
toolCallIndex = idx + 1
|
|
313
395
|
}
|
|
314
396
|
}
|
|
315
|
-
}
|
|
316
397
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
activeToolCalls.set(idx, {
|
|
322
|
-
id: start.toolUse.toolUseId ?? `tool-${Date.now()}`,
|
|
323
|
-
name: start.toolUse.name ?? '',
|
|
324
|
-
args: '',
|
|
325
|
-
})
|
|
398
|
+
if ('contentBlockStop' in event) {
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if ('messageStop' in event && event.messageStop) {
|
|
326
402
|
yield {
|
|
327
403
|
id: requestId,
|
|
328
|
-
delta: {
|
|
329
|
-
|
|
330
|
-
{
|
|
331
|
-
index: idx,
|
|
332
|
-
id: start.toolUse.toolUseId,
|
|
333
|
-
type: 'function',
|
|
334
|
-
function: { name: start.toolUse.name ?? '' },
|
|
335
|
-
},
|
|
336
|
-
],
|
|
337
|
-
},
|
|
404
|
+
delta: {},
|
|
405
|
+
finishReason: mapStopReason(event.messageStop.stopReason),
|
|
338
406
|
}
|
|
339
|
-
toolCallIndex = idx + 1
|
|
340
407
|
}
|
|
341
|
-
}
|
|
342
408
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
finishReason: mapStopReason(event.messageStop.stopReason),
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if ('metadata' in event && event.metadata?.usage) {
|
|
355
|
-
const usage = parseUsage(event.metadata.usage as RawBedrockUsage)
|
|
356
|
-
yield {
|
|
357
|
-
id: requestId,
|
|
358
|
-
delta: {},
|
|
359
|
-
usage,
|
|
409
|
+
if ('metadata' in event && event.metadata?.usage) {
|
|
410
|
+
const usage = parseUsage(event.metadata.usage as RawBedrockUsage)
|
|
411
|
+
yield {
|
|
412
|
+
id: requestId,
|
|
413
|
+
delta: {},
|
|
414
|
+
usage,
|
|
415
|
+
}
|
|
360
416
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
error: `Stream parse error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
417
|
+
} catch (parseErr) {
|
|
418
|
+
if (isProviderRequestError(parseErr)) throw parseErr
|
|
419
|
+
throw new ProviderRequestError({
|
|
420
|
+
kind: 'server',
|
|
421
|
+
providerId: 'bedrock',
|
|
422
|
+
detail: 'the provider stream returned malformed data',
|
|
423
|
+
})
|
|
369
424
|
}
|
|
370
425
|
}
|
|
426
|
+
} catch (err) {
|
|
427
|
+
if (isCallerAbortError(err, params.signal)) throw params.signal?.reason ?? err
|
|
428
|
+
if (isProviderRequestError(err)) throw err
|
|
429
|
+
throw providerVendorError({ providerId: 'bedrock', error: err })
|
|
371
430
|
}
|
|
372
431
|
}
|
|
373
432
|
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BedrockProvider } from './client.js'
|
|
1
|
+
import { ProviderRegistry, type RegisterOptions } from '@namzu/sdk'
|
|
2
|
+
import { BEDROCK_CAPABILITIES, BedrockProvider } from './client.js'
|
|
3
3
|
import type { BedrockProviderConfig } from './types.js'
|
|
4
4
|
|
|
5
5
|
// Module augmentation: register bedrock's config type in the sdk's registry interface.
|
|
@@ -10,12 +10,6 @@ declare module '@namzu/sdk' {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const BEDROCK_CAPABILITIES: ProviderCapabilities = {
|
|
14
|
-
supportsTools: true,
|
|
15
|
-
supportsStreaming: true,
|
|
16
|
-
supportsFunctionCalling: true,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
/**
|
|
20
14
|
* Register `BedrockProvider` under the `'bedrock'` type in `@namzu/sdk`'s
|
|
21
15
|
* `ProviderRegistry`. Call once at app startup before
|
|
@@ -28,5 +22,5 @@ export function registerBedrock(options?: RegisterOptions): void {
|
|
|
28
22
|
ProviderRegistry.register('bedrock', BedrockProvider, BEDROCK_CAPABILITIES, options)
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
export { BedrockProvider } from './client.js'
|
|
25
|
+
export { BEDROCK_CAPABILITIES, BedrockProvider } from './client.js'
|
|
32
26
|
export type { BedrockConfig, BedrockProviderConfig } from './types.js'
|