@meshagent/meshagent-tailwind 0.44.11 → 0.44.13

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 (48) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +47 -0
  3. package/dist/cjs/chat/chat-bot-view.d.ts +4 -1
  4. package/dist/cjs/chat/chat-bot-view.js +20 -52
  5. package/dist/cjs/chat/dataset-agent-thread.d.ts +35 -0
  6. package/dist/cjs/chat/dataset-agent-thread.js +429 -0
  7. package/dist/cjs/chat/realtime-audio-output.d.ts +44 -0
  8. package/dist/cjs/chat/realtime-audio-output.js +326 -0
  9. package/dist/cjs/chat/thread-list-view.js +18 -1
  10. package/dist/cjs/chat/thread-view.d.ts +32 -0
  11. package/dist/cjs/chat/thread-view.js +157 -0
  12. package/dist/cjs/index.d.ts +3 -0
  13. package/dist/cjs/index.js +3 -0
  14. package/dist/cjs/meetings/controls.js +8 -15
  15. package/dist/cjs/meetings/lobby.d.ts +1 -1
  16. package/dist/cjs/meetings/lobby.js +10 -6
  17. package/dist/cjs/meetings/meeting-scope.d.ts +3 -0
  18. package/dist/cjs/meetings/meeting-scope.js +25 -4
  19. package/dist/cjs/meetings/meeting-view.d.ts +4 -0
  20. package/dist/cjs/meetings/meeting-view.js +4 -10
  21. package/dist/cjs/meetings/meetings.d.ts +1 -0
  22. package/dist/cjs/meetings/meetings.js +1 -0
  23. package/dist/cjs/meetings/voice-agent-caller.d.ts +11 -0
  24. package/dist/cjs/meetings/voice-agent-caller.js +133 -0
  25. package/dist/esm/chat/chat-bot-view.d.ts +4 -1
  26. package/dist/esm/chat/chat-bot-view.js +23 -55
  27. package/dist/esm/chat/dataset-agent-thread.d.ts +35 -0
  28. package/dist/esm/chat/dataset-agent-thread.js +426 -0
  29. package/dist/esm/chat/realtime-audio-output.d.ts +44 -0
  30. package/dist/esm/chat/realtime-audio-output.js +310 -0
  31. package/dist/esm/chat/thread-list-view.js +18 -1
  32. package/dist/esm/chat/thread-view.d.ts +32 -0
  33. package/dist/esm/chat/thread-view.js +137 -0
  34. package/dist/esm/index.d.ts +3 -0
  35. package/dist/esm/index.js +3 -0
  36. package/dist/esm/meetings/controls.js +8 -15
  37. package/dist/esm/meetings/lobby.d.ts +1 -1
  38. package/dist/esm/meetings/lobby.js +10 -8
  39. package/dist/esm/meetings/meeting-scope.d.ts +3 -0
  40. package/dist/esm/meetings/meeting-scope.js +25 -4
  41. package/dist/esm/meetings/meeting-view.d.ts +4 -0
  42. package/dist/esm/meetings/meeting-view.js +4 -10
  43. package/dist/esm/meetings/meetings.d.ts +1 -0
  44. package/dist/esm/meetings/meetings.js +1 -0
  45. package/dist/esm/meetings/voice-agent-caller.d.ts +11 -0
  46. package/dist/esm/meetings/voice-agent-caller.js +113 -0
  47. package/dist/index.css +2 -2
  48. package/package.json +5 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.44.13]
2
+ - Stability
3
+
4
+ ## [0.44.12]
5
+ - Added generated project support flows across the SDK CLI, including visible-room selection, deploy-room updates, and expanded template creation coverage.
6
+ - Added `predev` dependency bootstrapping to generated JavaScript, TypeScript, and React templates, and restored room-workspace install/dev scripts.
7
+ - Expanded chat and voice UI support with realtime audio output, responsive meeting updates, and fixes for room-client invocation and voice-agent handoff behavior.
8
+ - Updated third-party packages: `ws` to `^8.21.0` and added `react-virtuoso` `^4.18.7`.
9
+
1
10
  ## [0.44.11]
