@ray-js/t-agent-plugin-aistream 0.2.7-beta.6 → 0.2.7-beta.8

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.
@@ -1,4 +1,3 @@
1
- import "core-js/modules/web.dom-collections.iterator.js";
2
1
  import { BuildInSkillCode, ReceivedSmartHomeSkillAction } from '../AIStreamTypes';
3
2
  export function withBuildIn() {
4
3
  return _agent => {
@@ -56,13 +55,15 @@ export function withBuildIn() {
56
55
  sceneInfo: [],
57
56
  changeInfo: []
58
57
  };
59
- for (const skill of skills) {
58
+ for (let i = 0; i < skills.length; i++) {
59
+ const skill = skills[i];
60
60
  if (skill.code !== BuildInSkillCode.SMART_HOME) {
61
61
  continue;
62
62
  }
63
63
  const content = skill;
64
64
  if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_SCENE) {
65
- for (const scene of content.general.data.scenes) {
65
+ for (let i1 = 0; i1 < content.general.data.scenes.length; i1++) {
66
+ const scene = content.general.data.scenes[i1];
66
67
  executeData.sceneInfo.push({
67
68
  type: scene.type,
68
69
  enabled: scene.enable,
@@ -76,7 +77,8 @@ export function withBuildIn() {
76
77
  });
77
78
  }
78
79
  } else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_SCENE) {
79
- for (const scene of content.general.data.scenes) {
80
+ for (let i1 = 0; i1 < content.general.data.scenes.length; i1++) {
81
+ const scene = content.general.data.scenes[i1];
80
82
  operateData.sceneInfo.push({
81
83
  type: scene.type,
82
84
  icon: scene.icon,
@@ -89,7 +91,8 @@ export function withBuildIn() {
89
91
  });
90
92
  }
91
93
  } else if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_DEVICE) {
92
- for (const dev of content.general.data.devices) {
94
+ for (let i1 = 0; i1 < content.general.data.devices.length; i1++) {
95
+ const dev = content.general.data.devices[i1];
93
96
  executeData.deviceInfo.push({
94
97
  icon: dev.icon,
95
98
  name: dev.name,
@@ -100,7 +103,8 @@ export function withBuildIn() {
100
103
  });
101
104
  }
102
105
  } else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_DEVICE) {
103
- for (const dev of content.general.data.devices) {
106
+ for (let i1 = 0; i1 < content.general.data.devices.length; i1++) {
107
+ const dev = content.general.data.devices[i1];
104
108
  operateData.deviceInfo.push({
105
109
  icon: dev.icon,
106
110
  name: dev.name,
@@ -128,8 +132,9 @@ export function withBuildIn() {
128
132
  const data = {
129
133
  documents: []
130
134
  };
131
- for (const skill of skills) {
135
+ for (let i = 0; i < skills.length; i++) {
132
136
  var _content$custom;
137
+ const skill = skills[i];
133
138
  if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
134
139
  continue;
135
140
  }
@@ -137,7 +142,8 @@ export function withBuildIn() {
137
142
  if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
138
143
  continue;
139
144
  }
140
- for (const doc of content.custom.data.documents) {
145
+ for (let i1 = 0; i1 < content.custom.data.documents.length; i1++) {
146
+ const doc = content.custom.data.documents[i1];
141
147
  data.documents.push({
142
148
  title: doc.title,
143
149
  url: doc.url
@@ -330,7 +330,8 @@ export class AIStreamSession {
330
330
  sessionId: this.sessionId
331
331
  };
332
332
  this.activeObserver = new AIStreamObserver(this.onDataEntry, this.pool);
333
- for (const revDataChannel of this.revDataChannels) {
333
+ for (let i = 0; i < this.revDataChannels.length; i++) {
334
+ const revDataChannel = this.revDataChannels[i];
334
335
  if (revDataChannel.startsWith('text')) {
335
336
  observerOptions.text = true;
336
337
  }
@@ -95,17 +95,13 @@ mock.hooks.hook('disconnect', context => {
95
95
  mock.data.set('sessionMap', new Map());
96
96
  });
97
97
  mock.hooks.hook('queryAgentToken', context => {
98
- var _context$options$extP, _context$options$extP2, _context$options$extP3;
98
+ var _context$options$extP, _context$options$extP3, _context$options$extP4;
99
99
  const agentToken = generateId();
100
100
  const map = mock.data.get('tokenMap');
101
- map.set(agentToken, {
102
- onlyAsr: ((_context$options$extP = context.options.extParams) === null || _context$options$extP === void 0 ? void 0 : _context$options$extP.onlyAsr) || false,
103
- needTts: ((_context$options$extP2 = context.options.extParams) === null || _context$options$extP2 === void 0 ? void 0 : _context$options$extP2.needTts) || false
104
- });
105
101
  let chatId;
106
- if (((_context$options$extP3 = context.options.extParams) === null || _context$options$extP3 === void 0 ? void 0 : _context$options$extP3.dialogueMode) === 1) {
107
- var _context$options$extP4;
108
- if ((_context$options$extP4 = context.options.extParams) !== null && _context$options$extP4 !== void 0 && _context$options$extP4.chatId) {
102
+ if (((_context$options$extP = context.options.extParams) === null || _context$options$extP === void 0 ? void 0 : _context$options$extP.dialogueMode) === 1) {
103
+ var _context$options$extP2;
104
+ if ((_context$options$extP2 = context.options.extParams) !== null && _context$options$extP2 !== void 0 && _context$options$extP2.chatId) {
109
105
  // 如果参数有传吗,则使用传入的 chatId
110
106
  chatId = context.options.extParams.chatId;
111
107
  } else {
@@ -113,6 +109,11 @@ mock.hooks.hook('queryAgentToken', context => {
113
109
  chatId = "chatId-".concat(generateId());
114
110
  }
115
111
  }
112
+ map.set(agentToken, {
113
+ onlyAsr: ((_context$options$extP3 = context.options.extParams) === null || _context$options$extP3 === void 0 ? void 0 : _context$options$extP3.onlyAsr) || false,
114
+ needTts: ((_context$options$extP4 = context.options.extParams) === null || _context$options$extP4 === void 0 ? void 0 : _context$options$extP4.needTts) || false,
115
+ chatId
116
+ });
116
117
  context.result = {
117
118
  agentToken,
118
119
  bizConfig: {
@@ -144,7 +145,8 @@ mock.hooks.hook('createSession', context => {
144
145
  sendDataChannels: ['audio', 'video', 'text', 'image'],
145
146
  revDataChannels: ['text', 'audio'],
146
147
  currentEvent: null,
147
- tokenConfig
148
+ tokenConfig,
149
+ chatId: tokenConfig.chatId
148
150
  };
149
151
  map.set(session.sessionId, session);
150
152
  context.result = {
@@ -273,7 +275,8 @@ mock.hooks.hook('sendEventEnd', async context => {
273
275
  const ctx = {
274
276
  data: event.data,
275
277
  responseText: '',
276
- wordDelayMs: 100
278
+ wordDelayMs: 100,
279
+ chatId: session.chatId
277
280
  };
278
281
  const [error] = await tryCatch(() => mock.hooks.callHook('sendToAIStream', ctx));
279
282
  if (error) {
@@ -310,7 +313,8 @@ mock.hooks.hook('sendEventEnd', async context => {
310
313
  }
311
314
  const bizId = generateId();
312
315
  event.replyText(StreamFlag.START);
313
- for (const word of words) {
316
+ for (let i = 0; i < words.length; i++) {
317
+ const word = words[i];
314
318
  await mock.sleep(wordDelayMs);
315
319
  if (event.controller.signal.aborted || session.closed) {
316
320
  return;
@@ -345,7 +349,8 @@ mock.hooks.hook('sendEventEnd', async context => {
345
349
  return;
346
350
  }
347
351
  if ((_ctx$responseSkills = ctx.responseSkills) !== null && _ctx$responseSkills !== void 0 && _ctx$responseSkills.length) {
348
- for (const skill of ctx.responseSkills) {
352
+ for (let i = 0; i < ctx.responseSkills.length; i++) {
353
+ const skill = ctx.responseSkills[i];
349
354
  await mock.sleep(100);
350
355
  if (event.controller.signal.aborted || session.closed) {
351
356
  return;
@@ -462,7 +467,8 @@ mock.hooks.hook('startRecordAndSendAudioData', async context => {
462
467
  text
463
468
  }
464
469
  });
465
- for (const part of parts) {
470
+ for (let i = 0; i < parts.length; i++) {
471
+ const part = parts[i];
466
472
  if (finishController.signal.aborted) {
467
473
  break;
468
474
  }
@@ -12,6 +12,7 @@ export interface SendToAIStreamContext {
12
12
  type: 'image';
13
13
  path: string;
14
14
  }>;
15
+ chatId: string;
15
16
  responseText: string | undefined;
16
17
  wordDelayMs: number;
17
18
  responseSkills?: ReceivedTextSkillPacketBody[];
@@ -33,7 +33,8 @@ const mock = {
33
33
  if (!rows) {
34
34
  return [];
35
35
  }
36
- for (const row of rows) {
36
+ for (let i = 0; i < rows.length; i++) {
37
+ const row = rows[i];
37
38
  mock.database.set(row.id, row);
38
39
  mock.lastId = Math.max(mock.lastId, row.id);
39
40
  }
@@ -24,7 +24,8 @@ export function sendBlocksToAIStream(params) {
24
24
  getUserData
25
25
  } = params;
26
26
  let audioEmitter = null;
27
- for (const block of blocks) {
27
+ for (let i = 0; i < blocks.length; i++) {
28
+ const block = blocks[i];
28
29
  if (block.type === 'audio') {
29
30
  if (audioEmitter) {
30
31
  throw new Error('only one audio emitter is allowed');
@@ -271,7 +272,8 @@ export function sendBlocksToAIStream(params) {
271
272
  }
272
273
  });
273
274
  event.on('error', emitError);
274
- for (const block of blocks) {
275
+ for (let i = 0; i < blocks.length; i++) {
276
+ const block = blocks[i];
275
277
  if (block.type === 'text') {
276
278
  event.write({
277
279
  type: 'text',
@@ -272,7 +272,8 @@ export function withAIStream() {
272
272
  userData
273
273
  } = options || {};
274
274
  let audioEmitter = null;
275
- for (const block of blocks) {
275
+ for (let i = 0; i < blocks.length; i++) {
276
+ const block = blocks[i];
276
277
  if (block.type === 'audio') {
277
278
  if (audioEmitter) {
278
279
  throw new Error('only one audio emitter is allowed');
@@ -423,7 +424,8 @@ export function withAIStream() {
423
424
  if (valid) {
424
425
  await message.persist();
425
426
  const [_, ...rest] = result.messages;
426
- for (const m of rest) {
427
+ for (let i = 0; i < rest.length; i++) {
428
+ const m = rest[i];
427
429
  await m.show();
428
430
  await m.persist();
429
431
  }
@@ -555,8 +557,9 @@ export function withAIStream() {
555
557
  };
556
558
  onSkillsEnd(async (skills, respMsg, result) => {
557
559
  const cards = [];
558
- for (const skill of skills) {
560
+ for (let i = 0; i < skills.length; i++) {
559
561
  var _skill$custom, _skill$general;
562
+ const skill = skills[i];
560
563
  if ((_skill$custom = skill.custom) !== null && _skill$custom !== void 0 && (_skill$custom = _skill$custom.data) !== null && _skill$custom !== void 0 && _skill$custom.aiCards) {
561
564
  for (const card of skill.custom.data.aiCards) {
562
565
  cards.push(card);
@@ -572,7 +575,8 @@ export function withAIStream() {
572
575
  cards: cards
573
576
  };
574
577
  await hooks.callHook('onCardsReceived', skills, r);
575
- for (const card of cards) {
578
+ for (let i = 0; i < cards.length; i++) {
579
+ const card = cards[i];
576
580
  const m = createMessage({
577
581
  role: respMsg.role,
578
582
  status: ChatMessageStatus.FINISH,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.7-beta.6",
3
+ "version": "0.2.7-beta.8",
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": "8c74cd727802f09ac6294a88ee72464fc39db49c"
38
+ "gitHead": "31a0d88f88eddae8bfd802e4861c76cd02c07692"
39
39
  }