@jini-ai/sqlite 0.3.0 → 0.5.0
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 +23 -110
- package/dist/index.d.ts +17 -9
- package/dist/index.js +12 -9
- package/package.json +11 -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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/db/core/types.ts"],"names":[],"mappings":""}
|
package/dist/db/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @jini-ai/sqlite/db
|
|
3
|
-
* Neutral SQLite persistence for the daemon: connection lifecycle + schema migration + per-table
|
|
4
|
-
* CRUD, ported from the upstream daemon's decomposed `db/` capability-barrel. Only the generic engine
|
|
5
|
-
* tables (projects, conversations, messages, agent_sessions) are ported; OD-product tables
|
|
6
|
-
* (preview_comments, tabs, deployments, routines, templates) are intentionally excluded.
|
|
7
|
-
*/
|
|
8
|
-
export { openDatabase, closeDatabase } from './connection/index.js';
|
|
9
|
-
export { listConversations, getConversation, normalizeConversationSessionMode, insertConversation, updateConversation, deleteConversation, } from './conversations/index.js';
|
|
10
|
-
export { listMessages, upsertMessage, getMessageTelemetryFinalizationState, appendMessageStatusEvent, appendMessageAgentEvent, deleteMessage, } from './messages/index.js';
|
|
11
|
-
export { listProjects, listLatestProjectRunStatuses, listLatestConversationRunStatuses, listFirstConversationRunStatuses, listLatestRunStatuses, listProjectsAwaitingInput, listConversationsAwaitingInput, getProject, insertProject, updateProject, deleteProject, } from './projects/index.js';
|
|
12
|
-
export { getAgentSession, upsertAgentSession, getAgentSessionRecord, latestCompletedAssistantMessageId, updateAgentSessionStableHash, clearAgentSession, } from './agent-sessions/index.js';
|
|
13
|
-
export type { SqliteDb, DbRow, JsonObject, ChatSessionMode } from './core/index.js';
|
|
14
|
-
export { parseJsonOrUndef, row, rows } from './core/index.js';
|
|
15
|
-
export { migrate } from './schema/index.js';
|
|
16
|
-
export type { ToolCatalogEntry, ToolCatalogSearchHit } from './tool-catalog/index.js';
|
|
17
|
-
export { ensureToolCatalogTables, reseedToolCatalog, getToolCatalogEntry, searchToolCatalog } from './tool-catalog/index.js';
|
|
18
|
-
/**
|
|
19
|
-
* Owner-scoped chat history. Not to be confused with `./conversations/index.js` above: that one
|
|
20
|
-
* is `project_id`-scoped with no owner predicate (single-user local trust model), this one binds
|
|
21
|
-
* an owner into the store so no query can read across tenants. Pick by trust model.
|
|
22
|
-
*/
|
|
23
|
-
export { CHAT_HISTORY_DDL, ensureChatHistoryTables, createChatHistoryStore, createChatHistoryMaintenance } from './chat-history/index.js';
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/db/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceR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jini-ai/sqlite/db
|
|
3
|
-
* Neutral SQLite persistence for the daemon: connection lifecycle + schema migration + per-table
|
|
4
|
-
* CRUD, ported from the upstream daemon's decomposed `db/` capability-barrel. Only the generic engine
|
|
5
|
-
* tables (projects, conversations, messages, agent_sessions) are ported; OD-product tables
|
|
6
|
-
* (preview_comments, tabs, deployments, routines, templates) are intentionally excluded.
|
|
7
|
-
*/
|
|
8
|
-
export { openDatabase, closeDatabase } from './connection/index.js';
|
|
9
|
-
export { listConversations, getConversation, normalizeConversationSessionMode, insertConversation, updateConversation, deleteConversation, } from './conversations/index.js';
|
|
10
|
-
export { listMessages, upsertMessage, getMessageTelemetryFinalizationState, appendMessageStatusEvent, appendMessageAgentEvent, deleteMessage, } from './messages/index.js';
|
|
11
|
-
export { listProjects, listLatestProjectRunStatuses, listLatestConversationRunStatuses, listFirstConversationRunStatuses, listLatestRunStatuses, listProjectsAwaitingInput, listConversationsAwaitingInput, getProject, insertProject, updateProject, deleteProject, } from './projects/index.js';
|
|
12
|
-
export { getAgentSession, upsertAgentSession, getAgentSessionRecord, latestCompletedAssistantMessageId, updateAgentSessionStableHash, clearAgentSession, } from './agent-sessions/index.js';
|
|
13
|
-
export { parseJsonOrUndef, row, rows } from './core/index.js';
|
|
14
|
-
export { migrate } from './schema/index.js';
|
|
15
|
-
export { ensureToolCatalogTables, reseedToolCatalog, getToolCatalogEntry, searchToolCatalog } from './tool-catalog/index.js';
|
|
16
|
-
/**
|
|
17
|
-
* Owner-scoped chat history. Not to be confused with `./conversations/index.js` above: that one
|
|
18
|
-
* is `project_id`-scoped with no owner predicate (single-user local trust model), this one binds
|
|
19
|
-
* an owner into the store so no query can read across tenants. Pick by trust model.
|
|
20
|
-
*/
|
|
21
|
-
export { CHAT_HISTORY_DDL, ensureChatHistoryTables, createChatHistoryStore, createChatHistoryMaintenance } from './chat-history/index.js';
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/db/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gCAAgC,EAChC,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,oCAAoC,EACpC,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,iCAAiC,EACjC,gCAAgC,EAChC,qBAAqB,EACrB,yBAAyB,EACzB,8BAA8B,EAC9B,UAAU,EACV,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,iCAAiC,EACjC,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC7H;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/messages/index.ts"],"names":[],"mappings":"AAAA;sEACsE;AACtE,cAAc,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/messages/index.ts"],"names":[],"mappings":"AAAA;sEACsE;AACtE,cAAc,eAAe,CAAC"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module db/messages/messages
|
|
3
|
-
* Chat message CRUD, streamed-event append, and telemetry finalization. Imports only the
|
|
4
|
-
* core/ kernel (SqliteDb, DbRow, ChatSessionMode, parseJsonOrUndef).
|
|
5
|
-
*
|
|
6
|
-
* NOTE (neutral port): drops six OD-product JSON columns with no generic engine equivalent —
|
|
7
|
-
* `comment_attachments_json` (the preview-comments/canvas-annotation feature, explicitly out of
|
|
8
|
-
* scope for this port), `produced_files_json` and `trace_object_files_json` (design-canvas file
|
|
9
|
-
* output tracking), `feedback_json` (Critique Theater's scoring feedback), `pre_turn_file_names_json`
|
|
10
|
-
* (design-canvas per-turn file context), and `applied_plugin_snapshot_json` (OD's plugin host). The
|
|
11
|
-
* already-ported `schema/migrate.ts` messages table was pre-trimmed to match; see that file and
|
|
12
|
-
* `source-map.md`'s Design Decisions for the same drop list.
|
|
13
|
-
*/
|
|
14
|
-
import type { SqliteDb, DbRow, ChatSessionMode } from '../core/index.js';
|
|
15
|
-
/**
|
|
16
|
-
* Returns all messages for a conversation in ascending position order, with JSON columns parsed.
|
|
17
|
-
* @param db - Open SQLite connection.
|
|
18
|
-
* @param conversationId - Conversation whose messages to fetch.
|
|
19
|
-
* @returns Normalized message objects ready for API serialization.
|
|
20
|
-
*/
|
|
21
|
-
export declare function listMessages(db: SqliteDb, conversationId: string): {
|
|
22
|
-
id: any;
|
|
23
|
-
role: any;
|
|
24
|
-
content: any;
|
|
25
|
-
agentId: any;
|
|
26
|
-
agentName: any;
|
|
27
|
-
runId: any;
|
|
28
|
-
runStatus: any;
|
|
29
|
-
lastRunEventId: any;
|
|
30
|
-
events: any;
|
|
31
|
-
attachments: any;
|
|
32
|
-
sessionMode: ChatSessionMode | undefined;
|
|
33
|
-
runContext: any;
|
|
34
|
-
createdAt: any;
|
|
35
|
-
startedAt: any;
|
|
36
|
-
endedAt: any;
|
|
37
|
-
}[];
|
|
38
|
-
/**
|
|
39
|
-
* Thrown by `upsertMessage` when the caller presents a message `id` together with a
|
|
40
|
-
* `conversationId` that does not match the conversation the row already belongs to (`id` is a
|
|
41
|
-
* global primary key, not scoped per-conversation, so this is the only signal available). Rather
|
|
42
|
-
* than silently updating the wrong conversation's message — or silently doing nothing — while
|
|
43
|
-
* still bumping the caller-supplied `conversationId`'s `updated_at`, this is a hard failure: it is
|
|
44
|
-
* always a caller/transport bug (a confused id, or a multi-tenant mixup) and never a legitimate
|
|
45
|
-
* state to paper over.
|
|
46
|
-
*/
|
|
47
|
-
export declare class MessageConversationMismatchError extends Error {
|
|
48
|
-
readonly messageId: string;
|
|
49
|
-
readonly actualConversationId: string;
|
|
50
|
-
readonly requestedConversationId: string;
|
|
51
|
-
constructor(messageId: string, actualConversationId: string, requestedConversationId: string);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Inserts or updates a message row and bumps the parent conversation's `updated_at` for recency sorting.
|
|
55
|
-
* On insert, appends to the end of the conversation's position sequence.
|
|
56
|
-
* On update, preserves `telemetry_finalized_at` once set (one-way latch).
|
|
57
|
-
*
|
|
58
|
-
* The existence check, position calculation, insert-or-update, and conversation `updated_at` bump
|
|
59
|
-
* all run inside one `better-sqlite3` transaction (opened with `BEGIN IMMEDIATE` via `.immediate()`,
|
|
60
|
-
* not the default deferred `BEGIN`) so the whole read-then-write sequence is atomic: a concurrent
|
|
61
|
-
* connection's own `upsertMessage` call for the same conversation cannot read the pre-write
|
|
62
|
-
* `MAX(position)` while this one is still in flight and thereby compute the same next position —
|
|
63
|
-
* `BEGIN IMMEDIATE` acquires the write lock before this transaction's first read, so a concurrent
|
|
64
|
-
* writer blocks (or fails with `SQLITE_BUSY`, per its own busy-timeout policy) until this one
|
|
65
|
-
* commits, rather than interleaving.
|
|
66
|
-
*
|
|
67
|
-
* `id` is the messages table's global primary key (not scoped per-conversation), so a row can only
|
|
68
|
-
* ever belong to one conversation. If the caller-supplied `m.id` already exists under a different
|
|
69
|
-
* `conversationId`, this throws {@link MessageConversationMismatchError} instead of silently
|
|
70
|
-
* updating the wrong conversation's row (or the wrong conversation's `updated_at`).
|
|
71
|
-
*
|
|
72
|
-
* @param db - Open SQLite connection.
|
|
73
|
-
* @param conversationId - Owning conversation id.
|
|
74
|
-
* @param m - Message fields; JSON sub-fields are stringified automatically.
|
|
75
|
-
* @returns The normalized, re-fetched message row, or null if the row vanished between write and read.
|
|
76
|
-
* @throws {MessageConversationMismatchError} if `m.id` already exists under a different conversation.
|
|
77
|
-
*/
|
|
78
|
-
export declare function upsertMessage(db: SqliteDb, conversationId: string, m: DbRow): {
|
|
79
|
-
id: any;
|
|
80
|
-
role: any;
|
|
81
|
-
content: any;
|
|
82
|
-
agentId: any;
|
|
83
|
-
agentName: any;
|
|
84
|
-
runId: any;
|
|
85
|
-
runStatus: any;
|
|
86
|
-
lastRunEventId: any;
|
|
87
|
-
events: any;
|
|
88
|
-
attachments: any;
|
|
89
|
-
sessionMode: ChatSessionMode | undefined;
|
|
90
|
-
runContext: any;
|
|
91
|
-
createdAt: any;
|
|
92
|
-
startedAt: any;
|
|
93
|
-
endedAt: any;
|
|
94
|
-
} | null;
|
|
95
|
-
/**
|
|
96
|
-
* Reads whether telemetry has been finalized for a message without loading the full row.
|
|
97
|
-
* Used to decide whether to enqueue a finalization job.
|
|
98
|
-
* @returns `{ exists: false }` when the message is not found; otherwise `{ exists: true, finalizedAt }`.
|
|
99
|
-
*/
|
|
100
|
-
export declare function getMessageTelemetryFinalizationState(db: SqliteDb, messageId: string): {
|
|
101
|
-
exists: boolean;
|
|
102
|
-
finalizedAt: number | null;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Appends a `{ kind: 'status', label, detail? }` event to the message's events array.
|
|
106
|
-
* Deduplicates consecutive identical status events so the UI does not stutter on repeated flushes.
|
|
107
|
-
* @param db - Open SQLite connection.
|
|
108
|
-
* @param messageId - Target message id.
|
|
109
|
-
* @param event - Must carry a non-empty `label`; `detail` is optional.
|
|
110
|
-
* @returns The updated events array, or null if the message does not exist or label is empty.
|
|
111
|
-
*/
|
|
112
|
-
export declare function appendMessageStatusEvent(db: SqliteDb, messageId: string, event: DbRow): any[] | null;
|
|
113
|
-
/**
|
|
114
|
-
* Appends an arbitrary agent event to the message's events array, also streaming `text` deltas
|
|
115
|
-
* into the `content` column so the message text grows incrementally during a run.
|
|
116
|
-
* Deduplicates byte-identical consecutive events.
|
|
117
|
-
* @param db - Open SQLite connection.
|
|
118
|
-
* @param messageId - Target message id.
|
|
119
|
-
* @param event - Must carry a non-empty `kind`; `text` field is appended to content when kind is 'text'.
|
|
120
|
-
* @returns The updated events array, or null if the message does not exist or kind is empty.
|
|
121
|
-
*/
|
|
122
|
-
export declare function appendMessageAgentEvent(db: SqliteDb, messageId: string, event: DbRow): any[] | null;
|
|
123
|
-
/**
|
|
124
|
-
* Hard-deletes a single message row by id.
|
|
125
|
-
* @param db - Open SQLite connection.
|
|
126
|
-
* @param id - Message id to remove.
|
|
127
|
-
*/
|
|
128
|
-
export declare function deleteMessage(db: SqliteDb, id: string): void;
|
|
129
|
-
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/db/messages/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAczE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM;;;;;;;;;;;;;;;;IAUhE;AAED;;;;;;;;GAQG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;aAEvC,SAAS,EAAE,MAAM;aACjB,oBAAoB,EAAE,MAAM;aAC5B,uBAAuB,EAAE,MAAM;gBAF/B,SAAS,EAAE,MAAM,EACjB,oBAAoB,EAAE,MAAM,EAC5B,uBAAuB,EAAE,MAAM;CAQlD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK;;;;;;;;;;;;;;;;SAgG3E;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM;;;EAmBnF;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,gBAqBrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,gBAmBpF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAErD"}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { parseJsonOrUndef } from '../core/index.js';
|
|
2
|
-
/** @internal Column alias list used by both `listMessages` and `upsertMessage`'s re-fetch. */
|
|
3
|
-
const MESSAGE_COLS = `id, role, content, agent_id AS agentId, agent_name AS agentName,
|
|
4
|
-
run_id AS runId, run_status AS runStatus,
|
|
5
|
-
last_run_event_id AS lastRunEventId,
|
|
6
|
-
events_json AS eventsJson,
|
|
7
|
-
attachments_json AS attachmentsJson,
|
|
8
|
-
session_mode AS sessionMode,
|
|
9
|
-
run_context_json AS runContextJson,
|
|
10
|
-
created_at AS createdAt, started_at AS startedAt, ended_at AS endedAt,
|
|
11
|
-
position`;
|
|
12
|
-
/**
|
|
13
|
-
* Returns all messages for a conversation in ascending position order, with JSON columns parsed.
|
|
14
|
-
* @param db - Open SQLite connection.
|
|
15
|
-
* @param conversationId - Conversation whose messages to fetch.
|
|
16
|
-
* @returns Normalized message objects ready for API serialization.
|
|
17
|
-
*/
|
|
18
|
-
export function listMessages(db, conversationId) {
|
|
19
|
-
return db
|
|
20
|
-
.prepare(`SELECT ${MESSAGE_COLS}
|
|
21
|
-
FROM messages
|
|
22
|
-
WHERE conversation_id = ?
|
|
23
|
-
ORDER BY position ASC`)
|
|
24
|
-
.all(conversationId)
|
|
25
|
-
.map(normalizeMessage);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Thrown by `upsertMessage` when the caller presents a message `id` together with a
|
|
29
|
-
* `conversationId` that does not match the conversation the row already belongs to (`id` is a
|
|
30
|
-
* global primary key, not scoped per-conversation, so this is the only signal available). Rather
|
|
31
|
-
* than silently updating the wrong conversation's message — or silently doing nothing — while
|
|
32
|
-
* still bumping the caller-supplied `conversationId`'s `updated_at`, this is a hard failure: it is
|
|
33
|
-
* always a caller/transport bug (a confused id, or a multi-tenant mixup) and never a legitimate
|
|
34
|
-
* state to paper over.
|
|
35
|
-
*/
|
|
36
|
-
export class MessageConversationMismatchError extends Error {
|
|
37
|
-
messageId;
|
|
38
|
-
actualConversationId;
|
|
39
|
-
requestedConversationId;
|
|
40
|
-
constructor(messageId, actualConversationId, requestedConversationId) {
|
|
41
|
-
super(`upsertMessage: message id ${JSON.stringify(messageId)} belongs to a different conversation ` +
|
|
42
|
-
`(${JSON.stringify(actualConversationId)}), not ${JSON.stringify(requestedConversationId)}`);
|
|
43
|
-
this.messageId = messageId;
|
|
44
|
-
this.actualConversationId = actualConversationId;
|
|
45
|
-
this.requestedConversationId = requestedConversationId;
|
|
46
|
-
this.name = 'MessageConversationMismatchError';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Inserts or updates a message row and bumps the parent conversation's `updated_at` for recency sorting.
|
|
51
|
-
* On insert, appends to the end of the conversation's position sequence.
|
|
52
|
-
* On update, preserves `telemetry_finalized_at` once set (one-way latch).
|
|
53
|
-
*
|
|
54
|
-
* The existence check, position calculation, insert-or-update, and conversation `updated_at` bump
|
|
55
|
-
* all run inside one `better-sqlite3` transaction (opened with `BEGIN IMMEDIATE` via `.immediate()`,
|
|
56
|
-
* not the default deferred `BEGIN`) so the whole read-then-write sequence is atomic: a concurrent
|
|
57
|
-
* connection's own `upsertMessage` call for the same conversation cannot read the pre-write
|
|
58
|
-
* `MAX(position)` while this one is still in flight and thereby compute the same next position —
|
|
59
|
-
* `BEGIN IMMEDIATE` acquires the write lock before this transaction's first read, so a concurrent
|
|
60
|
-
* writer blocks (or fails with `SQLITE_BUSY`, per its own busy-timeout policy) until this one
|
|
61
|
-
* commits, rather than interleaving.
|
|
62
|
-
*
|
|
63
|
-
* `id` is the messages table's global primary key (not scoped per-conversation), so a row can only
|
|
64
|
-
* ever belong to one conversation. If the caller-supplied `m.id` already exists under a different
|
|
65
|
-
* `conversationId`, this throws {@link MessageConversationMismatchError} instead of silently
|
|
66
|
-
* updating the wrong conversation's row (or the wrong conversation's `updated_at`).
|
|
67
|
-
*
|
|
68
|
-
* @param db - Open SQLite connection.
|
|
69
|
-
* @param conversationId - Owning conversation id.
|
|
70
|
-
* @param m - Message fields; JSON sub-fields are stringified automatically.
|
|
71
|
-
* @returns The normalized, re-fetched message row, or null if the row vanished between write and read.
|
|
72
|
-
* @throws {MessageConversationMismatchError} if `m.id` already exists under a different conversation.
|
|
73
|
-
*/
|
|
74
|
-
export function upsertMessage(db, conversationId, m) {
|
|
75
|
-
const runUpsert = db.transaction(() => {
|
|
76
|
-
const existing = db
|
|
77
|
-
.prepare(`SELECT conversation_id AS conversationId, position FROM messages WHERE id = ?`)
|
|
78
|
-
.get(m.id);
|
|
79
|
-
if (existing && existing.conversationId !== conversationId) {
|
|
80
|
-
throw new MessageConversationMismatchError(m.id, existing.conversationId, conversationId);
|
|
81
|
-
}
|
|
82
|
-
const now = Date.now();
|
|
83
|
-
if (existing) {
|
|
84
|
-
db.prepare(`UPDATE messages
|
|
85
|
-
SET role = ?, content = ?, agent_id = ?, agent_name = ?,
|
|
86
|
-
run_id = ?, run_status = ?, last_run_event_id = ?,
|
|
87
|
-
events_json = ?, attachments_json = ?,
|
|
88
|
-
session_mode = ?, run_context_json = ?,
|
|
89
|
-
telemetry_finalized_at = CASE
|
|
90
|
-
WHEN ? THEN COALESCE(telemetry_finalized_at, ?)
|
|
91
|
-
ELSE telemetry_finalized_at
|
|
92
|
-
END,
|
|
93
|
-
started_at = ?, ended_at = ?
|
|
94
|
-
WHERE id = ? AND conversation_id = ?`).run(m.role, m.content, m.agentId ?? null, m.agentName ?? null, m.runId ?? null, m.runStatus ?? null, m.lastRunEventId ?? null, m.events ? JSON.stringify(m.events) : null, m.attachments ? JSON.stringify(m.attachments) : null, normalizeMessageSessionModeForStorage(m.sessionMode), m.runContext ? JSON.stringify(m.runContext) : null, m.telemetryFinalized === true ? 1 : 0, now, m.startedAt ?? null, m.endedAt ?? null, m.id, conversationId);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const max = db
|
|
98
|
-
.prepare(`SELECT COALESCE(MAX(position), -1) AS m FROM messages WHERE conversation_id = ?`)
|
|
99
|
-
.get(conversationId);
|
|
100
|
-
const position = (max?.m ?? -1) + 1;
|
|
101
|
-
const createdAt = typeof m.createdAt === 'number' && Number.isFinite(m.createdAt)
|
|
102
|
-
? m.createdAt
|
|
103
|
-
: now;
|
|
104
|
-
// 18 values: id, conversation_id, role, content, agent_id, agent_name,
|
|
105
|
-
// run_id, run_status, last_run_event_id, events_json, attachments_json,
|
|
106
|
-
// session_mode, run_context_json, telemetry_finalized_at, started_at,
|
|
107
|
-
// ended_at, position, created_at.
|
|
108
|
-
db.prepare(`INSERT INTO messages
|
|
109
|
-
(id, conversation_id, role, content, agent_id, agent_name,
|
|
110
|
-
run_id, run_status, last_run_event_id, events_json,
|
|
111
|
-
attachments_json, session_mode, run_context_json,
|
|
112
|
-
telemetry_finalized_at, started_at, ended_at, position, created_at)
|
|
113
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(m.id, conversationId, m.role, m.content, m.agentId ?? null, m.agentName ?? null, m.runId ?? null, m.runStatus ?? null, m.lastRunEventId ?? null, m.events ? JSON.stringify(m.events) : null, m.attachments ? JSON.stringify(m.attachments) : null, normalizeMessageSessionModeForStorage(m.sessionMode), m.runContext ? JSON.stringify(m.runContext) : null, m.telemetryFinalized === true ? now : null, m.startedAt ?? null, m.endedAt ?? null, position, createdAt);
|
|
114
|
-
}
|
|
115
|
-
// Bump conversation activity so recency-sorted listings (e.g. `listConversations`) reflect this write.
|
|
116
|
-
db.prepare(`UPDATE conversations SET updated_at = ? WHERE id = ?`).run(now, conversationId);
|
|
117
|
-
const row = db
|
|
118
|
-
.prepare(`SELECT ${MESSAGE_COLS} FROM messages WHERE id = ? AND conversation_id = ?`)
|
|
119
|
-
.get(m.id, conversationId);
|
|
120
|
-
return row ? normalizeMessage(row) : null;
|
|
121
|
-
});
|
|
122
|
-
return runUpsert.immediate();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Reads whether telemetry has been finalized for a message without loading the full row.
|
|
126
|
-
* Used to decide whether to enqueue a finalization job.
|
|
127
|
-
* @returns `{ exists: false }` when the message is not found; otherwise `{ exists: true, finalizedAt }`.
|
|
128
|
-
*/
|
|
129
|
-
export function getMessageTelemetryFinalizationState(db, messageId) {
|
|
130
|
-
const row = db
|
|
131
|
-
.prepare(`SELECT telemetry_finalized_at AS telemetryFinalizedAt
|
|
132
|
-
FROM messages
|
|
133
|
-
WHERE id = ?`)
|
|
134
|
-
.get(messageId);
|
|
135
|
-
if (!row) {
|
|
136
|
-
return {
|
|
137
|
-
exists: false,
|
|
138
|
-
finalizedAt: null,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
exists: true,
|
|
143
|
-
finalizedAt: typeof row.telemetryFinalizedAt === 'number' ? row.telemetryFinalizedAt : null,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Appends a `{ kind: 'status', label, detail? }` event to the message's events array.
|
|
148
|
-
* Deduplicates consecutive identical status events so the UI does not stutter on repeated flushes.
|
|
149
|
-
* @param db - Open SQLite connection.
|
|
150
|
-
* @param messageId - Target message id.
|
|
151
|
-
* @param event - Must carry a non-empty `label`; `detail` is optional.
|
|
152
|
-
* @returns The updated events array, or null if the message does not exist or label is empty.
|
|
153
|
-
*/
|
|
154
|
-
export function appendMessageStatusEvent(db, messageId, event) {
|
|
155
|
-
const label = typeof event?.label === 'string' ? event.label.trim() : '';
|
|
156
|
-
const detail = typeof event?.detail === 'string' ? event.detail.trim() : '';
|
|
157
|
-
if (!label)
|
|
158
|
-
return null;
|
|
159
|
-
const row = db
|
|
160
|
-
.prepare(`SELECT events_json AS eventsJson FROM messages WHERE id = ?`)
|
|
161
|
-
.get(messageId);
|
|
162
|
-
if (!row)
|
|
163
|
-
return null;
|
|
164
|
-
const parsed = parseJsonOrUndef(row.eventsJson);
|
|
165
|
-
const events = Array.isArray(parsed) ? parsed : [];
|
|
166
|
-
const last = events[events.length - 1];
|
|
167
|
-
if (last?.kind === 'status' && last.label === label && (last.detail ?? '') === detail) {
|
|
168
|
-
return events;
|
|
169
|
-
}
|
|
170
|
-
const nextEvent = detail
|
|
171
|
-
? { kind: 'status', label, detail }
|
|
172
|
-
: { kind: 'status', label };
|
|
173
|
-
const next = [...events, nextEvent];
|
|
174
|
-
db.prepare(`UPDATE messages SET events_json = ? WHERE id = ?`)
|
|
175
|
-
.run(JSON.stringify(next), messageId);
|
|
176
|
-
return next;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Appends an arbitrary agent event to the message's events array, also streaming `text` deltas
|
|
180
|
-
* into the `content` column so the message text grows incrementally during a run.
|
|
181
|
-
* Deduplicates byte-identical consecutive events.
|
|
182
|
-
* @param db - Open SQLite connection.
|
|
183
|
-
* @param messageId - Target message id.
|
|
184
|
-
* @param event - Must carry a non-empty `kind`; `text` field is appended to content when kind is 'text'.
|
|
185
|
-
* @returns The updated events array, or null if the message does not exist or kind is empty.
|
|
186
|
-
*/
|
|
187
|
-
export function appendMessageAgentEvent(db, messageId, event) {
|
|
188
|
-
if (!event || typeof event !== 'object')
|
|
189
|
-
return null;
|
|
190
|
-
const kind = typeof event.kind === 'string' ? event.kind : '';
|
|
191
|
-
if (!kind)
|
|
192
|
-
return null;
|
|
193
|
-
const row = db
|
|
194
|
-
.prepare(`SELECT content, events_json AS eventsJson FROM messages WHERE id = ?`)
|
|
195
|
-
.get(messageId);
|
|
196
|
-
if (!row)
|
|
197
|
-
return null;
|
|
198
|
-
const parsed = parseJsonOrUndef(row.eventsJson);
|
|
199
|
-
const events = Array.isArray(parsed) ? parsed : [];
|
|
200
|
-
const last = events[events.length - 1];
|
|
201
|
-
if (last && JSON.stringify(last) === JSON.stringify(event)) {
|
|
202
|
-
return events;
|
|
203
|
-
}
|
|
204
|
-
const next = [...events, event];
|
|
205
|
-
const textDelta = kind === 'text' && typeof event.text === 'string' ? event.text : '';
|
|
206
|
-
db.prepare(`UPDATE messages SET content = COALESCE(content, '') || ?, events_json = ? WHERE id = ?`)
|
|
207
|
-
.run(textDelta, JSON.stringify(next), messageId);
|
|
208
|
-
return next;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Hard-deletes a single message row by id.
|
|
212
|
-
* @param db - Open SQLite connection.
|
|
213
|
-
* @param id - Message id to remove.
|
|
214
|
-
*/
|
|
215
|
-
export function deleteMessage(db, id) {
|
|
216
|
-
db.prepare(`DELETE FROM messages WHERE id = ?`).run(id);
|
|
217
|
-
}
|
|
218
|
-
/** @internal Converts a raw SQLite row to a plain object with JSON columns parsed and null coerced to undefined. */
|
|
219
|
-
function normalizeMessage(row) {
|
|
220
|
-
return {
|
|
221
|
-
id: row.id,
|
|
222
|
-
role: row.role,
|
|
223
|
-
content: row.content,
|
|
224
|
-
agentId: row.agentId ?? undefined,
|
|
225
|
-
agentName: row.agentName ?? undefined,
|
|
226
|
-
runId: row.runId ?? undefined,
|
|
227
|
-
runStatus: row.runStatus ?? undefined,
|
|
228
|
-
lastRunEventId: row.lastRunEventId ?? undefined,
|
|
229
|
-
events: parseJsonOrUndef(row.eventsJson),
|
|
230
|
-
attachments: parseJsonOrUndef(row.attachmentsJson),
|
|
231
|
-
sessionMode: normalizeMessageSessionMode(row.sessionMode),
|
|
232
|
-
runContext: parseJsonOrUndef(row.runContextJson),
|
|
233
|
-
createdAt: row.createdAt ?? undefined,
|
|
234
|
-
startedAt: row.startedAt ?? undefined,
|
|
235
|
-
endedAt: row.endedAt ?? undefined,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
/** @internal Validates that a stored session_mode value is a known ChatSessionMode; returns undefined for unrecognised values. */
|
|
239
|
-
function normalizeMessageSessionMode(value) {
|
|
240
|
-
return value === 'chat' || value === 'design' || value === 'plan' ? value : undefined;
|
|
241
|
-
}
|
|
242
|
-
/** @internal Same validation as normalizeMessageSessionMode but returns null (SQLite-safe) for unrecognised values. */
|
|
243
|
-
function normalizeMessageSessionModeForStorage(value) {
|
|
244
|
-
return value === 'chat' || value === 'design' || value === 'plan' ? value : null;
|
|
245
|
-
}
|
|
246
|
-
//# sourceMappingURL=messages.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/db/messages/messages.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,8FAA8F;AAC9F,MAAM,YAAY,GAAG;;;;;;;;WAQV,CAAC;AAEZ;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,EAAY,EAAE,cAAsB;IAC/D,OAAQ,EAAE;SACP,OAAO,CACN,UAAU,YAAY;;;8BAGE,CACzB;SACA,GAAG,CAAC,cAAc,CAAa;SAC/B,GAAG,CAAC,gBAAgB,CAAC,CAAC;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GAAG,CAAC,cAAc,IAAI,SAAS;QAC/C,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC;QACxC,WAAW,EAAE,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC;QAClD,WAAW,EAAE,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC;QACzD,UAAU,EAAE,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC;QAChD,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,SAAS;QACrC,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,SAAS;QACrC,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,SAAS;KAClC,CAAC;AACJ,CAAC;AAED,kIAAkI;AAClI,SAAS,2BAA2B,CAAC,KAAc;IACjD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACxF,CAAC;AAED,uHAAuH;AACvH,SAAS,qCAAqC,CAAC,KAAc;IAC3D,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACnF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/projects/index.ts"],"names":[],"mappings":"AAAA;uDACuD;AACvD,cAAc,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/projects/index.ts"],"names":[],"mappings":"AAAA;uDACuD;AACvD,cAAc,eAAe,CAAC"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/** @module db/projects
|
|
2
|
-
* CRUD, run-status queries, and awaiting-input detection for the `projects` SQLite table — a
|
|
3
|
-
* generic workspace/container row-store, not an OD-specific concept. Also queries `messages` and
|
|
4
|
-
* `conversations` for run-status and input-gate state. Imports only the core/ kernel (SqliteDb,
|
|
5
|
-
* DbRow); reaches no sibling concern.
|
|
6
|
-
*
|
|
7
|
-
* NOTE (neutral port): drops three OD-product columns with no generic engine equivalent —
|
|
8
|
-
* `skill_id` (OD's agent-skill marketplace selection), `design_system_id` (OD's Design System
|
|
9
|
-
* feature), and `applied_plugin_snapshot_id` (OD's plugin host). The already-ported
|
|
10
|
-
* `schema/migrate.ts` projects table was pre-trimmed to match; see that file and `source-map.md`'s
|
|
11
|
-
* Design Decisions for the same drop list. The kernel-noun exclusion in `extraction-plan.md` §2.1
|
|
12
|
-
* ("projects... conversations" are not kernel nouns) does not block this module for the same reason
|
|
13
|
-
* it didn't block `conversations`: `@jini-ai/sqlite` is a generic *optional* storage adapter any
|
|
14
|
-
* consumer may use, not the kernel itself (`@jini-ai/core`/`@jini-ai/daemon` know nothing about this
|
|
15
|
-
* table) — so "project" here is a de-branded generic workspace/container concept, not OD's model.
|
|
16
|
-
*/
|
|
17
|
-
import type { SqliteDb, DbRow } from '../core/index.js';
|
|
18
|
-
/**
|
|
19
|
-
* Returns all projects ordered by most-recently updated first.
|
|
20
|
-
* @param db - Open SQLite connection.
|
|
21
|
-
*/
|
|
22
|
-
export declare function listProjects(db: SqliteDb): {
|
|
23
|
-
id: any;
|
|
24
|
-
name: any;
|
|
25
|
-
pendingPrompt: any;
|
|
26
|
-
metadata: any;
|
|
27
|
-
customInstructions: any;
|
|
28
|
-
createdAt: number;
|
|
29
|
-
updatedAt: number;
|
|
30
|
-
}[];
|
|
31
|
-
/**
|
|
32
|
-
* Returns the most recent run status for each project, keyed by projectId.
|
|
33
|
-
* Scans messages with a run_status column and collapses to one entry per project,
|
|
34
|
-
* so callers can render project-level status badges without iterating conversations.
|
|
35
|
-
* @param db - Open SQLite connection.
|
|
36
|
-
*/
|
|
37
|
-
export declare function listLatestProjectRunStatuses(db: SqliteDb): Map<string, DbRow>;
|
|
38
|
-
/**
|
|
39
|
-
* Returns the most recent run status for each conversation, keyed by conversationId.
|
|
40
|
-
* Used to display per-conversation activity state in a project sidebar.
|
|
41
|
-
* @param db - Open SQLite connection.
|
|
42
|
-
*/
|
|
43
|
-
export declare function listLatestConversationRunStatuses(db: SqliteDb): Map<string, DbRow>;
|
|
44
|
-
/**
|
|
45
|
-
* Returns the earliest run status for each conversation, keyed by conversationId.
|
|
46
|
-
* Useful for determining when a conversation's first agent turn began.
|
|
47
|
-
* @param db - Open SQLite connection.
|
|
48
|
-
*/
|
|
49
|
-
export declare function listFirstConversationRunStatuses(db: SqliteDb): Map<string, DbRow>;
|
|
50
|
-
/**
|
|
51
|
-
* Returns the most recent run status for each individual run, keyed by runId.
|
|
52
|
-
* Powers per-run status indicators in a conversation thread.
|
|
53
|
-
* @param db - Open SQLite connection.
|
|
54
|
-
*/
|
|
55
|
-
export declare function listLatestRunStatuses(db: SqliteDb): Map<string, DbRow>;
|
|
56
|
-
/**
|
|
57
|
-
* Returns the set of project IDs whose latest assistant message contains a
|
|
58
|
-
* `<question-form>` or `<ask-question>` artifact and has not yet received a user reply.
|
|
59
|
-
* This is the data source for an "awaiting input" badge on a project list.
|
|
60
|
-
* @param db - Open SQLite connection.
|
|
61
|
-
*/
|
|
62
|
-
export declare function listProjectsAwaitingInput(db: SqliteDb): Set<any>;
|
|
63
|
-
/**
|
|
64
|
-
* Returns the set of conversation IDs whose latest assistant message contains a
|
|
65
|
-
* `<question-form>` or `<ask-question>` artifact and has not yet received a user reply.
|
|
66
|
-
* @param db - Open SQLite connection.
|
|
67
|
-
*/
|
|
68
|
-
export declare function listConversationsAwaitingInput(db: SqliteDb): Set<any>;
|
|
69
|
-
/**
|
|
70
|
-
* Fetches a single project by id, or returns null if it does not exist.
|
|
71
|
-
* @param db - Open SQLite connection.
|
|
72
|
-
* @param id - Project id.
|
|
73
|
-
*/
|
|
74
|
-
export declare function getProject(db: SqliteDb, id: string): {
|
|
75
|
-
id: any;
|
|
76
|
-
name: any;
|
|
77
|
-
pendingPrompt: any;
|
|
78
|
-
metadata: any;
|
|
79
|
-
customInstructions: any;
|
|
80
|
-
createdAt: number;
|
|
81
|
-
updatedAt: number;
|
|
82
|
-
} | null;
|
|
83
|
-
/**
|
|
84
|
-
* Inserts a new project row and returns the freshly read, normalized record.
|
|
85
|
-
* Metadata is serialized to JSON; all nullable fields default to null on omission.
|
|
86
|
-
* @param db - Open SQLite connection.
|
|
87
|
-
* @param p - Project fields to insert.
|
|
88
|
-
*/
|
|
89
|
-
export declare function insertProject(db: SqliteDb, p: DbRow): {
|
|
90
|
-
id: any;
|
|
91
|
-
name: any;
|
|
92
|
-
pendingPrompt: any;
|
|
93
|
-
metadata: any;
|
|
94
|
-
customInstructions: any;
|
|
95
|
-
createdAt: number;
|
|
96
|
-
updatedAt: number;
|
|
97
|
-
} | null;
|
|
98
|
-
/**
|
|
99
|
-
* Applies a partial patch to an existing project, preserving all unpatched fields.
|
|
100
|
-
* Returns null when the project does not exist; otherwise returns the updated record.
|
|
101
|
-
* updatedAt defaults to Date.now() when the patch omits it.
|
|
102
|
-
* @param db - Open SQLite connection.
|
|
103
|
-
* @param id - Project id to update.
|
|
104
|
-
* @param patch - Fields to overwrite.
|
|
105
|
-
*/
|
|
106
|
-
export declare function updateProject(db: SqliteDb, id: string, patch: DbRow): {
|
|
107
|
-
id: any;
|
|
108
|
-
name: any;
|
|
109
|
-
pendingPrompt: any;
|
|
110
|
-
metadata: any;
|
|
111
|
-
customInstructions: any;
|
|
112
|
-
createdAt: number;
|
|
113
|
-
updatedAt: number;
|
|
114
|
-
} | null;
|
|
115
|
-
/**
|
|
116
|
-
* Permanently removes a project row. Cascading deletes for related rows are
|
|
117
|
-
* handled at the SQLite schema level, not here.
|
|
118
|
-
* @param db - Open SQLite connection.
|
|
119
|
-
* @param id - Project id to delete.
|
|
120
|
-
*/
|
|
121
|
-
export declare function deleteProject(db: SqliteDb, id: string): void;
|
|
122
|
-
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../../src/db/projects/projects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAUxD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ;;;;;;;;IASxC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,QAAQ,sBAwBxD;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,QAAQ,sBAwB7D;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,QAAQ,sBAyB5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,sBAwBjD;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,YAsCrD;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,QAAQ,YAiC1D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM;;;;;;;;SAKlD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK;;;;;;;;SAenD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;;;;;;;;SAyBnE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAErD"}
|