Skip to content

Commit d831b8e

Browse files
committed
chore: dedupe non-interactive setup prompters
1 parent 8e9d5c4 commit d831b8e

3 files changed

Lines changed: 57 additions & 90 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { RuntimeEnv } from "../runtime.js";
2+
import type { WizardPrompter } from "../wizard/prompts.js";
3+
4+
export function createNonInteractiveLoggingPrompter(
5+
runtime: RuntimeEnv,
6+
formatPromptError: (message: string) => string,
7+
): WizardPrompter {
8+
const unavailable = <T>(message: string): Promise<T> =>
9+
Promise.reject(new Error(formatPromptError(message)));
10+
return {
11+
async intro(title) {
12+
runtime.log(title);
13+
},
14+
async outro(message) {
15+
runtime.log(message);
16+
},
17+
async note(message, title) {
18+
runtime.log(title ? `${title}\n${message}` : message);
19+
},
20+
async select(params) {
21+
return unavailable(params.message);
22+
},
23+
async multiselect(params) {
24+
return unavailable(params.message);
25+
},
26+
async text(params) {
27+
return unavailable(params.message);
28+
},
29+
async confirm(params) {
30+
return unavailable(params.message);
31+
},
32+
progress(label) {
33+
runtime.log(label);
34+
return {
35+
update(message) {
36+
runtime.log(message);
37+
},
38+
stop(message) {
39+
if (message) {
40+
runtime.log(message);
41+
}
42+
},
43+
};
44+
},
45+
};
46+
}

src/commands/onboard-non-interactive.ts

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,11 @@ import { logConfigUpdated } from "../config/logging.js";
55
import type { OpenClawConfig } from "../config/types.openclaw.js";
66
import type { RuntimeEnv } from "../runtime.js";
77
import { defaultRuntime } from "../runtime.js";
8-
import type { WizardPrompter } from "../wizard/prompts.js";
8+
import { createNonInteractiveLoggingPrompter } from "./non-interactive-prompter.js";
99
import { runNonInteractiveLocalSetup } from "./onboard-non-interactive/local.js";
1010
import { runNonInteractiveRemoteSetup } from "./onboard-non-interactive/remote.js";
1111
import type { OnboardOptions } from "./onboard-types.js";
1212

13-
function createNonInteractiveMigrationPrompter(runtime: RuntimeEnv): WizardPrompter {
14-
const unavailable = <T>(message: string): Promise<T> =>
15-
Promise.reject(
16-
new Error(
17-
`Non-interactive migration import needs explicit flags before prompting: ${message}`,
18-
),
19-
);
20-
return {
21-
async intro(title) {
22-
runtime.log(title);
23-
},
24-
async outro(message) {
25-
runtime.log(message);
26-
},
27-
async note(message, title) {
28-
runtime.log(title ? `${title}\n${message}` : message);
29-
},
30-
async select(params) {
31-
return unavailable(params.message);
32-
},
33-
async multiselect(params) {
34-
return unavailable(params.message);
35-
},
36-
async text(params) {
37-
return unavailable(params.message);
38-
},
39-
async confirm(params) {
40-
return unavailable(params.message);
41-
},
42-
progress(label) {
43-
runtime.log(label);
44-
return {
45-
update(message) {
46-
runtime.log(message);
47-
},
48-
stop(message) {
49-
if (message) {
50-
runtime.log(message);
51-
}
52-
},
53-
};
54-
},
55-
};
56-
}
57-
5813
async function runNonInteractiveMigrationImport(params: {
5914
opts: OnboardOptions;
6015
runtime: RuntimeEnv;
@@ -79,7 +34,11 @@ async function runNonInteractiveMigrationImport(params: {
7934
opts: { ...params.opts, importFrom: providerId, nonInteractive: true },
8035
baseConfig: params.baseConfig,
8136
detections,
82-
prompter: createNonInteractiveMigrationPrompter(params.runtime),
37+
prompter: createNonInteractiveLoggingPrompter(
38+
params.runtime,
39+
(message) =>
40+
`Non-interactive migration import needs explicit flags before prompting: ${message}`,
41+
),
8342
runtime: params.runtime,
8443
async commitConfigFile(config) {
8544
await replaceConfigFile({

src/commands/onboard-non-interactive/local/auth-choice.plugin-providers.ts

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import type {
1717
} from "../../../plugins/types.js";
1818
import type { RuntimeEnv } from "../../../runtime.js";
1919
import { createLazyRuntimeSurface } from "../../../shared/lazy-runtime.js";
20-
import type { WizardPrompter } from "../../../wizard/prompts.js";
2120
import {
2221
CODEX_RUNTIME_PLUGIN_ID,
2322
ensureCodexRuntimePluginForModelSelection,
2423
} from "../../codex-runtime-plugin-install.js";
24+
import { createNonInteractiveLoggingPrompter } from "../../non-interactive-prompter.js";
2525
import type { OnboardOptions } from "../../onboard-types.js";
2626

2727
const PROVIDER_PLUGIN_CHOICE_PREFIX = "provider-plugin:";
@@ -35,47 +35,6 @@ const loadAuthChoicePluginProvidersRuntime = createLazyRuntimeSurface(
3535
({ authChoicePluginProvidersRuntime }) => authChoicePluginProvidersRuntime,
3636
);
3737

38-
function createNonInteractivePluginInstallPrompter(runtime: RuntimeEnv): WizardPrompter {
39-
const unavailable = <T>(message: string): Promise<T> =>
40-
Promise.reject(new Error(`Non-interactive setup cannot prompt for plugin install: ${message}`));
41-
return {
42-
async intro(title) {
43-
runtime.log(title);
44-
},
45-
async outro(message) {
46-
runtime.log(message);
47-
},
48-
async note(message, title) {
49-
runtime.log(title ? `${title}\n${message}` : message);
50-
},
51-
async select(params) {
52-
return unavailable(params.message);
53-
},
54-
async multiselect(params) {
55-
return unavailable(params.message);
56-
},
57-
async text(params) {
58-
return unavailable(params.message);
59-
},
60-
async confirm(params) {
61-
return unavailable(params.message);
62-
},
63-
progress(label) {
64-
runtime.log(label);
65-
return {
66-
update(message) {
67-
runtime.log(message);
68-
},
69-
stop(message) {
70-
if (message) {
71-
runtime.log(message);
72-
}
73-
},
74-
};
75-
},
76-
};
77-
}
78-
7938
export async function applyNonInteractivePluginProviderChoice(params: {
8039
nextConfig: OpenClawConfig;
8140
authChoice: string;
@@ -204,7 +163,10 @@ export async function applyNonInteractivePluginProviderChoice(params: {
204163
if (!selectedModel) {
205164
return result;
206165
}
207-
const nonInteractivePrompter = createNonInteractivePluginInstallPrompter(params.runtime);
166+
const nonInteractivePrompter = createNonInteractiveLoggingPrompter(
167+
params.runtime,
168+
(message) => `Non-interactive setup cannot prompt for plugin install: ${message}`,
169+
);
208170
const codexInstall = await ensureCodexRuntimePluginForModelSelection({
209171
cfg: result,
210172
model: selectedModel,

0 commit comments

Comments
 (0)