@aisa-one/cli 0.0.1 → 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.
Files changed (45) hide show
  1. package/README.md +203 -0
  2. package/dist/api.d.ts +11 -0
  3. package/dist/api.js +61 -0
  4. package/dist/commands/account.d.ts +5 -0
  5. package/dist/commands/account.js +47 -0
  6. package/dist/commands/api.d.ts +10 -0
  7. package/dist/commands/api.js +116 -0
  8. package/dist/commands/auth.d.ts +5 -0
  9. package/dist/commands/auth.js +29 -0
  10. package/dist/commands/chat.d.ts +8 -0
  11. package/dist/commands/chat.js +78 -0
  12. package/dist/commands/configCmd.d.ts +4 -0
  13. package/dist/commands/configCmd.js +36 -0
  14. package/dist/commands/finance.d.ts +13 -0
  15. package/dist/commands/finance.js +85 -0
  16. package/dist/commands/mcp.d.ts +4 -0
  17. package/dist/commands/mcp.js +67 -0
  18. package/dist/commands/models.d.ts +4 -0
  19. package/dist/commands/models.js +65 -0
  20. package/dist/commands/run.d.ts +7 -0
  21. package/dist/commands/run.js +70 -0
  22. package/dist/commands/search.d.ts +9 -0
  23. package/dist/commands/search.js +43 -0
  24. package/dist/commands/skills.d.ts +22 -0
  25. package/dist/commands/skills.js +555 -0
  26. package/dist/commands/twitter.d.ts +14 -0
  27. package/dist/commands/twitter.js +85 -0
  28. package/dist/commands/video.d.ts +9 -0
  29. package/dist/commands/video.js +73 -0
  30. package/dist/config.d.ts +10 -0
  31. package/dist/config.js +56 -0
  32. package/dist/constants.d.ts +14 -0
  33. package/dist/constants.js +43 -0
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.js +291 -0
  36. package/dist/types.d.ts +100 -0
  37. package/dist/types.js +1 -0
  38. package/dist/utils/display.d.ts +8 -0
  39. package/dist/utils/display.js +33 -0
  40. package/dist/utils/file.d.ts +12 -0
  41. package/dist/utils/file.js +70 -0
  42. package/dist/utils/streaming.d.ts +5 -0
  43. package/dist/utils/streaming.js +37 -0
  44. package/package.json +53 -5
  45. package/index.js +0 -3
