@aintela/chat 0.14.2 → 0.14.4

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 (27) hide show
  1. package/dist/components.js +4571 -4558
  2. package/dist/components.js.map +1 -1
  3. package/dist/{detachedRunActivity-C_TBbcmB.js → detachedRunActivity-Cf-RPK9j.js} +352 -254
  4. package/dist/detachedRunActivity-Cf-RPK9j.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/services.js +1 -1
  7. package/dist/src/components/AiChat/AiChatTypes.d.ts +2 -0
  8. package/dist/src/components/AiChat/ChatPane/AskUserDialog.d.ts +2 -2
  9. package/dist/src/components/AiChat/ChatPane/friendlyToolConfig.d.ts +2 -0
  10. package/dist/src/components/AiChat/ChatPane/parts/askUserPartStrings.test.d.ts +1 -0
  11. package/dist/src/components/AiChat/aiChatEngine.d.ts +11 -0
  12. package/dist/src/components/AiChat/stateConfiguration.d.ts +1 -1
  13. package/dist/src/components/Library/markdownExtended.streaming.test.d.ts +1 -0
  14. package/dist/src/models/Notification.d.ts +3 -1
  15. package/dist/src/services/interaction/reduceInteraction.d.ts +16 -0
  16. package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +26 -0
  17. package/dist/src/services/servers/connectionSupervisor.credentials.test.d.ts +1 -0
  18. package/dist/src/services/servers/connectionSupervisor.d.ts +14 -1
  19. package/dist/src/services/servers/gatewayCredentials.wire.test.d.ts +0 -0
  20. package/dist/src/services/servers/gatewaySessionSwitch.test.d.ts +1 -0
  21. package/dist/src/utils/jwtExpiry.d.ts +6 -0
  22. package/dist/src/utils/jwtExpiry.test.d.ts +1 -0
  23. package/dist/tests/bench/markdownRender.bench.d.ts +1 -0
  24. package/dist/tests/bench/textSplit.bench.d.ts +1 -0
  25. package/dist/tests/fakes/fakeJwt.d.ts +4 -0
  26. package/package.json +3 -3
  27. package/dist/detachedRunActivity-C_TBbcmB.js.map +0 -1
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { A as s, a as n, b as r, c as o, d as i, C as c, e as l, f as A, E as p,
3
3
  import { C as w, C as G, D as W, a as z, i as K, b as J, c as X, d as j } from "./detachedRunModel-X59Pb5V-.js";
4
4
  import { A as q, a as Z, M as Q, b as $ } from "./Memory-BUnmYGNv.js";
5
5
  import { C as ae, P as te } from "./Prompt-DZb7OaPp.js";
6
- import { A as ne, A as re, C as oe, D as ie, a as ce, E as le, H as Ae, I as pe, b as ge, L as Se, M as Ce, T as de, W as he, c as ue, d as Ee, r as Te, e as Re, s as Ie, t as Pe } from "./detachedRunActivity-C_TBbcmB.js";
6
+ import { A as ne, A as re, C as oe, D as ie, a as ce, E as le, H as Ae, I as pe, b as ge, L as Se, M as Ce, T as de, W as he, c as ue, d as Ee, r as Te, e as Re, s as Ie, t as Pe } from "./detachedRunActivity-Cf-RPK9j.js";
7
7
  import { A as De } from "./artifactHtmlHandler-CMQJf1cX.js";
8
8
  import { H as me, d as _e, r as xe } from "./httpSessionService-B2wgAfly.js";
9
9
  import { APPBAR_HEIGHT as fe, APPBAR_HEIGHT as Me, ASK_USER_CANCELLED as Be, ActivityLine as Fe, AgentActivity as Oe, AgentActivity as Ue, AgentRunLabel as ke, AgentTyping as He, AiChat as Ve, AiChatDrawer as Ne, AiChatFloating as be, AiChatFloating as we, AiChatPane as Ge, AiChatProvider as We, AiChatServiceContext as ze, AiChatPane as Ke, AppBar as Je, AppBar as Xe, AppRail as je, AppRail as Ye, AppShell as qe, AppShell as Ze, ArtifactRender as Qe, AskUserDialog as $e, AskUserSheet as ea, AttachmentPreviewModal as aa, BillingLimitBanner as ta, BoxedPart as sa, BrainIcon as na, CHAT_VERBOSITY_LEVELS as ra, ChartIcon as oa, ChatAgentHeader as ia, ChatBoxContext as ca, ChatIcon as la, ChatPane as Aa, ChatsHistory as pa, ChatsHistory as ga, CheckIcon as Sa, ChevronIcon as Ca, ChevronRightIcon as da, CloseIcon as ha, CodeIcon as ua, ComposerIcon as Ea, CurrentMessage as Ta, DEFAULT_ACTIVITY_RENDERER as Ra, DEFAULT_INTERACTION_ORIGIN_LABELS as Ia, DEFAULT_PART_RENDERERS as Pa, DashboardIcon as va, DataExplorerIcon as Da, DelayTextComponent as La, DetachedRunBox as ma, DetachedRunBox as _a, DetachedRunTaskBox as xa, DetachedRunTranscript as ya, EnvironmentProvider as fa, FileIcon as Ma, FunctionPart as Ba, GlobeIcon as Fa, HandoffDivider as Oa, HistoryIcon as Ua, InertEnvironmentProvider as ka, InteractionOriginBadge as Ha, JsxErrorBoundary as Va, LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL as Na, LastPrompts as ba, LastPrompts as wa, LinearBackgroundProgress as Ga, LinearProgressBarWithMarkers as Wa, ListCheckIcon as za, LiveJsxBlock as Ka, LiveTsxConfigProvider as Ja, LlmResponseRender as Xa, LoadingDots as ja, LockClosedIcon as Ya, LockOpenIcon as qa, MOBILE_NAV_DEFAULT as Za, MarkdownExtended as Qa, MentionPickerPanel as $a, MenuIcon as et, Message as at, MessageScopeProvider as tt, MobileDrawer as st, MobileDrawer as nt, PanelIcon as rt, PaperclipIcon as ot, PauseIcon as it, PenIcon as ct, PersonaCard as lt, PinIcon as At, PlusIcon as pt, Prompt as gt, PromptDateMarkers as St, PromptGhostHint as Ct, Prompt as dt, RotateIcon as ht, RunProgressPanel as ut, RunProgressPanel as Et, RunProgressStrip as Tt, RunProgressStrip as Rt, SearchIcon as It, SendIcon as Pt, SessionStateManagerService as vt, SessionUsage as Dt, SessionUsage as Lt, SharedSessionTranscript as mt, SparkleIcon as _t, Sparkline as xt, StopIcon as yt, Stopwatch as ft, SuspendedPart as Mt, TableIcon as Bt, TaskList as Ft, TaskList as Ot, TerminalIcon as Ut, TextPart as kt, ThoughtPart as Ht, ToolIcon as Vt, TrashIcon as Nt, TriggerDropdown as bt, TurnAwareButton as wt, UiToolDispatcher as Gt, UndoIcon as Wt, UsersIcon as zt, V2_CHART_PALETTE as Kt, WaitingPart as Jt, ZoomInIcon as Xt, ZoomOutIcon as jt, acceptsFile as Yt, activitySteps as qt, agentFromKey as Zt, bareToolName as Qt, canStreamDetachedRun as $t, classifyPart as es, configureFriendlyMapping as as, createAiChatEngine as ts, createAiChatSessionStore as ss, createAiChatSessionStore as ns, createChatBoxStore as rs, createDetachedRunTranscriptEngine as os, createSharedSessionTranscriptEngine as is, createUiToolRegistry as cs, detachedRunHeadline as ls, disposeSharedAiChatEngine as As, engineKeyFor as ps, extendDefaultScope as gs, extendModuleRegistry as Ss, formatFileSize as Cs, getDefaultJsxScope as ds, getFriendlyLabel as hs, getSharedAiChatEngine as us, handoffAt as Es, itemsThatFit as Ts, openDetachedRunTranscript as Rs, openSharedSessionTranscript as Is, parseClientOutput as Ps, parseContentBlocks as vs, parseDetachedRunConclusion as Ds, parseUiArgs as Ls, previousAgentKey as ms, registerContentTools as _s, resolveChatAgent as xs, slotEnterSx as ys, useAgentEngine as fs, useAiChatServices as Ms, useAiChatSessionStore as Bs, useChatBoxHeight as Fs, useChatReadOnly as Os, useCoarsePointer as Us, useDetachedRunLiveActivity as ks, useDetachedRunResumeKey as Hs, useDetachedRunTranscript as Vs, useEnvironment as Ns, useEnvironmentOptional as bs, useFirstDrawBudget as ws, useLiveTsxMaxCharsForFull as Gs, useMessageScope as Ws, useParkedAskUser as zs, useResponsiveLayout as Ks, useSharedSessionTranscript as Js, useTurnOpen as Xs, useVisualViewport as js, v2Card as Ys, v2Chip as qs, v2IconBtn as Zs, v2MonoMeta as Qs, v2SectionLabel as $s, v2Theme as en } from "./components.js";
package/dist/services.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as r, A as s, D as t, a as c, E as o, H as n, b as i, L as A, M as S, T as d, c as v, d as E, r as T, e as D, s as m, t as H } from "./detachedRunActivity-C_TBbcmB.js";
1
+ import { A as r, A as s, D as t, a as c, E as o, H as n, b as i, L as A, M as S, T as d, c as v, d as E, r as T, e as D, s as m, t as H } from "./detachedRunActivity-Cf-RPK9j.js";
2
2
  import { A as p } from "./artifactHtmlHandler-CMQJf1cX.js";
