libretto 0.6.4 → 0.6.5
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/cli/commands/setup.js +63 -0
- package/package.json +1 -1
- package/src/cli/commands/setup.ts +68 -0
|
@@ -19,6 +19,61 @@ import {
|
|
|
19
19
|
resolveAiSetupStatus
|
|
20
20
|
} from "../core/ai-model.js";
|
|
21
21
|
import { SimpleCLI } from "../framework/simple-cli.js";
|
|
22
|
+
const PROVIDER_SDK_PACKAGES = {
|
|
23
|
+
openai: "@ai-sdk/openai",
|
|
24
|
+
anthropic: "@ai-sdk/anthropic",
|
|
25
|
+
google: "@ai-sdk/google",
|
|
26
|
+
vertex: "@ai-sdk/google-vertex"
|
|
27
|
+
};
|
|
28
|
+
function detectPackageManager() {
|
|
29
|
+
if (existsSync(join(REPO_ROOT, "pnpm-lock.yaml"))) return "pnpm";
|
|
30
|
+
if (existsSync(join(REPO_ROOT, "yarn.lock"))) return "yarn";
|
|
31
|
+
if (existsSync(join(REPO_ROOT, "bun.lockb"))) return "bun";
|
|
32
|
+
return "npm";
|
|
33
|
+
}
|
|
34
|
+
function installCommand(pkgManager) {
|
|
35
|
+
switch (pkgManager) {
|
|
36
|
+
case "yarn":
|
|
37
|
+
return "yarn add";
|
|
38
|
+
case "bun":
|
|
39
|
+
return "bun add";
|
|
40
|
+
case "pnpm":
|
|
41
|
+
return "pnpm add";
|
|
42
|
+
default:
|
|
43
|
+
return "npm install";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isSdkInstalled(sdkPackage) {
|
|
47
|
+
try {
|
|
48
|
+
const result = spawnSync("node", ["-e", `require.resolve("${sdkPackage}")`], {
|
|
49
|
+
cwd: REPO_ROOT,
|
|
50
|
+
stdio: "pipe"
|
|
51
|
+
});
|
|
52
|
+
return result.status === 0;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function installSdkIfNeeded(provider) {
|
|
58
|
+
const sdkPackage = PROVIDER_SDK_PACKAGES[provider];
|
|
59
|
+
if (isSdkInstalled(sdkPackage)) return;
|
|
60
|
+
const pkgManager = detectPackageManager();
|
|
61
|
+
const cmd = installCommand(pkgManager);
|
|
62
|
+
console.log(`
|
|
63
|
+
Installing ${sdkPackage}...`);
|
|
64
|
+
const result = spawnSync(cmd, [sdkPackage], {
|
|
65
|
+
cwd: REPO_ROOT,
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
shell: true
|
|
68
|
+
});
|
|
69
|
+
if (result.status === 0) {
|
|
70
|
+
console.log(`\u2713 Installed ${sdkPackage}`);
|
|
71
|
+
} else {
|
|
72
|
+
console.error(
|
|
73
|
+
`\u2717 Failed to install ${sdkPackage}. Install it manually: ${cmd} ${sdkPackage}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
22
77
|
const PROVIDER_CHOICES = [
|
|
23
78
|
{
|
|
24
79
|
key: "1",
|
|
@@ -178,6 +233,7 @@ Unknown choice "${answer}". Skipping API setup.`);
|
|
|
178
233
|
console.log(`
|
|
179
234
|
Add ${selected.envVar} to your .env file:`);
|
|
180
235
|
console.log(` ${selected.envHint}`);
|
|
236
|
+
installSdkIfNeeded(selected.provider);
|
|
181
237
|
return true;
|
|
182
238
|
}
|
|
183
239
|
function printSkipMessage() {
|
|
@@ -273,6 +329,13 @@ function detectAgentDirs(root) {
|
|
|
273
329
|
function copySkills() {
|
|
274
330
|
const agentDirs = detectAgentDirs(REPO_ROOT);
|
|
275
331
|
if (agentDirs.length === 0) {
|
|
332
|
+
console.log(
|
|
333
|
+
"\n\u26A0 No .agents/ or .claude/ directory found. Libretto skills were not installed."
|
|
334
|
+
);
|
|
335
|
+
console.log(
|
|
336
|
+
" Create one of these directories in your repo root and rerun `npx libretto setup` to install skills:"
|
|
337
|
+
);
|
|
338
|
+
console.log(` mkdir ${join(REPO_ROOT, ".claude")}`);
|
|
276
339
|
return;
|
|
277
340
|
}
|
|
278
341
|
let skillsRoot;
|
package/package.json
CHANGED
|
@@ -22,6 +22,66 @@ import {
|
|
|
22
22
|
import type { Provider } from "../core/resolve-model.js";
|
|
23
23
|
import { SimpleCLI } from "../framework/simple-cli.js";
|
|
24
24
|
|
|
25
|
+
const PROVIDER_SDK_PACKAGES: Record<Provider, string> = {
|
|
26
|
+
openai: "@ai-sdk/openai",
|
|
27
|
+
anthropic: "@ai-sdk/anthropic",
|
|
28
|
+
google: "@ai-sdk/google",
|
|
29
|
+
vertex: "@ai-sdk/google-vertex",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function detectPackageManager(): string {
|
|
33
|
+
if (existsSync(join(REPO_ROOT, "pnpm-lock.yaml"))) return "pnpm";
|
|
34
|
+
if (existsSync(join(REPO_ROOT, "yarn.lock"))) return "yarn";
|
|
35
|
+
if (existsSync(join(REPO_ROOT, "bun.lockb"))) return "bun";
|
|
36
|
+
return "npm";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function installCommand(pkgManager: string): string {
|
|
40
|
+
switch (pkgManager) {
|
|
41
|
+
case "yarn":
|
|
42
|
+
return "yarn add";
|
|
43
|
+
case "bun":
|
|
44
|
+
return "bun add";
|
|
45
|
+
case "pnpm":
|
|
46
|
+
return "pnpm add";
|
|
47
|
+
default:
|
|
48
|
+
return "npm install";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isSdkInstalled(sdkPackage: string): boolean {
|
|
53
|
+
try {
|
|
54
|
+
const result = spawnSync("node", ["-e", `require.resolve("${sdkPackage}")`], {
|
|
55
|
+
cwd: REPO_ROOT,
|
|
56
|
+
stdio: "pipe",
|
|
57
|
+
});
|
|
58
|
+
return result.status === 0;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function installSdkIfNeeded(provider: Provider): void {
|
|
65
|
+
const sdkPackage = PROVIDER_SDK_PACKAGES[provider];
|
|
66
|
+
if (isSdkInstalled(sdkPackage)) return;
|
|
67
|
+
|
|
68
|
+
const pkgManager = detectPackageManager();
|
|
69
|
+
const cmd = installCommand(pkgManager);
|
|
70
|
+
console.log(`\nInstalling ${sdkPackage}...`);
|
|
71
|
+
const result = spawnSync(cmd, [sdkPackage], {
|
|
72
|
+
cwd: REPO_ROOT,
|
|
73
|
+
stdio: "inherit",
|
|
74
|
+
shell: true,
|
|
75
|
+
});
|
|
76
|
+
if (result.status === 0) {
|
|
77
|
+
console.log(`✓ Installed ${sdkPackage}`);
|
|
78
|
+
} else {
|
|
79
|
+
console.error(
|
|
80
|
+
`✗ Failed to install ${sdkPackage}. Install it manually: ${cmd} ${sdkPackage}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
25
85
|
export type ProviderChoice = {
|
|
26
86
|
key: string;
|
|
27
87
|
label: string;
|
|
@@ -250,6 +310,7 @@ async function promptProviderSelection(
|
|
|
250
310
|
console.log(`\n✓ ${selected.label} selected (model: ${model}).`);
|
|
251
311
|
console.log(`\nAdd ${selected.envVar} to your .env file:`);
|
|
252
312
|
console.log(` ${selected.envHint}`);
|
|
313
|
+
installSdkIfNeeded(selected.provider);
|
|
253
314
|
return true;
|
|
254
315
|
}
|
|
255
316
|
|
|
@@ -369,6 +430,13 @@ function copySkills(): void {
|
|
|
369
430
|
const agentDirs = detectAgentDirs(REPO_ROOT);
|
|
370
431
|
|
|
371
432
|
if (agentDirs.length === 0) {
|
|
433
|
+
console.log(
|
|
434
|
+
"\n⚠ No .agents/ or .claude/ directory found. Libretto skills were not installed.",
|
|
435
|
+
);
|
|
436
|
+
console.log(
|
|
437
|
+
" Create one of these directories in your repo root and rerun `npx libretto setup` to install skills:",
|
|
438
|
+
);
|
|
439
|
+
console.log(` mkdir ${join(REPO_ROOT, ".claude")}`);
|
|
372
440
|
return;
|
|
373
441
|
}
|
|
374
442
|
|