@nexface/chat 0.1.20-alpha.1 → 0.1.21

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.
@@ -0,0 +1,5 @@
1
+ import type { UIMessagePart } from "./messages.js";
2
+ export declare function ToolConfirmationCards({ sessionId, parts, }: {
3
+ sessionId: string;
4
+ parts: readonly UIMessagePart[];
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useChat } from "./react.js";
4
+ import { confirmationControllers, confirmationRequest } from "./tool-confirmation.js";
5
+ import { Button } from "./ui/button.js";
6
+ import { cn } from "./ui/utils.js";
7
+ export function ToolConfirmationCards({ sessionId, parts, }) {
8
+ const chat = useChat();
9
+ const [error, setError] = useState();
10
+ const controller = confirmationControllers.get(chat.sendMessage);
11
+ return (_jsx(_Fragment, { children: parts.map((part) => {
12
+ const request = confirmationRequest(part);
13
+ if (!request || !controller)
14
+ return null;
15
+ const state = controller.state(sessionId, request);
16
+ const disabled = state !== "pending" || (chat.status !== "idle" && chat.status !== "error");
17
+ const respond = (approved) => {
18
+ setError(undefined);
19
+ void controller.respond(sessionId, request, approved).catch(() => {
20
+ if (controller.state(sessionId, request) === "pending")
21
+ setError({
22
+ toolCallId: request.toolCallId,
23
+ message: "Could not send your response. Please try again.",
24
+ });
25
+ });
26
+ };
27
+ return (_jsxs("section", { "aria-label": "\u64CD\u4F5C\u786E\u8BA4", className: cn("my-3 rounded-lg border p-4"), children: [_jsx("p", { className: cn("mb-3 whitespace-pre-wrap"), children: request.message }), state === "pending" || state === "sending" ? (_jsxs("div", { className: cn("flex gap-2"), children: [_jsx(Button, { disabled: disabled, onClick: () => respond(true), children: "\u786E\u8BA4" }), _jsx(Button, { variant: "outline", disabled: disabled, onClick: () => respond(false), children: "\u62D2\u7EDD" })] })) : (_jsx("p", { role: "status", children: state === "approved"
28
+ ? "已确认"
29
+ : state === "rejected"
30
+ ? "已拒绝"
31
+ : "此确认已失效,请重新发起操作。" })), error?.toolCallId === request.toolCallId ? _jsx("p", { role: "alert", children: error.message }) : null] }, request.toolCallId));
32
+ }) }));
33
+ }
@@ -0,0 +1,23 @@
1
+ import type { UIMessagePart } from "./messages.js";
2
+ export type ConfirmationRequest = {
3
+ toolCallId: string;
4
+ toolName: string;
5
+ requestId: string;
6
+ message: string;
7
+ };
8
+ export declare function parseConfirmationResult(content: string): {
9
+ requestId: string;
10
+ message: string;
11
+ } | undefined;
12
+ export declare function confirmationRequest(part: UIMessagePart): ConfirmationRequest | undefined;
13
+ export type ConfirmationState = "pending" | "sending" | "approved" | "rejected" | "expired";
14
+ export type ConfirmationSession = {
15
+ restored: Set<string>;
16
+ decisions: Map<string, ConfirmationState>;
17
+ };
18
+ type Controller = {
19
+ state(sessionId: string, request: ConfirmationRequest): ConfirmationState;
20
+ respond(sessionId: string, request: ConfirmationRequest, approved: boolean): Promise<void>;
21
+ };
22
+ export declare const confirmationControllers: WeakMap<(text: string, attachments?: import("./attachments.js").Attachment[], revisionOf?: string) => Promise<import("@nexface/agent").AgentRunResult>, Controller>;
23
+ export {};
@@ -0,0 +1,25 @@
1
+ export function parseConfirmationResult(content) {
2
+ try {
3
+ const parsed = JSON.parse(content);
4
+ const result = parsed?.result;
5
+ if (result?.status === "confirmation_required" &&
6
+ typeof result.requestId === "string" &&
7
+ result.requestId.trim() &&
8
+ typeof result.message === "string" &&
9
+ result.message.trim() &&
10
+ !parsed.error) {
11
+ return { requestId: result.requestId, message: result.message };
12
+ }
13
+ }
14
+ catch {
15
+ /* Other tool results are not confirmation requests. */
16
+ }
17
+ }
18
+ export function confirmationRequest(part) {
19
+ if (part.type !== "tool" || part.isError || !part.result)
20
+ return;
21
+ const result = parseConfirmationResult(part.result);
22
+ return result ? { ...result, toolCallId: part.toolCallId, toolName: part.name } : undefined;
23
+ }
24
+ // Internal bridge: the public useChat and Chat interfaces stay unchanged.
25
+ export const confirmationControllers = new WeakMap();
@@ -1,6 +1 @@
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;
@@ -14,34 +14,3 @@ 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, ReactNode } from "react";
2
+ import type { CSSProperties } from "react";
3
3
  import type { ChatDictation } from "./voice/types.js";
