Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #5

Merged
merged 12 commits into from
Sep 9, 2024
38 changes: 9 additions & 29 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Add SSH Key
run: |
mkdir $HOME/.ssh
echo "$SSH_KEY" > "$HOME/.ssh/key"
chmod 600 "$HOME/.ssh/key"
- name: Install composer deps
run: composer install --no-dev --prefer-dist --no-progress --no-suggest
- name: Install npm deps
Expand All @@ -20,33 +25,8 @@ jobs:
run: npm run build
- name: Build zip
run: npm run dist
- name: Upload Latest Version to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@master
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/hyve-lite/latest
- name: Upload Tagged Version to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/hyve-lite/$BUILD_VERSION
- name: Send update to the store
env:
PRODUCT_ID: ${{ secrets.THEMEISLE_ID }}
AUTH_TOKEN: ${{ secrets.THEMEISLE_STORE_AUTH }}
STORE_URL: ${{ secrets.THEMEISLE_STORE_URL }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
BUILD_VERSION: ${{ steps.get_version.outputs.VERSION }}
uses: Codeinwp/action-store-release@main
SVN_PASSWORD: ${{ secrets.SVN_THEMEISLE_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_THEMEISLE_USERNAME }}
Binary file added .wordpress-org/screenshot-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ module.exports = function( grunt ) {
flags: ''
},
src: [ 'hyve-lite.php' ]
},
readmetxt: {
options: {
prefix: 'Stable tag:\\s*'
},
src: [
'readme.txt'
]
}
}
}
Expand Down
Binary file modified artifact/hyve-lite.zip
Binary file not shown.
14 changes: 7 additions & 7 deletions inc/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function update_settings( $request ) {
}

if ( empty( $updated ) ) {
return rest_ensure_response( array( 'error' => __( 'No settings to update.', 'hyve' ) ) );
return rest_ensure_response( array( 'error' => __( 'No settings to update.', 'hyve-lite' ) ) );
}

