@aintela/chat 0.2.47 → 0.2.49

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/dist/index.js CHANGED
@@ -1,30 +1,30 @@
1
1
  import "reflect-metadata";
2
- import { C as s, F as n, a as o, I as r, L as i, S as c, b as l, c as S, d as A, e as C, T as p, f as g, g as d, h as I, i as E, s as h, j as v } from "./serializer-DNt8QqNO.js";
3
- import { A as u, a as T, C as L, M as x, b as P, S as U, i as f } from "./Memory-DjLZqgbF.js";
2
+ import { C as s, F as n, a as o, I as r, L as i, S as c, b as l, c as A, d as S, e as C, T as p, f as g, g as d, h as I, i as E, s as h, j as v } from "./serializer-DNt8QqNO.js";
3
+ import { A as m, a as T, C as L, M as x, b as P, S as U, i as f } from "./Memory-DjLZqgbF.js";
4
4
  import { C as M, C as y } from "./ClientMessage-EKgfuTp8.js";
5
5
  import { C as D, P as B } from "./Prompt-DZb7OaPp.js";
6
6
  import { A as k, a as F, b, c as N, d as H, e as G, C as O, f as W, D as w, E as z, g as J, G as j, h as K, M as q, i as X, R as Y, j as Q, S as Z, l as $, m as ee, n as ae, o as te, p as se, q as ne, r as oe, s as re, t as ie, u as ce } from "./environmentUtils-CUVZ6Dq1.js";
7
- import { A as Se, a as Ae, E as Ce, H as pe, I as ge, L as de, W as Ie } from "./httpArtifactService-CcYAfh2q.js";
7
+ import { A as Ae, a as Se, E as Ce, H as pe, I as ge, L as de, W as Ie } from "./httpArtifactService-CcYAfh2q.js";
8
8
  import { A as he } from "./artifactHtmlHandler-CMQJf1cX.js";
