@opencode/ai 0.0.0-dev-21922 → 0.0.0-dev-51

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.
Files changed (128) hide show
  1. package/README.md +39 -17
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/decision-client.d.ts +3 -3
  4. package/dist/decision.d.ts +4 -1
  5. package/dist/decision.js +3 -0
  6. package/dist/effect.d.ts +4 -5
  7. package/dist/effect.js +2 -3
  8. package/dist/experimental/realtime.d.ts +3 -2
  9. package/dist/image-client.d.ts +1 -1
  10. package/dist/image.js +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/llm.d.ts +3 -0
  13. package/dist/media-client.d.ts +2 -1
  14. package/dist/media-model.d.ts +3 -0
  15. package/dist/media-model.js +4 -1
  16. package/dist/protocols/alibaba-responses.d.ts +3 -3
  17. package/dist/protocols/bedrock-converse.d.ts +98 -3
  18. package/dist/protocols/bedrock-converse.js +112 -15
  19. package/dist/protocols/bedrock-event-stream.js +1 -0
  20. package/dist/protocols/open-responses.d.ts +3 -0
  21. package/dist/protocols/openai-chat.d.ts +3 -0
  22. package/dist/protocols/openai-compatible-chat.d.ts +2 -2
  23. package/dist/protocols/openai-compatible-responses.d.ts +3 -3
  24. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  25. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  26. package/dist/protocols/utils/tool-schema.js +15 -5
  27. package/dist/protocols/utils/tool-stream.d.ts +9 -0
  28. package/dist/providers/alibaba/images.d.ts +2 -0
  29. package/dist/providers/alibaba/images.js +1 -0
  30. package/dist/providers/alibaba.d.ts +3 -2
  31. package/dist/providers/alibaba.js +12 -8
  32. package/dist/providers/amazon-bedrock.d.ts +30 -10
  33. package/dist/providers/amazon-bedrock.js +11 -11
  34. package/dist/providers/azure/images.d.ts +2 -0
  35. package/dist/providers/azure/images.js +1 -0
  36. package/dist/providers/azure.d.ts +3 -1
  37. package/dist/providers/azure.js +19 -1
  38. package/dist/providers/baseten/decisions.d.ts +2 -0
  39. package/dist/providers/baseten/decisions.js +1 -0
  40. package/dist/providers/baseten.d.ts +5 -4
  41. package/dist/providers/baseten.js +15 -8
  42. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  43. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  44. package/dist/providers/cloudflare-ai-gateway.d.ts +3 -2
  45. package/dist/providers/cloudflare-ai-gateway.js +11 -6
  46. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  47. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  48. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  49. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  50. package/dist/providers/cloudflare-workers-ai.d.ts +5 -3
  51. package/dist/providers/cloudflare-workers-ai.js +16 -7
  52. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  53. package/dist/providers/digitalocean/decisions.js +1 -0
  54. package/dist/providers/digitalocean/images.d.ts +2 -0
  55. package/dist/providers/digitalocean/images.js +1 -0
  56. package/dist/providers/digitalocean.d.ts +9 -4
  57. package/dist/providers/digitalocean.js +25 -8
  58. package/dist/providers/google/images.d.ts +2 -0
  59. package/dist/providers/google/images.js +1 -0
  60. package/dist/providers/google-vertex/images.d.ts +2 -0
  61. package/dist/providers/google-vertex/images.js +1 -0
  62. package/dist/providers/google-vertex.d.ts +3 -1
  63. package/dist/providers/google-vertex.js +30 -13
  64. package/dist/providers/google.d.ts +5 -4
  65. package/dist/providers/google.js +15 -8
  66. package/dist/providers/openai/images.d.ts +2 -0
  67. package/dist/providers/openai/images.js +1 -0
  68. package/dist/providers/openai-compatible/images.d.ts +2 -0
  69. package/dist/providers/openai-compatible/images.js +1 -0
  70. package/dist/providers/openai-compatible.d.ts +3 -1
  71. package/dist/providers/openai-compatible.js +21 -9
  72. package/dist/providers/openai.d.ts +10 -8
  73. package/dist/providers/openai.js +10 -2
  74. package/dist/providers/opencode/decisions.d.ts +2 -0
  75. package/dist/providers/opencode/decisions.js +1 -0
  76. package/dist/providers/opencode.d.ts +9 -4
  77. package/dist/providers/opencode.js +2 -1
  78. package/dist/providers/openrouter/decisions.d.ts +2 -0
  79. package/dist/providers/openrouter/decisions.js +1 -0
  80. package/dist/providers/openrouter/images.d.ts +2 -0
  81. package/dist/providers/openrouter/images.js +1 -0
  82. package/dist/providers/openrouter.d.ts +9 -4
  83. package/dist/providers/openrouter.js +31 -9
  84. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  85. package/dist/providers/typesafe-ai/decisions.js +1 -0
  86. package/dist/providers/typesafe-ai.d.ts +9 -4
  87. package/dist/providers/typesafe-ai.js +2 -1
  88. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  89. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  90. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  91. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  92. package/dist/providers/vercel-ai-gateway.d.ts +9 -7
  93. package/dist/providers/vercel-ai-gateway.js +18 -10
  94. package/dist/providers/xai/images.d.ts +2 -0
  95. package/dist/providers/xai/images.js +1 -0
  96. package/dist/providers/xai.d.ts +5 -4
  97. package/dist/providers/xai.js +15 -8
  98. package/dist/providers/zai/images.d.ts +2 -0
  99. package/dist/providers/zai/images.js +1 -0
  100. package/dist/providers/zai.d.ts +5 -4
  101. package/dist/providers/zai.js +15 -8
  102. package/dist/route/client.d.ts +2 -2
  103. package/dist/route/client.js +15 -4
  104. package/dist/route/decision.d.ts +2 -1
  105. package/dist/route/decision.js +1 -0
  106. package/dist/route/executor.d.ts +1 -1
  107. package/dist/route/framing.d.ts +2 -0
  108. package/dist/route/index.d.ts +3 -0
  109. package/dist/route/index.js +3 -0
  110. package/dist/route/media.d.ts +5 -1
  111. package/dist/route/media.js +6 -2
  112. package/dist/route/transport/http.js +1 -0
  113. package/dist/route/transport/index.d.ts +1 -0
  114. package/dist/schema/events.d.ts +135 -6
  115. package/dist/schema/events.js +10 -0
  116. package/dist/schema/messages.d.ts +4 -0
  117. package/dist/schema/messages.js +3 -0
  118. package/dist/speech-client.d.ts +1 -1
  119. package/dist/speech.js +2 -1
  120. package/dist/testing.d.ts +25 -24
  121. package/dist/testing.js +3 -21
  122. package/dist/transcription-client.d.ts +1 -1
  123. package/dist/transcription.js +1 -0
  124. package/dist/video-client.d.ts +1 -1
  125. package/dist/video.js +1 -0
  126. package/package.json +510 -8
  127. package/dist/provider.d.ts +0 -23
  128. package/dist/provider.js +0 -2
