burnless 0.1.0

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,27 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __createRequire } from 'node:module';
3
+ import { fileURLToPath as __fileURLToPath } from 'node:url';
4
+ import { dirname as __pathDirname } from 'node:path';
5
+ const require = __createRequire(import.meta.url);
6
+ const __filename = __fileURLToPath(import.meta.url);
7
+ const __dirname = __pathDirname(__filename);
8
+
9
+ // src/errors.ts
10
+ var CliError = class extends Error {
11
+ constructor(message, exitCode = 1) {
12
+ super(message);
13
+ this.exitCode = exitCode;
14
+ this.name = "CliError";
15
+ }
16
+ };
17
+ var UsageError = class extends CliError {
18
+ constructor(message) {
19
+ super(message, 2);
20
+ this.name = "UsageError";
21
+ }
22
+ };
23
+
24
+ export {
25
+ CliError,
26
+ UsageError
27
+ };
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __createRequire } from 'node:module';
3
+ import { fileURLToPath as __fileURLToPath } from 'node:url';
4
+ import { dirname as __pathDirname } from 'node:path';
5
+ const require = __createRequire(import.meta.url);
6
+ const __filename = __fileURLToPath(import.meta.url);
7
+ const __dirname = __pathDirname(__filename);
8
+ import {
9
+ setInstanceEnvVar
10
+ } from "./chunk-CFKTW5EF.js";
11
+ import "./chunk-BN3QFA6Z.js";
12
+ import "./chunk-VKDF3OUE.js";
13
+ import {
14
+ defaultBaseUrl
15
+ } from "./chunk-OYCC45VC.js";
16
+ import "./chunk-BMDIVUSL.js";
17
+
18
+ // src/local/first-run-ai.ts
19
+ var KNOWN_KEY_ENVS = ["AI_API_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "OPENROUTER_API_KEY"];
20
+ function shouldOfferAiSetup(opts) {
21
+ if (!opts.isTTY) return false;
22
+ if (opts.env.AI_PROVIDER) return false;
23
+ return !KNOWN_KEY_ENVS.some((k) => (opts.env[k]?.length ?? 0) > 0);
24
+ }
25
+ function persistAiConfig(opts) {
26
+ const env = opts.env ?? process.env;
27
+ setInstanceEnvVar("AI_PROVIDER", opts.kind, opts.home);
28
+ setInstanceEnvVar("AI_API_KEY", opts.apiKey, opts.home);
29
+ env.AI_PROVIDER = opts.kind;
30
+ env.AI_API_KEY = opts.apiKey;
31
+ if (opts.baseUrl) {
32
+ setInstanceEnvVar("AI_BASE_URL", opts.baseUrl, opts.home);
33
+ env.AI_BASE_URL = opts.baseUrl;
34
+ }
35
+ }
36
+ async function runFirstRunAiSetup(deps) {
37
+ const kind = await deps.chooseKind();
38
+ if (!kind) return { configured: false };
39
+ const apiKey = await deps.readApiKey();
40
+ if (!apiKey) return { configured: false, detail: "no key entered" };
41
+ const baseUrl = defaultBaseUrl(kind);
42
+ if (baseUrl) {
43
+ const r = await deps.verify({ baseUrl, apiKey });
44
+ if (!r.ok) return { configured: false, detail: r.detail };
45
+ }
46
+ persistAiConfig({ kind, apiKey, baseUrl, home: deps.home, env: deps.env });
47
+ return { configured: true };
48
+ }
49
+ export {
50
+ persistAiConfig,
51
+ runFirstRunAiSetup,
52
+ shouldOfferAiSetup
53
+ };