한국어
문서
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 레퍼런스

상태 확인

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)
}