Files
open-agent-sdk/examples/08-official-api-compat.ts
T
idoubiandClaude Opus 4.6 308ee326a3 feat: initial release of @shipany/open-agent-sdk v0.1.0
Open-source Agent SDK inspired by @anthropic-ai/claude-agent-sdk.
Runs the agent loop in-process — no local CLI required.
Deploy anywhere: cloud, serverless, Docker, CI/CD.

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

39 lines
1.0 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 '../src/sdk.js'
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)