3
3
  import { H as _, d as l, r as f } from "./httpSessionService-B2wgAfly.js";
4
4
  export {
@@ -133,6 +133,8 @@ export interface AiChatBaseProps extends AiChatStyleProps {
133
133
  * `useAgentEngine`'s config instead.
134
134
  */
135
135
  getUser?: () => User | undefined;
136
+ /** See {@link AiChatEngineConfig.ensureDialableToken}: renew a stale token before every (re)dial, or say the session is over. */
137
+ ensureDialableToken?: () => Promise<boolean>;
136
138
  sessionService?: ISessionService;
137
139
  sessionId?: string;
138
140
  /**
@@ -20,7 +20,7 @@ import { DialogProps } from '@mui/material/Dialog';
20
20
  * host-registered ask-user components (AskCreateAccount, add_passengers, …) work here unchanged.</p>
21
21
  */
22
22
  export interface AskUserDialogProps {
23
- /** Heading above the prompt. Defaults to a neutral English label; hosts localize it. */
23
+ /** Heading above the prompt. Defaults to a neutral pt-BR label; a host can override it. */
24
24
  title?: React.ReactNode;
25
25
  /** Dialog width. Defaults to `'sm'`. */
26
26
  maxWidth?: DialogProps['maxWidth'];
@@ -29,7 +29,7 @@ export interface AskUserDialogProps {
29
29
  * anything behind the dialog and you want the question to stay in the way until it is dealt with.
30
30
  */
31
31
  minimizable?: boolean;
32
- /** Label of the restore chip while minimized. Defaults to an English label; hosts localize it. */
32
+ /** Label of the restore chip while minimized. Defaults to a pt-BR label; a host can override it. */
33
33
  minimizedLabel?: string;
34
34
  }
35
35
  declare const AskUserDialog: React.FC<AskUserDialogProps>;
@@ -6,6 +6,8 @@ export interface FriendlyToolEntry {
6
6
  extractDetail?: (args: any) => string;
7
7
  }
8
8
  export declare const friendlyToolConfigRegistry: Record<string, FriendlyToolEntry>;
9
+ /** What an unregistered tool reads as — generic on purpose: the tool's name is never shown. */
10
+ export declare const FALLBACK_FRIENDLY_LABELS: Readonly<Record<FriendlyState, string>>;
9
11
  export declare function configureFriendlyMapping(toolName: string, mapping: FriendlyToolEntry): void;
10
12
  export type FriendlyState = 'partial' | 'call' | 'response';
11
13
  export declare function getFriendlyLabel(toolName: string, state: FriendlyState, args?: any, isError?: boolean): string;
@@ -31,6 +31,17 @@ export interface AiChatEngineConfig {
31
31
  * (the JWT rides the handshake and is fixed for the socket's lifetime).
32
32
  */
33
33
  getUser?: () => User | undefined;
34
+ /**
35
+ * Can the socket dial with the token it holds? Renew a stale token here, and answer `false` only when the session
36
+ * is over for good. Called before EVERY dial the connection makes — the first one, each redial after a drop, and
37
+ * the redial when activity returns after an idle close — because the token rides the handshake, and an expired
38
+ * one is refused at the upgrade as a bare 1006 the retry loop cannot tell from a network blip.
39
+ *
40
+ * `true`: dial. `false`: stop, with halt reason `'credentials-expired'` (a later send asks again). A rejection is a
41
+ * transient failure (an unreachable IdP), retried on the backoff curve. Without it the engine still refuses a token
42
+ * that has already expired, but cannot renew one — long-lived hosts should pass it.
43
+ */
44
+ ensureDialableToken?: () => Promise<boolean>;
34
45
  /**
35
46
  * The agent this engine speaks as — and the ONLY public input that takes an
36
47
  * `AgentContext` (issue #59). It is fixed for the engine's lifetime: the
@@ -51,7 +51,7 @@ export interface ConnectionOutage {
51
51
  retryAt: number | null;
52
52
  /** Consecutive failed attempts so far (1 while waiting for the first redial). */
53
53
  attempt: number;
54
- /** Set when the supervisor gave up: 'attached-elsewhere' | 'session-gone' | 'closed-by-server'. */
54
+ /** Set when the supervisor gave up: 'attached-elsewhere' | 'session-gone' | 'closed-by-server' | 'credentials-expired'. */
55
55
  halted: string | null;
56
56
  }
57
57
  export interface AiChatState {
@@ -13,7 +13,9 @@ export type NotificationKind = 'connection-restarting'
13
13
  /** The server no longer has the session (4004, or it answered a dial with a different id); no redial. */
14
14
  | 'session-gone'
15
15
  /** The server closed on purpose (1000) or rejected the credentials (1008); no redial. */
16
- | 'connection-closed';
16
+ | 'connection-closed'
17
+ /** The access token expired and could not be renewed; the supervisor stopped dialling until a sign-in or a send. */
18
+ | 'credentials-expired';
17
19
  export interface BasicNotification {
18
20
  type: NotificationType;
19
21
  message: string;
@@ -10,12 +10,28 @@ import { FunctionDetails, ServerEvent } from '../../models/ServerEvent';
10
10
  * Soft: the check runs BEFORE a delta is appended, so a part ends up in
11
11
  * (cap, cap + one delta]. Since SDK v0.18 the server coalesces deltas into
12
12
  * ~50 ms / 4096-char frames, so a single delta can be larger than the cap.
13
+ *
14
+ * An answer's TEXT is cut only at a markdown block boundary past the cap, never
15
+ * mid-block (Issue 2239 — see `splitAtBlockBoundary`); a thought is cut at the cap.
13
16
  */
14
17
  export declare const MAX_CHAR_PER_TEXT_PART = 2000;
15
18
  export interface ReduceEffects {
16
19
  /** Called once per reduction that settles a tool RESULT onto its call (the fold). */
17
20
  onFunctionResponse?: (functionDetails: FunctionDetails) => void;
18
21
  }
22
+ /**
23
+ * Where a text delta may start a new part (Issue 2239), or -1.
24
+ *
25
+ * Every text part is rendered as its OWN markdown document, so a cut at an arbitrary character tears whatever
26
+ * block it lands in: half a table row becomes a paragraph with no header, half a code fence is unclosed. A cut is
27
+ * safe only at a block boundary — the live part plus the delta's head ends in a blank line, the tail starts with
28
+ * a non-blank character (an indented line could be a list item's continuation), and no code fence is open.
29
+ *
30
+ * Only once the live part is past the cap, and at the LAST such boundary in the delta, so a part is cut at most
31
+ * once per delta. A delta with no boundary returns -1 and the part keeps growing until one arrives: an
32
+ * oversized part costs render time, a torn one costs the answer.
33
+ */
34
+ export declare function splitAtBlockBoundary(liveText: string, delta: string): number;
19
35
  /**
20
36
  * The next interaction after one server event. Pure with respect to `prev`: no
21
37
  * part or array on the prior tree is mutated, and every part the event did not
@@ -39,6 +39,18 @@ export interface AgentGatewayOptions {
39
39
  * the conversation, and are treated as ordinary transcript frames.
40
40
  */
41
41
  transcriptOfDetachedRun?: boolean;
42
+ /**
43
+ * The bearer the socket dials with, read before every dial (AiChatEngine passes its `getUser`-backed reader). With
44
+ * no {@link ensureDialableToken}, an EXPIRED one halts the supervisor with `'credentials-expired'` instead of
45
+ * dialling: the server refuses it at the upgrade, and the browser reports that as a 1006 the loop would retry forever.
46
+ */
47
+ getToken?: () => string | null | undefined;
48
+ /**
49
+ * The host's own "can this socket dial?" — renew a stale token, refuse a dead session. Called before EVERY dial,
50
+ * redials included, and it replaces the built-in expiry check. `true`: dial. `false`: the session is over — halt
51
+ * with `'credentials-expired'`. A rejection is a transient failure, retried on the backoff curve.
52
+ */
53
+ ensureDialableToken?: () => Promise<boolean>;
42
54
  }
43
55
  /**
44
56
  * The agent gateway: owns the live session's interactions, turns server events
@@ -216,6 +228,20 @@ export declare class AgentGatewayWSAsync {
216
228
  * session is never swapped for another.
217
229
  */
218
230
  openConnection(sessionId?: string, options?: OpenOptions): Promise<string>;
231
+ /**
232
+ * Opening `sessionId` leaves the session this gateway is on: a different id, or a fresh session (undefined) while
233
+ * one is held. Re-opening the same session (a resume, a redial) is not a switch, and neither is the first open.
234
+ */
235
+ private isSessionSwitch;
236
+ /**
237
+ * Drop every piece of per-session turn state (AIA Issue 2261). The store's transcript is reset by the session
238
+ * record's bind, but the gateway is not: a turn of the previous conversation still open here (an `ask_user` card
239
+ * parked at its end, say) used to survive the switch, and the next conversation's first turn-complete handed the
240
+ * live message over to it — conversation A's question rendered in B, under B's agent, with A's timestamp. The
241
+ * status bubble of B's first send was a clone of A's interaction for the same reason, and a paused A merged B's
242
+ * first message into A's interaction id. Nothing here belongs to the next session, so none of it is carried over.
243
+ */
244
+ private forgetSession;
219
245
  closeConnection(closeTurn?: boolean): Promise<SendMessageResponse | null>;
220
246
  /** Hang up and stop supervising the connection. `closeTurn` also closes an open turn in the store. */
221
247
  stopStream(closeTurn?: boolean): void;
@@ -42,7 +42,13 @@ export type HaltReason =
42
42
  /** The server closed with 4004, or answered a dial for session A with session B: A is gone. */
43
43
  | 'session-gone'
44
44
  /** 1000 / 1008 — the server ended the conversation on purpose, or rejected our credentials. */
45
- | 'closed-by-server';
45
+ | 'closed-by-server'
46
+ /**
47
+ * The credential is gone: the token has expired and nothing renewed it ({@link ConnectionSupervisorPorts.ensureCredentials}
48
+ * said no). Decided BEFORE dialling, because the server refuses an expired token at the HTTP upgrade with a 401, and a
49
+ * browser reports a refused upgrade as a bare 1006 — the code that means "retry". Retrying would be forever.
50
+ */
51
+ | 'credentials-expired';
46
52
  export interface ConnectionTarget {
47
53
  /** The session to be on. Undefined only until the first fresh dial succeeds. */
48
54
  sessionId?: string;
@@ -64,6 +70,13 @@ export interface OpenOptions {
64
70
  prepare?: () => Promise<void>;
65
71
  }
66
72
  export interface ConnectionSupervisorPorts {
73
+ /**
74
+ * Asked before EVERY dial — the first one, each redial on the curve, and the redial when activity returns after an
75
+ * idle close. `true`: dial. `false`: the credential is gone for good — halt with `'credentials-expired'` instead of
76
+ * dialling a handshake the server will refuse. A rejection is a transient failure, retried on the curve like any
77
+ * other. Absent: every dial goes ahead.
78
+ */
79
+ ensureCredentials?: () => Promise<boolean>;
67
80
  /** Dial once. Resolves with the session id the server answered with; rejects when the socket died first. */
68
81
  dial: (sessionId: string | undefined, options: {
69
82
  resume: boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Seconds until a JWT's `exp`, read WITHOUT verifying it — the server verifies; this only answers
3
+ * "is it worth dialling with this token?". Negative once it has expired. `null` when the value is not a
4
+ * JWT or carries no numeric `exp` (an opaque token, a test stub): the caller then has no basis to refuse it.
5
+ */
6
+ export declare function secondsUntilJwtExpiry(token: string | null | undefined, nowMs?: number): number | null;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /** A JWT-shaped string (unsigned — the client only ever reads the payload). base64url, no padding, like a real one. */
2
+ export declare function jwtExpiringAt(expSeconds: number, extra?: Record<string, unknown>): string;
3
+ /** A JWT that expires `seconds` from now (negative: expired that long ago). */
4
+ export declare const jwtExpiringIn: (seconds: number, extra?: Record<string, unknown>) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aintela/chat",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -134,12 +134,12 @@
134
134
  "@types/react-syntax-highlighter": "^15.5.13",
135
135
  "@vitejs/plugin-react": "^4.5.2",
136
136
  "@vitest/coverage-v8": "^4.1.7",
137
- "happy-dom": "^20.11.1",
137
+ "happy-dom": "^21.0.4",
138
138
  "html-react-parser": "^5.2.0",
139
139
  "js-base64": "^3.7.0",
140
140
  "recharts": "^3.10.1",
141
141
  "typescript": "~5.8.3",
142
- "vite": "^6.3.5",
142
+ "vite": "^6.4.5",
143
143
  "vite-plugin-dts": "^4.5.0",
144
144
  "vitest": "^4.1.11"
145
145
  }