$validation = apply_filters(
Expand Down Expand Up @@ -267,7 +267,7 @@ function ( $carry, $item ) {
return rest_ensure_response(
array(
// translators: %s: option key.
'error' => sprintf( __( 'Invalid value: %s', 'hyve' ), $key ),
'error' => sprintf( __( 'Invalid value: %s', 'hyve-lite' ), $key ),
)
);
}
Expand All @@ -290,7 +290,7 @@ function ( $carry, $item ) {

update_option( 'hyve_settings', $settings );

return rest_ensure_response( __( 'Settings updated.', 'hyve' ) );
return rest_ensure_response( __( 'Settings updated.', 'hyve-lite' ) );
}

/**
Expand Down Expand Up @@ -426,7 +426,7 @@ public function add_data( $request ) {

return rest_ensure_response(
array(
'error' => __( 'The content failed moderation policies.', 'hyve' ),
'error' => __( 'The content failed moderation policies.', 'hyve-lite' ),
'code' => 'content_failed_moderation',
'review' => $moderation,
)
Expand Down Expand Up @@ -555,7 +555,7 @@ function ( $message ) use ( $run_id ) {
$message = json_decode( $message, true );

if ( json_last_error() !== JSON_ERROR_NONE ) {
return rest_ensure_response( array( 'error' => __( 'No messages found.', 'hyve' ) ) );
return rest_ensure_response( array( 'error' => __( 'No messages found.', 'hyve-lite' ) ) );
}

$settings = Main::get_settings();
Expand Down Expand Up @@ -586,7 +586,7 @@ public function send_chat( $request ) {
$moderation = $this->moderate( $message );

if ( true !== $moderation ) {
return rest_ensure_response( array( 'error' => __( 'Message was flagged.', 'hyve' ) ) );
return rest_ensure_response( array( 'error' => __( 'Message was flagged.', 'hyve-lite' ) ) );
}

$openai = new OpenAI();
Expand All @@ -595,7 +595,7 @@ public function send_chat( $request ) {
$message_vector = $message_vector->embedding;

if ( is_wp_error( $message_vector ) ) {
return rest_ensure_response( array( 'error' => __( 'No embeddings found.', 'hyve' ) ) );
return rest_ensure_response( array( 'error' => __( 'No embeddings found.', 'hyve-lite' ) ) );
}

$hash = md5( strtolower( $message ) );
Expand Down
4 changes: 2 additions & 2 deletions inc/BaseAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function __construct() {
$this->table = new DB_Table();

$this->errors = array(
'invalid_api_key' => __( 'Incorrect API key provided.', 'hyve' ),
'missing_scope' => __( ' You have insufficient permissions for this operation.', 'hyve' ),
'invalid_api_key' => __( 'Incorrect API key provided.', 'hyve-lite' ),
'missing_scope' => __( ' You have insufficient permissions for this operation.', 'hyve-lite' ),
);
}

Expand Down
10 changes: 3 additions & 7 deletions inc/DB_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function create_table() {
public function table_exists() {
global $wpdb;
$table = sanitize_text_field( $this->table_name );
return $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table;
}

/**
Expand Down Expand Up @@ -231,9 +231,7 @@ public function get_by_status( $status, $limit = 500 ) {
return $cache;
}

$query = $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE post_status = %s LIMIT %d", $status, $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared

$results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE post_status = %s LIMIT %d', $this->table_name, $status, $limit ) );

if ( 'scheduled' !== $status ) {
$this->set_cache( 'entries_' . $status, $results );
Expand Down Expand Up @@ -292,9 +290,7 @@ public function get_count() {

global $wpdb;

$query = "SELECT COUNT(*) FROM {$this->table_name}";

$count = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $this->table_name ) );

$this->set_cache( 'entries_count', $count );

Expand Down
34 changes: 11 additions & 23 deletions inc/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function __construct() {
*/
public function register_menu_page() {
$page_hook_suffix = add_menu_page(
__( 'Hyve', 'hyve' ),
__( 'Hyve', 'hyve' ),
__( 'Hyve', 'hyve-lite' ),
__( 'Hyve', 'hyve-lite' ),
'manage_options',
'hyve',
array( $this, 'menu_page' ),
Expand Down Expand Up @@ -118,7 +118,7 @@ public function enqueue_options_assets() {
true
);

wp_set_script_translations( 'hyve-lite-scripts', 'hyve' );
wp_set_script_translations( 'hyve-lite-scripts', 'hyve-lite' );

$post_types = get_post_types( array( 'public' => true ), 'objects' );
$post_types_for_js = array();
Expand Down Expand Up @@ -170,8 +170,8 @@ public static function get_default_settings() {
array(
'api_key' => '',
'chat_enabled' => true,
'welcome_message' => __( 'Hello! How can I help you today?', 'hyve' ),
'default_message' => __( 'Sorry, I\'m not able to help with that.', 'hyve' ),
'welcome_message' => __( 'Hello! How can I help you today?', 'hyve-lite' ),
'default_message' => __( 'Sorry, I\'m not able to help with that.', 'hyve-lite' ),
'temperature' => 1,
'top_p' => 1,
'moderation_threshold' => array(
Expand All @@ -187,7 +187,7 @@ public static function get_default_settings() {
'harassment/threatening' => 60,
'violence' => 70,
),
),
)
);
}

Expand Down Expand Up @@ -228,7 +228,7 @@ public function enqueue_assets() {
true
);

wp_set_script_translations( 'hyve-lite-scripts', 'hyve' );
wp_set_script_translations( 'hyve-lite-scripts', 'hyve-lite' );

$settings = self::get_settings();

Expand All @@ -245,7 +245,7 @@ public function enqueue_assets() {
),
'welcome' => $settings['welcome_message'] ?? '',
'isEnabled' => $settings['chat_enabled'],
),
)
)
);

Expand All @@ -262,21 +262,9 @@ public function enqueue_assets() {
return;
}

add_action(
'wp_footer',
function () {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
const credits = document.createElement('div');
credits.className = 'hyve-credits';
credits.innerHTML = '<a href="https://themeisle.com/plugins/hyve/" target="_blank">Powered by Hyve</a>';
document.querySelector( '.hyve-input-box' ).before( credits );
});
</script>
<?php
},
99
wp_add_inline_script(
'hyve-lite-scripts',
'document.addEventListener("DOMContentLoaded", function() { const c = document.createElement("div"); c.className = "hyve-credits"; c.innerHTML = "<a href=\"https://themeisle.com/plugins/hyve/\" target=\"_blank\">Powered by Hyve</a>"; document.querySelector( ".hyve-input-box" ).before( c ); });'
);
}

Expand Down
16 changes: 8 additions & 8 deletions inc/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function create_assistant() {
return $response->id;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the assistant.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the assistant.', 'hyve-lite' ) );
}

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ public function create_embeddings( $content, $model = 'text-embedding-3-small' )
return $response->data;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the embeddings.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the embeddings.', 'hyve-lite' ) );
}

