@ray-js/t-agent-ui-ray 0.2.0-beta-1 → 0.2.0-beta-2

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,7 +1,7 @@
1
1
  import React from 'react';
2
- export declare const WaveformVisualizer: React.FC<{
3
- data: number[];
4
- }>;
2
+ export declare const WaveformVisualizer: ({ amplitudeCount }: {
3
+ amplitudeCount: number;
4
+ }) => React.JSX.Element;
5
5
  interface IProps {
6
6
  amplitudeCount: number;
7
7
  recording: boolean;
@@ -2,52 +2,55 @@ import "core-js/modules/es.regexp.exec.js";
2
2
  import "core-js/modules/esnext.iterator.constructor.js";
3
3
  import "core-js/modules/esnext.iterator.map.js";
4
4
  import "core-js/modules/web.dom-collections.iterator.js";
5
- import React, { useMemo, useState } from 'react';
5
+ import React, { useState } from 'react';
6
6
  import { Button, View } from '@ray-js/ray';
7
7
  import cx from 'clsx';
8
8
  import { useOnEvent, useTranslate } from '../../hooks';
9
- export const WaveformVisualizer = /*#__PURE__*/React.memo(_ref => {
9
+ export const WaveformVisualizer = _ref => {
10
10
  let {
11
- data
11
+ amplitudeCount
12
12
  } = _ref;
13
- // 缓存计算后的波形条样式
14
- const bars = useMemo(() => {
15
- return data.map((value, index) => {
16
- // 将数值映射到高度范围(0-100 → 2px-20px)
17
-
18
- return {
19
- height: "".concat(2 + value / 100 * 18, "px"),
20
- // 添加渐变色偏移效果
21
- animationDelay: "".concat(index * 10, "ms")
22
- };
23
- });
24
- }, [data]);
25
- return /*#__PURE__*/React.createElement(View, {
26
- className: "t-agent-message-input-waveform-container"
27
- }, bars.map((barStyle, index) => /*#__PURE__*/React.createElement(View
13
+ const [bars, setBars] = useState(() => Array.from({
14
+ length: amplitudeCount
15
+ }, (_, index) => /*#__PURE__*/React.createElement(View
28
16
  // eslint-disable-next-line react/no-array-index-key
29
17
  , {
30
18
  key: "asr_wave_".concat(index),
31
19
  className: "t-agent-message-input-waveform-bar",
32
- style: barStyle
33
- // role="progressbar"
34
- ,
35
- "aria-valuenow": data[index],
36
- "aria-valuemin": 0,
37
- "aria-valuemax": 100
20
+ style: {
21
+ height: 0,
22
+ // 添加渐变色偏移效果
23
+ animationDelay: "".concat(index * 10, "ms")
24
+ }
38
25
  })));
39
- });
26
+ useOnEvent('amplitudes', val => {
27
+ const waveBase = val.body.amplitudes || [];
28
+ const bars = waveBase.map((item, index) => {
29
+ const value = item > 1 ? 1 : item * 100;
30
+ // 将数值映射到高度范围(0-100 → 2px-20px)
31
+ // const height = 2 + (value / 100) * 18;
32
+ return /*#__PURE__*/React.createElement(View
33
+ // eslint-disable-next-line react/no-array-index-key
34
+ , {
35
+ key: "asr_wave_".concat(index),
36
+ className: "t-agent-message-input-waveform-bar t-agent-item",
37
+ style: {
38
+ height: "".concat(value, "%"),
39
+ // 添加渐变色偏移效果
40
+ animationDelay: "".concat(index * 10, "ms")
41
+ }
42
+ });
43
+ });
44
+ setBars(bars);
45
+ });
46
+ return /*#__PURE__*/React.createElement(View, {
47
+ className: "t-agent-message-input-waveform-container"
48
+ }, bars);
49
+ };
40
50
  const AsrInput = props => {
41
51
  const [asrElementBounds, setAsrElementBounds] = useState(null);
42
52
  const t = useTranslate();
43
- const [waveData, setWaveData] = React.useState(Array.from({
44
- length: props.amplitudeCount
45
- }, () => 0));
46
53
  const [ptt, setPtt] = useState(false);
47
- useOnEvent('amplitudes', val => {
48
- const waveBase = val.body.amplitudes || [];
49
- setWaveData(waveBase.map(item => item > 1 ? 1 : item * 100));
50
- });
51
54
  const onVoiceTouchEnd = e => {
52
55
  const touch = e.origin.changedTouches[0];
53
56
  const touchY = touch.clientY;
@@ -97,7 +100,7 @@ const AsrInput = props => {
97
100
  }, t('t-agent.input.asr.oninput.text.top')), /*#__PURE__*/React.createElement(View, {
98
101
  className: "t-agent-message-input-oninput-text-center"
99
102
  }, t('t-agent.input.asr.oninput.text.center')), /*#__PURE__*/React.createElement(WaveformVisualizer, {
100
- data: waveData
103
+ amplitudeCount: props.amplitudeCount
101
104
  })) : /*#__PURE__*/React.createElement(View, {
102
105
  className: "t-agent-message-input-ptt-text"
103
106
  }, " ", t('t-agent.input.asr.ptt'))), !props.recording && /*#__PURE__*/React.createElement(Button, {
@@ -244,6 +244,7 @@ export default function MessageInputAIStream(props) {
244
244
  });
245
245
  console.error(event);
246
246
  setRecord({
247
+ startAt: 0,
247
248
  recording: false,
248
249
  confirm: null,
249
250
  cancel: null
@@ -2,7 +2,7 @@ import '../index.less';
2
2
  import { Button, Text, View, Textarea } from '@ray-js/components';
3
3
  import React from 'react';
4
4
  import cx from 'clsx';
5
- import { useAsrInput } from '../../hooks';
5
+ import { useAsrInput } from './useAsrInput';
6
6
  export default function AsrInput(props) {
7
7
  const {
8
8
  responding,
@@ -1,7 +1,7 @@
1
1
  import "core-js/modules/web.dom-collections.iterator.js";
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { Asr, AsrDetectResultState } from '@ray-js/t-agent-plugin-assistant';
4
- import { useIsUnmounted } from './useIsUnmounted';
4
+ import { useIsUnmounted } from '../../hooks';
5
5
  export let AsrErrorCode = /*#__PURE__*/function (AsrErrorCode) {
6
6
  AsrErrorCode[AsrErrorCode["SHORT_TIME"] = 0] = "SHORT_TIME";
7
7
  return AsrErrorCode;
@@ -355,28 +355,33 @@
355
355
  display: flex;
356
356
  align-items: center;
357
357
  justify-content: center;
358
- gap: 2px;
359
- height: 40px;
360
- padding: 8px 0;
358
+ height: 80rpx;
359
+ padding: 18rpx 0;
361
360
  }
362
361
 
363
362
  .t-agent-message-input-waveform-bar {
364
- width: 2px;
365
- min-height: 2px;
366
- background-color: #4a90e2;
367
- border-radius: 1px;
368
- transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
363
+ width: 4rpx;
364
+ min-height: 4rpx;
365
+ background-color: var(--app-M4);
366
+ border-radius: 2rpx;
367
+ transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
369
368
  animation: colorPulse 2s infinite;
369
+ margin-right: 4rpx;
370
+ opacity: 1;
371
+
372
+ &:last-child {
373
+ margin-right: 0;
374
+ }
370
375
  }
371
376
 
372
377
  @keyframes colorPulse {
373
378
  0% {
374
- background-color: #4a90e2;
379
+ opacity: 1;
375
380
  }
376
381
  50% {
377
- background-color: #7cb3ff;
382
+ opacity: 0.8;
378
383
  }
379
384
  100% {
380
- background-color: #4a90e2;
385
+ opacity: 1;
381
386
  }
382
387
  }
@@ -1,7 +1,17 @@
1
1
  import './index.less';
2
2
  import { ChatCardObject } from '@ray-js/t-agent';
3
- import { WorkflowReplyResource } from '@ray-js/t-agent-plugin-assistant';
4
3
  import React from 'react';
4
+ declare enum WorkflowReplyResourceType {
5
+ Image = 1,
6
+ Video = 2,
7
+ Web = 3,
8
+ MiniProgram = 4
9
+ }
10
+ interface WorkflowReplyResource {
11
+ type: WorkflowReplyResourceType;
12
+ title: string;
13
+ url: string;
14
+ }
5
15
  interface CardData {
6
16
  resources: WorkflowReplyResource[];
7
17
  }
@@ -1,11 +1,17 @@
1
1
  import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.map.js";
3
3
  import './index.less';
4
- import { WorkflowReplyResourceType } from '@ray-js/t-agent-plugin-assistant';
5
4
  import { View } from '@ray-js/components';
6
5
  import React from 'react';
7
6
  import { Image, Video } from '@ray-js/ray';
8
7
  import { useSendAction } from '../../hooks';
8
+ var WorkflowReplyResourceType = /*#__PURE__*/function (WorkflowReplyResourceType) {
9
+ WorkflowReplyResourceType[WorkflowReplyResourceType["Image"] = 1] = "Image";
10
+ WorkflowReplyResourceType[WorkflowReplyResourceType["Video"] = 2] = "Video";
11
+ WorkflowReplyResourceType[WorkflowReplyResourceType["Web"] = 3] = "Web";
12
+ WorkflowReplyResourceType[WorkflowReplyResourceType["MiniProgram"] = 4] = "MiniProgram";
13
+ return WorkflowReplyResourceType;
14
+ }(WorkflowReplyResourceType || {});
9
15
  const WorkflowReplyCard = props => {
10
16
  const {
11
17
  cardData
@@ -1,11 +1,11 @@
1
- import { TTTAction } from '@ray-js/t-agent-plugin-assistant';
1
+ import { TTTAction } from '../types';
2
2
  export declare const useChatAgent: () => import("../contexts").UIChatAgent;
3
3
  export declare const useAgentMessage: () => {
4
4
  messages: import("@ray-js/t-agent").ChatMessageObject[];
5
5
  keyboardHeight: number;
6
6
  };
7
- export declare const useRenderOptions: () => import("..").RenderOptions;
7
+ export declare const useRenderOptions: () => import("../types").RenderOptions;
8
8
  export declare const useOnEvent: (eventName: string, callback: (details: any) => void) => void;
9
9
  export declare const useEmitEvent: () => <T extends keyof import("@ray-js/t-agent").UIEventMap>(eventName: T, detail: import("@ray-js/t-agent").UIEventMap[T]) => void;
10
- export declare const useTileProps: () => import("..").TileProps<any, any>;
10
+ export declare const useTileProps: () => import("../types").TileProps<any, any>;
11
11
  export declare const useSendAction: () => (action: TTTAction) => void;
@@ -1,6 +1,5 @@
1
1
  export * from './context';
2
2
  export * from './useAttachmentInput';
3
- export * from './useAsrInput';
4
3
  export * from './useIsUnmounted';
5
4
  export * from './useLongPress';
6
5
  export * from './useTranslate';
@@ -1,6 +1,5 @@
1
1
  export * from './context';
2
2
  export * from './useAttachmentInput';
3
- export * from './useAsrInput';
4
3
  export * from './useIsUnmounted';
5
4
  export * from './useLongPress';
6
5
  export * from './useTranslate';
package/dist/types.d.ts CHANGED
@@ -1,7 +1,45 @@
1
- import type { ChatCardObject, ChatMessageObject, ChatTileObject } from '@ray-js/t-agent';
1
+ import type { ChatCardObject, ChatMessageObject, ChatTileObject, InputBlock } from '@ray-js/t-agent';
2
2
  import React from 'react';
3
3
  import { UIChatAgent } from './contexts';
4
4
  import { LongPressResult } from './hooks';
5
+ interface TTTActionOpenRoute {
6
+ type: 'openRoute';
7
+ url: string;
8
+ }
9
+ interface TTTActionOpenMiniApp {
10
+ type: 'openMiniApp';
11
+ appId?: string;
12
+ path?: string;
13
+ extraData?: Record<string, any>;
14
+ shortLink?: string;
15
+ position?: string;
16
+ aiPtChannel?: string;
17
+ }
18
+ interface TTTActionOpenH5 {
19
+ type: 'openH5';
20
+ url: string;
21
+ title?: string;
22
+ }
23
+ interface TTTActionSendMessage {
24
+ type: 'sendMessage';
25
+ blocks: InputBlock[];
26
+ sendImmediately?: boolean;
27
+ }
28
+ interface TTTActionSendSkill {
29
+ type: 'sendSkill';
30
+ block?: string;
31
+ options: {
32
+ domain: string;
33
+ intent: string;
34
+ [key: string]: any;
35
+ };
36
+ }
37
+ interface TTTActionBuildIn {
38
+ type: 'buildIn';
39
+ name: 'questionnaire' | 'homeLocation' | string;
40
+ data?: any;
41
+ }
42
+ export type TTTAction = TTTActionOpenRoute | TTTActionOpenMiniApp | TTTActionOpenH5 | TTTActionSendMessage | TTTActionSendSkill | TTTActionBuildIn;
5
43
  export interface TileProps<T = any, P = any> {
6
44
  side: 'start' | 'end' | string;
7
45
  message: ChatMessageObject;
@@ -39,3 +77,4 @@ export interface RenderOptions {
39
77
  getStaticResourceBizType: (src: string, scene?: string, data?: any) => string;
40
78
  i18nTranslate: (key: string) => string;
41
79
  }
80
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.2.0-beta-1",
3
+ "version": "0.2.0-beta-2",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -33,13 +33,12 @@
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@ray-js/ray": ">=1.6.8",
36
- "@ray-js/t-agent": "*",
37
- "@ray-js/t-agent-plugin-assistant": "*"
36
+ "@ray-js/t-agent": "*"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@tuya-miniapp/api-types": "^1.1.22",
41
40
  "@types/echarts": "^4.9.22",
42
41
  "@types/markdown-it": "^14.1.1"
43
42
  },
44
- "gitHead": "98229f8a9cb090a6fa0d9b47fa70b1f44ec2b34a"
43
+ "gitHead": "0784a0f440b67cc1f766a440dbad5350f633dfb1"
45
44
  }