SDK Reference Overview
The @teleton-agent/sdk package provides 102 methods across 9 namespaces for building Teleton Agent plugins.
Installation
Install the SDK as a dependency in your plugin project:
npm install @teleton-agent/sdkThe SDK package exports TypeScript type definitions only. There is no runtime code — the actual implementations are injected by the Teleton core platform when your plugin is loaded.
SDK Architecture
The PluginSDK interface is the root object passed to your plugin's tools(sdk) function. It provides namespaced access to all platform capabilities:
interface PluginSDK {
readonly version: string; // SDK version (e.g. "1.0.0")
readonly ton: TonSDK; // TON blockchain operations
readonly telegram: TelegramSDK; // Telegram messaging & users
readonly db: Database | null; // Isolated SQLite database
readonly config: Record<string, unknown>; // Sanitized app config
readonly pluginConfig: Record<string, unknown>; // Plugin-specific config
readonly secrets: SecretsSDK; // Secure secret access
readonly storage: StorageSDK | null; // Key-value storage
readonly log: PluginLogger; // Prefixed logger
readonly bot: BotSDK | null; // Inline bot mode
}Each namespace groups related methods. The SDK object is frozen and immutable — you cannot reassign its properties or add new ones. This guarantees isolation between plugins.
Quick Example
A minimal plugin that exposes a single tool to check TON balance:
import type { PluginSDK, SimpleToolDef, PluginManifest } from "@teleton-agent/sdk";
export const manifest: PluginManifest = {
name: "balance-checker",
version: "1.0.0",
description: "Check any TON address balance with USD conversion",
};
export const tools = (sdk: PluginSDK): SimpleToolDef[] => [
{
name: "check_balance",
description: "Check the TON balance and USD value of an address",
parameters: {
type: "object",
properties: {
address: {
type: "string",
description: "TON address to check (EQ... or UQ... format)",
},
},
required: ["address"],
},
async execute(params) {
const address = params.address as string;
if (!sdk.ton.validateAddress(address)) {
return { success: false, error: "Invalid TON address format" };
}
const [balance, price] = await Promise.all([
sdk.ton.getBalance(address),
sdk.ton.getPrice(),
]);
if (!balance) {
return { success: false, error: "Failed to fetch balance" };
}
const usdValue = price
? (parseFloat(balance.balance) * price.usd).toFixed(2)
: "unavailable";
sdk.log.info(`Balance check for ${address}: ${balance.balance} TON`);
return {
success: true,
data: {
address,
balance: balance.balance,
balanceNano: balance.balanceNano,
usdValue: `$${usdValue}`,
},
};
},
},
];Namespace Map
All SDK namespaces at a glance:
| Namespace | Methods | Description |
|---|---|---|
sdk.ton | 18 | Wallet, balance, price, send TON/jettons, NFTs, transaction history, payment verification, unit conversion |
sdk.ton.dex | 6 | DEX quotes and swaps on STON.fi and DeDust |
sdk.ton.dns | 8 | .ton domain check, resolve, auctions, bidding, linking, ADNL site records |
sdk.telegram | 51 | Messages, media, moderation, polls, Stars, gifts, NFT marketplace, stories |
sdk.bot | 7 | Inline queries, callback handlers, colored keyboards (Layer 222) |
sdk.secrets | 3 | Secure access to API keys and credentials |
sdk.storage | 5 | Simple key-value persistence with optional TTL |
sdk.log | 4 | Structured logging with auto plugin prefix |
sdk.db | N/A | Raw better-sqlite3 database for advanced SQL |
Plugin Manifest
The PluginManifest interface declares your plugin's identity, dependencies, and requirements. Export it as manifest from your plugin entry point.
interface PluginManifest {
name: string; // Lowercase alphanumeric + hyphens, 1-64 chars
version: string; // Semver (e.g. "1.0.0")
author?: string; // Plugin author
description?: string; // Short description (max 256 chars)
dependencies?: string[]; // Required built-in modules (e.g. ["deals"])
defaultConfig?: Record<string, unknown>; // Default config values
sdkVersion?: string; // Required SDK version range (e.g. ">=1.0.0")
secrets?: Record<string, SecretDeclaration>; // Required API keys
bot?: BotManifest; // Bot capabilities (inline, callbacks)
}import type { PluginManifest } from "@teleton-agent/sdk";
export const manifest: PluginManifest = {
name: "weather-report",
version: "2.1.0",
author: "dev@example.com",
description: "Real-time weather data via OpenWeatherMap API",
sdkVersion: ">=1.0.0",
defaultConfig: {
units: "metric",
defaultCity: "Paris",
},
secrets: {
api_key: {
required: true,
description: "OpenWeatherMap API key",
},
webhook_url: {
required: false,
description: "Optional webhook for alerts",
},
},
bot: {
inline: true,
callbacks: true,
rateLimits: {
inlinePerMinute: 20,
callbackPerMinute: 40,
},
},
};Tool Definition
Plugins expose tools to the AI agent via the tools(sdk) export. Each tool is a SimpleToolDef object:
interface SimpleToolDef {
name: string; // Unique tool name (e.g. "weather_forecast")
description: string; // Human-readable description for the LLM
parameters?: Record<string, unknown>; // JSON Schema for parameters
execute: (
params: Record<string, unknown>,
context: PluginToolContext
) => Promise<ToolResult>; // Tool executor function
scope?: ToolScope; // Visibility scope (default: "always")
category?: ToolCategory; // "data-bearing" or "action"
}ToolResult
Every tool executor must return a ToolResult:
interface ToolResult {
success: boolean; // Whether the execution succeeded
data?: unknown; // Result data (serialized to JSON for the LLM)
error?: string; // Error message if failed
}PluginToolContext
The context parameter provides runtime information about the current invocation:
interface PluginToolContext {
chatId: string; // Telegram chat ID where the tool was invoked
senderId: number; // Telegram user ID of the sender
isGroup: boolean; // Whether this is a group chat (vs DM)
bridge: unknown; // TelegramBridge instance
db: unknown; // Plugin's isolated SQLite database
config?: Record<string, unknown>; // Sanitized bot config
}export const tools = (sdk: PluginSDK): SimpleToolDef[] => [
{
name: "greet_user",
description: "Send a personalized greeting to the current chat",
parameters: {
type: "object",
properties: {
name: { type: "string", description: "Name to greet" },
},
required: ["name"],
},
scope: "dm-only",
async execute(params, context) {
const name = params.name as string;
await sdk.telegram.sendMessage(
context.chatId,
`Hello, ${name}! Welcome to the chat.`
);
return { success: true, data: { greeted: name } };
},
},
];Tool Scopes
Each tool can declare a scope that controls when it is visible to the AI agent:
| Scope | Visibility | Use Case |
|---|---|---|
"always" | All chats (DMs and groups) | General-purpose tools with no restrictions |
"dm-only" | Direct messages only | Sensitive operations (wallet, private data) |
"group-only" | Group chats only | Moderation, polls, group-specific features |
"admin-only" | Admin users only | Configuration, dangerous operations |
Scopes are enforced at three levels: tool registration, context filtering (getForContext()), and execution-time validation. An admin can override scopes per-tool via the tool_config database table.
{
name: "transfer_funds",
description: "Send TON from the bot wallet to a recipient",
scope: "admin-only",
async execute(params, context) {
const to = params.address as string;
const amount = params.amount as number;
const result = await sdk.ton.sendTON(to, amount);
return { success: true, data: result };
},
}Important Notes
- SDK is frozen and immutable. The
PluginSDKobject and all its namespaces areObject.freeze()-d at creation time. You cannot reassign properties, add new ones, or modify existing methods. This prevents plugins from interfering with each other. sdk.botisnullif your manifest does not declarebot. You must include abot: { inline: true }orbot: { callbacks: true }declaration in your manifest to receive aBotSDKinstance.sdk.dbisnullif your plugin does not exportmigrate(). To use the raw SQLite database, you must export amigrate(db)function from your plugin entry point. The storage namespace (sdk.storage) auto-creates its own_kvtable and does not requiremigrate().sdk.storageisnullif no database is available. This only happens if the core platform cannot create a plugin database at all (rare edge case).- Secret environment variable naming. Secrets are resolved from environment variables using the pattern
${PLUGIN_NAME_UPPER}_${KEY_UPPER}. For example, a plugin namedweather-reportwith a secret keyapi_keywould look forWEATHER_REPORT_API_KEYin the environment. - All async SDK methods can throw
PluginSDKError. Always wrap SDK calls in try/catch blocks or handle errors at the tool level. See the Error Handling guide.
Next Steps
Explore the detailed reference for each namespace:
- TON Blockchain — Wallet, balance, transfers, jettons, NFTs, payment verification
- DEX Trading — Quotes and swaps on STON.fi and DeDust
- DNS & Domains — .ton domain management, auctions, linking
- Telegram — Messages, media, moderation, Stars, gifts
- Bot SDK — Inline mode, callback handlers, colored keyboards
- Utilities — Secrets, storage, logging, database
- Error Handling — Error codes, patterns, debugging