okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b06ea51b
main
1/** 2* OpenRouter models: the Reasoning menu works when OpenRouter's own model list says the model can think, and the chosen effort reaches 3* OpenRouter in its own words (`reasoning: { effort }`). The server is a mock; no key exists and none is stored. 4*/ 5import test from 'node:test' ; 6import assert from 'node:assert/strict' ; 7import { mkdtempSync , mkdirSync , rmSync } from 'node:fs' ; 8import { tmpdir } from 'node:os' ; 9import { join } from 'node:path' ; 10import { startScriptedWorker } from './helpers/scripted-worker.mjs' ; 11import { createAgentBridge } from '../server/agent/agent-bridge.mjs' ; 12import { resolveHarness } from '../server/agent/harness-runtime.mjs' ; 13import { buildProfile , OPENROUTER_EFFORTS } from '../server/agent/profile.mjs' ; 14import { createModelProviders } from '../server/model-providers.mjs' ; 15import { createVisionProbe , modelSupportsReasoning , readsPicturesByDefault } from '../server/vision-probe.mjs' ; 16 17const HARNESS = process . env . STRATA_HARNESS_DIR ; 18const skip = ! HARNESS || ! resolveHarness ({ env :process . env }). ok ?'STRATA_HARNESS_DIR is not set to a built Harness' :false ; 19 20const LIST = { data :[ 21{ id :'deepseek/deepseek-v3.2' , name :'DeepSeek: DeepSeek V3.2' , context_length :163840 , architecture :{ input_modalities :[ 'text' ] }, supported_parameters :[ 'tools' , 'reasoning' , 'include_reasoning' , 'temperature' ] }, 22{ id :'meta/plain' , name :'Plain' , context_length :8192 , architecture :{ input_modalities :[ 'text' , 'image' ] }, supported_parameters :[ 'tools' , 'temperature' ] }, 23{ id :'unlisted/x' , name :'No parameters listed' }, 24] }; 25 26test ( 'a model list row says whether the model can think' , () => { 27assert . equal ( modelSupportsReasoning ( LIST . data [ 0 ]), true ); 28assert . equal ( modelSupportsReasoning ({ supported_parameters :[ 'include_reasoning' ] }), true ); 29assert . equal ( modelSupportsReasoning ( LIST . data [ 1 ]), false ); 30assert . equal ( modelSupportsReasoning ( LIST . data [ 2 ]), null ); 31}); 32 33test ( 'fetching the model list keeps the reasoning answer, and a saved connection keeps it' , async t => { 34const directory = mkdtempSync ( join ( tmpdir (), 'strata-or-' )); t . after (() => rmSync ( directory , { recursive :true , force :true })); 35const fetchImpl = async () => ({ ok :true , status :200 , json :async () => LIST , body :{ cancel () {} } }); 36const service = createModelProviders ({ directory, fetchImpl}); 37const found = await service . discover ({ kind :'provider' , provider :'openrouter' , apiKey :'mock-key' , models :[] }); 38assert . deepEqual ( found . models . map ( m => [ m . id , m . reasoning ]), [[ 'meta/plain' , false ], [ 'deepseek/deepseek-v3.2' , true ], [ 'unlisted/x' , null ]]. sort (( a , b ) => a [ 0 ]. localeCompare ( b [ 0 ])). sort (( x , y ) => found . models . findIndex ( m => m . id === x [ 0 ]) - found . models . findIndex ( m => m . id === y [ 0 ]))); 39const saved = service . save ({ kind :'provider' , provider :'openrouter' , apiKey :'mock-key' , models :found . models }). connections [ 0 ]; 40assert . equal ( saved . models . find ( m => m . id === 'deepseek/deepseek-v3.2' ). reasoning , true ); 41assert . equal ( createModelProviders ({ directory}). list (). connections [ 0 ]. models . find ( m => m . id === 'meta/plain' ). reasoning , false ); 42}); 43 44test ( 'the probe asks the list once for pictures and thinking, and pictures are on unless something says no' , async () => { 45const probe = createVisionProbe ({ fetcher :async () => ({ ok :true , json :async () => LIST }) }); 46const conn = { id :'c' , baseUrl :'https://openrouter.ai/api/v1' , apiKey :'k' }; 47assert . equal ( await probe . check ( conn , 'deepseek/deepseek-v3.2' ), false ); 48assert . equal ( probe . knownThinks ( conn , 'deepseek/deepseek-v3.2' ), true ); 49assert . equal ( await probe . check ( conn , 'unlisted/x' ), null ); 50assert . equal ( readsPicturesByDefault ({}, null ), true , 'unknown: on' ); 51assert . equal ( readsPicturesByDefault ({ vision :false }, true ), false , 'the person switched it off' ); 52assert . equal ( readsPicturesByDefault ({}, false ), false , 'the server says no' ); 53}); 54 55test ( 'the profile gives a thinking model the OpenRouter efforts and the OpenRouter format, even at another address' , () => { 56const conn = { id :'or' , name :'OpenRouter' , provider :'openrouter' , baseUrl :'http://127.0.0.1:1/v1' , protocol :'openai-chat' , apiKey :'k' , models :[{ id :'a/think' , reasoning :true }, { id :'a/plain' , reasoning :false }, { id :'a/unknown' }] }; 57const entries = JSON . parse ( buildProfile ({ local :[], connections :[ conn ] }). patch . split ( '\n' ). slice ( 1 ). join ( '\n' )); 58const provider = Object . values ( entries . find ( e => e . id === 'llm-pi-ai' ). config . providers )[ 0 ]; 59assert . equal ( provider . compat . thinkingFormat , 'openrouter' ); 60const [ think , plain , unknown ] = provider . models ; 61assert . deepEqual ( think . reasoningEfforts , OPENROUTER_EFFORTS ); assert . equal ( think . reasoning , true ); 62assert . equal ( plain . reasoning , undefined ); assert . equal ( unknown . reasoning , undefined ); 63assert . deepEqual ( unknown . input , [ 'text' , 'image' ], 'pictures on by default' ); 64}); 65 66test ( 'the real Harness: the chosen effort is sent to OpenRouter as reasoning.effort' , { skip}, async t => { 67const worker = await startScriptedWorker ({ model :'a/think' }); 68const dir = mkdtempSync ( join ( tmpdir (), 'strata-or-run-' )); const ws = join ( dir , 'ws' ); mkdirSync ( ws , { recursive :true }); 69const bridge = createAgentBridge ({ dataDir :dir , env :process . env , startTimeoutMs :90_000 , localInstances :() => [], connections :() => [{ id :'or-conn-1' , name :'OpenRouter' , provider :'openrouter' , baseUrl :worker . url , protocol :'openai-chat' , apiKey :'mock' , models :[{ id :'a/think' , name :'Think' , contextMax :32768 , reasoning :true }] }] }); 70t . after ( async () => { await bridge . close (); await worker . close (); try { rmSync ( dir , { recursive :true , force :true , maxRetries :3 }); } catch { /* best effort */ } }); 71const seen = {}; 72for ( const level of [ 'High' , 'Max' , 'Off' ]) { 73await bridge . runTurn ({ chatId :`or- ${ level } ` , message :'SCRIPT:echo hi' , workspacePath :ws , mode :'bypass' , thinking :level , choice :{ connectionId :'or-conn-1' , modelId :'a/think' }, onFrame :() => {} }); 74seen [ level ] = worker . requests . at ( - 1 ). params . reasoning ; 75} 76assert . deepEqual ( seen , { High :{ effort :'high' }, Max :{ effort :'xhigh' }, Off :{ effort :'none' } }); 77});