@rollrook-ai/sdk 0.0.0-stage → 0.1.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 (143) hide show
  1. package/dist/agents.d.ts +9 -0
  2. package/dist/agents.d.ts.map +1 -0
  3. package/dist/agents.js +13 -0
  4. package/dist/agents.js.map +1 -0
  5. package/dist/assets.d.ts +35 -0
  6. package/dist/assets.d.ts.map +1 -0
  7. package/dist/assets.js +66 -0
  8. package/dist/assets.js.map +1 -0
  9. package/dist/assistant.d.ts +76 -0
  10. package/dist/assistant.d.ts.map +1 -0
  11. package/dist/assistant.js +161 -0
  12. package/dist/assistant.js.map +1 -0
  13. package/dist/audio.d.ts +55 -0
  14. package/dist/audio.d.ts.map +1 -0
  15. package/dist/audio.js +82 -0
  16. package/dist/audio.js.map +1 -0
  17. package/dist/bridge.d.ts +51 -0
  18. package/dist/bridge.d.ts.map +1 -0
  19. package/dist/bridge.js +78 -0
  20. package/dist/bridge.js.map +1 -0
  21. package/dist/calendar.d.ts +33 -0
  22. package/dist/calendar.d.ts.map +1 -0
  23. package/dist/calendar.js +63 -0
  24. package/dist/calendar.js.map +1 -0
  25. package/dist/context.d.ts +19 -0
  26. package/dist/context.d.ts.map +1 -0
  27. package/dist/context.js +25 -0
  28. package/dist/context.js.map +1 -0
  29. package/dist/errors.d.ts +74 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +111 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/events.d.ts +36 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +81 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/files.d.ts +29 -0
  38. package/dist/files.d.ts.map +1 -0
  39. package/dist/files.js +43 -0
  40. package/dist/files.js.map +1 -0
  41. package/dist/index.d.ts +84 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +78 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/mock/index.d.ts +4 -0
  46. package/dist/mock/index.d.ts.map +1 -0
  47. package/dist/mock/index.js +3 -0
  48. package/dist/mock/index.js.map +1 -0
  49. package/dist/mock/mock-host.d.ts +255 -0
  50. package/dist/mock/mock-host.d.ts.map +1 -0
  51. package/dist/mock/mock-host.js +1274 -0
  52. package/dist/mock/mock-host.js.map +1 -0
  53. package/dist/mock/samples.d.ts +56 -0
  54. package/dist/mock/samples.d.ts.map +1 -0
  55. package/dist/mock/samples.js +283 -0
  56. package/dist/mock/samples.js.map +1 -0
  57. package/dist/mock/toolbar.d.ts +95 -0
  58. package/dist/mock/toolbar.d.ts.map +1 -0
  59. package/dist/mock/toolbar.js +279 -0
  60. package/dist/mock/toolbar.js.map +1 -0
  61. package/dist/net.d.ts +13 -0
  62. package/dist/net.d.ts.map +1 -0
  63. package/dist/net.js +26 -0
  64. package/dist/net.js.map +1 -0
  65. package/dist/plugin.d.ts +11 -0
  66. package/dist/plugin.d.ts.map +1 -0
  67. package/dist/plugin.js +13 -0
  68. package/dist/plugin.js.map +1 -0
  69. package/dist/raven.d.ts +51 -0
  70. package/dist/raven.d.ts.map +1 -0
  71. package/dist/raven.js +100 -0
  72. package/dist/raven.js.map +1 -0
  73. package/dist/segment-display.d.ts +93 -0
  74. package/dist/segment-display.d.ts.map +1 -0
  75. package/dist/segment-display.js +324 -0
  76. package/dist/segment-display.js.map +1 -0
  77. package/dist/settings.d.ts +19 -0
  78. package/dist/settings.d.ts.map +1 -0
  79. package/dist/settings.js +27 -0
  80. package/dist/settings.js.map +1 -0
  81. package/dist/storage.d.ts +28 -0
  82. package/dist/storage.d.ts.map +1 -0
  83. package/dist/storage.js +54 -0
  84. package/dist/storage.js.map +1 -0
  85. package/dist/system.d.ts +19 -0
  86. package/dist/system.d.ts.map +1 -0
  87. package/dist/system.js +24 -0
  88. package/dist/system.js.map +1 -0
  89. package/dist/theme.d.ts +51 -0
  90. package/dist/theme.d.ts.map +1 -0
  91. package/dist/theme.js +85 -0
  92. package/dist/theme.js.map +1 -0
  93. package/dist/types.d.ts +278 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/ui.d.ts +57 -0
  98. package/dist/ui.d.ts.map +1 -0
  99. package/dist/ui.js +78 -0
  100. package/dist/ui.js.map +1 -0
  101. package/dist/usage.d.ts +14 -0
  102. package/dist/usage.d.ts.map +1 -0
  103. package/dist/usage.js +19 -0
  104. package/dist/usage.js.map +1 -0
  105. package/dist/video.d.ts +11 -0
  106. package/dist/video.d.ts.map +1 -0
  107. package/dist/video.js +17 -0
  108. package/dist/video.js.map +1 -0
  109. package/dist/wire.d.ts +214 -0
  110. package/dist/wire.d.ts.map +1 -0
  111. package/dist/wire.js +538 -0
  112. package/dist/wire.js.map +1 -0
  113. package/package.json +39 -4
  114. package/src/agents.ts +14 -0
  115. package/src/assets.ts +80 -0
  116. package/src/assistant.ts +185 -0
  117. package/src/audio.ts +90 -0
  118. package/src/bridge.ts +96 -0
  119. package/src/calendar.ts +68 -0
  120. package/src/context.ts +28 -0
  121. package/src/errors.ts +131 -0
  122. package/src/events.ts +90 -0
  123. package/src/files.ts +47 -0
  124. package/src/index.ts +152 -0
  125. package/src/mock/index.ts +3 -0
  126. package/src/mock/mock-host.ts +1408 -0
  127. package/src/mock/samples.ts +300 -0
  128. package/src/mock/toolbar.ts +321 -0
  129. package/src/net.ts +27 -0
  130. package/src/plugin.ts +14 -0
  131. package/src/raven.ts +116 -0
  132. package/src/segment-display.ts +377 -0
  133. package/src/settings.ts +29 -0
  134. package/src/storage.ts +59 -0
  135. package/src/system.ts +26 -0
  136. package/src/theme.ts +97 -0
  137. package/src/types.ts +327 -0
  138. package/src/ui.ts +88 -0
  139. package/src/usage.ts +21 -0
  140. package/src/video.ts +17 -0
  141. package/src/wire.ts +608 -0
  142. package/theme.css +407 -0
  143. package/README.md +0 -3
