mirror of
https://github.com/codeany-ai/open-agent-sdk-typescript.git
synced 2026-04-27 07:16:21 +09:00
67e120b2ed
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>
39 lines
1.0 KiB
TypeScript
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)
|