Skip to content

Commit 529be33

Browse files
authored
feat(plugin-api): 补齐有界宿主工作流 API 与四种 SDK (#193)
* feat(plugin-api): add bounded workflow host APIs and SDKs * docs(plugin-api): 回填工作流 API PR 与公开返回语义
1 parent 5c56056 commit 529be33

40 files changed

Lines changed: 1915 additions & 112 deletions

File tree

‎rust/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/contracts/rust-core-api.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8810,3 +8810,18 @@ editor and may explicitly set selected default handlers. macOS associates conten
88108810
types, so extensions sharing a type may change together. The installed package
88118811
stays read-only. No regex or all-files catch-all
88128812
registration is permitted. See [fixtures](../fixtures/application/file-associations-v1.json).
8813+
8814+
## Plugin workflow projections (`plugins.workflow`)
8815+
8816+
`operation:"prepare"` takes `{method,params}` and returns strictly checked params
8817+
and `{textBytes,outputLines,outputBytes,resources}` limits. Network defaults are
8818+
resolved here. `quickPick` takes `{items,query}` and returns source `indices`;
8819+
`input` takes `{pick,value}` and returns `{valid}`. `status` takes bounded
8820+
`items:[{id,priority}]` and returns ordered `ids`. `treePage` takes `{cursor,
8821+
lastCursor,count,lastCount,rows,lastVisible}` and returns `{load}` only near the
8822+
end when both cursor and retained count advance. `output` takes `{open,text}`
8823+
and returns `{lines,open,maxLines,maxBytes}` as one bounded increment, never the
8824+
retained history. Unknown operations/fields and malformed projection input fail
8825+
with `invalid_request`. This hot path is excluded from request tracing; its text
8826+
may contain secrets. Public backend methods and lifecycle are specified in the
8827+
[plugin contract](../../shared/plugins/contract/v1/README.md#workflow-host-methods).

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ pub enum AiCommand {
217217
#[derive(Debug, Clone)]
218218
/// The `plugins.*` commands; their names live in [`CoreCommand::parse`].
219219
pub enum PluginsCommand {
220+
/// Plans bounded plugin interactions and projects their native input/output.
221+
Workflow,
220222
/// Validates and normalizes a declarative plugin manifest (`plugins.declarative.validate`).
221223
DeclarativeValidate,
222224
/// Checks what a backend returned for a plugin view and gives the whole view to draw (`plugins.ui.applyResult`).
@@ -1167,6 +1169,7 @@ impl CoreCommand {
11671169
"plugins.declarative.validate" => {
11681170
Some(Self::Plugins(PluginsCommand::DeclarativeValidate))
11691171
}
1172+
"plugins.workflow" => Some(Self::Plugins(PluginsCommand::Workflow)),
11701173
"plugins.ui.applyResult" => Some(Self::Plugins(PluginsCommand::UIApplyResult)),
11711174
"plugins.web.open" => Some(Self::Plugins(PluginsCommand::WebOpen)),
11721175
"plugins.web.close" => Some(Self::Plugins(PluginsCommand::WebClose)),

‎rust/crates/core/src/runtime/dispatcher/plugins.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub(super) fn dispatch(
1212
payload: Value,
1313
) -> CoreResponse {
1414
match command {
15+
PluginsCommand::Workflow => {
16+
plugin_response(id, payload, lithe_plugin_rpc::workflow::command)
17+
}
1518
PluginsCommand::UIApplyResult => {
1619
plugin_response(id, payload, lithe_plugin_manifest::apply_result_command)
1720
}

‎rust/crates/core/src/runtime/request_trace.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub(crate) fn is_hot(method: &str) -> bool {
153153
method,
154154
"document.classifyText"
155155
| "document.lifecycle"
156+
| "plugins.workflow"
156157
| "markdown.render"
157158
| "markdown.outline"
158159
| "markdown.resolveReference"

‎rust/crates/plugin-rpc/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ lithe-plugin-model = { path = "../plugin-model" }
1414
lithe-protocol = { path = "../protocol" }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = { version = "1.0", features = ["preserve_order"] }
17+
url = "2.5"

‎rust/crates/plugin-rpc/src/host_params.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn check_host_params(
3030
_ => return Err(invalid("Params must be an object.")),
3131
};
3232
let allowed: &[&str] = match rule {
33+
HostParams::Workflow => return Err(invalid("Workflow validation requires a method.")),
3334
HostParams::Empty => &[],
3435
HostParams::Credential { with_secret: true } => &["key", "secret"],
3536
HostParams::Credential { with_secret: false } => &["key"],
@@ -284,7 +285,7 @@ pub(crate) fn check_host_params(
284285
| HostParams::WorkspaceWatch
285286
| HostParams::WorkspaceFindFiles
286287
| HostParams::WorkspaceFindText => check_workspace_read_params(rule, params, &invalid)?,
287-
HostParams::Empty | HostParams::Object => {}
288+
HostParams::Empty | HostParams::Object | HostParams::Workflow => {}
288289
}
289290
Ok(())
290291
}

‎rust/crates/plugin-rpc/src/host_requests.rs‎

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub(crate) enum HostParams {
8989
WorkspaceFindFiles,
9090
/// A bounded text search at the workspace root (plan API-08).
9191
WorkspaceFindText,
92+
/// Strict, bounded interactive, presentation and managed-network requests.
93+
Workflow,
9294
/// Any object whose `context`, when present, is a well-formed
9395
/// reference. The service checks the rest and answers
9496
/// `plugin.host.invalidParams` or, for a field it does not know,
@@ -112,6 +114,120 @@ pub(crate) struct HostMethod {
112114
/// service adds its rows here, its grant to `GRANTABLE_HOST_SERVICES` and
113115
/// the manifest permission, and its handler to the host's dispatcher.
114116
pub(crate) const HOST_METHODS: &[HostMethod] = &[
117+
HostMethod {
118+
method: "lithe/host/window/showQuickPick",
119+
service: "window",
120+
permission: Some("window.input"),
121+
params: HostParams::Workflow,
122+
},
123+
HostMethod {
124+
method: "lithe/host/window/showInputBox",
125+
service: "window",
126+
permission: Some("window.input"),
127+
params: HostParams::Workflow,
128+
},
129+
HostMethod {
130+
method: "lithe/host/preview/openMarkdown",
131+
service: "preview",
132+
permission: Some("preview.open"),
133+
params: HostParams::Workflow,
134+
},
135+
HostMethod {
136+
method: "lithe/host/editor/showDiff",
137+
service: "editor",
138+
permission: Some("editor.open"),
139+
params: HostParams::Workflow,
140+
},
141+
HostMethod {
142+
method: "lithe/host/views/refresh",
143+
service: "views",
144+
permission: Some("views.refresh"),
145+
params: HostParams::Workflow,
146+
},
147+
HostMethod {
148+
method: "lithe/host/output/create",
149+
service: "output",
150+
permission: Some("output.write"),
151+
params: HostParams::Workflow,
152+
},
153+
HostMethod {
154+
method: "lithe/host/output/append",
155+
service: "output",
156+
permission: Some("output.write"),
157+
params: HostParams::Workflow,
158+
},
159+
HostMethod {
160+
method: "lithe/host/output/clear",
161+
service: "output",
162+
permission: Some("output.write"),
163+
params: HostParams::Workflow,
164+
},
165+
HostMethod {
166+
method: "lithe/host/output/show",
167+
service: "output",
168+
permission: Some("output.write"),
169+
params: HostParams::Workflow,
170+
},
171+
HostMethod {
172+
method: "lithe/host/output/dispose",
173+
service: "output",
174+
permission: Some("output.write"),
175+
params: HostParams::Workflow,
176+
},
177+
HostMethod {
178+
method: "lithe/host/progress/create",
179+
service: "progress",
180+
permission: Some("window.progress"),
181+
params: HostParams::Workflow,
182+
},
183+
HostMethod {
184+
method: "lithe/host/progress/report",
185+
service: "progress",
186+
permission: Some("window.progress"),
187+
params: HostParams::Workflow,
188+
},
189+
HostMethod {
190+
method: "lithe/host/progress/end",
191+
service: "progress",
192+
permission: Some("window.progress"),
193+
params: HostParams::Workflow,
194+
},
195+
HostMethod {
196+
method: "lithe/host/statusBar/setItem",
197+
service: "statusBar",
198+
permission: Some("statusBar.write"),
199+
params: HostParams::Workflow,
200+
},
201+
HostMethod {
202+
method: "lithe/host/statusBar/removeItem",
203+
service: "statusBar",
204+
permission: Some("statusBar.write"),
205+
params: HostParams::Workflow,
206+
},
207+
HostMethod {
208+
method: "lithe/host/clipboard/readText",
209+
service: "clipboard",
210+
permission: Some("clipboard.read"),
211+
params: HostParams::Workflow,
212+
},
213+
HostMethod {
214+
method: "lithe/host/clipboard/writeText",
215+
service: "clipboard",
216+
permission: Some("clipboard.write"),
217+
params: HostParams::Workflow,
218+
},
219+
HostMethod {
220+
method: "lithe/host/workspace/reveal",
221+
service: "workspace",
222+
permission: Some("workspace.reveal"),
223+
params: HostParams::Workflow,
224+
},
225+
HostMethod {
226+
method: "lithe/host/network/request",
227+
service: "network",
228+
permission: Some("network.request"),
229+
params: HostParams::Workflow,
230+
},
115231
HostMethod {
116232
method: RUN_START,
117233
service: HOST_SERVICE_RUN,
@@ -409,13 +525,13 @@ pub(crate) const HOST_METHODS: &[HostMethod] = &[
409525
method: "lithe/host/preview/openHTML",
410526
service: "preview",
411527
permission: Some("preview.open"),
412-
params: HostParams::Object,
528+
params: HostParams::Workflow,
413529
},
414530
HostMethod {
415531
method: "lithe/host/browser/openExternal",
416532
service: "browser",
417533
permission: Some("browser.open"),
418-
params: HostParams::Object,
534+
params: HostParams::Workflow,
419535
},
420536
HostMethod {
421537
method: "lithe/host/window/showInformation",
@@ -534,7 +650,11 @@ pub fn host_request(
534650
details: None,
535651
});
536652
}
537-
check_host_params(entry.params, params)?;
653+
if entry.params == HostParams::Workflow {
654+
workflow::check_params(method, params.unwrap_or(&Value::Null))?;
655+
} else {
656+
check_host_params(entry.params, params)?;
657+
}
538658
if entry.method == GET_CAPABILITIES {
539659
return Ok(HostRoute::Answer(capabilities_answer(version, granted)));
540660
}

‎rust/crates/plugin-rpc/src/lib.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//! dispatchers.
2222
2323
pub mod host_api;
24+
pub mod workflow;
2425

2526
use lithe_plugin_language_servers::is_protocol_name;
2627
use lithe_plugin_model::capabilities::{
@@ -138,6 +139,15 @@ pub fn methods_for_permission(permission: &str) -> Vec<&'static str> {
138139

139140
/// Permissions for the additive host services.
140141
pub const HOST_PERMISSIONS: &[&str] = &[
142+
"window.input",
143+
"views.refresh",
144+
"output.write",
145+
"window.progress",
146+
"statusBar.write",
147+
"clipboard.read",
148+
"clipboard.write",
149+
"workspace.reveal",
150+
"network.request",
141151
"workspace.files.read",
142152
"workspace.files.watch",
143153
"build.options.read",

0 commit comments

Comments
 (0)