@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
package/README.md
CHANGED
|
@@ -39,11 +39,13 @@ live under `providerMetadata.vertex`. The default is still full-history replay w
|
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
const model = Google.configure({ apiKey }).interactions("gemini-3.8-flash")
|
|
42
|
-
const response =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const response =
|
|
43
|
+
yield *
|
|
44
|
+
LLM.generate({
|
|
45
|
+
model,
|
|
46
|
+
prompt: "Say hello.",
|
|
47
|
+
providerOptions: { thinkingLevel: "low", thinkingSummaries: "auto", store: true },
|
|
48
|
+
})
|
|
47
49
|
```
|
|
48
50
|
|
|
49
51
|
Interactions supports text output, streamed function calls, native tool results, thought signatures, and multimodal
|
|
@@ -146,75 +148,73 @@ usage reads Venice's `cache_creation_input_tokens` field.
|
|
|
146
148
|
The native package entrypoint is `@opencode/ai/providers/venice`. Image generation, embeddings, Responses, and
|
|
147
149
|
client-side E2EE are not implemented by this provider.
|
|
148
150
|
|
|
149
|
-
##
|
|
151
|
+
## Decisions
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
Decision models answer typed questions about an input: a yes/no `predicate` (a probability), a `choice` from listed
|
|
154
|
+
values, or a `score` on ordered levels, each with the probability of every option.
|
|
153
155
|
|
|
154
156
|
```ts
|
|
155
157
|
import { Effect } from "effect"
|
|
156
|
-
import {
|
|
157
|
-
import {
|
|
158
|
-
|
|
159
|
-
const model = TypeSafeAI.configure().experimental.evaluation("jev-latest")
|
|
158
|
+
import { Decision, DecisionClient, Media } from "@opencode/ai"
|
|
159
|
+
import { OpenAI } from "@opencode/ai/providers"
|
|
160
160
|
|
|
161
|
-
const program =
|
|
162
|
-
model,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
const program = Decision.generate({
|
|
162
|
+
model: OpenAI.configure().decision("gpt-6-luna"),
|
|
163
|
+
input: [
|
|
164
|
+
{ type: "text", text: "I was charged twice. Please refund the duplicate payment." },
|
|
165
|
+
{ type: "media", media: Media.url("https://example.com/receipt.png", { mediaType: "image/png" }) },
|
|
166
|
+
],
|
|
167
|
+
questions: [
|
|
168
|
+
{ name: "refund", type: "predicate", instructions: "Is the customer asking for a refund?" },
|
|
169
|
+
{
|
|
170
|
+
name: "department",
|
|
166
171
|
type: "choice",
|
|
167
172
|
instructions: "Which team should handle this?",
|
|
168
|
-
|
|
173
|
+
choices: [{ value: "billing", description: "Payments and refunds" }, { value: "technical" }],
|
|
169
174
|
},
|
|
170
|
-
|
|
175
|
+
{
|
|
176
|
+
name: "urgency",
|
|
171
177
|
type: "score",
|
|
172
178
|
instructions: "How urgent is this?",
|
|
173
|
-
|
|
179
|
+
levels: [{ label: "Can wait" }, { label: "Needs prompt attention" }, { label: "Blocking revenue" }],
|
|
174
180
|
},
|
|
175
|
-
|
|
176
|
-
},
|
|
181
|
+
],
|
|
177
182
|
})
|
|
178
183
|
|
|
179
|
-
const response = await Effect.runPromise(program.pipe(Effect.provide(
|
|
180
|
-
|
|
181
|
-
console.log(response.answers.department.choice)
|
|
182
|
-
console.log(response.answers.refund.probability)
|
|
184
|
+
const response = await Effect.runPromise(program.pipe(Effect.provide(DecisionClient.fetchLayer)))
|
|
185
|
+
const [refund, department] = response.answers
|
|
183
186
|
```
|
|
184
187
|
|
|
185
|
-
`
|
|
186
|
-
`
|
|
188
|
+
`input` is a JSON object or an ordered list of `text`, `json` and `media` parts. Answers come back in question order.
|
|
189
|
+
A question the host declines is `{ name, type: "error", reason: "refusal" }`; the other answers still come back.
|
|
190
|
+
Media goes wherever the host reads it, and a kind the host has no place for fails the call. Host-specific fields go in
|
|
191
|
+
`providerOptions`, typed by the selected model (OpenAI `promptCacheKey` and `safetyIdentifier`, OpenRouter
|
|
192
|
+
`provider` routing, Baseten `max_len`).
|
|
187
193
|
|
|
188
194
|
```ts
|
|
189
|
-
import {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
```ts
|
|
209
|
-
import { CloudflareAIGateway, CloudflareWorkersAI } from "@opencode/ai/providers"
|
|
210
|
-
|
|
211
|
-
CloudflareWorkersAI.configure({ accountId }).experimental.evaluation("@cf/cloudflare/clef")
|
|
212
|
-
CloudflareAIGateway.configure({ accountId }).experimental.evaluation("typesafe/jev")
|
|
195
|
+
import {
|
|
196
|
+
Baseten,
|
|
197
|
+
CloudflareAIGateway,
|
|
198
|
+
CloudflareWorkersAI,
|
|
199
|
+
DigitalOcean,
|
|
200
|
+
OpenCode,
|
|
201
|
+
OpenRouter,
|
|
202
|
+
TypeSafeAI,
|
|
203
|
+
VercelAIGateway,
|
|
204
|
+
} from "@opencode/ai/providers"
|
|
205
|
+
|
|
206
|
+
TypeSafeAI.configure().decision("jev-latest")
|
|
207
|
+
OpenCode.configure().decision("jev-1.13")
|
|
208
|
+
OpenRouter.configure().decision("typesafe/jev-1.13")
|
|
209
|
+
VercelAIGateway.configure().decision("typesafe-ai/jev")
|
|
210
|
+
Baseten.configure().decision("decision-models/baseten-elephant-9b-latest")
|
|
211
|
+
DigitalOcean.configure().decision("typesafe-jev-1.13.0")
|
|
212
|
+
CloudflareWorkersAI.configure({ accountId }).decision("@cf/cloudflare/clef")
|
|
213
|
+
CloudflareAIGateway.configure({ accountId }).decision("typesafe/jev")
|
|
213
214
|
```
|
|
214
215
|
|
|
215
|
-
|
|
216
|
-
`
|
|
217
|
-
the provider's rounded probabilities are returned unchanged.
|
|
216
|
+
OpenAI and Vercel AI Gateway use OpenAI's `/v1/decisions` API. TypeSafe, OpenCode, OpenRouter, Baseten and
|
|
217
|
+
DigitalOcean use System One (`/systemone`), and Cloudflare sends the System One body through `/ai/run`.
|
|
218
218
|
|
|
219
219
|
## Alibaba Cloud Model Studio
|
|
220
220
|
|
package/dist/ai-client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { RequestExecutor } from "./route/executor.js";
|
|
3
3
|
/** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
|
|
4
|
-
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
|
|
4
|
+
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
|
|
5
5
|
/** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
|
|
6
|
-
export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
|
|
6
|
+
export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
|
|
7
7
|
export type Services = Layer.Success<typeof layer>;
|
|
8
8
|
export * as AIClient from "./ai-client.js";
|
package/dist/ai-client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
|
+
import { DecisionClient } from "./decision-client.js";
|
|
2
3
|
import { ImageClient } from "./image-client.js";
|
|
3
4
|
import { LLMClient } from "./route/client.js";
|
|
4
5
|
import { RequestExecutor } from "./route/executor.js";
|
|
@@ -6,7 +7,7 @@ import { SpeechClient } from "./speech-client.js";
|
|
|
6
7
|
import { TranscriptionClient } from "./transcription-client.js";
|
|
7
8
|
import { VideoClient } from "./video-client.js";
|
|
8
9
|
/** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
|
|
9
|
-
export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer).pipe(Layer.provideMerge(executor));
|
|
10
|
+
export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer, DecisionClient.layer).pipe(Layer.provideMerge(executor));
|
|
10
11
|
/** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
|
|
11
12
|
export const layer = layerWith(RequestExecutor.fetchLayer);
|
|
12
13
|
export * as AIClient from "./ai-client.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import type { DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionResponseFor } from "./decision.js";
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import { AIError } from "./schema/index.js";
|
|
5
|
+
export type Execute = RequestExecutor.Interface["execute"];
|
|
6
|
+
export interface Interface {
|
|
7
|
+
readonly generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequestFor<Options, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError>;
|
|
8
|
+
}
|
|
9
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/DecisionClient", Interface>;
|
|
10
|
+
export declare class Service extends Service_base {
|
|
11
|
+
}
|
|
12
|
+
export declare const generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequestFor<Options, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
|
|
13
|
+
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
14
|
+
export declare const fetchLayer: Layer.Layer<import("./route/executor-service.js").RequestExecutorService | Service, never, never>;
|
|
15
|
+
export declare const DecisionClient: {
|
|
16
|
+
readonly Service: typeof Service;
|
|
17
|
+
readonly layer: Layer.Layer<Service, never, import("./route/executor-service.js").RequestExecutorService>;
|
|
18
|
+
readonly fetchLayer: Layer.Layer<import("./route/executor-service.js").RequestExecutorService | Service, never, never>;
|
|
19
|
+
readonly generate: typeof generate;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
3
|
+
import { AIError, InvalidProviderOutputError } from "./schema/index.js";
|
|
4
|
+
export class Service extends Context.Service()("@opencode/AI/DecisionClient") {
|
|
5
|
+
}
|
|
6
|
+
export const generate = (request) => Effect.flatMap(Service, (client) => client.generate(request));
|
|
7
|
+
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
8
|
+
const executor = yield* RequestExecutor.Service;
|
|
9
|
+
return Service.of({
|
|
10
|
+
generate: Effect.fnUntraced(function* (request) {
|
|
11
|
+
const route = request.model.route;
|
|
12
|
+
const response = yield* route.generate(request, executor.execute);
|
|
13
|
+
if (answersMatch(request.questions, response.answers))
|
|
14
|
+
return response;
|
|
15
|
+
return yield* new AIError({
|
|
16
|
+
reason: new InvalidProviderOutputError({
|
|
17
|
+
route: route.id,
|
|
18
|
+
message: "Decision answers do not match the requested questions",
|
|
19
|
+
cause: response.answers,
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}));
|
|
25
|
+
export const fetchLayer = layer.pipe(Layer.provideMerge(RequestExecutor.fetchLayer));
|
|
26
|
+
/** Host bugs (a missing or extra answer, an option that wasn't offered, a score off the scale) fail the whole call. */
|
|
27
|
+
const answersMatch = (questions, answers) => questions.length === answers.length &&
|
|
28
|
+
questions.every((question, index) => {
|
|
29
|
+
const answer = answers[index];
|
|
30
|
+
if (answer.name !== question.name)
|
|
31
|
+
return false;
|
|
32
|
+
if (answer.type === "error")
|
|
33
|
+
return true;
|
|
34
|
+
if (question.type === "predicate")
|
|
35
|
+
return answer.type === "predicate";
|
|
36
|
+
if (question.type === "choice") {
|
|
37
|
+
if (answer.type !== "choice")
|
|
38
|
+
return false;
|
|
39
|
+
const values = question.choices.map((choice) => choice.value);
|
|
40
|
+
return (values.includes(answer.choice) &&
|
|
41
|
+
sameMembers(values, answer.probabilities.map((item) => item.value)));
|
|
42
|
+
}
|
|
43
|
+
if (answer.type !== "score" || answer.score < 0 || answer.score > question.levels.length - 1)
|
|
44
|
+
return false;
|
|
45
|
+
return sameMembers(question.levels.map((_, level) => level), answer.probabilities.map((item) => item.value));
|
|
46
|
+
});
|
|
47
|
+
const sameMembers = (expected, received) => expected.length === received.length &&
|
|
48
|
+
new Set(received).size === received.length &&
|
|
49
|
+
received.every((item) => expected.includes(item));
|
|
50
|
+
export const DecisionClient = {
|
|
51
|
+
Service,
|
|
52
|
+
layer,
|
|
53
|
+
fetchLayer,
|
|
54
|
+
generate,
|
|
55
|
+
};
|