@hsafa/cli 0.0.1
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/README.md +72 -0
- package/dist/commands/agent.js +853 -0
- package/dist/commands/auth.js +168 -0
- package/dist/commands/chat.js +233 -0
- package/dist/commands/doc.js +37 -0
- package/dist/commands/gql.js +106 -0
- package/dist/commands/invite.js +147 -0
- package/dist/commands/kb.js +155 -0
- package/dist/commands/key.js +87 -0
- package/dist/commands/mcp.js +56 -0
- package/dist/commands/member.js +103 -0
- package/dist/commands/profile.js +65 -0
- package/dist/commands/project.js +90 -0
- package/dist/commands/system.js +27 -0
- package/dist/commands/user.js +48 -0
- package/dist/commands/workspace.js +77 -0
- package/dist/index.js +56 -0
- package/dist/templates/basic-assistant.json +57 -0
- package/dist/templates/researcher.json +58 -0
- package/dist/utils/api.js +13 -0
- package/dist/utils/config.js +22 -0
- package/dist/utils/graphql.js +17 -0
- package/package.json +43 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import api from '../utils/api.js';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
export function registerWorkspaceCommands(program) {
|
|
6
|
+
const workspace = program.command('workspace').description('Workspace management');
|
|
7
|
+
workspace
|
|
8
|
+
.command('list')
|
|
9
|
+
.description('List all available workspaces')
|
|
10
|
+
.action(async () => {
|
|
11
|
+
const globalOptions = program.opts();
|
|
12
|
+
const spinner = !globalOptions.json ? ora('Fetching workspaces...').start() : null;
|
|
13
|
+
try {
|
|
14
|
+
const response = await api.get('/api/workspaces');
|
|
15
|
+
const workspaces = response.data;
|
|
16
|
+
if (spinner)
|
|
17
|
+
spinner.stop();
|
|
18
|
+
if (globalOptions.json) {
|
|
19
|
+
console.log(JSON.stringify(workspaces, null, 2));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (workspaces.length === 0) {
|
|
23
|
+
console.log(chalk.yellow('No workspaces found.'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const table = new Table({
|
|
27
|
+
head: [chalk.cyan('ID'), chalk.cyan('Name'), chalk.cyan('Description')],
|
|
28
|
+
colWidths: [36, 20, 40]
|
|
29
|
+
});
|
|
30
|
+
workspaces.forEach((w) => {
|
|
31
|
+
table.push([w.id, w.name, w.description || 'N/A']);
|
|
32
|
+
});
|
|
33
|
+
console.log(table.toString());
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (spinner)
|
|
37
|
+
spinner.fail(`Failed to fetch workspaces: ${error.message}`);
|
|
38
|
+
else
|
|
39
|
+
console.error(JSON.stringify({ error: error.message }));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
workspace
|
|
43
|
+
.command('projects <id>')
|
|
44
|
+
.description('List projects in a workspace')
|
|
45
|
+
.action(async (id) => {
|
|
46
|
+
const globalOptions = program.opts();
|
|
47
|
+
const spinner = !globalOptions.json ? ora('Fetching projects...').start() : null;
|
|
48
|
+
try {
|
|
49
|
+
const response = await api.get(`/api/workspaces/${id}/projects`);
|
|
50
|
+
const projects = response.data;
|
|
51
|
+
if (spinner)
|
|
52
|
+
spinner.stop();
|
|
53
|
+
if (globalOptions.json) {
|
|
54
|
+
console.log(JSON.stringify(projects, null, 2));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (projects.length === 0) {
|
|
58
|
+
console.log(chalk.yellow('No projects found in this workspace.'));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const table = new Table({
|
|
62
|
+
head: [chalk.cyan('ID'), chalk.cyan('Name'), chalk.cyan('Description')],
|
|
63
|
+
colWidths: [36, 20, 40]
|
|
64
|
+
});
|
|
65
|
+
projects.forEach((p) => {
|
|
66
|
+
table.push([p.id, p.name, p.description || 'N/A']);
|
|
67
|
+
});
|
|
68
|
+
console.log(table.toString());
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (spinner)
|
|
72
|
+
spinner.fail(`Failed to fetch projects: ${error.message}`);
|
|
73
|
+
else
|
|
74
|
+
console.error(JSON.stringify({ error: error.message }));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { registerAuthCommands } from './commands/auth.js';
|
|
5
|
+
import { registerAgentCommands } from './commands/agent.js';
|
|
6
|
+
import { registerChatCommands } from './commands/chat.js';
|
|
7
|
+
import { registerDocCommands } from './commands/doc.js';
|
|
8
|
+
import { registerKbCommands } from './commands/kb.js';
|
|
9
|
+
import { registerKeyCommands } from './commands/key.js';
|
|
10
|
+
import { registerProfileCommands } from './commands/profile.js';
|
|
11
|
+
import { registerProjectCommands } from './commands/project.js';
|
|
12
|
+
import { registerSystemCommands } from './commands/system.js';
|
|
13
|
+
import { registerUserCommands } from './commands/user.js';
|
|
14
|
+
import { registerMemberCommands } from './commands/member.js';
|
|
15
|
+
import { registerInviteCommands } from './commands/invite.js';
|
|
16
|
+
import { registerMcpCommands } from './commands/mcp.js';
|
|
17
|
+
import { registerWorkspaceCommands } from './commands/workspace.js';
|
|
18
|
+
import { registerGqlCommands } from './commands/gql.js';
|
|
19
|
+
import config from './utils/config.js';
|
|
20
|
+
const program = new Command();
|
|
21
|
+
program
|
|
22
|
+
.name('hsafa')
|
|
23
|
+
.description('CLI to control HSAFA without UI')
|
|
24
|
+
.version('0.0.1')
|
|
25
|
+
.option('--json', 'Output results in JSON format');
|
|
26
|
+
program
|
|
27
|
+
.command('config')
|
|
28
|
+
.description('Manage configuration')
|
|
29
|
+
.option('-s, --server <url>', 'Set server URL')
|
|
30
|
+
.action((options) => {
|
|
31
|
+
if (options.server) {
|
|
32
|
+
config.set('serverUrl', options.server);
|
|
33
|
+
console.log(chalk.green(`Server URL set to: ${options.server}`));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(chalk.cyan('Current configuration:'));
|
|
37
|
+
console.log(`Server URL: ${config.get('serverUrl')}`);
|
|
38
|
+
console.log(`Auth Token: ${config.get('token') ? '********' : 'Not set'}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
registerAuthCommands(program);
|
|
42
|
+
registerWorkspaceCommands(program);
|
|
43
|
+
registerAgentCommands(program);
|
|
44
|
+
registerChatCommands(program);
|
|
45
|
+
registerDocCommands(program);
|
|
46
|
+
registerKbCommands(program);
|
|
47
|
+
registerKeyCommands(program);
|
|
48
|
+
registerProfileCommands(program);
|
|
49
|
+
registerProjectCommands(program);
|
|
50
|
+
registerSystemCommands(program);
|
|
51
|
+
registerUserCommands(program);
|
|
52
|
+
registerMemberCommands(program);
|
|
53
|
+
registerInviteCommands(program);
|
|
54
|
+
registerMcpCommands(program);
|
|
55
|
+
registerGqlCommands(program);
|
|
56
|
+
program.parse();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Basic AI Assistant",
|
|
3
|
+
"description": "A versatile AI assistant with standard model and system prompt nodes.",
|
|
4
|
+
"nodes": [
|
|
5
|
+
{
|
|
6
|
+
"nodeId": "model-1",
|
|
7
|
+
"nodeType": "model",
|
|
8
|
+
"label": "Model",
|
|
9
|
+
"positionX": 100,
|
|
10
|
+
"positionY": 100,
|
|
11
|
+
"data": {
|
|
12
|
+
"provider": "openai",
|
|
13
|
+
"modelName": "gpt-4o-mini"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"nodeId": "system-1",
|
|
18
|
+
"nodeType": "system_prompt",
|
|
19
|
+
"label": "System Prompt",
|
|
20
|
+
"positionX": 100,
|
|
21
|
+
"positionY": 250,
|
|
22
|
+
"data": {
|
|
23
|
+
"systemPrompt": "You are a helpful and professional AI assistant. Provide concise and accurate answers."
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"nodeId": "temp-1",
|
|
28
|
+
"nodeType": "temperature",
|
|
29
|
+
"label": "Temperature",
|
|
30
|
+
"positionX": 100,
|
|
31
|
+
"positionY": 400,
|
|
32
|
+
"data": {
|
|
33
|
+
"temperature": 0.7
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"edges": [
|
|
38
|
+
{
|
|
39
|
+
"edgeId": "e1",
|
|
40
|
+
"sourceId": "model-1",
|
|
41
|
+
"targetId": "agent",
|
|
42
|
+
"edgeType": "default"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"edgeId": "e2",
|
|
46
|
+
"sourceId": "system-1",
|
|
47
|
+
"targetId": "agent",
|
|
48
|
+
"edgeType": "default"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"edgeId": "e3",
|
|
52
|
+
"sourceId": "temp-1",
|
|
53
|
+
"targetId": "agent",
|
|
54
|
+
"edgeType": "default"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "RAG Researcher",
|
|
3
|
+
"description": "An assistant optimized for searching and researching through Knowledge Bases.",
|
|
4
|
+
"nodes": [
|
|
5
|
+
{
|
|
6
|
+
"nodeId": "model-1",
|
|
7
|
+
"nodeType": "model",
|
|
8
|
+
"label": "Model",
|
|
9
|
+
"positionX": 100,
|
|
10
|
+
"positionY": 100,
|
|
11
|
+
"data": {
|
|
12
|
+
"provider": "openai",
|
|
13
|
+
"modelName": "gpt-4o"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"nodeId": "system-1",
|
|
18
|
+
"nodeType": "system_prompt",
|
|
19
|
+
"label": "Research Prompt",
|
|
20
|
+
"positionX": 100,
|
|
21
|
+
"positionY": 250,
|
|
22
|
+
"data": {
|
|
23
|
+
"systemPrompt": "You are a research assistant. Use the provided tools to search through knowledge bases and provide evidence-based answers. Cite your sources clearly."
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"nodeId": "tool-vector",
|
|
28
|
+
"nodeType": "tool_vector_search",
|
|
29
|
+
"label": "Knowledge Search",
|
|
30
|
+
"positionX": 400,
|
|
31
|
+
"positionY": 100,
|
|
32
|
+
"data": {
|
|
33
|
+
"toolTitle": "kbSearch",
|
|
34
|
+
"toolDescription": "Search through the connected knowledge bases for relevant information."
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"edges": [
|
|
39
|
+
{
|
|
40
|
+
"edgeId": "e1",
|
|
41
|
+
"sourceId": "model-1",
|
|
42
|
+
"targetId": "agent",
|
|
43
|
+
"edgeType": "default"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"edgeId": "e2",
|
|
47
|
+
"sourceId": "system-1",
|
|
48
|
+
"targetId": "agent",
|
|
49
|
+
"edgeType": "default"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"edgeId": "e3",
|
|
53
|
+
"sourceId": "tool-vector",
|
|
54
|
+
"targetId": "agent",
|
|
55
|
+
"edgeType": "default"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import config from './config.js';
|
|
3
|
+
const api = axios.create({
|
|
4
|
+
baseURL: config.get('serverUrl'),
|
|
5
|
+
});
|
|
6
|
+
api.interceptors.request.use((req) => {
|
|
7
|
+
const token = config.get('token');
|
|
8
|
+
if (token) {
|
|
9
|
+
req.headers.Cookie = `next-auth.session-token=${token}`;
|
|
10
|
+
}
|
|
11
|
+
return req;
|
|
12
|
+
});
|
|
13
|
+
export default api;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Conf from 'conf';
|
|
2
|
+
const schema = {
|
|
3
|
+
serverUrl: {
|
|
4
|
+
type: 'string',
|
|
5
|
+
default: 'https://server.hsafa.com',
|
|
6
|
+
},
|
|
7
|
+
token: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
profiles: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
default: {},
|
|
13
|
+
},
|
|
14
|
+
currentProfile: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const config = new Conf({
|
|
19
|
+
projectName: 'hsafa-cli',
|
|
20
|
+
schema,
|
|
21
|
+
});
|
|
22
|
+
export default config;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import api from './api.js';
|
|
2
|
+
export async function graphqlRequest(query, variables = {}, options = {}) {
|
|
3
|
+
try {
|
|
4
|
+
const response = await api.post('/api/graphql', {
|
|
5
|
+
query,
|
|
6
|
+
variables,
|
|
7
|
+
operationName: options.operationName,
|
|
8
|
+
});
|
|
9
|
+
if (response.data.errors) {
|
|
10
|
+
throw new Error(response.data.errors[0].message);
|
|
11
|
+
}
|
|
12
|
+
return response.data.data;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error(error.response?.data?.errors?.[0]?.message || error.message);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hsafa/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI to control HSAFA without UI",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"hsafa": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc && cp -r src/templates dist/",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"start": "node dist/index.js",
|
|
23
|
+
"prepublishOnly": "pnpm run build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios": "^1.6.7",
|
|
27
|
+
"chalk": "^5.3.0",
|
|
28
|
+
"cli-table3": "^0.6.3",
|
|
29
|
+
"commander": "^12.0.0",
|
|
30
|
+
"conf": "^12.0.0",
|
|
31
|
+
"dotenv": "^16.4.5",
|
|
32
|
+
"form-data": "^4.0.5",
|
|
33
|
+
"inquirer": "^9.2.15",
|
|
34
|
+
"open": "^11.0.0",
|
|
35
|
+
"ora": "^8.0.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/form-data": "^2.5.2",
|
|
39
|
+
"@types/inquirer": "^9.0.7",
|
|
40
|
+
"@types/node": "^20.11.20",
|
|
41
|
+
"typescript": "^5.3.3"
|
|
42
|
+
}
|
|
43
|
+
}
|