feat: add pi lab ai management integration
This commit is contained in:
@@ -298,6 +298,8 @@ pub async fn document_page_shell(
|
||||
secondary_requested,
|
||||
secondary_invalid,
|
||||
);
|
||||
let pi_lab_loader_script =
|
||||
render_page_ai_pi_lab_loader_script(state.config().enable_page_ai_pi_lab);
|
||||
let body_content = crate::ssr::render_view(leptos::view! {
|
||||
<DocumentPage
|
||||
title={title.to_string()}
|
||||
@@ -339,6 +341,7 @@ pub async fn document_page_shell(
|
||||
{}
|
||||
{}
|
||||
{}
|
||||
{}
|
||||
</body>
|
||||
</html>"#,
|
||||
escape_html(title),
|
||||
@@ -368,6 +371,7 @@ pub async fn document_page_shell(
|
||||
r#"<script type="module" src="{}"></script>"#,
|
||||
mnote_browser_runtime_src("document-conflict-panel-runtime.js")
|
||||
),
|
||||
pi_lab_loader_script,
|
||||
);
|
||||
let mut response = Html(html).into_response();
|
||||
stamp_shell_headers(response.headers_mut(), "document");
|
||||
@@ -850,6 +854,23 @@ pub(crate) fn render_editor_island_adapter_script() -> String {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn render_page_ai_pi_lab_loader_script(enabled: bool) -> String {
|
||||
if !enabled {
|
||||
return String::new();
|
||||
}
|
||||
format!(
|
||||
r#"<script>
|
||||
(function() {{
|
||||
var s = document.createElement('script');
|
||||
s.src = '{}';
|
||||
s.onload = function() {{ if (window.createSidebarPageAiPiLabRuntime) window.createSidebarPageAiPiLabRuntime({{}}); }};
|
||||
document.body.appendChild(s);
|
||||
}})();
|
||||
</script>"#,
|
||||
mnote_browser_runtime_src("sidebar-page-ai-pi-lab-runtime.js")
|
||||
)
|
||||
}
|
||||
|
||||
fn leptos_tiptap_runtime_src(asset: &str) -> String {
|
||||
let base = format!("/api/leptos-tiptap-runtime/{asset}");
|
||||
if let Some(cache_buster) = crate::routes::dev_hot::dev_hot_cache_buster() {
|
||||
@@ -2591,6 +2612,20 @@ pub async fn sidebar_page_ai_target_runtime_asset() -> Response {
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn sidebar_page_ai_pi_lab_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/sidebar-page-ai-pi-lab-runtime.js");
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(
|
||||
header::CONTENT_TYPE,
|
||||
"application/javascript; charset=utf-8",
|
||||
)
|
||||
.header(header::CACHE_CONTROL, runtime_asset_cache_control())
|
||||
.header(HEADER_MNOTE_WEB_OWNER, "mnote-web")
|
||||
.body(browser_runtime_js_body(JS))
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn sidebar_page_settings_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/sidebar-page-settings-runtime.js");
|
||||
Response::builder()
|
||||
@@ -3669,6 +3704,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -3726,6 +3762,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -3847,6 +3884,7 @@ mod tests {
|
||||
enable_legacy_next_compat: false,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: Some("http://127.0.0.1:9".into()),
|
||||
@@ -3989,6 +4027,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -4729,6 +4768,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -4797,6 +4837,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -4935,7 +4976,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn local_folder_page_aggregate_prefers_control_plane_ui_preference_over_default_title_header() {
|
||||
async fn local_folder_page_aggregate_prefers_control_plane_ui_preference_over_default_title_header(
|
||||
) {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"mnote-local-page-aggregate-ui-pref-{}",
|
||||
std::process::id()
|
||||
@@ -4954,6 +4996,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
@@ -5499,6 +5542,7 @@ mod tests {
|
||||
enable_legacy_next_compat: true,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
enable_page_ai_pi_lab: false,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
|
||||
Reference in New Issue
Block a user