Files
idoubiandClaude Opus 4.6 a86ab32b07 refactor: update examples to use npm package imports
Replace relative path imports (../src/agent.js, ../src/sdk.js) with
@shipany/open-agent-sdk package imports across all 10 examples.
Bump version to 0.1.1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 22:35:53 +08:00

41 lines
1.0 KiB
TypeScript

/**
* Example 10: Permissions and Allowed Tools
*
* Shows how to restrict which tools the agent can use.
* Creates a read-only agent that can analyze but not modify code.
*
* Run: npx tsx examples/10-permissions.ts
*/
import { query } from '@shipany/open-agent-sdk'
async function main() {
console.log('--- Example 10: Read-Only Agent ---\n')
// Read-only agent: can only use Read, Glob, Grep
for await (const message of query({
prompt: 'Review the code in src/agent.ts for best practices. Be concise.',
options: {
allowedTools: ['Read', 'Glob', 'Grep'],
},
})) {
const msg = message as any
if (msg.type === 'assistant') {
for (const block of msg.message?.content || []) {
if ('text' in block && block.text?.trim()) {
console.log(block.text)
}
if ('name' in block) {
console.log(`[${block.name}]`)
}
}
}
if (msg.type === 'result') {
console.log(`\n--- ${msg.subtype} ---`)
}
}
}
main().catch(console.error)