@open-dy/ai_coding_sdk 1.0.11 → 1.0.13
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 +31 -0
- package/dist/ai_platform_llm/client.d.ts +29 -0
- package/dist/ai_platform_llm/client.js +107 -0
- package/dist/ai_platform_llm/core.d.ts +21 -0
- package/dist/ai_platform_llm/core.js +193 -0
- package/dist/ai_platform_llm/index.d.ts +3 -0
- package/dist/ai_platform_llm/index.js +21 -0
- package/dist/ai_platform_llm/types.d.ts +292 -0
- package/dist/ai_platform_llm/types.js +2 -0
- package/dist/auth/access-token.d.ts +139 -0
- package/dist/auth/access-token.js +99 -0
- package/dist/auth/core.d.ts +15 -0
- package/dist/auth/core.js +76 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/openapi/account/firm.d.ts +31 -0
- package/dist/openapi/account/firm.js +23 -0
- package/dist/openapi/account/homepage-data.d.ts +85 -0
- package/dist/openapi/account/homepage-data.js +109 -0
- package/dist/openapi/account/index.d.ts +16 -8
- package/dist/openapi/account/index.js +21 -8
- package/dist/openapi/account/mobile-hash.d.ts +20 -0
- package/dist/openapi/account/mobile-hash.js +22 -0
- package/dist/openapi/account/public-info.d.ts +32 -0
- package/dist/openapi/account/public-info.js +22 -0
- package/dist/openapi/business/index.d.ts +2 -1
- package/dist/openapi/business/index.js +7 -0
- package/dist/openapi/business/task.d.ts +116 -0
- package/dist/openapi/business/task.js +71 -0
- package/dist/openapi/comment/index.d.ts +2 -0
- package/dist/openapi/comment/index.js +7 -1
- package/dist/openapi/comment/manage.d.ts +118 -0
- package/dist/openapi/comment/manage.js +88 -0
- package/dist/openapi/content/index.d.ts +2 -0
- package/dist/openapi/content/index.js +5 -1
- package/dist/openapi/content/video-data.d.ts +94 -0
- package/dist/openapi/content/video-data.js +56 -0
- package/dist/openapi/im/group.d.ts +119 -0
- package/dist/openapi/im/group.js +91 -0
- package/dist/openapi/im/index.d.ts +2 -1
- package/dist/openapi/im/index.js +8 -0
- package/dist/openapi/index.d.ts +21 -11
- package/dist/openapi/index.js +64 -23
- package/dist/openapi/live/index.d.ts +2 -1
- package/dist/openapi/live/index.js +5 -0
- package/dist/openapi/live/room.d.ts +60 -0
- package/dist/openapi/live/room.js +42 -0
- package/dist/openapi/music/collection.d.ts +42 -0
- package/dist/openapi/music/collection.js +20 -0
- package/dist/openapi/music/index.d.ts +2 -0
- package/dist/openapi/music/index.js +6 -0
- package/dist/openapi/relation/fans.d.ts +72 -0
- package/dist/openapi/relation/fans.js +71 -0
- package/dist/openapi/relation/index.d.ts +4 -1
- package/dist/openapi/relation/index.js +10 -0
- package/dist/openapi/relation/social.d.ts +56 -0
- package/dist/openapi/relation/social.js +40 -0
- package/package.json +58 -2
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
2
|
+
export interface ContentPart {
|
|
3
|
+
type: number;
|
|
4
|
+
text?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
data?: string;
|
|
7
|
+
mime_type?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ToolCall {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Message {
|
|
15
|
+
role: Role;
|
|
16
|
+
content?: string;
|
|
17
|
+
parts?: ContentPart[];
|
|
18
|
+
tool_calls?: ToolCall[];
|
|
19
|
+
tool_call_id?: string;
|
|
20
|
+
tool_name?: string;
|
|
21
|
+
reasoning?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ModelParams {
|
|
24
|
+
/**
|
|
25
|
+
* 文本模型常见建议范围为 `0-1`。
|
|
26
|
+
* 对 Doubao Seed 1.6 这类偏思考任务,通常更适合 `0-0.4`。
|
|
27
|
+
*/
|
|
28
|
+
temperature?: number;
|
|
29
|
+
/**
|
|
30
|
+
* 常见回答长度预算字段。
|
|
31
|
+
* 以 Doubao Seed 1.6 系列为例,常见预算可到 `32K`。
|
|
32
|
+
* 如果后续引入 `max_completion_tokens` 之类的思考型预算字段,不要和它同时传。
|
|
33
|
+
*/
|
|
34
|
+
max_tokens?: number;
|
|
35
|
+
top_p?: number;
|
|
36
|
+
stop?: string[];
|
|
37
|
+
frequency_penalty?: number;
|
|
38
|
+
presence_penalty?: number;
|
|
39
|
+
thinking_type?: string;
|
|
40
|
+
reasoning_effort?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 流式文本生成请求。
|
|
44
|
+
*
|
|
45
|
+
* 说明:
|
|
46
|
+
* - 当前联调文本模型示例主要是 `Doubao-Seed-1.6-back` 一类 Seed 1.6 系列。
|
|
47
|
+
* - 常见核心字段是 `messages`、`model_tenant`、`model_key`、`params`。
|
|
48
|
+
* - `messages[].role` 常见值为 `system`、`user`、`assistant`。
|
|
49
|
+
* - 旧 `messages` 结构更适合纯文本,不适合承载复杂多模态输入。
|
|
50
|
+
* - 参数限制和默认值应按 `model_key` 决定,不要把统一字段当成所有模型通用能力。
|
|
51
|
+
*/
|
|
52
|
+
export interface StreamGenerateRequest {
|
|
53
|
+
messages: Message[];
|
|
54
|
+
model_tenant: string;
|
|
55
|
+
model_key: string;
|
|
56
|
+
params?: ModelParams;
|
|
57
|
+
tools?: Array<{
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
parameters: string;
|
|
61
|
+
}>;
|
|
62
|
+
extra?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
export interface GenerateMessage {
|
|
65
|
+
Role: Role;
|
|
66
|
+
Content?: string;
|
|
67
|
+
Parts?: Array<{
|
|
68
|
+
Type: number;
|
|
69
|
+
Text?: string;
|
|
70
|
+
Url?: string;
|
|
71
|
+
Data?: string;
|
|
72
|
+
MimeType?: string;
|
|
73
|
+
}>;
|
|
74
|
+
ToolCalls?: Array<{
|
|
75
|
+
ID: string;
|
|
76
|
+
Name: string;
|
|
77
|
+
Arguments: string;
|
|
78
|
+
}>;
|
|
79
|
+
ToolCallID?: string;
|
|
80
|
+
ToolName?: string;
|
|
81
|
+
Reasoning?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface GenerateModelParams {
|
|
84
|
+
Temperature?: number;
|
|
85
|
+
MaxTokens?: number;
|
|
86
|
+
TopP?: number;
|
|
87
|
+
Stop?: string[];
|
|
88
|
+
FrequencyPenalty?: number;
|
|
89
|
+
PresencePenalty?: number;
|
|
90
|
+
ThinkingType?: string;
|
|
91
|
+
ReasoningEffort?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 非流式文本生成请求。
|
|
95
|
+
*
|
|
96
|
+
* 说明:
|
|
97
|
+
* - 当前网关字段仍保持 PascalCase,例如 `Messages`、`ModelTenant`、`ModelKey`、`Params`。
|
|
98
|
+
* - 不同 `ModelKey` 的可用参数范围不同,业务侧应按模型选择默认值和校验策略。
|
|
99
|
+
*/
|
|
100
|
+
export interface GenerateRequest {
|
|
101
|
+
Messages: GenerateMessage[];
|
|
102
|
+
ModelTenant: string;
|
|
103
|
+
ModelKey: string;
|
|
104
|
+
Params?: GenerateModelParams;
|
|
105
|
+
Tools?: Array<{
|
|
106
|
+
Name: string;
|
|
107
|
+
Description: string;
|
|
108
|
+
Parameters: string;
|
|
109
|
+
}>;
|
|
110
|
+
Extra?: Record<string, string>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 图片生成请求。
|
|
114
|
+
*
|
|
115
|
+
* 注意:
|
|
116
|
+
* - 不要假设每个图片模型都支持这里的所有字段。
|
|
117
|
+
* - 参数校验和默认值应按 `ModelKey` 决定。
|
|
118
|
+
* - 统一的请求类型只表示网关接受这些字段名,不表示每个模型都支持这些字段。
|
|
119
|
+
*
|
|
120
|
+
* 当前已知模型约束摘要:
|
|
121
|
+
* - `glm-image`
|
|
122
|
+
* - `Prompt` 和 `ReferenceImages` 至少一个非空
|
|
123
|
+
* - `Size` 优先 `1k` / `2k` / `4k`
|
|
124
|
+
* - `ImageNum` 建议先按 `1` 使用
|
|
125
|
+
* - 不要依赖 `FastMode` / `KeepRatio` 一定生效
|
|
126
|
+
* - `doubao-seedream-4-0-*`
|
|
127
|
+
* - `Prompt` 必填
|
|
128
|
+
* - 参考图最多 10 张,JPG/PNG,单图不超过 10 MB
|
|
129
|
+
* - `Size` 使用 `1K` / `2K` / `4K` 或 `widthxheight`,不要混用
|
|
130
|
+
* - `ImageNum` 不是简单平铺 `n`,多图能力要按模型侧顺序生图语义理解
|
|
131
|
+
* - `gpt-image-1`
|
|
132
|
+
* - 不要套用 Seedream 或 GLM 的限制
|
|
133
|
+
* - prompt 长度不超过 `32000`
|
|
134
|
+
* - 图片数量 `1-10`
|
|
135
|
+
* - size 常见值为 `1024x1024` / `1536x1024` / `1024x1536` / `auto`
|
|
136
|
+
*/
|
|
137
|
+
export interface GenerateImageRequest {
|
|
138
|
+
/**
|
|
139
|
+
* 图片模型通常需要该字段。
|
|
140
|
+
* `glm-image` 场景下可与 `ReferenceImages` 二选一,但二者不能同时为空。
|
|
141
|
+
*/
|
|
142
|
+
Prompt: string;
|
|
143
|
+
ModelTenant: string;
|
|
144
|
+
ModelKey: string;
|
|
145
|
+
Source: number;
|
|
146
|
+
/**
|
|
147
|
+
* 字段语义依模型而变:
|
|
148
|
+
* - `glm-image`:可选图片输入
|
|
149
|
+
* - Seedream 4.0:最多 10 张参考图
|
|
150
|
+
* - 视频模型不属于这个请求类型
|
|
151
|
+
*/
|
|
152
|
+
ReferenceImages?: string[];
|
|
153
|
+
/**
|
|
154
|
+
* 不是所有模型共用的一套枚举。
|
|
155
|
+
* 示例:
|
|
156
|
+
* - `glm-image`:`1k` / `2k` / `4k`
|
|
157
|
+
* - Seedream 4.0:`1K` / `2K` / `4K` 或 `widthxheight`
|
|
158
|
+
*/
|
|
159
|
+
Size?: string;
|
|
160
|
+
Ratio?: string;
|
|
161
|
+
/**
|
|
162
|
+
* 不要假设所有图片模型都支持多图输出。
|
|
163
|
+
* Seedream 4.0 的多图能力也不是简单的平铺 `n`。
|
|
164
|
+
*/
|
|
165
|
+
ImageNum?: number;
|
|
166
|
+
/** `false` 通常表示不加 AI 水印,但最终语义仍取决于具体模型。 */
|
|
167
|
+
Watermark?: boolean;
|
|
168
|
+
/** 不要把它当成所有模型都稳定支持的能力。 */
|
|
169
|
+
FastMode?: boolean;
|
|
170
|
+
/** 不要把它当成所有模型都稳定支持的能力。 */
|
|
171
|
+
KeepRatio?: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 视频生成请求。
|
|
175
|
+
*
|
|
176
|
+
* 注意:
|
|
177
|
+
* - `ReferenceImages` 是强场景相关字段,在不同 `ModelKey` 下可能表示首帧、尾帧或参考图。
|
|
178
|
+
* - 参数校验应按 `ModelKey` 决定,不要只按字段名做统一判断。
|
|
179
|
+
* - 统一请求类型不表示所有视频模型都支持同一组图生视频能力。
|
|
180
|
+
*
|
|
181
|
+
* 当前已知模型约束摘要:
|
|
182
|
+
* - `doubao-seedance-1-0-pro-250528`
|
|
183
|
+
* - 支持 T2V、首帧 I2V、首尾帧 I2V、参考图模式
|
|
184
|
+
* - `Prompt` 不超过 `500` 字符
|
|
185
|
+
* - `Duration` 常见范围 `2-12`
|
|
186
|
+
* - `Resolution` 常见值 `480p` / `720p` / `1080p`
|
|
187
|
+
* - 首帧、首尾帧、参考图模式不要混用
|
|
188
|
+
* - `seedance-1-0-pro-fast-*`
|
|
189
|
+
* - 仅支持 T2V 和首帧 I2V
|
|
190
|
+
* - 最多 1 张首帧图
|
|
191
|
+
* - 不支持首尾帧和通用参考图模式
|
|
192
|
+
* - `seedance-1-0-lite-t2v-*`
|
|
193
|
+
* - 仅支持 T2V,不要传图片输入
|
|
194
|
+
* - `seedance-1-0-lite-i2v-*`
|
|
195
|
+
* - 支持首帧、首尾帧、参考图模式,但图片 role 需要严格按场景校验
|
|
196
|
+
*/
|
|
197
|
+
export interface GenerateVideoRequest {
|
|
198
|
+
/** 通常必填,且往往受模型侧 prompt 长度限制。 */
|
|
199
|
+
Prompt: string;
|
|
200
|
+
ModelTenant: string;
|
|
201
|
+
ModelKey: string;
|
|
202
|
+
Source: number;
|
|
203
|
+
/**
|
|
204
|
+
* 示例:
|
|
205
|
+
* - Seedance Pro:首帧、首尾帧或参考图
|
|
206
|
+
* - Seedance Pro Fast:最多 1 张首帧图
|
|
207
|
+
* - Lite T2V:不应传图片输入
|
|
208
|
+
*/
|
|
209
|
+
ReferenceImages?: string[];
|
|
210
|
+
/** 常见值为 `480p`、`720p`、`1080p`;网关示例里也可能出现大写写法。 */
|
|
211
|
+
Resolution?: string;
|
|
212
|
+
Ratio?: string;
|
|
213
|
+
/** Seedance 系列常见约束为 `2-12` 秒整数。 */
|
|
214
|
+
Duration?: number;
|
|
215
|
+
/** Seedance 系列常见值为 `24`;部分场景建议严格校验。 */
|
|
216
|
+
FPS?: number;
|
|
217
|
+
Watermark?: boolean;
|
|
218
|
+
Style?: string;
|
|
219
|
+
}
|
|
220
|
+
export interface QueryVideoTaskRequest {
|
|
221
|
+
ModelTenant: string;
|
|
222
|
+
ModelKey: string;
|
|
223
|
+
TaskId: string;
|
|
224
|
+
}
|
|
225
|
+
export interface AIPlatformUsage {
|
|
226
|
+
prompt_tokens: number;
|
|
227
|
+
completion_tokens: number;
|
|
228
|
+
total_tokens: number;
|
|
229
|
+
reasoning_tokens?: number;
|
|
230
|
+
cached_prompt_tokens?: number;
|
|
231
|
+
}
|
|
232
|
+
export interface AIPlatformMessageEventPayload {
|
|
233
|
+
event?: Message;
|
|
234
|
+
usage?: AIPlatformUsage;
|
|
235
|
+
finish_reason?: string;
|
|
236
|
+
error?: string;
|
|
237
|
+
index?: number;
|
|
238
|
+
}
|
|
239
|
+
export interface AIPlatformEvent {
|
|
240
|
+
id?: string;
|
|
241
|
+
event: string;
|
|
242
|
+
data: string;
|
|
243
|
+
payload?: AIPlatformMessageEventPayload | null;
|
|
244
|
+
}
|
|
245
|
+
export interface AIPlatformOpenAPIResponse<T> {
|
|
246
|
+
err_no: number;
|
|
247
|
+
err_msg: string;
|
|
248
|
+
log_id?: string;
|
|
249
|
+
data: T;
|
|
250
|
+
}
|
|
251
|
+
export interface GenerateResponseData {
|
|
252
|
+
Message?: GenerateMessage;
|
|
253
|
+
Usage?: {
|
|
254
|
+
PromptTokens?: number;
|
|
255
|
+
CompletionTokens?: number;
|
|
256
|
+
TotalTokens?: number;
|
|
257
|
+
ReasoningTokens?: number;
|
|
258
|
+
CachedPromptTokens?: number;
|
|
259
|
+
};
|
|
260
|
+
FinishReason?: string;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
}
|
|
263
|
+
export interface GenerateImageResponseData {
|
|
264
|
+
ImageUrls?: string[];
|
|
265
|
+
[key: string]: unknown;
|
|
266
|
+
}
|
|
267
|
+
export interface GenerateVideoResponseData {
|
|
268
|
+
TaskId?: string;
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
}
|
|
271
|
+
export interface QueryVideoTaskResponseData {
|
|
272
|
+
Status?: string;
|
|
273
|
+
TaskId?: string;
|
|
274
|
+
ErrorMessage?: string;
|
|
275
|
+
VideoUrls?: string[];
|
|
276
|
+
LastFrameUrl?: string;
|
|
277
|
+
[key: string]: unknown;
|
|
278
|
+
}
|
|
279
|
+
export interface AIPlatformLLMClientOptions {
|
|
280
|
+
accessToken?: string;
|
|
281
|
+
timeoutMs?: number;
|
|
282
|
+
imageTimeoutMs?: number;
|
|
283
|
+
streamTimeoutMs?: number;
|
|
284
|
+
defaultHeaders?: Record<string, string>;
|
|
285
|
+
gatewayOrigin?: string;
|
|
286
|
+
}
|
|
287
|
+
export interface AIPlatformCallOptions {
|
|
288
|
+
accessToken?: string;
|
|
289
|
+
logid?: string;
|
|
290
|
+
timeoutMs?: number;
|
|
291
|
+
defaultHeaders?: Record<string, string>;
|
|
292
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { AuthCallOptions, AuthResponse } from './core';
|
|
2
|
+
export interface GetUserAccessTokenParams {
|
|
3
|
+
/** 应用唯一标识,即开放平台应用的 client_key。 */
|
|
4
|
+
client_key: string;
|
|
5
|
+
/** 应用密钥,即 client_key 对应的 client_secret。 */
|
|
6
|
+
client_secret: string;
|
|
7
|
+
/**
|
|
8
|
+
* 用户授权码。
|
|
9
|
+
* 授权码有效期 10 分钟,且只能使用一次。
|
|
10
|
+
*/
|
|
11
|
+
code: string;
|
|
12
|
+
}
|
|
13
|
+
export interface UserAccessTokenData {
|
|
14
|
+
/** 用户授权调用凭证 access_token。 */
|
|
15
|
+
access_token: string;
|
|
16
|
+
/** 人机校验信息,正常情况下通常为空字符串。 */
|
|
17
|
+
captcha?: string;
|
|
18
|
+
/** 错误详情页跳转地址,正常情况下通常为空字符串。 */
|
|
19
|
+
desc_url?: string;
|
|
20
|
+
/** 错误描述;成功时通常为空字符串。 */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** 业务错误码,0 表示成功。 */
|
|
23
|
+
error_code: number;
|
|
24
|
+
/** access_token 有效期,单位秒。文档说明默认 15 天。 */
|
|
25
|
+
expires_in: number;
|
|
26
|
+
/** 抖音开放平台侧日志 ID,可用于排查问题。 */
|
|
27
|
+
log_id?: string;
|
|
28
|
+
/** 用户在当前应用下的唯一标识 open_id。 */
|
|
29
|
+
open_id: string;
|
|
30
|
+
/** refresh_token 剩余有效期,单位秒。文档说明默认 30 天。 */
|
|
31
|
+
refresh_expires_in: number;
|
|
32
|
+
/** 用于刷新 access_token 的 refresh_token。 */
|
|
33
|
+
refresh_token: string;
|
|
34
|
+
/** 已授予权限范围,例如 user_info。 */
|
|
35
|
+
scope?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface RefreshUserAccessTokenParams {
|
|
38
|
+
/** 应用唯一标识,即开放平台应用的 client_key。 */
|
|
39
|
+
client_key: string;
|
|
40
|
+
/** 通过 /oauth/access_token/ 获取到的 refresh_token。 */
|
|
41
|
+
refresh_token: string;
|
|
42
|
+
}
|
|
43
|
+
export interface RefreshUserAccessTokenData {
|
|
44
|
+
/** 刷新后的 access_token。 */
|
|
45
|
+
access_token: string;
|
|
46
|
+
/** 错误描述;成功时通常为空字符串。 */
|
|
47
|
+
description?: string;
|
|
48
|
+
/** 业务错误码,0 表示成功。 */
|
|
49
|
+
error_code: number;
|
|
50
|
+
/** access_token 有效期,单位秒;文档示例里该字段是字符串。 */
|
|
51
|
+
expires_in: number | string;
|
|
52
|
+
/** 用户在当前应用下的唯一标识 open_id。 */
|
|
53
|
+
open_id: string;
|
|
54
|
+
/** refresh_token 剩余有效期,单位秒;文档示例里该字段是字符串。 */
|
|
55
|
+
refresh_expires_in: number | string;
|
|
56
|
+
/** 刷新后返回的 refresh_token;其有效期保持不变。 */
|
|
57
|
+
refresh_token: string;
|
|
58
|
+
/** 已授予权限范围,例如 user_info。 */
|
|
59
|
+
scope?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface RefreshUserTokenParams {
|
|
62
|
+
/** 应用唯一标识,即开放平台应用的 client_key。 */
|
|
63
|
+
client_key: string;
|
|
64
|
+
/** 通过 /oauth/access_token/ 获取到的 refresh_token。 */
|
|
65
|
+
refresh_token: string;
|
|
66
|
+
}
|
|
67
|
+
export interface RefreshUserTokenData {
|
|
68
|
+
/** 错误描述;成功时通常为空字符串。 */
|
|
69
|
+
description?: string;
|
|
70
|
+
/** 业务错误码,0 表示成功。 */
|
|
71
|
+
error_code: number;
|
|
72
|
+
/** 新 refresh_token 的有效期,单位秒;文档示例里该字段是字符串。 */
|
|
73
|
+
expires_in: number | string;
|
|
74
|
+
/** 新的 refresh_token。旧 refresh_token 会立即失效。 */
|
|
75
|
+
refresh_token: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 获取用户授权调用凭证。
|
|
79
|
+
* 对应 POST /oauth/access_token/
|
|
80
|
+
*
|
|
81
|
+
* 文档:
|
|
82
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/get-user-access-token
|
|
83
|
+
*
|
|
84
|
+
* 请求说明:
|
|
85
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
86
|
+
* - grant_type 固定为 authorization_code,由 SDK 自动填充
|
|
87
|
+
*
|
|
88
|
+
* 返回错误码:
|
|
89
|
+
* - 0: 成功
|
|
90
|
+
* - 10001: 系统异常
|
|
91
|
+
* - 10002: 参数错误,通常是参数漏传或请求格式不正确
|
|
92
|
+
* - 10003: 密钥错误,请确认 client_secret 是否正确
|
|
93
|
+
* - 10007: 授权码过期,code 只有 10 分钟有效期且只能使用一次
|
|
94
|
+
* - 10013: client_key 或 client_secret 错误
|
|
95
|
+
* - 10014: client_key 不匹配,获取授权码和换 token 使用的 client_key 不一致
|
|
96
|
+
*/
|
|
97
|
+
export declare function getUserAccessToken(params: GetUserAccessTokenParams, options?: AuthCallOptions): Promise<AuthResponse<UserAccessTokenData>>;
|
|
98
|
+
/**
|
|
99
|
+
* 刷新 access_token。
|
|
100
|
+
* 对应 POST /oauth/refresh_token/
|
|
101
|
+
*
|
|
102
|
+
* 文档:
|
|
103
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/refresh-user-access-token
|
|
104
|
+
*
|
|
105
|
+
* 请求说明:
|
|
106
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
107
|
+
* - grant_type 固定为 refresh_token,由 SDK 自动填充
|
|
108
|
+
* - access_token 默认有效期 15 天;refresh_token 默认有效期 30 天
|
|
109
|
+
* - refresh_token 过期后,需要重新引导用户授权
|
|
110
|
+
*
|
|
111
|
+
* 返回错误码:
|
|
112
|
+
* - 0: 成功
|
|
113
|
+
* - 10001: 系统错误
|
|
114
|
+
* - 10002: 参数错误
|
|
115
|
+
* - 10005: 参数缺失
|
|
116
|
+
* - 10010: refresh_token 已过期,需要用户重新授权
|
|
117
|
+
*/
|
|
118
|
+
export declare function refreshUserAccessToken(params: RefreshUserAccessTokenParams, options?: AuthCallOptions): Promise<AuthResponse<RefreshUserAccessTokenData>>;
|
|
119
|
+
/**
|
|
120
|
+
* 轮换 / 续期 refresh_token。
|
|
121
|
+
* 对应 POST /oauth/renew_refresh_token/
|
|
122
|
+
*
|
|
123
|
+
* 文档:
|
|
124
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/refresh-user-token
|
|
125
|
+
*
|
|
126
|
+
* 请求说明:
|
|
127
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
128
|
+
* - 调用成功后旧 refresh_token 失效,并返回新的 refresh_token
|
|
129
|
+
* - 新 refresh_token 有效期 30 天
|
|
130
|
+
* - 最多只能刷新 5 次;超过后需要用户重新授权
|
|
131
|
+
*
|
|
132
|
+
* 返回错误码:
|
|
133
|
+
* - 0: 成功
|
|
134
|
+
* - 10004: 权限不足,请申请 renew_refresh_token 权限
|
|
135
|
+
* - 10005: 缺少参数,请检查 client_key 和 refresh_token
|
|
136
|
+
* - 10010: refresh_token 过期,需要用户重新授权
|
|
137
|
+
* - 10020: 超过刷新次数限制,需要用户重新授权
|
|
138
|
+
*/
|
|
139
|
+
export declare function refreshUserToken(params: RefreshUserTokenParams, options?: AuthCallOptions): Promise<AuthResponse<RefreshUserTokenData>>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserAccessToken = getUserAccessToken;
|
|
4
|
+
exports.refreshUserAccessToken = refreshUserAccessToken;
|
|
5
|
+
exports.refreshUserToken = refreshUserToken;
|
|
6
|
+
const core_1 = require("./core");
|
|
7
|
+
/**
|
|
8
|
+
* 获取用户授权调用凭证。
|
|
9
|
+
* 对应 POST /oauth/access_token/
|
|
10
|
+
*
|
|
11
|
+
* 文档:
|
|
12
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/get-user-access-token
|
|
13
|
+
*
|
|
14
|
+
* 请求说明:
|
|
15
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
16
|
+
* - grant_type 固定为 authorization_code,由 SDK 自动填充
|
|
17
|
+
*
|
|
18
|
+
* 返回错误码:
|
|
19
|
+
* - 0: 成功
|
|
20
|
+
* - 10001: 系统异常
|
|
21
|
+
* - 10002: 参数错误,通常是参数漏传或请求格式不正确
|
|
22
|
+
* - 10003: 密钥错误,请确认 client_secret 是否正确
|
|
23
|
+
* - 10007: 授权码过期,code 只有 10 分钟有效期且只能使用一次
|
|
24
|
+
* - 10013: client_key 或 client_secret 错误
|
|
25
|
+
* - 10014: client_key 不匹配,获取授权码和换 token 使用的 client_key 不一致
|
|
26
|
+
*/
|
|
27
|
+
async function getUserAccessToken(params, options) {
|
|
28
|
+
return (0, core_1.callAuthAPI)({
|
|
29
|
+
path: '/oauth/access_token/',
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: {
|
|
32
|
+
client_key: params.client_key,
|
|
33
|
+
client_secret: params.client_secret,
|
|
34
|
+
code: params.code,
|
|
35
|
+
grant_type: 'authorization_code',
|
|
36
|
+
},
|
|
37
|
+
}, options);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 刷新 access_token。
|
|
41
|
+
* 对应 POST /oauth/refresh_token/
|
|
42
|
+
*
|
|
43
|
+
* 文档:
|
|
44
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/refresh-user-access-token
|
|
45
|
+
*
|
|
46
|
+
* 请求说明:
|
|
47
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
48
|
+
* - grant_type 固定为 refresh_token,由 SDK 自动填充
|
|
49
|
+
* - access_token 默认有效期 15 天;refresh_token 默认有效期 30 天
|
|
50
|
+
* - refresh_token 过期后,需要重新引导用户授权
|
|
51
|
+
*
|
|
52
|
+
* 返回错误码:
|
|
53
|
+
* - 0: 成功
|
|
54
|
+
* - 10001: 系统错误
|
|
55
|
+
* - 10002: 参数错误
|
|
56
|
+
* - 10005: 参数缺失
|
|
57
|
+
* - 10010: refresh_token 已过期,需要用户重新授权
|
|
58
|
+
*/
|
|
59
|
+
async function refreshUserAccessToken(params, options) {
|
|
60
|
+
return (0, core_1.callAuthAPI)({
|
|
61
|
+
path: '/oauth/refresh_token/',
|
|
62
|
+
method: 'POST',
|
|
63
|
+
body: {
|
|
64
|
+
client_key: params.client_key,
|
|
65
|
+
refresh_token: params.refresh_token,
|
|
66
|
+
grant_type: 'refresh_token',
|
|
67
|
+
},
|
|
68
|
+
}, options);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 轮换 / 续期 refresh_token。
|
|
72
|
+
* 对应 POST /oauth/renew_refresh_token/
|
|
73
|
+
*
|
|
74
|
+
* 文档:
|
|
75
|
+
* https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/user-authorization/refresh-user-token
|
|
76
|
+
*
|
|
77
|
+
* 请求说明:
|
|
78
|
+
* - content-type 固定为 application/x-www-form-urlencoded,由 core.ts 自动注入
|
|
79
|
+
* - 调用成功后旧 refresh_token 失效,并返回新的 refresh_token
|
|
80
|
+
* - 新 refresh_token 有效期 30 天
|
|
81
|
+
* - 最多只能刷新 5 次;超过后需要用户重新授权
|
|
82
|
+
*
|
|
83
|
+
* 返回错误码:
|
|
84
|
+
* - 0: 成功
|
|
85
|
+
* - 10004: 权限不足,请申请 renew_refresh_token 权限
|
|
86
|
+
* - 10005: 缺少参数,请检查 client_key 和 refresh_token
|
|
87
|
+
* - 10010: refresh_token 过期,需要用户重新授权
|
|
88
|
+
* - 10020: 超过刷新次数限制,需要用户重新授权
|
|
89
|
+
*/
|
|
90
|
+
async function refreshUserToken(params, options) {
|
|
91
|
+
return (0, core_1.callAuthAPI)({
|
|
92
|
+
path: '/oauth/renew_refresh_token/',
|
|
93
|
+
method: 'POST',
|
|
94
|
+
body: {
|
|
95
|
+
client_key: params.client_key,
|
|
96
|
+
refresh_token: params.refresh_token,
|
|
97
|
+
},
|
|
98
|
+
}, options);
|
|
99
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AuthCallParams {
|
|
2
|
+
path: string;
|
|
3
|
+
method?: 'POST';
|
|
4
|
+
body: URLSearchParams | Record<string, string | number | boolean | undefined>;
|
|
5
|
+
domain?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthCallOptions {
|
|
8
|
+
logid?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface AuthResponse<T> {
|
|
12
|
+
message: string;
|
|
13
|
+
data: T;
|
|
14
|
+
}
|
|
15
|
+
export declare function callAuthAPI<T>(params: AuthCallParams, options?: AuthCallOptions): Promise<AuthResponse<T>>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callAuthAPI = callAuthAPI;
|
|
4
|
+
function buildUrl(path, domain = 'open.douyin.com') {
|
|
5
|
+
return new URL(`https://${domain}${path}`).toString();
|
|
6
|
+
}
|
|
7
|
+
function toFormBody(body) {
|
|
8
|
+
if (body instanceof URLSearchParams) {
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
const params = new URLSearchParams();
|
|
12
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
13
|
+
if (value !== undefined) {
|
|
14
|
+
params.set(key, String(value));
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return params;
|
|
18
|
+
}
|
|
19
|
+
function maskBody(body) {
|
|
20
|
+
const clone = new URLSearchParams(body);
|
|
21
|
+
if (clone.has('client_secret')) {
|
|
22
|
+
clone.set('client_secret', '***');
|
|
23
|
+
}
|
|
24
|
+
return clone.toString();
|
|
25
|
+
}
|
|
26
|
+
function buildHeaders(options) {
|
|
27
|
+
const headers = {
|
|
28
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
29
|
+
};
|
|
30
|
+
if (options?.logid) {
|
|
31
|
+
headers['x-tt-logid'] = options.logid;
|
|
32
|
+
}
|
|
33
|
+
return headers;
|
|
34
|
+
}
|
|
35
|
+
async function callAuthAPI(params, options) {
|
|
36
|
+
const { path, method = 'POST', body, domain = 'open.douyin.com' } = params;
|
|
37
|
+
const requestBody = toFormBody(body);
|
|
38
|
+
const url = buildUrl(path, domain);
|
|
39
|
+
const headers = buildHeaders(options);
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const timeoutMs = options?.timeoutMs ?? 60000;
|
|
42
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
43
|
+
console.log(`[Auth] ${method} ${url}`);
|
|
44
|
+
console.log('[Auth] Headers:', headers);
|
|
45
|
+
console.log('[Auth] Body:', maskBody(requestBody));
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(url, {
|
|
48
|
+
method,
|
|
49
|
+
headers,
|
|
50
|
+
body: requestBody.toString(),
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
});
|
|
53
|
+
const rawData = await response.json();
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`HTTP Error: ${response.status} ${response.statusText}, x-tt-logid: ${response.headers.get('x-tt-logid') || 'N/A'}`);
|
|
56
|
+
}
|
|
57
|
+
if (!rawData || typeof rawData !== 'object' || !('data' in rawData) || !('message' in rawData)) {
|
|
58
|
+
throw new Error(`Invalid auth response, x-tt-logid: ${response.headers.get('x-tt-logid') || 'N/A'}`);
|
|
59
|
+
}
|
|
60
|
+
const result = rawData;
|
|
61
|
+
const resultData = result.data;
|
|
62
|
+
const errorCode = typeof resultData?.error_code === 'number' ? resultData.error_code : 0;
|
|
63
|
+
if (errorCode !== 0) {
|
|
64
|
+
throw new Error(`Auth Error: ${String(resultData?.description || result.message)} (${String(errorCode)}), x-tt-logid: ${response.headers.get('x-tt-logid') || resultData?.log_id || 'N/A'}`);
|
|
65
|
+
}
|
|
66
|
+
console.log('[Auth] Response:', JSON.stringify(result).slice(0, 500));
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('[Auth Error]', error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { callAuthAPI } from './core';
|
|
2
|
+
export type { AuthCallParams, AuthCallOptions, AuthResponse } from './core';
|
|
3
|
+
export { getUserAccessToken, refreshUserAccessToken, refreshUserToken, } from './access-token';
|
|
4
|
+
export type { GetUserAccessTokenParams, UserAccessTokenData, RefreshUserAccessTokenParams, RefreshUserAccessTokenData, RefreshUserTokenParams, RefreshUserTokenData, } from './access-token';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refreshUserToken = exports.refreshUserAccessToken = exports.getUserAccessToken = exports.callAuthAPI = void 0;
|
|
4
|
+
var core_1 = require("./core");
|
|
5
|
+
Object.defineProperty(exports, "callAuthAPI", { enumerable: true, get: function () { return core_1.callAuthAPI; } });
|
|
6
|
+
var access_token_1 = require("./access-token");
|
|
7
|
+
Object.defineProperty(exports, "getUserAccessToken", { enumerable: true, get: function () { return access_token_1.getUserAccessToken; } });
|
|
8
|
+
Object.defineProperty(exports, "refreshUserAccessToken", { enumerable: true, get: function () { return access_token_1.refreshUserAccessToken; } });
|
|
9
|
+
Object.defineProperty(exports, "refreshUserToken", { enumerable: true, get: function () { return access_token_1.refreshUserToken; } });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -33,7 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.openapi = void 0;
|
|
36
|
+
exports.ai_platform_llm = exports.auth = exports.openapi = void 0;
|
|
37
37
|
// AI Coding SDK — 聚合入口
|
|
38
38
|
// 按模块导入:import { callOpenAPI } from '@open-dy/ai_coding_sdk/openapi'
|
|
39
39
|
exports.openapi = __importStar(require("./openapi"));
|
|
40
|
+
exports.auth = __importStar(require("./auth"));
|
|
41
|
+
exports.ai_platform_llm = __importStar(require("./ai_platform_llm"));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CallOptions, OpenAPIResponse } from '../core';
|
|
2
|
+
export interface FirmSubjectDetailParams {
|
|
3
|
+
/** 目标 B 号 open_id,通过 /oauth/access_token/ 获取 */
|
|
4
|
+
open_id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FirmSubjectDetail {
|
|
7
|
+
/** 主体名称(企业/机构名称) */
|
|
8
|
+
subject_name?: string;
|
|
9
|
+
/** 主体类型 */
|
|
10
|
+
subject_type?: string;
|
|
11
|
+
/** 统一社会信用代码 */
|
|
12
|
+
credit_code?: string;
|
|
13
|
+
/** 认证状态 */
|
|
14
|
+
cert_status?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface FirmSubjectDetailResponse {
|
|
17
|
+
/** B 号主体资质详情,字段以实际接口返回为准 */
|
|
18
|
+
subject_detail?: FirmSubjectDetail;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取 B 号主体资质信息
|
|
22
|
+
*
|
|
23
|
+
* - Path: `/api/firm/v1/query_firm_subject_detail/`
|
|
24
|
+
* - Capability: `dy.open.firm_subject.detail`
|
|
25
|
+
* - Scope: `firm.subject.detail`
|
|
26
|
+
* - 需要用户授权: 是
|
|
27
|
+
*
|
|
28
|
+
* @remarks AI 分身相关接口,用于查询 B 号主体资质详细信息。
|
|
29
|
+
* 参考:【B号】支持 AI 分身 OpenAPI 开放技术方案。
|
|
30
|
+
*/
|
|
31
|
+
export declare function getFirmSubjectDetail(params: FirmSubjectDetailParams, options?: CallOptions): Promise<OpenAPIResponse<FirmSubjectDetailResponse>>;
|