@opencode/ai 2.2.7 → 2.3.1
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 +164 -99
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +11 -8
- package/dist/effect.js +2 -1
- package/dist/experimental.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -12
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +31 -68
- package/dist/index.js +54 -30
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +26 -4
- package/dist/media.js +52 -11
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-interactions-video.d.ts +38 -0
- package/dist/protocols/google-interactions-video.js +185 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +45 -0
- package/dist/protocols/minimax-video.js +290 -0
- package/dist/protocols/open-responses.d.ts +250 -24
- package/dist/protocols/open-responses.js +40 -24
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +36 -0
- package/dist/protocols/openrouter-video.js +139 -0
- package/dist/protocols/seedance-video.d.ts +45 -0
- package/dist/protocols/seedance-video.js +217 -0
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +42 -7
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +8 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +12 -11
- package/dist/protocols/xai-video.js +33 -24
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +26 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +11 -4
- package/dist/providers/google.js +16 -3
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +56 -3
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai-compatible.d.ts +2 -0
- package/dist/providers/openai-compatible.js +14 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +31 -0
- package/dist/providers/openrouter.js +8 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +26 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +7 -4
- package/dist/public.js +2 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +20 -1
- package/dist/route/executor-service.js +35 -1
- package/dist/route/executor.d.ts +11 -2
- package/dist/route/executor.js +25 -5
- package/dist/route/media-protocol.d.ts +21 -15
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +40 -22
- package/dist/route/protocol.d.ts +3 -0
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +25 -2
- package/dist/schema/messages.js +27 -7
- package/dist/schema/options.d.ts +18 -2
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +6 -6
- package/dist/speech-client.js +4 -4
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +6 -6
- package/dist/transcription-client.js +1 -2
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +30 -13
- package/dist/video.d.ts +54 -1126
- package/dist/video.js +29 -65
- package/package.json +59 -7
- package/dist/protocols/google-video.d.ts +0 -26
- package/dist/protocols/google-video.js +0 -146
- package/dist/protocols/runway-video.d.ts +0 -38
- package/dist/protocols/runway-video.js +0 -141
- package/dist/providers/runway.d.ts +0 -20
- package/dist/providers/runway.js +0 -17
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { VideoModel, VideoResponse, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
const route = MediaProtocol.identity({ id: "openrouter-video", name: "OpenRouter Video", provider: "openrouter" });
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
10
|
+
export const PATH = "/videos";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 2. Token and response schemas
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
15
|
+
export const Token = Schema.String;
|
|
16
|
+
const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
|
|
17
|
+
const Job = Schema.Struct({
|
|
18
|
+
id: optionalNull(Schema.String),
|
|
19
|
+
generation_id: optionalNull(Schema.String),
|
|
20
|
+
status: Schema.String,
|
|
21
|
+
unsigned_urls: optionalNull(Schema.Array(Schema.String)),
|
|
22
|
+
expires_at: optionalNull(Schema.Number),
|
|
23
|
+
error: optionalNull(Schema.String),
|
|
24
|
+
usage: optionalNull(Schema.Struct({
|
|
25
|
+
cost: optionalNull(Schema.Number),
|
|
26
|
+
is_byok: optionalNull(Schema.Boolean),
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// 3. Status
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
const STATUS = {
|
|
33
|
+
pending: "running",
|
|
34
|
+
in_progress: "running",
|
|
35
|
+
completed: "completed",
|
|
36
|
+
failed: "failed",
|
|
37
|
+
cancelled: "cancelled",
|
|
38
|
+
expired: "expired",
|
|
39
|
+
};
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// 4. Body construction
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
const imagePart = (asset) => ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((reference) => ({ type: "image_url", image_url: { url: reference.value } })));
|
|
44
|
+
const referencePart = Effect.fn("OpenRouterVideo.referencePart")(function* (asset) {
|
|
45
|
+
// OpenRouter rejects inline video and audio ("Only HTTPS URLs are allowed", verified live); inline images work.
|
|
46
|
+
if ((asset.kind === "video" || asset.kind === "audio") && asset.source.type !== "url")
|
|
47
|
+
return yield* route.unsupported("video.references", `${route.name} only takes reference ${asset.kind} as http(s) URLs`);
|
|
48
|
+
const reference = yield* ProviderShared.mediaReference(asset, undefined, route.name);
|
|
49
|
+
if (asset.kind === "video")
|
|
50
|
+
return { type: "video_url", video_url: { url: reference.value } };
|
|
51
|
+
if (asset.kind === "audio")
|
|
52
|
+
return { type: "audio_url", audio_url: { url: reference.value } };
|
|
53
|
+
return { type: "image_url", image_url: { url: reference.value } };
|
|
54
|
+
});
|
|
55
|
+
const fromRequest = Effect.fn("OpenRouterVideo.fromRequest")(function* (request) {
|
|
56
|
+
const frames = [
|
|
57
|
+
...(request.start === undefined
|
|
58
|
+
? []
|
|
59
|
+
: [{ ...(yield* imagePart(request.start)), frame_type: "first_frame" }]),
|
|
60
|
+
...(request.end === undefined ? [] : [{ ...(yield* imagePart(request.end)), frame_type: "last_frame" }]),
|
|
61
|
+
];
|
|
62
|
+
const inputReferences = yield* Effect.forEach(request.references ?? [], referencePart);
|
|
63
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
64
|
+
model: request.model.id,
|
|
65
|
+
prompt: request.prompt,
|
|
66
|
+
frame_images: frames.length === 0 ? undefined : frames,
|
|
67
|
+
input_references: inputReferences.length === 0 ? undefined : inputReferences,
|
|
68
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
69
|
+
// Leaving the aspect ratio out is how OpenRouter follows the input image on models that can.
|
|
70
|
+
aspect_ratio: request.aspect === "auto" ? undefined : request.aspect,
|
|
71
|
+
resolution: request.resolution === undefined ? undefined : resolution(request.resolution),
|
|
72
|
+
generate_audio: request.sound,
|
|
73
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
74
|
+
});
|
|
75
|
+
// OpenRouter spells the K resolutions in upper case (`1K`, `2K`, `4K`).
|
|
76
|
+
const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value);
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// 5. Response decoding
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
81
|
+
token: value.id,
|
|
82
|
+
snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status ?? "pending") },
|
|
83
|
+
}));
|
|
84
|
+
const decodeJob = route.decodeJson(Job);
|
|
85
|
+
const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
|
|
86
|
+
const output = yield* decodeJob(response);
|
|
87
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
88
|
+
});
|
|
89
|
+
const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
|
|
90
|
+
const output = yield* decodeJob(response);
|
|
91
|
+
const job = output.value;
|
|
92
|
+
const status = MediaProtocol.state(STATUS, job.status);
|
|
93
|
+
if (status === "running")
|
|
94
|
+
return yield* output.pending(context.token);
|
|
95
|
+
if (status === "failed") {
|
|
96
|
+
const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
|
|
97
|
+
if (job.error && /content policy|moderat/i.test(job.error))
|
|
98
|
+
return yield* output.contentPolicy(message);
|
|
99
|
+
return yield* output.ended("failed", message);
|
|
100
|
+
}
|
|
101
|
+
if (status !== "completed")
|
|
102
|
+
return yield* output.ended(status, `${route.name} job ${context.token} ${status}${job.error ? `: ${job.error}` : ""}`);
|
|
103
|
+
const urls = job.unsigned_urls ?? [];
|
|
104
|
+
if (urls.length === 0)
|
|
105
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
106
|
+
// The content URLs are OpenRouter's own and only download with the API key.
|
|
107
|
+
const videos = yield* Effect.forEach(urls, (url) => context.credentials(url).pipe(Effect.map((credentials) => Media.url(url, {
|
|
108
|
+
mediaType: "video/mp4",
|
|
109
|
+
expiresAt: job.expires_at === undefined || job.expires_at === null ? undefined : job.expires_at * 1000,
|
|
110
|
+
...credentials,
|
|
111
|
+
}))));
|
|
112
|
+
return new VideoResponse({
|
|
113
|
+
videos,
|
|
114
|
+
providerMetadata: {
|
|
115
|
+
openrouter: {
|
|
116
|
+
id: context.token,
|
|
117
|
+
generationId: job.generation_id ?? undefined,
|
|
118
|
+
cost: job.usage?.cost ?? undefined,
|
|
119
|
+
isByok: job.usage?.is_byok ?? undefined,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// 6. Protocol and route
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
const jobPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
128
|
+
// OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
|
|
129
|
+
export const protocol = MediaProtocol.queued(route, {
|
|
130
|
+
token: Token,
|
|
131
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
132
|
+
status: { path: jobPath, decode: decodeStatus },
|
|
133
|
+
result: { path: jobPath, decode: decodeResult },
|
|
134
|
+
});
|
|
135
|
+
export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
136
|
+
export const OpenRouterVideo = {
|
|
137
|
+
protocol,
|
|
138
|
+
model,
|
|
139
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
|
+
export declare const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
6
|
+
export declare const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
7
|
+
export declare const PATH = "/contents/generations/tasks";
|
|
8
|
+
/**
|
|
9
|
+
* Provider-native options, merged into the task body. Common fields (`start`, `end`, `references`, `duration`,
|
|
10
|
+
* `aspect`, `resolution`, `sound`) live on the request. `draft_task` adds a `draft_task` content item that turns a
|
|
11
|
+
* Draft video into the final one.
|
|
12
|
+
*/
|
|
13
|
+
export type SeedanceVideoOptions = {
|
|
14
|
+
readonly draft_task?: {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
};
|
|
17
|
+
readonly draft?: boolean;
|
|
18
|
+
readonly frames?: number;
|
|
19
|
+
readonly seed?: number;
|
|
20
|
+
readonly camera_fixed?: boolean;
|
|
21
|
+
readonly watermark?: boolean;
|
|
22
|
+
readonly return_last_frame?: boolean;
|
|
23
|
+
readonly omni_reference_task_type?: "auto" | "reference" | "edit" | "extend" | (string & {});
|
|
24
|
+
readonly output_format?: "mp4" | "mov" | (string & {});
|
|
25
|
+
readonly service_tier?: "default" | "flex" | (string & {});
|
|
26
|
+
readonly callback_url?: string;
|
|
27
|
+
readonly execution_expires_after?: number;
|
|
28
|
+
readonly priority?: number;
|
|
29
|
+
readonly safety_identifier?: string;
|
|
30
|
+
} & Record<string, unknown>;
|
|
31
|
+
export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
|
|
32
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
33
|
+
export declare const Token: Schema.String;
|
|
34
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
35
|
+
export type Provider = "volcengine" | "byteplus";
|
|
36
|
+
export declare const SeedanceVideo: {
|
|
37
|
+
readonly volcengine: {
|
|
38
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
39
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
40
|
+
};
|
|
41
|
+
readonly byteplus: {
|
|
42
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
43
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { VideoModel, VideoResponse, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
// One Ark API (`/contents/generations/tasks`) served by Volcengine Ark in China and BytePlus ModelArk elsewhere.
|
|
9
|
+
export const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
10
|
+
export const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
11
|
+
export const PATH = "/contents/generations/tasks";
|
|
12
|
+
// Video and last-frame URLs are documented as valid for 24 hours.
|
|
13
|
+
const OUTPUT_RETENTION = Duration.hours(24);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Token and response schemas
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
18
|
+
export const Token = Schema.String;
|
|
19
|
+
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
20
|
+
const Task = Schema.Struct({
|
|
21
|
+
id: optionalNull(Schema.String),
|
|
22
|
+
model: optionalNull(Schema.String),
|
|
23
|
+
status: Schema.String,
|
|
24
|
+
content: optionalNull(Schema.Struct({
|
|
25
|
+
video_url: optionalNull(Schema.String),
|
|
26
|
+
last_frame_url: optionalNull(Schema.String),
|
|
27
|
+
})),
|
|
28
|
+
error: optionalNull(Schema.Struct({
|
|
29
|
+
code: optionalNull(Schema.String),
|
|
30
|
+
message: optionalNull(Schema.String),
|
|
31
|
+
})),
|
|
32
|
+
usage: optionalNull(Schema.Struct({
|
|
33
|
+
completion_tokens: optionalNull(Schema.Number),
|
|
34
|
+
total_tokens: optionalNull(Schema.Number),
|
|
35
|
+
})),
|
|
36
|
+
updated_at: optionalNull(Schema.Number),
|
|
37
|
+
seed: optionalNull(Schema.Number),
|
|
38
|
+
resolution: optionalNull(Schema.String),
|
|
39
|
+
ratio: optionalNull(Schema.String),
|
|
40
|
+
duration: optionalNull(Schema.Number),
|
|
41
|
+
frames: optionalNull(Schema.Number),
|
|
42
|
+
framespersecond: optionalNull(Schema.Number),
|
|
43
|
+
generate_audio: optionalNull(Schema.Boolean),
|
|
44
|
+
output_format: optionalNull(Schema.String),
|
|
45
|
+
draft: optionalNull(Schema.Boolean),
|
|
46
|
+
service_tier: optionalNull(Schema.String),
|
|
47
|
+
});
|
|
48
|
+
const STATUS = {
|
|
49
|
+
queued: "running",
|
|
50
|
+
running: "running",
|
|
51
|
+
succeeded: "completed",
|
|
52
|
+
failed: "failed",
|
|
53
|
+
cancelled: "cancelled",
|
|
54
|
+
expired: "expired",
|
|
55
|
+
};
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// 3. Failures
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Ark error codes are dotted (`InvalidParameter.TaskTypeConstraint`); the leading segment is the category.
|
|
60
|
+
// `InternalServiceError`, `ServerOverloaded` and unknown codes are provider-side.
|
|
61
|
+
const FAILURE = {
|
|
62
|
+
InvalidParameter: "InvalidRequest",
|
|
63
|
+
MissingParameter: "InvalidRequest",
|
|
64
|
+
InvalidArgumentError: "InvalidRequest",
|
|
65
|
+
InvalidImageURL: "InvalidRequest",
|
|
66
|
+
AuthenticationError: "Authentication",
|
|
67
|
+
AccessDenied: "Authentication",
|
|
68
|
+
QuotaExceeded: "RateLimit",
|
|
69
|
+
RateLimitExceeded: "RateLimit",
|
|
70
|
+
};
|
|
71
|
+
// Input and output moderation codes: `InputImageSensitiveContentDetected.PrivacyInformation`,
|
|
72
|
+
// `OutputVideoSensitiveContentDetected`, `SensitiveContentDetected`, ...
|
|
73
|
+
const moderated = (code) => code !== undefined && code.includes("SensitiveContentDetected");
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// 4. Request body construction
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
const nativeOptions = (options) => {
|
|
78
|
+
if (!options)
|
|
79
|
+
return undefined;
|
|
80
|
+
const { draft_task: _draftTask, ...native } = options;
|
|
81
|
+
return native;
|
|
82
|
+
};
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// 5. Response decoding
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Ark returns `frames` when the request set it, otherwise `duration` rounded down to whole seconds.
|
|
87
|
+
const durationSeconds = (task) => {
|
|
88
|
+
if (task.frames !== undefined && task.frames !== null && task.framespersecond)
|
|
89
|
+
return task.frames / task.framespersecond;
|
|
90
|
+
return task.duration ?? undefined;
|
|
91
|
+
};
|
|
92
|
+
const make = (provider) => {
|
|
93
|
+
const route = MediaProtocol.identity({ id: "seedance-video", name: "Seedance Video", provider });
|
|
94
|
+
// `asset://<ID>` addresses a ModelArk digital character or authorized asset.
|
|
95
|
+
const item = (asset, type, role) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => ({
|
|
96
|
+
type,
|
|
97
|
+
[type]: { url: reference.type === "ref" ? `asset://${reference.value}` : reference.value },
|
|
98
|
+
role,
|
|
99
|
+
})));
|
|
100
|
+
const reference = (asset) => {
|
|
101
|
+
if (asset.kind === "video")
|
|
102
|
+
return item(asset, "video_url", "reference_video");
|
|
103
|
+
if (asset.kind === "audio")
|
|
104
|
+
return item(asset, "audio_url", "reference_audio");
|
|
105
|
+
return item(asset, "image_url", "reference_image");
|
|
106
|
+
};
|
|
107
|
+
// Frames and references are separate Seedance modes; mixing them is sent as-is and rejected by the provider.
|
|
108
|
+
const fromRequest = Effect.fn("SeedanceVideo.fromRequest")(function* (request) {
|
|
109
|
+
const content = [
|
|
110
|
+
// Every media mode accepts an optional prompt, so an empty one adds no text item.
|
|
111
|
+
...(request.prompt === "" ? [] : [{ type: "text", text: request.prompt }]),
|
|
112
|
+
...(request.start === undefined ? [] : [yield* item(request.start, "image_url", "first_frame")]),
|
|
113
|
+
...(request.end === undefined ? [] : [yield* item(request.end, "image_url", "last_frame")]),
|
|
114
|
+
...(yield* Effect.forEach(request.references ?? [], reference)),
|
|
115
|
+
...(request.providerOptions?.draft_task === undefined
|
|
116
|
+
? []
|
|
117
|
+
: [{ type: "draft_task", draft_task: request.providerOptions.draft_task }]),
|
|
118
|
+
];
|
|
119
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
120
|
+
model: request.model.id,
|
|
121
|
+
content,
|
|
122
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
123
|
+
ratio: request.aspect === "auto" ? "adaptive" : request.aspect,
|
|
124
|
+
resolution: request.resolution,
|
|
125
|
+
generate_audio: request.sound,
|
|
126
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
127
|
+
});
|
|
128
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
129
|
+
token: value.id,
|
|
130
|
+
snapshot: { id: value.id, status: "running" },
|
|
131
|
+
}));
|
|
132
|
+
const decodeTask = route.decodeJson(Task);
|
|
133
|
+
const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
|
|
134
|
+
const output = yield* decodeTask(response);
|
|
135
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
136
|
+
});
|
|
137
|
+
const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
|
|
138
|
+
const output = yield* decodeTask(response);
|
|
139
|
+
const task = output.value;
|
|
140
|
+
const status = MediaProtocol.state(STATUS, task.status);
|
|
141
|
+
if (status === "running")
|
|
142
|
+
return yield* output.pending(context.token);
|
|
143
|
+
if (status === "failed") {
|
|
144
|
+
const code = task.error?.code ?? undefined;
|
|
145
|
+
const detail = task.error?.message ?? undefined;
|
|
146
|
+
const message = `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${detail === undefined ? "" : `: ${detail}`}`;
|
|
147
|
+
if (moderated(code))
|
|
148
|
+
return yield* output.contentPolicy(message);
|
|
149
|
+
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
|
|
150
|
+
}
|
|
151
|
+
if (status === "cancelled")
|
|
152
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
153
|
+
if (status === "expired")
|
|
154
|
+
return yield* output.ended("expired", `${route.name} task ${context.token} expired`);
|
|
155
|
+
const videoURL = task.content?.video_url ?? undefined;
|
|
156
|
+
if (videoURL === undefined)
|
|
157
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
158
|
+
const duration = durationSeconds(task);
|
|
159
|
+
const options = {
|
|
160
|
+
mediaType: task.output_format === "mov" ? "video/quicktime" : "video/mp4",
|
|
161
|
+
info: duration === undefined ? undefined : { durationSeconds: duration },
|
|
162
|
+
};
|
|
163
|
+
// `updated_at` is when the task reached `succeeded`, which starts the URL's retention window.
|
|
164
|
+
const video = task.updated_at === undefined || task.updated_at === null
|
|
165
|
+
? yield* MediaProtocol.expiringUrl(videoURL, OUTPUT_RETENTION, options)
|
|
166
|
+
: Media.url(videoURL, {
|
|
167
|
+
...options,
|
|
168
|
+
expiresAt: task.updated_at * 1000 + Duration.toMillis(OUTPUT_RETENTION),
|
|
169
|
+
});
|
|
170
|
+
return new VideoResponse({
|
|
171
|
+
videos: [video],
|
|
172
|
+
usage: task.usage?.completion_tokens === undefined || task.usage.completion_tokens === null
|
|
173
|
+
? undefined
|
|
174
|
+
: {
|
|
175
|
+
type: "tokens",
|
|
176
|
+
output: task.usage.completion_tokens,
|
|
177
|
+
total: task.usage.total_tokens ?? undefined,
|
|
178
|
+
},
|
|
179
|
+
providerMetadata: {
|
|
180
|
+
[provider]: {
|
|
181
|
+
taskId: context.token,
|
|
182
|
+
model: task.model ?? undefined,
|
|
183
|
+
seed: task.seed ?? undefined,
|
|
184
|
+
ratio: task.ratio ?? undefined,
|
|
185
|
+
resolution: task.resolution ?? undefined,
|
|
186
|
+
duration: task.duration ?? undefined,
|
|
187
|
+
frames: task.frames ?? undefined,
|
|
188
|
+
framesPerSecond: task.framespersecond ?? undefined,
|
|
189
|
+
generateAudio: task.generate_audio ?? undefined,
|
|
190
|
+
outputFormat: task.output_format ?? undefined,
|
|
191
|
+
draft: task.draft ?? undefined,
|
|
192
|
+
serviceTier: task.service_tier ?? undefined,
|
|
193
|
+
lastFrameUrl: task.content?.last_frame_url ?? undefined,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
const taskPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
199
|
+
// DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
|
|
200
|
+
const protocol = MediaProtocol.queued(route, {
|
|
201
|
+
token: Token,
|
|
202
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
203
|
+
status: { path: taskPath, decode: decodeStatus },
|
|
204
|
+
result: { path: taskPath, decode: decodeResult },
|
|
205
|
+
cancel: { method: "DELETE", path: taskPath },
|
|
206
|
+
});
|
|
207
|
+
const model = (input) => VideoModel.fromRoute({
|
|
208
|
+
protocol,
|
|
209
|
+
baseURL: provider === "volcengine" ? VOLCENGINE_BASE_URL : BYTEPLUS_BASE_URL,
|
|
210
|
+
path: PATH,
|
|
211
|
+
}, input);
|
|
212
|
+
return { protocol, model };
|
|
213
|
+
};
|
|
214
|
+
export const SeedanceVideo = {
|
|
215
|
+
volcengine: make("volcengine"),
|
|
216
|
+
byteplus: make("byteplus"),
|
|
217
|
+
};
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { DecisionResponse, type DecisionModelCompatibility, type DecisionRequest } from "../decision.js";
|
|
2
|
+
import { DecisionResponse, type DecisionAnswer, type DecisionModelCompatibility, type DecisionQuestion, type DecisionRequest } from "../decision.js";
|
|
3
3
|
import { DecisionRoute } from "../route/decision.js";
|
|
4
4
|
import { AIError } from "../schema/index.js";
|
|
5
5
|
export declare const DEFAULT_PATH = "/systemone";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.typesafe.ai/v1";
|
|
7
7
|
/** `state.messages` is Baseten's own placement (parts in a user message inside `state.messages`), set by its provider. */
|
|
8
8
|
type MediaInput = NonNullable<DecisionModelCompatibility["mediaInput"]> | "state.messages";
|
|
9
|
+
declare const Answer: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
10
|
+
readonly type: Schema.Literal<"noul">;
|
|
11
|
+
readonly noul: Schema.Number;
|
|
12
|
+
}>, Schema.Struct<{
|
|
13
|
+
readonly type: Schema.Literal<"choice">;
|
|
14
|
+
readonly choice: Schema.String;
|
|
15
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
16
|
+
readonly confidence: Schema.Number;
|
|
17
|
+
}>, Schema.Struct<{
|
|
18
|
+
readonly type: Schema.Literal<"score">;
|
|
19
|
+
readonly score: Schema.Number;
|
|
20
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
21
|
+
readonly confidence: Schema.Number;
|
|
22
|
+
}>, Schema.Struct<{
|
|
23
|
+
readonly type: Schema.Literal<"refusal">;
|
|
24
|
+
readonly message: Schema.optional<Schema.String>;
|
|
25
|
+
}>]>;
|
|
9
26
|
export declare const Response: Schema.Struct<{
|
|
10
27
|
readonly model: Schema.String;
|
|
11
28
|
readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
@@ -21,6 +38,9 @@ export declare const Response: Schema.Struct<{
|
|
|
21
38
|
readonly score: Schema.Number;
|
|
22
39
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
23
40
|
readonly confidence: Schema.Number;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly type: Schema.Literal<"refusal">;
|
|
43
|
+
readonly message: Schema.optional<Schema.String>;
|
|
24
44
|
}>]>>;
|
|
25
45
|
readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
|
|
26
46
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -48,12 +68,31 @@ export declare const encodeBody: (request: DecisionRequest<import("../decision.j
|
|
|
48
68
|
};
|
|
49
69
|
};
|
|
50
70
|
}, AIError, never>;
|
|
71
|
+
declare const encodeQuestions: (questions: ReadonlyArray<DecisionQuestion>) => Effect.Effect<any, AIError, never>;
|
|
51
72
|
/** Map System One's answers, keyed by question name, back to the request's question order. */
|
|
52
73
|
export declare const toResponse: (data: Response, request: DecisionRequest, providerMetadataKey: string, invalid: (message: string) => AIError) => Effect.Effect<never, AIError, never> | Effect.Effect<DecisionResponse, never, never>;
|
|
74
|
+
declare const toAnswer: (question: DecisionQuestion, answer: typeof Answer.Type) => DecisionAnswer;
|
|
53
75
|
export declare const protocol: DecisionRoute.Protocol;
|
|
54
76
|
/** TypeSafe's API, the reference System One host; other hosts change the endpoint and auth with `route.with(...)`. */
|
|
55
77
|
export declare const route: DecisionRoute.Route;
|
|
56
78
|
export declare const SystemOne: {
|
|
79
|
+
readonly Answer: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
80
|
+
readonly type: Schema.Literal<"noul">;
|
|
81
|
+
readonly noul: Schema.Number;
|
|
82
|
+
}>, Schema.Struct<{
|
|
83
|
+
readonly type: Schema.Literal<"choice">;
|
|
84
|
+
readonly choice: Schema.String;
|
|
85
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
86
|
+
readonly confidence: Schema.Number;
|
|
87
|
+
}>, Schema.Struct<{
|
|
88
|
+
readonly type: Schema.Literal<"score">;
|
|
89
|
+
readonly score: Schema.Number;
|
|
90
|
+
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
91
|
+
readonly confidence: Schema.Number;
|
|
92
|
+
}>, Schema.Struct<{
|
|
93
|
+
readonly type: Schema.Literal<"refusal">;
|
|
94
|
+
readonly message: Schema.optional<Schema.String>;
|
|
95
|
+
}>]>;
|
|
57
96
|
readonly Response: Schema.Struct<{
|
|
58
97
|
readonly model: Schema.String;
|
|
59
98
|
readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
@@ -69,6 +108,9 @@ export declare const SystemOne: {
|
|
|
69
108
|
readonly score: Schema.Number;
|
|
70
109
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
71
110
|
readonly confidence: Schema.Number;
|
|
111
|
+
}>, Schema.Struct<{
|
|
112
|
+
readonly type: Schema.Literal<"refusal">;
|
|
113
|
+
readonly message: Schema.optional<Schema.String>;
|
|
72
114
|
}>]>>;
|
|
73
115
|
readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
|
|
74
116
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -94,6 +136,8 @@ export declare const SystemOne: {
|
|
|
94
136
|
};
|
|
95
137
|
};
|
|
96
138
|
}, AIError, never>;
|
|
139
|
+
readonly encodeQuestions: typeof encodeQuestions;
|
|
140
|
+
readonly toAnswer: typeof toAnswer;
|
|
97
141
|
readonly toResponse: typeof toResponse;
|
|
98
142
|
readonly protocol: DecisionRoute.Protocol;
|
|
99
143
|
readonly route: DecisionRoute.Route;
|
|
@@ -23,6 +23,8 @@ const Answer = Schema.Union([
|
|
|
23
23
|
probabilities: Schema.Record(Schema.String, Probability),
|
|
24
24
|
confidence: Probability,
|
|
25
25
|
}),
|
|
26
|
+
// OpenRouter's and OpenCode Zen's answer for a question the upstream model declined.
|
|
27
|
+
Schema.Struct({ type: Schema.Literal("refusal"), message: Schema.optional(Schema.String) }),
|
|
26
28
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
27
29
|
const NativeUsage = Schema.StructWithRest(Schema.Struct({
|
|
28
30
|
input_tokens: Schema.optional(Schema.Number),
|
|
@@ -67,7 +69,7 @@ const encodeQuestions = (questions) => Effect.forEach(questions, (question) => {
|
|
|
67
69
|
// Options are map keys, so `true` is sent as "true" and mapped back by `choiceValue`.
|
|
68
70
|
const keys = question.choices.map((choice) => String(choice.value));
|
|
69
71
|
if (new Set(keys).size !== keys.length)
|
|
70
|
-
return Effect.fail(ProviderShared.invalidRequest(`
|
|
72
|
+
return Effect.fail(ProviderShared.invalidRequest(`Decision choice options are sent as string keys; "${question.name}" has a boolean and a string with the same text`));
|
|
71
73
|
return Effect.succeed([
|
|
72
74
|
question.name,
|
|
73
75
|
{
|
|
@@ -91,7 +93,7 @@ const placeMedia = Effect.fnUntraced(function* (request, mediaInput) {
|
|
|
91
93
|
if (media.length === 0)
|
|
92
94
|
return { state: state(parts.map(plain)) };
|
|
93
95
|
if (mediaInput === "state")
|
|
94
|
-
return { state: yield* Effect.forEach(parts, (part) => stateItem(part, unsupported)) };
|
|
96
|
+
return { state: yield* Effect.forEach(parts, (part) => stateItem(part, unsupported, true)) };
|
|
95
97
|
// Chat-style content in one user message: text and JSON as text parts, media as in `state`.
|
|
96
98
|
if (mediaInput === "state.messages")
|
|
97
99
|
return {
|
|
@@ -100,7 +102,7 @@ const placeMedia = Effect.fnUntraced(function* (request, mediaInput) {
|
|
|
100
102
|
{
|
|
101
103
|
role: "user",
|
|
102
104
|
content: yield* Effect.forEach(parts, (part) => part.type === "media"
|
|
103
|
-
? stateItem(part, unsupported)
|
|
105
|
+
? stateItem(part, unsupported, false)
|
|
104
106
|
: Effect.succeed({ type: "text", text: part.type === "text" ? part.text : encodeJson(part.value) })),
|
|
105
107
|
},
|
|
106
108
|
],
|
|
@@ -144,20 +146,37 @@ const plain = (part) => {
|
|
|
144
146
|
return part.value;
|
|
145
147
|
return undefined;
|
|
146
148
|
};
|
|
147
|
-
|
|
149
|
+
/** A media part as a Chat Completions content part; `files` sends other media, such as PDFs, as `file` parts. */
|
|
150
|
+
const stateItem = (part, unsupported, files) => {
|
|
148
151
|
if (part.type !== "media")
|
|
149
152
|
return Effect.succeed(plain(part));
|
|
150
153
|
const asset = part.media;
|
|
151
|
-
if (asset.kind !== "image" && asset.kind !== "audio" && asset.kind !== "video")
|
|
154
|
+
if (!files && asset.kind !== "image" && asset.kind !== "audio" && asset.kind !== "video")
|
|
152
155
|
return Effect.fail(unsupported(asset, "images, audio and video"));
|
|
153
156
|
return ProviderShared.requireInlineMedia(NAME, asset).pipe(Effect.map((inline) => {
|
|
154
157
|
if (asset.kind === "image")
|
|
155
158
|
return { type: "image_url", image_url: { url: inline.dataUrl } };
|
|
156
159
|
if (asset.kind === "video")
|
|
157
160
|
return { type: "video_url", video_url: { url: inline.dataUrl } };
|
|
158
|
-
|
|
161
|
+
if (asset.kind === "audio") {
|
|
162
|
+
const format = inline.mime.slice("audio/".length).toLowerCase();
|
|
163
|
+
return { type: "input_audio", input_audio: { data: inline.base64, format: audioFormats[format] ?? format } };
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
type: "file",
|
|
167
|
+
file: { file_data: inline.dataUrl, ...(part.filename === undefined ? {} : { filename: part.filename }) },
|
|
168
|
+
};
|
|
159
169
|
}));
|
|
160
170
|
};
|
|
171
|
+
/** OpenRouter's `input_audio` format names for MIME subtypes that aren't one themselves. */
|
|
172
|
+
const audioFormats = {
|
|
173
|
+
"x-wav": "wav",
|
|
174
|
+
wave: "wav",
|
|
175
|
+
"vnd.wave": "wav",
|
|
176
|
+
"x-m4a": "m4a",
|
|
177
|
+
"x-aiff": "aiff",
|
|
178
|
+
"x-flac": "flac",
|
|
179
|
+
};
|
|
161
180
|
/** Map System One's answers, keyed by question name, back to the request's question order. */
|
|
162
181
|
export const toResponse = (data, request, providerMetadataKey, invalid) => {
|
|
163
182
|
const names = request.questions.map((question) => question.name);
|
|
@@ -185,6 +204,13 @@ export const toResponse = (data, request, providerMetadataKey, invalid) => {
|
|
|
185
204
|
}));
|
|
186
205
|
};
|
|
187
206
|
const toAnswer = (question, answer) => {
|
|
207
|
+
if (answer.type === "refusal")
|
|
208
|
+
return {
|
|
209
|
+
name: question.name,
|
|
210
|
+
type: "error",
|
|
211
|
+
reason: "refusal",
|
|
212
|
+
...(answer.message === undefined ? {} : { message: answer.message }),
|
|
213
|
+
};
|
|
188
214
|
if (answer.type === "noul")
|
|
189
215
|
return { name: question.name, type: "predicate", probability: answer.noul };
|
|
190
216
|
if (answer.type === "choice") {
|
|
@@ -234,4 +260,13 @@ export const route = DecisionRoute.make({
|
|
|
234
260
|
protocol,
|
|
235
261
|
endpoint: Endpoint.path("/systemone", { baseURL: DEFAULT_BASE_URL }),
|
|
236
262
|
});
|
|
237
|
-
export const SystemOne = {
|
|
263
|
+
export const SystemOne = {
|
|
264
|
+
Answer,
|
|
265
|
+
Response,
|
|
266
|
+
encodeBody,
|
|
267
|
+
encodeQuestions,
|
|
268
|
+
toAnswer,
|
|
269
|
+
toResponse,
|
|
270
|
+
protocol,
|
|
271
|
+
route,
|
|
272
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
3
|
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
|
+
import { foldToolUpdates } from "../../tool-updates.js";
|
|
4
5
|
import { Endpoint } from "../../route/endpoint.js";
|
|
5
6
|
import { RequestExecutor } from "../../route/executor.js";
|
|
6
7
|
import { HttpTransport } from "../../route/transport/index.js";
|
|
@@ -62,10 +63,13 @@ const Response = Schema.Struct({
|
|
|
62
63
|
});
|
|
63
64
|
export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
64
65
|
const route = request.model.route;
|
|
65
|
-
// The standalone compaction endpoint rejects
|
|
66
|
-
|
|
66
|
+
// The standalone compaction endpoint rejects effort updates (`configuration_update`). Every tool goes in
|
|
67
|
+
// top-level `tools`: after compacting a history whose tools were only in `additional_tools`, small models lost
|
|
68
|
+
// track of them more often.
|
|
69
|
+
const folded = foldToolUpdates(stripEffortUpdates(request));
|
|
70
|
+
const native = yield* OpenResponses.lowerConversation(folded, adapter);
|
|
67
71
|
const generation = OpenResponses.lowerGeneration(request);
|
|
68
|
-
const tools =
|
|
72
|
+
const tools = folded.tools.length === 0 ? undefined : yield* lowerTools(folded);
|
|
69
73
|
const body = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
70
74
|
...native,
|
|
71
75
|
service_tier: generation.service_tier,
|
|
@@ -88,7 +92,7 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
88
92
|
auth: route.auth,
|
|
89
93
|
encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)),
|
|
90
94
|
});
|
|
91
|
-
const response = yield* executor.execute(ProviderShared.jsonPost({
|
|
95
|
+
const response = yield* RequestExecutor.withTls(executor.execute, request.http?.tls)(ProviderShared.jsonPost({
|
|
92
96
|
url: parts.url,
|
|
93
97
|
body: parts.bodyText,
|
|
94
98
|
headers: parts.headers,
|