Let complete() accept coerce/preprocess schemas (fix tsc -b build)
The "creatures" alias fix wraps the balance schema in z.preprocess, whose input type is `unknown`. complete()'s `schema?: ZodType<T>` pinned input=output=T, so T inferred as unknown and `res.data.add` failed under tsc -b (project build). Loosen schema input to `ZodType<T, ZodTypeDef, any>` — T stays pinned to the schema output, but coerce/preprocess/transform schemas (input ≠ T) are accepted. Pin the advisor call's type param to BalanceSuggestion, matching the other complete<...> call sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -127,7 +127,7 @@ export function useEncounterAdvisor(campaign: Campaign, encounter: Encounter) {
|
|||||||
|
|
||||||
if (canUseLlm) {
|
if (canUseLlm) {
|
||||||
const prompt = buildBalancePrompt(ctx, { difficulty: current, targetDifficulty: target, candidates });
|
const prompt = buildBalancePrompt(ctx, { difficulty: current, targetDifficulty: target, candidates });
|
||||||
const res = await complete(getLlmConfig(), { system: prompt.system, user: prompt.user, schema: balanceSuggestionSchema });
|
const res = await complete<BalanceSuggestion>(getLlmConfig(), { system: prompt.system, user: prompt.user, schema: balanceSuggestionSchema });
|
||||||
if (res.ok && 'data' in res) {
|
if (res.ok && 'data' in res) {
|
||||||
const valid = res.data.add.filter((a) => candidates.some((c) => c.name === a.name));
|
const valid = res.data.add.filter((a) => candidates.some((c) => c.name === a.name));
|
||||||
if (valid.length) {
|
if (valid.length) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { ZodType } from 'zod';
|
import type { ZodType, ZodTypeDef } from 'zod';
|
||||||
|
|
||||||
export type LlmProvider = 'anthropic' | 'openai-compatible';
|
export type LlmProvider = 'anthropic' | 'openai-compatible';
|
||||||
|
|
||||||
@@ -34,8 +34,10 @@ export interface CompleteOptions<T = unknown> {
|
|||||||
system: string;
|
system: string;
|
||||||
/** User message. */
|
/** User message. */
|
||||||
user: string;
|
user: string;
|
||||||
/** When provided, structured JSON output is requested and validated against it. */
|
/** When provided, structured JSON output is requested and validated against it.
|
||||||
schema?: ZodType<T>;
|
* Input is left open (`any`) so schemas using coerce/preprocess/transform — whose
|
||||||
|
* parsed input type differs from T — are accepted; T is pinned to the output. */
|
||||||
|
schema?: ZodType<T, ZodTypeDef, any>;
|
||||||
/** A short name describing the JSON shape (used by providers that require it). */
|
/** A short name describing the JSON shape (used by providers that require it). */
|
||||||
schemaName?: string;
|
schemaName?: string;
|
||||||
signal?: AbortSignal;
|
signal?: AbortSignal;
|
||||||
|
|||||||
Reference in New Issue
Block a user