@open-dy/ai_coding_sdk 1.0.26-beta.0 → 1.0.27-beta.0
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/README.md +28 -0
- package/dist/openapi/content/video-data.d.ts +74 -14
- package/dist/openapi/content/video-data.js +38 -2
- package/dist/openapi/core.js +1 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,34 @@ const result = await searchVideo(
|
|
|
25
25
|
);
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
### Video pack
|
|
29
|
+
|
|
30
|
+
`getVideoPack` accepts decimal string IDs from search results or link parsing. Keep large IDs as strings: converting them with `Number(itemId)` loses precision. The SDK encodes `item_ids` as the JSON integer array required by the API and rejects unsafe numbers, invalid int64 values, and empty ID arrays before sending a request. The same int64 validation applies to `device_id`.
|
|
31
|
+
|
|
32
|
+
Results are keyed by video ID in `resp.data.data`; the author field is `author_info`. `resp.data.fail_item` contains per-video failure reasons. The response has no `list`, `author`, or `anchor` fields. Use the map's string keys as exact IDs; numeric i64 fields inside video metadata retain the standard JSON number representation.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { getVideoPack } from '@open-dy/ai_coding_sdk/openapi';
|
|
36
|
+
|
|
37
|
+
const itemId = '7633827527064177939';
|
|
38
|
+
const resp = await getVideoPack({
|
|
39
|
+
item_ids: [itemId],
|
|
40
|
+
device_id: Date.now(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const video = resp.data.data?.[itemId];
|
|
44
|
+
if (!video) {
|
|
45
|
+
throw new Error(resp.data.fail_item?.[itemId] ?? '未获取到该视频的公开信息');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const title = video.title;
|
|
49
|
+
const authorName = video.author_info?.nickname;
|
|
50
|
+
if (!title || !authorName) {
|
|
51
|
+
throw new Error('视频公开信息不完整');
|
|
52
|
+
}
|
|
53
|
+
// Only pass verified fields to subsequent generation; do not substitute placeholder titles or authors.
|
|
54
|
+
```
|
|
55
|
+
|
|
28
56
|
### Auth
|
|
29
57
|
|
|
30
58
|
```ts
|
|
@@ -1,27 +1,76 @@
|
|
|
1
1
|
import type { CallOptions, OpenAPIResponse } from '../core';
|
|
2
2
|
export interface VideoPackParams {
|
|
3
|
-
/** 作品 ID
|
|
4
|
-
item_ids:
|
|
5
|
-
/** 来源用户
|
|
3
|
+
/** 作品 ID 列表。大 ID 必须传十进制字符串,SDK 会无损编码为接口要求的 JSON i64 数组。 */
|
|
4
|
+
item_ids: ReadonlyArray<string | number>;
|
|
5
|
+
/** 来源用户 UID */
|
|
6
6
|
from_uid?: string;
|
|
7
|
-
/** 设备 ID */
|
|
7
|
+
/** 设备 ID。number 必须是安全整数,大 ID 请传十进制字符串。 */
|
|
8
8
|
device_id?: string | number;
|
|
9
9
|
}
|
|
10
10
|
export interface VideoPackItem {
|
|
11
|
-
/**
|
|
12
|
-
item_id?:
|
|
11
|
+
/** 服务端原始 i64;精确的视频 ID 请使用 VideoPackResponse.data 的字符串键。 */
|
|
12
|
+
item_id?: number;
|
|
13
13
|
/** 作品标题 */
|
|
14
14
|
title?: string;
|
|
15
|
+
/** 视频简介 */
|
|
16
|
+
desc?: string;
|
|
17
|
+
duration?: number;
|
|
18
|
+
create_time?: number;
|
|
19
|
+
/** 视频更新时间,字段拼写与接口保持一致。 */
|
|
20
|
+
modity_time?: number;
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
leader_names?: string[];
|
|
24
|
+
/** 封面信息 */
|
|
25
|
+
cover_info?: {
|
|
26
|
+
uri?: string;
|
|
27
|
+
url_list?: string[];
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
};
|
|
15
31
|
/** 作者信息 */
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
author_info?: {
|
|
33
|
+
auth_uid?: string;
|
|
34
|
+
nickname?: string;
|
|
35
|
+
avatar_info?: {
|
|
36
|
+
uri?: string;
|
|
37
|
+
url_list?: string[];
|
|
38
|
+
};
|
|
39
|
+
auth_info?: {
|
|
40
|
+
/** 字段拼写与接口保持一致。 */
|
|
41
|
+
is_verifed?: boolean;
|
|
42
|
+
auth_label?: Array<{
|
|
43
|
+
auth_type?: number;
|
|
44
|
+
auth_info?: string;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/** 当前接口提供的互动统计 */
|
|
49
|
+
statistics?: {
|
|
50
|
+
digg_count?: number;
|
|
51
|
+
};
|
|
52
|
+
/** 合集信息;其中 i64 数值沿用服务端 JSON 格式。 */
|
|
53
|
+
mix_info?: {
|
|
54
|
+
mix_id?: number;
|
|
55
|
+
name?: string;
|
|
56
|
+
mix_type?: number;
|
|
57
|
+
status?: number;
|
|
58
|
+
cover?: string;
|
|
59
|
+
ext_item_list_length?: Partial<Record<string, number>>;
|
|
60
|
+
extended_series_info?: {
|
|
61
|
+
total_episode?: number;
|
|
62
|
+
charge_strategy?: {
|
|
63
|
+
ChargeCount?: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
extra?: string;
|
|
67
|
+
};
|
|
21
68
|
}
|
|
22
69
|
export interface VideoPackResponse {
|
|
23
|
-
/**
|
|
24
|
-
|
|
70
|
+
/** 视频 ID -> 视频信息。部分视频可能未返回,请检查目标 ID 是否存在。 */
|
|
71
|
+
data?: Partial<Record<string, VideoPackItem>>;
|
|
72
|
+
/** 打包失败的视频 ID -> 失败原因。 */
|
|
73
|
+
fail_item?: Partial<Record<string, string>>;
|
|
25
74
|
}
|
|
26
75
|
/**
|
|
27
76
|
* 抖音视频合规打包(获取视频互动数据)
|
|
@@ -31,6 +80,17 @@ export interface VideoPackResponse {
|
|
|
31
80
|
* - Scope: `aweme.video.pack`
|
|
32
81
|
* - 需要用户授权: 否
|
|
33
82
|
*
|
|
34
|
-
* @remarks
|
|
83
|
+
* @remarks 按 `resp.data.data?.[itemId]` 读取视频,作者字段为 `author_info`。
|
|
84
|
+
* 目标视频不存在时请检查 `resp.data.fail_item?.[itemId]`,不要用占位信息替代真实视频。
|
|
85
|
+
* 数字形式的 ID 若已超出 JS 安全整数范围,SDK 会拒绝请求;请始终保留原始字符串 ID。
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const itemId = '7633827527064177939';
|
|
89
|
+
* const resp = await getVideoPack({ item_ids: [itemId], device_id: Date.now() });
|
|
90
|
+
* const video = resp.data.data?.[itemId];
|
|
91
|
+
* if (!video) {
|
|
92
|
+
* throw new Error(resp.data.fail_item?.[itemId] ?? '未获取到该视频的公开信息');
|
|
93
|
+
* }
|
|
94
|
+
* const authorName = video.author_info?.nickname;
|
|
35
95
|
*/
|
|
36
96
|
export declare function getVideoPack(params: VideoPackParams, options?: CallOptions): Promise<OpenAPIResponse<VideoPackResponse>>;
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVideoPack = getVideoPack;
|
|
4
4
|
const core_1 = require("../core");
|
|
5
|
+
function formatInt64(value, field) {
|
|
6
|
+
if (typeof value === 'number') {
|
|
7
|
+
if (!Number.isSafeInteger(value)) {
|
|
8
|
+
throw new TypeError(`${field} must be a safe integer; pass large IDs as decimal strings`);
|
|
9
|
+
}
|
|
10
|
+
return String(value);
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== 'string' || !/^-?\d+$/.test(value)) {
|
|
13
|
+
throw new TypeError(`${field} must be a decimal int64 string or a safe integer`);
|
|
14
|
+
}
|
|
15
|
+
const integer = BigInt(value);
|
|
16
|
+
if (integer < -9223372036854775808n || integer > 9223372036854775807n) {
|
|
17
|
+
throw new RangeError(`${field} is outside the int64 range`);
|
|
18
|
+
}
|
|
19
|
+
return integer.toString();
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* 抖音视频合规打包(获取视频互动数据)
|
|
7
23
|
*
|
|
@@ -10,13 +26,33 @@ const core_1 = require("../core");
|
|
|
10
26
|
* - Scope: `aweme.video.pack`
|
|
11
27
|
* - 需要用户授权: 否
|
|
12
28
|
*
|
|
13
|
-
* @remarks
|
|
29
|
+
* @remarks 按 `resp.data.data?.[itemId]` 读取视频,作者字段为 `author_info`。
|
|
30
|
+
* 目标视频不存在时请检查 `resp.data.fail_item?.[itemId]`,不要用占位信息替代真实视频。
|
|
31
|
+
* 数字形式的 ID 若已超出 JS 安全整数范围,SDK 会拒绝请求;请始终保留原始字符串 ID。
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const itemId = '7633827527064177939';
|
|
35
|
+
* const resp = await getVideoPack({ item_ids: [itemId], device_id: Date.now() });
|
|
36
|
+
* const video = resp.data.data?.[itemId];
|
|
37
|
+
* if (!video) {
|
|
38
|
+
* throw new Error(resp.data.fail_item?.[itemId] ?? '未获取到该视频的公开信息');
|
|
39
|
+
* }
|
|
40
|
+
* const authorName = video.author_info?.nickname;
|
|
14
41
|
*/
|
|
15
42
|
async function getVideoPack(params, options) {
|
|
43
|
+
if (!Array.isArray(params?.item_ids) || params.item_ids.length === 0) {
|
|
44
|
+
throw new TypeError('item_ids must be a non-empty array');
|
|
45
|
+
}
|
|
46
|
+
// 不能先转 Number(大 ID 会丢精度),也不能 JSON.stringify(string[])(会带引号)。
|
|
47
|
+
const itemIds = Array.from(params.item_ids, (id, index) => formatInt64(id, `item_ids[${index}]`));
|
|
16
48
|
return (0, core_1.callOpenAPI)({
|
|
17
49
|
path: '/dy_open_api/v1/video/pack/',
|
|
18
50
|
method: 'GET',
|
|
19
|
-
queryParams:
|
|
51
|
+
queryParams: {
|
|
52
|
+
item_ids: `[${itemIds.join(',')}]`,
|
|
53
|
+
from_uid: params.from_uid,
|
|
54
|
+
device_id: params.device_id === undefined ? undefined : formatInt64(params.device_id, 'device_id'),
|
|
55
|
+
},
|
|
20
56
|
domain: 'open.douyin.com',
|
|
21
57
|
}, options);
|
|
22
58
|
}
|
package/dist/openapi/core.js
CHANGED
|
@@ -94,10 +94,7 @@ function buildOpenAPIErrorMessage(errMsg, errNo, logId, subErrMsg, subErrNo) {
|
|
|
94
94
|
}
|
|
95
95
|
async function callOpenAPI(params, options) {
|
|
96
96
|
const { path, method = 'GET', queryParams, body, domain = 'open.douyin.com', requiresUserAuth, } = params;
|
|
97
|
-
const
|
|
98
|
-
const accessToken = requiresUserAuth || !isCloudEnvironment()
|
|
99
|
-
? providedAccessToken
|
|
100
|
-
: undefined;
|
|
97
|
+
const accessToken = options?.accessToken ?? options?.delegateToken;
|
|
101
98
|
const envPpeEnv = process.env.APP_ENV?.startsWith('ppe_') ? process.env.APP_ENV : undefined;
|
|
102
99
|
const ppeEnv = options?.ppeEnv || envPpeEnv;
|
|
103
100
|
const extraHeaders = options?.logid ? { 'x-tt-logid': options.logid } : {};
|