@alexkroman1/aai-cli 1.8.3 → 1.9.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.
- package/dist/_agent-cHGzbDVG.mjs +108 -0
- package/dist/_api-client-yJD7xGfd.mjs +47 -0
- package/dist/_bundler-BRQFvx00.mjs +62 -0
- package/dist/_config-zV70t71V.mjs +125 -0
- package/dist/_dev-server-CBrIeDoI.mjs +214 -0
- package/dist/{_init-Bh5etNEh.mjs → _init-y7K-dzni.mjs} +17 -43
- package/dist/{_output-vvoR6N1x.mjs → _output-fy2bXRNb.mjs} +12 -19
- package/dist/{_ui-nOp7hFVy.mjs → _ui-YqQ6Fi8K.mjs} +14 -20
- package/dist/_utils-BeU10C7O.mjs +55 -0
- package/dist/_vite-env-CmXG4ZAu.mjs +31 -0
- package/dist/cli.mjs +41 -40
- package/dist/client-bundler-D4VKqCxw.mjs +125 -0
- package/dist/client-bundler.mjs +3 -0
- package/dist/{delete-BEC2ZXbk.mjs → delete-DE35s3d5.mjs} +7 -8
- package/dist/{deploy-D8uMWSDH.mjs → deploy-C0LittrE.mjs} +20 -18
- package/dist/{dev-D2EwGHYi.mjs → dev-BvjnXK2x.mjs} +10 -3
- package/dist/{init-GWTdzrrm.mjs → init-kYsRaf7e.mjs} +29 -75
- package/dist/{secret-DlSN4FdF.mjs → secret-D-90QtDQ.mjs} +14 -16
- package/dist/{test-BLYrV5ap.mjs → test-C6jwCnFu.mjs} +30 -5
- package/dist/types.mjs +2 -0
- package/dist/worker-bundler.mjs +68 -0
- package/package.json +24 -13
- package/dist/_agent-De8f1JdZ.mjs +0 -38
- package/dist/_api-client-Cf9Lv2Rw.mjs +0 -46
- package/dist/_bundler-CMMSjh9o.mjs +0 -143
- package/dist/_config-B0FXR5GQ.mjs +0 -77
- package/dist/_default-html-BasMCgr9.mjs +0 -62
- package/dist/_dev-server-DMFyqc9v.mjs +0 -143
- package/dist/_utils-DZo3_J_v.mjs +0 -23
- package/dist/rolldown-runtime-uZa2dNXj.mjs +0 -15
- /package/dist/{_server-common-BVkNI-o4.mjs → _server-common-QpOTRZgi.mjs} +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-uZa2dNXj.mjs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import * as p from "@clack/prompts";
|
|
5
|
-
import fs from "node:fs/promises";
|
|
6
|
-
import { consola } from "consola";
|
|
7
|
-
import os from "node:os";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
//#region _config.ts
|
|
10
|
-
var _config_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
-
ensureApiKey: () => ensureApiKey,
|
|
12
|
-
getConfigDir: () => getConfigDir,
|
|
13
|
-
readGlobalConfig: () => readGlobalConfig,
|
|
14
|
-
readProjectConfig: () => readProjectConfig,
|
|
15
|
-
writeGlobalConfig: () => writeGlobalConfig,
|
|
16
|
-
writeProjectConfig: () => writeProjectConfig
|
|
17
|
-
});
|
|
18
|
-
const ProjectConfigSchema = z.object({
|
|
19
|
-
slug: z.string(),
|
|
20
|
-
serverUrl: z.string(),
|
|
21
|
-
sessionId: z.string().optional()
|
|
22
|
-
});
|
|
23
|
-
function getConfigDir() {
|
|
24
|
-
if (process.platform === "win32") return path.join(process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming"), "aai");
|
|
25
|
-
return path.join(process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config"), "aai");
|
|
26
|
-
}
|
|
27
|
-
async function readProjectConfig(agentDir) {
|
|
28
|
-
try {
|
|
29
|
-
return ProjectConfigSchema.parse(JSON.parse(await fs.readFile(path.join(agentDir, ".aai", "project.json"), "utf-8")));
|
|
30
|
-
} catch (error) {
|
|
31
|
-
consola.debug(`Failed to read project config from ${path.join(agentDir, ".aai", "project.json")}:`, error);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async function writeProjectConfig(agentDir, data) {
|
|
36
|
-
const aaiDir = path.join(agentDir, ".aai");
|
|
37
|
-
await fs.mkdir(aaiDir, { recursive: true });
|
|
38
|
-
await fs.writeFile(path.join(aaiDir, "project.json"), `${JSON.stringify(data, null, 2)}\n`);
|
|
39
|
-
}
|
|
40
|
-
async function readGlobalConfig(configDir) {
|
|
41
|
-
const dir = configDir ?? getConfigDir();
|
|
42
|
-
try {
|
|
43
|
-
return JSON.parse(await fs.readFile(path.join(dir, "config.json"), "utf-8"));
|
|
44
|
-
} catch {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function writeGlobalConfig(configDir, data) {
|
|
49
|
-
await fs.mkdir(configDir, { recursive: true });
|
|
50
|
-
await fs.writeFile(path.join(configDir, "config.json"), `${JSON.stringify(data, null, 2)}\n`);
|
|
51
|
-
}
|
|
52
|
-
async function ensureApiKey(configDir) {
|
|
53
|
-
const dir = configDir ?? getConfigDir();
|
|
54
|
-
const config = await readGlobalConfig(dir);
|
|
55
|
-
if (config.apiKey) return config.apiKey;
|
|
56
|
-
const envKey = process.env.ASSEMBLYAI_API_KEY;
|
|
57
|
-
if (envKey) {
|
|
58
|
-
await writeGlobalConfig(dir, {
|
|
59
|
-
...config,
|
|
60
|
-
apiKey: envKey
|
|
61
|
-
});
|
|
62
|
-
return envKey;
|
|
63
|
-
}
|
|
64
|
-
const result = await p.password({ message: "Enter your AssemblyAI API key" });
|
|
65
|
-
if (p.isCancel(result)) {
|
|
66
|
-
p.cancel("Setup cancelled");
|
|
67
|
-
process.exit(0);
|
|
68
|
-
}
|
|
69
|
-
const apiKey = result;
|
|
70
|
-
await writeGlobalConfig(dir, {
|
|
71
|
-
...config,
|
|
72
|
-
apiKey
|
|
73
|
-
});
|
|
74
|
-
return apiKey;
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
export { writeProjectConfig as i, ensureApiKey as n, readProjectConfig as r, _config_exports as t };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
//#region _default-html.ts
|
|
5
|
-
/**
|
|
6
|
-
* Default index.html for agents with a custom client.tsx but no index.html.
|
|
7
|
-
* Used by both the dev server (Vite HMR) and the production bundler.
|
|
8
|
-
* Users can override by placing their own index.html in the project root.
|
|
9
|
-
*/
|
|
10
|
-
const DEFAULT_HTML = `<!DOCTYPE html>
|
|
11
|
-
<html lang="en">
|
|
12
|
-
<head>
|
|
13
|
-
<meta charset="UTF-8" />
|
|
14
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
15
|
-
<title>aai</title>
|
|
16
|
-
<link rel="icon" href="data:," />
|
|
17
|
-
<style>html, body { background: #101010; margin: 0; }</style>
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
<main id="app"></main>
|
|
21
|
-
<script type="module" src="./client.tsx"><\/script>
|
|
22
|
-
</body>
|
|
23
|
-
</html>`;
|
|
24
|
-
/**
|
|
25
|
-
* Vite plugin that serves a fallback index.html in dev mode when one doesn't
|
|
26
|
-
* exist on disk. No-op if index.html exists (user override).
|
|
27
|
-
*/
|
|
28
|
-
function fallbackHtmlPlugin(root) {
|
|
29
|
-
const htmlExists = existsSync(path.join(root, "index.html"));
|
|
30
|
-
return {
|
|
31
|
-
name: "aai-fallback-html",
|
|
32
|
-
configureServer(server) {
|
|
33
|
-
if (htmlExists) return;
|
|
34
|
-
server.middlewares.use((req, res, next) => {
|
|
35
|
-
if (req.url === "/" || req.url === "/index.html") {
|
|
36
|
-
server.transformIndexHtml("/", DEFAULT_HTML, req.originalUrl).then((html) => {
|
|
37
|
-
res.setHeader("Content-Type", "text/html");
|
|
38
|
-
res.end(html);
|
|
39
|
-
}, next);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
next();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Write a temporary index.html for Vite build (HTML must be on disk for build).
|
|
49
|
-
* Returns a cleanup function to remove it. No-op if index.html already exists.
|
|
50
|
-
*/
|
|
51
|
-
function writeTempHtml(root) {
|
|
52
|
-
const htmlPath = path.join(root, "index.html");
|
|
53
|
-
if (existsSync(htmlPath)) return () => {};
|
|
54
|
-
writeFileSync(htmlPath, DEFAULT_HTML);
|
|
55
|
-
return () => {
|
|
56
|
-
try {
|
|
57
|
-
unlinkSync(htmlPath);
|
|
58
|
-
} catch {}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
export { writeTempHtml as n, fallbackHtmlPlugin as t };
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { r as log } from "./_ui-nOp7hFVy.mjs";
|
|
3
|
-
import { r as validateAgentExport } from "./_utils-DZo3_J_v.mjs";
|
|
4
|
-
import { n as ensureApiKey } from "./_config-B0FXR5GQ.mjs";
|
|
5
|
-
import { t as fallbackHtmlPlugin } from "./_default-html-BasMCgr9.mjs";
|
|
6
|
-
import { t as resolveServerEnv } from "./_server-common-BVkNI-o4.mjs";
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
|
-
import { existsSync, watch } from "node:fs";
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import { pathToFileURL } from "node:url";
|
|
11
|
-
import { errorMessage } from "@alexkroman1/aai";
|
|
12
|
-
import pDebounce from "p-debounce";
|
|
13
|
-
//#region _dev-server.ts
|
|
14
|
-
/**
|
|
15
|
-
* Dev server for directory-based agents.
|
|
16
|
-
*
|
|
17
|
-
* Imports agent.ts directly for the full agent definition,
|
|
18
|
-
* builds a runtime, and starts an HTTP+WebSocket server. Watches for
|
|
19
|
-
* file changes and restarts automatically. Optionally runs Vite for
|
|
20
|
-
* client SPA HMR.
|
|
21
|
-
*/
|
|
22
|
-
async function resolveAgentEnv(root) {
|
|
23
|
-
const env = await resolveServerEnv(root);
|
|
24
|
-
if (!env.ASSEMBLYAI_API_KEY) env.ASSEMBLYAI_API_KEY = await ensureApiKey();
|
|
25
|
-
return env;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Load agent definition from agent.ts directly.
|
|
29
|
-
* Uses cache-busting query param for hot reload support.
|
|
30
|
-
*/
|
|
31
|
-
async function loadAgentDef(cwd) {
|
|
32
|
-
const agentDef = (await import(`${pathToFileURL(path.join(cwd, "agent.ts")).href}?t=${Date.now()}`)).default;
|
|
33
|
-
validateAgentExport(agentDef);
|
|
34
|
-
return agentDef;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Watch the agent directory for changes and call `onChange` when detected.
|
|
38
|
-
* Debounces to avoid rapid restarts.
|
|
39
|
-
*/
|
|
40
|
-
function watchDirectory(dir, onChange) {
|
|
41
|
-
const watchers = [];
|
|
42
|
-
const debouncedChange = pDebounce((filename) => {
|
|
43
|
-
log.info("File change detected, restarting...");
|
|
44
|
-
onChange(filename);
|
|
45
|
-
}, 300);
|
|
46
|
-
function handleChange(filename) {
|
|
47
|
-
if (filename && (filename.startsWith(".aai") || filename.includes("node_modules"))) return;
|
|
48
|
-
debouncedChange(filename);
|
|
49
|
-
}
|
|
50
|
-
watchers.push(watch(dir, { persistent: false }, (_event, filename) => handleChange(filename)));
|
|
51
|
-
return watchers;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Start the dev server for a directory-based agent.
|
|
55
|
-
*
|
|
56
|
-
* Returns a cleanup function to shut down the server and watchers.
|
|
57
|
-
*/
|
|
58
|
-
async function startDevServer(opts) {
|
|
59
|
-
const { cwd, port } = opts;
|
|
60
|
-
const { createRuntime, createServer } = await import("@alexkroman1/aai/runtime");
|
|
61
|
-
const hasClient = existsSync(path.join(cwd, "client.tsx"));
|
|
62
|
-
const backendPort = hasClient ? port + 1 : port;
|
|
63
|
-
const vitePort = port;
|
|
64
|
-
const agentDef = await loadAgentDef(cwd);
|
|
65
|
-
const env = await resolveAgentEnv(cwd);
|
|
66
|
-
const runtime = createRuntime({
|
|
67
|
-
agent: agentDef,
|
|
68
|
-
env
|
|
69
|
-
});
|
|
70
|
-
function resolveDefaultClientDir() {
|
|
71
|
-
const pkgPath = createRequire(import.meta.url).resolve("@alexkroman1/aai-ui/package.json");
|
|
72
|
-
return path.join(path.dirname(pkgPath), "dist", "default-client");
|
|
73
|
-
}
|
|
74
|
-
const agentServer = createServer({
|
|
75
|
-
runtime,
|
|
76
|
-
name: agentDef.name,
|
|
77
|
-
...hasClient ? {} : { clientDir: resolveDefaultClientDir() }
|
|
78
|
-
});
|
|
79
|
-
await agentServer.listen(backendPort);
|
|
80
|
-
let viteServer;
|
|
81
|
-
if (hasClient) {
|
|
82
|
-
const { createServer: createViteServer } = await import("vite");
|
|
83
|
-
const target = `http://localhost:${backendPort}`;
|
|
84
|
-
viteServer = await createViteServer({
|
|
85
|
-
root: cwd,
|
|
86
|
-
plugins: [fallbackHtmlPlugin(cwd)],
|
|
87
|
-
server: {
|
|
88
|
-
port: vitePort,
|
|
89
|
-
proxy: {
|
|
90
|
-
"/health": target,
|
|
91
|
-
"/websocket": {
|
|
92
|
-
target,
|
|
93
|
-
ws: true
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
await viteServer.listen();
|
|
99
|
-
}
|
|
100
|
-
let restarting = false;
|
|
101
|
-
let currentServer = agentServer;
|
|
102
|
-
let currentVite = viteServer;
|
|
103
|
-
let currentEnv = env;
|
|
104
|
-
const watchers = watchDirectory(cwd, () => {
|
|
105
|
-
if (restarting) return;
|
|
106
|
-
restarting = true;
|
|
107
|
-
restart().finally(() => {
|
|
108
|
-
restarting = false;
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
async function restart() {
|
|
112
|
-
try {
|
|
113
|
-
await currentServer.close();
|
|
114
|
-
} catch {}
|
|
115
|
-
try {
|
|
116
|
-
const newAgentDef = await loadAgentDef(cwd);
|
|
117
|
-
currentEnv = await resolveAgentEnv(cwd);
|
|
118
|
-
const newServer = createServer({
|
|
119
|
-
runtime: createRuntime({
|
|
120
|
-
agent: newAgentDef,
|
|
121
|
-
env: currentEnv
|
|
122
|
-
}),
|
|
123
|
-
name: newAgentDef.name,
|
|
124
|
-
...hasClient ? {} : { clientDir: resolveDefaultClientDir() }
|
|
125
|
-
});
|
|
126
|
-
await newServer.listen(backendPort);
|
|
127
|
-
currentServer = newServer;
|
|
128
|
-
log.success("Restarted");
|
|
129
|
-
} catch (err) {
|
|
130
|
-
log.error(`Restart failed: ${errorMessage(err)}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return async () => {
|
|
134
|
-
for (const w of watchers) w.close();
|
|
135
|
-
if (currentVite) {
|
|
136
|
-
await currentVite.close();
|
|
137
|
-
currentVite = void 0;
|
|
138
|
-
}
|
|
139
|
-
await currentServer.close();
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
//#endregion
|
|
143
|
-
export { startDevServer };
|
package/dist/_utils-DZo3_J_v.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import { consola } from "consola";
|
|
4
|
-
//#region _utils.ts
|
|
5
|
-
/** Resolve the working directory from INIT_CWD or process.cwd(). */
|
|
6
|
-
function resolveCwd() {
|
|
7
|
-
return process.env.INIT_CWD || process.cwd();
|
|
8
|
-
}
|
|
9
|
-
/** Validate that a module's default export is a valid agent definition. Throws if invalid. */
|
|
10
|
-
function validateAgentExport(mod) {
|
|
11
|
-
if (!mod?.name || typeof mod.name !== "string") throw new Error("agent.ts must export default agent({ name: ... })");
|
|
12
|
-
}
|
|
13
|
-
async function fileExists(p) {
|
|
14
|
-
try {
|
|
15
|
-
await fs.access(p);
|
|
16
|
-
return true;
|
|
17
|
-
} catch (error) {
|
|
18
|
-
consola.debug(`File access check failed for ${p}:`, error);
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { resolveCwd as n, validateAgentExport as r, fileExists as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "node:module";
|
|
3
|
-
//#region \0rolldown/runtime.js
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __exportAll = (all, no_symbols) => {
|
|
6
|
-
let target = {};
|
|
7
|
-
for (var name in all) __defProp(target, name, {
|
|
8
|
-
get: all[name],
|
|
9
|
-
enumerable: true
|
|
10
|
-
});
|
|
11
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
-
return target;
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
15
|
-
export { __exportAll as t };
|
|
File without changes
|