@shiqianjiang/ceru-plugin-sdk 0.3.15 → 3.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.
Files changed (52) hide show
  1. package/README.md +14 -4
  2. package/dist/accounts.d.ts +107 -1
  3. package/dist/accounts.js +14 -0
  4. package/dist/catalog.d.ts +1 -1
  5. package/dist/catalog.js +23 -0
  6. package/dist/crypto-streams.d.ts +10 -0
  7. package/dist/crypto-streams.js +1 -0
  8. package/dist/events.d.ts +21 -0
  9. package/dist/events.js +14 -0
  10. package/dist/hooks.d.ts +211 -0
  11. package/dist/hooks.js +14 -0
  12. package/dist/index.d.ts +55 -22
  13. package/dist/index.js +46 -3
  14. package/dist/legacy-http.d.ts +1 -0
  15. package/dist/legacy-http.js +3 -0
  16. package/dist/lifecycle.d.ts +21 -0
  17. package/dist/lifecycle.js +1 -0
  18. package/dist/links.d.ts +2 -0
  19. package/dist/links.js +25 -0
  20. package/dist/manifest.d.ts +190 -131
  21. package/dist/music-api.d.ts +44 -0
  22. package/dist/music-api.js +1 -0
  23. package/dist/music.js +3 -0
  24. package/dist/navigation.d.ts +17 -0
  25. package/dist/navigation.js +45 -1
  26. package/dist/permissions.d.ts +92 -0
  27. package/dist/permissions.js +23 -0
  28. package/dist/plugins-api.d.ts +16 -0
  29. package/dist/plugins-api.js +1 -0
  30. package/dist/regions.d.ts +76 -0
  31. package/dist/regions.js +9 -0
  32. package/dist/server.d.ts +32 -0
  33. package/dist/server.js +4 -0
  34. package/dist/services.d.ts +48 -24
  35. package/dist/services.js +6 -22
  36. package/dist/streams.d.ts +35 -0
  37. package/dist/streams.js +51 -0
  38. package/dist/validate.d.ts +2 -1
  39. package/dist/validate.js +18 -0
  40. package/dist/view-bridge.d.ts +6 -0
  41. package/dist/view-bridge.js +1 -0
  42. package/dist/view-contracts.d.ts +136 -0
  43. package/dist/view-contracts.js +1 -0
  44. package/dist/vue/index.d.ts +17 -0
  45. package/dist/vue/index.js +74 -0
  46. package/dist/vue/region.d.ts +7 -0
  47. package/dist/vue/region.js +5 -0
  48. package/dist/wasm.d.ts +5 -0
  49. package/dist/wasm.js +1 -0
  50. package/package.json +14 -6
  51. package/dist/host-library.d.ts +0 -29
  52. package/dist/host-library.js +0 -69
@@ -3,10 +3,34 @@ import type { PermissionName } from './catalog.js';
3
3
  import type { PermissionStatus, UserIntentHandle } from './index.js';
4
4
  /** Permission groups are user-facing decisions, not one prompt per method. */
