@deepseek-ai/dsh-session-query-sqlite 0.0.1-rc.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/LICENSE +28 -0
- package/README.i18n.yaml +6 -0
- package/README.md +57 -0
- package/README.zh.md +57 -0
- package/lib/index.js +1129 -0
- package/lib/invariant.js +23 -0
- package/lib/types/index.d.ts +103 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/query.d.ts +106 -0
- package/lib/types/schema.d.ts +16 -0
- package/package.json +58 -0
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-session-query-sqlite`.
|
|
4
|
+
* @module @deepseek-ai/dsh-session-query-sqlite/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-session-query-sqlite";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "session-query-sqlite-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: reconciliation, cursor generations, and derived-index
|
|
13
|
+
* ownership are validated at each serialized query boundary.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => {};
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concrete session-query service with SQLite FTS5 over the live-preferred corpus.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-session-query-sqlite
|
|
5
|
+
*/
|
|
6
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
7
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
|
+
import SessionQueryService from '@deepseek-ai/dsh-session-query';
|
|
9
|
+
import type { Config as SessionQueryConfig, SessionEventSearchPage, SessionEventSearchRequest, SessionSearchExecContext, SessionSearchHit, SessionSearchPage, SessionSearchRequest } from '@deepseek-ai/dsh-session-query';
|
|
10
|
+
import { type JournalMode } from './schema.ts';
|
|
11
|
+
export { SESSION_QUERY_SQLITE_APPLICATION_ID, SESSION_QUERY_SQLITE_SCHEMA_VERSION, type JournalMode, } from './schema.ts';
|
|
12
|
+
/** Boot-context slot for a launcher-owned absolute path to this process's derived query index. */
|
|
13
|
+
export declare const SESSION_QUERY_SQLITE_PATH_KEY = "launcherSessionQueryPath";
|
|
14
|
+
declare module '@deepseek-ai/cordis' {
|
|
15
|
+
interface Context {
|
|
16
|
+
/** Launcher-owned absolute path to this process's disposable derived query index. */
|
|
17
|
+
launcherSessionQueryPath?: string;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Default result page size. */
|
|
21
|
+
export declare const SESSION_QUERY_SQLITE_DEFAULT_LIMIT = 20;
|
|
22
|
+
/** Maximum accepted result page size. */
|
|
23
|
+
export declare const SESSION_QUERY_SQLITE_MAX_LIMIT = 100;
|
|
24
|
+
/** Default maximum snippet length in Unicode code points. */
|
|
25
|
+
export declare const SESSION_QUERY_SQLITE_SNIPPET_CHARS = 240;
|
|
26
|
+
/** SQLite module/handle opening phase. */
|
|
27
|
+
export type OpenAt = 'startup' | 'first-search';
|
|
28
|
+
/** Combined session-query configuration backed by SQLite full-text search. */
|
|
29
|
+
export interface Config extends SessionQueryConfig {
|
|
30
|
+
/**
|
|
31
|
+
* Dedicated derived-index path; `:memory:` is supported for ephemeral
|
|
32
|
+
* indexes. Missing directories and database files are created owner-only on
|
|
33
|
+
* POSIX filesystems; existing modes are preserved.
|
|
34
|
+
*/
|
|
35
|
+
path: string;
|
|
36
|
+
/** Open the SQLite module and handle at service activation or the first search. Defaults to `startup`. */
|
|
37
|
+
openAt?: OpenAt;
|
|
38
|
+
/** SQLite journal mode. Defaults to `wal`. */
|
|
39
|
+
journalMode?: JournalMode;
|
|
40
|
+
/** Page size when a request omits `limit`. At most `Number.MAX_SAFE_INTEGER - 1`; defaults to 20. */
|
|
41
|
+
defaultLimit?: number;
|
|
42
|
+
/** Largest accepted page size. At most `Number.MAX_SAFE_INTEGER - 1`; defaults to 100. */
|
|
43
|
+
maxLimit?: number;
|
|
44
|
+
/** Maximum snippet length in Unicode code points. Defaults to 240. */
|
|
45
|
+
snippetChars?: number;
|
|
46
|
+
/** Maximum concurrent persisted-log inspections in one inherited batch read. Defaults to 4. */
|
|
47
|
+
persistedInspectConcurrency?: number;
|
|
48
|
+
}
|
|
49
|
+
interface ResolvedConfig {
|
|
50
|
+
path: string;
|
|
51
|
+
openAt: OpenAt;
|
|
52
|
+
journalMode: JournalMode;
|
|
53
|
+
defaultLimit: number;
|
|
54
|
+
maxLimit: number;
|
|
55
|
+
snippetChars: number;
|
|
56
|
+
readWindowMax: number;
|
|
57
|
+
persistedInspectConcurrency: number;
|
|
58
|
+
}
|
|
59
|
+
/** Concrete SQLite owner of the combined `ctx.sessionQuery` service. */
|
|
60
|
+
export declare class SessionQuerySqlite extends SessionQueryService {
|
|
61
|
+
static inject: string[];
|
|
62
|
+
static Config: z<Config>;
|
|
63
|
+
/** Validated and defaulted backend configuration. */
|
|
64
|
+
readonly config: ResolvedConfig;
|
|
65
|
+
private readonly _instance;
|
|
66
|
+
private _ready;
|
|
67
|
+
private _db;
|
|
68
|
+
private _persistenceBinding;
|
|
69
|
+
private _lastPersistenceIdentity;
|
|
70
|
+
private _persistenceEpoch;
|
|
71
|
+
private _globalGeneration;
|
|
72
|
+
private _localGeneration;
|
|
73
|
+
private _tail;
|
|
74
|
+
private _closed;
|
|
75
|
+
private _closePromise;
|
|
76
|
+
private readonly _optionalPersistenceFiber;
|
|
77
|
+
constructor(ctx: Context, config: Config);
|
|
78
|
+
/** Open eagerly only when activation owns the configured readiness boundary. */
|
|
79
|
+
protected [Service.init](): Promise<void>;
|
|
80
|
+
searchSessions(request: SessionSearchRequest, exec?: SessionSearchExecContext): Promise<SessionSearchPage<SessionSearchHit>>;
|
|
81
|
+
searchEvents(request: SessionEventSearchRequest, exec?: SessionSearchExecContext): Promise<SessionEventSearchPage>;
|
|
82
|
+
/** Close the database after every accepted operation reaches quiescence. */
|
|
83
|
+
close(): Promise<void>;
|
|
84
|
+
private _close;
|
|
85
|
+
private _open;
|
|
86
|
+
private _ensureReady;
|
|
87
|
+
private _serialized;
|
|
88
|
+
private _reconcile;
|
|
89
|
+
private _observeStable;
|
|
90
|
+
private _mainGeneration;
|
|
91
|
+
private _deleteSession;
|
|
92
|
+
private _replacePersistedSession;
|
|
93
|
+
private _replaceLiveSession;
|
|
94
|
+
private _querySessions;
|
|
95
|
+
private _queryEvents;
|
|
96
|
+
private _targetObservation;
|
|
97
|
+
private _sessionHit;
|
|
98
|
+
private _eventHit;
|
|
99
|
+
private _requireDb;
|
|
100
|
+
private _isClosed;
|
|
101
|
+
}
|
|
102
|
+
export default SessionQuerySqlite;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-session-query-sqlite`.
|
|
3
|
+
* @module @deepseek-ai/dsh-session-query-sqlite/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "session-query-sqlite-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** Request normalization, parameterized predicates, and result presentation. */
|
|
2
|
+
import type { SessionEventMetadataFilter, SessionEventSearchRequest, SessionResultFilter, SessionSearchCursor, SessionSearchRequest } from '@deepseek-ai/dsh-session-query';
|
|
3
|
+
/** Collision-free marker inserted before an FTS5 match by `highlight()`. */
|
|
4
|
+
export declare const FTS_HIGHLIGHT_START = "\uFDD0";
|
|
5
|
+
/** Collision-free marker inserted after an FTS5 match by `highlight()`. */
|
|
6
|
+
export declare const FTS_HIGHLIGHT_END = "\uFDD1";
|
|
7
|
+
/** Largest page size whose internal lookahead remains an exact SQLite integer binding. */
|
|
8
|
+
export declare const SQLITE_MAX_PAGE_LIMIT: number;
|
|
9
|
+
/** Portable host-parameter ceiling shared by predicate and statement builders. */
|
|
10
|
+
export declare const SQLITE_PORTABLE_VARIABLE_LIMIT = 32766;
|
|
11
|
+
/** Supported outer-predicate budget that keeps SQLite FTS5 MATCH usable. */
|
|
12
|
+
export declare const SQLITE_FTS5_OUTER_PREDICATE_LIMIT = 14;
|
|
13
|
+
/**
|
|
14
|
+
* Reject prospective SQLite binding growth beyond the portable ceiling.
|
|
15
|
+
* @param count - binding count at the current construction boundary.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertPortableBindingCount(count: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Reject compiled outer predicates beyond the supported FTS5 planner budget.
|
|
20
|
+
* @param count - predicate count including fixed statement predicates.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertFts5OuterPredicateCount(count: number): void;
|
|
23
|
+
/** Limit defaults needed to normalize a search request. */
|
|
24
|
+
export interface QueryLimits {
|
|
25
|
+
/** Page size used when the request omits one. */
|
|
26
|
+
defaultLimit: number;
|
|
27
|
+
/** Largest accepted page size. */
|
|
28
|
+
maxLimit: number;
|
|
29
|
+
}
|
|
30
|
+
/** Normalized cross-session request. */
|
|
31
|
+
export interface NormalizedSessionRequest {
|
|
32
|
+
query: string;
|
|
33
|
+
sessionFilters: readonly SessionResultFilter[];
|
|
34
|
+
eventFilters: readonly SessionEventMetadataFilter[];
|
|
35
|
+
limit: number;
|
|
36
|
+
cursor?: SessionSearchCursor;
|
|
37
|
+
}
|
|
38
|
+
/** Normalized within-session request. */
|
|
39
|
+
export interface NormalizedEventRequest {
|
|
40
|
+
sessionId: SessionEventSearchRequest['sessionId'];
|
|
41
|
+
query: string;
|
|
42
|
+
filters: readonly SessionEventMetadataFilter[];
|
|
43
|
+
limit: number;
|
|
44
|
+
cursor?: SessionSearchCursor;
|
|
45
|
+
}
|
|
46
|
+
/** Parameterized SQL predicate fragment. */
|
|
47
|
+
export interface SqlWhere {
|
|
48
|
+
/** SQL without the leading `WHERE`. */
|
|
49
|
+
sql: string;
|
|
50
|
+
/** Bindings in placeholder order. */
|
|
51
|
+
params: Array<string | number>;
|
|
52
|
+
/** Number of compiled predicates in `sql`. */
|
|
53
|
+
predicateCount: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate and canonicalize a cross-session request.
|
|
57
|
+
* @param request - caller-provided query, filters, limit, and cursor.
|
|
58
|
+
* @param limits - configured default and maximum page sizes.
|
|
59
|
+
* @returns normalized request with explicit arrays and limit.
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizeSessionRequest(request: SessionSearchRequest, limits: QueryLimits): NormalizedSessionRequest;
|
|
62
|
+
/**
|
|
63
|
+
* Validate and canonicalize a within-session request.
|
|
64
|
+
* @param request - caller-provided target, query, filters, limit, and cursor.
|
|
65
|
+
* @param limits - configured default and maximum page sizes.
|
|
66
|
+
* @returns normalized request with an explicit filter array and limit.
|
|
67
|
+
*/
|
|
68
|
+
export declare function normalizeEventRequest(request: SessionEventSearchRequest, limits: QueryLimits): NormalizedEventRequest;
|
|
69
|
+
/**
|
|
70
|
+
* Compile logical-session predicates against selected-document columns.
|
|
71
|
+
* @param filters - validated ANDed logical-session clauses.
|
|
72
|
+
* @returns parameterized SQL fragment and ordered bindings.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildSessionWhere(filters: readonly SessionResultFilter[]): SqlWhere;
|
|
75
|
+
/**
|
|
76
|
+
* Compile event metadata predicates against selected-document columns.
|
|
77
|
+
* @param filters - validated ANDed event metadata clauses.
|
|
78
|
+
* @returns parameterized SQL fragment and ordered bindings.
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildEventWhere(filters: readonly SessionEventMetadataFilter[]): SqlWhere;
|
|
81
|
+
/**
|
|
82
|
+
* Quote caller text as one FTS5 phrase so query syntax remains inert data.
|
|
83
|
+
* @param query - normalized caller query.
|
|
84
|
+
* @returns FTS5 expression containing one escaped literal phrase.
|
|
85
|
+
*/
|
|
86
|
+
export declare function quoteFtsData(query: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Remove reserved marker collisions before text enters FTS5 or MATCH.
|
|
89
|
+
* @param text - extracted document text or normalized caller query.
|
|
90
|
+
* @returns text with reserved noncharacters mapped to replacement characters.
|
|
91
|
+
*/
|
|
92
|
+
export declare function sanitizeFtsText(text: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Build the stable normalized request identity stored in opaque cursors.
|
|
95
|
+
* @param request - normalized request whose filter ordering is canonicalized.
|
|
96
|
+
* @returns deterministic JSON identity for cursor binding.
|
|
97
|
+
*/
|
|
98
|
+
export declare function requestFingerprint(request: NormalizedSessionRequest | NormalizedEventRequest): string;
|
|
99
|
+
/**
|
|
100
|
+
* Build a whitespace-normalized excerpt no longer than `maxChars`.
|
|
101
|
+
* @param markedText - complete document with FTS5 `highlight()` markers.
|
|
102
|
+
* @param maxChars - maximum result length in Unicode code points.
|
|
103
|
+
* @returns bounded plain-text snippet.
|
|
104
|
+
*/
|
|
105
|
+
export declare function makeSnippet(markedText: string, maxChars: number): string;
|
|
106
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** SQLite schema for the disposable session full-text read model. */
|
|
2
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
/** Current derived-index schema version. Incompatible versions reset in place. */
|
|
4
|
+
export declare const SESSION_QUERY_SQLITE_SCHEMA_VERSION = 8;
|
|
5
|
+
/** SQLite application id protecting unrelated databases from derived resets. */
|
|
6
|
+
export declare const SESSION_QUERY_SQLITE_APPLICATION_ID = 1146308689;
|
|
7
|
+
/** Supported SQLite journal modes. */
|
|
8
|
+
export type JournalMode = 'wal' | 'delete' | 'truncate' | 'persist';
|
|
9
|
+
/**
|
|
10
|
+
* Open, validate, and initialize persistent and connection-local schemas.
|
|
11
|
+
* @param path - dedicated derived-index path or `:memory:`; missing filesystem paths are created owner-only.
|
|
12
|
+
* @param journalMode - validated SQLite journal mode.
|
|
13
|
+
* @returns initialized database handle owned by the search service.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openSearchDatabase(path: string, journalMode: JournalMode): Promise<DatabaseSync>;
|
|
16
|
+
//# sourceMappingURL=schema.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-session-query-sqlite",
|
|
3
|
+
"description": "Concrete ctx.sessionQuery backend with SQLite FTS5 search",
|
|
4
|
+
"version": "0.0.1-rc.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/session-query/session-query-sqlite"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./src/*": "./src/*",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib/index.js",
|
|
30
|
+
"lib/invariant.js",
|
|
31
|
+
"lib/types/**/*.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"license": "BSD-3-Clause",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
36
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
37
|
+
"@deepseek-ai/dsh-session-persistence": "^0.0.1-rc.1",
|
|
38
|
+
"@deepseek-ai/dsh-session-query": "^0.0.1-rc.1",
|
|
39
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@deepseek-ai/dsh-session-persistence": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@deepseek-ai/schemastery": "^3.18.1-rc.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@deepseek-ai/cordis-plugin-loader": "^1.0.1-rc.1",
|
|
51
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-session-persistence": "^0.0.1-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-session-persistence-sqlite": "^0.0.1-rc.1",
|
|
54
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-session-query": "^0.0.1-rc.1",
|
|
56
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
57
|
+
}
|
|
58
|
+
}
|