@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.
- package/dist/index-frontend.cjs +79 -8
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +79 -8
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +79 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +79 -8
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +4 -4
- package/dist/test.js +9122 -3789
- package/dist/test.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/llm-config.d.ts.map +1 -1
- package/dist/types/llm-images.d.ts +5 -3
- package/dist/types/llm-images.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +35 -1
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types/types/llm-types.d.ts +3 -1
- package/dist/types/types/llm-types.d.ts.map +1 -1
- package/dist/types/types/market-time-types.d.ts +5 -0
- package/dist/types/types/market-time-types.d.ts.map +1 -1
- package/dist/types-frontend/index.d.ts +1 -0
- package/dist/types-frontend/index.d.ts.map +1 -1
- package/dist/types-frontend/llm-config.d.ts.map +1 -1
- package/dist/types-frontend/llm-images.d.ts +5 -3
- package/dist/types-frontend/llm-images.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +35 -1
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/dist/types-frontend/types/llm-types.d.ts +3 -1
- package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
- package/dist/types-frontend/types/market-time-types.d.ts +5 -0
- package/dist/types-frontend/types/market-time-types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index-frontend.mjs
CHANGED
|
@@ -258,7 +258,7 @@ const safeJSON = (text) => {
|
|
|
258
258
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
259
259
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
260
260
|
|
|
261
|
-
const VERSION = '6.
|
|
261
|
+
const VERSION = '6.15.0'; // x-release-please-version
|
|
262
262
|
|
|
263
263
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
264
264
|
const isRunningInBrowser = () => {
|
|
@@ -6104,10 +6104,12 @@ class Responses extends APIResource {
|
|
|
6104
6104
|
*
|
|
6105
6105
|
* @example
|
|
6106
6106
|
* ```ts
|
|
6107
|
-
* const compactedResponse = await client.responses.compact(
|
|
6107
|
+
* const compactedResponse = await client.responses.compact({
|
|
6108
|
+
* model: 'gpt-5.2',
|
|
6109
|
+
* });
|
|
6108
6110
|
* ```
|
|
6109
6111
|
*/
|
|
6110
|
-
compact(body
|
|
6112
|
+
compact(body, options) {
|
|
6111
6113
|
return this._client.post('/responses/compact', { body, ...options });
|
|
6112
6114
|
}
|
|
6113
6115
|
}
|
|
@@ -7288,6 +7290,7 @@ const deepseekModelCosts = {
|
|
|
7288
7290
|
/** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
|
|
7289
7291
|
const openAiImageCosts = {
|
|
7290
7292
|
'gpt-image-1': 0.0075, // $0.0075 per image for gpt-image-1
|
|
7293
|
+
'gpt-image-1.5': 0.0075, // Assumes parity pricing with gpt-image-1 until OpenAI publishes updated rates
|
|
7291
7294
|
};
|
|
7292
7295
|
/**
|
|
7293
7296
|
* Calculates the cost of generating images using OpenAI's Images API.
|
|
@@ -7297,10 +7300,12 @@ const openAiImageCosts = {
|
|
|
7297
7300
|
* @returns The cost of generating the images in USD.
|
|
7298
7301
|
*/
|
|
7299
7302
|
function calculateImageCost(model, imageCount) {
|
|
7300
|
-
if (typeof imageCount !== 'number' || imageCount <= 0) {
|
|
7303
|
+
if (typeof model !== 'string' || typeof imageCount !== 'number' || imageCount <= 0) {
|
|
7301
7304
|
return 0;
|
|
7302
7305
|
}
|
|
7303
7306
|
const costPerImage = openAiImageCosts[model];
|
|
7307
|
+
if (!costPerImage)
|
|
7308
|
+
return 0;
|
|
7304
7309
|
return imageCount * costPerImage;
|
|
7305
7310
|
}
|
|
7306
7311
|
/**
|
|
@@ -8027,6 +8032,8 @@ async function makeLLMCall(input, options = {}) {
|
|
|
8027
8032
|
return await makeResponsesAPICall(processedInput, responsesOptions);
|
|
8028
8033
|
}
|
|
8029
8034
|
|
|
8035
|
+
const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
|
|
8036
|
+
const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
|
|
8030
8037
|
const MULTIMODAL_VISION_MODELS = new Set([
|
|
8031
8038
|
'gpt-4o-mini',
|
|
8032
8039
|
'gpt-4o',
|
|
@@ -8075,7 +8082,8 @@ const MULTIMODAL_VISION_MODELS = new Set([
|
|
|
8075
8082
|
* @throws Error if the API call fails or invalid parameters are provided
|
|
8076
8083
|
*/
|
|
8077
8084
|
async function makeImagesCall(prompt, options = {}) {
|
|
8078
|
-
const { size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
|
|
8085
|
+
const { model, size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey, visionModel, } = options;
|
|
8086
|
+
const imageModel = resolveImageModel(model);
|
|
8079
8087
|
const supportedVisionModel = visionModel && MULTIMODAL_VISION_MODELS.has(visionModel) ? visionModel : undefined;
|
|
8080
8088
|
if (visionModel && !supportedVisionModel) {
|
|
8081
8089
|
console.warn(`Vision model ${visionModel} is not recognized as a multimodal OpenAI model. Ignoring for image usage metadata.`);
|
|
@@ -8100,7 +8108,7 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8100
8108
|
});
|
|
8101
8109
|
// Build the request parameters using OpenAI's type
|
|
8102
8110
|
const requestParams = {
|
|
8103
|
-
model:
|
|
8111
|
+
model: imageModel,
|
|
8104
8112
|
prompt,
|
|
8105
8113
|
n: count || 1,
|
|
8106
8114
|
size: size || 'auto',
|
|
@@ -8124,7 +8132,7 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8124
8132
|
throw new Error('No images returned from OpenAI Images API');
|
|
8125
8133
|
}
|
|
8126
8134
|
// Calculate cost
|
|
8127
|
-
const cost = calculateImageCost(
|
|
8135
|
+
const cost = calculateImageCost(imageModel, count || 1);
|
|
8128
8136
|
// Return the response with enhanced usage information
|
|
8129
8137
|
const enhancedResponse = {
|
|
8130
8138
|
...response,
|
|
@@ -8137,7 +8145,7 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8137
8145
|
total_tokens: 0,
|
|
8138
8146
|
}),
|
|
8139
8147
|
provider: 'openai',
|
|
8140
|
-
model:
|
|
8148
|
+
model: imageModel,
|
|
8141
8149
|
cost,
|
|
8142
8150
|
...(supportedVisionModel ? { visionModel: supportedVisionModel } : {}),
|
|
8143
8151
|
},
|
|
@@ -9372,6 +9380,68 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
9372
9380
|
minutes: Math.round(minutes),
|
|
9373
9381
|
};
|
|
9374
9382
|
}
|
|
9383
|
+
/**
|
|
9384
|
+
* Returns the trading day N days back from a reference date, along with its market open time.
|
|
9385
|
+
* Trading days are counted as full or half trading days (days that end count as 1 full trading day).
|
|
9386
|
+
* By default, the most recent completed trading day counts as day 1.
|
|
9387
|
+
* Set includeMostRecentFullDay to false to count strictly before that day.
|
|
9388
|
+
*
|
|
9389
|
+
* @param options - Object with:
|
|
9390
|
+
* - referenceDate: Date to count back from (default: now)
|
|
9391
|
+
* - days: Number of trading days to go back (must be an integer >= 1)
|
|
9392
|
+
* - includeMostRecentFullDay: Whether to include the most recent completed trading day (default: true)
|
|
9393
|
+
* @returns Object containing:
|
|
9394
|
+
* - date: Trading date in YYYY-MM-DD format
|
|
9395
|
+
* - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
|
|
9396
|
+
* - unixTimestamp: Market open time as Unix timestamp in seconds
|
|
9397
|
+
* @example
|
|
9398
|
+
* ```typescript
|
|
9399
|
+
* // Get the trading day 1 day back (most recent full trading day)
|
|
9400
|
+
* const result = getTradingDaysBack({ days: 1 });
|
|
9401
|
+
* console.log(result.date); // "2025-11-01"
|
|
9402
|
+
* console.log(result.marketOpenISO); // "2025-11-01T13:30:00.000Z"
|
|
9403
|
+
* console.log(result.unixTimestamp); // 1730466600
|
|
9404
|
+
*
|
|
9405
|
+
* // Get the trading day 5 days back from a specific date
|
|
9406
|
+
* const result2 = getTradingDaysBack({
|
|
9407
|
+
* referenceDate: new Date('2025-11-15T12:00:00-05:00'),
|
|
9408
|
+
* days: 5
|
|
9409
|
+
* });
|
|
9410
|
+
* ```
|
|
9411
|
+
*/
|
|
9412
|
+
function getTradingDaysBack(options) {
|
|
9413
|
+
const calendar = new MarketCalendar();
|
|
9414
|
+
const { referenceDate, days, includeMostRecentFullDay = true } = options;
|
|
9415
|
+
const refDate = referenceDate || new Date();
|
|
9416
|
+
const daysBack = days;
|
|
9417
|
+
if (!Number.isInteger(daysBack) || daysBack < 1) {
|
|
9418
|
+
throw new Error('days must be an integer >= 1');
|
|
9419
|
+
}
|
|
9420
|
+
// Start from the last full trading date relative to reference
|
|
9421
|
+
let targetDate = getLastFullTradingDateImpl(refDate);
|
|
9422
|
+
if (!includeMostRecentFullDay) {
|
|
9423
|
+
targetDate = calendar.getPreviousMarketDay(targetDate);
|
|
9424
|
+
}
|
|
9425
|
+
// Go back the specified number of days (we're already at day 1, so go back days-1 more)
|
|
9426
|
+
for (let i = 1; i < daysBack; i++) {
|
|
9427
|
+
targetDate = calendar.getPreviousMarketDay(targetDate);
|
|
9428
|
+
}
|
|
9429
|
+
// Get market open time for this date
|
|
9430
|
+
const marketTimes = getMarketTimes(targetDate);
|
|
9431
|
+
if (!marketTimes.open) {
|
|
9432
|
+
throw new Error(`No market open time for target date`);
|
|
9433
|
+
}
|
|
9434
|
+
// Format the date string (YYYY-MM-DD) in NY time
|
|
9435
|
+
const nyDate = toNYTime(marketTimes.open);
|
|
9436
|
+
const dateStr = `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
|
|
9437
|
+
const marketOpenISO = marketTimes.open.toISOString();
|
|
9438
|
+
const unixTimestamp = Math.floor(marketTimes.open.getTime() / 1000);
|
|
9439
|
+
return {
|
|
9440
|
+
date: dateStr,
|
|
9441
|
+
marketOpenISO,
|
|
9442
|
+
unixTimestamp,
|
|
9443
|
+
};
|
|
9444
|
+
}
|
|
9375
9445
|
// Export MARKET_TIMES for compatibility
|
|
9376
9446
|
const MARKET_TIMES = {
|
|
9377
9447
|
TIMEZONE: MARKET_CONFIG.TIMEZONE,
|
|
@@ -9418,6 +9488,7 @@ var time = /*#__PURE__*/Object.freeze({
|
|
|
9418
9488
|
getPreviousMarketDay: getPreviousMarketDay,
|
|
9419
9489
|
getStartAndEndDates: getStartAndEndDates,
|
|
9420
9490
|
getTradingDate: getTradingDate,
|
|
9491
|
+
getTradingDaysBack: getTradingDaysBack,
|
|
9421
9492
|
getTradingStartAndEndDates: getTradingStartAndEndDates,
|
|
9422
9493
|
isMarketDay: isMarketDay,
|
|
9423
9494
|
isWithinMarketHours: isWithinMarketHours
|