MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / normalizeClassifierInput

Function normalizeClassifierInput

packages/auto-routing-contracts/src/normalize.ts:89–139  ·  view source on GitHub ↗
(
  apiKind: ClassifierApiKind,
  body: unknown,
  overrides?: NormalizeOverrides
)

Source from the content-addressed store, hash-verified

87 'postgres',
88 'postgresql',
89 'private',
90 'public',
91 'redis',
92 'root',
93 'secret',
94 'service',
95 'session',
96 'signing',
97 'sql',
98 'subscription',
99];
100// A qualifier only counts when it ends immediately before a credential word, so
101// the scan before each occurrence never needs more than the longest qualifier.
102const MAX_QUALIFIER_LENGTH = Math.max(...SENSITIVE_KEY_QUALIFIERS.map(q => q.length));
103// These words also begin common English words, so they count only as an exact
104// token or a qualified occurrence, not at any token start.
105const TOKEN_START_EXCLUDED_WORDS: Record<string, true> = { pass: true };
106// Content-part `type` values that carry a tool/function result rather than text.
107const TOOL_RESULT_CONTENT_TYPES: ReadonlySet<string> = new Set([
108 'function_call_output',
109 'tool_call_output',
110 'tool_result',
111]);
112// The subset whose result text lives under `output`; the rest use `content`.
113const OUTPUT_KEYED_RESULT_TYPES: ReadonlySet<string> = new Set([
114 'function_call_output',
115 'tool_call_output',
116]);
117function isToolResultContentType(type: string): boolean {
118 return TOOL_RESULT_CONTENT_TYPES.has(type);
119}
120function isOutputKeyedResultType(type: string): boolean {
121 return OUTPUT_KEYED_RESULT_TYPES.has(type);
122}
123
124export type ClassifierApiKind = NormalizedClassifierInput['apiKind'];
125
126const modelSchema = z.string().trim().min(1);
127const messageSchema = z.looseObject({
128 role: z.string(),
129 content: z.unknown().optional(),
130});
131
132const commonBodySchema = {
133 model: modelSchema,
134 stream: z.boolean().optional(),
135 provider: z.unknown().optional(),
136 providerOptions: z.unknown().optional(),
137 tools: z.array(z.unknown()).optional(),
138};
139
140const chatCompletionBodySchema = z.looseObject({
141 ...commonBodySchema,
142 messages: z.array(messageSchema),

Callers 2

normalize.test.tsFile · 0.90
buildDecidePayloadFunction · 0.90

Calls 6

firstPromptPrefixFunction · 0.85
commonFieldsFunction · 0.85
inputToMessagesFunction · 0.85
textPrefixFunction · 0.85
messageCountFunction · 0.85

Tested by

no test coverage detected