@zhin.js/core 1.0.26 → 1.0.28
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/CHANGELOG.md +18 -0
- package/lib/ai/agent.d.ts.map +1 -1
- package/lib/ai/agent.js +4 -0
- package/lib/ai/agent.js.map +1 -1
- package/lib/ai/bootstrap.d.ts +82 -0
- package/lib/ai/bootstrap.d.ts.map +1 -0
- package/lib/ai/bootstrap.js +199 -0
- package/lib/ai/bootstrap.js.map +1 -0
- package/lib/ai/builtin-tools.d.ts +36 -0
- package/lib/ai/builtin-tools.d.ts.map +1 -0
- package/lib/ai/builtin-tools.js +509 -0
- package/lib/ai/builtin-tools.js.map +1 -0
- package/lib/ai/compaction.d.ts +132 -0
- package/lib/ai/compaction.d.ts.map +1 -0
- package/lib/ai/compaction.js +370 -0
- package/lib/ai/compaction.js.map +1 -0
- package/lib/ai/hooks.d.ts +143 -0
- package/lib/ai/hooks.d.ts.map +1 -0
- package/lib/ai/hooks.js +108 -0
- package/lib/ai/hooks.js.map +1 -0
- package/lib/ai/index.d.ts +6 -0
- package/lib/ai/index.d.ts.map +1 -1
- package/lib/ai/index.js +6 -0
- package/lib/ai/index.js.map +1 -1
- package/lib/ai/init.d.ts.map +1 -1
- package/lib/ai/init.js +120 -3
- package/lib/ai/init.js.map +1 -1
- package/lib/ai/types.d.ts +2 -0
- package/lib/ai/types.d.ts.map +1 -1
- package/lib/ai/zhin-agent.d.ts +28 -1
- package/lib/ai/zhin-agent.d.ts.map +1 -1
- package/lib/ai/zhin-agent.js +196 -57
- package/lib/ai/zhin-agent.js.map +1 -1
- package/lib/built/config.d.ts +10 -0
- package/lib/built/config.d.ts.map +1 -1
- package/lib/built/config.js +54 -3
- package/lib/built/config.js.map +1 -1
- package/lib/built/tool.d.ts +6 -0
- package/lib/built/tool.d.ts.map +1 -1
- package/lib/built/tool.js +12 -0
- package/lib/built/tool.js.map +1 -1
- package/lib/cron.d.ts +0 -27
- package/lib/cron.d.ts.map +1 -1
- package/lib/cron.js +28 -27
- package/lib/cron.js.map +1 -1
- package/lib/types-generator.js +1 -1
- package/lib/types-generator.js.map +1 -1
- package/lib/types.d.ts +7 -0
- package/lib/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/ai/agent.ts +6 -0
- package/src/ai/bootstrap.ts +263 -0
- package/src/ai/builtin-tools.ts +569 -0
- package/src/ai/compaction.ts +529 -0
- package/src/ai/hooks.ts +223 -0
- package/src/ai/index.ts +58 -0
- package/src/ai/init.ts +127 -3
- package/src/ai/types.ts +2 -0
- package/src/ai/zhin-agent.ts +226 -54
- package/src/built/config.ts +53 -3
- package/src/built/tool.ts +12 -0
- package/src/cron.ts +28 -27
- package/src/types-generator.ts +1 -1
- package/src/types.ts +8 -0
- package/tests/adapter.test.ts +1 -1
- package/tests/config.test.ts +2 -2
- package/test/minimal-bot.ts +0 -31
- package/test/stress-test.ts +0 -123
package/tests/adapter.test.ts
CHANGED
|
@@ -415,7 +415,7 @@ describe('Adapter Core Functionality', () => {
|
|
|
415
415
|
name: 'dispatcher',
|
|
416
416
|
description: 'mock dispatcher',
|
|
417
417
|
value: {
|
|
418
|
-
dispatch: (msg: any) => { dispatchCalled = true },
|
|
418
|
+
dispatch: (msg: any) => { dispatchCalled = true; return Promise.resolve() },
|
|
419
419
|
},
|
|
420
420
|
} as any)
|
|
421
421
|
|
package/tests/config.test.ts
CHANGED
|
@@ -357,8 +357,8 @@ describe('ConfigFeature', () => {
|
|
|
357
357
|
const json = feature.toJSON()
|
|
358
358
|
expect(json.name).toBe('config')
|
|
359
359
|
expect(json.count).toBe(2)
|
|
360
|
-
expect(json.items[0]).toEqual({ name: 'debug'
|
|
361
|
-
expect(json.items[1]).toEqual({ name: 'port'
|
|
360
|
+
expect(json.items[0]).toEqual({ name: 'debug' })
|
|
361
|
+
expect(json.items[1]).toEqual({ name: 'port' })
|
|
362
362
|
})
|
|
363
363
|
|
|
364
364
|
it('toJSON(pluginName) 应按插件过滤', () => {
|
package/test/minimal-bot.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { App } from '../src/app';
|
|
2
|
-
import { LogLevel } from '@zhin.js/logger';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
async function runMinimalBot() {
|
|
10
|
-
const app = new App({
|
|
11
|
-
log_level: LogLevel.INFO,
|
|
12
|
-
plugin_dirs: [path.join(__dirname, 'plugins')],
|
|
13
|
-
plugins: [],
|
|
14
|
-
bots: [],
|
|
15
|
-
debug: true
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
console.log('Starting Minimal Bot...');
|
|
19
|
-
await app.start();
|
|
20
|
-
console.log('Minimal Bot Started');
|
|
21
|
-
|
|
22
|
-
// Simulate a message
|
|
23
|
-
// await app.receiveMessage(...)
|
|
24
|
-
|
|
25
|
-
await app.stop();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (process.argv[1] === __filename) {
|
|
29
|
-
runMinimalBot().catch(console.error);
|
|
30
|
-
}
|
|
31
|
-
|
package/test/stress-test.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { App } from '../src/app';
|
|
2
|
-
import { LogLevel } from '@zhin.js/logger';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
// import { Message } from '../src/message'; // Message is a type/namespace, not a class
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
async function runStressTest() {
|
|
12
|
-
const PLUGIN_COUNT = 50;
|
|
13
|
-
const MSG_COUNT = 10000;
|
|
14
|
-
const WORK_DIR = path.join(__dirname, 'stress_plugins');
|
|
15
|
-
|
|
16
|
-
console.log('Starting Core Stress Test');
|
|
17
|
-
|
|
18
|
-
// Setup workspace
|
|
19
|
-
if (fs.existsSync(WORK_DIR)) fs.rmSync(WORK_DIR, { recursive: true, force: true });
|
|
20
|
-
fs.mkdirSync(WORK_DIR, { recursive: true });
|
|
21
|
-
|
|
22
|
-
// Generate plugins
|
|
23
|
-
let loadedCount = 0;
|
|
24
|
-
for (let i = 0; i < PLUGIN_COUNT; i++) {
|
|
25
|
-
fs.writeFileSync(path.join(WORK_DIR, `plugin-${i}.ts`), `
|
|
26
|
-
import { useContext } from '${path.resolve(__dirname, '../src/plugin').replace(/\\/g, '/')}';
|
|
27
|
-
|
|
28
|
-
export function install(ctx) {
|
|
29
|
-
ctx.on('message.receive', (msg) => {
|
|
30
|
-
// console.log('Plugin ${i} received message');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
ctx.middleware(async (msg, next) => {
|
|
34
|
-
await next();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const CONFIG_FILE = path.join(WORK_DIR, 'zhin.test.yaml');
|
|
41
|
-
// Write config to file to avoid reload overriding it with defaults
|
|
42
|
-
const config = {
|
|
43
|
-
log_level: LogLevel.WARN,
|
|
44
|
-
plugin_dirs: [WORK_DIR],
|
|
45
|
-
plugins: Array.from({ length: PLUGIN_COUNT }, (_, i) => `plugin-${i}`),
|
|
46
|
-
bots: [],
|
|
47
|
-
debug: false
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Simple YAML stringify since we can't require 'yaml' easily in ESM without import
|
|
51
|
-
const yamlString = `
|
|
52
|
-
log_level: ${config.log_level}
|
|
53
|
-
debug: ${config.debug}
|
|
54
|
-
plugin_dirs:
|
|
55
|
-
${config.plugin_dirs.map(d => ` - ${d}`).join('\n')}
|
|
56
|
-
plugins:
|
|
57
|
-
${config.plugins.map(p => ` - ${p}`).join('\n')}
|
|
58
|
-
bots: []
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
fs.writeFileSync(CONFIG_FILE, yamlString);
|
|
62
|
-
|
|
63
|
-
const app = new App(CONFIG_FILE);
|
|
64
|
-
|
|
65
|
-
console.log('Starting App...');
|
|
66
|
-
const startBoot = performance.now();
|
|
67
|
-
await app.start();
|
|
68
|
-
console.log(`App started in ${(performance.now() - startBoot).toFixed(2)}ms`);
|
|
69
|
-
|
|
70
|
-
// Verify plugins loaded
|
|
71
|
-
const loadedPlugins = app.hmrManager.dependencyList.length; // App itself + plugins
|
|
72
|
-
console.log(`Loaded Dependencies: ${loadedPlugins}`);
|
|
73
|
-
if (loadedPlugins < PLUGIN_COUNT) {
|
|
74
|
-
console.warn(`WARNING: Only ${loadedPlugins} dependencies loaded (expected >= ${PLUGIN_COUNT})`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const initialMem = process.memoryUsage();
|
|
78
|
-
console.log(`Initial RSS: ${(initialMem.rss / 1024 / 1024).toFixed(2)} MB`);
|
|
79
|
-
|
|
80
|
-
console.log(`Sending ${MSG_COUNT} messages...`);
|
|
81
|
-
const startMsg = performance.now();
|
|
82
|
-
|
|
83
|
-
// Mock message factory
|
|
84
|
-
const createMockMsg = (id: number) => ({
|
|
85
|
-
$id: `msg-${id}`,
|
|
86
|
-
$adapter: 'mock',
|
|
87
|
-
$bot: 'bot1',
|
|
88
|
-
$content: [{ type: 'text', data: { text: 'hello' } }],
|
|
89
|
-
$sender: { id: 'user1' },
|
|
90
|
-
$channel: { id: 'group1', type: 'group' as const },
|
|
91
|
-
$timestamp: Date.now(),
|
|
92
|
-
$raw: 'hello',
|
|
93
|
-
$reply: async () => 'reply-id',
|
|
94
|
-
$recall: async () => {},
|
|
95
|
-
// Custom fields usually added by adapters
|
|
96
|
-
raw_message: 'hello',
|
|
97
|
-
message_type: 'group',
|
|
98
|
-
sender: { id: 'user1' },
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
for (let i = 0; i < MSG_COUNT; i++) {
|
|
102
|
-
const msg = createMockMsg(i);
|
|
103
|
-
await app.receiveMessage(msg as any);
|
|
104
|
-
|
|
105
|
-
if (i % 1000 === 0) {
|
|
106
|
-
const mem = process.memoryUsage();
|
|
107
|
-
process.stdout.write(`\rMsgs: ${i}, RSS: ${(mem.rss / 1024 / 1024).toFixed(2)} MB`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
console.log(`\nProcessed ${MSG_COUNT} messages in ${(performance.now() - startMsg).toFixed(2)}ms`);
|
|
112
|
-
console.log(`Avg: ${((performance.now() - startMsg) / MSG_COUNT).toFixed(3)}ms/msg`);
|
|
113
|
-
|
|
114
|
-
const finalMem = process.memoryUsage();
|
|
115
|
-
console.log(`Final RSS: ${(finalMem.rss / 1024 / 1024).toFixed(2)} MB`);
|
|
116
|
-
console.log(`Memory Delta: ${((finalMem.rss - initialMem.rss) / 1024 / 1024).toFixed(2)} MB`);
|
|
117
|
-
|
|
118
|
-
await app.stop();
|
|
119
|
-
fs.rmSync(WORK_DIR, { recursive: true, force: true });
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
runStressTest().catch(console.error);
|
|
123
|
-
|