@chat-lab/ui 0.1.0-beta.51 → 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/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 +13 -3
- package/dist/hooks/useSkillAgent/index.cjs.map +1 -1
- package/dist/hooks/useSkillAgent/index.d.ts +3 -1
- package/dist/hooks/useSkillAgent/index.d.ts.map +1 -1
- package/dist/hooks/useSkillAgent/index.js +13 -3
- 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/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","ExecutionCard","useRef","I18nProvider","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,WAAW,GAAGA,gBAAU,CAC5B,CACE,KAoBC,EACD,GAA6B,KAC3B;AACF,IAAA,MAAM,EAAE,CAAC,EAAE,GAAGC,mBAAO,EAAE,CAAC;AACxB,IAAA,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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AM,EAAE,MAAM,EAAE,EAAA,cAAA,EAAA,IAAA,EAAA,QAAA,EAGzBE,gBAACG,0BAAK,EAAA,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,aAC9BL,cAAC,CAAAM,0BAAK,IAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,YAC/BN,cAAC,CAAA,WAAW,EAEV,EAAA,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAW,EAAA,EAdlB,eAAe,CAepB,GACI,EACP,aAAa,KACZA,eAACM,0BAAK,EAAA,EAAC,WAAW,EAAE,KAAK,EAAE,SAAS,EAAC,UAAU,EAAA,QAAA,EAC7CN,eAACW,OAAK,EAAA,EACJ,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
|
+
{"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;AAC1E,IAAA,MAAM,QAAQ,GAAGC,aAAO,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,GAAGA,aAAO,CACrC,MACE,yBAAyB,CAAC,QAAmC,EAAE;QAC7D,WAAW,EAAE,WAAW,IAAI,OAAO;AACpC,KAAA,CAAC,EACJ,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,MAAM,OAAO,GAAGC,+CA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/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;AACF,IAAA,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;AACxB,IAAA,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,YAAY,GACb,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AACpC,IAAA,MAAM,EAAE,SAAS,EAAE,eAA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AAE,GAAG,EAAE,OAAO,EAAE,GAAG,YAC/BH,GAAC,CAAA,WAAW,EAEV,EAAA,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAW,EAAA,EAdlB,eAAe,CAepB,GACI,EACP,aAAa,KACZA,IAACG,EAAK,EAAA,EAAC,WAAW,EAAE,KAAK,EAAE,SAAS,EAAC,UAAU,EAAA,QAAA,EAC7CH,IAACK,GAAK,EAAA,EACJ,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,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,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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"}
|
|
@@ -7,6 +7,7 @@ class SkillAgentPlugin extends index.ChatkitPlugin {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super({ pluginName });
|
|
9
9
|
this.onStateChange = options.onStateChange;
|
|
10
|
+
this.onUploadFiles = options.onUploadFiles;
|
|
10
11
|
}
|
|
11
12
|
apply(compiler) {
|
|
12
13
|
compiler.hooks.message.received.tap(pluginName, (ctx) => {
|
|
@@ -14,8 +15,34 @@ class SkillAgentPlugin extends index.ChatkitPlugin {
|
|
|
14
15
|
if (metadata.hasStateDelta) {
|
|
15
16
|
this.onStateChange?.(metadata.stateDelta);
|
|
16
17
|
}
|
|
18
|
+
const threadId = ctx.threadId;
|
|
19
|
+
const thread = this.chatController?.getThread(threadId);
|
|
20
|
+
this.chatController?.updateThread(threadId, {
|
|
21
|
+
metadata: {
|
|
22
|
+
...thread?.metadata,
|
|
23
|
+
stateDelta: metadata.stateDelta,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
17
26
|
return ctx;
|
|
18
27
|
});
|
|
28
|
+
compiler.hooks.message.beforeSend.tap(pluginName, async (ctx) => {
|
|
29
|
+
const filePaths = await this.onUploadFiles?.(ctx.userMessage.attaches.map(({ file }) => file));
|
|
30
|
+
return {
|
|
31
|
+
...ctx,
|
|
32
|
+
attachments: [],
|
|
33
|
+
userMessage: {
|
|
34
|
+
...ctx.userMessage,
|
|
35
|
+
content: ctx.userMessage.content.concat({
|
|
36
|
+
type: 'text',
|
|
37
|
+
text: `附件 :${filePaths?.join(',') || ''}`,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
updateOptions(options) {
|
|
44
|
+
this.onStateChange = options.onStateChange;
|
|
45
|
+
this.onUploadFiles = options.onUploadFiles;
|
|
19
46
|
}
|
|
20
47
|
}
|
|
21
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkillAgentPlugin.cjs","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n constructor(options: {
|
|
1
|
+
{"version":3,"file":"SkillAgentPlugin.cjs","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n if (metadata.hasStateDelta) {\n this.onStateChange?.(metadata.stateDelta);\n }\n const threadId = ctx.threadId;\n const thread = this.chatController?.getThread(threadId);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n stateDelta: metadata.stateDelta,\n },\n });\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":["ChatkitPlugin"],"mappings":";;;;AAEA,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,gBAAiB,SAAQA,mBAAa,CAAA;AAG1C,IAAA,WAAA,CAAY,OAGX,EAAA;AACC,QAAA,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AACtB,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACD,IAAA,KAAK,CAAC,QAAkB,EAAA;AACtB,QAAA,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,GAAQ,KAAI;AAC3D,YAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B,YAAA,IAAI,QAAQ,CAAC,aAAa,EAAE;gBAC1B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;aAC3C;AACD,YAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;AACx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Change?: (state: string) => void;
|
|
5
|
+
onUploadFiles?: (files: File[]) => Promise<string[]>;
|
|
4
6
|
constructor(options: {
|
|
5
7
|
onStateChange?: (state: string) => void;
|
|
8
|
+
onUploadFiles?: (files: File[]) => Promise<string[]>;
|
|
6
9
|
});
|
|
7
10
|
apply(compiler: Compiler): void;
|
|
11
|
+
updateOptions(options: SkillAgentOptions): void;
|
|
8
12
|
}
|
|
9
13
|
export default SkillAgentPlugin;
|
|
10
14
|
//# sourceMappingURL=SkillAgentPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkillAgentPlugin.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"SkillAgentPlugin.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,cAAM,gBAAiB,SAAQ,aAAa;IAC1C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;gBACzC,OAAO,EAAE;QACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QACxC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;KACtD;IAKD,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAqCxB,aAAa,CAAC,OAAO,EAAE,iBAAiB;CAIzC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -5,6 +5,7 @@ class SkillAgentPlugin extends ChatkitPlugin {
|
|
|
5
5
|
constructor(options) {
|
|
6
6
|
super({ pluginName });
|
|
7
7
|
this.onStateChange = options.onStateChange;
|
|
8
|
+
this.onUploadFiles = options.onUploadFiles;
|
|
8
9
|
}
|
|
9
10
|
apply(compiler) {
|
|
10
11
|
compiler.hooks.message.received.tap(pluginName, (ctx) => {
|
|
@@ -12,8 +13,34 @@ class SkillAgentPlugin extends ChatkitPlugin {
|
|
|
12
13
|
if (metadata.hasStateDelta) {
|
|
13
14
|
this.onStateChange?.(metadata.stateDelta);
|
|
14
15
|
}
|
|
16
|
+
const threadId = ctx.threadId;
|
|
17
|
+
const thread = this.chatController?.getThread(threadId);
|
|
18
|
+
this.chatController?.updateThread(threadId, {
|
|
19
|
+
metadata: {
|
|
20
|
+
...thread?.metadata,
|
|
21
|
+
stateDelta: metadata.stateDelta,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
15
24
|
return ctx;
|
|
16
25
|
});
|
|
26
|
+
compiler.hooks.message.beforeSend.tap(pluginName, async (ctx) => {
|
|
27
|
+
const filePaths = await this.onUploadFiles?.(ctx.userMessage.attaches.map(({ file }) => file));
|
|
28
|
+
return {
|
|
29
|
+
...ctx,
|
|
30
|
+
attachments: [],
|
|
31
|
+
userMessage: {
|
|
32
|
+
...ctx.userMessage,
|
|
33
|
+
content: ctx.userMessage.content.concat({
|
|
34
|
+
type: 'text',
|
|
35
|
+
text: `附件 :${filePaths?.join(',') || ''}`,
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
updateOptions(options) {
|
|
42
|
+
this.onStateChange = options.onStateChange;
|
|
43
|
+
this.onUploadFiles = options.onUploadFiles;
|
|
17
44
|
}
|
|
18
45
|
}
|
|
19
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkillAgentPlugin.js","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n constructor(options: {
|
|
1
|
+
{"version":3,"file":"SkillAgentPlugin.js","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n if (metadata.hasStateDelta) {\n this.onStateChange?.(metadata.stateDelta);\n }\n const threadId = ctx.threadId;\n const thread = this.chatController?.getThread(threadId);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n stateDelta: metadata.stateDelta,\n },\n });\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":[],"mappings":";;AAEA,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAC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L,gBAAA,GAAG,GAAG;AACN,gBAAA,WAAW,EAAE,EAAE;AACf,gBAAA,WAAW,EAAE;oBACX,GAAG,GAAG,CAAC,WAAW;oBAClB,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,wBAAA,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,CAAO,IAAA,EAAA,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAE,CAAA;qBAC1C,CAAC;AACH,iBAAA;aACF,CAAC;AACJ,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,aAAa,CAAC,OAA0B,EAAA;AACtC,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACF;;;;"}
|
|
@@ -7,11 +7,17 @@ var index$1 = require('../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_re
|
|
|
7
7
|
|
|
8
8
|
const useSkillAgent = (options) => {
|
|
9
9
|
const chatControllerRef = React.useRef();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const pluginRef = React.useRef();
|
|
11
|
+
if (!pluginRef.current) {
|
|
12
|
+
pluginRef.current = new SkillAgentPlugin({
|
|
13
13
|
onStateChange: options.onStateChange,
|
|
14
|
+
onUploadFiles: options.onUploadFiles,
|
|
14
15
|
});
|
|
16
|
+
}
|
|
17
|
+
pluginRef.current.updateOptions(options);
|
|
18
|
+
if (!chatControllerRef.current) {
|
|
19
|
+
const store = new index.ThreadMessageManager(index.createThreadManagerState());
|
|
20
|
+
const plugin = pluginRef.current;
|
|
15
21
|
const adlPlugin = new index.AdkPlugin({
|
|
16
22
|
appName: options.adkOptions.appName,
|
|
17
23
|
userId: options.adkOptions.userID,
|
|
@@ -57,10 +63,14 @@ const useSkillAgent = (options) => {
|
|
|
57
63
|
chatControllerRef.current?.setCurrentThread(sessionId);
|
|
58
64
|
});
|
|
59
65
|
});
|
|
66
|
+
const getDeltaState = index$1(() => {
|
|
67
|
+
return chatControllerRef.current?.getCurrentThread();
|
|
68
|
+
});
|
|
60
69
|
return {
|
|
61
70
|
controllerRef: chatControllerRef,
|
|
62
71
|
sendMessage,
|
|
63
72
|
ready,
|
|
73
|
+
getDeltaState,
|
|
64
74
|
};
|
|
65
75
|
};
|
|
66
76
|
|