@aintela/chat 0.6.0 → 0.7.0

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 (57) hide show
  1. package/README.md +43 -0
  2. package/dist/components.js +7528 -7182
  3. package/dist/components.js.map +1 -1
  4. package/dist/{httpArtifactService-DYQDPVVH.js → detachedRunActivity-CjyFTKSw.js} +769 -324
  5. package/dist/detachedRunActivity-CjyFTKSw.js.map +1 -0
  6. package/dist/detachedRunModel-X59Pb5V-.js +67 -0
  7. package/dist/{detachedRunModel-1ii9qGTW.js.map → detachedRunModel-X59Pb5V-.js.map} +1 -1
  8. package/dist/hooks.js +1 -1
  9. package/dist/httpSessionService-Ckb9Cxia.js +320 -0
  10. package/dist/httpSessionService-Ckb9Cxia.js.map +1 -0
  11. package/dist/index.js +296 -274
  12. package/dist/models.js +47 -41
  13. package/dist/{serializer-BNsp8xs2.js → serializer-DNUH6kgE.js} +567 -507
  14. package/dist/serializer-DNUH6kgE.js.map +1 -0
  15. package/dist/services.js +22 -15
  16. package/dist/src/components/AiChat/AiChatContext.d.ts +3 -1
  17. package/dist/src/components/AiChat/AiChatTypes.d.ts +7 -1
  18. package/dist/src/components/AiChat/ChatPane/InteractionOriginBadge.d.ts +15 -0
  19. package/dist/src/components/AiChat/ChatPane/messageUserOrigin.test.d.ts +1 -0
  20. package/dist/src/components/AiChat/aiChatEngine.d.ts +13 -1
  21. package/dist/src/components/index.d.ts +2 -0
  22. package/dist/src/components/v2/DetachedRunTaskBox.d.ts +30 -5
  23. package/dist/src/components/v2/DetachedRunTaskBox.live.test.d.ts +1 -0
  24. package/dist/src/components/v2/DetachedRunTranscript.d.ts +89 -0
  25. package/dist/src/components/v2/DetachedRunTranscript.test.d.ts +1 -0
  26. package/dist/src/components/v2/index.d.ts +5 -0
  27. package/dist/src/components/v2/useDetachedRunLiveActivity.d.ts +30 -0
  28. package/dist/src/components/v2/useDetachedRunResumeKey.d.ts +15 -0
  29. package/dist/src/components/v2/useDetachedRunResumeKey.test.d.ts +1 -0
  30. package/dist/src/models/Interaction.d.ts +15 -0
  31. package/dist/src/models/detachedRunModel.d.ts +11 -0
  32. package/dist/src/models/enums.d.ts +3 -1
  33. package/dist/src/models/index.d.ts +4 -3
  34. package/dist/src/models/semanticKernelModel/models.d.ts +22 -1
  35. package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +2 -1
  36. package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +15 -2
  37. package/dist/src/services/detachedRun/DetachedRunFramesTransport.d.ts +68 -0
  38. package/dist/src/services/detachedRun/DetachedRunFramesTransport.test.d.ts +1 -0
  39. package/dist/src/services/detachedRun/detachedRunActivity.d.ts +25 -0
  40. package/dist/src/services/detachedRun/streamDetachedRunFrames.d.ts +110 -0
  41. package/dist/src/services/detachedRun/streamDetachedRunFrames.test.d.ts +1 -0
  42. package/dist/src/services/index.d.ts +7 -0
  43. package/dist/src/services/servers/AgentGatewayService.d.ts +1 -1
  44. package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +67 -1
  45. package/dist/src/services/servers/gatewayAnnounceDetachedRun.test.d.ts +1 -0
  46. package/dist/src/services/servers/gatewayInteractionStarted.test.d.ts +1 -0
  47. package/dist/src/services/wire/decodeFrame.d.ts +6 -1
  48. package/dist/tests/fakes/fakeWebSocket.d.ts +8 -2
  49. package/dist/tests/fakes/makeGateway.d.ts +3 -1
  50. package/dist/{useChatSessions-Q41Jmr6P.js → useChatSessions-aTjNcj8q.js} +2 -2
  51. package/dist/{useChatSessions-Q41Jmr6P.js.map → useChatSessions-aTjNcj8q.js.map} +1 -1
  52. package/package.json +1 -1
  53. package/dist/detachedRunModel-1ii9qGTW.js +0 -50
  54. package/dist/httpArtifactService-DYQDPVVH.js.map +0 -1
  55. package/dist/httpSessionService-BY7JeW8d.js +0 -309
  56. package/dist/httpSessionService-BY7JeW8d.js.map +0 -1
  57. package/dist/serializer-BNsp8xs2.js.map +0 -1
@@ -13,10 +13,27 @@ import { AiChatState, AiChatStore } from '../../components/AiChat/stateConfigura
13
13
  import { INotificationPort } from '../../interfaces/INotificationPort';
14
14
  import { IStorageService } from '../storageService';
