@celljs/ta-protocol 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 (81) hide show
  1. package/esm/common/access-protocol.d.ts +41 -0
  2. package/esm/common/access-protocol.js +7 -0
  3. package/esm/common/app-protocol.d.ts +120 -0
  4. package/esm/common/app-protocol.js +213 -0
  5. package/esm/common/delegate-protocol.d.ts +30 -0
  6. package/esm/common/delegate-protocol.js +52 -0
  7. package/esm/common/deployment-protocol.d.ts +72 -0
  8. package/esm/common/deployment-protocol.js +171 -0
  9. package/esm/common/error-protocol.d.ts +42 -0
  10. package/esm/common/error-protocol.js +45 -0
  11. package/esm/common/event-protocol.d.ts +63 -0
  12. package/esm/common/event-protocol.js +2 -0
  13. package/esm/common/gateway-protocol.d.ts +29 -0
  14. package/esm/common/index.d.ts +11 -0
  15. package/esm/common/index.js +11 -0
  16. package/esm/common/message-protocol.d.ts +134 -0
  17. package/esm/common/message-protocol.js +322 -0
  18. package/esm/common/page-protocol.d.ts +56 -0
  19. package/esm/common/page-protocol.js +12 -0
  20. package/esm/common/path-map.d.ts +24 -0
  21. package/esm/common/path-map.js +127 -0
  22. package/esm/common/presence-protocol.js +1 -1
  23. package/esm/common/redactor.d.ts +12 -0
  24. package/esm/common/redactor.js +49 -11
  25. package/esm/common/relay-protocol.d.ts +20 -0
  26. package/esm/common/room-protocol.d.ts +52 -1
  27. package/esm/common/said-protocol.d.ts +76 -0
  28. package/esm/common/said-protocol.js +239 -0
  29. package/esm/common/screen-share-protocol.d.ts +304 -0
  30. package/esm/common/screen-share-protocol.js +88 -0
  31. package/esm/common/settings-protocol.d.ts +8 -0
  32. package/esm/common/settings-protocol.js +2 -0
  33. package/esm/common/ta-extension-host.d.ts +64 -1
  34. package/esm/common/ta-extension-host.js +8 -0
  35. package/esm/common/ta-protocol.d.ts +53 -175
  36. package/esm/common/ta-protocol.js +0 -234
  37. package/esm/common/team-protocol.d.ts +13 -2
  38. package/esm/common/team-protocol.js +27 -2
  39. package/esm/common/voice-protocol.d.ts +184 -0
  40. package/esm/common/voice-protocol.js +57 -0
  41. package/lib/common/access-protocol.d.ts +41 -0
  42. package/lib/common/access-protocol.js +8 -1
  43. package/lib/common/app-protocol.d.ts +121 -0
  44. package/lib/common/app-protocol.js +216 -0
  45. package/lib/common/delegate-protocol.d.ts +31 -0
  46. package/lib/common/delegate-protocol.js +55 -0
  47. package/lib/common/deployment-protocol.d.ts +73 -0
  48. package/lib/common/deployment-protocol.js +175 -0
  49. package/lib/common/error-protocol.d.ts +43 -0
  50. package/lib/common/error-protocol.js +48 -0
  51. package/lib/common/event-protocol.d.ts +64 -0
  52. package/lib/common/event-protocol.js +3 -0
  53. package/lib/common/gateway-protocol.d.ts +29 -0
  54. package/lib/common/index.d.ts +11 -0
  55. package/lib/common/index.js +11 -0
  56. package/lib/common/message-protocol.d.ts +135 -0
  57. package/lib/common/message-protocol.js +325 -0
  58. package/lib/common/page-protocol.d.ts +57 -0
  59. package/lib/common/page-protocol.js +15 -0
  60. package/lib/common/path-map.d.ts +25 -0
  61. package/lib/common/path-map.js +130 -0
  62. package/lib/common/presence-protocol.js +7 -7
  63. package/lib/common/redactor.d.ts +12 -0
  64. package/lib/common/redactor.js +49 -11
  65. package/lib/common/relay-protocol.d.ts +20 -0
  66. package/lib/common/room-protocol.d.ts +52 -1
  67. package/lib/common/said-protocol.d.ts +77 -0
  68. package/lib/common/said-protocol.js +242 -0
  69. package/lib/common/screen-share-protocol.d.ts +305 -0
  70. package/lib/common/screen-share-protocol.js +91 -0
  71. package/lib/common/settings-protocol.d.ts +8 -0
  72. package/lib/common/settings-protocol.js +3 -1
  73. package/lib/common/ta-extension-host.d.ts +64 -1
  74. package/lib/common/ta-extension-host.js +9 -1
  75. package/lib/common/ta-protocol.d.ts +53 -175
  76. package/lib/common/ta-protocol.js +1 -235
  77. package/lib/common/team-protocol.d.ts +13 -2
  78. package/lib/common/team-protocol.js +28 -3
  79. package/lib/common/voice-protocol.d.ts +185 -0
  80. package/lib/common/voice-protocol.js +60 -0
  81. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_RESUME_MESSAGE = exports.TA_SERVE_RESTART_EXIT_CODE = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
