reifyui 0.14.0 → 0.15.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/index.d.ts CHANGED
@@ -15,6 +15,9 @@ export interface ResponseHandlers {
15
15
  onCreated?(responseId: string): void;
16
16
  /** The server-side session id, for continuing this conversation on the next turn. */
17
17
  onSession?(sessionId: string): void;
18
+ /** Every event whole, as it arrives (streamTurn passes it; ChatPanel's agent view folds it into
19
+ * the turn's clock). */
20
+ onEvent?(event: { type: string; [k: string]: unknown }): void;
18
21
  onReasoningDelta?(text: string): void;
19
22
  onTextDelta?(text: string): void;
20
23
  onToolCall?(name: string, args: string, callId: string): void;
@@ -300,6 +303,14 @@ export interface ChatPanelProps {
300
303
  toolLabels?: Record<string, string>;
301
304
  /** The panel's placement in YOUR layout. Everything it paints inside is the package's. */
302
305
  classNames?: { root?: string };
306
+ /** 'agent' draws each turn with reifyui/agent-chat's AgentTurnView (needs styles/agent-chat.css). */
307
+ view?: 'messages' | 'agent';
308
+ /** The agent view's live-line mark: the harness's logo, as a node. */
309
+ mark?: ReactNode;
310
+ /** The mark's motion (reifyui/agent-chat motionFor(base)). */
311
+ motion?: string;
312
+ /** Overrides for the agent view's words (reifyui/agent-chat DEFAULT_AGENT_LABELS). */
313
+ agentLabels?: Record<string, unknown>;
303
314
  }
304
315
  export const ChatPanel: ComponentType<ChatPanelProps>;
305
316
 
package/dist/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ import {
2
+ AgentTurnView,
3
+ newTurn,
4
+ reduceTurn,
5
+ turnFromMessage
6
+ } from "./chunk-6CJPYMR2.js";
1
7
  import {
2
8
  createResponsesDispatcher,
3
9
  pumpResponsesStream,
@@ -723,6 +729,21 @@ var PANEL_STATUS_LABELS = {
723
729
  cancelled: "Stopped",
724
730
  incomplete: "The turn hit its limit. Send a follow up to continue."
725
731
  };
732
+ function pairTurns(messages) {
733
+ const out = [];
734
+ let user = null;
735
+ for (const m of messages) {
736
+ if (m.role === "user") {
737
+ if (user) out.push({ user, asst: null });
738
+ user = m;
739
+ } else {
740
+ out.push({ user, asst: m });
741
+ user = null;
742
+ }
743
+ }
744
+ if (user) out.push({ user, asst: null });
745
+ return out;
746
+ }
726
747
  function ChatPanel(props) {
727
748
  const {
728
749
  sessionId,
@@ -750,8 +771,17 @@ function ChatPanel(props) {
750
771
  renderMarkdown,
751
772
  userExtras,
752
773
  toolLabels,
753
- classNames = {}
774
+ classNames = {},
775
+ // view="agent" draws each turn with reifyui/agent-chat's AgentTurnView (the live line with the
776
+ // harness's mark, work folded per run of calls, every call openable) instead of ChatMessages.
777
+ // Needs styles/agent-chat.css too. `mark` (a node: the harness's logo) and `motion` (see
778
+ // motionFor) dress the live line; `agentLabels` overrides its words.
779
+ view = "messages",
780
+ mark,
781
+ motion,
782
+ agentLabels
754
783
  } = props;
784
+ const agentView = view === "agent";
755
785
  const [messages, setMessages] = useState3([]);
756
786
  const [draft, setDraft] = useState3("");
757
787
  const [busy, setBusy] = useState3(false);
@@ -797,13 +827,14 @@ function ChatPanel(props) {
797
827
  }, [messages, connecting, histLoading]);
798
828
  const deliver = useCallback(async (text, files = []) => {
799
829
  setBusy(true);
800
- setMessages((m) => [...m, { role: "assistant", blocks: [], status: "running" }]);
830
+ setMessages((m) => [...m, { role: "assistant", blocks: [], status: "running", clock: newTurn({ startedAt: Date.now() }) }]);
801
831
  try {
802
832
  const out = await api.current.runTurn({
803
833
  sessionId,
804
834
  text,
805
835
  attachments: files,
806
836
  handlers: {
837
+ onEvent: (ev) => updateLastAsst((a) => ({ ...a, clock: reduceTurn(a.clock || newTurn(), ev, Date.now()) })),
807
838
  onSession: (sid) => {
808
839
  if (sid && sid !== sessionId) adoptedRef.current = sid;
809
840
  api.current.onSessionStarted?.(sid);
@@ -1036,7 +1067,18 @@ function ChatPanel(props) {
1036
1067
  dropped ? /* @__PURE__ */ jsx5("span", { className: "uic-chat-conn", children: workingLabel }) : null
1037
1068
  ] }),
1038
1069
  /* @__PURE__ */ jsxs5("div", { className: "uic-chat-body", ref: bodyRef, onScroll: onBodyScroll, role: "log", "aria-live": "polite", children: [
1039
- histLoading ? /* @__PURE__ */ jsx5(ChatMessagesSkeleton, {}) : empty && externalBusy ? busyState === void 0 ? defaultBusyState : busyState : empty ? emptyState : /* @__PURE__ */ jsx5(
1070
+ histLoading ? /* @__PURE__ */ jsx5(ChatMessagesSkeleton, {}) : empty && externalBusy ? busyState === void 0 ? defaultBusyState : busyState : empty ? emptyState : agentView ? /* @__PURE__ */ jsx5("div", { className: "uic-chat-turns", children: pairTurns(messages).map(({ user, asst }, i) => /* @__PURE__ */ jsx5(
1071
+ AgentTurnView,
1072
+ {
1073
+ mark,
1074
+ motion,
1075
+ labels: agentLabels,
1076
+ renderMarkdown,
1077
+ turn: asst ? turnFromMessage(asst, asst.clock || null, user ? { text: user.text, files: (user.files || []).map((n) => ({ name: n })) } : null) : turnFromMessage({ status: "done", blocks: [] }, null, user ? { text: user.text, files: (user.files || []).map((n) => ({ name: n })) } : null),
1078
+ userExtra: user ? userExtras?.(user, i) : void 0
1079
+ },
1080
+ i
1081
+ )) }) : /* @__PURE__ */ jsx5(
1040
1082
  ChatMessages,
1041
1083
  {
1042
1084
  messages,