Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/personal-ai-chat/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Connectors rather than package-local credentials. Save user/assistant turns in
conversation Knowledge as `pos/ai-message` blocks; preserve meaningful model and
response metadata (`pos_model`, `pos_last_response_id`).

The selected conversation is addressable as
`/ai-chat/?conversation=<post ID>` and follows browser history. AI Chat owns
native permalinks and shortlinks for Knowledge rows carrying both `conversation`
and `ai-chat`. An editable legacy `?p=<post ID>` request redirects to that app
URL; unauthorized requests retain WordPress's normal response.

Use the package's PHP class and block metadata for exact REST and block schemas.
Do not restore old monolith `/pos/v1/openai/*` transport or root editor assets.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function register() {
$this->vocabulary()->register_type_labels();
$this->register_missing_knowledge_notice();
$this->register_wp_app( array( $this, 'render_admin_page' ) );
add_action( 'template_redirect', array( $this, 'redirect_conversation_link' ), 5 );
add_filter( 'post_type_link', array( $this, 'filter_conversation_permalink' ), 10, 2 );
add_filter( 'get_shortlink', array( $this, 'filter_conversation_shortlink' ), 10, 2 );
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
Expand Down Expand Up @@ -89,6 +92,47 @@ public function register_blocks() {
$this->register_block_from_package( 'build/blocks/tool' );
}

/**
* Return the AI Chat app URL for a conversation.
*
* @param int $post_id Post ID.
* @return string Empty when the post is not an AI Chat conversation.
*/
public function get_conversation_url( $post_id ) {
$post = get_post( $post_id );
if ( ! $this->is_conversation( $post ) ) {
return '';
}

return add_query_arg( 'conversation', $post->ID, home_url( '/ai-chat/' ) );
}

/** Filter a conversation permalink to its AI Chat interface URL. */
public function filter_conversation_permalink( $url, $post ) {
$conversation_url = $post instanceof WP_Post ? $this->get_conversation_url( $post->ID ) : '';

return $conversation_url ? $conversation_url : $url;
}

/** Filter a conversation shortlink to its AI Chat interface URL. */
public function filter_conversation_shortlink( $shortlink, $post_id ) {
$conversation_url = $this->get_conversation_url( $post_id );

return $conversation_url ? $conversation_url : $shortlink;
}

/** Redirect an editable legacy ?p= link to the AI Chat conversation. */
public function redirect_conversation_link() {
$post_id = absint( get_query_var( 'p' ) );
$conversation_url = $this->get_conversation_url( $post_id );
if ( get_query_var( 'preview' ) || ! $conversation_url || ! current_user_can( 'edit_post', $post_id ) ) {
return;
}

wp_safe_redirect( $conversation_url );
exit;
}

/**
* Register package REST routes.
*
Expand Down Expand Up @@ -464,7 +508,7 @@ public function rest_generate_message( WP_REST_Request $request ) {
* @return WP_REST_Response
*/
public function rest_list_abilities() {
return rest_ensure_response( array_map( array( $this, 'format_ability' ), $this->discover_abilities() ) );
return rest_ensure_response( array_values( array_map( array( $this, 'format_ability' ), $this->discover_abilities() ) ) );
}

/**
Expand Down Expand Up @@ -823,6 +867,17 @@ private function extract_conversation_messages( $content ) {
* @return array
*/
private function format_ability( $ability ) {
if ( is_object( $ability ) && is_callable( array( $ability, 'get_name' ) ) ) {
return array(
'name' => sanitize_text_field( $ability->get_name() ),
'label' => sanitize_text_field( $ability->get_label() ),
'description' => sanitize_text_field( $ability->get_description() ),
'input_schema' => $ability->get_input_schema(),
'output_schema' => $ability->get_output_schema(),
'meta' => $ability->get_meta(),
);
}

$ability = (array) $ability;

return array(
Expand Down
61 changes: 50 additions & 11 deletions packages/personal-ai-chat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ function AiChatAdmin() {
path: '/personal-ai-chat/v1/conversations',
} );
setConversations( response );
if ( ! active && response.length ) {
setActive( response[ 0 ] );
setTitle( response[ 0 ].title );
}
const conversationId = Number(
new URLSearchParams( window.location.search ).get(
'conversation'
)
);
const selected =
response.find( ( item ) => item.id === conversationId ) ||
response[ 0 ] ||
null;
Comment on lines +77 to +80
setActive( selected );
setTitle( selected?.title || '' );
} catch ( error ) {
setNotice( {
status: 'error',
Expand All @@ -83,7 +90,7 @@ function AiChatAdmin() {
} finally {
setLoading( false );
}
}, [ active ] );
}, [] );

