@opencode/ai 2.2.3 → 2.2.4
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 +75 -76
- package/dist/effect.d.ts +45 -3
- package/dist/effect.js +24 -3
- package/dist/index.d.ts +468 -1158
- package/dist/index.js +22 -20
- package/dist/llm.d.ts +2 -1
- package/dist/llm.js +2 -0
- package/dist/protocols/xai-responses.js +1 -1
- package/dist/route/client.d.ts +0 -2
- package/dist/route/client.js +1 -5
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import { Effect, Layer, ManagedRuntime, Schema, Stream } from "effect";
|
|
|
2
2
|
import { AIClient } from "./ai-client.js";
|
|
3
3
|
import { Decision } from "./decision.js";
|
|
4
4
|
import { Image } from "./image.js";
|
|
5
|
-
import { LLM } from "./
|
|
5
|
+
import { LLM } from "./llm.js";
|
|
6
6
|
import { Media } from "./media.js";
|
|
7
|
-
import {
|
|
7
|
+
import {} from "./route/client.js";
|
|
8
8
|
import { RequestExecutor } from "./route/executor.js";
|
|
9
9
|
import { AIError, InvalidRequestError, LanguageModel, } from "./schema/index.js";
|
|
10
10
|
import { Speech } from "./speech.js";
|
|
@@ -28,17 +28,17 @@ export const make = (options = {}) => {
|
|
|
28
28
|
const runtime = ManagedRuntime.make(Layer.merge(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer),
|
|
29
29
|
// `R` is only inferred from `clients`, so it is `never` whenever `clients` is omitted.
|
|
30
30
|
(options.clients ?? Layer.empty)));
|
|
31
|
-
/** Run any package Effect (for example `
|
|
31
|
+
/** Run any package Effect (for example `ai.compact(...)` from `@opencode/ai/effect`) inside this runtime. */
|
|
32
32
|
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
|
|
33
33
|
const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
|
|
34
34
|
function generateObject(input, options) {
|
|
35
35
|
return run("schema" in input ? LLM.generateObject(input) : LLM.generateObject(input), options);
|
|
36
36
|
}
|
|
37
|
-
// The overloads pair each request type with its mechanism; `
|
|
37
|
+
// The overloads pair each request type with its mechanism; `LLM.compact` checks the route's capability at runtime.
|
|
38
38
|
function compact(request, options) {
|
|
39
39
|
return options?.mechanism === "trigger"
|
|
40
|
-
? run(
|
|
41
|
-
: run(
|
|
40
|
+
? run(LLM.compact(request, options), options)
|
|
41
|
+
: run(LLM.compact(request, options), options);
|
|
42
42
|
}
|
|
43
43
|
const handle = (generation) => ({
|
|
44
44
|
...generation.snapshot,
|
|
@@ -77,18 +77,16 @@ export const make = (options = {}) => {
|
|
|
77
77
|
catch: (cause) => fileError(`Failed to write media file ${path}`, cause),
|
|
78
78
|
}))), options);
|
|
79
79
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
canCompact: LLMClient.canCompact,
|
|
91
|
-
},
|
|
80
|
+
request: LLM.request,
|
|
81
|
+
generate: (input, options) => run(LLM.generate(input, options), options),
|
|
82
|
+
stream: (input, options) => iterate(LLM.stream(input, options), options),
|
|
83
|
+
/** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
|
|
84
|
+
loop: (input, options) => iterate(LLM.loop(input, options), options),
|
|
85
|
+
/** Decode the model's output against `schema` (or `jsonSchema`, unvalidated). */
|
|
86
|
+
generateObject,
|
|
87
|
+
/** Compact a Responses request: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
|
|
88
|
+
compact,
|
|
89
|
+
canCompact: LLM.canCompact,
|
|
92
90
|
image: {
|
|
93
91
|
request: Image.request,
|
|
94
92
|
generate: (input, options) => run(Image.generate(input, options), options),
|
|
@@ -135,7 +133,11 @@ export const tool = (config) => {
|
|
|
135
133
|
catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
|
|
136
134
|
})));
|
|
137
135
|
};
|
|
138
|
-
/** Default client over `RequestExecutor.fetchLayer
|
|
136
|
+
/** Default client over `RequestExecutor.fetchLayer`; the runtime builds its layer on first use and holds nothing to dispose. */
|
|
139
137
|
export const ai = make();
|
|
140
|
-
export { AIError } from "./schema/index.js";
|
|
141
138
|
export * as AI from "./index.js";
|
|
139
|
+
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
140
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
141
|
+
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
142
|
+
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
143
|
+
export { Media } from "./media.js";
|
package/dist/llm.d.ts
CHANGED
|
@@ -276,4 +276,5 @@ export interface GenerateObjectDynamicOptions<SelectedLanguageModel extends Lang
|
|
|
276
276
|
*/
|
|
277
277
|
export declare function generateObject<const SelectedLanguageModel extends LanguageModel, S extends ToolSchema<any>>(options: GenerateObjectOptions<S, SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<Schema.Schema.Type<S>>, AIError, Service>;
|
|
278
278
|
export declare function generateObject<const SelectedLanguageModel extends LanguageModel>(options: GenerateObjectDynamicOptions<SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<unknown>, AIError, Service>;
|
|
279
|
-
export {};
|
|
279
|
+
export { canCompact, compact } from "./route/client.js";
|
|
280
|
+
export * as LLM from "./llm.js";
|
package/dist/llm.js
CHANGED
|
@@ -102,3 +102,5 @@ export function generateObject(options) {
|
|
|
102
102
|
const { jsonSchema, ...rest } = options;
|
|
103
103
|
return runGenerateObject(rest, tool({ description: GENERATE_OBJECT_TOOL_DESCRIPTION, jsonSchema }));
|
|
104
104
|
}
|
|
105
|
+
export { canCompact, compact } from "./route/client.js";
|
|
106
|
+
export * as LLM from "./llm.js";
|
|
@@ -50,7 +50,7 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
|
|
|
50
50
|
operation: "in-band-compaction",
|
|
51
51
|
provider: request.model.provider,
|
|
52
52
|
route: request.model.route.id,
|
|
53
|
-
message: "xAI requires explicit compaction through
|
|
53
|
+
message: "xAI requires explicit compaction through ai.compact; automatic context management is not supported",
|
|
54
54
|
});
|
|
55
55
|
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
56
56
|
const body = yield* OpenResponses.fromRequestWithAdapter(request, adapter);
|
package/dist/route/client.d.ts
CHANGED
|
@@ -220,8 +220,6 @@ export declare const Route: {
|
|
|
220
220
|
readonly make: typeof make;
|
|
221
221
|
};
|
|
222
222
|
export declare const LLMClient: {
|
|
223
|
-
readonly canCompact: typeof canCompact;
|
|
224
|
-
readonly compact: typeof compact;
|
|
225
223
|
readonly Service: typeof LLMClientService;
|
|
226
224
|
readonly layer: Layer.Layer<LLMClientService, never, RequestExecutor.RequestExecutorService>;
|
|
227
225
|
readonly stream: typeof stream;
|
package/dist/route/client.js
CHANGED
|
@@ -134,9 +134,7 @@ function makeFromTransport(input) {
|
|
|
134
134
|
id: id ?? routeInput.id,
|
|
135
135
|
provider: provider ?? routeInput.provider,
|
|
136
136
|
providerMetadataKey: providerMetadataKey ??
|
|
137
|
-
(provider !== undefined && provider !== routeInput.provider
|
|
138
|
-
? provider
|
|
139
|
-
: routeInput.providerMetadataKey),
|
|
137
|
+
(provider !== undefined && provider !== routeInput.provider ? provider : routeInput.providerMetadataKey),
|
|
140
138
|
auth: auth ?? routeInput.auth,
|
|
141
139
|
endpoint: endpoint ? Endpoint.merge(routeInput.endpoint, endpoint) : routeInput.endpoint,
|
|
142
140
|
transport: transport ?? routeInput.transport,
|
|
@@ -313,8 +311,6 @@ export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
313
311
|
}));
|
|
314
312
|
export const Route = { make };
|
|
315
313
|
export const LLMClient = {
|
|
316
|
-
canCompact,
|
|
317
|
-
compact,
|
|
318
314
|
Service,
|
|
319
315
|
layer,
|
|
320
316
|
stream,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -520,7 +520,7 @@
|
|
|
520
520
|
"devDependencies": {
|
|
521
521
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
522
522
|
"@effect/platform-node": "4.0.6",
|
|
523
|
-
"@opencode/http-recorder": "2.2.
|
|
523
|
+
"@opencode/http-recorder": "2.2.4",
|
|
524
524
|
"@tsconfig/bun": "1.0.9",
|
|
525
525
|
"@types/bun": "1.4.3",
|
|
526
526
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -530,7 +530,7 @@
|
|
|
530
530
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
531
531
|
"@smithy/eventstream-codec": "4.2.14",
|
|
532
532
|
"@smithy/util-utf8": "4.2.2",
|
|
533
|
-
"@opencode/schema": "2.2.
|
|
533
|
+
"@opencode/schema": "2.2.4",
|
|
534
534
|
"aws4fetch": "1.0.20",
|
|
535
535
|
"effect": "4.0.6",
|
|
536
536
|
"google-auth-library": "10.5.0"
|