Vertesia 客户端 API 参考
vertesia-api
Vertesia 客户端 API(@vertesia/client)参考。涵盖可用 API、常见操作(对象、工作流、交互、文件)、认证辅助函数和查询模式。在构建调用 Vertesia 平台的工具或 UI 时使用。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 5
- Forks
- 2
01 前言 Front Matter
- name
- vertesia-api
- description
- Reference for the Vertesia client API (@vertesia/client). Covers available APIs, common operations (objects, workflows, interactions, files), authentication helpers, and query patterns. Use when building tools or UI that call the Vertesia platform.
03 SKILL.md 正文
Vertesia Client API
The @vertesia/client package provides a typed client for the Vertesia platform.
Getting the Client
// In tool server code (inside tool run())
const client = await context.getClient();
// In UI code (React component)
import { useUserSession } from "@vertesia/ui/session";
const { client, user, project } = useUserSession();
Available APIs
Studio APIs
| API | Description |
|---|---|
client.projects |
Project management |
client.environments |
Environment configuration |
client.interactions |
Interaction execution and management |
client.prompts |
Prompt templates |
client.runs |
Run history and analytics |
client.account |
Current account operations |
client.analytics |
Analytics data |
client.apps |
Application management |
client.iam |
Identity and access management |
client.users |
User management |
client.apikeys |
API key management |
client.refs |
Reference management |
client.commands |
Command execution |
Store APIs
Accessible via client.store.* or shortcuts:
| API | Shortcut | Description |
|---|---|---|
client.store.objects |
client.objects |
Content object CRUD, search, upload |
client.store.files |
client.files |
File operations |
client.store.types |
client.types |
Content type definitions |
client.store.workflows |
client.workflows |
Workflow management, conversations |
client.store.collections |
— | Collection management |
client.store.embeddings |
— | Embedding operations |
client.store.agents |
— | Agent operations |
Object Operations
// Retrieve by ID
const object = await client.objects.retrieve(objectId);
// List with pagination
const objects = await client.objects.list({ limit: 100, offset: 0 });
// Search by text
const results = await client.objects.search({ query: 'search terms' });
// Find with MongoDB-style queries
const objects = await client.objects.find({
where: { status: 'active', type: 'article' },
limit: 50,
});
// Count
const { count } = await client.objects.count({ where: { status: 'active' } });
// Upload content
await client.objects.upload(payload);
// Get download URL
const { url } = await client.objects.getDownloadUrl(fileUri);
// Analyze document
const analysis = await client.objects.analyze(objectId);
Creating an object with an app-owned type
An object's type is either a stored type ObjectId or an in-code app type string. For an app-owned type, pass
the portable string directly:
const appName = import.meta.env.VITE_APP_NAME;
await client.objects.create({
type: `app:${appName}:bookmark`,
properties: { title, url },
});
Do not resolve app-owned types to project-local ObjectIds with types.list() or getTypeByName(). The platform
resolves the app:<app-name>:<type-name> string from the app package, including preview builds for the owner.
Workflow / Conversation Operations
// List conversations for an interaction
const { runs } = await client.store.workflows.listConversations({
interaction: 'app:my-app:collection:interaction-name',
page_size: 20,
});
// Returns: { runs: WorkflowRun[], next_page_token?, has_more? }
// WorkflowRun has: run_id, workflow_id, started_at, status, topic
// NOTE: listConversations does NOT return input field — use getRunDetails for that
// Get full run details (includes input, history)
const run = await client.store.workflows.getRunDetails(runId, workflowId);
// Search runs with filters
const results = await client.store.workflows.searchRuns({
interaction: 'interaction-name',
status: 'completed',
page_size: 10,
});
// Send signal to active workflow
await client.store.workflows.sendSignal(workflowId, runId, 'signal-name', payload);
Agent Runs (client.agents)
For listing/searching the runs that show up in chat sidebars and conversation pages.
// List recent runs (date-sorted; supports filter + cursor pagination)
const { items, total_count, next_cursor } = await client.agents.list({
limit: 100,
sort: 'started_at', // ⚠️ ONLY 'started_at' or 'updated_at' — no other fields
order: 'desc',
interaction: 'sys:my_agent', // optional, single interaction code
status: 'completed', // optional, single or array
});
// Backend full-text search (Elasticsearch)
const { hits, total } = await client.agents.search({
query: 'invoice review',
interaction: 'sys:my_agent',
status: ['running', 'completed'],
limit: 50,
});
Field-name gotchas (the ones that will bite you)
AgentRunResponse = AgentRun | ProcessRun. Only AgentRun (run_kind === 'agent') has interaction, topic, data. Common mistakes:
| Field | What it is | Trap |
|---|---|---|
run.interaction |
The interaction code (e.g. "sys:GeneralAgent") — always set on agent runs |
This is what the backend filter accepts and what stable IDs should use. |
run.interaction_name |
A human-readable display name — optional, often empty | Don't filter or key on this; it'll silently drop most rows. Use it as a label fallback only. |
run.topic |
Long topic generated by topic analysis — optional, set asynchronously | Empty for new conversations. |
run.title |
Short title — optional, may be empty | Often unset. |
run.data.user_prompt |
The user's first message — usually present | Best fallback for a label when topic+title are missing. |
Display-label fallback chain for conversation rows / sidebars:
const isAgent = run.run_kind === 'agent';
const label =
(isAgent ? run.topic : undefined) ||
run.title ||
(isAgent && typeof run.data === 'object' && run.data
? String((run.data as { user_prompt?: unknown }).user_prompt ?? '').trim() || undefined
: undefined) ||
'Untitled conversation';
Agent display + filter values — use interaction as the value, interaction_name || interaction as the label:
const value = isAgent ? run.interaction : undefined; // for filters / keys
const label = run.interaction_name || run.interaction; // for display
Sort limitations
agents.list only sorts by 'started_at' | 'updated_at'. To sort by any other column (topic, status, agent code), apply the sort client-side to the loaded page. agents.search doesn't accept a sort parameter at all (results come back by relevance).
Interaction Execution
// Synchronous execution (wait for result)
const result = await client.interactions.execute({
interaction: 'app:my-app:collection:interaction-name',
data: { input: 'some data' },
});
// Asynchronous execution (start and get run IDs)
const result = await client.interactions.executeAsync({
type: 'conversation',
interaction: 'app:my-app:collection:interaction-name',
interactive: true,
data: { user_prompt: 'Hello' },
});
// result: { runId: string, workflowId: string }
Interaction naming convention
Interactions registered by plugins follow this pattern:
app:<plugin-name>:<collection-name>:<interaction-name>
Authentication Helpers
// Get raw JWT token
const jwt = await client.getRawJWT();
// Get decoded JWT payload
const payload = await client.getDecodedJWT();
// Get current project from JWT
const project = await client.getProject();
// Get current account from JWT
const account = await client.getAccount();
Client Initialization (standalone)
When creating the client directly (outside Vertesia host):
import { VertesiaClient } from "@vertesia/client";
const client = new VertesiaClient({
site: 'api.vertesia.io', // or 'api-preview.vertesia.io'
apikey: 'your-api-key',
sessionTags: ['your-session-tag'],
});
// Or from an auth token:
const client = await VertesiaClient.fromAuthToken(jwtToken);
Query Patterns
Use MongoDB-style query operators in find() and count():
// Equality
{ where: { status: 'active' } }
// Comparison
{ where: { score: { $gt: 80, $lte: 100 } } }
// Logical
{ where: { $and: [{ status: 'active' }, { type: 'article' }] } }
{ where: { $or: [{ status: 'draft' }, { status: 'review' }] } }
// In set
{ where: { category: { $in: ['news', 'blog'] } } }
Security: Never pass user input directly as query operators. Validate and whitelist allowed operators to prevent injection.
Security
Input Validation
Always validate user inputs before passing to API calls:
// Validate ID format before querying
if (typeof objectId !== 'string' || !objectId.match(/^[0-9a-f]{24}$/)) {
throw new Error('Invalid object ID');
}
const object = await client.objects.retrieve(objectId);
Query Injection Prevention
Never construct queries from raw user input:
// ❌ BAD — user could inject operators like $where, $regex
const filter = JSON.parse(userInput);
await client.objects.find({ where: filter });
// ✅ GOOD — whitelist allowed fields and values
await client.objects.find({
where: { status: { $eq: validatedStatus }, type: { $eq: validatedType } }
});
Authorization
Check authentication state before accessing protected resources:
const { client, user } = useUserSession();
// Verify user has access before performing actions
if (!user) {
throw new Error('Not authenticated');
}
In tool server code, the SDK handles JWT validation automatically. Access the authenticated client:
async run(payload, context) {
const client = await context.getClient();
// client is pre-authenticated — org/project scoped from the JWT
}
Error Handling
Never expose internal API details to users:
try {
await client.objects.delete(objectId);
} catch (error) {
console.error('Delete failed:', error); // Log full error server-side
throw new Error('Unable to delete item'); // Generic user-facing message
}
Sensitive Data
- Never log JWT tokens, API keys, or user credentials
- Use
VERTESIA_ALLOWED_ORGSto restrict tool server access to specific organizations - Store secrets in environment variables, never in code
04 同仓库更多 Skills
用户选项收集
user-select
向用户呈现选项并收集其选择,用于交互式决策
Vertesia React UI 组件开发
vertesia-ui
使用 @vertesia/ui 构建 UI 的参考资料。涵盖组件 API(Input、Button、VModal、VTabs、Table)、支持无限滚动的列表/详情表格、可排序表头、带 URL 持久化和内联行过滤的 FilterProvider、布局组件(Sidebar、FullHeightLayout、GenericPageNavHeader)、路由(NestedRouterProvider、useParams、useNavigate)、智能体对话(ModernAgentConversation)、样式与安全。当创建或修改 React UI 页面或组件时使用。
Vertesia 工具服务器资源创建
vertesia-tool-server-resource
为 Vertesia 插件工具服务器创建工具、技能、交互、内容类型、渲染模板、钩子和事件订阅。处理文件脚手架搭建与模块资源索引接线。当向此插件添加新的工具服务器资源时使用。
Vertesia 插件架构参考
vertesia-plugin
关于插件架构、双构建系统、导入钩子和部署的参考资料。用于理解插件结构或构建配置。创建资源请使用 vertesia-tool-server-resource;构建 UI 请使用 vertesia-ui;客户端 API 请使用 vertesia-api。
Vertesia 需求能力差距评估
vertesia-gap-assessment
在提出实现方案之前,评估任意需求与现有 Vertesia 能力之间的差距。在审查 Vertesia 应用、插件、工作流或智能体的需求文档、调研笔记、演示请求或功能请求时使用,以便区分平台原生支持、已安装的项目能力、当前应用实现和真正需要自定义开发的工作。
Vertesia DSL 工作流参考
vertesia-dsl-workflow
DSL 工作流定义、远程活动、变量解析和条件处理的参考。在创建或调试调用插件远程活动的 DSL 工作流时使用。