@mobcode/openclaw-plugin 0.1.1 → 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/package.json +1 -1
- package/src/openclaw-session-reader.js +15 -4
- package/src/plugin-definition.js +6 -1
- package/src/state-store.js +14 -3
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/plugin-definition.js
CHANGED
|
@@ -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(
|
|
39
|
+
readSessionTranscriptMessages(
|
|
40
|
+
api.runtime.config.loadConfig(),
|
|
41
|
+
sessionKey,
|
|
42
|
+
api.logger,
|
|
43
|
+
),
|
|
39
44
|
);
|
|
40
45
|
},
|
|
41
46
|
};
|
package/src/state-store.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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) {
|