@opencode/ai 2.3.0 → 2.3.2
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 +65 -18
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +3 -1
- 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 -8
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +25 -25
- package/dist/index.js +29 -22
- 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.d.ts +17 -1
- package/dist/media.js +28 -7
- 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-interactions-video.d.ts +4 -9
- package/dist/protocols/google-interactions-video.js +9 -10
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- 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 +6 -15
- package/dist/protocols/minimax-video.js +25 -27
- package/dist/protocols/open-responses.d.ts +410 -138
- package/dist/protocols/open-responses.js +47 -28
- 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 +4 -9
- package/dist/protocols/openrouter-video.js +14 -13
- package/dist/protocols/seedance-video.d.ts +4 -9
- package/dist/protocols/seedance-video.js +13 -12
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +14 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +4 -9
- package/dist/protocols/xai-video.js +13 -9
- package/dist/protocols/zai-messages.d.ts +24 -2
- 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/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -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 +3 -3
- package/dist/providers/google.js +5 -2
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax.d.ts +50 -2
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter.d.ts +26 -0
- package/dist/providers/venice.d.ts +26 -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 +5 -4
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +14 -1
- package/dist/route/executor-service.js +28 -1
- package/dist/route/executor.d.ts +5 -2
- package/dist/route/executor.js +20 -5
- package/dist/route/media-protocol.d.ts +12 -7
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.js +12 -3
- package/dist/route/protocol.d.ts +3 -0
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +24 -1
- package/dist/schema/messages.js +26 -2
- package/dist/schema/options.d.ts +10 -2
- package/dist/speech-client.d.ts +5 -5
- 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 +5 -5
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +6 -6
- package/dist/video-client.js +13 -11
- package/dist/video.d.ts +17 -73
- package/dist/video.js +9 -8
- package/package.json +7 -3
|
@@ -11,7 +11,8 @@ export const PATH = "/videos";
|
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// 2. Token and response schemas
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
|
-
|
|
14
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
15
|
+
export const Token = Schema.String;
|
|
15
16
|
const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
|
|
16
17
|
const Job = Schema.Struct({
|
|
17
18
|
id: optionalNull(Schema.String),
|
|
@@ -29,7 +30,7 @@ const Job = Schema.Struct({
|
|
|
29
30
|
// 3. Status
|
|
30
31
|
// ---------------------------------------------------------------------------
|
|
31
32
|
const STATUS = {
|
|
32
|
-
pending: "
|
|
33
|
+
pending: "running",
|
|
33
34
|
in_progress: "running",
|
|
34
35
|
completed: "completed",
|
|
35
36
|
failed: "failed",
|
|
@@ -77,20 +78,20 @@ const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value
|
|
|
77
78
|
// 5. Response decoding
|
|
78
79
|
// ---------------------------------------------------------------------------
|
|
79
80
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
80
|
-
token:
|
|
81
|
-
snapshot: { id: value.id,
|
|
81
|
+
token: value.id,
|
|
82
|
+
snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status ?? "pending") },
|
|
82
83
|
}));
|
|
83
84
|
const decodeJob = route.decodeJson(Job);
|
|
84
85
|
const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
|
|
85
86
|
const output = yield* decodeJob(response);
|
|
86
|
-
return { id: context.token
|
|
87
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
87
88
|
});
|
|
88
89
|
const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
|
|
89
90
|
const output = yield* decodeJob(response);
|
|
90
91
|
const job = output.value;
|
|
91
|
-
const status = MediaProtocol.
|
|
92
|
-
if (status === "
|
|
93
|
-
return yield* output.pending(context.token
|
|
92
|
+
const status = MediaProtocol.state(STATUS, job.status);
|
|
93
|
+
if (status === "running")
|
|
94
|
+
return yield* output.pending(context.token);
|
|
94
95
|
if (status === "failed") {
|
|
95
96
|
const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
|
|
96
97
|
if (job.error && /content policy|moderat/i.test(job.error))
|
|
@@ -98,21 +99,21 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
|
|
|
98
99
|
return yield* output.ended("failed", message);
|
|
99
100
|
}
|
|
100
101
|
if (status !== "completed")
|
|
101
|
-
return yield* output.ended(status, `${route.name} job ${context.token
|
|
102
|
+
return yield* output.ended(status, `${route.name} job ${context.token} ${status}${job.error ? `: ${job.error}` : ""}`);
|
|
102
103
|
const urls = job.unsigned_urls ?? [];
|
|
103
104
|
if (urls.length === 0)
|
|
104
105
|
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
105
106
|
// The content URLs are OpenRouter's own and only download with the API key.
|
|
106
|
-
const videos = yield* Effect.forEach(urls, (url) => context.
|
|
107
|
+
const videos = yield* Effect.forEach(urls, (url) => context.credentials(url).pipe(Effect.map((credentials) => Media.url(url, {
|
|
107
108
|
mediaType: "video/mp4",
|
|
108
109
|
expiresAt: job.expires_at === undefined || job.expires_at === null ? undefined : job.expires_at * 1000,
|
|
109
|
-
|
|
110
|
+
...credentials,
|
|
110
111
|
}))));
|
|
111
112
|
return new VideoResponse({
|
|
112
113
|
videos,
|
|
113
114
|
providerMetadata: {
|
|
114
115
|
openrouter: {
|
|
115
|
-
id: context.token
|
|
116
|
+
id: context.token,
|
|
116
117
|
generationId: job.generation_id ?? undefined,
|
|
117
118
|
cost: job.usage?.cost ?? undefined,
|
|
118
119
|
isByok: job.usage?.is_byok ?? undefined,
|
|
@@ -123,7 +124,7 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
|
|
|
123
124
|
// ---------------------------------------------------------------------------
|
|
124
125
|
// 6. Protocol and route
|
|
125
126
|
// ---------------------------------------------------------------------------
|
|
126
|
-
const jobPath = (token) => `${PATH}/${encodeURIComponent(token
|
|
127
|
+
const jobPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
127
128
|
// OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
|
|
128
129
|
export const protocol = MediaProtocol.queued(route, {
|
|
129
130
|
token: Token,
|
|
@@ -29,22 +29,17 @@ export type SeedanceVideoOptions = {
|
|
|
29
29
|
readonly safety_identifier?: string;
|
|
30
30
|
} & Record<string, unknown>;
|
|
31
31
|
export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}>;
|
|
32
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
33
|
+
export declare const Token: Schema.String;
|
|
35
34
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
36
35
|
export type Provider = "volcengine" | "byteplus";
|
|
37
36
|
export declare const SeedanceVideo: {
|
|
38
37
|
readonly volcengine: {
|
|
39
|
-
protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
40
|
-
readonly taskID: string;
|
|
41
|
-
}>;
|
|
38
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
42
39
|
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
43
40
|
};
|
|
44
41
|
readonly byteplus: {
|
|
45
|
-
protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
46
|
-
readonly taskID: string;
|
|
47
|
-
}>;
|
|
42
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
48
43
|
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
49
44
|
};
|
|
50
45
|
};
|
|
@@ -14,7 +14,8 @@ const OUTPUT_RETENTION = Duration.hours(24);
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// 2. Token and response schemas
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
17
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
18
|
+
export const Token = Schema.String;
|
|
18
19
|
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
19
20
|
const Task = Schema.Struct({
|
|
20
21
|
id: optionalNull(Schema.String),
|
|
@@ -45,7 +46,7 @@ const Task = Schema.Struct({
|
|
|
45
46
|
service_tier: optionalNull(Schema.String),
|
|
46
47
|
});
|
|
47
48
|
const STATUS = {
|
|
48
|
-
queued: "
|
|
49
|
+
queued: "running",
|
|
49
50
|
running: "running",
|
|
50
51
|
succeeded: "completed",
|
|
51
52
|
failed: "failed",
|
|
@@ -125,20 +126,20 @@ const make = (provider) => {
|
|
|
125
126
|
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
126
127
|
});
|
|
127
128
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
128
|
-
token:
|
|
129
|
-
snapshot: { id: value.id, status: "
|
|
129
|
+
token: value.id,
|
|
130
|
+
snapshot: { id: value.id, status: "running" },
|
|
130
131
|
}));
|
|
131
132
|
const decodeTask = route.decodeJson(Task);
|
|
132
133
|
const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
|
|
133
134
|
const output = yield* decodeTask(response);
|
|
134
|
-
return { id: context.token
|
|
135
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
135
136
|
});
|
|
136
137
|
const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
|
|
137
138
|
const output = yield* decodeTask(response);
|
|
138
139
|
const task = output.value;
|
|
139
|
-
const status = MediaProtocol.
|
|
140
|
-
if (status === "
|
|
141
|
-
return yield* output.pending(context.token
|
|
140
|
+
const status = MediaProtocol.state(STATUS, task.status);
|
|
141
|
+
if (status === "running")
|
|
142
|
+
return yield* output.pending(context.token);
|
|
142
143
|
if (status === "failed") {
|
|
143
144
|
const code = task.error?.code ?? undefined;
|
|
144
145
|
const detail = task.error?.message ?? undefined;
|
|
@@ -148,9 +149,9 @@ const make = (provider) => {
|
|
|
148
149
|
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
|
|
149
150
|
}
|
|
150
151
|
if (status === "cancelled")
|
|
151
|
-
return yield* output.ended("cancelled", `${route.name} task ${context.token
|
|
152
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
152
153
|
if (status === "expired")
|
|
153
|
-
return yield* output.ended("expired", `${route.name} task ${context.token
|
|
154
|
+
return yield* output.ended("expired", `${route.name} task ${context.token} expired`);
|
|
154
155
|
const videoURL = task.content?.video_url ?? undefined;
|
|
155
156
|
if (videoURL === undefined)
|
|
156
157
|
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
@@ -177,7 +178,7 @@ const make = (provider) => {
|
|
|
177
178
|
},
|
|
178
179
|
providerMetadata: {
|
|
179
180
|
[provider]: {
|
|
180
|
-
taskId: context.token
|
|
181
|
+
taskId: context.token,
|
|
181
182
|
model: task.model ?? undefined,
|
|
182
183
|
seed: task.seed ?? undefined,
|
|
183
184
|
ratio: task.ratio ?? undefined,
|
|
@@ -194,7 +195,7 @@ const make = (provider) => {
|
|
|
194
195
|
},
|
|
195
196
|
});
|
|
196
197
|
});
|
|
197
|
-
const taskPath = (token) => `${PATH}/${token
|
|
198
|
+
const taskPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
198
199
|
// DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
|
|
199
200
|
const protocol = MediaProtocol.queued(route, {
|
|
200
201
|
token: Token,
|
|
@@ -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";
|
|
@@ -57,15 +58,22 @@ const Response = Schema.Struct({
|
|
|
57
58
|
role: Schema.Literal("assistant"),
|
|
58
59
|
content: Schema.Array(Text).check(Schema.isMinLength(1)),
|
|
59
60
|
}),
|
|
61
|
+
// The system prompt sent as a developer message, echoed back; the next request leads with its own.
|
|
62
|
+
Schema.Struct({ ...MessageFields, role: Schema.Literal("developer"), content: Schema.Unknown }),
|
|
60
63
|
])),
|
|
61
64
|
usage: Schema.optional(Schema.StructWithRest(OpenResponses.OpenResponsesUsage, [JsonObject])),
|
|
62
65
|
});
|
|
63
66
|
export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
64
67
|
const route = request.model.route;
|
|
65
|
-
// The standalone compaction endpoint rejects
|
|
66
|
-
|
|
68
|
+
// The standalone compaction endpoint rejects effort updates (`configuration_update`). Every tool goes in
|
|
69
|
+
// top-level `tools`: after compacting a history whose tools were only in `additional_tools`, small models lost
|
|
70
|
+
// track of them more often.
|
|
71
|
+
const folded = foldToolUpdates(stripEffortUpdates(request));
|
|
72
|
+
// The system prompt leads `input` as a developer message, as every step's request does, so `/compact` reads the
|
|
73
|
+
// prefix those requests cached.
|
|
74
|
+
const native = yield* OpenResponses.lowerConversation(folded, adapter);
|
|
67
75
|
const generation = OpenResponses.lowerGeneration(request);
|
|
68
|
-
const tools =
|
|
76
|
+
const tools = folded.tools.length === 0 ? undefined : yield* lowerTools(folded);
|
|
69
77
|
const body = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
70
78
|
...native,
|
|
71
79
|
service_tier: generation.service_tier,
|
|
@@ -108,7 +116,9 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
108
116
|
if (!result.output.some((item) => item.type === "compaction"))
|
|
109
117
|
return yield* invalid("Compaction response did not contain a checkpoint");
|
|
110
118
|
return new CompactionResponse({
|
|
111
|
-
replacement: result.output
|
|
119
|
+
replacement: result.output
|
|
120
|
+
.filter((item) => item.type !== "message" || item.role !== "developer")
|
|
121
|
+
.map((item) => toMessage(item, request.model)),
|
|
112
122
|
usage: OpenResponses.mapUsage(result.usage, OpenResponses.metadataKey(request.model)),
|
|
113
123
|
});
|
|
114
124
|
});
|
|
@@ -12,6 +12,32 @@ export declare const protocol: Protocol<{
|
|
|
12
12
|
readonly reasoning: {
|
|
13
13
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
14
14
|
};
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "additional_tools";
|
|
17
|
+
readonly role: "developer";
|
|
18
|
+
readonly tools: readonly ({
|
|
19
|
+
readonly type: "custom";
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly format: {
|
|
23
|
+
readonly type: "text";
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "grammar";
|
|
26
|
+
readonly syntax: "lark" | "regex";
|
|
27
|
+
readonly definition: string;
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "function";
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly parameters: {
|
|
34
|
+
readonly [x: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
readonly strict?: boolean | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly [x: string]: unknown;
|
|
39
|
+
readonly type: string;
|
|
40
|
+
})[];
|
|
15
41
|
} | {
|
|
16
42
|
readonly type: "message";
|
|
17
43
|
readonly role: "system";
|
|
@@ -24,17 +24,12 @@ export type XAIVideoOptions = {
|
|
|
24
24
|
}>;
|
|
25
25
|
} & Record<string, unknown>;
|
|
26
26
|
export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}>;
|
|
27
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
28
|
+
export declare const Token: Schema.String;
|
|
30
29
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
31
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
32
|
-
readonly requestID: string;
|
|
33
|
-
}>;
|
|
30
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
34
31
|
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<XAIVideoOptions>;
|
|
35
32
|
export declare const XAIVideo: {
|
|
36
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
37
|
-
readonly requestID: string;
|
|
38
|
-
}>;
|
|
33
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
39
34
|
readonly model: typeof model;
|
|
40
35
|
};
|
|
@@ -14,7 +14,8 @@ export const STATUS_PATH = "/videos";
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// 2. Token and response schemas
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
17
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
18
|
+
export const Token = Schema.String;
|
|
18
19
|
const StartResponse = Schema.Struct({ request_id: Schema.String });
|
|
19
20
|
const VideoStatus = Schema.Struct({
|
|
20
21
|
status: Schema.String,
|
|
@@ -78,7 +79,7 @@ const fromRequest = Effect.fn("XAIVideo.fromRequest")(function* (request) {
|
|
|
78
79
|
// 6. Response decoding
|
|
79
80
|
// ---------------------------------------------------------------------------
|
|
80
81
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
81
|
-
token:
|
|
82
|
+
token: value.request_id,
|
|
82
83
|
snapshot: { id: value.request_id, status: "running" },
|
|
83
84
|
}));
|
|
84
85
|
// `progress` is undocumented but observed live as a 0..100 percentage (recorded cassette: 1 → 10 → 37 → 100).
|
|
@@ -86,22 +87,25 @@ const fraction = (progress) => progress !== undefined && progress !== null && pr
|
|
|
86
87
|
const decodeVideoStatus = route.decodeJson(VideoStatus);
|
|
87
88
|
const decodeStatus = Effect.fn("XAIVideo.decodeStatus")(function* (response, context) {
|
|
88
89
|
const output = yield* decodeVideoStatus(response);
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
return {
|
|
91
|
+
id: context.token,
|
|
92
|
+
...MediaProtocol.status(STATUS, output.value.status),
|
|
93
|
+
progress: fraction(output.value.progress),
|
|
94
|
+
};
|
|
91
95
|
});
|
|
92
96
|
const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, context) {
|
|
93
97
|
const output = yield* decodeVideoStatus(response);
|
|
94
98
|
const decoded = output.value;
|
|
95
|
-
const status = MediaProtocol.
|
|
99
|
+
const status = MediaProtocol.state(STATUS, decoded.status);
|
|
96
100
|
if (status === "running")
|
|
97
|
-
return yield* output.pending(context.token
|
|
101
|
+
return yield* output.pending(context.token);
|
|
98
102
|
if (status === "failed") {
|
|
99
103
|
const code = decoded.error?.code ?? undefined;
|
|
100
104
|
const message = decoded.error?.message ?? undefined;
|
|
101
105
|
return yield* output.ended("failed", `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${message === undefined ? "" : `: ${message}`}`, MediaProtocol.failure(FAILURE, code));
|
|
102
106
|
}
|
|
103
107
|
if (status !== "completed")
|
|
104
|
-
return yield* output.ended("expired", `${route.name} request ${context.token
|
|
108
|
+
return yield* output.ended("expired", `${route.name} request ${context.token} expired`);
|
|
105
109
|
// `respect_moderation: false` marks a filtered result; a URL may still be present, so only a missing one fails.
|
|
106
110
|
const moderated = decoded.video?.respect_moderation === false;
|
|
107
111
|
const url = decoded.video?.url ?? undefined;
|
|
@@ -119,7 +123,7 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
|
|
|
119
123
|
],
|
|
120
124
|
providerMetadata: {
|
|
121
125
|
xai: {
|
|
122
|
-
requestId: context.token
|
|
126
|
+
requestId: context.token,
|
|
123
127
|
model: decoded.model ?? undefined,
|
|
124
128
|
respectModeration: decoded.video?.respect_moderation ?? undefined,
|
|
125
129
|
},
|
|
@@ -129,7 +133,7 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
|
|
|
129
133
|
// ---------------------------------------------------------------------------
|
|
130
134
|
// 7. Protocol and route
|
|
131
135
|
// ---------------------------------------------------------------------------
|
|
132
|
-
const statusPath = (token) => `${STATUS_PATH}/${token
|
|
136
|
+
const statusPath = (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`;
|
|
133
137
|
export const protocol = MediaProtocol.queued(route, {
|
|
134
138
|
token: Token,
|
|
135
139
|
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
@@ -237,14 +237,36 @@ export declare const protocol: Protocol<{
|
|
|
237
237
|
})[];
|
|
238
238
|
} | {
|
|
239
239
|
readonly role: "system";
|
|
240
|
-
readonly content: readonly {
|
|
240
|
+
readonly content: readonly ({
|
|
241
|
+
readonly type: "tool_addition";
|
|
242
|
+
readonly tool: {
|
|
243
|
+
readonly type: "tool_definition";
|
|
244
|
+
readonly definition: {
|
|
245
|
+
readonly name: string;
|
|
246
|
+
readonly description: string;
|
|
247
|
+
readonly input_schema: {
|
|
248
|
+
readonly [x: string]: unknown;
|
|
249
|
+
};
|
|
250
|
+
readonly cache_control?: {
|
|
251
|
+
readonly type: "ephemeral";
|
|
252
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
253
|
+
} | undefined;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
readonly type: "tool_removal";
|
|
258
|
+
readonly tool: {
|
|
259
|
+
readonly type: "tool_reference";
|
|
260
|
+
readonly name: string;
|
|
261
|
+
};
|
|
262
|
+
} | {
|
|
241
263
|
readonly type: "text";
|
|
242
264
|
readonly text: string;
|
|
243
265
|
readonly cache_control?: {
|
|
244
266
|
readonly type: "ephemeral";
|
|
245
267
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
246
268
|
} | undefined;
|
|
247
|
-
}[];
|
|
269
|
+
})[];
|
|
248
270
|
readonly output_config?: {
|
|
249
271
|
readonly effort: string;
|
|
250
272
|
} | undefined;
|
|
@@ -448,14 +448,36 @@ export declare const routes: (Route<{
|
|
|
448
448
|
})[];
|
|
449
449
|
} | {
|
|
450
450
|
readonly role: "system";
|
|
451
|
-
readonly content: readonly {
|
|
451
|
+
readonly content: readonly ({
|
|
452
|
+
readonly type: "tool_addition";
|
|
453
|
+
readonly tool: {
|
|
454
|
+
readonly type: "tool_definition";
|
|
455
|
+
readonly definition: {
|
|
456
|
+
readonly name: string;
|
|
457
|
+
readonly description: string;
|
|
458
|
+
readonly input_schema: {
|
|
459
|
+
readonly [x: string]: unknown;
|
|
460
|
+
};
|
|
461
|
+
readonly cache_control?: {
|
|
462
|
+
readonly type: "ephemeral";
|
|
463
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
464
|
+
} | undefined;
|
|
465
|
+
};
|
|
466
|
+
};
|
|
467
|
+
} | {
|
|
468
|
+
readonly type: "tool_removal";
|
|
469
|
+
readonly tool: {
|
|
470
|
+
readonly type: "tool_reference";
|
|
471
|
+
readonly name: string;
|
|
472
|
+
};
|
|
473
|
+
} | {
|
|
452
474
|
readonly type: "text";
|
|
453
475
|
readonly text: string;
|
|
454
476
|
readonly cache_control?: {
|
|
455
477
|
readonly type: "ephemeral";
|
|
456
478
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
457
479
|
} | undefined;
|
|
458
|
-
}[];
|
|
480
|
+
})[];
|
|
459
481
|
readonly output_config?: {
|
|
460
482
|
readonly effort: string;
|
|
461
483
|
} | undefined;
|
|
@@ -521,6 +543,32 @@ export declare const routes: (Route<{
|
|
|
521
543
|
readonly reasoning: {
|
|
522
544
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
523
545
|
};
|
|
546
|
+
} | {
|
|
547
|
+
readonly type: "additional_tools";
|
|
548
|
+
readonly role: "developer";
|
|
549
|
+
readonly tools: readonly ({
|
|
550
|
+
readonly type: "custom";
|
|
551
|
+
readonly name: string;
|
|
552
|
+
readonly description: string;
|
|
553
|
+
readonly format: {
|
|
554
|
+
readonly type: "text";
|
|
555
|
+
} | {
|
|
556
|
+
readonly type: "grammar";
|
|
557
|
+
readonly syntax: "lark" | "regex";
|
|
558
|
+
readonly definition: string;
|
|
559
|
+
};
|
|
560
|
+
} | {
|
|
561
|
+
readonly type: "function";
|
|
562
|
+
readonly name: string;
|
|
563
|
+
readonly description: string;
|
|
564
|
+
readonly parameters: {
|
|
565
|
+
readonly [x: string]: unknown;
|
|
566
|
+
};
|
|
567
|
+
readonly strict?: boolean | undefined;
|
|
568
|
+
} | {
|
|
569
|
+
readonly [x: string]: unknown;
|
|
570
|
+
readonly type: string;
|
|
571
|
+
})[];
|
|
524
572
|
} | {
|
|
525
573
|
readonly type: "message";
|
|
526
574
|
readonly role: "system";
|
|
@@ -266,14 +266,36 @@ export declare const routes: (Route<{
|
|
|
266
266
|
})[];
|
|
267
267
|
} | {
|
|
268
268
|
readonly role: "system";
|
|
269
|
-
readonly content: readonly {
|
|
269
|
+
readonly content: readonly ({
|
|
270
|
+
readonly type: "tool_addition";
|
|
271
|
+
readonly tool: {
|
|
272
|
+
readonly type: "tool_definition";
|
|
273
|
+
readonly definition: {
|
|
274
|
+
readonly name: string;
|
|
275
|
+
readonly description: string;
|
|
276
|
+
readonly input_schema: {
|
|
277
|
+
readonly [x: string]: unknown;
|
|
278
|
+
};
|
|
279
|
+
readonly cache_control?: {
|
|
280
|
+
readonly type: "ephemeral";
|
|
281
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
282
|
+
} | undefined;
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
} | {
|
|
286
|
+
readonly type: "tool_removal";
|
|
287
|
+
readonly tool: {
|
|
288
|
+
readonly type: "tool_reference";
|
|
289
|
+
readonly name: string;
|
|
290
|
+
};
|
|
291
|
+
} | {
|
|
270
292
|
readonly type: "text";
|
|
271
293
|
readonly text: string;
|
|
272
294
|
readonly cache_control?: {
|
|
273
295
|
readonly type: "ephemeral";
|
|
274
296
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
275
297
|
} | undefined;
|
|
276
|
-
}[];
|
|
298
|
+
})[];
|
|
277
299
|
readonly output_config?: {
|
|
278
300
|
readonly effort: string;
|
|
279
301
|
} | undefined;
|
|
@@ -351,6 +373,32 @@ export declare const routes: (Route<{
|
|
|
351
373
|
readonly reasoning: {
|
|
352
374
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
353
375
|
};
|
|
376
|
+
} | {
|
|
377
|
+
readonly type: "additional_tools";
|
|
378
|
+
readonly role: "developer";
|
|
379
|
+
readonly tools: readonly ({
|
|
380
|
+
readonly type: "custom";
|
|
381
|
+
readonly name: string;
|
|
382
|
+
readonly description: string;
|
|
383
|
+
readonly format: {
|
|
384
|
+
readonly type: "text";
|
|
385
|
+
} | {
|
|
386
|
+
readonly type: "grammar";
|
|
387
|
+
readonly syntax: "lark" | "regex";
|
|
388
|
+
readonly definition: string;
|
|
389
|
+
};
|
|
390
|
+
} | {
|
|
391
|
+
readonly type: "function";
|
|
392
|
+
readonly name: string;
|
|
393
|
+
readonly description: string;
|
|
394
|
+
readonly parameters: {
|
|
395
|
+
readonly [x: string]: unknown;
|
|
396
|
+
};
|
|
397
|
+
readonly strict?: boolean | undefined;
|
|
398
|
+
} | {
|
|
399
|
+
readonly [x: string]: unknown;
|
|
400
|
+
readonly type: string;
|
|
401
|
+
})[];
|
|
354
402
|
} | {
|
|
355
403
|
readonly type: "message";
|
|
356
404
|
readonly role: "system";
|
|
@@ -250,14 +250,36 @@ export declare const routes: import("../route.js").Route<{
|
|
|
250
250
|
})[];
|
|
251
251
|
} | {
|
|
252
252
|
readonly role: "system";
|
|
253
|
-
readonly content: readonly {
|
|
253
|
+
readonly content: readonly ({
|
|
254
|
+
readonly type: "tool_addition";
|
|
255
|
+
readonly tool: {
|
|
256
|
+
readonly type: "tool_definition";
|
|
257
|
+
readonly definition: {
|
|
258
|
+
readonly name: string;
|
|
259
|
+
readonly description: string;
|
|
260
|
+
readonly input_schema: {
|
|
261
|
+
readonly [x: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
readonly cache_control?: {
|
|
264
|
+
readonly type: "ephemeral";
|
|
265
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
266
|
+
} | undefined;
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
} | {
|
|
270
|
+
readonly type: "tool_removal";
|
|
271
|
+
readonly tool: {
|
|
272
|
+
readonly type: "tool_reference";
|
|
273
|
+
readonly name: string;
|
|
274
|
+
};
|
|
275
|
+
} | {
|
|
254
276
|
readonly type: "text";
|
|
255
277
|
readonly text: string;
|
|
256
278
|
readonly cache_control?: {
|
|
257
279
|
readonly type: "ephemeral";
|
|
258
280
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
259
281
|
} | undefined;
|
|
260
|
-
}[];
|
|
282
|
+
})[];
|
|
261
283
|
readonly output_config?: {
|
|
262
284
|
readonly effort: string;
|
|
263
285
|
} | undefined;
|
|
@@ -235,14 +235,36 @@ export declare const routes: import("../route.js").Route<{
|
|
|
235
235
|
})[];
|
|
236
236
|
} | {
|
|
237
237
|
readonly role: "system";
|
|
238
|
-
readonly content: readonly {
|
|
238
|
+
readonly content: readonly ({
|
|
239
|
+
readonly type: "tool_addition";
|
|
240
|
+
readonly tool: {
|
|
241
|
+
readonly type: "tool_definition";
|
|
242
|
+
readonly definition: {
|
|
243
|
+
readonly name: string;
|
|
244
|
+
readonly description: string;
|
|
245
|
+
readonly input_schema: {
|
|
246
|
+
readonly [x: string]: unknown;
|
|
247
|
+
};
|
|
248
|
+
readonly cache_control?: {
|
|
249
|
+
readonly type: "ephemeral";
|
|
250
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
251
|
+
} | undefined;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
} | {
|
|
255
|
+
readonly type: "tool_removal";
|
|
256
|
+
readonly tool: {
|
|
257
|
+
readonly type: "tool_reference";
|
|
258
|
+
readonly name: string;
|
|
259
|
+
};
|
|
260
|
+
} | {
|
|
239
261
|
readonly type: "text";
|
|
240
262
|
readonly text: string;
|
|
241
263
|
readonly cache_control?: {
|
|
242
264
|
readonly type: "ephemeral";
|
|
243
265
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
244
266
|
} | undefined;
|
|
245
|
-
}[];
|
|
267
|
+
})[];
|
|
246
268
|
readonly output_config?: {
|
|
247
269
|
readonly effort: string;
|
|
248
270
|
} | undefined;
|