SDK
Dropstone 서버용 타입 안전 JS 클라이언트.
Dropstone JS/TS SDK는 로컬 Dropstone 에이전트와 상호작용하기 위한 타입 안전 클라이언트를 제공합니다. dropstone serve를 서브프로세스로 실행하고 이를 가리키는 타입이 지정된 HTTP 클라이언트를 제공합니다.
CI에서 헤드리스 API 액세스가 필요하신가요?:
순수 프로그래매틱 사용(CI 파이프라인, 자동화, 서버리스)의 경우 DROPSTONE_API_KEY와 함께 HTTP API를 사용하는 것이 좋습니다. 이 페이지의 SDK는 CLI 바이너리가 함께 설치된 Node 프로세스에 대화형 에이전트를 포함하기 위한 것입니다.
기본 HTTP API의 작동 방식은 Server 페이지를 참조하세요.
설치
npm에서 SDK를 설치합니다:
npm install @blankline/dropstone-sdk
클라이언트 생성
dropstone 인스턴스를 생성합니다:
import { createDropstone } from "@blankline/dropstone-sdk"
const { client } = await createDropstone()
이는 서버와 클라이언트를 모두 시작합니다.
옵션
| 옵션 | 타입 | 설명 | 기본값 |
|---|---|---|---|
hostname | string | 서버 호스트명 | 127.0.0.1 |
port | number | 서버 포트 | 4096 |
signal | AbortSignal | 취소를 위한 중단 신호 | undefined |
timeout | number | 서버 시작 시간 초과(ms) | 5000 |
config | Config | 구성 객체 | {} |
구성
동작을 사용자 정의하기 위해 구성 객체를 전달할 수 있습니다. 인스턴스는 여전히 dropstone.json을 선택하지만 인라인으로 구성을 재정의하거나 추가할 수 있습니다:
import { createDropstone } from "@blankline/dropstone-sdk"
const dropstone = await createDropstone({
hostname: "127.0.0.1",
port: 4096,
config: {
model: "dropstone/dropstone-pro",
},
})
console.log(`Server running at ${dropstone.server.url}`)
dropstone.server.close()
클라이언트만
이미 실행 중인 dropstone 인스턴스가 있는 경우 클라이언트 인스턴스를 생성하여 연결할 수 있습니다:
import { createDropstoneClient } from "@blankline/dropstone-sdk"
const client = createDropstoneClient({
baseUrl: "http://localhost:4096",
})
옵션
| 옵션 | 타입 | 설명 | 기본값 |
|---|---|---|---|
baseUrl | string | 서버의 URL | http://localhost:4096 |
fetch | function | 사용자 정의 fetch 구현 | globalThis.fetch |
parseAs | string | 응답 파싱 방법 | auto |
responseStyle | string | 반환 스타일: data 또는 fields | fields |
throwOnError | boolean | 반환 대신 오류 발생 | false |
타입
SDK에는 모든 API 타입에 대한 TypeScript 정의가 포함되어 있습니다. 직접 가져옵니다:
import type { Session, Message, Part } from "@blankline/dropstone-sdk"
모든 타입은 서버의 OpenAPI 사양에서 생성되므로 TypeScript에서 보는 이름은 server 요청 및 응답 형태와 일대일로 매핑됩니다.
오류
SDK는 포착하고 처리할 수 있는 오류를 발생시킬 수 있습니다:
try {
await client.session.get({ path: { id: "invalid-id" } })
} catch (error) {
console.error("Failed to get session:", (error as Error).message)
}
구조화된 출력
JSON 스키마를 사용하여 format을 지정하여 모델에서 구조화된 JSON 출력을 요청할 수 있습니다. 모델은 StructuredOutput 도구를 사용하여 스키마와 일치하는 검증된 JSON을 반환합니다.
기본 사용법
const result = await client.session.prompt({
path: { id: sessionId },
body: {
parts: [{ type: "text", text: "Research Dropstone and provide company info" }],
format: {
type: "json_schema",
schema: {
type: "object",
properties: {
company: { type: "string", description: "Company name" },
founded: { type: "number", description: "Year founded" },
products: {
type: "array",
items: { type: "string" },
description: "Main products",
},
},
required: ["company", "founded"],
},
},
},
})
// 구조화된 출력에 액세스합니다
console.log(result.data.info.structured_output)
// { company: "Dropstone", founded: 2024, products: ["Dropstone CLI"] }
출력 형식 타입
| 타입 | 설명 |
|---|---|
text | 기본값. 표준 텍스트 응답(구조화된 출력 없음) |
json_schema | 제공된 스키마와 일치하는 검증된 JSON 반환 |
JSON 스키마 형식
type: 'json_schema'를 사용할 때 다음을 제공합니다:
| 필드 | 타입 | 설명 |
|---|---|---|
type | 'json_schema' | 필수. JSON 스키마 모드를 지정합니다 |
schema | object | 필수. 출력 구조를 정의하는 JSON 스키마 객체 |
retryCount | number | 선택사항. 검증 재시도 횟수(기본값: 2) |
오류 처리
모델이 모든 재시도 후 유효한 구조화된 출력을 생성하지 못하면 응답에 StructuredOutputError가 포함됩니다:
if (result.data.info.error?.name === "StructuredOutputError") {
console.error("Failed to produce structured output:", result.data.info.error.message)
console.error("Attempts:", result.data.info.error.retries)
}
모범 사례
- 명확한 설명 제공 - 스키마 속성에서 모델이 추출할 데이터를 이해하도록 돕습니다
required사용 - 반드시 있어야 하는 필드를 지정합니다- 스키마를 집중적으로 유지 - 복잡한 중첩 스키마는 모델이 올바르게 채우기 어려울 수 있습니다
- 적절한
retryCount설정 - 복잡한 스키마의 경우 증가, 단순한 스키마의 경우 감소
API
SDK는 타입 안전 클라이언트를 통해 모든 서버 API를 노출합니다.
전역
| 메서드 | 설명 | 응답 |
|---|---|---|
global.health() | 서버 상태 및 버전 확인 | { healthy: true, version: string } |
예제
const health = await client.global.health()
console.log(health.data.version)
앱
| 메서드 | 설명 | 응답 |
|---|---|---|
app.log() | 로그 항목 작성 | boolean |
app.agents() | 사용 가능한 모든 에이전트 나열 | Agent[] |
예제
// 로그 항목 작성
await client.app.log({
body: {
service: "my-app",
level: "info",
message: "Operation completed",
},
})
// 사용 가능한 에이전트 나열
const agents = await client.app.agents()
프로젝트
| 메서드 | 설명 | 응답 |
|---|---|---|
project.list() | 모든 프로젝트 나열 | Project[] |
project.current() | 현재 프로젝트 가져오기 | Project |
예제
// 모든 프로젝트 나열
const projects = await client.project.list()
// 현재 프로젝트 가져오기
const currentProject = await client.project.current()
경로
| 메서드 | 설명 | 응답 |
|---|---|---|
path.get() | 현재 경로 가져오기 | Path |
예제
// 현재 경로 정보 가져오기
const pathInfo = await client.path.get()
구성
| 메서드 | 설명 | 응답 |
|---|---|---|
config.get() | 구성 정보 가져오기 | Config |
예제
const config = await client.config.get()
세션
| 메서드 | 설명 | 참고 |
|---|---|---|
session.list() | 세션 나열 | Session[] 반환 |
session.get({ path }) | 세션 가져오기 | Session 반환 |
session.children({ path }) | 자식 세션 나열 | Session[] 반환 |
session.create({ body }) | 세션 생성 | Session 반환 |
session.delete({ path }) | 세션 삭제 | boolean 반환 |
session.update({ path, body }) | 세션 속성 업데이트 | Session 반환 |
session.init({ path, body }) | 앱 분석 및 AGENTS.md 생성 | boolean 반환 |
session.abort({ path }) | 실행 중인 세션 중단 | boolean 반환 |
session.summarize({ path, body }) | 세션 요약 | boolean 반환 |
session.messages({ path }) | 세션의 메시지 나열 | { info: Message, parts: Part[]}[] 반환 |
session.message({ path }) | 메시지 세부정보 가져오기 | { info: Message, parts: Part[]} 반환 |
session.prompt({ path, body }) | 프롬프트 메시지 전송 | body.noReply: true는 UserMessage(컨텍스트만)를 반환합니다. 기본값은 AI 응답과 함께 AssistantMessage를 반환합니다. 구조화된 출력을 위해 body.outputFormat 지원 |
session.command({ path, body }) | 세션에 명령 전송 | { info: AssistantMessage, parts: Part[]} 반환 |
session.shell({ path, body }) | 셸 명령 실행 | AssistantMessage 반환 |
session.revert({ path, body }) | 메시지 되돌리기 | Session 반환 |
session.unrevert({ path }) | 되돌린 메시지 복원 | Session 반환 |
postSessionByIdPermissionsByPermissionId({ path, body }) | 권한 요청에 응답 | boolean 반환 |
예제
// 세션 생성 및 관리
const session = await client.session.create({
body: { title: "My session" },
})
const sessions = await client.session.list()
// 프롬프트 메시지 전송
const result = await client.session.prompt({
path: { id: session.id },
body: {
model: { providerID: "dropstone", modelID: "dropstone-pro" },
parts: [{ type: "text", text: "Hello!" }],
},
})
// AI 응답을 트리거하지 않고 컨텍스트 주입(플러그인에 유용)
await client.session.prompt({
path: { id: session.id },
body: {
noReply: true,
parts: [{ type: "text", text: "You are a helpful assistant." }],
},
})
파일
| 메서드 | 설명 | 응답 |
|---|---|---|
find.text({ query }) | 파일에서 텍스트 검색 | path, lines, line_number, absolute_offset, submatches가 있는 일치 객체 배열 |
find.files({ query }) | 이름으로 파일 및 디렉토리 찾기 | string[] (경로) |
find.symbols({ query }) | 작업 공간 기호 찾기 | Symbol[] |
file.read({ query }) | 파일 읽기 | { type: "raw" | "patch", content: string } |
file.status({ query? }) | 추적된 파일의 상태 가져오기 | File[] |
find.files는 몇 가지 선택적 쿼리 필드를 지원합니다:
type:"file"또는"directory"directory: 검색을 위해 프로젝트 루트 재정의limit: 최대 결과(1–200)
예제
// 파일 검색 및 읽기
const textResults = await client.find.text({
query: { pattern: "function.*dropstone" },
})
const files = await client.find.files({
query: { query: "*.ts", type: "file" },
})
const directories = await client.find.files({
query: { query: "packages", type: "directory", limit: 20 },
})
const content = await client.file.read({
query: { path: "src/index.ts" },
})
인증
| 메서드 | 설명 | 응답 |
|---|---|---|
auth.set({ ... }) | 인증 자격증명 설정 | boolean |
예제
await client.auth.set({
path: { id: "dropstone" },
body: { type: "api", key: "your-dropstone-api-key" },
})
이벤트
| 메서드 | 설명 | 응답 |
|---|---|---|
event.subscribe() | 서버 전송 이벤트 스트림 | 서버 전송 이벤트 스트림 |
예제
// 실시간 이벤트 수신
const events = await client.event.subscribe()
for await (const event of events.stream) {
console.log("Event:", event.type, event.properties)
}