@discomedia/utils 1.0.68 → 1.0.70

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 +68 -208
  2. package/dist/index-frontend.cjs.map +1 -1
  3. package/dist/index-frontend.mjs +65 -209
  4. package/dist/index-frontend.mjs.map +1 -1
  5. package/dist/index.cjs +68 -208
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.mjs +65 -209
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/package.json +1 -1
  10. package/dist/test.js +119 -217
  11. package/dist/test.js.map +1 -1
  12. package/dist/types/index-frontend.d.ts +2 -0
  13. package/dist/types/index-frontend.d.ts.map +1 -1
  14. package/dist/types/index.d.ts +2 -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 +8 -2
  22. package/dist/types/types/llm-types.d.ts.map +1 -1
  23. package/dist/types-frontend/index-frontend.d.ts +2 -0
  24. package/dist/types-frontend/index-frontend.d.ts.map +1 -1
  25. package/dist/types-frontend/index.d.ts +2 -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 +8 -2
  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,37 +1141,66 @@ 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
+ }
1167
+ /**
1168
+ * Represents OpenRouter models
1169
+ */
1170
+ const OPENROUTER_MODELS = [
1171
+ 'openai/gpt-5',
1172
+ 'openai/gpt-5-mini',
1173
+ 'openai/gpt-5.4-mini',
1174
+ 'openai/gpt-5-nano',
1175
+ 'openai/gpt-5.1',
1176
+ 'openai/gpt-5.4',
1177
+ 'openai/gpt-5.4-pro',
1178
+ 'openai/gpt-5.5',
1179
+ 'openai/gpt-5.5-pro',
1180
+ 'openai/gpt-5.2',
1181
+ 'openai/gpt-5.2-pro',
1182
+ 'openai/gpt-5.1-codex',
1183
+ 'openai/gpt-5.1-codex-max',
1184
+ 'openai/gpt-oss-120b',
1185
+ 'z.ai/glm-4.5',
1186
+ 'z.ai/glm-4.5-air',
1187
+ 'google/gemini-2.5-flash',
1188
+ 'google/gemini-2.5-flash-lite',
1189
+ 'deepseek/deepseek-r1-0528',
1190
+ 'deepseek/deepseek-chat-v3-0324',
1191
+ ];
1144
1192
  /**
1145
1193
  * Type guard to check if a model is an OpenRouter model
1146
1194
  */
1147
1195
  function isOpenRouterModel(model) {
1148
- const openRouterModels = [
1149
- 'openai/gpt-5',
1150
- 'openai/gpt-5-mini',
1151
- 'openai/gpt-5.4-mini',
1152
- 'openai/gpt-5-nano',
1153
- 'openai/gpt-5.1',
1154
- 'openai/gpt-5.4',
1155
- 'openai/gpt-5.4-pro',
1156
- 'openai/gpt-5.5',
1157
- 'openai/gpt-5.5-pro',
1158
- 'openai/gpt-5.2',
1159
- 'openai/gpt-5.2-pro',
1160
- 'openai/gpt-5.1-codex',
1161
- 'openai/gpt-5.1-codex-max',
1162
- 'openai/gpt-oss-120b',
1163
- 'z.ai/glm-4.5',
1164
- 'z.ai/glm-4.5-air',
1165
- 'google/gemini-2.5-flash',
1166
- 'google/gemini-2.5-flash-lite',
1167
- 'deepseek/deepseek-r1-0528',
1168
- 'deepseek/deepseek-chat-v3-0324',
1169
- ];
1170
- return openRouterModels.includes(model);
1196
+ return OPENROUTER_MODELS.includes(model);
1171
1197
  }
1172
1198
 
1173
1199
  var Types = /*#__PURE__*/Object.freeze({
1174
1200
  __proto__: null,
1201
+ OPENAI_MODELS: OPENAI_MODELS,
1202
+ OPENROUTER_MODELS: OPENROUTER_MODELS,
1203
+ isOpenAIModel: isOpenAIModel,
1175
1204
  isOpenRouterModel: isOpenRouterModel
1176
1205
  });
1177
1206
 
@@ -11598,57 +11627,12 @@ function zodTextFormat(zodObject, name, props) {
11598
11627
  }
11599
11628
 
11600
11629
  // llm-openai-config.ts
11601
- const DEFAULT_MODEL = 'gpt-4.1-mini';
11630
+ const DEFAULT_MODEL = 'gpt-5-mini';
11602
11631
  const GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
11603
11632
  const GPT_5_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
11604
11633
  const GPT_5_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
11605
11634
  /** Token costs in USD per 1M tokens. Last updated May 2026. */
11606
11635
  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
11636
  'gpt-5': {
11653
11637
  inputCost: 1.25 / 1_000_000,
11654
11638
  cacheHitCost: 0.125 / 1_000_000,
@@ -11679,10 +11663,6 @@ const openAiModelCosts = {
11679
11663
  cacheHitCost: 0.25 / 1_000_000,
11680
11664
  outputCost: 15 / 1_000_000,
11681
11665
  },
11682
- 'gpt-5.4-pro': {
11683
- inputCost: 30 / 1_000_000,
11684
- outputCost: 180 / 1_000_000,
11685
- },
11686
11666
  'gpt-5.5': {
11687
11667
  inputCost: 5 / 1_000_000,
11688
11668
  cacheHitCost: 0.5 / 1_000_000,
@@ -11711,11 +11691,6 @@ const openAiModelCosts = {
11711
11691
  cacheHitCost: 0.125 / 1_000_000,
11712
11692
  outputCost: 10 / 1_000_000,
11713
11693
  },
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
11694
  };
11720
11695
  const deepseekModelCosts = {
11721
11696
  'deepseek-chat': {
@@ -11730,8 +11705,7 @@ const deepseekModelCosts = {
11730
11705
  },
11731
11706
  };
11732
11707
  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);
11708
+ return (model === 'gpt-5.4' || model === 'gpt-5.5') && inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS;
11735
11709
  }
