@tanstack/ai-bedrock 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/adapters/converse-text.js +404 -420
- package/dist/esm/adapters/converse-text.js.map +1 -1
- package/dist/esm/adapters/responses-text.js +24 -18
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/adapters/text.js +41 -32
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/converse/message-converter.js +112 -158
- package/dist/esm/converse/message-converter.js.map +1 -1
- package/dist/esm/converse/stream-processor.js +220 -198
- package/dist/esm/converse/stream-processor.js.map +1 -1
- package/dist/esm/converse/structured-output.js +19 -18
- package/dist/esm/converse/structured-output.js.map +1 -1
- package/dist/esm/converse/tool-converter.js +20 -17
- package/dist/esm/converse/tool-converter.js.map +1 -1
- package/dist/esm/index.js +48 -49
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model-catalog.generated.js +170 -89
- package/dist/esm/model-catalog.generated.js.map +1 -1
- package/dist/esm/model-meta.js +9 -13
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/utils/auth.js +33 -43
- package/dist/esm/utils/auth.js.map +1 -1
- package/dist/esm/utils/client.js +30 -29
- package/dist/esm/utils/client.js.map +1 -1
- package/dist/esm/utils/openai-sigv4-fetch.js +36 -31
- package/dist/esm/utils/openai-sigv4-fetch.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sources":["../../../src/utils/auth.ts"],"sourcesContent":["import type { AwsCredentialIdentityProvider } from '@smithy/types'\nimport type * as CredentialProviders from '@aws-sdk/credential-providers'\n\nexport type BedrockEndpoint = 'runtime' | 'mantle'\n\n/** SigV4 service name differs per endpoint. */\nexport function sigv4Service(endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle' ? 'bedrock-mantle' : 'bedrock'\n}\n\nexport type ResolvedBedrockAuth =\n | { kind: 'bearer'; token: string }\n | {\n kind: 'sigv4'\n region: string\n service: string\n credentials: AwsCredentialIdentityProvider\n }\n\nconst DEFAULT_REGION = 'us-east-1'\n\nfunction readApiKeyFromEnv(): string | undefined {\n // Bedrock is server-only (the AWS SDK is Node-only), so the key always comes\n // from process.env. Read it directly: a property access never throws, so —\n // unlike the previous try/catch around getApiKeyFromEnv — we no longer swallow\n // unrelated errors as \"key not set\". Each var is blank-checked independently\n // so a present-but-blank BEDROCK_API_KEY falls through to\n // AWS_BEARER_TOKEN_BEDROCK (and only then to SigV4) rather than masking it.\n const env = typeof process !== 'undefined' ? process.env : undefined\n for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) {\n if (value && value.trim() !== '') return value\n }\n return undefined\n}\n\nexport interface BedrockAuthConfig {\n apiKey?: string\n region?: string\n auth?: 'apikey' | 'sigv4' | 'auto'\n}\n\n/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig,\n endpoint: BedrockEndpoint,\n): ResolvedBedrockAuth {\n const mode = config.auth ?? 'auto'\n const region = config.region ?? DEFAULT_REGION\n\n if (mode !== 'sigv4') {\n const token = config.apiKey ?? readApiKeyFromEnv()\n if (token) return { kind: 'bearer', token }\n if (mode === 'apikey') {\n throw new Error(\n 'No Bedrock API key found. Set BEDROCK_API_KEY (or ' +\n 'AWS_BEARER_TOKEN_BEDROCK), pass `apiKey`, or use auth: \"sigv4\".',\n )\n }\n }\n\n return {\n kind: 'sigv4',\n region,\n service: sigv4Service(endpoint),\n // Lazy credential provider: the AWS SDK is Node/server-only, so we defer the\n // dynamic import until SigV4 actually needs to resolve credentials. The\n // specifier is held in a variable (not a string literal) so bundler dep\n // scanners (e.g. Vite/esbuild optimizeDeps) cannot statically discover the\n // AWS SDK and try to pre-bundle it for the browser — it would fail on the\n // SDK's Node-only `fromTokenFile` export chain. `typeof import(...)` is a\n // type-only reference (erased at emit) so we keep full typing.\n credentials: async (...args) => {\n const mod = '@aws-sdk/credential-providers'\n const { fromNodeProviderChain } = (await import(\n /* @vite-ignore */ mod\n )) as typeof CredentialProviders\n return fromNodeProviderChain()(...args)\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"auth.js","names":[],"sources":["../../../src/utils/auth.ts"],"sourcesContent":["import type { AwsCredentialIdentityProvider } from '@smithy/types'\nimport type * as CredentialProviders from '@aws-sdk/credential-providers'\n\nexport type BedrockEndpoint = 'runtime' | 'mantle'\n\n/** SigV4 service name differs per endpoint. */\nexport function sigv4Service(endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle' ? 'bedrock-mantle' : 'bedrock'\n}\n\nexport type ResolvedBedrockAuth =\n | { kind: 'bearer'; token: string }\n | {\n kind: 'sigv4'\n region: string\n service: string\n credentials: AwsCredentialIdentityProvider\n }\n\nconst DEFAULT_REGION = 'us-east-1'\n\nfunction readApiKeyFromEnv(): string | undefined {\n // Bedrock is server-only (the AWS SDK is Node-only), so the key always comes\n // from process.env. Read it directly: a property access never throws, so —\n // unlike the previous try/catch around getApiKeyFromEnv — we no longer swallow\n // unrelated errors as \"key not set\". Each var is blank-checked independently\n // so a present-but-blank BEDROCK_API_KEY falls through to\n // AWS_BEARER_TOKEN_BEDROCK (and only then to SigV4) rather than masking it.\n const env = typeof process !== 'undefined' ? process.env : undefined\n for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) {\n if (value && value.trim() !== '') return value\n }\n return undefined\n}\n\nexport interface BedrockAuthConfig {\n apiKey?: string\n region?: string\n auth?: 'apikey' | 'sigv4' | 'auto'\n}\n\n/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig,\n endpoint: BedrockEndpoint,\n): ResolvedBedrockAuth {\n const mode = config.auth ?? 'auto'\n const region = config.region ?? DEFAULT_REGION\n\n if (mode !== 'sigv4') {\n const token = config.apiKey ?? readApiKeyFromEnv()\n if (token) return { kind: 'bearer', token }\n if (mode === 'apikey') {\n throw new Error(\n 'No Bedrock API key found. Set BEDROCK_API_KEY (or ' +\n 'AWS_BEARER_TOKEN_BEDROCK), pass `apiKey`, or use auth: \"sigv4\".',\n )\n }\n }\n\n return {\n kind: 'sigv4',\n region,\n service: sigv4Service(endpoint),\n // Lazy credential provider: the AWS SDK is Node/server-only, so we defer the\n // dynamic import until SigV4 actually needs to resolve credentials. The\n // specifier is held in a variable (not a string literal) so bundler dep\n // scanners (e.g. Vite/esbuild optimizeDeps) cannot statically discover the\n // AWS SDK and try to pre-bundle it for the browser — it would fail on the\n // SDK's Node-only `fromTokenFile` export chain. `typeof import(...)` is a\n // type-only reference (erased at emit) so we keep full typing.\n credentials: async (...args) => {\n const mod = '@aws-sdk/credential-providers'\n const { fromNodeProviderChain } = (await import(\n /* @vite-ignore */ mod\n )) as typeof CredentialProviders\n return fromNodeProviderChain()(...args)\n },\n }\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,UAAmC;CAC9D,OAAO,aAAa,WAAW,mBAAmB;AACpD;AAWA,IAAM,iBAAiB;AAEvB,SAAS,oBAAwC;CAO/C,MAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM,KAAA;CAC3D,KAAK,MAAM,SAAS,CAAC,KAAK,iBAAiB,KAAK,wBAAwB,GACtE,IAAI,SAAS,MAAM,KAAK,MAAM,IAAI,OAAO;AAG7C;;AASA,SAAgB,mBACd,QACA,UACqB;CACrB,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,SAAS,OAAO,UAAU;CAEhC,IAAI,SAAS,SAAS;EACpB,MAAM,QAAQ,OAAO,UAAU,kBAAkB;EACjD,IAAI,OAAO,OAAO;GAAE,MAAM;GAAU;EAAM;EAC1C,IAAI,SAAS,UACX,MAAM,IAAI,MACR,qHAEF;CAEJ;CAEA,OAAO;EACL,MAAM;EACN;EACA,SAAS,aAAa,QAAQ;EAQ9B,aAAa,OAAO,GAAG,SAAS;GAE9B,MAAM,EAAE,0BAA2B,MAAM;;IACpB;;GAErB,OAAO,sBAAsB,CAAC,CAAC,GAAG,IAAI;EACxC;CACF;AACF"}
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import { resolveBedrockAuth } from "./auth.js";
|
|
2
2
|
import { createSigV4Fetch } from "./openai-sigv4-fetch.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
//#region src/utils/client.ts
|
|
4
|
+
var DEFAULT_REGION = "us-east-1";
|
|
5
|
+
/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */
|
|
6
|
+
var SIGV4_PLACEHOLDER_KEY = "bedrock-sigv4";
|
|
5
7
|
function buildBaseURL(region, endpoint) {
|
|
6
|
-
|
|
8
|
+
return endpoint === "mantle" ? `https://bedrock-mantle.${region}.api.aws/v1` : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`;
|
|
7
9
|
}
|
|
10
|
+
/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */
|
|
8
11
|
function withBedrockDefaults(config, forced) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
12
|
+
const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config;
|
|
13
|
+
const resolvedRegion = region ?? DEFAULT_REGION;
|
|
14
|
+
const resolvedEndpoint = forced ?? endpoint ?? "runtime";
|
|
15
|
+
const resolved = resolveBedrockAuth({
|
|
16
|
+
apiKey,
|
|
17
|
+
region: resolvedRegion,
|
|
18
|
+
auth
|
|
19
|
+
}, resolvedEndpoint);
|
|
20
|
+
if (resolved.kind === "bearer") return {
|
|
21
|
+
...rest,
|
|
22
|
+
baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),
|
|
23
|
+
apiKey: resolved.token,
|
|
24
|
+
...fetch ? { fetch } : {}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
...rest,
|
|
28
|
+
baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),
|
|
29
|
+
apiKey: SIGV4_PLACEHOLDER_KEY,
|
|
30
|
+
fetch: fetch ?? createSigV4Fetch(resolved)
|
|
31
|
+
};
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=client.js.map
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolveBedrockAuth, withBedrockDefaults };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import { resolveBedrockAuth } from './auth'\nimport { createSigV4Fetch } from './openai-sigv4-fetch'\nimport type { ClientOptions } from 'openai'\nimport type { BedrockEndpoint } from './auth'\n\nexport type { BedrockEndpoint } from './auth'\nexport { resolveBedrockAuth } from './auth'\nexport type { ResolvedBedrockAuth } from './auth'\n\nexport interface BedrockClientConfig extends Omit<\n ClientOptions,\n 'apiKey' | 'baseURL'\n> {\n /** Bedrock API key (bearer). Optional — falls back to env, then SigV4. */\n apiKey?: string\n /** Full AWS region (e.g. 'us-east-1'). Default 'us-east-1'. */\n region?: string\n /** Chat adapter only; the responses adapter forces 'mantle'. Default 'runtime'. */\n endpoint?: BedrockEndpoint\n /** Auth strategy. Default 'auto' (apiKey → env → SigV4). */\n auth?: 'apikey' | 'sigv4' | 'auto'\n /** Explicit override; wins over the computed endpoint URL (used by E2E → aimock). */\n baseURL?: string\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */\nconst SIGV4_PLACEHOLDER_KEY = 'bedrock-sigv4'\n\nfunction buildBaseURL(region: string, endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle'\n ? `https://bedrock-mantle.${region}.api.aws/v1`\n : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`\n}\n\n/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */\nexport function withBedrockDefaults(\n config: BedrockClientConfig,\n forced?: BedrockEndpoint,\n): ClientOptions {\n const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config\n const resolvedRegion = region ?? DEFAULT_REGION\n const resolvedEndpoint = forced ?? endpoint ?? 'runtime'\n const resolved = resolveBedrockAuth(\n { apiKey, region: resolvedRegion, auth },\n resolvedEndpoint,\n )\n if (resolved.kind === 'bearer') {\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: resolved.token,\n ...(fetch ? { fetch } : {}),\n }\n }\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: SIGV4_PLACEHOLDER_KEY,\n fetch: fetch ?? createSigV4Fetch(resolved),\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import { resolveBedrockAuth } from './auth'\nimport { createSigV4Fetch } from './openai-sigv4-fetch'\nimport type { ClientOptions } from 'openai'\nimport type { BedrockEndpoint } from './auth'\n\nexport type { BedrockEndpoint } from './auth'\nexport { resolveBedrockAuth } from './auth'\nexport type { ResolvedBedrockAuth } from './auth'\n\nexport interface BedrockClientConfig extends Omit<\n ClientOptions,\n 'apiKey' | 'baseURL'\n> {\n /** Bedrock API key (bearer). Optional — falls back to env, then SigV4. */\n apiKey?: string\n /** Full AWS region (e.g. 'us-east-1'). Default 'us-east-1'. */\n region?: string\n /** Chat adapter only; the responses adapter forces 'mantle'. Default 'runtime'. */\n endpoint?: BedrockEndpoint\n /** Auth strategy. Default 'auto' (apiKey → env → SigV4). */\n auth?: 'apikey' | 'sigv4' | 'auto'\n /** Explicit override; wins over the computed endpoint URL (used by E2E → aimock). */\n baseURL?: string\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */\nconst SIGV4_PLACEHOLDER_KEY = 'bedrock-sigv4'\n\nfunction buildBaseURL(region: string, endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle'\n ? `https://bedrock-mantle.${region}.api.aws/v1`\n : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`\n}\n\n/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */\nexport function withBedrockDefaults(\n config: BedrockClientConfig,\n forced?: BedrockEndpoint,\n): ClientOptions {\n const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config\n const resolvedRegion = region ?? DEFAULT_REGION\n const resolvedEndpoint = forced ?? endpoint ?? 'runtime'\n const resolved = resolveBedrockAuth(\n { apiKey, region: resolvedRegion, auth },\n resolvedEndpoint,\n )\n if (resolved.kind === 'bearer') {\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: resolved.token,\n ...(fetch ? { fetch } : {}),\n }\n }\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: SIGV4_PLACEHOLDER_KEY,\n fetch: fetch ?? createSigV4Fetch(resolved),\n }\n}\n"],"mappings":";;;AAyBA,IAAM,iBAAiB;;AAEvB,IAAM,wBAAwB;AAE9B,SAAS,aAAa,QAAgB,UAAmC;CACvE,OAAO,aAAa,WAChB,0BAA0B,OAAO,eACjC,2BAA2B,OAAO;AACxC;;AAGA,SAAgB,oBACd,QACA,QACe;CACf,MAAM,EAAE,QAAQ,UAAU,MAAM,QAAQ,SAAS,OAAO,GAAG,SAAS;CACpE,MAAM,iBAAiB,UAAU;CACjC,MAAM,mBAAmB,UAAU,YAAY;CAC/C,MAAM,WAAW,mBACf;EAAE;EAAQ,QAAQ;EAAgB;CAAK,GACvC,gBACF;CACA,IAAI,SAAS,SAAS,UACpB,OAAO;EACL,GAAG;EACH,SAAS,WAAW,aAAa,gBAAgB,gBAAgB;EACjE,QAAQ,SAAS;EACjB,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;CAC3B;CAEF,OAAO;EACL,GAAG;EACH,SAAS,WAAW,aAAa,gBAAgB,gBAAgB;EACjE,QAAQ;EACR,OAAO,SAAS,iBAAiB,QAAQ;CAC3C;AACF"}
|
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import { SignatureV4 } from "@smithy/signature-v4";
|
|
2
2
|
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
3
|
+
//#region src/utils/openai-sigv4-fetch.ts
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a fetch so each request is SigV4-signed via the AWS signer that ships
|
|
6
|
+
* with `@aws-sdk/client-bedrock-runtime`. Replaces the old aws-sigv4-fetch peer.
|
|
7
|
+
*/
|
|
3
8
|
function createSigV4Fetch(auth, baseFetch = fetch) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
const signer = new SignatureV4({
|
|
10
|
+
service: auth.service,
|
|
11
|
+
region: auth.region,
|
|
12
|
+
credentials: auth.credentials,
|
|
13
|
+
sha256: Sha256
|
|
14
|
+
});
|
|
15
|
+
return async (input, init) => {
|
|
16
|
+
const href = typeof input === "string" ? input : input instanceof Request ? input.url : input.toString();
|
|
17
|
+
const url = new URL(href);
|
|
18
|
+
const headers = {};
|
|
19
|
+
new Headers(init?.headers).forEach((v, k) => headers[k] = v);
|
|
20
|
+
headers["host"] = url.host;
|
|
21
|
+
const body = init?.body ?? void 0;
|
|
22
|
+
const request = {
|
|
23
|
+
method: init?.method ?? "GET",
|
|
24
|
+
protocol: url.protocol,
|
|
25
|
+
hostname: url.hostname,
|
|
26
|
+
path: url.pathname + url.search,
|
|
27
|
+
headers,
|
|
28
|
+
body
|
|
29
|
+
};
|
|
30
|
+
const signed = await signer.sign(request);
|
|
31
|
+
return baseFetch(url.toString(), {
|
|
32
|
+
...init,
|
|
33
|
+
headers: signed.headers
|
|
34
|
+
});
|
|
35
|
+
};
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=openai-sigv4-fetch.js.map
|
|
37
|
+
//#endregion
|
|
38
|
+
export { createSigV4Fetch };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=openai-sigv4-fetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-sigv4-fetch.js","sources":["../../../src/utils/openai-sigv4-fetch.ts"],"sourcesContent":["import { SignatureV4 } from '@smithy/signature-v4'\nimport { Sha256 } from '@aws-crypto/sha256-js'\nimport type { HttpRequest } from '@smithy/types'\nimport type { ResolvedBedrockAuth } from './auth'\n\ntype FetchLike = typeof fetch\n\n/**\n * Wraps a fetch so each request is SigV4-signed via the AWS signer that ships\n * with `@aws-sdk/client-bedrock-runtime`. Replaces the old aws-sigv4-fetch peer.\n */\nexport function createSigV4Fetch(\n auth: Extract<ResolvedBedrockAuth, { kind: 'sigv4' }>,\n baseFetch: FetchLike = fetch,\n): FetchLike {\n const signer = new SignatureV4({\n service: auth.service,\n region: auth.region,\n credentials: auth.credentials,\n sha256: Sha256,\n })\n\n return async (input, init) => {\n // Request.toString() returns '[object Request]', not the URL — use .url instead.\n const href =\n typeof input === 'string'\n ? input\n : input instanceof Request\n ? input.url\n : input.toString()\n const url = new URL(href)\n const headers: Record<string, string> = {}\n new Headers(init?.headers).forEach((v, k) => (headers[k] = v))\n headers['host'] = url.host\n\n const body = init?.body ?? undefined\n\n // Construct a plain object satisfying the @smithy/types HttpRequest interface —\n // no @smithy/protocol-http needed.\n const request: HttpRequest = {\n method: init?.method ?? 'GET',\n protocol: url.protocol,\n hostname: url.hostname,\n path: url.pathname + url.search,\n headers,\n body,\n }\n\n const signed = await signer.sign(request)\n return baseFetch(url.toString(), {\n ...init,\n headers: signed.headers as Record<string, string>,\n })\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"openai-sigv4-fetch.js","names":[],"sources":["../../../src/utils/openai-sigv4-fetch.ts"],"sourcesContent":["import { SignatureV4 } from '@smithy/signature-v4'\nimport { Sha256 } from '@aws-crypto/sha256-js'\nimport type { HttpRequest } from '@smithy/types'\nimport type { ResolvedBedrockAuth } from './auth'\n\ntype FetchLike = typeof fetch\n\n/**\n * Wraps a fetch so each request is SigV4-signed via the AWS signer that ships\n * with `@aws-sdk/client-bedrock-runtime`. Replaces the old aws-sigv4-fetch peer.\n */\nexport function createSigV4Fetch(\n auth: Extract<ResolvedBedrockAuth, { kind: 'sigv4' }>,\n baseFetch: FetchLike = fetch,\n): FetchLike {\n const signer = new SignatureV4({\n service: auth.service,\n region: auth.region,\n credentials: auth.credentials,\n sha256: Sha256,\n })\n\n return async (input, init) => {\n // Request.toString() returns '[object Request]', not the URL — use .url instead.\n const href =\n typeof input === 'string'\n ? input\n : input instanceof Request\n ? input.url\n : input.toString()\n const url = new URL(href)\n const headers: Record<string, string> = {}\n new Headers(init?.headers).forEach((v, k) => (headers[k] = v))\n headers['host'] = url.host\n\n const body = init?.body ?? undefined\n\n // Construct a plain object satisfying the @smithy/types HttpRequest interface —\n // no @smithy/protocol-http needed.\n const request: HttpRequest = {\n method: init?.method ?? 'GET',\n protocol: url.protocol,\n hostname: url.hostname,\n path: url.pathname + url.search,\n headers,\n body,\n }\n\n const signed = await signer.sign(request)\n return baseFetch(url.toString(), {\n ...init,\n headers: signed.headers as Record<string, string>,\n })\n }\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,iBACd,MACA,YAAuB,OACZ;CACX,MAAM,SAAS,IAAI,YAAY;EAC7B,SAAS,KAAK;EACd,QAAQ,KAAK;EACb,aAAa,KAAK;EAClB,QAAQ;CACV,CAAC;CAED,OAAO,OAAO,OAAO,SAAS;EAE5B,MAAM,OACJ,OAAO,UAAU,WACb,QACA,iBAAiB,UACf,MAAM,MACN,MAAM,SAAS;EACvB,MAAM,MAAM,IAAI,IAAI,IAAI;EACxB,MAAM,UAAkC,CAAC;EACzC,IAAI,QAAQ,MAAM,OAAO,CAAC,CAAC,SAAS,GAAG,MAAO,QAAQ,KAAK,CAAE;EAC7D,QAAQ,UAAU,IAAI;EAEtB,MAAM,OAAO,MAAM,QAAQ,KAAA;EAI3B,MAAM,UAAuB;GAC3B,QAAQ,MAAM,UAAU;GACxB,UAAU,IAAI;GACd,UAAU,IAAI;GACd,MAAM,IAAI,WAAW,IAAI;GACzB;GACA;EACF;EAEA,MAAM,SAAS,MAAM,OAAO,KAAK,OAAO;EACxC,OAAO,UAAU,IAAI,SAAS,GAAG;GAC/B,GAAG;GACH,SAAS,OAAO;EAClB,CAAC;CACH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-bedrock",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Amazon Bedrock adapter for TanStack AI — OpenAI-compatible chat, responses, tools, and reasoning.",
|
|
6
6
|
"author": "",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@vitest/coverage-v8": "4.0.14",
|
|
39
|
-
"vite": "^
|
|
39
|
+
"vite": "^8.1.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"zod": "^4.0.0",
|
|
43
|
-
"@tanstack/ai": "0.
|
|
43
|
+
"@tanstack/ai": "0.43.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@aws-crypto/sha256-js": "^5.2.0",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"@smithy/signature-v4": "^5.4.5",
|
|
50
50
|
"@smithy/types": "^4.14.2",
|
|
51
51
|
"openai": "^6.41.0",
|
|
52
|
-
"@tanstack/openai-base": "0.9.
|
|
52
|
+
"@tanstack/openai-base": "0.9.10"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vite build",
|
|
56
56
|
"clean": "premove ./build ./dist",
|
|
57
|
-
"lint:fix": "
|
|
57
|
+
"lint:fix": "oxlint src --type-aware --fix",
|
|
58
58
|
"test:build": "publint --strict",
|
|
59
|
-
"test:
|
|
59
|
+
"test:oxlint": "oxlint src --type-aware",
|
|
60
60
|
"test:lib": "vitest run",
|
|
61
61
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
62
62
|
"test:types": "tsc"
|