llm-strings 1.4.0 → 1.5.1
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/LICENSE +21 -0
- package/README.md +341 -330
- package/dist/ai-sdk.cjs +1 -1176
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/ai-sdk.js +1 -543
- package/dist/chunk-CT44CYBU.js +1 -0
- package/dist/chunk-JURQSYOT.js +1 -0
- package/dist/chunk-LIYUWJME.js +1 -0
- package/dist/chunk-M5ENVTNI.js +1 -0
- package/dist/index.cjs +1 -1351
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -22
- package/dist/normalize.cjs +1 -527
- package/dist/normalize.d.cts +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/normalize.js +1 -7
- package/dist/parse.cjs +1 -159
- package/dist/parse.d.cts +4 -4
- package/dist/parse.d.ts +4 -4
- package/dist/parse.js +1 -9
- package/dist/{provider-core-B934MuhJ.d.cts → provider-core-CjpJ4qyF.d.cts} +35 -15
- package/dist/{provider-core-B934MuhJ.d.ts → provider-core-CjpJ4qyF.d.ts} +35 -15
- package/dist/providers.cjs +1 -1267
- package/dist/providers.d.cts +2 -2
- package/dist/providers.d.ts +2 -2
- package/dist/providers.js +1 -218
- package/dist/validate.cjs +1 -1334
- package/dist/validate.d.cts +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +1 -9
- package/package.json +17 -2
- package/dist/chunk-5YTG2NRX.js +0 -42
- package/dist/chunk-76EFNZCF.js +0 -1043
- package/dist/chunk-DPVT3FFP.js +0 -116
- package/dist/chunk-OBLFZFNR.js +0 -175
package/dist/chunk-DPVT3FFP.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ALIASES,
|
|
3
|
-
CACHE_TTLS,
|
|
4
|
-
CACHE_VALUES,
|
|
5
|
-
DURATION_RE,
|
|
6
|
-
PROVIDER_PARAMS,
|
|
7
|
-
bedrockSupportsCaching,
|
|
8
|
-
canHostOpenAIModels,
|
|
9
|
-
detectGatewaySubProvider,
|
|
10
|
-
detectProvider,
|
|
11
|
-
isGatewayProvider,
|
|
12
|
-
isReasoningModel,
|
|
13
|
-
providerFromHostAlias
|
|
14
|
-
} from "./chunk-76EFNZCF.js";
|
|
15
|
-
|
|
16
|
-
// src/normalize.ts
|
|
17
|
-
function normalize(config, options = {}) {
|
|
18
|
-
const provider = (config.hostAlias ? providerFromHostAlias(config.hostAlias) : void 0) ?? detectProvider(config.host);
|
|
19
|
-
const subProvider = provider && isGatewayProvider(provider) ? detectGatewaySubProvider(config.model) : void 0;
|
|
20
|
-
const changes = [];
|
|
21
|
-
const params = {};
|
|
22
|
-
for (const [rawKey, value] of Object.entries(config.params)) {
|
|
23
|
-
let key = rawKey;
|
|
24
|
-
if (ALIASES[key]) {
|
|
25
|
-
const canonical = ALIASES[key];
|
|
26
|
-
if (options.verbose) {
|
|
27
|
-
changes.push({
|
|
28
|
-
from: key,
|
|
29
|
-
to: canonical,
|
|
30
|
-
value,
|
|
31
|
-
reason: `alias: "${key}" \u2192 "${canonical}"`
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
key = canonical;
|
|
35
|
-
}
|
|
36
|
-
if (key === "cache" && provider) {
|
|
37
|
-
let cacheValue = CACHE_VALUES[provider];
|
|
38
|
-
if (provider === "bedrock" && !bedrockSupportsCaching(config.model)) {
|
|
39
|
-
cacheValue = void 0;
|
|
40
|
-
}
|
|
41
|
-
if (!cacheValue) {
|
|
42
|
-
if (options.verbose) {
|
|
43
|
-
changes.push({
|
|
44
|
-
from: "cache",
|
|
45
|
-
to: "(dropped)",
|
|
46
|
-
value,
|
|
47
|
-
reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const isBool = value === "true" || value === "1" || value === "yes";
|
|
53
|
-
const isDuration = DURATION_RE.test(value);
|
|
54
|
-
if (isBool || isDuration) {
|
|
55
|
-
const providerKey = PROVIDER_PARAMS[provider]?.["cache"] ?? "cache";
|
|
56
|
-
if (options.verbose) {
|
|
57
|
-
changes.push({
|
|
58
|
-
from: "cache",
|
|
59
|
-
to: providerKey,
|
|
60
|
-
value: cacheValue,
|
|
61
|
-
reason: `cache=${value} \u2192 ${providerKey}=${cacheValue} for ${provider}`
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
params[providerKey] = cacheValue;
|
|
65
|
-
if (isDuration && CACHE_TTLS[provider]) {
|
|
66
|
-
if (options.verbose) {
|
|
67
|
-
changes.push({
|
|
68
|
-
from: "cache",
|
|
69
|
-
to: "cache_ttl",
|
|
70
|
-
value,
|
|
71
|
-
reason: `cache=${value} \u2192 cache_ttl=${value} for ${provider}`
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
params["cache_ttl"] = value;
|
|
75
|
-
}
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (provider && PROVIDER_PARAMS[provider]) {
|
|
80
|
-
const providerKey = PROVIDER_PARAMS[provider][key];
|
|
81
|
-
if (providerKey && providerKey !== key) {
|
|
82
|
-
if (options.verbose) {
|
|
83
|
-
changes.push({
|
|
84
|
-
from: key,
|
|
85
|
-
to: providerKey,
|
|
86
|
-
value,
|
|
87
|
-
reason: `${provider} uses "${providerKey}" instead of "${key}"`
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
key = providerKey;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && key === "max_tokens") {
|
|
94
|
-
if (options.verbose) {
|
|
95
|
-
changes.push({
|
|
96
|
-
from: "max_tokens",
|
|
97
|
-
to: "max_completion_tokens",
|
|
98
|
-
value,
|
|
99
|
-
reason: "OpenAI reasoning models use max_completion_tokens instead of max_tokens"
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
key = "max_completion_tokens";
|
|
103
|
-
}
|
|
104
|
-
params[key] = value;
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
config: { ...config, params },
|
|
108
|
-
provider,
|
|
109
|
-
subProvider,
|
|
110
|
-
changes
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export {
|
|
115
|
-
normalize
|
|
116
|
-
};
|
package/dist/chunk-OBLFZFNR.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalize
|
|
3
|
-
} from "./chunk-DPVT3FFP.js";
|
|
4
|
-
import {
|
|
5
|
-
parse
|
|
6
|
-
} from "./chunk-5YTG2NRX.js";
|
|
7
|
-
import {
|
|
8
|
-
PARAM_SPECS,
|
|
9
|
-
PROVIDER_PARAMS,
|
|
10
|
-
REASONING_MODEL_UNSUPPORTED,
|
|
11
|
-
bedrockSupportsCaching,
|
|
12
|
-
canHostOpenAIModels,
|
|
13
|
-
detectBedrockModelFamily,
|
|
14
|
-
isReasoningModel
|
|
15
|
-
} from "./chunk-76EFNZCF.js";
|
|
16
|
-
|
|
17
|
-
// src/validate.ts
|
|
18
|
-
function buildReverseParamMap(provider) {
|
|
19
|
-
const map = {};
|
|
20
|
-
for (const [canonical, specific] of Object.entries(
|
|
21
|
-
PROVIDER_PARAMS[provider]
|
|
22
|
-
)) {
|
|
23
|
-
map[specific] = canonical;
|
|
24
|
-
}
|
|
25
|
-
return map;
|
|
26
|
-
}
|
|
27
|
-
function lookupSubProviderSpec(gatewayParamName, gatewayReverseMap, subProvider) {
|
|
28
|
-
const canonical = gatewayReverseMap[gatewayParamName] ?? gatewayParamName;
|
|
29
|
-
const subProviderKey = PROVIDER_PARAMS[subProvider]?.[canonical];
|
|
30
|
-
if (!subProviderKey) return { spec: void 0, canonical };
|
|
31
|
-
return { spec: PARAM_SPECS[subProvider]?.[subProviderKey], canonical };
|
|
32
|
-
}
|
|
33
|
-
function buildSubProviderKnownParams(gateway, subProvider) {
|
|
34
|
-
const known = /* @__PURE__ */ new Set();
|
|
35
|
-
const subProviderCanonicals = new Set(
|
|
36
|
-
Object.keys(PROVIDER_PARAMS[subProvider])
|
|
37
|
-
);
|
|
38
|
-
for (const [canonical, gatewaySpecific] of Object.entries(
|
|
39
|
-
PROVIDER_PARAMS[gateway]
|
|
40
|
-
)) {
|
|
41
|
-
if (subProviderCanonicals.has(canonical)) {
|
|
42
|
-
known.add(gatewaySpecific);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return known;
|
|
46
|
-
}
|
|
47
|
-
function validate(connectionString, options = {}) {
|
|
48
|
-
const parsed = parse(connectionString);
|
|
49
|
-
const { config, provider, subProvider } = normalize(parsed);
|
|
50
|
-
const issues = [];
|
|
51
|
-
if (!provider) {
|
|
52
|
-
issues.push({
|
|
53
|
-
param: "host",
|
|
54
|
-
value: config.host,
|
|
55
|
-
message: `Unknown provider for host "${config.host}". Validation skipped.`,
|
|
56
|
-
severity: options.strict ? "error" : "warning"
|
|
57
|
-
});
|
|
58
|
-
return issues;
|
|
59
|
-
}
|
|
60
|
-
const effectiveProvider = subProvider ?? provider;
|
|
61
|
-
const specs = PARAM_SPECS[effectiveProvider];
|
|
62
|
-
const gatewayReverseMap = subProvider ? buildReverseParamMap(provider) : void 0;
|
|
63
|
-
const knownParams = subProvider ? buildSubProviderKnownParams(provider, subProvider) : new Set(Object.values(PROVIDER_PARAMS[provider]));
|
|
64
|
-
for (const [key, value] of Object.entries(config.params)) {
|
|
65
|
-
if (canHostOpenAIModels(provider) && isReasoningModel(config.model) && REASONING_MODEL_UNSUPPORTED.has(key)) {
|
|
66
|
-
issues.push({
|
|
67
|
-
param: key,
|
|
68
|
-
value,
|
|
69
|
-
message: `"${key}" is not supported by OpenAI reasoning model "${config.model}". Use "reasoning_effort" instead of temperature for controlling output.`,
|
|
70
|
-
severity: "error"
|
|
71
|
-
});
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (provider === "bedrock") {
|
|
75
|
-
const family = detectBedrockModelFamily(config.model);
|
|
76
|
-
if (key === "topK" && family && family !== "anthropic" && family !== "cohere" && family !== "mistral") {
|
|
77
|
-
issues.push({
|
|
78
|
-
param: key,
|
|
79
|
-
value,
|
|
80
|
-
message: `"topK" is not supported by ${family} models on Bedrock.`,
|
|
81
|
-
severity: "error"
|
|
82
|
-
});
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (key === "cache_control" && !bedrockSupportsCaching(config.model)) {
|
|
86
|
-
issues.push({
|
|
87
|
-
param: key,
|
|
88
|
-
value,
|
|
89
|
-
message: `Prompt caching is only supported for Anthropic Claude and Amazon Nova models on Bedrock, not ${family ?? "unknown"} models.`,
|
|
90
|
-
severity: "error"
|
|
91
|
-
});
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!knownParams.has(key) && !specs[key]) {
|
|
96
|
-
issues.push({
|
|
97
|
-
param: key,
|
|
98
|
-
value,
|
|
99
|
-
message: `Unknown param "${key}" for ${effectiveProvider}.`,
|
|
100
|
-
severity: options.strict ? "error" : "warning"
|
|
101
|
-
});
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
let spec = specs[key];
|
|
105
|
-
if (subProvider && gatewayReverseMap && !spec) {
|
|
106
|
-
const result = lookupSubProviderSpec(key, gatewayReverseMap, subProvider);
|
|
107
|
-
spec = result.spec;
|
|
108
|
-
}
|
|
109
|
-
if (!spec) continue;
|
|
110
|
-
if ((effectiveProvider === "anthropic" || provider === "bedrock" && detectBedrockModelFamily(config.model) === "anthropic") && (key === "temperature" || key === "top_p" || key === "topP")) {
|
|
111
|
-
const otherKey = key === "temperature" ? provider === "bedrock" ? "topP" : "top_p" : "temperature";
|
|
112
|
-
if (key === "temperature" && config.params[otherKey] !== void 0) {
|
|
113
|
-
issues.push({
|
|
114
|
-
param: key,
|
|
115
|
-
value,
|
|
116
|
-
message: `Cannot specify both "temperature" and "${otherKey}" for Anthropic models.`,
|
|
117
|
-
severity: "error"
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (spec.type === "number") {
|
|
122
|
-
const num = Number(value);
|
|
123
|
-
if (isNaN(num)) {
|
|
124
|
-
issues.push({
|
|
125
|
-
param: key,
|
|
126
|
-
value,
|
|
127
|
-
message: `"${key}" should be a number, got "${value}".`,
|
|
128
|
-
severity: "error"
|
|
129
|
-
});
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (spec.min !== void 0 && num < spec.min) {
|
|
133
|
-
issues.push({
|
|
134
|
-
param: key,
|
|
135
|
-
value,
|
|
136
|
-
message: `"${key}" must be >= ${spec.min}, got ${num}.`,
|
|
137
|
-
severity: "error"
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
if (spec.max !== void 0 && num > spec.max) {
|
|
141
|
-
issues.push({
|
|
142
|
-
param: key,
|
|
143
|
-
value,
|
|
144
|
-
message: `"${key}" must be <= ${spec.max}, got ${num}.`,
|
|
145
|
-
severity: "error"
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (spec.type === "boolean") {
|
|
150
|
-
if (!["true", "false", "0", "1"].includes(value)) {
|
|
151
|
-
issues.push({
|
|
152
|
-
param: key,
|
|
153
|
-
value,
|
|
154
|
-
message: `"${key}" should be a boolean (true/false), got "${value}".`,
|
|
155
|
-
severity: "error"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (spec.type === "string" && spec.values) {
|
|
160
|
-
if (!spec.values.includes(value)) {
|
|
161
|
-
issues.push({
|
|
162
|
-
param: key,
|
|
163
|
-
value,
|
|
164
|
-
message: `"${key}" must be one of [${spec.values.join(", ")}], got "${value}".`,
|
|
165
|
-
severity: "error"
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return issues;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
validate
|
|
175
|
-
};
|