11736
11710
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
11737
11711
  const openAiImageCosts = {
@@ -12172,100 +12146,13 @@ async function parseResponse(content, responseFormat) {
12172
12146
  }
12173
12147
 
12174
12148
  // 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
12149
  /**
12203
- * Checks if the given model supports the temperature parameter. Reasoning models (o1*, o3*, o4*) do not support temperature.
12150
+ * Checks if the given direct OpenAI model supports the temperature parameter.
12204
12151
  * @param model The model to check.
12205
12152
  * @returns True if the model supports the temperature parameter, false otherwise.
12206
12153
  */
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';
12154
+ function supportsTemperature(_model) {
12155
+ return false;
12269
12156
  }
12270
12157
  function isZodSchema(schema) {
12271
12158
  return typeof schema === 'object' && schema !== null && 'safeParse' in schema;
@@ -12300,7 +12187,7 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
12300
12187
  * - Built-in tools (web search, file search, computer use, code interpreter, image generation)
12301
12188
  * - Background processing
12302
12189
  * - Conversation state management
12303
- * - Reasoning support for o-series models
12190
+ * - GPT-5 reasoning controls
12304
12191
  *
12305
12192
  * @example
12306
12193
  * // Basic text response
@@ -12321,6 +12208,9 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
12321
12208
  */
12322
12209
  const makeResponsesAPICall = async (input, options = {}) => {
12323
12210
  const normalizedModel = normalizeModelName(options.model || DEFAULT_MODEL);
12211
+ if (!isOpenAIModel(normalizedModel)) {
12212
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
12213
+ }
12324
12214
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY;
12325
12215
  if (!apiKey) {
12326
12216
  throw new Error('OpenAI API key is not provided and OPENAI_API_KEY environment variable is not set');
@@ -12335,12 +12225,6 @@ const makeResponsesAPICall = async (input, options = {}) => {
12335
12225
  input,
12336
12226
  ...cleanOptions,
12337
12227
  };
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
12228
  // Make the API call to the Responses endpoint
12345
12229
  const response = await openai.responses.create(requestBody);
12346
12230
  const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
@@ -12447,8 +12331,8 @@ async function makeLLMCall(input, options = {}) {
12447
12331
  const { apiKey, model = DEFAULT_MODEL, responseFormat = 'text', schema, schemaName = 'response', schemaDescription, schemaStrict, tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context, } = options;
12448
12332
  // Validate model
12449
12333
  const normalizedModel = normalizeModelName(model);
12450
- if (!isSupportedModel(normalizedModel)) {
12451
- throw new Error(`Unsupported model: ${normalizedModel}. Please use one of the supported models.`);
12334
+ if (!isOpenAIModel(normalizedModel)) {
12335
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
12452
12336
  }
12453
12337
  // Process input for conversation context and image analysis
12454
12338
  let processedInput;
@@ -12517,10 +12401,6 @@ async function makeLLMCall(input, options = {}) {
12517
12401
  parallel_tool_calls: false,
12518
12402
  tools,
12519
12403
  };
12520
- // Only include temperature if the model supports it
12521
- if (supportsTemperature(normalizedModel)) {
12522
- responsesOptions.temperature = 0.2;
12523
- }
12524
12404
  // Configure response format
12525
12405
  if (schema) {
12526
12406
  responsesOptions.text = {
@@ -12536,41 +12416,17 @@ async function makeLLMCall(input, options = {}) {
12536
12416
  // Configure built-in tools
12537
12417
  if (useCodeInterpreter) {
12538
12418
  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
12419
  responsesOptions.include = ['code_interpreter_call.outputs'];
12544
12420
  }
12545
12421
  if (useWebSearch) {
12546
12422
  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
12423
  }
12552
12424
  return await makeResponsesAPICall(processedInput, responsesOptions);
12553
12425
  }
12554
12426
 
12555
12427
  const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
12556
12428
  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
- ]);
12429
+ const MULTIMODAL_VISION_MODELS = new Set(OPENAI_MODELS);
12574
12430
  /**
12575
12431
  * Makes a call to the OpenAI Images API to generate images based on a text prompt.
12576
12432
  *
@@ -21714,6 +21570,10 @@ const disco = {
21714
21570
 
21715
21571
  exports.AlpacaMarketDataAPI = AlpacaMarketDataAPI;
21716
21572
  exports.AlpacaTradingAPI = AlpacaTradingAPI;
21573
+ exports.OPENAI_MODELS = OPENAI_MODELS;
21574
+ exports.OPENROUTER_MODELS = OPENROUTER_MODELS;
21717
21575
  exports.disco = disco;
21576
+ exports.isOpenAIModel = isOpenAIModel;
21718
21577
  exports.isOpenRouterModel = isOpenRouterModel;
21578
+ exports.supportsTemperature = supportsTemperature;
21719
21579
  //# sourceMappingURL=index.cjs.map