@celljs/ta-protocol 4.15.2 → 4.17.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 (67) hide show
  1. package/esm/common/app-protocol.d.ts +115 -0
  2. package/esm/common/app-protocol.js +199 -0
  3. package/esm/common/delegate-protocol.d.ts +30 -0
  4. package/esm/common/delegate-protocol.js +52 -0
  5. package/esm/common/deployment-protocol.d.ts +59 -0
  6. package/esm/common/deployment-protocol.js +135 -0
  7. package/esm/common/error-protocol.d.ts +42 -0
  8. package/esm/common/error-protocol.js +45 -0
  9. package/esm/common/event-protocol.d.ts +63 -0
  10. package/esm/common/event-protocol.js +2 -0
  11. package/esm/common/gateway-protocol.d.ts +54 -2
  12. package/esm/common/index.d.ts +9 -0
  13. package/esm/common/index.js +9 -0
  14. package/esm/common/location.d.ts +18 -1
  15. package/esm/common/location.js +51 -4
  16. package/esm/common/message-protocol.d.ts +95 -0
  17. package/esm/common/message-protocol.js +237 -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/remote-protocol.d.ts +12 -4
  27. package/esm/common/room-protocol.d.ts +7 -1
  28. package/esm/common/ta-extension-host.d.ts +31 -1
  29. package/esm/common/ta-extension-host.js +2 -0
  30. package/esm/common/ta-protocol.d.ts +50 -175
  31. package/esm/common/ta-protocol.js +0 -234
  32. package/esm/common/voice-protocol.d.ts +139 -0
  33. package/esm/common/voice-protocol.js +3 -0
  34. package/lib/common/app-protocol.d.ts +116 -0
  35. package/lib/common/app-protocol.js +202 -0
  36. package/lib/common/delegate-protocol.d.ts +31 -0
  37. package/lib/common/delegate-protocol.js +55 -0
  38. package/lib/common/deployment-protocol.d.ts +60 -0
  39. package/lib/common/deployment-protocol.js +139 -0
  40. package/lib/common/error-protocol.d.ts +43 -0
  41. package/lib/common/error-protocol.js +48 -0
  42. package/lib/common/event-protocol.d.ts +64 -0
  43. package/lib/common/event-protocol.js +3 -0
  44. package/lib/common/gateway-protocol.d.ts +54 -2
  45. package/lib/common/index.d.ts +9 -0
  46. package/lib/common/index.js +9 -0
  47. package/lib/common/location.d.ts +18 -1
  48. package/lib/common/location.js +51 -4
  49. package/lib/common/message-protocol.d.ts +96 -0
  50. package/lib/common/message-protocol.js +240 -0
  51. package/lib/common/page-protocol.d.ts +57 -0
  52. package/lib/common/page-protocol.js +15 -0
  53. package/lib/common/path-map.d.ts +25 -0
  54. package/lib/common/path-map.js +130 -0
  55. package/lib/common/presence-protocol.js +7 -7
  56. package/lib/common/redactor.d.ts +12 -0
  57. package/lib/common/redactor.js +49 -11
  58. package/lib/common/relay-protocol.d.ts +20 -0
  59. package/lib/common/remote-protocol.d.ts +12 -4
  60. package/lib/common/room-protocol.d.ts +7 -1
  61. package/lib/common/ta-extension-host.d.ts +31 -1
  62. package/lib/common/ta-extension-host.js +3 -1
  63. package/lib/common/ta-protocol.d.ts +50 -175
  64. package/lib/common/ta-protocol.js +1 -235
  65. package/lib/common/voice-protocol.d.ts +140 -0
  66. package/lib/common/voice-protocol.js +6 -0
  67. package/package.json +1 -1
