@cpzxrobot/sdk 1.3.93 → 1.3.95

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/ai_gateway.ts CHANGED
@@ -15,5 +15,15 @@ export class AiGateway extends Object {
15
15
  return axios.post(" /api/chatai/deviceMatch", args);
16
16
  })
17
17
  }
18
+
19
+ assist(args:{
20
+ prompt: string;
21
+ output: {
22
+ type: string;
18
23
 
24
+ },
25
+ callback: (data: any) => void;
26
+ }){
27
+ this.context.platform.aiAssist(args);
28
+ }
19
29
  }
@@ -1,4 +1,4 @@
1
- import { Cpzxrobot, type Unit,type DeviceType } from "."
1
+ import { Cpzxrobot, type Unit, type DeviceType } from "."
2
2
 
3
3
  //缓存设备类型数据
4
4
  export class DeviceTypeGateway {
@@ -11,11 +11,15 @@ export class DeviceTypeGateway {
11
11
  }
12
12
 
13
13
  //需要返回.data
14
- list(): Promise<DeviceType[]> {
14
+ async list(): Promise<DeviceType[]> {
15
15
  if (this.deviceTypes) {
16
16
  return Promise.resolve(this.deviceTypes)
17
17
  }
18
- return this.context.axios.get('/api/v1/device/type')
18
+ var axios = await this.context.ready;
19
+ return axios.get('/api/v1/device/type').then((res) => {
20
+ this.deviceTypes = res.data
21
+ return res.data
22
+ })
19
23
  }
20
24
 
21
25
  alarmConfigForUnit(unit: Unit): Promise<any> {
@@ -27,5 +31,5 @@ export class DeviceTypeGateway {
27
31
  })
28
32
  });
29
33
  }
30
-
34
+
31
35
  }
@@ -11,5 +11,8 @@ class AiGateway extends Object {
11
11
  return axios.post(" /api/chatai/deviceMatch", args);
12
12
  });
13
13
  }
14
+ assist(args) {
15
+ this.context.platform.aiAssist(args);
16
+ }
14
17
  }
15
18
  exports.AiGateway = AiGateway;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.DeviceTypeGateway = void 0;
4
13
  //缓存设备类型数据
@@ -8,10 +17,16 @@ class DeviceTypeGateway {
8
17
  }
9
18
  //需要返回.data
10
19
  list() {
11
- if (this.deviceTypes) {
12
- return Promise.resolve(this.deviceTypes);
13
- }
14
- return this.context.axios.get('/api/v1/device/type');
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ if (this.deviceTypes) {
22
+ return Promise.resolve(this.deviceTypes);
23
+ }
24
+ var axios = yield this.context.ready;
25
+ return axios.get('/api/v1/device/type').then((res) => {
26
+ this.deviceTypes = res.data;
27
+ return res.data;
28
+ });
29
+ });
15
30
  }
