|
1 | 1 | /** SQLite-backed ACP session metadata storage keyed through session-store entries. */ |
2 | 2 | import type { DatabaseSync } from "node:sqlite"; |
| 3 | +import { safeParseJson } from "@openclaw/normalization-core"; |
| 4 | +import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce"; |
3 | 5 | import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
4 | 6 | import type { Insertable, Selectable } from "kysely"; |
5 | 7 | import { getRuntimeConfig } from "../../config/config.js"; |
@@ -29,7 +31,6 @@ import { |
29 | 31 | type OpenClawStateDatabaseOptions, |
30 | 32 | runOpenClawStateWriteTransaction, |
31 | 33 | } from "../../state/openclaw-state-db.js"; |
32 | | -import { isRecord } from "../../utils.js"; |
33 | 34 |
|
34 | 35 | /** ACP metadata joined with its legacy session-store row and config context. */ |
35 | 36 | export type AcpSessionStoreEntry = { |
@@ -89,21 +90,11 @@ function getAcpSessionKysely(db: DatabaseSync) { |
89 | 90 | return getNodeSqliteKysely<AcpSessionMetaDatabase>(db); |
90 | 91 | } |
91 | 92 |
|
92 | | -function parseOptionalJsonRecord(raw: string | null): Record<string, unknown> | undefined { |
93 | | - if (raw == null || raw === "") { |
94 | | - return undefined; |
95 | | - } |
96 | | - try { |
97 | | - const parsed = JSON.parse(raw) as unknown; |
98 | | - return isRecord(parsed) ? parsed : undefined; |
99 | | - } catch { |
100 | | - return undefined; |
101 | | - } |
102 | | -} |
103 | | - |
104 | 93 | function rowToAcpSessionMeta(row: AcpSessionRow): SessionAcpMeta { |
105 | | - const identity = parseOptionalJsonRecord(row.identity_json) as SessionAcpIdentity | undefined; |
106 | | - const runtimeOptions = parseOptionalJsonRecord(row.runtime_options_json) as |
| 94 | + const identity = asOptionalRecord(safeParseJson(row.identity_json ?? "")) as |
| 95 | + | SessionAcpIdentity |
| 96 | + | undefined; |
| 97 | + const runtimeOptions = asOptionalRecord(safeParseJson(row.runtime_options_json ?? "")) as |
107 | 98 | | AcpSessionRuntimeOptions |
108 | 99 | | undefined; |
109 | 100 | return { |
|
0 commit comments