- 重命名 ContentRules→ContentExpectations, KeyValueExpect→KeyedExpectations - 新增 Raw/Resolved 双层模型:resolve 阶段物化为执行计划,store 持久化 Raw 快照 - HTTP body 按需读取:status/headers 失败或无 body expectation 时不读取 body - 新增 displayValueExpectation() 解包 failure.expected 用户可读展示 - 修复 checkEarlyTimeout 独立 lte/lt 检查,修复 KeyedExpectations JSON Schema - 新增 expect/value.ts(resolve/check/display)、keyed.ts、content.ts、headers.ts、status.ts - 删除旧 normalize.ts/matcher.ts/validate-matcher.ts/key-value.ts - 更新 DEVELOPMENT.md:expect 五层管线表、displayValueExpectation、1.7↔1.10 交叉引用 - 同步 13 个 main specs,归档 refactor-expect-type-model 变更(62/62 tasks)
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { Type } from "@sinclair/typebox";
|
|
|
|
import type { CheckerSchemas } from "../types";
|
|
|
|
import {
|
|
createRawContentExpectationsSchema,
|
|
createRawKeyedExpectationsSchema,
|
|
createRawValueExpectationSchema,
|
|
statusCodePatternSchema,
|
|
stringMapSchema,
|
|
} from "../../schema/fragments";
|
|
|
|
function createLlmOptionsSchema() {
|
|
return Type.Object(
|
|
{
|
|
frequencyPenalty: Type.Optional(Type.Number()),
|
|
maxOutputTokens: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
presencePenalty: Type.Optional(Type.Number()),
|
|
seed: Type.Optional(Type.Number()),
|
|
stopSequences: Type.Optional(Type.Array(Type.String())),
|
|
temperature: Type.Optional(Type.Number()),
|
|
topK: Type.Optional(Type.Number()),
|
|
topP: Type.Optional(Type.Number()),
|
|
},
|
|
{ additionalProperties: false },
|
|
);
|
|
}
|
|
|
|
export const llmCheckerSchemas: CheckerSchemas = {
|
|
config: Type.Object(
|
|
{
|
|
authToken: Type.Optional(Type.String()),
|
|
headers: Type.Optional(stringMapSchema),
|
|
ignoreSSL: Type.Optional(Type.Boolean()),
|
|
key: Type.Optional(Type.String()),
|
|
mode: Type.Optional(Type.Union([Type.Literal("http"), Type.Literal("stream")])),
|
|
model: Type.String({ minLength: 1 }),
|
|
options: Type.Optional(createLlmOptionsSchema()),
|
|
prompt: Type.String({ minLength: 1 }),
|
|
provider: Type.Union([Type.Literal("openai"), Type.Literal("openai-responses"), Type.Literal("anthropic")]),
|
|
providerOptions: Type.Optional(Type.Record(Type.String(), Type.Object({}, { additionalProperties: true }))),
|
|
url: Type.String({ minLength: 1 }),
|
|
},
|
|
{ additionalProperties: false },
|
|
),
|
|
defaults: Type.Object(
|
|
{
|
|
headers: Type.Optional(stringMapSchema),
|
|
ignoreSSL: Type.Optional(Type.Boolean()),
|
|
mode: Type.Optional(Type.Union([Type.Literal("http"), Type.Literal("stream")])),
|
|
options: Type.Optional(createLlmOptionsSchema()),
|
|
providerOptions: Type.Optional(Type.Record(Type.String(), Type.Object({}, { additionalProperties: true }))),
|
|
},
|
|
{ additionalProperties: false },
|
|
),
|
|
expect: Type.Object(
|
|
{
|
|
durationMs: Type.Optional(createRawValueExpectationSchema()),
|
|
finishReason: Type.Optional(createRawValueExpectationSchema()),
|
|
headers: Type.Optional(createRawKeyedExpectationsSchema()),
|
|
output: Type.Optional(createRawContentExpectationsSchema()),
|
|
rawFinishReason: Type.Optional(createRawValueExpectationSchema()),
|
|
status: Type.Optional(Type.Array(statusCodePatternSchema)),
|
|
stream: Type.Optional(
|
|
Type.Object(
|
|
{
|
|
completed: Type.Optional(Type.Boolean()),
|
|
firstTokenMs: Type.Optional(createRawValueExpectationSchema()),
|
|
},
|
|
{ additionalProperties: false },
|
|
),
|
|
),
|
|
usage: Type.Optional(
|
|
Type.Object(
|
|
{
|
|
inputTokens: Type.Optional(createRawValueExpectationSchema()),
|
|
outputTokens: Type.Optional(createRawValueExpectationSchema()),
|
|
totalTokens: Type.Optional(createRawValueExpectationSchema()),
|
|
},
|
|
{ additionalProperties: false },
|
|
),
|
|
),
|
|
},
|
|
{ additionalProperties: false },
|
|
),
|
|
};
|