replicas-engine 0.1.279 → 0.1.281

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.
Files changed (34) hide show
  1. package/dist/src/bowser-UXBOYYAJ.js +2821 -0
  2. package/dist/src/chunk-3YYBZ6D5.js +576 -0
  3. package/dist/src/chunk-ATF5CAZW.js +2094 -0
  4. package/dist/src/chunk-B5KEKENG.js +436 -0
  5. package/dist/src/chunk-C6IOMGXW.js +1052 -0
  6. package/dist/src/chunk-MHJJJ2VP.js +2865 -0
  7. package/dist/src/chunk-YY2DS5UJ.js +1490 -0
  8. package/dist/src/{dist-es-GGHPJZ3K.js → dist-es-37YNNMWK.js} +47 -51
  9. package/dist/src/{dist-es-F6RG3S4O.js → dist-es-7IBRAXHQ.js} +25 -23
  10. package/dist/src/{dist-es-JIV2SPEM.js → dist-es-AYVDCHRQ.js} +9 -10
  11. package/dist/src/{dist-es-BUG4C6LP.js → dist-es-JSZE2H6Y.js} +21 -31
  12. package/dist/src/{dist-es-Q3YZVSCP.js → dist-es-M4ZCYBRD.js} +10 -11
  13. package/dist/src/{dist-es-YKS4LXBO.js → dist-es-MNGVDEEO.js} +4 -3
  14. package/dist/src/{dist-es-GZBSW2H3.js → dist-es-YA3RZ3J2.js} +27 -32
  15. package/dist/src/event-streams-7ZLUNSFX.js +1376 -0
  16. package/dist/src/index.js +71 -2
  17. package/dist/src/{loadSso-3WFGTQV7.js → loadSso-2A75N7C3.js} +84 -61
  18. package/dist/src/{signin-RSKKVVIS.js → signin-FXO7O6JB.js} +94 -82
  19. package/dist/src/{sso-oidc-LBVW2ORP.js → sso-oidc-4IFMUO6A.js} +102 -63
  20. package/dist/src/{sts-DKGAU6YE.js → sts-IAUEUXEW.js} +4964 -5055
  21. package/package.json +2 -2
  22. package/dist/src/chunk-2Y7PD56W.js +0 -164
  23. package/dist/src/chunk-5VUQ55WW.js +0 -242
  24. package/dist/src/chunk-AAVVX4U5.js +0 -175
  25. package/dist/src/chunk-BUG7ZAQW.js +0 -1033
  26. package/dist/src/chunk-ERL3EC7G.js +0 -44
  27. package/dist/src/chunk-SGITM26Q.js +0 -877
  28. package/dist/src/chunk-ST5JVROM.js +0 -39
  29. package/dist/src/chunk-SWX24AGM.js +0 -62
  30. package/dist/src/chunk-TU2SAX7Z.js +0 -5706
  31. package/dist/src/chunk-WPAL27HA.js +0 -29
  32. package/dist/src/chunk-ZDZBYCXV.js +0 -52
  33. package/dist/src/chunk-ZNARSMJG.js +0 -14
  34. package/dist/src/event-streams-XS4D2DFO.js +0 -252
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.279",
3
+ "version": "0.1.281",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -30,7 +30,7 @@
30
30
  "author": "Replicas",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@anthropic-ai/claude-agent-sdk": "0.2.112",
33
+ "@anthropic-ai/claude-agent-sdk": "0.3.168",
34
34
  "@hono/node-server": "^1.19.5",
35
35
  "hono": "^4.10.3",
36
36
  "smol-toml": "^1.6.0",
