@unieai/rabi-session-reference 0.0.0-stage → 0.2.1-rc.3
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.md +7 -2
- package/lib/index.js +745 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +793 -0
- package/lib/typert.remote-client.d.ts +29 -0
- package/lib/typert.remote-client.js +88 -0
- package/lib/types/config.d.ts +27 -0
- package/lib/types/config.js +17 -0
- package/lib/types/index.d.ts +103 -0
- package/lib/types/index.js +426 -0
- package/lib/types/projection.d.ts +34 -0
- package/lib/types/projection.js +148 -0
- package/lib/types/serialization.d.ts +8 -0
- package/lib/types/serialization.js +12 -0
- package/lib/types/spill.d.ts +37 -0
- package/lib/types/spill.js +68 -0
- package/lib/types/types.d.ts +81 -0
- package/lib/types/types.js +7 -0
- package/lib/types/uri.d.ts +40 -0
- package/lib/types/uri.js +80 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +72 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Generated by @unieai/rabi-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import type {
|
|
3
|
+
RemoteResult,
|
|
4
|
+
TypertRemoteInfo,
|
|
5
|
+
TypertRemoteMethod,
|
|
6
|
+
} from '@unieai/rabi-typert-protocol'
|
|
7
|
+
import type { SessionReferenceMentionCandidate } from '@unieai/rabi-session-reference/types'
|
|
8
|
+
import type { SessionId } from '@unieai/rabi-session/types'
|
|
9
|
+
|
|
10
|
+
declare module '@unieai/rabi-typert-protocol' {
|
|
11
|
+
interface TypertRemoteNamespace$73657373696f6e5265666572656e63655265736f6c766572 {
|
|
12
|
+
candidates: (agentId: SessionId, query: string, signal?: AbortSignal) => Promise<RemoteResult<SessionReferenceMentionCandidate[]>>
|
|
13
|
+
}
|
|
14
|
+
interface TypertRemoteMap {
|
|
15
|
+
'sessionReferenceResolver/candidates': (agentId: SessionId, query: string, signal?: AbortSignal) => Promise<RemoteResult<SessionReferenceMentionCandidate[]>>
|
|
16
|
+
}
|
|
17
|
+
interface TypertRemoteNamespaceMap {
|
|
18
|
+
'sessionReferenceResolver': TypertRemoteNamespace$73657373696f6e5265666572656e63655265736f6c766572
|
|
19
|
+
}
|
|
20
|
+
interface TypertRemoteScopeMap {
|
|
21
|
+
'agent:sessionReferenceResolver/candidates': (query: string, signal?: AbortSignal) => Promise<RemoteResult<SessionReferenceMentionCandidate[]>>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const TYPERT_REMOTE: TypertRemoteInfo<{
|
|
26
|
+
readonly 'sessionReferenceResolver/candidates': TypertRemoteMethod<{ readonly 'agentId': SessionId; readonly 'query': string }, SessionReferenceMentionCandidate[]>
|
|
27
|
+
}>
|
|
28
|
+
export default TYPERT_REMOTE
|
|
29
|
+
//# sourceMappingURL=typert.remote-client.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* Generated by @unieai/rabi-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { createTypertRemoteInfo } from '@unieai/rabi-typert-protocol/remote-info'
|
|
5
|
+
|
|
6
|
+
let _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0$schema$value
|
|
7
|
+
const _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0$schema = () => (_unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0$schema$value ??= z.string())
|
|
8
|
+
let _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1$schema$value
|
|
9
|
+
const _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1$schema = () => (_unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1$schema$value ??= z.string())
|
|
10
|
+
let _unieai_rabi_session_reference_sessionReferenceResolver_candidates_result$schema$value
|
|
11
|
+
const _unieai_rabi_session_reference_sessionReferenceResolver_candidates_result$schema = () => (_unieai_rabi_session_reference_sessionReferenceResolver_candidates_result$schema$value ??= z.array(z.object({
|
|
12
|
+
'mention': z.string().describe('Canonical `@[label](rabi-session:…)` mention serialized into the prompt draft.'),
|
|
13
|
+
'sessionId': z.string().describe('Opaque source session identity.'),
|
|
14
|
+
'label': z.string().describe('Latest log-backed title, falling back to the opaque session id.'),
|
|
15
|
+
'displayTitle': z.string().optional().describe('Display and canonical-mention text, preferring a subagent\'s durable creation label over {@link label}.'),
|
|
16
|
+
'cwd': z.string().optional().describe('Source session working directory, when recorded.'),
|
|
17
|
+
'sameWorkspace': z.boolean().describe('True when {@link SessionReferenceCandidate.cwd} is recorded and equals the requesting agent\'s. Hosts that only surface a distinguishing location read this instead of comparing paths they never received.'),
|
|
18
|
+
'createdAt': z.number().describe('Source session creation time in Unix epoch milliseconds.'),
|
|
19
|
+
})))
|
|
20
|
+
let _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0_strict$schema$value
|
|
21
|
+
const _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0_strict$schema = () => (_unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0_strict$schema$value ??= z.string())
|
|
22
|
+
let _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1_strict$schema$value
|
|
23
|
+
const _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1_strict$schema = () => (_unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1_strict$schema$value ??= z.string())
|
|
24
|
+
|
|
25
|
+
export const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
26
|
+
package: '@unieai/rabi-session-reference',
|
|
27
|
+
methods: {
|
|
28
|
+
'sessionReferenceResolver/candidates': {
|
|
29
|
+
service: 'sessionReferenceResolver',
|
|
30
|
+
description: 'Remote face of {@link listCandidates}: the configured candidate limit applies, and every candidate carries the canonical mention a host inserts into the prompt draft.',
|
|
31
|
+
implementation: 'remoteExportCandidates',
|
|
32
|
+
invocation: { kind: 'direct' },
|
|
33
|
+
scope: {
|
|
34
|
+
context: 'agent',
|
|
35
|
+
wire: 'agentId',
|
|
36
|
+
},
|
|
37
|
+
parameters: [
|
|
38
|
+
{
|
|
39
|
+
name: 'agent',
|
|
40
|
+
wire: 'agentId',
|
|
41
|
+
description: 'target agent; self is excluded and its cwd drives ranking.',
|
|
42
|
+
source: 'lookup',
|
|
43
|
+
lookup: 'agent',
|
|
44
|
+
codec: {
|
|
45
|
+
mode: 'strict',
|
|
46
|
+
typeSymbol: '@unieai/rabi-session/types#SessionId',
|
|
47
|
+
create: _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0$schema,
|
|
48
|
+
jsonSchema: {"type":"string"},
|
|
49
|
+
},
|
|
50
|
+
strictCodec: {
|
|
51
|
+
mode: 'strict',
|
|
52
|
+
typeSymbol: '@unieai/rabi-session/types#SessionId',
|
|
53
|
+
create: _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_0_strict$schema,
|
|
54
|
+
jsonSchema: {"type":"string"},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'query',
|
|
59
|
+
description: 'optional case-insensitive session-id/cwd/title substring.',
|
|
60
|
+
source: 'json',
|
|
61
|
+
codec: {
|
|
62
|
+
mode: 'strict',
|
|
63
|
+
typeSymbol: '@unieai/rabi-session-reference#sessionReferenceResolver/candidates:query',
|
|
64
|
+
create: _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1$schema,
|
|
65
|
+
jsonSchema: {"type":"string"},
|
|
66
|
+
},
|
|
67
|
+
strictCodec: {
|
|
68
|
+
mode: 'strict',
|
|
69
|
+
typeSymbol: '@unieai/rabi-session-reference#sessionReferenceResolver/candidates:query',
|
|
70
|
+
create: _unieai_rabi_session_reference_sessionReferenceResolver_candidates_parameter_1_strict$schema,
|
|
71
|
+
jsonSchema: {"type":"string"},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
cancellation: { parameter: 'signal' },
|
|
76
|
+
result: {
|
|
77
|
+
mode: 'strict',
|
|
78
|
+
typeSymbol: '@unieai/rabi-session-reference#sessionReferenceResolver/candidates:result',
|
|
79
|
+
create: _unieai_rabi_session_reference_sessionReferenceResolver_candidates_result$schema,
|
|
80
|
+
description: 'mention-carrying candidates in rank order.',
|
|
81
|
+
jsonSchema: {"type":"array","items":{"type":"object","properties":{"mention":{"type":"string","description":"Canonical `@[label](rabi-session:…)` mention serialized into the prompt draft."},"sessionId":{"type":"string","description":"Opaque source session identity."},"label":{"type":"string","description":"Latest log-backed title, falling back to the opaque session id."},"displayTitle":{"type":"string","description":"Display and canonical-mention text, preferring a subagent's durable creation label over {@link label}."},"cwd":{"type":"string","description":"Source session working directory, when recorded."},"sameWorkspace":{"type":"boolean","description":"True when {@link SessionReferenceCandidate.cwd} is recorded and equals the requesting agent's. Hosts that only surface a distinguishing location read this instead of comparing paths they never received."},"createdAt":{"type":"number","description":"Source session creation time in Unix epoch milliseconds."}},"required":["mention","sessionId","label","sameWorkspace","createdAt"],"additionalProperties":true}},
|
|
82
|
+
},
|
|
83
|
+
sourceLocation: {"file":"packages/context/session-reference/src/index.ts","line":290,"column":9},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}, z)
|
|
87
|
+
|
|
88
|
+
export default TYPERT_REMOTE
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Configuration and stable diagnostics for session references. */
|
|
2
|
+
/** Hard maximum references accepted by one message. */
|
|
3
|
+
export declare const MAX_REFERENCES = 3;
|
|
4
|
+
/** Default number of discovery candidates returned to a host. */
|
|
5
|
+
export declare const DEFAULT_CANDIDATE_LIMIT = 50;
|
|
6
|
+
/** Minimum automatic UTF-8 budget for one rendered reference JSON object. */
|
|
7
|
+
export declare const DEFAULT_MAX_REFERENCE_BYTES = 65536;
|
|
8
|
+
/** Session-reference service configuration. */
|
|
9
|
+
export interface Config {
|
|
10
|
+
/** Maximum distinct source sessions referenced by one message, from one to three. */
|
|
11
|
+
maxReferences?: number;
|
|
12
|
+
/** Default host candidate-list limit. */
|
|
13
|
+
candidateLimit?: number;
|
|
14
|
+
/** Explicit maximum rendered UTF-8 bytes per source; absent uses the model-relative budget with a 64 KiB floor. */
|
|
15
|
+
maxReferenceBytes?: number;
|
|
16
|
+
/** Fraction of the model context window per source, estimated at four bytes per token; between zero and one. */
|
|
17
|
+
referenceContextFraction?: number;
|
|
18
|
+
}
|
|
19
|
+
/** Stable failure codes exposed to host adapters. */
|
|
20
|
+
export type SessionReferenceErrorCode = 'SESSION_REFERENCE_INVALID_CONFIG' | 'SESSION_REFERENCE_INVALID_REFERENCE' | 'SESSION_REFERENCE_SELF_REFERENCE' | 'SESSION_REFERENCE_TOO_MANY' | 'SESSION_REFERENCE_READ_FAILED' | 'SESSION_REFERENCE_BUDGET_EXCEEDED' | 'SESSION_REFERENCE_CANCELLED';
|
|
21
|
+
/** Typed session-reference failure suitable for host protocol error mapping. */
|
|
22
|
+
export declare class SessionReferenceError extends Error {
|
|
23
|
+
readonly code: SessionReferenceErrorCode;
|
|
24
|
+
/** @param message Human-readable diagnosis. @param code Stable routing code. @param options Optional cause. */
|
|
25
|
+
constructor(message: string, code: SessionReferenceErrorCode, options?: ErrorOptions);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Configuration and stable diagnostics for session references. */
|
|
2
|
+
/** Hard maximum references accepted by one message. */
|
|
3
|
+
export const MAX_REFERENCES = 3;
|
|
4
|
+
/** Default number of discovery candidates returned to a host. */
|
|
5
|
+
export const DEFAULT_CANDIDATE_LIMIT = 50;
|
|
6
|
+
/** Minimum automatic UTF-8 budget for one rendered reference JSON object. */
|
|
7
|
+
export const DEFAULT_MAX_REFERENCE_BYTES = 65_536;
|
|
8
|
+
/** Typed session-reference failure suitable for host protocol error mapping. */
|
|
9
|
+
export class SessionReferenceError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
/** @param message Human-readable diagnosis. @param code Stable routing code. @param options Optional cause. */
|
|
12
|
+
constructor(message, code, options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = 'SessionReferenceError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-session snapshot preparation. Hosts adapt mentions into structured
|
|
3
|
+
* references; this service owns exact reads, projection, budgets, and durable context.
|
|
4
|
+
*
|
|
5
|
+
* @module @unieai/rabi-session-reference
|
|
6
|
+
*/
|
|
7
|
+
import { Context } from '@unieai/cordis';
|
|
8
|
+
import z from '@unieai/schemastery';
|
|
9
|
+
import type { Agent } from '@unieai/rabi-agent';
|
|
10
|
+
import { TypertRemoteService } from '@unieai/rabi-typert-protocol';
|
|
11
|
+
import type { ContentBlock } from '@unieai/rabi-llm';
|
|
12
|
+
import { type Config } from './config.ts';
|
|
13
|
+
import type { PreparedReferencedMessage, SessionReferenceCandidate, SessionReferenceInput, SessionReferenceMentionCandidate } from './types.ts';
|
|
14
|
+
export type * from './types.ts';
|
|
15
|
+
export type { Config, SessionReferenceErrorCode } from './config.ts';
|
|
16
|
+
export { DEFAULT_CANDIDATE_LIMIT, DEFAULT_MAX_REFERENCE_BYTES, MAX_REFERENCES, SessionReferenceError, } from './config.ts';
|
|
17
|
+
export { SESSION_REFERENCE_SCHEME, decodeSessionReferenceUri, encodeSessionReferenceUri, formatSessionReferenceMention, parseSessionReferenceText, } from './uri.ts';
|
|
18
|
+
declare module '@unieai/cordis' {
|
|
19
|
+
interface Context {
|
|
20
|
+
sessionReferenceResolver: SessionReferenceResolver;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Exact-read consumer that prepares immutable cross-session message context. */
|
|
24
|
+
export declare class SessionReferenceResolver extends TypertRemoteService {
|
|
25
|
+
static inject: string[];
|
|
26
|
+
static Config: z<Config>;
|
|
27
|
+
private readonly config;
|
|
28
|
+
private readonly assembledRoutes;
|
|
29
|
+
constructor(ctx: Context, config?: Config);
|
|
30
|
+
/**
|
|
31
|
+
* Replace canonical mentions in direct user messages and place each prepared
|
|
32
|
+
* snapshot immediately after the message that cited it.
|
|
33
|
+
* @param agent - agent entering the model step.
|
|
34
|
+
* @param messages - messages accepted by downstream pre-step listeners.
|
|
35
|
+
* @param signal - active turn cancellation.
|
|
36
|
+
* @returns direct messages followed by their session-reference context in citation order.
|
|
37
|
+
*/
|
|
38
|
+
private prepareDirectMessages;
|
|
39
|
+
/**
|
|
40
|
+
* List reference candidates, ranked by working-directory affinity.
|
|
41
|
+
*
|
|
42
|
+
* Discovery runs at keystroke rate, so titles and subagent labels only ever
|
|
43
|
+
* come from projection reads; sessions without either fall back to their id.
|
|
44
|
+
* @param agent - target agent; self is excluded and its cwd drives ranking.
|
|
45
|
+
* @param query - optional case-insensitive session-id/cwd/title/display-title substring.
|
|
46
|
+
* @param limit - optional positive result cap.
|
|
47
|
+
* @param signal - optional cancellation boundary for host autocomplete teardown.
|
|
48
|
+
* @returns candidates with canonical mention labels and presentation titles.
|
|
49
|
+
*/
|
|
50
|
+
listCandidates(agent: Agent, query?: string, limit?: number, signal?: AbortSignal): Promise<SessionReferenceCandidate[]>;
|
|
51
|
+
/**
|
|
52
|
+
* The mention label and display title each listed Session's projections can answer without reading its log.
|
|
53
|
+
*
|
|
54
|
+
* Attachment is decided by the store at read time, not by the listing:
|
|
55
|
+
* a session that attached in between would otherwise be answered from a
|
|
56
|
+
* checkpoint its live log has already moved past.
|
|
57
|
+
*
|
|
58
|
+
* An attached session answers from its live registry cut, which advances
|
|
59
|
+
* with every committed event, so a rename or a just-generated title is
|
|
60
|
+
* visible immediately; its events are already in memory, so the lazy fold
|
|
61
|
+
* costs no I/O. A cold session answers from the durable checkpoint the
|
|
62
|
+
* projection cache wrote when it went cold.
|
|
63
|
+
*
|
|
64
|
+
* Nothing else is attempted. Folding a title from a log costs the whole
|
|
65
|
+
* log, and this call sits under every keystroke of `@` completion. A
|
|
66
|
+
* session that no projection can answer for — one persisted before the
|
|
67
|
+
* cache was composed — is labeled by its id and cannot be found by its
|
|
68
|
+
* title until it is opened once, which checkpoints it.
|
|
69
|
+
*
|
|
70
|
+
* Services are resolved once per call and the cache's snapshot method is
|
|
71
|
+
* bound once: a service lookup per listed session would dominate the call.
|
|
72
|
+
* @param items - the listed sessions, live or cold.
|
|
73
|
+
* @returns each item with its title-backed mention label and subagent-label-first display title.
|
|
74
|
+
*/
|
|
75
|
+
private projectedLabels;
|
|
76
|
+
/**
|
|
77
|
+
* Remote face of {@link listCandidates}: the configured candidate limit
|
|
78
|
+
* applies, and every candidate carries the canonical mention a host inserts
|
|
79
|
+
* into the prompt draft.
|
|
80
|
+
* @param agent - target agent; self is excluded and its cwd drives ranking.
|
|
81
|
+
* @param query - optional case-insensitive session-id/cwd/title substring.
|
|
82
|
+
* @param signal - caller cancellation.
|
|
83
|
+
* @returns mention-carrying candidates in rank order.
|
|
84
|
+
*/
|
|
85
|
+
remoteExportCandidates(agent: Agent, query: string, signal: AbortSignal): Promise<SessionReferenceMentionCandidate[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Snapshot all references for one accepted direct message and return one aggregated durable context.
|
|
88
|
+
* Automatic budgets use the last assembled route, or agent options before any assembly.
|
|
89
|
+
* Missing model capacity or adapter uses 64 KiB; other metadata lookup failures and cancellation reject preparation.
|
|
90
|
+
* Truncated previews include omission facts and a full-snapshot spill locator, or an explicit unavailable notice.
|
|
91
|
+
* Cancellation prevents context publication, including when storage completes after cancellation.
|
|
92
|
+
* @param agent - target agent; references to it are rejected.
|
|
93
|
+
* @param content - already host-normalized readable message content.
|
|
94
|
+
* @param references - structured source sessions in mention order.
|
|
95
|
+
* @param signal - optional cancellation boundary for the active turn.
|
|
96
|
+
* @returns detached content and optional referenced-session context.
|
|
97
|
+
*/
|
|
98
|
+
prepare(agent: Agent, content: ContentBlock[], references: SessionReferenceInput[], signal?: AbortSignal): Promise<PreparedReferencedMessage>;
|
|
99
|
+
private referenceBudget;
|
|
100
|
+
private renderSources;
|
|
101
|
+
}
|
|
102
|
+
export default SessionReferenceResolver;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|