charness 4.3.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/agent-plugin/skills/charness-orchestration/SKILL.md +2 -2
- package/dist/agentLogin/agentLogin.d.ts.map +1 -1
- package/dist/agentLogin/agentLogin.js +6 -5
- package/dist/agentLogin/agentLogin.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +39 -27
- package/dist/bot.js.map +1 -1
- package/dist/cli/claudeProfiles.d.ts +4 -1
- package/dist/cli/claudeProfiles.d.ts.map +1 -1
- package/dist/cli/claudeProfiles.js +6 -2
- package/dist/cli/claudeProfiles.js.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts +12 -1
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +253 -89
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/fallbackChain.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/fallbackChain.js +8 -7
- package/dist/connectors/telegram/commands/fallbackChain.js.map +1 -1
- package/dist/connectors/telegram/commands/limitsBoard.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/limitsBoard.js +3 -1
- package/dist/connectors/telegram/commands/limitsBoard.js.map +1 -1
- package/dist/connectors/telegram/commands/modelPage.d.ts +2 -0
- package/dist/connectors/telegram/commands/modelPage.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/modelPage.js +1 -1
- package/dist/connectors/telegram/commands/modelPage.js.map +1 -1
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/de.js +42 -25
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +42 -25
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +42 -25
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +42 -25
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +42 -25
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +42 -25
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +42 -25
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +42 -25
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +42 -25
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +42 -25
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +42 -25
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +42 -25
- package/dist/i18n/zh.js.map +1 -1
- package/dist/i18n.d.ts +0 -12
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +6 -4
- package/dist/i18n.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +3 -1
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/state.d.ts +11 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +15 -0
- package/dist/state.js.map +1 -1
- package/dist/utils/backendSwitchPlan.d.ts +4 -1
- package/dist/utils/backendSwitchPlan.d.ts.map +1 -1
- package/dist/utils/backendSwitchPlan.js +6 -2
- package/dist/utils/backendSwitchPlan.js.map +1 -1
- package/dist/utils/claudeAccountAlert.d.ts +6 -3
- package/dist/utils/claudeAccountAlert.d.ts.map +1 -1
- package/dist/utils/claudeAccountAlert.js +13 -7
- package/dist/utils/claudeAccountAlert.js.map +1 -1
- package/dist/utils/claudeAccountPickerPlan.d.ts +17 -3
- package/dist/utils/claudeAccountPickerPlan.d.ts.map +1 -1
- package/dist/utils/claudeAccountPickerPlan.js +19 -4
- package/dist/utils/claudeAccountPickerPlan.js.map +1 -1
- package/dist/utils/claudeProfileLabels.d.ts +160 -0
- package/dist/utils/claudeProfileLabels.d.ts.map +1 -0
- package/dist/utils/claudeProfileLabels.js +283 -0
- package/dist/utils/claudeProfileLabels.js.map +1 -0
- package/dist/utils/claudeProfileUsageViews.d.ts +2 -0
- package/dist/utils/claudeProfileUsageViews.d.ts.map +1 -1
- package/dist/utils/claudeProfileUsageViews.js +3 -1
- package/dist/utils/claudeProfileUsageViews.js.map +1 -1
- package/dist/utils/claudeUsage.d.ts +5 -0
- package/dist/utils/claudeUsage.d.ts.map +1 -1
- package/dist/utils/claudeUsage.js +1 -0
- package/dist/utils/claudeUsage.js.map +1 -1
- package/dist/utils/fallbackChain.d.ts +4 -2
- package/dist/utils/fallbackChain.d.ts.map +1 -1
- package/dist/utils/fallbackChain.js +4 -3
- package/dist/utils/fallbackChain.js.map +1 -1
- package/dist/utils/fallbackSwitchNotice.d.ts +1 -1
- package/dist/utils/fallbackSwitchNotice.d.ts.map +1 -1
- package/dist/utils/fallbackSwitchNotice.js +4 -3
- package/dist/utils/fallbackSwitchNotice.js.map +1 -1
- package/dist/utils/limitsBoardPlan.d.ts +6 -4
- package/dist/utils/limitsBoardPlan.d.ts.map +1 -1
- package/dist/utils/limitsBoardPlan.js +11 -5
- package/dist/utils/limitsBoardPlan.js.map +1 -1
- package/dist/utils/threadStatusReport.d.ts +2 -0
- package/dist/utils/threadStatusReport.d.ts.map +1 -1
- package/dist/utils/threadStatusReport.js +4 -3
- package/dist/utils/threadStatusReport.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAccountAddWords = parseAccountAddWords;
|
|
3
4
|
exports.createClaudeAccounts = createClaudeAccounts;
|
|
4
5
|
/**
|
|
5
6
|
* `/accounts` — every account the bot works with, on one screen: the Claude accounts (profiles) with their usage
|
|
@@ -18,6 +19,7 @@ const fallbackChain_1 = require("../../../utils/fallbackChain");
|
|
|
18
19
|
const openCodeUsage_1 = require("../../../utils/openCodeUsage");
|
|
19
20
|
const modelPickerPlan_1 = require("../../../utils/modelPickerPlan");
|
|
20
21
|
const claudeProfiles_1 = require("../../../utils/claudeProfiles");
|
|
22
|
+
const claudeProfileLabels_1 = require("../../../utils/claudeProfileLabels");
|
|
21
23
|
const claudeProfileUsageLines_1 = require("../../../utils/claudeProfileUsageLines");
|
|
22
24
|
const claudeProfileSync_1 = require("../../../utils/claudeProfileSync");
|
|
23
25
|
const usageRefreshBudget_1 = require("../../../utils/usageRefreshBudget");
|
|
@@ -28,6 +30,26 @@ const callbackToast_1 = require("./callbackToast");
|
|
|
28
30
|
const modelPage_1 = require("./modelPage");
|
|
29
31
|
/** Screens whose provider snapshot is kept (the newest); an older keyboard is refused as expired. */
|
|
30
32
|
const providerSnapshotLimit = 50;
|
|
33
|
+
/** The word of `/accounts add … id:<id>` that picks the new account's id by hand (`id:` and the id, one word). */
|
|
34
|
+
const explicitIdPrefix = 'id:';
|
|
35
|
+
/** The last word of `/accounts add <name> api`: the account is billed to API credits. */
|
|
36
|
+
const apiBillingWord = 'api';
|
|
37
|
+
/**
|
|
38
|
+
* @description The words after `/accounts add`: the display name, whether the last word is `api` (an account billed to API credits)
|
|
39
|
+
* and the id typed by hand (`id:<id>`, anywhere; `null` when none). A bare `add` / `add api` has an empty name: the name is asked.
|
|
40
|
+
*/
|
|
41
|
+
function parseAccountAddWords(words) {
|
|
42
|
+
let explicitId = null;
|
|
43
|
+
const rest = [];
|
|
44
|
+
for (const word of words) {
|
|
45
|
+
if (word.toLowerCase().startsWith(explicitIdPrefix))
|
|
46
|
+
explicitId = word.slice(explicitIdPrefix.length);
|
|
47
|
+
else
|
|
48
|
+
rest.push(word);
|
|
49
|
+
}
|
|
50
|
+
const isApi = rest.at(-1)?.toLowerCase() === apiBillingWord;
|
|
51
|
+
return { label: (isApi ? rest.slice(0, -1) : rest).join(' ').trim(), isApi, explicitId };
|
|
52
|
+
}
|
|
31
53
|
/**
|
|
32
54
|
* @description Build the `/account` feature over its ports: the command, its buttons, the name capture the
|
|
33
55
|
* «Add» button arms (the text handler asks `checkIsAwaitingProfileName` / `submitProfileName`), and the
|
|
@@ -37,8 +59,7 @@ function createClaudeAccounts(ports) {
|
|
|
37
59
|
const { bot, command, getState, replyToThread, editThreadMessage, deleteThreadMessage, authoriseContext, withThreadLocale, checkIsGeneral, getDataDir, getInstanceTimezone, refreshClaudeUsage, syncClaudeProfiles, readClaudeAuthStatus, startClaudeProfileLogin, applyClaudeProfile, applyClaudeProfileEverywhere, switchTopicByOperator, detectOpenCodeProviders, listOpenCodeModels, getTopicRun, disconnectOpenCodeProvider, startOpenCodeConnect, applyAutoSwitch, getHomeClaudeDir, verifyAnthropicApiKey, getProfileUsageView, checkIsProfileMissingFromLimitsList, noteClaudeAccountsChanged, } = ports;
|
|
38
60
|
const answerWithWholeText = (0, callbackToast_1.createWholeTextAnswerer)(replyToThread);
|
|
39
61
|
/**
|
|
40
|
-
* Topics whose next plain message
|
|
41
|
-
* billed to the API), or the id of the OpenCode provider to connect. One capture per topic; armed by the buttons /
|
|
62
|
+
* Topics whose next plain message answers «➕» or ✏️ ({@link ProfileNameCapture}). One capture per topic; armed by the buttons /
|
|
42
63
|
* `add`, disarmed by a slash command or `/esc`.
|
|
43
64
|
*/
|
|
44
65
|
const awaitingProfileName = new Map();
|
|
@@ -78,13 +99,13 @@ function createClaudeAccounts(ports) {
|
|
|
78
99
|
return null;
|
|
79
100
|
return run.rung?.backend === 'claude' ? run.rung.profile : resolveClaudeAccountName(key, false);
|
|
80
101
|
}
|
|
81
|
-
/** Where the topic runs, for the title: `Claude «
|
|
102
|
+
/** Where the topic runs, for the title: `Claude «Work»` (the account's display name), `OpenCode openai/gpt-5`, or `OpenCode` while its model is unknown. */
|
|
82
103
|
function formatRunLabel(key) {
|
|
83
104
|
const run = getTopicRun(key);
|
|
84
105
|
if (run.family === 'opencode') {
|
|
85
106
|
return run.rung?.backend === 'opencode' ? `${(0, i18n_1.t)('fallback.backendOpenCode')} ${run.rung.providerId}/${run.rung.modelId}` : (0, i18n_1.t)('fallback.backendOpenCode');
|
|
86
107
|
}
|
|
87
|
-
return `${(0, i18n_1.t)('fallback.backendClaude')} «${resolveActiveName(key, false) ?? resolveClaudeAccountName(key, false)}»`;
|
|
108
|
+
return `${(0, i18n_1.t)('fallback.backendClaude')} «${formatLabel(resolveActiveName(key, false) ?? resolveClaudeAccountName(key, false))}»`;
|
|
88
109
|
}
|
|
89
110
|
/** The config directory of a profile; `null` for `default`. */
|
|
90
111
|
function resolveDir(name) {
|
|
@@ -93,6 +114,42 @@ function createClaudeAccounts(ports) {
|
|
|
93
114
|
function checkIsKnownProfile(name) {
|
|
94
115
|
return name === claudeProfiles_1.defaultClaudeProfileName || getState().getClaudeProfileRecord(name) !== undefined;
|
|
95
116
|
}
|
|
117
|
+
/** What an account is called on this screen: its display name, `default`'s «Main», else its id (`utils/claudeProfileLabels.ts`). */
|
|
118
|
+
function formatLabel(name) {
|
|
119
|
+
return (0, claudeProfileLabels_1.resolveClaudeProfileLabel)(name, getState().getAllClaudeProfileInfos());
|
|
120
|
+
}
|
|
121
|
+
/** What a message tells the operator to type for an account: its name when that finds it, else its id (`resolveClaudeProfileCommandName`). */
|
|
122
|
+
function formatCommandName(name) {
|
|
123
|
+
return (0, claudeProfileLabels_1.resolveClaudeProfileCommandName)(name, getState().getAllClaudeProfileInfos());
|
|
124
|
+
}
|
|
125
|
+
/** Every account the name rules look at — `default` (signed out or not: its id and «Main» in every language stay taken) and the added ones. */
|
|
126
|
+
function listNameEntries() {
|
|
127
|
+
return (0, claudeProfileLabels_1.buildClaudeProfileNameEntries)(getState().getAllClaudeProfileInfos());
|
|
128
|
+
}
|
|
129
|
+
/** The account a typed name means — an id or a display name, case ignored — or `null`. */
|
|
130
|
+
function findTypedProfile(typed) {
|
|
131
|
+
return (0, claudeProfileLabels_1.findClaudeProfileByTypedName)(typed, listNameEntries());
|
|
132
|
+
}
|
|
133
|
+
/** The refusal of a display name, in the active locale. */
|
|
134
|
+
function describeLabelProblem(problem) {
|
|
135
|
+
switch (problem.kind) {
|
|
136
|
+
case 'empty': return (0, i18n_1.t)('account.labelEmpty', { max: claudeProfileLabels_1.claudeProfileLabelMaxLength });
|
|
137
|
+
case 'tooLong': return (0, i18n_1.t)('account.labelTooLong', { max: problem.max });
|
|
138
|
+
case 'taken': return (0, i18n_1.t)('account.labelTaken', { name: problem.label });
|
|
139
|
+
case 'isId': return (0, i18n_1.t)('account.labelIsId', { name: problem.label });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** The refusal of an id typed by hand (`id:<id>`): which character it cannot hold, never that capitals are refused (they are lowercased). */
|
|
143
|
+
function describeIdProblem(problem) {
|
|
144
|
+
const reason = problem.kind === 'character' || problem.kind === 'firstCharacter'
|
|
145
|
+
? (0, i18n_1.t)(`account.idProblem.${problem.kind}`, { character: problem.character })
|
|
146
|
+
: problem.kind === 'tooLong'
|
|
147
|
+
? (0, i18n_1.t)('account.idProblem.tooLong', { max: problem.max })
|
|
148
|
+
: problem.kind === 'buttonWord'
|
|
149
|
+
? (0, i18n_1.t)('account.idProblem.buttonWord', { id: problem.id })
|
|
150
|
+
: (0, i18n_1.t)(`account.idProblem.${problem.kind}`);
|
|
151
|
+
return (0, i18n_1.t)('account.invalidName', { problem: reason, max: claudeProfiles_1.claudeProfileNameMaxLength });
|
|
152
|
+
}
|
|
96
153
|
/** How a known profile pays, as last recorded (`default` from its hidden record); `null` when never recorded. */
|
|
97
154
|
function readBilling(name) {
|
|
98
155
|
return getState().getClaudeProfileInfo(name)?.billing ?? null;
|
|
@@ -143,18 +200,19 @@ function createClaudeAccounts(ports) {
|
|
|
143
200
|
* and live topics moved onto it. Returns the line to post; the key itself is never logged or echoed.
|
|
144
201
|
*/
|
|
145
202
|
async function onClaudeProfileApiKey(_key, profile, apiKey) {
|
|
203
|
+
const label = formatLabel(profile.name);
|
|
146
204
|
if (profile.configDir === null || !checkIsKnownProfile(profile.name))
|
|
147
|
-
return (0, i18n_1.t)('account.apiKeyNoDirectory', { name:
|
|
205
|
+
return (0, i18n_1.t)('account.apiKeyNoDirectory', { name: label });
|
|
148
206
|
const check = await verifyAnthropicApiKey(apiKey);
|
|
149
207
|
if (check === 'invalid')
|
|
150
|
-
return (0, i18n_1.t)('account.apiKeyRejected', { name: profile.name });
|
|
208
|
+
return (0, i18n_1.t)('account.apiKeyRejected', { name: label, login: formatCommandName(profile.name) });
|
|
151
209
|
try {
|
|
152
210
|
(0, claudeProfiles_1.createClaudeProfileLayout)({ dataDir: getDataDir(), name: profile.name });
|
|
153
211
|
(0, claudeProfiles_1.writeClaudeProfileApiKey)(profile.configDir, apiKey);
|
|
154
212
|
}
|
|
155
213
|
catch (e) {
|
|
156
214
|
console.error(`[account] storing the API key of ${profile.name} failed:`, e instanceof Error ? e.message : e);
|
|
157
|
-
return (0, i18n_1.t)('account.createFailed', { name:
|
|
215
|
+
return (0, i18n_1.t)('account.createFailed', { name: label });
|
|
158
216
|
}
|
|
159
217
|
const status = await readClaudeAuthStatus(profile.configDir);
|
|
160
218
|
await getState().upsertClaudeProfileRecord(profile.name, { billing: 'api' });
|
|
@@ -165,7 +223,7 @@ function createClaudeAccounts(ports) {
|
|
|
165
223
|
if (status?.loggedIn)
|
|
166
224
|
await applyClaudeProfileEverywhere();
|
|
167
225
|
console.log(`[account] ${profile.name}: an API key was stored (${check === 'valid' ? 'accepted by the API' : 'not verified'})`);
|
|
168
|
-
return (0, agentLogin_1.appendLimitsListNote)((0, i18n_1.t)(check === 'valid' ? 'account.apiKeySaved' : 'account.apiKeySavedUnverified', { name:
|
|
226
|
+
return (0, agentLogin_1.appendLimitsListNote)((0, i18n_1.t)(check === 'valid' ? 'account.apiKeySaved' : 'account.apiKeySavedUnverified', { name: label }), profile.name, checkIsProfileMissingFromLimitsList(profile.name));
|
|
169
227
|
}
|
|
170
228
|
function formatRow(row) {
|
|
171
229
|
const marker = row.isActive ? '✓ ' : '• ';
|
|
@@ -173,7 +231,7 @@ function createClaudeAccounts(ports) {
|
|
|
173
231
|
? (0, i18n_1.t)('account.row.loggedOut')
|
|
174
232
|
: formatAccountDetail(row);
|
|
175
233
|
const users = row.topicCount > 0 ? (0, i18n_1.t)('account.row.topics', { count: row.topicCount }) : '';
|
|
176
|
-
return `${marker}${row.
|
|
234
|
+
return `${marker}${row.label} — ${account}${users}${formatUsageLines(row.name)}`;
|
|
177
235
|
}
|
|
178
236
|
/**
|
|
179
237
|
* The profile's usage under its row (`utils/claudeProfileUsageLines.ts`, the renderer `/limits` shares), each
|
|
@@ -192,12 +250,16 @@ function createClaudeAccounts(ports) {
|
|
|
192
250
|
return row.email === null ? (0, i18n_1.t)('account.kind.apiKey') : `${row.email}, ${(0, i18n_1.t)('account.kind.api')}`;
|
|
193
251
|
return `${row.email ?? '?'}, ${(0, i18n_1.t)(`account.kind.${row.kind}`, { plan: row.subscriptionType ?? '?' })}`;
|
|
194
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* A row's pick button: `✓ Work · work@example.com`, `Work · not signed in`, or the name alone when there is no email to show (a pasted
|
|
255
|
+
* API key) — the display name cut to fit a phone (the text above shows it whole), never twice.
|
|
256
|
+
*/
|
|
195
257
|
function formatRowButton(row) {
|
|
196
258
|
const marker = row.isActive ? '✓ ' : '';
|
|
197
259
|
const detail = row.loggedIn === false || (row.loggedIn === undefined && row.email === null && row.billing !== 'api')
|
|
198
260
|
? (0, i18n_1.t)('account.row.loggedOut')
|
|
199
|
-
: row.email
|
|
200
|
-
return `${marker}${row.
|
|
261
|
+
: row.email;
|
|
262
|
+
return `${marker}${(0, claudeProfileLabels_1.shortenClaudeProfileLabel)(row.label)}${detail === null ? '' : ` · ${detail}`}${row.billing === 'api' ? ' 💳' : ''}`;
|
|
201
263
|
}
|
|
202
264
|
async function buildPickerRows(key, isGeneral) {
|
|
203
265
|
// The usage poll runs beside the status probes; a snapshot younger than a minute is kept, and a slow usage endpoint never holds the screen.
|
|
@@ -206,6 +268,7 @@ function createClaudeAccounts(ports) {
|
|
|
206
268
|
const topicCounts = (0, claudeAccountPickerPlan_1.countTopicsPerProfile)(state.listBindings().map(({ key: boundKey }) => state.resolveClaudeProfileName(boundKey)));
|
|
207
269
|
return (0, claudeAccountPickerPlan_1.buildAccountPickerRows)({
|
|
208
270
|
isDefaultRemoved: state.getClaudeProfileInfo(claudeProfiles_1.defaultClaudeProfileName)?.isRemoved === true,
|
|
271
|
+
getLabel: formatLabel,
|
|
209
272
|
records: state.getClaudeProfileRecords(),
|
|
210
273
|
defaultStatus: {
|
|
211
274
|
// The CLI's refusal of `default` on a turn outweighs a probe that still finds a login there (a revoked one, a switch of the organization's).
|
|
@@ -245,22 +308,28 @@ function createClaudeAccounts(ports) {
|
|
|
245
308
|
const list = rows.map(formatRow).join('\n');
|
|
246
309
|
const run = getTopicRun(key);
|
|
247
310
|
const title = isGeneral
|
|
248
|
-
? (0, i18n_1.t)('account.titleGeneral', { name: resolveClaudeAccountName(key, true), list })
|
|
311
|
+
? (0, i18n_1.t)('account.titleGeneral', { name: formatLabel(resolveClaudeAccountName(key, true)), list })
|
|
249
312
|
: (0, i18n_1.t)('account.title', { current: formatRunLabel(key), list });
|
|
250
313
|
const openCodeSection = providers.length === 0
|
|
251
314
|
? (0, i18n_1.t)('accounts.openCodeNone')
|
|
252
315
|
: (0, i18n_1.t)('accounts.openCodeSection', { list: formatProviderList(providers, isGeneral ? null : run.rung) });
|
|
253
316
|
const isDefaultRemoved = getState().getClaudeProfileInfo(claudeProfiles_1.defaultClaudeProfileName)?.isRemoved === true;
|
|
254
|
-
const removedNote = isDefaultRemoved
|
|
317
|
+
const removedNote = isDefaultRemoved
|
|
318
|
+
? `\n\n${(0, i18n_1.t)('accounts.defaultRemovedNote', { name: formatLabel(claudeProfiles_1.defaultClaudeProfileName), login: formatCommandName(claudeProfiles_1.defaultClaudeProfileName) })}`
|
|
319
|
+
: '';
|
|
255
320
|
// The usage hint (which says the percentages are USED) follows the account list it explains.
|
|
256
321
|
const buttonsHint = (0, i18n_1.t)(isGeneral ? 'accounts.buttonsHintGeneral' : 'accounts.buttonsHint');
|
|
257
322
|
const text = `${title}${removedNote}\n\n${(0, i18n_1.t)('account.usageHint')}\n\n${openCodeSection}\n\n${buttonsHint}\n\n${(0, i18n_1.t)('account.autoSwitchHint')}`;
|
|
258
|
-
// One row per Claude account: pick it (✓ = where the topic runs), sign it in again, remove it (`default` too: signs it out).
|
|
323
|
+
// One row per Claude account: pick it (✓ = where the topic runs), sign it in again, remove it (`default` too: signs it out). Three
|
|
324
|
+
// buttons, no more: a phone splits a row's width evenly, and the pick must keep room for the account's name.
|
|
259
325
|
const keyboardRows = rows.map((row) => [
|
|
260
326
|
telegraf_1.Markup.button.callback(formatRowButton(row), (0, claudeAccountPickerPlan_1.buildAccountUseCallback)(row.name)),
|
|
261
327
|
telegraf_1.Markup.button.callback('🔑', (0, claudeAccountPickerPlan_1.buildAccountLoginCallback)(row.name)),
|
|
262
328
|
telegraf_1.Markup.button.callback('🗑', (0, claudeAccountPickerPlan_1.buildAccountRemoveCallback)(row.name)),
|
|
263
329
|
]);
|
|
330
|
+
// ✏️ once under the accounts: it opens the choice of the account to rename (its display name only).
|
|
331
|
+
if (rows.length > 0)
|
|
332
|
+
keyboardRows.push([telegraf_1.Markup.button.callback((0, i18n_1.t)('account.renameButton'), claudeAccountPickerPlan_1.accountRenameMenuCallback)]);
|
|
264
333
|
// A provider row mirrors it. In a topic its caption is the pick (the model page follows), 🔑 connects it again and
|
|
265
334
|
// 🔌 disconnects it; in General a provider can only be connected or disconnected: «🔌 Disconnect X» and 🔑.
|
|
266
335
|
providers.forEach((provider, index) => {
|
|
@@ -282,7 +351,7 @@ function createClaudeAccounts(ports) {
|
|
|
282
351
|
keyboardRows.push([telegraf_1.Markup.button.callback((0, i18n_1.t)('accounts.addClaudeApiButton'), claudeAccountPickerPlan_1.accountAddApiCallback)]);
|
|
283
352
|
if (!isGeneral && getState().getClaudeProfileOverride(key) !== undefined) {
|
|
284
353
|
keyboardRows.push([
|
|
285
|
-
telegraf_1.Markup.button.callback((0, i18n_1.t)('account.followButton', { name: getState().getClaudeProfileGlobalDefault() }), claudeAccountPickerPlan_1.accountFollowDefaultCallback),
|
|
354
|
+
telegraf_1.Markup.button.callback((0, i18n_1.t)('account.followButton', { name: (0, claudeProfileLabels_1.shortenClaudeProfileLabel)(formatLabel(getState().getClaudeProfileGlobalDefault())) }), claudeAccountPickerPlan_1.accountFollowDefaultCallback),
|
|
286
355
|
]);
|
|
287
356
|
}
|
|
288
357
|
return { text, keyboard: telegraf_1.Markup.inlineKeyboard(keyboardRows), providers };
|
|
@@ -294,10 +363,10 @@ function createClaudeAccounts(ports) {
|
|
|
294
363
|
if (messageId !== null)
|
|
295
364
|
rememberProviders(key, messageId, picker.providers);
|
|
296
365
|
}
|
|
297
|
-
/** A sub-picker: one button per profile (`default` included only when `includeDefault`), plus «Back». */
|
|
366
|
+
/** A sub-picker: one button per profile (`default` included only when `includeDefault`), named as the screen names it, plus «Back». */
|
|
298
367
|
function buildProfileChoiceKeyboard(buildCallback, includeDefault) {
|
|
299
368
|
const names = [...(includeDefault ? [claudeProfiles_1.defaultClaudeProfileName] : []), ...Object.keys(getState().getClaudeProfileRecords())];
|
|
300
|
-
const rows = names.map((name) => [telegraf_1.Markup.button.callback(name, buildCallback(name))]);
|
|
369
|
+
const rows = names.map((name) => [telegraf_1.Markup.button.callback((0, claudeProfileLabels_1.shortenClaudeProfileLabel)(formatLabel(name)), buildCallback(name))]);
|
|
301
370
|
rows.push([telegraf_1.Markup.button.callback((0, i18n_1.t)('account.backButton'), claudeAccountPickerPlan_1.accountBackCallback)]);
|
|
302
371
|
return telegraf_1.Markup.inlineKeyboard(rows);
|
|
303
372
|
}
|
|
@@ -328,7 +397,7 @@ function createClaudeAccounts(ports) {
|
|
|
328
397
|
const status = await readClaudeAuthStatus(resolveDir(name));
|
|
329
398
|
await recordProfileStatus(name, status);
|
|
330
399
|
if (status !== null && !status.loggedIn)
|
|
331
|
-
return (0, i18n_1.t)('account.notLoggedIn', { name });
|
|
400
|
+
return (0, i18n_1.t)('account.notLoggedIn', { name: formatLabel(name), login: formatCommandName(name) });
|
|
332
401
|
}
|
|
333
402
|
// An account billed to the API says so whenever it is picked: from now on that topic (or every topic following General) costs money per request.
|
|
334
403
|
const meteredNote = readBilling(name) === 'api' ? `\n${(0, i18n_1.t)(isGeneral ? 'account.pickedApiGeneral' : 'account.pickedApi')}` : '';
|
|
@@ -337,7 +406,7 @@ function createClaudeAccounts(ports) {
|
|
|
337
406
|
getState().liftClaudeProfileCreditExhaustion(name);
|
|
338
407
|
await getState().setClaudeProfileGlobalDefault(name);
|
|
339
408
|
await applyClaudeProfileEverywhere();
|
|
340
|
-
return `${(0, i18n_1.t)('account.setGlobal', { name })}${meteredNote}`;
|
|
409
|
+
return `${(0, i18n_1.t)('account.setGlobal', { name: formatLabel(name) })}${meteredNote}`;
|
|
341
410
|
}
|
|
342
411
|
const outcome = await switchTopicByOperator(key, { backend: 'claude', profile: name, model: null });
|
|
343
412
|
if (outcome.kind === 'asked')
|
|
@@ -349,30 +418,62 @@ function createClaudeAccounts(ports) {
|
|
|
349
418
|
await getState().setClaudeProfileOverride(key, null);
|
|
350
419
|
const name = getState().getClaudeProfileGlobalDefault();
|
|
351
420
|
const outcome = await applyClaudeProfile(key);
|
|
352
|
-
return (0, i18n_1.t)('account.followSet', { name, apply: describeApplyOutcome(outcome) });
|
|
421
|
+
return (0, i18n_1.t)('account.followSet', { name: formatLabel(name), apply: describeApplyOutcome(outcome) });
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* @description The id a new account with the display name `label` gets: the one typed by hand (`id:<id>`, lowercased), refused when it
|
|
425
|
+
* is no valid id or is taken; else derived from the name, a number added on a clash. Taken, both ways: a known id, `default`, another
|
|
426
|
+
* account's display name, or a folder already on disk — one the profile scan has not adopted yet holds whatever login it holds, and a
|
|
427
|
+
* new account must never start on it.
|
|
428
|
+
*/
|
|
429
|
+
function pickNewProfileId(label, explicitId, entries) {
|
|
430
|
+
const takenIds = new Set(entries.flatMap((entry) => [entry.name, ...entry.labels.map((known) => known.toLowerCase())]));
|
|
431
|
+
const checkIsTaken = (id) => takenIds.has(id) || (0, claudeProfiles_1.checkClaudeProfileDirExists)(getDataDir(), id);
|
|
432
|
+
if (explicitId !== null) {
|
|
433
|
+
const id = (0, claudeProfiles_1.normaliseClaudeProfileName)(explicitId);
|
|
434
|
+
const problem = (0, claudeProfileLabels_1.describeClaudeProfileIdProblem)(id);
|
|
435
|
+
if (problem !== null)
|
|
436
|
+
return { ok: false, refusal: describeIdProblem(problem) };
|
|
437
|
+
const owner = (0, claudeProfileLabels_1.findClaudeProfileByTypedName)(id, entries);
|
|
438
|
+
if (owner !== null || checkIsTaken(id))
|
|
439
|
+
return { ok: false, refusal: (0, i18n_1.t)('account.exists', { name: owner === null ? id : formatLabel(owner) }) };
|
|
440
|
+
return { ok: true, id };
|
|
441
|
+
}
|
|
442
|
+
return { ok: true, id: (0, claudeProfileLabels_1.deriveClaudeProfileId)(label, checkIsTaken) };
|
|
353
443
|
}
|
|
354
444
|
/**
|
|
355
|
-
* @description Create
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
445
|
+
* @description Create an account and start its sign-in: `rawLabel` is its display name (free text, {@link checkClaudeProfileLabel}),
|
|
446
|
+
* its fixed id derived from it unless typed by hand ({@link pickNewProfileId}); then the directory with its shared links, the registry
|
|
447
|
+
* record with the display name (flushed before the sign-in, so a crash never leaves a signed-in directory the picker cannot see), then
|
|
448
|
+
* the relay posts the link. An API account (`billing: 'api'`) is recorded as such and signs in to the Claude Console (`--console`), or
|
|
449
|
+
* takes a pasted API key. Returns the message to post BEFORE the link, or the refusal.
|
|
359
450
|
*/
|
|
360
|
-
async function addProfile(key,
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (
|
|
365
|
-
return (
|
|
451
|
+
async function addProfile(key, rawLabel, billing = 'subscription', explicitId = null) {
|
|
452
|
+
const label = (0, claudeProfileLabels_1.normaliseClaudeProfileLabel)(rawLabel);
|
|
453
|
+
const entries = listNameEntries();
|
|
454
|
+
const problem = (0, claudeProfileLabels_1.checkClaudeProfileLabel)({ label, selfName: null, accounts: entries });
|
|
455
|
+
if (problem !== null)
|
|
456
|
+
return describeLabelProblem(problem);
|
|
457
|
+
const picked = pickNewProfileId(label, explicitId, entries);
|
|
458
|
+
if (!picked.ok)
|
|
459
|
+
return picked.refusal;
|
|
460
|
+
const name = picked.id;
|
|
366
461
|
let configDir;
|
|
367
462
|
try {
|
|
368
463
|
configDir = (0, claudeProfiles_1.createClaudeProfileLayout)({ dataDir: getDataDir(), name });
|
|
369
464
|
}
|
|
370
465
|
catch (e) {
|
|
371
466
|
console.error(`[account] profile layout for ${name} failed:`, e instanceof Error ? e.message : e);
|
|
372
|
-
return (0, i18n_1.t)('account.createFailed', { name });
|
|
467
|
+
return (0, i18n_1.t)('account.createFailed', { name: label });
|
|
373
468
|
}
|
|
374
|
-
await getState().upsertClaudeProfileRecord(name, {
|
|
375
|
-
|
|
469
|
+
await getState().upsertClaudeProfileRecord(name, {
|
|
470
|
+
createdAt: new Date().toISOString(),
|
|
471
|
+
loggedIn: false,
|
|
472
|
+
...(label === name ? {} : { label }),
|
|
473
|
+
...(billing === 'api' ? { billing } : {}),
|
|
474
|
+
});
|
|
475
|
+
console.log(`[account] added the account ${name}${label === name ? '' : ` («${label}»)`}`);
|
|
476
|
+
await replyToThread(key, (0, i18n_1.t)(billing === 'api' ? 'account.createdApi' : 'account.created', { name: label }));
|
|
376
477
|
await startClaudeProfileLogin(key, { name, configDir, ...(billing === 'api' ? { billing } : {}) });
|
|
377
478
|
return '';
|
|
378
479
|
}
|
|
@@ -400,8 +501,10 @@ function createClaudeAccounts(ports) {
|
|
|
400
501
|
return signOutDefault();
|
|
401
502
|
if (!checkIsKnownProfile(name))
|
|
402
503
|
return (0, i18n_1.t)('account.unknown', { name });
|
|
504
|
+
// Read before the record goes: it carries the display name.
|
|
505
|
+
const label = formatLabel(name);
|
|
403
506
|
if (getState().getClaudeProfileGlobalDefault() === name)
|
|
404
|
-
return (0, i18n_1.t)('account.removeInstanceDefaultRefused', { name });
|
|
507
|
+
return (0, i18n_1.t)('account.removeInstanceDefaultRefused', { name: label });
|
|
405
508
|
// The directory goes FIRST: a folder with no record is what the profile scan adopts (`utils/claudeProfileSync.ts`), so a scan
|
|
406
509
|
// landing between the two steps — or a crash between them — would bring the profile back.
|
|
407
510
|
try {
|
|
@@ -412,7 +515,7 @@ function createClaudeAccounts(ports) {
|
|
|
412
515
|
}
|
|
413
516
|
const dropped = await getState().removeClaudeProfileRecord(name);
|
|
414
517
|
await applyClaudeProfileEverywhere();
|
|
415
|
-
return (0, i18n_1.t)('account.removed', { name, count: dropped.length });
|
|
518
|
+
return (0, i18n_1.t)('account.removed', { name: label, count: dropped.length });
|
|
416
519
|
}
|
|
417
520
|
/**
|
|
418
521
|
* @description «Remove» for `default`: sign `~/.claude` out (delete just its stored subscription login, see
|
|
@@ -426,42 +529,76 @@ function createClaudeAccounts(ports) {
|
|
|
426
529
|
}
|
|
427
530
|
catch (e) {
|
|
428
531
|
console.error('[account] signing the default account out failed:', e instanceof Error ? e.message : e);
|
|
429
|
-
return (0, i18n_1.t)('account.removeDefaultFailed');
|
|
532
|
+
return (0, i18n_1.t)('account.removeDefaultFailed', { name: formatLabel(claudeProfiles_1.defaultClaudeProfileName) });
|
|
430
533
|
}
|
|
431
534
|
await getState().upsertClaudeProfileRecord(claudeProfiles_1.defaultClaudeProfileName, { isRemoved: true, loggedIn: false });
|
|
432
535
|
console.log(`[account] the default account was signed out (${isSignedOut ? 'login deleted' : 'no stored login found'})`);
|
|
433
|
-
return (0, i18n_1.t)('account.removedDefault');
|
|
536
|
+
return (0, i18n_1.t)('account.removedDefault', { name: formatLabel(claudeProfiles_1.defaultClaudeProfileName), login: formatCommandName(claudeProfiles_1.defaultClaudeProfileName) });
|
|
434
537
|
}
|
|
435
538
|
/** The text of a removal confirmation and its Yes / Back keyboard. */
|
|
436
539
|
function buildRemoveConfirmation(name) {
|
|
437
540
|
const record = getState().getClaudeProfileRecord(name);
|
|
438
541
|
const count = getState().listClaudeProfileOverrideKeys(name).length;
|
|
542
|
+
const label = formatLabel(name);
|
|
543
|
+
const keyboard = telegraf_1.Markup.inlineKeyboard([
|
|
544
|
+
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.confirmRemoveButton', { name: (0, claudeProfileLabels_1.shortenClaudeProfileLabel)(label) }), (0, claudeAccountPickerPlan_1.buildAccountRemoveConfirmCallback)(name))],
|
|
545
|
+
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.backButton'), claudeAccountPickerPlan_1.accountBackCallback)],
|
|
546
|
+
]);
|
|
439
547
|
if (name === claudeProfiles_1.defaultClaudeProfileName) {
|
|
440
548
|
const email = getState().getClaudeProfileInfo(name)?.email ?? (0, i18n_1.t)('account.row.loggedOut');
|
|
441
|
-
return {
|
|
442
|
-
text: (0, i18n_1.t)('account.confirmRemoveDefault', { email }),
|
|
443
|
-
keyboard: telegraf_1.Markup.inlineKeyboard([
|
|
444
|
-
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.confirmRemoveButton', { name }), (0, claudeAccountPickerPlan_1.buildAccountRemoveConfirmCallback)(name))],
|
|
445
|
-
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.backButton'), claudeAccountPickerPlan_1.accountBackCallback)],
|
|
446
|
-
]),
|
|
447
|
-
};
|
|
549
|
+
return { text: (0, i18n_1.t)('account.confirmRemoveDefault', { name: label, email }), keyboard };
|
|
448
550
|
}
|
|
449
|
-
return {
|
|
450
|
-
text: (0, i18n_1.t)('account.confirmRemove', { name, email: record?.email ?? (0, i18n_1.t)('account.row.loggedOut'), count }),
|
|
451
|
-
keyboard: telegraf_1.Markup.inlineKeyboard([
|
|
452
|
-
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.confirmRemoveButton', { name }), (0, claudeAccountPickerPlan_1.buildAccountRemoveConfirmCallback)(name))],
|
|
453
|
-
[telegraf_1.Markup.button.callback((0, i18n_1.t)('account.backButton'), claudeAccountPickerPlan_1.accountBackCallback)],
|
|
454
|
-
]),
|
|
455
|
-
};
|
|
551
|
+
return { text: (0, i18n_1.t)('account.confirmRemove', { name: label, email: record?.email ?? (0, i18n_1.t)('account.row.loggedOut'), count }), keyboard };
|
|
456
552
|
}
|
|
457
|
-
// ── the «Add» name capture ──
|
|
458
|
-
/** Whether the topic's next plain message is a new
|
|
553
|
+
// ── the «Add» name capture and the ✏️ rename ──
|
|
554
|
+
/** Whether the topic's next plain message is a new account's name, a provider id or an account's new name (the text handler asks before forwarding). */
|
|
459
555
|
function checkIsAwaitingProfileName(key) {
|
|
460
556
|
return awaitingProfileName.has((0, sessionKey_1.keyToString)(key));
|
|
461
557
|
}
|
|
462
|
-
/** Disarm the capture (a slash command, `/esc`, a teardown). Returns
|
|
558
|
+
/** Disarm the capture (a slash command, `/esc`, a teardown). Returns what was armed — adding or renaming —, `null` for nothing. */
|
|
463
559
|
function cancelProfileNameCapture(key) {
|
|
464
|
-
|
|
560
|
+
const capture = awaitingProfileName.get((0, sessionKey_1.keyToString)(key));
|
|
561
|
+
if (capture === undefined)
|
|
562
|
+
return null;
|
|
563
|
+
awaitingProfileName.delete((0, sessionKey_1.keyToString)(key));
|
|
564
|
+
return capture.kind === 'rename' ? 'rename' : 'add';
|
|
565
|
+
}
|
|
566
|
+
/** An account picked in the ✏️ choice: ask for its new display name; the next plain message is it. */
|
|
567
|
+
async function askRename(key, name, pickerMessageId) {
|
|
568
|
+
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), { kind: 'rename', name, pickerMessageId });
|
|
569
|
+
await replyToThread(key, `${(0, i18n_1.t)('account.askRename', { name: formatLabel(name), max: claudeProfileLabels_1.claudeProfileLabelMaxLength })}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* @description The captured answer of ✏️: the account's new display name, checked by the same rules as a new account's (its own name
|
|
573
|
+
* and its own id are allowed; going back to its id drops the display name, `default` then shows «Main» again). A refused name keeps the
|
|
574
|
+
* capture armed; an API key is deleted and the name asked again. Only the display name changes — the id, the folder, every topic's pick,
|
|
575
|
+
* the `/limits` list and what agents recorded stay as they are. The screen the ✏️ sat on is re-rendered with the new name.
|
|
576
|
+
*/
|
|
577
|
+
async function submitRename(key, capture, text, messageId) {
|
|
578
|
+
if ((0, claudeProfiles_1.checkIsAnthropicSecretLike)(text)) {
|
|
579
|
+
if (messageId !== undefined)
|
|
580
|
+
await deleteThreadMessage(key, messageId);
|
|
581
|
+
await replyToThread(key, `${(0, i18n_1.t)('account.apiKeyAsLabel')}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const { name } = capture;
|
|
585
|
+
if (!checkIsKnownProfile(name)) {
|
|
586
|
+
awaitingProfileName.delete((0, sessionKey_1.keyToString)(key));
|
|
587
|
+
await replyToThread(key, (0, i18n_1.t)('account.unknown', { name }));
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const label = (0, claudeProfileLabels_1.normaliseClaudeProfileLabel)(text);
|
|
591
|
+
const problem = (0, claudeProfileLabels_1.checkClaudeProfileLabel)({ label, selfName: name, accounts: listNameEntries() });
|
|
592
|
+
if (problem !== null) {
|
|
593
|
+
await replyToThread(key, `${describeLabelProblem(problem)}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
awaitingProfileName.delete((0, sessionKey_1.keyToString)(key));
|
|
597
|
+
const previous = formatLabel(name);
|
|
598
|
+
await getState().setClaudeProfileLabel(name, label === name ? null : label);
|
|
599
|
+
console.log(`[account] the account ${name} is now called ${label === name ? 'by its id' : `«${label}»`}`);
|
|
600
|
+
await replyToThread(key, (0, i18n_1.t)('account.renamed', { old: previous, name: formatLabel(name) }));
|
|
601
|
+
await rerenderPicker(key, capture.pickerMessageId, checkIsGeneral(key));
|
|
465
602
|
}
|
|
466
603
|
/** The captured provider id: start the `/connect` flow for it; a bad id keeps the capture armed. */
|
|
467
604
|
async function submitProviderId(key, text) {
|
|
@@ -480,23 +617,29 @@ function createClaudeAccounts(ports) {
|
|
|
480
617
|
*/
|
|
481
618
|
async function submitProfileName(key, text, messageId) {
|
|
482
619
|
const asked = awaitingProfileName.get((0, sessionKey_1.keyToString)(key));
|
|
483
|
-
if (asked === 'providerId') {
|
|
620
|
+
if (asked?.kind === 'providerId') {
|
|
484
621
|
await submitProviderId(key, text);
|
|
485
622
|
return;
|
|
486
623
|
}
|
|
624
|
+
if (asked?.kind === 'rename') {
|
|
625
|
+
await submitRename(key, asked, text, messageId);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
487
628
|
if ((0, claudeProfiles_1.checkIsAnthropicSecretLike)(text)) {
|
|
488
629
|
if (messageId !== undefined)
|
|
489
630
|
await deleteThreadMessage(key, messageId);
|
|
490
|
-
await replyToThread(key, `${(0, i18n_1.t)('account.apiKeyAsName', { max:
|
|
631
|
+
await replyToThread(key, `${(0, i18n_1.t)('account.apiKeyAsName', { max: claudeProfileLabels_1.claudeProfileLabelMaxLength })}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
491
632
|
return;
|
|
492
633
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
634
|
+
// The name is checked first: a refused one keeps the prompt armed for the next try.
|
|
635
|
+
const label = (0, claudeProfileLabels_1.normaliseClaudeProfileLabel)(text);
|
|
636
|
+
const problem = (0, claudeProfileLabels_1.checkClaudeProfileLabel)({ label, selfName: null, accounts: listNameEntries() });
|
|
637
|
+
if (problem !== null) {
|
|
638
|
+
await replyToThread(key, `${describeLabelProblem(problem)}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
496
639
|
return;
|
|
497
640
|
}
|
|
498
641
|
awaitingProfileName.delete((0, sessionKey_1.keyToString)(key));
|
|
499
|
-
const message = await addProfile(key,
|
|
642
|
+
const message = await addProfile(key, label, asked?.kind === 'claudeApiName' ? 'api' : 'subscription');
|
|
500
643
|
if (message)
|
|
501
644
|
await replyToThread(key, message);
|
|
502
645
|
}
|
|
@@ -546,10 +689,10 @@ function createClaudeAccounts(ports) {
|
|
|
546
689
|
}
|
|
547
690
|
// ── the command ──
|
|
548
691
|
function registerClaudeAccountCommands() {
|
|
549
|
-
// `/accounts` (hidden alias `/account`) — bare: the screen. `add <name>` creates
|
|
550
|
-
// an account billed to a Claude Console organization's API balance); `use <name>`
|
|
551
|
-
// this topic (General: the
|
|
552
|
-
//
|
|
692
|
+
// `/accounts` (hidden alias `/account`) — bare: the screen. `add <name>` creates an account under that display name and signs it in
|
|
693
|
+
// (`add <name> api`: an account billed to a Claude Console organization's API balance; `id:<id>` picks its fixed id by hand); `use <name>`
|
|
694
|
+
// switches this topic (General: the account for all topics); `login <name>` signs an account in again; `remove <name>` deletes one —
|
|
695
|
+
// `<name>` is a display name or an id, case ignored. Not gated on a session: the pick is read at the next spawn, so it must be settable first.
|
|
553
696
|
command(['account', 'accounts'], async (ctx, key, parsed) => {
|
|
554
697
|
// A key typed on the command line (`/accounts add console api sk-ant-…`) is a secret like a pasted one: the message
|
|
555
698
|
// is deleted, the key never echoed nor taken — it belongs to the sign-in that follows.
|
|
@@ -560,63 +703,66 @@ function createClaudeAccounts(ports) {
|
|
|
560
703
|
}
|
|
561
704
|
const isGeneral = checkIsGeneral(key);
|
|
562
705
|
const [verb = '', ...rest] = parsed.args;
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const isApiAdd = verb.toLowerCase() === 'add' && rest.length >= 2 && rest.at(-1)?.toLowerCase() === 'api';
|
|
706
|
+
// A display name or an id, as typed (the lookup ignores case and spacing).
|
|
707
|
+
const typed = rest.join(' ').trim();
|
|
566
708
|
switch (verb.toLowerCase()) {
|
|
567
709
|
case '': {
|
|
568
710
|
await postPicker(key, isGeneral);
|
|
569
711
|
return;
|
|
570
712
|
}
|
|
571
713
|
case 'add': {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
awaitingProfileName.set((0, sessionKey_1.keyToString)(key),
|
|
575
|
-
await replyToThread(key, `${(0, i18n_1.t)(
|
|
714
|
+
const request = parseAccountAddWords(rest);
|
|
715
|
+
if (request.label === '' && request.explicitId === null) {
|
|
716
|
+
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), { kind: request.isApi ? 'claudeApiName' : 'claudeName' });
|
|
717
|
+
await replyToThread(key, `${(0, i18n_1.t)(request.isApi ? 'account.askNameApi' : 'account.askName', { max: claudeProfileLabels_1.claudeProfileLabelMaxLength })}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
576
718
|
return;
|
|
577
719
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
: await addProfile(key, name);
|
|
720
|
+
// `add id:<id>` alone: the id is the name too.
|
|
721
|
+
const message = await addProfile(key, request.label || (request.explicitId ?? ''), request.isApi ? 'api' : 'subscription', request.explicitId);
|
|
581
722
|
if (message)
|
|
582
723
|
await replyToThread(key, message);
|
|
583
724
|
return;
|
|
584
725
|
}
|
|
585
726
|
case 'use': {
|
|
586
|
-
if (!
|
|
727
|
+
if (!typed) {
|
|
587
728
|
await replyToThread(key, (0, i18n_1.t)('account.usage'));
|
|
588
729
|
return;
|
|
589
730
|
}
|
|
590
|
-
|
|
591
|
-
|
|
731
|
+
// An account first: a display name may hold a `/` too.
|
|
732
|
+
const profile = findTypedProfile(typed);
|
|
733
|
+
if (profile === null && typed.includes('/')) {
|
|
734
|
+
await applyTypedOpenCodePick(key, isGeneral, typed);
|
|
592
735
|
return;
|
|
593
736
|
}
|
|
594
|
-
const confirmation = await applyPick(key, isGeneral,
|
|
737
|
+
const confirmation = profile === null ? (0, i18n_1.t)('account.unknown', { name: typed }) : await applyPick(key, isGeneral, profile);
|
|
595
738
|
if (confirmation !== null)
|
|
596
739
|
await replyToThread(key, confirmation);
|
|
597
740
|
return;
|
|
598
741
|
}
|
|
599
742
|
case 'login': {
|
|
600
|
-
const
|
|
743
|
+
const profile = typed === '' ? claudeProfiles_1.defaultClaudeProfileName : findTypedProfile(typed);
|
|
744
|
+
const message = profile === null ? (0, i18n_1.t)('account.unknown', { name: typed }) : await loginProfile(key, profile);
|
|
601
745
|
if (message)
|
|
602
746
|
await replyToThread(key, message);
|
|
603
747
|
return;
|
|
604
748
|
}
|
|
605
749
|
case 'remove':
|
|
606
750
|
case 'rm': {
|
|
607
|
-
if (!
|
|
751
|
+
if (!typed) {
|
|
608
752
|
await replyToThread(key, (0, i18n_1.t)('account.usage'));
|
|
609
753
|
return;
|
|
610
754
|
}
|
|
611
|
-
|
|
755
|
+
const profile = findTypedProfile(typed);
|
|
756
|
+
await replyToThread(key, profile === null ? (0, i18n_1.t)('account.unknown', { name: typed }) : await removeProfile(profile));
|
|
612
757
|
return;
|
|
613
758
|
}
|
|
614
759
|
case 'autoswitch': {
|
|
615
|
-
|
|
760
|
+
const value = typed.toLowerCase();
|
|
761
|
+
if (value !== 'on' && value !== 'off') {
|
|
616
762
|
await replyToThread(key, (0, i18n_1.t)('account.usage'));
|
|
617
763
|
return;
|
|
618
764
|
}
|
|
619
|
-
await replyToThread(key, await applyAutoSwitch(key, isGeneral,
|
|
765
|
+
await replyToThread(key, await applyAutoSwitch(key, isGeneral, value === 'on'));
|
|
620
766
|
return;
|
|
621
767
|
}
|
|
622
768
|
default:
|
|
@@ -656,17 +802,17 @@ function createClaudeAccounts(ports) {
|
|
|
656
802
|
await rerenderPicker(key, messageId, isGeneral);
|
|
657
803
|
}));
|
|
658
804
|
bot.action(claudeAccountPickerPlan_1.accountAddCallback, (ctx) => handleTap(ctx, async (key) => {
|
|
659
|
-
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), 'claudeName');
|
|
805
|
+
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), { kind: 'claudeName' });
|
|
660
806
|
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx);
|
|
661
|
-
await replyToThread(key, `${(0, i18n_1.t)('account.askName', { max:
|
|
807
|
+
await replyToThread(key, `${(0, i18n_1.t)('account.askName', { max: claudeProfileLabels_1.claudeProfileLabelMaxLength })}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
662
808
|
}));
|
|
663
809
|
bot.action(claudeAccountPickerPlan_1.accountAddApiCallback, (ctx) => handleTap(ctx, async (key) => {
|
|
664
|
-
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), 'claudeApiName');
|
|
810
|
+
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), { kind: 'claudeApiName' });
|
|
665
811
|
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx);
|
|
666
|
-
await replyToThread(key, `${(0, i18n_1.t)('account.askNameApi', { max:
|
|
812
|
+
await replyToThread(key, `${(0, i18n_1.t)('account.askNameApi', { max: claudeProfileLabels_1.claudeProfileLabelMaxLength })}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
667
813
|
}));
|
|
668
814
|
bot.action(claudeAccountPickerPlan_1.accountAddProviderCallback, (ctx) => handleTap(ctx, async (key) => {
|
|
669
|
-
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), 'providerId');
|
|
815
|
+
awaitingProfileName.set((0, sessionKey_1.keyToString)(key), { kind: 'providerId' });
|
|
670
816
|
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx);
|
|
671
817
|
await replyToThread(key, `${(0, i18n_1.t)('accounts.askProvider')}\n${(0, i18n_1.t)('login.esc_hint')}`);
|
|
672
818
|
}));
|
|
@@ -799,6 +945,24 @@ function createClaudeAccounts(ports) {
|
|
|
799
945
|
if (message)
|
|
800
946
|
await replyToThread(key, message);
|
|
801
947
|
}));
|
|
948
|
+
// «✏️ Rename an account» → the choice of the account, in the screen's own message (Back returns to the screen).
|
|
949
|
+
bot.action(claudeAccountPickerPlan_1.accountRenameMenuCallback, (ctx) => handleTap(ctx, async (key, _isGeneral, messageId) => {
|
|
950
|
+
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx);
|
|
951
|
+
if (messageId !== null)
|
|
952
|
+
await editThreadMessage(key, messageId, (0, i18n_1.t)('account.pickRename'), buildProfileChoiceKeyboard(claudeAccountPickerPlan_1.buildAccountRenameCallback, true));
|
|
953
|
+
}));
|
|
954
|
+
// An account of the choice (or an older screen's ✏️) → the choice turns back into the screen and the account's new display name is
|
|
955
|
+
// asked; once it is set the screen is re-rendered with it.
|
|
956
|
+
bot.action(claudeAccountPickerPlan_1.accountRenameCallbackRe, (ctx) => handleTap(ctx, async (key, isGeneral, messageId) => {
|
|
957
|
+
const name = (0, claudeAccountPickerPlan_1.parseAccountCallbackName)(ctx.match[0], claudeAccountPickerPlan_1.accountRenameCallbackRe, { allowDefault: true });
|
|
958
|
+
if (name === null || !checkIsKnownProfile(name)) {
|
|
959
|
+
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx, (0, i18n_1.t)('account.unknown', { name: name ?? '?' }));
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
await (0, callbackToast_1.answerCallbackQuerySafely)(ctx);
|
|
963
|
+
await rerenderPicker(key, messageId, isGeneral);
|
|
964
|
+
await askRename(key, name, messageId);
|
|
965
|
+
}));
|
|
802
966
|
bot.action(claudeAccountPickerPlan_1.accountRemoveCallbackRe, (ctx) => handleTap(ctx, async (key, _isGeneral, messageId) => {
|
|
803
967
|
const name = (0, claudeAccountPickerPlan_1.parseAccountCallbackName)(ctx.match[0], claudeAccountPickerPlan_1.accountRemoveCallbackRe, { allowDefault: true });
|
|
804
968
|
if (name === null || !checkIsKnownProfile(name)) {
|