예제
JavaScript SDK의 파일 API와 Embedded Agent 흐름을 정리했어요.
External — 이름으로 워크플로우 호출
JavaScript SDK에는 이름 기반 실행 메소드가 아직 없어요.
REST POST /v1/run/{agentName}/{workflowName}을 직접 호출해주세요.
HTTP 요청과 결과 형식은 워크플로우 실행에서 확인할 수 있어요.
External — 파일 업로드
빌드 산출물을 Deplite 관리 스토리지에 올릴 수 있어요.
bindingId는 필요한 경우 관리 스토리지 바인딩을 지정해요.
import { Deplite } from '@deplite/sdk'
const deplite = new Deplite({ apiToken: process.env.DEPLITE_API_TOKEN! })
const uploaded = await deplite.files.upload({
file: { path: './build/app.apk' },
cleanupRule: { kind: 'persistent' },
contentType: 'application/vnd.android.package-archive',
})
console.log(uploaded.id, uploaded.bindingId)Embedded — 등록·실행·이벤트 처리
첫 실행에서 enroll하고 결과를 안전한 저장소에 보관해주세요.
이후 부팅에서는 저장한 키로 SSE 이벤트를 처리할 수 있어요.
import { Deplite, DepliteAgent, JobResult } from '@deplite/sdk'
const enrollment = await Deplite.enroll({
installCode: process.env.INSTALL_CODE!,
name: 'kiosk-seoul-01',
})
await secureStore.save(enrollment)
const stored = await secureStore.load()
const agent = new DepliteAgent({
identity: stored.identity,
privateKey: stored.privateKey,
})
for await (const event of agent.events()) {
if (event.type !== 'deploy') continue
try {
const output = await runJob(event.payload)
await agent.jobs.reportResult({
jobId: event.payload.jobId,
result: JobResult.success({ exitCode: 0, output }),
})
} catch (error) {
await agent.jobs.reportResult({
jobId: event.payload.jobId,
result: JobResult.failed({ exitCode: 1, errorMessage: String(error) }),
})
}
}privateKey는 SDK가 저장하지 않으므로 암호화해 보관해주세요.
Embedded — 워크플로우 인벤토리 동기화
sync_workflows 이벤트가 오면 현재 사용할 수 있는 워크플로우 이름과 메타데이터를 보고할 수 있어요.
실제 YAML이나 시크릿 값은 보고하지 않아요.
async function reportWorkflows(agent: DepliteAgent) {
await agent.workflows.report([
{ name: 'deploy-prod', verboseSteps: ['build', 'publish'], secretsKeys: ['DB_URL'] },
{ name: 'healthcheck', verboseSteps: ['ping'] },
])
}오류 처리 — 재시도 가능한 응답만 백오프
import { DepliteAuthError, DepliteApiError } from '@deplite/sdk'
async function runWithRetry<T>(fn: () => Promise<T>, max = 3): Promise<T> {
for (let i = 0; i < max; i++) {
try {
return await fn()
} catch (error) {
if (error instanceof DepliteAuthError) throw error
if (error instanceof DepliteApiError && error.statusCode < 500 && error.statusCode !== 429) {
throw error
}
if (i === max - 1) throw error
await sleep(Math.pow(2, i) * 500)
}
}
throw new Error('unreachable')
}관련 문서
최종 수정 일자: