mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
refactor: improve focus handling and simplify content parsing
- Refactored focus handling in useAssistantConsole to use a dedicated function for clarity and adjusted timeout duration. - Simplified content parsing in ChatMessageAction by directly returning parsed JSON and removing unnecessary mapping logic. - Updated ChatSidebar to allow a larger maximum width for improved layout flexibility. - Removed unused interface definitions in llm.d.ts to clean up the codebase.
This commit is contained in:
@@ -411,11 +411,12 @@ const useAssistantConsole = () => {
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
const focusInput = () => {
|
||||
setTimeout(() => {
|
||||
chatInputRef.value?.focus();
|
||||
}, 200);
|
||||
});
|
||||
}, 500);
|
||||
};
|
||||
onMounted(focusInput);
|
||||
|
||||
return {
|
||||
// Refs
|
||||
|
||||
@@ -24,28 +24,13 @@ const actionStatusIcon = computed<Icon>(() => {
|
||||
}
|
||||
});
|
||||
|
||||
const parsedContent = computed<ParsedResourceContent[] | null>(() => {
|
||||
const parsedContent = computed<Record<string, any> | Record<string, any>[] | null>(() => {
|
||||
if (!props.content) return null;
|
||||
let resourceContents: ResourceContent[];
|
||||
try {
|
||||
resourceContents = JSON.parse(props.content);
|
||||
return JSON.parse(props.content);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
if (!resourceContents) return null;
|
||||
return resourceContents.map(resourceContent => {
|
||||
const parsedResourceContent: ParsedResourceContent = {
|
||||
...resourceContent,
|
||||
};
|
||||
if (typeof parsedResourceContent.text === 'string') {
|
||||
try {
|
||||
parsedResourceContent.text = JSON.parse(parsedResourceContent.text);
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return parsedResourceContent;
|
||||
});
|
||||
});
|
||||
|
||||
const isJsonContent = computed(() => {
|
||||
@@ -101,7 +86,6 @@ defineOptions({ name: 'ClChatMessageAction' });
|
||||
<div class="json-content">
|
||||
<json-editor-vue
|
||||
v-model="parsedContent"
|
||||
mode="view"
|
||||
expanded-on-start
|
||||
read-only
|
||||
/>
|
||||
@@ -125,7 +109,6 @@ defineOptions({ name: 'ClChatMessageAction' });
|
||||
>
|
||||
<json-editor-vue
|
||||
v-model="parsedContent"
|
||||
mode="view"
|
||||
expanded-on-start
|
||||
read-only
|
||||
/>
|
||||
|
||||
@@ -40,7 +40,7 @@ const onResizeMove = (e: MouseEvent) => {
|
||||
if (!isResizing.value) return;
|
||||
const deltaX = startX.value - e.clientX;
|
||||
const minWidth = props.minWidth || 350;
|
||||
const maxWidth = props.maxWidth || 600;
|
||||
const maxWidth = props.maxWidth || 1200;
|
||||
const newWidth = Math.min(
|
||||
Math.max(startWidth.value + deltaX, minWidth),
|
||||
maxWidth
|
||||
|
||||
@@ -126,13 +126,4 @@ export declare global {
|
||||
is_text_done?: boolean;
|
||||
usage?: ChatMessageUsage;
|
||||
}
|
||||
|
||||
interface ResourceContent {
|
||||
uri?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
interface ParsedResourceContent extends ResourceContent {
|
||||
text?: string | boolean | number | Record<string, any> | Array<any>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user