@opencode/ai 0.0.0-dev-21483 → 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.
- package/dist/generation.js +1 -1
- package/dist/protocols/bedrock-converse.d.ts +6 -53
- package/dist/protocols/bedrock-converse.js +2 -1
- package/dist/protocols/bedrock-event-stream.d.ts +6 -1
- package/dist/protocols/bedrock-event-stream.js +9 -8
- package/dist/providers/amazon-bedrock.d.ts +4 -1
- package/dist/schema/errors.d.ts +1 -1
- package/dist/schema/errors.js +1 -1
- package/dist/schema/messages.js +4 -7
- package/package.json +3 -3
package/dist/generation.js
CHANGED
|
@@ -110,6 +110,6 @@ const within = (effect, id, timeout, deadline) => Clock.currentTimeMillis.pipe(E
|
|
|
110
110
|
const timeoutError = (id, timeout) => new AIError({
|
|
111
111
|
reason: new TimeoutError({
|
|
112
112
|
message: `Generation ${id} did not finish within ${Duration.format(timeout)}`,
|
|
113
|
-
timeoutMs: Duration.toMillis(timeout),
|
|
113
|
+
timeoutMs: Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.ceil(Duration.toMillis(timeout)))),
|
|
114
114
|
}),
|
|
115
115
|
});
|
|
@@ -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";
|
|
@@ -647,6 +647,7 @@ const step = (state, event) => Effect.gen(function* () {
|
|
|
647
647
|
return yield* new AIError({
|
|
648
648
|
reason: classifyProviderFailure({
|
|
649
649
|
message,
|
|
650
|
+
status: event.exception.details.originalStatusCode,
|
|
650
651
|
rawBody: body,
|
|
651
652
|
}),
|
|
652
653
|
});
|
|
@@ -690,7 +691,7 @@ export const protocol = Protocol.make({
|
|
|
690
691
|
from: fromRequest,
|
|
691
692
|
},
|
|
692
693
|
stream: {
|
|
693
|
-
event: BedrockEvent,
|
|
694
|
+
event: BedrockEventStream.Frame.pipe(Schema.decodeTo(BedrockEvent)),
|
|
694
695
|
initial: (request) => ({
|
|
695
696
|
providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
|
|
696
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/dist/schema/errors.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ declare const TimeoutError_base: Schema.Class<TimeoutError, Schema.TaggedStruct<
|
|
|
153
153
|
readonly body: Schema.optional<Schema.String>;
|
|
154
154
|
readonly http: Schema.optional<typeof HttpContext>;
|
|
155
155
|
readonly cause: Schema.optional<Schema.Defect>;
|
|
156
|
-
readonly timeoutMs: Schema.optional<Schema.
|
|
156
|
+
readonly timeoutMs: Schema.optional<Schema.Int>;
|
|
157
157
|
}>, import("effect/Cause").YieldableError>;
|
|
158
158
|
/** A caller-supplied deadline elapsed, such as `Generation.await` polling past its `Poll.timeout`. */
|
|
159
159
|
export declare class TimeoutError extends TimeoutError_base {
|
package/dist/schema/errors.js
CHANGED
|
@@ -104,7 +104,7 @@ export class UnknownProviderError extends Schema.TaggedError("AI.Error.UnknownPr
|
|
|
104
104
|
/** A caller-supplied deadline elapsed, such as `Generation.await` polling past its `Poll.timeout`. */
|
|
105
105
|
export class TimeoutError extends Schema.TaggedError("AI.Error.Timeout")("Timeout", {
|
|
106
106
|
...ReasonFields,
|
|
107
|
-
timeoutMs: Schema.optional(
|
|
107
|
+
timeoutMs: Schema.optional(NonNegativeInt),
|
|
108
108
|
}) {
|
|
109
109
|
}
|
|
110
110
|
export const AIErrorReason = Schema.Union([
|
package/dist/schema/messages.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
2
|
import { withStatics } from "@opencode/schema/schema";
|
|
3
3
|
import { Tool } from "@opencode/schema/tool";
|
|
4
4
|
import { CacheHint, CachePolicy, GenerationOptions, HttpOptions, JsonSchema, LanguageModelSchema, ProviderMetadata, ProviderOptions, ReasoningEffort, } from "./options.js";
|
|
5
5
|
import { ProviderID } from "./ids.js";
|
|
6
6
|
import { Media } from "../media.js";
|
|
7
|
+
import { Json } from "../utils/json.js";
|
|
7
8
|
export const MessageRole = Schema.Literals(["system", "user", "assistant", "tool"]);
|
|
8
9
|
const systemPartSchema = Schema.Struct({
|
|
9
10
|
type: Schema.Literal("text"),
|
|
@@ -89,15 +90,11 @@ export const ToolOutput = withStatics(Schema.Struct({
|
|
|
89
90
|
return { type: "content", value: output.content };
|
|
90
91
|
},
|
|
91
92
|
});
|
|
93
|
+
const encodeJsonOption = Schema.encodeUnknownOption(Json);
|
|
92
94
|
const toolResultText = (value) => {
|
|
93
95
|
if (typeof value === "string")
|
|
94
96
|
return value;
|
|
95
|
-
|
|
96
|
-
return JSON.stringify(value) ?? String(value);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return String(value);
|
|
100
|
-
}
|
|
97
|
+
return Option.getOrElse(encodeJsonOption(value), () => String(value));
|
|
101
98
|
};
|
|
102
99
|
export const ToolCallPart = withStatics(Schema.Struct({
|
|
103
100
|
type: Schema.Literal("tool-call"),
|
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"
|