@lubomirklimes/character-runtime 0.0.0-stage → 0.1.0-preview.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/dist/acs/acs15.d.ts +9 -0
  4. package/dist/acs/acs15.js +382 -0
  5. package/dist/acs/acs2-reader.d.ts +2 -0
  6. package/dist/acs/acs2-reader.js +277 -0
  7. package/dist/acs/binary.d.ts +1 -0
  8. package/dist/acs/binary.js +107 -0
  9. package/dist/acs/compound-file.d.ts +1 -0
  10. package/dist/acs/compound-file.js +326 -0
  11. package/dist/acs/document.d.ts +33 -0
  12. package/dist/acs/document.js +99 -0
  13. package/dist/acs/errors.d.ts +28 -0
  14. package/dist/acs/errors.js +41 -0
  15. package/dist/acs/image.d.ts +30 -0
  16. package/dist/acs/image.js +113 -0
  17. package/dist/acs/index.d.ts +11 -0
  18. package/dist/acs/index.js +10 -0
  19. package/dist/acs/lz.d.ts +7 -0
  20. package/dist/acs/lz.js +102 -0
  21. package/dist/acs/metadata.d.ts +14 -0
  22. package/dist/acs/metadata.js +126 -0
  23. package/dist/acs/model.d.ts +130 -0
  24. package/dist/acs/model.js +12 -0
  25. package/dist/acs/mouth.d.ts +37 -0
  26. package/dist/acs/mouth.js +43 -0
  27. package/dist/acs/wave.d.ts +53 -0
  28. package/dist/acs/wave.js +422 -0
  29. package/dist/browser/animation-frame-clock.d.ts +18 -0
  30. package/dist/browser/animation-frame-clock.js +42 -0
  31. package/dist/browser/canvas-renderer.d.ts +50 -0
  32. package/dist/browser/canvas-renderer.js +145 -0
  33. package/dist/browser/host.d.ts +84 -0
  34. package/dist/browser/host.js +206 -0
  35. package/dist/browser/index.d.ts +6 -0
  36. package/dist/browser/index.js +8 -0
  37. package/dist/browser/web-audio.d.ts +48 -0
  38. package/dist/browser/web-audio.js +205 -0
  39. package/dist/browser/web-speech.d.ts +131 -0
  40. package/dist/browser/web-speech.js +302 -0
  41. package/dist/core/activities.d.ts +10 -0
  42. package/dist/core/activities.js +479 -0
  43. package/dist/core/agent.d.ts +263 -0
  44. package/dist/core/agent.js +764 -0
  45. package/dist/core/audio.d.ts +17 -0
  46. package/dist/core/audio.js +174 -0
  47. package/dist/core/balloon.d.ts +43 -0
  48. package/dist/core/balloon.js +94 -0
  49. package/dist/core/clock.d.ts +32 -0
  50. package/dist/core/clock.js +51 -0
  51. package/dist/core/compositor.d.ts +22 -0
  52. package/dist/core/compositor.js +67 -0
  53. package/dist/core/events.d.ts +131 -0
  54. package/dist/core/events.js +1 -0
  55. package/dist/core/host.d.ts +29 -0
  56. package/dist/core/host.js +77 -0
  57. package/dist/core/index.d.ts +16 -0
  58. package/dist/core/index.js +13 -0
  59. package/dist/core/lipsync.d.ts +41 -0
  60. package/dist/core/lipsync.js +209 -0
  61. package/dist/core/random.d.ts +52 -0
  62. package/dist/core/random.js +105 -0
  63. package/dist/core/request.d.ts +68 -0
  64. package/dist/core/request.js +131 -0
  65. package/dist/core/resources.d.ts +70 -0
  66. package/dist/core/resources.js +243 -0
  67. package/dist/core/scheduler.d.ts +25 -0
  68. package/dist/core/scheduler.js +766 -0
  69. package/dist/core/source.d.ts +21 -0
  70. package/dist/core/source.js +54 -0
  71. package/dist/core/speech.d.ts +91 -0
  72. package/dist/core/speech.js +86 -0
  73. package/dist/core/text.d.ts +38 -0
  74. package/dist/core/text.js +97 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.js +4 -0
  77. package/package.json +68 -4
