-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathutils.ts
More file actions
95 lines (86 loc) · 2.67 KB
/
utils.ts
File metadata and controls
95 lines (86 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Logger } from "../logger"
import { isMessageCompacted } from "../shared-utils"
import type { SessionState, WithParts } from "../state"
/**
* Extracts a human-readable key from tool metadata for display purposes.
*/
export const extractParameterKey = (tool: string, parameters: any): string => {
if (!parameters) return ''
if (tool === "read" && parameters.filePath) {
return parameters.filePath
}
if (tool === "write" && parameters.filePath) {
return parameters.filePath
}
if (tool === "edit" && parameters.filePath) {
return parameters.filePath
}
if (tool === "list") {
return parameters.path || '(current directory)'
}
if (tool === "glob") {
if (parameters.pattern) {
const pathInfo = parameters.path ? ` in ${parameters.path}` : ""
return `"${parameters.pattern}"${pathInfo}`
}
return '(unknown pattern)'
}
if (tool === "grep") {
if (parameters.pattern) {
const pathInfo = parameters.path ? ` in ${parameters.path}` : ""
return `"${parameters.pattern}"${pathInfo}`
}
return '(unknown pattern)'
}
if (tool === "bash") {
if (parameters.description) return parameters.description
if (parameters.command) {
return parameters.command.length > 50
? parameters.command.substring(0, 50) + "..."
: parameters.command
}
}
if (tool === "webfetch" && parameters.url) {
return parameters.url
}
if (tool === "websearch" && parameters.query) {
return `"${parameters.query}"`
}
if (tool === "codesearch" && parameters.query) {
return `"${parameters.query}"`
}
if (tool === "todowrite") {
return `${parameters.todos?.length || 0} todos`
}
if (tool === "todoread") {
return "read todo list"
}
if (tool === "task" && parameters.description) {
return parameters.description
}
const paramStr = JSON.stringify(parameters)
if (paramStr === '{}' || paramStr === '[]' || paramStr === 'null') {
return ''
}
return paramStr.substring(0, 50)
}
export function buildToolIdList(
state: SessionState,
messages: WithParts[],
logger: Logger
): string[] {
const toolIds: string[] = []
for (const msg of messages) {
if (isMessageCompacted(state, msg)) {
continue
}
if (msg.parts) {
for (const part of msg.parts) {
if (part.type === 'tool' && part.callID && part.tool) {
toolIds.push(part.callID)
}
}
}
}
return toolIds
}