@celljs/ta-protocol 4.10.0 → 4.12.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/index.d.ts +1 -0
- package/esm/common/index.js +1 -0
- package/esm/common/package-protocol.d.ts +16 -5
- package/esm/common/redactor.d.ts +18 -0
- package/esm/common/redactor.js +66 -0
- package/esm/common/relay-protocol.d.ts +60 -0
- package/esm/common/room-protocol.d.ts +166 -0
- package/esm/common/room-protocol.js +36 -0
- package/esm/common/ta-extension-host.d.ts +34 -0
- package/esm/common/ta-extension-host.js +33 -0
- package/esm/common/ta-protocol.d.ts +91 -5
- package/esm/common/ta-protocol.js +87 -0
- package/esm/common/workspace-protocol.d.ts +2 -2
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/package-protocol.d.ts +16 -5
- package/lib/common/redactor.d.ts +19 -0
- package/lib/common/redactor.js +70 -0
- package/lib/common/relay-protocol.d.ts +60 -0
- package/lib/common/room-protocol.d.ts +167 -0
- package/lib/common/room-protocol.js +39 -0
- package/lib/common/ta-extension-host.d.ts +34 -0
- package/lib/common/ta-extension-host.js +34 -1
- package/lib/common/ta-protocol.d.ts +91 -5
- package/lib/common/ta-protocol.js +88 -1
- package/lib/common/workspace-protocol.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TaAuthEvent } from './auth-protocol.js';
|
|
2
2
|
import type { ImageContent, JsonAgentSessionEvent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types.js';
|
|
3
3
|
import type { TaRemoteEvent } from './remote-protocol.js';
|
|
4
|
+
import type { TaRoomEvent } from './room-protocol.js';
|
|
4
5
|
export declare const TaServer: unique symbol;
|
|
5
6
|
export declare const TaClient: unique symbol;
|
|
6
7
|
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
@@ -28,6 +29,8 @@ export interface TaServerInfo {
|
|
|
28
29
|
user: string;
|
|
29
30
|
/** The name of the machine of `ta serve`, without a `.local` suffix. */
|
|
30
31
|
host: string;
|
|
32
|
+
/** The home directory of that user there: what `~` of a path a reply names is. None from a ta serve of before. */
|
|
33
|
+
home?: string;
|
|
31
34
|
}
|
|
32
35
|
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
33
36
|
export declare const TaErrorCode: {
|
|
@@ -92,6 +95,18 @@ export type TaCommandResult<C extends TaCommand> = Extract<RpcResponse, {
|
|
|
92
95
|
}> extends {
|
|
93
96
|
data: infer D;
|
|
94
97
|
} ? D : undefined;
|
|
98
|
+
/**
|
|
99
|
+
* A command of the `/` menu as pi's `get_commands` gives it, with its description in other languages
|
|
100
|
+
* (`descriptions`, by language such as `zh-CN`): its package gives them in `pi.descriptions` of its package.json,
|
|
101
|
+
* by the name of the command (`loop`, `skill:ta-game`). `description` stays the one pi and the model read.
|
|
102
|
+
*/
|
|
103
|
+
export type TaSlashCommand = TaCommandResult<'get_commands'>['commands'][number] & {
|
|
104
|
+
descriptions?: Readonly<Record<string, string>>;
|
|
105
|
+
};
|
|
106
|
+
export declare namespace TaSlashCommandUtil {
|
|
107
|
+
/** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
|
|
108
|
+
function description(command: Pick<TaSlashCommand, 'description' | 'descriptions'>, language: string): string | undefined;
|
|
109
|
+
}
|
|
95
110
|
/** A tool the client runs: the model calls it like any other tool, the server asks the client for the result. */
|
|
96
111
|
export interface TaClientToolDefinition {
|
|
97
112
|
/** Letters, digits, `_` and `-`, starting with a letter; best not the name of another tool of the session. */
|
|
@@ -114,6 +129,15 @@ export interface TaOpenSessionOptions {
|
|
|
114
129
|
appendSystemPrompt?: string;
|
|
115
130
|
/** Sessions a package opens for its own work (the name of the package): clients list them apart, folded. */
|
|
116
131
|
group?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Attaches the connection as it opens, as `attach` without `afterSeq`: the conversation comes with the
|
|
134
|
+
* answer (TaOpenedSession.attachment), one round trip less before it shows. A server before it attaches nothing.
|
|
135
|
+
*/
|
|
136
|
+
attach?: TaAttachOptions;
|
|
137
|
+
}
|
|
138
|
+
export interface TaOpenedSession extends TaSessionInfo {
|
|
139
|
+
/** What `attach` gives, when the session was opened with `attach`: the connection follows it from `attachment.lastSeq`. */
|
|
140
|
+
attachment?: TaAttachResult;
|
|
117
141
|
}
|
|
118
142
|
export interface TaSessionInfo {
|
|
119
143
|
/** The id of this open session; stays the same through `newSession`, `switchSession` and `fork`. */
|
|
@@ -130,6 +154,11 @@ export interface TaSessionInfo {
|
|
|
130
154
|
/** `<provider>/<model id>`. */
|
|
131
155
|
model?: string;
|
|
132
156
|
isStreaming: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* A dialog of an extension waits for the user's answer (a confirmation, a choice): a list shows that the
|
|
159
|
+
* session needs them. None from a Ta service of before.
|
|
160
|
+
*/
|
|
161
|
+
waiting?: boolean;
|
|
133
162
|
messageCount: number;
|
|
134
163
|
/** Number of clients attached. */
|
|
135
164
|
attached: number;
|
|
@@ -159,6 +188,16 @@ export interface TaSavedSessionInfo {
|
|
|
159
188
|
/** The group it was opened for (TaOpenSessionOptions.group): its package opens it again, with its role. */
|
|
160
189
|
group?: string;
|
|
161
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Which saved conversations a list reads, by when they were updated (TaSavedSessionInfo.updatedAt): a list
|
|
193
|
+
* read every few seconds leaves out the old ones (archived), read only when shown.
|
|
194
|
+
*/
|
|
195
|
+
export interface TaSavedSessionQuery {
|
|
196
|
+
/** Those updated at this time (`Date.now()` time) or later. */
|
|
197
|
+
since?: number;
|
|
198
|
+
/** Those updated before this time. */
|
|
199
|
+
before?: number;
|
|
200
|
+
}
|
|
162
201
|
export interface TaPromptInput {
|
|
163
202
|
/** May start with a block of context for the model, which clients do not show: see {@link TaMessageContext}. */
|
|
164
203
|
message: string;
|
|
@@ -185,6 +224,13 @@ export declare namespace TaImageNote {
|
|
|
185
224
|
/** The text without the notes of its images: what the user sees of it. */
|
|
186
225
|
function strip(text: string): string;
|
|
187
226
|
}
|
|
227
|
+
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
228
|
+
export declare namespace TaImageSize {
|
|
229
|
+
function of(base64: string): {
|
|
230
|
+
width: number;
|
|
231
|
+
height: number;
|
|
232
|
+
} | undefined;
|
|
233
|
+
}
|
|
188
234
|
/**
|
|
189
235
|
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
190
236
|
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
@@ -316,6 +362,17 @@ export interface TaAttachOptions {
|
|
|
316
362
|
*/
|
|
317
363
|
recentBytes?: number;
|
|
318
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* An image of a message of the user as the conversation gives it: its kind and size, `data` empty; its bytes come
|
|
367
|
+
* with `getMessageImage` once it shows, so that a conversation with pictures opens as fast as one without.
|
|
368
|
+
*/
|
|
369
|
+
export interface TaShownImage {
|
|
370
|
+
type: 'image';
|
|
371
|
+
mimeType: string;
|
|
372
|
+
data: '';
|
|
373
|
+
width?: number;
|
|
374
|
+
height?: number;
|
|
375
|
+
}
|
|
319
376
|
/** The messages of a conversation before those a client has (`getEarlierMessages`). */
|
|
320
377
|
export interface TaMessagePage {
|
|
321
378
|
messages: TaMessage[];
|
|
@@ -365,11 +422,21 @@ export interface TaServer {
|
|
|
365
422
|
* restarts: where conversations open when the user names no directory. Sessions already open stay where they are.
|
|
366
423
|
*/
|
|
367
424
|
setWorkingDirectory(cwd: string): Promise<TaServerInfo>;
|
|
368
|
-
openSession(options: TaOpenSessionOptions): Promise<
|
|
425
|
+
openSession(options: TaOpenSessionOptions): Promise<TaOpenedSession>;
|
|
369
426
|
closeSession(sessionId: string): Promise<void>;
|
|
370
427
|
listSessions(): Promise<TaSessionInfo[]>;
|
|
371
|
-
/**
|
|
372
|
-
|
|
428
|
+
/**
|
|
429
|
+
* The open sessions, as listSessions, and from now on TaClient.onSessions with all of them whenever one
|
|
430
|
+
* opens, closes or changes what a list shows of it (it starts or stops working, a message ends, it is
|
|
431
|
+
* named, a dialog waits or is answered), for as long as the connection lasts. A Ta service of before has
|
|
432
|
+
* no such method: its clients read the list again now and then.
|
|
433
|
+
*/
|
|
434
|
+
watchSessions(): Promise<TaSessionInfo[]>;
|
|
435
|
+
/**
|
|
436
|
+
* The conversations in pi's session files that are not open, the latest first; with a query, those whose
|
|
437
|
+
* last message is in its window. A ta serve of before reads no query and lists them all.
|
|
438
|
+
*/
|
|
439
|
+
listSavedSessions(query?: TaSavedSessionQuery): Promise<TaSavedSessionInfo[]>;
|
|
373
440
|
/** Starts sending the events of the session to this connection. */
|
|
374
441
|
attach(sessionId: string, afterSeq?: number, options?: TaAttachOptions): Promise<TaAttachResult>;
|
|
375
442
|
/**
|
|
@@ -377,6 +444,12 @@ export interface TaServer {
|
|
|
377
444
|
* `timestamp` that of the message there, to know it is still the same; without `before`, the latest.
|
|
378
445
|
*/
|
|
379
446
|
getEarlierMessages(sessionId: string, before: number | undefined, timestamp: number | undefined, budget: number): Promise<TaMessagePage>;
|
|
447
|
+
/**
|
|
448
|
+
* An image of a message of the user: the conversation (`attach`, `getEarlierMessages`) gives them without
|
|
449
|
+
* their bytes (`TaShownImage`), which come with this when the image shows. `index`: of the block in the
|
|
450
|
+
* content of the message of `timestamp`. Undefined when the message is no longer there.
|
|
451
|
+
*/
|
|
452
|
+
getMessageImage(sessionId: string, timestamp: number, index: number): Promise<ImageContent | undefined>;
|
|
380
453
|
detach(sessionId: string): Promise<void>;
|
|
381
454
|
/** Answers a dialog; false when it was answered before or expired. */
|
|
382
455
|
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
@@ -386,7 +459,7 @@ export interface TaServer {
|
|
|
386
459
|
* that does something (opens a session) must not run in every page.
|
|
387
460
|
*/
|
|
388
461
|
claimClientTool(sessionId: string, id: string): Promise<boolean>;
|
|
389
|
-
/** Answers a call of a client tool; false when nobody waits for it. */
|
|
462
|
+
/** Answers a call of a client tool; false when nobody waits for it, or another client claimed it. */
|
|
390
463
|
respondClientTool(sessionId: string, result: TaClientToolResult): Promise<boolean>;
|
|
391
464
|
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
392
465
|
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
@@ -436,13 +509,24 @@ export interface TaServer {
|
|
|
436
509
|
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
437
510
|
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
438
511
|
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
439
|
-
getCommands(sessionId: string): Promise<
|
|
512
|
+
getCommands(sessionId: string): Promise<{
|
|
513
|
+
commands: TaSlashCommand[];
|
|
514
|
+
}>;
|
|
515
|
+
/**
|
|
516
|
+
* The commands a new conversation in `cwd` will have, before it is opened: for the `/` menu of a message
|
|
517
|
+
* that opens one. pi loads the extensions, prompts and skills of the directory for it, as a session does.
|
|
518
|
+
*/
|
|
519
|
+
getDirectoryCommands(cwd: string): Promise<{
|
|
520
|
+
commands: TaSlashCommand[];
|
|
521
|
+
}>;
|
|
440
522
|
/** Loads extensions, skills, prompts and themes again, as pi's `/reload` does. */
|
|
441
523
|
reload(sessionId: string): Promise<void>;
|
|
442
524
|
}
|
|
443
525
|
/** What a client implements. Events come in batches: one message per frame, however fast the model streams. */
|
|
444
526
|
export interface TaClient {
|
|
445
527
|
onEvents(events: TaEventEnvelope[]): Promise<void>;
|
|
528
|
+
/** The open sessions, newest last, once this connection called TaServer.watchSessions: at most every few hundred milliseconds. */
|
|
529
|
+
onSessions(sessions: TaSessionInfo[]): Promise<void>;
|
|
446
530
|
/** Output of a terminal of this connection; with `exitCode`, the terminal has ended. */
|
|
447
531
|
onTerminalData(terminalId: string, data: string, exitCode?: number): Promise<void>;
|
|
448
532
|
/**
|
|
@@ -455,5 +539,7 @@ export interface TaClient {
|
|
|
455
539
|
onAuthEvent(loginId: string, event: TaAuthEvent): Promise<void>;
|
|
456
540
|
/** What happens with the remote machines, once this connection called TaRemoteServer.watch. */
|
|
457
541
|
onRemoteEvent(event: TaRemoteEvent): Promise<void>;
|
|
542
|
+
/** What happens in the rooms, once this connection called TaRoomServer.watch. */
|
|
543
|
+
onRoomEvent(event: TaRoomEvent): Promise<void>;
|
|
458
544
|
}
|
|
459
545
|
export {};
|
|
@@ -44,6 +44,16 @@ export var TaErrorUtil;
|
|
|
44
44
|
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
45
45
|
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
46
46
|
export const TA_RPC_ERROR_CODE = -32050;
|
|
47
|
+
export var TaSlashCommandUtil;
|
|
48
|
+
(function (TaSlashCommandUtil) {
|
|
49
|
+
/** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
|
|
50
|
+
function description(command, language) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
const { descriptions } = command;
|
|
53
|
+
return (_b = (_a = descriptions === null || descriptions === void 0 ? void 0 : descriptions[language]) !== null && _a !== void 0 ? _a : descriptions === null || descriptions === void 0 ? void 0 : descriptions[language.split('-')[0]]) !== null && _b !== void 0 ? _b : command.description;
|
|
54
|
+
}
|
|
55
|
+
TaSlashCommandUtil.description = description;
|
|
56
|
+
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
47
57
|
/**
|
|
48
58
|
* A message of the user may start with a `<context>` block: what the model reads besides the message
|
|
49
59
|
* (where it is said, who is there, what was said before), which a client leaves out when it shows it.
|
|
@@ -79,6 +89,83 @@ export var TaImageNote;
|
|
|
79
89
|
}
|
|
80
90
|
TaImageNote.strip = strip;
|
|
81
91
|
})(TaImageNote || (TaImageNote = {}));
|
|
92
|
+
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
93
|
+
export var TaImageSize;
|
|
94
|
+
(function (TaImageSize) {
|
|
95
|
+
/** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
|
|
96
|
+
const JPEG_BYTES = 256 * 1024;
|
|
97
|
+
function of(base64) {
|
|
98
|
+
var _a, _b, _c;
|
|
99
|
+
let bytes;
|
|
100
|
+
try {
|
|
101
|
+
// Whole groups of four characters only.
|
|
102
|
+
const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
|
|
103
|
+
bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
|
|
104
|
+
}
|
|
105
|
+
catch (_d) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
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);
|
|
109
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
110
|
+
}
|
|
111
|
+
TaImageSize.of = of;
|
|
112
|
+
function u16be(bytes, at) {
|
|
113
|
+
return (bytes[at] << 8) | bytes[at + 1];
|
|
114
|
+
}
|
|
115
|
+
function u16le(bytes, at) {
|
|
116
|
+
return bytes[at] | (bytes[at + 1] << 8);
|
|
117
|
+
}
|
|
118
|
+
function u24le(bytes, at) {
|
|
119
|
+
return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
|
|
120
|
+
}
|
|
121
|
+
function u32be(bytes, at) {
|
|
122
|
+
return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
123
|
+
}
|
|
124
|
+
function text(bytes, at, length) {
|
|
125
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
126
|
+
}
|
|
127
|
+
function png(bytes) {
|
|
128
|
+
return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
129
|
+
}
|
|
130
|
+
function gif(bytes) {
|
|
131
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
132
|
+
}
|
|
133
|
+
function webp(bytes) {
|
|
134
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
switch (text(bytes, 12, 4)) {
|
|
138
|
+
case 'VP8 ':
|
|
139
|
+
return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
|
|
140
|
+
case 'VP8L': {
|
|
141
|
+
const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
|
|
142
|
+
return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
|
|
143
|
+
}
|
|
144
|
+
case 'VP8X':
|
|
145
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
146
|
+
default:
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function jpeg(bytes) {
|
|
151
|
+
if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
let at = 2;
|
|
155
|
+
while (at + 9 < bytes.length) {
|
|
156
|
+
if (bytes[at] !== 0xff) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
const marker = bytes[at + 1];
|
|
160
|
+
// A start of frame (not DHT, JPG or DAC, which share the range) says the size.
|
|
161
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
162
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
163
|
+
}
|
|
164
|
+
at += 2 + u16be(bytes, at + 2);
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
82
169
|
/**
|
|
83
170
|
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
84
171
|
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
@@ -82,8 +82,8 @@ export interface TaWorkspaceServer {
|
|
|
82
82
|
* A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
|
|
83
83
|
* what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
|
|
84
84
|
* no token, so that a page loads the files beside it with relative URLs; each `cwd` has its own
|
|
85
|
-
* secret part. A file outside `cwd` (an absolute path an agent wrote)
|
|
86
|
-
*
|
|
85
|
+
* secret part. A file outside `cwd` (an absolute path an agent wrote) has a secret part of its
|
|
86
|
+
* own that serves that file alone. Pages are answered sandboxed: they run in an origin of their own, not the server's.
|
|
87
87
|
*/
|
|
88
88
|
fileUrl(path: string, cwd?: string): Promise<string>;
|
|
89
89
|
/** Paths of files whose name matches `query` loosely, best first; ignored files are left out. */
|
package/lib/common/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './package-protocol';
|
|
|
6
6
|
export * from './pi-types';
|
|
7
7
|
export * from './relay-protocol';
|
|
8
8
|
export * from './remote-protocol';
|
|
9
|
+
export * from './room-protocol';
|
|
9
10
|
export * from './settings-protocol';
|
|
10
11
|
export * from './ta-extension-host';
|
|
11
12
|
export * from './ta-protocol';
|
package/lib/common/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./package-protocol"), exports);
|
|
|
22
22
|
__exportStar(require("./pi-types"), exports);
|
|
23
23
|
__exportStar(require("./relay-protocol"), exports);
|
|
24
24
|
__exportStar(require("./remote-protocol"), exports);
|
|
25
|
+
__exportStar(require("./room-protocol"), exports);
|
|
25
26
|
__exportStar(require("./settings-protocol"), exports);
|
|
26
27
|
__exportStar(require("./ta-extension-host"), exports);
|
|
27
28
|
__exportStar(require("./ta-protocol"), exports);
|
|
@@ -38,6 +38,16 @@ export interface TaWebExtensionInfo {
|
|
|
38
38
|
* opens, `pi.webActivation` of its package.json. A temporary one always on `open`.
|
|
39
39
|
*/
|
|
40
40
|
activation: 'startup' | 'open';
|
|
41
|
+
/**
|
|
42
|
+
* What kind of thing it is, `pi.category` of its package.json, for a page that lists those of a kind:
|
|
43
|
+
* `game` for games and what plays like one (the Games page of @celljs/ta-games lists them).
|
|
44
|
+
*/
|
|
45
|
+
category?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The kinds that a page of it lists, `pi.lists` of its package.json (`["game"]` for the Games page): the pages
|
|
48
|
+
* of extensions of those kinds are found there and in Quick open, not under Discover or in the navigation.
|
|
49
|
+
*/
|
|
50
|
+
lists?: string[];
|
|
41
51
|
/** For a temporary package. */
|
|
42
52
|
temporary?: TaTemporaryInfo;
|
|
43
53
|
}
|
|
@@ -100,12 +110,10 @@ export interface TaPackageServer {
|
|
|
100
110
|
/** The web extensions of the packages pi loads in `cwd` (default: the server's directory). */
|
|
101
111
|
listWebExtensions(cwd?: string): Promise<TaWebExtensionInfo[]>;
|
|
102
112
|
readWebExtension(id: string, cwd?: string): Promise<TaWebExtensionSource>;
|
|
103
|
-
/** Removes the package of a web extension: as `ta remove` for a package, deletes the directory for a directory. */
|
|
104
|
-
removeWebExtension(id: string, cwd?: string): Promise<void>;
|
|
105
113
|
/**
|
|
106
114
|
* Turns a package on or off, what pi loads of it and its web extension; sessions pick it up on reload.
|
|
107
|
-
* A built-in one by its name; another by its id of listPackages,
|
|
108
|
-
* resources on or off, in the settings of its scope.
|
|
115
|
+
* A built-in one by its name; another by its id (of listPackages, or of one of its web extensions), as
|
|
116
|
+
* `ta config` turns each of its resources on or off, in the settings of its scope.
|
|
109
117
|
*/
|
|
110
118
|
setPackageEnabled(nameOrId: string, enabled: boolean, cwd?: string): Promise<void>;
|
|
111
119
|
/** Every package pi loads in `cwd` (default: the server's directory), with a web extension or without. */
|
|
@@ -116,7 +124,10 @@ export interface TaPackageServer {
|
|
|
116
124
|
* project. Sessions pick it up on reload.
|
|
117
125
|
*/
|
|
118
126
|
installPackage(source: string, scope: TaSettingsScope, cwd?: string): Promise<void>;
|
|
119
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Removes a package by its id of listPackages or of one of its web extensions: as `ta remove` for a package of
|
|
129
|
+
* the setting, deletes the directory for a directory, drops a temporary one. A built-in one is turned off instead.
|
|
130
|
+
*/
|
|
120
131
|
removePackage(id: string, cwd?: string): Promise<void>;
|
|
121
132
|
/**
|
|
122
133
|
* Calls a method of what the module of `pi.host` of a package that comes with Ta returned
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** What a secret is replaced with. */
|
|
2
|
+
export declare const REDACTED = "[redacted]";
|
|
3
|
+
/**
|
|
4
|
+
* What looks like a secret in what is shared (docs/design/ta-link.md 2.8): keys of model services and code hosts,
|
|
5
|
+
* tokens, private keys, passwords in assignments and in URLs. It errs on hiding: a shared conversation is read
|
|
6
|
+
* by others, and what it hides by mistake costs a word.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Redactor {
|
|
9
|
+
/** How many places were hidden. */
|
|
10
|
+
count: number;
|
|
11
|
+
text(text: string): string;
|
|
12
|
+
/** Strings of a value, deep, each cut to `max` characters. */
|
|
13
|
+
value(value: unknown, max: number): unknown;
|
|
14
|
+
static cut(text: string, max: number): string;
|
|
15
|
+
protected hide(): string;
|
|
16
|
+
/** What is plainly not a secret: an environment variable, a placeholder, what was hidden already. */
|
|
17
|
+
protected static placeholder(value: string): boolean;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=redactor.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Redactor = exports.REDACTED = void 0;
|
|
4
|
+
/** What a secret is replaced with. */
|
|
5
|
+
exports.REDACTED = '[redacted]';
|
|
6
|
+
/** Secrets that have a shape of their own: the whole match goes. */
|
|
7
|
+
const WHOLE = [
|
|
8
|
+
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
|
|
9
|
+
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
|
|
10
|
+
/\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
|
|
11
|
+
/\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
|
|
12
|
+
/\bglpat-[A-Za-z0-9_-]{20,}\b/g,
|
|
13
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
14
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
15
|
+
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
16
|
+
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
|
|
17
|
+
];
|
|
18
|
+
/** Secrets named by what is before them: what is before stays. */
|
|
19
|
+
const NAMED = [
|
|
20
|
+
/(\bBearer\s+)[A-Za-z0-9._~+/-]{16,}=*/gi,
|
|
21
|
+
/(\b[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key|private[_-]?key)[A-Za-z0-9_.-]*["']?\s*[:=]\s*["']?)([^\s"'`,;]{6,})/gi,
|
|
22
|
+
/(:\/\/[^\s:/@]+:)([^\s@/]{3,})(@)/g,
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* What looks like a secret in what is shared (docs/design/ta-link.md 2.8): keys of model services and code hosts,
|
|
26
|
+
* tokens, private keys, passwords in assignments and in URLs. It errs on hiding: a shared conversation is read
|
|
27
|
+
* by others, and what it hides by mistake costs a word.
|
|
28
|
+
*/
|
|
29
|
+
class Redactor {
|
|
30
|
+
constructor() {
|
|
31
|
+
/** How many places were hidden. */
|
|
32
|
+
this.count = 0;
|
|
33
|
+
}
|
|
34
|
+
text(text) {
|
|
35
|
+
let out = text;
|
|
36
|
+
for (const pattern of WHOLE) {
|
|
37
|
+
out = out.replace(pattern, () => this.hide());
|
|
38
|
+
}
|
|
39
|
+
out = out.replace(NAMED[0], (_match, before) => before + this.hide());
|
|
40
|
+
out = out.replace(NAMED[1], (match, before, value) => (Redactor.placeholder(value) ? match : before + this.hide()));
|
|
41
|
+
out = out.replace(NAMED[2], (_match, before, _value, after) => before + this.hide() + after);
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Strings of a value, deep, each cut to `max` characters. */
|
|
45
|
+
value(value, max) {
|
|
46
|
+
if (typeof value === 'string') {
|
|
47
|
+
return Redactor.cut(this.text(value), max);
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
return value.map(item => this.value(item, max));
|
|
51
|
+
}
|
|
52
|
+
if (value && typeof value === 'object') {
|
|
53
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, this.value(item, max)]));
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
static cut(text, max) {
|
|
58
|
+
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
59
|
+
}
|
|
60
|
+
hide() {
|
|
61
|
+
this.count++;
|
|
62
|
+
return exports.REDACTED;
|
|
63
|
+
}
|
|
64
|
+
/** What is plainly not a secret: an environment variable, a placeholder, what was hidden already. */
|
|
65
|
+
static placeholder(value) {
|
|
66
|
+
return /^(?:\$|<|\{|\[redacted|process\.env|os\.environ|xxx|\*{3})/i.test(value) || /^(?:true|false|null|undefined|none|string|number)$/i.test(value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Redactor = Redactor;
|
|
70
|
+
//# sourceMappingURL=redactor.js.map
|
|
@@ -43,4 +43,64 @@ export interface TaPackageShare {
|
|
|
43
43
|
/** The largest package that goes, in bytes. */
|
|
44
44
|
maxBytes: number;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Who may open a link of content: anyone with it, anyone with it and its password, the one who shared it, or Ta friends of
|
|
48
|
+
* the one who shared it (`people`, TaRoomServer.listFriends), in their own Ta (docs/design/ta-link.md).
|
|
49
|
+
*/
|
|
50
|
+
export type TaShareAccess = 'link' | 'password' | 'self' | 'people';
|
|
51
|
+
/** What is shared by a link: a conversation (`ta-conversation`, JSON) or a file (`file`, with its media type). */
|
|
52
|
+
export interface TaShareInput {
|
|
53
|
+
kind: string;
|
|
54
|
+
title: string;
|
|
55
|
+
/** The media type of a file. */
|
|
56
|
+
type?: string;
|
|
57
|
+
data: Uint8Array;
|
|
58
|
+
access: TaShareAccess;
|
|
59
|
+
/** For `password`; not kept. */
|
|
60
|
+
password?: string;
|
|
61
|
+
/** For `people`: the ids of the Ta friends (TaFriend.id). */
|
|
62
|
+
people?: string[];
|
|
63
|
+
/** None or 0: until stopped. With `offline`, 30 at most. */
|
|
64
|
+
days?: number;
|
|
65
|
+
/** A copy sealed on the relay, for while this computer is off. */
|
|
66
|
+
offline?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** Content this ta serve shares. */
|
|
69
|
+
export interface TaShareInfo {
|
|
70
|
+
id: string;
|
|
71
|
+
kind: string;
|
|
72
|
+
title: string;
|
|
73
|
+
type?: string;
|
|
74
|
+
access: TaShareAccess;
|
|
75
|
+
size: number;
|
|
76
|
+
createdAt: number;
|
|
77
|
+
expiresAt?: number;
|
|
78
|
+
offline: boolean;
|
|
79
|
+
/** `https://<relay>/s#…`, its key in the fragment. */
|
|
80
|
+
link: string;
|
|
81
|
+
/** For `people`: the names of the Ta friends it is shared with. */
|
|
82
|
+
people?: string[];
|
|
83
|
+
}
|
|
84
|
+
/** What a link shares, opened. */
|
|
85
|
+
export interface TaSharedContent {
|
|
86
|
+
kind: string;
|
|
87
|
+
title: string;
|
|
88
|
+
type?: string;
|
|
89
|
+
createdAt: number;
|
|
90
|
+
data: Uint8Array;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Content shared by links, through the relay (TaExtensionHost.shares): made, listed and stopped here, and opened
|
|
94
|
+
* whoever shared it. `open` rejects with an error whose `reason` says why (RelayContentFailure of @celljs/ta-relay:
|
|
95
|
+
* `password`, `wrong`, `busy`, `gone`, `offline`, `self`, `people`, `invalid`, `timeout`, `large`).
|
|
96
|
+
*/
|
|
97
|
+
export interface TaShares {
|
|
98
|
+
create(input: TaShareInput): Promise<TaShareInfo>;
|
|
99
|
+
/** Those still on, the latest first. */
|
|
100
|
+
list(): Promise<TaShareInfo[]>;
|
|
101
|
+
/** Its link no longer works, at once, and its copy on the relay is deleted. False when there was none. */
|
|
102
|
+
remove(id: string): Promise<boolean>;
|
|
103
|
+
/** What a link shares: one of this ta serve read here (a link for `self` too), another fetched through the relay. */
|
|
104
|
+
open(link: string, password?: string): Promise<TaSharedContent>;
|
|
105
|
+
}
|
|
46
106
|
//# sourceMappingURL=relay-protocol.d.ts.map
|