15
15
  import { HaltReason, OpenOptions } from './connectionSupervisor';
16
+ import { InteractionStart } from '../../models/semanticKernelModel/models';
16
17
  import { IWebSocketConnection } from '../WebSocketConnection/webSocketConnection';
17
18
  export interface GatewaySendMessageOptions {
18
19
  callId?: string;
19
20
  }
21
+ /**
22
+ * What {@link AgentGatewayWSAsync.announceDetachedRun} did: `sent` — on the socket now; `queued` — a turn is open in
23
+ * this tab (or the socket is down), it goes out when the chat is idle and connected; `duplicate` — this tab already
24
+ * asked for this run's settle.
25
+ */
26
+ export type AnnounceDetachedRunResult = 'sent' | 'queued' | 'duplicate';
27
+ /** Construction-time switches of {@link AgentGatewayWSAsync}. */
28
+ export interface AgentGatewayOptions {
29
+ /**
30
+ * The gateway shows ONE detached run's own session as its transcript (AIA Issue 1548, `DetachedRunTranscript`).
31
+ * Every frame on a run's session carries `detachedRunId`, which normally routes it to the run's box
32
+ * ({@link AgentGatewayWSAsync.handleDetachedRunEvent}) instead of the conversation; in this mode those frames ARE
33
+ * the conversation, and are treated as ordinary transcript frames.
34
+ */
35
+ transcriptOfDetachedRun?: boolean;
36
+ }
20
37
  /**
21
38
  * The agent gateway: owns the live session's interactions, turns server events
22
39
  * into interaction trees (through {@link InteractionService} and the reducer),
@@ -41,6 +58,19 @@ export declare class AgentGatewayWSAsync {
41
58
  protected interactionCallIds: Map<string, string>;
42
59
  /** Interactions whose turn was committed (turn-complete or a server error); a second close is ignored. */
43
60
  protected committedTurns: Set<string>;
61
+ /** Interactions this tab sent. An `InteractionStarted` for one of them announces what is already here. */
62
+ protected localInteractionIds: Set<string>;
63
+ /**
64
+ * Turns open right now, local and remote. `turnOpen` in the store is "any of these": a remote turn finishing
65
+ * must not unlock the composer under a local turn still streaming, nor the other way round.
66
+ */
67
+ protected openTurns: Set<string>;
68
+ protected readonly options: AgentGatewayOptions;
69
+ /** Announcements asked for in this tab, by `runId|settleKey` — a second request for the same settle is a no-op. */
70
+ protected announceRequested: Set<string>;
71
+ /** Announcements waiting for the chat to be idle (no open turn) and connected, in request order. */
72
+ protected pendingAnnouncements: string[];
73
+ private flushingAnnouncements;
44
74
  protected rawJwt: string;
45
75
  protected sessionId?: string;
46
76
  eventBusService: EventBusService;