2
11
  - Stability
3
12
 
package/README.md CHANGED
@@ -38,6 +38,53 @@ MeshAgent removes the infrastructure headaches of building and shipping AI Agent
38
38
 
39
39
  Follow our [Getting Started Documentation](https://docs.meshagent.com/introduction/get_started) to setup your MeshAgent account, create your first project, and start building agents!
40
40
 
41
+ ## Threaded Chat
42
+
43
+ For new chat integrations, compose the thread list and thread view directly. Use a shared room client and chat client, then keep the selected thread path in your app state:
44
+
45
+ ```tsx
46
+ import { useState } from "react";
47
+ import {
48
+ ChatThreadDisplayMode,
49
+ ThreadListView,
50
+ ThreadView,
51
+ } from "@meshagent/meshagent-tailwind";
52
+ import type { RoomClient } from "@meshagent/meshagent";
53
+ import type { BaseChatClient } from "@meshagent/meshagent-agents";
54
+
55
+ export function AgentChat({
56
+ roomClient,
57
+ chatClient,
58
+ }: {
59
+ roomClient: RoomClient;
60
+ chatClient: BaseChatClient;
61
+ }) {
62
+ const [selectedThreadPath, setSelectedThreadPath] = useState<string | null>(null);
63
+
64
+ return (
65
+ <div className="flex min-h-0 flex-1">
66
+ <ThreadListView
67
+ room={roomClient}
68
+ chatClient={chatClient}
69
+ selectedThreadPath={selectedThreadPath}
70
+ onSelectedThreadPathChanged={setSelectedThreadPath}
71
+ />
72
+ <ThreadView
73
+ room={roomClient}
74
+ chatClient={chatClient}
75
+ agentName="support-agent"
76
+ threadDisplayMode={ChatThreadDisplayMode.MultiThreadComposer}
77
+ selectedThreadPath={selectedThreadPath}
78
+ onSelectedThreadPathChanged={setSelectedThreadPath}
79
+ onSelectedThreadResolved={(path) => setSelectedThreadPath(path)}
80
+ />
81
+ </div>
82
+ );
83
+ }
84
+ ```
85
+
86
+ `ThreadListView` loads and manages the available agent threads. `ThreadView` renders the active thread and can start a new thread when `threadDisplayMode` is `ChatThreadDisplayMode.MultiThreadComposer`.
87
+
41
88
  ## Meetings
42
89
 
43
90
  The meeting components use a connected `RoomClient` to request LiveKit credentials before joining a meeting. Wrap `MeetingView` in `MeetingScope` and pass the same room client used by the rest of your app:
@@ -2,6 +2,7 @@ import type { ReactElement } from "react";
2
2
  import type { Participant, RoomClient } from "@meshagent/meshagent";
3
3
  import type { BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
4
4
  import type { AgentToolChoice } from "./agent-thread";
5
+ import type { DatasetThreadRowsLoader } from "./dataset-agent-thread";
5
6
  import { ChatThreadDisplayMode } from "./conversation-descriptor";
6
7
  export { ChatThreadDisplayMode, chatDocumentPath, resolvedThreadListPath, } from "./conversation-descriptor";
7
8
  export interface ChatBotViewProps {
@@ -34,5 +35,7 @@ export interface ChatBotViewProps {
34
35
  clientToolkits?: ClientToolkitDescription[];
35
36
  toolChoice?: AgentToolChoice;
36
37
  collapseMessages?: boolean;
38
+ threadSource?: "session" | "dataset";
39
+ rowsLoader?: DatasetThreadRowsLoader;
37
40
  }
38
- export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, toolChoice, collapseMessages, }: ChatBotViewProps): ReactElement;
41
+ export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, toolChoice, collapseMessages, threadSource, rowsLoader, }: ChatBotViewProps): ReactElement;
@@ -27,12 +27,10 @@ module.exports = __toCommonJS(chat_bot_view_exports);
27
27
  var import_jsx_runtime = require("react/jsx-runtime");
28
28
  var import_react = require("react");
29
29
  var import_meshagent_agents = require("@meshagent/meshagent-agents");
