Skip to content

Commit

Permalink
clean up & apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix committed Jan 7, 2025
1 parent b8a4a35 commit 321da9a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions vscode/src/chat/agentic/CodyToolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ class ToolFactory {
return Array.from(this.tools.entries())
.filter(([name]) => name !== 'CliTool' || toolboxManager.getSettings()?.shell?.enabled)
.map(([_, config]) => config.createInstance(config, this.contextRetriever))
.filter(isDefined) as CodyTool[]
.filter(isDefined)
}

public createDefaultTools(contextRetriever?: Retriever): CodyTool[] {
return Object.entries(TOOL_CONFIGS)
.map(([name]) => this.createTool(name, contextRetriever))
.filter(isDefined) as CodyTool[]
.filter(isDefined)
}

public createOpenCtxTools(providers: ContextMentionProviderMetadata[]): CodyTool[] {
Expand All @@ -103,7 +103,7 @@ class ToolFactory {
})
return this.createTool(toolName)
})
.filter(Boolean) as CodyTool[]
.filter(isDefined)
}

private generateToolName(provider: ContextMentionProviderMetadata): string {
Expand Down
24 changes: 18 additions & 6 deletions vscode/src/chat/agentic/DeepCody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import { ACTIONS_TAGS, CODYAGENT_PROMPTS } from './prompts'
*/
export class DeepCodyAgent {
public static readonly id = 'deep-cody'
/**
* NOTE: Currently A/B test to default to 3.5 Haiku / 3.5 Sonnet for the review step.
*/
public static model: string | undefined = undefined

protected readonly multiplexer = new BotResponseMultiplexer()
Expand Down Expand Up @@ -217,7 +220,14 @@ export class DeepCodyAgent {
if (chatAbortSignal.aborted) return []
return await tool.run(span, this.statusCallback)
} catch (error) {
this.statusCallback.onComplete(tool.config.tags.tag.toString(), error as Error)
const errorMessage =
error instanceof Error
? error.message
: typeof error === 'object' && error !== null
? JSON.stringify(error)
: String(error)
const errorObject = error instanceof Error ? error : new Error(errorMessage)
this.statusCallback.onComplete(tool.config.tags.tag.toString(), errorObject)
return []
}
})
Expand Down Expand Up @@ -279,17 +289,18 @@ export class DeepCodyAgent {
accumulated.append(newText)
await this.multiplexer.publish(newText)
}

if (msg.type === 'complete' || msg.type === 'error') {
if (msg.type === 'error') throw new Error('Error while streaming')
if (msg.type === 'complete') {
break
}
if (msg.type === 'error') {
throw msg.error
}
}
} finally {
await this.multiplexer.notifyTurnComplete()
}

return accumulated.toString()
return accumulated.consumeAndClear()
}

protected getPrompter(items: ContextItem[]): DefaultPrompter {
Expand All @@ -313,7 +324,8 @@ export class RawTextProcessor {
this.parts.push(str)
}

public toString(): string {
// Destructive read that clears state
public consumeAndClear(): string {
const joined = this.parts.join('')
this.reset()
return joined
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/chat/chat-view/ChatsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
handleCodeFromInsertAtCursor,
handleCodeFromSaveToNewFile,
} from '../../services/utils/codeblock-action-tracker'
import { CodyToolProvider } from '../agentic/CodyToolProvider'
import type { ChatIntentAPIClient } from '../context/chatIntentAPIClient'
import type { SmartApplyResult } from '../protocol'
import {
Expand Down Expand Up @@ -579,6 +580,7 @@ export class ChatsController implements vscode.Disposable {

public dispose(): void {
this.disposeAllChats()
CodyToolProvider.dispose()
vscode.Disposable.from(...this.disposables).dispose()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export const AddContextButton: FunctionComponent<{
}> = ({ onClick, className }) => (
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" onClick={onClick} aria-label="Add context" className={className}>
<Button
variant="ghost"
size="none"
onClick={onClick}
aria-label="Add context"
className={className}
>
<AtSignIcon className="tw-w-8 tw-h-8" strokeWidth={1.25} />
</Button>
</TooltipTrigger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useTelemetryRecorder } from '../../../../../../utils/telemetry'
interface ToolboxButtonProps {
api: WebviewToExtensionAPI
settings: AgentToolboxSettings
className?: string
}

const ToolboxOptionText = {
Expand Down Expand Up @@ -44,7 +43,7 @@ export const ToolboxButton: FC<ToolboxButtonProps> = memo(({ settings, api }) =>
const onSubmit = useCallback(
(close: () => void) => {
setIsLoading(true)
api.updateToolboxSettings(settingsForm).subscribe({
const subscription = api.updateToolboxSettings(settingsForm).subscribe({
next: () => {
setIsLoading(false)
close()
Expand All @@ -54,7 +53,13 @@ export const ToolboxButton: FC<ToolboxButtonProps> = memo(({ settings, api }) =>
setSettingsForm(settings)
setIsLoading(false)
},
complete: () => {
setIsLoading(false)
},
})
return () => {
subscription.unsubscribe()
}
},
[api.updateToolboxSettings, settingsForm, settings]
)
Expand Down Expand Up @@ -149,13 +154,14 @@ export const ToolboxButton: FC<ToolboxButtonProps> = memo(({ settings, api }) =>
},
}}
>
<Button variant="ghost" className="!tw-p-2 tw-relative">
<BrainIcon size={16} strokeWidth={1.25} className="tw-w-8 tw-h-8" />
{settings.agent?.name ? (
<span className="tw-absolute tw-top-0 tw-right-0 tw-w-2 tw-h-2 tw-rounded-full tw-bg-green-500 tw-animate-[pulse_5s_ease-in-out_infinite]" />
) : (
<span className="tw-absolute tw-top-0 tw-right-0 tw-w-2 tw-h-2 tw-rounded-full tw-bg-red-500 tw-animate-[pulse_5s_ease-in-out_infinite]" />
)}
<Button variant="ghost" size="none">
<BrainIcon
size={16}
strokeWidth={1.25}
className={`tw-w-8 tw-h-8 ${
settings.agent?.name ? 'tw-text-green-500' : 'tw-text-muted-foreground'
}`}
/>
</Button>
</ToolbarPopoverItem>
</div>
Expand Down

0 comments on commit 321da9a

Please sign in to comment.