@opencode/ai 0.0.0-dev-21797 → 0.0.0-dev-21799

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.
Files changed (52) hide show
  1. package/README.md +55 -55
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/decision-client.d.ts +21 -0
  5. package/dist/decision-client.js +55 -0
  6. package/dist/decision.d.ts +452 -0
  7. package/dist/decision.js +143 -0
  8. package/dist/experimental.d.ts +0 -3
  9. package/dist/experimental.js +0 -2
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +4 -0
  12. package/dist/promise.d.ts +10 -1
  13. package/dist/promise.js +5 -0
  14. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  15. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  16. package/dist/protocols/index.d.ts +3 -0
  17. package/dist/protocols/index.js +3 -0
  18. package/dist/protocols/openai-decisions.d.ts +22 -0
  19. package/dist/protocols/openai-decisions.js +108 -0
  20. package/dist/protocols/system-one.d.ts +99 -0
  21. package/dist/protocols/system-one.js +228 -0
  22. package/dist/providers/baseten.d.ts +4 -10
  23. package/dist/providers/baseten.js +21 -8
  24. package/dist/providers/cloudflare-ai-gateway.d.ts +1 -3
  25. package/dist/providers/cloudflare-ai-gateway.js +10 -10
  26. package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
  27. package/dist/providers/cloudflare-workers-ai.js +11 -12
  28. package/dist/providers/digitalocean.d.ts +3 -9
  29. package/dist/providers/digitalocean.js +10 -10
  30. package/dist/providers/openai.d.ts +5 -10
  31. package/dist/providers/openai.js +11 -7
  32. package/dist/providers/opencode.d.ts +3 -9
  33. package/dist/providers/opencode.js +9 -9
  34. package/dist/providers/openrouter.d.ts +4 -10
  35. package/dist/providers/openrouter.js +8 -9
  36. package/dist/providers/typesafe-ai.d.ts +3 -9
  37. package/dist/providers/typesafe-ai.js +9 -9
  38. package/dist/providers/vercel-ai-gateway.d.ts +4 -15
  39. package/dist/providers/vercel-ai-gateway.js +13 -80
  40. package/dist/route/decision.d.ts +57 -0
  41. package/dist/route/decision.js +74 -0
  42. package/package.json +3 -3
  43. package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
  44. package/dist/experimental/cloudflare-run-evaluation.js +0 -43
  45. package/dist/experimental/evaluation-client.d.ts +0 -21
  46. package/dist/experimental/evaluation-client.js +0 -64
  47. package/dist/experimental/evaluation.d.ts +0 -242
  48. package/dist/experimental/evaluation.js +0 -108
  49. package/dist/experimental/openai-decisions.d.ts +0 -23
  50. package/dist/experimental/openai-decisions.js +0 -115
  51. package/dist/experimental/system-one.d.ts +0 -114
  52. package/dist/experimental/system-one.js +0 -140
