@admin-layout/tailwind-ui 12.2.4-alpha.57 → 12.2.4-alpha.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AIToolbar/components/completion/AssistantAvatar.d.ts +13 -1
- package/lib/components/AIToolbar/components/completion/AssistantAvatar.d.ts.map +1 -1
- package/lib/components/AIToolbar/components/completion/AssistantAvatar.js +17 -5
- package/lib/components/AIToolbar/components/completion/AssistantAvatar.js.map +1 -1
- package/lib/components/AIToolbar/components/completion/Input.d.ts.map +1 -1
- package/lib/components/AIToolbar/components/completion/Input.js +6 -2
- package/lib/components/AIToolbar/components/completion/Input.js.map +1 -1
- package/lib/components/AIToolbar/components/completion/MessageHistory.d.ts.map +1 -1
- package/lib/components/AIToolbar/components/completion/MessageHistory.js +3 -1
- package/lib/components/AIToolbar/components/completion/MessageHistory.js.map +1 -1
- package/lib/components/AIToolbar/hooks/useActiveCharacter.d.ts.map +1 -1
- package/lib/components/AIToolbar/hooks/useActiveCharacter.js +4 -1
- package/lib/components/AIToolbar/hooks/useActiveCharacter.js.map +1 -1
- package/lib/components/AIToolbar/hooks/useCharacterSprite.d.ts +14 -0
- package/lib/components/AIToolbar/hooks/useCharacterSprite.d.ts.map +1 -0
- package/lib/components/AIToolbar/hooks/useCharacterSprite.js +103 -0
- package/lib/components/AIToolbar/hooks/useCharacterSprite.js.map +1 -0
- package/lib/components/AIToolbar/utils/emotionClassifier.d.ts +19 -0
- package/lib/components/AIToolbar/utils/emotionClassifier.d.ts.map +1 -0
- package/lib/components/AIToolbar/utils/emotionClassifier.js +142 -0
- package/lib/components/AIToolbar/utils/emotionClassifier.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
interface AssistantAvatarProps {
|
|
2
|
+
/** Static fallback avatar (default portrait). Used when no sprite is resolved. */
|
|
2
3
|
avatarSrc: string | null;
|
|
3
4
|
/** Optional message sequence number rendered as "#N" beneath the avatar. */
|
|
4
5
|
index?: number;
|
|
@@ -6,7 +7,18 @@ interface AssistantAvatarProps {
|
|
|
6
7
|
size?: number;
|
|
7
8
|
/** Tailwind classes applied to the column wrapper. */
|
|
8
9
|
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Character `file_name` (i.e. the PNG card stem — "Seraphina"). When set
|
|
12
|
+
* together with `text`, the avatar switches to the matching expression
|
|
13
|
+
* sprite from the character's sprite folder.
|
|
14
|
+
*/
|
|
15
|
+
characterFileName?: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Message text used to pick an emotion sprite. The classifier maps the
|
|
18
|
+
* text to one of 28 GoEmotions labels (`neutral`, `joy`, `caring`, ...).
|
|
19
|
+
*/
|
|
20
|
+
text?: string | null;
|
|
9
21
|
}
|
|
10
|
-
export declare function AssistantAvatar({ avatarSrc, index, size, className }: AssistantAvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function AssistantAvatar({ avatarSrc, index, size, className, characterFileName, text, }: AssistantAvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
11
23
|
export default AssistantAvatar;
|
|
12
24
|
//# sourceMappingURL=AssistantAvatar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantAvatar.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/AssistantAvatar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AssistantAvatar.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/AssistantAvatar.tsx"],"names":[],"mappings":"AAgBA,UAAU,oBAAoB;IAC1B,kFAAkF;IAClF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAgB,eAAe,CAAC,EAC5B,SAAS,EACT,KAAK,EACL,IAAS,EACT,SAAS,EACT,iBAAiB,EACjB,IAAI,GACP,EAAE,oBAAoB,2CA2CtB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {jsxs,jsx}from'react/jsx-runtime';import'../../../../utils/isBrowser/index.js';import {cn}from'../../../../utils/util.js';import'
|
|
1
|
+
import {jsxs,jsx}from'react/jsx-runtime';import*as React from'react';import'../../../../utils/isBrowser/index.js';import {cn}from'../../../../utils/util.js';import'fast-deep-equal/react.js';import {useCharacterSprite}from'../../hooks/useCharacterSprite.js';import {classifyEmotion}from'../../utils/emotionClassifier.js';function AssistantAvatar({
|
|
2
2
|
avatarSrc,
|
|
3
3
|
index,
|
|
4
|
-
size =
|
|
5
|
-
className
|
|
4
|
+
size = 60,
|
|
5
|
+
className,
|
|
6
|
+
characterFileName,
|
|
7
|
+
text
|
|
6
8
|
}) {
|
|
7
9
|
const hasNumber = typeof index === 'number';
|
|
10
|
+
// Pick an emotion only when we actually have a character that can supply
|
|
11
|
+
// a sprite — avoids burning a Tauri round-trip for non-Tauri builds.
|
|
12
|
+
const emotion = React.useMemo(() => {
|
|
13
|
+
if (!characterFileName || !text) return null;
|
|
14
|
+
return classifyEmotion(text);
|
|
15
|
+
}, [characterFileName, text]);
|
|
16
|
+
const spriteSrc = useCharacterSprite(characterFileName ?? null, emotion);
|
|
17
|
+
// Prefer the emotion sprite; fall back to the static avatar while it loads
|
|
18
|
+
// or when sprite resolution returned null (no character / outside Tauri).
|
|
19
|
+
const renderedSrc = spriteSrc ?? avatarSrc;
|
|
8
20
|
return jsxs("div", {
|
|
9
21
|
className: cn('flex shrink-0 flex-col items-center gap-1 pt-0.5', className),
|
|
10
22
|
"aria-hidden": !hasNumber,
|
|
11
|
-
children: [
|
|
12
|
-
src:
|
|
23
|
+
children: [renderedSrc ? jsx("img", {
|
|
24
|
+
src: renderedSrc,
|
|
13
25
|
alt: "",
|
|
14
26
|
"aria-hidden": "true",
|
|
15
27
|
draggable: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantAvatar.js","sources":["../../../../../src/components/AIToolbar/components/completion/AssistantAvatar.tsx"],"sourcesContent":[null],"names":[
|
|
1
|
+
{"version":3,"file":"AssistantAvatar.js","sources":["../../../../../src/components/AIToolbar/components/completion/AssistantAvatar.tsx"],"sourcesContent":[null],"names":[],"mappings":"gUA+BI,SAAA,eAAA,CAAA;;;AAGG,EAAA,IAAA,GAAA,EAAA;AACH,EAAA,SAAO;AACV,EAAA,iBAAA;AAED,EAAA;AAoDA,CAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/Input.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAQ/C,eAAO,MAAM,KAAK,GAAI,sTAsBnB,mBAAmB,GAAG;IACrB,QAAQ,EAAE,OAAO,CAAC;CACrB,
|
|
1
|
+
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/Input.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAQ/C,eAAO,MAAM,KAAK,GAAI,sTAsBnB,mBAAmB,GAAG;IACrB,QAAQ,EAAE,OAAO,CAAC;CACrB,4CA6TA,CAAC"}
|
|
@@ -178,7 +178,9 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useRef,useMemo,useLayo
|
|
|
178
178
|
className: "flex w-full gap-3",
|
|
179
179
|
children: [jsx(AssistantAvatar, {
|
|
180
180
|
avatarSrc: character?.avatarSrc ?? null,
|
|
181
|
-
index: idx + 1
|
|
181
|
+
index: idx + 1,
|
|
182
|
+
characterFileName: character?.fileName ?? null,
|
|
183
|
+
text: msg.content
|
|
182
184
|
}), jsxs("div", {
|
|
183
185
|
className: "min-w-0 flex-1",
|
|
184
186
|
children: [jsxs("div", {
|
|
@@ -211,7 +213,9 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useRef,useMemo,useLayo
|
|
|
211
213
|
className: "flex w-full gap-3",
|
|
212
214
|
children: [jsx(AssistantAvatar, {
|
|
213
215
|
avatarSrc: character?.avatarSrc ?? null,
|
|
214
|
-
index: sortedAsc.length + 1
|
|
216
|
+
index: sortedAsc.length + 1,
|
|
217
|
+
characterFileName: character?.fileName ?? null,
|
|
218
|
+
text: response
|
|
215
219
|
}), jsxs("div", {
|
|
216
220
|
className: "min-w-0 flex-1",
|
|
217
221
|
children: [jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHistory.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/MessageHistory.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C,UAAU,mBAAmB;IACzB,mBAAmB,EAAE,WAAW,EAAE,CAAC;IACnC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,sBAAsB,EAAE,MAAM,IAAI,CAAC;IACnC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,cAAc,GAAI,6FAK5B,mBAAmB,
|
|
1
|
+
{"version":3,"file":"MessageHistory.d.ts","sourceRoot":"","sources":["../../../../../src/components/AIToolbar/components/completion/MessageHistory.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C,UAAU,mBAAmB;IACzB,mBAAmB,EAAE,WAAW,EAAE,CAAC;IACnC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,sBAAsB,EAAE,MAAM,IAAI,CAAC;IACnC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,cAAc,GAAI,6FAK5B,mBAAmB,4CAyIrB,CAAC"}
|
|
@@ -101,7 +101,9 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {MessageSquareText,Chev
|
|
|
101
101
|
className: "flex w-full gap-3",
|
|
102
102
|
children: [jsx(AssistantAvatar, {
|
|
103
103
|
avatarSrc: character?.avatarSrc ?? null,
|
|
104
|
-
index: arr.length - descIdx
|
|
104
|
+
index: arr.length - descIdx,
|
|
105
|
+
characterFileName: character?.fileName ?? null,
|
|
106
|
+
text: message.content
|
|
105
107
|
}), jsxs("div", {
|
|
106
108
|
className: "min-w-0 flex-1",
|
|
107
109
|
children: [jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHistory.js","sources":["../../../../../src/components/AIToolbar/components/completion/MessageHistory.tsx"],"sourcesContent":[null],"names":[],"mappings":"i1EAcC,MAAA,cAAA,GAAA,CAAA;AAED,EAAA,mBAAa
|
|
1
|
+
{"version":3,"file":"MessageHistory.js","sources":["../../../../../src/components/AIToolbar/components/completion/MessageHistory.tsx"],"sourcesContent":[null],"names":[],"mappings":"i1EAcC,MAAA,cAAA,GAAA,CAAA;AAED,EAAA,mBAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveCharacter.d.ts","sourceRoot":"","sources":["../../../../src/components/AIToolbar/hooks/useActiveCharacter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useActiveCharacter.d.ts","sourceRoot":"","sources":["../../../../src/components/AIToolbar/hooks/useActiveCharacter.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,eAAe;IAC5B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC5B,sDAAsD;IACtD,UAAU,EAAE,kBAAkB,EAAE,CAAC;IACjC,gFAAgF;IAChF,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iFAAiF;IACjF,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAC5C;AA2GD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,GAAG,IAAI,CAiE3D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CAqFpD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as React from'react';// Active-character lookup for the AIToolbar.
|
|
1
|
+
import*as React from'react';import {clearCharacterSpriteCache}from'./useCharacterSprite.js';// Active-character lookup for the AIToolbar.
|
|
2
2
|
//
|
|
3
3
|
// Surfaces the currently-selected character (name + avatar data URL) so the
|
|
4
4
|
// completion popover and message history can show "Seraphina" with her avatar
|
|
@@ -122,6 +122,9 @@ function useActiveCharacter() {
|
|
|
122
122
|
let unlisten = null;
|
|
123
123
|
let cancelled = false;
|
|
124
124
|
safeListen(CHARACTER_REFRESH_EVENT, () => {
|
|
125
|
+
// Sprites may have changed on disk (new install / uninstall); drop
|
|
126
|
+
// cached data URLs so the next render re-fetches.
|
|
127
|
+
clearCharacterSpriteCache();
|
|
125
128
|
void reload();
|
|
126
129
|
}).then(fn => {
|
|
127
130
|
if (cancelled) fn();else unlisten = fn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveCharacter.js","sources":["../../../../src/components/AIToolbar/hooks/useActiveCharacter.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useActiveCharacter.js","sources":["../../../../src/components/AIToolbar/hooks/useActiveCharacter.ts"],"sourcesContent":[null],"names":[],"mappings":"4FAyBA;;;;;;AAMI;AACH;AAED;;;AAGI;AACH;AAED;;;;AAII;;AA8GJ;;;;AAIG;AACH;AAmEA;;;AAGG,MAAA,8BAAA,GAAA,iCAAA;AACH,MAAA,4BAAgB,GAAA,8BAqFf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the data URL for `(characterFileName, label)` or `null` while the
|
|
3
|
+
* sprite is loading / when running outside Tauri / when no character is set.
|
|
4
|
+
*
|
|
5
|
+
* Re-evaluates whenever either input changes. Cached results resolve in the
|
|
6
|
+
* same render (no transient `null`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function useCharacterSprite(characterFileName: string | null | undefined, label: string | null | undefined): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Clears the sprite cache. Call after `character_refresh` so newly-installed
|
|
11
|
+
* sprite packs aren't shadowed by stale data URLs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clearCharacterSpriteCache(): void;
|
|
14
|
+
//# sourceMappingURL=useCharacterSprite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCharacterSprite.d.ts","sourceRoot":"","sources":["../../../../src/components/AIToolbar/hooks/useCharacterSprite.ts"],"names":[],"mappings":"AAqFA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC5C,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACjC,MAAM,GAAG,IAAI,CAoBf;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import*as React from'react';// Expression-sprite lookup for assistant message bubbles.
|
|
2
|
+
//
|
|
3
|
+
// Resolves `(characterFileName, label)` → `data:image/png;base64,...` via the
|
|
4
|
+
// Tauri command `character_get_expression`, with a module-level cache so the
|
|
5
|
+
// same sprite is fetched at most once per session even when many messages map
|
|
6
|
+
// to the same emotion.
|
|
7
|
+
//
|
|
8
|
+
// The Rust side (`character_get_expression`) already implements graceful
|
|
9
|
+
// fallback through `neutral`/`joy`/avatar when the requested label is missing,
|
|
10
|
+
// so callers can pass any of the 28 GoEmotions labels without first checking
|
|
11
|
+
// which sprites the character actually ships.
|
|
12
|
+
//
|
|
13
|
+
// Degrades to `null` outside Tauri / when no character file_name is provided.
|
|
14
|
+
function isTauri() {
|
|
15
|
+
if (typeof window === 'undefined') return false;
|
|
16
|
+
const w = window;
|
|
17
|
+
return Boolean(w.__TAURI_INTERNALS__ ?? w.__TAURI__);
|
|
18
|
+
}
|
|
19
|
+
async function safeInvoke(cmd, args) {
|
|
20
|
+
if (!isTauri()) return null;
|
|
21
|
+
try {
|
|
22
|
+
// @ts-ignore — optional dynamic import, present as a peer dep in Tauri builds.
|
|
23
|
+
const mod = await import('@tauri-apps/api/core');
|
|
24
|
+
return await mod.invoke(cmd, args);
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Two layered caches keyed by `${fileName}::${label}`:
|
|
30
|
+
//
|
|
31
|
+
// - `urlCache` resolves synchronously on subsequent calls (no re-render flicker).
|
|
32
|
+
// - `pendingCache` deduplicates concurrent fetches for the same key when
|
|
33
|
+
// several messages on screen happen to share the same emotion.
|
|
34
|
+
const urlCache = new Map();
|
|
35
|
+
const pendingCache = new Map();
|
|
36
|
+
function cacheKey(fileName, label) {
|
|
37
|
+
return `${fileName}::${label}`;
|
|
38
|
+
}
|
|
39
|
+
async function fetchSprite(fileName, label) {
|
|
40
|
+
const key = cacheKey(fileName, label);
|
|
41
|
+
const cached = urlCache.get(key);
|
|
42
|
+
if (cached !== undefined) return cached;
|
|
43
|
+
const pending = pendingCache.get(key);
|
|
44
|
+
if (pending) return pending;
|
|
45
|
+
const promise = (async () => {
|
|
46
|
+
const dto = await safeInvoke('character_get_expression', {
|
|
47
|
+
fileName,
|
|
48
|
+
label
|
|
49
|
+
});
|
|
50
|
+
if (!dto || !dto.base64 || dto.base64.length < 100) {
|
|
51
|
+
urlCache.set(key, '');
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const url = `data:${dto.mime_type || 'image/png'};base64,${dto.base64}`;
|
|
55
|
+
urlCache.set(key, url);
|
|
56
|
+
// If Rust fell back to a different label (sprite missing), also cache
|
|
57
|
+
// the resolved label so a subsequent call for it short-circuits.
|
|
58
|
+
if (dto.label && dto.label !== label) {
|
|
59
|
+
urlCache.set(cacheKey(fileName, dto.label), url);
|
|
60
|
+
}
|
|
61
|
+
return url;
|
|
62
|
+
})();
|
|
63
|
+
pendingCache.set(key, promise);
|
|
64
|
+
try {
|
|
65
|
+
return await promise;
|
|
66
|
+
} finally {
|
|
67
|
+
pendingCache.delete(key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the data URL for `(characterFileName, label)` or `null` while the
|
|
72
|
+
* sprite is loading / when running outside Tauri / when no character is set.
|
|
73
|
+
*
|
|
74
|
+
* Re-evaluates whenever either input changes. Cached results resolve in the
|
|
75
|
+
* same render (no transient `null`).
|
|
76
|
+
*/
|
|
77
|
+
function useCharacterSprite(characterFileName, label) {
|
|
78
|
+
const key = characterFileName && label ? cacheKey(characterFileName, label) : null;
|
|
79
|
+
const cachedInitial = key ? urlCache.get(key) ?? null : null;
|
|
80
|
+
const [src, setSrc] = React.useState(cachedInitial && cachedInitial !== '' ? cachedInitial : null);
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
if (!characterFileName || !label) {
|
|
83
|
+
setSrc(null);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let alive = true;
|
|
87
|
+
fetchSprite(characterFileName, label).then(url => {
|
|
88
|
+
if (alive) setSrc(url);
|
|
89
|
+
});
|
|
90
|
+
return () => {
|
|
91
|
+
alive = false;
|
|
92
|
+
};
|
|
93
|
+
}, [characterFileName, label]);
|
|
94
|
+
return src;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Clears the sprite cache. Call after `character_refresh` so newly-installed
|
|
98
|
+
* sprite packs aren't shadowed by stale data URLs.
|
|
99
|
+
*/
|
|
100
|
+
function clearCharacterSpriteCache() {
|
|
101
|
+
urlCache.clear();
|
|
102
|
+
pendingCache.clear();
|
|
103
|
+
}export{clearCharacterSpriteCache,useCharacterSprite};//# sourceMappingURL=useCharacterSprite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCharacterSprite.js","sources":["../../../../src/components/AIToolbar/hooks/useCharacterSprite.ts"],"sourcesContent":[null],"names":[],"mappings":"4BAqFA;;;;;;AAMG;AACH;AAyBA;;;AAGG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type EmotionLabel = 'admiration' | 'amusement' | 'anger' | 'annoyance' | 'approval' | 'caring' | 'confusion' | 'curiosity' | 'desire' | 'disappointment' | 'disapproval' | 'disgust' | 'embarrassment' | 'excitement' | 'fear' | 'gratitude' | 'grief' | 'joy' | 'love' | 'nervousness' | 'neutral' | 'optimism' | 'pride' | 'realization' | 'relief' | 'remorse' | 'sadness' | 'surprise';
|
|
2
|
+
/** All 28 labels, in the SillyTavern canonical order. */
|
|
3
|
+
export declare const ALL_EMOTIONS: EmotionLabel[];
|
|
4
|
+
/**
|
|
5
|
+
* Classify a chat-message string into one of the 28 GoEmotions labels.
|
|
6
|
+
*
|
|
7
|
+
* Returns `'neutral'` when no rule fires, which is what every sprite pack
|
|
8
|
+
* uses as the fallback (and what `character_get_expression` falls back to
|
|
9
|
+
* server-side when the requested sprite is missing).
|
|
10
|
+
*
|
|
11
|
+
* @param text - The assistant's message text. Markdown formatting is fine —
|
|
12
|
+
* the regexes only care about word content.
|
|
13
|
+
* @param available - Optional restrict-set: only return labels present here.
|
|
14
|
+
* Useful when the caller knows which sprites the
|
|
15
|
+
* character actually ships and wants to avoid a Tauri
|
|
16
|
+
* round-trip for labels that will fall back anyway.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyEmotion(text: string | null | undefined, available?: readonly string[]): EmotionLabel;
|
|
19
|
+
//# sourceMappingURL=emotionClassifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emotionClassifier.d.ts","sourceRoot":"","sources":["../../../../src/components/AIToolbar/utils/emotionClassifier.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,YAAY,GAClB,YAAY,GACZ,WAAW,GACX,OAAO,GACP,WAAW,GACX,UAAU,GACV,QAAQ,GACR,WAAW,GACX,WAAW,GACX,QAAQ,GACR,gBAAgB,GAChB,aAAa,GACb,SAAS,GACT,eAAe,GACf,YAAY,GACZ,MAAM,GACN,WAAW,GACX,OAAO,GACP,KAAK,GACL,MAAM,GACN,aAAa,GACb,SAAS,GACT,UAAU,GACV,OAAO,GACP,aAAa,GACb,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,CAAC;AAEjB,yDAAyD;AACzD,eAAO,MAAM,YAAY,EAAE,YAAY,EA6BtC,CAAC;AAgNF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,YAAY,CAuB5G"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Lightweight emotion classifier for assistant message text.
|
|
2
|
+
//
|
|
3
|
+
// Picks one of the 28 SillyTavern / GoEmotions labels so the AIToolbar can
|
|
4
|
+
// switch the assistant's avatar to the matching expression sprite (see
|
|
5
|
+
// `packages-extensions/seraphina-character-extension/characters/Seraphina/`
|
|
6
|
+
// for the canonical sprite layout: `neutral.png`, `joy.png`, `caring.png`,
|
|
7
|
+
// `surprise.png`, etc.).
|
|
8
|
+
//
|
|
9
|
+
// This is intentionally a heuristic (regex/keyword scoring) — fast, offline,
|
|
10
|
+
// no model dependency — and is the same shape (`text → label`) as a real
|
|
11
|
+
// GoEmotions classifier, so it can be transparently swapped for an ONNX
|
|
12
|
+
// transformer later without touching the call sites.
|
|
13
|
+
//
|
|
14
|
+
// Limitations:
|
|
15
|
+
// - English only; would need rework for i18n responses.
|
|
16
|
+
// - Misses subtle nuance (sarcasm, mixed emotions) — picks the *strongest*
|
|
17
|
+
// signal and never returns more than one label.
|
|
18
|
+
// - Stage directions in italics ("smiles warmly") count the same as inline
|
|
19
|
+
// dialogue; that's actually desirable for character-card style replies
|
|
20
|
+
// where mood lives in the prose.
|
|
21
|
+
/** All 28 labels, in the SillyTavern canonical order. */
|
|
22
|
+
const RULES = [{
|
|
23
|
+
label: 'joy',
|
|
24
|
+
patterns: [/\b(happy|happiness|joy(ful)?|delight(ed|ful)?|cheerful|glad)\b/gi, /\b(smile[sd]?|grin(s|ned|ning)?|beam(s|ing|ed)?)\b/gi, /:\)|=\)|<3+/g]
|
|
25
|
+
}, {
|
|
26
|
+
label: 'amusement',
|
|
27
|
+
patterns: [/\b(laugh(s|ed|ing|ter)?|chuckle[sd]?|giggle[sd]?|snicker(s|ed|ing)?)\b/gi, /\b(amus(ed|ing|ement)|funny|hilarious|teasing)\b/gi, /\bha+ha+\b/gi, /lol\b/gi]
|
|
28
|
+
}, {
|
|
29
|
+
label: 'love',
|
|
30
|
+
patterns: [/\b(i love you|love you|my love|beloved|darling|sweetheart|dearest)\b/gi, /\b(adore[sd]?|cherish(ed|es)?|smitten)\b/gi],
|
|
31
|
+
weight: 2
|
|
32
|
+
}, {
|
|
33
|
+
label: 'caring',
|
|
34
|
+
patterns: [/\b(gentle(ly)?|tender(ly)?|softly|kind(ly|ness)?|warm(ly|th)?|reassuring(ly)?)\b/gi, /\b(comfort(s|ed|ing)?|soothing(ly)?|protect(s|ing|ed)?|nurturing)\b/gi, /\b(are you (ok|okay|alright)|how are you feeling|don'?t worry)\b/gi]
|
|
35
|
+
}, {
|
|
36
|
+
label: 'admiration',
|
|
37
|
+
patterns: [/\b(impressive|impressed|brilliant|magnificent|incredible|amazing|remarkable|astonishing|stunning|breathtaking)\b/gi, /\b(well done|great job|so proud of you)\b/gi]
|
|
38
|
+
}, {
|
|
39
|
+
label: 'approval',
|
|
40
|
+
patterns: [/\b(approve|agree|exactly|precisely|that'?s right|good idea|sounds good|works for me)\b/gi, /\b(yes,?\s+(of course|absolutely|certainly))/gi]
|
|
41
|
+
}, {
|
|
42
|
+
label: 'disapproval',
|
|
43
|
+
patterns: [/\b(disapprove|that'?s wrong|i don'?t agree|i wouldn'?t|shouldn'?t have)\b/gi, /\b(unacceptable|not okay)\b/gi]
|
|
44
|
+
}, {
|
|
45
|
+
label: 'anger',
|
|
46
|
+
patterns: [/\b(angry|furious|enraged|seething|livid|outraged)\b/gi, /\b(scowl(s|ed|ing)?|glare[sd]?|snarl(s|ed|ing)?|growl(s|ed|ing)?)\b/gi, /\bhow dare you\b/gi],
|
|
47
|
+
weight: 2
|
|
48
|
+
}, {
|
|
49
|
+
label: 'annoyance',
|
|
50
|
+
patterns: [/\b(annoy(ed|ing|ance)?|irritat(ed|ing|ion)|frustrat(ed|ing|ion))\b/gi, /\b(sigh(s|ed|ing)?|huff(s|ed|ing)?|rolls? (her|his|their) eyes)\b/gi, /\b(ugh|tsk)\b/gi]
|
|
51
|
+
}, {
|
|
52
|
+
label: 'fear',
|
|
53
|
+
patterns: [/\b(afraid|scared|terrified|frightened|fearful|horrified)\b/gi, /\b(trembl(es|ed|ing)|shiver(s|ed|ing)?|flinch(es|ed|ing)?)\b/gi, /\b(panic(ked|king)?|dread)\b/gi],
|
|
54
|
+
weight: 2
|
|
55
|
+
}, {
|
|
56
|
+
label: 'nervousness',
|
|
57
|
+
patterns: [/\b(nervous(ly|ness)?|anxious(ly)?|uneasy|jittery|tense(ly)?|on edge)\b/gi, /\b(fidget(s|ed|ing)?|bites? (her|his|their) lip|wrings? (her|his|their) hands)\b/gi]
|
|
58
|
+
}, {
|
|
59
|
+
label: 'sadness',
|
|
60
|
+
patterns: [/\b(sad(ness|ly)?|unhappy|sorrow(ful)?|heartbroken|miserable|melancholy|forlorn)\b/gi, /\b(tear(s|ful|y)|crying|weep(s|ing|ed)?|sob(s|bing|bed)?)\b/gi, /:\(/g],
|
|
61
|
+
weight: 2
|
|
62
|
+
}, {
|
|
63
|
+
label: 'grief',
|
|
64
|
+
patterns: [/\b(grief|grieving|mourn(s|ed|ing)?|bereaved|devastated)\b/gi, /\b(loss of|passed away|gone forever)\b/gi],
|
|
65
|
+
weight: 2
|
|
66
|
+
}, {
|
|
67
|
+
label: 'remorse',
|
|
68
|
+
patterns: [/\b(i'?m sorry|i am sorry|my apologies|apologi[sz]e|forgive me|regret(s|ted|ting)?|guilty|guilt)\b/gi, /\b(shouldn'?t have|wish i hadn'?t)\b/gi],
|
|
69
|
+
weight: 2
|
|
70
|
+
}, {
|
|
71
|
+
label: 'disappointment',
|
|
72
|
+
patterns: [/\b(disappointed|disappointing|let down|underwhelm(ed|ing)?|expected (more|better))\b/gi]
|
|
73
|
+
}, {
|
|
74
|
+
label: 'embarrassment',
|
|
75
|
+
patterns: [/\b(embarrass(ed|ing|ment)?|flustered|mortified|sheepish(ly)?)\b/gi, /\b(blush(es|ed|ing)?|cheeks (turn|burn|flush))\b/gi]
|
|
76
|
+
}, {
|
|
77
|
+
label: 'disgust',
|
|
78
|
+
patterns: [/\b(disgust(ed|ing)?|revolted|repulsed|nauseat(ed|ing)|gross|yuck|ew)\b/gi, /\b(grimace[sd]?|wrinkles? (her|his|their) nose)\b/gi]
|
|
79
|
+
}, {
|
|
80
|
+
label: 'excitement',
|
|
81
|
+
patterns: [/\b(excited(ly)?|thrilled|exhilarat(ed|ing)|exhilaration|elated|ecstatic|stoked|pumped)\b/gi, /\b(can'?t wait|bouncing|jumps? up)\b/gi]
|
|
82
|
+
}, {
|
|
83
|
+
label: 'gratitude',
|
|
84
|
+
patterns: [/\b(thank you|thanks|thank(ful|fully)?|grateful(ly)?|appreciat(e|ed|ing|ion))\b/gi],
|
|
85
|
+
weight: 2
|
|
86
|
+
}, {
|
|
87
|
+
label: 'pride',
|
|
88
|
+
patterns: [/\b(proud(ly)?|pride)\b/gi, /\b(chin (held )?high|stands? tall)\b/gi]
|
|
89
|
+
}, {
|
|
90
|
+
label: 'relief',
|
|
91
|
+
patterns: [/\b(relief|relieved|reliev(es|ed|ing)?)\b/gi, /\b(exhale[sd]? (deeply|slowly)|breathes? out)\b/gi]
|
|
92
|
+
}, {
|
|
93
|
+
label: 'optimism',
|
|
94
|
+
patterns: [/\b(hopeful(ly)?|optimist(ic)?|things will (work|turn) out|look(ing)? forward|we'?ll figure)\b/gi]
|
|
95
|
+
}, {
|
|
96
|
+
label: 'desire',
|
|
97
|
+
patterns: [/\b(crave[sd]?|yearn(s|ed|ing)?|long(s|ed|ing) for|want(s|ed|ing)? you|need(s|ed|ing)? you)\b/gi, /\b(lean(s|ed|ing)? in close|breathless)\b/gi]
|
|
98
|
+
}, {
|
|
99
|
+
label: 'curiosity',
|
|
100
|
+
patterns: [/\b(curious(ly)?|curiosity|intrigu(ed|ing)|wonder(s|ed|ing)? (about|what|why|how))\b/gi, /\btell me more\b/gi]
|
|
101
|
+
}, {
|
|
102
|
+
label: 'confusion',
|
|
103
|
+
patterns: [/\b(confus(ed|ing|ion)|puzzl(ed|ing)|baffl(ed|ing)|perplex(ed|ing))\b/gi, /\b(tilts? (her|his|their) head|raises? an eyebrow|i don'?t understand|what do you mean)\b/gi, /\?\?+/g]
|
|
104
|
+
}, {
|
|
105
|
+
label: 'realization',
|
|
106
|
+
patterns: [/\b(realiz(es|ed|ing)|realisation|i see now|of course!|that makes sense|finally understand)\b/gi, /\b(aha|eureka)\b/gi]
|
|
107
|
+
}, {
|
|
108
|
+
label: 'surprise',
|
|
109
|
+
patterns: [/\b(surpris(ed|ing|e)|astonish(ed|ing)|astounded|shocked|stunned|taken aback)\b/gi, /\b(gasp(s|ed|ing)?|eyes (widen|go wide))\b/gi, /\b(oh!|wha[at]?\?!)/gi]
|
|
110
|
+
}];
|
|
111
|
+
/**
|
|
112
|
+
* Classify a chat-message string into one of the 28 GoEmotions labels.
|
|
113
|
+
*
|
|
114
|
+
* Returns `'neutral'` when no rule fires, which is what every sprite pack
|
|
115
|
+
* uses as the fallback (and what `character_get_expression` falls back to
|
|
116
|
+
* server-side when the requested sprite is missing).
|
|
117
|
+
*
|
|
118
|
+
* @param text - The assistant's message text. Markdown formatting is fine —
|
|
119
|
+
* the regexes only care about word content.
|
|
120
|
+
* @param available - Optional restrict-set: only return labels present here.
|
|
121
|
+
* Useful when the caller knows which sprites the
|
|
122
|
+
* character actually ships and wants to avoid a Tauri
|
|
123
|
+
* round-trip for labels that will fall back anyway.
|
|
124
|
+
*/
|
|
125
|
+
function classifyEmotion(text, available) {
|
|
126
|
+
if (!text) return 'neutral';
|
|
127
|
+
let bestLabel = 'neutral';
|
|
128
|
+
let bestScore = 0;
|
|
129
|
+
for (const rule of RULES) {
|
|
130
|
+
const weight = rule.weight ?? 1;
|
|
131
|
+
let score = 0;
|
|
132
|
+
for (const pattern of rule.patterns) {
|
|
133
|
+
const matches = text.match(pattern);
|
|
134
|
+
if (matches) score += matches.length * weight;
|
|
135
|
+
}
|
|
136
|
+
if (score > bestScore) {
|
|
137
|
+
bestScore = score;
|
|
138
|
+
bestLabel = rule.label;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return bestLabel;
|
|
142
|
+
}export{classifyEmotion};//# sourceMappingURL=emotionClassifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emotionClassifier.js","sources":["../../../../src/components/AIToolbar/utils/emotionClassifier.ts"],"sourcesContent":[null],"names":[],"mappings":"AAqBA;AA8BA;AACA;AA6OA;;;;;;;;;;;;;AAaG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@admin-layout/tailwind-ui",
|
|
3
|
-
"version": "12.2.4-alpha.
|
|
3
|
+
"version": "12.2.4-alpha.58",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"typescript": {
|
|
97
97
|
"definition": "lib/index.d.ts"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "4cf5febc99804338d85d52ec12787d7bbb661bad"
|
|
100
100
|
}
|