@hchuanz/pocket-core 0.1.1 → 0.1.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/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,