llm-exe 3.0.0 → 3.1.0-beta.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.
@@ -0,0 +1,39 @@
1
+ import {
2
+ createLlmExeError,
3
+ formatFromExtension,
4
+ parseExecutorConfig
5
+ } from "./chunk-2BUGTOKA.mjs";
6
+
7
+ // src/config/fromUrl.ts
8
+ async function loadConfigFromUrl(url, opts = {}) {
9
+ const { fetch: fetchImpl, init, format, ...patch } = opts;
10
+ const doFetch = fetchImpl ?? globalThis.fetch;
11
+ if (typeof doFetch !== "function") {
12
+ throw createLlmExeError(
13
+ {
14
+ code: "request.http_error",
15
+ message: () => `No fetch implementation available to load config from "${url}".`,
16
+ resolution: "Pass a `fetch` implementation in options, or run on a platform with a global fetch."
17
+ },
18
+ { url }
19
+ );
20
+ }
21
+ const response = await doFetch(url, init);
22
+ if (!response.ok) {
23
+ throw createLlmExeError(
24
+ {
25
+ code: "request.http_error",
26
+ message: (ctx) => `Failed to fetch config from "${ctx.url}": ${ctx.status ?? ""} ${ctx.statusText ?? ""}`.trim(),
27
+ resolution: "Check the URL is reachable and returns the config body."
28
+ },
29
+ { url, status: response.status, statusText: response.statusText }
30
+ );
31
+ }
32
+ const text = await response.text();
33
+ const resolvedFormat = format ?? formatFromExtension(url) ?? "auto";
34
+ return parseExecutorConfig(text, { format: resolvedFormat, ...patch });
35
+ }
36
+
37
+ export {
38
+ loadConfigFromUrl
39
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ configFileNotFoundError,
3
+ configFileReadFailedError,
4
+ executorFromConfig,
5
+ formatFromExtension,
6
+ parseExecutorConfig,
7
+ runConfig
8
+ } from "./chunk-2BUGTOKA.mjs";
9
+
10
+ // src/config/fromFile.ts
11
+ import { readFile } from "node:fs/promises";
12
+ async function loadConfigFromFile(path, patch) {
13
+ let text;
14
+ try {
15
+ text = await readFile(path, "utf8");
16
+ } catch (cause) {
17
+ const err = cause;
18
+ if (err?.code === "ENOENT") {
19
+ throw configFileNotFoundError({ path }, { cause });
20
+ }
21
+ throw configFileReadFailedError(
22
+ { path, syscall: err?.syscall, errno: err?.code },
23
+ { cause }
24
+ );
25
+ }
26
+ const format = formatFromExtension(path) ?? "auto";
27
+ return parseExecutorConfig(text, { format, ...patch ?? {} });
28
+ }
29
+ async function executorFromFile(path, patch, createOptions) {
30
+ return executorFromConfig(await loadConfigFromFile(path, patch), createOptions);
31
+ }
32
+ async function runFile(path, patch, overrides, createOptions) {
33
+ return runConfig(await loadConfigFromFile(path, patch), overrides, createOptions);
34
+ }
35
+
36
+ export {
37
+ loadConfigFromFile,
38
+ executorFromFile,
39
+ runFile
40
+ };
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node