@xopcai/xopc 0.0.170 → 0.0.171
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-CkUp1qvf.js → activity-store-BLz30jWq.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DDuem4HM.js → agent-avatar-dicebear-BKZO0EFn.js} +1 -1
- package/dist/gateway/static/root/assets/agents-ZCIC8mhO.js +2 -0
- package/dist/gateway/static/root/assets/{api-BnuPQhJW.js → api-N2qKY-WI.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-DdZw8Hi1.js → app-management-settings-panel-CNZkpXCD.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BN8Vk2bX.js → appearance-settings-Drf5a563.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-CuL8Q4yF.js → apps-page-DJmgBaAm.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-C82MaDQj.js → archive-plugin-ChVwOXE5.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-uilrwSdW.js → attachment-load-BVK3Y2d9.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-CkDZjAmy.js → automation-suggestion-card-DH4N0SYR.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-Ddot8-Md.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-B7NTL0_T.js → binary-plugins-CeHY6VVP.js} +1 -1
- package/dist/gateway/static/root/assets/block-editor-D3GIllO3.js +184 -0
- package/dist/gateway/static/root/assets/browser-settings-page-DvETvRcg.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-UFVUzn4v.js → browser-workflow-inputs-femCtfpo.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CGgC0N92.js → browser-workflows-page-o0GVE_aF.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-ChXIYbys.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-DUIorGUd.js → capability-presets-api-Bx-JJC0R.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-CUekXsJy.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-BYwSB8c6.js → channel-recipient-api-CTw3ibx4.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-CkhveNsQ.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-DRTb8DBk.js +1 -0
- package/dist/gateway/static/root/assets/{connector-logo-CsbegNqi.js → connector-logo-CQznQcd4.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-DkSGIxWP.js +2 -0
- package/dist/gateway/static/root/assets/desktop-pet-BtP-xUQ9.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DkbIzdA3.js → desktop-pet-settings-CIeH4VyP.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-dBQvj1sG.js → directory-picker-path-field-Ddgt6c3K.js} +1 -1
- package/dist/gateway/static/root/assets/{dreaming-settings-DkdnKMZx.js → dreaming-settings-gd9W6SLj.js} +3 -3
- package/dist/gateway/static/root/assets/{extension-debug-page-BfxoIiNo.js → extension-debug-page-CJGwUaQX.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-EIJ3wIb7.js → extension-page-B3zHKJAB.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-DBBec51N.js → extension-settings-page-Cj9rrSr1.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-4_u53Ufq.js → gateway-config-api-BdmtlJRP.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-v9kJM59H.js → gateway-settings-C2RwKIsl.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CXITih5d.js → gateway-startup-retry-mcMq_uu_.js} +1 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-5Ryd_rx4.js +1 -0
- package/dist/gateway/static/root/assets/goal-detail-page-DizZ6Cpl.js +4 -0
- package/dist/gateway/static/root/assets/{goals-config-api-D54YQPon.js → goals-config-api-CAO1J4jn.js} +1 -1
- package/dist/gateway/static/root/assets/goals-page-Dqry_hi2.js +2 -0
- package/dist/gateway/static/root/assets/{goals-settings-DDezXaVi.js → goals-settings-Boj2izKZ.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-CRsIUeZN.js → heartbeat-settings-DbPC9a_y.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-CY6cQUHL.js → image-generation-api-DrLCLTXn.js} +1 -1
- package/dist/gateway/static/root/assets/index-DEdyUjxM.css +1 -0
- package/dist/gateway/static/root/assets/{index-Dfq2laZe.js → index-vHb2z7VS.js} +7 -7
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D9k7EDdY.js → keyboard-shortcuts-settings-BrxfptgY.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-BP0_Ih0e.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DbaiBolh.js → local-apps-page-DNCRlfFs.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Dqp9H2Uf.js → locale-store-CzIfXqm8.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-mT48mcF4.js +7 -0
- package/dist/gateway/static/root/assets/{markdown-split-BGlQR-Be.js → markdown-split-CIUH9Lor.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BpaeV6f_.js → media-plugins-DX4AgkCs.js} +1 -1
- package/dist/gateway/static/root/assets/messages-CKZuaOeG.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-Cd2HpciM.js → notes-page-D1KprtxL.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-wgt2Osyk.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-DyimBUp_.js → page-tabs-DjZPJGf6.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-BKZulEYr.js → preview-open-alternatives-DNiJTpwZ.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-Bjz9BxBY.js → product-open-page-CNfR17-g.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-CDjHvxJm.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-kJZwQXfC.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-MJdI9ek_.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-BPTqb2_r.js → save-bar-controls-BGZFVO9S.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-YN0D81Dk.js → schedule-field-BAZiHtds.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BmY5PSS2.js → schema-form-CesBcwJH.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-BqC7GDC_.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-CYwz8MfF.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-B-RhgD_p.js → settings-form-section-Bxc54BLj.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-DkPupX2B.js → settings-loading-skeleton-CYrho7Db.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-2QBMvaxj.js → settings-page-C03X5fkh.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-CtrW-LD6.js → settings-page-layout-CZAJbv4E.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Jv8_bcOD.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BezIW1n9.js → share-preview-page-DSC7tKKG.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-h8tGDkA3.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-D2DGvRUn.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-vqhjSMhZ.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-WAFhKyAu.js → system-settings-panel-BO89zw5H.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BiC0gIBa.js → theme-store-1OkdVC8l.js} +1 -1
- package/dist/gateway/static/root/assets/time-picker-mtD64kFB.js +1 -0
- package/dist/gateway/static/root/assets/{typed-models-lib-WAQO3F_8.js → typed-models-lib-D-_vct_y.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-CKlfsSeU.js → use-channel-catalog-VlFtjlET.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-BgF0WxjM.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-BAFHF0_v.js → voice-api-key-field-BhDk-UV_.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-CP0Daig-.js +1 -0
- package/dist/gateway/static/root/assets/work-item-detail-page-NEWZPKB_.js +1 -0
- package/dist/gateway/static/root/assets/work-page-BkWntcQh.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-1OP4HyvS.js → workflow-run-setup-panel-uVw4Yoej.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-DRvhNQGe.js +11 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +71 -24
- package/dist/src/agent/embedded/run-turn.js +68 -4
- package/dist/src/agent/inbound/inbound-loop.d.ts +0 -2
- package/dist/src/agent/inbound/inbound-loop.js +0 -2
- package/dist/src/agent/memory/compaction-planner.d.ts +16 -0
- package/dist/src/agent/memory/compaction-planner.js +152 -0
- package/dist/src/agent/memory/compaction-policy.d.ts +10 -0
- package/dist/src/agent/memory/compaction-policy.js +24 -0
- package/dist/src/agent/memory/compaction.d.ts +21 -22
- package/dist/src/agent/memory/compaction.js +220 -194
- package/dist/src/agent/memory/context-budget.d.ts +40 -0
- package/dist/src/agent/memory/context-budget.js +106 -0
- package/dist/src/agent/orchestration/context-overflow.d.ts +1 -0
- package/dist/src/agent/orchestration/context-overflow.js +19 -0
- package/dist/src/agent/orchestration/loop-guard.js +13 -9
- package/dist/src/agent/reply/post-compaction-context.d.ts +4 -0
- package/dist/src/agent/reply/post-compaction-context.js +5 -3
- package/dist/src/agent/service/process-direct-one-shot.js +1 -2
- package/dist/src/agent/service/process-direct-streaming.js +1 -2
- package/dist/src/agent/service.d.ts +0 -2
- package/dist/src/agent/service.js +13 -44
- package/dist/src/agent/session/session-inspector.js +10 -2
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/config/schema.d.ts +17 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +23 -0
- package/dist/src/gateway/hono/lib/config-payload.js +3 -0
- package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +28 -0
- package/dist/src/gateway/hono/routes/sessions.js +17 -42
- package/dist/src/gateway/service/sessions-api.d.ts +2 -3
- package/dist/src/gateway/service/sessions-api.js +4 -7
- package/dist/src/session/index.d.ts +1 -2
- package/dist/src/session/index.js +1 -2
- package/dist/src/session/init-session-turn.d.ts +0 -1
- package/dist/src/session/init-session-turn.js +1 -2
- package/dist/src/session/manager.d.ts +11 -17
- package/dist/src/session/manager.js +11 -14
- package/dist/src/session/session-context-for-llm.d.ts +19 -1
- package/dist/src/session/session-context-for-llm.js +87 -129
- package/dist/src/session/store.d.ts +28 -23
- package/dist/src/session/store.js +94 -83
- package/dist/src/session/transcript-format.d.ts +2 -8
- package/dist/src/session/types.d.ts +8 -6
- package/dist/src/session/user-round-delete.d.ts +3 -6
- package/dist/src/session/user-round-delete.js +12 -16
- package/dist/src/storage/sqlite/index.d.ts +1 -1
- package/dist/src/storage/sqlite/index.js +2 -2
- package/dist/src/storage/sqlite/migrations/060_remove_runtime_transcript_messages.sql +45 -0
- package/dist/src/storage/sqlite/migrations/061_drop_compaction_checkpoints.sql +2 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -19
- package/dist/src/storage/sqlite/transcript-repository.d.ts +6 -11
- package/dist/src/storage/sqlite/transcript-repository.js +90 -84
- package/dist/src/user-context/config.d.ts +67 -2
- package/dist/src/user-context/config.js +36 -3
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents-BiaQhiQp.js +0 -2
- package/dist/gateway/static/root/assets/automations-page-TZOluRNp.js +0 -6
- package/dist/gateway/static/root/assets/block-editor-D_LDNlB-.js +0 -184
- package/dist/gateway/static/root/assets/browser-settings-page-C-l6O68Z.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BW8c0xPp.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-PTz00nR4.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-h9CsE0GT.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-C058Mcfr.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-BWALafGW.js +0 -2
- package/dist/gateway/static/root/assets/desktop-pet-CkT98fPT.js +0 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-y2Y3p7_k.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-DuzL-alv.js +0 -4
- package/dist/gateway/static/root/assets/goals-page-OeLtfKI2.js +0 -2
- package/dist/gateway/static/root/assets/index-o4uaOGKT.css +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-3ssYIEK6.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-DoCY0Mm9.js +0 -7
- package/dist/gateway/static/root/assets/messages-KEk-hTFt.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-CatZNAPc.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-DJUOgqm4.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-BQQAD_nu.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-fIGXTTnA.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-BuU-8FCe.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DlKoeZm3.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BSUcDFnb.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-Bk2-SwGJ.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-e_Fx1kVC.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-D_cCADfj.js +0 -2
- package/dist/gateway/static/root/assets/time-picker-fqRXpNJV.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-9Ov4htPW.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-DGN2FxWv.js +0 -1
- package/dist/gateway/static/root/assets/work-item-detail-page-HmyWSgUo.js +0 -1
- package/dist/gateway/static/root/assets/work-page-D3iKVjFq.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-B5L4SFw4.js +0 -11
- package/dist/src/agent/lifecycle/handlers/compaction.d.ts +0 -13
- package/dist/src/agent/lifecycle/handlers/compaction.js +0 -18
- package/dist/src/session/compaction-checkpoints.d.ts +0 -8
- package/dist/src/session/compaction-checkpoints.js +0 -19
|
@@ -3,18 +3,19 @@ import { createLogger } from "../utils/logger/index.js";
|
|
|
3
3
|
import { init_logger } from "../utils/logger.js";
|
|
4
4
|
import { requireXopcDatabase } from "../storage/sqlite/connection.js";
|
|
5
5
|
import "./types.js";
|
|
6
|
-
import { buildSessionContextForLlm, buildSessionDisplayMessages, mergeLlmMessagesPreservingContextRows, transcriptRowsFromJsonArray } from "./session-context-for-llm.js";
|
|
6
|
+
import { buildSessionContextForLlm, buildSessionDisplayMessages, isRuntimeOnlyTranscriptMessage, isTranscriptCompactionEntry, mergeLlmMessagesPreservingContextRows, transcriptRowsFromJsonArray } from "./session-context-for-llm.js";
|
|
7
7
|
import { estimateTokensFromMessages } from "../storage/sqlite/row-mappers.js";
|
|
8
8
|
import { deleteSessionRecord, ensureSessionRecord, findSessionKeyBySessionId, getGlobalSessionStats, getSessionMetadata, listSessionMetadata, listSessionsByAgent, patchSessionMetadata, resetSessionRecord } from "../storage/sqlite/session-repository.js";
|
|
9
|
-
import {
|
|
9
|
+
import { appendCompactionBoundary, appendTranscriptEntry, listCompactionBoundaries, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRowsForSession, paginateTranscriptMessages, replaceTranscriptRows, restoreBeforeCompactionBoundary } from "../storage/sqlite/transcript-repository.js";
|
|
10
10
|
import "../storage/sqlite/index.js";
|
|
11
11
|
import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.js";
|
|
12
12
|
import { readPostCompactionContext } from "../agent/reply/post-compaction-context.js";
|
|
13
13
|
import { SessionCompactor } from "../agent/memory/compaction.js";
|
|
14
|
+
import { resolveCompactionPolicy } from "../agent/memory/compaction-policy.js";
|
|
14
15
|
import { SlidingWindow } from "../agent/memory/window.js";
|
|
15
|
-
import { normalizeCompactionCheckpointId } from "./compaction-checkpoints.js";
|
|
16
16
|
import { isAppendOnlyLlmTranscriptMessage } from "./transcript-stats.js";
|
|
17
17
|
import { transcriptRowsToClientHistory } from "./client-history.js";
|
|
18
|
+
import { computeTranscriptUserRoundDeleteRange } from "./user-round-delete.js";
|
|
18
19
|
//#region src/session/store.ts
|
|
19
20
|
init_paths_state();
|
|
20
21
|
init_logger();
|
|
@@ -23,11 +24,30 @@ const INDEX_VERSION = "1.0";
|
|
|
23
24
|
var SessionStore = class {
|
|
24
25
|
window;
|
|
25
26
|
compactor;
|
|
27
|
+
compactionHooks = {};
|
|
26
28
|
constructor(options, windowConfig, compactionConfig) {
|
|
27
29
|
this.options = options;
|
|
28
30
|
this.window = new SlidingWindow(windowConfig);
|
|
29
31
|
this.compactor = new SessionCompactor(compactionConfig);
|
|
30
32
|
}
|
|
33
|
+
setCompactionHooks(hooks) {
|
|
34
|
+
this.compactionHooks = hooks;
|
|
35
|
+
}
|
|
36
|
+
async runCompactionHook(phase, event) {
|
|
37
|
+
try {
|
|
38
|
+
if (phase === "before") await this.compactionHooks.before?.(event);
|
|
39
|
+
else await this.compactionHooks.after?.({
|
|
40
|
+
...event,
|
|
41
|
+
compactedCount: event.compactedCount ?? 0
|
|
42
|
+
});
|
|
43
|
+
} catch (err) {
|
|
44
|
+
log.warn({
|
|
45
|
+
err,
|
|
46
|
+
phase,
|
|
47
|
+
sessionKey: event.sessionKey
|
|
48
|
+
}, `Session compaction ${phase} hook failed`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
31
51
|
resolveWorkspaceCwd(sessionKey) {
|
|
32
52
|
return resolveEffectiveAgentProfileForSession(this.options.config, sessionKey).resolvedWorkspacePath;
|
|
33
53
|
}
|
|
@@ -94,8 +114,7 @@ var SessionStore = class {
|
|
|
94
114
|
limit,
|
|
95
115
|
offset: hasBeforeCursor ? void 0 : offset,
|
|
96
116
|
beforeIndex: hasBeforeCursor ? parsedBefore : void 0,
|
|
97
|
-
includeContext: true
|
|
98
|
-
includeArchived: true
|
|
117
|
+
includeContext: true
|
|
99
118
|
});
|
|
100
119
|
const messages = transcriptRowsToClientHistory(page.rows);
|
|
101
120
|
const endIndex = hasBeforeCursor ? Math.min(page.total, Math.max(0, parsedBefore)) : Math.max(0, page.total - offset);
|
|
@@ -242,16 +261,19 @@ var SessionStore = class {
|
|
|
242
261
|
if (!metadata?.sessionId) return null;
|
|
243
262
|
const rows = await this.loadTranscriptRows(key);
|
|
244
263
|
const compactions = [];
|
|
245
|
-
for (const row of rows) if (row
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
264
|
+
for (const row of rows) if (isTranscriptCompactionEntry(row)) compactions.push({
|
|
265
|
+
at: row.at,
|
|
266
|
+
baseSeq: row.baseSeq,
|
|
267
|
+
plannerVersion: row.plannerVersion,
|
|
268
|
+
summaryModelRef: row.summaryModelRef,
|
|
269
|
+
qualityAudit: row.qualityAudit,
|
|
270
|
+
summary: row.summary,
|
|
271
|
+
messages: row.messages,
|
|
272
|
+
firstKeptIndex: row.firstKeptIndex,
|
|
273
|
+
tokensBefore: row.tokensBefore,
|
|
274
|
+
tokensAfter: row.tokensAfter,
|
|
275
|
+
restoredFromCompactionId: row.restoredFromCompactionId
|
|
276
|
+
});
|
|
255
277
|
return {
|
|
256
278
|
type: "xopc_session_transcript",
|
|
257
279
|
version: 1,
|
|
@@ -346,34 +368,42 @@ var SessionStore = class {
|
|
|
346
368
|
replaceTranscriptRows(key, mergeLlmMessagesPreservingContextRows(await this.loadTranscriptRows(key), messages));
|
|
347
369
|
});
|
|
348
370
|
}
|
|
371
|
+
async deleteUserRound(key, userRoundIndex) {
|
|
372
|
+
return this.runStoreMutation(async () => {
|
|
373
|
+
requireXopcDatabase();
|
|
374
|
+
const canonicalRows = (await this.loadTranscriptRows(key)).filter((row) => !isTranscriptCompactionEntry(row) && !isRuntimeOnlyTranscriptMessage(row));
|
|
375
|
+
const range = computeTranscriptUserRoundDeleteRange(canonicalRows, userRoundIndex);
|
|
376
|
+
if (!range) return null;
|
|
377
|
+
const removedRows = canonicalRows.slice(range.startIndex, range.startIndex + range.count);
|
|
378
|
+
const remainingRows = canonicalRows.slice(0, range.startIndex).concat(canonicalRows.slice(range.startIndex + range.count));
|
|
379
|
+
const removedMessages = buildSessionDisplayMessages(removedRows);
|
|
380
|
+
const remainingMessages = buildSessionDisplayMessages(remainingRows);
|
|
381
|
+
replaceTranscriptRows(key, remainingRows);
|
|
382
|
+
return {
|
|
383
|
+
deleted: removedMessages.length,
|
|
384
|
+
removedMessages,
|
|
385
|
+
remainingMessages
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
}
|
|
349
389
|
getWindowStats(messages) {
|
|
350
390
|
return this.window.getStats(messages);
|
|
351
391
|
}
|
|
352
|
-
needsCompaction(key, messages, contextWindow) {
|
|
353
|
-
return this.compactor.needsCompaction(messages, contextWindow);
|
|
354
|
-
}
|
|
355
|
-
prepareCompaction(key, messages, contextWindow) {
|
|
356
|
-
const result = this.compactor.needsCompaction(messages, contextWindow);
|
|
357
|
-
return {
|
|
358
|
-
needsCompaction: result.needed,
|
|
359
|
-
messages,
|
|
360
|
-
stats: result
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
392
|
async applyCompaction(key, messages, result) {
|
|
364
393
|
const compacted = this.compactor.applyCompaction(messages, result);
|
|
365
394
|
return this.runStoreMutation(async () => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
replaceTranscriptRows(key, merged, { appendCompaction: {
|
|
395
|
+
appendCompactionBoundary(key, {
|
|
396
|
+
type: "compaction",
|
|
369
397
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
398
|
+
plannerVersion: result.plannerVersion ?? 2,
|
|
399
|
+
summaryModelRef: result.summaryModelRef ?? "unknown",
|
|
400
|
+
qualityAudit: result.qualityAudit ?? "disabled",
|
|
370
401
|
summary: result.summary,
|
|
402
|
+
messages: compacted,
|
|
371
403
|
firstKeptIndex: result.firstKeptIndex,
|
|
372
404
|
tokensBefore: result.tokensBefore,
|
|
373
405
|
tokensAfter: result.tokensAfter
|
|
374
|
-
}
|
|
375
|
-
const metadata = await this.getMetadata(key);
|
|
376
|
-
if (metadata) await this.updateMetadata(key, { compactedCount: metadata.compactedCount + 1 });
|
|
406
|
+
});
|
|
377
407
|
log.info({
|
|
378
408
|
key,
|
|
379
409
|
tokensBefore: result.tokensBefore,
|
|
@@ -384,37 +414,44 @@ var SessionStore = class {
|
|
|
384
414
|
return compacted;
|
|
385
415
|
});
|
|
386
416
|
}
|
|
387
|
-
async compact(key, messages,
|
|
388
|
-
const
|
|
389
|
-
|
|
417
|
+
async compact(key, messages, model, instructions, force, executionOptions) {
|
|
418
|
+
const tokenCount = this.estimateTokens(messages);
|
|
419
|
+
await this.runCompactionHook("before", {
|
|
420
|
+
sessionKey: key,
|
|
421
|
+
messageCount: messages.length,
|
|
422
|
+
tokenCount
|
|
423
|
+
});
|
|
424
|
+
const result = await this.compactor.compact(messages, model, instructions, force, executionOptions);
|
|
425
|
+
if (result.compacted) {
|
|
426
|
+
const compacted = await this.applyCompaction(key, messages, result);
|
|
427
|
+
await this.runCompactionHook("after", {
|
|
428
|
+
sessionKey: key,
|
|
429
|
+
messageCount: compacted.length,
|
|
430
|
+
tokenCount: result.tokensAfter,
|
|
431
|
+
compactedCount: Math.max(0, Math.min(messages.length, result.firstKeptIndex))
|
|
432
|
+
});
|
|
433
|
+
}
|
|
390
434
|
return result;
|
|
391
435
|
}
|
|
392
436
|
async getCompactionStats(key) {
|
|
393
|
-
|
|
394
|
-
|
|
437
|
+
if (!await this.getMetadata(key)) return void 0;
|
|
438
|
+
const boundaries = listCompactionBoundaries(key);
|
|
395
439
|
return {
|
|
396
|
-
compactionCount:
|
|
397
|
-
totalTokensBefore: 0,
|
|
398
|
-
totalTokensAfter: 0,
|
|
399
|
-
lastCompactionAt:
|
|
440
|
+
compactionCount: boundaries.length,
|
|
441
|
+
totalTokensBefore: boundaries.reduce((sum, boundary) => sum + boundary.tokensBefore, 0),
|
|
442
|
+
totalTokensAfter: boundaries.reduce((sum, boundary) => sum + boundary.tokensAfter, 0),
|
|
443
|
+
lastCompactionAt: boundaries[0]?.createdAt
|
|
400
444
|
};
|
|
401
445
|
}
|
|
402
|
-
async
|
|
403
|
-
requireXopcDatabase();
|
|
404
|
-
return listCompactionCheckpoints(key);
|
|
405
|
-
}
|
|
406
|
-
async getCompactionCheckpointDetail(key, checkpointId) {
|
|
446
|
+
async listCompactionBoundaries(key) {
|
|
407
447
|
requireXopcDatabase();
|
|
408
|
-
|
|
409
|
-
if (!id) return null;
|
|
410
|
-
return getCompactionCheckpointDetail(key, id);
|
|
448
|
+
return listCompactionBoundaries(key);
|
|
411
449
|
}
|
|
412
|
-
async
|
|
450
|
+
async restoreBeforeCompactionBoundary(key, compactionId) {
|
|
413
451
|
return this.runStoreMutation(async () => {
|
|
414
452
|
requireXopcDatabase();
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
restoreCompactionCheckpoint(key, id);
|
|
453
|
+
if (!compactionId.trim()) throw new Error("compactionId is required");
|
|
454
|
+
restoreBeforeCompactionBoundary(key, compactionId);
|
|
418
455
|
});
|
|
419
456
|
}
|
|
420
457
|
async deleteSession(key) {
|
|
@@ -553,20 +590,7 @@ var SessionStore = class {
|
|
|
553
590
|
}
|
|
554
591
|
async loadDisplayMessages(key) {
|
|
555
592
|
requireXopcDatabase();
|
|
556
|
-
|
|
557
|
-
const rowSets = [];
|
|
558
|
-
for (const checkpoint of [...checkpoints].reverse()) rowSets.push(loadCheckpointRows(key, checkpoint.id));
|
|
559
|
-
rowSets.push(await this.loadTranscriptRows(key));
|
|
560
|
-
const messages = [];
|
|
561
|
-
const seen = /* @__PURE__ */ new Set();
|
|
562
|
-
for (const rows of rowSets) for (const message of buildSessionDisplayMessages(rows)) {
|
|
563
|
-
if (this.isCompactionSummaryMessage(message)) continue;
|
|
564
|
-
const identity = this.displayMessageIdentity(message);
|
|
565
|
-
if (seen.has(identity)) continue;
|
|
566
|
-
seen.add(identity);
|
|
567
|
-
messages.push(message);
|
|
568
|
-
}
|
|
569
|
-
return messages;
|
|
593
|
+
return buildSessionDisplayMessages(await this.loadTranscriptRows(key));
|
|
570
594
|
}
|
|
571
595
|
paginateDisplayMessages(messages, options = {}) {
|
|
572
596
|
const total = messages.length;
|
|
@@ -588,24 +612,9 @@ var SessionStore = class {
|
|
|
588
612
|
endIndex
|
|
589
613
|
};
|
|
590
614
|
}
|
|
591
|
-
displayMessageIdentity(message) {
|
|
592
|
-
const record = message;
|
|
593
|
-
return JSON.stringify({
|
|
594
|
-
role: message.role,
|
|
595
|
-
timestamp: record.timestamp,
|
|
596
|
-
toolCallId: record.toolCallId ?? record.tool_call_id,
|
|
597
|
-
toolName: record.toolName,
|
|
598
|
-
content: this.messageContent(message)
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
615
|
messageContent(msg) {
|
|
602
616
|
return msg.content;
|
|
603
617
|
}
|
|
604
|
-
isCompactionSummaryMessage(msg) {
|
|
605
|
-
if (msg.role !== "user") return false;
|
|
606
|
-
const text = this.extractTextContent(this.messageContent(msg)).trim();
|
|
607
|
-
return /^\[Previous conversation summary\]/i.test(text);
|
|
608
|
-
}
|
|
609
618
|
extractTextContent(content) {
|
|
610
619
|
if (typeof content === "string") return content;
|
|
611
620
|
if (Array.isArray(content)) {
|
|
@@ -621,9 +630,11 @@ var SessionStore = class {
|
|
|
621
630
|
return "";
|
|
622
631
|
}
|
|
623
632
|
async injectPostCompactionContext(key) {
|
|
633
|
+
const policy = resolveCompactionPolicy(this.options.config);
|
|
624
634
|
const contextText = readPostCompactionContext({
|
|
625
635
|
cfg: this.options.config,
|
|
626
|
-
sessionKey: key
|
|
636
|
+
sessionKey: key,
|
|
637
|
+
sectionNames: policy.postCompactionSections
|
|
627
638
|
});
|
|
628
639
|
if (!contextText?.trim()) return;
|
|
629
640
|
try {
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* API-level transcript summary types (authoritative storage is SQLite `transcript_entries`).
|
|
3
3
|
*/
|
|
4
|
-
import type { TranscriptStoredRow } from './session-context-for-llm.js';
|
|
4
|
+
import type { TranscriptStoredRow, XopcTranscriptCompactionEntry } from './session-context-for-llm.js';
|
|
5
5
|
export declare const XOPC_SESSION_TRANSCRIPT_TYPE: "xopc_session_transcript";
|
|
6
6
|
export declare const CURRENT_SESSION_TRANSCRIPT_VERSION = 1;
|
|
7
7
|
/** Record appended when context compaction runs (mirrors pi `CompactionEntry` audit fields). */
|
|
8
|
-
export
|
|
9
|
-
at: string;
|
|
10
|
-
summary: string;
|
|
11
|
-
firstKeptIndex: number;
|
|
12
|
-
tokensBefore: number;
|
|
13
|
-
tokensAfter: number;
|
|
14
|
-
}
|
|
8
|
+
export type TranscriptCompactionRecord = Omit<XopcTranscriptCompactionEntry, 'type'>;
|
|
15
9
|
/** Synthetic document shape returned by {@link SessionStore.loadTranscriptDocument} for API parity. */
|
|
16
10
|
export interface XopcSessionTranscriptV1 {
|
|
17
11
|
type: typeof XOPC_SESSION_TRANSCRIPT_TYPE;
|
|
@@ -179,12 +179,14 @@ export interface SessionExport {
|
|
|
179
179
|
/** Full on-disk rows (LLM + `kind: 'context'`) for audit / round-trip. */
|
|
180
180
|
transcriptRows: TranscriptStoredRow[];
|
|
181
181
|
}
|
|
182
|
-
/**
|
|
183
|
-
export interface
|
|
182
|
+
/** Append-only context boundary produced by compaction or logical restoration. */
|
|
183
|
+
export interface CompactionBoundarySummary {
|
|
184
184
|
id: string;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
export interface CompactionCheckpointDetail extends CompactionCheckpointSummary {
|
|
185
|
+
seq: number;
|
|
186
|
+
createdAt: string;
|
|
189
187
|
messageCount: number;
|
|
188
|
+
tokensBefore: number;
|
|
189
|
+
tokensAfter: number;
|
|
190
|
+
summaryPreview: string;
|
|
191
|
+
restoredFromCompactionId?: string;
|
|
190
192
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
* assistant / tool / toolResult row until the next user (or EOF).
|
|
5
|
-
*/
|
|
6
|
-
export declare function computeUserRoundDeleteRange(messages: readonly AgentMessage[], userRoundIndex: number): {
|
|
1
|
+
import { type TranscriptStoredRow } from './session-context-for-llm.js';
|
|
2
|
+
/** Raw transcript range for one UI-visible user turn. */
|
|
3
|
+
export declare function computeTranscriptUserRoundDeleteRange(rows: readonly TranscriptStoredRow[], userRoundIndex: number): {
|
|
7
4
|
startIndex: number;
|
|
8
5
|
count: number;
|
|
9
6
|
} | null;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
+
import { isTranscriptCustomMessageEntry } from "./session-context-for-llm.js";
|
|
1
2
|
//#region src/session/user-round-delete.ts
|
|
2
|
-
function
|
|
3
|
-
return
|
|
3
|
+
function isVisibleUserRow(row) {
|
|
4
|
+
if (isTranscriptCustomMessageEntry(row)) return row.display !== false;
|
|
5
|
+
return row.role === "user";
|
|
4
6
|
}
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
function computeUserRoundDeleteRange(messages, userRoundIndex) {
|
|
10
|
-
if (userRoundIndex < 0 || messages.length === 0) return null;
|
|
7
|
+
/** Raw transcript range for one UI-visible user turn. */
|
|
8
|
+
function computeTranscriptUserRoundDeleteRange(rows, userRoundIndex) {
|
|
9
|
+
if (!Number.isInteger(userRoundIndex) || userRoundIndex < 0 || rows.length === 0) return null;
|
|
11
10
|
let userCount = 0;
|
|
12
11
|
let startIndex = -1;
|
|
13
|
-
for (let
|
|
14
|
-
if (!
|
|
12
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
13
|
+
if (!isVisibleUserRow(rows[index])) continue;
|
|
15
14
|
if (userCount === userRoundIndex) {
|
|
16
|
-
startIndex =
|
|
15
|
+
startIndex = index;
|
|
17
16
|
break;
|
|
18
17
|
}
|
|
19
18
|
userCount += 1;
|
|
20
19
|
}
|
|
21
20
|
if (startIndex < 0) return null;
|
|
22
21
|
let end = startIndex + 1;
|
|
23
|
-
while (end <
|
|
24
|
-
if (isUserRole(String(messages[end]?.role ?? ""))) break;
|
|
25
|
-
end += 1;
|
|
26
|
-
}
|
|
22
|
+
while (end < rows.length && !isVisibleUserRow(rows[end])) end += 1;
|
|
27
23
|
return {
|
|
28
24
|
startIndex,
|
|
29
25
|
count: end - startIndex
|
|
30
26
|
};
|
|
31
27
|
}
|
|
32
28
|
//#endregion
|
|
33
|
-
export {
|
|
29
|
+
export { computeTranscriptUserRoundDeleteRange };
|
|
@@ -12,7 +12,7 @@ export { completeTaskOutcome, findTaskOutcomeForAssistant, getTaskOutcome, listT
|
|
|
12
12
|
export { buildDefaultSessionMetadata, type SessionMetadataSeed, } from './session-metadata.js';
|
|
13
13
|
export { buildGlobalSessionStats, classifyStoredRow, estimateTokensFromMessages, extractFtsContent, metadataToSessionInsert, sessionConfigRowToConfig, sessionRowToMetadata, transcriptEntryRowToStoredRow, type SessionConfigRow, type SessionRow, type TranscriptEntryRow, } from './row-mappers.js';
|
|
14
14
|
export { deleteSessionRecord, ensureSessionRecord, getCurrentSessionId, getGlobalSessionStats, findSessionKeyBySessionId, getSessionPersistedLevels, getSessionMetadata, incrementSessionStatsOnAppend, listSessionMetadata, listSessionsByAgent, patchSessionMetadata, resetSessionRecord, resolveSessionAgentId, updateSessionStats, } from './session-repository.js';
|
|
15
|
-
export {
|
|
15
|
+
export { appendCompactionBoundary, appendTranscriptEntry, listCompactionBoundaries, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRows, loadTranscriptRowsForSession, paginateTranscriptMessages, replaceTranscriptRows, restoreBeforeCompactionBoundary, } from './transcript-repository.js';
|
|
16
16
|
export { deleteNoteRecord, getNoteRecord, listNoteRecords, upsertNoteRecord, } from './notes-repository.js';
|
|
17
17
|
export { deleteNoteAgentContextRecord, getNoteAgentContextRecord, upsertNoteAgentContextRecord, type NoteAgentContextRecord, } from './note-agent-context-repository.js';
|
|
18
18
|
export { searchMemoryIndex, syncMemoryIndex, type MemorySearchHit, } from './memory-index-repository.js';
|
|
@@ -13,7 +13,7 @@ import { completeTaskOutcome, findTaskOutcomeForAssistant, getTaskOutcome, listT
|
|
|
13
13
|
import { buildDefaultSessionMetadata } from "./session-metadata.js";
|
|
14
14
|
import { buildGlobalSessionStats, classifyStoredRow, estimateTokensFromMessages, extractFtsContent, metadataToSessionInsert, sessionConfigRowToConfig, sessionRowToMetadata, transcriptEntryRowToStoredRow } from "./row-mappers.js";
|
|
15
15
|
import { deleteSessionRecord, ensureSessionRecord, findSessionKeyBySessionId, getCurrentSessionId, getGlobalSessionStats, getSessionMetadata, getSessionPersistedLevels, incrementSessionStatsOnAppend, listSessionMetadata, listSessionsByAgent, patchSessionMetadata, resetSessionRecord, resolveSessionAgentId, updateSessionStats } from "./session-repository.js";
|
|
16
|
-
import {
|
|
16
|
+
import { appendCompactionBoundary, appendTranscriptEntry, listCompactionBoundaries, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRows, loadTranscriptRowsForSession, paginateTranscriptMessages, replaceTranscriptRows, restoreBeforeCompactionBoundary } from "./transcript-repository.js";
|
|
17
17
|
import { deleteNoteRecord, getNoteRecord, listNoteRecords, upsertNoteRecord } from "./notes-repository.js";
|
|
18
18
|
import { deleteNoteAgentContextRecord, getNoteAgentContextRecord, upsertNoteAgentContextRecord } from "./note-agent-context-repository.js";
|
|
19
19
|
import { searchMemoryIndex, syncMemoryIndex } from "./memory-index-repository.js";
|
|
@@ -25,4 +25,4 @@ import { appendConnectorExecutionAudit, claimConnectorWebhookDelivery, completeC
|
|
|
25
25
|
import { getUserTrustPolicy, setUserTrustPolicy } from "./user-trust-repository.js";
|
|
26
26
|
import { consumeMemoryReferenceConsent, decideMemoryReferenceConsent, ensureMemoryReferenceConsentRequest, hasMemoryReferenceConsent, listMemoryReferenceConsents, revokeMemoryReferenceConsent } from "./memory-reference-consent-repository.js";
|
|
27
27
|
import { getUserProfilePromptState, setUserProfilePromptState } from "./user-profile-setup-repository.js";
|
|
28
|
-
export { COMPOSER_INPUT_HISTORY_LIMIT, DatabaseSchemaMigrationGapError, DatabaseSchemaTooNewError, SCHEMA_META_SCHEMA_VERSION_KEY, USER_UNDERSTANDING_REMEDIATION_POLICY, XOPC_DB_BASELINE_SCHEMA_VERSION, XOPC_DB_FILENAME, XOPC_DB_SCHEMA_VERSION, appendComposerInputHistory, appendConnectorExecutionAudit, appendMemorySignal, appendMemoryTraceEvent, appendTranscriptEntry, applyPendingMigrations, attachMemoryEvidence, buildDefaultSessionMetadata, buildGlobalSessionStats, buildRelationshipPrompt,
|
|
28
|
+
export { COMPOSER_INPUT_HISTORY_LIMIT, DatabaseSchemaMigrationGapError, DatabaseSchemaTooNewError, SCHEMA_META_SCHEMA_VERSION_KEY, USER_UNDERSTANDING_REMEDIATION_POLICY, XOPC_DB_BASELINE_SCHEMA_VERSION, XOPC_DB_FILENAME, XOPC_DB_SCHEMA_VERSION, appendCompactionBoundary, appendComposerInputHistory, appendConnectorExecutionAudit, appendMemorySignal, appendMemoryTraceEvent, appendTranscriptEntry, applyPendingMigrations, attachMemoryEvidence, buildDefaultSessionMetadata, buildGlobalSessionStats, buildRelationshipPrompt, claimConnectorWebhookDelivery, claimKnowledgeSourceItems, classifyStoredRow, clearComposerInputHistory, closeXopcDatabase, completeConnectorWebhookDelivery, completeKnowledgeSourceItemSynthesis, completeTaskOutcome, consumeConnectorApproval, consumeMemoryReferenceConsent, createConnectorApproval, createObjectLinkRecord, decideConnectorApproval, decideMemoryReferenceConsent, deleteConnectorConnection, deleteConnectorInstallation, deleteMemoryEvidenceForRecord, deleteMemoryRecord, deleteNoteAgentContextRecord, deleteNoteRecord, deleteSessionConfig, deleteSessionRecord, discoverSqlMigrations, ensureMemoryReferenceConsentRequest, ensureSessionRecord, ensureXopcDatabaseSchema, estimateTokensFromMessages, extractFtsContent, findLatestMemoryInjectTrace, findSessionKeyBySessionId, findTaskOutcomeForAssistant, finishKnowledgeSyncRun, getActivityEventRecord, getCachedConnectorCatalogEntry, getConnectorApproval, getConnectorConnection, getConnectorInstallation, getCurrentSessionId, getGlobalSessionStats, getInteractionState, getKnowledgeConsumerWatermark, getKnowledgeSourceCursor, getKnowledgeSourceItem, getMemoryProviderState, getMemoryRecord, getNoteAgentContextRecord, getNoteRecord, getRelationshipSettings, getSessionConfig, getSessionMetadata, getSessionPersistedLevels, getSqliteDatabase, getTaskOutcome, getUserProfilePromptState, getUserTrustPolicy, getXopcDatabase, hasMemoryReferenceConsent, hasSessionConfig, hasUnresolvedMemoryConflict, incrementSessionStatsOnAppend, inspectSchemaMigrationStatus, isProactiveSupportAllowed, isXopcDatabaseOpen, listActivityRecords, listCachedConnectorCatalogEntries, listCompactionBoundaries, listComposerInputHistory, listConnectorActionMetadata, listConnectorApprovals, listConnectorConnections, listConnectorExecutionAudit, listConnectorInstallations, listKnowledgeSourceChanges, listKnowledgeSourceItems, listKnowledgeSyncRuns, listMemoryEvidence, listMemoryRecords, listMemoryReferenceConsents, listMemorySignals, listMemoryTraceEvents, listNoteRecords, listObjectActivityRecords, listObjectLinkRecords, listProjectActivityRecords, listRegisteredMigrationTargets, listSessionMetadata, listSessionsByAgent, listTaskOutcomes, loadLlmMessagesForSession, loadTranscriptHistoryRowsForSession, loadTranscriptRows, loadTranscriptRowsForSession, markMemoryRecordsConflicted, metadataToSessionInsert, openXopcDatabase, paginateTranscriptMessages, patchSessionMetadata, readSchemaVersion, readSchemaVersionForTest, recordActivityEvent, releaseConnectorWebhookDelivery, replaceConnectorCatalogEntries, replaceTranscriptRows, requireXopcDatabase, resetSessionRecord, resetXopcDatabaseSingletonForTest, resolveMigrationsDir, resolveSessionAgentId, resolveXopcDatabasePath, restoreBeforeCompactionBoundary, revokeMemoryReferenceConsent, runSqliteWriteTransaction, searchMemoryIndex, searchMemoryRecords, sessionConfigRowToConfig, sessionRowToMetadata, setInteractionState, setKnowledgeConsumerWatermark, setKnowledgeSourceCursor, setKnowledgeSourceItemSynthesisStatus, setLatestMemoryInjectFeedback, setMemoryProviderState, setMemoryTraceFeedback, setSessionConfig, setTaskOutcomeFeedback, setUserProfilePromptState, setUserTrustPolicy, startKnowledgeSyncRun, startTaskOutcome, summarizeMemoryRecallFeedback, summarizeTaskOutcomes, summarizeUserUnderstandingQuality, syncMemoryIndex, transcriptEntryRowToStoredRow, updateInteractionStateFromMessage, updateRelationshipSettings, updateSessionConfig, updateSessionStats, updateTaskOutcome, upsertConnectorActionMetadata, upsertConnectorCatalogEntry, upsertConnectorConnection, upsertConnectorInstallation, upsertKnowledgeSourceItems, upsertMemoryRecord, upsertNoteAgentContextRecord, upsertNoteRecord };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
CREATE TEMP TABLE xopc_runtime_transcript_cleanup_sessions (
|
|
2
|
+
session_id TEXT PRIMARY KEY
|
|
3
|
+
);
|
|
4
|
+
|
|
5
|
+
INSERT INTO xopc_runtime_transcript_cleanup_sessions (session_id)
|
|
6
|
+
SELECT DISTINCT session_id
|
|
7
|
+
FROM transcript_entries
|
|
8
|
+
WHERE entry_kind = 'message'
|
|
9
|
+
AND json_extract(payload_json, '$.droppable') = 1;
|
|
10
|
+
|
|
11
|
+
DELETE FROM transcript_fts
|
|
12
|
+
WHERE entry_id IN (
|
|
13
|
+
SELECT entry_id
|
|
14
|
+
FROM transcript_entries
|
|
15
|
+
WHERE session_id IN (SELECT session_id FROM xopc_runtime_transcript_cleanup_sessions)
|
|
16
|
+
AND (
|
|
17
|
+
json_extract(payload_json, '$.droppable') = 1
|
|
18
|
+
OR json_extract(payload_json, '$.type') = 'compaction'
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
DELETE FROM transcript_entries
|
|
23
|
+
WHERE session_id IN (SELECT session_id FROM xopc_runtime_transcript_cleanup_sessions)
|
|
24
|
+
AND (
|
|
25
|
+
json_extract(payload_json, '$.droppable') = 1
|
|
26
|
+
OR json_extract(payload_json, '$.type') = 'compaction'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
UPDATE sessions
|
|
30
|
+
SET
|
|
31
|
+
message_count = (
|
|
32
|
+
SELECT COUNT(*)
|
|
33
|
+
FROM transcript_entries e
|
|
34
|
+
WHERE e.session_id = sessions.session_id
|
|
35
|
+
AND e.entry_kind = 'message'
|
|
36
|
+
),
|
|
37
|
+
estimated_tokens = (
|
|
38
|
+
SELECT COALESCE(SUM((length(COALESCE(json_extract(e.payload_json, '$.content'), '')) + 3) / 4), 0)
|
|
39
|
+
FROM transcript_entries e
|
|
40
|
+
WHERE e.session_id = sessions.session_id
|
|
41
|
+
AND e.entry_kind = 'message'
|
|
42
|
+
)
|
|
43
|
+
WHERE session_id IN (SELECT session_id FROM xopc_runtime_transcript_cleanup_sessions);
|
|
44
|
+
|
|
45
|
+
DROP TABLE xopc_runtime_transcript_cleanup_sessions;
|
|
@@ -3,7 +3,7 @@ import type { ApplyMigrationsOptions } from './types.js';
|
|
|
3
3
|
/** Baseline schema version applied from schema.sql on first open. */
|
|
4
4
|
export declare const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
|
|
5
5
|
/** Latest schema version this release supports (increment when adding migrations). */
|
|
6
|
-
export declare const XOPC_DB_SCHEMA_VERSION =
|
|
6
|
+
export declare const XOPC_DB_SCHEMA_VERSION = 61;
|
|
7
7
|
export declare function resolveMigrationsDir(override?: string): string;
|
|
8
8
|
/**
|
|
9
9
|
* Apply sequential SQL migrations from (currentVersion + 1) through targetVersion.
|
|
@@ -12,7 +12,7 @@ const log = createLogger("Sqlite:Migrations");
|
|
|
12
12
|
/** Baseline schema version applied from schema.sql on first open. */
|
|
13
13
|
const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
|
|
14
14
|
/** Latest schema version this release supports (increment when adding migrations). */
|
|
15
|
-
const XOPC_DB_SCHEMA_VERSION =
|
|
15
|
+
const XOPC_DB_SCHEMA_VERSION = 61;
|
|
16
16
|
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
17
17
|
function resolveMigrationsDir(override) {
|
|
18
18
|
if (override) return override;
|
|
@@ -46,7 +46,7 @@ function applySingleMigration(db, migration) {
|
|
|
46
46
|
* Each step runs in its own transaction and updates schema_meta on success.
|
|
47
47
|
*/
|
|
48
48
|
function applyPendingMigrations(db, options = {}) {
|
|
49
|
-
const targetVersion = options.targetVersion ??
|
|
49
|
+
const targetVersion = options.targetVersion ?? 61;
|
|
50
50
|
let currentVersion = readSchemaVersion(db);
|
|
51
51
|
if (currentVersion > targetVersion) throw new DatabaseSchemaTooNewError(currentVersion, targetVersion);
|
|
52
52
|
if (currentVersion >= targetVersion) return currentVersion;
|
|
@@ -62,7 +62,7 @@ function applyPendingMigrations(db, options = {}) {
|
|
|
62
62
|
}
|
|
63
63
|
/** Inspect schema version without mutating the database. */
|
|
64
64
|
function inspectSchemaMigrationStatus(db, options = {}) {
|
|
65
|
-
const appVersion = options.targetVersion ??
|
|
65
|
+
const appVersion = options.targetVersion ?? 61;
|
|
66
66
|
const dbVersion = readSchemaVersion(db);
|
|
67
67
|
if (dbVersion > appVersion) return {
|
|
68
68
|
dbVersion,
|
|
@@ -19,7 +19,7 @@ const log = createLogger('Sqlite:Migrations');
|
|
|
19
19
|
export const XOPC_DB_BASELINE_SCHEMA_VERSION = 11;
|
|
20
20
|
|
|
21
21
|
/** Latest schema version this release supports (increment when adding migrations). */
|
|
22
|
-
export const XOPC_DB_SCHEMA_VERSION =
|
|
22
|
+
export const XOPC_DB_SCHEMA_VERSION = 61;
|
|
23
23
|
|
|
24
24
|
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
25
25
|
|
|
@@ -31,7 +31,7 @@ function ensureXopcDatabaseSchema(db) {
|
|
|
31
31
|
bootstrapFreshDatabase(db);
|
|
32
32
|
currentVersion = 11;
|
|
33
33
|
}
|
|
34
|
-
applyPendingMigrations(db, { targetVersion:
|
|
34
|
+
applyPendingMigrations(db, { targetVersion: 61 });
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
37
|
export { SCHEMA_META_SCHEMA_VERSION_KEY, XOPC_DB_BASELINE_SCHEMA_VERSION, XOPC_DB_SCHEMA_VERSION, ensureSchemaMetaTable, ensureXopcDatabaseSchema, readSchemaVersion, readSchemaVersionForTest, setSchemaVersion };
|
|
@@ -91,25 +91,6 @@ CREATE INDEX IF NOT EXISTS idx_entries_session_seq
|
|
|
91
91
|
CREATE INDEX IF NOT EXISTS idx_entries_kind
|
|
92
92
|
ON transcript_entries(session_id, entry_kind);
|
|
93
93
|
|
|
94
|
-
CREATE TABLE IF NOT EXISTS compaction_checkpoints (
|
|
95
|
-
checkpoint_id TEXT PRIMARY KEY,
|
|
96
|
-
session_id TEXT NOT NULL,
|
|
97
|
-
session_key TEXT NOT NULL,
|
|
98
|
-
created_at INTEGER NOT NULL,
|
|
99
|
-
message_count INTEGER NOT NULL,
|
|
100
|
-
size_bytes INTEGER NOT NULL
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
CREATE TABLE IF NOT EXISTS checkpoint_entries (
|
|
104
|
-
checkpoint_id TEXT NOT NULL,
|
|
105
|
-
seq INTEGER NOT NULL,
|
|
106
|
-
entry_kind TEXT NOT NULL,
|
|
107
|
-
role TEXT,
|
|
108
|
-
payload_json TEXT NOT NULL,
|
|
109
|
-
PRIMARY KEY (checkpoint_id, seq),
|
|
110
|
-
FOREIGN KEY (checkpoint_id) REFERENCES compaction_checkpoints(checkpoint_id) ON DELETE CASCADE
|
|
111
|
-
);
|
|
112
|
-
|
|
113
94
|
CREATE VIRTUAL TABLE IF NOT EXISTS transcript_fts USING fts5(
|
|
114
95
|
content,
|
|
115
96
|
session_key UNINDEXED,
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import type { AgentMessage } from '@earendil-works/pi-agent-core';
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
import { type TranscriptStoredRow } from '../../session/session-context-for-llm.js';
|
|
2
|
+
import type { CompactionBoundarySummary } from '../../session/types.js';
|
|
3
|
+
import { type TranscriptStoredRow, type XopcTranscriptCompactionEntry } from '../../session/session-context-for-llm.js';
|
|
5
4
|
import { type TranscriptEntryRow } from './row-mappers.js';
|
|
6
5
|
export declare function appendTranscriptEntry(sessionKey: string, row: TranscriptStoredRow, opts?: {
|
|
7
6
|
sessionId?: string;
|
|
8
7
|
tokenDelta?: number;
|
|
9
8
|
}): TranscriptEntryRow;
|
|
9
|
+
export declare function appendCompactionBoundary(sessionKey: string, row: Omit<XopcTranscriptCompactionEntry, 'baseSeq'>): TranscriptEntryRow;
|
|
10
10
|
export declare function loadTranscriptRowsForSession(sessionKey: string): TranscriptStoredRow[];
|
|
11
11
|
export declare function loadTranscriptHistoryRowsForSession(sessionKey: string): TranscriptStoredRow[];
|
|
12
12
|
export declare function loadTranscriptRows(sessionId: string): TranscriptStoredRow[];
|
|
13
13
|
export declare function loadLlmMessagesForSession(sessionKey: string): AgentMessage[];
|
|
14
|
-
export declare function replaceTranscriptRows(sessionKey: string, rows: TranscriptStoredRow[]
|
|
15
|
-
appendCompaction?: TranscriptCompactionRecord;
|
|
16
|
-
}): void;
|
|
17
|
-
export declare function loadCheckpointRows(sessionKey: string, checkpointId: string): TranscriptStoredRow[];
|
|
14
|
+
export declare function replaceTranscriptRows(sessionKey: string, rows: TranscriptStoredRow[]): void;
|
|
18
15
|
export declare function paginateTranscriptMessages(sessionKey: string, options?: {
|
|
19
16
|
offset?: number;
|
|
20
17
|
limit?: number;
|
|
@@ -29,7 +26,5 @@ export declare function paginateTranscriptMessages(sessionKey: string, options?:
|
|
|
29
26
|
startSeq: number;
|
|
30
27
|
endSeq: number;
|
|
31
28
|
};
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function getCompactionCheckpointDetail(sessionKey: string, checkpointId: string): CompactionCheckpointDetail | null;
|
|
35
|
-
export declare function restoreCompactionCheckpoint(sessionKey: string, checkpointId: string): void;
|
|
29
|
+
export declare function listCompactionBoundaries(sessionKey: string): CompactionBoundarySummary[];
|
|
30
|
+
export declare function restoreBeforeCompactionBoundary(sessionKey: string, compactionId: string): void;
|