30
- var import_lucide_react = require("lucide-react");
31
- var import_agent_thread = require("./agent-thread");
32
30
  var import_conversation_descriptor = require("./conversation-descriptor");
33
31
  var import_utils = require("../lib/utils");
34
- var import_multi_thread_view = require("./multi-thread-view");
35
32
  var import_thread_list_view = require("./thread-list-view");
33
+ var import_thread_view = require("./thread-view");
36
34
  var import_conversation_descriptor2 = require("./conversation-descriptor");
37
35
  const multiThreadLayoutBreakpointPx = 920;
38
36
  function normalizePath(path) {
@@ -57,15 +55,6 @@ function useIsWideLayout(minWidth) {
57
55
  }, [minWidth]);
58
56
  return matches;
59
57
  }
60
- function MultiThreadUnavailable() {
61
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex min-h-0 flex-1 items-center justify-center px-4 py-8", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "w-full max-w-[912px] rounded-3xl border border-destructive/30 bg-destructive/5 p-6 text-destructive", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-start gap-3", children: [
62
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.AlertTriangle, { className: "mt-0.5 h-5 w-5 shrink-0" }),
63
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
64
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "text-lg font-semibold", children: "Unable to start a new thread" }),
65
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-1 text-sm text-destructive/80", children: "No chat agent is selected." })
66
- ] })
67
- ] }) }) });
68
- }
69
58
  function ChatBotView({
70
59
  room,
71
60
  chatClient,
@@ -93,11 +82,12 @@ function ChatBotView({
93
82
  threadListCollapsedHeight = 220,
94
83
  clientToolkits,
95
84
  toolChoice,
96
- collapseMessages = true
85
+ collapseMessages = true,
86
+ threadSource = "session",
87
+ rowsLoader
97
88
  }) {
98
89
  const isWideLayout = useIsWideLayout(multiThreadLayoutBreakpointPx);
99
90
  const resolvedDocumentPath = (0, import_react.useMemo)(() => normalizePath(documentPath ?? path), [documentPath, path]);
100
- const resolvedSingleThreadPath = (0, import_react.useMemo)(() => resolvedDocumentPath ?? (0, import_conversation_descriptor.chatDocumentPath)(agentName, { threadDir }), [agentName, resolvedDocumentPath, threadDir]);
101
91
  const needsChatClient = chatClient != null || threadDisplayMode === import_conversation_descriptor.ChatThreadDisplayMode.MultiThreadComposer;
102
92
  const ownsChatClient = chatClient == null && needsChatClient;
103
93
  const activeChatClient = (0, import_react.useMemo)(
@@ -159,59 +149,37 @@ function ChatBotView({
159
149
  }
160
150
  previousNewThreadResetVersionRef.current = newThreadResetVersion;
161
151
  }, [activeSelectedThreadPath, newThreadResetVersion, setSelectedThread, threadDisplayMode]);
162
- if (threadDisplayMode !== import_conversation_descriptor.ChatThreadDisplayMode.MultiThreadComposer) {
163
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
164
- import_agent_thread.AgentThread,
165
- {
166
- room,
167
- path: resolvedSingleThreadPath,
168
- chatClient: activeChatClient ?? void 0,
169
- disposeChatClient: false,
170
- agentName,
171
- emptyStateTitle,
172
- emptyStateDescription,
173
- clientToolkits,
174
- toolChoice,
175
- collapseMessages
176
- }
177
- );
178
- }
179
- if (!agentName?.trim()) {
180
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MultiThreadUnavailable, {});
181
- }
182
152
  const content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
183
- import_multi_thread_view.MultiThreadView,
153
+ import_thread_view.ThreadView,
184
154
  {
185
155
  room,
186
156
  chatClient: activeChatClient ?? void 0,
187
- disposeChatClient: false,
157
+ path,
158
+ documentPath,
188
159
  agentName,
160
+ threadDisplayMode,
161
+ threadDir,
189
162
  toolkit,
190
163
  tool,
164
+ centerComposer,
165
+ emptyStateTitle,
166
+ emptyStateDescription,
167
+ startNewThreadTitle,
168
+ startNewThreadDescription,
191
169
  selectedThreadPath: activeSelectedThreadPath,
192
170
  onSelectedThreadPathChanged: handleSelectedThreadPathChanged,
193
171
  onSelectedThreadResolved: emitResolvedThread,
194
172
  newThreadResetVersion,
195
- centerComposer,
196
173
  clientToolkits,
197
174
  toolChoice,
198
- builder: (threadPath) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
- import_agent_thread.AgentThread,
200
- {
201
- room,
202
- path: threadPath,
203
- chatClient: activeChatClient ?? void 0,
204
- disposeChatClient: false,
205
- agentName,
206
- emptyStateTitle: startNewThreadTitle,
207
- emptyStateDescription: startNewThreadDescription,
208
- clientToolkits,
209
- toolChoice,
210
- collapseMessages
211
- }
212
- )
175
+ collapseMessages,
176
+ threadSource,
177
+ rowsLoader
213
178
  }
