Official
opencode-v2
OpenCode 2 agent provider: runs opencode serve (2.x) and talks to its /api over HTTP and server-sent events.
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/opencode-v2@0.1.5
Permissions in 0.1.5
Files
usage.ts2.2 KB
import * as z from "zod";
import type { UsageWindow } from "divergence/protocol";
const meter = z.object({ percent: z.number(), limited: z.boolean(), resetsAt: z.number() });
const budgetModel = z.object({ providerID: z.string(), modelID: z.string(), name: z.string(), spent: z.number().optional() });
export const info = z.object({
workspace: z.object({ id: z.string(), name: z.string().optional(), usageURL: z.string() }),
go: z.object({ rolling: meter, weekly: meter, monthly: meter }).optional(),
budgets: z.array(z.looseObject({
id: z.string(), limit: z.number(), spent: z.number(), resetsAt: z.number(),
scope: z.enum(["each", "combined"]), per: z.enum(["set", "model"]),
coverage: z.enum(["all", "models"]), models: z.array(budgetModel),
vendors: z.array(z.string()), picked: z.boolean(), shared: z.boolean(),
})),
});
type Info = z.infer<typeof info>;
export type Window = UsageWindow & { workspace: Info["workspace"]; budget?: Info["budgets"][number] };
/** Keeps Console workspace and budget identity when locations contribute different allowances. */
export function windows(limits: Info): Window[] {
const { workspace } = limits;
const label = workspace.name ?? workspace.id;
const result: Window[] = [];
if (limits.go) {
for (const [period, meter] of Object.entries(limits.go)) result.push({
id: JSON.stringify([workspace.id, "go", period]), label: `${label}: Go ${period}`,
usedPercent: meter.percent, blocked: meter.limited, resetsAt: new Date(meter.resetsAt).toISOString(), workspace,
});
}
for (const budget of limits.budgets) {
const entries = budget.per === "model"
? budget.models.map((model) => ({ model, spent: model.spent ?? 0 }))
: [{ model: undefined, spent: budget.spent }];
for (const { model, spent } of entries) result.push({
id: JSON.stringify([workspace.id, "budget", budget.id, ...(model ? [model.providerID, model.modelID] : [])]),
label: `${label}: ${model?.name ?? "Monthly budget"}`,
usedPercent: budget.limit > 0 ? spent / budget.limit * 100 : 100,
blocked: spent >= budget.limit, resetsAt: new Date(budget.resetsAt).toISOString(),
...(model ? { model: model.name } : {}), workspace, budget,
});
}
return result;
}
No comments yet.