llm-strings 1.5.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/README.md +2 -0
- package/dist/ai-sdk.cjs +1 -2206
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/ai-sdk.js +1 -581
- 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 -1799
- 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 -1530
- 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 -1234
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +1 -9
- package/dist/{provider-core-B1GMszQP.d.cts → provider-core-CjpJ4qyF.d.cts} +34 -13
- package/dist/{provider-core-B1GMszQP.d.ts → provider-core-CjpJ4qyF.d.ts} +34 -13
- package/dist/providers.cjs +1 -1712
- 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 -1782
- package/dist/validate.js +1 -9
- package/package.json +2 -1
- package/dist/chunk-4BE457QA.js +0 -163
- package/dist/chunk-6HQOCOQI.js +0 -42
- package/dist/chunk-7Z7DCLZN.js +0 -128
- package/dist/chunk-PCJDQTOV.js +0 -1488
package/dist/validate.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
validate
|
|
3
|
-
} from "./chunk-4BE457QA.js";
|
|
4
|
-
import "./chunk-7Z7DCLZN.js";
|
|
5
|
-
import "./chunk-6HQOCOQI.js";
|
|
6
|
-
import "./chunk-PCJDQTOV.js";
|
|
7
|
-
export {
|
|
8
|
-
validate
|
|
9
|
-
};
|
|
1
|
+
import{validate as o}from"./chunk-CT44CYBU.js";import"./chunk-JURQSYOT.js";import"./chunk-M5ENVTNI.js";import"./chunk-LIYUWJME.js";export{o as validate};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-strings",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"packageManager": "pnpm@11.1.1",
|
|
5
5
|
"description": "Parse and build LLM connection strings — like database URLs, but for LLM APIs",
|
|
6
6
|
"type": "module",
|
|
@@ -117,6 +117,7 @@
|
|
|
117
117
|
"@vitest/coverage-v8": "^4.0.18",
|
|
118
118
|
"eslint": "^10.0.0",
|
|
119
119
|
"prettier": "^3.0.0",
|
|
120
|
+
"terser": "^5.48.0",
|
|
120
121
|
"tsup": "^8.0.0",
|
|
121
122
|
"typescript": "^5.5.0",
|
|
122
123
|
"typescript-eslint": "^8.0.0",
|
package/dist/chunk-4BE457QA.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalize
|
|
3
|
-
} from "./chunk-7Z7DCLZN.js";
|
|
4
|
-
import {
|
|
5
|
-
parse
|
|
6
|
-
} from "./chunk-6HQOCOQI.js";
|
|
7
|
-
import {
|
|
8
|
-
PARAM_SPECS,
|
|
9
|
-
PROVIDER_PARAMS,
|
|
10
|
-
bedrockSupportsCaching,
|
|
11
|
-
detectBedrockModelFamily
|
|
12
|
-
} from "./chunk-PCJDQTOV.js";
|
|
13
|
-
|
|
14
|
-
// src/validate.ts
|
|
15
|
-
function buildReverseParamMap(provider) {
|
|
16
|
-
const map = {};
|
|
17
|
-
for (const [canonical, specific] of Object.entries(
|
|
18
|
-
PROVIDER_PARAMS[provider]
|
|
19
|
-
)) {
|
|
20
|
-
map[specific] = canonical;
|
|
21
|
-
}
|
|
22
|
-
return map;
|
|
23
|
-
}
|
|
24
|
-
function lookupSubProviderSpec(gatewayParamName, gatewayReverseMap, subProvider) {
|
|
25
|
-
const canonical = gatewayReverseMap[gatewayParamName] ?? gatewayParamName;
|
|
26
|
-
const subProviderKey = PROVIDER_PARAMS[subProvider]?.[canonical];
|
|
27
|
-
if (!subProviderKey) return { spec: void 0, canonical };
|
|
28
|
-
return { spec: PARAM_SPECS[subProvider]?.[subProviderKey], canonical };
|
|
29
|
-
}
|
|
30
|
-
function buildSubProviderKnownParams(gateway, subProvider) {
|
|
31
|
-
const known = /* @__PURE__ */ new Set();
|
|
32
|
-
const subProviderCanonicals = new Set(
|
|
33
|
-
Object.keys(PROVIDER_PARAMS[subProvider])
|
|
34
|
-
);
|
|
35
|
-
for (const [canonical, gatewaySpecific] of Object.entries(
|
|
36
|
-
PROVIDER_PARAMS[gateway]
|
|
37
|
-
)) {
|
|
38
|
-
if (subProviderCanonicals.has(canonical)) {
|
|
39
|
-
known.add(gatewaySpecific);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return known;
|
|
43
|
-
}
|
|
44
|
-
function validate(connectionString, options = {}) {
|
|
45
|
-
const parsed = parse(connectionString);
|
|
46
|
-
const { config, provider, subProvider } = normalize(parsed);
|
|
47
|
-
const issues = [];
|
|
48
|
-
if (!provider) {
|
|
49
|
-
issues.push({
|
|
50
|
-
param: "host",
|
|
51
|
-
value: config.host,
|
|
52
|
-
message: `Unknown provider for host "${config.host}". Validation skipped.`,
|
|
53
|
-
severity: options.strict ? "error" : "warning"
|
|
54
|
-
});
|
|
55
|
-
return issues;
|
|
56
|
-
}
|
|
57
|
-
const effectiveProvider = subProvider ?? provider;
|
|
58
|
-
const specs = PARAM_SPECS[effectiveProvider];
|
|
59
|
-
const gatewayReverseMap = subProvider ? buildReverseParamMap(provider) : void 0;
|
|
60
|
-
const knownParams = subProvider ? buildSubProviderKnownParams(provider, subProvider) : new Set(Object.values(PROVIDER_PARAMS[provider]));
|
|
61
|
-
for (const [key, value] of Object.entries(config.params)) {
|
|
62
|
-
const subProviderSpecResult = subProvider && gatewayReverseMap ? lookupSubProviderSpec(key, gatewayReverseMap, subProvider) : void 0;
|
|
63
|
-
const gatewayOwnSpec = subProvider && !subProviderSpecResult?.spec ? PARAM_SPECS[provider]?.[key] : void 0;
|
|
64
|
-
if (provider === "bedrock") {
|
|
65
|
-
const family = detectBedrockModelFamily(config.model);
|
|
66
|
-
if (key === "topK" && family && family !== "anthropic" && family !== "cohere" && family !== "mistral") {
|
|
67
|
-
issues.push({
|
|
68
|
-
param: key,
|
|
69
|
-
value,
|
|
70
|
-
message: `"topK" is not supported by ${family} models on Bedrock.`,
|
|
71
|
-
severity: "error"
|
|
72
|
-
});
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (key === "cache_control" && !bedrockSupportsCaching(config.model)) {
|
|
76
|
-
issues.push({
|
|
77
|
-
param: key,
|
|
78
|
-
value,
|
|
79
|
-
message: `Prompt caching is only supported for Anthropic Claude and Amazon Nova models on Bedrock, not ${family ?? "unknown"} models.`,
|
|
80
|
-
severity: "error"
|
|
81
|
-
});
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!knownParams.has(key) && !specs[key] && !gatewayOwnSpec) {
|
|
86
|
-
if (options.strict) {
|
|
87
|
-
issues.push({
|
|
88
|
-
param: key,
|
|
89
|
-
value,
|
|
90
|
-
message: `Unknown param "${key}" for ${effectiveProvider}.`,
|
|
91
|
-
severity: "error"
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const spec = subProviderSpecResult?.spec ?? gatewayOwnSpec ?? specs[key];
|
|
97
|
-
if (!spec) continue;
|
|
98
|
-
if ((effectiveProvider === "anthropic" || provider === "bedrock" && detectBedrockModelFamily(config.model) === "anthropic") && (key === "temperature" || key === "top_p" || key === "topP")) {
|
|
99
|
-
const otherKey = key === "temperature" ? provider === "bedrock" ? "topP" : "top_p" : "temperature";
|
|
100
|
-
if (key === "temperature" && config.params[otherKey] !== void 0) {
|
|
101
|
-
issues.push({
|
|
102
|
-
param: key,
|
|
103
|
-
value,
|
|
104
|
-
message: `Cannot specify both "temperature" and "${otherKey}" for Anthropic models.`,
|
|
105
|
-
severity: "error"
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (spec.type === "number") {
|
|
110
|
-
const num = Number(value);
|
|
111
|
-
if (isNaN(num)) {
|
|
112
|
-
issues.push({
|
|
113
|
-
param: key,
|
|
114
|
-
value,
|
|
115
|
-
message: `"${key}" should be a number, got "${value}".`,
|
|
116
|
-
severity: "error"
|
|
117
|
-
});
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (spec.min !== void 0 && num < spec.min) {
|
|
121
|
-
issues.push({
|
|
122
|
-
param: key,
|
|
123
|
-
value,
|
|
124
|
-
message: `"${key}" must be >= ${spec.min}, got ${num}.`,
|
|
125
|
-
severity: "error"
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (spec.max !== void 0 && num > spec.max) {
|
|
129
|
-
issues.push({
|
|
130
|
-
param: key,
|
|
131
|
-
value,
|
|
132
|
-
message: `"${key}" must be <= ${spec.max}, got ${num}.`,
|
|
133
|
-
severity: "error"
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (spec.type === "boolean") {
|
|
138
|
-
if (!["true", "false", "0", "1"].includes(value)) {
|
|
139
|
-
issues.push({
|
|
140
|
-
param: key,
|
|
141
|
-
value,
|
|
142
|
-
message: `"${key}" should be a boolean (true/false), got "${value}".`,
|
|
143
|
-
severity: "error"
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (spec.type === "string" && spec.values) {
|
|
148
|
-
if (!spec.values.includes(value)) {
|
|
149
|
-
issues.push({
|
|
150
|
-
param: key,
|
|
151
|
-
value,
|
|
152
|
-
message: `"${key}" must be one of [${spec.values.join(", ")}], got "${value}".`,
|
|
153
|
-
severity: "error"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return issues;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
validate
|
|
163
|
-
};
|
package/dist/chunk-6HQOCOQI.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveHostAlias
|
|
3
|
-
} from "./chunk-PCJDQTOV.js";
|
|
4
|
-
|
|
5
|
-
// src/parse.ts
|
|
6
|
-
function parse(connectionString) {
|
|
7
|
-
const url = new URL(connectionString);
|
|
8
|
-
if (url.protocol !== "llm:") {
|
|
9
|
-
throw new Error(
|
|
10
|
-
`Invalid scheme: expected "llm://", got "${url.protocol}//"`
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
const { host, alias: hostAlias } = resolveHostAlias(url.host);
|
|
14
|
-
const model = url.pathname.replace(/^\//, "");
|
|
15
|
-
const label = url.username || void 0;
|
|
16
|
-
const apiKey = url.password || void 0;
|
|
17
|
-
const params = {};
|
|
18
|
-
for (const [key, value] of url.searchParams) {
|
|
19
|
-
params[key] = value;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
raw: connectionString,
|
|
23
|
-
host,
|
|
24
|
-
hostAlias,
|
|
25
|
-
model,
|
|
26
|
-
label,
|
|
27
|
-
apiKey,
|
|
28
|
-
params
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function build(config) {
|
|
32
|
-
const { host } = resolveHostAlias(config.host);
|
|
33
|
-
const auth = config.label || config.apiKey ? `${config.label ?? ""}${config.apiKey ? `:${config.apiKey}` : ""}@` : "";
|
|
34
|
-
const query = new URLSearchParams(config.params).toString();
|
|
35
|
-
const qs = query ? `?${query}` : "";
|
|
36
|
-
return `llm://${auth}${host}/${config.model}${qs}`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
parse,
|
|
41
|
-
build
|
|
42
|
-
};
|
package/dist/chunk-7Z7DCLZN.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ALIASES,
|
|
3
|
-
CACHE_TTLS,
|
|
4
|
-
CACHE_VALUES,
|
|
5
|
-
PROVIDER_PARAMS,
|
|
6
|
-
REASONING_MODEL_UNSUPPORTED,
|
|
7
|
-
bedrockSupportsCaching,
|
|
8
|
-
canHostOpenAIModels,
|
|
9
|
-
detectGatewaySubProvider,
|
|
10
|
-
detectProvider,
|
|
11
|
-
isGatewayProvider,
|
|
12
|
-
isReasoningModel,
|
|
13
|
-
providerFromHostAlias
|
|
14
|
-
} from "./chunk-PCJDQTOV.js";
|
|
15
|
-
|
|
16
|
-
// src/normalize.ts
|
|
17
|
-
var DURATION_RE = /^\d+[mh]$/;
|
|
18
|
-
function normalize(config, options = {}) {
|
|
19
|
-
const provider = (config.hostAlias ? providerFromHostAlias(config.hostAlias) : void 0) ?? detectProvider(config.host);
|
|
20
|
-
const subProvider = provider && isGatewayProvider(provider) ? detectGatewaySubProvider(config.model) : void 0;
|
|
21
|
-
const changes = [];
|
|
22
|
-
const params = {};
|
|
23
|
-
for (const [rawKey, value] of Object.entries(config.params)) {
|
|
24
|
-
let key = rawKey;
|
|
25
|
-
if (ALIASES[key]) {
|
|
26
|
-
const canonical = ALIASES[key];
|
|
27
|
-
if (options.verbose) {
|
|
28
|
-
changes.push({
|
|
29
|
-
from: key,
|
|
30
|
-
to: canonical,
|
|
31
|
-
value,
|
|
32
|
-
reason: `alias: "${key}" \u2192 "${canonical}"`
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
key = canonical;
|
|
36
|
-
}
|
|
37
|
-
if (key === "cache" && provider) {
|
|
38
|
-
let cacheValue = CACHE_VALUES[provider];
|
|
39
|
-
if (provider === "bedrock" && !bedrockSupportsCaching(config.model)) {
|
|
40
|
-
cacheValue = void 0;
|
|
41
|
-
}
|
|
42
|
-
if (!cacheValue) {
|
|
43
|
-
if (options.verbose) {
|
|
44
|
-
changes.push({
|
|
45
|
-
from: "cache",
|
|
46
|
-
to: "(dropped)",
|
|
47
|
-
value,
|
|
48
|
-
reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const isBool = value === "true" || value === "1" || value === "yes";
|
|
54
|
-
const isDuration = DURATION_RE.test(value);
|
|
55
|
-
if (isBool || isDuration) {
|
|
56
|
-
const providerKey = PROVIDER_PARAMS[provider]?.["cache"] ?? "cache";
|
|
57
|
-
if (options.verbose) {
|
|
58
|
-
changes.push({
|
|
59
|
-
from: "cache",
|
|
60
|
-
to: providerKey,
|
|
61
|
-
value: cacheValue,
|
|
62
|
-
reason: `cache=${value} \u2192 ${providerKey}=${cacheValue} for ${provider}`
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
params[providerKey] = cacheValue;
|
|
66
|
-
if (isDuration && CACHE_TTLS[provider]) {
|
|
67
|
-
if (options.verbose) {
|
|
68
|
-
changes.push({
|
|
69
|
-
from: "cache",
|
|
70
|
-
to: "cache_ttl",
|
|
71
|
-
value,
|
|
72
|
-
reason: `cache=${value} \u2192 cache_ttl=${value} for ${provider}`
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
params["cache_ttl"] = value;
|
|
76
|
-
}
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (provider && PROVIDER_PARAMS[provider]) {
|
|
81
|
-
const providerKey = PROVIDER_PARAMS[provider][key];
|
|
82
|
-
if (providerKey && providerKey !== key) {
|
|
83
|
-
if (options.verbose) {
|
|
84
|
-
changes.push({
|
|
85
|
-
from: key,
|
|
86
|
-
to: providerKey,
|
|
87
|
-
value,
|
|
88
|
-
reason: `${provider} uses "${providerKey}" instead of "${key}"`
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
key = providerKey;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && key === "max_tokens") {
|
|
95
|
-
if (options.verbose) {
|
|
96
|
-
changes.push({
|
|
97
|
-
from: "max_tokens",
|
|
98
|
-
to: "max_completion_tokens",
|
|
99
|
-
value,
|
|
100
|
-
reason: "OpenAI reasoning models use max_completion_tokens instead of max_tokens"
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
key = "max_completion_tokens";
|
|
104
|
-
}
|
|
105
|
-
if (provider && canHostOpenAIModels(provider) && isReasoningModel(config.model) && REASONING_MODEL_UNSUPPORTED.has(key)) {
|
|
106
|
-
if (options.verbose) {
|
|
107
|
-
changes.push({
|
|
108
|
-
from: key,
|
|
109
|
-
to: "(dropped)",
|
|
110
|
-
value,
|
|
111
|
-
reason: `${provider} reasoning model "${config.model}" does not support "${key}"`
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
params[key] = value;
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
config: { ...config, params },
|
|
120
|
-
provider,
|
|
121
|
-
subProvider,
|
|
122
|
-
changes
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
normalize
|
|
128
|
-
};
|