fix: wire up OpenAI-compatible provider in scenario/inject/script generation - #53
Open
Darth-Ginger wants to merge 1 commit into
Open
Conversation
…eration Symptom: "AI Generated" scenario creation failed with "AI scenario generation requires an active AI provider configured in the Admin → AI Config panel" even with a valid, connection-tested OpenAI-compatible provider set active. ai-config.ts stores and connection-tests full OpenAI-compatible settings (baseUrl, apiKey, model), but every AI-generation entry point only ever branched on 'anthropic' and 'ollama': - generate-inject.ts: generateScenarioSetup / streamScenarioSetup / generateSingleInject / streamSingleInject (the "AI Generated" creator, called from routes/sessions.ts) - adaptive-inject.ts: generateAdaptiveInject (the "AI-Driven" mode, called from socket/index.ts) and generateAIDebrief (post-session debrief narrative) - generate-script.ts: facilitator script generation (opening/round/ closing scripts) Adds an OpenAI-compatible branch (using the standard /v1/chat/completions endpoint) to each, modeled on the existing Claude/Ollama branches in the same files. Also uses the configured (≥4000-floored) openai.maxTokens budget instead of Claude's tighter hardcoded 768/2048 for setup/inject calls — reasoning models exposed through an OpenAI-compatible endpoint (e.g. Gemini) spend hidden "thinking" tokens out of the same max_tokens budget, so a small budget can be exhausted before any visible JSON is emitted, producing a response that fails validation. Testing: - npx tsc --noEmit — clean - npx vitest run — 5 files / 16 tests passing - Verified live against a self-hosted deployment pointed at Gemini's OpenAI-compatible endpoint: generateScenarioSetup and generateSingleInject both called directly against the running container and returned valid, fully-formed setup/inject JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
"AI Generated" scenario creation failed with:
even with a valid, connection-tested OpenAI-compatible provider set active.
ai-config.tsstores and connection-tests full OpenAI-compatible settings (baseUrl,apiKey,model), but every AI-generation entry point only ever branched onanthropicandollama:generate-inject.ts:generateScenarioSetup/streamScenarioSetup/generateSingleInject/streamSingleInject— the "AI Generated" creator, called fromroutes/sessions.tsadaptive-inject.ts:generateAdaptiveInject— the "AI-Driven" mode, called fromsocket/index.ts— andgenerateAIDebrief(post-session debrief narrative)generate-script.ts: facilitator script generation (opening/round/closing scripts)(
generate-scenario.tshas the same pattern but itsgenerateAIScenariofunction isn't called anywhere — left untouched.)Related to #52, which fixed the same missing-
openai-branch gap in the live-feedback resolver (services/ai/index.ts).Fix
Adds an OpenAI-compatible branch (standard
/v1/chat/completionsendpoint) to each entry point above, modeled on the existing Claude/Ollama branches in the same files.Also switches the setup/inject calls to use the configured (≥4000-floored)
openai.maxTokensbudget instead of Claude's tighter hardcoded768/2048. Reasoning models exposed through an OpenAI-compatible endpoint (e.g. Gemini) spend hidden "thinking" tokens out of the samemax_tokensbudget, so a small budget gets exhausted before any visible JSON is emitted — which fails validation downstream (Missing scenario title) even though the request itself succeeded.Testing
npx tsc --noEmit— cleannpx vitest run— 5 files / 16 tests passinggenerateScenarioSetupandgenerateSingleInjectdirectly against the running container and got back valid, fully-formed setup/inject JSON (confirmed the fix end-to-end, not just a type-check).