@ray-js/t-agent-plugin-aistream 0.2.6-beta-4 → 0.2.6-beta-6

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.
@@ -79,19 +79,19 @@ export function promisify(fn) {
79
79
  export function listening(on, off) {
80
80
  let enableMock = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
81
81
  return listener => {
82
+ const cb = event => {
83
+ logger.debug('listening on event', on.name, event.detail);
84
+ listener(event.detail);
85
+ };
86
+ on(listener);
82
87
  if (getEnableMock() && enableMock) {
83
- const cb = event => {
84
- logger.debug('listening on event', on.name, event.detail);
85
- listener(event.detail);
86
- };
87
88
  mock.emitter.addEventListener(on.name, cb);
88
- return () => {
89
- mock.emitter.removeEventListener(on.name, cb);
90
- };
91
89
  }
92
- on(listener);
93
90
  return () => {
94
91
  off(listener);
92
+ if (getEnableMock() && enableMock) {
93
+ mock.emitter.removeEventListener(on.name, cb);
94
+ }
95
95
  };
96
96
  };
97
97
  }
@@ -1,4 +1,4 @@
1
- import { ChatAgent, ChatCardObject, ChatMessage, ChatTile, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
1
+ import { ChatAgent, ChatCardObject, ChatMessage, ChatMessageStatus, ChatTile, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
2
2
  import { TTTAction } from './utils';
3
3
  import { ConnectClientType, ReceivedTextSkillPacketBody } from './AIStreamTypes';
4
4
  import { ChatHistoryStore, StoredMessageObject } from './ChatHistoryStore';
@@ -42,6 +42,9 @@ export interface AIStreamHooks {
42
42
  onMessageParse: (msgItem: StoredMessageObject, result: {
43
43
  messages: ChatMessage[];
44
44
  }) => void;
45
+ onTextCompose: (respMsg: ChatMessage, status: ChatMessageStatus, result: {
46
+ text: string;
47
+ }) => void;
45
48
  onSkillCompose: (skill: ReceivedTextSkillPacketBody[], respMsg: ChatMessage, result: {
46
49
  messages: ChatMessage[];
47
50
  }) => void;
@@ -78,6 +81,7 @@ export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAge
78
81
  data: string;
79
82
  }>;
80
83
  onSkillCompose: (fn: AIStreamHooks['onSkillCompose']) => () => void;
84
+ onTextCompose: (fn: AIStreamHooks['onTextCompose']) => () => void;
81
85
  onSkillsEnd: (fn: AIStreamHooks['onSkillsEnd']) => () => void;
82
86
  onCardsReceived: (fn: AIStreamHooks['onCardsReceived']) => () => void;
83
87
  onTTTAction: (fn: AIStreamHooks['onTTTAction']) => () => void;
@@ -354,6 +354,13 @@ export function withAIStream() {
354
354
  logger.debug('withAIStream chat agent.flushStreamToShow');
355
355
  const result = {
356
356
  messages: await agent.flushStreamToShow(message, response, {
357
+ textCompose: async (message, text, status) => {
358
+ const result = {
359
+ text
360
+ };
361
+ await hooks.callHook('onTextCompose', message, status, result);
362
+ return result.text;
363
+ },
357
364
  attachmentCompose: async (respMsg, part) => {
358
365
  const result = {
359
366
  messages: []
@@ -555,6 +562,9 @@ export function withAIStream() {
555
562
  onSkillCompose: fn => {
556
563
  return hooks.hook('onSkillCompose', fn);
557
564
  },
565
+ onTextCompose: fn => {
566
+ return hooks.hook('onTextCompose', fn);
567
+ },
558
568
  onSkillsEnd,
559
569
  onCardsReceived: fn => {
560
570
  return hooks.hook('onCardsReceived', fn);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.6-beta-4",
3
+ "version": "0.2.6-beta-6",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@types/url-parse": "^1.4.11"
37
37
  },
38
- "gitHead": "c1afc79e00950e8eb385ec233f74e1677a9c93cf"
38
+ "gitHead": "2f18554f908818b62ab24ead773d4e74fd5ef7fc"
39
39
  }