@namzu/bedrock 3.1.0 → 4.0.1
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 +79 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -3
- package/dist/client.js.map +1 -1
- package/dist/model-reachability.d.ts +12 -0
- package/dist/model-reachability.d.ts.map +1 -1
- package/dist/model-reachability.js +14 -0
- package/dist/model-reachability.js.map +1 -1
- package/package.json +13 -3
- package/src/client.ts +14 -4
- package/src/model-reachability.ts +15 -0
- package/dist/__tests__/bedrock.test.d.ts +0 -2
- package/dist/__tests__/bedrock.test.d.ts.map +0 -1
- package/dist/__tests__/bedrock.test.js +0 -94
- package/dist/__tests__/bedrock.test.js.map +0 -1
- package/dist/__tests__/error-taxonomy.test.d.ts +0 -17
- package/dist/__tests__/error-taxonomy.test.d.ts.map +0 -1
- package/dist/__tests__/error-taxonomy.test.js +0 -192
- package/dist/__tests__/error-taxonomy.test.js.map +0 -1
- package/dist/__tests__/model-reachability.test.d.ts +0 -2
- package/dist/__tests__/model-reachability.test.d.ts.map +0 -1
- package/dist/__tests__/model-reachability.test.js +0 -64
- package/dist/__tests__/model-reachability.test.js.map +0 -1
- package/dist/__tests__/prompt-cache.test.d.ts +0 -2
- package/dist/__tests__/prompt-cache.test.d.ts.map +0 -1
- package/dist/__tests__/prompt-cache.test.js +0 -68
- package/dist/__tests__/prompt-cache.test.js.map +0 -1
- package/dist/__tests__/thinking-refused.test.d.ts +0 -2
- package/dist/__tests__/thinking-refused.test.d.ts.map +0 -1
- package/dist/__tests__/thinking-refused.test.js +0 -35
- package/dist/__tests__/thinking-refused.test.js.map +0 -1
- package/dist/__tests__/tool-choice-none.test.d.ts +0 -2
- package/dist/__tests__/tool-choice-none.test.d.ts.map +0 -1
- package/dist/__tests__/tool-choice-none.test.js +0 -76
- package/dist/__tests__/tool-choice-none.test.js.map +0 -1
- package/dist/__tests__/tool-content-blocks.test.d.ts +0 -2
- package/dist/__tests__/tool-content-blocks.test.d.ts.map +0 -1
- package/dist/__tests__/tool-content-blocks.test.js +0 -92
- package/dist/__tests__/tool-content-blocks.test.js.map +0 -1
- package/dist/__tests__/vision.test.d.ts +0 -2
- package/dist/__tests__/vision.test.d.ts.map +0 -1
- package/dist/__tests__/vision.test.js +0 -77
- package/dist/__tests__/vision.test.js.map +0 -1
- package/src/__tests__/bedrock.test.ts +0 -103
- package/src/__tests__/error-taxonomy.test.ts +0 -236
- package/src/__tests__/model-reachability.test.ts +0 -74
- package/src/__tests__/prompt-cache.test.ts +0 -81
- package/src/__tests__/thinking-refused.test.ts +0 -44
- package/src/__tests__/tool-choice-none.test.ts +0 -87
- package/src/__tests__/tool-content-blocks.test.ts +0 -119
- package/src/__tests__/vision.test.ts +0 -98
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { BEDROCK_CAPABILITIES, toBedrockMessages } from '../client.js';
|
|
3
|
-
/**
|
|
4
|
-
* This driver does not map image attachments, and says so.
|
|
5
|
-
*
|
|
6
|
-
* That is a legitimate state — a driver may ship without a wire shape —
|
|
7
|
-
* but only while the claim and the code agree. The failure this pins is
|
|
8
|
-
* drift in either direction: flipping the flag without writing the mapping
|
|
9
|
-
* makes the runtime stop warning about images that still vanish, and
|
|
10
|
-
* writing the mapping without flipping the flag makes it keep warning
|
|
11
|
-
* about images that now arrive.
|
|
12
|
-
*
|
|
13
|
-
* The runtime reads the flag and warns (or fails under `strictCapabilities`)
|
|
14
|
-
* before the request is built, so the flag is the contract.
|
|
15
|
-
*/
|
|
16
|
-
const PNG = 'iVBORw0KGgo=';
|
|
17
|
-
function contentFor(attachments) {
|
|
18
|
-
const messages = toBedrockMessages([
|
|
19
|
-
{ role: 'user', content: 'what is this', attachments },
|
|
20
|
-
]);
|
|
21
|
-
return messages[0]?.content;
|
|
22
|
-
}
|
|
23
|
-
describe('the capability claim and the mapper agree', () => {
|
|
24
|
-
it('declares that images are not mapped', () => {
|
|
25
|
-
expect(BEDROCK_CAPABILITIES.supportsVision).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
it('declares that documents are not mapped', () => {
|
|
28
|
-
expect(BEDROCK_CAPABILITIES.supportsDocuments).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
it('sends no image block, matching the claim', () => {
|
|
31
|
-
const content = contentFor([{ type: 'image', data: PNG, mediaType: 'image/png' }]);
|
|
32
|
-
const blocks = content;
|
|
33
|
-
expect(blocks.some((b) => 'image' in b)).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
it('does not smuggle the payload into the text either', () => {
|
|
36
|
-
const content = contentFor([{ type: 'image', data: 'A'.repeat(2048), mediaType: 'image/png' }]);
|
|
37
|
-
// Dropping is the declared behaviour. Stringifying it into the
|
|
38
|
-
// prompt would be worse than dropping: unreadable, and billed.
|
|
39
|
-
expect(JSON.stringify(content)).not.toContain('A'.repeat(64));
|
|
40
|
-
});
|
|
41
|
-
it('still sends the message text', () => {
|
|
42
|
-
const content = contentFor([{ type: 'image', data: PNG, mediaType: 'image/png' }]);
|
|
43
|
-
const blocks = content;
|
|
44
|
-
expect(blocks.some((b) => b.text === 'what is this')).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
it('leaves a plain message untouched', () => {
|
|
47
|
-
const messages = toBedrockMessages([
|
|
48
|
-
{ role: 'user', content: 'no attachments' },
|
|
49
|
-
]);
|
|
50
|
-
expect(messages[0]?.content).toEqual([{ text: 'no attachments' }]);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('what the driver does map is unaffected', () => {
|
|
54
|
-
it('maps tool calls, which is what this driver is for', () => {
|
|
55
|
-
const messages = toBedrockMessages([
|
|
56
|
-
{ role: 'user', content: 'read it' },
|
|
57
|
-
{
|
|
58
|
-
role: 'assistant',
|
|
59
|
-
content: null,
|
|
60
|
-
toolCalls: [
|
|
61
|
-
{ id: 'call_1', type: 'function', function: { name: 'read', arguments: '{"p":1}' } },
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
]);
|
|
65
|
-
const toolUse = (messages[1]?.content ?? []).find((b) => b.toolUse);
|
|
66
|
-
expect(toolUse.toolUse.name).toBe('read');
|
|
67
|
-
expect(toolUse.toolUse.input).toEqual({ p: 1 });
|
|
68
|
-
});
|
|
69
|
-
it('drops system messages from the turn list', () => {
|
|
70
|
-
const messages = toBedrockMessages([
|
|
71
|
-
{ role: 'system', content: 'be terse' },
|
|
72
|
-
{ role: 'user', content: 'hi' },
|
|
73
|
-
]);
|
|
74
|
-
expect(messages.map((m) => m.role)).toEqual(['user']);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=vision.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vision.test.js","sourceRoot":"","sources":["../../src/__tests__/vision.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEtE;;;;;;;;;;;;GAYG;AAEH,MAAM,GAAG,GAAG,cAAc,CAAA;AAE1B,SAAS,UAAU,CAAC,WAAsB;IACzC,MAAM,QAAQ,GAAG,iBAAiB,CAAC;QAClC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE;KACP,CAAC,CAAA;IACjD,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAA;AAC5B,CAAC;AAED,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IAC1D,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QACjD,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IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACnD,MAAM,QAAQ,GAAG,iBAAiB,CAAC;YAClC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE;YACvC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;SACK,CAAC,CAAA;QAEtC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk'
|
|
2
|
-
import { beforeEach, describe, expect, it } from 'vitest'
|
|
3
|
-
import { BEDROCK_CAPABILITIES, BedrockProvider, registerBedrock } from '../index.js'
|
|
4
|
-
|
|
5
|
-
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
6
|
-
// via its sideEffects whitelist; we only need to clear 'bedrock' to make
|
|
7
|
-
// re-registration deterministic across tests.
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
if (ProviderRegistry.isSupported('bedrock')) {
|
|
10
|
-
ProviderRegistry.unregister('bedrock')
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('@namzu/bedrock', () => {
|
|
15
|
-
describe('registerBedrock()', () => {
|
|
16
|
-
it("adds 'bedrock' to the ProviderRegistry", () => {
|
|
17
|
-
expect(ProviderRegistry.isSupported('bedrock')).toBe(false)
|
|
18
|
-
registerBedrock()
|
|
19
|
-
expect(ProviderRegistry.isSupported('bedrock')).toBe(true)
|
|
20
|
-
expect(ProviderRegistry.listTypes()).toContain('bedrock')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('throws DuplicateProviderError when called twice without options', () => {
|
|
24
|
-
registerBedrock()
|
|
25
|
-
expect(() => registerBedrock()).toThrowError(DuplicateProviderError)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('allows re-registration when { replace: true } is passed', () => {
|
|
29
|
-
registerBedrock()
|
|
30
|
-
expect(() => registerBedrock({ replace: true })).not.toThrow()
|
|
31
|
-
expect(ProviderRegistry.isSupported('bedrock')).toBe(true)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('exposes capabilities through the registry after registration', () => {
|
|
35
|
-
registerBedrock()
|
|
36
|
-
const caps = ProviderRegistry.getCapabilities('bedrock')
|
|
37
|
-
expect(caps).toEqual(BEDROCK_CAPABILITIES)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe('BEDROCK_CAPABILITIES', () => {
|
|
42
|
-
it('declares the expected capability flags', () => {
|
|
43
|
-
expect(BEDROCK_CAPABILITIES).toEqual({
|
|
44
|
-
supportsTools: true,
|
|
45
|
-
supportsStreaming: true,
|
|
46
|
-
supportsFunctionCalling: true,
|
|
47
|
-
supportsVision: false,
|
|
48
|
-
supportsDocuments: false,
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('is exposed on the provider instance for runtime negotiation', () => {
|
|
53
|
-
const provider = new BedrockProvider({ region: 'us-east-1' })
|
|
54
|
-
expect(provider.capabilities).toEqual(BEDROCK_CAPABILITIES)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('keeps the Namzu enforcement hint out of the Bedrock command', async () => {
|
|
59
|
-
const provider = new BedrockProvider({ region: 'us-east-1' })
|
|
60
|
-
let commandInput: Record<string, unknown> | undefined
|
|
61
|
-
;(provider as unknown as { client: unknown }).client = {
|
|
62
|
-
send: async (command: { input: Record<string, unknown> }) => {
|
|
63
|
-
commandInput = command.input
|
|
64
|
-
return {
|
|
65
|
-
$metadata: { requestId: 'request-test' },
|
|
66
|
-
stream: (async function* () {})(),
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for await (const _chunk of provider.chatStream({
|
|
72
|
-
model: 'anthropic.claude-sonnet-5-v1:0',
|
|
73
|
-
messages: [{ role: 'user', content: 'edit' }],
|
|
74
|
-
tools: [
|
|
75
|
-
{
|
|
76
|
-
type: 'function',
|
|
77
|
-
function: {
|
|
78
|
-
name: 'edit',
|
|
79
|
-
description: 'Edit',
|
|
80
|
-
parameters: { type: 'object' },
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
enforceToolInputSchema: ['edit'],
|
|
85
|
-
})) {
|
|
86
|
-
// Drain the empty test stream.
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
expect(commandInput).not.toHaveProperty('enforceToolInputSchema')
|
|
90
|
-
expect(commandInput?.toolConfig).toEqual({
|
|
91
|
-
tools: [
|
|
92
|
-
{
|
|
93
|
-
toolSpec: {
|
|
94
|
-
name: 'edit',
|
|
95
|
-
description: 'Edit',
|
|
96
|
-
inputSchema: { json: { type: 'object' } },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
toolChoice: { auto: {} },
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
})
|
|
@@ -1,236 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { ChatCompletionParams } from '@namzu/sdk'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { BedrockProvider } from '../client.js'
|
|
5
|
-
import { assertModelReachable } from '../model-reachability.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This driver speaks Converse with ARN-versioned model ids. The current Claude
|
|
9
|
-
* generation is served by a different Bedrock integration whose ids carry no
|
|
10
|
-
* version suffix, and pointing this wire at one produced an opaque AWS
|
|
11
|
-
* validation error naming neither the cause nor the remedy.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
describe('model ids this wire can serve', () => {
|
|
15
|
-
const reachable = [
|
|
16
|
-
'anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
17
|
-
'us.anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
18
|
-
'eu.anthropic.claude-opus-4-5-20251101-v1:0',
|
|
19
|
-
'global.anthropic.claude-opus-4-6-v1',
|
|
20
|
-
'apac.anthropic.claude-sonnet-4-20250514-v1:0',
|
|
21
|
-
'anthropic.claude-haiku-4-5-20251001-v1:0',
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
for (const model of reachable) {
|
|
25
|
-
it(`accepts ${model}`, () => {
|
|
26
|
-
expect(() => assertModelReachable(model)).not.toThrow()
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const unreachable = [
|
|
31
|
-
'anthropic.claude-opus-5',
|
|
32
|
-
'anthropic.claude-sonnet-5',
|
|
33
|
-
'anthropic.claude-fable-5',
|
|
34
|
-
'anthropic.claude-opus-4-8',
|
|
35
|
-
'anthropic.claude-opus-4-7',
|
|
36
|
-
'us.anthropic.claude-opus-5',
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
for (const model of unreachable) {
|
|
40
|
-
it(`refuses ${model} and says why`, () => {
|
|
41
|
-
expect(() => assertModelReachable(model)).toThrow(/cannot reach/)
|
|
42
|
-
expect(() => assertModelReachable(model)).toThrow(/Converse API/)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
it('leaves a non-Claude model alone', () => {
|
|
47
|
-
// This driver serves whatever Bedrock serves. The check is about one
|
|
48
|
-
// vendor's id scheme, not about policing the catalogue.
|
|
49
|
-
expect(() => assertModelReachable('amazon.nova-pro-v1:0')).not.toThrow()
|
|
50
|
-
expect(() => assertModelReachable('meta.llama3-70b-instruct-v1:0')).not.toThrow()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('accepts an unknown versioned Claude id', () => {
|
|
54
|
-
// A model this file has never heard of passes as long as its id has
|
|
55
|
-
// the shape this wire carries. A list that must be edited for every
|
|
56
|
-
// new model is a list that is wrong before anyone reads it.
|
|
57
|
-
expect(() => assertModelReachable('anthropic.claude-sonnet-9-20991231-v1:0')).not.toThrow()
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('the driver refuses before it calls AWS', () => {
|
|
62
|
-
it('throws on an unreachable model with no credentials in play', async () => {
|
|
63
|
-
const provider = new BedrockProvider({ region: 'us-east-1' } as never)
|
|
64
|
-
|
|
65
|
-
await expect(async () => {
|
|
66
|
-
for await (const _ of provider.chatStream({
|
|
67
|
-
model: 'anthropic.claude-opus-5',
|
|
68
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
69
|
-
} as ChatCompletionParams)) {
|
|
70
|
-
// drain
|
|
71
|
-
}
|
|
72
|
-
}).rejects.toThrow(/cannot reach "anthropic\.claude-opus-5"/)
|
|
73
|
-
})
|
|
74
|
-
})
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { parseBedrockUsage } from '../client.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Cache reads and cache writes are priced differently from ordinary input,
|
|
7
|
-
* so folding either into the prompt count misreports what a run cost — and
|
|
8
|
-
* misreports it silently, because the total still looks plausible.
|
|
9
|
-
*
|
|
10
|
-
* The counters are also the only evidence that the breakpoints are working
|
|
11
|
-
* at all: a run whose cached count stays at zero is paying full price for
|
|
12
|
-
* a prefix it believes is cached, and nothing else says so.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
describe('cache counters are reported on their own axis', () => {
|
|
16
|
-
it('keeps reads out of the prompt count', () => {
|
|
17
|
-
const usage = parseBedrockUsage({
|
|
18
|
-
inputTokens: 10,
|
|
19
|
-
outputTokens: 2,
|
|
20
|
-
cacheReadInputTokenCount: 900,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
expect(usage.promptTokens).toBe(10)
|
|
24
|
-
expect(usage.cachedTokens).toBe(900)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('keeps writes on their own axis too', () => {
|
|
28
|
-
const usage = parseBedrockUsage({
|
|
29
|
-
inputTokens: 10,
|
|
30
|
-
outputTokens: 2,
|
|
31
|
-
cacheWriteInputTokenCount: 40,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
expect(usage.cacheWriteTokens).toBe(40)
|
|
35
|
-
expect(usage.promptTokens).toBe(10)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('reports both when both happen in one turn', () => {
|
|
39
|
-
const usage = parseBedrockUsage({
|
|
40
|
-
inputTokens: 10,
|
|
41
|
-
outputTokens: 2,
|
|
42
|
-
cacheReadInputTokenCount: 900,
|
|
43
|
-
cacheWriteInputTokenCount: 40,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
expect(usage).toMatchObject({ cachedTokens: 900, cacheWriteTokens: 40 })
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('reads an absent counter as zero, not undefined', () => {
|
|
50
|
-
const usage = parseBedrockUsage({ inputTokens: 5, outputTokens: 1 })
|
|
51
|
-
|
|
52
|
-
// A consumer summing these must not have to guard every field; an
|
|
53
|
-
// undefined here becomes NaN one addition later.
|
|
54
|
-
expect(usage.cachedTokens).toBe(0)
|
|
55
|
-
expect(usage.cacheWriteTokens).toBe(0)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('totals input and output, and nothing else', () => {
|
|
59
|
-
const usage = parseBedrockUsage({
|
|
60
|
-
inputTokens: 10,
|
|
61
|
-
outputTokens: 2,
|
|
62
|
-
cacheReadInputTokenCount: 900,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// Cached reads are already counted upstream; adding them here would
|
|
66
|
-
// double-count the same tokens in the run's own ledger.
|
|
67
|
-
expect(usage.totalTokens).toBe(12)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('reads a missing usage payload as all zeros', () => {
|
|
71
|
-
const usage = parseBedrockUsage(undefined)
|
|
72
|
-
|
|
73
|
-
expect(usage).toEqual({
|
|
74
|
-
promptTokens: 0,
|
|
75
|
-
completionTokens: 0,
|
|
76
|
-
totalTokens: 0,
|
|
77
|
-
cachedTokens: 0,
|
|
78
|
-
cacheWriteTokens: 0,
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
})
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ChatCompletionParams } from '@namzu/sdk'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { BedrockProvider } from '../client.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The shared guard's own tests pass whether or not this driver calls it, so
|
|
8
|
-
* this drives the real `chatStream`. The defect being fixed was exactly a
|
|
9
|
-
* declared parameter that no code path consumed — asserting the helper works
|
|
10
|
-
* would have reproduced that shape one level up.
|
|
11
|
-
*
|
|
12
|
-
* The guard runs before any client work, so no credentials and no network are
|
|
13
|
-
* involved: the request never gets that far.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const provider = new BedrockProvider({ region: 'us-east-1' } as never)
|
|
17
|
-
|
|
18
|
-
async function run(thinking?: ChatCompletionParams['thinking']): Promise<void> {
|
|
19
|
-
for await (const _chunk of provider.chatStream({
|
|
20
|
-
model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
21
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
22
|
-
...(thinking ? { thinking } : {}),
|
|
23
|
-
} as ChatCompletionParams)) {
|
|
24
|
-
// drain
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('BedrockProvider refuses a thinking request rather than dropping it', () => {
|
|
29
|
-
it('throws on a manual thinking request', async () => {
|
|
30
|
-
await expect(run({ type: 'enabled', budgetTokens: 10_000 })).rejects.toThrow(
|
|
31
|
-
/BedrockProvider does not implement thinking/,
|
|
32
|
-
)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('throws on an adaptive one', async () => {
|
|
36
|
-
await expect(run({ type: 'adaptive' })).rejects.toThrow(/does not implement thinking/)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('does not throw for an explicit disable', async () => {
|
|
40
|
-
// Reaches the client and fails on credentials or network instead,
|
|
41
|
-
// which is the point: the guard let it past.
|
|
42
|
-
await expect(run({ type: 'disabled' })).rejects.not.toThrow(/does not implement thinking/)
|
|
43
|
-
})
|
|
44
|
-
})
|