16
31
  alarmConfigForUnit(unit) {
17
32
  return this.context.ready.then((axios) => {
@@ -185,5 +185,8 @@ class MobilePlatform {
185
185
  setProgress(precentage) {
186
186
  this.platform.callHandler("app.setProgress", precentage);
187
187
  }
188
+ aiAssist(args) {
189
+ this.platform.callHandler("app.aiAssist", args);
190
+ }
188
191
  }
189
192
  exports.MobilePlatform = MobilePlatform;
@@ -23,9 +23,14 @@ class WebPlatform {
23
23
  }
24
24
  openFactorySelector() {
25
25
  //call open function of factory-selector
26
- var factorySelector = document.getElementById("cpzxrobot-factory-selector");
27
- //@ts-ignore
28
- factorySelector.open();
26
+ var factorySelector = document.querySelector("cpzxrobot-factory-selector");
27
+ if (factorySelector) {
28
+ //@ts-ignore
29
+ factorySelector.open();
30
+ }
31
+ else {
32
+ console.warn("Factory selector element not found");
33
+ }
29
34
  }
30
35
  addMessage(_message) {
31
36
  throw new Error("Method not implemented.");
@@ -463,5 +468,8 @@ class WebPlatform {
463
468
  setProgress(_precentage) {
464
469
  // No implementation in web platform
465
470
  }
471
+ aiAssist(_args) {
472
+ // No implementation in web platform
473
+ }
466
474
  }
467
475
  exports.WebPlatform = WebPlatform;
@@ -135,5 +135,10 @@ class WindwosMiniAppPlatform {
135
135
  // @ts-ignore
136
136
  (_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.setProgress(precentage);
137
137
  }
138
+ aiAssist(args) {
139
+ var _a;
140
+ // @ts-ignore
141
+ (_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.aiAssist(args);
142
+ }
138
143
  }
139
144
  exports.WindwosMiniAppPlatform = WindwosMiniAppPlatform;
@@ -1,5 +1,5 @@
1
1
  import { PlatformInterface } from "./platform_interface";
2
- import { Factory, MyAxiosInstance, Unit } from "./types";
2
+ import { AiAssistRequest, Factory, MyAxiosInstance, Unit } from "./types";
3
3
 
4
4
  export class MobilePlatform implements PlatformInterface {
5
5
  private platform: {
@@ -187,4 +187,8 @@ export class MobilePlatform implements PlatformInterface {
187
187
  setProgress(precentage: number): void {
188
188
  this.platform.callHandler("app.setProgress", precentage);
189
189
  }
190
+
191
+ aiAssist(args: AiAssistRequest): void {
192
+ this.platform.callHandler("app.aiAssist", args);
193
+ }
190
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.93",
3
+ "version": "1.3.95",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { type Factory, type MyAxiosInstance, type Unit } from "./types";
1
+ import { type AiAssistRequest, type Factory, type MyAxiosInstance, type Unit } from "./types";
2
2
 
3
3
  export abstract class PlatformInterface {
4
4
  appCode: string;
@@ -33,4 +33,5 @@ export abstract class PlatformInterface {
33
33
  abstract setSelectedFarm(farm: Factory | String | Number): void;
34
34
  //change factory
35
35
  abstract openFactorySelector():void;
36
+ abstract aiAssist(args:AiAssistRequest):void;
36
37
  }
package/types.d.ts CHANGED
@@ -608,7 +608,7 @@ interface CreateAlarmRuleResponse {
608
608
  */
609
609
  interface AlarmRuleDetail {
610
610
  /** 规则id */
611
- ruleId: number;
611
+ id: number;
612
612
  /** 工厂id */
613
613
  factoryId: number;
614
614
  /** 规则名称 */
@@ -645,6 +645,14 @@ interface AlarmRuleListResponse {
645
645
  message: string;
646
646
  }
647
647
 
648
+ interface AiAssistRequest {
649
+ prompt: string;
650
+ output: {
651
+ type: string;
652
+ };
653
+ callback: (data: any) => void;
654
+ }
655
+
648
656
  /**
649
657
  * 报警规则详情响应接口
650
658
  */
package/web_platform.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PlatformInterface } from "./platform_interface";
2
- import { Cpzxrobot, Factory, MyAxiosInstance, Unit } from "./types";
2
+ import { AiAssistRequest, Cpzxrobot, Factory, MyAxiosInstance, Unit } from "./types";
3
3
 
4
4
  export class WebPlatform implements PlatformInterface {
5
5
  token: string = "";
@@ -20,9 +20,13 @@ export class WebPlatform implements PlatformInterface {
20
20
  }
21
21
  openFactorySelector() {
22
22
  //call open function of factory-selector
23
- var factorySelector = document.getElementById("cpzxrobot-factory-selector");
24
- //@ts-ignore
25
- factorySelector.open();
23
+ var factorySelector = document.querySelector("cpzxrobot-factory-selector");
24
+ if (factorySelector) {
25
+ //@ts-ignore
26
+ factorySelector.open();
27
+ } else {
28
+ console.warn("Factory selector element not found");
29
+ }
26
30
  }
27
31
  addMessage(_message: any): void {
28
32
  throw new Error("Method not implemented.");
@@ -480,4 +484,8 @@ export class WebPlatform implements PlatformInterface {
480
484
  setProgress(_precentage: number): void {
481
485
  // No implementation in web platform
482
486
  }
487
+
488
+ aiAssist(_args: AiAssistRequest): void {
489
+ // No implementation in web platform
490
+ }
483
491
  }
@@ -1,5 +1,5 @@
1
1
  import { PlatformInterface } from "./platform_interface";
2
- import { Factory, MyAxiosInstance, Unit } from "./types";
2
+ import { AiAssistRequest, Factory, MyAxiosInstance, Unit } from "./types";
3
3
 
4
4
  export class WindwosMiniAppPlatform implements PlatformInterface {
5
5
  // private messagePort?: MessagePort;
@@ -128,4 +128,9 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
128
128
  // @ts-ignore
129
129
  window.miniapp?.setProgress(precentage);
130
130
  }
131
+
132
+ aiAssist(args: AiAssistRequest): void {
133
+ // @ts-ignore
134
+ window.miniapp?.aiAssist(args);
135
+ }
131
136
  }