PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.9
1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 0.8.6 All 33 releases
desktop-mode / includes / agents / run-window.php

run-window.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.9, at includes/agents/run-window.php

129 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Agents: "Agent chat" native window.
4 *
5 * Lazy-loaded native window the Agents section opens to talk to an
6 * agent (the chat trigger). The window is a shell — the dedicated
7 * `agent-run-window` bundle registers the render callback on
8 * `window.openStationNativeWindows['desktop-mode-agent-run']`,
9 * subscribes to the cross-bundle `desktop-mode/agents-run` shared
10 * store, and paints the conversation for whichever agent the opener
11 * selected.
12 *
13 * @package OpenStation
14 */
15
16 defined( 'ABSPATH' ) || exit;
17
18 /**
19 * Inline SVG bot icon — byte-identical to the agent avatar so the
20 * motif is consistent everywhere agents appear.
21 *
22 * @return string Data URI.
23 */
24 function openstation_agent_run_window_icon() {
25 return openstation_agent_avatar_url();
26 }
27
28 /**
29 * Register the bundle script + style handles. Lazy-loaded by the
30 * native-window sync the first time the window opens, same as the
31 * recycle-bin and posts-window modules.
32 *
33 * @return void
34 */
35 function openstation_agent_run_register_assets() {
36 $version = OPENSTATION_VERSION;
37 $suffix = openstation_asset_suffix();
38
39 $css_path = OPENSTATION_DIR . 'assets/css/agents.css';
40 wp_register_style(
41 'desktop-mode-agent-run',
42 OPENSTATION_URL . 'assets/css/agents.css',
43 array( 'os-variables', 'dashicons' ),
44 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
45 );
46
47 $js_path = OPENSTATION_DIR . 'assets/js/agent-run-window' . $suffix . '.js';
48 wp_register_script(
49 'desktop-mode-agent-run',
50 OPENSTATION_URL . 'assets/js/agent-run-window' . $suffix . '.js',
51 array( 'wp-i18n' ),
52 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
53 true
54 );
55 wp_set_script_translations(
56 'desktop-mode-agent-run',
57 'desktop-mode',
58 OPENSTATION_DIR . 'languages'
59 );
60 }
61 add_action( 'init', 'openstation_agent_run_register_assets', 5 );
62
63 /**
64 * Static template rendered into the window body — the bundle mounts
65 * its UI into `[data-os-agent-run-root]`.
66 *
67 * @return void
68 */
69 function openstation_agent_run_render_template() {
70 ?>
71 <div class="desktop-mode-agent-run" data-os-agent-run-root>
72 <div class="os-agent-run__loading">
73 <os-spinner></os-spinner>
74 </div>
75 </div>
76 <?php
77 }
78
79 /**
80 * Register the native window on `init` priority 25 — after the
81 * registries boot.
82 *
83 * @return void
84 */
85 function openstation_agent_run_window_register() {
86 if ( ! function_exists( 'openstation_register_window' ) ) {
87 return;
88 }
89 if ( ! openstation_agents_user_can_read() ) {
90 return;
91 }
92
93 $registered = openstation_register_window(
94 'desktop-mode-agent-run',
95 array(
96 'title' => __( 'Agent chat', 'desktop-mode' ),
97 'icon' => openstation_agent_run_window_icon(),
98 'template' => 'openstation_agent_run_render_template',
99 'script' => 'desktop-mode-agent-run',
100 'styles' => array( 'desktop-mode-agent-run' ),
101 'width' => 760,
102 'height' => 620,
103 'min_width' => 540,
104 'min_height' => 380,
105 'placement' => 'none',
106 // Chat invocations should always surface a visible window,
107 // not race a focused window into the background.
108 'autofocus' => true,
109 'config' => array(
110 'restRoot' => esc_url_raw( rest_url() ),
111 'restNonce' => wp_create_nonce( 'wp_rest' ),
112 'canManage' => openstation_agents_user_can_manage(),
113 // The viewer — the chat paints their avatar next to
114 // their own messages, WhatsApp-style.
115 'currentUser' => array(
116 'id' => (int) get_current_user_id(),
117 'name' => (string) wp_get_current_user()->display_name,
118 'avatarUrl' => (string) get_avatar_url( get_current_user_id(), array( 'size' => 96 ) ),
119 ),
120 ),
121 )
122 );
123 if ( is_wp_error( $registered ) ) {
124 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
125 error_log( '[openstation] Agent chat window registration failed: ' . $registered->get_error_message() );
126 }
127 }
128 add_action( 'init', 'openstation_agent_run_window_register', 25 );
129