refactor: enhance link preview functionality with Chromium fallback

- Added a fallback mechanism using headless Chromium to fetch page content when standard HTTP requests fail.
- Introduced utility functions for unescaping HTML entities and converting relative URLs to absolute.
- Updated HTTP request headers to mimic a browser for better compatibility with web servers.
- Improved error handling and logging for better debugging and user feedback.
- Made various properties in Zod schemas nullable for better type safety and flexibility in handling optional data.
This commit is contained in:
Anish Sarkar 2025-12-26 00:07:45 +05:30
parent 4c2de73694
commit bea18960a4
7 changed files with 271 additions and 86 deletions

View file

@ -70,12 +70,12 @@ const ThinkingStepSchema = z.object({
});
const DeepAgentThinkingArgsSchema = z.object({
query: z.string().optional(),
context: z.string().optional(),
query: z.string().nullish(),
context: z.string().nullish(),
});
const DeepAgentThinkingResultSchema = z.object({
steps: z.array(ThinkingStepSchema).optional(),
steps: z.array(ThinkingStepSchema).nullish(),
status: z
.enum([
THINKING_STATUS.THINKING,
@ -83,8 +83,8 @@ const DeepAgentThinkingResultSchema = z.object({
THINKING_STATUS.SYNTHESIZING,
THINKING_STATUS.COMPLETED,
])
.optional(),
summary: z.string().optional(),
.nullish(),
summary: z.string().nullish(),
});
/** Types derived from Zod schemas */
@ -325,7 +325,7 @@ export const DeepAgentThinkingToolUI = makeAssistantToolUI<
render: function DeepAgentThinkingUI({ result, status }) {
// Loading state - tool is still running
if (status.type === "running" || status.type === "requires-action") {
return <ThinkingLoadingState status={result?.status} />;
return <ThinkingLoadingState status={result?.status ?? undefined} />;
}
// Incomplete/cancelled state