From bdd25f7a6b6fb5d2774f9c90f344547c856451bb Mon Sep 17 00:00:00 2001 From: Gnkalk Date: Fri, 21 Feb 2025 01:09:43 +0330 Subject: [PATCH] Add OpenAI chat integration and dependencies - Add OpenAI library and related dependencies to package files - Implement chat functionality with custom OpenAI API endpoint - Update app.ts and create new chat.ts module for AI chat interface - Modify results template to support AI chat container - Add new font dependencies for Inter and Vazirmatn - Update package-lock.json with new package versions --- ...off2 => Vazirmatn-UI-Black.eebe1f15.woff2} | Bin ...woff2 => Vazirmatn-UI-Bold.bb01a60b.woff2} | Bin ... => Vazirmatn-UI-ExtraBold.b1556a2a.woff2} | Bin ...=> Vazirmatn-UI-ExtraLight.165c33b1.woff2} | Bin ...off2 => Vazirmatn-UI-Light.feccc9d1.woff2} | Bin ...ff2 => Vazirmatn-UI-Medium.9f10f335.woff2} | Bin ...f2 => Vazirmatn-UI-Regular.65a0d014.woff2} | Bin ...2 => Vazirmatn-UI-SemiBold.f297b6f6.woff2} | Bin ...woff2 => Vazirmatn-UI-Thin.7fd7be2d.woff2} | Bin ...> inter-cyrillic-400-normal.36464be3.woff} | Bin ... inter-cyrillic-400-normal.4b5feba6.woff2} | Bin ...ter-cyrillic-ext-400-normal.2cb5dc0c.woff} | Bin ...er-cyrillic-ext-400-normal.5b5b757f.woff2} | Bin ...rillic-ext-standard-normal.ad8a30de.woff2} | Bin ...r-cyrillic-standard-normal.edf2e0c8.woff2} | Bin ... => inter-greek-400-normal.334c89a2.woff2} | Bin ...f => inter-greek-400-normal.8f0b5c8d.woff} | Bin ...inter-greek-ext-400-normal.5f623e11.woff2} | Bin ... inter-greek-ext-400-normal.8c538869.woff} | Bin ...-greek-ext-standard-normal.f6de5c8f.woff2} | Bin ...nter-greek-standard-normal.caf6d48e.woff2} | Bin ...f => inter-latin-400-normal.106646e8.woff} | Bin ... => inter-latin-400-normal.c257aa80.woff2} | Bin ... inter-latin-ext-400-normal.3f4f9cd0.woff} | Bin ...inter-latin-ext-400-normal.9e6288f4.woff2} | Bin ...-latin-ext-standard-normal.c3e326ee.woff2} | Bin ...nter-latin-standard-normal.9d95bac0.woff2} | Bin ...inter-vietnamese-400-normal.1c764e18.woff} | Bin ...nter-vietnamese-400-normal.cd378412.woff2} | Bin ...vietnamese-standard-normal.02f2e048.woff2} | Bin searx/static/themes/smart/css/ltr-style.css | 37 +- searx/static/themes/smart/css/rtl-style.css | 27 +- searx/static/themes/smart/js/app.js | 9023 ++++++++++++++++- searx/static/themes/smart/package-lock.json | 534 +- searx/static/themes/smart/package.json | 5 +- searx/static/themes/smart/src/scss/style.scss | 9 +- searx/static/themes/smart/src/ts/app.ts | 88 +- searx/static/themes/smart/src/ts/chat.ts | 103 + .../smart/result_templates/default.html | 7 +- searx/templates/smart/results.html | 10 +- 40 files changed, 9693 insertions(+), 150 deletions(-) rename searx/static/themes/smart/css/{Vazirmatn-UI-Black.bc8837bc.woff2 => Vazirmatn-UI-Black.eebe1f15.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-Bold.b0065d44.woff2 => Vazirmatn-UI-Bold.bb01a60b.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-ExtraBold.c431ea38.woff2 => Vazirmatn-UI-ExtraBold.b1556a2a.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-ExtraLight.cba2b231.woff2 => Vazirmatn-UI-ExtraLight.165c33b1.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-Light.c77d6de0.woff2 => Vazirmatn-UI-Light.feccc9d1.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-Medium.972fdd22.woff2 => Vazirmatn-UI-Medium.9f10f335.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-Regular.a3c99ff7.woff2 => Vazirmatn-UI-Regular.65a0d014.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-SemiBold.37d9c53d.woff2 => Vazirmatn-UI-SemiBold.f297b6f6.woff2} (100%) rename searx/static/themes/smart/css/{Vazirmatn-UI-Thin.37503ccd.woff2 => Vazirmatn-UI-Thin.7fd7be2d.woff2} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-400-normal.be966a56.woff => inter-cyrillic-400-normal.36464be3.woff} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-400-normal.cb9ef530.woff2 => inter-cyrillic-400-normal.4b5feba6.woff2} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-ext-400-normal.8938e3ac.woff => inter-cyrillic-ext-400-normal.2cb5dc0c.woff} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-ext-400-normal.a48d4e19.woff2 => inter-cyrillic-ext-400-normal.5b5b757f.woff2} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-ext-standard-normal.fc62596d.woff2 => inter-cyrillic-ext-standard-normal.ad8a30de.woff2} (100%) rename searx/static/themes/smart/css/{inter-cyrillic-standard-normal.ea7e923a.woff2 => inter-cyrillic-standard-normal.edf2e0c8.woff2} (100%) rename searx/static/themes/smart/css/{inter-greek-400-normal.4515f19a.woff2 => inter-greek-400-normal.334c89a2.woff2} (100%) rename searx/static/themes/smart/css/{inter-greek-400-normal.77684a9d.woff => inter-greek-400-normal.8f0b5c8d.woff} (100%) rename searx/static/themes/smart/css/{inter-greek-ext-400-normal.bfaa2c39.woff2 => inter-greek-ext-400-normal.5f623e11.woff2} (100%) rename searx/static/themes/smart/css/{inter-greek-ext-400-normal.50e73398.woff => inter-greek-ext-400-normal.8c538869.woff} (100%) rename searx/static/themes/smart/css/{inter-greek-ext-standard-normal.e10982a0.woff2 => inter-greek-ext-standard-normal.f6de5c8f.woff2} (100%) rename searx/static/themes/smart/css/{inter-greek-standard-normal.0caa17e7.woff2 => inter-greek-standard-normal.caf6d48e.woff2} (100%) rename searx/static/themes/smart/css/{inter-latin-400-normal.a22ac1fc.woff => inter-latin-400-normal.106646e8.woff} (100%) rename searx/static/themes/smart/css/{inter-latin-400-normal.fcefd771.woff2 => inter-latin-400-normal.c257aa80.woff2} (100%) rename searx/static/themes/smart/css/{inter-latin-ext-400-normal.fbc4849c.woff => inter-latin-ext-400-normal.3f4f9cd0.woff} (100%) rename searx/static/themes/smart/css/{inter-latin-ext-400-normal.a6024ce9.woff2 => inter-latin-ext-400-normal.9e6288f4.woff2} (100%) rename searx/static/themes/smart/css/{inter-latin-ext-standard-normal.a7641455.woff2 => inter-latin-ext-standard-normal.c3e326ee.woff2} (100%) rename searx/static/themes/smart/css/{inter-latin-standard-normal.2d8fdd01.woff2 => inter-latin-standard-normal.9d95bac0.woff2} (100%) rename searx/static/themes/smart/css/{inter-vietnamese-400-normal.6507846e.woff => inter-vietnamese-400-normal.1c764e18.woff} (100%) rename searx/static/themes/smart/css/{inter-vietnamese-400-normal.c9e40957.woff2 => inter-vietnamese-400-normal.cd378412.woff2} (100%) rename searx/static/themes/smart/css/{inter-vietnamese-standard-normal.2aec2804.woff2 => inter-vietnamese-standard-normal.02f2e048.woff2} (100%) create mode 100644 searx/static/themes/smart/src/ts/chat.ts diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Black.bc8837bc.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Black.eebe1f15.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Black.bc8837bc.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Black.eebe1f15.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Bold.b0065d44.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Bold.bb01a60b.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Bold.b0065d44.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Bold.bb01a60b.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-ExtraBold.c431ea38.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-ExtraBold.b1556a2a.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-ExtraBold.c431ea38.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-ExtraBold.b1556a2a.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-ExtraLight.cba2b231.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-ExtraLight.165c33b1.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-ExtraLight.cba2b231.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-ExtraLight.165c33b1.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Light.c77d6de0.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Light.feccc9d1.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Light.c77d6de0.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Light.feccc9d1.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Medium.972fdd22.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Medium.9f10f335.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Medium.972fdd22.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Medium.9f10f335.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Regular.a3c99ff7.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Regular.65a0d014.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Regular.a3c99ff7.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Regular.65a0d014.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-SemiBold.37d9c53d.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-SemiBold.f297b6f6.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-SemiBold.37d9c53d.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-SemiBold.f297b6f6.woff2 diff --git a/searx/static/themes/smart/css/Vazirmatn-UI-Thin.37503ccd.woff2 b/searx/static/themes/smart/css/Vazirmatn-UI-Thin.7fd7be2d.woff2 similarity index 100% rename from searx/static/themes/smart/css/Vazirmatn-UI-Thin.37503ccd.woff2 rename to searx/static/themes/smart/css/Vazirmatn-UI-Thin.7fd7be2d.woff2 diff --git a/searx/static/themes/smart/css/inter-cyrillic-400-normal.be966a56.woff b/searx/static/themes/smart/css/inter-cyrillic-400-normal.36464be3.woff similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-400-normal.be966a56.woff rename to searx/static/themes/smart/css/inter-cyrillic-400-normal.36464be3.woff diff --git a/searx/static/themes/smart/css/inter-cyrillic-400-normal.cb9ef530.woff2 b/searx/static/themes/smart/css/inter-cyrillic-400-normal.4b5feba6.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-400-normal.cb9ef530.woff2 rename to searx/static/themes/smart/css/inter-cyrillic-400-normal.4b5feba6.woff2 diff --git a/searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.8938e3ac.woff b/searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.2cb5dc0c.woff similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.8938e3ac.woff rename to searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.2cb5dc0c.woff diff --git a/searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.a48d4e19.woff2 b/searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.5b5b757f.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.a48d4e19.woff2 rename to searx/static/themes/smart/css/inter-cyrillic-ext-400-normal.5b5b757f.woff2 diff --git a/searx/static/themes/smart/css/inter-cyrillic-ext-standard-normal.fc62596d.woff2 b/searx/static/themes/smart/css/inter-cyrillic-ext-standard-normal.ad8a30de.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-ext-standard-normal.fc62596d.woff2 rename to searx/static/themes/smart/css/inter-cyrillic-ext-standard-normal.ad8a30de.woff2 diff --git a/searx/static/themes/smart/css/inter-cyrillic-standard-normal.ea7e923a.woff2 b/searx/static/themes/smart/css/inter-cyrillic-standard-normal.edf2e0c8.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-cyrillic-standard-normal.ea7e923a.woff2 rename to searx/static/themes/smart/css/inter-cyrillic-standard-normal.edf2e0c8.woff2 diff --git a/searx/static/themes/smart/css/inter-greek-400-normal.4515f19a.woff2 b/searx/static/themes/smart/css/inter-greek-400-normal.334c89a2.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-greek-400-normal.4515f19a.woff2 rename to searx/static/themes/smart/css/inter-greek-400-normal.334c89a2.woff2 diff --git a/searx/static/themes/smart/css/inter-greek-400-normal.77684a9d.woff b/searx/static/themes/smart/css/inter-greek-400-normal.8f0b5c8d.woff similarity index 100% rename from searx/static/themes/smart/css/inter-greek-400-normal.77684a9d.woff rename to searx/static/themes/smart/css/inter-greek-400-normal.8f0b5c8d.woff diff --git a/searx/static/themes/smart/css/inter-greek-ext-400-normal.bfaa2c39.woff2 b/searx/static/themes/smart/css/inter-greek-ext-400-normal.5f623e11.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-greek-ext-400-normal.bfaa2c39.woff2 rename to searx/static/themes/smart/css/inter-greek-ext-400-normal.5f623e11.woff2 diff --git a/searx/static/themes/smart/css/inter-greek-ext-400-normal.50e73398.woff b/searx/static/themes/smart/css/inter-greek-ext-400-normal.8c538869.woff similarity index 100% rename from searx/static/themes/smart/css/inter-greek-ext-400-normal.50e73398.woff rename to searx/static/themes/smart/css/inter-greek-ext-400-normal.8c538869.woff diff --git a/searx/static/themes/smart/css/inter-greek-ext-standard-normal.e10982a0.woff2 b/searx/static/themes/smart/css/inter-greek-ext-standard-normal.f6de5c8f.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-greek-ext-standard-normal.e10982a0.woff2 rename to searx/static/themes/smart/css/inter-greek-ext-standard-normal.f6de5c8f.woff2 diff --git a/searx/static/themes/smart/css/inter-greek-standard-normal.0caa17e7.woff2 b/searx/static/themes/smart/css/inter-greek-standard-normal.caf6d48e.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-greek-standard-normal.0caa17e7.woff2 rename to searx/static/themes/smart/css/inter-greek-standard-normal.caf6d48e.woff2 diff --git a/searx/static/themes/smart/css/inter-latin-400-normal.a22ac1fc.woff b/searx/static/themes/smart/css/inter-latin-400-normal.106646e8.woff similarity index 100% rename from searx/static/themes/smart/css/inter-latin-400-normal.a22ac1fc.woff rename to searx/static/themes/smart/css/inter-latin-400-normal.106646e8.woff diff --git a/searx/static/themes/smart/css/inter-latin-400-normal.fcefd771.woff2 b/searx/static/themes/smart/css/inter-latin-400-normal.c257aa80.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-latin-400-normal.fcefd771.woff2 rename to searx/static/themes/smart/css/inter-latin-400-normal.c257aa80.woff2 diff --git a/searx/static/themes/smart/css/inter-latin-ext-400-normal.fbc4849c.woff b/searx/static/themes/smart/css/inter-latin-ext-400-normal.3f4f9cd0.woff similarity index 100% rename from searx/static/themes/smart/css/inter-latin-ext-400-normal.fbc4849c.woff rename to searx/static/themes/smart/css/inter-latin-ext-400-normal.3f4f9cd0.woff diff --git a/searx/static/themes/smart/css/inter-latin-ext-400-normal.a6024ce9.woff2 b/searx/static/themes/smart/css/inter-latin-ext-400-normal.9e6288f4.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-latin-ext-400-normal.a6024ce9.woff2 rename to searx/static/themes/smart/css/inter-latin-ext-400-normal.9e6288f4.woff2 diff --git a/searx/static/themes/smart/css/inter-latin-ext-standard-normal.a7641455.woff2 b/searx/static/themes/smart/css/inter-latin-ext-standard-normal.c3e326ee.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-latin-ext-standard-normal.a7641455.woff2 rename to searx/static/themes/smart/css/inter-latin-ext-standard-normal.c3e326ee.woff2 diff --git a/searx/static/themes/smart/css/inter-latin-standard-normal.2d8fdd01.woff2 b/searx/static/themes/smart/css/inter-latin-standard-normal.9d95bac0.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-latin-standard-normal.2d8fdd01.woff2 rename to searx/static/themes/smart/css/inter-latin-standard-normal.9d95bac0.woff2 diff --git a/searx/static/themes/smart/css/inter-vietnamese-400-normal.6507846e.woff b/searx/static/themes/smart/css/inter-vietnamese-400-normal.1c764e18.woff similarity index 100% rename from searx/static/themes/smart/css/inter-vietnamese-400-normal.6507846e.woff rename to searx/static/themes/smart/css/inter-vietnamese-400-normal.1c764e18.woff diff --git a/searx/static/themes/smart/css/inter-vietnamese-400-normal.c9e40957.woff2 b/searx/static/themes/smart/css/inter-vietnamese-400-normal.cd378412.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-vietnamese-400-normal.c9e40957.woff2 rename to searx/static/themes/smart/css/inter-vietnamese-400-normal.cd378412.woff2 diff --git a/searx/static/themes/smart/css/inter-vietnamese-standard-normal.2aec2804.woff2 b/searx/static/themes/smart/css/inter-vietnamese-standard-normal.02f2e048.woff2 similarity index 100% rename from searx/static/themes/smart/css/inter-vietnamese-standard-normal.2aec2804.woff2 rename to searx/static/themes/smart/css/inter-vietnamese-standard-normal.02f2e048.woff2 diff --git a/searx/static/themes/smart/css/ltr-style.css b/searx/static/themes/smart/css/ltr-style.css index b2dfbb63a..f4263ec8c 100644 --- a/searx/static/themes/smart/css/ltr-style.css +++ b/searx/static/themes/smart/css/ltr-style.css @@ -3,7 +3,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-cyrillic-ext-standard-normal.fc62596d.woff2") format("woff2-variations"); + src: url("inter-cyrillic-ext-standard-normal.ad8a30de.woff2") format("woff2-variations"); unicode-range: U+460-52F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; } @@ -12,7 +12,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-cyrillic-standard-normal.ea7e923a.woff2") format("woff2-variations"); + src: url("inter-cyrillic-standard-normal.edf2e0c8.woff2") format("woff2-variations"); unicode-range: U+301, U+400-45F, U+490-491, U+4B0-4B1, U+2116; } @@ -21,7 +21,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-greek-ext-standard-normal.e10982a0.woff2") format("woff2-variations"); + src: url("inter-greek-ext-standard-normal.f6de5c8f.woff2") format("woff2-variations"); unicode-range: U+1F??; } @@ -30,7 +30,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-greek-standard-normal.0caa17e7.woff2") format("woff2-variations"); + src: url("inter-greek-standard-normal.caf6d48e.woff2") format("woff2-variations"); unicode-range: U+370-377, U+37A-37F, U+384-38A, U+38C, U+38E-3A1, U+3A3-3FF; } @@ -39,7 +39,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-vietnamese-standard-normal.2aec2804.woff2") format("woff2-variations"); + src: url("inter-vietnamese-standard-normal.02f2e048.woff2") format("woff2-variations"); unicode-range: U+102-103, U+110-111, U+128-129, U+168-169, U+1A0-1A1, U+1AF-1B0, U+300-301, U+303-304, U+308-309, U+323, U+329, U+1EA0-1EF9, U+20AB; } @@ -48,7 +48,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-latin-ext-standard-normal.a7641455.woff2") format("woff2-variations"); + src: url("inter-latin-ext-standard-normal.c3e326ee.woff2") format("woff2-variations"); unicode-range: U+100-2BA, U+2BD-2C5, U+2C7-2CC, U+2CE-2D7, U+2DD-2FF, U+304, U+308, U+329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; } @@ -57,7 +57,7 @@ font-style: normal; font-display: swap; font-weight: 100 900; - src: url("inter-latin-standard-normal.2d8fdd01.woff2") format("woff2-variations"); + src: url("inter-latin-standard-normal.9d95bac0.woff2") format("woff2-variations"); unicode-range: U+??, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+304, U+308, U+329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @@ -66,7 +66,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-cyrillic-ext-400-normal.a48d4e19.woff2") format("woff2"), url("inter-cyrillic-ext-400-normal.8938e3ac.woff") format("woff"); + src: url("inter-cyrillic-ext-400-normal.5b5b757f.woff2") format("woff2"), url("inter-cyrillic-ext-400-normal.2cb5dc0c.woff") format("woff"); unicode-range: U+460-52F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; } @@ -75,7 +75,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-cyrillic-400-normal.cb9ef530.woff2") format("woff2"), url("inter-cyrillic-400-normal.be966a56.woff") format("woff"); + src: url("inter-cyrillic-400-normal.4b5feba6.woff2") format("woff2"), url("inter-cyrillic-400-normal.36464be3.woff") format("woff"); unicode-range: U+301, U+400-45F, U+490-491, U+4B0-4B1, U+2116; } @@ -84,7 +84,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-greek-ext-400-normal.bfaa2c39.woff2") format("woff2"), url("inter-greek-ext-400-normal.50e73398.woff") format("woff"); + src: url("inter-greek-ext-400-normal.5f623e11.woff2") format("woff2"), url("inter-greek-ext-400-normal.8c538869.woff") format("woff"); unicode-range: U+1F??; } @@ -93,7 +93,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-greek-400-normal.4515f19a.woff2") format("woff2"), url("inter-greek-400-normal.77684a9d.woff") format("woff"); + src: url("inter-greek-400-normal.334c89a2.woff2") format("woff2"), url("inter-greek-400-normal.8f0b5c8d.woff") format("woff"); unicode-range: U+370-377, U+37A-37F, U+384-38A, U+38C, U+38E-3A1, U+3A3-3FF; } @@ -102,7 +102,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-vietnamese-400-normal.c9e40957.woff2") format("woff2"), url("inter-vietnamese-400-normal.6507846e.woff") format("woff"); + src: url("inter-vietnamese-400-normal.cd378412.woff2") format("woff2"), url("inter-vietnamese-400-normal.1c764e18.woff") format("woff"); unicode-range: U+102-103, U+110-111, U+128-129, U+168-169, U+1A0-1A1, U+1AF-1B0, U+300-301, U+303-304, U+308-309, U+323, U+329, U+1EA0-1EF9, U+20AB; } @@ -111,7 +111,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-latin-ext-400-normal.a6024ce9.woff2") format("woff2"), url("inter-latin-ext-400-normal.fbc4849c.woff") format("woff"); + src: url("inter-latin-ext-400-normal.9e6288f4.woff2") format("woff2"), url("inter-latin-ext-400-normal.3f4f9cd0.woff") format("woff"); unicode-range: U+100-2BA, U+2BD-2C5, U+2C7-2CC, U+2CE-2D7, U+2DD-2FF, U+304, U+308, U+329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; } @@ -120,7 +120,7 @@ font-style: normal; font-display: swap; font-weight: 400; - src: url("inter-latin-400-normal.fcefd771.woff2") format("woff2"), url("inter-latin-400-normal.a22ac1fc.woff") format("woff"); + src: url("inter-latin-400-normal.c257aa80.woff2") format("woff2"), url("inter-latin-400-normal.106646e8.woff") format("woff"); unicode-range: U+??, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+304, U+308, U+329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @@ -1140,7 +1140,8 @@ main:has(.not-found) .button { #results .results-container .message-container { background-color: var(--background-color); border-radius: 2rem; - padding: 1.5rem; + padding: 1.5rem 1.5rem 5rem; + position: relative; } #results .results-container .message-container .title { @@ -1164,12 +1165,12 @@ main:has(.not-found) .button { border-radius: 1.5rem 1.5rem 1.5rem .5rem; width: 80%; max-width: 800px; - margin-bottom: 1rem; padding: 1rem; } #results .results-container .message-container .message-box .reference { color: var(--text-color); + margin-top: 1rem; font-size: .8rem; } @@ -1238,9 +1239,12 @@ main:has(.not-found) .button { border-radius: 9999px; align-items: center; gap: .5rem; + width: calc(100% - 3rem); margin-top: 1rem; padding: 0 .5rem; display: flex; + position: absolute; + bottom: 1.5rem; } #results .results-container .message-container .send-message input { @@ -1268,6 +1272,7 @@ main:has(.not-found) .button { #results .results-container .message-container.ai.loading { background-color: var(--primary-color); color: var(--filled-text-color); + padding: 1.5rem; } #results .results-container .message-container.ai.loading svg { diff --git a/searx/static/themes/smart/css/rtl-style.css b/searx/static/themes/smart/css/rtl-style.css index 9235643e0..734b0e48e 100644 --- a/searx/static/themes/smart/css/rtl-style.css +++ b/searx/static/themes/smart/css/rtl-style.css @@ -1,6 +1,6 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Thin.37503ccd.woff2") format("woff2"); + src: url("Vazirmatn-UI-Thin.7fd7be2d.woff2") format("woff2"); font-weight: 100; font-style: normal; font-display: swap; @@ -8,7 +8,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-ExtraLight.cba2b231.woff2") format("woff2"); + src: url("Vazirmatn-UI-ExtraLight.165c33b1.woff2") format("woff2"); font-weight: 200; font-style: normal; font-display: swap; @@ -16,7 +16,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Light.c77d6de0.woff2") format("woff2"); + src: url("Vazirmatn-UI-Light.feccc9d1.woff2") format("woff2"); font-weight: 300; font-style: normal; font-display: swap; @@ -24,7 +24,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Regular.a3c99ff7.woff2") format("woff2"); + src: url("Vazirmatn-UI-Regular.65a0d014.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; @@ -32,7 +32,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Medium.972fdd22.woff2") format("woff2"); + src: url("Vazirmatn-UI-Medium.9f10f335.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; @@ -40,7 +40,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-SemiBold.37d9c53d.woff2") format("woff2"); + src: url("Vazirmatn-UI-SemiBold.f297b6f6.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; @@ -48,7 +48,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Bold.b0065d44.woff2") format("woff2"); + src: url("Vazirmatn-UI-Bold.bb01a60b.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; @@ -56,7 +56,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-ExtraBold.c431ea38.woff2") format("woff2"); + src: url("Vazirmatn-UI-ExtraBold.b1556a2a.woff2") format("woff2"); font-weight: 800; font-style: normal; font-display: swap; @@ -64,7 +64,7 @@ @font-face { font-family: Vazirmatn UI; - src: url("Vazirmatn-UI-Black.bc8837bc.woff2") format("woff2"); + src: url("Vazirmatn-UI-Black.eebe1f15.woff2") format("woff2"); font-weight: 900; font-style: normal; font-display: swap; @@ -1086,7 +1086,8 @@ main:has(.not-found) .button { #results .results-container .message-container { background-color: var(--background-color); border-radius: 2rem; - padding: 1.5rem; + padding: 1.5rem 1.5rem 5rem; + position: relative; } #results .results-container .message-container .title { @@ -1110,12 +1111,12 @@ main:has(.not-found) .button { border-radius: 1.5rem 1.5rem 1.5rem .5rem; width: 80%; max-width: 800px; - margin-bottom: 1rem; padding: 1rem; } #results .results-container .message-container .message-box .reference { color: var(--text-color); + margin-top: 1rem; font-size: .8rem; } @@ -1184,9 +1185,12 @@ main:has(.not-found) .button { border-radius: 9999px; align-items: center; gap: .5rem; + width: calc(100% - 3rem); margin-top: 1rem; padding: 0 .5rem; display: flex; + position: absolute; + bottom: 1.5rem; } #results .results-container .message-container .send-message input { @@ -1214,6 +1218,7 @@ main:has(.not-found) .button { #results .results-container .message-container.ai.loading { background-color: var(--primary-color); color: var(--filled-text-color); + padding: 1.5rem; } #results .results-container .message-container.ai.loading svg { diff --git a/searx/static/themes/smart/js/app.js b/searx/static/themes/smart/js/app.js index 8eff7c931..3f4ed618c 100644 --- a/searx/static/themes/smart/js/app.js +++ b/searx/static/themes/smart/js/app.js @@ -589,6 +589,7 @@ var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); parcelHelpers.defineInteropFlag(exports); parcelHelpers.export(exports, "$", ()=>$); parcelHelpers.export(exports, "$$", ()=>$$); +var _chat = require("./chat"); var _images = require("./images"); var _utils = require("./utils"); function $(selector) { @@ -597,51 +598,8967 @@ function $(selector) { function $$(selector) { return document.querySelectorAll(selector); } +function setupShareBtn() { + const shareBtn = $("#share-url-btn"); + if (!shareBtn) return; + shareBtn.addEventListener("click", function() { + const searchUrl = shareBtn.getAttribute("data-search-url"); + if (!searchUrl) return; + (0, _utils.copyToClipboard)(searchUrl); + const copiedText = shareBtn.getAttribute("data-gitee-copied"); + if (!copiedText) return; + shareBtn.setAttribute("tooltip", copiedText); + setTimeout(()=>{ + shareBtn.removeAttribute("tooltip"); + }, 2000); + }); +} +function setupPreferencesPage() { + // check for preferences hash + const hashInput = $("#preferences-hash"); + if (!hashInput) return; + const copyBtn = $("#copy-preferences-hash"); + if (!copyBtn) return; + copyBtn.addEventListener("click", function() { + (0, _utils.copyToClipboard)(hashInput.value); + copyBtn.innerText = copyBtn.getAttribute("data-copied-text"); + setTimeout(()=>{ + copyBtn.innerText = copyBtn.getAttribute("data-copy-text"); + }, 2000); + }); + const pasteBtn = $("#paste-preferences-hash"); + const pasteInput = $("#paste-preferences-hash-input"); + if (!pasteBtn || !pasteInput) return; + pasteBtn.addEventListener("click", async function() { + const hash = await (0, _utils.getFromClipboard)(); + pasteInput.value = hash; + }); +} (0, _images.checkImagePage)(); function afterPageLoad() { // preferences page - if ($("#preferences")) { - // check for preferences hash - const hashInput = $("#preferences-hash"); - if (!hashInput) return; - const copyBtn = $("#copy-preferences-hash"); - if (!copyBtn) return; - copyBtn.addEventListener("click", function() { - (0, _utils.copyToClipboard)(hashInput.value); - copyBtn.innerText = copyBtn.getAttribute("data-copied-text"); - setTimeout(()=>{ - copyBtn.innerText = copyBtn.getAttribute("data-copy-text"); - }, 2000); - }); - const pasteBtn = $("#paste-preferences-hash"); - const pasteInput = $("#paste-preferences-hash-input"); - if (!pasteBtn || !pasteInput) return; - pasteBtn.addEventListener("click", async function() { - const hash = await (0, _utils.getFromClipboard)(); - pasteInput.value = hash; - }); - } + if ($("#preferences")) setupPreferencesPage(); // search page - if ($("#results")) { - const shareBtn = $("#share-url-btn"); - if (!shareBtn) return; - shareBtn.addEventListener("click", function() { - const searchUrl = shareBtn.getAttribute("data-search-url"); - if (!searchUrl) return; - (0, _utils.copyToClipboard)(searchUrl); - const copiedText = shareBtn.getAttribute("data-gitee-copied"); - if (!copiedText) return; - shareBtn.setAttribute("tooltip", copiedText); - setTimeout(()=>{ - shareBtn.removeAttribute("tooltip"); - }, 2000); - }); - } + if ($("#results")) setupShareBtn(); + // chat + (0, _chat.setupChat)(); } if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", afterPageLoad); else afterPageLoad(); -},{"./images":"jxVSe","@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh","./utils":"hKc06"}],"jxVSe":[function(require,module,exports,__globalThis) { +},{"./chat":"aEJBv","./images":"jxVSe","./utils":"hKc06","@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh"}],"aEJBv":[function(require,module,exports,__globalThis) { +var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); +parcelHelpers.defineInteropFlag(exports); +parcelHelpers.export(exports, "setupChat", ()=>setupChat); +var _app = require("./app"); +var _openai = require("openai"); +let client; +let messages = [ + { + role: "system", + content: "You are a Search Engine Assistant. You will answer questions about the search query.\ + dont answer like previous message. try to summarize the answer little bit" + } +]; +function setupChat() { + const chatContainer = (0, _app.$)("#ai-message-container"); + if (!chatContainer) return; + const sendMessageForm = (0, _app.$)("#send-message"); + if (!sendMessageForm) return; + const messageInput = sendMessageForm.querySelector("input"); + if (!messageInput) return; + const searchQuery = (0, _app.$)("#search-query"); + if (!searchQuery) return; + client = new (0, _openai.OpenAI)({ + apiKey: "FAKE", + dangerouslyAllowBrowser: true, + baseURL: "https://openai.jabirproject.org/v1" + }); + sendMessage(messageInput, chatContainer, searchQuery.innerText).then(()=>chatContainer.classList.remove("loading")); + sendMessageForm.addEventListener("submit", function(e) { + e.preventDefault(); + sendMessage(messageInput, chatContainer); + }); +} +function createMessage(chatContainer, role, refrence) { + const messageBox = document.createElement("div"); + messageBox.classList.add("message-box"); + messageBox.classList.add(role); + const messageElement = document.createElement("div"); + messageElement.classList.add("message"); + messageBox.appendChild(messageElement); + // TODO: improve this + if (refrence) { + const referenceElement = document.createElement("div"); + referenceElement.classList.add("reference"); + referenceElement.innerText = refrence; + messageBox.appendChild(referenceElement); + } + chatContainer.appendChild(messageBox); + return messageElement; +} +async function sendMessage(messageInput, chatContainer, message) { + const userMessage = messageInput.value; + if (!userMessage && !message) return; + messages.push({ + role: "user", + content: message || userMessage + }); + const stream = await client.chat.completions.create({ + // @ts-ignore + model: "jabir-400b-online", + messages + }); + const messageElement = createMessage(chatContainer, "ai"); + // for await (const chunk of stream) { + // const text = chunk.choices[0].delta.content || ""; + // messageElement.innerText += text; + // }\ + messageElement.innerText = stream.choices[0].message.content || ""; + if (messageElement.innerText.length <= 0) messageElement.parentElement?.remove(); +} + +},{"./app":"3uyIQ","openai":"2Tbrx","@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh"}],"2Tbrx":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +var _a; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.fileFromPath = exports.toFile = exports.AzureOpenAI = exports.OpenAI = void 0; +const qs = __importStar(require("325e82cfa6c96e3c")); +const Core = __importStar(require("b2532de701e2d347")); +const Errors = __importStar(require("d9709efe1d5aeb55")); +const Pagination = __importStar(require("f0e27e36bcaf5db9")); +const Uploads = __importStar(require("766331169fa70c1d")); +const API = __importStar(require("8c4c71835b3db0c1")); +const batches_1 = require("b3c4339798368c1b"); +const completions_1 = require("78c256d6ecaffc36"); +const embeddings_1 = require("2035042f9308aca8"); +const files_1 = require("92998fbf88c5ae97"); +const images_1 = require("f8fdb8050ee8df4d"); +const models_1 = require("5a687293bb5a1a90"); +const moderations_1 = require("7d1311e6ec1de953"); +const audio_1 = require("7fc0dbcfe4d671a2"); +const beta_1 = require("803b09213e7de984"); +const chat_1 = require("97ccbfa63f55a9d1"); +const fine_tuning_1 = require("e2f9e502351de2c7"); +const uploads_1 = require("4fe6d5dc83b0d6"); +const completions_2 = require("84d0dbb5319bd1d5"); +/** + * API Client for interfacing with the OpenAI API. + */ class OpenAI extends Core.APIClient { + /** + * API Client for interfacing with the OpenAI API. + * + * @param {string | undefined} [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined] + * @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null] + * @param {string | null | undefined} [opts.project=process.env['OPENAI_PROJECT_ID'] ?? null] + * @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API. + * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. + * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. + * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. + * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. + * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. + * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. + * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers. + */ constructor({ baseURL = Core.readEnv('OPENAI_BASE_URL'), apiKey = Core.readEnv('OPENAI_API_KEY'), organization = Core.readEnv('OPENAI_ORG_ID') ?? null, project = Core.readEnv('OPENAI_PROJECT_ID') ?? null, ...opts } = {}){ + if (apiKey === undefined) throw new Errors.OpenAIError("The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' })."); + const options = { + apiKey, + organization, + project, + ...opts, + baseURL: baseURL || `https://api.openai.com/v1` + }; + if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) throw new Errors.OpenAIError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n"); + super({ + baseURL: options.baseURL, + timeout: options.timeout ?? 600000 /* 10 minutes */ , + httpAgent: options.httpAgent, + maxRetries: options.maxRetries, + fetch: options.fetch + }); + this.completions = new API.Completions(this); + this.chat = new API.Chat(this); + this.embeddings = new API.Embeddings(this); + this.files = new API.Files(this); + this.images = new API.Images(this); + this.audio = new API.Audio(this); + this.moderations = new API.Moderations(this); + this.models = new API.Models(this); + this.fineTuning = new API.FineTuning(this); + this.beta = new API.Beta(this); + this.batches = new API.Batches(this); + this.uploads = new API.Uploads(this); + this._options = options; + this.apiKey = apiKey; + this.organization = organization; + this.project = project; + } + defaultQuery() { + return this._options.defaultQuery; + } + defaultHeaders(opts) { + return { + ...super.defaultHeaders(opts), + 'OpenAI-Organization': this.organization, + 'OpenAI-Project': this.project, + ...this._options.defaultHeaders + }; + } + authHeaders(opts) { + return { + Authorization: `Bearer ${this.apiKey}` + }; + } + stringifyQuery(query) { + return qs.stringify(query, { + arrayFormat: 'brackets' + }); + } +} +exports.OpenAI = OpenAI; +_a = OpenAI; +OpenAI.OpenAI = _a; +OpenAI.DEFAULT_TIMEOUT = 600000; // 10 minutes +OpenAI.OpenAIError = Errors.OpenAIError; +OpenAI.APIError = Errors.APIError; +OpenAI.APIConnectionError = Errors.APIConnectionError; +OpenAI.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; +OpenAI.APIUserAbortError = Errors.APIUserAbortError; +OpenAI.NotFoundError = Errors.NotFoundError; +OpenAI.ConflictError = Errors.ConflictError; +OpenAI.RateLimitError = Errors.RateLimitError; +OpenAI.BadRequestError = Errors.BadRequestError; +OpenAI.AuthenticationError = Errors.AuthenticationError; +OpenAI.InternalServerError = Errors.InternalServerError; +OpenAI.PermissionDeniedError = Errors.PermissionDeniedError; +OpenAI.UnprocessableEntityError = Errors.UnprocessableEntityError; +OpenAI.toFile = Uploads.toFile; +OpenAI.fileFromPath = Uploads.fileFromPath; +OpenAI.Completions = completions_1.Completions; +OpenAI.Chat = chat_1.Chat; +OpenAI.ChatCompletionsPage = completions_2.ChatCompletionsPage; +OpenAI.Embeddings = embeddings_1.Embeddings; +OpenAI.Files = files_1.Files; +OpenAI.FileObjectsPage = files_1.FileObjectsPage; +OpenAI.Images = images_1.Images; +OpenAI.Audio = audio_1.Audio; +OpenAI.Moderations = moderations_1.Moderations; +OpenAI.Models = models_1.Models; +OpenAI.ModelsPage = models_1.ModelsPage; +OpenAI.FineTuning = fine_tuning_1.FineTuning; +OpenAI.Beta = beta_1.Beta; +OpenAI.Batches = batches_1.Batches; +OpenAI.BatchesPage = batches_1.BatchesPage; +OpenAI.Uploads = uploads_1.Uploads; +/** API Client for interfacing with the Azure OpenAI API. */ class AzureOpenAI extends OpenAI { + /** + * API Client for interfacing with the Azure OpenAI API. + * + * @param {string | undefined} [opts.apiVersion=process.env['OPENAI_API_VERSION'] ?? undefined] + * @param {string | undefined} [opts.endpoint=process.env['AZURE_OPENAI_ENDPOINT'] ?? undefined] - Your Azure endpoint, including the resource, e.g. `https://example-resource.azure.openai.com/` + * @param {string | undefined} [opts.apiKey=process.env['AZURE_OPENAI_API_KEY'] ?? undefined] + * @param {string | undefined} opts.deployment - A model deployment, if given, sets the base client URL to include `/deployments/{deployment}`. + * @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null] + * @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.openai.com/openai/`. + * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. + * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. + * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. + * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. + * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. + * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. + * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers. + */ constructor({ baseURL = Core.readEnv('OPENAI_BASE_URL'), apiKey = Core.readEnv('AZURE_OPENAI_API_KEY'), apiVersion = Core.readEnv('OPENAI_API_VERSION'), endpoint, deployment, azureADTokenProvider, dangerouslyAllowBrowser, ...opts } = {}){ + if (!apiVersion) throw new Errors.OpenAIError("The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' })."); + if (typeof azureADTokenProvider === 'function') dangerouslyAllowBrowser = true; + if (!azureADTokenProvider && !apiKey) throw new Errors.OpenAIError('Missing credentials. Please pass one of `apiKey` and `azureADTokenProvider`, or set the `AZURE_OPENAI_API_KEY` environment variable.'); + if (azureADTokenProvider && apiKey) throw new Errors.OpenAIError('The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.'); + // define a sentinel value to avoid any typing issues + apiKey ?? (apiKey = API_KEY_SENTINEL); + opts.defaultQuery = { + ...opts.defaultQuery, + 'api-version': apiVersion + }; + if (!baseURL) { + if (!endpoint) endpoint = undefined; + if (!endpoint) throw new Errors.OpenAIError('Must provide one of the `baseURL` or `endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable'); + baseURL = `${endpoint}/openai`; + } else { + if (endpoint) throw new Errors.OpenAIError('baseURL and endpoint are mutually exclusive'); + } + super({ + apiKey, + baseURL, + ...opts, + ...dangerouslyAllowBrowser !== undefined ? { + dangerouslyAllowBrowser + } : {} + }); + this.apiVersion = ''; + this._azureADTokenProvider = azureADTokenProvider; + this.apiVersion = apiVersion; + this.deploymentName = deployment; + } + buildRequest(options, props = {}) { + if (_deployments_endpoints.has(options.path) && options.method === 'post' && options.body !== undefined) { + if (!Core.isObj(options.body)) throw new Error('Expected request body to be an object'); + const model = this.deploymentName || options.body['model'] || options.__metadata?.['model']; + if (model !== undefined && !this.baseURL.includes('/deployments')) options.path = `/deployments/${model}${options.path}`; + } + return super.buildRequest(options, props); + } + async _getAzureADToken() { + if (typeof this._azureADTokenProvider === 'function') { + const token = await this._azureADTokenProvider(); + if (!token || typeof token !== 'string') throw new Errors.OpenAIError(`Expected 'azureADTokenProvider' argument to return a string but it returned ${token}`); + return token; + } + return undefined; + } + authHeaders(opts) { + return {}; + } + async prepareOptions(opts) { + /** + * The user should provide a bearer token provider if they want + * to use Azure AD authentication. The user shouldn't set the + * Authorization header manually because the header is overwritten + * with the Azure AD token if a bearer token provider is provided. + */ if (opts.headers?.['api-key']) return super.prepareOptions(opts); + const token = await this._getAzureADToken(); + opts.headers ?? (opts.headers = {}); + if (token) opts.headers['Authorization'] = `Bearer ${token}`; + else if (this.apiKey !== API_KEY_SENTINEL) opts.headers['api-key'] = this.apiKey; + else throw new Errors.OpenAIError('Unable to handle auth'); + return super.prepareOptions(opts); + } +} +exports.AzureOpenAI = AzureOpenAI; +const _deployments_endpoints = new Set([ + '/completions', + '/chat/completions', + '/embeddings', + '/audio/transcriptions', + '/audio/translations', + '/audio/speech', + '/images/generations' +]); +const API_KEY_SENTINEL = ''; +// ---------------------- End Azure ---------------------- +var uploads_2 = require("766331169fa70c1d"); +Object.defineProperty(exports, "toFile", { + enumerable: true, + get: function() { + return uploads_2.toFile; + } +}); +Object.defineProperty(exports, "fileFromPath", { + enumerable: true, + get: function() { + return uploads_2.fileFromPath; + } +}); +var error_1 = require("d9709efe1d5aeb55"); +Object.defineProperty(exports, "OpenAIError", { + enumerable: true, + get: function() { + return error_1.OpenAIError; + } +}); +Object.defineProperty(exports, "APIError", { + enumerable: true, + get: function() { + return error_1.APIError; + } +}); +Object.defineProperty(exports, "APIConnectionError", { + enumerable: true, + get: function() { + return error_1.APIConnectionError; + } +}); +Object.defineProperty(exports, "APIConnectionTimeoutError", { + enumerable: true, + get: function() { + return error_1.APIConnectionTimeoutError; + } +}); +Object.defineProperty(exports, "APIUserAbortError", { + enumerable: true, + get: function() { + return error_1.APIUserAbortError; + } +}); +Object.defineProperty(exports, "NotFoundError", { + enumerable: true, + get: function() { + return error_1.NotFoundError; + } +}); +Object.defineProperty(exports, "ConflictError", { + enumerable: true, + get: function() { + return error_1.ConflictError; + } +}); +Object.defineProperty(exports, "RateLimitError", { + enumerable: true, + get: function() { + return error_1.RateLimitError; + } +}); +Object.defineProperty(exports, "BadRequestError", { + enumerable: true, + get: function() { + return error_1.BadRequestError; + } +}); +Object.defineProperty(exports, "AuthenticationError", { + enumerable: true, + get: function() { + return error_1.AuthenticationError; + } +}); +Object.defineProperty(exports, "InternalServerError", { + enumerable: true, + get: function() { + return error_1.InternalServerError; + } +}); +Object.defineProperty(exports, "PermissionDeniedError", { + enumerable: true, + get: function() { + return error_1.PermissionDeniedError; + } +}); +Object.defineProperty(exports, "UnprocessableEntityError", { + enumerable: true, + get: function() { + return error_1.UnprocessableEntityError; + } +}); +exports = module.exports = OpenAI; +module.exports.AzureOpenAI = AzureOpenAI; +exports.default = OpenAI; + +},{"325e82cfa6c96e3c":"1EsAS","b2532de701e2d347":"haosB","d9709efe1d5aeb55":"lRecV","f0e27e36bcaf5db9":"jePq8","766331169fa70c1d":"jcDgx","8c4c71835b3db0c1":"7j2pI","b3c4339798368c1b":"i3zsm","78c256d6ecaffc36":"cig5h","2035042f9308aca8":"5Emd7","92998fbf88c5ae97":"jXD91","f8fdb8050ee8df4d":"sbLkY","5a687293bb5a1a90":"hGG1e","7d1311e6ec1de953":"53MBP","7fc0dbcfe4d671a2":"6HUeV","803b09213e7de984":"4YBCL","97ccbfa63f55a9d1":"1Oy6q","e2f9e502351de2c7":"gt3GR","4fe6d5dc83b0d6":"1T47D","84d0dbb5319bd1d5":"5LC9N"}],"1EsAS":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.formats = exports.stringify = void 0; +const formats_1 = require("c610fa9674da8a7f"); +const formats = { + formatters: formats_1.formatters, + RFC1738: formats_1.RFC1738, + RFC3986: formats_1.RFC3986, + default: formats_1.default_format +}; +exports.formats = formats; +var stringify_1 = require("4b742f7a05e35864"); +Object.defineProperty(exports, "stringify", { + enumerable: true, + get: function() { + return stringify_1.stringify; + } +}); + +},{"c610fa9674da8a7f":"g9qSw","4b742f7a05e35864":"dtAg2"}],"g9qSw":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.RFC3986 = exports.RFC1738 = exports.formatters = exports.default_format = void 0; +exports.default_format = 'RFC3986'; +exports.formatters = { + RFC1738: (v)=>String(v).replace(/%20/g, '+'), + RFC3986: (v)=>String(v) +}; +exports.RFC1738 = 'RFC1738'; +exports.RFC3986 = 'RFC3986'; + +},{}],"dtAg2":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.stringify = void 0; +const utils_1 = require("e6fca6f703be456c"); +const formats_1 = require("d9fe3d00f41bf6e9"); +const has = Object.prototype.hasOwnProperty; +const array_prefix_generators = { + brackets (prefix) { + return String(prefix) + '[]'; + }, + comma: 'comma', + indices (prefix, key) { + return String(prefix) + '[' + key + ']'; + }, + repeat (prefix) { + return String(prefix); + } +}; +const is_array = Array.isArray; +const push = Array.prototype.push; +const push_to_array = function(arr, value_or_array) { + push.apply(arr, is_array(value_or_array) ? value_or_array : [ + value_or_array + ]); +}; +const to_ISO = Date.prototype.toISOString; +const defaults = { + addQueryPrefix: false, + allowDots: false, + allowEmptyArrays: false, + arrayFormat: 'indices', + charset: 'utf-8', + charsetSentinel: false, + delimiter: '&', + encode: true, + encodeDotInKeys: false, + encoder: utils_1.encode, + encodeValuesOnly: false, + format: formats_1.default_format, + formatter: formats_1.formatters[formats_1.default_format], + /** @deprecated */ indices: false, + serializeDate (date) { + return to_ISO.call(date); + }, + skipNulls: false, + strictNullHandling: false +}; +function is_non_nullish_primitive(v) { + return typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || typeof v === 'symbol' || typeof v === 'bigint'; +} +const sentinel = {}; +function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, sideChannel) { + let obj = object; + let tmp_sc = sideChannel; + let step = 0; + let find_flag = false; + while((tmp_sc = tmp_sc.get(sentinel)) !== void 0 && !find_flag){ + // Where object last appeared in the ref tree + const pos = tmp_sc.get(object); + step += 1; + if (typeof pos !== 'undefined') { + if (pos === step) throw new RangeError('Cyclic object value'); + else find_flag = true; // Break while + } + if (typeof tmp_sc.get(sentinel) === 'undefined') step = 0; + } + if (typeof filter === 'function') obj = filter(prefix, obj); + else if (obj instanceof Date) obj = serializeDate?.(obj); + else if (generateArrayPrefix === 'comma' && is_array(obj)) obj = (0, utils_1.maybe_map)(obj, function(value) { + if (value instanceof Date) return serializeDate?.(value); + return value; + }); + if (obj === null) { + if (strictNullHandling) return encoder && !encodeValuesOnly ? // @ts-expect-error + encoder(prefix, defaults.encoder, charset, 'key', format) : prefix; + obj = ''; + } + if (is_non_nullish_primitive(obj) || (0, utils_1.is_buffer)(obj)) { + if (encoder) { + const key_value = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format); + return [ + formatter?.(key_value) + '=' + // @ts-expect-error + formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)) + ]; + } + return [ + formatter?.(prefix) + '=' + formatter?.(String(obj)) + ]; + } + const values = []; + if (typeof obj === 'undefined') return values; + let obj_keys; + if (generateArrayPrefix === 'comma' && is_array(obj)) { + // we need to join elements in + if (encodeValuesOnly && encoder) // @ts-expect-error values only + obj = (0, utils_1.maybe_map)(obj, encoder); + obj_keys = [ + { + value: obj.length > 0 ? obj.join(',') || null : void 0 + } + ]; + } else if (is_array(filter)) obj_keys = filter; + else { + const keys = Object.keys(obj); + obj_keys = sort ? keys.sort(sort) : keys; + } + const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix); + const adjusted_prefix = commaRoundTrip && is_array(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix; + if (allowEmptyArrays && is_array(obj) && obj.length === 0) return adjusted_prefix + '[]'; + for(let j = 0; j < obj_keys.length; ++j){ + const key = obj_keys[j]; + const value = // @ts-ignore + typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key]; + if (skipNulls && value === null) continue; + // @ts-ignore + const encoded_key = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key; + const key_prefix = is_array(obj) ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjusted_prefix, encoded_key) : adjusted_prefix : adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']'); + sideChannel.set(object, step); + const valueSideChannel = new WeakMap(); + valueSideChannel.set(sentinel, sideChannel); + push_to_array(values, inner_stringify(value, key_prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, // @ts-ignore + generateArrayPrefix === 'comma' && encodeValuesOnly && is_array(obj) ? null : encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, valueSideChannel)); + } + return values; +} +function normalize_stringify_options(opts = defaults) { + if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided'); + if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided'); + if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') throw new TypeError('Encoder has to be a function.'); + const charset = opts.charset || defaults.charset; + if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'); + let format = formats_1.default_format; + if (typeof opts.format !== 'undefined') { + if (!has.call(formats_1.formatters, opts.format)) throw new TypeError('Unknown format option provided.'); + format = opts.format; + } + const formatter = formats_1.formatters[format]; + let filter = defaults.filter; + if (typeof opts.filter === 'function' || is_array(opts.filter)) filter = opts.filter; + let arrayFormat; + if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) arrayFormat = opts.arrayFormat; + else if ('indices' in opts) arrayFormat = opts.indices ? 'indices' : 'repeat'; + else arrayFormat = defaults.arrayFormat; + if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') throw new TypeError('`commaRoundTrip` must be a boolean, or absent'); + const allowDots = typeof opts.allowDots === 'undefined' ? !!opts.encodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots; + return { + addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix, + // @ts-ignore + allowDots: allowDots, + allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays, + arrayFormat: arrayFormat, + charset: charset, + charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel, + commaRoundTrip: !!opts.commaRoundTrip, + delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter, + encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode, + encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys, + encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder, + encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly, + filter: filter, + format: format, + formatter: formatter, + serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate, + skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls, + // @ts-ignore + sort: typeof opts.sort === 'function' ? opts.sort : null, + strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling + }; +} +function stringify(object, opts = {}) { + let obj = object; + const options = normalize_stringify_options(opts); + let obj_keys; + let filter; + if (typeof options.filter === 'function') { + filter = options.filter; + obj = filter('', obj); + } else if (is_array(options.filter)) { + filter = options.filter; + obj_keys = filter; + } + const keys = []; + if (typeof obj !== 'object' || obj === null) return ''; + const generateArrayPrefix = array_prefix_generators[options.arrayFormat]; + const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip; + if (!obj_keys) obj_keys = Object.keys(obj); + if (options.sort) obj_keys.sort(options.sort); + const sideChannel = new WeakMap(); + for(let i = 0; i < obj_keys.length; ++i){ + const key = obj_keys[i]; + if (options.skipNulls && obj[key] === null) continue; + push_to_array(keys, inner_stringify(obj[key], key, // @ts-expect-error + generateArrayPrefix, commaRoundTrip, options.allowEmptyArrays, options.strictNullHandling, options.skipNulls, options.encodeDotInKeys, options.encode ? options.encoder : null, options.filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel)); + } + const joined = keys.join(options.delimiter); + let prefix = options.addQueryPrefix === true ? '?' : ''; + if (options.charsetSentinel) { + if (options.charset === 'iso-8859-1') // encodeURIComponent('✓'), the "numeric entity" representation of a checkmark + prefix += 'utf8=%26%2310003%3B&'; + else // encodeURIComponent('✓') + prefix += 'utf8=%E2%9C%93&'; + } + return joined.length > 0 ? prefix + joined : ''; +} +exports.stringify = stringify; + +},{"e6fca6f703be456c":"fBCes","d9fe3d00f41bf6e9":"g9qSw"}],"fBCes":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.maybe_map = exports.combine = exports.is_buffer = exports.is_regexp = exports.compact = exports.encode = exports.decode = exports.assign_single_source = exports.merge = void 0; +const formats_1 = require("1cc37db3d8f98ba"); +const has = Object.prototype.hasOwnProperty; +const is_array = Array.isArray; +const hex_table = (()=>{ + const array = []; + for(let i = 0; i < 256; ++i)array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase()); + return array; +})(); +function compact_queue(queue) { + while(queue.length > 1){ + const item = queue.pop(); + if (!item) continue; + const obj = item.obj[item.prop]; + if (is_array(obj)) { + const compacted = []; + for(let j = 0; j < obj.length; ++j)if (typeof obj[j] !== 'undefined') compacted.push(obj[j]); + // @ts-ignore + item.obj[item.prop] = compacted; + } + } +} +function array_to_object(source, options) { + const obj = options && options.plainObjects ? Object.create(null) : {}; + for(let i = 0; i < source.length; ++i)if (typeof source[i] !== 'undefined') obj[i] = source[i]; + return obj; +} +function merge(target, source, options = {}) { + if (!source) return target; + if (typeof source !== 'object') { + if (is_array(target)) target.push(source); + else if (target && typeof target === 'object') { + if (options && (options.plainObjects || options.allowPrototypes) || !has.call(Object.prototype, source)) target[source] = true; + } else return [ + target, + source + ]; + return target; + } + if (!target || typeof target !== 'object') return [ + target + ].concat(source); + let mergeTarget = target; + if (is_array(target) && !is_array(source)) // @ts-ignore + mergeTarget = array_to_object(target, options); + if (is_array(target) && is_array(source)) { + source.forEach(function(item, i) { + if (has.call(target, i)) { + const targetItem = target[i]; + if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') target[i] = merge(targetItem, item, options); + else target.push(item); + } else target[i] = item; + }); + return target; + } + return Object.keys(source).reduce(function(acc, key) { + const value = source[key]; + if (has.call(acc, key)) acc[key] = merge(acc[key], value, options); + else acc[key] = value; + return acc; + }, mergeTarget); +} +exports.merge = merge; +function assign_single_source(target, source) { + return Object.keys(source).reduce(function(acc, key) { + acc[key] = source[key]; + return acc; + }, target); +} +exports.assign_single_source = assign_single_source; +function decode(str, _, charset) { + const strWithoutPlus = str.replace(/\+/g, ' '); + if (charset === 'iso-8859-1') // unescape never throws, no try...catch needed: + return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape); + // utf-8 + try { + return decodeURIComponent(strWithoutPlus); + } catch (e) { + return strWithoutPlus; + } +} +exports.decode = decode; +const limit = 1024; +const encode = (str, _defaultEncoder, charset, _kind, format)=>{ + // This code was originally written by Brian White for the io.js core querystring library. + // It has been adapted here for stricter adherence to RFC 3986 + if (str.length === 0) return str; + let string = str; + if (typeof str === 'symbol') string = Symbol.prototype.toString.call(str); + else if (typeof str !== 'string') string = String(str); + if (charset === 'iso-8859-1') return escape(string).replace(/%u[0-9a-f]{4}/gi, function($0) { + return '%26%23' + parseInt($0.slice(2), 16) + '%3B'; + }); + let out = ''; + for(let j = 0; j < string.length; j += limit){ + const segment = string.length >= limit ? string.slice(j, j + limit) : string; + const arr = []; + for(let i = 0; i < segment.length; ++i){ + let c = segment.charCodeAt(i); + if (c === 0x2d || // - + c === 0x2e || // . + c === 0x5f || // _ + c === 0x7e || // ~ + c >= 0x30 && c <= 0x39 || // 0-9 + c >= 0x41 && c <= 0x5a || // a-z + c >= 0x61 && c <= 0x7a || // A-Z + format === formats_1.RFC1738 && (c === 0x28 || c === 0x29) // ( ) + ) { + arr[arr.length] = segment.charAt(i); + continue; + } + if (c < 0x80) { + arr[arr.length] = hex_table[c]; + continue; + } + if (c < 0x800) { + arr[arr.length] = hex_table[0xc0 | c >> 6] + hex_table[0x80 | c & 0x3f]; + continue; + } + if (c < 0xd800 || c >= 0xe000) { + arr[arr.length] = hex_table[0xe0 | c >> 12] + hex_table[0x80 | c >> 6 & 0x3f] + hex_table[0x80 | c & 0x3f]; + continue; + } + i += 1; + c = 0x10000 + ((c & 0x3ff) << 10 | segment.charCodeAt(i) & 0x3ff); + arr[arr.length] = hex_table[0xf0 | c >> 18] + hex_table[0x80 | c >> 12 & 0x3f] + hex_table[0x80 | c >> 6 & 0x3f] + hex_table[0x80 | c & 0x3f]; + } + out += arr.join(''); + } + return out; +}; +exports.encode = encode; +function compact(value) { + const queue = [ + { + obj: { + o: value + }, + prop: 'o' + } + ]; + const refs = []; + for(let i = 0; i < queue.length; ++i){ + const item = queue[i]; + // @ts-ignore + const obj = item.obj[item.prop]; + const keys = Object.keys(obj); + for(let j = 0; j < keys.length; ++j){ + const key = keys[j]; + const val = obj[key]; + if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) { + queue.push({ + obj: obj, + prop: key + }); + refs.push(val); + } + } + } + compact_queue(queue); + return value; +} +exports.compact = compact; +function is_regexp(obj) { + return Object.prototype.toString.call(obj) === '[object RegExp]'; +} +exports.is_regexp = is_regexp; +function is_buffer(obj) { + if (!obj || typeof obj !== 'object') return false; + return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj)); +} +exports.is_buffer = is_buffer; +function combine(a, b) { + return [].concat(a, b); +} +exports.combine = combine; +function maybe_map(val, fn) { + if (is_array(val)) { + const mapped = []; + for(let i = 0; i < val.length; i += 1)mapped.push(fn(val[i])); + return mapped; + } + return fn(val); +} +exports.maybe_map = maybe_map; + +},{"1cc37db3d8f98ba":"g9qSw"}],"haosB":[function(require,module,exports,__globalThis) { +var Buffer = require("31d6bf55516590d9").Buffer; +var process = require("fb4de7ad07f6de68"); +"use strict"; +var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function(receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; +}; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _AbstractPage_client; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.isObj = exports.toBase64 = exports.getHeader = exports.getRequiredHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0; +const version_1 = require("b0256790d8e603c7"); +const streaming_1 = require("47bb96a4f222954c"); +const error_1 = require("87a70cbc43c14d1a"); +const index_1 = require("18a02ad669aa835c"); +const uploads_1 = require("e1f0fe6ce9ed9848"); +var uploads_2 = require("e1f0fe6ce9ed9848"); +Object.defineProperty(exports, "maybeMultipartFormRequestOptions", { + enumerable: true, + get: function() { + return uploads_2.maybeMultipartFormRequestOptions; + } +}); +Object.defineProperty(exports, "multipartFormRequestOptions", { + enumerable: true, + get: function() { + return uploads_2.multipartFormRequestOptions; + } +}); +Object.defineProperty(exports, "createForm", { + enumerable: true, + get: function() { + return uploads_2.createForm; + } +}); +async function defaultParseResponse(props) { + const { response } = props; + if (props.options.stream) { + debug('response', response.status, response.url, response.headers, response.body); + // Note: there is an invariant here that isn't represented in the type system + // that if you set `stream: true` the response type must also be `Stream` + if (props.options.__streamClass) return props.options.__streamClass.fromSSEResponse(response, props.controller); + return streaming_1.Stream.fromSSEResponse(response, props.controller); + } + // fetch refuses to read the body when the status code is 204. + if (response.status === 204) return null; + if (props.options.__binaryResponse) return response; + const contentType = response.headers.get('content-type'); + const isJSON = contentType?.includes('application/json') || contentType?.includes('application/vnd.api+json'); + if (isJSON) { + const json = await response.json(); + debug('response', response.status, response.url, response.headers, json); + return _addRequestID(json, response); + } + const text = await response.text(); + debug('response', response.status, response.url, response.headers, text); + // TODO handle blob, arraybuffer, other content types, etc. + return text; +} +function _addRequestID(value, response) { + if (!value || typeof value !== 'object' || Array.isArray(value)) return value; + return Object.defineProperty(value, '_request_id', { + value: response.headers.get('x-request-id'), + enumerable: false + }); +} +/** + * A subclass of `Promise` providing additional helper methods + * for interacting with the SDK. + */ class APIPromise extends Promise { + constructor(responsePromise, parseResponse = defaultParseResponse){ + super((resolve)=>{ + // this is maybe a bit weird but this has to be a no-op to not implicitly + // parse the response body; instead .then, .catch, .finally are overridden + // to parse the response + resolve(null); + }); + this.responsePromise = responsePromise; + this.parseResponse = parseResponse; + } + _thenUnwrap(transform) { + return new APIPromise(this.responsePromise, async (props)=>_addRequestID(transform(await this.parseResponse(props), props), props.response)); + } + /** + * Gets the raw `Response` instance instead of parsing the response + * data. + * + * If you want to parse the response body but still get the `Response` + * instance, you can use {@link withResponse()}. + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` if you can, + * or add one of these imports before your first `import … from 'openai'`: + * - `import 'openai/shims/node'` (if you're running on Node) + * - `import 'openai/shims/web'` (otherwise) + */ asResponse() { + return this.responsePromise.then((p)=>p.response); + } + /** + * Gets the parsed response data, the raw `Response` instance and the ID of the request, + * returned via the X-Request-ID header which is useful for debugging requests and reporting + * issues to OpenAI. + * + * If you just want to get the raw `Response` instance without parsing it, + * you can use {@link asResponse()}. + * + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` if you can, + * or add one of these imports before your first `import … from 'openai'`: + * - `import 'openai/shims/node'` (if you're running on Node) + * - `import 'openai/shims/web'` (otherwise) + */ async withResponse() { + const [data, response] = await Promise.all([ + this.parse(), + this.asResponse() + ]); + return { + data, + response, + request_id: response.headers.get('x-request-id') + }; + } + parse() { + if (!this.parsedPromise) this.parsedPromise = this.responsePromise.then(this.parseResponse); + return this.parsedPromise; + } + then(onfulfilled, onrejected) { + return this.parse().then(onfulfilled, onrejected); + } + catch(onrejected) { + return this.parse().catch(onrejected); + } + finally(onfinally) { + return this.parse().finally(onfinally); + } +} +exports.APIPromise = APIPromise; +class APIClient { + constructor({ baseURL, maxRetries = 2, timeout = 600000, httpAgent, fetch: overriddenFetch }){ + this.baseURL = baseURL; + this.maxRetries = validatePositiveInteger('maxRetries', maxRetries); + this.timeout = validatePositiveInteger('timeout', timeout); + this.httpAgent = httpAgent; + this.fetch = overriddenFetch ?? index_1.fetch; + } + authHeaders(opts) { + return {}; + } + /** + * Override this to add your own default headers, for example: + * + * { + * ...super.defaultHeaders(), + * Authorization: 'Bearer 123', + * } + */ defaultHeaders(opts) { + return { + Accept: 'application/json', + 'Content-Type': 'application/json', + 'User-Agent': this.getUserAgent(), + ...getPlatformHeaders(), + ...this.authHeaders(opts) + }; + } + /** + * Override this to add your own headers validation: + */ validateHeaders(headers, customHeaders) {} + defaultIdempotencyKey() { + return `stainless-node-retry-${uuid4()}`; + } + get(path, opts) { + return this.methodRequest('get', path, opts); + } + post(path, opts) { + return this.methodRequest('post', path, opts); + } + patch(path, opts) { + return this.methodRequest('patch', path, opts); + } + put(path, opts) { + return this.methodRequest('put', path, opts); + } + delete(path, opts) { + return this.methodRequest('delete', path, opts); + } + methodRequest(method, path, opts) { + return this.request(Promise.resolve(opts).then(async (opts)=>{ + const body = opts && (0, uploads_1.isBlobLike)(opts?.body) ? new DataView(await opts.body.arrayBuffer()) : opts?.body instanceof DataView ? opts.body : opts?.body instanceof ArrayBuffer ? new DataView(opts.body) : opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer) : opts?.body; + return { + method, + path, + ...opts, + body + }; + })); + } + getAPIList(path, Page, opts) { + return this.requestAPIList(Page, { + method: 'get', + path, + ...opts + }); + } + calculateContentLength(body) { + if (typeof body === 'string') { + if (typeof Buffer !== 'undefined') return Buffer.byteLength(body, 'utf8').toString(); + if (typeof TextEncoder !== 'undefined') { + const encoder = new TextEncoder(); + const encoded = encoder.encode(body); + return encoded.length.toString(); + } + } else if (ArrayBuffer.isView(body)) return body.byteLength.toString(); + return null; + } + buildRequest(options, { retryCount = 0 } = {}) { + options = { + ...options + }; + const { method, path, query, headers: headers = {} } = options; + const body = ArrayBuffer.isView(options.body) || options.__binaryRequest && typeof options.body === 'string' ? options.body : (0, uploads_1.isMultipartBody)(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null; + const contentLength = this.calculateContentLength(body); + const url = this.buildURL(path, query); + if ('timeout' in options) validatePositiveInteger('timeout', options.timeout); + options.timeout = options.timeout ?? this.timeout; + const httpAgent = options.httpAgent ?? this.httpAgent ?? (0, index_1.getDefaultAgent)(url); + const minAgentTimeout = options.timeout + 1000; + if (typeof httpAgent?.options?.timeout === 'number' && minAgentTimeout > (httpAgent.options.timeout ?? 0)) // Allow any given request to bump our agent active socket timeout. + // This may seem strange, but leaking active sockets should be rare and not particularly problematic, + // and without mutating agent we would need to create more of them. + // This tradeoff optimizes for performance. + httpAgent.options.timeout = minAgentTimeout; + if (this.idempotencyHeader && method !== 'get') { + if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey(); + headers[this.idempotencyHeader] = options.idempotencyKey; + } + const reqHeaders = this.buildHeaders({ + options, + headers, + contentLength, + retryCount + }); + const req = { + method, + ...body && { + body: body + }, + headers: reqHeaders, + ...httpAgent && { + agent: httpAgent + }, + // @ts-ignore node-fetch uses a custom AbortSignal type that is + // not compatible with standard web types + signal: options.signal ?? null + }; + return { + req, + url, + timeout: options.timeout + }; + } + buildHeaders({ options, headers, contentLength, retryCount }) { + const reqHeaders = {}; + if (contentLength) reqHeaders['content-length'] = contentLength; + const defaultHeaders = this.defaultHeaders(options); + applyHeadersMut(reqHeaders, defaultHeaders); + applyHeadersMut(reqHeaders, headers); + // let builtin fetch set the Content-Type for multipart bodies + if ((0, uploads_1.isMultipartBody)(options.body) && index_1.kind !== 'node') delete reqHeaders['content-type']; + // Don't set theses headers if they were already set or removed through default headers or by the caller. + // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account + // for the removal case. + if ((0, exports.getHeader)(defaultHeaders, 'x-stainless-retry-count') === undefined && (0, exports.getHeader)(headers, 'x-stainless-retry-count') === undefined) reqHeaders['x-stainless-retry-count'] = String(retryCount); + if ((0, exports.getHeader)(defaultHeaders, 'x-stainless-timeout') === undefined && (0, exports.getHeader)(headers, 'x-stainless-timeout') === undefined && options.timeout) reqHeaders['x-stainless-timeout'] = String(options.timeout); + this.validateHeaders(reqHeaders, headers); + return reqHeaders; + } + /** + * Used as a callback for mutating the given `FinalRequestOptions` object. + */ async prepareOptions(options) {} + /** + * Used as a callback for mutating the given `RequestInit` object. + * + * This is useful for cases where you want to add certain headers based off of + * the request properties, e.g. `method` or `url`. + */ async prepareRequest(request, { url, options }) {} + parseHeaders(headers) { + return !headers ? {} : Symbol.iterator in headers ? Object.fromEntries(Array.from(headers).map((header)=>[ + ...header + ])) : { + ...headers + }; + } + makeStatusError(status, error, message, headers) { + return error_1.APIError.generate(status, error, message, headers); + } + request(options, remainingRetries = null) { + return new APIPromise(this.makeRequest(options, remainingRetries)); + } + async makeRequest(optionsInput, retriesRemaining) { + const options = await optionsInput; + const maxRetries = options.maxRetries ?? this.maxRetries; + if (retriesRemaining == null) retriesRemaining = maxRetries; + await this.prepareOptions(options); + const { req, url, timeout } = this.buildRequest(options, { + retryCount: maxRetries - retriesRemaining + }); + await this.prepareRequest(req, { + url, + options + }); + debug('request', url, options, req.headers); + if (options.signal?.aborted) throw new error_1.APIUserAbortError(); + const controller = new AbortController(); + const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(exports.castToError); + if (response instanceof Error) { + if (options.signal?.aborted) throw new error_1.APIUserAbortError(); + if (retriesRemaining) return this.retryRequest(options, retriesRemaining); + if (response.name === 'AbortError') throw new error_1.APIConnectionTimeoutError(); + throw new error_1.APIConnectionError({ + cause: response + }); + } + const responseHeaders = (0, exports.createResponseHeaders)(response.headers); + if (!response.ok) { + if (retriesRemaining && this.shouldRetry(response)) { + const retryMessage = `retrying, ${retriesRemaining} attempts remaining`; + debug(`response (error; ${retryMessage})`, response.status, url, responseHeaders); + return this.retryRequest(options, retriesRemaining, responseHeaders); + } + const errText = await response.text().catch((e)=>(0, exports.castToError)(e).message); + const errJSON = (0, exports.safeJSON)(errText); + const errMessage = errJSON ? undefined : errText; + const retryMessage = retriesRemaining ? `(error; no more retries left)` : `(error; not retryable)`; + debug(`response (error; ${retryMessage})`, response.status, url, responseHeaders, errMessage); + const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders); + throw err; + } + return { + response, + options, + controller + }; + } + requestAPIList(Page, options) { + const request = this.makeRequest(options, null); + return new PagePromise(this, request, Page); + } + buildURL(path, query) { + const url = isAbsoluteURL(path) ? new URL(path) : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path)); + const defaultQuery = this.defaultQuery(); + if (!isEmptyObj(defaultQuery)) query = { + ...defaultQuery, + ...query + }; + if (typeof query === 'object' && query && !Array.isArray(query)) url.search = this.stringifyQuery(query); + return url.toString(); + } + stringifyQuery(query) { + return Object.entries(query).filter(([_, value])=>typeof value !== 'undefined').map(([key, value])=>{ + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`; + if (value === null) return `${encodeURIComponent(key)}=`; + throw new error_1.OpenAIError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`); + }).join('&'); + } + async fetchWithTimeout(url, init, ms, controller) { + const { signal, ...options } = init || {}; + if (signal) signal.addEventListener('abort', ()=>controller.abort()); + const timeout = setTimeout(()=>controller.abort(), ms); + const fetchOptions = { + signal: controller.signal, + ...options + }; + if (fetchOptions.method) // Custom methods like 'patch' need to be uppercased + // See https://github.com/nodejs/undici/issues/2294 + fetchOptions.method = fetchOptions.method.toUpperCase(); + return(// use undefined this binding; fetch errors if bound to something else in browser/cloudflare + this.fetch.call(undefined, url, fetchOptions).finally(()=>{ + clearTimeout(timeout); + })); + } + shouldRetry(response) { + // Note this is not a standard header. + const shouldRetryHeader = response.headers.get('x-should-retry'); + // If the server explicitly says whether or not to retry, obey. + if (shouldRetryHeader === 'true') return true; + if (shouldRetryHeader === 'false') return false; + // Retry on request timeouts. + if (response.status === 408) return true; + // Retry on lock timeouts. + if (response.status === 409) return true; + // Retry on rate limits. + if (response.status === 429) return true; + // Retry internal errors. + if (response.status >= 500) return true; + return false; + } + async retryRequest(options, retriesRemaining, responseHeaders) { + let timeoutMillis; + // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it. + const retryAfterMillisHeader = responseHeaders?.['retry-after-ms']; + if (retryAfterMillisHeader) { + const timeoutMs = parseFloat(retryAfterMillisHeader); + if (!Number.isNaN(timeoutMs)) timeoutMillis = timeoutMs; + } + // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After + const retryAfterHeader = responseHeaders?.['retry-after']; + if (retryAfterHeader && !timeoutMillis) { + const timeoutSeconds = parseFloat(retryAfterHeader); + if (!Number.isNaN(timeoutSeconds)) timeoutMillis = timeoutSeconds * 1000; + else timeoutMillis = Date.parse(retryAfterHeader) - Date.now(); + } + // If the API asks us to wait a certain amount of time (and it's a reasonable amount), + // just do what it says, but otherwise calculate a default + if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60000)) { + const maxRetries = options.maxRetries ?? this.maxRetries; + timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries); + } + await (0, exports.sleep)(timeoutMillis); + return this.makeRequest(options, retriesRemaining - 1); + } + calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) { + const initialRetryDelay = 0.5; + const maxRetryDelay = 8.0; + const numRetries = maxRetries - retriesRemaining; + // Apply exponential backoff, but not more than the max. + const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay); + // Apply some jitter, take up to at most 25 percent of the retry time. + const jitter = 1 - Math.random() * 0.25; + return sleepSeconds * jitter * 1000; + } + getUserAgent() { + return `${this.constructor.name}/JS ${version_1.VERSION}`; + } +} +exports.APIClient = APIClient; +class AbstractPage { + constructor(client, response, body, options){ + _AbstractPage_client.set(this, void 0); + __classPrivateFieldSet(this, _AbstractPage_client, client, "f"); + this.options = options; + this.response = response; + this.body = body; + } + hasNextPage() { + const items = this.getPaginatedItems(); + if (!items.length) return false; + return this.nextPageInfo() != null; + } + async getNextPage() { + const nextInfo = this.nextPageInfo(); + if (!nextInfo) throw new error_1.OpenAIError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.'); + const nextOptions = { + ...this.options + }; + if ('params' in nextInfo && typeof nextOptions.query === 'object') nextOptions.query = { + ...nextOptions.query, + ...nextInfo.params + }; + else if ('url' in nextInfo) { + const params = [ + ...Object.entries(nextOptions.query || {}), + ...nextInfo.url.searchParams.entries() + ]; + for (const [key, value] of params)nextInfo.url.searchParams.set(key, value); + nextOptions.query = undefined; + nextOptions.path = nextInfo.url.toString(); + } + return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions); + } + async *iterPages() { + // eslint-disable-next-line @typescript-eslint/no-this-alias + let page = this; + yield page; + while(page.hasNextPage()){ + page = await page.getNextPage(); + yield page; + } + } + async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() { + for await (const page of this.iterPages())for (const item of page.getPaginatedItems())yield item; + } +} +exports.AbstractPage = AbstractPage; +/** + * This subclass of Promise will resolve to an instantiated Page once the request completes. + * + * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg: + * + * for await (const item of client.items.list()) { + * console.log(item) + * } + */ class PagePromise extends APIPromise { + constructor(client, request, Page){ + super(request, async (props)=>new Page(client, props.response, await defaultParseResponse(props), props.options)); + } + /** + * Allow auto-paginating iteration on an unawaited list call, eg: + * + * for await (const item of client.items.list()) { + * console.log(item) + * } + */ async *[Symbol.asyncIterator]() { + const page = await this; + for await (const item of page)yield item; + } +} +exports.PagePromise = PagePromise; +const createResponseHeaders = (headers)=>{ + return new Proxy(Object.fromEntries(// @ts-ignore + headers.entries()), { + get (target, name) { + const key = name.toString(); + return target[key.toLowerCase()] || target[key]; + } + }); +}; +exports.createResponseHeaders = createResponseHeaders; +// This is required so that we can determine if a given object matches the RequestOptions +// type at runtime. While this requires duplication, it is enforced by the TypeScript +// compiler such that any missing / extraneous keys will cause an error. +const requestOptionsKeys = { + method: true, + path: true, + query: true, + body: true, + headers: true, + maxRetries: true, + stream: true, + timeout: true, + httpAgent: true, + signal: true, + idempotencyKey: true, + __metadata: true, + __binaryRequest: true, + __binaryResponse: true, + __streamClass: true +}; +const isRequestOptions = (obj)=>{ + return typeof obj === 'object' && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k)=>hasOwn(requestOptionsKeys, k)); +}; +exports.isRequestOptions = isRequestOptions; +const getPlatformProperties = ()=>{ + if (typeof Deno !== 'undefined' && Deno.build != null) return { + 'X-Stainless-Lang': 'js', + 'X-Stainless-Package-Version': version_1.VERSION, + 'X-Stainless-OS': normalizePlatform(Deno.build.os), + 'X-Stainless-Arch': normalizeArch(Deno.build.arch), + 'X-Stainless-Runtime': 'deno', + 'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown' + }; + if (typeof EdgeRuntime !== 'undefined') return { + 'X-Stainless-Lang': 'js', + 'X-Stainless-Package-Version': version_1.VERSION, + 'X-Stainless-OS': 'Unknown', + 'X-Stainless-Arch': `other:${EdgeRuntime}`, + 'X-Stainless-Runtime': 'edge', + 'X-Stainless-Runtime-Version': process.version + }; + // Check if Node.js + if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') return { + 'X-Stainless-Lang': 'js', + 'X-Stainless-Package-Version': version_1.VERSION, + 'X-Stainless-OS': normalizePlatform(process.platform), + 'X-Stainless-Arch': normalizeArch(process.arch), + 'X-Stainless-Runtime': 'node', + 'X-Stainless-Runtime-Version': process.version + }; + const browserInfo = getBrowserInfo(); + if (browserInfo) return { + 'X-Stainless-Lang': 'js', + 'X-Stainless-Package-Version': version_1.VERSION, + 'X-Stainless-OS': 'Unknown', + 'X-Stainless-Arch': 'unknown', + 'X-Stainless-Runtime': `browser:${browserInfo.browser}`, + 'X-Stainless-Runtime-Version': browserInfo.version + }; + // TODO add support for Cloudflare workers, etc. + return { + 'X-Stainless-Lang': 'js', + 'X-Stainless-Package-Version': version_1.VERSION, + 'X-Stainless-OS': 'Unknown', + 'X-Stainless-Arch': 'unknown', + 'X-Stainless-Runtime': 'unknown', + 'X-Stainless-Runtime-Version': 'unknown' + }; +}; +// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts +function getBrowserInfo() { + if (typeof navigator === 'undefined' || !navigator) return null; + // NOTE: The order matters here! + const browserPatterns = [ + { + key: 'edge', + pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ + }, + { + key: 'ie', + pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ + }, + { + key: 'ie', + pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ + }, + { + key: 'chrome', + pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ + }, + { + key: 'firefox', + pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ + }, + { + key: 'safari', + pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ + } + ]; + // Find the FIRST matching browser + for (const { key, pattern } of browserPatterns){ + const match = pattern.exec(navigator.userAgent); + if (match) { + const major = match[1] || 0; + const minor = match[2] || 0; + const patch = match[3] || 0; + return { + browser: key, + version: `${major}.${minor}.${patch}` + }; + } + } + return null; +} +const normalizeArch = (arch)=>{ + // Node docs: + // - https://nodejs.org/api/process.html#processarch + // Deno docs: + // - https://doc.deno.land/deno/stable/~/Deno.build + if (arch === 'x32') return 'x32'; + if (arch === 'x86_64' || arch === 'x64') return 'x64'; + if (arch === 'arm') return 'arm'; + if (arch === 'aarch64' || arch === 'arm64') return 'arm64'; + if (arch) return `other:${arch}`; + return 'unknown'; +}; +const normalizePlatform = (platform)=>{ + // Node platforms: + // - https://nodejs.org/api/process.html#processplatform + // Deno platforms: + // - https://doc.deno.land/deno/stable/~/Deno.build + // - https://github.com/denoland/deno/issues/14799 + platform = platform.toLowerCase(); + // NOTE: this iOS check is untested and may not work + // Node does not work natively on IOS, there is a fork at + // https://github.com/nodejs-mobile/nodejs-mobile + // however it is unknown at the time of writing how to detect if it is running + if (platform.includes('ios')) return 'iOS'; + if (platform === 'android') return 'Android'; + if (platform === 'darwin') return 'MacOS'; + if (platform === 'win32') return 'Windows'; + if (platform === 'freebsd') return 'FreeBSD'; + if (platform === 'openbsd') return 'OpenBSD'; + if (platform === 'linux') return 'Linux'; + if (platform) return `Other:${platform}`; + return 'Unknown'; +}; +let _platformHeaders; +const getPlatformHeaders = ()=>{ + return _platformHeaders ?? (_platformHeaders = getPlatformProperties()); +}; +const safeJSON = (text)=>{ + try { + return JSON.parse(text); + } catch (err) { + return undefined; + } +}; +exports.safeJSON = safeJSON; +// https://url.spec.whatwg.org/#url-scheme-string +const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i; +const isAbsoluteURL = (url)=>{ + return startsWithSchemeRegexp.test(url); +}; +const sleep = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms)); +exports.sleep = sleep; +const validatePositiveInteger = (name, n)=>{ + if (typeof n !== 'number' || !Number.isInteger(n)) throw new error_1.OpenAIError(`${name} must be an integer`); + if (n < 0) throw new error_1.OpenAIError(`${name} must be a positive integer`); + return n; +}; +const castToError = (err)=>{ + if (err instanceof Error) return err; + if (typeof err === 'object' && err !== null) try { + return new Error(JSON.stringify(err)); + } catch {} + return new Error(err); +}; +exports.castToError = castToError; +const ensurePresent = (value)=>{ + if (value == null) throw new error_1.OpenAIError(`Expected a value to be given but received ${value} instead.`); + return value; +}; +exports.ensurePresent = ensurePresent; +/** + * Read an environment variable. + * + * Trims beginning and trailing whitespace. + * + * Will return undefined if the environment variable doesn't exist or cannot be accessed. + */ const readEnv = (env)=>{ + if (typeof process !== 'undefined') return process.env?.[env]?.trim() ?? undefined; + if (typeof Deno !== 'undefined') return Deno.env?.get?.(env)?.trim(); + return undefined; +}; +exports.readEnv = readEnv; +const coerceInteger = (value)=>{ + if (typeof value === 'number') return Math.round(value); + if (typeof value === 'string') return parseInt(value, 10); + throw new error_1.OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`); +}; +exports.coerceInteger = coerceInteger; +const coerceFloat = (value)=>{ + if (typeof value === 'number') return value; + if (typeof value === 'string') return parseFloat(value); + throw new error_1.OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`); +}; +exports.coerceFloat = coerceFloat; +const coerceBoolean = (value)=>{ + if (typeof value === 'boolean') return value; + if (typeof value === 'string') return value === 'true'; + return Boolean(value); +}; +exports.coerceBoolean = coerceBoolean; +const maybeCoerceInteger = (value)=>{ + if (value === undefined) return undefined; + return (0, exports.coerceInteger)(value); +}; +exports.maybeCoerceInteger = maybeCoerceInteger; +const maybeCoerceFloat = (value)=>{ + if (value === undefined) return undefined; + return (0, exports.coerceFloat)(value); +}; +exports.maybeCoerceFloat = maybeCoerceFloat; +const maybeCoerceBoolean = (value)=>{ + if (value === undefined) return undefined; + return (0, exports.coerceBoolean)(value); +}; +exports.maybeCoerceBoolean = maybeCoerceBoolean; +// https://stackoverflow.com/a/34491287 +function isEmptyObj(obj) { + if (!obj) return true; + for(const _k in obj)return false; + return true; +} +exports.isEmptyObj = isEmptyObj; +// https://eslint.org/docs/latest/rules/no-prototype-builtins +function hasOwn(obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key); +} +exports.hasOwn = hasOwn; +/** + * Copies headers from "newHeaders" onto "targetHeaders", + * using lower-case for all properties, + * ignoring any keys with undefined values, + * and deleting any keys with null values. + */ function applyHeadersMut(targetHeaders, newHeaders) { + for(const k in newHeaders){ + if (!hasOwn(newHeaders, k)) continue; + const lowerKey = k.toLowerCase(); + if (!lowerKey) continue; + const val = newHeaders[k]; + if (val === null) delete targetHeaders[lowerKey]; + else if (val !== undefined) targetHeaders[lowerKey] = val; + } +} +const SENSITIVE_HEADERS = new Set([ + 'authorization', + 'api-key' +]); +function debug(action, ...args) { + if (typeof process !== 'undefined' && process?.env?.['DEBUG'] === 'true') { + const modifiedArgs = args.map((arg)=>{ + if (!arg) return arg; + // Check for sensitive headers in request body 'headers' object + if (arg['headers']) { + // clone so we don't mutate + const modifiedArg = { + ...arg, + headers: { + ...arg['headers'] + } + }; + for(const header in arg['headers'])if (SENSITIVE_HEADERS.has(header.toLowerCase())) modifiedArg['headers'][header] = 'REDACTED'; + return modifiedArg; + } + let modifiedArg = null; + // Check for sensitive headers in headers object + for(const header in arg)if (SENSITIVE_HEADERS.has(header.toLowerCase())) { + // avoid making a copy until we need to + modifiedArg ?? (modifiedArg = { + ...arg + }); + modifiedArg[header] = 'REDACTED'; + } + return modifiedArg ?? arg; + }); + console.log(`OpenAI:DEBUG:${action}`, ...modifiedArgs); + } +} +exports.debug = debug; +/** + * https://stackoverflow.com/a/2117523 + */ const uuid4 = ()=>{ + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c)=>{ + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : r & 0x3 | 0x8; + return v.toString(16); + }); +}; +const isRunningInBrowser = ()=>{ + return(// @ts-ignore + typeof window !== 'undefined' && // @ts-ignore + typeof window.document !== 'undefined' && // @ts-ignore + typeof navigator !== 'undefined'); +}; +exports.isRunningInBrowser = isRunningInBrowser; +const isHeadersProtocol = (headers)=>{ + return typeof headers?.get === 'function'; +}; +exports.isHeadersProtocol = isHeadersProtocol; +const getRequiredHeader = (headers, header)=>{ + const foundHeader = (0, exports.getHeader)(headers, header); + if (foundHeader === undefined) throw new Error(`Could not find ${header} header`); + return foundHeader; +}; +exports.getRequiredHeader = getRequiredHeader; +const getHeader = (headers, header)=>{ + const lowerCasedHeader = header.toLowerCase(); + if ((0, exports.isHeadersProtocol)(headers)) { + // to deal with the case where the header looks like Stainless-Event-Id + const intercapsHeader = header[0]?.toUpperCase() + header.substring(1).replace(/([^\w])(\w)/g, (_m, g1, g2)=>g1 + g2.toUpperCase()); + for (const key of [ + header, + lowerCasedHeader, + header.toUpperCase(), + intercapsHeader + ]){ + const value = headers.get(key); + if (value) return value; + } + } + for (const [key, value] of Object.entries(headers))if (key.toLowerCase() === lowerCasedHeader) { + if (Array.isArray(value)) { + if (value.length <= 1) return value[0]; + console.warn(`Received ${value.length} entries for the ${header} header, using the first entry.`); + return value[0]; + } + return value; + } + return undefined; +}; +exports.getHeader = getHeader; +/** + * Encodes a string to Base64 format. + */ const toBase64 = (str)=>{ + if (!str) return ''; + if (typeof Buffer !== 'undefined') return Buffer.from(str).toString('base64'); + if (typeof btoa !== 'undefined') return btoa(str); + throw new error_1.OpenAIError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined'); +}; +exports.toBase64 = toBase64; +function isObj(obj) { + return obj != null && typeof obj === 'object' && !Array.isArray(obj); +} +exports.isObj = isObj; + +},{"31d6bf55516590d9":"6tQNr","fb4de7ad07f6de68":"gq3cc","b0256790d8e603c7":"eUXIe","47bb96a4f222954c":"2gNIj","87a70cbc43c14d1a":"lRecV","18a02ad669aa835c":"5wsSO","e1f0fe6ce9ed9848":"jcDgx"}],"6tQNr":[function(require,module,exports,__globalThis) { +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ /* eslint-disable no-proto */ 'use strict'; +const base64 = require("9c62938f1dccc73c"); +const ieee754 = require("aceacb6a4531a9d2"); +const customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' // eslint-disable-line dot-notation + ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation + : null; +exports.Buffer = Buffer; +exports.SlowBuffer = SlowBuffer; +exports.INSPECT_MAX_BYTES = 50; +const K_MAX_LENGTH = 0x7fffffff; +exports.kMaxLength = K_MAX_LENGTH; +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. + */ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."); +function typedArraySupport() { + // Can typed array instances can be augmented? + try { + const arr = new Uint8Array(1); + const proto = { + foo: function() { + return 42; + } + }; + Object.setPrototypeOf(proto, Uint8Array.prototype); + Object.setPrototypeOf(arr, proto); + return arr.foo() === 42; + } catch (e) { + return false; + } +} +Object.defineProperty(Buffer.prototype, 'parent', { + enumerable: true, + get: function() { + if (!Buffer.isBuffer(this)) return undefined; + return this.buffer; + } +}); +Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get: function() { + if (!Buffer.isBuffer(this)) return undefined; + return this.byteOffset; + } +}); +function createBuffer(length) { + if (length > K_MAX_LENGTH) throw new RangeError('The value "' + length + '" is invalid for option "size"'); + // Return an augmented `Uint8Array` instance + const buf = new Uint8Array(length); + Object.setPrototypeOf(buf, Buffer.prototype); + return buf; +} +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ function Buffer(arg, encodingOrOffset, length) { + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') throw new TypeError('The "string" argument must be of type string. Received type number'); + return allocUnsafe(arg); + } + return from(arg, encodingOrOffset, length); +} +Buffer.poolSize = 8192 // not used by this implementation +; +function from(value, encodingOrOffset, length) { + if (typeof value === 'string') return fromString(value, encodingOrOffset); + if (ArrayBuffer.isView(value)) return fromArrayView(value); + if (value == null) throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); + if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) return fromArrayBuffer(value, encodingOrOffset, length); + if (typeof SharedArrayBuffer !== 'undefined' && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) return fromArrayBuffer(value, encodingOrOffset, length); + if (typeof value === 'number') throw new TypeError('The "value" argument must not be of type number. Received type number'); + const valueOf = value.valueOf && value.valueOf(); + if (valueOf != null && valueOf !== value) return Buffer.from(valueOf, encodingOrOffset, length); + const b = fromObject(value); + if (b) return b; + if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); + throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); +} +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ Buffer.from = function(value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length); +}; +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); +Object.setPrototypeOf(Buffer, Uint8Array); +function assertSize(size) { + if (typeof size !== 'number') throw new TypeError('"size" argument must be of type number'); + else if (size < 0) throw new RangeError('The value "' + size + '" is invalid for option "size"'); +} +function alloc(size, fill, encoding) { + assertSize(size); + if (size <= 0) return createBuffer(size); + if (fill !== undefined) // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpreted as a start offset. + return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); + return createBuffer(size); +} +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ Buffer.alloc = function(size, fill, encoding) { + return alloc(size, fill, encoding); +}; +function allocUnsafe(size) { + assertSize(size); + return createBuffer(size < 0 ? 0 : checked(size) | 0); +} +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ Buffer.allocUnsafe = function(size) { + return allocUnsafe(size); +}; +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ Buffer.allocUnsafeSlow = function(size) { + return allocUnsafe(size); +}; +function fromString(string, encoding) { + if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8'; + if (!Buffer.isEncoding(encoding)) throw new TypeError('Unknown encoding: ' + encoding); + const length = byteLength(string, encoding) | 0; + let buf = createBuffer(length); + const actual = buf.write(string, encoding); + if (actual !== length) // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + return buf; +} +function fromArrayLike(array) { + const length = array.length < 0 ? 0 : checked(array.length) | 0; + const buf = createBuffer(length); + for(let i = 0; i < length; i += 1)buf[i] = array[i] & 255; + return buf; +} +function fromArrayView(arrayView) { + if (isInstance(arrayView, Uint8Array)) { + const copy = new Uint8Array(arrayView); + return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); + } + return fromArrayLike(arrayView); +} +function fromArrayBuffer(array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) throw new RangeError('"offset" is outside of buffer bounds'); + if (array.byteLength < byteOffset + (length || 0)) throw new RangeError('"length" is outside of buffer bounds'); + let buf; + if (byteOffset === undefined && length === undefined) buf = new Uint8Array(array); + else if (length === undefined) buf = new Uint8Array(array, byteOffset); + else buf = new Uint8Array(array, byteOffset, length); + // Return an augmented `Uint8Array` instance + Object.setPrototypeOf(buf, Buffer.prototype); + return buf; +} +function fromObject(obj) { + if (Buffer.isBuffer(obj)) { + const len = checked(obj.length) | 0; + const buf = createBuffer(len); + if (buf.length === 0) return buf; + obj.copy(buf, 0, 0, len); + return buf; + } + if (obj.length !== undefined) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) return createBuffer(0); + return fromArrayLike(obj); + } + if (obj.type === 'Buffer' && Array.isArray(obj.data)) return fromArrayLike(obj.data); +} +function checked(length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + ' bytes'); + return length | 0; +} +function SlowBuffer(length) { + if (+length != length) length = 0; + return Buffer.alloc(+length); +} +Buffer.isBuffer = function isBuffer(b) { + return b != null && b._isBuffer === true && b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false + ; +}; +Buffer.compare = function compare(a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'); + if (a === b) return 0; + let x = a.length; + let y = b.length; + for(let i = 0, len = Math.min(x, y); i < len; ++i)if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + if (x < y) return -1; + if (y < x) return 1; + return 0; +}; +Buffer.isEncoding = function isEncoding(encoding) { + switch(String(encoding).toLowerCase()){ + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true; + default: + return false; + } +}; +Buffer.concat = function concat(list, length) { + if (!Array.isArray(list)) throw new TypeError('"list" argument must be an Array of Buffers'); + if (list.length === 0) return Buffer.alloc(0); + let i; + if (length === undefined) { + length = 0; + for(i = 0; i < list.length; ++i)length += list[i].length; + } + const buffer = Buffer.allocUnsafe(length); + let pos = 0; + for(i = 0; i < list.length; ++i){ + let buf = list[i]; + if (isInstance(buf, Uint8Array)) { + if (pos + buf.length > buffer.length) { + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); + buf.copy(buffer, pos); + } else Uint8Array.prototype.set.call(buffer, buf, pos); + } else if (!Buffer.isBuffer(buf)) throw new TypeError('"list" argument must be an Array of Buffers'); + else buf.copy(buffer, pos); + pos += buf.length; + } + return buffer; +}; +function byteLength(string, encoding) { + if (Buffer.isBuffer(string)) return string.length; + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) return string.byteLength; + if (typeof string !== 'string') throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string); + const len = string.length; + const mustMatch = arguments.length > 2 && arguments[2] === true; + if (!mustMatch && len === 0) return 0; + // Use a for loop to avoid recursion + let loweredCase = false; + for(;;)switch(encoding){ + case 'ascii': + case 'latin1': + case 'binary': + return len; + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length; + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2; + case 'hex': + return len >>> 1; + case 'base64': + return base64ToBytes(string).length; + default: + if (loweredCase) return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 + ; + encoding = ('' + encoding).toLowerCase(); + loweredCase = true; + } +} +Buffer.byteLength = byteLength; +function slowToString(encoding, start, end) { + let loweredCase = false; + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) start = 0; + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) return ''; + if (end === undefined || end > this.length) end = this.length; + if (end <= 0) return ''; + // Force coercion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0; + start >>>= 0; + if (end <= start) return ''; + if (!encoding) encoding = 'utf8'; + while(true)switch(encoding){ + case 'hex': + return hexSlice(this, start, end); + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end); + case 'ascii': + return asciiSlice(this, start, end); + case 'latin1': + case 'binary': + return latin1Slice(this, start, end); + case 'base64': + return base64Slice(this, start, end); + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end); + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); + encoding = (encoding + '').toLowerCase(); + loweredCase = true; + } +} +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 +Buffer.prototype._isBuffer = true; +function swap(b, n, m) { + const i = b[n]; + b[n] = b[m]; + b[m] = i; +} +Buffer.prototype.swap16 = function swap16() { + const len = this.length; + if (len % 2 !== 0) throw new RangeError('Buffer size must be a multiple of 16-bits'); + for(let i = 0; i < len; i += 2)swap(this, i, i + 1); + return this; +}; +Buffer.prototype.swap32 = function swap32() { + const len = this.length; + if (len % 4 !== 0) throw new RangeError('Buffer size must be a multiple of 32-bits'); + for(let i = 0; i < len; i += 4){ + swap(this, i, i + 3); + swap(this, i + 1, i + 2); + } + return this; +}; +Buffer.prototype.swap64 = function swap64() { + const len = this.length; + if (len % 8 !== 0) throw new RangeError('Buffer size must be a multiple of 64-bits'); + for(let i = 0; i < len; i += 8){ + swap(this, i, i + 7); + swap(this, i + 1, i + 6); + swap(this, i + 2, i + 5); + swap(this, i + 3, i + 4); + } + return this; +}; +Buffer.prototype.toString = function toString() { + const length = this.length; + if (length === 0) return ''; + if (arguments.length === 0) return utf8Slice(this, 0, length); + return slowToString.apply(this, arguments); +}; +Buffer.prototype.toLocaleString = Buffer.prototype.toString; +Buffer.prototype.equals = function equals(b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); + if (this === b) return true; + return Buffer.compare(this, b) === 0; +}; +Buffer.prototype.inspect = function inspect() { + let str = ''; + const max = exports.INSPECT_MAX_BYTES; + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); + if (this.length > max) str += ' ... '; + return ''; +}; +if (customInspectSymbol) Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; +Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) target = Buffer.from(target, target.offset, target.byteLength); + if (!Buffer.isBuffer(target)) throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target); + if (start === undefined) start = 0; + if (end === undefined) end = target ? target.length : 0; + if (thisStart === undefined) thisStart = 0; + if (thisEnd === undefined) thisEnd = this.length; + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) throw new RangeError('out of range index'); + if (thisStart >= thisEnd && start >= end) return 0; + if (thisStart >= thisEnd) return -1; + if (start >= end) return 1; + start >>>= 0; + end >>>= 0; + thisStart >>>= 0; + thisEnd >>>= 0; + if (this === target) return 0; + let x = thisEnd - thisStart; + let y = end - start; + const len = Math.min(x, y); + const thisCopy = this.slice(thisStart, thisEnd); + const targetCopy = target.slice(start, end); + for(let i = 0; i < len; ++i)if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i]; + y = targetCopy[i]; + break; + } + if (x < y) return -1; + if (y < x) return 1; + return 0; +}; +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1; + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset; + byteOffset = 0; + } else if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff; + else if (byteOffset < -2147483648) byteOffset = -2147483648; + byteOffset = +byteOffset // Coerce to Number. + ; + if (numberIsNaN(byteOffset)) // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : buffer.length - 1; + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset; + if (byteOffset >= buffer.length) { + if (dir) return -1; + else byteOffset = buffer.length - 1; + } else if (byteOffset < 0) { + if (dir) byteOffset = 0; + else return -1; + } + // Normalize val + if (typeof val === 'string') val = Buffer.from(val, encoding); + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) return -1; + return arrayIndexOf(buffer, val, byteOffset, encoding, dir); + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + ; + if (typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); + else return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); + } + return arrayIndexOf(buffer, [ + val + ], byteOffset, encoding, dir); + } + throw new TypeError('val must be string, number or Buffer'); +} +function arrayIndexOf(arr, val, byteOffset, encoding, dir) { + let indexSize = 1; + let arrLength = arr.length; + let valLength = val.length; + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase(); + if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) return -1; + indexSize = 2; + arrLength /= 2; + valLength /= 2; + byteOffset /= 2; + } + } + function read(buf, i) { + if (indexSize === 1) return buf[i]; + else return buf.readUInt16BE(i * indexSize); + } + let i; + if (dir) { + let foundIndex = -1; + for(i = byteOffset; i < arrLength; i++)if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i; + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; + } else { + if (foundIndex !== -1) i -= i - foundIndex; + foundIndex = -1; + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; + for(i = byteOffset; i >= 0; i--){ + let found = true; + for(let j = 0; j < valLength; j++)if (read(arr, i + j) !== read(val, j)) { + found = false; + break; + } + if (found) return i; + } + } + return -1; +} +Buffer.prototype.includes = function includes(val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1; +}; +Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true); +}; +Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false); +}; +function hexWrite(buf, string, offset, length) { + offset = Number(offset) || 0; + const remaining = buf.length - offset; + if (!length) length = remaining; + else { + length = Number(length); + if (length > remaining) length = remaining; + } + const strLen = string.length; + if (length > strLen / 2) length = strLen / 2; + let i; + for(i = 0; i < length; ++i){ + const parsed = parseInt(string.substr(i * 2, 2), 16); + if (numberIsNaN(parsed)) return i; + buf[offset + i] = parsed; + } + return i; +} +function utf8Write(buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); +} +function asciiWrite(buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length); +} +function base64Write(buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length); +} +function ucs2Write(buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); +} +Buffer.prototype.write = function write(string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8'; + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset; + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset >>> 0; + if (isFinite(length)) { + length = length >>> 0; + if (encoding === undefined) encoding = 'utf8'; + } else { + encoding = length; + length = undefined; + } + } else throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); + const remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) throw new RangeError('Attempt to write outside buffer bounds'); + if (!encoding) encoding = 'utf8'; + let loweredCase = false; + for(;;)switch(encoding){ + case 'hex': + return hexWrite(this, string, offset, length); + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length); + case 'ascii': + case 'latin1': + case 'binary': + return asciiWrite(this, string, offset, length); + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length); + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length); + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); + encoding = ('' + encoding).toLowerCase(); + loweredCase = true; + } +}; +Buffer.prototype.toJSON = function toJSON() { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + }; +}; +function base64Slice(buf, start, end) { + if (start === 0 && end === buf.length) return base64.fromByteArray(buf); + else return base64.fromByteArray(buf.slice(start, end)); +} +function utf8Slice(buf, start, end) { + end = Math.min(buf.length, end); + const res = []; + let i = start; + while(i < end){ + const firstByte = buf[i]; + let codePoint = null; + let bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; + if (i + bytesPerSequence <= end) { + let secondByte, thirdByte, fourthByte, tempCodePoint; + switch(bytesPerSequence){ + case 1: + if (firstByte < 0x80) codePoint = firstByte; + break; + case 2: + secondByte = buf[i + 1]; + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F; + if (tempCodePoint > 0x7F) codePoint = tempCodePoint; + } + break; + case 3: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F; + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) codePoint = tempCodePoint; + } + break; + case 4: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + fourthByte = buf[i + 3]; + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F; + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) codePoint = tempCodePoint; + } + } + } + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD; + bytesPerSequence = 1; + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000; + res.push(codePoint >>> 10 & 0x3FF | 0xD800); + codePoint = 0xDC00 | codePoint & 0x3FF; + } + res.push(codePoint); + i += bytesPerSequence; + } + return decodeCodePointsArray(res); +} +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +const MAX_ARGUMENTS_LENGTH = 0x1000; +function decodeCodePointsArray(codePoints) { + const len = codePoints.length; + if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + ; + // Decode in chunks to avoid "call stack size exceeded". + let res = ''; + let i = 0; + while(i < len)res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); + return res; +} +function asciiSlice(buf, start, end) { + let ret = ''; + end = Math.min(buf.length, end); + for(let i = start; i < end; ++i)ret += String.fromCharCode(buf[i] & 0x7F); + return ret; +} +function latin1Slice(buf, start, end) { + let ret = ''; + end = Math.min(buf.length, end); + for(let i = start; i < end; ++i)ret += String.fromCharCode(buf[i]); + return ret; +} +function hexSlice(buf, start, end) { + const len = buf.length; + if (!start || start < 0) start = 0; + if (!end || end < 0 || end > len) end = len; + let out = ''; + for(let i = start; i < end; ++i)out += hexSliceLookupTable[buf[i]]; + return out; +} +function utf16leSlice(buf, start, end) { + const bytes = buf.slice(start, end); + let res = ''; + // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) + for(let i = 0; i < bytes.length - 1; i += 2)res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); + return res; +} +Buffer.prototype.slice = function slice(start, end) { + const len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) start = len; + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) end = len; + if (end < start) end = start; + const newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + Object.setPrototypeOf(newBuf, Buffer.prototype); + return newBuf; +}; +/* + * Need to make sure that buffer isn't trying to write out of bounds. + */ function checkOffset(offset, ext, length) { + if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); +} +Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while(++i < byteLength && (mul *= 0x100))val += this[offset + i] * mul; + return val; +}; +Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let val = this[offset + --byteLength]; + let mul = 1; + while(byteLength > 0 && (mul *= 0x100))val += this[offset + --byteLength] * mul; + return val; +}; +Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + return this[offset]; +}; +Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return this[offset] | this[offset + 1] << 8; +}; +Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return this[offset] << 8 | this[offset + 1]; +}; +Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000; +}; +Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); +}; +Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, 'offset'); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) boundsError(offset, this.length - 8); + const lo = first + this[++offset] * 256 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24; + const hi = this[++offset] + this[++offset] * 256 + this[++offset] * 2 ** 16 + last * 2 ** 24; + return BigInt(lo) + (BigInt(hi) << BigInt(32)); +}); +Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, 'offset'); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) boundsError(offset, this.length - 8); + const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 256 + this[++offset]; + const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 256 + last; + return (BigInt(hi) << BigInt(32)) + BigInt(lo); +}); +Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while(++i < byteLength && (mul *= 0x100))val += this[offset + i] * mul; + mul *= 0x80; + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + return val; +}; +Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let i = byteLength; + let mul = 1; + let val = this[offset + --i]; + while(i > 0 && (mul *= 0x100))val += this[offset + --i] * mul; + mul *= 0x80; + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + return val; +}; +Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + if (!(this[offset] & 0x80)) return this[offset]; + return (0xff - this[offset] + 1) * -1; +}; +Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + const val = this[offset] | this[offset + 1] << 8; + return val & 0x8000 ? val | 0xFFFF0000 : val; +}; +Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + const val = this[offset + 1] | this[offset] << 8; + return val & 0x8000 ? val | 0xFFFF0000 : val; +}; +Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; +}; +Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; +}; +Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, 'offset'); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) boundsError(offset, this.length - 8); + const val = this[offset + 4] + this[offset + 5] * 256 + this[offset + 6] * 2 ** 16 + (last << 24 // Overflow + ); + return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 256 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24); +}); +Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, 'offset'); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) boundsError(offset, this.length - 8); + const val = (first << 24) + // Overflow + this[++offset] * 2 ** 16 + this[++offset] * 256 + this[++offset]; + return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 256 + last); +}); +Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, true, 23, 4); +}; +Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, false, 23, 4); +}; +Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, true, 52, 8); +}; +Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, false, 52, 8); +}; +function checkInt(buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); + if (offset + ext > buf.length) throw new RangeError('Index out of range'); +} +Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + let mul = 1; + let i = 0; + this[offset] = value & 0xFF; + while(++i < byteLength && (mul *= 0x100))this[offset + i] = value / mul & 0xFF; + return offset + byteLength; +}; +Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + let i = byteLength - 1; + let mul = 1; + this[offset + i] = value & 0xFF; + while(--i >= 0 && (mul *= 0x100))this[offset + i] = value / mul & 0xFF; + return offset + byteLength; +}; +Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); + this[offset] = value & 0xff; + return offset + 1; +}; +Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + return offset + 2; +}; +Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); + this[offset] = value >>> 8; + this[offset + 1] = value & 0xff; + return offset + 2; +}; +Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); + this[offset + 3] = value >>> 24; + this[offset + 2] = value >>> 16; + this[offset + 1] = value >>> 8; + this[offset] = value & 0xff; + return offset + 4; +}; +Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 0xff; + return offset + 4; +}; +function wrtBigUInt64LE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(0xffffffff)); + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + let hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + return offset; +} +function wrtBigUInt64BE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(0xffffffff)); + buf[offset + 7] = lo; + lo = lo >> 8; + buf[offset + 6] = lo; + lo = lo >> 8; + buf[offset + 5] = lo; + lo = lo >> 8; + buf[offset + 4] = lo; + let hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); + buf[offset + 3] = hi; + hi = hi >> 8; + buf[offset + 2] = hi; + hi = hi >> 8; + buf[offset + 1] = hi; + hi = hi >> 8; + buf[offset] = hi; + return offset + 8; +} +Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); +}); +Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); +}); +Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength - 1); + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + let i = 0; + let mul = 1; + let sub = 0; + this[offset] = value & 0xFF; + while(++i < byteLength && (mul *= 0x100)){ + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) sub = 1; + this[offset + i] = (value / mul >> 0) - sub & 0xFF; + } + return offset + byteLength; +}; +Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength - 1); + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + let i = byteLength - 1; + let mul = 1; + let sub = 0; + this[offset + i] = value & 0xFF; + while(--i >= 0 && (mul *= 0x100)){ + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) sub = 1; + this[offset + i] = (value / mul >> 0) - sub & 0xFF; + } + return offset + byteLength; +}; +Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128); + if (value < 0) value = 0xff + value + 1; + this[offset] = value & 0xff; + return offset + 1; +}; +Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + return offset + 2; +}; +Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768); + this[offset] = value >>> 8; + this[offset + 1] = value & 0xff; + return offset + 2; +}; +Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + this[offset + 2] = value >>> 16; + this[offset + 3] = value >>> 24; + return offset + 4; +}; +Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648); + if (value < 0) value = 0xffffffff + value + 1; + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 0xff; + return offset + 4; +}; +Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); +}); +Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); +}); +function checkIEEE754(buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range'); + if (offset < 0) throw new RangeError('Index out of range'); +} +function writeFloat(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -340282346638528860000000000000000000000); + ieee754.write(buf, value, offset, littleEndian, 23, 4); + return offset + 4; +} +Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert); +}; +Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert); +}; +function writeDouble(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); + ieee754.write(buf, value, offset, littleEndian, 52, 8); + return offset + 8; +} +Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert); +}; +Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert); +}; +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy(target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer'); + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + // Copy 0 bytes; we're done + if (end === start) return 0; + if (target.length === 0 || this.length === 0) return 0; + // Fatal error conditions + if (targetStart < 0) throw new RangeError('targetStart out of bounds'); + if (start < 0 || start >= this.length) throw new RangeError('Index out of range'); + if (end < 0) throw new RangeError('sourceEnd out of bounds'); + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) end = target.length - targetStart + start; + const len = end - start; + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end); + else Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); + return len; +}; +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill(val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start; + start = 0; + end = this.length; + } else if (typeof end === 'string') { + encoding = end; + end = this.length; + } + if (encoding !== undefined && typeof encoding !== 'string') throw new TypeError('encoding must be a string'); + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) throw new TypeError('Unknown encoding: ' + encoding); + if (val.length === 1) { + const code = val.charCodeAt(0); + if (encoding === 'utf8' && code < 128 || encoding === 'latin1') // Fast path: If `val` fits into a single byte, use that numeric value. + val = code; + } + } else if (typeof val === 'number') val = val & 255; + else if (typeof val === 'boolean') val = Number(val); + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) throw new RangeError('Out of range index'); + if (end <= start) return this; + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + if (!val) val = 0; + let i; + if (typeof val === 'number') for(i = start; i < end; ++i)this[i] = val; + else { + const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); + const len = bytes.length; + if (len === 0) throw new TypeError('The value "' + val + '" is invalid for argument "value"'); + for(i = 0; i < end - start; ++i)this[i + start] = bytes[i % len]; + } + return this; +}; +// CUSTOM ERRORS +// ============= +// Simplified versions from Node, changed for Buffer-only usage +const errors = {}; +function E(sym, getMessage, Base) { + errors[sym] = class NodeError extends Base { + constructor(){ + super(); + Object.defineProperty(this, 'message', { + value: getMessage.apply(this, arguments), + writable: true, + configurable: true + }); + // Add the error code to the name to include it in the stack trace. + this.name = `${this.name} [${sym}]`; + // Access the stack to generate the error message including the error code + // from the name. + this.stack // eslint-disable-line no-unused-expressions + ; + // Reset the name to the actual name. + delete this.name; + } + get code() { + return sym; + } + set code(value) { + Object.defineProperty(this, 'code', { + configurable: true, + enumerable: true, + value, + writable: true + }); + } + toString() { + return `${this.name} [${sym}]: ${this.message}`; + } + }; +} +E('ERR_BUFFER_OUT_OF_BOUNDS', function(name) { + if (name) return `${name} is outside of buffer bounds`; + return 'Attempt to access memory outside buffer bounds'; +}, RangeError); +E('ERR_INVALID_ARG_TYPE', function(name, actual) { + return `The "${name}" argument must be of type number. Received type ${typeof actual}`; +}, TypeError); +E('ERR_OUT_OF_RANGE', function(str, range, input) { + let msg = `The value of "${str}" is out of range.`; + let received = input; + if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) received = addNumericalSeparator(String(input)); + else if (typeof input === 'bigint') { + received = String(input); + if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) received = addNumericalSeparator(received); + received += 'n'; + } + msg += ` It must be ${range}. Received ${received}`; + return msg; +}, RangeError); +function addNumericalSeparator(val) { + let res = ''; + let i = val.length; + const start = val[0] === '-' ? 1 : 0; + for(; i >= start + 4; i -= 3)res = `_${val.slice(i - 3, i)}${res}`; + return `${val.slice(0, i)}${res}`; +} +// CHECK FUNCTIONS +// =============== +function checkBounds(buf, offset, byteLength) { + validateNumber(offset, 'offset'); + if (buf[offset] === undefined || buf[offset + byteLength] === undefined) boundsError(offset, buf.length - (byteLength + 1)); +} +function checkIntBI(value, min, max, buf, offset, byteLength) { + if (value > max || value < min) { + const n = typeof min === 'bigint' ? 'n' : ''; + let range; + if (byteLength > 3) { + if (min === 0 || min === BigInt(0)) range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`; + else range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + `${(byteLength + 1) * 8 - 1}${n}`; + } else range = `>= ${min}${n} and <= ${max}${n}`; + throw new errors.ERR_OUT_OF_RANGE('value', range, value); + } + checkBounds(buf, offset, byteLength); +} +function validateNumber(value, name) { + if (typeof value !== 'number') throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value); +} +function boundsError(value, length, type) { + if (Math.floor(value) !== value) { + validateNumber(value, type); + throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); + } + if (length < 0) throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); + throw new errors.ERR_OUT_OF_RANGE(type || 'offset', `>= ${type ? 1 : 0} and <= ${length}`, value); +} +// HELPER FUNCTIONS +// ================ +const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; +function base64clean(str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split('=')[0]; + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = str.trim().replace(INVALID_BASE64_RE, ''); + // Node converts strings with length < 2 to '' + if (str.length < 2) return ''; + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while(str.length % 4 !== 0)str = str + '='; + return str; +} +function utf8ToBytes(string, units) { + units = units || Infinity; + let codePoint; + const length = string.length; + let leadSurrogate = null; + const bytes = []; + for(let i = 0; i < length; ++i){ + codePoint = string.charCodeAt(i); + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue; + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + continue; + } + // valid lead + leadSurrogate = codePoint; + continue; + } + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + leadSurrogate = codePoint; + continue; + } + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; + } else if (leadSurrogate) // valid bmp char, but last char was a lead + { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); + } + leadSurrogate = null; + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break; + bytes.push(codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break; + bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break; + bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break; + bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); + } else throw new Error('Invalid code point'); + } + return bytes; +} +function asciiToBytes(str) { + const byteArray = []; + for(let i = 0; i < str.length; ++i)// Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF); + return byteArray; +} +function utf16leToBytes(str, units) { + let c, hi, lo; + const byteArray = []; + for(let i = 0; i < str.length; ++i){ + if ((units -= 2) < 0) break; + c = str.charCodeAt(i); + hi = c >> 8; + lo = c % 256; + byteArray.push(lo); + byteArray.push(hi); + } + return byteArray; +} +function base64ToBytes(str) { + return base64.toByteArray(base64clean(str)); +} +function blitBuffer(src, dst, offset, length) { + let i; + for(i = 0; i < length; ++i){ + if (i + offset >= dst.length || i >= src.length) break; + dst[i + offset] = src[i]; + } + return i; +} +// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass +// the `instanceof` check but they should be treated as of that type. +// See: https://github.com/feross/buffer/issues/166 +function isInstance(obj, type) { + return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; +} +function numberIsNaN(obj) { + // For IE11 support + return obj !== obj // eslint-disable-line no-self-compare + ; +} +// Create lookup table for `toString('hex')` +// See: https://github.com/feross/buffer/issues/219 +const hexSliceLookupTable = function() { + const alphabet = '0123456789abcdef'; + const table = new Array(256); + for(let i = 0; i < 16; ++i){ + const i16 = i * 16; + for(let j = 0; j < 16; ++j)table[i16 + j] = alphabet[i] + alphabet[j]; + } + return table; +}(); +// Return not function with Error if BigInt not supported +function defineBigIntMethod(fn) { + return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn; +} +function BufferBigIntNotDefined() { + throw new Error('BigInt not supported'); +} + +},{"9c62938f1dccc73c":"7jAMi","aceacb6a4531a9d2":"hITcF"}],"7jAMi":[function(require,module,exports,__globalThis) { +'use strict'; +exports.byteLength = byteLength; +exports.toByteArray = toByteArray; +exports.fromByteArray = fromByteArray; +var lookup = []; +var revLookup = []; +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +for(var i = 0, len = code.length; i < len; ++i){ + lookup[i] = code[i]; + revLookup[code.charCodeAt(i)] = i; +} +// Support decoding URL-safe base64 strings, as Node.js does. +// See: https://en.wikipedia.org/wiki/Base64#URL_applications +revLookup['-'.charCodeAt(0)] = 62; +revLookup['_'.charCodeAt(0)] = 63; +function getLens(b64) { + var len = b64.length; + if (len % 4 > 0) throw new Error('Invalid string. Length must be a multiple of 4'); + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('='); + if (validLen === -1) validLen = len; + var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; + return [ + validLen, + placeHoldersLen + ]; +} +// base64 is 4/3 + up to two characters of the original data +function byteLength(b64) { + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; +} +function _byteLength(b64, validLen, placeHoldersLen) { + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; +} +function toByteArray(b64) { + var tmp; + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); + var curByte = 0; + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 ? validLen - 4 : validLen; + var i; + for(i = 0; i < len; i += 4){ + tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; + arr[curByte++] = tmp >> 16 & 0xFF; + arr[curByte++] = tmp >> 8 & 0xFF; + arr[curByte++] = tmp & 0xFF; + } + if (placeHoldersLen === 2) { + tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; + arr[curByte++] = tmp & 0xFF; + } + if (placeHoldersLen === 1) { + tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; + arr[curByte++] = tmp >> 8 & 0xFF; + arr[curByte++] = tmp & 0xFF; + } + return arr; +} +function tripletToBase64(num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; +} +function encodeChunk(uint8, start, end) { + var tmp; + var output = []; + for(var i = start; i < end; i += 3){ + tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF); + output.push(tripletToBase64(tmp)); + } + return output.join(''); +} +function fromByteArray(uint8) { + var tmp; + var len = uint8.length; + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + ; + var parts = []; + var maxChunkLength = 16383 // must be multiple of 3 + ; + // go through the array every three bytes, we'll deal with trailing stuff later + for(var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength)parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1]; + parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '=='); + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1]; + parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '='); + } + return parts.join(''); +} + +},{}],"hITcF":[function(require,module,exports,__globalThis) { +/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ exports.read = function(buffer, offset, isLE, mLen, nBytes) { + var e, m; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var nBits = -7; + var i = isLE ? nBytes - 1 : 0; + var d = isLE ? -1 : 1; + var s = buffer[offset + i]; + i += d; + e = s & (1 << -nBits) - 1; + s >>= -nBits; + nBits += eLen; + for(; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); + m = e & (1 << -nBits) - 1; + e >>= -nBits; + nBits += mLen; + for(; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); + if (e === 0) e = 1 - eBias; + else if (e === eMax) return m ? NaN : (s ? -1 : 1) * Infinity; + else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); +}; +exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; + var i = isLE ? 0 : nBytes - 1; + var d = isLE ? 1 : -1; + var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; + value = Math.abs(value); + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) value += rt / c; + else value += rt * Math.pow(2, 1 - eBias); + if (value * c >= 2) { + e++; + c /= 2; + } + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + for(; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); + e = e << mLen | m; + eLen += mLen; + for(; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); + buffer[offset + i - d] |= s * 128; +}; + +},{}],"gq3cc":[function(require,module,exports,__globalThis) { +// shim for using process in browser +var process = module.exports = {}; +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. +var cachedSetTimeout; +var cachedClearTimeout; +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout() { + throw new Error('clearTimeout has not been defined'); +} +(function() { + try { + if (typeof setTimeout === 'function') cachedSetTimeout = setTimeout; + else cachedSetTimeout = defaultSetTimout; + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') cachedClearTimeout = clearTimeout; + else cachedClearTimeout = defaultClearTimeout; + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +})(); +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) //normal enviroments in sane situations + return setTimeout(fun, 0); + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch (e) { + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch (e) { + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) //normal enviroments in sane situations + return clearTimeout(marker); + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e) { + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e) { + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; +function cleanUpNextTick() { + if (!draining || !currentQueue) return; + draining = false; + if (currentQueue.length) queue = currentQueue.concat(queue); + else queueIndex = -1; + if (queue.length) drainQueue(); +} +function drainQueue() { + if (draining) return; + var timeout = runTimeout(cleanUpNextTick); + draining = true; + var len = queue.length; + while(len){ + currentQueue = queue; + queue = []; + while(++queueIndex < len)if (currentQueue) currentQueue[queueIndex].run(); + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} +process.nextTick = function(fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) for(var i = 1; i < arguments.length; i++)args[i - 1] = arguments[i]; + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) runTimeout(drainQueue); +}; +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function() { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; +function noop() {} +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; +process.listeners = function(name) { + return []; +}; +process.binding = function(name) { + throw new Error('process.binding is not supported'); +}; +process.cwd = function() { + return '/'; +}; +process.chdir = function(dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { + return 0; +}; + +},{}],"eUXIe":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.VERSION = void 0; +exports.VERSION = '4.85.3'; // x-release-please-version + +},{}],"2gNIj":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports._iterSSEMessages = exports.Stream = void 0; +const index_1 = require("9bd53aa11eecfd70"); +const error_1 = require("fe8b513380654374"); +const line_1 = require("3d176cc1197c2200"); +const stream_utils_1 = require("93bb4bfe6fd365ac"); +const error_2 = require("fe8b513380654374"); +class Stream { + constructor(iterator, controller){ + this.iterator = iterator; + this.controller = controller; + } + static fromSSEResponse(response, controller) { + let consumed = false; + async function* iterator() { + if (consumed) throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.'); + consumed = true; + let done = false; + try { + for await (const sse of _iterSSEMessages(response, controller)){ + if (done) continue; + if (sse.data.startsWith('[DONE]')) { + done = true; + continue; + } + if (sse.event === null) { + let data; + try { + data = JSON.parse(sse.data); + } catch (e) { + console.error(`Could not parse message into JSON:`, sse.data); + console.error(`From chunk:`, sse.raw); + throw e; + } + if (data && data.error) throw new error_2.APIError(undefined, data.error, undefined, undefined); + yield data; + } else { + let data; + try { + data = JSON.parse(sse.data); + } catch (e) { + console.error(`Could not parse message into JSON:`, sse.data); + console.error(`From chunk:`, sse.raw); + throw e; + } + // TODO: Is this where the error should be thrown? + if (sse.event == 'error') throw new error_2.APIError(undefined, data.error, data.message, undefined); + yield { + event: sse.event, + data: data + }; + } + } + done = true; + } catch (e) { + // If the user calls `stream.controller.abort()`, we should exit without throwing. + if (e instanceof Error && e.name === 'AbortError') return; + throw e; + } finally{ + // If the user `break`s, abort the ongoing request. + if (!done) controller.abort(); + } + } + return new Stream(iterator, controller); + } + /** + * Generates a Stream from a newline-separated ReadableStream + * where each item is a JSON value. + */ static fromReadableStream(readableStream, controller) { + let consumed = false; + async function* iterLines() { + const lineDecoder = new line_1.LineDecoder(); + const iter = (0, stream_utils_1.ReadableStreamToAsyncIterable)(readableStream); + for await (const chunk of iter)for (const line of lineDecoder.decode(chunk))yield line; + for (const line of lineDecoder.flush())yield line; + } + async function* iterator() { + if (consumed) throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.'); + consumed = true; + let done = false; + try { + for await (const line of iterLines()){ + if (done) continue; + if (line) yield JSON.parse(line); + } + done = true; + } catch (e) { + // If the user calls `stream.controller.abort()`, we should exit without throwing. + if (e instanceof Error && e.name === 'AbortError') return; + throw e; + } finally{ + // If the user `break`s, abort the ongoing request. + if (!done) controller.abort(); + } + } + return new Stream(iterator, controller); + } + [Symbol.asyncIterator]() { + return this.iterator(); + } + /** + * Splits the stream into two streams which can be + * independently read from at different speeds. + */ tee() { + const left = []; + const right = []; + const iterator = this.iterator(); + const teeIterator = (queue)=>{ + return { + next: ()=>{ + if (queue.length === 0) { + const result = iterator.next(); + left.push(result); + right.push(result); + } + return queue.shift(); + } + }; + }; + return [ + new Stream(()=>teeIterator(left), this.controller), + new Stream(()=>teeIterator(right), this.controller) + ]; + } + /** + * Converts this stream to a newline-separated ReadableStream of + * JSON stringified values in the stream + * which can be turned back into a Stream with `Stream.fromReadableStream()`. + */ toReadableStream() { + const self = this; + let iter; + const encoder = new TextEncoder(); + return new index_1.ReadableStream({ + async start () { + iter = self[Symbol.asyncIterator](); + }, + async pull (ctrl) { + try { + const { value, done } = await iter.next(); + if (done) return ctrl.close(); + const bytes = encoder.encode(JSON.stringify(value) + '\n'); + ctrl.enqueue(bytes); + } catch (err) { + ctrl.error(err); + } + }, + async cancel () { + await iter.return?.(); + } + }); + } +} +exports.Stream = Stream; +async function* _iterSSEMessages(response, controller) { + if (!response.body) { + controller.abort(); + throw new error_1.OpenAIError(`Attempted to iterate over a response with no body`); + } + const sseDecoder = new SSEDecoder(); + const lineDecoder = new line_1.LineDecoder(); + const iter = (0, stream_utils_1.ReadableStreamToAsyncIterable)(response.body); + for await (const sseChunk of iterSSEChunks(iter))for (const line of lineDecoder.decode(sseChunk)){ + const sse = sseDecoder.decode(line); + if (sse) yield sse; + } + for (const line of lineDecoder.flush()){ + const sse = sseDecoder.decode(line); + if (sse) yield sse; + } +} +exports._iterSSEMessages = _iterSSEMessages; +/** + * Given an async iterable iterator, iterates over it and yields full + * SSE chunks, i.e. yields when a double new-line is encountered. + */ async function* iterSSEChunks(iterator) { + let data = new Uint8Array(); + for await (const chunk of iterator){ + if (chunk == null) continue; + const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk; + let newData = new Uint8Array(data.length + binaryChunk.length); + newData.set(data); + newData.set(binaryChunk, data.length); + data = newData; + let patternIndex; + while((patternIndex = (0, line_1.findDoubleNewlineIndex)(data)) !== -1){ + yield data.slice(0, patternIndex); + data = data.slice(patternIndex); + } + } + if (data.length > 0) yield data; +} +class SSEDecoder { + constructor(){ + this.event = null; + this.data = []; + this.chunks = []; + } + decode(line) { + if (line.endsWith('\r')) line = line.substring(0, line.length - 1); + if (!line) { + // empty line and we didn't previously encounter any messages + if (!this.event && !this.data.length) return null; + const sse = { + event: this.event, + data: this.data.join('\n'), + raw: this.chunks + }; + this.event = null; + this.data = []; + this.chunks = []; + return sse; + } + this.chunks.push(line); + if (line.startsWith(':')) return null; + let [fieldname, _, value] = partition(line, ':'); + if (value.startsWith(' ')) value = value.substring(1); + if (fieldname === 'event') this.event = value; + else if (fieldname === 'data') this.data.push(value); + return null; + } +} +function partition(str, delimiter) { + const index = str.indexOf(delimiter); + if (index !== -1) return [ + str.substring(0, index), + delimiter, + str.substring(index + delimiter.length) + ]; + return [ + str, + '', + '' + ]; +} + +},{"9bd53aa11eecfd70":"5wsSO","fe8b513380654374":"lRecV","3d176cc1197c2200":"12IvA","93bb4bfe6fd365ac":"61ifW"}],"5wsSO":[function(require,module,exports,__globalThis) { +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ const shims = require("d1179e5e38feae2b"); +const auto = require("66f73694c80f1c49"); +if (!shims.kind) shims.setShims(auto.getRuntime(), { + auto: true +}); +for (const property of Object.keys(shims))Object.defineProperty(exports, property, { + get () { + return shims[property]; + } +}); + +},{"d1179e5e38feae2b":"DQQqs","66f73694c80f1c49":"jXUlN"}],"DQQqs":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.setShims = exports.isFsReadStream = exports.fileFromPath = exports.getDefaultAgent = exports.getMultipartRequestOptions = exports.ReadableStream = exports.File = exports.Blob = exports.FormData = exports.Headers = exports.Response = exports.Request = exports.fetch = exports.kind = exports.auto = void 0; +exports.auto = false; +exports.kind = undefined; +exports.fetch = undefined; +exports.Request = undefined; +exports.Response = undefined; +exports.Headers = undefined; +exports.FormData = undefined; +exports.Blob = undefined; +exports.File = undefined; +exports.ReadableStream = undefined; +exports.getMultipartRequestOptions = undefined; +exports.getDefaultAgent = undefined; +exports.fileFromPath = undefined; +exports.isFsReadStream = undefined; +function setShims(shims, options = { + auto: false +}) { + if (exports.auto) throw new Error(`you must \`import 'openai/shims/${shims.kind}'\` before importing anything else from openai`); + if (exports.kind) throw new Error(`can't \`import 'openai/shims/${shims.kind}'\` after \`import 'openai/shims/${exports.kind}'\``); + exports.auto = options.auto; + exports.kind = shims.kind; + exports.fetch = shims.fetch; + exports.Request = shims.Request; + exports.Response = shims.Response; + exports.Headers = shims.Headers; + exports.FormData = shims.FormData; + exports.Blob = shims.Blob; + exports.File = shims.File; + exports.ReadableStream = shims.ReadableStream; + exports.getMultipartRequestOptions = shims.getMultipartRequestOptions; + exports.getDefaultAgent = shims.getDefaultAgent; + exports.fileFromPath = shims.fileFromPath; + exports.isFsReadStream = shims.isFsReadStream; +} +exports.setShims = setShims; + +},{}],"jXUlN":[function(require,module,exports,__globalThis) { +"use strict"; +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __exportStar = this && this.__exportStar || function(m, exports1) { + for(var p in m)if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports1, p)) __createBinding(exports1, m, p); +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ __exportStar(require("3766c6d390d76e30"), exports); + +},{"3766c6d390d76e30":"6FiTV"}],"6FiTV":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getRuntime = void 0; +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ const MultipartBody_1 = require("eb7448caada0e9c8"); +function getRuntime({ manuallyImported } = {}) { + const recommendation = manuallyImported ? `You may need to use polyfills` : `Add one of these imports before your first \`import \u{2026} from 'openai'\`: +- \`import 'openai/shims/node'\` (if you're running on Node) +- \`import 'openai/shims/web'\` (otherwise) +`; + let _fetch, _Request, _Response, _Headers; + try { + // @ts-ignore + _fetch = fetch; + // @ts-ignore + _Request = Request; + // @ts-ignore + _Response = Response; + // @ts-ignore + _Headers = Headers; + } catch (error) { + throw new Error(`this environment is missing the following Web Fetch API type: ${error.message}. ${recommendation}`); + } + return { + kind: 'web', + fetch: _fetch, + Request: _Request, + Response: _Response, + Headers: _Headers, + FormData: // @ts-ignore + typeof FormData !== 'undefined' ? FormData : class FormData1 { + // @ts-ignore + constructor(){ + throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${recommendation}`); + } + }, + Blob: typeof Blob !== 'undefined' ? Blob : class Blob1 { + constructor(){ + throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${recommendation}`); + } + }, + File: // @ts-ignore + typeof File !== 'undefined' ? File : class File1 { + // @ts-ignore + constructor(){ + throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${recommendation}`); + } + }, + ReadableStream: // @ts-ignore + typeof ReadableStream !== 'undefined' ? ReadableStream : class ReadableStream1 { + // @ts-ignore + constructor(){ + throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${recommendation}`); + } + }, + getMultipartRequestOptions: async (// @ts-ignore + form, opts)=>({ + ...opts, + body: new MultipartBody_1.MultipartBody(form) + }), + getDefaultAgent: (url)=>undefined, + fileFromPath: ()=>{ + throw new Error('The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/openai/openai-node#file-uploads'); + }, + isFsReadStream: (value)=>false + }; +} +exports.getRuntime = getRuntime; + +},{"eb7448caada0e9c8":"gKM2D"}],"gKM2D":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.MultipartBody = void 0; +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ class MultipartBody { + constructor(body){ + this.body = body; + } + get [Symbol.toStringTag]() { + return 'MultipartBody'; + } +} +exports.MultipartBody = MultipartBody; + +},{}],"lRecV":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ContentFilterFinishReasonError = exports.LengthFinishReasonError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.OpenAIError = void 0; +const core_1 = require("f2afcf7da896f8b4"); +class OpenAIError extends Error { +} +exports.OpenAIError = OpenAIError; +class APIError extends OpenAIError { + constructor(status, error, message, headers){ + super(`${APIError.makeMessage(status, error, message)}`); + this.status = status; + this.headers = headers; + this.request_id = headers?.['x-request-id']; + this.error = error; + const data = error; + this.code = data?.['code']; + this.param = data?.['param']; + this.type = data?.['type']; + } + static makeMessage(status, error, message) { + const msg = error?.message ? typeof error.message === 'string' ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message; + if (status && msg) return `${status} ${msg}`; + if (status) return `${status} status code (no body)`; + if (msg) return msg; + return '(no status code or body)'; + } + static generate(status, errorResponse, message, headers) { + if (!status || !headers) return new APIConnectionError({ + message, + cause: (0, core_1.castToError)(errorResponse) + }); + const error = errorResponse?.['error']; + if (status === 400) return new BadRequestError(status, error, message, headers); + if (status === 401) return new AuthenticationError(status, error, message, headers); + if (status === 403) return new PermissionDeniedError(status, error, message, headers); + if (status === 404) return new NotFoundError(status, error, message, headers); + if (status === 409) return new ConflictError(status, error, message, headers); + if (status === 422) return new UnprocessableEntityError(status, error, message, headers); + if (status === 429) return new RateLimitError(status, error, message, headers); + if (status >= 500) return new InternalServerError(status, error, message, headers); + return new APIError(status, error, message, headers); + } +} +exports.APIError = APIError; +class APIUserAbortError extends APIError { + constructor({ message } = {}){ + super(undefined, undefined, message || 'Request was aborted.', undefined); + } +} +exports.APIUserAbortError = APIUserAbortError; +class APIConnectionError extends APIError { + constructor({ message, cause }){ + super(undefined, undefined, message || 'Connection error.', undefined); + // in some environments the 'cause' property is already declared + // @ts-ignore + if (cause) this.cause = cause; + } +} +exports.APIConnectionError = APIConnectionError; +class APIConnectionTimeoutError extends APIConnectionError { + constructor({ message } = {}){ + super({ + message: message ?? 'Request timed out.' + }); + } +} +exports.APIConnectionTimeoutError = APIConnectionTimeoutError; +class BadRequestError extends APIError { +} +exports.BadRequestError = BadRequestError; +class AuthenticationError extends APIError { +} +exports.AuthenticationError = AuthenticationError; +class PermissionDeniedError extends APIError { +} +exports.PermissionDeniedError = PermissionDeniedError; +class NotFoundError extends APIError { +} +exports.NotFoundError = NotFoundError; +class ConflictError extends APIError { +} +exports.ConflictError = ConflictError; +class UnprocessableEntityError extends APIError { +} +exports.UnprocessableEntityError = UnprocessableEntityError; +class RateLimitError extends APIError { +} +exports.RateLimitError = RateLimitError; +class InternalServerError extends APIError { +} +exports.InternalServerError = InternalServerError; +class LengthFinishReasonError extends OpenAIError { + constructor(){ + super(`Could not parse response content as the length limit was reached`); + } +} +exports.LengthFinishReasonError = LengthFinishReasonError; +class ContentFilterFinishReasonError extends OpenAIError { + constructor(){ + super(`Could not parse response content as the request was rejected by the content filter`); + } +} +exports.ContentFilterFinishReasonError = ContentFilterFinishReasonError; + +},{"f2afcf7da896f8b4":"haosB"}],"12IvA":[function(require,module,exports,__globalThis) { +var Buffer = require("2ee39b924adb6ad4").Buffer; +"use strict"; +var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function(receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; +}; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _LineDecoder_carriageReturnIndex; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.findDoubleNewlineIndex = exports.LineDecoder = void 0; +const error_1 = require("bb3a4eee6c6836e8"); +/** + * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally + * reading lines from text. + * + * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258 + */ class LineDecoder { + constructor(){ + _LineDecoder_carriageReturnIndex.set(this, void 0); + this.buffer = new Uint8Array(); + __classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f"); + } + decode(chunk) { + if (chunk == null) return []; + const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk; + let newData = new Uint8Array(this.buffer.length + binaryChunk.length); + newData.set(this.buffer); + newData.set(binaryChunk, this.buffer.length); + this.buffer = newData; + const lines = []; + let patternIndex; + while((patternIndex = findNewlineIndex(this.buffer, __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f"))) != null){ + if (patternIndex.carriage && __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") == null) { + // skip until we either get a corresponding `\n`, a new `\r` or nothing + __classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, patternIndex.index, "f"); + continue; + } + // we got double \r or \rtext\n + if (__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") != null && (patternIndex.index !== __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") + 1 || patternIndex.carriage)) { + lines.push(this.decodeText(this.buffer.slice(0, __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") - 1))); + this.buffer = this.buffer.slice(__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f")); + __classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f"); + continue; + } + const endIndex = __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") !== null ? patternIndex.preceding - 1 : patternIndex.preceding; + const line = this.decodeText(this.buffer.slice(0, endIndex)); + lines.push(line); + this.buffer = this.buffer.slice(patternIndex.index); + __classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f"); + } + return lines; + } + decodeText(bytes) { + if (bytes == null) return ''; + if (typeof bytes === 'string') return bytes; + // Node: + if (typeof Buffer !== 'undefined') { + if (bytes instanceof Buffer) return bytes.toString(); + if (bytes instanceof Uint8Array) return Buffer.from(bytes).toString(); + throw new error_1.OpenAIError(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`); + } + // Browser + if (typeof TextDecoder !== 'undefined') { + if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) { + this.textDecoder ?? (this.textDecoder = new TextDecoder('utf8')); + return this.textDecoder.decode(bytes); + } + throw new error_1.OpenAIError(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`); + } + throw new error_1.OpenAIError(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`); + } + flush() { + if (!this.buffer.length) return []; + return this.decode('\n'); + } +} +exports.LineDecoder = LineDecoder; +_LineDecoder_carriageReturnIndex = new WeakMap(); +// prettier-ignore +LineDecoder.NEWLINE_CHARS = new Set([ + '\n', + '\r' +]); +LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g; +/** + * This function searches the buffer for the end patterns, (\r or \n) + * and returns an object with the index preceding the matched newline and the + * index after the newline char. `null` is returned if no new line is found. + * + * ```ts + * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 } + * ``` + */ function findNewlineIndex(buffer, startIndex) { + const newline = 0x0a; // \n + const carriage = 0x0d; // \r + for(let i = startIndex ?? 0; i < buffer.length; i++){ + if (buffer[i] === newline) return { + preceding: i, + index: i + 1, + carriage: false + }; + if (buffer[i] === carriage) return { + preceding: i, + index: i + 1, + carriage: true + }; + } + return null; +} +function findDoubleNewlineIndex(buffer) { + // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n) + // and returns the index right after the first occurrence of any pattern, + // or -1 if none of the patterns are found. + const newline = 0x0a; // \n + const carriage = 0x0d; // \r + for(let i = 0; i < buffer.length - 1; i++){ + if (buffer[i] === newline && buffer[i + 1] === newline) // \n\n + return i + 2; + if (buffer[i] === carriage && buffer[i + 1] === carriage) // \r\r + return i + 2; + if (buffer[i] === carriage && buffer[i + 1] === newline && i + 3 < buffer.length && buffer[i + 2] === carriage && buffer[i + 3] === newline) // \r\n\r\n + return i + 4; + } + return -1; +} +exports.findDoubleNewlineIndex = findDoubleNewlineIndex; + +},{"2ee39b924adb6ad4":"6tQNr","bb3a4eee6c6836e8":"lRecV"}],"61ifW":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ReadableStreamToAsyncIterable = void 0; +/** + * Most browsers don't yet have async iterable support for ReadableStream, + * and Node has a very different way of reading bytes from its "ReadableStream". + * + * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490 + */ function ReadableStreamToAsyncIterable(stream) { + if (stream[Symbol.asyncIterator]) return stream; + const reader = stream.getReader(); + return { + async next () { + try { + const result = await reader.read(); + if (result?.done) reader.releaseLock(); // release lock when stream becomes closed + return result; + } catch (e) { + reader.releaseLock(); // release lock when stream becomes errored + throw e; + } + }, + async return () { + const cancelPromise = reader.cancel(); + reader.releaseLock(); + await cancelPromise; + return { + done: true, + value: undefined + }; + }, + [Symbol.asyncIterator] () { + return this; + } + }; +} +exports.ReadableStreamToAsyncIterable = ReadableStreamToAsyncIterable; + +},{}],"jcDgx":[function(require,module,exports,__globalThis) { +var Buffer = require("c36b36da7e5ab93").Buffer; +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.isMultipartBody = exports.toFile = exports.isUploadable = exports.isBlobLike = exports.isFileLike = exports.isResponseLike = exports.fileFromPath = void 0; +const index_1 = require("ca38cd3b898920cd"); +var index_2 = require("ca38cd3b898920cd"); +Object.defineProperty(exports, "fileFromPath", { + enumerable: true, + get: function() { + return index_2.fileFromPath; + } +}); +const isResponseLike = (value)=>value != null && typeof value === 'object' && typeof value.url === 'string' && typeof value.blob === 'function'; +exports.isResponseLike = isResponseLike; +const isFileLike = (value)=>value != null && typeof value === 'object' && typeof value.name === 'string' && typeof value.lastModified === 'number' && (0, exports.isBlobLike)(value); +exports.isFileLike = isFileLike; +/** + * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check + * adds the arrayBuffer() method type because it is available and used at runtime + */ const isBlobLike = (value)=>value != null && typeof value === 'object' && typeof value.size === 'number' && typeof value.type === 'string' && typeof value.text === 'function' && typeof value.slice === 'function' && typeof value.arrayBuffer === 'function'; +exports.isBlobLike = isBlobLike; +const isUploadable = (value)=>{ + return (0, exports.isFileLike)(value) || (0, exports.isResponseLike)(value) || (0, index_1.isFsReadStream)(value); +}; +exports.isUploadable = isUploadable; +/** + * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats + * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s + * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible + * @param {Object=} options additional properties + * @param {string=} options.type the MIME type of the content + * @param {number=} options.lastModified the last modified timestamp + * @returns a {@link File} with the given properties + */ async function toFile(value, name, options) { + // If it's a promise, resolve it. + value = await value; + // If we've been given a `File` we don't need to do anything + if ((0, exports.isFileLike)(value)) return value; + if ((0, exports.isResponseLike)(value)) { + const blob = await value.blob(); + name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file'); + // we need to convert the `Blob` into an array buffer because the `Blob` class + // that `node-fetch` defines is incompatible with the web standard which results + // in `new File` interpreting it as a string instead of binary data. + const data = (0, exports.isBlobLike)(blob) ? [ + await blob.arrayBuffer() + ] : [ + blob + ]; + return new index_1.File(data, name, options); + } + const bits = await getBytes(value); + name || (name = getName(value) ?? 'unknown_file'); + if (!options?.type) { + const type = bits[0]?.type; + if (typeof type === 'string') options = { + ...options, + type + }; + } + return new index_1.File(bits, name, options); +} +exports.toFile = toFile; +async function getBytes(value) { + let parts = []; + if (typeof value === 'string' || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc. + value instanceof ArrayBuffer) parts.push(value); + else if ((0, exports.isBlobLike)(value)) parts.push(await value.arrayBuffer()); + else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc. + ) for await (const chunk of value)parts.push(chunk); // TODO, consider validating? + else throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`); + return parts; +} +function propsForError(value) { + const props = Object.getOwnPropertyNames(value); + return `[${props.map((p)=>`"${p}"`).join(', ')}]`; +} +function getName(value) { + return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream + getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop(); +} +const getStringFromMaybeBuffer = (x)=>{ + if (typeof x === 'string') return x; + if (typeof Buffer !== 'undefined' && x instanceof Buffer) return String(x); + return undefined; +}; +const isAsyncIterableIterator = (value)=>value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function'; +const isMultipartBody = (body)=>body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody'; +exports.isMultipartBody = isMultipartBody; +/** + * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value. + * Otherwise returns the request as is. + */ const maybeMultipartFormRequestOptions = async (opts)=>{ + if (!hasUploadableValue(opts.body)) return opts; + const form = await (0, exports.createForm)(opts.body); + return (0, index_1.getMultipartRequestOptions)(form, opts); +}; +exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions; +const multipartFormRequestOptions = async (opts)=>{ + const form = await (0, exports.createForm)(opts.body); + return (0, index_1.getMultipartRequestOptions)(form, opts); +}; +exports.multipartFormRequestOptions = multipartFormRequestOptions; +const createForm = async (body)=>{ + const form = new index_1.FormData(); + await Promise.all(Object.entries(body || {}).map(([key, value])=>addFormValue(form, key, value))); + return form; +}; +exports.createForm = createForm; +const hasUploadableValue = (value)=>{ + if ((0, exports.isUploadable)(value)) return true; + if (Array.isArray(value)) return value.some(hasUploadableValue); + if (value && typeof value === 'object') for(const k in value){ + if (hasUploadableValue(value[k])) return true; + } + return false; +}; +const addFormValue = async (form, key, value)=>{ + if (value === undefined) return; + if (value == null) throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`); + // TODO: make nested formats configurable + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') form.append(key, String(value)); + else if ((0, exports.isUploadable)(value)) { + const file = await toFile(value); + form.append(key, file); + } else if (Array.isArray(value)) await Promise.all(value.map((entry)=>addFormValue(form, key + '[]', entry))); + else if (typeof value === 'object') await Promise.all(Object.entries(value).map(([name, prop])=>addFormValue(form, `${key}[${name}]`, prop))); + else throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`); +}; + +},{"c36b36da7e5ab93":"6tQNr","ca38cd3b898920cd":"5wsSO"}],"jePq8":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.CursorPage = exports.Page = void 0; +const core_1 = require("a38ae428231f51d7"); +/** + * Note: no pagination actually occurs yet, this is for forwards-compatibility. + */ class Page extends core_1.AbstractPage { + constructor(client, response, body, options){ + super(client, response, body, options); + this.data = body.data || []; + this.object = body.object; + } + getPaginatedItems() { + return this.data ?? []; + } + // @deprecated Please use `nextPageInfo()` instead + /** + * This page represents a response that isn't actually paginated at the API level + * so there will never be any next page params. + */ nextPageParams() { + return null; + } + nextPageInfo() { + return null; + } +} +exports.Page = Page; +class CursorPage extends core_1.AbstractPage { + constructor(client, response, body, options){ + super(client, response, body, options); + this.data = body.data || []; + this.has_more = body.has_more || false; + } + getPaginatedItems() { + return this.data ?? []; + } + hasNextPage() { + if (this.has_more === false) return false; + return super.hasNextPage(); + } + // @deprecated Please use `nextPageInfo()` instead + nextPageParams() { + const info = this.nextPageInfo(); + if (!info) return null; + if ('params' in info) return info.params; + const params = Object.fromEntries(info.url.searchParams); + if (!Object.keys(params).length) return null; + return params; + } + nextPageInfo() { + const data = this.getPaginatedItems(); + if (!data.length) return null; + const id = data[data.length - 1]?.id; + if (!id) return null; + return { + params: { + after: id + } + }; + } +} +exports.CursorPage = CursorPage; + +},{"a38ae428231f51d7":"haosB"}],"7j2pI":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __exportStar = this && this.__exportStar || function(m, exports1) { + for(var p in m)if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports1, p)) __createBinding(exports1, m, p); +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Uploads = exports.Moderations = exports.Models = exports.ModelsPage = exports.Images = exports.FineTuning = exports.Files = exports.FileObjectsPage = exports.Embeddings = exports.Completions = exports.Beta = exports.Batches = exports.BatchesPage = exports.Audio = void 0; +__exportStar(require("db5d3f46926db1e"), exports); +__exportStar(require("8d56f186c9937308"), exports); +var audio_1 = require("e9d5d4827ddce03f"); +Object.defineProperty(exports, "Audio", { + enumerable: true, + get: function() { + return audio_1.Audio; + } +}); +var batches_1 = require("5b56a759c4dfb62d"); +Object.defineProperty(exports, "BatchesPage", { + enumerable: true, + get: function() { + return batches_1.BatchesPage; + } +}); +Object.defineProperty(exports, "Batches", { + enumerable: true, + get: function() { + return batches_1.Batches; + } +}); +var beta_1 = require("46a4dba1ae7eedd7"); +Object.defineProperty(exports, "Beta", { + enumerable: true, + get: function() { + return beta_1.Beta; + } +}); +var completions_1 = require("cef4ba4fe9ff9765"); +Object.defineProperty(exports, "Completions", { + enumerable: true, + get: function() { + return completions_1.Completions; + } +}); +var embeddings_1 = require("f12c849f81a42b81"); +Object.defineProperty(exports, "Embeddings", { + enumerable: true, + get: function() { + return embeddings_1.Embeddings; + } +}); +var files_1 = require("6e52071044c45f56"); +Object.defineProperty(exports, "FileObjectsPage", { + enumerable: true, + get: function() { + return files_1.FileObjectsPage; + } +}); +Object.defineProperty(exports, "Files", { + enumerable: true, + get: function() { + return files_1.Files; + } +}); +var fine_tuning_1 = require("a24aa51ebba8c7c6"); +Object.defineProperty(exports, "FineTuning", { + enumerable: true, + get: function() { + return fine_tuning_1.FineTuning; + } +}); +var images_1 = require("a7ed61e46373ac5"); +Object.defineProperty(exports, "Images", { + enumerable: true, + get: function() { + return images_1.Images; + } +}); +var models_1 = require("b0389608b66e2ec9"); +Object.defineProperty(exports, "ModelsPage", { + enumerable: true, + get: function() { + return models_1.ModelsPage; + } +}); +Object.defineProperty(exports, "Models", { + enumerable: true, + get: function() { + return models_1.Models; + } +}); +var moderations_1 = require("267f9aea607efa7b"); +Object.defineProperty(exports, "Moderations", { + enumerable: true, + get: function() { + return moderations_1.Moderations; + } +}); +var uploads_1 = require("e9f29bec3c13872e"); +Object.defineProperty(exports, "Uploads", { + enumerable: true, + get: function() { + return uploads_1.Uploads; + } +}); + +},{"db5d3f46926db1e":"7PqYd","8d56f186c9937308":"j9eNz","e9d5d4827ddce03f":"6HUeV","5b56a759c4dfb62d":"i3zsm","46a4dba1ae7eedd7":"4YBCL","cef4ba4fe9ff9765":"cig5h","f12c849f81a42b81":"5Emd7","6e52071044c45f56":"jXD91","a24aa51ebba8c7c6":"gt3GR","a7ed61e46373ac5":"sbLkY","b0389608b66e2ec9":"hGG1e","267f9aea607efa7b":"53MBP","e9f29bec3c13872e":"1T47D"}],"7PqYd":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Completions = exports.ChatCompletionsPage = exports.ChatCompletionStoreMessagesPage = exports.Chat = void 0; +var chat_1 = require("a046273e7b6e1ea3"); +Object.defineProperty(exports, "Chat", { + enumerable: true, + get: function() { + return chat_1.Chat; + } +}); +var index_1 = require("65b7dba8dc49941c"); +Object.defineProperty(exports, "ChatCompletionStoreMessagesPage", { + enumerable: true, + get: function() { + return index_1.ChatCompletionStoreMessagesPage; + } +}); +Object.defineProperty(exports, "ChatCompletionsPage", { + enumerable: true, + get: function() { + return index_1.ChatCompletionsPage; + } +}); +Object.defineProperty(exports, "Completions", { + enumerable: true, + get: function() { + return index_1.Completions; + } +}); + +},{"a046273e7b6e1ea3":"1Oy6q","65b7dba8dc49941c":"gTSFX"}],"1Oy6q":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Chat = void 0; +const resource_1 = require("1a28e00a0944884f"); +const CompletionsAPI = __importStar(require("40a89af9ec10b6ff")); +const completions_1 = require("40a89af9ec10b6ff"); +class Chat extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.completions = new CompletionsAPI.Completions(this._client); + } +} +exports.Chat = Chat; +Chat.Completions = completions_1.Completions; +Chat.ChatCompletionsPage = completions_1.ChatCompletionsPage; + +},{"1a28e00a0944884f":"kPMwm","40a89af9ec10b6ff":"5LC9N"}],"kPMwm":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.APIResource = void 0; +class APIResource { + constructor(client){ + this._client = client; + } +} +exports.APIResource = APIResource; + +},{}],"5LC9N":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ChatCompletionStoreMessagesPage = exports.ChatCompletionsPage = exports.Completions = void 0; +const resource_1 = require("7de6a0e6f9ef1c1d"); +const core_1 = require("3ada332fe7f91d94"); +const MessagesAPI = __importStar(require("9de068d6f2125b2a")); +const messages_1 = require("9de068d6f2125b2a"); +const pagination_1 = require("b739a060daeedfed"); +class Completions extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.messages = new MessagesAPI.Messages(this._client); + } + create(body, options) { + return this._client.post('/chat/completions', { + body, + ...options, + stream: body.stream ?? false + }); + } + /** + * Get a stored chat completion. Only chat completions that have been created with + * the `store` parameter set to `true` will be returned. + */ retrieve(completionId, options) { + return this._client.get(`/chat/completions/${completionId}`, options); + } + /** + * Modify a stored chat completion. Only chat completions that have been created + * with the `store` parameter set to `true` can be modified. Currently, the only + * supported modification is to update the `metadata` field. + */ update(completionId, body, options) { + return this._client.post(`/chat/completions/${completionId}`, { + body, + ...options + }); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { + query, + ...options + }); + } + /** + * Delete a stored chat completion. Only chat completions that have been created + * with the `store` parameter set to `true` can be deleted. + */ del(completionId, options) { + return this._client.delete(`/chat/completions/${completionId}`, options); + } +} +exports.Completions = Completions; +class ChatCompletionsPage extends pagination_1.CursorPage { +} +exports.ChatCompletionsPage = ChatCompletionsPage; +class ChatCompletionStoreMessagesPage extends pagination_1.CursorPage { +} +exports.ChatCompletionStoreMessagesPage = ChatCompletionStoreMessagesPage; +Completions.ChatCompletionsPage = ChatCompletionsPage; +Completions.Messages = messages_1.Messages; + +},{"7de6a0e6f9ef1c1d":"kPMwm","3ada332fe7f91d94":"haosB","9de068d6f2125b2a":"9ycEI","b739a060daeedfed":"jePq8"}],"9ycEI":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ChatCompletionStoreMessagesPage = exports.Messages = void 0; +const resource_1 = require("5097755c770a63a3"); +const core_1 = require("658874ec3f8ff4d7"); +const completions_1 = require("9249c2782f6b55e7"); +Object.defineProperty(exports, "ChatCompletionStoreMessagesPage", { + enumerable: true, + get: function() { + return completions_1.ChatCompletionStoreMessagesPage; + } +}); +class Messages extends resource_1.APIResource { + list(completionId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(completionId, {}, query); + return this._client.getAPIList(`/chat/completions/${completionId}/messages`, completions_1.ChatCompletionStoreMessagesPage, { + query, + ...options + }); + } +} +exports.Messages = Messages; + +},{"5097755c770a63a3":"kPMwm","658874ec3f8ff4d7":"haosB","9249c2782f6b55e7":"5LC9N"}],"gTSFX":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Messages = exports.Completions = exports.ChatCompletionsPage = exports.ChatCompletionStoreMessagesPage = void 0; +var completions_1 = require("126cc96e5af31361"); +Object.defineProperty(exports, "ChatCompletionStoreMessagesPage", { + enumerable: true, + get: function() { + return completions_1.ChatCompletionStoreMessagesPage; + } +}); +Object.defineProperty(exports, "ChatCompletionsPage", { + enumerable: true, + get: function() { + return completions_1.ChatCompletionsPage; + } +}); +Object.defineProperty(exports, "Completions", { + enumerable: true, + get: function() { + return completions_1.Completions; + } +}); +var messages_1 = require("7a73ba5da4c553ec"); +Object.defineProperty(exports, "Messages", { + enumerable: true, + get: function() { + return messages_1.Messages; + } +}); + +},{"126cc96e5af31361":"5LC9N","7a73ba5da4c553ec":"9ycEI"}],"j9eNz":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); + +},{}],"6HUeV":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Audio = void 0; +const resource_1 = require("dfb731ecc1f82f92"); +const SpeechAPI = __importStar(require("ac19f3db1f8fd0ee")); +const speech_1 = require("ac19f3db1f8fd0ee"); +const TranscriptionsAPI = __importStar(require("b20775e3c803ba90")); +const transcriptions_1 = require("b20775e3c803ba90"); +const TranslationsAPI = __importStar(require("d44d4341ed12b7cf")); +const translations_1 = require("d44d4341ed12b7cf"); +class Audio extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.transcriptions = new TranscriptionsAPI.Transcriptions(this._client); + this.translations = new TranslationsAPI.Translations(this._client); + this.speech = new SpeechAPI.Speech(this._client); + } +} +exports.Audio = Audio; +Audio.Transcriptions = transcriptions_1.Transcriptions; +Audio.Translations = translations_1.Translations; +Audio.Speech = speech_1.Speech; + +},{"dfb731ecc1f82f92":"kPMwm","ac19f3db1f8fd0ee":"jxHXP","b20775e3c803ba90":"2ZGwI","d44d4341ed12b7cf":"3hJXz"}],"jxHXP":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Speech = void 0; +const resource_1 = require("aec390f02bbb0223"); +class Speech extends resource_1.APIResource { + /** + * Generates audio from the input text. + */ create(body, options) { + return this._client.post('/audio/speech', { + body, + ...options, + headers: { + Accept: 'application/octet-stream', + ...options?.headers + }, + __binaryResponse: true + }); + } +} +exports.Speech = Speech; + +},{"aec390f02bbb0223":"kPMwm"}],"2ZGwI":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Transcriptions = void 0; +const resource_1 = require("f3f926130cfec2f6"); +const Core = __importStar(require("fae742b648cb18d4")); +class Transcriptions extends resource_1.APIResource { + create(body, options) { + return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ + body, + ...options, + __metadata: { + model: body.model + } + })); + } +} +exports.Transcriptions = Transcriptions; + +},{"f3f926130cfec2f6":"kPMwm","fae742b648cb18d4":"haosB"}],"3hJXz":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Translations = void 0; +const resource_1 = require("5fc7fcae8666332"); +const Core = __importStar(require("8be6480449074f16")); +class Translations extends resource_1.APIResource { + create(body, options) { + return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ + body, + ...options, + __metadata: { + model: body.model + } + })); + } +} +exports.Translations = Translations; + +},{"5fc7fcae8666332":"kPMwm","8be6480449074f16":"haosB"}],"i3zsm":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.BatchesPage = exports.Batches = void 0; +const resource_1 = require("82235ffda2195b13"); +const core_1 = require("a3de6ce932b7d3c1"); +const pagination_1 = require("e6a6b913369be19e"); +class Batches extends resource_1.APIResource { + /** + * Creates and executes a batch from an uploaded file of requests + */ create(body, options) { + return this._client.post('/batches', { + body, + ...options + }); + } + /** + * Retrieves a batch. + */ retrieve(batchId, options) { + return this._client.get(`/batches/${batchId}`, options); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/batches', BatchesPage, { + query, + ...options + }); + } + /** + * Cancels an in-progress batch. The batch will be in status `cancelling` for up to + * 10 minutes, before changing to `cancelled`, where it will have partial results + * (if any) available in the output file. + */ cancel(batchId, options) { + return this._client.post(`/batches/${batchId}/cancel`, options); + } +} +exports.Batches = Batches; +class BatchesPage extends pagination_1.CursorPage { +} +exports.BatchesPage = BatchesPage; +Batches.BatchesPage = BatchesPage; + +},{"82235ffda2195b13":"kPMwm","a3de6ce932b7d3c1":"haosB","e6a6b913369be19e":"jePq8"}],"4YBCL":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Beta = void 0; +const resource_1 = require("939b58fda1e6aacd"); +const AssistantsAPI = __importStar(require("6c6a7be4af63c9a7")); +const ChatAPI = __importStar(require("756121247d1b456")); +const assistants_1 = require("6c6a7be4af63c9a7"); +const RealtimeAPI = __importStar(require("58ef51f0c209ac15")); +const realtime_1 = require("58ef51f0c209ac15"); +const ThreadsAPI = __importStar(require("d9b62b34f4f2cad2")); +const threads_1 = require("d9b62b34f4f2cad2"); +const VectorStoresAPI = __importStar(require("6ddd8517a1f23f80")); +const vector_stores_1 = require("6ddd8517a1f23f80"); +const chat_1 = require("756121247d1b456"); +class Beta extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.realtime = new RealtimeAPI.Realtime(this._client); + this.vectorStores = new VectorStoresAPI.VectorStores(this._client); + this.chat = new ChatAPI.Chat(this._client); + this.assistants = new AssistantsAPI.Assistants(this._client); + this.threads = new ThreadsAPI.Threads(this._client); + } +} +exports.Beta = Beta; +Beta.Realtime = realtime_1.Realtime; +Beta.VectorStores = vector_stores_1.VectorStores; +Beta.VectorStoresPage = vector_stores_1.VectorStoresPage; +Beta.Assistants = assistants_1.Assistants; +Beta.AssistantsPage = assistants_1.AssistantsPage; +Beta.Threads = threads_1.Threads; + +},{"939b58fda1e6aacd":"kPMwm","6c6a7be4af63c9a7":"8rdVi","756121247d1b456":"jxdyA","58ef51f0c209ac15":"j8ba6","d9b62b34f4f2cad2":"fHMCJ","6ddd8517a1f23f80":"jSaPI"}],"8rdVi":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.AssistantsPage = exports.Assistants = void 0; +const resource_1 = require("e3a59108f5ab9a4c"); +const core_1 = require("3d608d4299650018"); +const pagination_1 = require("f063ea69006300f9"); +class Assistants extends resource_1.APIResource { + /** + * Create an assistant with a model and instructions. + */ create(body, options) { + return this._client.post('/assistants', { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieves an assistant. + */ retrieve(assistantId, options) { + return this._client.get(`/assistants/${assistantId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Modifies an assistant. + */ update(assistantId, body, options) { + return this._client.post(`/assistants/${assistantId}`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/assistants', AssistantsPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Delete an assistant. + */ del(assistantId, options) { + return this._client.delete(`/assistants/${assistantId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } +} +exports.Assistants = Assistants; +class AssistantsPage extends pagination_1.CursorPage { +} +exports.AssistantsPage = AssistantsPage; +Assistants.AssistantsPage = AssistantsPage; + +},{"e3a59108f5ab9a4c":"kPMwm","3d608d4299650018":"haosB","f063ea69006300f9":"jePq8"}],"jxdyA":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Chat = void 0; +const resource_1 = require("6fdbda68af8fd193"); +const CompletionsAPI = __importStar(require("83c180094f5f2448")); +class Chat extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.completions = new CompletionsAPI.Completions(this._client); + } +} +exports.Chat = Chat; +(function(Chat) { + Chat.Completions = CompletionsAPI.Completions; +})(Chat = exports.Chat || (exports.Chat = {})); + +},{"6fdbda68af8fd193":"kPMwm","83c180094f5f2448":"32MnD"}],"32MnD":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Completions = exports.ChatCompletionRunner = exports.ChatCompletionStream = exports.ParsingToolFunction = exports.ParsingFunction = exports.ChatCompletionStreamingRunner = void 0; +const resource_1 = require("60b229b9e8d62f6c"); +const ChatCompletionRunner_1 = require("bd1709770a117b5b"); +const ChatCompletionStreamingRunner_1 = require("6a8af0be2bb53b63"); +const ChatCompletionStream_1 = require("b089ea201a13fc20"); +const parser_1 = require("471f8ad19861ab31"); +var ChatCompletionStreamingRunner_2 = require("6a8af0be2bb53b63"); +Object.defineProperty(exports, "ChatCompletionStreamingRunner", { + enumerable: true, + get: function() { + return ChatCompletionStreamingRunner_2.ChatCompletionStreamingRunner; + } +}); +var RunnableFunction_1 = require("29358d3ea6dcd5ea"); +Object.defineProperty(exports, "ParsingFunction", { + enumerable: true, + get: function() { + return RunnableFunction_1.ParsingFunction; + } +}); +Object.defineProperty(exports, "ParsingToolFunction", { + enumerable: true, + get: function() { + return RunnableFunction_1.ParsingToolFunction; + } +}); +var ChatCompletionStream_2 = require("b089ea201a13fc20"); +Object.defineProperty(exports, "ChatCompletionStream", { + enumerable: true, + get: function() { + return ChatCompletionStream_2.ChatCompletionStream; + } +}); +var ChatCompletionRunner_2 = require("bd1709770a117b5b"); +Object.defineProperty(exports, "ChatCompletionRunner", { + enumerable: true, + get: function() { + return ChatCompletionRunner_2.ChatCompletionRunner; + } +}); +class Completions extends resource_1.APIResource { + parse(body, options) { + (0, parser_1.validateInputTools)(body.tools); + return this._client.chat.completions.create(body, { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'beta.chat.completions.parse' + } + })._thenUnwrap((completion)=>(0, parser_1.parseChatCompletion)(completion, body)); + } + runFunctions(body, options) { + if (body.stream) return ChatCompletionStreamingRunner_1.ChatCompletionStreamingRunner.runFunctions(this._client, body, options); + return ChatCompletionRunner_1.ChatCompletionRunner.runFunctions(this._client, body, options); + } + runTools(body, options) { + if (body.stream) return ChatCompletionStreamingRunner_1.ChatCompletionStreamingRunner.runTools(this._client, body, options); + return ChatCompletionRunner_1.ChatCompletionRunner.runTools(this._client, body, options); + } + /** + * Creates a chat completion stream + */ stream(body, options) { + return ChatCompletionStream_1.ChatCompletionStream.createChatCompletion(this._client, body, options); + } +} +exports.Completions = Completions; + +},{"60b229b9e8d62f6c":"kPMwm","bd1709770a117b5b":"bJ8Dk","6a8af0be2bb53b63":"fqtsj","b089ea201a13fc20":"8L9Cr","471f8ad19861ab31":"gZPwj","29358d3ea6dcd5ea":"9PsV8"}],"bJ8Dk":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ChatCompletionRunner = void 0; +const AbstractChatCompletionRunner_1 = require("2647c005cf948bd9"); +const chatCompletionUtils_1 = require("89f381d1f373f6b6"); +class ChatCompletionRunner extends AbstractChatCompletionRunner_1.AbstractChatCompletionRunner { + /** @deprecated - please use `runTools` instead. */ static runFunctions(client, params, options) { + const runner = new ChatCompletionRunner(); + const opts = { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'runFunctions' + } + }; + runner._run(()=>runner._runFunctions(client, params, opts)); + return runner; + } + static runTools(client, params, options) { + const runner = new ChatCompletionRunner(); + const opts = { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'runTools' + } + }; + runner._run(()=>runner._runTools(client, params, opts)); + return runner; + } + _addMessage(message, emit = true) { + super._addMessage(message, emit); + if ((0, chatCompletionUtils_1.isAssistantMessage)(message) && message.content) this._emit('content', message.content); + } +} +exports.ChatCompletionRunner = ChatCompletionRunner; + +},{"2647c005cf948bd9":"6IJye","89f381d1f373f6b6":"1BcC2"}],"6IJye":[function(require,module,exports,__globalThis) { +"use strict"; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _AbstractChatCompletionRunner_instances, _AbstractChatCompletionRunner_getFinalContent, _AbstractChatCompletionRunner_getFinalMessage, _AbstractChatCompletionRunner_getFinalFunctionCall, _AbstractChatCompletionRunner_getFinalFunctionCallResult, _AbstractChatCompletionRunner_calculateTotalUsage, _AbstractChatCompletionRunner_validateParams, _AbstractChatCompletionRunner_stringifyFunctionCallResult; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.AbstractChatCompletionRunner = void 0; +const error_1 = require("abe062b849aaeac6"); +const RunnableFunction_1 = require("34515f0daf0a04dd"); +const chatCompletionUtils_1 = require("cd0bbc7e1184dd6b"); +const EventStream_1 = require("68d604f97454765f"); +const parser_1 = require("bd01c7dadda87c65"); +const DEFAULT_MAX_CHAT_COMPLETIONS = 10; +class AbstractChatCompletionRunner extends EventStream_1.EventStream { + constructor(){ + super(...arguments); + _AbstractChatCompletionRunner_instances.add(this); + this._chatCompletions = []; + this.messages = []; + } + _addChatCompletion(chatCompletion) { + this._chatCompletions.push(chatCompletion); + this._emit('chatCompletion', chatCompletion); + const message = chatCompletion.choices[0]?.message; + if (message) this._addMessage(message); + return chatCompletion; + } + _addMessage(message, emit = true) { + if (!('content' in message)) message.content = null; + this.messages.push(message); + if (emit) { + this._emit('message', message); + if (((0, chatCompletionUtils_1.isFunctionMessage)(message) || (0, chatCompletionUtils_1.isToolMessage)(message)) && message.content) // Note, this assumes that {role: 'tool', content: …} is always the result of a call of tool of type=function. + this._emit('functionCallResult', message.content); + else if ((0, chatCompletionUtils_1.isAssistantMessage)(message) && message.function_call) this._emit('functionCall', message.function_call); + else if ((0, chatCompletionUtils_1.isAssistantMessage)(message) && message.tool_calls) { + for (const tool_call of message.tool_calls)if (tool_call.type === 'function') this._emit('functionCall', tool_call.function); + } + } + } + /** + * @returns a promise that resolves with the final ChatCompletion, or rejects + * if an error occurred or the stream ended prematurely without producing a ChatCompletion. + */ async finalChatCompletion() { + await this.done(); + const completion = this._chatCompletions[this._chatCompletions.length - 1]; + if (!completion) throw new error_1.OpenAIError('stream ended without producing a ChatCompletion'); + return completion; + } + /** + * @returns a promise that resolves with the content of the final ChatCompletionMessage, or rejects + * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage. + */ async finalContent() { + await this.done(); + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this); + } + /** + * @returns a promise that resolves with the the final assistant ChatCompletionMessage response, + * or rejects if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage. + */ async finalMessage() { + await this.done(); + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this); + } + /** + * @returns a promise that resolves with the content of the final FunctionCall, or rejects + * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage. + */ async finalFunctionCall() { + await this.done(); + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this); + } + async finalFunctionCallResult() { + await this.done(); + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this); + } + async totalUsage() { + await this.done(); + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this); + } + allChatCompletions() { + return [ + ...this._chatCompletions + ]; + } + _emitFinal() { + const completion = this._chatCompletions[this._chatCompletions.length - 1]; + if (completion) this._emit('finalChatCompletion', completion); + const finalMessage = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this); + if (finalMessage) this._emit('finalMessage', finalMessage); + const finalContent = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this); + if (finalContent) this._emit('finalContent', finalContent); + const finalFunctionCall = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this); + if (finalFunctionCall) this._emit('finalFunctionCall', finalFunctionCall); + const finalFunctionCallResult = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this); + if (finalFunctionCallResult != null) this._emit('finalFunctionCallResult', finalFunctionCallResult); + if (this._chatCompletions.some((c)=>c.usage)) this._emit('totalUsage', __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this)); + } + async _createChatCompletion(client, params, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_validateParams).call(this, params); + const chatCompletion = await client.chat.completions.create({ + ...params, + stream: false + }, { + ...options, + signal: this.controller.signal + }); + this._connected(); + return this._addChatCompletion((0, parser_1.parseChatCompletion)(chatCompletion, params)); + } + async _runChatCompletion(client, params, options) { + for (const message of params.messages)this._addMessage(message, false); + return await this._createChatCompletion(client, params, options); + } + async _runFunctions(client, params, options) { + const role = 'function'; + const { function_call = 'auto', stream, ...restParams } = params; + const singleFunctionToCall = typeof function_call !== 'string' && function_call?.name; + const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {}; + const functionsByName = {}; + for (const f of params.functions)functionsByName[f.name || f.function.name] = f; + const functions = params.functions.map((f)=>({ + name: f.name || f.function.name, + parameters: f.parameters, + description: f.description + })); + for (const message of params.messages)this._addMessage(message, false); + for(let i = 0; i < maxChatCompletions; ++i){ + const chatCompletion = await this._createChatCompletion(client, { + ...restParams, + function_call, + functions, + messages: [ + ...this.messages + ] + }, options); + const message = chatCompletion.choices[0]?.message; + if (!message) throw new error_1.OpenAIError(`missing message in ChatCompletion response`); + if (!message.function_call) return; + const { name, arguments: args } = message.function_call; + const fn = functionsByName[name]; + if (!fn) { + const content = `Invalid function_call: ${JSON.stringify(name)}. Available options are: ${functions.map((f)=>JSON.stringify(f.name)).join(', ')}. Please try again`; + this._addMessage({ + role, + name, + content + }); + continue; + } else if (singleFunctionToCall && singleFunctionToCall !== name) { + const content = `Invalid function_call: ${JSON.stringify(name)}. ${JSON.stringify(singleFunctionToCall)} requested. Please try again`; + this._addMessage({ + role, + name, + content + }); + continue; + } + let parsed; + try { + parsed = (0, RunnableFunction_1.isRunnableFunctionWithParse)(fn) ? await fn.parse(args) : args; + } catch (error) { + this._addMessage({ + role, + name, + content: error instanceof Error ? error.message : String(error) + }); + continue; + } + // @ts-expect-error it can't rule out `never` type. + const rawContent = await fn.function(parsed, this); + const content = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent); + this._addMessage({ + role, + name, + content + }); + if (singleFunctionToCall) return; + } + } + async _runTools(client, params, options) { + const role = 'tool'; + const { tool_choice = 'auto', stream, ...restParams } = params; + const singleFunctionToCall = typeof tool_choice !== 'string' && tool_choice?.function?.name; + const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {}; + // TODO(someday): clean this logic up + const inputTools = params.tools.map((tool)=>{ + if ((0, parser_1.isAutoParsableTool)(tool)) { + if (!tool.$callback) throw new error_1.OpenAIError('Tool given to `.runTools()` that does not have an associated function'); + return { + type: 'function', + function: { + function: tool.$callback, + name: tool.function.name, + description: tool.function.description || '', + parameters: tool.function.parameters, + parse: tool.$parseRaw, + strict: true + } + }; + } + return tool; + }); + const functionsByName = {}; + for (const f of inputTools)if (f.type === 'function') functionsByName[f.function.name || f.function.function.name] = f.function; + const tools = 'tools' in params ? inputTools.map((t)=>t.type === 'function' ? { + type: 'function', + function: { + name: t.function.name || t.function.function.name, + parameters: t.function.parameters, + description: t.function.description, + strict: t.function.strict + } + } : t) : undefined; + for (const message of params.messages)this._addMessage(message, false); + for(let i = 0; i < maxChatCompletions; ++i){ + const chatCompletion = await this._createChatCompletion(client, { + ...restParams, + tool_choice, + tools, + messages: [ + ...this.messages + ] + }, options); + const message = chatCompletion.choices[0]?.message; + if (!message) throw new error_1.OpenAIError(`missing message in ChatCompletion response`); + if (!message.tool_calls?.length) return; + for (const tool_call of message.tool_calls){ + if (tool_call.type !== 'function') continue; + const tool_call_id = tool_call.id; + const { name, arguments: args } = tool_call.function; + const fn = functionsByName[name]; + if (!fn) { + const content = `Invalid tool_call: ${JSON.stringify(name)}. Available options are: ${Object.keys(functionsByName).map((name)=>JSON.stringify(name)).join(', ')}. Please try again`; + this._addMessage({ + role, + tool_call_id, + content + }); + continue; + } else if (singleFunctionToCall && singleFunctionToCall !== name) { + const content = `Invalid tool_call: ${JSON.stringify(name)}. ${JSON.stringify(singleFunctionToCall)} requested. Please try again`; + this._addMessage({ + role, + tool_call_id, + content + }); + continue; + } + let parsed; + try { + parsed = (0, RunnableFunction_1.isRunnableFunctionWithParse)(fn) ? await fn.parse(args) : args; + } catch (error) { + const content = error instanceof Error ? error.message : String(error); + this._addMessage({ + role, + tool_call_id, + content + }); + continue; + } + // @ts-expect-error it can't rule out `never` type. + const rawContent = await fn.function(parsed, this); + const content = __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent); + this._addMessage({ + role, + tool_call_id, + content + }); + if (singleFunctionToCall) return; + } + } + return; + } +} +exports.AbstractChatCompletionRunner = AbstractChatCompletionRunner; +_AbstractChatCompletionRunner_instances = new WeakSet(), _AbstractChatCompletionRunner_getFinalContent = function _AbstractChatCompletionRunner_getFinalContent() { + return __classPrivateFieldGet(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this).content ?? null; +}, _AbstractChatCompletionRunner_getFinalMessage = function _AbstractChatCompletionRunner_getFinalMessage() { + let i = this.messages.length; + while(i-- > 0){ + const message = this.messages[i]; + if ((0, chatCompletionUtils_1.isAssistantMessage)(message)) { + const { function_call, ...rest } = message; + // TODO: support audio here + const ret = { + ...rest, + content: message.content ?? null, + refusal: message.refusal ?? null + }; + if (function_call) ret.function_call = function_call; + return ret; + } + } + throw new error_1.OpenAIError('stream ended without producing a ChatCompletionMessage with role=assistant'); +}, _AbstractChatCompletionRunner_getFinalFunctionCall = function _AbstractChatCompletionRunner_getFinalFunctionCall() { + for(let i = this.messages.length - 1; i >= 0; i--){ + const message = this.messages[i]; + if ((0, chatCompletionUtils_1.isAssistantMessage)(message) && message?.function_call) return message.function_call; + if ((0, chatCompletionUtils_1.isAssistantMessage)(message) && message?.tool_calls?.length) return message.tool_calls.at(-1)?.function; + } + return; +}, _AbstractChatCompletionRunner_getFinalFunctionCallResult = function _AbstractChatCompletionRunner_getFinalFunctionCallResult() { + for(let i = this.messages.length - 1; i >= 0; i--){ + const message = this.messages[i]; + if ((0, chatCompletionUtils_1.isFunctionMessage)(message) && message.content != null) return message.content; + if ((0, chatCompletionUtils_1.isToolMessage)(message) && message.content != null && typeof message.content === 'string' && this.messages.some((x)=>x.role === 'assistant' && x.tool_calls?.some((y)=>y.type === 'function' && y.id === message.tool_call_id))) return message.content; + } + return; +}, _AbstractChatCompletionRunner_calculateTotalUsage = function _AbstractChatCompletionRunner_calculateTotalUsage() { + const total = { + completion_tokens: 0, + prompt_tokens: 0, + total_tokens: 0 + }; + for (const { usage } of this._chatCompletions)if (usage) { + total.completion_tokens += usage.completion_tokens; + total.prompt_tokens += usage.prompt_tokens; + total.total_tokens += usage.total_tokens; + } + return total; +}, _AbstractChatCompletionRunner_validateParams = function _AbstractChatCompletionRunner_validateParams(params) { + if (params.n != null && params.n > 1) throw new error_1.OpenAIError('ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.'); +}, _AbstractChatCompletionRunner_stringifyFunctionCallResult = function _AbstractChatCompletionRunner_stringifyFunctionCallResult(rawContent) { + return typeof rawContent === 'string' ? rawContent : rawContent === undefined ? 'undefined' : JSON.stringify(rawContent); +}; + +},{"abe062b849aaeac6":"lRecV","34515f0daf0a04dd":"9PsV8","cd0bbc7e1184dd6b":"1BcC2","68d604f97454765f":"3zcw5","bd01c7dadda87c65":"gZPwj"}],"9PsV8":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ParsingToolFunction = exports.ParsingFunction = exports.isRunnableFunctionWithParse = void 0; +function isRunnableFunctionWithParse(fn) { + return typeof fn.parse === 'function'; +} +exports.isRunnableFunctionWithParse = isRunnableFunctionWithParse; +/** + * This is helper class for passing a `function` and `parse` where the `function` + * argument type matches the `parse` return type. + * + * @deprecated - please use ParsingToolFunction instead. + */ class ParsingFunction { + constructor(input){ + this.function = input.function; + this.parse = input.parse; + this.parameters = input.parameters; + this.description = input.description; + this.name = input.name; + } +} +exports.ParsingFunction = ParsingFunction; +/** + * This is helper class for passing a `function` and `parse` where the `function` + * argument type matches the `parse` return type. + */ class ParsingToolFunction { + constructor(input){ + this.type = 'function'; + this.function = input; + } +} +exports.ParsingToolFunction = ParsingToolFunction; + +},{}],"1BcC2":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.isPresent = exports.isToolMessage = exports.isFunctionMessage = exports.isAssistantMessage = void 0; +const isAssistantMessage = (message)=>{ + return message?.role === 'assistant'; +}; +exports.isAssistantMessage = isAssistantMessage; +const isFunctionMessage = (message)=>{ + return message?.role === 'function'; +}; +exports.isFunctionMessage = isFunctionMessage; +const isToolMessage = (message)=>{ + return message?.role === 'tool'; +}; +exports.isToolMessage = isToolMessage; +function isPresent(obj) { + return obj != null; +} +exports.isPresent = isPresent; + +},{}],"3zcw5":[function(require,module,exports,__globalThis) { +"use strict"; +var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function(receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; +}; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _EventStream_instances, _EventStream_connectedPromise, _EventStream_resolveConnectedPromise, _EventStream_rejectConnectedPromise, _EventStream_endPromise, _EventStream_resolveEndPromise, _EventStream_rejectEndPromise, _EventStream_listeners, _EventStream_ended, _EventStream_errored, _EventStream_aborted, _EventStream_catchingPromiseCreated, _EventStream_handleError; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.EventStream = void 0; +const error_1 = require("f21ad7dd9589da8e"); +class EventStream { + constructor(){ + _EventStream_instances.add(this); + this.controller = new AbortController(); + _EventStream_connectedPromise.set(this, void 0); + _EventStream_resolveConnectedPromise.set(this, ()=>{}); + _EventStream_rejectConnectedPromise.set(this, ()=>{}); + _EventStream_endPromise.set(this, void 0); + _EventStream_resolveEndPromise.set(this, ()=>{}); + _EventStream_rejectEndPromise.set(this, ()=>{}); + _EventStream_listeners.set(this, {}); + _EventStream_ended.set(this, false); + _EventStream_errored.set(this, false); + _EventStream_aborted.set(this, false); + _EventStream_catchingPromiseCreated.set(this, false); + __classPrivateFieldSet(this, _EventStream_connectedPromise, new Promise((resolve, reject)=>{ + __classPrivateFieldSet(this, _EventStream_resolveConnectedPromise, resolve, "f"); + __classPrivateFieldSet(this, _EventStream_rejectConnectedPromise, reject, "f"); + }), "f"); + __classPrivateFieldSet(this, _EventStream_endPromise, new Promise((resolve, reject)=>{ + __classPrivateFieldSet(this, _EventStream_resolveEndPromise, resolve, "f"); + __classPrivateFieldSet(this, _EventStream_rejectEndPromise, reject, "f"); + }), "f"); + // Don't let these promises cause unhandled rejection errors. + // we will manually cause an unhandled rejection error later + // if the user hasn't registered any error listener or called + // any promise-returning method. + __classPrivateFieldGet(this, _EventStream_connectedPromise, "f").catch(()=>{}); + __classPrivateFieldGet(this, _EventStream_endPromise, "f").catch(()=>{}); + } + _run(executor) { + // Unfortunately if we call `executor()` immediately we get runtime errors about + // references to `this` before the `super()` constructor call returns. + setTimeout(()=>{ + executor().then(()=>{ + this._emitFinal(); + this._emit('end'); + }, __classPrivateFieldGet(this, _EventStream_instances, "m", _EventStream_handleError).bind(this)); + }, 0); + } + _connected() { + if (this.ended) return; + __classPrivateFieldGet(this, _EventStream_resolveConnectedPromise, "f").call(this); + this._emit('connect'); + } + get ended() { + return __classPrivateFieldGet(this, _EventStream_ended, "f"); + } + get errored() { + return __classPrivateFieldGet(this, _EventStream_errored, "f"); + } + get aborted() { + return __classPrivateFieldGet(this, _EventStream_aborted, "f"); + } + abort() { + this.controller.abort(); + } + /** + * Adds the listener function to the end of the listeners array for the event. + * No checks are made to see if the listener has already been added. Multiple calls passing + * the same combination of event and listener will result in the listener being added, and + * called, multiple times. + * @returns this ChatCompletionStream, so that calls can be chained + */ on(event, listener) { + const listeners = __classPrivateFieldGet(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _EventStream_listeners, "f")[event] = []); + listeners.push({ + listener + }); + return this; + } + /** + * Removes the specified listener from the listener array for the event. + * off() will remove, at most, one instance of a listener from the listener array. If any single + * listener has been added multiple times to the listener array for the specified event, then + * off() must be called multiple times to remove each instance. + * @returns this ChatCompletionStream, so that calls can be chained + */ off(event, listener) { + const listeners = __classPrivateFieldGet(this, _EventStream_listeners, "f")[event]; + if (!listeners) return this; + const index = listeners.findIndex((l)=>l.listener === listener); + if (index >= 0) listeners.splice(index, 1); + return this; + } + /** + * Adds a one-time listener function for the event. The next time the event is triggered, + * this listener is removed and then invoked. + * @returns this ChatCompletionStream, so that calls can be chained + */ once(event, listener) { + const listeners = __classPrivateFieldGet(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _EventStream_listeners, "f")[event] = []); + listeners.push({ + listener, + once: true + }); + return this; + } + /** + * This is similar to `.once()`, but returns a Promise that resolves the next time + * the event is triggered, instead of calling a listener callback. + * @returns a Promise that resolves the next time given event is triggered, + * or rejects if an error is emitted. (If you request the 'error' event, + * returns a promise that resolves with the error). + * + * Example: + * + * const message = await stream.emitted('message') // rejects if the stream errors + */ emitted(event) { + return new Promise((resolve, reject)=>{ + __classPrivateFieldSet(this, _EventStream_catchingPromiseCreated, true, "f"); + if (event !== 'error') this.once('error', reject); + this.once(event, resolve); + }); + } + async done() { + __classPrivateFieldSet(this, _EventStream_catchingPromiseCreated, true, "f"); + await __classPrivateFieldGet(this, _EventStream_endPromise, "f"); + } + _emit(event, ...args) { + // make sure we don't emit any events after end + if (__classPrivateFieldGet(this, _EventStream_ended, "f")) return; + if (event === 'end') { + __classPrivateFieldSet(this, _EventStream_ended, true, "f"); + __classPrivateFieldGet(this, _EventStream_resolveEndPromise, "f").call(this); + } + const listeners = __classPrivateFieldGet(this, _EventStream_listeners, "f")[event]; + if (listeners) { + __classPrivateFieldGet(this, _EventStream_listeners, "f")[event] = listeners.filter((l)=>!l.once); + listeners.forEach(({ listener })=>listener(...args)); + } + if (event === 'abort') { + const error = args[0]; + if (!__classPrivateFieldGet(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) Promise.reject(error); + __classPrivateFieldGet(this, _EventStream_rejectConnectedPromise, "f").call(this, error); + __classPrivateFieldGet(this, _EventStream_rejectEndPromise, "f").call(this, error); + this._emit('end'); + return; + } + if (event === 'error') { + // NOTE: _emit('error', error) should only be called from #handleError(). + const error = args[0]; + if (!__classPrivateFieldGet(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) // Trigger an unhandled rejection if the user hasn't registered any error handlers. + // If you are seeing stack traces here, make sure to handle errors via either: + // - runner.on('error', () => ...) + // - await runner.done() + // - await runner.finalChatCompletion() + // - etc. + Promise.reject(error); + __classPrivateFieldGet(this, _EventStream_rejectConnectedPromise, "f").call(this, error); + __classPrivateFieldGet(this, _EventStream_rejectEndPromise, "f").call(this, error); + this._emit('end'); + } + } + _emitFinal() {} +} +exports.EventStream = EventStream; +_EventStream_connectedPromise = new WeakMap(), _EventStream_resolveConnectedPromise = new WeakMap(), _EventStream_rejectConnectedPromise = new WeakMap(), _EventStream_endPromise = new WeakMap(), _EventStream_resolveEndPromise = new WeakMap(), _EventStream_rejectEndPromise = new WeakMap(), _EventStream_listeners = new WeakMap(), _EventStream_ended = new WeakMap(), _EventStream_errored = new WeakMap(), _EventStream_aborted = new WeakMap(), _EventStream_catchingPromiseCreated = new WeakMap(), _EventStream_instances = new WeakSet(), _EventStream_handleError = function _EventStream_handleError(error) { + __classPrivateFieldSet(this, _EventStream_errored, true, "f"); + if (error instanceof Error && error.name === 'AbortError') error = new error_1.APIUserAbortError(); + if (error instanceof error_1.APIUserAbortError) { + __classPrivateFieldSet(this, _EventStream_aborted, true, "f"); + return this._emit('abort', error); + } + if (error instanceof error_1.OpenAIError) return this._emit('error', error); + if (error instanceof Error) { + const openAIError = new error_1.OpenAIError(error.message); + // @ts-ignore + openAIError.cause = error; + return this._emit('error', openAIError); + } + return this._emit('error', new error_1.OpenAIError(String(error))); +}; + +},{"f21ad7dd9589da8e":"lRecV"}],"gZPwj":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.validateInputTools = exports.hasAutoParseableInput = exports.shouldParseToolCall = exports.parseChatCompletion = exports.maybeParseChatCompletion = exports.isAutoParsableTool = exports.makeParseableTool = exports.isAutoParsableResponseFormat = exports.makeParseableResponseFormat = void 0; +const error_1 = require("c26c7aca5a8dd13e"); +function makeParseableResponseFormat(response_format, parser) { + const obj = { + ...response_format + }; + Object.defineProperties(obj, { + $brand: { + value: 'auto-parseable-response-format', + enumerable: false + }, + $parseRaw: { + value: parser, + enumerable: false + } + }); + return obj; +} +exports.makeParseableResponseFormat = makeParseableResponseFormat; +function isAutoParsableResponseFormat(response_format) { + return response_format?.['$brand'] === 'auto-parseable-response-format'; +} +exports.isAutoParsableResponseFormat = isAutoParsableResponseFormat; +function makeParseableTool(tool, { parser, callback }) { + const obj = { + ...tool + }; + Object.defineProperties(obj, { + $brand: { + value: 'auto-parseable-tool', + enumerable: false + }, + $parseRaw: { + value: parser, + enumerable: false + }, + $callback: { + value: callback, + enumerable: false + } + }); + return obj; +} +exports.makeParseableTool = makeParseableTool; +function isAutoParsableTool(tool) { + return tool?.['$brand'] === 'auto-parseable-tool'; +} +exports.isAutoParsableTool = isAutoParsableTool; +function maybeParseChatCompletion(completion, params) { + if (!params || !hasAutoParseableInput(params)) return { + ...completion, + choices: completion.choices.map((choice)=>({ + ...choice, + message: { + ...choice.message, + parsed: null, + ...choice.message.tool_calls ? { + tool_calls: choice.message.tool_calls + } : undefined + } + })) + }; + return parseChatCompletion(completion, params); +} +exports.maybeParseChatCompletion = maybeParseChatCompletion; +function parseChatCompletion(completion, params) { + const choices = completion.choices.map((choice)=>{ + if (choice.finish_reason === 'length') throw new error_1.LengthFinishReasonError(); + if (choice.finish_reason === 'content_filter') throw new error_1.ContentFilterFinishReasonError(); + return { + ...choice, + message: { + ...choice.message, + ...choice.message.tool_calls ? { + tool_calls: choice.message.tool_calls?.map((toolCall)=>parseToolCall(params, toolCall)) ?? undefined + } : undefined, + parsed: choice.message.content && !choice.message.refusal ? parseResponseFormat(params, choice.message.content) : null + } + }; + }); + return { + ...completion, + choices + }; +} +exports.parseChatCompletion = parseChatCompletion; +function parseResponseFormat(params, content) { + if (params.response_format?.type !== 'json_schema') return null; + if (params.response_format?.type === 'json_schema') { + if ('$parseRaw' in params.response_format) { + const response_format = params.response_format; + return response_format.$parseRaw(content); + } + return JSON.parse(content); + } + return null; +} +function parseToolCall(params, toolCall) { + const inputTool = params.tools?.find((inputTool)=>inputTool.function?.name === toolCall.function.name); + return { + ...toolCall, + function: { + ...toolCall.function, + parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments) : inputTool?.function.strict ? JSON.parse(toolCall.function.arguments) : null + } + }; +} +function shouldParseToolCall(params, toolCall) { + if (!params) return false; + const inputTool = params.tools?.find((inputTool)=>inputTool.function?.name === toolCall.function.name); + return isAutoParsableTool(inputTool) || inputTool?.function.strict || false; +} +exports.shouldParseToolCall = shouldParseToolCall; +function hasAutoParseableInput(params) { + if (isAutoParsableResponseFormat(params.response_format)) return true; + return params.tools?.some((t)=>isAutoParsableTool(t) || t.type === 'function' && t.function.strict === true) ?? false; +} +exports.hasAutoParseableInput = hasAutoParseableInput; +function validateInputTools(tools) { + for (const tool of tools ?? []){ + if (tool.type !== 'function') throw new error_1.OpenAIError(`Currently only \`function\` tool types support auto-parsing; Received \`${tool.type}\``); + if (tool.function.strict !== true) throw new error_1.OpenAIError(`The \`${tool.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`); + } +} +exports.validateInputTools = validateInputTools; + +},{"c26c7aca5a8dd13e":"lRecV"}],"fqtsj":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ChatCompletionStreamingRunner = void 0; +const ChatCompletionStream_1 = require("d9dde4bc4fd281e4"); +class ChatCompletionStreamingRunner extends ChatCompletionStream_1.ChatCompletionStream { + static fromReadableStream(stream) { + const runner = new ChatCompletionStreamingRunner(null); + runner._run(()=>runner._fromReadableStream(stream)); + return runner; + } + /** @deprecated - please use `runTools` instead. */ static runFunctions(client, params, options) { + const runner = new ChatCompletionStreamingRunner(null); + const opts = { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'runFunctions' + } + }; + runner._run(()=>runner._runFunctions(client, params, opts)); + return runner; + } + static runTools(client, params, options) { + const runner = new ChatCompletionStreamingRunner(// @ts-expect-error TODO these types are incompatible + params); + const opts = { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'runTools' + } + }; + runner._run(()=>runner._runTools(client, params, opts)); + return runner; + } +} +exports.ChatCompletionStreamingRunner = ChatCompletionStreamingRunner; + +},{"d9dde4bc4fd281e4":"8L9Cr"}],"8L9Cr":[function(require,module,exports,__globalThis) { +"use strict"; +var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function(receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; +}; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _ChatCompletionStream_instances, _ChatCompletionStream_params, _ChatCompletionStream_choiceEventStates, _ChatCompletionStream_currentChatCompletionSnapshot, _ChatCompletionStream_beginRequest, _ChatCompletionStream_getChoiceEventState, _ChatCompletionStream_addChunk, _ChatCompletionStream_emitToolCallDoneEvent, _ChatCompletionStream_emitContentDoneEvents, _ChatCompletionStream_endRequest, _ChatCompletionStream_getAutoParseableResponseFormat, _ChatCompletionStream_accumulateChatCompletion; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ChatCompletionStream = void 0; +const error_1 = require("c23b89db1ca3adc7"); +const AbstractChatCompletionRunner_1 = require("9249f57561228160"); +const streaming_1 = require("7051e3bc8f64bc33"); +const parser_1 = require("32da66fb364c1e28"); +const parser_2 = require("5e7310de94d6a3e2"); +class ChatCompletionStream extends AbstractChatCompletionRunner_1.AbstractChatCompletionRunner { + constructor(params){ + super(); + _ChatCompletionStream_instances.add(this); + _ChatCompletionStream_params.set(this, void 0); + _ChatCompletionStream_choiceEventStates.set(this, void 0); + _ChatCompletionStream_currentChatCompletionSnapshot.set(this, void 0); + __classPrivateFieldSet(this, _ChatCompletionStream_params, params, "f"); + __classPrivateFieldSet(this, _ChatCompletionStream_choiceEventStates, [], "f"); + } + get currentChatCompletionSnapshot() { + return __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"); + } + /** + * Intended for use on the frontend, consuming a stream produced with + * `.toReadableStream()` on the backend. + * + * Note that messages sent to the model do not appear in `.on('message')` + * in this context. + */ static fromReadableStream(stream) { + const runner = new ChatCompletionStream(null); + runner._run(()=>runner._fromReadableStream(stream)); + return runner; + } + static createChatCompletion(client, params, options) { + const runner = new ChatCompletionStream(params); + runner._run(()=>runner._runChatCompletion(client, { + ...params, + stream: true + }, { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'stream' + } + })); + return runner; + } + async _createChatCompletion(client, params, options) { + super._createChatCompletion; + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this); + const stream = await client.chat.completions.create({ + ...params, + stream: true + }, { + ...options, + signal: this.controller.signal + }); + this._connected(); + for await (const chunk of stream)__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk); + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this)); + } + async _fromReadableStream(readableStream, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this); + this._connected(); + const stream = streaming_1.Stream.fromReadableStream(readableStream, this.controller); + let chatId; + for await (const chunk of stream){ + if (chatId && chatId !== chunk.id) // A new request has been made. + this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this)); + __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk); + chatId = chunk.id; + } + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this)); + } + [(_ChatCompletionStream_params = new WeakMap(), _ChatCompletionStream_choiceEventStates = new WeakMap(), _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap(), _ChatCompletionStream_instances = new WeakSet(), _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() { + if (this.ended) return; + __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f"); + }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) { + let state = __classPrivateFieldGet(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index]; + if (state) return state; + state = { + content_done: false, + refusal_done: false, + logprobs_content_done: false, + logprobs_refusal_done: false, + done_tool_calls: new Set(), + current_tool_call_index: null + }; + __classPrivateFieldGet(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state; + return state; + }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) { + if (this.ended) return; + const completion = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk); + this._emit('chunk', chunk, completion); + for (const choice of chunk.choices){ + const choiceSnapshot = completion.choices[choice.index]; + if (choice.delta.content != null && choiceSnapshot.message?.role === 'assistant' && choiceSnapshot.message?.content) { + this._emit('content', choice.delta.content, choiceSnapshot.message.content); + this._emit('content.delta', { + delta: choice.delta.content, + snapshot: choiceSnapshot.message.content, + parsed: choiceSnapshot.message.parsed + }); + } + if (choice.delta.refusal != null && choiceSnapshot.message?.role === 'assistant' && choiceSnapshot.message?.refusal) this._emit('refusal.delta', { + delta: choice.delta.refusal, + snapshot: choiceSnapshot.message.refusal + }); + if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') this._emit('logprobs.content.delta', { + content: choice.logprobs?.content, + snapshot: choiceSnapshot.logprobs?.content ?? [] + }); + if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') this._emit('logprobs.refusal.delta', { + refusal: choice.logprobs?.refusal, + snapshot: choiceSnapshot.logprobs?.refusal ?? [] + }); + const state = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); + if (choiceSnapshot.finish_reason) { + __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot); + if (state.current_tool_call_index != null) __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index); + } + for (const toolCall of choice.delta.tool_calls ?? []){ + if (state.current_tool_call_index !== toolCall.index) { + __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot); + // new tool call started, the previous one is done + if (state.current_tool_call_index != null) __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index); + } + state.current_tool_call_index = toolCall.index; + } + for (const toolCallDelta of choice.delta.tool_calls ?? []){ + const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index]; + if (!toolCallSnapshot?.type) continue; + if (toolCallSnapshot?.type === 'function') this._emit('tool_calls.function.arguments.delta', { + name: toolCallSnapshot.function?.name, + index: toolCallDelta.index, + arguments: toolCallSnapshot.function.arguments, + parsed_arguments: toolCallSnapshot.function.parsed_arguments, + arguments_delta: toolCallDelta.function?.arguments ?? '' + }); + else assertNever(toolCallSnapshot?.type); + } + } + }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) { + const state = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); + if (state.done_tool_calls.has(toolCallIndex)) // we've already fired the done event + return; + const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex]; + if (!toolCallSnapshot) throw new Error('no tool call snapshot'); + if (!toolCallSnapshot.type) throw new Error('tool call snapshot missing `type`'); + if (toolCallSnapshot.type === 'function') { + const inputTool = __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.tools?.find((tool)=>tool.type === 'function' && tool.function.name === toolCallSnapshot.function.name); + this._emit('tool_calls.function.arguments.done', { + name: toolCallSnapshot.function.name, + index: toolCallIndex, + arguments: toolCallSnapshot.function.arguments, + parsed_arguments: (0, parser_1.isAutoParsableTool)(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments) : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments) : null + }); + } else assertNever(toolCallSnapshot.type); + }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) { + const state = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); + if (choiceSnapshot.message.content && !state.content_done) { + state.content_done = true; + const responseFormat = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this); + this._emit('content.done', { + content: choiceSnapshot.message.content, + parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : null + }); + } + if (choiceSnapshot.message.refusal && !state.refusal_done) { + state.refusal_done = true; + this._emit('refusal.done', { + refusal: choiceSnapshot.message.refusal + }); + } + if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) { + state.logprobs_content_done = true; + this._emit('logprobs.content.done', { + content: choiceSnapshot.logprobs.content + }); + } + if (choiceSnapshot.logprobs?.refusal && !state.logprobs_refusal_done) { + state.logprobs_refusal_done = true; + this._emit('logprobs.refusal.done', { + refusal: choiceSnapshot.logprobs.refusal + }); + } + }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest() { + if (this.ended) throw new error_1.OpenAIError(`stream has ended, this shouldn't happen`); + const snapshot = __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"); + if (!snapshot) throw new error_1.OpenAIError(`request ended without sending any chunks`); + __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f"); + __classPrivateFieldSet(this, _ChatCompletionStream_choiceEventStates, [], "f"); + return finalizeChatCompletion(snapshot, __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")); + }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() { + const responseFormat = __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format; + if ((0, parser_1.isAutoParsableResponseFormat)(responseFormat)) return responseFormat; + return null; + }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) { + var _a, _b, _c, _d; + let snapshot = __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"); + const { choices, ...rest } = chunk; + if (!snapshot) snapshot = __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, { + ...rest, + choices: [] + }, "f"); + else Object.assign(snapshot, rest); + for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices){ + let choice = snapshot.choices[index]; + if (!choice) choice = snapshot.choices[index] = { + finish_reason, + index, + message: {}, + logprobs, + ...other + }; + if (logprobs) { + if (!choice.logprobs) choice.logprobs = Object.assign({}, logprobs); + else { + const { content, refusal, ...rest } = logprobs; + assertIsEmpty(rest); + Object.assign(choice.logprobs, rest); + if (content) { + (_a = choice.logprobs).content ?? (_a.content = []); + choice.logprobs.content.push(...content); + } + if (refusal) { + (_b = choice.logprobs).refusal ?? (_b.refusal = []); + choice.logprobs.refusal.push(...refusal); + } + } + } + if (finish_reason) { + choice.finish_reason = finish_reason; + if (__classPrivateFieldGet(this, _ChatCompletionStream_params, "f") && (0, parser_1.hasAutoParseableInput)(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"))) { + if (finish_reason === 'length') throw new error_1.LengthFinishReasonError(); + if (finish_reason === 'content_filter') throw new error_1.ContentFilterFinishReasonError(); + } + } + Object.assign(choice, other); + if (!delta) continue; // Shouldn't happen; just in case. + const { content, refusal, function_call, role, tool_calls, ...rest } = delta; + assertIsEmpty(rest); + Object.assign(choice.message, rest); + if (refusal) choice.message.refusal = (choice.message.refusal || '') + refusal; + if (role) choice.message.role = role; + if (function_call) { + if (!choice.message.function_call) choice.message.function_call = function_call; + else { + if (function_call.name) choice.message.function_call.name = function_call.name; + if (function_call.arguments) { + (_c = choice.message.function_call).arguments ?? (_c.arguments = ''); + choice.message.function_call.arguments += function_call.arguments; + } + } + } + if (content) { + choice.message.content = (choice.message.content || '') + content; + if (!choice.message.refusal && __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this)) choice.message.parsed = (0, parser_2.partialParse)(choice.message.content); + } + if (tool_calls) { + if (!choice.message.tool_calls) choice.message.tool_calls = []; + for (const { index, id, type, function: fn, ...rest } of tool_calls){ + const tool_call = (_d = choice.message.tool_calls)[index] ?? (_d[index] = {}); + Object.assign(tool_call, rest); + if (id) tool_call.id = id; + if (type) tool_call.type = type; + if (fn) tool_call.function ?? (tool_call.function = { + name: fn.name ?? '', + arguments: '' + }); + if (fn?.name) tool_call.function.name = fn.name; + if (fn?.arguments) { + tool_call.function.arguments += fn.arguments; + if ((0, parser_1.shouldParseToolCall)(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"), tool_call)) tool_call.function.parsed_arguments = (0, parser_2.partialParse)(tool_call.function.arguments); + } + } + } + } + return snapshot; + }, Symbol.asyncIterator)]() { + const pushQueue = []; + const readQueue = []; + let done = false; + this.on('chunk', (chunk)=>{ + const reader = readQueue.shift(); + if (reader) reader.resolve(chunk); + else pushQueue.push(chunk); + }); + this.on('end', ()=>{ + done = true; + for (const reader of readQueue)reader.resolve(undefined); + readQueue.length = 0; + }); + this.on('abort', (err)=>{ + done = true; + for (const reader of readQueue)reader.reject(err); + readQueue.length = 0; + }); + this.on('error', (err)=>{ + done = true; + for (const reader of readQueue)reader.reject(err); + readQueue.length = 0; + }); + return { + next: async ()=>{ + if (!pushQueue.length) { + if (done) return { + value: undefined, + done: true + }; + return new Promise((resolve, reject)=>readQueue.push({ + resolve, + reject + })).then((chunk)=>chunk ? { + value: chunk, + done: false + } : { + value: undefined, + done: true + }); + } + const chunk = pushQueue.shift(); + return { + value: chunk, + done: false + }; + }, + return: async ()=>{ + this.abort(); + return { + value: undefined, + done: true + }; + } + }; + } + toReadableStream() { + const stream = new streaming_1.Stream(this[Symbol.asyncIterator].bind(this), this.controller); + return stream.toReadableStream(); + } +} +exports.ChatCompletionStream = ChatCompletionStream; +function finalizeChatCompletion(snapshot, params) { + const { id, choices, created, model, system_fingerprint, ...rest } = snapshot; + const completion = { + ...rest, + id, + choices: choices.map(({ message, finish_reason, index, logprobs, ...choiceRest })=>{ + if (!finish_reason) throw new error_1.OpenAIError(`missing finish_reason for choice ${index}`); + const { content = null, function_call, tool_calls, ...messageRest } = message; + const role = message.role; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine. + if (!role) throw new error_1.OpenAIError(`missing role for choice ${index}`); + if (function_call) { + const { arguments: args, name } = function_call; + if (args == null) throw new error_1.OpenAIError(`missing function_call.arguments for choice ${index}`); + if (!name) throw new error_1.OpenAIError(`missing function_call.name for choice ${index}`); + return { + ...choiceRest, + message: { + content, + function_call: { + arguments: args, + name + }, + role, + refusal: message.refusal ?? null + }, + finish_reason, + index, + logprobs + }; + } + if (tool_calls) return { + ...choiceRest, + index, + finish_reason, + logprobs, + message: { + ...messageRest, + role, + content, + refusal: message.refusal ?? null, + tool_calls: tool_calls.map((tool_call, i)=>{ + const { function: fn, type, id, ...toolRest } = tool_call; + const { arguments: args, name, ...fnRest } = fn || {}; + if (id == null) throw new error_1.OpenAIError(`missing choices[${index}].tool_calls[${i}].id\n${str(snapshot)}`); + if (type == null) throw new error_1.OpenAIError(`missing choices[${index}].tool_calls[${i}].type\n${str(snapshot)}`); + if (name == null) throw new error_1.OpenAIError(`missing choices[${index}].tool_calls[${i}].function.name\n${str(snapshot)}`); + if (args == null) throw new error_1.OpenAIError(`missing choices[${index}].tool_calls[${i}].function.arguments\n${str(snapshot)}`); + return { + ...toolRest, + id, + type, + function: { + ...fnRest, + name, + arguments: args + } + }; + }) + } + }; + return { + ...choiceRest, + message: { + ...messageRest, + content, + role, + refusal: message.refusal ?? null + }, + finish_reason, + index, + logprobs + }; + }), + created, + model, + object: 'chat.completion', + ...system_fingerprint ? { + system_fingerprint + } : {} + }; + return (0, parser_1.maybeParseChatCompletion)(completion, params); +} +function str(x) { + return JSON.stringify(x); +} +/** + * Ensures the given argument is an empty object, useful for + * asserting that all known properties on an object have been + * destructured. + */ function assertIsEmpty(obj) { + return; +} +function assertNever(_x) {} + +},{"c23b89db1ca3adc7":"lRecV","9249f57561228160":"6IJye","7051e3bc8f64bc33":"2gNIj","32da66fb364c1e28":"gZPwj","5e7310de94d6a3e2":"cNi1z"}],"cNi1z":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.MalformedJSON = exports.PartialJSON = exports.partialParse = void 0; +const STR = 1; +const NUM = 2; +const ARR = 4; +const OBJ = 8; +const NULL = 16; +const BOOL = 32; +const NAN = 64; +const INFINITY = 128; +const MINUS_INFINITY = 256; +const INF = INFINITY | MINUS_INFINITY; +const SPECIAL = NULL | BOOL | INF | NAN; +const ATOM = STR | NUM | SPECIAL; +const COLLECTION = ARR | OBJ; +const ALL = ATOM | COLLECTION; +const Allow = { + STR, + NUM, + ARR, + OBJ, + NULL, + BOOL, + NAN, + INFINITY, + MINUS_INFINITY, + INF, + SPECIAL, + ATOM, + COLLECTION, + ALL +}; +// The JSON string segment was unable to be parsed completely +class PartialJSON extends Error { +} +exports.PartialJSON = PartialJSON; +class MalformedJSON extends Error { +} +exports.MalformedJSON = MalformedJSON; +/** + * Parse incomplete JSON + * @param {string} jsonString Partial JSON to be parsed + * @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details + * @returns The parsed JSON + * @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter) + * @throws {MalformedJSON} If the JSON is malformed + */ function parseJSON(jsonString, allowPartial = Allow.ALL) { + if (typeof jsonString !== 'string') throw new TypeError(`expecting str, got ${typeof jsonString}`); + if (!jsonString.trim()) throw new Error(`${jsonString} is empty`); + return _parseJSON(jsonString.trim(), allowPartial); +} +const _parseJSON = (jsonString, allow)=>{ + const length = jsonString.length; + let index = 0; + const markPartialJSON = (msg)=>{ + throw new PartialJSON(`${msg} at position ${index}`); + }; + const throwMalformedError = (msg)=>{ + throw new MalformedJSON(`${msg} at position ${index}`); + }; + const parseAny = ()=>{ + skipBlank(); + if (index >= length) markPartialJSON('Unexpected end of input'); + if (jsonString[index] === '"') return parseStr(); + if (jsonString[index] === '{') return parseObj(); + if (jsonString[index] === '[') return parseArr(); + if (jsonString.substring(index, index + 4) === 'null' || Allow.NULL & allow && length - index < 4 && 'null'.startsWith(jsonString.substring(index))) { + index += 4; + return null; + } + if (jsonString.substring(index, index + 4) === 'true' || Allow.BOOL & allow && length - index < 4 && 'true'.startsWith(jsonString.substring(index))) { + index += 4; + return true; + } + if (jsonString.substring(index, index + 5) === 'false' || Allow.BOOL & allow && length - index < 5 && 'false'.startsWith(jsonString.substring(index))) { + index += 5; + return false; + } + if (jsonString.substring(index, index + 8) === 'Infinity' || Allow.INFINITY & allow && length - index < 8 && 'Infinity'.startsWith(jsonString.substring(index))) { + index += 8; + return Infinity; + } + if (jsonString.substring(index, index + 9) === '-Infinity' || Allow.MINUS_INFINITY & allow && 1 < length - index && length - index < 9 && '-Infinity'.startsWith(jsonString.substring(index))) { + index += 9; + return -Infinity; + } + if (jsonString.substring(index, index + 3) === 'NaN' || Allow.NAN & allow && length - index < 3 && 'NaN'.startsWith(jsonString.substring(index))) { + index += 3; + return NaN; + } + return parseNum(); + }; + const parseStr = ()=>{ + const start = index; + let escape = false; + index++; // skip initial quote + while(index < length && (jsonString[index] !== '"' || escape && jsonString[index - 1] === '\\')){ + escape = jsonString[index] === '\\' ? !escape : false; + index++; + } + if (jsonString.charAt(index) == '"') try { + return JSON.parse(jsonString.substring(start, ++index - Number(escape))); + } catch (e) { + throwMalformedError(String(e)); + } + else if (Allow.STR & allow) try { + return JSON.parse(jsonString.substring(start, index - Number(escape)) + '"'); + } catch (e) { + // SyntaxError: Invalid escape sequence + return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('\\')) + '"'); + } + markPartialJSON('Unterminated string literal'); + }; + const parseObj = ()=>{ + index++; // skip initial brace + skipBlank(); + const obj = {}; + try { + while(jsonString[index] !== '}'){ + skipBlank(); + if (index >= length && Allow.OBJ & allow) return obj; + const key = parseStr(); + skipBlank(); + index++; // skip colon + try { + const value = parseAny(); + Object.defineProperty(obj, key, { + value, + writable: true, + enumerable: true, + configurable: true + }); + } catch (e) { + if (Allow.OBJ & allow) return obj; + else throw e; + } + skipBlank(); + if (jsonString[index] === ',') index++; // skip comma + } + } catch (e) { + if (Allow.OBJ & allow) return obj; + else markPartialJSON("Expected '}' at end of object"); + } + index++; // skip final brace + return obj; + }; + const parseArr = ()=>{ + index++; // skip initial bracket + const arr = []; + try { + while(jsonString[index] !== ']'){ + arr.push(parseAny()); + skipBlank(); + if (jsonString[index] === ',') index++; // skip comma + } + } catch (e) { + if (Allow.ARR & allow) return arr; + markPartialJSON("Expected ']' at end of array"); + } + index++; // skip final bracket + return arr; + }; + const parseNum = ()=>{ + if (index === 0) { + if (jsonString === '-' && Allow.NUM & allow) markPartialJSON("Not sure what '-' is"); + try { + return JSON.parse(jsonString); + } catch (e) { + if (Allow.NUM & allow) try { + if ('.' === jsonString[jsonString.length - 1]) return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('.'))); + return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('e'))); + } catch (e) {} + throwMalformedError(String(e)); + } + } + const start = index; + if (jsonString[index] === '-') index++; + while(jsonString[index] && !',]}'.includes(jsonString[index]))index++; + if (index == length && !(Allow.NUM & allow)) markPartialJSON('Unterminated number literal'); + try { + return JSON.parse(jsonString.substring(start, index)); + } catch (e) { + if (jsonString.substring(start, index) === '-' && Allow.NUM & allow) markPartialJSON("Not sure what '-' is"); + try { + return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('e'))); + } catch (e) { + throwMalformedError(String(e)); + } + } + }; + const skipBlank = ()=>{ + while(index < length && ' \n\r\t'.includes(jsonString[index]))index++; + }; + return parseAny(); +}; +// using this function with malformed JSON is undefined behavior +const partialParse = (input)=>parseJSON(input, Allow.ALL ^ Allow.NUM); +exports.partialParse = partialParse; + +},{}],"j8ba6":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Realtime = void 0; +const resource_1 = require("280cc15c97ef28f4"); +const SessionsAPI = __importStar(require("826d31ac01724d49")); +const sessions_1 = require("826d31ac01724d49"); +class Realtime extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.sessions = new SessionsAPI.Sessions(this._client); + } +} +exports.Realtime = Realtime; +Realtime.Sessions = sessions_1.Sessions; + +},{"280cc15c97ef28f4":"kPMwm","826d31ac01724d49":"kIjvg"}],"kIjvg":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Sessions = void 0; +const resource_1 = require("c86f4c000e1f5675"); +class Sessions extends resource_1.APIResource { + /** + * Create an ephemeral API token for use in client-side applications with the + * Realtime API. Can be configured with the same session parameters as the + * `session.update` client event. + * + * It responds with a session object, plus a `client_secret` key which contains a + * usable ephemeral API token that can be used to authenticate browser clients for + * the Realtime API. + */ create(body, options) { + return this._client.post('/realtime/sessions', { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } +} +exports.Sessions = Sessions; + +},{"c86f4c000e1f5675":"kPMwm"}],"fHMCJ":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Threads = void 0; +const resource_1 = require("3255d3d2c9989c7d"); +const core_1 = require("3044ea6c3051ba9e"); +const AssistantStream_1 = require("792b307e20aaaaa7"); +const MessagesAPI = __importStar(require("56a81e319684dd15")); +const messages_1 = require("56a81e319684dd15"); +const RunsAPI = __importStar(require("c1e8e1f4c6465bec")); +const runs_1 = require("c1e8e1f4c6465bec"); +class Threads extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.runs = new RunsAPI.Runs(this._client); + this.messages = new MessagesAPI.Messages(this._client); + } + create(body = {}, options) { + if ((0, core_1.isRequestOptions)(body)) return this.create({}, body); + return this._client.post('/threads', { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieves a thread. + */ retrieve(threadId, options) { + return this._client.get(`/threads/${threadId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Modifies a thread. + */ update(threadId, body, options) { + return this._client.post(`/threads/${threadId}`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Delete a thread. + */ del(threadId, options) { + return this._client.delete(`/threads/${threadId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + createAndRun(body, options) { + return this._client.post('/threads/runs', { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + }, + stream: body.stream ?? false + }); + } + /** + * A helper to create a thread, start a run and then poll for a terminal state. + * More information on Run lifecycles can be found here: + * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps + */ async createAndRunPoll(body, options) { + const run = await this.createAndRun(body, options); + return await this.runs.poll(run.thread_id, run.id, options); + } + /** + * Create a thread and stream the run back + */ createAndRunStream(body, options) { + return AssistantStream_1.AssistantStream.createThreadAssistantStream(body, this._client.beta.threads, options); + } +} +exports.Threads = Threads; +Threads.Runs = runs_1.Runs; +Threads.RunsPage = runs_1.RunsPage; +Threads.Messages = messages_1.Messages; +Threads.MessagesPage = messages_1.MessagesPage; + +},{"3255d3d2c9989c7d":"kPMwm","3044ea6c3051ba9e":"haosB","792b307e20aaaaa7":"izIxx","56a81e319684dd15":"lXfF8","c1e8e1f4c6465bec":"f09z1"}],"izIxx":[function(require,module,exports,__globalThis) { +"use strict"; +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function(receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function(receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; +}; +var _AssistantStream_instances, _AssistantStream_events, _AssistantStream_runStepSnapshots, _AssistantStream_messageSnapshots, _AssistantStream_messageSnapshot, _AssistantStream_finalRun, _AssistantStream_currentContentIndex, _AssistantStream_currentContent, _AssistantStream_currentToolCallIndex, _AssistantStream_currentToolCall, _AssistantStream_currentEvent, _AssistantStream_currentRunSnapshot, _AssistantStream_currentRunStepSnapshot, _AssistantStream_addEvent, _AssistantStream_endRequest, _AssistantStream_handleMessage, _AssistantStream_handleRunStep, _AssistantStream_handleEvent, _AssistantStream_accumulateRunStep, _AssistantStream_accumulateMessage, _AssistantStream_accumulateContent, _AssistantStream_handleRun; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.AssistantStream = void 0; +const Core = __importStar(require("d6cd8ed7023bf9e8")); +const streaming_1 = require("fc24bb6d749c8827"); +const error_1 = require("2feae34d7197ea81"); +const EventStream_1 = require("26d128d2dfdae8a1"); +class AssistantStream extends EventStream_1.EventStream { + constructor(){ + super(...arguments); + _AssistantStream_instances.add(this); + //Track all events in a single list for reference + _AssistantStream_events.set(this, []); + //Used to accumulate deltas + //We are accumulating many types so the value here is not strict + _AssistantStream_runStepSnapshots.set(this, {}); + _AssistantStream_messageSnapshots.set(this, {}); + _AssistantStream_messageSnapshot.set(this, void 0); + _AssistantStream_finalRun.set(this, void 0); + _AssistantStream_currentContentIndex.set(this, void 0); + _AssistantStream_currentContent.set(this, void 0); + _AssistantStream_currentToolCallIndex.set(this, void 0); + _AssistantStream_currentToolCall.set(this, void 0); + //For current snapshot methods + _AssistantStream_currentEvent.set(this, void 0); + _AssistantStream_currentRunSnapshot.set(this, void 0); + _AssistantStream_currentRunStepSnapshot.set(this, void 0); + } + [(_AssistantStream_events = new WeakMap(), _AssistantStream_runStepSnapshots = new WeakMap(), _AssistantStream_messageSnapshots = new WeakMap(), _AssistantStream_messageSnapshot = new WeakMap(), _AssistantStream_finalRun = new WeakMap(), _AssistantStream_currentContentIndex = new WeakMap(), _AssistantStream_currentContent = new WeakMap(), _AssistantStream_currentToolCallIndex = new WeakMap(), _AssistantStream_currentToolCall = new WeakMap(), _AssistantStream_currentEvent = new WeakMap(), _AssistantStream_currentRunSnapshot = new WeakMap(), _AssistantStream_currentRunStepSnapshot = new WeakMap(), _AssistantStream_instances = new WeakSet(), Symbol.asyncIterator)]() { + const pushQueue = []; + const readQueue = []; + let done = false; + //Catch all for passing along all events + this.on('event', (event)=>{ + const reader = readQueue.shift(); + if (reader) reader.resolve(event); + else pushQueue.push(event); + }); + this.on('end', ()=>{ + done = true; + for (const reader of readQueue)reader.resolve(undefined); + readQueue.length = 0; + }); + this.on('abort', (err)=>{ + done = true; + for (const reader of readQueue)reader.reject(err); + readQueue.length = 0; + }); + this.on('error', (err)=>{ + done = true; + for (const reader of readQueue)reader.reject(err); + readQueue.length = 0; + }); + return { + next: async ()=>{ + if (!pushQueue.length) { + if (done) return { + value: undefined, + done: true + }; + return new Promise((resolve, reject)=>readQueue.push({ + resolve, + reject + })).then((chunk)=>chunk ? { + value: chunk, + done: false + } : { + value: undefined, + done: true + }); + } + const chunk = pushQueue.shift(); + return { + value: chunk, + done: false + }; + }, + return: async ()=>{ + this.abort(); + return { + value: undefined, + done: true + }; + } + }; + } + static fromReadableStream(stream) { + const runner = new AssistantStream(); + runner._run(()=>runner._fromReadableStream(stream)); + return runner; + } + async _fromReadableStream(readableStream, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + this._connected(); + const stream = streaming_1.Stream.fromReadableStream(readableStream, this.controller); + for await (const event of stream)__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event); + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this)); + } + toReadableStream() { + const stream = new streaming_1.Stream(this[Symbol.asyncIterator].bind(this), this.controller); + return stream.toReadableStream(); + } + static createToolAssistantStream(threadId, runId, runs, params, options) { + const runner = new AssistantStream(); + runner._run(()=>runner._runToolAssistantStream(threadId, runId, runs, params, { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'stream' + } + })); + return runner; + } + async _createToolAssistantStream(run, threadId, runId, params, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + const body = { + ...params, + stream: true + }; + const stream = await run.submitToolOutputs(threadId, runId, body, { + ...options, + signal: this.controller.signal + }); + this._connected(); + for await (const event of stream)__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event); + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this)); + } + static createThreadAssistantStream(params, thread, options) { + const runner = new AssistantStream(); + runner._run(()=>runner._threadAssistantStream(params, thread, { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'stream' + } + })); + return runner; + } + static createAssistantStream(threadId, runs, params, options) { + const runner = new AssistantStream(); + runner._run(()=>runner._runAssistantStream(threadId, runs, params, { + ...options, + headers: { + ...options?.headers, + 'X-Stainless-Helper-Method': 'stream' + } + })); + return runner; + } + currentEvent() { + return __classPrivateFieldGet(this, _AssistantStream_currentEvent, "f"); + } + currentRun() { + return __classPrivateFieldGet(this, _AssistantStream_currentRunSnapshot, "f"); + } + currentMessageSnapshot() { + return __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"); + } + currentRunStepSnapshot() { + return __classPrivateFieldGet(this, _AssistantStream_currentRunStepSnapshot, "f"); + } + async finalRunSteps() { + await this.done(); + return Object.values(__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")); + } + async finalMessages() { + await this.done(); + return Object.values(__classPrivateFieldGet(this, _AssistantStream_messageSnapshots, "f")); + } + async finalRun() { + await this.done(); + if (!__classPrivateFieldGet(this, _AssistantStream_finalRun, "f")) throw Error('Final run was not received.'); + return __classPrivateFieldGet(this, _AssistantStream_finalRun, "f"); + } + async _createThreadAssistantStream(thread, params, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + const body = { + ...params, + stream: true + }; + const stream = await thread.createAndRun(body, { + ...options, + signal: this.controller.signal + }); + this._connected(); + for await (const event of stream)__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event); + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this)); + } + async _createAssistantStream(run, threadId, params, options) { + const signal = options?.signal; + if (signal) { + if (signal.aborted) this.controller.abort(); + signal.addEventListener('abort', ()=>this.controller.abort()); + } + const body = { + ...params, + stream: true + }; + const stream = await run.create(threadId, body, { + ...options, + signal: this.controller.signal + }); + this._connected(); + for await (const event of stream)__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event); + if (stream.controller.signal?.aborted) throw new error_1.APIUserAbortError(); + return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this)); + } + static accumulateDelta(acc, delta) { + for (const [key, deltaValue] of Object.entries(delta)){ + if (!acc.hasOwnProperty(key)) { + acc[key] = deltaValue; + continue; + } + let accValue = acc[key]; + if (accValue === null || accValue === undefined) { + acc[key] = deltaValue; + continue; + } + // We don't accumulate these special properties + if (key === 'index' || key === 'type') { + acc[key] = deltaValue; + continue; + } + // Type-specific accumulation logic + if (typeof accValue === 'string' && typeof deltaValue === 'string') accValue += deltaValue; + else if (typeof accValue === 'number' && typeof deltaValue === 'number') accValue += deltaValue; + else if (Core.isObj(accValue) && Core.isObj(deltaValue)) accValue = this.accumulateDelta(accValue, deltaValue); + else if (Array.isArray(accValue) && Array.isArray(deltaValue)) { + if (accValue.every((x)=>typeof x === 'string' || typeof x === 'number')) { + accValue.push(...deltaValue); // Use spread syntax for efficient addition + continue; + } + for (const deltaEntry of deltaValue){ + if (!Core.isObj(deltaEntry)) throw new Error(`Expected array delta entry to be an object but got: ${deltaEntry}`); + const index = deltaEntry['index']; + if (index == null) { + console.error(deltaEntry); + throw new Error('Expected array delta entry to have an `index` property'); + } + if (typeof index !== 'number') throw new Error(`Expected array delta entry \`index\` property to be a number but got ${index}`); + const accEntry = accValue[index]; + if (accEntry == null) accValue.push(deltaEntry); + else accValue[index] = this.accumulateDelta(accEntry, deltaEntry); + } + continue; + } else throw Error(`Unhandled record type: ${key}, deltaValue: ${deltaValue}, accValue: ${accValue}`); + acc[key] = accValue; + } + return acc; + } + _addRun(run) { + return run; + } + async _threadAssistantStream(params, thread, options) { + return await this._createThreadAssistantStream(thread, params, options); + } + async _runAssistantStream(threadId, runs, params, options) { + return await this._createAssistantStream(runs, threadId, params, options); + } + async _runToolAssistantStream(threadId, runId, runs, params, options) { + return await this._createToolAssistantStream(runs, threadId, runId, params, options); + } +} +exports.AssistantStream = AssistantStream; +_AssistantStream_addEvent = function _AssistantStream_addEvent(event) { + if (this.ended) return; + __classPrivateFieldSet(this, _AssistantStream_currentEvent, event, "f"); + __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleEvent).call(this, event); + switch(event.event){ + case 'thread.created': + break; + case 'thread.run.created': + case 'thread.run.queued': + case 'thread.run.in_progress': + case 'thread.run.requires_action': + case 'thread.run.completed': + case 'thread.run.incomplete': + case 'thread.run.failed': + case 'thread.run.cancelling': + case 'thread.run.cancelled': + case 'thread.run.expired': + __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleRun).call(this, event); + break; + case 'thread.run.step.created': + case 'thread.run.step.in_progress': + case 'thread.run.step.delta': + case 'thread.run.step.completed': + case 'thread.run.step.failed': + case 'thread.run.step.cancelled': + case 'thread.run.step.expired': + __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleRunStep).call(this, event); + break; + case 'thread.message.created': + case 'thread.message.in_progress': + case 'thread.message.delta': + case 'thread.message.completed': + case 'thread.message.incomplete': + __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleMessage).call(this, event); + break; + case 'error': + //This is included for completeness, but errors are processed in the SSE event processing so this should not occur + throw new Error('Encountered an error event in event processing - errors should be processed earlier'); + default: + assertNever(event); + } +}, _AssistantStream_endRequest = function _AssistantStream_endRequest() { + if (this.ended) throw new error_1.OpenAIError(`stream has ended, this shouldn't happen`); + if (!__classPrivateFieldGet(this, _AssistantStream_finalRun, "f")) throw Error('Final run has not been received'); + return __classPrivateFieldGet(this, _AssistantStream_finalRun, "f"); +}, _AssistantStream_handleMessage = function _AssistantStream_handleMessage(event) { + const [accumulatedMessage, newContent] = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateMessage).call(this, event, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")); + __classPrivateFieldSet(this, _AssistantStream_messageSnapshot, accumulatedMessage, "f"); + __classPrivateFieldGet(this, _AssistantStream_messageSnapshots, "f")[accumulatedMessage.id] = accumulatedMessage; + for (const content of newContent){ + const snapshotContent = accumulatedMessage.content[content.index]; + if (snapshotContent?.type == 'text') this._emit('textCreated', snapshotContent.text); + } + switch(event.event){ + case 'thread.message.created': + this._emit('messageCreated', event.data); + break; + case 'thread.message.in_progress': + break; + case 'thread.message.delta': + this._emit('messageDelta', event.data.delta, accumulatedMessage); + if (event.data.delta.content) for (const content of event.data.delta.content){ + //If it is text delta, emit a text delta event + if (content.type == 'text' && content.text) { + let textDelta = content.text; + let snapshot = accumulatedMessage.content[content.index]; + if (snapshot && snapshot.type == 'text') this._emit('textDelta', textDelta, snapshot.text); + else throw Error('The snapshot associated with this text delta is not text or missing'); + } + if (content.index != __classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f")) { + //See if we have in progress content + if (__classPrivateFieldGet(this, _AssistantStream_currentContent, "f")) switch(__classPrivateFieldGet(this, _AssistantStream_currentContent, "f").type){ + case 'text': + this._emit('textDone', __classPrivateFieldGet(this, _AssistantStream_currentContent, "f").text, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")); + break; + case 'image_file': + this._emit('imageFileDone', __classPrivateFieldGet(this, _AssistantStream_currentContent, "f").image_file, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")); + break; + } + __classPrivateFieldSet(this, _AssistantStream_currentContentIndex, content.index, "f"); + } + __classPrivateFieldSet(this, _AssistantStream_currentContent, accumulatedMessage.content[content.index], "f"); + } + break; + case 'thread.message.completed': + case 'thread.message.incomplete': + //We emit the latest content we were working on on completion (including incomplete) + if (__classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f") !== undefined) { + const currentContent = event.data.content[__classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f")]; + if (currentContent) switch(currentContent.type){ + case 'image_file': + this._emit('imageFileDone', currentContent.image_file, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")); + break; + case 'text': + this._emit('textDone', currentContent.text, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")); + break; + } + } + if (__classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")) this._emit('messageDone', event.data); + __classPrivateFieldSet(this, _AssistantStream_messageSnapshot, undefined, "f"); + } +}, _AssistantStream_handleRunStep = function _AssistantStream_handleRunStep(event) { + const accumulatedRunStep = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateRunStep).call(this, event); + __classPrivateFieldSet(this, _AssistantStream_currentRunStepSnapshot, accumulatedRunStep, "f"); + switch(event.event){ + case 'thread.run.step.created': + this._emit('runStepCreated', event.data); + break; + case 'thread.run.step.delta': + const delta = event.data.delta; + if (delta.step_details && delta.step_details.type == 'tool_calls' && delta.step_details.tool_calls && accumulatedRunStep.step_details.type == 'tool_calls') { + for (const toolCall of delta.step_details.tool_calls)if (toolCall.index == __classPrivateFieldGet(this, _AssistantStream_currentToolCallIndex, "f")) this._emit('toolCallDelta', toolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index]); + else { + if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")); + __classPrivateFieldSet(this, _AssistantStream_currentToolCallIndex, toolCall.index, "f"); + __classPrivateFieldSet(this, _AssistantStream_currentToolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index], "f"); + if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) this._emit('toolCallCreated', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")); + } + } + this._emit('runStepDelta', event.data.delta, accumulatedRunStep); + break; + case 'thread.run.step.completed': + case 'thread.run.step.failed': + case 'thread.run.step.cancelled': + case 'thread.run.step.expired': + __classPrivateFieldSet(this, _AssistantStream_currentRunStepSnapshot, undefined, "f"); + const details = event.data.step_details; + if (details.type == 'tool_calls') { + if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) { + this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")); + __classPrivateFieldSet(this, _AssistantStream_currentToolCall, undefined, "f"); + } + } + this._emit('runStepDone', event.data, accumulatedRunStep); + break; + case 'thread.run.step.in_progress': + break; + } +}, _AssistantStream_handleEvent = function _AssistantStream_handleEvent(event) { + __classPrivateFieldGet(this, _AssistantStream_events, "f").push(event); + this._emit('event', event); +}, _AssistantStream_accumulateRunStep = function _AssistantStream_accumulateRunStep(event) { + switch(event.event){ + case 'thread.run.step.created': + __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data; + return event.data; + case 'thread.run.step.delta': + let snapshot = __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id]; + if (!snapshot) throw Error('Received a RunStepDelta before creation of a snapshot'); + let data = event.data; + if (data.delta) { + const accumulated = AssistantStream.accumulateDelta(snapshot, data.delta); + __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = accumulated; + } + return __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id]; + case 'thread.run.step.completed': + case 'thread.run.step.failed': + case 'thread.run.step.cancelled': + case 'thread.run.step.expired': + case 'thread.run.step.in_progress': + __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data; + break; + } + if (__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id]) return __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id]; + throw new Error('No snapshot available'); +}, _AssistantStream_accumulateMessage = function _AssistantStream_accumulateMessage(event, snapshot) { + let newContent = []; + switch(event.event){ + case 'thread.message.created': + //On creation the snapshot is just the initial message + return [ + event.data, + newContent + ]; + case 'thread.message.delta': + if (!snapshot) throw Error('Received a delta with no existing snapshot (there should be one from message creation)'); + let data = event.data; + //If this delta does not have content, nothing to process + if (data.delta.content) { + for (const contentElement of data.delta.content)if (contentElement.index in snapshot.content) { + let currentContent = snapshot.content[contentElement.index]; + snapshot.content[contentElement.index] = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateContent).call(this, contentElement, currentContent); + } else { + snapshot.content[contentElement.index] = contentElement; + // This is a new element + newContent.push(contentElement); + } + } + return [ + snapshot, + newContent + ]; + case 'thread.message.in_progress': + case 'thread.message.completed': + case 'thread.message.incomplete': + //No changes on other thread events + if (snapshot) return [ + snapshot, + newContent + ]; + else throw Error('Received thread message event with no existing snapshot'); + } + throw Error('Tried to accumulate a non-message event'); +}, _AssistantStream_accumulateContent = function _AssistantStream_accumulateContent(contentElement, currentContent) { + return AssistantStream.accumulateDelta(currentContent, contentElement); +}, _AssistantStream_handleRun = function _AssistantStream_handleRun(event) { + __classPrivateFieldSet(this, _AssistantStream_currentRunSnapshot, event.data, "f"); + switch(event.event){ + case 'thread.run.created': + break; + case 'thread.run.queued': + break; + case 'thread.run.in_progress': + break; + case 'thread.run.requires_action': + case 'thread.run.cancelled': + case 'thread.run.failed': + case 'thread.run.completed': + case 'thread.run.expired': + __classPrivateFieldSet(this, _AssistantStream_finalRun, event.data, "f"); + if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) { + this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")); + __classPrivateFieldSet(this, _AssistantStream_currentToolCall, undefined, "f"); + } + break; + case 'thread.run.cancelling': + break; + } +}; +function assertNever(_x) {} + +},{"d6cd8ed7023bf9e8":"haosB","fc24bb6d749c8827":"2gNIj","2feae34d7197ea81":"lRecV","26d128d2dfdae8a1":"3zcw5"}],"lXfF8":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.MessagesPage = exports.Messages = void 0; +const resource_1 = require("ccacdb25c4bc0c8d"); +const core_1 = require("27a73dd6d6e6dd12"); +const pagination_1 = require("73d51f1cdf77b7c7"); +class Messages extends resource_1.APIResource { + /** + * Create a message. + */ create(threadId, body, options) { + return this._client.post(`/threads/${threadId}/messages`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieve a message. + */ retrieve(threadId, messageId, options) { + return this._client.get(`/threads/${threadId}/messages/${messageId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Modifies a message. + */ update(threadId, messageId, body, options) { + return this._client.post(`/threads/${threadId}/messages/${messageId}`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(threadId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(threadId, {}, query); + return this._client.getAPIList(`/threads/${threadId}/messages`, MessagesPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Deletes a message. + */ del(threadId, messageId, options) { + return this._client.delete(`/threads/${threadId}/messages/${messageId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } +} +exports.Messages = Messages; +class MessagesPage extends pagination_1.CursorPage { +} +exports.MessagesPage = MessagesPage; +Messages.MessagesPage = MessagesPage; + +},{"ccacdb25c4bc0c8d":"kPMwm","27a73dd6d6e6dd12":"haosB","73d51f1cdf77b7c7":"jePq8"}],"f09z1":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.RunsPage = exports.Runs = void 0; +const resource_1 = require("c1810b898216bffd"); +const core_1 = require("9f4ca446a480969"); +const AssistantStream_1 = require("5e9128308d9d51f7"); +const core_2 = require("9f4ca446a480969"); +const StepsAPI = __importStar(require("5c5e592d26603751")); +const steps_1 = require("5c5e592d26603751"); +const pagination_1 = require("a9d078c622ff2554"); +class Runs extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.steps = new StepsAPI.Steps(this._client); + } + create(threadId, params, options) { + const { include, ...body } = params; + return this._client.post(`/threads/${threadId}/runs`, { + query: { + include + }, + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + }, + stream: params.stream ?? false + }); + } + /** + * Retrieves a run. + */ retrieve(threadId, runId, options) { + return this._client.get(`/threads/${threadId}/runs/${runId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Modifies a run. + */ update(threadId, runId, body, options) { + return this._client.post(`/threads/${threadId}/runs/${runId}`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(threadId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(threadId, {}, query); + return this._client.getAPIList(`/threads/${threadId}/runs`, RunsPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Cancels a run that is `in_progress`. + */ cancel(threadId, runId, options) { + return this._client.post(`/threads/${threadId}/runs/${runId}/cancel`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * A helper to create a run an poll for a terminal state. More information on Run + * lifecycles can be found here: + * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps + */ async createAndPoll(threadId, body, options) { + const run = await this.create(threadId, body, options); + return await this.poll(threadId, run.id, options); + } + /** + * Create a Run stream + * + * @deprecated use `stream` instead + */ createAndStream(threadId, body, options) { + return AssistantStream_1.AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options); + } + /** + * A helper to poll a run status until it reaches a terminal state. More + * information on Run lifecycles can be found here: + * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps + */ async poll(threadId, runId, options) { + const headers = { + ...options?.headers, + 'X-Stainless-Poll-Helper': 'true' + }; + if (options?.pollIntervalMs) headers['X-Stainless-Custom-Poll-Interval'] = options.pollIntervalMs.toString(); + while(true){ + const { data: run, response } = await this.retrieve(threadId, runId, { + ...options, + headers: { + ...options?.headers, + ...headers + } + }).withResponse(); + switch(run.status){ + //If we are in any sort of intermediate state we poll + case 'queued': + case 'in_progress': + case 'cancelling': + let sleepInterval = 5000; + if (options?.pollIntervalMs) sleepInterval = options.pollIntervalMs; + else { + const headerInterval = response.headers.get('openai-poll-after-ms'); + if (headerInterval) { + const headerIntervalMs = parseInt(headerInterval); + if (!isNaN(headerIntervalMs)) sleepInterval = headerIntervalMs; + } + } + await (0, core_2.sleep)(sleepInterval); + break; + //We return the run in any terminal state. + case 'requires_action': + case 'incomplete': + case 'cancelled': + case 'completed': + case 'failed': + case 'expired': + return run; + } + } + } + /** + * Create a Run stream + */ stream(threadId, body, options) { + return AssistantStream_1.AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options); + } + submitToolOutputs(threadId, runId, body, options) { + return this._client.post(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + }, + stream: body.stream ?? false + }); + } + /** + * A helper to submit a tool output to a run and poll for a terminal run state. + * More information on Run lifecycles can be found here: + * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps + */ async submitToolOutputsAndPoll(threadId, runId, body, options) { + const run = await this.submitToolOutputs(threadId, runId, body, options); + return await this.poll(threadId, run.id, options); + } + /** + * Submit the tool outputs from a previous run and stream the run to a terminal + * state. More information on Run lifecycles can be found here: + * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps + */ submitToolOutputsStream(threadId, runId, body, options) { + return AssistantStream_1.AssistantStream.createToolAssistantStream(threadId, runId, this._client.beta.threads.runs, body, options); + } +} +exports.Runs = Runs; +class RunsPage extends pagination_1.CursorPage { +} +exports.RunsPage = RunsPage; +Runs.RunsPage = RunsPage; +Runs.Steps = steps_1.Steps; +Runs.RunStepsPage = steps_1.RunStepsPage; + +},{"c1810b898216bffd":"kPMwm","9f4ca446a480969":"haosB","5e9128308d9d51f7":"izIxx","5c5e592d26603751":"jE616","a9d078c622ff2554":"jePq8"}],"jE616":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.RunStepsPage = exports.Steps = void 0; +const resource_1 = require("4da65600b8482b85"); +const core_1 = require("c00329c98d9058a7"); +const pagination_1 = require("6c6be1d28e7761f2"); +class Steps extends resource_1.APIResource { + retrieve(threadId, runId, stepId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.retrieve(threadId, runId, stepId, {}, query); + return this._client.get(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(threadId, runId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(threadId, runId, {}, query); + return this._client.getAPIList(`/threads/${threadId}/runs/${runId}/steps`, RunStepsPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } +} +exports.Steps = Steps; +class RunStepsPage extends pagination_1.CursorPage { +} +exports.RunStepsPage = RunStepsPage; +Steps.RunStepsPage = RunStepsPage; + +},{"4da65600b8482b85":"kPMwm","c00329c98d9058a7":"haosB","6c6be1d28e7761f2":"jePq8"}],"jSaPI":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.VectorStoresPage = exports.VectorStores = void 0; +const resource_1 = require("375a5cdb57c792a6"); +const core_1 = require("fe648b0a7d306610"); +const FileBatchesAPI = __importStar(require("61e83ba5369c23e8")); +const file_batches_1 = require("61e83ba5369c23e8"); +const FilesAPI = __importStar(require("a8100cdcb6d76901")); +const files_1 = require("a8100cdcb6d76901"); +const pagination_1 = require("36d83c0f00c9fd55"); +class VectorStores extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.files = new FilesAPI.Files(this._client); + this.fileBatches = new FileBatchesAPI.FileBatches(this._client); + } + /** + * Create a vector store. + */ create(body, options) { + return this._client.post('/vector_stores', { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieves a vector store. + */ retrieve(vectorStoreId, options) { + return this._client.get(`/vector_stores/${vectorStoreId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Modifies a vector store. + */ update(vectorStoreId, body, options) { + return this._client.post(`/vector_stores/${vectorStoreId}`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/vector_stores', VectorStoresPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Delete a vector store. + */ del(vectorStoreId, options) { + return this._client.delete(`/vector_stores/${vectorStoreId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } +} +exports.VectorStores = VectorStores; +class VectorStoresPage extends pagination_1.CursorPage { +} +exports.VectorStoresPage = VectorStoresPage; +VectorStores.VectorStoresPage = VectorStoresPage; +VectorStores.Files = files_1.Files; +VectorStores.VectorStoreFilesPage = files_1.VectorStoreFilesPage; +VectorStores.FileBatches = file_batches_1.FileBatches; + +},{"375a5cdb57c792a6":"kPMwm","fe648b0a7d306610":"haosB","61e83ba5369c23e8":"iUjq5","a8100cdcb6d76901":"4iBYH","36d83c0f00c9fd55":"jePq8"}],"iUjq5":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.VectorStoreFilesPage = exports.FileBatches = void 0; +const resource_1 = require("a0e67baab8d956c4"); +const core_1 = require("94a17d2d22a1cf5a"); +const core_2 = require("94a17d2d22a1cf5a"); +const Util_1 = require("36f7ac26f76a8d45"); +const files_1 = require("d2a9efdde12b8f91"); +Object.defineProperty(exports, "VectorStoreFilesPage", { + enumerable: true, + get: function() { + return files_1.VectorStoreFilesPage; + } +}); +class FileBatches extends resource_1.APIResource { + /** + * Create a vector store file batch. + */ create(vectorStoreId, body, options) { + return this._client.post(`/vector_stores/${vectorStoreId}/file_batches`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieves a vector store file batch. + */ retrieve(vectorStoreId, batchId, options) { + return this._client.get(`/vector_stores/${vectorStoreId}/file_batches/${batchId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Cancel a vector store file batch. This attempts to cancel the processing of + * files in this batch as soon as possible. + */ cancel(vectorStoreId, batchId, options) { + return this._client.post(`/vector_stores/${vectorStoreId}/file_batches/${batchId}/cancel`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Create a vector store batch and poll until all files have been processed. + */ async createAndPoll(vectorStoreId, body, options) { + const batch = await this.create(vectorStoreId, body); + return await this.poll(vectorStoreId, batch.id, options); + } + listFiles(vectorStoreId, batchId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.listFiles(vectorStoreId, batchId, {}, query); + return this._client.getAPIList(`/vector_stores/${vectorStoreId}/file_batches/${batchId}/files`, files_1.VectorStoreFilesPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Wait for the given file batch to be processed. + * + * Note: this will return even if one of the files failed to process, you need to + * check batch.file_counts.failed_count to handle this case. + */ async poll(vectorStoreId, batchId, options) { + const headers = { + ...options?.headers, + 'X-Stainless-Poll-Helper': 'true' + }; + if (options?.pollIntervalMs) headers['X-Stainless-Custom-Poll-Interval'] = options.pollIntervalMs.toString(); + while(true){ + const { data: batch, response } = await this.retrieve(vectorStoreId, batchId, { + ...options, + headers + }).withResponse(); + switch(batch.status){ + case 'in_progress': + let sleepInterval = 5000; + if (options?.pollIntervalMs) sleepInterval = options.pollIntervalMs; + else { + const headerInterval = response.headers.get('openai-poll-after-ms'); + if (headerInterval) { + const headerIntervalMs = parseInt(headerInterval); + if (!isNaN(headerIntervalMs)) sleepInterval = headerIntervalMs; + } + } + await (0, core_2.sleep)(sleepInterval); + break; + case 'failed': + case 'cancelled': + case 'completed': + return batch; + } + } + } + /** + * Uploads the given files concurrently and then creates a vector store file batch. + * + * The concurrency limit is configurable using the `maxConcurrency` parameter. + */ async uploadAndPoll(vectorStoreId, { files, fileIds = [] }, options) { + if (files == null || files.length == 0) throw new Error(`No \`files\` provided to process. If you've already uploaded files you should use \`.createAndPoll()\` instead`); + const configuredConcurrency = options?.maxConcurrency ?? 5; + // We cap the number of workers at the number of files (so we don't start any unnecessary workers) + const concurrencyLimit = Math.min(configuredConcurrency, files.length); + const client = this._client; + const fileIterator = files.values(); + const allFileIds = [ + ...fileIds + ]; + // This code is based on this design. The libraries don't accommodate our environment limits. + // https://stackoverflow.com/questions/40639432/what-is-the-best-way-to-limit-concurrency-when-using-es6s-promise-all + async function processFiles(iterator) { + for (let item of iterator){ + const fileObj = await client.files.create({ + file: item, + purpose: 'assistants' + }, options); + allFileIds.push(fileObj.id); + } + } + // Start workers to process results + const workers = Array(concurrencyLimit).fill(fileIterator).map(processFiles); + // Wait for all processing to complete. + await (0, Util_1.allSettledWithThrow)(workers); + return await this.createAndPoll(vectorStoreId, { + file_ids: allFileIds + }); + } +} +exports.FileBatches = FileBatches; + +},{"a0e67baab8d956c4":"kPMwm","94a17d2d22a1cf5a":"haosB","36f7ac26f76a8d45":"6eHHk","d2a9efdde12b8f91":"4iBYH"}],"6eHHk":[function(require,module,exports,__globalThis) { +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.allSettledWithThrow = void 0; +/** + * Like `Promise.allSettled()` but throws an error if any promises are rejected. + */ const allSettledWithThrow = async (promises)=>{ + const results = await Promise.allSettled(promises); + const rejected = results.filter((result)=>result.status === 'rejected'); + if (rejected.length) { + for (const result of rejected)console.error(result.reason); + throw new Error(`${rejected.length} promise(s) failed - see the above errors`); + } + // Note: TS was complaining about using `.filter().map()` here for some reason + const values = []; + for (const result of results)if (result.status === 'fulfilled') values.push(result.value); + return values; +}; +exports.allSettledWithThrow = allSettledWithThrow; + +},{}],"4iBYH":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.VectorStoreFilesPage = exports.Files = void 0; +const resource_1 = require("73f47f71045eeadc"); +const core_1 = require("cf92c3d22ba9a85b"); +const pagination_1 = require("fa9bcb7f23976f8c"); +class Files extends resource_1.APIResource { + /** + * Create a vector store file by attaching a + * [File](https://platform.openai.com/docs/api-reference/files) to a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object). + */ create(vectorStoreId, body, options) { + return this._client.post(`/vector_stores/${vectorStoreId}/files`, { + body, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Retrieves a vector store file. + */ retrieve(vectorStoreId, fileId, options) { + return this._client.get(`/vector_stores/${vectorStoreId}/files/${fileId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + list(vectorStoreId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(vectorStoreId, {}, query); + return this._client.getAPIList(`/vector_stores/${vectorStoreId}/files`, VectorStoreFilesPage, { + query, + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Delete a vector store file. This will remove the file from the vector store but + * the file itself will not be deleted. To delete the file, use the + * [delete file](https://platform.openai.com/docs/api-reference/files/delete) + * endpoint. + */ del(vectorStoreId, fileId, options) { + return this._client.delete(`/vector_stores/${vectorStoreId}/files/${fileId}`, { + ...options, + headers: { + 'OpenAI-Beta': 'assistants=v2', + ...options?.headers + } + }); + } + /** + * Attach a file to the given vector store and wait for it to be processed. + */ async createAndPoll(vectorStoreId, body, options) { + const file = await this.create(vectorStoreId, body, options); + return await this.poll(vectorStoreId, file.id, options); + } + /** + * Wait for the vector store file to finish processing. + * + * Note: this will return even if the file failed to process, you need to check + * file.last_error and file.status to handle these cases + */ async poll(vectorStoreId, fileId, options) { + const headers = { + ...options?.headers, + 'X-Stainless-Poll-Helper': 'true' + }; + if (options?.pollIntervalMs) headers['X-Stainless-Custom-Poll-Interval'] = options.pollIntervalMs.toString(); + while(true){ + const fileResponse = await this.retrieve(vectorStoreId, fileId, { + ...options, + headers + }).withResponse(); + const file = fileResponse.data; + switch(file.status){ + case 'in_progress': + let sleepInterval = 5000; + if (options?.pollIntervalMs) sleepInterval = options.pollIntervalMs; + else { + const headerInterval = fileResponse.response.headers.get('openai-poll-after-ms'); + if (headerInterval) { + const headerIntervalMs = parseInt(headerInterval); + if (!isNaN(headerIntervalMs)) sleepInterval = headerIntervalMs; + } + } + await (0, core_1.sleep)(sleepInterval); + break; + case 'failed': + case 'completed': + return file; + } + } + } + /** + * Upload a file to the `files` API and then attach it to the given vector store. + * + * Note the file will be asynchronously processed (you can use the alternative + * polling helper method to wait for processing to complete). + */ async upload(vectorStoreId, file, options) { + const fileInfo = await this._client.files.create({ + file: file, + purpose: 'assistants' + }, options); + return this.create(vectorStoreId, { + file_id: fileInfo.id + }, options); + } + /** + * Add a file to a vector store and poll until processing is complete. + */ async uploadAndPoll(vectorStoreId, file, options) { + const fileInfo = await this.upload(vectorStoreId, file, options); + return await this.poll(vectorStoreId, fileInfo.id, options); + } +} +exports.Files = Files; +class VectorStoreFilesPage extends pagination_1.CursorPage { +} +exports.VectorStoreFilesPage = VectorStoreFilesPage; +Files.VectorStoreFilesPage = VectorStoreFilesPage; + +},{"73f47f71045eeadc":"kPMwm","cf92c3d22ba9a85b":"haosB","fa9bcb7f23976f8c":"jePq8"}],"cig5h":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Completions = void 0; +const resource_1 = require("a01b44df83810392"); +class Completions extends resource_1.APIResource { + create(body, options) { + return this._client.post('/completions', { + body, + ...options, + stream: body.stream ?? false + }); + } +} +exports.Completions = Completions; + +},{"a01b44df83810392":"kPMwm"}],"5Emd7":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Embeddings = void 0; +const resource_1 = require("a09530080d1baa01"); +class Embeddings extends resource_1.APIResource { + /** + * Creates an embedding vector representing the input text. + */ create(body, options) { + return this._client.post('/embeddings', { + body, + ...options + }); + } +} +exports.Embeddings = Embeddings; + +},{"a09530080d1baa01":"kPMwm"}],"jXD91":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.FileObjectsPage = exports.Files = void 0; +const resource_1 = require("6f1730549106d008"); +const core_1 = require("65729fe5ab38e7fc"); +const core_2 = require("65729fe5ab38e7fc"); +const error_1 = require("a87ec1f6d0991d08"); +const Core = __importStar(require("65729fe5ab38e7fc")); +const pagination_1 = require("cfcb0bab8a7abd2d"); +class Files extends resource_1.APIResource { + /** + * Upload a file that can be used across various endpoints. Individual files can be + * up to 512 MB, and the size of all files uploaded by one organization can be up + * to 100 GB. + * + * The Assistants API supports files up to 2 million tokens and of specific file + * types. See the + * [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for + * details. + * + * The Fine-tuning API only supports `.jsonl` files. The input also has certain + * required formats for fine-tuning + * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or + * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input) + * models. + * + * The Batch API only supports `.jsonl` files up to 200 MB in size. The input also + * has a specific required + * [format](https://platform.openai.com/docs/api-reference/batch/request-input). + * + * Please [contact us](https://help.openai.com/) if you need to increase these + * storage limits. + */ create(body, options) { + return this._client.post('/files', Core.multipartFormRequestOptions({ + body, + ...options + })); + } + /** + * Returns information about a specific file. + */ retrieve(fileId, options) { + return this._client.get(`/files/${fileId}`, options); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/files', FileObjectsPage, { + query, + ...options + }); + } + /** + * Delete a file. + */ del(fileId, options) { + return this._client.delete(`/files/${fileId}`, options); + } + /** + * Returns the contents of the specified file. + */ content(fileId, options) { + return this._client.get(`/files/${fileId}/content`, { + ...options, + headers: { + Accept: 'application/binary', + ...options?.headers + }, + __binaryResponse: true + }); + } + /** + * Returns the contents of the specified file. + * + * @deprecated The `.content()` method should be used instead + */ retrieveContent(fileId, options) { + return this._client.get(`/files/${fileId}/content`, options); + } + /** + * Waits for the given file to be processed, default timeout is 30 mins. + */ async waitForProcessing(id, { pollInterval = 5000, maxWait = 1800000 } = {}) { + const TERMINAL_STATES = new Set([ + 'processed', + 'error', + 'deleted' + ]); + const start = Date.now(); + let file = await this.retrieve(id); + while(!file.status || !TERMINAL_STATES.has(file.status)){ + await (0, core_2.sleep)(pollInterval); + file = await this.retrieve(id); + if (Date.now() - start > maxWait) throw new error_1.APIConnectionTimeoutError({ + message: `Giving up on waiting for file ${id} to finish processing after ${maxWait} milliseconds.` + }); + } + return file; + } +} +exports.Files = Files; +class FileObjectsPage extends pagination_1.CursorPage { +} +exports.FileObjectsPage = FileObjectsPage; +Files.FileObjectsPage = FileObjectsPage; + +},{"6f1730549106d008":"kPMwm","65729fe5ab38e7fc":"haosB","a87ec1f6d0991d08":"lRecV","cfcb0bab8a7abd2d":"jePq8"}],"gt3GR":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.FineTuning = void 0; +const resource_1 = require("d7629eaadbae503f"); +const JobsAPI = __importStar(require("408eafe0e6034d76")); +const jobs_1 = require("408eafe0e6034d76"); +class FineTuning extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.jobs = new JobsAPI.Jobs(this._client); + } +} +exports.FineTuning = FineTuning; +FineTuning.Jobs = jobs_1.Jobs; +FineTuning.FineTuningJobsPage = jobs_1.FineTuningJobsPage; +FineTuning.FineTuningJobEventsPage = jobs_1.FineTuningJobEventsPage; + +},{"d7629eaadbae503f":"kPMwm","408eafe0e6034d76":"7W31c"}],"7W31c":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.FineTuningJobEventsPage = exports.FineTuningJobsPage = exports.Jobs = void 0; +const resource_1 = require("e50e5a2b3aa51cf3"); +const core_1 = require("847322b3490dd21d"); +const CheckpointsAPI = __importStar(require("e8ada2d7fff634eb")); +const checkpoints_1 = require("e8ada2d7fff634eb"); +const pagination_1 = require("7c1d882729b3fc14"); +class Jobs extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.checkpoints = new CheckpointsAPI.Checkpoints(this._client); + } + /** + * Creates a fine-tuning job which begins the process of creating a new model from + * a given dataset. + * + * Response includes details of the enqueued job including job status and the name + * of the fine-tuned models once complete. + * + * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) + */ create(body, options) { + return this._client.post('/fine_tuning/jobs', { + body, + ...options + }); + } + /** + * Get info about a fine-tuning job. + * + * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) + */ retrieve(fineTuningJobId, options) { + return this._client.get(`/fine_tuning/jobs/${fineTuningJobId}`, options); + } + list(query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list({}, query); + return this._client.getAPIList('/fine_tuning/jobs', FineTuningJobsPage, { + query, + ...options + }); + } + /** + * Immediately cancel a fine-tune job. + */ cancel(fineTuningJobId, options) { + return this._client.post(`/fine_tuning/jobs/${fineTuningJobId}/cancel`, options); + } + listEvents(fineTuningJobId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.listEvents(fineTuningJobId, {}, query); + return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/events`, FineTuningJobEventsPage, { + query, + ...options + }); + } +} +exports.Jobs = Jobs; +class FineTuningJobsPage extends pagination_1.CursorPage { +} +exports.FineTuningJobsPage = FineTuningJobsPage; +class FineTuningJobEventsPage extends pagination_1.CursorPage { +} +exports.FineTuningJobEventsPage = FineTuningJobEventsPage; +Jobs.FineTuningJobsPage = FineTuningJobsPage; +Jobs.FineTuningJobEventsPage = FineTuningJobEventsPage; +Jobs.Checkpoints = checkpoints_1.Checkpoints; +Jobs.FineTuningJobCheckpointsPage = checkpoints_1.FineTuningJobCheckpointsPage; + +},{"e50e5a2b3aa51cf3":"kPMwm","847322b3490dd21d":"haosB","e8ada2d7fff634eb":"3Ubh1","7c1d882729b3fc14":"jePq8"}],"3Ubh1":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.FineTuningJobCheckpointsPage = exports.Checkpoints = void 0; +const resource_1 = require("c9c867f5295fd282"); +const core_1 = require("95647c2743b9ac5f"); +const pagination_1 = require("fee9049062ecf242"); +class Checkpoints extends resource_1.APIResource { + list(fineTuningJobId, query = {}, options) { + if ((0, core_1.isRequestOptions)(query)) return this.list(fineTuningJobId, {}, query); + return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/checkpoints`, FineTuningJobCheckpointsPage, { + query, + ...options + }); + } +} +exports.Checkpoints = Checkpoints; +class FineTuningJobCheckpointsPage extends pagination_1.CursorPage { +} +exports.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage; +Checkpoints.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage; + +},{"c9c867f5295fd282":"kPMwm","95647c2743b9ac5f":"haosB","fee9049062ecf242":"jePq8"}],"sbLkY":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Images = void 0; +const resource_1 = require("4b95f2195e7761b7"); +const Core = __importStar(require("7a4d610f1d4aeca7")); +class Images extends resource_1.APIResource { + /** + * Creates a variation of a given image. + */ createVariation(body, options) { + return this._client.post('/images/variations', Core.multipartFormRequestOptions({ + body, + ...options + })); + } + /** + * Creates an edited or extended image given an original image and a prompt. + */ edit(body, options) { + return this._client.post('/images/edits', Core.multipartFormRequestOptions({ + body, + ...options + })); + } + /** + * Creates an image given a prompt. + */ generate(body, options) { + return this._client.post('/images/generations', { + body, + ...options + }); + } +} +exports.Images = Images; + +},{"4b95f2195e7761b7":"kPMwm","7a4d610f1d4aeca7":"haosB"}],"hGG1e":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.ModelsPage = exports.Models = void 0; +const resource_1 = require("e44d8e4e404e03fb"); +const pagination_1 = require("9f7a6a65ccb9331"); +class Models extends resource_1.APIResource { + /** + * Retrieves a model instance, providing basic information about the model such as + * the owner and permissioning. + */ retrieve(model, options) { + return this._client.get(`/models/${model}`, options); + } + /** + * Lists the currently available models, and provides basic information about each + * one such as the owner and availability. + */ list(options) { + return this._client.getAPIList('/models', ModelsPage, options); + } + /** + * Delete a fine-tuned model. You must have the Owner role in your organization to + * delete a model. + */ del(model, options) { + return this._client.delete(`/models/${model}`, options); + } +} +exports.Models = Models; +/** + * Note: no pagination actually occurs yet, this is for forwards-compatibility. + */ class ModelsPage extends pagination_1.Page { +} +exports.ModelsPage = ModelsPage; +Models.ModelsPage = ModelsPage; + +},{"e44d8e4e404e03fb":"kPMwm","9f7a6a65ccb9331":"jePq8"}],"53MBP":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Moderations = void 0; +const resource_1 = require("62d6cbca07213bc7"); +class Moderations extends resource_1.APIResource { + /** + * Classifies if text and/or image inputs are potentially harmful. Learn more in + * the [moderation guide](https://platform.openai.com/docs/guides/moderation). + */ create(body, options) { + return this._client.post('/moderations', { + body, + ...options + }); + } +} +exports.Moderations = Moderations; + +},{"62d6cbca07213bc7":"kPMwm"}],"1T47D":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Uploads = void 0; +const resource_1 = require("b6c9cce4509c8373"); +const PartsAPI = __importStar(require("d4ffafc165e19174")); +const parts_1 = require("d4ffafc165e19174"); +class Uploads extends resource_1.APIResource { + constructor(){ + super(...arguments); + this.parts = new PartsAPI.Parts(this._client); + } + /** + * Creates an intermediate + * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object + * that you can add + * [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to. + * Currently, an Upload can accept at most 8 GB in total and expires after an hour + * after you create it. + * + * Once you complete the Upload, we will create a + * [File](https://platform.openai.com/docs/api-reference/files/object) object that + * contains all the parts you uploaded. This File is usable in the rest of our + * platform as a regular File object. + * + * For certain `purpose`s, the correct `mime_type` must be specified. Please refer + * to documentation for the supported MIME types for your use case: + * + * - [Assistants](https://platform.openai.com/docs/assistants/tools/file-search#supported-files) + * + * For guidance on the proper filename extensions for each purpose, please follow + * the documentation on + * [creating a File](https://platform.openai.com/docs/api-reference/files/create). + */ create(body, options) { + return this._client.post('/uploads', { + body, + ...options + }); + } + /** + * Cancels the Upload. No Parts may be added after an Upload is cancelled. + */ cancel(uploadId, options) { + return this._client.post(`/uploads/${uploadId}/cancel`, options); + } + /** + * Completes the + * [Upload](https://platform.openai.com/docs/api-reference/uploads/object). + * + * Within the returned Upload object, there is a nested + * [File](https://platform.openai.com/docs/api-reference/files/object) object that + * is ready to use in the rest of the platform. + * + * You can specify the order of the Parts by passing in an ordered list of the Part + * IDs. + * + * The number of bytes uploaded upon completion must match the number of bytes + * initially specified when creating the Upload object. No Parts may be added after + * an Upload is completed. + */ complete(uploadId, body, options) { + return this._client.post(`/uploads/${uploadId}/complete`, { + body, + ...options + }); + } +} +exports.Uploads = Uploads; +Uploads.Parts = parts_1.Parts; + +},{"b6c9cce4509c8373":"kPMwm","d4ffafc165e19174":"97D6t"}],"97D6t":[function(require,module,exports,__globalThis) { +"use strict"; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { + enumerable: true, + get: function() { + return m[k]; + } + }; + Object.defineProperty(o, k2, desc); +} : function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +}); +var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { + enumerable: true, + value: v + }); +} : function(o, v) { + o["default"] = v; +}); +var __importStar = this && this.__importStar || function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Parts = void 0; +const resource_1 = require("f5b5da0e04072a79"); +const Core = __importStar(require("be97891ccbbd6b8f")); +class Parts extends resource_1.APIResource { + /** + * Adds a + * [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an + * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object. + * A Part represents a chunk of bytes from the file you are trying to upload. + * + * Each Part can be at most 64 MB, and you can add Parts until you hit the Upload + * maximum of 8 GB. + * + * It is possible to add multiple Parts in parallel. You can decide the intended + * order of the Parts when you + * [complete the Upload](https://platform.openai.com/docs/api-reference/uploads/complete). + */ create(uploadId, body, options) { + return this._client.post(`/uploads/${uploadId}/parts`, Core.multipartFormRequestOptions({ + body, + ...options + })); + } +} +exports.Parts = Parts; + +},{"f5b5da0e04072a79":"kPMwm","be97891ccbbd6b8f":"haosB"}],"j7FRh":[function(require,module,exports,__globalThis) { +exports.interopDefault = function(a) { + return a && a.__esModule ? a : { + default: a + }; +}; +exports.defineInteropFlag = function(a) { + Object.defineProperty(a, '__esModule', { + value: true + }); +}; +exports.exportAll = function(source, dest) { + Object.keys(source).forEach(function(key) { + if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) return; + Object.defineProperty(dest, key, { + enumerable: true, + get: function() { + return source[key]; + } + }); + }); + return dest; +}; +exports.export = function(dest, destName, get) { + Object.defineProperty(dest, destName, { + enumerable: true, + get: get + }); +}; + +},{}],"jxVSe":[function(require,module,exports,__globalThis) { var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); parcelHelpers.defineInteropFlag(exports); parcelHelpers.export(exports, "checkImagePage", ()=>checkImagePage); @@ -753,37 +9670,7 @@ function checkImagePage() { if (resultsContainer.classList.contains("image-page")) setupImages(resultsContainer); } -},{"./app":"3uyIQ","@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh","./utils":"hKc06"}],"j7FRh":[function(require,module,exports,__globalThis) { -exports.interopDefault = function(a) { - return a && a.__esModule ? a : { - default: a - }; -}; -exports.defineInteropFlag = function(a) { - Object.defineProperty(a, '__esModule', { - value: true - }); -}; -exports.exportAll = function(source, dest) { - Object.keys(source).forEach(function(key) { - if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) return; - Object.defineProperty(dest, key, { - enumerable: true, - get: function() { - return source[key]; - } - }); - }); - return dest; -}; -exports.export = function(dest, destName, get) { - Object.defineProperty(dest, destName, { - enumerable: true, - get: get - }); -}; - -},{}],"hKc06":[function(require,module,exports,__globalThis) { +},{"./app":"3uyIQ","./utils":"hKc06","@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh"}],"hKc06":[function(require,module,exports,__globalThis) { var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); parcelHelpers.defineInteropFlag(exports); parcelHelpers.export(exports, "copyToClipboard", ()=>copyToClipboard); diff --git a/searx/static/themes/smart/package-lock.json b/searx/static/themes/smart/package-lock.json index 04b0d3d7b..ef81f67cc 100644 --- a/searx/static/themes/smart/package-lock.json +++ b/searx/static/themes/smart/package-lock.json @@ -5,15 +5,21 @@ "packages": { "": { "dependencies": { + "@fontsource-variable/inter": "^5.1.1", + "@fontsource/inter": "^5.1.1", "ejs": "^3.1.10", "nodemon": "^3.1.9", + "openai": "^4.85.3", "remixicon": "^4.5.0", - "svgo": "^3.3.2" + "svgo": "^3.3.2", + "vazirmatn": "^33.0.3" }, "devDependencies": { - "@parcel/transformer-sass": "^2.13.0", + "@parcel/transformer-sass": "2.13.0", + "buffer": "^6.0.3", "concurrently": "^9.1.0", - "parcel": "^2.13.0" + "parcel": "^2.13.0", + "process": "^0.11.10" } }, "node_modules/@babel/code-frame": { @@ -41,6 +47,18 @@ "node": ">=6.9.0" } }, + "node_modules/@fontsource-variable/inter": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@fontsource-variable/inter/-/inter-5.1.1.tgz", + "integrity": "sha512-OpXFTmiH6tHkYijMvQTycFKBLK4X+SRV6tet1m4YOUH7SzIIlMqDja+ocDtiCA72UthBH/vF+3ZtlMr2rN/wIw==", + "license": "OFL-1.1" + }, + "node_modules/@fontsource/inter": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@fontsource/inter/-/inter-5.1.1.tgz", + "integrity": "sha512-weN3E+rq0Xb3Z93VHJ+Rc7WOQX9ETJPTAJ+gDcaMHtjft67L58sfS65rAjC5tZUXQ2FdZ/V1/sSzCwZ6v05kJw==", + "license": "OFL-1.1" + }, "node_modules/@lezer/common": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.2.3.tgz", @@ -1990,6 +2008,49 @@ "node": ">=10.13.0" } }, + "node_modules/@types/node": { + "version": "18.19.76", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.76.tgz", + "integrity": "sha512-yvR7Q9LdPz2vGpmpJX5LolrgRdWvB67MJKDPSgIIzpFbaf9a1j/f5DnLp5VDyHGMR0QZHlTr1afsD87QCXFHKw==", + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/node-fetch": { + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==", + "license": "MIT", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/agentkeepalive": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.6.0.tgz", + "integrity": "sha512-kja8j7PjmncONqaTsB8fQ+wE2mSU2DJ9D4XKoJ5PFWIdRMa6SLSN1ff4mOr4jCbfRSsxR4keIiySJU0N9T5hIQ==", + "license": "MIT", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -2041,6 +2102,12 @@ "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", "license": "MIT" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2057,6 +2124,27 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -2130,6 +2218,44 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2246,6 +2372,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "12.1.0", "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", @@ -2422,6 +2560,15 @@ } } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-libc": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", @@ -2519,6 +2666,20 @@ "url": "https://dotenvx.com" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ejs": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", @@ -2580,6 +2741,51 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -2590,6 +2796,15 @@ "node": ">=6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/filelist": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", @@ -2632,6 +2847,40 @@ "node": ">=8" } }, + "node_modules/form-data": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", + "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==", + "license": "MIT" + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "license": "MIT", + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -2646,6 +2895,15 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -2656,6 +2914,30 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/get-intrinsic": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz", + "integrity": "sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.0.0", + "function-bind": "^1.1.2", + "get-proto": "^1.0.0", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-port": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/get-port/-/get-port-4.2.0.tgz", @@ -2666,6 +2948,19 @@ "node": ">=6" } }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -2694,6 +2989,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2703,6 +3010,45 @@ "node": ">=8" } }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/htmlnano": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/htmlnano/-/htmlnano-2.1.1.tgz", @@ -2771,6 +3117,36 @@ "entities": "^4.5.0" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.0.0" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", @@ -3211,6 +3587,15 @@ "dev": true, "license": "MIT" }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/mdn-data": { "version": "2.0.30", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", @@ -3231,6 +3616,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3316,6 +3722,45 @@ "dev": true, "license": "MIT" }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-gyp-build-optional-packages": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.1.1.tgz", @@ -3461,6 +3906,36 @@ "dev": true, "license": "MIT" }, + "node_modules/openai": { + "version": "4.85.3", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.85.3.tgz", + "integrity": "sha512-KTMXAK6FPd2IvsPtglMt0J1GyVrjMxCYzu/mVbCPabzzquSJoZlYpHtE0p0ScZPyt11XTc757xSO4j39j5g+Xw==", + "license": "Apache-2.0", + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "ws": "^8.18.0", + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "ws": { + "optional": true + }, + "zod": { + "optional": true + } + } + }, "node_modules/ordered-binary": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/ordered-binary/-/ordered-binary-1.5.3.tgz", @@ -3701,6 +4176,16 @@ "node": ">=12" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", @@ -3996,6 +4481,12 @@ "nodetouch": "bin/nodetouch.js" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/tree-kill": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", @@ -4048,6 +4539,12 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "license": "MIT" }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "license": "MIT" + }, "node_modules/update-browserslist-db": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", @@ -4089,6 +4586,12 @@ "node": ">= 4" } }, + "node_modules/vazirmatn": { + "version": "33.0.3", + "resolved": "https://registry.npmjs.org/vazirmatn/-/vazirmatn-33.0.3.tgz", + "integrity": "sha512-fbjNc0CMjazZpIegWzz9OHGzI1APFboT+x7ZecXlUCtDe/nkyx7gtCTZnWS/+eeXG7fbfXymCPKJI8EsnM3iqw==", + "license": "OFL" + }, "node_modules/weak-lru-cache": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/weak-lru-cache/-/weak-lru-cache-1.2.2.tgz", @@ -4096,6 +4599,31 @@ "dev": true, "license": "MIT" }, + "node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", diff --git a/searx/static/themes/smart/package.json b/searx/static/themes/smart/package.json index 67861039b..fff7f74e9 100644 --- a/searx/static/themes/smart/package.json +++ b/searx/static/themes/smart/package.json @@ -17,14 +17,17 @@ }, "devDependencies": { "@parcel/transformer-sass": "2.13.0", + "buffer": "^6.0.3", "concurrently": "^9.1.0", - "parcel": "^2.13.0" + "parcel": "^2.13.0", + "process": "^0.11.10" }, "dependencies": { "@fontsource-variable/inter": "^5.1.1", "@fontsource/inter": "^5.1.1", "ejs": "^3.1.10", "nodemon": "^3.1.9", + "openai": "^4.85.3", "remixicon": "^4.5.0", "svgo": "^3.3.2", "vazirmatn": "^33.0.3" diff --git a/searx/static/themes/smart/src/scss/style.scss b/searx/static/themes/smart/src/scss/style.scss index c96ea5ad0..3c06d343f 100644 --- a/searx/static/themes/smart/src/scss/style.scss +++ b/searx/static/themes/smart/src/scss/style.scss @@ -237,7 +237,8 @@ main:has(.not-found) { .message-container { background-color: var(--background-color); - padding: 1.5rem; + padding: 1.5rem 1.5rem 5rem; + position: relative; @include mixin.rounded(lg); .title { @@ -257,7 +258,6 @@ main:has(.not-found) { .message { background-color: var(--secondary-background-color); - margin-bottom: 1rem; padding: 1rem; border-radius: 1.5rem 1.5rem 1.5rem .5rem; width: 80%; @@ -265,6 +265,7 @@ main:has(.not-found) { } .reference { + margin-top: 1rem; font-size: .8rem; color: var(--text-color); @@ -335,6 +336,9 @@ main:has(.not-found) { border: 1px solid var(--border-color); @include mixin.rounded(full); padding: 0 .5rem; + position: absolute; + bottom: 1.5rem; + width: calc(100% - 3rem); gap: .5rem; align-items: center; margin-top: 1rem; @@ -366,6 +370,7 @@ main:has(.not-found) { &.ai.loading { background-color: var(--primary-color); color: var(--filled-text-color); + padding: 1.5rem; svg { diff --git a/searx/static/themes/smart/src/ts/app.ts b/searx/static/themes/smart/src/ts/app.ts index d6cbe0375..857a37358 100644 --- a/searx/static/themes/smart/src/ts/app.ts +++ b/searx/static/themes/smart/src/ts/app.ts @@ -1,3 +1,4 @@ +import { setupChat } from "./chat"; import { checkImagePage } from "./images"; import { copyToClipboard, getFromClipboard } from "./utils"; @@ -9,54 +10,57 @@ export function $$(selector: string) { return document.querySelectorAll(selector); } +function setupShareBtn() { + const shareBtn = $("#share-url-btn") as HTMLButtonElement; + if (!shareBtn) return; + shareBtn.addEventListener("click", function () { + const searchUrl = shareBtn.getAttribute("data-search-url"); + if (!searchUrl) return; + copyToClipboard(searchUrl); + const copiedText = shareBtn.getAttribute("data-gitee-copied"); + if (!copiedText) return; + shareBtn.setAttribute("tooltip", copiedText); + setTimeout(() => { + shareBtn.removeAttribute("tooltip"); + }, 2000); + }); +} + +function setupPreferencesPage() { + // check for preferences hash + const hashInput = $("#preferences-hash") as HTMLInputElement; + if (!hashInput) return; + const copyBtn = $("#copy-preferences-hash") as HTMLButtonElement; + if (!copyBtn) return; + copyBtn.addEventListener("click", function () { + copyToClipboard(hashInput.value); + copyBtn.innerText = copyBtn.getAttribute("data-copied-text") as string; + setTimeout(() => { + copyBtn.innerText = copyBtn.getAttribute( + "data-copy-text" + ) as string; + }, 2000); + }); + const pasteBtn = $("#paste-preferences-hash") as HTMLButtonElement; + const pasteInput = $("#paste-preferences-hash-input") as HTMLInputElement; + if (!pasteBtn || !pasteInput) return; + pasteBtn.addEventListener("click", async function () { + const hash = await getFromClipboard(); + pasteInput.value = hash; + }); +} + checkImagePage(); function afterPageLoad() { // preferences page - if ($("#preferences")) { - // check for preferences hash - const hashInput = $("#preferences-hash") as HTMLInputElement; - if (!hashInput) return; - const copyBtn = $("#copy-preferences-hash") as HTMLButtonElement; - if (!copyBtn) return; - copyBtn.addEventListener("click", function () { - copyToClipboard(hashInput.value); - copyBtn.innerText = copyBtn.getAttribute( - "data-copied-text" - ) as string; - setTimeout(() => { - copyBtn.innerText = copyBtn.getAttribute( - "data-copy-text" - ) as string; - }, 2000); - }); - const pasteBtn = $("#paste-preferences-hash") as HTMLButtonElement; - const pasteInput = $( - "#paste-preferences-hash-input" - ) as HTMLInputElement; - if (!pasteBtn || !pasteInput) return; - pasteBtn.addEventListener("click", async function () { - const hash = await getFromClipboard(); - pasteInput.value = hash; - }); - } + if ($("#preferences")) setupPreferencesPage(); // search page - if ($("#results")) { - const shareBtn = $("#share-url-btn") as HTMLButtonElement; - if (!shareBtn) return; - shareBtn.addEventListener("click", function () { - const searchUrl = shareBtn.getAttribute("data-search-url"); - if (!searchUrl) return; - copyToClipboard(searchUrl); - const copiedText = shareBtn.getAttribute("data-gitee-copied"); - if (!copiedText) return; - shareBtn.setAttribute("tooltip", copiedText); - setTimeout(() => { - shareBtn.removeAttribute("tooltip"); - }, 2000); - }); - } + if ($("#results")) setupShareBtn(); + + // chat + setupChat(); } if (document.readyState === "loading") { diff --git a/searx/static/themes/smart/src/ts/chat.ts b/searx/static/themes/smart/src/ts/chat.ts new file mode 100644 index 000000000..e97c58759 --- /dev/null +++ b/searx/static/themes/smart/src/ts/chat.ts @@ -0,0 +1,103 @@ +import { ChatCompletionMessageParam } from "openai/resources/index.mjs"; +import { $ } from "./app"; +import { OpenAI } from "openai"; + +let client: OpenAI; + +let messages: ChatCompletionMessageParam[] = [ + { + role: "system", + content: + "You are a Search Engine Assistant. You will answer questions about the search query.\ + dont answer like previous message. try to summarize the answer little bit", + }, +]; + +export function setupChat() { + const chatContainer = $("#ai-message-container") as HTMLDivElement; + if (!chatContainer) return; + const sendMessageForm = $("#send-message") as HTMLFormElement; + if (!sendMessageForm) return; + const messageInput = sendMessageForm.querySelector( + "input" + ) as HTMLInputElement; + if (!messageInput) return; + const searchQuery = $("#search-query") as HTMLParagraphElement; + if (!searchQuery) return; + + client = new OpenAI({ + apiKey: "FAKE", + dangerouslyAllowBrowser: true, + baseURL: "https://openai.jabirproject.org/v1", + }); + + sendMessage(messageInput, chatContainer, searchQuery.innerText).then(() => + chatContainer.classList.remove("loading") + ); + + sendMessageForm.addEventListener("submit", function (e) { + e.preventDefault(); + sendMessage(messageInput, chatContainer); + }); +} + +function createMessage( + chatContainer: HTMLDivElement, + role: "user" | "ai", + refrence?: string +) { + const messageBox = document.createElement("div"); + messageBox.classList.add("message-box"); + messageBox.classList.add(role); + const messageElement = document.createElement("div"); + messageElement.classList.add("message"); + messageBox.appendChild(messageElement); + + // TODO: improve this + if (refrence) { + const referenceElement = document.createElement("div"); + referenceElement.classList.add("reference"); + referenceElement.innerText = refrence; + messageBox.appendChild(referenceElement); + } + + chatContainer.appendChild(messageBox); + + return messageElement; +} + +async function sendMessage( + messageInput: HTMLInputElement, + chatContainer: HTMLDivElement, + message?: string +) { + const userMessage = messageInput.value; + if (!userMessage && !message) return; + + messages.push({ + role: "user", + content: message || userMessage, + }); + + const stream = await client.chat.completions.create({ + // @ts-ignore + model: "jabir-400b-online", + messages, + // do to some bugs right now i disabled it + // stream: true, + }); + + const messageElement = createMessage(chatContainer, "ai"); + + // for await (const chunk of stream) { + // const text = chunk.choices[0].delta.content || ""; + + // messageElement.innerText += text; + // }\ + + messageElement.innerText = stream.choices[0].message.content || ""; + + if (messageElement.innerText.length <= 0) { + messageElement.parentElement?.remove(); + } +} diff --git a/searx/templates/smart/result_templates/default.html b/searx/templates/smart/result_templates/default.html index e7a4b464d..9e7c6db52 100644 --- a/searx/templates/smart/result_templates/default.html +++ b/searx/templates/smart/result_templates/default.html @@ -11,7 +11,7 @@ endif %} > - {% if favicon_resolver != "" %} + {% if favicon_resolver != "" and result.parsed_url.netloc %}
- {{ result.parsed_url.netloc }}{{ result.parsed_url.path[:25] }} {% - if result.parsed_url.path|length > 25 %}... {% endif %} + {% if result.parsed_url.netloc %} {{ result.parsed_url.netloc }}{{ + result.parsed_url.path[:25] }} {% if result.parsed_url.path|length > + 25 %}... {% endif %} {% endif %}
{% for engine in result.engines %} {% if loop.index < 7 %} diff --git a/searx/templates/smart/results.html b/searx/templates/smart/results.html index fd801d38d..9dcc262ca 100644 --- a/searx/templates/smart/results.html +++ b/searx/templates/smart/results.html @@ -27,8 +27,9 @@ block body %} {% include 'smart/madules/search_header.html' %}
-

{{ q|e }}

+

{{ q|e }}

+ {#

temporary message

@@ -50,6 +51,7 @@ block body %} {% include 'smart/madules/search_header.html' %} >
+ #}
@@ -89,8 +91,8 @@ block body %} {% include 'smart/madules/search_header.html' %}
{%- endfor -%} - {% endif %} {% for result in results %} {% if result.open_group and not - is_image_page %} + {% endif %} {% if results %}{% for result in results %} {% if + result.open_group and not is_image_page %}
@@ -99,7 +101,7 @@ block body %} {% include 'smart/madules/search_header.html' %} result['template']) else get_result_template('smart', 'default.html') %} {% include template %} {% if result.close_group and not is_image_page %}
- {% endif %} {% endfor %} + {% endif %} {% endfor %} {% endif %}
{% if infoboxes %} {% include 'smart/madules/infoboxs.html' %} {% endif %}