@nexface/chat 0.1.18 → 0.1.20-alpha.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/assistant-components.js +8 -3
- package/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +547 -330
- package/dist/fonts/Inter-OFL.txt +93 -0
- package/dist/fonts/inter-medium.ttf +0 -0
- package/dist/protocol-messages.js +1 -6
- package/dist/react.d.ts +5 -0
- package/dist/react.js +26 -6
- package/dist/shared/tool-presentation.d.ts +16 -0
- package/dist/shared/tool-presentation.js +5 -0
- package/dist/styles.css +1481 -676
- package/dist/tool-presentation.d.ts +6 -0
- package/dist/tool-presentation.js +70 -0
- package/dist/tool-result.d.ts +5 -0
- package/dist/tool-result.js +31 -0
- package/dist/types.d.ts +3 -1
- package/dist/ui/home-demo/composer.js +1 -1
- package/dist/ui/home-demo/greeting.d.ts +3 -1
- package/dist/ui/home-demo/greeting.js +2 -2
- package/dist/ui/home-demo/suggestions.d.ts +2 -4
- package/dist/ui/home-demo/suggestions.js +4 -4
- package/dist/ui/home-demo/trace.js +2 -3
- package/package.json +4 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolCallMessagePartProps } from "@assistant-ui/react";
|
|
2
|
+
import type { UIMessagePart } from "./messages.js";
|
|
3
|
+
export declare function ToolPresentationUI({ presentation: tool, ...props }: ToolCallMessagePartProps & {
|
|
4
|
+
showDetails: boolean;
|
|
5
|
+
presentation?: UIMessagePart | undefined;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Component, memo, useMemo } from "react";
|
|
3
|
+
import { validateAgentToolInput } from "./shared/schema.js";
|
|
4
|
+
import { decodeToolResult } from "./tool-result.js";
|
|
5
|
+
import { useChat, useToolPresentations } from "./react.js";
|
|
6
|
+
import { ToolCall } from "./ui/home-demo/trace.js";
|
|
7
|
+
import { cn } from "./ui/utils.js";
|
|
8
|
+
class RenderBoundary extends Component {
|
|
9
|
+
state = { failed: false };
|
|
10
|
+
static getDerivedStateFromError() {
|
|
11
|
+
return { failed: true };
|
|
12
|
+
}
|
|
13
|
+
componentDidCatch(error) {
|
|
14
|
+
this.props.report(error);
|
|
15
|
+
}
|
|
16
|
+
render() {
|
|
17
|
+
return this.state.failed ? this.props.fallback : this.props.children;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const ToolContent = memo(function ToolContent({ presentation, context, }) {
|
|
21
|
+
return _jsx(_Fragment, { children: presentation.render(context) });
|
|
22
|
+
});
|
|
23
|
+
export function ToolPresentationUI({ presentation: tool, ...props }) {
|
|
24
|
+
const registry = useToolPresentations();
|
|
25
|
+
const chat = useChat();
|
|
26
|
+
const presentation = registry?.controller?.get(props.toolName);
|
|
27
|
+
const schema = presentation?.definition.inputSchema;
|
|
28
|
+
const parsed = useMemo(() => {
|
|
29
|
+
if (!schema)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const input = JSON.parse(props.argsText);
|
|
33
|
+
if (!validateAgentToolInput(schema, input).length)
|
|
34
|
+
return { input };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* Incomplete or invalid arguments use the default UI. */
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}, [schema, props.argsText]);
|
|
41
|
+
const decoded = useMemo(() => typeof props.result === "string" ? decodeToolResult(props.result, props.toolName) : undefined, [props.result, props.toolName]);
|
|
42
|
+
const state = tool?.type === "tool" ? tool.toolState : undefined;
|
|
43
|
+
const status = state === "cancelled" ||
|
|
44
|
+
state === "rejected" ||
|
|
45
|
+
(props.result === undefined &&
|
|
46
|
+
props.status.type === "incomplete" &&
|
|
47
|
+
props.status.reason === "cancelled")
|
|
48
|
+
? "cancelled"
|
|
49
|
+
: state || props.isError || (props.result === undefined && props.status.type === "incomplete")
|
|
50
|
+
? "error"
|
|
51
|
+
: props.result === undefined
|
|
52
|
+
? "running"
|
|
53
|
+
: "success";
|
|
54
|
+
const context = useMemo(() => parsed
|
|
55
|
+
? {
|
|
56
|
+
input: parsed.input,
|
|
57
|
+
status,
|
|
58
|
+
...(status === "success" ? { result: decoded ? decoded.value : props.result } : {}),
|
|
59
|
+
}
|
|
60
|
+
: undefined, [parsed, status, decoded, props.result]);
|
|
61
|
+
const fallback = _jsx(ToolCall, { ...props, presentation: tool });
|
|
62
|
+
if (!presentation ||
|
|
63
|
+
!context ||
|
|
64
|
+
decoded?.omitted ||
|
|
65
|
+
(chat.interrupt?.toolName === props.toolName &&
|
|
66
|
+
tool?.type === "tool" &&
|
|
67
|
+
tool.result === undefined))
|
|
68
|
+
return fallback;
|
|
69
|
+
return (_jsxs(RenderBoundary, { fallback: fallback, report: (error) => registry?.report(error, chat.activeSessionId, props.toolCallId), children: [_jsx("div", { className: cn("my-2 min-w-0 max-w-full"), "data-slot": "nexface-tool-content", children: _jsx(ToolContent, { presentation: presentation, context: context }) }), props.showDetails ? fallback : null] }, props.toolCallId));
|
|
70
|
+
}
|
package/dist/tool-result.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare function getToolResultError(content: string): string | undefined;
|
|
2
|
+
export declare function decodeToolResult(content: string, toolName?: string): {
|
|
3
|
+
value: unknown;
|
|
4
|
+
omitted: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function toolResultPreview(result: unknown): string;
|
package/dist/tool-result.js
CHANGED
|
@@ -14,3 +14,34 @@ export function getToolResultError(content) {
|
|
|
14
14
|
}
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
|
+
export function decodeToolResult(content, toolName) {
|
|
18
|
+
try {
|
|
19
|
+
const payload = JSON.parse(content);
|
|
20
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
21
|
+
const record = payload;
|
|
22
|
+
if (record.contentOmitted === true &&
|
|
23
|
+
typeof record.preview === "string" &&
|
|
24
|
+
Object.keys(record).length === 2)
|
|
25
|
+
return { value: record.preview, omitted: true };
|
|
26
|
+
if (Object.hasOwn(record, "result") &&
|
|
27
|
+
(Object.keys(record).length === 1 ||
|
|
28
|
+
(toolName !== undefined &&
|
|
29
|
+
record.toolName === toolName &&
|
|
30
|
+
Object.keys(record).length === 2)))
|
|
31
|
+
return { value: record.result, omitted: false };
|
|
32
|
+
}
|
|
33
|
+
return { value: payload, omitted: false };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return { value: content, omitted: false };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function toolResultPreview(result) {
|
|
40
|
+
const decoded = typeof result === "string" ? decodeToolResult(result) : undefined;
|
|
41
|
+
const text = decoded?.omitted
|
|
42
|
+
? String(decoded.value)
|
|
43
|
+
: typeof result === "string"
|
|
44
|
+
? result
|
|
45
|
+
: (JSON.stringify(result, null, 2) ?? "");
|
|
46
|
+
return text.length > 4000 || decoded?.omitted ? `${text.slice(0, 4000)}…` : text;
|
|
47
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentRunResult } from "@nexface/agent";
|
|
2
|
-
import type { CSSProperties } from "react";
|
|
2
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
3
3
|
import type { ChatDictation } from "./voice/types.js";
|
|
4
4
|
export type ChatRunResult = Extract<AgentRunResult, {
|
|
5
5
|
outcome: {
|
|
@@ -7,10 +7,12 @@ export type ChatRunResult = Extract<AgentRunResult, {
|
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
9
|
export interface ChatSuggestion {
|
|
10
|
+
readonly icon?: ReactNode;
|
|
10
11
|
readonly label: string;
|
|
11
12
|
readonly prompt: string;
|
|
12
13
|
}
|
|
13
14
|
export interface ChatProps {
|
|
15
|
+
welcomeIcon?: ReactNode;
|
|
14
16
|
dictation?: false | ChatDictation | undefined;
|
|
15
17
|
open?: boolean;
|
|
16
18
|
onOpenChange?: (open: boolean) => void;
|
|
@@ -11,5 +11,5 @@ export function Composer({ children, inputProps, actions, ...props }) {
|
|
|
11
11
|
}, children: _jsxs("div", { "data-slot": "aui_composer-shell", className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 data-[dragging=true]:border-foreground/40 rounded-thread flex flex-col border transition-colors data-[dragging=true]:border-dashed"), children: [_jsx("div", { className: cn("has-[.aui-attachment-root]:px-3 has-[.aui-attachment-root]:pt-3"), children: children }), _jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { "data-composer-input": true, rows: 1, className: cn("placeholder:text-muted-foreground field-sizing-content block max-h-48 w-full resize-none bg-transparent px-4 pt-3 pb-2 text-base leading-6 focus:outline-none") }) }), _jsx("div", { className: cn("flex items-center justify-between gap-2 px-2 pb-2"), children: actions })] }) }) }));
|
|
12
12
|
}
|
|
13
13
|
export function EditComposer({ children, inputProps, cancelProps, sendProps, ...props }) {
|
|
14
|
-
return (_jsx(MessagePrimitive.Root, { "data-role": "user", "data-slot": "aui_edit-composer-wrapper", className: cn("mx-auto flex w-full max-w-(--nxf-thread-max-width) flex-col items-end"), children: _jsxs(ComposerPrimitive.Root, { className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 rounded-thread flex w-full max-w-[85%] flex-col border transition-colors"), ...props, children: [_jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { autoFocus: true, rows: 1, className: cn("field-sizing-content max-h-48 min-h-12 w-full resize-none bg-transparent px-4 pt-3.5 pb-1 text-[15px] leading-6 focus:outline-none") }) }), children, _jsxs("div", { className: cn("flex items-center justify-end gap-1.5 px-2.5 pb-2.5"), children: [_jsx(ComposerPrimitive.Cancel, { asChild: true, children: _jsx("button", { type: "button", ...cancelProps, className: cn("text-muted-foreground hover:text-foreground rounded-control h-8 px-3 text-[13px] transition-colors"), children: "\u53D6\u6D88" }) }), _jsx(ComposerPrimitive.Send, { asChild: true, children: _jsx("button", { type: "button", ...sendProps, className: cn("bg-primary text-primary-foreground rounded-control h-8 px-3 text-[13px] font-medium transition-opacity disabled:opacity-40"), children: "\
|
|
14
|
+
return (_jsx(MessagePrimitive.Root, { "data-role": "user", "data-slot": "aui_edit-composer-wrapper", className: cn("mx-auto flex w-full max-w-(--nxf-thread-max-width) flex-col items-end"), children: _jsxs(ComposerPrimitive.Root, { className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 rounded-thread flex w-full max-w-[85%] flex-col border transition-colors"), ...props, children: [_jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { autoFocus: true, rows: 1, className: cn("field-sizing-content max-h-48 min-h-12 w-full resize-none bg-transparent px-4 pt-3.5 pb-1 text-[15px] leading-6 focus:outline-none") }) }), children, _jsxs("div", { className: cn("flex items-center justify-end gap-1.5 px-2.5 pb-2.5"), children: [_jsx(ComposerPrimitive.Cancel, { asChild: true, children: _jsx("button", { type: "button", ...cancelProps, className: cn("text-muted-foreground hover:text-foreground rounded-control h-8 px-3 text-[13px] transition-colors"), children: "\u53D6\u6D88" }) }), _jsx(ComposerPrimitive.Send, { asChild: true, children: _jsx("button", { type: "button", ...sendProps, className: cn("bg-primary text-primary-foreground rounded-control h-8 px-3 text-[13px] font-medium transition-opacity disabled:opacity-40"), children: "\u53D1\u9001" }) })] })] }) }));
|
|
15
15
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export declare function Greeting({ title, description, icon, }: {
|
|
2
3
|
title: string;
|
|
3
4
|
description?: string | undefined;
|
|
5
|
+
icon?: ReactNode;
|
|
4
6
|
}): import("react").JSX.Element;
|
|
@@ -2,6 +2,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// Adapted from the pinned official homepage Demo; see vendor/assistant-ui/home-demo/ADAPTATIONS.md.
|
|
3
3
|
import { cn } from "../utils.js";
|
|
4
4
|
import { typeSection, typeDeck } from "./type.js";
|
|
5
|
-
export function Greeting({ title, description, }) {
|
|
6
|
-
return (_jsxs("div", { className: cn("animate-in fade-in slide-in-from-bottom-1 mx-auto mb-8 flex w-full max-w-(--nxf-thread-max-width) flex-col items-center text-center duration-200"), children: [_jsx("p", { className: cn(typeSection), children: title }), description ? _jsx("p", { className: cn(typeDeck), children: description }) : null] }));
|
|
5
|
+
export function Greeting({ title, description, icon, }) {
|
|
6
|
+
return (_jsxs("div", { className: cn("animate-in fade-in slide-in-from-bottom-1 mx-auto mb-8 flex w-full max-w-(--nxf-thread-max-width) flex-col items-center text-center duration-200"), children: [icon != null ? (_jsx("div", { className: cn("mb-4 flex max-w-full justify-center [&_img]:max-w-full"), children: icon })) : null, _jsx("p", { className: cn(typeSection), children: title }), description ? _jsx("p", { className: cn(typeDeck), children: description }) : null] }));
|
|
7
7
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import type { ChatSuggestion } from "../../types.js";
|
|
1
2
|
export declare function Suggestions({ suggestions, disabled, onSend, }: {
|
|
2
|
-
suggestions: readonly
|
|
3
|
-
label: string;
|
|
4
|
-
prompt: string;
|
|
5
|
-
}[];
|
|
3
|
+
suggestions: readonly ChatSuggestion[];
|
|
6
4
|
disabled: boolean;
|
|
7
5
|
onSend(prompt: string): void;
|
|
8
6
|
}): import("react").JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Adapted from the pinned official homepage Demo; see vendor/assistant-ui/home-demo/ADAPTATIONS.md.
|
|
2
2
|
"use client";
|
|
3
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { ThreadPrimitive, useAuiState } from "@assistant-ui/react";
|
|
5
5
|
import { cn } from "../utils.js";
|
|
6
|
-
const suggestionChipClass = "
|
|
6
|
+
const suggestionChipClass = "bg-background text-suggestion hover:text-foreground font-suggestion inset-ring inset-ring-foreground/8 hover:inset-ring-foreground/25 rounded-xl inline-flex min-h-[46px] min-w-0 max-w-full items-center gap-2 px-4 py-3 text-sm font-medium leading-[1.57143] transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring";
|
|
7
7
|
export function Suggestions({ suggestions, disabled, onSend, }) {
|
|
8
8
|
const isComposerEmpty = useAuiState((s) => s.composer.isEmpty);
|
|
9
9
|
const hidden = !isComposerEmpty || disabled;
|
|
@@ -11,8 +11,8 @@ export function Suggestions({ suggestions, disabled, onSend, }) {
|
|
|
11
11
|
// Typing hides the suggestions without unmounting them: the empty view is
|
|
12
12
|
// centred, so collapsing a block this tall moves the composer out from
|
|
13
13
|
// under the cursor. Disabled buttons also stay out of the tab order in React 18.
|
|
14
|
-
_jsx("div", { "aria-hidden": hidden, className: cn("animate-in fade-in mx-auto flex max-w-[34rem] flex-wrap items-center justify-center gap-2 transition-opacity duration-200 motion-reduce:animate-none", hidden && "opacity-0"), children: suggestions.map((suggestion) => (
|
|
14
|
+
_jsx("div", { "aria-hidden": hidden, className: cn("animate-in fade-in mx-auto flex max-w-[34rem] flex-wrap items-center justify-center gap-2 transition-opacity duration-200 motion-reduce:animate-none", hidden && "opacity-0"), children: suggestions.map((suggestion) => (_jsxs(ThreadPrimitive.Suggestion, { prompt: suggestion.prompt, send: true, disabled: hidden, onClick: (event) => {
|
|
15
15
|
event.preventDefault();
|
|
16
16
|
onSend(suggestion.prompt);
|
|
17
|
-
}, className: cn(suggestionChipClass), children: suggestion.label }, suggestion.prompt))) }));
|
|
17
|
+
}, className: cn(suggestionChipClass), children: [suggestion.icon != null ? (_jsx("span", { "aria-hidden": "true", className: cn("inline-flex size-4 shrink-0 items-center justify-center [&>svg]:size-4 [&>img]:size-4"), children: suggestion.icon })) : null, _jsx("span", { className: cn("min-w-0 wrap-anywhere"), children: suggestion.label })] }, suggestion.prompt))) }));
|
|
18
18
|
}
|
|
@@ -5,6 +5,7 @@ import { Collapsible, CollapsibleContent } from "../collapsible.js";
|
|
|
5
5
|
import { ShimmerLabel } from "./surfaces.js";
|
|
6
6
|
import { CollapsibleTrigger } from "../collapsible.js";
|
|
7
7
|
import { TraceLine, TraceMarker, useToolDuration, formatDuration } from "./trace-line.js";
|
|
8
|
+
import { toolResultPreview } from "../../tool-result.js";
|
|
8
9
|
export const disclosureContentClass = "border-foreground/10 ms-[5px] border-s ps-4";
|
|
9
10
|
export function DisclosureTrigger({ live, label, detail, }) {
|
|
10
11
|
return (_jsxs(CollapsibleTrigger, { "data-slot": "tool-group-trigger", className: cn("group/trigger my-1 flex max-w-full items-baseline gap-2 text-left font-mono text-[12px] outline-none [font-variant-ligatures:none] focus-visible:underline"), children: [_jsx(TraceMarker, { live: live, className: cn("group-data-[state=open]/trigger:rotate-90") }), _jsx("span", { className: cn("text-muted-foreground group-hover/trigger:text-foreground min-w-0 truncate transition-colors"), children: live ? (_jsxs(ShimmerLabel, { children: [label, detail ? ` ${detail}` : null] })) : (_jsxs(_Fragment, { children: [label, detail ? ` ${detail}` : null] })) })] }));
|
|
@@ -37,7 +38,5 @@ export function ToolCall({ toolName, args, argsText, result, status, isError, sh
|
|
|
37
38
|
? "Rejected"
|
|
38
39
|
: tool?.toolState === "not_started"
|
|
39
40
|
? "Not started"
|
|
40
|
-
:
|
|
41
|
-
? result
|
|
42
|
-
: JSON.stringify(result, null, 2) })) : null] })] })] }));
|
|
41
|
+
: toolResultPreview(result) })) : null] })] })] }));
|
|
43
42
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexface/chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
5
6
|
"sideEffects": [
|
|
6
7
|
"./dist/index.js",
|
|
7
8
|
"**/*.css"
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"@ag-ui/core": "0.0.59",
|
|
21
|
-
"@nexface/agent": "0.1.
|
|
22
|
+
"@nexface/agent": "0.1.20-alpha.0",
|
|
22
23
|
"class-variance-authority": "0.7.1",
|
|
23
24
|
"clsx": "2.1.1",
|
|
24
25
|
"fast-json-patch": "3.1.1",
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"use-sync-external-store": "1.7.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@nexface/tools": "0.1.
|
|
31
|
+
"@nexface/tools": "0.1.20-alpha.0",
|
|
31
32
|
"react": ">=17",
|
|
32
33
|
"react-dom": ">=17"
|
|
33
34
|
},
|