@ray-js/t-agent 0.0.6-beta-1 → 0.0.7-beta-1

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/README-zh_CN.md CHANGED
@@ -84,7 +84,7 @@ const createAgent = () => {
84
84
  hello.bubble.setText('Hello, world!');
85
85
  result.messages.push(hello);
86
86
  // 持久化消息,下次进入时会展示
87
- await hello.persist('createText');
87
+ await hello.persist();
88
88
  });
89
89
 
90
90
  // 恢复聊天时,发送一条消息
@@ -95,7 +95,7 @@ const createAgent = () => {
95
95
 
96
96
  welcomeBack.bubble.setText('Welcome back');
97
97
  result.messages.push(welcomeBack);
98
- await welcomeBack.persist('createText');
98
+ await welcomeBack.persist();
99
99
  });
100
100
  return agent;
101
101
  };
package/README.md CHANGED
@@ -95,7 +95,7 @@ const createAgent = () => {
95
95
 
96
96
  welcomeBack.bubble.setText('Welcome back');
97
97
  result.messages.push(welcomeBack);
98
- await welcomeBack.persist('createText');
98
+ await welcomeBack.persist();
99
99
  });
100
100
  return agent;
101
101
  };
@@ -82,18 +82,20 @@ export default class ChatAgent {
82
82
  await this.hooks.callHook('onChatStart:before', result);
83
83
  await this.hooks.callHook('onChatStart', result);
84
84
  await this.hooks.callHook('onChatStart:after', result);
85
- logger.debug('onChatStart', result);
85
+ logger.debug('%conChatStart', 'background: gray; color: white', result);
86
86
  } else {
87
87
  await this.hooks.callHook('onChatResume:before', result);
88
88
  await this.hooks.callHook('onChatResume', result);
89
89
  await this.hooks.callHook('onChatResume:after', result);
90
- logger.debug('onChatResume', result);
90
+ logger.debug('%conChatResume', 'background: gray; color: white', result);
91
91
  }
92
92
  await this.hooks.callHook('onMessageListInit:before', result);
93
93
  await this.hooks.callHook('onMessageListInit', result);
94
94
  this.session.initMessages(result.messages);
95
95
  await this.hooks.callHook('onMessageListInit:after', result);
96
+ logger.debug('%conMessageListInit', 'background: gray; color: white', result);
96
97
  await this.hooks.callHook('onAgentStart:after');
98
+ logger.debug('%conAgentStart', 'background: gray; color: white');
97
99
  });
98
100
  });
99
101
  /**
@@ -109,6 +111,7 @@ export default class ChatAgent {
109
111
  hook.removeAllHooks();
110
112
  }
111
113
  await this.hooks.callHook('onAgentDispose:after');
114
+ logger.debug('%conAgentDispose', 'background: gray; color: white');
112
115
  this.hooks.removeAllHooks();
113
116
  });
114
117
  });
@@ -119,7 +122,10 @@ export default class ChatAgent {
119
122
  * @param signal abort signal
120
123
  */
121
124
  _defineProperty(this, "pushInputBlocks", (blocks, signal) => {
122
- logger.debug('pushInputBlocks', blocks);
125
+ logger.debug('%conInputBlocksPush', 'background: gray; color: white', {
126
+ blocks,
127
+ signal
128
+ });
123
129
  return this.runWithCatchError(async () => {
124
130
  await this.hooks.callHook('onInputBlocksPush:before', blocks, signal);
125
131
  await this.hooks.callHook('onInputBlocksPush', blocks, signal);
@@ -141,15 +147,15 @@ export default class ChatAgent {
141
147
  * @param payload message payload
142
148
  */
143
149
  _defineProperty(this, "emitTileEvent", (tileId, payload) => {
144
- logger.debug('emitTileEvent', {
145
- tileId,
146
- payload
147
- });
148
150
  return this.runWithCatchError(async () => {
149
151
  const tile = this.session.getTileById(tileId);
150
152
  await this.hooks.callHook('onTileEvent:before', tile, payload);
151
153
  await this.hooks.callHook('onTileEvent', tile, payload);
152
154
  await this.hooks.callHook('onTileEvent:after', tile, payload);
155
+ logger.debug('%conTileEvent', 'background: gray; color: white', {
156
+ tileId,
157
+ payload
158
+ });
153
159
  });
154
160
  });
155
161
  /**
@@ -9,7 +9,7 @@ export default class ChatSession {
9
9
  private tileIdIndex;
10
10
  hooks: Hookable<ChatSessionHooks>;
11
11
  isNewChat: boolean;
12
- sessionId: string;
12
+ sessionId: string | null;
13
13
  readonly messages: Map<string, ChatMessage>;
14
14
  constructor(agent: ChatAgent);
15
15
  set: (key: string, value: any) => Promise<void>;
@@ -9,7 +9,7 @@ export default class ChatSession {
9
9
  _defineProperty(this, "data", new Map());
10
10
  _defineProperty(this, "tileIdIndex", new Map());
11
11
  _defineProperty(this, "isNewChat", true);
12
- _defineProperty(this, "sessionId", '');
12
+ _defineProperty(this, "sessionId", null);
13
13
  _defineProperty(this, "messages", new Map());
14
14
  _defineProperty(this, "set", async (key, value) => {
15
15
  const oldValue = this.data.get(key);
@@ -72,11 +72,14 @@ export default class Logger {
72
72
  }
73
73
  _output(level, args) {
74
74
  if (!muted && passLevel(level)) {
75
- args = [...this.prefix, ...args];
75
+ let prefix = this.prefix.join(' ');
76
+ if (typeof args[0] === 'string') {
77
+ prefix = "".concat(prefix, " ").concat(args.shift());
78
+ }
76
79
  if (typeof console[level] === 'function') {
77
- console[level](...args);
80
+ console[level](prefix, ...args);
78
81
  } else {
79
- console.log(...args);
82
+ console.log(prefix, ...args);
80
83
  }
81
84
  }
82
85
  }
@@ -54,10 +54,11 @@ export declare enum ChatCardType {
54
54
  BUILD_IN = "buildIn",
55
55
  LOW_CODE = "lowCode"
56
56
  }
57
- export interface ChatCardObject<T = any> {
57
+ export interface ChatCardObject<T = any, S = any> {
58
58
  cardCode: string;
59
59
  cardType: ChatCardType;
60
60
  cardData: T;
61
+ cardState?: S;
61
62
  }
62
63
  export interface ChatTileObject<T = any> {
63
64
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent",
3
- "version": "0.0.6-beta-1",
3
+ "version": "0.0.7-beta-1",
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": "942a1aeceb65c55ba935409d386bc09f9874e283"
29
+ "gitHead": "95aecc47d002cbf5e608c129478905c7fb458ea9"
30
30
  }