Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ai): enable OpenRouter query expansion (#3499)
cybernaut64046920744dd882
diff --git a/TODOS.md b/TODOS.mdindex 9d548b71c1..6afeb95a88 100644--- a/TODOS.md+++ b/TODOS.md@@ -82,17 +82,20 @@ Deferred from the provider-agnostic plumbing wave (#1249/#1250/#1292/#2271/#2209Plan + review trail at `~/.claude/plans/system-instruction-you-are-working-keen-newell.md`.The eng-review + Codex outside-voice narrowed the wave to these deferrals:-- [ ] **P2 — Capability-aware query expansion on OpenAI-compat providers (#2372).**+- [x] **P2 — Capability-aware query expansion on OpenAI-compat providers (#2372).**Expansion only runs for recipes that declare an `expansion` touchpoint, and only thenative providers (anthropic/openai/google) do. To make expansion work onlitellm/openrouter/groq/together/deepseek you must ADD expansion touchpoints to thosechat-capable recipes AND add a `generateObject`→`generateText` capability fallback forbackends without strict structured outputs. Feature-shaped; overlaps the generalOpenAI-compat proxy story (`docs/designs/COMMUNITY_IDEAS.md`). Community PR #2373 is a- starting point. Where: `src/core/ai/gateway.ts:expand`, recipe files, `types.ts` (ExpansionTouchpoint).-- [ ] **P2 — LiteLLM as a chat/expansion backend.** `litellm-proxy` declares ONLY an+ starting point. Implemented by #2373 plus the DeepSeek/Groq/Together recipe wave,+ LiteLLM chat/expansion support, and the OpenRouter expansion touchpoint. Where:+ `src/core/ai/gateway.ts:expand`, recipe files, `types.ts` (ExpansionTouchpoint).+- [x] **P2 — LiteLLM as a chat/expansion backend.** `litellm-proxy` declares ONLY anembedding touchpoint, so `think`/chat on LiteLLM is dead. Add chat (and expansion) so a- LiteLLM proxy is a full LLM backend, not embedding-only. The general OpenAI-compat proxy story.+ LiteLLM proxy is a full LLM backend, not embedding-only. Implemented by #2208.+ The general OpenAI-compat proxy story.- [ ] **P3 — Per-model embedding dims metadata on `EmbeddingTouchpoint`.** `default_dims`is recipe-wide, so a recipe (ollama) can't carry different native dims per model. Thiswave added the modern ollama model NAMES + a `trust_custom_dims` passthrough (user suppliesdiff --git a/src/core/ai/recipes/openrouter.ts b/src/core/ai/recipes/openrouter.tsindex 4e4502aaa3..221041727b 100644--- a/src/core/ai/recipes/openrouter.ts+++ b/src/core/ai/recipes/openrouter.ts@@ -180,6 +180,17 @@ export const openrouter: Recipe = {// to pre-split batches, NOT per-input. Per-input is enforced upstream.max_batch_tokens: 300_000,},+ // Expansion uses the same routed OpenAI-compatible language-model endpoint+ // as chat. Keep a small cheap/fast advisory set; the openai-compat tier+ // still accepts any user-configured OpenRouter provider/model ID.+ expansion: {+ models: [+ 'anthropic/claude-haiku-4.5',+ 'google/gemini-3-flash-preview',+ 'deepseek/deepseek-chat',+ ],+ price_last_verified: '2026-05-20',+ },chat: {// Curated entry points (verified against OR's catalog 2026-05-20). The// openai-compat tier does NOT enforce this list at runtime — users candiff --git a/test/ai/gateway.test.ts b/test/ai/gateway.test.tsindex 10aaceeea6..730cc8b71f 100644--- a/test/ai/gateway.test.ts+++ b/test/ai/gateway.test.ts@@ -114,11 +114,12 @@ describe('gateway.isAvailable (silent-drop regression surface)', () => {// #1135 — an explicit expansion_model pointed at a chat-capable// OpenAI-compatible provider used to silently yield no expansion because// the recipe declared no expansion touchpoint.- test('expansion available for chat-capable openai-compat providers (deepseek/groq/together)', () => {+ test('expansion available for chat-capable openai-compat providers (deepseek/groq/together/openrouter)', () => {const cases: Array<[string, Record<string, string>]> = [['deepseek:deepseek-chat', { DEEPSEEK_API_KEY: 'fake' }],['groq:llama-3.1-8b-instant', { GROQ_API_KEY: 'fake' }],['together:meta-llama/Llama-3.3-70B-Instruct-Turbo', { TOGETHER_API_KEY: 'fake' }],+ ['openrouter:google/gemini-3-flash-preview', { OPENROUTER_API_KEY: 'fake' }],];for (const [model, env] of cases) {resetGateway();diff --git a/test/ai/recipe-openrouter.test.ts b/test/ai/recipe-openrouter.test.tsindex 6323c9bd70..1793a49653 100644--- a/test/ai/recipe-openrouter.test.ts+++ b/test/ai/recipe-openrouter.test.ts@@ -65,6 +65,18 @@ describe('recipe: openrouter', () => {).not.toThrow();});+ test('3b. expansion reuses routed chat models and accepts arbitrary provider/model IDs', () => {+ const r = getRecipe('openrouter')!;+ expect(r.touchpoints.expansion).toBeDefined();+ expect(r.touchpoints.expansion!.models.length).toBeGreaterThanOrEqual(3);+ expect(() =>+ assertTouchpoint(r, 'expansion', 'some/provider-model'),+ ).not.toThrow();+ expect(() =>+ assertTouchpoint(r, 'expansion', 'meta-llama/llama-future-2030'),+ ).not.toThrow();+ });+test('4. chat models list — every entry matches provider/model shape (D5 regression)', () => {// Codex correction: pinning specific slugs creates false confidence (the// list is advisory; OR's catalog churns). The shape test catches the