@volcengine/amk-editor 0.0.1 → 0.0.2-beta.1

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.
@@ -6,7 +6,7 @@ export interface CreateLocalUploadModalOptions {
6
6
  onConfirm: (files: File[]) => void;
7
7
  }
8
8
  export interface LocalUploadModalController {
9
- open: (files: File[]) => void;
9
+ open: (files?: File[]) => void;
10
10
  close: () => void;
11
11
  destroy: () => void;
12
12
  }
@@ -65,6 +65,10 @@ export interface VeVeditorMaterialOptions<TMaterialItem = VeVeditorMaterialItem>
65
65
  }
66
66
  export interface VeVeditorOptions<TMaterialOptions = VeVeditorMaterialOptions, TI18nOptions = VeVeditorI18nOptions, TResourceOptions extends VeVeditorResourceOptionTypes = VeVeditorResourceOptionTypes> {
67
67
  container: HTMLElement;
68
+ /** 埋点来源标识,用于区分业务接入方。 */
69
+ source?: string;
70
+ /** 埋点账号 ID;上报时写入事件 params.AccountID(对齐 master)。 */
71
+ accountId?: string;
68
72
  theme?: VeVeditorTheme;
69
73
  material?: TMaterialOptions;
70
74
  i18n?: TI18nOptions;
@@ -101,6 +105,7 @@ export interface VeVeditorOptions<TMaterialOptions = VeVeditorMaterialOptions, T
101
105
  item?: unknown;
102
106
  }) => void;
103
107
  onNodePreviewError?: (type: 'video' | 'audio', node: unknown) => void;
108
+ onPreviewNodeRefresh?: (type: 'video' | 'audio', node: unknown) => void | Promise<void>;
104
109
  onBeforeUndo?: (payload: unknown) => boolean | void;
105
110
  onBeforeRedo?: (payload: unknown) => boolean | void;
106
111
  onBeforeTimestampMount?: (params: Record<string, unknown>) => boolean | Promise<boolean>;
@@ -0,0 +1,46 @@
1
+ import type { AmkEditorStorageConfig, AmkEditorUploadSTSCredentials, MaterialItem } from './types';
2
+ export declare const DEFAULT_TOS_REGION = "cn-beijing";
3
+ export declare const DEFAULT_SIGNED_URL_EXPIRES_SECONDS: number;
4
+ export declare const TOS_SIGNED_URL_REFRESH_AHEAD_MS: number;
5
+ /** 签名最长 24 小时,但不能超过本次 STS 凭证的剩余有效期。 */
6
+ export declare function resolveSignedUrlExpiresSeconds(credentials: AmkEditorUploadSTSCredentials, now?: number): number;
7
+ /** 解析 TOS V4 签名 URL 的绝对过期时间;非 TOS 签名链返回 null。 */
8
+ export declare function resolveTosSignedUrlExpiresAt(urlValue: unknown): number | null;
9
+ interface TosClientLike {
10
+ putObject(input: {
11
+ bucket: string;
12
+ key: string;
13
+ body: File;
14
+ contentType?: string;
15
+ }): Promise<unknown>;
16
+ getPreSignedUrl(input: {
17
+ bucket: string;
18
+ key: string;
19
+ method?: 'GET' | 'PUT';
20
+ expires?: number;
21
+ }): string;
22
+ }
23
+ interface UploadFilesToTosOptions {
24
+ files: File[];
25
+ projectId: string;
26
+ storage: AmkEditorStorageConfig;
27
+ createClient?: (credentials: AmkEditorUploadSTSCredentials, region: string) => TosClientLike;
28
+ }
29
+ interface RefreshTosMaterialUrlsOptions {
30
+ materials: MaterialItem[];
31
+ storage: AmkEditorStorageConfig;
32
+ createClient?: UploadFilesToTosOptions['createClient'];
33
+ }
34
+ /** 使用宿主下发的临时 STS 将本地文件直传客户 TOS,并转换为编辑器素材。 */
35
+ export declare function uploadFilesToTos(options: UploadFilesToTosOptions): Promise<MaterialItem[]>;
36
+ /** 为已持久化的私有 TOS 素材重新生成播放签名,供初始化和按需刷新使用。 */
37
+ export declare function refreshTosMaterialUrls(options: RefreshTosMaterialUrlsOptions): Promise<Array<Partial<MaterialItem> & {
38
+ material_id: string;
39
+ }>>;
40
+ /** 为资产库导入的 TOS 素材签发播放 URL;稳定身份仍保留在 source_material_id。 */
41
+ export declare function signTosImportedMaterialUrls(options: {
42
+ materials: MaterialItem[];
43
+ storage: AmkEditorStorageConfig;
44
+ createClient?: UploadFilesToTosOptions['createClient'];
45
+ }): Promise<MaterialItem[]>;
46
+ export {};
package/dist/types.d.ts CHANGED
@@ -5,6 +5,23 @@ export interface MaterialItem extends VeVeditorMaterialItem {
5
5
  source_material_id: string;
6
6
  /** Editing API 生成的服务端 id;业务方不必传,传了也不会入库。 */
7
7
  material_id?: string;
8
+ /** poster 抽帧任务 ID;任务完成或不再使用时显式写回 null。 */
9
+ poster_task_id?: string | null;
10
+ /** sprite 抽帧任务 ID;任务完成或不再使用时显式写回 null。 */
11
+ sprite_task_id?: string | null;
12
+ }
13
+ export type SystemMaterialItem = Omit<Partial<MaterialItem>, 'source_material_id' | 'source'> & {
14
+ source_material_id: string;
15
+ source?: string;
16
+ type: NonNullable<MaterialItem['type']>;
17
+ name?: string;
18
+ };
19
+ /** 可由外部工具栏复用的素材导入入口。 */
20
+ export type AmkMaterialImportType = 'local' | 'url' | 'system';
21
+ /** Optional callbacks scoped to one externally triggered material import. */
22
+ export interface AmkMaterialImportRequestOptions {
23
+ /** Called with persisted materials only for this request. */
24
+ onMaterialsImported?: (materials: MaterialItem[]) => void | Promise<void>;
8
25
  }