3
+ exports.TaSlashCommandUtil = exports.TA_RESUME_MESSAGE = exports.TA_SERVE_RESTART_EXIT_CODE = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
4
4
  exports.TaServer = Symbol('TaServer');
5
5
  exports.TaClient = Symbol('TaClient');
6
6
  /** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
@@ -16,50 +16,6 @@ exports.TA_SERVE_RESTART_EXIT_CODE = 75;
16
16
  * the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
17
17
  */
18
18
  exports.TA_RESUME_MESSAGE = 'ta-resume';
19
- /** The stable `code` of each failure of a {@link TaServer} call. */
20
- exports.TaErrorCode = {
21
- SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
22
- SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
23
- TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
24
- MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
25
- MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
26
- INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
27
- COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
28
- /** Compacting found nothing to compact: the conversation is still short. */
29
- NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
30
- /** Compacting found nothing to compact: nothing came after the last compaction. */
31
- ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
32
- /** The session is answering or compacting, which has to end first. */
33
- SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
34
- /** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
35
- CANCELLED: 'CELL_TA_CANCELLED',
36
- /** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
37
- NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
38
- /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
39
- ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
40
- /** Behind a gateway: more messages a minute than one may send; try again in a moment. */
41
- RATE_LIMITED: 'CELL_TA_RATE_LIMITED',
42
- /** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
43
- FORBIDDEN: 'CELL_TA_FORBIDDEN',
44
- /** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
45
- LIMIT: 'CELL_TA_LIMIT',
46
- /** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
47
- CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST',
48
- };
49
- var TaErrorUtil;
50
- (function (TaErrorUtil) {
51
- /** The {@link TaErrorCode} of a failure: `code` of the client's error, `data.code` of the server's own, called in its process. */
52
- function code(error) {
53
- var _a;
54
- var _b;
55
- const failure = error;
56
- const code = (_b = failure === null || failure === void 0 ? void 0 : failure.code) !== null && _b !== void 0 ? _b : (_a = failure === null || failure === void 0 ? void 0 : failure.data) === null || _a === void 0 ? void 0 : _a.code;
57
- return typeof code === 'string' ? code : undefined;
58
- }
59
- TaErrorUtil.code = code;
60
- })(TaErrorUtil || (exports.TaErrorUtil = TaErrorUtil = {}));
61
- /** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
62
- exports.TA_RPC_ERROR_CODE = -32050;
63
19
  var TaSlashCommandUtil;
64
20
  (function (TaSlashCommandUtil) {
65
21
  /** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
@@ -70,194 +26,4 @@ var TaSlashCommandUtil;
70
26
  }
71
27
  TaSlashCommandUtil.description = description;
72
28
  })(TaSlashCommandUtil || (exports.TaSlashCommandUtil = TaSlashCommandUtil = {}));
73
- /**
74
- * A message of the user may start with a `<context>` block: what the model reads besides the message
75
- * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
76
- */
77
- var TaMessageContext;
78
- (function (TaMessageContext) {
79
- const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
80
- function wrap(context, message) {
81
- return `<context>\n${context}\n</context>\n${message}`;
82
- }
83
- TaMessageContext.wrap = wrap;
84
- /** The message without its context: what the user sees of it. */
85
- function strip(message) {
86
- return message.replace(BLOCK, '');
87
- }
88
- TaMessageContext.strip = strip;
89
- /** The context of the message, without its tags; undefined without one. */
90
- function read(message) {
91
- var _a;
92
- const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
93
- return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
94
- }
95
- TaMessageContext.read = read;
96
- })(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
97
- /**
98
- * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
99
- * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
100
- * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
101
- */
102
- var TaMessageSource;
103
- (function (TaMessageSource) {
104
- /** The double of the web page: the tasks it hands out, what it tells them on the way. */
105
- TaMessageSource.DOUBLE = 'ta:double';
106
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
107
- /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
108
- function mark(message, from, detail) {
109
- if (/^[/!]/.test(message) || of(message)) {
110
- return message;
111
- }
112
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
113
- const context = TaMessageContext.read(message);
114
- return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
115
- }
116
- TaMessageSource.mark = mark;
117
- function of(message) {
118
- const context = TaMessageContext.read(message);
119
- const match = context === undefined ? null : LINE.exec(context);
120
- return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
121
- }
122
- TaMessageSource.of = of;
123
- })(TaMessageSource || (exports.TaMessageSource = TaMessageSource = {}));
124
- /**
125
- * pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
126
- * the image was before it made it smaller, and what it was converted from. Clients leave them out.
127
- */
128
- var TaImageNote;
129
- (function (TaImageNote) {
130
- const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
131
- /** The text without the notes of its images: what the user sees of it. */
132
- function strip(text) {
133
- const lines = text.split('\n');
134
- const kept = lines.filter(line => !NOTE.test(line.trim()));
135
- if (kept.length === lines.length) {
136
- return text;
137
- }
138
- return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
139
- }
140
- TaImageNote.strip = strip;
141
- })(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
142
- /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
143
- var TaImageSize;
144
- (function (TaImageSize) {
145
- /** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
146
- const JPEG_BYTES = 256 * 1024;
147
- function of(base64) {
148
- var _a, _b, _c;
149
- let bytes;
150
- try {
151
- // Whole groups of four characters only.
152
- const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
153
- bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
154
- }
155
- catch (_d) {
156
- return undefined;
157
- }
158
- const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== void 0 ? _a : gif(bytes)) !== null && _b !== void 0 ? _b : webp(bytes)) !== null && _c !== void 0 ? _c : jpeg(bytes);
159
- return size && size.width > 0 && size.height > 0 ? size : undefined;
160
- }
161
- TaImageSize.of = of;
162
- function u16be(bytes, at) {
163
- return (bytes[at] << 8) | bytes[at + 1];
164
- }
165
- function u16le(bytes, at) {
166
- return bytes[at] | (bytes[at + 1] << 8);
167
- }
168
- function u24le(bytes, at) {
169
- return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
170
- }
171
- function u32be(bytes, at) {
172
- return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
173
- }
174
- function text(bytes, at, length) {
175
- return String.fromCharCode(...bytes.subarray(at, at + length));
176
- }
177
- function png(bytes) {
178
- return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
179
- }
180
- function gif(bytes) {
181
- return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
182
- }
183
- function webp(bytes) {
184
- if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
185
- return undefined;
186
- }
187
- switch (text(bytes, 12, 4)) {
188
- case 'VP8 ':
189
- return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
190
- case 'VP8L': {
191
- const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
192
- return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
193
- }
194
- case 'VP8X':
195
- return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
196
- default:
197
- return undefined;
198
- }
199
- }
200
- function jpeg(bytes) {
201
- if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
202
- return undefined;
203
- }
204
- let at = 2;
205
- while (at + 9 < bytes.length) {
206
- if (bytes[at] !== 0xff) {
207
- return undefined;
208
- }
209
- const marker = bytes[at + 1];
210
- // A start of frame (not DHT, JPG or DAC, which share the range) says the size.
211
- if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
212
- return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
213
- }
214
- at += 2 + u16be(bytes, at + 2);
215
- }
216
- return undefined;
217
- }
218
- })(TaImageSize || (exports.TaImageSize = TaImageSize = {}));
219
- /**
220
- * An external agent that compacts its own context says the summary it goes on from as text, in tags
221
- * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
222
- */
223
- var TaAgentSummary;
224
- (function (TaAgentSummary) {
225
- const START = /^\s*<conversation_history_summary>/;
226
- const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
227
- /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
228
- function read(text) {
229
- if (!START.test(text)) {
230
- return undefined;
231
- }
232
- return text
233
- .replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
234
- .replace(/<\/?\w*$/, '')
235
- .trim();
236
- }
237
- TaAgentSummary.read = read;
238
- /** The text without the summary it starts with. */
239
- function strip(text) {
240
- return text.replace(BLOCK, '');
241
- }
242
- TaAgentSummary.strip = strip;
243
- })(TaAgentSummary || (exports.TaAgentSummary = TaAgentSummary = {}));
244
- /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
245
- var TaSkillUse;
246
- (function (TaSkillUse) {
247
- const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
248
- function parse(message) {
249
- var _a;
250
- const match = BLOCK.exec(message);
251
- if (!match) {
252
- return undefined;
253
- }
254
- return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
255
- }
256
- TaSkillUse.parse = parse;
257
- /** What the user typed: `/skill:name` and what follows. */
258
- function command(use) {
259
- return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
260
- }
261
- TaSkillUse.command = command;
262
- })(TaSkillUse || (exports.TaSkillUse = TaSkillUse = {}));
263
29
  //# sourceMappingURL=ta-protocol.js.map
@@ -16,7 +16,7 @@ export interface TaSharedRef {
16
16
  /** What an action is done on. */
17
17
  export interface TaResource {
18
18
  /** `session`: a conversation, by its file; `dir`: a directory or a file in it, by its path; `agent`, `channel`: one of ta-channels, by its id. */
19
- kind: 'session' | 'dir' | 'agent' | 'channel';
19
+ kind: 'session' | 'dir' | 'agent' | 'channel' | 'desktop';
20
20
  /** The session file, the path, or the id of the agent or channel. */
21
21
  id: string;
22
22
  /** A session: where it works. */
@@ -128,14 +128,25 @@ export interface TaActionInfo {
128
128
  scoped?: boolean;
129
129
  /** Reaches beyond what Ta checks (a command can touch any file): only for people trusted. */
130
130
  risky?: boolean;
131
+ /** `single`: given only on its own to one person, never by a role (docs/design/ta-desktop-remote.md 6.2). */
132
+ grant?: 'role' | 'single';
131
133
  }
132
- export type TaActionArea = 'chat' | 'agent' | 'channel' | 'task' | 'files' | 'commands' | 'hosts' | 'models' | 'cron' | 'extensions' | 'settings' | 'members' | 'audit';
134
+ export type TaActionArea = 'chat' | 'agent' | 'channel' | 'task' | 'files' | 'commands' | 'hosts' | 'models' | 'cron' | 'extensions' | 'settings' | 'members' | 'audit' | 'desktop';
133
135
  /** Every action of Ta itself; packages add their own (`pi.permissions` of their package.json). */
134
136
  export declare const TA_ACTIONS: readonly TaActionInfo[];
137
+ /**
138
+ * Actions of the owner alone (docs/design/ta-desktop-remote.md 6.2): their words for records and notices, never in
139
+ * TA_ACTIONS, so that no role or grant gives them; TaActionUtil.grantable says no to every one of their areas.
140
+ */
141
+ export declare const TA_OWNER_ACTIONS: readonly TaActionInfo[];
135
142
  export declare namespace TaActionUtil {
136
143
  function info(id: string): TaActionInfo | undefined;
137
144
  /** Its title in a language such as `zh-CN`; the id for an action of no catalog. */
138
145
  function title(id: string, language: string): string;
146
+ /** Whether an action may be given to someone at all, by a role or on its own: one of TA_ACTIONS, of no area of the owner's. */
147
+ function grantable(id: string): boolean;
148
+ /** Whether an action may be in a role: grantable, and not one given only on its own (`grant: 'single'`). */
149
+ function inRoles(id: string): boolean;
139
150
  /** Whether `path` is `dir` or inside it; both absolute, `/` separated. */
140
151
  function inside(dir: string, path: string): boolean;
141
152
  }
@@ -6,7 +6,7 @@
6
6
  * may do anything.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TaActionUtil = exports.TA_ACTIONS = exports.TA_ACCESS_REQUEST_EVENT = exports.TaPermissionUtil = exports.TA_UNDECLARED = exports.TA_INVITE_PREFIX = exports.TA_OWNER = void 0;
9
+ exports.TaActionUtil = exports.TA_OWNER_ACTIONS = exports.TA_ACTIONS = exports.TA_ACCESS_REQUEST_EVENT = exports.TaPermissionUtil = exports.TA_UNDECLARED = exports.TA_INVITE_PREFIX = exports.TA_OWNER = void 0;
10
10
  const language_1 = require("./language");
11
11
  /** The user of the Ta: its own pages, devices and token. Everyone else is let in by a package. */
12
12
  exports.TA_OWNER = 'owner';
@@ -70,7 +70,8 @@ exports.TA_ACTIONS = [
70
70
  action('commands.terminal', 'Open terminals', '打开终端', '開啟終端機', 'ターミナルを開く', { scoped: true, risky: true }),
71
71
  action('hosts.use', 'Use remote hosts', '使用远程主机', '使用遠端主機', 'リモートホストを使用', { risky: true }),
72
72
  action('models.use', 'Use the models', '使用模型', '使用模型', 'モデルを使用'),
73
- action('models.manage', 'Sign in to models', '登录和更换模型账号', '登入和更換模型帳號', 'モデルアカウントにサインイン・変更'),
73
+ // In no role: who has it may send the owner's conversations to a service of their own (docs/design/ta-desktop-remote.md 6.2).
74
+ action('models.manage', 'Sign in to models', '登录和更换模型账号', '登入和更換模型帳號', 'モデルアカウントにサインイン・変更', { grant: 'single' }),
74
75
  action('cron.view', 'See scheduled tasks', '查看定时任务', '檢視定時任務', 'スケジュールタスクを確認'),
75
76
  action('cron.manage', 'Change scheduled tasks', '管理定时任务', '管理定時任務', 'スケジュールタスクを管理'),
76
77
  action('extensions.use', 'Use extensions', '使用扩展', '使用擴充功能', '拡張機能を使用'),
@@ -83,9 +84,21 @@ exports.TA_ACTIONS = [
83
84
  action('members.roles', 'Change roles and members', '管理角色和成员', '管理角色和成員', 'ロールとメンバーを管理'),
84
85
  action('audit.view', 'See the record', '查看记录', '檢視記錄', 'レコードを確認'),
85
86
  ];
87
+ /**
88
+ * Actions of the owner alone (docs/design/ta-desktop-remote.md 6.2): their words for records and notices, never in
89
+ * TA_ACTIONS, so that no role or grant gives them; TaActionUtil.grantable says no to every one of their areas.
90
+ */
91
+ exports.TA_OWNER_ACTIONS = [
92
+ action('desktop.view', 'See remote desktops', '查看远程桌面', '檢視遠端桌面', 'リモートデスクトップを見る', { risky: true }),
93
+ action('desktop.control', 'Work remote desktops', '操作远程桌面', '操作遠端桌面', 'リモートデスクトップを操作', { risky: true }),
94
+ ];
95
+ /** The areas of TA_OWNER_ACTIONS: nothing of them is given to anyone, whatever a role or team.json says. */
96
+ const OWNER_AREAS = ['desktop'];
86
97
  var TaActionUtil;
87
98
  (function (TaActionUtil) {
88
99
  const byId = new Map(exports.TA_ACTIONS.map(one => [one.id, one]));
100
+ /** Titles of the owner's actions too, for records and notices. */
101
+ const titled = new Map([...exports.TA_ACTIONS, ...exports.TA_OWNER_ACTIONS].map(one => [one.id, one]));
89
102
  function info(id) {
90
103
  return byId.get(id);
91
104
  }
@@ -94,7 +107,7 @@ var TaActionUtil;
94
107
  function title(id, language) {
95
108
  var _a;
96
109
  var _b, _c;
97
- const title = (_a = byId.get(id)) === null || _a === void 0 ? void 0 : _a.title;
110
+ const title = (_a = titled.get(id)) === null || _a === void 0 ? void 0 : _a.title;
98
111
  if (!title) {
99
112
  return id;
100
113
  }
@@ -106,6 +119,18 @@ var TaActionUtil;
106
119
  });
107
120
  }
108
121
  TaActionUtil.title = title;
122
+ /** Whether an action may be given to someone at all, by a role or on its own: one of TA_ACTIONS, of no area of the owner's. */
123
+ function grantable(id) {
124
+ const info = byId.get(id);
125
+ return !!info && !OWNER_AREAS.includes(info.area);
126
+ }
127
+ TaActionUtil.grantable = grantable;
128
+ /** Whether an action may be in a role: grantable, and not one given only on its own (`grant: 'single'`). */
129
+ function inRoles(id) {
130
+ var _a;
131
+ return grantable(id) && ((_a = byId.get(id)) === null || _a === void 0 ? void 0 : _a.grant) !== 'single';
132
+ }
133
+ TaActionUtil.inRoles = inRoles;
109
134
  /** Whether `path` is `dir` or inside it; both absolute, `/` separated. */
110
135
  function inside(dir, path) {
111
136
  const base = dir.replace(/\/+$/, '');
@@ -0,0 +1,185 @@
1
+ import type { TaPackageText } from './package-protocol';
2
+ import type { TaRelayOption } from './relay-protocol';
3
+ export declare const TaVoiceServer: unique symbol;
4
+ export declare const TA_VOICE_SERVICE = "TaVoiceServer";
5
+ /** A field of the form to add a service of a type (docs/design/ta-voice.md): the same as those of relays. */
6
+ export type TaVoiceOption = TaRelayOption;
7
+ /** A type of voice service a package registered, as the page shows it to add one. */
8
+ export interface TaVoiceTypeInfo {
9
+ type: string;
10
+ title: TaPackageText;
11
+ hint?: TaPackageText;
12
+ /** The name of an icon of `pi.ui.icons`. */
13
+ icon?: string;
14
+ options: TaVoiceOption[];
15
+ /** It reads text given to it; without, Ta reads with the voice of the device and the service only listens. */
16
+ speaks: boolean;
17
+ }
18
+ /** A service of voices.json, as the page sees it: never a password or a key. */
19
+ export interface TaVoiceService {
20
+ id: string;
21
+ type: string;
22
+ name?: string;
23
+ /** Where it is, in a few words (a host). */
24
+ where?: string;
25
+ options?: Record<string, unknown>;
26
+ /** Its type is of a package that is off. */
27
+ unavailable?: boolean;
28
+ }
29
+ /** The services of calls and the one in use (TaVoiceServer.listVoices). */
30
+ export interface TaVoices {
31
+ services: TaVoiceService[];
32
+ /** The service calls use; undefined: the voice of the device. */
33
+ use?: string;
34
+ types: TaVoiceTypeInfo[];
35
+ /** voices.json in the agent directory, to edit by hand. */
36
+ file: string;
37
+ /** When a sound stops what a service reads: voices.json `bargeIn` over the defaults. */
38
+ bargeIn: TaBargeIn;
39
+ }
40
+ /**
41
+ * When a sound heard while Ta reads is the user cutting in (voices.json `bargeIn`, docs/design/ta-voice.md): the reading
42
+ * first goes on lower, and stops only once the sound is speech long enough or words in its transcript.
43
+ */
44
+ export interface TaBargeIn {
45
+ /** How loud the reading goes on while a sound may be the user cutting in, 0 to 1. */
46
+ duck: number;
47
+ /** ms of speech that stop the reading: a cough, a knock, a cup set down is shorter. */
48
+ speechMs: number;
49
+ /** The level (RMS, 0 to 1) of the microphone, after its noise suppression, that counts as speech. */
50
+ level: number;
51
+ /** Letters or digits heard in the sound that stop the reading. */
52
+ words: number;
53
+ /** ms after which a sound not known as speech lets the reading go on loud again. */
54
+ waitMs: number;
55
+ /**
56
+ * Ta's own voice heard back: a sound of the microphone softer than this times what plays (after the lowering) is
57
+ * taken for its echo, not the user; nor are words heard while Ta plays with no such louder sound. 0: none is.
58
+ */
59
+ echo: number;
60
+ /** A sentence the service ended while the user's voice was heard this few ms before goes on: a short pause. */
61
+ joinMs: number;
62
+ /** Only a tap stops the reading: the user's voice never does. */
63
+ tap: boolean;
64
+ }
65
+ export declare namespace TaBargeIn {
66
+ const DEFAULTS: TaBargeIn;
67
+ /**
68
+ * The steps of the sensitivity of Settings, from the least to the most: how long and how loud speech must be to
69
+ * stop the reading. The middle one is the default.
70
+ */
71
+ const SENSITIVITY: Pick<TaBargeIn, 'speechMs' | 'level'>[];
72
+ /** The step of SENSITIVITY nearest to `bargeIn`, by how long speech must be. */
73
+ function sensitivity(bargeIn: TaBargeIn): number;
74
+ /** Of what is given, the keys of TaBargeIn of the right kind, numbers each kept in its range. */
75
+ function pick(value: unknown): Partial<TaBargeIn>;
76
+ /** What voices.json says, each value a number in its range, the default for one left out or wrong. */
77
+ function resolve(value: unknown): TaBargeIn;
78
+ }
79
+ /** A voice opened for a call (TaVoiceServer.openVoice). */
80
+ export interface TaVoiceSession {
81
+ voiceId: string;
82
+ /** The rate of the PCM16 mono a page sends (sendVoice). */
83
+ inputRate: number;
84
+ /** The rate of the PCM16 mono of `audio` events. */
85
+ outputRate: number;
86
+ speaks: boolean;
87
+ /** When a sound stops the reading: voices.json `bargeIn` over the defaults. */
88
+ bargeIn?: TaBargeIn;
89
+ }
90
+ /** What a voice opened by a connection tells it (TaClient.onVoiceEvent). */
91
+ export type TaVoiceEvent =
92
+ /** The user began to speak: Ta stops reading (barge-in). */
93
+ {
94
+ voiceId: string;
95
+ type: 'speech';
96
+ }
97
+ /** What the user said so far; `final` once a sentence ended. */
98
+ | {
99
+ voiceId: string;
100
+ type: 'text';
101
+ text: string;
102
+ final: boolean;
103
+ }
104
+ /** Audio of the reading `say`: base64 of PCM16 mono at `outputRate`. */
105
+ | {
106
+ voiceId: string;
107
+ type: 'audio';
108
+ say: number;
109
+ data: string;
110
+ }
111
+ /** The reading `say` has all its audio sent. */
112
+ | {
113
+ voiceId: string;
114
+ type: 'said';
115
+ say: number;
116
+ }
117
+ /** It closed, by itself (`error` then says why) or as asked. */
118
+ | {
119
+ voiceId: string;
120
+ type: 'closed';
121
+ error?: string;
122
+ };
123
+ /** The voices of calls for pages (docs/design/ta-voice.md). */
124
+ export interface TaVoiceServer {
125
+ listVoices(): Promise<TaVoices>;
126
+ /** Adds a service of a registered type after opening it once: a wrong key is said now. Its id. */
127
+ addVoice(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
128
+ /**
129
+ * Changes a service after opening it once with what it would be: its fields (a secret left empty keeps the one
130
+ * kept) and its name; a wrong key is said now and nothing changes.
131
+ */
132
+ updateVoice(id: string, options: Record<string, unknown>, name?: string): Promise<void>;
133
+ removeVoice(id: string): Promise<void>;
134
+ /** The service calls use from now on; null for the voice of the device. */
135
+ chooseVoice(id: string | null): Promise<void>;
136
+ /** Sets keys of `bargeIn` in voices.json, the others kept; the next call goes by it. */
137
+ setBargeIn(bargeIn: Partial<TaBargeIn>): Promise<void>;
138
+ /** Opens the service in use for a call of this connection; it closes as the connection does. */
139
+ openVoice(options: {
140
+ language: string;
141
+ }): Promise<TaVoiceSession>;
142
+ /** PCM16 mono at `inputRate`, base64. */
143
+ sendVoice(voiceId: string, audio: string): Promise<void>;
144
+ /** Reads text: the id its audio and its `said` carry. */
145
+ sayVoice(voiceId: string, text: string): Promise<number>;
146
+ /** Stops what it reads. */
147
+ hushVoice(voiceId: string): Promise<void>;
148
+ closeVoice(voiceId: string): Promise<void>;
149
+ }
150
+ /** What a voice service tells Ta as it runs (TaVoiceType.open). */
151
+ export interface TaVoiceEngineEvents {
152
+ speech(): void;
153
+ text(text: string, final: boolean): void;
154
+ audio(pcm: Uint8Array, say: number): void;
155
+ said(say: number): void;
156
+ /** It closed by itself: the connection dropped, the service refused. */
157
+ closed(error?: string): void;
158
+ }
159
+ /** A voice service opened (TaVoiceType.open): what Ta sends it. */
160
+ export interface TaVoiceEngine {
161
+ readonly inputRate: number;
162
+ readonly outputRate: number;
163
+ /** PCM16 mono at `inputRate`. */
164
+ send(pcm: Uint8Array): void;
165
+ /** Reads text aloud, its audio told with `say`; only of a type that `speaks`. */
166
+ say?(text: string, say: number): void;
167
+ /** Stops what it reads; its audio coming late is dropped by Ta anyway. */
168
+ hush(): void;
169
+ close(): void;
170
+ }
171
+ /** A type of voice service a package adds (TaExtensionVoices.registerType): its form, and how it opens. */
172
+ export interface TaVoiceType extends Omit<TaVoiceTypeInfo, 'type'> {
173
+ /** Where it is, in a few words for the list: a host. */
174
+ where(options: Record<string, unknown>): string;
175
+ /** Connects; resolves once it is ready to hear, rejects with why it is not (a wrong key). */
176
+ open(options: Record<string, unknown>, call: {
177
+ language: string;
178
+ }, events: TaVoiceEngineEvents): Promise<TaVoiceEngine>;
179
+ }
180
+ /** voices.json for the server side of packages (TaExtensionHost.voices). */
181
+ export interface TaExtensionVoices {
182
+ /** A type of service: `"type": "<type>"` in voices.json and a form in Settings. Gone with what it returns, or when the package stops. */
183
+ registerType(type: string, definition: TaVoiceType): () => void;
184
+ }
185
+ //# sourceMappingURL=voice-protocol.d.ts.map
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaBargeIn = exports.TA_VOICE_SERVICE = exports.TaVoiceServer = void 0;
4
+ exports.TaVoiceServer = Symbol('TaVoiceServer');
5
+ exports.TA_VOICE_SERVICE = 'TaVoiceServer';
6
+ var TaBargeIn;
7
+ (function (TaBargeIn) {
8
+ TaBargeIn.DEFAULTS = { duck: 0.2, speechMs: 500, level: 0.02, words: 2, waitMs: 1500, echo: 0.3, joinMs: 300, tap: false };
9
+ /**
10
+ * The steps of the sensitivity of Settings, from the least to the most: how long and how loud speech must be to
11
+ * stop the reading. The middle one is the default.
12
+ */
13
+ TaBargeIn.SENSITIVITY = [
14
+ { speechMs: 1000, level: 0.05 },
15
+ { speechMs: 750, level: 0.035 },
16
+ { speechMs: TaBargeIn.DEFAULTS.speechMs, level: TaBargeIn.DEFAULTS.level },
17
+ { speechMs: 300, level: 0.012 },
18
+ { speechMs: 150, level: 0.006 },
19
+ ];
20
+ /** The step of SENSITIVITY nearest to `bargeIn`, by how long speech must be. */
21
+ function sensitivity(bargeIn) {
22
+ let nearest = 0;
23
+ TaBargeIn.SENSITIVITY.forEach((step, index) => {
24
+ if (Math.abs(step.speechMs - bargeIn.speechMs) < Math.abs(TaBargeIn.SENSITIVITY[nearest].speechMs - bargeIn.speechMs)) {
25
+ nearest = index;
26
+ }
27
+ });
28
+ return nearest;
29
+ }
30
+ TaBargeIn.sensitivity = sensitivity;
31
+ /** Of what is given, the keys of TaBargeIn of the right kind, numbers each kept in its range. */
32
+ function pick(value) {
33
+ const given = value && typeof value === 'object' ? value : {};
34
+ const out = typeof given.tap === 'boolean' ? { tap: given.tap } : {};
35
+ for (const key of Object.keys(RANGES)) {
36
+ const number = given[key];
37
+ if (typeof number === 'number' && Number.isFinite(number)) {
38
+ const [min, max] = RANGES[key];
39
+ out[key] = Math.min(max, Math.max(min, number));
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+ TaBargeIn.pick = pick;
45
+ const RANGES = {
46
+ duck: [0, 1],
47
+ speechMs: [0, 5000],
48
+ level: [0, 1],
49
+ words: [1, 50],
50
+ waitMs: [100, 10000],
51
+ echo: [0, 4],
52
+ joinMs: [0, 3000],
53
+ };
54
+ /** What voices.json says, each value a number in its range, the default for one left out or wrong. */
55
+ function resolve(value) {
56
+ return { ...TaBargeIn.DEFAULTS, ...pick(value) };
57
+ }
58
+ TaBargeIn.resolve = resolve;
59
+ })(TaBargeIn || (exports.TaBargeIn = TaBargeIn = {}));
60
+ //# sourceMappingURL=voice-protocol.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-protocol",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "The protocol between ta serve and its clients",
5
5
  "homepage": "https://github.com/cellbang/ta",
6
6
  "bugs": {