@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.
- package/dist/index-frontend.cjs +40 -185
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +38 -186
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +40 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +38 -186
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/test.js +82 -194
- package/dist/test.js.map +1 -1
- package/dist/types/index-frontend.d.ts +1 -0
- package/dist/types/index-frontend.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/llm-config.d.ts +1 -1
- package/dist/types/llm-config.d.ts.map +1 -1
- package/dist/types/llm-images.d.ts.map +1 -1
- package/dist/types/llm-openai.d.ts +4 -16
- package/dist/types/llm-openai.d.ts.map +1 -1
- package/dist/types/types/llm-types.d.ts +6 -1
- package/dist/types/types/llm-types.d.ts.map +1 -1
- package/dist/types-frontend/index-frontend.d.ts +1 -0
- package/dist/types-frontend/index-frontend.d.ts.map +1 -1
- package/dist/types-frontend/index.d.ts +1 -0
- package/dist/types-frontend/index.d.ts.map +1 -1
- package/dist/types-frontend/llm-config.d.ts +1 -1
- package/dist/types-frontend/llm-config.d.ts.map +1 -1
- package/dist/types-frontend/llm-images.d.ts.map +1 -1
- package/dist/types-frontend/llm-openai.d.ts +4 -16
- package/dist/types-frontend/llm-openai.d.ts.map +1 -1
- package/dist/types-frontend/types/llm-types.d.ts +6 -1
- package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index-frontend.mjs
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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
|
+
}
|
|
1
24
|
/**
|
|
2
25
|
* Type guard to check if a model is an OpenRouter model
|
|
3
26
|
*/
|
|
@@ -29,6 +52,8 @@ function isOpenRouterModel(model) {
|
|
|
29
52
|
|
|
30
53
|
var Types = /*#__PURE__*/Object.freeze({
|
|
31
54
|
__proto__: null,
|
|
55
|
+
OPENAI_MODELS: OPENAI_MODELS,
|
|
56
|
+
isOpenAIModel: isOpenAIModel,
|
|
32
57
|
isOpenRouterModel: isOpenRouterModel
|
|
33
58
|
});
|
|
34
59
|
|
|
@@ -10242,57 +10267,12 @@ function zodTextFormat(zodObject, name, props) {
|
|
|
10242
10267
|
}
|
|
10243
10268
|
|
|
10244
10269
|
// llm-openai-config.ts
|
|
10245
|
-
const DEFAULT_MODEL = 'gpt-
|
|
10270
|
+
const DEFAULT_MODEL = 'gpt-5-mini';
|
|
10246
10271
|
const GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS = 272_000;
|
|
10247
10272
|
const GPT_5_HIGH_CONTEXT_INPUT_MULTIPLIER = 2;
|
|
10248
10273
|
const GPT_5_HIGH_CONTEXT_OUTPUT_MULTIPLIER = 1.5;
|
|
10249
10274
|
/** Token costs in USD per 1M tokens. Last updated May 2026. */
|
|
10250
10275
|
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
10276
|
'gpt-5': {
|
|
10297
10277
|
inputCost: 1.25 / 1_000_000,
|
|
10298
10278
|
cacheHitCost: 0.125 / 1_000_000,
|
|
@@ -10323,10 +10303,6 @@ const openAiModelCosts = {
|
|
|
10323
10303
|
cacheHitCost: 0.25 / 1_000_000,
|
|
10324
10304
|
outputCost: 15 / 1_000_000,
|
|
10325
10305
|
},
|
|
10326
|
-
'gpt-5.4-pro': {
|
|
10327
|
-
inputCost: 30 / 1_000_000,
|
|
10328
|
-
outputCost: 180 / 1_000_000,
|
|
10329
|
-
},
|
|
10330
10306
|
'gpt-5.5': {
|
|
10331
10307
|
inputCost: 5 / 1_000_000,
|
|
10332
10308
|
cacheHitCost: 0.5 / 1_000_000,
|
|
@@ -10355,11 +10331,6 @@ const openAiModelCosts = {
|
|
|
10355
10331
|
cacheHitCost: 0.125 / 1_000_000,
|
|
10356
10332
|
outputCost: 10 / 1_000_000,
|
|
10357
10333
|
},
|
|
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
10334
|
};
|
|
10364
10335
|
const deepseekModelCosts = {
|
|
10365
10336
|
'deepseek-chat': {
|
|
@@ -10374,8 +10345,7 @@ const deepseekModelCosts = {
|
|
|
10374
10345
|
},
|
|
10375
10346
|
};
|
|
10376
10347
|
function shouldUseGPT5HighContextPricing(model, inputTokens) {
|
|
10377
|
-
return (
|
|
10378
|
-
inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS);
|
|
10348
|
+
return (model === 'gpt-5.4' || model === 'gpt-5.5') && inputTokens > GPT_5_HIGH_CONTEXT_THRESHOLD_TOKENS;
|
|
10379
10349
|
}
|
|
10380
10350
|
/** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
|
|
10381
10351
|
const openAiImageCosts = {
|
|
@@ -10816,100 +10786,13 @@ async function parseResponse(content, responseFormat) {
|
|
|
10816
10786
|
}
|
|
10817
10787
|
|
|
10818
10788
|
// 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
10789
|
/**
|
|
10847
|
-
* Checks if the given model supports the temperature parameter.
|
|
10790
|
+
* Checks if the given direct OpenAI model supports the temperature parameter.
|
|
10848
10791
|
* @param model The model to check.
|
|
10849
10792
|
* @returns True if the model supports the temperature parameter, false otherwise.
|
|
10850
10793
|
*/
|
|
10851
|
-
function supportsTemperature(
|
|
10852
|
-
|
|
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';
|
|
10794
|
+
function supportsTemperature(_model) {
|
|
10795
|
+
return false;
|
|
10913
10796
|
}
|
|
10914
10797
|
function isZodSchema(schema) {
|
|
10915
10798
|
return typeof schema === 'object' && schema !== null && 'safeParse' in schema;
|
|
@@ -10944,7 +10827,7 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
|
|
|
10944
10827
|
* - Built-in tools (web search, file search, computer use, code interpreter, image generation)
|
|
10945
10828
|
* - Background processing
|
|
10946
10829
|
* - Conversation state management
|
|
10947
|
-
* -
|
|
10830
|
+
* - GPT-5 reasoning controls
|
|
10948
10831
|
*
|
|
10949
10832
|
* @example
|
|
10950
10833
|
* // Basic text response
|
|
@@ -10965,6 +10848,9 @@ function buildJsonSchemaFormat(schema, schemaName, schemaDescription, schemaStri
|
|
|
10965
10848
|
*/
|
|
10966
10849
|
const makeResponsesAPICall = async (input, options = {}) => {
|
|
10967
10850
|
const normalizedModel = normalizeModelName(options.model || DEFAULT_MODEL);
|
|
10851
|
+
if (!isOpenAIModel(normalizedModel)) {
|
|
10852
|
+
throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
|
|
10853
|
+
}
|
|
10968
10854
|
const apiKey = options.apiKey || process.env.OPENAI_API_KEY;
|
|
10969
10855
|
if (!apiKey) {
|
|
10970
10856
|
throw new Error('OpenAI API key is not provided and OPENAI_API_KEY environment variable is not set');
|
|
@@ -10979,12 +10865,6 @@ const makeResponsesAPICall = async (input, options = {}) => {
|
|
|
10979
10865
|
input,
|
|
10980
10866
|
...cleanOptions,
|
|
10981
10867
|
};
|
|
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
10868
|
// Make the API call to the Responses endpoint
|
|
10989
10869
|
const response = await openai.responses.create(requestBody);
|
|
10990
10870
|
const cacheHitTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
|
|
@@ -11091,8 +10971,8 @@ async function makeLLMCall(input, options = {}) {
|
|
|
11091
10971
|
const { apiKey, model = DEFAULT_MODEL, responseFormat = 'text', schema, schemaName = 'response', schemaDescription, schemaStrict, tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context, } = options;
|
|
11092
10972
|
// Validate model
|
|
11093
10973
|
const normalizedModel = normalizeModelName(model);
|
|
11094
|
-
if (!
|
|
11095
|
-
throw new Error(`Unsupported model: ${normalizedModel}. Please use
|
|
10974
|
+
if (!isOpenAIModel(normalizedModel)) {
|
|
10975
|
+
throw new Error(`Unsupported OpenAI model: ${normalizedModel}. Please use a supported GPT-5 model.`);
|
|
11096
10976
|
}
|
|
11097
10977
|
// Process input for conversation context and image analysis
|
|
11098
10978
|
let processedInput;
|
|
@@ -11161,10 +11041,6 @@ async function makeLLMCall(input, options = {}) {
|
|
|
11161
11041
|
parallel_tool_calls: false,
|
|
11162
11042
|
tools,
|
|
11163
11043
|
};
|
|
11164
|
-
// Only include temperature if the model supports it
|
|
11165
|
-
if (supportsTemperature(normalizedModel)) {
|
|
11166
|
-
responsesOptions.temperature = 0.2;
|
|
11167
|
-
}
|
|
11168
11044
|
// Configure response format
|
|
11169
11045
|
if (schema) {
|
|
11170
11046
|
responsesOptions.text = {
|
|
@@ -11180,41 +11056,17 @@ async function makeLLMCall(input, options = {}) {
|
|
|
11180
11056
|
// Configure built-in tools
|
|
11181
11057
|
if (useCodeInterpreter) {
|
|
11182
11058
|
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
11059
|
responsesOptions.include = ['code_interpreter_call.outputs'];
|
|
11188
11060
|
}
|
|
11189
11061
|
if (useWebSearch) {
|
|
11190
11062
|
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
11063
|
}
|
|
11196
11064
|
return await makeResponsesAPICall(processedInput, responsesOptions);
|
|
11197
11065
|
}
|
|
11198
11066
|
|
|
11199
11067
|
const DEFAULT_IMAGE_MODEL = 'gpt-image-1.5';
|
|
11200
11068
|
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
|
-
]);
|
|
11069
|
+
const MULTIMODAL_VISION_MODELS = new Set(OPENAI_MODELS);
|
|
11218
11070
|
/**
|
|
11219
11071
|
* Makes a call to the OpenAI Images API to generate images based on a text prompt.
|
|
11220
11072
|
*
|
|
@@ -12676,5 +12528,5 @@ const disco = {
|
|
|
12676
12528
|
time,
|
|
12677
12529
|
};
|
|
12678
12530
|
|
|
12679
|
-
export { disco, isOpenRouterModel };
|
|
12531
|
+
export { OPENAI_MODELS, disco, isOpenAIModel, isOpenRouterModel, supportsTemperature };
|
|
12680
12532
|
//# sourceMappingURL=index-frontend.mjs.map
|