mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-12-04 02:20:34 +08:00
* Let agents make pictures and videos with OpenBot credits Agents get list_media_models, generate_image and generate_video. They use the credits of the user, or the server wallet on a server. - An approval card shows the model, the options and the price when a generation costs more than the server limit. The user can change the model and the options, and set a default model. - A hold card shows when the balance is too low or when the server turned off agent use of credits. Buy, Turn on, Skip and Don't ask again are on the card. The call continues when the balance is enough. - The Credits rail item shows the wallet that the agents pay from. Its hover card has the agents switch, the ask switch and Move credits. - Server settings get "Agents can use credits", the approval limit and the ask switch, on desktop, the web client and mobile. - Joined servers: new optional Team API routes and capabilities. - The guidance tells agents that OpenBot asks the user, so that an agent does not ask for approval itself and then take a cheaper model. * Prefer the agent's own image and video tools An agent with its own image or video generation tool, such as Codex image_gen, uses it. It uses the OpenBot credits tools only when it has no such tool, when the user asks for OpenBot credits, or when the user names a model that its own tool cannot make. The developer asked for this default. * Tell Codex that image_gen makes GPT Image pictures In the smoke on gpt-6-luna, Codex called openbot.generate_image for "gpt-image-2.6" and spent 2 credits: it could not know that its own image_gen makes the same model. With this sentence it used image_gen (0 credits), and it still used generate_image for Nano Banana (1.5 credits). * Update the Credits rail when an agent spends credits A credits image or video job of an agent or a workflow changes the balance, but the rail read it only when the menu opened. The host now sends openbot-credits-changed when such a job ends, behind the new optional capability openbot-credits-events-v1 (protocol 10). The desktop, for this computer and joined servers, and the web client read the balance again on that event. Hosts without the capability keep the old behavior. Mobile ignores the event. * Give agents the saved credits media file and keep a stopped paid job The generate_image and generate_video results now give the saved file path, so an agent can edit a generated image or use it as a video frame. A stop interrupted the tool while the account service still ran and charged the job. The paid part now runs in the agent service scope, so the result still shows in the chat after a stop. * Remove credits media exports that no other file uses Knip found 9 exports that only their own file uses. * Shorten the credits media tool texts and fix a PageRail story type The agent context budget failed. The guidance repeated the rule of the tool descriptions, and the schema texts were long. After the cut, the two direct tools (generate_image, generate_video) add 2.4 KB to the visible tools, so the baseline goes up by that amount. Claude seldom uses a tool that is not direct, so both tools stay direct. The PageRail story passed undefined to optional props, which the exactOptionalPropertyTypes ratchet refuses. * Merge credits settings inside the write permit and keep media reads passive Two credits setting updates at the same time read the same old value, so the second write lost the first change. PreferenceStore.update now reads the current value inside the write permit. The member mute list uses it too. The approval card and the Credits rail read the media choice and mute routes by themselves. These reads no longer count as client use, so an idle server can install an update. * Count agent credits media in product analytics The host sends system_credit_media once for each generate_image and generate_video call. It has the agent provider and model, the media model, the price and the charge, the outcome, and the answers on the credits and approval cards, with where each answer came from (this computer, a joined client, or an automatic continue). A stopped call with a paid job sends its event when the result shows. Desktop and the web client send credits_card_action for the buttons on the credits and approval cards. Host generation 22 and desktop generation 14. No prompt, file name, path or picture is sent. * Remove two credits analytics type exports that no other file uses * Add the credits explainer, welcome credits and the private media gateway - Add the credits explainer dialog (stepper) and open it from the rail chip, help and setting links. - Give each account 10 welcome credits once, with no end date, for the welcome routes only (migration 0073). - Move the media processor adapters, routes and keys to the private openbot-media-gateway Worker; the account service calls it through the MEDIA_GATEWAY service binding. - Update AGENTS.md, PRIVACY.md and the account service README for the gateway. * Remove three exports that no other file uses * Keep the Linux sizes of the agent instructions in the context budget
188 lines
6.8 KiB
TypeScript
188 lines
6.8 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { devNull } from "node:os";
|
|
import { join } from "node:path";
|
|
import { config } from "@dotenvx/dotenvx";
|
|
import { readDevelopmentState } from "./development-secrets";
|
|
|
|
const LOCAL_IDENTITY_KEYS = [
|
|
"REMOTE_TICKET_PRIVATE_JWK",
|
|
"REMOTE_TICKET_PUBLIC_JWKS",
|
|
"REMOTE_AUTH_WEBHOOK_SECRET",
|
|
"SITE_REPORT_HASH_SECRET",
|
|
"COMPANY_SIGN_IN_SECRET",
|
|
"SKILLS_ADMIN_TOKEN",
|
|
] as const;
|
|
|
|
const MANUAL_TEST_KEYS = new Set(["INCEPTION_API_KEY", "DEV_TEST_GMAIL_ADDRESS", "DEV_TEST_GMAIL_PASSWORD"]);
|
|
|
|
export function withoutDecryptionKeys(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
return Object.fromEntries(Object.entries(environment).filter(([key]) => !key.startsWith("DOTENV_")));
|
|
}
|
|
|
|
export async function loadSharedDevelopmentEnvironment(
|
|
projectRoot: string,
|
|
environment: NodeJS.ProcessEnv = process.env,
|
|
): Promise<Record<string, string>> {
|
|
const privateKey = environment.DOTENV_PRIVATE_KEY_DEV;
|
|
if (!privateKey?.trim()) return {};
|
|
const values = await decryptEnvironment(
|
|
join(projectRoot, "apps/auth-api/.env.dev"),
|
|
{ DOTENV_PRIVATE_KEY_DEV: privateKey },
|
|
"Cannot decrypt shared development settings. Check the development key.",
|
|
);
|
|
return Object.fromEntries(Object.entries(values).filter(([key]) => !MANUAL_TEST_KEYS.has(key)));
|
|
}
|
|
|
|
async function decryptEnvironment(
|
|
path: string,
|
|
keys: Record<string, string>,
|
|
message: string,
|
|
): Promise<Record<string, string>> {
|
|
try {
|
|
const values = { ...keys };
|
|
const result = await config({
|
|
envs: [{ type: "env", value: readFileSync(path, "utf8") }],
|
|
processEnv: values,
|
|
envKeysFile: devNull,
|
|
strict: true,
|
|
quiet: true,
|
|
noArmor: true,
|
|
noNative: true,
|
|
no1Password: true,
|
|
noBitwarden: true,
|
|
});
|
|
if (result.error || Object.values(values).some((value) => value.startsWith("encrypted:"))) throw new Error(message);
|
|
return Object.fromEntries(Object.entries(values).filter(([key]) => !key.startsWith("DOTENV_")));
|
|
} catch {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
export async function loadDevelopmentEnvironment(
|
|
projectRoot: string,
|
|
environment: NodeJS.ProcessEnv = process.env,
|
|
): Promise<NodeJS.ProcessEnv> {
|
|
const state = readDevelopmentState(projectRoot);
|
|
const shared = await loadSharedDevelopmentEnvironment(projectRoot, environment);
|
|
for (const key of LOCAL_IDENTITY_KEYS) delete shared[key];
|
|
return withoutDecryptionKeys({
|
|
...state.defaults,
|
|
...shared,
|
|
...state.overrides,
|
|
...definedEnvironment(environment),
|
|
});
|
|
}
|
|
|
|
function definedEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
return Object.fromEntries(Object.entries(environment).filter(([, value]) => value !== undefined));
|
|
}
|
|
|
|
export async function loadTestDeploymentEnvironment(
|
|
projectRoot: string,
|
|
environment: NodeJS.ProcessEnv = process.env,
|
|
): Promise<NodeJS.ProcessEnv> {
|
|
const shared = await loadSharedDevelopmentEnvironment(projectRoot, environment);
|
|
let production: Record<string, string>;
|
|
try {
|
|
const values: Record<string, string> = {};
|
|
if (environment.DOTENV_PRIVATE_KEY_PRODUCTION) {
|
|
values.DOTENV_PRIVATE_KEY_PRODUCTION = environment.DOTENV_PRIVATE_KEY_PRODUCTION;
|
|
}
|
|
await config({
|
|
path: join(projectRoot, "apps/auth-api/.env.production"),
|
|
envKeysFile: join(projectRoot, ".env.keys"),
|
|
processEnv: values,
|
|
strict: true,
|
|
quiet: true,
|
|
noArmor: true,
|
|
noNative: true,
|
|
no1Password: true,
|
|
noBitwarden: true,
|
|
});
|
|
production = values;
|
|
} catch {
|
|
throw new Error("Cannot decrypt production inputs for the test Worker. Check the production key.");
|
|
}
|
|
const result = withoutDecryptionKeys({ ...production, ...shared, ...definedEnvironment(environment) });
|
|
requireDevelopmentValues(result, [
|
|
"EMAIL_SMTP_PASSWORD",
|
|
"SKILLS_ADMIN_TOKEN",
|
|
"SITE_REPORT_HASH_SECRET",
|
|
"REMOTE_TICKET_PRIVATE_JWK",
|
|
"REMOTE_TICKET_PUBLIC_JWKS",
|
|
"REMOTE_AUTH_WEBHOOK_SECRET",
|
|
"STRIPE_SECRET_KEY",
|
|
"STRIPE_WEBHOOK_SECRET",
|
|
"BOAT_API_KEY",
|
|
"BOAT_WEBHOOK_SECRET",
|
|
"HOSTED_SERVERS_DEVELOPER_KEY",
|
|
"HOSTED_SERVERS_TEST_ALLOW_LIST",
|
|
]);
|
|
if (!/^(sk|rk)_test_/u.test(result.STRIPE_SECRET_KEY ?? "")) {
|
|
throw new Error("Test deployment requires a Stripe test key.");
|
|
}
|
|
if (result.HOSTED_SERVERS_TEST_ALLOW_LIST?.split(",").some((value) => value.trim() === "*")) {
|
|
throw new Error("Test deployment requires an explicit hosted-server allow list.");
|
|
}
|
|
for (const names of [
|
|
["SLACK_CLIENT_ID", "SLACK_CLIENT_SECRET", "SLACK_STATE_SECRET"],
|
|
["SLACK_ROUTE_PRIVATE_JWK", "SLACK_ROUTE_KEY_ID"],
|
|
["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET", "DISCORD_STATE_SECRET"],
|
|
["DISCORD_ROUTE_PRIVATE_JWK", "DISCORD_ROUTE_KEY_ID"],
|
|
["APNS_PRIVATE_KEY", "APNS_KEY_ID"],
|
|
]) {
|
|
if (names.some((name) => result[name]?.trim())) requireDevelopmentValues(result, names);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function requireDevelopmentValues(environment: NodeJS.ProcessEnv, names: string[]): void {
|
|
const missing = names.filter((name) => !environment[name]?.trim() || environment[name]?.startsWith("encrypted:"));
|
|
if (missing.length) throw new Error(`Missing development settings: ${missing.join(", ")}.`);
|
|
}
|
|
|
|
const ACCOUNT_SETTINGS =
|
|
/^(?:STRIPE_|BOAT_|HOSTED_SERVERS_|HOSTED_SERVER_TEMPLATE$|EMAIL_|SITE_REPORT_HASH_SECRET$|COMPANY_SIGN_IN_SECRET$|SKILLS_ADMIN_TOKEN$|APNS_|FCM_|GITHUB_APP_|GITHUB_WEBHOOK_SECRET$|SLACK_|DISCORD_|TELEGRAM_|REMOTE_TICKET_|REMOTE_AUTH_WEBHOOK_SECRET$|OPENPANEL_)/u;
|
|
const SIGNAL_SETTINGS = new Set([
|
|
"REMOTE_TICKET_PUBLIC_JWKS",
|
|
"REMOTE_TICKET_PUBLIC_KEYS",
|
|
"REMOTE_TICKET_JWKS_URL",
|
|
"REMOTE_AUTH_WEBHOOK_SECRET",
|
|
"SLACK_SIGNING_SECRET",
|
|
"GITHUB_WEBHOOK_SECRET",
|
|
"DISCORD_BOT_TOKEN",
|
|
"DISCORD_APPLICATION_ID",
|
|
"TELEGRAM_BOT_TOKENS",
|
|
"TELEGRAM_WEBHOOK_SECRET",
|
|
"TELEGRAM_WEBHOOK_ORIGIN",
|
|
]);
|
|
|
|
export function developmentChildEnvironment(
|
|
environment: NodeJS.ProcessEnv,
|
|
service: "api" | "remote" | "app" | "test-client",
|
|
): NodeJS.ProcessEnv {
|
|
const child = withoutDecryptionKeys(environment);
|
|
delete child.OPENBOT_DEV_SLACK_SIGNING_SECRET;
|
|
for (const key of Object.keys(child)) {
|
|
if (!ACCOUNT_SETTINGS.test(key)) continue;
|
|
if (service === "api") continue;
|
|
if (service === "remote" && SIGNAL_SETTINGS.has(key)) continue;
|
|
delete child[key];
|
|
}
|
|
if (service === "app" || service === "test-client" || service === "api") {
|
|
delete child.REMOTE_SESSION_SECRET;
|
|
delete child.TURN_SHARED_SECRET;
|
|
delete child.REMOTE_METRICS_TOKEN;
|
|
}
|
|
return child;
|
|
}
|
|
|
|
export function developmentSettingsForService(
|
|
environment: NodeJS.ProcessEnv,
|
|
service: "api" | "remote" | "app" | "test-client",
|
|
): NodeJS.ProcessEnv {
|
|
if (service === "api") return withoutDecryptionKeys(environment);
|
|
if (service !== "remote") return {};
|
|
return Object.fromEntries(Object.entries(environment).filter(([key]) => SIGNAL_SETTINGS.has(key)));
|
|
}
|