9
26
  /**
10
27
  * 抽帧产物存储 key 的推荐命名,仅用于提供接入提示,不属于强制素材 Schema。
@@ -30,7 +47,17 @@ export interface MaterialConfig {
30
47
  uploadAccept?: string;
31
48
  onUploadMaterial?: (files: File[]) => Promise<MaterialItem[]> | MaterialItem[];
32
49
  onUploadUrlMaterial?: (urls: string[]) => Promise<MaterialItem[]> | MaterialItem[];
33
- onUploadFromSystem?: () => Promise<MaterialItem[]> | MaterialItem[];
50
+ /**
51
+ * 从业务资产库选择素材。业务方自行实现弹窗、列表查询与勾选,只返回选中数组。
52
+ * `tos://bucket/key` 条目会由 SDK 用 storage.getUploadSTS 自动签名和补齐元信息。
53
+ * 返回 `undefined` / `null` / `[]` 视为取消或未选择,不提示失败。
54
+ */
55
+ onUploadFromSystem?: () => Promise<SystemMaterialItem[] | undefined | null> | SystemMaterialItem[] | undefined | null;
56
+ /**
57
+ * 素材成功入库后回调(已合并 Editing API 返回的 `material_id`)。
58
+ * 本地 / URL / 资产库三条导入链路都会走到这里;失败或用户取消不会触发。
59
+ */
60
+ onMaterialsImported?: (materials: MaterialItem[]) => void | Promise<void>;
34
61
  /**
35
62
  * 刷新播放信息。未配置时用素材库已有字段;
36
63
  * 配置后:入参为待刷新素材列表(按服务端 material_id 区分,支持批量),
@@ -52,10 +79,22 @@ export interface MaterialConfig {
52
79
  material: MaterialItem;
53
80
  }) => Promise<PersistExtractUrlsResult | string[]> | PersistExtractUrlsResult | string[];
54
81
  }
82
+ export interface AmkEditorHeaderTitleUpdateSuccess {
83
+ readonly projectId: string;
84
+ /** Project title persisted successfully by the Editing API. */
85
+ readonly title: string;
86
+ }
55
87
  export interface AmkEditorHeaderConfig {
56
88
  show?: boolean;
89
+ /**
90
+ * When set, the header is rendered into this element instead of inside the
91
+ * editor root. Use this to place a full-width header above a host split layout.
92
+ */
93
+ mount?: HTMLElement;
57
94
  onBack?: () => void;
58
95
  onClose?: () => void;
96
+ /** Fired only after the project title is persisted successfully. */
97
+ onTitleUpdateSuccess?: (change: AmkEditorHeaderTitleUpdateSuccess) => void;
59
98
  }