@@ -0,0 +1,263 @@
1
+ import type { RgbaImage } from '../acs/image.js';
2
+ import type { Character } from '../acs/model.js';
3
+ import { type IdleOptions } from './activities.js';
4
+ import { type AudioLimits, type AudioOutput } from './audio.js';
5
+ import { type BalloonState, type Point } from './balloon.js';
6
+ import { type Clock } from './clock.js';
7
+ import type { AgentEvent, AgentVisibility } from './events.js';
8
+ import type { LipSyncSource } from './lipsync.js';
9
+ import { type RandomSource } from './random.js';
10
+ import { AgentRequest } from './request.js';
11
+ import { CharacterResources, type ResourceBudget } from './resources.js';
12
+ import { type RequestKind } from './scheduler.js';
13
+ import type { CharacterSource } from './source.js';
14
+ import { type SpeechContent, type SpeechProvider, type SpeechVoiceDecision } from './speech.js';
15
+ /** Balloon pacing and dismissal settings (Runtime.md §14). */
16
+ export interface BalloonOptions {
17
+ /** Reading time per text element without speech timing (default 45 ms). */
18
+ readonly characterMs?: number;
19
+ /** Additional reading time per word (default 120 ms). */
20
+ readonly wordMs?: number;
21
+ /** Shortest paced duration of one Speak/Think without audio (default 1,200 ms). */
22
+ readonly minimumMs?: number;
23
+ /** How long an auto-hiding balloon stays after its request completed (default 1,500 ms). */
24
+ readonly hideDelayMs?: number;
25
+ /** Longest accepted text in UTF-16 code units (default 4,096). */
26
+ readonly maxTextLength?: number;
27
+ }
28
+ /** Session settings of a {@link CharacterAgent}. Nothing here is written into the character file. */
29
+ export interface AgentOptions {
30
+ /** The time source (default: a new {@link SystemClock}; agents of a host use the host's clock). */
31
+ readonly clock?: Clock;
32
+ /** Seed of the agent's random generator (ignored when `random` is set). Default 0. */
33
+ readonly seed?: number | bigint;
34
+ readonly random?: RandomSource;
35
+ /** Creates the sound-effect output. Default: effects are timed but not heard. */
36
+ readonly audio?: () => AudioOutput;
37
+ /** Creates the speech output (a second voice). Default: `audio`. */
38
+ readonly speechAudio?: () => AudioOutput;
39
+ /** Frame sound effects play and extend requests (default true). */
40
+ readonly soundEffects?: boolean;
41
+ readonly speech?: SpeechProvider | null;
42
+ /** Explicit voice id for this session (default: chosen by the character's TTS language and gender). */
43
+ readonly voiceId?: string | null;
44
+ /** Speak synthesizes audio; unset follows the character's Style TTS bit. */
45
+ readonly speechEnabled?: boolean | null;
46
+ /** Speaking rate in percent (default 100). */
47
+ readonly speechRatePercent?: number;
48
+ /** Idle scheduling: `true`/`false`, or options (default enabled). */
49
+ readonly idle?: boolean | IdleOptions;
50
+ readonly balloon?: BalloonOptions;
51
+ /** Word balloons on or off for the session (default: the character's Style balloon bit). */
52
+ readonly balloonEnabled?: boolean;
53
+ /** Movement speed in logical units per second (default 400) and the longest move (default 60,000 ms). */
54
+ readonly movement?: {
55
+ readonly speed?: number;
56
+ readonly maxDurationMs?: number;
57
+ };
58
+ /** Initial visibility (default hidden). */
59
+ readonly visibility?: 'hidden' | 'visible';
60
+ readonly position?: Point;
61
+ /** Logical units per character pixel (default 1). */
62
+ readonly scale?: number;
63
+ /** Explicitly shared resources of the same source, or the budget of the agent's own resources. */
64
+ readonly resources?: CharacterResources | ResourceBudget;
65
+ readonly audioLimits?: AudioLimits;
66
+ /** Display name (default: the character's name). */
67
+ readonly name?: string;
68
+ }
69
+ /** Per-call Speak settings. */
70
+ export interface SpeakOptions {
71
+ /** Show the word balloon for this call (default: the session setting). */
72
+ readonly balloon?: boolean;
73
+ readonly interrupt?: boolean;
74
+ }
75
+ /** What a host presents for an agent now (Runtime.md §7). */
76
+ export interface PresentedFrame {
77
+ /** Animation index of the presented frame, or −1 when nothing is presented. */
78
+ readonly animation: number;
79
+ readonly frame: number;
80
+ /** The mouth overlay to apply (speech lip-sync), or null. */
81
+ readonly mouth: number | null;
82
+ /** The presented frame has no image layers: nothing is drawn. */
83
+ readonly blank: boolean;
84
+ /** False while hidden: nothing is drawn. */
85
+ readonly visible: boolean;
86
+ /** Top-left corner in logical surface units. */
87
+ readonly position: Point;
88
+ readonly scale: number;
89
+ readonly width: number;
90
+ readonly height: number;
91
+ /** True when there is something to draw. */
92
+ readonly hasImage: boolean;
93
+ }
94
+ /** The speech an agent presents now. */
95
+ export interface SpeechState {
96
+ readonly requestId: number;
97
+ readonly text: string;
98
+ readonly startedAtMs: number;
99
+ readonly durationMs: number;
100
+ readonly voice: string | null;
101
+ readonly lipSync: LipSyncSource;
102
+ readonly mouth: number | null;
103
+ readonly hasAudio: boolean;
104
+ }
105
+ /** The kinds `stopAll` accepts. */
106
+ export type StopKinds = readonly RequestKind[] | 'all';
107
+ /**
108
+ * One running character (Runtime.md): the request queue, random stream, visibility, position, scale, idle, speech, lip-sync, word balloon
109
+ * and typed events. It has no timers or threads: a host calls {@link advance} from its render loop and presents {@link currentFrame}.
110
+ */
111
+ export declare class CharacterAgent {
112
+ readonly source: CharacterSource;
113
+ readonly id: number;
114
+ readonly name: string;
115
+ readonly clock: Clock;
116
+ readonly resources: CharacterResources;
117
+ private readonly ownsResources;
118
+ private readonly audio;
119
+ private readonly idle;
120
+ private readonly pending;
121
+ private readonly listeners;
122
+ private readonly pacing;
123
+ private readonly maxTextLength;
124
+ private readonly movementSpeed;
125
+ private readonly maxMoveMs;
126
+ private speechRate;
127
+ private readonly hasAudioOption;
128
+ private readonly createSpeechOutput;
129
+ private speechOutput;
130
+ private visibilityValue;
131
+ private positionValue;
132
+ private scaleValue;
133
+ private now;
134
+ private pausedAt;
135
+ private disposed;
136
+ private paused;
137
+ private frame;
138
+ private provider;
139
+ private decision;
140
+ private voice;
141
+ private speechEnabledValue;
142
+ private balloonEnabledValue;
143
+ private speechAudioStatusValue;
144
+ private animationNames;
145
+ constructor(source: CharacterSource, options?: AgentOptions);
146
+ /** The character this agent plays. */
147
+ get character(): Character;
148
+ /** Animation names in file order. */
149
+ get animations(): readonly string[];
150
+ /** State names in file order. */
151
+ get states(): readonly string[];
152
+ get visibility(): AgentVisibility;
153
+ get position(): Point;
154
+ get scale(): number;
155
+ set scale(value: number);
156
+ get isPaused(): boolean;
157
+ get isDisposed(): boolean;
158
+ get balloon(): BalloonState;
159
+ /** What to present now. */
160
+ get currentFrame(): PresentedFrame;
161
+ /** The level the next idle animation uses (1–3), or 0 when the character has no idle states. */
162
+ get idleLevel(): number;
163
+ /** The running request (also idle requests the runtime created). */
164
+ get activeRequest(): AgentRequest | null;
165
+ /** Queued requests in start order. */
166
+ get queuedRequests(): readonly AgentRequest[];
167
+ /** The speech presented now, or null. */
168
+ get speechState(): SpeechState | null;
169
+ /** Frame sound effects (session setting). */
170
+ get soundEffects(): boolean;
171
+ set soundEffects(value: boolean);
172
+ get idleEnabled(): boolean;
173
+ set idleEnabled(value: boolean);
174
+ get balloonEnabled(): boolean;
175
+ set balloonEnabled(value: boolean);
176
+ get speechProvider(): SpeechProvider | null;
177
+ set speechProvider(value: SpeechProvider | null);
178
+ get voiceId(): string | null;
179
+ set voiceId(value: string | null);
180
+ /** Speak synthesizes audio (null follows the character's Style TTS bit). */
181
+ get speechEnabled(): boolean | null;
182
+ set speechEnabled(value: boolean | null);
183
+ /** Speaking rate in percent for speech synthesized from now on (100 = the voice's normal rate). */
184
+ get speechRatePercent(): number;
185
+ set speechRatePercent(value: number);
186
+ /** The voice Speak uses now, and why. */
187
+ get voiceDecision(): SpeechVoiceDecision;
188
+ /** What happened to the latest speech audio (diagnostic). */
189
+ get speechAudioStatus(): string;
190
+ /** The latest sound-effect status (diagnostic). */
191
+ get soundEffectStatus(): string;
192
+ /** Subscribes to every event (raised in time order inside {@link advance}). Returns the unsubscribe function. */
193
+ on(listener: (event: AgentEvent) => void): () => void;
194
+ /** Plays an animation by name (ignoring case). */
195
+ play(animation: string, options?: {
196
+ interrupt?: boolean;
197
+ }): AgentRequest;
198
+ /** Plays one animation of a state, chosen when the request starts. State requests are interruptible. */
199
+ playState(state: string, options?: {
200
+ interrupt?: boolean;
201
+ }): AgentRequest;
202
+ /** Shows the character: the Showing state animation (unless `fast` or missing), then visible. */
203
+ show(options?: {
204
+ fast?: boolean;
205
+ }): AgentRequest;
206
+ /** Hides the character: the Hiding state animation (unless `fast` or missing), then hidden. */
207
+ hide(options?: {
208
+ fast?: boolean;
209
+ }): AgentRequest;
210
+ private submitVisibility;
211
+ /** Moves the top-left corner to (x, y) at `speed` units per second (default the session speed; ≤ 0 moves instantly). */
212
+ moveTo(x: number, y: number, options?: {
213
+ speed?: number;
214
+ }): AgentRequest;
215
+ /** Gestures toward (x, y), measured from the character's centre, with the character-relative Gesturing state. */
216
+ gestureAt(x: number, y: number): AgentRequest;
217
+ /** Speaks text: synthesized audio when speech is enabled and a provider is set, lip-sync, the speech balloon and the Speaking state. */
218
+ speak(text: string | SpeechContent, options?: SpeakOptions): AgentRequest;
219
+ /** Shows text in a thought balloon (no audio, no lip-sync), paced by reading time. */
220
+ think(text: string, options?: {
221
+ interrupt?: boolean;
222
+ }): AgentRequest;
223
+ private speakCore;
224
+ /** Holds this agent's queue until `request` (of any agent) is terminal. */
225
+ wait(request: AgentRequest): AgentRequest;
226
+ /** Cancels one request of this agent. False when it is already terminal. */
227
+ cancel(request: AgentRequest): boolean;
228
+ /** Gracefully cancels queued and running requests of the given kinds (default: all but show and hide). Returns the count. */
229
+ stopAll(kinds?: StopKinds): number;
230
+ pause(): void;
231
+ resume(): void;
232
+ /** Cancels every request immediately (no exit path, no return), stops speech and sounds and hides the balloon. */
233
+ reset(): void;
234
+ private resetCore;
235
+ /** Sets the position immediately (not queued). A running move continues from here to its target. */
236
+ setPosition(x: number, y: number): void;
237
+ /** Hides the balloon now. */
238
+ dismissBalloon(): void;
239
+ /** Advances the agent to `time` (default: its clock) and returns the events since the previous call, in time order. */
240
+ advance(time?: number): AgentEvent[];
241
+ private nowTime;
242
+ private get shown();
243
+ private updateFrame;
244
+ private computeFrame;
245
+ /** Composes {@link currentFrame} to RGBA (null when nothing is shown). */
246
+ composeFrame(): RgbaImage | null;
247
+ private gestureState;
248
+ private prepareForStart;
249
+ private unavailableReason;
250
+ private canSpeakOn;
251
+ private canDrawMouth;
252
+ private usesSpeech;
253
+ private decide;
254
+ private checkText;
255
+ private submit;
256
+ private onRequestChanged;
257
+ private fromTrace;
258
+ /**
259
+ * Cancels every request (reason `disposed`), completes every handle, stops speech and sounds, removes listeners and releases what the
260
+ * agent owns. Idempotent.
261
+ */
262
+ dispose(): void;
263
+ }