@discomedia/utils 1.0.50 → 1.0.52

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.
Files changed (34) hide show
  1. package/dist/index-frontend.cjs +79 -8
  2. package/dist/index-frontend.cjs.map +1 -1
  3. package/dist/index-frontend.mjs +79 -8
  4. package/dist/index-frontend.mjs.map +1 -1
  5. package/dist/index.cjs +79 -8
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.mjs +79 -8
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/package.json +4 -4
  10. package/dist/test.js +9122 -3789
  11. package/dist/test.js.map +1 -1
  12. package/dist/types/index.d.ts +1 -0
  13. package/dist/types/index.d.ts.map +1 -1
  14. package/dist/types/llm-config.d.ts.map +1 -1
  15. package/dist/types/llm-images.d.ts +5 -3
  16. package/dist/types/llm-images.d.ts.map +1 -1
  17. package/dist/types/market-time.d.ts +35 -1
  18. package/dist/types/market-time.d.ts.map +1 -1
  19. package/dist/types/types/llm-types.d.ts +3 -1
  20. package/dist/types/types/llm-types.d.ts.map +1 -1
  21. package/dist/types/types/market-time-types.d.ts +5 -0
  22. package/dist/types/types/market-time-types.d.ts.map +1 -1
  23. package/dist/types-frontend/index.d.ts +1 -0
  24. package/dist/types-frontend/index.d.ts.map +1 -1
  25. package/dist/types-frontend/llm-config.d.ts.map +1 -1
  26. package/dist/types-frontend/llm-images.d.ts +5 -3
  27. package/dist/types-frontend/llm-images.d.ts.map +1 -1
  28. package/dist/types-frontend/market-time.d.ts +35 -1
  29. package/dist/types-frontend/market-time.d.ts.map +1 -1
  30. package/dist/types-frontend/types/llm-types.d.ts +3 -1
  31. package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
  32. package/dist/types-frontend/types/market-time-types.d.ts +5 -0
  33. package/dist/types-frontend/types/market-time-types.d.ts.map +1 -1
  34. package/package.json +4 -4