4
4
  export type ChatRunResult = Extract<AgentRunResult, {
5
5
  outcome: {
@@ -7,12 +7,10 @@ export type ChatRunResult = Extract<AgentRunResult, {
7
7
  };
8
8
  }>;
9
9
  export interface ChatSuggestion {
10
- readonly icon?: ReactNode;
11
10
  readonly label: string;
12
11
  readonly prompt: string;
13
12
  }
14
13
  export interface ChatProps {
15
- welcomeIcon?: ReactNode;
16
14
  dictation?: false | ChatDictation | undefined;
17
15
  open?: boolean;
18
16
  onOpenChange?: (open: boolean) => void;
@@ -1,6 +1,4 @@
1
- import type { ReactNode } from "react";
2
- export declare function Greeting({ title, description, icon, }: {
1
+ export declare function Greeting({ title, description, }: {
3
2
  title: string;
4
3
  description?: string | undefined;
5
- icon?: ReactNode;
6
4
  }): 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, 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] }));
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] }));
7
7
  }
@@ -1,6 +1,8 @@
1
- import type { ChatSuggestion } from "../../types.js";
2
1
  export declare function Suggestions({ suggestions, disabled, onSend, }: {
3
- suggestions: readonly ChatSuggestion[];
2
+ suggestions: readonly {
3
+ label: string;
4
+ prompt: string;
5
+ }[];
4
6
  disabled: boolean;
5
7
  onSend(prompt: string): void;
6
8
  }): 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, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { ThreadPrimitive, useAuiState } from "@assistant-ui/react";
5
5
  import { cn } from "../utils.js";
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";
6
+ const suggestionChipClass = "border-foreground/10 bg-background text-muted-foreground hover:border-foreground/25 hover:text-foreground rounded-control h-8 border px-3 text-[13px] transition-colors";
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) => (_jsxs(ThreadPrimitive.Suggestion, { prompt: suggestion.prompt, send: true, disabled: hidden, onClick: (event) => {
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) => (_jsx(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.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))) }));
17
+ }, className: cn(suggestionChipClass), children: suggestion.label }, suggestion.prompt))) }));
18
18
  }
@@ -5,7 +5,6 @@ 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";
9
8
  export const disclosureContentClass = "border-foreground/10 ms-[5px] border-s ps-4";
10
9
  export function DisclosureTrigger({ live, label, detail, }) {
11
10
  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] })) })] }));
@@ -38,5 +37,7 @@ export function ToolCall({ toolName, args, argsText, result, status, isError, sh
38
37
  ? "Rejected"
39
38
  : tool?.toolState === "not_started"
40
39
  ? "Not started"
41
- : toolResultPreview(result) })) : null] })] })] }));
40
+ : typeof result === "string"
41
+ ? result
42
+ : JSON.stringify(result, null, 2) })) : null] })] })] }));
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexface/chat",
3
- "version": "0.1.20-alpha.1",
3
+ "version": "0.1.21",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "sideEffects": [
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@ag-ui/core": "0.0.59",
22
- "@nexface/agent": "0.1.20-alpha.1",
22
+ "@nexface/agent": "0.1.21",
23
23
  "class-variance-authority": "0.7.1",
24
24
  "clsx": "2.1.1",
25
25
  "fast-json-patch": "3.1.1",
@@ -28,7 +28,7 @@
28
28
  "use-sync-external-store": "1.7.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@nexface/tools": "0.1.20-alpha.1",
31
+ "@nexface/tools": "0.1.21",
32
32
  "react": ">=17",
33
33
  "react-dom": ">=17"
34
34
  },
