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