@vinaverse/client 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (41) hide show
  1. package/README.md +46 -0
  2. package/dist/agent/index.cjs +2852 -0
  3. package/dist/agent/index.cjs.map +1 -0
  4. package/dist/agent/index.d.cts +57 -0
  5. package/dist/agent/index.d.ts +57 -0
  6. package/dist/agent/index.js +99 -0
  7. package/dist/agent/index.js.map +1 -0
  8. package/dist/{chunk-MKUNSAMT.js → chunk-GWLLUOFY.js} +3 -9
  9. package/dist/chunk-GWLLUOFY.js.map +1 -0
  10. package/dist/chunk-VSJDVLCP.js +9 -0
  11. package/dist/chunk-VSJDVLCP.js.map +1 -0
  12. package/dist/chunk-XPES5PZ3.js +416 -0
  13. package/dist/chunk-XPES5PZ3.js.map +1 -0
  14. package/dist/chunk-ZWG2TMUL.js +975 -0
  15. package/dist/chunk-ZWG2TMUL.js.map +1 -0
  16. package/dist/contract-_NMdPjgN.d.cts +6 -0
  17. package/dist/contract-_NMdPjgN.d.ts +6 -0
  18. package/dist/conversation/index.cjs +1 -1
  19. package/dist/conversation/index.cjs.map +1 -1
  20. package/dist/conversation/index.d.cts +6 -377
  21. package/dist/conversation/index.d.ts +6 -377
  22. package/dist/conversation/index.js +5 -973
  23. package/dist/conversation/index.js.map +1 -1
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +2 -1
  26. package/dist/index.d.ts +2 -1
  27. package/dist/index.js +2 -1
  28. package/dist/runtime-CErMdYxJ.d.cts +234 -0
  29. package/dist/runtime-DLJbJkSr.d.ts +234 -0
  30. package/dist/{session-C3qZwGPG.d.cts → session-8W3fRNeb.d.cts} +1514 -253
  31. package/dist/{session-C3qZwGPG.d.ts → session-8W3fRNeb.d.ts} +1514 -253
  32. package/dist/store-C7FtS5AY.d.cts +384 -0
  33. package/dist/store-DFk0ayh8.d.ts +384 -0
  34. package/dist/testing/index.cjs +237 -0
  35. package/dist/testing/index.cjs.map +1 -0
  36. package/dist/testing/index.d.cts +49 -0
  37. package/dist/testing/index.d.ts +49 -0
  38. package/dist/testing/index.js +222 -0
  39. package/dist/testing/index.js.map +1 -0
  40. package/package.json +33 -1
  41. package/dist/chunk-MKUNSAMT.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- export { A as AnswerInput, l as AuthMode, b as CONTRACT, c as Card, f as CardKind, h as ClientErrorCode, m as ClientEvent, C as ClientSecret, n as Connection, o as ConversationEngine, p as ConversationState, F as FetchLike, q as Frame, H as HeldCard, i as HeldQuestion, M as Message, j as Proposal, P as ProposalOutcome, Q as Question, R as Reconnect, r as ServerEvent, s as ServerEventOf, t as ServerEventType, u as SessionEvents, S as SessionInfo, a as SessionOptions, v as SessionStatus, w as SseTarget, T as ToolLine, x as TranscriptItem, y as TurnInput, V as VinaverseClientError, z as VinaverseSession, B as WebSocketFactory, D as WebSocketLike, E as cardActionSse, k as isKnownCard, G as sseFrames, I as turnSse } from './session-C3qZwGPG.cjs';
1
+ export { C as CONTRACT } from './contract-_NMdPjgN.cjs';
2
+ export { A as AnswerInput, h as AuthMode, a as Card, d as CardKind, e as ClientErrorCode, j as ClientEvent, k as ClientSecret, l as Connection, m as ConversationEngine, n as ConversationState, F as FetchLike, o as Frame, H as HeldCard, f as HeldQuestion, M as Message, P as Proposal, g as ProposalOutcome, Q as Question, R as Reconnect, S as Schemas, p as ServerEvent, q as ServerEventOf, r as ServerEventType, s as SessionEvents, t as SessionInfo, u as SessionOptions, v as SessionStatus, w as SseTarget, T as ToolLine, x as TranscriptItem, y as TurnInput, V as VinaverseClientError, z as VinaverseSession, B as WebSocketFactory, D as WebSocketLike, E as cardActionSse, G as components, i as isKnownCard, I as operations, J as paths, K as sseFrames, L as turnSse } from './session-8W3fRNeb.cjs';
2
3
 
