|
1 | 1 | import { publisher } from '../constants' |
2 | 2 |
|
3 | 3 | import type { SecretAgentDefinition } from '../types/secret-agent-definition' |
| 4 | +import { JSONObject, JSONValue } from 'types/util-types' |
4 | 5 |
|
5 | 6 | interface ListDirectoryQuery { |
6 | 7 | path: string |
@@ -31,23 +32,41 @@ const directoryLister: SecretAgentDefinition = { |
31 | 32 | 'Mechanically lists multiple directories and returns their contents', |
32 | 33 | model: 'anthropic/claude-sonnet-4.5', |
33 | 34 | publisher, |
34 | | - outputMode: 'all_messages', |
35 | 35 | includeMessageHistory: false, |
36 | | - toolNames: ['list_directory'], |
| 36 | + outputMode: 'structured_output', |
| 37 | + toolNames: ['list_directory', 'set_output'], |
37 | 38 | spawnableAgents: [], |
38 | 39 | inputSchema: { |
39 | 40 | params: paramsSchema, |
40 | 41 | }, |
41 | 42 | handleSteps: function* ({ params }) { |
42 | 43 | const directories: ListDirectoryQuery[] = params?.directories ?? [] |
43 | 44 |
|
| 45 | + const toolResults: JSONValue[] = [] |
44 | 46 | for (const directory of directories) { |
45 | | - yield { |
| 47 | + const { toolResult } = yield { |
46 | 48 | toolName: 'list_directory', |
47 | 49 | input: { |
48 | 50 | path: directory.path, |
49 | 51 | }, |
50 | 52 | } |
| 53 | + if (toolResult) { |
| 54 | + toolResults.push( |
| 55 | + ...toolResult |
| 56 | + .filter((result) => result.type === 'json') |
| 57 | + .map((result) => ({ |
| 58 | + path: directory.path, |
| 59 | + ...(result.value as JSONObject), |
| 60 | + })), |
| 61 | + ) |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + yield { |
| 66 | + toolName: 'set_output', |
| 67 | + input: { |
| 68 | + results: toolResults, |
| 69 | + }, |
51 | 70 | } |
52 | 71 | }, |
53 | 72 | } |
|
0 commit comments