@awt_ai/aws-sdk 0.3.0
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/.github/logo.svg +3 -0
- package/CHANGELOG.md +67 -0
- package/LICENSE +8 -0
- package/README.md +0 -0
- package/client.d.ts +124 -0
- package/client.d.ts.map +1 -0
- package/client.js +198 -0
- package/client.js.map +1 -0
- package/client.mjs +160 -0
- package/client.mjs.map +1 -0
- package/core/auth.d.ts +15 -0
- package/core/auth.d.ts.map +1 -0
- package/core/auth.js +113 -0
- package/core/auth.js.map +1 -0
- package/core/auth.mjs +73 -0
- package/core/auth.mjs.map +1 -0
- package/core/error.d.ts +2 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +18 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +2 -0
- package/core/error.mjs.map +1 -0
- package/core/pagination.d.ts +2 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +18 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +2 -0
- package/core/pagination.mjs.map +1 -0
- package/core/streaming.d.ts +2 -0
- package/core/streaming.d.ts.map +1 -0
- package/core/streaming.js +18 -0
- package/core/streaming.js.map +1 -0
- package/core/streaming.mjs +2 -0
- package/core/streaming.mjs.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +22 -0
- package/index.js.map +1 -0
- package/index.mjs +3 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/constants.d.ts +5 -0
- package/internal/constants.d.ts.map +1 -0
- package/internal/constants.js +18 -0
- package/internal/constants.js.map +1 -0
- package/internal/constants.mjs +15 -0
- package/internal/constants.mjs.map +1 -0
- package/internal/decoders/jsonl.d.ts +10 -0
- package/internal/decoders/jsonl.d.ts.map +1 -0
- package/internal/decoders/jsonl.js +39 -0
- package/internal/decoders/jsonl.js.map +1 -0
- package/internal/decoders/jsonl.mjs +35 -0
- package/internal/decoders/jsonl.mjs.map +1 -0
- package/internal/decoders/line.d.ts +17 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +123 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +118 -0
- package/internal/decoders/line.mjs.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.ts +22 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.ts +17 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +60 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +56 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/request-options.d.ts +77 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.ts +26 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/stream-utils.d.ts +8 -0
- package/internal/stream-utils.d.ts.map +1 -0
- package/internal/stream-utils.js +38 -0
- package/internal/stream-utils.js.map +1 -0
- package/internal/stream-utils.mjs +35 -0
- package/internal/stream-utils.mjs.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +96 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +93 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/types.d.ts +63 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +145 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +135 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +87 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +81 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +42 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +6 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/time.d.ts +3 -0
- package/internal/utils/time.d.ts.map +1 -0
- package/internal/utils/time.js +8 -0
- package/internal/utils/time.js.map +1 -0
- package/internal/utils/time.mjs +5 -0
- package/internal/utils/time.mjs.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.ts +19 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +119 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +100 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.ts +8 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +25 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +9 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +62 -0
- package/src/client.ts +294 -0
- package/src/core/auth.ts +101 -0
- package/src/core/error.ts +1 -0
- package/src/core/pagination.ts +1 -0
- package/src/core/streaming.ts +1 -0
- package/src/index.ts +4 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/constants.ts +15 -0
- package/src/internal/decoders/jsonl.ts +48 -0
- package/src/internal/decoders/line.ts +135 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +99 -0
- package/src/internal/parse.ts +90 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/request-options.ts +93 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/stream-utils.ts +32 -0
- package/src/internal/to-file.ts +159 -0
- package/src/internal/types.ts +93 -0
- package/src/internal/uploads.ts +204 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +128 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/query.ts +7 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/time.ts +4 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +112 -0
- package/src/internal/utils.ts +9 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./utils/values.js"), exports);
|
|
19
|
+
__exportStar(require("./utils/base64.js"), exports);
|
|
20
|
+
__exportStar(require("./utils/env.js"), exports);
|
|
21
|
+
__exportStar(require("./utils/log.js"), exports);
|
|
22
|
+
__exportStar(require("./utils/uuid.js"), exports);
|
|
23
|
+
__exportStar(require("./utils/sleep.js"), exports);
|
|
24
|
+
__exportStar(require("./utils/query.js"), exports);
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;AAEtF,oDAA+B;AAC/B,oDAA+B;AAC/B,iDAA4B;AAC5B,iDAA4B;AAC5B,kDAA6B;AAC7B,mDAA8B;AAC9B,mDAA8B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
export * from "./utils/values.mjs";
|
|
3
|
+
export * from "./utils/base64.mjs";
|
|
4
|
+
export * from "./utils/env.mjs";
|
|
5
|
+
export * from "./utils/log.mjs";
|
|
6
|
+
export * from "./utils/uuid.mjs";
|
|
7
|
+
export * from "./utils/sleep.mjs";
|
|
8
|
+
export * from "./utils/query.mjs";
|
|
9
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@awt_ai/aws-sdk",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "The official TypeScript library for the Awt AWS API",
|
|
5
|
+
"author": "Awt <support@awt.com>",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"type": "commonjs",
|
|
9
|
+
"repository": "github:awts/awt-sdk-typescript",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"packageManager": "yarn@1.22.21",
|
|
12
|
+
"private": false,
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"build": "bash ./build",
|
|
19
|
+
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
20
|
+
"tsn": "ts-node -r tsconfig-paths/register",
|
|
21
|
+
"lint": "eslint --ext ts,js .",
|
|
22
|
+
"fix": "eslint --fix --ext ts,js ."
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@awt_ai/sdk": ">=0.50.3 <1",
|
|
26
|
+
"@aws-crypto/sha256-js": "^4.0.0",
|
|
27
|
+
"@aws-sdk/credential-providers": "^3.796.0",
|
|
28
|
+
"@smithy/config-resolver": "^4.1.4",
|
|
29
|
+
"@smithy/fetch-http-handler": "^5.0.4",
|
|
30
|
+
"@smithy/node-config-provider": "^4.1.3",
|
|
31
|
+
"@smithy/protocol-http": "^3.0.6",
|
|
32
|
+
"@smithy/signature-v4": "^3.1.1",
|
|
33
|
+
"@smithy/types": "^2.3.4"
|
|
34
|
+
},
|
|
35
|
+
"imports": {
|
|
36
|
+
"@awt_ai/aws-sdk": ".",
|
|
37
|
+
"@awt_ai/aws-sdk/*": "./src/*"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./index.d.ts",
|
|
43
|
+
"default": "./index.js"
|
|
44
|
+
},
|
|
45
|
+
"types": "./index.d.mts",
|
|
46
|
+
"default": "./index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./*.mjs": {
|
|
49
|
+
"types": "./*.d.ts",
|
|
50
|
+
"default": "./*.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./*.js": {
|
|
53
|
+
"types": "./*.d.ts",
|
|
54
|
+
"default": "./*.js"
|
|
55
|
+
},
|
|
56
|
+
"./*": {
|
|
57
|
+
"types": "./*.d.ts",
|
|
58
|
+
"require": "./*.js",
|
|
59
|
+
"default": "./*.mjs"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { NullableHeaders } from './internal/headers';
|
|
2
|
+
import { buildHeaders } from './internal/headers';
|
|
3
|
+
import * as Errors from './core/error';
|
|
4
|
+
import { readEnv } from './internal/utils';
|
|
5
|
+
import { Awt, ClientOptions } from '@awt_ai/sdk/client';
|
|
6
|
+
export { BaseAwt } from '@awt_ai/sdk/client';
|
|
7
|
+
import { AwsCredentialIdentityProvider } from '@smithy/types';
|
|
8
|
+
import { loadConfig } from '@smithy/node-config-provider';
|
|
9
|
+
import { NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS } from '@smithy/config-resolver';
|
|
10
|
+
import { getAuthHeaders } from './core/auth';
|
|
11
|
+
import { FinalRequestOptions } from './internal/request-options';
|
|
12
|
+
import { FinalizedRequestInit } from './internal/types';
|
|
13
|
+
|
|
14
|
+
const DEFAULT_SERVICE_NAME = 'aws-external-awt';
|
|
15
|
+
|
|
16
|
+
export interface AwsClientOptions extends ClientOptions {
|
|
17
|
+
/**
|
|
18
|
+
* AWS region for the API gateway.
|
|
19
|
+
*
|
|
20
|
+
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
21
|
+
* `AWS_DEFAULT_REGION` env var > region from the AWS shared config file
|
|
22
|
+
* (`~/.aws/config`) for the given `awsProfile` (or `[default]`).
|
|
23
|
+
*
|
|
24
|
+
* When resolution falls through to the config file, the region is loaded
|
|
25
|
+
* asynchronously. It will be available after `await client.ready` or the
|
|
26
|
+
* first request; until then `awsRegion` and `baseURL` are `undefined`.
|
|
27
|
+
*/
|
|
28
|
+
awsRegion?: string | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* API key for x-api-key authentication.
|
|
32
|
+
*
|
|
33
|
+
* Takes precedence over AWS credential options. If neither `apiKey` nor
|
|
34
|
+
* AWS credentials are provided, falls back to the `AWT_AWS_API_KEY`
|
|
35
|
+
* environment variable, then to the default AWS credential chain.
|
|
36
|
+
*/
|
|
37
|
+
apiKey?: string | undefined;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* AWS access key ID for SigV4 authentication.
|
|
41
|
+
*
|
|
42
|
+
* Must be provided together with `awsSecretAccessKey`.
|
|
43
|
+
*/
|
|
44
|
+
awsAccessKey?: string | null | undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* AWS secret access key for SigV4 authentication.
|
|
48
|
+
*
|
|
49
|
+
* Must be provided together with `awsAccessKey`.
|
|
50
|
+
*/
|
|
51
|
+
awsSecretAccessKey?: string | null | undefined;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* AWS session token for temporary credentials.
|
|
55
|
+
*/
|
|
56
|
+
awsSessionToken?: string | null | undefined;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* AWS named profile for credential and region resolution.
|
|
60
|
+
*
|
|
61
|
+
* When set, credentials are loaded from the AWS credential chain using this
|
|
62
|
+
* profile, and the profile's `region` from `~/.aws/config` is used as a
|
|
63
|
+
* fallback when no region is provided via arg or environment variable.
|
|
64
|
+
*/
|
|
65
|
+
awsProfile?: string | undefined;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Custom provider chain resolver for AWS credentials.
|
|
69
|
+
* Useful for non-Node environments, like edge workers, where the default
|
|
70
|
+
* credential provider chain may not work.
|
|
71
|
+
*/
|
|
72
|
+
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Workspace ID sent on every request as the `awt-workspace-id` header.
|
|
76
|
+
*
|
|
77
|
+
* Resolved by precedence: `workspaceId` arg > `AWT_AWS_WORKSPACE_ID` env var.
|
|
78
|
+
*/
|
|
79
|
+
workspaceId?: string | undefined;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Skip authentication for requests. This is useful when you have a gateway
|
|
83
|
+
* or proxy that handles authentication on your behalf.
|
|
84
|
+
*
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
skipAuth?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const noRegionError = () =>
|
|
91
|
+
new Errors.AwtError(
|
|
92
|
+
'No AWS region or base URL found. Set `awsRegion` in the constructor, the `AWS_REGION` / `AWS_DEFAULT_REGION` ' +
|
|
93
|
+
'environment variable, configure a `region` for your profile in `~/.aws/config`, or provide a `baseURL` / ' +
|
|
94
|
+
'`AWT_AWS_BASE_URL` environment variable.',
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/** API Client for interfacing with the Awt AWS API. */
|
|
98
|
+
export class AwtAws extends Awt {
|
|
99
|
+
awsRegion: string | undefined;
|
|
100
|
+
awsAccessKey: string | null;
|
|
101
|
+
awsSecretAccessKey: string | null;
|
|
102
|
+
awsSessionToken: string | null;
|
|
103
|
+
awsProfile: string | null;
|
|
104
|
+
providerChainResolver: (() => Promise<AwsCredentialIdentityProvider>) | null;
|
|
105
|
+
workspaceId: string | undefined;
|
|
106
|
+
skipAuth: boolean = false;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resolves once the client is fully configured (region and base URL
|
|
110
|
+
* resolved). Rejects if region resolution fails. Await this to fail fast on
|
|
111
|
+
* misconfiguration instead of waiting for the first request.
|
|
112
|
+
*/
|
|
113
|
+
readonly ready: Promise<void>;
|
|
114
|
+
|
|
115
|
+
private _useSigV4: boolean;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* API Client for interfacing with the Awt AWS API.
|
|
119
|
+
*
|
|
120
|
+
* Auth is resolved by precedence: `apiKey` constructor arg > explicit AWS
|
|
121
|
+
* credentials > `awsProfile` > `AWT_AWS_API_KEY` env var > default
|
|
122
|
+
* AWS credential chain.
|
|
123
|
+
*
|
|
124
|
+
* @param {string | undefined} [opts.apiKey] - API key for x-api-key authentication.
|
|
125
|
+
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
126
|
+
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
127
|
+
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
128
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
129
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
130
|
+
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
131
|
+
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `awt-workspace-id` header. Resolved by precedence: arg > `AWT_AWS_WORKSPACE_ID` env var.
|
|
132
|
+
* @param {string} [opts.baseURL=process.env['AWT_AWS_BASE_URL'] ?? https://aws-external-awt.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
133
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
134
|
+
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
135
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
136
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
137
|
+
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
138
|
+
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
139
|
+
* @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.
|
|
140
|
+
* @param {boolean} [opts.skipAuth=false] - Skip authentication for requests. This is useful when you have a gateway or proxy that handles authentication on your behalf.
|
|
141
|
+
*/
|
|
142
|
+
constructor({
|
|
143
|
+
awsRegion,
|
|
144
|
+
baseURL,
|
|
145
|
+
apiKey,
|
|
146
|
+
awsAccessKey = null,
|
|
147
|
+
awsSecretAccessKey = null,
|
|
148
|
+
awsSessionToken = null,
|
|
149
|
+
awsProfile,
|
|
150
|
+
providerChainResolver = null,
|
|
151
|
+
workspaceId,
|
|
152
|
+
skipAuth = false,
|
|
153
|
+
...opts
|
|
154
|
+
}: AwsClientOptions = {}) {
|
|
155
|
+
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env > ~/.aws/config (async).
|
|
156
|
+
// The first three are resolved here; config-file fallback is kicked off below and
|
|
157
|
+
// awaited on `ready` / first request.
|
|
158
|
+
const syncRegion = awsRegion ?? readEnv('AWS_REGION') ?? readEnv('AWS_DEFAULT_REGION');
|
|
159
|
+
|
|
160
|
+
const explicitBaseURL = baseURL ?? readEnv('AWT_AWS_BASE_URL');
|
|
161
|
+
let resolvedBaseURL: string | undefined;
|
|
162
|
+
if (explicitBaseURL) {
|
|
163
|
+
resolvedBaseURL = explicitBaseURL;
|
|
164
|
+
} else if (syncRegion) {
|
|
165
|
+
resolvedBaseURL = `https://aws-external-awt.${syncRegion}.api.aws`;
|
|
166
|
+
} else {
|
|
167
|
+
// No region known yet (or skipAuth) — will be resolved async from ~/.aws/config,
|
|
168
|
+
// or is not needed at all.
|
|
169
|
+
resolvedBaseURL = undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Precedence-based auth resolution:
|
|
173
|
+
// 1. apiKey constructor arg
|
|
174
|
+
// 2. awsAccessKey/awsSecretAccessKey constructor args (SigV4)
|
|
175
|
+
// 3. awsProfile constructor arg (SigV4)
|
|
176
|
+
// 4. AWT_AWS_API_KEY env var
|
|
177
|
+
// 5. Default AWS credential chain (SigV4)
|
|
178
|
+
const hasExplicitApiKey = apiKey != null;
|
|
179
|
+
const hasPartialAwsCreds = (awsAccessKey != null) !== (awsSecretAccessKey != null);
|
|
180
|
+
if (hasPartialAwsCreds) {
|
|
181
|
+
throw new Errors.AwtError(
|
|
182
|
+
'`awsAccessKey` and `awsSecretAccessKey` must be provided together. You provided only one.',
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const hasExplicitAwsCreds = awsAccessKey != null && awsSecretAccessKey != null;
|
|
186
|
+
const hasAwsProfile = awsProfile != null;
|
|
187
|
+
|
|
188
|
+
let resolvedApiKey: string | undefined;
|
|
189
|
+
if (hasExplicitApiKey) {
|
|
190
|
+
resolvedApiKey = apiKey;
|
|
191
|
+
} else if (!hasExplicitAwsCreds && !hasAwsProfile) {
|
|
192
|
+
resolvedApiKey = readEnv('AWT_AWS_API_KEY') ?? undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const resolvedWorkspaceId = workspaceId ?? readEnv('AWT_AWS_WORKSPACE_ID');
|
|
196
|
+
if (!resolvedWorkspaceId && !skipAuth) {
|
|
197
|
+
throw new Errors.AwtError(
|
|
198
|
+
'No workspace ID found. Set `workspaceId` in the constructor or the `AWT_AWS_WORKSPACE_ID` environment variable.',
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
super({
|
|
203
|
+
apiKey: resolvedApiKey,
|
|
204
|
+
baseURL: resolvedBaseURL,
|
|
205
|
+
...opts,
|
|
206
|
+
defaultHeaders: buildHeaders([{ 'awt-workspace-id': resolvedWorkspaceId }, opts.defaultHeaders]),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
this.awsRegion = syncRegion;
|
|
210
|
+
this.awsAccessKey = awsAccessKey;
|
|
211
|
+
this.awsSecretAccessKey = awsSecretAccessKey;
|
|
212
|
+
this.awsSessionToken = awsSessionToken;
|
|
213
|
+
this.awsProfile = awsProfile ?? null;
|
|
214
|
+
this.providerChainResolver = providerChainResolver;
|
|
215
|
+
this.workspaceId = resolvedWorkspaceId;
|
|
216
|
+
this.skipAuth = skipAuth;
|
|
217
|
+
this._useSigV4 = resolvedApiKey == null;
|
|
218
|
+
|
|
219
|
+
if (syncRegion || explicitBaseURL || skipAuth) {
|
|
220
|
+
this.ready = Promise.resolve();
|
|
221
|
+
} else {
|
|
222
|
+
this.ready = this._resolveRegionFromConfig(awsProfile).then((region: string) => {
|
|
223
|
+
this.awsRegion = region;
|
|
224
|
+
this.baseURL = `https://aws-external-awt.${region}.api.aws`;
|
|
225
|
+
});
|
|
226
|
+
// Suppress unhandledRejection; the error surfaces via `await ready` or the first request.
|
|
227
|
+
this.ready.catch(() => {});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private _resolveRegionFromConfig(profile: string | undefined): Promise<string> {
|
|
232
|
+
return loadConfig(
|
|
233
|
+
{
|
|
234
|
+
...NODE_REGION_CONFIG_OPTIONS,
|
|
235
|
+
default: () => {
|
|
236
|
+
throw noRegionError();
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
...NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
241
|
+
...(profile && { profile }),
|
|
242
|
+
},
|
|
243
|
+
)();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
protected override async prepareOptions(options: FinalRequestOptions): Promise<void> {
|
|
247
|
+
await super.prepareOptions(options);
|
|
248
|
+
await this.ready;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
protected override async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
252
|
+
if (this.skipAuth) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!this._useSigV4) {
|
|
257
|
+
// API key mode — use inherited x-api-key auth
|
|
258
|
+
return super.authHeaders(opts);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// SigV4 mode — auth is handled in prepareRequest since it needs the full request
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
protected override validateHeaders(): void {
|
|
266
|
+
// Auth validation is handled in the constructor and prepareRequest
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
protected override async prepareRequest(
|
|
270
|
+
request: FinalizedRequestInit,
|
|
271
|
+
{ url, options }: { url: string; options: FinalRequestOptions },
|
|
272
|
+
): Promise<void> {
|
|
273
|
+
if (this.skipAuth || !this._useSigV4) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (!this.awsRegion) {
|
|
278
|
+
// Only reachable when an explicit baseURL was provided without a region.
|
|
279
|
+
throw noRegionError();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const headers = await getAuthHeaders(request, {
|
|
283
|
+
url,
|
|
284
|
+
regionName: this.awsRegion,
|
|
285
|
+
serviceName: DEFAULT_SERVICE_NAME,
|
|
286
|
+
awsAccessKey: this.awsAccessKey,
|
|
287
|
+
awsSecretAccessKey: this.awsSecretAccessKey,
|
|
288
|
+
awsSessionToken: this.awsSessionToken,
|
|
289
|
+
awsProfile: this.awsProfile,
|
|
290
|
+
providerChainResolver: this.providerChainResolver,
|
|
291
|
+
});
|
|
292
|
+
request.headers = buildHeaders([headers, request.headers]).values;
|
|
293
|
+
}
|
|
294
|
+
}
|
package/src/core/auth.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Sha256 } from '@aws-crypto/sha256-js';
|
|
2
|
+
import { FetchHttpHandler } from '@smithy/fetch-http-handler';
|
|
3
|
+
import { HttpRequest } from '@smithy/protocol-http';
|
|
4
|
+
import { SignatureV4 } from '@smithy/signature-v4';
|
|
5
|
+
import { AwsCredentialIdentityProvider } from '@smithy/types';
|
|
6
|
+
import assert from 'assert';
|
|
7
|
+
import { MergedRequestInit } from '../internal/types';
|
|
8
|
+
|
|
9
|
+
export type AuthProps = {
|
|
10
|
+
url: string;
|
|
11
|
+
regionName: string;
|
|
12
|
+
serviceName: string;
|
|
13
|
+
awsAccessKey: string | null | undefined;
|
|
14
|
+
awsSecretAccessKey: string | null | undefined;
|
|
15
|
+
awsSessionToken: string | null | undefined;
|
|
16
|
+
awsProfile?: string | null | undefined;
|
|
17
|
+
fetchOptions?: MergedRequestInit | undefined;
|
|
18
|
+
providerChainResolver?: (() => Promise<AwsCredentialIdentityProvider>) | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const defaultProviderChainResolver = (profile?: string | null): Promise<AwsCredentialIdentityProvider> =>
|
|
22
|
+
import('@aws-sdk/credential-providers')
|
|
23
|
+
.then(({ fromNodeProviderChain }) =>
|
|
24
|
+
fromNodeProviderChain({
|
|
25
|
+
...(profile != null ? { profile } : {}),
|
|
26
|
+
clientConfig: {
|
|
27
|
+
requestHandler: new FetchHttpHandler({
|
|
28
|
+
requestInit: (httpRequest) => {
|
|
29
|
+
return {
|
|
30
|
+
...httpRequest,
|
|
31
|
+
} as RequestInit;
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Failed to import '@aws-sdk/credential-providers'. ` +
|
|
40
|
+
`You can provide a custom \`providerChainResolver\` in the client options if your runtime does not have access to '@aws-sdk/credential-providers': ` +
|
|
41
|
+
`\`new AwtAws({ providerChainResolver })\` ` +
|
|
42
|
+
`Original error: ${error.message}`,
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const getAuthHeaders = async (req: RequestInit, props: AuthProps): Promise<Record<string, string>> => {
|
|
47
|
+
assert(req.method, 'Expected request method property to be set');
|
|
48
|
+
|
|
49
|
+
let credentials;
|
|
50
|
+
if (props.awsAccessKey && props.awsSecretAccessKey) {
|
|
51
|
+
credentials = {
|
|
52
|
+
accessKeyId: props.awsAccessKey,
|
|
53
|
+
secretAccessKey: props.awsSecretAccessKey,
|
|
54
|
+
...(props.awsSessionToken != null && { sessionToken: props.awsSessionToken }),
|
|
55
|
+
};
|
|
56
|
+
} else if (props.providerChainResolver) {
|
|
57
|
+
const provider = await props.providerChainResolver();
|
|
58
|
+
credentials = await provider();
|
|
59
|
+
} else {
|
|
60
|
+
const provider = await defaultProviderChainResolver(props.awsProfile);
|
|
61
|
+
credentials = await provider();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const signer = new SignatureV4({
|
|
65
|
+
service: props.serviceName,
|
|
66
|
+
region: props.regionName,
|
|
67
|
+
credentials,
|
|
68
|
+
sha256: Sha256,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const url = new URL(props.url);
|
|
72
|
+
|
|
73
|
+
const headers =
|
|
74
|
+
!req.headers ? {}
|
|
75
|
+
: Symbol.iterator in req.headers ?
|
|
76
|
+
Object.fromEntries(Array.from(req.headers).map((header) => [...header]))
|
|
77
|
+
: { ...req.headers };
|
|
78
|
+
|
|
79
|
+
// The connection header may be stripped by a proxy somewhere, so the receiver
|
|
80
|
+
// of this message may not see this header, so we remove it from the set of headers
|
|
81
|
+
// that are signed.
|
|
82
|
+
delete headers['connection'];
|
|
83
|
+
headers['host'] = url.hostname;
|
|
84
|
+
|
|
85
|
+
const query: Record<string, string> = {};
|
|
86
|
+
url.searchParams.forEach((value, key) => {
|
|
87
|
+
query[key] = value;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const request = new HttpRequest({
|
|
91
|
+
method: req.method.toUpperCase(),
|
|
92
|
+
protocol: url.protocol,
|
|
93
|
+
path: url.pathname,
|
|
94
|
+
query,
|
|
95
|
+
headers,
|
|
96
|
+
body: req.body,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const signed = await signer.sign(request);
|
|
100
|
+
return signed.headers;
|
|
101
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@awt_ai/sdk/core/error';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@awt_ai/sdk/core/pagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@awt_ai/sdk/core/streaming';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An alias to the builtin `RequestInit` type so we can
|
|
7
|
+
* easily alias it in import statements if there are name clashes.
|
|
8
|
+
*
|
|
9
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit
|
|
10
|
+
*/
|
|
11
|
+
type _RequestInit = RequestInit;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An alias to the builtin `Response` type so we can
|
|
15
|
+
* easily alias it in import statements if there are name clashes.
|
|
16
|
+
*
|
|
17
|
+
* https://developer.mozilla.org/docs/Web/API/Response
|
|
18
|
+
*/
|
|
19
|
+
type _Response = Response;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The type for the first argument to `fetch`.
|
|
23
|
+
*
|
|
24
|
+
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
|
|
25
|
+
*/
|
|
26
|
+
type _RequestInfo = Request | URL | string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The type for constructing `RequestInit` Headers.
|
|
30
|
+
*
|
|
31
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
|
|
32
|
+
*/
|
|
33
|
+
type _HeadersInit = RequestInit['headers'];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The type for constructing `RequestInit` body.
|
|
37
|
+
*
|
|
38
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
|
|
39
|
+
*/
|
|
40
|
+
type _BodyInit = RequestInit['body'];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An alias to the builtin `Array<T>` type so we can
|
|
44
|
+
* easily alias it in import statements if there are name clashes.
|
|
45
|
+
*/
|
|
46
|
+
type _Array<T> = Array<T>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An alias to the builtin `Record<K, T>` type so we can
|
|
50
|
+
* easily alias it in import statements if there are name clashes.
|
|
51
|
+
*/
|
|
52
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
53
|
+
|
|
54
|
+
export type {
|
|
55
|
+
_Array as Array,
|
|
56
|
+
_BodyInit as BodyInit,
|
|
57
|
+
_HeadersInit as HeadersInit,
|
|
58
|
+
_Record as Record,
|
|
59
|
+
_RequestInfo as RequestInfo,
|
|
60
|
+
_RequestInit as RequestInit,
|
|
61
|
+
_Response as Response,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
|
|
66
|
+
* environments and attempting to reference the global version will error.
|
|
67
|
+
*
|
|
68
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
|
|
69
|
+
*/
|
|
70
|
+
type EndingType = 'native' | 'transparent';
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
|
|
74
|
+
* environments and attempting to reference the global version will error.
|
|
75
|
+
*
|
|
76
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
|
|
77
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
|
|
78
|
+
*/
|
|
79
|
+
export interface BlobPropertyBag {
|
|
80
|
+
endings?: EndingType;
|
|
81
|
+
type?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
|
|
86
|
+
* environments and attempting to reference the global version will error.
|
|
87
|
+
*
|
|
88
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
|
|
89
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
|
|
90
|
+
*/
|
|
91
|
+
export interface FilePropertyBag extends BlobPropertyBag {
|
|
92
|
+
lastModified?: number;
|
|
93
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// File containing shared constants
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Model-specific timeout constraints for non-streaming requests
|
|
5
|
+
*/
|
|
6
|
+
export const MODEL_NONSTREAMING_TOKENS: Record<string, number> = {
|
|
7
|
+
'awt-opus-4-20250514': 8192,
|
|
8
|
+
'awt-opus-4-0': 8192,
|
|
9
|
+
'awt-4-opus-20250514': 8192,
|
|
10
|
+
'awt.awt-opus-4-20250514-v1:0': 8192,
|
|
11
|
+
'awt-opus-4@20250514': 8192,
|
|
12
|
+
'awt-opus-4-1-20250805': 8192,
|
|
13
|
+
'awt.awt-opus-4-1-20250805-v1:0': 8192,
|
|
14
|
+
'awt-opus-4-1@20250805': 8192,
|
|
15
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AwtError } from '../../core/error';
|
|
2
|
+
import { ReadableStreamToAsyncIterable } from '../shims';
|
|
3
|
+
import { LineDecoder, type Bytes } from './line';
|
|
4
|
+
|
|
5
|
+
export class JSONLDecoder<T> {
|
|
6
|
+
controller: AbortController;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
private iterator: AsyncIterableIterator<Bytes>,
|
|
10
|
+
controller: AbortController,
|
|
11
|
+
) {
|
|
12
|
+
this.controller = controller;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private async *decoder(): AsyncIterator<T, any, undefined> {
|
|
16
|
+
const lineDecoder = new LineDecoder();
|
|
17
|
+
for await (const chunk of this.iterator) {
|
|
18
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
19
|
+
yield JSON.parse(line) as T;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (const line of lineDecoder.flush()) {
|
|
24
|
+
yield JSON.parse(line) as T;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
[Symbol.asyncIterator](): AsyncIterator<T> {
|
|
29
|
+
return this.decoder();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromResponse<T>(response: Response, controller: AbortController): JSONLDecoder<T> {
|
|
33
|
+
if (!response.body) {
|
|
34
|
+
controller.abort();
|
|
35
|
+
if (
|
|
36
|
+
typeof (globalThis as any).navigator !== 'undefined' &&
|
|
37
|
+
(globalThis as any).navigator.product === 'ReactNative'
|
|
38
|
+
) {
|
|
39
|
+
throw new AwtError(
|
|
40
|
+
`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
throw new AwtError(`Attempted to iterate over a response with no body`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return new JSONLDecoder(ReadableStreamToAsyncIterable<Bytes>(response.body), controller);
|
|
47
|
+
}
|
|
48
|
+
}
|