@opencode/ai 2.2.4 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
package/dist/image.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
|
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
6
|
-
import { AIError,
|
|
6
|
+
import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
7
7
|
import { ImageClient, Service } from "./image-client.js";
|
|
8
8
|
export class ImageModel extends MediaModel {
|
|
9
9
|
static fromRoute(route, input) {
|
|
@@ -20,18 +20,15 @@ export const ImageModelSchema = Schema.declare((value) => value instanceof Image
|
|
|
20
20
|
expected: "Image.Model",
|
|
21
21
|
});
|
|
22
22
|
export const ImageAspectRatio = Media.AspectRatio;
|
|
23
|
-
|
|
23
|
+
const ImageRequestSchema = Schema.Struct({
|
|
24
24
|
model: ImageModelSchema,
|
|
25
25
|
prompt: Schema.String,
|
|
26
|
-
/** Edit sources or style/subject references, in order. */
|
|
27
26
|
images: Schema.optional(Schema.Array(Media.AssetSchema)),
|
|
28
27
|
n: Schema.optional(Schema.Int),
|
|
29
28
|
aspect: Schema.optional(ImageAspectRatio),
|
|
30
29
|
resolution: Schema.optional(Schema.String),
|
|
31
30
|
providerOptions: Schema.optional(ProviderOptions),
|
|
32
|
-
|
|
33
|
-
}) {
|
|
34
|
-
}
|
|
31
|
+
});
|
|
35
32
|
// ---------------------------------------------------------------------------
|
|
36
33
|
// Response and events
|
|
37
34
|
// ---------------------------------------------------------------------------
|
|
@@ -87,15 +84,20 @@ const collectResponse = (events) => {
|
|
|
87
84
|
providerMetadata: finish.providerMetadata,
|
|
88
85
|
}));
|
|
89
86
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
const
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Request-shaped call API
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
/** Normalize image request input into a plain `ImageRequest`. */
|
|
91
|
+
export const request = (input) => ({
|
|
92
|
+
...input,
|
|
93
|
+
images: input.images?.map((image) => Media.make(image)),
|
|
94
|
+
});
|
|
95
|
+
const validate = Schema.decodeUnknownSync(ImageRequestSchema);
|
|
96
|
+
const requestEffect = (input) => tryRequest(() => {
|
|
97
|
+
const normalized = request(input);
|
|
98
|
+
validate(normalized);
|
|
99
|
+
return normalized;
|
|
100
|
+
});
|
|
99
101
|
export function generate(input, options) {
|
|
100
102
|
return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.generate(request, options)));
|
|
101
103
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,22 +7,20 @@ import { LLM } from "./llm.js";
|
|
|
7
7
|
import { Media } from "./media.js";
|
|
8
8
|
import { type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type StreamOptions, type TriggerCompactOptions } from "./route/client.js";
|
|
9
9
|
import { RequestExecutor } from "./route/executor.js";
|
|
10
|
-
import { LanguageModel, type CompactionCheckpointResponse, type CompactionResponse, type
|
|
11
|
-
import type {
|
|
10
|
+
import { LanguageModel, type CompactionCheckpointResponse, type CompactionResponse, type LLMEvent, type LLMResponse } from "./schema/index.js";
|
|
11
|
+
import type { LoopObjectEvent, ObjectEvent, ObjectResponse, OutputSchema, OutputType, LLMLoopInput, LLMRequestInput } from "./llm.js";
|
|
12
12
|
import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
|
|
13
13
|
import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionRequestInput } from "./transcription.js";
|
|
14
|
-
import type { NoExecute, ToolExecuteContext, ToolOptions, ToolSchema } from "./tool.js";
|
|
14
|
+
import type { NoExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolOptions, ToolSchema } from "./tool.js";
|
|
15
15
|
import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
|
|
16
16
|
/**
|
|
17
17
|
* Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
|
|
18
18
|
* transcription and decision clients over a request executor; every method runs the corresponding Effect API and rethrows
|
|
19
19
|
* `AIError` unchanged. `file` and `write` load `node:fs/promises` on first use, so importing this module does not.
|
|
20
20
|
*/
|
|
21
|
-
export interface Options
|
|
21
|
+
export interface Options {
|
|
22
22
|
/** Executor layer; defaults to `RequestExecutor.fetchLayer`. Inject a recorder or `RequestExecutor.middleware(fn)` here. */
|
|
23
23
|
readonly layer?: Layer.Layer<RequestExecutor.Service>;
|
|
24
|
-
/** Replaces default clients, for example with `TestImage.testLayer()`; its other services are available to `run`. */
|
|
25
|
-
readonly clients?: Layer.Layer<R>;
|
|
26
24
|
}
|
|
27
25
|
export interface RunOptions {
|
|
28
26
|
readonly signal?: AbortSignal;
|
|
@@ -45,8 +43,8 @@ export type GenerationHandle<Response> = Snapshot & {
|
|
|
45
43
|
readonly refresh: (options?: RunOptions) => Promise<GenerationHandle<Response>>;
|
|
46
44
|
readonly cancel: (options?: RunOptions) => Promise<void>;
|
|
47
45
|
};
|
|
48
|
-
export declare const make:
|
|
49
|
-
run: <A, E>(effect: Effect.Effect<A, E, Services
|
|
46
|
+
export declare const make: (options?: Options) => {
|
|
47
|
+
run: <A, E>(effect: Effect.Effect<A, E, Services>, options?: RunOptions) => Promise<A>;
|
|
50
48
|
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
51
49
|
bytes: (asset: Media.Asset, options?: RunOptions) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
52
50
|
base64: (asset: Media.Asset, options?: RunOptions) => Promise<string>;
|
|
@@ -57,451 +55,26 @@ export declare const make: <R = never>(options?: Options<R>) => {
|
|
|
57
55
|
/** Write an asset's bytes like `Media.write`, downloading `url` sources through the executor. */
|
|
58
56
|
write: (asset: Media.Asset, path: string, options?: RunOptions) => Promise<void>;
|
|
59
57
|
request: typeof LLM.request;
|
|
60
|
-
generate:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
readonly [x: string]: unknown;
|
|
73
|
-
};
|
|
74
|
-
} | undefined;
|
|
75
|
-
} | {
|
|
76
|
-
readonly type: "text-delta";
|
|
77
|
-
readonly id: string;
|
|
78
|
-
readonly text: string;
|
|
79
|
-
readonly providerMetadata?: {
|
|
80
|
-
readonly [x: string]: {
|
|
81
|
-
readonly [x: string]: unknown;
|
|
82
|
-
};
|
|
83
|
-
} | undefined;
|
|
84
|
-
} | {
|
|
85
|
-
readonly type: "text-end";
|
|
86
|
-
readonly id: string;
|
|
87
|
-
readonly text?: string | undefined;
|
|
88
|
-
readonly providerMetadata?: {
|
|
89
|
-
readonly [x: string]: {
|
|
90
|
-
readonly [x: string]: unknown;
|
|
91
|
-
};
|
|
92
|
-
} | undefined;
|
|
93
|
-
} | {
|
|
94
|
-
readonly type: "reasoning-start";
|
|
95
|
-
readonly id: string;
|
|
96
|
-
readonly providerMetadata?: {
|
|
97
|
-
readonly [x: string]: {
|
|
98
|
-
readonly [x: string]: unknown;
|
|
99
|
-
};
|
|
100
|
-
} | undefined;
|
|
101
|
-
} | {
|
|
102
|
-
readonly type: "reasoning-delta";
|
|
103
|
-
readonly id: string;
|
|
104
|
-
readonly text: string;
|
|
105
|
-
readonly providerMetadata?: {
|
|
106
|
-
readonly [x: string]: {
|
|
107
|
-
readonly [x: string]: unknown;
|
|
108
|
-
};
|
|
109
|
-
} | undefined;
|
|
110
|
-
} | {
|
|
111
|
-
readonly type: "reasoning-end";
|
|
112
|
-
readonly id: string;
|
|
113
|
-
readonly text?: string | undefined;
|
|
114
|
-
readonly providerMetadata?: {
|
|
115
|
-
readonly [x: string]: {
|
|
116
|
-
readonly [x: string]: unknown;
|
|
117
|
-
};
|
|
118
|
-
} | undefined;
|
|
119
|
-
} | {
|
|
120
|
-
readonly type: "tool-input-start";
|
|
121
|
-
readonly id: string;
|
|
122
|
-
readonly name: string;
|
|
123
|
-
readonly namespace?: string | undefined;
|
|
124
|
-
readonly providerExecuted?: boolean | undefined;
|
|
125
|
-
readonly providerMetadata?: {
|
|
126
|
-
readonly [x: string]: {
|
|
127
|
-
readonly [x: string]: unknown;
|
|
128
|
-
};
|
|
129
|
-
} | undefined;
|
|
130
|
-
} | {
|
|
131
|
-
readonly type: "tool-input-delta";
|
|
132
|
-
readonly id: string;
|
|
133
|
-
readonly name: string;
|
|
134
|
-
readonly namespace?: string | undefined;
|
|
135
|
-
readonly text: string;
|
|
136
|
-
readonly input?: unknown;
|
|
137
|
-
} | {
|
|
138
|
-
readonly type: "tool-input-end";
|
|
139
|
-
readonly id: string;
|
|
140
|
-
readonly name: string;
|
|
141
|
-
readonly namespace?: string | undefined;
|
|
142
|
-
readonly providerMetadata?: {
|
|
143
|
-
readonly [x: string]: {
|
|
144
|
-
readonly [x: string]: unknown;
|
|
145
|
-
};
|
|
146
|
-
} | undefined;
|
|
147
|
-
} | {
|
|
148
|
-
readonly type: "tool-input-error";
|
|
149
|
-
readonly id: string;
|
|
150
|
-
readonly name: string;
|
|
151
|
-
readonly namespace?: string | undefined;
|
|
152
|
-
readonly raw: string;
|
|
153
|
-
} | {
|
|
154
|
-
readonly type: "tool-call";
|
|
155
|
-
readonly id: string;
|
|
156
|
-
readonly name: string;
|
|
157
|
-
readonly namespace?: string | undefined;
|
|
158
|
-
readonly input: unknown;
|
|
159
|
-
readonly providerExecuted?: boolean | undefined;
|
|
160
|
-
readonly providerMetadata?: {
|
|
161
|
-
readonly [x: string]: {
|
|
162
|
-
readonly [x: string]: unknown;
|
|
163
|
-
};
|
|
164
|
-
} | undefined;
|
|
165
|
-
} | {
|
|
166
|
-
readonly type: "tool-result";
|
|
167
|
-
readonly id: string;
|
|
168
|
-
readonly name: string;
|
|
169
|
-
readonly namespace?: string | undefined;
|
|
170
|
-
readonly result: {
|
|
171
|
-
readonly type: "json";
|
|
172
|
-
readonly value: unknown;
|
|
173
|
-
} | {
|
|
174
|
-
readonly type: "text";
|
|
175
|
-
readonly value: unknown;
|
|
176
|
-
} | {
|
|
177
|
-
readonly type: "error";
|
|
178
|
-
readonly value: unknown;
|
|
179
|
-
} | {
|
|
180
|
-
readonly type: "content";
|
|
181
|
-
readonly value: readonly ({
|
|
182
|
-
readonly type: "text";
|
|
183
|
-
readonly text: string;
|
|
184
|
-
} | {
|
|
185
|
-
readonly type: "file";
|
|
186
|
-
readonly uri: string;
|
|
187
|
-
readonly mime: string;
|
|
188
|
-
readonly name?: string | undefined;
|
|
189
|
-
})[];
|
|
190
|
-
};
|
|
191
|
-
readonly output?: {
|
|
192
|
-
readonly structured: unknown;
|
|
193
|
-
readonly content: readonly ({
|
|
194
|
-
readonly type: "text";
|
|
195
|
-
readonly text: string;
|
|
196
|
-
} | {
|
|
197
|
-
readonly type: "file";
|
|
198
|
-
readonly uri: string;
|
|
199
|
-
readonly mime: string;
|
|
200
|
-
readonly name?: string | undefined;
|
|
201
|
-
})[];
|
|
202
|
-
} | undefined;
|
|
203
|
-
readonly providerExecuted?: boolean | undefined;
|
|
204
|
-
readonly providerMetadata?: {
|
|
205
|
-
readonly [x: string]: {
|
|
206
|
-
readonly [x: string]: unknown;
|
|
207
|
-
};
|
|
208
|
-
} | undefined;
|
|
209
|
-
} | {
|
|
210
|
-
readonly type: "tool-error";
|
|
211
|
-
readonly id: string;
|
|
212
|
-
readonly name: string;
|
|
213
|
-
readonly namespace?: string | undefined;
|
|
214
|
-
readonly message: string;
|
|
215
|
-
readonly error?: unknown;
|
|
216
|
-
readonly providerMetadata?: {
|
|
217
|
-
readonly [x: string]: {
|
|
218
|
-
readonly [x: string]: unknown;
|
|
219
|
-
};
|
|
220
|
-
} | undefined;
|
|
221
|
-
} | {
|
|
222
|
-
readonly type: "step-finish";
|
|
223
|
-
readonly index: number;
|
|
224
|
-
readonly reason: {
|
|
225
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
226
|
-
readonly raw?: string | undefined;
|
|
227
|
-
readonly category?: string | undefined;
|
|
228
|
-
readonly explanation?: string | undefined;
|
|
229
|
-
};
|
|
230
|
-
readonly usage?: import("./index.js").Usage | undefined;
|
|
231
|
-
readonly providerMetadata?: {
|
|
232
|
-
readonly [x: string]: {
|
|
233
|
-
readonly [x: string]: unknown;
|
|
234
|
-
};
|
|
235
|
-
} | undefined;
|
|
236
|
-
} | {
|
|
237
|
-
readonly type: "finish";
|
|
238
|
-
readonly reason: {
|
|
239
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
240
|
-
readonly raw?: string | undefined;
|
|
241
|
-
readonly category?: string | undefined;
|
|
242
|
-
readonly explanation?: string | undefined;
|
|
243
|
-
};
|
|
244
|
-
readonly usage?: import("./index.js").Usage | undefined;
|
|
245
|
-
readonly providerMetadata?: {
|
|
246
|
-
readonly [x: string]: {
|
|
247
|
-
readonly [x: string]: unknown;
|
|
248
|
-
};
|
|
249
|
-
} | undefined;
|
|
250
|
-
} | {
|
|
251
|
-
readonly type: "media";
|
|
252
|
-
readonly media: Media.Asset;
|
|
253
|
-
readonly providerMetadata?: {
|
|
254
|
-
readonly [x: string]: {
|
|
255
|
-
readonly [x: string]: unknown;
|
|
256
|
-
};
|
|
257
|
-
} | undefined;
|
|
258
|
-
} | {
|
|
259
|
-
readonly type: "provider-error";
|
|
260
|
-
readonly message: string;
|
|
261
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
262
|
-
readonly providerMetadata?: {
|
|
263
|
-
readonly [x: string]: {
|
|
264
|
-
readonly [x: string]: unknown;
|
|
265
|
-
};
|
|
266
|
-
} | undefined;
|
|
267
|
-
} | ({
|
|
268
|
-
readonly type: "compaction";
|
|
269
|
-
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
270
|
-
readonly id?: string | undefined;
|
|
271
|
-
readonly encrypted?: string | undefined;
|
|
272
|
-
readonly text?: string | null | undefined;
|
|
273
|
-
} & ({
|
|
274
|
-
readonly encrypted: string;
|
|
275
|
-
readonly text?: never;
|
|
276
|
-
} | {
|
|
277
|
-
readonly text: string | null;
|
|
278
|
-
readonly encrypted?: never;
|
|
279
|
-
}))>;
|
|
58
|
+
generate: {
|
|
59
|
+
<const Model extends LanguageModel, S extends OutputSchema>(input: LLMRequestInput<Model> & {
|
|
60
|
+
readonly schema: S;
|
|
61
|
+
}, options?: StreamOptions & RunOptions): Promise<ObjectResponse<OutputType<S>>>;
|
|
62
|
+
<const Model extends LanguageModel>(input: LLMRequestInput<Model>, options?: StreamOptions & RunOptions): Promise<LLMResponse>;
|
|
63
|
+
};
|
|
64
|
+
stream: {
|
|
65
|
+
<const Model extends LanguageModel, S extends OutputSchema>(input: LLMRequestInput<Model> & {
|
|
66
|
+
readonly schema: S;
|
|
67
|
+
}, options?: StreamOptions & RunOptions): AsyncIterable<ObjectEvent<OutputType<S>>>;
|
|
68
|
+
<const Model extends LanguageModel>(input: LLMRequestInput<Model>, options?: StreamOptions & RunOptions): AsyncIterable<LLMEvent>;
|
|
69
|
+
};
|
|
280
70
|
/** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
|
|
281
|
-
loop:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
readonly data: unknown;
|
|
287
|
-
} | {
|
|
288
|
-
readonly type: "text-start";
|
|
289
|
-
readonly id: string;
|
|
290
|
-
readonly providerMetadata?: {
|
|
291
|
-
readonly [x: string]: {
|
|
292
|
-
readonly [x: string]: unknown;
|
|
293
|
-
};
|
|
294
|
-
} | undefined;
|
|
295
|
-
} | {
|
|
296
|
-
readonly type: "text-delta";
|
|
297
|
-
readonly id: string;
|
|
298
|
-
readonly text: string;
|
|
299
|
-
readonly providerMetadata?: {
|
|
300
|
-
readonly [x: string]: {
|
|
301
|
-
readonly [x: string]: unknown;
|
|
302
|
-
};
|
|
303
|
-
} | undefined;
|
|
304
|
-
} | {
|
|
305
|
-
readonly type: "text-end";
|
|
306
|
-
readonly id: string;
|
|
307
|
-
readonly text?: string | undefined;
|
|
308
|
-
readonly providerMetadata?: {
|
|
309
|
-
readonly [x: string]: {
|
|
310
|
-
readonly [x: string]: unknown;
|
|
311
|
-
};
|
|
312
|
-
} | undefined;
|
|
313
|
-
} | {
|
|
314
|
-
readonly type: "reasoning-start";
|
|
315
|
-
readonly id: string;
|
|
316
|
-
readonly providerMetadata?: {
|
|
317
|
-
readonly [x: string]: {
|
|
318
|
-
readonly [x: string]: unknown;
|
|
319
|
-
};
|
|
320
|
-
} | undefined;
|
|
321
|
-
} | {
|
|
322
|
-
readonly type: "reasoning-delta";
|
|
323
|
-
readonly id: string;
|
|
324
|
-
readonly text: string;
|
|
325
|
-
readonly providerMetadata?: {
|
|
326
|
-
readonly [x: string]: {
|
|
327
|
-
readonly [x: string]: unknown;
|
|
328
|
-
};
|
|
329
|
-
} | undefined;
|
|
330
|
-
} | {
|
|
331
|
-
readonly type: "reasoning-end";
|
|
332
|
-
readonly id: string;
|
|
333
|
-
readonly text?: string | undefined;
|
|
334
|
-
readonly providerMetadata?: {
|
|
335
|
-
readonly [x: string]: {
|
|
336
|
-
readonly [x: string]: unknown;
|
|
337
|
-
};
|
|
338
|
-
} | undefined;
|
|
339
|
-
} | {
|
|
340
|
-
readonly type: "tool-input-start";
|
|
341
|
-
readonly id: string;
|
|
342
|
-
readonly name: string;
|
|
343
|
-
readonly namespace?: string | undefined;
|
|
344
|
-
readonly providerExecuted?: boolean | undefined;
|
|
345
|
-
readonly providerMetadata?: {
|
|
346
|
-
readonly [x: string]: {
|
|
347
|
-
readonly [x: string]: unknown;
|
|
348
|
-
};
|
|
349
|
-
} | undefined;
|
|
350
|
-
} | {
|
|
351
|
-
readonly type: "tool-input-delta";
|
|
352
|
-
readonly id: string;
|
|
353
|
-
readonly name: string;
|
|
354
|
-
readonly namespace?: string | undefined;
|
|
355
|
-
readonly text: string;
|
|
356
|
-
readonly input?: unknown;
|
|
357
|
-
} | {
|
|
358
|
-
readonly type: "tool-input-end";
|
|
359
|
-
readonly id: string;
|
|
360
|
-
readonly name: string;
|
|
361
|
-
readonly namespace?: string | undefined;
|
|
362
|
-
readonly providerMetadata?: {
|
|
363
|
-
readonly [x: string]: {
|
|
364
|
-
readonly [x: string]: unknown;
|
|
365
|
-
};
|
|
366
|
-
} | undefined;
|
|
367
|
-
} | {
|
|
368
|
-
readonly type: "tool-input-error";
|
|
369
|
-
readonly id: string;
|
|
370
|
-
readonly name: string;
|
|
371
|
-
readonly namespace?: string | undefined;
|
|
372
|
-
readonly raw: string;
|
|
373
|
-
} | {
|
|
374
|
-
readonly type: "tool-call";
|
|
375
|
-
readonly id: string;
|
|
376
|
-
readonly name: string;
|
|
377
|
-
readonly namespace?: string | undefined;
|
|
378
|
-
readonly input: unknown;
|
|
379
|
-
readonly providerExecuted?: boolean | undefined;
|
|
380
|
-
readonly providerMetadata?: {
|
|
381
|
-
readonly [x: string]: {
|
|
382
|
-
readonly [x: string]: unknown;
|
|
383
|
-
};
|
|
384
|
-
} | undefined;
|
|
385
|
-
} | {
|
|
386
|
-
readonly type: "tool-result";
|
|
387
|
-
readonly id: string;
|
|
388
|
-
readonly name: string;
|
|
389
|
-
readonly namespace?: string | undefined;
|
|
390
|
-
readonly result: {
|
|
391
|
-
readonly type: "json";
|
|
392
|
-
readonly value: unknown;
|
|
393
|
-
} | {
|
|
394
|
-
readonly type: "text";
|
|
395
|
-
readonly value: unknown;
|
|
396
|
-
} | {
|
|
397
|
-
readonly type: "error";
|
|
398
|
-
readonly value: unknown;
|
|
399
|
-
} | {
|
|
400
|
-
readonly type: "content";
|
|
401
|
-
readonly value: readonly ({
|
|
402
|
-
readonly type: "text";
|
|
403
|
-
readonly text: string;
|
|
404
|
-
} | {
|
|
405
|
-
readonly type: "file";
|
|
406
|
-
readonly uri: string;
|
|
407
|
-
readonly mime: string;
|
|
408
|
-
readonly name?: string | undefined;
|
|
409
|
-
})[];
|
|
410
|
-
};
|
|
411
|
-
readonly output?: {
|
|
412
|
-
readonly structured: unknown;
|
|
413
|
-
readonly content: readonly ({
|
|
414
|
-
readonly type: "text";
|
|
415
|
-
readonly text: string;
|
|
416
|
-
} | {
|
|
417
|
-
readonly type: "file";
|
|
418
|
-
readonly uri: string;
|
|
419
|
-
readonly mime: string;
|
|
420
|
-
readonly name?: string | undefined;
|
|
421
|
-
})[];
|
|
422
|
-
} | undefined;
|
|
423
|
-
readonly providerExecuted?: boolean | undefined;
|
|
424
|
-
readonly providerMetadata?: {
|
|
425
|
-
readonly [x: string]: {
|
|
426
|
-
readonly [x: string]: unknown;
|
|
427
|
-
};
|
|
428
|
-
} | undefined;
|
|
429
|
-
} | {
|
|
430
|
-
readonly type: "tool-error";
|
|
431
|
-
readonly id: string;
|
|
432
|
-
readonly name: string;
|
|
433
|
-
readonly namespace?: string | undefined;
|
|
434
|
-
readonly message: string;
|
|
435
|
-
readonly error?: unknown;
|
|
436
|
-
readonly providerMetadata?: {
|
|
437
|
-
readonly [x: string]: {
|
|
438
|
-
readonly [x: string]: unknown;
|
|
439
|
-
};
|
|
440
|
-
} | undefined;
|
|
441
|
-
} | {
|
|
442
|
-
readonly type: "step-finish";
|
|
443
|
-
readonly index: number;
|
|
444
|
-
readonly reason: {
|
|
445
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
446
|
-
readonly raw?: string | undefined;
|
|
447
|
-
readonly category?: string | undefined;
|
|
448
|
-
readonly explanation?: string | undefined;
|
|
449
|
-
};
|
|
450
|
-
readonly usage?: import("./index.js").Usage | undefined;
|
|
451
|
-
readonly providerMetadata?: {
|
|
452
|
-
readonly [x: string]: {
|
|
453
|
-
readonly [x: string]: unknown;
|
|
454
|
-
};
|
|
455
|
-
} | undefined;
|
|
456
|
-
} | {
|
|
457
|
-
readonly type: "finish";
|
|
458
|
-
readonly reason: {
|
|
459
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
460
|
-
readonly raw?: string | undefined;
|
|
461
|
-
readonly category?: string | undefined;
|
|
462
|
-
readonly explanation?: string | undefined;
|
|
463
|
-
};
|
|
464
|
-
readonly usage?: import("./index.js").Usage | undefined;
|
|
465
|
-
readonly providerMetadata?: {
|
|
466
|
-
readonly [x: string]: {
|
|
467
|
-
readonly [x: string]: unknown;
|
|
468
|
-
};
|
|
469
|
-
} | undefined;
|
|
470
|
-
} | {
|
|
471
|
-
readonly type: "media";
|
|
472
|
-
readonly media: Media.Asset;
|
|
473
|
-
readonly providerMetadata?: {
|
|
474
|
-
readonly [x: string]: {
|
|
475
|
-
readonly [x: string]: unknown;
|
|
476
|
-
};
|
|
477
|
-
} | undefined;
|
|
478
|
-
} | {
|
|
479
|
-
readonly type: "provider-error";
|
|
480
|
-
readonly message: string;
|
|
481
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
482
|
-
readonly providerMetadata?: {
|
|
483
|
-
readonly [x: string]: {
|
|
484
|
-
readonly [x: string]: unknown;
|
|
485
|
-
};
|
|
486
|
-
} | undefined;
|
|
487
|
-
} | ({
|
|
488
|
-
readonly type: "compaction";
|
|
489
|
-
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
490
|
-
readonly id?: string | undefined;
|
|
491
|
-
readonly encrypted?: string | undefined;
|
|
492
|
-
readonly text?: string | null | undefined;
|
|
493
|
-
} & ({
|
|
494
|
-
readonly encrypted: string;
|
|
495
|
-
readonly text?: never;
|
|
496
|
-
} | {
|
|
497
|
-
readonly text: string | null;
|
|
498
|
-
readonly encrypted?: never;
|
|
499
|
-
}))>;
|
|
500
|
-
/** Decode the model's output against `schema` (or `jsonSchema`, unvalidated). */
|
|
501
|
-
generateObject: {
|
|
502
|
-
<const Model extends LanguageModel, S extends ToolSchema<any>>(input: GenerateObjectOptions<S, Model>, options?: RunOptions): Promise<GenerateObjectResponse<Schema.Schema.Type<S>>>;
|
|
503
|
-
<const Model extends LanguageModel>(input: GenerateObjectDynamicOptions<Model>, options?: RunOptions): Promise<GenerateObjectResponse<unknown>>;
|
|
71
|
+
loop: {
|
|
72
|
+
<const Model extends LanguageModel, S extends OutputSchema>(input: LLMLoopInput<Model> & {
|
|
73
|
+
readonly schema: S;
|
|
74
|
+
}, options?: StreamOptions & RunOptions): AsyncIterable<LoopObjectEvent<OutputType<S>>>;
|
|
75
|
+
<const Model extends LanguageModel>(input: LLMLoopInput<Model>, options?: StreamOptions & RunOptions): AsyncIterable<LLMEvent>;
|
|
504
76
|
};
|
|
77
|
+
collect: <Event extends LLMEvent>(events: AsyncIterable<Event>, options?: RunOptions) => Promise<LLM.CollectResult<Event>>;
|
|
505
78
|
/** Compact a Responses request: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
|
|
506
79
|
compact: {
|
|
507
80
|
(request: CheckpointRequest, options: TriggerCompactOptions & RunOptions): Promise<CompactionCheckpointResponse>;
|
|
@@ -737,22 +310,12 @@ export declare const make: <R = never>(options?: Options<R>) => {
|
|
|
737
310
|
};
|
|
738
311
|
dispose: () => Promise<void>;
|
|
739
312
|
};
|
|
740
|
-
export type Client
|
|
313
|
+
export type Client = ReturnType<typeof make>;
|
|
741
314
|
/** `tool` from `@opencode/ai/effect`, with an `execute` that returns a value or a Promise and throws to fail. */
|
|
742
|
-
export declare const tool: <
|
|
315
|
+
export declare const tool: <Input extends ToolInput = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Schema.Schema.Type<Success> | PromiseLike<Schema.Schema.Type<Success>> | NoExecute = NoExecute>(config: ToolOptions<Input, Success, (input: ToolInputType<Input>, context: Partial<ToolExecuteContext> & {
|
|
743
316
|
signal: AbortSignal;
|
|
744
|
-
}) => Result>) => 0 extends 1 & Result ? import("./tool.js").ExecutableTool<
|
|
317
|
+
}) => Result>) => 0 extends 1 & Result ? import("./tool.js").ExecutableTool<Input, Success> : [Result, NoExecute] extends [NoExecute, Result] ? import("./tool.js").Tool<Input, Success> : import("./tool.js").ExecutableTool<Input, Success>;
|
|
745
318
|
/** Default client over `RequestExecutor.fetchLayer`; the runtime builds its layer on first use and holds nothing to dispose. */
|
|
746
319
|
export declare const ai: Omit<Client, "dispose">;
|
|
747
320
|
export * as AI from "./index.js";
|
|
748
|
-
export
|
|
749
|
-
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";
|
|
750
|
-
export type { GenerationOptionsFields, GenerationOptionsInput, LanguageModelInput, LanguageModelProviderOptions, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, UsageInput, } from "./schema/index.js";
|
|
751
|
-
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
752
|
-
export type { ImageModelOptions, ImageOptions, ImageRequestFor, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
753
|
-
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";
|
|
754
|
-
export type { AnswerFor, AnswersFor, DecisionInput, DecisionModelOptions, DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
755
|
-
export { Media } from "./media.js";
|
|
756
|
-
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
757
|
-
export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolModelOutputInput, ToolOptions, Tools, ToolSchema, ToolToModelOutput, } from "./tool.js";
|
|
758
|
-
export type { LLM } from "./llm.js";
|
|
321
|
+
export * from "./public.js";
|
package/dist/index.js
CHANGED
|
@@ -25,15 +25,21 @@ const abortEffect = (signal) => signal === undefined
|
|
|
25
25
|
return Effect.sync(() => signal.removeEventListener("abort", onAbort));
|
|
26
26
|
});
|
|
27
27
|
export const make = (options = {}) => {
|
|
28
|
-
const runtime = ManagedRuntime.make(
|
|
29
|
-
// `R` is only inferred from `clients`, so it is `never` whenever `clients` is omitted.
|
|
30
|
-
(options.clients ?? Layer.empty)));
|
|
28
|
+
const runtime = ManagedRuntime.make(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer));
|
|
31
29
|
/** Run any package Effect (for example `ai.compact(...)` from `@opencode/ai/effect`) inside this runtime. */
|
|
32
30
|
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
|
|
33
31
|
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
|
-
function
|
|
35
|
-
return run(
|
|
32
|
+
function generate(input, options) {
|
|
33
|
+
return run(LLM.generate(input, options), options);
|
|
36
34
|
}
|
|
35
|
+
function stream(input, options) {
|
|
36
|
+
return iterate(LLM.stream(input, options), options);
|
|
37
|
+
}
|
|
38
|
+
function loop(input, options) {
|
|
39
|
+
return iterate(LLM.loop(input, options), options);
|
|
40
|
+
}
|
|
41
|
+
/** Read `events` from `stream` or `loop` to the end and fold them into the final result. */
|
|
42
|
+
const collect = (events, options) => run(LLM.collect(Stream.fromAsyncIterable(events, (error) => error)), options);
|
|
37
43
|
// The overloads pair each request type with its mechanism; `LLM.compact` checks the route's capability at runtime.
|
|
38
44
|
function compact(request, options) {
|
|
39
45
|
return options?.mechanism === "trigger"
|
|
@@ -78,12 +84,11 @@ export const make = (options = {}) => {
|
|
|
78
84
|
}))), options);
|
|
79
85
|
},
|
|
80
86
|
request: LLM.request,
|
|
81
|
-
generate
|
|
82
|
-
stream
|
|
87
|
+
generate,
|
|
88
|
+
stream,
|
|
83
89
|
/** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
|
|
84
|
-
loop
|
|
85
|
-
|
|
86
|
-
generateObject,
|
|
90
|
+
loop,
|
|
91
|
+
collect,
|
|
87
92
|
/** Compact a Responses request: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
|
|
88
93
|
compact,
|
|
89
94
|
canCompact: LLM.canCompact,
|
|
@@ -128,16 +133,12 @@ const fileError = (message, cause) => new AIError({ reason: new InvalidRequestEr
|
|
|
128
133
|
export const tool = (config) => {
|
|
129
134
|
const execute = config.execute;
|
|
130
135
|
return build(config, execute &&
|
|
131
|
-
((
|
|
132
|
-
try: async (signal) => execute(
|
|
136
|
+
((input, context) => Effect.tryPromise({
|
|
137
|
+
try: async (signal) => execute(input, { ...context, signal }),
|
|
133
138
|
catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
|
|
134
139
|
})));
|
|
135
140
|
};
|
|
136
141
|
/** Default client over `RequestExecutor.fetchLayer`; the runtime builds its layer on first use and holds nothing to dispose. */
|
|
137
142
|
export const ai = make();
|
|
138
143
|
export * as AI from "./index.js";
|
|
139
|
-
export
|
|
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";
|
|
144
|
+
export * from "./public.js";
|