@celljs/ta-protocol 4.10.0 → 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/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 +28 -0
- package/esm/common/ta-extension-host.js +27 -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 +28 -0
- package/lib/common/ta-extension-host.js +28 -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
|
@@ -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: {
|
|
@@ -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,6 +539,8 @@ 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 {};
|
|
460
546
|
//# sourceMappingURL=ta-protocol.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageNote = exports.TaMessageContext = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
|
|
3
|
+
exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
|
|
4
4
|
exports.TaServer = Symbol('TaServer');
|
|
5
5
|
exports.TaClient = Symbol('TaClient');
|
|
6
6
|
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
@@ -47,6 +47,16 @@ var TaErrorUtil;
|
|
|
47
47
|
})(TaErrorUtil || (exports.TaErrorUtil = TaErrorUtil = {}));
|
|
48
48
|
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
49
49
|
exports.TA_RPC_ERROR_CODE = -32050;
|
|
50
|
+
var TaSlashCommandUtil;
|
|
51
|
+
(function (TaSlashCommandUtil) {
|
|
52
|
+
/** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
|
|
53
|
+
function description(command, language) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const { descriptions } = command;
|
|
56
|
+
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;
|
|
57
|
+
}
|
|
58
|
+
TaSlashCommandUtil.description = description;
|
|
59
|
+
})(TaSlashCommandUtil || (exports.TaSlashCommandUtil = TaSlashCommandUtil = {}));
|
|
50
60
|
/**
|
|
51
61
|
* A message of the user may start with a `<context>` block: what the model reads besides the message
|
|
52
62
|
* (where it is said, who is there, what was said before), which a client leaves out when it shows it.
|
|
@@ -82,6 +92,83 @@ var TaImageNote;
|
|
|
82
92
|
}
|
|
83
93
|
TaImageNote.strip = strip;
|
|
84
94
|
})(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
|
|
95
|
+
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
96
|
+
var TaImageSize;
|
|
97
|
+
(function (TaImageSize) {
|
|
98
|
+
/** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
|
|
99
|
+
const JPEG_BYTES = 256 * 1024;
|
|
100
|
+
function of(base64) {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
let bytes;
|
|
103
|
+
try {
|
|
104
|
+
// Whole groups of four characters only.
|
|
105
|
+
const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
|
|
106
|
+
bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
|
|
107
|
+
}
|
|
108
|
+
catch (_d) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
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);
|
|
112
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
113
|
+
}
|
|
114
|
+
TaImageSize.of = of;
|
|
115
|
+
function u16be(bytes, at) {
|
|
116
|
+
return (bytes[at] << 8) | bytes[at + 1];
|
|
117
|
+
}
|
|
118
|
+
function u16le(bytes, at) {
|
|
119
|
+
return bytes[at] | (bytes[at + 1] << 8);
|
|
120
|
+
}
|
|
121
|
+
function u24le(bytes, at) {
|
|
122
|
+
return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
|
|
123
|
+
}
|
|
124
|
+
function u32be(bytes, at) {
|
|
125
|
+
return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
126
|
+
}
|
|
127
|
+
function text(bytes, at, length) {
|
|
128
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
129
|
+
}
|
|
130
|
+
function png(bytes) {
|
|
131
|
+
return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
132
|
+
}
|
|
133
|
+
function gif(bytes) {
|
|
134
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
135
|
+
}
|
|
136
|
+
function webp(bytes) {
|
|
137
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
switch (text(bytes, 12, 4)) {
|
|
141
|
+
case 'VP8 ':
|
|
142
|
+
return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
|
|
143
|
+
case 'VP8L': {
|
|
144
|
+
const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
|
|
145
|
+
return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
|
|
146
|
+
}
|
|
147
|
+
case 'VP8X':
|
|
148
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
149
|
+
default:
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function jpeg(bytes) {
|
|
154
|
+
if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
let at = 2;
|
|
158
|
+
while (at + 9 < bytes.length) {
|
|
159
|
+
if (bytes[at] !== 0xff) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const marker = bytes[at + 1];
|
|
163
|
+
// A start of frame (not DHT, JPG or DAC, which share the range) says the size.
|
|
164
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
165
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
166
|
+
}
|
|
167
|
+
at += 2 + u16be(bytes, at + 2);
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
})(TaImageSize || (exports.TaImageSize = TaImageSize = {}));
|
|
85
172
|
/**
|
|
86
173
|
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
87
174
|
* (`<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. */
|