@cline/shared 0.0.75 → 0.0.76

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.
@@ -1,4 +1,4 @@
1
- import { type MediaBudgetState } from "./media";
1
+ import { type GeneratedMedia, type MediaBudgetState } from "./media";
2
2
  /**
3
3
  * Sanitizes unpaired/lone Unicode surrogates in text content.
4
4
  *
@@ -24,6 +24,9 @@ export type AiSdkFormatterPart = {
24
24
  type: "image";
25
25
  image: string | Uint8Array | ArrayBuffer | URL;
26
26
  mediaType?: string;
27
+ } | {
28
+ type: "media";
29
+ media: GeneratedMedia;
27
30
  } | {
28
31
  type: "file";
29
32
  path: string;
@@ -64,5 +67,5 @@ export declare function formatMessagesForAiSdk(systemContent: string | AiSdkMess
64
67
  * Defaults to true. The substitution happens here at request-build
65
68
  * time only — stored conversation history is never mutated.
66
69
  */
67
- supportsImages?: boolean;
70
+ supportedInputModalities?: readonly string[];
68
71
  }): AiSdkMessage[];
@@ -2,6 +2,7 @@ import type { AgentMessage, AgentModelEvent, AgentToolDefinition } from "../agen
2
2
  import type { BasicLogger } from "../logging/logger";
3
3
  import type { ProviderCapability, ProviderConfigField } from "../rpc/runtime";
4
4
  import type { ITelemetryService } from "../services/telemetry";
5
+ import type { ModelModalities, ModelModality, ModelOperation, ModelOperationMode } from "./model-info";
5
6
  import type { ModelTool, ModelToolName } from "./model-tools";
6
7
  import type { ModelReasoningOption, ReasoningEffort } from "./reasoning-options";