@@ -71,7 +101,7 @@ export declare class AgentGatewayWSAsync {
71
101
  static readonly HALT_TURN_MESSAGE: Record<HaltReason, string>;
72
102
  /** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
73
103
  private readonly liveMessage;
74
- constructor(user: User, eventBusService: EventBusService, artifactService: IArtifactService, baseUrl: string, config: AgentContext, sessionStore: AiChatStore, notificationPort: INotificationPort, ws: IWebSocketConnection, storageService: IStorageService, sessionId?: string);
104
+ constructor(user: User, eventBusService: EventBusService, artifactService: IArtifactService, baseUrl: string, config: AgentContext, sessionStore: AiChatStore, notificationPort: INotificationPort, ws: IWebSocketConnection, storageService: IStorageService, sessionId?: string, options?: AgentGatewayOptions);
75
105
  /**
76
106
  * The turn the user is waiting on will not continue: close it from the client side with an error
77
107
  * part, the same way a server error would. No-op when no turn is open.
@@ -112,6 +142,24 @@ export declare class AgentGatewayWSAsync {
112
142
  getSessionId(): string | undefined;
113
143
  setSession(sessionId: string, _toolSessionId?: string): void;
114
144
  startInteraction(interactionQuestion: string, wasSuspended?: boolean | undefined, idOverrideForTests?: string): Interaction;
145
+ /** A new interaction and its merge service, in the maps. Who becomes current is the caller's decision. */
146
+ private registerInteraction;
147
+ /** The current interaction's turn is still open — it owns the live message, and must stay current. */
148
+ private currentTurnIsOpen;
149
+ /**
150
+ * A turn this tab did not send (AIA Issue 1548): a WhatsApp message, a platform wake turn, another tab's turn, a
151
+ * detached run's briefing. It becomes the current interaction only when no open turn holds that place — a local
152
+ * turn mid-stream keeps it, and with it the resume cursor, suspend and the client-side close; the remote turn
153
+ * streams into its own interaction and takes over the live message when that turn ends.
154
+ */
155
+ private openRemoteInteraction;
156
+ /**
157
+ * An `InteractionStarted` frame. Opens a turn this tab did not send, with the text that started it as its
158
+ * question; ignores one this tab sent (its interaction already exists) and one already known or committed.
159
+ * Outside {@link AgentGatewayOptions.transcriptOfDetachedRun}, a detached run's turn is ignored too: it runs on
160
+ * the run's own session, and its box — not this transcript — shows it.
161
+ */
162
+ interactionStarted(start: InteractionStart): void;
115
163
  getInteractions(): Interaction[];
116
164
  getCurrentInteractionId(): string | null;
117
165
  getCurrentInteraction(): Interaction | null;
@@ -131,6 +179,11 @@ export declare class AgentGatewayWSAsync {
131
179
  protected localEmitMessage(message: Interaction): void;
132
180
  protected localOpen(interactionId: string, _author: string): void;
133
181
  protected turnComplete(interactionId: string, agentInteraction: Interaction, _author: string, detachedRunId?: string): Promise<void>;
182
+ /**
183
+ * The current turn ended while another is still open (a remote turn that started under it): that one becomes
184
+ * current and its progress so far goes live at once.
185
+ */
186
+ private handOverLiveMessage;
134
187
  runningRequests: Map<string, Promise<Artifact | null>>;
135
188
  asyncLoadArtifact(artifactId: string): Promise<Artifact | null>;
136
189
  /**
@@ -169,6 +222,19 @@ export declare class AgentGatewayWSAsync {
169
222
  * thrown from a click handler — with the answer lost either way.
170
223
  */
171
224
  answerHumanTool(toolCallId: string, answer: string): 'sent' | 'queued';
225
+ /**
226
+ * Ask the server to tell this conversation about a detached run of it that settled (AIA Issue 1548 §5): the
227
+ * `AnnounceDetachedRun` socket action. The server claims every settled-and-unannounced run of the session at once
228
+ * (two tabs asking, one wins) and starts an ordinary turn on this socket, `origin: platform`, in the host's words —
229
+ * which arrives as any remote turn does (`InteractionStarted`).
230
+ *
231
+ * <p>Never over a turn: while one is open in this tab the request waits, and goes out when the chat is idle (and
232
+ * the socket up). `settleKey` — the run's `settledAt` — scopes the dedupe: a repeated request for the same settle
233
+ * is a no-op, a resumed run that settles anew is announced again.</p>
234
+ */
235
+ announceDetachedRun(runId: string, settleKey?: string | null): Promise<AnnounceDetachedRunResult>;
236
+ /** Send the queued announcements, oldest first, while the chat is idle and the socket is open. */
237
+ private flushAnnouncements;
172
238
  suspend(): Promise<boolean>;
173
239
  sleep(ms: number): Promise<unknown>;
174
240
  }
@@ -1,4 +1,4 @@
1
- import { LlmEvent, StreamingResponse, PartialLlmEvent } from '../../models/semanticKernelModel/models';
1
+ import { InteractionStart, LlmEvent, StreamingResponse, PartialLlmEvent } from '../../models/semanticKernelModel/models';
2
2
  /**
3
3
  * The server narrows a delta-only frame to `pe` (PartialEvent.cs): no envelope
4
4
  * fields beyond the interaction id, and one of `pt` (text, or the ARGUMENTS
@@ -19,3 +19,8 @@ export declare function llmEventFromPartial(pe: PartialLlmEvent): LlmEvent;
19
19
  export declare function llmEventFromFrame(frame: StreamingResponse): LlmEvent | undefined;
20
20
  /** True when the event carries any content item or streaming part — what counts as a first token. */
21
21
  export declare function carriesContent(event: LlmEvent): boolean;
22
+ /**
23
+ * The turn an `InteractionStarted` frame announces (AIA Issue 1548), with the envelope's detached run id carried
24
+ * onto it when the payload has none; undefined for any other frame, or one with no interaction id.
25
+ */
26
+ export declare function interactionStartFromFrame(frame: StreamingResponse): InteractionStart | undefined;
@@ -1,6 +1,6 @@
1
1
  import { ServerEvent } from '../../src/models/ServerEvent';
2
- import { IMessage, IWebSocketConnection } from '../../src/services/WebSocketConnection/webSocketConnection';
3
- import { InteractionStatistics } from '../../src/models/semanticKernelModel/models';
2
+ import { IMessage, IMessageBase, IWebSocketConnection } from '../../src/services/WebSocketConnection/webSocketConnection';
3
+ import { InteractionStart, InteractionStatistics } from '../../src/models/semanticKernelModel/models';
4
4
  export declare class FakeWebSocketConnection implements IWebSocketConnection {
5
5
  onEvent?: (event: MessageEvent | ServerEvent) => Promise<void>;
6
6
  onError?: (error: string) => void;
@@ -10,6 +10,7 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
10
10
  onClose?: (code: number, reason: string) => void;
11
11
  onNewPacket?: (stats: InteractionStatistics) => void;
12
12
  onRewindLost?: never;
13
+ onInteractionStarted?: (start: InteractionStart) => void;
13
14
  readonly recordedSends: IMessage[];
14
15
  sessionIdToReturn: string;
15
16
  /** Every `connect()` call — the id and options the gateway dialled with, in order. */
@@ -25,6 +26,9 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
25
26
  resume?: boolean;
26
27
  openInteractionId?: string;
27
28
  }): Promise<string>;
