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