@opencode/ai 0.0.0-dev-20140 → 0.0.0-dev-20142
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/image-client.d.ts +54 -21
- package/dist/image-client.js +14 -39
- package/dist/image.d.ts +13 -25
- package/dist/image.js +2 -13
- package/dist/media-client.d.ts +30 -0
- package/dist/media-client.js +51 -0
- package/dist/media-model.d.ts +9 -8
- package/dist/media-model.js +10 -10
- package/dist/promise.d.ts +26 -10
- package/dist/promise.js +15 -20
- package/dist/protocols/cartesia-speech.d.ts +16 -0
- package/dist/protocols/deepgram-speech.d.ts +16 -0
- package/dist/protocols/elevenlabs-speech.d.ts +16 -0
- package/dist/protocols/google-speech.d.ts +16 -0
- package/dist/protocols/open-responses.d.ts +3 -0
- package/dist/protocols/open-responses.js +2 -5
- package/dist/protocols/openai-responses.js +13 -18
- package/dist/protocols/openai-speech.d.ts +16 -0
- package/dist/protocols/utils/responses-checkpoint.js +3 -7
- package/dist/protocols/utils/responses-compaction.d.ts +3 -1
- package/dist/protocols/utils/responses-compaction.js +16 -3
- package/dist/protocols/xai-responses.js +1 -1
- package/dist/providers/openai-options.d.ts +3 -9
- package/dist/providers/openai-options.js +4 -7
- package/dist/providers/openai.js +1 -1
- package/dist/route/media.d.ts +4 -14
- package/dist/route/media.js +1 -36
- package/dist/speech-client.d.ts +57 -14
- package/dist/speech-client.js +15 -20
- package/dist/speech.d.ts +176 -19
- package/dist/speech.js +11 -6
- package/dist/transcription-client.d.ts +73 -21
- package/dist/transcription-client.js +7 -39
- package/dist/transcription.d.ts +13 -25
- package/dist/transcription.js +2 -8
- package/dist/video-client.d.ts +50 -21
- package/dist/video-client.js +14 -35
- package/dist/video.d.ts +14 -22
- package/dist/video.js +13 -14
- package/package.json +3 -3
|
@@ -16,6 +16,14 @@ export type DeepgramSpeechOptions = {
|
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
17
|
export type Request = SpeechRequestFor<DeepgramSpeechOptions>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly type: "generation-queued";
|
|
21
|
+
readonly position?: number | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly type: "generation-progress";
|
|
25
|
+
readonly progress?: number | undefined;
|
|
26
|
+
} | {
|
|
19
27
|
readonly type: "audio-delta";
|
|
20
28
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
21
29
|
} | {
|
|
@@ -67,6 +75,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
67
75
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
|
|
68
76
|
export declare const DeepgramSpeech: {
|
|
69
77
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly type: "generation-queued";
|
|
80
|
+
readonly position?: number | undefined;
|
|
81
|
+
} | {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly type: "generation-progress";
|
|
84
|
+
readonly progress?: number | undefined;
|
|
85
|
+
} | {
|
|
70
86
|
readonly type: "audio-delta";
|
|
71
87
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
72
88
|
} | {
|
|
@@ -19,6 +19,14 @@ export type ElevenLabsSpeechOptions = {
|
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
20
|
export type Request = SpeechRequestFor<ElevenLabsSpeechOptions>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly type: "generation-queued";
|
|
24
|
+
readonly position?: number | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly type: "generation-progress";
|
|
28
|
+
readonly progress?: number | undefined;
|
|
29
|
+
} | {
|
|
22
30
|
readonly type: "audio-delta";
|
|
23
31
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
24
32
|
} | {
|
|
@@ -70,6 +78,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
70
78
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
|
|
71
79
|
export declare const ElevenLabsSpeech: {
|
|
72
80
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly type: "generation-queued";
|
|
83
|
+
readonly position?: number | undefined;
|
|
84
|
+
} | {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly type: "generation-progress";
|
|
87
|
+
readonly progress?: number | undefined;
|
|
88
|
+
} | {
|
|
73
89
|
readonly type: "audio-delta";
|
|
74
90
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
75
91
|
} | {
|
|
@@ -26,6 +26,14 @@ interface State extends SpeechStream.Audio, GeminiGenerateContent.Metadata {
|
|
|
26
26
|
readonly mimeType?: string;
|
|
27
27
|
}
|
|
28
28
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly type: "generation-queued";
|
|
31
|
+
readonly position?: number | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly type: "generation-progress";
|
|
35
|
+
readonly progress?: number | undefined;
|
|
36
|
+
} | {
|
|
29
37
|
readonly type: "audio-delta";
|
|
30
38
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
31
39
|
} | {
|
|
@@ -77,6 +85,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
77
85
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<GoogleSpeechOptions>;
|
|
78
86
|
export declare const GoogleSpeech: {
|
|
79
87
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
88
|
+
readonly id: string;
|
|
89
|
+
readonly type: "generation-queued";
|
|
90
|
+
readonly position?: number | undefined;
|
|
91
|
+
} | {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly type: "generation-progress";
|
|
94
|
+
readonly progress?: number | undefined;
|
|
95
|
+
} | {
|
|
80
96
|
readonly type: "audio-delta";
|
|
81
97
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
82
98
|
} | {
|
|
@@ -725,6 +725,9 @@ export declare const lowerTool: (protocolName: string, tool: ToolDefinition) =>
|
|
|
725
725
|
};
|
|
726
726
|
strict: boolean;
|
|
727
727
|
}, AIError, never>;
|
|
728
|
+
export declare const lowerTools: (tools: ReadonlyArray<ToolDefinition>, adapter: ProviderAdapter) => Effect.Effect<{
|
|
729
|
+
readonly type: string;
|
|
730
|
+
}[], AIError, never>;
|
|
728
731
|
export declare const lowerToolChoice: (protocolName: string, toolChoice: NonNullable<LLMRequest["toolChoice"]>) => Effect.Effect<"required" | "auto" | "none" | {
|
|
729
732
|
type: "function";
|
|
730
733
|
name: string;
|
|
@@ -292,6 +292,7 @@ export const lowerTool = Effect.fn("OpenResponses.lowerTool")(function* (protoco
|
|
|
292
292
|
strict: false,
|
|
293
293
|
};
|
|
294
294
|
});
|
|
295
|
+
export const lowerTools = (tools, adapter) => Effect.forEach(tools, (tool) => tool.native !== undefined && adapter.nativeTool ? adapter.nativeTool(tool.native) : lowerTool(adapter.name, tool));
|
|
295
296
|
export const lowerToolChoice = (protocolName, toolChoice) => ProviderShared.matchToolChoice(protocolName, toolChoice, {
|
|
296
297
|
auto: () => "auto",
|
|
297
298
|
none: () => "none",
|
|
@@ -605,11 +606,7 @@ export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAd
|
|
|
605
606
|
return {
|
|
606
607
|
...(yield* lowerConversation(projected.request, adapter)),
|
|
607
608
|
...lowerGeneration(request),
|
|
608
|
-
tools: projected.tools.length === 0
|
|
609
|
-
? undefined
|
|
610
|
-
: yield* Effect.forEach(projected.tools, (tool) => tool.native !== undefined && adapter.nativeTool
|
|
611
|
-
? adapter.nativeTool(tool.native)
|
|
612
|
-
: lowerTool(adapter.name, tool)),
|
|
609
|
+
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter),
|
|
613
610
|
tool_choice: allowedToolChoice(request) ??
|
|
614
611
|
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
|
|
615
612
|
};
|
|
@@ -5,7 +5,7 @@ import { Auth } from "../route/auth.js";
|
|
|
5
5
|
import { Endpoint } from "../route/endpoint.js";
|
|
6
6
|
import { Protocol } from "../route/protocol.js";
|
|
7
7
|
import { HttpTransport } from "../route/transport/index.js";
|
|
8
|
-
import { LLMRequest
|
|
8
|
+
import { LLMRequest } from "../schema/index.js";
|
|
9
9
|
import { resolveEffortUpdates } from "../effort-updates.js";
|
|
10
10
|
import { OpenResponses } from "./open-responses.js";
|
|
11
11
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
@@ -105,9 +105,6 @@ export const CompactionTrigger = Schema.Struct({ type: Schema.Literal("compactio
|
|
|
105
105
|
const CheckpointBody = Schema.Struct({
|
|
106
106
|
...OpenAIResponsesBody.fields,
|
|
107
107
|
input: Schema.Array(Schema.Union([OpenAIResponsesInputItem, CompactionTrigger])),
|
|
108
|
-
store: Schema.Literal(false),
|
|
109
|
-
prompt_cache_retention: optionalNull(Schema.String),
|
|
110
|
-
prompt_cache_options: optionalNull(Schema.Struct({ mode: Schema.optional(Schema.String), ttl: Schema.optional(Schema.String) })),
|
|
111
108
|
});
|
|
112
109
|
const adapter = {
|
|
113
110
|
id: ADAPTER,
|
|
@@ -154,6 +151,7 @@ const lowerToolEntry = Effect.fn("OpenAIResponses.lowerToolEntry")(function* (to
|
|
|
154
151
|
tools: yield* Effect.forEach(ProviderShared.flattenTools(tool.tools), (leaf) => OpenResponses.lowerTool(NAME, leaf)),
|
|
155
152
|
};
|
|
156
153
|
});
|
|
154
|
+
const lowerTools = (request) => Effect.forEach(request.tools, lowerToolEntry);
|
|
157
155
|
const lowerToolChoice = (toolChoice, tools) => ProviderShared.matchToolChoice(NAME, toolChoice, {
|
|
158
156
|
auto: () => "auto",
|
|
159
157
|
none: () => "none",
|
|
@@ -171,7 +169,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
171
169
|
...(yield* OpenResponses.lowerConversation(updates.request, adapter)),
|
|
172
170
|
...OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort }),
|
|
173
171
|
context_management: management?.map((edit) => ({ type: edit.type, compact_threshold: edit.compactThreshold })),
|
|
174
|
-
tools: request.tools.length === 0 ? undefined : yield*
|
|
172
|
+
tools: request.tools.length === 0 ? undefined : yield* lowerTools(request),
|
|
175
173
|
tool_choice: request.tools.length === 0
|
|
176
174
|
? undefined
|
|
177
175
|
: (OpenResponses.allowedToolChoice(request) ??
|
|
@@ -181,25 +179,19 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
181
179
|
const checkpointBody = {
|
|
182
180
|
schema: CheckpointBody,
|
|
183
181
|
from: Effect.fn("OpenAIResponses.checkpointBody")(function* (request) {
|
|
184
|
-
const native = yield* fromRequest(LLMRequest.update(request, { toolChoice: undefined }));
|
|
185
182
|
const overlay = request.http?.body;
|
|
186
183
|
// Complete history is required for stateless replay and SSE recovery. Raw input overrides bypass that contract.
|
|
187
184
|
if (overlay?.input !== undefined ||
|
|
188
185
|
overlay?.previous_response_id !== undefined ||
|
|
189
186
|
overlay?.conversation !== undefined)
|
|
190
187
|
return yield* ProviderShared.invalidRequest("Trigger compaction requires complete canonical history, not an input or continuation override");
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
if (overlay?.stream !== undefined && overlay.stream !== true)
|
|
189
|
+
return yield* ProviderShared.invalidRequest("Trigger compaction requires a streamed response");
|
|
190
|
+
const native = yield* fromRequest(request);
|
|
191
|
+
return {
|
|
192
|
+
...native,
|
|
193
193
|
input: [...native.input, { type: "compaction_trigger" }],
|
|
194
|
-
|
|
195
|
-
store: false,
|
|
196
|
-
parallel_tool_calls: true,
|
|
197
|
-
tool_choice: undefined,
|
|
198
|
-
context_management: undefined,
|
|
199
|
-
text: undefined,
|
|
200
|
-
max_output_tokens: undefined,
|
|
201
|
-
max_tool_calls: undefined,
|
|
202
|
-
});
|
|
194
|
+
};
|
|
203
195
|
}),
|
|
204
196
|
};
|
|
205
197
|
const hostedToolResult = Effect.fn("OpenAIResponses.hostedToolResult")(function* (item) {
|
|
@@ -270,7 +262,10 @@ export const transport = channelTransport({
|
|
|
270
262
|
headers: (headers) => Headers.set(headers, "openai-beta", headers["openai-beta"] ?? WEBSOCKET_PROTOCOL_HEADER),
|
|
271
263
|
});
|
|
272
264
|
export const route = Route.make({
|
|
273
|
-
compact: {
|
|
265
|
+
compact: {
|
|
266
|
+
endpoint: ResponsesCompaction.make(adapter, lowerTools),
|
|
267
|
+
trigger: ResponsesCheckpoint.make(checkpointBody),
|
|
268
|
+
},
|
|
274
269
|
id: ADAPTER,
|
|
275
270
|
provider: "openai",
|
|
276
271
|
providerMetadataKey: "openai",
|
|
@@ -16,6 +16,14 @@ interface State extends SpeechStream.Audio {
|
|
|
16
16
|
readonly usage?: MediaUsage;
|
|
17
17
|
}
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly type: "generation-queued";
|
|
21
|
+
readonly position?: number | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly type: "generation-progress";
|
|
25
|
+
readonly progress?: number | undefined;
|
|
26
|
+
} | {
|
|
19
27
|
readonly type: "audio-delta";
|
|
20
28
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
21
29
|
} | {
|
|
@@ -67,6 +75,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
67
75
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<OpenAISpeechOptions>;
|
|
68
76
|
export declare const OpenAISpeech: {
|
|
69
77
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly type: "generation-queued";
|
|
80
|
+
readonly position?: number | undefined;
|
|
81
|
+
} | {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly type: "generation-progress";
|
|
84
|
+
readonly progress?: number | undefined;
|
|
85
|
+
} | {
|
|
70
86
|
readonly type: "audio-delta";
|
|
71
87
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
72
88
|
} | {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { Route } from "../../route/client.js";
|
|
3
3
|
import { Protocol } from "../../route/protocol.js";
|
|
4
|
-
import { CompactionCheckpointResponse,
|
|
4
|
+
import { CompactionCheckpointResponse, LLMEvent, LLMRequest } from "../../schema/index.js";
|
|
5
5
|
import { OpenResponses } from "../open-responses.js";
|
|
6
6
|
import { ProviderShared } from "../shared.js";
|
|
7
7
|
const onOutputItem = Effect.fn("ResponsesCheckpoint.onOutputItem")(function* (state, input) {
|
|
@@ -94,12 +94,8 @@ export const make = (body) => Effect.fn("ResponsesCheckpoint.execute")(function*
|
|
|
94
94
|
transport: source.transport,
|
|
95
95
|
});
|
|
96
96
|
const native = yield* body.from(request);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
http: request.http === undefined ? undefined : new HttpOptions({ ...request.http, body: undefined }),
|
|
100
|
-
});
|
|
101
|
-
const prepared = yield* route.prepareTransport(native, preparedRequest, options);
|
|
102
|
-
yield* route.streamPrepared(prepared, preparedRequest, { http: executor }, options).pipe(Stream.runDrain);
|
|
97
|
+
const prepared = yield* route.prepareTransport(native, request, options);
|
|
98
|
+
yield* route.streamPrepared(prepared, request, { http: executor }, options).pipe(Stream.runDrain);
|
|
103
99
|
if (!result)
|
|
104
100
|
return yield* ProviderShared.eventError(source.id, "Compaction response ended without a checkpoint");
|
|
105
101
|
return result;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { AIError, LLMRequest } from "../../schema/index.js";
|
|
1
3
|
import type { CompactOperation } from "../../route/client.js";
|
|
2
4
|
import { OpenResponses } from "../open-responses.js";
|
|
3
|
-
export declare const make: (adapter: OpenResponses.ProviderAdapter) => CompactOperation;
|
|
5
|
+
export declare const make: (adapter: OpenResponses.ProviderAdapter, lowerTools: (request: LLMRequest) => Effect.Effect<ReadonlyArray<Record<string, unknown>>, AIError>) => CompactOperation;
|
|
4
6
|
export * as ResponsesCompaction from "./responses-compaction.js";
|
|
@@ -7,12 +7,18 @@ import { HttpTransport } from "../../route/transport/index.js";
|
|
|
7
7
|
import { OpenResponses } from "../open-responses.js";
|
|
8
8
|
import { JsonObject, optionalNull, ProviderShared } from "../shared.js";
|
|
9
9
|
import { Media } from "../../media.js";
|
|
10
|
+
// /compact has a smaller wire contract than /responses; keep the request controls it accepts.
|
|
10
11
|
const Body = Schema.Struct({
|
|
11
12
|
model: Schema.String,
|
|
12
13
|
input: Schema.Array(Schema.Unknown),
|
|
13
14
|
instructions: optionalNull(Schema.String),
|
|
14
15
|
previous_response_id: optionalNull(Schema.String),
|
|
15
16
|
service_tier: optionalNull(Schema.String),
|
|
17
|
+
reasoning: Schema.optional(JsonObject),
|
|
18
|
+
text: Schema.optional(JsonObject),
|
|
19
|
+
include: OpenResponses.coreFields.include,
|
|
20
|
+
parallel_tool_calls: OpenResponses.coreFields.parallel_tool_calls,
|
|
21
|
+
tools: Schema.optional(Schema.Array(JsonObject)),
|
|
16
22
|
prompt_cache_key: optionalNull(Schema.String),
|
|
17
23
|
prompt_cache_retention: optionalNull(Schema.String),
|
|
18
24
|
prompt_cache_options: optionalNull(Schema.Struct({ mode: Schema.optional(Schema.String), ttl: Schema.optional(Schema.String) })),
|
|
@@ -54,14 +60,21 @@ const Response = Schema.Struct({
|
|
|
54
60
|
])),
|
|
55
61
|
usage: Schema.optional(Schema.StructWithRest(OpenResponses.OpenResponsesUsage, [JsonObject])),
|
|
56
62
|
});
|
|
57
|
-
export const make = (adapter) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
63
|
+
export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
58
64
|
const route = request.model.route;
|
|
59
65
|
// The standalone compaction endpoint rejects histories containing configuration updates.
|
|
60
66
|
const native = yield* OpenResponses.lowerConversation(stripEffortUpdates(request), adapter);
|
|
67
|
+
const generation = OpenResponses.lowerGeneration(request);
|
|
68
|
+
const tools = request.tools.length === 0 ? undefined : yield* lowerTools(request);
|
|
61
69
|
const body = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
62
70
|
...native,
|
|
63
|
-
service_tier:
|
|
64
|
-
|
|
71
|
+
service_tier: generation.service_tier,
|
|
72
|
+
reasoning: generation.reasoning,
|
|
73
|
+
text: generation.text,
|
|
74
|
+
include: generation.include,
|
|
75
|
+
parallel_tool_calls: generation.parallel_tool_calls,
|
|
76
|
+
tools,
|
|
77
|
+
prompt_cache_key: generation.prompt_cache_key,
|
|
65
78
|
}, request.http?.body));
|
|
66
79
|
const url = Endpoint.render(route.endpoint, { request, body: native });
|
|
67
80
|
url.pathname = `${url.pathname.replace(/\/$/, "")}/compact`;
|
|
@@ -77,5 +77,5 @@ export const protocol = Protocol.make({
|
|
|
77
77
|
terminal: OpenResponses.terminal,
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
|
-
export const compact = ResponsesCompaction.make(adapter);
|
|
80
|
+
export const compact = ResponsesCompaction.make(adapter, (request) => OpenResponses.lowerTools(ProviderShared.flattenTools(request.tools), adapter));
|
|
81
81
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -10,17 +10,11 @@ export type OpenAIOptionsInput = Omit<Options, "serviceTier"> & {
|
|
|
10
10
|
readonly [key: string]: unknown;
|
|
11
11
|
};
|
|
12
12
|
export type OpenAIProviderOptionsInput = OpenAIOptionsInput;
|
|
13
|
-
export declare const gpt5DefaultOptions: (modelID: string
|
|
14
|
-
|
|
15
|
-
}) => ProviderOptions | undefined;
|
|
16
|
-
export declare const openAIDefaultOptions: (modelID: string, options?: {
|
|
17
|
-
readonly textVerbosity?: boolean;
|
|
18
|
-
}) => ProviderOptions | undefined;
|
|
13
|
+
export declare const gpt5DefaultOptions: (modelID: string) => ProviderOptions | undefined;
|
|
14
|
+
export declare const openAIDefaultOptions: (modelID: string) => ProviderOptions | undefined;
|
|
19
15
|
export declare const withOpenAIOptions: <Options extends {
|
|
20
16
|
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
21
|
-
}>(modelID: string, options: Options,
|
|
22
|
-
readonly textVerbosity?: boolean;
|
|
23
|
-
}) => Omit<Options, "providerOptions"> & {
|
|
17
|
+
}>(modelID: string, options: Options) => Omit<Options, "providerOptions"> & {
|
|
24
18
|
readonly providerOptions?: ProviderOptions;
|
|
25
19
|
};
|
|
26
20
|
export * as OpenAIProviderOptions from "./openai-options.js";
|
|
@@ -13,7 +13,7 @@ const openAIProviderOptions = (options) => {
|
|
|
13
13
|
return undefined;
|
|
14
14
|
return result;
|
|
15
15
|
};
|
|
16
|
-
export const gpt5DefaultOptions = (modelID
|
|
16
|
+
export const gpt5DefaultOptions = (modelID) => {
|
|
17
17
|
const id = modelID.toLowerCase();
|
|
18
18
|
if (!id.includes("gpt-5") || id.includes("gpt-5-chat") || id.includes("gpt-5-pro"))
|
|
19
19
|
return undefined;
|
|
@@ -26,16 +26,13 @@ export const gpt5DefaultOptions = (modelID, options = {}) => {
|
|
|
26
26
|
// this, callers using the default model facade get reasoning summaries
|
|
27
27
|
// they cannot replay statelessly.
|
|
28
28
|
include: ["reasoning.encrypted_content"],
|
|
29
|
-
textVerbosity: options.textVerbosity === true && id.includes("gpt-5.") && !id.includes("codex") && !id.includes("-chat")
|
|
30
|
-
? "low"
|
|
31
|
-
: undefined,
|
|
32
29
|
});
|
|
33
30
|
};
|
|
34
|
-
export const openAIDefaultOptions = (modelID
|
|
35
|
-
export const withOpenAIOptions = (modelID, options
|
|
31
|
+
export const openAIDefaultOptions = (modelID) => mergeProviderOptions(openAIProviderOptions({ store: false }), gpt5DefaultOptions(modelID));
|
|
32
|
+
export const withOpenAIOptions = (modelID, options) => {
|
|
36
33
|
return {
|
|
37
34
|
...options,
|
|
38
|
-
providerOptions: mergeProviderOptions(openAIDefaultOptions(modelID
|
|
35
|
+
providerOptions: mergeProviderOptions(openAIDefaultOptions(modelID), options.providerOptions),
|
|
39
36
|
};
|
|
40
37
|
};
|
|
41
38
|
export * as OpenAIProviderOptions from "./openai-options.js";
|
package/dist/providers/openai.js
CHANGED
|
@@ -41,7 +41,7 @@ export const configure = (input = {}) => {
|
|
|
41
41
|
const chatRoute = configuredRoute(OpenAIChat.route, input);
|
|
42
42
|
const modelDefaults = defaults(input);
|
|
43
43
|
const responses = (id) => responsesRoute
|
|
44
|
-
.with(withOpenAIOptions(id, modelDefaults
|
|
44
|
+
.with(withOpenAIOptions(id, modelDefaults))
|
|
45
45
|
.model({ id });
|
|
46
46
|
const chat = (id) => chatRoute.with(withOpenAIOptions(id, modelDefaults)).model({
|
|
47
47
|
id,
|
package/dist/route/media.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Auth } from "./auth.js";
|
|
|
3
3
|
import { Endpoint } from "./endpoint.js";
|
|
4
4
|
import { type Interface } from "./executor-service.js";
|
|
5
5
|
import { MediaProtocol } from "./media-protocol.js";
|
|
6
|
-
import { Generation
|
|
6
|
+
import { Generation } from "../generation.js";
|
|
7
7
|
import { AIError, HttpOptions, ProviderID } from "../schema/index.js";
|
|
8
8
|
export type Execute = Interface["execute"];
|
|
9
9
|
/** The minimum a media request must carry for the route to build a transport request. */
|
|
@@ -30,7 +30,7 @@ export declare const deployment: (input: {
|
|
|
30
30
|
readonly http?: HttpOptions.Input;
|
|
31
31
|
}, auth: Auth.Definition) => Omit<ModelInput, "id">;
|
|
32
32
|
/** One request, one response. */
|
|
33
|
-
export interface
|
|
33
|
+
export interface InlineRoute<Request extends MediaRequest, Response> {
|
|
34
34
|
readonly kind: "inline";
|
|
35
35
|
readonly id: string;
|
|
36
36
|
readonly provider: ProviderID;
|
|
@@ -56,7 +56,7 @@ export interface StreamRoute<Request extends MediaRequest, Event, Response> {
|
|
|
56
56
|
readonly stream: (request: Request, execute: Execute) => Stream.Stream<Event, AIError>;
|
|
57
57
|
readonly generate: (request: Request, execute: Execute) => Effect.Effect<Response, AIError>;
|
|
58
58
|
}
|
|
59
|
-
export type AnyRoute<Request extends MediaRequest, Event, Response> =
|
|
59
|
+
export type AnyRoute<Request extends MediaRequest, Event, Response> = InlineRoute<Request, Response> | StreamRoute<Request, Event, Response> | QueuedRoute<Request, Response>;
|
|
60
60
|
export interface Composition<Request extends MediaRequest> {
|
|
61
61
|
readonly endpoint: Endpoint.Definition<MediaProtocol.Body, Request>;
|
|
62
62
|
readonly auth: Auth.Definition;
|
|
@@ -79,7 +79,7 @@ export interface StreamInput<Request extends MediaRequest, Event, Response, Fram
|
|
|
79
79
|
* rejection, URL and query rendering, auth headers, JSON, multipart, or binary encoding, and handing responses back
|
|
80
80
|
* to the protocol.
|
|
81
81
|
*/
|
|
82
|
-
export declare const inline: <Request extends MediaRequest, Response>(input: InlineInput<Request, Response>) =>
|
|
82
|
+
export declare const inline: <Request extends MediaRequest, Response>(input: InlineInput<Request, Response>) => InlineRoute<Request, Response>;
|
|
83
83
|
/**
|
|
84
84
|
* Compose a queued media protocol the same way, adding `start`/`resume` handles whose polls reuse the route's auth,
|
|
85
85
|
* deployment headers, and (for `start`) the request's `http` overlay. The token is decoded once at the boundary and
|
|
@@ -88,14 +88,4 @@ export declare const inline: <Request extends MediaRequest, Response>(input: Inl
|
|
|
88
88
|
export declare const queued: <Request extends MediaRequest, Response, Token>(input: QueuedInput<Request, Response, Token>) => QueuedRoute<Request, Response>;
|
|
89
89
|
/** Compose a streaming media protocol; `generate` runs the same stream in `generate` mode and folds it with `collect`. */
|
|
90
90
|
export declare const stream: <Request extends MediaRequest, Event, Response, Frame, State>(input: StreamInput<Request, Event, Response, Frame, State>) => StreamRoute<Request, Event, Response>;
|
|
91
|
-
export declare const dispatch: <Event, Response>(input: {
|
|
92
|
-
readonly modality: string;
|
|
93
|
-
readonly execute: Execute;
|
|
94
|
-
readonly responseEvents: (response: Response) => ReadonlyArray<Event>;
|
|
95
|
-
}) => {
|
|
96
|
-
start: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request) => Effect.Effect<Generation<Response>, AIError, never>;
|
|
97
|
-
resume: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, model: MediaRequest["model"], token: unknown) => Effect.Effect<Generation<Response>, AIError, never>;
|
|
98
|
-
generate: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request, options?: AwaitOptions) => Effect.Effect<Response, AIError, never>;
|
|
99
|
-
stream: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request, options?: AwaitOptions) => Stream.Stream<Event | Observation, AIError>;
|
|
100
|
-
};
|
|
101
91
|
export * as MediaRoute from "./media.js";
|
package/dist/route/media.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Endpoint } from "./endpoint.js";
|
|
|
5
5
|
import { RequestExecutorService } from "./executor-service.js";
|
|
6
6
|
import { RequestExecutor } from "./executor.js";
|
|
7
7
|
import { MediaProtocol } from "./media-protocol.js";
|
|
8
|
-
import { Generation
|
|
8
|
+
import { Generation } from "../generation.js";
|
|
9
9
|
import { AIError, AIErrorReason, HttpOptions, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeHttpOptions, } from "../schema/index.js";
|
|
10
10
|
import { encodeJson } from "../utils/json.js";
|
|
11
11
|
import { sanitizeSurrogates } from "../utils/sanitize.js";
|
|
@@ -112,41 +112,6 @@ export const stream = (input) => {
|
|
|
112
112
|
generate: (request, execute) => events(request, execute, "generate").pipe(Stream.runCollect, Effect.flatMap(input.collect)),
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
|
-
export const dispatch = (input) => {
|
|
116
|
-
const notQueued = (route, operation) => new AIError({
|
|
117
|
-
reason: new UnsupportedOperationError({
|
|
118
|
-
operation: `${input.modality}.${operation}`,
|
|
119
|
-
provider: route.provider,
|
|
120
|
-
route: route.id,
|
|
121
|
-
message: `${route.provider}/${route.id} is not a queued route; use generate or stream`,
|
|
122
|
-
}),
|
|
123
|
-
});
|
|
124
|
-
const start = (route, request) => {
|
|
125
|
-
if (route.kind !== "queued")
|
|
126
|
-
return Effect.fail(notQueued(route, "start"));
|
|
127
|
-
return route.start(request, input.execute);
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
start,
|
|
131
|
-
resume: (route, model, token) => {
|
|
132
|
-
if (route.kind !== "queued")
|
|
133
|
-
return Effect.fail(notQueued(route, "resume"));
|
|
134
|
-
return route.resume(model, token, input.execute);
|
|
135
|
-
},
|
|
136
|
-
generate: (route, request, options) => {
|
|
137
|
-
if (route.kind !== "queued")
|
|
138
|
-
return route.generate(request, input.execute);
|
|
139
|
-
return start(route, request).pipe(Effect.flatMap((generation) => generation.await(options)));
|
|
140
|
-
},
|
|
141
|
-
stream: (route, request, options) => {
|
|
142
|
-
if (route.kind === "stream")
|
|
143
|
-
return route.stream(request, input.execute);
|
|
144
|
-
if (route.kind === "queued")
|
|
145
|
-
return Stream.unwrap(start(route, request).pipe(Effect.map((generation) => resultEvents(generation, input.responseEvents, options))));
|
|
146
|
-
return Stream.fromIterableEffect(Effect.map(route.generate(request, input.execute), input.responseEvents));
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
115
|
// ---------------------------------------------------------------------------
|
|
151
116
|
// Transport plumbing shared by every kind
|
|
152
117
|
// ---------------------------------------------------------------------------
|
package/dist/speech-client.d.ts
CHANGED
|
@@ -1,23 +1,66 @@
|
|
|
1
|
-
import { Context
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export interface Interface {
|
|
6
|
-
readonly generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError>;
|
|
7
|
-
readonly stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError>;
|
|
8
|
-
}
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
import { MediaClient } from "./media-client.js";
|
|
3
|
+
import { type SpeechEvent, type SpeechRequestFor, type SpeechResponse } from "./speech.js";
|
|
4
|
+
export type Interface = MediaClient.Interface<SpeechRequestFor, SpeechEvent, SpeechResponse>;
|
|
9
5
|
declare const SpeechClientService_base: Context.ServiceClass<SpeechClientService, "@opencode/SpeechClient", Interface>;
|
|
10
6
|
export declare class SpeechClientService extends SpeechClientService_base {
|
|
11
7
|
}
|
|
12
8
|
export declare const Service: typeof SpeechClientService;
|
|
13
9
|
export type Service = SpeechClientService;
|
|
14
|
-
export declare const generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError, Service>;
|
|
15
|
-
export declare const stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError, Service>;
|
|
16
|
-
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
17
10
|
export declare const SpeechClient: {
|
|
11
|
+
readonly layer: import("effect/Layer").Layer<SpeechClientService, never, import("./route/executor-service.js").RequestExecutorService>;
|
|
12
|
+
readonly generate: (request: SpeechRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<SpeechResponse, import("./index.js").AIError, SpeechClientService>;
|
|
13
|
+
readonly stream: (request: SpeechRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<import("./generation.js").Observation | {
|
|
14
|
+
readonly type: "audio-delta";
|
|
15
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "timestamps";
|
|
18
|
+
readonly items: readonly {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly startSeconds: number;
|
|
21
|
+
readonly endSeconds: number;
|
|
22
|
+
}[];
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "finish";
|
|
25
|
+
readonly audio: import("./media.js").Asset;
|
|
26
|
+
readonly providerMetadata?: {
|
|
27
|
+
readonly [x: string]: {
|
|
28
|
+
readonly [x: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
} | undefined;
|
|
31
|
+
readonly usage?: {
|
|
32
|
+
readonly type: "tokens";
|
|
33
|
+
readonly input?: number | undefined;
|
|
34
|
+
readonly output?: number | undefined;
|
|
35
|
+
readonly total?: number | undefined;
|
|
36
|
+
readonly details?: {
|
|
37
|
+
readonly [x: string]: unknown;
|
|
38
|
+
} | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "seconds";
|
|
41
|
+
readonly seconds: number;
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "characters";
|
|
44
|
+
readonly characters: number;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "credits";
|
|
47
|
+
readonly credits: number;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "compute";
|
|
50
|
+
readonly seconds: number;
|
|
51
|
+
} | undefined;
|
|
52
|
+
readonly notices?: readonly {
|
|
53
|
+
readonly type: "other" | "moderated" | "filtered";
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly providerMetadata?: {
|
|
56
|
+
readonly [x: string]: {
|
|
57
|
+
readonly [x: string]: unknown;
|
|
58
|
+
};
|
|
59
|
+
} | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
}, import("./index.js").AIError, SpeechClientService>;
|
|
62
|
+
readonly start: (request: SpeechRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
|
|
63
|
+
readonly resume: (model: import("./speech.js").SpeechModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
|
|
18
64
|
readonly Service: typeof SpeechClientService;
|
|
19
|
-
readonly layer: Layer.Layer<SpeechClientService, never, import("./route/executor-service.js").RequestExecutorService>;
|
|
20
|
-
readonly generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError, Service>;
|
|
21
|
-
readonly stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError, Service>;
|
|
22
65
|
};
|
|
23
66
|
export {};
|
package/dist/speech-client.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { Context
|
|
2
|
-
import {
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
import { MediaClient } from "./media-client.js";
|
|
3
|
+
import { SpeechTimestampsEvent, SpeechFinishEvent, } from "./speech.js";
|
|
3
4
|
export class SpeechClientService extends Context.Service()("@opencode/SpeechClient") {
|
|
4
5
|
}
|
|
5
6
|
export const Service = SpeechClientService;
|
|
6
|
-
export const generate = (request) => Effect.gen(function* () {
|
|
7
|
-
const client = yield* Service;
|
|
8
|
-
return yield* client.generate(request);
|
|
9
|
-
});
|
|
10
|
-
export const stream = (request) => Stream.unwrap(Effect.gen(function* () {
|
|
11
|
-
const client = yield* Service;
|
|
12
|
-
return client.stream(request);
|
|
13
|
-
}));
|
|
14
|
-
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
15
|
-
const executor = yield* RequestExecutor.Service;
|
|
16
|
-
return Service.of({
|
|
17
|
-
generate: (request) => request.model.route.generate(request, executor.execute),
|
|
18
|
-
stream: (request) => request.model.route.stream(request, executor.execute),
|
|
19
|
-
});
|
|
20
|
-
}));
|
|
21
7
|
export const SpeechClient = {
|
|
22
8
|
Service,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
...MediaClient.make(Service, {
|
|
10
|
+
modality: "speech",
|
|
11
|
+
responseEvents: (response) => [
|
|
12
|
+
...(response.timestamps === undefined ? [] : [SpeechTimestampsEvent.make({ items: response.timestamps })]),
|
|
13
|
+
SpeechFinishEvent.make({
|
|
14
|
+
audio: response.audio,
|
|
15
|
+
usage: response.usage,
|
|
16
|
+
notices: response.notices,
|
|
17
|
+
providerMetadata: response.providerMetadata,
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
26
21
|
};
|