@cline/shared 0.0.74 → 0.0.75-nightly.1787107092

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,8 @@ 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";
6
+ import type { ModelTool, ModelToolName } from "./model-tools";
5
7
  import type { ModelReasoningOption, ReasoningEffort } from "./reasoning-options";
6
8
  export type JsonValue = string | number | boolean | null | JsonValue[] | {
7
9
  [key: string]: JsonValue | undefined;
@@ -14,6 +16,12 @@ export type GatewayPromptCacheFormat = "anthropic-cache-control" | "bedrock-cach
14
16
  export type GatewayReasoningFormat = "anthropic-thinking" | "glm-thinking" | "minimax-thinking";
15
17
  export type GatewayModelRoute = {
16
18
  matcher: "anthropic-compatible";
19
+ } | {
20
+ matcher: "model-operation";
21
+ operation: ModelOperation;
22
+ } | {
23
+ matcher: "model-output-modality";
24
+ modality: ModelModality;
17
25
  } | {
18
26
  matcher: "model-family";
19
27
  family: string;
@@ -23,6 +31,27 @@ export type GatewayModelRoute = {
23
31
  modelId: string;
24
32
  requiredCapability?: GatewayModelCapability;
25
33
  };
34
+ /**
35
+ * A provider-executed model tool exposed for matching models.
36
+ *
37
+ * Omitted `routes` means the tool is supported by every model on the provider.
38
+ * Exclusion routes take precedence so mixed transports such as Vertex can
39
+ * disable a tool for one model family while retaining a provider-level default.
40
+ */
41
+ export interface GatewayModelToolCapability {
42
+ name: ModelToolName;
43
+ routes?: readonly GatewayModelRoute[];
44
+ excludeRoutes?: readonly GatewayModelRoute[];
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
+ }
26
55
  export interface GatewayProviderRouting {
27
56
  promptCache?: {
28
57
  format: GatewayPromptCacheFormat;
@@ -49,6 +78,19 @@ export interface GatewayProviderMetadata {
49
78
  usageCostDisplay?: GatewayUsageCostDisplay;
50
79
  routing?: GatewayProviderRouting;
51
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";
52
94
  configFields?: readonly ProviderConfigField[];
53
95
  [key: string]: JsonValue | GatewayProviderRouting | GatewayStickySessionMetadata | readonly ProviderConfigField[] | undefined;
54
96
  }
@@ -60,6 +102,9 @@ export interface GatewayModelDefinition {
60
102
  contextWindow?: number;
61
103
  maxInputTokens?: number;
62
104
  maxOutputTokens?: number;
105
+ operation?: ModelOperation;
106
+ operationModes?: readonly ModelOperationMode[];
107
+ modalities?: ModelModalities;
63
108
  capabilities?: readonly GatewayModelCapability[];
64
109
  reasoningOptions?: readonly ModelReasoningOption[];
65
110
  metadata?: Record<string, JsonValue | undefined>;
@@ -70,6 +115,8 @@ export interface GatewayProviderManifest {
70
115
  description?: string;
71
116
  defaultModelId: string;
72
117
  models: readonly GatewayModelDefinition[];
118
+ modelOperationCapabilities?: readonly GatewayModelOperationCapability[];
119
+ modelToolCapabilities?: readonly GatewayModelToolCapability[];
73
120
  capabilities?: readonly ProviderCapability[];
74
121
  env?: readonly ("browser" | "node")[];
75
122
  api?: string;
@@ -119,6 +166,8 @@ export interface GatewayStreamRequest {
119
166
  systemPrompt?: string;
120
167
  messages: readonly AgentMessage[];
121
168
  tools?: readonly AgentToolDefinition[];
169
+ /** Provider-executed tools requested independently of runtime tools. */
170
+ modelTools?: readonly ModelTool[];
122
171
  temperature?: number;
123
172
  maxTokens?: number;
124
173
  /**
@@ -149,6 +198,7 @@ export interface GatewayProviderRegistration {
149
198
  }
150
199
  export interface GatewayModelHandleOptions {
151
200
  tools?: readonly AgentToolDefinition[];
201
+ modelTools?: readonly ModelTool[];
152
202
  temperature?: number;
153
203
  maxTokens?: number;
154
204
  metadata?: Record<string, unknown>;
@@ -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,95 @@ 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
+ /**
88
+ * Provider operation used to execute a model request.
89
+ *
90
+ * Modalities describe the values a model accepts and produces; they do not
91
+ * identify the provider endpoint. Keeping the operation explicit prevents an
92
+ * image-output model from being routed to a generic chat or compatible-image
93
+ * endpoint merely because its catalog advertises an image modality.
94
+ */
95
+ export declare const ModelOperationSchema: z.ZodEnum<{
96
+ language: "language";
97
+ "image-generation": "image-generation";
98
+ "speech-generation": "speech-generation";
99
+ "video-generation": "video-generation";
100
+ transcription: "transcription";
101
+ }>;
102
+ export type ModelOperation = z.infer<typeof ModelOperationSchema>;
103
+ /**
104
+ * Execution modes supported by a non-language model operation.
105
+ *
106
+ * The operation selects the provider transport; the mode describes how that
107
+ * transport is consumed. Keeping this separate from generic model
108
+ * capabilities prevents transcription-specific flags from spreading through
109
+ * otherwise modality-agnostic clients.
110
+ */
111
+ export declare const ModelOperationModeSchema: z.ZodEnum<{
112
+ streaming: "streaming";
113
+ batch: "batch";
114
+ }>;
115
+ export type ModelOperationMode = z.infer<typeof ModelOperationModeSchema>;
116
+ interface ImageOutputModelDescriptor {
117
+ operation?: ModelOperation;
118
+ modalities?: ModelModalities;
119
+ }
120
+ export declare function modelProducesImages(model: ImageOutputModelDescriptor): boolean;
121
+ export declare function usesImageGenerationOperation(model: ImageOutputModelDescriptor): boolean;
122
+ /**
123
+ * Whether a model's capability metadata declares `capability`.
124
+ *
125
+ * Capability lists reach this check from sources of very different fidelity:
126
+ * the generated catalog is complete, but host boundaries (VS Code's legacy
127
+ * ModelInfo, user-authored overrides, dynamic provider listings) may carry
128
+ * partial lists reconstructed from a handful of boolean flags. A missing or
129
+ * empty list therefore carries no signal, and each check declares its own
130
+ * default via `assumeWhenUnspecified` instead of treating absence as denial.
131
+ *
132
+ * Capability gates added by future model modes (audio, video, transcription,
133
+ * …) should route through this helper rather than reading
134
+ * `model.capabilities` directly, so the unspecified-list semantics stay
135
+ * consistent across the codebase.
136
+ */
137
+ export declare function modelHasCapability(model: {
138
+ capabilities?: readonly string[];
139
+ }, capability: string, options?: {
140
+ assumeWhenUnspecified?: boolean;
141
+ }): boolean;
142
+ /**
143
+ * Whether a model can receive function/tool definitions. Fails open when the
144
+ * capability list is missing or empty (user-entered and dynamically
145
+ * discovered models); a populated capability list without `tools` is
146
+ * authoritative.
147
+ */
148
+ export declare function modelSupportsToolCalling(model: {
149
+ capabilities?: readonly string[];
150
+ }): boolean;
62
151
  export declare const ModelInfoSchema: z.ZodObject<{
63
152
  id: z.ZodString;
64
153
  name: z.ZodOptional<z.ZodString>;
@@ -67,8 +156,8 @@ export declare const ModelInfoSchema: z.ZodObject<{
67
156
  contextWindow: z.ZodOptional<z.ZodNumber>;
68
157
  maxInputTokens: z.ZodOptional<z.ZodNumber>;
69
158
  capabilities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
70
- images: "images";
71
159
  video: "video";
160
+ images: "images";
72
161
  tools: "tools";
73
162
  streaming: "streaming";
74
163
  "prompt-cache": "prompt-cache";
@@ -80,11 +169,39 @@ export declare const ModelInfoSchema: z.ZodObject<{
80
169
  temperature: "temperature";
81
170
  files: "files";
82
171
  }>>>;
172
+ operation: z.ZodOptional<z.ZodEnum<{
173
+ language: "language";
174
+ "image-generation": "image-generation";
175
+ "speech-generation": "speech-generation";
176
+ "video-generation": "video-generation";
177
+ transcription: "transcription";
178
+ }>>;
179
+ operationModes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
180
+ streaming: "streaming";
181
+ batch: "batch";
182
+ }>>>;
183
+ modalities: z.ZodOptional<z.ZodObject<{
184
+ input: z.ZodArray<z.ZodEnum<{
185
+ image: "image";
186
+ audio: "audio";
187
+ video: "video";
188
+ text: "text";
189
+ pdf: "pdf";
190
+ }>>;
191
+ output: z.ZodArray<z.ZodEnum<{
192
+ image: "image";
193
+ audio: "audio";
194
+ video: "video";
195
+ text: "text";
196
+ pdf: "pdf";
197
+ }>>;
198
+ }, z.core.$strip>>;
83
199
  reasoningOptions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
84
200
  type: z.ZodLiteral<"toggle">;
85
201
  }, z.core.$strict>, z.ZodObject<{
86
202
  type: z.ZodLiteral<"effort">;
87
203
  values: z.ZodArray<z.ZodNullable<z.ZodEnum<{
204
+ default: "default";
88
205
  none: "none";
89
206
  minimal: "minimal";
90
207
  low: "low";
@@ -92,7 +209,6 @@ export declare const ModelInfoSchema: z.ZodObject<{
92
209
  high: "high";
93
210
  xhigh: "xhigh";
94
211
  max: "max";
95
- default: "default";
96
212
  }>>>;
97
213
  }, z.core.$strict>, z.ZodObject<{
98
214
  type: z.ZodLiteral<"budget_tokens">;
@@ -139,3 +255,4 @@ export declare const ModelInfoSchema: z.ZodObject<{
139
255
  }, z.core.$catchall<z.ZodUnknown>>>;
140
256
  }, z.core.$strip>;
141
257
  export type ModelInfo = z.infer<typeof ModelInfoSchema>;
258
+ export {};
@@ -0,0 +1,30 @@
1
+ /** Provider-executed tools requested from the selected language model. */
2
+ export declare const MODEL_TOOL_NAMES: readonly ["web_search", "image_generation"];
3
+ export declare const CONFIGURABLE_MODEL_TOOL_NAMES: readonly ["web_search"];
4
+ export type ModelToolName = (typeof MODEL_TOOL_NAMES)[number];
5
+ export type ConfigurableModelToolName = (typeof CONFIGURABLE_MODEL_TOOL_NAMES)[number];
6
+ export interface WebSearchModelTool {
7
+ name: "web_search";
8
+ maxUses?: number;
9
+ allowedDomains?: string[];
10
+ blockedDomains?: string[];
11
+ userLocation?: {
12
+ country?: string;
13
+ region?: string;
14
+ city?: string;
15
+ timezone?: string;
16
+ };
17
+ }
18
+ export interface ImageGenerationModelTool {
19
+ name: "image_generation";
20
+ outputFormat?: "png" | "jpeg" | "webp";
21
+ }
22
+ /**
23
+ * A tool executed by the model provider as part of inference. Unlike an
24
+ * AgentTool, it has no local executor or approval lifecycle.
25
+ */
26
+ export type ModelTool = WebSearchModelTool | ImageGenerationModelTool;
27
+ export interface ModelToolSetting {
28
+ enabled: boolean;
29
+ }
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">;
@@ -22,6 +22,8 @@ export interface ToolCallRecord {
22
22
  id: string;
23
23
  /** Name of the tool that was called */
24
24
  name: string;
25
+ /** Absent for ordinary AgentRuntime-executed tools. */
26
+ execution?: "client" | "provider";
25
27
  /** Input passed to the tool */
26
28
  input: unknown;
27
29
  /** Output returned from the tool (if successful) */
@@ -77,6 +79,10 @@ export interface ToolApprovalResult {
77
79
  export declare const ToolCallRecordSchema: z.ZodObject<{
78
80
  id: z.ZodString;
79
81
  name: z.ZodString;
82
+ execution: z.ZodOptional<z.ZodEnum<{
83
+ client: "client";
84
+ provider: "provider";
85
+ }>>;
80
86
  input: z.ZodUnknown;
81
87
  output: z.ZodUnknown;
82
88
  error: z.ZodOptional<z.ZodString>;