@theaiplatform/miniapp-sdk 0.0.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/dist/web.d.ts ADDED
@@ -0,0 +1,507 @@
1
+ /**
2
+ * Public miniapp API installed by the host. Importing this value is safe in
3
+ * build tools and tests; an unsupported-environment error is raised only when a
4
+ * property is read before the host installs the API.
5
+ */
6
+ export declare const app: MiniAppPlatformApi;
7
+
8
+ export declare function applyMiniAppTheme(theme: MiniAppTheme): void;
9
+
10
+ declare type CreateChannelOptions = {
11
+ workspaceId?: string;
12
+ name: string;
13
+ description?: string;
14
+ projectId?: string | null;
15
+ visibility?: string;
16
+ };
17
+
18
+ declare type CreateChannelResult = {
19
+ roomId: string;
20
+ };
21
+
22
+ declare type CreateProjectOptions = {
23
+ workspaceId?: string;
24
+ id?: string;
25
+ name: string;
26
+ discoverable?: boolean;
27
+ };
28
+
29
+ declare type CreateProjectResult = {
30
+ projectId: string;
31
+ };
32
+
33
+ declare type GetChannelAccessOptions = {
34
+ workspaceId?: string;
35
+ channelId: string;
36
+ };
37
+
38
+ declare type GetChannelAccessResult = {
39
+ archived: boolean;
40
+ capabilities: string[];
41
+ isParticipant: boolean;
42
+ /**
43
+ * Last timeline sequence retained for a former participant. When present,
44
+ * the channel remains readable through this sequence even though
45
+ * `isParticipant` is false.
46
+ */
47
+ visibleUntilSequence?: number | null;
48
+ };
49
+
50
+ declare type GetChannelTimelineOptions = {
51
+ workspaceId?: string;
52
+ channelId: string;
53
+ };
54
+
55
+ declare type GetChannelTimelineResult = {
56
+ timeline: {
57
+ messages: MiniAppChannelMessage[];
58
+ sequence: number;
59
+ };
60
+ };
61
+
62
+ export declare function getMiniAppThemeFromSearch(search?: string | URLSearchParams): MiniAppTheme;
63
+
64
+ /** Returns the public miniapp API proxy, which fails only when it is used. */
65
+ export declare function getPlatform(): MiniAppPlatform;
66
+
67
+ declare type GetProjectOptions = {
68
+ workspaceId?: string;
69
+ projectId: string;
70
+ };
71
+
72
+ declare type GetProjectResult = {
73
+ project: MiniAppProject | null;
74
+ };
75
+
76
+ export declare function installMiniAppThemeSync({ applyTheme, search, }?: InstallMiniAppThemeSyncOptions): () => void;
77
+
78
+ export declare type InstallMiniAppThemeSyncOptions = {
79
+ applyTheme?: (theme: MiniAppTheme) => void;
80
+ search?: string | URLSearchParams;
81
+ };
82
+
83
+ declare type InvokeSavedWorkflowOptions<TPayload = unknown> = {
84
+ workflowId: string;
85
+ payload?: TPayload;
86
+ };
87
+
88
+ declare type InvokeWorkflowOptions<TPayload = unknown> = {
89
+ workflowJson: string;
90
+ payload?: TPayload;
91
+ };
92
+
93
+ declare type InvokeWorkflowResult = {
94
+ success: boolean;
95
+ status: string;
96
+ message: string;
97
+ runId?: string | null;
98
+ error?: string | null;
99
+ };
100
+
101
+ declare type ListChannelsOptions = {
102
+ workspaceId?: string;
103
+ };
104
+
105
+ declare type ListChannelsResult = {
106
+ rooms: MiniAppChannel[];
107
+ readMode: string;
108
+ };
109
+
110
+ declare type ListWorkflowsOptions = {
111
+ workspaceId?: string;
112
+ };
113
+
114
+ declare type ListWorkflowsResult = {
115
+ workflows: MiniAppWorkflow[];
116
+ };
117
+
118
+ declare type MiniAppAuthApi = {
119
+ getUserProfile(): MiniAppMaybePromise<MiniAppUserProfile | null>;
120
+ };
121
+
122
+ /**
123
+ * @capability integrations-and-marketplace
124
+ */
125
+ declare type MiniAppChannel = {
126
+ roomId: string;
127
+ title?: string;
128
+ kind?: string;
129
+ description?: string;
130
+ visibility: string;
131
+ archived: boolean;
132
+ createdAt: number;
133
+ updatedAt: number;
134
+ };
135
+
136
+ /**
137
+ * One bounded JSON timeline row. The row schema is host-versioned, so callers
138
+ * must narrow it before reading fields.
139
+ */
140
+ declare type MiniAppChannelMessage = MiniAppJsonValue;
141
+
142
+ declare type MiniAppChatApi = {
143
+ /**
144
+ * Select the miniapp's active conversation, reveal the shared chat panel,
145
+ * and place text in its composer without unmounting the miniapp surface.
146
+ */
147
+ sendTextToChat(text: string): MiniAppMaybePromise<void>;
148
+ joinChannelSpecialist?(channelId: string, specialistId: string): MiniAppMaybePromise<null>;
149
+ archiveConversation?(workspaceId: string, userId: string, conversationId: string, projectId: string): MiniAppMaybePromise<null>;
150
+ };
151
+
152
+ declare type MiniAppCreateSpecialistOptions = {
153
+ name: string;
154
+ domain: string;
155
+ description: string | null;
156
+ configuration: MiniAppJsonValue;
157
+ };
158
+
159
+ declare type MiniAppCreateSpecialistResult = {
160
+ id: string;
161
+ name: string;
162
+ domain: string;
163
+ description: string | null;
164
+ isActive: boolean;
165
+ };
166
+
167
+ /** JSON-compatible values accepted by public miniapp operations. */
168
+ declare type MiniAppJsonValue = null | boolean | number | string | MiniAppJsonValue[] | {
169
+ [key: string]: MiniAppJsonValue;
170
+ };
171
+
172
+ /**
173
+ * Author-controlled manifest accepted by the host-managed specialist
174
+ * persistence operation. Ownership, visibility, installation, and verification
175
+ * metadata are derived by the host and cannot be supplied by a miniapp.
176
+ */
177
+ declare type MiniAppManagedSpecialist = {
178
+ id: string;
179
+ slug: string;
180
+ name: string;
181
+ publisher: string;
182
+ description: string;
183
+ icon: string;
184
+ category?: string;
185
+ categoryDisplayName?: string;
186
+ version?: string;
187
+ schemaVersion?: string;
188
+ displayName?: string;
189
+ maintainers?: Array<{
190
+ name: string;
191
+ email: string;
192
+ url?: string;
193
+ }>;
194
+ license?: string;
195
+ lastUpdated?: string;
196
+ fullDescription?: string;
197
+ knowledgeSources?: MiniAppJsonValue[];
198
+ ownedKnowledgePlotId?: string;
199
+ links?: {
200
+ terms?: string;
201
+ privacy?: string;
202
+ website?: string;
203
+ };
204
+ systemPrompt?: string;
205
+ prompts?: MiniAppJsonValue;
206
+ skills?: string[];
207
+ tooling?: MiniAppJsonValue;
208
+ orchestration?: MiniAppJsonValue;
209
+ taskModels?: Record<string, string>;
210
+ knowledgeTargeting?: MiniAppJsonValue;
211
+ tasks?: MiniAppJsonValue[];
212
+ identity?: MiniAppJsonValue;
213
+ audience?: MiniAppJsonValue;
214
+ constraints?: MiniAppJsonValue;
215
+ domainContext?: MiniAppJsonValue;
216
+ purpose?: string;
217
+ values?: MiniAppJsonValue[];
218
+ attributes?: string[];
219
+ techStack?: string[];
220
+ writingStyle?: MiniAppJsonValue;
221
+ tags?: string[];
222
+ preferredModel?: string;
223
+ supportsLocal?: boolean;
224
+ requiresNetwork?: boolean;
225
+ knowledgeGardens?: string[];
226
+ };
227
+
228
+ declare type MiniAppManagedSpecialistResult = {
229
+ specialistId: string;
230
+ };
231
+
232
+ declare type MiniAppMaybePromise<T> = T | Promise<T>;
233
+
234
+ /** Browser view of the public miniapp API. */
235
+ export declare type MiniAppPlatform = MiniAppPlatformApi;
236
+
237
+ export declare type MiniAppPlatformApi = {
238
+ channels: {
239
+ create(options: CreateChannelOptions): CreateChannelResult | Promise<CreateChannelResult>;
240
+ list(options?: ListChannelsOptions): ListChannelsResult | Promise<ListChannelsResult>;
241
+ sendMessage(options: SendChannelMessageOptions): SendChannelMessageResult | Promise<SendChannelMessageResult>;
242
+ /** Persist one deterministic completed row under a joined specialist. */
243
+ sendSpecialistMessage(options: SendChannelSpecialistMessageOptions): SendChannelSpecialistMessageResult | Promise<SendChannelSpecialistMessageResult>;
244
+ getAccess(options: GetChannelAccessOptions): GetChannelAccessResult | Promise<GetChannelAccessResult>;
245
+ getTimeline(options: GetChannelTimelineOptions): GetChannelTimelineResult | Promise<GetChannelTimelineResult>;
246
+ };
247
+ projects: {
248
+ create(options: CreateProjectOptions): CreateProjectResult | Promise<CreateProjectResult>;
249
+ get(options: GetProjectOptions): GetProjectResult | Promise<GetProjectResult>;
250
+ update(options: UpdateProjectOptions): UpdateProjectResult | Promise<UpdateProjectResult>;
251
+ };
252
+ workflows: {
253
+ list(options?: ListWorkflowsOptions): ListWorkflowsResult | Promise<ListWorkflowsResult>;
254
+ invokeSaved<TPayload = unknown>(options: InvokeSavedWorkflowOptions<TPayload>): InvokeWorkflowResult | Promise<InvokeWorkflowResult>;
255
+ invoke?<TPayload = unknown>(options: InvokeWorkflowOptions<TPayload>): InvokeWorkflowResult | Promise<InvokeWorkflowResult>;
256
+ };
257
+ navigation: {
258
+ open(options: OpenNavigationOptions): void | Promise<void>;
259
+ };
260
+ chat: MiniAppChatApi;
261
+ /** Browser capabilities appear only when the selected target supports them. */
262
+ auth?: MiniAppAuthApi;
263
+ vfs?: MiniAppVfsApi;
264
+ specialist?: MiniAppSpecialistApi;
265
+ hasEditorView?: boolean;
266
+ hasHostHttpRequest?: boolean;
267
+ };
268
+
269
+ declare type MiniAppProject = {
270
+ id: string;
271
+ name: string;
272
+ workspaceId: string;
273
+ discoverable: boolean;
274
+ channelIds: string[];
275
+ archivedChannelIds: string[];
276
+ };
277
+
278
+ declare type MiniAppProvisionProjectChatOptions = {
279
+ conversationId: string;
280
+ projectId: string;
281
+ referenceBranch?: string | null;
282
+ };
283
+
284
+ declare type MiniAppProvisionProjectChatResult = {
285
+ mountedRoots: string[];
286
+ worktreeBranch?: string | null;
287
+ worktreeBaseCommit?: string | null;
288
+ };
289
+
290
+ declare type MiniAppSpecialistApi = {
291
+ joinToChannel(channelId: string, specialistId: string): MiniAppMaybePromise<string>;
292
+ listWorkspace(workspaceId: string): MiniAppMaybePromise<MiniAppSpecialistSummary[]>;
293
+ create(options: MiniAppCreateSpecialistOptions): MiniAppMaybePromise<MiniAppCreateSpecialistResult>;
294
+ upsertManaged?(specialist: MiniAppManagedSpecialist): MiniAppMaybePromise<MiniAppManagedSpecialistResult>;
295
+ runTurnWithTools?(options: MiniAppSpecialistTurnOptions): MiniAppMaybePromise<MiniAppSpecialistTurnResult>;
296
+ };
297
+
298
+ declare type MiniAppSpecialistConversationPart = {
299
+ type: 'text';
300
+ content: string;
301
+ } | {
302
+ type: 'tool';
303
+ toolCallId: string;
304
+ toolName: string;
305
+ arguments: MiniAppJsonValue;
306
+ toolIntent: string | null;
307
+ success: boolean;
308
+ content: MiniAppJsonValue;
309
+ mediaCost?: MiniAppJsonValue | null;
310
+ error?: string | null;
311
+ executionTimeMs: number;
312
+ } | {
313
+ type: 'stepEnd';
314
+ iteration: number;
315
+ };
316
+
317
+ declare type MiniAppSpecialistInteractionMode = 'conversational' | 'agentic' | 'planning' | 'background' | 'longRunning' | 'inlineEdit' | 'focus';
318
+
319
+ declare type MiniAppSpecialistSummary = {
320
+ id: string;
321
+ slug: string;
322
+ displayName: string;
323
+ description: string;
324
+ tags: string[];
325
+ version: string;
326
+ availability: 'public' | 'internal' | 'private' | 'restricted';
327
+ canRunLocally: boolean;
328
+ category: string;
329
+ categoryDisplayName: string;
330
+ requiredCapabilities: {
331
+ inputModalities: string[];
332
+ toolUse?: boolean | null;
333
+ reasoning?: boolean | null;
334
+ } | null;
335
+ omnipresence?: {
336
+ autoJoinChannels: boolean;
337
+ includeDms: boolean;
338
+ pinSidebar: boolean;
339
+ } | null;
340
+ displayIcon?: {
341
+ type: 'bundled';
342
+ path: string;
343
+ } | {
344
+ type: 'remote';
345
+ url: string;
346
+ } | null;
347
+ };
348
+
349
+ declare type MiniAppSpecialistTurnOptions = {
350
+ workspaceId: string;
351
+ channelId: string;
352
+ specialistId: string;
353
+ content: string;
354
+ modelOverride: string;
355
+ messageId: null;
356
+ interactionMode: MiniAppSpecialistInteractionMode;
357
+ timeoutMs: number;
358
+ };
359
+
360
+ declare type MiniAppSpecialistTurnResult = {
361
+ completionEvent: {
362
+ parts: MiniAppSpecialistConversationPart[];
363
+ finishReason?: string;
364
+ modelUsed?: string;
365
+ };
366
+ };
367
+
368
+ export declare type MiniAppTheme = 'light' | 'dark';
369
+
370
+ declare type MiniAppUserProfile = {
371
+ sub: string;
372
+ name?: string | null;
373
+ givenName?: string | null;
374
+ familyName?: string | null;
375
+ middleName?: string | null;
376
+ nickname?: string | null;
377
+ preferredUsername?: string | null;
378
+ profile?: string | null;
379
+ picture?: string | null;
380
+ website?: string | null;
381
+ email?: string | null;
382
+ emailVerified?: boolean | null;
383
+ gender?: string | null;
384
+ birthdate?: string | null;
385
+ zoneinfo?: string | null;
386
+ locale?: string | null;
387
+ phoneNumber?: string | null;
388
+ phoneNumberVerified?: boolean | null;
389
+ address?: MiniAppJsonValue | null;
390
+ updatedAt?: string | null;
391
+ };
392
+
393
+ declare type MiniAppVfsApi = {
394
+ provisionProjectChat(options: MiniAppProvisionProjectChatOptions): MiniAppMaybePromise<MiniAppProvisionProjectChatResult>;
395
+ writeFile(conversationId: string, path: string, data: Uint8Array): MiniAppMaybePromise<null>;
396
+ mkdir(conversationId: string, path: string): MiniAppMaybePromise<null>;
397
+ };
398
+
399
+ declare type MiniAppWorkflow = {
400
+ id: string;
401
+ name: string;
402
+ type: string;
403
+ createdAt: number;
404
+ updatedAt: number;
405
+ };
406
+
407
+ /** Requests the host-owned editor capability for this exact miniapp frame. */
408
+ export declare function openEditorProject(options: OpenEditorProjectOptions): Promise<void>;
409
+
410
+ export declare type OpenEditorProjectOptions = {
411
+ conversationId: string;
412
+ files?: Array<{
413
+ path: string;
414
+ selection?: {
415
+ line: number;
416
+ column: number;
417
+ };
418
+ }>;
419
+ mode: 'embedded';
420
+ projectId?: string | null;
421
+ };
422
+
423
+ declare type OpenNavigationOptions = {
424
+ path: string;
425
+ };
426
+
427
+ /** Unknown capabilities fail closed. */
428
+ export declare function platformSatisfiesApp(platform: MiniAppPlatform, requiredCapabilities: readonly string[]): boolean;
429
+
430
+ declare type SendChannelMessageOptions = {
431
+ workspaceId?: string;
432
+ channelId: string;
433
+ /**
434
+ * Optional stable client id for product-owned messages such as seeded
435
+ * lifecycle notices. Omit for ordinary miniapp messages.
436
+ */
437
+ clientMessageId?: string;
438
+ name?: string;
439
+ /** Display body to persist. When omitted, the host formats `name` and `content`. */
440
+ body?: string;
441
+ content: string;
442
+ /** Optional structured chat content persisted with the message. */
443
+ messageContent?: Record<string, MiniAppJsonValue>;
444
+ };
445
+
446
+ declare type SendChannelMessageResult = {
447
+ messageId: string;
448
+ clientMessageId: string;
449
+ };
450
+
451
+ declare type SendChannelSpecialistMessageOptions = {
452
+ workspaceId?: string;
453
+ channelId: string;
454
+ projectId: string;
455
+ specialistId: string;
456
+ clientMessageId: string;
457
+ body: string;
458
+ messageContent?: Record<string, MiniAppJsonValue>;
459
+ };
460
+
461
+ declare type SendChannelSpecialistMessageResult = {
462
+ messageId: string;
463
+ clientMessageId: string;
464
+ };
465
+
466
+ export declare type SpecialistEvent = SpecialistTurnCompletedEvent | SpecialistTurnErrorEvent;
467
+
468
+ export declare type SpecialistTurnCompletedEvent = {
469
+ type: 'turnCompleted';
470
+ channelId: string;
471
+ clientMessageId?: string | null;
472
+ finishReason?: string | null;
473
+ messageId: string | null;
474
+ modelUsed?: string | null;
475
+ parts?: MiniAppSpecialistConversationPart[];
476
+ providerUsed?: string | null;
477
+ specialistId: string;
478
+ totalIterations?: number | null;
479
+ totalTimeMs?: number | null;
480
+ totalToolCalls?: number | null;
481
+ turnId?: string | null;
482
+ };
483
+
484
+ export declare type SpecialistTurnErrorEvent = {
485
+ type: 'turnError';
486
+ channelId: string;
487
+ clientMessageId?: string | null;
488
+ error?: string | null;
489
+ messageId?: string | null;
490
+ specialistId: string;
491
+ turnId?: string | null;
492
+ };
493
+
494
+ declare type UpdateProjectOptions = {
495
+ workspaceId?: string;
496
+ projectId: string;
497
+ name?: string;
498
+ discoverable?: boolean;
499
+ channelIds?: string[];
500
+ archivedChannelIds?: string[];
501
+ };
502
+
503
+ declare type UpdateProjectResult = {
504
+ project: MiniAppProject;
505
+ };
506
+
507
+ export { }
package/dist/web.js ADDED
@@ -0,0 +1,146 @@
1
+ import { sdk } from "./sdk.js";
2
+ function getPlatform() {
3
+ return sdk;
4
+ }
5
+ const PLATFORM_CAPABILITIES = {
6
+ editorView: (platform)=>true === platform.hasEditorView,
7
+ hostHttpRequest: (platform)=>true === platform.hasHostHttpRequest
8
+ };
9
+ function platformSatisfiesApp(platform, requiredCapabilities) {
10
+ return requiredCapabilities.every((capability)=>PLATFORM_CAPABILITIES[capability]?.(platform) ?? false);
11
+ }
12
+ const HOST_ACTION_REQUEST = 'tap-miniapp-host-action';
13
+ const HOST_ACTION_RESPONSE = 'tap-miniapp-host-action-response';
14
+ const OPEN_EDITOR_PROJECT_ACTION = 'tap.editor.open-project';
15
+ const HOST_ACTION_TIMEOUT_MS = 4000;
16
+ const MAX_HOST_ACTION_ID_CHARS = 256;
17
+ const MAX_HOST_ACTION_ERROR_CHARS = 1024;
18
+ const MINIAPP_DOCUMENT_ID_GLOBAL_KEY = 'zephyrcloudio.miniapp.document-id';
19
+ let hostActionSequence = 0;
20
+ function isExactBoundedString(value, maximumLength) {
21
+ return 'string' == typeof value && value.length > 0 && value.length <= maximumLength && value.trim() === value && !/[\u0000-\u001f\u007f]/u.test(value);
22
+ }
23
+ function isRecord(value) {
24
+ return 'object' == typeof value && null !== value;
25
+ }
26
+ function getMiniappDocumentId() {
27
+ const documentId = Reflect.get(globalThis, Symbol.for(MINIAPP_DOCUMENT_ID_GLOBAL_KEY));
28
+ if (!isExactBoundedString(documentId, MAX_HOST_ACTION_ID_CHARS)) throw new Error('The miniapp document identity is unavailable.');
29
+ return documentId;
30
+ }
31
+ function exactOrigin(value) {
32
+ if (!value) return null;
33
+ try {
34
+ const url = new URL(value);
35
+ return 'null' === url.origin || url.username || url.password ? null : url.origin;
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+ function getHostOrigin() {
41
+ const params = new URLSearchParams(window.location.search);
42
+ const referrer = "u" < typeof document ? '' : document.referrer;
43
+ return exactOrigin(params.get('hostOrigin')) ?? exactOrigin(params.get('miniappHostOrigin')) ?? exactOrigin(referrer);
44
+ }
45
+ function getFrameInstanceId() {
46
+ const params = new URLSearchParams(window.location.search);
47
+ const instanceId = params.get('miniappInstanceId') ?? params.get('instanceId') ?? params.get('miniappFrameId');
48
+ return isExactBoundedString(instanceId, MAX_HOST_ACTION_ID_CHARS) ? instanceId : null;
49
+ }
50
+ function createHostActionId() {
51
+ hostActionSequence += 1;
52
+ return `tap-host-action-${hostActionSequence}-${globalThis.crypto?.randomUUID?.() ?? Date.now().toString(36)}`;
53
+ }
54
+ function getHostActionError(value) {
55
+ if (isRecord(value) && isExactBoundedString(value.error, MAX_HOST_ACTION_ERROR_CHARS)) return new Error(value.error);
56
+ return new Error('The miniapp host action failed.');
57
+ }
58
+ function requestHostAction(action, payload) {
59
+ const hostOrigin = getHostOrigin();
60
+ if (!hostOrigin) return Promise.reject(new Error('The miniapp host origin is unavailable.'));
61
+ const instanceId = getFrameInstanceId();
62
+ if (!instanceId) return Promise.reject(new Error('The miniapp frame identity is unavailable.'));
63
+ const documentId = getMiniappDocumentId();
64
+ const parent = window.parent;
65
+ if (!parent || parent === window) return Promise.reject(new Error('The miniapp host is unavailable.'));
66
+ const id = createHostActionId();
67
+ return new Promise((resolve, reject)=>{
68
+ const timeout = setTimeout(()=>{
69
+ cleanup();
70
+ reject(new Error('The miniapp host action timed out.'));
71
+ }, HOST_ACTION_TIMEOUT_MS);
72
+ const handleMessage = (event)=>{
73
+ if (event.source !== parent || event.origin !== hostOrigin) return;
74
+ if (!isRecord(event.data)) return;
75
+ if (event.data.type !== HOST_ACTION_RESPONSE || event.data.id !== id || 'boolean' != typeof event.data.ok) return;
76
+ cleanup();
77
+ if (event.data.ok) resolve(event.data.result);
78
+ else reject(getHostActionError(event.data));
79
+ };
80
+ const cleanup = ()=>{
81
+ clearTimeout(timeout);
82
+ window.removeEventListener('message', handleMessage);
83
+ };
84
+ window.addEventListener('message', handleMessage);
85
+ try {
86
+ parent.postMessage({
87
+ type: HOST_ACTION_REQUEST,
88
+ id,
89
+ action,
90
+ documentId,
91
+ payload,
92
+ instanceId
93
+ }, hostOrigin);
94
+ } catch (error) {
95
+ cleanup();
96
+ reject(error);
97
+ }
98
+ });
99
+ }
100
+ async function openEditorProject(options) {
101
+ if ("u" < typeof window) throw new Error('The miniapp host is unavailable.');
102
+ await requestHostAction(OPEN_EDITOR_PROJECT_ACTION, options);
103
+ }
104
+ const MINIAPP_THEME_CHANGED_EVENTS = new Set([
105
+ 'zephyr-app-theme-changed',
106
+ 'tap-miniapp-theme-changed'
107
+ ]);
108
+ function isMiniAppTheme(value) {
109
+ return 'light' === value || 'dark' === value;
110
+ }
111
+ function readThemeFromSearch(search) {
112
+ const params = 'string' == typeof search ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search) : search;
113
+ const appTheme = params.get('appTheme');
114
+ return isMiniAppTheme(appTheme) ? appTheme : 'light';
115
+ }
116
+ function getMiniAppThemeFromSearch(search = "u" < typeof window ? '' : window.location.search) {
117
+ return readThemeFromSearch(search);
118
+ }
119
+ function applyMiniAppTheme(theme) {
120
+ if ("u" < typeof document) return;
121
+ document.documentElement.dataset.appTheme = theme;
122
+ document.documentElement.classList.toggle('dark', 'dark' === theme);
123
+ document.documentElement.classList.toggle('light', 'light' === theme);
124
+ document.documentElement.style.colorScheme = theme;
125
+ }
126
+ function installMiniAppThemeSync({ applyTheme = applyMiniAppTheme, search } = {}) {
127
+ applyTheme(getMiniAppThemeFromSearch(search));
128
+ if ("u" < typeof window) return ()=>void 0;
129
+ const hostOrigin = getHostOrigin();
130
+ const parent = window.parent;
131
+ if (!hostOrigin || !parent || parent === window) return ()=>void 0;
132
+ const handleMessage = (event)=>{
133
+ if (event.source !== parent || event.origin !== hostOrigin) return;
134
+ const data = event.data;
135
+ if ('object' != typeof data || null === data) return;
136
+ const record = data;
137
+ if ('string' != typeof record.type || !MINIAPP_THEME_CHANGED_EVENTS.has(record.type) || !isMiniAppTheme(record.appTheme)) return;
138
+ applyTheme(record.appTheme);
139
+ };
140
+ window.addEventListener('message', handleMessage);
141
+ return ()=>{
142
+ window.removeEventListener('message', handleMessage);
143
+ };
144
+ }
145
+ export { sdk as app } from "./sdk.js";
146
+ export { applyMiniAppTheme, getMiniAppThemeFromSearch, getPlatform, installMiniAppThemeSync, openEditorProject, platformSatisfiesApp };