7
8
  export type JsonValue = string | number | boolean | null | JsonValue[] | {
@@ -15,6 +16,12 @@ export type GatewayPromptCacheFormat = "anthropic-cache-control" | "bedrock-cach
15
16
  export type GatewayReasoningFormat = "anthropic-thinking" | "glm-thinking" | "minimax-thinking";
16
17
  export type GatewayModelRoute = {
17
18
  matcher: "anthropic-compatible";
19
+ } | {
20
+ matcher: "model-operation";
21
+ operation: ModelOperation;
22
+ } | {
23
+ matcher: "model-output-modality";
24
+ modality: ModelModality;
18
25
  } | {
19
26
  matcher: "model-family";
20
27
  family: string;
@@ -36,6 +43,15 @@ export interface GatewayModelToolCapability {
36
43
  routes?: readonly GatewayModelRoute[];
37
44
  excludeRoutes?: readonly GatewayModelRoute[];
38
45
  }
46
+ /** A provider transport capable of executing a matching model operation. */
47
+ export interface GatewayModelOperationCapability {
48
+ operation: ModelOperation;
49
+ modes?: readonly ModelOperationMode[];
50
+ inputModalities?: readonly ModelModality[];
51
+ outputModalities?: readonly ModelModality[];
52
+ routes?: readonly GatewayModelRoute[];
53
+ excludeRoutes?: readonly GatewayModelRoute[];
54
+ }
39
55
  export interface GatewayProviderRouting {
40
56
  promptCache?: {
41
57
  format: GatewayPromptCacheFormat;
@@ -62,6 +78,19 @@ export interface GatewayProviderMetadata {
62
78
  usageCostDisplay?: GatewayUsageCostDisplay;
63
79
  routing?: GatewayProviderRouting;
64
80
  stickySession?: GatewayStickySessionMetadata;
81
+ /**
82
+ * Provider-specific transport used for models whose output includes images.
83
+ * OpenRouter-compatible image responses require a richer schema than the
84
+ * generic OpenAI-compatible adapter exposes.
85
+ */
86
+ imageTransport?: "openrouter";
87
+ /** Provider-owned implementation used for the transcription operation. */
88
+ transcriptionTransport?: "openai-compatible" | "vercel-ai-gateway" | "elevenlabs";
89
+ /**
90
+ * Successful JSON responses are wrapped by the provider before reaching
91
+ * the protocol adapter. `success-data` represents `{ success, data }`.
92
+ */
93
+ responseEnvelope?: "success-data";
65
94
  configFields?: readonly ProviderConfigField[];
66
95
  [key: string]: JsonValue | GatewayProviderRouting | GatewayStickySessionMetadata | readonly ProviderConfigField[] | undefined;
67
96
  }
@@ -73,6 +102,9 @@ export interface GatewayModelDefinition {
73
102
  contextWindow?: number;
74
103
  maxInputTokens?: number;
75
104
  maxOutputTokens?: number;
105
+ operation?: ModelOperation;
106
+ operationModes?: readonly ModelOperationMode[];
107
+ modalities?: ModelModalities;
76
108
  capabilities?: readonly GatewayModelCapability[];
77
109
  reasoningOptions?: readonly ModelReasoningOption[];
78
110
  metadata?: Record<string, JsonValue | undefined>;
@@ -83,6 +115,7 @@ export interface GatewayProviderManifest {
83
115
  description?: string;
84
116
  defaultModelId: string;
85
117
  models: readonly GatewayModelDefinition[];
118
+ modelOperationCapabilities?: readonly GatewayModelOperationCapability[];
86
119
  modelToolCapabilities?: readonly GatewayModelToolCapability[];
87
120
  capabilities?: readonly ProviderCapability[];
88
121
  env?: readonly ("browser" | "node")[];
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  export declare const IMAGE_OMITTED_PLACEHOLDER = "[media omitted: invalid or exceeds size limit]";
2
3
  /**
3
4
  * Substituted for image content at request-build time when the target model
@@ -5,6 +6,50 @@ export declare const IMAGE_OMITTED_PLACEHOLDER = "[media omitted: invalid or exc
5
6
  * real image, so switching to an image-capable model restores it.
6
7
  */
7
8
  export declare const IMAGE_UNSUPPORTED_PLACEHOLDER = "[Image attached \u2014 this model cannot view images]";
9
+ export declare const GeneratedMediaModalitySchema: z.ZodEnum<{
10
+ image: "image";
11
+ audio: "audio";
12
+ video: "video";
13
+ file: "file";
14
+ }>;
15
+ export type GeneratedMediaModality = z.infer<typeof GeneratedMediaModalitySchema>;
16
+ export declare const GeneratedMediaSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
17
+ type: z.ZodLiteral<"base64">;
18
+ data: z.ZodString;
19
+ }, z.core.$strip>, z.ZodObject<{
20
+ type: z.ZodLiteral<"url">;
21
+ url: z.ZodString;
22
+ }, z.core.$strip>, z.ZodObject<{
23
+ type: z.ZodLiteral<"artifact">;
24
+ artifactId: z.ZodString;
25
+ }, z.core.$strip>], "type">;
26
+ export type GeneratedMediaSource = z.infer<typeof GeneratedMediaSourceSchema>;
27
+ /** Canonical model-generated media, shared by streaming and persistence. */
28
+ export declare const GeneratedMediaSchema: z.ZodObject<{
29
+ id: z.ZodString;
30
+ modality: z.ZodEnum<{
31
+ image: "image";
32
+ audio: "audio";
33
+ video: "video";
34
+ file: "file";
35
+ }>;
36
+ mediaType: z.ZodString;
37
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
38
+ type: z.ZodLiteral<"base64">;
39
+ data: z.ZodString;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ type: z.ZodLiteral<"url">;
42
+ url: z.ZodString;
43
+ }, z.core.$strip>, z.ZodObject<{
44
+ type: z.ZodLiteral<"artifact">;
45
+ artifactId: z.ZodString;
46
+ }, z.core.$strip>], "type">;
47
+ name: z.ZodOptional<z.ZodString>;
48
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
49
+ }, z.core.$strip>;
50
+ export type GeneratedMedia = z.infer<typeof GeneratedMediaSchema>;
51
+ export declare function isGeneratedMedia(value: unknown): value is GeneratedMedia;
52
+ export declare function generatedMediaModalityFromMediaType(mediaType: string): GeneratedMediaModality;
8
53
  export declare const SUPPORTED_IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
9
54
  export declare const DEFAULT_MAX_IMAGE_BASE64_BYTES: number;
10
55
  export declare const DEFAULT_MAX_IMAGE_ENCODED_BYTES: number;
@@ -44,6 +89,18 @@ export interface MediaBudgetState {
44
89
  omittedImages: number;
45
90
  omittedReasons: Partial<Record<ImageMediaValidationFailure["reason"], number>>;
46
91
  }
92
+ export interface Base64MediaValidationSuccess {
93
+ ok: true;
94
+ base64: string;
95
+ encodedBytes: number;
96
+ decodedBytes: number;
97
+ }
98
+ export interface Base64MediaValidationFailure {
99
+ ok: false;
100
+ reason: "invalid_base64" | "total_limit";
101
+ message: string;
102
+ }
103
+ export type Base64MediaValidationResult = Base64MediaValidationSuccess | Base64MediaValidationFailure;
47
104
  export declare function imageBase64EncodedByteLength(base64: string): number;
48
105
  export declare function imageBase64DecodedByteLength(base64: string): number;
49
106
  export declare function imageFileMaxDecodedBytesForBase64Limit(maxBase64Bytes?: number): number;
@@ -53,5 +110,7 @@ export declare function createMediaBudgetState(): MediaBudgetState;
53
110
  export declare function reserveImageMediaBytes(encodedBytes: number, decodedBytes: number, budget: MediaBudgetOptions, state: MediaBudgetState): ImageMediaValidationFailure | null;
54
111
  export declare function isBase64Char(charCode: number): boolean;
55
112
  export declare function isCanonicalBase64(base64: string): boolean;
113
+ /** Validate and reserve an arbitrary inline media payload against the turn budget. */
114
+ export declare function validateAndReserveBase64Media(data: string, budget: MediaBudgetOptions, state: MediaBudgetState): Base64MediaValidationResult;
56
115
  export declare function validateImageMedia(mediaType: string | undefined, data: string, limits?: ImageMediaLimits): ImageMediaValidationResult;
57
116
  export declare function validateAndReserveImageMedia(mediaType: string | undefined, data: string, budget: MediaBudgetOptions, state: MediaBudgetState): ImageMediaValidationResult;
@@ -5,6 +5,7 @@
5
5
  * This is a simplified, provider-agnostic format that can be
6
6
  * converted to any provider's native format.
7
7
  */
8
+ import type { GeneratedMedia } from "./media";
8
9
  /**
9
10
  * Message roles
10
11
  */
@@ -38,6 +39,11 @@ export interface ImageContent {
38
39
  /** MIME type (e.g., "image/png", "image/jpeg") */
39
40
  mediaType: string;
40
41
  }
42
+ /** Model-generated binary media preserved independently of textual files. */
43
+ export interface MediaContent {
44
+ type: "media";
45
+ media: GeneratedMedia;
46
+ }
41
47
  /**
42
48
  * Tool use content block (assistant's tool call)
43
49
  */
@@ -97,7 +103,7 @@ export interface RedactedThinkingContent {
97
103
  /**
98
104
  * Union of all content block types
99
105
  */
100
- export type ContentBlock = TextContent | ImageContent | ToolUseContent | ToolResultContent | ThinkingContent | FileContent | RedactedThinkingContent;
106
+ export type ContentBlock = TextContent | ImageContent | MediaContent | ToolUseContent | ToolResultContent | ThinkingContent | FileContent | RedactedThinkingContent;
101
107
  /**
102
108
  * A single message in the conversation
103
109
  */
@@ -18,8 +18,8 @@ export declare const ApiFormat: {
18
18
  readonly R1: "r1";
19
19
  };
20
20
  export declare const ModelCapabilitySchema: z.ZodEnum<{
21
- images: "images";
22
21
  video: "video";
22
+ images: "images";
23
23
  tools: "tools";
24
24
  streaming: "streaming";
25
25
  "prompt-cache": "prompt-cache";
@@ -59,6 +59,120 @@ export declare const ModelMetadataSchema: z.ZodObject<{
59
59
  reasoningDefaultOn: z.ZodOptional<z.ZodBoolean>;
60
60
  }, z.core.$catchall<z.ZodUnknown>>;
61
61
  export type ModelMetadata = z.infer<typeof ModelMetadataSchema>;
62
+ export declare const ModelModalitySchema: z.ZodEnum<{
63
+ image: "image";
64
+ audio: "audio";
65
+ video: "video";
66
+ text: "text";
67
+ pdf: "pdf";
68
+ }>;
69
+ export type ModelModality = z.infer<typeof ModelModalitySchema>;
70
+ export declare const ModelModalitiesSchema: z.ZodObject<{
71
+ input: z.ZodArray<z.ZodEnum<{
72
+ image: "image";
73
+ audio: "audio";
74
+ video: "video";
75
+ text: "text";
76
+ pdf: "pdf";
77
+ }>>;
78
+ output: z.ZodArray<z.ZodEnum<{
79
+ image: "image";
80
+ audio: "audio";
81
+ video: "video";
82
+ text: "text";
83
+ pdf: "pdf";
84
+ }>>;
85
+ }, z.core.$strip>;
86
+ export type ModelModalities = z.infer<typeof ModelModalitiesSchema>;
87
+ export type ChatModelModalities = {
88
+ readonly input?: readonly ModelModality[];
89
+ readonly output?: readonly ModelModality[];
90
+ };
91
+ /**
92
+ * Returns whether a model can participate in a text chat turn.
93
+ *
94
+ * Missing modality metadata is treated as chat-compatible for backwards
95
+ * compatibility. When a catalog does provide modalities, the model must both
96
+ * accept text and produce text; dedicated transcription and media-generation
97
+ * endpoints therefore stay available in the shared catalog without leaking
98
+ * into chat model pickers.
99
+ */
100
+ export declare function supportsChatModalities(modalities: ChatModelModalities | undefined): boolean;
101
+ /**
102
+ * Provider operation used to execute a model request.
103
+ *
104
+ * Modalities describe the values a model accepts and produces; they do not
105
+ * identify the provider endpoint. Keeping the operation explicit prevents an
106
+ * image-output model from being routed to a generic chat or compatible-image
107
+ * endpoint merely because its catalog advertises an image modality.
108
+ */
109
+ export declare const ModelOperationSchema: z.ZodEnum<{
110
+ language: "language";
111
+ "image-generation": "image-generation";
112
+ "speech-generation": "speech-generation";
113
+ "video-generation": "video-generation";
114
+ transcription: "transcription";
115
+ }>;
116
+ export type ModelOperation = z.infer<typeof ModelOperationSchema>;
117
+ export type ChatCompatibleModelDescriptor = {
118
+ readonly operation?: ModelOperation;
119
+ readonly modalities?: ChatModelModalities;
120
+ };
121
+ /**
122
+ * Returns whether a model uses the language operation and supports a text chat
123
+ * turn. Missing operation and modality metadata remain chat-compatible for
124
+ * backwards compatibility, while any explicitly non-language operation is
125
+ * excluded even when its modalities are absent.
126
+ */
127
+ export declare function isChatCompatibleModel(model: ChatCompatibleModelDescriptor): boolean;
128
+ /**
129
+ * Execution modes supported by a non-language model operation.
130
+ *
131
+ * The operation selects the provider transport; the mode describes how that
132
+ * transport is consumed. Keeping this separate from generic model
133
+ * capabilities prevents transcription-specific flags from spreading through
134
+ * otherwise modality-agnostic clients.
135
+ */
136
+ export declare const ModelOperationModeSchema: z.ZodEnum<{
137
+ streaming: "streaming";
138
+ batch: "batch";
139
+ }>;
140
+ export type ModelOperationMode = z.infer<typeof ModelOperationModeSchema>;
141
+ interface ImageOutputModelDescriptor {
142
+ operation?: ModelOperation;
143
+ modalities?: ModelModalities;
144
+ }
145
+ export declare function modelProducesImages(model: ImageOutputModelDescriptor): boolean;
146
+ export declare function usesImageGenerationOperation(model: ImageOutputModelDescriptor): boolean;
147
+ /**
148
+ * Whether a model's capability metadata declares `capability`.
149
+ *
150
+ * Capability lists reach this check from sources of very different fidelity:
151
+ * the generated catalog is complete, but host boundaries (VS Code's legacy
152
+ * ModelInfo, user-authored overrides, dynamic provider listings) may carry
153
+ * partial lists reconstructed from a handful of boolean flags. A missing or
154
+ * empty list therefore carries no signal, and each check declares its own
155
+ * default via `assumeWhenUnspecified` instead of treating absence as denial.
156
+ *
157
+ * Capability gates added by future model modes (audio, video, transcription,
158
+ * …) should route through this helper rather than reading
159
+ * `model.capabilities` directly, so the unspecified-list semantics stay
160
+ * consistent across the codebase.
161
+ */
162
+ export declare function modelHasCapability(model: {
163
+ capabilities?: readonly string[];
164
+ }, capability: string, options?: {
165
+ assumeWhenUnspecified?: boolean;
166
+ }): boolean;
167
+ /**
168
+ * Whether a model can receive function/tool definitions. Fails open when the
169
+ * capability list is missing or empty (user-entered and dynamically
170
+ * discovered models); a populated capability list without `tools` is
171
+ * authoritative.
172
+ */
173
+ export declare function modelSupportsToolCalling(model: {
174
+ capabilities?: readonly string[];
175
+ }): boolean;
62
176
  export declare const ModelInfoSchema: z.ZodObject<{
63
177
  id: z.ZodString;
64
178
  name: z.ZodOptional<z.ZodString>;
@@ -67,8 +181,8 @@ export declare const ModelInfoSchema: z.ZodObject<{
67
181
  contextWindow: z.ZodOptional<z.ZodNumber>;
68
182
  maxInputTokens: z.ZodOptional<z.ZodNumber>;
69
183
  capabilities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
70
- images: "images";
71
184
  video: "video";
185
+ images: "images";
72
186
  tools: "tools";
73
187
  streaming: "streaming";
74
188
  "prompt-cache": "prompt-cache";
@@ -80,11 +194,39 @@ export declare const ModelInfoSchema: z.ZodObject<{
80
194
  temperature: "temperature";
81
195
  files: "files";
82
196
  }>>>;
197
+ operation: z.ZodOptional<z.ZodEnum<{
198
+ language: "language";
199
+ "image-generation": "image-generation";
200
+ "speech-generation": "speech-generation";
201
+ "video-generation": "video-generation";
202
+ transcription: "transcription";
203
+ }>>;
204
+ operationModes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
205
+ streaming: "streaming";
206
+ batch: "batch";
207
+ }>>>;
208
+ modalities: z.ZodOptional<z.ZodObject<{
209
+ input: z.ZodArray<z.ZodEnum<{
210
+ image: "image";
211
+ audio: "audio";
212
+ video: "video";
213
+ text: "text";
214
+ pdf: "pdf";
215
+ }>>;
216
+ output: z.ZodArray<z.ZodEnum<{
217
+ image: "image";
218
+ audio: "audio";
219
+ video: "video";
220
+ text: "text";
221
+ pdf: "pdf";
222
+ }>>;
223
+ }, z.core.$strip>>;
83
224
  reasoningOptions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
84
225
  type: z.ZodLiteral<"toggle">;
85
226
  }, z.core.$strict>, z.ZodObject<{
86
227
  type: z.ZodLiteral<"effort">;
87
228
  values: z.ZodArray<z.ZodNullable<z.ZodEnum<{
229
+ default: "default";
88
230
  none: "none";
89
231
  minimal: "minimal";
90
232
  low: "low";
@@ -92,7 +234,6 @@ export declare const ModelInfoSchema: z.ZodObject<{
92
234
  high: "high";
93
235
  xhigh: "xhigh";
94
236
  max: "max";
95
- default: "default";
96
237
  }>>>;
97
238
  }, z.core.$strict>, z.ZodObject<{
98
239
  type: z.ZodLiteral<"budget_tokens">;
@@ -139,3 +280,4 @@ export declare const ModelInfoSchema: z.ZodObject<{
139
280
  }, z.core.$catchall<z.ZodUnknown>>>;
140
281
  }, z.core.$strip>;
141
282
  export type ModelInfo = z.infer<typeof ModelInfoSchema>;
283
+ export {};
@@ -1,6 +1,8 @@
1
1
  /** Provider-executed tools requested from the selected language model. */
2
- export declare const MODEL_TOOL_NAMES: readonly ["web_search"];
2
+ export declare const MODEL_TOOL_NAMES: readonly ["web_search", "image_generation"];
3
+ export declare const CONFIGURABLE_MODEL_TOOL_NAMES: readonly ["web_search"];
3
4
  export type ModelToolName = (typeof MODEL_TOOL_NAMES)[number];
5
+ export type ConfigurableModelToolName = (typeof CONFIGURABLE_MODEL_TOOL_NAMES)[number];
4
6
  export interface WebSearchModelTool {
5
7
  name: "web_search";
6
8
  maxUses?: number;
@@ -13,12 +15,16 @@ export interface WebSearchModelTool {
13
15
  timezone?: string;
14
16
  };
15
17
  }
18
+ export interface ImageGenerationModelTool {
19
+ name: "image_generation";
20
+ outputFormat?: "png" | "jpeg" | "webp";
21
+ }
16
22
  /**
17
23
  * A tool executed by the model provider as part of inference. Unlike an
18
24
  * AgentTool, it has no local executor or approval lifecycle.
19
25
  */
20
- export type ModelTool = WebSearchModelTool;
26
+ export type ModelTool = WebSearchModelTool | ImageGenerationModelTool;
21
27
  export interface ModelToolSetting {
22
28
  enabled: boolean;
23
29
  }
24
- export type ModelToolSettings = Partial<Record<ModelToolName, ModelToolSetting>>;
30
+ export type ModelToolSettings = Partial<Record<ConfigurableModelToolName, ModelToolSetting>>;
@@ -24,6 +24,7 @@ export declare const ModelReasoningOptionSchema: z.ZodDiscriminatedUnion<[z.ZodO
24
24
  }, z.core.$strict>, z.ZodObject<{
25
25
  type: z.ZodLiteral<"effort">;
26
26
  values: z.ZodArray<z.ZodNullable<z.ZodEnum<{
27
+ default: "default";
27
28
  none: "none";
28
29
  minimal: "minimal";
29
30
  low: "low";
@@ -31,7 +32,6 @@ export declare const ModelReasoningOptionSchema: z.ZodDiscriminatedUnion<[z.ZodO
31
32
  high: "high";
32
33
  xhigh: "xhigh";
33
34
  max: "max";
34
- default: "default";
35
35
  }>>>;
36
36
  }, z.core.$strict>, z.ZodObject<{
37
37
  type: z.ZodLiteral<"budget_tokens">;