@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,198 @@
1
+ /** Agent activation, composition, and model-selection policy owned by API Session. */
2
+ import type { Context } from '@unieai/cordis';
3
+ import type { Agent, AgentSetup, ModelSelection as AgentModelSelection, ModelSelectionRef } from '@unieai/rabi-agent';
4
+ import type { Session, SessionId } from '@unieai/rabi-session';
5
+ import type { SessionInspection } from '@unieai/rabi-session-persistence';
6
+ import { type SessionObservation } from '@unieai/rabi-session-query';
7
+ import { RemoteError } from '@unieai/rabi-typert-protocol';
8
+ /** Cold Session identity absent from persistence. */
9
+ export declare class ApiSessionNotFound extends Error {
10
+ }
11
+ /** Session identity whose lifecycle belongs to subagent routing. */
12
+ export declare class ApiSessionSubagentOwnership extends Error {
13
+ readonly sessionId: SessionId;
14
+ /** @param sessionId - identity reserved to subagent routing. */
15
+ constructor(sessionId: SessionId);
16
+ }
17
+ /** Explicit-id creation attempted to adopt a Session under another cwd. */
18
+ export declare class ApiSessionCwdConflict extends Error {
19
+ readonly sessionId: SessionId;
20
+ readonly requestedCwd: string;
21
+ readonly existingCwd: string | undefined;
22
+ constructor(sessionId: SessionId, requestedCwd: string, existingCwd: string | undefined);
23
+ }
24
+ /** Reuse of a Session named an Agent preset while the deployment composes no preset roster. */
25
+ export declare class ApiSessionPresetConflict extends Error {
26
+ readonly sessionId: SessionId;
27
+ readonly requestedPreset: string;
28
+ constructor(sessionId: SessionId, requestedPreset: string);
29
+ }
30
+ /** Placement and Agent preset for one Session created for a new conversation. */
31
+ export interface ApiSessionCreateRequest {
32
+ /** Blank Session to reuse, or the identity of a new Session when none is stored under it. */
33
+ readonly sessionId?: SessionId;
34
+ /** Directory the Session owns. */
35
+ readonly cwd: string;
36
+ /** Preset the Session runs; the configured default when omitted. */
37
+ readonly agentPreset?: string;
38
+ /**
39
+ * Placement rule the caller owns, such as Workspace membership and archive state.
40
+ * @param sessionId - existing Session named by the request.
41
+ * @returns whether that Session may be reused.
42
+ */
43
+ readonly reusable: (sessionId: SessionId) => boolean;
44
+ }
45
+ /** The Session one creation request created or reused. */
46
+ export interface ApiSessionCreated {
47
+ /** Live Agent of the Session. */
48
+ readonly agent: Agent;
49
+ /** Preset the Session ran when the request finished, before a later request for the same identity; absent without a roster. */
50
+ readonly agentPreset: string | undefined;
51
+ }
52
+ /** Resolved preset and pre-publication Agent setup for one create or resume. */
53
+ interface ApiSessionComposition {
54
+ readonly agentPreset?: string;
55
+ readonly setup: AgentSetup;
56
+ }
57
+ /** Failures produced while resolving one ordinary Session identity to its live Agent. */
58
+ export type ApiSessionAgentError = RemoteError<'session/not-found' | 'session/agent-busy' | 'session/writer-held' | 'gateway/internal'>;
59
+ /** Result of resolving one ordinary Session identity to its live Agent. */
60
+ export type ApiSessionAgentResult = {
61
+ readonly agent: Agent;
62
+ } | {
63
+ readonly error: ApiSessionAgentError;
64
+ };
65
+ type InstalledSelection = ModelSelectionRef & {
66
+ current: AgentModelSelection;
67
+ consume(provider: string, model: string, reasoningEffort: string | undefined): boolean;
68
+ };
69
+ /**
70
+ * Test whether generic Session routing must leave an identity to subagent routing.
71
+ * @param ctx - Host context carrying the Agent ownership registry.
72
+ * @param session - attached or live Session whose ownership is tested.
73
+ * @param agent - live Agent when one exists for the Session.
74
+ * @returns whether subagent routing owns the Session identity.
75
+ */
76
+ export declare function hasApiSessionSubagentOwner(ctx: Context, session: Pick<Session, 'header'>, agent: Agent | undefined): boolean;
77
+ /**
78
+ * Build the stable caller-facing subagent ownership rejection.
79
+ * @param sessionId - Session identity owned by subagent routing.
80
+ * @returns a stable Session-domain failure.
81
+ */
82
+ export declare function apiSessionSubagentOwnershipError(sessionId: SessionId): ApiSessionAgentError;
83
+ /**
84
+ * Inspect one cold Session without repairing, resuming, or publishing it.
85
+ * @param ctx - Host context carrying Session persistence.
86
+ * @param sessionId - durable Session identity.
87
+ * @param signal - optional cancellation for persistence reads.
88
+ * @returns the persisted header and complete event prefix.
89
+ */
90
+ export declare function inspectApiSession(ctx: Context, sessionId: SessionId, signal?: AbortSignal): Promise<SessionInspection>;
91
+ /** Owns every operation that may create, resume, or configure a Web Agent. */
92
+ export declare class ApiSessionAgentController {
93
+ private readonly ctx;
94
+ private readonly resumes;
95
+ private readonly claims;
96
+ private readonly selections;
97
+ private readonly imageAdmissionChains;
98
+ /** @param ctx - Host context carrying Agent, model, persistence, and Typert services. */
99
+ constructor(ctx: Context);
100
+ /**
101
+ * Resolve or resume one ordinary Session, deduplicating concurrent resumes.
102
+ * @param sessionId - ordinary Session identity.
103
+ * @returns the live Agent or a stable Session-domain failure.
104
+ */
105
+ resolveAgent(sessionId: SessionId): Promise<ApiSessionAgentResult>;
106
+ /**
107
+ * Resolve one ordinary Session from an already-retained exact observation.
108
+ * @param observation - Host-owned observation whose preparation stays pinned through setup.
109
+ * @returns the live Agent or a stable Session-domain failure.
110
+ */
111
+ resolveObservedAgent(observation: SessionObservation): Promise<ApiSessionAgentResult>;
112
+ private resolve;
113
+ /**
114
+ * Create a Session for a new conversation, reusing the named blank Session
115
+ * while it is still reusable. A reused Session runs the requested preset, or
116
+ * the configured default when the request names none; the preset it recorded
117
+ * is not resolved, and a change is logged as `agent-preset/selected` before
118
+ * the Agent is published. A named Session that has started a turn, fails the
119
+ * caller's placement rule, or is written by another owner stays unchanged,
120
+ * and a new Session is created instead. Requests naming one identity run in
121
+ * arrival order, including their preset resolution, and check the named
122
+ * Session's directory and ownership before resolving the preset.
123
+ * @param request - optional Session to reuse, directory, preset, and placement rule.
124
+ * @returns the reused or created Session and the preset it ran when this request finished.
125
+ * @throws ApiSessionCwdConflict when the named Session belongs to another directory.
126
+ * @throws ApiSessionSubagentOwnership when subagent routing owns the named Session.
127
+ * @throws RemoteError `agent-preset/not-found` or `agent-preset/invalid` for the requested or default preset.
128
+ * @throws ApiSessionPresetConflict when no roster is composed and the request names a preset for a reused Session.
129
+ */
130
+ createSession(request: ApiSessionCreateRequest): Promise<ApiSessionCreated>;
131
+ /**
132
+ * Install or return the Session-local model selection used by prompt assembly.
133
+ * @param agent - live Agent that owns the selection.
134
+ * @returns the installed mutable selection reference.
135
+ */
136
+ selectionFor(agent: Agent): InstalledSelection;
137
+ /**
138
+ * Commit and cache one validated selection for the next prompt assembly.
139
+ * @param agent - live Agent that owns the selection.
140
+ * @param selection - validated selection to record and apply.
141
+ */
142
+ selectForNextRequest(agent: Agent, selection: AgentModelSelection): void;
143
+ /**
144
+ * Let a matching durable request header retire the execution cache.
145
+ * @param agent - live Agent whose request was recorded.
146
+ * @param provider - provider route used by the request.
147
+ * @param model - provider-owned model used by the request.
148
+ * @param reasoningEffort - adapter-owned effort used by the request.
149
+ * @returns whether the pending selection was consumed.
150
+ */
151
+ consumeSelection(agent: Agent, provider: string, model: string, reasoningEffort: string | undefined): boolean;
152
+ /**
153
+ * Read the current Agent preset from the Session projection.
154
+ * @param session - live Session whose projection state is available.
155
+ * @returns the current preset, or undefined when the capability is absent.
156
+ */
157
+ presetForSession(session: Session): string | undefined;
158
+ /**
159
+ * Serialize image admission and model selection for one Agent.
160
+ * @param agent - live Agent that owns the serialization chain.
161
+ * @param operation - asynchronous operation admitted after prior work settles.
162
+ * @returns the operation result or rejection.
163
+ */
164
+ serializeImageAdmission<Value>(agent: Agent, operation: () => Promise<Value>): Promise<Value>;
165
+ /**
166
+ * Resolve the preset id and pre-publication Agent setup for a create or resume.
167
+ * @param presetId - requested preset or the configured default when omitted.
168
+ * @returns the resolved preset identity and Agent setup callback.
169
+ */
170
+ composeAgent(presetId: string | undefined): Promise<ApiSessionComposition>;
171
+ private liveAgent;
172
+ private resume;
173
+ private resumeObserved;
174
+ private inOrder;
175
+ /** @returns the reused Session, a new Session under `sessionId` when none is stored, or a new Session under a minted identity. */
176
+ private claim;
177
+ /** @returns the live blank Session under the requested preset, or undefined when it cannot be reused. */
178
+ private reuseLive;
179
+ /** Setup that re-checks blankness under the acquired writer, then records a preset change before publication. */
180
+ private reuseSetup;
181
+ /** Whether no turn has started, by the predicate the preset registry's `select` enforces. */
182
+ private isBlank;
183
+ /** Without a roster, reuse cannot apply a named preset. */
184
+ private assertPresetApplicable;
185
+ private created;
186
+ private createMinted;
187
+ private createAgent;
188
+ private agentOptions;
189
+ private installSelection;
190
+ /**
191
+ * Read the current Agent preset from an all-projections observation.
192
+ * @param observation - exact Session observation carrying its projection snapshot.
193
+ * @returns the current preset, or undefined when the capability is absent.
194
+ */
195
+ presetForObservation(observation: SessionObservation): string | undefined;
196
+ }
197
+ export {};
198
+ //# sourceMappingURL=agent.d.ts.map