@discomedia/utils 1.0.68 → 1.0.69

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 +40 -185
  2. package/dist/index-frontend.cjs.map +1 -1
  3. package/dist/index-frontend.mjs +38 -186
  4. package/dist/index-frontend.mjs.map +1 -1
  5. package/dist/index.cjs +40 -185
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.mjs +38 -186
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/package.json +1 -1
  10. package/dist/test.js +82 -194
  11. package/dist/test.js.map +1 -1
  12. package/dist/types/index-frontend.d.ts +1 -0
  13. package/dist/types/index-frontend.d.ts.map +1 -1
  14. package/dist/types/index.d.ts +1 -0
  15. package/dist/types/index.d.ts.map +1 -1
  16. package/dist/types/llm-config.d.ts +1 -1
  17. package/dist/types/llm-config.d.ts.map +1 -1
  18. package/dist/types/llm-images.d.ts.map +1 -1
  19. package/dist/types/llm-openai.d.ts +4 -16
  20. package/dist/types/llm-openai.d.ts.map +1 -1
  21. package/dist/types/types/llm-types.d.ts +6 -1
  22. package/dist/types/types/llm-types.d.ts.map +1 -1
  23. package/dist/types-frontend/index-frontend.d.ts +1 -0
  24. package/dist/types-frontend/index-frontend.d.ts.map +1 -1
  25. package/dist/types-frontend/index.d.ts +1 -0
  26. package/dist/types-frontend/index.d.ts.map +1 -1
  27. package/dist/types-frontend/llm-config.d.ts +1 -1
  28. package/dist/types-frontend/llm-config.d.ts.map +1 -1
  29. package/dist/types-frontend/llm-images.d.ts.map +1 -1
  30. package/dist/types-frontend/llm-openai.d.ts +4 -16
  31. package/dist/types-frontend/llm-openai.d.ts.map +1 -1
  32. package/dist/types-frontend/types/llm-types.d.ts +6 -1
  33. package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
  34. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1139,6 +1139,29 @@ function dateTimeForGS(date) {
1139
1139
  .replace(/\./g, '/');
1140
1140
  }
1141
1141
 
1142
+ /**
1143
+ * Represents OpenAI models
1144
+ */
1145
+ const OPENAI_MODELS = [
1146
+ 'gpt-5',
1147
+ 'gpt-5-mini',
1148
+ 'gpt-5.4-mini',
1149
+ 'gpt-5-nano',
1150
+ 'gpt-5.1',
1151
+ 'gpt-5.4',
1152
+ 'gpt-5.5',
1153
+ 'gpt-5.5-pro',
1154
+ 'gpt-5.2',
1155
+ 'gpt-5.2-pro',
1156
+ 'gpt-5.1-codex',
1157
+ 'gpt-5.1-codex-max',
1158
+ ];
1159
+ /**
1160
+ * Type guard to check if a model is a supported direct OpenAI model.
1161
+ */
1162
+ function isOpenAIModel(model) {
1163
+ return OPENAI_MODELS.includes(model);
1164
+ }
1142
1165
  /**
1143
1166
  * Type guard to check if a model is an OpenRouter model
1144
1167
  */
