@ray-js/t-agent-plugin-aistream 0.2.6-beta-3 → 0.2.6-beta-5

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.
@@ -272,7 +272,8 @@ mock.hooks.hook('sendEventEnd', async context => {
272
272
  }
273
273
  const ctx = {
274
274
  data: event.data,
275
- responseText: ''
275
+ responseText: '',
276
+ wordDelayMs: 100
276
277
  };
277
278
  const [error] = await tryCatch(() => mock.hooks.callHook('sendToAIStream', ctx));
278
279
  if (error) {
@@ -297,6 +298,7 @@ mock.hooks.hook('sendEventEnd', async context => {
297
298
  return;
298
299
  }
299
300
  const text = ctx.responseText || '⚠️ No mock text response matched!';
301
+ const wordDelayMs = ctx.wordDelayMs || 100;
300
302
  const words = splitString(text);
301
303
  if (event.controller.signal.aborted || session.closed) {
302
304
  return;
@@ -309,7 +311,7 @@ mock.hooks.hook('sendEventEnd', async context => {
309
311
  const bizId = generateId();
310
312
  event.replyText(StreamFlag.START);
311
313
  for (const word of words) {
312
- await mock.sleep(100);
314
+ await mock.sleep(wordDelayMs);
313
315
  if (event.controller.signal.aborted || session.closed) {
314
316
  return;
315
317
  }
@@ -15,6 +15,7 @@ export interface SendToAIStreamContext {
15
15
  userData?: Attribute[];
16
16
  }>;
17
17
  responseText: string | undefined;
18
+ wordDelayMs: number;
18
19
  responseSkills?: ReceivedTextSkillPacketBody[];
19
20
  }
20
21
  interface AsrDetectionContext {
@@ -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-3",
3
+ "version": "0.2.6-beta-5",
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": "e478ba7ce360563e061efc24d6a8dfb495c5f9e9"
38
+ "gitHead": "60f0d3f33a78b76aae90b22942d9bf64c430e565"
39
39
  }