@opencode/ai 0.0.0-dev-627 → 0.0.0-dev-646
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/README.md +6 -6
- package/dist/llm.d.ts +2 -3
- package/dist/llm.js +2 -2
- package/dist/protocols/alibaba-chat.js +2 -2
- package/dist/protocols/anthropic-messages.js +5 -6
- package/dist/protocols/bedrock-converse.js +8 -9
- package/dist/protocols/cohere-chat.js +9 -9
- package/dist/protocols/gemini.js +9 -10
- package/dist/protocols/google-interactions.js +6 -8
- package/dist/protocols/mistral-chat.js +7 -7
- package/dist/protocols/open-responses.js +5 -6
- package/dist/protocols/openai-chat.js +8 -9
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-responses.js +1 -1
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/openrouter.js +1 -1
- package/dist/public.d.ts +2 -2
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +3 -9
- package/dist/route/client.js +3 -5
- package/dist/schema/messages.d.ts +2 -3
- package/dist/schema/options.d.ts +9 -33
- package/dist/schema/options.js +14 -38
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ const program = Effect.gen(function* () {
|
|
|
37
37
|
model: openai.responses("gpt-4o-mini"), // `.chat(...)` selects the Chat Completions API instead
|
|
38
38
|
system: "You are concise.",
|
|
39
39
|
prompt: "Say hello in one short sentence.",
|
|
40
|
-
|
|
40
|
+
maxTokens: 40,
|
|
41
41
|
})
|
|
42
42
|
console.log(response.text)
|
|
43
43
|
})
|
|
@@ -409,7 +409,7 @@ shared host; the entry above follows the base URL table. Dedicated hosts can be
|
|
|
409
409
|
Replay complete `response.message` values to retain `reasoning_content` separately from answer text.
|
|
410
410
|
Qwen 3.8 defaults to preserving thinking; older models have different defaults.
|
|
411
411
|
Additional options include `toolStream`, `parallelToolCalls`, `repetitionPenalty`, `responseFormat`,
|
|
412
|
-
`enableSearch`, and native `searchOptions`. `
|
|
412
|
+
`enableSearch`, and native `searchOptions`. `topK` lowers to `top_k`.
|
|
413
413
|
`clearThinking` is a hosted GLM control, and `thinking.type` is available for hosted MiniMax models.
|
|
414
414
|
- **Messages:** `effort` → `output_config.effort`. `thinking.type` accepts enabled/disabled with an
|
|
415
415
|
optional `budgetTokens` (or native `budget_tokens`). `outputConfig.format` accepts a JSON schema.
|
|
@@ -578,7 +578,7 @@ const request = ai.request({
|
|
|
578
578
|
model: minimax.model("MiniMax-M3"), // also minimax.messages("MiniMax-M3")
|
|
579
579
|
prompt: "What is 173 multiplied by 219?",
|
|
580
580
|
providerOptions: { thinking: { type: "adaptive" } },
|
|
581
|
-
|
|
581
|
+
maxTokens: 1536,
|
|
582
582
|
})
|
|
583
583
|
|
|
584
584
|
const response = await Effect.runPromise(ai.generate(request).pipe(Effect.provide(AIClient.layer)))
|
|
@@ -616,7 +616,7 @@ const request = ai.request({
|
|
|
616
616
|
model: meta.responses("muse-spark-1.3"), // meta.model(...) also selects Responses
|
|
617
617
|
prompt: "What is 173 multiplied by 219? Reply with the integer.",
|
|
618
618
|
providerOptions: { reasoningEffort: "low" },
|
|
619
|
-
|
|
619
|
+
maxTokens: 1024,
|
|
620
620
|
})
|
|
621
621
|
```
|
|
622
622
|
|
|
@@ -638,7 +638,7 @@ Responses and Chat support only `toolChoice: "auto"` (the default). Messages als
|
|
|
638
638
|
its documented forced `"any"` choice currently returns HTTP 400. Messages defaults to adaptive thinking
|
|
639
639
|
with `display: "omitted"`, preserving encrypted `redacted_thinking` in `response.message`. Use
|
|
640
640
|
`providerOptions: { effort: "low" }` for depth or `thinking: { type: "enabled", budgetTokens: 1024 }`
|
|
641
|
-
for budget compatibility (with `
|
|
641
|
+
for budget compatibility (with `maxTokens > 1024`).
|
|
642
642
|
|
|
643
643
|
Add `tools: [Meta.webSearch()]` to a Spark Responses or Messages request for hosted web search.
|
|
644
644
|
Responses exposes hosted results and URL citations in text-part `providerMetadata.meta.annotations`.
|
|
@@ -1620,7 +1620,7 @@ Additional provider entrypoints include:
|
|
|
1620
1620
|
|
|
1621
1621
|
Request options in order of stability:
|
|
1622
1622
|
|
|
1623
|
-
1.
|
|
1623
|
+
1. **Portable knobs** — `maxTokens`, `temperature`, `topP`, `topK`, `frequencyPenalty`, `presencePenalty`, `seed` and `stop`, at the top level of a text request. `GENERATION_KEYS` lists them.
|
|
1624
1624
|
2. **`promptCacheKey`** — stable cache affinity lowered by every protocol that supports it.
|
|
1625
1625
|
3. **`providerOptions: { ... }`** — flat options inferred from the selected model (OpenAI `store`, Anthropic `thinking`, Gemini `thinkingConfig`, OpenRouter routing).
|
|
1626
1626
|
4. **`http: { body, headers, query }`** — last-resort serializable overlays merged into the final HTTP request. Reach for this only when a stable typed path doesn't yet exist.
|
package/dist/llm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, JsonSchema, Schema, Stream } from "effect";
|
|
2
2
|
import { Service, canCompact, type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type StreamOptions, type TriggerCompactOptions } from "./route/client.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AIError, LLMEvent, LLMResponse, Message, LanguageModel, SystemPart, type BaseRequest, type CachePolicy, type CompactionCheckpointResponse, type CompactionResponse, type Finish, ToolChoice, type LanguageModelProviderOptions, type GenerationOptionsFields, type LLMRequest, type ToolEntryInput } from "./schema/index.js";
|
|
4
4
|
import { type ExecutableTool, type Tool, type ToolSchema } from "./tool.js";
|
|
5
5
|
/** Input accepted by `ai.request`, `ai.generate`, `ai.stream` and `ai.compact`. An `LLMRequest` is also a valid input. */
|
|
6
6
|
export type LLMRequestInput<Model extends LanguageModel = LanguageModel> = TextRequestFields<Model> & PromptOrMessages;
|
|
@@ -12,13 +12,12 @@ export type PromptOrMessages = {
|
|
|
12
12
|
readonly messages: ReadonlyArray<Message | Message.Input>;
|
|
13
13
|
readonly prompt?: never;
|
|
14
14
|
};
|
|
15
|
-
interface TextRequestFields<Model extends LanguageModel> extends BaseRequest<Model, NoInfer<LanguageModelProviderOptions<Model
|
|
15
|
+
interface TextRequestFields<Model extends LanguageModel> extends BaseRequest<Model, NoInfer<LanguageModelProviderOptions<Model>>>, GenerationOptionsFields {
|
|
16
16
|
readonly id?: string;
|
|
17
17
|
readonly system?: string | SystemPart | ReadonlyArray<SystemPart>;
|
|
18
18
|
/** Sent in array order. Pass `tool(...)` values or wire entries such as hosted provider tools. */
|
|
19
19
|
readonly tools?: ReadonlyArray<Tool | ToolEntryInput>;
|
|
20
20
|
readonly toolChoice?: ToolChoice.Input;
|
|
21
|
-
readonly generation?: GenerationOptions.Input;
|
|
22
21
|
readonly cache?: CachePolicy;
|
|
23
22
|
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
|
|
24
23
|
readonly promptCacheKey?: string;
|
package/dist/llm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, JsonSchema, Schema, Stream } from "effect";
|
|
2
2
|
import { tryRequest } from "./media-model.js";
|
|
3
3
|
import { LLMClient, Service, canCompact, compactRequest, } from "./route/client.js";
|
|
4
|
-
import {
|
|
4
|
+
import { InvalidProviderOutputError, InvalidRequestError, mergeGeneration, AIError, LLMEvent, LLMResponse, ResponseFold, Message, LanguageModel, SystemPart, ToolChoice, ToolEntry, Usage, withPartial, } from "./schema/index.js";
|
|
5
5
|
import { tool } from "./tool.js";
|
|
6
6
|
import { runTools } from "./tool-runtime.js";
|
|
7
7
|
import { addUsage, nextRequest, pendingCalls } from "./loop.js";
|
|
@@ -97,7 +97,7 @@ export const request = (input) => {
|
|
|
97
97
|
messages: input.prompt === undefined ? (input.messages ?? []).map(Message.make) : [Message.user(input.prompt)],
|
|
98
98
|
tools: input.tools?.map((item) => ("_definition" in item ? item._definition : ToolEntry.make(item))) ?? [],
|
|
99
99
|
toolChoice: input.toolChoice ? ToolChoice.make(input.toolChoice) : undefined,
|
|
100
|
-
|
|
100
|
+
...mergeGeneration(input),
|
|
101
101
|
providerOptions: input.providerOptions,
|
|
102
102
|
headers: input.headers,
|
|
103
103
|
fetch: input.fetch,
|
|
@@ -58,7 +58,7 @@ export const protocol = Protocol.make({
|
|
|
58
58
|
// Alibaba also rejects an explicit budget that is not below `max_completion_tokens`.
|
|
59
59
|
thinking_budget: opts.thinkingBudget === undefined
|
|
60
60
|
? undefined
|
|
61
|
-
: ProviderShared.fitThinkingBudget(opts.thinkingBudget, req.
|
|
61
|
+
: ProviderShared.fitThinkingBudget(opts.thinkingBudget, req.maxTokens),
|
|
62
62
|
preserve_thinking: opts.preserveThinking,
|
|
63
63
|
clear_thinking: opts.clearThinking,
|
|
64
64
|
thinking: opts.thinking,
|
|
@@ -66,7 +66,7 @@ export const protocol = Protocol.make({
|
|
|
66
66
|
parallel_tool_calls: opts.parallelToolCalls ??
|
|
67
67
|
(req.toolChoice?.disableParallelToolUse === undefined ? undefined : !req.toolChoice.disableParallelToolUse),
|
|
68
68
|
repetition_penalty: opts.repetitionPenalty,
|
|
69
|
-
top_k: req.
|
|
69
|
+
top_k: req.topK,
|
|
70
70
|
response_format: opts.responseFormat,
|
|
71
71
|
enable_search: opts.enableSearch,
|
|
72
72
|
search_options: opts.searchOptions,
|
|
@@ -800,7 +800,6 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
800
800
|
const outputConfig = options.output_config ?? options.outputConfig;
|
|
801
801
|
const format = outputConfig?.format ?? undefined;
|
|
802
802
|
const updates = resolveEffortUpdates(request, options.effort ?? outputConfig?.effort ?? undefined);
|
|
803
|
-
const generation = request.generation;
|
|
804
803
|
// Allocate the 4-breakpoint budget in invalidation order: tools → system →
|
|
805
804
|
// messages. Tools live highest in the cache hierarchy, so when callers
|
|
806
805
|
// over-mark we keep their tool hints and shed the message-tail ones first.
|
|
@@ -820,7 +819,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
820
819
|
const messages = yield* lowerMessages(flattened.request, breakpoints);
|
|
821
820
|
yield* Cache.warnDropped(breakpoints, "Anthropic Messages", ANTHROPIC_BREAKPOINT_CAP);
|
|
822
821
|
const output_config = updates.effort === undefined && format === undefined ? undefined : { effort: updates.effort, format };
|
|
823
|
-
const maxTokens =
|
|
822
|
+
const maxTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
824
823
|
const body = {
|
|
825
824
|
model: request.model.id,
|
|
826
825
|
system,
|
|
@@ -829,10 +828,10 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
829
828
|
tool_choice: toolChoice,
|
|
830
829
|
stream: true,
|
|
831
830
|
max_tokens: maxTokens,
|
|
832
|
-
temperature:
|
|
833
|
-
top_p:
|
|
834
|
-
top_k:
|
|
835
|
-
stop_sequences:
|
|
831
|
+
temperature: request.temperature,
|
|
832
|
+
top_p: request.topP,
|
|
833
|
+
top_k: request.topK,
|
|
834
|
+
stop_sequences: request.stop,
|
|
836
835
|
thinking: applyThinkingBindingDefault(request.model, fitThinking(options.thinking, maxTokens)),
|
|
837
836
|
output_config,
|
|
838
837
|
// top-level passthrough per SDK MessageCreateParamsBase:4638,4643,4649,4654,4670
|
|
@@ -460,11 +460,10 @@ const applyThinkingBindingDefault = (request, thinking) => {
|
|
|
460
460
|
const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request) {
|
|
461
461
|
const toolChoice = request.toolChoice ? yield* lowerToolChoice(request.toolChoice) : undefined;
|
|
462
462
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
463
|
-
const generation = request.generation;
|
|
464
463
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
465
464
|
const maxTokens = isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
|
|
466
465
|
? undefined
|
|
467
|
-
:
|
|
466
|
+
: request.maxTokens;
|
|
468
467
|
const thinking = applyThinkingBindingDefault(request, (() => {
|
|
469
468
|
if (options.thinking?.type === "enabled")
|
|
470
469
|
return {
|
|
@@ -477,7 +476,7 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
477
476
|
return { type: "adaptive" };
|
|
478
477
|
})());
|
|
479
478
|
const additionalModelRequestFields = {
|
|
480
|
-
...(
|
|
479
|
+
...(request.topK === undefined ? {} : { top_k: request.topK }),
|
|
481
480
|
...(thinking === undefined ? {} : { thinking }),
|
|
482
481
|
...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
|
|
483
482
|
// Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
|
|
@@ -501,15 +500,15 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
501
500
|
yield* warnDropped(breakpoints, "Bedrock Converse", BedrockCache.BEDROCK_BREAKPOINT_CAP);
|
|
502
501
|
const inferenceConfig = (() => {
|
|
503
502
|
if (maxTokens === undefined &&
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
(
|
|
503
|
+
request.temperature === undefined &&
|
|
504
|
+
request.topP === undefined &&
|
|
505
|
+
(request.stop === undefined || request.stop.length === 0))
|
|
507
506
|
return undefined;
|
|
508
507
|
return {
|
|
509
508
|
maxTokens,
|
|
510
|
-
temperature:
|
|
511
|
-
topP:
|
|
512
|
-
stopSequences:
|
|
509
|
+
temperature: request.temperature,
|
|
510
|
+
topP: request.topP,
|
|
511
|
+
stopSequences: request.stop,
|
|
513
512
|
};
|
|
514
513
|
})();
|
|
515
514
|
return {
|
|
@@ -208,16 +208,16 @@ const fromRequest = Effect.fn("CohereChat.fromRequest")(function* (request) {
|
|
|
208
208
|
// Cohere rejects budgets above max_tokens; fitting also leaves room for the answer.
|
|
209
209
|
token_budget: options.thinking.tokenBudget === undefined
|
|
210
210
|
? undefined
|
|
211
|
-
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.
|
|
211
|
+
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.maxTokens),
|
|
212
212
|
},
|
|
213
|
-
max_tokens: request.
|
|
214
|
-
temperature: request.
|
|
215
|
-
p: request.
|
|
216
|
-
k: request.
|
|
217
|
-
seed: request.
|
|
218
|
-
stop_sequences: request.
|
|
219
|
-
frequency_penalty: request.
|
|
220
|
-
presence_penalty: request.
|
|
213
|
+
max_tokens: request.maxTokens,
|
|
214
|
+
temperature: request.temperature,
|
|
215
|
+
p: request.topP,
|
|
216
|
+
k: request.topK,
|
|
217
|
+
seed: request.seed,
|
|
218
|
+
stop_sequences: request.stop,
|
|
219
|
+
frequency_penalty: request.frequencyPenalty,
|
|
220
|
+
presence_penalty: request.presencePenalty,
|
|
221
221
|
};
|
|
222
222
|
});
|
|
223
223
|
const finishReason = (raw) => {
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -345,17 +345,16 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
345
345
|
const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
346
346
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
347
347
|
const hasTools = flattened.tools.length > 0;
|
|
348
|
-
const generation = request.generation;
|
|
349
348
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
350
349
|
const generationConfig = {
|
|
351
|
-
maxOutputTokens:
|
|
352
|
-
temperature:
|
|
353
|
-
topP:
|
|
354
|
-
topK:
|
|
355
|
-
frequencyPenalty:
|
|
356
|
-
presencePenalty:
|
|
357
|
-
seed:
|
|
358
|
-
stopSequences:
|
|
350
|
+
maxOutputTokens: request.maxTokens,
|
|
351
|
+
temperature: request.temperature,
|
|
352
|
+
topP: request.topP,
|
|
353
|
+
topK: request.topK,
|
|
354
|
+
frequencyPenalty: request.frequencyPenalty,
|
|
355
|
+
presencePenalty: request.presencePenalty,
|
|
356
|
+
seed: request.seed,
|
|
357
|
+
stopSequences: request.stop,
|
|
359
358
|
// Gemini accepts a budget above `maxOutputTokens`, but thinking then leaves the answer empty.
|
|
360
359
|
thinkingConfig: options.thinkingConfig === undefined
|
|
361
360
|
? undefined
|
|
@@ -364,7 +363,7 @@ const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
|
364
363
|
includeThoughts: options.thinkingConfig.includeThoughts ?? true,
|
|
365
364
|
thinkingBudget: options.thinkingConfig.thinkingBudget === undefined
|
|
366
365
|
? undefined
|
|
367
|
-
: ProviderShared.fitThinkingBudget(options.thinkingConfig.thinkingBudget,
|
|
366
|
+
: ProviderShared.fitThinkingBudget(options.thinkingConfig.thinkingBudget, request.maxTokens, MIN_THINKING_BUDGET),
|
|
368
367
|
},
|
|
369
368
|
};
|
|
370
369
|
return {
|
|
@@ -278,9 +278,7 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
|
|
|
278
278
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
279
279
|
if (flattened.tools.some((tool) => tool.native !== undefined))
|
|
280
280
|
return yield* ProviderShared.invalidRequest("Google Interactions hosted tools are not supported");
|
|
281
|
-
if (request.
|
|
282
|
-
request.generation?.frequencyPenalty !== undefined ||
|
|
283
|
-
request.generation?.presencePenalty !== undefined)
|
|
281
|
+
if (request.topK !== undefined || request.frequencyPenalty !== undefined || request.presencePenalty !== undefined)
|
|
284
282
|
return yield* ProviderShared.invalidRequest("Google Interactions does not support topK, frequencyPenalty, or presencePenalty");
|
|
285
283
|
const choice = request.toolChoice === undefined
|
|
286
284
|
? undefined
|
|
@@ -308,11 +306,11 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
|
|
|
308
306
|
}))
|
|
309
307
|
: undefined,
|
|
310
308
|
generation_config: {
|
|
311
|
-
max_output_tokens: request.
|
|
312
|
-
temperature: request.
|
|
313
|
-
top_p: request.
|
|
314
|
-
seed: request.
|
|
315
|
-
stop_sequences: request.
|
|
309
|
+
max_output_tokens: request.maxTokens,
|
|
310
|
+
temperature: request.temperature,
|
|
311
|
+
top_p: request.topP,
|
|
312
|
+
seed: request.seed,
|
|
313
|
+
stop_sequences: request.stop,
|
|
316
314
|
thinking_level: options.thinkingLevel,
|
|
317
315
|
thinking_summaries: options.thinkingSummaries,
|
|
318
316
|
tool_choice: choice,
|
|
@@ -302,13 +302,13 @@ export const fromRequest = Effect.fn("MistralChat.fromRequest")(function* (reque
|
|
|
302
302
|
tools: flattened.tools.length > 0 ? flattened.tools.map(lowerTool) : undefined,
|
|
303
303
|
tool_choice: toolChoice,
|
|
304
304
|
stream: true,
|
|
305
|
-
max_tokens: request.
|
|
306
|
-
random_seed: request.
|
|
307
|
-
temperature: request.
|
|
308
|
-
top_p: request.
|
|
309
|
-
frequency_penalty: request.
|
|
310
|
-
presence_penalty: request.
|
|
311
|
-
stop: request.
|
|
305
|
+
max_tokens: request.maxTokens,
|
|
306
|
+
random_seed: request.seed,
|
|
307
|
+
temperature: request.temperature,
|
|
308
|
+
top_p: request.topP,
|
|
309
|
+
frequency_penalty: request.frequencyPenalty,
|
|
310
|
+
presence_penalty: request.presencePenalty,
|
|
311
|
+
stop: request.stop,
|
|
312
312
|
prompt_cache_key: ProviderShared.sendsPromptCacheKey(request)
|
|
313
313
|
? (options.promptCacheKey ?? request.promptCacheKey)
|
|
314
314
|
: undefined,
|
|
@@ -606,16 +606,15 @@ export const lowerConversation = Effect.fnUntraced(function* (request, adapter)
|
|
|
606
606
|
};
|
|
607
607
|
});
|
|
608
608
|
export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
609
|
-
const generation = request.generation;
|
|
610
609
|
const cacheKey = ProviderShared.promptCacheKey(request);
|
|
611
610
|
const parallelToolCalls = resolveParallelToolCalls(request, options);
|
|
612
611
|
return {
|
|
613
612
|
stream: true,
|
|
614
|
-
max_output_tokens:
|
|
615
|
-
temperature:
|
|
616
|
-
top_p:
|
|
617
|
-
presence_penalty:
|
|
618
|
-
frequency_penalty:
|
|
613
|
+
max_output_tokens: request.maxTokens,
|
|
614
|
+
temperature: request.temperature,
|
|
615
|
+
top_p: request.topP,
|
|
616
|
+
presence_penalty: request.presencePenalty,
|
|
617
|
+
frequency_penalty: request.frequencyPenalty,
|
|
619
618
|
...(options.store !== undefined ? { store: options.store } : {}),
|
|
620
619
|
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
621
620
|
...(options.safetyIdentifier ? { safety_identifier: options.safetyIdentifier } : {}),
|
|
@@ -666,7 +666,6 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
666
666
|
const reasoningField = request.model.compatibility?.reasoningField;
|
|
667
667
|
if (reasoningField && RESERVED_REASONING_FIELDS.has(reasoningField))
|
|
668
668
|
return yield* ProviderShared.invalidRequest(`OpenAI Chat reasoning field conflicts with reserved field ${reasoningField}`);
|
|
669
|
-
const generation = request.generation;
|
|
670
669
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
671
670
|
const provider = request.model.provider;
|
|
672
671
|
const baseURL = request.model.route.endpoint.baseURL;
|
|
@@ -692,14 +691,14 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
692
691
|
...((request.model.compatibility?.streamUsage ?? true) ? { stream_options: { include_usage: true } } : {}),
|
|
693
692
|
...(zaiToolStream && hasActiveTools ? { tool_stream: true } : {}),
|
|
694
693
|
...(maxTokensField === "max_completion_tokens"
|
|
695
|
-
? { max_completion_tokens:
|
|
696
|
-
: { max_tokens:
|
|
697
|
-
temperature:
|
|
698
|
-
top_p:
|
|
699
|
-
frequency_penalty:
|
|
700
|
-
presence_penalty:
|
|
701
|
-
seed:
|
|
702
|
-
stop:
|
|
694
|
+
? { max_completion_tokens: request.maxTokens }
|
|
695
|
+
: { max_tokens: request.maxTokens }),
|
|
696
|
+
temperature: request.temperature,
|
|
697
|
+
top_p: request.topP,
|
|
698
|
+
frequency_penalty: request.frequencyPenalty,
|
|
699
|
+
presence_penalty: request.presencePenalty,
|
|
700
|
+
seed: request.seed,
|
|
701
|
+
stop: request.stop,
|
|
703
702
|
...lowerOptions(request, supportsStore, hasActiveTools),
|
|
704
703
|
};
|
|
705
704
|
});
|
|
@@ -138,7 +138,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
|
138
138
|
});
|
|
139
139
|
return {
|
|
140
140
|
...body,
|
|
141
|
-
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.
|
|
141
|
+
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.maxTokens,
|
|
142
142
|
reasoning_effort: undefined,
|
|
143
143
|
reasoning: options.reasoningEffort === undefined
|
|
144
144
|
? options.reasoning
|
|
@@ -153,7 +153,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
|
153
153
|
prompt_cache_retention: options.promptCacheRetention ?? body.prompt_cache_retention,
|
|
154
154
|
parallel_tool_calls: options.parallelToolCalls,
|
|
155
155
|
min_p: options.minP,
|
|
156
|
-
top_k: request.
|
|
156
|
+
top_k: request.topK,
|
|
157
157
|
repetition_penalty: options.repetitionPenalty,
|
|
158
158
|
stop_token_ids: options.stopTokenIds,
|
|
159
159
|
logprobs: options.logprobs,
|
|
@@ -95,7 +95,7 @@ const fromSettings = ({ apiKey, auth, baseURL, body, credentials, headers, profi
|
|
|
95
95
|
auth,
|
|
96
96
|
baseURL,
|
|
97
97
|
credentials,
|
|
98
|
-
|
|
98
|
+
topP,
|
|
99
99
|
headers,
|
|
100
100
|
http: body === undefined ? undefined : { body },
|
|
101
101
|
profile,
|
|
@@ -33,7 +33,7 @@ export const model = (modelID, { apiKey, auth, baseURL, credentials, profile, re
|
|
|
33
33
|
auth,
|
|
34
34
|
baseURL,
|
|
35
35
|
credentials,
|
|
36
|
-
|
|
36
|
+
topP,
|
|
37
37
|
headers: headers === undefined ? undefined : { ...headers },
|
|
38
38
|
http: body === undefined ? undefined : { body: { ...body } },
|
|
39
39
|
providerOptions,
|
|
@@ -56,7 +56,7 @@ export const protocol = Protocol.make({
|
|
|
56
56
|
reasoning_details: reasoningDetails,
|
|
57
57
|
};
|
|
58
58
|
},
|
|
59
|
-
}).pipe(Effect.map((body) => bodyOptions(body, request.providerOptions, request.
|
|
59
|
+
}).pipe(Effect.map((body) => bodyOptions(body, request.providerOptions, request.maxTokens))),
|
|
60
60
|
},
|
|
61
61
|
stream: OpenAIChat.protocol.stream,
|
|
62
62
|
});
|
package/dist/public.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding,
|
|
3
|
-
export type { BaseRequest, ContentPartInput, GenerationOptionsFields,
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GENERATION_KEYS, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export type { BaseRequest, ContentPartInput, GenerationOptionsFields, HttpOptions, LanguageModelDefaults, LanguageModelInput, LanguageModelProviderOptions, LLMRequest, MediaPartInput, RequestTimeout, TimeoutConfig, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, TransportOptions, UsageInput, } from "./schema/index.js";
|
|
4
4
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
5
5
|
export type { ImageModelOptions, ImageOptions, ImageRequest, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
6
6
|
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
package/dist/public.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding,
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GENERATION_KEYS, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
3
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
4
4
|
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
5
5
|
export { Media } from "./media.js";
|
package/dist/route/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { HttpMiddleware, Transport, TransportRuntime, WebSocketChannelExecu
|
|
|
8
8
|
import type { Protocol } from "./protocol.js";
|
|
9
9
|
import type { LanguageModelSanitizerCompatibility, ProtocolID, ProviderOptions } from "../schema/index.js";
|
|
10
10
|
import type { LLMRequestInput } from "../llm.js";
|
|
11
|
-
import { AIError, CompactionResponse, CompactionCheckpointResponse,
|
|
11
|
+
import { AIError, CompactionResponse, CompactionCheckpointResponse, LLMResponse, LanguageModel, LLMEvent, ProviderID, type LLMRequest, type LanguageModelDefaults } from "../schema/index.js";
|
|
12
12
|
export interface RouteBody<Body> {
|
|
13
13
|
/** Schema for the validated provider-native body sent as the JSON request. */
|
|
14
14
|
readonly schema: Schema.Codec<Body, unknown>;
|
|
@@ -49,14 +49,8 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
|
|
|
49
49
|
export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
|
|
50
50
|
export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
|
|
51
51
|
export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
readonly providerOptions?: ProviderOptions;
|
|
55
|
-
}
|
|
56
|
-
export interface RouteDefaultsInput extends TransportOptions {
|
|
57
|
-
readonly generation?: GenerationOptions.Input;
|
|
58
|
-
readonly providerOptions?: ProviderOptions;
|
|
59
|
-
}
|
|
52
|
+
export type RouteDefaults = LanguageModelDefaults;
|
|
53
|
+
export type RouteDefaultsInput = LanguageModelDefaults;
|
|
60
54
|
export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
|
|
61
55
|
readonly compact?: CompactionOperations;
|
|
62
56
|
readonly id?: string;
|
package/dist/route/client.js
CHANGED
|
@@ -10,7 +10,7 @@ import { normalizeToolHistory } from "../tool-history.js";
|
|
|
10
10
|
import { sanitizeSurrogates } from "../utils/sanitize.js";
|
|
11
11
|
import * as ProviderShared from "../protocols/shared.js";
|
|
12
12
|
import { ToolSchemaProjection } from "../protocols/utils/tool-schema.js";
|
|
13
|
-
import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason,
|
|
13
|
+
import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason, LLMResponse, ResponseFold, LanguageModel, Message, LLMEvent, InvalidProviderOutputError, ProviderConfigurationError, ProviderID, ToolChoice, ToolEntry, mergeGeneration, mergeProviderOptions, mergeTransport, withPartial, } from "../schema/index.js";
|
|
14
14
|
const makeRouteLanguageModel = (route, mapped) => {
|
|
15
15
|
const provider = route.provider ?? ("provider" in mapped ? mapped.provider : undefined);
|
|
16
16
|
if (!provider)
|
|
@@ -30,7 +30,7 @@ const mergeRouteDefaults = (base, patch) => ({
|
|
|
30
30
|
...base,
|
|
31
31
|
...patch,
|
|
32
32
|
...mergeTransport(base, patch),
|
|
33
|
-
|
|
33
|
+
...mergeGeneration(base, patch),
|
|
34
34
|
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
|
35
35
|
});
|
|
36
36
|
export function canCompact(target, options) {
|
|
@@ -59,10 +59,9 @@ const resolveRequestOptions = (request) => {
|
|
|
59
59
|
const normalized = messages === request.messages ? request : { ...request, messages };
|
|
60
60
|
const routeDefaults = normalized.model.route.defaults;
|
|
61
61
|
const modelDefaults = normalized.model.defaults;
|
|
62
|
-
const generation = mergeGenerationOptions(routeDefaults.generation, modelDefaults?.generation, normalized.generation);
|
|
63
62
|
return {
|
|
64
63
|
...normalized,
|
|
65
|
-
|
|
64
|
+
...mergeGeneration(routeDefaults, modelDefaults, normalized),
|
|
66
65
|
providerOptions: mergeProviderOptions(routeDefaults.providerOptions, modelDefaults?.providerOptions, normalized.providerOptions),
|
|
67
66
|
...mergeTransport(routeDefaults, modelDefaults, normalized),
|
|
68
67
|
};
|
|
@@ -220,7 +219,6 @@ const restoreClasses = (request) => ({
|
|
|
220
219
|
messages: request.messages.map(Message.make),
|
|
221
220
|
tools: request.tools.map(ToolEntry.make),
|
|
222
221
|
toolChoice: request.toolChoice === undefined ? undefined : ToolChoice.make(request.toolChoice),
|
|
223
|
-
generation: request.generation === undefined ? undefined : GenerationOptions.make(request.generation),
|
|
224
222
|
});
|
|
225
223
|
const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
226
224
|
const references = request.messages.flatMap((message) => message.content.flatMap((part) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Tool } from "@opencode/schema/tool";
|
|
3
|
-
import { type BaseRequest, CacheHint, type CachePolicy,
|
|
3
|
+
import { type BaseRequest, CacheHint, type CachePolicy, JsonSchema, type LanguageModel, type LanguageModelProviderOptions, ReasoningEffort, type GenerationOptionsFields } from "./options.js";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
5
|
export declare const MessageRole: Schema.Literals<readonly ["system", "user", "assistant", "tool"]>;
|
|
6
6
|
export type MessageRole = Schema.Schema.Type<typeof MessageRole>;
|
|
@@ -833,13 +833,12 @@ export declare namespace ToolChoice {
|
|
|
833
833
|
* A normalized text request, the plain object `ai.request(...)` returns. Edit it with a spread, such as
|
|
834
834
|
* `{ ...request, messages: [...request.messages, next] }`, or pass the edited object back to `ai.request`.
|
|
835
835
|
*/
|
|
836
|
-
export interface LLMRequest<Model extends LanguageModel = LanguageModel> extends BaseRequest<Model, LanguageModelProviderOptions<Model
|
|
836
|
+
export interface LLMRequest<Model extends LanguageModel = LanguageModel> extends BaseRequest<Model, LanguageModelProviderOptions<Model>>, GenerationOptionsFields {
|
|
837
837
|
readonly id?: string;
|
|
838
838
|
readonly system: ReadonlyArray<SystemPart>;
|
|
839
839
|
readonly messages: ReadonlyArray<Message>;
|
|
840
840
|
readonly tools: ReadonlyArray<ToolEntry>;
|
|
841
841
|
readonly toolChoice?: ToolChoice;
|
|
842
|
-
readonly generation?: GenerationOptions;
|
|
843
842
|
readonly cache?: CachePolicy;
|
|
844
843
|
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
|
|
845
844
|
readonly promptCacheKey?: string;
|
package/dist/schema/options.d.ts
CHANGED
|
@@ -59,24 +59,8 @@ export interface BaseRequest<Model, Options = ProviderOptions> extends Transport
|
|
|
59
59
|
export declare const timeoutConfig: (timeout: RequestTimeout | undefined) => TimeoutConfig;
|
|
60
60
|
/** Merge transport settings; later items win, headers, query and body merge by key. */
|
|
61
61
|
export declare const mergeTransport: (...items: ReadonlyArray<TransportOptions | undefined>) => TransportOptions;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
readonly temperature: Schema.optional<Schema.Number>;
|
|
65
|
-
readonly topP: Schema.optional<Schema.Number>;
|
|
66
|
-
readonly topK: Schema.optional<Schema.Number>;
|
|
67
|
-
readonly frequencyPenalty: Schema.optional<Schema.Number>;
|
|
68
|
-
readonly presencePenalty: Schema.optional<Schema.Number>;
|
|
69
|
-
readonly seed: Schema.optional<Schema.Number>;
|
|
70
|
-
readonly stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
71
|
-
}>, {}>;
|
|
72
|
-
export declare class GenerationOptions extends GenerationOptions_base {
|
|
73
|
-
}
|
|
74
|
-
export declare namespace GenerationOptions {
|
|
75
|
-
type Input = GenerationOptions | ConstructorParameters<typeof GenerationOptions>[0];
|
|
76
|
-
/** Normalize generation option input into the canonical `GenerationOptions` class. */
|
|
77
|
-
const make: (input?: Input) => GenerationOptions;
|
|
78
|
-
}
|
|
79
|
-
export type GenerationOptionsFields = {
|
|
62
|
+
/** Portable sampling knobs, set at the top level of text requests, model defaults and route defaults. */
|
|
63
|
+
export interface GenerationOptionsFields {
|
|
80
64
|
readonly maxTokens?: number;
|
|
81
65
|
readonly temperature?: number;
|
|
82
66
|
readonly topP?: number;
|
|
@@ -85,22 +69,15 @@ export type GenerationOptionsFields = {
|
|
|
85
69
|
readonly presencePenalty?: number;
|
|
86
70
|
readonly seed?: number;
|
|
87
71
|
readonly stop?: ReadonlyArray<string>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export declare const
|
|
72
|
+
}
|
|
73
|
+
/** The keys of `GenerationOptionsFields`, for splitting a flat record into portable knobs and provider options. */
|
|
74
|
+
export declare const GENERATION_KEYS: ReadonlySet<string>;
|
|
75
|
+
/** Pick the generation knobs out of each item; later items win per knob. */
|
|
76
|
+
export declare const mergeGeneration: (...items: ReadonlyArray<GenerationOptionsFields | undefined>) => GenerationOptionsFields;
|
|
91
77
|
/** Request defaults a selected model applies under each request. */
|
|
92
|
-
export interface LanguageModelDefaults extends TransportOptions {
|
|
93
|
-
readonly generation?: GenerationOptions;
|
|
78
|
+
export interface LanguageModelDefaults extends TransportOptions, GenerationOptionsFields {
|
|
94
79
|
readonly providerOptions?: ProviderOptions;
|
|
95
80
|
}
|
|
96
|
-
export declare namespace LanguageModelDefaults {
|
|
97
|
-
interface Input extends TransportOptions {
|
|
98
|
-
readonly generation?: GenerationOptions.Input;
|
|
99
|
-
readonly providerOptions?: ProviderOptions;
|
|
100
|
-
}
|
|
101
|
-
/** Normalize selected-model request defaults without applying precedence. */
|
|
102
|
-
const make: (input: Input) => LanguageModelDefaults;
|
|
103
|
-
}
|
|
104
81
|
/** Provider-defined string enum: known values for autocomplete, any string accepted. */
|
|
105
82
|
export type OpenString<Known extends string> = Known | (string & {});
|
|
106
83
|
export declare const ReasoningEfforts: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -168,10 +145,9 @@ export declare namespace LanguageModel {
|
|
|
168
145
|
readonly defaults?: LanguageModelDefaults;
|
|
169
146
|
readonly compatibility?: LanguageModelCompatibility;
|
|
170
147
|
};
|
|
171
|
-
type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "
|
|
148
|
+
type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "compatibility"> & {
|
|
172
149
|
readonly id: string | ModelID;
|
|
173
150
|
readonly provider: string | ProviderID;
|
|
174
|
-
readonly defaults?: LanguageModelDefaults.Input;
|
|
175
151
|
readonly compatibility?: LanguageModelCompatibility.Input;
|
|
176
152
|
};
|
|
177
153
|
}
|
package/dist/schema/options.js
CHANGED
|
@@ -64,43 +64,19 @@ export const mergeTransport = (...items) => {
|
|
|
64
64
|
}),
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
GenerationOptions.make = (input = {}) => (input instanceof GenerationOptions ? input : new GenerationOptions(input));
|
|
81
|
-
})(GenerationOptions || (GenerationOptions = {}));
|
|
82
|
-
const latestGeneration = (items, key) => items.findLast((item) => item?.[key] !== undefined)?.[key];
|
|
83
|
-
export const mergeGenerationOptions = (...items) => {
|
|
84
|
-
const result = new GenerationOptions({
|
|
85
|
-
maxTokens: latestGeneration(items, "maxTokens"),
|
|
86
|
-
temperature: latestGeneration(items, "temperature"),
|
|
87
|
-
topP: latestGeneration(items, "topP"),
|
|
88
|
-
topK: latestGeneration(items, "topK"),
|
|
89
|
-
frequencyPenalty: latestGeneration(items, "frequencyPenalty"),
|
|
90
|
-
presencePenalty: latestGeneration(items, "presencePenalty"),
|
|
91
|
-
seed: latestGeneration(items, "seed"),
|
|
92
|
-
stop: latestGeneration(items, "stop"),
|
|
93
|
-
});
|
|
94
|
-
return Object.values(result).some((value) => value !== undefined) ? result : undefined;
|
|
95
|
-
};
|
|
96
|
-
export var LanguageModelDefaults;
|
|
97
|
-
(function (LanguageModelDefaults) {
|
|
98
|
-
/** Normalize selected-model request defaults without applying precedence. */
|
|
99
|
-
LanguageModelDefaults.make = (input) => ({
|
|
100
|
-
...input,
|
|
101
|
-
generation: input.generation === undefined ? undefined : GenerationOptions.make(input.generation),
|
|
102
|
-
});
|
|
103
|
-
})(LanguageModelDefaults || (LanguageModelDefaults = {}));
|
|
67
|
+
/** The keys of `GenerationOptionsFields`, for splitting a flat record into portable knobs and provider options. */
|
|
68
|
+
export const GENERATION_KEYS = new Set([
|
|
69
|
+
"maxTokens",
|
|
70
|
+
"temperature",
|
|
71
|
+
"topP",
|
|
72
|
+
"topK",
|
|
73
|
+
"frequencyPenalty",
|
|
74
|
+
"presencePenalty",
|
|
75
|
+
"seed",
|
|
76
|
+
"stop",
|
|
77
|
+
]);
|
|
78
|
+
/** Pick the generation knobs out of each item; later items win per knob. */
|
|
79
|
+
export const mergeGeneration = (...items) => Object.fromEntries([...GENERATION_KEYS].map((key) => [key, last(items.map((item) => item?.[key]))]));
|
|
104
80
|
export const ReasoningEfforts = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
105
81
|
export const ReasoningEffort = Schema.declare((value) => typeof value === "string", { title: "ReasoningEffort" });
|
|
106
82
|
/** Tool schema sanitizer for a model family. `none` opts out of the protocol and model-name defaults. */
|
|
@@ -155,7 +131,7 @@ export class LanguageModel {
|
|
|
155
131
|
id: ModelID.make(input.id),
|
|
156
132
|
provider: ProviderID.make(input.provider),
|
|
157
133
|
route: input.route,
|
|
158
|
-
defaults: input.defaults
|
|
134
|
+
defaults: input.defaults,
|
|
159
135
|
compatibility: input.compatibility === undefined ? undefined : LanguageModelCompatibility.make(input.compatibility),
|
|
160
136
|
});
|
|
161
137
|
}
|
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-646",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -520,7 +520,7 @@
|
|
|
520
520
|
"devDependencies": {
|
|
521
521
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
522
522
|
"@effect/platform-node": "4.1.0",
|
|
523
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
523
|
+
"@opencode/http-recorder": "0.0.0-dev-646",
|
|
524
524
|
"@tsconfig/bun": "1.0.9",
|
|
525
525
|
"@types/bun": "1.4.3",
|
|
526
526
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -530,7 +530,7 @@
|
|
|
530
530
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
531
531
|
"@smithy/eventstream-codec": "4.2.14",
|
|
532
532
|
"@smithy/util-utf8": "4.2.2",
|
|
533
|
-
"@opencode/schema": "0.0.0-dev-
|
|
533
|
+
"@opencode/schema": "0.0.0-dev-646",
|
|
534
534
|
"aws4fetch": "1.0.20",
|
|
535
535
|
"effect": "4.1.0",
|
|
536
536
|
"google-auth-library": "10.5.0"
|