@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
@@ -1,36 +1,65 @@
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
+ }
26
+ /**
27
+ * Represents OpenRouter models
28
+ */
29
+ const OPENROUTER_MODELS = [
30
+ 'openai/gpt-5',
31
+ 'openai/gpt-5-mini',
32
+ 'openai/gpt-5.4-mini',
33
+ 'openai/gpt-5-nano',
34
+ 'openai/gpt-5.1',
35
+ 'openai/gpt-5.4',
36
+ 'openai/gpt-5.4-pro',
37
+ 'openai/gpt-5.5',
38
+ 'openai/gpt-5.5-pro',
39
+ 'openai/gpt-5.2',
40
+ 'openai/gpt-5.2-pro',
41
+ 'openai/gpt-5.1-codex',
42
+ 'openai/gpt-5.1-codex-max',
43
+ 'openai/gpt-oss-120b',
44
+ 'z.ai/glm-4.5',
45
+ 'z.ai/glm-4.5-air',
46
+ 'google/gemini-2.5-flash',
47
+ 'google/gemini-2.5-flash-lite',
48
+ 'deepseek/deepseek-r1-0528',
49
+ 'deepseek/deepseek-chat-v3-0324',
50
+ ];
3
51
  /**
4
52
  * Type guard to check if a model is an OpenRouter model
5
53
  */
6
54
  function isOpenRouterModel(model) {
7
- const openRouterModels = [
8
- 'openai/gpt-5',
9
- 'openai/gpt-5-mini',
10
- 'openai/gpt-5.4-mini',
11
- 'openai/gpt-5-nano',
12
- 'openai/gpt-5.1',
13
- 'openai/gpt-5.4',
14
- 'openai/gpt-5.4-pro',
15
- 'openai/gpt-5.5',
16
- 'openai/gpt-5.5-pro',
17
- 'openai/gpt-5.2',
18
- 'openai/gpt-5.2-pro',
19
- 'openai/gpt-5.1-codex',
20
- 'openai/gpt-5.1-codex-max',
21
- 'openai/gpt-oss-120b',
22
- 'z.ai/glm-4.5',
23
- 'z.ai/glm-4.5-air',
24
- 'google/gemini-2.5-flash',
25
- 'google/gemini-2.5-flash-lite',
26
- 'deepseek/deepseek-r1-0528',
27
- 'deepseek/deepseek-chat-v3-0324',
28
- ];
29
- return openRouterModels.includes(model);
55
+ return OPENROUTER_MODELS.includes(model);
30
56
  }
31
57
 
32
58
  var Types = /*#__PURE__*/Object.freeze({
33
59
  __proto__: null,
60
+ OPENAI_MODELS: OPENAI_MODELS,
61
+ OPENROUTER_MODELS: OPENROUTER_MODELS,
62
+ isOpenAIModel: isOpenAIModel,
34
63
  isOpenRouterModel: isOpenRouterModel
35
64
  });
36
65
 
@@ -10244,57 +10273,12 @@ function zodTextFormat(zodObject, name, props) {
10244
10273
  }
10245
10274
 
10246
10275
  // llm-openai-config.ts
10247
- const DEFAULT_MODEL = 'gpt-4.1-mini';
10276
+ const DEFAULT_MODEL = 'gpt-5-mini';
10248
10277
  const GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
10249
10278
  const GPT_5_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
10250
10279
  const GPT_5_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
10251
10280
  /** Token costs in USD per 1M tokens. Last updated May 2026. */
10252
10281
  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
10282
  'gpt-5': {
10299
10283
  inputCost: 1.25 / 1_000_000,
10300
10284
  cacheHitCost: 0.125 / 1_000_000,
@@ -10325,10 +10309,6 @@ const openAiModelCosts = {
10325
10309
  cacheHitCost: 0.25 / 1_000_000,
10326
10310
  outputCost: 15 / 1_000_000,
10327
10311
  },
10328
- 'gpt-5.4-pro': {
10329
- inputCost: 30 / 1_000_000,
10330
- outputCost: 180 / 1_000_000,
10331
- },
10332
10312
  'gpt-5.5': {
10333
10313
  inputCost: 5 / 1_000_000,
10334
10314
  cacheHitCost: 0.5 / 1_000_000,
@@ -10357,11 +10337,6 @@ const openAiModelCosts = {
10357
10337
  cacheHitCost: 0.125 / 1_000_000,
10358
10338
  outputCost: 10 / 1_000_000,
10359
10339
  },
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
10340
  };
10366
10341
  const deepseekModelCosts = {
10367
10342
  'deepseek-chat': {
@@ -10376,8 +10351,7 @@ const deepseekModelCosts = {
10376
10351
  },
10377
10352
  };
10378
10353
  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);
10354
+ return (model === 'gpt-5.4' || model === 'gpt-5.5') && inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS;
10381
10355
  }