214
179
  );
180
+ if (threadDisplayMode !== import_conversation_descriptor.ChatThreadDisplayMode.MultiThreadComposer) {
181
+ return content;
182
+ }
215
183
  if (!showThreadList || activeChatClient === null) {
216
184
  return content;
217
185
  }
@@ -0,0 +1,35 @@
1
+ import type { ReactElement } from "react";
2
+ import type { RoomClient } from "@meshagent/meshagent";
3
+ import { BaseChatClient } from "@meshagent/meshagent-agents";
4
+ import type { ClientToolkitDescription } from "@meshagent/meshagent-agents";
5
+ import { type AgentToolChoice } from "./agent-thread.js";
6
+ export type DatasetThreadRow = Record<string, unknown>;
7
+ export type DatasetThreadRows = Iterable<DatasetThreadRow>;
8
+ export type DatasetThreadRowsLoader = (args: DatasetThreadRowsLoaderArgs) => AsyncIterable<DatasetThreadRows> | Promise<DatasetThreadRows> | DatasetThreadRows;
9
+ export interface DatasetThreadRowsLoaderArgs {
10
+ path: string;
11
+ namespace: string[];
12
+ table: string;
13
+ }
14
+ export interface DatasetThreadRef {
15
+ namespace: string[];
16
+ table: string;
17
+ }
18
+ export interface DatasetAgentThreadProps {
19
+ room: RoomClient;
20
+ path: string;
21
+ chatClient?: BaseChatClient;
22
+ disposeChatClient?: boolean;
23
+ agentName?: string;
24
+ rowsLoader?: DatasetThreadRowsLoader;
25
+ emptyStateTitle?: string;
26
+ emptyStateDescription?: string;
27
+ clientToolkits?: ClientToolkitDescription[];
28
+ toolChoice?: AgentToolChoice;
29
+ collapseMessages?: boolean;
30
+ retryMissingTableMs?: number;
31
+ }
32
+ export type RoomDatasetAgentThreadProps = Omit<DatasetAgentThreadProps, "rowsLoader">;
33
+ export declare function DatasetAgentThread({ room, path, chatClient, disposeChatClient, agentName, rowsLoader, emptyStateTitle, emptyStateDescription, clientToolkits, toolChoice, collapseMessages, retryMissingTableMs, }: DatasetAgentThreadProps): ReactElement;
34
+ export declare function RoomDatasetAgentThread(props: RoomDatasetAgentThreadProps): ReactElement;
35
+ export declare function parseDatasetThreadRef(path: string): DatasetThreadRef;
@@ -0,0 +1,429 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var dataset_agent_thread_exports = {};
20
+ __export(dataset_agent_thread_exports, {
21
+ DatasetAgentThread: () => DatasetAgentThread,
22
+ RoomDatasetAgentThread: () => RoomDatasetAgentThread,
23
+ parseDatasetThreadRef: () => parseDatasetThreadRef
24
+ });
25
+ module.exports = __toCommonJS(dataset_agent_thread_exports);
26
+ var import_jsx_runtime = require("react/jsx-runtime");
27
+ var import_react = require("react");
28
+ var import_meshagent_agents = require("@meshagent/meshagent-agents");
29
+ var import_agent_thread = require("./agent-thread.js");
30
+ class DatasetReplayChatClient extends import_meshagent_agents.BaseChatClient {
31
+ upstream;
32
+ shouldStopUpstream;
33
+ eventPump;
34
+ stopped = false;
35
+ constructor({ upstream, shouldStopUpstream }) {
36
+ super();
37
+ this.upstream = upstream;
38
+ this.shouldStopUpstream = shouldStopUpstream;
39
+ }
40
+ agentParticipant() {
41
+ return this.upstream.agentParticipant();
42
+ }
43
+ localParticipantName() {
44
+ return this.upstream.localParticipantName();
45
+ }
46
+ async start() {
47
+ this.stopped = false;
48
+ await this.upstream.start();
49
+ if (this.eventPump == null) {
50
+ this.eventPump = this.pumpUpstreamEvents();
51
+ }
52
+ }
53
+ async stop() {
54
+ this.stopped = true;
55
+ if (this.shouldStopUpstream) {
56
+ await this.upstream.stop();
57
+ }
58
+ }
59
+ async sendAgentMessage(message, options) {
60
+ if (message.type === import_meshagent_agents.agentThreadOpenType || message.type === import_meshagent_agents.agentThreadCloseType) {
61
+ return;
62
+ }
63
+ await this.upstream.sendAgentMessage(message, options);
64
+ }
65
+ replayMessages(messages) {
66
+ for (const message of messages) {
67
+ this.handleAgentMessage(message, { createdAt: dateFromString(message.createdAt) ?? void 0 });
68
+ }
69
+ }
70
+ markThreadLoaded(path) {
71
+ this.handleAgentMessage(new import_meshagent_agents.ThreadLoaded({ threadId: path }));
72
+ }
73
+ async pumpUpstreamEvents() {
74
+ try {
75
+ for await (const event of this.upstream.events) {
76
+ if (this.stopped) {
77
+ return;
78
+ }
79
+ this.handleAgentMessage(event.message, {
80
+ createdAt: event.createdAt,
81
+ attachment: event.attachment
82
+ });
83
+ }
84
+ } finally {
85
+ this.eventPump = void 0;
86
+ }
87
+ }
88
+ }
89
+ function DatasetAgentThread({
90
+ room,
91
+ path,
92
+ chatClient,
93
+ disposeChatClient = false,
94
+ agentName,
95
+ rowsLoader,
96
+ emptyStateTitle,
97
+ emptyStateDescription,
98
+ clientToolkits,
99
+ toolChoice,
100
+ collapseMessages,
101
+ retryMissingTableMs = 500
102
+ }) {
103
+ const [loadError, setLoadError] = (0, import_react.useState)(null);
104
+ const normalizedPath = path.trim();
105
+ const activeRowsLoader = (0, import_react.useMemo)(() => rowsLoader ?? defaultRowsLoader(room), [room, rowsLoader]);
106
+ const upstreamChatClient = (0, import_react.useMemo)(
107
+ () => chatClient ?? new import_meshagent_agents.MessagingChatClient({ room, agentName }),
108
+ [agentName, chatClient, room]
109
+ );
110
+ const replayChatClient = (0, import_react.useMemo)(
111
+ () => new DatasetReplayChatClient({
112
+ upstream: upstreamChatClient,
113
+ shouldStopUpstream: chatClient == null || disposeChatClient
114
+ }),
115
+ [chatClient, disposeChatClient, upstreamChatClient]
116
+ );
117
+ (0, import_react.useEffect)(() => {
118
+ let cancelled = false;
119
+ let retryTimer;
120
+ const loadRows = async () => {
121
+ if (normalizedPath === "") {
122
+ setLoadError("thread path cannot be empty");
123
+ replayChatClient.markThreadLoaded(normalizedPath);
124
+ return;
125
+ }
126
+ let ref;
127
+ try {
128
+ ref = parseDatasetThreadRef(normalizedPath);
129
+ } catch (error) {
130
+ setLoadError(describeError(error));
131
+ replayChatClient.markThreadLoaded(normalizedPath);
132
+ return;
133
+ }
134
+ try {
135
+ setLoadError(null);
136
+ const messages = await loadDatasetThreadMessages(activeRowsLoader, {
137
+ path: normalizedPath,
138
+ namespace: ref.namespace,
139
+ table: ref.table
140
+ });
141
+ if (cancelled) {
142
+ return;
143
+ }
144
+ replayChatClient.replayMessages(messages);
145
+ replayChatClient.markThreadLoaded(normalizedPath);
146
+ } catch (error) {
147
+ if (cancelled) {
148
+ return;
149
+ }
150
+ if (isDatasetTableNotFoundError(error)) {
151
+ retryTimer = setTimeout(() => {
152
+ void loadRows();
153
+ }, retryMissingTableMs);
154
+ return;
155
+ }
156
+ setLoadError(describeError(error));
157
+ replayChatClient.markThreadLoaded(normalizedPath);
158
+ }
159
+ };
160
+ void loadRows();
161
+ return () => {
162
+ cancelled = true;
163
+ if (retryTimer !== void 0) {
164
+ clearTimeout(retryTimer);
165
+ }
166
+ };
167
+ }, [activeRowsLoader, normalizedPath, replayChatClient, retryMissingTableMs]);
168
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
169
+ loadError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pt-3", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mx-auto w-full max-w-[912px] whitespace-pre-wrap rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive", children: loadError }) }),
170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
171
+ import_agent_thread.AgentThread,
172
+ {
173
+ room,
174
+ path: normalizedPath,
175
+ chatClient: replayChatClient,
176
+ disposeChatClient: true,
177
+ agentName,
178
+ emptyStateTitle,
179
+ emptyStateDescription,
180
+ clientToolkits,
181
+ toolChoice,
182
+ collapseMessages
183
+ }
184
+ )
185
+ ] });
186
+ }
187
+ function RoomDatasetAgentThread(props) {
188
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DatasetAgentThread, { ...props });
189
+ }
190
+ function parseDatasetThreadRef(path) {
191
+ const normalized = path.trim().replace(/\/+$/u, "");
192
+ const prefix = "dataset://";
193
+ if (!normalized.startsWith(prefix)) {
194
+ throw new TypeError("dataset thread path must start with dataset://");
195
+ }
196
+ const body = normalized.slice(prefix.length);
197
+ const parts = body.split("/").map((part) => part.trim()).filter((part) => part !== "");
198
+ const table = parts[parts.length - 1];
199
+ if (table == null || table === "") {
200
+ throw new TypeError("dataset thread path must include a table name");
201
+ }
202
+ return {
203
+ namespace: parts.slice(0, -1),
204
+ table
205
+ };
206
+ }
207
+ function defaultRowsLoader(room) {
208
+ return async function* loadRows({ namespace, table }) {
209
+ for await (const chunk of room.datasets.searchStream({ table, namespace })) {
210
+ yield rowsFromTable(chunk);
211
+ }
212
+ };
213
+ }
214
+ async function loadDatasetThreadMessages(loader, args) {
215
+ const rows = [];
216
+ const loaded = await loader(args);
217
+ if (isAsyncIterable(loaded)) {
218
+ for await (const chunk of loaded) {
219
+ rows.push(...chunk);
220
+ }
221
+ } else {
222
+ rows.push(...loaded);
223
+ }
224
+ return rows.filter((row) => rowData(row) !== null).sort(compareDatasetThreadRows).flatMap((row) => messagesFromDatasetRow(row, args.path));
225
+ }
226
+ function rowsFromTable(table) {
227
+ const tableLike = table;
228
+ if (typeof tableLike.toArray !== "function") {
229
+ return [];
230
+ }
231
+ return tableLike.toArray().map((row) => row != null && typeof row === "object" ? { ...row } : {});
232
+ }
233
+ function messagesFromDatasetRow(row, path) {
234
+ const data = rowData(row);
235
+ if (data === null) {
236
+ return [];
237
+ }
238
+ const agentMessage = agentMessageFromPayload(data);
239
+ if (agentMessage !== null) {
240
+ return [agentMessage];
241
+ }
242
+ const kind = stringValue(data.kind);
243
+ if (kind === "message" || kind === "file") {
244
+ const text = stringValue(data.text) ?? "";
245
+ const attachments = kind === "file" ? stringList(data.urls) : stringList(data.attachments);
246
+ if (text.trim() === "" && attachments.length === 0) {
247
+ return [];
248
+ }
249
+ const role = stringValue(data.role);
250
+ if (role === "user") {
251
+ return [new import_meshagent_agents.TurnStart({
252
+ threadId: path,
253
+ messageId: rowItemId(row),
254
+ senderName: stringValue(data.sender_name),
255
+ createdAt: rowCreatedAt(row).toISOString(),
256
+ content: [
257
+ ...text.trim() === "" ? [] : [{ type: "text", text }],
258
+ ...attachments.map((url) => ({ type: "file", url }))
259
+ ]
260
+ })];
261
+ }
262
+ return [
263
+ new import_meshagent_agents.AgentTextContentStarted({
264
+ threadId: path,
265
+ itemId: rowItemId(row),
266
+ turnId: rowTurnId(row),
267
+ phase: stringValue(data.phase),
268
+ createdAt: rowCreatedAt(row).toISOString()
269
+ }),
270
+ ...text.trim() === "" ? [] : [new import_meshagent_agents.AgentTextContentDelta({
271
+ threadId: path,
272
+ itemId: rowItemId(row),
273
+ turnId: rowTurnId(row),
274
+ phase: stringValue(data.phase),
275
+ text,
276
+ createdAt: rowCreatedAt(row).toISOString()
277
+ })],
278
+ new import_meshagent_agents.AgentTextContentEnded({
279
+ threadId: path,
280
+ itemId: rowItemId(row),
281
+ turnId: rowTurnId(row),
282
+ phase: stringValue(data.phase),
283
+ createdAt: rowCreatedAt(row).toISOString()
284
+ })
285
+ ];
286
+ }
287
+ if (kind === "reasoning") {
288
+ const text = stringValue(data.text) ?? "";
289
+ if (text.trim() === "") {
290
+ return [];
291
+ }
292
+ return [
293
+ new import_meshagent_agents.AgentReasoningContentStarted({
294
+ threadId: path,
295
+ itemId: rowItemId(row),
296
+ turnId: rowTurnId(row),
297
+ createdAt: rowCreatedAt(row).toISOString()
298
+ }),
299
+ new import_meshagent_agents.AgentReasoningContentDelta({
300
+ threadId: path,
301
+ itemId: rowItemId(row),
302
+ turnId: rowTurnId(row),
303
+ text,
304
+ createdAt: rowCreatedAt(row).toISOString()
305
+ }),
306
+ new import_meshagent_agents.AgentReasoningContentEnded({
307
+ threadId: path,
308
+ itemId: rowItemId(row),
309
+ turnId: rowTurnId(row),
310
+ createdAt: rowCreatedAt(row).toISOString()
311
+ })
312
+ ];
313
+ }
314
+ if (kind === "tool_call") {
315
+ const toolkit = stringValue(data.toolkit) ?? "";
316
+ const tool = stringValue(data.tool) ?? "tool";
317
+ const status = stringValue(data.status);
318
+ const message = toolCallIsFinished(status) ? new import_meshagent_agents.AgentToolCallEnded({
319
+ threadId: path,
320
+ itemId: rowItemId(row),
321
+ turnId: rowTurnId(row),
322
+ toolkit,
323
+ tool,
324
+ arguments: objectValue(data.arguments) ?? void 0,
325
+ createdAt: rowCreatedAt(row).toISOString(),
326
+ error: stringValue(data.error_message) == null ? void 0 : { message: stringValue(data.error_message) }
327
+ }) : toolCallIsPending(status) ? new import_meshagent_agents.AgentToolCallPending({
328
+ threadId: path,
329
+ itemId: rowItemId(row),
330
+ turnId: rowTurnId(row),
331
+ toolkit,
332
+ tool,
333
+ arguments: objectValue(data.arguments) ?? void 0,
334
+ createdAt: rowCreatedAt(row).toISOString()
335
+ }) : new import_meshagent_agents.AgentToolCallStarted({
336
+ threadId: path,
337
+ itemId: rowItemId(row),
338
+ turnId: rowTurnId(row),
339
+ toolkit,
340
+ tool,
341
+ arguments: objectValue(data.arguments) ?? void 0,
342
+ createdAt: rowCreatedAt(row).toISOString()
343
+ });
344
+ return [message];
345
+ }
346
+ return [];
347
+ }
348
+ function agentMessageFromPayload(payload) {
349
+ if (typeof payload.type !== "string" || payload.type.trim() === "") {
350
+ return null;
351
+ }
352
+ try {
353
+ return import_meshagent_agents.AgentMessage.fromJson(payload);
354
+ } catch {
355
+ return null;
356
+ }
357
+ }
358
+ function rowData(row) {
359
+ return objectValue(row.data);
360
+ }
361
+ function compareDatasetThreadRows(left, right) {
362
+ const sequenceOrder = numberValue(left.sequence) - numberValue(right.sequence);
363
+ if (sequenceOrder !== 0) {
364
+ return sequenceOrder;
365
+ }
366
+ const timestampOrder = rowCreatedAt(left).getTime() - rowCreatedAt(right).getTime();
367
+ if (timestampOrder !== 0) {
368
+ return timestampOrder;
369
+ }
370
+ return rowItemId(left).localeCompare(rowItemId(right));
371
+ }
372
+ function rowItemId(row) {
373
+ return stringValue(row.item_id) ?? `row:${stringValue(row.sequence) ?? ""}:${stringValue(row.timestamp) ?? stringValue(row.created_at) ?? ""}`;
374
+ }
375
+ function rowTurnId(row) {
376
+ return stringValue(row.turn_id) ?? rowItemId(row);
377
+ }
378
+ function rowCreatedAt(row) {
379
+ return dateFromString(stringValue(row.timestamp) ?? stringValue(row.created_at)) ?? /* @__PURE__ */ new Date(0);
380
+ }
381
+ function dateFromString(value) {
382
+ if (value == null || value.trim() === "") {
383
+ return null;
384
+ }
385
+ const parsed = new Date(value);
386
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
387
+ }
388
+ function isDatasetTableNotFoundError(error) {
389
+ const values = [
390
+ error instanceof Error ? error.message : void 0,
391
+ typeof error === "object" && error !== null ? stringValue(error.code) : void 0
392
+ ].filter((value) => value != null);
393
+ return values.some((value) => {
394
+ const normalized = value.trim().toLowerCase();
395
+ return normalized.includes("not found") || normalized.includes("not_found") || normalized.includes("does not exist");
396
+ });
397
+ }
398
+ function describeError(error) {
399
+ if (error instanceof Error && error.message.trim() !== "") {
400
+ return error.message;
401
+ }
402
+ return String(error);
403
+ }
404
+ function isAsyncIterable(value) {
405
+ return value != null && typeof value === "object" && Symbol.asyncIterator in value;
406
+ }
407
+ function objectValue(value) {
408
+ return value != null && typeof value === "object" && !Array.isArray(value) ? value : null;
409
+ }
410
+ function stringValue(value) {
411
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
412
+ }
413
+ function stringList(value) {
414
+ if (!Array.isArray(value)) {
415
+ return [];
416
+ }
417
+ return value.filter((entry) => typeof entry === "string" && entry.trim() !== "").map((entry) => entry.trim());
418
+ }
419
+ function numberValue(value) {
420
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
421
+ }
422
+ function toolCallIsPending(status) {
423
+ const normalized = status?.trim().toLowerCase();
424
+ return normalized === "pending" || normalized === "queued";
425
+ }
426
+ function toolCallIsFinished(status) {
427
+ const normalized = status?.trim().toLowerCase();
428
+ return normalized === "completed" || normalized === "failed" || normalized === "error";
429
+ }