fix(codex): keep element types through the array coercion, model mcpAdd as a union

This commit is contained in:
2026-09-08 20:31:10 +07:00
parent 8021e569f2
commit e38dc5555c
+19 -15
View File
@@ -1703,27 +1703,31 @@ export const api = {
* Coerces the CLI's JSON output (which may be an object) to an array. * Coerces the CLI's JSON output (which may be an object) to an array.
* @returns `{ mcp }` — {@link CodexMcpServer} items. * @returns `{ mcp }` — {@link CodexMcpServer} items.
*/ */
mcp: async () => { mcp: async (): Promise<{ mcp: CodexMcpServer[] }> => {
const res = await request<{ mcp: unknown }>("/codex-config/mcp"); const res = await request<{ mcp: unknown }>("/codex-config/mcp");
return { mcp: Array.isArray(res.mcp) ? res.mcp : [] }; return { mcp: Array.isArray(res.mcp) ? (res.mcp as CodexMcpServer[]) : [] };
}, },
/** /**
* GET /api/codex-config/plugins - installed plugins from the codex CLI. * GET /api/codex-config/plugins - installed plugins from the codex CLI.
* Coerces the CLI's JSON output (which may be an object) to an array. * Coerces the CLI's JSON output (which may be an object) to an array.
* @returns `{ plugins }` — {@link CodexPlugin} items. * @returns `{ plugins }` — {@link CodexPlugin} items.
*/ */
plugins: async () => { plugins: async (): Promise<{ plugins: CodexPlugin[] }> => {
const res = await request<{ plugins: unknown }>("/codex-config/plugins"); const res = await request<{ plugins: unknown }>("/codex-config/plugins");
return { plugins: Array.isArray(res.plugins) ? res.plugins : [] }; return { plugins: Array.isArray(res.plugins) ? (res.plugins as CodexPlugin[]) : [] };
}, },
/** /**
* GET /api/codex-config/marketplaces - registered marketplaces from the codex CLI. * GET /api/codex-config/marketplaces - registered marketplaces from the codex CLI.
* Coerces the CLI's JSON output (which may be an object) to an array. * Coerces the CLI's JSON output (which may be an object) to an array.
* @returns `{ marketplaces }` — {@link CodexMarketplace} items. * @returns `{ marketplaces }` — {@link CodexMarketplace} items.
*/ */
marketplaces: async () => { marketplaces: async (): Promise<{ marketplaces: CodexMarketplace[] }> => {
const res = await request<{ marketplaces: unknown }>("/codex-config/marketplaces"); const res = await request<{ marketplaces: unknown }>("/codex-config/marketplaces");
return { marketplaces: Array.isArray(res.marketplaces) ? res.marketplaces : [] }; return {
marketplaces: Array.isArray(res.marketplaces)
? (res.marketplaces as CodexMarketplace[])
: [],
};
}, },
/** /**
* POST /api/codex-config/mcp/add - add an MCP server via the `codex` CLI. * POST /api/codex-config/mcp/add - add an MCP server via the `codex` CLI.
@@ -3006,15 +3010,15 @@ export interface CodexMarketplace {
[key: string]: unknown; [key: string]: unknown;
} }
/** Arguments for POST /api/codex-config/mcp/add. */ /**
export interface CodexMcpAddArgs { * Arguments for POST /api/codex-config/mcp/add. A union, not one optional-heavy
name: string; * shape: `codex mcp add` takes either a URL or a command and rejects both or
url?: string; * neither, and `env` is stdio-only. Modelling that here turns three of the
bearerTokenEnvVar?: string; * server's `EBADARG` responses into compile errors.
command?: string; */
args?: string[]; export type CodexMcpAddArgs =
env?: Record<string, string>; | { name: string; url: string; bearerTokenEnvVar?: string }
} | { name: string; command: string; args?: string[]; env?: Record<string, string> };
/** Arguments for POST /api/codex-config/plugins/action. */ /** Arguments for POST /api/codex-config/plugins/action. */
export interface CodexPluginActionArgs { export interface CodexPluginActionArgs {