@kindgi/adapter-model-bedrock 0.0.0-stage → 0.1.7

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kindgi Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,88 @@
1
- # Temporary Holding Version
1
+ # `@kindgi/adapter-model-bedrock`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Amazon Bedrock `ModelProvider` for [`@kindgi/capabilities`](../../capabilities/): a registration's models on Bedrock's Converse API (Anthropic's Claude, Amazon Nova, Meta's Llama, Mistral, OpenAI's models and the others Bedrock serves), signed in as the runtime's own AWS identity or with a Bedrock API key.
4
+
5
+ It's built on [`@kindgi/adapter-model-shared`](../model-shared/): the retries, typed errors (`ModelProviderError`), the reasoning state carried across a pause, usage and cost are the same as every adapter built on it. The requests are sent by the AI SDK's `@ai-sdk/amazon-bedrock` provider at the provider-spec level, pinned exactly.
6
+
7
+ ## A registration
8
+
9
+ `adapter_id: @kindgi/adapter-model-bedrock`:
10
+
11
+ | Setting | What |
12
+ |---|---|
13
+ | `metadata.region` | Required: the AWS region Bedrock runs in (`us-east-2`). The requests go to it and are signed for it. |
14
+ | `metadata.models[].name` | A Bedrock model id or inference-profile id, as Bedrock names it: `us.amazon.nova-pro-v1:0`, `us.anthropic.claude-sonnet-5-5`. A cross-region profile (`us.`, `eu.`, `apac.`…) is called from a region in its geography. |
15
+ | `adapter_config.auth` | `aws-identity` (default): the runtime's AWS identity, requests signed with SigV4. `api-key`: a Bedrock API key through `secret_ref`, sent as a bearer token. AWS recommends API keys for exploration only. |
16
+ | `adapter_config.baseURL` | Optional: another `bedrock-runtime` endpoint (https, its root), such as a VPC endpoint or a FIPS endpoint. With `aws-identity`, Bedrock's runtime in the region only (below); with `api-key`, any host and path (a gateway). Default: the region's own (`https://bedrock-runtime.<region>.amazonaws.com`, or its partition's domain). |
17
+
18
+ ```json
19
+ {
20
+ "adapter_id": "@kindgi/adapter-model-bedrock",
21
+ "metadata": {
22
+ "id": "bedrock",
23
+ "region": "us-east-2",
24
+ "models": [
25
+ {
26
+ "name": "us.amazon.nova-pro-v1:0",
27
+ "contextWindow": 300000,
28
+ "features": ["tool-use", "structured-output"],
29
+ "cost": { "promptUsdPer1kTokens": 0.0008, "completionUsdPer1kTokens": 0.0032 }
30
+ }
31
+ ]
32
+ }
33
+ }
34
+ ```
35
+
36
+ `checkConfig` reports each problem with a registration at the setting at fault, without the network or the secret:
37
+ - a `metadata.region` that isn't an AWS region (`global`, `unspecified`);
38
+ - an unknown `auth` or `adapter_config` key;
39
+ - a `baseURL` that isn't https, holds credentials, a query or a fragment, or has a path on Bedrock's own host;
40
+ - `aws-identity` with a `baseURL` that isn't Bedrock's runtime in the region, naming the host;
41
+ - `api-key` without `secret_ref`, or `aws-identity` with one.
42
+
43
+ ## How it signs in
44
+
45
+ Each of these has a test. It signs in before each attempt, with the call's abort signal, and the attempt's request carries what that sign-in got, so calls running at once never share credentials and each attempt asks the identity once.
46
+ - **`auth: aws-identity`:** SigV4, with credentials from the runtime's AWS identity (`AdapterFactoryInput.identities.aws`), asked for every attempt, within 10 seconds; a call stopped meanwhile ends at once, with its own reason. The identity refreshes them itself, so short-lived role credentials renew. A runtime with no AWS identity refuses the registration when it registers, naming `KINDGI_AWS_IDENTITY`.
47
+ - **Only Bedrock's runtime in the region gets them:** `bedrock-runtime.<region>`, `bedrock-runtime-fips.<region>`, or an interface VPC endpoint's own name (`vpce-….bedrock-runtime.<region>.vpce`), in the region's partition. A signed request carries the session token, so another host is refused at registration (and by the factory), naming it. A VPC endpoint with private DNS needs no `baseURL` at all. AWS lists the endpoints on [Amazon Bedrock endpoints and quotas](https://docs.aws.amazon.com/general/latest/gr/bedrock.html) and [interface VPC endpoints](https://docs.aws.amazon.com/bedrock/latest/userguide/vpc-interface-endpoints.html).
48
+ - **Its policy:** `bedrock:InvokeModel` on each model. For an inference profile, on the profile and on the foundation model in each Region the profile routes to; AWS shows these policies, a global profile's included, on [Prerequisites for inference profiles](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-prereq.html). The account also needs access to the model in the region.
49
+ - **`auth: api-key`:** the key `secret_ref` names, read for every attempt and sent as the bearer token (whitespace around it dropped), so a rotated key takes effect on the next call. A key with a line break or a control character inside it is refused as `auth` before the request, never quoted. No AWS credentials are looked for.
50
+ - **A failed sign-in** (the identity gives no credentials, the key can't be read, even with the secret store down, or is empty or blank) ends the call as an `auth` error at once, never retried.
51
+ - **A 403 from Bedrock says what to check**, for how it signed in: the identity's policy or the IAM user's the key belongs to, the account's access to the model, or expired credentials or an expired or revoked key.
52
+ - **No request follows a redirect** (`redirect: 'error'`): the credentials reach the endpoint and nothing else.
53
+ - **Never the environment:** `AWS_BEARER_TOKEN_BEDROCK`, `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` / `AWS_SESSION_TOKEN`, `AWS_REGION`, `AWS_ENDPOINT_URL_BEDROCK_RUNTIME` and `AWS_ENDPOINT_URL` are never read. The provider is always given its region, its endpoint and its credentials.
54
+
55
+ ## What it sends
56
+
57
+ `POST <endpoint>/model/<model id>/converse`, through the runtime's `fetch` (`AdapterFactoryInput.fetch`), which refuses the hosts its deployment forbids. Bedrock's request id (`x-amzn-requestid`) is the result's `providerRequestId`. Running out of context (`model_context_window_exceeded`) is the finish reason `length`.
58
+
59
+ **Model ids:** a model id or a system inference profile (`us.amazon.nova-pro-v1:0`). Application inference profiles (`…:application-inference-profile/…`) aren't supported yet: the Claude handling and the Nova clean-up go by the model's name, so one would get neither.
60
+
61
+ ## Nova's chain of thought
62
+
63
+ When tools are in play, Amazon Nova writes its reasoning into the answer: `<thinking>…</thinking>` before the reply. A Kindgi answer carries no reasoning (the other vendors keep it apart, and a result has no slot for reasoning text). So for a Nova model, one leading `<thinking>` block is taken out of the answer, and the result carries the warning `reasoning-text-removed` (`NOVA_THINKING_REMOVED`), which the model-call record keeps. Only an exact, closed, leading block is touched: one later in the text, or an unclosed one, is left as it came. Other vendors' models are never changed.
64
+
65
+ ## Prompt caching
66
+
67
+ Bedrock caches only the prompt prefixes a request marks with a cache point, so the adapter marks them for a model whose registration prices cache reads (a positive `cachedPromptMultiplier` or `promptCacheReadMultiplier`) and that is Anthropic's Claude or Amazon Nova:
68
+ - after the system prompt (the first system message). The tools come before it, so the cached prefix holds them too;
69
+ - after the last message, when the call will be sent again: it has tools (the next step of a tool loop sends everything again) or an earlier answer (the next turn does).
70
+
71
+ That's two cache points at most, under Bedrock's four per request, each with the 5-minute cache. A prefix shorter than the model's minimum isn't cached and costs nothing extra. Other models, OpenAI's on Bedrock or an application inference profile among them, get no cache points. Nova's cache can take a few seconds to become readable: a call right after the first may write the prefix again, which costs nothing on Nova.
72
+
73
+ ## Cost
74
+
75
+ `costUsd` is `tokenCostUsd` over the model's registered rates: prompt and completion, cache reads and writes at the model's `cachedPromptMultiplier` / `promptCacheCreationMultiplier` (the prompt rate when absent), and the long-context tier when registered. Bedrock's prices differ by model, region and tier, so register the rates of yours. Costs are estimates from published prices; AWS's invoice is authoritative.
76
+
77
+ ## Exports
78
+
79
+ - **`bedrockAdapterEntry`**: the `AdapterFactoryEntry` a runtime registers, with `bedrockAdapterFactory` and `bedrockCheckConfig`.
80
+ - `readBedrockConfig(input)`: a registration read and checked, or every problem with it.
81
+ - `bedrockRuntimeEndpoint(region)`: a region's own `bedrock-runtime` endpoint; `partitionDnsSuffix(region)`; `isBedrockRuntimeHost(hostname, region)`: whether a host may get the runtime's credentials.
82
+ - `IDENTITY_TIMEOUT_MS`: how long the runtime's AWS identity may take.
83
+ - `isNovaModel(name)`, `withoutLeadingThinking(result)` and `NOVA_THINKING_REMOVED`: the Nova rule above.
84
+ - `BEDROCK_ADAPTER_ID`, `BEDROCK_AUTHS`, and the `BedrockConfig` and `BedrockAuth` types.
85
+
86
+ ## License
87
+
88
+ Apache-2.0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * An Amazon Bedrock registration, read and checked: the region (`metadata.region`), how to sign
3
+ * in, and the endpoint. Static: no network, no secret read (`checkConfig` runs it at
4
+ * registration, the factory again when it builds).
5
+ */
6
+ import type { AdapterConfigCheckInput, AdapterConfigProblem } from '@kindgi/capabilities';
7
+ export declare const BEDROCK_ADAPTER_ID = "@kindgi/adapter-model-bedrock";
8
+ /**
9
+ * The runtime's AWS identity, requests signed with SigV4 (the default), or a Bedrock API key
10
+ * (`secret_ref`, sent as a bearer token), which AWS recommends for exploration only.
11
+ */
12
+ export declare const BEDROCK_AUTHS: readonly ["aws-identity", "api-key"];
13
+ export type BedrockAuth = (typeof BEDROCK_AUTHS)[number];
14
+ export interface BedrockConfig {
15
+ /** The AWS region the requests go to and are signed for. */
16
+ readonly region: string;
17
+ /** The `bedrock-runtime` endpoint: the region's own, or the registration's `baseURL`. */
18
+ readonly baseURL: string;
19
+ readonly auth: BedrockAuth;
20
+ }
21
+ /** The DNS suffix of a region's partition: `amazonaws.com`, `amazonaws.com.cn`, … */
22
+ export declare function partitionDnsSuffix(region: string): string;
23
+ /** The region's own `bedrock-runtime` endpoint. */
24
+ export declare function bedrockRuntimeEndpoint(region: string): string;
25
+ /**
26
+ * Whether a host is Bedrock's runtime in this region: its own endpoint, its FIPS endpoint, or
27
+ * an interface VPC endpoint's own name. Only these get requests signed with the runtime's AWS
28
+ * credentials: a registration naming another host would receive the session token and a
29
+ * signature. Sources (read 2026-10-09): https://docs.aws.amazon.com/general/latest/gr/bedrock.html
30
+ * (the endpoints and FIPS endpoints) and
31
+ * https://docs.aws.amazon.com/bedrock/latest/userguide/vpc-interface-endpoints.html
32
+ * (`vpce-id.bedrock-runtime.region.vpce.amazonaws.com`).
33
+ */
34
+ export declare function isBedrockRuntimeHost(hostname: string, region: string): boolean;
35
+ /** The registration read, or every problem with it. */
36
+ export declare function readBedrockConfig(input: AdapterConfigCheckInput): {
37
+ readonly kind: 'ok';
38
+ readonly config: BedrockConfig;
39
+ } | {
40
+ readonly kind: 'err';
41
+ readonly problems: readonly AdapterConfigProblem[];
42
+ };
43
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE1F,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAElE;;;GAGG;AACH,eAAO,MAAM,aAAa,sCAAuC,CAAC;AAClE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yFAAyF;IACzF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAqBD,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED,mDAAmD;AACnD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAM9E;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,uBAAuB,GAE5B;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,CAAA;CAAE,CA+D/E"}
package/dist/config.js ADDED
@@ -0,0 +1,159 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export const BEDROCK_ADAPTER_ID = '@kindgi/adapter-model-bedrock';
4
+ /**
5
+ * The runtime's AWS identity, requests signed with SigV4 (the default), or a Bedrock API key
6
+ * (`secret_ref`, sent as a bearer token), which AWS recommends for exploration only.
7
+ */
8
+ export const BEDROCK_AUTHS = ['aws-identity', 'api-key'];
9
+ const KEYS = ['auth', 'baseURL'];
10
+ /** An AWS region name: `us-east-2`, `us-gov-west-1`, `eusc-de-east-1`. */
11
+ const REGION = /^[a-z]{2,4}(?:-[a-z]+)+-\d{1,2}$/;
12
+ /**
13
+ * The DNS suffix of each AWS partition other than `aws` (`amazonaws.com`), by region prefix:
14
+ * the same table `@ai-sdk/amazon-bedrock` builds its default endpoint from. The runtime's AWS
15
+ * identity keeps a copy for its STS endpoint, until both read one shared module.
16
+ */
17
+ const PARTITION_DNS_SUFFIXES = [
18
+ ['cn-', 'amazonaws.com.cn'],
19
+ ['us-iso-', 'c2s.ic.gov'],
20
+ ['us-isob-', 'sc2s.sgov.gov'],
21
+ ['eu-isoe-', 'cloud.adc-e.uk'],
22
+ ['us-isof-', 'csp.hci.ic.gov'],
23
+ ['eusc-', 'amazonaws.eu'],
24
+ ];
25
+ const at = (key) => `/adapter_config/${key}`;
26
+ /** The DNS suffix of a region's partition: `amazonaws.com`, `amazonaws.com.cn`, … */
27
+ export function partitionDnsSuffix(region) {
28
+ return (PARTITION_DNS_SUFFIXES.find(([prefix]) => region.startsWith(prefix))?.[1] ?? 'amazonaws.com');
29
+ }
30
+ /** The region's own `bedrock-runtime` endpoint. */
31
+ export function bedrockRuntimeEndpoint(region) {
32
+ return `https://bedrock-runtime.${region}.${partitionDnsSuffix(region)}`;
33
+ }
34
+ /**
35
+ * Whether a host is Bedrock's runtime in this region: its own endpoint, its FIPS endpoint, or
36
+ * an interface VPC endpoint's own name. Only these get requests signed with the runtime's AWS
37
+ * credentials: a registration naming another host would receive the session token and a
38
+ * signature. Sources (read 2026-10-09): https://docs.aws.amazon.com/general/latest/gr/bedrock.html
39
+ * (the endpoints and FIPS endpoints) and
40
+ * https://docs.aws.amazon.com/bedrock/latest/userguide/vpc-interface-endpoints.html
41
+ * (`vpce-id.bedrock-runtime.region.vpce.amazonaws.com`).
42
+ */
43
+ export function isBedrockRuntimeHost(hostname, region) {
44
+ const host = hostname.toLowerCase();
45
+ const tail = `${region}.${partitionDnsSuffix(region)}`;
46
+ if (host === `bedrock-runtime.${tail}` || host === `bedrock-runtime-fips.${tail}`)
47
+ return true;
48
+ const vpce = `.bedrock-runtime.${region}.vpce.${partitionDnsSuffix(region)}`;
49
+ return host.endsWith(vpce) && /^vpce-[a-z0-9-]+$/.test(host.slice(0, -vpce.length));
50
+ }
51
+ /** The registration read, or every problem with it. */
52
+ export function readBedrockConfig(input) {
53
+ const config = input.config ?? {};
54
+ const problems = [];
55
+ for (const key of Object.keys(config)) {
56
+ if (!KEYS.includes(key)) {
57
+ problems.push({
58
+ path: at(key),
59
+ message: `adapter_config.${key} isn't an Amazon Bedrock setting: it takes auth and baseURL (the region is metadata.region).`,
60
+ });
61
+ }
62
+ }
63
+ const region = input.metadata.region;
64
+ const regionOk = typeof region === 'string' && REGION.test(region);
65
+ if (!regionOk) {
66
+ problems.push({
67
+ path: '/metadata/region',
68
+ message: `metadata.region must be the AWS region Bedrock runs in (e.g. us-east-2): the requests go to it and are signed for it. Got "${String(region)}".`,
69
+ });
70
+ }
71
+ const auth = config.auth ?? 'aws-identity';
72
+ const baseURL = config.baseURL;
73
+ if (baseURL !== undefined) {
74
+ readBaseURL(baseURL, auth, regionOk ? region : undefined, problems);
75
+ }
76
+ if (!BEDROCK_AUTHS.includes(auth)) {
77
+ problems.push({
78
+ path: at('auth'),
79
+ message: `adapter_config.auth must be one of ${BEDROCK_AUTHS.join(', ')}.`,
80
+ });
81
+ }
82
+ else if (auth === 'api-key' && !input.hasSecretRef) {
83
+ problems.push({
84
+ path: '/secret_ref',
85
+ message: "adapter_config.auth = api-key needs secret_ref: the Bedrock API key (or leave auth unset, to sign in as the runtime's AWS identity).",
86
+ });
87
+ }
88
+ else if (auth === 'aws-identity' && input.hasSecretRef) {
89
+ problems.push({
90
+ path: '/secret_ref',
91
+ message: "adapter_config.auth = aws-identity (the default) signs in as the runtime's AWS identity: remove secret_ref, or set auth = api-key for a Bedrock API key.",
92
+ });
93
+ }
94
+ if (auth === 'aws-identity' && input.identities?.aws === false) {
95
+ problems.push({
96
+ path: at('auth'),
97
+ message: "adapter_config.auth = aws-identity (the default) needs the runtime's AWS identity (KINDGI_AWS_IDENTITY says where it comes from), and this runtime has none. Or set auth = api-key for a Bedrock API key.",
98
+ });
99
+ }
100
+ if (problems.length > 0)
101
+ return { kind: 'err', problems };
102
+ return {
103
+ kind: 'ok',
104
+ config: {
105
+ region,
106
+ baseURL: baseURL ?? bedrockRuntimeEndpoint(region),
107
+ auth: auth,
108
+ },
109
+ };
110
+ }
111
+ /**
112
+ * A custom endpoint: https, with no credentials, query or fragment (they'd sit in the stored
113
+ * settings); Bedrock's own host at its root; with `auth: aws-identity`, Bedrock's runtime in
114
+ * the region only. A gateway (with `auth: api-key`) is any host and path.
115
+ */
116
+ function readBaseURL(value, auth, region, problems) {
117
+ const path = at('baseURL');
118
+ const url = typeof value === 'string' ? parseUrl(value) : undefined;
119
+ if (url === undefined || url.protocol !== 'https:') {
120
+ problems.push({
121
+ path,
122
+ message: 'adapter_config.baseURL must be an https URL: a bedrock-runtime endpoint of your own, such as a VPC endpoint or a FIPS endpoint.',
123
+ });
124
+ return;
125
+ }
126
+ const raw = value;
127
+ if (url.username !== '' || url.password !== '') {
128
+ problems.push({
129
+ path,
130
+ message: "adapter_config.baseURL can't hold credentials: a key goes in secret_ref, never in the URL.",
131
+ });
132
+ }
133
+ if (url.search !== '' || raw.includes('?') || url.hash !== '' || raw.includes('#')) {
134
+ problems.push({ path, message: "adapter_config.baseURL can't hold a query or a fragment." });
135
+ }
136
+ const bedrockHost = region !== undefined && isBedrockRuntimeHost(url.hostname, region);
137
+ if (bedrockHost && url.pathname !== '/' && url.pathname !== '') {
138
+ problems.push({
139
+ path,
140
+ message: `adapter_config.baseURL is an endpoint's root (https://${url.host}), with no path: the adapter adds the API's.`,
141
+ });
142
+ }
143
+ if (auth === 'aws-identity' && region !== undefined && !bedrockHost) {
144
+ const suffix = partitionDnsSuffix(region);
145
+ problems.push({
146
+ path,
147
+ message: `adapter_config.auth = aws-identity signs requests with the runtime's AWS credentials, which go only to Bedrock's runtime in ${region} (bedrock-runtime.${region}.${suffix}, bedrock-runtime-fips.${region}.${suffix}, or a VPC endpoint's vpce-….bedrock-runtime.${region}.vpce.${suffix}); ${url.hostname} isn't one. A VPC endpoint with private DNS needs no baseURL; another endpoint takes auth = api-key.`,
148
+ });
149
+ }
150
+ }
151
+ function parseUrl(value) {
152
+ try {
153
+ return new URL(value);
154
+ }
155
+ catch {
156
+ return undefined;
157
+ }
158
+ }
159
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAUjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,SAAS,CAAU,CAAC;AAWlE,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAU,CAAC;AAC1C,0EAA0E;AAC1E,MAAM,MAAM,GAAG,kCAAkC,CAAC;AAClD;;;;GAIG;AACH,MAAM,sBAAsB,GAA2D;IACrF,CAAC,KAAK,EAAE,kBAAkB,CAAC;IAC3B,CAAC,SAAS,EAAE,YAAY,CAAC;IACzB,CAAC,UAAU,EAAE,eAAe,CAAC;IAC7B,CAAC,UAAU,EAAE,gBAAgB,CAAC;IAC9B,CAAC,UAAU,EAAE,gBAAgB,C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AAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type AdapterConfigCheckInput, type AdapterConfigProblem, type AdapterFactory, type AdapterFactoryEntry, type ModelInfo } from '@kindgi/capabilities';
2
+ /** How long the runtime's AWS identity may take before the call fails as `auth`. */
3
+ export declare const IDENTITY_TIMEOUT_MS = 10000;
4
+ /** What's wrong with a registration, for `POST /v1/providers` and `GET …/check`. */
5
+ export declare function bedrockCheckConfig(input: AdapterConfigCheckInput): readonly AdapterConfigProblem[];
6
+ export declare const bedrockAdapterFactory: AdapterFactory;
7
+ /**
8
+ * Whether the adapter marks a model's prompts for Bedrock's cache: the registration prices
9
+ * cache reads (a positive `cachedPromptMultiplier` or `promptCacheReadMultiplier`), and the
10
+ * model is Claude or Nova, the families whose caching was seen live on Bedrock (2026-10-10).
11
+ * Others, OpenAI's models on Bedrock or an application inference profile's ARN among them, stay
12
+ * unmarked until they are.
13
+ */
14
+ export declare function cachesPrompts(model: ModelInfo): boolean;
15
+ /** The entry a runtime registers: the factory, and its static check. */
16
+ export declare const bedrockAdapterEntry: AdapterFactoryEntry;
17
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAkCA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAGxB,KAAK,SAAS,EAGf,MAAM,sBAAsB,CAAC;AAY9B,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,oFAAoF;AACpF,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,uBAAuB,GAC7B,SAAS,oBAAoB,EAAE,CAGjC;AAED,eAAO,MAAM,qBAAqB,EAAE,cAuDnC,CAAC;AAWF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAIvD;AAED,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,EAAE,mBAKjC,CAAC"}