@opencode-ai/ai
Advanced tools
| import { EventStreamCodec } from "@smithy/eventstream-codec"; | ||
| import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; | ||
| import { Effect, Encoding, Stream } from "effect"; | ||
| import { AIError, AIErrorReason } from "../schema/index.js"; | ||
| import { AIError, AIErrorReason, InvalidProviderOutputError } from "../schema/index.js"; | ||
| import { Framing } from "../route/framing.js"; | ||
@@ -14,2 +14,3 @@ import { ProviderShared } from "./shared.js"; | ||
| const initialFrameBuffer = { buffer: new Uint8Array(0), offset: 0 }; | ||
| const endOfStream = { _tag: "End" }; | ||
| const appendChunk = (state, chunk) => { | ||
@@ -25,4 +26,17 @@ const remaining = state.buffer.length - state.offset; | ||
| }; | ||
| const consumeFrames = (route) => (state, chunk) => Effect.gen(function* () { | ||
| let cursor = appendChunk(state, chunk); | ||
| const consumeFrames = (route) => (state, input) => Effect.gen(function* () { | ||
| if (input._tag === "End") { | ||
| const remaining = state.buffer.subarray(state.offset); | ||
| if (remaining.length > 0) | ||
| return yield* new AIError({ | ||
| reason: new InvalidProviderOutputError({ | ||
| route, | ||
| classification: "incomplete-stream", | ||
| message: `Incomplete Bedrock Converse event-stream frame: ${remaining.length} buffered bytes remain at end of stream`, | ||
| body: Encoding.encodeBase64(remaining), | ||
| }), | ||
| }); | ||
| return [state, []]; | ||
| } | ||
| let cursor = appendChunk(state, input.bytes); | ||
| const out = []; | ||
@@ -83,4 +97,4 @@ while (cursor.buffer.length - cursor.offset >= 4) { | ||
| body: (frame) => ("rawBody" in frame && typeof frame.rawBody === "string" ? frame.rawBody : undefined), | ||
| frame: (bytes) => bytes.pipe(Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))), | ||
| frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))), | ||
| }); | ||
| export * as BedrockEventStream from "./bedrock-event-stream.js"; |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-dev-18695", | ||
| "version": "0.0.0-dev-18696", | ||
| "name": "@opencode-ai/ai", | ||
@@ -33,3 +33,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-rc.112", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18695", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18696", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -43,3 +43,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-dev-18695", | ||
| "@opencode-ai/schema": "0.0.0-dev-18696", | ||
| "aws4fetch": "1.0.20", | ||
@@ -46,0 +46,0 @@ "effect": "4.0.0-rc.112", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1484086
0.05%34157
0.04%+ Added
- Removed