@eko-ai/eko 1.2.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/context-compressor.d.ts +10 -0
- package/dist/extension.cjs.js +1 -1
- package/dist/extension.esm.js +1 -1
- package/dist/index.cjs.js +1539 -896
- package/dist/index.esm.js +1539 -896
- package/dist/nodejs.cjs.js +55851 -54951
- package/dist/nodejs.esm.js +56059 -55159
- package/dist/schemas/workflow.schema.d.ts +1 -29
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -366,7 +366,7 @@ let Stream$1 = class Stream {
|
|
|
366
366
|
let consumed = false;
|
|
367
367
|
async function* iterLines() {
|
|
368
368
|
const lineDecoder = new LineDecoder$1();
|
|
369
|
-
const iter = readableStreamAsyncIterable
|
|
369
|
+
const iter = readableStreamAsyncIterable(readableStream);
|
|
370
370
|
for await (const chunk of iter) {
|
|
371
371
|
for (const line of lineDecoder.decode(chunk)) {
|
|
372
372
|
yield line;
|
|
@@ -471,7 +471,7 @@ async function* _iterSSEMessages$1(response, controller) {
|
|
|
471
471
|
}
|
|
472
472
|
const sseDecoder = new SSEDecoder$1();
|
|
473
473
|
const lineDecoder = new LineDecoder$1();
|
|
474
|
-
const iter = readableStreamAsyncIterable
|
|
474
|
+
const iter = readableStreamAsyncIterable(response.body);
|
|
475
475
|
for await (const sseChunk of iterSSEChunks$1(iter)) {
|
|
476
476
|
for (const line of lineDecoder.decode(sseChunk)) {
|
|
477
477
|
const sse = sseDecoder.decode(line);
|
|
@@ -592,7 +592,7 @@ function partition$1(str, delimiter) {
|
|
|
592
592
|
*
|
|
593
593
|
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
594
594
|
*/
|
|
595
|
-
function readableStreamAsyncIterable
|
|
595
|
+
function readableStreamAsyncIterable(stream) {
|
|
596
596
|
if (stream[Symbol.asyncIterator])
|
|
597
597
|
return stream;
|
|
598
598
|
const reader = stream.getReader();
|
|
@@ -718,13 +718,13 @@ const getStringFromMaybeBuffer$1 = (x) => {
|
|
|
718
718
|
const isAsyncIterableIterator$1 = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
|
719
719
|
const isMultipartBody$1 = (body) => body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
|
|
720
720
|
|
|
721
|
-
var __classPrivateFieldSet$
|
|
721
|
+
var __classPrivateFieldSet$7 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
722
722
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
723
723
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
724
724
|
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");
|
|
725
725
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
726
726
|
};
|
|
727
|
-
var __classPrivateFieldGet$
|
|
727
|
+
var __classPrivateFieldGet$8 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
728
728
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
729
729
|
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");
|
|
730
730
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -1156,7 +1156,7 @@ let APIClient$1 = class APIClient {
|
|
|
1156
1156
|
let AbstractPage$1 = class AbstractPage {
|
|
1157
1157
|
constructor(client, response, body, options) {
|
|
1158
1158
|
_AbstractPage_client$1.set(this, void 0);
|
|
1159
|
-
__classPrivateFieldSet$
|
|
1159
|
+
__classPrivateFieldSet$7(this, _AbstractPage_client$1, client, "f");
|
|
1160
1160
|
this.options = options;
|
|
1161
1161
|
this.response = response;
|
|
1162
1162
|
this.body = body;
|
|
@@ -1184,7 +1184,7 @@ let AbstractPage$1 = class AbstractPage {
|
|
|
1184
1184
|
nextOptions.query = undefined;
|
|
1185
1185
|
nextOptions.path = nextInfo.url.toString();
|
|
1186
1186
|
}
|
|
1187
|
-
return await __classPrivateFieldGet$
|
|
1187
|
+
return await __classPrivateFieldGet$8(this, _AbstractPage_client$1, "f").requestAPIList(this.constructor, nextOptions);
|
|
1188
1188
|
}
|
|
1189
1189
|
async *iterPages() {
|
|
1190
1190
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -1634,7 +1634,7 @@ class JSONLDecoder {
|
|
|
1634
1634
|
controller.abort();
|
|
1635
1635
|
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
1636
1636
|
}
|
|
1637
|
-
return new JSONLDecoder(readableStreamAsyncIterable
|
|
1637
|
+
return new JSONLDecoder(readableStreamAsyncIterable(response.body), controller);
|
|
1638
1638
|
}
|
|
1639
1639
|
}
|
|
1640
1640
|
|
|
@@ -1724,7 +1724,7 @@ class BetaMessageBatchesPage extends Page$1 {
|
|
|
1724
1724
|
Batches$2.BetaMessageBatchesPage = BetaMessageBatchesPage;
|
|
1725
1725
|
|
|
1726
1726
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
1727
|
-
let Messages$
|
|
1727
|
+
let Messages$3 = class Messages extends APIResource$1 {
|
|
1728
1728
|
constructor() {
|
|
1729
1729
|
super(...arguments);
|
|
1730
1730
|
this.batches = new Batches$2(this._client);
|
|
@@ -1760,20 +1760,20 @@ let Messages$2 = class Messages extends APIResource$1 {
|
|
|
1760
1760
|
});
|
|
1761
1761
|
}
|
|
1762
1762
|
};
|
|
1763
|
-
Messages$
|
|
1764
|
-
Messages$
|
|
1763
|
+
Messages$3.Batches = Batches$2;
|
|
1764
|
+
Messages$3.BetaMessageBatchesPage = BetaMessageBatchesPage;
|
|
1765
1765
|
|
|
1766
1766
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
1767
1767
|
let Beta$1 = class Beta extends APIResource$1 {
|
|
1768
1768
|
constructor() {
|
|
1769
1769
|
super(...arguments);
|
|
1770
1770
|
this.models = new Models$2(this._client);
|
|
1771
|
-
this.messages = new Messages$
|
|
1771
|
+
this.messages = new Messages$3(this._client);
|
|
1772
1772
|
}
|
|
1773
1773
|
};
|
|
1774
1774
|
Beta$1.Models = Models$2;
|
|
1775
1775
|
Beta$1.BetaModelInfosPage = BetaModelInfosPage;
|
|
1776
|
-
Beta$1.Messages = Messages$
|
|
1776
|
+
Beta$1.Messages = Messages$3;
|
|
1777
1777
|
|
|
1778
1778
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
1779
1779
|
let Completions$3 = class Completions extends APIResource$1 {
|
|
@@ -2068,13 +2068,13 @@ const tokenize = (input) => {
|
|
|
2068
2068
|
return output;
|
|
2069
2069
|
}, partialParse$1 = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
2070
2070
|
|
|
2071
|
-
var __classPrivateFieldSet$
|
|
2071
|
+
var __classPrivateFieldSet$6 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2072
2072
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2073
2073
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2074
2074
|
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");
|
|
2075
2075
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2076
2076
|
};
|
|
2077
|
-
var __classPrivateFieldGet$
|
|
2077
|
+
var __classPrivateFieldGet$7 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2078
2078
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2079
2079
|
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");
|
|
2080
2080
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -2100,12 +2100,12 @@ class MessageStream {
|
|
|
2100
2100
|
_MessageStream_aborted.set(this, false);
|
|
2101
2101
|
_MessageStream_catchingPromiseCreated.set(this, false);
|
|
2102
2102
|
_MessageStream_handleError.set(this, (error) => {
|
|
2103
|
-
__classPrivateFieldSet$
|
|
2103
|
+
__classPrivateFieldSet$6(this, _MessageStream_errored, true, "f");
|
|
2104
2104
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
2105
2105
|
error = new APIUserAbortError$1();
|
|
2106
2106
|
}
|
|
2107
2107
|
if (error instanceof APIUserAbortError$1) {
|
|
2108
|
-
__classPrivateFieldSet$
|
|
2108
|
+
__classPrivateFieldSet$6(this, _MessageStream_aborted, true, "f");
|
|
2109
2109
|
return this._emit('abort', error);
|
|
2110
2110
|
}
|
|
2111
2111
|
if (error instanceof AnthropicError) {
|
|
@@ -2119,20 +2119,20 @@ class MessageStream {
|
|
|
2119
2119
|
}
|
|
2120
2120
|
return this._emit('error', new AnthropicError(String(error)));
|
|
2121
2121
|
});
|
|
2122
|
-
__classPrivateFieldSet$
|
|
2123
|
-
__classPrivateFieldSet$
|
|
2124
|
-
__classPrivateFieldSet$
|
|
2122
|
+
__classPrivateFieldSet$6(this, _MessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
2123
|
+
__classPrivateFieldSet$6(this, _MessageStream_resolveConnectedPromise, resolve, "f");
|
|
2124
|
+
__classPrivateFieldSet$6(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
2125
2125
|
}), "f");
|
|
2126
|
-
__classPrivateFieldSet$
|
|
2127
|
-
__classPrivateFieldSet$
|
|
2128
|
-
__classPrivateFieldSet$
|
|
2126
|
+
__classPrivateFieldSet$6(this, _MessageStream_endPromise, new Promise((resolve, reject) => {
|
|
2127
|
+
__classPrivateFieldSet$6(this, _MessageStream_resolveEndPromise, resolve, "f");
|
|
2128
|
+
__classPrivateFieldSet$6(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
2129
2129
|
}), "f");
|
|
2130
2130
|
// Don't let these promises cause unhandled rejection errors.
|
|
2131
2131
|
// we will manually cause an unhandled rejection error later
|
|
2132
2132
|
// if the user hasn't registered any error listener or called
|
|
2133
2133
|
// any promise-returning method.
|
|
2134
|
-
__classPrivateFieldGet$
|
|
2135
|
-
__classPrivateFieldGet$
|
|
2134
|
+
__classPrivateFieldGet$7(this, _MessageStream_connectedPromise, "f").catch(() => { });
|
|
2135
|
+
__classPrivateFieldGet$7(this, _MessageStream_endPromise, "f").catch(() => { });
|
|
2136
2136
|
}
|
|
2137
2137
|
/**
|
|
2138
2138
|
* Intended for use on the frontend, consuming a stream produced with
|
|
@@ -2158,7 +2158,7 @@ class MessageStream {
|
|
|
2158
2158
|
executor().then(() => {
|
|
2159
2159
|
this._emitFinal();
|
|
2160
2160
|
this._emit('end');
|
|
2161
|
-
}, __classPrivateFieldGet$
|
|
2161
|
+
}, __classPrivateFieldGet$7(this, _MessageStream_handleError, "f"));
|
|
2162
2162
|
}
|
|
2163
2163
|
_addMessageParam(message) {
|
|
2164
2164
|
this.messages.push(message);
|
|
@@ -2176,31 +2176,31 @@ class MessageStream {
|
|
|
2176
2176
|
this.controller.abort();
|
|
2177
2177
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
2178
2178
|
}
|
|
2179
|
-
__classPrivateFieldGet$
|
|
2179
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
2180
2180
|
const stream = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
|
|
2181
2181
|
this._connected();
|
|
2182
2182
|
for await (const event of stream) {
|
|
2183
|
-
__classPrivateFieldGet$
|
|
2183
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
2184
2184
|
}
|
|
2185
2185
|
if (stream.controller.signal?.aborted) {
|
|
2186
2186
|
throw new APIUserAbortError$1();
|
|
2187
2187
|
}
|
|
2188
|
-
__classPrivateFieldGet$
|
|
2188
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
2189
2189
|
}
|
|
2190
2190
|
_connected() {
|
|
2191
2191
|
if (this.ended)
|
|
2192
2192
|
return;
|
|
2193
|
-
__classPrivateFieldGet$
|
|
2193
|
+
__classPrivateFieldGet$7(this, _MessageStream_resolveConnectedPromise, "f").call(this);
|
|
2194
2194
|
this._emit('connect');
|
|
2195
2195
|
}
|
|
2196
2196
|
get ended() {
|
|
2197
|
-
return __classPrivateFieldGet$
|
|
2197
|
+
return __classPrivateFieldGet$7(this, _MessageStream_ended, "f");
|
|
2198
2198
|
}
|
|
2199
2199
|
get errored() {
|
|
2200
|
-
return __classPrivateFieldGet$
|
|
2200
|
+
return __classPrivateFieldGet$7(this, _MessageStream_errored, "f");
|
|
2201
2201
|
}
|
|
2202
2202
|
get aborted() {
|
|
2203
|
-
return __classPrivateFieldGet$
|
|
2203
|
+
return __classPrivateFieldGet$7(this, _MessageStream_aborted, "f");
|
|
2204
2204
|
}
|
|
2205
2205
|
abort() {
|
|
2206
2206
|
this.controller.abort();
|
|
@@ -2213,7 +2213,7 @@ class MessageStream {
|
|
|
2213
2213
|
* @returns this MessageStream, so that calls can be chained
|
|
2214
2214
|
*/
|
|
2215
2215
|
on(event, listener) {
|
|
2216
|
-
const listeners = __classPrivateFieldGet$
|
|
2216
|
+
const listeners = __classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event] = []);
|
|
2217
2217
|
listeners.push({ listener });
|
|
2218
2218
|
return this;
|
|
2219
2219
|
}
|
|
@@ -2225,7 +2225,7 @@ class MessageStream {
|
|
|
2225
2225
|
* @returns this MessageStream, so that calls can be chained
|
|
2226
2226
|
*/
|
|
2227
2227
|
off(event, listener) {
|
|
2228
|
-
const listeners = __classPrivateFieldGet$
|
|
2228
|
+
const listeners = __classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event];
|
|
2229
2229
|
if (!listeners)
|
|
2230
2230
|
return this;
|
|
2231
2231
|
const index = listeners.findIndex((l) => l.listener === listener);
|
|
@@ -2239,7 +2239,7 @@ class MessageStream {
|
|
|
2239
2239
|
* @returns this MessageStream, so that calls can be chained
|
|
2240
2240
|
*/
|
|
2241
2241
|
once(event, listener) {
|
|
2242
|
-
const listeners = __classPrivateFieldGet$
|
|
2242
|
+
const listeners = __classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event] = []);
|
|
2243
2243
|
listeners.push({ listener, once: true });
|
|
2244
2244
|
return this;
|
|
2245
2245
|
}
|
|
@@ -2256,18 +2256,18 @@ class MessageStream {
|
|
|
2256
2256
|
*/
|
|
2257
2257
|
emitted(event) {
|
|
2258
2258
|
return new Promise((resolve, reject) => {
|
|
2259
|
-
__classPrivateFieldSet$
|
|
2259
|
+
__classPrivateFieldSet$6(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
2260
2260
|
if (event !== 'error')
|
|
2261
2261
|
this.once('error', reject);
|
|
2262
2262
|
this.once(event, resolve);
|
|
2263
2263
|
});
|
|
2264
2264
|
}
|
|
2265
2265
|
async done() {
|
|
2266
|
-
__classPrivateFieldSet$
|
|
2267
|
-
await __classPrivateFieldGet$
|
|
2266
|
+
__classPrivateFieldSet$6(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
2267
|
+
await __classPrivateFieldGet$7(this, _MessageStream_endPromise, "f");
|
|
2268
2268
|
}
|
|
2269
2269
|
get currentMessage() {
|
|
2270
|
-
return __classPrivateFieldGet$
|
|
2270
|
+
return __classPrivateFieldGet$7(this, _MessageStream_currentMessageSnapshot, "f");
|
|
2271
2271
|
}
|
|
2272
2272
|
/**
|
|
2273
2273
|
* @returns a promise that resolves with the the final assistant Message response,
|
|
@@ -2275,7 +2275,7 @@ class MessageStream {
|
|
|
2275
2275
|
*/
|
|
2276
2276
|
async finalMessage() {
|
|
2277
2277
|
await this.done();
|
|
2278
|
-
return __classPrivateFieldGet$
|
|
2278
|
+
return __classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this);
|
|
2279
2279
|
}
|
|
2280
2280
|
/**
|
|
2281
2281
|
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
|
@@ -2284,35 +2284,35 @@ class MessageStream {
|
|
|
2284
2284
|
*/
|
|
2285
2285
|
async finalText() {
|
|
2286
2286
|
await this.done();
|
|
2287
|
-
return __classPrivateFieldGet$
|
|
2287
|
+
return __classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_getFinalText).call(this);
|
|
2288
2288
|
}
|
|
2289
2289
|
_emit(event, ...args) {
|
|
2290
2290
|
// make sure we don't emit any MessageStreamEvents after end
|
|
2291
|
-
if (__classPrivateFieldGet$
|
|
2291
|
+
if (__classPrivateFieldGet$7(this, _MessageStream_ended, "f"))
|
|
2292
2292
|
return;
|
|
2293
2293
|
if (event === 'end') {
|
|
2294
|
-
__classPrivateFieldSet$
|
|
2295
|
-
__classPrivateFieldGet$
|
|
2294
|
+
__classPrivateFieldSet$6(this, _MessageStream_ended, true, "f");
|
|
2295
|
+
__classPrivateFieldGet$7(this, _MessageStream_resolveEndPromise, "f").call(this);
|
|
2296
2296
|
}
|
|
2297
|
-
const listeners = __classPrivateFieldGet$
|
|
2297
|
+
const listeners = __classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event];
|
|
2298
2298
|
if (listeners) {
|
|
2299
|
-
__classPrivateFieldGet$
|
|
2299
|
+
__classPrivateFieldGet$7(this, _MessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
2300
2300
|
listeners.forEach(({ listener }) => listener(...args));
|
|
2301
2301
|
}
|
|
2302
2302
|
if (event === 'abort') {
|
|
2303
2303
|
const error = args[0];
|
|
2304
|
-
if (!__classPrivateFieldGet$
|
|
2304
|
+
if (!__classPrivateFieldGet$7(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
2305
2305
|
Promise.reject(error);
|
|
2306
2306
|
}
|
|
2307
|
-
__classPrivateFieldGet$
|
|
2308
|
-
__classPrivateFieldGet$
|
|
2307
|
+
__classPrivateFieldGet$7(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
2308
|
+
__classPrivateFieldGet$7(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
2309
2309
|
this._emit('end');
|
|
2310
2310
|
return;
|
|
2311
2311
|
}
|
|
2312
2312
|
if (event === 'error') {
|
|
2313
2313
|
// NOTE: _emit('error', error) should only be called from #handleError().
|
|
2314
2314
|
const error = args[0];
|
|
2315
|
-
if (!__classPrivateFieldGet$
|
|
2315
|
+
if (!__classPrivateFieldGet$7(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
2316
2316
|
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
|
2317
2317
|
// If you are seeing stack traces here, make sure to handle errors via either:
|
|
2318
2318
|
// - runner.on('error', () => ...)
|
|
@@ -2321,15 +2321,15 @@ class MessageStream {
|
|
|
2321
2321
|
// - etc.
|
|
2322
2322
|
Promise.reject(error);
|
|
2323
2323
|
}
|
|
2324
|
-
__classPrivateFieldGet$
|
|
2325
|
-
__classPrivateFieldGet$
|
|
2324
|
+
__classPrivateFieldGet$7(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
2325
|
+
__classPrivateFieldGet$7(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
2326
2326
|
this._emit('end');
|
|
2327
2327
|
}
|
|
2328
2328
|
}
|
|
2329
2329
|
_emitFinal() {
|
|
2330
2330
|
const finalMessage = this.receivedMessages.at(-1);
|
|
2331
2331
|
if (finalMessage) {
|
|
2332
|
-
this._emit('finalMessage', __classPrivateFieldGet$
|
|
2332
|
+
this._emit('finalMessage', __classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this));
|
|
2333
2333
|
}
|
|
2334
2334
|
}
|
|
2335
2335
|
async _fromReadableStream(readableStream, options) {
|
|
@@ -2339,16 +2339,16 @@ class MessageStream {
|
|
|
2339
2339
|
this.controller.abort();
|
|
2340
2340
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
2341
2341
|
}
|
|
2342
|
-
__classPrivateFieldGet$
|
|
2342
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
2343
2343
|
this._connected();
|
|
2344
2344
|
const stream = Stream$1.fromReadableStream(readableStream, this.controller);
|
|
2345
2345
|
for await (const event of stream) {
|
|
2346
|
-
__classPrivateFieldGet$
|
|
2346
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
2347
2347
|
}
|
|
2348
2348
|
if (stream.controller.signal?.aborted) {
|
|
2349
2349
|
throw new APIUserAbortError$1();
|
|
2350
2350
|
}
|
|
2351
|
-
__classPrivateFieldGet$
|
|
2351
|
+
__classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
2352
2352
|
}
|
|
2353
2353
|
[(_MessageStream_currentMessageSnapshot = new WeakMap(), _MessageStream_connectedPromise = new WeakMap(), _MessageStream_resolveConnectedPromise = new WeakMap(), _MessageStream_rejectConnectedPromise = new WeakMap(), _MessageStream_endPromise = new WeakMap(), _MessageStream_resolveEndPromise = new WeakMap(), _MessageStream_rejectEndPromise = new WeakMap(), _MessageStream_listeners = new WeakMap(), _MessageStream_ended = new WeakMap(), _MessageStream_errored = new WeakMap(), _MessageStream_aborted = new WeakMap(), _MessageStream_catchingPromiseCreated = new WeakMap(), _MessageStream_handleError = new WeakMap(), _MessageStream_instances = new WeakSet(), _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage() {
|
|
2354
2354
|
if (this.receivedMessages.length === 0) {
|
|
@@ -2370,11 +2370,11 @@ class MessageStream {
|
|
|
2370
2370
|
}, _MessageStream_beginRequest = function _MessageStream_beginRequest() {
|
|
2371
2371
|
if (this.ended)
|
|
2372
2372
|
return;
|
|
2373
|
-
__classPrivateFieldSet$
|
|
2373
|
+
__classPrivateFieldSet$6(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
2374
2374
|
}, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent(event) {
|
|
2375
2375
|
if (this.ended)
|
|
2376
2376
|
return;
|
|
2377
|
-
const messageSnapshot = __classPrivateFieldGet$
|
|
2377
|
+
const messageSnapshot = __classPrivateFieldGet$7(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event);
|
|
2378
2378
|
this._emit('streamEvent', event, messageSnapshot);
|
|
2379
2379
|
switch (event.type) {
|
|
2380
2380
|
case 'content_block_delta': {
|
|
@@ -2399,7 +2399,7 @@ class MessageStream {
|
|
|
2399
2399
|
break;
|
|
2400
2400
|
}
|
|
2401
2401
|
case 'message_start': {
|
|
2402
|
-
__classPrivateFieldSet$
|
|
2402
|
+
__classPrivateFieldSet$6(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
2403
2403
|
break;
|
|
2404
2404
|
}
|
|
2405
2405
|
}
|
|
@@ -2407,14 +2407,14 @@ class MessageStream {
|
|
|
2407
2407
|
if (this.ended) {
|
|
2408
2408
|
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
|
2409
2409
|
}
|
|
2410
|
-
const snapshot = __classPrivateFieldGet$
|
|
2410
|
+
const snapshot = __classPrivateFieldGet$7(this, _MessageStream_currentMessageSnapshot, "f");
|
|
2411
2411
|
if (!snapshot) {
|
|
2412
2412
|
throw new AnthropicError(`request ended without sending any chunks`);
|
|
2413
2413
|
}
|
|
2414
|
-
__classPrivateFieldSet$
|
|
2414
|
+
__classPrivateFieldSet$6(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
2415
2415
|
return snapshot;
|
|
2416
2416
|
}, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage(event) {
|
|
2417
|
-
let snapshot = __classPrivateFieldGet$
|
|
2417
|
+
let snapshot = __classPrivateFieldGet$7(this, _MessageStream_currentMessageSnapshot, "f");
|
|
2418
2418
|
if (event.type === 'message_start') {
|
|
2419
2419
|
if (snapshot) {
|
|
2420
2420
|
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
@@ -2518,7 +2518,7 @@ class MessageStream {
|
|
|
2518
2518
|
}
|
|
2519
2519
|
|
|
2520
2520
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2521
|
-
let Messages$
|
|
2521
|
+
let Messages$2 = class Messages extends APIResource$1 {
|
|
2522
2522
|
constructor() {
|
|
2523
2523
|
super(...arguments);
|
|
2524
2524
|
this.batches = new Batches$1(this._client);
|
|
@@ -2557,8 +2557,8 @@ const DEPRECATED_MODELS = {
|
|
|
2557
2557
|
'claude-instant-1.1-100k': 'November 6th, 2024',
|
|
2558
2558
|
'claude-instant-1.2': 'November 6th, 2024',
|
|
2559
2559
|
};
|
|
2560
|
-
Messages$
|
|
2561
|
-
Messages$
|
|
2560
|
+
Messages$2.Batches = Batches$1;
|
|
2561
|
+
Messages$2.MessageBatchesPage = MessageBatchesPage;
|
|
2562
2562
|
|
|
2563
2563
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2564
2564
|
let Models$1 = class Models extends APIResource$1 {
|
|
@@ -2620,7 +2620,7 @@ class Anthropic extends APIClient$1 {
|
|
|
2620
2620
|
fetch: options.fetch,
|
|
2621
2621
|
});
|
|
2622
2622
|
this.completions = new Completions$3(this);
|
|
2623
|
-
this.messages = new Messages$
|
|
2623
|
+
this.messages = new Messages$2(this);
|
|
2624
2624
|
this.models = new Models$1(this);
|
|
2625
2625
|
this.beta = new Beta$1(this);
|
|
2626
2626
|
this._options = options;
|
|
@@ -2700,10 +2700,11 @@ Anthropic.UnprocessableEntityError = UnprocessableEntityError$1;
|
|
|
2700
2700
|
Anthropic.toFile = toFile$1;
|
|
2701
2701
|
Anthropic.fileFromPath = fileFromPath$1;
|
|
2702
2702
|
Anthropic.Completions = Completions$3;
|
|
2703
|
-
Anthropic.Messages = Messages$
|
|
2703
|
+
Anthropic.Messages = Messages$2;
|
|
2704
2704
|
Anthropic.Models = Models$1;
|
|
2705
2705
|
Anthropic.ModelInfosPage = ModelInfosPage;
|
|
2706
2706
|
Anthropic.Beta = Beta$1;
|
|
2707
|
+
const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
|
|
2707
2708
|
|
|
2708
2709
|
const prettyLogStyles = {
|
|
2709
2710
|
reset: [0, 0],
|
|
@@ -3629,7 +3630,7 @@ function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, al
|
|
|
3629
3630
|
let tmp_sc = sideChannel;
|
|
3630
3631
|
let step = 0;
|
|
3631
3632
|
let find_flag = false;
|
|
3632
|
-
while ((tmp_sc = tmp_sc.get(sentinel)) !== void
|
|
3633
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void 0 && !find_flag) {
|
|
3633
3634
|
// Where object last appeared in the ref tree
|
|
3634
3635
|
const pos = tmp_sc.get(object);
|
|
3635
3636
|
step += 1;
|
|
@@ -3693,7 +3694,7 @@ function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, al
|
|
|
3693
3694
|
// @ts-expect-error values only
|
|
3694
3695
|
obj = maybe_map(obj, encoder);
|
|
3695
3696
|
}
|
|
3696
|
-
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void
|
|
3697
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void 0 }];
|
|
3697
3698
|
}
|
|
3698
3699
|
else if (is_array(filter)) {
|
|
3699
3700
|
obj_keys = filter;
|
|
@@ -3849,7 +3850,7 @@ function stringify(object, opts = {}) {
|
|
|
3849
3850
|
return joined.length > 0 ? prefix + joined : '';
|
|
3850
3851
|
}
|
|
3851
3852
|
|
|
3852
|
-
const VERSION = '4.
|
|
3853
|
+
const VERSION = '4.87.3'; // x-release-please-version
|
|
3853
3854
|
|
|
3854
3855
|
let auto = false;
|
|
3855
3856
|
let kind = undefined;
|
|
@@ -4078,6 +4079,18 @@ class ContentFilterFinishReasonError extends OpenAIError {
|
|
|
4078
4079
|
}
|
|
4079
4080
|
}
|
|
4080
4081
|
|
|
4082
|
+
var __classPrivateFieldSet$5 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4083
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4084
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4085
|
+
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");
|
|
4086
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
4087
|
+
};
|
|
4088
|
+
var __classPrivateFieldGet$6 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
4089
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4090
|
+
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");
|
|
4091
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4092
|
+
};
|
|
4093
|
+
var _LineDecoder_carriageReturnIndex;
|
|
4081
4094
|
/**
|
|
4082
4095
|
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
4083
4096
|
* reading lines from text.
|
|
@@ -4086,39 +4099,42 @@ class ContentFilterFinishReasonError extends OpenAIError {
|
|
|
4086
4099
|
*/
|
|
4087
4100
|
class LineDecoder {
|
|
4088
4101
|
constructor() {
|
|
4089
|
-
this
|
|
4090
|
-
this.
|
|
4102
|
+
_LineDecoder_carriageReturnIndex.set(this, void 0);
|
|
4103
|
+
this.buffer = new Uint8Array();
|
|
4104
|
+
__classPrivateFieldSet$5(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
4091
4105
|
}
|
|
4092
4106
|
decode(chunk) {
|
|
4093
|
-
|
|
4094
|
-
if (this.trailingCR) {
|
|
4095
|
-
text = '\r' + text;
|
|
4096
|
-
this.trailingCR = false;
|
|
4097
|
-
}
|
|
4098
|
-
if (text.endsWith('\r')) {
|
|
4099
|
-
this.trailingCR = true;
|
|
4100
|
-
text = text.slice(0, -1);
|
|
4101
|
-
}
|
|
4102
|
-
if (!text) {
|
|
4103
|
-
return [];
|
|
4104
|
-
}
|
|
4105
|
-
const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
|
|
4106
|
-
let lines = text.split(LineDecoder.NEWLINE_REGEXP);
|
|
4107
|
-
// if there is a trailing new line then the last entry will be an empty
|
|
4108
|
-
// string which we don't care about
|
|
4109
|
-
if (trailingNewline) {
|
|
4110
|
-
lines.pop();
|
|
4111
|
-
}
|
|
4112
|
-
if (lines.length === 1 && !trailingNewline) {
|
|
4113
|
-
this.buffer.push(lines[0]);
|
|
4107
|
+
if (chunk == null) {
|
|
4114
4108
|
return [];
|
|
4115
4109
|
}
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4110
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
4111
|
+
: typeof chunk === 'string' ? new TextEncoder().encode(chunk)
|
|
4112
|
+
: chunk;
|
|
4113
|
+
let newData = new Uint8Array(this.buffer.length + binaryChunk.length);
|
|
4114
|
+
newData.set(this.buffer);
|
|
4115
|
+
newData.set(binaryChunk, this.buffer.length);
|
|
4116
|
+
this.buffer = newData;
|
|
4117
|
+
const lines = [];
|
|
4118
|
+
let patternIndex;
|
|
4119
|
+
while ((patternIndex = findNewlineIndex(this.buffer, __classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f"))) != null) {
|
|
4120
|
+
if (patternIndex.carriage && __classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f") == null) {
|
|
4121
|
+
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
|
4122
|
+
__classPrivateFieldSet$5(this, _LineDecoder_carriageReturnIndex, patternIndex.index, "f");
|
|
4123
|
+
continue;
|
|
4124
|
+
}
|
|
4125
|
+
// we got double \r or \rtext\n
|
|
4126
|
+
if (__classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f") != null &&
|
|
4127
|
+
(patternIndex.index !== __classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f") + 1 || patternIndex.carriage)) {
|
|
4128
|
+
lines.push(this.decodeText(this.buffer.slice(0, __classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f") - 1)));
|
|
4129
|
+
this.buffer = this.buffer.slice(__classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f"));
|
|
4130
|
+
__classPrivateFieldSet$5(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
4131
|
+
continue;
|
|
4132
|
+
}
|
|
4133
|
+
const endIndex = __classPrivateFieldGet$6(this, _LineDecoder_carriageReturnIndex, "f") !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
|
4134
|
+
const line = this.decodeText(this.buffer.slice(0, endIndex));
|
|
4135
|
+
lines.push(line);
|
|
4136
|
+
this.buffer = this.buffer.slice(patternIndex.index);
|
|
4137
|
+
__classPrivateFieldSet$5(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
4122
4138
|
}
|
|
4123
4139
|
return lines;
|
|
4124
4140
|
}
|
|
@@ -4148,18 +4164,99 @@ class LineDecoder {
|
|
|
4148
4164
|
throw new OpenAIError(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`);
|
|
4149
4165
|
}
|
|
4150
4166
|
flush() {
|
|
4151
|
-
if (!this.buffer.length
|
|
4167
|
+
if (!this.buffer.length) {
|
|
4152
4168
|
return [];
|
|
4153
4169
|
}
|
|
4154
|
-
|
|
4155
|
-
this.buffer = [];
|
|
4156
|
-
this.trailingCR = false;
|
|
4157
|
-
return lines;
|
|
4170
|
+
return this.decode('\n');
|
|
4158
4171
|
}
|
|
4159
4172
|
}
|
|
4173
|
+
_LineDecoder_carriageReturnIndex = new WeakMap();
|
|
4160
4174
|
// prettier-ignore
|
|
4161
4175
|
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
|
|
4162
4176
|
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
4177
|
+
/**
|
|
4178
|
+
* This function searches the buffer for the end patterns, (\r or \n)
|
|
4179
|
+
* and returns an object with the index preceding the matched newline and the
|
|
4180
|
+
* index after the newline char. `null` is returned if no new line is found.
|
|
4181
|
+
*
|
|
4182
|
+
* ```ts
|
|
4183
|
+
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
|
4184
|
+
* ```
|
|
4185
|
+
*/
|
|
4186
|
+
function findNewlineIndex(buffer, startIndex) {
|
|
4187
|
+
const newline = 0x0a; // \n
|
|
4188
|
+
const carriage = 0x0d; // \r
|
|
4189
|
+
for (let i = startIndex ?? 0; i < buffer.length; i++) {
|
|
4190
|
+
if (buffer[i] === newline) {
|
|
4191
|
+
return { preceding: i, index: i + 1, carriage: false };
|
|
4192
|
+
}
|
|
4193
|
+
if (buffer[i] === carriage) {
|
|
4194
|
+
return { preceding: i, index: i + 1, carriage: true };
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
return null;
|
|
4198
|
+
}
|
|
4199
|
+
function findDoubleNewlineIndex(buffer) {
|
|
4200
|
+
// This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
|
|
4201
|
+
// and returns the index right after the first occurrence of any pattern,
|
|
4202
|
+
// or -1 if none of the patterns are found.
|
|
4203
|
+
const newline = 0x0a; // \n
|
|
4204
|
+
const carriage = 0x0d; // \r
|
|
4205
|
+
for (let i = 0; i < buffer.length - 1; i++) {
|
|
4206
|
+
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
|
4207
|
+
// \n\n
|
|
4208
|
+
return i + 2;
|
|
4209
|
+
}
|
|
4210
|
+
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
|
4211
|
+
// \r\r
|
|
4212
|
+
return i + 2;
|
|
4213
|
+
}
|
|
4214
|
+
if (buffer[i] === carriage &&
|
|
4215
|
+
buffer[i + 1] === newline &&
|
|
4216
|
+
i + 3 < buffer.length &&
|
|
4217
|
+
buffer[i + 2] === carriage &&
|
|
4218
|
+
buffer[i + 3] === newline) {
|
|
4219
|
+
// \r\n\r\n
|
|
4220
|
+
return i + 4;
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
return -1;
|
|
4224
|
+
}
|
|
4225
|
+
|
|
4226
|
+
/**
|
|
4227
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
4228
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
4229
|
+
*
|
|
4230
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
4231
|
+
*/
|
|
4232
|
+
function ReadableStreamToAsyncIterable(stream) {
|
|
4233
|
+
if (stream[Symbol.asyncIterator])
|
|
4234
|
+
return stream;
|
|
4235
|
+
const reader = stream.getReader();
|
|
4236
|
+
return {
|
|
4237
|
+
async next() {
|
|
4238
|
+
try {
|
|
4239
|
+
const result = await reader.read();
|
|
4240
|
+
if (result?.done)
|
|
4241
|
+
reader.releaseLock(); // release lock when stream becomes closed
|
|
4242
|
+
return result;
|
|
4243
|
+
}
|
|
4244
|
+
catch (e) {
|
|
4245
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
|
4246
|
+
throw e;
|
|
4247
|
+
}
|
|
4248
|
+
},
|
|
4249
|
+
async return() {
|
|
4250
|
+
const cancelPromise = reader.cancel();
|
|
4251
|
+
reader.releaseLock();
|
|
4252
|
+
await cancelPromise;
|
|
4253
|
+
return { done: true, value: undefined };
|
|
4254
|
+
},
|
|
4255
|
+
[Symbol.asyncIterator]() {
|
|
4256
|
+
return this;
|
|
4257
|
+
},
|
|
4258
|
+
};
|
|
4259
|
+
}
|
|
4163
4260
|
|
|
4164
4261
|
class Stream {
|
|
4165
4262
|
constructor(iterator, controller) {
|
|
@@ -4182,7 +4279,7 @@ class Stream {
|
|
|
4182
4279
|
done = true;
|
|
4183
4280
|
continue;
|
|
4184
4281
|
}
|
|
4185
|
-
if (sse.event === null) {
|
|
4282
|
+
if (sse.event === null || sse.event.startsWith('response.')) {
|
|
4186
4283
|
let data;
|
|
4187
4284
|
try {
|
|
4188
4285
|
data = JSON.parse(sse.data);
|
|
@@ -4238,7 +4335,7 @@ class Stream {
|
|
|
4238
4335
|
let consumed = false;
|
|
4239
4336
|
async function* iterLines() {
|
|
4240
4337
|
const lineDecoder = new LineDecoder();
|
|
4241
|
-
const iter =
|
|
4338
|
+
const iter = ReadableStreamToAsyncIterable(readableStream);
|
|
4242
4339
|
for await (const chunk of iter) {
|
|
4243
4340
|
for (const line of lineDecoder.decode(chunk)) {
|
|
4244
4341
|
yield line;
|
|
@@ -4343,7 +4440,7 @@ async function* _iterSSEMessages(response, controller) {
|
|
|
4343
4440
|
}
|
|
4344
4441
|
const sseDecoder = new SSEDecoder();
|
|
4345
4442
|
const lineDecoder = new LineDecoder();
|
|
4346
|
-
const iter =
|
|
4443
|
+
const iter = ReadableStreamToAsyncIterable(response.body);
|
|
4347
4444
|
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
4348
4445
|
for (const line of lineDecoder.decode(sseChunk)) {
|
|
4349
4446
|
const sse = sseDecoder.decode(line);
|
|
@@ -4384,32 +4481,6 @@ async function* iterSSEChunks(iterator) {
|
|
|
4384
4481
|
yield data;
|
|
4385
4482
|
}
|
|
4386
4483
|
}
|
|
4387
|
-
function findDoubleNewlineIndex(buffer) {
|
|
4388
|
-
// This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
|
|
4389
|
-
// and returns the index right after the first occurrence of any pattern,
|
|
4390
|
-
// or -1 if none of the patterns are found.
|
|
4391
|
-
const newline = 0x0a; // \n
|
|
4392
|
-
const carriage = 0x0d; // \r
|
|
4393
|
-
for (let i = 0; i < buffer.length - 2; i++) {
|
|
4394
|
-
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
|
4395
|
-
// \n\n
|
|
4396
|
-
return i + 2;
|
|
4397
|
-
}
|
|
4398
|
-
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
|
4399
|
-
// \r\r
|
|
4400
|
-
return i + 2;
|
|
4401
|
-
}
|
|
4402
|
-
if (buffer[i] === carriage &&
|
|
4403
|
-
buffer[i + 1] === newline &&
|
|
4404
|
-
i + 3 < buffer.length &&
|
|
4405
|
-
buffer[i + 2] === carriage &&
|
|
4406
|
-
buffer[i + 3] === newline) {
|
|
4407
|
-
// \r\n\r\n
|
|
4408
|
-
return i + 4;
|
|
4409
|
-
}
|
|
4410
|
-
}
|
|
4411
|
-
return -1;
|
|
4412
|
-
}
|
|
4413
4484
|
class SSEDecoder {
|
|
4414
4485
|
constructor() {
|
|
4415
4486
|
this.event = null;
|
|
@@ -4458,40 +4529,6 @@ function partition(str, delimiter) {
|
|
|
4458
4529
|
}
|
|
4459
4530
|
return [str, '', ''];
|
|
4460
4531
|
}
|
|
4461
|
-
/**
|
|
4462
|
-
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
4463
|
-
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
4464
|
-
*
|
|
4465
|
-
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
4466
|
-
*/
|
|
4467
|
-
function readableStreamAsyncIterable(stream) {
|
|
4468
|
-
if (stream[Symbol.asyncIterator])
|
|
4469
|
-
return stream;
|
|
4470
|
-
const reader = stream.getReader();
|
|
4471
|
-
return {
|
|
4472
|
-
async next() {
|
|
4473
|
-
try {
|
|
4474
|
-
const result = await reader.read();
|
|
4475
|
-
if (result?.done)
|
|
4476
|
-
reader.releaseLock(); // release lock when stream becomes closed
|
|
4477
|
-
return result;
|
|
4478
|
-
}
|
|
4479
|
-
catch (e) {
|
|
4480
|
-
reader.releaseLock(); // release lock when stream becomes errored
|
|
4481
|
-
throw e;
|
|
4482
|
-
}
|
|
4483
|
-
},
|
|
4484
|
-
async return() {
|
|
4485
|
-
const cancelPromise = reader.cancel();
|
|
4486
|
-
reader.releaseLock();
|
|
4487
|
-
await cancelPromise;
|
|
4488
|
-
return { done: true, value: undefined };
|
|
4489
|
-
},
|
|
4490
|
-
[Symbol.asyncIterator]() {
|
|
4491
|
-
return this;
|
|
4492
|
-
},
|
|
4493
|
-
};
|
|
4494
|
-
}
|
|
4495
4532
|
|
|
4496
4533
|
const isResponseLike = (value) => value != null &&
|
|
4497
4534
|
typeof value === 'object' &&
|
|
@@ -4626,13 +4663,13 @@ const addFormValue = async (form, key, value) => {
|
|
|
4626
4663
|
}
|
|
4627
4664
|
};
|
|
4628
4665
|
|
|
4629
|
-
var __classPrivateFieldSet$
|
|
4666
|
+
var __classPrivateFieldSet$4 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4630
4667
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4631
4668
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4632
4669
|
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");
|
|
4633
4670
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
4634
4671
|
};
|
|
4635
|
-
var __classPrivateFieldGet$
|
|
4672
|
+
var __classPrivateFieldGet$5 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
4636
4673
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4637
4674
|
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");
|
|
4638
4675
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -4657,7 +4694,8 @@ async function defaultParseResponse(props) {
|
|
|
4657
4694
|
return response;
|
|
4658
4695
|
}
|
|
4659
4696
|
const contentType = response.headers.get('content-type');
|
|
4660
|
-
const
|
|
4697
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
4698
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
4661
4699
|
if (isJSON) {
|
|
4662
4700
|
const json = await response.json();
|
|
4663
4701
|
debug('response', response.status, response.url, response.headers, json);
|
|
@@ -4827,6 +4865,7 @@ class APIClient {
|
|
|
4827
4865
|
return null;
|
|
4828
4866
|
}
|
|
4829
4867
|
buildRequest(options, { retryCount = 0 } = {}) {
|
|
4868
|
+
options = { ...options };
|
|
4830
4869
|
const { method, path, query, headers: headers = {} } = options;
|
|
4831
4870
|
const body = ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
|
|
4832
4871
|
options.body
|
|
@@ -4837,9 +4876,9 @@ class APIClient {
|
|
|
4837
4876
|
const url = this.buildURL(path, query);
|
|
4838
4877
|
if ('timeout' in options)
|
|
4839
4878
|
validatePositiveInteger('timeout', options.timeout);
|
|
4840
|
-
|
|
4879
|
+
options.timeout = options.timeout ?? this.timeout;
|
|
4841
4880
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
|
|
4842
|
-
const minAgentTimeout = timeout + 1000;
|
|
4881
|
+
const minAgentTimeout = options.timeout + 1000;
|
|
4843
4882
|
if (typeof httpAgent?.options?.timeout === 'number' &&
|
|
4844
4883
|
minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
|
|
4845
4884
|
// Allow any given request to bump our agent active socket timeout.
|
|
@@ -4863,7 +4902,7 @@ class APIClient {
|
|
|
4863
4902
|
// not compatible with standard web types
|
|
4864
4903
|
signal: options.signal ?? null,
|
|
4865
4904
|
};
|
|
4866
|
-
return { req, url, timeout };
|
|
4905
|
+
return { req, url, timeout: options.timeout };
|
|
4867
4906
|
}
|
|
4868
4907
|
buildHeaders({ options, headers, contentLength, retryCount, }) {
|
|
4869
4908
|
const reqHeaders = {};
|
|
@@ -4877,13 +4916,18 @@ class APIClient {
|
|
|
4877
4916
|
if (isMultipartBody(options.body) && kind !== 'node') {
|
|
4878
4917
|
delete reqHeaders['content-type'];
|
|
4879
4918
|
}
|
|
4880
|
-
// Don't set
|
|
4881
|
-
//
|
|
4882
|
-
//
|
|
4919
|
+
// Don't set theses headers if they were already set or removed through default headers or by the caller.
|
|
4920
|
+
// We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
|
|
4921
|
+
// for the removal case.
|
|
4883
4922
|
if (getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
|
|
4884
4923
|
getHeader(headers, 'x-stainless-retry-count') === undefined) {
|
|
4885
4924
|
reqHeaders['x-stainless-retry-count'] = String(retryCount);
|
|
4886
4925
|
}
|
|
4926
|
+
if (getHeader(defaultHeaders, 'x-stainless-timeout') === undefined &&
|
|
4927
|
+
getHeader(headers, 'x-stainless-timeout') === undefined &&
|
|
4928
|
+
options.timeout) {
|
|
4929
|
+
reqHeaders['x-stainless-timeout'] = String(options.timeout);
|
|
4930
|
+
}
|
|
4887
4931
|
this.validateHeaders(reqHeaders, headers);
|
|
4888
4932
|
return reqHeaders;
|
|
4889
4933
|
}
|
|
@@ -4990,9 +5034,18 @@ class APIClient {
|
|
|
4990
5034
|
if (signal)
|
|
4991
5035
|
signal.addEventListener('abort', () => controller.abort());
|
|
4992
5036
|
const timeout = setTimeout(() => controller.abort(), ms);
|
|
5037
|
+
const fetchOptions = {
|
|
5038
|
+
signal: controller.signal,
|
|
5039
|
+
...options,
|
|
5040
|
+
};
|
|
5041
|
+
if (fetchOptions.method) {
|
|
5042
|
+
// Custom methods like 'patch' need to be uppercased
|
|
5043
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
5044
|
+
fetchOptions.method = fetchOptions.method.toUpperCase();
|
|
5045
|
+
}
|
|
4993
5046
|
return (
|
|
4994
5047
|
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
4995
|
-
this.fetch.call(undefined, url,
|
|
5048
|
+
this.fetch.call(undefined, url, fetchOptions).finally(() => {
|
|
4996
5049
|
clearTimeout(timeout);
|
|
4997
5050
|
}));
|
|
4998
5051
|
}
|
|
@@ -5065,7 +5118,7 @@ class APIClient {
|
|
|
5065
5118
|
class AbstractPage {
|
|
5066
5119
|
constructor(client, response, body, options) {
|
|
5067
5120
|
_AbstractPage_client.set(this, void 0);
|
|
5068
|
-
__classPrivateFieldSet$
|
|
5121
|
+
__classPrivateFieldSet$4(this, _AbstractPage_client, client, "f");
|
|
5069
5122
|
this.options = options;
|
|
5070
5123
|
this.response = response;
|
|
5071
5124
|
this.body = body;
|
|
@@ -5093,7 +5146,7 @@ class AbstractPage {
|
|
|
5093
5146
|
nextOptions.query = undefined;
|
|
5094
5147
|
nextOptions.path = nextInfo.url.toString();
|
|
5095
5148
|
}
|
|
5096
|
-
return await __classPrivateFieldGet$
|
|
5149
|
+
return await __classPrivateFieldGet$5(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
|
|
5097
5150
|
}
|
|
5098
5151
|
async *iterPages() {
|
|
5099
5152
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -5164,6 +5217,7 @@ const requestOptionsKeys = {
|
|
|
5164
5217
|
httpAgent: true,
|
|
5165
5218
|
signal: true,
|
|
5166
5219
|
idempotencyKey: true,
|
|
5220
|
+
__metadata: true,
|
|
5167
5221
|
__binaryRequest: true,
|
|
5168
5222
|
__binaryResponse: true,
|
|
5169
5223
|
__streamClass: true,
|
|
@@ -5387,9 +5441,36 @@ function applyHeadersMut(targetHeaders, newHeaders) {
|
|
|
5387
5441
|
}
|
|
5388
5442
|
}
|
|
5389
5443
|
}
|
|
5444
|
+
const SENSITIVE_HEADERS = new Set(['authorization', 'api-key']);
|
|
5390
5445
|
function debug(action, ...args) {
|
|
5391
5446
|
if (typeof process !== 'undefined' && process?.env?.['DEBUG'] === 'true') {
|
|
5392
|
-
|
|
5447
|
+
const modifiedArgs = args.map((arg) => {
|
|
5448
|
+
if (!arg) {
|
|
5449
|
+
return arg;
|
|
5450
|
+
}
|
|
5451
|
+
// Check for sensitive headers in request body 'headers' object
|
|
5452
|
+
if (arg['headers']) {
|
|
5453
|
+
// clone so we don't mutate
|
|
5454
|
+
const modifiedArg = { ...arg, headers: { ...arg['headers'] } };
|
|
5455
|
+
for (const header in arg['headers']) {
|
|
5456
|
+
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
|
|
5457
|
+
modifiedArg['headers'][header] = 'REDACTED';
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
return modifiedArg;
|
|
5461
|
+
}
|
|
5462
|
+
let modifiedArg = null;
|
|
5463
|
+
// Check for sensitive headers in headers object
|
|
5464
|
+
for (const header in arg) {
|
|
5465
|
+
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
|
|
5466
|
+
// avoid making a copy until we need to
|
|
5467
|
+
modifiedArg ?? (modifiedArg = { ...arg });
|
|
5468
|
+
modifiedArg[header] = 'REDACTED';
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
return modifiedArg ?? arg;
|
|
5472
|
+
});
|
|
5473
|
+
console.log(`OpenAI:DEBUG:${action}`, ...modifiedArgs);
|
|
5393
5474
|
}
|
|
5394
5475
|
}
|
|
5395
5476
|
/**
|
|
@@ -5473,10 +5554,17 @@ class CursorPage extends AbstractPage {
|
|
|
5473
5554
|
constructor(client, response, body, options) {
|
|
5474
5555
|
super(client, response, body, options);
|
|
5475
5556
|
this.data = body.data || [];
|
|
5557
|
+
this.has_more = body.has_more || false;
|
|
5476
5558
|
}
|
|
5477
5559
|
getPaginatedItems() {
|
|
5478
5560
|
return this.data ?? [];
|
|
5479
5561
|
}
|
|
5562
|
+
hasNextPage() {
|
|
5563
|
+
if (this.has_more === false) {
|
|
5564
|
+
return false;
|
|
5565
|
+
}
|
|
5566
|
+
return super.hasNextPage();
|
|
5567
|
+
}
|
|
5480
5568
|
// @deprecated Please use `nextPageInfo()` instead
|
|
5481
5569
|
nextPageParams() {
|
|
5482
5570
|
const info = this.nextPageInfo();
|
|
@@ -5509,12 +5597,60 @@ class APIResource {
|
|
|
5509
5597
|
}
|
|
5510
5598
|
}
|
|
5511
5599
|
|
|
5600
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5601
|
+
let Messages$1 = class Messages extends APIResource {
|
|
5602
|
+
list(completionId, query = {}, options) {
|
|
5603
|
+
if (isRequestOptions(query)) {
|
|
5604
|
+
return this.list(completionId, {}, query);
|
|
5605
|
+
}
|
|
5606
|
+
return this._client.getAPIList(`/chat/completions/${completionId}/messages`, ChatCompletionStoreMessagesPage, { query, ...options });
|
|
5607
|
+
}
|
|
5608
|
+
};
|
|
5609
|
+
|
|
5512
5610
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5513
5611
|
let Completions$2 = class Completions extends APIResource {
|
|
5612
|
+
constructor() {
|
|
5613
|
+
super(...arguments);
|
|
5614
|
+
this.messages = new Messages$1(this._client);
|
|
5615
|
+
}
|
|
5514
5616
|
create(body, options) {
|
|
5515
5617
|
return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false });
|
|
5516
5618
|
}
|
|
5619
|
+
/**
|
|
5620
|
+
* Get a stored chat completion. Only Chat Completions that have been created with
|
|
5621
|
+
* the `store` parameter set to `true` will be returned.
|
|
5622
|
+
*/
|
|
5623
|
+
retrieve(completionId, options) {
|
|
5624
|
+
return this._client.get(`/chat/completions/${completionId}`, options);
|
|
5625
|
+
}
|
|
5626
|
+
/**
|
|
5627
|
+
* Modify a stored chat completion. Only Chat Completions that have been created
|
|
5628
|
+
* with the `store` parameter set to `true` can be modified. Currently, the only
|
|
5629
|
+
* supported modification is to update the `metadata` field.
|
|
5630
|
+
*/
|
|
5631
|
+
update(completionId, body, options) {
|
|
5632
|
+
return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
|
|
5633
|
+
}
|
|
5634
|
+
list(query = {}, options) {
|
|
5635
|
+
if (isRequestOptions(query)) {
|
|
5636
|
+
return this.list({}, query);
|
|
5637
|
+
}
|
|
5638
|
+
return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
|
|
5639
|
+
}
|
|
5640
|
+
/**
|
|
5641
|
+
* Delete a stored chat completion. Only Chat Completions that have been created
|
|
5642
|
+
* with the `store` parameter set to `true` can be deleted.
|
|
5643
|
+
*/
|
|
5644
|
+
del(completionId, options) {
|
|
5645
|
+
return this._client.delete(`/chat/completions/${completionId}`, options);
|
|
5646
|
+
}
|
|
5517
5647
|
};
|
|
5648
|
+
class ChatCompletionsPage extends CursorPage {
|
|
5649
|
+
}
|
|
5650
|
+
class ChatCompletionStoreMessagesPage extends CursorPage {
|
|
5651
|
+
}
|
|
5652
|
+
Completions$2.ChatCompletionsPage = ChatCompletionsPage;
|
|
5653
|
+
Completions$2.Messages = Messages$1;
|
|
5518
5654
|
|
|
5519
5655
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5520
5656
|
let Chat$1 = class Chat extends APIResource {
|
|
@@ -5524,6 +5660,7 @@ let Chat$1 = class Chat extends APIResource {
|
|
|
5524
5660
|
}
|
|
5525
5661
|
};
|
|
5526
5662
|
Chat$1.Completions = Completions$2;
|
|
5663
|
+
Chat$1.ChatCompletionsPage = ChatCompletionsPage;
|
|
5527
5664
|
|
|
5528
5665
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5529
5666
|
class Speech extends APIResource {
|
|
@@ -5531,21 +5668,26 @@ class Speech extends APIResource {
|
|
|
5531
5668
|
* Generates audio from the input text.
|
|
5532
5669
|
*/
|
|
5533
5670
|
create(body, options) {
|
|
5534
|
-
return this._client.post('/audio/speech', {
|
|
5671
|
+
return this._client.post('/audio/speech', {
|
|
5672
|
+
body,
|
|
5673
|
+
...options,
|
|
5674
|
+
headers: { Accept: 'application/octet-stream', ...options?.headers },
|
|
5675
|
+
__binaryResponse: true,
|
|
5676
|
+
});
|
|
5535
5677
|
}
|
|
5536
5678
|
}
|
|
5537
5679
|
|
|
5538
5680
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5539
5681
|
class Transcriptions extends APIResource {
|
|
5540
5682
|
create(body, options) {
|
|
5541
|
-
return this._client.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options }));
|
|
5683
|
+
return this._client.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }));
|
|
5542
5684
|
}
|
|
5543
5685
|
}
|
|
5544
5686
|
|
|
5545
5687
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5546
5688
|
class Translations extends APIResource {
|
|
5547
5689
|
create(body, options) {
|
|
5548
|
-
return this._client.post('/audio/translations', multipartFormRequestOptions({ body, ...options }));
|
|
5690
|
+
return this._client.post('/audio/translations', multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }));
|
|
5549
5691
|
}
|
|
5550
5692
|
}
|
|
5551
5693
|
|
|
@@ -5664,13 +5806,13 @@ const isToolMessage = (message) => {
|
|
|
5664
5806
|
return message?.role === 'tool';
|
|
5665
5807
|
};
|
|
5666
5808
|
|
|
5667
|
-
var __classPrivateFieldSet$
|
|
5809
|
+
var __classPrivateFieldSet$3 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5668
5810
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5669
5811
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5670
5812
|
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");
|
|
5671
5813
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
5672
5814
|
};
|
|
5673
|
-
var __classPrivateFieldGet$
|
|
5815
|
+
var __classPrivateFieldGet$4 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5674
5816
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5675
5817
|
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");
|
|
5676
5818
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -5691,20 +5833,20 @@ class EventStream {
|
|
|
5691
5833
|
_EventStream_errored.set(this, false);
|
|
5692
5834
|
_EventStream_aborted.set(this, false);
|
|
5693
5835
|
_EventStream_catchingPromiseCreated.set(this, false);
|
|
5694
|
-
__classPrivateFieldSet$
|
|
5695
|
-
__classPrivateFieldSet$
|
|
5696
|
-
__classPrivateFieldSet$
|
|
5836
|
+
__classPrivateFieldSet$3(this, _EventStream_connectedPromise, new Promise((resolve, reject) => {
|
|
5837
|
+
__classPrivateFieldSet$3(this, _EventStream_resolveConnectedPromise, resolve, "f");
|
|
5838
|
+
__classPrivateFieldSet$3(this, _EventStream_rejectConnectedPromise, reject, "f");
|
|
5697
5839
|
}), "f");
|
|
5698
|
-
__classPrivateFieldSet$
|
|
5699
|
-
__classPrivateFieldSet$
|
|
5700
|
-
__classPrivateFieldSet$
|
|
5840
|
+
__classPrivateFieldSet$3(this, _EventStream_endPromise, new Promise((resolve, reject) => {
|
|
5841
|
+
__classPrivateFieldSet$3(this, _EventStream_resolveEndPromise, resolve, "f");
|
|
5842
|
+
__classPrivateFieldSet$3(this, _EventStream_rejectEndPromise, reject, "f");
|
|
5701
5843
|
}), "f");
|
|
5702
5844
|
// Don't let these promises cause unhandled rejection errors.
|
|
5703
5845
|
// we will manually cause an unhandled rejection error later
|
|
5704
5846
|
// if the user hasn't registered any error listener or called
|
|
5705
5847
|
// any promise-returning method.
|
|
5706
|
-
__classPrivateFieldGet$
|
|
5707
|
-
__classPrivateFieldGet$
|
|
5848
|
+
__classPrivateFieldGet$4(this, _EventStream_connectedPromise, "f").catch(() => { });
|
|
5849
|
+
__classPrivateFieldGet$4(this, _EventStream_endPromise, "f").catch(() => { });
|
|
5708
5850
|
}
|
|
5709
5851
|
_run(executor) {
|
|
5710
5852
|
// Unfortunately if we call `executor()` immediately we get runtime errors about
|
|
@@ -5713,23 +5855,23 @@ class EventStream {
|
|
|
5713
5855
|
executor().then(() => {
|
|
5714
5856
|
this._emitFinal();
|
|
5715
5857
|
this._emit('end');
|
|
5716
|
-
}, __classPrivateFieldGet$
|
|
5858
|
+
}, __classPrivateFieldGet$4(this, _EventStream_instances, "m", _EventStream_handleError).bind(this));
|
|
5717
5859
|
}, 0);
|
|
5718
5860
|
}
|
|
5719
5861
|
_connected() {
|
|
5720
5862
|
if (this.ended)
|
|
5721
5863
|
return;
|
|
5722
|
-
__classPrivateFieldGet$
|
|
5864
|
+
__classPrivateFieldGet$4(this, _EventStream_resolveConnectedPromise, "f").call(this);
|
|
5723
5865
|
this._emit('connect');
|
|
5724
5866
|
}
|
|
5725
5867
|
get ended() {
|
|
5726
|
-
return __classPrivateFieldGet$
|
|
5868
|
+
return __classPrivateFieldGet$4(this, _EventStream_ended, "f");
|
|
5727
5869
|
}
|
|
5728
5870
|
get errored() {
|
|
5729
|
-
return __classPrivateFieldGet$
|
|
5871
|
+
return __classPrivateFieldGet$4(this, _EventStream_errored, "f");
|
|
5730
5872
|
}
|
|
5731
5873
|
get aborted() {
|
|
5732
|
-
return __classPrivateFieldGet$
|
|
5874
|
+
return __classPrivateFieldGet$4(this, _EventStream_aborted, "f");
|
|
5733
5875
|
}
|
|
5734
5876
|
abort() {
|
|
5735
5877
|
this.controller.abort();
|
|
@@ -5742,7 +5884,7 @@ class EventStream {
|
|
|
5742
5884
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
5743
5885
|
*/
|
|
5744
5886
|
on(event, listener) {
|
|
5745
|
-
const listeners = __classPrivateFieldGet$
|
|
5887
|
+
const listeners = __classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event] = []);
|
|
5746
5888
|
listeners.push({ listener });
|
|
5747
5889
|
return this;
|
|
5748
5890
|
}
|
|
@@ -5754,7 +5896,7 @@ class EventStream {
|
|
|
5754
5896
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
5755
5897
|
*/
|
|
5756
5898
|
off(event, listener) {
|
|
5757
|
-
const listeners = __classPrivateFieldGet$
|
|
5899
|
+
const listeners = __classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event];
|
|
5758
5900
|
if (!listeners)
|
|
5759
5901
|
return this;
|
|
5760
5902
|
const index = listeners.findIndex((l) => l.listener === listener);
|
|
@@ -5768,7 +5910,7 @@ class EventStream {
|
|
|
5768
5910
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
5769
5911
|
*/
|
|
5770
5912
|
once(event, listener) {
|
|
5771
|
-
const listeners = __classPrivateFieldGet$
|
|
5913
|
+
const listeners = __classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event] = []);
|
|
5772
5914
|
listeners.push({ listener, once: true });
|
|
5773
5915
|
return this;
|
|
5774
5916
|
}
|
|
@@ -5785,44 +5927,44 @@ class EventStream {
|
|
|
5785
5927
|
*/
|
|
5786
5928
|
emitted(event) {
|
|
5787
5929
|
return new Promise((resolve, reject) => {
|
|
5788
|
-
__classPrivateFieldSet$
|
|
5930
|
+
__classPrivateFieldSet$3(this, _EventStream_catchingPromiseCreated, true, "f");
|
|
5789
5931
|
if (event !== 'error')
|
|
5790
5932
|
this.once('error', reject);
|
|
5791
5933
|
this.once(event, resolve);
|
|
5792
5934
|
});
|
|
5793
5935
|
}
|
|
5794
5936
|
async done() {
|
|
5795
|
-
__classPrivateFieldSet$
|
|
5796
|
-
await __classPrivateFieldGet$
|
|
5937
|
+
__classPrivateFieldSet$3(this, _EventStream_catchingPromiseCreated, true, "f");
|
|
5938
|
+
await __classPrivateFieldGet$4(this, _EventStream_endPromise, "f");
|
|
5797
5939
|
}
|
|
5798
5940
|
_emit(event, ...args) {
|
|
5799
5941
|
// make sure we don't emit any events after end
|
|
5800
|
-
if (__classPrivateFieldGet$
|
|
5942
|
+
if (__classPrivateFieldGet$4(this, _EventStream_ended, "f")) {
|
|
5801
5943
|
return;
|
|
5802
5944
|
}
|
|
5803
5945
|
if (event === 'end') {
|
|
5804
|
-
__classPrivateFieldSet$
|
|
5805
|
-
__classPrivateFieldGet$
|
|
5946
|
+
__classPrivateFieldSet$3(this, _EventStream_ended, true, "f");
|
|
5947
|
+
__classPrivateFieldGet$4(this, _EventStream_resolveEndPromise, "f").call(this);
|
|
5806
5948
|
}
|
|
5807
|
-
const listeners = __classPrivateFieldGet$
|
|
5949
|
+
const listeners = __classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event];
|
|
5808
5950
|
if (listeners) {
|
|
5809
|
-
__classPrivateFieldGet$
|
|
5951
|
+
__classPrivateFieldGet$4(this, _EventStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
5810
5952
|
listeners.forEach(({ listener }) => listener(...args));
|
|
5811
5953
|
}
|
|
5812
5954
|
if (event === 'abort') {
|
|
5813
5955
|
const error = args[0];
|
|
5814
|
-
if (!__classPrivateFieldGet$
|
|
5956
|
+
if (!__classPrivateFieldGet$4(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
5815
5957
|
Promise.reject(error);
|
|
5816
5958
|
}
|
|
5817
|
-
__classPrivateFieldGet$
|
|
5818
|
-
__classPrivateFieldGet$
|
|
5959
|
+
__classPrivateFieldGet$4(this, _EventStream_rejectConnectedPromise, "f").call(this, error);
|
|
5960
|
+
__classPrivateFieldGet$4(this, _EventStream_rejectEndPromise, "f").call(this, error);
|
|
5819
5961
|
this._emit('end');
|
|
5820
5962
|
return;
|
|
5821
5963
|
}
|
|
5822
5964
|
if (event === 'error') {
|
|
5823
5965
|
// NOTE: _emit('error', error) should only be called from #handleError().
|
|
5824
5966
|
const error = args[0];
|
|
5825
|
-
if (!__classPrivateFieldGet$
|
|
5967
|
+
if (!__classPrivateFieldGet$4(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
5826
5968
|
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
|
5827
5969
|
// If you are seeing stack traces here, make sure to handle errors via either:
|
|
5828
5970
|
// - runner.on('error', () => ...)
|
|
@@ -5831,20 +5973,20 @@ class EventStream {
|
|
|
5831
5973
|
// - etc.
|
|
5832
5974
|
Promise.reject(error);
|
|
5833
5975
|
}
|
|
5834
|
-
__classPrivateFieldGet$
|
|
5835
|
-
__classPrivateFieldGet$
|
|
5976
|
+
__classPrivateFieldGet$4(this, _EventStream_rejectConnectedPromise, "f").call(this, error);
|
|
5977
|
+
__classPrivateFieldGet$4(this, _EventStream_rejectEndPromise, "f").call(this, error);
|
|
5836
5978
|
this._emit('end');
|
|
5837
5979
|
}
|
|
5838
5980
|
}
|
|
5839
5981
|
_emitFinal() { }
|
|
5840
5982
|
}
|
|
5841
5983
|
_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) {
|
|
5842
|
-
__classPrivateFieldSet$
|
|
5984
|
+
__classPrivateFieldSet$3(this, _EventStream_errored, true, "f");
|
|
5843
5985
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
5844
5986
|
error = new APIUserAbortError();
|
|
5845
5987
|
}
|
|
5846
5988
|
if (error instanceof APIUserAbortError) {
|
|
5847
|
-
__classPrivateFieldSet$
|
|
5989
|
+
__classPrivateFieldSet$3(this, _EventStream_aborted, true, "f");
|
|
5848
5990
|
return this._emit('abort', error);
|
|
5849
5991
|
}
|
|
5850
5992
|
if (error instanceof OpenAIError) {
|
|
@@ -5862,16 +6004,24 @@ _EventStream_connectedPromise = new WeakMap(), _EventStream_resolveConnectedProm
|
|
|
5862
6004
|
function isAutoParsableResponseFormat(response_format) {
|
|
5863
6005
|
return response_format?.['$brand'] === 'auto-parseable-response-format';
|
|
5864
6006
|
}
|
|
5865
|
-
function isAutoParsableTool(tool) {
|
|
6007
|
+
function isAutoParsableTool$1(tool) {
|
|
5866
6008
|
return tool?.['$brand'] === 'auto-parseable-tool';
|
|
5867
6009
|
}
|
|
5868
6010
|
function maybeParseChatCompletion(completion, params) {
|
|
5869
|
-
if (!params || !hasAutoParseableInput(params)) {
|
|
6011
|
+
if (!params || !hasAutoParseableInput$1(params)) {
|
|
5870
6012
|
return {
|
|
5871
6013
|
...completion,
|
|
5872
6014
|
choices: completion.choices.map((choice) => ({
|
|
5873
6015
|
...choice,
|
|
5874
|
-
message: {
|
|
6016
|
+
message: {
|
|
6017
|
+
...choice.message,
|
|
6018
|
+
parsed: null,
|
|
6019
|
+
...(choice.message.tool_calls ?
|
|
6020
|
+
{
|
|
6021
|
+
tool_calls: choice.message.tool_calls,
|
|
6022
|
+
}
|
|
6023
|
+
: undefined),
|
|
6024
|
+
},
|
|
5875
6025
|
})),
|
|
5876
6026
|
};
|
|
5877
6027
|
}
|
|
@@ -5889,7 +6039,11 @@ function parseChatCompletion(completion, params) {
|
|
|
5889
6039
|
...choice,
|
|
5890
6040
|
message: {
|
|
5891
6041
|
...choice.message,
|
|
5892
|
-
|
|
6042
|
+
...(choice.message.tool_calls ?
|
|
6043
|
+
{
|
|
6044
|
+
tool_calls: choice.message.tool_calls?.map((toolCall) => parseToolCall$1(params, toolCall)) ?? undefined,
|
|
6045
|
+
}
|
|
6046
|
+
: undefined),
|
|
5893
6047
|
parsed: choice.message.content && !choice.message.refusal ?
|
|
5894
6048
|
parseResponseFormat(params, choice.message.content)
|
|
5895
6049
|
: null,
|
|
@@ -5911,13 +6065,13 @@ function parseResponseFormat(params, content) {
|
|
|
5911
6065
|
}
|
|
5912
6066
|
return null;
|
|
5913
6067
|
}
|
|
5914
|
-
function parseToolCall(params, toolCall) {
|
|
6068
|
+
function parseToolCall$1(params, toolCall) {
|
|
5915
6069
|
const inputTool = params.tools?.find((inputTool) => inputTool.function?.name === toolCall.function.name);
|
|
5916
6070
|
return {
|
|
5917
6071
|
...toolCall,
|
|
5918
6072
|
function: {
|
|
5919
6073
|
...toolCall.function,
|
|
5920
|
-
parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments)
|
|
6074
|
+
parsed_arguments: isAutoParsableTool$1(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments)
|
|
5921
6075
|
: inputTool?.function.strict ? JSON.parse(toolCall.function.arguments)
|
|
5922
6076
|
: null,
|
|
5923
6077
|
},
|
|
@@ -5928,13 +6082,13 @@ function shouldParseToolCall(params, toolCall) {
|
|
|
5928
6082
|
return false;
|
|
5929
6083
|
}
|
|
5930
6084
|
const inputTool = params.tools?.find((inputTool) => inputTool.function?.name === toolCall.function.name);
|
|
5931
|
-
return isAutoParsableTool(inputTool) || inputTool?.function.strict || false;
|
|
6085
|
+
return isAutoParsableTool$1(inputTool) || inputTool?.function.strict || false;
|
|
5932
6086
|
}
|
|
5933
|
-
function hasAutoParseableInput(params) {
|
|
6087
|
+
function hasAutoParseableInput$1(params) {
|
|
5934
6088
|
if (isAutoParsableResponseFormat(params.response_format)) {
|
|
5935
6089
|
return true;
|
|
5936
6090
|
}
|
|
5937
|
-
return (params.tools?.some((t) => isAutoParsableTool(t) || (t.type === 'function' && t.function.strict === true)) ?? false);
|
|
6091
|
+
return (params.tools?.some((t) => isAutoParsableTool$1(t) || (t.type === 'function' && t.function.strict === true)) ?? false);
|
|
5938
6092
|
}
|
|
5939
6093
|
function validateInputTools(tools) {
|
|
5940
6094
|
for (const tool of tools ?? []) {
|
|
@@ -5947,7 +6101,7 @@ function validateInputTools(tools) {
|
|
|
5947
6101
|
}
|
|
5948
6102
|
}
|
|
5949
6103
|
|
|
5950
|
-
var __classPrivateFieldGet$
|
|
6104
|
+
var __classPrivateFieldGet$3 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5951
6105
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5952
6106
|
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");
|
|
5953
6107
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -6008,7 +6162,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6008
6162
|
*/
|
|
6009
6163
|
async finalContent() {
|
|
6010
6164
|
await this.done();
|
|
6011
|
-
return __classPrivateFieldGet$
|
|
6165
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this);
|
|
6012
6166
|
}
|
|
6013
6167
|
/**
|
|
6014
6168
|
* @returns a promise that resolves with the the final assistant ChatCompletionMessage response,
|
|
@@ -6016,7 +6170,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6016
6170
|
*/
|
|
6017
6171
|
async finalMessage() {
|
|
6018
6172
|
await this.done();
|
|
6019
|
-
return __classPrivateFieldGet$
|
|
6173
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this);
|
|
6020
6174
|
}
|
|
6021
6175
|
/**
|
|
6022
6176
|
* @returns a promise that resolves with the content of the final FunctionCall, or rejects
|
|
@@ -6024,15 +6178,15 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6024
6178
|
*/
|
|
6025
6179
|
async finalFunctionCall() {
|
|
6026
6180
|
await this.done();
|
|
6027
|
-
return __classPrivateFieldGet$
|
|
6181
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this);
|
|
6028
6182
|
}
|
|
6029
6183
|
async finalFunctionCallResult() {
|
|
6030
6184
|
await this.done();
|
|
6031
|
-
return __classPrivateFieldGet$
|
|
6185
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this);
|
|
6032
6186
|
}
|
|
6033
6187
|
async totalUsage() {
|
|
6034
6188
|
await this.done();
|
|
6035
|
-
return __classPrivateFieldGet$
|
|
6189
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this);
|
|
6036
6190
|
}
|
|
6037
6191
|
allChatCompletions() {
|
|
6038
6192
|
return [...this._chatCompletions];
|
|
@@ -6041,20 +6195,20 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6041
6195
|
const completion = this._chatCompletions[this._chatCompletions.length - 1];
|
|
6042
6196
|
if (completion)
|
|
6043
6197
|
this._emit('finalChatCompletion', completion);
|
|
6044
|
-
const finalMessage = __classPrivateFieldGet$
|
|
6198
|
+
const finalMessage = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this);
|
|
6045
6199
|
if (finalMessage)
|
|
6046
6200
|
this._emit('finalMessage', finalMessage);
|
|
6047
|
-
const finalContent = __classPrivateFieldGet$
|
|
6201
|
+
const finalContent = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this);
|
|
6048
6202
|
if (finalContent)
|
|
6049
6203
|
this._emit('finalContent', finalContent);
|
|
6050
|
-
const finalFunctionCall = __classPrivateFieldGet$
|
|
6204
|
+
const finalFunctionCall = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this);
|
|
6051
6205
|
if (finalFunctionCall)
|
|
6052
6206
|
this._emit('finalFunctionCall', finalFunctionCall);
|
|
6053
|
-
const finalFunctionCallResult = __classPrivateFieldGet$
|
|
6207
|
+
const finalFunctionCallResult = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this);
|
|
6054
6208
|
if (finalFunctionCallResult != null)
|
|
6055
6209
|
this._emit('finalFunctionCallResult', finalFunctionCallResult);
|
|
6056
6210
|
if (this._chatCompletions.some((c) => c.usage)) {
|
|
6057
|
-
this._emit('totalUsage', __classPrivateFieldGet$
|
|
6211
|
+
this._emit('totalUsage', __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this));
|
|
6058
6212
|
}
|
|
6059
6213
|
}
|
|
6060
6214
|
async _createChatCompletion(client, params, options) {
|
|
@@ -6064,7 +6218,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6064
6218
|
this.controller.abort();
|
|
6065
6219
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
6066
6220
|
}
|
|
6067
|
-
__classPrivateFieldGet$
|
|
6221
|
+
__classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_validateParams).call(this, params);
|
|
6068
6222
|
const chatCompletion = await client.chat.completions.create({ ...params, stream: false }, { ...options, signal: this.controller.signal });
|
|
6069
6223
|
this._connected();
|
|
6070
6224
|
return this._addChatCompletion(parseChatCompletion(chatCompletion, params));
|
|
@@ -6133,7 +6287,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6133
6287
|
}
|
|
6134
6288
|
// @ts-expect-error it can't rule out `never` type.
|
|
6135
6289
|
const rawContent = await fn.function(parsed, this);
|
|
6136
|
-
const content = __classPrivateFieldGet$
|
|
6290
|
+
const content = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent);
|
|
6137
6291
|
this._addMessage({ role, name, content });
|
|
6138
6292
|
if (singleFunctionToCall)
|
|
6139
6293
|
return;
|
|
@@ -6146,7 +6300,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6146
6300
|
const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {};
|
|
6147
6301
|
// TODO(someday): clean this logic up
|
|
6148
6302
|
const inputTools = params.tools.map((tool) => {
|
|
6149
|
-
if (isAutoParsableTool(tool)) {
|
|
6303
|
+
if (isAutoParsableTool$1(tool)) {
|
|
6150
6304
|
if (!tool.$callback) {
|
|
6151
6305
|
throw new OpenAIError('Tool given to `.runTools()` that does not have an associated function');
|
|
6152
6306
|
}
|
|
@@ -6229,7 +6383,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6229
6383
|
}
|
|
6230
6384
|
// @ts-expect-error it can't rule out `never` type.
|
|
6231
6385
|
const rawContent = await fn.function(parsed, this);
|
|
6232
|
-
const content = __classPrivateFieldGet$
|
|
6386
|
+
const content = __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent);
|
|
6233
6387
|
this._addMessage({ role, tool_call_id, content });
|
|
6234
6388
|
if (singleFunctionToCall) {
|
|
6235
6389
|
return;
|
|
@@ -6240,7 +6394,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
6240
6394
|
}
|
|
6241
6395
|
}
|
|
6242
6396
|
_AbstractChatCompletionRunner_instances = new WeakSet(), _AbstractChatCompletionRunner_getFinalContent = function _AbstractChatCompletionRunner_getFinalContent() {
|
|
6243
|
-
return __classPrivateFieldGet$
|
|
6397
|
+
return __classPrivateFieldGet$3(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this).content ?? null;
|
|
6244
6398
|
}, _AbstractChatCompletionRunner_getFinalMessage = function _AbstractChatCompletionRunner_getFinalMessage() {
|
|
6245
6399
|
let i = this.messages.length;
|
|
6246
6400
|
while (i-- > 0) {
|
|
@@ -6578,13 +6732,13 @@ const _parseJSON = (jsonString, allow) => {
|
|
|
6578
6732
|
// using this function with malformed JSON is undefined behavior
|
|
6579
6733
|
const partialParse = (input) => parseJSON(input, Allow.ALL ^ Allow.NUM);
|
|
6580
6734
|
|
|
6581
|
-
var __classPrivateFieldSet$
|
|
6735
|
+
var __classPrivateFieldSet$2 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
6582
6736
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6583
6737
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
6584
6738
|
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");
|
|
6585
6739
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6586
6740
|
};
|
|
6587
|
-
var __classPrivateFieldGet$
|
|
6741
|
+
var __classPrivateFieldGet$2 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
6588
6742
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
6589
6743
|
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");
|
|
6590
6744
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -6597,11 +6751,11 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6597
6751
|
_ChatCompletionStream_params.set(this, void 0);
|
|
6598
6752
|
_ChatCompletionStream_choiceEventStates.set(this, void 0);
|
|
6599
6753
|
_ChatCompletionStream_currentChatCompletionSnapshot.set(this, void 0);
|
|
6600
|
-
__classPrivateFieldSet$
|
|
6601
|
-
__classPrivateFieldSet$
|
|
6754
|
+
__classPrivateFieldSet$2(this, _ChatCompletionStream_params, params, "f");
|
|
6755
|
+
__classPrivateFieldSet$2(this, _ChatCompletionStream_choiceEventStates, [], "f");
|
|
6602
6756
|
}
|
|
6603
6757
|
get currentChatCompletionSnapshot() {
|
|
6604
|
-
return __classPrivateFieldGet$
|
|
6758
|
+
return __classPrivateFieldGet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
6605
6759
|
}
|
|
6606
6760
|
/**
|
|
6607
6761
|
* Intended for use on the frontend, consuming a stream produced with
|
|
@@ -6628,16 +6782,16 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6628
6782
|
this.controller.abort();
|
|
6629
6783
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
6630
6784
|
}
|
|
6631
|
-
__classPrivateFieldGet$
|
|
6785
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
|
|
6632
6786
|
const stream = await client.chat.completions.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
|
|
6633
6787
|
this._connected();
|
|
6634
6788
|
for await (const chunk of stream) {
|
|
6635
|
-
__classPrivateFieldGet$
|
|
6789
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
|
|
6636
6790
|
}
|
|
6637
6791
|
if (stream.controller.signal?.aborted) {
|
|
6638
6792
|
throw new APIUserAbortError();
|
|
6639
6793
|
}
|
|
6640
|
-
return this._addChatCompletion(__classPrivateFieldGet$
|
|
6794
|
+
return this._addChatCompletion(__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
6641
6795
|
}
|
|
6642
6796
|
async _fromReadableStream(readableStream, options) {
|
|
6643
6797
|
const signal = options?.signal;
|
|
@@ -6646,29 +6800,29 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6646
6800
|
this.controller.abort();
|
|
6647
6801
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
6648
6802
|
}
|
|
6649
|
-
__classPrivateFieldGet$
|
|
6803
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
|
|
6650
6804
|
this._connected();
|
|
6651
6805
|
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
6652
6806
|
let chatId;
|
|
6653
6807
|
for await (const chunk of stream) {
|
|
6654
6808
|
if (chatId && chatId !== chunk.id) {
|
|
6655
6809
|
// A new request has been made.
|
|
6656
|
-
this._addChatCompletion(__classPrivateFieldGet$
|
|
6810
|
+
this._addChatCompletion(__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
6657
6811
|
}
|
|
6658
|
-
__classPrivateFieldGet$
|
|
6812
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
|
|
6659
6813
|
chatId = chunk.id;
|
|
6660
6814
|
}
|
|
6661
6815
|
if (stream.controller.signal?.aborted) {
|
|
6662
6816
|
throw new APIUserAbortError();
|
|
6663
6817
|
}
|
|
6664
|
-
return this._addChatCompletion(__classPrivateFieldGet$
|
|
6818
|
+
return this._addChatCompletion(__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
6665
6819
|
}
|
|
6666
6820
|
[(_ChatCompletionStream_params = new WeakMap(), _ChatCompletionStream_choiceEventStates = new WeakMap(), _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap(), _ChatCompletionStream_instances = new WeakSet(), _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
|
|
6667
6821
|
if (this.ended)
|
|
6668
6822
|
return;
|
|
6669
|
-
__classPrivateFieldSet$
|
|
6823
|
+
__classPrivateFieldSet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
|
|
6670
6824
|
}, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
|
|
6671
|
-
let state = __classPrivateFieldGet$
|
|
6825
|
+
let state = __classPrivateFieldGet$2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
|
|
6672
6826
|
if (state) {
|
|
6673
6827
|
return state;
|
|
6674
6828
|
}
|
|
@@ -6680,12 +6834,12 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6680
6834
|
done_tool_calls: new Set(),
|
|
6681
6835
|
current_tool_call_index: null,
|
|
6682
6836
|
};
|
|
6683
|
-
__classPrivateFieldGet$
|
|
6837
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
|
|
6684
6838
|
return state;
|
|
6685
6839
|
}, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
|
|
6686
6840
|
if (this.ended)
|
|
6687
6841
|
return;
|
|
6688
|
-
const completion = __classPrivateFieldGet$
|
|
6842
|
+
const completion = __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
|
|
6689
6843
|
this._emit('chunk', chunk, completion);
|
|
6690
6844
|
for (const choice of chunk.choices) {
|
|
6691
6845
|
const choiceSnapshot = completion.choices[choice.index];
|
|
@@ -6719,19 +6873,19 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6719
6873
|
snapshot: choiceSnapshot.logprobs?.refusal ?? [],
|
|
6720
6874
|
});
|
|
6721
6875
|
}
|
|
6722
|
-
const state = __classPrivateFieldGet$
|
|
6876
|
+
const state = __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
6723
6877
|
if (choiceSnapshot.finish_reason) {
|
|
6724
|
-
__classPrivateFieldGet$
|
|
6878
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
|
|
6725
6879
|
if (state.current_tool_call_index != null) {
|
|
6726
|
-
__classPrivateFieldGet$
|
|
6880
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index);
|
|
6727
6881
|
}
|
|
6728
6882
|
}
|
|
6729
6883
|
for (const toolCall of choice.delta.tool_calls ?? []) {
|
|
6730
6884
|
if (state.current_tool_call_index !== toolCall.index) {
|
|
6731
|
-
__classPrivateFieldGet$
|
|
6885
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
|
|
6732
6886
|
// new tool call started, the previous one is done
|
|
6733
6887
|
if (state.current_tool_call_index != null) {
|
|
6734
|
-
__classPrivateFieldGet$
|
|
6888
|
+
__classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index);
|
|
6735
6889
|
}
|
|
6736
6890
|
}
|
|
6737
6891
|
state.current_tool_call_index = toolCall.index;
|
|
@@ -6756,7 +6910,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6756
6910
|
}
|
|
6757
6911
|
}
|
|
6758
6912
|
}, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) {
|
|
6759
|
-
const state = __classPrivateFieldGet$
|
|
6913
|
+
const state = __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
6760
6914
|
if (state.done_tool_calls.has(toolCallIndex)) {
|
|
6761
6915
|
// we've already fired the done event
|
|
6762
6916
|
return;
|
|
@@ -6769,12 +6923,12 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6769
6923
|
throw new Error('tool call snapshot missing `type`');
|
|
6770
6924
|
}
|
|
6771
6925
|
if (toolCallSnapshot.type === 'function') {
|
|
6772
|
-
const inputTool = __classPrivateFieldGet$
|
|
6926
|
+
const inputTool = __classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f")?.tools?.find((tool) => tool.type === 'function' && tool.function.name === toolCallSnapshot.function.name);
|
|
6773
6927
|
this._emit('tool_calls.function.arguments.done', {
|
|
6774
6928
|
name: toolCallSnapshot.function.name,
|
|
6775
6929
|
index: toolCallIndex,
|
|
6776
6930
|
arguments: toolCallSnapshot.function.arguments,
|
|
6777
|
-
parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
|
|
6931
|
+
parsed_arguments: isAutoParsableTool$1(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
|
|
6778
6932
|
: inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)
|
|
6779
6933
|
: null,
|
|
6780
6934
|
});
|
|
@@ -6783,10 +6937,10 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6783
6937
|
assertNever(toolCallSnapshot.type);
|
|
6784
6938
|
}
|
|
6785
6939
|
}, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
|
|
6786
|
-
const state = __classPrivateFieldGet$
|
|
6940
|
+
const state = __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
6787
6941
|
if (choiceSnapshot.message.content && !state.content_done) {
|
|
6788
6942
|
state.content_done = true;
|
|
6789
|
-
const responseFormat = __classPrivateFieldGet$
|
|
6943
|
+
const responseFormat = __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this);
|
|
6790
6944
|
this._emit('content.done', {
|
|
6791
6945
|
content: choiceSnapshot.message.content,
|
|
6792
6946
|
parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : null,
|
|
@@ -6808,25 +6962,25 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6808
6962
|
if (this.ended) {
|
|
6809
6963
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
6810
6964
|
}
|
|
6811
|
-
const snapshot = __classPrivateFieldGet$
|
|
6965
|
+
const snapshot = __classPrivateFieldGet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
6812
6966
|
if (!snapshot) {
|
|
6813
6967
|
throw new OpenAIError(`request ended without sending any chunks`);
|
|
6814
6968
|
}
|
|
6815
|
-
__classPrivateFieldSet$
|
|
6816
|
-
__classPrivateFieldSet$
|
|
6817
|
-
return finalizeChatCompletion(snapshot, __classPrivateFieldGet$
|
|
6969
|
+
__classPrivateFieldSet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
|
|
6970
|
+
__classPrivateFieldSet$2(this, _ChatCompletionStream_choiceEventStates, [], "f");
|
|
6971
|
+
return finalizeChatCompletion(snapshot, __classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f"));
|
|
6818
6972
|
}, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
|
|
6819
|
-
const responseFormat = __classPrivateFieldGet$
|
|
6973
|
+
const responseFormat = __classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f")?.response_format;
|
|
6820
6974
|
if (isAutoParsableResponseFormat(responseFormat)) {
|
|
6821
6975
|
return responseFormat;
|
|
6822
6976
|
}
|
|
6823
6977
|
return null;
|
|
6824
6978
|
}, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
|
|
6825
6979
|
var _a, _b, _c, _d;
|
|
6826
|
-
let snapshot = __classPrivateFieldGet$
|
|
6980
|
+
let snapshot = __classPrivateFieldGet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
6827
6981
|
const { choices, ...rest } = chunk;
|
|
6828
6982
|
if (!snapshot) {
|
|
6829
|
-
snapshot = __classPrivateFieldSet$
|
|
6983
|
+
snapshot = __classPrivateFieldSet$2(this, _ChatCompletionStream_currentChatCompletionSnapshot, {
|
|
6830
6984
|
...rest,
|
|
6831
6985
|
choices: [],
|
|
6832
6986
|
}, "f");
|
|
@@ -6858,7 +7012,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6858
7012
|
}
|
|
6859
7013
|
if (finish_reason) {
|
|
6860
7014
|
choice.finish_reason = finish_reason;
|
|
6861
|
-
if (__classPrivateFieldGet$
|
|
7015
|
+
if (__classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f") && hasAutoParseableInput$1(__classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f"))) {
|
|
6862
7016
|
if (finish_reason === 'length') {
|
|
6863
7017
|
throw new LengthFinishReasonError();
|
|
6864
7018
|
}
|
|
@@ -6892,7 +7046,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6892
7046
|
}
|
|
6893
7047
|
if (content) {
|
|
6894
7048
|
choice.message.content = (choice.message.content || '') + content;
|
|
6895
|
-
if (!choice.message.refusal && __classPrivateFieldGet$
|
|
7049
|
+
if (!choice.message.refusal && __classPrivateFieldGet$2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this)) {
|
|
6896
7050
|
choice.message.parsed = partialParse(choice.message.content);
|
|
6897
7051
|
}
|
|
6898
7052
|
}
|
|
@@ -6912,7 +7066,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
6912
7066
|
tool_call.function.name = fn.name;
|
|
6913
7067
|
if (fn?.arguments) {
|
|
6914
7068
|
tool_call.function.arguments += fn.arguments;
|
|
6915
|
-
if (shouldParseToolCall(__classPrivateFieldGet$
|
|
7069
|
+
if (shouldParseToolCall(__classPrivateFieldGet$2(this, _ChatCompletionStream_params, "f"), tool_call)) {
|
|
6916
7070
|
tool_call.function.parsed_arguments = partialParse(tool_call.function.arguments);
|
|
6917
7071
|
}
|
|
6918
7072
|
}
|
|
@@ -7136,12 +7290,41 @@ class Chat extends APIResource {
|
|
|
7136
7290
|
Chat.Completions = Completions$1;
|
|
7137
7291
|
})(Chat || (Chat = {}));
|
|
7138
7292
|
|
|
7139
|
-
|
|
7293
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
7294
|
+
class Sessions extends APIResource {
|
|
7295
|
+
/**
|
|
7296
|
+
* Create an ephemeral API token for use in client-side applications with the
|
|
7297
|
+
* Realtime API. Can be configured with the same session parameters as the
|
|
7298
|
+
* `session.update` client event.
|
|
7299
|
+
*
|
|
7300
|
+
* It responds with a session object, plus a `client_secret` key which contains a
|
|
7301
|
+
* usable ephemeral API token that can be used to authenticate browser clients for
|
|
7302
|
+
* the Realtime API.
|
|
7303
|
+
*/
|
|
7304
|
+
create(body, options) {
|
|
7305
|
+
return this._client.post('/realtime/sessions', {
|
|
7306
|
+
body,
|
|
7307
|
+
...options,
|
|
7308
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
7309
|
+
});
|
|
7310
|
+
}
|
|
7311
|
+
}
|
|
7312
|
+
|
|
7313
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
7314
|
+
class Realtime extends APIResource {
|
|
7315
|
+
constructor() {
|
|
7316
|
+
super(...arguments);
|
|
7317
|
+
this.sessions = new Sessions(this._client);
|
|
7318
|
+
}
|
|
7319
|
+
}
|
|
7320
|
+
Realtime.Sessions = Sessions;
|
|
7321
|
+
|
|
7322
|
+
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
7140
7323
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
7141
7324
|
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");
|
|
7142
7325
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7143
7326
|
};
|
|
7144
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7327
|
+
var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7145
7328
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7146
7329
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7147
7330
|
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");
|
|
@@ -7236,12 +7419,12 @@ class AssistantStream extends EventStream {
|
|
|
7236
7419
|
this._connected();
|
|
7237
7420
|
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
7238
7421
|
for await (const event of stream) {
|
|
7239
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7422
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7240
7423
|
}
|
|
7241
7424
|
if (stream.controller.signal?.aborted) {
|
|
7242
7425
|
throw new APIUserAbortError();
|
|
7243
7426
|
}
|
|
7244
|
-
return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7427
|
+
return this._addRun(__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7245
7428
|
}
|
|
7246
7429
|
toReadableStream() {
|
|
7247
7430
|
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
@@ -7269,12 +7452,12 @@ class AssistantStream extends EventStream {
|
|
|
7269
7452
|
});
|
|
7270
7453
|
this._connected();
|
|
7271
7454
|
for await (const event of stream) {
|
|
7272
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7455
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7273
7456
|
}
|
|
7274
7457
|
if (stream.controller.signal?.aborted) {
|
|
7275
7458
|
throw new APIUserAbortError();
|
|
7276
7459
|
}
|
|
7277
|
-
return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7460
|
+
return this._addRun(__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7278
7461
|
}
|
|
7279
7462
|
static createThreadAssistantStream(params, thread, options) {
|
|
7280
7463
|
const runner = new AssistantStream();
|
|
@@ -7293,30 +7476,30 @@ class AssistantStream extends EventStream {
|
|
|
7293
7476
|
return runner;
|
|
7294
7477
|
}
|
|
7295
7478
|
currentEvent() {
|
|
7296
|
-
return __classPrivateFieldGet(this, _AssistantStream_currentEvent, "f");
|
|
7479
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_currentEvent, "f");
|
|
7297
7480
|
}
|
|
7298
7481
|
currentRun() {
|
|
7299
|
-
return __classPrivateFieldGet(this, _AssistantStream_currentRunSnapshot, "f");
|
|
7482
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_currentRunSnapshot, "f");
|
|
7300
7483
|
}
|
|
7301
7484
|
currentMessageSnapshot() {
|
|
7302
|
-
return __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f");
|
|
7485
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f");
|
|
7303
7486
|
}
|
|
7304
7487
|
currentRunStepSnapshot() {
|
|
7305
|
-
return __classPrivateFieldGet(this, _AssistantStream_currentRunStepSnapshot, "f");
|
|
7488
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_currentRunStepSnapshot, "f");
|
|
7306
7489
|
}
|
|
7307
7490
|
async finalRunSteps() {
|
|
7308
7491
|
await this.done();
|
|
7309
|
-
return Object.values(__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f"));
|
|
7492
|
+
return Object.values(__classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f"));
|
|
7310
7493
|
}
|
|
7311
7494
|
async finalMessages() {
|
|
7312
7495
|
await this.done();
|
|
7313
|
-
return Object.values(__classPrivateFieldGet(this, _AssistantStream_messageSnapshots, "f"));
|
|
7496
|
+
return Object.values(__classPrivateFieldGet$1(this, _AssistantStream_messageSnapshots, "f"));
|
|
7314
7497
|
}
|
|
7315
7498
|
async finalRun() {
|
|
7316
7499
|
await this.done();
|
|
7317
|
-
if (!__classPrivateFieldGet(this, _AssistantStream_finalRun, "f"))
|
|
7500
|
+
if (!__classPrivateFieldGet$1(this, _AssistantStream_finalRun, "f"))
|
|
7318
7501
|
throw Error('Final run was not received.');
|
|
7319
|
-
return __classPrivateFieldGet(this, _AssistantStream_finalRun, "f");
|
|
7502
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_finalRun, "f");
|
|
7320
7503
|
}
|
|
7321
7504
|
async _createThreadAssistantStream(thread, params, options) {
|
|
7322
7505
|
const signal = options?.signal;
|
|
@@ -7329,12 +7512,12 @@ class AssistantStream extends EventStream {
|
|
|
7329
7512
|
const stream = await thread.createAndRun(body, { ...options, signal: this.controller.signal });
|
|
7330
7513
|
this._connected();
|
|
7331
7514
|
for await (const event of stream) {
|
|
7332
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7515
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7333
7516
|
}
|
|
7334
7517
|
if (stream.controller.signal?.aborted) {
|
|
7335
7518
|
throw new APIUserAbortError();
|
|
7336
7519
|
}
|
|
7337
|
-
return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7520
|
+
return this._addRun(__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7338
7521
|
}
|
|
7339
7522
|
async _createAssistantStream(run, threadId, params, options) {
|
|
7340
7523
|
const signal = options?.signal;
|
|
@@ -7347,12 +7530,12 @@ class AssistantStream extends EventStream {
|
|
|
7347
7530
|
const stream = await run.create(threadId, body, { ...options, signal: this.controller.signal });
|
|
7348
7531
|
this._connected();
|
|
7349
7532
|
for await (const event of stream) {
|
|
7350
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7533
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
7351
7534
|
}
|
|
7352
7535
|
if (stream.controller.signal?.aborted) {
|
|
7353
7536
|
throw new APIUserAbortError();
|
|
7354
7537
|
}
|
|
7355
|
-
return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7538
|
+
return this._addRun(__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
7356
7539
|
}
|
|
7357
7540
|
static accumulateDelta(acc, delta) {
|
|
7358
7541
|
for (const [key, deltaValue] of Object.entries(delta)) {
|
|
@@ -7430,8 +7613,8 @@ class AssistantStream extends EventStream {
|
|
|
7430
7613
|
_AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
7431
7614
|
if (this.ended)
|
|
7432
7615
|
return;
|
|
7433
|
-
__classPrivateFieldSet(this, _AssistantStream_currentEvent, event, "f");
|
|
7434
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleEvent).call(this, event);
|
|
7616
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentEvent, event, "f");
|
|
7617
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_handleEvent).call(this, event);
|
|
7435
7618
|
switch (event.event) {
|
|
7436
7619
|
case 'thread.created':
|
|
7437
7620
|
//No action on this event.
|
|
@@ -7441,11 +7624,12 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7441
7624
|
case 'thread.run.in_progress':
|
|
7442
7625
|
case 'thread.run.requires_action':
|
|
7443
7626
|
case 'thread.run.completed':
|
|
7627
|
+
case 'thread.run.incomplete':
|
|
7444
7628
|
case 'thread.run.failed':
|
|
7445
7629
|
case 'thread.run.cancelling':
|
|
7446
7630
|
case 'thread.run.cancelled':
|
|
7447
7631
|
case 'thread.run.expired':
|
|
7448
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleRun).call(this, event);
|
|
7632
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_handleRun).call(this, event);
|
|
7449
7633
|
break;
|
|
7450
7634
|
case 'thread.run.step.created':
|
|
7451
7635
|
case 'thread.run.step.in_progress':
|
|
@@ -7454,14 +7638,14 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7454
7638
|
case 'thread.run.step.failed':
|
|
7455
7639
|
case 'thread.run.step.cancelled':
|
|
7456
7640
|
case 'thread.run.step.expired':
|
|
7457
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleRunStep).call(this, event);
|
|
7641
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_handleRunStep).call(this, event);
|
|
7458
7642
|
break;
|
|
7459
7643
|
case 'thread.message.created':
|
|
7460
7644
|
case 'thread.message.in_progress':
|
|
7461
7645
|
case 'thread.message.delta':
|
|
7462
7646
|
case 'thread.message.completed':
|
|
7463
7647
|
case 'thread.message.incomplete':
|
|
7464
|
-
__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_handleMessage).call(this, event);
|
|
7648
|
+
__classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_handleMessage).call(this, event);
|
|
7465
7649
|
break;
|
|
7466
7650
|
case 'error':
|
|
7467
7651
|
//This is included for completeness, but errors are processed in the SSE event processing so this should not occur
|
|
@@ -7471,13 +7655,13 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7471
7655
|
if (this.ended) {
|
|
7472
7656
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
7473
7657
|
}
|
|
7474
|
-
if (!__classPrivateFieldGet(this, _AssistantStream_finalRun, "f"))
|
|
7658
|
+
if (!__classPrivateFieldGet$1(this, _AssistantStream_finalRun, "f"))
|
|
7475
7659
|
throw Error('Final run has not been received');
|
|
7476
|
-
return __classPrivateFieldGet(this, _AssistantStream_finalRun, "f");
|
|
7660
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_finalRun, "f");
|
|
7477
7661
|
}, _AssistantStream_handleMessage = function _AssistantStream_handleMessage(event) {
|
|
7478
|
-
const [accumulatedMessage, newContent] = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateMessage).call(this, event, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"));
|
|
7479
|
-
__classPrivateFieldSet(this, _AssistantStream_messageSnapshot, accumulatedMessage, "f");
|
|
7480
|
-
__classPrivateFieldGet(this, _AssistantStream_messageSnapshots, "f")[accumulatedMessage.id] = accumulatedMessage;
|
|
7662
|
+
const [accumulatedMessage, newContent] = __classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_accumulateMessage).call(this, event, __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f"));
|
|
7663
|
+
__classPrivateFieldSet$1(this, _AssistantStream_messageSnapshot, accumulatedMessage, "f");
|
|
7664
|
+
__classPrivateFieldGet$1(this, _AssistantStream_messageSnapshots, "f")[accumulatedMessage.id] = accumulatedMessage;
|
|
7481
7665
|
for (const content of newContent) {
|
|
7482
7666
|
const snapshotContent = accumulatedMessage.content[content.index];
|
|
7483
7667
|
if (snapshotContent?.type == 'text') {
|
|
@@ -7505,48 +7689,48 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7505
7689
|
throw Error('The snapshot associated with this text delta is not text or missing');
|
|
7506
7690
|
}
|
|
7507
7691
|
}
|
|
7508
|
-
if (content.index != __classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f")) {
|
|
7692
|
+
if (content.index != __classPrivateFieldGet$1(this, _AssistantStream_currentContentIndex, "f")) {
|
|
7509
7693
|
//See if we have in progress content
|
|
7510
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentContent, "f")) {
|
|
7511
|
-
switch (__classPrivateFieldGet(this, _AssistantStream_currentContent, "f").type) {
|
|
7694
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentContent, "f")) {
|
|
7695
|
+
switch (__classPrivateFieldGet$1(this, _AssistantStream_currentContent, "f").type) {
|
|
7512
7696
|
case 'text':
|
|
7513
|
-
this._emit('textDone', __classPrivateFieldGet(this, _AssistantStream_currentContent, "f").text, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"));
|
|
7697
|
+
this._emit('textDone', __classPrivateFieldGet$1(this, _AssistantStream_currentContent, "f").text, __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f"));
|
|
7514
7698
|
break;
|
|
7515
7699
|
case 'image_file':
|
|
7516
|
-
this._emit('imageFileDone', __classPrivateFieldGet(this, _AssistantStream_currentContent, "f").image_file, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"));
|
|
7700
|
+
this._emit('imageFileDone', __classPrivateFieldGet$1(this, _AssistantStream_currentContent, "f").image_file, __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f"));
|
|
7517
7701
|
break;
|
|
7518
7702
|
}
|
|
7519
7703
|
}
|
|
7520
|
-
__classPrivateFieldSet(this, _AssistantStream_currentContentIndex, content.index, "f");
|
|
7704
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentContentIndex, content.index, "f");
|
|
7521
7705
|
}
|
|
7522
|
-
__classPrivateFieldSet(this, _AssistantStream_currentContent, accumulatedMessage.content[content.index], "f");
|
|
7706
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentContent, accumulatedMessage.content[content.index], "f");
|
|
7523
7707
|
}
|
|
7524
7708
|
}
|
|
7525
7709
|
break;
|
|
7526
7710
|
case 'thread.message.completed':
|
|
7527
7711
|
case 'thread.message.incomplete':
|
|
7528
7712
|
//We emit the latest content we were working on on completion (including incomplete)
|
|
7529
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f") !== undefined) {
|
|
7530
|
-
const currentContent = event.data.content[__classPrivateFieldGet(this, _AssistantStream_currentContentIndex, "f")];
|
|
7713
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentContentIndex, "f") !== undefined) {
|
|
7714
|
+
const currentContent = event.data.content[__classPrivateFieldGet$1(this, _AssistantStream_currentContentIndex, "f")];
|
|
7531
7715
|
if (currentContent) {
|
|
7532
7716
|
switch (currentContent.type) {
|
|
7533
7717
|
case 'image_file':
|
|
7534
|
-
this._emit('imageFileDone', currentContent.image_file, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"));
|
|
7718
|
+
this._emit('imageFileDone', currentContent.image_file, __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f"));
|
|
7535
7719
|
break;
|
|
7536
7720
|
case 'text':
|
|
7537
|
-
this._emit('textDone', currentContent.text, __classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f"));
|
|
7721
|
+
this._emit('textDone', currentContent.text, __classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f"));
|
|
7538
7722
|
break;
|
|
7539
7723
|
}
|
|
7540
7724
|
}
|
|
7541
7725
|
}
|
|
7542
|
-
if (__classPrivateFieldGet(this, _AssistantStream_messageSnapshot, "f")) {
|
|
7726
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_messageSnapshot, "f")) {
|
|
7543
7727
|
this._emit('messageDone', event.data);
|
|
7544
7728
|
}
|
|
7545
|
-
__classPrivateFieldSet(this, _AssistantStream_messageSnapshot, undefined, "f");
|
|
7729
|
+
__classPrivateFieldSet$1(this, _AssistantStream_messageSnapshot, undefined, "f");
|
|
7546
7730
|
}
|
|
7547
7731
|
}, _AssistantStream_handleRunStep = function _AssistantStream_handleRunStep(event) {
|
|
7548
|
-
const accumulatedRunStep = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateRunStep).call(this, event);
|
|
7549
|
-
__classPrivateFieldSet(this, _AssistantStream_currentRunStepSnapshot, accumulatedRunStep, "f");
|
|
7732
|
+
const accumulatedRunStep = __classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_accumulateRunStep).call(this, event);
|
|
7733
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentRunStepSnapshot, accumulatedRunStep, "f");
|
|
7550
7734
|
switch (event.event) {
|
|
7551
7735
|
case 'thread.run.step.created':
|
|
7552
7736
|
this._emit('runStepCreated', event.data);
|
|
@@ -7558,17 +7742,17 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7558
7742
|
delta.step_details.tool_calls &&
|
|
7559
7743
|
accumulatedRunStep.step_details.type == 'tool_calls') {
|
|
7560
7744
|
for (const toolCall of delta.step_details.tool_calls) {
|
|
7561
|
-
if (toolCall.index == __classPrivateFieldGet(this, _AssistantStream_currentToolCallIndex, "f")) {
|
|
7745
|
+
if (toolCall.index == __classPrivateFieldGet$1(this, _AssistantStream_currentToolCallIndex, "f")) {
|
|
7562
7746
|
this._emit('toolCallDelta', toolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index]);
|
|
7563
7747
|
}
|
|
7564
7748
|
else {
|
|
7565
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) {
|
|
7566
|
-
this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f"));
|
|
7749
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f")) {
|
|
7750
|
+
this._emit('toolCallDone', __classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f"));
|
|
7567
7751
|
}
|
|
7568
|
-
__classPrivateFieldSet(this, _AssistantStream_currentToolCallIndex, toolCall.index, "f");
|
|
7569
|
-
__classPrivateFieldSet(this, _AssistantStream_currentToolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index], "f");
|
|
7570
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f"))
|
|
7571
|
-
this._emit('toolCallCreated', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f"));
|
|
7752
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentToolCallIndex, toolCall.index, "f");
|
|
7753
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentToolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index], "f");
|
|
7754
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f"))
|
|
7755
|
+
this._emit('toolCallCreated', __classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f"));
|
|
7572
7756
|
}
|
|
7573
7757
|
}
|
|
7574
7758
|
}
|
|
@@ -7578,46 +7762,46 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7578
7762
|
case 'thread.run.step.failed':
|
|
7579
7763
|
case 'thread.run.step.cancelled':
|
|
7580
7764
|
case 'thread.run.step.expired':
|
|
7581
|
-
__classPrivateFieldSet(this, _AssistantStream_currentRunStepSnapshot, undefined, "f");
|
|
7765
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentRunStepSnapshot, undefined, "f");
|
|
7582
7766
|
const details = event.data.step_details;
|
|
7583
7767
|
if (details.type == 'tool_calls') {
|
|
7584
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) {
|
|
7585
|
-
this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f"));
|
|
7586
|
-
__classPrivateFieldSet(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
7768
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f")) {
|
|
7769
|
+
this._emit('toolCallDone', __classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f"));
|
|
7770
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
7587
7771
|
}
|
|
7588
7772
|
}
|
|
7589
7773
|
this._emit('runStepDone', event.data, accumulatedRunStep);
|
|
7590
7774
|
break;
|
|
7591
7775
|
}
|
|
7592
7776
|
}, _AssistantStream_handleEvent = function _AssistantStream_handleEvent(event) {
|
|
7593
|
-
__classPrivateFieldGet(this, _AssistantStream_events, "f").push(event);
|
|
7777
|
+
__classPrivateFieldGet$1(this, _AssistantStream_events, "f").push(event);
|
|
7594
7778
|
this._emit('event', event);
|
|
7595
7779
|
}, _AssistantStream_accumulateRunStep = function _AssistantStream_accumulateRunStep(event) {
|
|
7596
7780
|
switch (event.event) {
|
|
7597
7781
|
case 'thread.run.step.created':
|
|
7598
|
-
__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
7782
|
+
__classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
7599
7783
|
return event.data;
|
|
7600
7784
|
case 'thread.run.step.delta':
|
|
7601
|
-
let snapshot = __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7785
|
+
let snapshot = __classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7602
7786
|
if (!snapshot) {
|
|
7603
7787
|
throw Error('Received a RunStepDelta before creation of a snapshot');
|
|
7604
7788
|
}
|
|
7605
7789
|
let data = event.data;
|
|
7606
7790
|
if (data.delta) {
|
|
7607
7791
|
const accumulated = AssistantStream.accumulateDelta(snapshot, data.delta);
|
|
7608
|
-
__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = accumulated;
|
|
7792
|
+
__classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = accumulated;
|
|
7609
7793
|
}
|
|
7610
|
-
return __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7794
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7611
7795
|
case 'thread.run.step.completed':
|
|
7612
7796
|
case 'thread.run.step.failed':
|
|
7613
7797
|
case 'thread.run.step.cancelled':
|
|
7614
7798
|
case 'thread.run.step.expired':
|
|
7615
7799
|
case 'thread.run.step.in_progress':
|
|
7616
|
-
__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
7800
|
+
__classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
7617
7801
|
break;
|
|
7618
7802
|
}
|
|
7619
|
-
if (__classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id])
|
|
7620
|
-
return __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7803
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id])
|
|
7804
|
+
return __classPrivateFieldGet$1(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
7621
7805
|
throw new Error('No snapshot available');
|
|
7622
7806
|
}, _AssistantStream_accumulateMessage = function _AssistantStream_accumulateMessage(event, snapshot) {
|
|
7623
7807
|
let newContent = [];
|
|
@@ -7635,7 +7819,7 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7635
7819
|
for (const contentElement of data.delta.content) {
|
|
7636
7820
|
if (contentElement.index in snapshot.content) {
|
|
7637
7821
|
let currentContent = snapshot.content[contentElement.index];
|
|
7638
|
-
snapshot.content[contentElement.index] = __classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_accumulateContent).call(this, contentElement, currentContent);
|
|
7822
|
+
snapshot.content[contentElement.index] = __classPrivateFieldGet$1(this, _AssistantStream_instances, "m", _AssistantStream_accumulateContent).call(this, contentElement, currentContent);
|
|
7639
7823
|
}
|
|
7640
7824
|
else {
|
|
7641
7825
|
snapshot.content[contentElement.index] = contentElement;
|
|
@@ -7660,7 +7844,7 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7660
7844
|
}, _AssistantStream_accumulateContent = function _AssistantStream_accumulateContent(contentElement, currentContent) {
|
|
7661
7845
|
return AssistantStream.accumulateDelta(currentContent, contentElement);
|
|
7662
7846
|
}, _AssistantStream_handleRun = function _AssistantStream_handleRun(event) {
|
|
7663
|
-
__classPrivateFieldSet(this, _AssistantStream_currentRunSnapshot, event.data, "f");
|
|
7847
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentRunSnapshot, event.data, "f");
|
|
7664
7848
|
switch (event.event) {
|
|
7665
7849
|
case 'thread.run.created':
|
|
7666
7850
|
break;
|
|
@@ -7673,10 +7857,10 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
|
|
|
7673
7857
|
case 'thread.run.failed':
|
|
7674
7858
|
case 'thread.run.completed':
|
|
7675
7859
|
case 'thread.run.expired':
|
|
7676
|
-
__classPrivateFieldSet(this, _AssistantStream_finalRun, event.data, "f");
|
|
7677
|
-
if (__classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f")) {
|
|
7678
|
-
this._emit('toolCallDone', __classPrivateFieldGet(this, _AssistantStream_currentToolCall, "f"));
|
|
7679
|
-
__classPrivateFieldSet(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
7860
|
+
__classPrivateFieldSet$1(this, _AssistantStream_finalRun, event.data, "f");
|
|
7861
|
+
if (__classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f")) {
|
|
7862
|
+
this._emit('toolCallDone', __classPrivateFieldGet$1(this, _AssistantStream_currentToolCall, "f"));
|
|
7863
|
+
__classPrivateFieldSet$1(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
7680
7864
|
}
|
|
7681
7865
|
break;
|
|
7682
7866
|
}
|
|
@@ -7993,144 +8177,921 @@ Threads.RunsPage = RunsPage;
|
|
|
7993
8177
|
Threads.Messages = Messages;
|
|
7994
8178
|
Threads.MessagesPage = MessagesPage;
|
|
7995
8179
|
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
console.error(result.reason);
|
|
8005
|
-
}
|
|
8006
|
-
throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
|
|
8180
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8181
|
+
class Beta extends APIResource {
|
|
8182
|
+
constructor() {
|
|
8183
|
+
super(...arguments);
|
|
8184
|
+
this.realtime = new Realtime(this._client);
|
|
8185
|
+
this.chat = new Chat(this._client);
|
|
8186
|
+
this.assistants = new Assistants(this._client);
|
|
8187
|
+
this.threads = new Threads(this._client);
|
|
8007
8188
|
}
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8189
|
+
}
|
|
8190
|
+
Beta.Realtime = Realtime;
|
|
8191
|
+
Beta.Assistants = Assistants;
|
|
8192
|
+
Beta.AssistantsPage = AssistantsPage;
|
|
8193
|
+
Beta.Threads = Threads;
|
|
8194
|
+
|
|
8195
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8196
|
+
class Completions extends APIResource {
|
|
8197
|
+
create(body, options) {
|
|
8198
|
+
return this._client.post('/completions', { body, ...options, stream: body.stream ?? false });
|
|
8014
8199
|
}
|
|
8015
|
-
|
|
8016
|
-
|
|
8200
|
+
}
|
|
8201
|
+
|
|
8202
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8203
|
+
class Embeddings extends APIResource {
|
|
8204
|
+
/**
|
|
8205
|
+
* Creates an embedding vector representing the input text.
|
|
8206
|
+
*/
|
|
8207
|
+
create(body, options) {
|
|
8208
|
+
return this._client.post('/embeddings', { body, ...options });
|
|
8209
|
+
}
|
|
8210
|
+
}
|
|
8017
8211
|
|
|
8018
8212
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8019
8213
|
let Files$1 = class Files extends APIResource {
|
|
8020
8214
|
/**
|
|
8021
|
-
*
|
|
8022
|
-
*
|
|
8023
|
-
*
|
|
8215
|
+
* Upload a file that can be used across various endpoints. Individual files can be
|
|
8216
|
+
* up to 512 MB, and the size of all files uploaded by one organization can be up
|
|
8217
|
+
* to 100 GB.
|
|
8218
|
+
*
|
|
8219
|
+
* The Assistants API supports files up to 2 million tokens and of specific file
|
|
8220
|
+
* types. See the
|
|
8221
|
+
* [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for
|
|
8222
|
+
* details.
|
|
8223
|
+
*
|
|
8224
|
+
* The Fine-tuning API only supports `.jsonl` files. The input also has certain
|
|
8225
|
+
* required formats for fine-tuning
|
|
8226
|
+
* [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
|
|
8227
|
+
* [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
|
|
8228
|
+
* models.
|
|
8229
|
+
*
|
|
8230
|
+
* The Batch API only supports `.jsonl` files up to 200 MB in size. The input also
|
|
8231
|
+
* has a specific required
|
|
8232
|
+
* [format](https://platform.openai.com/docs/api-reference/batch/request-input).
|
|
8233
|
+
*
|
|
8234
|
+
* Please [contact us](https://help.openai.com/) if you need to increase these
|
|
8235
|
+
* storage limits.
|
|
8024
8236
|
*/
|
|
8025
|
-
create(
|
|
8026
|
-
return this._client.post(
|
|
8027
|
-
body,
|
|
8028
|
-
...options,
|
|
8029
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8030
|
-
});
|
|
8237
|
+
create(body, options) {
|
|
8238
|
+
return this._client.post('/files', multipartFormRequestOptions({ body, ...options }));
|
|
8031
8239
|
}
|
|
8032
8240
|
/**
|
|
8033
|
-
*
|
|
8241
|
+
* Returns information about a specific file.
|
|
8034
8242
|
*/
|
|
8035
|
-
retrieve(
|
|
8036
|
-
return this._client.get(`/
|
|
8037
|
-
...options,
|
|
8038
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8039
|
-
});
|
|
8243
|
+
retrieve(fileId, options) {
|
|
8244
|
+
return this._client.get(`/files/${fileId}`, options);
|
|
8040
8245
|
}
|
|
8041
|
-
list(
|
|
8246
|
+
list(query = {}, options) {
|
|
8042
8247
|
if (isRequestOptions(query)) {
|
|
8043
|
-
return this.list(
|
|
8248
|
+
return this.list({}, query);
|
|
8044
8249
|
}
|
|
8045
|
-
return this._client.getAPIList(
|
|
8046
|
-
query,
|
|
8047
|
-
...options,
|
|
8048
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8049
|
-
});
|
|
8250
|
+
return this._client.getAPIList('/files', FileObjectsPage, { query, ...options });
|
|
8050
8251
|
}
|
|
8051
8252
|
/**
|
|
8052
|
-
* Delete a
|
|
8053
|
-
* the file itself will not be deleted. To delete the file, use the
|
|
8054
|
-
* [delete file](https://platform.openai.com/docs/api-reference/files/delete)
|
|
8055
|
-
* endpoint.
|
|
8253
|
+
* Delete a file.
|
|
8056
8254
|
*/
|
|
8057
|
-
del(
|
|
8058
|
-
return this._client.delete(`/
|
|
8255
|
+
del(fileId, options) {
|
|
8256
|
+
return this._client.delete(`/files/${fileId}`, options);
|
|
8257
|
+
}
|
|
8258
|
+
/**
|
|
8259
|
+
* Returns the contents of the specified file.
|
|
8260
|
+
*/
|
|
8261
|
+
content(fileId, options) {
|
|
8262
|
+
return this._client.get(`/files/${fileId}/content`, {
|
|
8059
8263
|
...options,
|
|
8060
|
-
headers: {
|
|
8264
|
+
headers: { Accept: 'application/binary', ...options?.headers },
|
|
8265
|
+
__binaryResponse: true,
|
|
8061
8266
|
});
|
|
8062
8267
|
}
|
|
8063
8268
|
/**
|
|
8064
|
-
*
|
|
8269
|
+
* Returns the contents of the specified file.
|
|
8270
|
+
*
|
|
8271
|
+
* @deprecated The `.content()` method should be used instead
|
|
8065
8272
|
*/
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
return await this.poll(vectorStoreId, file.id, options);
|
|
8273
|
+
retrieveContent(fileId, options) {
|
|
8274
|
+
return this._client.get(`/files/${fileId}/content`, options);
|
|
8069
8275
|
}
|
|
8070
8276
|
/**
|
|
8071
|
-
*
|
|
8072
|
-
*
|
|
8073
|
-
* Note: this will return even if the file failed to process, you need to check
|
|
8074
|
-
* file.last_error and file.status to handle these cases
|
|
8277
|
+
* Waits for the given file to be processed, default timeout is 30 mins.
|
|
8075
8278
|
*/
|
|
8076
|
-
async
|
|
8077
|
-
const
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
switch (file.status) {
|
|
8088
|
-
case 'in_progress':
|
|
8089
|
-
let sleepInterval = 5000;
|
|
8090
|
-
if (options?.pollIntervalMs) {
|
|
8091
|
-
sleepInterval = options.pollIntervalMs;
|
|
8092
|
-
}
|
|
8093
|
-
else {
|
|
8094
|
-
const headerInterval = fileResponse.response.headers.get('openai-poll-after-ms');
|
|
8095
|
-
if (headerInterval) {
|
|
8096
|
-
const headerIntervalMs = parseInt(headerInterval);
|
|
8097
|
-
if (!isNaN(headerIntervalMs)) {
|
|
8098
|
-
sleepInterval = headerIntervalMs;
|
|
8099
|
-
}
|
|
8100
|
-
}
|
|
8101
|
-
}
|
|
8102
|
-
await sleep(sleepInterval);
|
|
8103
|
-
break;
|
|
8104
|
-
case 'failed':
|
|
8105
|
-
case 'completed':
|
|
8106
|
-
return file;
|
|
8279
|
+
async waitForProcessing(id, { pollInterval = 5000, maxWait = 30 * 60 * 1000 } = {}) {
|
|
8280
|
+
const TERMINAL_STATES = new Set(['processed', 'error', 'deleted']);
|
|
8281
|
+
const start = Date.now();
|
|
8282
|
+
let file = await this.retrieve(id);
|
|
8283
|
+
while (!file.status || !TERMINAL_STATES.has(file.status)) {
|
|
8284
|
+
await sleep(pollInterval);
|
|
8285
|
+
file = await this.retrieve(id);
|
|
8286
|
+
if (Date.now() - start > maxWait) {
|
|
8287
|
+
throw new APIConnectionTimeoutError({
|
|
8288
|
+
message: `Giving up on waiting for file ${id} to finish processing after ${maxWait} milliseconds.`,
|
|
8289
|
+
});
|
|
8107
8290
|
}
|
|
8108
8291
|
}
|
|
8292
|
+
return file;
|
|
8293
|
+
}
|
|
8294
|
+
};
|
|
8295
|
+
class FileObjectsPage extends CursorPage {
|
|
8296
|
+
}
|
|
8297
|
+
Files$1.FileObjectsPage = FileObjectsPage;
|
|
8298
|
+
|
|
8299
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8300
|
+
class Checkpoints extends APIResource {
|
|
8301
|
+
list(fineTuningJobId, query = {}, options) {
|
|
8302
|
+
if (isRequestOptions(query)) {
|
|
8303
|
+
return this.list(fineTuningJobId, {}, query);
|
|
8304
|
+
}
|
|
8305
|
+
return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/checkpoints`, FineTuningJobCheckpointsPage, { query, ...options });
|
|
8306
|
+
}
|
|
8307
|
+
}
|
|
8308
|
+
class FineTuningJobCheckpointsPage extends CursorPage {
|
|
8309
|
+
}
|
|
8310
|
+
Checkpoints.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage;
|
|
8311
|
+
|
|
8312
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8313
|
+
class Jobs extends APIResource {
|
|
8314
|
+
constructor() {
|
|
8315
|
+
super(...arguments);
|
|
8316
|
+
this.checkpoints = new Checkpoints(this._client);
|
|
8109
8317
|
}
|
|
8110
8318
|
/**
|
|
8111
|
-
*
|
|
8319
|
+
* Creates a fine-tuning job which begins the process of creating a new model from
|
|
8320
|
+
* a given dataset.
|
|
8112
8321
|
*
|
|
8113
|
-
*
|
|
8114
|
-
*
|
|
8322
|
+
* Response includes details of the enqueued job including job status and the name
|
|
8323
|
+
* of the fine-tuned models once complete.
|
|
8324
|
+
*
|
|
8325
|
+
* [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
|
|
8115
8326
|
*/
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
return this.create(vectorStoreId, { file_id: fileInfo.id }, options);
|
|
8327
|
+
create(body, options) {
|
|
8328
|
+
return this._client.post('/fine_tuning/jobs', { body, ...options });
|
|
8119
8329
|
}
|
|
8120
8330
|
/**
|
|
8121
|
-
*
|
|
8331
|
+
* Get info about a fine-tuning job.
|
|
8332
|
+
*
|
|
8333
|
+
* [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
|
|
8122
8334
|
*/
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
return await this.poll(vectorStoreId, fileInfo.id, options);
|
|
8335
|
+
retrieve(fineTuningJobId, options) {
|
|
8336
|
+
return this._client.get(`/fine_tuning/jobs/${fineTuningJobId}`, options);
|
|
8126
8337
|
}
|
|
8127
|
-
}
|
|
8128
|
-
|
|
8129
|
-
}
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8338
|
+
list(query = {}, options) {
|
|
8339
|
+
if (isRequestOptions(query)) {
|
|
8340
|
+
return this.list({}, query);
|
|
8341
|
+
}
|
|
8342
|
+
return this._client.getAPIList('/fine_tuning/jobs', FineTuningJobsPage, { query, ...options });
|
|
8343
|
+
}
|
|
8344
|
+
/**
|
|
8345
|
+
* Immediately cancel a fine-tune job.
|
|
8346
|
+
*/
|
|
8347
|
+
cancel(fineTuningJobId, options) {
|
|
8348
|
+
return this._client.post(`/fine_tuning/jobs/${fineTuningJobId}/cancel`, options);
|
|
8349
|
+
}
|
|
8350
|
+
listEvents(fineTuningJobId, query = {}, options) {
|
|
8351
|
+
if (isRequestOptions(query)) {
|
|
8352
|
+
return this.listEvents(fineTuningJobId, {}, query);
|
|
8353
|
+
}
|
|
8354
|
+
return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/events`, FineTuningJobEventsPage, {
|
|
8355
|
+
query,
|
|
8356
|
+
...options,
|
|
8357
|
+
});
|
|
8358
|
+
}
|
|
8359
|
+
}
|
|
8360
|
+
class FineTuningJobsPage extends CursorPage {
|
|
8361
|
+
}
|
|
8362
|
+
class FineTuningJobEventsPage extends CursorPage {
|
|
8363
|
+
}
|
|
8364
|
+
Jobs.FineTuningJobsPage = FineTuningJobsPage;
|
|
8365
|
+
Jobs.FineTuningJobEventsPage = FineTuningJobEventsPage;
|
|
8366
|
+
Jobs.Checkpoints = Checkpoints;
|
|
8367
|
+
Jobs.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage;
|
|
8368
|
+
|
|
8369
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8370
|
+
class FineTuning extends APIResource {
|
|
8371
|
+
constructor() {
|
|
8372
|
+
super(...arguments);
|
|
8373
|
+
this.jobs = new Jobs(this._client);
|
|
8374
|
+
}
|
|
8375
|
+
}
|
|
8376
|
+
FineTuning.Jobs = Jobs;
|
|
8377
|
+
FineTuning.FineTuningJobsPage = FineTuningJobsPage;
|
|
8378
|
+
FineTuning.FineTuningJobEventsPage = FineTuningJobEventsPage;
|
|
8379
|
+
|
|
8380
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8381
|
+
class Images extends APIResource {
|
|
8382
|
+
/**
|
|
8383
|
+
* Creates a variation of a given image.
|
|
8384
|
+
*/
|
|
8385
|
+
createVariation(body, options) {
|
|
8386
|
+
return this._client.post('/images/variations', multipartFormRequestOptions({ body, ...options }));
|
|
8387
|
+
}
|
|
8388
|
+
/**
|
|
8389
|
+
* Creates an edited or extended image given an original image and a prompt.
|
|
8390
|
+
*/
|
|
8391
|
+
edit(body, options) {
|
|
8392
|
+
return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options }));
|
|
8393
|
+
}
|
|
8394
|
+
/**
|
|
8395
|
+
* Creates an image given a prompt.
|
|
8396
|
+
*/
|
|
8397
|
+
generate(body, options) {
|
|
8398
|
+
return this._client.post('/images/generations', { body, ...options });
|
|
8399
|
+
}
|
|
8400
|
+
}
|
|
8401
|
+
|
|
8402
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8403
|
+
class Models extends APIResource {
|
|
8404
|
+
/**
|
|
8405
|
+
* Retrieves a model instance, providing basic information about the model such as
|
|
8406
|
+
* the owner and permissioning.
|
|
8407
|
+
*/
|
|
8408
|
+
retrieve(model, options) {
|
|
8409
|
+
return this._client.get(`/models/${model}`, options);
|
|
8410
|
+
}
|
|
8411
|
+
/**
|
|
8412
|
+
* Lists the currently available models, and provides basic information about each
|
|
8413
|
+
* one such as the owner and availability.
|
|
8414
|
+
*/
|
|
8415
|
+
list(options) {
|
|
8416
|
+
return this._client.getAPIList('/models', ModelsPage, options);
|
|
8417
|
+
}
|
|
8418
|
+
/**
|
|
8419
|
+
* Delete a fine-tuned model. You must have the Owner role in your organization to
|
|
8420
|
+
* delete a model.
|
|
8421
|
+
*/
|
|
8422
|
+
del(model, options) {
|
|
8423
|
+
return this._client.delete(`/models/${model}`, options);
|
|
8424
|
+
}
|
|
8425
|
+
}
|
|
8426
|
+
/**
|
|
8427
|
+
* Note: no pagination actually occurs yet, this is for forwards-compatibility.
|
|
8428
|
+
*/
|
|
8429
|
+
class ModelsPage extends Page {
|
|
8430
|
+
}
|
|
8431
|
+
Models.ModelsPage = ModelsPage;
|
|
8432
|
+
|
|
8433
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8434
|
+
class Moderations extends APIResource {
|
|
8435
|
+
/**
|
|
8436
|
+
* Classifies if text and/or image inputs are potentially harmful. Learn more in
|
|
8437
|
+
* the [moderation guide](https://platform.openai.com/docs/guides/moderation).
|
|
8438
|
+
*/
|
|
8439
|
+
create(body, options) {
|
|
8440
|
+
return this._client.post('/moderations', { body, ...options });
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
8443
|
+
|
|
8444
|
+
function maybeParseResponse(response, params) {
|
|
8445
|
+
if (!params || !hasAutoParseableInput(params)) {
|
|
8446
|
+
return {
|
|
8447
|
+
...response,
|
|
8448
|
+
output_parsed: null,
|
|
8449
|
+
output: response.output.map((item) => {
|
|
8450
|
+
if (item.type === 'function_call') {
|
|
8451
|
+
return {
|
|
8452
|
+
...item,
|
|
8453
|
+
parsed_arguments: null,
|
|
8454
|
+
};
|
|
8455
|
+
}
|
|
8456
|
+
if (item.type === 'message') {
|
|
8457
|
+
return {
|
|
8458
|
+
...item,
|
|
8459
|
+
content: item.content.map((content) => ({
|
|
8460
|
+
...content,
|
|
8461
|
+
parsed: null,
|
|
8462
|
+
})),
|
|
8463
|
+
};
|
|
8464
|
+
}
|
|
8465
|
+
else {
|
|
8466
|
+
return item;
|
|
8467
|
+
}
|
|
8468
|
+
}),
|
|
8469
|
+
};
|
|
8470
|
+
}
|
|
8471
|
+
return parseResponse(response, params);
|
|
8472
|
+
}
|
|
8473
|
+
function parseResponse(response, params) {
|
|
8474
|
+
const output = response.output.map((item) => {
|
|
8475
|
+
if (item.type === 'function_call') {
|
|
8476
|
+
return {
|
|
8477
|
+
...item,
|
|
8478
|
+
parsed_arguments: parseToolCall(params, item),
|
|
8479
|
+
};
|
|
8480
|
+
}
|
|
8481
|
+
if (item.type === 'message') {
|
|
8482
|
+
const content = item.content.map((content) => {
|
|
8483
|
+
if (content.type === 'output_text') {
|
|
8484
|
+
return {
|
|
8485
|
+
...content,
|
|
8486
|
+
parsed: parseTextFormat(params, content.text),
|
|
8487
|
+
};
|
|
8488
|
+
}
|
|
8489
|
+
return content;
|
|
8490
|
+
});
|
|
8491
|
+
return {
|
|
8492
|
+
...item,
|
|
8493
|
+
content,
|
|
8494
|
+
};
|
|
8495
|
+
}
|
|
8496
|
+
return item;
|
|
8497
|
+
});
|
|
8498
|
+
const parsed = Object.assign({}, response, { output });
|
|
8499
|
+
if (!Object.getOwnPropertyDescriptor(response, 'output_text')) {
|
|
8500
|
+
addOutputText(parsed);
|
|
8501
|
+
}
|
|
8502
|
+
Object.defineProperty(parsed, 'output_parsed', {
|
|
8503
|
+
enumerable: true,
|
|
8504
|
+
get() {
|
|
8505
|
+
for (const output of parsed.output) {
|
|
8506
|
+
if (output.type !== 'message') {
|
|
8507
|
+
continue;
|
|
8508
|
+
}
|
|
8509
|
+
for (const content of output.content) {
|
|
8510
|
+
if (content.type === 'output_text' && content.parsed !== null) {
|
|
8511
|
+
return content.parsed;
|
|
8512
|
+
}
|
|
8513
|
+
}
|
|
8514
|
+
}
|
|
8515
|
+
return null;
|
|
8516
|
+
},
|
|
8517
|
+
});
|
|
8518
|
+
return parsed;
|
|
8519
|
+
}
|
|
8520
|
+
function parseTextFormat(params, content) {
|
|
8521
|
+
if (params.text?.format?.type !== 'json_schema') {
|
|
8522
|
+
return null;
|
|
8523
|
+
}
|
|
8524
|
+
if ('$parseRaw' in params.text?.format) {
|
|
8525
|
+
const text_format = params.text?.format;
|
|
8526
|
+
return text_format.$parseRaw(content);
|
|
8527
|
+
}
|
|
8528
|
+
return JSON.parse(content);
|
|
8529
|
+
}
|
|
8530
|
+
function hasAutoParseableInput(params) {
|
|
8531
|
+
if (isAutoParsableResponseFormat(params.text?.format)) {
|
|
8532
|
+
return true;
|
|
8533
|
+
}
|
|
8534
|
+
return false;
|
|
8535
|
+
}
|
|
8536
|
+
function isAutoParsableTool(tool) {
|
|
8537
|
+
return tool?.['$brand'] === 'auto-parseable-tool';
|
|
8538
|
+
}
|
|
8539
|
+
function getInputToolByName(input_tools, name) {
|
|
8540
|
+
return input_tools.find((tool) => tool.type === 'function' && tool.name === name);
|
|
8541
|
+
}
|
|
8542
|
+
function parseToolCall(params, toolCall) {
|
|
8543
|
+
const inputTool = getInputToolByName(params.tools ?? [], toolCall.name);
|
|
8544
|
+
return {
|
|
8545
|
+
...toolCall,
|
|
8546
|
+
...toolCall,
|
|
8547
|
+
parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.arguments)
|
|
8548
|
+
: inputTool?.strict ? JSON.parse(toolCall.arguments)
|
|
8549
|
+
: null,
|
|
8550
|
+
};
|
|
8551
|
+
}
|
|
8552
|
+
function addOutputText(rsp) {
|
|
8553
|
+
const texts = [];
|
|
8554
|
+
for (const output of rsp.output) {
|
|
8555
|
+
if (output.type !== 'message') {
|
|
8556
|
+
continue;
|
|
8557
|
+
}
|
|
8558
|
+
for (const content of output.content) {
|
|
8559
|
+
if (content.type === 'output_text') {
|
|
8560
|
+
texts.push(content.text);
|
|
8561
|
+
}
|
|
8562
|
+
}
|
|
8563
|
+
}
|
|
8564
|
+
rsp.output_text = texts.join('');
|
|
8565
|
+
}
|
|
8566
|
+
|
|
8567
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8568
|
+
class InputItems extends APIResource {
|
|
8569
|
+
list(responseId, query = {}, options) {
|
|
8570
|
+
if (isRequestOptions(query)) {
|
|
8571
|
+
return this.list(responseId, {}, query);
|
|
8572
|
+
}
|
|
8573
|
+
return this._client.getAPIList(`/responses/${responseId}/input_items`, ResponseItemListDataPage, {
|
|
8574
|
+
query,
|
|
8575
|
+
...options,
|
|
8576
|
+
});
|
|
8577
|
+
}
|
|
8578
|
+
}
|
|
8579
|
+
class ResponseItemListDataPage extends CursorPage {
|
|
8580
|
+
}
|
|
8581
|
+
InputItems.ResponseItemListDataPage = ResponseItemListDataPage;
|
|
8582
|
+
|
|
8583
|
+
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8584
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8585
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
8586
|
+
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");
|
|
8587
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8588
|
+
};
|
|
8589
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8590
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
8591
|
+
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");
|
|
8592
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
8593
|
+
};
|
|
8594
|
+
var _ResponseStream_instances, _ResponseStream_params, _ResponseStream_currentResponseSnapshot, _ResponseStream_finalResponse, _ResponseStream_beginRequest, _ResponseStream_addEvent, _ResponseStream_endRequest, _ResponseStream_accumulateResponse;
|
|
8595
|
+
class ResponseStream extends EventStream {
|
|
8596
|
+
constructor(params) {
|
|
8597
|
+
super();
|
|
8598
|
+
_ResponseStream_instances.add(this);
|
|
8599
|
+
_ResponseStream_params.set(this, void 0);
|
|
8600
|
+
_ResponseStream_currentResponseSnapshot.set(this, void 0);
|
|
8601
|
+
_ResponseStream_finalResponse.set(this, void 0);
|
|
8602
|
+
__classPrivateFieldSet(this, _ResponseStream_params, params, "f");
|
|
8603
|
+
}
|
|
8604
|
+
static createResponse(client, params, options) {
|
|
8605
|
+
const runner = new ResponseStream(params);
|
|
8606
|
+
runner._run(() => runner._createResponse(client, params, {
|
|
8607
|
+
...options,
|
|
8608
|
+
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },
|
|
8609
|
+
}));
|
|
8610
|
+
return runner;
|
|
8611
|
+
}
|
|
8612
|
+
async _createResponse(client, params, options) {
|
|
8613
|
+
const signal = options?.signal;
|
|
8614
|
+
if (signal) {
|
|
8615
|
+
if (signal.aborted)
|
|
8616
|
+
this.controller.abort();
|
|
8617
|
+
signal.addEventListener('abort', () => this.controller.abort());
|
|
8618
|
+
}
|
|
8619
|
+
__classPrivateFieldGet(this, _ResponseStream_instances, "m", _ResponseStream_beginRequest).call(this);
|
|
8620
|
+
const stream = await client.responses.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
|
|
8621
|
+
this._connected();
|
|
8622
|
+
for await (const event of stream) {
|
|
8623
|
+
__classPrivateFieldGet(this, _ResponseStream_instances, "m", _ResponseStream_addEvent).call(this, event);
|
|
8624
|
+
}
|
|
8625
|
+
if (stream.controller.signal?.aborted) {
|
|
8626
|
+
throw new APIUserAbortError();
|
|
8627
|
+
}
|
|
8628
|
+
return __classPrivateFieldGet(this, _ResponseStream_instances, "m", _ResponseStream_endRequest).call(this);
|
|
8629
|
+
}
|
|
8630
|
+
[(_ResponseStream_params = new WeakMap(), _ResponseStream_currentResponseSnapshot = new WeakMap(), _ResponseStream_finalResponse = new WeakMap(), _ResponseStream_instances = new WeakSet(), _ResponseStream_beginRequest = function _ResponseStream_beginRequest() {
|
|
8631
|
+
if (this.ended)
|
|
8632
|
+
return;
|
|
8633
|
+
__classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, undefined, "f");
|
|
8634
|
+
}, _ResponseStream_addEvent = function _ResponseStream_addEvent(event) {
|
|
8635
|
+
if (this.ended)
|
|
8636
|
+
return;
|
|
8637
|
+
const response = __classPrivateFieldGet(this, _ResponseStream_instances, "m", _ResponseStream_accumulateResponse).call(this, event);
|
|
8638
|
+
this._emit('event', event);
|
|
8639
|
+
switch (event.type) {
|
|
8640
|
+
case 'response.output_text.delta': {
|
|
8641
|
+
const output = response.output[event.output_index];
|
|
8642
|
+
if (!output) {
|
|
8643
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
8644
|
+
}
|
|
8645
|
+
if (output.type === 'message') {
|
|
8646
|
+
const content = output.content[event.content_index];
|
|
8647
|
+
if (!content) {
|
|
8648
|
+
throw new OpenAIError(`missing content at index ${event.content_index}`);
|
|
8649
|
+
}
|
|
8650
|
+
if (content.type !== 'output_text') {
|
|
8651
|
+
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
8652
|
+
}
|
|
8653
|
+
this._emit('response.output_text.delta', {
|
|
8654
|
+
...event,
|
|
8655
|
+
snapshot: content.text,
|
|
8656
|
+
});
|
|
8657
|
+
}
|
|
8658
|
+
break;
|
|
8659
|
+
}
|
|
8660
|
+
case 'response.function_call_arguments.delta': {
|
|
8661
|
+
const output = response.output[event.output_index];
|
|
8662
|
+
if (!output) {
|
|
8663
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
8664
|
+
}
|
|
8665
|
+
if (output.type === 'function_call') {
|
|
8666
|
+
this._emit('response.function_call_arguments.delta', {
|
|
8667
|
+
...event,
|
|
8668
|
+
snapshot: output.arguments,
|
|
8669
|
+
});
|
|
8670
|
+
}
|
|
8671
|
+
break;
|
|
8672
|
+
}
|
|
8673
|
+
default:
|
|
8674
|
+
// @ts-ignore
|
|
8675
|
+
this._emit(event.type, event);
|
|
8676
|
+
break;
|
|
8677
|
+
}
|
|
8678
|
+
}, _ResponseStream_endRequest = function _ResponseStream_endRequest() {
|
|
8679
|
+
if (this.ended) {
|
|
8680
|
+
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
8681
|
+
}
|
|
8682
|
+
const snapshot = __classPrivateFieldGet(this, _ResponseStream_currentResponseSnapshot, "f");
|
|
8683
|
+
if (!snapshot) {
|
|
8684
|
+
throw new OpenAIError(`request ended without sending any events`);
|
|
8685
|
+
}
|
|
8686
|
+
__classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, undefined, "f");
|
|
8687
|
+
const parsedResponse = finalizeResponse(snapshot, __classPrivateFieldGet(this, _ResponseStream_params, "f"));
|
|
8688
|
+
__classPrivateFieldSet(this, _ResponseStream_finalResponse, parsedResponse, "f");
|
|
8689
|
+
return parsedResponse;
|
|
8690
|
+
}, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse(event) {
|
|
8691
|
+
let snapshot = __classPrivateFieldGet(this, _ResponseStream_currentResponseSnapshot, "f");
|
|
8692
|
+
if (!snapshot) {
|
|
8693
|
+
if (event.type !== 'response.created') {
|
|
8694
|
+
throw new OpenAIError(`When snapshot hasn't been set yet, expected 'response.created' event, got ${event.type}`);
|
|
8695
|
+
}
|
|
8696
|
+
snapshot = __classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response, "f");
|
|
8697
|
+
return snapshot;
|
|
8698
|
+
}
|
|
8699
|
+
switch (event.type) {
|
|
8700
|
+
case 'response.output_item.added': {
|
|
8701
|
+
snapshot.output.push(event.item);
|
|
8702
|
+
break;
|
|
8703
|
+
}
|
|
8704
|
+
case 'response.content_part.added': {
|
|
8705
|
+
const output = snapshot.output[event.output_index];
|
|
8706
|
+
if (!output) {
|
|
8707
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
8708
|
+
}
|
|
8709
|
+
if (output.type === 'message') {
|
|
8710
|
+
output.content.push(event.part);
|
|
8711
|
+
}
|
|
8712
|
+
break;
|
|
8713
|
+
}
|
|
8714
|
+
case 'response.output_text.delta': {
|
|
8715
|
+
const output = snapshot.output[event.output_index];
|
|
8716
|
+
if (!output) {
|
|
8717
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
8718
|
+
}
|
|
8719
|
+
if (output.type === 'message') {
|
|
8720
|
+
const content = output.content[event.content_index];
|
|
8721
|
+
if (!content) {
|
|
8722
|
+
throw new OpenAIError(`missing content at index ${event.content_index}`);
|
|
8723
|
+
}
|
|
8724
|
+
if (content.type !== 'output_text') {
|
|
8725
|
+
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
8726
|
+
}
|
|
8727
|
+
content.text += event.delta;
|
|
8728
|
+
}
|
|
8729
|
+
break;
|
|
8730
|
+
}
|
|
8731
|
+
case 'response.function_call_arguments.delta': {
|
|
8732
|
+
const output = snapshot.output[event.output_index];
|
|
8733
|
+
if (!output) {
|
|
8734
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
8735
|
+
}
|
|
8736
|
+
if (output.type === 'function_call') {
|
|
8737
|
+
output.arguments += event.delta;
|
|
8738
|
+
}
|
|
8739
|
+
break;
|
|
8740
|
+
}
|
|
8741
|
+
case 'response.completed': {
|
|
8742
|
+
__classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response, "f");
|
|
8743
|
+
break;
|
|
8744
|
+
}
|
|
8745
|
+
}
|
|
8746
|
+
return snapshot;
|
|
8747
|
+
}, Symbol.asyncIterator)]() {
|
|
8748
|
+
const pushQueue = [];
|
|
8749
|
+
const readQueue = [];
|
|
8750
|
+
let done = false;
|
|
8751
|
+
this.on('event', (event) => {
|
|
8752
|
+
const reader = readQueue.shift();
|
|
8753
|
+
if (reader) {
|
|
8754
|
+
reader.resolve(event);
|
|
8755
|
+
}
|
|
8756
|
+
else {
|
|
8757
|
+
pushQueue.push(event);
|
|
8758
|
+
}
|
|
8759
|
+
});
|
|
8760
|
+
this.on('end', () => {
|
|
8761
|
+
done = true;
|
|
8762
|
+
for (const reader of readQueue) {
|
|
8763
|
+
reader.resolve(undefined);
|
|
8764
|
+
}
|
|
8765
|
+
readQueue.length = 0;
|
|
8766
|
+
});
|
|
8767
|
+
this.on('abort', (err) => {
|
|
8768
|
+
done = true;
|
|
8769
|
+
for (const reader of readQueue) {
|
|
8770
|
+
reader.reject(err);
|
|
8771
|
+
}
|
|
8772
|
+
readQueue.length = 0;
|
|
8773
|
+
});
|
|
8774
|
+
this.on('error', (err) => {
|
|
8775
|
+
done = true;
|
|
8776
|
+
for (const reader of readQueue) {
|
|
8777
|
+
reader.reject(err);
|
|
8778
|
+
}
|
|
8779
|
+
readQueue.length = 0;
|
|
8780
|
+
});
|
|
8781
|
+
return {
|
|
8782
|
+
next: async () => {
|
|
8783
|
+
if (!pushQueue.length) {
|
|
8784
|
+
if (done) {
|
|
8785
|
+
return { value: undefined, done: true };
|
|
8786
|
+
}
|
|
8787
|
+
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((event) => (event ? { value: event, done: false } : { value: undefined, done: true }));
|
|
8788
|
+
}
|
|
8789
|
+
const event = pushQueue.shift();
|
|
8790
|
+
return { value: event, done: false };
|
|
8791
|
+
},
|
|
8792
|
+
return: async () => {
|
|
8793
|
+
this.abort();
|
|
8794
|
+
return { value: undefined, done: true };
|
|
8795
|
+
},
|
|
8796
|
+
};
|
|
8797
|
+
}
|
|
8798
|
+
/**
|
|
8799
|
+
* @returns a promise that resolves with the final Response, or rejects
|
|
8800
|
+
* if an error occurred or the stream ended prematurely without producing a REsponse.
|
|
8801
|
+
*/
|
|
8802
|
+
async finalResponse() {
|
|
8803
|
+
await this.done();
|
|
8804
|
+
const response = __classPrivateFieldGet(this, _ResponseStream_finalResponse, "f");
|
|
8805
|
+
if (!response)
|
|
8806
|
+
throw new OpenAIError('stream ended without producing a ChatCompletion');
|
|
8807
|
+
return response;
|
|
8808
|
+
}
|
|
8809
|
+
}
|
|
8810
|
+
function finalizeResponse(snapshot, params) {
|
|
8811
|
+
return maybeParseResponse(snapshot, params);
|
|
8812
|
+
}
|
|
8813
|
+
|
|
8814
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8815
|
+
class Responses extends APIResource {
|
|
8816
|
+
constructor() {
|
|
8817
|
+
super(...arguments);
|
|
8818
|
+
this.inputItems = new InputItems(this._client);
|
|
8819
|
+
}
|
|
8820
|
+
create(body, options) {
|
|
8821
|
+
return this._client.post('/responses', { body, ...options, stream: body.stream ?? false })._thenUnwrap((rsp) => {
|
|
8822
|
+
if ('object' in rsp && rsp.object === 'response') {
|
|
8823
|
+
addOutputText(rsp);
|
|
8824
|
+
}
|
|
8825
|
+
return rsp;
|
|
8826
|
+
});
|
|
8827
|
+
}
|
|
8828
|
+
retrieve(responseId, query = {}, options) {
|
|
8829
|
+
if (isRequestOptions(query)) {
|
|
8830
|
+
return this.retrieve(responseId, {}, query);
|
|
8831
|
+
}
|
|
8832
|
+
return this._client.get(`/responses/${responseId}`, { query, ...options });
|
|
8833
|
+
}
|
|
8834
|
+
/**
|
|
8835
|
+
* Deletes a model response with the given ID.
|
|
8836
|
+
*/
|
|
8837
|
+
del(responseId, options) {
|
|
8838
|
+
return this._client.delete(`/responses/${responseId}`, {
|
|
8839
|
+
...options,
|
|
8840
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
8841
|
+
});
|
|
8842
|
+
}
|
|
8843
|
+
parse(body, options) {
|
|
8844
|
+
return this._client.responses
|
|
8845
|
+
.create(body, options)
|
|
8846
|
+
._thenUnwrap((response) => parseResponse(response, body));
|
|
8847
|
+
}
|
|
8848
|
+
/**
|
|
8849
|
+
* Creates a chat completion stream
|
|
8850
|
+
*/
|
|
8851
|
+
stream(body, options) {
|
|
8852
|
+
return ResponseStream.createResponse(this._client, body, options);
|
|
8853
|
+
}
|
|
8854
|
+
}
|
|
8855
|
+
Responses.InputItems = InputItems;
|
|
8856
|
+
Responses.ResponseItemListDataPage = ResponseItemListDataPage;
|
|
8857
|
+
|
|
8858
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8859
|
+
class Parts extends APIResource {
|
|
8860
|
+
/**
|
|
8861
|
+
* Adds a
|
|
8862
|
+
* [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an
|
|
8863
|
+
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object.
|
|
8864
|
+
* A Part represents a chunk of bytes from the file you are trying to upload.
|
|
8865
|
+
*
|
|
8866
|
+
* Each Part can be at most 64 MB, and you can add Parts until you hit the Upload
|
|
8867
|
+
* maximum of 8 GB.
|
|
8868
|
+
*
|
|
8869
|
+
* It is possible to add multiple Parts in parallel. You can decide the intended
|
|
8870
|
+
* order of the Parts when you
|
|
8871
|
+
* [complete the Upload](https://platform.openai.com/docs/api-reference/uploads/complete).
|
|
8872
|
+
*/
|
|
8873
|
+
create(uploadId, body, options) {
|
|
8874
|
+
return this._client.post(`/uploads/${uploadId}/parts`, multipartFormRequestOptions({ body, ...options }));
|
|
8875
|
+
}
|
|
8876
|
+
}
|
|
8877
|
+
|
|
8878
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8879
|
+
class Uploads extends APIResource {
|
|
8880
|
+
constructor() {
|
|
8881
|
+
super(...arguments);
|
|
8882
|
+
this.parts = new Parts(this._client);
|
|
8883
|
+
}
|
|
8884
|
+
/**
|
|
8885
|
+
* Creates an intermediate
|
|
8886
|
+
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
|
|
8887
|
+
* that you can add
|
|
8888
|
+
* [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
|
|
8889
|
+
* Currently, an Upload can accept at most 8 GB in total and expires after an hour
|
|
8890
|
+
* after you create it.
|
|
8891
|
+
*
|
|
8892
|
+
* Once you complete the Upload, we will create a
|
|
8893
|
+
* [File](https://platform.openai.com/docs/api-reference/files/object) object that
|
|
8894
|
+
* contains all the parts you uploaded. This File is usable in the rest of our
|
|
8895
|
+
* platform as a regular File object.
|
|
8896
|
+
*
|
|
8897
|
+
* For certain `purpose` values, the correct `mime_type` must be specified. Please
|
|
8898
|
+
* refer to documentation for the
|
|
8899
|
+
* [supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).
|
|
8900
|
+
*
|
|
8901
|
+
* For guidance on the proper filename extensions for each purpose, please follow
|
|
8902
|
+
* the documentation on
|
|
8903
|
+
* [creating a File](https://platform.openai.com/docs/api-reference/files/create).
|
|
8904
|
+
*/
|
|
8905
|
+
create(body, options) {
|
|
8906
|
+
return this._client.post('/uploads', { body, ...options });
|
|
8907
|
+
}
|
|
8908
|
+
/**
|
|
8909
|
+
* Cancels the Upload. No Parts may be added after an Upload is cancelled.
|
|
8910
|
+
*/
|
|
8911
|
+
cancel(uploadId, options) {
|
|
8912
|
+
return this._client.post(`/uploads/${uploadId}/cancel`, options);
|
|
8913
|
+
}
|
|
8914
|
+
/**
|
|
8915
|
+
* Completes the
|
|
8916
|
+
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object).
|
|
8917
|
+
*
|
|
8918
|
+
* Within the returned Upload object, there is a nested
|
|
8919
|
+
* [File](https://platform.openai.com/docs/api-reference/files/object) object that
|
|
8920
|
+
* is ready to use in the rest of the platform.
|
|
8921
|
+
*
|
|
8922
|
+
* You can specify the order of the Parts by passing in an ordered list of the Part
|
|
8923
|
+
* IDs.
|
|
8924
|
+
*
|
|
8925
|
+
* The number of bytes uploaded upon completion must match the number of bytes
|
|
8926
|
+
* initially specified when creating the Upload object. No Parts may be added after
|
|
8927
|
+
* an Upload is completed.
|
|
8928
|
+
*/
|
|
8929
|
+
complete(uploadId, body, options) {
|
|
8930
|
+
return this._client.post(`/uploads/${uploadId}/complete`, { body, ...options });
|
|
8931
|
+
}
|
|
8932
|
+
}
|
|
8933
|
+
Uploads.Parts = Parts;
|
|
8934
|
+
|
|
8935
|
+
/**
|
|
8936
|
+
* Like `Promise.allSettled()` but throws an error if any promises are rejected.
|
|
8937
|
+
*/
|
|
8938
|
+
const allSettledWithThrow = async (promises) => {
|
|
8939
|
+
const results = await Promise.allSettled(promises);
|
|
8940
|
+
const rejected = results.filter((result) => result.status === 'rejected');
|
|
8941
|
+
if (rejected.length) {
|
|
8942
|
+
for (const result of rejected) {
|
|
8943
|
+
console.error(result.reason);
|
|
8944
|
+
}
|
|
8945
|
+
throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
|
|
8946
|
+
}
|
|
8947
|
+
// Note: TS was complaining about using `.filter().map()` here for some reason
|
|
8948
|
+
const values = [];
|
|
8949
|
+
for (const result of results) {
|
|
8950
|
+
if (result.status === 'fulfilled') {
|
|
8951
|
+
values.push(result.value);
|
|
8952
|
+
}
|
|
8953
|
+
}
|
|
8954
|
+
return values;
|
|
8955
|
+
};
|
|
8956
|
+
|
|
8957
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8958
|
+
class Files extends APIResource {
|
|
8959
|
+
/**
|
|
8960
|
+
* Create a vector store file by attaching a
|
|
8961
|
+
* [File](https://platform.openai.com/docs/api-reference/files) to a
|
|
8962
|
+
* [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).
|
|
8963
|
+
*/
|
|
8964
|
+
create(vectorStoreId, body, options) {
|
|
8965
|
+
return this._client.post(`/vector_stores/${vectorStoreId}/files`, {
|
|
8966
|
+
body,
|
|
8967
|
+
...options,
|
|
8968
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8969
|
+
});
|
|
8970
|
+
}
|
|
8971
|
+
/**
|
|
8972
|
+
* Retrieves a vector store file.
|
|
8973
|
+
*/
|
|
8974
|
+
retrieve(vectorStoreId, fileId, options) {
|
|
8975
|
+
return this._client.get(`/vector_stores/${vectorStoreId}/files/${fileId}`, {
|
|
8976
|
+
...options,
|
|
8977
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8978
|
+
});
|
|
8979
|
+
}
|
|
8980
|
+
/**
|
|
8981
|
+
* Update attributes on a vector store file.
|
|
8982
|
+
*/
|
|
8983
|
+
update(vectorStoreId, fileId, body, options) {
|
|
8984
|
+
return this._client.post(`/vector_stores/${vectorStoreId}/files/${fileId}`, {
|
|
8985
|
+
body,
|
|
8986
|
+
...options,
|
|
8987
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8988
|
+
});
|
|
8989
|
+
}
|
|
8990
|
+
list(vectorStoreId, query = {}, options) {
|
|
8991
|
+
if (isRequestOptions(query)) {
|
|
8992
|
+
return this.list(vectorStoreId, {}, query);
|
|
8993
|
+
}
|
|
8994
|
+
return this._client.getAPIList(`/vector_stores/${vectorStoreId}/files`, VectorStoreFilesPage, {
|
|
8995
|
+
query,
|
|
8996
|
+
...options,
|
|
8997
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8998
|
+
});
|
|
8999
|
+
}
|
|
9000
|
+
/**
|
|
9001
|
+
* Delete a vector store file. This will remove the file from the vector store but
|
|
9002
|
+
* the file itself will not be deleted. To delete the file, use the
|
|
9003
|
+
* [delete file](https://platform.openai.com/docs/api-reference/files/delete)
|
|
9004
|
+
* endpoint.
|
|
9005
|
+
*/
|
|
9006
|
+
del(vectorStoreId, fileId, options) {
|
|
9007
|
+
return this._client.delete(`/vector_stores/${vectorStoreId}/files/${fileId}`, {
|
|
9008
|
+
...options,
|
|
9009
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9010
|
+
});
|
|
9011
|
+
}
|
|
9012
|
+
/**
|
|
9013
|
+
* Attach a file to the given vector store and wait for it to be processed.
|
|
9014
|
+
*/
|
|
9015
|
+
async createAndPoll(vectorStoreId, body, options) {
|
|
9016
|
+
const file = await this.create(vectorStoreId, body, options);
|
|
9017
|
+
return await this.poll(vectorStoreId, file.id, options);
|
|
9018
|
+
}
|
|
9019
|
+
/**
|
|
9020
|
+
* Wait for the vector store file to finish processing.
|
|
9021
|
+
*
|
|
9022
|
+
* Note: this will return even if the file failed to process, you need to check
|
|
9023
|
+
* file.last_error and file.status to handle these cases
|
|
9024
|
+
*/
|
|
9025
|
+
async poll(vectorStoreId, fileId, options) {
|
|
9026
|
+
const headers = { ...options?.headers, 'X-Stainless-Poll-Helper': 'true' };
|
|
9027
|
+
if (options?.pollIntervalMs) {
|
|
9028
|
+
headers['X-Stainless-Custom-Poll-Interval'] = options.pollIntervalMs.toString();
|
|
9029
|
+
}
|
|
9030
|
+
while (true) {
|
|
9031
|
+
const fileResponse = await this.retrieve(vectorStoreId, fileId, {
|
|
9032
|
+
...options,
|
|
9033
|
+
headers,
|
|
9034
|
+
}).withResponse();
|
|
9035
|
+
const file = fileResponse.data;
|
|
9036
|
+
switch (file.status) {
|
|
9037
|
+
case 'in_progress':
|
|
9038
|
+
let sleepInterval = 5000;
|
|
9039
|
+
if (options?.pollIntervalMs) {
|
|
9040
|
+
sleepInterval = options.pollIntervalMs;
|
|
9041
|
+
}
|
|
9042
|
+
else {
|
|
9043
|
+
const headerInterval = fileResponse.response.headers.get('openai-poll-after-ms');
|
|
9044
|
+
if (headerInterval) {
|
|
9045
|
+
const headerIntervalMs = parseInt(headerInterval);
|
|
9046
|
+
if (!isNaN(headerIntervalMs)) {
|
|
9047
|
+
sleepInterval = headerIntervalMs;
|
|
9048
|
+
}
|
|
9049
|
+
}
|
|
9050
|
+
}
|
|
9051
|
+
await sleep(sleepInterval);
|
|
9052
|
+
break;
|
|
9053
|
+
case 'failed':
|
|
9054
|
+
case 'completed':
|
|
9055
|
+
return file;
|
|
9056
|
+
}
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
9059
|
+
/**
|
|
9060
|
+
* Upload a file to the `files` API and then attach it to the given vector store.
|
|
9061
|
+
*
|
|
9062
|
+
* Note the file will be asynchronously processed (you can use the alternative
|
|
9063
|
+
* polling helper method to wait for processing to complete).
|
|
9064
|
+
*/
|
|
9065
|
+
async upload(vectorStoreId, file, options) {
|
|
9066
|
+
const fileInfo = await this._client.files.create({ file: file, purpose: 'assistants' }, options);
|
|
9067
|
+
return this.create(vectorStoreId, { file_id: fileInfo.id }, options);
|
|
9068
|
+
}
|
|
9069
|
+
/**
|
|
9070
|
+
* Add a file to a vector store and poll until processing is complete.
|
|
9071
|
+
*/
|
|
9072
|
+
async uploadAndPoll(vectorStoreId, file, options) {
|
|
9073
|
+
const fileInfo = await this.upload(vectorStoreId, file, options);
|
|
9074
|
+
return await this.poll(vectorStoreId, fileInfo.id, options);
|
|
9075
|
+
}
|
|
9076
|
+
/**
|
|
9077
|
+
* Retrieve the parsed contents of a vector store file.
|
|
9078
|
+
*/
|
|
9079
|
+
content(vectorStoreId, fileId, options) {
|
|
9080
|
+
return this._client.getAPIList(`/vector_stores/${vectorStoreId}/files/${fileId}/content`, FileContentResponsesPage, { ...options, headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers } });
|
|
9081
|
+
}
|
|
9082
|
+
}
|
|
9083
|
+
class VectorStoreFilesPage extends CursorPage {
|
|
9084
|
+
}
|
|
9085
|
+
/**
|
|
9086
|
+
* Note: no pagination actually occurs yet, this is for forwards-compatibility.
|
|
9087
|
+
*/
|
|
9088
|
+
class FileContentResponsesPage extends Page {
|
|
9089
|
+
}
|
|
9090
|
+
Files.VectorStoreFilesPage = VectorStoreFilesPage;
|
|
9091
|
+
Files.FileContentResponsesPage = FileContentResponsesPage;
|
|
9092
|
+
|
|
9093
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
9094
|
+
class FileBatches extends APIResource {
|
|
8134
9095
|
/**
|
|
8135
9096
|
* Create a vector store file batch.
|
|
8136
9097
|
*/
|
|
@@ -8236,420 +9197,97 @@ class FileBatches extends APIResource {
|
|
|
8236
9197
|
allFileIds.push(fileObj.id);
|
|
8237
9198
|
}
|
|
8238
9199
|
}
|
|
8239
|
-
// Start workers to process results
|
|
8240
|
-
const workers = Array(concurrencyLimit).fill(fileIterator).map(processFiles);
|
|
8241
|
-
// Wait for all processing to complete.
|
|
8242
|
-
await allSettledWithThrow(workers);
|
|
8243
|
-
return await this.createAndPoll(vectorStoreId, {
|
|
8244
|
-
file_ids: allFileIds,
|
|
8245
|
-
});
|
|
8246
|
-
}
|
|
8247
|
-
}
|
|
8248
|
-
|
|
8249
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8250
|
-
class VectorStores extends APIResource {
|
|
8251
|
-
constructor() {
|
|
8252
|
-
super(...arguments);
|
|
8253
|
-
this.files = new Files$1(this._client);
|
|
8254
|
-
this.fileBatches = new FileBatches(this._client);
|
|
8255
|
-
}
|
|
8256
|
-
/**
|
|
8257
|
-
* Create a vector store.
|
|
8258
|
-
*/
|
|
8259
|
-
create(body, options) {
|
|
8260
|
-
return this._client.post('/vector_stores', {
|
|
8261
|
-
body,
|
|
8262
|
-
...options,
|
|
8263
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8264
|
-
});
|
|
8265
|
-
}
|
|
8266
|
-
/**
|
|
8267
|
-
* Retrieves a vector store.
|
|
8268
|
-
*/
|
|
8269
|
-
retrieve(vectorStoreId, options) {
|
|
8270
|
-
return this._client.get(`/vector_stores/${vectorStoreId}`, {
|
|
8271
|
-
...options,
|
|
8272
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8273
|
-
});
|
|
8274
|
-
}
|
|
8275
|
-
/**
|
|
8276
|
-
* Modifies a vector store.
|
|
8277
|
-
*/
|
|
8278
|
-
update(vectorStoreId, body, options) {
|
|
8279
|
-
return this._client.post(`/vector_stores/${vectorStoreId}`, {
|
|
8280
|
-
body,
|
|
8281
|
-
...options,
|
|
8282
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8283
|
-
});
|
|
8284
|
-
}
|
|
8285
|
-
list(query = {}, options) {
|
|
8286
|
-
if (isRequestOptions(query)) {
|
|
8287
|
-
return this.list({}, query);
|
|
8288
|
-
}
|
|
8289
|
-
return this._client.getAPIList('/vector_stores', VectorStoresPage, {
|
|
8290
|
-
query,
|
|
8291
|
-
...options,
|
|
8292
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8293
|
-
});
|
|
8294
|
-
}
|
|
8295
|
-
/**
|
|
8296
|
-
* Delete a vector store.
|
|
8297
|
-
*/
|
|
8298
|
-
del(vectorStoreId, options) {
|
|
8299
|
-
return this._client.delete(`/vector_stores/${vectorStoreId}`, {
|
|
8300
|
-
...options,
|
|
8301
|
-
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8302
|
-
});
|
|
8303
|
-
}
|
|
8304
|
-
}
|
|
8305
|
-
class VectorStoresPage extends CursorPage {
|
|
8306
|
-
}
|
|
8307
|
-
VectorStores.VectorStoresPage = VectorStoresPage;
|
|
8308
|
-
VectorStores.Files = Files$1;
|
|
8309
|
-
VectorStores.VectorStoreFilesPage = VectorStoreFilesPage;
|
|
8310
|
-
VectorStores.FileBatches = FileBatches;
|
|
8311
|
-
|
|
8312
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8313
|
-
class Beta extends APIResource {
|
|
8314
|
-
constructor() {
|
|
8315
|
-
super(...arguments);
|
|
8316
|
-
this.vectorStores = new VectorStores(this._client);
|
|
8317
|
-
this.chat = new Chat(this._client);
|
|
8318
|
-
this.assistants = new Assistants(this._client);
|
|
8319
|
-
this.threads = new Threads(this._client);
|
|
8320
|
-
}
|
|
8321
|
-
}
|
|
8322
|
-
Beta.VectorStores = VectorStores;
|
|
8323
|
-
Beta.VectorStoresPage = VectorStoresPage;
|
|
8324
|
-
Beta.Assistants = Assistants;
|
|
8325
|
-
Beta.AssistantsPage = AssistantsPage;
|
|
8326
|
-
Beta.Threads = Threads;
|
|
8327
|
-
|
|
8328
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8329
|
-
class Completions extends APIResource {
|
|
8330
|
-
create(body, options) {
|
|
8331
|
-
return this._client.post('/completions', { body, ...options, stream: body.stream ?? false });
|
|
8332
|
-
}
|
|
8333
|
-
}
|
|
8334
|
-
|
|
8335
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8336
|
-
class Embeddings extends APIResource {
|
|
8337
|
-
/**
|
|
8338
|
-
* Creates an embedding vector representing the input text.
|
|
8339
|
-
*/
|
|
8340
|
-
create(body, options) {
|
|
8341
|
-
return this._client.post('/embeddings', { body, ...options });
|
|
8342
|
-
}
|
|
8343
|
-
}
|
|
8344
|
-
|
|
8345
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8346
|
-
class Files extends APIResource {
|
|
8347
|
-
/**
|
|
8348
|
-
* Upload a file that can be used across various endpoints. Individual files can be
|
|
8349
|
-
* up to 512 MB, and the size of all files uploaded by one organization can be up
|
|
8350
|
-
* to 100 GB.
|
|
8351
|
-
*
|
|
8352
|
-
* The Assistants API supports files up to 2 million tokens and of specific file
|
|
8353
|
-
* types. See the
|
|
8354
|
-
* [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for
|
|
8355
|
-
* details.
|
|
8356
|
-
*
|
|
8357
|
-
* The Fine-tuning API only supports `.jsonl` files. The input also has certain
|
|
8358
|
-
* required formats for fine-tuning
|
|
8359
|
-
* [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
|
|
8360
|
-
* [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
|
|
8361
|
-
* models.
|
|
8362
|
-
*
|
|
8363
|
-
* The Batch API only supports `.jsonl` files up to 200 MB in size. The input also
|
|
8364
|
-
* has a specific required
|
|
8365
|
-
* [format](https://platform.openai.com/docs/api-reference/batch/request-input).
|
|
8366
|
-
*
|
|
8367
|
-
* Please [contact us](https://help.openai.com/) if you need to increase these
|
|
8368
|
-
* storage limits.
|
|
8369
|
-
*/
|
|
8370
|
-
create(body, options) {
|
|
8371
|
-
return this._client.post('/files', multipartFormRequestOptions({ body, ...options }));
|
|
8372
|
-
}
|
|
8373
|
-
/**
|
|
8374
|
-
* Returns information about a specific file.
|
|
8375
|
-
*/
|
|
8376
|
-
retrieve(fileId, options) {
|
|
8377
|
-
return this._client.get(`/files/${fileId}`, options);
|
|
8378
|
-
}
|
|
8379
|
-
list(query = {}, options) {
|
|
8380
|
-
if (isRequestOptions(query)) {
|
|
8381
|
-
return this.list({}, query);
|
|
8382
|
-
}
|
|
8383
|
-
return this._client.getAPIList('/files', FileObjectsPage, { query, ...options });
|
|
8384
|
-
}
|
|
8385
|
-
/**
|
|
8386
|
-
* Delete a file.
|
|
8387
|
-
*/
|
|
8388
|
-
del(fileId, options) {
|
|
8389
|
-
return this._client.delete(`/files/${fileId}`, options);
|
|
8390
|
-
}
|
|
8391
|
-
/**
|
|
8392
|
-
* Returns the contents of the specified file.
|
|
8393
|
-
*/
|
|
8394
|
-
content(fileId, options) {
|
|
8395
|
-
return this._client.get(`/files/${fileId}/content`, { ...options, __binaryResponse: true });
|
|
8396
|
-
}
|
|
8397
|
-
/**
|
|
8398
|
-
* Returns the contents of the specified file.
|
|
8399
|
-
*
|
|
8400
|
-
* @deprecated The `.content()` method should be used instead
|
|
8401
|
-
*/
|
|
8402
|
-
retrieveContent(fileId, options) {
|
|
8403
|
-
return this._client.get(`/files/${fileId}/content`, {
|
|
8404
|
-
...options,
|
|
8405
|
-
headers: { Accept: 'application/json', ...options?.headers },
|
|
8406
|
-
});
|
|
8407
|
-
}
|
|
8408
|
-
/**
|
|
8409
|
-
* Waits for the given file to be processed, default timeout is 30 mins.
|
|
8410
|
-
*/
|
|
8411
|
-
async waitForProcessing(id, { pollInterval = 5000, maxWait = 30 * 60 * 1000 } = {}) {
|
|
8412
|
-
const TERMINAL_STATES = new Set(['processed', 'error', 'deleted']);
|
|
8413
|
-
const start = Date.now();
|
|
8414
|
-
let file = await this.retrieve(id);
|
|
8415
|
-
while (!file.status || !TERMINAL_STATES.has(file.status)) {
|
|
8416
|
-
await sleep(pollInterval);
|
|
8417
|
-
file = await this.retrieve(id);
|
|
8418
|
-
if (Date.now() - start > maxWait) {
|
|
8419
|
-
throw new APIConnectionTimeoutError({
|
|
8420
|
-
message: `Giving up on waiting for file ${id} to finish processing after ${maxWait} milliseconds.`,
|
|
8421
|
-
});
|
|
8422
|
-
}
|
|
8423
|
-
}
|
|
8424
|
-
return file;
|
|
8425
|
-
}
|
|
8426
|
-
}
|
|
8427
|
-
class FileObjectsPage extends CursorPage {
|
|
8428
|
-
}
|
|
8429
|
-
Files.FileObjectsPage = FileObjectsPage;
|
|
8430
|
-
|
|
8431
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8432
|
-
class Checkpoints extends APIResource {
|
|
8433
|
-
list(fineTuningJobId, query = {}, options) {
|
|
8434
|
-
if (isRequestOptions(query)) {
|
|
8435
|
-
return this.list(fineTuningJobId, {}, query);
|
|
8436
|
-
}
|
|
8437
|
-
return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/checkpoints`, FineTuningJobCheckpointsPage, { query, ...options });
|
|
9200
|
+
// Start workers to process results
|
|
9201
|
+
const workers = Array(concurrencyLimit).fill(fileIterator).map(processFiles);
|
|
9202
|
+
// Wait for all processing to complete.
|
|
9203
|
+
await allSettledWithThrow(workers);
|
|
9204
|
+
return await this.createAndPoll(vectorStoreId, {
|
|
9205
|
+
file_ids: allFileIds,
|
|
9206
|
+
});
|
|
8438
9207
|
}
|
|
8439
9208
|
}
|
|
8440
|
-
class FineTuningJobCheckpointsPage extends CursorPage {
|
|
8441
|
-
}
|
|
8442
|
-
Checkpoints.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage;
|
|
8443
9209
|
|
|
8444
9210
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8445
|
-
class
|
|
9211
|
+
class VectorStores extends APIResource {
|
|
8446
9212
|
constructor() {
|
|
8447
9213
|
super(...arguments);
|
|
8448
|
-
this.
|
|
9214
|
+
this.files = new Files(this._client);
|
|
9215
|
+
this.fileBatches = new FileBatches(this._client);
|
|
8449
9216
|
}
|
|
8450
9217
|
/**
|
|
8451
|
-
*
|
|
8452
|
-
* a given dataset.
|
|
8453
|
-
*
|
|
8454
|
-
* Response includes details of the enqueued job including job status and the name
|
|
8455
|
-
* of the fine-tuned models once complete.
|
|
8456
|
-
*
|
|
8457
|
-
* [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
|
|
9218
|
+
* Create a vector store.
|
|
8458
9219
|
*/
|
|
8459
9220
|
create(body, options) {
|
|
8460
|
-
return this._client.post('/
|
|
9221
|
+
return this._client.post('/vector_stores', {
|
|
9222
|
+
body,
|
|
9223
|
+
...options,
|
|
9224
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9225
|
+
});
|
|
8461
9226
|
}
|
|
8462
9227
|
/**
|
|
8463
|
-
*
|
|
8464
|
-
*
|
|
8465
|
-
* [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
|
|
9228
|
+
* Retrieves a vector store.
|
|
8466
9229
|
*/
|
|
8467
|
-
retrieve(
|
|
8468
|
-
return this._client.get(`/
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
return this.list({}, query);
|
|
8473
|
-
}
|
|
8474
|
-
return this._client.getAPIList('/fine_tuning/jobs', FineTuningJobsPage, { query, ...options });
|
|
9230
|
+
retrieve(vectorStoreId, options) {
|
|
9231
|
+
return this._client.get(`/vector_stores/${vectorStoreId}`, {
|
|
9232
|
+
...options,
|
|
9233
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9234
|
+
});
|
|
8475
9235
|
}
|
|
8476
9236
|
/**
|
|
8477
|
-
*
|
|
9237
|
+
* Modifies a vector store.
|
|
8478
9238
|
*/
|
|
8479
|
-
|
|
8480
|
-
return this._client.post(`/
|
|
9239
|
+
update(vectorStoreId, body, options) {
|
|
9240
|
+
return this._client.post(`/vector_stores/${vectorStoreId}`, {
|
|
9241
|
+
body,
|
|
9242
|
+
...options,
|
|
9243
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9244
|
+
});
|
|
8481
9245
|
}
|
|
8482
|
-
|
|
9246
|
+
list(query = {}, options) {
|
|
8483
9247
|
if (isRequestOptions(query)) {
|
|
8484
|
-
return this.
|
|
9248
|
+
return this.list({}, query);
|
|
8485
9249
|
}
|
|
8486
|
-
return this._client.getAPIList(
|
|
9250
|
+
return this._client.getAPIList('/vector_stores', VectorStoresPage, {
|
|
8487
9251
|
query,
|
|
8488
9252
|
...options,
|
|
9253
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
8489
9254
|
});
|
|
8490
9255
|
}
|
|
8491
|
-
}
|
|
8492
|
-
class FineTuningJobsPage extends CursorPage {
|
|
8493
|
-
}
|
|
8494
|
-
class FineTuningJobEventsPage extends CursorPage {
|
|
8495
|
-
}
|
|
8496
|
-
Jobs.FineTuningJobsPage = FineTuningJobsPage;
|
|
8497
|
-
Jobs.FineTuningJobEventsPage = FineTuningJobEventsPage;
|
|
8498
|
-
Jobs.Checkpoints = Checkpoints;
|
|
8499
|
-
Jobs.FineTuningJobCheckpointsPage = FineTuningJobCheckpointsPage;
|
|
8500
|
-
|
|
8501
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8502
|
-
class FineTuning extends APIResource {
|
|
8503
|
-
constructor() {
|
|
8504
|
-
super(...arguments);
|
|
8505
|
-
this.jobs = new Jobs(this._client);
|
|
8506
|
-
}
|
|
8507
|
-
}
|
|
8508
|
-
FineTuning.Jobs = Jobs;
|
|
8509
|
-
FineTuning.FineTuningJobsPage = FineTuningJobsPage;
|
|
8510
|
-
FineTuning.FineTuningJobEventsPage = FineTuningJobEventsPage;
|
|
8511
|
-
|
|
8512
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8513
|
-
class Images extends APIResource {
|
|
8514
|
-
/**
|
|
8515
|
-
* Creates a variation of a given image.
|
|
8516
|
-
*/
|
|
8517
|
-
createVariation(body, options) {
|
|
8518
|
-
return this._client.post('/images/variations', multipartFormRequestOptions({ body, ...options }));
|
|
8519
|
-
}
|
|
8520
9256
|
/**
|
|
8521
|
-
*
|
|
9257
|
+
* Delete a vector store.
|
|
8522
9258
|
*/
|
|
8523
|
-
|
|
8524
|
-
return this._client.
|
|
9259
|
+
del(vectorStoreId, options) {
|
|
9260
|
+
return this._client.delete(`/vector_stores/${vectorStoreId}`, {
|
|
9261
|
+
...options,
|
|
9262
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9263
|
+
});
|
|
8525
9264
|
}
|
|
8526
9265
|
/**
|
|
8527
|
-
*
|
|
9266
|
+
* Search a vector store for relevant chunks based on a query and file attributes
|
|
9267
|
+
* filter.
|
|
8528
9268
|
*/
|
|
8529
|
-
|
|
8530
|
-
return this._client.
|
|
9269
|
+
search(vectorStoreId, body, options) {
|
|
9270
|
+
return this._client.getAPIList(`/vector_stores/${vectorStoreId}/search`, VectorStoreSearchResponsesPage, {
|
|
9271
|
+
body,
|
|
9272
|
+
method: 'post',
|
|
9273
|
+
...options,
|
|
9274
|
+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
9275
|
+
});
|
|
8531
9276
|
}
|
|
8532
9277
|
}
|
|
8533
|
-
|
|
8534
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8535
|
-
class Models extends APIResource {
|
|
8536
|
-
/**
|
|
8537
|
-
* Retrieves a model instance, providing basic information about the model such as
|
|
8538
|
-
* the owner and permissioning.
|
|
8539
|
-
*/
|
|
8540
|
-
retrieve(model, options) {
|
|
8541
|
-
return this._client.get(`/models/${model}`, options);
|
|
8542
|
-
}
|
|
8543
|
-
/**
|
|
8544
|
-
* Lists the currently available models, and provides basic information about each
|
|
8545
|
-
* one such as the owner and availability.
|
|
8546
|
-
*/
|
|
8547
|
-
list(options) {
|
|
8548
|
-
return this._client.getAPIList('/models', ModelsPage, options);
|
|
8549
|
-
}
|
|
8550
|
-
/**
|
|
8551
|
-
* Delete a fine-tuned model. You must have the Owner role in your organization to
|
|
8552
|
-
* delete a model.
|
|
8553
|
-
*/
|
|
8554
|
-
del(model, options) {
|
|
8555
|
-
return this._client.delete(`/models/${model}`, options);
|
|
8556
|
-
}
|
|
9278
|
+
class VectorStoresPage extends CursorPage {
|
|
8557
9279
|
}
|
|
8558
9280
|
/**
|
|
8559
9281
|
* Note: no pagination actually occurs yet, this is for forwards-compatibility.
|
|
8560
9282
|
*/
|
|
8561
|
-
class
|
|
8562
|
-
}
|
|
8563
|
-
Models.ModelsPage = ModelsPage;
|
|
8564
|
-
|
|
8565
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8566
|
-
class Moderations extends APIResource {
|
|
8567
|
-
/**
|
|
8568
|
-
* Classifies if text and/or image inputs are potentially harmful. Learn more in
|
|
8569
|
-
* the [moderation guide](https://platform.openai.com/docs/guides/moderation).
|
|
8570
|
-
*/
|
|
8571
|
-
create(body, options) {
|
|
8572
|
-
return this._client.post('/moderations', { body, ...options });
|
|
8573
|
-
}
|
|
8574
|
-
}
|
|
8575
|
-
|
|
8576
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8577
|
-
class Parts extends APIResource {
|
|
8578
|
-
/**
|
|
8579
|
-
* Adds a
|
|
8580
|
-
* [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an
|
|
8581
|
-
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object.
|
|
8582
|
-
* A Part represents a chunk of bytes from the file you are trying to upload.
|
|
8583
|
-
*
|
|
8584
|
-
* Each Part can be at most 64 MB, and you can add Parts until you hit the Upload
|
|
8585
|
-
* maximum of 8 GB.
|
|
8586
|
-
*
|
|
8587
|
-
* It is possible to add multiple Parts in parallel. You can decide the intended
|
|
8588
|
-
* order of the Parts when you
|
|
8589
|
-
* [complete the Upload](https://platform.openai.com/docs/api-reference/uploads/complete).
|
|
8590
|
-
*/
|
|
8591
|
-
create(uploadId, body, options) {
|
|
8592
|
-
return this._client.post(`/uploads/${uploadId}/parts`, multipartFormRequestOptions({ body, ...options }));
|
|
8593
|
-
}
|
|
8594
|
-
}
|
|
8595
|
-
|
|
8596
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8597
|
-
class Uploads extends APIResource {
|
|
8598
|
-
constructor() {
|
|
8599
|
-
super(...arguments);
|
|
8600
|
-
this.parts = new Parts(this._client);
|
|
8601
|
-
}
|
|
8602
|
-
/**
|
|
8603
|
-
* Creates an intermediate
|
|
8604
|
-
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
|
|
8605
|
-
* that you can add
|
|
8606
|
-
* [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
|
|
8607
|
-
* Currently, an Upload can accept at most 8 GB in total and expires after an hour
|
|
8608
|
-
* after you create it.
|
|
8609
|
-
*
|
|
8610
|
-
* Once you complete the Upload, we will create a
|
|
8611
|
-
* [File](https://platform.openai.com/docs/api-reference/files/object) object that
|
|
8612
|
-
* contains all the parts you uploaded. This File is usable in the rest of our
|
|
8613
|
-
* platform as a regular File object.
|
|
8614
|
-
*
|
|
8615
|
-
* For certain `purpose`s, the correct `mime_type` must be specified. Please refer
|
|
8616
|
-
* to documentation for the supported MIME types for your use case:
|
|
8617
|
-
*
|
|
8618
|
-
* - [Assistants](https://platform.openai.com/docs/assistants/tools/file-search#supported-files)
|
|
8619
|
-
*
|
|
8620
|
-
* For guidance on the proper filename extensions for each purpose, please follow
|
|
8621
|
-
* the documentation on
|
|
8622
|
-
* [creating a File](https://platform.openai.com/docs/api-reference/files/create).
|
|
8623
|
-
*/
|
|
8624
|
-
create(body, options) {
|
|
8625
|
-
return this._client.post('/uploads', { body, ...options });
|
|
8626
|
-
}
|
|
8627
|
-
/**
|
|
8628
|
-
* Cancels the Upload. No Parts may be added after an Upload is cancelled.
|
|
8629
|
-
*/
|
|
8630
|
-
cancel(uploadId, options) {
|
|
8631
|
-
return this._client.post(`/uploads/${uploadId}/cancel`, options);
|
|
8632
|
-
}
|
|
8633
|
-
/**
|
|
8634
|
-
* Completes the
|
|
8635
|
-
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object).
|
|
8636
|
-
*
|
|
8637
|
-
* Within the returned Upload object, there is a nested
|
|
8638
|
-
* [File](https://platform.openai.com/docs/api-reference/files/object) object that
|
|
8639
|
-
* is ready to use in the rest of the platform.
|
|
8640
|
-
*
|
|
8641
|
-
* You can specify the order of the Parts by passing in an ordered list of the Part
|
|
8642
|
-
* IDs.
|
|
8643
|
-
*
|
|
8644
|
-
* The number of bytes uploaded upon completion must match the number of bytes
|
|
8645
|
-
* initially specified when creating the Upload object. No Parts may be added after
|
|
8646
|
-
* an Upload is completed.
|
|
8647
|
-
*/
|
|
8648
|
-
complete(uploadId, body, options) {
|
|
8649
|
-
return this._client.post(`/uploads/${uploadId}/complete`, { body, ...options });
|
|
8650
|
-
}
|
|
9283
|
+
class VectorStoreSearchResponsesPage extends Page {
|
|
8651
9284
|
}
|
|
8652
|
-
|
|
9285
|
+
VectorStores.VectorStoresPage = VectorStoresPage;
|
|
9286
|
+
VectorStores.VectorStoreSearchResponsesPage = VectorStoreSearchResponsesPage;
|
|
9287
|
+
VectorStores.Files = Files;
|
|
9288
|
+
VectorStores.VectorStoreFilesPage = VectorStoreFilesPage;
|
|
9289
|
+
VectorStores.FileContentResponsesPage = FileContentResponsesPage;
|
|
9290
|
+
VectorStores.FileBatches = FileBatches;
|
|
8653
9291
|
|
|
8654
9292
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8655
9293
|
var _a;
|
|
@@ -8696,15 +9334,17 @@ class OpenAI extends APIClient {
|
|
|
8696
9334
|
this.completions = new Completions(this);
|
|
8697
9335
|
this.chat = new Chat$1(this);
|
|
8698
9336
|
this.embeddings = new Embeddings(this);
|
|
8699
|
-
this.files = new Files(this);
|
|
9337
|
+
this.files = new Files$1(this);
|
|
8700
9338
|
this.images = new Images(this);
|
|
8701
9339
|
this.audio = new Audio(this);
|
|
8702
9340
|
this.moderations = new Moderations(this);
|
|
8703
9341
|
this.models = new Models(this);
|
|
8704
9342
|
this.fineTuning = new FineTuning(this);
|
|
9343
|
+
this.vectorStores = new VectorStores(this);
|
|
8705
9344
|
this.beta = new Beta(this);
|
|
8706
9345
|
this.batches = new Batches(this);
|
|
8707
9346
|
this.uploads = new Uploads(this);
|
|
9347
|
+
this.responses = new Responses(this);
|
|
8708
9348
|
this._options = options;
|
|
8709
9349
|
this.apiKey = apiKey;
|
|
8710
9350
|
this.organization = organization;
|
|
@@ -8748,8 +9388,9 @@ OpenAI.toFile = toFile;
|
|
|
8748
9388
|
OpenAI.fileFromPath = fileFromPath;
|
|
8749
9389
|
OpenAI.Completions = Completions;
|
|
8750
9390
|
OpenAI.Chat = Chat$1;
|
|
9391
|
+
OpenAI.ChatCompletionsPage = ChatCompletionsPage;
|
|
8751
9392
|
OpenAI.Embeddings = Embeddings;
|
|
8752
|
-
OpenAI.Files = Files;
|
|
9393
|
+
OpenAI.Files = Files$1;
|
|
8753
9394
|
OpenAI.FileObjectsPage = FileObjectsPage;
|
|
8754
9395
|
OpenAI.Images = Images;
|
|
8755
9396
|
OpenAI.Audio = Audio;
|
|
@@ -8757,10 +9398,14 @@ OpenAI.Moderations = Moderations;
|
|
|
8757
9398
|
OpenAI.Models = Models;
|
|
8758
9399
|
OpenAI.ModelsPage = ModelsPage;
|
|
8759
9400
|
OpenAI.FineTuning = FineTuning;
|
|
9401
|
+
OpenAI.VectorStores = VectorStores;
|
|
9402
|
+
OpenAI.VectorStoresPage = VectorStoresPage;
|
|
9403
|
+
OpenAI.VectorStoreSearchResponsesPage = VectorStoreSearchResponsesPage;
|
|
8760
9404
|
OpenAI.Beta = Beta;
|
|
8761
9405
|
OpenAI.Batches = Batches;
|
|
8762
9406
|
OpenAI.BatchesPage = BatchesPage;
|
|
8763
9407
|
OpenAI.Uploads = Uploads;
|
|
9408
|
+
OpenAI.Responses = Responses;
|
|
8764
9409
|
|
|
8765
9410
|
class OpenaiProvider {
|
|
8766
9411
|
constructor(param, defaultModel, options) {
|
|
@@ -9378,7 +10023,7 @@ ${JSON.stringify(nodeOutputs)}
|
|
|
9378
10023
|
return {
|
|
9379
10024
|
isSuccessful: contextVariables.get("__isSuccessful__"),
|
|
9380
10025
|
summary: response.toolCalls[0].input.summary,
|
|
9381
|
-
payload: response.toolCalls[0].input.document,
|
|
10026
|
+
payload: (response.toolCalls[0].input.isDocumentGenerationTask ? response.toolCalls[0].input.document : undefined),
|
|
9382
10027
|
};
|
|
9383
10028
|
}
|
|
9384
10029
|
|
|
@@ -9746,7 +10391,7 @@ class ActionImpl {
|
|
|
9746
10391
|
// unwrap the toolCall
|
|
9747
10392
|
let unwrapped = this.unwrapToolCall(toolCall);
|
|
9748
10393
|
let input = unwrapped.toolCall.input;
|
|
9749
|
-
logger.
|
|
10394
|
+
logger.info("LLM Response:", unwrapped);
|
|
9750
10395
|
if (unwrapped.thinking) {
|
|
9751
10396
|
(_d = (_b = context.callback) === null || _b === void 0 ? void 0 : (_c = _b.hooks).onLlmMessage) === null || _d === void 0 ? void 0 : _d.call(_c, unwrapped.thinking);
|
|
9752
10397
|
}
|
|
@@ -9936,9 +10581,11 @@ class ActionImpl {
|
|
|
9936
10581
|
toolMap.set(returnTool.name, returnTool);
|
|
9937
10582
|
// get already existing tabs as task background
|
|
9938
10583
|
const currentWindow = await context.ekoConfig.chromeProxy.windows.getCurrent();
|
|
9939
|
-
|
|
10584
|
+
let existingTabs = await context.ekoConfig.chromeProxy.tabs.query({
|
|
9940
10585
|
windowId: currentWindow.id,
|
|
9941
10586
|
});
|
|
10587
|
+
existingTabs = existingTabs.filter((tab) => { tab.title && tab.url; });
|
|
10588
|
+
logger.debug("existingTabs:", existingTabs);
|
|
9942
10589
|
// get patchs for task
|
|
9943
10590
|
let patchs = [];
|
|
9944
10591
|
if (context.ekoConfig.patchServerUrl) {
|
|
@@ -10181,6 +10828,18 @@ Navigation Bar or Menu Changes: After logging in, the navigation bar will includ
|
|
|
10181
10828
|
// "type": "string",
|
|
10182
10829
|
// "description": 'Your observation of the previous steps. Should start with "In the previous step, I\'ve ...".',
|
|
10183
10830
|
// },
|
|
10831
|
+
evaluate_previous_goal: {
|
|
10832
|
+
"type": "string",
|
|
10833
|
+
"description": "Success|Failed|Unknown - Analyze the current elements and the image to check if the previous goals/actions are successful like intended by the task. Mention if something unexpected happened. Shortly state why/why not"
|
|
10834
|
+
},
|
|
10835
|
+
memory: {
|
|
10836
|
+
"type": "string",
|
|
10837
|
+
"description": "Description of what has been done and what you need to remember. Be very specific. Count here ALWAYS how many times you have done something and how many remain. E.g. 0 out of 10 websites analyzed. Continue with abc and xyz",
|
|
10838
|
+
},
|
|
10839
|
+
next_goal: {
|
|
10840
|
+
"type": "string",
|
|
10841
|
+
"description": "What needs to be done with the next immediate action",
|
|
10842
|
+
},
|
|
10184
10843
|
thinking: {
|
|
10185
10844
|
"type": "string",
|
|
10186
10845
|
"description": 'Your thinking draft.',
|
|
@@ -10196,6 +10855,9 @@ Navigation Bar or Menu Changes: After logging in, the navigation bar will includ
|
|
|
10196
10855
|
// "observation",
|
|
10197
10856
|
"thinking",
|
|
10198
10857
|
"userSidePrompt",
|
|
10858
|
+
"memory",
|
|
10859
|
+
"next_goal",
|
|
10860
|
+
"evaluate_previous_goal",
|
|
10199
10861
|
"toolCall",
|
|
10200
10862
|
],
|
|
10201
10863
|
};
|
|
@@ -10206,6 +10868,9 @@ Navigation Bar or Menu Changes: After logging in, the navigation bar will includ
|
|
|
10206
10868
|
observation: toolCall.input.observation,
|
|
10207
10869
|
thinking: toolCall.input.thinking,
|
|
10208
10870
|
userSidePrompt: toolCall.input.userSidePrompt,
|
|
10871
|
+
evaluate_previous_goal: toolCall.input.evaluate_previous_goal,
|
|
10872
|
+
memory: toolCall.input.memory,
|
|
10873
|
+
next_goal: toolCall.input.next_goal,
|
|
10209
10874
|
toolCall: {
|
|
10210
10875
|
id: toolCall.id,
|
|
10211
10876
|
name: toolCall.name,
|
|
@@ -10266,6 +10931,8 @@ class WorkflowGenerator {
|
|
|
10266
10931
|
}
|
|
10267
10932
|
async doGenerateWorkflow(prompt, modify, ekoConfig) {
|
|
10268
10933
|
// Create prompts with current set of tools
|
|
10934
|
+
logger.debug("doGenerateWorkflow...");
|
|
10935
|
+
let retry_counter = 3;
|
|
10269
10936
|
const prompts = createWorkflowPrompts(this.toolRegistry.getToolDefinitions());
|
|
10270
10937
|
let messages = [];
|
|
10271
10938
|
if (modify) {
|
|
@@ -10293,41 +10960,38 @@ class WorkflowGenerator {
|
|
|
10293
10960
|
tools: [createWorkflowGenerationTool(this.toolRegistry)],
|
|
10294
10961
|
toolChoice: { type: 'tool', name: 'generate_workflow' },
|
|
10295
10962
|
};
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
logger.debug("Debug the workflow...", { ...workflowData });
|
|
10326
|
-
// Generate a new UUID if not provided
|
|
10327
|
-
if (!workflowData.id) {
|
|
10328
|
-
workflowData.id = v4();
|
|
10963
|
+
while (retry_counter > 0) {
|
|
10964
|
+
try {
|
|
10965
|
+
console.time('Workflow Generation Time'); // 开始计时
|
|
10966
|
+
const response = await this.llmProvider.generateText(messages, params);
|
|
10967
|
+
console.timeEnd('Workflow Generation Time'); // 结束计时并输出时间差
|
|
10968
|
+
logger.debug("generateText() done!");
|
|
10969
|
+
if (!response.toolCalls.length || !response.toolCalls[0].input.workflow) {
|
|
10970
|
+
messages.pop();
|
|
10971
|
+
throw new Error('Failed to generate workflow: Invalid response from LLM');
|
|
10972
|
+
}
|
|
10973
|
+
let workflowData = response.toolCalls[0].input.workflow;
|
|
10974
|
+
// debug
|
|
10975
|
+
if (typeof workflowData == "string") {
|
|
10976
|
+
logger.warn("workflowData is string, try to transform it into object...");
|
|
10977
|
+
logger.debug("workflowData string:", workflowData);
|
|
10978
|
+
workflowData = JSON.parse(workflowData);
|
|
10979
|
+
}
|
|
10980
|
+
logger.debug("Debug the workflow...", { ...workflowData });
|
|
10981
|
+
// Generate a new UUID if not provided
|
|
10982
|
+
if (!workflowData.id) {
|
|
10983
|
+
workflowData.id = v4();
|
|
10984
|
+
}
|
|
10985
|
+
return this.createFastWorkflowFromData(workflowData, ekoConfig);
|
|
10986
|
+
}
|
|
10987
|
+
catch (e) {
|
|
10988
|
+
logger.warn("an error occured when generating workflow:", e);
|
|
10989
|
+
logger.info(`retry...${retry_counter}`);
|
|
10990
|
+
retry_counter -= 1;
|
|
10991
|
+
}
|
|
10329
10992
|
}
|
|
10330
|
-
|
|
10993
|
+
logger.error("cannot generate workflow with retry");
|
|
10994
|
+
throw Error("many errors occured when generating workflow");
|
|
10331
10995
|
}
|
|
10332
10996
|
createWorkflowFromData(data, ekoConfig) {
|
|
10333
10997
|
const workflow = new WorkflowImpl(data.id, data.name, ekoConfig, data, data.description || '', [], new Map(Object.entries(data.variables || {})), this.llmProvider, {
|
|
@@ -10397,44 +11061,23 @@ const workflowSchema = {
|
|
|
10397
11061
|
type: "array",
|
|
10398
11062
|
items: {
|
|
10399
11063
|
type: "object",
|
|
10400
|
-
required: ["id", "
|
|
11064
|
+
required: ["id", "action"],
|
|
10401
11065
|
properties: {
|
|
10402
11066
|
id: { type: "string" },
|
|
10403
|
-
type: {
|
|
10404
|
-
type: "string",
|
|
10405
|
-
enum: ["action"], // only action nodes for now; reserved for future types like condition, loop, etc.
|
|
10406
|
-
},
|
|
10407
|
-
dependencies: {
|
|
10408
|
-
type: "array",
|
|
10409
|
-
items: { type: "string" },
|
|
10410
|
-
},
|
|
10411
|
-
output: {
|
|
10412
|
-
type: "object",
|
|
10413
|
-
properties: {
|
|
10414
|
-
name: { type: "string" },
|
|
10415
|
-
description: { type: "string" },
|
|
10416
|
-
},
|
|
10417
|
-
},
|
|
10418
11067
|
action: {
|
|
10419
11068
|
type: "object",
|
|
10420
|
-
required: ["
|
|
11069
|
+
required: ["name", "description"],
|
|
10421
11070
|
properties: {
|
|
10422
|
-
type:
|
|
11071
|
+
name: { type: "string" },
|
|
11072
|
+
description: {
|
|
10423
11073
|
type: "string",
|
|
10424
|
-
|
|
10425
|
-
enum: ["prompt"],
|
|
11074
|
+
description: "Note that do not use \" mark.",
|
|
10426
11075
|
},
|
|
10427
|
-
name: { type: "string" },
|
|
10428
|
-
description: { type: "string" },
|
|
10429
11076
|
},
|
|
10430
11077
|
},
|
|
10431
11078
|
},
|
|
10432
11079
|
},
|
|
10433
11080
|
},
|
|
10434
|
-
variables: {
|
|
10435
|
-
type: "object",
|
|
10436
|
-
additionalProperties: true,
|
|
10437
|
-
},
|
|
10438
11081
|
},
|
|
10439
11082
|
};
|
|
10440
11083
|
|
|
@@ -10497,7 +11140,7 @@ class Eko {
|
|
|
10497
11140
|
this.llmProvider = LLMProviderFactory.buildLLMProvider(llmConfig);
|
|
10498
11141
|
this.ekoConfig = this.buildEkoConfig(ekoConfig);
|
|
10499
11142
|
this.registerTools();
|
|
10500
|
-
logger.info("using Eko@" + "
|
|
11143
|
+
logger.info("using Eko@" + "416349eaa1535085d74b14170d4e0741756da46f");
|
|
10501
11144
|
logger.debug("caller's ekoConfig:", ekoConfig);
|
|
10502
11145
|
}
|
|
10503
11146
|
static getLogger() {
|