@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
|
@@ -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
|
|
@@ -67,7 +67,10 @@ export interface TaRemoteServer {
|
|
|
67
67
|
addHost(host: string): Promise<void>;
|
|
68
68
|
/** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
|
|
69
69
|
removeHost(host: string): Promise<void>;
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A location as the user wrote it, whole: `~/src`, `ssh://<host>` (its home), `ssh://<host>/~/src`, or a path
|
|
72
|
+
* relative to the default directory; one already whole as it is. Connects to the host when it needs its home.
|
|
73
|
+
*/
|
|
71
74
|
resolveLocation(location: string): Promise<string>;
|
|
72
75
|
/**
|
|
73
76
|
* A port of the machine of `cwd` on the machine of ta serve, for a page served there: the same port
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export declare const TaRoomServer: unique symbol;
|
|
2
|
+
export declare const TA_ROOM_SERVICE = "TaRoomServer";
|
|
3
|
+
/**
|
|
4
|
+
* Rooms of Ta (docs/design/ta-link.md 3): a place several Ta share, through the relay, end to end: they send each other
|
|
5
|
+
* messages and keep a shared state, which the relay keeps sealed. One makes a room and invites by a link; one with the
|
|
6
|
+
* link asks to join, and is in once the owner said so, in their own Ta.
|
|
7
|
+
*/
|
|
8
|
+
/** `member` in the room; `waiting` for the owner to answer; `refused` by the owner; `gone`: closed, removed, or the invitation no longer works. */
|
|
9
|
+
export type TaRoomStatus = 'member' | 'waiting' | 'refused' | 'gone';
|
|
10
|
+
/** Who a Ta is to others: the id of its keys, and the name it gives. */
|
|
11
|
+
export interface TaIdentity {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TaRoomMember {
|
|
16
|
+
/** Its id in this room alone: what messages say they are `from`, and `to` sends to. */
|
|
17
|
+
member: string;
|
|
18
|
+
/** The identity of its Ta. */
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
owner: boolean;
|
|
22
|
+
online: boolean;
|
|
23
|
+
self: boolean;
|
|
24
|
+
/** In a browser, without Ta (docs/design/ta-link.md 3.8): it only chats, and is no Ta friend. */
|
|
25
|
+
guest?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface TaRoomInfo {
|
|
28
|
+
id: string;
|
|
29
|
+
/** What the extension that made it calls such rooms (`ta-town`): it finds its rooms by it. */
|
|
30
|
+
kind: string;
|
|
31
|
+
title: string;
|
|
32
|
+
/** The view that shows it (`ui.showView`), as the extension that made it said. */
|
|
33
|
+
view?: string;
|
|
34
|
+
/** This Ta made it. */
|
|
35
|
+
owner: boolean;
|
|
36
|
+
ownerName: string;
|
|
37
|
+
status: TaRoomStatus;
|
|
38
|
+
/** Why it is `gone`: `closed` by the owner, `removed` by the owner, the `invite` no longer works. */
|
|
39
|
+
reason?: 'closed' | 'removed' | 'invite';
|
|
40
|
+
/** Connected to the room now. */
|
|
41
|
+
connected: boolean;
|
|
42
|
+
members: TaRoomMember[];
|
|
43
|
+
createdAt: number;
|
|
44
|
+
joinedAt?: number;
|
|
45
|
+
}
|
|
46
|
+
/** One asking to join a room of this Ta: for the user to answer. */
|
|
47
|
+
export interface TaRoomRequest {
|
|
48
|
+
room: string;
|
|
49
|
+
title: string;
|
|
50
|
+
ask: string;
|
|
51
|
+
/** Its identity, and the name it gives. */
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
/** Met before, in another room. */
|
|
55
|
+
friend: boolean;
|
|
56
|
+
/** Asks from a browser, without Ta: admitted, it only chats. */
|
|
57
|
+
guest?: boolean;
|
|
58
|
+
at: number;
|
|
59
|
+
}
|
|
60
|
+
/** One met in a room. */
|
|
61
|
+
export interface TaFriend extends TaIdentity {
|
|
62
|
+
/** Titles of rooms shared, the latest last. */
|
|
63
|
+
rooms: string[];
|
|
64
|
+
metAt: number;
|
|
65
|
+
seenAt: number;
|
|
66
|
+
}
|
|
67
|
+
export interface TaRoomValue {
|
|
68
|
+
value: unknown;
|
|
69
|
+
version: number;
|
|
70
|
+
/** The member who wrote it last. */
|
|
71
|
+
by: string;
|
|
72
|
+
}
|
|
73
|
+
/** What happens in the rooms, to the connections that called TaRoomServer.watch. */
|
|
74
|
+
export type TaRoomEvent =
|
|
75
|
+
/** The list, a room's members, who is online, or a room's status changed: read it again. */
|
|
76
|
+
{
|
|
77
|
+
type: 'rooms';
|
|
78
|
+
} | {
|
|
79
|
+
type: 'request';
|
|
80
|
+
request: TaRoomRequest;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'message';
|
|
83
|
+
room: string;
|
|
84
|
+
from: string;
|
|
85
|
+
name: string;
|
|
86
|
+
data: unknown;
|
|
87
|
+
} | {
|
|
88
|
+
type: 'state';
|
|
89
|
+
room: string;
|
|
90
|
+
key: string;
|
|
91
|
+
value: unknown;
|
|
92
|
+
version: number;
|
|
93
|
+
by: string;
|
|
94
|
+
};
|
|
95
|
+
export interface TaRoomServer {
|
|
96
|
+
/** This Ta as others see it; made the first time. */
|
|
97
|
+
getIdentity(): Promise<TaIdentity>;
|
|
98
|
+
setName(name: string): Promise<TaIdentity>;
|
|
99
|
+
listRooms(): Promise<TaRoomInfo[]>;
|
|
100
|
+
createRoom(input: {
|
|
101
|
+
kind: string;
|
|
102
|
+
title: string;
|
|
103
|
+
view?: string;
|
|
104
|
+
}): Promise<TaRoomInfo>;
|
|
105
|
+
/**
|
|
106
|
+
* The link others ask to join by (the owner only): the one of before while it has a day left; else, or with `renew`,
|
|
107
|
+
* a new one for `days` (7 by default, 30 at most), and the links of before stop working.
|
|
108
|
+
*/
|
|
109
|
+
invite(room: string, options?: {
|
|
110
|
+
days?: number;
|
|
111
|
+
renew?: boolean;
|
|
112
|
+
}): Promise<{
|
|
113
|
+
link: string;
|
|
114
|
+
expiresAt: number;
|
|
115
|
+
}>;
|
|
116
|
+
/** Asks to join the room of a link: `waiting` till its owner answers. Ask the user first. */
|
|
117
|
+
join(link: string): Promise<TaRoomInfo>;
|
|
118
|
+
/** Those asking to join the rooms of this Ta. */
|
|
119
|
+
listRequests(): Promise<TaRoomRequest[]>;
|
|
120
|
+
/** The user's answer to one asking to join. Only ever on the user's word, never on an agent's. */
|
|
121
|
+
answer(room: string, ask: string, accept: boolean): Promise<void>;
|
|
122
|
+
/** The owner takes a member out. */
|
|
123
|
+
removeMember(room: string, member: string): Promise<void>;
|
|
124
|
+
/** Leaves the room; its owner closes it for everyone. A room asked to join, refused or gone is forgotten. */
|
|
125
|
+
leave(room: string): Promise<void>;
|
|
126
|
+
/** To every other member, or to one (`to`, its member id): JSON, 64 KB at most. */
|
|
127
|
+
send(room: string, data: unknown, to?: string): Promise<void>;
|
|
128
|
+
/** The shared state, by its keys; with `prefix`, only the keys that start with it (`chat:`), not all a game keeps. */
|
|
129
|
+
getState(room: string, prefix?: string): Promise<Record<string, TaRoomValue>>;
|
|
130
|
+
/**
|
|
131
|
+
* Sets a key (`null` clears it); with `version`, only if it is still that version (0: not set), else `ok` is false
|
|
132
|
+
* and `version` says what it is: read it again, and set it again. A value is 64 KB at most.
|
|
133
|
+
*/
|
|
134
|
+
setState(room: string, key: string, value: unknown, version?: number): Promise<{
|
|
135
|
+
ok: boolean;
|
|
136
|
+
version: number;
|
|
137
|
+
}>;
|
|
138
|
+
listFriends(): Promise<TaFriend[]>;
|
|
139
|
+
removeFriend(id: string): Promise<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* This connection hears TaRoomEvent (TaClient.onRoomEvent) from now on; again after it connected again. Without
|
|
142
|
+
* `messages`, only `rooms` and `request`: messages and the state come often (a game's), for a page that shows them;
|
|
143
|
+
* with `state`, also the state of the keys that start with one of them (`chat:`), not the messages, for a list
|
|
144
|
+
* that shows what was said last.
|
|
145
|
+
*/
|
|
146
|
+
watch(messages?: boolean, state?: string[]): Promise<void>;
|
|
147
|
+
/** No more: messages of rooms come often (a game's), and need not go to a page that shows none. */
|
|
148
|
+
unwatch(): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
/** What a connection or a listener hears of the rooms (TaRoomServer.watch). */
|
|
151
|
+
export interface TaRoomWatch {
|
|
152
|
+
messages: boolean;
|
|
153
|
+
/** Prefixes of keys whose state it hears without `messages`. */
|
|
154
|
+
state: string[];
|
|
155
|
+
}
|
|
156
|
+
export declare namespace TaRoomWatchUtil {
|
|
157
|
+
function of(messages: boolean | undefined, state: unknown): TaRoomWatch;
|
|
158
|
+
/** All that several want: messages if one does, the prefixes of all. */
|
|
159
|
+
function union(watches: Iterable<TaRoomWatch>): TaRoomWatch;
|
|
160
|
+
function same(a: TaRoomWatch | undefined, b: TaRoomWatch | undefined): boolean;
|
|
161
|
+
function hears(watch: TaRoomWatch, event: TaRoomEvent): boolean;
|
|
162
|
+
}
|
|
163
|
+
/** The rooms for the server side of packages (TaExtensionHost.rooms): TaRoomServer, its events heard directly. */
|
|
164
|
+
export interface TaRooms extends Omit<TaRoomServer, 'watch' | 'unwatch'> {
|
|
165
|
+
onEvent(listener: (event: TaRoomEvent) => void): () => void;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=room-protocol.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaRoomWatchUtil = exports.TA_ROOM_SERVICE = exports.TaRoomServer = void 0;
|
|
4
|
+
exports.TaRoomServer = Symbol('TaRoomServer');
|
|
5
|
+
exports.TA_ROOM_SERVICE = 'TaRoomServer';
|
|
6
|
+
var TaRoomWatchUtil;
|
|
7
|
+
(function (TaRoomWatchUtil) {
|
|
8
|
+
function of(messages, state) {
|
|
9
|
+
const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === 'string' && prefix.length > 0) : [];
|
|
10
|
+
return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
|
|
11
|
+
}
|
|
12
|
+
TaRoomWatchUtil.of = of;
|
|
13
|
+
/** All that several want: messages if one does, the prefixes of all. */
|
|
14
|
+
function union(watches) {
|
|
15
|
+
let messages = false;
|
|
16
|
+
const state = [];
|
|
17
|
+
for (const watch of watches) {
|
|
18
|
+
messages || (messages = watch.messages);
|
|
19
|
+
state.push(...watch.state);
|
|
20
|
+
}
|
|
21
|
+
return of(messages, messages ? [] : state);
|
|
22
|
+
}
|
|
23
|
+
TaRoomWatchUtil.union = union;
|
|
24
|
+
function same(a, b) {
|
|
25
|
+
return a === b || (!!a && !!b && a.messages === b.messages && a.state.join('\n') === b.state.join('\n'));
|
|
26
|
+
}
|
|
27
|
+
TaRoomWatchUtil.same = same;
|
|
28
|
+
function hears(watch, event) {
|
|
29
|
+
if (event.type === 'message') {
|
|
30
|
+
return watch.messages;
|
|
31
|
+
}
|
|
32
|
+
if (event.type === 'state') {
|
|
33
|
+
return watch.messages || watch.state.some(prefix => event.key.startsWith(prefix));
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
TaRoomWatchUtil.hears = hears;
|
|
38
|
+
})(TaRoomWatchUtil || (exports.TaRoomWatchUtil = TaRoomWatchUtil = {}));
|
|
39
|
+
//# sourceMappingURL=room-protocol.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { TaPackageServer } from './package-protocol';
|
|
2
|
+
import type { TaShares } from './relay-protocol';
|
|
3
|
+
import type { TaRooms } from './room-protocol';
|
|
2
4
|
import type { TaServer } from './ta-protocol';
|
|
3
5
|
/**
|
|
4
6
|
* What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
|
|
@@ -10,6 +12,17 @@ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listS
|
|
|
10
12
|
readonly agentDir: string;
|
|
11
13
|
/** Where the conversation of a session file works, as clients name it (a path or an `ssh://` location), without opening it; undefined when it cannot be read. */
|
|
12
14
|
sessionCwd(sessionFile: string): Promise<string | undefined>;
|
|
15
|
+
/** Content shared by links, through the relay (docs/design/ta-link.md). */
|
|
16
|
+
readonly shares: TaShares;
|
|
17
|
+
/** Rooms shared with other Ta, through the relay (docs/design/ta-link.md 3). */
|
|
18
|
+
readonly rooms: TaRooms;
|
|
19
|
+
/** pi's messages of a session file, of the branch it is on (its first message first), without opening it. */
|
|
20
|
+
sessionMessages(sessionFile: string): Promise<unknown[]>;
|
|
21
|
+
/**
|
|
22
|
+
* A new conversation of `cwd` holding these messages of pi (an assistant's among them), named `name`: its session
|
|
23
|
+
* file, to open with `openSession`. As a conversation brought from elsewhere (a link of another Ta).
|
|
24
|
+
*/
|
|
25
|
+
createSession(cwd: string, messages: readonly unknown[], name?: string): Promise<string>;
|
|
13
26
|
/** Keys of the data of a package that changed, by a page or by the server, as they change; `cwd` for a key of a directory. */
|
|
14
27
|
onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
|
|
15
28
|
}
|
|
@@ -34,6 +47,21 @@ export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService |
|
|
|
34
47
|
* and the extension should say its tools need `ta serve`.
|
|
35
48
|
*/
|
|
36
49
|
export declare const TA_HOST_EVENT = "ta:host";
|
|
50
|
+
/**
|
|
51
|
+
* How a pi extension reaches the host of its package. Import it from `@celljs/ta-protocol/lib/common/ta-extension-host`
|
|
52
|
+
* in a bundle: this file has nothing else to run, where the whole protocol would come along with its index.
|
|
53
|
+
*/
|
|
54
|
+
export declare namespace TaHostUtil {
|
|
55
|
+
/**
|
|
56
|
+
* Under `ta serve` the host answers at once; under `ta` alone nobody answers. The timer also keeps the process
|
|
57
|
+
* alive meanwhile: a tool waiting for the host in `ta -p` would otherwise end it.
|
|
58
|
+
*/
|
|
59
|
+
const WAIT_MS = 1000;
|
|
60
|
+
/** Asks for the host of the package `name` (TA_HOST_EVENT); undefined when nobody answers: not under `ta serve`. */
|
|
61
|
+
function reach(events: {
|
|
62
|
+
emit(event: string, data: unknown): void;
|
|
63
|
+
}, name: string, waitMs?: number): Promise<TaHostAnswer | undefined>;
|
|
64
|
+
}
|
|
37
65
|
/**
|
|
38
66
|
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
39
67
|
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TA_DOUBLE_FILE = exports.TA_FILE_WRITE_EVENT = exports.TA_HOST_EVENT = void 0;
|
|
3
|
+
exports.TA_DOUBLE_FILE = exports.TA_FILE_WRITE_EVENT = exports.TaHostUtil = exports.TA_HOST_EVENT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The event of pi's `pi.events` by which a pi extension asks for the host of its package:
|
|
6
6
|
* `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
|
|
@@ -8,6 +8,33 @@ exports.TA_DOUBLE_FILE = exports.TA_FILE_WRITE_EVENT = exports.TA_HOST_EVENT = v
|
|
|
8
8
|
* and the extension should say its tools need `ta serve`.
|
|
9
9
|
*/
|
|
10
10
|
exports.TA_HOST_EVENT = 'ta:host';
|
|
11
|
+
/**
|
|
12
|
+
* How a pi extension reaches the host of its package. Import it from `@celljs/ta-protocol/lib/common/ta-extension-host`
|
|
13
|
+
* in a bundle: this file has nothing else to run, where the whole protocol would come along with its index.
|
|
14
|
+
*/
|
|
15
|
+
var TaHostUtil;
|
|
16
|
+
(function (TaHostUtil) {
|
|
17
|
+
/**
|
|
18
|
+
* Under `ta serve` the host answers at once; under `ta` alone nobody answers. The timer also keeps the process
|
|
19
|
+
* alive meanwhile: a tool waiting for the host in `ta -p` would otherwise end it.
|
|
20
|
+
*/
|
|
21
|
+
TaHostUtil.WAIT_MS = 1000;
|
|
22
|
+
/** Asks for the host of the package `name` (TA_HOST_EVENT); undefined when nobody answers: not under `ta serve`. */
|
|
23
|
+
function reach(events, name, waitMs = TaHostUtil.WAIT_MS) {
|
|
24
|
+
return new Promise(resolve => {
|
|
25
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
26
|
+
const request = {
|
|
27
|
+
name,
|
|
28
|
+
resolve: answer => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
resolve(answer);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
events.emit(exports.TA_HOST_EVENT, request);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
TaHostUtil.reach = reach;
|
|
37
|
+
})(TaHostUtil || (exports.TaHostUtil = TaHostUtil = {}));
|
|
11
38
|
/**
|
|
12
39
|
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
13
40
|
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TaAuthEvent } from './auth-protocol';
|
|
2
2
|
import type { ImageContent, JsonAgentSessionEvent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types';
|
|
3
3
|
import type { TaRemoteEvent } from './remote-protocol';
|
|
4
|
+
import type { TaRoomEvent } from './room-protocol';
|
|
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,6 +539,8 @@ 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 {};
|
|
419
546
|
//# sourceMappingURL=ta-protocol.d.ts.map
|