@zhin.js/core 1.0.54 → 1.0.56

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @zhin.js/core
2
2
 
3
+ ## 1.0.56
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [20ab379]
8
+ - @zhin.js/ai@1.0.17
9
+ - @zhin.js/database@1.0.43
10
+ - @zhin.js/logger@0.1.40
11
+ - @zhin.js/schema@1.0.40
12
+ - @zhin.js/kernel@0.0.17
13
+
14
+ ## 1.0.55
15
+
16
+ ### Patch Changes
17
+
18
+ - 75709e1: fix: ai 强化,文档梳理
19
+ - @zhin.js/database@1.0.42
20
+ - @zhin.js/logger@0.1.39
21
+ - @zhin.js/schema@1.0.39
22
+ - @zhin.js/ai@1.0.16
23
+ - @zhin.js/kernel@0.0.16
24
+
3
25
  ## 1.0.54
4
26
 
5
27
  ### Patch Changes
@@ -9,6 +9,7 @@
9
9
  * Agent 预设以标准 *.agent.md 文件提供,框架自动扫描发现。
10
10
  * 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
11
11
  */
12
+ import { Feature, type FeatureJSON } from '../feature.js';
12
13
  import type { Tool } from '../types.js';
13
14
  /**
14
15
  * Agent 预设(从 *.agent.md 文件解析或编程式注册)
@@ -37,4 +38,26 @@ export interface AgentPreset {
37
38
  /** *.agent.md 文件的绝对路径 */
38
39
  filePath?: string;
39
40
  }
41
+ declare module '../plugin.js' {
42
+ namespace Plugin {
43
+ interface Contexts {
44
+ agentPreset: AgentPresetFeature;
45
+ }
46
+ }
47
+ }
48
+ export declare class AgentPresetFeature extends Feature<AgentPreset> {
49
+ #private;
50
+ readonly name: "agentPreset";
51
+ readonly icon = "Bot";
52
+ readonly desc = "Agent \u9884\u8BBE";
53
+ readonly byName: Map<string, AgentPreset>;
54
+ add(preset: AgentPreset, pluginName: string): () => void;
55
+ remove(preset: AgentPreset, pluginName?: string): boolean;
56
+ get(name: string): AgentPreset | undefined;
57
+ getAll(): AgentPreset[];
58
+ search(query: string, options?: {
59
+ maxResults?: number;
60
+ }): AgentPreset[];
61
+ toJSON(pluginName?: string): FeatureJSON;
62
+ }
40
63
  //# sourceMappingURL=agent-preset.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-preset.d.ts","sourceRoot":"","sources":["../../src/built/agent-preset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAMxC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,cAAc;IACd,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IAEf,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB,YAAY;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,iBAAiB;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,qBAAqB;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"agent-preset.d.ts","sourceRoot":"","sources":["../../src/built/agent-preset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAMxC;;GAEG;AACH,MAAM,WAAW,WAA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AM,CAAA;KAAE,GAAG,WAAW,EAAE;IAwBvE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW;CAiBzC"}
@@ -9,5 +9,68 @@
9
9
  * Agent 预设以标准 *.agent.md 文件提供,框架自动扫描发现。
10
10
  * 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
11
11
  */
