@opencode/ai 0.0.0-dev-21586 → 0.0.0-dev-21590
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.
|
@@ -1057,8 +1057,8 @@ export declare const lowerGeneration: (request: LLMRequest, options?: OpenRespon
|
|
|
1057
1057
|
parallel_tool_calls?: boolean | undefined;
|
|
1058
1058
|
truncation?: "auto" | "disabled" | undefined;
|
|
1059
1059
|
};
|
|
1060
|
-
export declare const resolveParallelToolCalls: (request: LLMRequest) => boolean | undefined;
|
|
1061
|
-
export declare const allowedToolChoice: (request: LLMRequest) => {
|
|
1060
|
+
export declare const resolveParallelToolCalls: (request: LLMRequest, options?: OpenResponsesOptions.Resolved) => boolean | undefined;
|
|
1061
|
+
export declare const allowedToolChoice: (request: LLMRequest, options?: OpenResponsesOptions.Resolved) => {
|
|
1062
1062
|
type: "allowed_tools";
|
|
1063
1063
|
mode: "auto" | "none" | "required";
|
|
1064
1064
|
tools: {
|
|
@@ -566,7 +566,7 @@ export const lowerConversation = Effect.fnUntraced(function* (request, adapter)
|
|
|
566
566
|
export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
567
567
|
const generation = request.generation;
|
|
568
568
|
const cacheKey = ProviderShared.promptCacheKey(request);
|
|
569
|
-
const parallelToolCalls = resolveParallelToolCalls(request);
|
|
569
|
+
const parallelToolCalls = resolveParallelToolCalls(request, options);
|
|
570
570
|
return {
|
|
571
571
|
stream: true,
|
|
572
572
|
max_output_tokens: generation?.maxTokens,
|
|
@@ -593,15 +593,15 @@ export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(
|
|
|
593
593
|
...(options.truncation ? { truncation: options.truncation } : {}),
|
|
594
594
|
};
|
|
595
595
|
};
|
|
596
|
-
export const resolveParallelToolCalls = (request) => {
|
|
597
|
-
const configured =
|
|
596
|
+
export const resolveParallelToolCalls = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
597
|
+
const configured = options.parallelToolCalls;
|
|
598
598
|
if (configured !== undefined)
|
|
599
599
|
return configured;
|
|
600
600
|
const disabled = request.toolChoice?.disableParallelToolUse;
|
|
601
601
|
return disabled === undefined ? undefined : !disabled;
|
|
602
602
|
};
|
|
603
|
-
export const allowedToolChoice = (request) => {
|
|
604
|
-
const allowed =
|
|
603
|
+
export const allowedToolChoice = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
604
|
+
const allowed = options.allowedTools;
|
|
605
605
|
if (!allowed)
|
|
606
606
|
return undefined;
|
|
607
607
|
return {
|
|
@@ -612,11 +612,12 @@ export const allowedToolChoice = (request) => {
|
|
|
612
612
|
};
|
|
613
613
|
export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAdapter")(function* (request, adapter) {
|
|
614
614
|
const projected = ProviderShared.flattenToolRequest(request);
|
|
615
|
+
const options = OpenResponsesOptions.resolve(request);
|
|
615
616
|
return {
|
|
616
617
|
...(yield* lowerConversation(projected.request, adapter)),
|
|
617
|
-
...lowerGeneration(request),
|
|
618
|
+
...lowerGeneration(request, options),
|
|
618
619
|
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter),
|
|
619
|
-
tool_choice: allowedToolChoice(request) ??
|
|
620
|
+
tool_choice: allowedToolChoice(request, options) ??
|
|
620
621
|
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
|
|
621
622
|
};
|
|
622
623
|
});
|
|
@@ -170,7 +170,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
170
170
|
tools: request.tools.length === 0 ? undefined : yield* lowerTools(request),
|
|
171
171
|
tool_choice: request.tools.length === 0
|
|
172
172
|
? undefined
|
|
173
|
-
: (OpenResponses.allowedToolChoice(request) ??
|
|
173
|
+
: (OpenResponses.allowedToolChoice(request, options) ??
|
|
174
174
|
(request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools) : undefined)),
|
|
175
175
|
};
|
|
176
176
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema, Stream } from "effect";
|
|
1
|
+
import { Effect, Schema, SchemaGetter, Stream } from "effect";
|
|
2
2
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
3
3
|
import { Framing } from "../route/framing.js";
|
|
4
4
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
@@ -39,8 +39,14 @@ const transcriptFields = {
|
|
|
39
39
|
words: Schema.optional(Schema.Array(Schema.Struct({ word: Schema.String, start: Schema.Number, end: Schema.Number }))),
|
|
40
40
|
usage: Schema.optional(Usage),
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const EVENT_TYPES = new Set(["transcript.text.delta", "transcript.text.segment", "transcript.text.done", "error"]);
|
|
43
|
+
/** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
|
|
44
|
+
const UnknownEvent = Schema.Struct({
|
|
45
|
+
type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
|
|
46
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
47
|
+
decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
|
|
48
|
+
encode: SchemaGetter.forbidden(() => "Unknown OpenAI Transcription stream events are decode-only"),
|
|
49
|
+
}));
|
|
44
50
|
const Event = Schema.Union([
|
|
45
51
|
Schema.Struct({ type: Schema.Literal("transcript.text.delta"), delta: Schema.String }),
|
|
46
52
|
Schema.Struct({ type: Schema.Literal("transcript.text.segment"), ...Segment.fields }),
|
|
@@ -50,10 +56,9 @@ const Event = Schema.Union([
|
|
|
50
56
|
message: Schema.optional(Schema.String),
|
|
51
57
|
error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
|
|
52
58
|
}),
|
|
59
|
+
UnknownEvent,
|
|
53
60
|
]);
|
|
54
|
-
const EVENT_TYPES = new Set(["transcript.text.delta", "transcript.text.segment", "transcript.text.done", "error"]);
|
|
55
61
|
const Transcript = Schema.Struct(transcriptFields);
|
|
56
|
-
const decodeEventType = route.decodeFrame(EventType);
|
|
57
62
|
const decodeEvent = route.decodeFrame(Event);
|
|
58
63
|
const decodeTranscript = route.decodeFrame(Transcript);
|
|
59
64
|
const TRANSCRIBE = { stream: true, timestamps: [], diarize: false, languageField: "language" };
|
|
@@ -132,9 +137,9 @@ const segment = (value) => ({
|
|
|
132
137
|
speaker: value.speaker,
|
|
133
138
|
});
|
|
134
139
|
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
135
|
-
if (!EVENT_TYPES.has((yield* decodeEventType(frame)).type))
|
|
136
|
-
return [state, []];
|
|
137
140
|
const event = yield* decodeEvent(frame);
|
|
141
|
+
if (event.type === "unknown")
|
|
142
|
+
return [state, []];
|
|
138
143
|
if (event.type === "error")
|
|
139
144
|
return yield* new AIError({
|
|
140
145
|
reason: classifyProviderFailure({
|
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-21590",
|
|
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-21590",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.3",
|
|
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-21590",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.1",
|
|
50
50
|
"google-auth-library": "10.5.0"
|