11// Bundlers replace this local declaration's guarded development check.
22declare const process: { env: { NODE_ENV?: string } };
3- import { createContext, memo, useContext } from 'octane';
3+ import { createContext, isChildrenBlock, memo, useContext } from 'octane';
44import type { ComponentProps, ComponentType, Context, OctaneNode } from 'octane';
55import {
66 automaticPartsForMessage,
@@ -469,9 +469,13 @@ function createChatUIImpl<
469469 const chat = useChatContext();
470470 const messages = readMessages(chat);
471471 const interrupts = readInterrupts(chat);
472- if (children) return <>
473- {children(messages)}
474- </>;
472+ if (children) {
473+ return <>
474+ {typeof children === 'function' && !isChildrenBlock(children)
475+ ? children(messages)
476+ : children}
477+ </>;
478+ }
475479 return <>
476480 {messages.map(
477481 (message) =>
@@ -523,9 +527,13 @@ function createChatUIImpl<
523527 interrupts,
524528 inlineToolNames: names,
525529 });
526- if (children) return <>
527- {children(selected.parts)}
528- </>;
530+ if (children) {
531+ return <>
532+ {typeof children === 'function' && !isChildrenBlock(children)
533+ ? children(selected.parts)
534+ : children}
535+ </>;
536+ }
529537 return <MessageRenderContext.Provider value={{ message, interrupts, inlineToolNames: names }}>
530538 <MessageComponent message={message} Parts={Parts} />
531539 </MessageRenderContext.Provider>;
@@ -629,7 +637,11 @@ function createChatUIImpl<
629637 }).parts[0];
630638 if (!selected) return null;
631639 return <PartContext.Provider value={selected}>
632- {children ? (children(mixPart(selected))) : <SelectedPartInner selected={selected} />}
640+ {children
641+ ? (typeof children === 'function' && !isChildrenBlock(children)
642+ ? children(mixPart(selected))
643+ : children)
644+ : <SelectedPartInner selected={selected} />}
633645 </PartContext.Provider>;
634646 }
635647
@@ -646,9 +658,13 @@ function createChatUIImpl<
646658 interrupts: readInterrupts(chat),
647659 inlineToolNames,
648660 });
649- if (children) return <>
650- {children(selected.interrupts)}
651- </>;
661+ if (children) {
662+ return <>
663+ {typeof children === 'function' && !isChildrenBlock(children)
664+ ? children(selected.interrupts)
665+ : children}
666+ </>;
667+ }
652668 return <>
653669 {selected.interrupts.map(
654670 (interrupt) => <Interrupt key={interrupt.id} interrupt={interrupt} />,
@@ -686,7 +702,11 @@ function createChatUIImpl<
686702 children?: (mixed: ChatUIInterrupt & InterruptMixins<TOptions>) => OctaneNode;
687703 }) {
688704 return <InterruptContext.Provider value={interrupt}>
689- {children ? (children(mixInterrupt(interrupt))) : <InterruptInner interrupt={interrupt} />}
705+ {children
706+ ? (typeof children === 'function' && !isChildrenBlock(children)
707+ ? children(mixInterrupt(interrupt))
708+ : children)
709+ : <InterruptInner interrupt={interrupt} />}
690710 </InterruptContext.Provider>;
691711 },
692712 );
0 commit comments