@effect-agent/ai-decision 0.1.0-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/DecisionModel-BQpmPcHb.mjs +96 -0
- package/dist/DecisionModel-BQpmPcHb.mjs.map +1 -0
- package/dist/DecisionModel.d.mts +37 -0
- package/dist/DecisionModel.mjs +3 -0
- package/dist/DecisionQuery.d.mts +59 -0
- package/dist/DecisionQuery.mjs +48 -0
- package/dist/DecisionQuery.mjs.map +1 -0
- package/dist/DecisionSchema.d.mts +313 -0
- package/dist/DecisionSchema.mjs +177 -0
- package/dist/DecisionSchema.mjs.map +1 -0
- package/dist/DecisionSet.d.mts +27 -0
- package/dist/DecisionSet.mjs +20 -0
- package/dist/DecisionSet.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +1 -0
- package/src/DecisionModel.ts +144 -0
- package/src/DecisionQuery.ts +56 -0
- package/src/DecisionSchema.ts +295 -0
- package/src/DecisionSet.ts +36 -0
- package/src/index.ts +4 -0
- package/src/internal/schema.ts +98 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @effect-agent/ai-decision
|
|
2
|
+
|
|
3
|
+
Ask typed questions about application state. A `DecisionSet` defines the input and questions;
|
|
4
|
+
a `DecisionModel` evaluates them through a provider. Your application owns thresholds,
|
|
5
|
+
routing, and side effects.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
input + DecisionSet → DecisionModel → typed answers → application action
|
|
9
|
+
↑
|
|
10
|
+
provider Layer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { DecisionModel, DecisionQuery, DecisionSet } from "@effect-agent/ai-decision";
|
|
15
|
+
import { Effect, Schema } from "effect";
|
|
16
|
+
|
|
17
|
+
const TicketAssessment = DecisionSet.make({
|
|
18
|
+
input: Schema.Struct({ message: Schema.String }),
|
|
19
|
+
questions: {
|
|
20
|
+
department: DecisionQuery.choice({
|
|
21
|
+
instructions: "Which team should handle this ticket?",
|
|
22
|
+
options: { billing: "Payments and refunds", technical: "Bugs and outages" },
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const assess = Effect.gen(function* () {
|
|
28
|
+
const model = yield* DecisionModel.DecisionModel;
|
|
29
|
+
const { answers } = yield* model.evaluate(TicketAssessment, {
|
|
30
|
+
message: "Please refund my duplicate charge.",
|
|
31
|
+
});
|
|
32
|
+
return answers.department.choice; // "billing" | "technical"
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Supply a provider Layer such as `TypeSafeDecisionModel.model("jev-latest")` from
|
|
37
|
+
[`@effect-agent/ai-typesafe`](../ai-typesafe). The [complete example](../ai-typesafe/examples/decision.ts)
|
|
38
|
+
includes provider setup and an application state transition.
|
|
39
|
+
|
|
40
|
+
Use `choice` for named alternatives, `score` for ordered levels, and `probability` for a yes/no
|
|
41
|
+
estimate. Questions in a set evaluate independently against the same schema-encoded input.
|
|
42
|
+
Only include input the provider should receive. Returned probabilities are evidence for your
|
|
43
|
+
application's policy, not authorization to act.
|
|
44
|
+
|
|
45
|
+
Read the [guide](https://effect-agent.com/guide/tools#decision-transitions) for the mental model
|
|
46
|
+
and the [reference](https://effect-agent.com/reference/decision-models) for query options,
|
|
47
|
+
results, errors, and provider behavior.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { ChoiceAnswer, Content, EvaluateRequest, EvaluateResponse, Probability, ProbabilityAnswer, ScoreAnswer } from "./DecisionSchema.mjs";
|
|
3
|
+
import { Context, Effect, Schema } from "effect";
|
|
4
|
+
import { AiError } from "effect/unstable/ai";
|
|
5
|
+
import * as Schema$1 from "effect/Schema";
|
|
6
|
+
//#region src/internal/schema.ts
|
|
7
|
+
const tolerance = 1e-6;
|
|
8
|
+
const probabilitySum = Schema$1.makeFilter((probabilities) => Math.abs(Object.values(probabilities).reduce((sum, value) => sum + value, 0) - 1) <= tolerance, { expected: "probabilities summing to 1 (within 1e-6)" });
|
|
9
|
+
const distribution = (keys, sumCheck = probabilitySum) => Schema$1.Record(Schema$1.Literals(keys), Probability).check(sumCheck);
|
|
10
|
+
const answerFor = (question, choiceProbabilitySum) => {
|
|
11
|
+
switch (question.type) {
|
|
12
|
+
case "choice": {
|
|
13
|
+
const keys = Object.keys(question.criteria);
|
|
14
|
+
return Schema$1.Struct({
|
|
15
|
+
...ChoiceAnswer.fields,
|
|
16
|
+
choice: Schema$1.Literals(keys),
|
|
17
|
+
probabilities: distribution(keys, choiceProbabilitySum)
|
|
18
|
+
}).check(Schema$1.makeFilter(({ choice, probabilities }) => Object.values(probabilities).every((value) => value <= probabilities[choice]), { expected: "a highest-probability choice" }));
|
|
19
|
+
}
|
|
20
|
+
case "score": {
|
|
21
|
+
const maxLevel = question.criteria.length - 1;
|
|
22
|
+
const levels = question.criteria.map((description, index) => [String(index), description]);
|
|
23
|
+
return Schema$1.Struct({
|
|
24
|
+
...ScoreAnswer.fields,
|
|
25
|
+
score: Schema$1.Finite.check(Schema$1.isBetween({
|
|
26
|
+
minimum: 0,
|
|
27
|
+
maximum: maxLevel
|
|
28
|
+
})),
|
|
29
|
+
legend: Schema$1.Struct(Object.fromEntries(levels.map(([key, description]) => [key, Schema$1.Literal(description)]))),
|
|
30
|
+
probabilities: distribution(levels.map(([key]) => key))
|
|
31
|
+
}).check(Schema$1.makeFilter(({ score, probabilities }) => Math.abs(score - Object.entries(probabilities).reduce((sum, [level, probability]) => sum + Number(level) * probability, 0)) <= tolerance * Math.max(1, maxLevel), { expected: "the probability-weighted score (within 1e-6 per level)" }));
|
|
32
|
+
}
|
|
33
|
+
case "probability": return ProbabilityAnswer;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function responseFor(questions, choiceProbabilitySum) {
|
|
37
|
+
return Schema$1.Struct({
|
|
38
|
+
...EvaluateResponse.fields,
|
|
39
|
+
answers: Schema$1.Struct(Object.fromEntries(Object.entries(questions).map(([id, question]) => [id, answerFor(question, choiceProbabilitySum)])))
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/DecisionModel.ts
|
|
44
|
+
var DecisionModel_exports = /* @__PURE__ */ __exportAll({
|
|
45
|
+
DecisionModel: () => DecisionModel,
|
|
46
|
+
make: () => make
|
|
47
|
+
});
|
|
48
|
+
/** A decision provider, independent of the agent's generative LanguageModel. */
|
|
49
|
+
var DecisionModel = class extends Context.Service()("@effect-agent/ai-decision/DecisionModel") {};
|
|
50
|
+
/**
|
|
51
|
+
* Construct a provider with request-derived response validation. Capture dependencies once;
|
|
52
|
+
* resources acquired by evaluate close per call. Invalid data fails with native AiError.
|
|
53
|
+
* Defects and interruption propagate. There are no implicit retries, deadlines, confidence
|
|
54
|
+
* thresholds, or transitions. Usage is returned to the caller, not charged to an agent Run.
|
|
55
|
+
*/
|
|
56
|
+
const make = Effect.fnUntraced(function* (options) {
|
|
57
|
+
const services = yield* Effect.context();
|
|
58
|
+
const evaluateRequest = Effect.fn("DecisionModel.evaluate")(function* (request) {
|
|
59
|
+
const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(EvaluateRequest))(request).pipe(Effect.mapError(() => new AiError.AiError({
|
|
60
|
+
module: "DecisionModel",
|
|
61
|
+
method: "evaluate",
|
|
62
|
+
reason: new AiError.InvalidRequestError({ description: "Invalid decision evaluation request" })
|
|
63
|
+
})));
|
|
64
|
+
const snapshot = yield* Schema.decodeEffect(Schema.fromJsonString(EvaluateRequest))(encoded).pipe(Effect.mapError(() => new AiError.AiError({
|
|
65
|
+
module: "DecisionModel",
|
|
66
|
+
method: "evaluate",
|
|
67
|
+
reason: new AiError.InvalidRequestError({ description: "Invalid decision evaluation request" })
|
|
68
|
+
})));
|
|
69
|
+
const schema = responseFor(request.questions, options.choiceProbabilitySum);
|
|
70
|
+
const result = yield* Effect.scoped(options.evaluate(snapshot)).pipe(Effect.provideContext(services));
|
|
71
|
+
return yield* Schema.decodeUnknownEffect(schema)(result, { onExcessProperty: "error" }).pipe(Effect.mapError(() => new AiError.AiError({
|
|
72
|
+
module: "DecisionModel",
|
|
73
|
+
method: "evaluate",
|
|
74
|
+
reason: new AiError.InvalidOutputError({ description: "Decision response disagrees with the submitted questions" })
|
|
75
|
+
})));
|
|
76
|
+
});
|
|
77
|
+
const evaluateSet = Effect.fnUntraced(function* (set, input) {
|
|
78
|
+
const state = yield* Schema.encodeEffect(set.input)(input).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Content)), Effect.mapError(() => new AiError.AiError({
|
|
79
|
+
module: "DecisionModel",
|
|
80
|
+
method: "evaluate",
|
|
81
|
+
reason: new AiError.InvalidRequestError({ description: "Decision set input must encode to valid decision state" })
|
|
82
|
+
})));
|
|
83
|
+
return yield* evaluateRequest({
|
|
84
|
+
state,
|
|
85
|
+
questions: set.questions
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
function evaluate(...args) {
|
|
89
|
+
return args.length === 1 ? evaluateRequest(args[0]) : evaluateSet(args[0], args[1]);
|
|
90
|
+
}
|
|
91
|
+
return DecisionModel.of({ evaluate });
|
|
92
|
+
});
|
|
93
|
+
//#endregion
|
|
94
|
+
export { DecisionModel_exports as n, make as r, DecisionModel as t };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=DecisionModel-BQpmPcHb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionModel-BQpmPcHb.mjs","names":["Schema","DecisionSchema.Probability","DecisionSchema.ProbabilityAnswer","DecisionSchema.EvaluateRequest","DecisionSchema.Content"],"sources":["../src/internal/schema.ts","../src/DecisionModel.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport type * as SchemaAST from \"effect/SchemaAST\";\n\nimport * as DecisionSchema from \"../DecisionSchema.ts\";\n\n// Permit floating-point serialization error without changing provider values.\nconst tolerance = 1e-6;\n\nconst probabilitySum = Schema.makeFilter(\n (probabilities: Readonly<Record<string, number>>) =>\n Math.abs(Object.values(probabilities).reduce((sum, value) => sum + value, 0) - 1) <= tolerance,\n { expected: \"probabilities summing to 1 (within 1e-6)\" },\n);\n\nconst distribution = (\n keys: ReadonlyArray<string>,\n sumCheck: SchemaAST.Check<Readonly<Record<string, number>>> = probabilitySum,\n) => Schema.Record(Schema.Literals(keys), DecisionSchema.Probability).check(sumCheck);\n\nconst answerFor = (\n question: DecisionSchema.Question,\n choiceProbabilitySum: SchemaAST.Check<Readonly<Record<string, number>>> | undefined,\n) => {\n switch (question.type) {\n case \"choice\": {\n const keys = Object.keys(question.criteria);\n\n return Schema.Struct({\n ...DecisionSchema.ChoiceAnswer.fields,\n choice: Schema.Literals(keys),\n probabilities: distribution(keys, choiceProbabilitySum),\n }).check(\n Schema.makeFilter(\n ({ choice, probabilities }) =>\n Object.values(probabilities).every((value) => value <= probabilities[choice]),\n { expected: \"a highest-probability choice\" },\n ),\n );\n }\n case \"score\": {\n const maxLevel = question.criteria.length - 1;\n\n const levels = question.criteria.map(\n (description, index) => [String(index), description] as const,\n );\n\n return Schema.Struct({\n ...DecisionSchema.ScoreAnswer.fields,\n score: Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: maxLevel })),\n legend: Schema.Struct(\n Object.fromEntries(\n levels.map(([key, description]) => [key, Schema.Literal(description)]),\n ),\n ),\n probabilities: distribution(levels.map(([key]) => key)),\n }).check(\n Schema.makeFilter(\n ({ score, probabilities }) =>\n Math.abs(\n score -\n Object.entries(probabilities).reduce(\n (sum, [level, probability]) => sum + Number(level) * probability,\n 0,\n ),\n ) <=\n tolerance * Math.max(1, maxLevel),\n { expected: \"the probability-weighted score (within 1e-6 per level)\" },\n ),\n );\n }\n case \"probability\":\n return DecisionSchema.ProbabilityAnswer;\n }\n};\n\n// The overload describes the dependent type enforced by the literal keys and\n// per-question schemas below. No JSON value is asserted to have that type.\nexport function responseFor<const Q extends DecisionSchema.Questions>(\n questions: Q,\n choiceProbabilitySum?: SchemaAST.Check<Readonly<Record<string, number>>>,\n): Schema.Codec<DecisionSchema.EvaluateResponse<Q>>;\n\nexport function responseFor(\n questions: DecisionSchema.Questions,\n choiceProbabilitySum?: SchemaAST.Check<Readonly<Record<string, number>>>,\n): Schema.Top {\n return Schema.Struct({\n ...DecisionSchema.EvaluateResponse.fields,\n answers: Schema.Struct(\n Object.fromEntries(\n Object.entries(questions).map(([id, question]) => [\n id,\n answerFor(question, choiceProbabilitySum),\n ]),\n ),\n ),\n });\n}\n","import { Context, Effect, Schema, type SchemaAST, type Scope } from \"effect\";\nimport { AiError } from \"effect/unstable/ai\";\n\nimport * as DecisionSchema from \"./DecisionSchema.ts\";\nimport type * as DecisionSet from \"./DecisionSet.ts\";\nimport { responseFor } from \"./internal/schema.ts\";\n\n/** Typed semantic evaluations; the caller owns thresholds, transitions, and side effects. */\nexport interface Service {\n readonly evaluate: {\n <const Q extends DecisionSchema.Questions>(\n request: DecisionSchema.EvaluateRequest<Q>,\n ): Effect.Effect<DecisionSchema.EvaluateResponse<Q>, AiError.AiError>;\n /** Encode typed input as state, preserving the schema's encoding requirements. */\n <Input extends Schema.Top, const Q extends DecisionSchema.Questions>(\n set: DecisionSet.DecisionSet<Input, Q>,\n input: NoInfer<Input[\"Type\"]>,\n ): Effect.Effect<\n DecisionSchema.EvaluateResponse<Q>,\n AiError.AiError,\n Input[\"EncodingServices\"]\n >;\n };\n}\n\n/** A decision provider, independent of the agent's generative LanguageModel. */\nexport class DecisionModel extends Context.Service<DecisionModel, Service>()(\n \"@effect-agent/ai-decision/DecisionModel\",\n) {}\n\n/**\n * Construct a provider with request-derived response validation. Capture dependencies once;\n * resources acquired by evaluate close per call. Invalid data fails with native AiError.\n * Defects and interruption propagate. There are no implicit retries, deadlines, confidence\n * thresholds, or transitions. Usage is returned to the caller, not charged to an agent Run.\n */\nexport const make = Effect.fnUntraced(function* <R>(options: {\n /**\n * Provider-owned rounding check replacing only the Choice probability-sum check.\n * Defaults to a sum of 1 within 1e-6. Exact keys, ranges, winning choices, and\n * all Score checks remain enforced. This trusted construction option never\n * comes from response metadata and must not normalize the supplied values.\n */\n readonly choiceProbabilitySum?: SchemaAST.Check<Readonly<Record<string, number>>>;\n readonly evaluate: (\n request: DecisionSchema.EvaluateRequest,\n ) => Effect.Effect<unknown, AiError.AiError, R>;\n}): Effect.fn.Return<Service, never, Exclude<R, Scope.Scope>> {\n const services = yield* Effect.context<Exclude<R, Scope.Scope>>();\n\n const evaluateRequest = Effect.fn(\"DecisionModel.evaluate\")(function* <\n const Q extends DecisionSchema.Questions,\n >(\n request: DecisionSchema.EvaluateRequest<Q>,\n ): Effect.fn.Return<DecisionSchema.EvaluateResponse<Q>, AiError.AiError> {\n // Encode and decode once to snapshot caller-owned state and criteria before provider I/O.\n const encoded = yield* Schema.encodeEffect(\n Schema.fromJsonString(DecisionSchema.EvaluateRequest),\n )(request).pipe(\n Effect.mapError(\n () =>\n new AiError.AiError({\n module: \"DecisionModel\",\n method: \"evaluate\",\n reason: new AiError.InvalidRequestError({\n description: \"Invalid decision evaluation request\",\n }),\n }),\n ),\n );\n\n const snapshot = yield* Schema.decodeEffect(\n Schema.fromJsonString(DecisionSchema.EvaluateRequest),\n )(encoded).pipe(\n Effect.mapError(\n () =>\n new AiError.AiError({\n module: \"DecisionModel\",\n method: \"evaluate\",\n reason: new AiError.InvalidRequestError({\n description: \"Invalid decision evaluation request\",\n }),\n }),\n ),\n );\n\n const schema = responseFor(request.questions, options.choiceProbabilitySum);\n\n const result = yield* Effect.scoped(options.evaluate(snapshot)).pipe(\n Effect.provideContext(services),\n );\n\n return yield* Schema.decodeUnknownEffect(schema)(result, { onExcessProperty: \"error\" }).pipe(\n Effect.mapError(\n () =>\n new AiError.AiError({\n module: \"DecisionModel\",\n method: \"evaluate\",\n reason: new AiError.InvalidOutputError({\n description: \"Decision response disagrees with the submitted questions\",\n }),\n }),\n ),\n );\n });\n\n const evaluateSet = Effect.fnUntraced(function* <\n Input extends Schema.Top,\n const Q extends DecisionSchema.Questions,\n >(set: DecisionSet.DecisionSet<Input, Q>, input: Input[\"Type\"]) {\n const state = yield* Schema.encodeEffect(set.input)(input).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(DecisionSchema.Content)),\n Effect.mapError(\n () =>\n new AiError.AiError({\n module: \"DecisionModel\",\n method: \"evaluate\",\n reason: new AiError.InvalidRequestError({\n description: \"Decision set input must encode to valid decision state\",\n }),\n }),\n ),\n );\n\n return yield* evaluateRequest({ state, questions: set.questions });\n });\n\n function evaluate<const Q extends DecisionSchema.Questions>(\n request: DecisionSchema.EvaluateRequest<Q>,\n ): Effect.Effect<DecisionSchema.EvaluateResponse<Q>, AiError.AiError>;\n function evaluate<Input extends Schema.Top, const Q extends DecisionSchema.Questions>(\n set: DecisionSet.DecisionSet<Input, Q>,\n input: NoInfer<Input[\"Type\"]>,\n ): Effect.Effect<DecisionSchema.EvaluateResponse<Q>, AiError.AiError, Input[\"EncodingServices\"]>;\n function evaluate<Input extends Schema.Top, const Q extends DecisionSchema.Questions>(\n ...args:\n | [DecisionSchema.EvaluateRequest<Q>]\n | [DecisionSet.DecisionSet<Input, Q>, Input[\"Type\"]]\n ): Effect.Effect<DecisionSchema.EvaluateResponse<Q>, AiError.AiError, Input[\"EncodingServices\"]> {\n return args.length === 1 ? evaluateRequest(args[0]) : evaluateSet(args[0], args[1]);\n }\n\n return DecisionModel.of({ evaluate });\n});\n"],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EvaluateRequest, EvaluateResponse, Questions, t as DecisionSchema_d_exports } from "./DecisionSchema.mjs";
|
|
2
|
+
import { DecisionSet, t as DecisionSet_d_exports } from "./DecisionSet.mjs";
|
|
3
|
+
import { Context, Effect, Schema, SchemaAST, Scope } from "effect";
|
|
4
|
+
import { AiError } from "effect/unstable/ai";
|
|
5
|
+
declare namespace DecisionModel_d_exports {
|
|
6
|
+
export { DecisionModel, Service, make };
|
|
7
|
+
}
|
|
8
|
+
/** Typed semantic evaluations; the caller owns thresholds, transitions, and side effects. */
|
|
9
|
+
export interface Service {
|
|
10
|
+
readonly evaluate: {
|
|
11
|
+
<const Q extends Questions>(request: EvaluateRequest<Q>): Effect.Effect<EvaluateResponse<Q>, AiError.AiError>;
|
|
12
|
+
/** Encode typed input as state, preserving the schema's encoding requirements. */
|
|
13
|
+
<Input extends Schema.Top, const Q extends Questions>(set: DecisionSet<Input, Q>, input: NoInfer<Input["Type"]>): Effect.Effect<EvaluateResponse<Q>, AiError.AiError, Input["EncodingServices"]>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare const DecisionModel_base: Context.ServiceClass<DecisionModel, "@effect-agent/ai-decision/DecisionModel", Service>;
|
|
17
|
+
/** A decision provider, independent of the agent's generative LanguageModel. */
|
|
18
|
+
export declare class DecisionModel extends DecisionModel_base {}
|
|
19
|
+
/**
|
|
20
|
+
* Construct a provider with request-derived response validation. Capture dependencies once;
|
|
21
|
+
* resources acquired by evaluate close per call. Invalid data fails with native AiError.
|
|
22
|
+
* Defects and interruption propagate. There are no implicit retries, deadlines, confidence
|
|
23
|
+
* thresholds, or transitions. Usage is returned to the caller, not charged to an agent Run.
|
|
24
|
+
*/
|
|
25
|
+
export declare const make: <R>(options: {
|
|
26
|
+
/**
|
|
27
|
+
* Provider-owned rounding check replacing only the Choice probability-sum check.
|
|
28
|
+
* Defaults to a sum of 1 within 1e-6. Exact keys, ranges, winning choices, and
|
|
29
|
+
* all Score checks remain enforced. This trusted construction option never
|
|
30
|
+
* comes from response metadata and must not normalize the supplied values.
|
|
31
|
+
*/
|
|
32
|
+
readonly choiceProbabilitySum?: SchemaAST.Check<Readonly<Record<string, number>>>;
|
|
33
|
+
readonly evaluate: (request: EvaluateRequest) => Effect.Effect<unknown, AiError.AiError, R>;
|
|
34
|
+
}) => Effect.Effect<Service, never, Exclude<R, Scope.Scope>>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { DecisionModel_d_exports as t };
|
|
37
|
+
//# sourceMappingURL=DecisionModel.d.mts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ChoiceQuestion, Content, ProbabilityQuestion, t as DecisionSchema_d_exports } from "./DecisionSchema.mjs";
|
|
2
|
+
declare namespace DecisionQuery_d_exports {
|
|
3
|
+
export { choice, probability, score };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Choose one named option and retain the complete categorical distribution.
|
|
7
|
+
* Option keys infer the answer's choice union. Supply at least one option;
|
|
8
|
+
* null descriptions use the option name alone.
|
|
9
|
+
*
|
|
10
|
+
* @category constructors
|
|
11
|
+
* @since 0.1.0
|
|
12
|
+
*/
|
|
13
|
+
export declare const choice: <const Options extends ChoiceQuestion["criteria"]>(options: {
|
|
14
|
+
readonly instructions: Content;
|
|
15
|
+
readonly options: Options;
|
|
16
|
+
}) => Readonly<{
|
|
17
|
+
type: "choice";
|
|
18
|
+
instructions: string | readonly import("effect/Schema").Json[] | {
|
|
19
|
+
readonly [x: string]: import("effect/Schema").Json;
|
|
20
|
+
};
|
|
21
|
+
criteria: Readonly<Options>;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Rate a state along at least two ordered descriptions. The answer is the
|
|
25
|
+
* probability-weighted, zero-indexed position and may fall between levels.
|
|
26
|
+
*
|
|
27
|
+
* @category constructors
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export declare const score: (options: {
|
|
31
|
+
readonly instructions: Content;
|
|
32
|
+
readonly levels: ReadonlyArray<string>;
|
|
33
|
+
}) => Readonly<{
|
|
34
|
+
type: "score";
|
|
35
|
+
instructions: string | readonly import("effect/Schema").Json[] | {
|
|
36
|
+
readonly [x: string]: import("effect/Schema").Json;
|
|
37
|
+
};
|
|
38
|
+
criteria: readonly string[];
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate the probability a proposition is true. Optional criteria clarify
|
|
42
|
+
* either outcome. No threshold or implicit boolean conversion is applied.
|
|
43
|
+
*
|
|
44
|
+
* @category constructors
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
*/
|
|
47
|
+
export declare const probability: (options: Omit<ProbabilityQuestion, "type">) => Readonly<{
|
|
48
|
+
type: "probability";
|
|
49
|
+
instructions: string | readonly import("effect/Schema").Json[] | {
|
|
50
|
+
readonly [x: string]: import("effect/Schema").Json;
|
|
51
|
+
};
|
|
52
|
+
criteria?: Readonly<{
|
|
53
|
+
true?: string | undefined;
|
|
54
|
+
false?: string | undefined;
|
|
55
|
+
}> | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { DecisionQuery_d_exports as t };
|
|
59
|
+
//# sourceMappingURL=DecisionQuery.d.mts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
//#region src/DecisionQuery.ts
|
|
3
|
+
var DecisionQuery_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
choice: () => choice,
|
|
5
|
+
probability: () => probability,
|
|
6
|
+
score: () => score
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Choose one named option and retain the complete categorical distribution.
|
|
10
|
+
* Option keys infer the answer's choice union. Supply at least one option;
|
|
11
|
+
* null descriptions use the option name alone.
|
|
12
|
+
*
|
|
13
|
+
* @category constructors
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*/
|
|
16
|
+
const choice = (options) => Object.freeze({
|
|
17
|
+
type: "choice",
|
|
18
|
+
instructions: options.instructions,
|
|
19
|
+
criteria: Object.freeze({ ...options.options })
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Rate a state along at least two ordered descriptions. The answer is the
|
|
23
|
+
* probability-weighted, zero-indexed position and may fall between levels.
|
|
24
|
+
*
|
|
25
|
+
* @category constructors
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
const score = (options) => Object.freeze({
|
|
29
|
+
type: "score",
|
|
30
|
+
instructions: options.instructions,
|
|
31
|
+
criteria: Object.freeze([...options.levels])
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Estimate the probability a proposition is true. Optional criteria clarify
|
|
35
|
+
* either outcome. No threshold or implicit boolean conversion is applied.
|
|
36
|
+
*
|
|
37
|
+
* @category constructors
|
|
38
|
+
* @since 0.1.0
|
|
39
|
+
*/
|
|
40
|
+
const probability = (options) => Object.freeze({
|
|
41
|
+
type: "probability",
|
|
42
|
+
instructions: options.instructions,
|
|
43
|
+
...options.criteria === void 0 ? {} : { criteria: Object.freeze({ ...options.criteria }) }
|
|
44
|
+
});
|
|
45
|
+
//#endregion
|
|
46
|
+
export { choice, probability, score, DecisionQuery_exports as t };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=DecisionQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionQuery.mjs","names":[],"sources":["../src/DecisionQuery.ts"],"sourcesContent":["/**\n * Pure constructors for questions evaluated by a DecisionModel. Definitions\n * are validated when evaluated; constructing a query performs no model I/O.\n *\n * @since 0.1.0\n */\nimport type * as DecisionSchema from \"./DecisionSchema.ts\";\n\n/**\n * Choose one named option and retain the complete categorical distribution.\n * Option keys infer the answer's choice union. Supply at least one option;\n * null descriptions use the option name alone.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const choice = <const Options extends DecisionSchema.ChoiceQuestion[\"criteria\"]>(options: {\n readonly instructions: DecisionSchema.Content;\n readonly options: Options;\n}) =>\n Object.freeze({\n type: \"choice\" as const,\n instructions: options.instructions,\n criteria: Object.freeze({ ...options.options }),\n });\n\n/**\n * Rate a state along at least two ordered descriptions. The answer is the\n * probability-weighted, zero-indexed position and may fall between levels.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const score = (options: {\n readonly instructions: DecisionSchema.Content;\n readonly levels: ReadonlyArray<string>;\n}) =>\n Object.freeze({\n type: \"score\" as const,\n instructions: options.instructions,\n criteria: Object.freeze([...options.levels]),\n });\n\n/**\n * Estimate the probability a proposition is true. Optional criteria clarify\n * either outcome. No threshold or implicit boolean conversion is applied.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const probability = (options: Omit<DecisionSchema.ProbabilityQuestion, \"type\">) =>\n Object.freeze({\n type: \"probability\" as const,\n instructions: options.instructions,\n ...(options.criteria === undefined ? {} : { criteria: Object.freeze({ ...options.criteria }) }),\n });\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,UAA2E,YAItF,OAAO,OAAO;CACZ,MAAM;CACN,cAAc,QAAQ;CACtB,UAAU,OAAO,OAAO,EAAE,GAAG,QAAQ,QAAQ,CAAC;AAChD,CAAC;;;;;;;;AASH,MAAa,SAAS,YAIpB,OAAO,OAAO;CACZ,MAAM;CACN,cAAc,QAAQ;CACtB,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,MAAM,CAAC;AAC7C,CAAC;;;;;;;;AASH,MAAa,eAAe,YAC1B,OAAO,OAAO;CACZ,MAAM;CACN,cAAc,QAAQ;CACtB,GAAI,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,OAAO,OAAO,EAAE,GAAG,QAAQ,SAAS,CAAC,EAAE;AAC/F,CAAC"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
declare namespace DecisionSchema_d_exports {
|
|
3
|
+
export { Answer, AnswerFor, Answers, ChoiceAnswer, ChoiceQuestion, Content, EvaluateRequest, EvaluateResponse, Probability, ProbabilityAnswer, ProbabilityQuestion, ProviderMetadata, Question, Questions, ScoreAnswer, ScoreQuestion, Usage };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Text or JSON objects and arrays used as state and question instructions.
|
|
7
|
+
*
|
|
8
|
+
* @category schemas
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
export declare const Content: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
12
|
+
/** @category models
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
export type Content = typeof Content.Type;
|
|
16
|
+
/**
|
|
17
|
+
* A choice between named options. A null rubric uses the option name alone.
|
|
18
|
+
*
|
|
19
|
+
* @category schemas
|
|
20
|
+
* @since 0.1.0
|
|
21
|
+
*/
|
|
22
|
+
export declare const ChoiceQuestion: Schema.Struct<{
|
|
23
|
+
readonly type: Schema.Literal<"choice">;
|
|
24
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
25
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.String>>;
|
|
26
|
+
}>;
|
|
27
|
+
/** @category models
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export type ChoiceQuestion = typeof ChoiceQuestion.Type;
|
|
31
|
+
/**
|
|
32
|
+
* A rating along at least two ordered, zero-indexed level descriptions.
|
|
33
|
+
*
|
|
34
|
+
* @category schemas
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
*/
|
|
37
|
+
export declare const ScoreQuestion: Schema.Struct<{
|
|
38
|
+
readonly type: Schema.Literal<"score">;
|
|
39
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
40
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
41
|
+
}>;
|
|
42
|
+
/** @category models
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
export type ScoreQuestion = typeof ScoreQuestion.Type;
|
|
46
|
+
/**
|
|
47
|
+
* A yes/no judgment, with optional descriptions of either outcome.
|
|
48
|
+
*
|
|
49
|
+
* @category schemas
|
|
50
|
+
* @since 0.1.0
|
|
51
|
+
*/
|
|
52
|
+
export declare const ProbabilityQuestion: Schema.Struct<{
|
|
53
|
+
readonly type: Schema.Literal<"probability">;
|
|
54
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
55
|
+
readonly criteria: Schema.optionalKey<Schema.Struct<{
|
|
56
|
+
readonly true: Schema.optionalKey<Schema.String>;
|
|
57
|
+
readonly false: Schema.optionalKey<Schema.String>;
|
|
58
|
+
}>>;
|
|
59
|
+
}>;
|
|
60
|
+
/** @category models
|
|
61
|
+
* @since 0.1.0
|
|
62
|
+
*/
|
|
63
|
+
export type ProbabilityQuestion = typeof ProbabilityQuestion.Type;
|
|
64
|
+
/** @category schemas
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*/
|
|
67
|
+
export declare const Question: Schema.Union<readonly [Schema.Struct<{
|
|
68
|
+
readonly type: Schema.Literal<"choice">;
|
|
69
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
70
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.String>>;
|
|
71
|
+
}>, Schema.Struct<{
|
|
72
|
+
readonly type: Schema.Literal<"score">;
|
|
73
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
74
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
75
|
+
}>, Schema.Struct<{
|
|
76
|
+
readonly type: Schema.Literal<"probability">;
|
|
77
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
78
|
+
readonly criteria: Schema.optionalKey<Schema.Struct<{
|
|
79
|
+
readonly true: Schema.optionalKey<Schema.String>;
|
|
80
|
+
readonly false: Schema.optionalKey<Schema.String>;
|
|
81
|
+
}>>;
|
|
82
|
+
}>]>;
|
|
83
|
+
/** @category models
|
|
84
|
+
* @since 0.1.0
|
|
85
|
+
*/
|
|
86
|
+
export type Question = typeof Question.Type;
|
|
87
|
+
/** @category schemas
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
export declare const Questions: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
91
|
+
readonly type: Schema.Literal<"choice">;
|
|
92
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
93
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.String>>;
|
|
94
|
+
}>, Schema.Struct<{
|
|
95
|
+
readonly type: Schema.Literal<"score">;
|
|
96
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
97
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
98
|
+
}>, Schema.Struct<{
|
|
99
|
+
readonly type: Schema.Literal<"probability">;
|
|
100
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
101
|
+
readonly criteria: Schema.optionalKey<Schema.Struct<{
|
|
102
|
+
readonly true: Schema.optionalKey<Schema.String>;
|
|
103
|
+
readonly false: Schema.optionalKey<Schema.String>;
|
|
104
|
+
}>>;
|
|
105
|
+
}>]>>;
|
|
106
|
+
/** @category models
|
|
107
|
+
* @since 0.1.0
|
|
108
|
+
*/
|
|
109
|
+
export type Questions = typeof Questions.Type;
|
|
110
|
+
/** @category schemas
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
*/
|
|
113
|
+
export declare const EvaluateRequest: Schema.Struct<{
|
|
114
|
+
readonly state: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
115
|
+
readonly questions: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
116
|
+
readonly type: Schema.Literal<"choice">;
|
|
117
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
118
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.NullOr<Schema.String>>;
|
|
119
|
+
}>, Schema.Struct<{
|
|
120
|
+
readonly type: Schema.Literal<"score">;
|
|
121
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
122
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
123
|
+
}>, Schema.Struct<{
|
|
124
|
+
readonly type: Schema.Literal<"probability">;
|
|
125
|
+
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
126
|
+
readonly criteria: Schema.optionalKey<Schema.Struct<{
|
|
127
|
+
readonly true: Schema.optionalKey<Schema.String>;
|
|
128
|
+
readonly false: Schema.optionalKey<Schema.String>;
|
|
129
|
+
}>>;
|
|
130
|
+
}>]>>;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Evaluation input. Keep question literals with `satisfies Questions` when
|
|
134
|
+
* storing questions separately from the call to `evaluate`.
|
|
135
|
+
*
|
|
136
|
+
* @category models
|
|
137
|
+
* @since 0.1.0
|
|
138
|
+
*/
|
|
139
|
+
export type EvaluateRequest<Q extends Questions = Questions> = Omit<typeof EvaluateRequest.Type, "questions"> & {
|
|
140
|
+
readonly questions: Q;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* A finite probability or confidence in the inclusive range [0, 1].
|
|
144
|
+
*
|
|
145
|
+
* @category schemas
|
|
146
|
+
* @since 0.1.0
|
|
147
|
+
*/
|
|
148
|
+
export declare const Probability: Schema.Finite;
|
|
149
|
+
/**
|
|
150
|
+
* A selected option and its full distribution. Provider-specific confidence
|
|
151
|
+
* statistics belong to evaluation metadata, not the shared answer contract.
|
|
152
|
+
* Probabilities retain the provider's reported precision and are not normalized.
|
|
153
|
+
*
|
|
154
|
+
* @category schemas
|
|
155
|
+
* @since 0.1.0
|
|
156
|
+
*/
|
|
157
|
+
export declare const ChoiceAnswer: Schema.Struct<{
|
|
158
|
+
readonly type: Schema.Literal<"choice">;
|
|
159
|
+
readonly choice: Schema.String;
|
|
160
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Known option unions infer literal choices and required probability keys.
|
|
164
|
+
* Open string or template-pattern option types allow absent dictionary entries.
|
|
165
|
+
*
|
|
166
|
+
* @category models
|
|
167
|
+
* @since 0.1.0
|
|
168
|
+
*/
|
|
169
|
+
export type ChoiceAnswer<Choice extends string = string> = Omit<typeof ChoiceAnswer.Type, "choice" | "probabilities"> & {
|
|
170
|
+
readonly choice: Choice;
|
|
171
|
+
readonly probabilities: { readonly [K in Choice]: {} extends Pick<Record<Choice, unknown>, K> ? number | undefined : number; };
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* A fractional, probability-weighted level, with the supplied rubric as legend.
|
|
175
|
+
*
|
|
176
|
+
* @category schemas
|
|
177
|
+
* @since 0.1.0
|
|
178
|
+
*/
|
|
179
|
+
export declare const ScoreAnswer: Schema.Struct<{
|
|
180
|
+
readonly type: Schema.Literal<"score">;
|
|
181
|
+
readonly score: Schema.Finite;
|
|
182
|
+
readonly legend: Schema.$Record<Schema.String, Schema.String>;
|
|
183
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* Score levels are keyed at runtime; an arbitrary legend or probability lookup
|
|
187
|
+
* may be absent.
|
|
188
|
+
*
|
|
189
|
+
* @category models
|
|
190
|
+
* @since 0.1.0
|
|
191
|
+
*/
|
|
192
|
+
export type ScoreAnswer = Omit<typeof ScoreAnswer.Type, "legend" | "probabilities"> & {
|
|
193
|
+
readonly legend: {
|
|
194
|
+
readonly [level: string]: string | undefined;
|
|
195
|
+
};
|
|
196
|
+
readonly probabilities: {
|
|
197
|
+
readonly [level: string]: number | undefined;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* The probability of yes. A probability answer has no separate confidence field.
|
|
202
|
+
*
|
|
203
|
+
* @category schemas
|
|
204
|
+
* @since 0.1.0
|
|
205
|
+
*/
|
|
206
|
+
export declare const ProbabilityAnswer: Schema.Struct<{
|
|
207
|
+
readonly type: Schema.Literal<"probability">;
|
|
208
|
+
readonly probability: Schema.Finite;
|
|
209
|
+
}>;
|
|
210
|
+
/** @category models
|
|
211
|
+
* @since 0.1.0
|
|
212
|
+
*/
|
|
213
|
+
export type ProbabilityAnswer = typeof ProbabilityAnswer.Type;
|
|
214
|
+
/** @category schemas
|
|
215
|
+
* @since 0.1.0
|
|
216
|
+
*/
|
|
217
|
+
export declare const Answer: Schema.Union<readonly [Schema.Struct<{
|
|
218
|
+
readonly type: Schema.Literal<"choice">;
|
|
219
|
+
readonly choice: Schema.String;
|
|
220
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
221
|
+
}>, Schema.Struct<{
|
|
222
|
+
readonly type: Schema.Literal<"score">;
|
|
223
|
+
readonly score: Schema.Finite;
|
|
224
|
+
readonly legend: Schema.$Record<Schema.String, Schema.String>;
|
|
225
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
226
|
+
}>, Schema.Struct<{
|
|
227
|
+
readonly type: Schema.Literal<"probability">;
|
|
228
|
+
readonly probability: Schema.Finite;
|
|
229
|
+
}>]>;
|
|
230
|
+
/** @category models
|
|
231
|
+
* @since 0.1.0
|
|
232
|
+
*/
|
|
233
|
+
export type Answer = ChoiceAnswer | ScoreAnswer | ProbabilityAnswer;
|
|
234
|
+
/** @category schemas
|
|
235
|
+
* @since 0.1.0
|
|
236
|
+
*/
|
|
237
|
+
export declare const Usage: Schema.Struct<{
|
|
238
|
+
readonly inputTokens: Schema.NullOr<Schema.Natural>;
|
|
239
|
+
readonly outputTokens: Schema.NullOr<Schema.Natural>;
|
|
240
|
+
}>;
|
|
241
|
+
/** @category models
|
|
242
|
+
* @since 0.1.0
|
|
243
|
+
*/
|
|
244
|
+
export type Usage = typeof Usage.Type;
|
|
245
|
+
/**
|
|
246
|
+
* Provider-namespaced evidence that has no shared interpretation. Consumers
|
|
247
|
+
* decode a namespace with its provider's schema before using its contents.
|
|
248
|
+
*
|
|
249
|
+
* @category schemas
|
|
250
|
+
* @since 0.1.0
|
|
251
|
+
*/
|
|
252
|
+
export declare const ProviderMetadata: Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
253
|
+
/** @category models
|
|
254
|
+
* @since 0.1.0
|
|
255
|
+
*/
|
|
256
|
+
export type ProviderMetadata = typeof ProviderMetadata.Type;
|
|
257
|
+
/**
|
|
258
|
+
* The wire response shape. `DecisionModel.evaluate` additionally validates
|
|
259
|
+
* answer IDs, question kinds, criteria, distributions, and score correlations.
|
|
260
|
+
*
|
|
261
|
+
* @category schemas
|
|
262
|
+
* @since 0.1.0
|
|
263
|
+
*/
|
|
264
|
+
export declare const EvaluateResponse: Schema.Struct<{
|
|
265
|
+
readonly provider: Schema.NonEmptyString;
|
|
266
|
+
readonly model: Schema.String;
|
|
267
|
+
readonly answers: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
268
|
+
readonly type: Schema.Literal<"choice">;
|
|
269
|
+
readonly choice: Schema.String;
|
|
270
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
271
|
+
}>, Schema.Struct<{
|
|
272
|
+
readonly type: Schema.Literal<"score">;
|
|
273
|
+
readonly score: Schema.Finite;
|
|
274
|
+
readonly legend: Schema.$Record<Schema.String, Schema.String>;
|
|
275
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Finite>;
|
|
276
|
+
}>, Schema.Struct<{
|
|
277
|
+
readonly type: Schema.Literal<"probability">;
|
|
278
|
+
readonly probability: Schema.Finite;
|
|
279
|
+
}>]>>;
|
|
280
|
+
readonly usage: Schema.Struct<{
|
|
281
|
+
readonly inputTokens: Schema.NullOr<Schema.Natural>;
|
|
282
|
+
readonly outputTokens: Schema.NullOr<Schema.Natural>;
|
|
283
|
+
}>;
|
|
284
|
+
readonly providerMetadata: Schema.optionalKey<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>>;
|
|
285
|
+
}>;
|
|
286
|
+
type ChoiceAnswerFor<Criteria> = Criteria extends unknown ? Omit<typeof ChoiceAnswer.Type, "choice" | "probabilities"> & {
|
|
287
|
+
readonly choice: `${Extract<keyof Criteria, string | number>}`;
|
|
288
|
+
readonly probabilities: { readonly [K in keyof Criteria as K extends string | number ? `${K}` : never]: {} extends Pick<Criteria, K> ? number | undefined : number; };
|
|
289
|
+
} : never;
|
|
290
|
+
/**
|
|
291
|
+
* Infer a question's answer, preserving optional choice criteria in its probabilities.
|
|
292
|
+
*
|
|
293
|
+
* @category models
|
|
294
|
+
* @since 0.1.0
|
|
295
|
+
*/
|
|
296
|
+
export type AnswerFor<Q extends Question> = Q extends ChoiceQuestion ? ChoiceAnswerFor<Q["criteria"]> : Q extends ScoreQuestion ? ScoreAnswer : ProbabilityAnswer;
|
|
297
|
+
/**
|
|
298
|
+
* One answer for each required question. Optional properties and open string,
|
|
299
|
+
* numeric, or template-pattern indexes require checking an entry for absence.
|
|
300
|
+
*
|
|
301
|
+
* @category models
|
|
302
|
+
* @since 0.1.0
|
|
303
|
+
*/
|
|
304
|
+
export type Answers<Q extends Questions> = { readonly [K in keyof Q as K extends string | number ? `${K}` : never]: {} extends Pick<Q, K> ? AnswerFor<NonNullable<Q[K]>> | undefined : AnswerFor<Q[K]>; };
|
|
305
|
+
/** @category models
|
|
306
|
+
* @since 0.1.0
|
|
307
|
+
*/
|
|
308
|
+
export type EvaluateResponse<Q extends Questions = Questions> = Omit<typeof EvaluateResponse.Type, "answers"> & {
|
|
309
|
+
readonly answers: Answers<Q>;
|
|
310
|
+
};
|
|
311
|
+
//#endregion
|
|
312
|
+
export { DecisionSchema_d_exports as t };
|
|
313
|
+
//# sourceMappingURL=DecisionSchema.d.mts.map
|