import { DESKTOP_LOGIN_MESSAGE, isDesktopMode } from './desktop-mode.js'; export const OFFICIAL_URL = 'https://myclaw.163.com/'; export const REGISTER_COMMAND = 'ccl account register [--name ] [--invite-code ]'; export const REGISTRATION_CHECK_COMMAND = 'ccl account register --check'; export const DEFAULT_NAME_REGISTER_COMMAND = 'ccl account register'; export const NAMED_REGISTER_COMMAND = 'ccl account register --name '; export const INVITE_RETRY_COMMAND = 'ccl account register --invite-code '; export const NAMED_INVITE_RETRY_COMMAND = 'ccl account register --name --invite-code '; export const POST_REGISTRATION_NEXT_STEP = 'Ask the player whether to start matchmaking now. If yes, run `ccl prepare` first. When participation.status is `idle`, launch `ccl start match` with the host stream tool; if participation already exists, attach with `ccl join` instead.'; // Player-facing prompts the Agent can translate. This is the only place // registration wording is defined, so the gated and ungated flows cannot drift. // The gated script asks for the invite code and the game name in one turn, // which is why the policy has to be known before the player is asked anything. export const INVITE_REQUIRED_SCRIPT = '注册新账号需要邀请码。请把邀请码发我;另外,你想给这个角色起什么游戏名?如果不想起名,也可以只发邀请码,我会用系统随机名。'; export const NO_INVITE_SCRIPT = '你想给这个角色起什么游戏名?不想起名我就用系统随机名。'; export function registrationScript(inviteRequired: boolean): string { return inviteRequired ? INVITE_REQUIRED_SCRIPT : NO_INVITE_SCRIPT; } // The registration policy lives on the server, so the Agent has to ask before // it can know which script to use. `--check` is the only probe that never // creates an account, which is what makes asking first safe. const REGISTRATION_PROMPT = [ `Next: run \`${REGISTRATION_CHECK_COMMAND}\` before asking the player anything. It reports whether this server gates registration and returns the question to ask.`, 'Never guess whether an invite code is needed, and never ask about one before that check.', 'Ask the question in `next_step` in the player’s language, then register with:', ` ${DEFAULT_NAME_REGISTER_COMMAND}`, ` ${NAMED_REGISTER_COMMAND} (only when the player explicitly gave a name)`, ` ${INVITE_RETRY_COMMAND} (invite code required, no game name given)`, ` ${NAMED_INVITE_RETRY_COMMAND} (invite code required and the player gave a name)`, 'A reply carrying only an invite code means the player accepted a system-generated name: register with --invite-code and do not ask about the name again.', ].join('\n'); export interface RegistrationCheckResult { inviteRequired: boolean; source: 'server' | 'fallback'; } export function registrationCheckOutput(result: RegistrationCheckResult): Record { return { success: true, data: { invite_required: result.inviteRequired, source: result.source, }, next_step: registrationScript(result.inviteRequired), }; } type NoAccountAction = 'prepare' | 'load' | 'gameStart' | 'accountInfo'; // Safety net for a caller that registered without checking the policy first. // No account was created, so the only thing missing is the code. export function missingInviteCodeMessage(): string { return [ 'This server requires an invite code to register. No account was created.', 'Next: ask the player for an invite code. Keep any game name already chosen and retry:', ` ${NAMED_INVITE_RETRY_COMMAND}`, ` ${INVITE_RETRY_COMMAND} (when no game name was chosen)`, `When no game name has been chosen yet, ask the following in the player's language: ${INVITE_REQUIRED_SCRIPT}`, 'A reply carrying only an invite code means the player accepted a system-generated name: do not ask about the name again.', 'Do not tell the player where to obtain an invite code. If the player has none, stop and say this server requires one.', ].join('\n'); } export function noAccountMessage(action: NoAccountAction): string { if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE; const firstLine = action === 'gameStart' ? 'Cannot start matchmaking: no local ClawClaw account is configured.' : action === 'accountInfo' ? 'No local ClawClaw account is configured.' : action === 'prepare' ? 'Cannot prepare gameplay resources: no local ClawClaw account is configured.' : 'Cannot load persona/memory: no local ClawClaw account is configured.'; return [ firstLine, REGISTRATION_PROMPT, POST_REGISTRATION_NEXT_STEP, ].join('\n'); } export function invalidAccountMessage(): string { if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE; return [ 'Account not found or API key expired.', REGISTRATION_PROMPT, POST_REGISTRATION_NEXT_STEP, ].join('\n'); } export function malformedApiKeyMessage(): string { if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE; return [ 'API key is missing or malformed.', REGISTRATION_PROMPT, POST_REGISTRATION_NEXT_STEP, ].join('\n'); } export function registrationSuccessOutput(result: Record, agentName: string): Record { return { ...result, message: `Registered and saved as profile "${agentName}"`, officialUrl: OFFICIAL_URL, next_step: POST_REGISTRATION_NEXT_STEP, }; }