@opencode/ai 0.0.0-dev-20212 → 0.0.0-dev-20213
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.
|
@@ -17,7 +17,7 @@ export const Token = Schema.Struct({ operation: Schema.String });
|
|
|
17
17
|
const StartResponse = Schema.Struct({ name: Schema.String });
|
|
18
18
|
const Operation = Schema.Struct({
|
|
19
19
|
done: Schema.optional(Schema.Boolean),
|
|
20
|
-
error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
|
|
20
|
+
error: Schema.optional(Schema.Struct({ code: Schema.optional(Schema.Number), message: Schema.optional(Schema.String) })),
|
|
21
21
|
response: Schema.optional(Schema.Struct({
|
|
22
22
|
generateVideoResponse: Schema.optional(Schema.Struct({
|
|
23
23
|
generatedSamples: optionalArray(Schema.Struct({
|
|
@@ -32,6 +32,15 @@ const Operation = Schema.Struct({
|
|
|
32
32
|
})),
|
|
33
33
|
metadata: Schema.optional(Schema.Unknown),
|
|
34
34
|
});
|
|
35
|
+
// Operation errors are `google.rpc.Status`; unlisted codes (INTERNAL, UNAVAILABLE, ...) are provider-side.
|
|
36
|
+
const FAILURE = {
|
|
37
|
+
3: "InvalidRequest", // INVALID_ARGUMENT
|
|
38
|
+
7: "Authentication", // PERMISSION_DENIED
|
|
39
|
+
8: "RateLimit", // RESOURCE_EXHAUSTED
|
|
40
|
+
9: "InvalidRequest", // FAILED_PRECONDITION
|
|
41
|
+
11: "InvalidRequest", // OUT_OF_RANGE
|
|
42
|
+
16: "Authentication", // UNAUTHENTICATED
|
|
43
|
+
};
|
|
35
44
|
// ---------------------------------------------------------------------------
|
|
36
45
|
// 5. Request body construction
|
|
37
46
|
// ---------------------------------------------------------------------------
|
|
@@ -92,7 +101,7 @@ const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response,
|
|
|
92
101
|
if (status === "running")
|
|
93
102
|
return yield* output.pending(context.token.operation);
|
|
94
103
|
if (status === "failed")
|
|
95
|
-
return yield* output.ended("failed", `${route.name} operation failed${operation.error?.message === undefined ? "" : `: ${operation.error.message}`}
|
|
104
|
+
return yield* output.ended("failed", `${route.name} operation failed${operation.error?.message === undefined ? "" : `: ${operation.error.message}`}`, MediaProtocol.failure(FAILURE, operation.error?.code));
|
|
96
105
|
const generated = operation.response?.generateVideoResponse;
|
|
97
106
|
// Downloads require the same API key as the poll; the asset carries it transiently and follows the redirect.
|
|
98
107
|
const videos = yield* Effect.forEach((generated?.generatedSamples ?? []).flatMap((sample) => sample.video?.uri === undefined ? [] : [{ uri: sample.video.uri, mimeType: sample.video.mimeType }]), (video) => MediaProtocol.expiringUrl(video.uri, FILE_RETENTION, {
|
|
@@ -89,7 +89,8 @@ const decodeResult = Effect.fn("RunwayVideo.decodeResult")(function* (response,
|
|
|
89
89
|
// Runway failure codes are dotted paths; every moderation outcome carries a SAFETY segment.
|
|
90
90
|
if (code !== undefined && /(^|\.)SAFETY(\.|$)/.test(code))
|
|
91
91
|
return yield* output.contentPolicy(message);
|
|
92
|
-
|
|
92
|
+
// ASSET.INVALID rejects the caller's input media; Runway documents it as not retryable.
|
|
93
|
+
return yield* output.ended("failed", message, code !== undefined && /^ASSET\.INVALID(\.|$)/.test(code) ? "InvalidRequest" : "ProviderInternal");
|
|
93
94
|
}
|
|
94
95
|
if (status === "cancelled")
|
|
95
96
|
return yield* output.ended("cancelled", `${route.name} task ${context.token.taskID} was cancelled`);
|
|
@@ -36,6 +36,12 @@ const STATUS = {
|
|
|
36
36
|
failed: "failed",
|
|
37
37
|
expired: "expired",
|
|
38
38
|
};
|
|
39
|
+
// Documented video error codes; `service_unavailable`, `internal_error`, and unknown codes are provider-side.
|
|
40
|
+
const FAILURE = {
|
|
41
|
+
invalid_argument: "InvalidRequest",
|
|
42
|
+
failed_precondition: "InvalidRequest",
|
|
43
|
+
permission_denied: "Authentication",
|
|
44
|
+
};
|
|
39
45
|
// ---------------------------------------------------------------------------
|
|
40
46
|
// 5. Request body construction
|
|
41
47
|
// ---------------------------------------------------------------------------
|
|
@@ -88,7 +94,7 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
|
|
|
88
94
|
if (status === "failed") {
|
|
89
95
|
const code = decoded.error?.code ?? undefined;
|
|
90
96
|
const message = decoded.error?.message ?? undefined;
|
|
91
|
-
return yield* output.ended("failed", `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${message === undefined ? "" : `: ${message}`}
|
|
97
|
+
return yield* output.ended("failed", `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${message === undefined ? "" : `: ${message}`}`, MediaProtocol.failure(FAILURE, code));
|
|
92
98
|
}
|
|
93
99
|
if (status !== "completed")
|
|
94
100
|
return yield* output.ended("expired", `${route.name} request ${context.token.requestID} expired`);
|
|
@@ -3,7 +3,7 @@ import { HttpClientResponse } from "effect/unstable/http";
|
|
|
3
3
|
import type { Snapshot, Status } from "../generation.js";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
5
|
import type { AuthInput } from "./auth.js";
|
|
6
|
-
import { AIError, HttpContext, ProviderID } from "../schema/index.js";
|
|
6
|
+
import { AIError, AuthenticationError, HttpContext, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError } from "../schema/index.js";
|
|
7
7
|
/** Array values become repeated parameters (`keyterm=a&keyterm=b`). */
|
|
8
8
|
export type Query = Readonly<Record<string, string | ReadonlyArray<string>>>;
|
|
9
9
|
/** `query` is appended to the endpoint URL before the route and caller `http.query` overlays. */
|
|
@@ -128,6 +128,14 @@ export interface Streamed<Request, Event, Frame, State> {
|
|
|
128
128
|
readonly finish: (state: State, context: ResponseContext<Request>) => Effect.Effect<ReadonlyArray<Event>, AIError>;
|
|
129
129
|
}
|
|
130
130
|
export declare const stream: <Request, Event, Frame, State>(route: Identity, input: Omit<Streamed<Request, Event, Frame, State>, "kind" | "id" | "provider">) => Streamed<Request, Event, Frame, State>;
|
|
131
|
+
/** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
|
|
132
|
+
declare const FAILURES: {
|
|
133
|
+
InvalidRequest: typeof InvalidRequestError;
|
|
134
|
+
Authentication: typeof AuthenticationError;
|
|
135
|
+
RateLimit: typeof RateLimitError;
|
|
136
|
+
ProviderInternal: typeof ProviderInternalError;
|
|
137
|
+
};
|
|
138
|
+
export type Failure = keyof typeof FAILURES;
|
|
131
139
|
/** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
|
|
132
140
|
export declare const identity: (input: {
|
|
133
141
|
readonly id: string;
|
|
@@ -141,7 +149,7 @@ export declare const identity: (input: {
|
|
|
141
149
|
body: string;
|
|
142
150
|
http: HttpContext;
|
|
143
151
|
invalid: (message: string, cause?: unknown) => AIError;
|
|
144
|
-
ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string) => AIError;
|
|
152
|
+
ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string, failure?: Failure) => AIError;
|
|
145
153
|
pending: (id: string) => AIError;
|
|
146
154
|
contentPolicy: (message: string) => AIError;
|
|
147
155
|
}, AIError, never>;
|
|
@@ -150,7 +158,7 @@ export declare const identity: (input: {
|
|
|
150
158
|
body: string;
|
|
151
159
|
http: HttpContext;
|
|
152
160
|
invalid: (message: string, cause?: unknown) => AIError;
|
|
153
|
-
ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string) => AIError;
|
|
161
|
+
ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string, failure?: Failure) => AIError;
|
|
154
162
|
pending: (id: string) => AIError;
|
|
155
163
|
contentPolicy: (message: string) => AIError;
|
|
156
164
|
}, AIError, never>;
|
|
@@ -167,6 +175,8 @@ export type Identity = ReturnType<typeof identity>;
|
|
|
167
175
|
export type Output = Effect.Success<ReturnType<Identity["text"]>>;
|
|
168
176
|
/** Map a provider status string through the protocol's table; unknown values are an invalid provider document. */
|
|
169
177
|
export declare const status: <Table extends Record<string, Status>>(table: Table, raw: string, output: Output) => Effect.Effect<Status, AIError>;
|
|
178
|
+
/** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
|
|
179
|
+
export declare const failure: (table: Readonly<Record<string, Failure>>, code: string | number | undefined) => Failure;
|
|
170
180
|
/** A `url` asset whose provider-declared retention window starts now. */
|
|
171
181
|
export declare const expiringUrl: (url: string, retention: Duration.Duration, options?: Parameters<typeof Media.url>[1]) => Effect.Effect<Media.Asset, never, never>;
|
|
172
182
|
export * as MediaProtocol from "./media-protocol.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Clock, Duration, Effect, Schema } from "effect";
|
|
2
2
|
import { HttpClientResponse } from "effect/unstable/http";
|
|
3
3
|
import { Media } from "../media.js";
|
|
4
|
-
import { AIError, ContentPolicyError, HttpContext, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, UnsupportedOperationError, } from "../schema/index.js";
|
|
4
|
+
import { AIError, AuthenticationError, ContentPolicyError, HttpContext, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError, UnsupportedOperationError, } from "../schema/index.js";
|
|
5
5
|
export const json = (value, query) => ({
|
|
6
6
|
type: "json",
|
|
7
7
|
value,
|
|
@@ -20,6 +20,13 @@ export const stream = (route, input) => ({ kind: "stream", id: route.id, provide
|
|
|
20
20
|
// ---------------------------------------------------------------------------
|
|
21
21
|
// Response helpers
|
|
22
22
|
// ---------------------------------------------------------------------------
|
|
23
|
+
/** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
|
|
24
|
+
const FAILURES = {
|
|
25
|
+
InvalidRequest: InvalidRequestError,
|
|
26
|
+
Authentication: AuthenticationError,
|
|
27
|
+
RateLimit: RateLimitError,
|
|
28
|
+
ProviderInternal: ProviderInternalError,
|
|
29
|
+
};
|
|
23
30
|
const context = (response) => new HttpContext({ url: response.request.url, status: response.status, headers: response.headers });
|
|
24
31
|
/** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
|
|
25
32
|
export const identity = (input) => {
|
|
@@ -27,9 +34,10 @@ export const identity = (input) => {
|
|
|
27
34
|
const frameError = (message, body, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, cause }) });
|
|
28
35
|
/**
|
|
29
36
|
* Read a text body while retaining the original payload and HTTP context on every downstream error. `invalid` is a
|
|
30
|
-
* malformed provider document; `ended` is a generation that reached a terminal status without output (`failed`
|
|
31
|
-
* provider
|
|
32
|
-
* generation finished, which is caller misuse;
|
|
37
|
+
* malformed provider document; `ended` is a generation that reached a terminal status without output (`failed`
|
|
38
|
+
* carries the provider's classification, defaulting to `ProviderInternal`; `cancelled`/`expired` mean the result
|
|
39
|
+
* will never exist); `pending` is a `result()` read before the generation finished, which is caller misuse;
|
|
40
|
+
* `contentPolicy` is a moderated result.
|
|
33
41
|
*/
|
|
34
42
|
const text = Effect.fn("MediaProtocol.text")(function* (response) {
|
|
35
43
|
const http = context(response);
|
|
@@ -45,9 +53,9 @@ export const identity = (input) => {
|
|
|
45
53
|
body,
|
|
46
54
|
http,
|
|
47
55
|
invalid: (message, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, http, cause }) }),
|
|
48
|
-
ended: (status, message) => new AIError({
|
|
56
|
+
ended: (status, message, failure = "ProviderInternal") => new AIError({
|
|
49
57
|
reason: status === "failed"
|
|
50
|
-
? new
|
|
58
|
+
? new FAILURES[failure]({ message, body, http })
|
|
51
59
|
: new InvalidRequestError({ message, body, http }),
|
|
52
60
|
}),
|
|
53
61
|
pending: (id) => new AIError({
|
|
@@ -103,6 +111,8 @@ export const status = (table, raw, output) => {
|
|
|
103
111
|
return Effect.fail(output.invalid(`Unknown generation status "${raw}"`));
|
|
104
112
|
return Effect.succeed(table[raw]);
|
|
105
113
|
};
|
|
114
|
+
/** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
|
|
115
|
+
export const failure = (table, code) => code !== undefined && Object.hasOwn(table, code) ? table[code] : "ProviderInternal";
|
|
106
116
|
/** A `url` asset whose provider-declared retention window starts now. */
|
|
107
117
|
export const expiringUrl = (url, retention, options) => Clock.currentTimeMillis.pipe(Effect.map((now) => Media.url(url, { ...options, expiresAt: now + Duration.toMillis(retention) })));
|
|
108
118
|
export * as MediaProtocol from "./media-protocol.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20213",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
36
36
|
"@effect/platform-node": "4.0.0-rc.112",
|
|
37
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
37
|
+
"@opencode/http-recorder": "0.0.0-dev-20213",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.0",
|
|
40
40
|
"@typescript/native-preview": "7.0.0-dev.20251207.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
45
45
|
"@smithy/eventstream-codec": "4.2.14",
|
|
46
46
|
"@smithy/util-utf8": "4.2.2",
|
|
47
|
-
"@opencode/schema": "0.0.0-dev-
|
|
47
|
+
"@opencode/schema": "0.0.0-dev-20213",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.0-rc.112",
|
|
50
50
|
"google-auth-library": "10.5.0"
|