@tusi-ai/plugins 0.0.1-beta.2 → 0.0.1-beta.4

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.
Files changed (38) hide show
  1. package/README.md +6 -2
  2. package/dist/calendar/index.cjs +41 -6
  3. package/dist/calendar/index.d.mts +5 -5
  4. package/dist/calendar/index.d.ts +5 -5
  5. package/dist/calendar/index.js +42 -7
  6. package/dist/camera/index.cjs +44 -12
  7. package/dist/camera/index.d.mts +9 -9
  8. package/dist/camera/index.d.ts +9 -9
  9. package/dist/camera/index.js +45 -13
  10. package/dist/clipboard/index.cjs +43 -8
  11. package/dist/clipboard/index.d.mts +7 -7
  12. package/dist/clipboard/index.d.ts +7 -7
  13. package/dist/clipboard/index.js +44 -9
  14. package/dist/contact-picker/index.cjs +38 -24
  15. package/dist/contact-picker/index.d.mts +5 -4
  16. package/dist/contact-picker/index.d.ts +5 -4
  17. package/dist/contact-picker/index.js +39 -25
  18. package/dist/filesystem/index.cjs +76 -36
  19. package/dist/filesystem/index.d.mts +22 -22
  20. package/dist/filesystem/index.d.ts +22 -22
  21. package/dist/filesystem/index.js +77 -37
  22. package/dist/geolocation/index.cjs +38 -4
  23. package/dist/geolocation/index.d.mts +5 -5
  24. package/dist/geolocation/index.d.ts +5 -5
  25. package/dist/geolocation/index.js +39 -5
  26. package/dist/index.d.mts +2 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/local-notifications/index.cjs +44 -13
  29. package/dist/local-notifications/index.d.mts +9 -10
  30. package/dist/local-notifications/index.d.ts +9 -10
  31. package/dist/local-notifications/index.js +45 -14
  32. package/dist/result-CbliqkNp.d.mts +13 -0
  33. package/dist/result-CbliqkNp.d.ts +13 -0
  34. package/dist/share/index.cjs +40 -7
  35. package/dist/share/index.d.mts +7 -6
  36. package/dist/share/index.d.ts +7 -6
  37. package/dist/share/index.js +41 -8
  38. package/package.json +3 -2
@@ -22,6 +22,42 @@ var __async = (__this, __arguments, generator) => {
22
22
  step((generator = generator.apply(__this, __arguments)).next());
23
23
  });
24
24
  };
25
+ function callPlugin(task) {
26
+ return Promise.resolve().then(task).then((data) => ({
27
+ code: core.ErrorCode.Success,
28
+ data: data === void 0 ? null : data,
29
+ errMsg: ""
30
+ })).catch((error) => {
31
+ const code = error instanceof core.TusiError ? error.code : core.ErrorCode.NativeFailure;
32
+ return { code, data: null, errMsg: userMessage(code) };
33
+ });
34
+ }
35
+ function userMessage(code) {
36
+ switch (code) {
37
+ case core.ErrorCode.InvalidParams:
38
+ return "\u53C2\u6570\u6709\u8BEF";
39
+ case core.ErrorCode.NotImplemented:
40
+ return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
41
+ case core.ErrorCode.PermissionDenied:
42
+ return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
43
+ case core.ErrorCode.Cancelled:
44
+ return "\u5DF2\u53D6\u6D88";
45
+ case core.ErrorCode.NotFound:
46
+ return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
47
+ case core.ErrorCode.Conflict:
48
+ return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
49
+ case core.ErrorCode.Timeout:
50
+ return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
51
+ case core.ErrorCode.Unsupported:
52
+ return core.getRuntimeEnv() === core.RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
53
+ case core.ErrorCode.SchemeFailed:
54
+ return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
55
+ case core.ErrorCode.PreviewConnectionFailed:
56
+ return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
57
+ default:
58
+ return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
59
+ }
60
+ }
25
61
  var BaseAdapter = class {
26
62
  /**
27
63
  * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
@@ -123,22 +159,19 @@ var Share = {
123
159
  /**
124
160
  * 查询能否分享。
125
161
  *
126
- * @returns `value` 表示当前环境有没有分享能力
162
+ * @returns `code` 为 0 时 `data.value` 表示当前环境有没有分享能力
127
163
  */
128
164
  canShare() {
129
- return getAdapter().canShare();
165
+ return callPlugin(() => getAdapter().canShare());
130
166
  },
131
167
  /**
132
168
  * 打开分享面板。
133
169
  *
134
170
  * @param options - 标题、正文、链接或本地文件
135
- * @returns 成功时带 `activityType`。用户取消时为空对象
136
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前环境不能分享
171
+ * @returns `code` 为 0 时 `data` 带 `activityType`。用户取消时 `data` 为空对象。失败时 `errMsg` 可直接 toast
137
172
  */
138
173
  share(options) {
139
- return __async(this, null, function* () {
140
- return getAdapter().share(options);
141
- });
174
+ return callPlugin(() => getAdapter().share(options));
142
175
  }
143
176
  };
