@opencode/ai 0.0.0-dev-21800 → 0.0.0-dev-21802
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 +45 -37
- package/dist/effect.d.ts +39 -0
- package/dist/effect.js +28 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/image-client.d.ts +4 -4
- package/dist/index.d.ts +1030 -39
- package/dist/index.js +106 -28
- package/dist/protocols/alibaba-responses.d.ts +6 -3
- package/dist/protocols/meta-responses.d.ts +6 -0
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/open-responses.d.ts +27 -0
- package/dist/protocols/open-responses.js +7 -18
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +8 -5
- package/dist/protocols/openai-responses.d.ts +18 -0
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/xai-responses.d.ts +3 -0
- package/dist/protocols/xai-responses.js +9 -0
- package/dist/providers/alibaba.d.ts +3 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +3 -0
- package/dist/providers/azure.d.ts +6 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +6 -0
- package/dist/providers/google-vertex-responses.d.ts +3 -0
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/minimax.d.ts +3 -0
- package/dist/providers/moonshot.d.ts +3 -0
- package/dist/providers/openai-compatible-responses.d.ts +3 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/zai-coding-plan.d.ts +3 -0
- package/dist/speech-client.d.ts +4 -4
- package/dist/transcription-client.d.ts +4 -4
- package/dist/video-client.d.ts +4 -4
- package/package.json +6 -6
- package/dist/promise.d.ts +0 -1030
- package/dist/promise.js +0 -106
package/dist/index.js
CHANGED
|
@@ -1,28 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { Effect, Layer, ManagedRuntime, Stream } from "effect";
|
|
2
|
+
import { AIClient } from "./ai-client.js";
|
|
3
|
+
import { Decision } from "./decision.js";
|
|
4
|
+
import { Image } from "./image.js";
|
|
5
|
+
import { LLM } from "./effect.js";
|
|
6
|
+
import { Media } from "./media.js";
|
|
7
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
8
|
+
import { AIError, InvalidRequestError, LanguageModel } from "./schema/index.js";
|
|
9
|
+
import { Speech } from "./speech.js";
|
|
10
|
+
import { Transcription, } from "./transcription.js";
|
|
11
|
+
import { fileMediaType } from "./utils/media-type.js";
|
|
12
|
+
import { Video } from "./video.js";
|
|
13
|
+
// Fails with `signal.reason` so aborted calls reject and aborted streams throw like `fetch`: an `AbortError` by default.
|
|
14
|
+
const abortEffect = (signal) => signal === undefined
|
|
15
|
+
? Effect.never
|
|
16
|
+
: Effect.callback((resume) => {
|
|
17
|
+
if (signal.aborted) {
|
|
18
|
+
resume(Effect.fail(signal.reason));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const onAbort = () => resume(Effect.fail(signal.reason));
|
|
22
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
23
|
+
return Effect.sync(() => signal.removeEventListener("abort", onAbort));
|
|
24
|
+
});
|
|
25
|
+
export const make = (options = {}) => {
|
|
26
|
+
const runtime = ManagedRuntime.make(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer));
|
|
27
|
+
/** Run any package Effect (for example `LLMClient.compact(...)`) inside this runtime. */
|
|
28
|
+
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
|
|
29
|
+
const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
|
|
30
|
+
const handle = (generation) => ({
|
|
31
|
+
...generation.snapshot,
|
|
32
|
+
token: generation.token,
|
|
33
|
+
await: (options) => run(generation.await({ poll: options?.poll }), options),
|
|
34
|
+
events: (options) => iterate(generation.events({ poll: options?.poll }), options),
|
|
35
|
+
result: (options) => run(generation.result(), options),
|
|
36
|
+
refresh: (options) => run(generation.refresh(), options).then(handle),
|
|
37
|
+
cancel: (options) => run(generation.cancel(), options),
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
run,
|
|
41
|
+
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
42
|
+
bytes: (asset, options) => run(asset.bytes(), options),
|
|
43
|
+
base64: (asset, options) => run(asset.base64(), options),
|
|
44
|
+
/** Pull a `url` asset into owned bytes before the provider URL expires. */
|
|
45
|
+
materialize: (asset, options) => run(asset.materialize(), options),
|
|
46
|
+
/** Read a file into an asset like `Media.file`: sniffed media type, then the extension's. */
|
|
47
|
+
file: async (path, options) => {
|
|
48
|
+
const { readFile } = await import("node:fs/promises");
|
|
49
|
+
return run(Effect.tryPromise({
|
|
50
|
+
try: (signal) => readFile(path, { signal }),
|
|
51
|
+
catch: (cause) => fileError(`Failed to read media file ${path}`, cause),
|
|
52
|
+
}).pipe(Effect.map((buffer) => {
|
|
53
|
+
const data = new Uint8Array(buffer);
|
|
54
|
+
return Media.bytes(data, fileMediaType(data, path), options);
|
|
55
|
+
})), options);
|
|
56
|
+
},
|
|
57
|
+
/** Write an asset's bytes like `Media.write`, downloading `url` sources through the executor. */
|
|
58
|
+
write: async (asset, path, options) => {
|
|
59
|
+
const { writeFile } = await import("node:fs/promises");
|
|
60
|
+
return run(asset.bytes().pipe(Effect.flatMap((data) => Effect.tryPromise({
|
|
61
|
+
try: (signal) => writeFile(path, data, { signal }),
|
|
62
|
+
catch: (cause) => fileError(`Failed to write media file ${path}`, cause),
|
|
63
|
+
}))), options);
|
|
64
|
+
},
|
|
65
|
+
llm: {
|
|
66
|
+
request: LLM.request,
|
|
67
|
+
generate: (input, options) => run(LLM.generate(input), options),
|
|
68
|
+
stream: (input, options) => iterate(LLM.stream(input), options),
|
|
69
|
+
},
|
|
70
|
+
image: {
|
|
71
|
+
request: Image.request,
|
|
72
|
+
generate: (input, options) => run(Image.generate(input, { poll: options?.poll }), options),
|
|
73
|
+
stream: (input, options) => iterate(Image.stream(input, { poll: options?.poll }), options),
|
|
74
|
+
start: (input, options) => run(Image.start(input), options).then(handle),
|
|
75
|
+
resume: (model, token, options) => run(Image.resume(model, token), options).then(handle),
|
|
76
|
+
},
|
|
77
|
+
video: {
|
|
78
|
+
request: Video.request,
|
|
79
|
+
start: (input, options) => run(Video.start(input), options).then(handle),
|
|
80
|
+
generate: (input, options) => run(Video.generate(input, { poll: options?.poll }), options),
|
|
81
|
+
resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
|
|
82
|
+
stream: (input, options) => iterate(Video.stream(input, { poll: options?.poll }), options),
|
|
83
|
+
},
|
|
84
|
+
speech: {
|
|
85
|
+
request: Speech.request,
|
|
86
|
+
generate: (input, options) => run(Speech.generate(input), options),
|
|
87
|
+
stream: (input, options) => iterate(Speech.stream(input), options),
|
|
88
|
+
},
|
|
89
|
+
transcription: {
|
|
90
|
+
request: Transcription.request,
|
|
91
|
+
generate: (input, options) => run(Transcription.generate(input, { poll: options?.poll }), options),
|
|
92
|
+
stream: (input, options) => iterate(Transcription.stream(input, { poll: options?.poll }), options),
|
|
93
|
+
start: (input, options) => run(Transcription.start(input), options).then(handle),
|
|
94
|
+
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
|
|
95
|
+
},
|
|
96
|
+
decision: {
|
|
97
|
+
request: Decision.request,
|
|
98
|
+
generate: (input, options) => run(Decision.generate(input), options),
|
|
99
|
+
},
|
|
100
|
+
dispose: () => runtime.dispose(),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const fileError = (message, cause) => new AIError({ reason: new InvalidRequestError({ message, cause }) });
|
|
104
|
+
/** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
|
|
105
|
+
export const ai = make();
|
|
106
|
+
export * as AI from "./index.js";
|
|
@@ -63,6 +63,9 @@ export declare const protocol: Protocol<{
|
|
|
63
63
|
readonly content: readonly ({
|
|
64
64
|
readonly type: "input_text";
|
|
65
65
|
readonly text: string;
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: "input_video";
|
|
68
|
+
readonly video_url: string;
|
|
66
69
|
} | {
|
|
67
70
|
readonly type: "input_image";
|
|
68
71
|
readonly image_url: string;
|
|
@@ -169,15 +172,15 @@ export declare const protocol: Protocol<{
|
|
|
169
172
|
} | undefined;
|
|
170
173
|
readonly top_logprobs?: number | undefined;
|
|
171
174
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
172
|
-
readonly service_tier?: import("../
|
|
175
|
+
readonly service_tier?: import("../effect.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
173
176
|
readonly prompt_cache_key?: string | undefined;
|
|
174
|
-
readonly include?: readonly import("../
|
|
177
|
+
readonly include?: readonly import("../effect.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
175
178
|
readonly reasoning?: {
|
|
176
179
|
readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
|
|
177
180
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
178
181
|
} | undefined;
|
|
179
182
|
readonly text?: {
|
|
180
|
-
readonly verbosity?: import("../
|
|
183
|
+
readonly verbosity?: import("../effect.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
181
184
|
} | undefined;
|
|
182
185
|
readonly max_output_tokens?: number | undefined;
|
|
183
186
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -77,6 +77,9 @@ export declare const protocol: Protocol<{
|
|
|
77
77
|
readonly content: readonly ({
|
|
78
78
|
readonly type: "input_text";
|
|
79
79
|
readonly text: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: "input_video";
|
|
82
|
+
readonly video_url: string;
|
|
80
83
|
} | {
|
|
81
84
|
readonly type: "input_image";
|
|
82
85
|
readonly image_url: string;
|
|
@@ -313,6 +316,9 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
313
316
|
readonly content: readonly ({
|
|
314
317
|
readonly type: "input_text";
|
|
315
318
|
readonly text: string;
|
|
319
|
+
} | {
|
|
320
|
+
readonly type: "input_video";
|
|
321
|
+
readonly video_url: string;
|
|
316
322
|
} | {
|
|
317
323
|
readonly type: "input_image";
|
|
318
324
|
readonly image_url: string;
|
|
@@ -48,7 +48,7 @@ const adapter = {
|
|
|
48
48
|
};
|
|
49
49
|
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
50
50
|
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
51
|
-
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter(LLMRequest.update(request, {
|
|
52
52
|
messages: request.messages.map((message) => Message.make({
|
|
53
53
|
...message,
|
|
54
54
|
content: message.content.map((part) => {
|
|
@@ -69,7 +69,35 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
69
69
|
}),
|
|
70
70
|
})),
|
|
71
71
|
}), adapter);
|
|
72
|
+
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
73
|
+
const input = [];
|
|
74
|
+
const videos = [];
|
|
75
|
+
const flushVideos = () => {
|
|
76
|
+
if (videos.length > 0)
|
|
77
|
+
input.push({ type: "message", role: "user", content: videos.splice(0) });
|
|
78
|
+
};
|
|
79
|
+
for (const item of body.input) {
|
|
80
|
+
if (!isFunctionCallOutput(item)) {
|
|
81
|
+
flushVideos();
|
|
82
|
+
input.push(item);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof item.output === "string") {
|
|
86
|
+
input.push(item);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const content = item.output.filter((part) => part.type !== "input_video");
|
|
90
|
+
videos.push(...item.output.filter((part) => part.type === "input_video"));
|
|
91
|
+
input.push({
|
|
92
|
+
...item,
|
|
93
|
+
output: content.length === 0 && item.output.length > 0 ? "Video attached in the following user message." : content,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
flushVideos();
|
|
97
|
+
return { ...body, input };
|
|
72
98
|
});
|
|
99
|
+
// Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
|
|
100
|
+
const isFunctionCallOutput = (item) => item.type === "function_call_output";
|
|
73
101
|
const HOSTED_TOOLS = {
|
|
74
102
|
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
75
103
|
image_generation_call: {
|
|
@@ -33,6 +33,9 @@ declare const MediaInput: Schema.Union<readonly [Schema.Struct<{
|
|
|
33
33
|
readonly detail: Schema.optional<Schema.String>;
|
|
34
34
|
readonly file_data: Schema.optional<Schema.String>;
|
|
35
35
|
readonly file_url: Schema.optional<Schema.String>;
|
|
36
|
+
}>, Schema.Struct<{
|
|
37
|
+
readonly type: Schema.tag<"input_video">;
|
|
38
|
+
readonly video_url: Schema.String;
|
|
36
39
|
}>]>;
|
|
37
40
|
export type MediaInput = Schema.Schema.Type<typeof MediaInput>;
|
|
38
41
|
export declare const OpenResponsesOutputText: Schema.Struct<{
|
|
@@ -134,6 +137,9 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
|
|
|
134
137
|
readonly detail: Schema.optional<Schema.String>;
|
|
135
138
|
readonly file_data: Schema.optional<Schema.String>;
|
|
136
139
|
readonly file_url: Schema.optional<Schema.String>;
|
|
140
|
+
}>, Schema.Struct<{
|
|
141
|
+
readonly type: Schema.tag<"input_video">;
|
|
142
|
+
readonly video_url: Schema.String;
|
|
137
143
|
}>]>]>>;
|
|
138
144
|
readonly id: Schema.optional<Schema.String>;
|
|
139
145
|
readonly status: Schema.optional<Schema.String>;
|
|
@@ -270,6 +276,9 @@ export declare const coreFields: {
|
|
|
270
276
|
readonly detail: Schema.optional<Schema.String>;
|
|
271
277
|
readonly file_data: Schema.optional<Schema.String>;
|
|
272
278
|
readonly file_url: Schema.optional<Schema.String>;
|
|
279
|
+
}>, Schema.Struct<{
|
|
280
|
+
readonly type: Schema.tag<"input_video">;
|
|
281
|
+
readonly video_url: Schema.String;
|
|
273
282
|
}>]>]>>;
|
|
274
283
|
readonly id: Schema.optional<Schema.String>;
|
|
275
284
|
readonly status: Schema.optional<Schema.String>;
|
|
@@ -431,6 +440,9 @@ export declare const OpenResponsesBody: Schema.Struct<{
|
|
|
431
440
|
readonly detail: Schema.optional<Schema.String>;
|
|
432
441
|
readonly file_data: Schema.optional<Schema.String>;
|
|
433
442
|
readonly file_url: Schema.optional<Schema.String>;
|
|
443
|
+
}>, Schema.Struct<{
|
|
444
|
+
readonly type: Schema.tag<"input_video">;
|
|
445
|
+
readonly video_url: Schema.String;
|
|
434
446
|
}>]>]>>;
|
|
435
447
|
readonly id: Schema.optional<Schema.String>;
|
|
436
448
|
readonly status: Schema.optional<Schema.String>;
|
|
@@ -953,6 +965,9 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
|
|
|
953
965
|
readonly content: readonly ({
|
|
954
966
|
readonly type: "input_text";
|
|
955
967
|
readonly text: string;
|
|
968
|
+
} | {
|
|
969
|
+
readonly type: "input_video";
|
|
970
|
+
readonly video_url: string;
|
|
956
971
|
} | {
|
|
957
972
|
readonly type: "input_image";
|
|
958
973
|
readonly image_url: string;
|
|
@@ -1121,6 +1136,9 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
|
|
|
1121
1136
|
readonly content: readonly ({
|
|
1122
1137
|
readonly type: "input_text";
|
|
1123
1138
|
readonly text: string;
|
|
1139
|
+
} | {
|
|
1140
|
+
readonly type: "input_video";
|
|
1141
|
+
readonly video_url: string;
|
|
1124
1142
|
} | {
|
|
1125
1143
|
readonly type: "input_image";
|
|
1126
1144
|
readonly image_url: string;
|
|
@@ -1299,6 +1317,9 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
|
|
|
1299
1317
|
readonly content: readonly ({
|
|
1300
1318
|
readonly type: "input_text";
|
|
1301
1319
|
readonly text: string;
|
|
1320
|
+
} | {
|
|
1321
|
+
readonly type: "input_video";
|
|
1322
|
+
readonly video_url: string;
|
|
1302
1323
|
} | {
|
|
1303
1324
|
readonly type: "input_image";
|
|
1304
1325
|
readonly image_url: string;
|
|
@@ -1712,6 +1733,9 @@ export declare const protocol: Protocol<{
|
|
|
1712
1733
|
readonly content: readonly ({
|
|
1713
1734
|
readonly type: "input_text";
|
|
1714
1735
|
readonly text: string;
|
|
1736
|
+
} | {
|
|
1737
|
+
readonly type: "input_video";
|
|
1738
|
+
readonly video_url: string;
|
|
1715
1739
|
} | {
|
|
1716
1740
|
readonly type: "input_image";
|
|
1717
1741
|
readonly image_url: string;
|
|
@@ -1948,6 +1972,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
1948
1972
|
readonly content: readonly ({
|
|
1949
1973
|
readonly type: "input_text";
|
|
1950
1974
|
readonly text: string;
|
|
1975
|
+
} | {
|
|
1976
|
+
readonly type: "input_video";
|
|
1977
|
+
readonly video_url: string;
|
|
1951
1978
|
} | {
|
|
1952
1979
|
readonly type: "input_image";
|
|
1953
1980
|
readonly image_url: string;
|
|
@@ -34,7 +34,7 @@ const OpenResponsesInputVideo = Schema.Struct({
|
|
|
34
34
|
type: Schema.tag("input_video"),
|
|
35
35
|
video_url: Schema.String,
|
|
36
36
|
});
|
|
37
|
-
const MediaInput = Schema.Union([OpenResponsesInputImage, OpenResponsesInputFile]);
|
|
37
|
+
const MediaInput = Schema.Union([OpenResponsesInputImage, OpenResponsesInputFile, OpenResponsesInputVideo]);
|
|
38
38
|
const OpenResponsesInputContent = Schema.Union([OpenResponsesInputText, MediaInput]);
|
|
39
39
|
export const OpenResponsesOutputText = Schema.Struct({
|
|
40
40
|
type: Schema.tag("output_text"),
|
|
@@ -341,7 +341,7 @@ const lowerReasoning = (part, providerMetadataKey) => {
|
|
|
341
341
|
};
|
|
342
342
|
const decodeImageDetail = ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesInputImage.fields.detail));
|
|
343
343
|
const decodeMessageMetadata = ProviderShared.validateWith(Schema.decodeUnknownEffect(MessageMetadata));
|
|
344
|
-
const lowerMedia = Effect.fnUntraced(function* (part, request, adapter
|
|
344
|
+
const lowerMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
345
345
|
const media = part.media.inline();
|
|
346
346
|
const providerMedia = adapter.lowerMedia?.({ part, media, request });
|
|
347
347
|
if (providerMedia)
|
|
@@ -352,7 +352,7 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter, target)
|
|
|
352
352
|
const url = ProviderShared.mediaUrl(part.media);
|
|
353
353
|
const location = url ?? (yield* ProviderShared.requireInlineMedia(adapter.name, part.media)).dataUrl;
|
|
354
354
|
if (part.media.kind !== "image") {
|
|
355
|
-
if (
|
|
355
|
+
if (part.media.kind === "video")
|
|
356
356
|
return { type: "input_video", video_url: location };
|
|
357
357
|
return {
|
|
358
358
|
type: "input_file",
|
|
@@ -371,26 +371,15 @@ const lowerUserContent = Effect.fnUntraced(function* (part, request, adapter) {
|
|
|
371
371
|
if (part.type === "text")
|
|
372
372
|
return { type: "input_text", text: part.text };
|
|
373
373
|
if (part.type === "media")
|
|
374
|
-
return yield*
|
|
374
|
+
return yield* lowerMedia(part, request, adapter);
|
|
375
375
|
return yield* ProviderShared.unsupportedContent(adapter.name, "user", ["text", "media"]);
|
|
376
376
|
});
|
|
377
|
-
const lowerMessageMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
378
|
-
const lowered = yield* lowerMedia(part, request, adapter, "message");
|
|
379
|
-
if (lowered.type === "input_video")
|
|
380
|
-
return yield* ProviderShared.invalidRequest(`${adapter.name} user messages do not support input_video`);
|
|
381
|
-
return lowered;
|
|
382
|
-
});
|
|
383
377
|
// Tool results may carry structured text, images, and files. Keep media as provider-native
|
|
384
378
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
385
379
|
const lowerToolResultContentItem = Effect.fnUntraced(function* (item, request, adapter) {
|
|
386
380
|
if (item.type === "text")
|
|
387
381
|
return { type: "input_text", text: item.text };
|
|
388
|
-
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request, adapter
|
|
389
|
-
});
|
|
390
|
-
const lowerHostedToolResultContentItem = Effect.fnUntraced(function* (item, request, adapter) {
|
|
391
|
-
if (item.type === "text")
|
|
392
|
-
return { type: "input_text", text: item.text };
|
|
393
|
-
return yield* lowerMessageMedia(ProviderShared.toolFileMedia(item), request, adapter);
|
|
382
|
+
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request, adapter);
|
|
394
383
|
});
|
|
395
384
|
const lowerToolResultOutput = Effect.fnUntraced(function* (part, request, adapter) {
|
|
396
385
|
// Text/json/error results are encoded as a plain string for backward
|
|
@@ -518,7 +507,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
518
507
|
input.push({
|
|
519
508
|
type: "message",
|
|
520
509
|
role: "user",
|
|
521
|
-
content: yield* Effect.forEach(content, (item) =>
|
|
510
|
+
content: yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, adapter)),
|
|
522
511
|
});
|
|
523
512
|
continue;
|
|
524
513
|
}
|
|
@@ -528,7 +517,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
528
517
|
input.push({
|
|
529
518
|
type: "message",
|
|
530
519
|
role: "user",
|
|
531
|
-
content: [yield*
|
|
520
|
+
content: [yield* lowerMedia(part, request, adapter)],
|
|
532
521
|
});
|
|
533
522
|
continue;
|
|
534
523
|
}
|
|
@@ -127,7 +127,7 @@ export declare const route: Route<{
|
|
|
127
127
|
} | undefined;
|
|
128
128
|
readonly store?: boolean | undefined;
|
|
129
129
|
readonly prompt_cache_key?: string | undefined;
|
|
130
|
-
readonly reasoning_effort?: import("../
|
|
130
|
+
readonly reasoning_effort?: import("../effect.js").ReasoningEffort | undefined;
|
|
131
131
|
readonly tool_stream?: boolean | undefined;
|
|
132
132
|
readonly max_completion_tokens?: number | undefined;
|
|
133
133
|
readonly max_tokens?: number | undefined;
|
|
@@ -9,7 +9,7 @@ export declare const route: Route<{
|
|
|
9
9
|
readonly input: readonly ({
|
|
10
10
|
readonly type: "configuration_update";
|
|
11
11
|
readonly reasoning: {
|
|
12
|
-
readonly effort: import("../
|
|
12
|
+
readonly effort: import("../effect.js").ReasoningEffort;
|
|
13
13
|
};
|
|
14
14
|
} | {
|
|
15
15
|
readonly type: "message";
|
|
@@ -57,6 +57,9 @@ export declare const route: Route<{
|
|
|
57
57
|
readonly content: readonly ({
|
|
58
58
|
readonly type: "input_text";
|
|
59
59
|
readonly text: string;
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: "input_video";
|
|
62
|
+
readonly video_url: string;
|
|
60
63
|
} | {
|
|
61
64
|
readonly type: "input_image";
|
|
62
65
|
readonly image_url: string;
|
|
@@ -163,15 +166,15 @@ export declare const route: Route<{
|
|
|
163
166
|
} | undefined;
|
|
164
167
|
readonly top_logprobs?: number | undefined;
|
|
165
168
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
166
|
-
readonly service_tier?: import("../
|
|
169
|
+
readonly service_tier?: import("../effect.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
167
170
|
readonly prompt_cache_key?: string | undefined;
|
|
168
|
-
readonly include?: readonly import("../
|
|
171
|
+
readonly include?: readonly import("../effect.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
169
172
|
readonly reasoning?: {
|
|
170
|
-
readonly effort?: import("../
|
|
173
|
+
readonly effort?: import("../effect.js").ReasoningEffort | undefined;
|
|
171
174
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
172
175
|
} | undefined;
|
|
173
176
|
readonly text?: {
|
|
174
|
-
readonly verbosity?: import("../
|
|
177
|
+
readonly verbosity?: import("../effect.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
175
178
|
} | undefined;
|
|
176
179
|
readonly max_output_tokens?: number | undefined;
|
|
177
180
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -46,6 +46,9 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
46
46
|
readonly detail: Schema.optional<Schema.String>;
|
|
47
47
|
readonly file_data: Schema.optional<Schema.String>;
|
|
48
48
|
readonly file_url: Schema.optional<Schema.String>;
|
|
49
|
+
}>, Schema.Struct<{
|
|
50
|
+
readonly type: Schema.tag<"input_video">;
|
|
51
|
+
readonly video_url: Schema.String;
|
|
49
52
|
}>]>]>>;
|
|
50
53
|
readonly id: Schema.optional<Schema.String>;
|
|
51
54
|
readonly status: Schema.optional<Schema.String>;
|
|
@@ -256,6 +259,9 @@ export declare const protocol: Protocol<{
|
|
|
256
259
|
readonly content: readonly ({
|
|
257
260
|
readonly type: "input_text";
|
|
258
261
|
readonly text: string;
|
|
262
|
+
} | {
|
|
263
|
+
readonly type: "input_video";
|
|
264
|
+
readonly video_url: string;
|
|
259
265
|
} | {
|
|
260
266
|
readonly type: "input_image";
|
|
261
267
|
readonly image_url: string;
|
|
@@ -518,6 +524,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
518
524
|
readonly content: readonly ({
|
|
519
525
|
readonly type: "input_text";
|
|
520
526
|
readonly text: string;
|
|
527
|
+
} | {
|
|
528
|
+
readonly type: "input_video";
|
|
529
|
+
readonly video_url: string;
|
|
521
530
|
} | {
|
|
522
531
|
readonly type: "input_image";
|
|
523
532
|
readonly image_url: string;
|
|
@@ -722,6 +731,9 @@ export declare const channelTransport: (options: import("./open-responses-channe
|
|
|
722
731
|
readonly content: readonly ({
|
|
723
732
|
readonly type: "input_text";
|
|
724
733
|
readonly text: string;
|
|
734
|
+
} | {
|
|
735
|
+
readonly type: "input_video";
|
|
736
|
+
readonly video_url: string;
|
|
725
737
|
} | {
|
|
726
738
|
readonly type: "input_image";
|
|
727
739
|
readonly image_url: string;
|
|
@@ -926,6 +938,9 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
926
938
|
readonly content: readonly ({
|
|
927
939
|
readonly type: "input_text";
|
|
928
940
|
readonly text: string;
|
|
941
|
+
} | {
|
|
942
|
+
readonly type: "input_video";
|
|
943
|
+
readonly video_url: string;
|
|
929
944
|
} | {
|
|
930
945
|
readonly type: "input_image";
|
|
931
946
|
readonly image_url: string;
|
|
@@ -1130,6 +1145,9 @@ export declare const route: Route<{
|
|
|
1130
1145
|
readonly content: readonly ({
|
|
1131
1146
|
readonly type: "input_text";
|
|
1132
1147
|
readonly text: string;
|
|
1148
|
+
} | {
|
|
1149
|
+
readonly type: "input_video";
|
|
1150
|
+
readonly video_url: string;
|
|
1133
1151
|
} | {
|
|
1134
1152
|
readonly type: "input_image";
|
|
1135
1153
|
readonly image_url: string;
|
|
@@ -30,5 +30,5 @@ export declare const nearest: (shape: Shape, sizes: ReadonlyArray<Size>) => Size
|
|
|
30
30
|
/** Reports a size more than 2% off the requested aspect or more than √2 per edge off the requested tier. */
|
|
31
31
|
export declare const notice: (name: string, shape: Shape, size: Size) => Media.Notice | undefined;
|
|
32
32
|
/** Free width and height that must honor the shape; a size that misses it fails instead of returning a notice. */
|
|
33
|
-
export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../
|
|
33
|
+
export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../effect.js").AIError, never> | Effect.Effect<Size, never, never>;
|
|
34
34
|
export * as ImageSizing from "./image-sizing.js";
|
|
@@ -53,6 +53,9 @@ export declare const protocol: Protocol<{
|
|
|
53
53
|
readonly content: readonly ({
|
|
54
54
|
readonly type: "input_text";
|
|
55
55
|
readonly text: string;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "input_video";
|
|
58
|
+
readonly video_url: string;
|
|
56
59
|
} | {
|
|
57
60
|
readonly type: "input_image";
|
|
58
61
|
readonly image_url: string;
|
|
@@ -24,6 +24,15 @@ const XAIResponsesHostedToolItem = Schema.Union([
|
|
|
24
24
|
const adapter = {
|
|
25
25
|
id: ADAPTER,
|
|
26
26
|
name: NAME,
|
|
27
|
+
lowerMedia: ({ part, media }) => {
|
|
28
|
+
if (part.media.kind !== "video")
|
|
29
|
+
return undefined;
|
|
30
|
+
const filename = part.filename ?? "file";
|
|
31
|
+
const url = ProviderShared.mediaUrl(part.media);
|
|
32
|
+
if (url)
|
|
33
|
+
return { type: "input_file", filename, file_url: url };
|
|
34
|
+
return media && { type: "input_file", filename, file_data: media.dataUrl };
|
|
35
|
+
},
|
|
27
36
|
restoreHostedToolItem: (item) => (Schema.is(XAIResponsesHostedToolItem)(item) ? item : undefined),
|
|
28
37
|
};
|
|
29
38
|
const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
|
|
@@ -524,6 +524,9 @@ export declare const routes: (Route<{
|
|
|
524
524
|
readonly content: readonly ({
|
|
525
525
|
readonly type: "input_text";
|
|
526
526
|
readonly text: string;
|
|
527
|
+
} | {
|
|
528
|
+
readonly type: "input_video";
|
|
529
|
+
readonly video_url: string;
|
|
527
530
|
} | {
|
|
528
531
|
readonly type: "input_image";
|
|
529
532
|
readonly image_url: string;
|
|
@@ -520,6 +520,9 @@ export declare const routes: (Route<{
|
|
|
520
520
|
readonly content: readonly ({
|
|
521
521
|
readonly type: "input_text";
|
|
522
522
|
readonly text: string;
|
|
523
|
+
} | {
|
|
524
|
+
readonly type: "input_video";
|
|
525
|
+
readonly video_url: string;
|
|
523
526
|
} | {
|
|
524
527
|
readonly type: "input_image";
|
|
525
528
|
readonly image_url: string;
|
|
@@ -74,6 +74,9 @@ declare const responsesRoute: Route<{
|
|
|
74
74
|
readonly content: readonly ({
|
|
75
75
|
readonly type: "input_text";
|
|
76
76
|
readonly text: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly type: "input_video";
|
|
79
|
+
readonly video_url: string;
|
|
77
80
|
} | {
|
|
78
81
|
readonly type: "input_image";
|
|
79
82
|
readonly image_url: string;
|
|
@@ -411,6 +414,9 @@ export declare const routes: (Route<{
|
|
|
411
414
|
readonly content: readonly ({
|
|
412
415
|
readonly type: "input_text";
|
|
413
416
|
readonly text: string;
|
|
417
|
+
} | {
|
|
418
|
+
readonly type: "input_video";
|
|
419
|
+
readonly video_url: string;
|
|
414
420
|
} | {
|
|
415
421
|
readonly type: "input_image";
|
|
416
422
|
readonly image_url: string;
|
|
@@ -82,6 +82,9 @@ export declare const responsesRoute: import("../route/client.js").Route<{
|
|
|
82
82
|
readonly content: readonly ({
|
|
83
83
|
readonly type: "input_text";
|
|
84
84
|
readonly text: string;
|
|
85
|
+
} | {
|
|
86
|
+
readonly type: "input_video";
|
|
87
|
+
readonly video_url: string;
|
|
85
88
|
} | {
|
|
86
89
|
readonly type: "input_image";
|
|
87
90
|
readonly image_url: string;
|
|
@@ -1165,6 +1168,9 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
1165
1168
|
readonly content: readonly ({
|
|
1166
1169
|
readonly type: "input_text";
|
|
1167
1170
|
readonly text: string;
|
|
1171
|
+
} | {
|
|
1172
|
+
readonly type: "input_video";
|
|
1173
|
+
readonly video_url: string;
|
|
1168
1174
|
} | {
|
|
1169
1175
|
readonly type: "input_image";
|
|
1170
1176
|
readonly image_url: string;
|
|
@@ -70,6 +70,9 @@ export declare const routes: Route<{
|
|
|
70
70
|
readonly content: readonly ({
|
|
71
71
|
readonly type: "input_text";
|
|
72
72
|
readonly text: string;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: "input_video";
|
|
75
|
+
readonly video_url: string;
|
|
73
76
|
} | {
|
|
74
77
|
readonly type: "input_image";
|
|
75
78
|
readonly image_url: string;
|
package/dist/providers/meta.d.ts
CHANGED
|
@@ -222,6 +222,9 @@ export declare const routes: (Route<{
|
|
|
222
222
|
readonly content: readonly ({
|
|
223
223
|
readonly type: "input_text";
|
|
224
224
|
readonly text: string;
|
|
225
|
+
} | {
|
|
226
|
+
readonly type: "input_video";
|
|
227
|
+
readonly video_url: string;
|
|
225
228
|
} | {
|
|
226
229
|
readonly type: "input_image";
|
|
227
230
|
readonly image_url: string;
|
|
@@ -392,6 +392,9 @@ export declare const routes: (Route<{
|
|
|
392
392
|
readonly content: readonly ({
|
|
393
393
|
readonly type: "input_text";
|
|
394
394
|
readonly text: string;
|
|
395
|
+
} | {
|
|
396
|
+
readonly type: "input_video";
|
|
397
|
+
readonly video_url: string;
|
|
395
398
|
} | {
|
|
396
399
|
readonly type: "input_image";
|
|
397
400
|
readonly image_url: string;
|