From f4211394029410271eff6627d78951722b3b35fb Mon Sep 17 00:00:00 2001 From: steve green Date: Sat, 11 May 2024 17:05:13 +0800 Subject: [PATCH] Create char-data.js for type hint (#2209) * Create char-data.js for type hint code from https://github.com/steve02081504/GentianAphrodite/blob/7df0d1e06d98469c0ecae6190c4ee75661dfcfc7/src/charData.mjs * add hint * fixes * `class` -> JSdoc typedef by AI * use `import` * `v2DataWorldInfo` * Rename book typedef * Fix type errors --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com> --- public/global.d.ts | 2 +- public/script.js | 1 + public/scripts/char-data.js | 94 +++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 public/scripts/char-data.js diff --git a/public/global.d.ts b/public/global.d.ts index 42b3f007e..6c11da256 100644 --- a/public/global.d.ts +++ b/public/global.d.ts @@ -20,7 +20,7 @@ interface JQuery { pagination(method: 'getCurrentPageNum'): number; pagination(method: string, options?: any): JQuery; pagination(options?: any): JQuery; - transition(options?: any): JQuery; + transition(options?: any, complete?: function): JQuery; autocomplete(options?: any): JQuery; autocomplete(method: string, options?: any): JQuery; slider(options?: any): JQuery; diff --git a/public/script.js b/public/script.js index a5f4c0bc0..923cddee5 100644 --- a/public/script.js +++ b/public/script.js @@ -463,6 +463,7 @@ let currentVersion = '0.0.0'; export const default_ch_mes = 'Hello'; let generatedPromptCache = ''; let generation_started = new Date(); +/** @type {import('scripts/char-data.js').v1CharData[]} */ export let characters = []; export let this_chid; let saveCharactersPage = 0; diff --git a/public/scripts/char-data.js b/public/scripts/char-data.js new file mode 100644 index 000000000..fa2f03382 --- /dev/null +++ b/public/scripts/char-data.js @@ -0,0 +1,94 @@ +/** + * @typedef {object} v2DataWorldInfoEntry + * @property {string[]} keys - An array of primary keys associated with the entry. + * @property {string[]} secondary_keys - An array of secondary keys associated with the entry (optional). + * @property {string} comment - A human-readable description or explanation for the entry. + * @property {string} content - The main content or data associated with the entry. + * @property {boolean} constant - Indicates if the entry's content is fixed and unchangeable. + * @property {boolean} selective - Indicates if the entry's inclusion is controlled by specific conditions. + * @property {number} insertion_order - Defines the order in which the entry is inserted during processing. + * @property {boolean} enabled - Controls whether the entry is currently active and used. + * @property {string} position - Specifies the location or context where the entry applies. + * @property {v2DataWorldInfoEntryExtensionInfos} extensions - An object containing additional details for extensions associated with the entry. + * @property {number} id - A unique identifier assigned to the entry. + */ +/** + * @typedef {object} v2DataWorldInfoEntryExtensionInfos + * @property {number} position - The order in which the extension is applied relative to other extensions. + * @property {boolean} exclude_recursion - Prevents the extension from being applied recursively. + * @property {number} probability - The chance (between 0 and 1) of the extension being applied. + * @property {boolean} useProbability - Determines if the `probability` property is used. + * @property {number} depth - The maximum level of nesting allowed for recursive application of the extension. + * @property {number} selectiveLogic - Defines the logic used to determine if the extension is applied selectively. + * @property {string} group - A category or grouping for the extension. + * @property {boolean} group_override - Overrides any existing group assignment for the extension. + * @property {number} group_weight - A value used for prioritizing extensions within the same group. + * @property {boolean} prevent_recursion - Completely disallows recursive application of the extension. + * @property {number} scan_depth - The maximum depth to search for matches when applying the extension. + * @property {boolean} match_whole_words - Specifies if only entire words should be matched during extension application. + * @property {boolean} use_group_scoring - Indicates if group weight is considered when selecting extensions. + * @property {boolean} case_sensitive - Controls whether case sensitivity is applied during matching for the extension. + * @property {string} automation_id - An identifier used for automation purposes related to the extension. + * @property {number} role - The specific function or purpose of the extension. + * @property {boolean} vectorized - Indicates if the extension is optimized for vectorized processing. + * @property {number} display_index - The order in which the extension should be displayed for user interfaces. + */ + +/** + * @typedef {object} v2WorldInfoBook + * @property {string} name - the name of the book + * @property {v2DataWorldInfoEntry[]} entries - the entries of the book + */ + +/** + * @typedef {object} v2CharData + * @property {string} name - The character's name. + * @property {string} description - A brief description of the character. + * @property {string} character_version - The character's data version. + * @property {string} personality - A short summary of the character's personality traits. + * @property {string} scenario - A description of the character's background or setting. + * @property {string} first_mes - The character's opening message in a conversation. + * @property {string} mes_example - An example message demonstrating the character's conversation style. + * @property {string} creator_notes - Internal notes or comments left by the character's creator. + * @property {string[]} tags - A list of keywords or labels associated with the character. + * @property {string} system_prompt - The system prompt used to interact with the character. + * @property {string} post_history_instructions - Instructions for handling the character's conversation history. + * @property {string} creator - The name of the person who created the character. + * @property {string[]} alternate_greetings - Additional greeting messages the character can use. + * @property {v2WorldInfoBook} character_book - Data about the character's world or story (if applicable). + * @property {v2CharDataExtensionInfos} extensions - Additional details specific to the character. + */ +/** + * @typedef {object} v2CharDataExtensionInfos + * @property {number} talkativeness - A numerical value indicating the character's propensity to talk. + * @property {boolean} fav - A flag indicating whether the character is a favorite. + * @property {string} world - The fictional world or setting where the character exists (if applicable). + * @property {object} depth_prompt - Prompts used to explore the character's depth and complexity. + * @property {number} depth_prompt.depth - The level of detail or nuance targeted by the prompt. + * @property {string} depth_prompt.prompt - The actual prompt text used for deeper character interaction. + * @property {"system" | "user" | "assistant"} depth_prompt.role - The role the character takes on during the prompted interaction (system, user, or assistant). + * // Non-standard extensions added by external tools + * @property {string} [pygmalion_id] - The unique identifier assigned to the character by the Pygmalion.chat. + * @property {{full_path: string}} [chub] - The Chub-specific data associated with the character. + */ + +/** + * @typedef {object} v1CharData + * @property {string} name - the name of the character + * @property {string} description - the description of the character + * @property {string} personality - a short personality description of the character + * @property {string} scenario - a scenario description of the character + * @property {string} first_mes - the first message in the conversation + * @property {string} mes_example - the example message in the conversation + * @property {string} creatorcomment - creator's notes of the character + * @property {string[]} tags - the tags of the character + * @property {number} talkativeness - talkativeness + * @property {boolean|string} fav - fav + * @property {string} create_date - create_date + * @property {v2CharData} data - v2 data extension + * // Non-standard extensions added by the ST server (not part of the original data) + * @property {string} chat - name of the current chat file chat + * @property {string} avatar - file name of the avatar image (acts as a unique identifier) + * @property {string} json_data - the full raw JSON data of the character + */ +export default 0;// now this file is a module