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