mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 11:02:12 +03:00
refactor(onboarding): share promptAccountId helper
This commit is contained in:
@@ -1,44 +1 @@
|
|||||||
import type { OpenClawConfig, WizardPrompter } from "openclaw/plugin-sdk";
|
export { promptAccountId } from "openclaw/plugin-sdk";
|
||||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
||||||
|
|
||||||
type PromptAccountIdParams = {
|
|
||||||
cfg: OpenClawConfig;
|
|
||||||
prompter: WizardPrompter;
|
|
||||||
label: string;
|
|
||||||
currentId?: string;
|
|
||||||
listAccountIds: (cfg: OpenClawConfig) => string[];
|
|
||||||
defaultAccountId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function promptAccountId(params: PromptAccountIdParams): Promise<string> {
|
|
||||||
const existingIds = params.listAccountIds(params.cfg);
|
|
||||||
const initial = params.currentId?.trim() || params.defaultAccountId || DEFAULT_ACCOUNT_ID;
|
|
||||||
const choice = await params.prompter.select({
|
|
||||||
message: `${params.label} account`,
|
|
||||||
options: [
|
|
||||||
...existingIds.map((id) => ({
|
|
||||||
value: id,
|
|
||||||
label: id === DEFAULT_ACCOUNT_ID ? "default (primary)" : id,
|
|
||||||
})),
|
|
||||||
{ value: "__new__", label: "Add a new account" },
|
|
||||||
],
|
|
||||||
initialValue: initial,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (choice !== "__new__") {
|
|
||||||
return normalizeAccountId(choice);
|
|
||||||
}
|
|
||||||
|
|
||||||
const entered = await params.prompter.text({
|
|
||||||
message: `New ${params.label} account id`,
|
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
|
||||||
});
|
|
||||||
const normalized = normalizeAccountId(String(entered));
|
|
||||||
if (String(entered).trim() !== normalized) {
|
|
||||||
await params.prompter.note(
|
|
||||||
`Normalized account id to "${normalized}".`,
|
|
||||||
`${params.label} account`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,37 +1,8 @@
|
|||||||
import type { PromptAccountId, PromptAccountIdParams } from "../onboarding-types.js";
|
import type { PromptAccountId, PromptAccountIdParams } from "../onboarding-types.js";
|
||||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js";
|
import { promptAccountId as promptAccountIdSdk } from "../../../plugin-sdk/onboarding.js";
|
||||||
|
|
||||||
export const promptAccountId: PromptAccountId = async (params: PromptAccountIdParams) => {
|
export const promptAccountId: PromptAccountId = async (params: PromptAccountIdParams) => {
|
||||||
const existingIds = params.listAccountIds(params.cfg);
|
return await promptAccountIdSdk(params);
|
||||||
const initial = params.currentId?.trim() || params.defaultAccountId || DEFAULT_ACCOUNT_ID;
|
|
||||||
const choice = await params.prompter.select({
|
|
||||||
message: `${params.label} account`,
|
|
||||||
options: [
|
|
||||||
...existingIds.map((id) => ({
|
|
||||||
value: id,
|
|
||||||
label: id === DEFAULT_ACCOUNT_ID ? "default (primary)" : id,
|
|
||||||
})),
|
|
||||||
{ value: "__new__", label: "Add a new account" },
|
|
||||||
],
|
|
||||||
initialValue: initial,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (choice !== "__new__") {
|
|
||||||
return normalizeAccountId(choice);
|
|
||||||
}
|
|
||||||
|
|
||||||
const entered = await params.prompter.text({
|
|
||||||
message: `New ${params.label} account id`,
|
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
|
||||||
});
|
|
||||||
const normalized = normalizeAccountId(String(entered));
|
|
||||||
if (String(entered).trim() !== normalized) {
|
|
||||||
await params.prompter.note(
|
|
||||||
`Normalized account id to "${normalized}".`,
|
|
||||||
`${params.label} account`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return normalized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function addWildcardAllowFrom(
|
export function addWildcardAllowFrom(
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||||
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||||
|
|
||||||
|
export type PromptAccountIdParams = {
|
||||||
|
cfg: OpenClawConfig;
|
||||||
|
prompter: WizardPrompter;
|
||||||
|
label: string;
|
||||||
|
currentId?: string;
|
||||||
|
listAccountIds: (cfg: OpenClawConfig) => string[];
|
||||||
|
defaultAccountId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function promptAccountId(params: PromptAccountIdParams): Promise<string> {
|
||||||
|
const existingIds = params.listAccountIds(params.cfg);
|
||||||
|
const initial = params.currentId?.trim() || params.defaultAccountId || DEFAULT_ACCOUNT_ID;
|
||||||
|
const choice = await params.prompter.select({
|
||||||
|
message: `${params.label} account`,
|
||||||
|
options: [
|
||||||
|
...existingIds.map((id) => ({
|
||||||
|
value: id,
|
||||||
|
label: id === DEFAULT_ACCOUNT_ID ? "default (primary)" : id,
|
||||||
|
})),
|
||||||
|
{ value: "__new__", label: "Add a new account" },
|
||||||
|
],
|
||||||
|
initialValue: initial,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (choice !== "__new__") {
|
||||||
|
return normalizeAccountId(choice);
|
||||||
|
}
|
||||||
|
|
||||||
|
const entered = await params.prompter.text({
|
||||||
|
message: `New ${params.label} account id`,
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
const normalized = normalizeAccountId(String(entered));
|
||||||
|
if (String(entered).trim() !== normalized) {
|
||||||
|
await params.prompter.note(
|
||||||
|
`Normalized account id to "${normalized}".`,
|
||||||
|
`${params.label} account`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user