@@ -10,7 +10,7 @@ import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
10
10
  import { BedrockAuth } from "./utils/bedrock-auth.js";
11
11
  import { BedrockCache } from "./utils/bedrock-cache.js";
12
12
  import { BedrockMedia } from "./utils/bedrock-media.js";
13
- import { supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
13
+ import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
14
14
  import { Lifecycle } from "./utils/lifecycle.js";
15
15
  import { MistralToolID } from "./utils/mistral-tool-id.js";
16
16
  import { ToolStream } from "./utils/tool-stream.js";
@@ -86,6 +86,11 @@ const BedrockToolChoice = Schema.Union([
86
86
  Schema.Struct({ any: Schema.Struct({}) }),
87
87
  Schema.Struct({ tool: Schema.Struct({ name: Schema.String }) }),
88
88
  ]);
89
+ // Value sets from the Converse API reference. Unknown values pass through for forward compatibility.
90
+ const ServiceTierType = ProviderShared.knownString();
91
+ const GuardrailTrace = ProviderShared.knownString();
92
+ const GuardrailStreamProcessingMode = ProviderShared.knownString();
93
+ const TextFormatType = ProviderShared.knownString();
89
94
  const BedrockBodyFields = {
90
95
  modelId: Schema.String,
91
96
  messages: Schema.Array(BedrockMessage),
@@ -101,6 +106,26 @@ const BedrockBodyFields = {
101
106
  toolChoice: Schema.optional(BedrockToolChoice),
102
107
  })),
103
108
  additionalModelRequestFields: Schema.optional(JsonObject),
109
+ serviceTier: Schema.optional(Schema.Struct({ type: ServiceTierType })),
110
+ guardrailConfig: Schema.optional(Schema.Struct({
111
+ guardrailIdentifier: Schema.String,
112
+ guardrailVersion: Schema.String,
113
+ trace: Schema.optional(GuardrailTrace),
114
+ streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
115
+ })),
116
+ outputConfig: Schema.optional(Schema.Struct({
117
+ textFormat: Schema.Struct({
118
+ type: TextFormatType,
119
+ structure: Schema.Struct({
120
+ jsonSchema: Schema.Struct({
121
+ schema: Schema.String,
122
+ name: Schema.optional(Schema.String),
123
+ description: Schema.optional(Schema.String),
124
+ }),
125
+ }),
126
+ }),
127
+ })),
128
+ requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
104
129
  };
105
130
  const BedrockConverseBody = Schema.Struct(BedrockBodyFields);
