@talesofai/neta-skills 0.14.0 → 0.14.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @neta/skills-neta
2
2
 
3
+ ## 0.14.2
4
+
5
+ ### Patch Changes
6
+
7
+ - usage analytics
8
+
9
+ ## 0.14.1
10
+
11
+ ### Patch Changes
12
+
13
+ - - Add api logs for debug.
14
+ - Add api timeout with 10000ms.
15
+
16
+ - Fixed error info about remove_background input_image param in docs.
17
+
3
18
  ## 0.14.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -223,6 +223,13 @@ Both the AI agent skills and the CLI require the following environment configura
223
223
  |----------|----------|---------|-------------|
224
224
  | `NETA_TOKEN` | ✅ | - | Your Neta Art API access token. |
225
225
  | `NETA_API_BASE_URL` | ❌ | default: `https://api.talesofai.com` | Base URL for the Neta API. |
226
+ | `DISABLE_TELEMETRY` | ❌ | unset | Set to `1` to disable CLI usage analytics (see below). |
227
+
228
+ ### CLI usage analytics (telemetry)
229
+
230
+ The `@talesofai/neta-skills` CLI sends lightweight usage data—such as which command ran, the options you passed, CLI version and locale, a coarse API-region hint, outcomes and timing, and your user UUID when signed in (not your API token)—so we can measure reliability and improve the experience.
231
+
232
+ To disable analytics entirely, set `DISABLE_TELEMETRY=1` in your environment; no telemetry HTTP requests are sent.
226
233
 
227
234
  ### i18n and locale detection
228
235
 
package/README.zh_cn.md CHANGED
@@ -222,6 +222,13 @@ neta-skills/
222
222
  |--------|------|--------|------|
223
223
  | `NETA_TOKEN` | ✅ | - | Neta Art API 访问令牌 |
224
224
  | `NETA_API_BASE_URL` | ❌ | default: `https://api.talesofai.com` | Neta API 网关地址 |
225
+ | `DISABLE_TELEMETRY` | ❌ | 未设置 | 设为 `1` 可关闭 CLI 使用数据统计(见下文) |
226
+
227
+ ### CLI 使用数据(埋点 / 遥测)
228
+
229
+ `@talesofai/neta-skills` CLI 会上报轻量使用数据(例如执行的命令、命令行参数、CLI 版本与语言、大致 API 区域、执行结果与耗时、登录时的用户 UUID 等;**不包含** API Token),用于衡量稳定性并改进产品体验。
230
+
231
+ 若不希望参与统计,请在环境中设置 `DISABLE_TELEMETRY=1`,此时不会发起相关上报请求。
225
232
 
226
233
  ### 多语言与本地化(i18n)
227
234
 
package/bin/apis/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import axios from "axios";
2
- import { handleAxiosError } from "../utils/errors.js";
1
+ import axios, { AxiosError } from "axios";
2
+ import { catchErrorResponse, handleAxiosError } from "../utils/errors.js";
3
3
  import { createActivityApis } from "./activity.js";
4
4
  import { createArtifactApis } from "./artifact.js";
5
5
  import { createAudioApis } from "./audio.js";
@@ -19,14 +19,31 @@ import { createUserApis } from "./user.js";
19
19
  import { createVerseApis } from "./verse.js";
