@jini-ai/sqlite 0.3.0 → 0.5.1
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/CHANGELOG.md +23 -0
- package/README.md +27 -110
- package/dist/index.d.ts +17 -9
- package/dist/index.js +12 -9
- package/package.json +12 -7
- package/dist/backend-config.d.ts +0 -42
- package/dist/backend-config.d.ts.map +0 -1
- package/dist/backend-config.js +0 -57
- package/dist/backend-config.js.map +0 -1
- package/dist/db/agent-sessions/agent-sessions.d.ts +0 -79
- package/dist/db/agent-sessions/agent-sessions.d.ts.map +0 -1
- package/dist/db/agent-sessions/agent-sessions.js +0 -121
- package/dist/db/agent-sessions/agent-sessions.js.map +0 -1
- package/dist/db/agent-sessions/index.d.ts +0 -6
- package/dist/db/agent-sessions/index.d.ts.map +0 -1
- package/dist/db/agent-sessions/index.js +0 -6
- package/dist/db/agent-sessions/index.js.map +0 -1
- package/dist/db/capabilities/capabilities.d.ts +0 -39
- package/dist/db/capabilities/capabilities.d.ts.map +0 -1
- package/dist/db/capabilities/capabilities.js +0 -54
- package/dist/db/capabilities/capabilities.js.map +0 -1
- package/dist/db/capabilities/index.d.ts +0 -4
- package/dist/db/capabilities/index.d.ts.map +0 -1
- package/dist/db/capabilities/index.js +0 -4
- package/dist/db/capabilities/index.js.map +0 -1
- package/dist/db/chat-history/index.d.ts +0 -15
- package/dist/db/chat-history/index.d.ts.map +0 -1
- package/dist/db/chat-history/index.js +0 -15
- package/dist/db/chat-history/index.js.map +0 -1
- package/dist/db/chat-history/schema.d.ts +0 -61
- package/dist/db/chat-history/schema.d.ts.map +0 -1
- package/dist/db/chat-history/schema.js +0 -80
- package/dist/db/chat-history/schema.js.map +0 -1
- package/dist/db/chat-history/store.d.ts +0 -41
- package/dist/db/chat-history/store.d.ts.map +0 -1
- package/dist/db/chat-history/store.js +0 -254
- package/dist/db/chat-history/store.js.map +0 -1
- package/dist/db/connection/connection.d.ts +0 -18
- package/dist/db/connection/connection.d.ts.map +0 -1
- package/dist/db/connection/connection.js +0 -48
- package/dist/db/connection/connection.js.map +0 -1
- package/dist/db/connection/index.d.ts +0 -3
- package/dist/db/connection/index.d.ts.map +0 -1
- package/dist/db/connection/index.js +0 -3
- package/dist/db/connection/index.js.map +0 -1
- package/dist/db/conversations/conversations.d.ts +0 -109
- package/dist/db/conversations/conversations.d.ts.map +0 -1
- package/dist/db/conversations/conversations.js +0 -274
- package/dist/db/conversations/conversations.js.map +0 -1
- package/dist/db/conversations/index.d.ts +0 -3
- package/dist/db/conversations/index.d.ts.map +0 -1
- package/dist/db/conversations/index.js +0 -3
- package/dist/db/conversations/index.js.map +0 -1
- package/dist/db/core/index.d.ts +0 -6
- package/dist/db/core/index.d.ts.map +0 -1
- package/dist/db/core/index.js +0 -6
- package/dist/db/core/index.js.map +0 -1
- package/dist/db/core/json.d.ts +0 -13
- package/dist/db/core/json.d.ts.map +0 -1
- package/dist/db/core/json.js +0 -22
- package/dist/db/core/json.js.map +0 -1
- package/dist/db/core/rows.d.ts +0 -18
- package/dist/db/core/rows.d.ts.map +0 -1
- package/dist/db/core/rows.js +0 -17
- package/dist/db/core/rows.js.map +0 -1
- package/dist/db/core/types.d.ts +0 -14
- package/dist/db/core/types.d.ts.map +0 -1
- package/dist/db/core/types.js +0 -2
- package/dist/db/core/types.js.map +0 -1
- package/dist/db/index.d.ts +0 -24
- package/dist/db/index.d.ts.map +0 -1
- package/dist/db/index.js +0 -22
- package/dist/db/index.js.map +0 -1
- package/dist/db/messages/index.d.ts +0 -4
- package/dist/db/messages/index.d.ts.map +0 -1
- package/dist/db/messages/index.js +0 -4
- package/dist/db/messages/index.js.map +0 -1
- package/dist/db/messages/messages.d.ts +0 -129
- package/dist/db/messages/messages.d.ts.map +0 -1
- package/dist/db/messages/messages.js +0 -246
- package/dist/db/messages/messages.js.map +0 -1
- package/dist/db/projects/index.d.ts +0 -4
- package/dist/db/projects/index.d.ts.map +0 -1
- package/dist/db/projects/index.js +0 -4
- package/dist/db/projects/index.js.map +0 -1
- package/dist/db/projects/projects.d.ts +0 -122
- package/dist/db/projects/projects.d.ts.map +0 -1
- package/dist/db/projects/projects.js +0 -311
- package/dist/db/projects/projects.js.map +0 -1
- package/dist/db/schema/index.d.ts +0 -3
- package/dist/db/schema/index.d.ts.map +0 -1
- package/dist/db/schema/index.js +0 -3
- package/dist/db/schema/index.js.map +0 -1
- package/dist/db/schema/migrate.d.ts +0 -29
- package/dist/db/schema/migrate.d.ts.map +0 -1
- package/dist/db/schema/migrate.js +0 -78
- package/dist/db/schema/migrate.js.map +0 -1
- package/dist/db/tool-catalog/index.d.ts +0 -6
- package/dist/db/tool-catalog/index.d.ts.map +0 -1
- package/dist/db/tool-catalog/index.js +0 -6
- package/dist/db/tool-catalog/index.js.map +0 -1
- package/dist/db/tool-catalog/tool-catalog.d.ts +0 -70
- package/dist/db/tool-catalog/tool-catalog.d.ts.map +0 -1
- package/dist/db/tool-catalog/tool-catalog.js +0 -87
- package/dist/db/tool-catalog/tool-catalog.js.map +0 -1
- package/dist/db-inspect.d.ts +0 -62
- package/dist/db-inspect.d.ts.map +0 -1
- package/dist/db-inspect.js +0 -153
- package/dist/db-inspect.js.map +0 -1
- package/dist/event-log.d.ts +0 -33
- package/dist/event-log.d.ts.map +0 -1
- package/dist/event-log.js +0 -191
- package/dist/event-log.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## 0.5.1 — 2026-10-08
|
|
2
|
+
|
|
3
|
+
### BREAKING
|
|
4
|
+
|
|
5
|
+
- Remove 18 server-owned root names (backend configuration/types, legacy acquisition/bootstrap and project CRUD/status helpers). Import their server concern subpaths directly; sqlite no longer depends on server.
|
|
6
|
+
- Keep the immutable old surface snapshot as migration evidence; current runtime/declaration assertions explicitly check the remaining surface.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## 0.5.0 — 2026-10-02
|
|
10
|
+
|
|
11
|
+
### BREAKING
|
|
12
|
+
|
|
13
|
+
- Deprecated database compatibility facade retains its runtime exports for one release while publishing only release/runtime artifacts.
|
|
14
|
+
- Distribution includes runtime output, release documentation and required assets only. Process records and per-job neutrality checks are no longer part of the package surface.
|
|
15
|
+
|
|
16
|
+
- Align packed runtime and declaration fixtures with the injected object arguments of the relocated stores.
|
|
17
|
+
|
|
18
|
+
# Changelog
|
|
19
|
+
|
|
20
|
+
## 0.4.0 — final compatibility release
|
|
21
|
+
- Re-exported all 65 old public names, including erased types, from concern-owned packages.
|
|
22
|
+
- Removed driver autoload. Resource-opening signatures now require a borrowed connection or host opener.
|
|
23
|
+
- Replaced the obsolete j04 renamed-package manifest assertion with the final old-name shim contract.
|
package/README.md
CHANGED
|
@@ -1,110 +1,27 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`@jini-ai/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
to
|
|
28
|
-
operational risk; pass an explicit cap (larger, smaller, or `0`) to own that tradeoff yourself.
|
|
29
|
-
|
|
30
|
-
**Connection and migration** — `openDatabase(projectRoot, { dataDir })` (opens/creates
|
|
31
|
-
`<dataDir ?? projectRoot/.jini>/app.sqlite` and memoizes the handle), `closeDatabase()`, and
|
|
32
|
-
`migrate(db)`. Core types: `SqliteDb`, `DbRow`, `JsonObject`, `ChatSessionMode`.
|
|
33
|
-
|
|
34
|
-
**Backend selection** — `resolveSqliteBackendConfig(env)` → `SqliteBackendConfig`
|
|
35
|
-
(`kind: 'sqlite' | 'postgres'` plus Postgres resolution metadata a future adapter will read, with
|
|
36
|
-
secrets deliberately never read through env at this layer), and `SqliteBackendConfigError`.
|
|
37
|
-
|
|
38
|
-
**Application queries** — plain functions over a `SqliteDb`, grouped by table:
|
|
39
|
-
- projects: `listProjects`, `getProject`, `insertProject`, `updateProject`, `deleteProject`, and the
|
|
40
|
-
run-status rollups (`listLatestRunStatuses`, `listLatestProjectRunStatuses`,
|
|
41
|
-
`listLatestConversationRunStatuses`, `listFirstConversationRunStatuses`,
|
|
42
|
-
`listProjectsAwaitingInput`, `listConversationsAwaitingInput`)
|
|
43
|
-
- conversations: `listConversations`, `getConversation`, `insertConversation`, `updateConversation`,
|
|
44
|
-
`deleteConversation`, `normalizeConversationSessionMode`
|
|
45
|
-
- messages: `listMessages`, `upsertMessage`, `deleteMessage`, `appendMessageStatusEvent`,
|
|
46
|
-
`appendMessageAgentEvent`, `getMessageTelemetryFinalizationState`, and
|
|
47
|
-
`MessageConversationMismatchError`
|
|
48
|
-
- agent sessions: `getAgentSession`, `getAgentSessionRecord`, `upsertAgentSession`,
|
|
49
|
-
`clearAgentSession`, `updateAgentSessionStableHash`, `latestCompletedAssistantMessageId`
|
|
50
|
-
|
|
51
|
-
**Tool catalog** — `ensureToolCatalogTables`, `reseedToolCatalog`, `getToolCatalogEntry`,
|
|
52
|
-
`searchToolCatalog` (FTS-backed), with `ToolCatalogEntry` / `ToolCatalogSearchHit`.
|
|
53
|
-
|
|
54
|
-
**Inspection** — `inspectSqliteDatabase({ db, file })` → `DaemonDbStatusReport` (table/row
|
|
55
|
-
inventory) and `verifySqliteIntegrity(opts)` → `DbIntegrityReport` (`PRAGMA integrity_check` plus
|
|
56
|
-
foreign-key violations).
|
|
57
|
-
|
|
58
|
-
**Row utilities** — `row`, `rows`, `parseJsonOrUndef`.
|
|
59
|
-
|
|
60
|
-
## Usage
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import {
|
|
64
|
-
createSqliteEventLog,
|
|
65
|
-
openDatabase,
|
|
66
|
-
migrate,
|
|
67
|
-
listProjects,
|
|
68
|
-
searchToolCatalog,
|
|
69
|
-
verifySqliteIntegrity,
|
|
70
|
-
} from '@jini-ai/sqlite';
|
|
71
|
-
import type { EventLog } from '@jini-ai/protocol';
|
|
72
|
-
|
|
73
|
-
// The durable EventLog port — drop-in for @jini-ai/daemon's in-memory log.
|
|
74
|
-
const eventLog: EventLog = createSqliteEventLog('/var/lib/example/events.sqlite', {
|
|
75
|
-
maxEntriesPerRun: 5000,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await eventLog.append({ runId: 'run_123', event: 'stdout', data: { text: 'hello' } });
|
|
79
|
-
const replay = await eventLog.replay('run_123', null);
|
|
80
|
-
if (replay.kind === 'replay-gap') {
|
|
81
|
-
// The requested cursor was already evicted — resync rather than trusting a hole.
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// The application database.
|
|
85
|
-
const db = openDatabase('/srv/workspace');
|
|
86
|
-
migrate(db);
|
|
87
|
-
|
|
88
|
-
const projects = listProjects(db);
|
|
89
|
-
const hits = searchToolCatalog(db, 'deploy', 5);
|
|
90
|
-
const integrity = verifySqliteIntegrity({ db });
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## What's swappable
|
|
94
|
-
|
|
95
|
-
This package *is* an adapter — it implements `@jini-ai/protocol`'s `EventLog` so a host can bind
|
|
96
|
-
either it or an in-memory log behind the same token. Going the other way, very little inside is
|
|
97
|
-
injectable: `createSqliteEventLog` takes only a path plus the retention cap, and the query helpers
|
|
98
|
-
take an already-open `SqliteDb` handle (so you control connection lifetime, and can pass a
|
|
99
|
-
`:memory:` database in tests) but the SQL and schema themselves are fixed.
|
|
100
|
-
`resolveSqliteBackendConfig` reads a caller-supplied `env` record rather than `process.env` directly.
|
|
101
|
-
|
|
102
|
-
## Runtime
|
|
103
|
-
|
|
104
|
-
`jini.runtime: "node"` — `better-sqlite3` plus `node:fs`/`node:path`.
|
|
105
|
-
ESM only — ships `"type": "module"` with no CommonJS `require` build.
|
|
106
|
-
|
|
107
|
-
## Provenance
|
|
108
|
-
|
|
109
|
-
See [source-map.md](./source-map.md) for per-file provenance and scope decisions. Apache-2.0,
|
|
110
|
-
inherited from Open Design — see the repo `NOTICE`.
|
|
1
|
+
# @jini-ai/sqlite — deprecated compatibility release
|
|
2
|
+
|
|
3
|
+
This package and its published exports remain available for compatibility. The package owner
|
|
4
|
+
applies npm registry deprecation at publish time; the manifest notice does not deprecate existing
|
|
5
|
+
registry versions by itself.
|
|
6
|
+
|
|
7
|
+
Version 0.5.0 is a deprecated compatibility surface for chat, daemon, registry and driver concerns,
|
|
8
|
+
including their erased types. Server-owned composition is no longer forwarded by this package. Prefer `@jini-ai/chat/store/{sqlite,legacy/sqlite}`,
|
|
9
|
+
`@jini-ai/daemon/store/{event-log/sqlite,agent-sessions/sqlite}`, `@jini-ai/registry/tool-catalog/sqlite`,
|
|
10
|
+
`@jini-ai/db/{core,sqlite}`, and `@jini-ai/server/{storage,storage/legacy/sqlite,store/projects/sqlite}`.
|
|
11
|
+
|
|
12
|
+
Pre-1.0 breaking acquisition change: Jini never autoloads a database driver. Use
|
|
13
|
+
`createSqliteEventLog({ db }, options)` for a borrowed connection. Canonical owned acquisition is
|
|
14
|
+
`openSqliteEventLog({ file, open }, options)` from the daemon concern entry. Server
|
|
15
|
+
`openDatabase({ projectRoot, open }, { dataDir? })` likewise requires the host opener. Hosts may use `(file, options) => new Database(file, options)`.
|
|
16
|
+
Borrowed event-log close never closes the host handle. Owned close is idempotent; failed setup
|
|
17
|
+
closes the newly acquired handle. The remaining event/CRUD/cursor/schema semantics stay unchanged.
|
|
18
|
+
|
|
19
|
+
This explicit re-export shim depends on concern owners. None depends on it. It eagerly loads
|
|
20
|
+
several adapters and requires the db/Kysely SQL peers; lean consumers should use the concern subpaths.
|
|
21
|
+
No driver is bundled, a hard dependency, dynamically imported, or obtained from a global registry.
|
|
22
|
+
The unpublished sqlite-chat implementation directory is drained; no registry release is changed here.
|
|
23
|
+
|
|
24
|
+
Backend config and types now come directly from `@jini-ai/server/storage`;
|
|
25
|
+
`openDatabase`, `closeDatabase` and `migrate` from `@jini-ai/server/storage/legacy/sqlite`;
|
|
26
|
+
project CRUD/status helpers from `@jini-ai/server/store/projects/sqlite`. This removes
|
|
27
|
+
the sqlite-to-server dependency rather than adding a wrapper or duplicated implementation.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* See
|
|
2
|
+
* @deprecated Compatibility for the remaining 0.3.x storage names; prefer concern subpaths.
|
|
3
|
+
* Durable event-log adapters live in daemon, inspection/driver primitives in db.
|
|
4
|
+
* Backend selection, acquisition and project composition belong to the server shell;
|
|
5
|
+
* importing this facade must not pull that higher-level assembly into storage consumers.
|
|
6
|
+
* Inject host handles/openers. See docs/spec/api.spec.md for scope and migration targets.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
8
|
+
export { createSqliteEventLog, DEFAULT_MAX_ENTRIES_PER_RUN } from '@jini-ai/daemon/store/event-log/sqlite';
|
|
9
|
+
export type { SqliteEventLog, SqliteEventLogOptions } from '@jini-ai/daemon/store/event-log/sqlite';
|
|
10
|
+
export { inspectSqliteDatabase, verifySqliteIntegrity } from '@jini-ai/db/sqlite';
|
|
11
|
+
export type { DaemonDbStatusReport, DaemonDbTableInfo, DbIntegrityIssue, DbIntegrityIssueKind, DbIntegrityReport, SqliteDb, VerifyDbOptions } from '@jini-ai/db/sqlite';
|
|
12
|
+
export { parseJsonOrUndef, row, rows } from '@jini-ai/db/core';
|
|
13
|
+
export type { DbRow, JsonObject } from '@jini-ai/db/core';
|
|
14
|
+
export type { ChatSessionMode } from '@jini-ai/chat/store/legacy';
|
|
15
|
+
export { CHAT_HISTORY_DDL, createChatHistoryMaintenance, createChatHistoryStore, ensureChatHistoryTables } from '@jini-ai/chat/store/sqlite';
|
|
16
|
+
export type { ToolCatalogEntry, ToolCatalogSearchHit } from '@jini-ai/registry/tool-catalog';
|
|
17
|
+
export { ensureToolCatalogTables, getToolCatalogEntry, reseedToolCatalog, searchToolCatalog } from '@jini-ai/registry/tool-catalog/sqlite';
|
|
18
|
+
export { appendMessageAgentEvent, appendMessageStatusEvent, deleteConversation, deleteMessage, getConversation, getMessageTelemetryFinalizationState, insertConversation, listConversations, listMessages, normalizeConversationSessionMode, updateConversation, upsertMessage } from '@jini-ai/chat/store/legacy/sqlite';
|
|
19
|
+
export { clearAgentSession, getAgentSession, getAgentSessionRecord, latestCompletedAssistantMessageId, updateAgentSessionStableHash, upsertAgentSession } from '@jini-ai/daemon/store/agent-sessions/sqlite';
|
|
12
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* See
|
|
2
|
+
* @deprecated Compatibility for the remaining 0.3.x storage names; prefer concern subpaths.
|
|
3
|
+
* Durable event-log adapters live in daemon, inspection/driver primitives in db.
|
|
4
|
+
* Backend selection, acquisition and project composition belong to the server shell;
|
|
5
|
+
* importing this facade must not pull that higher-level assembly into storage consumers.
|
|
6
|
+
* Inject host handles/openers. See docs/spec/api.spec.md for scope and migration targets.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
8
|
+
export { createSqliteEventLog, DEFAULT_MAX_ENTRIES_PER_RUN } from '@jini-ai/daemon/store/event-log/sqlite';
|
|
9
|
+
export { inspectSqliteDatabase, verifySqliteIntegrity } from '@jini-ai/db/sqlite';
|
|
10
|
+
export { parseJsonOrUndef, row, rows } from '@jini-ai/db/core';
|
|
11
|
+
export { CHAT_HISTORY_DDL, createChatHistoryMaintenance, createChatHistoryStore, ensureChatHistoryTables } from '@jini-ai/chat/store/sqlite';
|
|
12
|
+
export { ensureToolCatalogTables, getToolCatalogEntry, reseedToolCatalog, searchToolCatalog } from '@jini-ai/registry/tool-catalog/sqlite';
|
|
13
|
+
export { appendMessageAgentEvent, appendMessageStatusEvent, deleteConversation, deleteMessage, getConversation, getMessageTelemetryFinalizationState, insertConversation, listConversations, listMessages, normalizeConversationSessionMode, updateConversation, upsertMessage } from '@jini-ai/chat/store/legacy/sqlite';
|
|
14
|
+
export { clearAgentSession, getAgentSession, getAgentSessionRecord, latestCompletedAssistantMessageId, updateAgentSessionStableHash, upsertAgentSession } from '@jini-ai/daemon/store/agent-sessions/sqlite';
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/sqlite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Deprecated compatibility exports for chat, daemon, registry and database concerns; server composition is imported directly from server.",
|
|
5
|
+
"deprecated": "Compatibility shim: use @jini-ai/chat/store, @jini-ai/daemon/store, @jini-ai/registry/tool-catalog/sqlite and @jini-ai/db directly. See README.md for exact subpaths.",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
@@ -26,23 +27,27 @@
|
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"LICENSE",
|
|
29
33
|
"!dist/**/*.test.js",
|
|
30
34
|
"!dist/**/*.test.d.ts",
|
|
31
35
|
"!dist/**/*.test.js.map",
|
|
32
36
|
"!dist/**/*.test.d.ts.map",
|
|
33
|
-
"!dist/**/__tests__/**"
|
|
37
|
+
"!dist/**/__tests__/**",
|
|
38
|
+
"!dist/**/*.map"
|
|
34
39
|
],
|
|
35
40
|
"publishConfig": {
|
|
36
41
|
"access": "public",
|
|
37
42
|
"registry": "https://registry.npmjs.org"
|
|
38
43
|
},
|
|
39
44
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"@jini-ai/
|
|
42
|
-
"@jini-ai/
|
|
45
|
+
"@jini-ai/chat": "^0.5.5",
|
|
46
|
+
"@jini-ai/db": "^0.3.1",
|
|
47
|
+
"@jini-ai/registry": "^0.5.2",
|
|
48
|
+
"@jini-ai/daemon": "^0.5.4"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"@types/better-sqlite3": "^7.6.11",
|
|
46
51
|
"@vitest/coverage-v8": "^2.1.9"
|
|
47
52
|
},
|
|
48
53
|
"scripts": {
|
package/dist/backend-config.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module backend-config
|
|
3
|
-
*
|
|
4
|
-
* Resolves which SQL backend a host daemon should use from environment
|
|
5
|
-
* variables. v1 ships local SQLite via `better-sqlite3` (see `./event-log.js`);
|
|
6
|
-
* a `postgres` selection is recorded so a future adapter can read it, but
|
|
7
|
-
* `resolveSqliteBackendConfig` never opens a connection itself — it only
|
|
8
|
-
* pins the parameter surface (host/port/database/user/sslMode) so a
|
|
9
|
-
* follow-up package can land the adapter without re-litigating the env-var
|
|
10
|
-
* contract.
|
|
11
|
-
*/
|
|
12
|
-
export type SqliteBackendKind = 'sqlite' | 'postgres';
|
|
13
|
-
export interface SqliteBackendConfig {
|
|
14
|
-
kind: SqliteBackendKind;
|
|
15
|
-
/** Resolution metadata a future Postgres adapter will read. */
|
|
16
|
-
postgres?: {
|
|
17
|
-
host: string;
|
|
18
|
-
port: number;
|
|
19
|
-
database: string;
|
|
20
|
-
user: string;
|
|
21
|
-
/**
|
|
22
|
-
* Password / connection string are looked up at runtime from the
|
|
23
|
-
* caller's own secret manager; this layer never reads them through env.
|
|
24
|
-
*/
|
|
25
|
-
sslMode?: 'disable' | 'require' | 'verify-full';
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export declare class SqliteBackendConfigError extends Error {
|
|
29
|
-
constructor(message: string);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Reads `JINI_SQLITE_BACKEND` (`'sqlite'` default, or `'postgres'`) and, for
|
|
33
|
-
* `postgres`, `JINI_PG_HOST`/`JINI_PG_PORT`/`JINI_PG_DATABASE`/`JINI_PG_USER`/
|
|
34
|
-
* `JINI_PG_SSL_MODE` from the given env map (defaults to `process.env`).
|
|
35
|
-
*
|
|
36
|
-
* @param env - Environment map to read from. Defaults to `process.env`.
|
|
37
|
-
* @returns The resolved backend config.
|
|
38
|
-
* @throws {SqliteBackendConfigError} When `kind` is unrecognized, or `postgres`
|
|
39
|
-
* is selected without the required host/database/user.
|
|
40
|
-
*/
|
|
41
|
-
export declare function resolveSqliteBackendConfig(env?: Record<string, string | undefined>): SqliteBackendConfig;
|
|
42
|
-
//# sourceMappingURL=backend-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backend-config.d.ts","sourceRoot":"","sources":["../src/backend-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,iBAAiB,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb;;;WAGG;QACH,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;KACjD,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,mBAAmB,CA+BxG"}
|
package/dist/backend-config.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module backend-config
|
|
3
|
-
*
|
|
4
|
-
* Resolves which SQL backend a host daemon should use from environment
|
|
5
|
-
* variables. v1 ships local SQLite via `better-sqlite3` (see `./event-log.js`);
|
|
6
|
-
* a `postgres` selection is recorded so a future adapter can read it, but
|
|
7
|
-
* `resolveSqliteBackendConfig` never opens a connection itself — it only
|
|
8
|
-
* pins the parameter surface (host/port/database/user/sslMode) so a
|
|
9
|
-
* follow-up package can land the adapter without re-litigating the env-var
|
|
10
|
-
* contract.
|
|
11
|
-
*/
|
|
12
|
-
export class SqliteBackendConfigError extends Error {
|
|
13
|
-
constructor(message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = 'SqliteBackendConfigError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Reads `JINI_SQLITE_BACKEND` (`'sqlite'` default, or `'postgres'`) and, for
|
|
20
|
-
* `postgres`, `JINI_PG_HOST`/`JINI_PG_PORT`/`JINI_PG_DATABASE`/`JINI_PG_USER`/
|
|
21
|
-
* `JINI_PG_SSL_MODE` from the given env map (defaults to `process.env`).
|
|
22
|
-
*
|
|
23
|
-
* @param env - Environment map to read from. Defaults to `process.env`.
|
|
24
|
-
* @returns The resolved backend config.
|
|
25
|
-
* @throws {SqliteBackendConfigError} When `kind` is unrecognized, or `postgres`
|
|
26
|
-
* is selected without the required host/database/user.
|
|
27
|
-
*/
|
|
28
|
-
export function resolveSqliteBackendConfig(env) {
|
|
29
|
-
const e = env ?? process.env;
|
|
30
|
-
const kind = (e.JINI_SQLITE_BACKEND ?? 'sqlite').trim().toLowerCase();
|
|
31
|
-
if (kind === 'postgres') {
|
|
32
|
-
const host = e.JINI_PG_HOST ?? '';
|
|
33
|
-
const portStr = e.JINI_PG_PORT ?? '5432';
|
|
34
|
-
const database = e.JINI_PG_DATABASE ?? '';
|
|
35
|
-
const user = e.JINI_PG_USER ?? '';
|
|
36
|
-
const sslMode = e.JINI_PG_SSL_MODE === 'disable' || e.JINI_PG_SSL_MODE === 'verify-full' ? e.JINI_PG_SSL_MODE : 'require';
|
|
37
|
-
if (!host || !database || !user) {
|
|
38
|
-
throw new SqliteBackendConfigError('JINI_SQLITE_BACKEND=postgres requires JINI_PG_HOST, JINI_PG_DATABASE, JINI_PG_USER. ' +
|
|
39
|
-
'JINI_PG_PORT defaults to 5432; JINI_PG_SSL_MODE defaults to "require".');
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
kind: 'postgres',
|
|
43
|
-
postgres: {
|
|
44
|
-
host,
|
|
45
|
-
port: Number.parseInt(portStr, 10) || 5432,
|
|
46
|
-
database,
|
|
47
|
-
user,
|
|
48
|
-
sslMode,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (kind !== 'sqlite' && kind !== '') {
|
|
53
|
-
throw new SqliteBackendConfigError(`unknown JINI_SQLITE_BACKEND value '${kind}'. Accepted: 'sqlite' (default), 'postgres'.`);
|
|
54
|
-
}
|
|
55
|
-
return { kind: 'sqlite' };
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=backend-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backend-config.js","sourceRoot":"","sources":["../src/backend-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAwC;IACjF,MAAM,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAC7B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,mBAAmB,IAAI,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtE,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC;QACzC,MAAM,QAAQ,GAAG,CAAC,CAAC,gBAAgB,IAAI,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC;QAClC,MAAM,OAAO,GACX,CAAC,CAAC,gBAAgB,KAAK,SAAS,IAAI,CAAC,CAAC,gBAAgB,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5G,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,wBAAwB,CAChC,sFAAsF;gBACpF,wEAAwE,CAC3E,CAAC;QACJ,CAAC;QACD,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI;gBACJ,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,IAAI;gBAC1C,QAAQ;gBACR,IAAI;gBACJ,OAAO;aACR;SACF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,wBAAwB,CAAC,sCAAsC,IAAI,8CAA8C,CAAC,CAAC;IAC/H,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module db/agent-sessions
|
|
3
|
-
* Owns the per-(conversation, agent) upstream CLI session cache used by the resume identity guard.
|
|
4
|
-
* Imports only the core/ kernel (types). No other db concern is imported.
|
|
5
|
-
*
|
|
6
|
-
* NOTE (neutral port): no OD-specific columns or logic — every field (session id, prompt hash,
|
|
7
|
-
* model, cwd, last message id) is generic resume-identity bookkeeping already matched 1:1 by the
|
|
8
|
-
* already-ported `schema/migrate.ts` `agent_sessions` table. Ported verbatim aside from
|
|
9
|
-
* de-branding the module doc comment.
|
|
10
|
-
*/
|
|
11
|
-
import type { SqliteDb } from '../core/index.js';
|
|
12
|
-
/**
|
|
13
|
-
* Returns the stored upstream CLI session id for a (conversation, agent) pair, or null if none exists.
|
|
14
|
-
* Used as a quick existence check before the full record is needed.
|
|
15
|
-
* @param db - Open SQLite database handle.
|
|
16
|
-
* @param conversationId - Conversation scope for the session.
|
|
17
|
-
* @param agentId - Agent whose session to look up.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getAgentSession(db: SqliteDb, conversationId: string, agentId: string): string | null;
|
|
20
|
-
/**
|
|
21
|
-
* Creates or replaces the agent session record for a (conversation, agent) pair.
|
|
22
|
-
* All nullable fields are stored as SQL NULL when omitted, preserving the resume guard's
|
|
23
|
-
* ability to detect staleness via stablePromptHash and lastMessageId.
|
|
24
|
-
* @param db - Open SQLite database handle.
|
|
25
|
-
* @param input - Session fields to persist; conversationId, agentId, and sessionId are required.
|
|
26
|
-
*/
|
|
27
|
-
export declare function upsertAgentSession(db: SqliteDb, input: {
|
|
28
|
-
conversationId: string;
|
|
29
|
-
agentId: string;
|
|
30
|
-
sessionId: string;
|
|
31
|
-
stablePromptHash?: string | null;
|
|
32
|
-
model?: string | null;
|
|
33
|
-
cwd?: string | null;
|
|
34
|
-
lastMessageId?: string | null;
|
|
35
|
-
}): void;
|
|
36
|
-
/**
|
|
37
|
-
* Fetches the full agent session record for a (conversation, agent) pair, or null if absent.
|
|
38
|
-
* Callers that need only the session id should use {@link getAgentSession} instead.
|
|
39
|
-
* @param db - Open SQLite database handle.
|
|
40
|
-
* @param conversationId - Conversation scope for the session.
|
|
41
|
-
* @param agentId - Agent whose session to retrieve.
|
|
42
|
-
*/
|
|
43
|
-
export declare function getAgentSessionRecord(db: SqliteDb, conversationId: string, agentId: string): {
|
|
44
|
-
sessionId: string;
|
|
45
|
-
stablePromptHash: string | null;
|
|
46
|
-
model: string | null;
|
|
47
|
-
cwd: string | null;
|
|
48
|
-
lastMessageId: string | null;
|
|
49
|
-
} | null;
|
|
50
|
-
/**
|
|
51
|
-
* Returns the conversation cursor used by the resume identity guard: the id of the most recent
|
|
52
|
-
* completed (succeeded) assistant message, excluding the current in-flight placeholder.
|
|
53
|
-
* See the inline comment above for the full invariant and the resumableMessageId exception.
|
|
54
|
-
* @param db - Open SQLite database handle.
|
|
55
|
-
* @param conversationId - Conversation to inspect.
|
|
56
|
-
* @param excludeMessageId - The in-flight run's own placeholder message id to skip.
|
|
57
|
-
* @param resumableMessageId - Optional id of a transiently-failed session's last message, admitted through the succeeded-only filter.
|
|
58
|
-
* @returns The matching message id, or null if no prior completed turn exists.
|
|
59
|
-
*/
|
|
60
|
-
export declare function latestCompletedAssistantMessageId(db: SqliteDb, conversationId: string, excludeMessageId: string, resumableMessageId?: string | null): string | null;
|
|
61
|
-
/**
|
|
62
|
-
* Updates the stable prompt hash for an existing agent session without touching other fields.
|
|
63
|
-
* Called after the resume path confirms the prompt context is still stable, recording the
|
|
64
|
-
* current hash so future identity checks can compare against it.
|
|
65
|
-
* @param db - Open SQLite database handle.
|
|
66
|
-
* @param conversationId - Conversation scope for the session.
|
|
67
|
-
* @param agentId - Agent whose session to update.
|
|
68
|
-
* @param stablePromptHash - The new prompt hash to record.
|
|
69
|
-
*/
|
|
70
|
-
export declare function updateAgentSessionStableHash(db: SqliteDb, conversationId: string, agentId: string, stablePromptHash: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Deletes the agent session record for a (conversation, agent) pair.
|
|
73
|
-
* Forces the next run to start a fresh upstream CLI session rather than attempting resume.
|
|
74
|
-
* @param db - Open SQLite database handle.
|
|
75
|
-
* @param conversationId - Conversation scope for the session.
|
|
76
|
-
* @param agentId - Agent whose session to clear.
|
|
77
|
-
*/
|
|
78
|
-
export declare function clearAgentSession(db: SqliteDb, conversationId: string, agentId: string): void;
|
|
79
|
-
//# sourceMappingURL=agent-sessions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-sessions.d.ts","sourceRoot":"","sources":["../../../src/db/agent-sessions/agent-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAS,MAAM,kBAAkB,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAQf;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,QAAQ,EACZ,KAAK,EAAE;IACL,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,GACA,IAAI,CAsBN;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,GAAG,IAAI,CAgBP;AAyBD;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,GAAE,MAAM,GAAG,IAAW,GACvC,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GACvB,IAAI,CAKN;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd,IAAI,CAIN"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the stored upstream CLI session id for a (conversation, agent) pair, or null if none exists.
|
|
3
|
-
* Used as a quick existence check before the full record is needed.
|
|
4
|
-
* @param db - Open SQLite database handle.
|
|
5
|
-
* @param conversationId - Conversation scope for the session.
|
|
6
|
-
* @param agentId - Agent whose session to look up.
|
|
7
|
-
*/
|
|
8
|
-
export function getAgentSession(db, conversationId, agentId) {
|
|
9
|
-
const row = db
|
|
10
|
-
.prepare(`SELECT session_id FROM agent_sessions
|
|
11
|
-
WHERE conversation_id = ? AND agent_id = ?`)
|
|
12
|
-
.get(conversationId, agentId);
|
|
13
|
-
return row && typeof row.session_id === 'string' ? row.session_id : null;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Creates or replaces the agent session record for a (conversation, agent) pair.
|
|
17
|
-
* All nullable fields are stored as SQL NULL when omitted, preserving the resume guard's
|
|
18
|
-
* ability to detect staleness via stablePromptHash and lastMessageId.
|
|
19
|
-
* @param db - Open SQLite database handle.
|
|
20
|
-
* @param input - Session fields to persist; conversationId, agentId, and sessionId are required.
|
|
21
|
-
*/
|
|
22
|
-
export function upsertAgentSession(db, input) {
|
|
23
|
-
db.prepare(`INSERT INTO agent_sessions
|
|
24
|
-
(conversation_id, agent_id, session_id, stable_prompt_hash, model, cwd, last_message_id, updated_at)
|
|
25
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
26
|
-
ON CONFLICT(conversation_id, agent_id)
|
|
27
|
-
DO UPDATE SET session_id = excluded.session_id,
|
|
28
|
-
stable_prompt_hash = excluded.stable_prompt_hash,
|
|
29
|
-
model = excluded.model,
|
|
30
|
-
cwd = excluded.cwd,
|
|
31
|
-
last_message_id = excluded.last_message_id,
|
|
32
|
-
updated_at = excluded.updated_at`).run(input.conversationId, input.agentId, input.sessionId, input.stablePromptHash ?? null, input.model ?? null, input.cwd ?? null, input.lastMessageId ?? null, Date.now());
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Fetches the full agent session record for a (conversation, agent) pair, or null if absent.
|
|
36
|
-
* Callers that need only the session id should use {@link getAgentSession} instead.
|
|
37
|
-
* @param db - Open SQLite database handle.
|
|
38
|
-
* @param conversationId - Conversation scope for the session.
|
|
39
|
-
* @param agentId - Agent whose session to retrieve.
|
|
40
|
-
*/
|
|
41
|
-
export function getAgentSessionRecord(db, conversationId, agentId) {
|
|
42
|
-
const row = db
|
|
43
|
-
.prepare(`SELECT session_id, stable_prompt_hash, model, cwd, last_message_id FROM agent_sessions
|
|
44
|
-
WHERE conversation_id = ? AND agent_id = ?`)
|
|
45
|
-
.get(conversationId, agentId);
|
|
46
|
-
if (!row || typeof row.session_id !== 'string')
|
|
47
|
-
return null;
|
|
48
|
-
return {
|
|
49
|
-
sessionId: row.session_id,
|
|
50
|
-
stablePromptHash: typeof row.stable_prompt_hash === 'string' ? row.stable_prompt_hash : null,
|
|
51
|
-
model: typeof row.model === 'string' ? row.model : null,
|
|
52
|
-
cwd: typeof row.cwd === 'string' ? row.cwd : null,
|
|
53
|
-
lastMessageId: typeof row.last_message_id === 'string' ? row.last_message_id : null,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
// Conversation cursor for the resume identity guard: the id of the latest
|
|
57
|
-
// COMPLETED assistant message in the conversation, EXCLUDING the current run's
|
|
58
|
-
// in-flight placeholder (`excludeMessageId`). At resolve time the session is in
|
|
59
|
-
// sync iff this equals the assistant message the session last produced —
|
|
60
|
-
// otherwise another agent completed a turn in between, or the session's own last
|
|
61
|
-
// message was edited/removed, and the session is behind. Returns null when there
|
|
62
|
-
// is no prior completed assistant turn.
|
|
63
|
-
//
|
|
64
|
-
// "Completed" means run_status = 'succeeded' — a run stamps its assistant
|
|
65
|
-
// message with the terminal status on finish, so an intervening agent run that
|
|
66
|
-
// FAILED or was CANCELED leaves a placeholder that produced no completed turn;
|
|
67
|
-
// counting it as advancement would force a needless cold reseed (silently
|
|
68
|
-
// disabling the resume perf path) even though the stored session is still the
|
|
69
|
-
// latest completed turn. In-flight placeholders have a null run_status and are
|
|
70
|
-
// likewise excluded.
|
|
71
|
-
//
|
|
72
|
-
// `resumableMessageId` is the one allowed exception: a resume-on-failure path
|
|
73
|
-
// may persist a session whose own last assistant turn FAILED transiently (the
|
|
74
|
-
// CLI session already committed a tool/artifact block and is resumable). That
|
|
75
|
-
// stored id is admitted through the filter so the session it owns still matches
|
|
76
|
-
// its cursor — while a DIFFERENT later failed/canceled turn (a different id)
|
|
77
|
-
// stays excluded, so genuine advancement by a later succeeded turn is still
|
|
78
|
-
// detected.
|
|
79
|
-
/**
|
|
80
|
-
* Returns the conversation cursor used by the resume identity guard: the id of the most recent
|
|
81
|
-
* completed (succeeded) assistant message, excluding the current in-flight placeholder.
|
|
82
|
-
* See the inline comment above for the full invariant and the resumableMessageId exception.
|
|
83
|
-
* @param db - Open SQLite database handle.
|
|
84
|
-
* @param conversationId - Conversation to inspect.
|
|
85
|
-
* @param excludeMessageId - The in-flight run's own placeholder message id to skip.
|
|
86
|
-
* @param resumableMessageId - Optional id of a transiently-failed session's last message, admitted through the succeeded-only filter.
|
|
87
|
-
* @returns The matching message id, or null if no prior completed turn exists.
|
|
88
|
-
*/
|
|
89
|
-
export function latestCompletedAssistantMessageId(db, conversationId, excludeMessageId, resumableMessageId = null) {
|
|
90
|
-
const row = db
|
|
91
|
-
.prepare(`SELECT id FROM messages
|
|
92
|
-
WHERE conversation_id = ? AND role = 'assistant' AND id != ?
|
|
93
|
-
AND (run_status = 'succeeded' OR id = ?)
|
|
94
|
-
ORDER BY position DESC LIMIT 1`)
|
|
95
|
-
.get(conversationId, excludeMessageId, resumableMessageId);
|
|
96
|
-
return row && typeof row.id === 'string' ? row.id : null;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Updates the stable prompt hash for an existing agent session without touching other fields.
|
|
100
|
-
* Called after the resume path confirms the prompt context is still stable, recording the
|
|
101
|
-
* current hash so future identity checks can compare against it.
|
|
102
|
-
* @param db - Open SQLite database handle.
|
|
103
|
-
* @param conversationId - Conversation scope for the session.
|
|
104
|
-
* @param agentId - Agent whose session to update.
|
|
105
|
-
* @param stablePromptHash - The new prompt hash to record.
|
|
106
|
-
*/
|
|
107
|
-
export function updateAgentSessionStableHash(db, conversationId, agentId, stablePromptHash) {
|
|
108
|
-
db.prepare(`UPDATE agent_sessions SET stable_prompt_hash = ?, updated_at = ?
|
|
109
|
-
WHERE conversation_id = ? AND agent_id = ?`).run(stablePromptHash, Date.now(), conversationId, agentId);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Deletes the agent session record for a (conversation, agent) pair.
|
|
113
|
-
* Forces the next run to start a fresh upstream CLI session rather than attempting resume.
|
|
114
|
-
* @param db - Open SQLite database handle.
|
|
115
|
-
* @param conversationId - Conversation scope for the session.
|
|
116
|
-
* @param agentId - Agent whose session to clear.
|
|
117
|
-
*/
|
|
118
|
-
export function clearAgentSession(db, conversationId, agentId) {
|
|
119
|
-
db.prepare(`DELETE FROM agent_sessions WHERE conversation_id = ? AND agent_id = ?`).run(conversationId, agentId);
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=agent-sessions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-sessions.js","sourceRoot":"","sources":["../../../src/db/agent-sessions/agent-sessions.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/agent-sessions/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/agent-sessions/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
|