@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/dist/index.d.cts CHANGED
@@ -723,7 +723,7 @@ declare class MirrorIndex {
723
723
  private storage;
724
724
  private logger;
725
725
  private llmClient;
726
- constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient);
726
+ constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient | null);
727
727
  /**
728
728
  * Load index from disk (returns null if not exists)
729
729
  */
@@ -781,7 +781,7 @@ declare class MirrorMemory {
781
781
  private storage;
782
782
  private logger;
783
783
  private llmClient;
784
- constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient);
784
+ constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient | null);
785
785
  private ensureDir;
786
786
  /**
787
787
  * Load memory file
@@ -1220,7 +1220,7 @@ interface CoreDependencies {
1220
1220
  secureStorage: ISecureStorage;
1221
1221
  configStore: IConfigStore;
1222
1222
  flipDataSource: IFlipDataSource;
1223
- llmClient: ILlmClient;
1223
+ llmClient?: ILlmClient;
1224
1224
  /** 流式聊天输出;Electron 用 IPC,MCP 用回调 */
1225
1225
  chatStreamSink?: IChatStreamSink;
1226
1226
  /** 事件推送;Electron 用 webContents,MCP 用空实现 */
package/dist/index.d.ts CHANGED
@@ -723,7 +723,7 @@ declare class MirrorIndex {
723
723
  private storage;
724
724
  private logger;
725
725
  private llmClient;
726
- constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient);
726
+ constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient | null);
727
727
  /**
728
728
  * Load index from disk (returns null if not exists)
729
729
  */
@@ -781,7 +781,7 @@ declare class MirrorMemory {
781
781
  private storage;
782
782
  private logger;
783
783
  private llmClient;
784
- constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient);
784
+ constructor(storage: IStorage, logger: ILogger, llmClient: ILlmClient | null);
785
785
  private ensureDir;
786
786
  /**
787
787
  * Load memory file
@@ -1220,7 +1220,7 @@ interface CoreDependencies {
1220
1220
  secureStorage: ISecureStorage;
1221
1221
  configStore: IConfigStore;
1222
1222
  flipDataSource: IFlipDataSource;
1223
- llmClient: ILlmClient;
1223
+ llmClient?: ILlmClient;
1224
1224
  /** 流式聊天输出;Electron 用 IPC,MCP 用回调 */
1225
1225
  chatStreamSink?: IChatStreamSink;
1226
1226
  /** 事件推送;Electron 用 webContents,MCP 用空实现 */
package/dist/index.js CHANGED
@@ -728,6 +728,7 @@ var MirrorIndex = class {
728
728
  for (let i = 0; i < toEmbed.length; i += EMBED_BATCH_SIZE) {
729
729
  const batch = toEmbed.slice(i, i + EMBED_BATCH_SIZE);
730
730
  const texts = batch.map((b) => b.text);
731
+ if (!this.llmClient) throw new Error("LLM client not configured, cannot build index");
731
732
  const vectors = await this.llmClient.embed(config, texts);
732
733
  batch.forEach((b, j) => {
733
734
  newVectors.push({ ...b.rec, hash: b.hash, vector: vectors[j] || [] });
@@ -756,6 +757,7 @@ var MirrorIndex = class {
756
757
  async search(xoxId, config, query, topK = 5) {
757
758
  const index = this.load(xoxId);
758
759
  if (!index || index.vectors.length === 0) return [];
760
+ if (!this.llmClient) throw new Error("LLM client not configured, cannot search index");
759
761
  const [qv] = await this.llmClient.embed(config, [query]);
760
762
  if (!qv) return [];
761
763
  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));
@@ -845,6 +847,10 @@ var MirrorMemory = class {
845
847
  */
846
848
  async recordEpisode(xoxId, config, messages) {
847
849
  if (messages.length < 4) return null;
850
+ if (!this.llmClient) {
851
+ this.logger.warn("[mirrorMemory] LLM client not configured, skipping episode summarization");
852
+ return null;
853
+ }
848
854
  const convText = messages.slice(-30).map((m) => `${m.role === "user" ? "\u7C89\u4E1D" : "\u5076\u50CF"}: ${m.content}`).join("\n");
849
855
  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:
850
856
  {"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"}
@@ -3131,8 +3137,8 @@ function createPocketCore(deps) {
3131
3137
  const mirrorStore = new MirrorStore(deps.storage, deps.logger);
3132
3138
  const flipCacheService = new FlipCacheService(deps.storage, deps.logger, deps.configStore);
3133
3139
  const groupChatStore = new GroupChatStore(deps.storage, deps.logger);
3134
- const mirrorIndex = new MirrorIndex(deps.storage, deps.logger, deps.llmClient);
3135
- const mirrorMemory = new MirrorMemory(deps.storage, deps.logger, deps.llmClient);
3140
+ const mirrorIndex = new MirrorIndex(deps.storage, deps.logger, deps.llmClient ?? null);
3141
+ const mirrorMemory = new MirrorMemory(deps.storage, deps.logger, deps.llmClient ?? null);
3136
3142
  return {
3137
3143
  deps,
3138
3144
  toolRegistry,