Docs/SDK API Overview

SDK API Overview

Universal Developer

SDK API Overview

Overview

The Tuff Plugin SDK provides a complete set of APIs for developing CoreBox plugins. All APIs follow a functional design pattern, accessed through use* hook functions.

Introduction

The SDK exposes window control, clipboard, search, storage, and transport capabilities through a unified runtime context, so plugins can stay small and focused.

Installation

EXAMPLE.BASH
pnpm add @talex-touch/utils

API Reference

ModuleImportDescription
Plugin ContextIPluginContext / context.utilsCanonical lifecycle capability facade
Box SDKuseBox()Control CoreBox window
Clipboard SDKuseClipboard() / system.captureSelection()Clipboard, selected text, and history
TempFile SDKuseTempPluginFiles()Create and clean temp files
Storage SDKusePluginStorage()Plugin data persistence
Download SDKuseDownloadSdk()Download task management
Platform Capabilities SDKusePlatformSdk()Platform capability catalog
Screenshot SDKscreenshot / plugin.screenshotPermission-gated display, cursor, and region capture
PowerSDKusePowerSDK()Low-power status for plugin adaptation
RecommendSDKrecommendCustom recommendation provider registration
Account SDKaccountSDKUser info, subscription, quota
TuffTransportuseTuffTransport()Next-gen IPC (recommended)
Feature SDKuseFeature()Search result management
Search / Indexed Source SDK@talex-touch/utils/searchSearch providers and indexed-source lifecycle contracts
QuickActions SDKquickActions / plugin.quickActionsMetaK global actions and native share
QuickOps SDKquickOps / plugin.quickOpsBounded, policy-aware host facade for built-in local tools
DivisionBox SDKuseDivisionBox()Independent window management
Flow SDKcreateFlowSDK()Inter-plugin data transfer
Intelligence SDKuseIntelligenceSdk() / plugin.intelligenceAI capabilities and provider discovery
Localization SDKusePluginI18n() / plugin.i18nHost locale, localized text, and scoped Domain Lexicon

New: TuffTransport is the recommended IPC API for new plugins. It provides type-safe events, automatic batching, and streaming support. See also TuffTransport Internals for technical details.


Quick Start

EXAMPLE.TYPESCRIPT
import {
useBox,
useClipboard,
usePluginStorage,
usePowerSDK,
useFeature,
useDivisionBox
} from '@talex-touch/utils/plugin/sdk'
import { useTuffTransport } from '@talex-touch/utils/transport'

// Initialize SDKs
const box = useBox()
const clipboard = useClipboard()
const storage = usePluginStorage()
const power = usePowerSDK()
const transport = useTuffTransport()
const feature = useFeature()
const divisionBox = useDivisionBox()

// Usage example
async function init() {
// Read config
const config = await storage.getFile('config.json')

    // Read low-power status
    const lowPower = await power.isLowPower({ threshold: 25 })
    if (lowPower) {
      console.log('Skip heavy work on battery')
    }

    // Listen to input changes
    feature.onInputChange(async (input) => {
      const results = await search(input)
      feature.pushItems(results)
    })

    // Listen to clipboard
    await box.allowClipboard(ClipboardType.TEXT)
    clipboard.history.onDidChange((item) => {
      console.log('Clipboard changed:', item)
    })

## }

Best Practices

1. Functional API

All SDKs are accessed through use* functions, no context passing required:

EXAMPLE.TYPESCRIPT
// ✅ Correct
const storage = usePluginStorage()
await storage.getFile('config.json')

// ❌ Wrong (deprecated API)
// const storage = ctx.storage
// await storage.getItem('key')

2. Automatic Context Detection

SDKs automatically detect plugin context, no manual configuration needed:

EXAMPLE.TYPESCRIPT
const storage = usePluginStorage()
// Automatically gets current plugin name

3. Returns Dispose Function

All listeners return an unsubscribe function:

EXAMPLE.TYPESCRIPT
const unsubscribe = feature.onInputChange((input) => {
// ...
})

// Unsubscribe when component unmounts
onUnmounted(() => {
unsubscribe()
})

4. Promise-based Async

All async operations return Promises:

EXAMPLE.TYPESCRIPT
const config = await storage.getFile('config.json')
await clipboard.copyAndPaste({ text: 'Hello' })

Technical Notes

  • use* hooks resolve plugin context at runtime to avoid manual wiring.
  • IPC and transport abstractions provide consistent cleanup via dispose functions.

Type Imports

EXAMPLE.TYPESCRIPT
import type {
TuffItem,
TuffQuery,
ClipboardType,
DivisionBoxConfig,
FlowPayload
} from '@talex-touch/utils/plugin/sdk'