@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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/lib/client.js +4325 -0
  4. package/lib/index.js +3367 -0
  5. package/lib/typert.host.d.ts +3 -0
  6. package/lib/typert.host.js +4053 -0
  7. package/lib/typert.remote-client.d.ts +97 -0
  8. package/lib/typert.remote-client.js +2013 -0
  9. package/lib/types/agent.d.ts +198 -0
  10. package/lib/types/agent.js +609 -0
  11. package/lib/types/archived-session-gate.d.ts +30 -0
  12. package/lib/types/archived-session-gate.js +51 -0
  13. package/lib/types/assistant-stream.d.ts +26 -0
  14. package/lib/types/assistant-stream.js +82 -0
  15. package/lib/types/catalog.d.ts +24 -0
  16. package/lib/types/catalog.js +106 -0
  17. package/lib/types/client/contract/events.d.ts +102 -0
  18. package/lib/types/client/contract/events.js +111 -0
  19. package/lib/types/client/contract/session.d.ts +157 -0
  20. package/lib/types/client/contract/session.js +1 -0
  21. package/lib/types/client/contract/sessions.d.ts +161 -0
  22. package/lib/types/client/contract/sessions.js +1 -0
  23. package/lib/types/client/contract/snapshot.d.ts +81 -0
  24. package/lib/types/client/contract/snapshot.js +1 -0
  25. package/lib/types/client/index.d.ts +39 -0
  26. package/lib/types/client/index.js +60 -0
  27. package/lib/types/client/ordered-baseline.d.ts +12 -0
  28. package/lib/types/client/ordered-baseline.js +40 -0
  29. package/lib/types/client/scope.d.ts +46 -0
  30. package/lib/types/client/scope.js +46 -0
  31. package/lib/types/client/session-wire-event.d.ts +11 -0
  32. package/lib/types/client/session-wire-event.js +42 -0
  33. package/lib/types/client/sessions/assistant-stream.d.ts +56 -0
  34. package/lib/types/client/sessions/assistant-stream.js +182 -0
  35. package/lib/types/client/sessions/history-records.d.ts +22 -0
  36. package/lib/types/client/sessions/history-records.js +25 -0
  37. package/lib/types/client/sessions/lineage.d.ts +40 -0
  38. package/lib/types/client/sessions/lineage.js +54 -0
  39. package/lib/types/client/sessions/manager.d.ts +269 -0
  40. package/lib/types/client/sessions/manager.js +799 -0
  41. package/lib/types/client/sessions/notifier.d.ts +39 -0
  42. package/lib/types/client/sessions/notifier.js +97 -0
  43. package/lib/types/client/sessions/projection-store.d.ts +128 -0
  44. package/lib/types/client/sessions/projection-store.js +161 -0
  45. package/lib/types/client/sessions/remotes.d.ts +29 -0
  46. package/lib/types/client/sessions/remotes.js +7 -0
  47. package/lib/types/client/sessions/service.d.ts +258 -0
  48. package/lib/types/client/sessions/service.js +582 -0
  49. package/lib/types/client/sessions/session.d.ts +287 -0
  50. package/lib/types/client/sessions/session.js +866 -0
  51. package/lib/types/client/time-zone.d.ts +8 -0
  52. package/lib/types/client/time-zone.js +13 -0
  53. package/lib/types/client/transport.d.ts +77 -0
  54. package/lib/types/client/transport.js +129 -0
  55. package/lib/types/commands.d.ts +86 -0
  56. package/lib/types/commands.js +624 -0
  57. package/lib/types/control.d.ts +20 -0
  58. package/lib/types/control.js +106 -0
  59. package/lib/types/file-references.d.ts +27 -0
  60. package/lib/types/file-references.js +68 -0
  61. package/lib/types/history.d.ts +32 -0
  62. package/lib/types/history.js +441 -0
  63. package/lib/types/index.d.ts +222 -0
  64. package/lib/types/index.js +658 -0
  65. package/lib/types/list.d.ts +50 -0
  66. package/lib/types/list.js +325 -0
  67. package/lib/types/media-references.d.ts +16 -0
  68. package/lib/types/media-references.js +76 -0
  69. package/lib/types/model-selection-projection.d.ts +8 -0
  70. package/lib/types/model-selection-projection.js +65 -0
  71. package/lib/types/remote-events.d.ts +8 -0
  72. package/lib/types/remote-events.js +1 -0
  73. package/lib/types/skill-catalog.d.ts +28 -0
  74. package/lib/types/skill-catalog.js +203 -0
  75. package/lib/types/types.d.ts +611 -0
  76. package/lib/types/types.js +4 -0
  77. package/locale/en.json +5 -0
  78. package/locale/zh.json +6 -0
  79. package/package.json +114 -4
