forked from ThariqS/poke-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.ts
More file actions
44 lines (40 loc) · 1.36 KB
/
agent.ts
File metadata and controls
44 lines (40 loc) · 1.36 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
#!/usr/bin/env node
import { query } from "@anthropic-ai/claude-agent-sdk";
import path from "path";
async function main() {
// Run a query using the SDK
const result = query({
model: "sonnet-4-5",
workingDirectory: path.join(import.meta.dir, "agent"),
prompt: "Introduce yourself and explain what you can help with in the context of this PokeAPI SDK project.",
hooks: {
preExecution: async ({ operation }) => {
// Security hook: block script files (.js and .ts) from being written
// outside the custom_scripts directory
if (operation.type === "Write") {
const filePath = operation.parameters.file_path;
if (
(filePath.endsWith(".js") || filePath.endsWith(".ts")) &&
!filePath.includes("custom_scripts")
) {
return {
blocked: true,
message: `Security policy: Script files can only be written to the custom_scripts directory. Please use a path like: ${path.join(
import.meta.dir,
"agent",
"custom_scripts",
path.basename(filePath)
)}`,
};
}
}
return { blocked: false };
},
},
});
// Consume the async iterator to get streaming responses
for await (const message of result) {
console.log(message);
}
}
main();