-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
183 lines (178 loc) · 5.15 KB
/
Copy pathindex.ts
File metadata and controls
183 lines (178 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* SDK media primitives — aggregated facade.
*
* Gene: `sdk.media.gen1` · enforces `repo.engineering.client_side_computation.gen1`.
*
* Attached to the SDK as `sdk.media.*` by the SDK constructor. Can also be
* imported directly for tree-shaking:
* `import { createThumbnailer } from '@agentstack/sdk/media';`
* (path subject to `exports` map in `package.json`).
*/
import {
createOpfsStore,
isOpfsAvailable,
OpfsUnavailableError,
type OpfsStore,
type OpfsStoreOptions,
} from './opfsStore';
import {
createThumbnailer,
DEFAULT_THUMBNAILER_NAMESPACE,
type ThumbnailerContract,
type ThumbnailerOptions,
type ThumbnailOptions,
type ThumbnailResult,
} from './thumbnailer';
import {
blobChunkSource,
opfsChunkSource,
runResumableUpload,
ResumableUploadError,
type ChunkSource,
type ResumableUploadInput,
type ResumableUploadOptions,
type ResumableUploadResult,
type ResumableUploadTarget,
} from './resumableUpload';
import {
buildHostingZipOpId,
fingerprintHostingZipFile,
} from './hostingZipUploadId';
import {
createLightbox,
isLightboxAvailable,
type HtmlSlide,
type ImageSlide,
type LightboxController,
type LightboxFactoryOptions,
type LightboxOpenOptions,
type LightboxSlide,
type VideoSlide,
} from './lightbox';
import {
getLightboxViewportSize,
LIGHTBOX_ORIENTATION_ASPECT_EPS,
shouldOfferOrientationMatch,
} from './lightboxViewport';
import {
DEFAULT_PROBE_IMAGE_NATURAL_TIMEOUT_MS,
probeImageNaturalSize,
} from './probeImageNaturalSize';
import { downloadUrlAsFile, sanitizeDownloadFilename } from './browserDownload';
import {
lightboxSlideDownloadBasename,
lightboxSlideDownloadUrl,
} from './lightboxSlideDownload';
import { createAgentStackMediaAudio, type AgentStackMediaAudioSurface } from './audio';
import { createAgentStackMediaPhoto, type AgentStackMediaPhotoSurface } from './photo';
/** Singleton surface returned from `sdk.media`. */
export interface AgentStackMediaSurface {
/** Pre-built thumbnail pipeline with default cache. */
readonly thumbnail: ThumbnailerContract;
/** Lazily-constructed singleton lightbox controller. */
readonly lightbox: LightboxController;
/** Resumable upload loop — pass an op_id + a ChunkSource. */
uploadResumable: typeof runResumableUpload;
/** Adapters to feed the resumable loop. */
chunkSource: {
blob: typeof blobChunkSource;
opfs: typeof opfsChunkSource;
};
/** Create a named OPFS store (separate from the one `thumbnail` uses). */
opfs: {
create: (opts: OpfsStoreOptions) => OpfsStore;
isAvailable: () => boolean;
};
/** Realtime capture denoise + metering (`sdk.media.audio.gen1`). */
readonly audio: AgentStackMediaAudioSurface;
/** Multi-size photo ladder + BlurHash (`sdk.media.photo.gen1`). */
readonly photo: AgentStackMediaPhotoSurface;
/** Errors (for consumer `instanceof` checks). */
errors: {
ResumableUploadError: typeof ResumableUploadError;
OpfsUnavailableError: typeof OpfsUnavailableError;
};
}
export interface AgentStackMediaFactoryOptions {
thumbnailer?: ThumbnailerOptions;
lightbox?: LightboxFactoryOptions;
}
export function createAgentStackMedia(
options: AgentStackMediaFactoryOptions = {}
): AgentStackMediaSurface {
let lightbox: LightboxController | null = null;
const thumbnail = createThumbnailer(options.thumbnailer);
const audio = createAgentStackMediaAudio();
const photo = createAgentStackMediaPhoto();
return {
thumbnail,
get lightbox(): LightboxController {
if (!lightbox) {
lightbox = createLightbox(options.lightbox);
}
return lightbox;
},
uploadResumable: runResumableUpload,
chunkSource: { blob: blobChunkSource, opfs: opfsChunkSource },
opfs: { create: createOpfsStore, isAvailable: isOpfsAvailable },
audio,
photo,
errors: { ResumableUploadError, OpfsUnavailableError },
};
}
export {
createOpfsStore,
isOpfsAvailable,
OpfsUnavailableError,
createThumbnailer,
DEFAULT_THUMBNAILER_NAMESPACE,
blobChunkSource,
opfsChunkSource,
runResumableUpload,
ResumableUploadError,
buildHostingZipOpId,
fingerprintHostingZipFile,
createLightbox,
isLightboxAvailable,
getLightboxViewportSize,
LIGHTBOX_ORIENTATION_ASPECT_EPS,
shouldOfferOrientationMatch,
DEFAULT_PROBE_IMAGE_NATURAL_TIMEOUT_MS,
probeImageNaturalSize,
downloadUrlAsFile,
sanitizeDownloadFilename,
lightboxSlideDownloadUrl,
lightboxSlideDownloadBasename,
};
export type {
OpfsStore,
OpfsStoreOptions,
ThumbnailerContract,
ThumbnailerOptions,
ThumbnailOptions,
ThumbnailResult,
ChunkSource,
ResumableUploadInput,
ResumableUploadOptions,
ResumableUploadResult,
ResumableUploadTarget,
HtmlSlide,
ImageSlide,
LightboxController,
LightboxFactoryOptions,
LightboxOpenOptions,
LightboxSlide,
VideoSlide,
};
export type {
AgentStackMediaAudioSurface,
AudioCaptureHandle,
AudioCaptureOptions,
AudioEnhanceProfileId,
} from './audio';
export type { AgentStackMediaPhotoSurface, PhotoCompressOptions, PhotoCompressResult } from './photo';
export {
getWebCodecsVideoEncodeCapability,
probeVp8EncoderConfigurable,
type WebCodecsVideoEncodeCapability,
} from './video/webcodecsEncodeCapabilities';