@ghostspeak/plugin-gateway-ghost 0.1.2 → 0.2.1
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/index.js +4284 -9
- package/dist/index.js.map +42 -6
- package/package.json +27 -2
- package/dist/src/config.d.ts +0 -56
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/gateway.d.ts +0 -34
- package/dist/src/gateway.d.ts.map +0 -1
- package/dist/src/handlers/image-description.d.ts +0 -15
- package/dist/src/handlers/image-description.d.ts.map +0 -1
- package/dist/src/handlers/image-generation.d.ts +0 -15
- package/dist/src/handlers/image-generation.d.ts.map +0 -1
- package/dist/src/handlers/index.d.ts +0 -12
- package/dist/src/handlers/index.d.ts.map +0 -1
- package/dist/src/handlers/object-generation.d.ts +0 -20
- package/dist/src/handlers/object-generation.d.ts.map +0 -1
- package/dist/src/handlers/text-embedding.d.ts +0 -12
- package/dist/src/handlers/text-embedding.d.ts.map +0 -1
- package/dist/src/handlers/text-generation.d.ts +0 -34
- package/dist/src/handlers/text-generation.d.ts.map +0 -1
- package/dist/src/handlers/text-to-speech.d.ts +0 -12
- package/dist/src/handlers/text-to-speech.d.ts.map +0 -1
- package/dist/src/handlers/tokenizer.d.ts +0 -16
- package/dist/src/handlers/tokenizer.d.ts.map +0 -1
- package/dist/src/handlers/transcription.d.ts +0 -12
- package/dist/src/handlers/transcription.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -22
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/plugin.d.ts +0 -19
- package/dist/src/plugin.d.ts.map +0 -1
- package/dist/src/utils/error-handler.d.ts +0 -25
- package/dist/src/utils/error-handler.d.ts.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
package/dist/index.js
CHANGED
|
@@ -1613,6 +1613,3753 @@ var require_base64_js = __commonJS((exports) => {
|
|
|
1613
1613
|
}
|
|
1614
1614
|
});
|
|
1615
1615
|
|
|
1616
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/middleware.js
|
|
1617
|
+
var require_middleware = __commonJS((exports) => {
|
|
1618
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
1619
|
+
function adopt(value) {
|
|
1620
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1621
|
+
resolve(value);
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1625
|
+
function fulfilled(value) {
|
|
1626
|
+
try {
|
|
1627
|
+
step(generator.next(value));
|
|
1628
|
+
} catch (e) {
|
|
1629
|
+
reject(e);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
function rejected(value) {
|
|
1633
|
+
try {
|
|
1634
|
+
step(generator["throw"](value));
|
|
1635
|
+
} catch (e) {
|
|
1636
|
+
reject(e);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function step(result) {
|
|
1640
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1641
|
+
}
|
|
1642
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1643
|
+
});
|
|
1644
|
+
};
|
|
1645
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1646
|
+
exports.TARGET_URL_HEADER = undefined;
|
|
1647
|
+
exports.withMiddleware = withMiddleware;
|
|
1648
|
+
exports.withProxy = withProxy;
|
|
1649
|
+
function withMiddleware(...middlewares) {
|
|
1650
|
+
const isDefined = (middleware) => typeof middleware === "function";
|
|
1651
|
+
return (config) => __awaiter(this, undefined, undefined, function* () {
|
|
1652
|
+
let currentConfig2 = Object.assign({}, config);
|
|
1653
|
+
for (const middleware of middlewares.filter(isDefined)) {
|
|
1654
|
+
currentConfig2 = yield middleware(currentConfig2);
|
|
1655
|
+
}
|
|
1656
|
+
return currentConfig2;
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
exports.TARGET_URL_HEADER = "x-fal-target-url";
|
|
1660
|
+
function withProxy(config) {
|
|
1661
|
+
const passthrough = (requestConfig) => Promise.resolve(requestConfig);
|
|
1662
|
+
if (typeof window === "undefined") {
|
|
1663
|
+
return passthrough;
|
|
1664
|
+
}
|
|
1665
|
+
return (requestConfig) => requestConfig.headers && (exports.TARGET_URL_HEADER in requestConfig) ? passthrough(requestConfig) : Promise.resolve(Object.assign(Object.assign({}, requestConfig), { url: config.targetUrl, headers: Object.assign(Object.assign({}, requestConfig.headers || {}), { [exports.TARGET_URL_HEADER]: requestConfig.url }) }));
|
|
1666
|
+
}
|
|
1667
|
+
});
|
|
1668
|
+
|
|
1669
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/response.js
|
|
1670
|
+
var require_response = __commonJS((exports) => {
|
|
1671
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
1672
|
+
function adopt(value) {
|
|
1673
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1674
|
+
resolve(value);
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1678
|
+
function fulfilled(value) {
|
|
1679
|
+
try {
|
|
1680
|
+
step(generator.next(value));
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
reject(e);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function rejected(value) {
|
|
1686
|
+
try {
|
|
1687
|
+
step(generator["throw"](value));
|
|
1688
|
+
} catch (e) {
|
|
1689
|
+
reject(e);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
function step(result) {
|
|
1693
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1694
|
+
}
|
|
1695
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1696
|
+
});
|
|
1697
|
+
};
|
|
1698
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1699
|
+
exports.ValidationError = exports.ApiError = undefined;
|
|
1700
|
+
exports.defaultResponseHandler = defaultResponseHandler;
|
|
1701
|
+
exports.resultResponseHandler = resultResponseHandler;
|
|
1702
|
+
var REQUEST_ID_HEADER = "x-fal-request-id";
|
|
1703
|
+
|
|
1704
|
+
class ApiError extends Error {
|
|
1705
|
+
constructor({ message, status, body, requestId }) {
|
|
1706
|
+
super(message);
|
|
1707
|
+
this.name = "ApiError";
|
|
1708
|
+
this.status = status;
|
|
1709
|
+
this.body = body;
|
|
1710
|
+
this.requestId = requestId || "";
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
exports.ApiError = ApiError;
|
|
1714
|
+
|
|
1715
|
+
class ValidationError extends ApiError {
|
|
1716
|
+
constructor(args) {
|
|
1717
|
+
super(args);
|
|
1718
|
+
this.name = "ValidationError";
|
|
1719
|
+
}
|
|
1720
|
+
get fieldErrors() {
|
|
1721
|
+
if (typeof this.body.detail === "string") {
|
|
1722
|
+
return [
|
|
1723
|
+
{
|
|
1724
|
+
loc: ["body"],
|
|
1725
|
+
msg: this.body.detail,
|
|
1726
|
+
type: "value_error"
|
|
1727
|
+
}
|
|
1728
|
+
];
|
|
1729
|
+
}
|
|
1730
|
+
return this.body.detail || [];
|
|
1731
|
+
}
|
|
1732
|
+
getFieldErrors(field) {
|
|
1733
|
+
return this.fieldErrors.filter((error) => error.loc[error.loc.length - 1] === field);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
exports.ValidationError = ValidationError;
|
|
1737
|
+
function defaultResponseHandler(response) {
|
|
1738
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
1739
|
+
var _a17;
|
|
1740
|
+
const { status, statusText } = response;
|
|
1741
|
+
const contentType = (_a17 = response.headers.get("Content-Type")) !== null && _a17 !== undefined ? _a17 : "";
|
|
1742
|
+
const requestId = response.headers.get(REQUEST_ID_HEADER) || undefined;
|
|
1743
|
+
if (!response.ok) {
|
|
1744
|
+
if (contentType.includes("application/json")) {
|
|
1745
|
+
const body = yield response.json();
|
|
1746
|
+
const ErrorType = status === 422 ? ValidationError : ApiError;
|
|
1747
|
+
throw new ErrorType({
|
|
1748
|
+
message: body.message || statusText,
|
|
1749
|
+
status,
|
|
1750
|
+
body,
|
|
1751
|
+
requestId
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
throw new ApiError({
|
|
1755
|
+
message: `HTTP ${status}: ${statusText}`,
|
|
1756
|
+
status,
|
|
1757
|
+
requestId
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
if (contentType.includes("application/json")) {
|
|
1761
|
+
return response.json();
|
|
1762
|
+
}
|
|
1763
|
+
if (contentType.includes("text/html")) {
|
|
1764
|
+
return response.text();
|
|
1765
|
+
}
|
|
1766
|
+
if (contentType.includes("application/octet-stream")) {
|
|
1767
|
+
return response.arrayBuffer();
|
|
1768
|
+
}
|
|
1769
|
+
return response.text();
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
function resultResponseHandler(response) {
|
|
1773
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
1774
|
+
const data = yield defaultResponseHandler(response);
|
|
1775
|
+
return {
|
|
1776
|
+
data,
|
|
1777
|
+
requestId: response.headers.get(REQUEST_ID_HEADER) || ""
|
|
1778
|
+
};
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
});
|
|
1782
|
+
|
|
1783
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/utils.js
|
|
1784
|
+
var require_utils3 = __commonJS((exports) => {
|
|
1785
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
1786
|
+
function adopt(value) {
|
|
1787
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1788
|
+
resolve(value);
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1792
|
+
function fulfilled(value) {
|
|
1793
|
+
try {
|
|
1794
|
+
step(generator.next(value));
|
|
1795
|
+
} catch (e) {
|
|
1796
|
+
reject(e);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
function rejected(value) {
|
|
1800
|
+
try {
|
|
1801
|
+
step(generator["throw"](value));
|
|
1802
|
+
} catch (e) {
|
|
1803
|
+
reject(e);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
function step(result) {
|
|
1807
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1808
|
+
}
|
|
1809
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1810
|
+
});
|
|
1811
|
+
};
|
|
1812
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1813
|
+
exports.ensureEndpointIdFormat = ensureEndpointIdFormat;
|
|
1814
|
+
exports.parseEndpointId = parseEndpointId;
|
|
1815
|
+
exports.isValidUrl = isValidUrl;
|
|
1816
|
+
exports.throttle = throttle;
|
|
1817
|
+
exports.isReact = isReact;
|
|
1818
|
+
exports.isPlainObject = isPlainObject;
|
|
1819
|
+
exports.sleep = sleep;
|
|
1820
|
+
function ensureEndpointIdFormat(id) {
|
|
1821
|
+
const parts = id.split("/");
|
|
1822
|
+
if (parts.length > 1) {
|
|
1823
|
+
return id;
|
|
1824
|
+
}
|
|
1825
|
+
const [, appOwner, appId] = /^([0-9]+)-([a-zA-Z0-9-]+)$/.exec(id) || [];
|
|
1826
|
+
if (appOwner && appId) {
|
|
1827
|
+
return `${appOwner}/${appId}`;
|
|
1828
|
+
}
|
|
1829
|
+
throw new Error(`Invalid app id: ${id}. Must be in the format <appOwner>/<appId>`);
|
|
1830
|
+
}
|
|
1831
|
+
var ENDPOINT_NAMESPACES = ["workflows", "comfy"];
|
|
1832
|
+
function parseEndpointId(id) {
|
|
1833
|
+
const normalizedId = ensureEndpointIdFormat(id);
|
|
1834
|
+
const parts = normalizedId.split("/");
|
|
1835
|
+
if (ENDPOINT_NAMESPACES.includes(parts[0])) {
|
|
1836
|
+
return {
|
|
1837
|
+
owner: parts[1],
|
|
1838
|
+
alias: parts[2],
|
|
1839
|
+
path: parts.slice(3).join("/") || undefined,
|
|
1840
|
+
namespace: parts[0]
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
return {
|
|
1844
|
+
owner: parts[0],
|
|
1845
|
+
alias: parts[1],
|
|
1846
|
+
path: parts.slice(2).join("/") || undefined
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
function isValidUrl(url) {
|
|
1850
|
+
try {
|
|
1851
|
+
const { host } = new URL(url);
|
|
1852
|
+
return /(fal\.(ai|run))$/.test(host);
|
|
1853
|
+
} catch (_) {
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
function throttle(func, limit, leading = false) {
|
|
1858
|
+
let lastFunc;
|
|
1859
|
+
let lastRan;
|
|
1860
|
+
return (...args) => {
|
|
1861
|
+
if (!lastRan && leading) {
|
|
1862
|
+
func(...args);
|
|
1863
|
+
lastRan = Date.now();
|
|
1864
|
+
} else {
|
|
1865
|
+
if (lastFunc) {
|
|
1866
|
+
clearTimeout(lastFunc);
|
|
1867
|
+
}
|
|
1868
|
+
lastFunc = setTimeout(() => {
|
|
1869
|
+
if (Date.now() - lastRan >= limit) {
|
|
1870
|
+
func(...args);
|
|
1871
|
+
lastRan = Date.now();
|
|
1872
|
+
}
|
|
1873
|
+
}, limit - (Date.now() - lastRan));
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
var isRunningInReact;
|
|
1878
|
+
function isReact() {
|
|
1879
|
+
if (isRunningInReact === undefined) {
|
|
1880
|
+
const stack = new Error().stack;
|
|
1881
|
+
isRunningInReact = !!stack && (stack.includes("node_modules/react-dom/") || stack.includes("node_modules/next/"));
|
|
1882
|
+
}
|
|
1883
|
+
return isRunningInReact;
|
|
1884
|
+
}
|
|
1885
|
+
function isPlainObject(value) {
|
|
1886
|
+
return !!value && Object.getPrototypeOf(value) === Object.prototype;
|
|
1887
|
+
}
|
|
1888
|
+
function sleep(ms) {
|
|
1889
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
1890
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/retry.js
|
|
1896
|
+
var require_retry = __commonJS((exports) => {
|
|
1897
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
1898
|
+
function adopt(value) {
|
|
1899
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1900
|
+
resolve(value);
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1904
|
+
function fulfilled(value) {
|
|
1905
|
+
try {
|
|
1906
|
+
step(generator.next(value));
|
|
1907
|
+
} catch (e) {
|
|
1908
|
+
reject(e);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
function rejected(value) {
|
|
1912
|
+
try {
|
|
1913
|
+
step(generator["throw"](value));
|
|
1914
|
+
} catch (e) {
|
|
1915
|
+
reject(e);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
function step(result) {
|
|
1919
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1920
|
+
}
|
|
1921
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1922
|
+
});
|
|
1923
|
+
};
|
|
1924
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1925
|
+
exports.DEFAULT_RETRY_OPTIONS = exports.DEFAULT_RETRYABLE_STATUS_CODES = undefined;
|
|
1926
|
+
exports.isRetryableError = isRetryableError;
|
|
1927
|
+
exports.calculateBackoffDelay = calculateBackoffDelay;
|
|
1928
|
+
exports.executeWithRetry = executeWithRetry;
|
|
1929
|
+
var response_1 = require_response();
|
|
1930
|
+
var utils_1 = require_utils3();
|
|
1931
|
+
exports.DEFAULT_RETRYABLE_STATUS_CODES = [429, 502, 503, 504];
|
|
1932
|
+
exports.DEFAULT_RETRY_OPTIONS = {
|
|
1933
|
+
maxRetries: 3,
|
|
1934
|
+
baseDelay: 1000,
|
|
1935
|
+
maxDelay: 30000,
|
|
1936
|
+
backoffMultiplier: 2,
|
|
1937
|
+
retryableStatusCodes: exports.DEFAULT_RETRYABLE_STATUS_CODES,
|
|
1938
|
+
enableJitter: true
|
|
1939
|
+
};
|
|
1940
|
+
function isRetryableError(error, retryableStatusCodes) {
|
|
1941
|
+
return error instanceof response_1.ApiError && retryableStatusCodes.includes(error.status);
|
|
1942
|
+
}
|
|
1943
|
+
function calculateBackoffDelay(attempt, baseDelay, maxDelay, backoffMultiplier, enableJitter) {
|
|
1944
|
+
const exponentialDelay = Math.min(baseDelay * Math.pow(backoffMultiplier, attempt), maxDelay);
|
|
1945
|
+
if (enableJitter) {
|
|
1946
|
+
const jitter = 0.25 * exponentialDelay * (Math.random() * 2 - 1);
|
|
1947
|
+
return Math.max(0, exponentialDelay + jitter);
|
|
1948
|
+
}
|
|
1949
|
+
return exponentialDelay;
|
|
1950
|
+
}
|
|
1951
|
+
function executeWithRetry(operation, options, onRetry) {
|
|
1952
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
1953
|
+
const metrics = {
|
|
1954
|
+
totalAttempts: 0,
|
|
1955
|
+
totalDelay: 0
|
|
1956
|
+
};
|
|
1957
|
+
let lastError;
|
|
1958
|
+
for (let attempt = 0;attempt <= options.maxRetries; attempt++) {
|
|
1959
|
+
metrics.totalAttempts++;
|
|
1960
|
+
try {
|
|
1961
|
+
const result = yield operation();
|
|
1962
|
+
return { result, metrics };
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
lastError = error;
|
|
1965
|
+
metrics.lastError = error;
|
|
1966
|
+
if (attempt === options.maxRetries || !isRetryableError(error, options.retryableStatusCodes)) {
|
|
1967
|
+
throw error;
|
|
1968
|
+
}
|
|
1969
|
+
const delay2 = calculateBackoffDelay(attempt, options.baseDelay, options.maxDelay, options.backoffMultiplier, options.enableJitter);
|
|
1970
|
+
metrics.totalDelay += delay2;
|
|
1971
|
+
if (onRetry) {
|
|
1972
|
+
onRetry(attempt + 1, error, delay2);
|
|
1973
|
+
}
|
|
1974
|
+
yield (0, utils_1.sleep)(delay2);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
throw lastError;
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
|
|
1982
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/package.json
|
|
1983
|
+
var require_package = __commonJS((exports, module) => {
|
|
1984
|
+
module.exports = {
|
|
1985
|
+
name: "@fal-ai/client",
|
|
1986
|
+
description: "The fal.ai client for JavaScript and TypeScript",
|
|
1987
|
+
version: "1.8.1",
|
|
1988
|
+
license: "MIT",
|
|
1989
|
+
repository: {
|
|
1990
|
+
type: "git",
|
|
1991
|
+
url: "https://github.com/fal-ai/fal-js.git",
|
|
1992
|
+
directory: "libs/client"
|
|
1993
|
+
},
|
|
1994
|
+
keywords: [
|
|
1995
|
+
"fal",
|
|
1996
|
+
"client",
|
|
1997
|
+
"ai",
|
|
1998
|
+
"ml",
|
|
1999
|
+
"typescript"
|
|
2000
|
+
],
|
|
2001
|
+
exports: {
|
|
2002
|
+
".": "./src/index.js",
|
|
2003
|
+
"./endpoints": "./src/types/endpoints.js"
|
|
2004
|
+
},
|
|
2005
|
+
typesVersions: {
|
|
2006
|
+
"*": {
|
|
2007
|
+
endpoints: [
|
|
2008
|
+
"src/types/endpoints.d.ts"
|
|
2009
|
+
]
|
|
2010
|
+
}
|
|
2011
|
+
},
|
|
2012
|
+
main: "./src/index.js",
|
|
2013
|
+
types: "./src/index.d.ts",
|
|
2014
|
+
dependencies: {
|
|
2015
|
+
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
2016
|
+
"eventsource-parser": "^1.1.2",
|
|
2017
|
+
robot3: "^0.4.1"
|
|
2018
|
+
},
|
|
2019
|
+
engines: {
|
|
2020
|
+
node: ">=22.0.0"
|
|
2021
|
+
},
|
|
2022
|
+
type: "commonjs"
|
|
2023
|
+
};
|
|
2024
|
+
});
|
|
2025
|
+
|
|
2026
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/runtime.js
|
|
2027
|
+
var require_runtime = __commonJS((exports) => {
|
|
2028
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2029
|
+
exports.isBrowser = isBrowser;
|
|
2030
|
+
exports.getUserAgent = getUserAgent;
|
|
2031
|
+
function isBrowser() {
|
|
2032
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2033
|
+
}
|
|
2034
|
+
var memoizedUserAgent = null;
|
|
2035
|
+
function getUserAgent() {
|
|
2036
|
+
if (memoizedUserAgent !== null) {
|
|
2037
|
+
return memoizedUserAgent;
|
|
2038
|
+
}
|
|
2039
|
+
const packageInfo = require_package();
|
|
2040
|
+
memoizedUserAgent = `${packageInfo.name}/${packageInfo.version}`;
|
|
2041
|
+
return memoizedUserAgent;
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
|
|
2045
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/config.js
|
|
2046
|
+
var require_config = __commonJS((exports) => {
|
|
2047
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2048
|
+
exports.credentialsFromEnv = undefined;
|
|
2049
|
+
exports.resolveDefaultFetch = resolveDefaultFetch;
|
|
2050
|
+
exports.createConfig = createConfig;
|
|
2051
|
+
exports.getRestApiUrl = getRestApiUrl;
|
|
2052
|
+
var middleware_1 = require_middleware();
|
|
2053
|
+
var response_1 = require_response();
|
|
2054
|
+
var retry_1 = require_retry();
|
|
2055
|
+
var runtime_1 = require_runtime();
|
|
2056
|
+
function resolveDefaultFetch() {
|
|
2057
|
+
if (typeof fetch === "undefined") {
|
|
2058
|
+
throw new Error("Your environment does not support fetch. Please provide your own fetch implementation.");
|
|
2059
|
+
}
|
|
2060
|
+
return fetch;
|
|
2061
|
+
}
|
|
2062
|
+
function hasEnvVariables() {
|
|
2063
|
+
return typeof process !== "undefined" && process.env && (typeof process.env.FAL_KEY !== "undefined" || typeof process.env.FAL_KEY_ID !== "undefined" && typeof process.env.FAL_KEY_SECRET !== "undefined");
|
|
2064
|
+
}
|
|
2065
|
+
var credentialsFromEnv = () => {
|
|
2066
|
+
if (!hasEnvVariables()) {
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
if (typeof process.env.FAL_KEY !== "undefined") {
|
|
2070
|
+
return process.env.FAL_KEY;
|
|
2071
|
+
}
|
|
2072
|
+
return process.env.FAL_KEY_ID ? `${process.env.FAL_KEY_ID}:${process.env.FAL_KEY_SECRET}` : undefined;
|
|
2073
|
+
};
|
|
2074
|
+
exports.credentialsFromEnv = credentialsFromEnv;
|
|
2075
|
+
var DEFAULT_CONFIG = {
|
|
2076
|
+
credentials: exports.credentialsFromEnv,
|
|
2077
|
+
suppressLocalCredentialsWarning: false,
|
|
2078
|
+
requestMiddleware: (request) => Promise.resolve(request),
|
|
2079
|
+
responseHandler: response_1.defaultResponseHandler,
|
|
2080
|
+
retry: retry_1.DEFAULT_RETRY_OPTIONS
|
|
2081
|
+
};
|
|
2082
|
+
function createConfig(config) {
|
|
2083
|
+
var _a17;
|
|
2084
|
+
let configuration = Object.assign(Object.assign(Object.assign({}, DEFAULT_CONFIG), config), {
|
|
2085
|
+
fetch: (_a17 = config.fetch) !== null && _a17 !== undefined ? _a17 : resolveDefaultFetch(),
|
|
2086
|
+
retry: Object.assign(Object.assign({}, retry_1.DEFAULT_RETRY_OPTIONS), config.retry || {})
|
|
2087
|
+
});
|
|
2088
|
+
if (config.proxyUrl) {
|
|
2089
|
+
configuration = Object.assign(Object.assign({}, configuration), { requestMiddleware: (0, middleware_1.withMiddleware)(configuration.requestMiddleware, (0, middleware_1.withProxy)({ targetUrl: config.proxyUrl })) });
|
|
2090
|
+
}
|
|
2091
|
+
const { credentials: resolveCredentials, suppressLocalCredentialsWarning } = configuration;
|
|
2092
|
+
const credentials = typeof resolveCredentials === "function" ? resolveCredentials() : resolveCredentials;
|
|
2093
|
+
if ((0, runtime_1.isBrowser)() && credentials && !suppressLocalCredentialsWarning) {
|
|
2094
|
+
console.warn("The fal credentials are exposed in the browser's environment. " + "That's not recommended for production use cases.");
|
|
2095
|
+
}
|
|
2096
|
+
return configuration;
|
|
2097
|
+
}
|
|
2098
|
+
function getRestApiUrl() {
|
|
2099
|
+
return "https://rest.alpha.fal.ai";
|
|
2100
|
+
}
|
|
2101
|
+
});
|
|
2102
|
+
|
|
2103
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/request.js
|
|
2104
|
+
var require_request = __commonJS((exports) => {
|
|
2105
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2106
|
+
function adopt(value) {
|
|
2107
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
2108
|
+
resolve(value);
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2112
|
+
function fulfilled(value) {
|
|
2113
|
+
try {
|
|
2114
|
+
step(generator.next(value));
|
|
2115
|
+
} catch (e) {
|
|
2116
|
+
reject(e);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
function rejected(value) {
|
|
2120
|
+
try {
|
|
2121
|
+
step(generator["throw"](value));
|
|
2122
|
+
} catch (e) {
|
|
2123
|
+
reject(e);
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
function step(result) {
|
|
2127
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2128
|
+
}
|
|
2129
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2130
|
+
});
|
|
2131
|
+
};
|
|
2132
|
+
var __rest = exports && exports.__rest || function(s, e) {
|
|
2133
|
+
var t = {};
|
|
2134
|
+
for (var p in s)
|
|
2135
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
2136
|
+
t[p] = s[p];
|
|
2137
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
2138
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s);i < p.length; i++) {
|
|
2139
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
2140
|
+
t[p[i]] = s[p[i]];
|
|
2141
|
+
}
|
|
2142
|
+
return t;
|
|
2143
|
+
};
|
|
2144
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2145
|
+
exports.dispatchRequest = dispatchRequest;
|
|
2146
|
+
exports.buildUrl = buildUrl;
|
|
2147
|
+
var retry_1 = require_retry();
|
|
2148
|
+
var runtime_1 = require_runtime();
|
|
2149
|
+
var utils_1 = require_utils3();
|
|
2150
|
+
var isCloudflareWorkers = typeof navigator !== "undefined" && (navigator === null || navigator === undefined ? undefined : navigator.userAgent) === "Cloudflare-Workers";
|
|
2151
|
+
function dispatchRequest(params) {
|
|
2152
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2153
|
+
var _a17;
|
|
2154
|
+
const { targetUrl, input, config, options = {} } = params;
|
|
2155
|
+
const { credentials: credentialsValue, requestMiddleware, responseHandler, fetch: fetch2 } = config;
|
|
2156
|
+
const retryOptions = Object.assign(Object.assign({}, config.retry), options.retry || {});
|
|
2157
|
+
const executeRequest = () => __awaiter(this, undefined, undefined, function* () {
|
|
2158
|
+
var _a18, _b, _c;
|
|
2159
|
+
const userAgent = (0, runtime_1.isBrowser)() ? {} : { "User-Agent": (0, runtime_1.getUserAgent)() };
|
|
2160
|
+
const credentials = typeof credentialsValue === "function" ? credentialsValue() : credentialsValue;
|
|
2161
|
+
const { method, url, headers } = yield requestMiddleware({
|
|
2162
|
+
method: ((_b = (_a18 = params.method) !== null && _a18 !== undefined ? _a18 : options.method) !== null && _b !== undefined ? _b : "post").toUpperCase(),
|
|
2163
|
+
url: targetUrl,
|
|
2164
|
+
headers: params.headers
|
|
2165
|
+
});
|
|
2166
|
+
const authHeader = credentials ? { Authorization: `Key ${credentials}` } : {};
|
|
2167
|
+
const requestHeaders = Object.assign(Object.assign(Object.assign(Object.assign({}, authHeader), { Accept: "application/json", "Content-Type": "application/json" }), userAgent), headers !== null && headers !== undefined ? headers : {});
|
|
2168
|
+
const { responseHandler: customResponseHandler, retry: _ } = options, requestInit = __rest(options, ["responseHandler", "retry"]);
|
|
2169
|
+
const response = yield fetch2(url, Object.assign(Object.assign(Object.assign(Object.assign({}, requestInit), { method, headers: Object.assign(Object.assign({}, requestHeaders), (_c = requestInit.headers) !== null && _c !== undefined ? _c : {}) }), !isCloudflareWorkers && { mode: "cors" }), { signal: options.signal, body: method.toLowerCase() !== "get" && input ? JSON.stringify(input) : undefined }));
|
|
2170
|
+
const handleResponse = customResponseHandler !== null && customResponseHandler !== undefined ? customResponseHandler : responseHandler;
|
|
2171
|
+
return yield handleResponse(response);
|
|
2172
|
+
});
|
|
2173
|
+
let lastError;
|
|
2174
|
+
for (let attempt = 0;attempt <= retryOptions.maxRetries; attempt++) {
|
|
2175
|
+
try {
|
|
2176
|
+
return yield executeRequest();
|
|
2177
|
+
} catch (error) {
|
|
2178
|
+
lastError = error;
|
|
2179
|
+
const shouldNotRetry = attempt === retryOptions.maxRetries || !(0, retry_1.isRetryableError)(error, retryOptions.retryableStatusCodes) || ((_a17 = options.signal) === null || _a17 === undefined ? undefined : _a17.aborted);
|
|
2180
|
+
if (shouldNotRetry) {
|
|
2181
|
+
throw error;
|
|
2182
|
+
}
|
|
2183
|
+
const delay2 = (0, retry_1.calculateBackoffDelay)(attempt, retryOptions.baseDelay, retryOptions.maxDelay, retryOptions.backoffMultiplier, retryOptions.enableJitter);
|
|
2184
|
+
yield (0, utils_1.sleep)(delay2);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
throw lastError;
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
function buildUrl(id, options = {}) {
|
|
2191
|
+
var _a17, _b;
|
|
2192
|
+
const method = ((_a17 = options.method) !== null && _a17 !== undefined ? _a17 : "post").toLowerCase();
|
|
2193
|
+
const path = ((_b = options.path) !== null && _b !== undefined ? _b : "").replace(/^\//, "").replace(/\/{2,}/, "/");
|
|
2194
|
+
const input = options.input;
|
|
2195
|
+
const params = Object.assign(Object.assign({}, options.query || {}), method === "get" ? input : {});
|
|
2196
|
+
const queryParams = Object.keys(params).length > 0 ? `?${new URLSearchParams(params).toString()}` : "";
|
|
2197
|
+
if ((0, utils_1.isValidUrl)(id)) {
|
|
2198
|
+
const url2 = id.endsWith("/") ? id : `${id}/`;
|
|
2199
|
+
return `${url2}${path}${queryParams}`;
|
|
2200
|
+
}
|
|
2201
|
+
const appId = (0, utils_1.ensureEndpointIdFormat)(id);
|
|
2202
|
+
const subdomain = options.subdomain ? `${options.subdomain}.` : "";
|
|
2203
|
+
const url = `https://${subdomain}fal.run/${appId}/${path}`;
|
|
2204
|
+
return `${url.replace(/\/$/, "")}${queryParams}`;
|
|
2205
|
+
}
|
|
2206
|
+
});
|
|
2207
|
+
|
|
2208
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/storage.js
|
|
2209
|
+
var require_storage = __commonJS((exports) => {
|
|
2210
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2211
|
+
function adopt(value) {
|
|
2212
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
2213
|
+
resolve(value);
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2217
|
+
function fulfilled(value) {
|
|
2218
|
+
try {
|
|
2219
|
+
step(generator.next(value));
|
|
2220
|
+
} catch (e) {
|
|
2221
|
+
reject(e);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
function rejected(value) {
|
|
2225
|
+
try {
|
|
2226
|
+
step(generator["throw"](value));
|
|
2227
|
+
} catch (e) {
|
|
2228
|
+
reject(e);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
function step(result) {
|
|
2232
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2233
|
+
}
|
|
2234
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2235
|
+
});
|
|
2236
|
+
};
|
|
2237
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2238
|
+
exports.OBJECT_LIFECYCYLE_PREFERENCE_HEADER = undefined;
|
|
2239
|
+
exports.getExpirationDurationSeconds = getExpirationDurationSeconds;
|
|
2240
|
+
exports.buildObjectLifecycleHeaders = buildObjectLifecycleHeaders;
|
|
2241
|
+
exports.createStorageClient = createStorageClient;
|
|
2242
|
+
var config_1 = require_config();
|
|
2243
|
+
var request_1 = require_request();
|
|
2244
|
+
var utils_1 = require_utils3();
|
|
2245
|
+
exports.OBJECT_LIFECYCYLE_PREFERENCE_HEADER = "x-fal-object-lifecycle-preference";
|
|
2246
|
+
var EXPIRATION_VALUES = {
|
|
2247
|
+
never: 3153600000,
|
|
2248
|
+
immediate: undefined,
|
|
2249
|
+
"1h": 3600,
|
|
2250
|
+
"1d": 86400,
|
|
2251
|
+
"7d": 604800,
|
|
2252
|
+
"30d": 2592000,
|
|
2253
|
+
"1y": 31536000
|
|
2254
|
+
};
|
|
2255
|
+
function getExpirationDurationSeconds(lifecycle) {
|
|
2256
|
+
const { expiresIn } = lifecycle;
|
|
2257
|
+
return typeof expiresIn === "number" ? expiresIn : EXPIRATION_VALUES[expiresIn];
|
|
2258
|
+
}
|
|
2259
|
+
function buildObjectLifecycleHeaders(lifecycle) {
|
|
2260
|
+
if (!lifecycle) {
|
|
2261
|
+
return {};
|
|
2262
|
+
}
|
|
2263
|
+
const expirationDurationSeconds = getExpirationDurationSeconds(lifecycle);
|
|
2264
|
+
if (expirationDurationSeconds === undefined) {
|
|
2265
|
+
return {};
|
|
2266
|
+
}
|
|
2267
|
+
return {
|
|
2268
|
+
[exports.OBJECT_LIFECYCYLE_PREFERENCE_HEADER]: JSON.stringify({
|
|
2269
|
+
expiration_duration_seconds: expirationDurationSeconds
|
|
2270
|
+
})
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
function getExtensionFromContentType(contentType) {
|
|
2274
|
+
var _a17;
|
|
2275
|
+
const [, fileType] = contentType.split("/");
|
|
2276
|
+
return (_a17 = fileType.split(/[-;]/)[0]) !== null && _a17 !== undefined ? _a17 : "bin";
|
|
2277
|
+
}
|
|
2278
|
+
function initiateUpload(file, config, contentType, lifecycle) {
|
|
2279
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2280
|
+
const filename = file.name || `${Date.now()}.${getExtensionFromContentType(contentType)}`;
|
|
2281
|
+
const headers = {};
|
|
2282
|
+
if (lifecycle) {
|
|
2283
|
+
const lifecycleConfig = {
|
|
2284
|
+
expiration_duration_seconds: getExpirationDurationSeconds(lifecycle),
|
|
2285
|
+
allow_io_storage: lifecycle.expiresIn !== "immediate"
|
|
2286
|
+
};
|
|
2287
|
+
headers["X-Fal-Object-Lifecycle"] = JSON.stringify(lifecycleConfig);
|
|
2288
|
+
}
|
|
2289
|
+
return yield (0, request_1.dispatchRequest)({
|
|
2290
|
+
method: "POST",
|
|
2291
|
+
targetUrl: `${(0, config_1.getRestApiUrl)()}/storage/upload/initiate?storage_type=fal-cdn-v3`,
|
|
2292
|
+
input: {
|
|
2293
|
+
content_type: contentType,
|
|
2294
|
+
file_name: filename
|
|
2295
|
+
},
|
|
2296
|
+
config,
|
|
2297
|
+
headers
|
|
2298
|
+
});
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
function initiateMultipartUpload(file, config, contentType, lifecycle) {
|
|
2302
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2303
|
+
const filename = file.name || `${Date.now()}.${getExtensionFromContentType(contentType)}`;
|
|
2304
|
+
const headers = {};
|
|
2305
|
+
if (lifecycle) {
|
|
2306
|
+
headers["X-Fal-Object-Lifecycle"] = JSON.stringify(lifecycle);
|
|
2307
|
+
}
|
|
2308
|
+
return yield (0, request_1.dispatchRequest)({
|
|
2309
|
+
method: "POST",
|
|
2310
|
+
targetUrl: `${(0, config_1.getRestApiUrl)()}/storage/upload/initiate-multipart?storage_type=fal-cdn-v3`,
|
|
2311
|
+
input: {
|
|
2312
|
+
content_type: contentType,
|
|
2313
|
+
file_name: filename
|
|
2314
|
+
},
|
|
2315
|
+
config,
|
|
2316
|
+
headers
|
|
2317
|
+
});
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
function partUploadRetries(uploadUrl_1, chunk_1, config_2) {
|
|
2321
|
+
return __awaiter(this, arguments, undefined, function* (uploadUrl, chunk, config, tries = 3) {
|
|
2322
|
+
if (tries === 0) {
|
|
2323
|
+
throw new Error("Part upload failed, retries exhausted");
|
|
2324
|
+
}
|
|
2325
|
+
const { fetch: fetch2, responseHandler } = config;
|
|
2326
|
+
try {
|
|
2327
|
+
const response = yield fetch2(uploadUrl, {
|
|
2328
|
+
method: "PUT",
|
|
2329
|
+
body: chunk
|
|
2330
|
+
});
|
|
2331
|
+
return yield responseHandler(response);
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
return yield partUploadRetries(uploadUrl, chunk, config, tries - 1);
|
|
2334
|
+
}
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
function multipartUpload(file, config, lifecycle) {
|
|
2338
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2339
|
+
const { fetch: fetch2, responseHandler } = config;
|
|
2340
|
+
const contentType = file.type || "application/octet-stream";
|
|
2341
|
+
const { upload_url: uploadUrl, file_url: url } = yield initiateMultipartUpload(file, config, contentType, lifecycle);
|
|
2342
|
+
const chunkSize = 10 * 1024 * 1024;
|
|
2343
|
+
const chunks = Math.ceil(file.size / chunkSize);
|
|
2344
|
+
const parsedUrl = new URL(uploadUrl);
|
|
2345
|
+
const responses = [];
|
|
2346
|
+
for (let i = 0;i < chunks; i++) {
|
|
2347
|
+
const start = i * chunkSize;
|
|
2348
|
+
const end = Math.min(start + chunkSize, file.size);
|
|
2349
|
+
const chunk = file.slice(start, end);
|
|
2350
|
+
const partNumber = i + 1;
|
|
2351
|
+
const partUploadUrl = `${parsedUrl.origin}${parsedUrl.pathname}/${partNumber}${parsedUrl.search}`;
|
|
2352
|
+
responses.push(yield partUploadRetries(partUploadUrl, chunk, config));
|
|
2353
|
+
}
|
|
2354
|
+
const completeUrl = `${parsedUrl.origin}${parsedUrl.pathname}/complete${parsedUrl.search}`;
|
|
2355
|
+
const response = yield fetch2(completeUrl, {
|
|
2356
|
+
method: "POST",
|
|
2357
|
+
headers: {
|
|
2358
|
+
"Content-Type": "application/json"
|
|
2359
|
+
},
|
|
2360
|
+
body: JSON.stringify({
|
|
2361
|
+
parts: responses.map((mpart) => ({
|
|
2362
|
+
partNumber: mpart.partNumber,
|
|
2363
|
+
etag: mpart.etag
|
|
2364
|
+
}))
|
|
2365
|
+
})
|
|
2366
|
+
});
|
|
2367
|
+
yield responseHandler(response);
|
|
2368
|
+
return url;
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
function createStorageClient({ config }) {
|
|
2372
|
+
const ref = {
|
|
2373
|
+
upload: (file, options) => __awaiter(this, undefined, undefined, function* () {
|
|
2374
|
+
const lifecycle = options === null || options === undefined ? undefined : options.lifecycle;
|
|
2375
|
+
if (file.size > 90 * 1024 * 1024) {
|
|
2376
|
+
return yield multipartUpload(file, config, lifecycle);
|
|
2377
|
+
}
|
|
2378
|
+
const contentType = file.type || "application/octet-stream";
|
|
2379
|
+
const { fetch: fetch2, responseHandler } = config;
|
|
2380
|
+
const { upload_url: uploadUrl, file_url: url } = yield initiateUpload(file, config, contentType, lifecycle);
|
|
2381
|
+
const response = yield fetch2(uploadUrl, {
|
|
2382
|
+
method: "PUT",
|
|
2383
|
+
body: file,
|
|
2384
|
+
headers: {
|
|
2385
|
+
"Content-Type": file.type || "application/octet-stream"
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
yield responseHandler(response);
|
|
2389
|
+
return url;
|
|
2390
|
+
}),
|
|
2391
|
+
transformInput: (input) => __awaiter(this, undefined, undefined, function* () {
|
|
2392
|
+
if (Array.isArray(input)) {
|
|
2393
|
+
return Promise.all(input.map((item) => ref.transformInput(item)));
|
|
2394
|
+
} else if (input instanceof Blob) {
|
|
2395
|
+
return yield ref.upload(input);
|
|
2396
|
+
} else if ((0, utils_1.isPlainObject)(input)) {
|
|
2397
|
+
const inputObject = input;
|
|
2398
|
+
const promises = Object.entries(inputObject).map((_a17) => __awaiter(this, [_a17], undefined, function* ([key, value]) {
|
|
2399
|
+
return [key, yield ref.transformInput(value)];
|
|
2400
|
+
}));
|
|
2401
|
+
const results = yield Promise.all(promises);
|
|
2402
|
+
return Object.fromEntries(results);
|
|
2403
|
+
}
|
|
2404
|
+
return input;
|
|
2405
|
+
})
|
|
2406
|
+
};
|
|
2407
|
+
return ref;
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
// ../../node_modules/.bun/eventsource-parser@1.1.2/node_modules/eventsource-parser/dist/index.cjs
|
|
2412
|
+
var require_dist = __commonJS((exports) => {
|
|
2413
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2414
|
+
value: true
|
|
2415
|
+
});
|
|
2416
|
+
function createParser(onParse) {
|
|
2417
|
+
let isFirstChunk;
|
|
2418
|
+
let buffer;
|
|
2419
|
+
let startingPosition;
|
|
2420
|
+
let startingFieldLength;
|
|
2421
|
+
let eventId;
|
|
2422
|
+
let eventName;
|
|
2423
|
+
let data;
|
|
2424
|
+
reset();
|
|
2425
|
+
return {
|
|
2426
|
+
feed,
|
|
2427
|
+
reset
|
|
2428
|
+
};
|
|
2429
|
+
function reset() {
|
|
2430
|
+
isFirstChunk = true;
|
|
2431
|
+
buffer = "";
|
|
2432
|
+
startingPosition = 0;
|
|
2433
|
+
startingFieldLength = -1;
|
|
2434
|
+
eventId = undefined;
|
|
2435
|
+
eventName = undefined;
|
|
2436
|
+
data = "";
|
|
2437
|
+
}
|
|
2438
|
+
function feed(chunk) {
|
|
2439
|
+
buffer = buffer ? buffer + chunk : chunk;
|
|
2440
|
+
if (isFirstChunk && hasBom(buffer)) {
|
|
2441
|
+
buffer = buffer.slice(BOM.length);
|
|
2442
|
+
}
|
|
2443
|
+
isFirstChunk = false;
|
|
2444
|
+
const length = buffer.length;
|
|
2445
|
+
let position = 0;
|
|
2446
|
+
let discardTrailingNewline = false;
|
|
2447
|
+
while (position < length) {
|
|
2448
|
+
if (discardTrailingNewline) {
|
|
2449
|
+
if (buffer[position] === `
|
|
2450
|
+
`) {
|
|
2451
|
+
++position;
|
|
2452
|
+
}
|
|
2453
|
+
discardTrailingNewline = false;
|
|
2454
|
+
}
|
|
2455
|
+
let lineLength = -1;
|
|
2456
|
+
let fieldLength = startingFieldLength;
|
|
2457
|
+
let character;
|
|
2458
|
+
for (let index = startingPosition;lineLength < 0 && index < length; ++index) {
|
|
2459
|
+
character = buffer[index];
|
|
2460
|
+
if (character === ":" && fieldLength < 0) {
|
|
2461
|
+
fieldLength = index - position;
|
|
2462
|
+
} else if (character === "\r") {
|
|
2463
|
+
discardTrailingNewline = true;
|
|
2464
|
+
lineLength = index - position;
|
|
2465
|
+
} else if (character === `
|
|
2466
|
+
`) {
|
|
2467
|
+
lineLength = index - position;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
if (lineLength < 0) {
|
|
2471
|
+
startingPosition = length - position;
|
|
2472
|
+
startingFieldLength = fieldLength;
|
|
2473
|
+
break;
|
|
2474
|
+
} else {
|
|
2475
|
+
startingPosition = 0;
|
|
2476
|
+
startingFieldLength = -1;
|
|
2477
|
+
}
|
|
2478
|
+
parseEventStreamLine(buffer, position, fieldLength, lineLength);
|
|
2479
|
+
position += lineLength + 1;
|
|
2480
|
+
}
|
|
2481
|
+
if (position === length) {
|
|
2482
|
+
buffer = "";
|
|
2483
|
+
} else if (position > 0) {
|
|
2484
|
+
buffer = buffer.slice(position);
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
function parseEventStreamLine(lineBuffer, index, fieldLength, lineLength) {
|
|
2488
|
+
if (lineLength === 0) {
|
|
2489
|
+
if (data.length > 0) {
|
|
2490
|
+
onParse({
|
|
2491
|
+
type: "event",
|
|
2492
|
+
id: eventId,
|
|
2493
|
+
event: eventName || undefined,
|
|
2494
|
+
data: data.slice(0, -1)
|
|
2495
|
+
});
|
|
2496
|
+
data = "";
|
|
2497
|
+
eventId = undefined;
|
|
2498
|
+
}
|
|
2499
|
+
eventName = undefined;
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
const noValue = fieldLength < 0;
|
|
2503
|
+
const field = lineBuffer.slice(index, index + (noValue ? lineLength : fieldLength));
|
|
2504
|
+
let step = 0;
|
|
2505
|
+
if (noValue) {
|
|
2506
|
+
step = lineLength;
|
|
2507
|
+
} else if (lineBuffer[index + fieldLength + 1] === " ") {
|
|
2508
|
+
step = fieldLength + 2;
|
|
2509
|
+
} else {
|
|
2510
|
+
step = fieldLength + 1;
|
|
2511
|
+
}
|
|
2512
|
+
const position = index + step;
|
|
2513
|
+
const valueLength = lineLength - step;
|
|
2514
|
+
const value = lineBuffer.slice(position, position + valueLength).toString();
|
|
2515
|
+
if (field === "data") {
|
|
2516
|
+
data += value ? "".concat(value, `
|
|
2517
|
+
`) : `
|
|
2518
|
+
`;
|
|
2519
|
+
} else if (field === "event") {
|
|
2520
|
+
eventName = value;
|
|
2521
|
+
} else if (field === "id" && !value.includes("\x00")) {
|
|
2522
|
+
eventId = value;
|
|
2523
|
+
} else if (field === "retry") {
|
|
2524
|
+
const retry = parseInt(value, 10);
|
|
2525
|
+
if (!Number.isNaN(retry)) {
|
|
2526
|
+
onParse({
|
|
2527
|
+
type: "reconnect-interval",
|
|
2528
|
+
value: retry
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
var BOM = [239, 187, 191];
|
|
2535
|
+
function hasBom(buffer) {
|
|
2536
|
+
return BOM.every((charCode, index) => buffer.charCodeAt(index) === charCode);
|
|
2537
|
+
}
|
|
2538
|
+
exports.createParser = createParser;
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2541
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/auth.js
|
|
2542
|
+
var require_auth = __commonJS((exports) => {
|
|
2543
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2544
|
+
function adopt(value) {
|
|
2545
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
2546
|
+
resolve(value);
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2550
|
+
function fulfilled(value) {
|
|
2551
|
+
try {
|
|
2552
|
+
step(generator.next(value));
|
|
2553
|
+
} catch (e) {
|
|
2554
|
+
reject(e);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
function rejected(value) {
|
|
2558
|
+
try {
|
|
2559
|
+
step(generator["throw"](value));
|
|
2560
|
+
} catch (e) {
|
|
2561
|
+
reject(e);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
function step(result) {
|
|
2565
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2566
|
+
}
|
|
2567
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2568
|
+
});
|
|
2569
|
+
};
|
|
2570
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2571
|
+
exports.TOKEN_EXPIRATION_SECONDS = undefined;
|
|
2572
|
+
exports.getTemporaryAuthToken = getTemporaryAuthToken;
|
|
2573
|
+
var config_1 = require_config();
|
|
2574
|
+
var request_1 = require_request();
|
|
2575
|
+
var utils_1 = require_utils3();
|
|
2576
|
+
exports.TOKEN_EXPIRATION_SECONDS = 120;
|
|
2577
|
+
function getTemporaryAuthToken(app, config) {
|
|
2578
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2579
|
+
const appId = (0, utils_1.parseEndpointId)(app);
|
|
2580
|
+
const token = yield (0, request_1.dispatchRequest)({
|
|
2581
|
+
method: "POST",
|
|
2582
|
+
targetUrl: `${(0, config_1.getRestApiUrl)()}/tokens/`,
|
|
2583
|
+
config,
|
|
2584
|
+
input: {
|
|
2585
|
+
allowed_apps: [appId.alias],
|
|
2586
|
+
token_expiration: exports.TOKEN_EXPIRATION_SECONDS
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
if (typeof token !== "string" && token["detail"]) {
|
|
2590
|
+
return token["detail"];
|
|
2591
|
+
}
|
|
2592
|
+
return token;
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
2596
|
+
|
|
2597
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/streaming.js
|
|
2598
|
+
var require_streaming = __commonJS((exports) => {
|
|
2599
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2600
|
+
function adopt(value) {
|
|
2601
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
2602
|
+
resolve(value);
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2606
|
+
function fulfilled(value) {
|
|
2607
|
+
try {
|
|
2608
|
+
step(generator.next(value));
|
|
2609
|
+
} catch (e) {
|
|
2610
|
+
reject(e);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
function rejected(value) {
|
|
2614
|
+
try {
|
|
2615
|
+
step(generator["throw"](value));
|
|
2616
|
+
} catch (e) {
|
|
2617
|
+
reject(e);
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
function step(result) {
|
|
2621
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2622
|
+
}
|
|
2623
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2624
|
+
});
|
|
2625
|
+
};
|
|
2626
|
+
var __await = exports && exports.__await || function(v) {
|
|
2627
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
2628
|
+
};
|
|
2629
|
+
var __asyncGenerator = exports && exports.__asyncGenerator || function(thisArg, _arguments, generator) {
|
|
2630
|
+
if (!Symbol.asyncIterator)
|
|
2631
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2632
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
2633
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
|
|
2634
|
+
return this;
|
|
2635
|
+
}, i;
|
|
2636
|
+
function awaitReturn(f) {
|
|
2637
|
+
return function(v) {
|
|
2638
|
+
return Promise.resolve(v).then(f, reject);
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
function verb(n, f) {
|
|
2642
|
+
if (g[n]) {
|
|
2643
|
+
i[n] = function(v) {
|
|
2644
|
+
return new Promise(function(a, b) {
|
|
2645
|
+
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
if (f)
|
|
2649
|
+
i[n] = f(i[n]);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
function resume(n, v) {
|
|
2653
|
+
try {
|
|
2654
|
+
step(g[n](v));
|
|
2655
|
+
} catch (e) {
|
|
2656
|
+
settle(q[0][3], e);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
function step(r) {
|
|
2660
|
+
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
2661
|
+
}
|
|
2662
|
+
function fulfill(value) {
|
|
2663
|
+
resume("next", value);
|
|
2664
|
+
}
|
|
2665
|
+
function reject(value) {
|
|
2666
|
+
resume("throw", value);
|
|
2667
|
+
}
|
|
2668
|
+
function settle(f, v) {
|
|
2669
|
+
if (f(v), q.shift(), q.length)
|
|
2670
|
+
resume(q[0][0], q[0][1]);
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2674
|
+
exports.FalStream = undefined;
|
|
2675
|
+
exports.createStreamingClient = createStreamingClient;
|
|
2676
|
+
var eventsource_parser_1 = require_dist();
|
|
2677
|
+
var auth_1 = require_auth();
|
|
2678
|
+
var request_1 = require_request();
|
|
2679
|
+
var response_1 = require_response();
|
|
2680
|
+
var CONTENT_TYPE_EVENT_STREAM = "text/event-stream";
|
|
2681
|
+
var EVENT_STREAM_TIMEOUT = 15 * 1000;
|
|
2682
|
+
|
|
2683
|
+
class FalStream {
|
|
2684
|
+
constructor(endpointId, config, options) {
|
|
2685
|
+
var _a17;
|
|
2686
|
+
this.listeners = new Map;
|
|
2687
|
+
this.buffer = [];
|
|
2688
|
+
this.currentData = undefined;
|
|
2689
|
+
this.lastEventTimestamp = 0;
|
|
2690
|
+
this.streamClosed = false;
|
|
2691
|
+
this._requestId = null;
|
|
2692
|
+
this.abortController = new AbortController;
|
|
2693
|
+
this.start = () => __awaiter(this, undefined, undefined, function* () {
|
|
2694
|
+
var _a18, _b;
|
|
2695
|
+
const { endpointId: endpointId2, options: options2 } = this;
|
|
2696
|
+
const { input, method = "post", connectionMode = "server" } = options2;
|
|
2697
|
+
try {
|
|
2698
|
+
if (connectionMode === "client") {
|
|
2699
|
+
const token = yield (0, auth_1.getTemporaryAuthToken)(endpointId2, this.config);
|
|
2700
|
+
const { fetch: fetch2 } = this.config;
|
|
2701
|
+
const parsedUrl = new URL(this.url);
|
|
2702
|
+
parsedUrl.searchParams.set("fal_jwt_token", token);
|
|
2703
|
+
const response = yield fetch2(parsedUrl.toString(), {
|
|
2704
|
+
method: method.toUpperCase(),
|
|
2705
|
+
headers: {
|
|
2706
|
+
accept: (_a18 = options2.accept) !== null && _a18 !== undefined ? _a18 : CONTENT_TYPE_EVENT_STREAM,
|
|
2707
|
+
"content-type": "application/json"
|
|
2708
|
+
},
|
|
2709
|
+
body: input && method !== "get" ? JSON.stringify(input) : undefined,
|
|
2710
|
+
signal: this.abortController.signal
|
|
2711
|
+
});
|
|
2712
|
+
this._requestId = response.headers.get("x-fal-request-id");
|
|
2713
|
+
return yield this.handleResponse(response);
|
|
2714
|
+
}
|
|
2715
|
+
return yield (0, request_1.dispatchRequest)({
|
|
2716
|
+
method: method.toUpperCase(),
|
|
2717
|
+
targetUrl: this.url,
|
|
2718
|
+
input,
|
|
2719
|
+
config: this.config,
|
|
2720
|
+
options: {
|
|
2721
|
+
headers: {
|
|
2722
|
+
accept: (_b = options2.accept) !== null && _b !== undefined ? _b : CONTENT_TYPE_EVENT_STREAM
|
|
2723
|
+
},
|
|
2724
|
+
responseHandler: (response) => __awaiter(this, undefined, undefined, function* () {
|
|
2725
|
+
this._requestId = response.headers.get("x-fal-request-id");
|
|
2726
|
+
return yield this.handleResponse(response);
|
|
2727
|
+
}),
|
|
2728
|
+
signal: this.abortController.signal
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
} catch (error) {
|
|
2732
|
+
this.handleError(error);
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
this.handleResponse = (response) => __awaiter(this, undefined, undefined, function* () {
|
|
2736
|
+
var _a18, _b;
|
|
2737
|
+
if (!response.ok) {
|
|
2738
|
+
try {
|
|
2739
|
+
yield (0, response_1.defaultResponseHandler)(response);
|
|
2740
|
+
} catch (error) {
|
|
2741
|
+
this.emit("error", error);
|
|
2742
|
+
}
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
const body = response.body;
|
|
2746
|
+
if (!body) {
|
|
2747
|
+
this.emit("error", new response_1.ApiError({
|
|
2748
|
+
message: "Response body is empty.",
|
|
2749
|
+
status: 400,
|
|
2750
|
+
body: undefined,
|
|
2751
|
+
requestId: this._requestId || undefined
|
|
2752
|
+
}));
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
const isEventStream = ((_a18 = response.headers.get("content-type")) !== null && _a18 !== undefined ? _a18 : "").startsWith(CONTENT_TYPE_EVENT_STREAM);
|
|
2756
|
+
if (!isEventStream) {
|
|
2757
|
+
const reader2 = body.getReader();
|
|
2758
|
+
const emitRawChunk = () => {
|
|
2759
|
+
reader2.read().then(({ done, value }) => {
|
|
2760
|
+
if (done) {
|
|
2761
|
+
this.emit("done", this.currentData);
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
this.buffer.push(value);
|
|
2765
|
+
this.currentData = value;
|
|
2766
|
+
this.emit("data", value);
|
|
2767
|
+
emitRawChunk();
|
|
2768
|
+
});
|
|
2769
|
+
};
|
|
2770
|
+
emitRawChunk();
|
|
2771
|
+
return;
|
|
2772
|
+
}
|
|
2773
|
+
const decoder = new TextDecoder("utf-8");
|
|
2774
|
+
const reader = response.body.getReader();
|
|
2775
|
+
const parser = (0, eventsource_parser_1.createParser)((event) => {
|
|
2776
|
+
if (event.type === "event") {
|
|
2777
|
+
const data = event.data;
|
|
2778
|
+
try {
|
|
2779
|
+
const parsedData = JSON.parse(data);
|
|
2780
|
+
this.buffer.push(parsedData);
|
|
2781
|
+
this.currentData = parsedData;
|
|
2782
|
+
this.emit("data", parsedData);
|
|
2783
|
+
this.emit("message", parsedData);
|
|
2784
|
+
} catch (e) {
|
|
2785
|
+
this.emit("error", e);
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
const timeout = (_b = this.options.timeout) !== null && _b !== undefined ? _b : EVENT_STREAM_TIMEOUT;
|
|
2790
|
+
const readPartialResponse = () => __awaiter(this, undefined, undefined, function* () {
|
|
2791
|
+
const { value, done } = yield reader.read();
|
|
2792
|
+
this.lastEventTimestamp = Date.now();
|
|
2793
|
+
parser.feed(decoder.decode(value));
|
|
2794
|
+
if (Date.now() - this.lastEventTimestamp > timeout) {
|
|
2795
|
+
this.emit("error", new response_1.ApiError({
|
|
2796
|
+
message: `Event stream timed out after ${(timeout / 1000).toFixed(0)} seconds with no messages.`,
|
|
2797
|
+
status: 408,
|
|
2798
|
+
requestId: this._requestId || undefined
|
|
2799
|
+
}));
|
|
2800
|
+
}
|
|
2801
|
+
if (!done) {
|
|
2802
|
+
readPartialResponse().catch(this.handleError);
|
|
2803
|
+
} else {
|
|
2804
|
+
this.emit("done", this.currentData);
|
|
2805
|
+
}
|
|
2806
|
+
});
|
|
2807
|
+
readPartialResponse().catch(this.handleError);
|
|
2808
|
+
return;
|
|
2809
|
+
});
|
|
2810
|
+
this.handleError = (error) => {
|
|
2811
|
+
var _a18;
|
|
2812
|
+
if (error.name === "AbortError" || this.signal.aborted) {
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2815
|
+
const apiError = error instanceof response_1.ApiError ? error : new response_1.ApiError({
|
|
2816
|
+
message: (_a18 = error.message) !== null && _a18 !== undefined ? _a18 : "An unknown error occurred",
|
|
2817
|
+
status: 500,
|
|
2818
|
+
requestId: this._requestId || undefined
|
|
2819
|
+
});
|
|
2820
|
+
this.emit("error", apiError);
|
|
2821
|
+
return;
|
|
2822
|
+
};
|
|
2823
|
+
this.on = (type, listener) => {
|
|
2824
|
+
var _a18;
|
|
2825
|
+
if (!this.listeners.has(type)) {
|
|
2826
|
+
this.listeners.set(type, []);
|
|
2827
|
+
}
|
|
2828
|
+
(_a18 = this.listeners.get(type)) === null || _a18 === undefined || _a18.push(listener);
|
|
2829
|
+
};
|
|
2830
|
+
this.emit = (type, event) => {
|
|
2831
|
+
const listeners = this.listeners.get(type) || [];
|
|
2832
|
+
for (const listener of listeners) {
|
|
2833
|
+
listener(event);
|
|
2834
|
+
}
|
|
2835
|
+
};
|
|
2836
|
+
this.done = () => __awaiter(this, undefined, undefined, function* () {
|
|
2837
|
+
return this.donePromise;
|
|
2838
|
+
});
|
|
2839
|
+
this.abort = (reason) => {
|
|
2840
|
+
if (!this.streamClosed) {
|
|
2841
|
+
this.abortController.abort(reason);
|
|
2842
|
+
}
|
|
2843
|
+
};
|
|
2844
|
+
this.endpointId = endpointId;
|
|
2845
|
+
this.config = config;
|
|
2846
|
+
this.url = (_a17 = options.url) !== null && _a17 !== undefined ? _a17 : (0, request_1.buildUrl)(endpointId, {
|
|
2847
|
+
path: "/stream",
|
|
2848
|
+
query: options.queryParams
|
|
2849
|
+
});
|
|
2850
|
+
this.options = options;
|
|
2851
|
+
this.donePromise = new Promise((resolve, reject) => {
|
|
2852
|
+
if (this.streamClosed) {
|
|
2853
|
+
reject(new response_1.ApiError({
|
|
2854
|
+
message: "Streaming connection is already closed.",
|
|
2855
|
+
status: 400,
|
|
2856
|
+
body: undefined,
|
|
2857
|
+
requestId: this._requestId || undefined
|
|
2858
|
+
}));
|
|
2859
|
+
}
|
|
2860
|
+
this.signal.addEventListener("abort", () => {
|
|
2861
|
+
var _a18;
|
|
2862
|
+
resolve((_a18 = this.currentData) !== null && _a18 !== undefined ? _a18 : {});
|
|
2863
|
+
});
|
|
2864
|
+
this.on("done", (data) => {
|
|
2865
|
+
this.streamClosed = true;
|
|
2866
|
+
resolve(data);
|
|
2867
|
+
});
|
|
2868
|
+
this.on("error", (error) => {
|
|
2869
|
+
this.streamClosed = true;
|
|
2870
|
+
reject(error);
|
|
2871
|
+
});
|
|
2872
|
+
});
|
|
2873
|
+
if (options.signal) {
|
|
2874
|
+
options.signal.addEventListener("abort", () => {
|
|
2875
|
+
this.abortController.abort();
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
this.start().catch(this.handleError);
|
|
2879
|
+
}
|
|
2880
|
+
[Symbol.asyncIterator]() {
|
|
2881
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
2882
|
+
let running = true;
|
|
2883
|
+
const stopAsyncIterator = () => running = false;
|
|
2884
|
+
this.on("error", stopAsyncIterator);
|
|
2885
|
+
this.on("done", stopAsyncIterator);
|
|
2886
|
+
while (running || this.buffer.length > 0) {
|
|
2887
|
+
const data = this.buffer.shift();
|
|
2888
|
+
if (data) {
|
|
2889
|
+
yield yield __await(data);
|
|
2890
|
+
}
|
|
2891
|
+
yield __await(new Promise((resolve) => setTimeout(resolve, 16)));
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
get signal() {
|
|
2896
|
+
return this.abortController.signal;
|
|
2897
|
+
}
|
|
2898
|
+
get requestId() {
|
|
2899
|
+
return this._requestId;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
exports.FalStream = FalStream;
|
|
2903
|
+
function createStreamingClient({ config, storage }) {
|
|
2904
|
+
return {
|
|
2905
|
+
stream(endpointId, options) {
|
|
2906
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2907
|
+
const input = options.input ? yield storage.transformInput(options.input) : undefined;
|
|
2908
|
+
return new FalStream(endpointId, config, Object.assign(Object.assign({}, options), { input }));
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
});
|
|
2914
|
+
|
|
2915
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/queue.js
|
|
2916
|
+
var require_queue = __commonJS((exports) => {
|
|
2917
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2918
|
+
function adopt(value) {
|
|
2919
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
2920
|
+
resolve(value);
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2924
|
+
function fulfilled(value) {
|
|
2925
|
+
try {
|
|
2926
|
+
step(generator.next(value));
|
|
2927
|
+
} catch (e) {
|
|
2928
|
+
reject(e);
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
function rejected(value) {
|
|
2932
|
+
try {
|
|
2933
|
+
step(generator["throw"](value));
|
|
2934
|
+
} catch (e) {
|
|
2935
|
+
reject(e);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
function step(result) {
|
|
2939
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2940
|
+
}
|
|
2941
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2942
|
+
});
|
|
2943
|
+
};
|
|
2944
|
+
var __rest = exports && exports.__rest || function(s, e) {
|
|
2945
|
+
var t = {};
|
|
2946
|
+
for (var p in s)
|
|
2947
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
2948
|
+
t[p] = s[p];
|
|
2949
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
2950
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s);i < p.length; i++) {
|
|
2951
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
2952
|
+
t[p[i]] = s[p[i]];
|
|
2953
|
+
}
|
|
2954
|
+
return t;
|
|
2955
|
+
};
|
|
2956
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2957
|
+
exports.createQueueClient = undefined;
|
|
2958
|
+
var request_1 = require_request();
|
|
2959
|
+
var response_1 = require_response();
|
|
2960
|
+
var retry_1 = require_retry();
|
|
2961
|
+
var storage_1 = require_storage();
|
|
2962
|
+
var streaming_1 = require_streaming();
|
|
2963
|
+
var utils_1 = require_utils3();
|
|
2964
|
+
var DEFAULT_POLL_INTERVAL = 500;
|
|
2965
|
+
var QUEUE_PRIORITY_HEADER = "x-fal-queue-priority";
|
|
2966
|
+
var RUNNER_HINT_HEADER = "x-fal-runner-hint";
|
|
2967
|
+
var QUEUE_RETRY_CONFIG = {
|
|
2968
|
+
maxRetries: 3,
|
|
2969
|
+
baseDelay: 1000,
|
|
2970
|
+
maxDelay: 60000,
|
|
2971
|
+
retryableStatusCodes: retry_1.DEFAULT_RETRYABLE_STATUS_CODES
|
|
2972
|
+
};
|
|
2973
|
+
var QUEUE_STATUS_RETRY_CONFIG = {
|
|
2974
|
+
maxRetries: 5,
|
|
2975
|
+
baseDelay: 1000,
|
|
2976
|
+
maxDelay: 30000,
|
|
2977
|
+
retryableStatusCodes: [...retry_1.DEFAULT_RETRYABLE_STATUS_CODES, 500]
|
|
2978
|
+
};
|
|
2979
|
+
var createQueueClient = ({ config, storage }) => {
|
|
2980
|
+
const ref = {
|
|
2981
|
+
submit(endpointId, options) {
|
|
2982
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
2983
|
+
const { webhookUrl, priority, hint, headers, storageSettings } = options, runOptions = __rest(options, ["webhookUrl", "priority", "hint", "headers", "storageSettings"]);
|
|
2984
|
+
const input = options.input ? yield storage.transformInput(options.input) : undefined;
|
|
2985
|
+
const extraHeaders = Object.fromEntries(Object.entries(headers !== null && headers !== undefined ? headers : {}).map(([key, value]) => [
|
|
2986
|
+
key.toLowerCase(),
|
|
2987
|
+
value
|
|
2988
|
+
]));
|
|
2989
|
+
return (0, request_1.dispatchRequest)({
|
|
2990
|
+
method: options.method,
|
|
2991
|
+
targetUrl: (0, request_1.buildUrl)(endpointId, Object.assign(Object.assign({}, runOptions), { subdomain: "queue", query: webhookUrl ? { fal_webhook: webhookUrl } : undefined })),
|
|
2992
|
+
headers: Object.assign(Object.assign(Object.assign(Object.assign({}, extraHeaders), (0, storage_1.buildObjectLifecycleHeaders)(storageSettings)), { [QUEUE_PRIORITY_HEADER]: priority !== null && priority !== undefined ? priority : "normal" }), hint && { [RUNNER_HINT_HEADER]: hint }),
|
|
2993
|
+
input,
|
|
2994
|
+
config,
|
|
2995
|
+
options: {
|
|
2996
|
+
signal: options.abortSignal,
|
|
2997
|
+
retry: QUEUE_RETRY_CONFIG
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
});
|
|
3001
|
+
},
|
|
3002
|
+
status(endpointId_1, _a17) {
|
|
3003
|
+
return __awaiter(this, arguments, undefined, function* (endpointId, { requestId, logs = false, abortSignal }) {
|
|
3004
|
+
const appId = (0, utils_1.parseEndpointId)(endpointId);
|
|
3005
|
+
const prefix = appId.namespace ? `${appId.namespace}/` : "";
|
|
3006
|
+
return (0, request_1.dispatchRequest)({
|
|
3007
|
+
method: "get",
|
|
3008
|
+
targetUrl: (0, request_1.buildUrl)(`${prefix}${appId.owner}/${appId.alias}`, {
|
|
3009
|
+
subdomain: "queue",
|
|
3010
|
+
query: { logs: logs ? "1" : "0" },
|
|
3011
|
+
path: `/requests/${requestId}/status`
|
|
3012
|
+
}),
|
|
3013
|
+
config,
|
|
3014
|
+
options: {
|
|
3015
|
+
signal: abortSignal,
|
|
3016
|
+
retry: QUEUE_STATUS_RETRY_CONFIG
|
|
3017
|
+
}
|
|
3018
|
+
});
|
|
3019
|
+
});
|
|
3020
|
+
},
|
|
3021
|
+
streamStatus(endpointId_1, _a17) {
|
|
3022
|
+
return __awaiter(this, arguments, undefined, function* (endpointId, { requestId, logs = false, connectionMode }) {
|
|
3023
|
+
const appId = (0, utils_1.parseEndpointId)(endpointId);
|
|
3024
|
+
const prefix = appId.namespace ? `${appId.namespace}/` : "";
|
|
3025
|
+
const queryParams = {
|
|
3026
|
+
logs: logs ? "1" : "0"
|
|
3027
|
+
};
|
|
3028
|
+
const url = (0, request_1.buildUrl)(`${prefix}${appId.owner}/${appId.alias}`, {
|
|
3029
|
+
subdomain: "queue",
|
|
3030
|
+
path: `/requests/${requestId}/status/stream`,
|
|
3031
|
+
query: queryParams
|
|
3032
|
+
});
|
|
3033
|
+
return new streaming_1.FalStream(endpointId, config, {
|
|
3034
|
+
url,
|
|
3035
|
+
method: "get",
|
|
3036
|
+
connectionMode,
|
|
3037
|
+
queryParams
|
|
3038
|
+
});
|
|
3039
|
+
});
|
|
3040
|
+
},
|
|
3041
|
+
subscribeToStatus(endpointId, options) {
|
|
3042
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
3043
|
+
const requestId = options.requestId;
|
|
3044
|
+
const timeout = options.timeout;
|
|
3045
|
+
let timeoutId = undefined;
|
|
3046
|
+
const handleCancelError = () => {};
|
|
3047
|
+
if (options.mode === "streaming") {
|
|
3048
|
+
const status = yield ref.streamStatus(endpointId, {
|
|
3049
|
+
requestId,
|
|
3050
|
+
logs: options.logs,
|
|
3051
|
+
connectionMode: "connectionMode" in options ? options.connectionMode : undefined
|
|
3052
|
+
});
|
|
3053
|
+
const logs = [];
|
|
3054
|
+
if (timeout) {
|
|
3055
|
+
timeoutId = setTimeout(() => {
|
|
3056
|
+
status.abort();
|
|
3057
|
+
ref.cancel(endpointId, { requestId }).catch(handleCancelError);
|
|
3058
|
+
throw new Error(`Client timed out waiting for the request to complete after ${timeout}ms`);
|
|
3059
|
+
}, timeout);
|
|
3060
|
+
}
|
|
3061
|
+
status.on("data", (data) => {
|
|
3062
|
+
if (options.onQueueUpdate) {
|
|
3063
|
+
if ("logs" in data && Array.isArray(data.logs) && data.logs.length > 0) {
|
|
3064
|
+
logs.push(...data.logs);
|
|
3065
|
+
}
|
|
3066
|
+
options.onQueueUpdate("logs" in data ? Object.assign(Object.assign({}, data), { logs }) : data);
|
|
3067
|
+
}
|
|
3068
|
+
});
|
|
3069
|
+
const doneStatus = yield status.done();
|
|
3070
|
+
if (timeoutId) {
|
|
3071
|
+
clearTimeout(timeoutId);
|
|
3072
|
+
}
|
|
3073
|
+
return doneStatus;
|
|
3074
|
+
}
|
|
3075
|
+
return new Promise((resolve, reject) => {
|
|
3076
|
+
var _a17;
|
|
3077
|
+
let pollingTimeoutId;
|
|
3078
|
+
const pollInterval = "pollInterval" in options && typeof options.pollInterval === "number" ? (_a17 = options.pollInterval) !== null && _a17 !== undefined ? _a17 : DEFAULT_POLL_INTERVAL : DEFAULT_POLL_INTERVAL;
|
|
3079
|
+
const clearScheduledTasks = () => {
|
|
3080
|
+
if (timeoutId) {
|
|
3081
|
+
clearTimeout(timeoutId);
|
|
3082
|
+
}
|
|
3083
|
+
if (pollingTimeoutId) {
|
|
3084
|
+
clearTimeout(pollingTimeoutId);
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
if (timeout) {
|
|
3088
|
+
timeoutId = setTimeout(() => {
|
|
3089
|
+
clearScheduledTasks();
|
|
3090
|
+
ref.cancel(endpointId, { requestId }).catch(handleCancelError);
|
|
3091
|
+
reject(new Error(`Client timed out waiting for the request to complete after ${timeout}ms`));
|
|
3092
|
+
}, timeout);
|
|
3093
|
+
}
|
|
3094
|
+
const poll = () => __awaiter(this, undefined, undefined, function* () {
|
|
3095
|
+
var _a18;
|
|
3096
|
+
try {
|
|
3097
|
+
const requestStatus = yield ref.status(endpointId, {
|
|
3098
|
+
requestId,
|
|
3099
|
+
logs: (_a18 = options.logs) !== null && _a18 !== undefined ? _a18 : false,
|
|
3100
|
+
abortSignal: options.abortSignal
|
|
3101
|
+
});
|
|
3102
|
+
if (options.onQueueUpdate) {
|
|
3103
|
+
options.onQueueUpdate(requestStatus);
|
|
3104
|
+
}
|
|
3105
|
+
if (requestStatus.status === "COMPLETED") {
|
|
3106
|
+
clearScheduledTasks();
|
|
3107
|
+
resolve(requestStatus);
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
pollingTimeoutId = setTimeout(poll, pollInterval);
|
|
3111
|
+
} catch (error) {
|
|
3112
|
+
clearScheduledTasks();
|
|
3113
|
+
reject(error);
|
|
3114
|
+
}
|
|
3115
|
+
});
|
|
3116
|
+
poll().catch(reject);
|
|
3117
|
+
});
|
|
3118
|
+
});
|
|
3119
|
+
},
|
|
3120
|
+
result(endpointId_1, _a17) {
|
|
3121
|
+
return __awaiter(this, arguments, undefined, function* (endpointId, { requestId, abortSignal }) {
|
|
3122
|
+
const appId = (0, utils_1.parseEndpointId)(endpointId);
|
|
3123
|
+
const prefix = appId.namespace ? `${appId.namespace}/` : "";
|
|
3124
|
+
return (0, request_1.dispatchRequest)({
|
|
3125
|
+
method: "get",
|
|
3126
|
+
targetUrl: (0, request_1.buildUrl)(`${prefix}${appId.owner}/${appId.alias}`, {
|
|
3127
|
+
subdomain: "queue",
|
|
3128
|
+
path: `/requests/${requestId}`
|
|
3129
|
+
}),
|
|
3130
|
+
config: Object.assign(Object.assign({}, config), { responseHandler: response_1.resultResponseHandler }),
|
|
3131
|
+
options: {
|
|
3132
|
+
signal: abortSignal,
|
|
3133
|
+
retry: QUEUE_RETRY_CONFIG
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3136
|
+
});
|
|
3137
|
+
},
|
|
3138
|
+
cancel(endpointId_1, _a17) {
|
|
3139
|
+
return __awaiter(this, arguments, undefined, function* (endpointId, { requestId, abortSignal }) {
|
|
3140
|
+
const appId = (0, utils_1.parseEndpointId)(endpointId);
|
|
3141
|
+
const prefix = appId.namespace ? `${appId.namespace}/` : "";
|
|
3142
|
+
yield (0, request_1.dispatchRequest)({
|
|
3143
|
+
method: "put",
|
|
3144
|
+
targetUrl: (0, request_1.buildUrl)(`${prefix}${appId.owner}/${appId.alias}`, {
|
|
3145
|
+
subdomain: "queue",
|
|
3146
|
+
path: `/requests/${requestId}/cancel`
|
|
3147
|
+
}),
|
|
3148
|
+
config,
|
|
3149
|
+
options: {
|
|
3150
|
+
signal: abortSignal
|
|
3151
|
+
}
|
|
3152
|
+
});
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
};
|
|
3156
|
+
return ref;
|
|
3157
|
+
};
|
|
3158
|
+
exports.createQueueClient = createQueueClient;
|
|
3159
|
+
});
|
|
3160
|
+
|
|
3161
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs
|
|
3162
|
+
var require_utf8 = __commonJS((exports) => {
|
|
3163
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3164
|
+
exports.utf8Count = utf8Count;
|
|
3165
|
+
exports.utf8EncodeJs = utf8EncodeJs;
|
|
3166
|
+
exports.utf8EncodeTE = utf8EncodeTE;
|
|
3167
|
+
exports.utf8Encode = utf8Encode;
|
|
3168
|
+
exports.utf8DecodeJs = utf8DecodeJs;
|
|
3169
|
+
exports.utf8DecodeTD = utf8DecodeTD;
|
|
3170
|
+
exports.utf8Decode = utf8Decode;
|
|
3171
|
+
function utf8Count(str) {
|
|
3172
|
+
const strLength = str.length;
|
|
3173
|
+
let byteLength = 0;
|
|
3174
|
+
let pos = 0;
|
|
3175
|
+
while (pos < strLength) {
|
|
3176
|
+
let value = str.charCodeAt(pos++);
|
|
3177
|
+
if ((value & 4294967168) === 0) {
|
|
3178
|
+
byteLength++;
|
|
3179
|
+
continue;
|
|
3180
|
+
} else if ((value & 4294965248) === 0) {
|
|
3181
|
+
byteLength += 2;
|
|
3182
|
+
} else {
|
|
3183
|
+
if (value >= 55296 && value <= 56319) {
|
|
3184
|
+
if (pos < strLength) {
|
|
3185
|
+
const extra = str.charCodeAt(pos);
|
|
3186
|
+
if ((extra & 64512) === 56320) {
|
|
3187
|
+
++pos;
|
|
3188
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
if ((value & 4294901760) === 0) {
|
|
3193
|
+
byteLength += 3;
|
|
3194
|
+
} else {
|
|
3195
|
+
byteLength += 4;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
return byteLength;
|
|
3200
|
+
}
|
|
3201
|
+
function utf8EncodeJs(str, output, outputOffset) {
|
|
3202
|
+
const strLength = str.length;
|
|
3203
|
+
let offset = outputOffset;
|
|
3204
|
+
let pos = 0;
|
|
3205
|
+
while (pos < strLength) {
|
|
3206
|
+
let value = str.charCodeAt(pos++);
|
|
3207
|
+
if ((value & 4294967168) === 0) {
|
|
3208
|
+
output[offset++] = value;
|
|
3209
|
+
continue;
|
|
3210
|
+
} else if ((value & 4294965248) === 0) {
|
|
3211
|
+
output[offset++] = value >> 6 & 31 | 192;
|
|
3212
|
+
} else {
|
|
3213
|
+
if (value >= 55296 && value <= 56319) {
|
|
3214
|
+
if (pos < strLength) {
|
|
3215
|
+
const extra = str.charCodeAt(pos);
|
|
3216
|
+
if ((extra & 64512) === 56320) {
|
|
3217
|
+
++pos;
|
|
3218
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
if ((value & 4294901760) === 0) {
|
|
3223
|
+
output[offset++] = value >> 12 & 15 | 224;
|
|
3224
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
3225
|
+
} else {
|
|
3226
|
+
output[offset++] = value >> 18 & 7 | 240;
|
|
3227
|
+
output[offset++] = value >> 12 & 63 | 128;
|
|
3228
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
output[offset++] = value & 63 | 128;
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
var sharedTextEncoder = new TextEncoder;
|
|
3235
|
+
var TEXT_ENCODER_THRESHOLD = 50;
|
|
3236
|
+
function utf8EncodeTE(str, output, outputOffset) {
|
|
3237
|
+
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
3238
|
+
}
|
|
3239
|
+
function utf8Encode(str, output, outputOffset) {
|
|
3240
|
+
if (str.length > TEXT_ENCODER_THRESHOLD) {
|
|
3241
|
+
utf8EncodeTE(str, output, outputOffset);
|
|
3242
|
+
} else {
|
|
3243
|
+
utf8EncodeJs(str, output, outputOffset);
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
var CHUNK_SIZE = 4096;
|
|
3247
|
+
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
3248
|
+
let offset = inputOffset;
|
|
3249
|
+
const end = offset + byteLength;
|
|
3250
|
+
const units = [];
|
|
3251
|
+
let result = "";
|
|
3252
|
+
while (offset < end) {
|
|
3253
|
+
const byte1 = bytes[offset++];
|
|
3254
|
+
if ((byte1 & 128) === 0) {
|
|
3255
|
+
units.push(byte1);
|
|
3256
|
+
} else if ((byte1 & 224) === 192) {
|
|
3257
|
+
const byte2 = bytes[offset++] & 63;
|
|
3258
|
+
units.push((byte1 & 31) << 6 | byte2);
|
|
3259
|
+
} else if ((byte1 & 240) === 224) {
|
|
3260
|
+
const byte2 = bytes[offset++] & 63;
|
|
3261
|
+
const byte3 = bytes[offset++] & 63;
|
|
3262
|
+
units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
|
|
3263
|
+
} else if ((byte1 & 248) === 240) {
|
|
3264
|
+
const byte2 = bytes[offset++] & 63;
|
|
3265
|
+
const byte3 = bytes[offset++] & 63;
|
|
3266
|
+
const byte4 = bytes[offset++] & 63;
|
|
3267
|
+
let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
|
|
3268
|
+
if (unit > 65535) {
|
|
3269
|
+
unit -= 65536;
|
|
3270
|
+
units.push(unit >>> 10 & 1023 | 55296);
|
|
3271
|
+
unit = 56320 | unit & 1023;
|
|
3272
|
+
}
|
|
3273
|
+
units.push(unit);
|
|
3274
|
+
} else {
|
|
3275
|
+
units.push(byte1);
|
|
3276
|
+
}
|
|
3277
|
+
if (units.length >= CHUNK_SIZE) {
|
|
3278
|
+
result += String.fromCharCode(...units);
|
|
3279
|
+
units.length = 0;
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
if (units.length > 0) {
|
|
3283
|
+
result += String.fromCharCode(...units);
|
|
3284
|
+
}
|
|
3285
|
+
return result;
|
|
3286
|
+
}
|
|
3287
|
+
var sharedTextDecoder = new TextDecoder;
|
|
3288
|
+
var TEXT_DECODER_THRESHOLD = 200;
|
|
3289
|
+
function utf8DecodeTD(bytes, inputOffset, byteLength) {
|
|
3290
|
+
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
|
|
3291
|
+
return sharedTextDecoder.decode(stringBytes);
|
|
3292
|
+
}
|
|
3293
|
+
function utf8Decode(bytes, inputOffset, byteLength) {
|
|
3294
|
+
if (byteLength > TEXT_DECODER_THRESHOLD) {
|
|
3295
|
+
return utf8DecodeTD(bytes, inputOffset, byteLength);
|
|
3296
|
+
} else {
|
|
3297
|
+
return utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
});
|
|
3301
|
+
|
|
3302
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs
|
|
3303
|
+
var require_ExtData = __commonJS((exports) => {
|
|
3304
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3305
|
+
exports.ExtData = undefined;
|
|
3306
|
+
|
|
3307
|
+
class ExtData {
|
|
3308
|
+
constructor(type, data) {
|
|
3309
|
+
this.type = type;
|
|
3310
|
+
this.data = data;
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
exports.ExtData = ExtData;
|
|
3314
|
+
});
|
|
3315
|
+
|
|
3316
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs
|
|
3317
|
+
var require_DecodeError = __commonJS((exports) => {
|
|
3318
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3319
|
+
exports.DecodeError = undefined;
|
|
3320
|
+
|
|
3321
|
+
class DecodeError extends Error {
|
|
3322
|
+
constructor(message) {
|
|
3323
|
+
super(message);
|
|
3324
|
+
const proto = Object.create(DecodeError.prototype);
|
|
3325
|
+
Object.setPrototypeOf(this, proto);
|
|
3326
|
+
Object.defineProperty(this, "name", {
|
|
3327
|
+
configurable: true,
|
|
3328
|
+
enumerable: false,
|
|
3329
|
+
value: DecodeError.name
|
|
3330
|
+
});
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
exports.DecodeError = DecodeError;
|
|
3334
|
+
});
|
|
3335
|
+
|
|
3336
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs
|
|
3337
|
+
var require_int = __commonJS((exports) => {
|
|
3338
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3339
|
+
exports.UINT32_MAX = undefined;
|
|
3340
|
+
exports.setUint64 = setUint64;
|
|
3341
|
+
exports.setInt64 = setInt64;
|
|
3342
|
+
exports.getInt64 = getInt64;
|
|
3343
|
+
exports.getUint64 = getUint64;
|
|
3344
|
+
exports.UINT32_MAX = 4294967295;
|
|
3345
|
+
function setUint64(view, offset, value) {
|
|
3346
|
+
const high = value / 4294967296;
|
|
3347
|
+
const low = value;
|
|
3348
|
+
view.setUint32(offset, high);
|
|
3349
|
+
view.setUint32(offset + 4, low);
|
|
3350
|
+
}
|
|
3351
|
+
function setInt64(view, offset, value) {
|
|
3352
|
+
const high = Math.floor(value / 4294967296);
|
|
3353
|
+
const low = value;
|
|
3354
|
+
view.setUint32(offset, high);
|
|
3355
|
+
view.setUint32(offset + 4, low);
|
|
3356
|
+
}
|
|
3357
|
+
function getInt64(view, offset) {
|
|
3358
|
+
const high = view.getInt32(offset);
|
|
3359
|
+
const low = view.getUint32(offset + 4);
|
|
3360
|
+
return high * 4294967296 + low;
|
|
3361
|
+
}
|
|
3362
|
+
function getUint64(view, offset) {
|
|
3363
|
+
const high = view.getUint32(offset);
|
|
3364
|
+
const low = view.getUint32(offset + 4);
|
|
3365
|
+
return high * 4294967296 + low;
|
|
3366
|
+
}
|
|
3367
|
+
});
|
|
3368
|
+
|
|
3369
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs
|
|
3370
|
+
var require_timestamp = __commonJS((exports) => {
|
|
3371
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3372
|
+
exports.timestampExtension = exports.EXT_TIMESTAMP = undefined;
|
|
3373
|
+
exports.encodeTimeSpecToTimestamp = encodeTimeSpecToTimestamp;
|
|
3374
|
+
exports.encodeDateToTimeSpec = encodeDateToTimeSpec;
|
|
3375
|
+
exports.encodeTimestampExtension = encodeTimestampExtension;
|
|
3376
|
+
exports.decodeTimestampToTimeSpec = decodeTimestampToTimeSpec;
|
|
3377
|
+
exports.decodeTimestampExtension = decodeTimestampExtension;
|
|
3378
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
3379
|
+
var int_ts_1 = require_int();
|
|
3380
|
+
exports.EXT_TIMESTAMP = -1;
|
|
3381
|
+
var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
|
|
3382
|
+
var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
|
|
3383
|
+
function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
3384
|
+
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
3385
|
+
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
3386
|
+
const rv = new Uint8Array(4);
|
|
3387
|
+
const view = new DataView(rv.buffer);
|
|
3388
|
+
view.setUint32(0, sec);
|
|
3389
|
+
return rv;
|
|
3390
|
+
} else {
|
|
3391
|
+
const secHigh = sec / 4294967296;
|
|
3392
|
+
const secLow = sec & 4294967295;
|
|
3393
|
+
const rv = new Uint8Array(8);
|
|
3394
|
+
const view = new DataView(rv.buffer);
|
|
3395
|
+
view.setUint32(0, nsec << 2 | secHigh & 3);
|
|
3396
|
+
view.setUint32(4, secLow);
|
|
3397
|
+
return rv;
|
|
3398
|
+
}
|
|
3399
|
+
} else {
|
|
3400
|
+
const rv = new Uint8Array(12);
|
|
3401
|
+
const view = new DataView(rv.buffer);
|
|
3402
|
+
view.setUint32(0, nsec);
|
|
3403
|
+
(0, int_ts_1.setInt64)(view, 4, sec);
|
|
3404
|
+
return rv;
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
function encodeDateToTimeSpec(date2) {
|
|
3408
|
+
const msec = date2.getTime();
|
|
3409
|
+
const sec = Math.floor(msec / 1000);
|
|
3410
|
+
const nsec = (msec - sec * 1000) * 1e6;
|
|
3411
|
+
const nsecInSec = Math.floor(nsec / 1e9);
|
|
3412
|
+
return {
|
|
3413
|
+
sec: sec + nsecInSec,
|
|
3414
|
+
nsec: nsec - nsecInSec * 1e9
|
|
3415
|
+
};
|
|
3416
|
+
}
|
|
3417
|
+
function encodeTimestampExtension(object3) {
|
|
3418
|
+
if (object3 instanceof Date) {
|
|
3419
|
+
const timeSpec = encodeDateToTimeSpec(object3);
|
|
3420
|
+
return encodeTimeSpecToTimestamp(timeSpec);
|
|
3421
|
+
} else {
|
|
3422
|
+
return null;
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
function decodeTimestampToTimeSpec(data) {
|
|
3426
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
3427
|
+
switch (data.byteLength) {
|
|
3428
|
+
case 4: {
|
|
3429
|
+
const sec = view.getUint32(0);
|
|
3430
|
+
const nsec = 0;
|
|
3431
|
+
return { sec, nsec };
|
|
3432
|
+
}
|
|
3433
|
+
case 8: {
|
|
3434
|
+
const nsec30AndSecHigh2 = view.getUint32(0);
|
|
3435
|
+
const secLow32 = view.getUint32(4);
|
|
3436
|
+
const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
|
|
3437
|
+
const nsec = nsec30AndSecHigh2 >>> 2;
|
|
3438
|
+
return { sec, nsec };
|
|
3439
|
+
}
|
|
3440
|
+
case 12: {
|
|
3441
|
+
const sec = (0, int_ts_1.getInt64)(view, 4);
|
|
3442
|
+
const nsec = view.getUint32(0);
|
|
3443
|
+
return { sec, nsec };
|
|
3444
|
+
}
|
|
3445
|
+
default:
|
|
3446
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
function decodeTimestampExtension(data) {
|
|
3450
|
+
const timeSpec = decodeTimestampToTimeSpec(data);
|
|
3451
|
+
return new Date(timeSpec.sec * 1000 + timeSpec.nsec / 1e6);
|
|
3452
|
+
}
|
|
3453
|
+
exports.timestampExtension = {
|
|
3454
|
+
type: exports.EXT_TIMESTAMP,
|
|
3455
|
+
encode: encodeTimestampExtension,
|
|
3456
|
+
decode: decodeTimestampExtension
|
|
3457
|
+
};
|
|
3458
|
+
});
|
|
3459
|
+
|
|
3460
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs
|
|
3461
|
+
var require_ExtensionCodec = __commonJS((exports) => {
|
|
3462
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3463
|
+
exports.ExtensionCodec = undefined;
|
|
3464
|
+
var ExtData_ts_1 = require_ExtData();
|
|
3465
|
+
var timestamp_ts_1 = require_timestamp();
|
|
3466
|
+
|
|
3467
|
+
class ExtensionCodec {
|
|
3468
|
+
constructor() {
|
|
3469
|
+
this.builtInEncoders = [];
|
|
3470
|
+
this.builtInDecoders = [];
|
|
3471
|
+
this.encoders = [];
|
|
3472
|
+
this.decoders = [];
|
|
3473
|
+
this.register(timestamp_ts_1.timestampExtension);
|
|
3474
|
+
}
|
|
3475
|
+
register({ type, encode, decode }) {
|
|
3476
|
+
if (type >= 0) {
|
|
3477
|
+
this.encoders[type] = encode;
|
|
3478
|
+
this.decoders[type] = decode;
|
|
3479
|
+
} else {
|
|
3480
|
+
const index = -1 - type;
|
|
3481
|
+
this.builtInEncoders[index] = encode;
|
|
3482
|
+
this.builtInDecoders[index] = decode;
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
tryToEncode(object3, context) {
|
|
3486
|
+
for (let i = 0;i < this.builtInEncoders.length; i++) {
|
|
3487
|
+
const encodeExt = this.builtInEncoders[i];
|
|
3488
|
+
if (encodeExt != null) {
|
|
3489
|
+
const data = encodeExt(object3, context);
|
|
3490
|
+
if (data != null) {
|
|
3491
|
+
const type = -1 - i;
|
|
3492
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
for (let i = 0;i < this.encoders.length; i++) {
|
|
3497
|
+
const encodeExt = this.encoders[i];
|
|
3498
|
+
if (encodeExt != null) {
|
|
3499
|
+
const data = encodeExt(object3, context);
|
|
3500
|
+
if (data != null) {
|
|
3501
|
+
const type = i;
|
|
3502
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
if (object3 instanceof ExtData_ts_1.ExtData) {
|
|
3507
|
+
return object3;
|
|
3508
|
+
}
|
|
3509
|
+
return null;
|
|
3510
|
+
}
|
|
3511
|
+
decode(data, type, context) {
|
|
3512
|
+
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
3513
|
+
if (decodeExt) {
|
|
3514
|
+
return decodeExt(data, type, context);
|
|
3515
|
+
} else {
|
|
3516
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
exports.ExtensionCodec = ExtensionCodec;
|
|
3521
|
+
ExtensionCodec.defaultCodec = new ExtensionCodec;
|
|
3522
|
+
});
|
|
3523
|
+
|
|
3524
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs
|
|
3525
|
+
var require_typedArrays = __commonJS((exports) => {
|
|
3526
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3527
|
+
exports.ensureUint8Array = ensureUint8Array;
|
|
3528
|
+
function isArrayBufferLike(buffer) {
|
|
3529
|
+
return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer;
|
|
3530
|
+
}
|
|
3531
|
+
function ensureUint8Array(buffer) {
|
|
3532
|
+
if (buffer instanceof Uint8Array) {
|
|
3533
|
+
return buffer;
|
|
3534
|
+
} else if (ArrayBuffer.isView(buffer)) {
|
|
3535
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
3536
|
+
} else if (isArrayBufferLike(buffer)) {
|
|
3537
|
+
return new Uint8Array(buffer);
|
|
3538
|
+
} else {
|
|
3539
|
+
return Uint8Array.from(buffer);
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
});
|
|
3543
|
+
|
|
3544
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs
|
|
3545
|
+
var require_Encoder = __commonJS((exports) => {
|
|
3546
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3547
|
+
exports.Encoder = exports.DEFAULT_INITIAL_BUFFER_SIZE = exports.DEFAULT_MAX_DEPTH = undefined;
|
|
3548
|
+
var utf8_ts_1 = require_utf8();
|
|
3549
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
3550
|
+
var int_ts_1 = require_int();
|
|
3551
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
3552
|
+
exports.DEFAULT_MAX_DEPTH = 100;
|
|
3553
|
+
exports.DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
3554
|
+
|
|
3555
|
+
class Encoder {
|
|
3556
|
+
constructor(options) {
|
|
3557
|
+
this.entered = false;
|
|
3558
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
3559
|
+
this.context = options?.context;
|
|
3560
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
3561
|
+
this.maxDepth = options?.maxDepth ?? exports.DEFAULT_MAX_DEPTH;
|
|
3562
|
+
this.initialBufferSize = options?.initialBufferSize ?? exports.DEFAULT_INITIAL_BUFFER_SIZE;
|
|
3563
|
+
this.sortKeys = options?.sortKeys ?? false;
|
|
3564
|
+
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
3565
|
+
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
3566
|
+
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
3567
|
+
this.pos = 0;
|
|
3568
|
+
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
3569
|
+
this.bytes = new Uint8Array(this.view.buffer);
|
|
3570
|
+
}
|
|
3571
|
+
clone() {
|
|
3572
|
+
return new Encoder({
|
|
3573
|
+
extensionCodec: this.extensionCodec,
|
|
3574
|
+
context: this.context,
|
|
3575
|
+
useBigInt64: this.useBigInt64,
|
|
3576
|
+
maxDepth: this.maxDepth,
|
|
3577
|
+
initialBufferSize: this.initialBufferSize,
|
|
3578
|
+
sortKeys: this.sortKeys,
|
|
3579
|
+
forceFloat32: this.forceFloat32,
|
|
3580
|
+
ignoreUndefined: this.ignoreUndefined,
|
|
3581
|
+
forceIntegerToFloat: this.forceIntegerToFloat
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
reinitializeState() {
|
|
3585
|
+
this.pos = 0;
|
|
3586
|
+
}
|
|
3587
|
+
encodeSharedRef(object3) {
|
|
3588
|
+
if (this.entered) {
|
|
3589
|
+
const instance = this.clone();
|
|
3590
|
+
return instance.encodeSharedRef(object3);
|
|
3591
|
+
}
|
|
3592
|
+
try {
|
|
3593
|
+
this.entered = true;
|
|
3594
|
+
this.reinitializeState();
|
|
3595
|
+
this.doEncode(object3, 1);
|
|
3596
|
+
return this.bytes.subarray(0, this.pos);
|
|
3597
|
+
} finally {
|
|
3598
|
+
this.entered = false;
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
encode(object3) {
|
|
3602
|
+
if (this.entered) {
|
|
3603
|
+
const instance = this.clone();
|
|
3604
|
+
return instance.encode(object3);
|
|
3605
|
+
}
|
|
3606
|
+
try {
|
|
3607
|
+
this.entered = true;
|
|
3608
|
+
this.reinitializeState();
|
|
3609
|
+
this.doEncode(object3, 1);
|
|
3610
|
+
return this.bytes.slice(0, this.pos);
|
|
3611
|
+
} finally {
|
|
3612
|
+
this.entered = false;
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
doEncode(object3, depth) {
|
|
3616
|
+
if (depth > this.maxDepth) {
|
|
3617
|
+
throw new Error(`Too deep objects in depth ${depth}`);
|
|
3618
|
+
}
|
|
3619
|
+
if (object3 == null) {
|
|
3620
|
+
this.encodeNil();
|
|
3621
|
+
} else if (typeof object3 === "boolean") {
|
|
3622
|
+
this.encodeBoolean(object3);
|
|
3623
|
+
} else if (typeof object3 === "number") {
|
|
3624
|
+
if (!this.forceIntegerToFloat) {
|
|
3625
|
+
this.encodeNumber(object3);
|
|
3626
|
+
} else {
|
|
3627
|
+
this.encodeNumberAsFloat(object3);
|
|
3628
|
+
}
|
|
3629
|
+
} else if (typeof object3 === "string") {
|
|
3630
|
+
this.encodeString(object3);
|
|
3631
|
+
} else if (this.useBigInt64 && typeof object3 === "bigint") {
|
|
3632
|
+
this.encodeBigInt64(object3);
|
|
3633
|
+
} else {
|
|
3634
|
+
this.encodeObject(object3, depth);
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
ensureBufferSizeToWrite(sizeToWrite) {
|
|
3638
|
+
const requiredSize = this.pos + sizeToWrite;
|
|
3639
|
+
if (this.view.byteLength < requiredSize) {
|
|
3640
|
+
this.resizeBuffer(requiredSize * 2);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
resizeBuffer(newSize) {
|
|
3644
|
+
const newBuffer = new ArrayBuffer(newSize);
|
|
3645
|
+
const newBytes = new Uint8Array(newBuffer);
|
|
3646
|
+
const newView = new DataView(newBuffer);
|
|
3647
|
+
newBytes.set(this.bytes);
|
|
3648
|
+
this.view = newView;
|
|
3649
|
+
this.bytes = newBytes;
|
|
3650
|
+
}
|
|
3651
|
+
encodeNil() {
|
|
3652
|
+
this.writeU8(192);
|
|
3653
|
+
}
|
|
3654
|
+
encodeBoolean(object3) {
|
|
3655
|
+
if (object3 === false) {
|
|
3656
|
+
this.writeU8(194);
|
|
3657
|
+
} else {
|
|
3658
|
+
this.writeU8(195);
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
encodeNumber(object3) {
|
|
3662
|
+
if (!this.forceIntegerToFloat && Number.isSafeInteger(object3)) {
|
|
3663
|
+
if (object3 >= 0) {
|
|
3664
|
+
if (object3 < 128) {
|
|
3665
|
+
this.writeU8(object3);
|
|
3666
|
+
} else if (object3 < 256) {
|
|
3667
|
+
this.writeU8(204);
|
|
3668
|
+
this.writeU8(object3);
|
|
3669
|
+
} else if (object3 < 65536) {
|
|
3670
|
+
this.writeU8(205);
|
|
3671
|
+
this.writeU16(object3);
|
|
3672
|
+
} else if (object3 < 4294967296) {
|
|
3673
|
+
this.writeU8(206);
|
|
3674
|
+
this.writeU32(object3);
|
|
3675
|
+
} else if (!this.useBigInt64) {
|
|
3676
|
+
this.writeU8(207);
|
|
3677
|
+
this.writeU64(object3);
|
|
3678
|
+
} else {
|
|
3679
|
+
this.encodeNumberAsFloat(object3);
|
|
3680
|
+
}
|
|
3681
|
+
} else {
|
|
3682
|
+
if (object3 >= -32) {
|
|
3683
|
+
this.writeU8(224 | object3 + 32);
|
|
3684
|
+
} else if (object3 >= -128) {
|
|
3685
|
+
this.writeU8(208);
|
|
3686
|
+
this.writeI8(object3);
|
|
3687
|
+
} else if (object3 >= -32768) {
|
|
3688
|
+
this.writeU8(209);
|
|
3689
|
+
this.writeI16(object3);
|
|
3690
|
+
} else if (object3 >= -2147483648) {
|
|
3691
|
+
this.writeU8(210);
|
|
3692
|
+
this.writeI32(object3);
|
|
3693
|
+
} else if (!this.useBigInt64) {
|
|
3694
|
+
this.writeU8(211);
|
|
3695
|
+
this.writeI64(object3);
|
|
3696
|
+
} else {
|
|
3697
|
+
this.encodeNumberAsFloat(object3);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
} else {
|
|
3701
|
+
this.encodeNumberAsFloat(object3);
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
encodeNumberAsFloat(object3) {
|
|
3705
|
+
if (this.forceFloat32) {
|
|
3706
|
+
this.writeU8(202);
|
|
3707
|
+
this.writeF32(object3);
|
|
3708
|
+
} else {
|
|
3709
|
+
this.writeU8(203);
|
|
3710
|
+
this.writeF64(object3);
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
encodeBigInt64(object3) {
|
|
3714
|
+
if (object3 >= BigInt(0)) {
|
|
3715
|
+
this.writeU8(207);
|
|
3716
|
+
this.writeBigUint64(object3);
|
|
3717
|
+
} else {
|
|
3718
|
+
this.writeU8(211);
|
|
3719
|
+
this.writeBigInt64(object3);
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
writeStringHeader(byteLength) {
|
|
3723
|
+
if (byteLength < 32) {
|
|
3724
|
+
this.writeU8(160 + byteLength);
|
|
3725
|
+
} else if (byteLength < 256) {
|
|
3726
|
+
this.writeU8(217);
|
|
3727
|
+
this.writeU8(byteLength);
|
|
3728
|
+
} else if (byteLength < 65536) {
|
|
3729
|
+
this.writeU8(218);
|
|
3730
|
+
this.writeU16(byteLength);
|
|
3731
|
+
} else if (byteLength < 4294967296) {
|
|
3732
|
+
this.writeU8(219);
|
|
3733
|
+
this.writeU32(byteLength);
|
|
3734
|
+
} else {
|
|
3735
|
+
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
encodeString(object3) {
|
|
3739
|
+
const maxHeaderSize = 1 + 4;
|
|
3740
|
+
const byteLength = (0, utf8_ts_1.utf8Count)(object3);
|
|
3741
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
3742
|
+
this.writeStringHeader(byteLength);
|
|
3743
|
+
(0, utf8_ts_1.utf8Encode)(object3, this.bytes, this.pos);
|
|
3744
|
+
this.pos += byteLength;
|
|
3745
|
+
}
|
|
3746
|
+
encodeObject(object3, depth) {
|
|
3747
|
+
const ext = this.extensionCodec.tryToEncode(object3, this.context);
|
|
3748
|
+
if (ext != null) {
|
|
3749
|
+
this.encodeExtension(ext);
|
|
3750
|
+
} else if (Array.isArray(object3)) {
|
|
3751
|
+
this.encodeArray(object3, depth);
|
|
3752
|
+
} else if (ArrayBuffer.isView(object3)) {
|
|
3753
|
+
this.encodeBinary(object3);
|
|
3754
|
+
} else if (typeof object3 === "object") {
|
|
3755
|
+
this.encodeMap(object3, depth);
|
|
3756
|
+
} else {
|
|
3757
|
+
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object3)}`);
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
encodeBinary(object3) {
|
|
3761
|
+
const size = object3.byteLength;
|
|
3762
|
+
if (size < 256) {
|
|
3763
|
+
this.writeU8(196);
|
|
3764
|
+
this.writeU8(size);
|
|
3765
|
+
} else if (size < 65536) {
|
|
3766
|
+
this.writeU8(197);
|
|
3767
|
+
this.writeU16(size);
|
|
3768
|
+
} else if (size < 4294967296) {
|
|
3769
|
+
this.writeU8(198);
|
|
3770
|
+
this.writeU32(size);
|
|
3771
|
+
} else {
|
|
3772
|
+
throw new Error(`Too large binary: ${size}`);
|
|
3773
|
+
}
|
|
3774
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(object3);
|
|
3775
|
+
this.writeU8a(bytes);
|
|
3776
|
+
}
|
|
3777
|
+
encodeArray(object3, depth) {
|
|
3778
|
+
const size = object3.length;
|
|
3779
|
+
if (size < 16) {
|
|
3780
|
+
this.writeU8(144 + size);
|
|
3781
|
+
} else if (size < 65536) {
|
|
3782
|
+
this.writeU8(220);
|
|
3783
|
+
this.writeU16(size);
|
|
3784
|
+
} else if (size < 4294967296) {
|
|
3785
|
+
this.writeU8(221);
|
|
3786
|
+
this.writeU32(size);
|
|
3787
|
+
} else {
|
|
3788
|
+
throw new Error(`Too large array: ${size}`);
|
|
3789
|
+
}
|
|
3790
|
+
for (const item of object3) {
|
|
3791
|
+
this.doEncode(item, depth + 1);
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
countWithoutUndefined(object3, keys) {
|
|
3795
|
+
let count = 0;
|
|
3796
|
+
for (const key of keys) {
|
|
3797
|
+
if (object3[key] !== undefined) {
|
|
3798
|
+
count++;
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
return count;
|
|
3802
|
+
}
|
|
3803
|
+
encodeMap(object3, depth) {
|
|
3804
|
+
const keys = Object.keys(object3);
|
|
3805
|
+
if (this.sortKeys) {
|
|
3806
|
+
keys.sort();
|
|
3807
|
+
}
|
|
3808
|
+
const size = this.ignoreUndefined ? this.countWithoutUndefined(object3, keys) : keys.length;
|
|
3809
|
+
if (size < 16) {
|
|
3810
|
+
this.writeU8(128 + size);
|
|
3811
|
+
} else if (size < 65536) {
|
|
3812
|
+
this.writeU8(222);
|
|
3813
|
+
this.writeU16(size);
|
|
3814
|
+
} else if (size < 4294967296) {
|
|
3815
|
+
this.writeU8(223);
|
|
3816
|
+
this.writeU32(size);
|
|
3817
|
+
} else {
|
|
3818
|
+
throw new Error(`Too large map object: ${size}`);
|
|
3819
|
+
}
|
|
3820
|
+
for (const key of keys) {
|
|
3821
|
+
const value = object3[key];
|
|
3822
|
+
if (!(this.ignoreUndefined && value === undefined)) {
|
|
3823
|
+
this.encodeString(key);
|
|
3824
|
+
this.doEncode(value, depth + 1);
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
encodeExtension(ext) {
|
|
3829
|
+
if (typeof ext.data === "function") {
|
|
3830
|
+
const data = ext.data(this.pos + 6);
|
|
3831
|
+
const size2 = data.length;
|
|
3832
|
+
if (size2 >= 4294967296) {
|
|
3833
|
+
throw new Error(`Too large extension object: ${size2}`);
|
|
3834
|
+
}
|
|
3835
|
+
this.writeU8(201);
|
|
3836
|
+
this.writeU32(size2);
|
|
3837
|
+
this.writeI8(ext.type);
|
|
3838
|
+
this.writeU8a(data);
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
const size = ext.data.length;
|
|
3842
|
+
if (size === 1) {
|
|
3843
|
+
this.writeU8(212);
|
|
3844
|
+
} else if (size === 2) {
|
|
3845
|
+
this.writeU8(213);
|
|
3846
|
+
} else if (size === 4) {
|
|
3847
|
+
this.writeU8(214);
|
|
3848
|
+
} else if (size === 8) {
|
|
3849
|
+
this.writeU8(215);
|
|
3850
|
+
} else if (size === 16) {
|
|
3851
|
+
this.writeU8(216);
|
|
3852
|
+
} else if (size < 256) {
|
|
3853
|
+
this.writeU8(199);
|
|
3854
|
+
this.writeU8(size);
|
|
3855
|
+
} else if (size < 65536) {
|
|
3856
|
+
this.writeU8(200);
|
|
3857
|
+
this.writeU16(size);
|
|
3858
|
+
} else if (size < 4294967296) {
|
|
3859
|
+
this.writeU8(201);
|
|
3860
|
+
this.writeU32(size);
|
|
3861
|
+
} else {
|
|
3862
|
+
throw new Error(`Too large extension object: ${size}`);
|
|
3863
|
+
}
|
|
3864
|
+
this.writeI8(ext.type);
|
|
3865
|
+
this.writeU8a(ext.data);
|
|
3866
|
+
}
|
|
3867
|
+
writeU8(value) {
|
|
3868
|
+
this.ensureBufferSizeToWrite(1);
|
|
3869
|
+
this.view.setUint8(this.pos, value);
|
|
3870
|
+
this.pos++;
|
|
3871
|
+
}
|
|
3872
|
+
writeU8a(values) {
|
|
3873
|
+
const size = values.length;
|
|
3874
|
+
this.ensureBufferSizeToWrite(size);
|
|
3875
|
+
this.bytes.set(values, this.pos);
|
|
3876
|
+
this.pos += size;
|
|
3877
|
+
}
|
|
3878
|
+
writeI8(value) {
|
|
3879
|
+
this.ensureBufferSizeToWrite(1);
|
|
3880
|
+
this.view.setInt8(this.pos, value);
|
|
3881
|
+
this.pos++;
|
|
3882
|
+
}
|
|
3883
|
+
writeU16(value) {
|
|
3884
|
+
this.ensureBufferSizeToWrite(2);
|
|
3885
|
+
this.view.setUint16(this.pos, value);
|
|
3886
|
+
this.pos += 2;
|
|
3887
|
+
}
|
|
3888
|
+
writeI16(value) {
|
|
3889
|
+
this.ensureBufferSizeToWrite(2);
|
|
3890
|
+
this.view.setInt16(this.pos, value);
|
|
3891
|
+
this.pos += 2;
|
|
3892
|
+
}
|
|
3893
|
+
writeU32(value) {
|
|
3894
|
+
this.ensureBufferSizeToWrite(4);
|
|
3895
|
+
this.view.setUint32(this.pos, value);
|
|
3896
|
+
this.pos += 4;
|
|
3897
|
+
}
|
|
3898
|
+
writeI32(value) {
|
|
3899
|
+
this.ensureBufferSizeToWrite(4);
|
|
3900
|
+
this.view.setInt32(this.pos, value);
|
|
3901
|
+
this.pos += 4;
|
|
3902
|
+
}
|
|
3903
|
+
writeF32(value) {
|
|
3904
|
+
this.ensureBufferSizeToWrite(4);
|
|
3905
|
+
this.view.setFloat32(this.pos, value);
|
|
3906
|
+
this.pos += 4;
|
|
3907
|
+
}
|
|
3908
|
+
writeF64(value) {
|
|
3909
|
+
this.ensureBufferSizeToWrite(8);
|
|
3910
|
+
this.view.setFloat64(this.pos, value);
|
|
3911
|
+
this.pos += 8;
|
|
3912
|
+
}
|
|
3913
|
+
writeU64(value) {
|
|
3914
|
+
this.ensureBufferSizeToWrite(8);
|
|
3915
|
+
(0, int_ts_1.setUint64)(this.view, this.pos, value);
|
|
3916
|
+
this.pos += 8;
|
|
3917
|
+
}
|
|
3918
|
+
writeI64(value) {
|
|
3919
|
+
this.ensureBufferSizeToWrite(8);
|
|
3920
|
+
(0, int_ts_1.setInt64)(this.view, this.pos, value);
|
|
3921
|
+
this.pos += 8;
|
|
3922
|
+
}
|
|
3923
|
+
writeBigUint64(value) {
|
|
3924
|
+
this.ensureBufferSizeToWrite(8);
|
|
3925
|
+
this.view.setBigUint64(this.pos, value);
|
|
3926
|
+
this.pos += 8;
|
|
3927
|
+
}
|
|
3928
|
+
writeBigInt64(value) {
|
|
3929
|
+
this.ensureBufferSizeToWrite(8);
|
|
3930
|
+
this.view.setBigInt64(this.pos, value);
|
|
3931
|
+
this.pos += 8;
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
exports.Encoder = Encoder;
|
|
3935
|
+
});
|
|
3936
|
+
|
|
3937
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/encode.cjs
|
|
3938
|
+
var require_encode = __commonJS((exports) => {
|
|
3939
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3940
|
+
exports.encode = encode;
|
|
3941
|
+
var Encoder_ts_1 = require_Encoder();
|
|
3942
|
+
function encode(value, options) {
|
|
3943
|
+
const encoder = new Encoder_ts_1.Encoder(options);
|
|
3944
|
+
return encoder.encodeSharedRef(value);
|
|
3945
|
+
}
|
|
3946
|
+
});
|
|
3947
|
+
|
|
3948
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs
|
|
3949
|
+
var require_prettyByte = __commonJS((exports) => {
|
|
3950
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3951
|
+
exports.prettyByte = prettyByte;
|
|
3952
|
+
function prettyByte(byte) {
|
|
3953
|
+
return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
|
|
3954
|
+
}
|
|
3955
|
+
});
|
|
3956
|
+
|
|
3957
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs
|
|
3958
|
+
var require_CachedKeyDecoder = __commonJS((exports) => {
|
|
3959
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3960
|
+
exports.CachedKeyDecoder = undefined;
|
|
3961
|
+
var utf8_ts_1 = require_utf8();
|
|
3962
|
+
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
3963
|
+
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
3964
|
+
|
|
3965
|
+
class CachedKeyDecoder {
|
|
3966
|
+
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
3967
|
+
this.hit = 0;
|
|
3968
|
+
this.miss = 0;
|
|
3969
|
+
this.maxKeyLength = maxKeyLength;
|
|
3970
|
+
this.maxLengthPerKey = maxLengthPerKey;
|
|
3971
|
+
this.caches = [];
|
|
3972
|
+
for (let i = 0;i < this.maxKeyLength; i++) {
|
|
3973
|
+
this.caches.push([]);
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
canBeCached(byteLength) {
|
|
3977
|
+
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
3978
|
+
}
|
|
3979
|
+
find(bytes, inputOffset, byteLength) {
|
|
3980
|
+
const records = this.caches[byteLength - 1];
|
|
3981
|
+
FIND_CHUNK:
|
|
3982
|
+
for (const record2 of records) {
|
|
3983
|
+
const recordBytes = record2.bytes;
|
|
3984
|
+
for (let j = 0;j < byteLength; j++) {
|
|
3985
|
+
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
3986
|
+
continue FIND_CHUNK;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
return record2.str;
|
|
3990
|
+
}
|
|
3991
|
+
return null;
|
|
3992
|
+
}
|
|
3993
|
+
store(bytes, value) {
|
|
3994
|
+
const records = this.caches[bytes.length - 1];
|
|
3995
|
+
const record2 = { bytes, str: value };
|
|
3996
|
+
if (records.length >= this.maxLengthPerKey) {
|
|
3997
|
+
records[Math.random() * records.length | 0] = record2;
|
|
3998
|
+
} else {
|
|
3999
|
+
records.push(record2);
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
decode(bytes, inputOffset, byteLength) {
|
|
4003
|
+
const cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
4004
|
+
if (cachedValue != null) {
|
|
4005
|
+
this.hit++;
|
|
4006
|
+
return cachedValue;
|
|
4007
|
+
}
|
|
4008
|
+
this.miss++;
|
|
4009
|
+
const str = (0, utf8_ts_1.utf8DecodeJs)(bytes, inputOffset, byteLength);
|
|
4010
|
+
const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
4011
|
+
this.store(slicedCopyOfBytes, str);
|
|
4012
|
+
return str;
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
exports.CachedKeyDecoder = CachedKeyDecoder;
|
|
4016
|
+
});
|
|
4017
|
+
|
|
4018
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs
|
|
4019
|
+
var require_Decoder = __commonJS((exports) => {
|
|
4020
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4021
|
+
exports.Decoder = undefined;
|
|
4022
|
+
var prettyByte_ts_1 = require_prettyByte();
|
|
4023
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
4024
|
+
var int_ts_1 = require_int();
|
|
4025
|
+
var utf8_ts_1 = require_utf8();
|
|
4026
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
4027
|
+
var CachedKeyDecoder_ts_1 = require_CachedKeyDecoder();
|
|
4028
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
4029
|
+
var STATE_ARRAY = "array";
|
|
4030
|
+
var STATE_MAP_KEY = "map_key";
|
|
4031
|
+
var STATE_MAP_VALUE = "map_value";
|
|
4032
|
+
var mapKeyConverter = (key) => {
|
|
4033
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
4034
|
+
return key;
|
|
4035
|
+
}
|
|
4036
|
+
throw new DecodeError_ts_1.DecodeError("The type of key must be string or number but " + typeof key);
|
|
4037
|
+
};
|
|
4038
|
+
|
|
4039
|
+
class StackPool {
|
|
4040
|
+
constructor() {
|
|
4041
|
+
this.stack = [];
|
|
4042
|
+
this.stackHeadPosition = -1;
|
|
4043
|
+
}
|
|
4044
|
+
get length() {
|
|
4045
|
+
return this.stackHeadPosition + 1;
|
|
4046
|
+
}
|
|
4047
|
+
top() {
|
|
4048
|
+
return this.stack[this.stackHeadPosition];
|
|
4049
|
+
}
|
|
4050
|
+
pushArrayState(size) {
|
|
4051
|
+
const state = this.getUninitializedStateFromPool();
|
|
4052
|
+
state.type = STATE_ARRAY;
|
|
4053
|
+
state.position = 0;
|
|
4054
|
+
state.size = size;
|
|
4055
|
+
state.array = new Array(size);
|
|
4056
|
+
}
|
|
4057
|
+
pushMapState(size) {
|
|
4058
|
+
const state = this.getUninitializedStateFromPool();
|
|
4059
|
+
state.type = STATE_MAP_KEY;
|
|
4060
|
+
state.readCount = 0;
|
|
4061
|
+
state.size = size;
|
|
4062
|
+
state.map = {};
|
|
4063
|
+
}
|
|
4064
|
+
getUninitializedStateFromPool() {
|
|
4065
|
+
this.stackHeadPosition++;
|
|
4066
|
+
if (this.stackHeadPosition === this.stack.length) {
|
|
4067
|
+
const partialState = {
|
|
4068
|
+
type: undefined,
|
|
4069
|
+
size: 0,
|
|
4070
|
+
array: undefined,
|
|
4071
|
+
position: 0,
|
|
4072
|
+
readCount: 0,
|
|
4073
|
+
map: undefined,
|
|
4074
|
+
key: null
|
|
4075
|
+
};
|
|
4076
|
+
this.stack.push(partialState);
|
|
4077
|
+
}
|
|
4078
|
+
return this.stack[this.stackHeadPosition];
|
|
4079
|
+
}
|
|
4080
|
+
release(state) {
|
|
4081
|
+
const topStackState = this.stack[this.stackHeadPosition];
|
|
4082
|
+
if (topStackState !== state) {
|
|
4083
|
+
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
4084
|
+
}
|
|
4085
|
+
if (state.type === STATE_ARRAY) {
|
|
4086
|
+
const partialState = state;
|
|
4087
|
+
partialState.size = 0;
|
|
4088
|
+
partialState.array = undefined;
|
|
4089
|
+
partialState.position = 0;
|
|
4090
|
+
partialState.type = undefined;
|
|
4091
|
+
}
|
|
4092
|
+
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
|
|
4093
|
+
const partialState = state;
|
|
4094
|
+
partialState.size = 0;
|
|
4095
|
+
partialState.map = undefined;
|
|
4096
|
+
partialState.readCount = 0;
|
|
4097
|
+
partialState.type = undefined;
|
|
4098
|
+
}
|
|
4099
|
+
this.stackHeadPosition--;
|
|
4100
|
+
}
|
|
4101
|
+
reset() {
|
|
4102
|
+
this.stack.length = 0;
|
|
4103
|
+
this.stackHeadPosition = -1;
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
var HEAD_BYTE_REQUIRED = -1;
|
|
4107
|
+
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
4108
|
+
var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
4109
|
+
try {
|
|
4110
|
+
EMPTY_VIEW.getInt8(0);
|
|
4111
|
+
} catch (e) {
|
|
4112
|
+
if (!(e instanceof RangeError)) {
|
|
4113
|
+
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
var MORE_DATA = new RangeError("Insufficient data");
|
|
4117
|
+
var sharedCachedKeyDecoder = new CachedKeyDecoder_ts_1.CachedKeyDecoder;
|
|
4118
|
+
|
|
4119
|
+
class Decoder {
|
|
4120
|
+
constructor(options) {
|
|
4121
|
+
this.totalPos = 0;
|
|
4122
|
+
this.pos = 0;
|
|
4123
|
+
this.view = EMPTY_VIEW;
|
|
4124
|
+
this.bytes = EMPTY_BYTES;
|
|
4125
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
4126
|
+
this.stack = new StackPool;
|
|
4127
|
+
this.entered = false;
|
|
4128
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
4129
|
+
this.context = options?.context;
|
|
4130
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
4131
|
+
this.rawStrings = options?.rawStrings ?? false;
|
|
4132
|
+
this.maxStrLength = options?.maxStrLength ?? int_ts_1.UINT32_MAX;
|
|
4133
|
+
this.maxBinLength = options?.maxBinLength ?? int_ts_1.UINT32_MAX;
|
|
4134
|
+
this.maxArrayLength = options?.maxArrayLength ?? int_ts_1.UINT32_MAX;
|
|
4135
|
+
this.maxMapLength = options?.maxMapLength ?? int_ts_1.UINT32_MAX;
|
|
4136
|
+
this.maxExtLength = options?.maxExtLength ?? int_ts_1.UINT32_MAX;
|
|
4137
|
+
this.keyDecoder = options?.keyDecoder !== undefined ? options.keyDecoder : sharedCachedKeyDecoder;
|
|
4138
|
+
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
|
|
4139
|
+
}
|
|
4140
|
+
clone() {
|
|
4141
|
+
return new Decoder({
|
|
4142
|
+
extensionCodec: this.extensionCodec,
|
|
4143
|
+
context: this.context,
|
|
4144
|
+
useBigInt64: this.useBigInt64,
|
|
4145
|
+
rawStrings: this.rawStrings,
|
|
4146
|
+
maxStrLength: this.maxStrLength,
|
|
4147
|
+
maxBinLength: this.maxBinLength,
|
|
4148
|
+
maxArrayLength: this.maxArrayLength,
|
|
4149
|
+
maxMapLength: this.maxMapLength,
|
|
4150
|
+
maxExtLength: this.maxExtLength,
|
|
4151
|
+
keyDecoder: this.keyDecoder
|
|
4152
|
+
});
|
|
4153
|
+
}
|
|
4154
|
+
reinitializeState() {
|
|
4155
|
+
this.totalPos = 0;
|
|
4156
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
4157
|
+
this.stack.reset();
|
|
4158
|
+
}
|
|
4159
|
+
setBuffer(buffer) {
|
|
4160
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(buffer);
|
|
4161
|
+
this.bytes = bytes;
|
|
4162
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
4163
|
+
this.pos = 0;
|
|
4164
|
+
}
|
|
4165
|
+
appendBuffer(buffer) {
|
|
4166
|
+
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
4167
|
+
this.setBuffer(buffer);
|
|
4168
|
+
} else {
|
|
4169
|
+
const remainingData = this.bytes.subarray(this.pos);
|
|
4170
|
+
const newData = (0, typedArrays_ts_1.ensureUint8Array)(buffer);
|
|
4171
|
+
const newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
4172
|
+
newBuffer.set(remainingData);
|
|
4173
|
+
newBuffer.set(newData, remainingData.length);
|
|
4174
|
+
this.setBuffer(newBuffer);
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
hasRemaining(size) {
|
|
4178
|
+
return this.view.byteLength - this.pos >= size;
|
|
4179
|
+
}
|
|
4180
|
+
createExtraByteError(posToShow) {
|
|
4181
|
+
const { view, pos } = this;
|
|
4182
|
+
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
|
|
4183
|
+
}
|
|
4184
|
+
decode(buffer) {
|
|
4185
|
+
if (this.entered) {
|
|
4186
|
+
const instance = this.clone();
|
|
4187
|
+
return instance.decode(buffer);
|
|
4188
|
+
}
|
|
4189
|
+
try {
|
|
4190
|
+
this.entered = true;
|
|
4191
|
+
this.reinitializeState();
|
|
4192
|
+
this.setBuffer(buffer);
|
|
4193
|
+
const object3 = this.doDecodeSync();
|
|
4194
|
+
if (this.hasRemaining(1)) {
|
|
4195
|
+
throw this.createExtraByteError(this.pos);
|
|
4196
|
+
}
|
|
4197
|
+
return object3;
|
|
4198
|
+
} finally {
|
|
4199
|
+
this.entered = false;
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
*decodeMulti(buffer) {
|
|
4203
|
+
if (this.entered) {
|
|
4204
|
+
const instance = this.clone();
|
|
4205
|
+
yield* instance.decodeMulti(buffer);
|
|
4206
|
+
return;
|
|
4207
|
+
}
|
|
4208
|
+
try {
|
|
4209
|
+
this.entered = true;
|
|
4210
|
+
this.reinitializeState();
|
|
4211
|
+
this.setBuffer(buffer);
|
|
4212
|
+
while (this.hasRemaining(1)) {
|
|
4213
|
+
yield this.doDecodeSync();
|
|
4214
|
+
}
|
|
4215
|
+
} finally {
|
|
4216
|
+
this.entered = false;
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
async decodeAsync(stream) {
|
|
4220
|
+
if (this.entered) {
|
|
4221
|
+
const instance = this.clone();
|
|
4222
|
+
return instance.decodeAsync(stream);
|
|
4223
|
+
}
|
|
4224
|
+
try {
|
|
4225
|
+
this.entered = true;
|
|
4226
|
+
let decoded = false;
|
|
4227
|
+
let object3;
|
|
4228
|
+
for await (const buffer of stream) {
|
|
4229
|
+
if (decoded) {
|
|
4230
|
+
this.entered = false;
|
|
4231
|
+
throw this.createExtraByteError(this.totalPos);
|
|
4232
|
+
}
|
|
4233
|
+
this.appendBuffer(buffer);
|
|
4234
|
+
try {
|
|
4235
|
+
object3 = this.doDecodeSync();
|
|
4236
|
+
decoded = true;
|
|
4237
|
+
} catch (e) {
|
|
4238
|
+
if (!(e instanceof RangeError)) {
|
|
4239
|
+
throw e;
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
this.totalPos += this.pos;
|
|
4243
|
+
}
|
|
4244
|
+
if (decoded) {
|
|
4245
|
+
if (this.hasRemaining(1)) {
|
|
4246
|
+
throw this.createExtraByteError(this.totalPos);
|
|
4247
|
+
}
|
|
4248
|
+
return object3;
|
|
4249
|
+
}
|
|
4250
|
+
const { headByte, pos, totalPos } = this;
|
|
4251
|
+
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_ts_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`);
|
|
4252
|
+
} finally {
|
|
4253
|
+
this.entered = false;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
decodeArrayStream(stream) {
|
|
4257
|
+
return this.decodeMultiAsync(stream, true);
|
|
4258
|
+
}
|
|
4259
|
+
decodeStream(stream) {
|
|
4260
|
+
return this.decodeMultiAsync(stream, false);
|
|
4261
|
+
}
|
|
4262
|
+
async* decodeMultiAsync(stream, isArray) {
|
|
4263
|
+
if (this.entered) {
|
|
4264
|
+
const instance = this.clone();
|
|
4265
|
+
yield* instance.decodeMultiAsync(stream, isArray);
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4268
|
+
try {
|
|
4269
|
+
this.entered = true;
|
|
4270
|
+
let isArrayHeaderRequired = isArray;
|
|
4271
|
+
let arrayItemsLeft = -1;
|
|
4272
|
+
for await (const buffer of stream) {
|
|
4273
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
4274
|
+
throw this.createExtraByteError(this.totalPos);
|
|
4275
|
+
}
|
|
4276
|
+
this.appendBuffer(buffer);
|
|
4277
|
+
if (isArrayHeaderRequired) {
|
|
4278
|
+
arrayItemsLeft = this.readArraySize();
|
|
4279
|
+
isArrayHeaderRequired = false;
|
|
4280
|
+
this.complete();
|
|
4281
|
+
}
|
|
4282
|
+
try {
|
|
4283
|
+
while (true) {
|
|
4284
|
+
yield this.doDecodeSync();
|
|
4285
|
+
if (--arrayItemsLeft === 0) {
|
|
4286
|
+
break;
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
} catch (e) {
|
|
4290
|
+
if (!(e instanceof RangeError)) {
|
|
4291
|
+
throw e;
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
this.totalPos += this.pos;
|
|
4295
|
+
}
|
|
4296
|
+
} finally {
|
|
4297
|
+
this.entered = false;
|
|
4298
|
+
}
|
|
4299
|
+
}
|
|
4300
|
+
doDecodeSync() {
|
|
4301
|
+
DECODE:
|
|
4302
|
+
while (true) {
|
|
4303
|
+
const headByte = this.readHeadByte();
|
|
4304
|
+
let object3;
|
|
4305
|
+
if (headByte >= 224) {
|
|
4306
|
+
object3 = headByte - 256;
|
|
4307
|
+
} else if (headByte < 192) {
|
|
4308
|
+
if (headByte < 128) {
|
|
4309
|
+
object3 = headByte;
|
|
4310
|
+
} else if (headByte < 144) {
|
|
4311
|
+
const size = headByte - 128;
|
|
4312
|
+
if (size !== 0) {
|
|
4313
|
+
this.pushMapState(size);
|
|
4314
|
+
this.complete();
|
|
4315
|
+
continue DECODE;
|
|
4316
|
+
} else {
|
|
4317
|
+
object3 = {};
|
|
4318
|
+
}
|
|
4319
|
+
} else if (headByte < 160) {
|
|
4320
|
+
const size = headByte - 144;
|
|
4321
|
+
if (size !== 0) {
|
|
4322
|
+
this.pushArrayState(size);
|
|
4323
|
+
this.complete();
|
|
4324
|
+
continue DECODE;
|
|
4325
|
+
} else {
|
|
4326
|
+
object3 = [];
|
|
4327
|
+
}
|
|
4328
|
+
} else {
|
|
4329
|
+
const byteLength = headByte - 160;
|
|
4330
|
+
object3 = this.decodeString(byteLength, 0);
|
|
4331
|
+
}
|
|
4332
|
+
} else if (headByte === 192) {
|
|
4333
|
+
object3 = null;
|
|
4334
|
+
} else if (headByte === 194) {
|
|
4335
|
+
object3 = false;
|
|
4336
|
+
} else if (headByte === 195) {
|
|
4337
|
+
object3 = true;
|
|
4338
|
+
} else if (headByte === 202) {
|
|
4339
|
+
object3 = this.readF32();
|
|
4340
|
+
} else if (headByte === 203) {
|
|
4341
|
+
object3 = this.readF64();
|
|
4342
|
+
} else if (headByte === 204) {
|
|
4343
|
+
object3 = this.readU8();
|
|
4344
|
+
} else if (headByte === 205) {
|
|
4345
|
+
object3 = this.readU16();
|
|
4346
|
+
} else if (headByte === 206) {
|
|
4347
|
+
object3 = this.readU32();
|
|
4348
|
+
} else if (headByte === 207) {
|
|
4349
|
+
if (this.useBigInt64) {
|
|
4350
|
+
object3 = this.readU64AsBigInt();
|
|
4351
|
+
} else {
|
|
4352
|
+
object3 = this.readU64();
|
|
4353
|
+
}
|
|
4354
|
+
} else if (headByte === 208) {
|
|
4355
|
+
object3 = this.readI8();
|
|
4356
|
+
} else if (headByte === 209) {
|
|
4357
|
+
object3 = this.readI16();
|
|
4358
|
+
} else if (headByte === 210) {
|
|
4359
|
+
object3 = this.readI32();
|
|
4360
|
+
} else if (headByte === 211) {
|
|
4361
|
+
if (this.useBigInt64) {
|
|
4362
|
+
object3 = this.readI64AsBigInt();
|
|
4363
|
+
} else {
|
|
4364
|
+
object3 = this.readI64();
|
|
4365
|
+
}
|
|
4366
|
+
} else if (headByte === 217) {
|
|
4367
|
+
const byteLength = this.lookU8();
|
|
4368
|
+
object3 = this.decodeString(byteLength, 1);
|
|
4369
|
+
} else if (headByte === 218) {
|
|
4370
|
+
const byteLength = this.lookU16();
|
|
4371
|
+
object3 = this.decodeString(byteLength, 2);
|
|
4372
|
+
} else if (headByte === 219) {
|
|
4373
|
+
const byteLength = this.lookU32();
|
|
4374
|
+
object3 = this.decodeString(byteLength, 4);
|
|
4375
|
+
} else if (headByte === 220) {
|
|
4376
|
+
const size = this.readU16();
|
|
4377
|
+
if (size !== 0) {
|
|
4378
|
+
this.pushArrayState(size);
|
|
4379
|
+
this.complete();
|
|
4380
|
+
continue DECODE;
|
|
4381
|
+
} else {
|
|
4382
|
+
object3 = [];
|
|
4383
|
+
}
|
|
4384
|
+
} else if (headByte === 221) {
|
|
4385
|
+
const size = this.readU32();
|
|
4386
|
+
if (size !== 0) {
|
|
4387
|
+
this.pushArrayState(size);
|
|
4388
|
+
this.complete();
|
|
4389
|
+
continue DECODE;
|
|
4390
|
+
} else {
|
|
4391
|
+
object3 = [];
|
|
4392
|
+
}
|
|
4393
|
+
} else if (headByte === 222) {
|
|
4394
|
+
const size = this.readU16();
|
|
4395
|
+
if (size !== 0) {
|
|
4396
|
+
this.pushMapState(size);
|
|
4397
|
+
this.complete();
|
|
4398
|
+
continue DECODE;
|
|
4399
|
+
} else {
|
|
4400
|
+
object3 = {};
|
|
4401
|
+
}
|
|
4402
|
+
} else if (headByte === 223) {
|
|
4403
|
+
const size = this.readU32();
|
|
4404
|
+
if (size !== 0) {
|
|
4405
|
+
this.pushMapState(size);
|
|
4406
|
+
this.complete();
|
|
4407
|
+
continue DECODE;
|
|
4408
|
+
} else {
|
|
4409
|
+
object3 = {};
|
|
4410
|
+
}
|
|
4411
|
+
} else if (headByte === 196) {
|
|
4412
|
+
const size = this.lookU8();
|
|
4413
|
+
object3 = this.decodeBinary(size, 1);
|
|
4414
|
+
} else if (headByte === 197) {
|
|
4415
|
+
const size = this.lookU16();
|
|
4416
|
+
object3 = this.decodeBinary(size, 2);
|
|
4417
|
+
} else if (headByte === 198) {
|
|
4418
|
+
const size = this.lookU32();
|
|
4419
|
+
object3 = this.decodeBinary(size, 4);
|
|
4420
|
+
} else if (headByte === 212) {
|
|
4421
|
+
object3 = this.decodeExtension(1, 0);
|
|
4422
|
+
} else if (headByte === 213) {
|
|
4423
|
+
object3 = this.decodeExtension(2, 0);
|
|
4424
|
+
} else if (headByte === 214) {
|
|
4425
|
+
object3 = this.decodeExtension(4, 0);
|
|
4426
|
+
} else if (headByte === 215) {
|
|
4427
|
+
object3 = this.decodeExtension(8, 0);
|
|
4428
|
+
} else if (headByte === 216) {
|
|
4429
|
+
object3 = this.decodeExtension(16, 0);
|
|
4430
|
+
} else if (headByte === 199) {
|
|
4431
|
+
const size = this.lookU8();
|
|
4432
|
+
object3 = this.decodeExtension(size, 1);
|
|
4433
|
+
} else if (headByte === 200) {
|
|
4434
|
+
const size = this.lookU16();
|
|
4435
|
+
object3 = this.decodeExtension(size, 2);
|
|
4436
|
+
} else if (headByte === 201) {
|
|
4437
|
+
const size = this.lookU32();
|
|
4438
|
+
object3 = this.decodeExtension(size, 4);
|
|
4439
|
+
} else {
|
|
4440
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
4441
|
+
}
|
|
4442
|
+
this.complete();
|
|
4443
|
+
const stack = this.stack;
|
|
4444
|
+
while (stack.length > 0) {
|
|
4445
|
+
const state = stack.top();
|
|
4446
|
+
if (state.type === STATE_ARRAY) {
|
|
4447
|
+
state.array[state.position] = object3;
|
|
4448
|
+
state.position++;
|
|
4449
|
+
if (state.position === state.size) {
|
|
4450
|
+
object3 = state.array;
|
|
4451
|
+
stack.release(state);
|
|
4452
|
+
} else {
|
|
4453
|
+
continue DECODE;
|
|
4454
|
+
}
|
|
4455
|
+
} else if (state.type === STATE_MAP_KEY) {
|
|
4456
|
+
if (object3 === "__proto__") {
|
|
4457
|
+
throw new DecodeError_ts_1.DecodeError("The key __proto__ is not allowed");
|
|
4458
|
+
}
|
|
4459
|
+
state.key = this.mapKeyConverter(object3);
|
|
4460
|
+
state.type = STATE_MAP_VALUE;
|
|
4461
|
+
continue DECODE;
|
|
4462
|
+
} else {
|
|
4463
|
+
state.map[state.key] = object3;
|
|
4464
|
+
state.readCount++;
|
|
4465
|
+
if (state.readCount === state.size) {
|
|
4466
|
+
object3 = state.map;
|
|
4467
|
+
stack.release(state);
|
|
4468
|
+
} else {
|
|
4469
|
+
state.key = null;
|
|
4470
|
+
state.type = STATE_MAP_KEY;
|
|
4471
|
+
continue DECODE;
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
return object3;
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
readHeadByte() {
|
|
4479
|
+
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
4480
|
+
this.headByte = this.readU8();
|
|
4481
|
+
}
|
|
4482
|
+
return this.headByte;
|
|
4483
|
+
}
|
|
4484
|
+
complete() {
|
|
4485
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
4486
|
+
}
|
|
4487
|
+
readArraySize() {
|
|
4488
|
+
const headByte = this.readHeadByte();
|
|
4489
|
+
switch (headByte) {
|
|
4490
|
+
case 220:
|
|
4491
|
+
return this.readU16();
|
|
4492
|
+
case 221:
|
|
4493
|
+
return this.readU32();
|
|
4494
|
+
default: {
|
|
4495
|
+
if (headByte < 160) {
|
|
4496
|
+
return headByte - 144;
|
|
4497
|
+
} else {
|
|
4498
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized array type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
4499
|
+
}
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
pushMapState(size) {
|
|
4504
|
+
if (size > this.maxMapLength) {
|
|
4505
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
4506
|
+
}
|
|
4507
|
+
this.stack.pushMapState(size);
|
|
4508
|
+
}
|
|
4509
|
+
pushArrayState(size) {
|
|
4510
|
+
if (size > this.maxArrayLength) {
|
|
4511
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
|
|
4512
|
+
}
|
|
4513
|
+
this.stack.pushArrayState(size);
|
|
4514
|
+
}
|
|
4515
|
+
decodeString(byteLength, headerOffset) {
|
|
4516
|
+
if (!this.rawStrings || this.stateIsMapKey()) {
|
|
4517
|
+
return this.decodeUtf8String(byteLength, headerOffset);
|
|
4518
|
+
}
|
|
4519
|
+
return this.decodeBinary(byteLength, headerOffset);
|
|
4520
|
+
}
|
|
4521
|
+
decodeUtf8String(byteLength, headerOffset) {
|
|
4522
|
+
if (byteLength > this.maxStrLength) {
|
|
4523
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
|
|
4524
|
+
}
|
|
4525
|
+
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
4526
|
+
throw MORE_DATA;
|
|
4527
|
+
}
|
|
4528
|
+
const offset = this.pos + headerOffset;
|
|
4529
|
+
let object3;
|
|
4530
|
+
if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) {
|
|
4531
|
+
object3 = this.keyDecoder.decode(this.bytes, offset, byteLength);
|
|
4532
|
+
} else {
|
|
4533
|
+
object3 = (0, utf8_ts_1.utf8Decode)(this.bytes, offset, byteLength);
|
|
4534
|
+
}
|
|
4535
|
+
this.pos += headerOffset + byteLength;
|
|
4536
|
+
return object3;
|
|
4537
|
+
}
|
|
4538
|
+
stateIsMapKey() {
|
|
4539
|
+
if (this.stack.length > 0) {
|
|
4540
|
+
const state = this.stack.top();
|
|
4541
|
+
return state.type === STATE_MAP_KEY;
|
|
4542
|
+
}
|
|
4543
|
+
return false;
|
|
4544
|
+
}
|
|
4545
|
+
decodeBinary(byteLength, headOffset) {
|
|
4546
|
+
if (byteLength > this.maxBinLength) {
|
|
4547
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
|
|
4548
|
+
}
|
|
4549
|
+
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
4550
|
+
throw MORE_DATA;
|
|
4551
|
+
}
|
|
4552
|
+
const offset = this.pos + headOffset;
|
|
4553
|
+
const object3 = this.bytes.subarray(offset, offset + byteLength);
|
|
4554
|
+
this.pos += headOffset + byteLength;
|
|
4555
|
+
return object3;
|
|
4556
|
+
}
|
|
4557
|
+
decodeExtension(size, headOffset) {
|
|
4558
|
+
if (size > this.maxExtLength) {
|
|
4559
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
|
|
4560
|
+
}
|
|
4561
|
+
const extType = this.view.getInt8(this.pos + headOffset);
|
|
4562
|
+
const data = this.decodeBinary(size, headOffset + 1);
|
|
4563
|
+
return this.extensionCodec.decode(data, extType, this.context);
|
|
4564
|
+
}
|
|
4565
|
+
lookU8() {
|
|
4566
|
+
return this.view.getUint8(this.pos);
|
|
4567
|
+
}
|
|
4568
|
+
lookU16() {
|
|
4569
|
+
return this.view.getUint16(this.pos);
|
|
4570
|
+
}
|
|
4571
|
+
lookU32() {
|
|
4572
|
+
return this.view.getUint32(this.pos);
|
|
4573
|
+
}
|
|
4574
|
+
readU8() {
|
|
4575
|
+
const value = this.view.getUint8(this.pos);
|
|
4576
|
+
this.pos++;
|
|
4577
|
+
return value;
|
|
4578
|
+
}
|
|
4579
|
+
readI8() {
|
|
4580
|
+
const value = this.view.getInt8(this.pos);
|
|
4581
|
+
this.pos++;
|
|
4582
|
+
return value;
|
|
4583
|
+
}
|
|
4584
|
+
readU16() {
|
|
4585
|
+
const value = this.view.getUint16(this.pos);
|
|
4586
|
+
this.pos += 2;
|
|
4587
|
+
return value;
|
|
4588
|
+
}
|
|
4589
|
+
readI16() {
|
|
4590
|
+
const value = this.view.getInt16(this.pos);
|
|
4591
|
+
this.pos += 2;
|
|
4592
|
+
return value;
|
|
4593
|
+
}
|
|
4594
|
+
readU32() {
|
|
4595
|
+
const value = this.view.getUint32(this.pos);
|
|
4596
|
+
this.pos += 4;
|
|
4597
|
+
return value;
|
|
4598
|
+
}
|
|
4599
|
+
readI32() {
|
|
4600
|
+
const value = this.view.getInt32(this.pos);
|
|
4601
|
+
this.pos += 4;
|
|
4602
|
+
return value;
|
|
4603
|
+
}
|
|
4604
|
+
readU64() {
|
|
4605
|
+
const value = (0, int_ts_1.getUint64)(this.view, this.pos);
|
|
4606
|
+
this.pos += 8;
|
|
4607
|
+
return value;
|
|
4608
|
+
}
|
|
4609
|
+
readI64() {
|
|
4610
|
+
const value = (0, int_ts_1.getInt64)(this.view, this.pos);
|
|
4611
|
+
this.pos += 8;
|
|
4612
|
+
return value;
|
|
4613
|
+
}
|
|
4614
|
+
readU64AsBigInt() {
|
|
4615
|
+
const value = this.view.getBigUint64(this.pos);
|
|
4616
|
+
this.pos += 8;
|
|
4617
|
+
return value;
|
|
4618
|
+
}
|
|
4619
|
+
readI64AsBigInt() {
|
|
4620
|
+
const value = this.view.getBigInt64(this.pos);
|
|
4621
|
+
this.pos += 8;
|
|
4622
|
+
return value;
|
|
4623
|
+
}
|
|
4624
|
+
readF32() {
|
|
4625
|
+
const value = this.view.getFloat32(this.pos);
|
|
4626
|
+
this.pos += 4;
|
|
4627
|
+
return value;
|
|
4628
|
+
}
|
|
4629
|
+
readF64() {
|
|
4630
|
+
const value = this.view.getFloat64(this.pos);
|
|
4631
|
+
this.pos += 8;
|
|
4632
|
+
return value;
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
exports.Decoder = Decoder;
|
|
4636
|
+
});
|
|
4637
|
+
|
|
4638
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/decode.cjs
|
|
4639
|
+
var require_decode = __commonJS((exports) => {
|
|
4640
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4641
|
+
exports.decode = decode;
|
|
4642
|
+
exports.decodeMulti = decodeMulti;
|
|
4643
|
+
var Decoder_ts_1 = require_Decoder();
|
|
4644
|
+
function decode(buffer, options) {
|
|
4645
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
4646
|
+
return decoder.decode(buffer);
|
|
4647
|
+
}
|
|
4648
|
+
function decodeMulti(buffer, options) {
|
|
4649
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
4650
|
+
return decoder.decodeMulti(buffer);
|
|
4651
|
+
}
|
|
4652
|
+
});
|
|
4653
|
+
|
|
4654
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/utils/stream.cjs
|
|
4655
|
+
var require_stream = __commonJS((exports) => {
|
|
4656
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4657
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
4658
|
+
exports.asyncIterableFromStream = asyncIterableFromStream;
|
|
4659
|
+
exports.ensureAsyncIterable = ensureAsyncIterable;
|
|
4660
|
+
function isAsyncIterable(object3) {
|
|
4661
|
+
return object3[Symbol.asyncIterator] != null;
|
|
4662
|
+
}
|
|
4663
|
+
async function* asyncIterableFromStream(stream) {
|
|
4664
|
+
const reader = stream.getReader();
|
|
4665
|
+
try {
|
|
4666
|
+
while (true) {
|
|
4667
|
+
const { done, value } = await reader.read();
|
|
4668
|
+
if (done) {
|
|
4669
|
+
return;
|
|
4670
|
+
}
|
|
4671
|
+
yield value;
|
|
4672
|
+
}
|
|
4673
|
+
} finally {
|
|
4674
|
+
reader.releaseLock();
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
function ensureAsyncIterable(streamLike) {
|
|
4678
|
+
if (isAsyncIterable(streamLike)) {
|
|
4679
|
+
return streamLike;
|
|
4680
|
+
} else {
|
|
4681
|
+
return asyncIterableFromStream(streamLike);
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
});
|
|
4685
|
+
|
|
4686
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/decodeAsync.cjs
|
|
4687
|
+
var require_decodeAsync = __commonJS((exports) => {
|
|
4688
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4689
|
+
exports.decodeAsync = decodeAsync;
|
|
4690
|
+
exports.decodeArrayStream = decodeArrayStream;
|
|
4691
|
+
exports.decodeMultiStream = decodeMultiStream;
|
|
4692
|
+
var Decoder_ts_1 = require_Decoder();
|
|
4693
|
+
var stream_ts_1 = require_stream();
|
|
4694
|
+
async function decodeAsync(streamLike, options) {
|
|
4695
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
4696
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
4697
|
+
return decoder.decodeAsync(stream);
|
|
4698
|
+
}
|
|
4699
|
+
function decodeArrayStream(streamLike, options) {
|
|
4700
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
4701
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
4702
|
+
return decoder.decodeArrayStream(stream);
|
|
4703
|
+
}
|
|
4704
|
+
function decodeMultiStream(streamLike, options) {
|
|
4705
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
4706
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
4707
|
+
return decoder.decodeStream(stream);
|
|
4708
|
+
}
|
|
4709
|
+
});
|
|
4710
|
+
|
|
4711
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.cjs/index.cjs
|
|
4712
|
+
var require_dist2 = __commonJS((exports) => {
|
|
4713
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4714
|
+
exports.decodeTimestampExtension = exports.encodeTimestampExtension = exports.decodeTimestampToTimeSpec = exports.encodeTimeSpecToTimestamp = exports.encodeDateToTimeSpec = exports.EXT_TIMESTAMP = exports.ExtData = exports.ExtensionCodec = exports.Encoder = exports.DecodeError = exports.Decoder = exports.decodeMultiStream = exports.decodeArrayStream = exports.decodeAsync = exports.decodeMulti = exports.decode = exports.encode = undefined;
|
|
4715
|
+
var encode_ts_1 = require_encode();
|
|
4716
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function() {
|
|
4717
|
+
return encode_ts_1.encode;
|
|
4718
|
+
} });
|
|
4719
|
+
var decode_ts_1 = require_decode();
|
|
4720
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function() {
|
|
4721
|
+
return decode_ts_1.decode;
|
|
4722
|
+
} });
|
|
4723
|
+
Object.defineProperty(exports, "decodeMulti", { enumerable: true, get: function() {
|
|
4724
|
+
return decode_ts_1.decodeMulti;
|
|
4725
|
+
} });
|
|
4726
|
+
var decodeAsync_ts_1 = require_decodeAsync();
|
|
4727
|
+
Object.defineProperty(exports, "decodeAsync", { enumerable: true, get: function() {
|
|
4728
|
+
return decodeAsync_ts_1.decodeAsync;
|
|
4729
|
+
} });
|
|
4730
|
+
Object.defineProperty(exports, "decodeArrayStream", { enumerable: true, get: function() {
|
|
4731
|
+
return decodeAsync_ts_1.decodeArrayStream;
|
|
4732
|
+
} });
|
|
4733
|
+
Object.defineProperty(exports, "decodeMultiStream", { enumerable: true, get: function() {
|
|
4734
|
+
return decodeAsync_ts_1.decodeMultiStream;
|
|
4735
|
+
} });
|
|
4736
|
+
var Decoder_ts_1 = require_Decoder();
|
|
4737
|
+
Object.defineProperty(exports, "Decoder", { enumerable: true, get: function() {
|
|
4738
|
+
return Decoder_ts_1.Decoder;
|
|
4739
|
+
} });
|
|
4740
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
4741
|
+
Object.defineProperty(exports, "DecodeError", { enumerable: true, get: function() {
|
|
4742
|
+
return DecodeError_ts_1.DecodeError;
|
|
4743
|
+
} });
|
|
4744
|
+
var Encoder_ts_1 = require_Encoder();
|
|
4745
|
+
Object.defineProperty(exports, "Encoder", { enumerable: true, get: function() {
|
|
4746
|
+
return Encoder_ts_1.Encoder;
|
|
4747
|
+
} });
|
|
4748
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
4749
|
+
Object.defineProperty(exports, "ExtensionCodec", { enumerable: true, get: function() {
|
|
4750
|
+
return ExtensionCodec_ts_1.ExtensionCodec;
|
|
4751
|
+
} });
|
|
4752
|
+
var ExtData_ts_1 = require_ExtData();
|
|
4753
|
+
Object.defineProperty(exports, "ExtData", { enumerable: true, get: function() {
|
|
4754
|
+
return ExtData_ts_1.ExtData;
|
|
4755
|
+
} });
|
|
4756
|
+
var timestamp_ts_1 = require_timestamp();
|
|
4757
|
+
Object.defineProperty(exports, "EXT_TIMESTAMP", { enumerable: true, get: function() {
|
|
4758
|
+
return timestamp_ts_1.EXT_TIMESTAMP;
|
|
4759
|
+
} });
|
|
4760
|
+
Object.defineProperty(exports, "encodeDateToTimeSpec", { enumerable: true, get: function() {
|
|
4761
|
+
return timestamp_ts_1.encodeDateToTimeSpec;
|
|
4762
|
+
} });
|
|
4763
|
+
Object.defineProperty(exports, "encodeTimeSpecToTimestamp", { enumerable: true, get: function() {
|
|
4764
|
+
return timestamp_ts_1.encodeTimeSpecToTimestamp;
|
|
4765
|
+
} });
|
|
4766
|
+
Object.defineProperty(exports, "decodeTimestampToTimeSpec", { enumerable: true, get: function() {
|
|
4767
|
+
return timestamp_ts_1.decodeTimestampToTimeSpec;
|
|
4768
|
+
} });
|
|
4769
|
+
Object.defineProperty(exports, "encodeTimestampExtension", { enumerable: true, get: function() {
|
|
4770
|
+
return timestamp_ts_1.encodeTimestampExtension;
|
|
4771
|
+
} });
|
|
4772
|
+
Object.defineProperty(exports, "decodeTimestampExtension", { enumerable: true, get: function() {
|
|
4773
|
+
return timestamp_ts_1.decodeTimestampExtension;
|
|
4774
|
+
} });
|
|
4775
|
+
});
|
|
4776
|
+
|
|
4777
|
+
// ../../node_modules/.bun/robot3@0.4.1/node_modules/robot3/dist/machine.js
|
|
4778
|
+
var require_machine = __commonJS((exports) => {
|
|
4779
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4780
|
+
function valueEnumerable(value) {
|
|
4781
|
+
return { enumerable: true, value };
|
|
4782
|
+
}
|
|
4783
|
+
function valueEnumerableWritable(value) {
|
|
4784
|
+
return { enumerable: true, writable: true, value };
|
|
4785
|
+
}
|
|
4786
|
+
var d = {};
|
|
4787
|
+
var truthy = () => true;
|
|
4788
|
+
var empty = () => ({});
|
|
4789
|
+
var identity = (a) => a;
|
|
4790
|
+
var callBoth = (par, fn, self, args) => par.apply(self, args) && fn.apply(self, args);
|
|
4791
|
+
var callForward = (par, fn, self, [a, b]) => fn.call(self, par.call(self, a, b), b);
|
|
4792
|
+
var create = (a, b) => Object.freeze(Object.create(a, b));
|
|
4793
|
+
function stack(fns, def, caller) {
|
|
4794
|
+
return fns.reduce((par, fn) => {
|
|
4795
|
+
return function(...args) {
|
|
4796
|
+
return caller(par, fn, this, args);
|
|
4797
|
+
};
|
|
4798
|
+
}, def);
|
|
4799
|
+
}
|
|
4800
|
+
function fnType(fn) {
|
|
4801
|
+
return create(this, { fn: valueEnumerable(fn) });
|
|
4802
|
+
}
|
|
4803
|
+
var reduceType = {};
|
|
4804
|
+
var reduce = fnType.bind(reduceType);
|
|
4805
|
+
var action = (fn) => reduce((ctx, ev) => !!~fn(ctx, ev) && ctx);
|
|
4806
|
+
var guardType = {};
|
|
4807
|
+
var guard = fnType.bind(guardType);
|
|
4808
|
+
function filter(Type, arr) {
|
|
4809
|
+
return arr.filter((value) => Type.isPrototypeOf(value));
|
|
4810
|
+
}
|
|
4811
|
+
function makeTransition(from, to, ...args) {
|
|
4812
|
+
let guards = stack(filter(guardType, args).map((t) => t.fn), truthy, callBoth);
|
|
4813
|
+
let reducers = stack(filter(reduceType, args).map((t) => t.fn), identity, callForward);
|
|
4814
|
+
return create(this, {
|
|
4815
|
+
from: valueEnumerable(from),
|
|
4816
|
+
to: valueEnumerable(to),
|
|
4817
|
+
guards: valueEnumerable(guards),
|
|
4818
|
+
reducers: valueEnumerable(reducers)
|
|
4819
|
+
});
|
|
4820
|
+
}
|
|
4821
|
+
var transitionType = {};
|
|
4822
|
+
var immediateType = {};
|
|
4823
|
+
var transition = makeTransition.bind(transitionType);
|
|
4824
|
+
var immediate = makeTransition.bind(immediateType, null);
|
|
4825
|
+
function enterImmediate(machine2, service2, event) {
|
|
4826
|
+
return transitionTo(service2, machine2, event, this.immediates) || machine2;
|
|
4827
|
+
}
|
|
4828
|
+
function transitionsToMap(transitions) {
|
|
4829
|
+
let m = new Map;
|
|
4830
|
+
for (let t of transitions) {
|
|
4831
|
+
if (!m.has(t.from))
|
|
4832
|
+
m.set(t.from, []);
|
|
4833
|
+
m.get(t.from).push(t);
|
|
4834
|
+
}
|
|
4835
|
+
return m;
|
|
4836
|
+
}
|
|
4837
|
+
var stateType = { enter: identity };
|
|
4838
|
+
function state(...args) {
|
|
4839
|
+
let transitions = filter(transitionType, args);
|
|
4840
|
+
let immediates = filter(immediateType, args);
|
|
4841
|
+
let desc = {
|
|
4842
|
+
final: valueEnumerable(args.length === 0),
|
|
4843
|
+
transitions: valueEnumerable(transitionsToMap(transitions))
|
|
4844
|
+
};
|
|
4845
|
+
if (immediates.length) {
|
|
4846
|
+
desc.immediates = valueEnumerable(immediates);
|
|
4847
|
+
desc.enter = valueEnumerable(enterImmediate);
|
|
4848
|
+
}
|
|
4849
|
+
return create(stateType, desc);
|
|
4850
|
+
}
|
|
4851
|
+
var invokeFnType = {
|
|
4852
|
+
enter(machine2, service2, event) {
|
|
4853
|
+
let rn = this.fn.call(service2, service2.context, event);
|
|
4854
|
+
if (machine.isPrototypeOf(rn))
|
|
4855
|
+
return create(invokeMachineType, {
|
|
4856
|
+
machine: valueEnumerable(rn),
|
|
4857
|
+
transitions: valueEnumerable(this.transitions)
|
|
4858
|
+
}).enter(machine2, service2, event);
|
|
4859
|
+
rn.then((data) => service2.send({ type: "done", data })).catch((error) => service2.send({ type: "error", error }));
|
|
4860
|
+
return machine2;
|
|
4861
|
+
}
|
|
4862
|
+
};
|
|
4863
|
+
var invokeMachineType = {
|
|
4864
|
+
enter(machine2, service2, event) {
|
|
4865
|
+
service2.child = interpret(this.machine, (s) => {
|
|
4866
|
+
service2.onChange(s);
|
|
4867
|
+
if (service2.child == s && s.machine.state.value.final) {
|
|
4868
|
+
delete service2.child;
|
|
4869
|
+
service2.send({ type: "done", data: s.context });
|
|
4870
|
+
}
|
|
4871
|
+
}, service2.context, event);
|
|
4872
|
+
if (service2.child.machine.state.value.final) {
|
|
4873
|
+
let data = service2.child.context;
|
|
4874
|
+
delete service2.child;
|
|
4875
|
+
return transitionTo(service2, machine2, { type: "done", data }, this.transitions.get("done"));
|
|
4876
|
+
}
|
|
4877
|
+
return machine2;
|
|
4878
|
+
}
|
|
4879
|
+
};
|
|
4880
|
+
function invoke(fn, ...transitions) {
|
|
4881
|
+
let t = valueEnumerable(transitionsToMap(transitions));
|
|
4882
|
+
return machine.isPrototypeOf(fn) ? create(invokeMachineType, {
|
|
4883
|
+
machine: valueEnumerable(fn),
|
|
4884
|
+
transitions: t
|
|
4885
|
+
}) : create(invokeFnType, {
|
|
4886
|
+
fn: valueEnumerable(fn),
|
|
4887
|
+
transitions: t
|
|
4888
|
+
});
|
|
4889
|
+
}
|
|
4890
|
+
var machine = {
|
|
4891
|
+
get state() {
|
|
4892
|
+
return {
|
|
4893
|
+
name: this.current,
|
|
4894
|
+
value: this.states[this.current]
|
|
4895
|
+
};
|
|
4896
|
+
}
|
|
4897
|
+
};
|
|
4898
|
+
function createMachine(current, states, contextFn = empty) {
|
|
4899
|
+
if (typeof current !== "string") {
|
|
4900
|
+
contextFn = states || empty;
|
|
4901
|
+
states = current;
|
|
4902
|
+
current = Object.keys(states)[0];
|
|
4903
|
+
}
|
|
4904
|
+
if (d._create)
|
|
4905
|
+
d._create(current, states);
|
|
4906
|
+
return create(machine, {
|
|
4907
|
+
context: valueEnumerable(contextFn),
|
|
4908
|
+
current: valueEnumerable(current),
|
|
4909
|
+
states: valueEnumerable(states)
|
|
4910
|
+
});
|
|
4911
|
+
}
|
|
4912
|
+
function transitionTo(service2, machine2, fromEvent, candidates) {
|
|
4913
|
+
let { context } = service2;
|
|
4914
|
+
for (let { to, guards, reducers } of candidates) {
|
|
4915
|
+
if (guards(context, fromEvent)) {
|
|
4916
|
+
service2.context = reducers.call(service2, context, fromEvent);
|
|
4917
|
+
let original = machine2.original || machine2;
|
|
4918
|
+
let newMachine = create(original, {
|
|
4919
|
+
current: valueEnumerable(to),
|
|
4920
|
+
original: { value: original }
|
|
4921
|
+
});
|
|
4922
|
+
if (d._onEnter)
|
|
4923
|
+
d._onEnter(machine2, to, service2.context, context, fromEvent);
|
|
4924
|
+
let state2 = newMachine.state.value;
|
|
4925
|
+
return state2.enter(newMachine, service2, fromEvent);
|
|
4926
|
+
}
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
function send(service2, event) {
|
|
4930
|
+
let eventName = event.type || event;
|
|
4931
|
+
let { machine: machine2 } = service2;
|
|
4932
|
+
let { value: state2, name: currentStateName } = machine2.state;
|
|
4933
|
+
if (state2.transitions.has(eventName)) {
|
|
4934
|
+
return transitionTo(service2, machine2, event, state2.transitions.get(eventName)) || machine2;
|
|
4935
|
+
} else {
|
|
4936
|
+
if (d._send)
|
|
4937
|
+
d._send(eventName, currentStateName);
|
|
4938
|
+
}
|
|
4939
|
+
return machine2;
|
|
4940
|
+
}
|
|
4941
|
+
var service = {
|
|
4942
|
+
send(event) {
|
|
4943
|
+
this.machine = send(this, event);
|
|
4944
|
+
this.onChange(this);
|
|
4945
|
+
}
|
|
4946
|
+
};
|
|
4947
|
+
function interpret(machine2, onChange, initialContext, event) {
|
|
4948
|
+
let s = Object.create(service, {
|
|
4949
|
+
machine: valueEnumerableWritable(machine2),
|
|
4950
|
+
context: valueEnumerableWritable(machine2.context(initialContext, event)),
|
|
4951
|
+
onChange: valueEnumerable(onChange)
|
|
4952
|
+
});
|
|
4953
|
+
s.send = s.send.bind(s);
|
|
4954
|
+
s.machine = s.machine.state.value.enter(s.machine, s, event);
|
|
4955
|
+
return s;
|
|
4956
|
+
}
|
|
4957
|
+
exports.action = action;
|
|
4958
|
+
exports.createMachine = createMachine;
|
|
4959
|
+
exports.d = d;
|
|
4960
|
+
exports.guard = guard;
|
|
4961
|
+
exports.immediate = immediate;
|
|
4962
|
+
exports.interpret = interpret;
|
|
4963
|
+
exports.invoke = invoke;
|
|
4964
|
+
exports.reduce = reduce;
|
|
4965
|
+
exports.state = state;
|
|
4966
|
+
exports.transition = transition;
|
|
4967
|
+
});
|
|
4968
|
+
|
|
4969
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/realtime.js
|
|
4970
|
+
var require_realtime = __commonJS((exports) => {
|
|
4971
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4972
|
+
exports.createRealtimeClient = createRealtimeClient;
|
|
4973
|
+
var msgpack_1 = require_dist2();
|
|
4974
|
+
var robot3_1 = require_machine();
|
|
4975
|
+
var auth_1 = require_auth();
|
|
4976
|
+
var response_1 = require_response();
|
|
4977
|
+
var runtime_1 = require_runtime();
|
|
4978
|
+
var utils_1 = require_utils3();
|
|
4979
|
+
var initialState = () => ({
|
|
4980
|
+
enqueuedMessage: undefined
|
|
4981
|
+
});
|
|
4982
|
+
function hasToken(context) {
|
|
4983
|
+
return context.token !== undefined;
|
|
4984
|
+
}
|
|
4985
|
+
function noToken(context) {
|
|
4986
|
+
return !hasToken(context);
|
|
4987
|
+
}
|
|
4988
|
+
function enqueueMessage(context, event) {
|
|
4989
|
+
return Object.assign(Object.assign({}, context), { enqueuedMessage: event.message });
|
|
4990
|
+
}
|
|
4991
|
+
function closeConnection(context) {
|
|
4992
|
+
if (context.websocket && context.websocket.readyState === WebSocket.OPEN) {
|
|
4993
|
+
context.websocket.close();
|
|
4994
|
+
}
|
|
4995
|
+
return Object.assign(Object.assign({}, context), { websocket: undefined });
|
|
4996
|
+
}
|
|
4997
|
+
function sendMessage(context, event) {
|
|
4998
|
+
if (context.websocket && context.websocket.readyState === WebSocket.OPEN) {
|
|
4999
|
+
if (event.message instanceof Uint8Array) {
|
|
5000
|
+
context.websocket.send(event.message);
|
|
5001
|
+
} else {
|
|
5002
|
+
context.websocket.send((0, msgpack_1.encode)(event.message));
|
|
5003
|
+
}
|
|
5004
|
+
return Object.assign(Object.assign({}, context), { enqueuedMessage: undefined });
|
|
5005
|
+
}
|
|
5006
|
+
return Object.assign(Object.assign({}, context), { enqueuedMessage: event.message });
|
|
5007
|
+
}
|
|
5008
|
+
function expireToken(context) {
|
|
5009
|
+
return Object.assign(Object.assign({}, context), { token: undefined });
|
|
5010
|
+
}
|
|
5011
|
+
function setToken(context, event) {
|
|
5012
|
+
return Object.assign(Object.assign({}, context), { token: event.token });
|
|
5013
|
+
}
|
|
5014
|
+
function connectionEstablished(context, event) {
|
|
5015
|
+
return Object.assign(Object.assign({}, context), { websocket: event.websocket });
|
|
5016
|
+
}
|
|
5017
|
+
var connectionStateMachine = (0, robot3_1.createMachine)("idle", {
|
|
5018
|
+
idle: (0, robot3_1.state)((0, robot3_1.transition)("send", "connecting", (0, robot3_1.reduce)(enqueueMessage)), (0, robot3_1.transition)("expireToken", "idle", (0, robot3_1.reduce)(expireToken)), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection))),
|
|
5019
|
+
connecting: (0, robot3_1.state)((0, robot3_1.transition)("connecting", "connecting"), (0, robot3_1.transition)("connected", "active", (0, robot3_1.reduce)(connectionEstablished)), (0, robot3_1.transition)("connectionClosed", "idle", (0, robot3_1.reduce)(closeConnection)), (0, robot3_1.transition)("send", "connecting", (0, robot3_1.reduce)(enqueueMessage)), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection)), (0, robot3_1.immediate)("authRequired", (0, robot3_1.guard)(noToken))),
|
|
5020
|
+
authRequired: (0, robot3_1.state)((0, robot3_1.transition)("initiateAuth", "authInProgress"), (0, robot3_1.transition)("send", "authRequired", (0, robot3_1.reduce)(enqueueMessage)), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection))),
|
|
5021
|
+
authInProgress: (0, robot3_1.state)((0, robot3_1.transition)("authenticated", "connecting", (0, robot3_1.reduce)(setToken)), (0, robot3_1.transition)("unauthorized", "idle", (0, robot3_1.reduce)(expireToken), (0, robot3_1.reduce)(closeConnection)), (0, robot3_1.transition)("send", "authInProgress", (0, robot3_1.reduce)(enqueueMessage)), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection))),
|
|
5022
|
+
active: (0, robot3_1.state)((0, robot3_1.transition)("send", "active", (0, robot3_1.reduce)(sendMessage)), (0, robot3_1.transition)("unauthorized", "idle", (0, robot3_1.reduce)(expireToken)), (0, robot3_1.transition)("connectionClosed", "idle", (0, robot3_1.reduce)(closeConnection)), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection))),
|
|
5023
|
+
failed: (0, robot3_1.state)((0, robot3_1.transition)("send", "failed"), (0, robot3_1.transition)("close", "idle", (0, robot3_1.reduce)(closeConnection)))
|
|
5024
|
+
}, initialState);
|
|
5025
|
+
function buildRealtimeUrl(app, { token, maxBuffering }) {
|
|
5026
|
+
if (maxBuffering !== undefined && (maxBuffering < 1 || maxBuffering > 60)) {
|
|
5027
|
+
throw new Error("The `maxBuffering` must be between 1 and 60 (inclusive)");
|
|
5028
|
+
}
|
|
5029
|
+
const queryParams = new URLSearchParams({
|
|
5030
|
+
fal_jwt_token: token
|
|
5031
|
+
});
|
|
5032
|
+
if (maxBuffering !== undefined) {
|
|
5033
|
+
queryParams.set("max_buffering", maxBuffering.toFixed(0));
|
|
5034
|
+
}
|
|
5035
|
+
const appId = (0, utils_1.ensureEndpointIdFormat)(app);
|
|
5036
|
+
return `wss://fal.run/${appId}/realtime?${queryParams.toString()}`;
|
|
5037
|
+
}
|
|
5038
|
+
var DEFAULT_THROTTLE_INTERVAL = 128;
|
|
5039
|
+
function isUnauthorizedError(message) {
|
|
5040
|
+
return message["status"] === "error" && message["error"] === "Unauthorized";
|
|
5041
|
+
}
|
|
5042
|
+
var WebSocketErrorCodes = {
|
|
5043
|
+
NORMAL_CLOSURE: 1000,
|
|
5044
|
+
GOING_AWAY: 1001
|
|
5045
|
+
};
|
|
5046
|
+
var connectionCache = new Map;
|
|
5047
|
+
var connectionCallbacks = new Map;
|
|
5048
|
+
function reuseInterpreter(key, throttleInterval, onChange) {
|
|
5049
|
+
if (!connectionCache.has(key)) {
|
|
5050
|
+
const machine = (0, robot3_1.interpret)(connectionStateMachine, onChange);
|
|
5051
|
+
connectionCache.set(key, Object.assign(Object.assign({}, machine), { throttledSend: throttleInterval > 0 ? (0, utils_1.throttle)(machine.send, throttleInterval, true) : machine.send }));
|
|
5052
|
+
}
|
|
5053
|
+
return connectionCache.get(key);
|
|
5054
|
+
}
|
|
5055
|
+
var noop = () => {};
|
|
5056
|
+
var NoOpConnection = {
|
|
5057
|
+
send: noop,
|
|
5058
|
+
close: noop
|
|
5059
|
+
};
|
|
5060
|
+
function isSuccessfulResult(data) {
|
|
5061
|
+
return data.status !== "error" && data.type !== "x-fal-message" && !isFalErrorResult(data);
|
|
5062
|
+
}
|
|
5063
|
+
function isFalErrorResult(data) {
|
|
5064
|
+
return data.type === "x-fal-error";
|
|
5065
|
+
}
|
|
5066
|
+
function createRealtimeClient({ config }) {
|
|
5067
|
+
return {
|
|
5068
|
+
connect(app, handler) {
|
|
5069
|
+
const {
|
|
5070
|
+
clientOnly = (0, utils_1.isReact)() && !(0, runtime_1.isBrowser)(),
|
|
5071
|
+
connectionKey = crypto.randomUUID(),
|
|
5072
|
+
maxBuffering,
|
|
5073
|
+
throttleInterval = DEFAULT_THROTTLE_INTERVAL
|
|
5074
|
+
} = handler;
|
|
5075
|
+
if (clientOnly && !(0, runtime_1.isBrowser)()) {
|
|
5076
|
+
return NoOpConnection;
|
|
5077
|
+
}
|
|
5078
|
+
let previousState;
|
|
5079
|
+
connectionCallbacks.set(connectionKey, {
|
|
5080
|
+
onError: handler.onError,
|
|
5081
|
+
onResult: handler.onResult
|
|
5082
|
+
});
|
|
5083
|
+
const getCallbacks = () => connectionCallbacks.get(connectionKey);
|
|
5084
|
+
const stateMachine = reuseInterpreter(connectionKey, throttleInterval, ({ context, machine, send: send2 }) => {
|
|
5085
|
+
const { enqueuedMessage, token } = context;
|
|
5086
|
+
if (machine.current === "active" && enqueuedMessage) {
|
|
5087
|
+
send2({ type: "send", message: enqueuedMessage });
|
|
5088
|
+
}
|
|
5089
|
+
if (machine.current === "authRequired" && token === undefined && previousState !== machine.current) {
|
|
5090
|
+
send2({ type: "initiateAuth" });
|
|
5091
|
+
(0, auth_1.getTemporaryAuthToken)(app, config).then((token2) => {
|
|
5092
|
+
send2({ type: "authenticated", token: token2 });
|
|
5093
|
+
const tokenExpirationTimeout = Math.round(auth_1.TOKEN_EXPIRATION_SECONDS * 0.9 * 1000);
|
|
5094
|
+
setTimeout(() => {
|
|
5095
|
+
send2({ type: "expireToken" });
|
|
5096
|
+
}, tokenExpirationTimeout);
|
|
5097
|
+
}).catch((error) => {
|
|
5098
|
+
send2({ type: "unauthorized", error });
|
|
5099
|
+
});
|
|
5100
|
+
}
|
|
5101
|
+
if (machine.current === "connecting" && previousState !== machine.current && token !== undefined) {
|
|
5102
|
+
const ws = new WebSocket(buildRealtimeUrl(app, { token, maxBuffering }));
|
|
5103
|
+
ws.onopen = () => {
|
|
5104
|
+
send2({ type: "connected", websocket: ws });
|
|
5105
|
+
};
|
|
5106
|
+
ws.onclose = (event) => {
|
|
5107
|
+
if (event.code !== WebSocketErrorCodes.NORMAL_CLOSURE) {
|
|
5108
|
+
const { onError = noop } = getCallbacks();
|
|
5109
|
+
onError(new response_1.ApiError({
|
|
5110
|
+
message: `Error closing the connection: ${event.reason}`,
|
|
5111
|
+
status: event.code
|
|
5112
|
+
}));
|
|
5113
|
+
}
|
|
5114
|
+
send2({ type: "connectionClosed", code: event.code });
|
|
5115
|
+
};
|
|
5116
|
+
ws.onerror = (event) => {
|
|
5117
|
+
const { onError = noop } = getCallbacks();
|
|
5118
|
+
onError(new response_1.ApiError({ message: "Unknown error", status: 500 }));
|
|
5119
|
+
};
|
|
5120
|
+
ws.onmessage = (event) => {
|
|
5121
|
+
const { onResult } = getCallbacks();
|
|
5122
|
+
if (event.data instanceof ArrayBuffer) {
|
|
5123
|
+
const result = (0, msgpack_1.decode)(new Uint8Array(event.data));
|
|
5124
|
+
onResult(result);
|
|
5125
|
+
return;
|
|
5126
|
+
}
|
|
5127
|
+
if (event.data instanceof Uint8Array) {
|
|
5128
|
+
const result = (0, msgpack_1.decode)(event.data);
|
|
5129
|
+
onResult(result);
|
|
5130
|
+
return;
|
|
5131
|
+
}
|
|
5132
|
+
if (event.data instanceof Blob) {
|
|
5133
|
+
event.data.arrayBuffer().then((buffer) => {
|
|
5134
|
+
const result = (0, msgpack_1.decode)(new Uint8Array(buffer));
|
|
5135
|
+
onResult(result);
|
|
5136
|
+
});
|
|
5137
|
+
return;
|
|
5138
|
+
}
|
|
5139
|
+
const data = JSON.parse(event.data);
|
|
5140
|
+
if (isUnauthorizedError(data)) {
|
|
5141
|
+
send2({
|
|
5142
|
+
type: "unauthorized",
|
|
5143
|
+
error: new Error("Unauthorized")
|
|
5144
|
+
});
|
|
5145
|
+
return;
|
|
5146
|
+
}
|
|
5147
|
+
if (isSuccessfulResult(data)) {
|
|
5148
|
+
onResult(data);
|
|
5149
|
+
return;
|
|
5150
|
+
}
|
|
5151
|
+
if (isFalErrorResult(data)) {
|
|
5152
|
+
if (data.error === "TIMEOUT") {
|
|
5153
|
+
return;
|
|
5154
|
+
}
|
|
5155
|
+
const { onError = noop } = getCallbacks();
|
|
5156
|
+
onError(new response_1.ApiError({
|
|
5157
|
+
message: `${data.error}: ${data.reason}`,
|
|
5158
|
+
status: 400,
|
|
5159
|
+
body: data
|
|
5160
|
+
}));
|
|
5161
|
+
return;
|
|
5162
|
+
}
|
|
5163
|
+
};
|
|
5164
|
+
}
|
|
5165
|
+
previousState = machine.current;
|
|
5166
|
+
});
|
|
5167
|
+
const send = (input) => {
|
|
5168
|
+
stateMachine.throttledSend({
|
|
5169
|
+
type: "send",
|
|
5170
|
+
message: input
|
|
5171
|
+
});
|
|
5172
|
+
};
|
|
5173
|
+
const close = () => {
|
|
5174
|
+
stateMachine.send({ type: "close" });
|
|
5175
|
+
};
|
|
5176
|
+
return {
|
|
5177
|
+
send,
|
|
5178
|
+
close
|
|
5179
|
+
};
|
|
5180
|
+
}
|
|
5181
|
+
};
|
|
5182
|
+
}
|
|
5183
|
+
});
|
|
5184
|
+
|
|
5185
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/client.js
|
|
5186
|
+
var require_client = __commonJS((exports) => {
|
|
5187
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
5188
|
+
function adopt(value) {
|
|
5189
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
5190
|
+
resolve(value);
|
|
5191
|
+
});
|
|
5192
|
+
}
|
|
5193
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
5194
|
+
function fulfilled(value) {
|
|
5195
|
+
try {
|
|
5196
|
+
step(generator.next(value));
|
|
5197
|
+
} catch (e) {
|
|
5198
|
+
reject(e);
|
|
5199
|
+
}
|
|
5200
|
+
}
|
|
5201
|
+
function rejected(value) {
|
|
5202
|
+
try {
|
|
5203
|
+
step(generator["throw"](value));
|
|
5204
|
+
} catch (e) {
|
|
5205
|
+
reject(e);
|
|
5206
|
+
}
|
|
5207
|
+
}
|
|
5208
|
+
function step(result) {
|
|
5209
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
5210
|
+
}
|
|
5211
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
5212
|
+
});
|
|
5213
|
+
};
|
|
5214
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5215
|
+
exports.createFalClient = createFalClient;
|
|
5216
|
+
var config_1 = require_config();
|
|
5217
|
+
var queue_1 = require_queue();
|
|
5218
|
+
var realtime_1 = require_realtime();
|
|
5219
|
+
var request_1 = require_request();
|
|
5220
|
+
var response_1 = require_response();
|
|
5221
|
+
var storage_1 = require_storage();
|
|
5222
|
+
var streaming_1 = require_streaming();
|
|
5223
|
+
function createFalClient(userConfig = {}) {
|
|
5224
|
+
const config = (0, config_1.createConfig)(userConfig);
|
|
5225
|
+
const storage = (0, storage_1.createStorageClient)({ config });
|
|
5226
|
+
const queue = (0, queue_1.createQueueClient)({ config, storage });
|
|
5227
|
+
const streaming = (0, streaming_1.createStreamingClient)({ config, storage });
|
|
5228
|
+
const realtime = (0, realtime_1.createRealtimeClient)({ config });
|
|
5229
|
+
return {
|
|
5230
|
+
queue,
|
|
5231
|
+
realtime,
|
|
5232
|
+
storage,
|
|
5233
|
+
streaming,
|
|
5234
|
+
stream: streaming.stream,
|
|
5235
|
+
run(endpointId_1) {
|
|
5236
|
+
return __awaiter(this, arguments, undefined, function* (endpointId, options = {}) {
|
|
5237
|
+
const input = options.input ? yield storage.transformInput(options.input) : undefined;
|
|
5238
|
+
return (0, request_1.dispatchRequest)({
|
|
5239
|
+
method: options.method,
|
|
5240
|
+
targetUrl: (0, request_1.buildUrl)(endpointId, options),
|
|
5241
|
+
input,
|
|
5242
|
+
headers: (0, storage_1.buildObjectLifecycleHeaders)(options.storageSettings),
|
|
5243
|
+
config: Object.assign(Object.assign({}, config), { responseHandler: response_1.resultResponseHandler }),
|
|
5244
|
+
options: {
|
|
5245
|
+
signal: options.abortSignal,
|
|
5246
|
+
retry: {
|
|
5247
|
+
maxRetries: 3,
|
|
5248
|
+
baseDelay: 500,
|
|
5249
|
+
maxDelay: 15000
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
});
|
|
5253
|
+
});
|
|
5254
|
+
},
|
|
5255
|
+
subscribe: (endpointId, options) => __awaiter(this, undefined, undefined, function* () {
|
|
5256
|
+
const { request_id: requestId } = yield queue.submit(endpointId, options);
|
|
5257
|
+
if (options.onEnqueue) {
|
|
5258
|
+
options.onEnqueue(requestId);
|
|
5259
|
+
}
|
|
5260
|
+
yield queue.subscribeToStatus(endpointId, Object.assign({ requestId }, options));
|
|
5261
|
+
return queue.result(endpointId, { requestId });
|
|
5262
|
+
})
|
|
5263
|
+
};
|
|
5264
|
+
}
|
|
5265
|
+
});
|
|
5266
|
+
|
|
5267
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/types/common.js
|
|
5268
|
+
var require_common = __commonJS((exports) => {
|
|
5269
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5270
|
+
exports.isQueueStatus = isQueueStatus;
|
|
5271
|
+
exports.isCompletedQueueStatus = isCompletedQueueStatus;
|
|
5272
|
+
function isQueueStatus(obj) {
|
|
5273
|
+
return obj && obj.status && obj.response_url;
|
|
5274
|
+
}
|
|
5275
|
+
function isCompletedQueueStatus(obj) {
|
|
5276
|
+
return isQueueStatus(obj) && obj.status === "COMPLETED";
|
|
5277
|
+
}
|
|
5278
|
+
});
|
|
5279
|
+
|
|
5280
|
+
// ../../node_modules/.bun/@fal-ai+client@1.8.1/node_modules/@fal-ai/client/src/index.js
|
|
5281
|
+
var require_src2 = __commonJS((exports) => {
|
|
5282
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
5283
|
+
if (k2 === undefined)
|
|
5284
|
+
k2 = k;
|
|
5285
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5286
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5287
|
+
desc = { enumerable: true, get: function() {
|
|
5288
|
+
return m[k];
|
|
5289
|
+
} };
|
|
5290
|
+
}
|
|
5291
|
+
Object.defineProperty(o, k2, desc);
|
|
5292
|
+
} : function(o, m, k, k2) {
|
|
5293
|
+
if (k2 === undefined)
|
|
5294
|
+
k2 = k;
|
|
5295
|
+
o[k2] = m[k];
|
|
5296
|
+
});
|
|
5297
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
5298
|
+
for (var p in m)
|
|
5299
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
5300
|
+
__createBinding(exports2, m, p);
|
|
5301
|
+
};
|
|
5302
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5303
|
+
exports.fal = exports.parseEndpointId = exports.isRetryableError = exports.ValidationError = exports.ApiError = exports.withProxy = exports.withMiddleware = exports.createFalClient = undefined;
|
|
5304
|
+
var client_1 = require_client();
|
|
5305
|
+
var client_2 = require_client();
|
|
5306
|
+
Object.defineProperty(exports, "createFalClient", { enumerable: true, get: function() {
|
|
5307
|
+
return client_2.createFalClient;
|
|
5308
|
+
} });
|
|
5309
|
+
var middleware_1 = require_middleware();
|
|
5310
|
+
Object.defineProperty(exports, "withMiddleware", { enumerable: true, get: function() {
|
|
5311
|
+
return middleware_1.withMiddleware;
|
|
5312
|
+
} });
|
|
5313
|
+
Object.defineProperty(exports, "withProxy", { enumerable: true, get: function() {
|
|
5314
|
+
return middleware_1.withProxy;
|
|
5315
|
+
} });
|
|
5316
|
+
var response_1 = require_response();
|
|
5317
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function() {
|
|
5318
|
+
return response_1.ApiError;
|
|
5319
|
+
} });
|
|
5320
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
5321
|
+
return response_1.ValidationError;
|
|
5322
|
+
} });
|
|
5323
|
+
var retry_1 = require_retry();
|
|
5324
|
+
Object.defineProperty(exports, "isRetryableError", { enumerable: true, get: function() {
|
|
5325
|
+
return retry_1.isRetryableError;
|
|
5326
|
+
} });
|
|
5327
|
+
__exportStar(require_common(), exports);
|
|
5328
|
+
var utils_1 = require_utils3();
|
|
5329
|
+
Object.defineProperty(exports, "parseEndpointId", { enumerable: true, get: function() {
|
|
5330
|
+
return utils_1.parseEndpointId;
|
|
5331
|
+
} });
|
|
5332
|
+
exports.fal = function createSingletonFalClient() {
|
|
5333
|
+
let currentInstance = (0, client_1.createFalClient)();
|
|
5334
|
+
return {
|
|
5335
|
+
config(config) {
|
|
5336
|
+
currentInstance = (0, client_1.createFalClient)(config);
|
|
5337
|
+
},
|
|
5338
|
+
get queue() {
|
|
5339
|
+
return currentInstance.queue;
|
|
5340
|
+
},
|
|
5341
|
+
get realtime() {
|
|
5342
|
+
return currentInstance.realtime;
|
|
5343
|
+
},
|
|
5344
|
+
get storage() {
|
|
5345
|
+
return currentInstance.storage;
|
|
5346
|
+
},
|
|
5347
|
+
get streaming() {
|
|
5348
|
+
return currentInstance.streaming;
|
|
5349
|
+
},
|
|
5350
|
+
run(id, options) {
|
|
5351
|
+
return currentInstance.run(id, options);
|
|
5352
|
+
},
|
|
5353
|
+
subscribe(endpointId, options) {
|
|
5354
|
+
return currentInstance.subscribe(endpointId, options);
|
|
5355
|
+
},
|
|
5356
|
+
stream(endpointId, options) {
|
|
5357
|
+
return currentInstance.stream(endpointId, options);
|
|
5358
|
+
}
|
|
5359
|
+
};
|
|
5360
|
+
}();
|
|
5361
|
+
});
|
|
5362
|
+
|
|
1616
5363
|
// src/plugin.ts
|
|
1617
5364
|
import { ModelType, logger } from "@elizaos/core";
|
|
1618
5365
|
|
|
@@ -1624,11 +5371,15 @@ var aiGatewayConfigSchema = z.object({
|
|
|
1624
5371
|
AI_GATEWAY_TEXT_SMALL_MODEL: z.string().default("anthropic/claude-haiku-4.5"),
|
|
1625
5372
|
AI_GATEWAY_TEXT_LARGE_MODEL: z.string().default("anthropic/claude-opus-4.5"),
|
|
1626
5373
|
AI_GATEWAY_EMBEDDING_MODEL: z.string().default("openai/text-embedding-3-large"),
|
|
1627
|
-
AI_GATEWAY_IMAGE_MODEL: z.string().default("
|
|
5374
|
+
AI_GATEWAY_IMAGE_MODEL: z.string().default("google/imagen-4.0-generate"),
|
|
1628
5375
|
AI_GATEWAY_VISION_MODEL: z.string().default("xai/grok-2-vision"),
|
|
1629
5376
|
AI_GATEWAY_TRANSCRIPTION_MODEL: z.string().default("openai/whisper-1"),
|
|
1630
5377
|
AI_GATEWAY_TTS_MODEL: z.string().default("openai/tts-1-hd"),
|
|
1631
|
-
AI_GATEWAY_TTS_VOICE: z.enum(["alloy", "echo", "fable", "onyx", "nova", "shimmer"]).default("alloy")
|
|
5378
|
+
AI_GATEWAY_TTS_VOICE: z.enum(["alloy", "echo", "fable", "onyx", "nova", "shimmer"]).default("alloy"),
|
|
5379
|
+
FAL_API_KEY: z.string().optional(),
|
|
5380
|
+
FAL_IMAGE_MODEL: z.string().default("fal-ai/flux/dev"),
|
|
5381
|
+
FAL_VIDEO_MODEL: z.string().default("fal-ai/minimax-video/image-to-video"),
|
|
5382
|
+
FAL_PREFER_FOR_IMAGES: z.boolean().default(false)
|
|
1632
5383
|
});
|
|
1633
5384
|
function parseConfig(env) {
|
|
1634
5385
|
return aiGatewayConfigSchema.parse({
|
|
@@ -1641,13 +5392,414 @@ function parseConfig(env) {
|
|
|
1641
5392
|
AI_GATEWAY_VISION_MODEL: env.AI_GATEWAY_VISION_MODEL,
|
|
1642
5393
|
AI_GATEWAY_TRANSCRIPTION_MODEL: env.AI_GATEWAY_TRANSCRIPTION_MODEL,
|
|
1643
5394
|
AI_GATEWAY_TTS_MODEL: env.AI_GATEWAY_TTS_MODEL,
|
|
1644
|
-
AI_GATEWAY_TTS_VOICE: env.AI_GATEWAY_TTS_VOICE
|
|
5395
|
+
AI_GATEWAY_TTS_VOICE: env.AI_GATEWAY_TTS_VOICE,
|
|
5396
|
+
FAL_API_KEY: env.FAL_API_KEY,
|
|
5397
|
+
FAL_IMAGE_MODEL: env.FAL_IMAGE_MODEL,
|
|
5398
|
+
FAL_VIDEO_MODEL: env.FAL_VIDEO_MODEL,
|
|
5399
|
+
FAL_PREFER_FOR_IMAGES: env.FAL_PREFER_FOR_IMAGES === "true"
|
|
1645
5400
|
});
|
|
1646
5401
|
}
|
|
1647
5402
|
function getConfigWithDefaults(partial) {
|
|
1648
5403
|
return aiGatewayConfigSchema.parse(partial);
|
|
1649
5404
|
}
|
|
1650
5405
|
|
|
5406
|
+
// src/handlers/fal-models.ts
|
|
5407
|
+
var FAL_API_BASE = "https://fal.ai/api";
|
|
5408
|
+
async function fetchFalModels(apiKey, filters = {}) {
|
|
5409
|
+
const params = new URLSearchParams;
|
|
5410
|
+
if (filters.query) {
|
|
5411
|
+
params.set("q", filters.query);
|
|
5412
|
+
}
|
|
5413
|
+
if (filters.category) {
|
|
5414
|
+
params.set("category", filters.category);
|
|
5415
|
+
}
|
|
5416
|
+
if (filters.status === "active") {
|
|
5417
|
+
params.set("deprecated", "false");
|
|
5418
|
+
} else if (filters.status === "deprecated") {
|
|
5419
|
+
params.set("deprecated", "true");
|
|
5420
|
+
}
|
|
5421
|
+
if (filters.limit) {
|
|
5422
|
+
params.set("limit", filters.limit.toString());
|
|
5423
|
+
}
|
|
5424
|
+
if (filters.cursor) {
|
|
5425
|
+
params.set("cursor", filters.cursor);
|
|
5426
|
+
}
|
|
5427
|
+
const url = `${FAL_API_BASE}/models${params.toString() ? `?${params.toString()}` : ""}`;
|
|
5428
|
+
const headers = {
|
|
5429
|
+
"Content-Type": "application/json"
|
|
5430
|
+
};
|
|
5431
|
+
if (apiKey) {
|
|
5432
|
+
headers["Authorization"] = `Key ${apiKey}`;
|
|
5433
|
+
}
|
|
5434
|
+
const response = await fetch(url, { headers });
|
|
5435
|
+
if (!response.ok) {
|
|
5436
|
+
const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));
|
|
5437
|
+
throw new Error(`FAL API error: ${errorData.error?.message || response.statusText}`);
|
|
5438
|
+
}
|
|
5439
|
+
let data;
|
|
5440
|
+
try {
|
|
5441
|
+
data = await response.json();
|
|
5442
|
+
} catch {
|
|
5443
|
+
throw new Error("Failed to parse FAL API response");
|
|
5444
|
+
}
|
|
5445
|
+
if (filters.sort && data.items.length > 0) {
|
|
5446
|
+
data.items = sortModels(data.items, filters.sort);
|
|
5447
|
+
}
|
|
5448
|
+
return data;
|
|
5449
|
+
}
|
|
5450
|
+
function sortModels(models, sort) {
|
|
5451
|
+
return [...models].sort((a, b) => {
|
|
5452
|
+
switch (sort) {
|
|
5453
|
+
case "newest":
|
|
5454
|
+
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
|
5455
|
+
case "oldest":
|
|
5456
|
+
return new Date(a.date).getTime() - new Date(b.date).getTime();
|
|
5457
|
+
case "highlighted":
|
|
5458
|
+
if (b.highlighted !== a.highlighted) {
|
|
5459
|
+
return b.highlighted ? 1 : -1;
|
|
5460
|
+
}
|
|
5461
|
+
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
|
5462
|
+
case "name":
|
|
5463
|
+
return a.title.localeCompare(b.title);
|
|
5464
|
+
default:
|
|
5465
|
+
return 0;
|
|
5466
|
+
}
|
|
5467
|
+
});
|
|
5468
|
+
}
|
|
5469
|
+
async function fetchAllFalModels(apiKey, filters = {}, maxPages = 10) {
|
|
5470
|
+
const allModels = [];
|
|
5471
|
+
let cursor;
|
|
5472
|
+
let pages = 0;
|
|
5473
|
+
do {
|
|
5474
|
+
const response = await fetchFalModels(apiKey, { ...filters, cursor });
|
|
5475
|
+
allModels.push(...response.items);
|
|
5476
|
+
cursor = response.nextCursor;
|
|
5477
|
+
pages++;
|
|
5478
|
+
} while (cursor && pages < maxPages);
|
|
5479
|
+
if (filters.sort) {
|
|
5480
|
+
return sortModels(allModels, filters.sort);
|
|
5481
|
+
}
|
|
5482
|
+
return allModels;
|
|
5483
|
+
}
|
|
5484
|
+
async function getImageModels(apiKey, options = {}) {
|
|
5485
|
+
const response = await fetchFalModels(apiKey, {
|
|
5486
|
+
status: "active",
|
|
5487
|
+
sort: options.sort || "newest",
|
|
5488
|
+
limit: 100
|
|
5489
|
+
});
|
|
5490
|
+
const imageModels = response.items.filter((m) => m.category === "text-to-image");
|
|
5491
|
+
return imageModels.slice(0, options.limit || 50);
|
|
5492
|
+
}
|
|
5493
|
+
async function getVideoModels(apiKey, options = {}) {
|
|
5494
|
+
const response = await fetchFalModels(apiKey, {
|
|
5495
|
+
status: "active",
|
|
5496
|
+
sort: options.sort || "newest",
|
|
5497
|
+
limit: 100
|
|
5498
|
+
});
|
|
5499
|
+
const videoModels = response.items.filter((m) => m.category === "text-to-video" || m.category === "image-to-video");
|
|
5500
|
+
return videoModels.slice(0, options.limit || 50);
|
|
5501
|
+
}
|
|
5502
|
+
async function get3DModels(apiKey, options = {}) {
|
|
5503
|
+
const response = await fetchFalModels(apiKey, {
|
|
5504
|
+
status: "active",
|
|
5505
|
+
sort: options.sort || "newest",
|
|
5506
|
+
limit: 100
|
|
5507
|
+
});
|
|
5508
|
+
const models3d = response.items.filter((m) => m.category === "image-to-3d" || m.category === "text-to-3d");
|
|
5509
|
+
return models3d.slice(0, options.limit || 50);
|
|
5510
|
+
}
|
|
5511
|
+
async function searchModels(apiKey, query, options = {}) {
|
|
5512
|
+
const response = await fetchFalModels(apiKey, {
|
|
5513
|
+
query,
|
|
5514
|
+
category: options.category,
|
|
5515
|
+
status: "active",
|
|
5516
|
+
sort: options.sort || "highlighted",
|
|
5517
|
+
limit: options.limit || 50
|
|
5518
|
+
});
|
|
5519
|
+
return response.items;
|
|
5520
|
+
}
|
|
5521
|
+
async function getModel(apiKey, modelId) {
|
|
5522
|
+
const url = `${FAL_API_BASE}/models?q=${encodeURIComponent(modelId)}&limit=1`;
|
|
5523
|
+
const headers = {
|
|
5524
|
+
"Content-Type": "application/json"
|
|
5525
|
+
};
|
|
5526
|
+
if (apiKey) {
|
|
5527
|
+
headers["Authorization"] = `Key ${apiKey}`;
|
|
5528
|
+
}
|
|
5529
|
+
const response = await fetch(url, { headers });
|
|
5530
|
+
if (!response.ok) {
|
|
5531
|
+
if (response.status === 404) {
|
|
5532
|
+
return null;
|
|
5533
|
+
}
|
|
5534
|
+
const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));
|
|
5535
|
+
throw new Error(`FAL API error: ${errorData.error?.message || response.statusText}`);
|
|
5536
|
+
}
|
|
5537
|
+
const data = await response.json();
|
|
5538
|
+
return data.items.find((m) => m.id === modelId) || data.items[0] || null;
|
|
5539
|
+
}
|
|
5540
|
+
function formatModelDisplay(m) {
|
|
5541
|
+
const tags = m.tags.length > 0 ? ` [${m.tags.join(", ")}]` : "";
|
|
5542
|
+
return `${m.title} (${m.id})${tags}`;
|
|
5543
|
+
}
|
|
5544
|
+
function createFalModelsProvider(config) {
|
|
5545
|
+
return {
|
|
5546
|
+
name: "FAL_MODELS",
|
|
5547
|
+
description: "Provides information about available FAL.ai models for image, video, and 3D generation",
|
|
5548
|
+
position: 50,
|
|
5549
|
+
get: async () => {
|
|
5550
|
+
if (!config.FAL_API_KEY) {
|
|
5551
|
+
return {
|
|
5552
|
+
text: "FAL models: Not configured (FAL_API_KEY not set)",
|
|
5553
|
+
data: { configured: false }
|
|
5554
|
+
};
|
|
5555
|
+
}
|
|
5556
|
+
try {
|
|
5557
|
+
const [imageModels, videoModels] = await Promise.all([
|
|
5558
|
+
getImageModels(config.FAL_API_KEY, { sort: "highlighted", limit: 5 }),
|
|
5559
|
+
getVideoModels(config.FAL_API_KEY, { sort: "highlighted", limit: 5 })
|
|
5560
|
+
]);
|
|
5561
|
+
const text = `FAL.ai Models Available:
|
|
5562
|
+
|
|
5563
|
+
**Image Generation (text-to-image):**
|
|
5564
|
+
${imageModels.map((m) => `- ${formatModelDisplay(m)}`).join(`
|
|
5565
|
+
`)}
|
|
5566
|
+
|
|
5567
|
+
**Video Generation:**
|
|
5568
|
+
${videoModels.map((m) => `- ${formatModelDisplay(m)}`).join(`
|
|
5569
|
+
`)}
|
|
5570
|
+
|
|
5571
|
+
Current defaults:
|
|
5572
|
+
- Image: ${config.FAL_IMAGE_MODEL}
|
|
5573
|
+
- Video: ${config.FAL_VIDEO_MODEL}`;
|
|
5574
|
+
return {
|
|
5575
|
+
text,
|
|
5576
|
+
data: {
|
|
5577
|
+
configured: true,
|
|
5578
|
+
imageModels: imageModels.map((m) => ({
|
|
5579
|
+
id: m.id,
|
|
5580
|
+
name: m.title,
|
|
5581
|
+
tags: m.tags
|
|
5582
|
+
})),
|
|
5583
|
+
videoModels: videoModels.map((m) => ({
|
|
5584
|
+
id: m.id,
|
|
5585
|
+
name: m.title,
|
|
5586
|
+
tags: m.tags
|
|
5587
|
+
})),
|
|
5588
|
+
currentDefaults: {
|
|
5589
|
+
image: config.FAL_IMAGE_MODEL,
|
|
5590
|
+
video: config.FAL_VIDEO_MODEL
|
|
5591
|
+
}
|
|
5592
|
+
}
|
|
5593
|
+
};
|
|
5594
|
+
} catch (err) {
|
|
5595
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
5596
|
+
return {
|
|
5597
|
+
text: `FAL models: Error fetching models - ${message}`,
|
|
5598
|
+
data: { configured: true, error: message }
|
|
5599
|
+
};
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
};
|
|
5603
|
+
}
|
|
5604
|
+
|
|
5605
|
+
// src/actions/list-fal-models.ts
|
|
5606
|
+
function formatModel(model) {
|
|
5607
|
+
const tags = model.tags.length > 0 ? ` [${model.tags.join(", ")}]` : "";
|
|
5608
|
+
const status = model.deprecated ? " (DEPRECATED)" : "";
|
|
5609
|
+
const updated = model.date ? ` - Added: ${new Date(model.date).toLocaleDateString()}` : "";
|
|
5610
|
+
return `- **${model.title}** (${model.id})${tags}${status}${updated}
|
|
5611
|
+
${model.shortDescription || ""}`;
|
|
5612
|
+
}
|
|
5613
|
+
var listFalModelsAction = {
|
|
5614
|
+
name: "LIST_FAL_MODELS",
|
|
5615
|
+
description: "Search and list available FAL.ai models for image, video, and 3D generation. Use this to discover the newest and best models.",
|
|
5616
|
+
similes: [
|
|
5617
|
+
"list fal models",
|
|
5618
|
+
"show fal models",
|
|
5619
|
+
"search fal models",
|
|
5620
|
+
"get fal models",
|
|
5621
|
+
"find fal models",
|
|
5622
|
+
"what models are available",
|
|
5623
|
+
"newest models",
|
|
5624
|
+
"latest models",
|
|
5625
|
+
"best image models",
|
|
5626
|
+
"best video models"
|
|
5627
|
+
],
|
|
5628
|
+
examples: [
|
|
5629
|
+
[
|
|
5630
|
+
{
|
|
5631
|
+
name: "user",
|
|
5632
|
+
content: { text: "What are the newest image generation models on FAL?" }
|
|
5633
|
+
},
|
|
5634
|
+
{
|
|
5635
|
+
name: "assistant",
|
|
5636
|
+
content: { text: "Let me search for the newest FAL image models...", action: "LIST_FAL_MODELS" }
|
|
5637
|
+
}
|
|
5638
|
+
],
|
|
5639
|
+
[
|
|
5640
|
+
{
|
|
5641
|
+
name: "user",
|
|
5642
|
+
content: { text: "Show me video generation models" }
|
|
5643
|
+
},
|
|
5644
|
+
{
|
|
5645
|
+
name: "assistant",
|
|
5646
|
+
content: { text: "I'll list the available video generation models on FAL...", action: "LIST_FAL_MODELS" }
|
|
5647
|
+
}
|
|
5648
|
+
],
|
|
5649
|
+
[
|
|
5650
|
+
{
|
|
5651
|
+
name: "user",
|
|
5652
|
+
content: { text: "Search for FLUX models" }
|
|
5653
|
+
},
|
|
5654
|
+
{
|
|
5655
|
+
name: "assistant",
|
|
5656
|
+
content: { text: "Searching FAL for FLUX models...", action: "LIST_FAL_MODELS" }
|
|
5657
|
+
}
|
|
5658
|
+
]
|
|
5659
|
+
],
|
|
5660
|
+
validate: async (_runtime, message, _state) => {
|
|
5661
|
+
const text = message.content?.text?.toLowerCase() || "";
|
|
5662
|
+
const keywords = [
|
|
5663
|
+
"fal model",
|
|
5664
|
+
"models available",
|
|
5665
|
+
"list model",
|
|
5666
|
+
"show model",
|
|
5667
|
+
"search model",
|
|
5668
|
+
"find model",
|
|
5669
|
+
"what model",
|
|
5670
|
+
"which model",
|
|
5671
|
+
"image model",
|
|
5672
|
+
"video model",
|
|
5673
|
+
"3d model",
|
|
5674
|
+
"newest model",
|
|
5675
|
+
"latest model",
|
|
5676
|
+
"best model",
|
|
5677
|
+
"flux",
|
|
5678
|
+
"minimax",
|
|
5679
|
+
"luma",
|
|
5680
|
+
"stable diffusion"
|
|
5681
|
+
];
|
|
5682
|
+
return keywords.some((keyword) => text.includes(keyword));
|
|
5683
|
+
},
|
|
5684
|
+
handler: async (runtime, message, _state, _options, callback) => {
|
|
5685
|
+
const text = message.content?.text?.toLowerCase() || "";
|
|
5686
|
+
const settingValue = runtime.getSetting("FAL_API_KEY");
|
|
5687
|
+
const apiKey = typeof settingValue === "string" ? settingValue : process.env.FAL_API_KEY;
|
|
5688
|
+
if (!apiKey) {
|
|
5689
|
+
if (callback) {
|
|
5690
|
+
await callback({
|
|
5691
|
+
text: "FAL API key is not configured. Please set FAL_API_KEY to use model discovery.",
|
|
5692
|
+
action: "LIST_FAL_MODELS"
|
|
5693
|
+
});
|
|
5694
|
+
}
|
|
5695
|
+
return { success: false, data: { error: "FAL_API_KEY not configured" } };
|
|
5696
|
+
}
|
|
5697
|
+
try {
|
|
5698
|
+
let category = "all";
|
|
5699
|
+
if (text.includes("image") || text.includes("picture") || text.includes("photo")) {
|
|
5700
|
+
category = "image";
|
|
5701
|
+
} else if (text.includes("video") || text.includes("animation")) {
|
|
5702
|
+
category = "video";
|
|
5703
|
+
} else if (text.includes("3d") || text.includes("three-d") || text.includes("mesh")) {
|
|
5704
|
+
category = "3d";
|
|
5705
|
+
}
|
|
5706
|
+
let sort = "highlighted";
|
|
5707
|
+
if (text.includes("newest") || text.includes("latest") || text.includes("recent")) {
|
|
5708
|
+
sort = "newest";
|
|
5709
|
+
} else if (text.includes("oldest")) {
|
|
5710
|
+
sort = "oldest";
|
|
5711
|
+
} else if (text.includes("name") || text.includes("alphabetical")) {
|
|
5712
|
+
sort = "name";
|
|
5713
|
+
}
|
|
5714
|
+
const searchMatch = text.match(/search(?:\s+for)?\s+["']?([^"']+)["']?/i);
|
|
5715
|
+
const queryMatch = text.match(/(?:find|show|list)\s+(?:me\s+)?["']?([a-zA-Z0-9\s]+)["']?\s+models?/i);
|
|
5716
|
+
const searchQuery = searchMatch?.[1] || queryMatch?.[1];
|
|
5717
|
+
let models = [];
|
|
5718
|
+
let categoryLabel = "";
|
|
5719
|
+
if (searchQuery) {
|
|
5720
|
+
models = await searchModels(apiKey, searchQuery.trim(), { sort, limit: 20 });
|
|
5721
|
+
categoryLabel = `Search results for "${searchQuery.trim()}"`;
|
|
5722
|
+
} else if (category === "image") {
|
|
5723
|
+
models = await getImageModels(apiKey, { sort, limit: 15 });
|
|
5724
|
+
categoryLabel = "Image Generation Models (text-to-image)";
|
|
5725
|
+
} else if (category === "video") {
|
|
5726
|
+
models = await getVideoModels(apiKey, { sort, limit: 15 });
|
|
5727
|
+
categoryLabel = "Video Generation Models";
|
|
5728
|
+
} else if (category === "3d") {
|
|
5729
|
+
models = await get3DModels(apiKey, { sort, limit: 15 });
|
|
5730
|
+
categoryLabel = "3D Generation Models (image-to-3d)";
|
|
5731
|
+
} else {
|
|
5732
|
+
const [imageModels, videoModels] = await Promise.all([
|
|
5733
|
+
getImageModels(apiKey, { sort, limit: 8 }),
|
|
5734
|
+
getVideoModels(apiKey, { sort, limit: 8 })
|
|
5735
|
+
]);
|
|
5736
|
+
const responseText2 = `**FAL.ai Available Models** (sorted by ${sort})
|
|
5737
|
+
|
|
5738
|
+
## Image Generation (text-to-image)
|
|
5739
|
+
${imageModels.map(formatModel).join(`
|
|
5740
|
+
`)}
|
|
5741
|
+
|
|
5742
|
+
## Video Generation
|
|
5743
|
+
${videoModels.map(formatModel).join(`
|
|
5744
|
+
`)}
|
|
5745
|
+
|
|
5746
|
+
Use more specific queries like "show newest image models" or "search for FLUX models" for targeted results.`;
|
|
5747
|
+
if (callback) {
|
|
5748
|
+
await callback({
|
|
5749
|
+
text: responseText2,
|
|
5750
|
+
action: "LIST_FAL_MODELS"
|
|
5751
|
+
});
|
|
5752
|
+
}
|
|
5753
|
+
return {
|
|
5754
|
+
success: true,
|
|
5755
|
+
data: {
|
|
5756
|
+
imageModels: imageModels.map((m) => m.id),
|
|
5757
|
+
videoModels: videoModels.map((m) => m.id),
|
|
5758
|
+
sort
|
|
5759
|
+
}
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
const responseText = `**${categoryLabel}** (sorted by ${sort})
|
|
5763
|
+
|
|
5764
|
+
${models.length > 0 ? models.map(formatModel).join(`
|
|
5765
|
+
|
|
5766
|
+
`) : "No models found matching your criteria."}
|
|
5767
|
+
|
|
5768
|
+
Total: ${models.length} model${models.length !== 1 ? "s" : ""}`;
|
|
5769
|
+
if (callback) {
|
|
5770
|
+
await callback({
|
|
5771
|
+
text: responseText,
|
|
5772
|
+
action: "LIST_FAL_MODELS"
|
|
5773
|
+
});
|
|
5774
|
+
}
|
|
5775
|
+
return {
|
|
5776
|
+
success: true,
|
|
5777
|
+
data: {
|
|
5778
|
+
category,
|
|
5779
|
+
sort,
|
|
5780
|
+
searchQuery,
|
|
5781
|
+
models: models.map((m) => ({
|
|
5782
|
+
id: m.id,
|
|
5783
|
+
name: m.title,
|
|
5784
|
+
category: m.category,
|
|
5785
|
+
tags: m.tags,
|
|
5786
|
+
date: m.date
|
|
5787
|
+
})),
|
|
5788
|
+
count: models.length
|
|
5789
|
+
}
|
|
5790
|
+
};
|
|
5791
|
+
} catch (err) {
|
|
5792
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
5793
|
+
if (callback) {
|
|
5794
|
+
await callback({
|
|
5795
|
+
text: `Failed to fetch FAL models: ${errorMessage}`,
|
|
5796
|
+
action: "LIST_FAL_MODELS"
|
|
5797
|
+
});
|
|
5798
|
+
}
|
|
5799
|
+
return { success: false, data: { error: errorMessage } };
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5802
|
+
};
|
|
1651
5803
|
// ../../node_modules/.bun/@ai-sdk+provider@1.1.3/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
1652
5804
|
var marker = "vercel.ai.error";
|
|
1653
5805
|
var symbol = Symbol.for(marker);
|
|
@@ -10703,11 +14855,13 @@ function createTextEmbeddingHandler(config) {
|
|
|
10703
14855
|
if (!text2 || text2.trim().length === 0) {
|
|
10704
14856
|
return new Array(3072).fill(0);
|
|
10705
14857
|
}
|
|
14858
|
+
console.log(`[AI Gateway] Generating embedding for text (${text2.length} chars)`);
|
|
10706
14859
|
const model = getEmbeddingModel(config, config.AI_GATEWAY_EMBEDDING_MODEL);
|
|
10707
14860
|
const result = await embed({
|
|
10708
14861
|
model,
|
|
10709
14862
|
value: text2
|
|
10710
14863
|
});
|
|
14864
|
+
console.log(`[AI Gateway] Embedding generated (${result.embedding.length} dimensions)`);
|
|
10711
14865
|
return result.embedding;
|
|
10712
14866
|
};
|
|
10713
14867
|
}
|
|
@@ -11261,11 +15415,86 @@ function createTokenizerDecodeHandler() {
|
|
|
11261
15415
|
return tokenizer.decode(detokenParams.tokens);
|
|
11262
15416
|
};
|
|
11263
15417
|
}
|
|
15418
|
+
// src/handlers/fal.ts
|
|
15419
|
+
var import_client = __toESM(require_src2(), 1);
|
|
15420
|
+
function initFalClient(apiKey) {
|
|
15421
|
+
import_client.fal.config({
|
|
15422
|
+
credentials: apiKey
|
|
15423
|
+
});
|
|
15424
|
+
}
|
|
15425
|
+
function createFalImageHandler(config) {
|
|
15426
|
+
return async (_runtime, params) => {
|
|
15427
|
+
if (!config.FAL_API_KEY) {
|
|
15428
|
+
throw new Error("FAL_API_KEY is required for FAL image generation");
|
|
15429
|
+
}
|
|
15430
|
+
initFalClient(config.FAL_API_KEY);
|
|
15431
|
+
const imageParams = params;
|
|
15432
|
+
let width = 1024;
|
|
15433
|
+
let height = 1024;
|
|
15434
|
+
if (imageParams.size) {
|
|
15435
|
+
const [w, h] = imageParams.size.split("x").map(Number);
|
|
15436
|
+
if (w && h) {
|
|
15437
|
+
width = w;
|
|
15438
|
+
height = h;
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
const result = await import_client.fal.subscribe(config.FAL_IMAGE_MODEL, {
|
|
15442
|
+
input: {
|
|
15443
|
+
prompt: imageParams.prompt,
|
|
15444
|
+
image_size: {
|
|
15445
|
+
width,
|
|
15446
|
+
height
|
|
15447
|
+
},
|
|
15448
|
+
num_images: imageParams.count || 1
|
|
15449
|
+
}
|
|
15450
|
+
});
|
|
15451
|
+
const images = result.data?.images || [result.data];
|
|
15452
|
+
return images.map((img) => ({ url: img.url }));
|
|
15453
|
+
};
|
|
15454
|
+
}
|
|
15455
|
+
function createFalVideoHandler(config) {
|
|
15456
|
+
return async (_runtime, params) => {
|
|
15457
|
+
if (!config.FAL_API_KEY) {
|
|
15458
|
+
throw new Error("FAL_API_KEY is required for FAL video generation");
|
|
15459
|
+
}
|
|
15460
|
+
initFalClient(config.FAL_API_KEY);
|
|
15461
|
+
const videoParams = params;
|
|
15462
|
+
const input = {
|
|
15463
|
+
prompt: videoParams.prompt
|
|
15464
|
+
};
|
|
15465
|
+
if (videoParams.image_url) {
|
|
15466
|
+
input.image_url = videoParams.image_url;
|
|
15467
|
+
}
|
|
15468
|
+
const result = await import_client.fal.subscribe(config.FAL_VIDEO_MODEL, {
|
|
15469
|
+
input
|
|
15470
|
+
});
|
|
15471
|
+
const data = result.data;
|
|
15472
|
+
const videoUrl = data.video?.url || data.url;
|
|
15473
|
+
if (!videoUrl) {
|
|
15474
|
+
throw new Error("No video URL returned from FAL");
|
|
15475
|
+
}
|
|
15476
|
+
return { url: videoUrl };
|
|
15477
|
+
};
|
|
15478
|
+
}
|
|
15479
|
+
var FAL_MODELS = {
|
|
15480
|
+
IMAGE: {
|
|
15481
|
+
FLUX_DEV: "fal-ai/flux/dev",
|
|
15482
|
+
FLUX_PRO: "fal-ai/flux-pro",
|
|
15483
|
+
FLUX_SCHNELL: "fal-ai/flux/schnell",
|
|
15484
|
+
RECRAFT_V3: "fal-ai/recraft-v3",
|
|
15485
|
+
SD_V35_LARGE: "fal-ai/stable-diffusion-v35-large"
|
|
15486
|
+
},
|
|
15487
|
+
VIDEO: {
|
|
15488
|
+
MINIMAX: "fal-ai/minimax-video/image-to-video",
|
|
15489
|
+
LUMA_DREAM_MACHINE: "fal-ai/luma-dream-machine/image-to-video",
|
|
15490
|
+
KLING_V1: "fal-ai/kling-video/v1/standard/image-to-video"
|
|
15491
|
+
}
|
|
15492
|
+
};
|
|
11264
15493
|
// src/plugin.ts
|
|
11265
15494
|
var PLUGIN_NAME = "@ghostspeak/plugin-gateway-ghost";
|
|
11266
15495
|
var PRIORITY = 10;
|
|
11267
15496
|
function createModelHandlers(config) {
|
|
11268
|
-
|
|
15497
|
+
const handlers = {
|
|
11269
15498
|
[ModelType.TEXT_SMALL]: {
|
|
11270
15499
|
handler: createTextSmallHandler(config),
|
|
11271
15500
|
provider: PLUGIN_NAME,
|
|
@@ -11307,7 +15536,7 @@ function createModelHandlers(config) {
|
|
|
11307
15536
|
priority: PRIORITY
|
|
11308
15537
|
},
|
|
11309
15538
|
[ModelType.IMAGE]: {
|
|
11310
|
-
handler: createImageHandler(config),
|
|
15539
|
+
handler: config.FAL_API_KEY && config.FAL_PREFER_FOR_IMAGES ? createFalImageHandler(config) : createImageHandler(config),
|
|
11311
15540
|
provider: PLUGIN_NAME,
|
|
11312
15541
|
priority: PRIORITY
|
|
11313
15542
|
},
|
|
@@ -11337,7 +15566,16 @@ function createModelHandlers(config) {
|
|
|
11337
15566
|
priority: PRIORITY
|
|
11338
15567
|
}
|
|
11339
15568
|
};
|
|
15569
|
+
if (config.FAL_API_KEY) {
|
|
15570
|
+
handlers[ModelType.VIDEO] = {
|
|
15571
|
+
handler: createFalVideoHandler(config),
|
|
15572
|
+
provider: PLUGIN_NAME,
|
|
15573
|
+
priority: PRIORITY
|
|
15574
|
+
};
|
|
15575
|
+
}
|
|
15576
|
+
return handlers;
|
|
11340
15577
|
}
|
|
15578
|
+
var pluginConfigCache = null;
|
|
11341
15579
|
var aiGatewayPlugin = {
|
|
11342
15580
|
name: PLUGIN_NAME,
|
|
11343
15581
|
description: "Unified Vercel AI Gateway - one API key for all models (Claude, FLUX, Grok Vision, Whisper, etc.)",
|
|
@@ -11353,8 +15591,13 @@ var aiGatewayPlugin = {
|
|
|
11353
15591
|
AI_GATEWAY_VISION_MODEL: pluginConfig.AI_GATEWAY_VISION_MODEL || process.env.AI_GATEWAY_VISION_MODEL,
|
|
11354
15592
|
AI_GATEWAY_TRANSCRIPTION_MODEL: pluginConfig.AI_GATEWAY_TRANSCRIPTION_MODEL || process.env.AI_GATEWAY_TRANSCRIPTION_MODEL,
|
|
11355
15593
|
AI_GATEWAY_TTS_MODEL: pluginConfig.AI_GATEWAY_TTS_MODEL || process.env.AI_GATEWAY_TTS_MODEL,
|
|
11356
|
-
AI_GATEWAY_TTS_VOICE: pluginConfig.AI_GATEWAY_TTS_VOICE || process.env.AI_GATEWAY_TTS_VOICE
|
|
15594
|
+
AI_GATEWAY_TTS_VOICE: pluginConfig.AI_GATEWAY_TTS_VOICE || process.env.AI_GATEWAY_TTS_VOICE,
|
|
15595
|
+
FAL_API_KEY: pluginConfig.FAL_API_KEY || process.env.FAL_API_KEY,
|
|
15596
|
+
FAL_IMAGE_MODEL: pluginConfig.FAL_IMAGE_MODEL || process.env.FAL_IMAGE_MODEL,
|
|
15597
|
+
FAL_VIDEO_MODEL: pluginConfig.FAL_VIDEO_MODEL || process.env.FAL_VIDEO_MODEL,
|
|
15598
|
+
FAL_PREFER_FOR_IMAGES: pluginConfig.FAL_PREFER_FOR_IMAGES || process.env.FAL_PREFER_FOR_IMAGES
|
|
11357
15599
|
});
|
|
15600
|
+
pluginConfigCache = config;
|
|
11358
15601
|
const handlers = createModelHandlers(config);
|
|
11359
15602
|
for (const [modelType, registration] of Object.entries(handlers)) {
|
|
11360
15603
|
runtime.registerModel(modelType, registration.handler, registration.provider, registration.priority);
|
|
@@ -11364,14 +15607,34 @@ var aiGatewayPlugin = {
|
|
|
11364
15607
|
models: Object.keys(handlers).length,
|
|
11365
15608
|
textSmall: config.AI_GATEWAY_TEXT_SMALL_MODEL,
|
|
11366
15609
|
textLarge: config.AI_GATEWAY_TEXT_LARGE_MODEL,
|
|
11367
|
-
image: config.AI_GATEWAY_IMAGE_MODEL,
|
|
11368
|
-
|
|
15610
|
+
image: config.FAL_API_KEY && config.FAL_PREFER_FOR_IMAGES ? `FAL: ${config.FAL_IMAGE_MODEL}` : config.AI_GATEWAY_IMAGE_MODEL,
|
|
15611
|
+
video: config.FAL_API_KEY ? config.FAL_VIDEO_MODEL : "not configured",
|
|
15612
|
+
vision: config.AI_GATEWAY_VISION_MODEL,
|
|
15613
|
+
falEnabled: !!config.FAL_API_KEY
|
|
11369
15614
|
}, "AI Gateway plugin initialized");
|
|
11370
15615
|
} catch (error) {
|
|
11371
15616
|
logger.error({ error, plugin: PLUGIN_NAME }, "Failed to initialize AI Gateway plugin");
|
|
11372
15617
|
throw error;
|
|
11373
15618
|
}
|
|
11374
15619
|
},
|
|
15620
|
+
providers: [
|
|
15621
|
+
{
|
|
15622
|
+
name: "FAL_MODELS",
|
|
15623
|
+
description: "Provides information about available FAL.ai models for image, video, and 3D generation",
|
|
15624
|
+
position: 50,
|
|
15625
|
+
get: async () => {
|
|
15626
|
+
if (!pluginConfigCache?.FAL_API_KEY) {
|
|
15627
|
+
return {
|
|
15628
|
+
text: "FAL models: Not configured (FAL_API_KEY not set)",
|
|
15629
|
+
data: { configured: false }
|
|
15630
|
+
};
|
|
15631
|
+
}
|
|
15632
|
+
const provider = createFalModelsProvider(pluginConfigCache);
|
|
15633
|
+
return provider.get();
|
|
15634
|
+
}
|
|
15635
|
+
}
|
|
15636
|
+
],
|
|
15637
|
+
actions: [listFalModelsAction],
|
|
11375
15638
|
models: {}
|
|
11376
15639
|
};
|
|
11377
15640
|
var plugin_default = aiGatewayPlugin;
|
|
@@ -11401,12 +15664,20 @@ function isAuthError(error) {
|
|
|
11401
15664
|
return false;
|
|
11402
15665
|
}
|
|
11403
15666
|
export {
|
|
15667
|
+
searchModels,
|
|
11404
15668
|
parseConfig,
|
|
15669
|
+
listFalModelsAction,
|
|
11405
15670
|
isRateLimitError,
|
|
11406
15671
|
isAuthError,
|
|
15672
|
+
getVideoModels,
|
|
15673
|
+
getModel,
|
|
11407
15674
|
getLanguageModel,
|
|
15675
|
+
getImageModels,
|
|
11408
15676
|
getEmbeddingModel,
|
|
11409
15677
|
getConfigWithDefaults,
|
|
15678
|
+
get3DModels,
|
|
15679
|
+
fetchFalModels,
|
|
15680
|
+
fetchAllFalModels,
|
|
11410
15681
|
plugin_default as default,
|
|
11411
15682
|
createTranscriptionHandler,
|
|
11412
15683
|
createTokenizerEncodeHandler,
|
|
@@ -11423,11 +15694,15 @@ export {
|
|
|
11423
15694
|
createImageHandler,
|
|
11424
15695
|
createImageDescriptionHandler,
|
|
11425
15696
|
createGatewayClient,
|
|
15697
|
+
createFalVideoHandler,
|
|
15698
|
+
createFalModelsProvider,
|
|
15699
|
+
createFalImageHandler,
|
|
11426
15700
|
clearGatewayCache,
|
|
11427
15701
|
aiGatewayPlugin,
|
|
11428
15702
|
aiGatewayConfigSchema,
|
|
15703
|
+
FAL_MODELS,
|
|
11429
15704
|
AIGatewayError
|
|
11430
15705
|
};
|
|
11431
15706
|
|
|
11432
|
-
//# debugId=
|
|
15707
|
+
//# debugId=3480F6C08AEEFBD264756E2164756E21
|
|
11433
15708
|
//# sourceMappingURL=index.js.map
|