@atomm-developer/generator-sdk 1.0.3
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 +453 -0
- package/dist/index-qYdFih-w.js +81234 -0
- package/dist/index-wW-kUlHs.js +245 -0
- package/dist/index.d.ts +672 -0
- package/dist/index.es.js +7 -0
- package/dist/index.umd.js +20 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
/** 登录状态变化回调 */
|
|
4
|
+
export declare type AuthChangeCallback = (status: AuthStatus) => void;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Auth 模块
|
|
8
|
+
* 对外暴露:getStatus / login / logout / onChange / getToken
|
|
9
|
+
*/
|
|
10
|
+
declare class AuthModule {
|
|
11
|
+
private readonly appKey;
|
|
12
|
+
private readonly passportClient;
|
|
13
|
+
private readonly http;
|
|
14
|
+
private readonly emitter;
|
|
15
|
+
private _status;
|
|
16
|
+
constructor(appKey: string, env: SdkEnv, http: AxiosInstance);
|
|
17
|
+
/**
|
|
18
|
+
* 获取当前登录状态(同步,读本地缓存)
|
|
19
|
+
*/
|
|
20
|
+
getStatus(): AuthStatus;
|
|
21
|
+
/**
|
|
22
|
+
* 获取当前 uToken
|
|
23
|
+
* 未登录时返回空字符串
|
|
24
|
+
*/
|
|
25
|
+
getToken(): string;
|
|
26
|
+
/**
|
|
27
|
+
* 弹出登录弹窗
|
|
28
|
+
* 登录成功后 resolve UserInfo,用户取消则 reject
|
|
29
|
+
*/
|
|
30
|
+
login(): Promise<UserInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* 退出登录
|
|
33
|
+
*/
|
|
34
|
+
logout(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* 监听登录状态变化,返回取消监听函数
|
|
37
|
+
*/
|
|
38
|
+
onChange(callback: AuthChangeCallback): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* 初始化时从 localStorage 恢复登录状态
|
|
41
|
+
* 如果 token 存在,尝试拉取用户信息验证有效性
|
|
42
|
+
*/
|
|
43
|
+
private _restoreFromStorage;
|
|
44
|
+
/**
|
|
45
|
+
* 通过 passport-client 获取用户信息(同时验证 token 有效性)
|
|
46
|
+
* 接口响应格式:{ code: 0, data: { uid, userName, headpic, uuid, email, ... } }
|
|
47
|
+
*/
|
|
48
|
+
private _fetchUserInfo;
|
|
49
|
+
private _setLoginStatus;
|
|
50
|
+
private _clearLoginStatus;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 登录状态 */
|
|
54
|
+
export declare interface AuthStatus {
|
|
55
|
+
isLogin: boolean;
|
|
56
|
+
userInfo: UserInfo | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 额度变化回调 */
|
|
60
|
+
export declare type BillingChangeCallback = (usage: UsageInfo) => void;
|
|
61
|
+
|
|
62
|
+
/** billing.check() 校验结果 */
|
|
63
|
+
export declare interface BillingCheckResult {
|
|
64
|
+
/** 是否可以继续操作 */
|
|
65
|
+
canProceed: boolean;
|
|
66
|
+
/** 原因:free_period=免费时段 free_count=免费次数 credits=扣积分 insufficient=积分不足 */
|
|
67
|
+
reason: 'free_period' | 'free_count' | 'credits' | 'insufficient';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** billing.consume() 参数 */
|
|
71
|
+
export declare interface BillingConsumeOptions {
|
|
72
|
+
/** 业务幂等 ID,防止重复扣费(可选) */
|
|
73
|
+
externalId?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** billing.consume() 返回值 */
|
|
77
|
+
export declare interface BillingConsumeResult {
|
|
78
|
+
/** 剩余免费次数 */
|
|
79
|
+
freeRemaining: number;
|
|
80
|
+
/** 本次是否扣了积分(false 表示扣的免费次数或处于免费时段) */
|
|
81
|
+
isCredit: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Billing 模块
|
|
86
|
+
* 对外暴露:getUsage / getCachedUsage / check / consume / refreshCredits / onChange
|
|
87
|
+
*/
|
|
88
|
+
declare class BillingModule {
|
|
89
|
+
private readonly http;
|
|
90
|
+
private readonly module;
|
|
91
|
+
private readonly credits;
|
|
92
|
+
private readonly emitter;
|
|
93
|
+
/** 缓存的免费次数信息 */
|
|
94
|
+
private _freeRemaining;
|
|
95
|
+
private _freeTotal;
|
|
96
|
+
private _creditsPerUse;
|
|
97
|
+
/** 免费时段截止时间戳 */
|
|
98
|
+
private _freePeriodEnd;
|
|
99
|
+
/** 是否已首次加载过 */
|
|
100
|
+
private _loaded;
|
|
101
|
+
constructor(appKey: string, http: AxiosInstance, credits: CreditsModule);
|
|
102
|
+
/**
|
|
103
|
+
* 获取使用额度(发起网络请求,刷新缓存)
|
|
104
|
+
* 并行拉取免费次数和积分余额
|
|
105
|
+
*/
|
|
106
|
+
getUsage(): Promise<UsageInfo>;
|
|
107
|
+
/**
|
|
108
|
+
* 获取缓存的使用额度(同步,无网络请求)
|
|
109
|
+
* 首次调用 getUsage() 前返回 null
|
|
110
|
+
*/
|
|
111
|
+
getCachedUsage(): UsageInfo | null;
|
|
112
|
+
/**
|
|
113
|
+
* 校验当前是否可执行付费操作(同步,基于缓存判断)
|
|
114
|
+
* 不弹窗、不扣费,纯校验
|
|
115
|
+
*/
|
|
116
|
+
check(): BillingCheckResult;
|
|
117
|
+
/**
|
|
118
|
+
* 消耗一次(调后端 POST /ai/v5/artimind/free_trial)
|
|
119
|
+
* 后端自动判断扣免费次数还是积分
|
|
120
|
+
*
|
|
121
|
+
* 免费时段内不发请求,直接返回成功
|
|
122
|
+
*
|
|
123
|
+
* external_id 优先使用调用方传入的值(便于业务幂等),
|
|
124
|
+
* 未传则 SDK 内部自动生成 UUID,确保每次请求都有唯一幂等键
|
|
125
|
+
*/
|
|
126
|
+
consume(options?: BillingConsumeOptions): Promise<BillingConsumeResult>;
|
|
127
|
+
/**
|
|
128
|
+
* 手动刷新积分余额
|
|
129
|
+
* consume() 中 isCredit=true 时会自动调用,一般不需手动调
|
|
130
|
+
*/
|
|
131
|
+
refreshCredits(): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* 监听额度变化(consume 成功、refreshCredits 后触发)
|
|
134
|
+
* 返回取消监听函数
|
|
135
|
+
*/
|
|
136
|
+
onChange(callback: BillingChangeCallback): () => void;
|
|
137
|
+
private _isInFreePeriod;
|
|
138
|
+
private _buildUsageInfo;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Cloud 模块
|
|
143
|
+
* 对外暴露:save / restore / delete
|
|
144
|
+
*/
|
|
145
|
+
declare class CloudModule {
|
|
146
|
+
private readonly appKey;
|
|
147
|
+
private readonly env;
|
|
148
|
+
private readonly http;
|
|
149
|
+
private uploader;
|
|
150
|
+
constructor(appKey: string, env: SdkEnv, http: AxiosInstance);
|
|
151
|
+
/**
|
|
152
|
+
* 保存当前状态到云端(自动判断新建或更新)
|
|
153
|
+
*
|
|
154
|
+
* 封面和原图由 SDK 客户端上传 OSS,后端只接收 URL,
|
|
155
|
+
* 与 Header.vue saveGeneratorData() 处理逻辑保持一致
|
|
156
|
+
*/
|
|
157
|
+
save(options: CloudSaveOptions): Promise<CloudSaveResult>;
|
|
158
|
+
/**
|
|
159
|
+
* 恢复云端数据(根据 id 获取完整记录含 snapshot)
|
|
160
|
+
*
|
|
161
|
+
* 对应现有接口:GET /ai/v5/artimind/generator/:id
|
|
162
|
+
*/
|
|
163
|
+
restore(id: number): Promise<CloudRecord>;
|
|
164
|
+
/**
|
|
165
|
+
* 删除云端记录
|
|
166
|
+
*
|
|
167
|
+
* 对应现有接口:DELETE /ai/v5/artimind/generator/:id
|
|
168
|
+
*/
|
|
169
|
+
delete(id: number): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* 将后端原始结构转换为 SDK 公开的 CloudRecord 结构
|
|
172
|
+
* info 字段中 originImageUrl 提取到顶层,snapshot 为其余字段
|
|
173
|
+
*/
|
|
174
|
+
private _normalizeRecord;
|
|
175
|
+
/** 获取或懒初始化 Uploader 实例 */
|
|
176
|
+
private getUploader;
|
|
177
|
+
/**
|
|
178
|
+
* 将 HTMLCanvasElement 导出为 PNG 并上传到 OSS
|
|
179
|
+
* @param canvas 画布元素
|
|
180
|
+
* @param name OSS 文件名(不含扩展名),同一记录复用文件名实现覆盖更新
|
|
181
|
+
*/
|
|
182
|
+
private _uploadCanvas;
|
|
183
|
+
/**
|
|
184
|
+
* 上传原图到 OSS
|
|
185
|
+
* 支持三种输入:HTMLCanvasElement / data URL / HTTP URL
|
|
186
|
+
* HTTP URL(已在 OSS 上)时直接返回,避免重复上传
|
|
187
|
+
*/
|
|
188
|
+
private _uploadOriginImage;
|
|
189
|
+
/** 上传 File 到 OSS,返回 OSS URL */
|
|
190
|
+
private _uploadFile;
|
|
191
|
+
/** data URL → File 对象 */
|
|
192
|
+
private _dataUrlToFile;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** 云端记录详情 */
|
|
196
|
+
export declare interface CloudRecord {
|
|
197
|
+
id: number;
|
|
198
|
+
title: string;
|
|
199
|
+
cover: string;
|
|
200
|
+
snapshot: Record<string, unknown>;
|
|
201
|
+
/** 原始素材图片的 OSS URL,可直接用于 img.src */
|
|
202
|
+
originImageUrl: string;
|
|
203
|
+
createdAt: number;
|
|
204
|
+
updatedAt: number;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** cloud.save() 参数 */
|
|
208
|
+
export declare interface CloudSaveOptions {
|
|
209
|
+
/** 记录标题,默认 'Draft' */
|
|
210
|
+
title?: string;
|
|
211
|
+
/**
|
|
212
|
+
* 应用状态快照
|
|
213
|
+
* 必须是可 JSON 序列化的纯对象(不含函数、DOM、循环引用)
|
|
214
|
+
*/
|
|
215
|
+
snapshot: Record<string, unknown>;
|
|
216
|
+
/**
|
|
217
|
+
* 封面画布元素
|
|
218
|
+
* SDK 内部自动调用 toDataURL 并上传 OSS,后端只存 URL
|
|
219
|
+
*/
|
|
220
|
+
cover?: HTMLCanvasElement | null;
|
|
221
|
+
/**
|
|
222
|
+
* 原始素材图片
|
|
223
|
+
* 可传 HTMLCanvasElement(自动导出)、data URL 或 HTTP URL
|
|
224
|
+
*/
|
|
225
|
+
originImage?: HTMLCanvasElement | string | null;
|
|
226
|
+
/**
|
|
227
|
+
* 记录 ID
|
|
228
|
+
* 传入时执行更新,不传时新建记录
|
|
229
|
+
*/
|
|
230
|
+
id?: number | null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** cloud.save() 返回值 */
|
|
234
|
+
export declare interface CloudSaveResult {
|
|
235
|
+
/** 记录 ID */
|
|
236
|
+
id: number;
|
|
237
|
+
/** 是否是新建(false 表示更新) */
|
|
238
|
+
isNew: boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** 积分变化回调 */
|
|
242
|
+
export declare type CreditsChangeCallback = (balance: number) => void;
|
|
243
|
+
|
|
244
|
+
/** credits.consume() 参数 */
|
|
245
|
+
export declare interface CreditsConsumeOptions {
|
|
246
|
+
/** 扣除积分数量 */
|
|
247
|
+
amount: number;
|
|
248
|
+
/**
|
|
249
|
+
* 业务标识
|
|
250
|
+
* 需在开发者控制台预先申请,后端据此校验权限
|
|
251
|
+
*/
|
|
252
|
+
action: string;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** credits.consume() 返回值 */
|
|
256
|
+
export declare interface CreditsConsumeResult {
|
|
257
|
+
success: boolean;
|
|
258
|
+
/** 扣除后剩余积分 */
|
|
259
|
+
balance: number;
|
|
260
|
+
/** 流水号 */
|
|
261
|
+
transactionId: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Credits 模块
|
|
266
|
+
* 对外暴露:getBalance / consume / onChange
|
|
267
|
+
*/
|
|
268
|
+
declare class CreditsModule {
|
|
269
|
+
private readonly http;
|
|
270
|
+
private readonly emitter;
|
|
271
|
+
private _balance;
|
|
272
|
+
constructor(http: AxiosInstance);
|
|
273
|
+
/**
|
|
274
|
+
* 获取当前用户积分余额
|
|
275
|
+
*
|
|
276
|
+
* 对应现有接口:GET /ai/v1/credit/getBalance
|
|
277
|
+
* 返回格式:{ code: 0, data: { quota: number }, message: string }
|
|
278
|
+
*/
|
|
279
|
+
getBalance(): Promise<{
|
|
280
|
+
quota: number;
|
|
281
|
+
}>;
|
|
282
|
+
/**
|
|
283
|
+
* 扣除积分
|
|
284
|
+
* 用于 AI 生成等消耗性操作,action 需提前在开发者控制台申请
|
|
285
|
+
*
|
|
286
|
+
* 注意:此接口需后端配合新增,现有项目中暂无积分扣除 API
|
|
287
|
+
* 临时方案:调用 /sdk/v1/credits/consume(后端按需新增)
|
|
288
|
+
*/
|
|
289
|
+
consume(options: CreditsConsumeOptions): Promise<CreditsConsumeResult>;
|
|
290
|
+
/**
|
|
291
|
+
* 监听积分变化(getBalance/consume 成功后自动触发)
|
|
292
|
+
* 返回取消监听函数
|
|
293
|
+
*/
|
|
294
|
+
onChange(callback: CreditsChangeCallback): () => void;
|
|
295
|
+
/**
|
|
296
|
+
* 获取本地缓存的积分余额(同步,最后一次 getBalance/consume 的结果)
|
|
297
|
+
*/
|
|
298
|
+
getCachedBalance(): number;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** export.download() 参数 */
|
|
302
|
+
export declare interface ExportDownloadOptions {
|
|
303
|
+
/** 文件名(可选,默认 'export-{timestamp}.png') */
|
|
304
|
+
fileName?: string;
|
|
305
|
+
/** 导出格式(可选,默认 'png') */
|
|
306
|
+
format?: 'png' | 'svg';
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** export.download() 返回值 */
|
|
310
|
+
export declare interface ExportDownloadResult {
|
|
311
|
+
success: boolean;
|
|
312
|
+
fileName: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Export 模块
|
|
317
|
+
* 对外暴露:register / download / openInStudio
|
|
318
|
+
*/
|
|
319
|
+
declare class ExportModule {
|
|
320
|
+
private readonly appKey;
|
|
321
|
+
private readonly env;
|
|
322
|
+
private readonly http;
|
|
323
|
+
private provider;
|
|
324
|
+
private uploader;
|
|
325
|
+
constructor(appKey: string, env: SdkEnv, http: AxiosInstance);
|
|
326
|
+
/**
|
|
327
|
+
* 注册导出能力提供者
|
|
328
|
+
* 开发者实现 ExportProvider 接口,在初始化时调用一次
|
|
329
|
+
*/
|
|
330
|
+
register(provider: ExportProvider): void;
|
|
331
|
+
/**
|
|
332
|
+
* 下载图片到本地
|
|
333
|
+
* 内部流程:getExportCanvas('download') → toBlob → 触发浏览器下载
|
|
334
|
+
*/
|
|
335
|
+
download(options?: ExportDownloadOptions): Promise<ExportDownloadResult>;
|
|
336
|
+
/**
|
|
337
|
+
* 打开到 xTool Studio
|
|
338
|
+
* 内部流程:
|
|
339
|
+
* - 传入图片 URL:直接拉起 Studio
|
|
340
|
+
* - 传入图片数据:上传 OSS → 调用 xtool:// 协议
|
|
341
|
+
* - 未传参数:getExportCanvas('studio') → toDataURL → 上传 OSS → 调用 xtool:// 协议
|
|
342
|
+
*/
|
|
343
|
+
openInStudio(source?: ExportOpenInStudioSource): Promise<ExportOpenInStudioResult>;
|
|
344
|
+
/**
|
|
345
|
+
* 获取导出 Canvas 并校验
|
|
346
|
+
*/
|
|
347
|
+
private _getCanvas;
|
|
348
|
+
/**
|
|
349
|
+
* 解析 openInStudio 的输入来源:
|
|
350
|
+
* - URL 直传给 Studio
|
|
351
|
+
* - data URL / Blob / File 先上传 OSS
|
|
352
|
+
* - 未传时回退到 provider canvas
|
|
353
|
+
*/
|
|
354
|
+
private _resolveStudioAsset;
|
|
355
|
+
/** 获取或懒初始化 Uploader 实例 */
|
|
356
|
+
private _getUploader;
|
|
357
|
+
/** 上传 File 到 OSS,返回 OSS URL */
|
|
358
|
+
private _uploadFile;
|
|
359
|
+
/** 通过 xtool:// 协议打开 Studio */
|
|
360
|
+
private _openStudioProtocol;
|
|
361
|
+
/** data URL → File 对象 */
|
|
362
|
+
private _dataUrlToFile;
|
|
363
|
+
/** Blob → File 对象 */
|
|
364
|
+
private _blobToFile;
|
|
365
|
+
/** 判断是否为 data URL */
|
|
366
|
+
private _isDataUrl;
|
|
367
|
+
/** 判断是否为可直接交给 Studio 的远程 URL */
|
|
368
|
+
private _isHttpUrl;
|
|
369
|
+
/** MIME 类型 → 文件扩展名 */
|
|
370
|
+
private _mimeTypeToExtension;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** export.openInStudio() 返回值 */
|
|
374
|
+
export declare interface ExportOpenInStudioResult {
|
|
375
|
+
success: boolean;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** export.openInStudio() 输入源 */
|
|
379
|
+
export declare type ExportOpenInStudioSource = string | Blob | File;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* 导出能力提供者
|
|
383
|
+
* 开发者实现此接口并通过 sdk.export.register() 注册
|
|
384
|
+
*/
|
|
385
|
+
export declare interface ExportProvider {
|
|
386
|
+
/**
|
|
387
|
+
* 获取导出用的 Canvas
|
|
388
|
+
* @param purpose 用途:download=下载 studio=打开到Studio cover=封面
|
|
389
|
+
*/
|
|
390
|
+
getExportCanvas: (purpose: ExportPurpose) => HTMLCanvasElement | Promise<HTMLCanvasElement | null> | null;
|
|
391
|
+
/** 自定义文件名生成器(可选) */
|
|
392
|
+
getFileName?: (purpose: ExportPurpose) => string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** 导出画布用途 */
|
|
396
|
+
export declare type ExportPurpose = 'download' | 'studio' | 'cover';
|
|
397
|
+
|
|
398
|
+
export declare class GeneratorSDK {
|
|
399
|
+
/** 登录/退出/用户信息 */
|
|
400
|
+
readonly auth: AuthModule;
|
|
401
|
+
/** 云保存/恢复/删除 */
|
|
402
|
+
readonly cloud: CloudModule;
|
|
403
|
+
/** 历史记录列表/详情/删除 */
|
|
404
|
+
readonly history: HistoryModule;
|
|
405
|
+
/** 积分余额/扣除(底层能力) */
|
|
406
|
+
readonly credits: CreditsModule;
|
|
407
|
+
/** 统一计费(免费次数 + 积分,推荐使用) */
|
|
408
|
+
readonly billing: BillingModule;
|
|
409
|
+
/** 导出(下载 + 打开到 Studio) */
|
|
410
|
+
readonly export: ExportModule;
|
|
411
|
+
/** 模板协议与导入导出 */
|
|
412
|
+
readonly template: TemplateModule;
|
|
413
|
+
private readonly appKey;
|
|
414
|
+
private readonly env;
|
|
415
|
+
private constructor();
|
|
416
|
+
/**
|
|
417
|
+
* 初始化 SDK,返回 SDK 实例
|
|
418
|
+
*
|
|
419
|
+
* 同一 appKey 多次调用返回同一实例,不会重复初始化
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```js
|
|
423
|
+
* const sdk = GeneratorSDK.init({ appKey: 'app_xxx' })
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
static init(options: SdkInitOptions): GeneratorSDK;
|
|
427
|
+
/**
|
|
428
|
+
* 清除实例缓存(测试场景使用)
|
|
429
|
+
*/
|
|
430
|
+
static _clearCache(): void;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** 标准模板定义协议 */
|
|
434
|
+
export declare interface GeneratorTemplateDefinition {
|
|
435
|
+
type: 'generator-template';
|
|
436
|
+
version: '1.0.0';
|
|
437
|
+
generatorId: string;
|
|
438
|
+
appKey?: string;
|
|
439
|
+
templateMeta?: Record<string, unknown>;
|
|
440
|
+
defaults: Record<string, unknown>;
|
|
441
|
+
panelFilter: PanelFilter;
|
|
442
|
+
adjustableFields: TemplateFieldOption[];
|
|
443
|
+
metadata?: Record<string, unknown>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** 历史记录列表项(不含 snapshot) */
|
|
447
|
+
export declare interface HistoryItem {
|
|
448
|
+
id: number;
|
|
449
|
+
title: string;
|
|
450
|
+
cover: string;
|
|
451
|
+
createdAt: number;
|
|
452
|
+
updatedAt: number;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** history.getList() 参数 */
|
|
456
|
+
export declare interface HistoryListOptions {
|
|
457
|
+
/** 页码,默认 1 */
|
|
458
|
+
page?: number;
|
|
459
|
+
/** 每页条数,默认 20,最大 50 */
|
|
460
|
+
pageSize?: number;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** history.getList() 返回值 */
|
|
464
|
+
export declare interface HistoryListResult {
|
|
465
|
+
total: number;
|
|
466
|
+
items: HistoryItem[];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* History 模块
|
|
471
|
+
* 对外暴露:getList / getDetail / delete
|
|
472
|
+
*/
|
|
473
|
+
declare class HistoryModule {
|
|
474
|
+
private readonly appKey;
|
|
475
|
+
private readonly http;
|
|
476
|
+
constructor(appKey: string, http: AxiosInstance);
|
|
477
|
+
/**
|
|
478
|
+
* 获取当前用户在此应用下的历史记录列表(分页,仅元数据,不含 snapshot)
|
|
479
|
+
*
|
|
480
|
+
* 对应现有接口:POST /ai/v5/artimind/generator/type
|
|
481
|
+
* category 传入 appKey,实现多应用数据隔离
|
|
482
|
+
*/
|
|
483
|
+
getList(options?: HistoryListOptions): Promise<HistoryListResult>;
|
|
484
|
+
/**
|
|
485
|
+
* 获取单条历史记录详情(含完整 snapshot)
|
|
486
|
+
*
|
|
487
|
+
* 对应现有接口:GET /ai/v5/artimind/generator/:id
|
|
488
|
+
*/
|
|
489
|
+
getDetail(id: number): Promise<CloudRecord>;
|
|
490
|
+
/**
|
|
491
|
+
* 删除历史记录
|
|
492
|
+
*
|
|
493
|
+
* 对应现有接口:DELETE /ai/v5/artimind/generator/:id
|
|
494
|
+
*/
|
|
495
|
+
delete(id: number): Promise<void>;
|
|
496
|
+
/** 将后端原始结构转换为 SDK 公开的 CloudRecord 结构 */
|
|
497
|
+
private _normalizeRecord;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Runtime 参数字段 */
|
|
501
|
+
export declare interface PanelField {
|
|
502
|
+
id: string;
|
|
503
|
+
label?: string;
|
|
504
|
+
type?: string;
|
|
505
|
+
bind?: {
|
|
506
|
+
path?: string;
|
|
507
|
+
};
|
|
508
|
+
readonly?: boolean;
|
|
509
|
+
[key: string]: unknown;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** Runtime 参数裁剪规则 */
|
|
513
|
+
export declare interface PanelFilter {
|
|
514
|
+
includeGroups?: string[];
|
|
515
|
+
includeFields?: string[];
|
|
516
|
+
excludeGroups?: string[];
|
|
517
|
+
excludeFields?: string[];
|
|
518
|
+
readonlyFields?: string[];
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** Runtime 参数分组 */
|
|
522
|
+
export declare interface PanelGroup {
|
|
523
|
+
id: string;
|
|
524
|
+
title?: string;
|
|
525
|
+
fields: PanelField[];
|
|
526
|
+
[key: string]: unknown;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Runtime 参数 schema */
|
|
530
|
+
export declare interface PanelSchema {
|
|
531
|
+
version?: string;
|
|
532
|
+
generatorId?: string;
|
|
533
|
+
groups: PanelGroup[];
|
|
534
|
+
[key: string]: unknown;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Atomm Generator SDK 全部公开类型定义
|
|
539
|
+
*/
|
|
540
|
+
/** SDK 支持的运行环境 */
|
|
541
|
+
export declare type SdkEnv = 'prod' | 'pre' | 'test' | 'dev';
|
|
542
|
+
|
|
543
|
+
/** SDK 业务错误 */
|
|
544
|
+
export declare class SdkError extends Error {
|
|
545
|
+
readonly code: number;
|
|
546
|
+
constructor(code: number, message: string);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** GeneratorSDK.init() 配置项 */
|
|
550
|
+
export declare interface SdkInitOptions {
|
|
551
|
+
/** 开发者控制台获取的应用标识(必填) */
|
|
552
|
+
appKey: string;
|
|
553
|
+
/** 运行环境,默认 'prod' */
|
|
554
|
+
env?: SdkEnv;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** 模板应用参数 */
|
|
558
|
+
export declare interface TemplateApplyOptions {
|
|
559
|
+
source?: string;
|
|
560
|
+
onPanelFilter?: (panelFilter: PanelFilter) => void | Promise<void>;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** 构建模板参数 */
|
|
564
|
+
export declare interface TemplateBuildOptions {
|
|
565
|
+
generatorId: string;
|
|
566
|
+
appKey?: string;
|
|
567
|
+
state: Record<string, unknown>;
|
|
568
|
+
panelSchema: PanelSchema;
|
|
569
|
+
selectedFieldPaths: string[];
|
|
570
|
+
templateMeta?: Record<string, unknown>;
|
|
571
|
+
metadata?: Record<string, unknown>;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** 模板下载参数 */
|
|
575
|
+
export declare interface TemplateDownloadOptions {
|
|
576
|
+
fileName?: string;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** 模板作者可勾选字段 */
|
|
580
|
+
export declare interface TemplateFieldOption {
|
|
581
|
+
groupId: string;
|
|
582
|
+
groupTitle?: string;
|
|
583
|
+
fieldId: string;
|
|
584
|
+
fieldLabel?: string;
|
|
585
|
+
path: string;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Template 模块
|
|
590
|
+
* 负责模板协议构建、校验、下载与 runtime 应用
|
|
591
|
+
*/
|
|
592
|
+
export declare class TemplateModule {
|
|
593
|
+
getFieldOptions(args: {
|
|
594
|
+
panelSchema: PanelSchema;
|
|
595
|
+
}): TemplateFieldOption[];
|
|
596
|
+
build(args: TemplateBuildOptions): GeneratorTemplateDefinition;
|
|
597
|
+
serialize(template: GeneratorTemplateDefinition): string;
|
|
598
|
+
parse(text: string): GeneratorTemplateDefinition;
|
|
599
|
+
download(template: GeneratorTemplateDefinition, options?: TemplateDownloadOptions): void;
|
|
600
|
+
toRuntimeSnapshot(template: GeneratorTemplateDefinition): TemplateRuntimeSnapshot;
|
|
601
|
+
applyToRuntime(runtime: TemplateRuntime, template: GeneratorTemplateDefinition, options?: TemplateApplyOptions): Promise<void>;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** 最小 runtime 约束 */
|
|
605
|
+
export declare interface TemplateRuntime {
|
|
606
|
+
setState: (nextState: Record<string, unknown>, options?: {
|
|
607
|
+
source?: string;
|
|
608
|
+
silent?: boolean;
|
|
609
|
+
}) => void | Promise<void>;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** 模板转 runtime 快照后的结果 */
|
|
613
|
+
export declare interface TemplateRuntimeSnapshot {
|
|
614
|
+
state: Record<string, unknown>;
|
|
615
|
+
panelFilter: PanelFilter;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/** 使用额度信息(整合免费次数 + 积分余额 + 免费时段) */
|
|
619
|
+
export declare interface UsageInfo {
|
|
620
|
+
/** 剩余免费次数 */
|
|
621
|
+
freeRemaining: number;
|
|
622
|
+
/** 免费总次数 */
|
|
623
|
+
freeTotal: number;
|
|
624
|
+
/** 免费次数用完后每次操作所需积分 */
|
|
625
|
+
creditsPerUse: number;
|
|
626
|
+
/** 当前积分余额 */
|
|
627
|
+
creditsBalance: number;
|
|
628
|
+
/** 是否在免费时段内(成功操作后短时间内可免费重复操作) */
|
|
629
|
+
inFreePeriod: boolean;
|
|
630
|
+
/** 免费时段剩余秒数 */
|
|
631
|
+
freePeriodRemaining: number;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** 用户信息 */
|
|
635
|
+
export declare interface UserInfo {
|
|
636
|
+
uid: number;
|
|
637
|
+
uuid: string;
|
|
638
|
+
/** 用户名(对应接口 userName 字段) */
|
|
639
|
+
userName: string;
|
|
640
|
+
headpic: string;
|
|
641
|
+
email: string;
|
|
642
|
+
phoneNumber: string;
|
|
643
|
+
phoneZone: string;
|
|
644
|
+
/** 性别:0 未知 / 1 男 / 2 女 */
|
|
645
|
+
gender: number;
|
|
646
|
+
/** 个性签名 */
|
|
647
|
+
signature: string;
|
|
648
|
+
/** 账号创建时间(Unix 秒) */
|
|
649
|
+
createTime: number;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* 将异步操作与计费流程组合
|
|
654
|
+
*
|
|
655
|
+
* 执行顺序:
|
|
656
|
+
* 1. billing.check() — 积分不足时直接 reject(code: BILLING_INSUFFICIENT)
|
|
657
|
+
* 2. action() — 执行实际操作
|
|
658
|
+
* 3. billing.consume() — 操作成功后扣费
|
|
659
|
+
*
|
|
660
|
+
* @param billing SDK billing 模块实例
|
|
661
|
+
* @param action 要执行的异步操作
|
|
662
|
+
* @param options consume 参数(可选)
|
|
663
|
+
*/
|
|
664
|
+
export declare const withBilling: <T>(billing: BillingModule, action: () => Promise<T>, options?: BillingConsumeOptions) => Promise<WithBillingResult<T>>;
|
|
665
|
+
|
|
666
|
+
/** withBilling() 组合返回值 */
|
|
667
|
+
export declare interface WithBillingResult<T> {
|
|
668
|
+
result: T;
|
|
669
|
+
billing: BillingConsumeResult;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export { }
|