@nexface/chat 0.1.21-alpha.5 → 0.1.21-alpha.7

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/dist/BUNDLED_DEPENDENCIES.json +12 -0
  2. package/dist/BUNDLED_LICENSES.txt +50 -0
  3. package/dist/assistant-components.d.ts +1 -2
  4. package/dist/assistant-components.js +6 -8
  5. package/dist/assistant-runtime.d.ts +1 -4
  6. package/dist/assistant-runtime.js +5 -19
  7. package/dist/client.js +12 -24
  8. package/dist/default-chat.d.ts +1 -1
  9. package/dist/default-chat.js +7864 -1553
  10. package/dist/messages.d.ts +0 -3
  11. package/dist/protocol-messages.d.ts +2 -3
  12. package/dist/protocol-messages.js +27 -145
  13. package/dist/protocol-response.js +2 -2
  14. package/dist/react.d.ts +1 -11
  15. package/dist/react.js +100 -515
  16. package/dist/storage.d.ts +6 -3
  17. package/dist/storage.js +44 -50
  18. package/dist/styles.css +676 -1503
  19. package/dist/tool-result.d.ts +0 -5
  20. package/dist/tool-result.js +0 -31
  21. package/dist/types.d.ts +1 -3
  22. package/dist/ui/home-demo/action-bar.js +2 -13
  23. package/dist/ui/home-demo/greeting.d.ts +1 -3
  24. package/dist/ui/home-demo/greeting.js +2 -2
  25. package/dist/ui/home-demo/suggestions.d.ts +4 -2
  26. package/dist/ui/home-demo/suggestions.js +4 -5
  27. package/dist/ui/home-demo/trace.js +3 -2
  28. package/dist/ui/markdown-text.d.ts +1 -6
  29. package/dist/ui/markdown-text.js +2 -39
  30. package/dist/ui/thread-list.aui.d.ts +1 -2
  31. package/dist/ui/thread-list.aui.js +2 -6
  32. package/package.json +3 -4
  33. package/dist/fonts/Inter-OFL.txt +0 -93
  34. package/dist/fonts/inter-medium.ttf +0 -0
  35. package/dist/session-coordinator.d.ts +0 -23
  36. package/dist/session-coordinator.js +0 -139
  37. package/dist/session-history.d.ts +0 -29
  38. package/dist/session-history.js +0 -282
  39. package/dist/shared/text-only-reply.d.ts +0 -6
  40. package/dist/shared/text-only-reply.js +0 -10
  41. package/dist/shared/tool-presentation.d.ts +0 -18
  42. package/dist/shared/tool-presentation.js +0 -5
  43. package/dist/shared/tool-result-markdown.d.ts +0 -15
  44. package/dist/shared/tool-result-markdown.js +0 -55
  45. package/dist/shared/tool-result-reference.d.ts +0 -2
  46. package/dist/shared/tool-result-reference.js +0 -5
  47. package/dist/tool-presentation.d.ts +0 -6
  48. package/dist/tool-presentation.js +0 -113
@@ -571,6 +571,12 @@
571
571
  "license": "MIT",
572
572
  "purl": "pkg:npm/mdast-util-find-and-replace@3.0.2"
573
573
  },
574
+ {
575
+ "name": "mdast-util-from-markdown",
576
+ "version": "2.0.3",
577
+ "license": "MIT",
578
+ "purl": "pkg:npm/mdast-util-from-markdown@2.0.3"
579
+ },
574
580
  {
575
581
  "name": "mdast-util-gfm",
576
582
  "version": "3.1.0",
@@ -631,6 +637,12 @@
631
637
  "license": "MIT",
632
638
  "purl": "pkg:npm/mdast-util-to-string@4.0.0"
633
639
  },
