@agentic-canvas/media 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ Agentic Creative Canvas (ACC)
2
+ Copyright 2026 ACC contributors.
3
+
4
+ ACC-authored code is licensed under the Apache License, Version 2.0.
5
+ Third-party code, fonts and other assets retain their original licenses.
6
+ The ACC license does not replace or remove those third-party terms.
7
+
8
+ The grida-adapter package includes third-party source provenance, license
9
+ texts and modification records under dist/third-party/, plus font and
10
+ WASM license texts alongside dist/native-ui-public/ assets.
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @agentic-canvas/media
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 框架无关的外部资产解析、图片 / 视频生命周期与活动资源预算,仅依赖 core,不依赖 React、Grida、embed、Demo 或模型服务。文件与鉴权由外部 Asset Store 提供,不创建可写 Document。
4
+
5
+ ## 当前导出
6
+
7
+ | API | 范围 |
8
+ | --- | --- |
9
+ | `createAssetLoader(options?)` | 地址解析、来源策略、外部 resolver、取消与临时 lease;不下载 / 缓存媒体字节 |
10
+ | `AssetLoadError` | 固定 code / 消息,不携带临时 URL 或原始 resolver 异常 |
11
+ | `createActivationScheduler(options?)` | 全局 / perKind 活动预算、最早激活优先淘汰、可重用 clear 与永久 dispose |
12
+ | `createVideoSession(video, options)` | 宿主 video 的解析、play、错误、取消与来源清理 |
13
+ | `createImageSession(image, { assets })` | 宿主 image 的来源 / 原生 decode 生命周期;不代表 Skia 解码 |
14
+
15
+ AssetLoaderOptions 支持 resolver、baseUrl、精确 allowedOrigins 与显式 allowBlob。resolver + assetRef 解析失败不回退;其他路径先 src 再 assetRef.uri。URI 是临时运行结果,不能反写文档、工具结果或日志。lease.dispose 幂等,只释放该临时结果,不删除原资产。
16
+
17
+ ActivationSchedulerOptions 的 maxActive 默认 1,可配置 perKind;该值是 Demo 策略,不是实测解码数量或性能上限。视频 / HTML 从 loading 起申请预算,图片会话当前不计入。共享池资源 ID 应唯一。
18
+
19
+ VideoSessionOptions 包含 assets、scheduler、muted(默认 true)与 loop(默认 false)。session 独占元素来源;宿主拥有 DOM、布局和创作 SDK。activate、deactivate、setVisible、getState、subscribe、dispose 使用 core ResourceSession 协议。隐藏 / 停用 / 替换 / 销毁会及时取消并释放,忽略迟到结果;重新可见不自动激活。通知或清理中递归 activate 返回 false。
20
+
21
+ 完整接入、所有权及浏览器限制见 [示例](../../docs/examples/resource-lifecycle.md)与 [ADR 0006](../../docs/decisions/0006-resource-lifecycle.md)。模块测试与真实浏览器解码 / 资源回收分开判定;静态缩略图分级、完整缓存和 M2 性能仍待推进。
@@ -0,0 +1,162 @@
1
+ import { AssetResolver, AssetLoader, ActiveResourceKind, ActivationScheduler, ResourceSession, MediaAdapter, CanvasTypeDefinition, StudioHostMessage, StudioIssue, StudioDefinition, CanvasObject, AssetRef, CanvasObjectPatch, CommandResult } from '@agentic-canvas/core';
2
+
3
+ type AssetLoadErrorCode = "INVALID_REQUEST" | "INVALID_URI" | "ORIGIN_DENIED" | "RESOLUTION_FAILED" | "ABORTED";
4
+ /** Safe to classify or present: it never includes a URL or resolver exception. */
5
+ declare class AssetLoadError extends Error {
6
+ readonly code: AssetLoadErrorCode;
7
+ constructor(code: AssetLoadErrorCode);
8
+ }
9
+ interface AssetLoaderOptions {
10
+ resolver?: AssetResolver;
11
+ baseUrl?: string;
12
+ /** Exact normalized HTTP(S) origins; omitted means no host origin restriction. */
13
+ allowedOrigins?: readonly string[];
14
+ /** Blob URLs are transient resources and require explicit host opt-in. */
15
+ allowBlob?: boolean;
16
+ }
17
+ /** Resolve addresses and temporary handles only. The loader does not fetch or cache bytes. */
18
+ declare function createAssetLoader(options?: AssetLoaderOptions): AssetLoader;
19
+
20
+ interface ActivationSchedulerOptions {
21
+ /** Explicit host policy. The default of one is a Demo budget, not a performance claim. */
22
+ maxActive?: number;
23
+ perKind?: Partial<Record<ActiveResourceKind, number>>;
24
+ }
25
+ /**
26
+ * Oldest-first transient activation policy, not an object or document store.
27
+ * Eviction callbacks are synchronous cleanup notifications. Exceptions are
28
+ * contained so every selected resource is released; returned promises are not
29
+ * awaited, and any rejection is observed without leaking its contents.
30
+ */
31
+ declare function createActivationScheduler(options?: ActivationSchedulerOptions): ActivationScheduler;
32
+
33
+ interface VideoSessionOptions {
34
+ assets: AssetLoader;
35
+ scheduler: ActivationScheduler;
36
+ muted?: boolean;
37
+ loop?: boolean;
38
+ }
39
+ /** An exclusive, disposable playback session for one host-owned video element. */
40
+ declare function createVideoSession(video: HTMLVideoElement, options: VideoSessionOptions): ResourceSession;
41
+
42
+ /**
43
+ * Audio as a registered medium (the Grida document has no audio node): a card
44
+ * with the title, duration and a waveform drawn from `peaks`, and a live mode
45
+ * that plays the asset in a host-owned `<audio>` element. The bytes stay behind
46
+ * `assetRef` (or a `src` URL); the resolved URL is never written back.
47
+ */
48
+ declare const AUDIO_TYPE = "audio";
49
+ declare const AUDIO_VERSION = 1;
50
+ /** Bars stored for the waveform; enough for a 1600 px card at 4 px per bar. */
51
+ declare const AUDIO_PEAKS = 96;
52
+ interface AudioProps {
53
+ title: string;
54
+ /** Seconds, as decoded at import. */
55
+ duration: number;
56
+ /** AUDIO_PEAKS values in 0–1 (peak amplitude per equal time slice). */
57
+ peaks: number[];
58
+ loop?: boolean;
59
+ src?: string;
60
+ }
61
+ declare const audioDefinition: CanvasTypeDefinition;
62
+ /** "m:ss" (or "h:mm:ss"). */
63
+ declare function formatAudioTime(seconds: number): string;
64
+ /** The card as SVG markup; `progress` (0–1) colours the played part of the waveform, `elapsed` (seconds) shows next to the duration. */
65
+ declare function audioSvg(audio: AudioProps, width: number, height: number, options?: {
66
+ progress?: number;
67
+ playing?: boolean;
68
+ elapsed?: number;
69
+ }): string;
70
+ declare const audioAdapter: MediaAdapter;
71
+ /** Peak amplitude per equal time slice of decoded audio, normalised to the loudest slice. */
72
+ declare function audioPeaks(channels: readonly Float32Array[], count?: number): number[];
73
+
74
+ interface ImageSessionOptions {
75
+ assets: AssetLoader;
76
+ }
77
+ /** Source/decode lifecycle for an exclusive, host-owned image element. */
78
+ declare function createImageSession(image: HTMLImageElement, options: ImageSessionOptions): ResourceSession;
79
+
80
+ /** How the host talks to one Studio: posting to it, and hearing messages with their origin and whether they came from that Studio. */
81
+ interface StudioChannel {
82
+ post(message: StudioHostMessage): void;
83
+ listen(handler: (event: {
84
+ origin: string;
85
+ fromStudio: boolean;
86
+ data: unknown;
87
+ }) => void): () => void;
88
+ }
89
+ /** A channel to a Studio in a frame or window: posts with its exact origin, and marks messages by their source window. */
90
+ declare function createWindowStudioChannel(target: () => Window | null | undefined, origin: string, host?: Pick<Window, "addEventListener" | "removeEventListener">): StudioChannel;
91
+ type StudioSessionState = {
92
+ phase: "opening";
93
+ } | {
94
+ phase: "editing";
95
+ } | {
96
+ phase: "committing";
97
+ } | {
98
+ phase: "committed";
99
+ revision: number;
100
+ }
101
+ /** Fields the Studio owns changed while it was open; the host decides: overwrite with the Studio's result, or discard it. */
102
+ | {
103
+ phase: "conflict";
104
+ } | {
105
+ phase: "cancelled";
106
+ by: "host" | "studio";
107
+ } | {
108
+ phase: "removed";
109
+ } | {
110
+ phase: "failed";
111
+ code: "STUDIO_TIMEOUT" | "INVALID_RESULT" | "STALE_SESSION" | "ASSET_STORE_FAILED" | "COMMIT_REJECTED";
112
+ message: string;
113
+ issues?: StudioIssue[];
114
+ };
115
+ interface StudioSessionOptions {
116
+ studio: StudioDefinition;
117
+ channel: StudioChannel;
118
+ /** The object as the host opened it, and the revision it was read at. */
119
+ object: CanvasObject;
120
+ revision: number;
121
+ media?: {
122
+ mimeType?: string;
123
+ bytes: ArrayBuffer;
124
+ };
125
+ /** The object's current state in the host's document (undefined once deleted). */
126
+ current(objectId: string): CanvasObject | undefined;
127
+ /** Stores a Studio output as a new asset version in the host's asset store. */
128
+ storeAsset(input: {
129
+ objectId: string;
130
+ slot: string;
131
+ mimeType: string;
132
+ bytes: ArrayBuffer;
133
+ }): Promise<AssetRef>;
134
+ /** The host's public transaction (one undoable step). */
135
+ commit(objectId: string, patch: CanvasObjectPatch): CommandResult;
136
+ readyTimeoutMs?: number;
137
+ sessionId?: string;
138
+ }
139
+ interface StudioSession {
140
+ readonly id: string;
141
+ state(): StudioSessionState;
142
+ subscribe(listener: (state: StudioSessionState) => void): () => void;
143
+ cancel(): void;
144
+ resolveConflict(choice: "overwrite" | "discard"): void;
145
+ /** Messages ignored: foreign origin / source / session or malformed (`ignored`), and arriving after the session ended (`late`). */
146
+ stats(): {
147
+ ignored: number;
148
+ late: number;
149
+ };
150
+ dispose(): void;
151
+ }
152
+ /**
153
+ * One host-side Studio session. Nothing the Studio sends is written until it
154
+ * passes: origin and source, session id, base revision, the Studio's declared
155
+ * props and asset slots, and an object-level check that the fields the Studio
156
+ * owns did not change since opening. Assets are stored first, then props and
157
+ * asset references commit as one transaction. Ended sessions ignore results.
158
+ */
159
+ declare function openStudioSession(options: StudioSessionOptions): StudioSession;
160
+
161
+ export { AUDIO_PEAKS, AUDIO_TYPE, AUDIO_VERSION, AssetLoadError, audioAdapter, audioDefinition, audioPeaks, audioSvg, createActivationScheduler, createAssetLoader, createImageSession, createVideoSession, createWindowStudioChannel, formatAudioTime, openStudioSession };
162
+ export type { ActivationSchedulerOptions, AssetLoadErrorCode, AssetLoaderOptions, AudioProps, ImageSessionOptions, StudioChannel, StudioSession, StudioSessionOptions, StudioSessionState, VideoSessionOptions };