Skip to content

Commit d3cf1a1

Browse files
committed
fix circular import
1 parent 3b2740c commit d3cf1a1

File tree

3 files changed

+4
-130
lines changed

3 files changed

+4
-130
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ import {
8989
import { ChatSession } from '../../clients/chat/v0/chat'
9090
import { ChatHistoryManager } from '../../storages/chatHistory'
9191
import { amazonQTabSuffix } from '../../../shared/constants'
92-
import { OutputKind, Tool, ToolUtils } from '../../tools/toolShared'
92+
import { OutputKind } from '../../tools/toolShared'
9393
import { Writable } from 'stream'
94+
import { ToolUtils, Tool } from '../../tools/toolUtils'
9495

9596
export interface ChatControllerMessagePublishers {
9697
readonly processPromptChatMessage: MessagePublisher<PromptMessage>

packages/core/src/codewhispererChat/tools/toolShared.ts

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55

66
import path from 'path'
77
import fs from '../../shared/fs/fs'
8-
import { Writable } from 'stream'
9-
import { FsRead, FsReadParams } from './fsRead'
10-
import { FsWrite, FsWriteParams } from './fsWrite'
11-
import { ExecuteBash, ExecuteBashParams } from './executeBash'
12-
import { ToolResult, ToolResultContentBlock, ToolResultStatus, ToolUse } from '@amzn/codewhisperer-streaming'
138

149
export const maxToolResponseSize = 30720 // 30KB
1510

@@ -25,122 +20,6 @@ export interface InvokeOutput {
2520
}
2621
}
2722

28-
export enum ToolType {
29-
FsRead = 'fsRead',
30-
FsWrite = 'fsWrite',
31-
ExecuteBash = 'executeBash',
32-
}
33-
34-
export type Tool =
35-
| { type: ToolType.FsRead; tool: FsRead }
36-
| { type: ToolType.FsWrite; tool: FsWrite }
37-
| { type: ToolType.ExecuteBash; tool: ExecuteBash }
38-
39-
export class ToolUtils {
40-
static displayName(tool: Tool): string {
41-
switch (tool.type) {
42-
case ToolType.FsRead:
43-
return 'Read from filesystem'
44-
case ToolType.FsWrite:
45-
return 'Write to filesystem'
46-
case ToolType.ExecuteBash:
47-
return 'Execute shell command'
48-
}
49-
}
50-
51-
static requiresAcceptance(tool: Tool) {
52-
switch (tool.type) {
53-
case ToolType.FsRead:
54-
return false
55-
case ToolType.FsWrite:
56-
return true
57-
case ToolType.ExecuteBash:
58-
return tool.tool.requiresAcceptance()
59-
}
60-
}
61-
62-
static async invoke(tool: Tool, updates: Writable): Promise<InvokeOutput> {
63-
switch (tool.type) {
64-
case ToolType.FsRead:
65-
return tool.tool.invoke(updates)
66-
case ToolType.FsWrite:
67-
return tool.tool.invoke(updates)
68-
case ToolType.ExecuteBash:
69-
return tool.tool.invoke(updates)
70-
}
71-
}
72-
73-
static queueDescription(tool: Tool, updates: Writable): void {
74-
switch (tool.type) {
75-
case ToolType.FsRead:
76-
tool.tool.queueDescription(updates)
77-
break
78-
case ToolType.FsWrite:
79-
tool.tool.queueDescription(updates)
80-
break
81-
case ToolType.ExecuteBash:
82-
tool.tool.queueDescription(updates)
83-
break
84-
}
85-
}
86-
87-
static async validate(tool: Tool): Promise<void> {
88-
switch (tool.type) {
89-
case ToolType.FsRead:
90-
return tool.tool.validate()
91-
case ToolType.FsWrite:
92-
return tool.tool.validate()
93-
case ToolType.ExecuteBash:
94-
return tool.tool.validate()
95-
}
96-
}
97-
98-
static tryFromToolUse(value: ToolUse): Tool | ToolResult {
99-
const mapErr = (parseError: any): ToolResult => ({
100-
toolUseId: value.toolUseId,
101-
content: [
102-
{
103-
type: 'text',
104-
text: `Failed to validate tool parameters: ${parseError}. The model has either suggested tool parameters which are incompatible with the existing tools, or has suggested one or more tool that does not exist in the list of known tools.`,
105-
} as ToolResultContentBlock,
106-
],
107-
status: ToolResultStatus.ERROR,
108-
})
109-
110-
try {
111-
switch (value.name) {
112-
case ToolType.FsRead:
113-
return {
114-
type: ToolType.FsRead,
115-
tool: new FsRead(value.input as unknown as FsReadParams),
116-
}
117-
case ToolType.FsWrite:
118-
return {
119-
type: ToolType.FsWrite,
120-
tool: new FsWrite(value.input as unknown as FsWriteParams),
121-
}
122-
case ToolType.ExecuteBash:
123-
return {
124-
type: ToolType.ExecuteBash,
125-
tool: new ExecuteBash(value.input as unknown as ExecuteBashParams),
126-
}
127-
default:
128-
return {
129-
toolUseId: value.toolUseId,
130-
content: [
131-
{
132-
type: 'text',
133-
text: `The tool, "${value.name}" is not supported by the client`,
134-
} as ToolResultContentBlock,
135-
],
136-
}
137-
}
138-
} catch (error) {
139-
return mapErr(error)
140-
}
141-
}
142-
}
143-
14423
export function sanitizePath(inputPath: string): string {
14524
let sanitized = inputPath.trim()
14625

packages/core/src/test/codewhispererChat/tools/toolShared.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66
import assert from 'assert'
77
import * as sinon from 'sinon'
88
import { Writable } from 'stream'
9-
import {
10-
ToolUtils,
11-
Tool,
12-
ToolType,
13-
sanitizePath,
14-
OutputKind,
15-
InvokeOutput,
16-
} from '../../../codewhispererChat/tools/toolShared'
9+
import { sanitizePath, OutputKind, InvokeOutput } from '../../../codewhispererChat/tools/toolShared'
10+
import { ToolUtils, Tool, ToolType } from '../../../codewhispererChat/tools/toolUtils'
1711
import { FsRead } from '../../../codewhispererChat/tools/fsRead'
1812
import { FsWrite } from '../../../codewhispererChat/tools/fsWrite'
1913
import { ExecuteBash } from '../../../codewhispererChat/tools/executeBash'

0 commit comments

Comments
 (0)