Open History to see the last commit
1/**
2 * Schemas for OpenRouter's alpha Decisions API.
3 *
4 * @stability unstable
5 * @since 4.0.0
6 */
7import * as Schema from "effect/Schema"
8import * as Generated from "./Generated.ts"
9
10const Entry = Schema.Union([Schema.String, Schema.JsonObject, Schema.Array(Schema.Json)])
11
12/**
13 * A choice question with descriptions keyed by choice label.
14 *
15 * @stability unstable
16 * @category schemas
17 * @since 4.0.0
18 */
19export const ChoiceQuestion = Schema.Struct({
20 type: Schema.Literal("choice"),
21 instructions: Entry,
22 criteria: Schema.Record(Schema.String, Schema.NullOr(Entry))
23})
24
25/**
26 * A score question with ordered criteria.
27 *
28 * @stability unstable
29 * @category schemas
30 * @since 4.0.0
31 */
32export const ScoreQuestion = Schema.Struct({
33 type: Schema.Literal("score"),
34 instructions: Entry,
35 criteria: Schema.Array(Entry)
36})
37
38/**
39 * A probability question with optional true and false descriptions.
40 *
41 * @stability unstable
42 * @category schemas
43 * @since 4.0.0
44 */
45export const NoulQuestion = Schema.Struct({
46 type: Schema.Literal("noul"),
47 instructions: Entry,
48 criteria: Schema.optional(Schema.Struct({ true: Entry, false: Entry }))
49})
50
51/**
52 * A choice, score, or probability question with string, JSON object, or JSON array
53 * instructions and descriptions. Choice descriptions also accept `null`.
54 *
55 * @stability unstable
56 * @category schemas
57 * @since 4.0.0
58 */
59export const DecisionsQuestion = Schema.Union([
60 ChoiceQuestion,
61 ScoreQuestion,
62 NoulQuestion
63])
64
65/**
66 * A provider answer with optional probabilities and confidence.
67 *
68 * @stability unstable
69 * @category schemas
70 * @since 4.0.0
71 */
72export const Answer = Schema.Union([
73 Schema.Struct({
74 type: Schema.Literal("choice"),
75 choice: Schema.String,
76 confidence: Schema.optional(Schema.Finite),
77 probabilities: Schema.optional(Schema.Record(Schema.String, Schema.Finite))
78 }),
79 Schema.Struct({
80 type: Schema.Literal("score"),
81 score: Schema.Finite,
82 confidence: Schema.optional(Schema.Finite),
83 probabilities: Schema.optional(Schema.Record(Schema.String, Schema.Finite)),
84 legend: Schema.optional(Schema.Record(Schema.String, Schema.Json))
85 }),
86 Schema.Struct({ type: Schema.Literal("noul"), noul: Schema.Finite })
87])
88
89/**
90 * Request body for the alpha Decisions endpoint.
91 *
92 * @stability unstable
93 * @category schemas
94 * @since 4.0.0
95 */
96export const DecisionsRequest = Schema.Struct({
97 model: Schema.String,
98 state: Schema.Unknown,
99 questions: Schema.Record(Schema.String, DecisionsQuestion),
100 provider: Schema.optional(Generated.ProviderPreferences),
101 session_id: Schema.optional(Schema.String),
102 user: Schema.optional(Schema.String),
103 trace: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
104})
105
106/**
107 * Response body for the alpha Decisions endpoint.
108 *
109 * @stability unstable
110 * @category schemas
111 * @since 4.0.0
112 */
113export const DecisionsResponse = Schema.Struct({
114 model: Schema.String,
115 answers: Schema.Record(Schema.String, Answer),
116 usage: Schema.Struct({
117 input_tokens: Schema.Int,
118 output_tokens: Schema.Int,
119 cost: Schema.optional(Schema.Finite)
120 }),
121 id: Schema.optional(Schema.String),
122 provider: Schema.optional(Schema.String)
123})