@opencode/ai 0.0.0-dev-21463 → 0.0.0-dev-21474

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.
@@ -94,8 +94,9 @@ const markSystemBoundaries = (system, hint, budget) => {
94
94
  return changed ? next : system;
95
95
  };
96
96
  const lastIndexOfRole = (messages, role) => messages.findLastIndex((m) => m.role === role);
97
+ const isCacheablePart = (part) => part.type !== "compaction" && part.type !== "effort";
97
98
  // Mark the last text part of `messages[index]`. If no text part exists, mark
98
- // the last content part regardless of type — that's the breakpoint position
99
+ // the last cacheable content part — that's the breakpoint position
99
100
  // in tool-result-only messages too.
100
101
  const markMessageAt = (messages, index, hint, budget) => {
101
102
  if (index < 0 || index >= messages.length)
@@ -104,12 +105,12 @@ const markMessageAt = (messages, index, hint, budget) => {
104
105
  if (target.content.length === 0)
105
106
  return messages;
106
107
  const lastTextIndex = target.content.findLastIndex((part) => part.type === "text");
107
- const markAt = lastTextIndex >= 0 ? lastTextIndex : target.content.length - 1;
108
+ const markAt = lastTextIndex >= 0 ? lastTextIndex : target.content.findLastIndex(isCacheablePart);
108
109
  const existing = target.content[markAt];
109
- if (("cache" in existing && existing.cache) || budget.remaining === 0)
110
+ if (!existing || !isCacheablePart(existing) || existing.cache || budget.remaining === 0)
110
111
  return messages;
111
112
  budget.remaining -= 1;
112
- const nextContent = target.content.map((part, i) => (i === markAt ? { ...part, cache: hint } : part));
113
+ const nextContent = target.content.map((part, i) => (i === markAt ? { ...existing, cache: hint } : part));
113
114
  const next = new Message({ ...target, content: nextContent });
114
115
  // Single pass over `messages`, substituting the one updated entry. Long
115
116
  // conversations call this on every request, so avoid `.map()` here — its
@@ -141,7 +142,7 @@ const markMessages = (messages, strategy, hint, budget) => {
141
142
  const countHints = (request) => countToolHints(request.tools) +
142
143
  request.system.reduce((count, part) => count + (part.cache === undefined ? 0 : 1), 0) +
143
144
  request.messages.reduce((count, message) => count +
144
- message.content.reduce((contentCount, part) => contentCount + ("cache" in part && part.cache !== undefined ? 1 : 0), 0), 0);
145
+ message.content.reduce((contentCount, part) => contentCount + (isCacheablePart(part) && part.cache !== undefined ? 1 : 0), 0), 0);
145
146
  export const applyCachePolicy = (request) => {
146
147
  const policy = selectPolicy(request);
147
148
  if (!policy.tools && !policy.system && !policy.messages)
@@ -57,7 +57,9 @@ export declare const ImageClient: {
57
57
  } | undefined;
58
58
  } | import("./generation.js").Observation, import("./index.js").AIError, ImageClientService>;
59
59
  readonly start: (request: ImageRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./index.js").AIError, ImageClientService>;
60
- readonly resume: (model: import("./image.js").ImageModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./index.js").AIError, ImageClientService>;
60
+ readonly resume: (model: import("./image.js").ImageModel<{
61
+ readonly [x: string]: unknown;
62
+ }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./index.js").AIError, ImageClientService>;
61
63
  readonly Service: typeof ImageClientService;
62
64
  };
63
65
  export {};
package/dist/image.d.ts CHANGED
@@ -14,14 +14,22 @@ export declare class ImageModel<Options extends ImageOptions = ImageOptions> ext
14
14
  static fromRoute<Options extends ImageOptions, Frame, State>(route: MediaModel.StreamRouteInput<ImageRequestFor<Options>, ImageEvent, Frame, State>, input: MediaRoute.ModelInput): ImageModel<Options>;
15
15
  static fromRoute<Options extends ImageOptions, Token>(route: MediaModel.QueuedRouteInput<ImageRequestFor<Options>, ImageResponse, Token>, input: MediaRoute.ModelInput): ImageModel<Options>;
16
16
  }
17
- export declare const ImageModelSchema: Schema.declare<ImageModel<MediaModel.Options>, ImageModel<MediaModel.Options>>;
17
+ export declare const ImageModelSchema: Schema.declare<ImageModel<{
18
+ readonly [x: string]: unknown;
19
+ }>, ImageModel<{
20
+ readonly [x: string]: unknown;
21
+ }>>;
18
22
  export type ImageSize = `${number}x${number}`;
19
23
  export declare const ImageSize: Schema.declare<`${number}x${number}`, `${number}x${number}`>;
20
24
  export type ImageAspectRatio = Media.AspectRatio;
21
25
  export declare const ImageAspectRatio: Schema.declare<`${number}:${number}`, `${number}:${number}`>;
22
26
  export type ImageFormat = OpenString<"png" | "jpeg" | "webp">;
23
27
  declare const ImageRequest_base: Schema.Class<ImageRequest, Schema.Struct<{
24
- readonly model: Schema.declare<ImageModel<MediaModel.Options>, ImageModel<MediaModel.Options>>;
28
+ readonly model: Schema.declare<ImageModel<{
29
+ readonly [x: string]: unknown;
30
+ }>, ImageModel<{
31
+ readonly [x: string]: unknown;
32
+ }>>;
25
33
  readonly prompt: Schema.String;
26
34
  /** Edit sources or style/subject references, in order. */
27
35
  readonly images: Schema.optional<Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
package/dist/image.js CHANGED
@@ -3,7 +3,7 @@ import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
6
- import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
6
+ import { AIError, HttpOptions, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
7
7
  import { ImageClient, Service } from "./image-client.js";
8
8
  export class ImageModel extends MediaModel {
9
9
  static fromRoute(route, input) {
@@ -32,7 +32,7 @@ export class ImageRequest extends Schema.Class("Image.Request")({
32
32
  aspectRatio: Schema.optional(ImageAspectRatio),
33
33
  seed: Schema.optional(Schema.Number),
34
34
  format: Schema.optional(Schema.String),
35
- providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
35
+ providerOptions: Schema.optional(ProviderOptions),
36
36
  http: Schema.optional(HttpOptions),
37
37
  }) {
38
38
  }
@@ -2,7 +2,7 @@ import { Effect } from "effect";
2
2
  import { Endpoint } from "./route/endpoint.js";
3
3
  import { MediaRoute } from "./route/media.js";
4
4
  import type { MediaProtocol } from "./route/media-protocol.js";
5
- import { AIError, HttpOptions, ModelID, ProviderID } from "./schema/index.js";
5
+ import { AIError, HttpOptions, ModelID, ProviderID, type ProviderOptions } from "./schema/index.js";
6
6
  /**
7
7
  * What every media model carries: ids, the configured route, and deployment `http` overlays. Modality classes
8
8
  * (`ImageModel`, `VideoModel`, `SpeechModel`, `TranscriptionModel`) extend it with their route type and a nominal
@@ -17,7 +17,7 @@ export declare class MediaModel<Route, Options> {
17
17
  constructor(input: MediaModel.Input<Route>);
18
18
  }
19
19
  export declare namespace MediaModel {
20
- type Options = Record<string, unknown>;
20
+ type Options = ProviderOptions;
21
21
  interface Input<Route> {
22
22
  readonly id: string | ModelID;
23
23
  readonly provider: string | ProviderID;
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import { Endpoint } from "./route/endpoint.js";
3
3
  import { MediaRoute } from "./route/media.js";
4
- import { AIError, HttpOptions, InvalidRequestError, ModelID, ProviderID } from "./schema/index.js";
4
+ import { AIError, HttpOptions, InvalidRequestError, ModelID, ProviderID, } from "./schema/index.js";
5
5
  /**
6
6
  * What every media model carries: ids, the configured route, and deployment `http` overlays. Modality classes
7
7
  * (`ImageModel`, `VideoModel`, `SpeechModel`, `TranscriptionModel`) extend it with their route type and a nominal
@@ -60,7 +60,9 @@ export declare const SpeechClient: {
60
60
  } | undefined;
61
61
  } | import("./generation.js").Observation, import("./index.js").AIError, SpeechClientService>;
62
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>;
63
+ readonly resume: (model: import("./speech.js").SpeechModel<{
64
+ readonly [x: string]: unknown;
65
+ }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
64
66
  readonly Service: typeof SpeechClientService;
65
67
  };
66
68
  export {};
package/dist/speech.d.ts CHANGED
@@ -13,7 +13,11 @@ export declare class SpeechModel<Options extends SpeechOptions = SpeechOptions>
13
13
  static fromRoute<Options extends SpeechOptions, Frame, State>(route: MediaModel.StreamRouteInput<SpeechRequestFor<Options>, SpeechEvent, Frame, State>, input: MediaRoute.ModelInput): SpeechModel<Options>;
14
14
  static fromRoute<Options extends SpeechOptions, Token>(route: MediaModel.QueuedRouteInput<SpeechRequestFor<Options>, SpeechResponse, Token>, input: MediaRoute.ModelInput): SpeechModel<Options>;
15
15
  }
16
- export declare const SpeechModelSchema: Schema.declare<SpeechModel<MediaModel.Options>, SpeechModel<MediaModel.Options>>;
16
+ export declare const SpeechModelSchema: Schema.declare<SpeechModel<{
17
+ readonly [x: string]: unknown;
18
+ }>, SpeechModel<{
19
+ readonly [x: string]: unknown;
20
+ }>>;
17
21
  /** Provider-native: a name on OpenAI and Gemini, a voice id on ElevenLabs and Cartesia; `{ id }` is an OpenAI custom voice. */
18
22
  export declare const SpeechVoice: Schema.Union<readonly [Schema.String, Schema.Struct<{
19
23
  readonly id: Schema.String;
@@ -28,7 +32,11 @@ export declare const SpeechTimestamp: Schema.Struct<{
28
32
  }>;
29
33
  export type SpeechTimestamp = Schema.Schema.Type<typeof SpeechTimestamp>;
30
34
  declare const SpeechRequest_base: Schema.Class<SpeechRequest, Schema.Struct<{
31
- readonly model: Schema.declare<SpeechModel<MediaModel.Options>, SpeechModel<MediaModel.Options>>;
35
+ readonly model: Schema.declare<SpeechModel<{
36
+ readonly [x: string]: unknown;
37
+ }>, SpeechModel<{
38
+ readonly [x: string]: unknown;
39
+ }>>;
32
40
  readonly text: Schema.String;
33
41
  readonly voice: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Struct<{
34
42
  readonly id: Schema.String;
package/dist/speech.js CHANGED
@@ -3,7 +3,7 @@ import { ProgressEvent, QueuedEvent } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
6
- import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
6
+ import { AIError, HttpOptions, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
7
7
  import { SpeechClient, Service } from "./speech-client.js";
8
8
  export class SpeechModel extends MediaModel {
9
9
  static fromRoute(route, input) {
@@ -40,7 +40,7 @@ export class SpeechRequest extends Schema.Class("Speech.Request")({
40
40
  language: Schema.optional(Schema.String),
41
41
  instructions: Schema.optional(Schema.String),
42
42
  timestamps: Schema.optional(Schema.Boolean),
43
- providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
43
+ providerOptions: Schema.optional(ProviderOptions),
44
44
  http: Schema.optional(HttpOptions),
45
45
  }) {
46
46
  }
@@ -76,7 +76,9 @@ export declare const TranscriptionClient: {
76
76
  readonly type: "finish";
77
77
  } | import("./generation.js").Observation, import("./index.js").AIError, TranscriptionClientService>;
78
78
  readonly start: (request: TranscriptionRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./index.js").AIError, TranscriptionClientService>;
79
- readonly resume: (model: import("./transcription.js").TranscriptionModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./index.js").AIError, TranscriptionClientService>;
79
+ readonly resume: (model: import("./transcription.js").TranscriptionModel<{
80
+ readonly [x: string]: unknown;
81
+ }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./index.js").AIError, TranscriptionClientService>;
80
82
  readonly Service: typeof TranscriptionClientService;
81
83
  };
82
84
  export {};
@@ -14,11 +14,19 @@ export declare class TranscriptionModel<Options extends TranscriptionOptions = T
14
14
  static fromRoute<Options extends TranscriptionOptions, Frame, State>(route: MediaModel.StreamRouteInput<TranscriptionRequestFor<Options>, TranscriptionEvent, Frame, State>, input: MediaRoute.ModelInput): TranscriptionModel<Options>;
15
15
  static fromRoute<Options extends TranscriptionOptions, Token>(route: MediaModel.QueuedRouteInput<TranscriptionRequestFor<Options>, TranscriptionResponse, Token>, input: MediaRoute.ModelInput): TranscriptionModel<Options>;
16
16
  }
17
- export declare const TranscriptionModelSchema: Schema.declare<TranscriptionModel<MediaModel.Options>, TranscriptionModel<MediaModel.Options>>;
17
+ export declare const TranscriptionModelSchema: Schema.declare<TranscriptionModel<{
18
+ readonly [x: string]: unknown;
19
+ }>, TranscriptionModel<{
20
+ readonly [x: string]: unknown;
21
+ }>>;
18
22
  export declare const TranscriptionTimestamps: Schema.Literals<readonly ["none", "segment", "word"]>;
19
23
  export type TranscriptionTimestamps = Schema.Schema.Type<typeof TranscriptionTimestamps>;
20
24
  declare const TranscriptionRequest_base: Schema.Class<TranscriptionRequest, Schema.Struct<{
21
- readonly model: Schema.declare<TranscriptionModel<MediaModel.Options>, TranscriptionModel<MediaModel.Options>>;
25
+ readonly model: Schema.declare<TranscriptionModel<{
26
+ readonly [x: string]: unknown;
27
+ }>, TranscriptionModel<{
28
+ readonly [x: string]: unknown;
29
+ }>>;
22
30
  readonly audio: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
23
31
  readonly source: Schema.Union<readonly [Schema.Struct<{
24
32
  readonly type: Schema.Literal<"bytes">;
@@ -3,7 +3,7 @@ import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
6
- import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
6
+ import { AIError, HttpOptions, MediaUsage, ProviderMetadata, ProviderOptions } from "./schema/index.js";
7
7
  import { TranscriptionClient, Service } from "./transcription-client.js";
8
8
  export class TranscriptionModel extends MediaModel {
9
9
  static fromRoute(route, input) {
@@ -29,7 +29,7 @@ export class TranscriptionRequest extends Schema.Class("Transcription.Request")(
29
29
  timestamps: Schema.optional(TranscriptionTimestamps),
30
30
  diarize: Schema.optional(Schema.Boolean),
31
31
  speakers: Schema.optional(Schema.Int),
32
- providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
32
+ providerOptions: Schema.optional(ProviderOptions),
33
33
  http: Schema.optional(HttpOptions),
34
34
  }) {
35
35
  }
@@ -53,7 +53,9 @@ export declare const VideoClient: {
53
53
  } | undefined;
54
54
  } | import("./generation.js").Observation, import("./index.js").AIError, VideoClientService>;
55
55
  readonly start: (request: VideoRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./index.js").AIError, VideoClientService>;
56
- readonly resume: (model: import("./video.js").VideoModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./index.js").AIError, VideoClientService>;
56
+ readonly resume: (model: import("./video.js").VideoModel<{
57
+ readonly [x: string]: unknown;
58
+ }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./index.js").AIError, VideoClientService>;
57
59
  readonly Service: typeof VideoClientService;
58
60
  };
59
61
  export {};
package/dist/video.d.ts CHANGED
@@ -14,7 +14,11 @@ export declare class VideoModel<Options extends VideoOptions = VideoOptions> ext
14
14
  static fromRoute<Options extends VideoOptions, Frame, State>(route: MediaModel.StreamRouteInput<VideoRequestFor<Options>, VideoEvent, Frame, State>, input: MediaRoute.ModelInput): VideoModel<Options>;
15
15
  static fromRoute<Options extends VideoOptions, Token>(route: MediaModel.QueuedRouteInput<VideoRequestFor<Options>, VideoResponse, Token>, input: MediaRoute.ModelInput): VideoModel<Options>;
16
16
  }
17
- export declare const VideoModelSchema: Schema.declare<VideoModel<MediaModel.Options>, VideoModel<MediaModel.Options>>;
17
+ export declare const VideoModelSchema: Schema.declare<VideoModel<{
18
+ readonly [x: string]: unknown;
19
+ }>, VideoModel<{
20
+ readonly [x: string]: unknown;
21
+ }>>;
18
22
  export type VideoAspectRatio = Media.AspectRatio;
19
23
  export declare const VideoAspectRatio: Schema.declare<`${number}:${number}`, `${number}:${number}`>;
20
24
  export type VideoResolution = OpenString<"480p" | "720p" | "1080p" | "4k">;
@@ -85,7 +89,11 @@ export declare const VideoFrames: Schema.Struct<{
85
89
  }>;
86
90
  export type VideoFrames = Schema.Schema.Type<typeof VideoFrames>;
87
91
  declare const VideoRequest_base: Schema.Class<VideoRequest, Schema.Struct<{
88
- readonly model: Schema.declare<VideoModel<MediaModel.Options>, VideoModel<MediaModel.Options>>;
92
+ readonly model: Schema.declare<VideoModel<{
93
+ readonly [x: string]: unknown;
94
+ }>, VideoModel<{
95
+ readonly [x: string]: unknown;
96
+ }>>;
89
97
  readonly prompt: Schema.String;
90
98
  readonly frames: Schema.optional<Schema.Struct<{
91
99
  readonly first: Schema.optional<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
package/dist/video.js CHANGED
@@ -3,7 +3,7 @@ import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
6
- import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
6
+ import { AIError, HttpOptions, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
7
7
  import { VideoClient, Service } from "./video-client.js";
8
8
  export class VideoModel extends MediaModel {
9
9
  static fromRoute(route, input) {
@@ -40,7 +40,7 @@ export class VideoRequest extends Schema.Class("Video.Request")({
40
40
  n: Schema.optional(Schema.Int),
41
41
  seed: Schema.optional(Schema.Number),
42
42
  negativePrompt: Schema.optional(Schema.String),
43
- providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
43
+ providerOptions: Schema.optional(ProviderOptions),
44
44
  http: Schema.optional(HttpOptions),
45
45
  }) {
46
46
  }
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-21463",
3
+ "version": "0.0.0-dev-21474",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@clack/prompts": "1.0.0-alpha.1",
36
36
  "@effect/platform-node": "4.0.1",
37
- "@opencode/http-recorder": "0.0.0-dev-21463",
37
+ "@opencode/http-recorder": "0.0.0-dev-21474",
38
38
  "@tsconfig/bun": "1.0.9",
39
39
  "@types/bun": "1.4.0",
40
40
  "@typescript/native": "npm:typescript@7.0.2",
@@ -44,7 +44,7 @@
44
44
  "@aws-sdk/credential-providers": "3.1057.0",
45
45
  "@smithy/eventstream-codec": "4.2.14",
46
46
  "@smithy/util-utf8": "4.2.2",
47
- "@opencode/schema": "0.0.0-dev-21463",
47
+ "@opencode/schema": "0.0.0-dev-21474",
48
48
  "aws4fetch": "1.0.20",
49
49
  "effect": "4.0.1",
50
50
  "google-auth-library": "10.5.0"