@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,311 +0,0 @@
|
|
|
1
|
-
/** @internal Column alias list used in every SELECT against the projects table. */
|
|
2
|
-
const PROJECT_COLS = `id, name,
|
|
3
|
-
pending_prompt AS pendingPrompt,
|
|
4
|
-
metadata_json AS metadataJson,
|
|
5
|
-
custom_instructions AS customInstructions,
|
|
6
|
-
created_at AS createdAt,
|
|
7
|
-
updated_at AS updatedAt`;
|
|
8
|
-
/**
|
|
9
|
-
* Returns all projects ordered by most-recently updated first.
|
|
10
|
-
* @param db - Open SQLite connection.
|
|
11
|
-
*/
|
|
12
|
-
export function listProjects(db) {
|
|
13
|
-
const rows = db
|
|
14
|
-
.prepare(`SELECT ${PROJECT_COLS}
|
|
15
|
-
FROM projects
|
|
16
|
-
ORDER BY updated_at DESC`)
|
|
17
|
-
.all();
|
|
18
|
-
return rows.map(normalizeProject);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns the most recent run status for each project, keyed by projectId.
|
|
22
|
-
* Scans messages with a run_status column and collapses to one entry per project,
|
|
23
|
-
* so callers can render project-level status badges without iterating conversations.
|
|
24
|
-
* @param db - Open SQLite connection.
|
|
25
|
-
*/
|
|
26
|
-
export function listLatestProjectRunStatuses(db) {
|
|
27
|
-
const rows = db
|
|
28
|
-
.prepare(`SELECT c.project_id AS projectId,
|
|
29
|
-
m.run_id AS runId,
|
|
30
|
-
m.run_status AS status,
|
|
31
|
-
COALESCE(m.ended_at, m.started_at, m.created_at) AS updatedAt
|
|
32
|
-
FROM messages m
|
|
33
|
-
JOIN conversations c ON c.id = m.conversation_id
|
|
34
|
-
WHERE m.run_status IS NOT NULL
|
|
35
|
-
ORDER BY updatedAt DESC`)
|
|
36
|
-
.all();
|
|
37
|
-
const latestByProject = new Map();
|
|
38
|
-
for (const row of rows) {
|
|
39
|
-
if (!latestByProject.has(row.projectId)) {
|
|
40
|
-
latestByProject.set(row.projectId, {
|
|
41
|
-
value: normalizeProjectRunStatus(row.status),
|
|
42
|
-
updatedAt: Number(row.updatedAt),
|
|
43
|
-
runId: row.runId ?? undefined,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return latestByProject;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns the most recent run status for each conversation, keyed by conversationId.
|
|
51
|
-
* Used to display per-conversation activity state in a project sidebar.
|
|
52
|
-
* @param db - Open SQLite connection.
|
|
53
|
-
*/
|
|
54
|
-
export function listLatestConversationRunStatuses(db) {
|
|
55
|
-
const rows = db
|
|
56
|
-
.prepare(`SELECT m.conversation_id AS conversationId,
|
|
57
|
-
m.run_id AS runId,
|
|
58
|
-
m.run_status AS status,
|
|
59
|
-
COALESCE(m.ended_at, m.started_at, m.created_at) AS updatedAt,
|
|
60
|
-
m.position AS position
|
|
61
|
-
FROM messages m
|
|
62
|
-
WHERE m.run_status IS NOT NULL
|
|
63
|
-
ORDER BY updatedAt DESC, m.position DESC`)
|
|
64
|
-
.all();
|
|
65
|
-
const latestByConversation = new Map();
|
|
66
|
-
for (const row of rows) {
|
|
67
|
-
if (!latestByConversation.has(row.conversationId)) {
|
|
68
|
-
latestByConversation.set(row.conversationId, {
|
|
69
|
-
value: normalizeProjectRunStatus(row.status),
|
|
70
|
-
updatedAt: Number(row.updatedAt),
|
|
71
|
-
runId: row.runId ?? undefined,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return latestByConversation;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Returns the earliest run status for each conversation, keyed by conversationId.
|
|
79
|
-
* Useful for determining when a conversation's first agent turn began.
|
|
80
|
-
* @param db - Open SQLite connection.
|
|
81
|
-
*/
|
|
82
|
-
export function listFirstConversationRunStatuses(db) {
|
|
83
|
-
const rows = db
|
|
84
|
-
.prepare(`SELECT m.conversation_id AS conversationId,
|
|
85
|
-
m.run_id AS runId,
|
|
86
|
-
m.run_status AS status,
|
|
87
|
-
COALESCE(m.ended_at, m.started_at, m.created_at) AS updatedAt,
|
|
88
|
-
m.position AS position
|
|
89
|
-
FROM messages m
|
|
90
|
-
WHERE m.run_status IS NOT NULL
|
|
91
|
-
AND m.run_id IS NOT NULL
|
|
92
|
-
ORDER BY m.position ASC`)
|
|
93
|
-
.all();
|
|
94
|
-
const firstByConversation = new Map();
|
|
95
|
-
for (const row of rows) {
|
|
96
|
-
if (!firstByConversation.has(row.conversationId)) {
|
|
97
|
-
firstByConversation.set(row.conversationId, {
|
|
98
|
-
value: normalizeProjectRunStatus(row.status),
|
|
99
|
-
updatedAt: Number(row.updatedAt),
|
|
100
|
-
runId: row.runId ?? undefined,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return firstByConversation;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Returns the most recent run status for each individual run, keyed by runId.
|
|
108
|
-
* Powers per-run status indicators in a conversation thread.
|
|
109
|
-
* @param db - Open SQLite connection.
|
|
110
|
-
*/
|
|
111
|
-
export function listLatestRunStatuses(db) {
|
|
112
|
-
const rows = db
|
|
113
|
-
.prepare(`SELECT m.run_id AS runId,
|
|
114
|
-
m.run_status AS status,
|
|
115
|
-
COALESCE(m.ended_at, m.started_at, m.created_at) AS updatedAt,
|
|
116
|
-
m.position AS position
|
|
117
|
-
FROM messages m
|
|
118
|
-
WHERE m.run_status IS NOT NULL
|
|
119
|
-
AND m.run_id IS NOT NULL
|
|
120
|
-
ORDER BY updatedAt DESC, m.position DESC`)
|
|
121
|
-
.all();
|
|
122
|
-
const latestByRun = new Map();
|
|
123
|
-
for (const row of rows) {
|
|
124
|
-
if (!latestByRun.has(row.runId)) {
|
|
125
|
-
latestByRun.set(row.runId, {
|
|
126
|
-
value: normalizeProjectRunStatus(row.status),
|
|
127
|
-
updatedAt: Number(row.updatedAt),
|
|
128
|
-
runId: row.runId ?? undefined,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return latestByRun;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Returns the set of project IDs whose latest assistant message contains a
|
|
136
|
-
* `<question-form>` or `<ask-question>` artifact and has not yet received a user reply.
|
|
137
|
-
* This is the data source for an "awaiting input" badge on a project list.
|
|
138
|
-
* @param db - Open SQLite connection.
|
|
139
|
-
*/
|
|
140
|
-
export function listProjectsAwaitingInput(db) {
|
|
141
|
-
const rows = db
|
|
142
|
-
.prepare(`SELECT latest.projectId
|
|
143
|
-
FROM (
|
|
144
|
-
SELECT c.project_id AS projectId,
|
|
145
|
-
m.conversation_id AS conversationId,
|
|
146
|
-
m.created_at AS createdAt,
|
|
147
|
-
m.position AS position,
|
|
148
|
-
ROW_NUMBER() OVER (
|
|
149
|
-
PARTITION BY c.project_id
|
|
150
|
-
ORDER BY m.created_at DESC, m.position DESC
|
|
151
|
-
) AS rowNum
|
|
152
|
-
FROM messages m
|
|
153
|
-
JOIN conversations c ON c.id = m.conversation_id
|
|
154
|
-
WHERE m.role = 'assistant'
|
|
155
|
-
-- ask-question is an accepted alias for question-form (host UI parser
|
|
156
|
-
-- + agent open-tag matcher), so an alias-form turn must also count as
|
|
157
|
-
-- awaiting input.
|
|
158
|
-
AND (
|
|
159
|
-
LOWER(m.content) LIKE '%<question-form%'
|
|
160
|
-
OR LOWER(m.content) LIKE '%<ask-question%'
|
|
161
|
-
)
|
|
162
|
-
) latest
|
|
163
|
-
WHERE latest.rowNum = 1
|
|
164
|
-
AND NOT EXISTS (
|
|
165
|
-
SELECT 1
|
|
166
|
-
FROM messages reply
|
|
167
|
-
WHERE reply.conversation_id = latest.conversationId
|
|
168
|
-
AND reply.role = 'user'
|
|
169
|
-
AND (
|
|
170
|
-
reply.created_at > latest.createdAt
|
|
171
|
-
OR (reply.created_at = latest.createdAt AND reply.position > latest.position)
|
|
172
|
-
)
|
|
173
|
-
)`)
|
|
174
|
-
.all();
|
|
175
|
-
return new Set(rows.map((row) => row.projectId));
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Returns the set of conversation IDs whose latest assistant message contains a
|
|
179
|
-
* `<question-form>` or `<ask-question>` artifact and has not yet received a user reply.
|
|
180
|
-
* @param db - Open SQLite connection.
|
|
181
|
-
*/
|
|
182
|
-
export function listConversationsAwaitingInput(db) {
|
|
183
|
-
const rows = db
|
|
184
|
-
.prepare(`SELECT latest.conversationId
|
|
185
|
-
FROM (
|
|
186
|
-
SELECT m.conversation_id AS conversationId,
|
|
187
|
-
m.created_at AS createdAt,
|
|
188
|
-
m.position AS position,
|
|
189
|
-
ROW_NUMBER() OVER (
|
|
190
|
-
PARTITION BY m.conversation_id
|
|
191
|
-
ORDER BY m.created_at DESC, m.position DESC
|
|
192
|
-
) AS rowNum
|
|
193
|
-
FROM messages m
|
|
194
|
-
WHERE m.role = 'assistant'
|
|
195
|
-
AND (
|
|
196
|
-
LOWER(m.content) LIKE '%<question-form%'
|
|
197
|
-
OR LOWER(m.content) LIKE '%<ask-question%'
|
|
198
|
-
)
|
|
199
|
-
) latest
|
|
200
|
-
WHERE latest.rowNum = 1
|
|
201
|
-
AND NOT EXISTS (
|
|
202
|
-
SELECT 1
|
|
203
|
-
FROM messages reply
|
|
204
|
-
WHERE reply.conversation_id = latest.conversationId
|
|
205
|
-
AND reply.role = 'user'
|
|
206
|
-
AND (
|
|
207
|
-
reply.created_at > latest.createdAt
|
|
208
|
-
OR (reply.created_at = latest.createdAt AND reply.position > latest.position)
|
|
209
|
-
)
|
|
210
|
-
)`)
|
|
211
|
-
.all();
|
|
212
|
-
return new Set(rows.map((row) => row.conversationId));
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Fetches a single project by id, or returns null if it does not exist.
|
|
216
|
-
* @param db - Open SQLite connection.
|
|
217
|
-
* @param id - Project id.
|
|
218
|
-
*/
|
|
219
|
-
export function getProject(db, id) {
|
|
220
|
-
const row = db
|
|
221
|
-
.prepare(`SELECT ${PROJECT_COLS} FROM projects WHERE id = ?`)
|
|
222
|
-
.get(id);
|
|
223
|
-
return row ? normalizeProject(row) : null;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Inserts a new project row and returns the freshly read, normalized record.
|
|
227
|
-
* Metadata is serialized to JSON; all nullable fields default to null on omission.
|
|
228
|
-
* @param db - Open SQLite connection.
|
|
229
|
-
* @param p - Project fields to insert.
|
|
230
|
-
*/
|
|
231
|
-
export function insertProject(db, p) {
|
|
232
|
-
db.prepare(`INSERT INTO projects
|
|
233
|
-
(id, name, pending_prompt, metadata_json, custom_instructions, created_at, updated_at)
|
|
234
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`).run(p.id, p.name, p.pendingPrompt ?? null, p.metadata ? JSON.stringify(p.metadata) : null, p.customInstructions ?? null, p.createdAt, p.updatedAt);
|
|
235
|
-
return getProject(db, p.id);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Applies a partial patch to an existing project, preserving all unpatched fields.
|
|
239
|
-
* Returns null when the project does not exist; otherwise returns the updated record.
|
|
240
|
-
* updatedAt defaults to Date.now() when the patch omits it.
|
|
241
|
-
* @param db - Open SQLite connection.
|
|
242
|
-
* @param id - Project id to update.
|
|
243
|
-
* @param patch - Fields to overwrite.
|
|
244
|
-
*/
|
|
245
|
-
export function updateProject(db, id, patch) {
|
|
246
|
-
const existing = getProject(db, id);
|
|
247
|
-
if (!existing)
|
|
248
|
-
return null;
|
|
249
|
-
const merged = {
|
|
250
|
-
...existing,
|
|
251
|
-
...patch,
|
|
252
|
-
updatedAt: typeof patch.updatedAt === 'number' ? patch.updatedAt : Date.now(),
|
|
253
|
-
};
|
|
254
|
-
db.prepare(`UPDATE projects
|
|
255
|
-
SET name = ?,
|
|
256
|
-
pending_prompt = ?,
|
|
257
|
-
metadata_json = ?,
|
|
258
|
-
custom_instructions = ?,
|
|
259
|
-
updated_at = ?
|
|
260
|
-
WHERE id = ?`).run(merged.name, merged.pendingPrompt ?? null, merged.metadata ? JSON.stringify(merged.metadata) : null, merged.customInstructions ?? null, merged.updatedAt, id);
|
|
261
|
-
return getProject(db, id);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Permanently removes a project row. Cascading deletes for related rows are
|
|
265
|
-
* handled at the SQLite schema level, not here.
|
|
266
|
-
* @param db - Open SQLite connection.
|
|
267
|
-
* @param id - Project id to delete.
|
|
268
|
-
*/
|
|
269
|
-
export function deleteProject(db, id) {
|
|
270
|
-
db.prepare(`DELETE FROM projects WHERE id = ?`).run(id);
|
|
271
|
-
}
|
|
272
|
-
/** @internal Converts a raw SQLite row into the typed project shape, parsing
|
|
273
|
-
* metadataJson and casting numeric timestamps. */
|
|
274
|
-
function normalizeProject(row) {
|
|
275
|
-
let metadata;
|
|
276
|
-
if (row.metadataJson) {
|
|
277
|
-
try {
|
|
278
|
-
metadata = JSON.parse(row.metadataJson);
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
metadata = undefined;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
id: row.id,
|
|
286
|
-
name: row.name,
|
|
287
|
-
pendingPrompt: row.pendingPrompt ?? undefined,
|
|
288
|
-
metadata,
|
|
289
|
-
customInstructions: row.customInstructions ?? undefined,
|
|
290
|
-
createdAt: Number(row.createdAt),
|
|
291
|
-
updatedAt: Number(row.updatedAt),
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
/** @internal Maps raw DB run_status strings to the canonical client-facing enum,
|
|
295
|
-
* collapsing 'starting' → 'running' and 'cancelled' → 'canceled', and defaulting
|
|
296
|
-
* unknown values to 'not_started'. */
|
|
297
|
-
function normalizeProjectRunStatus(status) {
|
|
298
|
-
if (status === 'starting')
|
|
299
|
-
return 'running';
|
|
300
|
-
if (status === 'cancelled')
|
|
301
|
-
return 'canceled';
|
|
302
|
-
if (status === 'queued' ||
|
|
303
|
-
status === 'running' ||
|
|
304
|
-
status === 'succeeded' ||
|
|
305
|
-
status === 'failed' ||
|
|
306
|
-
status === 'canceled') {
|
|
307
|
-
return status;
|
|
308
|
-
}
|
|
309
|
-
return 'not_started';
|
|
310
|
-
}
|
|
311
|
-
//# sourceMappingURL=projects.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../../src/db/projects/projects.ts"],"names":[],"mappings":"AAkBA,mFAAmF;AACnF,MAAM,YAAY,GAAG;;;;;0BAKK,CAAC;AAE3B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAAY;IACvC,MAAM,IAAI,GAAG,EAAE;SACZ,OAAO,CACN,UAAU,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ACmD;AACnD,SAAS,gBAAgB,CAAC,GAAU;IAClC,IAAI,QAAQ,CAAC;IACb,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,IAAI,CAAC;YACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,QAAQ,GAAG,SAAS,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,aAAa,EAAE,GAAG,CAAC,aAAa,IAAI,SAAS;QAC7C,QAAQ;QACR,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,IAAI,SAAS;QACvD,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QAChC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;KACjC,CAAC;AACJ,CAAC;AAED;;uCAEuC;AACvC,SAAS,yBAAyB,CAAC,MAAe;IAChD,IAAI,MAAM,KAAK,UAAU;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC;IAC9C,IACE,MAAM,KAAK,QAAQ;QACnB,MAAM,KAAK,SAAS;QACpB,MAAM,KAAK,WAAW;QACtB,MAAM,KAAK,QAAQ;QACnB,MAAM,KAAK,UAAU,EACrB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/schema/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/db/schema/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/schema/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/** @module db/schema/migrate
|
|
2
|
-
* DDL for the daemon's SQLite database — creates the generic engine tables and indexes.
|
|
3
|
-
* Imports only `core/`.
|
|
4
|
-
*
|
|
5
|
-
* NOTE (neutral port): ported from the upstream daemon's decomposed `db/schema` barrel. Two
|
|
6
|
-
* deliberate changes: (1) OD-product tables (preview_comments, tabs, deployments, routines,
|
|
7
|
-
* templates) and their per-feature migrators (critique, media/tasks, library-store, plugins)
|
|
8
|
-
* are excluded — they belong in a consumer adapter, not the neutral engine; (2) OD's
|
|
9
|
-
* forward-compatible `ALTER TABLE … ADD COLUMN` machinery (migrating pre-existing OD databases)
|
|
10
|
-
* is dropped — Jini is greenfield, so every column lives in the base `CREATE`.
|
|
11
|
-
*
|
|
12
|
-
* `capability_definitions`/`capability_executions` were added 2026-07-24 (the SQLite half of
|
|
13
|
-
* `ai-control-plane.md` §9's proposed capability catalog) and removed 2026-07-25: they had zero
|
|
14
|
-
* consumers, so `migrate()` was creating two tables in every daemon's database that nothing read
|
|
15
|
-
* or wrote. The registry (`@jini-ai/daemon`'s `ToolRegistry`) is the catalog until search-at-scale is
|
|
16
|
-
* a real requirement, and `capability_executions` duplicated `ToolExecutionAuditRecord`
|
|
17
|
-
* (`packages/daemon/src/tool-executor.ts`) in a strictly weaker shape — no `principalId`, no
|
|
18
|
-
* `runId`, no per-phase event log. When the audit trail needs durability, back *that* record here
|
|
19
|
-
* so there is one audit noun, rather than reviving a parallel one.
|
|
20
|
-
*/
|
|
21
|
-
import type { SqliteDb } from '../core/index.js';
|
|
22
|
-
/**
|
|
23
|
-
* Idempotent schema bootstrap: creates the generic tables and indexes.
|
|
24
|
-
* Safe to call repeatedly (all statements are `IF NOT EXISTS`).
|
|
25
|
-
* Must be called once after `openDatabase`.
|
|
26
|
-
* @param db - the open better-sqlite3 handle to migrate
|
|
27
|
-
*/
|
|
28
|
-
export declare function migrate(db: SqliteDb): void;
|
|
29
|
-
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/db/schema/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAsE1C"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Idempotent schema bootstrap: creates the generic tables and indexes.
|
|
3
|
-
* Safe to call repeatedly (all statements are `IF NOT EXISTS`).
|
|
4
|
-
* Must be called once after `openDatabase`.
|
|
5
|
-
* @param db - the open better-sqlite3 handle to migrate
|
|
6
|
-
*/
|
|
7
|
-
export function migrate(db) {
|
|
8
|
-
db.exec(`
|
|
9
|
-
CREATE TABLE IF NOT EXISTS projects (
|
|
10
|
-
id TEXT PRIMARY KEY,
|
|
11
|
-
name TEXT NOT NULL,
|
|
12
|
-
pending_prompt TEXT,
|
|
13
|
-
metadata_json TEXT,
|
|
14
|
-
custom_instructions TEXT,
|
|
15
|
-
created_at INTEGER NOT NULL,
|
|
16
|
-
updated_at INTEGER NOT NULL
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
CREATE TABLE IF NOT EXISTS conversations (
|
|
20
|
-
id TEXT PRIMARY KEY,
|
|
21
|
-
project_id TEXT NOT NULL,
|
|
22
|
-
title TEXT,
|
|
23
|
-
session_mode TEXT NOT NULL DEFAULT 'design',
|
|
24
|
-
created_at INTEGER NOT NULL,
|
|
25
|
-
updated_at INTEGER NOT NULL,
|
|
26
|
-
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_conv_project
|
|
30
|
-
ON conversations(project_id, updated_at DESC);
|
|
31
|
-
|
|
32
|
-
CREATE TABLE IF NOT EXISTS agent_sessions (
|
|
33
|
-
conversation_id TEXT NOT NULL,
|
|
34
|
-
agent_id TEXT NOT NULL,
|
|
35
|
-
session_id TEXT NOT NULL,
|
|
36
|
-
stable_prompt_hash TEXT,
|
|
37
|
-
-- Resume identity guard: the session is only safe to resume when the
|
|
38
|
-
-- conversation has not changed shape under it. model/cwd are the runtime
|
|
39
|
-
-- identity the upstream session was created with; a change forces a fresh
|
|
40
|
-
-- session. last_message_id is the assistant message this session produced
|
|
41
|
-
-- on its last turn -- if it is no longer the latest completed assistant
|
|
42
|
-
-- turn (another agent ran in between, or it was edited away), the session
|
|
43
|
-
-- is behind and we reseed the full transcript.
|
|
44
|
-
model TEXT,
|
|
45
|
-
cwd TEXT,
|
|
46
|
-
last_message_id TEXT,
|
|
47
|
-
updated_at INTEGER NOT NULL,
|
|
48
|
-
PRIMARY KEY (conversation_id, agent_id),
|
|
49
|
-
FOREIGN KEY(conversation_id) REFERENCES conversations(id) ON DELETE CASCADE
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
CREATE TABLE IF NOT EXISTS messages (
|
|
53
|
-
id TEXT PRIMARY KEY,
|
|
54
|
-
conversation_id TEXT NOT NULL,
|
|
55
|
-
role TEXT NOT NULL,
|
|
56
|
-
content TEXT NOT NULL,
|
|
57
|
-
agent_id TEXT,
|
|
58
|
-
agent_name TEXT,
|
|
59
|
-
events_json TEXT,
|
|
60
|
-
attachments_json TEXT,
|
|
61
|
-
run_context_json TEXT,
|
|
62
|
-
session_mode TEXT,
|
|
63
|
-
run_id TEXT,
|
|
64
|
-
run_status TEXT,
|
|
65
|
-
last_run_event_id TEXT,
|
|
66
|
-
telemetry_finalized_at INTEGER,
|
|
67
|
-
started_at INTEGER,
|
|
68
|
-
ended_at INTEGER,
|
|
69
|
-
position INTEGER NOT NULL,
|
|
70
|
-
created_at INTEGER NOT NULL,
|
|
71
|
-
FOREIGN KEY(conversation_id) REFERENCES conversations(id) ON DELETE CASCADE
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
CREATE INDEX IF NOT EXISTS idx_messages_conv
|
|
75
|
-
ON messages(conversation_id, position);
|
|
76
|
-
`);
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=migrate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/db/schema/migrate.ts"],"names":[],"mappings":"AAsBA;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,EAAY;IAClC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEP,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/tool-catalog/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/tool-catalog/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module db/tool-catalog/tool-catalog
|
|
3
|
-
*
|
|
4
|
-
* A durable, searchable snapshot of a `ToolRegistry`'s public descriptors (id/description/
|
|
5
|
-
* inputSchema — never the handler or policy) — v0 of `ai-control-plane.md` §29 /
|
|
6
|
-
* `PROP-tool-catalog-discovery-2026-07-26.md`, scoped down for a first real end-to-end proof
|
|
7
|
-
* rather than the full design: no versioning, no principal narrowing, no provider indirection.
|
|
8
|
-
* Every row's id is still resolved against a live `ToolRegistry`/`ToolExecutor` at call time —
|
|
9
|
-
* this table only makes that id *discoverable* before the caller already knows it.
|
|
10
|
-
*
|
|
11
|
-
* Deliberately NOT wired into `schema/migrate.ts` — `migrate.ts`'s own header explains why
|
|
12
|
-
* (`capability_definitions`/`capability_executions` were added there 2026-07-24 and removed
|
|
13
|
-
* 2026-07-25 for having zero consumers in every daemon's database). `ensureToolCatalogTables`
|
|
14
|
-
* is called only by a host that actually seeds and queries this table, mirroring
|
|
15
|
-
* `@jini-ai/registry`'s `ensureRegistryTables` precedent — the same discipline, applied this time
|
|
16
|
-
* without reviving the earlier mistake of a table nothing reads.
|
|
17
|
-
*
|
|
18
|
-
* Ranking is **FTS5 + `bm25()`**, not `LIKE` — verified against this repo's own `better-sqlite3`
|
|
19
|
-
* build (FTS5 is compiled in). `PROP` §5.3 sequences `LIKE` first and treats FTS5 as a later
|
|
20
|
-
* swap once row counts justify it; at v0's actual row count (tens of tools) that swap costs
|
|
21
|
-
* nothing extra to do now, so there is no hand-rolled scorer to throw away later. `tool_catalog`
|
|
22
|
-
* is FTS5's external-content table (`content='tool_catalog', content_rowid='rowid'`) — the
|
|
23
|
-
* canonical row lives once, in a plain table any other query/dump tool can read; the FTS index is
|
|
24
|
-
* rebuilt wholesale on every reseed rather than kept in sync via triggers, since `reseedToolCatalog`
|
|
25
|
-
* already replaces the entire table in one transaction. Column weights (id 6x description, matching
|
|
26
|
-
* the asymmetry `examples/nlweb-demo`'s keyword-scoring spike measured) are passed to `bm25()` at
|
|
27
|
-
* query time, not baked into the index.
|
|
28
|
-
*/
|
|
29
|
-
import type { SqliteDb } from '../core/types.js';
|
|
30
|
-
export interface ToolCatalogEntry {
|
|
31
|
-
readonly id: string;
|
|
32
|
-
readonly description: string;
|
|
33
|
-
/** JSON-Schema-shaped, `unknown` for the same reason `@jini-ai/core`'s `ToolDescriptor.inputSchema` is — this table never parses or validates it. */
|
|
34
|
-
readonly inputSchema?: unknown;
|
|
35
|
-
/** `first-party | plugin | unverified` — carried into what a model sees, per `PROP` §7.1. Every entry seeded from an in-tree `ToolRegistry` today is `first-party`. */
|
|
36
|
-
readonly source: string;
|
|
37
|
-
}
|
|
38
|
-
export interface ToolCatalogSearchHit {
|
|
39
|
-
readonly id: string;
|
|
40
|
-
readonly description: string;
|
|
41
|
-
readonly source: string;
|
|
42
|
-
readonly score: number;
|
|
43
|
-
}
|
|
44
|
-
/** Idempotent. Safe to call repeatedly (`IF NOT EXISTS`), matching `migrate()`'s own convention. */
|
|
45
|
-
export declare function ensureToolCatalogTables(db: SqliteDb): void;
|
|
46
|
-
/**
|
|
47
|
-
* Replaces the entire catalog with `entries` in one transaction — this table is a *snapshot* of
|
|
48
|
-
* whatever `ToolRegistry` a host assembled at boot, not an independently-edited store (§7.2's
|
|
49
|
-
* "the agent may never write the catalog" holds trivially at v0: nothing here accepts writes
|
|
50
|
-
* from a run at all). A tool no longer registered — the id simply is not in `entries` — is gone
|
|
51
|
-
* from the snapshot on the next reseed, which is the correct behavior for an append-only
|
|
52
|
-
* `ToolRegistry`: this table can only ever lag it, never diverge from it.
|
|
53
|
-
*
|
|
54
|
-
* Rebuilds the FTS5 index wholesale afterward (`INSERT INTO tool_catalog_fts(tool_catalog_fts)
|
|
55
|
-
* VALUES('rebuild')`) rather than via triggers — correct and sufficient because every reseed
|
|
56
|
-
* already replaces 100% of the rows in the same transaction.
|
|
57
|
-
*/
|
|
58
|
-
export declare function reseedToolCatalog(db: SqliteDb, entries: readonly ToolCatalogEntry[], now?: number): void;
|
|
59
|
-
export declare function getToolCatalogEntry(db: SqliteDb, id: string): ToolCatalogEntry | null;
|
|
60
|
-
/**
|
|
61
|
-
* `PROP` §6.1's `search_tools`: candidates only, no schemas — loading schemas at search time is
|
|
62
|
-
* what blows the context budget. Never returns an empty-query "everything" page (§6.1's staged
|
|
63
|
-
* discovery loses its point if the first call already dumps the whole catalog).
|
|
64
|
-
*
|
|
65
|
-
* Terms are OR'd (`term1 OR term2 OR ...`), not FTS5's implicit AND, so a multi-word query still
|
|
66
|
-
* surfaces a tool matching only one significant word — the same behavior a hand-rolled
|
|
67
|
-
* any-term-scores scorer would give, but ranked by real BM25 instead of a hand-tuned weight sum.
|
|
68
|
-
*/
|
|
69
|
-
export declare function searchToolCatalog(db: SqliteDb, query: string, limit?: number): readonly ToolCatalogSearchHit[];
|
|
70
|
-
//# sourceMappingURL=tool-catalog.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-catalog.d.ts","sourceRoot":"","sources":["../../../src/db/tool-catalog/tool-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,qJAAqJ;IACrJ,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,uKAAuK;IACvK,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,oGAAoG;AACpG,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAiB1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,GAAG,SAAa,GAAG,IAAI,CAmB5G;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAWrF;AAOD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,SAAS,oBAAoB,EAAE,CAmB1G"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/** Idempotent. Safe to call repeatedly (`IF NOT EXISTS`), matching `migrate()`'s own convention. */
|
|
2
|
-
export function ensureToolCatalogTables(db) {
|
|
3
|
-
db.exec(`
|
|
4
|
-
CREATE TABLE IF NOT EXISTS tool_catalog (
|
|
5
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
6
|
-
description TEXT NOT NULL,
|
|
7
|
-
input_schema_json TEXT CHECK (input_schema_json IS NULL OR json_valid(input_schema_json)),
|
|
8
|
-
source TEXT NOT NULL DEFAULT 'first-party',
|
|
9
|
-
updated_at INTEGER NOT NULL
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS tool_catalog_fts USING fts5(
|
|
13
|
-
id,
|
|
14
|
-
description,
|
|
15
|
-
content='tool_catalog',
|
|
16
|
-
content_rowid='rowid'
|
|
17
|
-
);
|
|
18
|
-
`);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Replaces the entire catalog with `entries` in one transaction — this table is a *snapshot* of
|
|
22
|
-
* whatever `ToolRegistry` a host assembled at boot, not an independently-edited store (§7.2's
|
|
23
|
-
* "the agent may never write the catalog" holds trivially at v0: nothing here accepts writes
|
|
24
|
-
* from a run at all). A tool no longer registered — the id simply is not in `entries` — is gone
|
|
25
|
-
* from the snapshot on the next reseed, which is the correct behavior for an append-only
|
|
26
|
-
* `ToolRegistry`: this table can only ever lag it, never diverge from it.
|
|
27
|
-
*
|
|
28
|
-
* Rebuilds the FTS5 index wholesale afterward (`INSERT INTO tool_catalog_fts(tool_catalog_fts)
|
|
29
|
-
* VALUES('rebuild')`) rather than via triggers — correct and sufficient because every reseed
|
|
30
|
-
* already replaces 100% of the rows in the same transaction.
|
|
31
|
-
*/
|
|
32
|
-
export function reseedToolCatalog(db, entries, now = Date.now()) {
|
|
33
|
-
const replace = db.transaction((rows) => {
|
|
34
|
-
db.prepare('DELETE FROM tool_catalog').run();
|
|
35
|
-
const insert = db.prepare(`
|
|
36
|
-
INSERT INTO tool_catalog (id, description, input_schema_json, source, updated_at)
|
|
37
|
-
VALUES (?, ?, ?, ?, ?)
|
|
38
|
-
`);
|
|
39
|
-
for (const entry of rows) {
|
|
40
|
-
insert.run(entry.id, entry.description, entry.inputSchema === undefined ? null : JSON.stringify(entry.inputSchema), entry.source, now);
|
|
41
|
-
}
|
|
42
|
-
db.exec(`INSERT INTO tool_catalog_fts(tool_catalog_fts) VALUES('rebuild')`);
|
|
43
|
-
});
|
|
44
|
-
replace(entries);
|
|
45
|
-
}
|
|
46
|
-
export function getToolCatalogEntry(db, id) {
|
|
47
|
-
const row = db.prepare('SELECT id, description, input_schema_json, source FROM tool_catalog WHERE id = ?').get(id);
|
|
48
|
-
if (!row)
|
|
49
|
-
return null;
|
|
50
|
-
return {
|
|
51
|
-
id: row.id,
|
|
52
|
-
description: row.description,
|
|
53
|
-
source: row.source,
|
|
54
|
-
...(row.input_schema_json === null ? {} : { inputSchema: JSON.parse(row.input_schema_json) }),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/** Alphanumeric tokens only — deliberate: an FTS5 MATCH string built from these can never contain FTS5 query-syntax operators (`"`, `*`, `NOT`, `NEAR`, column filters), so a query string is never treated as anything but plain terms. */
|
|
58
|
-
function tokenize(text) {
|
|
59
|
-
return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* `PROP` §6.1's `search_tools`: candidates only, no schemas — loading schemas at search time is
|
|
63
|
-
* what blows the context budget. Never returns an empty-query "everything" page (§6.1's staged
|
|
64
|
-
* discovery loses its point if the first call already dumps the whole catalog).
|
|
65
|
-
*
|
|
66
|
-
* Terms are OR'd (`term1 OR term2 OR ...`), not FTS5's implicit AND, so a multi-word query still
|
|
67
|
-
* surfaces a tool matching only one significant word — the same behavior a hand-rolled
|
|
68
|
-
* any-term-scores scorer would give, but ranked by real BM25 instead of a hand-tuned weight sum.
|
|
69
|
-
*/
|
|
70
|
-
export function searchToolCatalog(db, query, limit = 10) {
|
|
71
|
-
const terms = tokenize(query);
|
|
72
|
-
if (terms.length === 0)
|
|
73
|
-
return [];
|
|
74
|
-
const matchExpr = terms.join(' OR ');
|
|
75
|
-
const rows = db
|
|
76
|
-
.prepare(`SELECT tc.id, tc.description, tc.source, bm25(tool_catalog_fts, 6.0, 1.0) AS rank
|
|
77
|
-
FROM tool_catalog_fts
|
|
78
|
-
JOIN tool_catalog tc ON tc.rowid = tool_catalog_fts.rowid
|
|
79
|
-
WHERE tool_catalog_fts MATCH ?
|
|
80
|
-
ORDER BY rank
|
|
81
|
-
LIMIT ?`)
|
|
82
|
-
.all(matchExpr, limit);
|
|
83
|
-
// bm25() returns a cost (smaller/more-negative = better match); invert to a positive score so
|
|
84
|
-
// callers see "higher is better", matching every other ranked-result convention in this repo.
|
|
85
|
-
return rows.map((row) => ({ id: row.id, description: row.description, source: row.source, score: -row.rank }));
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=tool-catalog.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-catalog.js","sourceRoot":"","sources":["../../../src/db/tool-catalog/tool-catalog.ts"],"names":[],"mappings":"AA8CA,oGAAoG;AACpG,MAAM,UAAU,uBAAuB,CAAC,EAAY;IAClD,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;GAeP,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAY,EAAE,OAAoC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACpG,MAAM,OAAO,GAAG,EAAE,CAAC,WAA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