@@ -1170,6 +1193,8 @@ function isOpenRouterModel(model) {
1170
1193
 
1171
1194
  var Types = /*#__PURE__*/Object.freeze({
1172
1195
  __proto__: null,
1196
+ OPENAI_MODELS: OPENAI_MODELS,
1197
+ isOpenAIModel: isOpenAIModel,
1173
1198
  isOpenRouterModel: isOpenRouterModel
1174
1199
  });
1175
1200
 
@@ -11596,57 +11621,12 @@ function zodTextFormat(zodObject, name, props) {
11596
11621
  }
11597
11622
 
11598
11623
  // llm-openai-config.ts
11599
- const DEFAULT_MODEL = 'gpt-4.1-mini';
11624
+ const DEFAULT_MODEL = 'gpt-5-mini';
11600
11625
  const GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
11601
11626
  const GPT_5_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
11602
11627
  const GPT_5_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
11603
11628
  /** Token costs in USD per 1M tokens. Last updated May 2026. */
11604
11629
  const openAiModelCosts = {
11605
- 'gpt-4o': {
11606
- inputCost: 2.5 / 1_000_000,
11607
- cacheHitCost: 1.25 / 1_000_000,
11608
- outputCost: 10 / 1_000_000,
11609
- },
11610
- 'gpt-4o-mini': {
11611
- inputCost: 0.15 / 1_000_000,
11612
- cacheHitCost: 0.075 / 1_000_000,
11613
- outputCost: 0.6 / 1_000_000,
11614
- },
11615
- 'o1-mini': {
11616
- inputCost: 1.1 / 1_000_000,
11617
- cacheHitCost: 0.55 / 1_000_000,
11618
- outputCost: 4.4 / 1_000_000,
11619
- },
11620
- 'o1': {
11621
- inputCost: 15 / 1_000_000,
11622
- cacheHitCost: 7.5 / 1_000_000,
11623
- outputCost: 60 / 1_000_000,
11624
- },
11625
- 'o3-mini': {
11626
- inputCost: 1.1 / 1_000_000,
11627
- cacheHitCost: 0.55 / 1_000_000,
11628
- outputCost: 4.4 / 1_000_000,
11629
- },
11630
- 'o3': {
11631
- inputCost: 2 / 1_000_000,
11632
- cacheHitCost: 0.5 / 1_000_000,
11633
- outputCost: 8 / 1_000_000,
11634
- },
11635
- 'gpt-4.1': {
11636
- inputCost: 2 / 1_000_000,
11637
- cacheHitCost: 0.5 / 1_000_000,
11638
- outputCost: 8 / 1_000_000,
11639
- },
11640
- 'gpt-4.1-mini': {
11641
- inputCost: 0.4 / 1_000_000,
11642
- cacheHitCost: 0.1 / 1_000_000,
11643
- outputCost: 1.6 / 1_000_000,
11644
- },
11645
- 'gpt-4.1-nano': {
11646
- inputCost: 0.1 / 1_000_000,
11647
- cacheHitCost: 0.025 / 1_000_000,
11648
- outputCost: 0.4 / 1_000_000,
11649
- },
11650
11630
  'gpt-5': {
11651
11631
  inputCost: 1.25 / 1_000_000,
11652
11632
  cacheHitCost: 0.125 / 1_000_000,
@@ -11677,10 +11657,6 @@ const openAiModelCosts = {
11677
11657
  cacheHitCost: 0.25 / 1_000_000,
11678
11658
  outputCost: 15 / 1_000_000,
11679
11659
  },
11680
- 'gpt-5.4-pro': {
11681
- inputCost: 30 / 1_000_000,
11682
- outputCost: 180 / 1_000_000,
11683
- },
11684
11660
  'gpt-5.5': {
11685
11661
  inputCost: 5 / 1_000_000,
11686
11662
  cacheHitCost: 0.5 / 1_000_000,
@@ -11709,11 +11685,6 @@ const openAiModelCosts = {
11709
11685
  cacheHitCost: 0.125 / 1_000_000,
11710
11686
  outputCost: 10 / 1_000_000,
11711
11687
  },
11712
- 'o4-mini': {
11713
- inputCost: 1.1 / 1_000_000,
11714
- cacheHitCost: 0.275 / 1_000_000,
11715
- outputCost: 4.4 / 1_000_000,
11716
- },
11717
11688
  };
11718
11689
  const deepseekModelCosts = {
11719
11690
  'deepseek-chat': {
@@ -11728,8 +11699,7 @@ const deepseekModelCosts = {
11728
11699
  },
11729
11700
  };
11730
11701
  function shouldUseGPT5HighContextPricing(model, inputTokens) {
11731
- return ((model === 'gpt-5.4' || model === 'gpt-5.4-pro' || model === 'gpt-5.5') &&
11732
- inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS);
11702
+ return (model === 'gpt-5.4' || model === 'gpt-5.5') && inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS;
11733
11703
  }
11734
11704
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
11735
11705
  const openAiImageCosts = {
@@ -12170,100 +12140,13 @@ async function parseResponse(content, responseFormat) {
12170
12140
  }
12171
12141
 
12172
12142
  // llm-openai.ts
12173
- const isSupportedModel = (model) => {
12174
- return [
12175
- 'gpt-4o-mini',
12176
- 'gpt-4o',
12177
- 'o1-mini',
12178
- 'o1',
12179
- 'o3-mini',
12180
- 'gpt-4.1',
12181
- 'gpt-4.1-mini',
12182
- 'gpt-4.1-nano',
12183
- 'gpt-5',
12184
- 'gpt-5-mini',
12185
- 'gpt-5.4-mini',
12186
- 'gpt-5-nano',
12187
- 'gpt-5.1',
12188
- 'gpt-5.4',
12189
- 'gpt-5.4-pro',
12190
- 'gpt-5.5',
12191
- 'gpt-5.5-pro',
12192
- 'gpt-5.2',
12193
- 'gpt-5.2-pro',
12194
- 'gpt-5.1-codex',
12195
- 'gpt-5.1-codex-max',
12196
- 'o4-mini',
12197
- 'o3',
12198
- ].includes(model);
12199
- };
12200
12143
  /**
12201
- * Checks if the given model supports the temperature parameter. Reasoning models (o1*, o3*, o4*) do not support temperature.
12144
+ * Checks if the given direct OpenAI model supports the temperature parameter.
12202
12145
  * @param model The model to check.
12203
12146
  * @returns True if the model supports the temperature parameter, false otherwise.
12204
12147
  */
12205
- function supportsTemperature(model) {
12206
- // Reasoning models don't support temperature
12207
- // GPT-5 models also do not support temperature
12208
- const reasoningAndGPT5Models = [
12209
- 'o1',
12210
- 'o1-mini',
12211
- 'o3-mini',
12212
- 'o4-mini',
12213
- 'o3',
12214
- 'gpt-5',
12215
- 'gpt-5-mini',
12216
- 'gpt-5.4-mini',
12217
- 'gpt-5-nano',
12218
- 'gpt-5.1',
12219
- 'gpt-5.4',
12220
- 'gpt-5.4-pro',
12221
- 'gpt-5.5',
12222
- 'gpt-5.5-pro',
12223
- 'gpt-5.2',
12224
- 'gpt-5.2-pro',
12225
- 'gpt-5.1-codex',
12226
- 'gpt-5.1-codex-max',
12227
- ];
12228
- return !reasoningAndGPT5Models.includes(model);
12229
- }
12230
- /**
12231
- * Checks if the given model is a reasoning model. Reasoning models have different tool choice constraints.
12232
- * @param model The model to check.
12233
- * @returns True if the model is a reasoning model, false otherwise.
12234
- */
12235
- function isReasoningModel(model) {
12236
- const reasoningModels = ['o1', 'o1-mini', 'o3-mini', 'o4-mini', 'o3'];
12237
- return reasoningModels.includes(model);
12238
- }
12239
- /**
12240
- * Checks if the given model is a GPT-5 model. GPT-5 models don't support tool_choice other than 'auto'.
12241
- * @param model The model to check.
12242
- * @returns True if the model is a GPT-5 model, false otherwise.
12243
- */
12244
- function isGPT5Model(model) {
12245
- const gpt5Models = [
12246
- 'gpt-5',
12247
- 'gpt-5-mini',
12248
- 'gpt-5.4-mini',
12249
- 'gpt-5-nano',
12250
- 'gpt-5.1',
12251
- 'gpt-5.4',
12252
- 'gpt-5.4-pro',
12253
- 'gpt-5.5',
12254
- 'gpt-5.5-pro',
12255
- 'gpt-5.2',
12256
- 'gpt-5.2-pro',
12257
- 'gpt-5.1-codex',
12258
- 'gpt-5.1-codex-max',
12259
- ];
12260
- return gpt5Models.includes(model);
12261
- }
12262
- function supportsStructuredOutputs(model) {
12263
- return normalizeModelName(model) !== 'gpt-5.4-pro';
12264
- }
12265
- function supportsDistillation(model) {
12266
- return normalizeModelName(model) !== 'gpt-5.4-pro';
12148
+ function supportsTemperature(_model) {
12149
+ return false;
12267
12150
  }
12268
12151
  function isZodSchema(schema) {
12269
12152
  return typeof schema === 'object' && schema !== null && 'safeParse' in schema;
@@ -12298,7 +12181,7 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
12298
12181
  * - Built-in tools (web search, file search, computer use, code interpreter, image generation)
12299
12182
  * - Background processing
12300
12183
  * - Conversation state management
12301
- * - Reasoning support for o-series models
12184
+ * - GPT-5 reasoning controls
12302
12185
  *
12303
12186
  * @example
12304
12187
  * // Basic text response
@@ -12319,6 +12202,9 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
12319
12202
  */
12320
12203
  const makeResponsesAPICall = async (input, options = {}) => {
12321
12204
  const normalizedModel = normalizeModelName(options.model || DEFAULT_MODEL);
12205
+ if (!isOpenAIModel(normalizedModel)) {
12206
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
12207
+ }
12322
12208
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY;
12323
12209
  if (!apiKey) {
12324
12210
  throw new Error('OpenAI API key is not provided and OPENAI_API_KEY environment variable is not set');
@@ -12333,12 +12219,6 @@ const makeResponsesAPICall = async (input, options = {}) => {
12333
12219
  input,
12334
12220
  ...cleanOptions,
12335
12221
  };
12336
- if (requestBody.text?.format?.type === 'json_schema' && !supportsStructuredOutputs(normalizedModel)) {
12337
- throw new Error(`Model ${normalizedModel} does not support structured outputs`);
12338
- }
12339
- if (requestBody.store && !supportsDistillation(normalizedModel)) {
12340
- throw new Error(`Model ${normalizedModel} does not support distillation`);
12341
- }
12342
12222
  // Make the API call to the Responses endpoint
12343
12223
  const response = await openai.responses.create(requestBody);
12344
12224
  const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
@@ -12445,8 +12325,8 @@ async function makeLLMCall(input, options = {}) {
12445
12325
  const { apiKey, model = DEFAULT_MODEL, responseFormat = 'text', schema, schemaName = 'response', schemaDescription, schemaStrict, tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context, } = options;
12446
12326
  // Validate model
12447
12327
  const normalizedModel = normalizeModelName(model);
12448
- if (!isSupportedModel(normalizedModel)) {
12449
- throw new Error(`Unsupported model: ${normalizedModel}. Please use one of the supported models.`);
12328
+ if (!isOpenAIModel(normalizedModel)) {
12329
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
12450
12330
  }
12451
12331
  // Process input for conversation context and image analysis
12452
12332
  let processedInput;
@@ -12515,10 +12395,6 @@ async function makeLLMCall(input, options = {}) {
12515
12395
  parallel_tool_calls: false,
12516
12396
  tools,
12517
12397
  };
12518
- // Only include temperature if the model supports it
12519
- if (supportsTemperature(normalizedModel)) {
12520
- responsesOptions.temperature = 0.2;
12521
- }
12522
12398
  // Configure response format
12523
12399
  if (schema) {
12524
12400
  responsesOptions.text = {
@@ -12534,41 +12410,17 @@ async function makeLLMCall(input, options = {}) {
12534
12410
  // Configure built-in tools
12535
12411
  if (useCodeInterpreter) {
12536
12412
  responsesOptions.tools = [{ type: 'code_interpreter', container: { type: 'auto' } }];
12537
- // For reasoning models, we can't force tool choice - they only support 'auto'
12538
- if (!isReasoningModel(normalizedModel)) {
12539
- responsesOptions.tool_choice = { type: 'code_interpreter' };
12540
- }
12541
12413
  responsesOptions.include = ['code_interpreter_call.outputs'];
12542
12414
  }
12543
12415
  if (useWebSearch) {
12544
12416
  responsesOptions.tools = [{ type: 'web_search_preview' }];
12545
- // For reasoning models and GPT-5 models, we can't force tool choice - they only support 'auto'
12546
- if (!isReasoningModel(normalizedModel) && !isGPT5Model(normalizedModel)) {
12547
- responsesOptions.tool_choice = { type: 'web_search_preview' };
12548
- }
12549
12417
  }
12550
12418
  return await makeResponsesAPICall(processedInput, responsesOptions);
12551
12419
  }
12552
12420
 
12553
12421
  const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
12554
12422
  const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
12555
- const MULTIMODAL_VISION_MODELS = new Set([
12556
- 'gpt-4o-mini',
12557
- 'gpt-4o',
12558
- 'gpt-5',
12559
- 'gpt-5-mini',
12560
- 'gpt-5.4-mini',
12561
- 'gpt-5-nano',
12562
- 'gpt-5.1',
12563
- 'gpt-5.4',
12564
- 'gpt-5.4-pro',
12565
- 'gpt-5.5',
12566
- 'gpt-5.5-pro',
12567
- 'gpt-5.2',
12568
- 'gpt-5.2-pro',
12569
- 'gpt-5.1-codex',
12570
- 'gpt-5.1-codex-max',
12571
- ]);
12423
+ const MULTIMODAL_VISION_MODELS = new Set(OPENAI_MODELS);
12572
12424
  /**
12573
12425
  * Makes a call to the OpenAI Images API to generate images based on a text prompt.
12574
12426
  *
@@ -21710,5 +21562,5 @@ const disco = {
21710
21562
  },
21711
21563
  };
21712
21564
 
21713
- export { AlpacaMarketDataAPI, AlpacaTradingAPI, disco, isOpenRouterModel };
21565
+ export { AlpacaMarketDataAPI, AlpacaTradingAPI, OPENAI_MODELS, disco, isOpenAIModel, isOpenRouterModel, supportsTemperature };
21714
21566
  //# sourceMappingURL=index.mjs.map