@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.
- package/esm/common/access-protocol.d.ts +41 -0
- package/esm/common/access-protocol.js +7 -0
- package/esm/common/app-protocol.d.ts +120 -0
- package/esm/common/app-protocol.js +213 -0
- package/esm/common/delegate-protocol.d.ts +30 -0
- package/esm/common/delegate-protocol.js +52 -0
- package/esm/common/deployment-protocol.d.ts +72 -0
- package/esm/common/deployment-protocol.js +171 -0
- package/esm/common/error-protocol.d.ts +42 -0
- package/esm/common/error-protocol.js +45 -0
- package/esm/common/event-protocol.d.ts +63 -0
- package/esm/common/event-protocol.js +2 -0
- package/esm/common/gateway-protocol.d.ts +29 -0
- package/esm/common/index.d.ts +11 -0
- package/esm/common/index.js +11 -0
- package/esm/common/message-protocol.d.ts +134 -0
- package/esm/common/message-protocol.js +322 -0
- package/esm/common/page-protocol.d.ts +56 -0
- package/esm/common/page-protocol.js +12 -0
- package/esm/common/path-map.d.ts +24 -0
- package/esm/common/path-map.js +127 -0
- package/esm/common/presence-protocol.js +1 -1
- package/esm/common/redactor.d.ts +12 -0
- package/esm/common/redactor.js +49 -11
- package/esm/common/relay-protocol.d.ts +20 -0
- package/esm/common/room-protocol.d.ts +52 -1
- package/esm/common/said-protocol.d.ts +76 -0
- package/esm/common/said-protocol.js +239 -0
- package/esm/common/screen-share-protocol.d.ts +304 -0
- package/esm/common/screen-share-protocol.js +88 -0
- package/esm/common/settings-protocol.d.ts +8 -0
- package/esm/common/settings-protocol.js +2 -0
- package/esm/common/ta-extension-host.d.ts +64 -1
- package/esm/common/ta-extension-host.js +8 -0
- package/esm/common/ta-protocol.d.ts +53 -175
- package/esm/common/ta-protocol.js +0 -234
- package/esm/common/team-protocol.d.ts +13 -2
- package/esm/common/team-protocol.js +27 -2
- package/esm/common/voice-protocol.d.ts +184 -0
- package/esm/common/voice-protocol.js +57 -0
- package/lib/common/access-protocol.d.ts +41 -0
- package/lib/common/access-protocol.js +8 -1
- package/lib/common/app-protocol.d.ts +121 -0
- package/lib/common/app-protocol.js +216 -0
- package/lib/common/delegate-protocol.d.ts +31 -0
- package/lib/common/delegate-protocol.js +55 -0
- package/lib/common/deployment-protocol.d.ts +73 -0
- package/lib/common/deployment-protocol.js +175 -0
- package/lib/common/error-protocol.d.ts +43 -0
- package/lib/common/error-protocol.js +48 -0
- package/lib/common/event-protocol.d.ts +64 -0
- package/lib/common/event-protocol.js +3 -0
- package/lib/common/gateway-protocol.d.ts +29 -0
- package/lib/common/index.d.ts +11 -0
- package/lib/common/index.js +11 -0
- package/lib/common/message-protocol.d.ts +135 -0
- package/lib/common/message-protocol.js +325 -0
- package/lib/common/page-protocol.d.ts +57 -0
- package/lib/common/page-protocol.js +15 -0
- package/lib/common/path-map.d.ts +25 -0
- package/lib/common/path-map.js +130 -0
- package/lib/common/presence-protocol.js +7 -7
- package/lib/common/redactor.d.ts +12 -0
- package/lib/common/redactor.js +49 -11
- package/lib/common/relay-protocol.d.ts +20 -0
- package/lib/common/room-protocol.d.ts +52 -1
- package/lib/common/said-protocol.d.ts +77 -0
- package/lib/common/said-protocol.js +242 -0
- package/lib/common/screen-share-protocol.d.ts +305 -0
- package/lib/common/screen-share-protocol.js +91 -0
- package/lib/common/settings-protocol.d.ts +8 -0
- package/lib/common/settings-protocol.js +3 -1
- package/lib/common/ta-extension-host.d.ts +64 -1
- package/lib/common/ta-extension-host.js +9 -1
- package/lib/common/ta-protocol.d.ts +53 -175
- package/lib/common/ta-protocol.js +1 -235
- package/lib/common/team-protocol.d.ts +13 -2
- package/lib/common/team-protocol.js +28 -3
- package/lib/common/voice-protocol.d.ts +185 -0
- package/lib/common/voice-protocol.js +60 -0
- package/package.json +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
* Who wrote a message of the user's role (docs/design/ta-sources.md). What the user typed has no mark. A message a
|
|
27
|
+
* package sends for the user (their choice in a card, what they said in a call, a task they scheduled) says so in the
|
|
28
|
+
* last line of its `<context>` block, `[ta:from <name> <detail>]`: it is theirs. A message that is not theirs (news of
|
|
29
|
+
* work elsewhere, a time limit, a grant) is a notice, `[ta:notice <name> <detail>]`: the model reads it as information
|
|
30
|
+
* below what the user said (the section `<ta-sources>` of the system prompt), and a page shows it as a line, not as a
|
|
31
|
+
* bubble of the user. A page older than these leaves them out with the rest of the context. A command (`/compact`,
|
|
32
|
+
* `!ls`) is not marked.
|
|
33
|
+
*/
|
|
34
|
+
export var TaMessageSource;
|
|
35
|
+
(function (TaMessageSource) {
|
|
36
|
+
/** The double of the web page: the tasks it hands out, what it tells them on the way. */
|
|
37
|
+
TaMessageSource.DOUBLE = 'ta:double';
|
|
38
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
39
|
+
/** `message` as sent by `from` for the user; as it was when it is a command or says where it came from already. */
|
|
40
|
+
function mark(message, from, detail) {
|
|
41
|
+
return marked(message, line(from, detail));
|
|
42
|
+
}
|
|
43
|
+
TaMessageSource.mark = mark;
|
|
44
|
+
/** `message` as a notice of `from`: not the user's; as it was when it says where it came from already. */
|
|
45
|
+
function notice(message, from, detail) {
|
|
46
|
+
return marked(message, line(from, detail, true));
|
|
47
|
+
}
|
|
48
|
+
TaMessageSource.notice = notice;
|
|
49
|
+
/** The line of the context that says a message came from `from` (a notice of it, with `notice`), for one who writes the context of their own. */
|
|
50
|
+
function line(from, detail, notice = false) {
|
|
51
|
+
return `[ta:${notice ? 'notice' : 'from'} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
|
|
52
|
+
}
|
|
53
|
+
TaMessageSource.line = line;
|
|
54
|
+
function of(message) {
|
|
55
|
+
const context = TaMessageContext.read(message);
|
|
56
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
57
|
+
return match
|
|
58
|
+
? { from: match[2], ...(match[3] ? { detail: match[3].trim() } : {}), ...(match[1] === 'notice' ? { notice: true } : {}) }
|
|
59
|
+
: undefined;
|
|
60
|
+
}
|
|
61
|
+
TaMessageSource.of = of;
|
|
62
|
+
/** Whether a message is a notice: not the user's (TaMessageSource.notice). */
|
|
63
|
+
function isNotice(message) {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = of(message)) === null || _a === void 0 ? void 0 : _a.notice) === true;
|
|
66
|
+
}
|
|
67
|
+
TaMessageSource.isNotice = isNotice;
|
|
68
|
+
/** The section of the system prompt that says who wrote a message, and that the user's words come first (SourcesExtension of ta-host). */
|
|
69
|
+
TaMessageSource.SECTION = 'ta-sources';
|
|
70
|
+
TaMessageSource.PROMPT = [
|
|
71
|
+
'Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.',
|
|
72
|
+
"One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
|
|
73
|
+
'- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.',
|
|
74
|
+
'- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).',
|
|
75
|
+
"- Never quote it as the user's words nor answer it as if they had said it.",
|
|
76
|
+
].join('\n');
|
|
77
|
+
function marked(message, source) {
|
|
78
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
79
|
+
return message;
|
|
80
|
+
}
|
|
81
|
+
const context = TaMessageContext.read(message);
|
|
82
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}\n${source}`, TaMessageContext.strip(message));
|
|
83
|
+
}
|
|
84
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
85
|
+
/**
|
|
86
|
+
* 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
|
|
87
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
88
|
+
*/
|
|
89
|
+
export var TaImageNote;
|
|
90
|
+
(function (TaImageNote) {
|
|
91
|
+
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 [^\]]+\.\]$/;
|
|
92
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
93
|
+
function strip(text) {
|
|
94
|
+
const lines = text.split('\n');
|
|
95
|
+
const kept = lines.filter(line => !NOTE.test(line.trim()));
|
|
96
|
+
if (kept.length === lines.length) {
|
|
97
|
+
return text;
|
|
98
|
+
}
|
|
99
|
+
return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
|
|
100
|
+
}
|
|
101
|
+
TaImageNote.strip = strip;
|
|
102
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
103
|
+
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
104
|
+
export var TaImageSize;
|
|
105
|
+
(function (TaImageSize) {
|
|
106
|
+
/** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
|
|
107
|
+
const JPEG_BYTES = 256 * 1024;
|
|
108
|
+
function of(base64) {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
let bytes;
|
|
111
|
+
try {
|
|
112
|
+
// Whole groups of four characters only.
|
|
113
|
+
const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
|
|
114
|
+
bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
|
|
115
|
+
}
|
|
116
|
+
catch (_d) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
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);
|
|
120
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
121
|
+
}
|
|
122
|
+
TaImageSize.of = of;
|
|
123
|
+
function u16be(bytes, at) {
|
|
124
|
+
return (bytes[at] << 8) | bytes[at + 1];
|
|
125
|
+
}
|
|
126
|
+
function u16le(bytes, at) {
|
|
127
|
+
return bytes[at] | (bytes[at + 1] << 8);
|
|
128
|
+
}
|
|
129
|
+
function u24le(bytes, at) {
|
|
130
|
+
return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
|
|
131
|
+
}
|
|
132
|
+
function u32be(bytes, at) {
|
|
133
|
+
return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
134
|
+
}
|
|
135
|
+
function text(bytes, at, length) {
|
|
136
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
137
|
+
}
|
|
138
|
+
function png(bytes) {
|
|
139
|
+
return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
140
|
+
}
|
|
141
|
+
function gif(bytes) {
|
|
142
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
143
|
+
}
|
|
144
|
+
function webp(bytes) {
|
|
145
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
switch (text(bytes, 12, 4)) {
|
|
149
|
+
case 'VP8 ':
|
|
150
|
+
return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
|
|
151
|
+
case 'VP8L': {
|
|
152
|
+
const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
|
|
153
|
+
return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
|
|
154
|
+
}
|
|
155
|
+
case 'VP8X':
|
|
156
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
157
|
+
default:
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function jpeg(bytes) {
|
|
162
|
+
if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
let at = 2;
|
|
166
|
+
while (at + 9 < bytes.length) {
|
|
167
|
+
if (bytes[at] !== 0xff) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const marker = bytes[at + 1];
|
|
171
|
+
// A start of frame (not DHT, JPG or DAC, which share the range) says the size.
|
|
172
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
173
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
174
|
+
}
|
|
175
|
+
at += 2 + u16be(bytes, at + 2);
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
180
|
+
/**
|
|
181
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
182
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
183
|
+
*/
|
|
184
|
+
export var TaAgentSummary;
|
|
185
|
+
(function (TaAgentSummary) {
|
|
186
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
187
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
188
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
189
|
+
function read(text) {
|
|
190
|
+
if (!START.test(text)) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
return text
|
|
194
|
+
.replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
|
|
195
|
+
.replace(/<\/?\w*$/, '')
|
|
196
|
+
.trim();
|
|
197
|
+
}
|
|
198
|
+
TaAgentSummary.read = read;
|
|
199
|
+
/** The text without the summary it starts with. */
|
|
200
|
+
function strip(text) {
|
|
201
|
+
return text.replace(BLOCK, '');
|
|
202
|
+
}
|
|
203
|
+
TaAgentSummary.strip = strip;
|
|
204
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
205
|
+
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
206
|
+
export var TaSkillUse;
|
|
207
|
+
(function (TaSkillUse) {
|
|
208
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
209
|
+
function parse(message) {
|
|
210
|
+
var _a;
|
|
211
|
+
const match = BLOCK.exec(message);
|
|
212
|
+
if (!match) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
|
|
216
|
+
}
|
|
217
|
+
TaSkillUse.parse = parse;
|
|
218
|
+
/** What the user typed: `/skill:name` and what follows. */
|
|
219
|
+
function command(use) {
|
|
220
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
221
|
+
}
|
|
222
|
+
TaSkillUse.command = command;
|
|
223
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
224
|
+
/**
|
|
225
|
+
* The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
|
|
226
|
+
* and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
|
|
227
|
+
* conversations says by the task's title.
|
|
228
|
+
*/
|
|
229
|
+
export var TaTaskNote;
|
|
230
|
+
(function (TaTaskNote) {
|
|
231
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
232
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
233
|
+
function write(note) {
|
|
234
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
235
|
+
if (note.was !== undefined) {
|
|
236
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
237
|
+
}
|
|
238
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
239
|
+
if (note.status !== undefined) {
|
|
240
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
241
|
+
}
|
|
242
|
+
return `<task_${note.kind} ${attributes.join(' ')}>\n${note.body}\n</task_${note.kind}>`;
|
|
243
|
+
}
|
|
244
|
+
TaTaskNote.write = write;
|
|
245
|
+
/** The note `text` is, all of it; undefined for anything else. */
|
|
246
|
+
function parse(text) {
|
|
247
|
+
const match = NOTE.exec(text.trim());
|
|
248
|
+
if (!match) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const attributes = {};
|
|
252
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
253
|
+
attributes[name] = unquote(value);
|
|
254
|
+
}
|
|
255
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
const { id, title, status, was } = attributes;
|
|
259
|
+
return { kind: match[1], id, title, ...(status ? { status } : {}), ...(was ? { was } : {}), body: match[3] };
|
|
260
|
+
}
|
|
261
|
+
TaTaskNote.parse = parse;
|
|
262
|
+
/** A title the model gave, in the quotes of an attribute: a quote in it would end the attribute, a new line the tag. */
|
|
263
|
+
function quote(text) {
|
|
264
|
+
return text.replace(/&/g, '&').replace(/"/g, '"').replace(/\n/g, ' ');
|
|
265
|
+
}
|
|
266
|
+
function unquote(text) {
|
|
267
|
+
return text.replace(/"/g, '"').replace(/&/g, '&');
|
|
268
|
+
}
|
|
269
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
270
|
+
/**
|
|
271
|
+
* The names the vault of Ta (ta-secrets) puts in place of what it took out of a message (`$TA_SECRET_PHONE`,
|
|
272
|
+
* `${TA_SECRET_GITHUB_TOKEN}`): the model reads them so; a page shows each as what it stands for, not as a variable.
|
|
273
|
+
*/
|
|
274
|
+
export var TaSecretRef;
|
|
275
|
+
(function (TaSecretRef) {
|
|
276
|
+
/** The package of the vault: `list` of its host gives what it keeps by name, the masked hint of a personal detail, never a value. */
|
|
277
|
+
TaSecretRef.PACKAGE = '@celljs/ta-secrets';
|
|
278
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
279
|
+
const KINDS = [
|
|
280
|
+
[/^PHONE(?:_\d+)?$/, 'phone'],
|
|
281
|
+
[/^EMAIL(?:_\d+)?$/, 'email'],
|
|
282
|
+
[/^ID_NUMBER(?:_\d+)?$/, 'idNumber'],
|
|
283
|
+
[/^BANK_CARD(?:_\d+)?$/, 'bankCard'],
|
|
284
|
+
];
|
|
285
|
+
function has(text) {
|
|
286
|
+
return text.includes('TA_SECRET_') && new RegExp(REF.source).test(text);
|
|
287
|
+
}
|
|
288
|
+
TaSecretRef.has = has;
|
|
289
|
+
/** What a name is of: the kinds of personal details the vault takes in by itself, `secret` for the rest. */
|
|
290
|
+
function kind(name) {
|
|
291
|
+
var _a;
|
|
292
|
+
var _b;
|
|
293
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : 'secret';
|
|
294
|
+
}
|
|
295
|
+
TaSecretRef.kind = kind;
|
|
296
|
+
/** The text in parts, its names apart; one part of words when it has none. */
|
|
297
|
+
function split(text) {
|
|
298
|
+
if (!has(text)) {
|
|
299
|
+
return [{ text }];
|
|
300
|
+
}
|
|
301
|
+
const parts = [];
|
|
302
|
+
let at = 0;
|
|
303
|
+
for (const match of text.matchAll(REF)) {
|
|
304
|
+
if (match.index > at) {
|
|
305
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
306
|
+
}
|
|
307
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
308
|
+
at = match.index + match[0].length;
|
|
309
|
+
}
|
|
310
|
+
if (at < text.length) {
|
|
311
|
+
parts.push({ text: text.slice(at) });
|
|
312
|
+
}
|
|
313
|
+
return parts;
|
|
314
|
+
}
|
|
315
|
+
TaSecretRef.split = split;
|
|
316
|
+
/** The text with each name as `label` says it, for a line that shows no more than words (a preview). */
|
|
317
|
+
function plain(text, label) {
|
|
318
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
319
|
+
}
|
|
320
|
+
TaSecretRef.plain = plain;
|
|
321
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
322
|
+
//# 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 './
|
|
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. */
|
package/esm/common/redactor.d.ts
CHANGED
|
@@ -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. */
|
package/esm/common/redactor.js
CHANGED
|
@@ -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
|
}
|