useEffect( () => {
document.body.classList.add( 'personal-ai-chat-js' );
Expand All @@ -93,6 +100,40 @@ function AiChatAdmin() {
.catch( () => setAbilities( [] ) );
}, [ fetchConversations ] );

useEffect( () => {
function syncConversationToRoute() {
const conversationId = Number(
new URLSearchParams( window.location.search ).get(
'conversation'
)
);
const selected =
conversations.find( ( item ) => item.id === conversationId ) ||
conversations[ 0 ];

if ( selected ) {
setActive( selected );
setTitle( selected.title );
}
}

window.addEventListener( 'popstate', syncConversationToRoute );
return () =>
window.removeEventListener( 'popstate', syncConversationToRoute );
}, [ conversations ] );

function selectConversation( conversation ) {
setActive( conversation );
setTitle( conversation.title );
const route = new URLSearchParams( window.location.search );
route.set( 'conversation', conversation.id );
window.history.pushState(
{},
'',
`${ window.location.pathname }?${ route }`
);
}

async function createConversation() {
setSaving( true );
setNotice( null );
Expand All @@ -108,8 +149,7 @@ function AiChatAdmin() {
content: '',
},
} );
setActive( response );
setTitle( response.title );
selectConversation( response );
setConversations( ( current ) => [ response, ...current ] );
setNotice( {
status: 'success',
Expand Down Expand Up @@ -221,10 +261,9 @@ function AiChatAdmin() {
key={ conversation.id }
type="button"
className="personal-ai-chat-admin__conversation"
onClick={ () => {
setActive( conversation );
setTitle( conversation.title );
} }
onClick={ () =>
selectConversation( conversation )
}
>
<span>{ conversation.title }</span>
<small>{ conversation.modified_gmt }</small>
Expand Down
5 changes: 5 additions & 0 deletions packages/personal-notes/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The library lists `note` records. Stuff uses `artifact` + `stuff-item`, without
`note`, and should not automatically appear as ordinary Notes rows. Preserve
source/provenance terms (`manual`, `readwise`, `evernote`, `synced`) during edits.

Notes owns native permalinks and shortlinks for Knowledge rows carrying the
`note` identity and resolves them to the native WordPress editor. An editable
legacy `?p=<post ID>` request redirects to that editor; unauthorized requests
retain WordPress's normal response.

## Gutenberg sidebar

The package-local sidebar searches Knowledge, filters by Knowledge Type, previews
Expand Down
50 changes: 50 additions & 0 deletions packages/personal-notes/includes/class-personal-notes-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function register() {
$this->vocabulary()->register_type_labels();
$this->register_missing_knowledge_notice();
$this->register_wp_app( array( $this, 'render_admin_page' ) );
add_action( 'template_redirect', array( $this, 'redirect_note_link' ), 5 );
add_filter( 'post_type_link', array( $this, 'filter_note_permalink' ), 10, 2 );
add_filter( 'get_shortlink', array( $this, 'filter_note_shortlink' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );

Expand Down Expand Up @@ -155,6 +158,53 @@ public function enqueue_package_assets() {
);
}

/**
* Return the native editor URL for a note.
*
* @param int $post_id Post ID.
* @return string Empty when the post is not a note.
*/
public function get_note_url( $post_id ) {
$post = get_post( $post_id );
if ( ! $this->is_note( $post ) ) {
return '';
}

return add_query_arg(
array(
'post' => $post->ID,
'action' => 'edit',
),
admin_url( 'post.php' )
);
}

/** Filter a note permalink to its native editor URL. */
public function filter_note_permalink( $url, $post ) {
$note_url = $post instanceof WP_Post ? $this->get_note_url( $post->ID ) : '';

return $note_url ? $note_url : $url;
}

/** Filter a note shortlink to its native editor URL. */
public function filter_note_shortlink( $shortlink, $post_id ) {
$note_url = $this->get_note_url( $post_id );

return $note_url ? $note_url : $shortlink;
}

/** Redirect an editable legacy ?p= link to the native note editor. */
public function redirect_note_link() {
$post_id = absint( get_query_var( 'p' ) );
$note_url = $this->get_note_url( $post_id );
if ( get_query_var( 'preview' ) || ! $note_url || ! current_user_can( 'edit_post', $post_id ) ) {
return;
}

wp_safe_redirect( $note_url );
exit;
}

/**
* Enqueue the Notes sidebar in native post block editors.
*
Expand Down
5 changes: 5 additions & 0 deletions packages/personal-stuff/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ The app assigns the leaf identity, physical location and tags, preserving unrela

Derived in memory: breadcrumbs, descendants, cover, photo count, search index, filtered collection, previous/next order. Filters and item selection are URL query parameters (`q`, `place`, `tag`, `photo`, `item`); place/tag filter values are slugs. DataViews layout and paging stay in memory. There is no localStorage database, service worker or offline write queue.

Stuff owns links for Knowledge rows carrying the `stuff-item` identity. Native
permalinks and shortlinks resolve to `/stuff/?item=<post ID>`. An editable legacy
`?p=<post ID>` request redirects there as well; unauthorized requests retain
WordPress's normal response.

## Content and editing

Core paragraphs, images and galleries are the only native structures needed. Gallery children and document block order define photo order; the first image is the cover. Captions, alt text, image links, gallery layout and any other blocks live in their ordinary block attributes/HTML.
Expand Down
56 changes: 56 additions & 0 deletions packages/personal-stuff/includes/class-personal-stuff-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function register() {
$this->vocabulary()->register_rest_descriptions();
$this->register_missing_knowledge_notice();
$this->register_wp_app( array( $this, 'render_app' ) );
add_action( 'template_redirect', array( $this, 'redirect_item_link' ), 5 );
add_filter( 'post_type_link', array( $this, 'filter_item_permalink' ), 10, 2 );
add_filter( 'get_shortlink', array( $this, 'filter_item_shortlink' ), 10, 2 );
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
// Recheck actual terms when Knowledge becomes available; no installed flag.
$this->ensure_terms();
Expand Down Expand Up @@ -125,6 +128,59 @@ public function is_item( $post_id ) {
return 'wp_knowledge' === get_post_type( $post_id ) && has_term( 'stuff-item', 'wp_knowledge_type', $post_id );
}

/**
* Return the Stuff app URL for an item.
*
* @param int $post_id Post ID.
* @return string Empty when the post is not a Stuff item.
*/
public function get_item_url( $post_id ) {
$post = get_post( $post_id );
if ( ! $post instanceof WP_Post || ! $this->is_item( $post->ID ) ) {
return '';
}

return add_query_arg( 'item', $post->ID, home_url( '/stuff/' ) );
}

/**
* Point native Knowledge permalinks at the owning Stuff interface.
*
* @param string $url Existing permalink.
* @param WP_Post $post Post object.
* @return string
*/
public function filter_item_permalink( $url, $post ) {
$item_url = $post instanceof WP_Post ? $this->get_item_url( $post->ID ) : '';

return $item_url ? $item_url : $url;
}

/**
* Point native shortlinks at the owning Stuff interface.
*
* @param string $shortlink Existing shortlink.
* @param int $post_id Post ID.
* @return string
*/
public function filter_item_shortlink( $shortlink, $post_id ) {
$item_url = $this->get_item_url( $post_id );

return $item_url ? $item_url : $shortlink;
}

/** Redirect an editable legacy ?p= link to the Stuff item interface. */
public function redirect_item_link() {
$post_id = absint( get_query_var( 'p' ) );
$item_url = $this->get_item_url( $post_id );
if ( get_query_var( 'preview' ) || ! $item_url || ! current_user_can( 'edit_post', $post_id ) ) {
return;
}

wp_safe_redirect( $item_url );
exit;
}

/**
* Keep empty Stuff items in Gutenberg even with Personal Notes active.
*
Expand Down
5 changes: 5 additions & 0 deletions packages/personal-todo/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Preserve compact quick-add, the DataViews list/filter/actions, and the full edit
modal with scheduling, recurrence, dependencies and history. Use shared Knowledge
Type terms in assignment controls instead of the old notebook controls.

The selected edit modal is addressable as `/todo/?task=<post ID>` and follows
browser history. TODO owns native permalinks and shortlinks for Knowledge rows
carrying the `todo` identity. An editable legacy `?p=<post ID>` request redirects
to that app URL; unauthorized requests retain WordPress's normal response.

## Runtime Dependencies

Personal TODO requires a WordPress Knowledge surface but does not require any
Expand Down
Loading
Loading