10382
10356
  /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
10383
10357
  const openAiImageCosts = {
@@ -10818,100 +10792,13 @@ async function parseResponse(content, responseFormat) {
10818
10792
  }
10819
10793
 
10820
10794
  // 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
10795
  /**
10849
- * Checks if the given model supports the temperature parameter. Reasoning models (o1*, o3*, o4*) do not support temperature.
10796
+ * Checks if the given direct OpenAI model supports the temperature parameter.
10850
10797
  * @param model The model to check.
10851
10798
  * @returns True if the model supports the temperature parameter, false otherwise.
10852
10799
  */
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';
10800
+ function supportsTemperature(_model) {
10801
+ return false;
10915
10802
  }
10916
10803
  function isZodSchema(schema) {
10917
10804
  return typeof schema === 'object' && schema !== null && 'safeParse' in schema;
@@ -10946,7 +10833,7 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
10946
10833
  * - Built-in tools (web search, file search, computer use, code interpreter, image generation)
10947
10834
  * - Background processing
10948
10835
  * - Conversation state management
10949
- * - Reasoning support for o-series models
10836
+ * - GPT-5 reasoning controls
10950
10837
  *
10951
10838
  * @example
10952
10839
  * // Basic text response
@@ -10967,6 +10854,9 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
10967
10854
  */
10968
10855
  const makeResponsesAPICall = async (input, options = {}) => {
10969
10856
  const normalizedModel = normalizeModelName(options.model || DEFAULT_MODEL);
10857
+ if (!isOpenAIModel(normalizedModel)) {
10858
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
10859
+ }
10970
10860
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY;
10971
10861
  if (!apiKey) {
10972
10862
  throw new Error('OpenAI API key is not provided and OPENAI_API_KEY environment variable is not set');
@@ -10981,12 +10871,6 @@ const makeResponsesAPICall = async (input, options = {}) => {
10981
10871
  input,
10982
10872
  ...cleanOptions,
10983
10873
  };
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
10874
  // Make the API call to the Responses endpoint
10991
10875
  const response = await openai.responses.create(requestBody);
10992
10876
  const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
@@ -11093,8 +10977,8 @@ async function makeLLMCall(input, options = {}) {
11093
10977
  const { apiKey, model = DEFAULT_MODEL, responseFormat = 'text', schema, schemaName = 'response', schemaDescription, schemaStrict, tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context, } = options;
11094
10978
  // Validate model
11095
10979
  const normalizedModel = normalizeModelName(model);
11096
- if (!isSupportedModel(normalizedModel)) {
11097
- throw new Error(`Unsupported model: ${normalizedModel}. Please use one of the supported models.`);
10980
+ if (!isOpenAIModel(normalizedModel)) {
10981
+ throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
11098
10982
  }
11099
10983
  // Process input for conversation context and image analysis
11100
10984
  let processedInput;
@@ -11163,10 +11047,6 @@ async function makeLLMCall(input, options = {}) {
11163
11047
  parallel_tool_calls: false,
11164
11048
  tools,
11165
11049
  };
11166
- // Only include temperature if the model supports it
11167
- if (supportsTemperature(normalizedModel)) {
11168
- responsesOptions.temperature = 0.2;
11169
- }
11170
11050
  // Configure response format
11171
11051
  if (schema) {
11172
11052
  responsesOptions.text = {
@@ -11182,41 +11062,17 @@ async function makeLLMCall(input, options = {}) {
11182
11062
  // Configure built-in tools
11183
11063
  if (useCodeInterpreter) {
11184
11064
  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
11065
  responsesOptions.include = ['code_interpreter_call.outputs'];
11190
11066
  }
11191
11067
  if (useWebSearch) {
11192
11068
  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
11069
  }
11198
11070
  return await makeResponsesAPICall(processedInput, responsesOptions);
11199
11071
  }
11200
11072
 
11201
11073
  const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
11202
11074
  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
- ]);
11075
+ const MULTIMODAL_VISION_MODELS = new Set(OPENAI_MODELS);
11220
11076
  /**
11221
11077
  * Makes a call to the OpenAI Images API to generate images based on a text prompt.
11222
11078
  *
@@ -12678,6 +12534,10 @@ const disco = {
12678
12534
  time,
12679
12535
  };
12680
12536
 
12537
+ exports.OPENAI_MODELS = OPENAI_MODELS;
12538
+ exports.OPENROUTER_MODELS = OPENROUTER_MODELS;
12681
12539
  exports.disco = disco;
12540
+ exports.isOpenAIModel = isOpenAIModel;
12682
12541
  exports.isOpenRouterModel = isOpenRouterModel;
12542
+ exports.supportsTemperature = supportsTemperature;
12683
12543
  //# sourceMappingURL=index-frontend.cjs.map