9
- import { H as me, d as ue, r as Te } from "./httpSessionService-BDlqebW2.js";
10
- import { APPBAR_V2_HEIGHT as xe, ASK_USER_CANCELLED as Pe, AgentActivityV2 as Ue, AiChat as fe, AiChatDrawer as Re, AiChatFloating as Me, AiChatFloatingV2 as ye, AiChatProvider as _e, AiChatServiceContext as De, AiChatV2Pane as Be, AppBarV2 as Ve, AppRailV2 as ke, AppShellV2 as Fe, ArtifactRender as be, AskUserDialog as Ne, AskUserSheet as He, BoxedPart as Ge, BrainIcon as Oe, ChartIcon as We, ChatIcon as we, ChatPane as ze, ChatsHistoryV2 as Je, CheckIcon as je, ChevronIcon as Ke, ChevronRightIcon as qe, CloseIcon as Xe, CodeIcon as Ye, ComposerIcon as Qe, CurrentMessage as Ze, DEFAULT_PART_RENDERERS as $e, DashboardIcon as ea, DataExplorerIcon as aa, DelayTextComponent as ta, EnvironmentProvider as sa, FileIcon as na, FunctionPart as oa, GlobeIcon as ra, HistoryIcon as ia, IDLE_TIMEOUT as ca, InertEnvironmentProvider as la, JsxErrorBoundary as Sa, LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL as Aa, LastPromptsV2 as Ca, LinearBackgroundProgress as pa, LinearProgressBarWithMarkers as ga, ListCheckIcon as da, LiveJsxBlock as Ia, LiveTsxConfigProvider as Ea, LlmResponseRender as ha, LoadingDots as va, LockClosedIcon as ma, LockOpenIcon as ua, MOBILE_NAV_DEFAULT as Ta, MarkdownExtended as La, MenuIcon as xa, Message as Pa, MobileDrawerV2 as Ua, PanelIcon as fa, PauseIcon as Ra, PinIcon as Ma, PlusIcon as ya, PromptDateMarkers as _a, PromptV2 as Da, RunProgressPanelV2 as Ba, RunProgressStripV2 as Va, SearchIcon as ka, SendIcon as Fa, SessionStateManagerService as ba, SparkleIcon as Na, Sparkline as Ha, StopIcon as Ga, Stopwatch as Oa, SubAgentBox as Wa, SubAgentBoxV2 as wa, SuspendedPart as za, TableIcon as Ja, TaskListV2 as ja, TerminalIcon as Ka, TextPart as qa, ThoughtPart as Xa, ToolIcon as Ya, TrashIcon as Qa, UiToolDispatcher as Za, UsersIcon as $a, V2_CHART_PALETTE as et, WARNING_THRESHOLD as at, WaitingPart as tt, classifyPart as st, configureFriendlyMapping as nt, createAiChatEngine as ot, createAiChatSessionStore as rt, createAiChatSessionStore as it, createUiToolRegistry as ct, disposeSharedAiChatEngine as lt, extendDefaultScope as St, extendModuleRegistry as At, getDefaultJsxScope as Ct, getFriendlyLabel as pt, getSharedAiChatEngine as gt, parseClientOutput as dt, parseContentBlocks as It, parseUiArgs as Et, useAiChatServices as ht, useAiChatSessionStore as vt, useEnvironment as mt, useEnvironmentOptional as ut, useLiveSession as Tt, useLiveTsxMaxCharsForFull as Lt, useParkedAskUser as xt, useResponsiveLayout as Pt, v2Card as Ut, v2Chip as ft, v2IconBtn as Rt, v2MonoMeta as Mt, v2SectionLabel as yt, v2Theme as _t } from "./components.js";
11
- import { u as Bt, a as Vt, b as kt, c as Ft } from "./useContainerWidth-CDv8UQyZ.js";
12
- import { A as Nt, a as Ht, b as Gt, G as Ot, d as Wt, c as wt, e as zt, f as Jt, g as jt, h as Kt, i as qt, j as Xt, k as Yt, l as Qt, m as Zt, n as $t, o as es, p as as, q as ts, r as ss, s as ns, t as os, u as rs, v as is } from "./auth-xpQrzSI2.js";
13
- import { S as ls, c as Ss, a as As, e as Cs, b as ps, f as gs, i as ds, d as Is, p as Es, g as hs, s as vs, k as ms, t as us } from "./atMentions-CJUmkOh9.js";
14
- import { u as Ls } from "./useChatSessions-sbBneRk9.js";
15
- import { Score as Ps } from "./interfaces.js";
9
+ import { H as ue, d as me, r as Te } from "./httpSessionService-BDlqebW2.js";
10
+ import { APPBAR_V2_HEIGHT as xe, ASK_USER_CANCELLED as Pe, AgentActivityV2 as Ue, AiChat as fe, AiChatDrawer as Re, AiChatFloating as Me, AiChatFloatingV2 as ye, AiChatProvider as _e, AiChatServiceContext as De, AiChatV2Pane as Be, AppBarV2 as Ve, AppRailV2 as ke, AppShellV2 as Fe, ArtifactRender as be, AskUserDialog as Ne, AskUserSheet as He, BoxedPart as Ge, BrainIcon as Oe, ChartIcon as We, ChatIcon as we, ChatPane as ze, ChatsHistoryV2 as Je, CheckIcon as je, ChevronIcon as Ke, ChevronRightIcon as qe, CloseIcon as Xe, CodeIcon as Ye, ComposerIcon as Qe, CurrentMessage as Ze, DEFAULT_PART_RENDERERS as $e, DashboardIcon as ea, DataExplorerIcon as aa, DelayTextComponent as ta, EnvironmentProvider as sa, FileIcon as na, FunctionPart as oa, GlobeIcon as ra, HistoryIcon as ia, IDLE_TIMEOUT as ca, InertEnvironmentProvider as la, JsxErrorBoundary as Aa, LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL as Sa, LastPromptsV2 as Ca, LinearBackgroundProgress as pa, LinearProgressBarWithMarkers as ga, ListCheckIcon as da, LiveJsxBlock as Ia, LiveTsxConfigProvider as Ea, LlmResponseRender as ha, LoadingDots as va, LockClosedIcon as ua, LockOpenIcon as ma, MOBILE_NAV_DEFAULT as Ta, MarkdownExtended as La, MenuIcon as xa, Message as Pa, MobileDrawerV2 as Ua, PanelIcon as fa, PauseIcon as Ra, PinIcon as Ma, PlusIcon as ya, PromptDateMarkers as _a, PromptV2 as Da, RunProgressPanelV2 as Ba, RunProgressStripV2 as Va, SearchIcon as ka, SendIcon as Fa, SessionStateManagerService as ba, SparkleIcon as Na, Sparkline as Ha, StopIcon as Ga, Stopwatch as Oa, SubAgentBox as Wa, SubAgentBoxV2 as wa, SuspendedPart as za, TableIcon as Ja, TaskListV2 as ja, TerminalIcon as Ka, TextPart as qa, ThoughtPart as Xa, ToolIcon as Ya, TrashIcon as Qa, TurnAwareButton as Za, UiToolDispatcher as $a, UsersIcon as et, V2_CHART_PALETTE as at, WARNING_THRESHOLD as tt, WaitingPart as st, classifyPart as nt, configureFriendlyMapping as ot, createAiChatEngine as rt, createAiChatSessionStore as it, createAiChatSessionStore as ct, createUiToolRegistry as lt, disposeSharedAiChatEngine as At, extendDefaultScope as St, extendModuleRegistry as Ct, getDefaultJsxScope as pt, getFriendlyLabel as gt, getSharedAiChatEngine as dt, parseClientOutput as It, parseContentBlocks as Et, parseUiArgs as ht, useAiChatServices as vt, useAiChatSessionStore as ut, useEnvironment as mt, useEnvironmentOptional as Tt, useLiveSession as Lt, useLiveTsxMaxCharsForFull as xt, useParkedAskUser as Pt, useResponsiveLayout as Ut, useTurnOpen as ft, v2Card as Rt, v2Chip as Mt, v2IconBtn as yt, v2MonoMeta as _t, v2SectionLabel as Dt, v2Theme as Bt } from "./components.js";
11
+ import { u as kt, a as Ft, b as bt, c as Nt } from "./useContainerWidth-CDv8UQyZ.js";
12
+ import { A as Gt, a as Ot, b as Wt, G as wt, d as zt, c as Jt, e as jt, f as Kt, g as qt, h as Xt, i as Yt, j as Qt, k as Zt, l as $t, m as es, n as as, o as ts, p as ss, q as ns, r as os, s as rs, t as is, u as cs, v as ls } from "./auth-xpQrzSI2.js";
13
+ import { S as Ss, c as Cs, a as ps, e as gs, b as ds, f as Is, i as Es, d as hs, p as vs, g as us, s as ms, k as Ts, t as Ls } from "./atMentions-CJUmkOh9.js";
14
+ import { u as Ps } from "./useChatSessions-sbBneRk9.js";
15
+ import { Score as fs } from "./interfaces.js";
16
16
  export {
17
- Nt as ALLOWED_DOMAINS,
18
- Ht as ALLOWED_EMAILS,
17
+ Gt as ALLOWED_DOMAINS,
18
+ Ot as ALLOWED_EMAILS,
19
19
  k as ANALYTICS_AGENT_NAME,
20
20
  xe as APPBAR_V2_HEIGHT,
21
21
  Pe as ASK_USER_CANCELLED,
22
- Gt as AUTH_CONFIG,
23
- u as Account,
22
+ Wt as AUTH_CONFIG,
23
+ m as Account,
24
24
  Ue as AgentActivityV2,
25
25
  F as AgentConfig,
26
- Se as AgentGatewayService,
27
- Ae as AgentGatewayWSAsync,
26
+ Ae as AgentGatewayService,
27
+ Se as AgentGatewayWSAsync,
28
28
  T as AgentKind,
29
29
  b as AgentMode,
30
30
  N as AgentType,
@@ -77,19 +77,19 @@ export {
77
77
  n as FunctionCallContent,
78
78
  oa as FunctionPart,
79
79
  o as FunctionResultContent,
80
- Ot as GOOGLE_CLIENT_ID,
80
+ wt as GOOGLE_CLIENT_ID,
81
81
  j as GetEventTypeFromDotNetName,
82
82
  K as GetEventTypeFromPythonName,
83
83
  ra as GlobeIcon,
84
84
  ia as HistoryIcon,
85
85
  pe as HttpArtifactService,
86
- me as HttpSessionService,
86
+ ue as HttpSessionService,
87
87
  ca as IDLE_TIMEOUT,
88
88
  la as InertEnvironmentProvider,
89
89
  r as InteractionPartUtils,
90
90
  ge as InteractionService,
91
- Sa as JsxErrorBoundary,
92
- Aa as LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL,
91
+ Aa as JsxErrorBoundary,
92
+ Sa as LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL,
93
93
  Ca as LastPromptsV2,
94
94
  pa as LinearBackgroundProgress,
95
95
  ga as LinearProgressBarWithMarkers,
@@ -100,8 +100,8 @@ export {
100
100
  ha as LlmResponseRender,
101
101
  va as LoadingDots,
102
102
  de as LocalStorageService,
103
- ma as LockClosedIcon,
104
- ua as LockOpenIcon,
103
+ ua as LockClosedIcon,
104
+ ma as LockOpenIcon,
105
105
  Ta as MOBILE_NAV_DEFAULT,
106
106
  La as MarkdownExtended,
107
107
  x as MemoryContextLabels,
@@ -123,20 +123,20 @@ export {
123
123
  Ba as RunProgressPanelV2,
124
124
  Va as RunProgressStripV2,
125
125
  U as SUB_AGENT_TERMINAL_STATUSES,
126
- Ps as Score,
126
+ fs as Score,
127
127
  ka as SearchIcon,
128
128
  Fa as SendIcon,
129
129
  c as ServerEvent,
130
130
  ba as SessionStateManagerService,
131
131
  Z as SkillLevel,
132
- ls as SortableTable,
132
+ Ss as SortableTable,
133
133
  Na as SparkleIcon,
134
134
  Ha as Sparkline,
135
135
  Ga as StopIcon,
136
136
  Oa as Stopwatch,
137
137
  l as StreamingFunctionCallUpdateContent,
138
- S as StreamingReasoningContent,
139
- A as StreamingResponse,
138
+ A as StreamingReasoningContent,
139
+ S as StreamingResponse,
140
140
  C as StreamingTextContent,
141
141
  Wa as SubAgentBox,
142
142
  wa as SubAgentBoxV2,
@@ -149,96 +149,98 @@ export {
149
149
  Xa as ThoughtPart,
150
150
  Ya as ToolIcon,
151
151
  Qa as TrashIcon,
152
- Za as UiToolDispatcher,
153
- $a as UsersIcon,
154
- et as V2_CHART_PALETTE,
155
- at as WARNING_THRESHOLD,
156
- tt as WaitingPart,
152
+ Za as TurnAwareButton,
153
+ $a as UiToolDispatcher,
154
+ et as UsersIcon,
155
+ at as V2_CHART_PALETTE,
156
+ tt as WARNING_THRESHOLD,
157
+ st as WaitingPart,
157
158
  Ie as WebSocketConnecionV2,
158
- Ss as chipLocations,
159
- As as chunkArray,
160
- st as classifyPart,
161
- nt as configureFriendlyMapping,
162
- ot as createAiChatEngine,
163
- rt as createAiChatSessionStore,
164
- it as createAiChatStore,
159
+ Cs as chipLocations,
160
+ ps as chunkArray,
161
+ nt as classifyPart,
162
+ ot as configureFriendlyMapping,
163
+ rt as createAiChatEngine,
164
+ it as createAiChatSessionStore,
165
+ ct as createAiChatStore,
165
166
  g as createEventSerializer,
166
167
  d as createStreamingResponseSerializer,
167
- ct as createUiToolRegistry,
168
- Wt as dateReviver,
169
- wt as decodeBase64,
170
- ue as decodeSessionEvents,
171
- zt as decodeUri,
172
- Jt as decodeUriFromPython,
168
+ lt as createUiToolRegistry,
169
+ zt as dateReviver,
170
+ Jt as decodeBase64,
171
+ me as decodeSessionEvents,
172
+ jt as decodeUri,
173
+ Kt as decodeUriFromPython,
173
174
  I as deserializeEvent,
174
175
  E as deserializePayload,
175
- lt as disposeSharedAiChatEngine,
176
- jt as encodeBase64,
177
- Kt as encodeUri,
176
+ At as disposeSharedAiChatEngine,
177
+ qt as encodeBase64,
178
+ Xt as encodeUri,
178
179
  St as extendDefaultScope,
179
- At as extendModuleRegistry,
180
- Cs as extractInteractionId,
181
- ps as extractLinkAction,
182
- gs as fetchAtMentions,
183
- qt as getAgentBaseUrl,
180
+ Ct as extendModuleRegistry,
181
+ gs as extractInteractionId,
182
+ ds as extractLinkAction,
183
+ Is as fetchAtMentions,
184
+ Yt as getAgentBaseUrl,
184
185
  $ as getAgentServerBaseUrl,
185
- Xt as getArtifactsBaseUrl,
186
+ Qt as getArtifactsBaseUrl,
186
187
  ee as getConnectionStateColor,
187
- Ct as getDefaultJsxScope,
188
- Yt as getDotNetBaseUrl,
188
+ pt as getDefaultJsxScope,
189
+ Zt as getDotNetBaseUrl,
189
190
  ae as getEnvVar,
190
191
  te as getEnvironmentInfo,
191
- pt as getFriendlyLabel,
192
- Qt as getIconByName,
192
+ gt as getFriendlyLabel,
193
+ $t as getIconByName,
193
194
  se as getModelVendor,
194
195
  ne as getRandomUUID,
195
196
  oe as getServerBaseUrl,
196
197
  re as getServerClientBaseUrl,
197
- gt as getSharedAiChatEngine,
198
- Zt as iconCategories,
199
- $t as isBase64Encoded,
200
- ds as isSectionStart,
198
+ dt as getSharedAiChatEngine,
199
+ es as iconCategories,
200
+ as as isBase64Encoded,
201
+ Es as isSectionStart,
201
202
  ie as isServer,
202
203
  f as isSubAgentTerminalStatus,
203
- es as isUriEncoded,
204
- Is as isValidInteractionId,
205
- as as isValidUri,
206
- ts as materialIcons,
207
- Es as parseAndValidateArtifactUrl,
208
- ss as parseArtifactFromJson,
209
- dt as parseClientOutput,
210
- It as parseContentBlocks,
211
- hs as parseKnownNumbers,
212
- Et as parseUiArgs,
213
- ns as parseUriParams,
204
+ ts as isUriEncoded,
205
+ hs as isValidInteractionId,
206
+ ss as isValidUri,
207
+ ns as materialIcons,
208
+ vs as parseAndValidateArtifactUrl,
209
+ os as parseArtifactFromJson,
210
+ It as parseClientOutput,
211
+ Et as parseContentBlocks,
212
+ us as parseKnownNumbers,
213
+ ht as parseUiArgs,
214
+ rs as parseUriParams,
214
215
  Te as resolveAccessToken,
215
216
  ce as resolveApiUrl,
216
217
  h as sanitizeJsonString,
217
- os as searchIcons,
218
+ is as searchIcons,
218
219
  v as serializeEvent,
219
- rs as setEbiContextData,
220
- is as setEbiContextSessionId,
221
- vs as splitBigLinesWithSpaces,
222
- ms as startsWithInteractionId,
223
- us as tokenizeForHighlight,
224
- ht as useAiChatServices,
225
- vt as useAiChatSessionStore,
226
- Ls as useChatSessions,
227
- Bt as useContainerRectangle,
228
- Vt as useContainerWidth,
220
+ cs as setEbiContextData,
221
+ ls as setEbiContextSessionId,
222
+ ms as splitBigLinesWithSpaces,
223
+ Ts as startsWithInteractionId,
224
+ Ls as tokenizeForHighlight,
225
+ vt as useAiChatServices,
226
+ ut as useAiChatSessionStore,
227
+ Ps as useChatSessions,
228
+ kt as useContainerRectangle,
229
+ Ft as useContainerWidth,
229
230
  mt as useEnvironment,
230
- ut as useEnvironmentOptional,
231
- kt as useInterval,
232
- Tt as useLiveSession,
233
- Lt as useLiveTsxMaxCharsForFull,
234
- xt as useParkedAskUser,
235
- Ft as usePromptAssist,
236
- Pt as useResponsiveLayout,
237
- Ut as v2Card,
238
- ft as v2Chip,
239
- Rt as v2IconBtn,
240
- Mt as v2MonoMeta,
241
- yt as v2SectionLabel,
242
- _t as v2Theme
231
+ Tt as useEnvironmentOptional,
232
+ bt as useInterval,
233
+ Lt as useLiveSession,
234
+ xt as useLiveTsxMaxCharsForFull,
235
+ Pt as useParkedAskUser,
236
+ Nt as usePromptAssist,
237
+ Ut as useResponsiveLayout,
238
+ ft as useTurnOpen,
239
+ Rt as v2Card,
240
+ Mt as v2Chip,
241
+ yt as v2IconBtn,
242
+ _t as v2MonoMeta,
243
+ Dt as v2SectionLabel,
244
+ Bt as v2Theme
243
245
  };
244
246
  //# sourceMappingURL=index.js.map
@@ -37,6 +37,12 @@ import { default as React } from 'react';
37
37
  export interface AskUserSheetProps {
38
38
  /** Height of the composer to dock above, in px. Omit to stay positioning-agnostic. */
39
39
  promptHeight?: number;
40
+ /**
41
+ * Leading label of the eyebrow, before the tool name. Defaults to pt-BR, like the
42
+ * library's other user-facing strings (`atPersonLabel`, `datePresets`). Pass `null`
43
+ * to drop the eyebrow entirely.
44
+ */
45
+ eyebrowLabel?: string | null;
40
46
  }
41
47
  declare const AskUserSheet: React.FC<AskUserSheetProps>;
42
48
  export default AskUserSheet;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Live "is the agent streaming a turn?" flag, readable from ANYWHERE — including
3
+ * outside an `<AiChat>` provider, where it is simply `false`.
4
+ *
5
+ * That tolerance is the whole point, and it is why this doesn't just call
6
+ * `useAiChatSessionStore((s) => s.turnOpen)`: that hook throws without a provider,
7
+ * and its `useStore` needs a store instance that a hook cannot conditionally
8
+ * acquire. Components shared between the chat surface and a plain page (obtapp's
9
+ * flight cards are rendered in both) would otherwise have to know which one they
10
+ * are in. Subscribing by hand to the store off the context handles the missing
11
+ * provider and keeps the re-render narrowed to `turnOpen` alone.
12
+ *
13
+ * Prefer this over `UiToolContext.onGoing` when the question is "is a turn open
14
+ * right now": `onGoing` is a snapshot of the SURFACE a part was rendered on
15
+ * (`true` in the live bubble, hardcoded `false` in settled history), so a card in
16
+ * history reports `false` forever even while a later turn streams.
17
+ */
18
+ export declare function useTurnOpen(): boolean;
@@ -0,0 +1,46 @@
1
+ import { ButtonProps } from '@mui/material/Button';
2
+ /**
3
+ * The handler. Return a promise (e.g. the `sendMessage(...)` you kick off) and the
4
+ * button keeps waiting until it settles — see the note on the open_turn gap below.
5
+ */
6
+ export type TurnAwareClickHandler = () => void | Promise<unknown>;
7
+ export interface TurnAwareButtonProps extends Omit<ButtonProps, 'onClick'> {
8
+ /** Runs on click, but only while no turn is open. */
9
+ onClick?: TurnAwareClickHandler;
10
+ /** Tooltip explaining the wait. */
11
+ waitingTitle?: string;
12
+ /** Drop the inline spinner (the button still blocks — this is presentation only). */
13
+ hideSpinner?: boolean;
14
+ }
15
+ /**
16
+ * A `Button` that will not act while the agent's turn is open.
17
+ *
18
+ * Chat-rendered components are drawn mid-turn — a `present_tripstretch` card
19
+ * appears while the agent is still talking — and acting on one then races the run
20
+ * that is still writing to the session. So for as long as the turn is open this
21
+ * button is disabled AND spinning: the spinner is the point, not the disabling.
22
+ * A user who clicks a card mid-turn has usually just not noticed that the agent
23
+ * is still writing, and the spinner is what tells them; a plainly dead button
24
+ * would leave them clicking at nothing. Everything else is a plain MUI `Button`:
25
+ * same props, same theming, drop-in at the call site.
26
+ *
27
+ * ```tsx
28
+ * <TurnAwareButton variant="contained" onClick={() => sendMessage('escolhi a opção 2')}>
29
+ * selecionar ida
30
+ * </TurnAwareButton>
31
+ * ```
32
+ *
33
+ * Outside an `<AiChat>` provider there is no turn, so it behaves exactly like
34
+ * `Button` — components shared between the chat and a plain page need no branch.
35
+ *
36
+ * ⚠️ **The open_turn gap.** `turnOpen` only flips true when the server's
37
+ * `open_turn` command arrives, so for a moment after a handler sends a message the
38
+ * turn still reads as closed. Return the promise from your handler (`onClick={() =>
39
+ * sendMessage(…)}`, not `onClick={() => { sendMessage(…); }}`) and the button stays
40
+ * disabled across that window instead of briefly offering itself for a second click.
41
+ *
42
+ * The decision logic lives in `turnAwareButtonState.ts` (pure, unit-tested);
43
+ * this component is the React/MUI shell around it.
44
+ */
45
+ export declare function TurnAwareButton({ onClick, waitingTitle, hideSpinner, disabled, children, endIcon, sx, ...buttonProps }: TurnAwareButtonProps): import("react/jsx-runtime").JSX.Element;
46
+ export default TurnAwareButton;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The decision logic behind {@link TurnAwareButton}, kept as pure functions so
3
+ * it can be unit-tested without a DOM (this package's vitest runs in `node`).
4
+ *
5
+ * The problem it solves: a chat-rendered component (a `present_tripstretch`
6
+ * card, say) is drawn WHILE the agent is still streaming its turn. Acting on it
7
+ * mid-turn races the run that is still writing to the session — and the click is
8
+ * usually a mistake anyway: the user didn't notice the agent was still writing.
9
+ * So the button blocks the click and SHOWS why, which is the part that helps.
10
+ */
11
+ /**
12
+ * What the button itself is doing, independent of the turn:
13
+ * - `idle` — nothing pending.
14
+ * - `running` — the caller's handler is executing (an async handler that returned
15
+ * a promise keeps this until the promise settles).
16
+ */
17
+ export type TurnAwarePhase = 'idle' | 'running';
18
+ export interface TurnAwareButtonSnapshot {
19
+ /** Live `turnOpen` from the chat session store — true while the agent streams a turn. */
20
+ turnOpen: boolean;
21
+ phase: TurnAwarePhase;
22
+ /** The caller's own `disabled`. Always wins. */
23
+ disabled?: boolean;
24
+ }
25
+ /**
26
+ * Should the button show its waiting affordance (spinner + tooltip)? True while
27
+ * the turn is open, and while our own handler is still running — the whole span
28
+ * in which the button is not ready to be clicked.
29
+ *
30
+ * This is the cue, not just decoration: a user clicking a card mid-turn has
31
+ * usually missed that the agent is still writing, and the spinner is what tells
32
+ * them. It always accompanies the block — the button is never inertly dead.
33
+ */
34
+ export declare function isWaiting(snapshot: TurnAwareButtonSnapshot): boolean;
35
+ /** Should the underlying MUI button be `disabled`? Whenever it is waiting, plus the caller's own flag. */
36
+ export declare function isBlocked(snapshot: TurnAwareButtonSnapshot): boolean;
37
+ export type TurnAwareClickDecision = 'run' | 'ignore';
38
+ /**
39
+ * What a click right now should do. `ignore` is belt-and-braces: a blocked button
40
+ * fires no click event, but the two must not be able to drift apart.
41
+ */
42
+ export declare function decideClick(snapshot: TurnAwareButtonSnapshot): TurnAwareClickDecision;
@@ -5,6 +5,7 @@ export { AiChatProvider } from './AiChat/AiChatProvider';
5
5
  export { AiChatDrawer } from './AiChat/AiChatDrawer';
6
6
  export { AiChatFloating } from './AiChat/AiChatFloating';
7
7
  export { AiChatServiceContext, useAiChatServices, useAiChatSessionStore, } from './AiChat/AiChatContext';
8
+ export { useTurnOpen } from './AiChat/useTurnOpen';
8
9
  export type { AiChatContextState as AiChatServices } from './AiChat/AiChatContext';
9
10
  export type { AiChatProps, AiChatHandle, AiChatStyleProps, AiChatDrawerProps, AiChatFloatingProps, ConnectionInformation, AuthPromptContext, } from './AiChat/AiChatTypes';
10
11
  export type { AiChatState, AiChatStore, SubAgentState } from './AiChat/stateConfiguration';
@@ -38,6 +39,9 @@ export { default as ArtifactRender } from './Library/ArtifactRender';
38
39
  export { default as LinearBackgroundProgress } from './Library/LinearBackgroundProgress';
39
40
  export { default as LinearProgressBarWithMarkers } from './Library/LinearProgressBarWithMarkers';
40
41
  export { default as DelayTextComponent } from './Library/DelayTextComponent';
42
+ export { default as TurnAwareButton } from './Library/TurnAwareButton';
43
+ export type { TurnAwareButtonProps, TurnAwareClickHandler } from './Library/TurnAwareButton';
44
+ export type { TurnAwarePhase } from './Library/turnAwareButtonState';
41
45
  export { LlmResponseRender, LiveJsxBlock, JsxErrorBoundary, EnvironmentProvider, InertEnvironmentProvider, useEnvironment, useEnvironmentOptional, LiveTsxConfigProvider, useLiveTsxMaxCharsForFull, LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL, extendModuleRegistry, extendDefaultScope, getDefaultJsxScope, parseContentBlocks, } from './LlmResponseRender';
42
46
  export type { ContentBlock } from './LlmResponseRender';
43
47
  export * from './v2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aintela/chat",
3
- "version": "0.2.47",
3
+ "version": "0.2.49",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -116,6 +116,8 @@
116
116
  },
117
117
  "devDependencies": {
118
118
  "@microlink/react-json-view": "^1.27.0",
119
+ "@testing-library/dom": "^10.4.1",
120
+ "@testing-library/react": "^16.3.2",
119
121
  "@types/lodash": "^4.17.0",
120
122
  "@types/node": "^20.11.0",
121
123
  "@types/react": "^18.2.0",
@@ -123,6 +125,7 @@
123
125
  "@types/react-syntax-highlighter": "^15.5.13",
124
126
  "@vitejs/plugin-react": "^4.5.2",
125
127
  "@vitest/coverage-v8": "^4.1.7",
128
+ "happy-dom": "^20.11.1",
126
129
  "html-react-parser": "^5.2.0",
127
130
  "js-base64": "^3.7.0",
128
131
  "recharts": "^2.15.0",