@@ -0,0 +1,85 @@
1
+ import ora from "ora";
2
+ import { requireApiKey } from "../config.js";
3
+ import { apiRequest } from "../api.js";
4
+ import { error, formatJson } from "../utils/display.js";
5
+ const FIELD_ENDPOINTS = {
6
+ price: "stock/price",
7
+ earnings: "analyst-estimates",
8
+ financials: "financial-statements",
9
+ filings: "filings",
10
+ insider: "insider-trades",
11
+ institutional: "institutional-ownership",
12
+ };
13
+ export async function stockAction(symbol, options) {
14
+ const key = requireApiKey();
15
+ const field = options.field || "price";
16
+ const endpoint = FIELD_ENDPOINTS[field];
17
+ if (!endpoint) {
18
+ error(`Unknown field: ${field}. Valid: ${Object.keys(FIELD_ENDPOINTS).join(", ")}`);
19
+ return;
20
+ }
21
+ const spinner = ora(`Fetching ${field} for ${symbol.toUpperCase()}...`).start();
22
+ const res = await apiRequest(key, endpoint, {
23
+ query: { symbol: symbol.toUpperCase() },
24
+ });
25
+ if (!res.success) {
26
+ spinner.fail(`Failed to fetch ${field}`);
27
+ error(res.error || "Unknown error");
28
+ return;
29
+ }
30
+ spinner.stop();
31
+ if (options.raw) {
32
+ console.log(JSON.stringify(res.data));
33
+ }
34
+ else {
35
+ console.log(formatJson(res.data));
36
+ }
37
+ }
38
+ export async function cryptoAction(symbol, options) {
39
+ const key = requireApiKey();
40
+ const spinner = ora(`Fetching ${symbol.toUpperCase()}...`).start();
41
+ const query = { symbol: symbol.toUpperCase() };
42
+ if (options.period)
43
+ query.period = options.period;
44
+ const endpoint = options.period && options.period !== "current"
45
+ ? "crypto/price"
46
+ : "crypto/price/snapshot";
47
+ const res = await apiRequest(key, endpoint, { query });
48
+ if (!res.success) {
49
+ spinner.fail("Failed to fetch crypto price");
50
+ error(res.error || "Unknown error");
51
+ return;
52
+ }
53
+ spinner.stop();
54
+ if (options.raw) {
55
+ console.log(JSON.stringify(res.data));
56
+ }
57
+ else {
58
+ console.log(formatJson(res.data));
59
+ }
60
+ }
61
+ export async function screenerAction(options) {
62
+ const key = requireApiKey();
63
+ const spinner = ora("Running stock screener...").start();
64
+ const body = {};
65
+ if (options.sector)
66
+ body.sector = options.sector;
67
+ if (options.limit)
68
+ body.limit = parseInt(options.limit);
69
+ const res = await apiRequest(key, "search/financials", {
70
+ method: "POST",
71
+ body,
72
+ });
73
+ if (!res.success) {
74
+ spinner.fail("Screener failed");
75
+ error(res.error || "Unknown error");
76
+ return;
77
+ }
78
+ spinner.stop();
79
+ if (options.raw) {
80
+ console.log(JSON.stringify(res.data));
81
+ }
82
+ else {
83
+ console.log(formatJson(res.data));
84
+ }
85
+ }
@@ -0,0 +1,4 @@
1
+ export declare function mcpSetupAction(options: {
2
+ agent?: string;
3
+ }): void;
4
+ export declare function mcpStatusAction(): void;
@@ -0,0 +1,67 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import chalk from "chalk";
3
+ import { success, error, info, hint } from "../utils/display.js";
4
+ import { expandHome, ensureDir } from "../utils/file.js";
5
+ import { MCP_CONFIGS, MCP_URL } from "../constants.js";
6
+ import { join } from "node:path";
7
+ export function mcpSetupAction(options) {
8
+ const targets = options.agent && options.agent !== "all"
9
+ ? [options.agent]
10
+ : Object.keys(MCP_CONFIGS);
11
+ let configured = 0;
12
+ for (const agent of targets) {
13
+ const config = MCP_CONFIGS[agent];
14
+ if (!config) {
15
+ error(`Unknown agent: ${agent}. Valid: ${Object.keys(MCP_CONFIGS).join(", ")}, all`);
16
+ return;
17
+ }
18
+ const filePath = expandHome(config.path);
19
+ let existing = {};
20
+ if (existsSync(filePath)) {
21
+ try {
22
+ existing = JSON.parse(readFileSync(filePath, "utf-8"));
23
+ }
24
+ catch {
25
+ existing = {};
26
+ }
27
+ }
28
+ else {
29
+ ensureDir(join(filePath, ".."));
30
+ }
31
+ const servers = existing[config.key] || {};
32
+ servers["aisa"] = { url: MCP_URL };
33
+ existing[config.key] = servers;
34
+ writeFileSync(filePath, JSON.stringify(existing, null, 2) + "\n", "utf-8");
35
+ console.log(` ${chalk.green("✓")} ${agent}: ${config.path}`);
36
+ configured++;
37
+ }
38
+ if (configured > 0) {
39
+ success(`MCP server configured for ${configured} agent(s)`);
40
+ hint("Restart your agent/editor to activate");
41
+ }
42
+ }
43
+ export function mcpStatusAction() {
44
+ info(`MCP Server: ${MCP_URL}`);
45
+ for (const [agent, config] of Object.entries(MCP_CONFIGS)) {
46
+ const filePath = expandHome(config.path);
47
+ if (existsSync(filePath)) {
48
+ try {
49
+ const data = JSON.parse(readFileSync(filePath, "utf-8"));
50
+ const servers = data[config.key];
51
+ if (servers?.["aisa"]) {
52
+ console.log(` ${chalk.green("✓")} ${agent}: configured`);
53
+ }
54
+ else {
55
+ console.log(` ${chalk.gray("○")} ${agent}: not configured`);
56
+ }
57
+ }
58
+ catch {
59
+ console.log(` ${chalk.gray("○")} ${agent}: config unreadable`);
60
+ }
61
+ }
62
+ else {
63
+ console.log(` ${chalk.gray("○")} ${agent}: not installed`);
64
+ }
65
+ }
66
+ hint("Run 'aisa mcp setup' to configure");
67
+ }
@@ -0,0 +1,4 @@
1
+ export declare function modelsListAction(options: {
2
+ provider?: string;
3
+ }): Promise<void>;
4
+ export declare function modelsShowAction(modelId: string): Promise<void>;
@@ -0,0 +1,65 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ import { requireApiKey } from "../config.js";
4
+ import { apiRequest } from "../api.js";
5
+ import { error, badge } from "../utils/display.js";
6
+ export async function modelsListAction(options) {
7
+ const key = requireApiKey();
8
+ const spinner = ora("Fetching models...").start();
9
+ const query = {};
10
+ if (options.provider)
11
+ query.provider = options.provider;
12
+ const res = await apiRequest(key, "models", { query });
13
+ if (!res.success || !res.data) {
14
+ spinner.fail("Failed to fetch models");
15
+ error(res.error || "Unknown error");
16
+ return;
17
+ }
18
+ spinner.stop();
19
+ const models = res.data.data;
20
+ if (models.length === 0) {
21
+ console.log(" No models found.");
22
+ return;
23
+ }
24
+ // Group by provider
25
+ const grouped = {};
26
+ for (const m of models) {
27
+ const p = m.provider || "other";
28
+ if (!grouped[p])
29
+ grouped[p] = [];
30
+ grouped[p].push(m);
31
+ }
32
+ for (const [provider, pModels] of Object.entries(grouped)) {
33
+ console.log(`\n ${chalk.cyan.bold(provider.toUpperCase())}`);
34
+ for (const m of pModels) {
35
+ console.log(` ${chalk.white(m.id)}`);
36
+ }
37
+ }
38
+ console.log(chalk.gray(`\n ${models.length} models available`));
39
+ console.log(chalk.gray(" Run 'aisa models show <model-id>' for details"));
40
+ }
41
+ export async function modelsShowAction(modelId) {
42
+ const key = requireApiKey();
43
+ const spinner = ora(`Loading ${modelId}...`).start();
44
+ const res = await apiRequest(key, `models/${modelId}`);
45
+ if (!res.success || !res.data) {
46
+ spinner.fail("Model not found");
47
+ error(res.error || "Unknown error");
48
+ return;
49
+ }
50
+ spinner.stop();
51
+ const m = res.data;
52
+ console.log(`\n ${chalk.cyan.bold(m.name)} ${badge(m.provider)}`);
53
+ console.log(` ID: ${m.id}`);
54
+ if (m.contextWindow)
55
+ console.log(` Context: ${(m.contextWindow / 1000).toFixed(0)}k tokens`);
56
+ if (m.maxTokens)
57
+ console.log(` Max output: ${(m.maxTokens / 1000).toFixed(0)}k tokens`);
58
+ if (m.pricing) {
59
+ console.log(` Pricing: $${m.pricing.input}/M input, $${m.pricing.output}/M output`);
60
+ }
61
+ if (m.capabilities?.length) {
62
+ console.log(` Capabilities: ${m.capabilities.join(", ")}`);
63
+ }
64
+ console.log(chalk.gray(`\n Use: aisa chat "message" --model ${m.id}`));
65
+ }
@@ -0,0 +1,7 @@
1
+ export declare function runAction(slug: string, path: string, options: {
2
+ q?: string[];
3
+ d?: string;
4
+ method?: string;
5
+ raw?: boolean;
6
+ stream?: boolean;
7
+ }): Promise<void>;
@@ -0,0 +1,70 @@
1
+ import ora from "ora";
2
+ import { requireApiKey } from "../config.js";
3
+ import { apiRequest, apiRequestRaw } from "../api.js";
4
+ import { error, formatJson } from "../utils/display.js";
5
+ import { handleSSEStream } from "../utils/streaming.js";
6
+ export async function runAction(slug, path, options) {
7
+ const key = requireApiKey();
8
+ // Parse query params
9
+ const query = {};
10
+ if (options.q) {
11
+ for (const q of options.q) {
12
+ const pairs = q.split("&");
13
+ for (const pair of pairs) {
14
+ const eqIdx = pair.indexOf("=");
15
+ if (eqIdx > 0) {
16
+ query[pair.slice(0, eqIdx)] = pair.slice(eqIdx + 1);
17
+ }
18
+ }
19
+ }
20
+ }
21
+ // Parse body
22
+ let body;
23
+ if (options.d) {
24
+ try {
25
+ body = JSON.parse(options.d);
26
+ }
27
+ catch {
28
+ error("Invalid JSON body. Use -d '{\"key\": \"value\"}'");
29
+ process.exit(1);
30
+ }
31
+ }
32
+ // Detect method
33
+ const method = (options.method || (body ? "POST" : "GET")).toUpperCase();
34
+ const endpoint = `${slug}${path}`;
35
+ // Streaming mode
36
+ if (options.stream) {
37
+ const res = await apiRequestRaw(key, endpoint, {
38
+ method,
39
+ query: Object.keys(query).length > 0 ? query : undefined,
40
+ body,
41
+ headers: { Accept: "text/event-stream" },
42
+ });
43
+ if (!res.ok) {
44
+ const text = await res.text();
45
+ error(`${res.status}: ${text}`);
46
+ return;
47
+ }
48
+ await handleSSEStream(res, (token) => process.stdout.write(token), () => console.log());
49
+ return;
50
+ }
51
+ // Normal mode
52
+ const spinner = ora(`Calling ${slug} ${path}...`).start();
53
+ const res = await apiRequest(key, endpoint, {
54
+ method,
55
+ query: Object.keys(query).length > 0 ? query : undefined,
56
+ body,
57
+ });
58
+ if (!res.success) {
59
+ spinner.fail("API call failed");
60
+ error(res.error || "Unknown error");
61
+ return;
62
+ }
63
+ spinner.stop();
64
+ if (options.raw) {
65
+ console.log(JSON.stringify(res.data));
66
+ }
67
+ else {
68
+ console.log(formatJson(res.data));
69
+ }
70
+ }
@@ -0,0 +1,9 @@
1
+ export declare function webSearchAction(query: string, options: {
2
+ type?: string;
3
+ limit?: string;
4
+ raw?: boolean;
5
+ }): Promise<void>;
6
+ export declare function scholarAction(query: string, options: {
7
+ limit?: string;
8
+ raw?: boolean;
9
+ }): Promise<void>;
@@ -0,0 +1,43 @@
1
+ import ora from "ora";
2
+ import { requireApiKey } from "../config.js";
3
+ import { apiRequest } from "../api.js";
4
+ import { error, formatJson } from "../utils/display.js";
5
+ export async function webSearchAction(query, options) {
6
+ const key = requireApiKey();
7
+ const type = options.type || "smart";
8
+ const spinner = ora(`Searching (${type})...`).start();
9
+ const endpointMap = {
10
+ smart: { endpoint: "search/smart", method: "GET" },
11
+ full: { endpoint: "search/full", method: "GET" },
12
+ youtube: { endpoint: "youtube/search", method: "GET" },
13
+ scholar: { endpoint: "scholar/search", method: "POST" },
14
+ tavily: { endpoint: "tavily/search", method: "POST" },
15
+ };
16
+ const config = endpointMap[type];
17
+ if (!config) {
18
+ spinner.fail(`Unknown search type: ${type}`);
19
+ error("Valid types: smart, full, youtube, scholar, tavily");
20
+ return;
21
+ }
22
+ const res = await apiRequest(key, config.endpoint, {
23
+ method: config.method,
24
+ ...(config.method === "GET"
25
+ ? { query: { query, ...(options.limit ? { limit: options.limit } : {}) } }
26
+ : { body: { query, limit: parseInt(options.limit || "10") } }),
27
+ });
28
+ if (!res.success) {
29
+ spinner.fail("Search failed");
30
+ error(res.error || "Unknown error");
31
+ return;
32
+ }
33
+ spinner.stop();
34
+ if (options.raw) {
35
+ console.log(JSON.stringify(res.data));
36
+ }
37
+ else {
38
+ console.log(formatJson(res.data));
39
+ }
40
+ }
41
+ export async function scholarAction(query, options) {
42
+ return webSearchAction(query, { type: "scholar", ...options });
43
+ }
@@ -0,0 +1,22 @@
1
+ export declare function skillsListAction(options: {
2
+ category?: string;
3
+ limit?: string;
4
+ }): Promise<void>;
5
+ export declare function skillsSearchAction(query: string, options: {
6
+ limit?: string;
7
+ }): Promise<void>;
8
+ export declare function skillsShowAction(slug: string): Promise<void>;
9
+ export declare function skillsAddAction(slug: string, options: {
10
+ agent?: string;
11
+ }): Promise<void>;
12
+ export declare function skillsRemoveAction(slug: string, options: {
13
+ agent?: string;
14
+ }): Promise<void>;
15
+ export declare function skillsInitAction(name: string, options: {
16
+ template?: string;
17
+ bare?: boolean;
18
+ }): void;
19
+ export declare function skillsSubmitAction(path: string): Promise<void>;
20
+ export declare function skillsPushAction(slug: string): Promise<void>;
21
+ export declare function skillsVerifyAction(slug: string): Promise<void>;
22
+ export declare function skillsUpdateAction(slug?: string): Promise<void>;