import { useContextSelector } from "use-context-selector";
import { ChatAnywhereSessionsContext, useChatAnywhereSessions } from "../Context/ChatAnywhereSessionsContext";
import { Button, IconButton } from "@agentscope-ai/design";
import { ChatAnywhereInputContext } from "../Context/ChatAnywhereInputContext";
import { useProviderContext } from "@agentscope-ai/chat";
import { useChatAnywhereOptions } from "../Context/ChatAnywhereOptionsContext";
import React, { useContext, useMemo } from "react";
import { SparkDeleteLine, SparkOperateLeftLine, SparkOperateRightLine, SparkPlusLine } from "@agentscope-ai/icons";
import { HistoryPanel } from '@agentscope-ai/chat';
import { ChatAnyWhereLayoutContext } from "../Context/ChatAnywhereLayoutContext";
import cls from 'classnames';
export default function Sessions() {
const { collapsed } = useContext(ChatAnyWhereLayoutContext);
const prefixCls = useProviderContext().getPrefixCls('chat-anywhere-sessions');
const leftHeader = useChatAnywhereOptions(v => v.theme?.leftHeader) || {};
return <>
{
React.isValidElement(leftHeader) ? leftHeader :
}
>;
}
export function InnerHeader({ className }: { className?: string }) {
const leftHeader = useChatAnywhereOptions(v => v.theme?.leftHeader) || {};
const prefixCls = useProviderContext().getPrefixCls('chat-anywhere-sessions');
const { toggleCollapsed, collapsed } = useContext(ChatAnyWhereLayoutContext);
const multiple = useChatAnywhereOptions(v => v.session.multiple);
const {
logo = 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
title = 'Runtime WebUI'
} = leftHeader as { logo?: string; title?: string };
return <>
{
logo &&

}
{title}
{
multiple &&
:
}
onClick={toggleCollapsed}
/>
}
>
}
export function InnerAdder(props: { style?: React.CSSProperties; narrowMode?: boolean }) {
const loading = useContextSelector(ChatAnywhereInputContext, v => v.loading);
const { createSession } = useChatAnywhereSessions();
const prefixCls = useProviderContext().getPrefixCls('chat-anywhere-sessions');
const { toggleCollapsed } = useContext(ChatAnyWhereLayoutContext);
return
} disabled={!!loading} onClick={async () => {
await createSession();
if (props.narrowMode) {
toggleCollapsed();
}
}}>
New Chat
}
export function InnerList(props: { style?: React.CSSProperties, narrowMode?: boolean }) {
const prefixCls = useProviderContext().getPrefixCls('chat-anywhere-sessions');
const sessions = useContextSelector(ChatAnywhereSessionsContext, v => v.sessions);
const { changeCurrentSessionId, removeSession } = useChatAnywhereSessions();
const currentSessionId = useContextSelector(ChatAnywhereSessionsContext, v => v.currentSessionId);
const { toggleCollapsed } = useContext(ChatAnyWhereLayoutContext);
const items = useMemo(() => sessions.map(session => ({
key: session.id,
label: session.name || 'New Chat',
})), [sessions]);
return
,
danger: true,
onClick: async (session) => await removeSession({ id: session.key }),
},
]}
activeKey={currentSessionId}
onActiveChange={(key) => {
changeCurrentSessionId(key);
if (props.narrowMode) {
toggleCollapsed();
}
}}
/>
;
}