agentbase-docs

Console SDK(Java)

Java 管理面 SDK(io.agentbase.console:agentbase-console-java-sdk)覆盖 Console / 管理面 API:组织与项目治理、Key 与平台注册、跨项目运维。与 Server SDK(../server-sdk/java.md)可同 classpath 并用。Node / Python / Go 面见同目录 nodejs.md / python.md / go.md。

制品与安装

ZIP 交付包(不发布到 Maven registry),托管在 agentbase-sdks release v2.8.0;下载、双层 SHA256SUMS 校验与 mvn install:install-file 完整步骤见 ../integration.md(路径二)。与 Server SDK 的 Client 同名、namespace 独立:同一 Java 文件只 import 一个,另一个用全限定类名;两边的 model / enum / service 禁止混用。

初始化与认证装载

import io.agentbase.console.Client;
import io.agentbase.console.services.Projects;

Client consoleClient = new Client()
    .setEndpoint("https://appbuild.oceanbase.com/v1")
    .setProject(System.getenv("APPBASE_CONSOLE_PROJECT_ID"));  // Console 项目,常为 console

// 凭据三选一(互斥):
consoleClient.setKey("<Console API Key>");     // 服务端自动化首选
// consoleClient.setJWT("<短期 JWT>");
// consoleClient.setSession("<Console 会话 Cookie>");

典型治理调用

方法为位置参数风格,同步返回:

new io.agentbase.console.services.Projects(consoleClient)
    .getUsageAggregates("<projectId>");        // 三级用量(最近 30 个 UTC 日;注意方法名与 JS 的 listUsageAggregates 不同)
new io.agentbase.console.services.Project(consoleClient)
    .getUsage(null, null, null);               // 旧口径 /project/usage

组织、成员、平台注册(createPlatform)等 Console-only 操作不能用项目 API Key。

功能面导航

治理域到服务的全量映射见 nodejs.md「功能面导航」;各域功能页:组织、项目与 Key、配额、用量、站点与域名、平台运维。

Java Console 面特有差异:

各语言调用示例

以下按功能域给出各语言调用示例;每个卡片可切换语言(全页同步)。

建团队、项目与签发 Key

Python 方法名为 snake_case、Go 为 facade New* 构造器 + With* 可选项。该域无 REST 直调页签,REST 直调见下文「配额与限频」卡。

import { Client, Teams, Projects, ID, Scopes } from 'agentbase-console-sdk';

const client = new Client()
    .setEndpoint(process.env.APPBASE_ENDPOINT!)           // https://appbuild.oceanbase.com/v1
    .setProject(process.env.APPBASE_CONSOLE_PROJECT_ID!); // Console 项目,常为 console

const teams = new Teams(client);
const team = await teams.create({ teamId: ID.unique(), name: 'My Team' });

const projects = new Projects(client);
const project = await projects.create({
    projectId: ID.unique(),
    name: 'todo-app',
    teamId: team.$id,
    region: 'default'        // 不使用 Appwrite Cloud 的区域枚举
});

const key = await projects.createKey({
    projectId: project.$id,
    name: 'setup-script',
    scopes: [Scopes.UsersRead, Scopes.UsersWrite]   // scope 最小化
});
// key.secret 仅创建时返回一次

用量查询

三级聚合(最近 30 个 UTC 日)与旧口径是两套体系,方法名不可互猜(见 用量)。

// account / organizations / projects 为 Console SDK 对应 service 实例
await account.listUsageAggregates();
await organizations.listUsageAggregates({ organizationId: '<organizationId>' });
await projects.listUsageAggregates({ projectId: '<projectId>' });

配额与限频(REST 直调)

Java Console SDK 无 typed quota/ratelimit 方法(Python / Go 面亦无对应 typed 证据),统一走 REST 入口:

# 查询当前配额与限频:
curl -sS "$APPBASE_ENDPOINT/projects/<projectId>/limits" \
  -H "X-Appwrite-Project: $APPBASE_CONSOLE_PROJECT_ID" \
  -H "X-Appwrite-Key: $APPBASE_CONSOLE_API_KEY"
# 设置:PATCH 同路径,body 为扁平的限频 + 配额字段;Quota 0 = 不限量,RateLimit 必须正整数
curl -sS -X PATCH "$APPBASE_ENDPOINT/projects/<projectId>/limits" \
  -H 'Content-Type: application/json' \
  -H "X-Appwrite-Project: $APPBASE_CONSOLE_PROJECT_ID" \
  -H "X-Appwrite-Key: $APPBASE_CONSOLE_API_KEY" \
  -d '{"databaseStorageLimit": 0}'
# 字段全集与字段名陷阱见 limits.mdx

示例指引

事实源