29
+ /** Every non-turn frame (`AnnounceDetachedRun`) sent through `sendBaseMessage`. */
30
+ readonly recordedBaseSends: IMessageBase[];
31
+ sendBaseMessage(message: IMessageBase): void;
28
32
  sendMessage(message: IMessage): void;
29
33
  suspendStream(): void;
30
34
  disconnect(): void;
@@ -44,5 +48,7 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
44
48
  * merge path is fully synchronous after the await, but if onEvent
45
49
  * ever grows an internal async hop the test stays correct).
46
50
  */
51
+ /** Drive an `InteractionStarted` announcement, as the real transport does for that frame type. */
52
+ announce(start: InteractionStart): void;
47
53
  deliver(event: ServerEvent): Promise<void>;
48
54
  }
@@ -1,6 +1,6 @@
1
1
  import { AiChatStore } from '../../src/components/AiChat/stateConfiguration';
2
2
  import { EventBusService } from '../../src/services/eventBusService';
3
- import { AgentGatewayWSAsync } from '../../src/services/servers/AgentGatewayWSAsync';
3
+ import { AgentGatewayWSAsync, AgentGatewayOptions } from '../../src/services/servers/AgentGatewayWSAsync';
4
4
  import { AgentContext } from '../../src/models/contexts';
5
5
  import { BasicNotification } from '../../src/models/Notification';
6
6
  import { INotificationPort } from '../../src/interfaces/INotificationPort';
@@ -43,6 +43,8 @@ export interface MakeGatewayOptions {
43
43
  * against the real wire code. `handle.ws` is then that object, typed as the fake.
44
44
  */
45
45
  ws?: IWebSocketConnection;
46
+ /** Construction-time gateway switches (e.g. `transcriptOfDetachedRun`). */
47
+ gatewayOptions?: AgentGatewayOptions;
46
48
  }
