@discomedia/utils 1.0.50 → 1.0.51

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.cjs CHANGED
@@ -966,6 +966,61 @@ function countTradingDays(startDate, endDate = new Date()) {
966
966
  minutes: Math.round(minutes),
967
967
  };
968
968
  }
969
+ /**
970
+ * Returns the trading day N days back from a reference date, along with its market open time.
971
+ * Trading days are counted as full or half trading days (days that end count as 1 full trading day).
972
+ *
973
+ * @param options - Object with:
974
+ * - referenceDate: Date to count back from (default: now)
975
+ * - days: Number of trading days to go back (must be >= 1)
976
+ * @returns Object containing:
977
+ * - date: Trading date in YYYY-MM-DD format
978
+ * - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
979
+ * - unixTimestamp: Market open time as Unix timestamp in seconds
980
+ * @example
981
+ * ```typescript
982
+ * // Get the trading day 1 day back (most recent full trading day)
983
+ * const result = getTradingDaysBack({ days: 1 });
984
+ * console.log(result.date); // "2025-11-01"
985
+ * console.log(result.marketOpenISO); // "2025-11-01T13:30:00.000Z"
986
+ * console.log(result.unixTimestamp); // 1730466600
987
+ *
988
+ * // Get the trading day 5 days back from a specific date
989
+ * const result2 = getTradingDaysBack({
990
+ * referenceDate: new Date('2025-11-15T12:00:00-05:00'),
991
+ * days: 5
992
+ * });
993
+ * ```
994
+ */
995
+ function getTradingDaysBack(options) {
996
+ const calendar = new MarketCalendar();
997
+ const refDate = options.referenceDate || new Date();
998
+ const daysBack = options.days;
999
+ if (daysBack < 1) {
1000
+ throw new Error('days must be at least 1');
1001
+ }
1002
+ // Start from the last full trading date relative to reference
1003
+ let targetDate = getLastFullTradingDateImpl(refDate);
1004
+ // Go back the specified number of days (we're already at day 1, so go back days-1 more)
1005
+ for (let i = 1; i < daysBack; i++) {
1006
+ targetDate = calendar.getPreviousMarketDay(targetDate);
1007
+ }
1008
+ // Get market open time for this date
1009
+ const marketTimes = getMarketTimes(targetDate);
1010
+ if (!marketTimes.open) {
1011
+ throw new Error(`No market open time for target date`);
1012
+ }
1013
+ // Format the date string (YYYY-MM-DD) in NY time
1014
+ const nyDate = toNYTime(marketTimes.open);
1015
+ const dateStr = `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
1016
+ const marketOpenISO = marketTimes.open.toISOString();
1017
+ const unixTimestamp = Math.floor(marketTimes.open.getTime() / 1000);
1018
+ return {
1019
+ date: dateStr,
1020
+ marketOpenISO,
1021
+ unixTimestamp,
1022
+ };
1023
+ }
969
1024
  // Export MARKET_TIMES for compatibility
970
1025
  const MARKET_TIMES = {
971
1026
  TIMEZONE: MARKET_CONFIG.TIMEZONE,
@@ -2457,7 +2512,7 @@ const safeJSON = (text) => {
2457
2512
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2458
2513
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2459
2514
 
2460
- const VERSION = '6.10.0'; // x-release-please-version
2515
+ const VERSION = '6.15.0'; // x-release-please-version
2461
2516
 
2462
2517
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2463
2518
  const isRunningInBrowser = () => {
@@ -8303,10 +8358,12 @@ class Responses extends APIResource {
8303
8358
  *
8304
8359
  * @example
8305
8360
  * ```ts
8306
- * const compactedResponse = await client.responses.compact();
8361
+ * const compactedResponse = await client.responses.compact({
8362
+ * model: 'gpt-5.2',
8363
+ * });
8307
8364
  * ```
8308
8365
  */
8309
- compact(body = {}, options) {
8366
+ compact(body, options) {
8310
8367
  return this._client.post('/responses/compact', { body, ...options });
8311
8368
  }
8312
8369
  }
@@ -9487,6 +9544,7 @@ const deepseekModelCosts = {
9487
9544
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
9488
9545
  const openAiImageCosts = {
9489
9546
  'gpt-image-1': 0.0075, // $0.0075 per image for gpt-image-1
9547
+ 'gpt-image-1.5': 0.0075, // Assumes parity pricing with gpt-image-1 until OpenAI publishes updated rates
9490
9548
  };
9491
9549
  /**
9492
9550
  * Calculates the cost of generating images using OpenAI's Images API.
@@ -9496,10 +9554,12 @@ const openAiImageCosts = {
9496
9554
  * @returns The cost of generating the images in USD.
9497
9555
  */
9498
9556
  function calculateImageCost(model, imageCount) {
9499
- if (typeof imageCount !== 'number' || imageCount <= 0) {
9557
+ if (typeof model !== 'string' || typeof imageCount !== 'number' || imageCount <= 0) {
9500
9558
  return 0;
9501
9559
  }
9502
9560
  const costPerImage = openAiImageCosts[model];
9561
+ if (!costPerImage)
9562
+ return 0;
9503
9563
  return imageCount * costPerImage;
9504
9564
  }
9505
9565
  /**
@@ -10226,6 +10286,8 @@ async function makeLLMCall(input, options = {}) {
10226
10286
  return await makeResponsesAPICall(processedInput, responsesOptions);
10227
10287
  }
10228
10288
 
10289
+ const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
10290
+ const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
10229
10291
  const MULTIMODAL_VISION_MODELS = new Set([
10230
10292
  'gpt-4o-mini',
10231
10293
  'gpt-4o',
@@ -10274,7 +10336,8 @@ const MULTIMODAL_VISION_MODELS = new Set([
10274
10336
  * @throws Error if the API call fails or invalid parameters are provided
10275
10337
  */
10276
10338
  async function makeImagesCall(prompt, options = {}) {
10277
- const { size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10339
+ const { model, size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10340
+ const imageModel = resolveImageModel(model);
10278
10341
  const supportedVisionModel = visionModel && MULTIMODAL_VISION_MODELS.has(visionModel) ? visionModel : undefined;
10279
10342
  if (visionModel && !supportedVisionModel) {
10280
10343
  console.warn(`Vision model ${visionModel} is not recognized as a multimodal OpenAI model. Ignoring for image usage metadata.`);
@@ -10299,7 +10362,7 @@ async function makeImagesCall(prompt, options = {}) {
10299
10362
  });
10300
10363
  // Build the request parameters using OpenAI's type
10301
10364
  const requestParams = {
10302
- model: 'gpt-image-1',
10365
+ model: imageModel,
10303
10366
  prompt,
10304
10367
  n: count || 1,
10305
10368
  size: size || 'auto',
@@ -10323,7 +10386,7 @@ async function makeImagesCall(prompt, options = {}) {
10323
10386
  throw new Error('No images returned from OpenAI Images API');
10324
10387
  }
10325
10388
  // Calculate cost
10326
- const cost = calculateImageCost('gpt-image-1', count || 1);
10389
+ const cost = calculateImageCost(imageModel, count || 1);
10327
10390
  // Return the response with enhanced usage information
10328
10391
  const enhancedResponse = {
10329
10392
  ...response,
@@ -10336,7 +10399,7 @@ async function makeImagesCall(prompt, options = {}) {
10336
10399
  total_tokens: 0,
10337
10400
  }),
10338
10401
  provider: 'openai',
10339
- model: 'gpt-image-1',
10402
+ model: imageModel,
10340
10403
  cost,
10341
10404
  ...(supportedVisionModel ? { visionModel: supportedVisionModel } : {}),
10342
10405
  },
@@ -19465,6 +19528,7 @@ const disco = {
19465
19528
  getNYTimeZone: getNYTimeZone,
19466
19529
  getTradingDate: getTradingDate,
19467
19530
  getTradingStartAndEndDates: getTradingStartAndEndDates,
19531
+ getTradingDaysBack: getTradingDaysBack,
19468
19532
  isMarketDay: isMarketDay,
19469
19533
  isWithinMarketHours: isWithinMarketHours,
19470
19534
  countTradingDays: countTradingDays,