@hchuanz/pocket-core 0.1.0 → 0.1.2
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 +29 -0
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @hchuanz/pocket-core
|
|
2
|
+
|
|
3
|
+
口袋 helper 生态的**核心业务逻辑**(平台无关),从 Electron 桌面应用中抽取,支持 ESM + CJS 双格式。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @hchuanz/pocket-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 架构
|
|
12
|
+
|
|
13
|
+
采用 ports & adapters(六边形)架构,core 不依赖任何 UI 框架,运行时依赖通过接口注入。
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createPocketCore, ConsoleLogger, NodeJsonFileStorage } from '@hchuanz/pocket-core'
|
|
19
|
+
|
|
20
|
+
const core = createPocketCore({
|
|
21
|
+
logger: new ConsoleLogger(),
|
|
22
|
+
storage: new NodeJsonFileStorage('./data'),
|
|
23
|
+
// ... 其他适配器
|
|
24
|
+
})
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -823,6 +823,7 @@ var MirrorIndex = class {
|
|
|
823
823
|
for (let i = 0; i < toEmbed.length; i += EMBED_BATCH_SIZE) {
|
|
824
824
|
const batch = toEmbed.slice(i, i + EMBED_BATCH_SIZE);
|
|
825
825
|
const texts = batch.map((b) => b.text);
|
|
826
|
+
if (!this.llmClient) throw new Error("LLM client not configured, cannot build index");
|
|
826
827
|
const vectors = await this.llmClient.embed(config, texts);
|
|
827
828
|
batch.forEach((b, j) => {
|
|
828
829
|
newVectors.push({ ...b.rec, hash: b.hash, vector: vectors[j] || [] });
|
|
@@ -851,6 +852,7 @@ var MirrorIndex = class {
|
|
|
851
852
|
async search(xoxId, config, query, topK = 5) {
|
|
852
853
|
const index = this.load(xoxId);
|
|
853
854
|
if (!index || index.vectors.length === 0) return [];
|
|
855
|
+
if (!this.llmClient) throw new Error("LLM client not configured, cannot search index");
|
|
854
856
|
const [qv] = await this.llmClient.embed(config, [query]);
|
|
855
857
|
if (!qv) return [];
|
|
856
858
|
const scored = index.vectors.map((v) => ({ record: v, score: cosine(qv, v.vector) })).sort((a, b) => b.score - a.score).slice(0, Math.min(topK * 3, index.vectors.length));
|
|
@@ -940,6 +942,10 @@ var MirrorMemory = class {
|
|
|
940
942
|
*/
|
|
941
943
|
async recordEpisode(xoxId, config, messages) {
|
|
942
944
|
if (messages.length < 4) return null;
|
|
945
|
+
if (!this.llmClient) {
|
|
946
|
+
this.logger.warn("[mirrorMemory] LLM client not configured, skipping episode summarization");
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
943
949
|
const convText = messages.slice(-30).map((m) => `${m.role === "user" ? "\u7C89\u4E1D" : "\u5076\u50CF"}: ${m.content}`).join("\n");
|
|
944
950
|
const systemPrompt = `\u4F60\u662F\u5BF9\u8BDD\u8BB0\u5FC6\u538B\u7F29\u5668\u3002\u8BF7\u628A\u4EE5\u4E0B\u5BF9\u8BDD\u538B\u7F29\u6210\u4E00\u6761\u8BB0\u5FC6\u6761\u76EE\uFF0C\u8F93\u51FA JSON:
|
|
945
951
|
{"topic": "\u8BDD\u9898\u5173\u952E\u8BCD(2-6\u5B57)", "summary": "30-80\u5B57\u7684\u5BF9\u8BDD\u6458\u8981\uFF0C\u5305\u542B\u5173\u952E\u4E8B\u5B9E\u3001\u60C5\u7EEA\u548C\u7EA6\u5B9A"}
|
|
@@ -3226,8 +3232,8 @@ function createPocketCore(deps) {
|
|
|
3226
3232
|
const mirrorStore = new MirrorStore(deps.storage, deps.logger);
|
|
3227
3233
|
const flipCacheService = new FlipCacheService(deps.storage, deps.logger, deps.configStore);
|
|
3228
3234
|
const groupChatStore = new GroupChatStore(deps.storage, deps.logger);
|
|
3229
|
-
const mirrorIndex = new MirrorIndex(deps.storage, deps.logger, deps.llmClient);
|
|
3230
|
-
const mirrorMemory = new MirrorMemory(deps.storage, deps.logger, deps.llmClient);
|
|
3235
|
+
const mirrorIndex = new MirrorIndex(deps.storage, deps.logger, deps.llmClient ?? null);
|
|
3236
|
+
const mirrorMemory = new MirrorMemory(deps.storage, deps.logger, deps.llmClient ?? null);
|
|
3231
3237
|
return {
|
|
3232
3238
|
deps,
|
|
3233
3239
|
toolRegistry,
|