feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

Binary file not shown.

View File

@@ -0,0 +1 @@
/home/uroma2/zcode-cli-x/~/.npm-cache/@alcalzone/ansi-tokenize@0.3.0@@@1

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-2026 AlCalzone
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,278 @@
# @alcalzone/ansi-tokenize
> Efficiently modify strings containing [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
If you find yourself modifying styled strings repeatedly, alternatives like [`slice-ansi`](https://github.com/chalk/slice-ansi/) may end up doing a lot of unnecessary work by re-parsing the string each time. This module provides a way to parse the string into an array of tokens (characters or ANSI codes), which can then be modified and re-serialized into a styled string.
## Install
```
$ npm install @alcalzone/ansi-tokenize
```
## Usage
### Tokenize a string
```js
import { tokenize } from "@alcalzone/ansi-tokenize";
// red "foo", followed by unstyled "bar"
const str = "\x1B[31mfoo\x1B[39mbar";
const tokens = tokenize(str);
// tokens will now look like this:
[
{
type: "ansi",
code: "\x1B[31m",
endCode: "\x1B[39m",
},
{
type: "char",
value: "f",
fullWidth: false,
},
{
type: "char",
value: "o",
fullWidth: false,
},
{
type: "char",
value: "o",
fullWidth: false,
},
{
type: "ansi",
code: "\x1B[39m",
endCode: "\x1B[39m",
},
{
type: "char",
value: "b",
fullWidth: false,
},
{
type: "char",
value: "a",
fullWidth: false,
},
{
type: "char",
value: "r",
fullWidth: false,
},
];
```
Each token is either a character
```ts
export interface Char {
type: "char";
value: string;
fullWidth: boolean;
}
```
where
- `value` is the string representation of the character
- `fullWidth` is `true` if the character is full width (takes up 2 characters in monospace, like CJK characters)
or an ANSI code
```ts
export interface AnsiCode {
type: "ansi";
code: string;
endCode: string;
}
```
where
- `code` is the ANSI code that starts the style
- and `endCode` is the corresponding ANSI code that ends the style.
An `AnsiCode` can also be an end code, in which case `code` and `endCode` will be the same.
### Convert an array of tokens into an array of "styled" chars
This representation is a 1:1 mapping of the original string, but not very useful for modifying the string. The `styledCharsFromTokens` function converts a token array to an array of characters, where each character has an all currently active styles associated with it:
```ts
export interface StyledChar {
type: "char";
value: string;
fullWidth: boolean;
styles: AnsiCode[];
}
```
Using the above example:
```js
import { tokenize, styledCharsFromTokens } from "@alcalzone/ansi-tokenize";
// red "foo", followed by unstyled "bar"
const str = "\x1B[31mfoo\x1B[39mbar";
const tokens = tokenize(str);
const styledChars = styledCharsFromTokens(tokens);
// styledChars will contain the following:
[
{
type: "char",
value: "f",
fullWidth: false,
styles: [
{
type: "ansi",
code: "\x1B[31m",
endCode: "\x1B[39m",
},
],
},
{
type: "char",
value: "o",
fullWidth: false,
styles: [
{
type: "ansi",
code: "\x1B[31m",
endCode: "\x1B[39m",
},
],
},
{
type: "char",
value: "o",
fullWidth: false,
styles: [
{
type: "ansi",
code: "\x1B[31m",
endCode: "\x1B[39m",
},
],
},
{
type: "char",
value: "b",
fullWidth: false,
styles: [],
},
{
type: "char",
value: "a",
fullWidth: false,
styles: [],
},
{
type: "char",
value: "r",
fullWidth: false,
styles: [],
},
];
```
### Modify an array of styled characters
For modification simply edit the items in the array as necessary, as long as the following rules are followed:
1. The `code` and `endCode` properties must match. You can use the `ansi-styles` module to do this.
2. The `fullWidth` property must be correct. You can use the `is-fullwidth-code-point` module to do this, or if working with multiple strings, turn those into styled char arrays first.
E.g. to make the first `o` blue and bold:
```js
import ansiStyles from "ansi-styles";
// ... include the above code
styledChars[1].styles = [
{
type: "ansi",
code: ansiStyles.blue.open,
endCode: ansiStyles.blue.close,
},
{
type: "ansi",
code: ansiStyles.bold.open,
endCode: ansiStyles.bold.close,
},
];
```
### Serialize a styled character array back to a string
The `styledCharsToString` function converts a styled character array back to a string:
```js
import { styledCharsToString } from "@alcalzone/ansi-tokenize";
// ... include the above code
const strOut = styledCharsToString(styledChars);
// str will now be '\x1B[31mf\x1B[34m\x1B[1mo\x1B[22m\x1B[31mo\x1B[39mbar'
```
This automatically figures out the least amount of escape codes necessary to achieve the desired result, as long as the `styles` arrays contain no unnecessary styles, e.g. blue + red foreground.
## Changelog
<!--
Placeholder for next release:
### __WORK IN PROGRESS__
-->
### 0.3.0 (2026-02-20)
- Fix: preserve non-hyperlink OSC sequences when tokenizing (#54)
- Fix: support ST-terminated OSC hyperlinks (#53)
### 0.2.5 (2026-02-11)
- Fix: preserve grapheme clusters when tokenizing (#51)
### 0.2.4 (2026-01-29)
- Fix: Support hyperlinks with parameters (#45)
### 0.2.3 (2026-01-02)
- Fix: Regression when rendering adjacent `dim` and `bold` styles (#43, #44)
### 0.2.2 (2025-10-22)
- Fix: Support compound SGR sequences with multiple attributes (#39, #40)
### 0.2.1 (2025-10-20)
- Fix: Prevent `dim` and `bold` modifiers from canceling each other (#37)
### 0.2.0 (2025-04-24)
- Breaking: Require Node.js 18+
- Fix: Detect emojis as being full width
### 0.1.3 (2023-09-07)
- Fix: Support links
### 0.1.2 (2023-08-07)
- Fix: Reduce minimum Node.js version to `14.13.1`
### 0.1.1 (2023-04-05)
- Fix: Active styles are now correctly reset at the end of the string
### 0.1.0 (2023-03-20)
Initial release

View File

@@ -0,0 +1,7 @@
import type { AnsiCode } from "./tokenize.js";
export declare const endCodesSet: Set<string>;
export declare function getLinkStartCode(url: string, params?: Record<string, string>): string;
export declare function getEndCode(code: string): string;
export declare function ansiCodesToString(codes: AnsiCode[]): string;
/** Check if a code is an intensity code (bold or dim) - these share endCode 22m but can coexist */
export declare function isIntensityCode(code: AnsiCode): boolean;

View File

@@ -0,0 +1,57 @@
import ansiStyles from "ansi-styles";
import { linkCodePrefix, linkCodeSuffix, linkEndCode, linkEndCodeC1ST, linkEndCodeST, } from "./consts.js";
export const endCodesSet = new Set();
const endCodesMap = new Map();
for (const [start, end] of ansiStyles.codes) {
endCodesSet.add(ansiStyles.color.ansi(end));
endCodesMap.set(ansiStyles.color.ansi(start), ansiStyles.color.ansi(end));
}
export function getLinkStartCode(url, params) {
const paramsStr = params
? Object.entries(params)
.map(([k, v]) => `${k}=${v}`)
.join(":")
: "";
return `${linkCodePrefix}${paramsStr};${url}${linkCodeSuffix}`;
}
export function getEndCode(code) {
if (endCodesSet.has(code))
return code;
if (endCodesMap.has(code))
return endCodesMap.get(code);
// We have a few special cases to handle here:
// Links:
if (code.startsWith(linkCodePrefix)) {
if (code.endsWith("\x1B\\"))
return linkEndCodeST;
if (code.endsWith("\x9C"))
return linkEndCodeC1ST;
return linkEndCode; // BEL (\x07)
}
code = code.slice(2);
// 8-bit/24-bit colors:
if (code.startsWith("38")) {
return ansiStyles.color.close;
}
else if (code.startsWith("48")) {
return ansiStyles.bgColor.close;
}
// Otherwise find the reset code in the ansi-styles map
const ret = ansiStyles.codes.get(parseInt(code, 10));
if (ret) {
return ansiStyles.color.ansi(ret);
}
else {
return ansiStyles.reset.open;
}
}
export function ansiCodesToString(codes) {
// Deduplicate ANSI code strings before joining
const deduplicated = new Set(codes.map((code) => code.code));
return [...deduplicated].join("");
}
/** Check if a code is an intensity code (bold or dim) - these share endCode 22m but can coexist */
export function isIntensityCode(code) {
return code.code === ansiStyles.bold.open || code.code === ansiStyles.dim.open;
}
//# sourceMappingURL=ansiCodes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ansiCodes.js","sourceRoot":"","sources":["../src/ansiCodes.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,EACN,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,aAAa,GACb,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;AAC7C,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC9C,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,KAAK,EAAE;IAC5C,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;CAC1E;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,MAA+B;IAC5E,MAAM,SAAS,GAAG,MAAM;QACvB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;aACrB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,C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C7B;AACF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAClD,+CAA+C;IAC/C,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,IAAc;IAC7C,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;AAChF,CAAC"}

View File

@@ -0,0 +1,17 @@
export declare const CC_BEL: number;
export declare const CC_ESC: number;
export declare const CC_BACKSLASH: number;
export declare const CC_CSI: number;
export declare const CC_OSC: number;
export declare const CC_C1_ST: number;
export declare const CC_0: number;
export declare const CC_9: number;
export declare const CC_SEMI: number;
export declare const CC_M: number;
export declare const ESCAPES: Set<number>;
export declare const linkCodePrefix: string;
export declare const linkCodePrefixCharCodes: number[];
export declare const linkCodeSuffix = "\u0007";
export declare const linkEndCode: string;
export declare const linkEndCodeST: string;
export declare const linkEndCodeC1ST: string;

View File

@@ -0,0 +1,28 @@
// Named ANSI control characters
const BEL = "\x07";
const ESC = "\x1b";
const BACKSLASH = "\\";
const CSI = "[";
const OSC = "]";
const C1_ST = "\x9c";
// Char codes (derived from named characters)
export const CC_BEL = BEL.charCodeAt(0);
export const CC_ESC = ESC.charCodeAt(0);
export const CC_BACKSLASH = BACKSLASH.charCodeAt(0);
export const CC_CSI = CSI.charCodeAt(0);
export const CC_OSC = OSC.charCodeAt(0);
export const CC_C1_ST = C1_ST.charCodeAt(0);
export const CC_0 = "0".charCodeAt(0);
export const CC_9 = "9".charCodeAt(0);
export const CC_SEMI = ";".charCodeAt(0);
export const CC_M = "m".charCodeAt(0);
// Escape code points
export const ESCAPES = new Set([CC_ESC, 0x9b]); // \x1b and \x9b
// OSC 8 hyperlink constants
export const linkCodePrefix = `${ESC}${OSC}8;`;
export const linkCodePrefixCharCodes = linkCodePrefix.split("").map((char) => char.charCodeAt(0));
export const linkCodeSuffix = BEL;
export const linkEndCode = `${ESC}${OSC}8;;${BEL}`;
export const linkEndCodeST = `${ESC}${OSC}8;;${ESC}${BACKSLASH}`;
export const linkEndCodeC1ST = `${ESC}${OSC}8;;${C1_ST}`;
//# sourceMappingURL=consts.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,KAAK,GAAG,MAAM,CAAC;AAErB,6CAA6C;AAC7C,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAEtC,qBAAqB;AACrB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB;AAEhE,4BAA4B;AAC5B,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,EAAE,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,KAAK,EAAE,CAAC"}

View File

@@ -0,0 +1,6 @@
import type { AnsiCode } from "./tokenize.js";
/**
* Returns the minimum amount of ANSI codes necessary to get from the compound style `from` to `to`.
* Both `from` and `to` are expected to be reduced.
*/
export declare function diffAnsiCodes(from: AnsiCode[], to: AnsiCode[]): AnsiCode[];

View File

@@ -0,0 +1,26 @@
import { isIntensityCode } from "./ansiCodes.js";
import { undoAnsiCodes } from "./undo.js";
/**
* Returns the minimum amount of ANSI codes necessary to get from the compound style `from` to `to`.
* Both `from` and `to` are expected to be reduced.
*/
export function diffAnsiCodes(from, to) {
const endCodesInTo = new Set(to.map((code) => code.endCode));
const startCodesInTo = new Set(to.map((code) => code.code));
const startCodesInFrom = new Set(from.map((code) => code.code));
return [
// Ignore all styles in `from` that are not overwritten or removed by `to`
// Disable all styles in `from` that are removed in `to`
...undoAnsiCodes(from.filter((code) => {
// Special case: Intensity codes (1m, 2m) can coexist (both end with 22m).
// We have to check the start codes for those, otherwise we might miss a reset.
if (isIntensityCode(code)) {
return !startCodesInTo.has(code.code);
}
return !endCodesInTo.has(code.endCode);
})),
// Add all styles in `to` that don't exist in `from`
...to.filter((code) => !startCodesInFrom.has(code.code)),
];
}
//# sourceMappingURL=diff.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgB,EAAE,EAAc;IAC7D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEhE,OAAO;QACN,0EAA0E;QAC1E,wDAAwD;QACxD,GAAG,aAAa,CACf,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACpB,0EAA0E;YAC1E,+EAA+E;YAC/E,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;gBAC1B,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACtC;YACD,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC,CAAC,CACF;QACD,oDAAoD;QACpD,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACxD,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,6 @@
export { ansiCodesToString } from "./ansiCodes.js";
export { diffAnsiCodes } from "./diff.js";
export { reduceAnsiCodes, reduceAnsiCodesIncremental } from "./reduce.js";
export * from "./styledChars.js";
export * from "./tokenize.js";
export { undoAnsiCodes } from "./undo.js";

View File

@@ -0,0 +1,7 @@
export { ansiCodesToString } from "./ansiCodes.js";
export { diffAnsiCodes } from "./diff.js";
export { reduceAnsiCodes, reduceAnsiCodesIncremental } from "./reduce.js";
export * from "./styledChars.js";
export * from "./tokenize.js";
export { undoAnsiCodes } from "./undo.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC1E,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}

View File

@@ -0,0 +1,5 @@
import type { AnsiCode } from "./tokenize.js";
/** Reduces the given array of ANSI codes to the minimum necessary to render with the same style */
export declare function reduceAnsiCodes(codes: AnsiCode[]): AnsiCode[];
/** Like {@link reduceAnsiCodes}, but assumes that `codes` is already reduced. Further reductions are only done for the items in `newCodes`. */
export declare function reduceAnsiCodesIncremental(codes: AnsiCode[], newCodes: AnsiCode[]): AnsiCode[];

View File

@@ -0,0 +1,37 @@
import ansiStyles from "ansi-styles";
import { endCodesSet, isIntensityCode } from "./ansiCodes.js";
/** Reduces the given array of ANSI codes to the minimum necessary to render with the same style */
export function reduceAnsiCodes(codes) {
return reduceAnsiCodesIncremental([], codes);
}
/** Like {@link reduceAnsiCodes}, but assumes that `codes` is already reduced. Further reductions are only done for the items in `newCodes`. */
export function reduceAnsiCodesIncremental(codes, newCodes) {
let ret = [...codes];
for (const code of newCodes) {
if (code.code === ansiStyles.reset.open) {
// Reset code, disable all codes
ret = [];
}
else if (endCodesSet.has(code.code)) {
// This is an end code, disable all matching start codes
ret = ret.filter((retCode) => retCode.endCode !== code.code);
}
else {
// This is a start code. Remove codes it "overrides", then add it.
// If a new code has the same endCode, it "overrides" existing ones.
// Special case: Intensity codes (1m, 2m) can coexist (both end with 22m).
// We only add those if the exact same code is not already present.
if (isIntensityCode(code)) {
if (!ret.find((retCode) => retCode.code === code.code && retCode.endCode === code.endCode)) {
ret.push(code);
}
}
else {
ret = ret.filter((retCode) => retCode.endCode !== code.endCode);
ret.push(code);
}
}
}
return ret;
}
//# sourceMappingURL=reduce.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"reduce.js","sourceRoot":"","sources":["../src/reduce.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAG9D,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,KAAiB;IAChD,OAAO,0BAA0B,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,+IAA+I;AAC/I,MAAM,UAAU,0BAA0B,CAAC,KAAiB,EAAE,QAAoB;IACjF,IAAI,GAAG,GAAe,CAAC,GAAG,KAAK,CAAC,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE;YACxC,gCAAgC;YAChC,GAAG,GAAG,EAAE,CAAC;SACT;aAAM,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtC,wDAAwD;YACxD,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;SAC7D;aAAM;YACN,kEAAkE;YAClE,oEAAoE;YACpE,0EAA0E;YAC1E,mEAAmE;YACnE,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;gBAC1B,IACC,CAAC,GAAG,CAAC,IAAI,CACR,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAC3E,EACA;oBACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACf;aACD;iBAAM;gBACN,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC;gBAChE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACf;SACD;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}

View File

@@ -0,0 +1,6 @@
import type { AnsiCode, Char, Token } from "./tokenize.js";
export interface StyledChar extends Char {
styles: AnsiCode[];
}
export declare function styledCharsFromTokens(tokens: Token[]): StyledChar[];
export declare function styledCharsToString(chars: StyledChar[]): string;

View File

@@ -0,0 +1,38 @@
import { ansiCodesToString } from "./ansiCodes.js";
import { diffAnsiCodes } from "./diff.js";
import { reduceAnsiCodesIncremental } from "./reduce.js";
export function styledCharsFromTokens(tokens) {
let codes = [];
const ret = [];
for (const token of tokens) {
if (token.type === "ansi") {
codes = reduceAnsiCodesIncremental(codes, [token]);
}
else if (token.type === "char") {
ret.push({
...token,
styles: [...codes],
});
}
}
return ret;
}
export function styledCharsToString(chars) {
let ret = "";
for (let i = 0; i < chars.length; i++) {
const char = chars[i];
if (i === 0) {
ret += ansiCodesToString(char.styles);
}
else {
ret += ansiCodesToString(diffAnsiCodes(chars[i - 1].styles, char.styles));
}
ret += char.value;
// reset active styles at the end of the string
if (i === chars.length - 1) {
ret += ansiCodesToString(diffAnsiCodes(char.styles, []));
}
}
return ret;
}
//# sourceMappingURL=styledChars.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"styledChars.js","sourceRoot":"","sources":["../src/styledChars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAOzD,MAAM,UAAU,qBAAqB,CAAC,MAAe;IACpD,IAAI,KAAK,GAAe,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;YAC1B,KAAK,GAAG,0BAA0B,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;SACnD;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;YACjC,GAAG,CAAC,IAAI,CAAC;gBACR,GAAG,KAAK;gBACR,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;aAClB,CAAC,CAAC;SACH;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAmB;IACtD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,EAAE;YACZ,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACtC;aAAM;YACN,GAAG,IAAI,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SAC1E;QACD,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;QAClB,+CAA+C;QAC/C,IAAI,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,GAAG,IAAI,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;SACzD;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}

View File

@@ -0,0 +1,16 @@
export interface AnsiCode {
type: "ansi";
code: string;
endCode: string;
}
export interface ControlCode {
type: "control";
code: string;
}
export interface Char {
type: "char";
value: string;
fullWidth: boolean;
}
export type Token = AnsiCode | ControlCode | Char;
export declare function tokenize(str: string, endChar?: number): Token[];

View File

@@ -0,0 +1,194 @@
import isFullwidthCodePoint from "is-fullwidth-code-point";
import { getEndCode } from "./ansiCodes.js";
import { CC_0, CC_9, CC_BEL, CC_BACKSLASH, CC_C1_ST, CC_ESC, CC_M, CC_CSI, CC_OSC, CC_SEMI, ESCAPES, linkCodePrefix, linkCodePrefixCharCodes, } from "./consts.js";
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
function isFullwidthGrapheme(grapheme, baseCodePoint) {
if (isFullwidthCodePoint(baseCodePoint))
return true;
// Variation Selector 16 forces emoji presentation (2 columns wide)
if (grapheme.includes("\uFE0F"))
return true;
// Regional indicator pairs form flag emoji (2 columns wide)
if (baseCodePoint >= 0x1f1e6 && baseCodePoint <= 0x1f1ff)
return true;
return false;
}
// HOT PATH: Use only basic string/char code operations for maximum performance
function parseLinkCode(string, offset) {
string = string.slice(offset);
for (let index = 1; index < linkCodePrefixCharCodes.length; index++) {
if (string.charCodeAt(index) !== linkCodePrefixCharCodes[index]) {
return undefined;
}
}
// Find the semicolon that ends params
const paramsEndIndex = string.indexOf(";", linkCodePrefix.length);
if (paramsEndIndex === -1)
return undefined;
// This is a link code (with or without the URL part). Find the end of it.
const endIndex = findOSCTerminatorIndex(string, paramsEndIndex + 1);
if (endIndex === -1)
return undefined;
return string.slice(0, endIndex + 1);
}
// HOT PATH: Generic fallback for non-link OSC sequences (window title, notifications, etc.)
function parseOSCSequence(string, offset) {
string = string.slice(offset);
// Find the OSC terminator (starting after "ESC ]")
const endIndex = findOSCTerminatorIndex(string, 2);
if (endIndex === -1)
return undefined;
return string.slice(0, endIndex + 1);
}
/**
* Finds the index of the last character of the first OSC terminator at or after startIndex.
* Recognizes BEL (\x07), C1 ST (\x9C), and ESC+backslash (\x1B\x5C).
* Returns -1 if no terminator is found.
*/
function findOSCTerminatorIndex(string, startIndex) {
for (let i = startIndex; i < string.length; i++) {
const ch = string.charCodeAt(i);
if (ch === CC_BEL)
return i;
if (ch === CC_C1_ST)
return i;
if (ch === CC_ESC && i + 1 < string.length && string.charCodeAt(i + 1) === CC_BACKSLASH) {
return i + 1;
}
}
return -1;
}
/**
* Scans through the given string and finds the index of the last character of an SGR sequence
* like `\x1B[38;2;123;123;123m`. This assumes that the string has been checked to start with `\x1B[`.
* Returns -1 if no valid SGR sequence is found.
*/
function findSGRSequenceEndIndex(str) {
for (let index = 2; index < str.length; index++) {
const charCode = str.charCodeAt(index);
// m marks the end of the SGR sequence
if (charCode === CC_M)
return index;
// Digits and semicolons are valid
if (charCode === CC_SEMI)
continue;
if (charCode >= CC_0 && charCode <= CC_9)
continue;
// Everything else is invalid
break;
}
return -1;
}
// HOT PATH: Use only basic string/char code operations for maximum performance
function parseSGRSequence(string, offset) {
string = string.slice(offset);
const endIndex = findSGRSequenceEndIndex(string);
if (endIndex === -1)
return;
return string.slice(0, endIndex + 1);
}
/**
* Splits compound SGR sequences like `\x1B[1;3;31m` into individual components
*/
function splitCompoundSGRSequences(code) {
if (!code.includes(";")) {
// Not a compound code
return [code];
}
const codeParts = code
// Strip off the escape sequences \x1B[ and m
.slice(2, -1)
.split(";");
const ret = [];
for (let i = 0; i < codeParts.length; i++) {
const rawCode = codeParts[i];
// Keep 8-bit and 24-bit color codes (containing multiple ";") together
if (rawCode === "38" || rawCode === "48") {
if (i + 2 < codeParts.length && codeParts[i + 1] === "5") {
// 8-bit color, followed by another number
ret.push(codeParts.slice(i, i + 3).join(";"));
i += 2;
continue;
}
else if (i + 4 < codeParts.length && codeParts[i + 1] === "2") {
// 24-bit color, followed by three numbers
ret.push(codeParts.slice(i, i + 5).join(";"));
i += 4;
continue;
}
}
// Not a (valid) 8/24-bit color code, push as is
ret.push(rawCode);
}
return ret.map((part) => `\x1b[${part}m`);
}
export function tokenize(str, endChar = Number.POSITIVE_INFINITY) {
const ret = [];
let visible = 0;
let codeEndIndex = 0;
for (const { segment, index } of segmenter.segment(str)) {
// Skip segments consumed as part of an ANSI sequence
if (index < codeEndIndex)
continue;
const codePoint = segment.codePointAt(0);
if (ESCAPES.has(codePoint)) {
let code;
// Peek the next code point to determine the type of ANSI sequence
const nextCodePoint = str.codePointAt(index + 1);
if (nextCodePoint === CC_OSC) {
// ] = operating system commands
code = parseLinkCode(str, index);
if (code) {
// OSC 8 hyperlinks are paired codes with an endCode
ret.push({
type: "ansi",
code: code,
endCode: getEndCode(code),
});
}
else {
// Other OSC sequences (window title, etc.) are self-contained
// control codes with no endCode.
code = parseOSCSequence(str, index);
if (code) {
ret.push({
type: "control",
code: code,
});
}
}
}
else if (nextCodePoint === CC_CSI) {
// [ = control sequence introducer, like SGR sequences [...m
code = parseSGRSequence(str, index);
if (code) {
// Split compound codes into individual tokens
const codes = splitCompoundSGRSequences(code);
for (const individualCode of codes) {
ret.push({
type: "ansi",
code: individualCode,
endCode: getEndCode(individualCode),
});
}
}
}
if (code) {
codeEndIndex = index + code.length;
continue;
}
}
const fullWidth = isFullwidthGrapheme(segment, codePoint);
ret.push({
type: "char",
value: segment,
fullWidth,
});
visible += fullWidth ? 2 : 1;
if (visible >= endChar) {
break;
}
}
return ret;
}
//# sourceMappingURL=tokenize.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
import type { AnsiCode } from "./tokenize.js";
/** Returns the combination of ANSI codes needed to undo the given ANSI codes */
export declare function undoAnsiCodes(codes: AnsiCode[]): AnsiCode[];

View File

@@ -0,0 +1,11 @@
import { reduceAnsiCodes } from "./reduce.js";
/** Returns the combination of ANSI codes needed to undo the given ANSI codes */
export function undoAnsiCodes(codes) {
return reduceAnsiCodes(codes)
.reverse()
.map((code) => ({
...code,
code: code.endCode,
}));
}
//# sourceMappingURL=undo.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"undo.js","sourceRoot":"","sources":["../src/undo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC9C,OAAO,eAAe,CAAC,KAAK,CAAC;SAC3B,OAAO,EAAE;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACf,GAAG,IAAI;QACP,IAAI,EAAE,IAAI,CAAC,OAAO;KAClB,CAAC,CAAC,CAAC;AACN,CAAC"}

View File

@@ -0,0 +1,55 @@
{
"name": "@alcalzone/ansi-tokenize",
"version": "0.3.0",
"description": "Efficiently modify strings containing ANSI escape codes",
"publishConfig": {
"access": "public"
},
"author": {
"name": "AlCalzone",
"email": "d.griesel@gmx.net"
},
"license": "MIT",
"type": "module",
"module": "build/index.js",
"types": "build/index.d.ts",
"exports": {
".": {
"types": "./build/index.d.ts",
"import": "./build/index.js"
},
"./package.json": "./package.json"
},
"files": [
"build"
],
"engines": {
"node": ">=18"
},
"devDependencies": {
"@alcalzone/release-script": "~4.0.0",
"@alcalzone/release-script-plugin-license": "~4.0.0",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^18.19.130",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.4",
"typescript": "^5.0.2",
"vitest": "^3.2.4"
},
"dependencies": {
"ansi-styles": "^6.2.1",
"is-fullwidth-code-point": "^5.0.0"
},
"scripts": {
"prepare": "tsc -p tsconfig.build.json",
"build": "tsc -p tsconfig.build.json",
"test": "vitest run",
"lint": "eslint .",
"release": "release-script"
},
"packageManager": "yarn@4.10.3"
}

View File

@@ -0,0 +1 @@
/home/uroma2/zcode-cli-x/~/.npm-cache/@anthropic-ai/bedrock-sdk@0.26.4@@@1

View File

@@ -0,0 +1,3 @@
<svg width="248" height="248" viewBox="0 0 248 248" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M52.4285 162.873L98.7844 136.879L99.5485 134.602L98.7844 133.334H96.4921L88.7237 132.862L62.2346 132.153L39.3113 131.207L17.0249 130.026L11.4214 128.844L6.2 121.873L6.7094 118.447L11.4214 115.257L18.171 115.847L33.0711 116.911L55.485 118.447L71.6586 119.392L95.728 121.873H99.5485L100.058 120.337L98.7844 119.392L97.7656 118.447L74.5877 102.732L49.4995 86.1905L36.3823 76.62L29.3779 71.7757L25.8121 67.2858L24.2839 57.3608L30.6515 50.2716L39.3113 50.8623L41.4763 51.4531L50.2636 58.1879L68.9842 72.7209L93.4357 90.6804L97.0015 93.6343L98.4374 92.6652L98.6571 91.9801L97.0015 89.2625L83.757 65.2772L69.621 40.8192L63.2534 30.6579L61.5978 24.632C60.9565 22.1032 60.579 20.0111 60.579 17.4246L67.8381 7.49965L71.9133 6.19995L81.7193 7.49965L85.7946 11.0443L91.9074 24.9865L101.714 46.8451L116.996 76.62L121.453 85.4816L123.873 93.6343L124.764 96.1155H126.292V94.6976L127.566 77.9197L129.858 57.3608L132.15 30.8942L132.915 23.4505L136.608 14.4708L143.994 9.62643L149.725 12.344L154.437 19.0788L153.8 23.4505L150.998 41.6463L145.522 70.1215L141.957 89.2625H143.994L146.414 86.7813L156.093 74.0206L172.266 53.698L179.398 45.6635L187.803 36.802L193.152 32.5484H203.34L210.726 43.6549L207.415 55.1159L196.972 68.3492L188.312 79.5739L175.896 96.2095L168.191 109.585L168.882 110.689L170.738 110.53L198.755 104.504L213.91 101.787L231.994 98.7149L240.144 102.496L241.036 106.395L237.852 114.311L218.495 119.037L195.826 123.645L162.07 131.592L161.696 131.893L162.137 132.547L177.36 133.925L183.855 134.279H199.774L229.447 136.524L237.215 141.605L241.8 147.867L241.036 152.711L229.065 158.737L213.019 154.956L175.45 145.977L162.587 142.787H160.805V143.85L171.502 154.366L191.242 172.089L215.82 195.011L217.094 200.682L213.91 205.172L210.599 204.699L188.949 188.394L180.544 181.069L161.696 165.118H160.422V166.772L164.752 173.152L187.803 207.771L188.949 218.405L187.294 221.832L181.308 223.959L174.813 222.777L161.187 203.754L147.305 182.486L136.098 163.345L134.745 164.2L128.075 235.42L125.019 239.082L117.887 241.8L111.902 237.31L108.718 229.984L111.902 215.452L115.722 196.547L118.779 181.541L121.58 162.873L123.291 156.636L123.14 156.219L121.773 156.449L107.699 175.752L86.304 204.699L69.3663 222.777L65.291 224.431L58.2867 220.768L58.9235 214.27L62.8713 208.48L86.304 178.705L100.44 160.155L109.551 149.507L109.462 147.967L108.959 147.924L46.6977 188.512L35.6182 189.93L30.7788 185.44L31.4156 178.115L33.7079 175.752L52.4285 162.873Z" fill="#D97757"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,7 @@
import { EventStreamSerdeContext as __EventStreamSerdeContext, SerdeContext as __SerdeContext } from '@smithy/types';
import { ResponseStream } from '@aws-sdk/client-bedrock-runtime';
/**
* deserializeAws_restJson1ResponseStream
*/
export declare const de_ResponseStream: (output: any, context: __SerdeContext & __EventStreamSerdeContext) => AsyncIterable<ResponseStream>;
//# sourceMappingURL=AWS_restJson1.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AWS_restJson1.d.mts","sourceRoot":"","sources":["src/AWS_restJson1.ts"],"names":[],"mappings":"OAaO,EACL,uBAAuB,IAAI,yBAAyB,EAEpD,YAAY,IAAI,cAAc,EAC/B,MAAM,eAAe;OAEf,EAIL,cAAc,EAGf,MAAM,iCAAiC;AAoFxC;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,GAAG,EACX,SAAS,cAAc,GAAG,yBAAyB,KAClD,aAAa,CAAC,cAAc,CAmC9B,CAAC"}

View File

@@ -0,0 +1,7 @@
import { EventStreamSerdeContext as __EventStreamSerdeContext, SerdeContext as __SerdeContext } from '@smithy/types';
import { ResponseStream } from '@aws-sdk/client-bedrock-runtime';
/**
* deserializeAws_restJson1ResponseStream
*/
export declare const de_ResponseStream: (output: any, context: __SerdeContext & __EventStreamSerdeContext) => AsyncIterable<ResponseStream>;
//# sourceMappingURL=AWS_restJson1.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AWS_restJson1.d.ts","sourceRoot":"","sources":["src/AWS_restJson1.ts"],"names":[],"mappings":"OAaO,EACL,uBAAuB,IAAI,yBAAyB,EAEpD,YAAY,IAAI,cAAc,EAC/B,MAAM,eAAe;OAEf,EAIL,cAAc,EAGf,MAAM,iCAAiC;AAoFxC;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,GAAG,EACX,SAAS,cAAc,GAAG,yBAAyB,KAClD,aAAa,CAAC,cAAc,CAmC9B,CAAC"}

View File

@@ -0,0 +1,167 @@
"use strict";
// Copied from https://github.com/aws/aws-sdk-js-v3/blob/bee66fbd2a519a16b57c787b2689af857af720af/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts
// Modified to remove unnecessary code (we only need to call `de_ResponseStream`) and to adjust imports.
Object.defineProperty(exports, "__esModule", { value: true });
exports.de_ResponseStream = void 0;
const smithy_client_1 = require("@smithy/smithy-client");
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
/**
* deserializeAws_restJson1InternalServerExceptionRes
*/
const de_InternalServerExceptionRes = async (parsedOutput, context) => {
const contents = (0, smithy_client_1.map)({});
const data = parsedOutput.body;
const doc = (0, smithy_client_1.take)(data, {
message: smithy_client_1.expectString,
});
Object.assign(contents, doc);
const exception = new client_bedrock_runtime_1.InternalServerException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ModelStreamErrorExceptionRes
*/
const de_ModelStreamErrorExceptionRes = async (parsedOutput, context) => {
const contents = (0, smithy_client_1.map)({});
const data = parsedOutput.body;
const doc = (0, smithy_client_1.take)(data, {
message: smithy_client_1.expectString,
originalMessage: smithy_client_1.expectString,
originalStatusCode: smithy_client_1.expectInt32,
});
Object.assign(contents, doc);
const exception = new client_bedrock_runtime_1.ModelStreamErrorException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ThrottlingExceptionRes
*/
const de_ThrottlingExceptionRes = async (parsedOutput, context) => {
const contents = (0, smithy_client_1.map)({});
const data = parsedOutput.body;
const doc = (0, smithy_client_1.take)(data, {
message: smithy_client_1.expectString,
});
Object.assign(contents, doc);
const exception = new client_bedrock_runtime_1.ThrottlingException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ValidationExceptionRes
*/
const de_ValidationExceptionRes = async (parsedOutput, context) => {
const contents = (0, smithy_client_1.map)({});
const data = parsedOutput.body;
const doc = (0, smithy_client_1.take)(data, {
message: smithy_client_1.expectString,
});
Object.assign(contents, doc);
const exception = new client_bedrock_runtime_1.ValidationException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ResponseStream
*/
const de_ResponseStream = (output, context) => {
return context.eventStreamMarshaller.deserialize(output, async (event) => {
if (event['chunk'] != null) {
return {
chunk: await de_PayloadPart_event(event['chunk'], context),
};
}
if (event['internalServerException'] != null) {
return {
internalServerException: await de_InternalServerException_event(event['internalServerException'], context),
};
}
if (event['modelStreamErrorException'] != null) {
return {
modelStreamErrorException: await de_ModelStreamErrorException_event(event['modelStreamErrorException'], context),
};
}
if (event['validationException'] != null) {
return {
validationException: await de_ValidationException_event(event['validationException'], context),
};
}
if (event['throttlingException'] != null) {
return {
throttlingException: await de_ThrottlingException_event(event['throttlingException'], context),
};
}
return { $unknown: output };
});
};
exports.de_ResponseStream = de_ResponseStream;
const de_InternalServerException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_InternalServerExceptionRes(parsedOutput, context);
};
const de_ModelStreamErrorException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ModelStreamErrorExceptionRes(parsedOutput, context);
};
const de_PayloadPart_event = async (output, context) => {
const contents = {};
const data = await parseBody(output.body, context);
Object.assign(contents, de_PayloadPart(data, context));
return contents;
};
const de_ThrottlingException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ThrottlingExceptionRes(parsedOutput, context);
};
const de_ValidationException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ValidationExceptionRes(parsedOutput, context);
};
/**
* deserializeAws_restJson1PayloadPart
*/
const de_PayloadPart = (output, context) => {
return (0, smithy_client_1.take)(output, {
bytes: context.base64Decoder,
});
};
const deserializeMetadata = (output) => ({
httpStatusCode: output.statusCode,
requestId: output.headers['x-amzn-requestid'] ??
output.headers['x-amzn-request-id'] ??
output.headers['x-amz-request-id'] ??
'',
extendedRequestId: output.headers['x-amz-id-2'] ?? '',
cfId: output.headers['x-amz-cf-id'] ?? '',
});
// Encode Uint8Array data into string with utf-8.
const collectBodyString = (streamBody, context) => (0, smithy_client_1.collectBody)(streamBody, context).then((body) => context.utf8Encoder(body));
const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});
//# sourceMappingURL=AWS_restJson1.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,163 @@
// Copied from https://github.com/aws/aws-sdk-js-v3/blob/bee66fbd2a519a16b57c787b2689af857af720af/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts
// Modified to remove unnecessary code (we only need to call `de_ResponseStream`) and to adjust imports.
import { collectBody, decorateServiceException as __decorateServiceException, expectInt32 as __expectInt32, expectString as __expectString, map, take, } from '@smithy/smithy-client';
import { InternalServerException, ModelStreamErrorException, ThrottlingException, ValidationException, } from '@aws-sdk/client-bedrock-runtime';
/**
* deserializeAws_restJson1InternalServerExceptionRes
*/
const de_InternalServerExceptionRes = async (parsedOutput, context) => {
const contents = map({});
const data = parsedOutput.body;
const doc = take(data, {
message: __expectString,
});
Object.assign(contents, doc);
const exception = new InternalServerException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return __decorateServiceException(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ModelStreamErrorExceptionRes
*/
const de_ModelStreamErrorExceptionRes = async (parsedOutput, context) => {
const contents = map({});
const data = parsedOutput.body;
const doc = take(data, {
message: __expectString,
originalMessage: __expectString,
originalStatusCode: __expectInt32,
});
Object.assign(contents, doc);
const exception = new ModelStreamErrorException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return __decorateServiceException(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ThrottlingExceptionRes
*/
const de_ThrottlingExceptionRes = async (parsedOutput, context) => {
const contents = map({});
const data = parsedOutput.body;
const doc = take(data, {
message: __expectString,
});
Object.assign(contents, doc);
const exception = new ThrottlingException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return __decorateServiceException(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ValidationExceptionRes
*/
const de_ValidationExceptionRes = async (parsedOutput, context) => {
const contents = map({});
const data = parsedOutput.body;
const doc = take(data, {
message: __expectString,
});
Object.assign(contents, doc);
const exception = new ValidationException({
$metadata: deserializeMetadata(parsedOutput),
...contents,
});
return __decorateServiceException(exception, parsedOutput.body);
};
/**
* deserializeAws_restJson1ResponseStream
*/
export const de_ResponseStream = (output, context) => {
return context.eventStreamMarshaller.deserialize(output, async (event) => {
if (event['chunk'] != null) {
return {
chunk: await de_PayloadPart_event(event['chunk'], context),
};
}
if (event['internalServerException'] != null) {
return {
internalServerException: await de_InternalServerException_event(event['internalServerException'], context),
};
}
if (event['modelStreamErrorException'] != null) {
return {
modelStreamErrorException: await de_ModelStreamErrorException_event(event['modelStreamErrorException'], context),
};
}
if (event['validationException'] != null) {
return {
validationException: await de_ValidationException_event(event['validationException'], context),
};
}
if (event['throttlingException'] != null) {
return {
throttlingException: await de_ThrottlingException_event(event['throttlingException'], context),
};
}
return { $unknown: output };
});
};
const de_InternalServerException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_InternalServerExceptionRes(parsedOutput, context);
};
const de_ModelStreamErrorException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ModelStreamErrorExceptionRes(parsedOutput, context);
};
const de_PayloadPart_event = async (output, context) => {
const contents = {};
const data = await parseBody(output.body, context);
Object.assign(contents, de_PayloadPart(data, context));
return contents;
};
const de_ThrottlingException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ThrottlingExceptionRes(parsedOutput, context);
};
const de_ValidationException_event = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
return de_ValidationExceptionRes(parsedOutput, context);
};
/**
* deserializeAws_restJson1PayloadPart
*/
const de_PayloadPart = (output, context) => {
return take(output, {
bytes: context.base64Decoder,
});
};
const deserializeMetadata = (output) => ({
httpStatusCode: output.statusCode,
requestId: output.headers['x-amzn-requestid'] ??
output.headers['x-amzn-request-id'] ??
output.headers['x-amz-request-id'] ??
'',
extendedRequestId: output.headers['x-amz-id-2'] ?? '',
cfId: output.headers['x-amz-cf-id'] ?? '',
});
// Encode Uint8Array data into string with utf-8.
const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
}
return {};
});
//# sourceMappingURL=AWS_restJson1.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,637 @@
# Changelog
## 0.26.4 (2026-02-19)
Full Changelog: [bedrock-sdk-v0.26.3...bedrock-sdk-v0.26.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.26.3...bedrock-sdk-v0.26.4)
### Bug Fixes
* **bedrock:** eliminate race condition in AWS credential resolution ([#901](https://github.com/anthropics/anthropic-sdk-typescript/issues/901)) ([e5a101d](https://github.com/anthropics/anthropic-sdk-typescript/commit/e5a101d060cdce65872ec787e792c94799dcc295))
## 0.26.3 (2026-02-05)
Full Changelog: [bedrock-sdk-v0.26.2...bedrock-sdk-v0.26.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.26.2...bedrock-sdk-v0.26.3)
### Bug Fixes
* **client:** avoid memory leak with abort signals ([53e47df](https://github.com/anthropics/anthropic-sdk-typescript/commit/53e47dfa6985e6a206c475b8c920b8a97c27e17e))
## 0.26.2 (2026-01-29)
Full Changelog: [bedrock-sdk-v0.26.1...bedrock-sdk-v0.26.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.26.1...bedrock-sdk-v0.26.2)
### Chores
* **internal:** version bump ([24ecc83](https://github.com/anthropics/anthropic-sdk-typescript/commit/24ecc838b0adbb837b14fe24fac0895d81ea8891))
### Documentation
* update README with Claude branding ([#611](https://github.com/anthropics/anthropic-sdk-typescript/issues/611)) ([2a9a5f7](https://github.com/anthropics/anthropic-sdk-typescript/commit/2a9a5f7f94d2fe807bcc73aa6a3a92f8e50db763))
## 0.26.1 (2025-11-24)
Full Changelog: [bedrock-sdk-v0.26.0...bedrock-sdk-v0.26.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.26.0...bedrock-sdk-v0.26.1)
### Chores
* include publishConfig in all package.json files ([4c72960](https://github.com/anthropics/anthropic-sdk-typescript/commit/4c72960c5f494317d3f88816b941ffa103bf24d5))
## 0.26.0 (2025-11-14)
Full Changelog: [bedrock-sdk-v0.25.0...bedrock-sdk-v0.26.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.25.0...bedrock-sdk-v0.26.0)
### Features
* **api:** add support for structured outputs beta ([e6562d7](https://github.com/anthropics/anthropic-sdk-typescript/commit/e6562d72502030e6cf90a31192b21b23c0b03422))
## 0.25.0 (2025-09-17)
Full Changelog: [bedrock-sdk-v0.24.0...bedrock-sdk-v0.25.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.24.0...bedrock-sdk-v0.25.0)
### Features
* **client:** add support for toolRunner helpers ([28f5837](https://github.com/anthropics/anthropic-sdk-typescript/commit/28f583739d4f15c202ecc88002cd8abc9d3aed76))
## 0.24.0 (2025-08-05)
Full Changelog: [bedrock-sdk-v0.23.0...bedrock-sdk-v0.24.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.23.0...bedrock-sdk-v0.24.0)
### Features
* **api:** removed older deprecated models ([352a5fd](https://github.com/anthropics/anthropic-sdk-typescript/commit/352a5fd17372ac37277a2f001122973537579968))
### Chores
* **internal:** version bump ([eb97e85](https://github.com/anthropics/anthropic-sdk-typescript/commit/eb97e8577279fb150582297d2a0924a297185c3c))
## 0.23.0 (2025-07-21)
Full Changelog: [bedrock-sdk-v0.22.4...bedrock-sdk-v0.23.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.22.4...bedrock-sdk-v0.23.0)
### Features
* **bedrock:** better edge runtime support ([#462](https://github.com/anthropics/anthropic-sdk-typescript/issues/462)) ([5f8d1bb](https://github.com/anthropics/anthropic-sdk-typescript/commit/5f8d1bb6a1e7a71acf7a89a090bb2296c050e1d2))
### Bug Fixes
* **bedrock:** fix lint errors ([aa40e9c](https://github.com/anthropics/anthropic-sdk-typescript/commit/aa40e9c6987a23ca964683a72fb89c9f570528bd))
## 0.22.4 (2025-07-03)
Full Changelog: [bedrock-sdk-v0.22.3...bedrock-sdk-v0.22.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.22.3...bedrock-sdk-v0.22.4)
### Bug Fixes
* **bedrock:** fix bedrock logger ([f183bc9](https://github.com/anthropics/anthropic-sdk-typescript/commit/f183bc97bc5a83b0e00053740caa387a1c98c322))
## 0.22.3 (2025-06-30)
Full Changelog: [bedrock-sdk-v0.22.2...bedrock-sdk-v0.22.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.22.2...bedrock-sdk-v0.22.3)
### Bug Fixes
* **client:** use proxy in bedrock when requesting credentials from AWS ([8cfd227](https://github.com/anthropics/anthropic-sdk-typescript/commit/8cfd227dd82686101ea54d5d32a0c1d6ad04d336))
## 0.22.2 (2025-06-24)
Full Changelog: [bedrock-sdk-v0.22.1...bedrock-sdk-v0.22.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.22.1...bedrock-sdk-v0.22.2)
## 0.22.1 (2025-05-22)
Full Changelog: [bedrock-sdk-v0.22.0...bedrock-sdk-v0.22.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.22.0...bedrock-sdk-v0.22.1)
### Chores
* **internal:** version bump ([8ebaf61](https://github.com/anthropics/anthropic-sdk-typescript/commit/8ebaf616d2e5c6aebc153f19a403dde41ab5a9f1))
## 0.22.0 (2025-05-15)
Full Changelog: [bedrock-sdk-v0.21.2...bedrock-sdk-v0.22.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.21.2...bedrock-sdk-v0.22.0)
### Features
* **bedrock:** support skipAuth on Bedrock client to bypass local auth requirements ([b661c5f](https://github.com/anthropics/anthropic-sdk-typescript/commit/b661c5fe4d93fa749de5b7cbbce98dc224a68adc))
### Bug Fixes
* **bedrock:** support model names with slashes ([cb5fa8a](https://github.com/anthropics/anthropic-sdk-typescript/commit/cb5fa8a8f55ed12382aeb5f09110b0d5fefc46bb))
## 0.21.2 (2025-05-09)
Full Changelog: [bedrock-sdk-v0.21.1...bedrock-sdk-v0.21.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.21.1...bedrock-sdk-v0.21.2)
### Bug Fixes
* **client:** always overwrite when merging headers ([657912a](https://github.com/anthropics/anthropic-sdk-typescript/commit/657912ad66f86e878291a4cab5436844efbb633b))
## 0.21.1 (2025-05-09)
Full Changelog: [bedrock-sdk-v0.21.0...bedrock-sdk-v0.21.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.21.0...bedrock-sdk-v0.21.1)
### Chores
* sync repo ([508e385](https://github.com/anthropics/anthropic-sdk-typescript/commit/508e38511c13ba8842065d0dafbc7f462abe0322))
## 0.21.0 (2025-05-09)
Full Changelog: [bedrock-sdk-v0.20.0...bedrock-sdk-v0.21.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.20.0...bedrock-sdk-v0.21.0)
### Features
* **bedrock:** add beta.messages.create() method ([faf8484](https://github.com/anthropics/anthropic-sdk-typescript/commit/faf84848e42ec02994003283bf6178aa55233531))
### Bug Fixes
* **bedrock,vertex:** update to new SDK version ([cb620bb](https://github.com/anthropics/anthropic-sdk-typescript/commit/cb620bbb60e64f27168f74db7a48ad8c2d5f953e))
* **bedrock:** correct messages beta handling ([f34d67a](https://github.com/anthropics/anthropic-sdk-typescript/commit/f34d67abca1270f04f9bbf6ce430ce67b36d4932))
* **bedrock:** don't mutate request body inputs ([4523ca9](https://github.com/anthropics/anthropic-sdk-typescript/commit/4523ca92b0fa194c2de0ac8bbc7e66873ec5e817))
* **bedrock:** update streaming util import ([01d03bf](https://github.com/anthropics/anthropic-sdk-typescript/commit/01d03bf79615de601f8bb9284df818e7d066aafa))
* **streaming:** handle more AbortError cases ([521d6cd](https://github.com/anthropics/anthropic-sdk-typescript/commit/521d6cda1c43bad9b0ef110809e0d3e7cd411a0d))
* **vertex,bedrock:** correct build script ([df895a7](https://github.com/anthropics/anthropic-sdk-typescript/commit/df895a7d7cbd51422343fca95ab9f1d58918b2a1))
### Chores
* **bedrock,vertex:** remove unsupported countTokens method ([#597](https://github.com/anthropics/anthropic-sdk-typescript/issues/597)) ([6f6db16](https://github.com/anthropics/anthropic-sdk-typescript/commit/6f6db164d2526c2fb272151f4d68140da27ce1ea))
* **bedrock:** add `skipAuth` option to allow users to let authorization be handled elsewhere ([ee58772](https://github.com/anthropics/anthropic-sdk-typescript/commit/ee587723718109797efa80b020076c43a300f1b9))
* **bedrock:** bump [@aws-sdk](https://github.com/aws-sdk) dependencies ([ff925db](https://github.com/anthropics/anthropic-sdk-typescript/commit/ff925db987a66950c997ec50b9c55e67152d1945))
* **bedrock:** bump [@aws-sdk](https://github.com/aws-sdk) dependencies ([9891107](https://github.com/anthropics/anthropic-sdk-typescript/commit/98911074a745bfefe29f26c725bf54b6e228c93c))
* **bedrock:** bump @aws-sdk/credential-providers ([9f611d6](https://github.com/anthropics/anthropic-sdk-typescript/commit/9f611d6ba8c6b3de02c3183e4f2f42d1540525f0))
* **bedrock:** bump @aws-sdk/credential-providers ([491646e](https://github.com/anthropics/anthropic-sdk-typescript/commit/491646e10a48a09c0828d0fb23908f43f38d8e6a))
* **bedrock:** bump dependency on @anthropic-ai/sdk ([2d0d4b6](https://github.com/anthropics/anthropic-sdk-typescript/commit/2d0d4b61368286581e281b604e005fc81139b6b9))
* **bedrock:** remove unsupported methods ([8bb04ed](https://github.com/anthropics/anthropic-sdk-typescript/commit/8bb04ed2370c894b080d56d37e960ad4c3dc5925))
* **internal:** migrate to eslint v9 ([1141664](https://github.com/anthropics/anthropic-sdk-typescript/commit/114166498a54e0b62cd9ea071fc736d714cefde6))
### Documentation
* use latest sonnet in example snippets ([#625](https://github.com/anthropics/anthropic-sdk-typescript/issues/625)) ([a965791](https://github.com/anthropics/anthropic-sdk-typescript/commit/a9657918aaf1246609105cbafaf4bb043b146356))
## 0.20.0 (2025-05-09)
Full Changelog: [bedrock-sdk-v0.12.6...bedrock-sdk-v0.12.7](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.6...bedrock-sdk-v0.12.7)
### Bug Fixes
* **bedrock,vertex:** update to new SDK version ([cb620bb](https://github.com/anthropics/anthropic-sdk-typescript/commit/cb620bbb60e64f27168f74db7a48ad8c2d5f953e))
* **vertex,bedrock:** correct build script ([df895a7](https://github.com/anthropics/anthropic-sdk-typescript/commit/df895a7d7cbd51422343fca95ab9f1d58918b2a1))
### Chores
* **bedrock:** add `skipAuth` option to allow users to let authorization be handled elsewhere ([ee58772](https://github.com/anthropics/anthropic-sdk-typescript/commit/ee587723718109797efa80b020076c43a300f1b9))
* **bedrock:** bump [@aws-sdk](https://github.com/aws-sdk) dependencies ([ff925db](https://github.com/anthropics/anthropic-sdk-typescript/commit/ff925db987a66950c997ec50b9c55e67152d1945))
* **bedrock:** bump @aws-sdk/credential-providers ([9f611d6](https://github.com/anthropics/anthropic-sdk-typescript/commit/9f611d6ba8c6b3de02c3183e4f2f42d1540525f0))
## 0.12.6 (2025-04-28)
Full Changelog: [bedrock-sdk-v0.12.5...bedrock-sdk-v0.12.6](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.5...bedrock-sdk-v0.12.6)
### Chores
* **bedrock:** bump [@aws-sdk](https://github.com/aws-sdk) dependencies ([6440e1d](https://github.com/anthropics/anthropic-sdk-typescript/commit/6440e1db992779aeead231b420a55002ec0991d1))
## 0.12.5 (2025-04-25)
Full Changelog: [bedrock-sdk-v0.12.4...bedrock-sdk-v0.12.5](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.4...bedrock-sdk-v0.12.5)
### Chores
* **bedrock:** bump @aws-sdk/credential-providers ([a4d88d7](https://github.com/anthropics/anthropic-sdk-typescript/commit/a4d88d7807e2cf1a0836dc05d9deff5bfc0c665f))
## 0.12.4 (2025-01-23)
Full Changelog: [bedrock-sdk-v0.12.3...bedrock-sdk-v0.12.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.3...bedrock-sdk-v0.12.4)
### Bug Fixes
* **bedrock:** update streaming util import ([255c059](https://github.com/anthropics/anthropic-sdk-typescript/commit/255c0599e333e6fae582255e3b0631538b168c69))
## 0.12.3 (2025-01-23)
Full Changelog: [bedrock-sdk-v0.12.2...bedrock-sdk-v0.12.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.2...bedrock-sdk-v0.12.3)
### Chores
* **bedrock:** bump dependency on @anthropic-ai/sdk ([8745ca2](https://github.com/anthropics/anthropic-sdk-typescript/commit/8745ca2160f5af4d89e5732a44e560c5e2787aa8))
## 0.12.2 (2025-01-21)
Full Changelog: [bedrock-sdk-v0.12.1...bedrock-sdk-v0.12.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.1...bedrock-sdk-v0.12.2)
### Chores
* **internal:** temporary revert commit ([#643](https://github.com/anthropics/anthropic-sdk-typescript/issues/643)) ([43dd43c](https://github.com/anthropics/anthropic-sdk-typescript/commit/43dd43c4c8ab69d5a60e59473af7dff5f7799048))
## 0.12.1 (2024-12-20)
Full Changelog: [bedrock-sdk-v0.12.0...bedrock-sdk-v0.12.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.12.0...bedrock-sdk-v0.12.1)
### Chores
* **internal:** temporary revert commit ([#643](https://github.com/anthropics/anthropic-sdk-typescript/issues/643)) ([8057b1e](https://github.com/anthropics/anthropic-sdk-typescript/commit/8057b1eb67ccccee042a45f2efe53cccced15682))
## 0.12.0 (2024-12-17)
Full Changelog: [bedrock-sdk-v0.11.2...bedrock-sdk-v0.12.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.11.2...bedrock-sdk-v0.12.0)
### Features
* **api:** general availability updates ([#631](https://github.com/anthropics/anthropic-sdk-typescript/issues/631)) ([b5c92e5](https://github.com/anthropics/anthropic-sdk-typescript/commit/b5c92e5b74c370ac3f9ba28e915bd54588a42be0))
### Chores
* **bedrock,vertex:** remove unsupported countTokens method ([#597](https://github.com/anthropics/anthropic-sdk-typescript/issues/597)) ([17b7da5](https://github.com/anthropics/anthropic-sdk-typescript/commit/17b7da5ee6f35ea2bdd53a66a662871affae6341))
* **bedrock:** remove unsupported methods ([6458dc1](https://github.com/anthropics/anthropic-sdk-typescript/commit/6458dc14544c16240a6580a21a36fcf5bde594b2))
### Documentation
* use latest sonnet in example snippets ([#625](https://github.com/anthropics/anthropic-sdk-typescript/issues/625)) ([f70882b](https://github.com/anthropics/anthropic-sdk-typescript/commit/f70882b0e8119a414b01b9f0b85fbe1ccb06f122))
## 0.11.2 (2024-11-05)
Full Changelog: [bedrock-sdk-v0.11.1...bedrock-sdk-v0.11.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.11.1...bedrock-sdk-v0.11.2)
### Bug Fixes
* **bedrock:** don't mutate request body inputs ([f83b535](https://github.com/anthropics/anthropic-sdk-typescript/commit/f83b53520262219229cecc388f95d92be83c09d5))
## 0.11.1 (2024-10-23)
Full Changelog: [bedrock-sdk-v0.11.0...bedrock-sdk-v0.11.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.11.0...bedrock-sdk-v0.11.1)
### Bug Fixes
* **bedrock:** correct messages beta handling ([9b57586](https://github.com/anthropics/anthropic-sdk-typescript/commit/9b57586456221f8900902b8e85c7c017959c150a))
## 0.11.0 (2024-10-22)
Full Changelog: [bedrock-sdk-v0.10.4...bedrock-sdk-v0.11.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.10.4...bedrock-sdk-v0.11.0)
### Features
* **bedrock:** add beta.messages.create() method ([6317592](https://github.com/anthropics/anthropic-sdk-typescript/commit/63175920a016a2ad187dd1127d263357cf6c007e))
## 0.10.4 (2024-10-08)
Full Changelog: [bedrock-sdk-v0.10.3...bedrock-sdk-v0.10.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.10.3...bedrock-sdk-v0.10.4)
### Refactors
* **types:** improve metadata type names ([#547](https://github.com/anthropics/anthropic-sdk-typescript/issues/547)) ([cef499c](https://github.com/anthropics/anthropic-sdk-typescript/commit/cef499cf3b01643f7e5e3c09524f49e198b940be))
## 0.10.3 (2024-10-04)
Full Changelog: [bedrock-sdk-v0.10.2...bedrock-sdk-v0.10.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.10.2...bedrock-sdk-v0.10.3)
### Chores
* better object fallback behaviour for casting errors ([#526](https://github.com/anthropics/anthropic-sdk-typescript/issues/526)) ([4ffb2e4](https://github.com/anthropics/anthropic-sdk-typescript/commit/4ffb2e4e1f5fef3ae58d9f4c99a63e75dd459c5b))
## 0.10.2 (2024-07-29)
Full Changelog: [bedrock-sdk-v0.10.1...bedrock-sdk-v0.10.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.10.1...bedrock-sdk-v0.10.2)
### Chores
* **bedrock:** use `chunk` for internal SSE parsing instead of `completion` ([#472](https://github.com/anthropics/anthropic-sdk-typescript/issues/472)) ([0f6190a](https://github.com/anthropics/anthropic-sdk-typescript/commit/0f6190a69d8986ac3779441eba43d345ec3fb342))
* **docs:** rename anthropic const to client ([#471](https://github.com/anthropics/anthropic-sdk-typescript/issues/471)) ([e1a7f9f](https://github.com/anthropics/anthropic-sdk-typescript/commit/e1a7f9f813077fb033c732c004c7bda85738a321))
* **internal:** remove old reference to check-test-server ([8dc9afc](https://github.com/anthropics/anthropic-sdk-typescript/commit/8dc9afcf00c4a38c2d85171ebceafc5f6a47c117))
## 0.10.1 (2024-06-25)
Full Changelog: [bedrock-sdk-v0.10.0...bedrock-sdk-v0.10.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.10.0...bedrock-sdk-v0.10.1)
### Chores
* **internal:** replace deprecated aws-sdk packages with [@smithy](https://github.com/smithy) ([#447](https://github.com/anthropics/anthropic-sdk-typescript/issues/447)) ([4328cbf](https://github.com/anthropics/anthropic-sdk-typescript/commit/4328cbf9e64f8bfc9b95a9048b18729c9a938ba5))
## 0.10.0 (2024-05-30)
Full Changelog: [bedrock-sdk-v0.9.8...bedrock-sdk-v0.10.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.8...bedrock-sdk-v0.10.0)
### Features
* **bedrock:** support tools ([91fc61a](https://github.com/anthropics/anthropic-sdk-typescript/commit/91fc61ae7246705d26e96a95dae38b46e9ad9290))
## 0.9.8 (2024-05-16)
Full Changelog: [bedrock-sdk-v0.9.7...bedrock-sdk-v0.9.8](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.7...bedrock-sdk-v0.9.8)
### Chores
* **internal:** fix generated version numbers ([#413](https://github.com/anthropics/anthropic-sdk-typescript/issues/413)) ([ea77063](https://github.com/anthropics/anthropic-sdk-typescript/commit/ea770630897bb85caaecd39bccf478e4dd3f169c))
## 0.9.7 (2024-05-07)
Full Changelog: [bedrock-sdk-v0.9.6...bedrock-sdk-v0.9.7](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.6...bedrock-sdk-v0.9.7)
### Chores
* **internal:** refactor scripts ([#404](https://github.com/anthropics/anthropic-sdk-typescript/issues/404)) ([f60e2d8](https://github.com/anthropics/anthropic-sdk-typescript/commit/f60e2d81bb241063507d2d7e728c78e78c1c5e51))
## 0.9.6 (2024-04-09)
Full Changelog: [bedrock-sdk-v0.9.5...bedrock-sdk-v0.9.6](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.5...bedrock-sdk-v0.9.6)
### Chores
* **internal:** update lock files ([#377](https://github.com/anthropics/anthropic-sdk-typescript/issues/377)) ([6d239ef](https://github.com/anthropics/anthropic-sdk-typescript/commit/6d239efaca730baba374a1b49f6b1a4037b3e163))
## 0.9.5 (2024-04-04)
Full Changelog: [bedrock-sdk-v0.9.4...bedrock-sdk-v0.9.5](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.4...bedrock-sdk-v0.9.5)
### Documentation
* **readme:** mention tool use ([#375](https://github.com/anthropics/anthropic-sdk-typescript/issues/375)) ([72356dd](https://github.com/anthropics/anthropic-sdk-typescript/commit/72356dd9c498344074c292ffdab602d54c4fa13e))
## 0.9.4 (2024-04-04)
Full Changelog: [bedrock-sdk-v0.9.3...bedrock-sdk-v0.9.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.3...bedrock-sdk-v0.9.4)
### Bug Fixes
* **types:** correctly mark type as a required property in requests ([#371](https://github.com/anthropics/anthropic-sdk-typescript/issues/371)) ([a04edd8](https://github.com/anthropics/anthropic-sdk-typescript/commit/a04edd8d7f4c552281b37a44099edf432d7fcb27))
## 0.9.3 (2024-04-04)
Full Changelog: [bedrock-sdk-v0.9.2...bedrock-sdk-v0.9.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.2...bedrock-sdk-v0.9.3)
### Chores
* **deps:** remove unused dependency digest-fetch ([#368](https://github.com/anthropics/anthropic-sdk-typescript/issues/368)) ([df1df0f](https://github.com/anthropics/anthropic-sdk-typescript/commit/df1df0f509682841c703fa1ea5062a796cfe2091))
## 0.9.2 (2024-03-29)
Full Changelog: [bedrock-sdk-v0.9.1...bedrock-sdk-v0.9.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.1...bedrock-sdk-v0.9.2)
### Documentation
* **bedrock:** fix dead link ([#356](https://github.com/anthropics/anthropic-sdk-typescript/issues/356)) ([a953e00](https://github.com/anthropics/anthropic-sdk-typescript/commit/a953e0070698f3238b728ffe06a056a9f2d6b7ff))
## 0.9.1 (2024-03-06)
Full Changelog: [bedrock-sdk-v0.9.0...bedrock-sdk-v0.9.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.9.0...bedrock-sdk-v0.9.1)
### Documentation
* remove extraneous --save and yarn install instructions ([#323](https://github.com/anthropics/anthropic-sdk-typescript/issues/323)) ([775ecb9](https://github.com/anthropics/anthropic-sdk-typescript/commit/775ecb9ef3ab17e88dabc149faa0876cd6ab5f0b))
## 0.9.0 (2024-03-04)
Full Changelog: [bedrock-sdk-v0.8.0...bedrock-sdk-v0.9.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.8.0...bedrock-sdk-v0.9.0)
### Features
* **bedrock:** add messages API ([#305](https://github.com/anthropics/anthropic-sdk-typescript/issues/305)) ([8b7f89e](https://github.com/anthropics/anthropic-sdk-typescript/commit/8b7f89e1e60416f9ad5b575d43238a4259654395))
## 0.8.0 (2024-03-04)
Full Changelog: [bedrock-sdk-v0.7.1...bedrock-sdk-v0.8.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.7.1...bedrock-sdk-v0.8.0)
### Features
* **messages:** add support for image inputs ([#303](https://github.com/anthropics/anthropic-sdk-typescript/issues/303)) ([7663bd6](https://github.com/anthropics/anthropic-sdk-typescript/commit/7663bd6e1a4427483cf5f13889bc5c63314e5bae))
## 0.7.1 (2024-01-31)
Full Changelog: [bedrock-sdk-v0.7.0...bedrock-sdk-v0.7.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/bedrock-sdk-v0.7.0...bedrock-sdk-v0.7.1)
### Chores
* **bedrock:** move bedrock SDK to the main repo ([#274](https://github.com/anthropics/anthropic-sdk-typescript/issues/274)) ([1a565fe](https://github.com/anthropics/anthropic-sdk-typescript/commit/1a565feddd19c3dbe62f087fc9f13520bb69fc0e))
* release main ([6679340](https://github.com/anthropics/anthropic-sdk-typescript/commit/6679340c68b7f1599e5a9a543371f7426f96307a))
## 0.7.0 (2024-01-31)
This release restructures the SDK so that it relies on the main `@anthropic-ai/sdk` instead of duplicating everything.
- All subpath imports are broken, e.g. `import { Completion } from '@anthropic-ai/bedrock-sdk/resources/completions'`
- Types are no longer exported through the default import, e.g. `AnthropicBedrock.Completion`
- e.g. AnthropicBedrock.APIError, AnthropicBedrock.HUMAN_PROMPT
However, these are all an straightforward fixes, you just have to replace `@anthropic-ai/bedrock-sdk` with `@anthropic-ai/sdk`, e.g.
```diff
- import AnthropicBedrock from '@anthropic-ai/bedrock-sdk';
+ import Anthropic from '@anthropic-ai/sdk';
- type Completion = AnthropicBedrock.Completion;
+ type Completion = Anthropic.Completion;
```
## 0.6.5 (2024-01-30)
Full Changelog: [v0.6.4...v0.6.5](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.6.4...v0.6.5)
### Chores
* **internal:** support pre-release versioning ([#77](https://github.com/anthropics/anthropic-bedrock-typescript/issues/77)) ([b96f745](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b96f745cf406677a552c863b2c5ee967f3353919))
## 0.6.4 (2024-01-25)
Full Changelog: [v0.6.3...v0.6.4](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.6.3...v0.6.4)
### Chores
* **internal:** add internal helpers & improve build scripts ([#73](https://github.com/anthropics/anthropic-bedrock-typescript/issues/73)) ([d12b655](https://github.com/anthropics/anthropic-bedrock-typescript/commit/d12b655286e3677e4a24a5616bb633b553fa5784))
* **internal:** don't re-export streaming type ([#76](https://github.com/anthropics/anthropic-bedrock-typescript/issues/76)) ([92fb967](https://github.com/anthropics/anthropic-bedrock-typescript/commit/92fb967c40d8c730441fc3b42bef92bc478436aa))
* **internal:** minor streaming updates ([#75](https://github.com/anthropics/anthropic-bedrock-typescript/issues/75)) ([73bac4c](https://github.com/anthropics/anthropic-bedrock-typescript/commit/73bac4c4f2f6edc4b7a72274cd3146c5821b53a8))
## 0.6.3 (2024-01-19)
Full Changelog: [v0.6.2...v0.6.3](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.6.2...v0.6.3)
### Bug Fixes
* allow body type in RequestOptions to be null ([#71](https://github.com/anthropics/anthropic-bedrock-typescript/issues/71)) ([a04f753](https://github.com/anthropics/anthropic-bedrock-typescript/commit/a04f7538e789324cebcea61476c1d745bbfc30cf))
## 0.6.2 (2024-01-18)
Full Changelog: [v0.6.1...v0.6.2](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.6.1...v0.6.2)
### Bug Fixes
* **ci:** ignore stainless-app edits to release PR title ([#70](https://github.com/anthropics/anthropic-bedrock-typescript/issues/70)) ([c3a058c](https://github.com/anthropics/anthropic-bedrock-typescript/commit/c3a058cccfdc0f0db1fbf06c57c13374bad58015))
* **headers:** always send lowercase headers and strip undefined (BREAKING in rare cases) ([#60](https://github.com/anthropics/anthropic-bedrock-typescript/issues/60)) ([9cc4518](https://github.com/anthropics/anthropic-bedrock-typescript/commit/9cc4518ebd41d6ee438e686f4d0da2629e511796))
* **types:** accept undefined for optional client options ([#69](https://github.com/anthropics/anthropic-bedrock-typescript/issues/69)) ([cf597f6](https://github.com/anthropics/anthropic-bedrock-typescript/commit/cf597f6384337109011cd7d920b6a6530cdef74f))
* use default base url if BASE_URL env var is blank ([#64](https://github.com/anthropics/anthropic-bedrock-typescript/issues/64)) ([134bf8f](https://github.com/anthropics/anthropic-bedrock-typescript/commit/134bf8f35d6071224280c9bed6151e107fee3c93))
### Chores
* add .keep files for examples and custom code directories ([#63](https://github.com/anthropics/anthropic-bedrock-typescript/issues/63)) ([0064f30](https://github.com/anthropics/anthropic-bedrock-typescript/commit/0064f3035cf4a11645c632abf1e026ee27ac92a2))
* **internal:** debug logging for retries; speculative retry-after-ms support ([#68](https://github.com/anthropics/anthropic-bedrock-typescript/issues/68)) ([e6a95f6](https://github.com/anthropics/anthropic-bedrock-typescript/commit/e6a95f644a300c5e3d5856edcaf98c60c953e461))
* **internal:** improve type signatures ([#62](https://github.com/anthropics/anthropic-bedrock-typescript/issues/62)) ([6e24bdc](https://github.com/anthropics/anthropic-bedrock-typescript/commit/6e24bdc7ee82252243c0f83c68c5b6a363d756fc))
* **internal:** narrow type into stringifyQuery ([#65](https://github.com/anthropics/anthropic-bedrock-typescript/issues/65)) ([443febf](https://github.com/anthropics/anthropic-bedrock-typescript/commit/443febf02c4c71b28934a776da0198fdd094de8f))
### Documentation
* fix missing async in readme code sample ([#67](https://github.com/anthropics/anthropic-bedrock-typescript/issues/67)) ([a6d20eb](https://github.com/anthropics/anthropic-bedrock-typescript/commit/a6d20eb8d3d4c6be9d92afd4eb7d93ea5c661094))
* **readme:** improve api reference ([#66](https://github.com/anthropics/anthropic-bedrock-typescript/issues/66)) ([f90bbaf](https://github.com/anthropics/anthropic-bedrock-typescript/commit/f90bbaf631e9ac34fb613a43ece1f489d82f04b8))
## 0.6.1 (2023-12-20)
Full Changelog: [v0.6.0...v0.6.1](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.6.0...v0.6.1)
### Chores
* **ci:** run release workflow once per day ([#54](https://github.com/anthropics/anthropic-bedrock-typescript/issues/54)) ([b5072dd](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b5072ddc0c068737cdca2dd6ecfcb231ac7edc1b))
* **deps:** update dependency ts-jest to v29.1.1 ([#55](https://github.com/anthropics/anthropic-bedrock-typescript/issues/55)) ([946a832](https://github.com/anthropics/anthropic-bedrock-typescript/commit/946a8326410b47143f2c9e611e6b62866d5d9734))
* **deps:** update jest ([#56](https://github.com/anthropics/anthropic-bedrock-typescript/issues/56)) ([492232d](https://github.com/anthropics/anthropic-bedrock-typescript/commit/492232de92f7d79b42869ca619cc85ae4a1b7966))
* **internal:** update test examples ([#50](https://github.com/anthropics/anthropic-bedrock-typescript/issues/50)) ([33132ea](https://github.com/anthropics/anthropic-bedrock-typescript/commit/33132eaab93f2fa39cc9e975df0b0323bb486395))
* update dependencies ([#53](https://github.com/anthropics/anthropic-bedrock-typescript/issues/53)) ([4a72bd7](https://github.com/anthropics/anthropic-bedrock-typescript/commit/4a72bd7f857a7024ff0e8caf574e92998431f4f3))
* update prettier ([#52](https://github.com/anthropics/anthropic-bedrock-typescript/issues/52)) ([acfe9e4](https://github.com/anthropics/anthropic-bedrock-typescript/commit/acfe9e46299275fc14c9a704c7c048c87e0e33db))
### Documentation
* reformat README.md ([#58](https://github.com/anthropics/anthropic-bedrock-typescript/issues/58)) ([050b328](https://github.com/anthropics/anthropic-bedrock-typescript/commit/050b328725d37f5a0876704b5754953967495ada))
### Refactors
* write jest config in typescript ([#57](https://github.com/anthropics/anthropic-bedrock-typescript/issues/57)) ([bbaa155](https://github.com/anthropics/anthropic-bedrock-typescript/commit/bbaa155e6377283a12258a470d4d10da3d9ebe54))
### Build System
* specify `packageManager: yarn` ([#51](https://github.com/anthropics/anthropic-bedrock-typescript/issues/51)) ([59453e5](https://github.com/anthropics/anthropic-bedrock-typescript/commit/59453e581ad770fb1d12a7458774d7427d0b90de))
## 0.6.0 (2023-12-06)
Full Changelog: [v0.5.2...v0.6.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.5.2...v0.6.0)
### Features
* **client:** support reading the base url from an env variable ([#43](https://github.com/anthropics/anthropic-bedrock-typescript/issues/43)) ([783e9a1](https://github.com/anthropics/anthropic-bedrock-typescript/commit/783e9a1c6bacbc18028ee5e052758103e7c89453))
### Bug Fixes
* bump default request timeout to 10min to match documentation ([#47](https://github.com/anthropics/anthropic-bedrock-typescript/issues/47)) ([16d2d96](https://github.com/anthropics/anthropic-bedrock-typescript/commit/16d2d960dfb8076bb41d769a35aeaec564177238))
## 0.5.2 (2023-11-28)
Full Changelog: [v0.5.1...v0.5.2](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.5.1...v0.5.2)
## 0.5.1 (2023-11-24)
Full Changelog: [v0.5.0...v0.5.1](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.5.0...v0.5.1)
### Chores
* **internal:** remove file import and conditionally run prepare ([#39](https://github.com/anthropics/anthropic-bedrock-typescript/issues/39)) ([546295e](https://github.com/anthropics/anthropic-bedrock-typescript/commit/546295e63e5d0c373f7f84d36b98cf8094c2c5c8))
## 0.5.0 (2023-11-21)
Full Changelog: [v0.4.1...v0.5.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.4.1...v0.5.0)
### Features
* allow installing package directly from github ([#37](https://github.com/anthropics/anthropic-bedrock-typescript/issues/37)) ([758b62f](https://github.com/anthropics/anthropic-bedrock-typescript/commit/758b62f86b7d62229f9f41c931c03eebc16d03fc))
### Chores
* **ci:** fix publish-npm ([#35](https://github.com/anthropics/anthropic-bedrock-typescript/issues/35)) ([03ca66d](https://github.com/anthropics/anthropic-bedrock-typescript/commit/03ca66d6a9b9d7fcc7f930c62535d162e46917ea))
* **internal:** don't call prepare in dist ([#38](https://github.com/anthropics/anthropic-bedrock-typescript/issues/38)) ([21038f6](https://github.com/anthropics/anthropic-bedrock-typescript/commit/21038f62cf3dafda7cf9f79d5694bd2e89392bc6))
## 0.4.1 (2023-11-14)
Full Changelog: [v0.4.0...v0.4.1](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.4.0...v0.4.1)
### Chores
* **ci:** update release-please config ([#29](https://github.com/anthropics/anthropic-bedrock-typescript/issues/29)) ([9f932f7](https://github.com/anthropics/anthropic-bedrock-typescript/commit/9f932f7091d3c0a31c650d326c7669ee90c534ee))
* **docs:** fix github links ([#31](https://github.com/anthropics/anthropic-bedrock-typescript/issues/31)) ([8c433fd](https://github.com/anthropics/anthropic-bedrock-typescript/commit/8c433fdde7c618afc7b5ecd32c85eb06dd0f048b))
* **internal:** update APIResource structure ([#34](https://github.com/anthropics/anthropic-bedrock-typescript/issues/34)) ([c85a2e3](https://github.com/anthropics/anthropic-bedrock-typescript/commit/c85a2e3bfa8d95ea2d7444d32ba884984b7e61e7))
* **internal:** update jest config ([#33](https://github.com/anthropics/anthropic-bedrock-typescript/issues/33)) ([a46da67](https://github.com/anthropics/anthropic-bedrock-typescript/commit/a46da679e8f40600fa37c0de3a90c633b78356eb))
* **internal:** update tsconfig ([#32](https://github.com/anthropics/anthropic-bedrock-typescript/issues/32)) ([b9295df](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b9295dff2a3aa721f057d64dfc41eaf7d6bd0f6c))
## 0.4.0 (2023-11-04)
Full Changelog: [v0.3.0...v0.4.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.3.0...v0.4.0)
### Features
* **client:** allow binary returns ([#27](https://github.com/anthropics/anthropic-bedrock-typescript/issues/27)) ([d9e84a1](https://github.com/anthropics/anthropic-bedrock-typescript/commit/d9e84a1f8d25d43f3eb256723bfb89cf0d354453))
* **github:** include a devcontainer setup ([#26](https://github.com/anthropics/anthropic-bedrock-typescript/issues/26)) ([c37cf14](https://github.com/anthropics/anthropic-bedrock-typescript/commit/c37cf14409464bceeacb97cb6f8e098a1bfefd2d))
### Chores
* **internal:** update gitignore ([#22](https://github.com/anthropics/anthropic-bedrock-typescript/issues/22)) ([d448991](https://github.com/anthropics/anthropic-bedrock-typescript/commit/d448991a6f24c0a50f686380957473bfa2cd13b7))
* small cleanups ([#25](https://github.com/anthropics/anthropic-bedrock-typescript/issues/25)) ([d18cfcb](https://github.com/anthropics/anthropic-bedrock-typescript/commit/d18cfcb28428ca944b423ea515d046720553c28d))
### Documentation
* document customizing fetch ([#28](https://github.com/anthropics/anthropic-bedrock-typescript/issues/28)) ([878bd1b](https://github.com/anthropics/anthropic-bedrock-typescript/commit/878bd1b240dc319e3ab37b7e8b4fe96eb155688a))
* fix github links ([#24](https://github.com/anthropics/anthropic-bedrock-typescript/issues/24)) ([9560ba7](https://github.com/anthropics/anthropic-bedrock-typescript/commit/9560ba7c165d373a23d77d8d14a864845e2dc721))
## 0.3.0 (2023-10-25)
Full Changelog: [v0.2.0...v0.3.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.2.0...v0.3.0)
### Features
* **client:** adjust retry behavior to be exponential backoff ([#18](https://github.com/anthropics/anthropic-bedrock-typescript/issues/18)) ([51d3a6e](https://github.com/anthropics/anthropic-bedrock-typescript/commit/51d3a6e8ab71ba935bd71b497d83df1896835199))
### Bug Fixes
* typo in build script ([#21](https://github.com/anthropics/anthropic-bedrock-typescript/issues/21)) ([b86502d](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b86502d913b2d607c49db9fc1c5656d2a089e7a9))
## 0.2.0 (2023-10-19)
Full Changelog: [v0.1.2...v0.2.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.1.2...v0.2.0)
### Features
* handle 204 No Content gracefully ([#17](https://github.com/anthropics/anthropic-bedrock-typescript/issues/17)) ([f11420b](https://github.com/anthropics/anthropic-bedrock-typescript/commit/f11420b2a9e2b9a127194bd811708f9f010447b5))
## 0.1.2 (2023-10-17)
Full Changelog: [v0.1.1...v0.1.2](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.1.1...v0.1.2)
### Bug Fixes
* import web-streams-polyfill without overriding globals ([#13](https://github.com/anthropics/anthropic-bedrock-typescript/issues/13)) ([30db709](https://github.com/anthropics/anthropic-bedrock-typescript/commit/30db7098fea0154c8dcb484bfee2ed5c4ec946aa))
## 0.1.1 (2023-10-16)
Full Changelog: [v0.1.0...v0.1.1](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.1.0...v0.1.1)
### Bug Fixes
* improve status code in error messages ([#9](https://github.com/anthropics/anthropic-bedrock-typescript/issues/9)) ([aa3f1b0](https://github.com/anthropics/anthropic-bedrock-typescript/commit/aa3f1b01ee5d9161c793f3f263fc5b297d1d1258))
### Chores
* add case insensitive get header function ([#4](https://github.com/anthropics/anthropic-bedrock-typescript/issues/4)) ([b7309b1](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b7309b10201e048f726993c70bbf075f6927cabe))
* **internal:** add debug logs for stream responses ([#8](https://github.com/anthropics/anthropic-bedrock-typescript/issues/8)) ([b8763a7](https://github.com/anthropics/anthropic-bedrock-typescript/commit/b8763a73376e2a1ddb9073b649d4aacfad27bf69))
* update comment ([#6](https://github.com/anthropics/anthropic-bedrock-typescript/issues/6)) ([7361f09](https://github.com/anthropics/anthropic-bedrock-typescript/commit/7361f09aa5430d8dcd8193dc599ea9fa75d17e4e))
### Documentation
* organisation -&gt; organization (UK to US English) ([#11](https://github.com/anthropics/anthropic-bedrock-typescript/issues/11)) ([5cbea8e](https://github.com/anthropics/anthropic-bedrock-typescript/commit/5cbea8e9ef936b314617765d7bc2dbb2c3d98eac))
## 0.1.0 (2023-10-12)
Full Changelog: [v0.0.1...v0.1.0](https://github.com/anthropics/anthropic-bedrock-typescript/compare/v0.0.1...v0.1.0)
### Features
* **init:** initial commit ([#1](https://github.com/anthropics/anthropic-bedrock-typescript/issues/1)) ([17f9073](https://github.com/anthropics/anthropic-bedrock-typescript/commit/17f9073f1545f9f578e67c56f827322a7691ca21))

View File

@@ -0,0 +1,8 @@
Copyright 2023 Anthropic, PBC.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,87 @@
# <img src=".github/logo.svg" alt="" width="32"> Claude SDK for AWS Bedrock
[![NPM version](https://img.shields.io/npm/v/@anthropic-ai/bedrock-sdk.svg?color=blue)](https://npmjs.org/package/@anthropic-ai/bedrock-sdk)
This library provides convenient access to the Claude API via AWS Bedrock. See the [documentation](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock) for more details.
For the direct Claude API at api.anthropic.com, see [`@anthropic-ai/sdk`](https://github.com/anthropics/anthropic-sdk-typescript).
## Installation
```sh
npm install @anthropic-ai/bedrock-sdk
```
## Usage
<!-- prettier-ignore -->
```js
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
// Note: this assumes you have configured AWS credentials in a way
// that the AWS Node SDK will recognise, typicaly a shared `~/.aws/credentials`
// file or `AWS_ACCESS_KEY_ID` & `AWS_SECRET_ACCESS_KEY` environment variables.
//
// https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
const client = new AnthropicBedrock();
async function main() {
const message = await client.messages.create({
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
messages: [
{
role: 'user',
content: 'Hello!',
},
],
max_tokens: 1024,
});
console.log(message);
}
main();
```
### Custom Credential Provider (for non-Node environments)
For non-Node environments like Vercel Edge Runtime where the default AWS credential provider chain isn't available, you can provide a custom credential resolver:
```js
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
const customCredentialProvider = async () => {
// Return an object that implements the AwsCredentialIdentityProvider interface
return {
accessKeyId: 'your-aws-access-key-id',
secretAccessKey: 'your-aws-secret-access-key',
sessionToken: 'your-aws-session-token', // Optional, if using temporary credentials
};
};
const client = new AnthropicBedrock({
awsRegion: 'us-east-1',
providerChainResolver: async () => {
return customCredentialProvider;
},
});
```
For more details on how to use the SDK, see the [README.md for the main Claude SDK](https://github.com/anthropics/anthropic-sdk-typescript/tree/main#readme) which this library extends.
## Requirements
TypeScript >= 4.5 is supported.
The following runtimes are supported:
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import { AnthropicBedrock } from "npm:@anthropic-ai/bedrock-sdk"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
- Nitro v2.6 or greater.
Note that React Native is not supported at this time.
If you are interested in other runtime environments, please open or upvote an issue on GitHub.

View File

@@ -0,0 +1,83 @@
import { BaseAnthropic, ClientOptions as CoreClientOptions } from '@anthropic-ai/sdk/client';
import * as Resources from '@anthropic-ai/sdk/resources/index';
import { AwsCredentialIdentityProvider } from '@smithy/types';
import { FinalRequestOptions } from "./internal/request-options.mjs";
import { FinalizedRequestInit } from "./internal/types.mjs";
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
export type ClientOptions = Omit<CoreClientOptions, 'apiKey' | 'authToken'> & {
awsSecretKey?: string | null | undefined;
awsAccessKey?: string | null | undefined;
/**
* Defaults to process.env['AWS_REGION'].
*/
awsRegion?: string | undefined;
awsSessionToken?: string | null | undefined;
skipAuth?: boolean;
/** Custom provider chain resolver for AWS credentials. Useful for non-Node environments, like edge workers, where the default credential provider chain may not work. */
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
};
type BothStaticCreds = {
awsAccessKey: string;
awsSecretKey: string;
awsSessionToken?: string | null | undefined;
};
type NoStaticCreds = {
awsAccessKey?: null | undefined;
awsSecretKey?: null | undefined;
awsSessionToken?: null | undefined;
};
type AccessOnly = {
awsAccessKey: string;
awsSecretKey?: null | undefined;
awsSessionToken?: string | null | undefined;
};
type SecretOnly = {
awsSecretKey: string;
awsAccessKey?: null | undefined;
awsSessionToken?: string | null | undefined;
};
/** API Client for interfacing with the Anthropic Bedrock API. */
export declare class AnthropicBedrock extends BaseAnthropic {
awsSecretKey: string | null;
awsAccessKey: string | null;
awsRegion: string;
awsSessionToken: string | null;
skipAuth: boolean;
providerChainResolver: (() => Promise<AwsCredentialIdentityProvider>) | null;
constructor(opts: ClientOptions & BothStaticCreds);
constructor(opts?: ClientOptions & NoStaticCreds);
/**
* @deprecated Passing only `awsAccessKey` without `awsSecretKey` is deprecated.
* Provide both keys, or provide neither and rely on the AWS credential provider chain.
*/
constructor(opts: ClientOptions & AccessOnly);
/**
* @deprecated Passing only `awsSecretKey` without `awsAccessKey` is deprecated.
* Provide both keys, or provide neither and rely on the AWS credential provider chain.
*/
constructor(opts: ClientOptions & SecretOnly);
messages: MessagesResource;
completions: Resources.Completions;
beta: BetaResource;
protected validateHeaders(): void;
protected prepareRequest(request: FinalizedRequestInit, { url, options }: {
url: string;
options: FinalRequestOptions;
}): Promise<void>;
buildRequest(options: FinalRequestOptions): Promise<{
req: FinalizedRequestInit;
url: string;
timeout: number;
}>;
}
/**
* The Bedrock API does not currently support token counting or the Batch API.
*/
type MessagesResource = Omit<Resources.Messages, 'batches' | 'countTokens'>;
/**
* The Bedrock API does not currently support prompt caching, token counting or the Batch API.
*/
type BetaResource = Omit<Resources.Beta, 'promptCaching' | 'messages'> & {
messages: Omit<Resources.Beta['messages'], 'batches' | 'countTokens'>;
};
//# sourceMappingURL=client.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"client.d.mts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,EAAE,aAAa,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,0BAA0B;OACrF,KAAK,SAAS,MAAM,mCAAmC;OACvD,EAAE,6BAA6B,EAAE,MAAM,eAAe;OAItD,EAAE,mBAAmB,EAAE;OAGvB,EAAE,oBAAoB,EAAE;OAIxB,EAAE,aAAa,EAAE,MAAM,0BAA0B;AAKxD,MAAM,MA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ACvE,CAAC"}

View File

@@ -0,0 +1,83 @@
import { BaseAnthropic, ClientOptions as CoreClientOptions } from '@anthropic-ai/sdk/client';
import * as Resources from '@anthropic-ai/sdk/resources/index';
import { AwsCredentialIdentityProvider } from '@smithy/types';
import { FinalRequestOptions } from "./internal/request-options.js";
import { FinalizedRequestInit } from "./internal/types.js";
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
export type ClientOptions = Omit<CoreClientOptions, 'apiKey' | 'authToken'> & {
awsSecretKey?: string | null | undefined;
awsAccessKey?: string | null | undefined;
/**
* Defaults to process.env['AWS_REGION'].
*/
awsRegion?: string | undefined;
awsSessionToken?: string | null | undefined;
skipAuth?: boolean;
/** Custom provider chain resolver for AWS credentials. Useful for non-Node environments, like edge workers, where the default credential provider chain may not work. */
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
};
type BothStaticCreds = {
awsAccessKey: string;
awsSecretKey: string;
awsSessionToken?: string | null | undefined;
};
type NoStaticCreds = {
awsAccessKey?: null | undefined;
awsSecretKey?: null | undefined;
awsSessionToken?: null | undefined;
};
type AccessOnly = {
awsAccessKey: string;
awsSecretKey?: null | undefined;
awsSessionToken?: string | null | undefined;
};
type SecretOnly = {
awsSecretKey: string;
awsAccessKey?: null | undefined;
awsSessionToken?: string | null | undefined;
};
/** API Client for interfacing with the Anthropic Bedrock API. */
export declare class AnthropicBedrock extends BaseAnthropic {
awsSecretKey: string | null;
awsAccessKey: string | null;
awsRegion: string;
awsSessionToken: string | null;
skipAuth: boolean;
providerChainResolver: (() => Promise<AwsCredentialIdentityProvider>) | null;
constructor(opts: ClientOptions & BothStaticCreds);
constructor(opts?: ClientOptions & NoStaticCreds);
/**
* @deprecated Passing only `awsAccessKey` without `awsSecretKey` is deprecated.
* Provide both keys, or provide neither and rely on the AWS credential provider chain.
*/
constructor(opts: ClientOptions & AccessOnly);
/**
* @deprecated Passing only `awsSecretKey` without `awsAccessKey` is deprecated.
* Provide both keys, or provide neither and rely on the AWS credential provider chain.
*/
constructor(opts: ClientOptions & SecretOnly);
messages: MessagesResource;
completions: Resources.Completions;
beta: BetaResource;
protected validateHeaders(): void;
protected prepareRequest(request: FinalizedRequestInit, { url, options }: {
url: string;
options: FinalRequestOptions;
}): Promise<void>;
buildRequest(options: FinalRequestOptions): Promise<{
req: FinalizedRequestInit;
url: string;
timeout: number;
}>;
}
/**
* The Bedrock API does not currently support token counting or the Batch API.
*/
type MessagesResource = Omit<Resources.Messages, 'batches' | 'countTokens'>;
/**
* The Bedrock API does not currently support prompt caching, token counting or the Batch API.
*/
type BetaResource = Omit<Resources.Beta, 'promptCaching' | 'messages'> & {
messages: Omit<Resources.Beta['messages'], 'batches' | 'countTokens'>;
};
//# sourceMappingURL=client.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,EAAE,aAAa,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,0BAA0B;OACrF,KAAK,SAAS,MAAM,mCAAmC;OACvD,EAAE,6BAA6B,EAAE,MAAM,eAAe;OAItD,EAAE,mBAAmB,EAAE;OAGvB,EAAE,oBAAoB,EAAE;OAIxB,EAAE,aAAa,EAAE,MAAM,0BAA0B;AAKxD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,WAAW,CAAC,GAAG;IAC5E,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAEzC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,yKAAyK;IACzK,qBAAqB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC,G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gD5C,QAAQ,EAAE,gBAAgB,CAA8B;IACxD,WAAW,EAAE,SAAS,CAAC,WAAW,CAAmC;IACrE,IAAI,EAAE,YAAY,CAA0B;cAEzB,eAAe;cAIT,cAAc,CACrC,OAAO,EAAE,oBAAoB,EAC7B,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAC9D,OAAO,CAAC,IAAI,CAAC;IAuBD,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC;QACjE,GAAG,EAAE,oBAAoB,CAAC;QAC1B,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CA0CH;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC;AAc5E;;GAEG;AACH,KAAK,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,CAAC,GAAG;IACvE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC;CACvE,CAAC"}

View File

@@ -0,0 +1,166 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnthropicBedrock = exports.BaseAnthropic = void 0;
const client_1 = require("@anthropic-ai/sdk/client");
const Resources = __importStar(require("@anthropic-ai/sdk/resources/index"));
const auth_1 = require("./core/auth.js");
const streaming_1 = require("./core/streaming.js");
const env_1 = require("./internal/utils/env.js");
const values_1 = require("./internal/utils/values.js");
const headers_1 = require("./internal/headers.js");
const path_1 = require("./internal/utils/path.js");
const log_1 = require("./internal/utils/log.js");
var client_2 = require("@anthropic-ai/sdk/client");
Object.defineProperty(exports, "BaseAnthropic", { enumerable: true, get: function () { return client_2.BaseAnthropic; } });
const DEFAULT_VERSION = 'bedrock-2023-05-31';
const MODEL_ENDPOINTS = new Set(['/v1/complete', '/v1/messages', '/v1/messages?beta=true']);
/** API Client for interfacing with the Anthropic Bedrock API. */
class AnthropicBedrock extends client_1.BaseAnthropic {
/**
* API Client for interfacing with the Anthropic Bedrock API.
*
* @param {string | null | undefined} [opts.awsSecretKey]
* @param {string | null | undefined} [opts.awsAccessKey]
* @param {string | undefined} [opts.awsRegion=process.env['AWS_REGION'] ?? us-east-1]
* @param {string | null | undefined} [opts.awsSessionToken]
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials. Useful for non-Node environments.
* @param {string} [opts.baseURL=process.env['ANTHROPIC_BEDROCK_BASE_URL'] ?? https://bedrock-runtime.${this.awsRegion}.amazonaws.com] - Override the default base URL for the API.
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
* @param {boolean} [opts.skipAuth=false] - Skip authentication for this request. This is useful if you have an internal proxy that handles authentication for you.
*/
constructor({ awsRegion = (0, env_1.readEnv)('AWS_REGION') ?? 'us-east-1', baseURL = (0, env_1.readEnv)('ANTHROPIC_BEDROCK_BASE_URL') ?? `https://bedrock-runtime.${awsRegion}.amazonaws.com`, awsSecretKey = null, awsAccessKey = null, awsSessionToken = null, providerChainResolver = null, ...opts } = {}) {
super({ baseURL, ...opts });
this.skipAuth = false;
this.messages = makeMessagesResource(this);
this.completions = new Resources.Completions(this);
this.beta = makeBetaResource(this);
const hasAccess = awsAccessKey != null;
const hasSecret = awsSecretKey != null;
if (hasAccess !== hasSecret) {
(0, log_1.loggerFor)(this).warn('Warning: Passing only one of `awsAccessKey` or `awsSecretKey` is deprecated. ' +
'Please provide both keys, or provide neither and rely on the AWS credential provider chain.');
}
this.awsSecretKey = awsSecretKey;
this.awsAccessKey = awsAccessKey;
this.awsRegion = awsRegion;
this.awsSessionToken = awsSessionToken;
this.skipAuth = opts.skipAuth ?? false;
this.providerChainResolver = providerChainResolver;
}
validateHeaders() {
// auth validation is handled in prepareRequest since it needs to be async
}
async prepareRequest(request, { url, options }) {
if (this.skipAuth) {
return;
}
const regionName = this.awsRegion;
if (!regionName) {
throw new Error('Expected `awsRegion` option to be passed to the client or the `AWS_REGION` environment variable to be present');
}
const headers = await (0, auth_1.getAuthHeaders)(request, {
url,
regionName,
awsAccessKey: this.awsAccessKey,
awsSecretKey: this.awsSecretKey,
awsSessionToken: this.awsSessionToken,
fetchOptions: this.fetchOptions,
providerChainResolver: this.providerChainResolver,
});
request.headers = (0, headers_1.buildHeaders)([headers, request.headers]).values;
}
async buildRequest(options) {
options.__streamClass = streaming_1.Stream;
if ((0, values_1.isObj)(options.body)) {
// create a shallow copy of the request body so that code that mutates it later
// doesn't mutate the original user-provided object
options.body = { ...options.body };
}
if ((0, values_1.isObj)(options.body)) {
if (!options.body['anthropic_version']) {
options.body['anthropic_version'] = DEFAULT_VERSION;
}
if (options.headers && !options.body['anthropic_beta']) {
const betas = (0, headers_1.buildHeaders)([options.headers]).values.get('anthropic-beta');
if (betas != null) {
options.body['anthropic_beta'] = betas.split(',');
}
}
}
if (MODEL_ENDPOINTS.has(options.path) && options.method === 'post') {
if (!(0, values_1.isObj)(options.body)) {
throw new Error('Expected request body to be an object for post /v1/messages');
}
const model = options.body['model'];
options.body['model'] = undefined;
const stream = options.body['stream'];
options.body['stream'] = undefined;
if (stream) {
options.path = (0, path_1.path) `/model/${model}/invoke-with-response-stream`;
}
else {
options.path = (0, path_1.path) `/model/${model}/invoke`;
}
}
return super.buildRequest(options);
}
}
exports.AnthropicBedrock = AnthropicBedrock;
function makeMessagesResource(client) {
const resource = new Resources.Messages(client);
// @ts-expect-error we're deleting non-optional properties
delete resource.batches;
// @ts-expect-error we're deleting non-optional properties
delete resource.countTokens;
return resource;
}
function makeBetaResource(client) {
const resource = new Resources.Beta(client);
// @ts-expect-error we're deleting non-optional properties
delete resource.promptCaching;
// @ts-expect-error we're deleting non-optional properties
delete resource.messages.batches;
// @ts-expect-error we're deleting non-optional properties
delete resource.messages.countTokens;
return resource;
}
//# sourceMappingURL=client.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"client.js","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA6F;AAC7F,6EAA+D;AAE/D,yCAA6C;AAC7C,m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,OAAO,CAAC,IAAI,GAAG,IAAA,WAAI,EAAA,UAAU,KAAK,SAAS,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF;AArJD,4CAqJC;AAOD,SAAS,oBAAoB,CAAC,MAAwB;IACpD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEhD,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,OAAO,CAAC;IAExB,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,WAAW,CAAC;IAE5B,OAAO,QAAQ,CAAC;AAClB,CAAC;AASD,SAAS,gBAAgB,CAAC,MAAwB;IAChD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,aAAa,CAAC;IAE9B,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;IAEjC,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC"}

View File

@@ -0,0 +1,128 @@
import { BaseAnthropic } from '@anthropic-ai/sdk/client';
import * as Resources from '@anthropic-ai/sdk/resources/index';
import { getAuthHeaders } from "./core/auth.mjs";
import { Stream } from "./core/streaming.mjs";
import { readEnv } from "./internal/utils/env.mjs";
import { isObj } from "./internal/utils/values.mjs";
import { buildHeaders } from "./internal/headers.mjs";
import { path } from "./internal/utils/path.mjs";
import { loggerFor } from "./internal/utils/log.mjs";
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
const DEFAULT_VERSION = 'bedrock-2023-05-31';
const MODEL_ENDPOINTS = new Set(['/v1/complete', '/v1/messages', '/v1/messages?beta=true']);
/** API Client for interfacing with the Anthropic Bedrock API. */
export class AnthropicBedrock extends BaseAnthropic {
/**
* API Client for interfacing with the Anthropic Bedrock API.
*
* @param {string | null | undefined} [opts.awsSecretKey]
* @param {string | null | undefined} [opts.awsAccessKey]
* @param {string | undefined} [opts.awsRegion=process.env['AWS_REGION'] ?? us-east-1]
* @param {string | null | undefined} [opts.awsSessionToken]
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials. Useful for non-Node environments.
* @param {string} [opts.baseURL=process.env['ANTHROPIC_BEDROCK_BASE_URL'] ?? https://bedrock-runtime.${this.awsRegion}.amazonaws.com] - Override the default base URL for the API.
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
* @param {boolean} [opts.skipAuth=false] - Skip authentication for this request. This is useful if you have an internal proxy that handles authentication for you.
*/
constructor({ awsRegion = readEnv('AWS_REGION') ?? 'us-east-1', baseURL = readEnv('ANTHROPIC_BEDROCK_BASE_URL') ?? `https://bedrock-runtime.${awsRegion}.amazonaws.com`, awsSecretKey = null, awsAccessKey = null, awsSessionToken = null, providerChainResolver = null, ...opts } = {}) {
super({ baseURL, ...opts });
this.skipAuth = false;
this.messages = makeMessagesResource(this);
this.completions = new Resources.Completions(this);
this.beta = makeBetaResource(this);
const hasAccess = awsAccessKey != null;
const hasSecret = awsSecretKey != null;
if (hasAccess !== hasSecret) {
loggerFor(this).warn('Warning: Passing only one of `awsAccessKey` or `awsSecretKey` is deprecated. ' +
'Please provide both keys, or provide neither and rely on the AWS credential provider chain.');
}
this.awsSecretKey = awsSecretKey;
this.awsAccessKey = awsAccessKey;
this.awsRegion = awsRegion;
this.awsSessionToken = awsSessionToken;
this.skipAuth = opts.skipAuth ?? false;
this.providerChainResolver = providerChainResolver;
}
validateHeaders() {
// auth validation is handled in prepareRequest since it needs to be async
}
async prepareRequest(request, { url, options }) {
if (this.skipAuth) {
return;
}
const regionName = this.awsRegion;
if (!regionName) {
throw new Error('Expected `awsRegion` option to be passed to the client or the `AWS_REGION` environment variable to be present');
}
const headers = await getAuthHeaders(request, {
url,
regionName,
awsAccessKey: this.awsAccessKey,
awsSecretKey: this.awsSecretKey,
awsSessionToken: this.awsSessionToken,
fetchOptions: this.fetchOptions,
providerChainResolver: this.providerChainResolver,
});
request.headers = buildHeaders([headers, request.headers]).values;
}
async buildRequest(options) {
options.__streamClass = Stream;
if (isObj(options.body)) {
// create a shallow copy of the request body so that code that mutates it later
// doesn't mutate the original user-provided object
options.body = { ...options.body };
}
if (isObj(options.body)) {
if (!options.body['anthropic_version']) {
options.body['anthropic_version'] = DEFAULT_VERSION;
}
if (options.headers && !options.body['anthropic_beta']) {
const betas = buildHeaders([options.headers]).values.get('anthropic-beta');
if (betas != null) {
options.body['anthropic_beta'] = betas.split(',');
}
}
}
if (MODEL_ENDPOINTS.has(options.path) && options.method === 'post') {
if (!isObj(options.body)) {
throw new Error('Expected request body to be an object for post /v1/messages');
}
const model = options.body['model'];
options.body['model'] = undefined;
const stream = options.body['stream'];
options.body['stream'] = undefined;
if (stream) {
options.path = path `/model/${model}/invoke-with-response-stream`;
}
else {
options.path = path `/model/${model}/invoke`;
}
}
return super.buildRequest(options);
}
}
function makeMessagesResource(client) {
const resource = new Resources.Messages(client);
// @ts-expect-error we're deleting non-optional properties
delete resource.batches;
// @ts-expect-error we're deleting non-optional properties
delete resource.countTokens;
return resource;
}
function makeBetaResource(client) {
const resource = new Resources.Beta(client);
// @ts-expect-error we're deleting non-optional properties
delete resource.promptCaching;
// @ts-expect-error we're deleting non-optional properties
delete resource.messages.batches;
// @ts-expect-error we're deleting non-optional properties
delete resource.messages.countTokens;
return resource;
}
//# sourceMappingURL=client.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"client.mjs","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,EAAE,aAAa,EAAsC,MAAM,0BAA0B;OACrF,KAAK,SAAS,MAAM,mCAAmC;OAEvD,EAAE,cAAc,EAAE;OAClB,EAAE,MAAM,EAAE;OACV,EAAE,OAAO,EAAE;OAEX,EAAE,KAAK,EAAE;OACT,EAAE,YAAY,EAAE;OAEhB,EAAE,IAAI,EAAE;OACR,EAAE,SAAS,EAAE;OAEb,EAAE,aAAa,EAAE,MAAM,0BAA0B;AAExD,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAC7C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS,CAAC,cAAc,EAAE,cAAc,EAAE,wBAAwB,CAAC,CAAC,CAAC;AAyCpG,iEAAiE;AACjE,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAuBjD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,EACV,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,WAAW,EAChD,OAAO,GAAG,OAAO,CAAC,4BAA4B,CAAC,IAAI,2BAA2B,SAAS,gBAAgB,EACvG,YAAY,GAAG,IAAI,EACnB,YAAY,GAAG,IAAI,EACnB,eAAe,GAAG,IAAI,EACtB,qBAAqB,GAAG,IAAI,EAC5B,GAAG,IAAI,KACU,EAAE;QACnB,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QA7C9B,aAAQ,GAAY,KAAK,CAAC;QAgE1B,aAAQ,GAAqB,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxD,gBAAW,GAA0B,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACrE,SAAI,GAAiB,gBAAgB,CAAC,IAAI,CAAC,CAAC;QA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,SAAS,CAAC;YAElC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;YAEnC,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA,UAAU,KAAK,8BAA8B,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA,UAAU,KAAK,SAAS,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF;AAOD,SAAS,oBAAoB,CAAC,MAAwB;IACpD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEhD,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,OAAO,CAAC;IAExB,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,WAAW,CAAC;IAE5B,OAAO,QAAQ,CAAC;AAClB,CAAC;AASD,SAAS,gBAAgB,CAAC,MAAwB;IAChD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,aAAa,CAAC;IAE9B,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;IAEjC,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC"}

View File

@@ -0,0 +1,14 @@
import { AwsCredentialIdentityProvider } from '@smithy/types';
import { MergedRequestInit } from "../internal/types.mjs";
type AuthProps = {
url: string;
regionName: string;
awsAccessKey: string | null | undefined;
awsSecretKey: string | null | undefined;
awsSessionToken: string | null | undefined;
fetchOptions?: MergedRequestInit | undefined;
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
};
export declare const getAuthHeaders: (req: RequestInit, props: AuthProps) => Promise<Record<string, string>>;
export {};
//# sourceMappingURL=auth.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"auth.d.mts","sourceRoot":"","sources":["../src/core/auth.ts"],"names":[],"mappings":"OAIO,EAAE,6BAA6B,EAAE,MAAM,eAAe;OAEtD,EAAE,iBAAiB,EAAE;AAE5B,KAAK,SAAS,GAAG;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,eAAe,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,YAAY,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC7C,qBAAqB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC,GAAG,IAAI,CAAC;CAC/E,CAAC;AA0BF,eAAO,MAAM,cAAc,GAAU,KAAK,WAAW,EAAE,OAAO,SAAS,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgDvG,CAAC"}

View File

@@ -0,0 +1,14 @@
import { AwsCredentialIdentityProvider } from '@smithy/types';
import { MergedRequestInit } from "../internal/types.js";
type AuthProps = {
url: string;
regionName: string;
awsAccessKey: string | null | undefined;
awsSecretKey: string | null | undefined;
awsSessionToken: string | null | undefined;
fetchOptions?: MergedRequestInit | undefined;
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
};
export declare const getAuthHeaders: (req: RequestInit, props: AuthProps) => Promise<Record<string, string>>;
export {};
//# sourceMappingURL=auth.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/core/auth.ts"],"names":[],"mappings":"OAIO,EAAE,6BAA6B,EAAE,MAAM,eAAe;OAEtD,EAAE,iBAAiB,EAAE;AAE5B,KAAK,SAAS,GAAG;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,eAAe,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,YAAY,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC7C,qBAAqB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC,GAAG,IAAI,CAAC;CAC/E,CAAC;AA0BF,eAAO,MAAM,cAAc,GAAU,KAAK,WAAW,EAAE,OAAO,SAAS,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgDvG,CAAC"}

View File

@@ -0,0 +1,105 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAuthHeaders = void 0;
const sha256_js_1 = require("@aws-crypto/sha256-js");
const fetch_http_handler_1 = require("@smithy/fetch-http-handler");
const protocol_http_1 = require("@smithy/protocol-http");
const signature_v4_1 = require("@smithy/signature-v4");
const assert_1 = __importDefault(require("assert"));
const DEFAULT_PROVIDER_CHAIN_RESOLVER = () => Promise.resolve().then(() => __importStar(require('@aws-sdk/credential-providers'))).then(({ fromNodeProviderChain }) => fromNodeProviderChain({
clientConfig: {
requestHandler: new fetch_http_handler_1.FetchHttpHandler({
requestInit: (httpRequest) => {
return {
...httpRequest,
};
},
}),
},
}))
.catch((error) => {
throw new Error(`Failed to import '@aws-sdk/credential-providers'.` +
`You can provide a custom \`providerChainResolver\` in the client options if your runtime does not have access to '@aws-sdk/credential-providers': ` +
`\`new AnthropicBedrock({ providerChainResolver })\` ` +
`Original error: ${error.message}`);
});
const getAuthHeaders = async (req, props) => {
(0, assert_1.default)(req.method, 'Expected request method property to be set');
let credentials;
if (props.awsAccessKey && props.awsSecretKey) {
credentials = {
accessKeyId: props.awsAccessKey,
secretAccessKey: props.awsSecretKey,
...(props.awsSessionToken != null && { sessionToken: props.awsSessionToken }),
};
}
else {
const provider = await (props.providerChainResolver ?
props.providerChainResolver()
: DEFAULT_PROVIDER_CHAIN_RESOLVER());
credentials = await provider();
}
const signer = new signature_v4_1.SignatureV4({
service: 'bedrock',
region: props.regionName,
credentials,
sha256: sha256_js_1.Sha256,
});
const url = new URL(props.url);
const headers = !req.headers ? {}
: Symbol.iterator in req.headers ?
Object.fromEntries(Array.from(req.headers).map((header) => [...header]))
: { ...req.headers };
// The connection header may be stripped by a proxy somewhere, so the receiver
// of this message may not see this header, so we remove it from the set of headers
// that are signed.
delete headers['connection'];
headers['host'] = url.hostname;
const request = new protocol_http_1.HttpRequest({
method: req.method.toUpperCase(),
protocol: url.protocol,
path: url.pathname,
headers,
body: req.body,
});
const signed = await signer.sign(request);
return signed.headers;
};
exports.getAuthHeaders = getAuthHeaders;
//# sourceMappingURL=auth.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/core/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA+C;AAC/C,mEAA8D;AAC9D,yDAAoD;AACpD,uDAAmD;AAEnD,oDAA4B;AAa5B,MAAM,+BAA+B,GAAiD,GAAG,EAAE,CACzF,kDAAO,+BAA+B,IACnC,IAAI,CAAC,CAAC,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAClC,qBAAqB,CAAC;IACpB,YAAY,EAAE;QACZ,cAAc,EAAE,IAAI,qCAAgB,CAAC;YACnC,WAAW,EAAE,CAAC,WAAW,EAAE,EAAE;gBAC3B,OAAO;oBACL,GAAG,WAAW;iBACA,CAAC;YACnB,CAAC;SACF,CAAC;KACH;CACF,CAAC,CACH;KACA,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,MAAM,IAAI,KAAK,CACb,mDAAmD;QACjD,oJAAoJ;QACpJ,sDAAsD;QACtD,mBAAmB,KAAK,CAAC,OAAO,EAAE,CACrC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEA,MAAM,cAAc,GAAG,KAAK,EAAE,GAAgB,EAAE,KAAgB,EAAmC,EAAE;IAC1G,IAAA,gBAAM,EAAC,GAAG,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC;IAEjE,IAAI,WAAW,CAAC;IAChB,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC7C,WAAW,GAAG;YACZ,WAAW,EAAE,KAAK,CAAC,YAAY;YAC/B,eAAe,EAAE,KAAK,CAAC,YAAY;YACnC,GAAG,CAAC,KAAK,CAAC,eAAe,IAAI,IAA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QACP,IAAI,EAAE,GAAG,CAAC,IAAI;KACf,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC;AAhDW,QAAA,cAAc,kBAgDzB"}

View File

@@ -0,0 +1,65 @@
import { Sha256 } from '@aws-crypto/sha256-js';
import { FetchHttpHandler } from '@smithy/fetch-http-handler';
import { HttpRequest } from '@smithy/protocol-http';
import { SignatureV4 } from '@smithy/signature-v4';
import assert from 'assert';
const DEFAULT_PROVIDER_CHAIN_RESOLVER = () => import('@aws-sdk/credential-providers').then(({ fromNodeProviderChain }) => fromNodeProviderChain({
clientConfig: {
requestHandler: new FetchHttpHandler({
requestInit: (httpRequest) => {
return {
...httpRequest,
};
},
}),
},
}))
.catch((error) => {
throw new Error(`Failed to import '@aws-sdk/credential-providers'.` +
`You can provide a custom \`providerChainResolver\` in the client options if your runtime does not have access to '@aws-sdk/credential-providers': ` +
`\`new AnthropicBedrock({ providerChainResolver })\` ` +
`Original error: ${error.message}`);
});
export const getAuthHeaders = async (req, props) => {
assert(req.method, 'Expected request method property to be set');
let credentials;
if (props.awsAccessKey && props.awsSecretKey) {
credentials = {
accessKeyId: props.awsAccessKey,
secretAccessKey: props.awsSecretKey,
...(props.awsSessionToken != null && { sessionToken: props.awsSessionToken }),
};
}
else {
const provider = await (props.providerChainResolver ?
props.providerChainResolver()
: DEFAULT_PROVIDER_CHAIN_RESOLVER());
credentials = await provider();
}
const signer = new SignatureV4({
service: 'bedrock',
region: props.regionName,
credentials,
sha256: Sha256,
});
const url = new URL(props.url);
const headers = !req.headers ? {}
: Symbol.iterator in req.headers ?
Object.fromEntries(Array.from(req.headers).map((header) => [...header]))
: { ...req.headers };
// The connection header may be stripped by a proxy somewhere, so the receiver
// of this message may not see this header, so we remove it from the set of headers
// that are signed.
delete headers['connection'];
headers['host'] = url.hostname;
const request = new HttpRequest({
method: req.method.toUpperCase(),
protocol: url.protocol,
path: url.pathname,
headers,
body: req.body,
});
const signed = await signer.sign(request);
return signed.headers;
};
//# sourceMappingURL=auth.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"auth.mjs","sourceRoot":"","sources":["../src/core/auth.ts"],"names":[],"mappings":"OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB;OACvC,EAAE,gBAAgB,EAAE,MAAM,4BAA4B;OACtD,EAAE,WAAW,EAAE,MAAM,uBAAuB;OAC5C,EAAE,WAAW,EAAE,MAAM,sBAAsB;OAE3C,MAAM,MAAM,QAAQ;AAa3B,MAAM,+BAA+B,GAAiD,GAAG,EAAE,CACzF,MAAM,CAAC,+BAA+B,EACnC,IAAI,CAAC,CAAC,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAClC,qBAAqB,CAAC;IACpB,YAAY,EAAE;QACZ,cAAc,EAAE,IAAI,gBAAgB,CAAC;YACnC,WAAW,EAAE,CAAC,WAAW,EAAE,EAAE;gBAC3B,OAAO;oBACL,GAAG,WAAW;iBACA,CAAC;YACnB,CAAC;SACF,CAAC;KACH;CACF,CAAC,CACH;KACA,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,MAAM,IAAI,KAAK,CACb,mDAAmD;QACjD,oJAAoJ;QACpJ,sDAAsD;QACtD,mBAAmB,KAAK,CAAC,OAAO,EAAE,CACrC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEP,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,GAAgB,EAAE,KAAgB,EAAmC,EAAE;IAC1G,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC;IAEjE,IAAI,WAAW,CAAC;IAChB,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC7C,WAAW,GAAG;YACZ,WAAW,EAAE,KAAK,CAAC,YAAY;YAC/B,eAAe,EAAE,KAAK,CAAC,YAAY;YACnC,G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AE,GAAG,CAAC,QAAQ;QAClB,OAAO;QACP,IAAI,EAAE,GAAG,CAAC,IAAI;KACf,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/error';
//# sourceMappingURL=error.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"error.d.mts","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/error';
//# sourceMappingURL=error.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}

View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("@anthropic-ai/sdk/core/error"), exports);
//# sourceMappingURL=error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/error';
//# sourceMappingURL=error.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"error.mjs","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/pagination';
//# sourceMappingURL=pagination.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pagination.d.mts","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/pagination';
//# sourceMappingURL=pagination.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}

View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("@anthropic-ai/sdk/core/pagination"), exports);
//# sourceMappingURL=pagination.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD"}

View File

@@ -0,0 +1,2 @@
export * from '@anthropic-ai/sdk/core/pagination';
//# sourceMappingURL=pagination.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pagination.mjs","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}

View File

@@ -0,0 +1,10 @@
import { EventStreamSerdeContext, SerdeContext } from '@smithy/types';
import { Stream as CoreStream } from '@anthropic-ai/sdk/streaming';
import { BaseAnthropic } from '@anthropic-ai/sdk';
export declare const toUtf8: (input: Uint8Array) => string;
export declare const fromUtf8: (input: string) => Uint8Array;
export declare const getMinimalSerdeContext: () => SerdeContext & EventStreamSerdeContext;
export declare class Stream<Item> extends CoreStream<Item> {
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
}
//# sourceMappingURL=streaming.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"streaming.d.mts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"OAGO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,eAAe;OAC9D,EAAE,MAAM,IAAI,UAAU,EAAmB,MAAM,6BAA6B;OAE5E,EAAY,aAAa,EAAE,MAAM,mBAAmB;AAQ3D,eAAO,MAAM,MAAM,GAAI,OAAO,UAAU,KAAG,MAAgD,CAAC;AAC5F,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,UAA6C,CAAC;AAKvF,eAAO,MAAM,sBAAsB,QAAO,YAAY,GAAG,uBAUxD,CAAC;AAEF,qBAAa,MAAM,CAAC,IAAI,CAAE,SAAQ,UAAU,CAAC,IAAI,CAAC;WAChC,eAAe,CAAC,IAAI,EAClC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa;CAqEzB"}

View File

@@ -0,0 +1,10 @@
import { EventStreamSerdeContext, SerdeContext } from '@smithy/types';
import { Stream as CoreStream } from '@anthropic-ai/sdk/streaming';
import { BaseAnthropic } from '@anthropic-ai/sdk';
export declare const toUtf8: (input: Uint8Array) => string;
export declare const fromUtf8: (input: string) => Uint8Array;
export declare const getMinimalSerdeContext: () => SerdeContext & EventStreamSerdeContext;
export declare class Stream<Item> extends CoreStream<Item> {
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
}
//# sourceMappingURL=streaming.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"OAGO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,eAAe;OAC9D,EAAE,MAAM,IAAI,UAAU,EAAmB,MAAM,6BAA6B;OAE5E,EAAY,aAAa,EAAE,MAAM,mBAAmB;AAQ3D,eAAO,MAAM,MAAM,GAAI,OAAO,UAAU,KAAG,MAAgD,CAAC;AAC5F,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,UAA6C,CAAC;AAKvF,eAAO,MAAM,sBAAsB,QAAO,YAAY,GAAG,uBAUxD,CAAC;AAEF,qBAAa,MAAM,CAAC,IAAI,CAAE,SAAQ,UAAU,CAAC,IAAI,CAAC;WAChC,eAAe,CAAC,IAAI,EAClC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa;CAqEzB"}

View File

@@ -0,0 +1,115 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stream = exports.getMinimalSerdeContext = exports.fromUtf8 = exports.toUtf8 = void 0;
const eventstream_serde_node_1 = require("@smithy/eventstream-serde-node");
const util_base64_1 = require("@smithy/util-base64");
const fetch_http_handler_1 = require("@smithy/fetch-http-handler");
const streaming_1 = require("@anthropic-ai/sdk/streaming");
const error_1 = require("@anthropic-ai/sdk/error");
const sdk_1 = require("@anthropic-ai/sdk");
const AWS_restJson1_1 = require("../AWS_restJson1.js");
const shims_1 = require("../internal/shims.js");
const values_1 = require("../internal/utils/values.js");
const log_1 = require("../internal/utils/log.js");
const toUtf8 = (input) => new TextDecoder('utf-8').decode(input);
exports.toUtf8 = toUtf8;
const fromUtf8 = (input) => new TextEncoder().encode(input);
exports.fromUtf8 = fromUtf8;
// `de_ResponseStream` parses a Bedrock response stream and emits events as they are found.
// It requires a "context" argument which has many fields, but for what we're using it for
// it only needs this.
const getMinimalSerdeContext = () => {
const marshaller = new eventstream_serde_node_1.EventStreamMarshaller({ utf8Encoder: exports.toUtf8, utf8Decoder: exports.fromUtf8 });
return {
base64Decoder: util_base64_1.fromBase64,
base64Encoder: util_base64_1.toBase64,
utf8Decoder: exports.fromUtf8,
utf8Encoder: exports.toUtf8,
eventStreamMarshaller: marshaller,
streamCollector: fetch_http_handler_1.streamCollector,
};
};
exports.getMinimalSerdeContext = getMinimalSerdeContext;
class Stream extends streaming_1.Stream {
static fromSSEResponse(response, controller, client) {
let consumed = false;
const logger = client ? (0, log_1.loggerFor)(client) : console;
async function* iterMessages() {
if (!response.body) {
controller.abort();
throw new error_1.AnthropicError(`Attempted to iterate over a response with no body`);
}
const responseBodyIter = (0, shims_1.ReadableStreamToAsyncIterable)(response.body);
const eventStream = (0, AWS_restJson1_1.de_ResponseStream)(responseBodyIter, (0, exports.getMinimalSerdeContext)());
for await (const event of eventStream) {
if (event.chunk && event.chunk.bytes) {
const s = (0, exports.toUtf8)(event.chunk.bytes);
yield { event: 'chunk', data: s, raw: [] };
}
else if (event.internalServerException) {
yield { event: 'error', data: 'InternalServerException', raw: [] };
}
else if (event.modelStreamErrorException) {
yield { event: 'error', data: 'ModelStreamErrorException', raw: [] };
}
else if (event.validationException) {
yield { event: 'error', data: 'ValidationException', raw: [] };
}
else if (event.throttlingException) {
yield { event: 'error', data: 'ThrottlingException', raw: [] };
}
}
}
// Note: this function is copied entirely from the core SDK
async function* iterator() {
if (consumed) {
throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
}
consumed = true;
let done = false;
try {
for await (const sse of iterMessages()) {
if (sse.event === 'chunk') {
try {
yield JSON.parse(sse.data);
}
catch (e) {
logger.error(`Could not parse message into JSON:`, sse.data);
logger.error(`From chunk:`, sse.raw);
throw e;
}
}
if (sse.event === 'error') {
const errText = sse.data;
const errJSON = (0, values_1.safeJSON)(errText);
const errMessage = errJSON ? undefined : errText;
throw sdk_1.APIError.generate(undefined, errJSON, errMessage, response.headers);
}
}
done = true;
}
catch (e) {
// If the user calls `stream.controller.abort()`, we should exit without throwing.
if (isAbortError(e))
return;
throw e;
}
finally {
// If the user `break`s, abort the ongoing request.
if (!done)
controller.abort();
}
}
return new Stream(iterator, controller);
}
}
exports.Stream = Stream;
function isAbortError(err) {
return (typeof err === 'object' &&
err !== null &&
// Spec-compliant fetch implementations
(('name' in err && err.name === 'AbortError') ||
// Expo fetch
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
}
//# sourceMappingURL=streaming.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,qDAA2D;AAC3D,mEAA6D;AAE7D,2DAAoF;AACpF,mDAAyD;AACzD,2CAA4D;AAC5D,uDAAqD;AACrD,gDAAkE;AAClE,wDAAoD;AACpD,kDAAkD;AAI3C,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAU,EAAE,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAA/E,QAAA,MAAM,UAAyE;AACrF,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAA1E,QAAA,QAAQ,YAAkE;AAEvF,2FAA2F;AAC3F,0FAA0F;AAC1F,sBAAsB;AACf,MAAM,sBAAsB,GAAG,GAA2C,EAAE;IACjF,MAAM,UAAU,GAAG,IAAI,8CAAqB,CAAC,EAAE,WAAW,EAAE,cAAM,EAAE,WAAW,EAAE,gBAAQ,EAAE,CAAC,CAAC;IAC7F,OAAO;QACL,aAAa,EAAE,wBAAU;QACzB,aAAa,EAAE,sBAAQ;QACvB,WAAW,EAAE,gBAAQ;QACrB,WAAW,EAAE,cAAM;QACnB,qBA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AG,GAAG,CAAC,IAAI,CAAC;wBACzB,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,OAAO,CAAC,CAAC;wBAClC,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;wBAEjD,MAAM,cAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAC5E,CAAC;gBACH,CAAC;gBACD,IAAI,GAAG,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,kFAAkF;gBAClF,IAAI,YAAY,CAAC,CAAC,CAAC;oBAAE,OAAO;gBAC5B,MAAM,CAAC,CAAC;YACV,CAAC;oBAAS,CAAC;gBACT,mDAAmD;gBACnD,IAAI,CAAC,IAAI;oBAAE,UAAU,CAAC,KAAK,EAAE,CAAC;YAChC,CAAC;QACH,CAAC;QAED,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;CACF;AAzED,wBAyEC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,uCAAuC;QACvC,CAAC,CAAC,MAAM,IAAI,GAAG,IAAK,GAAW,CAAC,IAAI,KAAK,YAAY,CAAC;YACpD,aAAa;YACb,CAAC,SAAS,IAAI,GAAG,IAAI,MAAM,CAAE,GAAW,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,+BAA+B,CAAC,CAAC,CAAC,CAChG,CAAC;AACJ,CAAC"}

View File

@@ -0,0 +1,108 @@
import { EventStreamMarshaller } from '@smithy/eventstream-serde-node';
import { fromBase64, toBase64 } from '@smithy/util-base64';
import { streamCollector } from '@smithy/fetch-http-handler';
import { Stream as CoreStream } from '@anthropic-ai/sdk/streaming';
import { AnthropicError } from '@anthropic-ai/sdk/error';
import { APIError } from '@anthropic-ai/sdk';
import { de_ResponseStream } from "../AWS_restJson1.mjs";
import { ReadableStreamToAsyncIterable } from "../internal/shims.mjs";
import { safeJSON } from "../internal/utils/values.mjs";
import { loggerFor } from "../internal/utils/log.mjs";
export const toUtf8 = (input) => new TextDecoder('utf-8').decode(input);
export const fromUtf8 = (input) => new TextEncoder().encode(input);
// `de_ResponseStream` parses a Bedrock response stream and emits events as they are found.
// It requires a "context" argument which has many fields, but for what we're using it for
// it only needs this.
export const getMinimalSerdeContext = () => {
const marshaller = new EventStreamMarshaller({ utf8Encoder: toUtf8, utf8Decoder: fromUtf8 });
return {
base64Decoder: fromBase64,
base64Encoder: toBase64,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
eventStreamMarshaller: marshaller,
streamCollector: streamCollector,
};
};
export class Stream extends CoreStream {
static fromSSEResponse(response, controller, client) {
let consumed = false;
const logger = client ? loggerFor(client) : console;
async function* iterMessages() {
if (!response.body) {
controller.abort();
throw new AnthropicError(`Attempted to iterate over a response with no body`);
}
const responseBodyIter = ReadableStreamToAsyncIterable(response.body);
const eventStream = de_ResponseStream(responseBodyIter, getMinimalSerdeContext());
for await (const event of eventStream) {
if (event.chunk && event.chunk.bytes) {
const s = toUtf8(event.chunk.bytes);
yield { event: 'chunk', data: s, raw: [] };
}
else if (event.internalServerException) {
yield { event: 'error', data: 'InternalServerException', raw: [] };
}
else if (event.modelStreamErrorException) {
yield { event: 'error', data: 'ModelStreamErrorException', raw: [] };
}
else if (event.validationException) {
yield { event: 'error', data: 'ValidationException', raw: [] };
}
else if (event.throttlingException) {
yield { event: 'error', data: 'ThrottlingException', raw: [] };
}
}
}
// Note: this function is copied entirely from the core SDK
async function* iterator() {
if (consumed) {
throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
}
consumed = true;
let done = false;
try {
for await (const sse of iterMessages()) {
if (sse.event === 'chunk') {
try {
yield JSON.parse(sse.data);
}
catch (e) {
logger.error(`Could not parse message into JSON:`, sse.data);
logger.error(`From chunk:`, sse.raw);
throw e;
}
}
if (sse.event === 'error') {
const errText = sse.data;
const errJSON = safeJSON(errText);
const errMessage = errJSON ? undefined : errText;
throw APIError.generate(undefined, errJSON, errMessage, response.headers);
}
}
done = true;
}
catch (e) {
// If the user calls `stream.controller.abort()`, we should exit without throwing.
if (isAbortError(e))
return;
throw e;
}
finally {
// If the user `break`s, abort the ongoing request.
if (!done)
controller.abort();
}
}
return new Stream(iterator, controller);
}
}
function isAbortError(err) {
return (typeof err === 'object' &&
err !== null &&
// Spec-compliant fetch implementations
(('name' in err && err.name === 'AbortError') ||
// Expo fetch
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
}
//# sourceMappingURL=streaming.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC;OAC/D,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,qBAAqB;OACnD,EAAE,eAAe,EAAE,MAAM,4BAA4B;OAErD,EAAE,MAAM,IAAI,UAAU,EAAmB,MAAM,6BAA6B;OAC5E,EAAE,cAAc,EAAE,MAAM,yBAAyB;OACjD,EAAE,QAAQ,EAAiB,MAAM,mBAAmB;OACpD,EAAE,iBAAiB,EAAE;OACrB,EAAE,6BAA6B,EAAE;OACjC,EAAE,QAAQ,EAAE;OACZ,EAAE,SAAS,EAAE;AAIpB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAU,EAAE,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEvF,2FAA2F;AAC3F,0FAA0F;AAC1F,sBAAsB;AACtB,MAAM,CAAC,MAAM,sB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@@
export * from "./client.mjs";
export { AnthropicBedrock as default } from "./client.mjs";
//# sourceMappingURL=index.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";OACO,EAAE,gBAAgB,IAAI,OAAO,EAAE"}

View File

@@ -0,0 +1,3 @@
export * from "./client.js";
export { AnthropicBedrock as default } from "./client.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";OACO,EAAE,gBAAgB,IAAI,OAAO,EAAE"}

View File

@@ -0,0 +1,24 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports = module.exports = function (...args) {
return new exports.default(...args)
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = void 0;
__exportStar(require("./client.js"), exports);
var client_1 = require("./client.js");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_1.AnthropicBedrock; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAAyB;AACzB,sCAAuD;AAA9C,iGAAA,gBAAgB,OAAW"}

View File

@@ -0,0 +1,3 @@
export * from "./client.mjs";
export { AnthropicBedrock as default } from "./client.mjs";
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";OACO,EAAE,gBAAgB,IAAI,OAAO,EAAE"}

View File

@@ -0,0 +1,73 @@
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
/**
* An alias to the builtin `RequestInit` type so we can
* easily alias it in import statements if there are name clashes.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit
*/
type _RequestInit = RequestInit;
/**
* An alias to the builtin `Response` type so we can
* easily alias it in import statements if there are name clashes.
*
* https://developer.mozilla.org/docs/Web/API/Response
*/
type _Response = Response;
/**
* The type for the first argument to `fetch`.
*
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
*/
type _RequestInfo = Request | URL | string;
/**
* The type for constructing `RequestInit` Headers.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
*/
type _HeadersInit = RequestInit['headers'];
/**
* The type for constructing `RequestInit` body.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
*/
type _BodyInit = RequestInit['body'];
/**
* An alias to the builtin `Array<T>` type so we can
* easily alias it in import statements if there are name clashes.
*/
type _Array<T> = Array<T>;
/**
* An alias to the builtin `Record<K, T>` type so we can
* easily alias it in import statements if there are name clashes.
*/
type _Record<K extends keyof any, T> = Record<K, T>;
export type { _Array as Array, _BodyInit as BodyInit, _HeadersInit as HeadersInit, _Record as Record, _RequestInfo as RequestInfo, _RequestInit as RequestInit, _Response as Response, };
/**
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
*/
type EndingType = 'native' | 'transparent';
/**
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
*/
export interface BlobPropertyBag {
endings?: EndingType;
type?: string;
}
/**
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
*/
export interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}
//# sourceMappingURL=builtin-types.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"builtin-types.d.mts","sourceRoot":"","sources":["../src/internal/builtin-types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE7F;;;;;GAKG;AACH,KAAK,YAAY,GAAG,WAAW,CAAC;AAEhC;;;;;GAKG;AACH,KAAK,SAAS,GAAG,QAAQ,CAAC;AAE1B;;;;GAIG;AACH,KAAK,YAAY,GAAG,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC;AAE3C;;;;GAIG;AACH,KAAK,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AAE3C;;;;GAIG;AACH,KAAK,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAErC;;;GAGG;AACH,KAAK,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AAE1B;;;GAGG;AACH,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpD,YAAY,EACV,MAAM,IAAI,KAAK,EACf,SAAS,IAAI,QAAQ,EACrB,YAAY,IAAI,WAAW,EAC3B,OAAO,IAAI,MAAM,EACjB,YAAY,IAAI,WAAW,EAC3B,YAAY,IAAI,WAAW,EAC3B,SAAS,IAAI,QAAQ,GACtB,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}

View File

@@ -0,0 +1,73 @@
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
/**
* An alias to the builtin `RequestInit` type so we can
* easily alias it in import statements if there are name clashes.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit
*/
type _RequestInit = RequestInit;
/**
* An alias to the builtin `Response` type so we can
* easily alias it in import statements if there are name clashes.
*
* https://developer.mozilla.org/docs/Web/API/Response
*/
type _Response = Response;
/**
* The type for the first argument to `fetch`.
*
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
*/
type _RequestInfo = Request | URL | string;
/**
* The type for constructing `RequestInit` Headers.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
*/
type _HeadersInit = RequestInit['headers'];
/**
* The type for constructing `RequestInit` body.
*
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
*/
type _BodyInit = RequestInit['body'];
/**
* An alias to the builtin `Array<T>` type so we can
* easily alias it in import statements if there are name clashes.
*/
type _Array<T> = Array<T>;
/**
* An alias to the builtin `Record<K, T>` type so we can
* easily alias it in import statements if there are name clashes.
*/
type _Record<K extends keyof any, T> = Record<K, T>;
export type { _Array as Array, _BodyInit as BodyInit, _HeadersInit as HeadersInit, _Record as Record, _RequestInfo as RequestInfo, _RequestInit as RequestInit, _Response as Response, };
/**
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
*/
type EndingType = 'native' | 'transparent';
/**
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
*/
export interface BlobPropertyBag {
endings?: EndingType;
type?: string;
}
/**
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
* environments and attempting to reference the global version will error.
*
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
*/
export interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}
//# sourceMappingURL=builtin-types.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"builtin-types.d.ts","sourceRoot":"","sources":["../src/internal/builtin-types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE7F;;;;;GAKG;AACH,KAAK,YAAY,GAAG,WAAW,CAAC;AAEhC;;;;;GAKG;AACH,KAAK,SAAS,GAAG,QAAQ,CAAC;AAE1B;;;;GAIG;AACH,KAAK,YAAY,GAAG,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC;AAE3C;;;;GAIG;AACH,KAAK,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AAE3C;;;;GAIG;AACH,KAAK,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAErC;;;GAGG;AACH,KAAK,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AAE1B;;;GAGG;AACH,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpD,YAAY,EACV,MAAM,IAAI,KAAK,EACf,SAAS,IAAI,QAAQ,EACrB,YAAY,IAAI,WAAW,EAC3B,OAAO,IAAI,MAAM,EACjB,YAAY,IAAI,WAAW,EAC3B,YAAY,IAAI,WAAW,EAC3B,SAAS,IAAI,QAAQ,GACtB,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}

View File

@@ -0,0 +1,4 @@
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=builtin-types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"builtin-types.js","sourceRoot":"","sources":["../src/internal/builtin-types.ts"],"names":[],"mappings":";AAAA,sFAAsF"}

View File

@@ -0,0 +1,3 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
export {};
//# sourceMappingURL=builtin-types.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"builtin-types.mjs","sourceRoot":"","sources":["../src/internal/builtin-types.ts"],"names":[],"mappings":"AAAA,sFAAsF"}

View File

@@ -0,0 +1,5 @@
/**
* Model-specific timeout constraints for non-streaming requests
*/
export declare const MODEL_NONSTREAMING_TOKENS: Record<string, number>;
//# sourceMappingURL=constants.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/internal/constants.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS5D,CAAC"}

Some files were not shown because too many files have changed in this diff Show More