144
177
 
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.mjs';
2
+
1
3
  /** {@link Share.canShare} 的结果。 */
2
4
  interface CanShareResult {
3
5
  /** 当前环境能否打开分享面板。 */
@@ -29,17 +31,16 @@ declare const Share: {
29
31
  /**
30
32
  * 查询能否分享。
31
33
  *
32
- * @returns `value` 表示当前环境有没有分享能力
34
+ * @returns `code` 为 0 时 `data.value` 表示当前环境有没有分享能力
33
35
  */
34
- canShare(): Promise<CanShareResult>;
36
+ canShare(): Promise<PluginResult<CanShareResult>>;
35
37
  /**
36
38
  * 打开分享面板。
37
39
  *
38
40
  * @param options - 标题、正文、链接或本地文件
39
- * @returns 成功时带 `activityType`。用户取消时为空对象
40
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前环境不能分享
41
+ * @returns `code` 为 0 时 `data` 带 `activityType`。用户取消时 `data` 为空对象。失败时 `errMsg` 可直接 toast
41
42
  */
42
- share(options?: ShareOptions): Promise<ShareResult>;
43
+ share(options?: ShareOptions): Promise<PluginResult<ShareResult>>;
43
44
  };
44
45
 
45
- export { type CanShareResult, Share, type ShareOptions, type ShareResult };
46
+ export { type CanShareResult, PluginResult, Share, type ShareOptions, type ShareResult };
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.js';
2
+
1
3
  /** {@link Share.canShare} 的结果。 */
2
4
  interface CanShareResult {
3
5
  /** 当前环境能否打开分享面板。 */
@@ -29,17 +31,16 @@ declare const Share: {
29
31
  /**
30
32
  * 查询能否分享。
31
33
  *
32
- * @returns `value` 表示当前环境有没有分享能力
34
+ * @returns `code` 为 0 时 `data.value` 表示当前环境有没有分享能力
33
35
  */
34
- canShare(): Promise<CanShareResult>;
36
+ canShare(): Promise<PluginResult<CanShareResult>>;
35
37
  /**
36
38
  * 打开分享面板。
37
39
  *
38
40
  * @param options - 标题、正文、链接或本地文件
39
- * @returns 成功时带 `activityType`。用户取消时为空对象
40
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前环境不能分享
41
+ * @returns `code` 为 0 时 `data` 带 `activityType`。用户取消时 `data` 为空对象。失败时 `errMsg` 可直接 toast
41
42
  */
42
- share(options?: ShareOptions): Promise<ShareResult>;
43
+ share(options?: ShareOptions): Promise<PluginResult<ShareResult>>;
43
44
  };
44
45
 
45
- export { type CanShareResult, Share, type ShareOptions, type ShareResult };
46
+ export { type CanShareResult, PluginResult, Share, type ShareOptions, type ShareResult };
@@ -1,4 +1,4 @@
1
- import { getRuntimeEnv, RuntimeEnv, TusiError, ErrorCode, bridge } from '@tusi-ai/core';
1
+ import { ErrorCode, TusiError, getRuntimeEnv, RuntimeEnv, bridge } from '@tusi-ai/core';
2
2
 
3
3
  var __async = (__this, __arguments, generator) => {
4
4
  return new Promise((resolve, reject) => {
@@ -20,6 +20,42 @@ var __async = (__this, __arguments, generator) => {
20
20
  step((generator = generator.apply(__this, __arguments)).next());
21
21
  });
22
22
  };
23
+ function callPlugin(task) {
24
+ return Promise.resolve().then(task).then((data) => ({
25
+ code: ErrorCode.Success,
26
+ data: data === void 0 ? null : data,
27
+ errMsg: ""
28
+ })).catch((error) => {
29
+ const code = error instanceof TusiError ? error.code : ErrorCode.NativeFailure;
30
+ return { code, data: null, errMsg: userMessage(code) };
31
+ });
32
+ }
33
+ function userMessage(code) {
34
+ switch (code) {
35
+ case ErrorCode.InvalidParams:
36
+ return "\u53C2\u6570\u6709\u8BEF";
37
+ case ErrorCode.NotImplemented:
38
+ return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
39
+ case ErrorCode.PermissionDenied:
40
+ return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
41
+ case ErrorCode.Cancelled:
42
+ return "\u5DF2\u53D6\u6D88";
43
+ case ErrorCode.NotFound:
44
+ return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
45
+ case ErrorCode.Conflict:
46
+ return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
47
+ case ErrorCode.Timeout:
48
+ return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
49
+ case ErrorCode.Unsupported:
50
+ return getRuntimeEnv() === RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
51
+ case ErrorCode.SchemeFailed:
52
+ return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
53
+ case ErrorCode.PreviewConnectionFailed:
54
+ return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
55
+ default:
56
+ return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
57
+ }
58
+ }
23
59
  var BaseAdapter = class {
24
60
  /**
25
61
  * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
@@ -121,22 +157,19 @@ var Share = {
121
157
  /**
122
158
  * 查询能否分享。
123
159
  *
124
- * @returns `value` 表示当前环境有没有分享能力
160
+ * @returns `code` 为 0 时 `data.value` 表示当前环境有没有分享能力
125
161
  */
126
162
  canShare() {
127
- return getAdapter().canShare();
163
+ return callPlugin(() => getAdapter().canShare());
128
164
  },
129
165
  /**
130
166
  * 打开分享面板。
131
167
  *
132
168
  * @param options - 标题、正文、链接或本地文件
133
- * @returns 成功时带 `activityType`。用户取消时为空对象
134
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前环境不能分享
169
+ * @returns `code` 为 0 时 `data` 带 `activityType`。用户取消时 `data` 为空对象。失败时 `errMsg` 可直接 toast
135
170
  */
136
171
  share(options) {
137
- return __async(this, null, function* () {
138
- return getAdapter().share(options);
139
- });
172
+ return callPlugin(() => getAdapter().share(options));
140
173
  }
141
174
  };
142
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tusi-ai/plugins",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "吐司端能力插件",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -102,7 +102,7 @@
102
102
  ],
103
103
  "sideEffects": false,
104
104
  "dependencies": {
105
- "@tusi-ai/core": "^0.0.1-beta.2"
105
+ "@tusi-ai/core": "^0.0.1-beta.4"
106
106
  },
107
107
  "devDependencies": {
108
108
  "@types/node": "^22.19.0",
@@ -118,6 +118,7 @@
118
118
  "playground": "vite",
119
119
  "playground:build": "vite build",
120
120
  "skills": "node scripts/copy-skills.mjs",
121
+ "skills:overwrite": "pnpm skills && node scripts/overwrite-prompt-skills.mjs",
121
122
  "skills:pack": "pnpm skills && tar -czf tusi-ai-skills.tar.gz skills",
122
123
  "test": "vitest run --root ../.. packages/plugins",
123
124
  "typecheck": "tsc --noEmit",