UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

9 lines • 11.7 kB
import{o as writeRuntimeJson}from"./runtime-DIcLIHcp.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{n as stylePromptMessage,r as stylePromptTitle,t as stylePromptHint}from"./prompt-style-B-J86yY8.mjs";import{r as promptYesNo}from"./prompt-BGeJBE18.mjs";import{r as withProgress}from"./progress-BcNIavn6.mjs";import{h as redactMigrationPlan,v as summarizeMigrationItems}from"./migration-B8ObiJfa.mjs";import{t as withPluginMigrationProviders}from"./migration-provider-runtime-lHLy-ONV.mjs";import{i as formatMigrationPreview}from"./output-DFtq0v4l.mjs";import{n as createMigrationPlan,r as withMigrationProvider}from"./providers-BYDOHUEE.mjs";import{a as applyMigrationSelectedItemIds,c as formatMigrationSelectionLabel,d as reconcileInteractiveMigrationEnterValues,f as reconcileInteractiveMigrationShortcutValues,i as MIGRATION_SELECTION_TOGGLE_ALL_ON,l as getDefaultMigrationSelectionValues,m as resolveInteractiveMigrationSelection,n as MIGRATION_SELECTION_ACCEPT,o as applyMigrationSelections,p as reconcileInteractiveMigrationSkillToggleValues,r as MIGRATION_SELECTION_TOGGLE_ALL_OFF,s as formatMigrationSelectionHint,t as runMigrationApply,u as getSelectableMigrationItems}from"./apply-Ds3-dMvM.mjs";import{styleText}from"node:util";import{S_BAR,S_BAR_END,S_CHECKBOX_ACTIVE,S_CHECKBOX_INACTIVE,S_CHECKBOX_SELECTED,cancel,confirm,isCancel,limitOptions,log,symbol,symbolBar}from"@clack/prompts";import{MultiSelectPrompt,settings as settings$1,wrapTextWithPrefix}from"@clack/core"; //!src/commands/migrate/skill-selection-prompt.ts function formatOption(e,t){const n=e.label??e.value;const r=e.hint?`${n} ${styleText(`dim`,`(${e.hint})`)}`:n;switch(t){case`active`:return`${styleText(`cyan`,S_CHECKBOX_ACTIVE)} ${r}`;case`active-selected`:return`${styleText(`green`,S_CHECKBOX_SELECTED)} ${r}`;case`cancelled`:return styleText([`strikethrough`,`dim`],n);case`selected`:return`${styleText(`green`,S_CHECKBOX_SELECTED)} ${styleText(`dim`,r)}`;case`submitted`:return styleText(`dim`,n);default:return`${styleText(`dim`,S_CHECKBOX_INACTIVE)} ${styleText(`dim`,r)}`}}function promptMigrationSkillSelectionValues(e){const t=new MultiSelectPrompt({options:e.options,input:e.input,output:e.output,initialValues:e.initialValues,cursorAt:e.cursorAt,render(){const t=e.withGuide??settings$1.withGuide;const n=wrapTextWithPrefix(e.output,e.message,t?`${symbolBar(this.state)} `:``,`${symbol(this.state)} `);const r=`${t?`${styleText(`gray`,S_BAR)}\n`:``}${n}\n`;const i=this.value??[];const optionState=(e,t)=>{const n=i.includes(e.value);if(t&&n)return formatOption(e,`active-selected`);if(n)return formatOption(e,`selected`);return formatOption(e,t?`active`:`inactive`)};switch(this.state){case`submit`:case`cancel`:{const n=this.options.filter(e=>i.includes(e.value)).map(e=>formatOption(e,this.state===`submit`?`submitted`:`cancelled`)).join(styleText(`dim`,`, `));if(this.state===`submit`){const i=n||styleText(`dim`,`none`);return`${r}${wrapTextWithPrefix(e.output,i,t?`${styleText(`gray`,S_BAR)} `:``)}`}if(n.trim()===``)return`${r}${styleText(`gray`,S_BAR)}`;return`${r}${wrapTextWithPrefix(e.output,n,t?`${styleText(`gray`,S_BAR)} `:``)}${t?`\n${styleText(`gray`,S_BAR)}`:``}`}default:{const n=t?`${styleText(`cyan`,S_BAR)} `:``;return`${r}${n}${limitOptions({output:e.output,options:this.options,cursor:this.cursor,columnPadding:n.length,rowPadding:r.split(` `).length+(t?2:1),style:optionState}).join(`\n${n}`)}\n${t?styleText(`cyan`,S_BAR_END):``}\n`}}}});let n=[...t.value??[]];let r;t.on(`cursor`,i=>{if(i!==`space`){r=void 0;return}const a=t.options[t.cursor]?.value;if(a===`__openclaw_migrate_accept_recommended__`){t.value=[...e.initialValues??[]];r=void 0;n=[...t.value??[]];return}const o=n;const s=t.value??[];t.value=reconcileInteractiveMigrationSkillToggleValues(s,a,e.selectableValues);r=a!==void 0&&e.selectableValues.includes(a)&&o.includes(a)&&!(t.value??[]).includes(a)?a:void 0;n=[...t.value??[]]});t.on(`key`,(i,a)=>{if(a.name===`return`){const i=t.options[t.cursor]?.value;if(i===`__openclaw_migrate_accept_recommended__`)t.value=[...e.initialValues??[]];else t.value=reconcileInteractiveMigrationEnterValues(t.value??[],i,e.selectableValues,{preserveDeselectedActivatedValue:i!==void 0&&i===r&&!(t.value??[]).includes(i)});r=void 0;n=[...t.value??[]];return}if(i!==`a`&&i!==`i`)return;t.value=reconcileInteractiveMigrationShortcutValues(n,t.value??[],e.selectableValues,i);r=void 0;n=[...t.value??[]]});return t.prompt()} //!src/commands/migrate.ts function isAuthCredentialItem(e){return e.kind===`auth`||e.kind===`secret`||e.sensitive===true}function resolveDefaultIncludeSecrets(e){if(e.authCredentials===false)return{...e,includeSecrets:false};return e}function shouldPromptForAuthCredentials(e){return e.includeSecrets===void 0&&e.authCredentials!==false&&!e.yes&&!e.json&&process.stdin.isTTY}async function createInteractiveMigrationPlanWithAuthPrompt(e,t,n){if(!shouldPromptForAuthCredentials(t))return await migratePlanCommand(e,resolveDefaultIncludeSecrets(t),n);const scan=r=>migratePlanCommand(e,{...t,includeSecrets:r,suppressPlanLog:true},n);let r=await scan(false);if(r.items.some(isAuthCredentialItem)){const t=await confirm({message:stylePromptMessage(`Do you want to migrate your auth credentials as well?`),initialValue:true});if(isCancel(t)){cancel(stylePromptTitle(`Migration cancelled.`)??`Migration cancelled.`);e.exit(0);throw new Error(`unreachable`)}if(t)r=await scan(true)}if(!t.suppressPlanLog)log.message(formatMigrationPreview(r).join(` `));return r}function assertVerifyPluginAppsProvider(e,t){if(t.verifyPluginApps&&e!==`codex`)throw new Error(`--verify-plugin-apps is only supported for Codex migrations.`)}async function promptCodexMigrationSelection(e,t,n,r){if(t.providerId!==`codex`||n.yes||n.json||n[r]!==void 0||!process.stdin.isTTY)return t;const i=r===`skills`;const a=i?`skill`:`plugin`;const o=getSelectableMigrationItems(t,a);if(o.length===0)return t;const s=await promptMigrationSkillSelectionValues({message:stylePromptMessage(i?`Select Codex skills to migrate into this agent`:`Select native Codex plugins to activate in this agent`),options:[{value:MIGRATION_SELECTION_ACCEPT,label:`Accept recommended`,hint:i?`Migrate every recommended skill`:`Migrate every recommended plugin`},...o.map(e=>{const t=formatMigrationSelectionHint(e,a);return{value:e.id,label:formatMigrationSelectionLabel(e,a),hint:t===void 0?void 0:stylePromptHint(t)}}),{value:MIGRATION_SELECTION_TOGGLE_ALL_ON,label:`Toggle all on`},{value:MIGRATION_SELECTION_TOGGLE_ALL_OFF,label:`Toggle all off`}],initialValues:getDefaultMigrationSelectionValues(o),selectableValues:o.map(e=>e.id),cursorAt:MIGRATION_SELECTION_ACCEPT});if(typeof s===`symbol`){cancel(stylePromptTitle(`Migration cancelled.`)??`Migration cancelled.`);e.log(`Migration cancelled.`);return null}const c=resolveInteractiveMigrationSelection(o,s??[]);const l=applyMigrationSelectedItemIds(t,c,a);const u=i?`Codex skills for migration`:`native Codex plugins for activation`;e.log(`Selected ${c.size} of ${o.length} ${u}.`);return l}async function confirmInteractiveMigrationPlan(e,t,n){const r=await promptCodexMigrationSelection(e,t,n,`skills`);const i=r&&await promptCodexMigrationSelection(e,r,n,`plugins`);if(!i)return{plan:t};if(i.providerId===`codex`&&!hasSelectedCodexMigrationWork(i)){logNoCodexSelection(e,i);return{plan:i}}if(!await promptYesNo(`Apply this migration now?`,false)){e.log(`Migration cancelled.`);return{plan:i}}return{plan:i,applyOpts:{...n,yes:true,includeSecrets:n.includeSecrets??i.items.some(e=>e.status===`planned`&&isAuthCredentialItem(e)),preflightPlan:i}}}function hasSelectedCodexMigrationWork(e){return e.items.some(e=>e.status===`planned`&&(e.kind===`auth`||e.kind===`secret`||e.kind===`skill`&&e.action===`copy`||e.kind===`plugin`&&e.action===`install`))}function logNoCodexSelection(e,t){if(t.providerId===`codex`&&t.items.some(e=>e.reason===`codex_subscription_required`)){const n=t.warnings?.find(e=>e.includes(`Codex app-backed plugin migration requires`));if(n)e.log(n);e.log(`No Codex skills selected; native Codex plugins are not eligible for migration in this run.`);return}e.log(`No Codex skills or native Codex plugins selected for migration.`)}async function migrateListCommand(e,t={}){return await withPluginMigrationProviders({},async n=>{const r=n.map(e=>({id:e.id,label:e.label,description:e.description}));if(t.json){writeRuntimeJson(e,{providers:r});return}if(r.length===0){e.log(`No migration providers found. Run ${formatCliCommand(`openclaw plugins list`)} to verify provider plugins are installed and enabled.`);return}e.log(r.map(e=>e.description?`${e.id}\t${e.label} - ${e.description}`:`${e.id}\t${e.label}`).join(` `))})}async function migratePlanCommand(e,t,n){const r=t.provider?.trim();if(!r)throw new Error(`Migration provider is required. Run ${formatCliCommand(`openclaw migrate list`)} to choose one.`);const i=resolveDefaultIncludeSecrets(t);assertVerifyPluginAppsProvider(r,i);if(!n)return await withMigrationProvider(r,t.configOverride,async n=>await migratePlanCommand(e,t,n));const createPlan=()=>createMigrationPlan(e,{...i,provider:r},n);const a=applyMigrationSelections(i.json?await createPlan():await withProgress({label:`Scanning ${r} migration…`,indeterminate:true},async e=>{e.setLabel(`Reading migration source…`);const t=await createPlan();e.tick();return t}),i);if(i.json)writeRuntimeJson(e,redactMigrationPlan(a));else if(i.suppressPlanLog!==true)log.message(formatMigrationPreview(a).join(` `));return a}async function migrateApplyCommand(e,t,n){const r=t.provider?.trim();if(!r)throw new Error(`Migration provider is required. Run ${formatCliCommand(`openclaw migrate list`)} to choose one.`);assertVerifyPluginAppsProvider(r,t);if(t.noBackup&&!t.force)throw new Error(`--no-backup requires --force because it skips the automatic rollback copy.`);if(!t.yes&&!process.stdin.isTTY)throw new Error(`openclaw migrate apply requires --yes in non-interactive mode. Preview first with ${formatCliCommand(`openclaw migrate plan '${r.replaceAll(`'`,`'\\''`)}'`)}.`);if(!n)return await withMigrationProvider(r,t.configOverride,async n=>await migrateApplyCommand(e,t,n));let i=resolveDefaultIncludeSecrets(t);if(!t.yes){const a=await createInteractiveMigrationPlanWithAuthPrompt(e,{...t,provider:r},n);if(t.json)return a;const o=await confirmInteractiveMigrationPlan(e,a,t);if(!o.applyOpts)return o.plan;i={...o.applyOpts,provider:r}}return await runMigrationApply({runtime:e,opts:i,providerId:r,provider:n})}async function migrateDefaultCommand(e,t,n){const r=t.provider?.trim();if(!r){await migrateListCommand(e,{json:t.json});return{providerId:`list`,source:``,summary:summarizeMigrationItems([]),items:[]}}assertVerifyPluginAppsProvider(r,t);if(!n)return await withMigrationProvider(r,t.configOverride,async n=>await migrateDefaultCommand(e,t,n));const i=resolveDefaultIncludeSecrets(t);const a={...t,provider:r,json:t.json&&(t.dryRun||!t.yes)};let o=t.json&&t.yes&&!t.dryRun?applyMigrationSelections(await createMigrationPlan(e,{...i,provider:r},n),i):!t.yes&&process.stdin.isTTY?await createInteractiveMigrationPlanWithAuthPrompt(e,a,n):await migratePlanCommand(e,resolveDefaultIncludeSecrets(a),n);if(t.dryRun||t.json&&!t.yes)return o;let s=i;if(!t.yes){if(!process.stdin.isTTY){e.log(`Re-run with --yes to apply this migration non-interactively.`);return o}const n=await confirmInteractiveMigrationPlan(e,o,t);if(!n.applyOpts)return n.plan;o=n.plan;s=n.applyOpts}return await migrateApplyCommand(e,{...s,provider:r,yes:true,json:t.json,preflightPlan:o},n)}export{migratePlanCommand as i,migrateDefaultCommand as n,migrateListCommand as r,migrateApplyCommand as t};