60
99
  export interface AmkEditorExportConfig {
61
100
  /**
@@ -64,6 +103,34 @@ export interface AmkEditorExportConfig {
64
103
  */
65
104
  qualityEnhancement?: boolean;
66
105
  }
106
+ /** 浏览器直传 TOS 使用的临时凭证;字段可直接用于初始化 TOS Browser SDK。 */
107
+ export interface AmkEditorUploadSTSCredentials {
108
+ accessKeyId: string;
109
+ accessKeySecret: string;
110
+ /** 临时凭证必填;使用长期 AK/SK 做本地联调时可省略。 */
111
+ stsToken?: string;
112
+ /** 凭证过期时间,支持 ISO 8601、秒时间戳或毫秒时间戳;用于限制签名 URL 有效期。 */
113
+ expiration?: string | number;
114
+ }
115
+ /**
116
+ * 产物 / 主动上传的存储目标。
117
+ * `media_output_destination` 用于 TOS 直传的 Bucket 定位;当前不会自动写入 AMK tools 请求体。
118
+ * @see https://docs.volcengine.com/docs/6448/2386113
119
+ */
120
+ export interface AmkEditorStorageConfig {
121
+ /**
122
+ * 处理产物存储目标。支持 `vod://<空间名>` 或 `tos://<桶名>`。
123
+ * 配置后任务结果中的 url 为对应资源地址,而不是临时下载链。
124
+ */
125
+ media_output_destination?: string;
126
+ /**
127
+ * 配置后,本地上传会优先使用 TOS Browser SDK 直传
128
+ * `media_output_destination` 指定的 TOS Bucket;未配置时沿用
129
+ * `material.onUploadMaterial`。业务服务端应返回最小权限、短有效期凭证,
130
+ * 浏览器端不得保存客户长期 AK/SK。
131
+ */
132
+ getUploadSTS?: () => AmkEditorUploadSTSCredentials | Promise<AmkEditorUploadSTSCredentials>;
133
+ }
67
134
  export interface ExportVideoParams {
68
135
  videoName: string;
69
136
  qualityEnhancement: boolean;
@@ -73,12 +140,24 @@ export interface ExportVideoParams {
73
140
  format: 'mp4' | 'mp3';
74
141
  codec: 'h264' | 'h265' | 'vp9' | 'mp3';
75
142
  }
143
+ /** Result of {@link AmkEditor.requestExport} for Agent/frontend-tool callers. */
144
+ export type AmkExportRequestResult = {
145
+ status: 'success';
146
+ taskId: string;
147
+ } | {
148
+ status: 'cancel';
149
+ } | {
150
+ status: 'failed';
151
+ error: string;
152
+ };
76
153
  export interface VeVeditorInstance {
77
154
  destroy: () => void;
78
155
  on?: (eventName: string, handler: (...args: any[]) => void) => void;
79
156
  off?: (eventName: string, handler: (...args: any[]) => void) => void;
80
157
  getTrack?: () => any[];
81
- setTrack?: (track: any[]) => Promise<void>;
158
+ setTrack?: (track: any[], options?: {
159
+ recordHistory?: boolean;
160
+ }) => Promise<void>;
82
161
  setTrackElementMarker?: (elementId: string, marker: {
83
162
  key?: string;
84
163
  content: string;
@@ -124,15 +203,22 @@ type AmkResourceOptionTypes = {
124
203
  filter: boolean;
125
204
  effect: boolean;
126
205
  };
127
- type AmkInheritedVeVeditorOptions = Omit<VeVeditorOptions<MaterialConfig, VeVeditorI18nOptions, AmkResourceOptionTypes>, 'initialData' | 'recording' | 'onSketchItemsChange' | 'onNodePreviewError' | 'onBeforeUndo' | 'onBeforeRedo' | 'onBeforeTimestampMount' | 'onBeforeKeyframeMount' | 'onTrackChanged' | 'onRecordingUpload' | 'decode'>;
206
+ type AmkInheritedVeVeditorOptions = Omit<VeVeditorOptions<MaterialConfig, VeVeditorI18nOptions, AmkResourceOptionTypes>, 'initialData' | 'recording' | 'onSketchItemsChange' | 'onNodePreviewError' | 'onPreviewNodeRefresh' | 'onBeforeUndo' | 'onBeforeRedo' | 'onBeforeTimestampMount' | 'onBeforeKeyframeMount' | 'onTrackChanged' | 'onRecordingUpload' | 'decode'>;
128
207
  export type AmkEditorDecodeOptions = VeVeditorDecodeOptions;
208
+ /** 每次 AMK 请求前动态获取、原样透传给 endpoint 的业务请求头。 */
209
+ export type AmkEditorGetHeaders = () => Readonly<Record<string, string>> | undefined | Promise<Readonly<Record<string, string>> | undefined>;
129
210
  export interface AmkEditorOptions extends AmkInheritedVeVeditorOptions {
130
211
  projectId: string;
212
+ /** AMK Editing API 的业务代理地址。 */
131
213
  endpoint: string;
214
+ /** 每次请求前调用;返回值不解析、不改写,仅透传给 endpoint。 */
215
+ getHeaders?: AmkEditorGetHeaders;
132
216
  header?: AmkEditorHeaderConfig;
133
217
  export?: AmkEditorExportConfig;
134
218
  getLicenseUrl?: string | (() => string | Promise<string>);
135
219
  decode?: AmkEditorDecodeOptions;
220
+ /** 产物 / 主动上传的存储目标,包括 TOS / VOD。 */
221
+ storage?: AmkEditorStorageConfig;
136
222
  }
137
223
  export interface AmkEditorInternalConfig {
138
224
  projectId: string;
@@ -6,7 +6,7 @@ export type SpriteState = {
6
6
  /**
7
7
  * 素材 `sprite`:
8
8
  * - object `{ storeurls, capturenum }`:已完成;链接是否失效由实际网络请求判断
9
- * - string:抽帧 taskId(进行中)
9
+ * - 进行中任务放在 `sprite_task_id`;旧 `sprite` 字符串仅用于一次性迁移
10
10
  * - 缺省:需要新建任务
11
11
  */
12
12
  export declare function resolveSpriteState(material: MaterialItem): SpriteState;
@@ -16,18 +16,21 @@ export declare function isPersistablePosterUrl(value: unknown): boolean;
16
16
  export declare function isRuntimeOnlyPosterUrl(value: unknown): boolean;
17
17
  /** http poster;有效性由实际网络请求判断 */
18
18
  export declare function isPosterAssetReady(material: MaterialItem): boolean;
19
+ /** poster 任务只能存在独立字段;旧 poster 非 http/dataURL 字符串仅用于一次性迁移。 */
20
+ export declare function resolvePosterTaskId(material: MaterialItem): string | undefined;
19
21
  export declare function isExtractableVideoMaterial(material: MaterialItem): boolean;
20
22
  export declare function resolveMaterialMediaUrl(material: MaterialItem): string;
21
23
  export type MaterialExtractActions = {
22
24
  url: string;
23
- /** 需要新建 sprite 抽帧任务,完成后 PUT sprite=taskId */
25
+ /** 需要新建 sprite 抽帧任务,任务 ID 写入 sprite_task_id */
24
26
  createSpriteTask: boolean;
25
- /** 已有 taskId,继续轮询,完成后 PUT sprite 结果 */
27
+ /** 已有 taskId,从 sprite_task_id 继续轮询 */
26
28
  resumeSpriteTaskId?: string;
29
+ /** 已有 poster 任务,从 poster_task_id 继续轮询。 */
30
+ resumePosterTaskId?: string;
27
31
  /**
28
- * 需要抓封面:
29
- * - 接口模式:缺有效 http poster(含 auth_key 过期)时抓取,http 结果 PUT 落盘
30
- * - 前端解码模式:无运行时缓存时也可抓取(dataURL 不落盘)
32
+ * 需要抓封面:缺有效 http poster,或需恢复进行中的 poster_task_id。
33
+ * 前端 DataURL 仅作会话预览,不单独驱动 capturePoster。
31
34
  */
32
35
  capturePoster: boolean;
33
36
  };