@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
200 lines • 10.1 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { args, flags } from '@adonisjs/core/ace';
import { AgentRegistry } from '../src/agent-registry.js';
import { AgentCommand, dayFlag, opt } from '../src/cli/agent_command.js';
import { PRICE_INPUT_SHAPE, parseModelPriceInput } from '../src/pricing/price-input.js';
const usd = (value) => value === null || value === undefined ? '—' : `$${value.toFixed(4)}`;
/** `--actor`, `--role`, `--tenant`: the actor a per-actor read is answered for. */
class AsActorCommand extends AgentCommand {
asActor() {
const id = opt(this.actor);
if (id === undefined)
return this.refuse('Name the actor: --actor <ref>.');
const roles = (this.role ?? []).flatMap((role) => role.split(',')).filter(Boolean);
const tenant = opt(this.tenant);
return {
id,
...(roles.length > 0 ? { roles } : {}),
...(tenant !== undefined ? { tenantRef: tenant } : {}),
};
}
}
__decorate([
flags.string({ description: 'The actor ref to answer for' })
], AsActorCommand.prototype, "actor", void 0);
__decorate([
flags.array({ description: 'A role the actor holds (repeat for more)' })
], AsActorCommand.prototype, "role", void 0);
__decorate([
flags.string({ description: "The actor's organization (with tenancy on)" })
], AsActorCommand.prototype, "tenant", void 0);
/** `agent:quota:show --actor <ref>` — an actor's budget windows (`GET <path>/quota` for them). */
export class AgentQuotaShow extends AsActorCommand {
static commandName = 'agent:quota:show';
static description = "Show an actor's budget windows and what was spent in each";
async execute() {
const report = await (await this.agentService()).quotaReport(this.asActor());
return this.output(report, (value) => {
this.table(['Window', 'Tokens', 'Token limit', 'Spent', 'Spend limit', 'Resets'], value.windows.map((window) => [
window.period,
window.usedTokens ?? '—',
window.limitTokens ?? '—',
usd(window.usedUsd),
window.limitUsd === undefined ? '—' : usd(window.limitUsd),
window.resetsAt ?? '—',
]), 'No budget windows.');
if (value.blocked !== undefined)
this.logger.warning(`Blocked: ${value.blocked.period} window`);
});
}
}
/** `agent:tools:list --actor <ref>` — the tool catalog an actor reaches through an agent. */
export class AgentToolsList extends AsActorCommand {
static commandName = 'agent:tools:list';
static description = 'List the tools an actor can reach through an agent';
async execute() {
const service = await this.agentService();
const actor = this.asActor();
const agent = opt(this.agent);
// An unknown name is refused, not answered with the widest catalog (the route's `404`).
if (agent !== undefined && agent !== '*') {
const agents = await this.app.container.make(AgentRegistry);
if (agents.get(agent) === undefined)
return this.refuse(`No agent named "${agent}".`);
}
const rows = agent === '*'
? await service.toolCatalogForAllAgents(actor)
: await service.toolCatalog(actor, agent);
return this.output(rows, (items) => this.table(['Tool', 'Kind', 'Label'], items.map((tool) => [tool.name, tool.kind, tool.presentation?.label ?? '']), 'No tools.'));
}
}
__decorate([
flags.string({ description: 'The agent (default: the default agent; * for every agent)' })
], AgentToolsList.prototype, "agent", void 0);
/** `agent:tools:stats` — per-tool calls, failures, rejections and latency (the Tools tab). */
export class AgentToolsStats extends AgentCommand {
static commandName = 'agent:tools:stats';
static description = 'Per-tool calls, failures, rejections and latency';
async execute() {
const gov = (await this.governance()).queries(opt(this.tenant));
const from = dayFlag('from', this.from);
const to = dayFlag('to', this.to);
const rows = await gov.perToolStats({
...(from !== undefined ? { from } : {}),
...(to !== undefined ? { to } : {}),
});
const ms = (value) => value === null || value === undefined ? '—' : `${Math.round(value)}ms`;
return this.output(rows, (items) => this.table(['Tool', 'Type', 'Calls', 'Failed', 'Rejected', 'Avg', 'p50', 'p95'], items.map((row) => [
row.toolName,
row.toolType,
row.calls,
row.failed,
row.rejected,
ms(row.avgDurationMs),
ms(row.p50ExecutionMs),
ms(row.p95ExecutionMs),
]), 'No tool calls.'));
}
}
__decorate([
flags.string({ description: 'First UTC day, YYYY-MM-DD (default: all time)' })
], AgentToolsStats.prototype, "from", void 0);
__decorate([
flags.string({ description: 'Last UTC day, YYYY-MM-DD' })
], AgentToolsStats.prototype, "to", void 0);
__decorate([
flags.string({ description: 'Only this organization (with tenancy on)' })
], AgentToolsStats.prototype, "tenant", void 0);
/** `agent:pricing:list` — every model's current per-1M rates (the Pricing tab). */
export class AgentPricingList extends AgentCommand {
static commandName = 'agent:pricing:list';
static description = "List every model's current per-1M token prices";
async execute() {
const rows = await (await this.governance()).pricing().listCurrentPrices();
return this.output(rows, (items) => this.table(['Model', 'Input /1M', 'Output /1M', 'Cache write /1M', 'Cache read /1M', 'Since'], items.map((row) => [
row.modelId,
row.inputPricePer1m,
row.outputPricePer1m,
row.cacheWritePricePer1m ?? '—',
row.cacheReadPricePer1m ?? '—',
row.effectiveFrom,
]), 'No prices.'));
}
}
/**
* `agent:pricing:set <model> --input <usd> --output <usd>` — set a model's current price (atomic
* supersede, the console's Pricing form). Replacing an existing price asks first.
*/
export class AgentPricingSet extends AgentCommand {
static commandName = 'agent:pricing:set';
static description = "Set a model's per-1M token prices";
async execute() {
const pricing = (await this.governance()).pricing();
const price = parseModelPriceInput({
modelId: this.modelId,
inputPricePer1m: this.inputPrice,
outputPricePer1m: this.outputPrice,
cacheWritePricePer1m: this.cacheWrite,
cacheReadPricePer1m: this.cacheRead,
});
if (price === null) {
return this.refuse(`A price needs a model, --input and --output (${PRICE_INPUT_SHAPE}).`);
}
const current = (await pricing.listCurrentPrices()).find((row) => row.modelId === price.modelId) ?? null;
const result = { dryRun: this.dryRun === true, previous: current, price };
if (this.dryRun) {
return this.output(result, () => {
this.logger.info(`${current === null ? 'Would set' : 'Would replace'} the price of ${price.modelId}: input ${price.inputPricePer1m}, output ${price.outputPricePer1m} per 1M.`);
});
}
if (current !== null &&
!(await this.confirmed(this.force, `Replace the price of ${price.modelId} (input ${current.inputPricePer1m}, output ${current.outputPricePer1m} per 1M)?`))) {
return this.refuse('Cancelled.');
}
await pricing.upsertModelPrice(price);
return this.output(result, () => this.logger.success(`Price of ${price.modelId} set.`));
}
}
__decorate([
args.string({ description: 'Model id' })
], AgentPricingSet.prototype, "modelId", void 0);
__decorate([
flags.number({ flagName: 'input', description: 'USD per 1M input tokens' })
], AgentPricingSet.prototype, "inputPrice", void 0);
__decorate([
flags.number({ flagName: 'output', description: 'USD per 1M output tokens' })
], AgentPricingSet.prototype, "outputPrice", void 0);
__decorate([
flags.number({ description: 'USD per 1M cache-write tokens (default: the input rate)' })
], AgentPricingSet.prototype, "cacheWrite", void 0);
__decorate([
flags.number({ description: 'USD per 1M cache-read tokens (default: the input rate)' })
], AgentPricingSet.prototype, "cacheRead", void 0);
__decorate([
flags.boolean({ description: 'Skip the confirmation when a price is replaced' })
], AgentPricingSet.prototype, "force", void 0);
__decorate([
flags.boolean({ description: 'Show what would change, change nothing' })
], AgentPricingSet.prototype, "dryRun", void 0);
/** `agent:tenants:list` — the organizations agent data belongs to (the console's picker). */
export class AgentTenantsList extends AgentCommand {
static commandName = 'agent:tenants:list';
static description = 'List the organizations that have agent data';
async execute() {
const console = await this.governance();
if (!console.tenancyEnabled)
return this.refuse('Tenancy is off for the agent.');
const gov = console.queries();
if (gov.listTenants === undefined) {
return this.refuse('This governance adapter cannot list organizations.');
}
const ids = await gov.listTenants();
return this.output(ids, (items) => this.table(['Organization'], items.map((id) => [id]), 'No organizations.'));
}
}
//# sourceMappingURL=agent_catalog.js.map