47
49
  /**
48
50
  * Build a fully-wired AgentGatewayWSAsync for tests. The `ws` field is
@@ -1,7 +1,7 @@
1
1
  var L = Object.defineProperty;
2
2
  var d = (e, t) => L(e, "name", { value: t, configurable: !0 });
3
3
  import { useMemo as h, useState as v, useCallback as g, useEffect as C } from "react";
4
- import { H } from "./httpSessionService-BY7JeW8d.js";
4
+ import { H } from "./httpSessionService-Ckb9Cxia.js";
5
5
  const w = 6e4, y = 60 * w, l = 24 * y;
6
6
  function k(e) {
7
7
  if (!e) return;
@@ -104,4 +104,4 @@ d(Y, "useChatSessions");
104
104
  export {
105
105
  Y as u
106
106
  };
107
- //# sourceMappingURL=useChatSessions-Q41Jmr6P.js.map
107
+ //# sourceMappingURL=useChatSessions-aTjNcj8q.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useChatSessions-Q41Jmr6P.js","sources":["../src/hooks/useChatSessions.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport type { ChatSession } from '@lib/models/ChatSession';\nimport type { ISessionService } from '@lib/services/servers/sessionService/ISessionService';\nimport { HttpSessionService } from '../services';\n\n/**\n * One row in a session-picker UI. `raw` is the original ChatSession the\n * server returned; everything else is a derived label the hook computed\n * (and the host's `decorate` callback may have overridden).\n */\nexport interface ChatSessionListItem {\n id: string;\n title: string;\n snippet?: string;\n /** Compact relative-time label (\"now\", \"5m\", \"2h\", \"Mar 14\"). */\n timeLabel?: string;\n /** Optional per-row tag — host-supplied via the `decorate` callback. */\n kind?: string;\n updatedAt?: Date;\n raw: ChatSession;\n}\n\n/**\n * Sessions bucketed by recency. The order of `label` reflects display\n * order top-down (\"Today\" first, \"Older\" last).\n */\nexport interface ChatSessionGroup {\n label: string;\n items: ChatSessionListItem[];\n}\n\nexport interface UseChatSessionsOptions {\n sessionService?: ISessionService;\n /**\n * If provided, the live (current) session is merged into the list —\n * replacing an existing entry by id, or prepended if not yet on the\n * server. Lets a \"New chat\" row appear instantly without waiting for\n * the server roundtrip.\n */\n liveSession?: ChatSession | null;\n\n accessToken: string,\n serverBaseUrl: string,\n /**\n * Per-row override hook. Whatever fields you return are merged on top\n * of the hook's computed item — typical use is adding a `kind` tag for\n * application-specific session types (`'chat' | 'composer' | ...`) the\n * library doesn't know about.\n */\n decorate?: (session: ChatSession) => Partial<ChatSessionListItem>;\n}\n\nexport interface UseChatSessionsResult {\n /** Flat list (live session merged in, server order preserved). */\n sessions: ChatSession[];\n /** Same data bucketed by recency. */\n groups: ChatSessionGroup[];\n isLoading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n /** Optimistic rename — patches local state immediately, rolls back on failure. */\n rename: (id: string, title: string) => Promise<void>;\n /** Optimistic remove — drops from local state immediately, rolls back on failure. */\n remove: (id: string) => Promise<void>;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nfunction toDate(value: Date | string | undefined | null): Date | undefined {\n if (!value) return undefined;\n if (value instanceof Date) return value;\n const d = new Date(value);\n return Number.isNaN(d.getTime()) ? undefined : d;\n}\n\nfunction formatTimeLabel(date: Date | undefined): string {\n if (!date) return '';\n const diff = Date.now() - date.getTime();\n if (diff < MINUTE_MS) return 'now';\n if (diff < HOUR_MS) return `${Math.floor(diff / MINUTE_MS)}m`;\n if (diff < DAY_MS) return `${Math.floor(diff / HOUR_MS)}h`;\n if (diff < 7 * DAY_MS) return `${Math.floor(diff / DAY_MS)}d`;\n return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });\n}\n\nfunction startOfToday(): Date {\n const d = new Date();\n d.setHours(0, 0, 0, 0);\n return d;\n}\n\nfunction groupByTime(items: ChatSessionListItem[]): ChatSessionGroup[] {\n const today = startOfToday();\n const yesterday = new Date(today.getTime() - DAY_MS);\n const weekAgo = new Date(today.getTime() - 7 * DAY_MS);\n const monthAgo = new Date(today.getTime() - 30 * DAY_MS);\n\n // Insertion-ordered map preserves the bucket display order.\n const buckets: Array<[string, ChatSessionListItem[]]> = [\n ['Today', []],\n ['Yesterday', []],\n ['This Week', []],\n ['This Month', []],\n ['Older', []],\n ];\n\n for (const item of items) {\n const u = item.updatedAt;\n if (!u) { buckets[4][1].push(item); continue; }\n if (u >= today) buckets[0][1].push(item);\n else if (u >= yesterday) buckets[1][1].push(item);\n else if (u >= weekAgo) buckets[2][1].push(item);\n else if (u >= monthAgo) buckets[3][1].push(item);\n else buckets[4][1].push(item);\n }\n\n return buckets\n .filter(([, list]) => list.length > 0)\n .map(([label, list]) => ({ label, items: list }));\n}\n\nfunction buildItem(\n session: ChatSession,\n decorate?: (s: ChatSession) => Partial<ChatSessionListItem>,\n): ChatSessionListItem {\n const updatedAt = toDate(session.updatedAt) ?? toDate(session.created);\n const base: ChatSessionListItem = {\n id: session.id ?? session.browserScopeId ?? '',\n title: session.overview || session.userDescription || '(untitled chat)',\n snippet: session.lastQuestion ?? undefined,\n timeLabel: formatTimeLabel(updatedAt),\n kind: session.agentType as string | undefined,\n updatedAt,\n raw: session,\n };\n return { ...base, ...(decorate?.(session) ?? {}) };\n}\n\n/**\n * Fetch + organise the user's chat sessions for a picker UI. Backend-agnostic\n * — the host injects an `ISessionService` so the same hook drives an HTTP\n * client, an in-memory fake, or whatever else.\n *\n * Replaces the duplicated `useEffect(async () => sessionService.getAllSessions())`\n * + grouping logic that lived in DataExplorerViewV2 and MobileSessionsList,\n * and consolidates the optimistic rename/delete pattern.\n */\nexport function useChatSessions(opts: UseChatSessionsOptions): UseChatSessionsResult {\n\n const defaultSessionService = useMemo(() => {\n return new HttpSessionService(opts.serverBaseUrl, opts.accessToken);\n }, [opts.accessToken, opts.serverBaseUrl]);\n\n const { sessionService, liveSession, decorate } = {\n sessionService: defaultSessionService,\n liveSession: opts.liveSession,\n decorate: opts.decorate\n };\n const [sessions, setSessions] = useState<ChatSession[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n\n const refresh = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n try {\n const list = await sessionService.getAllSessions();\n setSessions(list);\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)));\n } finally {\n setIsLoading(false);\n }\n }, [sessionService]);\n\n useEffect(() => { void refresh(); }, [refresh]);\n\n const merged = useMemo(() => {\n if (!liveSession?.id) return sessions;\n const idx = sessions.findIndex(s => s.id === liveSession.id);\n if (idx === -1) return [liveSession, ...sessions];\n const copy = sessions.slice();\n copy[idx] = liveSession;\n return copy;\n }, [sessions, liveSession]);\n\n const items = useMemo(\n () => merged.map(s => buildItem(s, decorate)),\n [merged, decorate],\n );\n\n const groups = useMemo(() => groupByTime(items), [items]);\n\n const rename = useCallback(async (id: string, title: string) => {\n setSessions(current =>\n current.map(s => (s.id === id ? { ...s, overview: title } : s)),\n );\n try {\n await sessionService.patchSession(id, { overview: title });\n } catch (err) {\n console.error('[useChatSessions] rename failed; refreshing to roll back:', err);\n void refresh();\n }\n }, [sessionService, refresh]);\n\n const remove = useCallback(async (id: string) => {\n setSessions(current => current.filter(s => s.id !== id));\n try {\n await sessionService.removeSession(id);\n } catch (err) {\n console.error('[useChatSessions] remove failed; refreshing to roll back:', err);\n void refresh();\n }\n }, [sessionService, refresh]);\n\n return { sessions: merged, groups, isLoading, error, refresh, rename, remove };\n}\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","toDate","value","d","__name","formatTimeLabel","date","diff","startOfToday","groupByTime","items","today","yesterday","weekAgo","monthAgo","buckets","item","u","list","label","buildItem","session","decorate","updatedAt","useChatSessions","opts","defaultSessionService","useMemo","HttpSessionService","sessionService","liveSession","sessions","setSessions","useState","isLoading","setIsLoading","error","setError","refresh","useCallback","err","useEffect","merged","idx","s","copy","groups","rename","id","title","current","remove"],"mappings":";;;;AAkEA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD;AAEpB,SAASE,EAAOC,GAA2D;AACvE,MAAI,CAACA,EAAO;AACZ,MAAIA,aAAiB,KAAM,QAAOA;AAClC,QAAMC,IAAI,IAAI,KAAKD,CAAK;AACxB,SAAO,OAAO,MAAMC,EAAE,QAAA,CAAS,IAAI,SAAYA;AACnD;AALSC,EAA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AAe,aAAamB,GAAI,EAAE,UAAUC,GAAO;AAAA,IAC7D,SAAST,GAAK;AACV,cAAQ,MAAM,6DAA6DA,CAAG,GACzEF,EAAA;AAAA,IACT;AAAA,EACJ,GAAG,CAACT,GAAgBS,CAAO,CAAC,GAEtBa,IAASZ,EAAY,OAAOS,MAAe;AAC7C,IAAAhB,EAAY,OAAWkB,EAAQ,OAAO,OAAKN,EAAE,OAAOI,CAAE,CAAC;AACvD,QAAI;AACA,YAAMnB,EAAe,cAAcmB,CAAE;AAAA,IACzC,SAASR,GAAK;AACV,cAAQ,MAAM,6DAA6DA,CAAG,GACzEF,EAAA;AAAA,IACT;AAAA,EACJ,GAAG,CAACT,GAAgBS,CAAO,CAAC;AAE5B,SAAO,EAAE,UAAUI,GAAQ,QAAAI,GAAQ,WAAAZ,GAAW,OAAAE,GAAO,SAAAE,GAAS,QAAAS,GAAQ,QAAAI,EAAA;AAC1E;AAtEgB/C,EAAAoB,GAAA;"}
1
+ {"version":3,"file":"useChatSessions-aTjNcj8q.js","sources":["../src/hooks/useChatSessions.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport type { ChatSession } from '@lib/models/ChatSession';\nimport type { ISessionService } from '@lib/services/servers/sessionService/ISessionService';\nimport { HttpSessionService } from '../services';\n\n/**\n * One row in a session-picker UI. `raw` is the original ChatSession the\n * server returned; everything else is a derived label the hook computed\n * (and the host's `decorate` callback may have overridden).\n */\nexport interface ChatSessionListItem {\n id: string;\n title: string;\n snippet?: string;\n /** Compact relative-time label (\"now\", \"5m\", \"2h\", \"Mar 14\"). */\n timeLabel?: string;\n /** Optional per-row tag — host-supplied via the `decorate` callback. */\n kind?: string;\n updatedAt?: Date;\n raw: ChatSession;\n}\n\n/**\n * Sessions bucketed by recency. The order of `label` reflects display\n * order top-down (\"Today\" first, \"Older\" last).\n */\nexport interface ChatSessionGroup {\n label: string;\n items: ChatSessionListItem[];\n}\n\nexport interface UseChatSessionsOptions {\n sessionService?: ISessionService;\n /**\n * If provided, the live (current) session is merged into the list —\n * replacing an existing entry by id, or prepended if not yet on the\n * server. Lets a \"New chat\" row appear instantly without waiting for\n * the server roundtrip.\n */\n liveSession?: ChatSession | null;\n\n accessToken: string,\n serverBaseUrl: string,\n /**\n * Per-row override hook. Whatever fields you return are merged on top\n * of the hook's computed item — typical use is adding a `kind` tag for\n * application-specific session types (`'chat' | 'composer' | ...`) the\n * library doesn't know about.\n */\n decorate?: (session: ChatSession) => Partial<ChatSessionListItem>;\n}\n\nexport interface UseChatSessionsResult {\n /** Flat list (live session merged in, server order preserved). */\n sessions: ChatSession[];\n /** Same data bucketed by recency. */\n groups: ChatSessionGroup[];\n isLoading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n /** Optimistic rename — patches local state immediately, rolls back on failure. */\n rename: (id: string, title: string) => Promise<void>;\n /** Optimistic remove — drops from local state immediately, rolls back on failure. */\n remove: (id: string) => Promise<void>;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nfunction toDate(value: Date | string | undefined | null): Date | undefined {\n if (!value) return undefined;\n if (value instanceof Date) return value;\n const d = new Date(value);\n return Number.isNaN(d.getTime()) ? undefined : d;\n}\n\nfunction formatTimeLabel(date: Date | undefined): string {\n if (!date) return '';\n const diff = Date.now() - date.getTime();\n if (diff < MINUTE_MS) return 'now';\n if (diff < HOUR_MS) return `${Math.floor(diff / MINUTE_MS)}m`;\n if (diff < DAY_MS) return `${Math.floor(diff / HOUR_MS)}h`;\n if (diff < 7 * DAY_MS) return `${Math.floor(diff / DAY_MS)}d`;\n return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });\n}\n\nfunction startOfToday(): Date {\n const d = new Date();\n d.setHours(0, 0, 0, 0);\n return d;\n}\n\nfunction groupByTime(items: ChatSessionListItem[]): ChatSessionGroup[] {\n const today = startOfToday();\n const yesterday = new Date(today.getTime() - DAY_MS);\n const weekAgo = new Date(today.getTime() - 7 * DAY_MS);\n const monthAgo = new Date(today.getTime() - 30 * DAY_MS);\n\n // Insertion-ordered map preserves the bucket display order.\n const buckets: Array<[string, ChatSessionListItem[]]> = [\n ['Today', []],\n ['Yesterday', []],\n ['This Week', []],\n ['This Month', []],\n ['Older', []],\n ];\n\n for (const item of items) {\n const u = item.updatedAt;\n if (!u) { buckets[4][1].push(item); continue; }\n if (u >= today) buckets[0][1].push(item);\n else if (u >= yesterday) buckets[1][1].push(item);\n else if (u >= weekAgo) buckets[2][1].push(item);\n else if (u >= monthAgo) buckets[3][1].push(item);\n else buckets[4][1].push(item);\n }\n\n return buckets\n .filter(([, list]) => list.length > 0)\n .map(([label, list]) => ({ label, items: list }));\n}\n\nfunction buildItem(\n session: ChatSession,\n decorate?: (s: ChatSession) => Partial<ChatSessionListItem>,\n): ChatSessionListItem {\n const updatedAt = toDate(session.updatedAt) ?? toDate(session.created);\n const base: ChatSessionListItem = {\n id: session.id ?? session.browserScopeId ?? '',\n title: session.overview || session.userDescription || '(untitled chat)',\n snippet: session.lastQuestion ?? undefined,\n timeLabel: formatTimeLabel(updatedAt),\n kind: session.agentType as string | undefined,\n updatedAt,\n raw: session,\n };\n return { ...base, ...(decorate?.(session) ?? {}) };\n}\n\n/**\n * Fetch + organise the user's chat sessions for a picker UI. Backend-agnostic\n * — the host injects an `ISessionService` so the same hook drives an HTTP\n * client, an in-memory fake, or whatever else.\n *\n * Replaces the duplicated `useEffect(async () => sessionService.getAllSessions())`\n * + grouping logic that lived in DataExplorerViewV2 and MobileSessionsList,\n * and consolidates the optimistic rename/delete pattern.\n */\nexport function useChatSessions(opts: UseChatSessionsOptions): UseChatSessionsResult {\n\n const defaultSessionService = useMemo(() => {\n return new HttpSessionService(opts.serverBaseUrl, opts.accessToken);\n }, [opts.accessToken, opts.serverBaseUrl]);\n\n const { sessionService, liveSession, decorate } = {\n sessionService: defaultSessionService,\n liveSession: opts.liveSession,\n decorate: opts.decorate\n };\n const [sessions, setSessions] = useState<ChatSession[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n\n const refresh = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n try {\n const list = await sessionService.getAllSessions();\n setSessions(list);\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)));\n } finally {\n setIsLoading(false);\n }\n }, [sessionService]);\n\n useEffect(() => { void refresh(); }, [refresh]);\n\n const merged = useMemo(() => {\n if (!liveSession?.id) return sessions;\n const idx = sessions.findIndex(s => s.id === liveSession.id);\n if (idx === -1) return [liveSession, ...sessions];\n const copy = sessions.slice();\n copy[idx] = liveSession;\n return copy;\n }, [sessions, liveSession]);\n\n const items = useMemo(\n () => merged.map(s => buildItem(s, decorate)),\n [merged, decorate],\n );\n\n const groups = useMemo(() => groupByTime(items), [items]);\n\n const rename = useCallback(async (id: string, title: string) => {\n setSessions(current =>\n current.map(s => (s.id === id ? { ...s, overview: title } : s)),\n );\n try {\n await sessionService.patchSession(id, { overview: title });\n } catch (err) {\n console.error('[useChatSessions] rename failed; refreshing to roll back:', err);\n void refresh();\n }\n }, [sessionService, refresh]);\n\n const remove = useCallback(async (id: string) => {\n setSessions(current => current.filter(s => s.id !== id));\n try {\n await sessionService.removeSession(id);\n } catch (err) {\n console.error('[useChatSessions] remove failed; refreshing to roll back:', err);\n void refresh();\n }\n }, [sessionService, refresh]);\n\n return { sessions: merged, groups, isLoading, error, refresh, rename, remove };\n}\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","toDate","value","d","__name","formatTimeLabel","date","diff","startOfToday","groupByTime","items","today","yesterday","weekAgo","monthAgo","buckets","item","u","list","label","buildItem","session","decorate","updatedAt","useChatSessions","opts","defaultSessionService","useMemo","HttpSessionService","sessionService","liveSession","sessions","setSessions","useState","isLoading","setIsLoading","error","setError","refresh","useCallback","err","useEffect","merged","idx","s","copy","groups","rename","id","title","current","remove"],"mappings":";;;;AAkEA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE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qC,IAASR,EAAY,OAAOS,GAAYC,MAAkB;AAC5D,IAAAjB;AAAA,MAAY,CAAAkB,MACRA,EAAQ,IAAI,CAAAN,MAAMA,EAAE,OAAOI,IAAK,EAAE,GAAGJ,GAAG,UAAUK,EAAA,IAAUL,CAAE;AAAA,IAAA;AAElE,QAAI;AACA,YAAMf,EAAe,aAAamB,GAAI,EAAE,UAAUC,GAAO;AAAA,IAC7D,SAAST,GAAK;AACV,cAAQ,MAAM,6DAA6DA,CAAG,GACzEF,EAAA;AAAA,IACT;AAAA,EACJ,GAAG,CAACT,GAAgBS,CAAO,CAAC,GAEtBa,IAASZ,EAAY,OAAOS,MAAe;AAC7C,IAAAhB,EAAY,OAAWkB,EAAQ,OAAO,OAAKN,EAAE,OAAOI,CAAE,CAAC;AACvD,QAAI;AACA,YAAMnB,EAAe,cAAcmB,CAAE;AAAA,IACzC,SAASR,GAAK;AACV,cAAQ,MAAM,6DAA6DA,CAAG,GACzEF,EAAA;AAAA,IACT;AAAA,EACJ,GAAG,CAACT,GAAgBS,CAAO,CAAC;AAE5B,SAAO,EAAE,UAAUI,GAAQ,QAAAI,GAAQ,WAAAZ,GAAW,OAAAE,GAAO,SAAAE,GAAS,QAAAS,GAAQ,QAAAI,EAAA;AAC1E;AAtEgB/C,EAAAoB,GAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aintela/chat",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,50 +0,0 @@
1
- var r = Object.defineProperty;
2
- var f = (e, i, t) => i in e ? r(e, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[i] = t;
3
- var s = (e, i) => r(e, "name", { value: i, configurable: !0 });
4
- var a = (e, i, t) => f(e, typeof i != "symbol" ? i + "" : i, t);
5
- const n = class n {
6
- constructor(i, t, c, d, o) {
7
- a(this, "mimeType");
8
- a(this, "data");
9
- a(this, "friendlyMessage");
10
- a(this, "fake");
11
- /**
12
- * Optional image attachments that travel as a structured payload
13
- * on the WS frame (see `IMessage.Images`). Kept separate from
14
- * `data` so we don't have to encode them into the text body — the
15
- * server adds them as `ImageContent` entries on the user turn.
16
- */
17
- a(this, "images");
18
- /**
19
- * Optional client-only UI representation for this user turn. Carried to the
20
- * server as a `UserUiContent` sibling (persisted + replayed) but stripped from
21
- * every model request — `data` stays the only model-facing text. `args` is a
22
- * serialized JSON string. The gateway also injects a matching `UserAnswer` part
23
- * on the live interaction so the component renders immediately.
24
- */
25
- a(this, "userUi");
26
- this.data = i, this.mimeType = t, this.friendlyMessage = d, this.fake = c, this.images = o;
27
- }
28
- };
29
- s(n, "ClientMessage");
30
- let u = n;
31
- const l = [
32
- "Completed",
33
- "Failed",
34
- "Cancelled"
35
- ];
36
- function h(e) {
37
- return e ? l.includes(e) : !1;
38
- }
39
- s(h, "isDetachedRunTerminalStatus");
40
- function T(e) {
41
- return e === "WaitingForInput";
42
- }
43
- s(T, "isDetachedRunWaitingForInput");
44
- export {
45
- u as C,
46
- l as D,
47
- T as a,
48
- h as i
49
- };
50
- //# sourceMappingURL=detachedRunModel-1ii9qGTW.js.map