doomiaichat 7.1.17 → 7.1.19

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,5 +1,5 @@
1
1
  export declare class CorzAuthorization {
2
- private appid;
2
+ appid: string;
3
3
  private accessToken;
4
4
  private expiresAt;
5
5
  private pemfile;
package/dist/corzbot.d.ts CHANGED
@@ -28,7 +28,7 @@ export default class CorzBot extends GptBase {
28
28
  * @param params
29
29
  * @returns
30
30
  */
31
- setVariables(params: any): Promise<ApiResult>;
31
+ setVariables(params?: any): Promise<ApiResult>;
32
32
  /**
33
33
  * 获取设置的变量
34
34
  * @returns
package/dist/corzbot.js CHANGED
@@ -99,11 +99,17 @@ class CorzBot extends gptbase_1.default {
99
99
  * @param params
100
100
  * @returns
101
101
  */
102
- setVariables(params) {
102
+ setVariables(params = {}) {
103
103
  return __awaiter(this, void 0, void 0, function* () {
104
104
  const client = yield this.createClient();
105
- const cozeParams = Object.assign({}, this.botid ? { bot_id: this.botid } : {}, params);
106
- client.variables.update(cozeParams);
105
+ !params.type && (params.type = 'app');
106
+ const cozeParams = { data: params.data };
107
+ params.type === 'app' && (cozeParams.app_id = this.authorizationProvider.appid);
108
+ params.type === 'bot' && this.botid && (cozeParams.bot_id = this.botid);
109
+ params.user_id && (cozeParams.connector_uid = params.user_id);
110
+ //Object.assign({ connector_uid: params?.user_id||'123456' }, params.type==='app'?{app_id:this.authorizationProvider.appid}:(params.type==='bot' ? { bot_id: this.botid } : {}), params);
111
+ const result = yield client.variables.update(cozeParams, { debug: true });
112
+ console.log('setVariables result', result);
107
113
  return { successed: true };
108
114
  });
109
115
  }
@@ -207,9 +213,15 @@ class CorzBot extends gptbase_1.default {
207
213
  ////否则用智能体的对话来输出结果
208
214
  const params = yield this.getRequestStream(client, message, callChatOption);
209
215
  const response = this.botid ? yield client.chat.create(params) : yield client.workflows.runs.create(params);
210
- if (this.workflowid && response.msg === 'Success') {
211
- const resp = response.data;
212
- return { successed: true, message: [{ role: 'assistant', type: 'answer', content: resp }] };
216
+ if (this.workflowid) {
217
+ const workflowResp = response;
218
+ if (workflowResp.msg === 'Success') {
219
+ const resp = workflowResp.data;
220
+ return { successed: true, message: [{ role: 'assistant', type: 'answer', content: resp }] };
221
+ }
222
+ else {
223
+ console.error('workflow run failed', workflowResp.msg, workflowResp);
224
+ }
213
225
  // try {
214
226
  // return { successed: true, message: [{ role: 'assistant', type: 'answer', content: JSON.parse(resp).data }] };
215
227
  // } catch (error) {
@@ -315,7 +327,7 @@ class CorzBot extends gptbase_1.default {
315
327
  const stream = this.botid ? client.chat.stream(params) :
316
328
  (this.workflowid ? client.workflows.runs.stream(params) :
317
329
  client.workflows.chat.stream(params));
318
- let deltaindex = 0, fullanswer = [], followup = [], cardData = [];
330
+ let deltaindex = 0, fullanswer = [], cardfollowup = [], followup = [], cardData = [];
319
331
  let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = '', preresponseText = ''; // 是否在深度思考中
320
332
  try {
321
333
  for (var _g = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a;) {
@@ -353,8 +365,12 @@ class CorzBot extends gptbase_1.default {
353
365
  const allCards = cardResource.replace(/[\x00-\x1F\x7F]/g, '').split('|');
354
366
  for (const item of allCards) {
355
367
  const cardinfo = (0, querystring_1.parse)(item);
356
- if (cardinfo.type && cardinfo.tag)
357
- cardData.push(Object.assign({}, cardinfo));
368
+ if (cardinfo.type && cardinfo.tag) {
369
+ if (cardinfo.type === 'follow_up')
370
+ cardfollowup.push(cardinfo.tag);
371
+ else
372
+ cardData.push(Object.assign({}, cardinfo));
373
+ }
358
374
  }
359
375
  // 将卡片资源返回给客户端
360
376
  this.emit('chatcard', cardData);
@@ -396,7 +412,7 @@ class CorzBot extends gptbase_1.default {
396
412
  if (part.event === api_1.ChatEventType.CONVERSATION_CHAT_COMPLETED ||
397
413
  part.event === api_1.WorkflowEventType.DONE) {
398
414
  const { conversation_id, content } = (_f = (part.data)) !== null && _f !== void 0 ? _f : {};
399
- let output = { successed: true, cards: cardData.length ? cardData : null, followup, type: 'answer', content_type: 'text', role: api_1.RoleType.Assistant, requestid, segment: null, text: content !== null && content !== void 0 ? content : fullanswer.join(''), index: index++, session_id: conversation_id };
415
+ let output = { successed: true, cards: cardData.length ? cardData : null, cardfollowup: cardfollowup.filter(x => typeof x === 'string' && x.length > 0), followup, type: 'answer', content_type: 'text', role: api_1.RoleType.Assistant, requestid, segment: null, text: content !== null && content !== void 0 ? content : fullanswer.join(''), index: index++, session_id: conversation_id };
400
416
  if (attach)
401
417
  output = Object.assign({}, output, attach);
402
418
  this.emit('chatdone', output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "7.1.17",
3
+ "version": "7.1.19",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -7,7 +7,7 @@ export class CorzAuthorization {
7
7
  private pemfile: string;
8
8
  private secret: string;
9
9
  private sessionName: string;
10
- constructor(private appid: string,setting:Record<string,any>) {
10
+ constructor(public appid: string,setting:Record<string,any>) {
11
11
  this.secret = setting["keyid"];
12
12
  this.pemfile = setting["pemfile"] || "private.pem"
13
13
  this.sessionName = setting["sessionName"] || "default";
package/src/corzbot.ts CHANGED
@@ -94,10 +94,16 @@ export default class CorzBot extends GptBase {
94
94
  * @param params
95
95
  * @returns
96
96
  */
97
- override async setVariables(params: any): Promise<ApiResult> {
97
+ override async setVariables(params: any = {}): Promise<ApiResult> {
98
98
  const client = await this.createClient();
99
- const cozeParams: VariableUpdateReq = Object.assign({}, this.botid ? { bot_id: this.botid } : {}, params);
100
- client.variables.update(cozeParams)
99
+ !params.type && (params.type='app');
100
+ const cozeParams: VariableUpdateReq = { data: params.data };
101
+ params.type === 'app' && (cozeParams.app_id = this.authorizationProvider.appid);
102
+ params.type === 'bot' && this.botid && (cozeParams.bot_id = this.botid);
103
+ params.user_id && (cozeParams.connector_uid = params.user_id);
104
+ //Object.assign({ connector_uid: params?.user_id||'123456' }, params.type==='app'?{app_id:this.authorizationProvider.appid}:(params.type==='bot' ? { bot_id: this.botid } : {}), params);
105
+ const result = await client.variables.update(cozeParams, { debug : true })
106
+ console.log('setVariables result', result);
101
107
  return { successed: true };
102
108
  }
103
109
  /**
@@ -189,9 +195,14 @@ export default class CorzBot extends GptBase {
189
195
  ////否则用智能体的对话来输出结果
190
196
  const params = await this.getRequestStream(client, message, callChatOption);
191
197
  const response = this.botid ? await client.chat.create(params as CreateChatReq) : await client.workflows.runs.create(params as RunWorkflowReq);
192
- if (this.workflowid && (response as RunWorkflowData).msg === 'Success') {
193
- const resp = (response as RunWorkflowData).data;
194
- return { successed: true, message: [{ role: 'assistant', type: 'answer', content: resp }] };
198
+ if (this.workflowid) {
199
+ const workflowResp = response as RunWorkflowData;
200
+ if (workflowResp.msg === 'Success'){
201
+ const resp = workflowResp.data;
202
+ return { successed: true, message: [{ role: 'assistant', type: 'answer', content: resp }] };
203
+ }else{
204
+ console.error('workflow run failed', workflowResp.msg, workflowResp)
205
+ }
195
206
  // try {
196
207
  // return { successed: true, message: [{ role: 'assistant', type: 'answer', content: JSON.parse(resp).data }] };
197
208
  // } catch (error) {
@@ -290,7 +301,7 @@ export default class CorzBot extends GptBase {
290
301
  const stream = this.botid ? client.chat.stream(params as StreamChatReq) :
291
302
  (this.workflowid ? client.workflows.runs.stream(params as RunWorkflowReq) :
292
303
  client.workflows.chat.stream(params as ChatWorkflowReq));
293
- let deltaindex = 0, fullanswer: string[] = [], followup: string[] = [], cardData: CardType[] = [];
304
+ let deltaindex = 0, fullanswer: string[] = [],cardfollowup: string[] = [], followup: string[] = [], cardData: CardType[] = [];
294
305
  let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = '', preresponseText=''; // 是否在深度思考中
295
306
  for await (const part of stream) {
296
307
  if (part.event === ChatEventType.ERROR) return this.emit('chaterror', { successed: false, error: 'call failed' });
@@ -322,7 +333,12 @@ export default class CorzBot extends GptBase {
322
333
  const allCards = cardResource.replace(/[\x00-\x1F\x7F]/g, '').split('|')
323
334
  for (const item of allCards) {
324
335
  const cardinfo: any = parse(item);
325
- if (cardinfo.type && cardinfo.tag) cardData.push({ ...cardinfo })
336
+ if (cardinfo.type && cardinfo.tag) {
337
+ if (cardinfo.type === 'follow_up')
338
+ cardfollowup.push(cardinfo.tag);
339
+ else
340
+ cardData.push({ ...cardinfo })
341
+ }
326
342
  }
327
343
  // 将卡片资源返回给客户端
328
344
  this.emit('chatcard', cardData);
@@ -360,7 +376,7 @@ export default class CorzBot extends GptBase {
360
376
  part.event === WorkflowEventType.DONE
361
377
  ) {
362
378
  const { conversation_id, content } = (part.data) ?? {} as any;
363
- let output = { successed: true, cards: cardData.length ? cardData : null, followup, type: 'answer', content_type: 'text', role: RoleType.Assistant, requestid, segment: null, text: content ?? fullanswer.join(''), index: index++, session_id: conversation_id };
379
+ let output = { successed: true, cards: cardData.length ? cardData : null, cardfollowup: cardfollowup.filter(x=>typeof x === 'string' && x.length > 0), followup, type: 'answer', content_type: 'text', role: RoleType.Assistant, requestid, segment: null, text: content ?? fullanswer.join(''), index: index++, session_id: conversation_id };
364
380
  if (attach) output = Object.assign({}, output, attach);
365
381
  this.emit('chatdone', output)
366
382
  }