@unieai/rabi-api-session-controller 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/client.js +4325 -0
- package/lib/index.js +3367 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +4053 -0
- package/lib/typert.remote-client.d.ts +97 -0
- package/lib/typert.remote-client.js +2013 -0
- package/lib/types/agent.d.ts +198 -0
- package/lib/types/agent.js +609 -0
- package/lib/types/archived-session-gate.d.ts +30 -0
- package/lib/types/archived-session-gate.js +51 -0
- package/lib/types/assistant-stream.d.ts +26 -0
- package/lib/types/assistant-stream.js +82 -0
- package/lib/types/catalog.d.ts +24 -0
- package/lib/types/catalog.js +106 -0
- package/lib/types/client/contract/events.d.ts +102 -0
- package/lib/types/client/contract/events.js +111 -0
- package/lib/types/client/contract/session.d.ts +157 -0
- package/lib/types/client/contract/session.js +1 -0
- package/lib/types/client/contract/sessions.d.ts +161 -0
- package/lib/types/client/contract/sessions.js +1 -0
- package/lib/types/client/contract/snapshot.d.ts +81 -0
- package/lib/types/client/contract/snapshot.js +1 -0
- package/lib/types/client/index.d.ts +39 -0
- package/lib/types/client/index.js +60 -0
- package/lib/types/client/ordered-baseline.d.ts +12 -0
- package/lib/types/client/ordered-baseline.js +40 -0
- package/lib/types/client/scope.d.ts +46 -0
- package/lib/types/client/scope.js +46 -0
- package/lib/types/client/session-wire-event.d.ts +11 -0
- package/lib/types/client/session-wire-event.js +42 -0
- package/lib/types/client/sessions/assistant-stream.d.ts +56 -0
- package/lib/types/client/sessions/assistant-stream.js +182 -0
- package/lib/types/client/sessions/history-records.d.ts +22 -0
- package/lib/types/client/sessions/history-records.js +25 -0
- package/lib/types/client/sessions/lineage.d.ts +40 -0
- package/lib/types/client/sessions/lineage.js +54 -0
- package/lib/types/client/sessions/manager.d.ts +269 -0
- package/lib/types/client/sessions/manager.js +799 -0
- package/lib/types/client/sessions/notifier.d.ts +39 -0
- package/lib/types/client/sessions/notifier.js +97 -0
- package/lib/types/client/sessions/projection-store.d.ts +128 -0
- package/lib/types/client/sessions/projection-store.js +161 -0
- package/lib/types/client/sessions/remotes.d.ts +29 -0
- package/lib/types/client/sessions/remotes.js +7 -0
- package/lib/types/client/sessions/service.d.ts +258 -0
- package/lib/types/client/sessions/service.js +582 -0
- package/lib/types/client/sessions/session.d.ts +287 -0
- package/lib/types/client/sessions/session.js +866 -0
- package/lib/types/client/time-zone.d.ts +8 -0
- package/lib/types/client/time-zone.js +13 -0
- package/lib/types/client/transport.d.ts +77 -0
- package/lib/types/client/transport.js +129 -0
- package/lib/types/commands.d.ts +86 -0
- package/lib/types/commands.js +624 -0
- package/lib/types/control.d.ts +20 -0
- package/lib/types/control.js +106 -0
- package/lib/types/file-references.d.ts +27 -0
- package/lib/types/file-references.js +68 -0
- package/lib/types/history.d.ts +32 -0
- package/lib/types/history.js +441 -0
- package/lib/types/index.d.ts +222 -0
- package/lib/types/index.js +658 -0
- package/lib/types/list.d.ts +50 -0
- package/lib/types/list.js +325 -0
- package/lib/types/media-references.d.ts +16 -0
- package/lib/types/media-references.js +76 -0
- package/lib/types/model-selection-projection.d.ts +8 -0
- package/lib/types/model-selection-projection.js +65 -0
- package/lib/types/remote-events.d.ts +8 -0
- package/lib/types/remote-events.js +1 -0
- package/lib/types/skill-catalog.d.ts +28 -0
- package/lib/types/skill-catalog.js +203 -0
- package/lib/types/types.d.ts +611 -0
- package/lib/types/types.js +4 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +114 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outward sessions-service face — what `ctx.sessions` exposes to feature
|
|
3
|
+
* packages. Transport entry points and implementation internals stay on
|
|
4
|
+
* the concrete class. Widening this interface is the
|
|
5
|
+
* explicit act of widening what features may do to the sessions domain.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@unieai/cordis';
|
|
8
|
+
import type { SubagentAddress } from '@unieai/rabi-subagent/client';
|
|
9
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
10
|
+
import type { WorkspaceId } from '@unieai/rabi-workspace/types';
|
|
11
|
+
import type { RemoteResult } from '@unieai/rabi-typert-protocol';
|
|
12
|
+
import type { AgentContext } from '../scope.ts';
|
|
13
|
+
import type { SessionSearchResultItem } from '../sessions/manager.ts';
|
|
14
|
+
import type { SessionBinding, SessionListState } from '../sessions/service.ts';
|
|
15
|
+
import type { SessionFace } from './session.ts';
|
|
16
|
+
import type { ObservableSnapshot } from '@unieai/rabi-client-store';
|
|
17
|
+
import type { SessionReferenceSource } from '../index.ts';
|
|
18
|
+
export type { AgentContext } from '../scope.ts';
|
|
19
|
+
/** Known Session identity or durable direct-parent subagent address; an address owns no lifetime. */
|
|
20
|
+
export type SessionTarget = SessionId | SubagentAddress;
|
|
21
|
+
/** One independent use of an exact Client generation, without Host Agent ownership. */
|
|
22
|
+
export interface SessionReference extends Disposable {
|
|
23
|
+
readonly sessionId: SessionId;
|
|
24
|
+
/** Shared binding; access fails after reference release or generation disposal. */
|
|
25
|
+
readonly binding: SessionBinding;
|
|
26
|
+
/** This reference's cancellable wait for the shared initial `Session.open()` attempt to settle. */
|
|
27
|
+
readonly ready: Promise<SessionBinding>;
|
|
28
|
+
/** Release once; the final reference starts local scope and history teardown. */
|
|
29
|
+
release(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Consumer identity and optional cancellation of one acquisition waiter. */
|
|
32
|
+
export interface SessionRetainOptions {
|
|
33
|
+
readonly source: SessionReferenceSource;
|
|
34
|
+
readonly signal?: AbortSignal | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** Local ownership counts, independent of catalog membership and never persisted. */
|
|
37
|
+
export interface SessionRetainInfo {
|
|
38
|
+
readonly referenceCount: number;
|
|
39
|
+
/** Positive source counts only; a source without references is absent. */
|
|
40
|
+
readonly retainedBy: Readonly<Partial<Record<SessionReferenceSource, number>>>;
|
|
41
|
+
}
|
|
42
|
+
/** The sessions-service face injected as `ctx.sessions`. */
|
|
43
|
+
export interface ISessions {
|
|
44
|
+
/** Host catalog and local reference-source counts; navigation belongs to view owners. */
|
|
45
|
+
readonly list: ObservableSnapshot<SessionListState>;
|
|
46
|
+
/**
|
|
47
|
+
* Retain an exact Client generation and start its shared initial history opening.
|
|
48
|
+
* @param target - known identity or durable direct-parent address.
|
|
49
|
+
* @param options - required consumer source and optional independent waiter cancellation.
|
|
50
|
+
* @returns an owned reference immediately; await `reference.ready` when the initial open attempt must settle first.
|
|
51
|
+
*/
|
|
52
|
+
retain(target: SessionTarget, options: SessionRetainOptions): SessionReference;
|
|
53
|
+
/**
|
|
54
|
+
* Hold one reference through callback settlement, including synchronous and asynchronous failures.
|
|
55
|
+
* @param target - Session to acquire.
|
|
56
|
+
* @param options - source and acquisition cancellation.
|
|
57
|
+
* @param operation - callback using the reference only until its returned value or Promise settles.
|
|
58
|
+
* @returns the callback result after release; acquisition and callback failures propagate unchanged.
|
|
59
|
+
*/
|
|
60
|
+
using<T>(target: SessionTarget, options: SessionRetainOptions, operation: (reference: SessionReference) => T | Promise<T>): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Observe local reference counts without retaining, creating a scope, or opening history.
|
|
63
|
+
* The returned source keeps stable identity across same-id generations and remains allocated
|
|
64
|
+
* until the Client root is disposed, even after its final subscriber leaves.
|
|
65
|
+
* @param id - explicit Session identity; Host existence is not implied.
|
|
66
|
+
* @returns a stable read-only source across same-id generations, with zero counts when none is live.
|
|
67
|
+
*/
|
|
68
|
+
retainInfo(id: SessionId): ObservableSnapshot<SessionRetainInfo>;
|
|
69
|
+
/**
|
|
70
|
+
* The `session.search` result bound the wire schema fixes, exposed to
|
|
71
|
+
* presentation as injected data. Not per-connection state: every transport
|
|
72
|
+
* (fixture included) reports the same number.
|
|
73
|
+
*/
|
|
74
|
+
readonly searchResultLimit: number;
|
|
75
|
+
/**
|
|
76
|
+
* Create a Session for a new conversation on the Host. The Host reuses the
|
|
77
|
+
* named blank Session while it is reusable and otherwise creates another; the
|
|
78
|
+
* Session runs the named preset, or the Host default when none is named.
|
|
79
|
+
* @param opts - target workspace or directory, an optional blank Session to reuse, and an optional Agent preset.
|
|
80
|
+
* @returns the catalogued identity the Host created or reused; retain it before borrowing its binding.
|
|
81
|
+
*/
|
|
82
|
+
create(opts?: {
|
|
83
|
+
workspaceId?: WorkspaceId;
|
|
84
|
+
cwd?: string;
|
|
85
|
+
sessionId?: SessionId;
|
|
86
|
+
agentPreset?: string;
|
|
87
|
+
}): Promise<SessionId>;
|
|
88
|
+
/**
|
|
89
|
+
* Resolve an already discovered direct-parent address without opening it.
|
|
90
|
+
* @param id - possible addressed child id.
|
|
91
|
+
* @returns a retained, catalog-derived, or unknown-mode listed address, without retaining a new selection or scope.
|
|
92
|
+
*/
|
|
93
|
+
subagentAddress(id: SessionId): SubagentAddress | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Read projections without starting migration; retry failed or migration-deferred reads.
|
|
96
|
+
* @param sessionId - Session to inspect without opening its conversation.
|
|
97
|
+
* @returns completion of the current or newly started refresh.
|
|
98
|
+
*/
|
|
99
|
+
refreshProjections(sessionId: SessionId): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Refresh the Host-authoritative Session list.
|
|
102
|
+
* @returns completion of the current or newly started Session-list refresh.
|
|
103
|
+
*/
|
|
104
|
+
refresh(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Search the Host's visible message-content index. Results stay
|
|
107
|
+
* request-local; the list snapshot remains the metadata authority.
|
|
108
|
+
* @param query - non-blank literal phrase.
|
|
109
|
+
* @param signal - cancellation for a superseded search.
|
|
110
|
+
* @returns bounded results, or a business/transport error.
|
|
111
|
+
*/
|
|
112
|
+
search(query: string, signal: AbortSignal): Promise<RemoteResult<{
|
|
113
|
+
items: SessionSearchResultItem[];
|
|
114
|
+
hasMore: boolean;
|
|
115
|
+
}>>;
|
|
116
|
+
/**
|
|
117
|
+
* Fork a session from an exact inclusive prefix of the source; on
|
|
118
|
+
* resolution the child is catalogued and can be explicitly retained.
|
|
119
|
+
* @param opts - source session id, the optional exact inclusive boundary
|
|
120
|
+
* seq (a real event seq the caller already knows; a cut inside an open
|
|
121
|
+
* turn is balanced Host-side with synthetic closers, and omission selects
|
|
122
|
+
* the latest completed-turn prefix), and whether to increment an
|
|
123
|
+
* inherited durable title before resolving. `onCreated` observes the catalogued child before that optional rename.
|
|
124
|
+
* @returns the child session id.
|
|
125
|
+
* @throws when the fork fails, or when a requested child-title rename fails after creation.
|
|
126
|
+
*/
|
|
127
|
+
fork(opts: {
|
|
128
|
+
sessionId: SessionId;
|
|
129
|
+
atSeq?: number;
|
|
130
|
+
increaseTitle?: boolean;
|
|
131
|
+
onCreated?: (childId: SessionId) => void;
|
|
132
|
+
/** False refuses source migration; omission preserves the Host default. */
|
|
133
|
+
allowMigration?: boolean;
|
|
134
|
+
}): Promise<SessionId>;
|
|
135
|
+
/**
|
|
136
|
+
* Borrow an already-retained Agent-scoped Context without extending its lifetime.
|
|
137
|
+
* @param id - session id.
|
|
138
|
+
* @returns the live scoped Context, or undefined without a retained generation.
|
|
139
|
+
*/
|
|
140
|
+
scope(id: SessionId): AgentContext | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Read the Agent scope tag off a context (service-method boundary: fetch
|
|
143
|
+
* bundles must reach scope resolution through ctx.sessions).
|
|
144
|
+
* @param ctx - any client context.
|
|
145
|
+
* @returns the session id, or undefined on root contexts.
|
|
146
|
+
*/
|
|
147
|
+
scopeOf(ctx: Context): SessionId | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Resolve the session face behind an Agent-scoped context.
|
|
150
|
+
* @param ctx - an Agent-scoped context.
|
|
151
|
+
* @returns the matching live Session, or undefined for an untagged, foreign, or ended generation.
|
|
152
|
+
*/
|
|
153
|
+
sessionOf(ctx: Context): SessionFace | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Borrow an already-retained Session binding without extending its lifetime.
|
|
156
|
+
* @param id - session id.
|
|
157
|
+
* @returns the live binding, or undefined without a retained generation.
|
|
158
|
+
*/
|
|
159
|
+
binding(id: SessionId): SessionBinding | undefined;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=sessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Session-owned observable state excluding Conversation target data. */
|
|
2
|
+
import type { FileAttachmentRef } from '@unieai/rabi-attachment';
|
|
3
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
4
|
+
import type { SubagentAddress } from '@unieai/rabi-subagent/client';
|
|
5
|
+
import type { RemoteFailure } from '@unieai/rabi-typert-protocol';
|
|
6
|
+
import type { SessionRequestId } from '../../types.ts';
|
|
7
|
+
/** One image displayed by a local submission echo before durable admission. */
|
|
8
|
+
export interface PendingSubmissionImage {
|
|
9
|
+
/** Browser-owned preview URL; its lifecycle belongs to the submitter, never this snapshot. */
|
|
10
|
+
readonly previewUrl: string;
|
|
11
|
+
/** Browser file name, when the file had one. */
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
/** Intrinsic pixel width, when the submitter has probed it. */
|
|
14
|
+
readonly width?: number;
|
|
15
|
+
/** Intrinsic pixel height, when the submitter has probed it. */
|
|
16
|
+
readonly height?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Image branch of a local submission echo attachment. */
|
|
19
|
+
export interface PendingSubmissionImageAttachment {
|
|
20
|
+
readonly type: 'image';
|
|
21
|
+
readonly value: PendingSubmissionImage;
|
|
22
|
+
}
|
|
23
|
+
/** File branch of a local submission echo attachment. */
|
|
24
|
+
export interface PendingSubmissionFileAttachment {
|
|
25
|
+
readonly type: 'file';
|
|
26
|
+
readonly value: FileAttachmentRef;
|
|
27
|
+
}
|
|
28
|
+
/** One attachment displayed by a local submission echo, in prompt order. */
|
|
29
|
+
export type PendingSubmissionAttachment = PendingSubmissionImageAttachment | PendingSubmissionFileAttachment;
|
|
30
|
+
/** Client surface selected when a local submission begins. */
|
|
31
|
+
export type PendingSubmissionPlacement = 'transcript' | 'queued' | 'steering';
|
|
32
|
+
/**
|
|
33
|
+
* One local prompt-submission echo: inserted synchronously when a submission
|
|
34
|
+
* begins, so the conversation can show the message before serialization,
|
|
35
|
+
* transport, and durable admission complete. Client-memory only — reload and
|
|
36
|
+
* reconnect rebuild the conversation from durable events alone.
|
|
37
|
+
*/
|
|
38
|
+
export interface PendingSubmission {
|
|
39
|
+
/** The prompt RPC identity; the durable `user/message` source echoes it as `rpcId`. */
|
|
40
|
+
readonly requestId: SessionRequestId;
|
|
41
|
+
/** Surface fixed at submission time; Inbox acceptance does not move a Chat echo into the dock. */
|
|
42
|
+
readonly placement: PendingSubmissionPlacement;
|
|
43
|
+
/** Client wall-clock ms when the submission began. */
|
|
44
|
+
readonly time: number;
|
|
45
|
+
/** Prompt text exactly as it will be sent (one text block). */
|
|
46
|
+
readonly text: string;
|
|
47
|
+
/** Ordered image previews and durable file metadata matching the prompt attachments. */
|
|
48
|
+
readonly attachments: readonly PendingSubmissionAttachment[];
|
|
49
|
+
}
|
|
50
|
+
/** History-open lifecycle of a Session event window. */
|
|
51
|
+
export type OpenState = 'cold' | 'loading' | 'open' | 'error';
|
|
52
|
+
/** Send/stop failure surfaced by Session consumers. */
|
|
53
|
+
export interface PromptError {
|
|
54
|
+
readonly op: 'send' | 'stop';
|
|
55
|
+
readonly error: RemoteFailure;
|
|
56
|
+
}
|
|
57
|
+
/** Immutable Session lifecycle and control snapshot. */
|
|
58
|
+
export interface SessionSnapshot {
|
|
59
|
+
readonly sessionId: SessionId;
|
|
60
|
+
/** Local prompt-submission echoes not yet observed as durable events or queue occurrences. */
|
|
61
|
+
readonly pendingSubmissions: readonly PendingSubmission[];
|
|
62
|
+
readonly running: boolean;
|
|
63
|
+
readonly subagent: {
|
|
64
|
+
readonly address: SubagentAddress;
|
|
65
|
+
/** Absent until the direct-parent catalog resolves. */
|
|
66
|
+
readonly parentAvailable?: boolean;
|
|
67
|
+
} | null;
|
|
68
|
+
readonly removed: boolean;
|
|
69
|
+
readonly openState: OpenState;
|
|
70
|
+
readonly openError: RemoteFailure | null;
|
|
71
|
+
readonly hasMore: boolean;
|
|
72
|
+
readonly loadingOlder: boolean;
|
|
73
|
+
readonly promptError: PromptError | null;
|
|
74
|
+
readonly blank: boolean;
|
|
75
|
+
readonly lastAgentError: string | null;
|
|
76
|
+
/** A prompt call has begun on this Client Session object. */
|
|
77
|
+
readonly promptAttempted: boolean;
|
|
78
|
+
/** The first accepted prompt has not reached a durable `turn/start` event. */
|
|
79
|
+
readonly awaitingFirstTurn: boolean;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Client Session object layer, Agent scopes, and Remote lifecycle wiring. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
export { createSessionControlStream, SessionEventStream, SESSION_SEARCH_RESULT_LIMIT, SESSION_SEARCH_SNIPPET_MAX_CODE_POINTS, } from './transport.ts';
|
|
4
|
+
export type { ClientSessionPageRequest, SessionControlStream, SessionControlStreamOptions, SessionEventStreamOptions, SessionJournalChange, SessionRemote, } from './transport.ts';
|
|
5
|
+
export { createScope, scopeOf } from './scope.ts';
|
|
6
|
+
export type { AgentContext, AgentScopeHandle } from './scope.ts';
|
|
7
|
+
export { SessionCreateError, SessionForkError } from './sessions/service.ts';
|
|
8
|
+
export type { SessionBinding, SessionListState, SessionSummary } from './sessions/service.ts';
|
|
9
|
+
export type { SessionListPhase, SessionListSnapshot, SessionSearchResultItem, SessionProjectionSnapshot, } from './sessions/manager.ts';
|
|
10
|
+
export type { Session } from './sessions/session.ts';
|
|
11
|
+
export type { ProjectionsBaseline, ProjectionValueStore, SessionProjectionMap, UseProjection, } from './sessions/projection-store.ts';
|
|
12
|
+
export type { BeginSubmissionInput, ISession, PendingSubmissionRetirement, ProjectionsFace, SessionFace, SubmissionHandle, } from './contract/session.ts';
|
|
13
|
+
export type { ISessions, SessionReference, SessionRetainInfo, SessionRetainOptions, SessionTarget, } from './contract/sessions.ts';
|
|
14
|
+
export { MutableSessionEventSource } from './contract/events.ts';
|
|
15
|
+
export type { AssistantLiveChunkEvent, SessionAssistantSettlementEntry, SessionEventChange, SessionEventLike, SessionEventLikeEntry, SessionEventSource, SessionEventWindow, SessionLiveEventEntry, SessionTransientEventEntry, } from './contract/events.ts';
|
|
16
|
+
export type { OpenState, PendingSubmission, PendingSubmissionAttachment, PendingSubmissionFileAttachment, PendingSubmissionImage, PendingSubmissionImageAttachment, PendingSubmissionPlacement, PromptError, SessionSnapshot, } from './contract/snapshot.ts';
|
|
17
|
+
/** Consumer-owned reference labels; extend this map through the package's canonical /client entry. */
|
|
18
|
+
export interface SessionReferenceSourceMap {
|
|
19
|
+
/** Temporary Client Controller work, including fork-title preparation. */
|
|
20
|
+
controllerOperation: unknown;
|
|
21
|
+
/** A Client Gateway invocation's synchronous Context ownership. */
|
|
22
|
+
gateway: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** Declaration-merge-extensible labels carried by independent Client references. */
|
|
25
|
+
export type SessionReferenceSource = Extract<keyof SessionReferenceSourceMap, string>;
|
|
26
|
+
declare module '@unieai/cordis' {
|
|
27
|
+
interface Context {
|
|
28
|
+
/** Client Session object layer and Agent scope owner. */
|
|
29
|
+
sessions: import('./contract/sessions.ts').ISessions;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Required Remote and Context projection services. */
|
|
33
|
+
export declare const inject: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Install Client Session state and its reconnecting control stream.
|
|
36
|
+
* @param ctx - Client Cordis context.
|
|
37
|
+
*/
|
|
38
|
+
export declare function apply(ctx: Context): void;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Client Session object layer, Agent scopes, and Remote lifecycle wiring. */
|
|
2
|
+
import { typertOwnedValue } from '@unieai/rabi-typert-protocol';
|
|
3
|
+
import { createSessionControlStream } from "./transport.js";
|
|
4
|
+
import { ClientSessions } from "./sessions/service.js";
|
|
5
|
+
export { createSessionControlStream, SessionEventStream, SESSION_SEARCH_RESULT_LIMIT, SESSION_SEARCH_SNIPPET_MAX_CODE_POINTS, } from "./transport.js";
|
|
6
|
+
export { createScope, scopeOf } from "./scope.js";
|
|
7
|
+
export { SessionCreateError, SessionForkError } from "./sessions/service.js";
|
|
8
|
+
export { MutableSessionEventSource } from "./contract/events.js";
|
|
9
|
+
/** Required Remote and Context projection services. */
|
|
10
|
+
export const inject = [
|
|
11
|
+
'connection',
|
|
12
|
+
'fileUpload',
|
|
13
|
+
'typert',
|
|
14
|
+
'remote',
|
|
15
|
+
'remote.commands',
|
|
16
|
+
'remote.session',
|
|
17
|
+
'remote.subagents',
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Install Client Session state and its reconnecting control stream.
|
|
21
|
+
* @param ctx - Client Cordis context.
|
|
22
|
+
*/
|
|
23
|
+
export function apply(ctx) {
|
|
24
|
+
const remotes = ctx.remote;
|
|
25
|
+
const connection = ctx.get('connection');
|
|
26
|
+
const sessions = new ClientSessions(ctx, remotes);
|
|
27
|
+
ctx.remote.$on('api-session/added', (summary) => { sessions.handleSessionAdded(summary); });
|
|
28
|
+
ctx.remote.$on('api-session/removed', (sessionId) => { sessions.handleSessionRemoved(sessionId); });
|
|
29
|
+
ctx.remote.$on('api-session/status', (sessionId, running) => {
|
|
30
|
+
sessions.handleSessionStatus(sessionId, running);
|
|
31
|
+
});
|
|
32
|
+
ctx.remote.$on('api-session/activity', (sessionId, updatedAt) => {
|
|
33
|
+
sessions.handleSessionActivity(sessionId, updatedAt);
|
|
34
|
+
});
|
|
35
|
+
ctx.remote.$on('api-session/error', (sessionId, message) => {
|
|
36
|
+
sessions.handleSessionError(sessionId, message);
|
|
37
|
+
});
|
|
38
|
+
const control = createSessionControlStream(remotes, {
|
|
39
|
+
accept: (frame) => { sessions.handleControlFrame(frame); },
|
|
40
|
+
failed: (error) => { console.error('[session-controller] control stream failed:', error); },
|
|
41
|
+
});
|
|
42
|
+
const connected = () => {
|
|
43
|
+
if (connection.generation.getSnapshot() === undefined)
|
|
44
|
+
return;
|
|
45
|
+
// A ready control baseline may arrive before Cordis delivers connection/reset.
|
|
46
|
+
sessions.handleConnected();
|
|
47
|
+
control.restart();
|
|
48
|
+
control.start();
|
|
49
|
+
};
|
|
50
|
+
ctx.effect(() => connection.generation.subscribe(connected), 'session-controller.client.generation');
|
|
51
|
+
connected();
|
|
52
|
+
ctx.typert.contexts.registerClient('agent', {
|
|
53
|
+
identity: candidate => sessions.sessionOf(candidate)?.sessionId,
|
|
54
|
+
resolve: (sessionId) => {
|
|
55
|
+
const reference = sessions.retainAgentScope(sessionId);
|
|
56
|
+
return typertOwnedValue(reference.binding.ctx, () => { reference.release(); });
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
ctx.effect(() => async () => { await control.dispose(); }, 'session-controller.client.control');
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge an authoritative baseline without moving identities already visible to
|
|
3
|
+
* the client. Baseline-only identities are inserted relative to the nearest
|
|
4
|
+
* following known identity; identities absent from the baseline are removed.
|
|
5
|
+
*
|
|
6
|
+
* @param current - the established client order.
|
|
7
|
+
* @param baseline - the latest authoritative rows.
|
|
8
|
+
* @param keyOf - stable identity selector.
|
|
9
|
+
* @returns baseline-valued rows with the established relative order retained.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeOrderedBaseline<T>(current: readonly T[], baseline: readonly T[], keyOf: (value: T) => unknown): T[];
|
|
12
|
+
//# sourceMappingURL=ordered-baseline.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge an authoritative baseline without moving identities already visible to
|
|
3
|
+
* the client. Baseline-only identities are inserted relative to the nearest
|
|
4
|
+
* following known identity; identities absent from the baseline are removed.
|
|
5
|
+
*
|
|
6
|
+
* @param current - the established client order.
|
|
7
|
+
* @param baseline - the latest authoritative rows.
|
|
8
|
+
* @param keyOf - stable identity selector.
|
|
9
|
+
* @returns baseline-valued rows with the established relative order retained.
|
|
10
|
+
*/
|
|
11
|
+
export function mergeOrderedBaseline(current, baseline, keyOf) {
|
|
12
|
+
const baselineByKey = new Map();
|
|
13
|
+
for (const value of baseline)
|
|
14
|
+
baselineByKey.set(keyOf(value), value);
|
|
15
|
+
const merged = current
|
|
16
|
+
.map(value => baselineByKey.get(keyOf(value)))
|
|
17
|
+
.filter((value) => value !== undefined);
|
|
18
|
+
const mergedKeys = new Set(merged.map(keyOf));
|
|
19
|
+
for (let index = 0; index < baseline.length; index++) {
|
|
20
|
+
const value = baseline[index];
|
|
21
|
+
/* v8 ignore next -- dense-array guard: index is bounded by baseline.length. */
|
|
22
|
+
if (value === undefined || mergedKeys.has(keyOf(value)))
|
|
23
|
+
continue;
|
|
24
|
+
let insertion = merged.length;
|
|
25
|
+
for (let following = index + 1; following < baseline.length; following++) {
|
|
26
|
+
const candidate = baseline[following];
|
|
27
|
+
/* v8 ignore next -- dense-array guard: following is bounded by baseline.length. */
|
|
28
|
+
if (candidate === undefined)
|
|
29
|
+
continue;
|
|
30
|
+
const known = merged.findIndex(item => keyOf(item) === keyOf(candidate));
|
|
31
|
+
if (known !== -1) {
|
|
32
|
+
insertion = known;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
merged.splice(insertion, 0, value);
|
|
37
|
+
mergedKeys.add(keyOf(value));
|
|
38
|
+
}
|
|
39
|
+
return merged;
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Context, Fiber } from '@unieai/cordis';
|
|
2
|
+
import type { ClientRemote } from '@unieai/rabi-api-gateway/client';
|
|
3
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
4
|
+
import type { TypertRemoteScopeApi } from '@unieai/rabi-typert-protocol';
|
|
5
|
+
/** Client Cordis Context carrying one Agent identity and its scoped Remote namespaces. */
|
|
6
|
+
export type AgentContext = Omit<Context, 'remote'> & {
|
|
7
|
+
readonly remote: ClientRemote & TypertRemoteScopeApi<'agent'>;
|
|
8
|
+
};
|
|
9
|
+
interface ScopeIdentity {
|
|
10
|
+
readonly sessionId: SessionId;
|
|
11
|
+
}
|
|
12
|
+
/** A minted Agent scope and its disposal boundary. */
|
|
13
|
+
export interface AgentScopeHandle {
|
|
14
|
+
/**
|
|
15
|
+
* Tagged context: scope-owned registrations and scoped dispatch both go
|
|
16
|
+
* through it (passing it as the dispatch subject routes to this generation's
|
|
17
|
+
* tagged listeners plus every untagged one).
|
|
18
|
+
*/
|
|
19
|
+
ctx: AgentContext;
|
|
20
|
+
/** Backing fiber (dispose tears down every scope-owned registration). */
|
|
21
|
+
fiber: Fiber;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Mint an Agent scope under `ctx`: a no-op plugin fiber whose context
|
|
25
|
+
* carries the agent tag and the dispatch filter — untagged listeners are
|
|
26
|
+
* admitted globally, tagged listeners only for the same Client generation.
|
|
27
|
+
* Registrations through the returned ctx dispose with the fiber.
|
|
28
|
+
* @param ctx - client root context the scope fiber mounts under.
|
|
29
|
+
* @param key - durable Session identity carried by this generation.
|
|
30
|
+
* @returns the tagged context and its backing fiber.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createScope(ctx: Context, key: SessionId): AgentScopeHandle;
|
|
33
|
+
/**
|
|
34
|
+
* Read the nearest agent tag inherited by a context.
|
|
35
|
+
* @param ctx - any client context.
|
|
36
|
+
* @returns its agent identity (the session id), or undefined for root contexts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function scopeOf(ctx: Context): SessionId | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Read the exact generation identity inherited by a Client Context.
|
|
41
|
+
* @param ctx - scoped or root Client Context.
|
|
42
|
+
* @returns the generation identity, or undefined for an unscoped Context.
|
|
43
|
+
*/
|
|
44
|
+
export declare function scopeIdentityOf(ctx: Context): ScopeIdentity | undefined;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Client scope generations route local events independently of Host Agent residency. */
|
|
2
|
+
import { Context as CordisContext } from '@unieai/cordis';
|
|
3
|
+
/** Context tag written by {@link createScope}. */
|
|
4
|
+
const kScope = Symbol('rabi.client.scope');
|
|
5
|
+
/** Shared no-op plugin backing each Agent scope fiber. */
|
|
6
|
+
function agentScope() { }
|
|
7
|
+
/**
|
|
8
|
+
* Mint an Agent scope under `ctx`: a no-op plugin fiber whose context
|
|
9
|
+
* carries the agent tag and the dispatch filter — untagged listeners are
|
|
10
|
+
* admitted globally, tagged listeners only for the same Client generation.
|
|
11
|
+
* Registrations through the returned ctx dispose with the fiber.
|
|
12
|
+
* @param ctx - client root context the scope fiber mounts under.
|
|
13
|
+
* @param key - durable Session identity carried by this generation.
|
|
14
|
+
* @returns the tagged context and its backing fiber.
|
|
15
|
+
*/
|
|
16
|
+
export function createScope(ctx, key) {
|
|
17
|
+
const fiber = ctx.plugin(agentScope);
|
|
18
|
+
const identity = { sessionId: key };
|
|
19
|
+
const scoped = fiber.ctx.extend({
|
|
20
|
+
[kScope]: identity,
|
|
21
|
+
[CordisContext.filter](listenerCtx) {
|
|
22
|
+
const tag = scopeIdentityOf(listenerCtx);
|
|
23
|
+
return tag === undefined || tag === identity;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
fiber,
|
|
28
|
+
ctx: scoped,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read the nearest agent tag inherited by a context.
|
|
33
|
+
* @param ctx - any client context.
|
|
34
|
+
* @returns its agent identity (the session id), or undefined for root contexts.
|
|
35
|
+
*/
|
|
36
|
+
export function scopeOf(ctx) {
|
|
37
|
+
return scopeIdentityOf(ctx)?.sessionId;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read the exact generation identity inherited by a Client Context.
|
|
41
|
+
* @param ctx - scoped or root Client Context.
|
|
42
|
+
* @returns the generation identity, or undefined for an unscoped Context.
|
|
43
|
+
*/
|
|
44
|
+
export function scopeIdentityOf(ctx) {
|
|
45
|
+
return ctx[kScope];
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Event-local acceptance for raw Session journal responses; payloads remain owner-defined JSON. */
|
|
2
|
+
import type { SessionWireEvent } from '../types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Reject non-current event envelopes without stripping or normalizing wire fields.
|
|
5
|
+
* Range membership and source existence require the durable log and remain Host-owned.
|
|
6
|
+
* @param value - one event received in a follow frame or history page.
|
|
7
|
+
* @returns nothing after narrowing the accepted event envelope.
|
|
8
|
+
* @throws when the envelope or current event-local metadata is invalid.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertSessionWireEvent(value: unknown): asserts value is SessionWireEvent;
|
|
11
|
+
//# sourceMappingURL=session-wire-event.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Event-local acceptance for raw Session journal responses; payloads remain owner-defined JSON. */
|
|
2
|
+
import { validateSessionEventData, validateSurfaceMetadata } from '@unieai/rabi-session/surface';
|
|
3
|
+
/**
|
|
4
|
+
* Reject non-current event envelopes without stripping or normalizing wire fields.
|
|
5
|
+
* Range membership and source existence require the durable log and remain Host-owned.
|
|
6
|
+
* @param value - one event received in a follow frame or history page.
|
|
7
|
+
* @returns nothing after narrowing the accepted event envelope.
|
|
8
|
+
* @throws when the envelope or current event-local metadata is invalid.
|
|
9
|
+
*/
|
|
10
|
+
export function assertSessionWireEvent(value) {
|
|
11
|
+
const subject = 'session wire event';
|
|
12
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
13
|
+
throw new Error(`${subject} must be an object`);
|
|
14
|
+
}
|
|
15
|
+
const event = value;
|
|
16
|
+
for (const key of Object.keys(event)) {
|
|
17
|
+
switch (key) {
|
|
18
|
+
case 'type':
|
|
19
|
+
case 'seq':
|
|
20
|
+
case 'time':
|
|
21
|
+
case 'data':
|
|
22
|
+
case 'ignorable':
|
|
23
|
+
case 'surfaceOp':
|
|
24
|
+
case 'sourceEventSeqs':
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`${subject} has unexpected field ${key}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const seq = event['seq'];
|
|
31
|
+
if (typeof event['type'] !== 'string'
|
|
32
|
+
|| typeof seq !== 'number' || !Number.isSafeInteger(seq) || seq < 0 || Object.is(seq, -0)
|
|
33
|
+
|| typeof event['time'] !== 'number' || !Number.isSafeInteger(event['time'])
|
|
34
|
+
|| !Object.hasOwn(event, 'data') || event['data'] === undefined
|
|
35
|
+
|| (Object.hasOwn(event, 'ignorable') && event['ignorable'] !== true)) {
|
|
36
|
+
throw new Error(`${subject} has an invalid envelope`);
|
|
37
|
+
}
|
|
38
|
+
// Event names and payloads are merge-extensible; only event-local owner rules run here.
|
|
39
|
+
const current = event;
|
|
40
|
+
validateSurfaceMetadata(current);
|
|
41
|
+
validateSessionEventData(current, subject);
|
|
42
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Web presentation fold joining transient Assistant frames to one durable v2 settlement. */
|
|
2
|
+
import type { SessionAssistantStreamBaseline, SessionAssistantStreamFrame } from '../../types.ts';
|
|
3
|
+
import type { LlmAttemptId } from '@unieai/rabi-llm/brand';
|
|
4
|
+
import type { SessionAssistantSettlementEntry, SessionEventLikeEntry, SessionLiveEventEntry, SessionTransientEventEntry } from '../contract/events.ts';
|
|
5
|
+
/** One Web publication decision from the assistant stream fold. */
|
|
6
|
+
export type ClientAssistantStreamResult = {
|
|
7
|
+
readonly type: 'publish';
|
|
8
|
+
readonly entry: SessionLiveEventEntry;
|
|
9
|
+
/** Retire the successful attempt's transient rows after publishing its Step end. */
|
|
10
|
+
readonly retireAttemptId?: LlmAttemptId;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'settlement';
|
|
13
|
+
readonly attemptId: LlmAttemptId;
|
|
14
|
+
readonly entry: SessionAssistantSettlementEntry;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: 'abandonment';
|
|
17
|
+
readonly attemptId: LlmAttemptId;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: 'transient';
|
|
20
|
+
readonly entry: SessionTransientEventEntry;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: 'rebaseline';
|
|
23
|
+
} | undefined;
|
|
24
|
+
/** Keeps transient Assistant presentation behind one settlement-aware interface. */
|
|
25
|
+
export declare class ClientAssistantStream {
|
|
26
|
+
private activeAttempt;
|
|
27
|
+
private retainedAttempt;
|
|
28
|
+
private readonly pending;
|
|
29
|
+
private publishedSeqs;
|
|
30
|
+
private durableCursor;
|
|
31
|
+
private transientInGap;
|
|
32
|
+
/**
|
|
33
|
+
* Replace the durable Web window and adopt an optional reconnect baseline.
|
|
34
|
+
* @param entries - durable entries in the replacement window.
|
|
35
|
+
* @param baseline - compact prefix for an Assistant attempt that is still live.
|
|
36
|
+
* @returns immediately visible durable entries plus reconstructed transient chunks.
|
|
37
|
+
*/
|
|
38
|
+
replace(entries: readonly SessionEventLikeEntry[], baseline?: SessionAssistantStreamBaseline): readonly SessionEventLikeEntry[];
|
|
39
|
+
/**
|
|
40
|
+
* Stage one durable v2 settlement while its matching live attempt is open.
|
|
41
|
+
* @param entry - newly followed durable entry.
|
|
42
|
+
* @returns a publication decision, or `undefined` when no entry becomes visible.
|
|
43
|
+
*/
|
|
44
|
+
acceptDurable(entry: SessionLiveEventEntry): ClientAssistantStreamResult;
|
|
45
|
+
/**
|
|
46
|
+
* Fold one dense transient frame and release its named durable settlement.
|
|
47
|
+
* Successful messages retain their transient rows until the owning Step ends;
|
|
48
|
+
* interrupted messages, failed attempts, and abandonment retire them immediately.
|
|
49
|
+
* @param frame - next Assistant stream frame received by the follow connection.
|
|
50
|
+
* @returns a transient, publication, or rebaseline decision, or `undefined` when no entry becomes visible.
|
|
51
|
+
*/
|
|
52
|
+
acceptFrame(frame: SessionAssistantStreamFrame): ClientAssistantStreamResult;
|
|
53
|
+
private attemptForSettlement;
|
|
54
|
+
private publish;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=assistant-stream.d.ts.map
|