@celljs/ta-host 4.16.0 → 4.18.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 (179) hide show
  1. package/esm/node/app-commands.d.ts +111 -0
  2. package/esm/node/app-commands.js +646 -0
  3. package/esm/node/credentials.d.ts +12 -0
  4. package/esm/node/credentials.js +35 -0
  5. package/esm/node/delegate-extension.d.ts +11 -0
  6. package/esm/node/delegate-extension.js +33 -0
  7. package/esm/node/directory-relocator.d.ts +49 -0
  8. package/esm/node/directory-relocator.js +267 -0
  9. package/esm/node/extension-providers.d.ts +16 -1
  10. package/esm/node/extension-providers.js +23 -3
  11. package/esm/node/index.d.ts +8 -0
  12. package/esm/node/index.js +8 -0
  13. package/esm/node/keep-awake.d.ts +8 -1
  14. package/esm/node/keep-awake.js +24 -3
  15. package/esm/node/message-page.d.ts +6 -1
  16. package/esm/node/message-page.js +50 -2
  17. package/esm/node/package-hosts.d.ts +8 -0
  18. package/esm/node/package-hosts.js +41 -0
  19. package/esm/node/package-webhooks.d.ts +26 -0
  20. package/esm/node/package-webhooks.js +101 -0
  21. package/esm/node/page-book.d.ts +48 -0
  22. package/esm/node/page-book.js +117 -0
  23. package/esm/node/relay-bridge.d.ts +2 -0
  24. package/esm/node/relay-bridge.js +35 -1
  25. package/esm/node/rooms-bridge.d.ts +13 -1
  26. package/esm/node/rooms-bridge.js +29 -0
  27. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  28. package/esm/node/screen-share/desktop-picture.js +133 -0
  29. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  30. package/esm/node/screen-share/desktop-session.js +437 -0
  31. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  32. package/esm/node/screen-share/desktop-targets.js +80 -0
  33. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  34. package/esm/node/screen-share/desktop-viewer.js +339 -0
  35. package/esm/node/screen-share/index.d.ts +8 -0
  36. package/esm/node/screen-share/index.js +9 -0
  37. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  38. package/esm/node/screen-share/rfb-client.js +179 -0
  39. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  40. package/esm/node/screen-share/rfb-des.js +143 -0
  41. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  42. package/esm/node/screen-share/rfb-encodings.js +288 -0
  43. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  44. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  45. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  46. package/esm/node/screen-share/rfb-protocol.js +36 -0
  47. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  48. package/esm/node/screen-share/rfb-reader.js +110 -0
  49. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  50. package/esm/node/screen-share/rfb-security.js +136 -0
  51. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  52. package/esm/node/screen-share/rfb-test-server.js +116 -0
  53. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  54. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  55. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  56. package/esm/node/screen-share/screen-shares.js +463 -0
  57. package/esm/node/session-info-util.d.ts +10 -9
  58. package/esm/node/session-info-util.js +16 -68
  59. package/esm/node/settings-store.d.ts +1 -1
  60. package/esm/node/settings-store.js +7 -4
  61. package/esm/node/sign-in/access-store.d.ts +1 -1
  62. package/esm/node/sign-in/access-store.js +4 -1
  63. package/esm/node/sign-in/index.d.ts +2 -0
  64. package/esm/node/sign-in/index.js +2 -0
  65. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  66. package/esm/node/sign-in/polled-sign-in.js +83 -0
  67. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  68. package/esm/node/sign-in/sign-in-devices.js +113 -0
  69. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  70. package/esm/node/sign-in/sign-in-flow.js +79 -4
  71. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  72. package/esm/node/sign-in/sign-in-pages.js +137 -8
  73. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  74. package/esm/node/sign-in/sign-in-provider.js +15 -0
  75. package/esm/node/sources-extension.d.ts +10 -0
  76. package/esm/node/sources-extension.js +18 -0
  77. package/esm/node/ta-server-impl.d.ts +5 -1
  78. package/esm/node/ta-server-impl.js +25 -3
  79. package/esm/node/ta-session-factory.d.ts +13 -1
  80. package/esm/node/ta-session-factory.js +41 -4
  81. package/esm/node/ta-session.d.ts +2 -0
  82. package/esm/node/ta-session.js +1 -0
  83. package/esm/node/team/team-calls.js +49 -0
  84. package/esm/node/voice-bridge.d.ts +70 -0
  85. package/esm/node/voice-bridge.js +280 -0
  86. package/esm/node/voices-file.d.ts +38 -0
  87. package/esm/node/voices-file.js +100 -0
  88. package/esm/node/working-directory.d.ts +8 -2
  89. package/esm/node/working-directory.js +7 -0
  90. package/lib/node/app-commands.d.ts +112 -0
  91. package/lib/node/app-commands.js +650 -0
  92. package/lib/node/credentials.d.ts +13 -0
  93. package/lib/node/credentials.js +38 -0
  94. package/lib/node/delegate-extension.d.ts +12 -0
  95. package/lib/node/delegate-extension.js +37 -0
  96. package/lib/node/directory-relocator.d.ts +50 -0
  97. package/lib/node/directory-relocator.js +270 -0
  98. package/lib/node/extension-providers.d.ts +16 -1
  99. package/lib/node/extension-providers.js +23 -3
  100. package/lib/node/index.d.ts +8 -0
  101. package/lib/node/index.js +8 -0
  102. package/lib/node/keep-awake.d.ts +8 -1
  103. package/lib/node/keep-awake.js +24 -3
  104. package/lib/node/message-page.d.ts +6 -1
  105. package/lib/node/message-page.js +50 -2
  106. package/lib/node/package-hosts.d.ts +8 -0
  107. package/lib/node/package-hosts.js +41 -0
  108. package/lib/node/package-webhooks.d.ts +27 -0
  109. package/lib/node/package-webhooks.js +104 -0
  110. package/lib/node/page-book.d.ts +49 -0
  111. package/lib/node/page-book.js +120 -0
  112. package/lib/node/relay-bridge.d.ts +2 -0
  113. package/lib/node/relay-bridge.js +34 -0
  114. package/lib/node/rooms-bridge.d.ts +13 -1
  115. package/lib/node/rooms-bridge.js +29 -0
  116. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  117. package/lib/node/screen-share/desktop-picture.js +136 -0
  118. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  119. package/lib/node/screen-share/desktop-session.js +442 -0
  120. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  121. package/lib/node/screen-share/desktop-targets.js +84 -0
  122. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  123. package/lib/node/screen-share/desktop-viewer.js +343 -0
  124. package/lib/node/screen-share/index.d.ts +9 -0
  125. package/lib/node/screen-share/index.js +25 -0
  126. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  127. package/lib/node/screen-share/rfb-client.js +183 -0
  128. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  129. package/lib/node/screen-share/rfb-des.js +146 -0
  130. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  131. package/lib/node/screen-share/rfb-encodings.js +295 -0
  132. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  133. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  134. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  135. package/lib/node/screen-share/rfb-protocol.js +39 -0
  136. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  137. package/lib/node/screen-share/rfb-reader.js +115 -0
  138. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  139. package/lib/node/screen-share/rfb-security.js +141 -0
  140. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  141. package/lib/node/screen-share/rfb-test-server.js +120 -0
  142. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  143. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  144. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  145. package/lib/node/screen-share/screen-shares.js +464 -0
  146. package/lib/node/session-info-util.d.ts +10 -9
  147. package/lib/node/session-info-util.js +15 -67
  148. package/lib/node/settings-store.d.ts +1 -1
  149. package/lib/node/settings-store.js +6 -3
  150. package/lib/node/sign-in/access-store.d.ts +1 -1
  151. package/lib/node/sign-in/access-store.js +4 -1
  152. package/lib/node/sign-in/index.d.ts +2 -0
  153. package/lib/node/sign-in/index.js +2 -0
  154. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  155. package/lib/node/sign-in/polled-sign-in.js +87 -0
  156. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  157. package/lib/node/sign-in/sign-in-devices.js +117 -0
  158. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  159. package/lib/node/sign-in/sign-in-flow.js +80 -5
  160. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  161. package/lib/node/sign-in/sign-in-pages.js +136 -7
  162. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  163. package/lib/node/sign-in/sign-in-provider.js +15 -0
  164. package/lib/node/sources-extension.d.ts +11 -0
  165. package/lib/node/sources-extension.js +22 -0
  166. package/lib/node/ta-server-impl.d.ts +5 -1
  167. package/lib/node/ta-server-impl.js +24 -2
  168. package/lib/node/ta-session-factory.d.ts +13 -1
  169. package/lib/node/ta-session-factory.js +40 -3
  170. package/lib/node/ta-session.d.ts +2 -0
  171. package/lib/node/ta-session.js +1 -0
  172. package/lib/node/team/team-calls.js +49 -0
  173. package/lib/node/voice-bridge.d.ts +71 -0
  174. package/lib/node/voice-bridge.js +281 -0
  175. package/lib/node/voices-file.d.ts +39 -0
  176. package/lib/node/voices-file.js +104 -0
  177. package/lib/node/working-directory.d.ts +8 -2
  178. package/lib/node/working-directory.js +7 -0
  179. package/package.json +14 -10