package/src/wire.ts ADDED
@@ -0,0 +1,608 @@
1
+ import { FailedError } from "./errors.js";
2
+ import type {
3
+ AgentHarness,
4
+ AgentSession,
5
+ AudioLevels,
6
+ AudioSettings,
7
+ AudioTarget,
8
+ AudioTrack,
9
+ AudioTracksChange,
10
+ CalendarItem,
11
+ CalendarMove,
12
+ CalendarOpen,
13
+ City,
14
+ FetchResponse,
15
+ FileEntry,
16
+ JsonObject,
17
+ JsonValue,
18
+ PluginContext,
19
+ PluginMessage,
20
+ RavenAnswer,
21
+ RavenTurn,
22
+ ReverbRoom,
23
+ SettingValues,
24
+ Theme,
25
+ UsageAccount,
26
+ UsageLimit,
27
+ UsageSeverity,
28
+ UsageSnapshot,
29
+ ViewSlot,
30
+ VisibilityChange,
31
+ } from "./types.js";
32
+
33
+ /**
34
+ * Reads the host's replies and event payloads, checks their shape and maps
35
+ * the protocol's camelCase fields to the SDK's names.
36
+ */
37
+ export class Wire {
38
+ /**
39
+ * Whether a value is a plain JSON object.
40
+ *
41
+ * @param value - the value to test
42
+ * @returns true for a non-null, non-array object
43
+ */
44
+ static is_record(value: unknown): value is Record<string, unknown> {
45
+ return typeof value === "object" && value !== null && !Array.isArray(value);
46
+ }
47
+
48
+ /**
49
+ * Whether a value is JSON: what `storage` may keep.
50
+ *
51
+ * @param value - the value to test
52
+ * @returns true when the value survives a JSON round trip unchanged
53
+ */
54
+ static is_json(value: unknown): value is JsonValue {
55
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
56
+ return true;
57
+ }
58
+ if (typeof value === "number") {
59
+ return Number.isFinite(value);
60
+ }
61
+ if (Array.isArray(value)) {
62
+ return value.every((item: unknown) => Wire.is_json(item));
63
+ }
64
+ if (Wire.is_record(value)) {
65
+ return Object.values(value).every((item: unknown) => Wire.is_json(item));
66
+ }
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * @param value - a reply or payload
72
+ * @param what - what the value should be, for the error message
73
+ * @returns the value as an object
74
+ * @throws FailedError when it is not one
75
+ */
76
+ static record(value: unknown, what: string): Record<string, unknown> {
77
+ if (!Wire.is_record(value)) {
78
+ throw new FailedError(`malformed ${what}: expected an object`);
79
+ }
80
+ return value;
81
+ }
82
+
83
+ /**
84
+ * @param record - the object holding the field
85
+ * @param key - the field's wire name
86
+ * @param what - the object, for the error message
87
+ * @returns the field as a string
88
+ * @throws FailedError when it is not one
89
+ */
90
+ static string(record: Record<string, unknown>, key: string, what: string): string {
91
+ const value = record[key];
92
+ if (typeof value !== "string") {
93
+ throw new FailedError(`malformed ${what}: ${key} is not a string`);
94
+ }
95
+ return value;
96
+ }
97
+
98
+ /**
99
+ * @param record - the object holding the field
100
+ * @param key - the field's wire name
101
+ * @param what - the object, for the error message
102
+ * @returns the field as a string, or undefined when it is null or missing
103
+ * @throws FailedError when it is something else
104
+ */
105
+ static optional_string(record: Record<string, unknown>, key: string, what: string): string | undefined {
106
+ const value = record[key];
107
+ if (value === null || value === undefined) {
108
+ return undefined;
109
+ }
110
+ if (typeof value !== "string") {
111
+ throw new FailedError(`malformed ${what}: ${key} is not a string`);
112
+ }
113
+ return value;
114
+ }
115
+
116
+ /**
117
+ * @param record - the object holding the field
118
+ * @param key - the field's wire name
119
+ * @param what - the object, for the error message
120
+ * @returns the field as a number
121
+ * @throws FailedError when it is not one
122
+ */
123
+ static number(record: Record<string, unknown>, key: string, what: string): number {
124
+ const value = record[key];
125
+ if (typeof value !== "number" || !Number.isFinite(value)) {
126
+ throw new FailedError(`malformed ${what}: ${key} is not a number`);
127
+ }
128
+ return value;
129
+ }
130
+
131
+ /**
132
+ * @param record - the object holding the field
133
+ * @param key - the field's wire name
134
+ * @param what - the object, for the error message
135
+ * @returns the field as a boolean
136
+ * @throws FailedError when it is not one
137
+ */
138
+ static boolean(record: Record<string, unknown>, key: string, what: string): boolean {
139
+ const value = record[key];
140
+ if (typeof value !== "boolean") {
141
+ throw new FailedError(`malformed ${what}: ${key} is not a boolean`);
142
+ }
143
+ return value;
144
+ }
145
+
146
+ /**
147
+ * @param record - the object holding the field
148
+ * @param key - the field's wire name
149
+ * @param what - the object, for the error message
150
+ * @returns the field as an array
151
+ * @throws FailedError when it is not one
152
+ */
153
+ static array(record: Record<string, unknown>, key: string, what: string): unknown[] {
154
+ const value = record[key];
155
+ if (!Array.isArray(value)) {
156
+ throw new FailedError(`malformed ${what}: ${key} is not an array`);
157
+ }
158
+ return value;
159
+ }
160
+
161
+ /**
162
+ * @param record - the object holding the field
163
+ * @param key - the field's wire name
164
+ * @param what - the object, for the error message
165
+ * @returns the field as a date, or undefined when it is null, missing or not a time
166
+ */
167
+ static optional_date(record: Record<string, unknown>, key: string, what: string): Date | undefined {
168
+ const text = Wire.optional_string(record, key, what);
169
+ const date = text === undefined ? undefined : new Date(text);
170
+ return date === undefined || Number.isNaN(date.getTime()) ? undefined : date;
171
+ }
172
+
173
+ /**
174
+ * @param record - the object holding the field
175
+ * @param key - the field's wire name
176
+ * @param list_allowed - the values the field may take
177
+ * @returns the field, one of the allowed values
178
+ * @throws FailedError when it is something else
179
+ */
180
+ static one_of<T extends string>(record: Record<string, unknown>, key: string, list_allowed: readonly T[]): T {
181
+ const value = record[key];
182
+ const found = list_allowed.find((allowed: T) => allowed === value);
183
+ if (found === undefined) {
184
+ throw new FailedError(`malformed reply: ${key} is not one of ${list_allowed.join(", ")}`);
185
+ }
186
+ return found;
187
+ }
188
+
189
+ /**
190
+ * @param raw - the theme as the host sends it
191
+ * @returns the theme
192
+ */
193
+ static theme(raw: unknown): Theme {
194
+ const record = Wire.record(raw, "theme");
195
+ const colors = Wire.record(record["colors"], "theme colors");
196
+ const what = "theme colors";
197
+ return {
198
+ is_dark: Wire.boolean(record, "isDark", "theme"),
199
+ is_high_contrast: Wire.boolean(record, "isHighContrast", "theme"),
200
+ colors: {
201
+ background: Wire.string(colors, "background", what),
202
+ surface: Wire.string(colors, "surface", what),
203
+ sidebar: Wire.string(colors, "sidebar", what),
204
+ text: Wire.string(colors, "text", what),
205
+ secondary_text: Wire.string(colors, "secondaryText", what),
206
+ tertiary_text: Wire.string(colors, "tertiaryText", what),
207
+ separator: Wire.string(colors, "separator", what),
208
+ accent: Wire.string(colors, "accent", what),
209
+ on_accent: Wire.string(colors, "onAccent", what),
210
+ caution: Wire.string(colors, "caution", what),
211
+ segment: Wire.string(colors, "segment", what),
212
+ },
213
+ };
214
+ }
215
+
216
+ /**
217
+ * @param raw - the context as the host sends it
218
+ * @returns the context
219
+ */
220
+ static context(raw: unknown): PluginContext {
221
+ const record = Wire.record(raw, "context");
222
+ return {
223
+ protocol: Wire.number(record, "protocol", "context"),
224
+ plugin_id: Wire.string(record, "pluginId", "context"),
225
+ plugin_version: Wire.string(record, "pluginVersion", "context"),
226
+ app_version: Wire.string(record, "appVersion", "context"),
227
+ view_id: Wire.string(record, "viewId", "context"),
228
+ slot: Wire.one_of(record, "slot", Wire.LIST_SLOTS),
229
+ instance_id: Wire.string(record, "instanceId", "context"),
230
+ theme: Wire.theme(record["theme"]),
231
+ };
232
+ }
233
+
234
+ /** The slots a view may show in. */
235
+ static readonly LIST_SLOTS: readonly ViewSlot[] = ["dock", "sidebar", "footbar", "popover", "settings", "background"];
236
+
237
+ /** The code agents RollRook knows. */
238
+ static readonly LIST_HARNESSES: readonly AgentHarness[] = ["claude", "codex", "agy"];
239
+
240
+ /** The severities of a plan limit. */
241
+ static readonly LIST_SEVERITIES: readonly UsageSeverity[] = ["normal", "warning", "critical"];
242
+
243
+ /** The reverb rooms of the mixer. */
244
+ static readonly LIST_REVERB_ROOMS: readonly ReverbRoom[] = [
245
+ "smallRoom",
246
+ "mediumRoom",
247
+ "largeRoom",
248
+ "mediumHall",
249
+ "largeHall",
250
+ "plate",
251
+ "cathedral",
252
+ ];
253
+
254
+ /**
255
+ * @param raw - a folder entry as the host sends it
256
+ * @returns the entry
257
+ */
258
+ static file_entry(raw: unknown): FileEntry {
259
+ const record = Wire.record(raw, "file entry");
260
+ return {
261
+ name: Wire.string(record, "name", "file entry"),
262
+ is_directory: Wire.boolean(record, "isDirectory", "file entry"),
263
+ size: Wire.number(record, "size", "file entry"),
264
+ };
265
+ }
266
+
267
+ /**
268
+ * @param raw - the reply to `raven.answer`
269
+ * @returns the answer
270
+ */
271
+ static raven_answer(raw: unknown): RavenAnswer {
272
+ const record = Wire.record(raw, "raven answer");
273
+ return {
274
+ is_running: Wire.boolean(record, "isRunning", "raven answer"),
275
+ answer: Wire.optional_string(record, "answer", "raven answer") ?? "",
276
+ };
277
+ }
278
+
279
+ /**
280
+ * @param raw - the `raven.turn` event's payload
281
+ * @returns the turn
282
+ */
283
+ static raven_turn(raw: unknown): RavenTurn {
284
+ const record = Wire.record(raw, "raven turn");
285
+ return {
286
+ conversation_id: Wire.string(record, "conversationId", "raven turn"),
287
+ is_running: Wire.boolean(record, "isRunning", "raven turn"),
288
+ answer: Wire.optional_string(record, "answer", "raven turn") ?? "",
289
+ };
290
+ }
291
+
292
+ /**
293
+ * @param raw - the `visibility` event's payload
294
+ * @returns the change
295
+ */
296
+ static visibility(raw: unknown): VisibilityChange {
297
+ const record = Wire.record(raw, "visibility");
298
+ return {
299
+ is_shown: Wire.boolean(record, "isShown", "visibility"),
300
+ };
301
+ }
302
+
303
+ /**
304
+ * @param raw - the reply to `settings.get` or the `settings.changed` payload
305
+ * @returns the values by key
306
+ */
307
+ static setting_values(raw: unknown): SettingValues {
308
+ const values = Wire.record(Wire.record(raw, "settings")["values"], "settings values");
309
+ const map_values: SettingValues = {};
310
+ for (const [key, value] of Object.entries(values)) {
311
+ if (Wire.is_json(value)) {
312
+ map_values[key] = value;
313
+ }
314
+ }
315
+ return map_values;
316
+ }
317
+
318
+ /**
319
+ * @param raw - the `message` event's payload
320
+ * @returns the message
321
+ */
322
+ static plugin_message(raw: unknown): PluginMessage {
323
+ const record = Wire.record(raw, "message");
324
+ const message = record["message"] ?? null;
325
+ return {
326
+ from_view_id: Wire.string(record, "fromViewId", "message"),
327
+ from_instance_id: Wire.string(record, "fromInstanceId", "message"),
328
+ message: Wire.is_json(message) ? message : null,
329
+ };
330
+ }
331
+
332
+ /**
333
+ * @param raw - one session of `agents.list`
334
+ * @returns the session
335
+ */
336
+ static agent_session(raw: unknown): AgentSession {
337
+ const record = Wire.record(raw, "agent");
338
+ return {
339
+ id: Wire.string(record, "id", "agent"),
340
+ title: Wire.string(record, "title", "agent"),
341
+ harness: Wire.one_of(record, "harness", Wire.LIST_HARNESSES),
342
+ state: Wire.string(record, "state", "agent"),
343
+ host: Wire.optional_string(record, "host", "agent") ?? "",
344
+ };
345
+ }
346
+
347
+ /**
348
+ * @param raw - one limit of a `usage.list` account
349
+ * @returns the limit
350
+ */
351
+ static usage_limit(raw: unknown): UsageLimit {
352
+ const record = Wire.record(raw, "usage limit");
353
+ return {
354
+ id: Wire.string(record, "id", "usage limit"),
355
+ title: Wire.string(record, "title", "usage limit"),
356
+ used_percent: Wire.number(record, "usedPercent", "usage limit"),
357
+ resets_at: Wire.optional_date(record, "resetsAt", "usage limit"),
358
+ severity: Wire.one_of(record, "severity", Wire.LIST_SEVERITIES),
359
+ };
360
+ }
361
+
362
+ /**
363
+ * @param raw - one account of `usage.list`
364
+ * @returns the account
365
+ */
366
+ static usage_account(raw: unknown): UsageAccount {
367
+ const record = Wire.record(raw, "usage account");
368
+ const what = "usage account";
369
+ return {
370
+ harness: Wire.one_of(record, "harness", Wire.LIST_HARNESSES),
371
+ signed_in_as: Wire.optional_string(record, "signedInAs", what),
372
+ plan: Wire.optional_string(record, "plan", what),
373
+ is_default: Wire.boolean(record, "isDefault", what),
374
+ error: Wire.optional_string(record, "error", what),
375
+ fetched_at: Wire.optional_date(record, "fetchedAt", what),
376
+ list_limits: Wire.array(record, "limits", what).map((item: unknown) => Wire.usage_limit(item)),
377
+ };
378
+ }
379
+
380
+ /**
381
+ * @param raw - the reply to `usage.list` or the `usage.changed` payload
382
+ * @returns the accounts and the refresh state
383
+ */
384
+ static usage_snapshot(raw: unknown): UsageSnapshot {
385
+ const record = Wire.record(raw, "usage");
386
+ return {
387
+ list_accounts: Wire.array(record, "accounts", "usage").map((item: unknown) => Wire.usage_account(item)),
388
+ is_refreshing: Wire.boolean(record, "isRefreshing", "usage"),
389
+ next_refresh_at: Wire.optional_date(record, "nextRefreshAt", "usage"),
390
+ };
391
+ }
392
+
393
+ /**
394
+ * @param raw - a track's target as the host sends it
395
+ * @returns the target
396
+ */
397
+ static audio_target(raw: unknown): AudioTarget {
398
+ const record = Wire.record(raw, "audio target");
399
+ if (record["kind"] === "app") {
400
+ return { kind: "app", bundle_id: Wire.string(record, "bundleId", "audio target") };
401
+ }
402
+ if (record["kind"] === "tab") {
403
+ return {
404
+ kind: "tab",
405
+ session_id: Wire.number(record, "sessionId", "audio target"),
406
+ tab_id: Wire.number(record, "tabId", "audio target"),
407
+ };
408
+ }
409
+ throw new FailedError("malformed audio target: kind is not app or tab");
410
+ }
411
+
412
+ /**
413
+ * @param target - a track's target
414
+ * @returns the target as the host takes it
415
+ */
416
+ static audio_target_to_wire(target: AudioTarget): JsonObject {
417
+ return target.kind === "app"
418
+ ? { kind: "app", bundleId: target.bundle_id }
419
+ : { kind: "tab", sessionId: target.session_id, tabId: target.tab_id };
420
+ }
421
+
422
+ /**
423
+ * @param raw - a track's settings as the host sends them
424
+ * @returns the settings
425
+ */
426
+ static audio_settings(raw: unknown): AudioSettings {
427
+ const record = Wire.record(raw, "audio settings");
428
+ const what = "audio settings";
429
+ return {
430
+ is_taken_over: Wire.boolean(record, "isTakenOver", what),
431
+ is_muted: Wire.boolean(record, "isMuted", what),
432
+ volume: Wire.number(record, "volume", what),
433
+ pan: Wire.number(record, "pan", what),
434
+ is_left_inverted: Wire.boolean(record, "isLeftInverted", what),
435
+ is_right_inverted: Wire.boolean(record, "isRightInverted", what),
436
+ is_swapped: Wire.boolean(record, "isSwapped", what),
437
+ width: Wire.number(record, "width", what),
438
+ is_equalizer_enabled: Wire.boolean(record, "isEqualizerEnabled", what),
439
+ list_equalizer_gains: Wire.array(record, "equalizerGains", what).filter(
440
+ (gain: unknown) => typeof gain === "number",
441
+ ),
442
+ reverb_room: Wire.one_of(record, "reverbRoom", Wire.LIST_REVERB_ROOMS),
443
+ reverb_mix: Wire.number(record, "reverbMix", what),
444
+ };
445
+ }
446
+
447
+ /**
448
+ * @param settings - some of a track's settings
449
+ * @returns them as the host takes them
450
+ */
451
+ static audio_settings_to_wire(settings: Partial<AudioSettings>): JsonObject {
452
+ const map_wire: JsonObject = {};
453
+ for (const [key, value] of Object.entries(settings)) {
454
+ const wire_key = Wire.map_audio_setting_names[key];
455
+ if (wire_key !== undefined && Wire.is_json(value)) {
456
+ map_wire[wire_key] = value;
457
+ }
458
+ }
459
+ return map_wire;
460
+ }
461
+
462
+ /** Each audio setting's wire name, by the SDK's name. */
463
+ static readonly map_audio_setting_names: Record<string, string> = {
464
+ is_taken_over: "isTakenOver",
465
+ is_muted: "isMuted",
466
+ volume: "volume",
467
+ pan: "pan",
468
+ is_left_inverted: "isLeftInverted",
469
+ is_right_inverted: "isRightInverted",
470
+ is_swapped: "isSwapped",
471
+ width: "width",
472
+ is_equalizer_enabled: "isEqualizerEnabled",
473
+ list_equalizer_gains: "equalizerGains",
474
+ reverb_room: "reverbRoom",
475
+ reverb_mix: "reverbMix",
476
+ };
477
+
478
+ /**
479
+ * @param raw - one track of `audio.list` or `audio.tracks`
480
+ * @returns the track
481
+ */
482
+ static audio_track(raw: unknown): AudioTrack {
483
+ const record = Wire.record(raw, "audio track");
484
+ return {
485
+ target: Wire.audio_target(record["target"]),
486
+ name: Wire.string(record, "name", "audio track"),
487
+ icon_url: Wire.optional_string(record, "iconURL", "audio track"),
488
+ is_playing: Wire.boolean(record, "isPlaying", "audio track"),
489
+ is_capturing: Wire.boolean(record, "isCapturing", "audio track"),
490
+ has_video: record["hasVideo"] === true,
491
+ settings: Wire.audio_settings(record["settings"]),
492
+ };
493
+ }
494
+
495
+ /**
496
+ * @param raw - the reply to `audio.list` or the `audio.tracks` payload
497
+ * @returns the tracks
498
+ */
499
+ static audio_tracks(raw: unknown): AudioTracksChange {
500
+ const record = Wire.record(raw, "audio tracks");
501
+ return {
502
+ list_tracks: Wire.array(record, "tracks", "audio tracks").map((item: unknown) => Wire.audio_track(item)),
503
+ };
504
+ }
505
+
506
+ /**
507
+ * @param raw - the `audio.levels` payload
508
+ * @returns the levels
509
+ */
510
+ static audio_levels(raw: unknown): AudioLevels {
511
+ const record = Wire.record(raw, "audio levels");
512
+ return {
513
+ list_levels: Wire.array(record, "levels", "audio levels").map((item: unknown) => {
514
+ const level = Wire.record(item, "audio level");
515
+ return {
516
+ key: Wire.string(level, "key", "audio level"),
517
+ left: Wire.number(level, "left", "audio level"),
518
+ right: Wire.number(level, "right", "audio level"),
519
+ };
520
+ }),
521
+ };
522
+ }
523
+
524
+ /**
525
+ * @param raw - the reply to `system.searchCities`
526
+ * @returns the cities
527
+ */
528
+ static cities(raw: unknown): City[] {
529
+ const record = Wire.record(raw, "system.searchCities reply");
530
+ return Wire.array(record, "cities", "system.searchCities reply").map((item: unknown) => {
531
+ const city = Wire.record(item, "city");
532
+ return {
533
+ name: Wire.string(city, "name", "city"),
534
+ time_zone_id: Wire.string(city, "timeZoneId", "city"),
535
+ };
536
+ });
537
+ }
538
+
539
+ /**
540
+ * @param raw - the reply to `net.fetch`
541
+ * @returns the response
542
+ */
543
+ static fetch_response(raw: unknown): FetchResponse {
544
+ const record = Wire.record(raw, "fetch response");
545
+ const headers = Wire.record(record["headers"] ?? {}, "fetch headers");
546
+ const map_headers: Record<string, string> = {};
547
+ for (const [name, value] of Object.entries(headers)) {
548
+ if (typeof value === "string") {
549
+ map_headers[name.toLowerCase()] = value;
550
+ }
551
+ }
552
+ return {
553
+ status: Wire.number(record, "status", "fetch response"),
554
+ map_headers,
555
+ body: Wire.optional_string(record, "body", "fetch response") ?? "",
556
+ };
557
+ }
558
+
559
+ /**
560
+ * @param item - one calendar item, with the SDK's names
561
+ * @returns the item in wire form, its unset fields left out
562
+ */
563
+ static calendar_item_to_wire(item: CalendarItem): JsonObject {
564
+ const record: JsonObject = {
565
+ id: item.id,
566
+ title: item.title,
567
+ };
568
+ const map_optional: Record<string, string | boolean | undefined> = {
569
+ start: item.start,
570
+ end: item.end,
571
+ due: item.due,
572
+ isAllDay: item.is_all_day,
573
+ isDone: item.is_done,
574
+ color: item.color,
575
+ };
576
+ for (const [key, value] of Object.entries(map_optional)) {
577
+ if (value !== undefined) {
578
+ record[key] = value;
579
+ }
580
+ }
581
+ return record;
582
+ }
583
+
584
+ /**
585
+ * @param raw - the `calendar.open` payload
586
+ * @returns the item the user opened
587
+ */
588
+ static calendar_open(raw: unknown): CalendarOpen {
589
+ const record = Wire.record(raw, "calendar.open");
590
+ return {
591
+ id: Wire.string(record, "id", "calendar.open"),
592
+ };
593
+ }
594
+
595
+ /**
596
+ * @param raw - the `calendar.move` payload
597
+ * @returns the item the user moved and its new times
598
+ */
599
+ static calendar_move(raw: unknown): CalendarMove {
600
+ const record = Wire.record(raw, "calendar.move");
601
+ return {
602
+ id: Wire.string(record, "id", "calendar.move"),
603
+ start: Wire.optional_string(record, "start", "calendar.move"),
604
+ end: Wire.optional_string(record, "end", "calendar.move"),
605
+ due: Wire.optional_string(record, "due", "calendar.move"),
606
+ };
607
+ }
608
+ }