Fix background MCP input and add mirror dungeon feedback records
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
// Only send a concise game-state description and explicit permitted choices.
|
||||||
|
// Credentials are supplied in memory or OPENCODE_API_KEY, never stored here.
|
||||||
|
export async function decide(state, criteria, options = {}) {
|
||||||
|
const apiKey = options.apiKey ?? process.env.OPENCODE_API_KEY;
|
||||||
|
if (!apiKey) throw new Error('OPENCODE_API_KEY is required');
|
||||||
|
if (typeof state !== 'string' || !state.trim()) throw new Error('State text is required');
|
||||||
|
if (!criteria || Object.keys(criteria).length < 2) throw new Error('At least two choices are required');
|
||||||
|
const started = performance.now();
|
||||||
|
const response = await fetch('https://opencode.ai/zen/v1/systemone', {
|
||||||
|
method: 'POST',
|
||||||
|
redirect: 'error',
|
||||||
|
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
||||||
|
signal: AbortSignal.timeout(options.timeoutMs ?? 7000),
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: options.model ?? 'jev-1.13-free',
|
||||||
|
state,
|
||||||
|
questions: {
|
||||||
|
action: {
|
||||||
|
type: 'choice',
|
||||||
|
instructions: 'Choose the action that respects the stated user rules and completes the Limbus Company Mirror Dungeon fastest. Use only the supplied choices.',
|
||||||
|
criteria,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error(`Jev HTTP ${response.status}`);
|
||||||
|
const body = await response.json();
|
||||||
|
const answer = body.answers?.action;
|
||||||
|
if (answer?.type !== 'choice' || !Object.hasOwn(criteria, answer.choice)) {
|
||||||
|
throw new Error('Jev returned an unsupported choice');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
choice: answer.choice,
|
||||||
|
confidence: answer.confidence,
|
||||||
|
probabilities: answer.probabilities,
|
||||||
|
latencyMs: Math.round(performance.now() - started),
|
||||||
|
model: body.model,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user