Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166/** Advisor tool parameter schema and argument normalization. @module */
import { type TObject, type TOptional, type TString, Type,} from 'typebox';import type { AdvisorToolParams, } from './types.ts';
//region Schema
/** TypeBox object builder aliased to satisfy constructor-style lint. */const typeObject = Type.Object;
/** TypeBox optional builder aliased to satisfy constructor-style lint. */const typeOptional = Type.Optional;
/** TypeBox string builder aliased to satisfy constructor-style lint. */const typeString = Type.String;
/** TypeBox schema for Advisor tool parameters. */export const AdvisorToolParametersSchema: TObject<{ model: TOptional<TString>; question: TOptional<TString>;}> = typeObject( { model: typeOptional(typeString({ description: 'Optional scoped model slug. Use provider/model for canonical slugs. Empty params select the highest expected-cost non-current scoped model when possible.', },),), question: typeOptional(typeString({ description: 'Optional focused question or review request for Advisor to answer using the conversation context.', },),), }, { additionalProperties: false, },);
//endregion Schema
//region Argument normalization
/** Normalize optional model argument. @param rawModel - raw model value @returns model param when non-blank */function normalizeModelArgument( rawModel: unknown,): Pick<AdvisorToolParams, 'model'> { if ((typeof rawModel) !== 'string') return {}; if (rawModel.trim() === '') return {}; return { model: rawModel, };}
/** Normalize optional focused-question argument. @param rawQuestion - raw focused-question value @returns question param when non-blank */function normalizeQuestionArgument( rawQuestion: unknown,): Pick<AdvisorToolParams, 'question'> { if ((typeof rawQuestion) !== 'string') return {}; /** Trimmed focused question text. */ const question = rawQuestion.trim(); if (question === '') return {}; return { question, };}
/** Normalize raw tool arguments before TypeBox validation. @param args - raw tool-call arguments from the model @returns normalized Advisor params @throws when non-empty args are malformed @example ```typescript prepareAdvisorArguments('anthropic/claude-sonnet'); ``` */export function prepareAdvisorArguments( args: unknown,): AdvisorToolParams { if ((args === undefined) || (args === null)) return {}; if ((typeof args) === 'string') return args.trim() === '' ? {} : { model: args, }; if ((typeof args) !== 'object') throw new Error('advisor: arguments must be an object with optional model field',);
/** Unknown fields not accepted by public tool contract. */ const extraKeys = Object .keys(args,) .filter(function isExtraKey(key,) { return (key !== 'model') && (key !== 'question'); },); if (extraKeys.length > 0) throw new Error(`advisor: unsupported argument fields: ${extraKeys.join(', ',)}`,);
/** Raw model value read after object narrowing. */ const rawModel = 'model' in args ? args.model : undefined; /** Raw question value read after object narrowing. */ const rawQuestion = 'question' in args ? args.question : undefined;
if ((rawModel !== undefined) && ((typeof rawModel) !== 'string')) throw new Error('advisor: model must be a string when provided',); if ((rawQuestion !== undefined) && ((typeof rawQuestion) !== 'string')) throw new Error('advisor: question must be a string when provided',);
/** Model parameter carried through after existing string compatibility rules. */ const normalizedModel = normalizeModelArgument(rawModel,); /** Trimmed focused question, omitted when blank. */ const normalizedQuestion = normalizeQuestionArgument(rawQuestion,);
return { ...normalizedModel, ...normalizedQuestion, };}
//endregion Argument normalization