20
20
  export const createApis = (option) => {
21
21
  const baseUrl = option.baseUrl;
22
+ const logger = option.logger;
22
23
  const client = axios.create({
23
24
  adapter: "fetch",
24
25
  baseURL: baseUrl,
25
26
  headers: {
26
27
  ...option.headers,
27
28
  },
29
+ timeout: 10 * 1000,
28
30
  });
29
- client.interceptors.response.use((response) => response, (error) => {
31
+ client.interceptors.request.use((config) => {
32
+ const now = Date.now();
33
+ config.start_time = now;
34
+ logger.debug("[api] request: %s %s", config.method, config.url);
35
+ return config;
36
+ });
37
+ client.interceptors.response.use((response) => {
38
+ const now = Date.now();
39
+ const startTime = response.config.start_time ?? now;
40
+ const duration = now - startTime;
41
+ logger.debug("[api] response: %s %s %s %dms", response.config.method, response.status, response.config.url, duration);
42
+ return response;
43
+ }, (error) => {
44
+ if (error instanceof AxiosError) {
45
+ logger.debug("[api] response error: %s %s %s %s", error.request?.method, error.request?.url, error.response?.status, catchErrorResponse(error.response?.data));
46
+ }
30
47
  handleAxiosError(error);
31
48
  });
32
49
  const tcp = createTcpApis(client);
@@ -16,9 +16,8 @@ export const listMyCharacters = createCommand({
16
16
  title: meta.title,
17
17
  description: meta.description,
18
18
  inputSchema: listMyCharactersParameters,
19
- }, async ({ keyword, page_index, page_size }, { apis }) => {
19
+ }, async ({ keyword, page_index, page_size }, { apis, user }) => {
20
20
  // Get current user info to obtain UUID
21
- const user = await apis.user.me();
22
21
  if (!user) {
23
22
  throw new Error("Failed to get user info. Please check your NETA_TOKEN.");
24
23
  }
@@ -16,9 +16,8 @@ export const listMyElementum = createCommand({
16
16
  title: meta.title,
17
17
  description: meta.description,
18
18
  inputSchema: listMyElementumParameters,
19
- }, async ({ keyword, page_index, page_size }, { apis }) => {
19
+ }, async ({ keyword, page_index, page_size }, { apis, user }) => {
20
20
  // Get current user info to obtain UUID
21
- const user = await apis.user.me();
22
21
  if (!user) {
23
22
  throw new Error("Failed to get user info. Please check your NETA_TOKEN.");
24
23
  }
@@ -2,6 +2,8 @@ remove_background:
2
2
  name: remove_background
3
3
  title: Remove Image Background
4
4
  description: Remove the background of an input image while preserving the main subject, and return an image with a transparent background.
5
+ parameters:
6
+ input_image: The UUID of the input image artifact.
5
7
 
6
8
  remove_background_nocrop:
7
9
  name: remove_background_nocrop
@@ -7,6 +7,9 @@ const meta = parseMeta(Type.Object({
7
7
  name: Type.String(),
8
8
  title: Type.String(),
9
9
  description: Type.String(),
10
+ parameters: Type.Object({
11
+ input_image: Type.String(),
12
+ }),
10
13
  }),
11
14
  remove_background_nocrop: Type.Object({
12
15
  name: Type.String(),
@@ -15,7 +18,9 @@ const meta = parseMeta(Type.Object({
15
18
  }),
16
19
  }), import.meta);
17
20
  const removeBackgroundV1Parameters = Type.Object({
18
- input_image: Type.String(),
21
+ input_image: Type.String({
22
+ description: meta.remove_background.parameters.input_image,
23
+ }),
19
24
  });
20
25
  export const removeBackground = createCommand({
21
26
  name: meta.remove_background.name,
@@ -24,6 +29,13 @@ export const removeBackground = createCommand({
24
29
  inputSchema: removeBackgroundV1Parameters,
25
30
  }, async ({ input_image }, { apis, log }) => {
26
31
  const createTask = async () => {
32
+ const artifacts = await apis.artifact.artifactDetail([input_image]);
33
+ if (!artifacts ||
34
+ !artifacts[0] ||
35
+ artifacts[0].modality !== "PICTURE" ||
36
+ artifacts[0].status !== "SUCCESS") {
37
+ throw new Error("Input is not a valid picture artifact UUID");
38
+ }
27
39
  return apis.artifact.postProcess(input_image, "0_null/抠图SEG", {
28
40
  entrance: "PICTURE,CLI",
29
41
  });
@@ -52,6 +64,13 @@ export const removeBackgroundNoCrop = createCommand({
52
64
  inputSchema: removeBackgroundV1Parameters,
53
65
  }, async ({ input_image }, { apis, log }) => {
54
66
  const createTask = async () => {
67
+ const artifacts = await apis.artifact.artifactDetail([input_image]);
68
+ if (!artifacts ||
69
+ !artifacts[0] ||
70
+ artifacts[0].modality !== "PICTURE" ||
71
+ artifacts[0].status !== "SUCCESS") {
72
+ throw new Error("Input is not a valid picture artifact UUID");
73
+ }
55
74
  return apis.artifact.postProcess(input_image, "0_null/抠图SEG", {
56
75
  entrance: "PICTURE,CLI",
57
76
  });
@@ -2,6 +2,8 @@ remove_background:
2
2
  name: remove_background
3
3
  title: 去除图片背景
4
4
  description: 输入图片保留主体去除背景,返回透明通道图片
5
+ parameters:
6
+ input_image: 输入图片的 artifact UUID。
5
7
 
6
8
  remove_background_nocrop:
7
9
  name: remove_background_nocrop
@@ -14,7 +14,9 @@ import { Type } from "@sinclair/typebox";
14
14
  import { AssertError, Value } from "@sinclair/typebox/value";
15
15
  import { createApis } from "../apis/index.js";
16
16
  import { ApiResponseError } from "../utils/errors.js";
17
+ import { getLocale } from "../utils/lang.js";
17
18
  import { setLocale } from "../utils/parse_meta.js";
19
+ import { formatCommandParams, track, trackConfig, trackConfigUser, } from "../utils/telemetry.js";
18
20
  import { isCommand } from "./factory.js";
19
21
  export const loadCommands = async (domains) => {
20
22
  const cmdFiles = await Promise.all(domains.map(async (domain) => {
@@ -89,7 +91,12 @@ export const buildCommands = async (cli) => {
89
91
  const baseUrl = typeof api_base_url === "string"
90
92
  ? api_base_url
91
93
  : (process.env["NETA_API_BASE_URL"] ?? "https://api.talesofai.com");
94
+ trackConfig({
95
+ app_region: baseUrl.endsWith("cn") ? "cn" : "global",
96
+ app_language: getLocale(),
97
+ });
92
98
  const apis = createApis({
99
+ logger,
93
100
  baseUrl,
94
101
  headers: {
95
102
  "x-token": process.env["NETA_TOKEN"] ?? "",
@@ -102,12 +109,19 @@ export const buildCommands = async (cli) => {
102
109
  }
103
110
  return null;
104
111
  });
112
+ const startTime = Date.now();
113
+ logger.debug("[telemetry] user: %s", user?.uuid);
114
+ trackConfigUser(user ? { user_unique_id: user.uuid } : null);
115
+ track("command_call", {
116
+ command: cmd.name,
117
+ ...formatCommandParams(args),
118
+ });
105
119
  const type = cmd.inputSchema ?? Type.Object({});
106
120
  const input = Value.Parse(type, args);
107
121
  if (IS_DEV) {
108
- logger.debug("command: %s, params: %o", cmd.name, input);
122
+ logger.debug("[command] %s, params: %o", cmd.name, input);
109
123
  }
110
- const result = await cmd
124
+ await cmd
111
125
  .execute(input, {
112
126
  apis,
113
127
  user,
@@ -119,9 +133,31 @@ export const buildCommands = async (cli) => {
119
133
  info: () => { },
120
134
  debug: () => { },
121
135
  },
136
+ })
137
+ .then((result) => {
138
+ const duration = Date.now() - startTime;
139
+ track("command_result", {
140
+ command: cmd.name,
141
+ ...formatCommandParams(args),
142
+ duration,
143
+ });
144
+ if (!result)
145
+ return;
146
+ if (IS_DEV) {
147
+ logger.debug(JSON.stringify(result, null, 2));
148
+ }
149
+ else {
150
+ logger.info(JSON.stringify(result));
151
+ }
122
152
  })
123
153
  .catch((e) => {
124
154
  if (e instanceof AssertError) {
155
+ track("command_error", {
156
+ command: cmd.name,
157
+ ...formatCommandParams(args),
158
+ error_type: e.name,
159
+ error_message: e.message,
160
+ });
125
161
  logger.error({
126
162
  error: {
127
163
  type: e.name,
@@ -133,6 +169,13 @@ export const buildCommands = async (cli) => {
133
169
  return null;
134
170
  }
135
171
  if (e instanceof ApiResponseError) {
172
+ track("command_error", {
173
+ command: cmd.name,
174
+ ...formatCommandParams(args),
175
+ error_type: e.name,
176
+ error_message: e.message,
177
+ error_code: e.code,
178
+ });
136
179
  logger.error({
137
180
  error: {
138
181
  type: e.name,
@@ -143,6 +186,12 @@ export const buildCommands = async (cli) => {
143
186
  return null;
144
187
  }
145
188
  if (e instanceof Error) {
189
+ track("command_error", {
190
+ command: cmd.name,
191
+ ...formatCommandParams(args),
192
+ error_type: e.name,
193
+ error_message: e.message,
194
+ });
146
195
  logger.error({
147
196
  error: {
148
197
  type: e.name,
@@ -151,17 +200,15 @@ export const buildCommands = async (cli) => {
151
200
  });
152
201
  return null;
153
202
  }
203
+ track("command_error", {
204
+ command: cmd.name,
205
+ ...formatCommandParams(args),
206
+ error_type: "unknown",
207
+ error_message: typeof e === "string" ? e : JSON.stringify(e),
208
+ });
154
209
  logger.error(e);
155
210
  return null;
156
211
  });
157
- if (!result)
158
- return;
159
- if (IS_DEV) {
160
- logger.debug(JSON.stringify(result, null, 2));
161
- }
162
- else {
163
- logger.info(JSON.stringify(result));
164
- }
165
212
  });
166
213
  return command;
167
214
  });
@@ -17,11 +17,13 @@ export const getCurrentPremiumPlan = createCommand({
17
17
  name: meta.name,
18
18
  title: meta.title,
19
19
  description: meta.description,
20
- }, async (_, { apis }) => {
20
+ }, async (_, { apis, user }) => {
21
21
  if (!apis.baseUrl.endsWith("talesofai.com")) {
22
22
  throw new Error("This command is not supported in the current region");
23
23
  }
24
- const user = await apis.user.me();
24
+ if (!user) {
25
+ throw new Error("Not authenticated. Please check your NETA_TOKEN.");
26
+ }
25
27
  const level = user.properties?.vip_level ?? 0;
26
28
  return {
27
29
  plan: PlanningMap[level],
@@ -0,0 +1,78 @@
1
+ import axios from "axios";
2
+ import pkg from "../../package.json" with { type: "json" };
3
+ const DISABLE_TELEMETRY = process.env["DISABLE_TELEMETRY"] === "1";
4
+ const api = axios.create({
5
+ baseURL: "https://gator.volces.com/v2/event/json",
6
+ headers: {
7
+ "content-type": "application/json",
8
+ "x-mcs-appkey": "e8cf31177d1687876753d8359bf633258f9c5c8e8b63e7b061affe59fe1f106d",
9
+ },
10
+ });
11
+ let _user = null;
12
+ let _header = {
13
+ app_name: "neta_cli",
14
+ app_package: pkg.name,
15
+ app_version: pkg.version,
16
+ };
17
+ export const trackConfigUser = (user) => {
18
+ _user = user;
19
+ };
20
+ export const trackConfig = (config) => {
21
+ _header = {
22
+ ..._header,
23
+ ...config,
24
+ };
25
+ };
26
+ const logger = console;
27
+ export const track = (event, params) => {
28
+ if (DISABLE_TELEMETRY)
29
+ return;
30
+ api
31
+ .post("/", {
32
+ user: _user,
33
+ header: {
34
+ ..._header,
35
+ },
36
+ events: [
37
+ {
38
+ event,
39
+ params,
40
+ local_time_ms: Date.now(),
41
+ },
42
+ ],
43
+ })
44
+ .then((e) => {
45
+ if (process.env["NODE_ENV"] !== "development")
46
+ return;
47
+ if (e.status === 200)
48
+ return;
49
+ logger.warn("[telemetry] track error: %s %o", e.status, e.data);
50
+ })
51
+ .catch((e) => {
52
+ if (process.env["NODE_ENV"] !== "development")
53
+ return;
54
+ logger.warn("[telemetry] track error: %o", e);
55
+ });
56
+ };
57
+ export const formatCommandParams = (params) => {
58
+ return Object.fromEntries(Object.entries(params).map(([key, value]) => {
59
+ if (typeof value === "string") {
60
+ return [`param_${key}`, value];
61
+ }
62
+ if (typeof value === "number") {
63
+ return [`param_${key}`, value];
64
+ }
65
+ if (typeof value === "boolean") {
66
+ return [`param_${key}`, value];
67
+ }
68
+ if (Array.isArray(value)) {
69
+ if (value.every((item) => typeof item === "string")) {
70
+ return [`param_${key}`, value];
71
+ }
72
+ if (value.every((item) => typeof item === "number")) {
73
+ return [`param_${key}`, value];
74
+ }
75
+ }
76
+ return [`param_${key}`, JSON.stringify(value)];
77
+ }));
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talesofai/neta-skills",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Neta API pi coding agent skills for interacting with Neta API to generate images, videos, songs, and manage characters/elements.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -52,7 +52,7 @@ Combine an audio track and video to create a full MV.
52
52
  **Remove background**
53
53
 
54
54
  ```bash
55
- npx -y @talesofai/neta-skills@latest remove_background --input_image "image_url"
55
+ npx -y @talesofai/neta-skills@latest remove_background --input_image "image_artifact_uuid"
56
56
  ```
57
57
 
58
58
  ### Character queries
@@ -124,7 +124,7 @@ npx -y @talesofai/neta-skills@latest make_image --prompt "@character_name, shy e
124
124
  ### Background Removal
125
125
 
126
126
  ```bash
127
- npx -y @talesofai/neta-skills@latest remove_background --input_image "image_uuid"
127
+ npx -y @talesofai/neta-skills@latest remove_background --input_image "image_artifact_uuid"
128
128
  ```
129
129
  ---
130
130
 
@@ -44,7 +44,7 @@ npx -y @talesofai/neta-skills@latest make_song --prompt "风格描述" --lyrics
44
44
 
45
45
  **移除背景**
46
46
  ```bash
47
- npx -y @talesofai/neta-skills@latest remove_background --input_image "image_url"
47
+ npx -y @talesofai/neta-skills@latest remove_background --input_image "image_artifact_uuid"
48
48
  ```
49
49
 
50
50
  ### 角色查询
@@ -124,7 +124,7 @@ npx -y @talesofai/neta-skills@latest make_image --prompt "@角色名,害羞表
124
124
  ### 去背景(抠图)
125
125
 
126
126
  ```bash
127
- npx -y @talesofai/neta-skills@latest remove_background --input_image "image_uuid"
127
+ npx -y @talesofai/neta-skills@latest remove_background --input_image "image_artifact_uuid"
128
128
  ```
129
129
  ---
130
130