/**
Expand All @@ -225,7 +225,7 @@ public function create_thread( $params = array() ) {
return $response->id;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the thread.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the thread.', 'hyve-lite' ) );
}

/**
Expand Down Expand Up @@ -254,7 +254,7 @@ public function send_message( $message, $thread, $role = 'assistant' ) {
return true;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while sending the message.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while sending the message.', 'hyve-lite' ) );
}

/**
Expand Down Expand Up @@ -286,7 +286,7 @@ public function create_run( $messages, $thread ) {
}

if ( ! isset( $response->id ) || ( isset( $response->status ) && 'queued' !== $response->status ) ) {
return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the run.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while creating the run.', 'hyve-lite' ) );
}

return $response->id;
Expand All @@ -311,7 +311,7 @@ public function get_status( $run_id, $thread ) {
return $response->status;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while getting the run status.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while getting the run status.', 'hyve-lite' ) );
}

/**
Expand All @@ -332,7 +332,7 @@ public function get_messages( $thread ) {
return $response->data;
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while getting the messages.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while getting the messages.', 'hyve-lite' ) );
}

/**
Expand Down Expand Up @@ -430,7 +430,7 @@ private function request( $endpoint, $params = array(), $method = 'POST' ) {
return new \WP_Error( isset( $body->error->code ) ? $body->error->code : 'unknown_error', $body->error->message );
}

return new \WP_Error( 'unknown_error', __( 'An error occurred while processing the request.', 'hyve' ) );
return new \WP_Error( 'unknown_error', __( 'An error occurred while processing the request.', 'hyve-lite' ) );
}

return $body;
Expand Down
33 changes: 16 additions & 17 deletions inc/Threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ public function __construct() {
*/
public function register() {
$labels = array(
'name' => _x( 'Threads', 'post type general name', 'hyve' ),
'singular_name' => _x( 'Thread', 'post type singular name', 'hyve' ),
'menu_name' => _x( 'Threads', 'admin menu', 'hyve' ),
'name_admin_bar' => _x( 'Thread', 'add new on admin bar', 'hyve' ),
'add_new' => _x( 'Add New', 'Thread', 'hyve' ),
'add_new_item' => __( 'Add New Thread', 'hyve' ),
'new_item' => __( 'New Thread', 'hyve' ),
'edit_item' => __( 'Edit Thread', 'hyve' ),
'view_item' => __( 'View Thread', 'hyve' ),
'all_items' => __( 'All Threads', 'hyve' ),
'search_items' => __( 'Search Threads', 'hyve' ),
'parent_item_colon' => __( 'Parent Thread:', 'hyve' ),
'not_found' => __( 'No Threads found.', 'hyve' ),
'not_found_in_trash' => __( 'No Threads found in Trash.', 'hyve' ),
'name' => _x( 'Threads', 'post type general name', 'hyve-lite' ),
'singular_name' => _x( 'Thread', 'post type singular name', 'hyve-lite' ),
'menu_name' => _x( 'Threads', 'admin menu', 'hyve-lite' ),
'name_admin_bar' => _x( 'Thread', 'add new on admin bar', 'hyve-lite' ),
'add_new' => _x( 'Add New', 'Thread', 'hyve-lite' ),
'add_new_item' => __( 'Add New Thread', 'hyve-lite' ),
'new_item' => __( 'New Thread', 'hyve-lite' ),
'edit_item' => __( 'Edit Thread', 'hyve-lite' ),
'view_item' => __( 'View Thread', 'hyve-lite' ),
'all_items' => __( 'All Threads', 'hyve-lite' ),
'search_items' => __( 'Search Threads', 'hyve-lite' ),
'parent_item_colon' => __( 'Parent Thread:', 'hyve-lite' ),
'not_found' => __( 'No Threads found.', 'hyve-lite' ),
'not_found_in_trash' => __( 'No Threads found in Trash.', 'hyve-lite' ),
);

$args = array(
'labels' => $labels,
'description' => __( 'Threads.', 'hyve' ),
'description' => __( 'Threads.', 'hyve-lite' ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
Expand Down Expand Up @@ -206,8 +206,7 @@ public static function get_messages_count() {
if ( ! $messages ) {
global $wpdb;

$query = "SELECT SUM( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} WHERE meta_key = '_hyve_thread_count'";
$messages = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$messages = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} WHERE meta_key = %s", '_hyve_thread_count' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

if ( ! $messages ) {
$messages = 0;
Expand Down
Loading
Loading