|
1 | 1 | import objHash from 'object-hash'; |
2 | 2 | import { EventEmitter } from 'events'; |
3 | | -import { objType } from 'tiny-essentials'; |
| 3 | +import { isJsonObject, objType } from 'tiny-essentials'; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * Tiny AI Server Communication API |
@@ -393,7 +393,7 @@ class TinyAiInstance { |
393 | 393 | // Validate the custom value |
394 | 394 | const props = history.customList.find((/** @type {*} */ item) => item.name === name); |
395 | 395 | if ( |
396 | | - objType(props, 'object') && |
| 396 | + isJsonObject(props) && |
397 | 397 | typeof props.type === 'string' && |
398 | 398 | typeof props.name === 'string' |
399 | 399 | ) { |
@@ -839,7 +839,7 @@ class TinyAiInstance { |
839 | 839 | * @returns {Record<string, any>|null} The inserted model data, or null if the model already exists. |
840 | 840 | */ |
841 | 841 | _insertNewModel(model) { |
842 | | - if (!objType(model, 'object')) throw new Error('Model data must be a valid object.'); |
| 842 | + if (!isJsonObject(model)) throw new Error('Model data must be a valid object.'); |
843 | 843 |
|
844 | 844 | if (this.models.findIndex((item) => item.id === model.id) < 0) { |
845 | 845 | /** @type {Record<string, any>} */ |
@@ -962,7 +962,7 @@ class TinyAiInstance { |
962 | 962 | if (errData) { |
963 | 963 | if (typeof errData === 'string') return { text: errData }; |
964 | 964 | // @ts-ignore |
965 | | - else if (objType(errData, 'object') && typeof errData.text === 'string') return errData; |
| 965 | + else if (isJsonObject(errData) && typeof errData.text === 'string') return errData; |
966 | 966 | } |
967 | 967 | } |
968 | 968 | return null; |
@@ -1331,7 +1331,7 @@ class TinyAiInstance { |
1331 | 1331 | this.history[selectedId].nextId++; |
1332 | 1332 | const hash = objHash(data); |
1333 | 1333 |
|
1334 | | - const tokenContent = objType(tokenData, 'object') |
| 1334 | + const tokenContent = isJsonObject(tokenData) |
1335 | 1335 | ? tokenData |
1336 | 1336 | : { count: typeof tokenData === 'number' ? tokenData : null }; |
1337 | 1337 |
|
|
0 commit comments