106
131
  const BedrockUsageSchema = Schema.Struct({
@@ -376,8 +401,49 @@ const isHighReasoningEffort = Schema.is(Schema.Struct({
376
401
  reasoningConfig: Schema.Struct({ maxReasoningEffort: Schema.Literal("high") }),
377
402
  }),
378
403
  }));
404
+ // Claude 4.6+ pairs effort with adaptive thinking; earlier Claude models take effort beside a manual budget.
405
+ const supportsAdaptiveThinking = (model) => {
406
+ const version = claudeVersion(model.id);
407
+ return version !== undefined && (version.major > 4 || (version.major === 4 && version.minor >= 6));
408
+ };
409
+ const effortFields = (model, effort) => {
410
+ if (model.id.includes("anthropic"))
411
+ return { output_config: { effort } };
412
+ // gpt-oss takes the flat chat-completions spelling; newer OpenAI and xAI models take the Responses one.
413
+ if (model.id.includes("openai.gpt-oss"))
414
+ return { reasoning_effort: effort };
415
+ if (model.id.includes("openai.") || model.id.includes("xai."))
416
+ return { reasoning: { effort } };
417
+ return { reasoningConfig: { type: "enabled", maxReasoningEffort: effort } };
418
+ };
379
419
  const Options = Schema.Struct({
380
- thinking: Schema.optional(Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number })),
420
+ /** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
421
+ thinking: Schema.optional(Schema.Union([
422
+ Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number }),
423
+ Schema.Struct({
424
+ type: Schema.Literal("adaptive"),
425
+ display: Schema.optional(ProviderShared.knownString()),
426
+ }),
427
+ Schema.Struct({ type: Schema.Literal("disabled") }),
428
+ ])),
429
+ /** Reasoning effort, sent in the field each model family reads. */
430
+ effort: Schema.optional(ProviderShared.knownString()),
431
+ serviceTier: Schema.optional(ServiceTierType),
432
+ /** Constrains the response text to a JSON schema. */
433
+ outputFormat: Schema.optional(Schema.Struct({
434
+ type: TextFormatType,
435
+ schema: JsonObject,
436
+ name: Schema.optional(Schema.String),
437
+ description: Schema.optional(Schema.String),
438
+ })),
439
+ guardrail: Schema.optional(Schema.Struct({
440
+ identifier: Schema.String,
441
+ version: Schema.String,
442
+ trace: Schema.optional(GuardrailTrace),
443
+ streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
444
+ })),
445
+ /** Key-value pairs for filtering invocation logs. */
446
+ requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
381
447
  });
382
448
  const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
383
449
  // Claude on Bedrock requires the thinking budget below `maxTokens`, with a minimum of 1,024.
