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