Export variable manipulation functions to getContext
| @@ -69,6 +69,7 @@ import { textgenerationwebui_settings } from './textgen-settings.js'; | |||
| 69 | import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; | 69 | import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; |
| 70 | import { ToolManager } from './tool-calling.js'; | 70 | import { ToolManager } from './tool-calling.js'; |
| 71 | import { timestampToMoment, uuidv4 } from './utils.js'; | 71 | import { timestampToMoment, uuidv4 } from './utils.js'; |
| 72 | import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js'; | ||
| 72 | 73 | ||
| 73 | export function getContext() { | 74 | export function getContext() { |
| 74 | return { | 75 | return { |
| @@ -175,6 +176,16 @@ export function getContext() { | |||
| 175 | humanizedDateTime, | 176 | humanizedDateTime, |
| 176 | updateMessageBlock, | 177 | updateMessageBlock, |
| 177 | appendMediaToMessage, | 178 | appendMediaToMessage, |
| 179 | variables: { | ||
| 180 | local: { | ||
| 181 | get: getLocalVariable, | ||
| 182 | set: setLocalVariable, | ||
| 183 | }, | ||
| 184 | global: { | ||
| 185 | get: getGlobalVariable, | ||
| 186 | set: setGlobalVariable, | ||
| 187 | }, | ||
| 188 | }, | ||
| 178 | }; | 189 | }; |
| 179 | } | 190 | } |
| 180 | 191 | ||
| @@ -19,7 +19,7 @@ import { isFalseBoolean, convertValueType, isTrueBoolean } from './utils.js'; | |||
| 19 | 19 | ||
| 20 | const MAX_LOOPS = 100; | 20 | const MAX_LOOPS = 100; |
| 21 | 21 | ||
| 22 | function getLocalVariable(name, args = {}) { | 22 | export function getLocalVariable(name, args = {}) { |
| 23 | if (!chat_metadata.variables) { | 23 | if (!chat_metadata.variables) { |
| 24 | chat_metadata.variables = {}; | 24 | chat_metadata.variables = {}; |
| 25 | } | 25 | } |
| @@ -45,7 +45,7 @@ function getLocalVariable(name, args = {}) { | |||
| 45 | return (localVariable?.trim?.() === '' || isNaN(Number(localVariable))) ? (localVariable || '') : Number(localVariable); | 45 | return (localVariable?.trim?.() === '' || isNaN(Number(localVariable))) ? (localVariable || '') : Number(localVariable); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | function setLocalVariable(name, value, args = {}) { | 48 | export function setLocalVariable(name, value, args = {}) { |
| 49 | if (!name) { | 49 | if (!name) { |
| 50 | throw new Error('Variable name cannot be empty or undefined.'); | 50 | throw new Error('Variable name cannot be empty or undefined.'); |
| 51 | } | 51 | } |
| @@ -80,7 +80,7 @@ function setLocalVariable(name, value, args = {}) { | |||
| 80 | return value; | 80 | return value; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | function getGlobalVariable(name, args = {}) { | 83 | export function getGlobalVariable(name, args = {}) { |
| 84 | let globalVariable = extension_settings.variables.global[args.key ?? name]; | 84 | let globalVariable = extension_settings.variables.global[args.key ?? name]; |
| 85 | if (args.index !== undefined) { | 85 | if (args.index !== undefined) { |
| 86 | try { | 86 | try { |
| @@ -102,7 +102,7 @@ function getGlobalVariable(name, args = {}) { | |||
| 102 | return (globalVariable?.trim?.() === '' || isNaN(Number(globalVariable))) ? (globalVariable || '') : Number(globalVariable); | 102 | return (globalVariable?.trim?.() === '' || isNaN(Number(globalVariable))) ? (globalVariable || '') : Number(globalVariable); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | function setGlobalVariable(name, value, args = {}) { | 105 | export function setGlobalVariable(name, value, args = {}) { |
| 106 | if (!name) { | 106 | if (!name) { |
| 107 | throw new Error('Variable name cannot be empty or undefined.'); | 107 | throw new Error('Variable name cannot be empty or undefined.'); |
| 108 | } | 108 | } |