@@ -390,7 +456,7 @@ const isThinkingDisabled = Schema.is(Schema.Struct({
390
456
  // Claude 5.1+ binds each thinking signature to the prefix above it. Ask Bedrock to drop the affected blocks instead of
391
457
  // failing when that prefix changes. `http.body` overlays this field by field, so callers can still override it.
392
458
  const applyThinkingBindingDefault = (request, thinking) => {
393
- if (isThinkingDisabled(request.http?.body))
459
+ if (thinking?.type === "disabled" || isThinkingDisabled(request.http?.body))
394
460
  return thinking;
395
461
  if (!supportsThinkingBlockBinding(request.model))
396
462
  return thinking;
@@ -404,13 +470,27 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
404
470
  const flattened = ProviderShared.flattenToolRequest(request);
405
471
  const generation = request.generation;
406
472
  const options = yield* decodeOptions(request.providerOptions ?? {});
407
- const maxTokens = isNova2(request.model) && isHighReasoningEffort(request.http?.body) ? undefined : generation?.maxTokens;
408
- const thinking = applyThinkingBindingDefault(request, options.thinking === undefined
473
+ const maxTokens = isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
409
474
  ? undefined
410
- : {
411
- type: "enabled",
412
- budget_tokens: ProviderShared.fitThinkingBudget(options.thinking.budgetTokens, maxTokens, MIN_THINKING_BUDGET),
413
- });
475
+ : generation?.maxTokens;
476
+ const thinking = applyThinkingBindingDefault(request, (() => {
477
+ if (options.thinking?.type === "enabled")
478
+ return {
479
+ type: "enabled",
480
+ budget_tokens: ProviderShared.fitThinkingBudget(options.thinking.budgetTokens, maxTokens, MIN_THINKING_BUDGET),
481
+ };
482
+ if (options.thinking !== undefined)
483
+ return options.thinking;
484
+ if (options.effort !== undefined && supportsAdaptiveThinking(request.model))
485
+ return { type: "adaptive" };
486
+ })());
487
+ const additionalModelRequestFields = {
488
+ ...(generation?.topK === undefined ? {} : { top_k: generation.topK }),
489
+ ...(thinking === undefined ? {} : { thinking }),
490
+ ...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
491
+ // Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
492
+ ...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
493
+ };
414
494
  // Bedrock-Claude shares Anthropic's 4-breakpoint cap. Spend the budget in
415
495
  // tools → system → messages order to favour the highest-impact prefixes.
416
496
  const breakpoints = BedrockCache.breakpoints(request.model);
@@ -448,16 +528,33 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
448
528
  system,
449
529
  inferenceConfig,
450
530
  toolConfig,
451
- // Converse's base inferenceConfig has no topK or thinking; Anthropic/Nova accept them
531
+ // Converse's base inferenceConfig has no topK, thinking or effort; models accept them
452
532
  // as model-specific fields, so they go through additionalModelRequestFields.
453
- additionalModelRequestFields: generation?.topK === undefined && thinking === undefined
533
+ additionalModelRequestFields: Object.keys(additionalModelRequestFields).length === 0 ? undefined : additionalModelRequestFields,
534
+ serviceTier: options.serviceTier === undefined ? undefined : { type: options.serviceTier },
535
+ guardrailConfig: options.guardrail === undefined
454
536
  ? undefined
455
537
  : {
456
- ...(generation?.topK === undefined ? {} : { top_k: generation.topK }),
457
- ...(thinking === undefined ? {} : { thinking }),
458
- // Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
459
- ...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
538
+ guardrailIdentifier: options.guardrail.identifier,
539
+ guardrailVersion: options.guardrail.version,
540
+ trace: options.guardrail.trace,
541
+ streamProcessingMode: options.guardrail.streamProcessingMode,
542
+ },
543
+ outputConfig: options.outputFormat === undefined
544
+ ? undefined
545
+ : {
546
+ textFormat: {
547
+ type: options.outputFormat.type,
548
+ structure: {
549
+ jsonSchema: {
550
+ schema: ProviderShared.encodeJson(options.outputFormat.schema),
551
+ name: options.outputFormat.name,
552
+ description: options.outputFormat.description,
553
+ },
554
+ },
555
+ },
460
556
  },
557
+ requestMetadata: options.requestMetadata,
461
558
  };
462
559
  });
463
560
  // =============================================================================
@@ -94,6 +94,7 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
94
94
  export const framing = (route) => ({
95
95
  id: "aws-event-stream",
96
96
  body: (frame) => frame.rawBody,
97
+ raw: ({ rawBody: _, ...event }) => event,
97
98
  frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
98
99
  });
99
100
  export * as BedrockEventStream from "./bedrock-event-stream.js";
@@ -1462,6 +1462,9 @@ export declare const providerFailure: (event: Event, fallback: string, body?: st
1462
1462
  export declare const step: (state: ParserState, event: NormalizedEvent) => AIError | Effect.Effect<StepResult, never, never> | Effect.Effect<[ParserState, readonly ({
1463
1463
  readonly type: "step-start";
1464
1464
  readonly index: number;
1465
+ } | {
1466
+ readonly type: "raw";
1467
+ readonly data: unknown;
1465
1468
  } | {
1466
1469
  readonly type: "text-start";
1467
1470
  readonly id: string;
@@ -1453,6 +1453,9 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
1453
1453
  export declare const finishEvents: (state: ParserState) => Effect.Effect<({
1454
1454
  readonly type: "step-start";
1455
1455
  readonly index: number;
1456
+ } | {
1457
+ readonly type: "raw";
1458
+ readonly data: unknown;
1456
1459
  } | {
1457
1460
  readonly type: "text-start";
1458
1461
  readonly id: string;
@@ -132,8 +132,8 @@ export declare const route: Route<{
132
132
  readonly ttl?: string | undefined;
133
133
  } | undefined;
134
134
  readonly reasoning_effort?: import("../effect.js").ReasoningEffort | undefined;
135
- readonly verbosity?: import("../effect.js").OpenString<"high" | "low" | "medium"> | undefined;
136
- readonly service_tier?: import("../effect.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
135
+ readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
136
+ readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
137
137
  readonly parallel_tool_calls?: boolean | undefined;
138
138
  readonly metadata?: {
139
139
  readonly [x: string]: string;
@@ -166,15 +166,15 @@ export declare const route: Route<{
166
166
  } | undefined;
167
167
  readonly top_logprobs?: number | undefined;
168
168
  readonly truncation?: "auto" | "disabled" | undefined;
169
- readonly service_tier?: import("../effect.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
169
+ readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
170
170
  readonly prompt_cache_key?: string | undefined;
171
- readonly include?: readonly import("../effect.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
171
+ readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
172
172
  readonly reasoning?: {
173
173
  readonly effort?: import("../effect.js").ReasoningEffort | undefined;
174
174
  readonly summary?: "auto" | "concise" | "detailed" | undefined;
175
175
  } | undefined;
176
176
  readonly text?: {
177
- readonly verbosity?: import("../effect.js").OpenString<"high" | "low" | "medium"> | undefined;
177
+ readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
178
178
  } | undefined;
179
179
  readonly max_output_tokens?: number | undefined;
180
180
  readonly max_tool_calls?: number | undefined;
@@ -1,3 +1,8 @@
1
1
  import type { JsonSchema } from "../../schema/index.js";
2
+ export declare const SCHEMA_MAPS: Set<string>;
3
+ export declare const VALUES: Set<string>;
4
+ export declare const mapValues: (record: Record<string, unknown>, map: (value: unknown, key: string) => unknown) => {
5
+ [k: string]: unknown;
6
+ };
2
7
  export declare const normalize: (schema: JsonSchema) => JsonSchema;
3
8
  export * as GeminiJsonSchema from "./gemini-json-schema.js";
@@ -1,7 +1,7 @@
1
1
  import { isRecord } from "../../utils/record.js";
2
2
  // Gemini's `parametersJsonSchema` accepts standard JSON Schema, but rejects a few shapes that
3
3
  // published tool schemas commonly contain. Rewrite only those and send everything else unchanged.
4
- const SCHEMA_MAPS = new Set([
4
+ export const SCHEMA_MAPS = new Set([
5
5
  "properties",
6
6
  "patternProperties",
7
7
  "$defs",
@@ -9,8 +9,8 @@ const SCHEMA_MAPS = new Set([
9
9
  "dependentSchemas",
10
10
  "dependencies",
11
11
  ]);
12
- const VALUES = new Set(["const", "default", "enum", "examples", "dependentRequired"]);
13
- const mapValues = (record, map) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value, key)]));
12
+ export const VALUES = new Set(["const", "default", "enum", "examples", "dependentRequired"]);
13
+ export const mapValues = (record, map) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value, key)]));
14
14
  const normalizeNode = (schema) => {
15
15
  if (Array.isArray(schema))
16
16
  return schema.map(normalizeNode);
@@ -1,6 +1,7 @@
1
1
  import { ToolDefinition } from "../../schema/index.js";
2
2
  import { isRecord } from "../../utils/record.js";
3
3
  import { GeminiJsonSchema } from "./gemini-json-schema.js";
4
+ const { SCHEMA_MAPS, VALUES, mapValues } = GeminiJsonSchema;
4
5
  const tupleItemsSchema = (items) => {
5
6
  const projected = items.map(moonshotNode);
6
7
  if (projected.length === 0)
@@ -31,12 +32,21 @@ const moonshotNode = (schema) => {
31
32
  return Object.fromEntries([
32
33
  ...(type === undefined ? [] : [["type", type]]),
33
34
  ...Object.entries(schema).flatMap(([key, value]) => {
34
- if (key === "items" && Array.isArray(value))
35
- return [[key, tupleItemsSchema(value)]];
36
- if (key === "prefixItems") {
37
- if ("items" in schema)
35
+ if (VALUES.has(key))
36
+ return [[key, value]];
37
+ if (SCHEMA_MAPS.has(key) && isRecord(value))
38
+ return [[key, mapValues(value, moonshotNode)]];
39
+ if (key === "items") {
40
+ if (Array.isArray(schema.prefixItems))
38
41
  return [];
39
- return [["items", tupleItemsSchema(Array.isArray(value) ? value : [])]];
42
+ if (Array.isArray(value))
43
+ return [[key, tupleItemsSchema(value)]];
44
+ }
45
+ if (key === "prefixItems") {
46
+ if (!Array.isArray(value))
47
+ return "items" in schema ? [] : [["items", {}]];
48
+ const rest = isRecord(schema.items) ? [schema.items] : Array.isArray(schema.items) ? schema.items : [];
49
+ return [["items", tupleItemsSchema([...value, ...rest])]];
40
50
  }
41
51
  if (key === "unevaluatedItems")
42
52
  return [];
@@ -79,6 +79,9 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
79
79
  events: readonly ({
80
80
  readonly type: "step-start";
81
81
  readonly index: number;
82
+ } | {
83
+ readonly type: "raw";
84
+ readonly data: unknown;
82
85
  } | {
83
86
  readonly type: "text-start";
84
87
  readonly id: string;
@@ -306,6 +309,9 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
306
309
  events: readonly ({
307
310
  readonly type: "step-start";
308
311
  readonly index: number;
312
+ } | {
313
+ readonly type: "raw";
314
+ readonly data: unknown;
309
315
  } | {
310
316
  readonly type: "text-start";
311
317
  readonly id: string;
@@ -530,6 +536,9 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
530
536
  events: ({
531
537
  readonly type: "step-start";
532
538
  readonly index: number;
539
+ } | {
540
+ readonly type: "raw";
541
+ readonly data: unknown;
533
542
  } | {
534
543
  readonly type: "text-start";
535
544
  readonly id: string;
@@ -0,0 +1,2 @@
1
+ export { imageModel as model } from "../alibaba.js";
2
+ export type { Settings } from "../alibaba.js";
@@ -0,0 +1 @@
1
+ export { imageModel as model } from "../alibaba.js";
@@ -4,7 +4,7 @@ import { AlibabaMessages } from "../protocols/alibaba-messages.js";
4
4
  import { AlibabaResponses } from "../protocols/alibaba-responses.js";
5
5
  import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
6
6
  import { Route, type RouteDefaultsInput } from "../route/client.js";
7
- import { ToolDefinition, type ModelID } from "../schema/index.js";
7
+ import { ToolDefinition, type ModelID, type ProviderOptions } from "../schema/index.js";
8
8
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
9
9
  export type Region = "ap-southeast-1" | "cn-beijing" | "cn-hongkong" | "us-east-1" | "eu-central-1" | "ap-northeast-1" | (string & {});
10
10
  export type ChatOptionsInput = AlibabaChat.OptionsInput;
@@ -726,7 +726,7 @@ export declare const configure: (input: Config) => {
726
726
  readonly previousResponseId?: string | undefined;
727
727
  readonly conversation?: string | undefined;
728
728
  }, import("../route/client.js").CompactionOperations | undefined>;
729
- image: (id: string | ModelID) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
729
+ image: (id: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
730
730
  configure: typeof configure;
731
731
  };
732
732
  export declare const provider: {
@@ -736,6 +736,7 @@ export declare const provider: {
736
736
  export declare const model: ProviderPackage.Definition<Settings, ChatOptionsInput>["model"];
737
737
  export declare const messagesModel: ProviderPackage.Definition<Settings<MessagesOptionsInput>, MessagesOptionsInput>["model"];
738
738
  export declare const responsesModel: ProviderPackage.Definition<Settings<ResponsesOptionsInput>, ResponsesOptionsInput>["model"];
739
+ export declare const imageModel: (id: string, settings: Settings) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
739
740
  export declare const webSearch: () => ToolDefinition;
740
741
  export declare const webExtractor: () => ToolDefinition;
741
742
  export declare const codeInterpreter: () => ToolDefinition;
@@ -8,7 +8,7 @@ import { Route } from "../route/client.js";
8
8
  import { Endpoint } from "../route/endpoint.js";
9
9
  import { Framing } from "../route/framing.js";
10
10
  import { MediaRoute } from "../route/media.js";
11
- import { ProviderConfigurationError, ProviderID, ToolDefinition } from "../schema/index.js";
11
+ import { ProviderConfigurationError, ProviderID, ToolDefinition, } from "../schema/index.js";
12
12
  export const id = ProviderID.make("alibaba");
13
13
  const hosts = new Map([
14
14
  ["ap-southeast-1", "dashscope-intl.aliyuncs.com"],
@@ -69,20 +69,24 @@ export const configure = (input) => {
69
69
  .model({ id, compatibility: { requireSignature: false } });
70
70
  const responses = (id) => responsesRoute.with(common).model({ id });
71
71
  const media = MediaRoute.deployment({ ...input, baseURL: baseURL ?? `https://${host}/api/v1` }, opts.auth);
72
- const image = (id) => AlibabaImages.model({ ...media, id });
72
+ const image = (id, providerOptions) => AlibabaImages.model({ ...media, id, providerOptions });
73
73
  return { id, model: chat, chat, messages, responses, image, configure };
74
74
  };
75
75
  export const provider = { id, configure };
76
- export const model = (id, input) => fromSettings(input).chat(id);
77
- export const messagesModel = (id, input) => fromSettings(input).messages(id);
78
- export const responsesModel = (id, input) => fromSettings(input).responses(id);
79
- function fromSettings(input) {
76
+ export const model = (id, input) => configure(config(input)).chat(id);
77
+ export const messagesModel = (id, input) => configure(config(input)).messages(id);
78
+ export const responsesModel = (id, input) => configure(config(input)).responses(id);
79
+ export const imageModel = (id, settings) => {
80
+ const input = config(settings);
81
+ return configure(input).image(id, input.providerOptions);
82
+ };
83
+ function config(input) {
80
84
  const { body, ...rest } = input;
81
- return configure({
85
+ return {
82
86
  ...rest,
83
87
  http: body === undefined ? undefined : { body },
84
88
  providerOptions: Struct.omit(rest, ["apiKey", "baseURL", "headers", "region", "workspaceID"]),
85
- });
89
+ };
86
90
  }
87
91
  export const webSearch = () => hostedTool("web_search", "Search the web with Alibaba's hosted search tool.");
88
92
  export const webExtractor = () => hostedTool("web_extractor", "Extract web page content with Alibaba's hosted tool.");
@@ -18,8 +18,9 @@ export type Config = RouteDefaultsInput & {
18
18
  readonly region?: string;
19
19
  /** Override the computed `https://bedrock-runtime.<region>.amazonaws.com` URL. */
20
20
  readonly baseURL?: string;
21
+ readonly providerOptions?: BedrockConverse.OptionsInput;
21
22
  };
22
- export interface Settings extends ProviderPackage.Settings {
23
+ export type Settings = ProviderPackage.Settings & BedrockConverse.OptionsInput & {
23
24
  readonly apiKey?: string;
24
25
  readonly auth?: "bearer" | "sigv4";
25
26
  readonly baseURL?: string;
@@ -27,8 +28,7 @@ export interface Settings extends ProviderPackage.Settings {
27
28
  readonly profile?: string;
28
29
  readonly region?: string;
29
30
  readonly topP?: number;
30
- readonly thinking?: BedrockConverse.OptionsInput["thinking"];
31
- }
31
+ };
32
32
  export declare const routes: import("../route/client.js").Route<{
33
33
  readonly modelId: string;
34
34
  readonly messages: readonly ({
@@ -151,22 +151,42 @@ export declare const routes: import("../route/client.js").Route<{
151
151
  readonly additionalModelRequestFields?: {
152
152
  readonly [x: string]: unknown;
153
153
  } | undefined;
154
+ readonly serviceTier?: {
155
+ readonly type: import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">;
156
+ } | undefined;
157
+ readonly guardrailConfig?: {
158
+ readonly guardrailIdentifier: string;
159
+ readonly guardrailVersion: string;
160
+ readonly trace?: import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full"> | undefined;
161
+ readonly streamProcessingMode?: import("../schema/options.js").OpenString<"async" | "sync"> | undefined;
162
+ } | undefined;
163
+ readonly outputConfig?: {
164
+ readonly textFormat: {
165
+ readonly type: import("../schema/options.js").OpenString<"json_schema">;
166
+ readonly structure: {
167
+ readonly jsonSchema: {
168
+ readonly schema: string;
169
+ readonly name?: string | undefined;
170
+ readonly description?: string | undefined;
171
+ };
172
+ };
173
+ };
174
+ } | undefined;
175
+ readonly requestMetadata?: {
176
+ readonly [x: string]: string;
177
+ } | undefined;
154
178
  }, import("../route/transport/http.js").HttpPrepared<{
155
179
  readonly [x: string]: unknown;
156
180
  readonly rawBody: string;
157
181
  }>, import("../route/client.js").CompactionOperations | undefined>[];
158
182
  export declare const configure: (input?: Config) => {
159
183
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
160
- model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
161
- readonly [x: string]: unknown;
162
- }, import("../route/client.js").CompactionOperations | undefined>;
184
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<BedrockConverse.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
163
185
  configure: typeof configure;
164
186
  };
165
187
  export declare const provider: {
166
188
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
167
- model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
168
- readonly [x: string]: unknown;
169
- }, import("../route/client.js").CompactionOperations | undefined>;
189
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<BedrockConverse.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
170
190
  configure: typeof configure;
171
191
  };
172
- export declare const model: ProviderPackage.Definition<Settings>["model"];
192
+ export declare const model: ProviderPackage.Definition<Settings, BedrockConverse.OptionsInput>["model"];
@@ -28,15 +28,15 @@ export const configure = (input = {}) => {
28
28
  };
29
29
  };
30
30
  export const provider = configure();
31
- export const model = (modelID, settings) => configure({
32
- apiKey: settings.apiKey,
33
- auth: settings.auth,
34
- baseURL: settings.baseURL,
35
- credentials: settings.credentials,
36
- generation: settings.topP === undefined ? undefined : { topP: settings.topP },
37
- headers: settings.headers === undefined ? undefined : { ...settings.headers },
38
- http: settings.body === undefined ? undefined : { body: { ...settings.body } },
39
- providerOptions: settings.thinking === undefined ? undefined : { thinking: settings.thinking },
40
- profile: settings.profile,
41
- region: settings.region,
31
+ export const model = (modelID, { apiKey, auth, baseURL, credentials, profile, region, topP, headers, body, ...providerOptions }) => configure({
32
+ apiKey,
33
+ auth,
34
+ baseURL,
35
+ credentials,
36
+ generation: topP === undefined ? undefined : { topP },
37
+ headers: headers === undefined ? undefined : { ...headers },
38
+ http: body === undefined ? undefined : { body: { ...body } },
39
+ providerOptions,
40
+ profile,
41
+ region,
42
42
  }).model(modelID);
@@ -0,0 +1,2 @@
1
+ export { imageModel as model } from "../azure.js";
2
+ export type { Settings } from "../azure.js";
@@ -0,0 +1 @@
1
+ export { imageModel as model } from "../azure.js";
@@ -1,7 +1,7 @@
1
1
  import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
2
2
  import type { Route, RouteDefaultsInput, CompactionOperations } from "../route/client.js";
3
3
  import type { ProviderPackage } from "../provider-package.js";
4
- import { type ModelID } from "../schema/index.js";
4
+ import { type ModelID, type ProviderOptions } from "../schema/index.js";
5
5
  import { type OpenAIProviderOptionsInput } from "./openai-options.js";
6
6
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
7
  type AzureURL = AtLeastOne<{
@@ -602,6 +602,7 @@ export declare const configure: (input: Config) => {
602
602
  endpoint: import("../route/client.js").CompactOperation;
603
603
  }>;
604
604
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, CompactionOperations | undefined>;
605
+ image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
605
606
  configure: typeof configure;
606
607
  };
607
608
  export declare const provider: {
@@ -610,6 +611,7 @@ export declare const provider: {
610
611
  };
611
612
  export declare const responsesModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput, typeof responsesRoute.compact>["model"];
612
613
  export declare const chatModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
614
+ export declare const imageModel: (modelID: string, settings: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
613
615
  export declare const model: (modelID: string, settings: Settings) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, {
614
616
  endpoint: import("../route/client.js").CompactOperation;
615
617
  }>;
@@ -1,7 +1,9 @@
1
1
  import { Auth } from "../route/auth.js";
2
2
  import {} from "../route/auth-options.js";
3
3
  import { Endpoint } from "../route/endpoint.js";
4
- import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
4
+ import { MediaRoute } from "../route/media.js";
5
+ import { HttpOptions, ProviderConfigurationError, ProviderID, mergeHttpOptions, } from "../schema/index.js";
6
+ import { OpenAIImages } from "../protocols/openai-images.js";
5
7
  import * as OpenAIChat from "../protocols/openai-chat.js";
6
8
  import * as OpenAIResponses from "../protocols/openai-responses.js";
7
9
  import { withOpenAIOptions } from "./openai-options.js";
@@ -75,11 +77,23 @@ export const configure = (input) => {
75
77
  const chat = (modelID) => configuredRoute(chatRoute, input, modelID)
76
78
  .with(withOpenAIOptions(modelID, modelDefaults))
77
79
  .model({ id: modelID, compatibility: { supportsPromptCacheKey: true } });
80
+ const image = (modelID, providerOptions) => {
81
+ const target = endpoint(input, modelID);
82
+ const media = MediaRoute.deployment({ ...input, baseURL: target.baseURL }, auth(input));
83
+ return OpenAIImages.model({
84
+ ...media,
85
+ id: modelID,
86
+ provider: id,
87
+ providerOptions,
88
+ http: mergeHttpOptions(media.http, target.query === undefined ? undefined : new HttpOptions({ query: target.query })),
89
+ });
90
+ };
78
91
  return {
79
92
  id,
80
93
  model: responses,
81
94
  responses,
82
95
  chat,
96
+ image,
83
97
  configure,
84
98
  };
85
99
  };
@@ -105,4 +119,8 @@ const config = ({ apiKey, apiVersion, baseURL, body, headers, queryParams, resou
105
119
  };
106
120
  export const responsesModel = (modelID, settings) => configure(config(settings)).responses(modelID);
107
121
  export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
122
+ export const imageModel = (modelID, settings) => {
123
+ const input = config(settings);
124
+ return configure(input).image(modelID, input.providerOptions);
125
+ };
108
126
  export const model = responsesModel;
@@ -0,0 +1,2 @@
1
+ export { decisionModel as model } from "../baseten.js";
2
+ export type { Settings } from "../baseten.js";
@@ -0,0 +1 @@
1
+ export { decisionModel as model } from "../baseten.js";
@@ -1,7 +1,7 @@
1
1
  import type { ProviderPackage } from "../provider-package.js";
2
2
  import { type ProviderAuthOption } from "../route/auth-options.js";
3
3
  import { Route, type RouteDefaultsInput } from "../route/client.js";
4
- import { type ModelID } from "../schema/index.js";
4
+ import { type ModelID, type ProviderOptions } from "../schema/index.js";
5
5
  import type { OpenAIProviderOptionsInput } from "./openai-options.js";
6
6
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
7
  export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
@@ -305,15 +305,16 @@ export declare const routes: Route<{
305
305
  export declare const configure: (input?: LanguageModelOptions) => {
306
306
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
307
307
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
308
- decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
308
+ decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
309
309
  configure: typeof configure;
310
310
  };
311
311
  export declare const provider: {
312
312
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
313
313
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
314
- decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
314
+ decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
315
315
  configure: typeof configure;
316
316
  };
317
- export declare const decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
317
+ export declare const decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
318
318
  export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
319
+ export declare const decisionModel: (modelID: string, settings: Settings) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
319
320
  export * as Baseten from "./baseten.js";