@@ -0,0 +1,26 @@
1
+ /** Process-local assistant state retained for reconnecting Web followers. */
2
+ import type { AssistantStreamFrame } from '@unieai/rabi-agent';
3
+ import type { SessionSeqCursor } from '@unieai/rabi-session';
4
+ import type { SessionAssistantStreamBaseline } from './types.ts';
5
+ /**
6
+ * Folds dense Agent frames and materializes one shared immutable reconnect
7
+ * baseline per accepted revision.
8
+ */
9
+ export declare class SessionAssistantStreamAccumulator {
10
+ private activeAttempt;
11
+ private revision;
12
+ private snapshotValue;
13
+ private dirty;
14
+ /**
15
+ * Fold one trusted frame from the current attached Agent lifecycle.
16
+ * @param frame - next dense process-local Assistant frame.
17
+ * @param durableCursor - last committed Session seq when this frame was observed.
18
+ */
19
+ accept(frame: AssistantStreamFrame, durableCursor: SessionSeqCursor): void;
20
+ /**
21
+ * Read the cached reconnect baseline, materializing it after a state change.
22
+ * @returns the identity-stable baseline for the latest accepted revision.
23
+ */
24
+ snapshot(): SessionAssistantStreamBaseline;
25
+ }
26
+ //# sourceMappingURL=assistant-stream.d.ts.map
@@ -0,0 +1,82 @@
1
+ /** Process-local assistant state retained for reconnecting Web followers. */
2
+ import { AssistantStreamAccumulator } from '@unieai/rabi-llm';
3
+ const EMPTY_BASELINE = { revision: 0 };
4
+ /**
5
+ * Folds dense Agent frames and materializes one shared immutable reconnect
6
+ * baseline per accepted revision.
7
+ */
8
+ export class SessionAssistantStreamAccumulator {
9
+ activeAttempt;
10
+ revision = 0;
11
+ snapshotValue = EMPTY_BASELINE;
12
+ dirty = false;
13
+ /**
14
+ * Fold one trusted frame from the current attached Agent lifecycle.
15
+ * @param frame - next dense process-local Assistant frame.
16
+ * @param durableCursor - last committed Session seq when this frame was observed.
17
+ */
18
+ accept(frame, durableCursor) {
19
+ if (frame.type === 'start' && frame.revision === 1 && this.revision !== 0) {
20
+ this.activeAttempt = undefined;
21
+ this.revision = 0;
22
+ }
23
+ if (frame.revision !== this.revision + 1) {
24
+ this.activeAttempt = undefined;
25
+ this.revision = frame.revision;
26
+ this.dirty = true;
27
+ return;
28
+ }
29
+ this.revision = frame.revision;
30
+ switch (frame.type) {
31
+ case 'start':
32
+ this.activeAttempt = {
33
+ attemptId: frame.attemptId,
34
+ startedAfterSeq: durableCursor,
35
+ turn: frame.turn,
36
+ step: frame.step,
37
+ stream: new AssistantStreamAccumulator(),
38
+ nextIndex: 0,
39
+ };
40
+ break;
41
+ case 'chunk': {
42
+ const attempt = this.activeAttempt;
43
+ if (attempt === undefined
44
+ || attempt.attemptId !== frame.attemptId
45
+ || frame.index !== attempt.nextIndex) {
46
+ this.activeAttempt = undefined;
47
+ break;
48
+ }
49
+ attempt.stream.push({ time: frame.time, chunk: frame.chunk });
50
+ attempt.nextIndex += 1;
51
+ break;
52
+ }
53
+ case 'end':
54
+ this.activeAttempt = undefined;
55
+ break;
56
+ }
57
+ this.dirty = true;
58
+ }
59
+ /**
60
+ * Read the cached reconnect baseline, materializing it after a state change.
61
+ * @returns the identity-stable baseline for the latest accepted revision.
62
+ */
63
+ snapshot() {
64
+ if (!this.dirty)
65
+ return this.snapshotValue;
66
+ this.snapshotValue = {
67
+ revision: this.revision,
68
+ ...this.activeAttempt === undefined ? {} : {
69
+ activeAttempt: {
70
+ attemptId: this.activeAttempt.attemptId,
71
+ startedAfterSeq: this.activeAttempt.startedAfterSeq,
72
+ turn: this.activeAttempt.turn,
73
+ step: this.activeAttempt.step,
74
+ nextIndex: this.activeAttempt.nextIndex,
75
+ stream: this.activeAttempt.stream.snapshot(),
76
+ },
77
+ },
78
+ };
79
+ this.dirty = false;
80
+ return this.snapshotValue;
81
+ }
82
+ }
@@ -0,0 +1,24 @@
1
+ /** Shared projection of the live LLM registry into the browser model catalog. */
2
+ import type { Context } from '@unieai/cordis';
3
+ import type { ModelCatalog, ModelSelection } from './types.ts';
4
+ /**
5
+ * Build the browser model catalog without requiring a Session.
6
+ * @param ctx - Host context carrying the live LLM registry.
7
+ * @param defaultSelection - deployment default used before a Session selects a model.
8
+ * @returns successful non-empty provider groups and isolated provider failures.
9
+ */
10
+ export declare function buildModelCatalog(ctx: Context, defaultSelection?: ModelSelection): Promise<ModelCatalog>;
11
+ /**
12
+ * Check a GUI selection against the current available provider catalog.
13
+ * @param ctx - Host LLM registry.
14
+ * @param selection - stored or explicitly requested selection.
15
+ * @returns whether the exact model is currently advertised as available.
16
+ */
17
+ export declare function modelAvailable(ctx: Context, selection: ModelSelection): Promise<boolean>;
18
+ /**
19
+ * Check configured provider API-key references independently of model availability.
20
+ * @param ctx - Host registry, settings, and credential services.
21
+ * @returns whether any API-key provider has a configured credential.
22
+ */
23
+ export declare function hasProviderApiKey(ctx: Context): Promise<boolean>;
24
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1,106 @@
1
+ /** Shared projection of the live LLM registry into the browser model catalog. */
2
+ import { RemoteError } from '@unieai/rabi-typert-protocol';
3
+ import { credentialRef } from '@unieai/rabi-credentials';
4
+ /**
5
+ * Build the browser model catalog without requiring a Session.
6
+ * @param ctx - Host context carrying the live LLM registry.
7
+ * @param defaultSelection - deployment default used before a Session selects a model.
8
+ * @returns successful non-empty provider groups and isolated provider failures.
9
+ */
10
+ export async function buildModelCatalog(ctx, defaultSelection = ctx.agentDefaultModel.currentSelection()) {
11
+ const providers = ctx.llm.listProviders();
12
+ const catalog = await Promise.all(providers.map(async (provider) => {
13
+ try {
14
+ const models = await ctx.llm.listModels(provider.id);
15
+ const entries = await Promise.all(models.map(async (model) => {
16
+ const resolved = await ctx.llm.resolveModelInfo(provider.id, model.id);
17
+ const reasoning = resolved.reasoning === undefined
18
+ ? undefined
19
+ : {
20
+ efforts: resolved.reasoning.efforts.map(effort => ({
21
+ id: effort.id,
22
+ name: effort.name,
23
+ ...(effort.description === undefined ? {} : { description: effort.description }),
24
+ })),
25
+ ...(resolved.reasoning.defaultEffort === undefined
26
+ ? {}
27
+ : { defaultEffort: resolved.reasoning.defaultEffort }),
28
+ };
29
+ return {
30
+ id: model.id,
31
+ name: model.name,
32
+ ...(model.description === undefined ? {} : { description: model.description }),
33
+ ...(reasoning === undefined ? {} : { reasoning }),
34
+ };
35
+ }));
36
+ return {
37
+ kind: 'group',
38
+ group: { id: provider.id, name: provider.name, models: entries },
39
+ };
40
+ }
41
+ catch (error) {
42
+ return {
43
+ kind: 'failure',
44
+ failure: {
45
+ id: provider.id,
46
+ name: provider.name,
47
+ message: error instanceof Error ? error.message : String(error),
48
+ },
49
+ };
50
+ }
51
+ }));
52
+ const groups = catalog.flatMap(item => item.kind === 'group' ? [item.group] : [])
53
+ .filter(group => group.models.length > 0);
54
+ return {
55
+ default: { ...defaultSelection },
56
+ routableProviders: groups.map(group => group.id),
57
+ groups,
58
+ failures: catalog.flatMap(item => item.kind === 'failure' ? [item.failure] : []),
59
+ };
60
+ }
61
+ /**
62
+ * Check a GUI selection against the current available provider catalog.
63
+ * @param ctx - Host LLM registry.
64
+ * @param selection - stored or explicitly requested selection.
65
+ * @returns whether the exact model is currently advertised as available.
66
+ */
67
+ export async function modelAvailable(ctx, selection) {
68
+ if (!ctx.llm.listProviders().some(provider => provider.id === selection.provider))
69
+ return false;
70
+ let models;
71
+ try {
72
+ models = await ctx.llm.listModels(selection.provider);
73
+ }
74
+ catch (error) {
75
+ throw new RemoteError('session/model-unavailable', error instanceof Error ? error.message : String(error), { provider: selection.provider, model: selection.model });
76
+ }
77
+ return models.some(model => model.id === selection.model);
78
+ }
79
+ /**
80
+ * Check configured provider API-key references independently of model availability.
81
+ * @param ctx - Host registry, settings, and credential services.
82
+ * @returns whether any API-key provider has a configured credential.
83
+ */
84
+ export async function hasProviderApiKey(ctx) {
85
+ const settings = ctx.get('settings');
86
+ const credentials = ctx.get('credentials');
87
+ if (settings === undefined || credentials === undefined) {
88
+ throw new RemoteError('session/provider-credentials-unavailable', 'provider credentials are unavailable', {});
89
+ }
90
+ const namespaces = settings.describe({ redactSecrets: true });
91
+ for (const provider of ctx.llm.listConfigurableProviders()) {
92
+ if (provider.provider === 'deepseek-account')
93
+ continue;
94
+ let profile = namespaces.find(namespace => namespace.ns === provider.settingsNs)?.value;
95
+ for (const key of provider.settingsPath) {
96
+ profile = typeof profile === 'object' && profile !== null ? Reflect.get(profile, key) : undefined;
97
+ }
98
+ if (typeof profile !== 'object' || profile === null)
99
+ continue;
100
+ const ref = Reflect.get(profile, 'apiKeyEnv');
101
+ if (typeof ref === 'string' && ref.length > 0
102
+ && (await credentials.describe(credentialRef(ref))).configured)
103
+ return true;
104
+ }
105
+ return false;
106
+ }
@@ -0,0 +1,102 @@
1
+ /** Observable contiguous Session event window consumed by domain assemblers. */
2
+ import { type ObservableSnapshot } from '@unieai/rabi-client-store';
3
+ import type { LlmAttemptId, StreamChunk } from '@unieai/rabi-llm';
4
+ import type { SessionEvent } from '@unieai/rabi-session/types';
5
+ /** Client-only live chunk presentation; `seq` orders the transient row between durable Session seqs. */
6
+ export interface AssistantLiveChunkEvent {
7
+ readonly type: 'assistant/live-chunk';
8
+ readonly seq: number;
9
+ readonly time: number;
10
+ readonly data: {
11
+ readonly attemptId: LlmAttemptId;
12
+ readonly turn: number;
13
+ readonly step: number;
14
+ readonly chunk: StreamChunk;
15
+ };
16
+ }
17
+ /** Current durable Session event or one client-only live chunk presentation. */
18
+ export type SessionEventLike = SessionEvent | AssistantLiveChunkEvent;
19
+ /** Client history entry retaining its coarse transport discriminator. */
20
+ export type SessionEventLikeEntry = {
21
+ readonly type: 'event';
22
+ readonly event: SessionEvent;
23
+ } | {
24
+ readonly type: 'transient';
25
+ readonly event: AssistantLiveChunkEvent;
26
+ };
27
+ /** Scalar live entry accepted by append-only Client paths. */
28
+ export type SessionLiveEventEntry = Extract<SessionEventLikeEntry, {
29
+ readonly type: 'event';
30
+ }>;
31
+ /** Durable Assistant event that atomically supersedes one attempt's transient rows. */
32
+ export interface SessionAssistantSettlementEntry {
33
+ readonly type: 'event';
34
+ readonly event: SessionEvent<'assistant/message'> | SessionEvent<'assistant/attempt'>;
35
+ }
36
+ /** Client-only Assistant frame admitted outside durable cursor algebra. */
37
+ export type SessionTransientEventEntry = Extract<SessionEventLikeEntry, {
38
+ readonly type: 'transient';
39
+ }>;
40
+ /** Exact delta that produced the latest event-window revision. */
41
+ export type SessionEventChange = {
42
+ readonly kind: 'replace';
43
+ readonly entries: readonly SessionEventLikeEntry[];
44
+ } | {
45
+ readonly kind: 'prepend';
46
+ readonly entries: readonly SessionEventLikeEntry[];
47
+ } | {
48
+ readonly kind: 'append';
49
+ readonly entries: readonly SessionEventLikeEntry[];
50
+ } | {
51
+ readonly kind: 'settle-assistant';
52
+ readonly attemptId: LlmAttemptId;
53
+ readonly entry?: SessionAssistantSettlementEntry;
54
+ };
55
+ /** Current contiguous event window and its latest synchronous delta. */
56
+ export interface SessionEventWindow {
57
+ readonly entries: readonly SessionEventLikeEntry[];
58
+ readonly hasMore: boolean;
59
+ readonly revision: number;
60
+ readonly change: SessionEventChange;
61
+ }
62
+ /** Conversation-facing event source exposed by one Session binding. */
63
+ export type SessionEventSource = ObservableSnapshot<SessionEventWindow>;
64
+ /** Session-owned event feed; every accepted window mutation publishes synchronously. */
65
+ export declare class MutableSessionEventSource implements SessionEventSource {
66
+ private readonly listeners;
67
+ private window;
68
+ private snapshot;
69
+ /** @returns the cached event-window snapshot. */
70
+ getSnapshot(): SessionEventWindow;
71
+ /**
72
+ * Subscribe to synchronous window publication.
73
+ * @param listener - invalidation callback.
74
+ * @returns unsubscribe function.
75
+ */
76
+ subscribe(listener: () => void): () => void;
77
+ /**
78
+ * Replace the complete contiguous window.
79
+ * @param entries - complete window.
80
+ * @param hasMore - whether older history remains.
81
+ */
82
+ replace(entries: readonly SessionEventLikeEntry[], hasMore: boolean): void;
83
+ /**
84
+ * Prepend one older contiguous page.
85
+ * @param entries - newly loaded older entries.
86
+ * @param hasMore - whether still older history remains.
87
+ */
88
+ prepend(entries: readonly SessionEventLikeEntry[], hasMore: boolean): void;
89
+ /**
90
+ * Append one contiguous live entry.
91
+ * @param entry - live tail entry.
92
+ */
93
+ append(entry: SessionEventLikeEntry): void;
94
+ /**
95
+ * Replace one attempt's transient rows with its committed durable settlement.
96
+ * @param attemptId - process-local attempt whose live rows are now redundant.
97
+ * @param entry - durable settlement committed for that attempt.
98
+ */
99
+ settleAssistant(attemptId: LlmAttemptId, entry?: SessionAssistantSettlementEntry): void;
100
+ private publish;
101
+ }
102
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,111 @@
1
+ /** Observable contiguous Session event window consumed by domain assemblers. */
2
+ import { notifySubscribers } from '@unieai/rabi-client-store';
3
+ function leaf(entries) {
4
+ return { kind: 'leaf', entries, length: entries.length };
5
+ }
6
+ function concat(left, right) {
7
+ return { kind: 'concat', left, right, length: left.length + right.length };
8
+ }
9
+ function materialize(node) {
10
+ if (node.kind === 'leaf')
11
+ return node.entries;
12
+ const entries = new Array(node.length);
13
+ const pending = [node];
14
+ let index = 0;
15
+ while (pending.length > 0) {
16
+ const current = pending.pop();
17
+ if (current.kind === 'concat') {
18
+ pending.push(current.right, current.left);
19
+ continue;
20
+ }
21
+ for (const entry of current.entries) {
22
+ entries[index] = entry;
23
+ index += 1;
24
+ }
25
+ }
26
+ return entries;
27
+ }
28
+ function windowSnapshot(node, hasMore, revision, change) {
29
+ let entries;
30
+ return {
31
+ get entries() {
32
+ entries ??= materialize(node);
33
+ return entries;
34
+ },
35
+ hasMore,
36
+ revision,
37
+ change,
38
+ };
39
+ }
40
+ /** Session-owned event feed; every accepted window mutation publishes synchronously. */
41
+ export class MutableSessionEventSource {
42
+ listeners = new Set();
43
+ window = leaf([]);
44
+ snapshot = windowSnapshot(this.window, false, 0, { kind: 'replace', entries: [] });
45
+ /** @returns the cached event-window snapshot. */
46
+ getSnapshot() { return this.snapshot; }
47
+ /**
48
+ * Subscribe to synchronous window publication.
49
+ * @param listener - invalidation callback.
50
+ * @returns unsubscribe function.
51
+ */
52
+ subscribe(listener) {
53
+ this.listeners.add(listener);
54
+ return () => { this.listeners.delete(listener); };
55
+ }
56
+ /**
57
+ * Replace the complete contiguous window.
58
+ * @param entries - complete window.
59
+ * @param hasMore - whether older history remains.
60
+ */
61
+ replace(entries, hasMore) {
62
+ this.window = leaf(entries);
63
+ this.publish(hasMore, { kind: 'replace', entries });
64
+ }
65
+ /**
66
+ * Prepend one older contiguous page.
67
+ * @param entries - newly loaded older entries.
68
+ * @param hasMore - whether still older history remains.
69
+ */
70
+ prepend(entries, hasMore) {
71
+ this.window = concat(leaf(entries), this.window);
72
+ this.publish(hasMore, { kind: 'prepend', entries });
73
+ }
74
+ /**
75
+ * Append one contiguous live entry.
76
+ * @param entry - live tail entry.
77
+ */
78
+ append(entry) {
79
+ const entries = [entry];
80
+ this.window = concat(this.window, leaf(entries));
81
+ this.publish(this.snapshot.hasMore, {
82
+ kind: 'append',
83
+ entries,
84
+ });
85
+ }
86
+ /**
87
+ * Replace one attempt's transient rows with its committed durable settlement.
88
+ * @param attemptId - process-local attempt whose live rows are now redundant.
89
+ * @param entry - durable settlement committed for that attempt.
90
+ */
91
+ settleAssistant(attemptId, entry) {
92
+ const entries = materialize(this.window).filter(candidate => (candidate.type !== 'transient' || candidate.event.data.attemptId !== attemptId));
93
+ if (entry !== undefined) {
94
+ const index = entries.findIndex(candidate => candidate.event.seq > entry.event.seq);
95
+ if (index < 0)
96
+ entries.push(entry);
97
+ else
98
+ entries.splice(index, 0, entry);
99
+ }
100
+ this.window = leaf(entries);
101
+ this.publish(this.snapshot.hasMore, {
102
+ kind: 'settle-assistant',
103
+ attemptId,
104
+ ...(entry === undefined ? {} : { entry }),
105
+ });
106
+ }
107
+ publish(hasMore, change) {
108
+ this.snapshot = windowSnapshot(this.window, hasMore, this.snapshot.revision + 1, change);
109
+ notifySubscribers(this.listeners, '[session-controller] event feed');
110
+ }
111
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The outward session face. Feature packages never see the concrete Session
3
+ * class: components read lifecycle state through `useSession` (the
4
+ * ObservableSnapshot half), and orchestration code calls the behavior verbs
5
+ * below — nothing else. Widening this interface is the explicit act of
6
+ * widening what features may do to a session (and what every test fixture
7
+ * must stub); implementation-internal entry points (history staging, wire-frame
8
+ * dispatch) stay on the class, invisible out here.
9
+ */
10
+ import type { AttachmentIdType, FileAttachmentRef, ImageAttachmentRef } from '@unieai/rabi-attachment';
11
+ import type { MessageId } from '@unieai/rabi-llm/brand';
12
+ import type { SessionId, SessionSeq } from '@unieai/rabi-session/types';
13
+ import type { RemoteResult } from '@unieai/rabi-typert-protocol';
14
+ import type { ObservableSnapshot } from '@unieai/rabi-client-store';
15
+ import type { PromptContentPart, QueueAction, SessionRequestId } from '../../types.ts';
16
+ import type { PendingSubmissionAttachment, SessionSnapshot } from './snapshot.ts';
17
+ /**
18
+ * Why a local submission echo left the snapshot: `observed` when its durable
19
+ * `user/message` event or host queue occurrence arrived (with the admitted
20
+ * attachment references in prompt order), `failed` when the prompt was rejected,
21
+ * threw, or was aborted before acceptance.
22
+ */
23
+ export type PendingSubmissionRetirement = {
24
+ readonly reason: 'observed';
25
+ readonly attachments: readonly (ImageAttachmentRef | FileAttachmentRef)[];
26
+ } | {
27
+ readonly reason: 'failed';
28
+ };
29
+ /** Input registering one local submission echo ahead of its prompt call. */
30
+ export interface BeginSubmissionInput {
31
+ /** Delivery mode used with the upcoming prompt. */
32
+ readonly mode: 'queue' | 'steer';
33
+ /** Prompt text exactly as the upcoming prompt will send it. */
34
+ readonly text: string;
35
+ /** Ordered image previews and durable file metadata matching the upcoming prompt attachments. */
36
+ readonly attachments: readonly PendingSubmissionAttachment[];
37
+ /** Settlement callback fired exactly once when the echo retires. */
38
+ readonly onRetire?: (retirement: PendingSubmissionRetirement) => void;
39
+ }
40
+ /** One registered submission echo: the identity its prompt must carry, and the pre-prompt escape hatch. */
41
+ export interface SubmissionHandle {
42
+ /** The prompt RPC identity; pass it to {@link ISession.prompt}. */
43
+ readonly requestId: SessionRequestId;
44
+ /** Retire the echo as failed when the caller cannot reach prompt() (serialization failure); no-op after any other settlement. */
45
+ abandon(): void;
46
+ }
47
+ /** Key-addressed projection read face (the useProjection resolution path; see ProjectionValueStore). */
48
+ export interface ProjectionsFace {
49
+ /**
50
+ * The identity-stable bare observable for one projection key (absence is
51
+ * an `undefined` snapshot, never a missing face).
52
+ * @param key - projection key.
53
+ * @returns the key's value face.
54
+ */
55
+ faceOf(key: string): ObservableSnapshot<unknown>;
56
+ }
57
+ /** Identity plus the behavior verbs features may invoke on a session. */
58
+ export interface ISession {
59
+ /** The session's host identity (agent id — same axis). */
60
+ readonly sessionId: SessionId;
61
+ /** Host-computed projection values by key (the useProjection seat). */
62
+ readonly projections: ProjectionsFace;
63
+ /**
64
+ * Register one local submission echo in `snapshot.pendingSubmissions`,
65
+ * synchronously, before the caller serializes and sends the prompt. The
66
+ * Chat echoes persist until durable admission; transcript identities also
67
+ * wait for the Inbox claim watermark so stale queue rows stay suppressed.
68
+ * Queued echoes retire on queue acceptance. Identified failures retire
69
+ * submissions that have not already reached durable admission.
70
+ * @param input - echo content and the optional settlement callback.
71
+ * @returns the minted identity for {@link prompt} plus the pre-prompt abandon path.
72
+ */
73
+ beginSubmission(input: BeginSubmissionInput): SubmissionHandle;
74
+ /**
75
+ * Send a prompt into the session.
76
+ * @param content - text plus browser-owned temporary image uploads.
77
+ * @param mode - 'queue' appends a turn; 'steer' interrupts the running one.
78
+ * @param signal - optional caller cancellation for the complete admission round-trip.
79
+ * @param requestId - identity from {@link beginSubmission}; a failed identified prompt retires its echo.
80
+ * @returns acceptance, or the business error (also mirrored into snapshot.promptError).
81
+ */
82
+ prompt(content: PromptContentPart[], mode: 'queue' | 'steer', signal?: AbortSignal, requestId?: SessionRequestId): Promise<RemoteResult<{
83
+ accepted: true;
84
+ }>>;
85
+ /**
86
+ * Resolve one durable image referenced by this session.
87
+ * @param attachmentId - opaque id found in the folded session log.
88
+ * @returns the authenticated reference and decoded bytes.
89
+ */
90
+ readAttachment(attachmentId: AttachmentIdType): Promise<RemoteResult<{
91
+ attachment: ImageAttachmentRef;
92
+ data: Uint8Array;
93
+ }>>;
94
+ /**
95
+ * Apply one edit, remove, or Steer action to a still-pending queue occurrence.
96
+ * @param itemId - agent-owned inbox occurrence identity.
97
+ * @param action - requested queue operation.
98
+ * @returns acceptance, or a business/transport error.
99
+ */
100
+ updateQueue(itemId: MessageId, action: QueueAction): Promise<RemoteResult<{
101
+ accepted: true;
102
+ }>>;
103
+ /**
104
+ * Cancel the running turn. Pending queued work remains and resumes in FIFO
105
+ * order after the Host reaches cancellation quiescence.
106
+ * @returns acceptance, or the business error.
107
+ */
108
+ cancel(): Promise<RemoteResult<{
109
+ accepted: true;
110
+ }>>;
111
+ /**
112
+ * Rename this session (explicit user title; pins it against automatic
113
+ * regeneration).
114
+ * @param title - raw title text (the host normalizes acceptance).
115
+ * @returns the normalized accepted title and its event seq, or the business error.
116
+ */
117
+ rename(title: string): Promise<RemoteResult<{
118
+ title: string;
119
+ seq: SessionSeq;
120
+ }>>;
121
+ /**
122
+ * Extend history by at least 50 messages and two Turn starts, including a
123
+ * partial Turn at the window's beginning. Stop at 500 messages or history
124
+ * exhaustion even when those minima cannot be met. Publish one prepend.
125
+ * @returns completion; failures land in snapshot.openState/loadingOlder.
126
+ */
127
+ loadOlder(): Promise<void>;
128
+ /**
129
+ * Page history backwards until the window covers `seq` (inclusive) — the
130
+ * turn-jump loader. Repeated calls while a jump is paging lower its shared
131
+ * target and return the in-flight completion; `snapshot.loadingOlder` is
132
+ * the busy signal for the whole jump.
133
+ * Each page uses the same Turn alignment as loadOlder, with a 200-message
134
+ * minimum. The 500-message limit applies per page, not to the whole jump.
135
+ * Older pages publish together at completion, including successful pages
136
+ * before a later failure; live events remain independently visible.
137
+ * @param seq - durable event seq the window must reach (a turn's `turn/start` seq).
138
+ * @returns completion once covered, exhausted, superseded, or failed soft.
139
+ */
140
+ loadThrough(seq: SessionSeq): Promise<void>;
141
+ /**
142
+ * Execute one slash-command line against this session's agent — pure
143
+ * admission semantics (the host executor durably logs the lifecycle).
144
+ * @param line - the full command line, leading slash included.
145
+ * @returns the admission result, or the Remote face's error branch.
146
+ */
147
+ command(line: string): Promise<RemoteResult<{
148
+ matched: boolean;
149
+ }>>;
150
+ }
151
+ /**
152
+ * The full outward face: behavior verbs plus the Session lifecycle read side
153
+ * (the `useSession` hook source). This is the type carried by
154
+ * `SessionBinding.session` and the provide channel.
155
+ */
156
+ export type SessionFace = ISession & ObservableSnapshot<SessionSnapshot>;
157
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ export {};