@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
@@ -1,5 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * Represents OpenAI models
5
+ */
6
+ const OPENAI_MODELS = [
7
+ 'gpt-5',
8
+ 'gpt-5-mini',
9
+ 'gpt-5.4-mini',
10
+ 'gpt-5-nano',
11
+ 'gpt-5.1',
12
+ 'gpt-5.4',
13
+ 'gpt-5.5',
14
+ 'gpt-5.5-pro',
15
+ 'gpt-5.2',
16
+ 'gpt-5.2-pro',
17
+ 'gpt-5.1-codex',
18
+ 'gpt-5.1-codex-max',
19
+ ];
20
+ /**
21
+ * Type guard to check if a model is a supported direct OpenAI model.
22
+ */
23
+ function isOpenAIModel(model) {
24
+ return OPENAI_MODELS.includes(model);
25
+ }
3
26
  /**
4
27
  * Type guard to check if a model is an OpenRouter model
5
28
  */
@@ -31,6 +54,8 @@ function isOpenRouterModel(model) {
31
54
 
32
55
  var Types = /*#__PURE__*/Object.freeze({
33
56
  __proto__: null,
57
+ OPENAI_MODELS: OPENAI_MODELS,
58
+ isOpenAIModel: isOpenAIModel,
34
59
  isOpenRouterModel: isOpenRouterModel
35
60
  });
36
61
 
@@ -10244,57 +10269,12 @@ function zodTextFormat(zodObject, name, props) {
10244
10269
  }
10245
10270
 
10246
10271
  // llm-openai-config.ts
10247
- const DEFAULT_MODEL = 'gpt-4.1-mini';
10272
+ const DEFAULT_MODEL = 'gpt-5-mini';
10248
10273
  const GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
10249
10274
  const GPT_5_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
10250
10275
  const GPT_5_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
10251
10276
  /** Token costs in USD per 1M tokens. Last updated May 2026. */
10252
10277
  const openAiModelCosts = {
10253
- 'gpt-4o': {
10254
- inputCost: 2.5 / 1_000_000,
10255
- cacheHitCost: 1.25 / 1_000_000,
10256
- outputCost: 10 / 1_000_000,
10257
- },
10258
- 'gpt-4o-mini': {
10259
- inputCost: 0.15 / 1_000_000,
10260
- cacheHitCost: 0.075 / 1_000_000,
10261
- outputCost: 0.6 / 1_000_000,
10262
- },
10263
- 'o1-mini': {
10264
- inputCost: 1.1 / 1_000_000,
10265
- cacheHitCost: 0.55 / 1_000_000,
10266
- outputCost: 4.4 / 1_000_000,
10267
- },
10268
- 'o1': {
10269
- inputCost: 15 / 1_000_000,
10270
- cacheHitCost: 7.5 / 1_000_000,
10271
- outputCost: 60 / 1_000_000,
10272
- },
10273
- 'o3-mini': {
10274
- inputCost: 1.1 / 1_000_000,
10275
- cacheHitCost: 0.55 / 1_000_000,
10276
- outputCost: 4.4 / 1_000_000,
10277
- },
10278
- 'o3': {
10279
- inputCost: 2 / 1_000_000,
10280
- cacheHitCost: 0.5 / 1_000_000,
10281
- outputCost: 8 / 1_000_000,
10282
- },
10283
- 'gpt-4.1': {
10284
- inputCost: 2 / 1_000_000,
10285
- cacheHitCost: 0.5 / 1_000_000,
10286
- outputCost: 8 / 1_000_000,
10287
- },
10288
- 'gpt-4.1-mini': {
10289
- inputCost: 0.4 / 1_000_000,
10290
- cacheHitCost: 0.1 / 1_000_000,
10291
- outputCost: 1.6 / 1_000_000,
10292
- },
10293
- 'gpt-4.1-nano': {
10294
- inputCost: 0.1 / 1_000_000,
10295
- cacheHitCost: 0.025 / 1_000_000,
10296
- outputCost: 0.4 / 1_000_000,
10297
- },
10298
10278
  'gpt-5': {
10299
10279
  inputCost: 1.25 / 1_000_000,
10300
10280
  cacheHitCost: 0.125 / 1_000_000,
@@ -10325,10 +10305,6 @@ const openAiModelCosts = {
10325
10305
  cacheHitCost: 0.25 / 1_000_000,
10326
10306
  outputCost: 15 / 1_000_000,
10327
10307
  },
10328
- 'gpt-5.4-pro': {
10329
- inputCost: 30 / 1_000_000,
10330
- outputCost: 180 / 1_000_000,
10331
- },
10332
10308
  'gpt-5.5': {
10333
10309
  inputCost: 5 / 1_000_000,
10334
10310
  cacheHitCost: 0.5 / 1_000_000,
@@ -10357,11 +10333,6 @@ const openAiModelCosts = {
10357
10333
  cacheHitCost: 0.125 / 1_000_000,
10358
10334
  outputCost: 10 / 1_000_000,
10359
10335
  },
10360
- 'o4-mini': {
10361
- inputCost: 1.1 / 1_000_000,
10362
- cacheHitCost: 0.275 / 1_000_000,
10363
- outputCost: 4.4 / 1_000_000,
10364
- },
10365
10336
  };
10366
10337
  const deepseekModelCosts = {
10367
10338
  'deepseek-chat': {
@@ -10376,8 +10347,7 @@ const deepseekModelCosts = {
10376
10347
  },
10377
10348
  };
10378
10349
  function shouldUseGPT5HighContextPricing(model, inputTokens) {
10379
- return ((model === 'gpt-5.4' || model === 'gpt-5.4-pro' || model === 'gpt-5.5') &&
10380
- inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS);
10350
+ return (model === 'gpt-5.4' || model === 'gpt-5.5') && inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS;
10381
10351
  }
10382
10352
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
10383
10353
  const openAiImageCosts = {
@@ -10818,100 +10788,13 @@ async function parseResponse(content, responseFormat) {
10818
10788
  }
10819
10789
 
10820
10790
  // llm-openai.ts
10821
- const isSupportedModel = (model) => {
10822
- return [
10823
- 'gpt-4o-mini',
10824
- 'gpt-4o',
10825
- 'o1-mini',
10826
- 'o1',
10827
- 'o3-mini',
10828
- 'gpt-4.1',
10829
- 'gpt-4.1-mini',
10830
- 'gpt-4.1-nano',
10831
- 'gpt-5',
10832
- 'gpt-5-mini',
10833
- 'gpt-5.4-mini',
10834
- 'gpt-5-nano',
10835
- 'gpt-5.1',
10836
- 'gpt-5.4',
10837
- 'gpt-5.4-pro',
10838
- 'gpt-5.5',
10839
- 'gpt-5.5-pro',
10840
- 'gpt-5.2',
10841
- 'gpt-5.2-pro',
10842
- 'gpt-5.1-codex',
10843
- 'gpt-5.1-codex-max',
10844
- 'o4-mini',
10845
- 'o3',
10846
- ].includes(model);
10847
- };
10848
10791
  /**
10849
- * Checks if the given model supports the temperature parameter. Reasoning models (o1*, o3*, o4*) do not support temperature.
10792
+ * Checks if the given direct OpenAI model supports the temperature parameter.
10850
10793
  * @param model The model to check.
10851
10794
  * @returns True if the model supports the temperature parameter, false otherwise.
10852
10795
  */
10853
- function supportsTemperature(model) {
10854
- // Reasoning models don't support temperature
10855
- // GPT-5 models also do not support temperature
10856
- const reasoningAndGPT5Models = [
10857
- 'o1',
10858
- 'o1-mini',
10859
- 'o3-mini',
10860
- 'o4-mini',
10861
- 'o3',
10862
- 'gpt-5',
10863
- 'gpt-5-mini',
10864
- 'gpt-5.4-mini',
10865
- 'gpt-5-nano',
10866
- 'gpt-5.1',
10867
- 'gpt-5.4',
10868
- 'gpt-5.4-pro',
10869
- 'gpt-5.5',
10870
- 'gpt-5.5-pro',
10871
- 'gpt-5.2',
10872
- 'gpt-5.2-pro',
10873
- 'gpt-5.1-codex',
10874
- 'gpt-5.1-codex-max',
10875
- ];
10876
- return !reasoningAndGPT5Models.includes(model);
10877
- }
10878
- /**
10879
- * Checks if the given model is a reasoning model. Reasoning models have different tool choice constraints.
10880
- * @param model The model to check.
10881
- * @returns True if the model is a reasoning model, false otherwise.
10882
- */
10883
- function isReasoningModel(model) {
10884
- const reasoningModels = ['o1', 'o1-mini', 'o3-mini', 'o4-mini', 'o3'];
10885
- return reasoningModels.includes(model);
10886
- }
10887
- /**
10888
- * Checks if the given model is a GPT-5 model. GPT-5 models don't support tool_choice other than 'auto'.
10889
- * @param model The model to check.
10890
- * @returns True if the model is a GPT-5 model, false otherwise.
10891
- */
10892
- function isGPT5Model(model) {
10893
- const gpt5Models = [
10894
- 'gpt-5',
10895
- 'gpt-5-mini',
10896
- 'gpt-5.4-mini',
10897
- 'gpt-5-nano',
10898
- 'gpt-5.1',
10899
- 'gpt-5.4',
10900
- 'gpt-5.4-pro',
10901
- 'gpt-5.5',
10902
- 'gpt-5.5-pro',
10903
- 'gpt-5.2',
10904
- 'gpt-5.2-pro',
10905
- 'gpt-5.1-codex',
10906
- 'gpt-5.1-codex-max',
10907
- ];
10908
- return gpt5Models.includes(model);
10909
- }
10910
- function supportsStructuredOutputs(model) {
10911
- return normalizeModelName(model) !== 'gpt-5.4-pro';
10912
- }
10913
- function supportsDistillation(model) {
10914
- return normalizeModelName(model) !== 'gpt-5.4-pro';
10796
+ function supportsTemperature(_model) {
10797
+ return false;
10915
10798
  }
10916
10799
  function isZodSchema(schema) {
10917
10800
  return typeof schema === 'object' && schema !== null && 'safeParse' in schema;
@@ -10946,7 +10829,7 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
10946
10829
  * - Built-in tools (web search, file search, computer use, code interpreter, image generation)
10947
10830
  * - Background processing
10948
10831
  * - Conversation state management
10949
- * - Reasoning support for o-series models
10832
+ * - GPT-5 reasoning controls
10950
10833
  *
10951
10834
  * @example
10952
10835
  * // Basic text response
@@ -10967,6 +10850,9 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
10967
10850
  */
10968
10851
  const makeResponsesAPICall = async (input, options = {}) => {
10969
10852
  const normalizedModel = normalizeModelName(options.model || DEFAULT_MODEL);
10853
+ if (!isOpenAIModel(normalizedModel)) {
10854
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
10855
+ }
10970
10856
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY;
10971
10857
  if (!apiKey) {
10972
10858
  throw new Error('OpenAI API key is not provided and OPENAI_API_KEY environment variable is not set');
@@ -10981,12 +10867,6 @@ const makeResponsesAPICall = async (input, options = {}) => {
10981
10867
  input,
10982
10868
  ...cleanOptions,
10983
10869
  };
10984
- if (requestBody.text?.format?.type === 'json_schema' && !supportsStructuredOutputs(normalizedModel)) {
10985
- throw new Error(`Model ${normalizedModel} does not support structured outputs`);
10986
- }
10987
- if (requestBody.store && !supportsDistillation(normalizedModel)) {
10988
- throw new Error(`Model ${normalizedModel} does not support distillation`);
10989
- }
10990
10870
  // Make the API call to the Responses endpoint
10991
10871
  const response = await openai.responses.create(requestBody);
10992
10872
  const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
@@ -11093,8 +10973,8 @@ async function makeLLMCall(input, options = {}) {
11093
10973
  const { apiKey, model = DEFAULT_MODEL, responseFormat = 'text', schema, schemaName = 'response', schemaDescription, schemaStrict, tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context, } = options;
11094
10974
  // Validate model
11095
10975
  const normalizedModel = normalizeModelName(model);
11096
- if (!isSupportedModel(normalizedModel)) {
11097
- throw new Error(`Unsupported model: ${normalizedModel}. Please use one of the supported models.`);
10976
+ if (!isOpenAIModel(normalizedModel)) {
10977
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
11098
10978
  }
11099
10979
  // Process input for conversation context and image analysis
11100
10980
  let processedInput;
@@ -11163,10 +11043,6 @@ async function makeLLMCall(input, options = {}) {
11163
11043
  parallel_tool_calls: false,
11164
11044
  tools,
11165
11045
  };
11166
- // Only include temperature if the model supports it
11167
- if (supportsTemperature(normalizedModel)) {
11168
- responsesOptions.temperature = 0.2;
11169
- }
11170
11046
  // Configure response format
11171
11047
  if (schema) {
11172
11048
  responsesOptions.text = {
@@ -11182,41 +11058,17 @@ async function makeLLMCall(input, options = {}) {
11182
11058
  // Configure built-in tools
11183
11059
  if (useCodeInterpreter) {
11184
11060
  responsesOptions.tools = [{ type: 'code_interpreter', container: { type: 'auto' } }];
11185
- // For reasoning models, we can't force tool choice - they only support 'auto'
11186
- if (!isReasoningModel(normalizedModel)) {
11187
- responsesOptions.tool_choice = { type: 'code_interpreter' };
11188
- }
11189
11061
  responsesOptions.include = ['code_interpreter_call.outputs'];
11190
11062
  }
11191
11063
  if (useWebSearch) {
11192
11064
  responsesOptions.tools = [{ type: 'web_search_preview' }];
11193
- // For reasoning models and GPT-5 models, we can't force tool choice - they only support 'auto'
11194
- if (!isReasoningModel(normalizedModel) && !isGPT5Model(normalizedModel)) {
11195
- responsesOptions.tool_choice = { type: 'web_search_preview' };
11196
- }
11197
11065
  }
11198
11066
  return await makeResponsesAPICall(processedInput, responsesOptions);
11199
11067
  }
11200
11068
 
11201
11069
  const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
11202
11070
  const resolveImageModel = (model) => model ?? DEFAULT_IMAGE_MODEL;
11203
- const MULTIMODAL_VISION_MODELS = new Set([
11204
- 'gpt-4o-mini',
11205
- 'gpt-4o',
11206
- 'gpt-5',
11207
- 'gpt-5-mini',
11208
- 'gpt-5.4-mini',
11209
- 'gpt-5-nano',
11210
- 'gpt-5.1',
11211
- 'gpt-5.4',
11212
- 'gpt-5.4-pro',
11213
- 'gpt-5.5',
11214
- 'gpt-5.5-pro',
11215
- 'gpt-5.2',
11216
- 'gpt-5.2-pro',
11217
- 'gpt-5.1-codex',
11218
- 'gpt-5.1-codex-max',
11219
- ]);
11071
+ const MULTIMODAL_VISION_MODELS = new Set(OPENAI_MODELS);
11220
11072
  /**
11221
11073
  * Makes a call to the OpenAI Images API to generate images based on a text prompt.
11222
11074
  *
@@ -12678,6 +12530,9 @@ const disco = {
12678
12530
  time,
12679
12531
  };
12680
12532
 
12533
+ exports.OPENAI_MODELS = OPENAI_MODELS;
12681
12534
  exports.disco = disco;
12535
+ exports.isOpenAIModel = isOpenAIModel;
12682
12536
  exports.isOpenRouterModel = isOpenRouterModel;
12537
+ exports.supportsTemperature = supportsTemperature;
12683
12538
  //# sourceMappingURL=index-frontend.cjs.map