@x1a0f3n9/dsh-session-query 0.1.5-alpha.2
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 +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +167 -0
- package/README.zh.md +167 -0
- package/lib/index.js +1234 -0
- package/lib/types/cold-read.d.ts +27 -0
- package/lib/types/config.d.ts +29 -0
- package/lib/types/corpus.d.ts +66 -0
- package/lib/types/cursor.d.ts +11 -0
- package/lib/types/documents.d.ts +18 -0
- package/lib/types/extraction.d.ts +12 -0
- package/lib/types/filters.d.ts +35 -0
- package/lib/types/index.d.ts +155 -0
- package/lib/types/observation.d.ts +85 -0
- package/lib/types/sources.d.ts +9 -0
- package/lib/types/tracing.d.ts +33 -0
- package/lib/types/types.d.ts +265 -0
- package/package.json +62 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One-shot cold session read through the handle-based persistence seam. */
|
|
2
|
+
import type { SessionEvent, SessionHeader, SessionId, SessionLogOffset, SessionSeedEventState } from '@x1a0f3n9/dsh-session';
|
|
3
|
+
import type SessionPersistence from '@x1a0f3n9/dsh-session-persistence';
|
|
4
|
+
/** A stored session log balanced for read-only viewing. */
|
|
5
|
+
export interface ColdSessionLog {
|
|
6
|
+
/** Aliasing state of the persisted events; synthetic closers are locally owned. */
|
|
7
|
+
readonly eventState: SessionSeedEventState;
|
|
8
|
+
/** The stored header, fixed when the read handle opened. */
|
|
9
|
+
readonly header: SessionHeader;
|
|
10
|
+
/** Exact fork-inherited event count paired with {@link header}. */
|
|
11
|
+
readonly inheritedEventCount: SessionLogOffset;
|
|
12
|
+
/** Stored events plus deterministic in-memory closers for an interrupted final turn; nothing is written back. */
|
|
13
|
+
readonly events: SessionEvent[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read one complete stored session log without taking ownership or mutating
|
|
17
|
+
* storage: open a read handle, read the validated contiguous log, close the
|
|
18
|
+
* handle, and append `interruptedTurnClosers` so a log whose writer crashed
|
|
19
|
+
* mid-turn folds as a balanced transcript. Backend failures propagate
|
|
20
|
+
* unmapped — each caller owns its error taxonomy.
|
|
21
|
+
* @param persistence - the mounted persistence service.
|
|
22
|
+
* @param sessionId - the stored session to read.
|
|
23
|
+
* @param signal - optional cancellation for the open and read work.
|
|
24
|
+
* @returns an adoptable seed in a caller-owned outer array, ready for in-place Session restoration.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readColdSessionLog(persistence: SessionPersistence, sessionId: SessionId, signal?: AbortSignal): Promise<ColdSessionLog>;
|
|
27
|
+
//# sourceMappingURL=cold-read.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Public configuration and typed failures for the combined session-query service. */
|
|
2
|
+
import { HarnessError } from '@x1a0f3n9/dsh-llm';
|
|
3
|
+
/** Default maximum `before`/`after` raw-event window. */
|
|
4
|
+
export declare const SESSION_QUERY_READ_WINDOW_MAX = 50;
|
|
5
|
+
/** Default maximum number of concurrent persisted-log reads in one batch read. */
|
|
6
|
+
export declare const SESSION_QUERY_DEFAULT_PERSISTED_INSPECT_CONCURRENCY = 4;
|
|
7
|
+
/** Default maximum number of cold prepared-Session observations retained for reuse. */
|
|
8
|
+
export declare const SESSION_QUERY_DEFAULT_PREPARED_SESSION_CACHE_SIZE = 5;
|
|
9
|
+
/** Backend-independent configuration inherited by every session-query implementation. */
|
|
10
|
+
export interface Config {
|
|
11
|
+
/** Maximum accepted raw read context on either side. Defaults to 50. */
|
|
12
|
+
readWindowMax?: number;
|
|
13
|
+
/** Maximum concurrent persisted-log reads in one batch read. Defaults to 4. */
|
|
14
|
+
persistedReadConcurrency?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum cold prepared-Session observations retained for reuse, keyed by
|
|
17
|
+
* durable revision. Entries pinned by active observation leases do not count
|
|
18
|
+
* against this bound until released. Defaults to 5.
|
|
19
|
+
*/
|
|
20
|
+
preparedSessionCacheSize?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Stable machine-routable failure taxonomy for session reads, traces, and search. */
|
|
23
|
+
export type SessionQueryErrorCode = 'SESSION_QUERY_ABORTED' | 'SESSION_QUERY_CORRUPT_SESSION' | 'SESSION_QUERY_EVENT_NOT_FOUND' | 'SESSION_QUERY_INDEX_FAILED' | 'SESSION_QUERY_INVALID_CONFIG' | 'SESSION_QUERY_INVALID_CURSOR' | 'SESSION_QUERY_INVALID_FILTER' | 'SESSION_QUERY_INVALID_LIMIT' | 'SESSION_QUERY_INVALID_QUERY' | 'SESSION_QUERY_INVALID_LINEAGE' | 'SESSION_QUERY_INVALID_SURFACE' | 'SESSION_QUERY_INVALID_WINDOW' | 'SESSION_QUERY_PERSISTENCE_FAILED' | 'SESSION_QUERY_SEARCH_DISABLED' | 'SESSION_QUERY_SESSION_NOT_FOUND' | 'SESSION_QUERY_STALE_CURSOR' | 'SESSION_QUERY_SOURCE_CONFLICT';
|
|
24
|
+
/** Typed session-query failure whose `code` is one closed taxonomy member. */
|
|
25
|
+
export declare class SessionQueryError extends HarnessError {
|
|
26
|
+
readonly code: SessionQueryErrorCode;
|
|
27
|
+
constructor(message: string, code: SessionQueryErrorCode, options?: ErrorOptions);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Live/persisted logical-corpus resolution for session-query. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { SessionEvent, SessionHeader, SessionId, SessionLogOffset } from '@x1a0f3n9/dsh-session';
|
|
4
|
+
import type { SessionRecord } from './types.ts';
|
|
5
|
+
/** Detached source selected for one exact read. */
|
|
6
|
+
export interface LogicalSession {
|
|
7
|
+
/** Cloned source header. */
|
|
8
|
+
header: SessionHeader;
|
|
9
|
+
/** Exact fork-inherited event count paired with {@link header}. */
|
|
10
|
+
inheritedEventCount: SessionLogOffset;
|
|
11
|
+
/** Cloned raw event log. */
|
|
12
|
+
events: SessionEvent[];
|
|
13
|
+
}
|
|
14
|
+
/** Borrowed source visible only during one synchronous batch projection. */
|
|
15
|
+
export interface LogicalSessionSource {
|
|
16
|
+
/** Header selected with `events`; callers must clone retained output. */
|
|
17
|
+
readonly header: SessionHeader;
|
|
18
|
+
/** Raw events selected with `header`; valid only for the projection call. */
|
|
19
|
+
readonly events: readonly SessionEvent[];
|
|
20
|
+
}
|
|
21
|
+
/** One source-projection result in a batch logical-corpus observation. */
|
|
22
|
+
export type LogicalProjectionResult<Value> = {
|
|
23
|
+
sessionId: SessionId;
|
|
24
|
+
status: 'fulfilled';
|
|
25
|
+
value: Value;
|
|
26
|
+
} | {
|
|
27
|
+
sessionId: SessionId;
|
|
28
|
+
status: 'rejected';
|
|
29
|
+
reason: unknown;
|
|
30
|
+
};
|
|
31
|
+
/** Resolves a live-preferred corpus against the persistence service mounted now. */
|
|
32
|
+
export declare class SessionCorpus {
|
|
33
|
+
private readonly _ctx;
|
|
34
|
+
private readonly _persistedReadConcurrency;
|
|
35
|
+
private _persistence;
|
|
36
|
+
private readonly _optionalPersistenceFiber;
|
|
37
|
+
constructor(_ctx: Context, _persistedReadConcurrency: number);
|
|
38
|
+
/**
|
|
39
|
+
* List the complete logical corpus with live precedence and cloned headers.
|
|
40
|
+
* @param signal - optional cancellation for persistence listing.
|
|
41
|
+
* @returns records in deterministic newest-first order.
|
|
42
|
+
*/
|
|
43
|
+
listSessions(signal?: AbortSignal): Promise<SessionRecord[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Load one logical source, preferring a detached live snapshot.
|
|
46
|
+
*
|
|
47
|
+
* A known live target never consults persistence, so an optional backend's
|
|
48
|
+
* failure cannot make current in-memory history unreadable.
|
|
49
|
+
* @param sessionId - session to resolve.
|
|
50
|
+
* @param signal - optional cancellation for persisted source resolution.
|
|
51
|
+
* @returns detached live-preferred header and events.
|
|
52
|
+
*/
|
|
53
|
+
load(sessionId: SessionId, signal?: AbortSignal): Promise<LogicalSession>;
|
|
54
|
+
/**
|
|
55
|
+
* Project unique logical sources immediately from one persistence listing.
|
|
56
|
+
*
|
|
57
|
+
* The synchronous projector runs before a persisted worker claims its next id.
|
|
58
|
+
* Full logs are borrowed only for that call and never retained by the batch.
|
|
59
|
+
* @param sessionIds - sessions to resolve in first-occurrence order.
|
|
60
|
+
* @param project - synchronous fold that owns/clones every retained value.
|
|
61
|
+
* @param signal - cancellation shared by listing and every persisted inspection.
|
|
62
|
+
* @returns one fulfilled or rejected projected result per unique requested id.
|
|
63
|
+
*/
|
|
64
|
+
projectMany<Value>(sessionIds: readonly SessionId[], project: (source: LogicalSessionSource) => Value, signal?: AbortSignal): Promise<LogicalProjectionResult<Value>[]>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=corpus.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Opaque cursor identity for session-search pagination. */
|
|
2
|
+
import type { Branded } from '@x1a0f3n9/dsh-brand';
|
|
3
|
+
/** Provider-owned opaque continuation token returned by session search. */
|
|
4
|
+
export type SessionSearchCursor = Branded<'SessionSearchCursor'>;
|
|
5
|
+
/**
|
|
6
|
+
* Brand an encoded provider cursor for the public search contract.
|
|
7
|
+
* @param value - opaque encoded cursor value.
|
|
8
|
+
* @returns the same runtime string with session-search cursor identity.
|
|
9
|
+
*/
|
|
10
|
+
export declare function SessionSearchCursor(value: string): SessionSearchCursor;
|
|
11
|
+
//# sourceMappingURL=cursor.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Shared event metadata and semantic-document projection. */
|
|
2
|
+
import type { SessionEvent, SessionId } from '@x1a0f3n9/dsh-session';
|
|
3
|
+
import type { SessionEventRecord, SessionEventSearchDocument } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Project a raw log into lightweight surface-aware event records.
|
|
6
|
+
* @param sessionId - session that owns the log.
|
|
7
|
+
* @param events - complete contiguous raw event log.
|
|
8
|
+
* @returns one record per event in ascending seq order.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildSessionEventRecords(sessionId: SessionId, events: readonly SessionEvent[]): SessionEventRecord[];
|
|
11
|
+
/**
|
|
12
|
+
* Build first-party semantic documents for one complete raw event log.
|
|
13
|
+
* @param sessionId - session that owns the log.
|
|
14
|
+
* @param events - complete contiguous raw event log.
|
|
15
|
+
* @returns searchable documents in ascending seq order; structural events are omitted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildSessionEventSearchDocuments(sessionId: SessionId, events: readonly SessionEvent[]): SessionEventSearchDocument[];
|
|
18
|
+
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** First-party semantic text extraction for session-query consumers. */
|
|
2
|
+
import type { SessionEvent } from '@x1a0f3n9/dsh-session';
|
|
3
|
+
/**
|
|
4
|
+
* Extract searchable semantic text from one first-party session event.
|
|
5
|
+
*
|
|
6
|
+
* Structural boundaries, embedded raw streams, request envelopes, and unknown
|
|
7
|
+
* declaration-merged events contribute no text.
|
|
8
|
+
* @param event - event to inspect.
|
|
9
|
+
* @returns newline-joined semantic text, or an empty string when non-searchable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractSessionEventText(event: SessionEvent): string;
|
|
12
|
+
//# sourceMappingURL=extraction.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Pure provider-independent predicates for logical sessions and event text. */
|
|
2
|
+
import type { SessionEventResultFilter, SessionEventSearchDocument, SessionRecord, SessionResultFilter } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Apply ANDed logical-session filters while preserving input order.
|
|
5
|
+
* @param records - detached logical-session records to inspect.
|
|
6
|
+
* @param filters - clauses whose list values are ORed within each clause.
|
|
7
|
+
* @returns records accepted by every clause.
|
|
8
|
+
*/
|
|
9
|
+
export declare function filterSessionResults<T extends SessionRecord>(records: readonly T[], filters?: readonly SessionResultFilter[]): T[];
|
|
10
|
+
/**
|
|
11
|
+
* Apply ANDed event filters to extracted semantic documents.
|
|
12
|
+
* @param documents - semantic documents produced by {@link buildSessionEventSearchDocuments}.
|
|
13
|
+
* @param filters - metadata and literal-text predicates.
|
|
14
|
+
* @returns documents accepted by every clause, in input order.
|
|
15
|
+
*/
|
|
16
|
+
export declare function filterSessionEventDocuments<T extends SessionEventSearchDocument>(documents: readonly T[], filters?: readonly SessionEventResultFilter[]): T[];
|
|
17
|
+
/**
|
|
18
|
+
* Copy and validate logical-session filters before an asynchronous boundary.
|
|
19
|
+
* @param filters - caller-owned clauses to materialize.
|
|
20
|
+
* @returns detached validated clauses.
|
|
21
|
+
*/
|
|
22
|
+
export declare function materializeSessionResultFilters(filters: readonly SessionResultFilter[]): SessionResultFilter[];
|
|
23
|
+
/**
|
|
24
|
+
* Copy and validate event filters before an asynchronous boundary.
|
|
25
|
+
* @param filters - caller-owned clauses to materialize.
|
|
26
|
+
* @returns detached validated clauses.
|
|
27
|
+
*/
|
|
28
|
+
export declare function materializeSessionEventResultFilters(filters: readonly SessionEventResultFilter[]): SessionEventResultFilter[];
|
|
29
|
+
/**
|
|
30
|
+
* Compile a literal case-insensitive, whitespace-flexible semantic-text match.
|
|
31
|
+
* @param text - caller-provided literal text.
|
|
32
|
+
* @returns Unicode-aware regular expression safe from regex injection.
|
|
33
|
+
*/
|
|
34
|
+
export declare function compileSessionTextFilter(text: string): RegExp;
|
|
35
|
+
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Definition for combined session-history reads, traces, filters, and full-text search.
|
|
3
|
+
*
|
|
4
|
+
* @module @x1a0f3n9/dsh-session-query
|
|
5
|
+
*/
|
|
6
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
7
|
+
import { type SessionId } from '@x1a0f3n9/dsh-session';
|
|
8
|
+
import type { SessionTitleSnapshot } from '@x1a0f3n9/dsh-session-title';
|
|
9
|
+
import type { SessionEventResultFilter, SessionEventSearchPage, SessionEventReadRequest, SessionEventRecord, SessionEventSearchDocument, SessionEventSearchRequest, SessionEventTraceObservation, SessionEventTraceRequest, SessionEventWindow, SessionLineageTrace, SessionLogSnapshot, SessionRecord, SessionResultFilter, SessionSearchExecContext, SessionSearchHit, SessionSearchPage, SessionSearchRequest, SessionSurfaceSnapshot, SessionTitleObservation, SessionTitleObservationResult } from './types.ts';
|
|
10
|
+
import { type Config } from './config.ts';
|
|
11
|
+
import { type SessionObservation, type SessionObservationOptions } from './observation.ts';
|
|
12
|
+
export type * from './types.ts';
|
|
13
|
+
export { SessionSearchCursor } from './cursor.ts';
|
|
14
|
+
export type { Config, SessionQueryErrorCode } from './config.ts';
|
|
15
|
+
export { SESSION_QUERY_DEFAULT_PERSISTED_INSPECT_CONCURRENCY, SESSION_QUERY_DEFAULT_PREPARED_SESSION_CACHE_SIZE, SESSION_QUERY_READ_WINDOW_MAX, SessionQueryError, } from './config.ts';
|
|
16
|
+
export { readColdSessionLog } from './cold-read.ts';
|
|
17
|
+
export type { ColdSessionLog } from './cold-read.ts';
|
|
18
|
+
export { extractSessionEventText } from './extraction.ts';
|
|
19
|
+
export { buildSessionEventRecords, buildSessionEventSearchDocuments } from './documents.ts';
|
|
20
|
+
export { compileSessionTextFilter, filterSessionEventDocuments, filterSessionResults, materializeSessionEventResultFilters, materializeSessionResultFilters, } from './filters.ts';
|
|
21
|
+
export { assertSessionHeadersCompatible } from './sources.ts';
|
|
22
|
+
export type { SessionObservation, SessionObservationOptions } from './observation.ts';
|
|
23
|
+
declare module '@deepseek-ai/cordis' {
|
|
24
|
+
interface Context {
|
|
25
|
+
sessionQuery: SessionQueryEngine;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Unified live-preferred session query service.
|
|
30
|
+
*
|
|
31
|
+
* Exact reads, filters, and traces are backend-independent concrete behavior.
|
|
32
|
+
* A backend implements full-text observation, reconciliation, ranking, cursor
|
|
33
|
+
* generations, and query execution on the same `ctx.sessionQuery` service.
|
|
34
|
+
*/
|
|
35
|
+
export declare abstract class SessionQueryEngine extends Service {
|
|
36
|
+
static inject: string[];
|
|
37
|
+
private readonly _readWindowMax;
|
|
38
|
+
private readonly _corpus;
|
|
39
|
+
private readonly _observations;
|
|
40
|
+
constructor(ctx: Context, config?: Config);
|
|
41
|
+
/**
|
|
42
|
+
* Observe one exact live or prepared Session without a persistence listing preflight.
|
|
43
|
+
* @param sessionId - logical Session identity.
|
|
44
|
+
* @param options - cancellation and projection selection for this read.
|
|
45
|
+
* @returns a caller-owned observation lease.
|
|
46
|
+
*/
|
|
47
|
+
observeSession(sessionId: SessionId, options?: SessionObservationOptions): Promise<SessionObservation>;
|
|
48
|
+
/**
|
|
49
|
+
* Search the live-preferred logical corpus and group by session.
|
|
50
|
+
* @param request - query text, metadata filters, page size, and cursor.
|
|
51
|
+
* @param exec - optional cancellation control.
|
|
52
|
+
* @returns session hits ranked by their strongest matching event.
|
|
53
|
+
*/
|
|
54
|
+
abstract searchSessions(request: SessionSearchRequest, exec?: SessionSearchExecContext): Promise<SessionSearchPage<SessionSearchHit>>;
|
|
55
|
+
/**
|
|
56
|
+
* Search events within one live-preferred logical session.
|
|
57
|
+
* @param request - target session, query text, filters, page size, and cursor.
|
|
58
|
+
* @param exec - optional cancellation control.
|
|
59
|
+
* @returns matching event hits and their target header from one indexed generation.
|
|
60
|
+
*/
|
|
61
|
+
abstract searchEvents(request: SessionEventSearchRequest, exec?: SessionSearchExecContext): Promise<SessionEventSearchPage>;
|
|
62
|
+
/**
|
|
63
|
+
* List the complete logical corpus using live-preferred records.
|
|
64
|
+
* @param signal - optional cancellation for persistence listing.
|
|
65
|
+
* @returns deterministic newest-first cloned session records.
|
|
66
|
+
*/
|
|
67
|
+
listSessions(signal?: AbortSignal): Promise<SessionRecord[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Read and replay-validate one complete logical session log without making it live.
|
|
70
|
+
* @param sessionId - live or persisted session id to read.
|
|
71
|
+
* @returns cloned header and complete raw event log from one observation.
|
|
72
|
+
* @throws when persistence, header compatibility, or replay validation fails.
|
|
73
|
+
*/
|
|
74
|
+
readSession(sessionId: SessionId): Promise<SessionLogSnapshot>;
|
|
75
|
+
/**
|
|
76
|
+
* Filter the complete logical corpus with provider-independent predicates.
|
|
77
|
+
* @param filters - ANDed session metadata and availability clauses.
|
|
78
|
+
* @param signal - optional cancellation for persistence listing.
|
|
79
|
+
* @returns matching cloned records in deterministic newest-first order.
|
|
80
|
+
*/
|
|
81
|
+
filterSessions(filters: readonly SessionResultFilter[], signal?: AbortSignal): Promise<SessionRecord[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Fold the latest log-backed title from one live-preferred logical session.
|
|
84
|
+
* @param sessionId - live or persisted session id to read.
|
|
85
|
+
* @param signal - optional cancellation for source resolution and title folding.
|
|
86
|
+
* @returns latest title snapshot, or `undefined` when the log has no title event.
|
|
87
|
+
*/
|
|
88
|
+
readTitle(sessionId: SessionId, signal?: AbortSignal): Promise<SessionTitleSnapshot | undefined>;
|
|
89
|
+
/**
|
|
90
|
+
* Fold the latest title and return its source header from one corpus observation.
|
|
91
|
+
* @param sessionId - live or persisted session id to read.
|
|
92
|
+
* @param signal - optional cancellation for source resolution and title folding.
|
|
93
|
+
* @returns cloned source header and optional latest title snapshot.
|
|
94
|
+
*/
|
|
95
|
+
readTitleSnapshot(sessionId: SessionId, signal?: AbortSignal): Promise<SessionTitleObservation>;
|
|
96
|
+
/**
|
|
97
|
+
* Fold titles for unique sessions from one cancellable corpus observation.
|
|
98
|
+
*
|
|
99
|
+
* Results preserve first-occurrence input order. Operational failures stay
|
|
100
|
+
* isolated per session, while cancellation rejects the complete operation.
|
|
101
|
+
* @param sessionIds - live or persisted session ids to observe.
|
|
102
|
+
* @param signal - optional cancellation shared by all source reads.
|
|
103
|
+
* @returns one fulfilled or rejected result per unique requested id.
|
|
104
|
+
*/
|
|
105
|
+
readTitleSnapshots(sessionIds: readonly SessionId[], signal?: AbortSignal): Promise<SessionTitleObservationResult[]>;
|
|
106
|
+
/**
|
|
107
|
+
* List lightweight raw-log event records for one logical session.
|
|
108
|
+
* @param sessionId - live-preferred session id to read.
|
|
109
|
+
* @returns event records in ascending seq order.
|
|
110
|
+
*/
|
|
111
|
+
listEvents(sessionId: SessionId): Promise<SessionEventRecord[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Scan first-party semantic event documents with provider-independent filters.
|
|
114
|
+
* @param sessionId - live-preferred session id to scan.
|
|
115
|
+
* @param filters - ANDed metadata and literal-text predicates.
|
|
116
|
+
* @returns matching semantic documents in ascending seq order.
|
|
117
|
+
*/
|
|
118
|
+
filterEvents(sessionId: SessionId, filters: readonly SessionEventResultFilter[]): Promise<SessionEventSearchDocument[]>;
|
|
119
|
+
private _filterSessions;
|
|
120
|
+
private _filterEvents;
|
|
121
|
+
/**
|
|
122
|
+
* Read one session's complete current model surface from one corpus observation.
|
|
123
|
+
* @param sessionId - live-preferred session id to read.
|
|
124
|
+
* @returns cloned header, current surface, and the last sequence number included in the raw-log capture.
|
|
125
|
+
* @throws when source resolution fails or the session surface is invalid.
|
|
126
|
+
*/
|
|
127
|
+
readSurface(sessionId: SessionId): Promise<SessionSurfaceSnapshot>;
|
|
128
|
+
/**
|
|
129
|
+
* Trace known ancestry and descendants from one corpus observation.
|
|
130
|
+
* @param sessionId - logical session id to trace.
|
|
131
|
+
* @param signal - optional cancellation for persistence listing.
|
|
132
|
+
* @returns a complete lineage or the first parent that could not be resolved.
|
|
133
|
+
* @throws when corpus resolution fails, the target is absent, or its known ancestry cycles.
|
|
134
|
+
*/
|
|
135
|
+
traceSession(sessionId: SessionId, signal?: AbortSignal): Promise<SessionLineageTrace>;
|
|
136
|
+
/**
|
|
137
|
+
* Trace one event's direct positional replacements and cited source events.
|
|
138
|
+
* @param request - target session id and event seq.
|
|
139
|
+
* @param signal - optional cancellation for persisted source resolution.
|
|
140
|
+
* @returns source header, direct links, and the target's positional replacement chain.
|
|
141
|
+
* @throws when source resolution fails, the target is absent, or surface/source-event validation fails.
|
|
142
|
+
*/
|
|
143
|
+
traceEvent(request: SessionEventTraceRequest, signal?: AbortSignal): Promise<SessionEventTraceObservation>;
|
|
144
|
+
/**
|
|
145
|
+
* Read one full event plus a bounded raw-log context window.
|
|
146
|
+
* @param request - target session/seq and context sizes.
|
|
147
|
+
* @param signal - optional cancellation for persisted source resolution.
|
|
148
|
+
* @returns cloned target and neighboring events.
|
|
149
|
+
*/
|
|
150
|
+
readEvent(request: SessionEventReadRequest, signal?: AbortSignal): Promise<SessionEventWindow>;
|
|
151
|
+
private _readEvent;
|
|
152
|
+
private _readWindow;
|
|
153
|
+
}
|
|
154
|
+
export default SessionQueryEngine;
|
|
155
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Shared live/prepared observations for Session page and lifecycle consumers. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { SessionEvent, SessionHeader, SessionId, SessionLogOffset as SessionLogOffsetType, SessionSeqCursor } from '@x1a0f3n9/dsh-session';
|
|
4
|
+
import type { SessionPersistenceRevision } from '@x1a0f3n9/dsh-session-persistence';
|
|
5
|
+
import type { ProjectionSnapshot } from '@x1a0f3n9/dsh-session-projection';
|
|
6
|
+
/** One exact immutable Session cut retained for the caller's read lifetime. */
|
|
7
|
+
export interface SessionObservation extends Disposable {
|
|
8
|
+
/** Whether the cut came from an attached Session or a retained preparation. */
|
|
9
|
+
readonly source: 'live' | 'prepared';
|
|
10
|
+
/** Immutable Session identity metadata. */
|
|
11
|
+
readonly header: SessionHeader;
|
|
12
|
+
/** Exact fork-inherited event count paired with {@link header}. */
|
|
13
|
+
readonly inheritedEventCount: SessionLogOffsetType;
|
|
14
|
+
/**
|
|
15
|
+
* Immutable contiguous events at {@link cursor}. A live observation
|
|
16
|
+
* materializes this array on first read, so a consumer that reads only the
|
|
17
|
+
* header, cursor, or projections never copies the log.
|
|
18
|
+
*/
|
|
19
|
+
readonly events: readonly SessionEvent[];
|
|
20
|
+
/** Last observed event seq, or -1 for an empty log. */
|
|
21
|
+
readonly cursor: SessionSeqCursor;
|
|
22
|
+
/** Durable source revision for a cold prepared observation. */
|
|
23
|
+
readonly revision?: SessionPersistenceRevision;
|
|
24
|
+
/** Exact projection baseline at {@link cursor}, when the registry is mounted. */
|
|
25
|
+
readonly projections?: ProjectionSnapshot;
|
|
26
|
+
/**
|
|
27
|
+
* Retain the same immutable cut for another Host owner.
|
|
28
|
+
* @returns an independently disposable lease over this observation.
|
|
29
|
+
*/
|
|
30
|
+
retain(): SessionObservation;
|
|
31
|
+
}
|
|
32
|
+
/** Projection work and cancellation requested for one exact observation. */
|
|
33
|
+
export interface SessionObservationOptions {
|
|
34
|
+
/** Optional cancellation while resolving a cold source. */
|
|
35
|
+
readonly signal?: AbortSignal;
|
|
36
|
+
/** Whether to compute every projection or leave projection state untouched. */
|
|
37
|
+
readonly projectionMode?: 'all' | 'none';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Builds point observations without a corpus listing preflight.
|
|
41
|
+
*
|
|
42
|
+
* Cold reads are cached per session id, keyed by the persistence instance and
|
|
43
|
+
* the `stat` revision observed before the log read: an unchanged revision
|
|
44
|
+
* reuses the restored Session without re-reading the log. The cache is bounded
|
|
45
|
+
* (least-recently-used unpinned entries are evicted past the capacity), and
|
|
46
|
+
* entries pinned by active leases survive eviction and replacement — a lease's
|
|
47
|
+
* cut stays valid for the lease lifetime even after a newer revision lands.
|
|
48
|
+
*/
|
|
49
|
+
export declare class SessionObservationReader {
|
|
50
|
+
private readonly ctx;
|
|
51
|
+
private readonly cacheCapacity;
|
|
52
|
+
private readonly cache;
|
|
53
|
+
/**
|
|
54
|
+
* @param ctx - context carrying Session and optional persistence/projection services.
|
|
55
|
+
* @param cacheCapacity - maximum unpinned cold observations retained for reuse.
|
|
56
|
+
*/
|
|
57
|
+
constructor(ctx: Context, cacheCapacity?: number);
|
|
58
|
+
/**
|
|
59
|
+
* Observe one live-preferred Session and retain a cold preparation until disposal.
|
|
60
|
+
* @param sessionId - logical Session identity.
|
|
61
|
+
* @param options - cancellation and all-or-none projection computation for this read.
|
|
62
|
+
* @returns one exact immutable observation.
|
|
63
|
+
*/
|
|
64
|
+
read(sessionId: SessionId, options?: SessionObservationOptions): Promise<SessionObservation>;
|
|
65
|
+
/** Observe the stored snapshot, mapping absence and backend failures to the query taxonomy. */
|
|
66
|
+
private statSource;
|
|
67
|
+
/** Read the complete balanced cold log, mapping backend failures to the query taxonomy. */
|
|
68
|
+
private loadSource;
|
|
69
|
+
/** Return a still-valid cached entry and mark it most recently used. */
|
|
70
|
+
private cachedEntry;
|
|
71
|
+
/** Insert or replace the entry for one id, then evict past the capacity. */
|
|
72
|
+
private store;
|
|
73
|
+
/**
|
|
74
|
+
* Evict oldest unpinned entries until the cache fits its capacity again.
|
|
75
|
+
* Runs on store and whenever a lease release unpins an entry, so leases
|
|
76
|
+
* that pinned every candidate cannot leave the cache over budget for good.
|
|
77
|
+
* @param keep - the entry being stored, about to be leased; never evicted.
|
|
78
|
+
*/
|
|
79
|
+
private evictPastCapacity;
|
|
80
|
+
/** Build one disposable lease over a cached entry, pinning it until every lease releases. */
|
|
81
|
+
private preparedLease;
|
|
82
|
+
private live;
|
|
83
|
+
private preparedProjections;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Shared immutable-header checks for logical session source observers. */
|
|
2
|
+
import type { SessionHeader } from '@x1a0f3n9/dsh-session';
|
|
3
|
+
/**
|
|
4
|
+
* Reject incompatible observations of one logical session source.
|
|
5
|
+
* @param a - first live, listed, or loaded header observation.
|
|
6
|
+
* @param b - second header observation expected to identify the same source.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertSessionHeadersCompatible(a: SessionHeader, b: SessionHeader): void;
|
|
9
|
+
//# sourceMappingURL=sources.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** One-shot session-lineage and event-relationship tracing helpers. */
|
|
2
|
+
import type { SessionEvent, SessionId, SessionSeq, SurfaceEvent } from '@x1a0f3n9/dsh-session';
|
|
3
|
+
import type { SessionEventRecord, SessionEventTrace, SessionLineageTrace, SessionRecord } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Classify a raw event log with one canonical surface fold.
|
|
6
|
+
* @param sessionId - owner of the event log.
|
|
7
|
+
* @param events - detached raw event log.
|
|
8
|
+
* @returns lightweight records in ascending log order.
|
|
9
|
+
*/
|
|
10
|
+
export declare function eventRecords(sessionId: SessionId, events: readonly SessionEvent[]): SessionEventRecord[];
|
|
11
|
+
/**
|
|
12
|
+
* Fold and return the current model surface after validating the whole log.
|
|
13
|
+
* @param sessionId - owner used in query diagnostics.
|
|
14
|
+
* @param events - detached raw event log from one corpus observation.
|
|
15
|
+
* @returns detached current surface events in folded order.
|
|
16
|
+
*/
|
|
17
|
+
export declare function currentSurfaceEvents(sessionId: SessionId, events: readonly SessionEvent[]): SurfaceEvent[];
|
|
18
|
+
/**
|
|
19
|
+
* Trace one target after one canonical surface fold and whole-log validation.
|
|
20
|
+
* @param sessionId - owner of the event log.
|
|
21
|
+
* @param events - detached raw event log.
|
|
22
|
+
* @param seq - target event seq.
|
|
23
|
+
* @returns direct surface replacements and relationships to cited source events.
|
|
24
|
+
*/
|
|
25
|
+
export declare function traceEvent(sessionId: SessionId, events: readonly SessionEvent[], seq: SessionSeq): SessionEventTrace;
|
|
26
|
+
/**
|
|
27
|
+
* Trace one target's known ancestry and recursively known descendants.
|
|
28
|
+
* @param records - complete logical corpus from one observation.
|
|
29
|
+
* @param sessionId - target session id.
|
|
30
|
+
* @returns complete or explicitly partial lineage.
|
|
31
|
+
*/
|
|
32
|
+
export declare function traceSession(records: readonly SessionRecord[], sessionId: SessionId): SessionLineageTrace;
|
|
33
|
+
//# sourceMappingURL=tracing.d.ts.map
|