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.9.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 面特有差异:
- **无
Sql服务**:SQL 走 HTTP 形态或 JS Console SDK(../databases/sql-proxy.md)。 - 无 typed quota/ratelimit 方法:走 REST 入口(../limits.md)。
- 三级用量方法名为
getUsageAggregates——不要按 JS 命名猜测。 - 异常类型为
AppBaseException(code/type)。
各语言调用示例
以下按功能域给出各语言调用示例;每个卡片可切换语言(全页同步)。
建团队、项目与签发 Key
Python 方法名为 snake_case、Go 为 facade New* 构造器 + With* 可选项。该域无 REST 直调页签,REST 直调见下文「配额与限频」卡。
- Console(Node)
- Java
- Python
- Go
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 仅创建时返回一次// 组织 = Team:Teams.create(teamId, name, roles)(位置参数,POST /teams),
// team.getId() 填入下方 projects.create 第 3 个位置参数;create 位置参数全集见上文「快速上手」
io.agentbase.console.services.Teams teams = new io.agentbase.console.services.Teams(consoleClient);
var team = teams.create(
io.agentbase.console.ID.unique(), "My Team", java.util.List.of("owner"));
Projects projects = new Projects(consoleClient);
var project = projects.create(
io.agentbase.console.ID.unique(), "billing-service", team.getId(),
io.agentbase.console.enums.Region.DEFAULT, null, // poolTag 可空
null, null, null, null, null, null, null, null, null, null);
var key = projects.createKey(project.getId(), "ci-deploy",
java.util.List.of(io.agentbase.console.enums.Scopes.USERS_READ,
io.agentbase.console.enums.Scopes.USERS_WRITE),
null, null, null);
System.out.println(key.getSecret()); // secret 只在创建响应出现一次from agentbase_console.services.projects import Projects
from agentbase_console.services.teams import Teams
teams = Teams(console_client) # console_client 初始化见上文「初始化与认证装载」
projects = Projects(console_client)
teams.create(team_id='my-team', name='My Team', roles=['owner'])
project = projects.create(project_id='unique()', name='My Project', team_id='my-team')
key = projects.create_key(
project_id=project.id,
name='server key',
scopes=['users.read', 'users.write', 'teams.read', 'teams.write'],
key_id='unique()')
print(key.secret) # 只在创建响应出现一次// consolefacade "agentbase-console-go-sdk/agentbase";consoleClient 初始化见上文
consoleTeams := consolefacade.NewTeams(consoleClient)
consoleProjects := consolefacade.NewProjects(consoleClient)
_, _ = consoleTeams.Create("my-team", "My Team", consoleTeams.WithCreateRoles([]string{"owner"}))
project, _ := consoleProjects.Create("unique()", "My Project", "my-team")
key, _ := consoleProjects.CreateKey(project.Id, "server key", []string{
"users.read", "users.write", "teams.read", "teams.write",
})
fmt.Println(key.Secret) // 只在创建响应出现一次用量查询
三级聚合(最近 30 个 UTC 日)与旧口径是两套体系,方法名不可互猜(见 用量)。
- Console(Node)
- Java
- Python
- Go
// account / organizations / projects 为 Console SDK 对应 service 实例
await account.listUsageAggregates();
await organizations.listUsageAggregates({ organizationId: '<organizationId>' });
await projects.listUsageAggregates({ projectId: '<projectId>' });// Java Console SDK 生成名是 getUsageAggregates(与 JS 的 listUsageAggregates 不同名)
new io.agentbase.console.services.Projects(consoleClient)
.getUsageAggregates("<projectId>"); // 项目级
new io.agentbase.console.services.SelfHostedOrganizations(consoleClient)
.getUsageAggregates("<organizationId>"); // 组织级(端点同 JS organizations 面)
// 账号级(/account/usage/aggregates)在 console-java 无 typed 方法,走 REST 直调
// 旧口径:作用于 setProject 的当前项目(period 枚举 ONE_HOUR / ONE_DAY)
new io.agentbase.console.services.Project(consoleClient)
.getUsage(null, null, io.agentbase.console.enums.ProjectUsageRange.ONE_DAY);# Python 2.6.0 事实源(appbase release-2.6.0@c0ae98d2,app_base/services)无三级聚合
# typed 方法:无 list_usage_aggregates / get_usage_aggregates;唯一 usage 面是
# self_hosted_organizations.get_usage(organization_id, range=None)(旧口径)。
# Console wheel 源码不在事实源内,三级聚合不要按 JS 命名互猜,走 Node / Java / REST// Go 2.6.0 事实源(server-go@release-2.6.0)无三级聚合方法:全域目录无 UsageAggregates
// 面,唯一旧口径是 selfhostedorganizations.GetUsage(organizationId, WithGetUsageRange)。
// Console Go 面 2.7.0 起交付且不在事实源内,三级聚合不要按 JS 命名互猜,走 Node / Java / REST配额与限频(REST 直调)
Java Console SDK 无 typed quota/ratelimit 方法(Python / Go 面亦无对应 typed 证据),统一走 REST 入口:
- REST(curl)
# 查询当前配额与限频:
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示例指引
- Java(Server / Console)完整调用写法:../examples/java.md
事实源
skills/ob-agentbase/references/java-console-sdk.mdskills/ob-agentbase/references/console-sdk.md- appbase v2.7.0(tag v2.7.0)
- agentbase-sdks v2.7.0 specs(
packages/sdks/console-java/src/main/java/io/agentbase/console/)