3
4
  /**
4
5
  * The client secret, checked: an app holds only the session's `vv_cs_` secret, which the tenant's backend got from
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { A as AnswerInput, l as AuthMode, b as CONTRACT, c as Card, f as CardKind, h as ClientErrorCode, m as ClientEvent, C as ClientSecret, n as Connection, o as ConversationEngine, p as ConversationState, F as FetchLike, q as Frame, H as HeldCard, i as HeldQuestion, M as Message, j as Proposal, P as ProposalOutcome, Q as Question, R as Reconnect, r as ServerEvent, s as ServerEventOf, t as ServerEventType, u as SessionEvents, S as SessionInfo, a as SessionOptions, v as SessionStatus, w as SseTarget, T as ToolLine, x as TranscriptItem, y as TurnInput, V as VinaverseClientError, z as VinaverseSession, B as WebSocketFactory, D as WebSocketLike, E as cardActionSse, k as isKnownCard, G as sseFrames, I as turnSse } from './session-C3qZwGPG.js';
1
+ export { C as CONTRACT } from './contract-_NMdPjgN.js';
2
+ export { A as AnswerInput, h as AuthMode, a as Card, d as CardKind, e as ClientErrorCode, j as ClientEvent, k as ClientSecret, l as Connection, m as ConversationEngine, n as ConversationState, F as FetchLike, o as Frame, H as HeldCard, f as HeldQuestion, M as Message, P as Proposal, g as ProposalOutcome, Q as Question, R as Reconnect, S as Schemas, p as ServerEvent, q as ServerEventOf, r as ServerEventType, s as SessionEvents, t as SessionInfo, u as SessionOptions, v as SessionStatus, w as SseTarget, T as ToolLine, x as TranscriptItem, y as TurnInput, V as VinaverseClientError, z as VinaverseSession, B as WebSocketFactory, D as WebSocketLike, E as cardActionSse, G as components, i as isKnownCard, I as operations, J as paths, K as sseFrames, L as turnSse } from './session-8W3fRNeb.js';
2
3
 
3
4
  /**
4
5
  * The client secret, checked: an app holds only the session's `vv_cs_` secret, which the tenant's backend got from
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
- export { CONTRACT, ConversationEngine, VinaverseClientError, VinaverseSession, cardActionSse, clientSecret, isKnownCard, sseFrames, turnSse } from './chunk-MKUNSAMT.js';
1
+ export { CONTRACT } from './chunk-VSJDVLCP.js';
2
+ export { ConversationEngine, VinaverseClientError, VinaverseSession, cardActionSse, clientSecret, isKnownCard, sseFrames, turnSse } from './chunk-GWLLUOFY.js';
2
3
  //# sourceMappingURL=index.js.map
3
4
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,234 @@
1
+ import { S as SessionRequest, b as ConversationSession, C as ConversationStore, a as ConversationOptions } from './store-C7FtS5AY.cjs';
2
+ import { S as Schemas } from './session-8W3fRNeb.cjs';
3
+
4
+ /** Whose conversation: a person (null for a guest), the app's side, the business acted for, and the thread. */
5
+ interface AgentKey {
6
+ readonly subject: string | null;
7
+ readonly mode: string;
8
+ readonly scope?: string | null;
9
+ /** Default `chat`; a flow of its own (a business setup, say) is another thread. */
10
+ readonly thread?: string;
11
+ }
12
+ type ScreenContext = Schemas['ScreenContext'];
13
+ /**
14
+ * Where the person asks from, in the contract's vocabulary (`ScreenContext`: the screen, the entity, the filters): told
15
+ * to the agent as data (`Session.screen_context`), never as their words. The tenant's backend vouches for it.
16
+ */
17
+ interface AgentPlace {
18
+ readonly screen: ScreenContext['screen'];
19
+ readonly entity?: {
20
+ readonly type: string;
21
+ readonly id: string;
22
+ } | null;
23
+ readonly filters?: ScreenContext['filters'];
24
+ }
25
+ /** What the runtime asks the tenant's backend for: a session, for this key, told this place. */
26
+ interface AgentSessionRequest extends SessionRequest {
27
+ readonly key: AgentKey;
28
+ readonly place: AgentPlace | null;
29
+ /** How the person came in (`button`, `inbox`, …): the app's own words, passed through. */
30
+ readonly entryPoint: string | null;
31
+ }
32
+ /** Why there is no session, typed, so an app never needs sentinel errors of its own. */
33
+ type AgentFailureReason =
34
+ /** The conversation asked for is over: not theirs, deleted (404), or past the time it is kept (410). */
35
+ 'ended'
36
+ /** The person's sign-in was refused by the tenant's API. */
37
+ | 'auth'
38
+ /** The agent is switched off for this tenant, mode or person. */
39
+ | 'off' | 'rate_limited'
40
+ /** No network, a timeout: retried, then said. */
41
+ | 'network'
42
+ /** The tenant's API or Vinaverse failed (5xx): retried, then said. */
43
+ | 'server'
44
+ /** The backend answered with a session the runtime will not use (not wss://, a field missing). */
45
+ | 'invalid_session' | 'unknown';
46
+ /**
47
+ * A refusal from the backend, typed: `ended` (the conversation is over; a new one starts only when the person asks) or
48
+ * `unavailable` with its reason. An error with `retryable: true` (and its `reason`, `network` by default) is waited out
49
+ * by the retry policy, then said as `unreachable`.
50
+ */
51
+ declare class AgentRefusal extends Error {
52
+ readonly kind: 'ended' | 'unavailable';
53
+ readonly reason: AgentFailureReason;
54
+ readonly code: string | null;
55
+ constructor(kind: 'ended' | 'unavailable', options?: {
56
+ readonly reason?: AgentFailureReason;
57
+ readonly code?: string;
58
+ readonly message?: string;
59
+ });
60
+ }
61
+ interface AgentStatus {
62
+ readonly available: boolean;
63
+ /** The floating launcher may show. */
64
+ readonly launcher: boolean;
65
+ readonly displayName: string | null;
66
+ readonly avatarUrl: string | null;
67
+ readonly features: {
68
+ readonly history: boolean;
69
+ readonly memory: boolean;
70
+ readonly businessAgent: boolean;
71
+ readonly businessSetup: boolean;
72
+ };
73
+ }
74
+ /** The status as the backend reads it; what it leaves out is off. */
75
+ interface AgentStatusRead {
76
+ readonly available: boolean;
77
+ readonly launcher?: boolean;
78
+ readonly displayName?: string | null;
79
+ readonly avatarUrl?: string | null;
80
+ readonly features?: Partial<AgentStatus['features']>;
81
+ }
82
+ /** The tenant's backend: the one piece of integration an app writes. */
83
+ interface AgentBackend {
84
+ /** A session from the tenant's API (it creates it at Vinaverse with its service key), or an `AgentRefusal`. */
85
+ openSession(request: AgentSessionRequest): Promise<ConversationSession>;
86
+ /** A fresh client secret for the same session (before its end). */
87
+ refreshSecret?(sessionId: string): Promise<string>;
88
+ /**
89
+ * The person's place changed while the chat is open: the tenant's backend tells Vinaverse
90
+ * (`PUT /v1/sessions/{id}/context`). Absent, or refused, the kit offers a question about the new place instead.
91
+ */
92
+ updateContext?(sessionId: string, place: AgentPlace, revision: number): Promise<void>;
93
+ /** Whether the agent is offered, and what it can do. Absent: available, nothing extra. */
94
+ status?(signal?: AbortSignal): Promise<AgentStatusRead>;
95
+ /** A thumbs on a whole reply; best effort, never an error for the person. */
96
+ sendFeedback?(feedback: {
97
+ readonly sessionId: string;
98
+ readonly turnId: string;
99
+ readonly rating: AgentRating;
100
+ }): Promise<void>;
101
+ /** Sign-out: end the person's open sessions at the tenant's API. */
102
+ endSessions?(): Promise<void>;
103
+ }
104
+ type AgentRating = 'up' | 'down';
105
+ type AgentFailure = 'ended' | 'unreachable' | 'unavailable';
106
+ type AgentEventType = 'session_opened' | 'session_resumed' | 'session_retried' | 'session_failed' | 'conversation_ended' | 'context_updated' | 'rated' | 'chip_tapped' | 'card_action' | 'target_opened' | 'link_opened' | 'launcher_shown' | 'launcher_opened' | 'launcher_greeted' | 'greeting_closed';
107
+ /** For the app's analytics: what happened, for which conversation, with nothing the person said. */
108
+ interface AgentEvent {
109
+ readonly type: AgentEventType;
110
+ readonly key?: string;
111
+ readonly sessionId?: string;
112
+ readonly failure?: AgentFailure;
113
+ readonly reason?: AgentFailureReason;
114
+ readonly attempt?: number;
115
+ readonly turnId?: string;
116
+ readonly rating?: AgentRating;
117
+ readonly cardId?: string;
118
+ readonly kind?: string;
119
+ /** Where the person opened from (`entryPoint`, the screen). */
120
+ readonly from?: string;
121
+ }
122
+ /** What a UI draws around the store: why there is no session, whether the person moved, the thumbs given. */
123
+ interface AgentConversationState {
124
+ readonly failure: AgentFailure | null;
125
+ readonly reason: AgentFailureReason | null;
126
+ /** The API's own code for the failure (`conversation_expired`, …), when it gave one. */
127
+ readonly code: string | null;
128
+ /** The session was told another place than the one the person now asks from, and it could not be told live. */
129
+ readonly moved: boolean;
130
+ readonly ratings: ReadonlyMap<string, AgentRating>;
131
+ readonly sessionId: string | null;
132
+ }
133
+ interface AgentConversation {
134
+ /** The key as a string, for the app's own maps and the events. */
135
+ readonly key: string;
136
+ readonly store: ConversationStore;
137
+ /**
138
+ * A view attaches: kept, with its connection, while any view is attached. The first time, it starts. Returns the
139
+ * detach: with no view attached it is suspended (no pings; closed with `closeInBackground`) while its session lives
140
+ * (`keepAlive: 'session'`), and let go when it has none, is past its end, or `keepAlive` is `'view'`. Separate from the
141
+ * app's background, which the platform adapter tells the store.
142
+ */
143
+ show(open?: {
144
+ readonly place?: AgentPlace | null;
145
+ readonly entryPoint?: string | null;
146
+ }): () => void;
147
+ /** The place and the way in changed while a view is attached: told live where the backend can, else on the next session. */
148
+ tell(open: {
149
+ readonly place?: AgentPlace | null;
150
+ readonly entryPoint?: string | null;
151
+ }): void;
152
+ getState(): AgentConversationState;
153
+ subscribe(listener: () => void): () => void;
154
+ /** Asks for a session again, after the backend could not be reached. */
155
+ retry(): void;
156
+ /** A thumbs on a whole reply; a change of mind only is sent again. */
157
+ rate(turnId: string, rating: AgentRating): void;
158
+ /**
159
+ * Sends the person's `text` once in this conversation's life (a chip tapped twice, a retried tap). It is shown as
160
+ * theirs: only words they typed or tapped, never the app's in their name.
161
+ */
162
+ sendOnce(text: string): void;
163
+ }
164
+ /** When the runtime tries the backend again: before each try, a delay; `isRetryable` decides which errors are waited out. */
165
+ interface AgentRetryPolicy {
166
+ readonly delays: readonly number[];
167
+ readonly isRetryable?: (error: unknown) => boolean;
168
+ }
169
+ /** The time the runtime judges a session's end by: the server's, when the app has it (a clock synced from responses). */
170
+ interface AgentClock {
171
+ now(): number;
172
+ }
173
+ interface AgentRuntimeOptions {
174
+ readonly backend: AgentBackend;
175
+ /** The store's own options (locale, time zone, deep-link prefixes, transport, persistence, closeInBackground…). */
176
+ readonly conversation?: Omit<ConversationOptions, 'getSession' | 'refreshSecret' | 'clock'>;
177
+ /** Default: 500, 1500, 3500 ms, for errors with `retryable: true`; applied to `openSession` and `refreshSecret`. */
178
+ readonly retry?: AgentRetryPolicy;
179
+ /** Default: the device's clock. Give the server's: a phone set wrong otherwise reuses a dead session or drops a live one. */
180
+ readonly clock?: AgentClock;
181
+ /** `session` (default): kept while its session lives with no view attached; `view`: let go when the last view goes. */
182
+ readonly keepAlive?: 'session' | 'view';
183
+ /** How long a status read stays fresh. Default 5 minutes. */
184
+ readonly statusStaleMs?: number;
185
+ /**
186
+ * DANGEROUS: for mocks and local development only. Lets a leg's session address be plaintext (`ws://`, `http://`),
187
+ * which would carry the person's messages and the session's secret unencrypted. Off by default, whatever transport
188
+ * the app supplies; outside `__DEV__` the runtime warns once.
189
+ */
190
+ readonly insecureAddresses?: AgentInsecureAddresses;
191
+ readonly onEvent?: (event: AgentEvent) => void;
192
+ /** Where the runtime's warnings go (the app's logger, crash reporter); default `console.warn`. */
193
+ readonly onWarning?: (message: string) => void;
194
+ }
195
+ /** The legs whose session address may be plaintext: `realtime` (the WebSocket), `turns` (HTTP). */
196
+ interface AgentInsecureAddresses {
197
+ readonly realtime?: boolean;
198
+ readonly turns?: boolean;
199
+ }
200
+ interface AgentRuntime {
201
+ /** The key's conversation: the same while it lives; a new one after `startNew`, `dispose` or its end. */
202
+ conversation(key: AgentKey): AgentConversation;
203
+ /**
204
+ * The key's conversation as it stands, ending nothing and telling no one: for a render (`useSyncExternalStore`).
205
+ * One past its session's end is ended when it is next shown, and subscribers then read the key's next one.
206
+ */
207
+ peek(key: AgentKey): AgentConversation;
208
+ /** A new conversation for the key from the person's next opening; the old one is let go and forgotten. */
209
+ startNew(key: AgentKey): void;
210
+ /** Closes the key's conversation now and drops every reference to it; the next opening continues it in a new session. */
211
+ dispose(key: AgentKey): void;
212
+ /**
213
+ * The key goes on with this conversation (history's "Continue"): pinned for the key and opened through the backend's
214
+ * resume. One that is gone (404, 410: the backend's `AgentRefusal('ended')`) is said as `ended`, never replaced by a
215
+ * new one silently.
216
+ */
217
+ continue(key: AgentKey, conversationId: string): AgentConversation;
218
+ /** Every conversation closed and forgotten (what the device kept too), and the backend told to end the sessions. */
219
+ signOut(): Promise<void>;
220
+ /** The agent's status, read from the backend at most every `statusStaleMs`. */
221
+ status(): Promise<AgentStatus>;
222
+ getStatus(): AgentStatus | null;
223
+ /** The agent's name: from the newest session, else from the status. */
224
+ getName(): string | null;
225
+ /** Told when the status or name changes, and when a key's conversation is let go (its next one is another). */
226
+ subscribe(listener: () => void): () => void;
227
+ /** An event from a kit or the app, passed to `onEvent`. */
228
+ emit(event: AgentEvent): void;
229
+ }
230
+ /** The key as a string: one conversation per person, mode, business and thread. */
231
+ declare function agentKey(key: AgentKey): string;
232
+ declare function createAgentRuntime(options: AgentRuntimeOptions): AgentRuntime;
233
+
234
+ export { type AgentBackend as A, type AgentClock as a, type AgentConversation as b, type AgentConversationState as c, type AgentEvent as d, type AgentEventType as e, type AgentFailure as f, type AgentFailureReason as g, type AgentInsecureAddresses as h, type AgentKey as i, type AgentPlace as j, type AgentRating as k, AgentRefusal as l, type AgentRetryPolicy as m, type AgentRuntime as n, type AgentRuntimeOptions as o, type AgentSessionRequest as p, type AgentStatus as q, type AgentStatusRead as r, agentKey as s, createAgentRuntime as t };
@@ -0,0 +1,234 @@
1
+ import { S as SessionRequest, b as ConversationSession, C as ConversationStore, a as ConversationOptions } from './store-DFk0ayh8.js';
2
+ import { S as Schemas } from './session-8W3fRNeb.js';
3
+
4
+ /** Whose conversation: a person (null for a guest), the app's side, the business acted for, and the thread. */
5
+ interface AgentKey {
6
+ readonly subject: string | null;
7
+ readonly mode: string;
8
+ readonly scope?: string | null;
9
+ /** Default `chat`; a flow of its own (a business setup, say) is another thread. */
10
+ readonly thread?: string;
11
+ }
12
+ type ScreenContext = Schemas['ScreenContext'];
13
+ /**
14
+ * Where the person asks from, in the contract's vocabulary (`ScreenContext`: the screen, the entity, the filters): told
15
+ * to the agent as data (`Session.screen_context`), never as their words. The tenant's backend vouches for it.
16
+ */
17
+ interface AgentPlace {
18
+ readonly screen: ScreenContext['screen'];
19
+ readonly entity?: {
20
+ readonly type: string;
21
+ readonly id: string;
22
+ } | null;
23
+ readonly filters?: ScreenContext['filters'];
24
+ }
25
+ /** What the runtime asks the tenant's backend for: a session, for this key, told this place. */
26
+ interface AgentSessionRequest extends SessionRequest {
27
+ readonly key: AgentKey;
28
+ readonly place: AgentPlace | null;
29
+ /** How the person came in (`button`, `inbox`, …): the app's own words, passed through. */
30
+ readonly entryPoint: string | null;
31
+ }
32
+ /** Why there is no session, typed, so an app never needs sentinel errors of its own. */
33
+ type AgentFailureReason =
34
+ /** The conversation asked for is over: not theirs, deleted (404), or past the time it is kept (410). */
35
+ 'ended'
36
+ /** The person's sign-in was refused by the tenant's API. */
37
+ | 'auth'
38
+ /** The agent is switched off for this tenant, mode or person. */
39
+ | 'off' | 'rate_limited'
40
+ /** No network, a timeout: retried, then said. */
41
+ | 'network'
42
+ /** The tenant's API or Vinaverse failed (5xx): retried, then said. */
43
+ | 'server'
44
+ /** The backend answered with a session the runtime will not use (not wss://, a field missing). */
45
+ | 'invalid_session' | 'unknown';
46
+ /**
47
+ * A refusal from the backend, typed: `ended` (the conversation is over; a new one starts only when the person asks) or
48
+ * `unavailable` with its reason. An error with `retryable: true` (and its `reason`, `network` by default) is waited out
49
+ * by the retry policy, then said as `unreachable`.
50
+ */
51
+ declare class AgentRefusal extends Error {
52
+ readonly kind: 'ended' | 'unavailable';
53
+ readonly reason: AgentFailureReason;
54
+ readonly code: string | null;
55
+ constructor(kind: 'ended' | 'unavailable', options?: {
56
+ readonly reason?: AgentFailureReason;
57
+ readonly code?: string;
58
+ readonly message?: string;
59
+ });
60
+ }
61
+ interface AgentStatus {
62
+ readonly available: boolean;
63
+ /** The floating launcher may show. */
64
+ readonly launcher: boolean;
65
+ readonly displayName: string | null;
66
+ readonly avatarUrl: string | null;
67
+ readonly features: {
68
+ readonly history: boolean;
69
+ readonly memory: boolean;
70
+ readonly businessAgent: boolean;
71
+ readonly businessSetup: boolean;
72
+ };
73
+ }
74
+ /** The status as the backend reads it; what it leaves out is off. */
75
+ interface AgentStatusRead {
76
+ readonly available: boolean;
77
+ readonly launcher?: boolean;
78
+ readonly displayName?: string | null;
79
+ readonly avatarUrl?: string | null;
80
+ readonly features?: Partial<AgentStatus['features']>;
81
+ }
82
+ /** The tenant's backend: the one piece of integration an app writes. */
83
+ interface AgentBackend {
84
+ /** A session from the tenant's API (it creates it at Vinaverse with its service key), or an `AgentRefusal`. */
85
+ openSession(request: AgentSessionRequest): Promise<ConversationSession>;
86
+ /** A fresh client secret for the same session (before its end). */
87
+ refreshSecret?(sessionId: string): Promise<string>;
88
+ /**
89
+ * The person's place changed while the chat is open: the tenant's backend tells Vinaverse
90
+ * (`PUT /v1/sessions/{id}/context`). Absent, or refused, the kit offers a question about the new place instead.
91
+ */
92
+ updateContext?(sessionId: string, place: AgentPlace, revision: number): Promise<void>;
93
+ /** Whether the agent is offered, and what it can do. Absent: available, nothing extra. */
94
+ status?(signal?: AbortSignal): Promise<AgentStatusRead>;
95
+ /** A thumbs on a whole reply; best effort, never an error for the person. */
96
+ sendFeedback?(feedback: {
97
+ readonly sessionId: string;
98
+ readonly turnId: string;
99
+ readonly rating: AgentRating;
100
+ }): Promise<void>;
101
+ /** Sign-out: end the person's open sessions at the tenant's API. */
102
+ endSessions?(): Promise<void>;
103
+ }
104
+ type AgentRating = 'up' | 'down';
105
+ type AgentFailure = 'ended' | 'unreachable' | 'unavailable';
106
+ type AgentEventType = 'session_opened' | 'session_resumed' | 'session_retried' | 'session_failed' | 'conversation_ended' | 'context_updated' | 'rated' | 'chip_tapped' | 'card_action' | 'target_opened' | 'link_opened' | 'launcher_shown' | 'launcher_opened' | 'launcher_greeted' | 'greeting_closed';
107
+ /** For the app's analytics: what happened, for which conversation, with nothing the person said. */
108
+ interface AgentEvent {
109
+ readonly type: AgentEventType;
110
+ readonly key?: string;
111
+ readonly sessionId?: string;
112
+ readonly failure?: AgentFailure;
113
+ readonly reason?: AgentFailureReason;
114
+ readonly attempt?: number;
115
+ readonly turnId?: string;
116
+ readonly rating?: AgentRating;
117
+ readonly cardId?: string;
118
+ readonly kind?: string;
119
+ /** Where the person opened from (`entryPoint`, the screen). */
120
+ readonly from?: string;
121
+ }
122
+ /** What a UI draws around the store: why there is no session, whether the person moved, the thumbs given. */
123
+ interface AgentConversationState {
124
+ readonly failure: AgentFailure | null;
125
+ readonly reason: AgentFailureReason | null;
126
+ /** The API's own code for the failure (`conversation_expired`, …), when it gave one. */
127
+ readonly code: string | null;
128
+ /** The session was told another place than the one the person now asks from, and it could not be told live. */
129
+ readonly moved: boolean;
130
+ readonly ratings: ReadonlyMap<string, AgentRating>;
131
+ readonly sessionId: string | null;
132
+ }
133
+ interface AgentConversation {
134
+ /** The key as a string, for the app's own maps and the events. */
135
+ readonly key: string;
136
+ readonly store: ConversationStore;
137
+ /**
138
+ * A view attaches: kept, with its connection, while any view is attached. The first time, it starts. Returns the
139
+ * detach: with no view attached it is suspended (no pings; closed with `closeInBackground`) while its session lives
140
+ * (`keepAlive: 'session'`), and let go when it has none, is past its end, or `keepAlive` is `'view'`. Separate from the
141
+ * app's background, which the platform adapter tells the store.
142
+ */
143
+ show(open?: {
144
+ readonly place?: AgentPlace | null;
145
+ readonly entryPoint?: string | null;
146
+ }): () => void;
147
+ /** The place and the way in changed while a view is attached: told live where the backend can, else on the next session. */
148
+ tell(open: {
149
+ readonly place?: AgentPlace | null;
150
+ readonly entryPoint?: string | null;
151
+ }): void;
152
+ getState(): AgentConversationState;
153
+ subscribe(listener: () => void): () => void;
154
+ /** Asks for a session again, after the backend could not be reached. */
155
+ retry(): void;
156
+ /** A thumbs on a whole reply; a change of mind only is sent again. */
157
+ rate(turnId: string, rating: AgentRating): void;
158
+ /**
159
+ * Sends the person's `text` once in this conversation's life (a chip tapped twice, a retried tap). It is shown as
160
+ * theirs: only words they typed or tapped, never the app's in their name.
161
+ */
162
+ sendOnce(text: string): void;
163
+ }
164
+ /** When the runtime tries the backend again: before each try, a delay; `isRetryable` decides which errors are waited out. */
165
+ interface AgentRetryPolicy {
166
+ readonly delays: readonly number[];
167
+ readonly isRetryable?: (error: unknown) => boolean;
168
+ }
169
+ /** The time the runtime judges a session's end by: the server's, when the app has it (a clock synced from responses). */
170
+ interface AgentClock {
171
+ now(): number;
172
+ }
173
+ interface AgentRuntimeOptions {
174
+ readonly backend: AgentBackend;
175
+ /** The store's own options (locale, time zone, deep-link prefixes, transport, persistence, closeInBackground…). */
176
+ readonly conversation?: Omit<ConversationOptions, 'getSession' | 'refreshSecret' | 'clock'>;
177
+ /** Default: 500, 1500, 3500 ms, for errors with `retryable: true`; applied to `openSession` and `refreshSecret`. */
178
+ readonly retry?: AgentRetryPolicy;
179
+ /** Default: the device's clock. Give the server's: a phone set wrong otherwise reuses a dead session or drops a live one. */
180
+ readonly clock?: AgentClock;
181
+ /** `session` (default): kept while its session lives with no view attached; `view`: let go when the last view goes. */
182
+ readonly keepAlive?: 'session' | 'view';
183
+ /** How long a status read stays fresh. Default 5 minutes. */
184
+ readonly statusStaleMs?: number;
185
+ /**
186
+ * DANGEROUS: for mocks and local development only. Lets a leg's session address be plaintext (`ws://`, `http://`),
187
+ * which would carry the person's messages and the session's secret unencrypted. Off by default, whatever transport
188
+ * the app supplies; outside `__DEV__` the runtime warns once.
189
+ */
190
+ readonly insecureAddresses?: AgentInsecureAddresses;
191
+ readonly onEvent?: (event: AgentEvent) => void;
192
+ /** Where the runtime's warnings go (the app's logger, crash reporter); default `console.warn`. */
193
+ readonly onWarning?: (message: string) => void;
194
+ }
195
+ /** The legs whose session address may be plaintext: `realtime` (the WebSocket), `turns` (HTTP). */
196
+ interface AgentInsecureAddresses {
197
+ readonly realtime?: boolean;
198
+ readonly turns?: boolean;
199
+ }
200
+ interface AgentRuntime {
201
+ /** The key's conversation: the same while it lives; a new one after `startNew`, `dispose` or its end. */
202
+ conversation(key: AgentKey): AgentConversation;
203
+ /**
204
+ * The key's conversation as it stands, ending nothing and telling no one: for a render (`useSyncExternalStore`).
205
+ * One past its session's end is ended when it is next shown, and subscribers then read the key's next one.
206
+ */
207
+ peek(key: AgentKey): AgentConversation;
208
+ /** A new conversation for the key from the person's next opening; the old one is let go and forgotten. */
209
+ startNew(key: AgentKey): void;
210
+ /** Closes the key's conversation now and drops every reference to it; the next opening continues it in a new session. */
211
+ dispose(key: AgentKey): void;
212
+ /**
213
+ * The key goes on with this conversation (history's "Continue"): pinned for the key and opened through the backend's
214
+ * resume. One that is gone (404, 410: the backend's `AgentRefusal('ended')`) is said as `ended`, never replaced by a
215
+ * new one silently.
216
+ */
217
+ continue(key: AgentKey, conversationId: string): AgentConversation;
218
+ /** Every conversation closed and forgotten (what the device kept too), and the backend told to end the sessions. */
219
+ signOut(): Promise<void>;
220
+ /** The agent's status, read from the backend at most every `statusStaleMs`. */
221
+ status(): Promise<AgentStatus>;
222
+ getStatus(): AgentStatus | null;
223
+ /** The agent's name: from the newest session, else from the status. */
224
+ getName(): string | null;
225
+ /** Told when the status or name changes, and when a key's conversation is let go (its next one is another). */
226
+ subscribe(listener: () => void): () => void;
227
+ /** An event from a kit or the app, passed to `onEvent`. */
228
+ emit(event: AgentEvent): void;
229
+ }
230
+ /** The key as a string: one conversation per person, mode, business and thread. */
231
+ declare function agentKey(key: AgentKey): string;
232
+ declare function createAgentRuntime(options: AgentRuntimeOptions): AgentRuntime;
233
+
234
+ export { type AgentBackend as A, type AgentClock as a, type AgentConversation as b, type AgentConversationState as c, type AgentEvent as d, type AgentEventType as e, type AgentFailure as f, type AgentFailureReason as g, type AgentInsecureAddresses as h, type AgentKey as i, type AgentPlace as j, type AgentRating as k, AgentRefusal as l, type AgentRetryPolicy as m, type AgentRuntime as n, type AgentRuntimeOptions as o, type AgentSessionRequest as p, type AgentStatus as q, type AgentStatusRead as r, agentKey as s, createAgentRuntime as t };