@opencode/ai 0.0.0-dev-21798 → 0.0.0-dev-21800

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 (70) 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/alibaba-messages.d.ts +34 -0
  15. package/dist/protocols/anthropic-messages.d.ts +102 -0
  16. package/dist/protocols/anthropic-messages.js +32 -8
  17. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  18. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  19. package/dist/protocols/index.d.ts +3 -0
  20. package/dist/protocols/index.js +3 -0
  21. package/dist/protocols/meta-messages.d.ts +34 -0
  22. package/dist/protocols/meta-messages.js +12 -0
  23. package/dist/protocols/openai-decisions.d.ts +22 -0
  24. package/dist/protocols/openai-decisions.js +108 -0
  25. package/dist/protocols/shared.d.ts +1 -1
  26. package/dist/protocols/shared.js +2 -2
  27. package/dist/protocols/system-one.d.ts +99 -0
  28. package/dist/protocols/system-one.js +228 -0
  29. package/dist/protocols/zai-messages.d.ts +34 -0
  30. package/dist/providers/alibaba.d.ts +34 -0
  31. package/dist/providers/amazon-bedrock-mantle.d.ts +34 -0
  32. package/dist/providers/anthropic-compatible.d.ts +34 -0
  33. package/dist/providers/anthropic.d.ts +34 -0
  34. package/dist/providers/baseten.d.ts +4 -10
  35. package/dist/providers/baseten.js +21 -8
  36. package/dist/providers/cloudflare-ai-gateway.d.ts +69 -3
  37. package/dist/providers/cloudflare-ai-gateway.js +10 -10
  38. package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
  39. package/dist/providers/cloudflare-workers-ai.js +11 -12
  40. package/dist/providers/digitalocean.d.ts +3 -9
  41. package/dist/providers/digitalocean.js +10 -10
  42. package/dist/providers/google-vertex-messages.d.ts +34 -0
  43. package/dist/providers/meta.d.ts +34 -0
  44. package/dist/providers/minimax.d.ts +34 -0
  45. package/dist/providers/moonshot.d.ts +34 -0
  46. package/dist/providers/openai.d.ts +5 -10
  47. package/dist/providers/openai.js +11 -7
  48. package/dist/providers/opencode.d.ts +3 -9
  49. package/dist/providers/opencode.js +9 -9
  50. package/dist/providers/openrouter.d.ts +4 -10
  51. package/dist/providers/openrouter.js +8 -9
  52. package/dist/providers/typesafe-ai.d.ts +3 -9
  53. package/dist/providers/typesafe-ai.js +9 -9
  54. package/dist/providers/vercel-ai-gateway.d.ts +4 -15
  55. package/dist/providers/vercel-ai-gateway.js +13 -80
  56. package/dist/providers/zai-coding-plan.d.ts +34 -0
  57. package/dist/route/client.js +11 -0
  58. package/dist/route/decision.d.ts +57 -0
  59. package/dist/route/decision.js +74 -0
  60. package/package.json +3 -3
  61. package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
  62. package/dist/experimental/cloudflare-run-evaluation.js +0 -43
  63. package/dist/experimental/evaluation-client.d.ts +0 -21
  64. package/dist/experimental/evaluation-client.js +0 -64
  65. package/dist/experimental/evaluation.d.ts +0 -242
  66. package/dist/experimental/evaluation.js +0 -108
  67. package/dist/experimental/openai-decisions.d.ts +0 -23
  68. package/dist/experimental/openai-decisions.js +0 -115
  69. package/dist/experimental/system-one.d.ts +0 -114
  70. package/dist/experimental/system-one.js +0 -140
@@ -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
- };
@@ -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 };