@celljs/ta-protocol 4.9.1 → 4.11.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/README.en.md +2 -2
- package/README.md +3 -3
- package/esm/common/index.d.ts +1 -0
- package/esm/common/index.js +1 -0
- package/esm/common/location.d.ts +7 -0
- package/esm/common/location.js +20 -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/remote-protocol.d.ts +4 -1
- 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 +28 -0
- package/esm/common/ta-extension-host.js +27 -0
- package/esm/common/ta-protocol.d.ts +135 -8
- package/esm/common/ta-protocol.js +138 -0
- package/esm/common/workspace-protocol.d.ts +2 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/location.d.ts +7 -0
- package/lib/common/location.js +20 -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/remote-protocol.d.ts +4 -1
- 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 +28 -0
- package/lib/common/ta-extension-host.js +28 -1
- package/lib/common/ta-protocol.d.ts +135 -8
- package/lib/common/ta-protocol.js +139 -1
- package/lib/common/workspace-protocol.d.ts +2 -1
- package/package.json +5 -5
|
@@ -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: {
|
|
@@ -38,6 +41,14 @@ export declare const TaErrorCode: {
|
|
|
38
41
|
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
39
42
|
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
40
43
|
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
44
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
45
|
+
readonly NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT';
|
|
46
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
47
|
+
readonly ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED';
|
|
48
|
+
/** The session is answering or compacting, which has to end first. */
|
|
49
|
+
readonly SESSION_BUSY: 'CELL_TA_SESSION_BUSY';
|
|
50
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
51
|
+
readonly CANCELLED: 'CELL_TA_CANCELLED';
|
|
41
52
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
42
53
|
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
43
54
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -84,6 +95,18 @@ export type TaCommandResult<C extends TaCommand> = Extract<RpcResponse, {
|
|
|
84
95
|
}> extends {
|
|
85
96
|
data: infer D;
|
|
86
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
|
+
}
|
|
87
110
|
/** A tool the client runs: the model calls it like any other tool, the server asks the client for the result. */
|
|
88
111
|
export interface TaClientToolDefinition {
|
|
89
112
|
/** Letters, digits, `_` and `-`, starting with a letter; best not the name of another tool of the session. */
|
|
@@ -106,6 +129,15 @@ export interface TaOpenSessionOptions {
|
|
|
106
129
|
appendSystemPrompt?: string;
|
|
107
130
|
/** Sessions a package opens for its own work (the name of the package): clients list them apart, folded. */
|
|
108
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;
|
|
109
141
|
}
|
|
110
142
|
export interface TaSessionInfo {
|
|
111
143
|
/** The id of this open session; stays the same through `newSession`, `switchSession` and `fork`. */
|
|
@@ -117,9 +149,16 @@ export interface TaSessionInfo {
|
|
|
117
149
|
sessionName?: string;
|
|
118
150
|
/** The first line of the first message of the user, which a list shows when the session has no name. */
|
|
119
151
|
firstMessage?: string;
|
|
152
|
+
/** The last thing said in it, by the user or the agent, on one line: what a list shows under its title. */
|
|
153
|
+
lastMessage?: string;
|
|
120
154
|
/** `<provider>/<model id>`. */
|
|
121
155
|
model?: string;
|
|
122
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;
|
|
123
162
|
messageCount: number;
|
|
124
163
|
/** Number of clients attached. */
|
|
125
164
|
attached: number;
|
|
@@ -140,6 +179,8 @@ export interface TaSavedSessionInfo {
|
|
|
140
179
|
sessionName?: string;
|
|
141
180
|
/** The first line of the first message of the user. */
|
|
142
181
|
firstMessage?: string;
|
|
182
|
+
/** TaSessionInfo.lastMessage. */
|
|
183
|
+
lastMessage?: string;
|
|
143
184
|
messageCount: number;
|
|
144
185
|
createdAt: number;
|
|
145
186
|
/** When the last message came; `createdAt` before the first. */
|
|
@@ -147,6 +188,16 @@ export interface TaSavedSessionInfo {
|
|
|
147
188
|
/** The group it was opened for (TaOpenSessionOptions.group): its package opens it again, with its role. */
|
|
148
189
|
group?: string;
|
|
149
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
|
+
}
|
|
150
201
|
export interface TaPromptInput {
|
|
151
202
|
/** May start with a block of context for the model, which clients do not show: see {@link TaMessageContext}. */
|
|
152
203
|
message: string;
|
|
@@ -165,6 +216,31 @@ export declare namespace TaMessageContext {
|
|
|
165
216
|
/** The message without its context: what the user sees of it. */
|
|
166
217
|
function strip(message: string): string;
|
|
167
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* 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
|
|
221
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
222
|
+
*/
|
|
223
|
+
export declare namespace TaImageNote {
|
|
224
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
225
|
+
function strip(text: string): string;
|
|
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
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
236
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
237
|
+
*/
|
|
238
|
+
export declare namespace TaAgentSummary {
|
|
239
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
240
|
+
function read(text: string): string | undefined;
|
|
241
|
+
/** The text without the summary it starts with. */
|
|
242
|
+
function strip(text: string): string;
|
|
243
|
+
}
|
|
168
244
|
/** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
|
|
169
245
|
export interface TaSkillUse {
|
|
170
246
|
name: string;
|
|
@@ -187,8 +263,11 @@ export declare namespace TaSkillUse {
|
|
|
187
263
|
*/
|
|
188
264
|
export interface TaPromptReceipt {
|
|
189
265
|
clientMessageId: string;
|
|
190
|
-
/**
|
|
191
|
-
|
|
266
|
+
/**
|
|
267
|
+
* `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before;
|
|
268
|
+
* `handled`: a command or an extension took it, and no message of the user comes of it.
|
|
269
|
+
*/
|
|
270
|
+
status: 'accepted' | 'queued' | 'duplicate' | 'handled';
|
|
192
271
|
}
|
|
193
272
|
/** An extension's dialog was answered by another client, or expired. */
|
|
194
273
|
export interface TaUiRequestResolved {
|
|
@@ -218,6 +297,14 @@ export interface TaSessionReloaded {
|
|
|
218
297
|
export interface TaSessionClosed {
|
|
219
298
|
type: 'session_closed';
|
|
220
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* What the agent is doing while it works, from an extension (pi's `setWorkingMessage`), as starting the
|
|
302
|
+
* program of an external agent; none: the client's own words again.
|
|
303
|
+
*/
|
|
304
|
+
export interface TaWorkingMessage {
|
|
305
|
+
type: 'working_message';
|
|
306
|
+
message?: string;
|
|
307
|
+
}
|
|
221
308
|
/**
|
|
222
309
|
* The model called a tool of `clientTools`: a client that runs it takes it with `claimClientTool`, so
|
|
223
310
|
* that one client runs it, however many are attached, and answers with `respondClientTool`. When that
|
|
@@ -236,7 +323,7 @@ export interface TaClientToolResolved {
|
|
|
236
323
|
type: 'client_tool_resolved';
|
|
237
324
|
id: string;
|
|
238
325
|
}
|
|
239
|
-
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed;
|
|
326
|
+
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed | TaWorkingMessage;
|
|
240
327
|
export interface TaEventEnvelope {
|
|
241
328
|
sessionId: string;
|
|
242
329
|
/** Increases by one per event of the session. */
|
|
@@ -275,6 +362,17 @@ export interface TaAttachOptions {
|
|
|
275
362
|
*/
|
|
276
363
|
recentBytes?: number;
|
|
277
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
|
+
}
|
|
278
376
|
/** The messages of a conversation before those a client has (`getEarlierMessages`). */
|
|
279
377
|
export interface TaMessagePage {
|
|
280
378
|
messages: TaMessage[];
|
|
@@ -324,11 +422,21 @@ export interface TaServer {
|
|
|
324
422
|
* restarts: where conversations open when the user names no directory. Sessions already open stay where they are.
|
|
325
423
|
*/
|
|
326
424
|
setWorkingDirectory(cwd: string): Promise<TaServerInfo>;
|
|
327
|
-
openSession(options: TaOpenSessionOptions): Promise<
|
|
425
|
+
openSession(options: TaOpenSessionOptions): Promise<TaOpenedSession>;
|
|
328
426
|
closeSession(sessionId: string): Promise<void>;
|
|
329
427
|
listSessions(): Promise<TaSessionInfo[]>;
|
|
330
|
-
/**
|
|
331
|
-
|
|
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[]>;
|
|
332
440
|
/** Starts sending the events of the session to this connection. */
|
|
333
441
|
attach(sessionId: string, afterSeq?: number, options?: TaAttachOptions): Promise<TaAttachResult>;
|
|
334
442
|
/**
|
|
@@ -336,6 +444,12 @@ export interface TaServer {
|
|
|
336
444
|
* `timestamp` that of the message there, to know it is still the same; without `before`, the latest.
|
|
337
445
|
*/
|
|
338
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>;
|
|
339
453
|
detach(sessionId: string): Promise<void>;
|
|
340
454
|
/** Answers a dialog; false when it was answered before or expired. */
|
|
341
455
|
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
@@ -345,7 +459,7 @@ export interface TaServer {
|
|
|
345
459
|
* that does something (opens a session) must not run in every page.
|
|
346
460
|
*/
|
|
347
461
|
claimClientTool(sessionId: string, id: string): Promise<boolean>;
|
|
348
|
-
/** 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. */
|
|
349
463
|
respondClientTool(sessionId: string, result: TaClientToolResult): Promise<boolean>;
|
|
350
464
|
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
351
465
|
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
@@ -395,13 +509,24 @@ export interface TaServer {
|
|
|
395
509
|
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
396
510
|
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
397
511
|
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
398
|
-
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
|
+
}>;
|
|
399
522
|
/** Loads extensions, skills, prompts and themes again, as pi's `/reload` does. */
|
|
400
523
|
reload(sessionId: string): Promise<void>;
|
|
401
524
|
}
|
|
402
525
|
/** What a client implements. Events come in batches: one message per frame, however fast the model streams. */
|
|
403
526
|
export interface TaClient {
|
|
404
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>;
|
|
405
530
|
/** Output of a terminal of this connection; with `exitCode`, the terminal has ended. */
|
|
406
531
|
onTerminalData(terminalId: string, data: string, exitCode?: number): Promise<void>;
|
|
407
532
|
/**
|
|
@@ -414,5 +539,7 @@ export interface TaClient {
|
|
|
414
539
|
onAuthEvent(loginId: string, event: TaAuthEvent): Promise<void>;
|
|
415
540
|
/** What happens with the remote machines, once this connection called TaRemoteServer.watch. */
|
|
416
541
|
onRemoteEvent(event: TaRemoteEvent): Promise<void>;
|
|
542
|
+
/** What happens in the rooms, once this connection called TaRoomServer.watch. */
|
|
543
|
+
onRoomEvent(event: TaRoomEvent): Promise<void>;
|
|
417
544
|
}
|
|
418
545
|
export {};
|
|
@@ -15,6 +15,14 @@ export const TaErrorCode = {
|
|
|
15
15
|
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
16
16
|
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
17
17
|
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
18
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
19
|
+
NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
|
|
20
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
21
|
+
ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
|
|
22
|
+
/** The session is answering or compacting, which has to end first. */
|
|
23
|
+
SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
|
|
24
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
25
|
+
CANCELLED: 'CELL_TA_CANCELLED',
|
|
18
26
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
19
27
|
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
20
28
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -36,6 +44,16 @@ export var TaErrorUtil;
|
|
|
36
44
|
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
37
45
|
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
38
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 = {}));
|
|
39
57
|
/**
|
|
40
58
|
* A message of the user may start with a `<context>` block: what the model reads besides the message
|
|
41
59
|
* (where it is said, who is there, what was said before), which a client leaves out when it shows it.
|
|
@@ -53,6 +71,126 @@ export var TaMessageContext;
|
|
|
53
71
|
}
|
|
54
72
|
TaMessageContext.strip = strip;
|
|
55
73
|
})(TaMessageContext || (TaMessageContext = {}));
|
|
74
|
+
/**
|
|
75
|
+
* 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
|
|
76
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
77
|
+
*/
|
|
78
|
+
export var TaImageNote;
|
|
79
|
+
(function (TaImageNote) {
|
|
80
|
+
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 [^\]]+\.\]$/;
|
|
81
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
82
|
+
function strip(text) {
|
|
83
|
+
const lines = text.split('\n');
|
|
84
|
+
const kept = lines.filter(line => !NOTE.test(line.trim()));
|
|
85
|
+
if (kept.length === lines.length) {
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
|
|
89
|
+
}
|
|
90
|
+
TaImageNote.strip = strip;
|
|
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 = {}));
|
|
169
|
+
/**
|
|
170
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
171
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
172
|
+
*/
|
|
173
|
+
export var TaAgentSummary;
|
|
174
|
+
(function (TaAgentSummary) {
|
|
175
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
176
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
177
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
178
|
+
function read(text) {
|
|
179
|
+
if (!START.test(text)) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
return text
|
|
183
|
+
.replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
|
|
184
|
+
.replace(/<\/?\w*$/, '')
|
|
185
|
+
.trim();
|
|
186
|
+
}
|
|
187
|
+
TaAgentSummary.read = read;
|
|
188
|
+
/** The text without the summary it starts with. */
|
|
189
|
+
function strip(text) {
|
|
190
|
+
return text.replace(BLOCK, '');
|
|
191
|
+
}
|
|
192
|
+
TaAgentSummary.strip = strip;
|
|
193
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
56
194
|
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
57
195
|
export var TaSkillUse;
|
|
58
196
|
(function (TaSkillUse) {
|
|
@@ -82,7 +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.
|
|
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.
|
|
86
87
|
*/
|
|
87
88
|
fileUrl(path: string, cwd?: string): Promise<string>;
|
|
88
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);
|
package/lib/common/location.d.ts
CHANGED
|
@@ -47,5 +47,12 @@ export declare namespace TaLocation {
|
|
|
47
47
|
function child(location: string, name: string): string;
|
|
48
48
|
/** The last name of the path; the host for its home directory. */
|
|
49
49
|
function basename(location: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
52
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
53
|
+
*/
|
|
54
|
+
function homeRelative(location: string): string | undefined;
|
|
55
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
56
|
+
function isAbsolute(location: string): boolean;
|
|
50
57
|
}
|
|
51
58
|
//# sourceMappingURL=location.d.ts.map
|
package/lib/common/location.js
CHANGED
|
@@ -168,6 +168,26 @@ var TaLocation;
|
|
|
168
168
|
return name || (remote === null || remote === void 0 ? void 0 : remote.host) || location;
|
|
169
169
|
}
|
|
170
170
|
TaLocation.basename = basename;
|
|
171
|
+
/**
|
|
172
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
173
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
174
|
+
*/
|
|
175
|
+
function homeRelative(location) {
|
|
176
|
+
var _a;
|
|
177
|
+
const remote = parse(location);
|
|
178
|
+
const path = remote ? (remote.path ? remote.path.slice(1) : '~') : location;
|
|
179
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path);
|
|
180
|
+
return match ? ((_a = match[1]) !== null && _a !== void 0 ? _a : '').replace(/[\\/]+$/, '') : undefined;
|
|
181
|
+
}
|
|
182
|
+
TaLocation.homeRelative = homeRelative;
|
|
183
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
184
|
+
function isAbsolute(location) {
|
|
185
|
+
if (homeRelative(location) !== undefined) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
189
|
+
}
|
|
190
|
+
TaLocation.isAbsolute = isAbsolute;
|
|
171
191
|
function parentPath(path) {
|
|
172
192
|
const trimmed = path.replace(/[\\/]+$/, '');
|
|
173
193
|
const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
@@ -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
|