@@ -1,93 +0,0 @@
1
- Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
2
-
3
- This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
- This license is copied below, and is also available with a FAQ at:
5
- https://scripts.sil.org/OFL
6
-
7
-
8
- -----------------------------------------------------------
9
- SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
- -----------------------------------------------------------
11
-
12
- PREAMBLE
13
- The goals of the Open Font License (OFL) are to stimulate worldwide
14
- development of collaborative font projects, to support the font creation
15
- efforts of academic and linguistic communities, and to provide a free and
16
- open framework in which fonts may be shared and improved in partnership
17
- with others.
18
-
19
- The OFL allows the licensed fonts to be used, studied, modified and
20
- redistributed freely as long as they are not sold by themselves. The
21
- fonts, including any derivative works, can be bundled, embedded,
22
- redistributed and/or sold with any software provided that any reserved
23
- names are not used by derivative works. The fonts and derivatives,
24
- however, cannot be released under any other type of license. The
25
- requirement for fonts to remain under this license does not apply
26
- to any document created using the fonts or their derivatives.
27
-
28
- DEFINITIONS
29
- "Font Software" refers to the set of files released by the Copyright
30
- Holder(s) under this license and clearly marked as such. This may
31
- include source files, build scripts and documentation.
32
-
33
- "Reserved Font Name" refers to any names specified as such after the
34
- copyright statement(s).
35
-
36
- "Original Version" refers to the collection of Font Software components as
37
- distributed by the Copyright Holder(s).
38
-
39
- "Modified Version" refers to any derivative made by adding to, deleting,
40
- or substituting -- in part or in whole -- any of the components of the
41
- Original Version, by changing formats or by porting the Font Software to a
42
- new environment.
43
-
44
- "Author" refers to any designer, engineer, programmer, technical
45
- writer or other person who contributed to the Font Software.
46
-
47
- PERMISSION & CONDITIONS
48
- Permission is hereby granted, free of charge, to any person obtaining
49
- a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
- redistribute, and sell modified and unmodified copies of the Font
51
- Software, subject to the following conditions:
52
-
53
- 1) Neither the Font Software nor any of its individual components,
54
- in Original or Modified Versions, may be sold by itself.
55
-
56
- 2) Original or Modified Versions of the Font Software may be bundled,
57
- redistributed and/or sold with any software, provided that each copy
58
- contains the above copyright notice and this license. These can be
59
- included either as stand-alone text files, human-readable headers or
60
- in the appropriate machine-readable metadata fields within text or
61
- binary files as long as those fields can be easily viewed by the user.
62
-
63
- 3) No Modified Version of the Font Software may use the Reserved Font
64
- Name(s) unless explicit written permission is granted by the corresponding
65
- Copyright Holder. This restriction only applies to the primary font name as
66
- presented to the users.
67
-
68
- 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
- Software shall not be used to promote, endorse or advertise any
70
- Modified Version, except to acknowledge the contribution(s) of the
71
- Copyright Holder(s) and the Author(s) or with their explicit written
72
- permission.
73
-
74
- 5) The Font Software, modified or unmodified, in part or in whole,
75
- must be distributed entirely under this license, and must not be
76
- distributed under any other license. The requirement for fonts to
77
- remain under this license does not apply to any document created
78
- using the Font Software.
79
-
80
- TERMINATION
81
- This license becomes null and void if any of the above conditions are
82
- not met.
83
-
84
- DISCLAIMER
85
- THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
- OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
- COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
- INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
- DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
- FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
- OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
@@ -1,17 +0,0 @@
1
- import type { ToolRuntime } from "@nexface/tools";
2
- export interface ToolRenderContext<TInput = unknown, TResult = unknown> {
3
- input: TInput;
4
- status: "running" | "success" | "error" | "cancelled";
5
- result?: TResult;
6
- }
7
- export interface ToolPresentation {
8
- definition: ReturnType<ToolRuntime["getTools"]>[number]["definition"];
9
- confirmationProtocol?: true;
10
- render(context: ToolRenderContext): unknown;
11
- }
12
- export interface ToolPresentationController {
13
- get(name: string): ToolPresentation | undefined;
14
- subscribe(listener: () => void): () => void;
15
- }
16
- export declare const toolPresentationSymbol: unique symbol;
17
- export declare function getToolPresentationController(runtime: ToolRuntime): ToolPresentationController | undefined;
@@ -1,5 +0,0 @@
1
- // Generated from shared/tool-presentation.ts. Do not edit manually.
2
- export const toolPresentationSymbol = Symbol.for("@nexface/tools/tool-presentation");
3
- export function getToolPresentationController(runtime) {
4
- return runtime[toolPresentationSymbol];
5
- }
@@ -1,6 +0,0 @@
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;
@@ -1,132 +0,0 @@
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
- function confirmationInputText(argsText, toolName, toolCallId, messages) {
9
- try {
10
- const wire = JSON.parse(argsText);
11
- if (!wire || typeof wire !== "object" || Array.isArray(wire))
12
- return;
13
- if (Object.keys(wire).length !== 1)
14
- return;
15
- if (Object.hasOwn(wire, "input"))
16
- return JSON.stringify(wire.input);
17
- const answer = wire.confirmation;
18
- if (!answer || typeof answer.requestId !== "string" || typeof answer.approved !== "boolean")
19
- return;
20
- // Use the original receipt so settled calls also render after history recovery.
21
- for (const message of messages)
22
- for (const part of message.parts) {
23
- if (part.type !== "tool")
24
- continue;
25
- if (part.toolCallId === toolCallId)
26
- return;
27
- if (part.name !== toolName || part.result === undefined)
28
- continue;
29
- const { value, omitted } = decodeToolResult(part.result, toolName);
30
- if (!omitted &&
31
- value &&
32
- typeof value === "object" &&
33
- "status" in value &&
34
- value.status === "confirmation_required" &&
35
- "requestId" in value &&
36
- value.requestId === answer.requestId) {
37
- const original = JSON.parse(part.arguments);
38
- if (original && Object.hasOwn(original, "input"))
39
- return JSON.stringify(original.input);
40
- }
41
- }
42
- }
43
- catch {
44
- /* Invalid or unavailable business arguments use the default UI. */
45
- }
46
- return;
47
- }
48
- class RenderBoundary extends Component {
49
- state = { failed: false };
50
- static getDerivedStateFromError() {
51
- return { failed: true };
52
- }
53
- componentDidCatch(error) {
54
- this.props.report(error);
55
- }
56
- render() {
57
- return this.state.failed ? this.props.fallback : this.props.children;
58
- }
59
- }
60
- const ToolContent = memo(function ToolContent({ presentation, context, }) {
61
- return _jsx(_Fragment, { children: presentation.render(context) });
62
- });
63
- export function ToolPresentationUI({ presentation: tool, ...props }) {
64
- const registry = useToolPresentations();
65
- const chat = useChat();
66
- const presentation = registry?.controller?.get(props.toolName);
67
- const schema = presentation?.definition.inputSchema;
68
- const argsText = useMemo(() => presentation?.confirmationProtocol
69
- ? confirmationInputText(props.argsText, props.toolName, props.toolCallId, chat.messages)
70
- : props.argsText, [
71
- presentation?.confirmationProtocol,
72
- props.argsText,
73
- props.toolName,
74
- props.toolCallId,
75
- chat.messages,
76
- ]);
77
- const parsed = useMemo(() => {
78
- if (!schema || argsText === undefined)
79
- return;
80
- try {
81
- const input = JSON.parse(argsText);
82
- if (!validateAgentToolInput(schema, input).length)
83
- return { input };
84
- }
85
- catch {
86
- /* Incomplete or invalid arguments use the default UI. */
87
- }
88
- return;
89
- }, [schema, argsText]);
90
- const decoded = useMemo(() => typeof props.result === "string" ? decodeToolResult(props.result, props.toolName) : undefined, [props.result, props.toolName]);
91
- const confirmation = presentation?.confirmationProtocol && decoded?.value && typeof decoded.value === "object"
92
- ? decoded.value
93
- : undefined;
94
- const confirmationPending = confirmation?.status === "confirmation_required" &&
95
- typeof confirmation.requestId === "string" &&
96
- typeof confirmation.message === "string" &&
97
- typeof confirmation.nextAction === "string" &&
98
- Object.keys(confirmation).length === 4;
99
- const confirmationRejected = confirmation?.status === "rejected" &&
100
- confirmation.toolExecuted === false &&
101
- Object.keys(confirmation).every((key) => ["status", "requestId", "toolExecuted"].includes(key));
102
- const state = tool?.type === "tool" ? tool.toolState : undefined;
103
- const status = confirmationRejected ||
104
- state === "cancelled" ||
105
- state === "rejected" ||
106
- (props.result === undefined &&
107
- props.status.type === "incomplete" &&
108
- props.status.reason === "cancelled")
109
- ? "cancelled"
110
- : state || props.isError || (props.result === undefined && props.status.type === "incomplete")
111
- ? "error"
112
- : props.result === undefined
113
- ? "running"
114
- : "success";
115
- const context = useMemo(() => parsed
116
- ? {
117
- input: parsed.input,
118
- status,
119
- ...(status === "success" ? { result: decoded ? decoded.value : props.result } : {}),
120
- }
121
- : undefined, [parsed, status, decoded, props.result]);
122
- const fallback = _jsx(ToolCall, { ...props, presentation: tool });
123
- if (!presentation ||
124
- !context ||
125
- confirmationPending ||
126
- decoded?.omitted ||
127
- (chat.interrupt?.toolName === props.toolName &&
128
- tool?.type === "tool" &&
129
- tool.result === undefined))
130
- return fallback;
131
- 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));
132
- }