Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(llm-proxy): read the catalog name as a bounded display name (#739)
Alfredo Lopez209816b840dc
diff --git a/codex-llm-proxy/src/codexTransport.ts b/codex-llm-proxy/src/codexTransport.tsindex 94c7ab08b..c94f391ae 100644--- a/codex-llm-proxy/src/codexTransport.ts+++ b/codex-llm-proxy/src/codexTransport.ts@@ -729,6 +729,9 @@ export const CATALOG_LIMITS = {maxBodyBytes: 8 * 1_048_576,maxModels: 256,maxModelIdLength: 128,+ // A longer display name is omitted, never truncated: a stored name is+ // always one the upstream sent.+ maxDisplayNameLength: 256,// control-api stores the window in a Postgres INTEGER column; a larger value// would fail the whole catalog sync, so it is omitted here instead.maxContextWindowTokens: 2_147_483_647,@@ -736,6 +739,17 @@ export const CATALOG_LIMITS = {type CatalogModel = { model: string; displayName?: string; contextWindowTokens?: number }+/**+ * The row's display name by precedence: the camelCase and `title` spellings+ * first, then the `display_name` the Codex catalog sends, then `name`.+ */+function displayNameOf(row: Record<string, unknown>): string | undefined {+ for (const value of [row.displayName, row.title, row.display_name, row.name]) {+ if (typeof value === 'string') return value+ }+ return undefined+}+/*** The upstream row's `context_window`, when it is a positive integer the* catalog store can hold. `max_context_window` is an opt-in extension, not the@@ -819,6 +833,7 @@ function normalizeModels(body: unknown): CatalogModel[] {const models: CatalogModel[] = []let droppedOverlongIds = 0let droppedOverLimit = 0+ let omittedOverlongDisplayNames = 0for (const row of rows) {if (!isPlainObject(row)) continueconst model = String(row.model || row.slug || row.id || '').trim()@@ -831,16 +846,11 @@ function normalizeModels(body: unknown): CatalogModel[] {droppedOverLimit += 1continue}- // The upstream catalog sends `display_name`; the camelCase and `title`- // spellings keep their precedence.- const displayName =- typeof row.displayName === 'string'- ? row.displayName- : typeof row.title === 'string'- ? row.title- : typeof row.display_name === 'string'- ? row.display_name- : undefined+ let displayName = displayNameOf(row)+ if (displayName !== undefined && displayName.length > CATALOG_LIMITS.maxDisplayNameLength) {+ omittedOverlongDisplayNames += 1+ displayName = undefined+ }const contextWindowTokens = contextWindowOf(row)models.push({model,@@ -848,7 +858,7 @@ function normalizeModels(body: unknown): CatalogModel[] {...(contextWindowTokens !== undefined ? { contextWindowTokens } : {}),})}- if (droppedOverlongIds > 0 || droppedOverLimit > 0) {+ if (droppedOverlongIds > 0 || droppedOverLimit > 0 || omittedOverlongDisplayNames > 0) {logger.warn({event: 'codex_catalog_bounded',@@ -856,6 +866,7 @@ function normalizeModels(body: unknown): CatalogModel[] {accepted: models.length,droppedOverlongIds,droppedOverLimit,+ omittedOverlongDisplayNames,},'Codex catalog response exceeded proxy bounds')diff --git a/codex-llm-proxy/test/catalogBounds.test.ts b/codex-llm-proxy/test/catalogBounds.test.tsindex fa15dd5cb..1c19fc1ee 100644--- a/codex-llm-proxy/test/catalogBounds.test.ts+++ b/codex-llm-proxy/test/catalogBounds.test.ts@@ -28,6 +28,7 @@ describe('Codex catalog upstream bounds', () => {maxBodyBytes: 8 * 1_048_576,maxModels: 256,maxModelIdLength: 128,+ maxDisplayNameLength: 256,maxContextWindowTokens: 2_147_483_647,})})diff --git a/grok-llm-proxy/src/grokTransport.ts b/grok-llm-proxy/src/grokTransport.tsindex 691588752..34b6d8d54 100644--- a/grok-llm-proxy/src/grokTransport.ts+++ b/grok-llm-proxy/src/grokTransport.ts@@ -713,6 +713,9 @@ export const CATALOG_LIMITS = {maxBodyBytes: 1_048_576,maxModels: 256,maxModelIdLength: 128,+ // A longer display name is omitted, never truncated: a stored name is+ // always one the upstream sent.+ maxDisplayNameLength: 256,// control-api stores the window in a Postgres INTEGER column; a larger value// would fail the whole catalog sync, so it is omitted here instead.maxContextWindowTokens: 2_147_483_647,@@ -720,6 +723,17 @@ export const CATALOG_LIMITS = {type CatalogModel = { model: string; displayName?: string; contextWindowTokens?: number }+/**+ * The row's display name by precedence: the camelCase and `title` spellings+ * first, then the `name` the Grok catalog row carries.+ */+function displayNameOf(row: Record<string, unknown>): string | undefined {+ for (const value of [row.displayName, row.title, row.name]) {+ if (typeof value === 'string') return value+ }+ return undefined+}+/*** The upstream row's `context_window`, when it is a positive integer the* catalog store can hold. The field name matches the Grok CLI's model cache;@@ -798,6 +812,7 @@ function normalizeModels(body: unknown): CatalogModel[] {const models: CatalogModel[] = []let droppedOverlongIds = 0let droppedOverLimit = 0+ let omittedOverlongDisplayNames = 0for (const row of rows) {if (!isPlainObject(row)) continueconst model = String(row.model || row.slug || row.id || '').trim()@@ -810,12 +825,11 @@ function normalizeModels(body: unknown): CatalogModel[] {droppedOverLimit += 1continue}- const displayName =- typeof row.displayName === 'string'- ? row.displayName- : typeof row.title === 'string'- ? row.title- : undefined+ let displayName = displayNameOf(row)+ if (displayName !== undefined && displayName.length > CATALOG_LIMITS.maxDisplayNameLength) {+ omittedOverlongDisplayNames += 1+ displayName = undefined+ }const contextWindowTokens = contextWindowOf(row)models.push({model,@@ -823,7 +837,7 @@ function normalizeModels(body: unknown): CatalogModel[] {...(contextWindowTokens !== undefined ? { contextWindowTokens } : {}),})}- if (droppedOverlongIds > 0 || droppedOverLimit > 0) {+ if (droppedOverlongIds > 0 || droppedOverLimit > 0 || omittedOverlongDisplayNames > 0) {logger.warn({event: 'grok_catalog_bounded',@@ -831,6 +845,7 @@ function normalizeModels(body: unknown): CatalogModel[] {accepted: models.length,droppedOverlongIds,droppedOverLimit,+ omittedOverlongDisplayNames,},'Grok catalog response exceeded proxy bounds')diff --git a/grok-llm-proxy/test/catalogBounds.test.ts b/grok-llm-proxy/test/catalogBounds.test.tsindex b1dae5c6d..706c6972d 100644--- a/grok-llm-proxy/test/catalogBounds.test.ts+++ b/grok-llm-proxy/test/catalogBounds.test.ts@@ -28,6 +28,7 @@ describe('Grok catalog upstream bounds', () => {maxBodyBytes: 1_048_576,maxModels: 256,maxModelIdLength: 128,+ maxDisplayNameLength: 256,maxContextWindowTokens: 2_147_483_647,})})