@@ -20,11 +20,18 @@ import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
2020import { findLast } from "../../shared/array"
2121import { ApiConfigMeta , ExtensionMessage } from "../../shared/ExtensionMessage"
2222import { HistoryItem } from "../../shared/HistoryItem"
23- import { checkoutDiffPayloadSchema , checkoutRestorePayloadSchema , WebviewMessage } from "../../shared/WebviewMessage"
23+ import {
24+ checkoutDiffPayloadSchema ,
25+ checkoutRestorePayloadSchema ,
26+ researchTaskPayloadSchema ,
27+ researchInputPayloadSchema ,
28+ WebviewMessage ,
29+ } from "../../shared/WebviewMessage"
2430import { Mode , CustomModePrompts , PromptComponent , defaultModeSlug } from "../../shared/modes"
2531import { SYSTEM_PROMPT } from "../prompts/system"
2632import { fileExistsAtPath } from "../../utils/fs"
2733import { Cline } from "../Cline"
34+ import { DeepResearchService } from "../../services/deep-research/DeepResearchService"
2835import { openMention } from "../mentions"
2936import { getNonce } from "./getNonce"
3037import { getUri } from "./getUri"
@@ -60,6 +67,8 @@ type SecretKey =
6067 | "mistralApiKey"
6168 | "unboundApiKey"
6269 | "requestyApiKey"
70+ | "firecrawlApiKey"
71+
6372type GlobalStateKey =
6473 | "apiProvider"
6574 | "apiModelId"
@@ -148,6 +157,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
148157 private view ?: vscode . WebviewView | vscode . WebviewPanel
149158 private isViewLaunched = false
150159 private cline ?: Cline
160+ private deepResearchService ?: DeepResearchService
151161 private workspaceTracker ?: WorkspaceTracker
152162 protected mcpHub ?: McpHub // Change from private to protected
153163 private latestAnnouncementId = "jan-21-2025-custom-modes" // update to some unique identifier when we add a new announcement
@@ -1529,6 +1539,82 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15291539 await this . updateGlobalState ( "mode" , defaultModeSlug )
15301540 await this . postStateToWebview ( )
15311541 }
1542+ break
1543+ case "research.task" : {
1544+ const result = researchTaskPayloadSchema . safeParse ( message . payload )
1545+
1546+ if ( ! result . success ) {
1547+ console . warn (
1548+ `[ClineProvider#research.task] Invalid payload: ${ JSON . stringify ( message . payload ) } ` ,
1549+ )
1550+ break
1551+ }
1552+
1553+ if ( result . success && ! this . deepResearchService ) {
1554+ const { session } = result . data
1555+ this . deepResearchService = new DeepResearchService ( session , this )
1556+ await this . deepResearchService . input ( session . query )
1557+ }
1558+
1559+ break
1560+ }
1561+ case "research.input" : {
1562+ const result = researchInputPayloadSchema . safeParse ( message . payload )
1563+
1564+ if ( ! result . success ) {
1565+ console . warn (
1566+ `[ClineProvider#research.input] Invalid payload: ${ JSON . stringify ( message . payload ) } ` ,
1567+ )
1568+ break
1569+ }
1570+
1571+ if ( result . success && this . deepResearchService ) {
1572+ const { content } = result . data . message
1573+ this . deepResearchService . input ( content )
1574+ }
1575+
1576+ break
1577+ }
1578+ case "research.viewReport" :
1579+ await this . deepResearchService ?. viewReport ( )
1580+ break
1581+ case "research.createTask" :
1582+ await this . deepResearchService ?. createTask ( )
1583+ break
1584+ case "research.getTasks" :
1585+ const tasks = await DeepResearchService . getTasks ( this . context . globalStorageUri . fsPath )
1586+
1587+ await this . postMessageToWebview ( {
1588+ type : "research.history" ,
1589+ text : JSON . stringify (
1590+ tasks
1591+ . sort ( ( a , b ) => b . createdAt - a . createdAt )
1592+ . map ( ( task ) => ( {
1593+ taskId : task . taskId ,
1594+ query : task . inquiry . initialQuery ,
1595+ createdAt : task . createdAt ,
1596+ } ) ) ,
1597+ ) ,
1598+ } )
1599+
1600+ break
1601+ case "research.getTask" :
1602+ if ( message . text ) {
1603+ const task = await DeepResearchService . getTask (
1604+ this . context . globalStorageUri . fsPath ,
1605+ message . text ,
1606+ )
1607+ await this . postMessageToWebview ( { type : "research.task" , text : JSON . stringify ( task ) } )
1608+ }
1609+
1610+ break
1611+ case "research.abort" :
1612+ await this . deepResearchService ?. abort ( )
1613+ break
1614+ case "research.reset" :
1615+ await this . deepResearchService ?. abort ( )
1616+ this . deepResearchService = undefined
1617+ break
15321618 }
15331619 } ,
15341620 null ,
@@ -1676,6 +1762,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
16761762 requestyModelId,
16771763 requestyModelInfo,
16781764 modelTemperature,
1765+ firecrawlApiKey,
16791766 } = apiConfiguration
16801767 await Promise . all ( [
16811768 this . updateGlobalState ( "apiProvider" , apiProvider ) ,
@@ -1723,6 +1810,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
17231810 this . updateGlobalState ( "requestyModelId" , requestyModelId ) ,
17241811 this . updateGlobalState ( "requestyModelInfo" , requestyModelInfo ) ,
17251812 this . updateGlobalState ( "modelTemperature" , modelTemperature ) ,
1813+ this . storeSecret ( "firecrawlApiKey" , firecrawlApiKey ) ,
17261814 ] )
17271815 if ( this . cline ) {
17281816 this . cline . api = buildApiHandler ( apiConfiguration )
@@ -2606,6 +2694,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
26062694 requestyModelInfo ,
26072695 modelTemperature ,
26082696 maxOpenTabsContext ,
2697+ firecrawlApiKey ,
26092698 ] = await Promise . all ( [
26102699 this . getGlobalState ( "apiProvider" ) as Promise < ApiProvider | undefined > ,
26112700 this . getGlobalState ( "apiModelId" ) as Promise < string | undefined > ,
@@ -2688,6 +2777,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
26882777 this . getGlobalState ( "requestyModelInfo" ) as Promise < ModelInfo | undefined > ,
26892778 this . getGlobalState ( "modelTemperature" ) as Promise < number | undefined > ,
26902779 this . getGlobalState ( "maxOpenTabsContext" ) as Promise < number | undefined > ,
2780+ this . getSecret ( "firecrawlApiKey" ) as Promise < string | undefined > ,
26912781 ] )
26922782
26932783 let apiProvider : ApiProvider
@@ -2751,6 +2841,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
27512841 requestyModelId,
27522842 requestyModelInfo,
27532843 modelTemperature,
2844+ firecrawlApiKey,
27542845 } ,
27552846 lastShownAnnouncementId,
27562847 customInstructions,
@@ -2908,6 +2999,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
29082999 "mistralApiKey" ,
29093000 "unboundApiKey" ,
29103001 "requestyApiKey" ,
3002+ "firecrawlApiKey" ,
29113003 ]
29123004 for ( const key of secretKeys ) {
29133005 await this . storeSecret ( key , undefined )
0 commit comments