zhitalk 0.0.0 → 0.0.3
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/CLAUDE.md +98 -0
- package/README.md +36 -1
- package/dist/agent/agent.d.ts +24 -0
- package/dist/agent/agent.js +345 -0
- package/dist/agent/cli.d.ts +1 -0
- package/dist/agent/cli.js +185 -0
- package/dist/agent/colors.d.ts +19 -0
- package/dist/agent/colors.js +81 -0
- package/dist/agent/commands.d.ts +7 -0
- package/dist/agent/commands.js +69 -0
- package/dist/agent/config.d.ts +38 -0
- package/dist/agent/config.js +116 -0
- package/dist/agent/context.d.ts +3 -0
- package/dist/agent/context.js +107 -0
- package/dist/agent/db.d.ts +21 -0
- package/dist/agent/db.js +159 -0
- package/dist/agent/hooks.d.ts +27 -0
- package/dist/agent/hooks.js +115 -0
- package/dist/agent/mcp/client.d.ts +25 -0
- package/dist/agent/mcp/client.js +113 -0
- package/dist/agent/mcp/index.d.ts +4 -0
- package/dist/agent/mcp/index.js +27 -0
- package/dist/agent/mcp/wrapper.d.ts +7 -0
- package/dist/agent/mcp/wrapper.js +25 -0
- package/dist/agent/model.d.ts +5 -0
- package/dist/agent/model.js +31 -0
- package/dist/agent/permission/dangerous-path.json +115 -0
- package/dist/agent/permission/exec.d.ts +11 -0
- package/dist/agent/permission/exec.js +34 -0
- package/dist/agent/permission/is-dangerous-path.d.ts +1 -0
- package/dist/agent/permission/is-dangerous-path.js +53 -0
- package/dist/agent/permission/is-safe-domains.d.ts +1 -0
- package/dist/agent/permission/is-safe-domains.js +142 -0
- package/dist/agent/permission/network.d.ts +8 -0
- package/dist/agent/permission/network.js +14 -0
- package/dist/agent/permission/read.d.ts +9 -0
- package/dist/agent/permission/read.js +17 -0
- package/dist/agent/permission/util.d.ts +11 -0
- package/dist/agent/permission/util.js +160 -0
- package/dist/agent/permission/write.d.ts +11 -0
- package/dist/agent/permission/write.js +21 -0
- package/dist/agent/prompt.d.ts +1 -0
- package/dist/agent/prompt.js +50 -0
- package/dist/agent/skills.d.ts +8 -0
- package/dist/agent/skills.js +91 -0
- package/dist/agent/tools/agent_tool.d.ts +3 -0
- package/dist/agent/tools/agent_tool.js +44 -0
- package/dist/agent/tools/exec_tool.d.ts +3 -0
- package/dist/agent/tools/exec_tool.js +28 -0
- package/dist/agent/tools/load_skill_tool.d.ts +3 -0
- package/dist/agent/tools/load_skill_tool.js +15 -0
- package/dist/agent/tools/memory_create_tool.d.ts +6 -0
- package/dist/agent/tools/memory_create_tool.js +37 -0
- package/dist/agent/tools/memory_delete_tool.d.ts +3 -0
- package/dist/agent/tools/memory_delete_tool.js +28 -0
- package/dist/agent/tools/memory_retrieve_tool.d.ts +4 -0
- package/dist/agent/tools/memory_retrieve_tool.js +24 -0
- package/dist/agent/tools/profile_update_tool.d.ts +3 -0
- package/dist/agent/tools/profile_update_tool.js +50 -0
- package/dist/agent/tools/read_file_tool.d.ts +3 -0
- package/dist/agent/tools/read_file_tool.js +16 -0
- package/dist/agent/tools/run_js_tool.d.ts +3 -0
- package/dist/agent/tools/run_js_tool.js +36 -0
- package/dist/agent/tools/run_py_tool.d.ts +3 -0
- package/dist/agent/tools/run_py_tool.js +27 -0
- package/dist/agent/tools/search.d.ts +3 -0
- package/dist/agent/tools/search.js +10 -0
- package/dist/agent/tools/web_fetch_tool.d.ts +3 -0
- package/dist/agent/tools/web_fetch_tool.js +33 -0
- package/dist/agent/tools/web_search_tool.d.ts +3 -0
- package/dist/agent/tools/web_search_tool.js +38 -0
- package/dist/agent/tools/write_file_tool.d.ts +4 -0
- package/dist/agent/tools/write_file_tool.js +15 -0
- package/dist/agent/tools.d.ts +8 -0
- package/dist/agent/tools.js +193 -0
- package/dist/agent/utils.d.ts +2 -0
- package/dist/agent/utils.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +72 -0
- package/dist/install.d.ts +1 -0
- package/dist/install.js +108 -0
- package/package.json +43 -6
- package/index.js +0 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tools = exports.nativeTools = void 0;
|
|
4
|
+
exports.maybePersistedOutput = maybePersistedOutput;
|
|
5
|
+
exports.initTools = initTools;
|
|
6
|
+
const tools_1 = require("@langchain/core/tools");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const read_file_tool_1 = require("./tools/read_file_tool");
|
|
12
|
+
const write_file_tool_1 = require("./tools/write_file_tool");
|
|
13
|
+
const exec_tool_1 = require("./tools/exec_tool");
|
|
14
|
+
const run_js_tool_1 = require("./tools/run_js_tool");
|
|
15
|
+
const run_py_tool_1 = require("./tools/run_py_tool");
|
|
16
|
+
const web_search_tool_1 = require("./tools/web_search_tool");
|
|
17
|
+
const web_fetch_tool_1 = require("./tools/web_fetch_tool");
|
|
18
|
+
const load_skill_tool_1 = require("./tools/load_skill_tool");
|
|
19
|
+
const memory_create_tool_1 = require("./tools/memory_create_tool");
|
|
20
|
+
const memory_retrieve_tool_1 = require("./tools/memory_retrieve_tool");
|
|
21
|
+
const memory_delete_tool_1 = require("./tools/memory_delete_tool");
|
|
22
|
+
const profile_update_tool_1 = require("./tools/profile_update_tool");
|
|
23
|
+
const agent_tool_1 = require("./tools/agent_tool");
|
|
24
|
+
const mcp_1 = require("./mcp");
|
|
25
|
+
function createZhitalkTool(impl, options, permission_level) {
|
|
26
|
+
const t = (0, tools_1.tool)(impl, options);
|
|
27
|
+
t.permission_level = permission_level;
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
const readFileTool = createZhitalkTool(read_file_tool_1.readFileTool, {
|
|
31
|
+
name: 'read_file',
|
|
32
|
+
description: 'Read the contents of a file.',
|
|
33
|
+
schema: zod_1.z.object({
|
|
34
|
+
filepath: zod_1.z.string().describe('The path of the file to read. Can be relative, absolute, or start with ~.'),
|
|
35
|
+
}),
|
|
36
|
+
}, 'read');
|
|
37
|
+
const writeFileTool = createZhitalkTool(write_file_tool_1.writeFileTool, {
|
|
38
|
+
name: 'write_file',
|
|
39
|
+
description: 'Create or overwrite a file. Will create parent directories if needed.',
|
|
40
|
+
schema: zod_1.z.object({
|
|
41
|
+
filepath: zod_1.z.string().describe('The path of the file to write. Can be relative, absolute, or start with ~.'),
|
|
42
|
+
content: zod_1.z.string().describe('The content to write to the file.'),
|
|
43
|
+
}),
|
|
44
|
+
}, 'write');
|
|
45
|
+
const execTool = createZhitalkTool(exec_tool_1.execTool, {
|
|
46
|
+
name: 'exec',
|
|
47
|
+
description: 'Execute a safe shell command in the current directory. Dangerous commands (rm, rmdir, etc.), absolute paths, and parent directory references are blocked.',
|
|
48
|
+
schema: zod_1.z.object({
|
|
49
|
+
command: zod_1.z.string().describe('The shell command to execute.'),
|
|
50
|
+
}),
|
|
51
|
+
}, 'exec');
|
|
52
|
+
const runJsTool = createZhitalkTool(run_js_tool_1.runJsTool, {
|
|
53
|
+
name: 'run_js',
|
|
54
|
+
description: 'Execute JavaScript code using Node.js in the current directory. Returns stdout/stderr or error messages.',
|
|
55
|
+
schema: zod_1.z.object({
|
|
56
|
+
code: zod_1.z.string().describe('The JavaScript code to execute.'),
|
|
57
|
+
}),
|
|
58
|
+
}, 'exec');
|
|
59
|
+
const runPyTool = createZhitalkTool(run_py_tool_1.runPyTool, {
|
|
60
|
+
name: 'run_py',
|
|
61
|
+
description: 'Execute Python code using Python3 in the current directory. Returns stdout/stderr or error messages.',
|
|
62
|
+
schema: zod_1.z.object({
|
|
63
|
+
code: zod_1.z.string().describe('The Python code to execute.'),
|
|
64
|
+
}),
|
|
65
|
+
}, 'exec');
|
|
66
|
+
const webSearchTool = createZhitalkTool(web_search_tool_1.webSearchTool, {
|
|
67
|
+
name: 'web_search',
|
|
68
|
+
description: 'Search the web using Tavily. Useful for finding current information, news, and facts.',
|
|
69
|
+
schema: zod_1.z.object({
|
|
70
|
+
query: zod_1.z.string().describe('The search query.'),
|
|
71
|
+
}),
|
|
72
|
+
}, 'network');
|
|
73
|
+
const webFetchTool = createZhitalkTool(web_fetch_tool_1.webFetchTool, {
|
|
74
|
+
name: 'web_fetch',
|
|
75
|
+
description: 'Fetch the content of a web page by URL. Returns the raw HTML/text content. Useful when you need to read a specific page.',
|
|
76
|
+
schema: zod_1.z.object({
|
|
77
|
+
url: zod_1.z.string().describe('The full URL of the web page to fetch.'),
|
|
78
|
+
}),
|
|
79
|
+
}, 'network');
|
|
80
|
+
const loadSkillTool = createZhitalkTool(load_skill_tool_1.loadSkillTool, {
|
|
81
|
+
name: 'load_skill',
|
|
82
|
+
description: 'Load the full content of a skill by its name. Call this when you need to use a specific skill to handle the user request. You can only load one skill at a time.',
|
|
83
|
+
schema: zod_1.z.object({
|
|
84
|
+
name: zod_1.z.string().describe('The name of the skill to load.'),
|
|
85
|
+
}),
|
|
86
|
+
}, 'read');
|
|
87
|
+
const memoryCreateTool = createZhitalkTool(memory_create_tool_1.memoryCreateTool, {
|
|
88
|
+
name: 'memory_create',
|
|
89
|
+
description: 'Save a piece of memory to the database. Use this when the user shares something worth remembering, such as a personal fact, event, preference, or skill.',
|
|
90
|
+
schema: zod_1.z.object({
|
|
91
|
+
type: zod_1.z
|
|
92
|
+
.enum(['fact', 'event', 'preference', 'skill'])
|
|
93
|
+
.describe('The type of memory to save.'),
|
|
94
|
+
content: zod_1.z
|
|
95
|
+
.string()
|
|
96
|
+
.describe('The natural language description of the memory.'),
|
|
97
|
+
keywords: zod_1.z
|
|
98
|
+
.array(zod_1.z.string())
|
|
99
|
+
.optional()
|
|
100
|
+
.describe('Optional keywords for retrieval, as an array of strings.'),
|
|
101
|
+
importance: zod_1.z
|
|
102
|
+
.number()
|
|
103
|
+
.min(1)
|
|
104
|
+
.max(5)
|
|
105
|
+
.optional()
|
|
106
|
+
.describe('Importance level from 1 to 5. Default is 3.'),
|
|
107
|
+
}),
|
|
108
|
+
}, 'db');
|
|
109
|
+
const memoryRetrieveTool = createZhitalkTool(memory_retrieve_tool_1.memoryRetrieveTool, {
|
|
110
|
+
name: 'memory_retrieve',
|
|
111
|
+
description: 'Retrieve relevant memories from the database using full-text search. Use this when the user asks about something that may have been remembered before but is not in the current conversation context. Extract a few key keywords from the question and pass them as the query.',
|
|
112
|
+
schema: zod_1.z.object({
|
|
113
|
+
query: zod_1.z
|
|
114
|
+
.array(zod_1.z.string())
|
|
115
|
+
.describe('Keywords to search for in memories.'),
|
|
116
|
+
limit: zod_1.z
|
|
117
|
+
.number()
|
|
118
|
+
.min(1)
|
|
119
|
+
.max(50)
|
|
120
|
+
.optional()
|
|
121
|
+
.describe('Maximum number of memories to return. Default is 10.'),
|
|
122
|
+
}),
|
|
123
|
+
}, 'db');
|
|
124
|
+
const memoryDeleteTool = createZhitalkTool(memory_delete_tool_1.memoryDeleteTool, {
|
|
125
|
+
name: 'memory_delete',
|
|
126
|
+
description: 'Delete a memory from the database by its id. Use this when the user wants to forget or remove a specific memory.',
|
|
127
|
+
schema: zod_1.z.object({
|
|
128
|
+
id: zod_1.z
|
|
129
|
+
.number()
|
|
130
|
+
.int()
|
|
131
|
+
.positive()
|
|
132
|
+
.describe('The id of the memory to delete.'),
|
|
133
|
+
}),
|
|
134
|
+
}, 'db');
|
|
135
|
+
const profileUpdateTool = createZhitalkTool(profile_update_tool_1.profileUpdateTool, {
|
|
136
|
+
name: 'profile_update',
|
|
137
|
+
description: "Update the user's profile information. When providing new profile info, also include all other fields mentioned in <profile_info> — all profile information must be updated together.",
|
|
138
|
+
schema: zod_1.z.object({
|
|
139
|
+
profile_info: zod_1.z
|
|
140
|
+
.string()
|
|
141
|
+
.describe('The complete profile information in markdown format, including all existing and updated fields.'),
|
|
142
|
+
}),
|
|
143
|
+
}, 'write');
|
|
144
|
+
const agentTool = createZhitalkTool(agent_tool_1.agentTool, {
|
|
145
|
+
name: 'agent_tool',
|
|
146
|
+
description: 'Launch a sub-agent to execute an independent task. The sub-agent has access to all tools (except this one), skills, memory, and hooks. It will run to completion and return its final result. Use this for tasks that can be delegated, such as research, code generation, or data processing.',
|
|
147
|
+
schema: zod_1.z.object({
|
|
148
|
+
prompt: zod_1.z
|
|
149
|
+
.string()
|
|
150
|
+
.describe('A clear, self-contained task prompt for the sub-agent. It should include all necessary context because the sub-agent cannot see the current conversation history.'),
|
|
151
|
+
}),
|
|
152
|
+
}, 'exec');
|
|
153
|
+
async function maybePersistedOutput(content, toolCallId) {
|
|
154
|
+
const MAX_LENGTH = 50000;
|
|
155
|
+
if (content.length <= MAX_LENGTH) {
|
|
156
|
+
return content;
|
|
157
|
+
}
|
|
158
|
+
const id = toolCallId || Math.random().toString(36).slice(2, 9);
|
|
159
|
+
const dir = (0, path_1.resolve)(config_1.WORKSPACE_DIR, '.tool_output');
|
|
160
|
+
const filePath = (0, path_1.resolve)(dir, `tool_output_${id}.txt`);
|
|
161
|
+
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
162
|
+
await (0, promises_1.writeFile)(filePath, content, 'utf-8');
|
|
163
|
+
return `<persisted-output>
|
|
164
|
+
Output too large (${(content.length / 1024).toFixed(1)}KB).
|
|
165
|
+
Full output saved to: ${filePath}
|
|
166
|
+
|
|
167
|
+
If you need the complete content, it is recommended to read it in segments.
|
|
168
|
+
|
|
169
|
+
Preview (first 2KB):
|
|
170
|
+
${content.slice(0, 2000)}
|
|
171
|
+
...
|
|
172
|
+
</persisted-output>`;
|
|
173
|
+
}
|
|
174
|
+
exports.nativeTools = [
|
|
175
|
+
readFileTool,
|
|
176
|
+
writeFileTool,
|
|
177
|
+
execTool,
|
|
178
|
+
runJsTool,
|
|
179
|
+
runPyTool,
|
|
180
|
+
webSearchTool,
|
|
181
|
+
webFetchTool,
|
|
182
|
+
loadSkillTool,
|
|
183
|
+
memoryCreateTool,
|
|
184
|
+
memoryRetrieveTool,
|
|
185
|
+
memoryDeleteTool,
|
|
186
|
+
profileUpdateTool,
|
|
187
|
+
agentTool,
|
|
188
|
+
];
|
|
189
|
+
exports.tools = [...exports.nativeTools];
|
|
190
|
+
async function initTools() {
|
|
191
|
+
const mcpTools = await (0, mcp_1.initMcpTools)();
|
|
192
|
+
exports.tools = [...exports.nativeTools, ...mcpTools];
|
|
193
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
4
|
+
exports.truncate = truncate;
|
|
5
|
+
function formatRelativeTime(ts) {
|
|
6
|
+
const diffMs = Date.now() - new Date(ts).getTime();
|
|
7
|
+
const diffMin = Math.floor(diffMs / 60000);
|
|
8
|
+
const diffHour = Math.floor(diffMin / 60);
|
|
9
|
+
const diffDay = Math.floor(diffHour / 24);
|
|
10
|
+
if (diffMin < 1)
|
|
11
|
+
return '刚刚';
|
|
12
|
+
if (diffMin < 5)
|
|
13
|
+
return '5分钟内';
|
|
14
|
+
if (diffMin < 10)
|
|
15
|
+
return '10分钟内';
|
|
16
|
+
if (diffMin < 30)
|
|
17
|
+
return '30分钟内';
|
|
18
|
+
if (diffMin < 60)
|
|
19
|
+
return '1小时内';
|
|
20
|
+
if (diffHour < 24)
|
|
21
|
+
return `${diffHour}小时内`;
|
|
22
|
+
if (diffDay < 2)
|
|
23
|
+
return '1天前';
|
|
24
|
+
return `${diffDay}天前`;
|
|
25
|
+
}
|
|
26
|
+
function truncate(str, maxLen) {
|
|
27
|
+
if (!str)
|
|
28
|
+
return '-';
|
|
29
|
+
return str.length > maxLen ? str.slice(0, maxLen) + '...' : str;
|
|
30
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const commander_1 = require("commander");
|
|
38
|
+
const fs_1 = require("fs");
|
|
39
|
+
const path_1 = require("path");
|
|
40
|
+
const config_1 = require("./agent/config");
|
|
41
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf-8'));
|
|
42
|
+
async function main() {
|
|
43
|
+
if (!(0, fs_1.existsSync)(config_1.CONFIG_PATH)) {
|
|
44
|
+
const { runInstall } = await Promise.resolve().then(() => __importStar(require('./install')));
|
|
45
|
+
await runInstall();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const { initColors } = await Promise.resolve().then(() => __importStar(require('./agent/colors')));
|
|
49
|
+
const { initDb } = await Promise.resolve().then(() => __importStar(require('./agent/db')));
|
|
50
|
+
const { initAgent } = await Promise.resolve().then(() => __importStar(require('./agent/agent')));
|
|
51
|
+
const { interactiveChat } = await Promise.resolve().then(() => __importStar(require('./agent/cli')));
|
|
52
|
+
const { shutdownMcp } = await Promise.resolve().then(() => __importStar(require('./agent/mcp')));
|
|
53
|
+
const { checkModel } = await Promise.resolve().then(() => __importStar(require('./agent/model')));
|
|
54
|
+
await initColors();
|
|
55
|
+
await checkModel();
|
|
56
|
+
initDb();
|
|
57
|
+
await initAgent();
|
|
58
|
+
process.once('SIGINT', async () => {
|
|
59
|
+
await shutdownMcp();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
});
|
|
62
|
+
const program = new commander_1.Command();
|
|
63
|
+
program.name(pkg.name).description(pkg.description).version(pkg.version);
|
|
64
|
+
if (process.argv.length > 2) {
|
|
65
|
+
program.parse();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
await interactiveChat();
|
|
69
|
+
}
|
|
70
|
+
await shutdownMcp();
|
|
71
|
+
}
|
|
72
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runInstall(): Promise<void>;
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runInstall = runInstall;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
const child_process_1 = require("child_process");
|
|
41
|
+
const config_1 = require("./agent/config");
|
|
42
|
+
const db_1 = require("./agent/db");
|
|
43
|
+
const SKILLS_DIR = path.join(config_1.WORKSPACE_DIR, '.agents', 'skills');
|
|
44
|
+
function run(command) {
|
|
45
|
+
(0, child_process_1.execSync)(command, { stdio: 'inherit' });
|
|
46
|
+
}
|
|
47
|
+
function installSkill(name, repo, skillPath, targetDir, tempDir) {
|
|
48
|
+
if (fs.existsSync(targetDir)) {
|
|
49
|
+
console.log(` ✅ ${name} 已存在,跳过`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.log(` 📥 正在下载 ${name}...`);
|
|
53
|
+
const tarPath = path.join(tempDir, `${name}.tar.gz`);
|
|
54
|
+
const extractDir = path.join(tempDir, `${name}-extract`);
|
|
55
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
56
|
+
run(`curl -fsSL -o "${tarPath}" "https://github.com/${repo}/archive/refs/heads/main.tar.gz"`);
|
|
57
|
+
run(`tar -xzf "${tarPath}" -C "${extractDir}"`);
|
|
58
|
+
const subDir = fs.readdirSync(extractDir)[0];
|
|
59
|
+
fs.cpSync(path.join(extractDir, subDir, skillPath), targetDir, {
|
|
60
|
+
recursive: true,
|
|
61
|
+
});
|
|
62
|
+
console.log(` ✅ ${name} 安装完成`);
|
|
63
|
+
}
|
|
64
|
+
async function runInstall() {
|
|
65
|
+
console.log('🚀 欢迎使用 Zhitalk!首次使用需要进行初始化配置。\n');
|
|
66
|
+
// 1. 初始化数据库
|
|
67
|
+
console.log('📦 正在初始化数据库...');
|
|
68
|
+
(0, db_1.initDb)();
|
|
69
|
+
console.log('✅ 数据库初始化完成\n');
|
|
70
|
+
// 2. 安装 skills
|
|
71
|
+
console.log('🔧 正在安装默认 skills...');
|
|
72
|
+
fs.mkdirSync(SKILLS_DIR, { recursive: true });
|
|
73
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'zhitalk-'));
|
|
74
|
+
try {
|
|
75
|
+
installSkill('find-skills', 'vercel-labs/skills', 'skills/find-skills', path.join(SKILLS_DIR, 'find-skills'), tempDir);
|
|
76
|
+
installSkill('skill-creator', 'anthropics/skills', 'skills/skill-creator', path.join(SKILLS_DIR, 'skill-creator'), tempDir);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
console.log('✅ Skills 安装完成\n');
|
|
82
|
+
// 3. 创建配置文件
|
|
83
|
+
console.log('⚙️ 正在创建配置文件...');
|
|
84
|
+
const configTemplate = {
|
|
85
|
+
model: {
|
|
86
|
+
model: 'kimi-k2.6',
|
|
87
|
+
apiKey: 'your-api-key',
|
|
88
|
+
baseURL: 'https://api.moonshot.cn/v1',
|
|
89
|
+
},
|
|
90
|
+
env: {
|
|
91
|
+
TAVILY_API_KEY: 'your-tavily-api-key',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
fs.mkdirSync(path.dirname(config_1.CONFIG_PATH), { recursive: true });
|
|
95
|
+
fs.writeFileSync(config_1.CONFIG_PATH, JSON.stringify(configTemplate, null, 2), 'utf-8');
|
|
96
|
+
console.log(`✅ 配置文件已创建: ${config_1.CONFIG_PATH}\n`);
|
|
97
|
+
// 4. 提示用户
|
|
98
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
99
|
+
console.log('🎉 初始化完成!');
|
|
100
|
+
console.log('');
|
|
101
|
+
console.log('⚠️ 请编辑配置文件,填入你的 API 密钥:');
|
|
102
|
+
console.log(` ${config_1.CONFIG_PATH}`);
|
|
103
|
+
console.log('');
|
|
104
|
+
console.log('📖 配置文档: https://zhitalk.chat/#config');
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log('🔄 修改完成后,请重新运行 zhitalk');
|
|
107
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zhitalk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "A personal AI Agent like OpenClaw, including tools, skills, memory, hook, sub-agent, MCP server, etc. Run in the terminal.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"zhitalk": "dist/index.js"
|
|
10
|
+
},
|
|
6
11
|
"scripts": {
|
|
7
|
-
"
|
|
12
|
+
"fix:perms": "chmod +x dist/index.js",
|
|
13
|
+
"build": "pnpm clean && tsc && pnpm fix:perms",
|
|
14
|
+
"dev": "ts-node src/index.ts",
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"test:watch": "jest --watch",
|
|
18
|
+
"test:coverage": "jest --coverage",
|
|
19
|
+
"clean": "rm -rf dist"
|
|
8
20
|
},
|
|
9
21
|
"keywords": [],
|
|
10
|
-
"author": "",
|
|
22
|
+
"author": "双越",
|
|
11
23
|
"license": "ISC",
|
|
12
|
-
"
|
|
24
|
+
"docs": "https://zhitalk.chat/",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/jest": "^29.5.12",
|
|
27
|
+
"@types/node": "^20.11.0",
|
|
28
|
+
"jest": "^29.7.0",
|
|
29
|
+
"ts-jest": "^29.1.2",
|
|
30
|
+
"ts-node": "^10.9.2",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@langchain/core": "^1.1.46",
|
|
35
|
+
"@langchain/langgraph": "^1.3.0",
|
|
36
|
+
"@langchain/langgraph-checkpoint-sqlite": "^1.0.1",
|
|
37
|
+
"@langchain/openai": "^1.4.5",
|
|
38
|
+
"@langchain/tavily": "^1.2.0",
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
40
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
41
|
+
"better-sqlite3": "^12.10.0",
|
|
42
|
+
"boxen": "^8.0.1",
|
|
43
|
+
"chalk": "^5.6.2",
|
|
44
|
+
"cli-table3": "^0.6.5",
|
|
45
|
+
"commander": "^14.0.3",
|
|
46
|
+
"figlet": "^1.11.0",
|
|
47
|
+
"langchain": "^1.4.0",
|
|
48
|
+
"zod": "^4.4.3"
|
|
49
|
+
}
|
|
13
50
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('hello zhitalk')
|