@chat-lab/ui 0.1.0-beta.50 → 0.1.0-beta.52
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/components/Chatkit/index.cjs +42 -18
- package/dist/components/Chatkit/index.cjs.map +1 -1
- package/dist/components/Chatkit/index.d.ts.map +1 -1
- package/dist/components/Chatkit/index.js +42 -18
- package/dist/components/Chatkit/index.js.map +1 -1
- package/dist/components/Chatkit/types.d.ts +1 -0
- package/dist/components/Chatkit/types.d.ts.map +1 -1
- package/dist/hooks/useADKChat.cjs.map +1 -1
- package/dist/hooks/useADKChat.d.ts.map +1 -1
- package/dist/hooks/useADKChat.js.map +1 -1
- package/dist/hooks/useDebugChat.cjs +49 -0
- package/dist/hooks/useDebugChat.cjs.map +1 -0
- package/dist/hooks/useDebugChat.d.ts +18 -0
- package/dist/hooks/useDebugChat.d.ts.map +1 -0
- package/dist/hooks/useDebugChat.js +47 -0
- package/dist/hooks/useDebugChat.js.map +1 -0
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.cjs +27 -0
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.cjs.map +1 -1
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.d.ts +4 -0
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.d.ts.map +1 -1
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.js +27 -0
- package/dist/hooks/useSkillAgent/SkillAgentPlugin.js.map +1 -1
- package/dist/hooks/useSkillAgent/index.cjs +25 -12
- package/dist/hooks/useSkillAgent/index.cjs.map +1 -1
- package/dist/hooks/useSkillAgent/index.d.ts +5 -1
- package/dist/hooks/useSkillAgent/index.d.ts.map +1 -1
- package/dist/hooks/useSkillAgent/index.js +25 -12
- package/dist/hooks/useSkillAgent/index.js.map +1 -1
- package/dist/hooks/useThread.d.ts +24 -0
- package/dist/hooks/useThread.d.ts.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/packages/core/dist/index.cjs +7 -6
- package/dist/packages/core/dist/index.cjs.map +1 -1
- package/dist/packages/core/dist/index.js +7 -6
- package/dist/packages/core/dist/index.js.map +1 -1
- package/dist/utils/convertToAssistantMessage.cjs +0 -1
- package/dist/utils/convertToAssistantMessage.cjs.map +1 -1
- package/dist/utils/convertToAssistantMessage.d.ts.map +1 -1
- package/dist/utils/convertToAssistantMessage.js +0 -1
- package/dist/utils/convertToAssistantMessage.js.map +1 -1
- package/package.json +1 -1
|
@@ -24,7 +24,7 @@ var react = require('../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2
|
|
|
24
24
|
|
|
25
25
|
const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
26
26
|
const { t } = I18nContext.useI18n();
|
|
27
|
-
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList: threadList$1, showHeader = true, renderHeader, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, threadBottom, } = props;
|
|
27
|
+
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList: threadList$1, showHeader = true, renderHeader, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, uploadeBase64 = true, threadBottom, accept, } = props;
|
|
28
28
|
const controller = props.controller;
|
|
29
29
|
const { threadMap, currentThreadId } = react.useSnapshot(controller.store.state);
|
|
30
30
|
// useImperativeHandleChatkitRef(ref, controller, onError);
|
|
@@ -39,18 +39,21 @@ const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
|
39
39
|
isDisabled: !!currentThread?.metadata['isInitingSession'],
|
|
40
40
|
convertMessage: message => message,
|
|
41
41
|
onNew: async (message) => {
|
|
42
|
-
const attachments =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
const attachments = uploadeBase64
|
|
43
|
+
? await Promise.all(message.attachments?.map(async (item) => {
|
|
44
|
+
return {
|
|
45
|
+
...item,
|
|
46
|
+
base64: await convertToBase64.convertToBase64(item.file),
|
|
47
|
+
};
|
|
48
|
+
}) || [])
|
|
49
|
+
: message.attachments || [];
|
|
48
50
|
controller?.sendMessage({
|
|
49
51
|
attaches: attachments.map(item => ({
|
|
50
52
|
id: item.id,
|
|
51
53
|
attachId: item.id,
|
|
52
|
-
url: item
|
|
54
|
+
url: item?.base64 || '',
|
|
53
55
|
status: 'success',
|
|
56
|
+
file: item.file,
|
|
54
57
|
type: checkMedia(item.contentType),
|
|
55
58
|
mimeType: item.contentType,
|
|
56
59
|
})),
|
|
@@ -85,24 +88,45 @@ const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
|
85
88
|
console.log(id);
|
|
86
89
|
},
|
|
87
90
|
send: async ({ id, file }) => {
|
|
91
|
+
// Map media type to valid content type
|
|
92
|
+
const baseMediaType = checkMedia(file.type);
|
|
93
|
+
const mediaType = [
|
|
94
|
+
'image',
|
|
95
|
+
'video',
|
|
96
|
+
'audio',
|
|
97
|
+
].includes(baseMediaType)
|
|
98
|
+
? baseMediaType
|
|
99
|
+
: 'file';
|
|
100
|
+
const contentItem = {
|
|
101
|
+
type: mediaType,
|
|
102
|
+
};
|
|
103
|
+
switch (mediaType) {
|
|
104
|
+
case 'image':
|
|
105
|
+
contentItem.image = file.name;
|
|
106
|
+
break;
|
|
107
|
+
case 'video':
|
|
108
|
+
contentItem.video = file.name;
|
|
109
|
+
break;
|
|
110
|
+
case 'audio':
|
|
111
|
+
contentItem.audio = file.name;
|
|
112
|
+
break;
|
|
113
|
+
case 'file':
|
|
114
|
+
contentItem.file = file.name;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
88
117
|
return {
|
|
89
118
|
id,
|
|
90
|
-
type:
|
|
119
|
+
type: mediaType,
|
|
91
120
|
name: file.name,
|
|
92
121
|
contentType: file.type,
|
|
93
|
-
content: [
|
|
94
|
-
{
|
|
95
|
-
type: 'image',
|
|
96
|
-
image: file.name,
|
|
97
|
-
},
|
|
98
|
-
],
|
|
122
|
+
content: [contentItem],
|
|
99
123
|
status: {
|
|
100
124
|
type: 'complete',
|
|
101
125
|
},
|
|
102
126
|
file,
|
|
103
127
|
};
|
|
104
128
|
},
|
|
105
|
-
accept: 'image/*',
|
|
129
|
+
accept: accept || 'image/*',
|
|
106
130
|
add: async ({ file }) => {
|
|
107
131
|
return {
|
|
108
132
|
file,
|
|
@@ -141,13 +165,13 @@ const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
|
141
165
|
})) : (jsxRuntime.jsx(threadList, {}))), jsxRuntime.jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxRuntime.jsxs(reactResizablePanels.Group, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { children: jsxRuntime.jsx(thread.Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '30%', children: jsxRuntime.jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) })), threadBottom] }) })] }), (tools || []).map((tool, index) => React.createElement(tool)), jsxRuntime.jsx(executionCard, {})] }) }, currentThreadId));
|
|
142
166
|
});
|
|
143
167
|
const Chatkit = (props) => {
|
|
144
|
-
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, tools, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup, expandToolDetail, debugger: debuggerProps, locale, } = props;
|
|
168
|
+
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, tools, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup, expandToolDetail, debugger: debuggerProps, locale, accept, } = props;
|
|
145
169
|
const controllerRef = React.useRef(chatControllerFromProps);
|
|
146
170
|
const controller = controllerRef.current;
|
|
147
171
|
const { currentThreadId, threadMap } = react.useSnapshot(controller.store.state);
|
|
148
172
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
149
173
|
const messages = React.useMemo(() => threadMap[currentThread?.id || '']?.messages || [], [currentThread?.id, threadMap]);
|
|
150
|
-
return (jsxRuntime.jsx(I18nContext.I18nProvider, { defaultLocale: locale, children: jsxRuntime.jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxRuntime.jsxs(reactResizablePanels.Group, { style: { height: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { minSize: 750, maxSize: 900, children: jsxRuntime.jsx(ChatkitImpl, { tools: tools || [], showHeader: showHeader, renderHeader: renderHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, toolDisplay: toolDisplay, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller }, currentThreadId) }), debuggerProps && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '25%', className: "border-l", children: jsxRuntime.jsx(index$1, { region: debuggerProps.region, controller: controller, thread: currentThread, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }) }));
|
|
174
|
+
return (jsxRuntime.jsx(I18nContext.I18nProvider, { defaultLocale: locale, children: jsxRuntime.jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxRuntime.jsxs(reactResizablePanels.Group, { style: { height: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { minSize: 750, maxSize: 900, children: jsxRuntime.jsx(ChatkitImpl, { tools: tools || [], showHeader: showHeader, renderHeader: renderHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, toolDisplay: toolDisplay, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller, accept: accept }, currentThreadId) }), debuggerProps && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '25%', className: "border-l", children: jsxRuntime.jsx(index$1, { region: debuggerProps.region, controller: controller, thread: currentThread, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }) }));
|
|
151
175
|
};
|
|
152
176
|
var index = React.forwardRef(Chatkit);
|
|
153
177
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\nimport { I18nProvider, useI18n } from '@/contexts/I18nContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n tool,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nimport {\n BashTool,\n skillAgentToolSet,\n} from '../assistant-ui-tools/skill-agent-tool-set';\nimport React from 'react';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ElementType[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n threadBottom?: React.ReactNode;\n showHeader?: boolean;\n renderHeader?: (props: { thread: ThreadType }) => React.ReactNode;\n\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const { t } = useI18n();\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n threadBottom,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [] || [],\n [currentThread?.id, threadMap],\n );\n\n const { uiMessages, authors } = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n );\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: item.base64,\n status: 'success',\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error(t('thread.notFound')));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n return {\n id,\n type: 'image',\n name: file.name,\n contentType: file.type,\n content: [\n {\n type: 'image',\n image: file.name,\n },\n ],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || t('thread.prompt'),\n showHeader,\n renderHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n authors,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: values(threadMap) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n {threadBottom}\n </Group>\n </div>\n </div>\n {(tools || []).map((tool, index) => React.createElement(tool))}\n <ExecutionCard />\n </ChatkitProvider>\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (props: ChatkitProps) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n tools,\n chatController: chatControllerFromProps = null,\n threadBottom,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n debugger: debuggerProps,\n locale,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [],\n [currentThread?.id, threadMap],\n );\n\n return (\n <I18nProvider defaultLocale={locale}>\n <div\n className={'chatkit-wrapper'}\n style={{ height: '100%' }}\n data-chatkit\n >\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={tools || []}\n showHeader={showHeader}\n renderHeader={renderHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n toolDisplay={toolDisplay}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n threadBottom={threadBottom}\n controller={controller!}\n />\n </Panel>\n {debuggerProps && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={debuggerProps.region}\n controller={controller!}\n thread={currentThread}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n </I18nProvider>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["forwardRef","useI18n","threadList","useSnapshot","useMemo","useExternalStoreRuntime","convertToBase64","uuid","useTraceStore","useEffect","_jsx","AssistantRuntimeProvider","_jsxs","ChatkitProvider","ThreadList","Group","Panel","Thread","Exec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EACvB,MAAM,EAAE,aAAa,EACrB,QAAQ,GACL,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAU,GAE9D,EACI,CAAA,CACT,IACK,EACJ,CAAA,EAAA,CACO,EACf;AACJ,CAAC,CAAC;AAEF,YAAerB,gBAAU,CAAC,OAAO,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\nimport { I18nProvider, useI18n } from '@/contexts/I18nContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n tool,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nimport {\n BashTool,\n skillAgentToolSet,\n} from '../assistant-ui-tools/skill-agent-tool-set';\nimport React from 'react';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ElementType[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n threadBottom?: React.ReactNode;\n showHeader?: boolean;\n renderHeader?: (props: { thread: ThreadType }) => React.ReactNode;\n\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n accept?: string;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const { t } = useI18n();\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n uploadeBase64 = true,\n threadBottom,\n accept,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [] || [],\n [currentThread?.id, threadMap],\n );\n\n const { uiMessages, authors } = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = uploadeBase64\n ? await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n )\n : message.attachments || [];\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: (item as { base64?: string })?.base64 || '',\n status: 'success',\n file: item.file,\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error(t('thread.notFound')));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n // Map media type to valid content type\n const baseMediaType = checkMedia(file.type) as\n | 'image'\n | 'video'\n | 'audio';\n const mediaType: 'image' | 'video' | 'audio' | 'file' = [\n 'image',\n 'video',\n 'audio',\n ].includes(baseMediaType)\n ? baseMediaType\n : 'file';\n\n const contentItem: {\n type: typeof mediaType;\n image?: string;\n video?: string;\n audio?: string;\n file?: string;\n } = {\n type: mediaType,\n };\n\n switch (mediaType) {\n case 'image':\n contentItem.image = file.name;\n break;\n case 'video':\n contentItem.video = file.name;\n break;\n case 'audio':\n contentItem.audio = file.name;\n break;\n case 'file':\n contentItem.file = file.name;\n break;\n }\n\n return {\n id,\n type: mediaType,\n name: file.name,\n contentType: file.type,\n content: [contentItem],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: accept || 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || t('thread.prompt'),\n showHeader,\n renderHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n authors,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: values(threadMap) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n {threadBottom}\n </Group>\n </div>\n </div>\n {(tools || []).map((tool, index) => React.createElement(tool))}\n <ExecutionCard />\n </ChatkitProvider>\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (props: ChatkitProps) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n tools,\n chatController: chatControllerFromProps = null,\n threadBottom,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n debugger: debuggerProps,\n locale,\n accept,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [],\n [currentThread?.id, threadMap],\n );\n\n return (\n <I18nProvider defaultLocale={locale}>\n <div\n className={'chatkit-wrapper'}\n style={{ height: '100%' }}\n data-chatkit\n >\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={tools || []}\n showHeader={showHeader}\n renderHeader={renderHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n toolDisplay={toolDisplay}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n threadBottom={threadBottom}\n controller={controller!}\n accept={accept}\n />\n </Panel>\n {debuggerProps && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={debuggerProps.region}\n controller={controller!}\n thread={currentThread}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n </I18nProvider>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["forwardRef","useI18n","threadList","useSnapshot","useMemo","useExternalStoreRuntime","convertToBase64","uuid","useTraceStore","useEffect","_jsx","AssistantRuntimeProvider","_jsxs","ChatkitProvider","ThreadList","Group","Panel","Thread","ExecutionCard","useRef","I18nProvider","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,WAAW,GAAGA,gBAAU,CAC5B,CACE,KAqBC,EACD,GAA6B,KAC3B;AACF,IAAA,MAAM,EAAE,CAAC,EAAE,GAAGC,mBAAO,EAAE,CAAC;IACxB,MAAM,EACJ,aAAa,EACb,KAAK,EACL,WAAW,GAAG,OAAO,EACrB,OAAO,EACP,UAAU,EACV,OAAO,cACPC,YAAU,EACV,UAAU,GAAG,IAAI,EACjB,YAAY,EACZ,WAAW,EACX,eAAe,GAAG,KAAK,EACvB,eAAe,GAAG,KAAK,EACvB,gBAAgB,GAAG,KAAK,EACxB,aAAa,GAAG,IAAI,EACpB,YAAY,EACZ,MAAM,GACP,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AACpC,IAAA,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAGC,iBAAW,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAG3E,IAAA,MAAM,aAAa,GAAG,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;AAC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cAAC,CAAAW,OAAK,EACJ,EAAA,MAAM,EAAE,aAAa,CAAC,MAAM,EAC5B,UAAU,EAAE,UAAW,EACvB,MAAM,EAAE,aAAa,EACrB,QAAQ,GACL,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAU,GAE9D,EACI,CAAA,CACT,IACK,EACJ,CAAA,EAAA,CACO,EACf;AACJ,CAAC,CAAC;AAEF,YAAerB,gBAAU,CAAC,OAAO,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Chatkit/index.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAqBnD,OAAO,cAAc,CAAC;AAQtB,OAAO,KAAK,MAAM,OAAO,CAAC;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Chatkit/index.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAqBnD,OAAO,cAAc,CAAC;AAQtB,OAAO,KAAK,MAAM,OAAO,CAAC;;AA4U1B,wBAAmC"}
|
|
@@ -22,7 +22,7 @@ import { useSnapshot } from '../../node_modules/.pnpm/valtio@2.1.8_patch_hash_bo
|
|
|
22
22
|
|
|
23
23
|
const ChatkitImpl = forwardRef((props, ref) => {
|
|
24
24
|
const { t } = useI18n();
|
|
25
|
-
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, threadBottom, } = props;
|
|
25
|
+
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, uploadeBase64 = true, threadBottom, accept, } = props;
|
|
26
26
|
const controller = props.controller;
|
|
27
27
|
const { threadMap, currentThreadId } = useSnapshot(controller.store.state);
|
|
28
28
|
// useImperativeHandleChatkitRef(ref, controller, onError);
|
|
@@ -37,18 +37,21 @@ const ChatkitImpl = forwardRef((props, ref) => {
|
|
|
37
37
|
isDisabled: !!currentThread?.metadata['isInitingSession'],
|
|
38
38
|
convertMessage: message => message,
|
|
39
39
|
onNew: async (message) => {
|
|
40
|
-
const attachments =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const attachments = uploadeBase64
|
|
41
|
+
? await Promise.all(message.attachments?.map(async (item) => {
|
|
42
|
+
return {
|
|
43
|
+
...item,
|
|
44
|
+
base64: await convertToBase64(item.file),
|
|
45
|
+
};
|
|
46
|
+
}) || [])
|
|
47
|
+
: message.attachments || [];
|
|
46
48
|
controller?.sendMessage({
|
|
47
49
|
attaches: attachments.map(item => ({
|
|
48
50
|
id: item.id,
|
|
49
51
|
attachId: item.id,
|
|
50
|
-
url: item
|
|
52
|
+
url: item?.base64 || '',
|
|
51
53
|
status: 'success',
|
|
54
|
+
file: item.file,
|
|
52
55
|
type: checkMedia(item.contentType),
|
|
53
56
|
mimeType: item.contentType,
|
|
54
57
|
})),
|
|
@@ -83,24 +86,45 @@ const ChatkitImpl = forwardRef((props, ref) => {
|
|
|
83
86
|
console.log(id);
|
|
84
87
|
},
|
|
85
88
|
send: async ({ id, file }) => {
|
|
89
|
+
// Map media type to valid content type
|
|
90
|
+
const baseMediaType = checkMedia(file.type);
|
|
91
|
+
const mediaType = [
|
|
92
|
+
'image',
|
|
93
|
+
'video',
|
|
94
|
+
'audio',
|
|
95
|
+
].includes(baseMediaType)
|
|
96
|
+
? baseMediaType
|
|
97
|
+
: 'file';
|
|
98
|
+
const contentItem = {
|
|
99
|
+
type: mediaType,
|
|
100
|
+
};
|
|
101
|
+
switch (mediaType) {
|
|
102
|
+
case 'image':
|
|
103
|
+
contentItem.image = file.name;
|
|
104
|
+
break;
|
|
105
|
+
case 'video':
|
|
106
|
+
contentItem.video = file.name;
|
|
107
|
+
break;
|
|
108
|
+
case 'audio':
|
|
109
|
+
contentItem.audio = file.name;
|
|
110
|
+
break;
|
|
111
|
+
case 'file':
|
|
112
|
+
contentItem.file = file.name;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
86
115
|
return {
|
|
87
116
|
id,
|
|
88
|
-
type:
|
|
117
|
+
type: mediaType,
|
|
89
118
|
name: file.name,
|
|
90
119
|
contentType: file.type,
|
|
91
|
-
content: [
|
|
92
|
-
{
|
|
93
|
-
type: 'image',
|
|
94
|
-
image: file.name,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
120
|
+
content: [contentItem],
|
|
97
121
|
status: {
|
|
98
122
|
type: 'complete',
|
|
99
123
|
},
|
|
100
124
|
file,
|
|
101
125
|
};
|
|
102
126
|
},
|
|
103
|
-
accept: 'image/*',
|
|
127
|
+
accept: accept || 'image/*',
|
|
104
128
|
add: async ({ file }) => {
|
|
105
129
|
return {
|
|
106
130
|
file,
|
|
@@ -139,13 +163,13 @@ const ChatkitImpl = forwardRef((props, ref) => {
|
|
|
139
163
|
})) : (jsx(ThreadList, {}))), jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxs(Tt, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsx($t, { children: jsx(Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsx($t, { defaultSize: '30%', children: jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) })), threadBottom] }) })] }), (tools || []).map((tool, index) => React__default.createElement(tool)), jsx(ExecutionCard, {})] }) }, currentThreadId));
|
|
140
164
|
});
|
|
141
165
|
const Chatkit = (props) => {
|
|
142
|
-
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, tools, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup, expandToolDetail, debugger: debuggerProps, locale, } = props;
|
|
166
|
+
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, tools, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, renderHeader, placeholder, expandToolGroup, expandToolDetail, debugger: debuggerProps, locale, accept, } = props;
|
|
143
167
|
const controllerRef = useRef(chatControllerFromProps);
|
|
144
168
|
const controller = controllerRef.current;
|
|
145
169
|
const { currentThreadId, threadMap } = useSnapshot(controller.store.state);
|
|
146
170
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
147
171
|
const messages = useMemo(() => threadMap[currentThread?.id || '']?.messages || [], [currentThread?.id, threadMap]);
|
|
148
|
-
return (jsx(I18nProvider, { defaultLocale: locale, children: jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxs(Tt, { style: { height: '100%' }, children: [jsx($t, { minSize: 750, maxSize: 900, children: jsx(ChatkitImpl, { tools: tools || [], showHeader: showHeader, renderHeader: renderHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, toolDisplay: toolDisplay, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller }, currentThreadId) }), debuggerProps && (jsx($t, { defaultSize: '25%', className: "border-l", children: jsx(ADK, { region: debuggerProps.region, controller: controller, thread: currentThread, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }) }));
|
|
172
|
+
return (jsx(I18nProvider, { defaultLocale: locale, children: jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxs(Tt, { style: { height: '100%' }, children: [jsx($t, { minSize: 750, maxSize: 900, children: jsx(ChatkitImpl, { tools: tools || [], showHeader: showHeader, renderHeader: renderHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, toolDisplay: toolDisplay, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller, accept: accept }, currentThreadId) }), debuggerProps && (jsx($t, { defaultSize: '25%', className: "border-l", children: jsx(ADK, { region: debuggerProps.region, controller: controller, thread: currentThread, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }) }));
|
|
149
173
|
};
|
|
150
174
|
var index = forwardRef(Chatkit);
|
|
151
175
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\nimport { I18nProvider, useI18n } from '@/contexts/I18nContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n tool,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nimport {\n BashTool,\n skillAgentToolSet,\n} from '../assistant-ui-tools/skill-agent-tool-set';\nimport React from 'react';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ElementType[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n threadBottom?: React.ReactNode;\n showHeader?: boolean;\n renderHeader?: (props: { thread: ThreadType }) => React.ReactNode;\n\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const { t } = useI18n();\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n threadBottom,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [] || [],\n [currentThread?.id, threadMap],\n );\n\n const { uiMessages, authors } = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n );\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: item.base64,\n status: 'success',\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error(t('thread.notFound')));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n return {\n id,\n type: 'image',\n name: file.name,\n contentType: file.type,\n content: [\n {\n type: 'image',\n image: file.name,\n },\n ],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || t('thread.prompt'),\n showHeader,\n renderHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n authors,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: values(threadMap) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n {threadBottom}\n </Group>\n </div>\n </div>\n {(tools || []).map((tool, index) => React.createElement(tool))}\n <ExecutionCard />\n </ChatkitProvider>\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (props: ChatkitProps) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n tools,\n chatController: chatControllerFromProps = null,\n threadBottom,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n debugger: debuggerProps,\n locale,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [],\n [currentThread?.id, threadMap],\n );\n\n return (\n <I18nProvider defaultLocale={locale}>\n <div\n className={'chatkit-wrapper'}\n style={{ height: '100%' }}\n data-chatkit\n >\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={tools || []}\n showHeader={showHeader}\n renderHeader={renderHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n toolDisplay={toolDisplay}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n threadBottom={threadBottom}\n controller={controller!}\n />\n </Panel>\n {debuggerProps && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={debuggerProps.region}\n controller={controller!}\n thread={currentThread}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n </I18nProvider>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["uuid","_jsx","_jsxs","Group","Panel","React","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,WAAW,GAAG,UAAU,CAC5B,CACE,KAoBC,EACD,GAA6B,KAC3B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,CACO,EACf;AACJ,CAAC,CAAC;AAEF,YAAe,UAAU,CAAC,OAAO,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\nimport { I18nProvider, useI18n } from '@/contexts/I18nContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n tool,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nimport {\n BashTool,\n skillAgentToolSet,\n} from '../assistant-ui-tools/skill-agent-tool-set';\nimport React from 'react';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ElementType[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n threadBottom?: React.ReactNode;\n showHeader?: boolean;\n renderHeader?: (props: { thread: ThreadType }) => React.ReactNode;\n\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n accept?: string;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const { t } = useI18n();\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n uploadeBase64 = true,\n threadBottom,\n accept,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [] || [],\n [currentThread?.id, threadMap],\n );\n\n const { uiMessages, authors } = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = uploadeBase64\n ? await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n )\n : message.attachments || [];\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: (item as { base64?: string })?.base64 || '',\n status: 'success',\n file: item.file,\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error(t('thread.notFound')));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n // Map media type to valid content type\n const baseMediaType = checkMedia(file.type) as\n | 'image'\n | 'video'\n | 'audio';\n const mediaType: 'image' | 'video' | 'audio' | 'file' = [\n 'image',\n 'video',\n 'audio',\n ].includes(baseMediaType)\n ? baseMediaType\n : 'file';\n\n const contentItem: {\n type: typeof mediaType;\n image?: string;\n video?: string;\n audio?: string;\n file?: string;\n } = {\n type: mediaType,\n };\n\n switch (mediaType) {\n case 'image':\n contentItem.image = file.name;\n break;\n case 'video':\n contentItem.video = file.name;\n break;\n case 'audio':\n contentItem.audio = file.name;\n break;\n case 'file':\n contentItem.file = file.name;\n break;\n }\n\n return {\n id,\n type: mediaType,\n name: file.name,\n contentType: file.type,\n content: [contentItem],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: accept || 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || t('thread.prompt'),\n showHeader,\n renderHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n authors,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: values(threadMap) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n {threadBottom}\n </Group>\n </div>\n </div>\n {(tools || []).map((tool, index) => React.createElement(tool))}\n <ExecutionCard />\n </ChatkitProvider>\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (props: ChatkitProps) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n tools,\n chatController: chatControllerFromProps = null,\n threadBottom,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n renderHeader,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n debugger: debuggerProps,\n locale,\n accept,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [],\n [currentThread?.id, threadMap],\n );\n\n return (\n <I18nProvider defaultLocale={locale}>\n <div\n className={'chatkit-wrapper'}\n style={{ height: '100%' }}\n data-chatkit\n >\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={tools || []}\n showHeader={showHeader}\n renderHeader={renderHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n toolDisplay={toolDisplay}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n threadBottom={threadBottom}\n controller={controller!}\n accept={accept}\n />\n </Panel>\n {debuggerProps && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={debuggerProps.region}\n controller={controller!}\n thread={currentThread}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n </I18nProvider>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["uuid","_jsx","_jsxs","Group","Panel","React","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,WAAW,GAAG,UAAU,CAC5B,CACE,KAqBC,EACD,GAA6B,KAC3B;AACF,IAAA,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;IACxB,MAAM,EACJ,aAAa,EACb,KAAK,EACL,WAAW,GAAG,OAAO,EACrB,OAAO,EACP,UAAU,EACV,OAAO,EACP,UAAU,EACV,UAAU,GAAG,IAAI,EACjB,YAAY,EACZ,WAAW,EACX,eAAe,GAAG,KAAK,EACvB,eAAe,GAAG,KAAK,EACvB,gBAAgB,GAAG,KAAK,EACxB,aAAa,GAAG,IAAI,EACpB,YAAY,EACZ,MAAM,GACP,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AACpC,IAAA,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAG3E,IAAA,MAAM,aAAa,GAAG,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;AAC1E,IAAA,MAAM,QAAQ,GAAG,OAAO,CACtB,MAAM,SAAS,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,IAAI,EAAE,IAAI,EAAE,EAC9D,CAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,CAC/B,CAAC;AAEF,IAAA,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO,CACrC,MACE,yBAAyB,CAAC,QAAmC,EAAE;QAC7D,WAAW,EAAE,WAAW,IAA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EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,aAAa,EACT;QACE,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,EAAE,IAAI,CAAC;KACf,GACD;QACE,cAAc,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACxC,OAAO,EAAE,KAAK,CAAC;KAChB,KACF,IAAI,CAAC;IACV,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IACpE,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAG7D,iBAAiB,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IAC5D,iBAAiB,EAAE,MAAM,cAAc,CAAC;IACxC,kBAAkB,EAAE,CAAC,eAAe,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAClE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;IAC7C;;OAEG;IAEH;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,UAAU,CAAC,KAAK,IAAI,CAAC;IAE1E,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useADKChat.cjs","sources":["../../src/hooks/useADKChat.ts"],"sourcesContent":["import { useState, Ref, useRef } from 'react';\nimport {\n AdkPlugin,\n ChatController,\n createThreadManagerState,\n createThreadManagerStateWithDefault,\n ProtocolOptions,\n ThreadMessageManager,\n type RequestOptions,\n A2ACompletion,\n AdkCompletion,\n} from '@chat-lab/core';\nimport { v4 as uuid } from 'uuid';\nimport
|
|
1
|
+
{"version":3,"file":"useADKChat.cjs","sources":["../../src/hooks/useADKChat.ts"],"sourcesContent":["import { useState, Ref, useRef } from 'react';\nimport {\n AdkPlugin,\n ChatController,\n createThreadManagerState,\n createThreadManagerStateWithDefault,\n ProtocolOptions,\n ThreadMessageManager,\n type RequestOptions,\n A2ACompletion,\n AdkCompletion,\n} from '@chat-lab/core';\nimport { v4 as uuid } from 'uuid';\nimport dayjs from 'dayjs';\n\nexport const useADKChat = ({\n initialConfig,\n onError,\n adkOptions,\n}: {\n initialConfig: {\n requestOptions: RequestOptions;\n protocolOptions: ProtocolOptions;\n };\n adkOptions?: {\n appName: string;\n userID: string;\n };\n onError?: (error: Error) => void;\n}) => {\n const controllerRef = useRef<ChatController | null>(null);\n const runtimeType = useRef<'a2a' | 'adk' | null>(null);\n const adkPluginRef = useRef<AdkPlugin | null>(null);\n const runtimeStore = useRef<Map<string, ThreadMessageManager> | null>(null);\n if (!runtimeStore.current) {\n runtimeStore.current = new Map();\n }\n if (!controllerRef.current) {\n const state = createThreadManagerStateWithDefault();\n const storeManager = new ThreadMessageManager(state);\n const adkPlugin = new AdkPlugin({\n appName: adkOptions?.appName || 'veadk',\n userId: adkOptions?.userID || uuid(),\n });\n adkPluginRef.current = adkPlugin;\n controllerRef.current = new ChatController({\n requestOptions: initialConfig.requestOptions,\n protocolOptions: initialConfig.protocolOptions,\n plugins: [adkPlugin],\n onError: onError,\n storeManager,\n });\n }\n const switchRuntime = (\n runtime: string,\n options: { type: 'a2a' } | { type: 'adk'; appName: string },\n ) => {\n // adkPluginRef.current?.switchRuntime(runtime);\n const storeManager = runtimeStore.current?.get(runtime);\n if (storeManager) {\n controllerRef.current?.setStore(storeManager);\n } else {\n const state = createThreadManagerState();\n\n const storeManager = new ThreadMessageManager(state);\n runtimeStore.current?.set(runtime, storeManager);\n controllerRef.current?.setStore(storeManager);\n }\n if (options.type === runtimeType.current) {\n if (options.type === 'adk') {\n adkPluginRef.current?.switchRuntime(runtime, options.appName);\n }\n } else {\n const prevRequestOptions =\n controllerRef.current?.getRequestOptions() as RequestOptions;\n if (options.type === 'adk' && adkPluginRef.current) {\n controllerRef.current?.pluginManager.addPlugin(adkPluginRef.current);\n controllerRef.current?.setProtocolOptions({ protocol: 'ADK' });\n controllerRef.current?.setRequestOptions({\n ...prevRequestOptions,\n completions: AdkCompletion,\n });\n adkPluginRef.current?.switchRuntime(runtime, options.appName);\n } else {\n if (adkPluginRef.current) {\n controllerRef.current?.pluginManager.removePlugin(\n adkPluginRef.current,\n );\n controllerRef.current?.setRequestOptions({\n ...prevRequestOptions,\n completions: A2ACompletion,\n });\n controllerRef.current?.setProtocolOptions({ protocol: 'A2A' });\n if (!controllerRef.current?.getCurrentThread()) {\n const _id = uuid();\n controllerRef.current\n ?.addThread({\n id: _id,\n name: _id,\n metadata: {},\n sending: false,\n createdAt: dayjs().unix(),\n messages: [],\n })\n .then(({ id }) => {\n controllerRef.current?.setCurrentThread(id);\n });\n }\n }\n }\n }\n runtimeType.current = options.type;\n };\n return {\n controllerRef,\n switchRuntime,\n };\n};\n"],"names":["useRef","createThreadManagerStateWithDefault","ThreadMessageManager","AdkPlugin","uuid","ChatController","createThreadManagerState","AdkCompletion","A2ACompletion","dayjs"],"mappings":";;;;;;;AAeO,MAAM,UAAU,GAAG,CAAC,EACzB,aAAa,EACb,OAAO,EACP,UAAU,GAWX,KAAI;AACH,IAAA,MAAM,aAAa,GAAGA,YAAM,CAAwB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,WAAW,GAAGA,YAAM,CAAuB,IAAI,CAAC,CAAC;AACvD,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAmB,IAAI,CAAC,CAAC;AACpD,IAAA,MAAM,YAAY,GAAGA,YAAM,CAA2C,IAAI,CAAC,CAAC;AAC5E,IAAA,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;AACzB,QAAA,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;KAClC;AACD,IAAA,IAAI,CAA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E,GAAG;AACP,4BAAA,IAAI,EAAE,GAAG;AACT,4BAAA,QAAQ,EAAE,EAAE;AACZ,4BAAA,OAAO,EAAE,KAAK;AACd,4BAAA,SAAS,EAAEK,iBAAK,EAAE,CAAC,IAAI,EAAE;AACzB,4BAAA,QAAQ,EAAE,EAAE;yBACb,CAAC;AACD,6BAAA,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,KAAI;AACf,4BAAA,aAAa,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAC9C,yBAAC,CAAC,CAAC;qBACN;iBACF;aACF;SACF;AACD,QAAA,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;AACrC,KAAC,CAAC;IACF,OAAO;QACL,aAAa;QACb,aAAa;KACd,CAAC;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useADKChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useADKChat.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EAGd,eAAe,EAEf,KAAK,cAAc,EAGpB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useADKChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useADKChat.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EAGd,eAAe,EAEf,KAAK,cAAc,EAGpB,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,UAAU,GAAI,yCAIxB;IACD,aAAa,EAAE;QACb,cAAc,EAAE,cAAc,CAAC;QAC/B,eAAe,EAAE,eAAe,CAAC;KAClC,CAAC;IACF,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;;6BAyBY,MAAM,WACN;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CA8D9D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useADKChat.js","sources":["../../src/hooks/useADKChat.ts"],"sourcesContent":["import { useState, Ref, useRef } from 'react';\nimport {\n AdkPlugin,\n ChatController,\n createThreadManagerState,\n createThreadManagerStateWithDefault,\n ProtocolOptions,\n ThreadMessageManager,\n type RequestOptions,\n A2ACompletion,\n AdkCompletion,\n} from '@chat-lab/core';\nimport { v4 as uuid } from 'uuid';\nimport
|
|
1
|
+
{"version":3,"file":"useADKChat.js","sources":["../../src/hooks/useADKChat.ts"],"sourcesContent":["import { useState, Ref, useRef } from 'react';\nimport {\n AdkPlugin,\n ChatController,\n createThreadManagerState,\n createThreadManagerStateWithDefault,\n ProtocolOptions,\n ThreadMessageManager,\n type RequestOptions,\n A2ACompletion,\n AdkCompletion,\n} from '@chat-lab/core';\nimport { v4 as uuid } from 'uuid';\nimport dayjs from 'dayjs';\n\nexport const useADKChat = ({\n initialConfig,\n onError,\n adkOptions,\n}: {\n initialConfig: {\n requestOptions: RequestOptions;\n protocolOptions: ProtocolOptions;\n };\n adkOptions?: {\n appName: string;\n userID: string;\n };\n onError?: (error: Error) => void;\n}) => {\n const controllerRef = useRef<ChatController | null>(null);\n const runtimeType = useRef<'a2a' | 'adk' | null>(null);\n const adkPluginRef = useRef<AdkPlugin | null>(null);\n const runtimeStore = useRef<Map<string, ThreadMessageManager> | null>(null);\n if (!runtimeStore.current) {\n runtimeStore.current = new Map();\n }\n if (!controllerRef.current) {\n const state = createThreadManagerStateWithDefault();\n const storeManager = new ThreadMessageManager(state);\n const adkPlugin = new AdkPlugin({\n appName: adkOptions?.appName || 'veadk',\n userId: adkOptions?.userID || uuid(),\n });\n adkPluginRef.current = adkPlugin;\n controllerRef.current = new ChatController({\n requestOptions: initialConfig.requestOptions,\n protocolOptions: initialConfig.protocolOptions,\n plugins: [adkPlugin],\n onError: onError,\n storeManager,\n });\n }\n const switchRuntime = (\n runtime: string,\n options: { type: 'a2a' } | { type: 'adk'; appName: string },\n ) => {\n // adkPluginRef.current?.switchRuntime(runtime);\n const storeManager = runtimeStore.current?.get(runtime);\n if (storeManager) {\n controllerRef.current?.setStore(storeManager);\n } else {\n const state = createThreadManagerState();\n\n const storeManager = new ThreadMessageManager(state);\n runtimeStore.current?.set(runtime, storeManager);\n controllerRef.current?.setStore(storeManager);\n }\n if (options.type === runtimeType.current) {\n if (options.type === 'adk') {\n adkPluginRef.current?.switchRuntime(runtime, options.appName);\n }\n } else {\n const prevRequestOptions =\n controllerRef.current?.getRequestOptions() as RequestOptions;\n if (options.type === 'adk' && adkPluginRef.current) {\n controllerRef.current?.pluginManager.addPlugin(adkPluginRef.current);\n controllerRef.current?.setProtocolOptions({ protocol: 'ADK' });\n controllerRef.current?.setRequestOptions({\n ...prevRequestOptions,\n completions: AdkCompletion,\n });\n adkPluginRef.current?.switchRuntime(runtime, options.appName);\n } else {\n if (adkPluginRef.current) {\n controllerRef.current?.pluginManager.removePlugin(\n adkPluginRef.current,\n );\n controllerRef.current?.setRequestOptions({\n ...prevRequestOptions,\n completions: A2ACompletion,\n });\n controllerRef.current?.setProtocolOptions({ protocol: 'A2A' });\n if (!controllerRef.current?.getCurrentThread()) {\n const _id = uuid();\n controllerRef.current\n ?.addThread({\n id: _id,\n name: _id,\n metadata: {},\n sending: false,\n createdAt: dayjs().unix(),\n messages: [],\n })\n .then(({ id }) => {\n controllerRef.current?.setCurrentThread(id);\n });\n }\n }\n }\n }\n runtimeType.current = options.type;\n };\n return {\n controllerRef,\n switchRuntime,\n };\n};\n"],"names":["uuid"],"mappings":";;;;;AAeO,MAAM,UAAU,GAAG,CAAC,EACzB,aAAa,EACb,OAAO,EACP,UAAU,GAWX,KAAI;AACH,IAAA,MAAM,aAAa,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,WAAW,GAAG,MAAM,CAAuB,IA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EAAE,kBAAkB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;oBAC/D,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE;AAC9C,wBAAA,MAAM,GAAG,GAAGA,EAAI,EAAE,CAAC;AACnB,wBAAA,aAAa,CAAC,OAAO;AACnB,8BAAE,SAAS,CAAC;AACV,4BAAA,EAAE,EAAE,GAAG;AACP,4BAAA,IAAI,EAAE,GAAG;AACT,4BAAA,QAAQ,EAAE,EAAE;AACZ,4BAAA,OAAO,EAAE,KAAK;AACd,4BAAA,SAAS,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE;AACzB,4BAAA,QAAQ,EAAE,EAAE;yBACb,CAAC;AACD,6BAAA,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,KAAI;AACf,4BAAA,aAAa,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAC9C,yBAAC,CAAC,CAAC;qBACN;iBACF;aACF;SACF;AACD,QAAA,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;AACrC,KAAC,CAAC;IACF,OAAO;QACL,aAAa;QACb,aAAa;KACd,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var index = require('../packages/core/dist/index.cjs');
|
|
5
|
+
var dayjs_min = require('../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.cjs');
|
|
6
|
+
var index$1 = require('../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useMemoizedFn/index.cjs');
|
|
7
|
+
var v4 = require('../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.cjs');
|
|
8
|
+
|
|
9
|
+
const useDebugChat = ({ initialConfig, onError, adkOptions, }) => {
|
|
10
|
+
const controllerRef = React.useRef(null);
|
|
11
|
+
const adkPluginRef = React.useRef(null);
|
|
12
|
+
if (!controllerRef.current) {
|
|
13
|
+
const state = index.createThreadManagerState();
|
|
14
|
+
const storeManager = new index.ThreadMessageManager(state);
|
|
15
|
+
const adkPlugin = new index.AdkPlugin({
|
|
16
|
+
appName: adkOptions?.appName || 'veadk',
|
|
17
|
+
userId: adkOptions?.userID || v4(),
|
|
18
|
+
});
|
|
19
|
+
adkPluginRef.current = adkPlugin;
|
|
20
|
+
controllerRef.current = new index.ChatController({
|
|
21
|
+
requestOptions: initialConfig.requestOptions,
|
|
22
|
+
protocolOptions: initialConfig.protocolOptions,
|
|
23
|
+
plugins: [adkPlugin],
|
|
24
|
+
onError: onError,
|
|
25
|
+
storeManager,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const ready = index$1(({ sessionId }) => {
|
|
29
|
+
controllerRef.current
|
|
30
|
+
?.addThread({
|
|
31
|
+
id: sessionId,
|
|
32
|
+
name: sessionId,
|
|
33
|
+
sending: false,
|
|
34
|
+
metadata: {},
|
|
35
|
+
messages: [],
|
|
36
|
+
createdAt: dayjs_min.default().unix(),
|
|
37
|
+
})
|
|
38
|
+
.then(({ id }) => {
|
|
39
|
+
controllerRef.current?.setCurrentThread(id);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
controllerRef,
|
|
44
|
+
ready,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.useDebugChat = useDebugChat;
|
|
49
|
+
//# sourceMappingURL=useDebugChat.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebugChat.cjs","sources":["../../src/hooks/useDebugChat.tsx"],"sourcesContent":["import { useState, Ref, useRef } from 'react';\nimport {\n AdkPlugin,\n ChatController,\n createThreadManagerState,\n ProtocolOptions,\n ThreadMessageManager,\n type RequestOptions,\n A2ACompletion,\n AdkCompletion,\n} from '@chat-lab/core';\nimport { v4 as uuid } from 'uuid';\nimport dayjs from 'dayjs';\nimport { useMemoizedFn } from 'ahooks';\n\nexport const useDebugChat = ({\n initialConfig,\n onError,\n adkOptions,\n}: {\n initialConfig: {\n requestOptions: RequestOptions;\n protocolOptions: ProtocolOptions;\n };\n adkOptions?: {\n appName: string;\n userID: string;\n };\n onError?: (error: Error) => void;\n}) => {\n const controllerRef = useRef<ChatController | null>(null);\n const adkPluginRef = useRef<AdkPlugin | null>(null);\n\n if (!controllerRef.current) {\n const state = createThreadManagerState();\n const storeManager = new ThreadMessageManager(state);\n const adkPlugin = new AdkPlugin({\n appName: adkOptions?.appName || 'veadk',\n userId: adkOptions?.userID || uuid(),\n });\n adkPluginRef.current = adkPlugin;\n controllerRef.current = new ChatController({\n requestOptions: initialConfig.requestOptions,\n protocolOptions: initialConfig.protocolOptions,\n plugins: [adkPlugin],\n onError: onError,\n storeManager,\n });\n }\n\n const ready = useMemoizedFn(({ sessionId }: { sessionId: string }) => {\n controllerRef.current\n ?.addThread({\n id: sessionId,\n name: sessionId,\n sending: false,\n metadata: {},\n messages: [],\n createdAt: dayjs().unix(),\n })\n .then(({ id }) => {\n controllerRef.current?.setCurrentThread(id);\n });\n });\n\n return {\n controllerRef,\n ready,\n };\n};\n"],"names":["useRef","createThreadManagerState","ThreadMessageManager","AdkPlugin","uuid","ChatController","useMemoizedFn","dayjs"],"mappings":";;;;;;;;AAeO,MAAM,YAAY,GAAG,CAAC,EAC3B,aAAa,EACb,OAAO,EACP,UAAU,GAWX,KAAI;AACH,IAAA,MAAM,aAAa,GAAGA,YAAM,CAAwB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAmB,IAAI,CAAC,CAAC;AAEpD,IAAA,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE;AAC1B,QAAA,MAAM,KAAK,GAAGC,8BAAwB,EAAE,CAAC;AACzC,QAAA,MAAM,YAAY,GAAG,IAAIC,0BAAoB,CAAC,KAAK,CAAC,CAAC;AACrD,QAAA,MAAM,SAAS,GAAG,IAAIC,eAAS,CAAC;AAC9B,YAAA,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,OAAO;AACvC,YAAA,MAAM,EAAE,UAAU,EAAE,MAAM,IAAIC,EAAI,EAAE;AACrC,SAAA,CAAC,CAAC;AACH,QAAA,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;AACjC,QAAA,aAAa,CAAC,OAAO,GAAG,IAAIC,oBAAc,CAAC;YACzC,cAAc,EAAE,aAAa,CAAC,cAAc;YAC5C,eAAe,EAAE,aAAa,CAAC,eAAe;YAC9C,OAAO,EAAE,CAAC,SAAS,CAAC;AACpB,YAAA,OAAO,EAAE,OAAO;YAChB,YAAY;AACb,SAAA,CAAC,CAAC;KACJ;IAED,MAAM,KAAK,GAAGC,OAAa,CAAC,CAAC,EAAE,SAAS,EAAyB,KAAI;AACnE,QAAA,aAAa,CAAC,OAAO;AACnB,cAAE,SAAS,CAAC;AACV,YAAA,EAAE,EAAE,SAAS;AACb,YAAA,IAAI,EAAE,SAAS;AACf,YAAA,OAAO,EAAE,KAAK;AACd,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,SAAS,EAAEC,iBAAK,EAAE,CAAC,IAAI,EAAE;SAC1B,CAAC;AACD,aAAA,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,KAAI;AACf,YAAA,aAAa,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAC9C,SAAC,CAAC,CAAC;AACP,KAAC,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,KAAK;KACN,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChatController, ProtocolOptions, type RequestOptions } from '@chat-lab/core';
|
|
2
|
+
export declare const useDebugChat: ({ initialConfig, onError, adkOptions, }: {
|
|
3
|
+
initialConfig: {
|
|
4
|
+
requestOptions: RequestOptions;
|
|
5
|
+
protocolOptions: ProtocolOptions;
|
|
6
|
+
};
|
|
7
|
+
adkOptions?: {
|
|
8
|
+
appName: string;
|
|
9
|
+
userID: string;
|
|
10
|
+
};
|
|
11
|
+
onError?: (error: Error) => void;
|
|
12
|
+
}) => {
|
|
13
|
+
controllerRef: import("react").MutableRefObject<ChatController<import("@chat-lab/core").ChatMessage<import("@chat-lab/core").BaseMessage>> | null>;
|
|
14
|
+
ready: (this: unknown, args_0: {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
}) => void;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=useDebugChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebugChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useDebugChat.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EAEd,eAAe,EAEf,KAAK,cAAc,EAGpB,MAAM,gBAAgB,CAAC;AAKxB,eAAO,MAAM,YAAY,GAAI,yCAI1B;IACD,aAAa,EAAE;QACb,cAAc,EAAE,cAAc,CAAC;QAC/B,eAAe,EAAE,eAAe,CAAC;KAClC,CAAC;IACF,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;;;mBAqB0D,MAAM;;CAmBhE,CAAC"}
|