@hasna-internal/kai-session-query 0.1.1-rc.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.
@@ -0,0 +1,23 @@
1
+ //#region lib/types/invariant.js
2
+ /**
3
+ * Package-owned invariant companion for `@hasna-internal/kai-session-query`.
4
+ * @module @hasna-internal/kai-session-query/invariant
5
+ */
6
+ const PACKAGE_NAME = "@hasna-internal/kai-session-query";
7
+ /** Cordis companion plugin name. */
8
+ const name = "session-query-invariant";
9
+ /** Service required before the companion can reserve package ownership. */
10
+ const inject = ["invariants"];
11
+ /**
12
+ * No runtime invariant: query results are immutable per-call projections whose lineage and event
13
+ * relations are validated while they are built; the service retains no observable result state.
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,21 @@
1
+ /** Public configuration and typed failures for the combined session-query service. */
2
+ import { HarnessError } from '@hasna-internal/kai-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 inspections in one batch read. */
6
+ export declare const SESSION_QUERY_DEFAULT_PERSISTED_INSPECT_CONCURRENCY = 4;
7
+ /** Backend-independent configuration inherited by every session-query implementation. */
8
+ export interface Config {
9
+ /** Maximum accepted raw read context on either side. Defaults to 50. */
10
+ readWindowMax?: number;
11
+ /** Maximum concurrent persisted-log inspections in one batch read. Defaults to 4. */
12
+ persistedInspectConcurrency?: number;
13
+ }
14
+ /** Stable machine-routable failure taxonomy for session reads, traces, and search. */
15
+ 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';
16
+ /** Typed session-query failure whose `code` is one closed taxonomy member. */
17
+ export declare class SessionQueryError extends HarnessError {
18
+ readonly code: SessionQueryErrorCode;
19
+ constructor(message: string, code: SessionQueryErrorCode, options?: ErrorOptions);
20
+ }
21
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,64 @@
1
+ /** Live/persisted logical-corpus resolution for session-query. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { SessionEvent, SessionHeader, SessionId } from '@hasna-internal/kai-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
+ /** Cloned raw event log. */
10
+ events: SessionEvent[];
11
+ }
12
+ /** Borrowed source visible only during one synchronous batch projection. */
13
+ export interface LogicalSessionSource {
14
+ /** Header selected with `events`; callers must clone retained output. */
15
+ readonly header: SessionHeader;
16
+ /** Raw events selected with `header`; valid only for the projection call. */
17
+ readonly events: readonly SessionEvent[];
18
+ }
19
+ /** One source-projection result in a batch logical-corpus observation. */
20
+ export type LogicalProjectionResult<Value> = {
21
+ sessionId: SessionId;
22
+ status: 'fulfilled';
23
+ value: Value;
24
+ } | {
25
+ sessionId: SessionId;
26
+ status: 'rejected';
27
+ reason: unknown;
28
+ };
29
+ /** Resolves a live-preferred corpus against the persistence service mounted now. */
30
+ export declare class SessionCorpus {
31
+ private readonly _ctx;
32
+ private readonly _persistedInspectConcurrency;
33
+ private _persistence;
34
+ private readonly _optionalPersistenceFiber;
35
+ constructor(_ctx: Context, _persistedInspectConcurrency: number);
36
+ /**
37
+ * List the complete logical corpus with live precedence and cloned headers.
38
+ * @param signal - optional cancellation for persistence listing.
39
+ * @returns records in deterministic newest-first order.
40
+ */
41
+ listSessions(signal?: AbortSignal): Promise<SessionRecord[]>;
42
+ /**
43
+ * Load one logical source, preferring a detached live snapshot.
44
+ *
45
+ * A known live target never consults persistence, so an optional backend's
46
+ * failure cannot make current in-memory history unreadable.
47
+ * @param sessionId - session to resolve.
48
+ * @param signal - optional cancellation for persisted source resolution.
49
+ * @returns detached live-preferred header and events.
50
+ */
51
+ load(sessionId: SessionId, signal?: AbortSignal): Promise<LogicalSession>;
52
+ /**
53
+ * Project unique logical sources immediately from one persistence listing.
54
+ *
55
+ * The synchronous projector runs before a persisted worker claims its next id.
56
+ * Full logs are borrowed only for that call and never retained by the batch.
57
+ * @param sessionIds - sessions to resolve in first-occurrence order.
58
+ * @param project - synchronous fold that owns/clones every retained value.
59
+ * @param signal - cancellation shared by listing and every persisted inspection.
60
+ * @returns one fulfilled or rejected projected result per unique requested id.
61
+ */
62
+ projectMany<Value>(sessionIds: readonly SessionId[], project: (source: LogicalSessionSource) => Value, signal?: AbortSignal): Promise<LogicalProjectionResult<Value>[]>;
63
+ }
64
+ //# sourceMappingURL=corpus.d.ts.map
@@ -0,0 +1,11 @@
1
+ /** Opaque cursor identity for session-search pagination. */
2
+ import type { Branded } from '@hasna-internal/kai-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 '@hasna-internal/kai-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 '@hasna-internal/kai-session';
3
+ /**
4
+ * Extract searchable semantic text from one first-party session event.
5
+ *
6
+ * Structural boundaries, raw stream chunks, 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,143 @@
1
+ /**
2
+ * Service Definition for combined session-history reads, traces, filters, and full-text search.
3
+ *
4
+ * @module @hasna-internal/kai-session-query
5
+ */
6
+ import { Context, Service } from '@deepseek-ai/cordis';
7
+ import { type SessionId } from '@hasna-internal/kai-session';
8
+ import type { SessionTitleSnapshot } from '@hasna-internal/kai-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
+ export type * from './types.ts';
12
+ export { SessionSearchCursor } from './cursor.ts';
13
+ export type { Config, SessionQueryErrorCode } from './config.ts';
14
+ export { SESSION_QUERY_DEFAULT_PERSISTED_INSPECT_CONCURRENCY, SESSION_QUERY_READ_WINDOW_MAX, SessionQueryError, } from './config.ts';
15
+ export { extractSessionEventText } from './extraction.ts';
16
+ export { buildSessionEventRecords, buildSessionEventSearchDocuments } from './documents.ts';
17
+ export { compileSessionTextFilter, filterSessionEventDocuments, filterSessionResults, materializeSessionEventResultFilters, materializeSessionResultFilters, } from './filters.ts';
18
+ export { assertSessionHeadersCompatible } from './sources.ts';
19
+ declare module '@deepseek-ai/cordis' {
20
+ interface Context {
21
+ sessionQuery: SessionQueryEngine;
22
+ }
23
+ }
24
+ /**
25
+ * Unified live-preferred session query service.
26
+ *
27
+ * Exact reads, filters, and traces are backend-independent concrete behavior.
28
+ * A backend implements full-text observation, reconciliation, ranking, cursor
29
+ * generations, and query execution on the same `ctx.sessionQuery` service.
30
+ */
31
+ export declare abstract class SessionQueryEngine extends Service {
32
+ static inject: string[];
33
+ private readonly _readWindowMax;
34
+ private readonly _corpus;
35
+ constructor(ctx: Context, config?: Config);
36
+ /**
37
+ * Search the live-preferred logical corpus and group by session.
38
+ * @param request - query text, metadata filters, page size, and cursor.
39
+ * @param exec - optional cancellation control.
40
+ * @returns session hits ranked by their strongest matching event.
41
+ */
42
+ abstract searchSessions(request: SessionSearchRequest, exec?: SessionSearchExecContext): Promise<SessionSearchPage<SessionSearchHit>>;
43
+ /**
44
+ * Search events within one live-preferred logical session.
45
+ * @param request - target session, query text, filters, page size, and cursor.
46
+ * @param exec - optional cancellation control.
47
+ * @returns matching event hits and their target header from one indexed generation.
48
+ */
49
+ abstract searchEvents(request: SessionEventSearchRequest, exec?: SessionSearchExecContext): Promise<SessionEventSearchPage>;
50
+ /**
51
+ * List the complete logical corpus using live-preferred records.
52
+ * @param signal - optional cancellation for persistence listing.
53
+ * @returns deterministic newest-first cloned session records.
54
+ */
55
+ listSessions(signal?: AbortSignal): Promise<SessionRecord[]>;
56
+ /**
57
+ * Read and replay-validate one complete logical session log without making it live.
58
+ * @param sessionId - live or persisted session id to read.
59
+ * @returns cloned header and complete raw event log from one observation.
60
+ * @throws when persistence, header compatibility, or replay validation fails.
61
+ */
62
+ readSession(sessionId: SessionId): Promise<SessionLogSnapshot>;
63
+ /**
64
+ * Filter the complete logical corpus with provider-independent predicates.
65
+ * @param filters - ANDed session metadata and availability clauses.
66
+ * @param signal - optional cancellation for persistence listing.
67
+ * @returns matching cloned records in deterministic newest-first order.
68
+ */
69
+ filterSessions(filters: readonly SessionResultFilter[], signal?: AbortSignal): Promise<SessionRecord[]>;
70
+ /**
71
+ * Fold the latest log-backed title from one live-preferred logical session.
72
+ * @param sessionId - live or persisted session id to read.
73
+ * @param signal - optional cancellation for source resolution and title folding.
74
+ * @returns latest title snapshot, or `undefined` when the log has no title event.
75
+ */
76
+ readTitle(sessionId: SessionId, signal?: AbortSignal): Promise<SessionTitleSnapshot | undefined>;
77
+ /**
78
+ * Fold the latest title and return its source header from one corpus observation.
79
+ * @param sessionId - live or persisted session id to read.
80
+ * @param signal - optional cancellation for source resolution and title folding.
81
+ * @returns cloned source header and optional latest title snapshot.
82
+ */
83
+ readTitleSnapshot(sessionId: SessionId, signal?: AbortSignal): Promise<SessionTitleObservation>;
84
+ /**
85
+ * Fold titles for unique sessions from one cancellable corpus observation.
86
+ *
87
+ * Results preserve first-occurrence input order. Operational failures stay
88
+ * isolated per session, while cancellation rejects the complete operation.
89
+ * @param sessionIds - live or persisted session ids to observe.
90
+ * @param signal - optional cancellation shared by all source reads.
91
+ * @returns one fulfilled or rejected result per unique requested id.
92
+ */
93
+ readTitleSnapshots(sessionIds: readonly SessionId[], signal?: AbortSignal): Promise<SessionTitleObservationResult[]>;
94
+ /**
95
+ * List lightweight raw-log event records for one logical session.
96
+ * @param sessionId - live-preferred session id to read.
97
+ * @returns event records in ascending seq order.
98
+ */
99
+ listEvents(sessionId: SessionId): Promise<SessionEventRecord[]>;
100
+ /**
101
+ * Scan first-party semantic event documents with provider-independent filters.
102
+ * @param sessionId - live-preferred session id to scan.
103
+ * @param filters - ANDed metadata and literal-text predicates.
104
+ * @returns matching semantic documents in ascending seq order.
105
+ */
106
+ filterEvents(sessionId: SessionId, filters: readonly SessionEventResultFilter[]): Promise<SessionEventSearchDocument[]>;
107
+ private _filterSessions;
108
+ private _filterEvents;
109
+ /**
110
+ * Read one session's complete current model surface from one corpus observation.
111
+ * @param sessionId - live-preferred session id to read.
112
+ * @returns cloned header, current surface, and the last sequence number included in the raw-log capture.
113
+ * @throws when source resolution fails or the session surface is invalid.
114
+ */
115
+ readSurface(sessionId: SessionId): Promise<SessionSurfaceSnapshot>;
116
+ /**
117
+ * Trace known ancestry and descendants from one corpus observation.
118
+ * @param sessionId - logical session id to trace.
119
+ * @param signal - optional cancellation for persistence listing.
120
+ * @returns a complete lineage or the first parent that could not be resolved.
121
+ * @throws when corpus resolution fails, the target is absent, or its known ancestry cycles.
122
+ */
123
+ traceSession(sessionId: SessionId, signal?: AbortSignal): Promise<SessionLineageTrace>;
124
+ /**
125
+ * Trace one event's direct positional replacements and cited source events.
126
+ * @param request - target session id and event seq.
127
+ * @param signal - optional cancellation for persisted source resolution.
128
+ * @returns source header, direct links, and the target's positional replacement chain.
129
+ * @throws when source resolution fails, the target is absent, or surface/source-event validation fails.
130
+ */
131
+ traceEvent(request: SessionEventTraceRequest, signal?: AbortSignal): Promise<SessionEventTraceObservation>;
132
+ /**
133
+ * Read one full event plus a bounded raw-log context window.
134
+ * @param request - target session/seq and context sizes.
135
+ * @param signal - optional cancellation for persisted source resolution.
136
+ * @returns cloned target and neighboring events.
137
+ */
138
+ readEvent(request: SessionEventReadRequest, signal?: AbortSignal): Promise<SessionEventWindow>;
139
+ private _readEvent;
140
+ private _readWindow;
141
+ }
142
+ export default SessionQueryEngine;
143
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Package-owned invariant companion for `@hasna-internal/kai-session-query`.
3
+ * @module @hasna-internal/kai-session-query/invariant
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ /** Cordis companion plugin name. */
7
+ export declare const name = "session-query-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,9 @@
1
+ /** Shared immutable-header checks for logical session source observers. */
2
+ import type { SessionHeader } from '@hasna-internal/kai-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, SurfaceEvent } from '@hasna-internal/kai-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: number): 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
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Public records for exact reads and relationship traces over the
3
+ * live-preferred logical session corpus.
4
+ *
5
+ * @module @hasna-internal/kai-session-query/types
6
+ */
7
+ import type { SessionEvent, SessionEventType, SessionHeader, SessionId, SurfaceEvent } from '@hasna-internal/kai-session';
8
+ import type { SessionTitleSnapshot } from '@hasna-internal/kai-session-title';
9
+ import type { SessionSearchCursor } from './cursor.ts';
10
+ export type { SessionSearchCursor } from './cursor.ts';
11
+ /** Whether an event is current model context, replaced context, or raw-log-only. */
12
+ export type SessionEventSurface = 'current' | 'shadowed' | 'log-only';
13
+ /** Lightweight identity and source availability for one logical session. */
14
+ export interface SessionRecord {
15
+ /** Cloned session header selected from the live-preferred corpus. */
16
+ header: SessionHeader;
17
+ /** Whether the id currently exists in `ctx.sessions`. */
18
+ live: boolean;
19
+ /** Whether the active persistence backend currently materializes the id. */
20
+ persisted: boolean;
21
+ }
22
+ /** One atomic live-preferred observation of a session's current model surface. */
23
+ export interface SessionSurfaceSnapshot {
24
+ /** Cloned session header selected from the same corpus observation as `events`. */
25
+ session: SessionHeader;
26
+ /** Highest raw-log seq included in the observation, or `null` for an empty log. */
27
+ capturedThroughSeq: number | null;
28
+ /** Cloned current surface events in model-history order. */
29
+ events: SurfaceEvent[];
30
+ }
31
+ /** One validated detached observation of a logical session's complete raw log. */
32
+ export interface SessionLogSnapshot {
33
+ /** Cloned session header selected from the same observation as `events`. */
34
+ session: SessionHeader;
35
+ /** Cloned contiguous raw events after persistence repair and replay validation. */
36
+ events: SessionEvent[];
37
+ }
38
+ /** Lightweight metadata for one event within a logical session. */
39
+ export interface SessionEventRecord {
40
+ /** Session that owns the event. */
41
+ sessionId: SessionId;
42
+ /** Monotonic event seq within the session. */
43
+ seq: number;
44
+ /** Discriminant of the session event. */
45
+ type: SessionEventType;
46
+ /** Event timestamp in Unix epoch milliseconds. */
47
+ time: number;
48
+ /** Event placement in the folded session surface. */
49
+ surface: SessionEventSurface;
50
+ }
51
+ /** Recursive descendant node in a session-lineage trace. */
52
+ export interface SessionLineageNode {
53
+ /** Detached logical-corpus record for this descendant. */
54
+ session: SessionRecord;
55
+ /** Direct children, each carrying its own recursive descendants. */
56
+ descendants: SessionLineageNode[];
57
+ }
58
+ /** Known ancestry and descendants for one logical session. */
59
+ export type SessionLineageTrace = {
60
+ /** Detached record for the session that was traced. */
61
+ target: SessionRecord;
62
+ /** Known parents from the immediate parent outward. */
63
+ ancestors: SessionRecord[];
64
+ /** Complete known descendant trees rooted at the target's direct children. */
65
+ descendants: SessionLineageNode[];
66
+ } & ({
67
+ /** The complete parent chain is present in the logical corpus. */
68
+ complete: true;
69
+ /** Detached record at the top of the complete lineage. */
70
+ root: SessionRecord;
71
+ } | {
72
+ /** The parent chain leaves the visible logical corpus. */
73
+ complete: false;
74
+ /** First parent id that is not present in the logical corpus. */
75
+ unresolvedParentId: SessionId;
76
+ });
77
+ /** Request for direct surface replacements and relationships to cited source events around one event. */
78
+ export interface SessionEventTraceRequest {
79
+ /** Session that owns the target event. */
80
+ sessionId: SessionId;
81
+ /** Target event seq. */
82
+ seq: number;
83
+ }
84
+ /** Direct surface replacements and relationships to cited source events for one event. */
85
+ export interface SessionEventTrace {
86
+ /** Lightweight target record. */
87
+ target: SessionEventRecord;
88
+ /** Immediate positional replacement event, when the target was shadowed. */
89
+ replacedBy?: number;
90
+ /** Positional replacers from the immediate replacement to the final replacement. */
91
+ replacementChain: number[];
92
+ /** Surface nodes directly removed when the target itself performed a replacement. */
93
+ replacedEventSeqs: number[];
94
+ /** Earlier events cited directly as sources, in their recorded order. */
95
+ sourceEventSeqs: number[];
96
+ /** Later events that directly cite the target as a source, in log order. */
97
+ derivedEventSeqs: number[];
98
+ }
99
+ /** Event relationships bound to the same session-header observation. */
100
+ export interface SessionEventTraceObservation extends SessionEventTrace {
101
+ /** Cloned header selected with the event log used for the trace. */
102
+ session: SessionHeader;
103
+ }
104
+ /** Request for one event plus raw neighboring log context. */
105
+ export interface SessionEventReadRequest {
106
+ /** Session that owns the target event. */
107
+ sessionId: SessionId;
108
+ /** Target event seq. */
109
+ seq: number;
110
+ /** Number of preceding raw events to include. */
111
+ before?: number;
112
+ /** Number of following raw events to include. */
113
+ after?: number;
114
+ }
115
+ /** Full target event and a bounded raw-log window. */
116
+ export interface SessionEventWindow {
117
+ /** Cloned header for the live-preferred source read. */
118
+ session: SessionHeader;
119
+ /** Full cloned target event. */
120
+ target: SessionEvent;
121
+ /** Full cloned events from `startSeq` through `endSeq`. */
122
+ events: SessionEvent[];
123
+ /** First seq included in `events`. */
124
+ startSeq: number;
125
+ /** Last seq included in `events`. */
126
+ endSeq: number;
127
+ }
128
+ /** Latest folded title bound to the same session-header observation. */
129
+ export interface SessionTitleObservation {
130
+ /** Cloned header selected with the event log used for the title fold. */
131
+ session: SessionHeader;
132
+ /** Latest title snapshot, absent when the observed log has no title. */
133
+ title?: SessionTitleSnapshot;
134
+ }
135
+ /** One ordered result from a batch title observation. */
136
+ export type SessionTitleObservationResult = {
137
+ /** Requested session id. */
138
+ sessionId: SessionId;
139
+ /** Successful atomic header/title observation. */
140
+ status: 'fulfilled';
141
+ /** Header and optional latest title from one logical source. */
142
+ value: SessionTitleObservation;
143
+ } | {
144
+ /** Requested session id. */
145
+ sessionId: SessionId;
146
+ /** Operational failure isolated to this session. */
147
+ status: 'rejected';
148
+ /** Original failure from logical-source resolution or title folding. */
149
+ reason: unknown;
150
+ };
151
+ /** Inclusive numeric interval used by time and sequence filters. */
152
+ export interface SessionResultRange {
153
+ /** Inclusive lower bound. */
154
+ from?: number;
155
+ /** Inclusive upper bound. */
156
+ to?: number;
157
+ }
158
+ /** Source availability predicates understood by logical-session filters. */
159
+ export type SessionAvailability = 'live' | 'persisted';
160
+ /**
161
+ * One logical-session predicate. A filter array is ANDed; `values` within a
162
+ * clause are ORed.
163
+ */
164
+ export type SessionResultFilter = {
165
+ kind: 'id';
166
+ values: readonly SessionId[];
167
+ } | {
168
+ kind: 'cwd';
169
+ values: readonly (string | null)[];
170
+ } | ({
171
+ kind: 'created-at';
172
+ } & SessionResultRange) | {
173
+ kind: 'parent';
174
+ values: readonly (SessionId | null)[];
175
+ } | {
176
+ kind: 'availability';
177
+ values: readonly SessionAvailability[];
178
+ };
179
+ /**
180
+ * One event predicate. A filter array is ANDed; list-valued clauses are ORed.
181
+ * Text is a literal, case-insensitive, whitespace-flexible semantic-text scan.
182
+ */
183
+ export type SessionEventResultFilter = ({
184
+ kind: 'seq';
185
+ } & SessionResultRange) | ({
186
+ kind: 'time';
187
+ } & SessionResultRange) | {
188
+ kind: 'type';
189
+ values: readonly SessionEventType[];
190
+ } | {
191
+ kind: 'surface';
192
+ values: readonly SessionEventSurface[];
193
+ } | {
194
+ kind: 'text';
195
+ text: string;
196
+ };
197
+ /** Event predicates a full-text provider can apply before relevance ranking. */
198
+ export type SessionEventMetadataFilter = Exclude<SessionEventResultFilter, {
199
+ kind: 'text';
200
+ }>;
201
+ /** Searchable semantic document derived from one session event. */
202
+ export interface SessionEventSearchDocument extends SessionEventRecord {
203
+ /** First-party semantic text used by scan filters and full-text indexes. */
204
+ text: string;
205
+ }
206
+ /** One cursor-paginated result page. */
207
+ export interface SessionSearchPage<T> {
208
+ /** Results for this page in contract-defined order. */
209
+ items: readonly T[];
210
+ /** Opaque continuation cursor, absent on the final page. */
211
+ nextCursor?: SessionSearchCursor;
212
+ }
213
+ /** Event-search results bound to the indexed target-session observation. */
214
+ export interface SessionEventSearchPage extends SessionSearchPage<SessionEventSearchHit> {
215
+ /** Cloned target header from the same indexed generation as `items`. */
216
+ session: SessionHeader;
217
+ }
218
+ /** Controls shared by cross-session and within-session search calls. */
219
+ export interface SessionSearchExecContext {
220
+ /** Abort caller waiting and interrupt provider work where supported. */
221
+ signal?: AbortSignal;
222
+ }
223
+ /** Cross-session full-text search request. */
224
+ export interface SessionSearchRequest {
225
+ /** Full-text query interpreted as data, never executable FTS syntax. */
226
+ query: string;
227
+ /** Logical-session predicates applied before event ranking. */
228
+ sessionFilters?: readonly SessionResultFilter[];
229
+ /** Event predicates applied before event ranking. */
230
+ eventFilters?: readonly SessionEventMetadataFilter[];
231
+ /** Maximum sessions in this page. */
232
+ limit?: number;
233
+ /** Opaque cursor returned for the identical normalized request. */
234
+ cursor?: SessionSearchCursor;
235
+ }
236
+ /** Within-session full-text search request. */
237
+ export interface SessionEventSearchRequest {
238
+ /** Session whose live-preferred logical log is searched. */
239
+ sessionId: SessionId;
240
+ /** Full-text query interpreted as data, never executable FTS syntax. */
241
+ query: string;
242
+ /** Event predicates applied before ranking. */
243
+ filters?: readonly SessionEventMetadataFilter[];
244
+ /** Maximum events in this page. */
245
+ limit?: number;
246
+ /** Opaque cursor returned for the identical normalized request. */
247
+ cursor?: SessionSearchCursor;
248
+ }
249
+ /** One event full-text search hit with a bounded plain-text excerpt. */
250
+ export interface SessionEventSearchHit extends SessionEventRecord {
251
+ /** Plain text excerpt selected around the match. */
252
+ snippet: string;
253
+ }
254
+ /** One grouped cross-session hit, ranked by its strongest matching event. */
255
+ export interface SessionSearchHit extends SessionRecord {
256
+ /** Strongest matching event for this session. */
257
+ bestMatch: SessionEventSearchHit;
258
+ }
259
+ //# sourceMappingURL=types.d.ts.map