@aigentyc/chat-sdk 0.2.3 → 0.2.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/bin/aigentyc.mjs +45 -0
- package/bin/lib/add.mjs +267 -0
- package/bin/{doctor.mjs → lib/doctor.mjs} +2 -11
- package/bin/lib/io.mjs +59 -0
- package/context7.json +1 -1
- package/dist/{chunk-2677FDTG.js → chunk-FOZXDUSZ.js} +3 -3
- package/dist/{chunk-2677FDTG.js.map → chunk-FOZXDUSZ.js.map} +1 -1
- package/dist/{chunk-UKEL7FWS.js → chunk-IU7Q7O5G.js} +3 -2
- package/dist/chunk-IU7Q7O5G.js.map +1 -0
- package/dist/{chunk-WQARQ2FJ.cjs → chunk-MC6QDYB6.cjs} +4 -4
- package/dist/{chunk-WQARQ2FJ.cjs.map → chunk-MC6QDYB6.cjs.map} +1 -1
- package/dist/{chunk-7BNYTOTE.cjs → chunk-P3RPAI4F.cjs} +3 -2
- package/dist/chunk-P3RPAI4F.cjs.map +1 -0
- package/dist/components.cjs +13 -13
- package/dist/components.js +3 -3
- package/dist/hooks.cjs +2 -2
- package/dist/hooks.js +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.js +3 -3
- package/dist/theme.cjs +3 -3
- package/dist/theme.js +1 -1
- package/package.json +5 -3
- package/dist/chunk-7BNYTOTE.cjs.map +0 -1
- package/dist/chunk-UKEL7FWS.js.map +0 -1
package/bin/aigentyc.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* aigentyc — CLI router for @aigentyc/chat-sdk.
|
|
4
|
+
*
|
|
5
|
+
* Subcommands:
|
|
6
|
+
* doctor diagnose install / config issues
|
|
7
|
+
* add integrate the SDK into an existing project
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* npx @aigentyc/chat-sdk add
|
|
11
|
+
* npx @aigentyc/chat-sdk doctor
|
|
12
|
+
* npx @aigentyc/chat-sdk → shows help
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const sub = process.argv[2];
|
|
16
|
+
|
|
17
|
+
const HELP = `
|
|
18
|
+
aigentyc — CLI for @aigentyc/chat-sdk
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
npx @aigentyc/chat-sdk <command>
|
|
22
|
+
|
|
23
|
+
Commands:
|
|
24
|
+
add Integrate the SDK into an existing Vite/Next/CRA project
|
|
25
|
+
doctor Diagnose install + configuration
|
|
26
|
+
|
|
27
|
+
Docs: https://www.npmjs.com/package/@aigentyc/chat-sdk
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
31
|
+
console.log(HELP);
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (sub === "doctor") {
|
|
36
|
+
const { run } = await import("./lib/doctor.mjs");
|
|
37
|
+
await run();
|
|
38
|
+
} else if (sub === "add") {
|
|
39
|
+
const { run } = await import("./lib/add.mjs");
|
|
40
|
+
await run();
|
|
41
|
+
} else {
|
|
42
|
+
console.error(`\n Unknown command: ${sub}`);
|
|
43
|
+
console.log(HELP);
|
|
44
|
+
process.exit(2);
|
|
45
|
+
}
|
package/bin/lib/add.mjs
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aigentyc add` — integrate @aigentyc/chat-sdk into an existing project.
|
|
3
|
+
*
|
|
4
|
+
* Detects framework + package manager, installs the SDK, configures env vars,
|
|
5
|
+
* adds the required CSS import, and drops a starter component.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFile, writeFile, stat } from "node:fs/promises";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
import { C, text, select, note, closePrompts } from "./io.mjs";
|
|
13
|
+
|
|
14
|
+
const CWD = process.cwd();
|
|
15
|
+
|
|
16
|
+
function parseFlags(argv) {
|
|
17
|
+
const flags = {};
|
|
18
|
+
for (const a of argv) {
|
|
19
|
+
if (!a.startsWith("--")) continue;
|
|
20
|
+
const [k, v] = a.slice(2).split("=");
|
|
21
|
+
flags[k] = v ?? true;
|
|
22
|
+
}
|
|
23
|
+
return flags;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ---------- detection ----------
|
|
27
|
+
|
|
28
|
+
async function readJson(path) {
|
|
29
|
+
try { return JSON.parse(await readFile(path, "utf8")); } catch { return null; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function detectPM() {
|
|
33
|
+
if (existsSync(join(CWD, "pnpm-lock.yaml"))) return "pnpm";
|
|
34
|
+
if (existsSync(join(CWD, "yarn.lock"))) return "yarn";
|
|
35
|
+
if (existsSync(join(CWD, "bun.lockb")) || existsSync(join(CWD, "bun.lock"))) return "bun";
|
|
36
|
+
return "npm";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function detectFramework(pkg) {
|
|
40
|
+
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
41
|
+
if (deps.next) {
|
|
42
|
+
// App Router or Pages?
|
|
43
|
+
if (existsSync(join(CWD, "app")) || existsSync(join(CWD, "src/app"))) return "next-app";
|
|
44
|
+
if (existsSync(join(CWD, "pages")) || existsSync(join(CWD, "src/pages"))) return "next-pages";
|
|
45
|
+
return "next-app";
|
|
46
|
+
}
|
|
47
|
+
if (deps.vite || deps["@vitejs/plugin-react"]) return "vite";
|
|
48
|
+
if (deps["react-scripts"]) return "cra";
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function findFile(candidates) {
|
|
53
|
+
for (const c of candidates) {
|
|
54
|
+
const full = join(CWD, c);
|
|
55
|
+
try { await stat(full); return full; } catch { /* nope */ }
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function findEntry(framework) {
|
|
61
|
+
if (framework === "next-app") {
|
|
62
|
+
return findFile(["app/layout.tsx", "app/layout.jsx", "src/app/layout.tsx", "src/app/layout.jsx"]);
|
|
63
|
+
}
|
|
64
|
+
if (framework === "next-pages") {
|
|
65
|
+
return findFile(["pages/_app.tsx", "pages/_app.jsx", "src/pages/_app.tsx", "src/pages/_app.jsx"]);
|
|
66
|
+
}
|
|
67
|
+
if (framework === "vite") {
|
|
68
|
+
return findFile(["src/main.tsx", "src/main.jsx", "src/index.tsx", "src/index.jsx"]);
|
|
69
|
+
}
|
|
70
|
+
if (framework === "cra") {
|
|
71
|
+
return findFile(["src/index.tsx", "src/index.jsx", "src/index.js"]);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------- helpers ----------
|
|
77
|
+
|
|
78
|
+
function spawnP(cmd, args) {
|
|
79
|
+
return new Promise((resolveP, reject) => {
|
|
80
|
+
const proc = spawn(cmd, args, { stdio: "inherit", cwd: CWD });
|
|
81
|
+
proc.on("exit", (code) => (code === 0 ? resolveP() : reject(new Error(`${cmd} exited ${code}`))));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const CSS_IMPORT = `import "@aigentyc/chat-sdk/theme/styles.css";`;
|
|
86
|
+
|
|
87
|
+
async function addCssImport(entryPath) {
|
|
88
|
+
let src = await readFile(entryPath, "utf8");
|
|
89
|
+
if (src.includes("@aigentyc/chat-sdk/theme/styles.css")) {
|
|
90
|
+
return { added: false, reason: "already present" };
|
|
91
|
+
}
|
|
92
|
+
// Insert after the last existing import; fallback to top.
|
|
93
|
+
const importLines = [...src.matchAll(/^import .+;?$/gm)];
|
|
94
|
+
if (importLines.length > 0) {
|
|
95
|
+
const last = importLines[importLines.length - 1];
|
|
96
|
+
const insertAt = last.index + last[0].length;
|
|
97
|
+
src = src.slice(0, insertAt) + `\n${CSS_IMPORT}` + src.slice(insertAt);
|
|
98
|
+
} else {
|
|
99
|
+
src = `${CSS_IMPORT}\n${src}`;
|
|
100
|
+
}
|
|
101
|
+
await writeFile(entryPath, src);
|
|
102
|
+
return { added: true };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function envContent(framework, projectId, apiEndpoint, apiKey) {
|
|
106
|
+
const prefix = framework.startsWith("next") ? "NEXT_PUBLIC_AIGENTYC" : "VITE_AIGENTYC";
|
|
107
|
+
const lines = [
|
|
108
|
+
`${prefix}_PROJECT_ID=${projectId || "replace-me"}`,
|
|
109
|
+
`${prefix}_API_ENDPOINT=${apiEndpoint}`,
|
|
110
|
+
];
|
|
111
|
+
if (apiKey) lines.push(`${prefix}_API_KEY=${apiKey}`);
|
|
112
|
+
return { content: lines.join("\n") + "\n", filename: framework.startsWith("next") ? ".env.local" : ".env" };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function exampleSnippet(framework, mode, hasKey) {
|
|
116
|
+
const Comp = mode === "floating" ? "ChatWidget" : "Chat";
|
|
117
|
+
if (framework.startsWith("next")) {
|
|
118
|
+
const apiKeyProp = hasKey ? "\n apiKey={process.env.NEXT_PUBLIC_AIGENTYC_API_KEY}" : "";
|
|
119
|
+
return `import { ${Comp} } from "@aigentyc/chat-sdk";
|
|
120
|
+
|
|
121
|
+
export default function AigentycChat() {
|
|
122
|
+
return (
|
|
123
|
+
<${Comp}
|
|
124
|
+
projectId={process.env.NEXT_PUBLIC_AIGENTYC_PROJECT_ID!}
|
|
125
|
+
apiEndpoint={process.env.NEXT_PUBLIC_AIGENTYC_API_ENDPOINT!}${apiKeyProp}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
// vite / cra
|
|
132
|
+
const apiKeyLine = hasKey
|
|
133
|
+
? `const apiKey = import.meta.env.VITE_AIGENTYC_API_KEY as string | undefined;\n`
|
|
134
|
+
: "";
|
|
135
|
+
const apiKeyProp = hasKey ? " apiKey={apiKey}" : "";
|
|
136
|
+
return `import { ${Comp} } from "@aigentyc/chat-sdk";
|
|
137
|
+
|
|
138
|
+
const projectId = import.meta.env.VITE_AIGENTYC_PROJECT_ID as string;
|
|
139
|
+
const apiEndpoint = import.meta.env.VITE_AIGENTYC_API_ENDPOINT as string;
|
|
140
|
+
${apiKeyLine}
|
|
141
|
+
export function AigentycChat() {
|
|
142
|
+
return <${Comp} projectId={projectId} apiEndpoint={apiEndpoint}${apiKeyProp} />;
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ---------- main ----------
|
|
148
|
+
|
|
149
|
+
export async function run() {
|
|
150
|
+
const flags = parseFlags(process.argv.slice(3));
|
|
151
|
+
console.log("");
|
|
152
|
+
console.log(` ${C.bgCyan(" aigentyc add ")} ${C.dim("add @aigentyc/chat-sdk to this project")}\n`);
|
|
153
|
+
|
|
154
|
+
const pkg = await readJson(join(CWD, "package.json"));
|
|
155
|
+
if (!pkg) {
|
|
156
|
+
console.log(C.red(" ✗ No package.json in current directory."));
|
|
157
|
+
console.log(C.dim(" Run from your project root.\n"));
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const pm = detectPM();
|
|
162
|
+
const framework = await detectFramework(pkg);
|
|
163
|
+
|
|
164
|
+
if (!framework) {
|
|
165
|
+
console.log(C.red(" ✗ Could not detect Next.js / Vite / CRA in this project."));
|
|
166
|
+
console.log(C.dim(" Aigentyc Chat SDK requires React 19. Add manually if your stack is custom.\n"));
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log(` ${C.green("✓")} detected: ${C.bold(framework)} (package manager: ${pm})`);
|
|
171
|
+
|
|
172
|
+
// Prompts (or flags)
|
|
173
|
+
const mode = flags.mode || (await select({
|
|
174
|
+
message: "Chat layout",
|
|
175
|
+
options: [
|
|
176
|
+
{ value: "fullpage", label: "Full-page chat", hint: "<Chat />" },
|
|
177
|
+
{ value: "floating", label: "Floating widget", hint: "<ChatWidget />" },
|
|
178
|
+
],
|
|
179
|
+
initialIndex: 1,
|
|
180
|
+
}));
|
|
181
|
+
|
|
182
|
+
note("Get your credentials", [
|
|
183
|
+
`${C.dim("Dashboard:")} https://app.aigentyc.ai/dashboard`,
|
|
184
|
+
`Open your project, then ${C.bold("API Keys")} tab.`,
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
const projectId = flags["project-id"] ?? (await text({
|
|
188
|
+
message: "Aigentyc projectId",
|
|
189
|
+
placeholder: "proj_abc123 — leave blank to set later",
|
|
190
|
+
}));
|
|
191
|
+
|
|
192
|
+
if (projectId) {
|
|
193
|
+
note("API Keys page", [
|
|
194
|
+
C.cyan(`https://app.aigentyc.ai/dashboard/${projectId}/api-keys`),
|
|
195
|
+
`Permissions: ${C.bold("Chat → Full")}`,
|
|
196
|
+
`Allowed Origins: ${C.cyan(framework.startsWith("next") ? "http://localhost:3000" : "http://localhost:5173")}`,
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const apiKey = flags["api-key"] ?? (await text({
|
|
201
|
+
message: "Aigentyc apiKey",
|
|
202
|
+
placeholder: "tyco_pk_... — leave blank to set later",
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
const apiEndpoint = "https://app.aigentyc.ai";
|
|
206
|
+
closePrompts();
|
|
207
|
+
|
|
208
|
+
// ---- Install ----
|
|
209
|
+
console.log(`\n ${C.dim(`→ ${pm} install @aigentyc/chat-sdk...`)}\n`);
|
|
210
|
+
const installArgs = pm === "yarn" ? ["add", "@aigentyc/chat-sdk"] : ["install", "@aigentyc/chat-sdk"];
|
|
211
|
+
await spawnP(pm, installArgs);
|
|
212
|
+
|
|
213
|
+
// ---- Env ----
|
|
214
|
+
const env = envContent(framework, projectId, apiEndpoint, apiKey);
|
|
215
|
+
const envPath = join(CWD, env.filename);
|
|
216
|
+
if (existsSync(envPath)) {
|
|
217
|
+
const existing = await readFile(envPath, "utf8");
|
|
218
|
+
if (!existing.includes("AIGENTYC")) {
|
|
219
|
+
await writeFile(envPath, existing + "\n# Aigentyc Chat SDK\n" + env.content);
|
|
220
|
+
console.log(` ${C.green("✓")} appended Aigentyc env vars to ${env.filename}`);
|
|
221
|
+
} else {
|
|
222
|
+
console.log(` ${C.yellow("⚠")} ${env.filename} already has AIGENTYC vars — skipped`);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
await writeFile(envPath, env.content);
|
|
226
|
+
console.log(` ${C.green("✓")} created ${env.filename}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ---- CSS import ----
|
|
230
|
+
const entry = await findEntry(framework);
|
|
231
|
+
if (entry) {
|
|
232
|
+
const r = await addCssImport(entry);
|
|
233
|
+
if (r.added) console.log(` ${C.green("✓")} added CSS import to ${entry.replace(CWD + "/", "")}`);
|
|
234
|
+
else console.log(` ${C.yellow("⚠")} CSS import in ${entry.replace(CWD + "/", "")} — ${r.reason}`);
|
|
235
|
+
} else {
|
|
236
|
+
console.log(` ${C.yellow("⚠")} could not locate entry/layout file — add manually:`);
|
|
237
|
+
console.log(` ${C.dim(CSS_IMPORT)}`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ---- Example component ----
|
|
241
|
+
const componentDir = framework.startsWith("next") ? "components" : "src/components";
|
|
242
|
+
const componentPath = join(CWD, componentDir, "AigentycChat.tsx");
|
|
243
|
+
if (existsSync(componentPath)) {
|
|
244
|
+
console.log(` ${C.yellow("⚠")} ${componentDir}/AigentycChat.tsx already exists — skipped`);
|
|
245
|
+
} else {
|
|
246
|
+
await spawnP("mkdir", ["-p", join(CWD, componentDir)]);
|
|
247
|
+
await writeFile(componentPath, exampleSnippet(framework, mode, Boolean(apiKey)));
|
|
248
|
+
console.log(` ${C.green("✓")} wrote ${componentDir}/AigentycChat.tsx`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ---- Final note ----
|
|
252
|
+
console.log("");
|
|
253
|
+
console.log(C.bold(" Wired up. Use it from anywhere:"));
|
|
254
|
+
console.log("");
|
|
255
|
+
if (framework.startsWith("next")) {
|
|
256
|
+
console.log(` ${C.dim("// app/page.tsx")}`);
|
|
257
|
+
console.log(` import AigentycChat from "@/components/AigentycChat";`);
|
|
258
|
+
console.log(` export default function Home() { return <AigentycChat /> }`);
|
|
259
|
+
} else {
|
|
260
|
+
console.log(` ${C.dim("// src/App.tsx")}`);
|
|
261
|
+
console.log(` import { AigentycChat } from "./components/AigentycChat";`);
|
|
262
|
+
console.log(` export function App() { return <AigentycChat /> }`);
|
|
263
|
+
}
|
|
264
|
+
console.log("");
|
|
265
|
+
console.log(` ${C.dim("Verify install:")} npx @aigentyc/chat-sdk doctor`);
|
|
266
|
+
console.log("");
|
|
267
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* aigentyc doctor — diagnose Aigentyc Chat SDK install issues.
|
|
4
4
|
*
|
|
5
5
|
* Run inside a project that uses @aigentyc/chat-sdk:
|
|
6
|
-
* npx aigentyc doctor
|
|
6
|
+
* npx @aigentyc/chat-sdk doctor
|
|
7
7
|
*
|
|
8
8
|
* Checks (in order):
|
|
9
9
|
* 1. Node >= 18
|
|
@@ -22,13 +22,6 @@ import { readFile, readdir, stat } from "node:fs/promises";
|
|
|
22
22
|
import { existsSync } from "node:fs";
|
|
23
23
|
import { resolve, join } from "node:path";
|
|
24
24
|
|
|
25
|
-
const argv = process.argv.slice(2);
|
|
26
|
-
const sub = argv[0];
|
|
27
|
-
if (sub && sub !== "doctor") {
|
|
28
|
-
console.error(`Unknown command: ${sub}\nUsage: npx aigentyc doctor`);
|
|
29
|
-
process.exit(2);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
25
|
const CWD = process.cwd();
|
|
33
26
|
const C = {
|
|
34
27
|
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
@@ -121,7 +114,7 @@ async function pingEndpoint(url) {
|
|
|
121
114
|
// Checks
|
|
122
115
|
// ---------------------------------------------------------------------------
|
|
123
116
|
|
|
124
|
-
async function run() {
|
|
117
|
+
export async function run() {
|
|
125
118
|
console.log(C.bold("\n aigentyc doctor"));
|
|
126
119
|
console.log(C.dim(` cwd: ${CWD}\n`));
|
|
127
120
|
|
|
@@ -251,5 +244,3 @@ function finish() {
|
|
|
251
244
|
process.exit(1);
|
|
252
245
|
}
|
|
253
246
|
}
|
|
254
|
-
|
|
255
|
-
run();
|
package/bin/lib/io.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Tiny prompt + colors helpers — no deps. */
|
|
2
|
+
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
|
|
5
|
+
export const C = {
|
|
6
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
7
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
8
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
9
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
10
|
+
yellow: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
11
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
12
|
+
bgCyan: (s) => `\x1b[46m\x1b[30m${s}\x1b[0m`,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let _rl = null;
|
|
16
|
+
function getRl() {
|
|
17
|
+
if (!_rl) _rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
18
|
+
return _rl;
|
|
19
|
+
}
|
|
20
|
+
function ask(question) {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
getRl().question(question, (a) => resolve(a.trim()));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function closePrompts() {
|
|
26
|
+
if (_rl) { _rl.close(); _rl = null; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function text({ message, placeholder, defaultValue = "" }) {
|
|
30
|
+
const hint = placeholder ? C.dim(` (${placeholder})`) : "";
|
|
31
|
+
const def = defaultValue ? C.dim(` [${defaultValue}]`) : "";
|
|
32
|
+
const a = await ask(` ${C.cyan("?")} ${message}${hint}${def}: `);
|
|
33
|
+
return a || defaultValue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function select({ message, options, initialIndex = 0 }) {
|
|
37
|
+
console.log(`\n ${C.cyan("?")} ${message}`);
|
|
38
|
+
options.forEach((o, i) => {
|
|
39
|
+
const tag = i === initialIndex ? C.green("›") : " ";
|
|
40
|
+
const hint = o.hint ? C.dim(` — ${o.hint}`) : "";
|
|
41
|
+
console.log(` ${tag} ${i + 1}. ${o.label}${hint}`);
|
|
42
|
+
});
|
|
43
|
+
const a = await ask(` ${C.dim(`Pick 1-${options.length}`)} [${initialIndex + 1}]: `);
|
|
44
|
+
if (!a) return options[initialIndex].value;
|
|
45
|
+
const n = Number(a);
|
|
46
|
+
if (Number.isFinite(n) && n >= 1 && n <= options.length) return options[n - 1].value;
|
|
47
|
+
const byValue = options.find((o) => String(o.value).toLowerCase() === a.toLowerCase());
|
|
48
|
+
if (byValue) return byValue.value;
|
|
49
|
+
const byLabel = options.find((o) => String(o.label).toLowerCase().includes(a.toLowerCase()));
|
|
50
|
+
if (byLabel) return byLabel.value;
|
|
51
|
+
return options[initialIndex].value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function note(title, lines) {
|
|
55
|
+
const body = Array.isArray(lines) ? lines : [lines];
|
|
56
|
+
console.log(`\n ${C.bold(title)}`);
|
|
57
|
+
body.forEach((l) => console.log(` ${l}`));
|
|
58
|
+
console.log("");
|
|
59
|
+
}
|
package/context7.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useIsMobile, useLiveChat, usePreviewEmbed } from './chunk-5F3O3ZJH.js';
|
|
3
|
-
import { useTheme } from './chunk-
|
|
3
|
+
import { useTheme } from './chunk-IU7Q7O5G.js';
|
|
4
4
|
import { Conversation, ConversationContent, Sources, SourcesTrigger, SourcesContent, Source, Loader } from './chunk-A7PCSWIK.js';
|
|
5
5
|
import { useI18n } from './chunk-QYCEHFAB.js';
|
|
6
6
|
import { ToolRenderer } from './chunk-U3FXVLUK.js';
|
|
@@ -1675,5 +1675,5 @@ function PreviewEmbedPanel({ isOpen, isRightSide, zIndex }) {
|
|
|
1675
1675
|
}
|
|
1676
1676
|
|
|
1677
1677
|
export { CartDrawer, ChatFooter, ChatHeader, ChatInput, ChatInterface, FloatingButton, LiveChatPanel, MobileLiveChatDrawer, PreviewEmbedPanel, QuickQuestions, WelcomePage };
|
|
1678
|
-
//# sourceMappingURL=chunk-
|
|
1679
|
-
//# sourceMappingURL=chunk-
|
|
1678
|
+
//# sourceMappingURL=chunk-FOZXDUSZ.js.map
|
|
1679
|
+
//# sourceMappingURL=chunk-FOZXDUSZ.js.map
|