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:
Marvin Zhang
2025-04-17 16:28:56 +08:00
parent 336ca5770b
commit 36c7d5e3a3
4 changed files with 7 additions and 32 deletions

View File

@@ -411,11 +411,12 @@ const useAssistantConsole = () => {
}
});
onMounted(() => {
const focusInput = () => {
setTimeout(() => {
chatInputRef.value?.focus();
}, 200);
});
}, 500);
};
onMounted(focusInput);
return {
// Refs

View File

@@ -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
/>

View File

@@ -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

View File

@@ -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>;
}
}