@lantos1618/better-ui 0.7.0 → 0.8.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.
- package/dist/{ThemeProvider-CGxHnF2T.d.ts → ThemeProvider-BESbs5p6.d.ts} +1 -1
- package/dist/{ThemeProvider-A7krFsCJ.d.mts → ThemeProvider-Dx3STQtp.d.mts} +1 -1
- package/dist/agui/index.d.mts +1 -1
- package/dist/agui/index.d.ts +1 -1
- package/dist/components/index.d.mts +3 -3
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +53 -14
- package/dist/components/index.mjs +54 -15
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/mcp/index.d.mts +4 -2
- package/dist/mcp/index.d.ts +4 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.mjs +1 -1
- package/dist/react/index.d.mts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{tool-DGpwM6G6.d.mts → tool-yZTixiN2.d.mts} +20 -10
- package/dist/{tool-DGpwM6G6.d.ts → tool-yZTixiN2.d.ts} +20 -10
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { UIMessage, ChatStatus } from 'ai';
|
|
4
|
-
import { T as Tool } from './tool-
|
|
4
|
+
import { T as Tool } from './tool-yZTixiN2.js';
|
|
5
5
|
import { P as PersistenceAdapter, T as Thread$1 } from './types-CAOfGUPH.js';
|
|
6
6
|
|
|
7
7
|
interface ToolStateEntry {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { UIMessage, ChatStatus } from 'ai';
|
|
4
|
-
import { T as Tool } from './tool-
|
|
4
|
+
import { T as Tool } from './tool-yZTixiN2.mjs';
|
|
5
5
|
import { P as PersistenceAdapter, T as Thread$1 } from './types-CAOfGUPH.mjs';
|
|
6
6
|
|
|
7
7
|
interface ToolStateEntry {
|
package/dist/agui/index.d.mts
CHANGED
package/dist/agui/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { f as ToolStateStore, g as ToolStateEntry } from '../ThemeProvider-
|
|
2
|
-
export { h as Chat, C as ChatProps, i as ChatProvider, a as ChatProviderProps, j as Composer, b as ComposerProps, k as Message, M as MessageProps, l as ThemeProvider, T as ThemeProviderProps, m as Thread, c as ThreadProps, d as ToolPartInfo, n as ToolResult, e as ToolResultProps, o as createToolStateStore, u as useChatContext, p as useToolState } from '../ThemeProvider-
|
|
1
|
+
import { f as ToolStateStore, g as ToolStateEntry } from '../ThemeProvider-Dx3STQtp.mjs';
|
|
2
|
+
export { h as Chat, C as ChatProps, i as ChatProvider, a as ChatProviderProps, j as Composer, b as ComposerProps, k as Message, M as MessageProps, l as ThemeProvider, T as ThemeProviderProps, m as Thread, c as ThreadProps, d as ToolPartInfo, n as ToolResult, e as ToolResultProps, o as createToolStateStore, u as useChatContext, p as useToolState } from '../ThemeProvider-Dx3STQtp.mjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { T as Tool } from '../tool-
|
|
4
|
+
import { T as Tool } from '../tool-yZTixiN2.mjs';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import 'ai';
|
|
7
7
|
import '../types-CAOfGUPH.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { f as ToolStateStore, g as ToolStateEntry } from '../ThemeProvider-
|
|
2
|
-
export { h as Chat, C as ChatProps, i as ChatProvider, a as ChatProviderProps, j as Composer, b as ComposerProps, k as Message, M as MessageProps, l as ThemeProvider, T as ThemeProviderProps, m as Thread, c as ThreadProps, d as ToolPartInfo, n as ToolResult, e as ToolResultProps, o as createToolStateStore, u as useChatContext, p as useToolState } from '../ThemeProvider-
|
|
1
|
+
import { f as ToolStateStore, g as ToolStateEntry } from '../ThemeProvider-BESbs5p6.js';
|
|
2
|
+
export { h as Chat, C as ChatProps, i as ChatProvider, a as ChatProviderProps, j as Composer, b as ComposerProps, k as Message, M as MessageProps, l as ThemeProvider, T as ThemeProviderProps, m as Thread, c as ThreadProps, d as ToolPartInfo, n as ToolResult, e as ToolResultProps, o as createToolStateStore, u as useChatContext, p as useToolState } from '../ThemeProvider-BESbs5p6.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { T as Tool } from '../tool-
|
|
4
|
+
import { T as Tool } from '../tool-yZTixiN2.js';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import 'ai';
|
|
7
7
|
import '../types-CAOfGUPH.js';
|
package/dist/components/index.js
CHANGED
|
@@ -179,16 +179,24 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
179
179
|
const [threads, setThreads] = (0, import_react2.useState)([]);
|
|
180
180
|
const [activeThreadId, setActiveThreadId] = (0, import_react2.useState)(threadId);
|
|
181
181
|
(0, import_react2.useEffect)(() => {
|
|
182
|
-
if (persistence)
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
if (!persistence) return;
|
|
183
|
+
let cancelled = false;
|
|
184
|
+
persistence.listThreads().then((t) => {
|
|
185
|
+
if (!cancelled) setThreads(t);
|
|
186
|
+
}).catch((err) => console.warn("[better-ui] persistence error:", err));
|
|
187
|
+
return () => {
|
|
188
|
+
cancelled = true;
|
|
189
|
+
};
|
|
185
190
|
}, [persistence]);
|
|
186
191
|
(0, import_react2.useEffect)(() => {
|
|
187
|
-
if (persistence
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
+
if (!persistence || !activeThreadId) return;
|
|
193
|
+
let cancelled = false;
|
|
194
|
+
persistence.getMessages(activeThreadId).then((msgs) => {
|
|
195
|
+
if (!cancelled) setMessages(msgs);
|
|
196
|
+
}).catch((err) => console.warn("[better-ui] persistence error:", err));
|
|
197
|
+
return () => {
|
|
198
|
+
cancelled = true;
|
|
199
|
+
};
|
|
192
200
|
}, [persistence, activeThreadId, setMessages]);
|
|
193
201
|
const prevStatusRef = (0, import_react2.useRef)(status);
|
|
194
202
|
(0, import_react2.useEffect)(() => {
|
|
@@ -212,9 +220,10 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
212
220
|
}, [persistence, setMessages, toolStateStore]);
|
|
213
221
|
const switchThreadFn = (0, import_react2.useCallback)(async (id) => {
|
|
214
222
|
if (!persistence) throw new Error("Persistence not configured");
|
|
215
|
-
|
|
216
|
-
setMessages([]);
|
|
223
|
+
const msgs = await persistence.getMessages(id);
|
|
217
224
|
toolStateStore.clear();
|
|
225
|
+
setMessages(msgs);
|
|
226
|
+
setActiveThreadId(id);
|
|
218
227
|
}, [persistence, setMessages, toolStateStore]);
|
|
219
228
|
const deleteThreadFn = (0, import_react2.useCallback)(async (id) => {
|
|
220
229
|
if (!persistence) throw new Error("Persistence not configured");
|
|
@@ -237,8 +246,11 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
237
246
|
stateContext[entry.toolName] = entry.output;
|
|
238
247
|
}
|
|
239
248
|
}
|
|
240
|
-
|
|
241
|
-
|
|
249
|
+
if (Object.keys(stateContext).length > 0) {
|
|
250
|
+
dirty.clear();
|
|
251
|
+
return stateContext;
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
242
254
|
}, [toolStateStore]);
|
|
243
255
|
const executeToolDirect = (0, import_react2.useCallback)(async (toolName, toolInput, toolCallId) => {
|
|
244
256
|
const currentVersion = (versionRef.current.get(toolCallId) || 0) + 1;
|
|
@@ -420,6 +432,33 @@ var import_ai2 = require("ai");
|
|
|
420
432
|
// src/components/ToolResult.tsx
|
|
421
433
|
var import_react4 = require("react");
|
|
422
434
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
435
|
+
var ToolViewErrorBoundary = class extends import_react4.Component {
|
|
436
|
+
constructor() {
|
|
437
|
+
super(...arguments);
|
|
438
|
+
this.state = { error: null };
|
|
439
|
+
}
|
|
440
|
+
static getDerivedStateFromError(error) {
|
|
441
|
+
return { error };
|
|
442
|
+
}
|
|
443
|
+
componentDidCatch(error, info) {
|
|
444
|
+
console.error(`[better-ui] View for tool "${this.props.toolName}" threw:`, error, info);
|
|
445
|
+
}
|
|
446
|
+
render() {
|
|
447
|
+
if (this.state.error) {
|
|
448
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "bg-[var(--bui-error-muted,rgba(220,38,38,0.08))] border border-[var(--bui-error-border,rgba(153,27,27,0.5))] rounded-xl p-4", children: [
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
450
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "w-4 h-4 text-[var(--bui-error-fg,#f87171)] shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" }) }),
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "text-[var(--bui-error-fg,#f87171)] text-sm font-medium", children: [
|
|
452
|
+
this.props.toolName,
|
|
453
|
+
" view error"
|
|
454
|
+
] })
|
|
455
|
+
] }),
|
|
456
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-[var(--bui-error-fg,#f87171)]/70 text-xs mt-1", children: this.state.error.message })
|
|
457
|
+
] });
|
|
458
|
+
}
|
|
459
|
+
return this.props.children;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
423
462
|
function useIsFollowup(toolStateStore, toolCallId) {
|
|
424
463
|
const subscribe = (0, import_react4.useCallback)(
|
|
425
464
|
(listener) => toolStateStore.subscribeAll(listener),
|
|
@@ -602,7 +641,7 @@ function ToolResult({
|
|
|
602
641
|
)
|
|
603
642
|
] });
|
|
604
643
|
}
|
|
605
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: className || "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
644
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: className || "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolViewErrorBoundary, { toolName, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
606
645
|
toolDef.View,
|
|
607
646
|
{
|
|
608
647
|
data: resolvedOutput,
|
|
@@ -610,7 +649,7 @@ function ToolResult({
|
|
|
610
649
|
onAction: getOnAction(toolCallId, toolName),
|
|
611
650
|
error: storeState?.error ? new Error(storeState.error) : null
|
|
612
651
|
}
|
|
613
|
-
) });
|
|
652
|
+
) }) });
|
|
614
653
|
}
|
|
615
654
|
|
|
616
655
|
// src/components/Markdown.tsx
|
|
@@ -121,16 +121,24 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
121
121
|
const [threads, setThreads] = useState([]);
|
|
122
122
|
const [activeThreadId, setActiveThreadId] = useState(threadId);
|
|
123
123
|
useEffect(() => {
|
|
124
|
-
if (persistence)
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if (!persistence) return;
|
|
125
|
+
let cancelled = false;
|
|
126
|
+
persistence.listThreads().then((t) => {
|
|
127
|
+
if (!cancelled) setThreads(t);
|
|
128
|
+
}).catch((err) => console.warn("[better-ui] persistence error:", err));
|
|
129
|
+
return () => {
|
|
130
|
+
cancelled = true;
|
|
131
|
+
};
|
|
127
132
|
}, [persistence]);
|
|
128
133
|
useEffect(() => {
|
|
129
|
-
if (persistence
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
+
if (!persistence || !activeThreadId) return;
|
|
135
|
+
let cancelled = false;
|
|
136
|
+
persistence.getMessages(activeThreadId).then((msgs) => {
|
|
137
|
+
if (!cancelled) setMessages(msgs);
|
|
138
|
+
}).catch((err) => console.warn("[better-ui] persistence error:", err));
|
|
139
|
+
return () => {
|
|
140
|
+
cancelled = true;
|
|
141
|
+
};
|
|
134
142
|
}, [persistence, activeThreadId, setMessages]);
|
|
135
143
|
const prevStatusRef = useRef(status);
|
|
136
144
|
useEffect(() => {
|
|
@@ -154,9 +162,10 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
154
162
|
}, [persistence, setMessages, toolStateStore]);
|
|
155
163
|
const switchThreadFn = useCallback2(async (id) => {
|
|
156
164
|
if (!persistence) throw new Error("Persistence not configured");
|
|
157
|
-
|
|
158
|
-
setMessages([]);
|
|
165
|
+
const msgs = await persistence.getMessages(id);
|
|
159
166
|
toolStateStore.clear();
|
|
167
|
+
setMessages(msgs);
|
|
168
|
+
setActiveThreadId(id);
|
|
160
169
|
}, [persistence, setMessages, toolStateStore]);
|
|
161
170
|
const deleteThreadFn = useCallback2(async (id) => {
|
|
162
171
|
if (!persistence) throw new Error("Persistence not configured");
|
|
@@ -179,8 +188,11 @@ function ChatProvider({ endpoint = "/api/chat", tools, toolStateStore: externalS
|
|
|
179
188
|
stateContext[entry.toolName] = entry.output;
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
|
-
|
|
183
|
-
|
|
191
|
+
if (Object.keys(stateContext).length > 0) {
|
|
192
|
+
dirty.clear();
|
|
193
|
+
return stateContext;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
184
196
|
}, [toolStateStore]);
|
|
185
197
|
const executeToolDirect = useCallback2(async (toolName, toolInput, toolCallId) => {
|
|
186
198
|
const currentVersion = (versionRef.current.get(toolCallId) || 0) + 1;
|
|
@@ -364,8 +376,35 @@ import {
|
|
|
364
376
|
} from "ai";
|
|
365
377
|
|
|
366
378
|
// src/components/ToolResult.tsx
|
|
367
|
-
import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2, useCallback as useCallback3 } from "react";
|
|
379
|
+
import { Component, useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2, useCallback as useCallback3 } from "react";
|
|
368
380
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
381
|
+
var ToolViewErrorBoundary = class extends Component {
|
|
382
|
+
constructor() {
|
|
383
|
+
super(...arguments);
|
|
384
|
+
this.state = { error: null };
|
|
385
|
+
}
|
|
386
|
+
static getDerivedStateFromError(error) {
|
|
387
|
+
return { error };
|
|
388
|
+
}
|
|
389
|
+
componentDidCatch(error, info) {
|
|
390
|
+
console.error(`[better-ui] View for tool "${this.props.toolName}" threw:`, error, info);
|
|
391
|
+
}
|
|
392
|
+
render() {
|
|
393
|
+
if (this.state.error) {
|
|
394
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-[var(--bui-error-muted,rgba(220,38,38,0.08))] border border-[var(--bui-error-border,rgba(153,27,27,0.5))] rounded-xl p-4", children: [
|
|
395
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
396
|
+
/* @__PURE__ */ jsx2("svg", { className: "w-4 h-4 text-[var(--bui-error-fg,#f87171)] shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" }) }),
|
|
397
|
+
/* @__PURE__ */ jsxs("span", { className: "text-[var(--bui-error-fg,#f87171)] text-sm font-medium", children: [
|
|
398
|
+
this.props.toolName,
|
|
399
|
+
" view error"
|
|
400
|
+
] })
|
|
401
|
+
] }),
|
|
402
|
+
/* @__PURE__ */ jsx2("p", { className: "text-[var(--bui-error-fg,#f87171)]/70 text-xs mt-1", children: this.state.error.message })
|
|
403
|
+
] });
|
|
404
|
+
}
|
|
405
|
+
return this.props.children;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
369
408
|
function useIsFollowup(toolStateStore, toolCallId) {
|
|
370
409
|
const subscribe = useCallback3(
|
|
371
410
|
(listener) => toolStateStore.subscribeAll(listener),
|
|
@@ -548,7 +587,7 @@ function ToolResult({
|
|
|
548
587
|
)
|
|
549
588
|
] });
|
|
550
589
|
}
|
|
551
|
-
return /* @__PURE__ */ jsx2("div", { className: className || "", children: /* @__PURE__ */ jsx2(
|
|
590
|
+
return /* @__PURE__ */ jsx2("div", { className: className || "", children: /* @__PURE__ */ jsx2(ToolViewErrorBoundary, { toolName, children: /* @__PURE__ */ jsx2(
|
|
552
591
|
toolDef.View,
|
|
553
592
|
{
|
|
554
593
|
data: resolvedOutput,
|
|
@@ -556,7 +595,7 @@ function ToolResult({
|
|
|
556
595
|
onAction: getOnAction(toolCallId, toolName),
|
|
557
596
|
error: storeState?.error ? new Error(storeState.error) : null
|
|
558
597
|
}
|
|
559
|
-
) });
|
|
598
|
+
) }) });
|
|
560
599
|
}
|
|
561
600
|
|
|
562
601
|
// src/components/Markdown.tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CacheConfig, a as ClientFetchConfig, b as ClientHandler, S as ServerHandler, c as StreamCallback, d as StreamHandler, T as Tool, e as ToolBuilder, f as ToolConfig, g as ToolContext, V as ViewComponent, h as ViewState, t as tool } from './tool-
|
|
1
|
+
export { C as CacheConfig, a as ClientFetchConfig, b as ClientHandler, S as ServerHandler, c as StreamCallback, d as StreamHandler, T as Tool, e as ToolBuilder, f as ToolConfig, g as ToolContext, V as ViewComponent, h as ViewState, t as tool } from './tool-yZTixiN2.mjs';
|
|
2
2
|
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
3
|
-
export { C as ChatProps, a as ChatProviderProps, b as ComposerProps, M as MessageProps, T as ThemeProviderProps, c as ThreadProps, d as ToolPartInfo, e as ToolResultProps } from './ThemeProvider-
|
|
3
|
+
export { C as ChatProps, a as ChatProviderProps, b as ComposerProps, M as MessageProps, T as ThemeProviderProps, c as ThreadProps, d as ToolPartInfo, e as ToolResultProps } from './ThemeProvider-Dx3STQtp.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CacheConfig, a as ClientFetchConfig, b as ClientHandler, S as ServerHandler, c as StreamCallback, d as StreamHandler, T as Tool, e as ToolBuilder, f as ToolConfig, g as ToolContext, V as ViewComponent, h as ViewState, t as tool } from './tool-
|
|
1
|
+
export { C as CacheConfig, a as ClientFetchConfig, b as ClientHandler, S as ServerHandler, c as StreamCallback, d as StreamHandler, T as Tool, e as ToolBuilder, f as ToolConfig, g as ToolContext, V as ViewComponent, h as ViewState, t as tool } from './tool-yZTixiN2.js';
|
|
2
2
|
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
3
|
-
export { C as ChatProps, a as ChatProviderProps, b as ComposerProps, M as MessageProps, T as ThemeProviderProps, c as ThreadProps, d as ToolPartInfo, e as ToolResultProps } from './ThemeProvider-
|
|
3
|
+
export { C as ChatProps, a as ChatProviderProps, b as ComposerProps, M as MessageProps, T as ThemeProviderProps, c as ThreadProps, d as ToolPartInfo, e as ToolResultProps } from './ThemeProvider-BESbs5p6.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'react/jsx-runtime';
|
package/dist/mcp/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Tool, g as ToolContext } from '../tool-
|
|
1
|
+
import { T as Tool, g as ToolContext } from '../tool-yZTixiN2.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
@@ -152,6 +152,8 @@ interface JsonSchema {
|
|
|
152
152
|
additionalProperties?: boolean | JsonSchema;
|
|
153
153
|
[key: string]: unknown;
|
|
154
154
|
}
|
|
155
|
-
declare function zodToJsonSchema(schema: z.ZodType
|
|
155
|
+
declare function zodToJsonSchema(schema: z.ZodType | {
|
|
156
|
+
[key: string]: any;
|
|
157
|
+
}): JsonSchema;
|
|
156
158
|
|
|
157
159
|
export { MCPServer, type MCPServerConfig, createMCPServer, zodToJsonSchema };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Tool, g as ToolContext } from '../tool-
|
|
1
|
+
import { T as Tool, g as ToolContext } from '../tool-yZTixiN2.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
@@ -152,6 +152,8 @@ interface JsonSchema {
|
|
|
152
152
|
additionalProperties?: boolean | JsonSchema;
|
|
153
153
|
[key: string]: unknown;
|
|
154
154
|
}
|
|
155
|
-
declare function zodToJsonSchema(schema: z.ZodType
|
|
155
|
+
declare function zodToJsonSchema(schema: z.ZodType | {
|
|
156
|
+
[key: string]: any;
|
|
157
|
+
}): JsonSchema;
|
|
156
158
|
|
|
157
159
|
export { MCPServer, type MCPServerConfig, createMCPServer, zodToJsonSchema };
|
package/dist/mcp/index.js
CHANGED
package/dist/mcp/index.mjs
CHANGED
package/dist/react/index.d.mts
CHANGED
package/dist/react/index.d.ts
CHANGED
|
@@ -8,6 +8,16 @@ import React, { ReactElement } from 'react';
|
|
|
8
8
|
* with Better UI's unique view integration.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Schema type that works with both Zod 3 and Zod 4.
|
|
13
|
+
* Zod 4 removed internal properties (_parse, _type, etc.) from ZodType,
|
|
14
|
+
* so we use a structural type instead of z.ZodType directly.
|
|
15
|
+
*/
|
|
16
|
+
type ZodSchema<T = any> = z.ZodType<T> | {
|
|
17
|
+
parse: (data: unknown) => T;
|
|
18
|
+
safeParse: (data: unknown) => any;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
11
21
|
/** Behavioral hints for tools */
|
|
12
22
|
interface ToolHints {
|
|
13
23
|
/** Tool performs destructive/irreversible actions (auto-implies requiresConfirmation) */
|
|
@@ -63,8 +73,8 @@ interface ClientFetchConfig {
|
|
|
63
73
|
interface ToolConfig<TInput, TOutput> {
|
|
64
74
|
name: string;
|
|
65
75
|
description?: string;
|
|
66
|
-
input:
|
|
67
|
-
output?:
|
|
76
|
+
input: ZodSchema<TInput>;
|
|
77
|
+
output?: ZodSchema<TOutput>;
|
|
68
78
|
tags?: string[];
|
|
69
79
|
cache?: CacheConfig<TInput>;
|
|
70
80
|
/** Configure auto-fetch behavior for client-side execution */
|
|
@@ -99,8 +109,8 @@ type ViewComponent<TOutput, TInput = unknown> = (data: TOutput, state?: ViewStat
|
|
|
99
109
|
declare class Tool<TInput = any, TOutput = any> {
|
|
100
110
|
readonly name: string;
|
|
101
111
|
readonly description?: string;
|
|
102
|
-
readonly inputSchema:
|
|
103
|
-
readonly outputSchema?:
|
|
112
|
+
readonly inputSchema: ZodSchema<TInput>;
|
|
113
|
+
readonly outputSchema?: ZodSchema<TOutput>;
|
|
104
114
|
readonly tags: string[];
|
|
105
115
|
readonly cacheConfig?: CacheConfig<TInput>;
|
|
106
116
|
readonly clientFetchConfig?: ClientFetchConfig;
|
|
@@ -233,11 +243,11 @@ declare class Tool<TInput = any, TOutput = any> {
|
|
|
233
243
|
*/
|
|
234
244
|
toAITool(): {
|
|
235
245
|
description: string;
|
|
236
|
-
inputSchema:
|
|
246
|
+
inputSchema: ZodSchema<TInput>;
|
|
237
247
|
execute?: undefined;
|
|
238
248
|
} | {
|
|
239
249
|
description: string;
|
|
240
|
-
inputSchema:
|
|
250
|
+
inputSchema: ZodSchema<TInput>;
|
|
241
251
|
execute: (input: TInput) => Promise<TOutput>;
|
|
242
252
|
};
|
|
243
253
|
}
|
|
@@ -294,11 +304,11 @@ declare class ToolBuilder<TInput = any, TOutput = any> {
|
|
|
294
304
|
* 2. The return type correctly reflects the new generic parameter
|
|
295
305
|
* 3. TypeScript doesn't support "this type mutation" in fluent builders
|
|
296
306
|
*/
|
|
297
|
-
input<T>(schema:
|
|
307
|
+
input<T>(schema: ZodSchema<T>): ToolBuilder<T, TOutput>;
|
|
298
308
|
/**
|
|
299
309
|
* Define output schema - enables type inference for results
|
|
300
310
|
*/
|
|
301
|
-
output<O>(schema:
|
|
311
|
+
output<O>(schema: ZodSchema<O>): ToolBuilder<TInput, O>;
|
|
302
312
|
tags(...tags: string[]): this;
|
|
303
313
|
cache(config: CacheConfig<TInput>): this;
|
|
304
314
|
/** Configure auto-fetch endpoint for client-side execution */
|
|
@@ -349,11 +359,11 @@ declare class ToolBuilder<TInput = any, TOutput = any> {
|
|
|
349
359
|
};
|
|
350
360
|
toAITool(): {
|
|
351
361
|
description: string;
|
|
352
|
-
inputSchema:
|
|
362
|
+
inputSchema: ZodSchema<TInput>;
|
|
353
363
|
execute?: undefined;
|
|
354
364
|
} | {
|
|
355
365
|
description: string;
|
|
356
|
-
inputSchema:
|
|
366
|
+
inputSchema: ZodSchema<TInput>;
|
|
357
367
|
execute: (input: TInput) => Promise<TOutput>;
|
|
358
368
|
};
|
|
359
369
|
}
|
|
@@ -8,6 +8,16 @@ import React, { ReactElement } from 'react';
|
|
|
8
8
|
* with Better UI's unique view integration.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Schema type that works with both Zod 3 and Zod 4.
|
|
13
|
+
* Zod 4 removed internal properties (_parse, _type, etc.) from ZodType,
|
|
14
|
+
* so we use a structural type instead of z.ZodType directly.
|
|
15
|
+
*/
|
|
16
|
+
type ZodSchema<T = any> = z.ZodType<T> | {
|
|
17
|
+
parse: (data: unknown) => T;
|
|
18
|
+
safeParse: (data: unknown) => any;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
11
21
|
/** Behavioral hints for tools */
|
|
12
22
|
interface ToolHints {
|
|
13
23
|
/** Tool performs destructive/irreversible actions (auto-implies requiresConfirmation) */
|
|
@@ -63,8 +73,8 @@ interface ClientFetchConfig {
|
|
|
63
73
|
interface ToolConfig<TInput, TOutput> {
|
|
64
74
|
name: string;
|
|
65
75
|
description?: string;
|
|
66
|
-
input:
|
|
67
|
-
output?:
|
|
76
|
+
input: ZodSchema<TInput>;
|
|
77
|
+
output?: ZodSchema<TOutput>;
|
|
68
78
|
tags?: string[];
|
|
69
79
|
cache?: CacheConfig<TInput>;
|
|
70
80
|
/** Configure auto-fetch behavior for client-side execution */
|
|
@@ -99,8 +109,8 @@ type ViewComponent<TOutput, TInput = unknown> = (data: TOutput, state?: ViewStat
|
|
|
99
109
|
declare class Tool<TInput = any, TOutput = any> {
|
|
100
110
|
readonly name: string;
|
|
101
111
|
readonly description?: string;
|
|
102
|
-
readonly inputSchema:
|
|
103
|
-
readonly outputSchema?:
|
|
112
|
+
readonly inputSchema: ZodSchema<TInput>;
|
|
113
|
+
readonly outputSchema?: ZodSchema<TOutput>;
|
|
104
114
|
readonly tags: string[];
|
|
105
115
|
readonly cacheConfig?: CacheConfig<TInput>;
|
|
106
116
|
readonly clientFetchConfig?: ClientFetchConfig;
|
|
@@ -233,11 +243,11 @@ declare class Tool<TInput = any, TOutput = any> {
|
|
|
233
243
|
*/
|
|
234
244
|
toAITool(): {
|
|
235
245
|
description: string;
|
|
236
|
-
inputSchema:
|
|
246
|
+
inputSchema: ZodSchema<TInput>;
|
|
237
247
|
execute?: undefined;
|
|
238
248
|
} | {
|
|
239
249
|
description: string;
|
|
240
|
-
inputSchema:
|
|
250
|
+
inputSchema: ZodSchema<TInput>;
|
|
241
251
|
execute: (input: TInput) => Promise<TOutput>;
|
|
242
252
|
};
|
|
243
253
|
}
|
|
@@ -294,11 +304,11 @@ declare class ToolBuilder<TInput = any, TOutput = any> {
|
|
|
294
304
|
* 2. The return type correctly reflects the new generic parameter
|
|
295
305
|
* 3. TypeScript doesn't support "this type mutation" in fluent builders
|
|
296
306
|
*/
|
|
297
|
-
input<T>(schema:
|
|
307
|
+
input<T>(schema: ZodSchema<T>): ToolBuilder<T, TOutput>;
|
|
298
308
|
/**
|
|
299
309
|
* Define output schema - enables type inference for results
|
|
300
310
|
*/
|
|
301
|
-
output<O>(schema:
|
|
311
|
+
output<O>(schema: ZodSchema<O>): ToolBuilder<TInput, O>;
|
|
302
312
|
tags(...tags: string[]): this;
|
|
303
313
|
cache(config: CacheConfig<TInput>): this;
|
|
304
314
|
/** Configure auto-fetch endpoint for client-side execution */
|
|
@@ -349,11 +359,11 @@ declare class ToolBuilder<TInput = any, TOutput = any> {
|
|
|
349
359
|
};
|
|
350
360
|
toAITool(): {
|
|
351
361
|
description: string;
|
|
352
|
-
inputSchema:
|
|
362
|
+
inputSchema: ZodSchema<TInput>;
|
|
353
363
|
execute?: undefined;
|
|
354
364
|
} | {
|
|
355
365
|
description: string;
|
|
356
|
-
inputSchema:
|
|
366
|
+
inputSchema: ZodSchema<TInput>;
|
|
357
367
|
execute: (input: TInput) => Promise<TOutput>;
|
|
358
368
|
};
|
|
359
369
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lantos1618/better-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A minimal, type-safe AI-first UI framework for building tools",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"react-markdown": "^10.1.0",
|
|
82
82
|
"remark-gfm": "^4.0.1",
|
|
83
83
|
"shiki": "^4.0.2",
|
|
84
|
-
"zod": "^3.25.76"
|
|
84
|
+
"zod": "^3.25.76 || ^4.0.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"@ai-sdk/anthropic": "^3.0.0",
|