Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(codex): preserve web search render details (#16569)

AmAzing-dfb962d3a5cd
diff --git a/AGENTS.md b/AGENTS.md
index 9696c9ba636..2f8354bd28b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -138,3 +138,11 @@ bun run type-check
Before reviewing a PR / diff / branch change, read the **review-checklist** skill (`.agents/skills/review-checklist/SKILL.md`) — it lists the recurring mistakes specific to this codebase.
When designing or reviewing user-facing flows (empty/loading/error states, confirmations, async feedback, button hierarchy, lists at scale, pickers), follow the **ux** skill (`.agents/skills/ux/SKILL.md`) — LobeHub's design values (自然 / 意义感 / 确定性) plus per-aspect execution checklists.
+
+<!-- BEGIN:nextjs-agent-rules -->
+# This is NOT the Next.js you know
+
+This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
+
+**Keep this block, including in commits.** It is part of the project's agent setup, maintained by `next dev` for every agent that works here. If it appears as an uncommitted change, that is intentional — commit it as-is. Do not remove it to clean up a diff; it will be regenerated.
+<!-- END:nextjs-agent-rules -->
diff --git a/packages/builtin-tools/src/codex/WebSearchInspector.tsx b/packages/builtin-tools/src/codex/WebSearchInspector.tsx
index d3a00b6ee8f..1a7c0de30c7 100644
--- a/packages/builtin-tools/src/codex/WebSearchInspector.tsx
+++ b/packages/builtin-tools/src/codex/WebSearchInspector.tsx
@@ -12,11 +12,12 @@ import { useTranslation } from 'react-i18next';
import { type CodexWebSearchArgs, getWebSearchQuery } from './webSearchUtils';
-const WebSearchInspector = memo<BuiltinInspectorProps<CodexWebSearchArgs>>(
- ({ args, partialArgs, isArgumentsStreaming, isLoading }) => {
+const WebSearchInspector = memo<BuiltinInspectorProps<CodexWebSearchArgs, CodexWebSearchArgs>>(
+ ({ args, partialArgs, pluginState, isArgumentsStreaming, isLoading }) => {
const { t } = useTranslation('plugin');
const label = t('builtins.codex.apiName.web_search', { defaultValue: 'Search the web' });
- const query = getWebSearchQuery(args) || getWebSearchQuery(partialArgs);
+ const query =
+ getWebSearchQuery(args) || getWebSearchQuery(partialArgs) || getWebSearchQuery(pluginState);
if (isArgumentsStreaming && !query) {
return <div className={cx(inspectorTextStyles.root, shinyTextStyles.shinyText)}>{label}</div>;
diff --git a/packages/builtin-tools/src/codex/WebSearchRender.tsx b/packages/builtin-tools/src/codex/WebSearchRender.tsx
index 7d0bcbbdecb..6fe34e62f20 100644
--- a/packages/builtin-tools/src/codex/WebSearchRender.tsx
+++ b/packages/builtin-tools/src/codex/WebSearchRender.tsx
@@ -98,50 +98,53 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
`,
}));
-const WebSearchRender = memo<BuiltinRenderProps<CodexWebSearchArgs>>(({ args, content }) => {
- const { t } = useTranslation('plugin');
- const query = getWebSearchQuery(args);
- const results = getWebSearchResults(args, content);
- const output = results.length > 0 ? '' : getWebSearchOutput(content);
-
- if (!query && results.length === 0 && !output) return null;
-
- return (
- <Flexbox className={styles.root}>
- {query && (
- <Flexbox horizontal className={styles.queryRow}>
- <span className={styles.queryLabel}>
- {t('builtins.codex.webSearch.query', { defaultValue: 'Query' })}
- </span>
- <span className={styles.query}>{query}</span>
- </Flexbox>
- )}
- {results.length > 0 && (
- <Flexbox className={styles.resultList}>
- {results.map((result, index) => {
- const key = result.url || `${result.title}-${index}`;
- const title = <span className={styles.title}>{result.title}</span>;
-
- return (
- <Flexbox className={styles.resultItem} gap={3} key={key}>
- {result.url ? (
- <a href={result.url} rel={'noreferrer'} target={'_blank'}>
- {title}
- </a>
- ) : (
- title
- )}
- {result.url && <Text className={styles.url}>{result.url}</Text>}
- {result.snippet && <Text className={styles.snippet}>{result.snippet}</Text>}
- </Flexbox>
- );
- })}
- </Flexbox>
- )}
- {output && <pre className={styles.output}>{output}</pre>}
- </Flexbox>
- );
-});
+const WebSearchRender = memo<BuiltinRenderProps<CodexWebSearchArgs, CodexWebSearchArgs>>(
+ ({ args, content, pluginState }) => {
+ const { t } = useTranslation('plugin');
+ const query = getWebSearchQuery(args) || getWebSearchQuery(pluginState);
+ const argResults = getWebSearchResults(args, content);
+ const results = argResults.length > 0 ? argResults : getWebSearchResults(pluginState);
+ const output = results.length > 0 ? '' : getWebSearchOutput(content);
+
+ if (!query && results.length === 0 && !output) return null;
+
+ return (
+ <Flexbox className={styles.root}>
+ {query && (
+ <Flexbox horizontal className={styles.queryRow}>
+ <span className={styles.queryLabel}>
+ {t('builtins.codex.webSearch.query', { defaultValue: 'Query' })}
+ </span>
+ <span className={styles.query}>{query}</span>
+ </Flexbox>
+ )}
+ {results.length > 0 && (
+ <Flexbox className={styles.resultList}>
+ {results.map((result, index) => {
+ const key = result.url || `${result.title}-${index}`;
+ const title = <span className={styles.title}>{result.title}</span>;
+
+ return (
+ <Flexbox className={styles.resultItem} gap={3} key={key}>
+ {result.url ? (
+ <a href={result.url} rel={'noreferrer'} target={'_blank'}>
+ {title}
+ </a>
+ ) : (
+ title
+ )}
+ {result.url && <Text className={styles.url}>{result.url}</Text>}
+ {result.snippet && <Text className={styles.snippet}>{result.snippet}</Text>}
+ </Flexbox>
+ );
+ })}
+ </Flexbox>
+ )}
+ {output && <pre className={styles.output}>{output}</pre>}
+ </Flexbox>
+ );
+ },
+);
WebSearchRender.displayName = 'CodexWebSearchRender';
diff --git a/packages/builtin-tools/src/codex/webSearchUtils.test.ts b/packages/builtin-tools/src/codex/webSearchUtils.test.ts
new file mode 100644
index 00000000000..b7ab5f10464
--- /dev/null
+++ b/packages/builtin-tools/src/codex/webSearchUtils.test.ts
@@ -0,0 +1,68 @@
+import { describe, expect, it } from 'vitest';
+
+import { getWebSearchOutput, getWebSearchQuery, getWebSearchResults } from './webSearchUtils';
+
+describe('getWebSearchQuery', () => {
+ it('reads the completed Codex web_search query from plugin state action', () => {
+ expect(
+ getWebSearchQuery({
+ action: {
+ query: 'OpenAI Codex CLI install official documentation',
+ type: 'search',
+ },
+ status: 'completed',
+ }),
+ ).toBe('OpenAI Codex CLI install official documentation');
+ });
+
+ it('reads the completed Codex web_search query from action queries', () => {
+ expect(
+ getWebSearchQuery({
+ action: {
+ queries: ['OpenAI Codex CLI install official documentation'],
+ type: 'search',
+ },
+ status: 'completed',
+ }),
+ ).toBe('OpenAI Codex CLI install official documentation');
+ });
+
+ it('keeps direct args query as the first match', () => {
+ expect(
+ getWebSearchQuery({
+ action: { query: 'completed query' },
+ query: 'streaming query',
+ }),
+ ).toBe('streaming query');
+ });
+});
+
+describe('getWebSearchResults', () => {
+ it('parses search results from plugin state data', () => {
+ expect(
+ getWebSearchResults({
+ action: {
+ results: [
+ {
+ snippet: 'Official documentation',
+ title: 'Codex docs',
+ url: 'https://developers.openai.com/codex',
+ },
+ ],
+ },
+ }),
+ ).toEqual([
+ {
+ snippet: 'Official documentation',
+ title: 'Codex docs',
+ url: 'https://developers.openai.com/codex',
+ },
+ ]);
+ });
+});
+
+describe('getWebSearchOutput', () => {
+ it('hides Codex fallback completion copy', () => {
+ expect(getWebSearchOutput('Completed web_search.')).toBe('');
+ });
+});
diff --git a/packages/builtin-tools/src/codex/webSearchUtils.ts b/packages/builtin-tools/src/codex/webSearchUtils.ts
index 6d4ceefd8c0..2bb8c5b8e91 100644
--- a/packages/builtin-tools/src/codex/webSearchUtils.ts
+++ b/packages/builtin-tools/src/codex/webSearchUtils.ts
@@ -1,7 +1,9 @@
'use client';
export interface CodexWebSearchArgs extends Record<string, unknown> {
+ action?: unknown;
query?: unknown;
+ queries?: unknown;
results?: unknown;
search_query?: unknown;
searchQuery?: unknown;
@@ -13,8 +15,26 @@ export interface CodexWebSearchResult {
url?: string;
}
-const QUERY_KEYS = ['query', 'search_query', 'searchQuery', 'q', 'keyword', 'keywords', 'term'];
-const NESTED_ARG_KEYS = ['args', 'arguments', 'input', 'params', 'request', 'payload', 'data'];
+const QUERY_KEYS = [
+ 'query',
+ 'queries',
+ 'search_query',
+ 'searchQuery',
+ 'q',
+ 'keyword',
+ 'keywords',
+ 'term',
+];
+const NESTED_ARG_KEYS = [
+ 'args',
+ 'arguments',
+ 'input',
+ 'params',
+ 'request',
+ 'payload',
+ 'data',
+ 'action',
+];
const RESULT_KEYS = ['results', 'search_results', 'searchResults', 'items', 'sources', 'citations'];
const TITLE_KEYS = ['title', 'name', 'pageTitle', 'source'];
const URL_KEYS = ['url', 'link', 'href', 'sourceUrl'];
diff --git a/packages/heterogeneous-agents/src/adapters/codex.test.ts b/packages/heterogeneous-agents/src/adapters/codex.test.ts
index a7ab7bd1db0..133025c62aa 100644
--- a/packages/heterogeneous-agents/src/adapters/codex.test.ts
+++ b/packages/heterogeneous-agents/src/adapters/codex.test.ts
@@ -491,6 +491,109 @@ describe('CodexAdapter', () => {
});
});
+ it('preserves completed web_search query details for tool rendering', () => {
+ const adapter = new CodexAdapter();
+ const query = 'OpenAI Codex CLI install official documentation';
+
+ const started = adapter.adapt({
+ item: {
+ action: { type: 'other' },
+ id: 'ws_search',
+ query: '',
+ type: 'web_search',
+ },
+ type: 'item.started',
+ });
+ const completed = adapter.adapt({
+ item: {
+ action: {
+ queries: [query, 'OpenAI Codex npm @openai/codex GitHub'],
+ query,
+ type: 'search',
+ },
+ id: 'ws_search',
+ query,
+ status: 'completed',
+ type: 'web_search',
+ },
+ type: 'item.completed',
+ });
+
+ expect(started[0]).toMatchObject({
+ data: {
+ chunkType: 'tools_calling',
+ toolsCalling: [
+ {
+ apiName: 'web_search',
+ arguments: JSON.stringify({
+ action: { type: 'other' },
+ id: 'ws_search',
+ query: '',
+ type: 'web_search',
+ }),
+ id: 'ws_search',
+ identifier: 'codex',
+ },
+ ],
+ },
+ type: 'stream_chunk',
+ });
+ expect(completed[0]).toMatchObject({
+ data: {
+ content: 'Completed web_search.',
+ isError: false,
+ pluginState: {
+ action: {
+ queries: [query, 'OpenAI Codex npm @openai/codex GitHub'],
+ query,
+ type: 'search',
+ },
+ query,
+ status: 'completed',
+ },
+ toolCallId: 'ws_search',
+ },
+ type: 'tool_result',
+ });
+ expect(completed[1]).toMatchObject({
+ data: { isSuccess: true, toolCallId: 'ws_search' },
+ type: 'tool_end',
+ });
+ });
+
+ it('preserves completed web_search action queries for tool rendering', () => {
+ const adapter = new CodexAdapter();
+ const query = 'OpenAI Codex CLI install official documentation';
+ const completed = adapter.adapt({
+ item: {
+ action: {
+ queries: [query, 'OpenAI Codex npm @openai/codex GitHub'],
+ type: 'search',
+ },
+ id: 'ws_search',
+ status: 'completed',
+ type: 'web_search',
+ },
+ type: 'item.completed',
+ });
+ const result = completed.find((event) => event.type === 'tool_result');
+
+ expect(result).toMatchObject({
+ data: {
+ pluginState: {
+ action: {
+ queries: [query, 'OpenAI Codex npm @openai/codex GitHub'],
+ type: 'search',
+ },
+ query,
+ status: 'completed',
+ },
+ toolCallId: 'ws_search',
+ },
+ type: 'tool_result',
+ });
+ });
+
it('truncates oversized Codex command output before forwarding tool results', () => {
const adapter = new CodexAdapter();
const oversizedOutput = 'x'.repeat(25_010);
diff --git a/packages/heterogeneous-agents/src/adapters/codex.ts b/packages/heterogeneous-agents/src/adapters/codex.ts
index 9587b344ea4..30952cb7a2f 100644
--- a/packages/heterogeneous-agents/src/adapters/codex.ts
+++ b/packages/heterogeneous-agents/src/adapters/codex.ts
@@ -17,6 +17,7 @@ const CODEX_COMMAND_API = 'command_execution';
const CODEX_FILE_CHANGE_API = 'file_change';
const CODEX_MCP_TOOL_CALL_API = 'mcp_tool_call';
const CODEX_TODO_LIST_API = 'todo_list';
+const CODEX_WEB_SEARCH_API = 'web_search';
const CODEX_USAGE_SETTINGS_URL = 'https://chatgpt.com/codex/settings/usage';
const CODEX_COMMAND_OUTPUT_MAX_LENGTH = 25_000;
@@ -73,6 +74,11 @@ interface CodexMcpToolCallItem extends CodexBaseItem {
tool?: string;
}
+interface CodexWebSearchItem extends CodexBaseItem {
+ action?: unknown;
+ query?: unknown;
+}
+
interface CodexCollabAgentState {
message?: string | null;
status?: string;
@@ -92,7 +98,8 @@ type CodexToolItem =
| CodexCommandExecutionItem
| CodexFileChangeItem
| CodexMcpToolCallItem
- | CodexTodoListItem;
+ | CodexTodoListItem
+ | CodexWebSearchItem;
interface ZonedDateTimeParts {
day: number;
@@ -118,6 +125,9 @@ const isMcpToolCallItem = (item: CodexToolItem): item is CodexMcpToolCallItem =>
const isTodoListItem = (item: CodexToolItem): item is CodexTodoListItem =>
item.type === CODEX_TODO_LIST_API;
+const isWebSearchItem = (item: CodexToolItem): item is CodexWebSearchItem =>
+ item.type === CODEX_WEB_SEARCH_API;
+
const normalizeTodoListItems = (item: CodexTodoListItem) =>
(item.items || [])
.map((todo) => ({
@@ -193,6 +203,35 @@ const getRecordString = (record: Record<string, unknown>, key: string): string |
return typeof value === 'string' && value.trim() ? value : undefined;
};
+const getFirstStringFromArray = (value: unknown): string | undefined => {
+ if (!Array.isArray(value)) return;
+
+ for (const item of value) {
+ if (typeof item === 'string' && item.trim()) return item.trim();
+ }
+};
+
+const getWebSearchActionQuery = (action: Record<string, unknown>): string | undefined =>
+ getRecordString(action, 'query')?.trim() || getFirstStringFromArray(action.queries);
+
+const getWebSearchQuery = (item: CodexWebSearchItem): string | undefined => {
+ if (typeof item.query === 'string' && item.query.trim()) return item.query.trim();
+
+ return isRecord(item.action) ? getWebSearchActionQuery(item.action) : undefined;
+};
+
+const synthesizeWebSearchPluginState = (item: CodexWebSearchItem) => {
+ const query = getWebSearchQuery(item);
+
+ if (item.action === undefined && !query && !item.status) return;
+
+ return {
+ ...(item.action === undefined ? {} : { action: item.action }),
+ ...(query ? { query } : {}),
+ ...(item.status ? { status: item.status } : {}),
+ };
+};
+
const unwrapMcpResultEnvelope = (value: unknown): unknown => {
if (!isRecord(value)) return value;
@@ -368,6 +407,10 @@ const summarizeCollabToolCall = (item: CodexCollabToolCallItem): string => {
return `${toolName} completed.`;
};
+const summarizeWebSearch = (item: CodexWebSearchItem): string => {
+ return `Completed ${item.type}.`;
+};
+
const summarizeFallbackTool = (item: CodexToolItem): string => {
return `Completed ${item.type}.`;
};
@@ -397,6 +440,7 @@ const getToolContent = (item: CodexToolItem, isSuccess: boolean): string => {
if (isFileChangeItem(item)) return summarizeFileChange(item);
if (isMcpToolCallItem(item)) return getMcpResultContent(item);
if (isCollabToolCallItem(item)) return summarizeCollabToolCall(item);
+ if (isWebSearchItem(item)) return summarizeWebSearch(item);
return summarizeFallbackTool(item);
};
@@ -478,7 +522,9 @@ const getToolResultData = (item: CodexToolItem): ToolResultData => {
? synthesizeMcpToolPluginState(item)
: isCollabToolCallItem(item)
? synthesizeCollabToolPluginState(item)
- : undefined;
+ : isWebSearchItem(item)
+ ? synthesizeWebSearchPluginState(item)
+ : undefined;
return {
content: output,