@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,96 @@
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 declare namespace TaMessageContext {
6
+ function wrap(context: string, message: string): string;
7
+ /** The message without its context: what the user sees of it. */
8
+ function strip(message: string): string;
9
+ /** The context of the message, without its tags; undefined without one. */
10
+ function read(message: string): string | undefined;
11
+ }
12
+ /** Where a message of the user came from, when not from what they typed: see {@link TaMessageSource}. */
13
+ export interface TaMessageFrom {
14
+ /** The name of the package that sent it, or TaMessageSource.DOUBLE. */
15
+ from: string;
16
+ /** What the package says of it besides, in a few words (the channel and who spoke in it). */
17
+ detail?: string;
18
+ }
19
+ /**
20
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
21
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
22
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
23
+ */
24
+ export declare namespace TaMessageSource {
25
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
26
+ const DOUBLE = "ta:double";
27
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
28
+ function mark(message: string, from: string, detail?: string): string;
29
+ function of(message: string): TaMessageFrom | undefined;
30
+ }
31
+ /**
32
+ * 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
33
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
34
+ */
35
+ export declare namespace TaImageNote {
36
+ /** The text without the notes of its images: what the user sees of it. */
37
+ function strip(text: string): string;
38
+ }
39
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
40
+ export declare namespace TaImageSize {
41
+ function of(base64: string): {
42
+ width: number;
43
+ height: number;
44
+ } | undefined;
45
+ }
46
+ /**
47
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
48
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
49
+ */
50
+ export declare namespace TaAgentSummary {
51
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
52
+ function read(text: string): string | undefined;
53
+ /** The text without the summary it starts with. */
54
+ function strip(text: string): string;
55
+ }
56
+ /** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
57
+ export interface TaSkillUse {
58
+ name: string;
59
+ /** The path of its SKILL.md. */
60
+ location: string;
61
+ /** What pi read of it, for the model. */
62
+ content: string;
63
+ /** What the user wrote after `/skill:name`. */
64
+ message?: string;
65
+ }
66
+ /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
67
+ export declare namespace TaSkillUse {
68
+ function parse(message: string): TaSkillUse | undefined;
69
+ /** What the user typed: `/skill:name` and what follows. */
70
+ function command(use: TaSkillUse): string;
71
+ }
72
+ /** What a note of the double's tasks is about: how one ended, that the user handed it one, that one has another id now. */
73
+ export type TaTaskNoteKind = 'update' | 'adopted' | 'renamed';
74
+ /** A note of the double's tasks, as {@link TaTaskNote.write} puts it and {@link TaTaskNote.parse} reads it. */
75
+ export interface TaTaskNote {
76
+ kind: TaTaskNoteKind;
77
+ id: string;
78
+ title: string;
79
+ /** How the task stands: running, done, failed, stopped; none in a note of a new id. */
80
+ status?: string;
81
+ /** The id it had, in a note of a new id. */
82
+ was?: string;
83
+ /** What the note says, for the double. */
84
+ body: string;
85
+ }
86
+ /**
87
+ * The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
88
+ * and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
89
+ * conversations says by the task's title.
90
+ */
91
+ export declare namespace TaTaskNote {
92
+ function write(note: TaTaskNote): string;
93
+ /** The note `text` is, all of it; undefined for anything else. */
94
+ function parse(text: string): TaTaskNote | undefined;
95
+ }
96
+ //# sourceMappingURL=message-protocol.d.ts.map
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaTaskNote = exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = void 0;
4
+ /**
5
+ * A message of the user may start with a `<context>` block: what the model reads besides the message
6
+ * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
7
+ */
8
+ var TaMessageContext;
9
+ (function (TaMessageContext) {
10
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
11
+ function wrap(context, message) {
12
+ return `<context>\n${context}\n</context>\n${message}`;
13
+ }
14
+ TaMessageContext.wrap = wrap;
15
+ /** The message without its context: what the user sees of it. */
16
+ function strip(message) {
17
+ return message.replace(BLOCK, '');
18
+ }
19
+ TaMessageContext.strip = strip;
20
+ /** The context of the message, without its tags; undefined without one. */
21
+ function read(message) {
22
+ var _a;
23
+ const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
24
+ return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
25
+ }
26
+ TaMessageContext.read = read;
27
+ })(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
28
+ /**
29
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
30
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
31
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
32
+ */
33
+ var TaMessageSource;
34
+ (function (TaMessageSource) {
35
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
36
+ TaMessageSource.DOUBLE = 'ta:double';
37
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
38
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
39
+ function mark(message, from, detail) {
40
+ if (/^[/!]/.test(message) || of(message)) {
41
+ return message;
42
+ }
43
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
44
+ const context = TaMessageContext.read(message);
45
+ return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
46
+ }
47
+ TaMessageSource.mark = mark;
48
+ function of(message) {
49
+ const context = TaMessageContext.read(message);
50
+ const match = context === undefined ? null : LINE.exec(context);
51
+ return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
52
+ }
53
+ TaMessageSource.of = of;
54
+ })(TaMessageSource || (exports.TaMessageSource = TaMessageSource = {}));
55
+ /**
56
+ * 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
57
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
58
+ */
59
+ var TaImageNote;
60
+ (function (TaImageNote) {
61
+ 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 [^\]]+\.\]$/;
62
+ /** The text without the notes of its images: what the user sees of it. */
63
+ function strip(text) {
64
+ const lines = text.split('\n');
65
+ const kept = lines.filter(line => !NOTE.test(line.trim()));
66
+ if (kept.length === lines.length) {
67
+ return text;
68
+ }
69
+ return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
70
+ }
71
+ TaImageNote.strip = strip;
72
+ })(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
73
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
74
+ var TaImageSize;
75
+ (function (TaImageSize) {
76
+ /** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
77
+ const JPEG_BYTES = 256 * 1024;
78
+ function of(base64) {
79
+ var _a, _b, _c;
80
+ let bytes;
81
+ try {
82
+ // Whole groups of four characters only.
83
+ const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
84
+ bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
85
+ }
86
+ catch (_d) {
87
+ return undefined;
88
+ }
89
+ 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);
90
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
91
+ }
92
+ TaImageSize.of = of;
93
+ function u16be(bytes, at) {
94
+ return (bytes[at] << 8) | bytes[at + 1];
95
+ }
96
+ function u16le(bytes, at) {
97
+ return bytes[at] | (bytes[at + 1] << 8);
98
+ }
99
+ function u24le(bytes, at) {
100
+ return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
101
+ }
102
+ function u32be(bytes, at) {
103
+ return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
104
+ }
105
+ function text(bytes, at, length) {
106
+ return String.fromCharCode(...bytes.subarray(at, at + length));
107
+ }
108
+ function png(bytes) {
109
+ return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
110
+ }
111
+ function gif(bytes) {
112
+ return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
113
+ }
114
+ function webp(bytes) {
115
+ if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
116
+ return undefined;
117
+ }
118
+ switch (text(bytes, 12, 4)) {
119
+ case 'VP8 ':
120
+ return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
121
+ case 'VP8L': {
122
+ const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
123
+ return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
124
+ }
125
+ case 'VP8X':
126
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
127
+ default:
128
+ return undefined;
129
+ }
130
+ }
131
+ function jpeg(bytes) {
132
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
133
+ return undefined;
134
+ }
135
+ let at = 2;
136
+ while (at + 9 < bytes.length) {
137
+ if (bytes[at] !== 0xff) {
138
+ return undefined;
139
+ }
140
+ const marker = bytes[at + 1];
141
+ // A start of frame (not DHT, JPG or DAC, which share the range) says the size.
142
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
143
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
144
+ }
145
+ at += 2 + u16be(bytes, at + 2);
146
+ }
147
+ return undefined;
148
+ }
149
+ })(TaImageSize || (exports.TaImageSize = TaImageSize = {}));
150
+ /**
151
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
152
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
153
+ */
154
+ var TaAgentSummary;
155
+ (function (TaAgentSummary) {
156
+ const START = /^\s*<conversation_history_summary>/;
157
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
158
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
159
+ function read(text) {
160
+ if (!START.test(text)) {
161
+ return undefined;
162
+ }
163
+ return text
164
+ .replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
165
+ .replace(/<\/?\w*$/, '')
166
+ .trim();
167
+ }
168
+ TaAgentSummary.read = read;
169
+ /** The text without the summary it starts with. */
170
+ function strip(text) {
171
+ return text.replace(BLOCK, '');
172
+ }
173
+ TaAgentSummary.strip = strip;
174
+ })(TaAgentSummary || (exports.TaAgentSummary = TaAgentSummary = {}));
175
+ /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
176
+ var TaSkillUse;
177
+ (function (TaSkillUse) {
178
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
179
+ function parse(message) {
180
+ var _a;
181
+ const match = BLOCK.exec(message);
182
+ if (!match) {
183
+ return undefined;
184
+ }
185
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
186
+ }
187
+ TaSkillUse.parse = parse;
188
+ /** What the user typed: `/skill:name` and what follows. */
189
+ function command(use) {
190
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
191
+ }
192
+ TaSkillUse.command = command;
193
+ })(TaSkillUse || (exports.TaSkillUse = TaSkillUse = {}));
194
+ /**
195
+ * The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
196
+ * and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
197
+ * conversations says by the task's title.
198
+ */
199
+ var TaTaskNote;
200
+ (function (TaTaskNote) {
201
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
202
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
203
+ function write(note) {
204
+ const attributes = [`id="${quote(note.id)}"`];
205
+ if (note.was !== undefined) {
206
+ attributes.push(`was="${quote(note.was)}"`);
207
+ }
208
+ attributes.push(`title="${quote(note.title)}"`);
209
+ if (note.status !== undefined) {
210
+ attributes.push(`status="${quote(note.status)}"`);
211
+ }
212
+ return `<task_${note.kind} ${attributes.join(' ')}>\n${note.body}\n</task_${note.kind}>`;
213
+ }
214
+ TaTaskNote.write = write;
215
+ /** The note `text` is, all of it; undefined for anything else. */
216
+ function parse(text) {
217
+ const match = NOTE.exec(text.trim());
218
+ if (!match) {
219
+ return undefined;
220
+ }
221
+ const attributes = {};
222
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
223
+ attributes[name] = unquote(value);
224
+ }
225
+ if (!attributes.id || attributes.title === undefined) {
226
+ return undefined;
227
+ }
228
+ const { id, title, status, was } = attributes;
229
+ return { kind: match[1], id, title, ...(status ? { status } : {}), ...(was ? { was } : {}), body: match[3] };
230
+ }
231
+ TaTaskNote.parse = parse;
232
+ /** A title the model gave, in the quotes of an attribute: a quote in it would end the attribute, a new line the tag. */
233
+ function quote(text) {
234
+ return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/\n/g, ' ');
235
+ }
236
+ function unquote(text) {
237
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, '&');
238
+ }
239
+ })(TaTaskNote || (exports.TaTaskNote = TaTaskNote = {}));
240
+ //# sourceMappingURL=message-protocol.js.map
@@ -0,0 +1,57 @@
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
+ }
57
+ //# sourceMappingURL=page-protocol.d.ts.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TA_PAGE_CONFIRM = exports.TA_PAGE_ASK_MS = exports.TA_PAGE_SERVICE = exports.TaPageServer = void 0;
4
+ /**
5
+ * 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
6
+ * answers (TaPageServer.attach) and is asked one by TaClient.onPageAsk, on its own connection. A package of Ta asks
7
+ * the page of who asked its run (TaExtensionHost.pages), never another's: what one sees on their screen is theirs.
8
+ */
9
+ exports.TaPageServer = Symbol('TaPageServer');
10
+ exports.TA_PAGE_SERVICE = 'TaPageServer';
11
+ /** How long a page may take to answer, unless the asker says otherwise. */
12
+ exports.TA_PAGE_ASK_MS = 30000;
13
+ /** A request of ta serve itself: the user agrees on their screen to something an agent wants to do (TaPageConfirm). */
14
+ exports.TA_PAGE_CONFIRM = 'ta/confirm';
15
+ //# sourceMappingURL=page-protocol.js.map
@@ -0,0 +1,25 @@
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
+ }
25
+ //# sourceMappingURL=path-map.d.ts.map
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaPathMap = void 0;
4
+ /**
5
+ * 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
6
+ * project in another folder. A base is matched whatever its separators, and regardless of case for a path of Windows;
7
+ * what follows it takes the separators of the base it is mapped to.
8
+ */
9
+ var TaPathMap;
10
+ (function (TaPathMap) {
11
+ /** `C:\...`, `c:/...` or `\\server\share`. */
12
+ function isWindows(path) {
13
+ return /^[a-zA-Z]:([\\/]|$)/.test(path) || /^\\\\[^\\]/.test(path);
14
+ }
15
+ TaPathMap.isWindows = isWindows;
16
+ /** The parts of `path` after `base`, none when it is `base`; undefined when it is not `base` nor under it. */
17
+ function rest(path, base) {
18
+ const windows = isWindows(base);
19
+ if (windows ? !isWindows(path) : !base.startsWith('/') || !path.startsWith('/')) {
20
+ return undefined;
21
+ }
22
+ const within = parts(base, windows);
23
+ const all = parts(path, windows);
24
+ if (!within.length || all.length < within.length) {
25
+ return undefined;
26
+ }
27
+ const same = (a, b) => (windows ? a.toLowerCase() === b.toLowerCase() : a === b);
28
+ return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
29
+ }
30
+ TaPathMap.rest = rest;
31
+ function under(path, base) {
32
+ return rest(path, base) !== undefined;
33
+ }
34
+ TaPathMap.under = under;
35
+ /** `parts` under `base`, with its separator. */
36
+ function join(base, parts) {
37
+ if (!parts.length) {
38
+ return base;
39
+ }
40
+ const sep = isWindows(base) ? '\\' : '/';
41
+ return `${base.replace(/[\\/]+$/, '')}${sep}${parts.join(sep)}`;
42
+ }
43
+ TaPathMap.join = join;
44
+ /** The last part of a path, of either kind. */
45
+ function basename(path) {
46
+ var _a;
47
+ return ((_a = path
48
+ .split(/[\\/]+/)
49
+ .filter(Boolean)
50
+ .pop()) !== null && _a !== void 0 ? _a : '');
51
+ }
52
+ TaPathMap.basename = basename;
53
+ /** A path under the deepest base of `pairs` it is under, as it is there; else itself. */
54
+ function path(value, pairs) {
55
+ for (const [from, to] of deepest(pairs)) {
56
+ const found = rest(value, from);
57
+ if (found) {
58
+ return join(to, found);
59
+ }
60
+ }
61
+ return value;
62
+ }
63
+ TaPathMap.path = path;
64
+ /** The paths in a text (a command, `dir:<path>`), each mapped as `path` maps it; a path ends at a space or a quote. */
65
+ function text(value, pairs) {
66
+ const order = deepest(pairs);
67
+ if (!order.length) {
68
+ return value;
69
+ }
70
+ const end = String.raw `\s"'<>|*?:;,`;
71
+ const pattern = new RegExp(String.raw `(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join('|')})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, 'g');
72
+ return value.replace(pattern, (...match) => {
73
+ var _a;
74
+ const before = match[1];
75
+ const found = order.findIndex((_, i) => match[i + 2] !== undefined);
76
+ const tail = (_a = match[order.length + 2]) !== null && _a !== void 0 ? _a : '';
77
+ return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
78
+ });
79
+ }
80
+ TaPathMap.text = text;
81
+ /** Every string of a value of JSON, keys too, mapped: a whole path as `path` maps it, paths in a text as `text` does. */
82
+ function json(value, pairs) {
83
+ const order = deepest(pairs);
84
+ if (!order.length) {
85
+ return value;
86
+ }
87
+ const one = (each) => {
88
+ const whole = path(each, order);
89
+ return whole !== each ? whole : text(each, order);
90
+ };
91
+ const walk = (each) => {
92
+ if (typeof each === 'string') {
93
+ return one(each);
94
+ }
95
+ if (Array.isArray(each)) {
96
+ return each.map(walk);
97
+ }
98
+ if (each && typeof each === 'object') {
99
+ return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
100
+ }
101
+ return each;
102
+ };
103
+ return walk(value);
104
+ }
105
+ TaPathMap.json = json;
106
+ function parts(path, windows) {
107
+ return path.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
108
+ }
109
+ /** The pairs that map something, the deepest base first: a path goes under the nearest. */
110
+ function deepest(pairs) {
111
+ return pairs
112
+ .filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0)
113
+ .sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
114
+ }
115
+ /** A base as a pattern: its parts by any separator, and for Windows regardless of case. */
116
+ function source(base) {
117
+ const windows = isWindows(base);
118
+ const quote = (part) => [...part]
119
+ .map(char => windows && char.toLowerCase() !== char.toUpperCase()
120
+ ? `[${char.toLowerCase()}${char.toUpperCase()}]`
121
+ : char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
122
+ .join('');
123
+ const each = parts(base, windows).map(quote);
124
+ if (!windows) {
125
+ return `/${each.join('/+')}`;
126
+ }
127
+ return `${base.startsWith('\\\\') ? String.raw `\\\\` : ''}${each.join(String.raw `[\\/]+`)}`;
128
+ }
129
+ })(TaPathMap || (exports.TaPathMap = TaPathMap = {}));
130
+ //# sourceMappingURL=path-map.js.map
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaMessageAuthor = exports.TA_PRESENCE_EXPIRY_MS = exports.TA_PRESENCE_HEARTBEAT_MS = exports.TA_PRESENCE_SERVICE = exports.TaPresenceServer = void 0;
4
- const ta_protocol_1 = require("./ta-protocol");
4
+ const message_protocol_1 = require("./message-protocol");
5
5
  exports.TaPresenceServer = Symbol('TaPresenceServer');
6
6
  exports.TA_PRESENCE_SERVICE = 'TaPresenceServer';
7
7
  /** A page says what it is at again this often while it lasts, the same or not. */
@@ -19,13 +19,13 @@ var TaMessageAuthor;
19
19
  const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
20
20
  /** `message` without the lines of an author. */
21
21
  function strip(message) {
22
- const context = ta_protocol_1.TaMessageContext.read(message);
22
+ const context = message_protocol_1.TaMessageContext.read(message);
23
23
  if (context === undefined || !LINE.test(context)) {
24
24
  return message;
25
25
  }
26
26
  const kept = context.replace(LINES, '').replace(/\n+$/, '');
27
- const body = ta_protocol_1.TaMessageContext.strip(message);
28
- return kept.trim() ? ta_protocol_1.TaMessageContext.wrap(kept, body) : body;
27
+ const body = message_protocol_1.TaMessageContext.strip(message);
28
+ return kept.trim() ? message_protocol_1.TaMessageContext.wrap(kept, body) : body;
29
29
  }
30
30
  TaMessageAuthor.strip = strip;
31
31
  /** `message` as written by `id`, called `name`; a command (`/compact`, `!ls`) stays a command. */
@@ -35,14 +35,14 @@ var TaMessageAuthor;
35
35
  return plain;
36
36
  }
37
37
  const line = `[ta:by ${id.replace(/[\s\]]/g, '')} ${name.replace(/[\]\n]/g, ' ').trim() || id}]`;
38
- const context = ta_protocol_1.TaMessageContext.read(plain);
39
- return ta_protocol_1.TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, ta_protocol_1.TaMessageContext.strip(plain));
38
+ const context = message_protocol_1.TaMessageContext.read(plain);
39
+ return message_protocol_1.TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, message_protocol_1.TaMessageContext.strip(plain));
40
40
  }
41
41
  TaMessageAuthor.mark = mark;
42
42
  /** Who wrote it; undefined for the user of the Ta (no line). */
43
43
  function of(message) {
44
44
  var _a;
45
- const context = ta_protocol_1.TaMessageContext.read(message);
45
+ const context = message_protocol_1.TaMessageContext.read(message);
46
46
  const match = context === undefined ? null : LINE.exec(context);
47
47
  return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== void 0 ? _a : match[1]).trim() } : undefined;
48
48
  }
@@ -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. */