@discomedia/utils 1.0.41 → 1.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1502,8 +1502,8 @@ function pLimit(concurrency) {
1502
1502
  },
1503
1503
  },
1504
1504
  map: {
1505
- async value(array, function_) {
1506
- const promises = array.map((value, index) => this(function_, value, index));
1505
+ async value(iterable, function_) {
1506
+ const promises = Array.from(iterable, (value, index) => this(function_, value, index));
1507
1507
  return Promise.all(promises);
1508
1508
  },
1509
1509
  },
@@ -2449,7 +2449,7 @@ const safeJSON = (text) => {
2449
2449
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2450
2450
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2451
2451
 
2452
- const VERSION = '6.2.0'; // x-release-please-version
2452
+ const VERSION = '6.7.0'; // x-release-please-version
2453
2453
 
2454
2454
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2455
2455
  const isRunningInBrowser = () => {
@@ -6004,19 +6004,6 @@ class ChatKit extends APIResource {
6004
6004
  this.sessions = new Sessions(this._client);
6005
6005
  this.threads = new Threads$1(this._client);
6006
6006
  }
6007
- /**
6008
- * Upload a ChatKit file
6009
- *
6010
- * @example
6011
- * ```ts
6012
- * const response = await client.beta.chatkit.uploadFile({
6013
- * file: fs.createReadStream('path/to/file'),
6014
- * });
6015
- * ```
6016
- */
6017
- uploadFile(body, options) {
6018
- return this._client.post('/chatkit/files', maybeMultipartFormRequestOptions({ body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) }, this._client));
6019
- }
6020
6007
  }
6021
6008
  ChatKit.Sessions = Sessions;
6022
6009
  ChatKit.Threads = Threads$1;
@@ -7304,20 +7291,19 @@ let Files$1 = class Files extends APIResource {
7304
7291
  * up to 512 MB, and the size of all files uploaded by one organization can be up
7305
7292
  * to 1 TB.
7306
7293
  *
7307
- * The Assistants API supports files up to 2 million tokens and of specific file
7308
- * types. See the
7309
- * [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for
7310
- * details.
7311
- *
7312
- * The Fine-tuning API only supports `.jsonl` files. The input also has certain
7313
- * required formats for fine-tuning
7314
- * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
7315
- * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
7316
- * models.
7317
- *
7318
- * The Batch API only supports `.jsonl` files up to 200 MB in size. The input also
7319
- * has a specific required
7320
- * [format](https://platform.openai.com/docs/api-reference/batch/request-input).
7294
+ * - The Assistants API supports files up to 2 million tokens and of specific file
7295
+ * types. See the
7296
+ * [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools)
7297
+ * for details.
7298
+ * - The Fine-tuning API only supports `.jsonl` files. The input also has certain
7299
+ * required formats for fine-tuning
7300
+ * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input)
7301
+ * or
7302
+ * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
7303
+ * models.
7304
+ * - The Batch API only supports `.jsonl` files up to 200 MB in size. The input
7305
+ * also has a specific required
7306
+ * [format](https://platform.openai.com/docs/api-reference/batch/request-input).
7321
7307
  *
7322
7308
  * Please [contact us](https://help.openai.com/) if you need to increase these
7323
7309
  * storage limits.
@@ -7338,7 +7324,7 @@ let Files$1 = class Files extends APIResource {
7338
7324
  return this._client.getAPIList('/files', (CursorPage), { query, ...options });
7339
7325
  }
7340
7326
  /**
7341
- * Delete a file.
7327
+ * Delete a file and remove it from all vector stores.
7342
7328
  */
7343
7329
  delete(fileID, options) {
7344
7330
  return this._client.delete(path `/files/${fileID}`, options);
@@ -8220,11 +8206,27 @@ class InputItems extends APIResource {
8220
8206
  }
8221
8207
  }
8222
8208
 
8209
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
8210
+ class InputTokens extends APIResource {
8211
+ /**
8212
+ * Get input token counts
8213
+ *
8214
+ * @example
8215
+ * ```ts
8216
+ * const response = await client.responses.inputTokens.count();
8217
+ * ```
8218
+ */
8219
+ count(body = {}, options) {
8220
+ return this._client.post('/responses/input_tokens', { body, ...options });
8221
+ }
8222
+ }
8223
+
8223
8224
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
8224
8225
  class Responses extends APIResource {
8225
8226
  constructor() {
8226
8227
  super(...arguments);
8227
8228
  this.inputItems = new InputItems(this._client);
8229
+ this.inputTokens = new InputTokens(this._client);
8228
8230
  }
8229
8231
  create(body, options) {
8230
8232
  return this._client.post('/responses', { body, ...options, stream: body.stream ?? false })._thenUnwrap((rsp) => {
@@ -8290,6 +8292,7 @@ class Responses extends APIResource {
8290
8292
  }
8291
8293
  }
8292
8294
  Responses.InputItems = InputItems;
8295
+ Responses.InputTokens = InputTokens;
8293
8296
 
8294
8297
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
8295
8298
  class Parts extends APIResource {
@@ -16708,7 +16711,11 @@ function requireConfig () {
16708
16711
 
16709
16712
  requireConfig();
16710
16713
 
16714
+ const DEBUG_LOGGING = process.env['DEBUG'] === 'true' || false;
16711
16715
  const log = (message, options = { type: 'info' }) => {
16716
+ if (!DEBUG_LOGGING && options.type === 'debug') {
16717
+ return;
16718
+ }
16712
16719
  log$1(message, { ...options, source: 'AlpacaMarketDataAPI' });
16713
16720
  };
16714
16721
  // Default settings for market data API
@@ -16798,7 +16805,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16798
16805
  this.optionWs = ws;
16799
16806
  }
16800
16807
  ws.on('open', () => {
16801
- log(`${streamType} stream connected`, { type: 'info' });
16808
+ log(`${streamType} stream connected`);
16802
16809
  const authMessage = {
16803
16810
  action: 'auth',
16804
16811
  key: process.env.ALPACA_API_KEY,
@@ -16811,7 +16818,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16811
16818
  const messages = JSON.parse(data.toString());
16812
16819
  for (const message of messages) {
16813
16820
  if (message.T === 'success' && message.msg === 'authenticated') {
16814
- log(`${streamType} stream authenticated`, { type: 'info' });
16821
+ log(`${streamType} stream authenticated`);
16815
16822
  this.sendSubscription(streamType);
16816
16823
  }
16817
16824
  else if (message.T === 'error') {
@@ -16961,9 +16968,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16961
16968
  symbols.forEach((symbol) => {
16962
16969
  allBars[symbol] = [];
16963
16970
  });
16964
- log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
16965
- type: 'info',
16966
- });
16971
+ log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
16967
16972
  while (hasMorePages) {
16968
16973
  pageCount++;
16969
16974
  const requestParams = {
@@ -17008,7 +17013,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17008
17013
  const dateRangeStr = earliestTimestamp && latestTimestamp
17009
17014
  ? `${new Date(earliestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${new Date(latestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17010
17015
  : 'unknown range';
17011
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`);
17016
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17012
17017
  // Prevent infinite loops
17013
17018
  if (pageCount > 1000) {
17014
17019
  log(`Stopping pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
@@ -17019,7 +17024,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17019
17024
  const symbolsJoined = Object.entries(allBars)
17020
17025
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17021
17026
  .join(', ');
17022
- log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17027
+ log(`Bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17023
17028
  return {
17024
17029
  bars: allBars,
17025
17030
  next_page_token: null, // Always null since we fetch all pages
@@ -17300,9 +17305,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17300
17305
  symbols.forEach((symbol) => {
17301
17306
  allBars[symbol] = [];
17302
17307
  });
17303
- log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
17304
- type: 'info',
17305
- });
17308
+ log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17306
17309
  while (hasMorePages) {
17307
17310
  pageCount++;
17308
17311
  const requestParams = {
@@ -17342,7 +17345,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17342
17345
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17343
17346
  : 'unknown range';
17344
17347
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17345
- type: 'info',
17348
+ type: 'debug',
17346
17349
  });
17347
17350
  // Prevent infinite loops
17348
17351
  if (pageCount > 1000) {
@@ -17354,9 +17357,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17354
17357
  const symbolCounts = Object.entries(allBars)
17355
17358
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17356
17359
  .join(', ');
17357
- log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
17358
- type: 'info',
17359
- });
17360
+ log(`Options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`);
17360
17361
  return {
17361
17362
  bars: allBars,
17362
17363
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17382,9 +17383,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17382
17383
  symbols.forEach((symbol) => {
17383
17384
  allTrades[symbol] = [];
17384
17385
  });
17385
- log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
17386
- type: 'info',
17387
- });
17386
+ log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17388
17387
  while (hasMorePages) {
17389
17388
  pageCount++;
17390
17389
  const requestParams = {
@@ -17424,7 +17423,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17424
17423
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17425
17424
  : 'unknown range';
17426
17425
  log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17427
- type: 'info',
17426
+ type: 'debug',
17428
17427
  });
17429
17428
  // Prevent infinite loops
17430
17429
  if (pageCount > 1000) {
@@ -17436,9 +17435,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17436
17435
  const symbolCounts = Object.entries(allTrades)
17437
17436
  .map(([symbol, trades]) => `${symbol}: ${trades.length}`)
17438
17437
  .join(', ');
17439
- log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
17440
- type: 'info',
17441
- });
17438
+ log(`Options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`);
17442
17439
  return {
17443
17440
  trades: allTrades,
17444
17441
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17646,7 +17643,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17646
17643
  symbols.forEach((symbol) => {
17647
17644
  allBars[symbol] = [];
17648
17645
  });
17649
- log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17646
+ log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17650
17647
  while (hasMorePages) {
17651
17648
  pageCount++;
17652
17649
  const requestParams = {
@@ -17670,14 +17667,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17670
17667
  totalBarsCount += pageBarsCount;
17671
17668
  pageToken = response.next_page_token || null;
17672
17669
  hasMorePages = !!pageToken;
17673
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17670
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17674
17671
  // Prevent infinite loops
17675
17672
  if (pageCount > 1000) {
17676
17673
  log(`Stopping crypto bars pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17677
17674
  break;
17678
17675
  }
17679
17676
  }
17680
- log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`, { type: 'info' });
17677
+ log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`);
17681
17678
  return {
17682
17679
  bars: allBars,
17683
17680
  next_page_token: null, // Always null since we fetch all pages
@@ -17709,7 +17706,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17709
17706
  symbols.forEach((symbol) => {
17710
17707
  allQuotes[symbol] = [];
17711
17708
  });
17712
- log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17709
+ log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17713
17710
  while (hasMorePages) {
17714
17711
  pageCount++;
17715
17712
  const requestParams = {
@@ -17733,14 +17730,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17733
17730
  totalQuotesCount += pageQuotesCount;
17734
17731
  pageToken = response.next_page_token || null;
17735
17732
  hasMorePages = !!pageToken;
17736
- log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17733
+ log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17737
17734
  // Prevent infinite loops
17738
17735
  if (pageCount > 1000) {
17739
17736
  log(`Stopping crypto quotes pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17740
17737
  break;
17741
17738
  }
17742
17739
  }
17743
- log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`, { type: 'info' });
17740
+ log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`);
17744
17741
  return {
17745
17742
  quotes: allQuotes,
17746
17743
  next_page_token: null, // Always null since we fetch all pages
@@ -17776,7 +17773,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17776
17773
  symbols.forEach((symbol) => {
17777
17774
  allTrades[symbol] = [];
17778
17775
  });
17779
- log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17776
+ log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17780
17777
  while (hasMorePages) {
17781
17778
  pageCount++;
17782
17779
  const requestParams = {
@@ -17800,14 +17797,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17800
17797
  totalTradesCount += pageTradesCount;
17801
17798
  pageToken = response.next_page_token || null;
17802
17799
  hasMorePages = !!pageToken;
17803
- log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17800
+ log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17804
17801
  // Prevent infinite loops
17805
17802
  if (pageCount > 1000) {
17806
17803
  log(`Stopping crypto trades pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17807
17804
  break;
17808
17805
  }
17809
17806
  }
17810
- log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`, { type: 'info' });
17807
+ log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`);
17811
17808
  return {
17812
17809
  trades: allTrades,
17813
17810
  next_page_token: null, // Always null since we fetch all pages