@opencode/ai 0.0.0-dev-21489 → 0.0.0-dev-21491
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.
|
@@ -260,58 +260,8 @@ export declare const protocol: Protocol<{
|
|
|
260
260
|
readonly [x: string]: unknown;
|
|
261
261
|
} | undefined;
|
|
262
262
|
}, {
|
|
263
|
-
readonly
|
|
264
|
-
|
|
265
|
-
} | undefined;
|
|
266
|
-
readonly contentBlockStart?: {
|
|
267
|
-
readonly contentBlockIndex: number;
|
|
268
|
-
readonly start?: {
|
|
269
|
-
readonly toolUse?: {
|
|
270
|
-
readonly toolUseId: string;
|
|
271
|
-
readonly name: string;
|
|
272
|
-
} | undefined;
|
|
273
|
-
} | undefined;
|
|
274
|
-
} | undefined;
|
|
275
|
-
readonly contentBlockDelta?: {
|
|
276
|
-
readonly contentBlockIndex: number;
|
|
277
|
-
readonly delta?: {
|
|
278
|
-
readonly text?: string | undefined;
|
|
279
|
-
readonly toolUse?: {
|
|
280
|
-
readonly input: string;
|
|
281
|
-
} | undefined;
|
|
282
|
-
readonly reasoningContent?: {
|
|
283
|
-
readonly text?: string | undefined;
|
|
284
|
-
readonly signature?: string | undefined;
|
|
285
|
-
readonly redactedContent?: string | undefined;
|
|
286
|
-
readonly data?: string | undefined;
|
|
287
|
-
} | undefined;
|
|
288
|
-
} | undefined;
|
|
289
|
-
} | undefined;
|
|
290
|
-
readonly contentBlockStop?: {
|
|
291
|
-
readonly contentBlockIndex: number;
|
|
292
|
-
} | undefined;
|
|
293
|
-
readonly messageStop?: {
|
|
294
|
-
readonly stopReason: string;
|
|
295
|
-
readonly additionalModelResponseFields?: unknown;
|
|
296
|
-
} | undefined;
|
|
297
|
-
readonly metadata?: {
|
|
298
|
-
readonly usage?: {
|
|
299
|
-
readonly inputTokens?: number | undefined;
|
|
300
|
-
readonly outputTokens?: number | undefined;
|
|
301
|
-
readonly totalTokens?: number | undefined;
|
|
302
|
-
readonly cacheReadInputTokens?: number | undefined;
|
|
303
|
-
readonly cacheWriteInputTokens?: number | undefined;
|
|
304
|
-
} | undefined;
|
|
305
|
-
readonly metrics?: unknown;
|
|
306
|
-
} | undefined;
|
|
307
|
-
readonly exception?: {
|
|
308
|
-
readonly type: string;
|
|
309
|
-
readonly details: {
|
|
310
|
-
readonly message?: string | undefined;
|
|
311
|
-
readonly originalMessage?: string | undefined;
|
|
312
|
-
readonly originalStatusCode?: number | undefined;
|
|
313
|
-
};
|
|
314
|
-
} | undefined;
|
|
263
|
+
readonly [x: string]: unknown;
|
|
264
|
+
readonly rawBody: string;
|
|
315
265
|
}, {
|
|
316
266
|
readonly messageStart?: {
|
|
317
267
|
readonly role: string;
|
|
@@ -497,6 +447,9 @@ export declare const route: Route<{
|
|
|
497
447
|
readonly additionalModelRequestFields?: {
|
|
498
448
|
readonly [x: string]: unknown;
|
|
499
449
|
} | undefined;
|
|
500
|
-
}, import("../route/transport/http.js").HttpPrepared<
|
|
450
|
+
}, import("../route/transport/http.js").HttpPrepared<{
|
|
451
|
+
readonly [x: string]: unknown;
|
|
452
|
+
readonly rawBody: string;
|
|
453
|
+
}>, import("../route/client.js").CompactionOperations | undefined>;
|
|
501
454
|
export declare const sigV4Auth: typeof BedrockAuth.sigV4;
|
|
502
455
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
@@ -691,7 +691,7 @@ export const protocol = Protocol.make({
|
|
|
691
691
|
from: fromRequest,
|
|
692
692
|
},
|
|
693
693
|
stream: {
|
|
694
|
-
event: BedrockEvent,
|
|
694
|
+
event: BedrockEventStream.Frame.pipe(Schema.decodeTo(BedrockEvent)),
|
|
695
695
|
initial: (request) => ({
|
|
696
696
|
providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
|
|
697
697
|
tools: ToolStream.empty(),
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
import { Framing } from "../route/framing.js";
|
|
3
|
+
export declare const Frame: Schema.StructWithRest<Schema.Struct<{
|
|
4
|
+
readonly rawBody: Schema.String;
|
|
5
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
6
|
+
export type Frame = typeof Frame.Type;
|
|
2
7
|
/**
|
|
3
8
|
* AWS event-stream framing for Bedrock Converse. Each frame is decoded by
|
|
4
9
|
* `@smithy/eventstream-codec` (length + header + payload + CRC) and rewrapped
|
|
5
10
|
* under its `:event-type` header so the chunk schema can match the JSON
|
|
6
11
|
* payload directly.
|
|
7
12
|
*/
|
|
8
|
-
export declare const framing: (route: string) => Framing.Definition<
|
|
13
|
+
export declare const framing: (route: string) => Framing.Definition<Frame>;
|
|
9
14
|
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
2
2
|
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
|
|
3
|
-
import { Effect, Stream } from "effect";
|
|
3
|
+
import { Effect, Schema, Stream } from "effect";
|
|
4
4
|
import { Base64 } from "effect/encoding";
|
|
5
5
|
import { AIError, AIErrorReason, InvalidProviderOutputError } from "../schema/index.js";
|
|
6
6
|
import { Framing } from "../route/framing.js";
|
|
@@ -12,6 +12,7 @@ import { ProviderShared } from "./shared.js";
|
|
|
12
12
|
const eventCodec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
13
13
|
const utf8 = new TextDecoder();
|
|
14
14
|
const initialFrameBuffer = { buffer: new Uint8Array(0), offset: 0 };
|
|
15
|
+
export const Frame = Schema.StructWithRest(Schema.Struct({ rawBody: Schema.String }), [ProviderShared.JsonObject]);
|
|
15
16
|
const endOfStream = { _tag: "End" };
|
|
16
17
|
const appendChunk = (state, chunk) => {
|
|
17
18
|
const remaining = state.buffer.length - state.offset;
|
|
@@ -71,14 +72,14 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
|
71
72
|
// before handing the object to the chunk schema. JSON decode goes
|
|
72
73
|
// through the shared Schema-driven codec to satisfy the package rule
|
|
73
74
|
// against ad-hoc `JSON.parse` calls.
|
|
74
|
-
const parsed =
|
|
75
|
+
const parsed = yield* ProviderShared.parseJson(route, payload, "Failed to parse Bedrock Converse event-stream payload").pipe(Effect.mapError((error) => new AIError({
|
|
75
76
|
reason: AIErrorReason.make({ ...error.reason, message: error.message, cause: error.reason.cause, body }),
|
|
76
|
-
})))
|
|
77
|
-
|
|
77
|
+
})));
|
|
78
|
+
if (!ProviderShared.isRecord(parsed))
|
|
79
|
+
return yield* ProviderShared.eventError(route, "Failed to parse Bedrock Converse event-stream payload", body);
|
|
80
|
+
const { p: _, ...event } = parsed;
|
|
78
81
|
out.push({
|
|
79
|
-
...(messageType === "exception"
|
|
80
|
-
? { exception: { type: eventType, details: parsed } }
|
|
81
|
-
: { [eventType]: parsed }),
|
|
82
|
+
...(messageType === "exception" ? { exception: { type: eventType, details: event } } : { [eventType]: event }),
|
|
82
83
|
rawBody: body,
|
|
83
84
|
});
|
|
84
85
|
}
|
|
@@ -92,7 +93,7 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
|
92
93
|
*/
|
|
93
94
|
export const framing = (route) => ({
|
|
94
95
|
id: "aws-event-stream",
|
|
95
|
-
body: (frame) =>
|
|
96
|
+
body: (frame) => frame.rawBody,
|
|
96
97
|
frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
|
|
97
98
|
});
|
|
98
99
|
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -151,7 +151,10 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
151
151
|
readonly additionalModelRequestFields?: {
|
|
152
152
|
readonly [x: string]: unknown;
|
|
153
153
|
} | undefined;
|
|
154
|
-
}, import("../route/transport/http.js").HttpPrepared<
|
|
154
|
+
}, import("../route/transport/http.js").HttpPrepared<{
|
|
155
|
+
readonly [x: string]: unknown;
|
|
156
|
+
readonly rawBody: string;
|
|
157
|
+
}>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
155
158
|
export declare const configure: (input?: Config) => {
|
|
156
159
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
157
160
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
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-21491",
|
|
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-21491",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.0",
|
|
40
40
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
@@ -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-21491",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.1",
|
|
50
50
|
"google-auth-library": "10.5.0"
|