@discomedia/utils 1.0.46 → 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/README.md +10 -1
- package/dist/index-frontend.cjs +151 -11
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +151 -11
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +151 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +151 -11
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +4 -4
- package/dist/test.js +292 -46
- 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 +6 -3
- package/dist/types/llm-images.d.ts.map +1 -1
- package/dist/types/llm-openai.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +34 -0
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types/types/llm-types.d.ts +10 -4
- package/dist/types/types/llm-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 +6 -3
- package/dist/types-frontend/llm-images.d.ts.map +1 -1
- package/dist/types-frontend/llm-openai.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +34 -0
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/dist/types-frontend/types/llm-types.d.ts +10 -4
- package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index-frontend.mjs
CHANGED
|
@@ -7,6 +7,10 @@ function isOpenRouterModel(model) {
|
|
|
7
7
|
'openai/gpt-5-mini',
|
|
8
8
|
'openai/gpt-5-nano',
|
|
9
9
|
'openai/gpt-5.1',
|
|
10
|
+
'openai/gpt-5.2',
|
|
11
|
+
'openai/gpt-5.2-pro',
|
|
12
|
+
'openai/gpt-5.1-codex',
|
|
13
|
+
'openai/gpt-5.1-codex-max',
|
|
10
14
|
'openai/gpt-oss-120b',
|
|
11
15
|
'z.ai/glm-4.5',
|
|
12
16
|
'z.ai/glm-4.5-air',
|
|
@@ -254,7 +258,7 @@ const safeJSON = (text) => {
|
|
|
254
258
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
255
259
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
260
|
|
|
257
|
-
const VERSION = '6.
|
|
261
|
+
const VERSION = '6.15.0'; // x-release-please-version
|
|
258
262
|
|
|
259
263
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
260
264
|
const isRunningInBrowser = () => {
|
|
@@ -6095,6 +6099,19 @@ class Responses extends APIResource {
|
|
|
6095
6099
|
cancel(responseID, options) {
|
|
6096
6100
|
return this._client.post(path `/responses/${responseID}/cancel`, options);
|
|
6097
6101
|
}
|
|
6102
|
+
/**
|
|
6103
|
+
* Compact conversation
|
|
6104
|
+
*
|
|
6105
|
+
* @example
|
|
6106
|
+
* ```ts
|
|
6107
|
+
* const compactedResponse = await client.responses.compact({
|
|
6108
|
+
* model: 'gpt-5.2',
|
|
6109
|
+
* });
|
|
6110
|
+
* ```
|
|
6111
|
+
*/
|
|
6112
|
+
compact(body, options) {
|
|
6113
|
+
return this._client.post('/responses/compact', { body, ...options });
|
|
6114
|
+
}
|
|
6098
6115
|
}
|
|
6099
6116
|
Responses.InputItems = InputItems;
|
|
6100
6117
|
Responses.InputTokens = InputTokens;
|
|
@@ -7237,6 +7254,22 @@ const openAiModelCosts = {
|
|
|
7237
7254
|
inputCost: 1.25 / 1_000_000,
|
|
7238
7255
|
outputCost: 10 / 1_000_000,
|
|
7239
7256
|
},
|
|
7257
|
+
'gpt-5.2': {
|
|
7258
|
+
inputCost: 1.5 / 1_000_000,
|
|
7259
|
+
outputCost: 12 / 1_000_000,
|
|
7260
|
+
},
|
|
7261
|
+
'gpt-5.2-pro': {
|
|
7262
|
+
inputCost: 3 / 1_000_000,
|
|
7263
|
+
outputCost: 24 / 1_000_000,
|
|
7264
|
+
},
|
|
7265
|
+
'gpt-5.1-codex': {
|
|
7266
|
+
inputCost: 1.1 / 1_000_000,
|
|
7267
|
+
outputCost: 8.8 / 1_000_000,
|
|
7268
|
+
},
|
|
7269
|
+
'gpt-5.1-codex-max': {
|
|
7270
|
+
inputCost: 1.8 / 1_000_000,
|
|
7271
|
+
outputCost: 14.4 / 1_000_000,
|
|
7272
|
+
},
|
|
7240
7273
|
'o4-mini': {
|
|
7241
7274
|
inputCost: 1.1 / 1_000_000,
|
|
7242
7275
|
outputCost: 4.4 / 1_000_000,
|
|
@@ -7257,6 +7290,7 @@ const deepseekModelCosts = {
|
|
|
7257
7290
|
/** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
|
|
7258
7291
|
const openAiImageCosts = {
|
|
7259
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
|
|
7260
7294
|
};
|
|
7261
7295
|
/**
|
|
7262
7296
|
* Calculates the cost of generating images using OpenAI's Images API.
|
|
@@ -7266,10 +7300,12 @@ const openAiImageCosts = {
|
|
|
7266
7300
|
* @returns The cost of generating the images in USD.
|
|
7267
7301
|
*/
|
|
7268
7302
|
function calculateImageCost(model, imageCount) {
|
|
7269
|
-
if (typeof imageCount !== 'number' || imageCount <= 0) {
|
|
7303
|
+
if (typeof model !== 'string' || typeof imageCount !== 'number' || imageCount <= 0) {
|
|
7270
7304
|
return 0;
|
|
7271
7305
|
}
|
|
7272
7306
|
const costPerImage = openAiImageCosts[model];
|
|
7307
|
+
if (!costPerImage)
|
|
7308
|
+
return 0;
|
|
7273
7309
|
return imageCount * costPerImage;
|
|
7274
7310
|
}
|
|
7275
7311
|
/**
|
|
@@ -7698,6 +7734,10 @@ const isSupportedModel = (model) => {
|
|
|
7698
7734
|
'gpt-5-mini',
|
|
7699
7735
|
'gpt-5-nano',
|
|
7700
7736
|
'gpt-5.1',
|
|
7737
|
+
'gpt-5.2',
|
|
7738
|
+
'gpt-5.2-pro',
|
|
7739
|
+
'gpt-5.1-codex',
|
|
7740
|
+
'gpt-5.1-codex-max',
|
|
7701
7741
|
'o4-mini',
|
|
7702
7742
|
'o3',
|
|
7703
7743
|
].includes(model);
|
|
@@ -7710,7 +7750,21 @@ const isSupportedModel = (model) => {
|
|
|
7710
7750
|
function supportsTemperature(model) {
|
|
7711
7751
|
// Reasoning models don't support temperature
|
|
7712
7752
|
// GPT-5 models also do not support temperature
|
|
7713
|
-
const reasoningAndGPT5Models = [
|
|
7753
|
+
const reasoningAndGPT5Models = [
|
|
7754
|
+
'o1',
|
|
7755
|
+
'o1-mini',
|
|
7756
|
+
'o3-mini',
|
|
7757
|
+
'o4-mini',
|
|
7758
|
+
'o3',
|
|
7759
|
+
'gpt-5',
|
|
7760
|
+
'gpt-5-mini',
|
|
7761
|
+
'gpt-5-nano',
|
|
7762
|
+
'gpt-5.1',
|
|
7763
|
+
'gpt-5.2',
|
|
7764
|
+
'gpt-5.2-pro',
|
|
7765
|
+
'gpt-5.1-codex',
|
|
7766
|
+
'gpt-5.1-codex-max',
|
|
7767
|
+
];
|
|
7714
7768
|
return !reasoningAndGPT5Models.includes(model);
|
|
7715
7769
|
}
|
|
7716
7770
|
/**
|
|
@@ -7728,7 +7782,16 @@ function isReasoningModel(model) {
|
|
|
7728
7782
|
* @returns True if the model is a GPT-5 model, false otherwise.
|
|
7729
7783
|
*/
|
|
7730
7784
|
function isGPT5Model(model) {
|
|
7731
|
-
const gpt5Models = [
|
|
7785
|
+
const gpt5Models = [
|
|
7786
|
+
'gpt-5',
|
|
7787
|
+
'gpt-5-mini',
|
|
7788
|
+
'gpt-5-nano',
|
|
7789
|
+
'gpt-5.1',
|
|
7790
|
+
'gpt-5.2',
|
|
7791
|
+
'gpt-5.2-pro',
|
|
7792
|
+
'gpt-5.1-codex',
|
|
7793
|
+
'gpt-5.1-codex-max',
|
|
7794
|
+
];
|
|
7732
7795
|
return gpt5Models.includes(model);
|
|
7733
7796
|
}
|
|
7734
7797
|
/**
|
|
@@ -7969,6 +8032,20 @@ async function makeLLMCall(input, options = {}) {
|
|
|
7969
8032
|
return await makeResponsesAPICall(processedInput, responsesOptions);
|
|
7970
8033
|
}
|
|
7971
8034
|
|
|
8035
|
+
const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
|
|
8036
|
+
const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
|
|
8037
|
+
const MULTIMODAL_VISION_MODELS = new Set([
|
|
8038
|
+
'gpt-4o-mini',
|
|
8039
|
+
'gpt-4o',
|
|
8040
|
+
'gpt-5',
|
|
8041
|
+
'gpt-5-mini',
|
|
8042
|
+
'gpt-5-nano',
|
|
8043
|
+
'gpt-5.1',
|
|
8044
|
+
'gpt-5.2',
|
|
8045
|
+
'gpt-5.2-pro',
|
|
8046
|
+
'gpt-5.1-codex',
|
|
8047
|
+
'gpt-5.1-codex-max',
|
|
8048
|
+
]);
|
|
7972
8049
|
/**
|
|
7973
8050
|
* Makes a call to the OpenAI Images API to generate images based on a text prompt.
|
|
7974
8051
|
*
|
|
@@ -8005,7 +8082,12 @@ async function makeLLMCall(input, options = {}) {
|
|
|
8005
8082
|
* @throws Error if the API call fails or invalid parameters are provided
|
|
8006
8083
|
*/
|
|
8007
8084
|
async function makeImagesCall(prompt, options = {}) {
|
|
8008
|
-
const { size = 'auto', outputFormat = 'webp', compression = 50, quality = 'high', count = 1, background = 'auto', moderation = 'auto', apiKey } = 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);
|
|
8087
|
+
const supportedVisionModel = visionModel && MULTIMODAL_VISION_MODELS.has(visionModel) ? visionModel : undefined;
|
|
8088
|
+
if (visionModel && !supportedVisionModel) {
|
|
8089
|
+
console.warn(`Vision model ${visionModel} is not recognized as a multimodal OpenAI model. Ignoring for image usage metadata.`);
|
|
8090
|
+
}
|
|
8009
8091
|
// Get API key
|
|
8010
8092
|
const effectiveApiKey = apiKey || process.env.OPENAI_API_KEY;
|
|
8011
8093
|
if (!effectiveApiKey) {
|
|
@@ -8026,7 +8108,7 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8026
8108
|
});
|
|
8027
8109
|
// Build the request parameters using OpenAI's type
|
|
8028
8110
|
const requestParams = {
|
|
8029
|
-
model:
|
|
8111
|
+
model: imageModel,
|
|
8030
8112
|
prompt,
|
|
8031
8113
|
n: count || 1,
|
|
8032
8114
|
size: size || 'auto',
|
|
@@ -8050,7 +8132,7 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8050
8132
|
throw new Error('No images returned from OpenAI Images API');
|
|
8051
8133
|
}
|
|
8052
8134
|
// Calculate cost
|
|
8053
|
-
const cost = calculateImageCost(
|
|
8135
|
+
const cost = calculateImageCost(imageModel, count || 1);
|
|
8054
8136
|
// Return the response with enhanced usage information
|
|
8055
8137
|
const enhancedResponse = {
|
|
8056
8138
|
...response,
|
|
@@ -8063,8 +8145,9 @@ async function makeImagesCall(prompt, options = {}) {
|
|
|
8063
8145
|
total_tokens: 0,
|
|
8064
8146
|
}),
|
|
8065
8147
|
provider: 'openai',
|
|
8066
|
-
model:
|
|
8148
|
+
model: imageModel,
|
|
8067
8149
|
cost,
|
|
8150
|
+
...(supportedVisionModel ? { visionModel: supportedVisionModel } : {}),
|
|
8068
8151
|
},
|
|
8069
8152
|
};
|
|
8070
8153
|
return enhancedResponse;
|
|
@@ -8765,9 +8848,10 @@ function getLastFullTradingDateImpl(currentDate = new Date()) {
|
|
|
8765
8848
|
if (calendar.isEarlyCloseDay(prevMarketDay)) {
|
|
8766
8849
|
prevCloseMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
|
|
8767
8850
|
}
|
|
8768
|
-
const
|
|
8769
|
-
const
|
|
8770
|
-
const
|
|
8851
|
+
const prevNYDate = toNYTime(prevMarketDay);
|
|
8852
|
+
const year = prevNYDate.getUTCFullYear();
|
|
8853
|
+
const month = prevNYDate.getUTCMonth();
|
|
8854
|
+
const day = prevNYDate.getUTCDate();
|
|
8771
8855
|
const closeHour = Math.floor(prevCloseMinutes / 60);
|
|
8772
8856
|
const closeMinute = prevCloseMinutes % 60;
|
|
8773
8857
|
return fromNYTime(new Date(Date.UTC(year, month, day, closeHour, closeMinute, 0, 0)));
|
|
@@ -9296,6 +9380,61 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
9296
9380
|
minutes: Math.round(minutes),
|
|
9297
9381
|
};
|
|
9298
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
|
+
*
|
|
9387
|
+
* @param options - Object with:
|
|
9388
|
+
* - referenceDate: Date to count back from (default: now)
|
|
9389
|
+
* - days: Number of trading days to go back (must be >= 1)
|
|
9390
|
+
* @returns Object containing:
|
|
9391
|
+
* - date: Trading date in YYYY-MM-DD format
|
|
9392
|
+
* - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
|
|
9393
|
+
* - unixTimestamp: Market open time as Unix timestamp in seconds
|
|
9394
|
+
* @example
|
|
9395
|
+
* ```typescript
|
|
9396
|
+
* // Get the trading day 1 day back (most recent full trading day)
|
|
9397
|
+
* const result = getTradingDaysBack({ days: 1 });
|
|
9398
|
+
* console.log(result.date); // "2025-11-01"
|
|
9399
|
+
* console.log(result.marketOpenISO); // "2025-11-01T13:30:00.000Z"
|
|
9400
|
+
* console.log(result.unixTimestamp); // 1730466600
|
|
9401
|
+
*
|
|
9402
|
+
* // Get the trading day 5 days back from a specific date
|
|
9403
|
+
* const result2 = getTradingDaysBack({
|
|
9404
|
+
* referenceDate: new Date('2025-11-15T12:00:00-05:00'),
|
|
9405
|
+
* days: 5
|
|
9406
|
+
* });
|
|
9407
|
+
* ```
|
|
9408
|
+
*/
|
|
9409
|
+
function getTradingDaysBack(options) {
|
|
9410
|
+
const calendar = new MarketCalendar();
|
|
9411
|
+
const refDate = options.referenceDate || new Date();
|
|
9412
|
+
const daysBack = options.days;
|
|
9413
|
+
if (daysBack < 1) {
|
|
9414
|
+
throw new Error('days must be at least 1');
|
|
9415
|
+
}
|
|
9416
|
+
// Start from the last full trading date relative to reference
|
|
9417
|
+
let targetDate = getLastFullTradingDateImpl(refDate);
|
|
9418
|
+
// Go back the specified number of days (we're already at day 1, so go back days-1 more)
|
|
9419
|
+
for (let i = 1; i < daysBack; i++) {
|
|
9420
|
+
targetDate = calendar.getPreviousMarketDay(targetDate);
|
|
9421
|
+
}
|
|
9422
|
+
// Get market open time for this date
|
|
9423
|
+
const marketTimes = getMarketTimes(targetDate);
|
|
9424
|
+
if (!marketTimes.open) {
|
|
9425
|
+
throw new Error(`No market open time for target date`);
|
|
9426
|
+
}
|
|
9427
|
+
// Format the date string (YYYY-MM-DD) in NY time
|
|
9428
|
+
const nyDate = toNYTime(marketTimes.open);
|
|
9429
|
+
const dateStr = `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
|
|
9430
|
+
const marketOpenISO = marketTimes.open.toISOString();
|
|
9431
|
+
const unixTimestamp = Math.floor(marketTimes.open.getTime() / 1000);
|
|
9432
|
+
return {
|
|
9433
|
+
date: dateStr,
|
|
9434
|
+
marketOpenISO,
|
|
9435
|
+
unixTimestamp,
|
|
9436
|
+
};
|
|
9437
|
+
}
|
|
9299
9438
|
// Export MARKET_TIMES for compatibility
|
|
9300
9439
|
const MARKET_TIMES = {
|
|
9301
9440
|
TIMEZONE: MARKET_CONFIG.TIMEZONE,
|
|
@@ -9342,6 +9481,7 @@ var time = /*#__PURE__*/Object.freeze({
|
|
|
9342
9481
|
getPreviousMarketDay: getPreviousMarketDay,
|
|
9343
9482
|
getStartAndEndDates: getStartAndEndDates,
|
|
9344
9483
|
getTradingDate: getTradingDate,
|
|
9484
|
+
getTradingDaysBack: getTradingDaysBack,
|
|
9345
9485
|
getTradingStartAndEndDates: getTradingStartAndEndDates,
|
|
9346
9486
|
isMarketDay: isMarketDay,
|
|
9347
9487
|
isWithinMarketHours: isWithinMarketHours
|