5
5
  export declare const PERMISSION_GROUPS: {
6
+ readonly musicRead: {
7
+ readonly title: "搜索与读取所有已安装音源";
8
+ readonly permissions: readonly ["music.read"];
9
+ };
10
+ readonly musicControl: {
11
+ readonly title: "播放任意音源的歌曲";
12
+ readonly permissions: readonly ["music.control"];
13
+ };
6
14
  readonly network: {
7
15
  readonly title: "访问公网服务";
8
16
  readonly permissions: readonly ["network.request", "network.socket"];
9
17
  };
18
+ readonly localServer: {
19
+ readonly title: "在本机运行网络服务";
20
+ readonly permissions: readonly ["network.serve"];
21
+ };
22
+ readonly lanServer: {
23
+ readonly title: "允许局域网设备访问插件服务";
24
+ readonly permissions: readonly ["network.serve.lan"];
25
+ };
26
+ readonly audioTransform: {
27
+ readonly title: "处理播放器的音频数据流";
28
+ readonly permissions: readonly ["streams.transform"];
29
+ };
30
+ readonly trustedRuntime: {
31
+ readonly title: "在独立进程中运行完全信任的代码";
32
+ readonly permissions: readonly ["runtime.trusted"];
33
+ };
10
34
  readonly localNetwork: {
11
35
  readonly title: "访问局域网与本机服务";
12
36
  readonly permissions: readonly ["network.private", "network.discovery"];
@@ -15,6 +39,34 @@ export declare const PERMISSION_GROUPS: {
15
39
  readonly title: "读取登录状态与基本账号资料";
16
40
  readonly permissions: readonly ["account.profile"];
17
41
  };
42
+ readonly accountIntercept: {
43
+ readonly title: "可以拦截子账号切换";
44
+ readonly permissions: readonly ["account.intercept"];
45
+ };
46
+ readonly libraryIntercept: {
47
+ readonly title: "可以拦截和改变收藏与歌单操作";
48
+ readonly permissions: readonly ["library.intercept"];
49
+ };
50
+ readonly searchIntercept: {
51
+ readonly title: "可以拦截搜索并改写搜索词";
52
+ readonly permissions: readonly ["search.intercept"];
53
+ };
54
+ readonly searchRead: {
55
+ readonly title: "观察搜索操作";
56
+ readonly permissions: readonly ["search.read"];
57
+ };
58
+ readonly linksRead: {
59
+ readonly title: "观察主动打开的公开链接";
60
+ readonly permissions: readonly ["links.read"];
61
+ };
62
+ readonly notificationsRead: {
63
+ readonly title: "观察软件内文字提示";
64
+ readonly permissions: readonly ["notifications.read"];
65
+ };
66
+ readonly windowRead: {
67
+ readonly title: "观察窗口关闭请求";
68
+ readonly permissions: readonly ["window.read"];
69
+ };
18
70
  readonly libraryRead: {
19
71
  readonly title: "读取歌单与收藏";
20
72
  readonly permissions: readonly ["library.read"];
@@ -31,6 +83,18 @@ export declare const PERMISSION_GROUPS: {
31
83
  readonly title: "读取播放状态和队列";
32
84
  readonly permissions: readonly ["player.read"];
33
85
  };
86
+ readonly navigationRead: {
87
+ readonly title: "读取当前页面名称";
88
+ readonly permissions: readonly ["route.read"];
89
+ };
90
+ readonly navigationIntercept: {
91
+ readonly title: "拦截页面跳转";
92
+ readonly permissions: readonly ["navigation.intercept"];
93
+ };
94
+ readonly playbackIntercept: {
95
+ readonly title: "可以拦截和改变你的播放操作,例如切歌、换歌";
96
+ readonly permissions: readonly ["player.intercept"];
97
+ };
34
98
  readonly playbackControl: {
35
99
  readonly title: "控制播放和播放队列";
36
100
  readonly permissions: readonly ["player.control", "playback.fallback.hold"];
@@ -75,6 +139,30 @@ export declare const PERMISSION_GROUPS: {
75
139
  readonly title: "控制软件窗口";
76
140
  readonly permissions: readonly ["window.control"];
77
141
  };
142
+ readonly windowIntercept: {
143
+ readonly title: "可以拦截窗口关闭请求";
144
+ readonly permissions: readonly ["window.intercept"];
145
+ };
146
+ readonly lyricsIntercept: {
147
+ readonly title: "读取和处理当前歌曲的歌词";
148
+ readonly permissions: readonly ["lyrics.intercept"];
149
+ };
150
+ readonly downloadsIntercept: {
151
+ readonly title: "处理下载请求与下载文件名";
152
+ readonly permissions: readonly ["downloads.intercept"];
153
+ };
154
+ readonly sharingIntercept: {
155
+ readonly title: "处理歌曲分享请求与分享链接";
156
+ readonly permissions: readonly ["sharing.intercept"];
157
+ };
158
+ readonly linksIntercept: {
159
+ readonly title: "处理主动粘贴、拖入与打开的公开链接";
160
+ readonly permissions: readonly ["links.intercept"];
161
+ };
162
+ readonly notificationsIntercept: {
163
+ readonly title: "改写或隐藏软件内提示";
164
+ readonly permissions: readonly ["notifications.intercept"];
165
+ };
78
166
  readonly hotkeys: {
79
167
  readonly title: "注册全局快捷键";
80
168
  readonly permissions: readonly ["hotkeys.register"];
@@ -111,6 +199,10 @@ export declare const PERMISSION_GROUPS: {
111
199
  readonly title: "使用本插件已保存的连接凭据";
112
200
  readonly permissions: readonly ["credentials.use"];
113
201
  };
202
+ readonly credentialCapture: {
203
+ readonly title: "从独立登录窗口保存指定网站的登录凭据";
204
+ readonly permissions: readonly ["credentials.capture"];
205
+ };
114
206
  readonly credentialExport: {
115
207
  readonly title: "读取本插件连接凭据明文";
116
208
  readonly permissions: readonly ["credentials.read"];
@@ -1,15 +1,31 @@
1
1
  /** Permission groups are user-facing decisions, not one prompt per method. */
2
2
  export const PERMISSION_GROUPS = {
3
+ musicRead: { title: '搜索与读取所有已安装音源', permissions: ['music.read'] },
4
+ musicControl: { title: '播放任意音源的歌曲', permissions: ['music.control'] },
3
5
  network: { title: '访问公网服务', permissions: ['network.request', 'network.socket'] },
6
+ localServer: { title: '在本机运行网络服务', permissions: ['network.serve'] },
7
+ lanServer: { title: '允许局域网设备访问插件服务', permissions: ['network.serve.lan'] },
8
+ audioTransform: { title: '处理播放器的音频数据流', permissions: ['streams.transform'] },
9
+ trustedRuntime: { title: '在独立进程中运行完全信任的代码', permissions: ['runtime.trusted'] },
4
10
  localNetwork: {
5
11
  title: '访问局域网与本机服务',
6
12
  permissions: ['network.private', 'network.discovery'],
7
13
  },
8
14
  account: { title: '读取登录状态与基本账号资料', permissions: ['account.profile'] },
15
+ accountIntercept: { title: '可以拦截子账号切换', permissions: ['account.intercept'] },
16
+ libraryIntercept: { title: '可以拦截和改变收藏与歌单操作', permissions: ['library.intercept'] },
17
+ searchIntercept: { title: '可以拦截搜索并改写搜索词', permissions: ['search.intercept'] },
18
+ searchRead: { title: '观察搜索操作', permissions: ['search.read'] },
19
+ linksRead: { title: '观察主动打开的公开链接', permissions: ['links.read'] },
20
+ notificationsRead: { title: '观察软件内文字提示', permissions: ['notifications.read'] },
21
+ windowRead: { title: '观察窗口关闭请求', permissions: ['window.read'] },
9
22
  libraryRead: { title: '读取歌单与收藏', permissions: ['library.read'] },
10
23
  libraryManage: { title: '创建和修改歌单与收藏', permissions: ['library.write'] },
11
24
  libraryDelete: { title: '删除歌单与歌曲记录', permissions: ['library.delete'] },
12
25
  playbackRead: { title: '读取播放状态和队列', permissions: ['player.read'] },
26
+ navigationRead: { title: '读取当前页面名称', permissions: ['route.read'] },
27
+ navigationIntercept: { title: '拦截页面跳转', permissions: ['navigation.intercept'] },
28
+ playbackIntercept: { title: '可以拦截和改变你的播放操作,例如切歌、换歌', permissions: ['player.intercept'] },
13
29
  playbackControl: {
14
30
  title: '控制播放和播放队列',
15
31
  permissions: ['player.control', 'playback.fallback.hold'],
@@ -27,6 +43,12 @@ export const PERMISSION_GROUPS = {
27
43
  settingsRead: { title: '读取软件偏好', permissions: ['settings.read'] },
28
44
  settingsWrite: { title: '修改软件偏好', permissions: ['settings.write'] },
29
45
  window: { title: '控制软件窗口', permissions: ['window.control'] },
46
+ windowIntercept: { title: '可以拦截窗口关闭请求', permissions: ['window.intercept'] },
47
+ lyricsIntercept: { title: '读取和处理当前歌曲的歌词', permissions: ['lyrics.intercept'] },
48
+ downloadsIntercept: { title: '处理下载请求与下载文件名', permissions: ['downloads.intercept'] },
49
+ sharingIntercept: { title: '处理歌曲分享请求与分享链接', permissions: ['sharing.intercept'] },
50
+ linksIntercept: { title: '处理主动粘贴、拖入与打开的公开链接', permissions: ['links.intercept'] },
51
+ notificationsIntercept: { title: '改写或隐藏软件内提示', permissions: ['notifications.intercept'] },
30
52
  hotkeys: { title: '注册全局快捷键', permissions: ['hotkeys.register'] },
31
53
  sharing: { title: '发布和撤销分享', permissions: ['sharing.publish', 'sharing.revoke'] },
32
54
  roomsRead: { title: '读取一起听房间状态', permissions: ['rooms.read'] },
@@ -36,6 +58,7 @@ export const PERMISSION_GROUPS = {
36
58
  uiAppearance: { title: '修改软件全局外观', permissions: ['ui.styles.global'] },
37
59
  background: { title: '后台任务', permissions: ['background.run'] },
38
60
  credentials: { title: '使用本插件已保存的连接凭据', permissions: ['credentials.use'] },
61
+ credentialCapture: { title: '从独立登录窗口保存指定网站的登录凭据', permissions: ['credentials.capture'] },
39
62
  credentialExport: { title: '读取本插件连接凭据明文', permissions: ['credentials.read'] },
40
63
  guestPlugins: { title: '安装和运行兼容子插件', permissions: ['guests.manage', 'guests.run'] },
41
64
  services: { title: '调用其他插件提供的服务', permissions: ['services.consume'] },
@@ -0,0 +1,16 @@
1
+ import type { JsonValue, OperationContext, ServiceDeclaration } from './index.js';
2
+ export type ServiceHandler = (input: JsonValue, call: {
3
+ callerPluginId: string;
4
+ operation: OperationContext;
5
+ }) => JsonValue | void | Promise<JsonValue | void>;
6
+ export interface PluginsAPI {
7
+ use<T = Record<string, (input: JsonValue) => Promise<JsonValue>>>(pluginId: string, service: string): Promise<T | null>;
8
+ list(): Promise<{
9
+ pluginId: string;
10
+ services: ServiceDeclaration[];
11
+ }[]>;
12
+ on(event: 'available' | 'unavailable', handler: (info: {
13
+ pluginId: string;
14
+ service: string;
15
+ }) => void): () => void;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import type { LyricLine } from './music.js';
2
+ export declare const PLAYER_REGIONS: readonly ["player.lyrics", "player.artwork", "player.background", "player.visualizer", "player.songInfo", "player.stage", "desktopLyric"];
3
+ export type PlayerRegion = typeof PLAYER_REGIONS[number];
4
+ export declare function parsePlayerRegion(value: string): {
5
+ name: PlayerRegion;
6
+ version: number;
7
+ } | null;
8
+ type Live<Value> = {
9
+ readonly value: Value;
10
+ };
11
+ type DeepReadonly<Value> = Value extends object ? {
12
+ readonly [Key in keyof Value]: DeepReadonly<Value[Key]>;
13
+ } : Value;
14
+ export type RegionJsonValue = null | string | number | boolean | RegionJsonObject | readonly RegionJsonValue[];
15
+ export interface RegionJsonObject {
16
+ readonly [key: string]: RegionJsonValue;
17
+ }
18
+ export interface RegionTrack {
19
+ readonly title: string;
20
+ readonly artists: readonly string[];
21
+ readonly album?: string;
22
+ readonly durationMs?: number;
23
+ }
24
+ interface PlayerProps {
25
+ readonly track: RegionTrack | null;
26
+ readonly currentTime: Live<number>;
27
+ readonly playing: Live<boolean>;
28
+ readonly palette: Readonly<{
29
+ accent: string;
30
+ foreground: string;
31
+ background: string;
32
+ }>;
33
+ readonly layout: 'cd' | 'cover';
34
+ readonly forward: RegionJsonObject;
35
+ }
36
+ interface LyricsProps {
37
+ readonly lines: DeepReadonly<LyricLine[]>;
38
+ }
39
+ interface ArtworkProps {
40
+ readonly artwork: string | null;
41
+ }
42
+ interface SpectrumProps {
43
+ readonly spectrum: Readonly<Float32Array>;
44
+ }
45
+ interface DesktopProps {
46
+ readonly current: DeepReadonly<LyricLine> | null;
47
+ readonly next: DeepReadonly<LyricLine> | null;
48
+ readonly locked: Live<boolean>;
49
+ }
50
+ export interface RegionProps {
51
+ 'player.lyrics': PlayerProps & LyricsProps;
52
+ 'player.artwork': PlayerProps & ArtworkProps;
53
+ 'player.background': PlayerProps & ArtworkProps & SpectrumProps;
54
+ 'player.visualizer': PlayerProps & SpectrumProps;
55
+ 'player.songInfo': PlayerProps;
56
+ 'player.stage': PlayerProps & LyricsProps & ArtworkProps & SpectrumProps;
57
+ desktopLyric: PlayerProps & DesktopProps;
58
+ }
59
+ export interface RegionContext<Name extends PlayerRegion> {
60
+ readonly size: Live<Readonly<{
61
+ width: number;
62
+ height: number;
63
+ }>>;
64
+ readonly name: Name;
65
+ readonly version: 1;
66
+ readonly props: RegionProps[Name];
67
+ readonly settings: RegionJsonObject;
68
+ readonly actions: Name extends 'player.lyrics' | 'player.stage' ? {
69
+ seek(milliseconds: number): Promise<void>;
70
+ } : Readonly<Record<string, never>>;
71
+ onFrame(callback: (timestamp: number) => void): () => void;
72
+ }
73
+ export type MountedRegion = {
74
+ [Name in PlayerRegion]: RegionContext<Name>;
75
+ }[PlayerRegion];
76
+ export {};
@@ -0,0 +1,9 @@
1
+ export const PLAYER_REGIONS = ['player.lyrics', 'player.artwork', 'player.background',
2
+ 'player.visualizer', 'player.songInfo', 'player.stage', 'desktopLyric'];
3
+ export function parsePlayerRegion(value) {
4
+ const match = /^([A-Za-z.]+)(?:@([1-9]\d*))?$/.exec(value);
5
+ if (!match || !PLAYER_REGIONS.includes(match[1]))
6
+ return null;
7
+ const version = Number(match[2] ?? 1);
8
+ return Number.isSafeInteger(version) ? { name: match[1], version } : null;
9
+ }
@@ -0,0 +1,32 @@
1
+ import type { MaybePromise } from './manifest.js';
2
+ import type { Disposable } from './manifest.js';
3
+ import type { PluginContext } from './index.js';
4
+ /** Use an explicit context type for trusted Node entries supplied by the Host. */
5
+ export type ServerEntry<Context = PluginContext> = (ctx: Context) => MaybePromise<void | Disposable>;
6
+ /** Identity helper shared by sandbox and explicitly typed trusted server entries. */
7
+ export declare function defineServer<Context = PluginContext>(entry: ServerEntry<Context>): ServerEntry<Context>;
8
+ /** The handler and its Web streams stay inside the plugin's sandbox. */
9
+ export type ServerHandler = (request: Request) => MaybePromise<Response>;
10
+ export interface ServerOptions {
11
+ port?: number;
12
+ lan?: boolean;
13
+ permissionKey?: string;
14
+ lanPermissionKey?: string;
15
+ }
16
+ export interface ServerHandle {
17
+ readonly url: string;
18
+ readonly port: number;
19
+ /** Stops the listener and cancels its outstanding requests. Idempotent. */
20
+ close(): Promise<void>;
21
+ }
22
+ export interface ServerAPI {
23
+ /** Current sandbox or trusted server address; undefined while stopped. */
24
+ readonly url: string | undefined;
25
+ readonly port: number | undefined;
26
+ /**
27
+ * Starts one HTTP listener per plugin. The Host checks network.serve and any
28
+ * additional LAN permission. Bodies stream in chunks of at most 1 MiB;
29
+ * no more than eight requests may be active in a sandbox at once.
30
+ */
31
+ serve(handler: ServerHandler, options?: ServerOptions): Promise<ServerHandle>;
32
+ }
package/dist/server.js ADDED
@@ -0,0 +1,4 @@
1
+ /** Identity helper shared by sandbox and explicitly typed trusted server entries. */
2
+ export function defineServer(entry) {
3
+ return entry;
4
+ }
@@ -4,6 +4,18 @@ import type { LibraryPlaylist, PlaylistReference } from './library.js';
4
4
  import type { LyricsDocument } from './music.js';
5
5
  import type { PermissionGroup } from './permissions.js';
6
6
  import type { HostNavigationRequest } from './navigation.js';
7
+ import type { OperationInputs, ShareOperationResult } from './hooks.js';
8
+ import type { PermissionName } from './catalog.js';
9
+ export type CallableOperation = 'track.like' | 'player.play' | 'player.next' | 'player.pause' | 'player.resume' | 'player.previous' | 'player.seek' | 'player.setVolume' | 'player.setMode' | 'queue.add' | 'queue.remove' | 'queue.clear' | 'download.create' | 'share.create' | 'notification.show' | 'link.open' | 'window.close' | 'playlist.create' | 'playlist.delete' | 'playlist.addTracks' | 'playlist.removeTracks' | 'playlist.import' | 'playlist.export';
10
+ export type OperationToolResult<Name extends CallableOperation> = Name extends 'share.create' ? ShareOperationResult | null : null;
11
+ export interface OperationTool {
12
+ name: CallableOperation;
13
+ description: string;
14
+ inputSchema: JsonObject;
15
+ outputSchema: JsonObject;
16
+ /** null means the operation needs no additional grant (for example an in-app toast). */
17
+ permission: PermissionName | null;
18
+ }
7
19
  /** Supplied by Host actions/events. Never construct trusted intents from plugin JSON. */
8
20
  export interface ServiceCall {
9
21
  operation: OperationContext;
@@ -97,8 +109,37 @@ export interface AppInfo {
97
109
  theme: 'light' | 'dark';
98
110
  hostApi: string;
99
111
  }
112
+ export interface ListeningTrack {
113
+ title: string;
114
+ artist: string;
115
+ source: string;
116
+ }
100
117
  export interface HostServiceEvents {
101
- 'account.changed': AccountSession;
118
+ 'entries.selectionChanged': import('./manifest.js').SourceSelection;
119
+ 'player.progress': {
120
+ positionMs: number;
121
+ durationMs: number;
122
+ };
123
+ 'track.started': {
124
+ track: ListeningTrack;
125
+ };
126
+ 'track.finished': {
127
+ track: ListeningTrack;
128
+ playedMs: number;
129
+ completed: boolean;
130
+ };
131
+ 'route.changed': {
132
+ from: string | null;
133
+ to: string | null;
134
+ };
135
+ 'account.changed': AccountSession & {
136
+ accountId?: string;
137
+ connectionId?: string | null;
138
+ };
139
+ 'account.expired': {
140
+ accountId: string;
141
+ connectionId: string;
142
+ };
102
143
  'library.changed': {
103
144
  target: PlaylistReference;
104
145
  reason: 'created' | 'updated' | 'deleted' | 'synced';
@@ -119,7 +160,7 @@ export interface HostServiceEvents {
119
160
  keys: string[];
120
161
  };
121
162
  }
122
- export declare const HOST_SERVICE_EVENT_NAMES: readonly ["account.changed", "library.changed", "player.changed", "queue.changed", "lyrics.changed", "downloads.changed", "settings.changed", "theme.changed", "rooms.changed", "devices.changed", "permissions.changed"];
163
+ export declare const HOST_SERVICE_EVENT_NAMES: readonly ["entries.selectionChanged", "player.progress", "track.started", "track.finished", "route.changed", "account.changed", "account.expired", "library.changed", "player.changed", "queue.changed", "lyrics.changed", "downloads.changed", "settings.changed", "theme.changed", "rooms.changed", "devices.changed", "permissions.changed"];
123
164
  /** Contract first: availability must be checked before using services not connected by this Host. */
124
165
  export interface HostServices {
125
166
  capabilities: {
@@ -133,6 +174,10 @@ export interface HostServices {
133
174
  openLogin(operation: OperationContext): Promise<void>;
134
175
  };
135
176
  app: {
177
+ operations: {
178
+ list(): Promise<OperationTool[]>;
179
+ };
180
+ call<Name extends CallableOperation>(name: Name, input: OperationInputs[Name], call: ServiceCall): Promise<OperationToolResult<Name>>;
136
181
  getInfo(): Promise<AppInfo>;
137
182
  openSettings(section?: string): Promise<void>;
138
183
  openExternal(url: string, call: ServiceCall): Promise<void>;
@@ -264,6 +309,7 @@ export interface HostServices {
264
309
  cancel(id: string, call: ServiceCall): Promise<void>;
265
310
  };
266
311
  events: {
312
+ on<K extends import('./events.js').OperationEventName>(event: K, listener: (value: import('./events.js').OperationEvent<K>) => void | Promise<void>): Disposable;
267
313
  on<K extends keyof HostServiceEvents>(event: K, listener: (value: HostServiceEvents[K]) => void, call?: ServiceCall): Disposable;
268
314
  };
269
315
  }
@@ -320,26 +366,4 @@ export interface MenuContribution {
320
366
  loggedIn?: boolean;
321
367
  };
322
368
  }
323
- /** Explicit allowlist for future Core routing; never forward arbitrary IPC channel names. */
324
- export declare const HOST_SERVICE_METHODS: {
325
- readonly capabilities: readonly ["list", "get"];
326
- readonly account: readonly ["getSession", "getProfile", "openLogin"];
327
- readonly app: readonly ["getInfo", "openSettings", "openExternal"];
328
- readonly player: readonly ["getState", "play", "pause", "next", "previous", "seek", "setVolume", "setMode"];
329
- readonly queue: readonly ["get", "append", "replace", "remove", "reorder"];
330
- readonly favorites: readonly ["contains", "add", "remove"];
331
- readonly history: readonly ["list"];
332
- readonly downloads: readonly ["list", "create", "pause", "resume", "cancel", "retry", "reveal"];
333
- readonly files: readonly ["pick", "pickDirectory", "readText", "readBase64", "saveText", "writeText"];
334
- readonly clipboard: readonly ["readText", "writeText"];
335
- readonly localMusic: readonly ["list", "scan", "getTags", "writeTags"];
336
- readonly settings: readonly ["get", "update"];
337
- readonly window: readonly ["control"];
338
- readonly hotkeys: readonly ["register"];
339
- readonly sharing: readonly ["create", "revoke", "resolve"];
340
- readonly rooms: readonly ["getState", "join", "leave", "requestTrack"];
341
- readonly devices: readonly ["list", "select"];
342
- readonly ai: readonly ["generate"];
343
- readonly tasks: readonly ["schedule", "cancel"];
344
- };
345
369
  export type SerializedHostValue = JsonValue | AssetHandle;
package/dist/services.js CHANGED
@@ -1,5 +1,11 @@
1
1
  export const HOST_SERVICE_EVENT_NAMES = [
2
+ 'entries.selectionChanged',
3
+ 'player.progress',
4
+ 'track.started',
5
+ 'track.finished',
6
+ 'route.changed',
2
7
  'account.changed',
8
+ 'account.expired',
3
9
  'library.changed',
4
10
  'player.changed',
5
11
  'queue.changed',
@@ -11,25 +17,3 @@ export const HOST_SERVICE_EVENT_NAMES = [
11
17
  'devices.changed',
12
18
  'permissions.changed',
13
19
  ];
14
- /** Explicit allowlist for future Core routing; never forward arbitrary IPC channel names. */
15
- export const HOST_SERVICE_METHODS = {
16
- capabilities: ['list', 'get'],
17
- account: ['getSession', 'getProfile', 'openLogin'],
18
- app: ['getInfo', 'openSettings', 'openExternal'],
19
- player: ['getState', 'play', 'pause', 'next', 'previous', 'seek', 'setVolume', 'setMode'],
20
- queue: ['get', 'append', 'replace', 'remove', 'reorder'],
21
- favorites: ['contains', 'add', 'remove'],
22
- history: ['list'],
23
- downloads: ['list', 'create', 'pause', 'resume', 'cancel', 'retry', 'reveal'],
24
- files: ['pick', 'pickDirectory', 'readText', 'readBase64', 'saveText', 'writeText'],
25
- clipboard: ['readText', 'writeText'],
26
- localMusic: ['list', 'scan', 'getTags', 'writeTags'],
27
- settings: ['get', 'update'],
28
- window: ['control'],
29
- hotkeys: ['register'],
30
- sharing: ['create', 'revoke', 'resolve'],
31
- rooms: ['getState', 'join', 'leave', 'requestTrack'],
32
- devices: ['list', 'select'],
33
- ai: ['generate'],
34
- tasks: ['schedule', 'cancel'],
35
- };
@@ -0,0 +1,35 @@
1
+ import type { JsonObject, MaybePromise } from './manifest.js';
2
+ export type StreamAlgorithm = 'aes-128-ctr' | 'aes-256-ctr' | 'aes-128-cbc' | 'aes-256-cbc' | 'chacha20';
3
+ export interface StreamMetadata {
4
+ contentType?: string;
5
+ /** Plaintext byte length, including any audio headers. */
6
+ contentLength?: number;
7
+ }
8
+ export type StreamSpec = StreamMetadata & ({
9
+ decrypt: {
10
+ algorithm: StreamAlgorithm;
11
+ key: string;
12
+ iv: string;
13
+ encoding?: 'hex' | 'base64';
14
+ };
15
+ } | {
16
+ transform: string;
17
+ info?: JsonObject;
18
+ });
19
+ export interface StreamTransform {
20
+ transform(chunk: Uint8Array): MaybePromise<Uint8Array>;
21
+ flush?(): MaybePromise<Uint8Array | void>;
22
+ dispose?(): MaybePromise<void>;
23
+ }
24
+ export interface StreamTransformFactory {
25
+ seekable: boolean;
26
+ create(input: {
27
+ offset: number;
28
+ info?: JsonObject;
29
+ signal?: AbortSignal;
30
+ }): MaybePromise<StreamTransform>;
31
+ }
32
+ export interface StreamsAPI {
33
+ registerTransform(id: string, factory: StreamTransformFactory): () => void;
34
+ }
35
+ export declare function assertStreamSpec(value: unknown): asserts value is StreamSpec;
@@ -0,0 +1,51 @@
1
+ export function assertStreamSpec(value) {
2
+ const record = (row) => !!row && typeof row === 'object' && !Array.isArray(row);
3
+ if (!record(value) ||
4
+ Object.keys(value).some((key) => !['decrypt', 'transform', 'info', 'contentType', 'contentLength'].includes(key)))
5
+ throw Error('Invalid stream specification');
6
+ if (value.contentType !== undefined &&
7
+ (typeof value.contentType !== 'string' ||
8
+ value.contentType.length > 256 ||
9
+ !/^[\w!#$&^.+-]+\/[\w!#$&^.+-]+(?:;[\x20-\x7e]*)?$/.test(value.contentType)))
10
+ throw Error('Invalid stream content type');
11
+ if (value.contentLength !== undefined &&
12
+ (!Number.isSafeInteger(value.contentLength) || value.contentLength < 0))
13
+ throw Error('Invalid stream content length');
14
+ if (value.decrypt !== undefined) {
15
+ const row = value.decrypt;
16
+ if (value.transform !== undefined ||
17
+ value.info !== undefined ||
18
+ !record(row) ||
19
+ Object.keys(row).some((key) => !['algorithm', 'key', 'iv', 'encoding'].includes(key)))
20
+ throw Error('Invalid stream decryption');
21
+ if (!['aes-128-ctr', 'aes-256-ctr', 'aes-128-cbc', 'aes-256-cbc', 'chacha20'].includes(row.algorithm))
22
+ throw Error('Invalid stream algorithm');
23
+ const keyBytes = row.algorithm.startsWith('aes-128') ? 16 : 32;
24
+ if (row.encoding !== undefined && !['hex', 'base64'].includes(row.encoding))
25
+ throw Error('Invalid stream encoding');
26
+ for (const [name, bytes] of [
27
+ ['key', keyBytes],
28
+ ['iv', 16],
29
+ ]) {
30
+ const text = row[name];
31
+ const symbols = Math.floor(bytes / 3) * 4 + (bytes % 3 ? (bytes % 3) + 1 : 0);
32
+ const valid = typeof text === 'string' &&
33
+ ((row.encoding ?? 'hex') === 'hex'
34
+ ? new RegExp('^[a-fA-F0-9]{' + bytes * 2 + '}$').test(text)
35
+ : new RegExp('^[A-Za-z0-9+/]{' +
36
+ symbols +
37
+ '}' +
38
+ (bytes % 3 ? '='.repeat(3 - (bytes % 3)) : '') +
39
+ '$').test(text));
40
+ if (!valid)
41
+ throw Error('Invalid stream ' + name);
42
+ }
43
+ }
44
+ else {
45
+ if (typeof value.transform !== 'string' || !/^[\w.-]{1,128}$/.test(value.transform))
46
+ throw Error('Invalid stream transform');
47
+ if (value.info !== undefined &&
48
+ (!record(value.info) || new TextEncoder().encode(JSON.stringify(value.info)).length > 65536))
49
+ throw Error('Invalid stream transform info');
50
+ }
51
+ }
@@ -1,4 +1,5 @@
1
- import type { ContentEntity } from './index.js';
1
+ import type { ContentEntity, SearchRequest } from './index.js';
2
+ export declare function assertSearchRequest(value: unknown): asserts value is SearchRequest;
2
3
  /**
3
4
  * Reject anything that is not a plain track list before a destructive call.
4
5
  * Hosts pass untrusted renderer input here, so this must not depend on the
package/dist/validate.js CHANGED
@@ -1,3 +1,21 @@
1
+ export function assertSearchRequest(value) {
2
+ const request = value;
3
+ if (!request ||
4
+ typeof request.query !== 'string' ||
5
+ request.query.length > 4096 ||
6
+ !Array.isArray(request.kinds) ||
7
+ request.kinds.length > 32 ||
8
+ !request.kinds.every((kind) => typeof kind === 'string' && kind.length > 0 && kind.length <= 128) ||
9
+ !request.filters ||
10
+ typeof request.filters !== 'object' ||
11
+ Array.isArray(request.filters) ||
12
+ (request.cursor !== undefined &&
13
+ (typeof request.cursor !== 'string' || request.cursor.length > 2048)) ||
14
+ !Number.isSafeInteger(request.limit) ||
15
+ request.limit < 1 ||
16
+ request.limit > 1000)
17
+ throw new Error('Invalid music search request');
18
+ }
1
19
  /**
2
20
  * Reject anything that is not a plain track list before a destructive call.
3
21
  * Hosts pass untrusted renderer input here, so this must not depend on the
@@ -0,0 +1,6 @@
1
+ export type * from './view-contracts.js';
2
+ export interface ViewDeps {
3
+ vue: typeof import('vue');
4
+ tdesign: typeof import('tdesign-vue-next');
5
+ sdk: typeof import('./vue/index.js');
6
+ }
@@ -0,0 +1 @@
1
+ export {};