@@ -1,164 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- chain
4
- } from "./chunk-WPAL27HA.js";
5
- import {
6
- getProfileName,
7
- loadSharedConfigFiles
8
- } from "./chunk-5VUQ55WW.js";
9
- import {
10
- CredentialsProviderError
11
- } from "./chunk-ST5JVROM.js";
12
-
13
- // ../node_modules/.bun/@smithy+querystring-parser@4.2.14/node_modules/@smithy/querystring-parser/dist-es/index.js
14
- function parseQueryString(querystring) {
15
- const query = {};
16
- querystring = querystring.replace(/^\?/, "");
17
- if (querystring) {
18
- for (const pair of querystring.split("&")) {
19
- let [key, value = null] = pair.split("=");
20
- key = decodeURIComponent(key);
21
- if (value) {
22
- value = decodeURIComponent(value);
23
- }
24
- if (!(key in query)) {
25
- query[key] = value;
26
- } else if (Array.isArray(query[key])) {
27
- query[key].push(value);
28
- } else {
29
- query[key] = [query[key], value];
30
- }
31
- }
32
- }
33
- return query;
34
- }
35
-
36
- // ../node_modules/.bun/@smithy+url-parser@4.2.14/node_modules/@smithy/url-parser/dist-es/index.js
37
- var parseUrl = (url) => {
38
- if (typeof url === "string") {
39
- return parseUrl(new URL(url));
40
- }
41
- const { hostname, pathname, port, protocol, search } = url;
42
- let query;
43
- if (search) {
44
- query = parseQueryString(search);
45
- }
46
- return {
47
- hostname,
48
- port: port ? parseInt(port) : void 0,
49
- protocol,
50
- path: pathname,
51
- query
52
- };
53
- };
54
-
55
- // ../node_modules/.bun/@smithy+property-provider@4.2.14/node_modules/@smithy/property-provider/dist-es/fromStatic.js
56
- var fromStatic = (staticValue) => () => Promise.resolve(staticValue);
57
-
58
- // ../node_modules/.bun/@smithy+property-provider@4.2.14/node_modules/@smithy/property-provider/dist-es/memoize.js
59
- var memoize = (provider, isExpired, requiresRefresh) => {
60
- let resolved;
61
- let pending;
62
- let hasResult;
63
- let isConstant = false;
64
- const coalesceProvider = async () => {
65
- if (!pending) {
66
- pending = provider();
67
- }
68
- try {
69
- resolved = await pending;
70
- hasResult = true;
71
- isConstant = false;
72
- } finally {
73
- pending = void 0;
74
- }
75
- return resolved;
76
- };
77
- if (isExpired === void 0) {
78
- return async (options) => {
79
- if (!hasResult || options?.forceRefresh) {
80
- resolved = await coalesceProvider();
81
- }
82
- return resolved;
83
- };
84
- }
85
- return async (options) => {
86
- if (!hasResult || options?.forceRefresh) {
87
- resolved = await coalesceProvider();
88
- }
89
- if (isConstant) {
90
- return resolved;
91
- }
92
- if (requiresRefresh && !requiresRefresh(resolved)) {
93
- isConstant = true;
94
- return resolved;
95
- }
96
- if (isExpired(resolved)) {
97
- await coalesceProvider();
98
- return resolved;
99
- }
100
- return resolved;
101
- };
102
- };
103
-
104
- // ../node_modules/.bun/@smithy+node-config-provider@4.3.14/node_modules/@smithy/node-config-provider/dist-es/getSelectorName.js
105
- function getSelectorName(functionString) {
106
- try {
107
- const constants = new Set(Array.from(functionString.match(/([A-Z_]){3,}/g) ?? []));
108
- constants.delete("CONFIG");
109
- constants.delete("CONFIG_PREFIX_SEPARATOR");
110
- constants.delete("ENV");
111
- return [...constants].join(", ");
112
- } catch (e) {
113
- return functionString;
114
- }
115
- }
116
-
117
- // ../node_modules/.bun/@smithy+node-config-provider@4.3.14/node_modules/@smithy/node-config-provider/dist-es/fromEnv.js
118
- var fromEnv = (envVarSelector, options) => async () => {
119
- try {
120
- const config = envVarSelector(process.env, options);
121
- if (config === void 0) {
122
- throw new Error();
123
- }
124
- return config;
125
- } catch (e) {
126
- throw new CredentialsProviderError(e.message || `Not found in ENV: ${getSelectorName(envVarSelector.toString())}`, { logger: options?.logger });
127
- }
128
- };
129
-
130
- // ../node_modules/.bun/@smithy+node-config-provider@4.3.14/node_modules/@smithy/node-config-provider/dist-es/fromSharedConfigFiles.js
131
- var fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
132
- const profile = getProfileName(init);
133
- const { configFile, credentialsFile } = await loadSharedConfigFiles(init);
134
- const profileFromCredentials = credentialsFile[profile] || {};
135
- const profileFromConfig = configFile[profile] || {};
136
- const mergedProfile = preferredFile === "config" ? { ...profileFromCredentials, ...profileFromConfig } : { ...profileFromConfig, ...profileFromCredentials };
137
- try {
138
- const cfgFile = preferredFile === "config" ? configFile : credentialsFile;
139
- const configValue = configSelector(mergedProfile, cfgFile);
140
- if (configValue === void 0) {
141
- throw new Error();
142
- }
143
- return configValue;
144
- } catch (e) {
145
- throw new CredentialsProviderError(e.message || `Not found in config files w/ profile [${profile}]: ${getSelectorName(configSelector.toString())}`, { logger: init.logger });
146
- }
147
- };
148
-
149
- // ../node_modules/.bun/@smithy+node-config-provider@4.3.14/node_modules/@smithy/node-config-provider/dist-es/fromStatic.js
150
- var isFunction = (func) => typeof func === "function";
151
- var fromStatic2 = (defaultValue) => isFunction(defaultValue) ? async () => await defaultValue() : fromStatic(defaultValue);
152
-
153
- // ../node_modules/.bun/@smithy+node-config-provider@4.3.14/node_modules/@smithy/node-config-provider/dist-es/configLoader.js
154
- var loadConfig = ({ environmentVariableSelector, configFileSelector, default: defaultValue }, configuration = {}) => {
155
- const { signingName, logger } = configuration;
156
- const envOptions = { signingName, logger };
157
- return memoize(chain(fromEnv(environmentVariableSelector, envOptions), fromSharedConfigFiles(configFileSelector, configuration), fromStatic2(defaultValue)));
158
- };
159
-
160
- export {
161
- parseUrl,
162
- memoize,
163
- loadConfig
164
- };
@@ -1,242 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getProfileName.js
4
- var ENV_PROFILE = "AWS_PROFILE";
5
- var DEFAULT_PROFILE = "default";
6
- var getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
7
-
8
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
9
- import { join } from "path";
10
-
11
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js
12
- import { homedir } from "os";
13
- import { sep } from "path";
14
- var homeDirCache = {};
15
- var getHomeDirCacheKey = () => {
16
- if (process && process.geteuid) {
17
- return `${process.geteuid()}`;
18
- }
19
- return "DEFAULT";
20
- };
21
- var getHomeDir = () => {
22
- const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${sep}` } = process.env;
23
- if (HOME)
24
- return HOME;
25
- if (USERPROFILE)
26
- return USERPROFILE;
27
- if (HOMEPATH)
28
- return `${HOMEDRIVE}${HOMEPATH}`;
29
- const homeDirCacheKey = getHomeDirCacheKey();
30
- if (!homeDirCache[homeDirCacheKey])
31
- homeDirCache[homeDirCacheKey] = homedir();
32
- return homeDirCache[homeDirCacheKey];
33
- };
34
-
35
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
36
- var ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
37
- var getConfigFilepath = () => process.env[ENV_CONFIG_PATH] || join(getHomeDir(), ".aws", "config");
38
-
39
- // ../node_modules/.bun/@smithy+types@4.14.1/node_modules/@smithy/types/dist-es/profile.js
40
- var IniSectionType;
41
- (function(IniSectionType2) {
42
- IniSectionType2["PROFILE"] = "profile";
43
- IniSectionType2["SSO_SESSION"] = "sso-session";
44
- IniSectionType2["SERVICES"] = "services";
45
- })(IniSectionType || (IniSectionType = {}));
46
-
47
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
48
- import { join as join3 } from "path";
49
-
50
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/constants.js
51
- var CONFIG_PREFIX_SEPARATOR = ".";
52
-
53
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigData.js
54
- var getConfigData = (data) => Object.entries(data).filter(([key]) => {
55
- const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
56
- if (indexOfSeparator === -1) {
57
- return false;
58
- }
59
- return Object.values(IniSectionType).includes(key.substring(0, indexOfSeparator));
60
- }).reduce((acc, [key, value]) => {
61
- const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
62
- const updatedKey = key.substring(0, indexOfSeparator) === IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
63
- acc[updatedKey] = value;
64
- return acc;
65
- }, {
66
- ...data.default && { default: data.default }
67
- });
68
-
69
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getCredentialsFilepath.js
70
- import { join as join2 } from "path";
71
- var ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
72
- var getCredentialsFilepath = () => process.env[ENV_CREDENTIALS_PATH] || join2(getHomeDir(), ".aws", "credentials");
73
-
74
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/parseIni.js
75
- var prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
76
- var profileNameBlockList = ["__proto__", "profile __proto__"];
77
- var parseIni = (iniData) => {
78
- const map = {};
79
- let currentSection;
80
- let currentSubSection;
81
- for (const iniLine of iniData.split(/\r?\n/)) {
82
- const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
83
- const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
84
- if (isSection) {
85
- currentSection = void 0;
86
- currentSubSection = void 0;
87
- const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
88
- const matches = prefixKeyRegex.exec(sectionName);
89
- if (matches) {
90
- const [, prefix, , name] = matches;
91
- if (Object.values(IniSectionType).includes(prefix)) {
92
- currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
93
- }
94
- } else {
95
- currentSection = sectionName;
96
- }
97
- if (profileNameBlockList.includes(sectionName)) {
98
- throw new Error(`Found invalid profile name "${sectionName}"`);
99
- }
100
- } else if (currentSection) {
101
- const indexOfEqualsSign = trimmedLine.indexOf("=");
102
- if (![0, -1].includes(indexOfEqualsSign)) {
103
- const [name, value] = [
104
- trimmedLine.substring(0, indexOfEqualsSign).trim(),
105
- trimmedLine.substring(indexOfEqualsSign + 1).trim()
106
- ];
107
- if (value === "") {
108
- currentSubSection = name;
109
- } else {
110
- if (currentSubSection && iniLine.trimStart() === iniLine) {
111
- currentSubSection = void 0;
112
- }
113
- map[currentSection] = map[currentSection] || {};
114
- const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
115
- map[currentSection][key] = value;
116
- }
117
- }
118
- }
119
- }
120
- return map;
121
- };
122
-
123
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/readFile.js
124
- import { readFile as fsReadFile } from "fs/promises";
125
- var filePromises = {};
126
- var fileIntercept = {};
127
- var readFile = (path, options) => {
128
- if (fileIntercept[path] !== void 0) {
129
- return fileIntercept[path];
130
- }
131
- if (!filePromises[path] || options?.ignoreCache) {
132
- filePromises[path] = fsReadFile(path, "utf8");
133
- }
134
- return filePromises[path];
135
- };
136
-
137
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
138
- var swallowError = () => ({});
139
- var loadSharedConfigFiles = async (init = {}) => {
140
- const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
141
- const homeDir = getHomeDir();
142
- const relativeHomeDirPrefix = "~/";
143
- let resolvedFilepath = filepath;
144
- if (filepath.startsWith(relativeHomeDirPrefix)) {
145
- resolvedFilepath = join3(homeDir, filepath.slice(2));
146
- }
147
- let resolvedConfigFilepath = configFilepath;
148
- if (configFilepath.startsWith(relativeHomeDirPrefix)) {
149
- resolvedConfigFilepath = join3(homeDir, configFilepath.slice(2));
150
- }
151
- const parsedFiles = await Promise.all([
152
- readFile(resolvedConfigFilepath, {
153
- ignoreCache: init.ignoreCache
154
- }).then(parseIni).then(getConfigData).catch(swallowError),
155
- readFile(resolvedFilepath, {
156
- ignoreCache: init.ignoreCache
157
- }).then(parseIni).catch(swallowError)
158
- ]);
159
- return {
160
- configFile: parsedFiles[0],
161
- credentialsFile: parsedFiles[1]
162
- };
163
- };
164
-
165
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getSsoSessionData.js
166
- var getSsoSessionData = (data) => Object.entries(data).filter(([key]) => key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)).reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});
167
-
168
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSsoSessionData.js
169
- var swallowError2 = () => ({});
170
- var loadSsoSessionData = async (init = {}) => readFile(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError2);
171
-
172
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/mergeConfigFiles.js
173
- var mergeConfigFiles = (...files) => {
174
- const merged = {};
175
- for (const file of files) {
176
- for (const [key, values] of Object.entries(file)) {
177
- if (merged[key] !== void 0) {
178
- Object.assign(merged[key], values);
179
- } else {
180
- merged[key] = values;
181
- }
182
- }
183
- }
184
- return merged;
185
- };
186
-
187
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/parseKnownFiles.js
188
- var parseKnownFiles = async (init) => {
189
- const parsedFiles = await loadSharedConfigFiles(init);
190
- return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
191
- };
192
-
193
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFromFile.js
194
- import { readFile as readFile2 } from "fs/promises";
195
-
196
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFilepath.js
197
- import { createHash } from "crypto";
198
- import { join as join4 } from "path";
199
- var getSSOTokenFilepath = (id) => {
200
- const hasher = createHash("sha1");
201
- const cacheName = hasher.update(id).digest("hex");
202
- return join4(getHomeDir(), ".aws", "sso", "cache", `${cacheName}.json`);
203
- };
204
-
205
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFromFile.js
206
- var tokenIntercept = {};
207
- var getSSOTokenFromFile = async (id) => {
208
- if (tokenIntercept[id]) {
209
- return tokenIntercept[id];
210
- }
211
- const ssoTokenFilepath = getSSOTokenFilepath(id);
212
- const ssoTokenText = await readFile2(ssoTokenFilepath, "utf8");
213
- return JSON.parse(ssoTokenText);
214
- };
215
-
216
- // ../node_modules/.bun/@smithy+shared-ini-file-loader@4.4.9/node_modules/@smithy/shared-ini-file-loader/dist-es/externalDataInterceptor.js
217
- var externalDataInterceptor = {
218
- getFileRecord() {
219
- return fileIntercept;
220
- },
221
- interceptFile(path, contents) {
222
- fileIntercept[path] = Promise.resolve(contents);
223
- },
224
- getTokenRecord() {
225
- return tokenIntercept;
226
- },
227
- interceptToken(id, contents) {
228
- tokenIntercept[id] = contents;
229
- }
230
- };
231
-
232
- export {
233
- getProfileName,
234
- getSSOTokenFilepath,
235
- getSSOTokenFromFile,
236
- CONFIG_PREFIX_SEPARATOR,
237
- readFile,
238
- loadSharedConfigFiles,
239
- loadSsoSessionData,
240
- parseKnownFiles,
241
- externalDataInterceptor
242
- };
@@ -1,175 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- fromBase64,
4
- streamCollector,
5
- toBase64,
6
- toHex
7
- } from "./chunk-SGITM26Q.js";
8
- import {
9
- fromArrayBuffer,
10
- toUtf8
11
- } from "./chunk-ERL3EC7G.js";
12
-
13
- // ../node_modules/.bun/@smithy+util-stream@4.5.25/node_modules/@smithy/util-stream/dist-es/sdk-stream-mixin.js
14
- import { Readable } from "stream";
15
-
16
- // ../node_modules/.bun/@smithy+fetch-http-handler@5.3.17/node_modules/@smithy/fetch-http-handler/dist-es/stream-collector.js
17
- var streamCollector2 = async (stream) => {
18
- if (typeof Blob === "function" && stream instanceof Blob || stream.constructor?.name === "Blob") {
19
- if (Blob.prototype.arrayBuffer !== void 0) {
20
- return new Uint8Array(await stream.arrayBuffer());
21
- }
22
- return collectBlob(stream);
23
- }
24
- return collectStream(stream);
25
- };
26
- async function collectBlob(blob) {
27
- const base64 = await readToBase64(blob);
28
- const arrayBuffer = fromBase64(base64);
29
- return new Uint8Array(arrayBuffer);
30
- }
31
- async function collectStream(stream) {
32
- const chunks = [];
33
- const reader = stream.getReader();
34
- let isDone = false;
35
- let length = 0;
36
- while (!isDone) {
37
- const { done, value } = await reader.read();
38
- if (value) {
39
- chunks.push(value);
40
- length += value.length;
41
- }
42
- isDone = done;
43
- }
44
- const collected = new Uint8Array(length);
45
- let offset = 0;
46
- for (const chunk of chunks) {
47
- collected.set(chunk, offset);
48
- offset += chunk.length;
49
- }
50
- return collected;
51
- }
52
- function readToBase64(blob) {
53
- return new Promise((resolve, reject) => {
54
- const reader = new FileReader();
55
- reader.onloadend = () => {
56
- if (reader.readyState !== 2) {
57
- return reject(new Error("Reader aborted too early"));
58
- }
59
- const result = reader.result ?? "";
60
- const commaIndex = result.indexOf(",");
61
- const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
62
- resolve(result.substring(dataOffset));
63
- };
64
- reader.onabort = () => reject(new Error("Read aborted"));
65
- reader.onerror = () => reject(reader.error);
66
- reader.readAsDataURL(blob);
67
- });
68
- }
69
-
70
- // ../node_modules/.bun/@smithy+util-stream@4.5.25/node_modules/@smithy/util-stream/dist-es/stream-type-check.js
71
- var isReadableStream = (stream) => typeof ReadableStream === "function" && (stream?.constructor?.name === ReadableStream.name || stream instanceof ReadableStream);
72
-
73
- // ../node_modules/.bun/@smithy+util-stream@4.5.25/node_modules/@smithy/util-stream/dist-es/sdk-stream-mixin.browser.js
74
- var ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed.";
75
- var sdkStreamMixin = (stream) => {
76
- if (!isBlobInstance(stream) && !isReadableStream(stream)) {
77
- const name = stream?.__proto__?.constructor?.name || stream;
78
- throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${name}`);
79
- }
80
- let transformed = false;
81
- const transformToByteArray = async () => {
82
- if (transformed) {
83
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED);
84
- }
85
- transformed = true;
86
- return await streamCollector2(stream);
87
- };
88
- const blobToWebStream = (blob) => {
89
- if (typeof blob.stream !== "function") {
90
- throw new Error("Cannot transform payload Blob to web stream. Please make sure the Blob.stream() is polyfilled.\nIf you are using React Native, this API is not yet supported, see: https://react-native.canny.io/feature-requests/p/fetch-streaming-body");
91
- }
92
- return blob.stream();
93
- };
94
- return Object.assign(stream, {
95
- transformToByteArray,
96
- transformToString: async (encoding) => {
97
- const buf = await transformToByteArray();
98
- if (encoding === "base64") {
99
- return toBase64(buf);
100
- } else if (encoding === "hex") {
101
- return toHex(buf);
102
- } else if (encoding === void 0 || encoding === "utf8" || encoding === "utf-8") {
103
- return toUtf8(buf);
104
- } else if (typeof TextDecoder === "function") {
105
- return new TextDecoder(encoding).decode(buf);
106
- } else {
107
- throw new Error("TextDecoder is not available, please make sure polyfill is provided.");
108
- }
109
- },
110
- transformToWebStream: () => {
111
- if (transformed) {
112
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED);
113
- }
114
- transformed = true;
115
- if (isBlobInstance(stream)) {
116
- return blobToWebStream(stream);
117
- } else if (isReadableStream(stream)) {
118
- return stream;
119
- } else {
120
- throw new Error(`Cannot transform payload to web stream, got ${stream}`);
121
- }
122
- }
123
- });
124
- };
125
- var isBlobInstance = (stream) => typeof Blob === "function" && stream instanceof Blob;
126
-
127
- // ../node_modules/.bun/@smithy+util-stream@4.5.25/node_modules/@smithy/util-stream/dist-es/sdk-stream-mixin.js
128
- var ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED2 = "The stream has already been transformed.";
129
- var sdkStreamMixin2 = (stream) => {
130
- if (!(stream instanceof Readable)) {
131
- try {
132
- return sdkStreamMixin(stream);
133
- } catch (e) {
134
- const name = stream?.__proto__?.constructor?.name || stream;
135
- throw new Error(`Unexpected stream implementation, expect Stream.Readable instance, got ${name}`);
136
- }
137
- }
138
- let transformed = false;
139
- const transformToByteArray = async () => {
140
- if (transformed) {
141
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED2);
142
- }
143
- transformed = true;
144
- return await streamCollector(stream);
145
- };
146
- return Object.assign(stream, {
147
- transformToByteArray,
148
- transformToString: async (encoding) => {
149
- const buf = await transformToByteArray();
150
- if (encoding === void 0 || Buffer.isEncoding(encoding)) {
151
- return fromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength).toString(encoding);
152
- } else {
153
- const decoder = new TextDecoder(encoding);
154
- return decoder.decode(buf);
155
- }
156
- },
157
- transformToWebStream: () => {
158
- if (transformed) {
159
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED2);
160
- }
161
- if (stream.readableFlowing !== null) {
162
- throw new Error("The stream has been consumed by other callbacks.");
163
- }
164
- if (typeof Readable.toWeb !== "function") {
165
- throw new Error("Readable.toWeb() is not supported. Please ensure a polyfill is available.");
166
- }
167
- transformed = true;
168
- return Readable.toWeb(stream);
169
- }
170
- });
171
- };
172
-
173
- export {
174
- sdkStreamMixin2 as sdkStreamMixin
175
- };