@@ -0,0 +1,71 @@
1
+ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
+ import { type RpcConnection } from '@celljs/rpc/lib/node';
3
+ import { TaBargeIn, type TaExtensionVoices, type TaVoiceEngine, TaVoiceServer, type TaVoiceSession, type TaVoices, type TaVoiceType } from '@celljs/ta-protocol';
4
+ import { VoicesFile } from './voices-file';
5
+ export declare const VOICE_BRIDGE: unique symbol;
6
+ interface OpenVoice {
7
+ id: string;
8
+ connection: RpcConnection;
9
+ engine: TaVoiceEngine;
10
+ speaks: boolean;
11
+ nextSay: number;
12
+ closed: boolean;
13
+ }
14
+ /**
15
+ * The voice services of calls (docs/design/ta-voice.md): the types packages register, voices.json, and the voices
16
+ * pages open, each of its connection and closed with it. A page never gets a key: its audio comes here.
17
+ */
18
+ export declare class VoiceBridge {
19
+ protected readonly codingAgentOptions?: CodingAgentOptions;
20
+ protected readonly types: Map<string, TaVoiceType>;
21
+ protected readonly open: Map<string, OpenVoice>;
22
+ protected nextId: number;
23
+ protected filed?: VoicesFile;
24
+ protected get file(): VoicesFile;
25
+ /** For the server side of packages (TaExtensionHost.voices). */
26
+ readonly extensionVoices: TaExtensionVoices;
27
+ list(): TaVoices;
28
+ /** Opens a service of the type once before it is kept, so that a wrong key is said now. */
29
+ add(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
30
+ /** Its fields as the form gave them, a secret left empty kept as it was; tried before it is written. */
31
+ update(id: string, options: Record<string, unknown>, name?: string): Promise<void>;
32
+ /** The fields of a form of the type, needed ones checked, then opened once and closed: what is kept. */
33
+ protected tried(type: string, options: Record<string, unknown>): Promise<Record<string, unknown>>;
34
+ remove(id: string): void;
35
+ choose(id: string | null): void;
36
+ setBargeIn(bargeIn: Partial<TaBargeIn>): void;
37
+ openFor(connection: RpcConnection, language: string): Promise<TaVoiceSession>;
38
+ send(connection: RpcConnection, id: string, audio: string): void;
39
+ say(connection: RpcConnection, id: string, text: string): number;
40
+ hush(connection: RpcConnection, id: string): void;
41
+ close(connection: RpcConnection, id: string): void;
42
+ protected require(connection: RpcConnection, id: string): OpenVoice;
43
+ protected static where(definition: TaVoiceType, options: Record<string, unknown>): string;
44
+ /** What trying a service hears: nothing is told. */
45
+ protected static readonly SILENT: {
46
+ speech(): void;
47
+ text(): void;
48
+ audio(): void;
49
+ said(): void;
50
+ closed(): void;
51
+ };
52
+ }
53
+ /** The voices for pages (TaVoiceServer), each of the connection that opened it. */
54
+ export declare class TaVoiceServerImpl implements TaVoiceServer {
55
+ protected readonly bridge: VoiceBridge;
56
+ listVoices(): Promise<TaVoices>;
57
+ addVoice(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
58
+ updateVoice(id: string, options: Record<string, unknown>, name?: string): Promise<void>;
59
+ removeVoice(id: string): Promise<void>;
60
+ chooseVoice(id: string | null): Promise<void>;
61
+ setBargeIn(bargeIn: Partial<TaBargeIn>): Promise<void>;
62
+ openVoice(options: {
63
+ language: string;
64
+ }): Promise<TaVoiceSession>;
65
+ sendVoice(voiceId: string, audio: string): Promise<void>;
66
+ sayVoice(voiceId: string, text: string): Promise<number>;
67
+ hushVoice(voiceId: string): Promise<void>;
68
+ closeVoice(voiceId: string): Promise<void>;
69
+ }
70
+ export {};
71
+ //# sourceMappingURL=voice-bridge.d.ts.map
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var VoiceBridge_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.TaVoiceServerImpl = exports.VoiceBridge = exports.VOICE_BRIDGE = void 0;
14
+ const ai_coding_agent_1 = require("@celljs/ai-coding-agent");
15
+ const core_1 = require("@celljs/core");
16
+ const rpc_1 = require("@celljs/rpc");
17
+ const node_1 = require("@celljs/rpc/lib/node");
18
+ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
19
+ const ta_protocol_1 = require("@celljs/ta-protocol");
20
+ const ta_errors_1 = require("./ta-errors");
21
+ const voices_file_1 = require("./voices-file");
22
+ exports.VOICE_BRIDGE = Symbol('VoiceBridge');
23
+ /** The voices a connection may have open at once: a call each, of a page or two. */
24
+ const MAX_PER_CONNECTION = 2;
25
+ /** The longest a reading may be, in characters: a reply read out is cut there. */
26
+ const MAX_SAY = 4000;
27
+ /** The most audio a page may send at once (base64 of about 2 s at 24 kHz). */
28
+ const MAX_AUDIO = 160 * 1024;
29
+ /**
30
+ * The voice services of calls (docs/design/ta-voice.md): the types packages register, voices.json, and the voices
31
+ * pages open, each of its connection and closed with it. A page never gets a key: its audio comes here.
32
+ */
33
+ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
34
+ constructor() {
35
+ this.types = new Map();
36
+ this.open = new Map();
37
+ this.nextId = 0;
38
+ /** For the server side of packages (TaExtensionHost.voices). */
39
+ this.extensionVoices = {
40
+ registerType: (type, definition) => {
41
+ this.types.set(type, definition);
42
+ return () => {
43
+ if (this.types.get(type) === definition) {
44
+ this.types.delete(type);
45
+ }
46
+ };
47
+ },
48
+ };
49
+ }
50
+ get file() {
51
+ var _a;
52
+ var _b, _c;
53
+ (_b = this.filed) !== null && _b !== void 0 ? _b : (this.filed = new voices_file_1.VoicesFile((_c = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _c !== void 0 ? _c : ta_brand_1.TaBrand.agentDir()));
54
+ return this.filed;
55
+ }
56
+ list() {
57
+ var _a;
58
+ const { config } = this.file.safeRead();
59
+ const services = ((_a = config.services) !== null && _a !== void 0 ? _a : []).map(service => {
60
+ const name = service.name ? { name: service.name } : {};
61
+ const definition = this.types.get(service.type);
62
+ if (!definition) {
63
+ return { id: service.id, type: service.type, unavailable: true, ...name };
64
+ }
65
+ // What the page sees of it: never a password or a key.
66
+ const secret = new Set(definition.options.filter(option => option.secret).map(option => option.key));
67
+ const options = Object.fromEntries(Object.entries(service.options).filter(([key]) => !secret.has(key)));
68
+ return { id: service.id, type: service.type, where: VoiceBridge_1.where(definition, service.options), options, ...name };
69
+ });
70
+ const types = [...this.types].map(([type, { title, hint, icon, options, speaks }]) => ({
71
+ type,
72
+ title,
73
+ ...(hint ? { hint } : {}),
74
+ ...(icon ? { icon } : {}),
75
+ options,
76
+ speaks,
77
+ }));
78
+ const use = config.use && services.some(service => service.id === config.use) ? { use: config.use } : {};
79
+ return { services, types, file: this.file.file, bargeIn: ta_protocol_1.TaBargeIn.resolve(config.bargeIn), ...use };
80
+ }
81
+ /** Opens a service of the type once before it is kept, so that a wrong key is said now. */
82
+ async add(type, options, name) {
83
+ const filled = await this.tried(type, options);
84
+ const id = this.file.add(type, filled, (name === null || name === void 0 ? void 0 : name.trim()) || undefined);
85
+ if (!this.file.safeRead().config.use) {
86
+ this.file.use(id);
87
+ }
88
+ return id;
89
+ }
90
+ /** Its fields as the form gave them, a secret left empty kept as it was; tried before it is written. */
91
+ async update(id, options, name) {
92
+ var _a;
93
+ var _b, _c;
94
+ const service = this.file.services().find(each => each.id === id);
95
+ if (!service) {
96
+ throw ta_errors_1.TaErrors.invalidArgument(`There is no voice service ${id}.`, 'Read the services again with listVoices.');
97
+ }
98
+ const secrets = new Set(((_b = (_a = this.types.get(service.type)) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : []).filter(option => option.secret).map(option => option.key));
99
+ const given = { ...(options !== null && options !== void 0 ? options : {}) };
100
+ for (const key of secrets) {
101
+ if (!String((_c = given[key]) !== null && _c !== void 0 ? _c : '').trim() && service.options[key] !== undefined) {
102
+ given[key] = service.options[key];
103
+ }
104
+ }
105
+ const filled = await this.tried(service.type, given);
106
+ this.file.update(id, filled, (name === null || name === void 0 ? void 0 : name.trim()) || undefined);
107
+ }
108
+ /** The fields of a form of the type, needed ones checked, then opened once and closed: what is kept. */
109
+ async tried(type, options) {
110
+ const definition = this.types.get(type);
111
+ if (!definition) {
112
+ throw ta_errors_1.TaErrors.invalidArgument(`There is no voice service of type ${type}.`, 'Turn on the package that adds it.');
113
+ }
114
+ const filled = {};
115
+ for (const option of definition.options) {
116
+ const value = typeof (options === null || options === void 0 ? void 0 : options[option.key]) === 'string' ? String(options[option.key]).trim() : '';
117
+ if (!value && !option.optional) {
118
+ throw ta_errors_1.TaErrors.invalidArgument(`${option.key} is needed.`, 'Fill in every field that is not optional.');
119
+ }
120
+ if (value) {
121
+ filled[option.key] = value;
122
+ }
123
+ }
124
+ const engine = await definition.open(filled, { language: 'zh-CN' }, VoiceBridge_1.SILENT);
125
+ engine.close();
126
+ return filled;
127
+ }
128
+ remove(id) {
129
+ this.file.remove(id);
130
+ }
131
+ choose(id) {
132
+ this.file.use(id !== null && id !== void 0 ? id : undefined);
133
+ }
134
+ setBargeIn(bargeIn) {
135
+ this.file.setBargeIn(ta_protocol_1.TaBargeIn.pick(bargeIn));
136
+ }
137
+ async openFor(connection, language) {
138
+ var _a;
139
+ const service = this.file.inUse();
140
+ if (!service) {
141
+ throw ta_errors_1.TaErrors.invalidArgument('No voice service is chosen for calls.', 'Choose one in Settings → Voice, or call with the voice of the device.');
142
+ }
143
+ const definition = this.types.get(service.type);
144
+ if (!definition) {
145
+ throw ta_errors_1.TaErrors.invalidArgument(`The voice service ${(_a = service.name) !== null && _a !== void 0 ? _a : service.id} is of type ${service.type}.`, 'Turn on the package that adds it.');
146
+ }
147
+ if ([...this.open.values()].filter(voice => voice.connection === connection).length >= MAX_PER_CONNECTION) {
148
+ throw ta_errors_1.TaErrors.invalidArgument('This page has calls open already.', 'Hang up a call first.');
149
+ }
150
+ const id = `v${++this.nextId}`;
151
+ const tell = (event) => {
152
+ if (!connection.closed) {
153
+ connection
154
+ .client(ta_protocol_1.TaClient)
155
+ .onVoiceEvent(event)
156
+ .catch(() => undefined);
157
+ }
158
+ };
159
+ const engine = await definition.open(service.options, { language: String(language || 'zh-CN') }, {
160
+ speech: () => tell({ voiceId: id, type: 'speech' }),
161
+ text: (text, final) => tell({ voiceId: id, type: 'text', text, final }),
162
+ audio: (pcm, say) => tell({ voiceId: id, type: 'audio', say, data: Buffer.from(pcm).toString('base64') }),
163
+ said: say => tell({ voiceId: id, type: 'said', say }),
164
+ closed: error => {
165
+ const voice = this.open.get(id);
166
+ if (voice && !voice.closed) {
167
+ voice.closed = true;
168
+ this.open.delete(id);
169
+ tell({ voiceId: id, type: 'closed', ...(error ? { error } : {}) });
170
+ }
171
+ },
172
+ });
173
+ const voice = { id, connection, engine, speaks: definition.speaks && !!engine.say, nextSay: 0, closed: false };
174
+ this.open.set(id, voice);
175
+ connection.onClose(() => this.close(connection, id));
176
+ const bargeIn = ta_protocol_1.TaBargeIn.resolve(this.file.safeRead().config.bargeIn);
177
+ return { voiceId: id, inputRate: engine.inputRate, outputRate: engine.outputRate, speaks: voice.speaks, bargeIn };
178
+ }
179
+ send(connection, id, audio) {
180
+ if (typeof audio !== 'string' || audio.length > MAX_AUDIO) {
181
+ throw ta_errors_1.TaErrors.invalidArgument('The audio is too long.', 'Send it in pieces of about 100 ms.');
182
+ }
183
+ this.require(connection, id).engine.send(Buffer.from(audio, 'base64'));
184
+ }
185
+ say(connection, id, text) {
186
+ const voice = this.require(connection, id);
187
+ if (!voice.speaks || !voice.engine.say) {
188
+ throw ta_errors_1.TaErrors.invalidArgument('This voice service does not read text.', 'Read with the voice of the device.');
189
+ }
190
+ const say = ++voice.nextSay;
191
+ voice.engine.say(String(text !== null && text !== void 0 ? text : '').slice(0, MAX_SAY), say);
192
+ return say;
193
+ }
194
+ hush(connection, id) {
195
+ this.require(connection, id).engine.hush();
196
+ }
197
+ close(connection, id) {
198
+ const voice = this.open.get(id);
199
+ if (!voice || voice.connection !== connection || voice.closed) {
200
+ return;
201
+ }
202
+ voice.closed = true;
203
+ this.open.delete(id);
204
+ try {
205
+ voice.engine.close();
206
+ }
207
+ catch (_a) {
208
+ // Closed already.
209
+ }
210
+ }
211
+ require(connection, id) {
212
+ const voice = this.open.get(id);
213
+ if (!voice || voice.connection !== connection) {
214
+ throw ta_errors_1.TaErrors.invalidArgument(`There is no voice ${id} open.`, 'Open it again with openVoice.');
215
+ }
216
+ return voice;
217
+ }
218
+ static where(definition, options) {
219
+ try {
220
+ return definition.where(options);
221
+ }
222
+ catch (_a) {
223
+ return '';
224
+ }
225
+ }
226
+ };
227
+ exports.VoiceBridge = VoiceBridge;
228
+ /** What trying a service hears: nothing is told. */
229
+ VoiceBridge.SILENT = { speech() { }, text() { }, audio() { }, said() { }, closed() { } };
230
+ __decorate([
231
+ (0, core_1.Value)(ai_coding_agent_1.CODING_AGENT_OPTIONS),
232
+ __metadata("design:type", Object)
233
+ ], VoiceBridge.prototype, "codingAgentOptions", void 0);
234
+ exports.VoiceBridge = VoiceBridge = VoiceBridge_1 = __decorate([
235
+ (0, core_1.Component)(exports.VOICE_BRIDGE)
236
+ ], VoiceBridge);
237
+ /** The voices for pages (TaVoiceServer), each of the connection that opened it. */
238
+ let TaVoiceServerImpl = class TaVoiceServerImpl {
239
+ listVoices() {
240
+ return ta_errors_1.TaErrors.guard(() => this.bridge.list());
241
+ }
242
+ addVoice(type, options, name) {
243
+ return ta_errors_1.TaErrors.guard(() => this.bridge.add(type, options !== null && options !== void 0 ? options : {}, name !== null && name !== void 0 ? name : undefined));
244
+ }
245
+ updateVoice(id, options, name) {
246
+ return ta_errors_1.TaErrors.guard(() => this.bridge.update(id, options !== null && options !== void 0 ? options : {}, name !== null && name !== void 0 ? name : undefined));
247
+ }
248
+ removeVoice(id) {
249
+ return ta_errors_1.TaErrors.guard(() => this.bridge.remove(id));
250
+ }
251
+ chooseVoice(id) {
252
+ return ta_errors_1.TaErrors.guard(() => this.bridge.choose(id !== null && id !== void 0 ? id : null));
253
+ }
254
+ setBargeIn(bargeIn) {
255
+ return ta_errors_1.TaErrors.guard(() => this.bridge.setBargeIn(bargeIn !== null && bargeIn !== void 0 ? bargeIn : {}));
256
+ }
257
+ openVoice(options) {
258
+ return ta_errors_1.TaErrors.guard(() => this.bridge.openFor(node_1.RpcContext.requireConnection(), options === null || options === void 0 ? void 0 : options.language));
259
+ }
260
+ sendVoice(voiceId, audio) {
261
+ return ta_errors_1.TaErrors.guard(() => this.bridge.send(node_1.RpcContext.requireConnection(), voiceId, audio));
262
+ }
263
+ sayVoice(voiceId, text) {
264
+ return ta_errors_1.TaErrors.guard(() => this.bridge.say(node_1.RpcContext.requireConnection(), voiceId, text));
265
+ }
266
+ hushVoice(voiceId) {
267
+ return ta_errors_1.TaErrors.guard(() => this.bridge.hush(node_1.RpcContext.requireConnection(), voiceId));
268
+ }
269
+ closeVoice(voiceId) {
270
+ return ta_errors_1.TaErrors.guard(() => this.bridge.close(node_1.RpcContext.requireConnection(), voiceId));
271
+ }
272
+ };
273
+ exports.TaVoiceServerImpl = TaVoiceServerImpl;
274
+ __decorate([
275
+ (0, core_1.Autowired)(exports.VOICE_BRIDGE),
276
+ __metadata("design:type", VoiceBridge)
277
+ ], TaVoiceServerImpl.prototype, "bridge", void 0);
278
+ exports.TaVoiceServerImpl = TaVoiceServerImpl = __decorate([
279
+ (0, rpc_1.Rpc)(ta_protocol_1.TaVoiceServer)
280
+ ], TaVoiceServerImpl);
281
+ //# sourceMappingURL=voice-bridge.js.map
@@ -0,0 +1,39 @@
1
+ import type { TaBargeIn } from '@celljs/ta-protocol';
2
+ /** A service of voices.json: a type a package registered, and the options of its form. */
3
+ export interface VoiceServiceEntry {
4
+ id: string;
5
+ type: string;
6
+ name?: string;
7
+ options: Record<string, unknown>;
8
+ }
9
+ export interface VoicesConfig {
10
+ services?: VoiceServiceEntry[];
11
+ /** The service calls use; none: the voice of the device. */
12
+ use?: string;
13
+ /** When a sound stops what the service reads: any of it, over the defaults (TaBargeIn.resolve). */
14
+ bargeIn?: Partial<TaBargeIn>;
15
+ }
16
+ /** voices.json of the agent directory (docs/design/ta-voice.md 3): its keys stay there, written 0600. */
17
+ export declare class VoicesFile {
18
+ readonly file: string;
19
+ constructor(agentDir: string);
20
+ read(): VoicesConfig;
21
+ /** What reads, or nothing with why it does not parse. */
22
+ safeRead(): {
23
+ config: VoicesConfig;
24
+ error?: string;
25
+ };
26
+ services(): VoiceServiceEntry[];
27
+ /** The service in use, if it is still there. */
28
+ inUse(): VoiceServiceEntry | undefined;
29
+ /** Its id: the type with a number when there is one of it already. */
30
+ add(type: string, options: Record<string, unknown>, name?: string): string;
31
+ /** Its options and name, the rest as it was; throws for one that is not there. */
32
+ update(id: string, options: Record<string, unknown>, name?: string): void;
33
+ /** Sets keys of bargeIn, the others kept. */
34
+ setBargeIn(bargeIn: Partial<TaBargeIn>): void;
35
+ remove(id: string): void;
36
+ use(id: string | undefined): void;
37
+ protected write(config: VoicesConfig): void;
38
+ }
39
+ //# sourceMappingURL=voices-file.d.ts.map
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoicesFile = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ /** voices.json of the agent directory (docs/design/ta-voice.md 3): its keys stay there, written 0600. */
7
+ class VoicesFile {
8
+ constructor(agentDir) {
9
+ this.file = (0, node_path_1.join)(agentDir, 'voices.json');
10
+ }
11
+ read() {
12
+ let text;
13
+ try {
14
+ text = (0, node_fs_1.readFileSync)(this.file, 'utf8');
15
+ }
16
+ catch (_a) {
17
+ return {};
18
+ }
19
+ const config = JSON.parse(text);
20
+ const services = Array.isArray(config === null || config === void 0 ? void 0 : config.services)
21
+ ? config.services.filter(service => service && typeof service.id === 'string' && typeof service.type === 'string' && typeof service.options === 'object')
22
+ : [];
23
+ return {
24
+ services,
25
+ ...(typeof (config === null || config === void 0 ? void 0 : config.use) === 'string' ? { use: config.use } : {}),
26
+ ...((config === null || config === void 0 ? void 0 : config.bargeIn) && typeof config.bargeIn === 'object' ? { bargeIn: config.bargeIn } : {}),
27
+ };
28
+ }
29
+ /** What reads, or nothing with why it does not parse. */
30
+ safeRead() {
31
+ try {
32
+ return { config: this.read() };
33
+ }
34
+ catch (error) {
35
+ return { config: {}, error: error instanceof Error ? error.message : String(error) };
36
+ }
37
+ }
38
+ services() {
39
+ var _a;
40
+ return (_a = this.safeRead().config.services) !== null && _a !== void 0 ? _a : [];
41
+ }
42
+ /** The service in use, if it is still there. */
43
+ inUse() {
44
+ const { services = [], use } = this.safeRead().config;
45
+ return use ? services.find(service => service.id === use) : undefined;
46
+ }
47
+ /** Its id: the type with a number when there is one of it already. */
48
+ add(type, options, name) {
49
+ var _a;
50
+ const config = this.read();
51
+ const services = (_a = config.services) !== null && _a !== void 0 ? _a : [];
52
+ const stem = type.replace(/[^a-z0-9-]/gi, '').toLowerCase() || 'voice';
53
+ let id = stem;
54
+ for (let n = 2; services.some(service => service.id === id); n++) {
55
+ id = `${stem}-${n}`;
56
+ }
57
+ services.push({ id, type, ...(name ? { name } : {}), options });
58
+ this.write({ ...config, services });
59
+ return id;
60
+ }
61
+ /** Its options and name, the rest as it was; throws for one that is not there. */
62
+ update(id, options, name) {
63
+ var _a;
64
+ const config = this.read();
65
+ const services = (_a = config.services) !== null && _a !== void 0 ? _a : [];
66
+ const at = services.findIndex(service => service.id === id);
67
+ if (at < 0) {
68
+ throw new Error(`There is no voice service ${id} in voices.json.`);
69
+ }
70
+ const { name: _, ...kept } = services[at];
71
+ services[at] = { ...kept, ...(name ? { name } : {}), options };
72
+ this.write({ ...config, services });
73
+ }
74
+ /** Sets keys of bargeIn, the others kept. */
75
+ setBargeIn(bargeIn) {
76
+ const config = this.read();
77
+ this.write({ ...config, bargeIn: { ...config.bargeIn, ...bargeIn } });
78
+ }
79
+ remove(id) {
80
+ var _a;
81
+ const config = this.read();
82
+ const services = ((_a = config.services) !== null && _a !== void 0 ? _a : []).filter(service => service.id !== id);
83
+ const { use, ...rest } = config;
84
+ this.write({ ...rest, services, ...(use && use !== id ? { use } : {}) });
85
+ }
86
+ use(id) {
87
+ var _a, _b;
88
+ const config = this.read();
89
+ if (id !== undefined && !((_a = config.services) !== null && _a !== void 0 ? _a : []).some(service => service.id === id)) {
90
+ throw new Error(`There is no voice service ${id} in voices.json.`);
91
+ }
92
+ const { use: _, ...rest } = config;
93
+ this.write({ ...rest, services: (_b = config.services) !== null && _b !== void 0 ? _b : [], ...(id ? { use: id } : {}) });
94
+ }
95
+ write(config) {
96
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(this.file), { recursive: true });
97
+ const temporary = `${this.file}.${process.pid}.tmp`;
98
+ (0, node_fs_1.writeFileSync)(temporary, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
99
+ (0, node_fs_1.chmodSync)(temporary, 0o600);
100
+ (0, node_fs_1.renameSync)(temporary, this.file);
101
+ }
102
+ }
103
+ exports.VoicesFile = VoicesFile;
104
+ //# sourceMappingURL=voices-file.js.map
@@ -1,7 +1,8 @@
1
1
  export declare const TaWorkingDirectory: unique symbol;
2
2
  /**
3
- * The working directory the user chose for ta serve (TaServer.setWorkingDirectory), and the hosts of the
4
- * remote directories opened lately (TaRemoteServer), kept across restarts.
3
+ * The working directory the user chose for ta serve (TaServer.setWorkingDirectory), the hosts of the
4
+ * remote directories opened lately (TaRemoteServer) and the desktops added (TaScreenShareServer), kept across
5
+ * restarts.
5
6
  */
6
7
  export interface TaWorkingDirectory {
7
8
  get(): string | undefined;
@@ -10,6 +11,9 @@ export interface TaWorkingDirectory {
10
11
  recentHosts(): string[];
11
12
  addRecentHost(host: string): void;
12
13
  removeRecentHost(host: string): void;
14
+ /** The desktops the user added, as kept: checked by whoever reads them. */
15
+ desktops(): unknown[];
16
+ setDesktops(desktops: unknown[]): void;
13
17
  }
14
18
  /** In ta.json of the agent directory, beside Ta's other settings of its own; the file keeps its other keys. */
15
19
  export declare class TaWorkingDirectoryImpl implements TaWorkingDirectory {
@@ -19,6 +23,8 @@ export declare class TaWorkingDirectoryImpl implements TaWorkingDirectory {
19
23
  recentHosts(): string[];
20
24
  addRecentHost(host: string): void;
21
25
  removeRecentHost(host: string): void;
26
+ desktops(): unknown[];
27
+ setDesktops(desktops: unknown[]): void;
22
28
  protected write(changes: Record<string, unknown>): void;
23
29
  protected read(): Record<string, unknown>;
24
30
  }
@@ -43,6 +43,13 @@ let TaWorkingDirectoryImpl = class TaWorkingDirectoryImpl {
43
43
  this.write({ remoteHosts: hosts.filter(other => other !== host) });
44
44
  }
45
45
  }
46
+ desktops() {
47
+ const { desktops } = this.read();
48
+ return Array.isArray(desktops) ? desktops : [];
49
+ }
50
+ setDesktops(desktops) {
51
+ this.write({ desktops });
52
+ }
46
53
  write(changes) {
47
54
  (0, node_fs_1.writeFileSync)(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), ...changes }, null, 2)}\n`);
48
55
  (0, node_fs_1.renameSync)(`${this.file}.tmp`, this.file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-host",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "ta serve: pi sessions for many clients over WebSocket",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -34,15 +34,15 @@
34
34
  "watch": "tsc -b -w --preserveWatchOutput"
35
35
  },
36
36
  "dependencies": {
37
- "@celljs/ai-agent": "4.16.0",
38
- "@celljs/ai-coding-agent": "4.16.0",
39
- "@celljs/core": "4.16.0",
40
- "@celljs/rpc": "4.16.0",
41
- "@celljs/ta-exec": "4.16.0",
42
- "@celljs/ta-harness": "4.16.0",
43
- "@celljs/ta-protocol": "4.16.0",
44
- "@celljs/ta-relay": "4.16.0",
45
- "@celljs/web": "4.16.0",
37
+ "@celljs/ai-agent": "4.18.0",
38
+ "@celljs/ai-coding-agent": "4.18.0",
39
+ "@celljs/core": "4.18.0",
40
+ "@celljs/rpc": "4.18.0",
41
+ "@celljs/ta-exec": "4.18.0",
42
+ "@celljs/ta-harness": "4.18.0",
43
+ "@celljs/ta-protocol": "4.18.0",
44
+ "@celljs/ta-relay": "4.18.0",
45
+ "@celljs/web": "4.18.0",
46
46
  "@earendil-works/pi-coding-agent": "^1.5.2"
47
47
  },
48
48
  "devDependencies": {
@@ -75,6 +75,10 @@
75
75
  "import": "./esm/node/remote/index.js",
76
76
  "default": "./lib/node/remote/index.js"
77
77
  },
78
+ "./lib/node/screen-share": {
79
+ "import": "./esm/node/screen-share/index.js",
80
+ "default": "./lib/node/screen-share/index.js"
81
+ },
78
82
  "./lib/node/session-storage": {
79
83
  "import": "./esm/node/session-storage/index.js",
80
84
  "default": "./lib/node/session-storage/index.js"