@opencode/ai 0.0.0-dev-20858 → 0.0.0-dev-20859
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/dist/media.d.ts +1 -1
- package/dist/protocols/open-responses-channel.js +6 -1
- package/dist/protocols/shared.d.ts +4 -1
- package/dist/protocols/shared.js +24 -1
- package/dist/protocols/utils/responses-compaction.js +6 -1
- package/dist/route/transport/http.js +1 -0
- package/dist/schema/options.d.ts +5 -0
- package/dist/schema/options.js +13 -2
- package/package.json +3 -3
package/dist/media.d.ts
CHANGED
|
@@ -100,12 +100,12 @@ export declare class Asset {
|
|
|
100
100
|
};
|
|
101
101
|
info: {
|
|
102
102
|
readonly format?: string | undefined;
|
|
103
|
+
readonly encoding?: string | undefined;
|
|
103
104
|
readonly width?: number | undefined;
|
|
104
105
|
readonly height?: number | undefined;
|
|
105
106
|
readonly durationSeconds?: number | undefined;
|
|
106
107
|
readonly sampleRate?: number | undefined;
|
|
107
108
|
readonly channels?: number | undefined;
|
|
108
|
-
readonly encoding?: string | undefined;
|
|
109
109
|
} | undefined;
|
|
110
110
|
providerMetadata: {
|
|
111
111
|
readonly [x: string]: {
|
|
@@ -106,7 +106,12 @@ export const transport = (options) => {
|
|
|
106
106
|
});
|
|
107
107
|
return {
|
|
108
108
|
http: {
|
|
109
|
-
request: ProviderShared.jsonPost({
|
|
109
|
+
request: ProviderShared.jsonPost({
|
|
110
|
+
url: parts.url,
|
|
111
|
+
body: parts.bodyText,
|
|
112
|
+
headers: parts.headers,
|
|
113
|
+
encoding: input.request.http?.encoding,
|
|
114
|
+
}),
|
|
110
115
|
framing: Framing.sse,
|
|
111
116
|
middleware: input.middleware,
|
|
112
117
|
},
|
|
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
|
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
|
-
import { AIError, LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type ToolEntry, type ToolResultPart } from "../schema/index.js";
|
|
5
|
+
import { AIError, LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
|
|
6
6
|
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
7
|
import { isRecord } from "../utils/record.js";
|
|
8
8
|
export { Json, decodeJson, encodeJson, isRecord };
|
|
@@ -193,10 +193,13 @@ export declare const validateWith: <A, I, E extends {
|
|
|
193
193
|
* send JSON with a stale content type. The body is passed pre-encoded so
|
|
194
194
|
* routes can choose between
|
|
195
195
|
* `Schema.encodeSync(payload)` and `ProviderShared.encodeJson(payload)`.
|
|
196
|
+
* A `zstd` or `gzip` encoding compresses the body and sets `content-encoding`;
|
|
197
|
+
* it falls back to plain JSON when the runtime has no zlib.
|
|
196
198
|
*/
|
|
197
199
|
export declare const jsonPost: (input: {
|
|
198
200
|
readonly url: string;
|
|
199
201
|
readonly body: string;
|
|
200
202
|
readonly headers?: Headers.Input;
|
|
203
|
+
readonly encoding?: RequestEncoding;
|
|
201
204
|
}) => HttpClientRequest.HttpClientRequest;
|
|
202
205
|
export * as ProviderShared from "./shared.js";
|
package/dist/protocols/shared.js
CHANGED
|
@@ -282,6 +282,29 @@ export const validateWith = (decode) => (payload) => decode(payload).pipe(Effect
|
|
|
282
282
|
* send JSON with a stale content type. The body is passed pre-encoded so
|
|
283
283
|
* routes can choose between
|
|
284
284
|
* `Schema.encodeSync(payload)` and `ProviderShared.encodeJson(payload)`.
|
|
285
|
+
* A `zstd` or `gzip` encoding compresses the body and sets `content-encoding`;
|
|
286
|
+
* it falls back to plain JSON when the runtime has no zlib.
|
|
285
287
|
*/
|
|
286
|
-
export const jsonPost = (input) =>
|
|
288
|
+
export const jsonPost = (input) => {
|
|
289
|
+
const headers = Headers.set(Headers.fromInput(input.headers), "content-type", "application/json");
|
|
290
|
+
const compressed = compressBody(input.body, input.encoding);
|
|
291
|
+
if (!compressed)
|
|
292
|
+
return HttpClientRequest.post(input.url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(input.body, "application/json"));
|
|
293
|
+
return HttpClientRequest.post(input.url).pipe(HttpClientRequest.setHeaders(Headers.set(headers, "content-encoding", compressed.encoding)), HttpClientRequest.bodyUint8Array(compressed.body, "application/json"));
|
|
294
|
+
};
|
|
295
|
+
function compressBody(text, encoding) {
|
|
296
|
+
if (encoding === undefined || encoding === "none")
|
|
297
|
+
return undefined;
|
|
298
|
+
// Looked up at call time instead of imported: a runtime without node:zlib or its zstd export
|
|
299
|
+
// (browsers, older Node, some workerd setups) sends plain JSON rather than failing to load this module.
|
|
300
|
+
const zlib = globalThis.process?.getBuiltinModule?.("node:zlib");
|
|
301
|
+
try {
|
|
302
|
+
const body = encoding === "zstd" ? zlib?.zstdCompressSync?.(text) : zlib?.gzipSync(text);
|
|
303
|
+
return body && { encoding, body };
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// Compression is an optimization, so a failure sends plain JSON instead of failing the request.
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
287
310
|
export * as ProviderShared from "./shared.js";
|
|
@@ -87,7 +87,12 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
87
87
|
auth: route.auth,
|
|
88
88
|
encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)),
|
|
89
89
|
});
|
|
90
|
-
const response = yield* executor.execute(ProviderShared.jsonPost({
|
|
90
|
+
const response = yield* executor.execute(ProviderShared.jsonPost({
|
|
91
|
+
url: parts.url,
|
|
92
|
+
body: parts.bodyText,
|
|
93
|
+
headers: parts.headers,
|
|
94
|
+
encoding: request.http?.encoding,
|
|
95
|
+
}), options?.http);
|
|
91
96
|
const text = yield* RequestExecutor.responseStream(response).pipe(Stream.decodeText(), Stream.runFold(() => "", (text, chunk) => text + chunk));
|
|
92
97
|
const invalid = (message, cause) => new AIError({
|
|
93
98
|
reason: new InvalidProviderOutputError({
|
package/dist/schema/options.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export declare const HttpTimeout: Schema.Union<readonly [Schema.Number, Schema.L
|
|
|
14
14
|
export type HttpTimeout = Schema.Schema.Type<typeof HttpTimeout>;
|
|
15
15
|
/** Applied to `headerTimeout` and `chunkTimeout` when a request leaves them unset. */
|
|
16
16
|
export declare const DEFAULT_HTTP_TIMEOUT_MS = 300000;
|
|
17
|
+
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
18
|
+
export declare const RequestEncoding: Schema.Literals<readonly ["zstd", "gzip", "none"]>;
|
|
19
|
+
export type RequestEncoding = Schema.Schema.Type<typeof RequestEncoding>;
|
|
17
20
|
declare const HttpOptions_base: Schema.Class<HttpOptions, Schema.Struct<{
|
|
18
21
|
readonly body: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
19
22
|
readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
@@ -24,6 +27,8 @@ declare const HttpOptions_base: Schema.Class<HttpOptions, Schema.Struct<{
|
|
|
24
27
|
readonly headerTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
25
28
|
/** Time allowed between streamed response chunks once headers have arrived. */
|
|
26
29
|
readonly chunkTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
30
|
+
/** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
|
|
31
|
+
readonly encoding: Schema.optional<Schema.Literals<readonly ["zstd", "gzip", "none"]>>;
|
|
27
32
|
}>, {}>;
|
|
28
33
|
export declare class HttpOptions extends HttpOptions_base {
|
|
29
34
|
}
|
package/dist/schema/options.js
CHANGED
|
@@ -36,6 +36,8 @@ export const mergeProviderOptions = (...items) => mergeJsonRecords(...items);
|
|
|
36
36
|
export const HttpTimeout = Schema.Union([Schema.Number.check(Schema.isGreaterThan(0)), Schema.Literal(false)]);
|
|
37
37
|
/** Applied to `headerTimeout` and `chunkTimeout` when a request leaves them unset. */
|
|
38
38
|
export const DEFAULT_HTTP_TIMEOUT_MS = 300_000;
|
|
39
|
+
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
40
|
+
export const RequestEncoding = Schema.Literals(["zstd", "gzip", "none"]);
|
|
39
41
|
export class HttpOptions extends Schema.Class("AI.HttpOptions")({
|
|
40
42
|
body: Schema.optional(JsonSchema),
|
|
41
43
|
headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
@@ -46,6 +48,8 @@ export class HttpOptions extends Schema.Class("AI.HttpOptions")({
|
|
|
46
48
|
headerTimeout: Schema.optional(HttpTimeout),
|
|
47
49
|
/** Time allowed between streamed response chunks once headers have arrived. */
|
|
48
50
|
chunkTimeout: Schema.optional(HttpTimeout),
|
|
51
|
+
/** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
|
|
52
|
+
encoding: Schema.optional(RequestEncoding),
|
|
49
53
|
}) {
|
|
50
54
|
}
|
|
51
55
|
(function (HttpOptions) {
|
|
@@ -63,9 +67,16 @@ export const mergeHttpOptions = (...items) => {
|
|
|
63
67
|
const timeout = items.findLast((item) => item?.timeout !== undefined)?.timeout;
|
|
64
68
|
const headerTimeout = items.findLast((item) => item?.headerTimeout !== undefined)?.headerTimeout;
|
|
65
69
|
const chunkTimeout = items.findLast((item) => item?.chunkTimeout !== undefined)?.chunkTimeout;
|
|
66
|
-
|
|
70
|
+
const encoding = items.findLast((item) => item?.encoding !== undefined)?.encoding;
|
|
71
|
+
if (!body &&
|
|
72
|
+
!headers &&
|
|
73
|
+
!query &&
|
|
74
|
+
timeout === undefined &&
|
|
75
|
+
headerTimeout === undefined &&
|
|
76
|
+
chunkTimeout === undefined &&
|
|
77
|
+
encoding === undefined)
|
|
67
78
|
return undefined;
|
|
68
|
-
return new HttpOptions({ body, headers, query, timeout, headerTimeout, chunkTimeout });
|
|
79
|
+
return new HttpOptions({ body, headers, query, timeout, headerTimeout, chunkTimeout, encoding });
|
|
69
80
|
};
|
|
70
81
|
export class GenerationOptions extends Schema.Class("LLM.GenerationOptions")({
|
|
71
82
|
maxTokens: Schema.optional(Schema.Number),
|
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-20859",
|
|
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.1",
|
|
37
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
37
|
+
"@opencode/http-recorder": "0.0.0-dev-20859",
|
|
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-20859",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.1",
|
|
50
50
|
"google-auth-library": "10.5.0"
|