12
- export {};
12
+ import { Feature } from '../feature.js';
13
+ export class AgentPresetFeature extends Feature {
14
+ name = 'agentPreset';
15
+ icon = 'Bot';
16
+ desc = 'Agent 预设';
17
+ byName = new Map();
18
+ add(preset, pluginName) {
19
+ this.byName.set(preset.name, preset);
20
+ return super.add(preset, pluginName);
21
+ }
22
+ remove(preset, pluginName) {
23
+ this.byName.delete(preset.name);
24
+ return super.remove(preset, pluginName);
25
+ }
26
+ get(name) {
27
+ return this.byName.get(name);
28
+ }
29
+ getAll() {
30
+ return [...this.items];
31
+ }
32
+ search(query, options) {
33
+ const maxResults = options?.maxResults ?? 5;
34
+ const lower = query.toLowerCase();
35
+ const scored = this.items
36
+ .map(preset => ({ preset, score: this.#scorePreset(preset, lower) }))
37
+ .filter(({ score }) => score > 0)
38
+ .sort((a, b) => b.score - a.score)
39
+ .slice(0, maxResults);
40
+ return scored.map(({ preset }) => preset);
41
+ }
42
+ #scorePreset(preset, query) {
43
+ let score = 0;
44
+ if (preset.name.toLowerCase().includes(query))
45
+ score += 10;
46
+ if (preset.description.toLowerCase().includes(query))
47
+ score += 5;
48
+ for (const kw of preset.keywords || []) {
49
+ if (kw.toLowerCase().includes(query) || query.includes(kw.toLowerCase()))
50
+ score += 8;
51
+ }
52
+ for (const tag of preset.tags || []) {
53
+ if (tag.toLowerCase().includes(query))
54
+ score += 3;
55
+ }
56
+ return score;
57
+ }
58
+ toJSON(pluginName) {
59
+ const list = pluginName ? this.getByPlugin(pluginName) : this.items;
60
+ return {
61
+ name: this.name,
62
+ icon: this.icon,
63
+ desc: this.desc,
64
+ count: list.length,
65
+ items: list.map(p => ({
66
+ name: p.name,
67
+ desc: p.description,
68
+ keywords: p.keywords,
69
+ tags: p.tags,
70
+ model: p.model,
71
+ provider: p.provider,
72
+ })),
73
+ };
74
+ }
75
+ }
13
76
  //# sourceMappingURL=agent-preset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-preset.js","sourceRoot":"","sources":["../../src/built/agent-preset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
1
+ {"version":3,"file":"agent-preset.js","sourceRoot":"","sources":["../../src/built/agent-preset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAyD1D,MAAM,OAAO,kBAAmB,SAAQ,OAAoB;IACjD,IAAI,GAAG,aAAsB,CAAC;IAC9B,IAAI,GAAG,KAAK,CAAC;IACb,IAAI,GAAG,UAAU,CAAC;IAElB,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEjD,GAAG,CAAC,MAAmB,EAAE,UAAkB;QACzC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,MAAmB,EAAE,UAAmB;QAC7C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAa,EAAE,OAAiC;QACrD,MAAM,UAAU,GAAG,OAAO,EA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C,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,KAAK,IAAI,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,UAAmB;QACxB,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QACpE,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,IAAI,EAAE,CAAC,CAAC,WAAW;gBACnB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;aACrB,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "Zhin机器人核心框架",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -37,11 +37,11 @@
37
37
  "segment-matcher": "^1.0.5",
38
38
  "smol-toml": "^1.6.0",
39
39
  "yaml": "^2.3.4",
40
- "@zhin.js/ai": "1.0.15",
41
- "@zhin.js/database": "1.0.41",
42
- "@zhin.js/kernel": "0.0.15",
43
- "@zhin.js/logger": "0.1.38",
44
- "@zhin.js/schema": "1.0.38"
40
+ "@zhin.js/ai": "1.0.17",
41
+ "@zhin.js/kernel": "0.0.17",
42
+ "@zhin.js/logger": "0.1.40",
43
+ "@zhin.js/schema": "1.0.40",
44
+ "@zhin.js/database": "1.0.43"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^24.3.0",
@@ -10,6 +10,7 @@
10
10
  * 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
11
11
  */
12
12
 
13
+ import { Feature, type FeatureJSON } from '../feature.js';
13
14
  import type { Tool } from '../types.js';
14
15
 
15
16
  // ============================================================================
@@ -53,3 +54,83 @@ export interface AgentPreset {
53
54
  /** *.agent.md 文件的绝对路径 */
54
55
  filePath?: string;
55
56
  }
57
+
58
+ // ============================================================================
59
+ // AgentPresetFeature
60
+ // ============================================================================
61
+
62
+ declare module '../plugin.js' {
63
+ namespace Plugin {
64
+ interface Contexts {
65
+ agentPreset: AgentPresetFeature;
66
+ }
67
+ }
68
+ }
69
+
70
+ export class AgentPresetFeature extends Feature<AgentPreset> {
71
+ readonly name = 'agentPreset' as const;
72
+ readonly icon = 'Bot';
73
+ readonly desc = 'Agent 预设';
74
+
75
+ readonly byName = new Map<string, AgentPreset>();
76
+
77
+ add(preset: AgentPreset, pluginName: string): () => void {
78
+ this.byName.set(preset.name, preset);
79
+ return super.add(preset, pluginName);
80
+ }
81
+
82
+ remove(preset: AgentPreset, pluginName?: string): boolean {
83
+ this.byName.delete(preset.name);
84
+ return super.remove(preset, pluginName);
85
+ }
86
+
87
+ get(name: string): AgentPreset | undefined {
88
+ return this.byName.get(name);
89
+ }
90
+
91
+ getAll(): AgentPreset[] {
92
+ return [...this.items];
93
+ }
94
+
95
+ search(query: string, options?: { maxResults?: number }): AgentPreset[] {
96
+ const maxResults = options?.maxResults ?? 5;
97
+ const lower = query.toLowerCase();
98
+ const scored = this.items
99
+ .map(preset => ({ preset, score: this.#scorePreset(preset, lower) }))
100
+ .filter(({ score }) => score > 0)
101
+ .sort((a, b) => b.score - a.score)
102
+ .slice(0, maxResults);
103
+ return scored.map(({ preset }) => preset);
104
+ }
105
+
106
+ #scorePreset(preset: AgentPreset, query: string): number {
107
+ let score = 0;
108
+ if (preset.name.toLowerCase().includes(query)) score += 10;
109
+ if (preset.description.toLowerCase().includes(query)) score += 5;
110
+ for (const kw of preset.keywords || []) {
111
+ if (kw.toLowerCase().includes(query) || query.includes(kw.toLowerCase())) score += 8;
112
+ }
113
+ for (const tag of preset.tags || []) {
114
+ if (tag.toLowerCase().includes(query)) score += 3;
115
+ }
116
+ return score;
117
+ }
118
+
119
+ toJSON(pluginName?: string): FeatureJSON {
120
+ const list = pluginName ? this.getByPlugin(pluginName) : this.items;
121
+ return {
122
+ name: this.name,
123
+ icon: this.icon,
124
+ desc: this.desc,
125
+ count: list.length,
126
+ items: list.map(p => ({
127
+ name: p.name,
128
+ desc: p.description,
129
+ keywords: p.keywords,
130
+ tags: p.tags,
131
+ model: p.model,
132
+ provider: p.provider,
133
+ })),
134
+ };
135
+ }
136
+ }