Skip to content

Commit 23f80b1

Browse files
committed
Fix filepicker
1 parent c713967 commit 23f80b1

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

.agents/file-explorer/file-picker.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ToolCall } from 'types/agent-definition'
1+
import { StepText, ToolCall } from 'types/agent-definition'
22
import { publisher } from '../constants'
33

44
import {
@@ -50,7 +50,7 @@ In your report, please give a very concise analysis that includes the full paths
5050
Do not use any further tools or spawn any further agents.
5151
`.trim(),
5252

53-
handleSteps: function* ({ prompt, params }) {
53+
handleSteps: function* ({ prompt, params, logger }) {
5454
const { toolResult: fileListerResults } = yield {
5555
toolName: 'spawn_agents',
5656
input: {
@@ -64,21 +64,46 @@ Do not use any further tools or spawn any further agents.
6464
},
6565
} satisfies ToolCall
6666

67-
const fileListerResult = fileListerResults?.[0]
68-
const filesStr =
69-
fileListerResult && fileListerResult.type === 'json'
70-
? ((fileListerResult.value as any)?.[0]?.value?.value as string)
71-
: ''
72-
const files = filesStr.split('\n').filter(Boolean)
67+
const filesResult =
68+
extractSpawnResults<{ text: string }[]>(fileListerResults)[0]
69+
if (!Array.isArray(filesResult)) {
70+
yield {
71+
type: 'STEP_TEXT',
72+
text: filesResult.errorMessage,
73+
} satisfies StepText
74+
return
75+
}
76+
77+
const paths = filesResult[0].text.split('\n').filter(Boolean)
7378

7479
yield {
7580
toolName: 'read_files',
7681
input: {
77-
paths: files,
82+
paths,
7883
},
7984
}
8085

8186
yield 'STEP'
87+
88+
function extractSpawnResults<T>(
89+
results: any[] | undefined,
90+
): (T | { errorMessage: string })[] {
91+
if (!results) return []
92+
const spawnedResults = results
93+
.filter((result) => result.type === 'json')
94+
.map((result) => result.value)
95+
.flat() as {
96+
agentType: string
97+
value: { value?: T; errorMessage?: string }
98+
}[]
99+
return spawnedResults.map(
100+
(result) =>
101+
result.value.value ?? {
102+
errorMessage:
103+
result.value.errorMessage ?? 'Error extracting spawn results',
104+
},
105+
)
106+
}
82107
},
83108
}
84109

0 commit comments

Comments
 (0)