Files
cline-multi-mirror/src/shared/ExtensionMessage.ts
T
Bee a50200aba1 feat: Support compact system prompt for LM studio models and token usage tracking (#5720)
* Add compact system prompt for local models

- Introduce compact system prompt for local models (lm studio, ollama)
- Add ApiProviderInfo { modelId, providerId } to API
- Persist promptType in global state and propagate to webview
  (updateSettings, state keys/helpers, ExtensionMessage, UI context)
- Wire provider info through task pipeline to buildSystemPrompt

* isLocalModelFamily

* Add custom prompt support and LM Studio API improvements

* Enable token usage tracking in LM Studio stream responses

This change adds the stream_options parameter with include_usage: true to LM Studio API requests, allowing the system to receive token usage information along with streaming responses. This enables better tracking of token consumption for LM Studio model interactions.

* update compact system prompt

* feat: Support compact system prompt for LM studio models and token usage tracking

* clean up

* Update UI helper text
2025-08-22 11:32:19 -07:00

222 lines
5.7 KiB
TypeScript

// type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or 'settingsButtonClicked' or 'hello'
import { AutoApprovalSettings } from "./AutoApprovalSettings"
import { ApiConfiguration } from "./api"
import { BrowserSettings } from "./BrowserSettings"
import { ClineRulesToggles } from "./cline-rules"
import { FocusChainSettings } from "./FocusChainSettings"
import { HistoryItem } from "./HistoryItem"
import { McpDisplayMode } from "./McpDisplayMode"
import { Mode, OpenaiReasoningEffort } from "./storage/types"
import { TelemetrySetting } from "./TelemetrySetting"
import { UserInfo } from "./UserInfo"
// webview will hold state
export interface ExtensionMessage {
type: "grpc_response" // New type for gRPC responses
grpc_response?: GrpcResponse
}
export type GrpcResponse = {
message?: any // JSON serialized protobuf message
request_id: string // Same ID as the request
error?: string // Optional error message
is_streaming?: boolean // Whether this is part of a streaming response
sequence_number?: number // For ordering chunks in streaming responses
}
export type Platform = "aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32" | "unknown"
export const DEFAULT_PLATFORM = "unknown"
export interface ExtensionState {
isNewUser: boolean
welcomeViewCompleted: boolean
apiConfiguration?: ApiConfiguration
autoApprovalSettings: AutoApprovalSettings
browserSettings: BrowserSettings
remoteBrowserHost?: string
preferredLanguage?: string
openaiReasoningEffort?: OpenaiReasoningEffort
mode: Mode
checkpointTrackerErrorMessage?: string
clineMessages: ClineMessage[]
currentTaskItem?: HistoryItem
currentFocusChainChecklist?: string | null
mcpMarketplaceEnabled?: boolean
mcpDisplayMode: McpDisplayMode
planActSeparateModelsSetting: boolean
enableCheckpointsSetting?: boolean
platform: Platform
shouldShowAnnouncement: boolean
taskHistory: HistoryItem[]
telemetrySetting: TelemetrySetting
shellIntegrationTimeout: number
terminalReuseEnabled?: boolean
terminalOutputLineLimit: number
defaultTerminalProfile?: string
uriScheme?: string
userInfo?: UserInfo
version: string
distinctId: string
globalClineRulesToggles: ClineRulesToggles
localClineRulesToggles: ClineRulesToggles
localWorkflowToggles: ClineRulesToggles
globalWorkflowToggles: ClineRulesToggles
localCursorRulesToggles: ClineRulesToggles
localWindsurfRulesToggles: ClineRulesToggles
mcpResponsesCollapsed?: boolean
strictPlanModeEnabled?: boolean
useAutoCondense?: boolean
focusChainSettings: FocusChainSettings
focusChainFeatureFlagEnabled?: boolean
customPrompt?: string
}
export interface ClineMessage {
ts: number
type: "ask" | "say"
ask?: ClineAsk
say?: ClineSay
text?: string
reasoning?: string
images?: string[]
files?: string[]
partial?: boolean
lastCheckpointHash?: string
isCheckpointCheckedOut?: boolean
isOperationOutsideWorkspace?: boolean
conversationHistoryIndex?: number
conversationHistoryDeletedRange?: [number, number] // for when conversation history is truncated for API requests
}
export type ClineAsk =
| "followup"
| "plan_mode_respond"
| "command"
| "command_output"
| "completion_result"
| "tool"
| "api_req_failed"
| "resume_task"
| "resume_completed_task"
| "mistake_limit_reached"
| "auto_approval_max_req_reached"
| "browser_action_launch"
| "use_mcp_server"
| "new_task"
| "condense"
| "summarize_task"
| "report_bug"
export type ClineSay =
| "task"
| "error"
| "api_req_started"
| "api_req_finished"
| "text"
| "reasoning"
| "completion_result"
| "user_feedback"
| "user_feedback_diff"
| "api_req_retried"
| "command"
| "command_output"
| "tool"
| "shell_integration_warning"
| "browser_action_launch"
| "browser_action"
| "browser_action_result"
| "mcp_server_request_started"
| "mcp_server_response"
| "mcp_notification"
| "use_mcp_server"
| "diff_error"
| "deleted_api_reqs"
| "clineignore_error"
| "checkpoint_created"
| "load_mcp_documentation"
| "info" // Added for general informational messages like retry status
| "task_progress"
export interface ClineSayTool {
tool:
| "editedExistingFile"
| "newFileCreated"
| "readFile"
| "listFilesTopLevel"
| "listFilesRecursive"
| "listCodeDefinitionNames"
| "searchFiles"
| "webFetch"
| "summarizeTask"
path?: string
diff?: string
content?: string
regex?: string
filePattern?: string
operationIsLocatedInWorkspace?: boolean
}
// must keep in sync with system prompt
export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
export type BrowserAction = (typeof browserActions)[number]
export interface ClineSayBrowserAction {
action: BrowserAction
coordinate?: string
text?: string
}
export type BrowserActionResult = {
screenshot?: string
logs?: string
currentUrl?: string
currentMousePosition?: string
}
export interface ClineAskUseMcpServer {
serverName: string
type: "use_mcp_tool" | "access_mcp_resource"
toolName?: string
arguments?: string
uri?: string
}
export interface ClinePlanModeResponse {
response: string
options?: string[]
selected?: string
}
export interface ClineAskQuestion {
question: string
options?: string[]
selected?: string
}
export interface ClineAskNewTask {
context: string
}
export interface ClineApiReqInfo {
request?: string
tokensIn?: number
tokensOut?: number
cacheWrites?: number
cacheReads?: number
cost?: number
cancelReason?: ClineApiReqCancelReason
streamingFailedMessage?: string
retryStatus?: {
attempt: number
maxAttempts: number
delaySec: number
errorSnippet?: string
}
}
export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled" | "retries_exhausted"
export const COMPLETION_RESULT_CHANGES_FLAG = "HAS_CHANGES"