The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | /** |
| 2 | * Codecs for text and JSON decisions from Cloudflare Clef models. |
| 3 | * |
| 4 | * @stability unstable |
| 5 | * @since 4.0.0 |
| 6 | */ |
| 7 | import * as Schema from "effect/Schema" |
| 8 | |
| 9 | const Entry = Schema.Union([Schema.String, Schema.JsonObject, Schema.Array(Schema.Json)]) |
| 10 | |
| 11 | /** |
| 12 | * A classification question. |
| 13 | * |
| 14 | * @stability unstable |
| 15 | * @category schemas |
| 16 | * @since 4.0.0 |
| 17 | */ |
| 18 | export const ChoiceQuestion = Schema.Struct({ |
| 19 | type: Schema.Literal("choice"), |
| 20 | instructions: Entry, |
| 21 | criteria: Schema.Record(Schema.String, Schema.NullOr(Entry)) |
| 22 | }) |
| 23 | |
| 24 | /** |
| 25 | * An ordered rating question. |
| 26 | * |
| 27 | * @stability unstable |
| 28 | * @category schemas |
| 29 | * @since 4.0.0 |
| 30 | */ |
| 31 | export const ScoreQuestion = Schema.Struct({ |
| 32 | type: Schema.Literal("score"), |
| 33 | instructions: Entry, |
| 34 | criteria: Schema.Array(Schema.Json) |
| 35 | }) |
| 36 | |
| 37 | /** |
| 38 | * A probability question. |
| 39 | * |
| 40 | * @stability unstable |
| 41 | * @category schemas |
| 42 | * @since 4.0.0 |
| 43 | */ |
| 44 | export const NoulQuestion = Schema.Struct({ |
| 45 | type: Schema.Literal("noul"), |
| 46 | instructions: Entry, |
| 47 | criteria: Schema.optional(Schema.Struct({ false: Schema.Json, true: Schema.Json })) |
| 48 | }) |
| 49 | |
| 50 | /** |
| 51 | * A Clef question with string, JSON object, or JSON array instructions. |
| 52 | * Choice descriptions also accept `null`; Score and Noul descriptions accept any JSON value. |
| 53 | * |
| 54 | * @stability unstable |
| 55 | * @category schemas |
| 56 | * @since 4.0.0 |
| 57 | */ |
| 58 | export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion]) |
| 59 | |
| 60 | /** |
| 61 | * An image as a `data:` URL or as base64 data with its media type. Clef |
| 62 | * rejects remote URLs. |
| 63 | * |
| 64 | * @stability unstable |
| 65 | * @category schemas |
| 66 | * @since 4.0.5 |
| 67 | */ |
| 68 | export const Image = Schema.Union([ |
| 69 | Schema.String, |
| 70 | Schema.Struct({ |
| 71 | content_type: Schema.Union([ |
| 72 | Schema.Literals(["image/png", "image/jpeg", "image/webp"]), |
| 73 | Schema.StringForLiteralAutocomplete |
| 74 | ]), |
| 75 | base64: Schema.String |
| 76 | }) |
| 77 | ]) |
| 78 | |
| 79 | /** |
| 80 | * A batch of questions about text or JSON state, with optional images shown |
| 81 | * to the model before the state. |
| 82 | * |
| 83 | * **Details** |
| 84 | * |
| 85 | * Clef accepts up to 4 images of at most 4 MiB and 16 megapixels each, 8 MiB |
| 86 | * of decoded images in total, and 13 MiB per request body. |
| 87 | * |
| 88 | * @stability unstable |
| 89 | * @category schemas |
| 90 | * @since 4.0.0 |
| 91 | */ |
| 92 | export const DecisionsRequest = Schema.Struct({ |
| 93 | model: Schema.Union([Schema.Literals(["clef", "clef-flash"]), Schema.StringForLiteralAutocomplete]), |
| 94 | state: Schema.Json, |
| 95 | questions: Schema.Record(Schema.String, Question), |
| 96 | images: Schema.optional(Schema.Array(Image)) |
| 97 | }) |
| 98 | |
| 99 | /** |
| 100 | * A classification distribution. |
| 101 | * |
| 102 | * @stability unstable |
| 103 | * @category schemas |
| 104 | * @since 4.0.0 |
| 105 | */ |
| 106 | export const ChoiceAnswer = Schema.Struct({ |
| 107 | type: Schema.Literal("choice"), |
| 108 | choice: Schema.String, |
| 109 | probabilities: Schema.Record(Schema.String, Schema.Number), |
| 110 | confidence: Schema.Number |
| 111 | }) |
| 112 | |
| 113 | /** |
| 114 | * A zero-based rating and index-keyed distribution. `legend` maps indices to descriptions. |
| 115 | * |
| 116 | * @stability unstable |
| 117 | * @category schemas |
| 118 | * @since 4.0.0 |
| 119 | */ |
| 120 | export const ScoreAnswer = Schema.Struct({ |
| 121 | type: Schema.Literal("score"), |
| 122 | score: Schema.Number, |
| 123 | probabilities: Schema.Record(Schema.String, Schema.Number), |
| 124 | confidence: Schema.Number, |
| 125 | legend: Schema.Record(Schema.String, Schema.Json) |
| 126 | }) |
| 127 | |
| 128 | /** |
| 129 | * A Bernoulli probability. |
| 130 | * |
| 131 | * @stability unstable |
| 132 | * @category schemas |
| 133 | * @since 4.0.0 |
| 134 | */ |
| 135 | export const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Schema.Number }) |
| 136 | |
| 137 | /** |
| 138 | * A Clef classification, rating, or probability answer. |
| 139 | * |
| 140 | * @stability unstable |
| 141 | * @category schemas |
| 142 | * @since 4.0.0 |
| 143 | */ |
| 144 | export const Answer = Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer]) |
| 145 | |
| 146 | /** |
| 147 | * Answers and token usage for a batch. |
| 148 | * |
| 149 | * @stability unstable |
| 150 | * @category schemas |
| 151 | * @since 4.0.0 |
| 152 | */ |
| 153 | export const DecisionsResponse = Schema.Struct({ |
| 154 | model: Schema.String, |
| 155 | answers: Schema.Record(Schema.String, Answer), |
| 156 | usage: Schema.Struct({ |
| 157 | input_tokens: Schema.Int, |
| 158 | output_tokens: Schema.Int |
| 159 | }) |
| 160 | }) |