@mobcode/openclaw-plugin 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobcode/openclaw-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "MobCode integration plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,11 +47,17 @@ export function registerMobcodeGatewayMethods({
47
47
  respond(false, { error: "sessionKey required" });
48
48
  return;
49
49
  }
50
+ api.logger?.info?.(
51
+ `[mobcode.messages.page] request sessionKey=${sessionKey} limit=${String(params?.limit ?? "") || "-"} beforeId=${typeof params?.beforeId === "string" && params.beforeId.trim() ? params.beforeId.trim() : "-"}`,
52
+ );
50
53
  await builders.ensureSessionMessages(sessionKey);
51
54
  const page = await store.pageSessionMessages(sessionKey, {
52
55
  limit: params?.limit,
53
56
  beforeId: params?.beforeId,
54
57
  });
58
+ api.logger?.info?.(
59
+ `[mobcode.messages.page] response sessionKey=${sessionKey} count=${page.items.length} total=${page.total} hasMore=${page.hasMore} nextBeforeId=${page.nextBeforeId ?? "-"}`,
60
+ );
55
61
  respond(true, {
56
62
  ok: true,
57
63
  sessionKey: page.sessionKey,
@@ -41,7 +41,7 @@ async function readSessionTranscriptMessagesFromInternals(sessionKey) {
41
41
  return Array.isArray(rawMessages) ? rawMessages : [];
42
42
  }
43
43
 
44
- async function readSessionMessagesThroughChatHistory(config, sessionKey) {
44
+ async function readSessionMessagesThroughChatHistory(config, sessionKey, logger) {
45
45
  const normalizedSessionKey = String(sessionKey ?? "").trim();
46
46
  if (!normalizedSessionKey) {
47
47
  return [];
@@ -56,20 +56,31 @@ async function readSessionMessagesThroughChatHistory(config, sessionKey) {
56
56
  clientDisplayName: "MobCode History Backfill",
57
57
  });
58
58
  const messages = payload?.messages;
59
+ logger?.info?.(
60
+ `[mobcode-history] chat.history session=${normalizedSessionKey} messages=${Array.isArray(messages) ? messages.length : 0}`,
61
+ );
59
62
  return Array.isArray(messages) ? messages : [];
60
63
  }
61
64
 
62
- export async function readSessionTranscriptMessages(config, sessionKey) {
65
+ export async function readSessionTranscriptMessages(config, sessionKey, logger) {
63
66
  try {
64
67
  const gatewayMessages = await readSessionMessagesThroughChatHistory(
65
68
  config,
66
69
  sessionKey,
70
+ logger,
67
71
  );
68
72
  if (gatewayMessages.length > 0) {
69
73
  return gatewayMessages;
70
74
  }
71
- } catch {
75
+ } catch (error) {
76
+ logger?.warn?.(
77
+ `[mobcode-history] chat.history failed session=${String(sessionKey ?? "").trim()}: ${error instanceof Error ? error.message : String(error)}`,
78
+ );
72
79
  // Fall back to adjacent-source runtime imports for development checkouts.
73
80
  }
74
- return readSessionTranscriptMessagesFromInternals(sessionKey);
81
+ const internalMessages = await readSessionTranscriptMessagesFromInternals(sessionKey);
82
+ logger?.info?.(
83
+ `[mobcode-history] internal fallback session=${String(sessionKey ?? "").trim()} messages=${internalMessages.length}`,
84
+ );
85
+ return internalMessages;
75
86
  }
@@ -26,6 +26,7 @@ export function createMobcodePluginDefinition() {
26
26
  const pluginMetadata = readPluginMetadata();
27
27
  const store = new MobcodeStateStore({
28
28
  rootDir: path.join(stateDir, "plugins", "mobcode"),
29
+ logger: api.logger,
29
30
  });
30
31
 
31
32
  const builders = {
@@ -35,7 +36,11 @@ export function createMobcodePluginDefinition() {
35
36
  await tryBuildProviderModelsPayload(api, providerId),
36
37
  ensureSessionMessages: async (sessionKey) => {
37
38
  await store.ensureSessionIndexed(sessionKey, async () =>
38
- readSessionTranscriptMessages(api.runtime.config.loadConfig(), sessionKey),
39
+ readSessionTranscriptMessages(
40
+ api.runtime.config.loadConfig(),
41
+ sessionKey,
42
+ api.logger,
43
+ ),
39
44
  );
40
45
  },
41
46
  };
@@ -596,8 +596,9 @@ function normalizeApprovalStatus(status, decision) {
596
596
  }
597
597
 
598
598
  export class MobcodeStateStore {
599
- constructor({ rootDir }) {
599
+ constructor({ rootDir, logger = null }) {
600
600
  this.rootDir = rootDir;
601
+ this.logger = logger;
601
602
  this.databasePath = path.join(rootDir, "mobcode.sqlite");
602
603
  this.database = null;
603
604
  this.clientActionWaiters = new Map();
@@ -803,9 +804,16 @@ export class MobcodeStateStore {
803
804
  return;
804
805
  }
805
806
  const existing = this._db()
806
- .prepare(`SELECT session_key FROM indexed_sessions WHERE session_key=? LIMIT 1`)
807
+ .prepare(
808
+ `SELECT session_key, last_backfill_at
809
+ FROM indexed_sessions
810
+ WHERE session_key=?
811
+ LIMIT 1`,
812
+ )
807
813
  .get(normalizedSessionKey);
808
- if (existing) {
814
+ const alreadyBackfilled =
815
+ typeof existing?.last_backfill_at === "string" && existing.last_backfill_at.trim().length > 0;
816
+ if (alreadyBackfilled) {
809
817
  return;
810
818
  }
811
819
  const messages = Array.isArray(loader) ? loader : await loader();
@@ -918,6 +926,9 @@ export class MobcodeStateStore {
918
926
  });
919
927
 
920
928
  transaction(messages);
929
+ this.logger?.info?.(
930
+ `[mobcode-store] indexed session=${normalizedSessionKey} messages=${messages.length}`,
931
+ );
921
932
  }
922
933
 
923
934
  async appendMessage(update) {