Fix tiptap selection sync and toolbar event loop
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
use core_protocol::{InvocationKind, ToolExecutionMode};
|
||||
use mnote_cli::{
|
||||
execute_output, plan_block_embed, plan_block_insert, plan_block_move, plan_block_patch,
|
||||
plan_mindmap_get, plan_mindmap_op, plan_mindmap_put, plan_page_create, plan_page_delete,
|
||||
plan_page_get, plan_page_move, plan_page_restore, plan_page_save, plan_page_title,
|
||||
plan_search_blocks, plan_search_documents, plan_sidebar_dataset, plan_tool_run,
|
||||
editor_ai_pipeline, editor_markdown_roundtrip, editor_session_demo, execute_output,
|
||||
plan_block_embed, plan_block_insert, plan_block_move, plan_block_patch, plan_mindmap_get,
|
||||
plan_mindmap_op, plan_mindmap_put, plan_page_create, plan_page_delete, plan_page_get,
|
||||
plan_page_move, plan_page_restore, plan_page_save, plan_page_title, plan_search_blocks,
|
||||
plan_search_documents, plan_sidebar_dataset, plan_tool_run, render_editor_plain_output,
|
||||
render_plain_output, BlockEmbedArgs, BlockMoveArgs, CliContext, CliError, CliJsonOutput,
|
||||
PageCreateArgs, PageDeleteArgs, PageMoveArgs, PageRestoreArgs,
|
||||
EditorAiScenarioArg, EditorCliOutput, EditorInputKindArg, PageCreateArgs, PageDeleteArgs,
|
||||
PageMoveArgs, PageRestoreArgs,
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -57,6 +59,7 @@ enum Commands {
|
||||
Mindmap(MindmapCommand),
|
||||
Search(SearchCommand),
|
||||
Sidebar(SidebarCommand),
|
||||
Editor(EditorCliCommand),
|
||||
Tool(ToolCommand),
|
||||
}
|
||||
|
||||
@@ -370,6 +373,43 @@ struct SidebarDatasetArgs {
|
||||
workspace_id: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct EditorCliCommand {
|
||||
#[command(subcommand)]
|
||||
action: EditorAction,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum EditorAction {
|
||||
MarkdownRoundtrip(EditorMarkdownRoundtripArgs),
|
||||
SessionDemo(EditorSessionDemoArgs),
|
||||
AiPipeline(EditorAiPipelineArgs),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct EditorMarkdownRoundtripArgs {
|
||||
#[arg(long)]
|
||||
markdown: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct EditorSessionDemoArgs {
|
||||
#[arg(long)]
|
||||
markdown: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct EditorAiPipelineArgs {
|
||||
#[arg(long, value_enum, default_value_t = EditorInputKindArg::PlainText)]
|
||||
kind: EditorInputKindArg,
|
||||
|
||||
#[arg(long, value_enum, default_value_t = EditorAiScenarioArg::MeetingNotesToTodos)]
|
||||
scenario: EditorAiScenarioArg,
|
||||
|
||||
#[arg(long)]
|
||||
input: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct ToolCommand {
|
||||
#[command(subcommand)]
|
||||
@@ -422,6 +462,11 @@ fn main() {
|
||||
dry_run: cli.global.dry_run,
|
||||
};
|
||||
|
||||
enum CommandOutcome {
|
||||
Bridge(CliJsonOutput),
|
||||
Editor(EditorCliOutput),
|
||||
}
|
||||
|
||||
let result = match cli.command {
|
||||
Commands::Page(command) => match command.action {
|
||||
PageAction::Get(args) => {
|
||||
@@ -475,7 +520,8 @@ fn main() {
|
||||
workspace_id: args.workspace_id.as_deref(),
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
Commands::Block(command) => match command.action {
|
||||
BlockAction::Insert(args) => plan_block_insert(
|
||||
&context,
|
||||
@@ -512,7 +558,8 @@ fn main() {
|
||||
target_block_id: args.target_block_id.as_deref(),
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
Commands::Mindmap(command) => match command.action {
|
||||
MindmapAction::Get(args) => plan_mindmap_get(
|
||||
&context,
|
||||
@@ -535,7 +582,8 @@ fn main() {
|
||||
&args.mindmap_id,
|
||||
&args.ops_json,
|
||||
),
|
||||
},
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
Commands::Search(command) => match command.action {
|
||||
SearchAction::Documents(args) => plan_search_documents(
|
||||
&context,
|
||||
@@ -551,10 +599,22 @@ fn main() {
|
||||
args.limit,
|
||||
args.cursor.as_deref(),
|
||||
),
|
||||
},
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
Commands::Sidebar(command) => match command.action {
|
||||
SidebarAction::Dataset(args) => plan_sidebar_dataset(&context, &args.workspace_id),
|
||||
},
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
Commands::Editor(command) => match command.action {
|
||||
EditorAction::MarkdownRoundtrip(args) => editor_markdown_roundtrip(&args.markdown),
|
||||
EditorAction::SessionDemo(args) => editor_session_demo(&args.markdown),
|
||||
EditorAction::AiPipeline(args) => editor_ai_pipeline(
|
||||
to_editor_input_kind(args.kind),
|
||||
to_editor_ai_scenario(args.scenario),
|
||||
&args.input,
|
||||
),
|
||||
}
|
||||
.map(CommandOutcome::Editor),
|
||||
Commands::Tool(command) => match command.action {
|
||||
ToolAction::Run(args) => plan_tool_run(
|
||||
&context,
|
||||
@@ -563,18 +623,23 @@ fn main() {
|
||||
to_execution_mode(args.mode),
|
||||
&args.args_json,
|
||||
),
|
||||
},
|
||||
}
|
||||
.and_then(|output| {
|
||||
if cli.global.execute {
|
||||
execute_output(&output, &context)
|
||||
} else {
|
||||
Ok(output)
|
||||
}
|
||||
.map(CommandOutcome::Bridge),
|
||||
}
|
||||
.and_then(|output| match output {
|
||||
CommandOutcome::Bridge(output) => {
|
||||
if cli.global.execute {
|
||||
execute_output(&output, &context).map(CommandOutcome::Bridge)
|
||||
} else {
|
||||
Ok(CommandOutcome::Bridge(output))
|
||||
}
|
||||
}
|
||||
CommandOutcome::Editor(output) => Ok(CommandOutcome::Editor(output)),
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(output) => emit_success(&output, cli.global.json),
|
||||
Ok(CommandOutcome::Bridge(output)) => emit_success(&output, cli.global.json),
|
||||
Ok(CommandOutcome::Editor(output)) => emit_editor_success(&output, cli.global.json),
|
||||
Err(error) => emit_error(&error, cli.global.json),
|
||||
}
|
||||
}
|
||||
@@ -590,6 +655,17 @@ fn emit_success(output: &CliJsonOutput, json_mode: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_editor_success(output: &EditorCliOutput, json_mode: bool) {
|
||||
if json_mode {
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(output).expect("editor CLI JSON 输出必须可序列化")
|
||||
);
|
||||
} else {
|
||||
println!("{}", render_editor_plain_output(output));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_error(error: &CliError, json_mode: bool) -> ! {
|
||||
if json_mode {
|
||||
println!(
|
||||
@@ -625,3 +701,22 @@ fn to_execution_mode(mode: ToolModeArg) -> ToolExecutionMode {
|
||||
ToolModeArg::ExplainPlan => ToolExecutionMode::ExplainPlan,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_editor_input_kind(kind: EditorInputKindArg) -> mnote_editor_core::EditorInputKind {
|
||||
match kind {
|
||||
EditorInputKindArg::PlainText => mnote_editor_core::EditorInputKind::PlainText,
|
||||
EditorInputKindArg::Markdown => mnote_editor_core::EditorInputKind::Markdown,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_editor_ai_scenario(scenario: EditorAiScenarioArg) -> mnote_editor_core::EditorAiScenario {
|
||||
match scenario {
|
||||
EditorAiScenarioArg::MeetingNotesToTodos => {
|
||||
mnote_editor_core::EditorAiScenario::MeetingNotesToTodos
|
||||
}
|
||||
EditorAiScenarioArg::LongParagraphToTitle => {
|
||||
mnote_editor_core::EditorAiScenario::LongParagraphToTitle
|
||||
}
|
||||
EditorAiScenarioArg::PageReorder => mnote_editor_core::EditorAiScenario::PageReorder,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user