@@ -1,242 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import { AIError, HttpOptions, ModelID, ProviderID, Usage } from "../schema/index.js";
3
- import { Service, type Execute } from "./evaluation-client.js";
4
- export declare const EvaluationInput: 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>>]>;
5
- export type EvaluationInput = Schema.Schema.Type<typeof EvaluationInput>;
6
- export declare const ChoiceQuestion: Schema.Struct<{
7
- readonly type: Schema.Literal<"choice">;
8
- 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>>]>;
9
- readonly criteria: Schema.refine<{
10
- readonly [x: string]: string | readonly Schema.Json[] | {
11
- readonly [x: string]: Schema.Json;
12
- } | null;
13
- }, Schema.$Record<Schema.String, Schema.NullOr<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>>]>>>>;
14
- }>;
15
- export type ChoiceQuestion = Schema.Schema.Type<typeof ChoiceQuestion>;
16
- export declare const ScoreQuestion: Schema.Struct<{
17
- readonly type: Schema.Literal<"score">;
18
- 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>>]>;
19
- readonly criteria: Schema.$Array<Schema.NullOr<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>>]>>>;
20
- }>;
21
- export type ScoreQuestion = Schema.Schema.Type<typeof ScoreQuestion>;
22
- export declare const BooleanQuestion: Schema.Struct<{
23
- readonly type: Schema.Literal<"boolean">;
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.optional<Schema.Struct<{
26
- readonly true: Schema.optional<Schema.NullOr<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>>]>>>;
27
- readonly false: Schema.optional<Schema.NullOr<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>>]>>>;
28
- }>>;
29
- }>;
30
- export type BooleanQuestion = Schema.Schema.Type<typeof BooleanQuestion>;
31
- export declare const EvaluationQuestion: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
32
- readonly type: Schema.Literal<"choice">;
33
- 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>>]>;
34
- readonly criteria: Schema.refine<{
35
- readonly [x: string]: string | readonly Schema.Json[] | {
36
- readonly [x: string]: Schema.Json;
37
- } | null;
38
- }, Schema.$Record<Schema.String, Schema.NullOr<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>>]>>>>;
39
- }>, Schema.Struct<{
40
- readonly type: Schema.Literal<"score">;
41
- 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>>]>;
42
- readonly criteria: Schema.$Array<Schema.NullOr<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>>]>>>;
43
- }>, Schema.Struct<{
44
- readonly type: Schema.Literal<"boolean">;
45
- 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>>]>;
46
- readonly criteria: Schema.optional<Schema.Struct<{
47
- readonly true: Schema.optional<Schema.NullOr<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>>]>>>;
48
- readonly false: Schema.optional<Schema.NullOr<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>>]>>>;
49
- }>>;
50
- }>]>;
51
- export type EvaluationQuestion = Schema.Schema.Type<typeof EvaluationQuestion>;
52
- export type EvaluationQuestions = Readonly<Record<string, EvaluationQuestion>>;
53
- export declare const ChoiceAnswer: Schema.Struct<{
54
- readonly type: Schema.Literal<"choice">;
55
- readonly choice: Schema.String;
56
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
57
- readonly confidence: Schema.optional<Schema.Number>;
58
- }>;
59
- export type ChoiceAnswer = Schema.Schema.Type<typeof ChoiceAnswer>;
60
- export declare const ScoreAnswer: Schema.Struct<{
61
- readonly type: Schema.Literal<"score">;
62
- readonly score: Schema.Number;
63
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
64
- readonly confidence: Schema.optional<Schema.Number>;
65
- }>;
66
- export type ScoreAnswer = Schema.Schema.Type<typeof ScoreAnswer>;
67
- export declare const BooleanAnswer: Schema.Struct<{
68
- readonly type: Schema.Literal<"boolean">;
69
- readonly probability: Schema.Number;
70
- }>;
71
- export type BooleanAnswer = Schema.Schema.Type<typeof BooleanAnswer>;
72
- export declare const EvaluationAnswer: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
73
- readonly type: Schema.Literal<"choice">;
74
- readonly choice: Schema.String;
75
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
76
- readonly confidence: Schema.optional<Schema.Number>;
77
- }>, Schema.Struct<{
78
- readonly type: Schema.Literal<"score">;
79
- readonly score: Schema.Number;
80
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
81
- readonly confidence: Schema.optional<Schema.Number>;
82
- }>, Schema.Struct<{
83
- readonly type: Schema.Literal<"boolean">;
84
- readonly probability: Schema.Number;
85
- }>]>;
86
- export type EvaluationAnswer = Schema.Schema.Type<typeof EvaluationAnswer>;
87
- export type AnswerFor<Question extends EvaluationQuestion> = Question extends {
88
- readonly type: "choice";
89
- readonly criteria: infer Criteria;
90
- } ? {
91
- readonly type: "choice";
92
- readonly choice: Extract<keyof Criteria, string>;
93
- readonly probabilities?: Readonly<Record<Extract<keyof Criteria, string>, number>>;
94
- readonly confidence?: number;
95
- } : Question extends {
96
- readonly type: "score";
97
- } ? ScoreAnswer : BooleanAnswer;
98
- export type AnswersFor<Questions extends EvaluationQuestions> = {
99
- readonly [ID in keyof Questions]: AnswerFor<Questions[ID]>;
100
- };
101
- export type EvaluationOptions = Record<string, unknown>;
102
- export interface EvaluationRoute<Options extends EvaluationOptions = EvaluationOptions> {
103
- readonly id: string;
104
- evaluate(request: EvaluationRequestFor<Options>, execute: Execute): Effect.Effect<EvaluationResponse, AIError>;
105
- }
106
- export declare class EvaluationModel<Options extends EvaluationOptions = EvaluationOptions> {
107
- protected readonly _Options: Options;
108
- readonly id: ModelID;
109
- readonly provider: ProviderID;
110
- readonly route: EvaluationRoute<Options>;
111
- readonly http?: HttpOptions;
112
- constructor(input: EvaluationModel.Input<Options>);
113
- static make<Options extends EvaluationOptions = EvaluationOptions>(input: EvaluationModel.MakeInput<Options>): EvaluationModel<Options>;
114
- }
115
- export declare namespace EvaluationModel {
116
- interface Input<Options extends EvaluationOptions = EvaluationOptions> {
117
- readonly id: ModelID;
118
- readonly provider: ProviderID;
119
- readonly route: EvaluationRoute<Options>;
120
- readonly http?: HttpOptions;
121
- }
122
- interface MakeInput<Options extends EvaluationOptions = EvaluationOptions> extends Omit<Input<Options>, "id" | "provider"> {
123
- readonly id: string | ModelID;
124
- readonly provider: string | ProviderID;
125
- }
126
- }
127
- export declare const EvaluationModelSchema: Schema.declare<EvaluationModel<EvaluationOptions>, EvaluationModel<EvaluationOptions>>;
128
- declare const EvaluationRequest_base: Schema.Class<EvaluationRequest, Schema.Struct<{
129
- readonly model: Schema.declare<EvaluationModel<EvaluationOptions>, EvaluationModel<EvaluationOptions>>;
130
- 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>>]>;
131
- readonly questions: Schema.refine<{
132
- readonly [x: string]: {
133
- readonly type: "choice";
134
- readonly instructions: string | readonly Schema.Json[] | {
135
- readonly [x: string]: Schema.Json;
136
- };
137
- readonly criteria: {
138
- readonly [x: string]: string | readonly Schema.Json[] | {
139
- readonly [x: string]: Schema.Json;
140
- } | null;
141
- };
142
- } | {
143
- readonly type: "score";
144
- readonly instructions: string | readonly Schema.Json[] | {
145
- readonly [x: string]: Schema.Json;
146
- };
147
- readonly criteria: readonly (string | readonly Schema.Json[] | {
148
- readonly [x: string]: Schema.Json;
149
- } | null)[];
150
- } | {
151
- readonly type: "boolean";
152
- readonly instructions: string | readonly Schema.Json[] | {
153
- readonly [x: string]: Schema.Json;
154
- };
155
- readonly criteria?: {
156
- readonly true?: string | readonly Schema.Json[] | {
157
- readonly [x: string]: Schema.Json;
158
- } | null | undefined;
159
- readonly false?: string | readonly Schema.Json[] | {
160
- readonly [x: string]: Schema.Json;
161
- } | null | undefined;
162
- } | undefined;
163
- };
164
- }, Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
165
- readonly type: Schema.Literal<"choice">;
166
- 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>>]>;
167
- readonly criteria: Schema.refine<{
168
- readonly [x: string]: string | readonly Schema.Json[] | {
169
- readonly [x: string]: Schema.Json;
170
- } | null;
171
- }, Schema.$Record<Schema.String, Schema.NullOr<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>>]>>>>;
172
- }>, Schema.Struct<{
173
- readonly type: Schema.Literal<"score">;
174
- 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>>]>;
175
- readonly criteria: Schema.$Array<Schema.NullOr<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>>]>>>;
176
- }>, Schema.Struct<{
177
- readonly type: Schema.Literal<"boolean">;
178
- 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>>]>;
179
- readonly criteria: Schema.optional<Schema.Struct<{
180
- readonly true: Schema.optional<Schema.NullOr<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>>]>>>;
181
- readonly false: Schema.optional<Schema.NullOr<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>>]>>>;
182
- }>>;
183
- }>]>>>;
184
- readonly options: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
185
- readonly http: Schema.optional<typeof HttpOptions>;
186
- }>, {}>;
187
- export declare class EvaluationRequest extends EvaluationRequest_base {
188
- protected readonly _EvaluationRequest: void;
189
- }
190
- export type EvaluationModelOptions<Model> = Model extends EvaluationModel<infer Options> ? Options : never;
191
- export type EvaluationRequestFor<Options extends EvaluationOptions = EvaluationOptions, Questions extends EvaluationQuestions = EvaluationQuestions> = Omit<EvaluationRequest, "model" | "questions" | "options"> & {
192
- readonly model: EvaluationModel<Options>;
193
- readonly questions: Questions;
194
- readonly options?: Options;
195
- };
196
- export type EvaluationRequestInput<Model extends EvaluationModel = EvaluationModel, Questions extends EvaluationQuestions = EvaluationQuestions> = Omit<ConstructorParameters<typeof EvaluationRequest>[0], "model" | "questions" | "options" | "http"> & {
197
- readonly model: Model;
198
- readonly questions: Questions;
199
- readonly options?: NoInfer<EvaluationModelOptions<Model>>;
200
- readonly http?: HttpOptions.Input;
201
- };
202
- declare const EvaluationRounding_base: Schema.Class<EvaluationRounding, Schema.Struct<{
203
- readonly probabilityDecimals: Schema.optional<Schema.Int>;
204
- readonly scoreDecimals: Schema.optional<Schema.Int>;
205
- }>, {}>;
206
- export declare class EvaluationRounding extends EvaluationRounding_base {
207
- }
208
- declare const EvaluationResponse_base: Schema.Class<EvaluationResponse, Schema.Struct<{
209
- readonly model: Schema.brand<Schema.String, "AI.ModelID">;
210
- readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
211
- readonly type: Schema.Literal<"choice">;
212
- readonly choice: Schema.String;
213
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
214
- readonly confidence: Schema.optional<Schema.Number>;
215
- }>, Schema.Struct<{
216
- readonly type: Schema.Literal<"score">;
217
- readonly score: Schema.Number;
218
- readonly probabilities: Schema.optional<Schema.$Record<Schema.String, Schema.Number>>;
219
- readonly confidence: Schema.optional<Schema.Number>;
220
- }>, Schema.Struct<{
221
- readonly type: Schema.Literal<"boolean">;
222
- readonly probability: Schema.Number;
223
- }>]>>;
224
- readonly usage: Schema.optional<typeof Usage>;
225
- readonly rounding: Schema.optional<typeof EvaluationRounding>;
226
- readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
227
- }>, {}>;
228
- export declare class EvaluationResponse extends EvaluationResponse_base {
229
- }
230
- export type EvaluationResponseFor<Questions extends EvaluationQuestions> = Omit<EvaluationResponse, "answers"> & {
231
- readonly answers: AnswersFor<Questions>;
232
- };
233
- export declare function request<const Model extends EvaluationModel, const Questions extends EvaluationQuestions>(input: EvaluationRequestInput<Model, Questions>): EvaluationRequestFor<EvaluationModelOptions<Model>, Questions>;
234
- export declare function request(input: EvaluationRequest): EvaluationRequest;
235
- export declare function request(input: EvaluationRequest | EvaluationRequestInput): EvaluationRequest;
236
- export declare function run<const Model extends EvaluationModel, const Questions extends EvaluationQuestions>(input: EvaluationRequestInput<Model, Questions>): Effect.Effect<EvaluationResponseFor<Questions>, AIError, Service>;
237
- export declare function run(input: EvaluationRequest): Effect.Effect<EvaluationResponse, AIError, Service>;
238
- export declare const Evaluation: {
239
- readonly request: typeof request;
240
- readonly run: typeof run;
241
- };
242
- export {};
@@ -1,108 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import { tryRequest } from "../media-model.js";
3
- import { AIError, HttpOptions, ModelID, ProviderID, ProviderMetadata, Usage, } from "../schema/index.js";
4
- import { EvaluationClient, Service } from "./evaluation-client.js";
5
- export const EvaluationInput = Schema.Union([Schema.String, Schema.JsonObject, Schema.Array(Schema.Json)]);
6
- const EvaluationCriterion = Schema.NullOr(EvaluationInput);
7
- const ChoiceCriteria = Schema.Record(Schema.String, EvaluationCriterion).pipe(Schema.refine((x) => Object.keys(x).length > 0, {
8
- message: "Choice criteria must be a nonempty option map",
9
- }));
10
- export const ChoiceQuestion = Schema.Struct({
11
- type: Schema.Literal("choice"),
12
- instructions: EvaluationInput,
13
- criteria: ChoiceCriteria,
14
- });
15
- export const ScoreQuestion = Schema.Struct({
16
- type: Schema.Literal("score"),
17
- instructions: EvaluationInput,
18
- criteria: Schema.Array(EvaluationCriterion).check(Schema.isMinLength(2)),
19
- });
20
- export const BooleanQuestion = Schema.Struct({
21
- type: Schema.Literal("boolean"),
22
- instructions: EvaluationInput,
23
- criteria: Schema.optional(Schema.Struct({
24
- true: Schema.optional(EvaluationCriterion),
25
- false: Schema.optional(EvaluationCriterion),
26
- })),
27
- });
28
- export const EvaluationQuestion = Schema.Union([ChoiceQuestion, ScoreQuestion, BooleanQuestion]).pipe(Schema.toTaggedUnion("type"));
29
- const EvaluationQuestions = Schema.Record(Schema.String, EvaluationQuestion).pipe(Schema.refine((x) => Object.keys(x).length > 0, {
30
- message: "Evaluation questions must be a nonempty map",
31
- }));
32
- const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
33
- export const ChoiceAnswer = Schema.Struct({
34
- type: Schema.Literal("choice"),
35
- choice: Schema.String,
36
- probabilities: Schema.optional(Schema.Record(Schema.String, Probability)),
37
- confidence: Schema.optional(Probability),
38
- });
39
- export const ScoreAnswer = Schema.Struct({
40
- type: Schema.Literal("score"),
41
- score: Schema.Number,
42
- probabilities: Schema.optional(Schema.Record(Schema.String, Probability)),
43
- confidence: Schema.optional(Probability),
44
- });
45
- export const BooleanAnswer = Schema.Struct({
46
- type: Schema.Literal("boolean"),
47
- probability: Probability,
48
- });
49
- export const EvaluationAnswer = Schema.Union([ChoiceAnswer, ScoreAnswer, BooleanAnswer]).pipe(Schema.toTaggedUnion("type"));
50
- export class EvaluationModel {
51
- id;
52
- provider;
53
- route;
54
- http;
55
- constructor(input) {
56
- this.id = input.id;
57
- this.provider = input.provider;
58
- this.route = input.route;
59
- this.http = input.http;
60
- }
61
- static make(input) {
62
- return new EvaluationModel({
63
- id: ModelID.make(input.id),
64
- provider: ProviderID.make(input.provider),
65
- route: input.route,
66
- http: input.http,
67
- });
68
- }
69
- }
70
- export const EvaluationModelSchema = Schema.declare((value) => value instanceof EvaluationModel, {
71
- expected: "Evaluation.Model",
72
- });
73
- export class EvaluationRequest extends Schema.Class("Evaluation.Request")({
74
- model: EvaluationModelSchema,
75
- state: EvaluationInput,
76
- questions: EvaluationQuestions,
77
- options: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
78
- http: Schema.optional(HttpOptions),
79
- }) {
80
- }
81
- export class EvaluationRounding extends Schema.Class("Evaluation.Rounding")({
82
- probabilityDecimals: Schema.optional(Schema.Int),
83
- scoreDecimals: Schema.optional(Schema.Int),
84
- }) {
85
- }
86
- export class EvaluationResponse extends Schema.Class("Evaluation.Response")({
87
- model: ModelID,
88
- answers: Schema.Record(Schema.String, EvaluationAnswer),
89
- usage: Schema.optional(Usage),
90
- rounding: Schema.optional(EvaluationRounding),
91
- providerMetadata: Schema.optional(ProviderMetadata),
92
- }) {
93
- }
94
- export function request(input) {
95
- if (input instanceof EvaluationRequest)
96
- return input;
97
- return new EvaluationRequest({
98
- ...input,
99
- http: HttpOptions.make(input.http),
100
- });
101
- }
102
- export function run(input) {
103
- return tryRequest(() => request(input)).pipe(Effect.flatMap(EvaluationClient.evaluate));
104
- }
105
- export const Evaluation = {
106
- request,
107
- run,
108
- };
@@ -1,23 +0,0 @@
1
- import { EvaluationModel, EvaluationResponse, type EvaluationRequestFor } from "./evaluation.js";
2
- import { MediaProtocol } from "../route/media-protocol.js";
3
- import { MediaRoute } from "../route/media.js";
4
- import { type OpenString } from "../schema/index.js";
5
- export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
6
- export declare const PATH = "/decisions";
7
- /** Native body fields, sent as given. */
8
- export type OpenAIDecisionOptions = {
9
- readonly prompt_cache_key?: string;
10
- readonly prompt_cache_options?: Readonly<{
11
- mode?: OpenString<"implicit" | "explicit">;
12
- ttl?: OpenString<"30m">;
13
- }>;
14
- readonly safety_identifier?: string;
15
- } & Record<string, unknown>;
16
- type Request = EvaluationRequestFor<OpenAIDecisionOptions>;
17
- export declare const protocol: MediaProtocol.Inline<Request, EvaluationResponse>;
18
- export declare const model: (input: MediaRoute.ModelInput) => EvaluationModel<OpenAIDecisionOptions>;
19
- export declare const OpenAIDecisions: {
20
- readonly protocol: MediaProtocol.Inline<Request, EvaluationResponse>;
21
- readonly model: typeof model;
22
- };
23
- export {};
@@ -1,115 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import { EvaluationModel, EvaluationResponse, EvaluationRounding, } from "./evaluation.js";
3
- import { OpenResponses } from "../protocols/open-responses.js";
4
- import { Endpoint } from "../route/endpoint.js";
5
- import { MediaProtocol } from "../route/media-protocol.js";
6
- import { MediaRoute } from "../route/media.js";
7
- import { ModelID, mergeJsonRecords } from "../schema/index.js";
8
- import { encodeJson } from "../utils/json.js";
9
- const route = MediaProtocol.identity({ id: "openai-decisions", name: "OpenAI Decisions", provider: "openai" });
10
- export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
11
- export const PATH = "/decisions";
12
- const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
13
- const Answer = Schema.Union([
14
- Schema.Struct({ type: Schema.Literal("predicate"), name: Schema.String, probability: Probability }),
15
- Schema.Struct({
16
- type: Schema.Literal("choice"),
17
- name: Schema.String,
18
- choice: Schema.String,
19
- probabilities: Schema.Array(Schema.Struct({ value: Schema.String, probability: Probability })),
20
- confidence: Schema.optional(Probability),
21
- }),
22
- Schema.Struct({
23
- type: Schema.Literal("score"),
24
- name: Schema.String,
25
- score: Schema.Number,
26
- probabilities: Schema.Array(Schema.Struct({ value: Schema.Int, probability: Probability })),
27
- confidence: Schema.optional(Probability),
28
- }),
29
- Schema.Struct({ type: Schema.Literal("refusal"), name: Schema.String }),
30
- ]);
31
- const Response = Schema.Struct({
32
- model: Schema.String,
33
- answers: Schema.Array(Answer),
34
- usage: Schema.optional(OpenResponses.OpenResponsesUsage),
35
- });
36
- const fromRequest = Effect.fn("OpenAIDecisions.fromRequest")(function* (request) {
37
- const criteria = Object.entries(request.questions).flatMap(([name, question]) => question.type === "boolean" && question.criteria !== undefined ? [name] : []);
38
- if (criteria.length > 0)
39
- return yield* route.unsupported("evaluation.criteria", `${route.name} boolean questions take instructions only; remove criteria from ${criteria.join(", ")}`);
40
- return MediaProtocol.json({
41
- ...mergeJsonRecords(request.options, request.http?.body),
42
- model: request.model.id,
43
- input: typeof request.state === "string" ? request.state : [{ role: "user", content: json(request.state) }],
44
- questions: Object.entries(request.questions).map(([name, question]) => {
45
- const instructions = typeof question.instructions === "string" ? question.instructions : json(question.instructions);
46
- if (question.type === "boolean")
47
- return { type: "predicate", name, instructions };
48
- if (question.type === "choice")
49
- return {
50
- type: "choice",
51
- name,
52
- instructions,
53
- choices: Object.entries(question.criteria).map(([value, description]) => ({
54
- value,
55
- ...(description === null ? {} : { description: text(description) }),
56
- })),
57
- };
58
- return {
59
- type: "score",
60
- name,
61
- instructions,
62
- levels: question.criteria.map((level, index) => typeof level === "string"
63
- ? { label: level }
64
- : { label: String(index), ...(level === null ? {} : { description: text(level) }) }),
65
- };
66
- }),
67
- });
68
- });
69
- const json = (data) => [{ type: "input_json", data }];
70
- const text = (value) => (typeof value === "string" ? value : encodeJson(value));
71
- const decodeDocument = route.decodeJson(Response);
72
- const decodeResponse = Effect.fn("OpenAIDecisions.decodeResponse")(function* (response) {
73
- const output = yield* decodeDocument(response);
74
- const refused = output.value.answers.flatMap((answer) => (answer.type === "refusal" ? [answer.name] : []));
75
- if (refused.length > 0)
76
- return yield* output.contentPolicy(`${route.name} refused to answer ${refused.join(", ")}`);
77
- return new EvaluationResponse({
78
- model: ModelID.make(output.value.model),
79
- answers: Object.fromEntries(output.value.answers.flatMap((answer) => {
80
- if (answer.type === "refusal")
81
- return [];
82
- if (answer.type === "predicate")
83
- return [[answer.name, { type: "boolean", probability: answer.probability }]];
84
- const probabilities = Object.fromEntries(answer.probabilities.map((item) => [item.value, item.probability]));
85
- const confidence = answer.confidence === undefined ? {} : { confidence: answer.confidence };
86
- if (answer.type === "choice")
87
- return [[answer.name, { type: "choice", choice: answer.choice, probabilities, ...confidence }]];
88
- return [[answer.name, { type: "score", score: answer.score, probabilities, ...confidence }]];
89
- })),
90
- usage: OpenResponses.mapUsage(output.value.usage, "openai"),
91
- rounding: new EvaluationRounding({ probabilityDecimals: 2, scoreDecimals: 2 }),
92
- });
93
- });
94
- export const protocol = MediaProtocol.inline(route, {
95
- body: { from: fromRequest },
96
- response: { decode: decodeResponse },
97
- });
98
- export const model = (input) => {
99
- const composed = MediaRoute.inline({
100
- protocol,
101
- endpoint: Endpoint.path(PATH, { baseURL: input.baseURL ?? DEFAULT_BASE_URL }),
102
- auth: input.auth,
103
- headers: input.headers,
104
- });
105
- return EvaluationModel.make({
106
- id: input.id,
107
- provider: protocol.provider,
108
- http: input.http,
109
- route: { id: composed.id, evaluate: composed.generate },
110
- });
111
- };
112
- export const OpenAIDecisions = {
113
- protocol,
114
- model,
115
- };
@@ -1,114 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import { EvaluationModel, EvaluationResponse, EvaluationRounding, type EvaluationOptions, type EvaluationRequestFor } from "./evaluation.js";
3
- import { type Definition as AuthDefinition } from "../route/auth.js";
4
- import { AIError, HttpOptions, ModelID } from "../schema/index.js";
5
- export declare const Response: Schema.Struct<{
6
- readonly model: Schema.String;
7
- readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
8
- readonly type: Schema.Literal<"noul">;
9
- readonly noul: Schema.Number;
10
- }>, Schema.Struct<{
11
- readonly type: Schema.Literal<"choice">;
12
- readonly choice: Schema.String;
13
- readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
14
- readonly confidence: Schema.optional<Schema.Number>;
15
- }>, Schema.Struct<{
16
- readonly type: Schema.Literal<"score">;
17
- readonly score: Schema.Number;
18
- readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
19
- readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
20
- readonly confidence: Schema.optional<Schema.Number>;
21
- }>]>>;
22
- readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
23
- readonly input_tokens: Schema.optional<Schema.Number>;
24
- readonly output_tokens: Schema.optional<Schema.Number>;
25
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
26
- readonly id: Schema.optional<Schema.String>;
27
- readonly provider: Schema.optional<Schema.String>;
28
- readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
29
- }>;
30
- export interface ModelInput {
31
- readonly id: string | ModelID;
32
- readonly provider: string;
33
- readonly providerMetadataKey: string;
34
- readonly auth: AuthDefinition;
35
- readonly baseURL: string;
36
- readonly headers?: Record<string, string>;
37
- readonly http?: HttpOptions;
38
- readonly rounding?: EvaluationRounding;
39
- }
40
- export declare const jevRounding: EvaluationRounding;
41
- /** The System One request body without `model`, with `boolean` questions lowered to native `noul`. */
42
- export declare const encodeInput: (req: EvaluationRequestFor) => Effect.Effect<{
43
- readonly [x: string]: unknown;
44
- readonly state: string | readonly Schema.Json[] | {
45
- readonly [x: string]: Schema.Json;
46
- };
47
- readonly questions: {
48
- readonly [x: string]: {
49
- readonly type: "choice";
50
- readonly instructions: string | readonly Schema.Json[] | {
51
- readonly [x: string]: Schema.Json;
52
- };
53
- readonly criteria: {
54
- readonly [x: string]: string | readonly Schema.Json[] | {
55
- readonly [x: string]: Schema.Json;
56
- } | null;
57
- };
58
- } | {
59
- readonly type: "score";
60
- readonly instructions: string | readonly Schema.Json[] | {
61
- readonly [x: string]: Schema.Json;
62
- };
63
- readonly criteria: readonly (string | readonly Schema.Json[] | {
64
- readonly [x: string]: Schema.Json;
65
- } | null)[];
66
- } | {
67
- readonly type: "noul";
68
- readonly instructions: string | readonly Schema.Json[] | {
69
- readonly [x: string]: Schema.Json;
70
- };
71
- readonly criteria?: {
72
- readonly true?: string | readonly Schema.Json[] | {
73
- readonly [x: string]: Schema.Json;
74
- } | null | undefined;
75
- readonly false?: string | readonly Schema.Json[] | {
76
- readonly [x: string]: Schema.Json;
77
- } | null | undefined;
78
- } | undefined;
79
- };
80
- };
81
- }, AIError, never>;
82
- export declare const toResponse: (data: typeof Response.Type, providerMetadataKey: string, rounding?: EvaluationRounding) => EvaluationResponse;
83
- export declare const model: <Options extends EvaluationOptions = EvaluationOptions>(cfg: ModelInput) => EvaluationModel<Options>;
84
- export declare const SystemOne: {
85
- readonly Response: Schema.Struct<{
86
- readonly model: Schema.String;
87
- readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
88
- readonly type: Schema.Literal<"noul">;
89
- readonly noul: Schema.Number;
90
- }>, Schema.Struct<{
91
- readonly type: Schema.Literal<"choice">;
92
- readonly choice: Schema.String;
93
- readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
94
- readonly confidence: Schema.optional<Schema.Number>;
95
- }>, Schema.Struct<{
96
- readonly type: Schema.Literal<"score">;
97
- readonly score: Schema.Number;
98
- readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
99
- readonly legend: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
100
- readonly confidence: Schema.optional<Schema.Number>;
101
- }>]>>;
102
- readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
103
- readonly input_tokens: Schema.optional<Schema.Number>;
104
- readonly output_tokens: Schema.optional<Schema.Number>;
105
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
106
- readonly id: Schema.optional<Schema.String>;
107
- readonly provider: Schema.optional<Schema.String>;
108
- readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
109
- }>;
110
- readonly encodeInput: typeof encodeInput;
111
- readonly toResponse: typeof toResponse;
112
- readonly model: typeof model;
113
- readonly jevRounding: EvaluationRounding;
114
- };