@mica-js/widget 0.4.0 → 0.5.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.
@@ -0,0 +1,23 @@
1
+ import { defineRpcService } from "@mica-js/core/rpc";
2
+ //#region src/guest/audio/protocol.ts
3
+ /**
4
+ * Typed RPC contracts of the widget audio path (RFC 0016).
5
+ *
6
+ * Three endpoints carry the whole path:
7
+ *
8
+ * - the guest runtime talks to the `AudioWorklet` over a `MessagePort` it receives from the host;
9
+ * - the host talks to the same worklet over the `AudioWorkletNode` port;
10
+ * - the host pushes availability and the direct port into the guest over the sandbox RPC endpoint.
11
+ *
12
+ * `createRpc` serializes every call, so PCM stays on the worker ↔ worklet port and never passes
13
+ * through the render host.
14
+ */
15
+ /** Name the worklet registers its processor under. */
16
+ var widgetAudioWorkletProcessor = "mica-widget-audio";
17
+ var widgetAudioWorkletService = defineRpcService("audio-worklet");
18
+ var widgetAudioControlService = defineRpcService("audio-control");
19
+ var widgetAudioGuestService = defineRpcService("audio-guest");
20
+ //#endregion
21
+ export { widgetAudioWorkletService as i, widgetAudioGuestService as n, widgetAudioWorkletProcessor as r, widgetAudioControlService as t };
22
+
23
+ //# sourceMappingURL=protocol-BuE4pcSf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-BuE4pcSf.js","names":[],"sources":["../src/guest/audio/protocol.ts"],"sourcesContent":["/**\n * Typed RPC contracts of the widget audio path (RFC 0016).\n *\n * Three endpoints carry the whole path:\n *\n * - the guest runtime talks to the `AudioWorklet` over a `MessagePort` it receives from the host;\n * - the host talks to the same worklet over the `AudioWorkletNode` port;\n * - the host pushes availability and the direct port into the guest over the sandbox RPC endpoint.\n *\n * `createRpc` serializes every call, so PCM stays on the worker ↔ worklet port and never passes\n * through the render host.\n */\n\nimport { defineRpcService } from '@mica-js/core/rpc';\n\n/** Name the worklet registers its processor under. */\nexport const widgetAudioWorkletProcessor = 'mica-widget-audio';\n\n/** Per-instance ceiling on simultaneous tones. */\nexport const defaultMaxVoices = 8;\n/** Per-instance ceiling on open PCM streams. */\nexport const defaultMaxStreams = 4;\n\n/** Availability of the host audio path. */\nexport type WidgetAudioState = 'unavailable' | 'suspended' | 'running';\n\n/** Why a tone or stream stopped. */\nexport type WidgetAudioEndReason =\n 'finished' | 'stopped' | 'dropped' | 'error' | 'unavailable' | 'disposed';\n\n/** Sample layout of a PCM stream. */\nexport type WidgetAudioFormat = 's16' | 'f32';\n\n/** Waveforms the worklet synthesizes for `api.audio.tone()`. */\nexport type WidgetOscillatorType = 'sine' | 'square' | 'triangle' | 'sawtooth';\n\n/** Playback state of a PCM stream, as the guest sees it. */\nexport type WidgetAudioStreamState = 'buffering' | 'playing' | 'ended' | 'closed';\n\n/** Per-instance ceilings; a host may tighten them through its options. */\nexport interface WidgetAudioLimits {\n readonly maxVoices: number;\n readonly maxStreams: number;\n}\n\n/** One mount generation of one instance, opened by the host before the guest can use it. */\nexport interface WidgetAudioSessionOpen {\n /** One-shot token every guest call must carry. */\n readonly session: string;\n /** Guest runtime that owns the token; a port from another runtime is rejected. */\n readonly runtimeId: string;\n readonly instanceId: string;\n readonly maxVoices: number;\n readonly maxStreams: number;\n}\n\nexport interface WidgetAudioToneInit {\n /** Guest-assigned id; unique per session. */\n readonly voiceId: string;\n readonly type: WidgetOscillatorType;\n /** Hz, `(0, 24000]`. */\n readonly frequency: number;\n /** `0`–`1`. */\n readonly volume: number;\n}\n\nexport interface WidgetAudioToneSettings {\n readonly volume?: number;\n readonly frequency?: number;\n /** Smoothing window in milliseconds, `0`–`10000`. */\n readonly rampMs: number;\n}\n\nexport interface WidgetAudioStop {\n /** Fade-out in milliseconds, `0`–`10000`. */\n readonly fadeMs: number;\n}\n\nexport interface WidgetAudioStreamInit {\n /** Guest-assigned id; unique per session. */\n readonly streamId: string;\n /** Source rate in Hz, `8000`–`96000`. */\n readonly sampleRate: number;\n readonly channels: 1 | 2;\n readonly format: WidgetAudioFormat;\n readonly capacityFrames: number;\n readonly startFrames: number;\n readonly volume: number;\n}\n\n/** Answer of `createStream`: the worklet re-checks the per-session quota. */\nexport interface WidgetAudioStreamOpened {\n readonly accepted: boolean;\n}\n\n/** Credit report; `consumedFrames` is cumulative over the stream's lifetime. */\nexport interface WidgetAudioProgress {\n readonly streamId: string;\n readonly consumedFrames: number;\n readonly underruns: number;\n readonly state: WidgetAudioStreamState;\n}\n\n/** Terminal event of one tone or stream. */\nexport interface WidgetAudioEndedMessage {\n readonly target: 'tone' | 'stream';\n readonly id: string;\n readonly reason: WidgetAudioEndReason;\n}\n\n/** Diagnostic codes the audio path reports. */\nexport type WidgetAudioDiagnosticCode = 'widget/audio-failed' | 'widget/audio-limit';\n\n/** Quota or validation class the receiving side dedupes against. */\nexport type WidgetAudioDiagnosticCategory = 'voices' | 'streams' | 'capacity' | 'worklet';\n\nexport interface WidgetAudioDiagnostic {\n /** Session the diagnostic belongs to; the host maps it back to the instance. */\n readonly session: string;\n readonly code: WidgetAudioDiagnosticCode;\n readonly category: WidgetAudioDiagnosticCategory;\n readonly message: string;\n}\n\n/**\n * Guest → worklet.\n *\n * Every member names a session; the worklet checks that the session belongs to the runtime that\n * owns the calling port, so a guest cannot steer another instance.\n */\nexport interface WidgetAudioWorkletService {\n createTone(session: string, init: WidgetAudioToneInit): void;\n setTone(session: string, voiceId: string, settings: WidgetAudioToneSettings): void;\n stopTone(session: string, voiceId: string, options: WidgetAudioStop): void;\n createStream(session: string, init: WidgetAudioStreamInit): WidgetAudioStreamOpened;\n /** `samples` travels as a transferred buffer; `true` means the whole block was accepted. */\n writeStream(session: string, streamId: string, samples: Int16Array | Float32Array): boolean;\n /** Drops everything that has not played yet and keeps the stream open. */\n clearStream(session: string, streamId: string): void;\n /** Drains the buffer, then ends the stream with `finished`. */\n endStream(session: string, streamId: string): void;\n /** Discards the buffer and closes the stream immediately. */\n closeStream(session: string, streamId: string): void;\n onDidProgress(listener: (progress: WidgetAudioProgress) => void): () => void;\n onDidEnded(listener: (ended: WidgetAudioEndedMessage) => void): () => void;\n}\n\nexport const widgetAudioWorkletService =\n defineRpcService<WidgetAudioWorkletService>('audio-worklet');\n\n/** Host → worklet, over the `AudioWorkletNode` port. */\nexport interface WidgetAudioControlService {\n openSession(init: WidgetAudioSessionOpen): void;\n closeSession(session: string): void;\n setSessionVolume(session: string, volume: number): void;\n setMuted(muted: boolean): void;\n suspend(): void;\n resume(): void;\n /** `port` is the guest end of the direct PCM channel; it is always transferred. */\n attachGuestPort(runtimeId: string, port: MessagePort): void;\n detachGuestPort(runtimeId: string): void;\n onDidDiagnostic(listener: (diagnostic: WidgetAudioDiagnostic) => void): () => void;\n}\n\nexport const widgetAudioControlService =\n defineRpcService<WidgetAudioControlService>('audio-control');\n\n/** Host → guest: audio availability and the direct PCM port handoff. */\nexport interface WidgetAudioGuestService {\n attachPort(port: MessagePort): void;\n setState(state: WidgetAudioState): void;\n}\n\nexport const widgetAudioGuestService = defineRpcService<WidgetAudioGuestService>('audio-guest');\n\n/** Attached to `mount` so the factory can read `api.audio.state` synchronously. */\nexport interface WidgetAudioMountInfo {\n readonly state: WidgetAudioState;\n /** One-shot token this mount generation uses on the direct port. */\n readonly session?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAa,8BAA8B;AAmI3C,IAAa,4BACX,iBAA4C,eAAe;AAgB7D,IAAa,4BACX,iBAA4C,eAAe;AAQ7D,IAAa,0BAA0B,iBAA0C,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mica-js/widget",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Mica widget contract and runtime: author definitions, package loading, and sandboxed instance execution",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,6 +11,14 @@
11
11
  "type": "module",
12
12
  "sideEffects": false,
13
13
  "exports": {
14
+ "./audio-host": {
15
+ "types": "./dist/audio-host.d.ts",
16
+ "import": "./dist/audio-host.js"
17
+ },
18
+ "./audio-guest": {
19
+ "types": "./dist/audio-guest.d.ts",
20
+ "import": "./dist/audio-guest.js"
21
+ },
14
22
  ".": {
15
23
  "types": "./dist/index.d.ts",
16
24
  "import": "./dist/index.js"
@@ -32,9 +40,9 @@
32
40
  },
33
41
  "dependencies": {
34
42
  "@mica-js/core": "0.7.0",
35
- "@mica-js/sandbox": "0.5.0",
43
+ "@mica-js/sandbox": "0.5.2",
36
44
  "rolldown": "^1.2.14",
37
- "@mica-js/document": "0.2.0"
45
+ "@mica-js/document": "0.3.0"
38
46
  },
39
47
  "peerDependencies": {
40
48
  "vite": "^8.0.0"