@@ -0,0 +1,237 @@
1
+ /**
2
+ * A message of the user may start with a `<context>` block: what the model reads besides the message
3
+ * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
4
+ */
5
+ export var TaMessageContext;
6
+ (function (TaMessageContext) {
7
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
8
+ function wrap(context, message) {
9
+ return `<context>\n${context}\n</context>\n${message}`;
10
+ }
11
+ TaMessageContext.wrap = wrap;
12
+ /** The message without its context: what the user sees of it. */
13
+ function strip(message) {
14
+ return message.replace(BLOCK, '');
15
+ }
16
+ TaMessageContext.strip = strip;
17
+ /** The context of the message, without its tags; undefined without one. */
18
+ function read(message) {
19
+ var _a;
20
+ const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
21
+ return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
22
+ }
23
+ TaMessageContext.read = read;
24
+ })(TaMessageContext || (TaMessageContext = {}));
25
+ /**
26
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
27
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
28
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
29
+ */
30
+ export var TaMessageSource;
31
+ (function (TaMessageSource) {
32
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
33
+ TaMessageSource.DOUBLE = 'ta:double';
34
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
35
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
36
+ function mark(message, from, detail) {
37
+ if (/^[/!]/.test(message) || of(message)) {
38
+ return message;
39
+ }
40
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
41
+ const context = TaMessageContext.read(message);
42
+ return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
43
+ }
44
+ TaMessageSource.mark = mark;
45
+ function of(message) {
46
+ const context = TaMessageContext.read(message);
47
+ const match = context === undefined ? null : LINE.exec(context);
48
+ return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
49
+ }
50
+ TaMessageSource.of = of;
51
+ })(TaMessageSource || (TaMessageSource = {}));
52
+ /**
53
+ * 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
54
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
55
+ */
56
+ export var TaImageNote;
57
+ (function (TaImageNote) {
58
+ 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 [^\]]+\.\]$/;
59
+ /** The text without the notes of its images: what the user sees of it. */
60
+ function strip(text) {
61
+ const lines = text.split('\n');
62
+ const kept = lines.filter(line => !NOTE.test(line.trim()));
63
+ if (kept.length === lines.length) {
64
+ return text;
65
+ }
66
+ return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
67
+ }
68
+ TaImageNote.strip = strip;
69
+ })(TaImageNote || (TaImageNote = {}));
70
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
71
+ export var TaImageSize;
72
+ (function (TaImageSize) {
73
+ /** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
74
+ const JPEG_BYTES = 256 * 1024;
75
+ function of(base64) {
76
+ var _a, _b, _c;
77
+ let bytes;
78
+ try {
79
+ // Whole groups of four characters only.
80
+ const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
81
+ bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
82
+ }
83
+ catch (_d) {
84
+ return undefined;
85
+ }
86
+ 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);
87
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
88
+ }
89
+ TaImageSize.of = of;
90
+ function u16be(bytes, at) {
91
+ return (bytes[at] << 8) | bytes[at + 1];
92
+ }
93
+ function u16le(bytes, at) {
94
+ return bytes[at] | (bytes[at + 1] << 8);
95
+ }
96
+ function u24le(bytes, at) {
97
+ return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
98
+ }
99
+ function u32be(bytes, at) {
100
+ return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
101
+ }
102
+ function text(bytes, at, length) {
103
+ return String.fromCharCode(...bytes.subarray(at, at + length));
104
+ }
105
+ function png(bytes) {
106
+ return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
107
+ }
108
+ function gif(bytes) {
109
+ return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
110
+ }
111
+ function webp(bytes) {
112
+ if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
113
+ return undefined;
114
+ }
115
+ switch (text(bytes, 12, 4)) {
116
+ case 'VP8 ':
117
+ return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
118
+ case 'VP8L': {
119
+ const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
120
+ return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
121
+ }
122
+ case 'VP8X':
123
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
124
+ default:
125
+ return undefined;
126
+ }
127
+ }
128
+ function jpeg(bytes) {
129
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
130
+ return undefined;
131
+ }
132
+ let at = 2;
133
+ while (at + 9 < bytes.length) {
134
+ if (bytes[at] !== 0xff) {
135
+ return undefined;
136
+ }
137
+ const marker = bytes[at + 1];
138
+ // A start of frame (not DHT, JPG or DAC, which share the range) says the size.
139
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
140
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
141
+ }
142
+ at += 2 + u16be(bytes, at + 2);
143
+ }
144
+ return undefined;
145
+ }
146
+ })(TaImageSize || (TaImageSize = {}));
147
+ /**
148
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
149
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
150
+ */
151
+ export var TaAgentSummary;
152
+ (function (TaAgentSummary) {
153
+ const START = /^\s*<conversation_history_summary>/;
154
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
155
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
156
+ function read(text) {
157
+ if (!START.test(text)) {
158
+ return undefined;
159
+ }
160
+ return text
161
+ .replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
162
+ .replace(/<\/?\w*$/, '')
163
+ .trim();
164
+ }
165
+ TaAgentSummary.read = read;
166
+ /** The text without the summary it starts with. */
167
+ function strip(text) {
168
+ return text.replace(BLOCK, '');
169
+ }
170
+ TaAgentSummary.strip = strip;
171
+ })(TaAgentSummary || (TaAgentSummary = {}));
172
+ /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
173
+ export var TaSkillUse;
174
+ (function (TaSkillUse) {
175
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
176
+ function parse(message) {
177
+ var _a;
178
+ const match = BLOCK.exec(message);
179
+ if (!match) {
180
+ return undefined;
181
+ }
182
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
183
+ }
184
+ TaSkillUse.parse = parse;
185
+ /** What the user typed: `/skill:name` and what follows. */
186
+ function command(use) {
187
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
188
+ }
189
+ TaSkillUse.command = command;
190
+ })(TaSkillUse || (TaSkillUse = {}));
191
+ /**
192
+ * The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
193
+ * and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
194
+ * conversations says by the task's title.
195
+ */
196
+ export var TaTaskNote;
197
+ (function (TaTaskNote) {
198
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
199
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
200
+ function write(note) {
201
+ const attributes = [`id="${quote(note.id)}"`];
202
+ if (note.was !== undefined) {
203
+ attributes.push(`was="${quote(note.was)}"`);
204
+ }
205
+ attributes.push(`title="${quote(note.title)}"`);
206
+ if (note.status !== undefined) {
207
+ attributes.push(`status="${quote(note.status)}"`);
208
+ }
209
+ return `<task_${note.kind} ${attributes.join(' ')}>\n${note.body}\n</task_${note.kind}>`;
210
+ }
211
+ TaTaskNote.write = write;
212
+ /** The note `text` is, all of it; undefined for anything else. */
213
+ function parse(text) {
214
+ const match = NOTE.exec(text.trim());
215
+ if (!match) {
216
+ return undefined;
217
+ }
218
+ const attributes = {};
219
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
220
+ attributes[name] = unquote(value);
221
+ }
222
+ if (!attributes.id || attributes.title === undefined) {
223
+ return undefined;
224
+ }
225
+ const { id, title, status, was } = attributes;
226
+ return { kind: match[1], id, title, ...(status ? { status } : {}), ...(was ? { was } : {}), body: match[3] };
227
+ }
228
+ TaTaskNote.parse = parse;
229
+ /** A title the model gave, in the quotes of an attribute: a quote in it would end the attribute, a new line the tag. */
230
+ function quote(text) {
231
+ return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/\n/g, ' ');
232
+ }
233
+ function unquote(text) {
234
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, '&');
235
+ }
236
+ })(TaTaskNote || (TaTaskNote = {}));
237
+ //# sourceMappingURL=message-protocol.js.map
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Pages of Ta that ta serve may ask something (docs/design/ta-app-use.md 4.1): a page says which kinds of request it
3
+ * answers (TaPageServer.attach) and is asked one by TaClient.onPageAsk, on its own connection. A package of Ta asks
4
+ * the page of who asked its run (TaExtensionHost.pages), never another's: what one sees on their screen is theirs.
5
+ */
6
+ export declare const TaPageServer: unique symbol;
7
+ export declare const TA_PAGE_SERVICE = "TaPageServer";
8
+ /** How long a page may take to answer, unless the asker says otherwise. */
9
+ export declare const TA_PAGE_ASK_MS = 30000;
10
+ /** A request of ta serve itself: the user agrees on their screen to something an agent wants to do (TaPageConfirm). */
11
+ export declare const TA_PAGE_CONFIRM = "ta/confirm";
12
+ /** What a page says of itself (TaPageServer.attach), again as it changes. */
13
+ export interface TaPageInfo {
14
+ /** The requests it answers: `<package>/<kind>` of a web extension, `ta/<kind>` of the page itself. */
15
+ kinds: string[];
16
+ /** A phone, a tablet or a computer, as the page lays itself out. */
17
+ device: 'phone' | 'tablet' | 'computer';
18
+ /** The window of Ta Desktop: a page kept while its window is closed. */
19
+ desktop?: boolean;
20
+ /** It is in front of the user now. */
21
+ visible?: boolean;
22
+ /** The user touched, clicked or typed in it just now (a page tells it at most every few seconds). */
23
+ active?: boolean;
24
+ }
25
+ export interface TaPageServer {
26
+ attach(info: TaPageInfo): Promise<void>;
27
+ }
28
+ /** What the user is asked to agree to (TA_PAGE_CONFIRM): the answer is a boolean. */
29
+ export interface TaPageConfirm {
30
+ /** Who wants it: the name of the conversation, or of the person. */
31
+ who: string;
32
+ /** What it does, in a line of the user's language. */
33
+ what: string;
34
+ /** More, when a line is not enough. */
35
+ detail?: string;
36
+ }
37
+ /** Which page a package asks (TaHostPages.ask). */
38
+ export interface TaPageAskOptions {
39
+ /** The run that asks: the page of who asked it, the owner's for a run nobody asked. */
40
+ sessionFile?: string;
41
+ /** Or this one's page (a page that taps something). */
42
+ principal?: string;
43
+ /** How long to wait for the answer; TA_PAGE_ASK_MS without. */
44
+ timeoutMs?: number;
45
+ }
46
+ /** The pages of Ta, for the server side of a package (TaExtensionHost.pages). */
47
+ export interface TaHostPages {
48
+ /**
49
+ * Asks a page of this package (`pi.ui.answer(kind, …)` of its web extension) and resolves to its answer: the page of
50
+ * that person in front of them, else the one they touched last, else the window of Ta Desktop. Rejects when they have
51
+ * no page open that answers it, or it does not answer in time.
52
+ */
53
+ ask(kind: string, payload: unknown, options?: TaPageAskOptions): Promise<unknown>;
54
+ /** Whether that person has a page open that answers it. */
55
+ has(kind: string, options?: TaPageAskOptions): boolean;
56
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Pages of Ta that ta serve may ask something (docs/design/ta-app-use.md 4.1): a page says which kinds of request it
3
+ * answers (TaPageServer.attach) and is asked one by TaClient.onPageAsk, on its own connection. A package of Ta asks
4
+ * the page of who asked its run (TaExtensionHost.pages), never another's: what one sees on their screen is theirs.
5
+ */
6
+ export const TaPageServer = Symbol('TaPageServer');
7
+ export const TA_PAGE_SERVICE = 'TaPageServer';
8
+ /** How long a page may take to answer, unless the asker says otherwise. */
9
+ export const TA_PAGE_ASK_MS = 30000;
10
+ /** A request of ta serve itself: the user agrees on their screen to something an agent wants to do (TaPageConfirm). */
11
+ export const TA_PAGE_CONFIRM = 'ta/confirm';
12
+ //# sourceMappingURL=page-protocol.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A path of one computer as it is on another (docs/design/ta-sync.md 8.4): a move from Windows to Linux or back, a
3
+ * project in another folder. A base is matched whatever its separators, and regardless of case for a path of Windows;
4
+ * what follows it takes the separators of the base it is mapped to.
5
+ */
6
+ export declare namespace TaPathMap {
7
+ /** A directory as it was, and as it is now. */
8
+ type Pair = readonly [from: string, to: string];
9
+ /** `C:\...`, `c:/...` or `\\server\share`. */
10
+ function isWindows(path: string): boolean;
11
+ /** The parts of `path` after `base`, none when it is `base`; undefined when it is not `base` nor under it. */
12
+ function rest(path: string, base: string): string[] | undefined;
13
+ function under(path: string, base: string): boolean;
14
+ /** `parts` under `base`, with its separator. */
15
+ function join(base: string, parts: readonly string[]): string;
16
+ /** The last part of a path, of either kind. */
17
+ function basename(path: string): string;
18
+ /** A path under the deepest base of `pairs` it is under, as it is there; else itself. */
19
+ function path(value: string, pairs: readonly Pair[]): string;
20
+ /** The paths in a text (a command, `dir:<path>`), each mapped as `path` maps it; a path ends at a space or a quote. */
21
+ function text(value: string, pairs: readonly Pair[]): string;
22
+ /** Every string of a value of JSON, keys too, mapped: a whole path as `path` maps it, paths in a text as `text` does. */
23
+ function json<T>(value: T, pairs: readonly Pair[]): T;
24
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * A path of one computer as it is on another (docs/design/ta-sync.md 8.4): a move from Windows to Linux or back, a
3
+ * project in another folder. A base is matched whatever its separators, and regardless of case for a path of Windows;
4
+ * what follows it takes the separators of the base it is mapped to.
5
+ */
6
+ export var TaPathMap;
7
+ (function (TaPathMap) {
8
+ /** `C:\...`, `c:/...` or `\\server\share`. */
9
+ function isWindows(path) {
10
+ return /^[a-zA-Z]:([\\/]|$)/.test(path) || /^\\\\[^\\]/.test(path);
11
+ }
12
+ TaPathMap.isWindows = isWindows;
13
+ /** The parts of `path` after `base`, none when it is `base`; undefined when it is not `base` nor under it. */
14
+ function rest(path, base) {
15
+ const windows = isWindows(base);
16
+ if (windows ? !isWindows(path) : !base.startsWith('/') || !path.startsWith('/')) {
17
+ return undefined;
18
+ }
19
+ const within = parts(base, windows);
20
+ const all = parts(path, windows);
21
+ if (!within.length || all.length < within.length) {
22
+ return undefined;
23
+ }
24
+ const same = (a, b) => (windows ? a.toLowerCase() === b.toLowerCase() : a === b);
25
+ return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
26
+ }
27
+ TaPathMap.rest = rest;
28
+ function under(path, base) {
29
+ return rest(path, base) !== undefined;
30
+ }
31
+ TaPathMap.under = under;
32
+ /** `parts` under `base`, with its separator. */
33
+ function join(base, parts) {
34
+ if (!parts.length) {
35
+ return base;
36
+ }
37
+ const sep = isWindows(base) ? '\\' : '/';
38
+ return `${base.replace(/[\\/]+$/, '')}${sep}${parts.join(sep)}`;
39
+ }
40
+ TaPathMap.join = join;
41
+ /** The last part of a path, of either kind. */
42
+ function basename(path) {
43
+ var _a;
44
+ return ((_a = path
45
+ .split(/[\\/]+/)
46
+ .filter(Boolean)
47
+ .pop()) !== null && _a !== void 0 ? _a : '');
48
+ }
49
+ TaPathMap.basename = basename;
50
+ /** A path under the deepest base of `pairs` it is under, as it is there; else itself. */
51
+ function path(value, pairs) {
52
+ for (const [from, to] of deepest(pairs)) {
53
+ const found = rest(value, from);
54
+ if (found) {
55
+ return join(to, found);
56
+ }
57
+ }
58
+ return value;
59
+ }
60
+ TaPathMap.path = path;
61
+ /** The paths in a text (a command, `dir:<path>`), each mapped as `path` maps it; a path ends at a space or a quote. */
62
+ function text(value, pairs) {
63
+ const order = deepest(pairs);
64
+ if (!order.length) {
65
+ return value;
66
+ }
67
+ const end = String.raw `\s"'<>|*?:;,`;
68
+ const pattern = new RegExp(String.raw `(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join('|')})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, 'g');
69
+ return value.replace(pattern, (...match) => {
70
+ var _a;
71
+ const before = match[1];
72
+ const found = order.findIndex((_, i) => match[i + 2] !== undefined);
73
+ const tail = (_a = match[order.length + 2]) !== null && _a !== void 0 ? _a : '';
74
+ return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
75
+ });
76
+ }
77
+ TaPathMap.text = text;
78
+ /** Every string of a value of JSON, keys too, mapped: a whole path as `path` maps it, paths in a text as `text` does. */
79
+ function json(value, pairs) {
80
+ const order = deepest(pairs);
81
+ if (!order.length) {
82
+ return value;
83
+ }
84
+ const one = (each) => {
85
+ const whole = path(each, order);
86
+ return whole !== each ? whole : text(each, order);
87
+ };
88
+ const walk = (each) => {
89
+ if (typeof each === 'string') {
90
+ return one(each);
91
+ }
92
+ if (Array.isArray(each)) {
93
+ return each.map(walk);
94
+ }
95
+ if (each && typeof each === 'object') {
96
+ return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
97
+ }
98
+ return each;
99
+ };
100
+ return walk(value);
101
+ }
102
+ TaPathMap.json = json;
103
+ function parts(path, windows) {
104
+ return path.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
105
+ }
106
+ /** The pairs that map something, the deepest base first: a path goes under the nearest. */
107
+ function deepest(pairs) {
108
+ return pairs
109
+ .filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0)
110
+ .sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
111
+ }
112
+ /** A base as a pattern: its parts by any separator, and for Windows regardless of case. */
113
+ function source(base) {
114
+ const windows = isWindows(base);
115
+ const quote = (part) => [...part]
116
+ .map(char => windows && char.toLowerCase() !== char.toUpperCase()
117
+ ? `[${char.toLowerCase()}${char.toUpperCase()}]`
118
+ : char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
119
+ .join('');
120
+ const each = parts(base, windows).map(quote);
121
+ if (!windows) {
122
+ return `/${each.join('/+')}`;
123
+ }
124
+ return `${base.startsWith('\\\\') ? String.raw `\\\\` : ''}${each.join(String.raw `[\\/]+`)}`;
125
+ }
126
+ })(TaPathMap || (TaPathMap = {}));
127
+ //# sourceMappingURL=path-map.js.map
@@ -1,4 +1,4 @@
1
- import { TaMessageContext } from './ta-protocol.js';
1
+ import { TaMessageContext } from './message-protocol.js';
2
2
  export const TaPresenceServer = Symbol('TaPresenceServer');
3
3
  export const TA_PRESENCE_SERVICE = 'TaPresenceServer';
4
4
  /** A page says what it is at again this often while it lasts, the same or not. */
@@ -1,5 +1,11 @@
1
1
  /** What a secret is replaced with. */
2
2
  export declare const REDACTED = "[redacted]";
3
+ /** Where a secret is in a text (Redactor.spans). */
4
+ export interface RedactorSpan {
5
+ start: number;
6
+ end: number;
7
+ kind: string;
8
+ }
3
9
  /**
4
10
  * What looks like a secret in what is shared (docs/design/ta-link.md 2.8): keys of model services and code hosts,
5
11
  * tokens, private keys, passwords in assignments and in URLs. It errs on hiding: a shared conversation is read
@@ -11,6 +17,12 @@ export declare class Redactor {
11
17
  text(text: string): string;
12
18
  /** Strings of a value, deep, each cut to `max` characters. */
13
19
  value(value: unknown, max: number): unknown;
20
+ /**
21
+ * Where secrets are in a text, by the same patterns, none overlapping, the first first: what the vault of
22
+ * ta-secrets takes out of what the user sends. `kind` names it: `GITHUB_TOKEN`, `API_KEY` (an `sk-` key),
23
+ * `PRIVATE_KEY`, `BEARER_TOKEN`, `URL_PASSWORD`, or the name it was assigned to (`DB_PASSWORD`).
24
+ */
25
+ static spans(text: string): RedactorSpan[];
14
26
  static cut(text: string, max: number): string;
15
27
  protected hide(): string;
16
28
  /** What is plainly not a secret: an environment variable, a placeholder, what was hidden already. */
@@ -1,16 +1,16 @@
1
1
  /** What a secret is replaced with. */
2
2
  export const REDACTED = '[redacted]';
3
- /** Secrets that have a shape of their own: the whole match goes. */
3
+ /** Secrets that have a shape of their own, by what they are: the whole match goes. */
4
4
  const WHOLE = [
5
- /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
6
- /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
7
- /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
8
- /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
9
- /\bglpat-[A-Za-z0-9_-]{20,}\b/g,
10
- /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
11
- /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
12
- /\bAIza[0-9A-Za-z_-]{35}\b/g,
13
- /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
5
+ ['PRIVATE_KEY', /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
6
+ ['API_KEY', /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g],
7
+ ['GITHUB_TOKEN', /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g],
8
+ ['GITHUB_TOKEN', /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g],
9
+ ['GITLAB_TOKEN', /\bglpat-[A-Za-z0-9_-]{20,}\b/g],
10
+ ['SLACK_TOKEN', /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g],
11
+ ['AWS_ACCESS_KEY_ID', /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
12
+ ['GOOGLE_API_KEY', /\bAIza[0-9A-Za-z_-]{35}\b/g],
13
+ ['JWT', /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g],
14
14
  ];
15
15
  /** Secrets named by what is before them: what is before stays. */
16
16
  const NAMED = [
@@ -30,7 +30,7 @@ export class Redactor {
30
30
  }
31
31
  text(text) {
32
32
  let out = text;
33
- for (const pattern of WHOLE) {
33
+ for (const [, pattern] of WHOLE) {
34
34
  out = out.replace(pattern, () => this.hide());
35
35
  }
36
36
  out = out.replace(NAMED[0], (_match, before) => before + this.hide());
@@ -51,6 +51,44 @@ export class Redactor {
51
51
  }
52
52
  return value;
53
53
  }
54
+ /**
55
+ * Where secrets are in a text, by the same patterns, none overlapping, the first first: what the vault of
56
+ * ta-secrets takes out of what the user sends. `kind` names it: `GITHUB_TOKEN`, `API_KEY` (an `sk-` key),
57
+ * `PRIVATE_KEY`, `BEARER_TOKEN`, `URL_PASSWORD`, or the name it was assigned to (`DB_PASSWORD`).
58
+ */
59
+ static spans(text) {
60
+ var _a;
61
+ var _b;
62
+ const found = [];
63
+ for (const [kind, pattern] of WHOLE) {
64
+ for (const match of text.matchAll(pattern)) {
65
+ found.push({ start: match.index, end: match.index + match[0].length, kind });
66
+ }
67
+ }
68
+ for (const match of text.matchAll(NAMED[0])) {
69
+ found.push({ start: match.index + match[1].length, end: match.index + match[0].length, kind: 'BEARER_TOKEN' });
70
+ }
71
+ for (const match of text.matchAll(NAMED[1])) {
72
+ if (!Redactor.placeholder(match[2])) {
73
+ const start = match.index + match[1].length;
74
+ const name = (_b = (_a = /[A-Za-z0-9_.-]+/.exec(match[1])) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 'SECRET';
75
+ found.push({ start, end: start + match[2].length, kind: name.replace(/[^A-Za-z0-9]+/g, '_').toUpperCase() });
76
+ }
77
+ }
78
+ for (const match of text.matchAll(NAMED[2])) {
79
+ const start = match.index + match[1].length;
80
+ found.push({ start, end: start + match[2].length, kind: 'URL_PASSWORD' });
81
+ }
82
+ found.sort((a, b) => a.start - b.start || b.end - a.end);
83
+ const spans = [];
84
+ for (const span of found) {
85
+ const last = spans.at(-1);
86
+ if (!last || span.start >= last.end) {
87
+ spans.push(span);
88
+ }
89
+ }
90
+ return spans;
91
+ }
54
92
  static cut(text, max) {
55
93
  return text.length > max ? `${text.slice(0, max)}…` : text;
56
94
  }
@@ -105,6 +105,18 @@ export interface TaRelays {
105
105
  }[];
106
106
  /** The types of services packages registered (WebDAV, S3…), to add one of. */
107
107
  types?: TaRelayTypeInfo[];
108
+ /** The deployment of Ta joined (TaRelayServer.joinDeployment): its relay is the default of what is new. */
109
+ deployment?: TaJoinedDeployment;
110
+ }
111
+ /** A deployment of Ta joined by its address (docs/design/ta-deploy.md 8). */
112
+ export interface TaJoinedDeployment {
113
+ /** The address the user gave. */
114
+ url: string;
115
+ name?: string;
116
+ /** Its gateway: a Ta in the cloud of one's own account there, or its sandbox as a cloud workspace. */
117
+ gateway?: string;
118
+ /** The id of its relay in TaRelays.relays. */
119
+ relay?: string;
108
120
  }
109
121
  /** What asking a relay what it is found (TaRelayServer.probeRelay). */
110
122
  export interface TaRelayProbe {
@@ -164,6 +176,14 @@ export interface TaRelayServer {
164
176
  * on the relay it was made on.
165
177
  */
166
178
  chooseRelay(feature: TaRelayFeature, id: string | null): Promise<TaRelays>;
179
+ /**
180
+ * Joins a deployment of Ta by the address of any of its services (its gateway, its relay), which says what it is at
181
+ * /.well-known/ta: its relay is added and made the default of new pairings, rooms and links; what was made before
182
+ * stays where it is.
183
+ */
184
+ joinDeployment(url: string): Promise<TaRelays>;
185
+ /** Leaves the deployment joined: the relay of this build is the default again. */
186
+ leaveDeployment(): Promise<TaRelays>;
167
187
  /** Asks a relay, by its id or address, what it can do and how much; never throws. */
168
188
  probeRelay(idOrUrl: string): Promise<TaRelayProbe>;
169
189
  /**
@@ -1,11 +1,13 @@
1
1
  export declare const TaRemoteServer: unique symbol;
2
2
  export declare const TA_REMOTE_SERVICE = "TaRemoteServer";
3
- /** A machine ta serve can reach with ssh. */
3
+ /** A machine ta serve can reach with ssh, or a cloud workspace it reaches over a WebSocket. */
4
4
  export interface TaRemoteHost {
5
- /** What follows `ssh://` in a location (TaLocation). */
5
+ /** What follows `ssh://` in a location (TaLocation), or `ta://<name>` for a cloud workspace. */
6
6
  host: string;
7
- /** A Host of ~/.ssh/config, or one opened before. */
8
- source: 'config' | 'recent';
7
+ /** A Host of ~/.ssh/config, one opened before, or a cloud workspace added (TaRemoteServer.addCloudHost). */
8
+ source: 'config' | 'recent' | 'cloud';
9
+ /** Of a cloud workspace: the address of its Ta gateway or Ta service, never its token. */
10
+ url?: string;
9
11
  /** ta serve is connected to it now. */
10
12
  connected: boolean;
11
13
  }
@@ -67,6 +69,12 @@ export interface TaRemoteServer {
67
69
  addHost(host: string): Promise<void>;
68
70
  /** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
69
71
  removeHost(host: string): Promise<void>;
72
+ /**
73
+ * A cloud workspace, `ta://<name>`: the sandbox of the account of `token` on the Ta gateway at `url` (or the
74
+ * machine of a Ta service, with its token), whose directories conversations work in while the agent stays here.
75
+ * Checked by connecting first; kept with its token, which never comes back.
76
+ */
77
+ addCloudHost(name: string, url: string, token: string): Promise<TaRemoteHost>;
70
78
  /**
71
79
  * A location as the user wrote it, whole: `~/src`, `ssh://<host>` (its home), `ssh://<host>/~/src`, or a path
72
80
  * relative to the default directory; one already whole as it is. Connects to the host when it needs its home.
@@ -49,6 +49,8 @@ export interface TaRoomInfo {
49
49
  relay?: string;
50
50
  /** This Ta made it. */
51
51
  owner: boolean;
52
+ /** Of a room this Ta made: the members it lets in at most (TaRoomServer.configureRoom). */
53
+ capacity?: number;
52
54
  ownerName: string;
53
55
  status: TaRoomStatus;
54
56
  /** Why it is `gone`: `closed` by the owner, `removed` by the owner, the `invite` no longer works. */
@@ -155,7 +157,7 @@ export interface TaRoomServer {
155
157
  }): Promise<TaRoomInfo>;
156
158
  /**
157
159
  * The link others ask to join by (the owner only): the one of before while it has a day left; else, or with `renew`,
158
- * a new one for `days` (7 by default, 30 at most), and the links of before stop working.
160
+ * a new one for `days` (7 by default, 365 at most), and the links of before stop working.
159
161
  */
160
162
  invite(room: string, options?: {
161
163
  days?: number;
@@ -164,6 +166,10 @@ export interface TaRoomServer {
164
166
  link: string;
165
167
  expiresAt: number;
166
168
  }>;
169
+ /** The owner's choices for a room: the members it lets in at most (16 by default, 2 to 100); those in already stay. */
170
+ configureRoom(room: string, options: {
171
+ members?: number;
172
+ }): Promise<TaRoomInfo>;
167
173
  /** Asks to join the room of a link: `waiting` till its owner answers. Ask the user first. */
168
174
  join(link: string): Promise<TaRoomInfo>;
169
175
  /** Those asking to join the rooms of this Ta. */