文档
हिंदी दस्तावेज़
SDK

SDK

OpenCode SDK OpenCode सर्वर के साथ प्रोग्रामेटिक इंटरैक्शन के लिए एक टाइप-सेफ क्लाइंट प्रदान करता है।

इंस्टॉलेशन

npm install @opencode-ai/sdk

क्लाइंट सेटअप

पूर्ण इंस्टेंस

import { createOpencode } from "@opencode-ai/sdk"
const { client } = await createOpencode()

केवल क्लाइंट

import { createOpencodeClient } from "@opencode-ai/sdk"
const client = createOpencodeClient({
  baseUrl: "http://localhost:4096"
})

कॉन्फ़िगरेशन

const opencode = await createOpencode({
  hostname: "127.0.0.1",
  port: 4096,
  config: {
    model: "anthropic/claude-3-5-sonnet"
  }
})

TypeScript सपोर्ट

import type { Session, Message, Part } from "@opencode-ai/sdk"

API संदर्भ

Health Check

const health = await client.global.health()

सेशंस

await client.session.list()
await client.session.create()
await client.session.prompt({
  path: { id: sessionId },
  body: {
    model: { providerID: "anthropic", modelID: "claude-3-5-sonnet" },
    parts: [{ type: "text", text: "Your query" }]
  }
})

फाइलें

const content = await client.file.read({
  query: { path: "src/index.ts" }
})

इवेंट्स

const events = await client.event.subscribe()
for await (const event of events.stream) {
  console.log("Event:", event.type)
}