From a80022795ea3a04262bc6b550b15d60c0dd9adc2 Mon Sep 17 00:00:00 2001 From: pashpashpash Date: Sun, 30 Mar 2025 05:57:26 -0700 Subject: [PATCH] adding task id to request headers (#2555) * adding task id to request headers * changeset --- .changeset/silent-sheep-nail.md | 5 +++++ src/api/providers/cline.ts | 5 +++++ src/core/Cline.ts | 18 +++++++++++++++--- src/shared/api.ts | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .changeset/silent-sheep-nail.md diff --git a/.changeset/silent-sheep-nail.md b/.changeset/silent-sheep-nail.md new file mode 100644 index 0000000000..20599e0d00 --- /dev/null +++ b/.changeset/silent-sheep-nail.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +adding task id to request headers diff --git a/src/api/providers/cline.ts b/src/api/providers/cline.ts index d93e0bad96..23064eb1ce 100644 --- a/src/api/providers/cline.ts +++ b/src/api/providers/cline.ts @@ -17,6 +17,11 @@ export class ClineHandler implements ApiHandler { this.client = new OpenAI({ baseURL: "https://api.cline.bot/v1", apiKey: this.options.clineApiKey || "", + defaultHeaders: { + "HTTP-Referer": "https://cline.bot", // Optional, for including your app on cline.bot rankings. + "X-Title": "Cline", // Optional. Shows in rankings on cline.bot. + "X-Task-ID": this.options.taskId || "", // Include the task ID in the request headers + }, }) } diff --git a/src/core/Cline.ts b/src/core/Cline.ts index d95de767ff..5f4f757c0b 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -142,7 +142,6 @@ export class Cline { }) this.providerRef = new WeakRef(provider) this.apiProvider = apiConfiguration.apiProvider - this.api = buildApiHandler(apiConfiguration) this.terminalManager = new TerminalManager() this.urlContentFetcher = new UrlContentFetcher(provider.context) this.browserSession = new BrowserSession(provider.context, browserSettings) @@ -152,17 +151,30 @@ export class Cline { this.autoApprovalSettings = autoApprovalSettings this.browserSettings = browserSettings this.chatSettings = chatSettings + + // Initialize taskId first if (historyItem) { this.taskId = historyItem.id this.conversationHistoryDeletedRange = historyItem.conversationHistoryDeletedRange - this.resumeTaskFromHistory() } else if (task || images) { this.taskId = Date.now().toString() - this.startTask(task, images) } else { throw new Error("Either historyItem or task/images must be provided") } + // Now that taskId is initialized, we can build the API handler + this.api = buildApiHandler({ + ...apiConfiguration, + taskId: this.taskId, + }) + + // Continue with task initialization + if (historyItem) { + this.resumeTaskFromHistory() + } else if (task || images) { + this.startTask(task, images) + } + if (historyItem) { // Open task from history telemetryService.captureTaskRestarted(this.taskId, this.apiProvider) diff --git a/src/shared/api.ts b/src/shared/api.ts index 76c71b94f4..ecf529ff56 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -24,6 +24,7 @@ export interface ApiHandlerOptions { apiModelId?: string apiKey?: string // anthropic clineApiKey?: string + taskId?: string // Used to identify the task in API requests liteLlmBaseUrl?: string liteLlmModelId?: string liteLlmApiKey?: string