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