llm-strings 1.1.0 → 1.1.2

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/parse.cjs CHANGED
@@ -1,9 +1,62 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
-
4
- var _chunkN6NVBE43cjs = require('./chunk-N6NVBE43.cjs');
5
-
6
-
7
-
8
- exports.build = _chunkN6NVBE43cjs.build; exports.parse = _chunkN6NVBE43cjs.parse;
20
+ // src/parse.ts
21
+ var parse_exports = {};
22
+ __export(parse_exports, {
23
+ build: () => build,
24
+ parse: () => parse
25
+ });
26
+ module.exports = __toCommonJS(parse_exports);
27
+ function parse(connectionString) {
28
+ const url = new URL(connectionString);
29
+ if (url.protocol !== "llm:") {
30
+ throw new Error(
31
+ `Invalid scheme: expected "llm://", got "${url.protocol}//"`
32
+ );
33
+ }
34
+ const host = url.hostname;
35
+ const model = url.pathname.replace(/^\//, "");
36
+ const label = url.username || void 0;
37
+ const apiKey = url.password || void 0;
38
+ const params = {};
39
+ for (const [key, value] of url.searchParams) {
40
+ params[key] = value;
41
+ }
42
+ return {
43
+ raw: connectionString,
44
+ host,
45
+ model,
46
+ label,
47
+ apiKey,
48
+ params
49
+ };
50
+ }
51
+ function build(config) {
52
+ const auth = config.label || config.apiKey ? `${config.label ?? ""}${config.apiKey ? `:${config.apiKey}` : ""}@` : "";
53
+ const query = new URLSearchParams(config.params).toString();
54
+ const qs = query ? `?${query}` : "";
55
+ return `llm://${auth}${config.host}/${config.model}${qs}`;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ build,
60
+ parse
61
+ });
9
62
  //# sourceMappingURL=parse.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/dan/code/oss/llm-strings/dist/parse.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,iFAAC","file":"/Users/dan/code/oss/llm-strings/dist/parse.cjs"}
1
+ {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["export interface LlmConnectionConfig {\n /** The original connection string */\n raw: string;\n /** Provider's API base URL (e.g. \"api.openai.com\") */\n host: string;\n /** Model name (e.g. \"gpt-5.2\") */\n model: string;\n /** Optional label or app name */\n label?: string;\n /** Optional API key or password */\n apiKey?: string;\n /** Additional config parameters (temp, max_tokens, etc.) */\n params: Record<string, string>;\n}\n\n/**\n * Parse an LLM connection string into its component parts.\n *\n * Format: `llm://[label[:apiKey]@]host/model[?key=value&...]`\n *\n * @example\n * ```ts\n * parse(\"llm://api.openai.com/gpt-5.2?temp=0.7&max_tokens=1500\")\n * parse(\"llm://app-name:sk-proj-123456@api.openai.com/gpt-5.2?temp=0.7\")\n * ```\n */\nexport function parse(connectionString: string): LlmConnectionConfig {\n const url = new URL(connectionString);\n\n if (url.protocol !== \"llm:\") {\n throw new Error(\n `Invalid scheme: expected \"llm://\", got \"${url.protocol}//\"`,\n );\n }\n\n const host = url.hostname;\n const model = url.pathname.replace(/^\\//, \"\");\n const label = url.username || undefined;\n const apiKey = url.password || undefined;\n\n const params: Record<string, string> = {};\n for (const [key, value] of url.searchParams) {\n params[key] = value;\n }\n\n return {\n raw: connectionString,\n host,\n model,\n label,\n apiKey,\n params,\n };\n}\n\n/**\n * Build an LLM connection string from a config object.\n */\nexport function build(config: Omit<LlmConnectionConfig, \"raw\">): string {\n const auth =\n config.label || config.apiKey\n ? `${config.label ?? \"\"}${config.apiKey ? `:${config.apiKey}` : \"\"}@`\n : \"\";\n\n const query = new URLSearchParams(config.params).toString();\n const qs = query ? `?${query}` : \"\";\n\n return `llm://${auth}${config.host}/${config.model}${qs}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BO,SAAS,MAAM,kBAA+C;AACnE,QAAM,MAAM,IAAI,IAAI,gBAAgB;AAEpC,MAAI,IAAI,aAAa,QAAQ;AAC3B,UAAM,IAAI;AAAA,MACR,2CAA2C,IAAI,QAAQ;AAAA,IACzD;AAAA,EACF;AAEA,QAAM,OAAO,IAAI;AACjB,QAAM,QAAQ,IAAI,SAAS,QAAQ,OAAO,EAAE;AAC5C,QAAM,QAAQ,IAAI,YAAY;AAC9B,QAAM,SAAS,IAAI,YAAY;AAE/B,QAAM,SAAiC,CAAC;AACxC,aAAW,CAAC,KAAK,KAAK,KAAK,IAAI,cAAc;AAC3C,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO;AAAA,IACL,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,MAAM,QAAkD;AACtE,QAAM,OACJ,OAAO,SAAS,OAAO,SACnB,GAAG,OAAO,SAAS,EAAE,GAAG,OAAO,SAAS,IAAI,OAAO,MAAM,KAAK,EAAE,MAChE;AAEN,QAAM,QAAQ,IAAI,gBAAgB,OAAO,MAAM,EAAE,SAAS;AAC1D,QAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;AAEjC,SAAO,SAAS,IAAI,GAAG,OAAO,IAAI,IAAI,OAAO,KAAK,GAAG,EAAE;AACzD;","names":[]}
@@ -50,4 +50,4 @@ declare const CACHE_TTLS: Record<Provider, string[] | undefined>;
50
50
  /** Match a duration expression like "5m", "1h", "30m". */
51
51
  declare const DURATION_RE: RegExp;
52
52
 
53
- export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, PARAM_SPECS as P, REASONING_MODEL_UNSUPPORTED as R, PROVIDER_PARAMS as a, type ParamSpec as b, type Provider as c, canHostOpenAIModels as d, detectBedrockModelFamily as e, detectGatewaySubProvider as f, detectProvider as g, isReasoningModel as h, isGatewayProvider as i, CACHE_VALUES as j, bedrockSupportsCaching as k };
53
+ export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, CACHE_VALUES as a, PARAM_SPECS as b, PROVIDER_PARAMS as c, type ParamSpec as d, bedrockSupportsCaching as e, canHostOpenAIModels as f, detectBedrockModelFamily as g, detectGatewaySubProvider as h, detectProvider as i, isGatewayProvider as j, isReasoningModel as k };
@@ -50,4 +50,4 @@ declare const CACHE_TTLS: Record<Provider, string[] | undefined>;
50
50
  /** Match a duration expression like "5m", "1h", "30m". */
51
51
  declare const DURATION_RE: RegExp;
52
52
 
53
- export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, PARAM_SPECS as P, REASONING_MODEL_UNSUPPORTED as R, PROVIDER_PARAMS as a, type ParamSpec as b, type Provider as c, canHostOpenAIModels as d, detectBedrockModelFamily as e, detectGatewaySubProvider as f, detectProvider as g, isReasoningModel as h, isGatewayProvider as i, CACHE_VALUES as j, bedrockSupportsCaching as k };
53
+ export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, CACHE_VALUES as a, PARAM_SPECS as b, PROVIDER_PARAMS as c, type ParamSpec as d, bedrockSupportsCaching as e, canHostOpenAIModels as f, detectBedrockModelFamily as g, detectGatewaySubProvider as h, detectProvider as i, isGatewayProvider as j, isReasoningModel as k };