Files
open-agent-sdk/examples/08-official-api-compat.ts
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

39 lines
1.1 KiB
TypeScript

/**
* Example 8: Official SDK-Compatible API
*
* Demonstrates the query() function with the same API pattern
* as @anthropic-ai/claude-agent-sdk. Drop-in compatible.
*
* Run: npx tsx examples/08-official-api-compat.ts
*/
import { query } from '@shipany/open-agent-sdk'
async function main() {
console.log('--- Example 8: Official SDK-Compatible API ---\n')
// Same pattern as the official claude-agent-sdk quickstart
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)