Files
open-agent-sdk-typescript/examples/08-official-api-compat.ts
T
idoubi 67e120b2ed Initial commit: Open Agent SDK (TypeScript)
Open-source Agent SDK with 30+ built-in tools, MCP integration,
multi-turn sessions, subagents, and streaming support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 17:51:53 +08:00

39 lines
1.0 KiB
TypeScript

/**
* Example 8: Official SDK-Compatible API
*
* Demonstrates the query() function with the same API pattern
* as open-agent-sdk. Drop-in compatible.
*
* Run: npx tsx examples/08-official-api-compat.ts
*/
import { query } from '../src/index.js'
async function main() {
console.log('--- Example 8: Official SDK-Compatible API ---\n')
// Standard SDK query pattern
for await (const message of query({
prompt: 'What files are in this directory? Be brief.',
options: {
allowedTools: ['Bash', 'Glob'],
permissionMode: 'bypassPermissions',
},
})) {
const msg = message as any
if (msg.type === 'assistant' && msg.message?.content) {
for (const block of msg.message.content) {
if ('text' in block && block.text) {
console.log(block.text)
} else if ('name' in block) {
console.log(`Tool: ${block.name}`)
}
}
} else if (msg.type === 'result') {
console.log(`\nDone: ${msg.subtype}`)
}
}
}
main().catch(console.error)