@opencode/ai 0.0.0-dev-21798 → 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.
- package/README.md +55 -55
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +452 -0
- package/dist/decision.js +143 -0
- package/dist/experimental.d.ts +0 -3
- package/dist/experimental.js +0 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/promise.d.ts +10 -1
- package/dist/promise.js +5 -0
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +108 -0
- package/dist/protocols/system-one.d.ts +99 -0
- package/dist/protocols/system-one.js +228 -0
- package/dist/providers/baseten.d.ts +4 -10
- package/dist/providers/baseten.js +21 -8
- package/dist/providers/cloudflare-ai-gateway.d.ts +1 -3
- package/dist/providers/cloudflare-ai-gateway.js +10 -10
- package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
- package/dist/providers/cloudflare-workers-ai.js +11 -12
- package/dist/providers/digitalocean.d.ts +3 -9
- package/dist/providers/digitalocean.js +10 -10
- package/dist/providers/openai.d.ts +5 -10
- package/dist/providers/openai.js +11 -7
- package/dist/providers/opencode.d.ts +3 -9
- package/dist/providers/opencode.js +9 -9
- package/dist/providers/openrouter.d.ts +4 -10
- package/dist/providers/openrouter.js +8 -9
- package/dist/providers/typesafe-ai.d.ts +3 -9
- package/dist/providers/typesafe-ai.js +9 -9
- package/dist/providers/vercel-ai-gateway.d.ts +4 -15
- package/dist/providers/vercel-ai-gateway.js +13 -80
- package/dist/route/decision.d.ts +57 -0
- package/dist/route/decision.js +74 -0
- package/package.json +3 -3
- package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
- package/dist/experimental/cloudflare-run-evaluation.js +0 -43
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/openai-decisions.d.ts +0 -23
- package/dist/experimental/openai-decisions.js +0 -115
- package/dist/experimental/system-one.d.ts +0 -114
- package/dist/experimental/system-one.js +0 -140
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { Headers, HttpClientRequest } from "effect/http";
|
|
3
|
-
import { ChoiceQuestion, EvaluationInput, EvaluationModel, EvaluationResponse, EvaluationRounding, ScoreQuestion, } from "./evaluation.js";
|
|
4
|
-
import { Auth } from "../route/auth.js";
|
|
5
|
-
import { RequestExecutor } from "../route/executor.js";
|
|
6
|
-
import { JsonObject, ProviderShared } from "../protocols/shared.js";
|
|
7
|
-
import { AIError, HttpOptions, InvalidProviderOutputError, InvalidRequestError, ModelID, ProviderMetadata, Usage, mergeJsonRecords, } from "../schema/index.js";
|
|
8
|
-
import { encodeJson } from "../utils/json.js";
|
|
9
|
-
const Noul = Schema.Struct({
|
|
10
|
-
type: Schema.Literal("noul"),
|
|
11
|
-
instructions: EvaluationInput,
|
|
12
|
-
criteria: Schema.optional(Schema.Struct({
|
|
13
|
-
true: Schema.optional(Schema.NullOr(EvaluationInput)),
|
|
14
|
-
false: Schema.optional(Schema.NullOr(EvaluationInput)),
|
|
15
|
-
})),
|
|
16
|
-
});
|
|
17
|
-
const Question = Schema.Union([
|
|
18
|
-
ChoiceQuestion.pipe(Schema.refine((x) => Object.keys(x.criteria).length <= 255, {
|
|
19
|
-
message: "System One Choice questions support at most 255 options",
|
|
20
|
-
})),
|
|
21
|
-
ScoreQuestion.pipe(Schema.refine((x) => x.criteria.length <= 10, {
|
|
22
|
-
message: "System One Score questions support at most 10 levels",
|
|
23
|
-
})),
|
|
24
|
-
Noul,
|
|
25
|
-
]);
|
|
26
|
-
const Input = Schema.StructWithRest(Schema.Struct({
|
|
27
|
-
state: EvaluationInput,
|
|
28
|
-
questions: Schema.Record(Schema.String, Question),
|
|
29
|
-
}), [JsonObject]);
|
|
30
|
-
const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
|
|
31
|
-
const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Probability });
|
|
32
|
-
const Choice = Schema.Struct({
|
|
33
|
-
type: Schema.Literal("choice"),
|
|
34
|
-
choice: Schema.String,
|
|
35
|
-
probabilities: Schema.Record(Schema.String, Probability),
|
|
36
|
-
confidence: Schema.optional(Probability),
|
|
37
|
-
});
|
|
38
|
-
const Score = Schema.Struct({
|
|
39
|
-
type: Schema.Literal("score"),
|
|
40
|
-
score: Schema.Number,
|
|
41
|
-
probabilities: Schema.Record(Schema.String, Probability),
|
|
42
|
-
legend: Schema.optional(Schema.Record(Schema.String, Schema.Json)),
|
|
43
|
-
confidence: Schema.optional(Probability),
|
|
44
|
-
});
|
|
45
|
-
const Answer = Schema.Union([NoulAnswer, Choice, Score]).pipe(Schema.toTaggedUnion("type"));
|
|
46
|
-
const NativeUsage = Schema.StructWithRest(Schema.Struct({
|
|
47
|
-
input_tokens: Schema.optional(Schema.Number),
|
|
48
|
-
output_tokens: Schema.optional(Schema.Number),
|
|
49
|
-
}), [JsonObject]);
|
|
50
|
-
export const Response = Schema.Struct({
|
|
51
|
-
model: Schema.String,
|
|
52
|
-
answers: Schema.Record(Schema.String, Answer),
|
|
53
|
-
usage: Schema.optional(NativeUsage),
|
|
54
|
-
id: Schema.optional(Schema.String),
|
|
55
|
-
provider: Schema.optional(Schema.String),
|
|
56
|
-
provider_metadata: Schema.optional(ProviderMetadata),
|
|
57
|
-
});
|
|
58
|
-
export const jevRounding = new EvaluationRounding({ probabilityDecimals: 2, scoreDecimals: 2 });
|
|
59
|
-
/** The System One request body without `model`, with `boolean` questions lowered to native `noul`. */
|
|
60
|
-
export const encodeInput = (req) => Schema.encodeUnknownEffect(Input)({
|
|
61
|
-
...mergeJsonRecords(req.options, req.http?.body),
|
|
62
|
-
state: req.state,
|
|
63
|
-
questions: Object.fromEntries(Object.entries(req.questions).map(([id, x]) => [id, x.type === "boolean" ? { ...x, type: "noul" } : x])),
|
|
64
|
-
}).pipe(Effect.mapError((cause) => new AIError({ reason: new InvalidRequestError({ message: cause.message, cause }) })));
|
|
65
|
-
export const toResponse = (data, providerMetadataKey, rounding) => {
|
|
66
|
-
const legend = {};
|
|
67
|
-
const answers = Object.fromEntries(Object.entries(data.answers).map(([id, answer]) => {
|
|
68
|
-
if (answer.type === "noul")
|
|
69
|
-
return [id, { type: "boolean", probability: answer.noul }];
|
|
70
|
-
if (answer.type === "choice") {
|
|
71
|
-
return [
|
|
72
|
-
id,
|
|
73
|
-
{
|
|
74
|
-
type: "choice",
|
|
75
|
-
choice: answer.choice,
|
|
76
|
-
probabilities: answer.probabilities,
|
|
77
|
-
...(answer.confidence === undefined ? {} : { confidence: answer.confidence }),
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
if (answer.legend !== undefined)
|
|
82
|
-
legend[id] = answer.legend;
|
|
83
|
-
return [
|
|
84
|
-
id,
|
|
85
|
-
{
|
|
86
|
-
type: "score",
|
|
87
|
-
score: answer.score,
|
|
88
|
-
probabilities: answer.probabilities,
|
|
89
|
-
...(answer.confidence === undefined ? {} : { confidence: answer.confidence }),
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
}));
|
|
93
|
-
const meta = {
|
|
94
|
-
...(data.id === undefined ? {} : { responseId: data.id }),
|
|
95
|
-
...(data.provider === undefined ? {} : { provider: data.provider }),
|
|
96
|
-
...data.provider_metadata?.[providerMetadataKey],
|
|
97
|
-
...(Object.keys(legend).length === 0 ? {} : { legend }),
|
|
98
|
-
};
|
|
99
|
-
return new EvaluationResponse({
|
|
100
|
-
model: ModelID.make(data.model),
|
|
101
|
-
answers,
|
|
102
|
-
usage: data.usage
|
|
103
|
-
? new Usage({
|
|
104
|
-
inputTokens: data.usage.input_tokens,
|
|
105
|
-
outputTokens: data.usage.output_tokens,
|
|
106
|
-
totalTokens: ProviderShared.totalTokens(data.usage.input_tokens, data.usage.output_tokens, undefined),
|
|
107
|
-
providerMetadata: { [providerMetadataKey]: data.usage },
|
|
108
|
-
})
|
|
109
|
-
: undefined,
|
|
110
|
-
rounding,
|
|
111
|
-
providerMetadata: Object.keys(meta).length === 0 ? undefined : { [providerMetadataKey]: meta },
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
export const model = (cfg) => EvaluationModel.make({
|
|
115
|
-
id: cfg.id,
|
|
116
|
-
provider: cfg.provider,
|
|
117
|
-
http: cfg.http,
|
|
118
|
-
route: {
|
|
119
|
-
id: "system-one",
|
|
120
|
-
evaluate: (req, send) => Effect.gen(function* () {
|
|
121
|
-
const url = new URL(`${cfg.baseURL.replace(/\/$/, "")}/systemone`);
|
|
122
|
-
Object.entries(req.http?.query ?? {}).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
123
|
-
const body = encodeJson({ ...(yield* encodeInput(req)), model: req.model.id });
|
|
124
|
-
const headers = yield* Auth.toEffect(cfg.auth)({
|
|
125
|
-
request: req,
|
|
126
|
-
method: "POST",
|
|
127
|
-
url: url.toString(),
|
|
128
|
-
body,
|
|
129
|
-
headers: Headers.fromInput({ ...cfg.headers, ...req.http?.headers }),
|
|
130
|
-
});
|
|
131
|
-
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
132
|
-
const http = RequestExecutor.responseHttp(res);
|
|
133
|
-
const fail = (message, cause, body) => new AIError({ reason: new InvalidProviderOutputError({ route: "system-one", message, body, http, cause }) });
|
|
134
|
-
const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the System One response", cause)));
|
|
135
|
-
const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("System One returned an invalid response", cause, text)));
|
|
136
|
-
return toResponse(data, cfg.providerMetadataKey, cfg.rounding);
|
|
137
|
-
}),
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
export const SystemOne = { Response, encodeInput, toResponse, model, jevRounding };
|