package/dist/index.cjs CHANGED
@@ -966,6 +966,68 @@ 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
+ * By default, the most recent completed trading day counts as day 1.
973
+ * Set includeMostRecentFullDay to false to count strictly before that day.
974
+ *
975
+ * @param options - Object with:
976
+ * - referenceDate: Date to count back from (default: now)
977
+ * - days: Number of trading days to go back (must be an integer >= 1)
978
+ * - includeMostRecentFullDay: Whether to include the most recent completed trading day (default: true)
979
+ * @returns Object containing:
980
+ * - date: Trading date in YYYY-MM-DD format
981
+ * - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
982
+ * - unixTimestamp: Market open time as Unix timestamp in seconds
983
+ * @example
984
+ * ```typescript
985
+ * // Get the trading day 1 day back (most recent full trading day)
986
+ * const result = getTradingDaysBack({ days: 1 });
987
+ * console.log(result.date); // "2025-11-01"
988
+ * console.log(result.marketOpenISO); // "2025-11-01T13:30:00.000Z"
989
+ * console.log(result.unixTimestamp); // 1730466600
990
+ *
991
+ * // Get the trading day 5 days back from a specific date
992
+ * const result2 = getTradingDaysBack({
993
+ * referenceDate: new Date('2025-11-15T12:00:00-05:00'),
994
+ * days: 5
995
+ * });
996
+ * ```
997
+ */
998
+ function getTradingDaysBack(options) {
999
+ const calendar = new MarketCalendar();
1000
+ const { referenceDate, days, includeMostRecentFullDay = true } = options;
1001
+ const refDate = referenceDate || new Date();
1002
+ const daysBack = days;
1003
+ if (!Number.isInteger(daysBack) || daysBack < 1) {
1004
+ throw new Error('days must be an integer >= 1');
1005
+ }
1006
+ // Start from the last full trading date relative to reference
1007
+ let targetDate = getLastFullTradingDateImpl(refDate);
1008
+ if (!includeMostRecentFullDay) {
1009
+ targetDate = calendar.getPreviousMarketDay(targetDate);
1010
+ }
1011
+ // Go back the specified number of days (we're already at day 1, so go back days-1 more)
1012
+ for (let i = 1; i < daysBack; i++) {
1013
+ targetDate = calendar.getPreviousMarketDay(targetDate);
1014
+ }
1015
+ // Get market open time for this date
1016
+ const marketTimes = getMarketTimes(targetDate);
1017
+ if (!marketTimes.open) {
1018
+ throw new Error(`No market open time for target date`);
1019
+ }
1020
+ // Format the date string (YYYY-MM-DD) in NY time
1021
+ const nyDate = toNYTime(marketTimes.open);
1022
+ const dateStr = `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
1023
+ const marketOpenISO = marketTimes.open.toISOString();
1024
+ const unixTimestamp = Math.floor(marketTimes.open.getTime() / 1000);
1025
+ return {
1026
+ date: dateStr,
1027
+ marketOpenISO,
1028
+ unixTimestamp,
1029
+ };
1030
+ }
969
1031
  // Export MARKET_TIMES for compatibility
970
1032
  const MARKET_TIMES = {
971
1033
  TIMEZONE: MARKET_CONFIG.TIMEZONE,
@@ -2457,7 +2519,7 @@ const safeJSON = (text) => {
2457
2519
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2458
2520
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2459
2521
 
2460
- const VERSION = '6.10.0'; // x-release-please-version
2522
+ const VERSION = '6.15.0'; // x-release-please-version
2461
2523
 
2462
2524
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2463
2525
  const isRunningInBrowser = () => {
@@ -8303,10 +8365,12 @@ class Responses extends APIResource {
8303
8365
  *
8304
8366
  * @example
8305
8367
  * ```ts
8306
- * const compactedResponse = await client.responses.compact();
8368
+ * const compactedResponse = await client.responses.compact({
8369
+ * model: 'gpt-5.2',
8370
+ * });
8307
8371
  * ```
8308
8372
  */
8309
- compact(body = {}, options) {
8373
+ compact(body, options) {
8310
8374
  return this._client.post('/responses/compact', { body, ...options });
8311
8375
  }
8312
8376
  }
@@ -9487,6 +9551,7 @@ const deepseekModelCosts = {
9487
9551
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
9488
9552
  const openAiImageCosts = {
9489
9553
  'gpt-image-1': 0.0075, // $0.0075 per image for gpt-image-1
9554
+ 'gpt-image-1.5': 0.0075, // Assumes parity pricing with gpt-image-1 until OpenAI publishes updated rates
9490
9555
  };
9491
9556
  /**
9492
9557
  * Calculates the cost of generating images using OpenAI's Images API.
@@ -9496,10 +9561,12 @@ const openAiImageCosts = {
9496
9561
  * @returns The cost of generating the images in USD.
9497
9562
  */
9498
9563
  function calculateImageCost(model, imageCount) {
9499
- if (typeof imageCount !== 'number' || imageCount <= 0) {
9564
+ if (typeof model !== 'string' || typeof imageCount !== 'number' || imageCount <= 0) {
9500
9565
  return 0;
9501
9566
  }
9502
9567
  const costPerImage = openAiImageCosts[model];
9568
+ if (!costPerImage)
9569
+ return 0;
9503
9570
  return imageCount * costPerImage;
9504
9571
  }
9505
9572
  /**
@@ -10226,6 +10293,8 @@ async function makeLLMCall(input, options = {}) {
10226
10293
  return await makeResponsesAPICall(processedInput, responsesOptions);
10227
10294
  }
10228
10295
 
10296
+ const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
10297
+ const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
10229
10298
  const MULTIMODAL_VISION_MODELS = new Set([
10230
10299
  'gpt-4o-mini',
10231
10300
  'gpt-4o',
@@ -10274,7 +10343,8 @@ const MULTIMODAL_VISION_MODELS = new Set([
10274
10343
  * @throws Error if the API call fails or invalid parameters are provided
10275
10344
  */
10276
10345
  async function makeImagesCall(prompt, options = {}) {
10277
- const { size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10346
+ const { model, size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10347
+ const imageModel = resolveImageModel(model);
10278
10348
  const supportedVisionModel = visionModel && MULTIMODAL_VISION_MODELS.has(visionModel) ? visionModel : undefined;
10279
10349
  if (visionModel && !supportedVisionModel) {
10280
10350
  console.warn(`Vision model ${visionModel} is not recognized as a multimodal OpenAI model. Ignoring for image usage metadata.`);
@@ -10299,7 +10369,7 @@ async function makeImagesCall(prompt, options = {}) {
10299
10369
  });
10300
10370
  // Build the request parameters using OpenAI's type
10301
10371
  const requestParams = {
10302
- model: 'gpt-image-1',
10372
+ model: imageModel,
10303
10373
  prompt,
10304
10374
  n: count || 1,
10305
10375
  size: size || 'auto',
@@ -10323,7 +10393,7 @@ async function makeImagesCall(prompt, options = {}) {
10323
10393
  throw new Error('No images returned from OpenAI Images API');
10324
10394
  }
10325
10395
  // Calculate cost
10326
- const cost = calculateImageCost('gpt-image-1', count || 1);
10396
+ const cost = calculateImageCost(imageModel, count || 1);
10327
10397
  // Return the response with enhanced usage information
10328
10398
  const enhancedResponse = {
10329
10399
  ...response,
@@ -10336,7 +10406,7 @@ async function makeImagesCall(prompt, options = {}) {
10336
10406
  total_tokens: 0,
10337
10407
  }),
10338
10408
  provider: 'openai',
10339
- model: 'gpt-image-1',
10409
+ model: imageModel,
10340
10410
  cost,
10341
10411
  ...(supportedVisionModel ? { visionModel: supportedVisionModel } : {}),
10342
10412
  },
@@ -19465,6 +19535,7 @@ const disco = {
19465
19535
  getNYTimeZone: getNYTimeZone,
19466
19536
  getTradingDate: getTradingDate,
19467
19537
  getTradingStartAndEndDates: getTradingStartAndEndDates,
19538
+ getTradingDaysBack: getTradingDaysBack,
19468
19539
  isMarketDay: isMarketDay,
19469
19540
  isWithinMarketHours: isWithinMarketHours,
19470
19541
  countTradingDays: countTradingDays,