@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.mjs CHANGED
@@ -964,6 +964,68 @@ 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
+ * By default, the most recent completed trading day counts as day 1.
971
+ * Set includeMostRecentFullDay to false to count strictly before that 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 an integer >= 1)
976
+ * - includeMostRecentFullDay: Whether to include the most recent completed trading day (default: true)
977
+ * @returns Object containing:
978
+ * - date: Trading date in YYYY-MM-DD format
979
+ * - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
980
+ * - unixTimestamp: Market open time as Unix timestamp in seconds
981
+ * @example
982
+ * ```typescript
983
+ * // Get the trading day 1 day back (most recent full trading day)
984
+ * const result = getTradingDaysBack({ days: 1 });
985
+ * console.log(result.date); // "2025-11-01"
986
+ * console.log(result.marketOpenISO); // "2025-11-01T13:30:00.000Z"
987
+ * console.log(result.unixTimestamp); // 1730466600
988
+ *
989
+ * // Get the trading day 5 days back from a specific date
990
+ * const result2 = getTradingDaysBack({
991
+ * referenceDate: new Date('2025-11-15T12:00:00-05:00'),
992
+ * days: 5
993
+ * });
994
+ * ```
995
+ */
996
+ function getTradingDaysBack(options) {
997
+ const calendar = new MarketCalendar();
998
+ const { referenceDate, days, includeMostRecentFullDay = true } = options;
999
+ const refDate = referenceDate || new Date();
1000
+ const daysBack = days;
1001
+ if (!Number.isInteger(daysBack) || daysBack < 1) {
1002
+ throw new Error('days must be an integer >= 1');
1003
+ }
1004
+ // Start from the last full trading date relative to reference
1005
+ let targetDate = getLastFullTradingDateImpl(refDate);
1006
+ if (!includeMostRecentFullDay) {
1007
+ targetDate = calendar.getPreviousMarketDay(targetDate);
1008
+ }
1009
+ // Go back the specified number of days (we're already at day 1, so go back days-1 more)
1010
+ for (let i = 1; i < daysBack; i++) {
1011
+ targetDate = calendar.getPreviousMarketDay(targetDate);
1012
+ }
1013
+ // Get market open time for this date
1014
+ const marketTimes = getMarketTimes(targetDate);
1015
+ if (!marketTimes.open) {
1016
+ throw new Error(`No market open time for target date`);
1017
+ }
1018
+ // Format the date string (YYYY-MM-DD) in NY time
1019
+ const nyDate = toNYTime(marketTimes.open);
1020
+ const dateStr = `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
1021
+ const marketOpenISO = marketTimes.open.toISOString();
1022
+ const unixTimestamp = Math.floor(marketTimes.open.getTime() / 1000);
1023
+ return {
1024
+ date: dateStr,
1025
+ marketOpenISO,
1026
+ unixTimestamp,
1027
+ };
1028
+ }
967
1029
  // Export MARKET_TIMES for compatibility
968
1030
  const MARKET_TIMES = {
969
1031
  TIMEZONE: MARKET_CONFIG.TIMEZONE,
@@ -2455,7 +2517,7 @@ const safeJSON = (text) => {
2455
2517
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2456
2518
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2457
2519
 
2458
- const VERSION = '6.10.0'; // x-release-please-version
2520
+ const VERSION = '6.15.0'; // x-release-please-version
2459
2521
 
2460
2522
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2461
2523
  const isRunningInBrowser = () => {
@@ -8301,10 +8363,12 @@ class Responses extends APIResource {
8301
8363
  *
8302
8364
  * @example
8303
8365
  * ```ts
8304
- * const compactedResponse = await client.responses.compact();
8366
+ * const compactedResponse = await client.responses.compact({
8367
+ * model: 'gpt-5.2',
8368
+ * });
8305
8369
  * ```
8306
8370
  */
8307
- compact(body = {}, options) {
8371
+ compact(body, options) {
8308
8372
  return this._client.post('/responses/compact', { body, ...options });
8309
8373
  }
8310
8374
  }
@@ -9485,6 +9549,7 @@ const deepseekModelCosts = {
9485
9549
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
9486
9550
  const openAiImageCosts = {
9487
9551
  'gpt-image-1': 0.0075, // $0.0075 per image for gpt-image-1
9552
+ 'gpt-image-1.5': 0.0075, // Assumes parity pricing with gpt-image-1 until OpenAI publishes updated rates
9488
9553
  };
9489
9554
  /**
9490
9555
  * Calculates the cost of generating images using OpenAI's Images API.
@@ -9494,10 +9559,12 @@ const openAiImageCosts = {
9494
9559
  * @returns The cost of generating the images in USD.
9495
9560
  */
9496
9561
  function calculateImageCost(model, imageCount) {
9497
- if (typeof imageCount !== 'number' || imageCount <= 0) {
9562
+ if (typeof model !== 'string' || typeof imageCount !== 'number' || imageCount <= 0) {
9498
9563
  return 0;
9499
9564
  }
9500
9565
  const costPerImage = openAiImageCosts[model];
9566
+ if (!costPerImage)
9567
+ return 0;
9501
9568
  return imageCount * costPerImage;
9502
9569
  }
9503
9570
  /**
@@ -10224,6 +10291,8 @@ async function makeLLMCall(input, options = {}) {
10224
10291
  return await makeResponsesAPICall(processedInput, responsesOptions);
10225
10292
  }
10226
10293
 
10294
+ const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
10295
+ const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
10227
10296
  const MULTIMODAL_VISION_MODELS = new Set([
10228
10297
  'gpt-4o-mini',
10229
10298
  'gpt-4o',
@@ -10272,7 +10341,8 @@ const MULTIMODAL_VISION_MODELS = new Set([
10272
10341
  * @throws Error if the API call fails or invalid parameters are provided
10273
10342
  */
10274
10343
  async function makeImagesCall(prompt, options = {}) {
10275
- const { size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10344
+ const { model, size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
10345
+ const imageModel = resolveImageModel(model);
10276
10346
  const supportedVisionModel = visionModel && MULTIMODAL_VISION_MODELS.has(visionModel) ? visionModel : undefined;
10277
10347
  if (visionModel && !supportedVisionModel) {
10278
10348
  console.warn(`Vision model ${visionModel} is not recognized as a multimodal OpenAI model. Ignoring for image usage metadata.`);
@@ -10297,7 +10367,7 @@ async function makeImagesCall(prompt, options = {}) {
10297
10367
  });
10298
10368
  // Build the request parameters using OpenAI's type
10299
10369
  const requestParams = {
10300
- model: 'gpt-image-1',
10370
+ model: imageModel,
10301
10371
  prompt,
10302
10372
  n: count || 1,
10303
10373
  size: size || 'auto',
@@ -10321,7 +10391,7 @@ async function makeImagesCall(prompt, options = {}) {
10321
10391
  throw new Error('No images returned from OpenAI Images API');
10322
10392
  }
10323
10393
  // Calculate cost
10324
- const cost = calculateImageCost('gpt-image-1', count || 1);
10394
+ const cost = calculateImageCost(imageModel, count || 1);
10325
10395
  // Return the response with enhanced usage information
10326
10396
  const enhancedResponse = {
10327
10397
  ...response,
@@ -10334,7 +10404,7 @@ async function makeImagesCall(prompt, options = {}) {
10334
10404
  total_tokens: 0,
10335
10405
  }),
10336
10406
  provider: 'openai',
10337
- model: 'gpt-image-1',
10407
+ model: imageModel,
10338
10408
  cost,
10339
10409
  ...(supportedVisionModel ? { visionModel: supportedVisionModel } : {}),
10340
10410
  },
@@ -19463,6 +19533,7 @@ const disco = {
19463
19533
  getNYTimeZone: getNYTimeZone,
19464
19534
  getTradingDate: getTradingDate,
19465
19535
  getTradingStartAndEndDates: getTradingStartAndEndDates,
19536
+ getTradingDaysBack: getTradingDaysBack,
19466
19537
  isMarketDay: isMarketDay,
19467
19538
  isWithinMarketHours: isWithinMarketHours,
19468
19539
  countTradingDays: countTradingDays,