doomiaichat 7.1.18 → 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) {
@@ -400,7 +412,7 @@ class CorzBot extends gptbase_1.default {
400
412
  if (part.event === api_1.ChatEventType.CONVERSATION_CHAT_COMPLETED ||
401
413
  part.event === api_1.WorkflowEventType.DONE) {
402
414
  const { conversation_id, content } = (_f = (part.data)) !== null && _f !== void 0 ? _f : {};
403
- let output = { successed: true, cards: cardData.length ? cardData : null, cardfollowup, 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 };
404
416
  if (attach)
405
417
  output = Object.assign({}, output, attach);
406
418
  this.emit('chatdone', output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "7.1.18",
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) {
@@ -365,7 +376,7 @@ export default class CorzBot extends GptBase {
365
376
  part.event === WorkflowEventType.DONE
366
377
  ) {
367
378
  const { conversation_id, content } = (part.data) ?? {} as any;
368
- let output = { successed: true, cards: cardData.length ? cardData : null, cardfollowup, 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 };
369
380
  if (attach) output = Object.assign({}, output, attach);
370
381
  this.emit('chatdone', output)
371
382
  }