640
+ {
641
+ "name": "micromark",
642
+ "version": "4.0.2",
643
+ "license": "MIT",
644
+ "purl": "pkg:npm/micromark@4.0.2"
645
+ },
634
646
  {
635
647
  "name": "micromark-core-commonmark",
636
648
  "version": "2.0.3",
@@ -2398,6 +2398,31 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2398
2398
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2399
2399
 
2400
2400
 
2401
+ mdast-util-from-markdown@2.0.3 (MIT)
2402
+ (The MIT License)
2403
+
2404
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
2405
+
2406
+ Permission is hereby granted, free of charge, to any person obtaining
2407
+ a copy of this software and associated documentation files (the
2408
+ 'Software'), to deal in the Software without restriction, including
2409
+ without limitation the rights to use, copy, modify, merge, publish,
2410
+ distribute, sublicense, and/or sell copies of the Software, and to
2411
+ permit persons to whom the Software is furnished to do so, subject to
2412
+ the following conditions:
2413
+
2414
+ The above copyright notice and this permission notice shall be
2415
+ included in all copies or substantial portions of the Software.
2416
+
2417
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
2418
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2419
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2420
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2421
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2422
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2423
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
+
2425
+
2401
2426
  mdast-util-gfm-autolink-literal@2.0.1 (MIT)
2402
2427
  (The MIT License)
2403
2428
 
@@ -3274,6 +3299,31 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
3274
3299
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3275
3300
 
3276
3301
 
3302
+ micromark@4.0.2 (MIT)
3303
+ (The MIT License)
3304
+
3305
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
3306
+
3307
+ Permission is hereby granted, free of charge, to any person obtaining
3308
+ a copy of this software and associated documentation files (the
3309
+ 'Software'), to deal in the Software without restriction, including
3310
+ without limitation the rights to use, copy, modify, merge, publish,
3311
+ distribute, sublicense, and/or sell copies of the Software, and to
3312
+ permit persons to whom the Software is furnished to do so, subject to
3313
+ the following conditions:
3314
+
3315
+ The above copyright notice and this permission notice shall be
3316
+ included in all copies or substantial portions of the Software.
3317
+
3318
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
3319
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3320
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
3321
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
3322
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
3323
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
3324
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3325
+
3326
+
3277
3327
  nanoid@6.0.1 (MIT)
3278
3328
  The MIT License (MIT)
3279
3329
 
@@ -15,8 +15,7 @@ export declare function AssistantComposer({ binding, options, placeholder, sugge
15
15
  recoveryUnavailable: boolean;
16
16
  cancel(): void;
17
17
  }): import("react").JSX.Element;
18
- export declare function AssistantParts({ showDetails, tools, toolReplyIndex, }: {
18
+ export declare function AssistantParts({ showDetails, tools, }: {
19
19
  showDetails: boolean;
20
20
  tools?: readonly UIMessagePart[];
21
- toolReplyIndex?: number | undefined;
22
21
  }): import("react").JSX.Element;
@@ -11,7 +11,7 @@ import { TooltipIconButton } from "./ui/tooltip-icon-button.js";
11
11
  import { Button } from "./ui/button.js";
12
12
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip.js";
13
13
  import { ToolGroupRoot, ToolGroupContent } from "./ui/tool-group.aui.js";
14
- import { ToolCall, DisclosureTrigger, disclosureContentClass } from "./ui/home-demo/trace.js";
14
+ import { DisclosureTrigger, ToolCall, disclosureContentClass } from "./ui/home-demo/trace.js";
15
15
  import { Reasoning, ReasoningRoot, ReasoningContent, ReasoningText } from "./ui/reasoning.aui.js";
16
16
  import { TraceLine } from "./ui/home-demo/trace-line.js";
17
17
  import { attachmentAccept } from "./attachments.js";
@@ -109,13 +109,13 @@ const groupAssistantParts = groupPartByType({
109
109
  "tool-call": ["group-chainOfThought", "group-tool"],
110
110
  "standalone-tool-call": [],
111
111
  });
112
- export function AssistantParts({ showDetails, tools = [], toolReplyIndex, }) {
112
+ export function AssistantParts({ showDetails, tools = [], }) {
113
113
  return (_jsx(_Fragment, { children: _jsx(GroupedParts, { groupBy: groupAssistantParts, children: ({ part, children }) => {
114
114
  switch (part.type) {
115
115
  case "group-chainOfThought":
116
116
  return _jsx("div", { className: cn("mb-3"), children: children });
117
117
  case "group-tool":
118
- return part.indices.length === 1 ? (children) : (_jsx(ToolGroup, { tools: tools.filter((_, index) => part.indices.includes(index)), running: part.status.type === "running", count: part.indices.length, children: children }));
118
+ return part.indices.length === 1 ? (_jsx(_Fragment, { children: children })) : (_jsx(ToolGroup, { tools: tools.filter((_, index) => part.indices.includes(index)), running: part.status.type === "running", count: part.indices.length, children: children }));
119
119
  case "group-reasoning":
120
120
  return (_jsxs(ReasoningRoot, { variant: "ghost", streaming: part.status.type === "running", className: cn("my-1"), children: [_jsx(DisclosureTrigger, { live: part.status.type === "running", label: part.status.type === "running" ? "thinking" : "reasoning" }), _jsx(ReasoningContent, { "aria-busy": part.status.type === "running", className: cn(disclosureContentClass), children: _jsx(ReasoningText, { className: cn("ps-0"), children: children }) })] }));
121
121
  case "reasoning":
@@ -126,11 +126,9 @@ export function AssistantParts({ showDetails, tools = [], toolReplyIndex, }) {
126
126
  case "data":
127
127
  return part.dataRendererUI;
128
128
  case "text":
129
- return part.text === "" && part.status?.type === "running" ? (_jsx(TraceLine, { live: true, label: "thinking" })) : (_jsx(MarkdownText, { assistant: true, replyIndex: toolReplyIndex, replyParts: tools }));
130
- case "tool-call": {
131
- const presentation = tools.find((tool) => tool.type === "tool" && tool.toolCallId === part.toolCallId);
132
- return (_jsxs(_Fragment, { children: [_jsx(ToolCall, { ...part, showDetails: showDetails, presentation: presentation }), part.toolUI] }));
133
- }
129
+ return part.text === "" && part.status?.type === "running" ? (_jsx(TraceLine, { live: true, label: "thinking" })) : (_jsx(MarkdownText, {}));
130
+ case "tool-call":
131
+ return (part.toolUI ?? (_jsx(ToolCall, { ...part, showDetails: showDetails, presentation: tools.find((tool) => tool.type === "tool" && tool.toolCallId === part.toolCallId) })));
134
132
  case "indicator":
135
133
  return _jsx(TraceLine, { live: true, label: "thinking" });
136
134
  default:
@@ -3,7 +3,6 @@ import { type AssistantRuntime, type ThreadMessageLike } from "@assistant-ui/rea
3
3
  import { AssistantAttachments } from "./assistant-attachments.js";
4
4
  import { type useChat, type UIMessage } from "./react.js";
5
5
  import type { ChatProps } from "./types.js";
6
- import type { PresentedMessage } from "./messages.js";
7
6
  import { type VoiceComposerState } from "./voice/use-voice.js";
8
7
  type ChatState = ReturnType<typeof useChat>;
9
8
  export type AssistantBinding = {
@@ -16,9 +15,7 @@ export type AssistantBinding = {
16
15
  send(): Promise<void>;
17
16
  };
18
17
  export declare function convertMessage(message: UIMessage): ThreadMessageLike;
19
- export declare function projectMessages(messages: readonly PresentedMessage[]): (UIMessage & {
20
- toolReplyIndex?: number;
21
- })[];
18
+ export declare function projectMessages(messages: readonly UIMessage[]): UIMessage[];
22
19
  export declare function SessionRuntime({ id, chat, options, dictation, open, blocked, active, onEdit, children, }: {
23
20
  id: string;
24
21
  chat: ChatState;
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useReducer, useRef, useState } from "react";
3
3
  import { AssistantRuntimeProvider, MessageNotSentError, useExternalStoreRuntime, } from "@assistant-ui/react";
4
4
  import { AssistantAttachments, toAssistantAttachment } from "./assistant-attachments.js";
5
- import { assertChatSendable, sessionCommandResult } from "./react.js";
5
+ import { assertChatSendable } from "./react.js";
6
6
  import { useVoiceInput } from "./voice/use-voice.js";
7
7
  function parseToolArgs(text) {
8
8
  try {
@@ -52,20 +52,16 @@ export function projectMessages(messages) {
52
52
  const projected = [];
53
53
  for (const message of messages) {
54
54
  const previous = projected.at(-1);
55
- const replyIndex = message.finalToolReply
56
- ? message.parts.findIndex(({ type }) => type === "text")
57
- : -1;
58
55
  if (message.role === "assistant" && previous?.role === "assistant") {
59
56
  projected[projected.length - 1] = {
60
57
  ...previous,
61
58
  parts: [...previous.parts, ...message.parts],
62
- ...(replyIndex >= 0 ? { toolReplyIndex: previous.parts.length + replyIndex } : {}),
63
59
  ...(message.state ? { state: message.state } : {}),
64
60
  ...(message.error ? { error: message.error } : {}),
65
61
  };
66
62
  }
67
63
  else
68
- projected.push(replyIndex >= 0 ? { ...message, toolReplyIndex: replyIndex } : message);
64
+ projected.push(message);
69
65
  }
70
66
  return projected;
71
67
  }
@@ -159,20 +155,10 @@ export function SessionRuntime({ id, chat, options, dictation, open = true, bloc
159
155
  })),
160
156
  onSwitchToNewThread: () => {
161
157
  latest.current.createSession();
162
- return sessionCommandResult(latest.current);
163
- },
164
- onSwitchToThread: (next) => {
165
- latest.current.switchSession(next);
166
- return sessionCommandResult(latest.current);
167
- },
168
- onRename: (target, title) => {
169
- latest.current.renameSession(target, title);
170
- return sessionCommandResult(latest.current);
171
- },
172
- onDelete: (target) => {
173
- latest.current.deleteSession(target);
174
- return sessionCommandResult(latest.current);
175
158
  },
159
+ onSwitchToThread: (next) => latest.current.switchSession(next),
160
+ onRename: (target, title) => latest.current.renameSession(target, title),
161
+ onDelete: (target) => latest.current.deleteSession(target),
176
162
  },
177
163
  },
178
164
  });
package/dist/client.js CHANGED
@@ -1,6 +1,3 @@
1
- import { getToolPresentationController } from "./shared/tool-presentation.js";
2
- import { stripToolResultBlocks } from "./shared/tool-result-markdown.js";
3
- import { requestsTextOnlyReply } from "./shared/text-only-reply.js";
4
1
  import { decodeToolProxy } from "./shared/tool-proxy.js";
5
2
  import { pageDecisionSymbol } from "./shared/runtime-execution.js";
6
3
  import { createAgent, } from "@nexface/agent";
@@ -10,7 +7,7 @@ import { getRuntimeController } from "./shared/runtime-controller.js";
10
7
  import { validateAgentToolInput } from "./shared/schema.js";
11
8
  import { EventType, EventSchemas, RunAgentInputSchema, TextInputContentSchema, ImageInputContentSchema, } from "@ag-ui/core";
12
9
  import { conversationFromMessages } from "./storage.js";
13
- import { completeToolReply, createMessageUpdater, restoreMessages, settleApproval, projectMessages, } from "./protocol-messages.js";
10
+ import { createMessageUpdater, restoreMessages, settleApproval, projectMessages, } from "./protocol-messages.js";
14
11
  import { resolveModelConfig } from "./config.js";
15
12
  import { markErrorPresented, reportError, runError, toolError, } from "./errors.js";
16
13
  const controllerSymbol = Symbol.for("@nexface/agent/chat-controller");
@@ -422,13 +419,8 @@ class ChatClientImplementation {
422
419
  if (this.#cancelled)
423
420
  controller.abort(abortError());
424
421
  controller.signal.throwIfAborted();
425
- const output = stripToolResultBlocks(result.output);
426
- if (requestsTextOnlyReply(content) && result.output.trim() && !output.trim()) {
427
- throw new ClientError("INVALID_MODEL_RESPONSE", "The text-only reply contains no text.");
428
- }
429
- this.#messages = completeToolReply(this.#messages);
430
422
  succeeded = true;
431
- return output === result.output ? result : { ...result, output };
423
+ return result;
432
424
  }
433
425
  catch (failure) {
434
426
  unsubscribe();
@@ -696,9 +688,6 @@ class ChatClientImplementation {
696
688
  const contexts = await this.runtime.getContexts({ signal });
697
689
  const runId = id();
698
690
  this.#runId = runId;
699
- const toolMetadata = new Map(catalog.map(({ definition: { name, effect } }) => [name, effect ? { effect } : {}]));
700
- for (const name of getToolPresentationController(this.runtime)?.names() ?? [])
701
- toolMetadata.set(name, { ...toolMetadata.get(name), hasRenderer: true });
702
691
  const input = {
703
692
  threadId: this.id,
704
693
  runId,
@@ -717,7 +706,10 @@ class ChatClientImplementation {
717
706
  forwardedProps: {
718
707
  nexface: {
719
708
  version: 3,
720
- toolMetadata: Object.fromEntries(toolMetadata),
709
+ toolMetadata: Object.fromEntries(catalog.map(({ definition }) => [
710
+ definition.name,
711
+ { ...(definition.effect ? { effect: definition.effect } : {}) },
712
+ ])),
721
713
  },
722
714
  },
723
715
  };
@@ -883,15 +875,13 @@ class ChatClientImplementation {
883
875
  }
884
876
  }
885
877
  catch (error) {
886
- const executionOutcomeUnknown = (inFlight && !serverCannotWrite) ||
878
+ const unknown = (inFlight && (!signal.aborted || !serverCannotWrite)) ||
887
879
  completedBrowserCall ||
888
880
  this.#executingBrowserCall !== undefined;
889
- const recoveryStateUnknown = executionOutcomeUnknown || (inFlight && !signal.aborted);
890
- if ((this.#appendOnly && (recoveryStateUnknown || this.#cancelled)) ||
891
- (error instanceof ClientError && error.code === "CHAT_RECOVERY_UNAVAILABLE")) {
881
+ if (this.#appendOnly ? unknown || this.#cancelled : unknown && !signal.aborted) {
892
882
  this.#recoveryUnavailable = true;
893
883
  }
894
- else if (recoveryStateUnknown) {
884
+ else if (unknown) {
895
885
  this.#cancelledInterrupt = undefined;
896
886
  }
897
887
  else if (interruptId) {
@@ -925,14 +915,12 @@ class ChatClientImplementation {
925
915
  });
926
916
  }
927
917
  }
928
- if (executionOutcomeUnknown && !this.#recoveryUnavailable) {
918
+ if (signal.aborted && unknown && !this.#appendOnly) {
929
919
  this.#messages.push({
930
920
  id: id(),
931
921
  role: "assistant",
932
- content: signal.aborted
933
- ? "The previous run was stopped and its execution outcome is unknown. Check the result before repeating any action."
934
- : "Check the previous action results before repeating any action.",
935
- metadata: { nexface: { state: signal.aborted ? "cancelled" : "error" } },
922
+ content: "The previous run was stopped and its execution outcome is unknown. Check the result before repeating any action.",
923
+ metadata: { nexface: { state: "cancelled" } },
936
924
  });
937
925
  }
938
926
  throw error;
@@ -1,3 +1,3 @@
1
1
  import { type ReactElement } from "react";
2
2
  import type { ChatProps } from "./types.js";
3
- export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, welcomeIcon, open, onOpenChange, placeholder, layout, side, className, style, suggestions, suggestNextMessage, attachments, dictation, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult, }: ChatProps): ReactElement | null;
3
+ export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, open, onOpenChange, placeholder, layout, side, className, style, suggestions, suggestNextMessage, attachments, dictation, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult, }: ChatProps): ReactElement | null;