@ray-js/t-agent 0.2.0-beta-1 → 0.2.0-beta-3
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/dist/chat/ChatMessage.js
CHANGED
|
@@ -107,7 +107,7 @@ export default class ChatMessage {
|
|
|
107
107
|
await this.agent.hooks.callHook('onMessagePersist:before', payload, this);
|
|
108
108
|
await this.agent.hooks.callHook('onMessagePersist', payload, this);
|
|
109
109
|
await this.agent.hooks.callHook('onMessagePersist:after', payload, this);
|
|
110
|
-
logger.debug('%
|
|
110
|
+
logger.debug('%conMessagePersist', 'background: gray; color: white', payload, this);
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
setTilesLocked(locked) {
|
|
@@ -12,6 +12,7 @@ export default class ChatSession {
|
|
|
12
12
|
sessionId: string | null;
|
|
13
13
|
readonly messages: Map<string, ChatMessage>;
|
|
14
14
|
constructor(agent: ChatAgent);
|
|
15
|
+
initValue: (key: string, value: any) => void;
|
|
15
16
|
set: (key: string, value: any) => Promise<void>;
|
|
16
17
|
get: <T = any>(key: string, defaultValue?: T | undefined) => any;
|
|
17
18
|
getData: () => Record<string, any>;
|
package/dist/chat/ChatSession.js
CHANGED
|
@@ -11,6 +11,9 @@ export default class ChatSession {
|
|
|
11
11
|
_defineProperty(this, "isNewChat", true);
|
|
12
12
|
_defineProperty(this, "sessionId", null);
|
|
13
13
|
_defineProperty(this, "messages", new Map());
|
|
14
|
+
_defineProperty(this, "initValue", (key, value) => {
|
|
15
|
+
this.data.set(key, value);
|
|
16
|
+
});
|
|
14
17
|
_defineProperty(this, "set", async (key, value) => {
|
|
15
18
|
const oldValue = this.data.get(key);
|
|
16
19
|
if (oldValue === value) {
|
package/dist/plugins/debug.js
CHANGED
|
@@ -5,13 +5,6 @@ export function withDebug(options) {
|
|
|
5
5
|
throw new Error('Debug plugin already exists');
|
|
6
6
|
}
|
|
7
7
|
const start = () => {
|
|
8
|
-
// debugs.push(
|
|
9
|
-
// createDebugger(agent.hooks, { tag: 'ChatAgent', filter: options?.filter }),
|
|
10
|
-
// createDebugger(agent.session.hooks, { tag: 'ChatSession', filter: options?.filter }),
|
|
11
|
-
// )
|
|
12
|
-
// for (const hook of agent.pluginHooks) {
|
|
13
|
-
// debugs.push(createDebugger(hook, { tag: 'ChatPlugin', filter: options?.filter }))
|
|
14
|
-
// }
|
|
15
8
|
Logger.setLogLevel('debug');
|
|
16
9
|
};
|
|
17
10
|
if ((options === null || options === void 0 ? void 0 : options.autoStart) !== false) {
|
package/dist/plugins/ui.d.ts
CHANGED
|
@@ -23,8 +23,27 @@ export interface UIEventMap {
|
|
|
23
23
|
};
|
|
24
24
|
[key: string]: any;
|
|
25
25
|
}
|
|
26
|
+
export interface UIHooksContext<P = any, R = any> {
|
|
27
|
+
payload: P;
|
|
28
|
+
result: R | null;
|
|
29
|
+
error?: Error;
|
|
30
|
+
}
|
|
31
|
+
export interface UIHooks {
|
|
32
|
+
onMessageFeedback: (context: UIHooksContext<{
|
|
33
|
+
messageId: string;
|
|
34
|
+
content?: string;
|
|
35
|
+
rate?: string;
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}, {
|
|
38
|
+
success: boolean;
|
|
39
|
+
}>) => void | Promise<void>;
|
|
40
|
+
[key: string]: (context: UIHooksContext) => void;
|
|
41
|
+
}
|
|
26
42
|
export declare function withUI(): (agent: ChatAgent) => {
|
|
43
|
+
hooks: import("hookable").Hookable<UIHooks, string>;
|
|
27
44
|
ui: {
|
|
45
|
+
callHook: <K extends keyof UIHooks>(hookName: K, payload: UIHooks[K] extends (context: UIHooksContext<infer P, any>) => void ? P : never) => Promise<UIHooks[K] extends (context: UIHooksContext<any, infer R>) => void ? R : null>;
|
|
46
|
+
hook: <K_1 extends keyof UIHooks>(hookName: K_1, fn: UIHooks[K_1]) => () => void;
|
|
28
47
|
emitter: Emitter;
|
|
29
48
|
emitEvent: <T extends keyof UIEventMap>(eventName: T, detail: UIEventMap[T]) => void;
|
|
30
49
|
onEvent: <T_1 extends keyof UIEventMap>(eventName: T_1, handler: (detail: UIEventMap[T_1]) => void) => () => void;
|
package/dist/plugins/ui.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
2
|
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
3
4
|
import { Emitter, EmitterEvent } from '../chat';
|
|
5
|
+
import { createHooks } from 'hookable';
|
|
4
6
|
export function withUI() {
|
|
7
|
+
const hooks = createHooks();
|
|
5
8
|
return agent => {
|
|
6
9
|
if (agent.plugins.ui) {
|
|
7
10
|
throw new Error('UI plugin already exists');
|
|
@@ -28,6 +31,12 @@ export function withUI() {
|
|
|
28
31
|
};
|
|
29
32
|
emitEvent('messageChange', detail);
|
|
30
33
|
}, 'after');
|
|
34
|
+
agent.onAgentDispose(() => {
|
|
35
|
+
const types = Object.keys(emitter.listeners);
|
|
36
|
+
for (const type of types) {
|
|
37
|
+
delete emitter.listeners[type];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
31
40
|
agent.session.onChange((key, value, oldValue) => {
|
|
32
41
|
emitEvent('sessionChange', {
|
|
33
42
|
key,
|
|
@@ -36,7 +45,28 @@ export function withUI() {
|
|
|
36
45
|
});
|
|
37
46
|
});
|
|
38
47
|
return {
|
|
48
|
+
hooks,
|
|
39
49
|
ui: {
|
|
50
|
+
callHook: async (hookName, payload) => {
|
|
51
|
+
const context = {
|
|
52
|
+
payload,
|
|
53
|
+
result: null
|
|
54
|
+
};
|
|
55
|
+
await hooks.callHook(hookName, context);
|
|
56
|
+
if (context.error) {
|
|
57
|
+
throw context.error;
|
|
58
|
+
}
|
|
59
|
+
return context.result;
|
|
60
|
+
},
|
|
61
|
+
hook: (hookName, fn) => {
|
|
62
|
+
return hooks.hook(hookName, async context => {
|
|
63
|
+
try {
|
|
64
|
+
await fn(context);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
context.error = error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
},
|
|
40
70
|
emitter,
|
|
41
71
|
emitEvent,
|
|
42
72
|
onEvent: (eventName, handler) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent",
|
|
3
|
-
"version": "0.2.0-beta-
|
|
3
|
+
"version": "0.2.0-beta-3",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"build": "ray build --type=component --output dist",
|
|
27
27
|
"clean": "rimraf ./dist"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "03c4af7fe4cfe27069db83d99a61042c8053399e"
|
|
30
30
|
}
|