@celljs/ta-protocol 4.15.2 → 4.17.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/app-protocol.d.ts +115 -0
- package/esm/common/app-protocol.js +199 -0
- package/esm/common/delegate-protocol.d.ts +30 -0
- package/esm/common/delegate-protocol.js +52 -0
- package/esm/common/deployment-protocol.d.ts +59 -0
- package/esm/common/deployment-protocol.js +135 -0
- package/esm/common/error-protocol.d.ts +42 -0
- package/esm/common/error-protocol.js +45 -0
- package/esm/common/event-protocol.d.ts +63 -0
- package/esm/common/event-protocol.js +2 -0
- package/esm/common/gateway-protocol.d.ts +54 -2
- package/esm/common/index.d.ts +9 -0
- package/esm/common/index.js +9 -0
- package/esm/common/location.d.ts +18 -1
- package/esm/common/location.js +51 -4
- package/esm/common/message-protocol.d.ts +95 -0
- package/esm/common/message-protocol.js +237 -0
- package/esm/common/page-protocol.d.ts +56 -0
- package/esm/common/page-protocol.js +12 -0
- package/esm/common/path-map.d.ts +24 -0
- package/esm/common/path-map.js +127 -0
- package/esm/common/presence-protocol.js +1 -1
- package/esm/common/redactor.d.ts +12 -0
- package/esm/common/redactor.js +49 -11
- package/esm/common/relay-protocol.d.ts +20 -0
- package/esm/common/remote-protocol.d.ts +12 -4
- package/esm/common/room-protocol.d.ts +7 -1
- package/esm/common/ta-extension-host.d.ts +31 -1
- package/esm/common/ta-extension-host.js +2 -0
- package/esm/common/ta-protocol.d.ts +50 -175
- package/esm/common/ta-protocol.js +0 -234
- package/esm/common/voice-protocol.d.ts +139 -0
- package/esm/common/voice-protocol.js +3 -0
- package/lib/common/app-protocol.d.ts +116 -0
- package/lib/common/app-protocol.js +202 -0
- package/lib/common/delegate-protocol.d.ts +31 -0
- package/lib/common/delegate-protocol.js +55 -0
- package/lib/common/deployment-protocol.d.ts +60 -0
- package/lib/common/deployment-protocol.js +139 -0
- package/lib/common/error-protocol.d.ts +43 -0
- package/lib/common/error-protocol.js +48 -0
- package/lib/common/event-protocol.d.ts +64 -0
- package/lib/common/event-protocol.js +3 -0
- package/lib/common/gateway-protocol.d.ts +54 -2
- package/lib/common/index.d.ts +9 -0
- package/lib/common/index.js +9 -0
- package/lib/common/location.d.ts +18 -1
- package/lib/common/location.js +51 -4
- package/lib/common/message-protocol.d.ts +96 -0
- package/lib/common/message-protocol.js +240 -0
- package/lib/common/page-protocol.d.ts +57 -0
- package/lib/common/page-protocol.js +15 -0
- package/lib/common/path-map.d.ts +25 -0
- package/lib/common/path-map.js +130 -0
- package/lib/common/presence-protocol.js +7 -7
- package/lib/common/redactor.d.ts +12 -0
- package/lib/common/redactor.js +49 -11
- package/lib/common/relay-protocol.d.ts +20 -0
- package/lib/common/remote-protocol.d.ts +12 -4
- package/lib/common/room-protocol.d.ts +7 -1
- package/lib/common/ta-extension-host.d.ts +31 -1
- package/lib/common/ta-extension-host.js +3 -1
- package/lib/common/ta-protocol.d.ts +50 -175
- package/lib/common/ta-protocol.js +1 -235
- package/lib/common/voice-protocol.d.ts +140 -0
- package/lib/common/voice-protocol.js +6 -0
- package/package.json +1 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { TaSignInProvider } from './access-protocol.js';
|
|
2
|
+
import type { TaHostCommands } from './app-protocol.js';
|
|
2
3
|
import type { TaPackageServer } from './package-protocol.js';
|
|
4
|
+
import type { TaHostPages } from './page-protocol.js';
|
|
3
5
|
import type { TaPresencePerson } from './presence-protocol.js';
|
|
4
6
|
import type { TaRelayFeature, TaRelayService, TaRelayStore, TaRelayType, TaShares } from './relay-protocol.js';
|
|
5
7
|
import type { TaRooms } from './room-protocol.js';
|
|
6
8
|
import type { TaServer } from './ta-protocol.js';
|
|
7
9
|
import type { TaAuthorizer, TaMemberInfo, TaResource, TaSharedData, TaSharedRef } from './team-protocol.js';
|
|
10
|
+
import type { TaExtensionVoices } from './voice-protocol.js';
|
|
8
11
|
/**
|
|
9
12
|
* What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
|
|
10
13
|
* process, without a token. A subset of TaServer and TaPackageServer: it can open, drive, stop and close
|
|
11
14
|
* sessions (best those it opened: closing one takes it from every client), not remove anything.
|
|
12
15
|
*/
|
|
13
|
-
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages' | 'callPackageHost' | 'installPackage' | 'removePackage'> {
|
|
16
|
+
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText' | 'relocateDirectory'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages' | 'callPackageHost' | 'installPackage' | 'removePackage'> {
|
|
14
17
|
/** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
|
|
15
18
|
readonly agentDir: string;
|
|
16
19
|
/** 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. */
|
|
@@ -21,8 +24,12 @@ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listS
|
|
|
21
24
|
readonly rooms: TaRooms;
|
|
22
25
|
/** The services of relays.json, as the user chose them for each feature (docs/design/ta-relays.md). */
|
|
23
26
|
readonly relays: TaExtensionRelays;
|
|
27
|
+
/** The voice services of calls, as packages add types of them (docs/design/ta-voice.md). */
|
|
28
|
+
readonly voices: TaExtensionVoices;
|
|
24
29
|
/** pi's messages of a session file, of the branch it is on (its first message first), without opening it. */
|
|
25
30
|
sessionMessages(sessionFile: string): Promise<unknown[]>;
|
|
31
|
+
/** The role a session file was opened with last (TaOpenSessionOptions.appendSystemPrompt), without opening it; undefined without one. */
|
|
32
|
+
sessionRole(sessionFile: string): Promise<string | undefined>;
|
|
26
33
|
/**
|
|
27
34
|
* A new conversation of `cwd` holding these messages of pi (an assistant's among them), named `name`: its session
|
|
28
35
|
* file, to open with `openSession`. As a conversation brought from elsewhere (a link of another Ta).
|
|
@@ -39,6 +46,13 @@ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listS
|
|
|
39
46
|
presence(): TaPresence;
|
|
40
47
|
/** The people let into this Ta besides its user, and what they may do (docs/design/ta-team.md). */
|
|
41
48
|
readonly team: TaHostTeam;
|
|
49
|
+
/**
|
|
50
|
+
* The catalog of what can be done to Ta without its pages (docs/design/ta-app-use.md 2): an action a package
|
|
51
|
+
* registers goes when the package stops.
|
|
52
|
+
*/
|
|
53
|
+
readonly commands: TaHostCommands;
|
|
54
|
+
/** The pages of Ta open now, to ask one of them what its web extension answers (docs/design/ta-app-use.md 4.1). */
|
|
55
|
+
readonly pages: TaHostPages;
|
|
42
56
|
/**
|
|
43
57
|
* Rewrites pi's `settings.json` of the user as pi does, under its lock: `update` gets the settings read under the
|
|
44
58
|
* lock and returns them whole; the open sessions read them again. For what changes settings of the user that are no
|
|
@@ -79,7 +93,23 @@ export interface TaExtensionRelays {
|
|
|
79
93
|
export interface TaPackageService {
|
|
80
94
|
/** `ta serve` stops, or the package is turned off. */
|
|
81
95
|
dispose?(): void | Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* A POST to `/api/hooks/<directory name of the package>/<path>` of ta serve, from a script or a service of this
|
|
98
|
+
* machine: reached WITHOUT the token of ta serve, so the package checks a secret of its own in `path` and throws
|
|
99
|
+
* for one it does not know (the caller gets a 404). Its answer is sent back as JSON.
|
|
100
|
+
*/
|
|
101
|
+
webhook?(request: TaWebhookRequest): unknown | Promise<unknown>;
|
|
102
|
+
}
|
|
103
|
+
/** What a webhook of a package was sent (TaPackageService.webhook). */
|
|
104
|
+
export interface TaWebhookRequest {
|
|
105
|
+
/** After the name of the package, without a leading slash, without the query. */
|
|
106
|
+
path: string;
|
|
107
|
+
/** The body, as text, at most TA_WEBHOOK_MAX_BYTES. */
|
|
108
|
+
body: string;
|
|
109
|
+
contentType?: string;
|
|
82
110
|
}
|
|
111
|
+
/** The largest body a webhook takes; a larger one is refused (413). */
|
|
112
|
+
export declare const TA_WEBHOOK_MAX_BYTES: number;
|
|
83
113
|
/**
|
|
84
114
|
* The default export of a module that a package names in `pi.host` of its package.json. `ta serve` runs it
|
|
85
115
|
* once when it starts (or when the package is turned on), for built-in packages; `ta` without `serve`
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** The largest body a webhook takes; a larger one is refused (413). */
|
|
2
|
+
export const TA_WEBHOOK_MAX_BYTES = 256 * 1024;
|
|
1
3
|
/**
|
|
2
4
|
* The event of pi's `pi.events` by which a pi extension asks for the host of its package:
|
|
3
5
|
* `pi.events.emit(TA_HOST_EVENT, { name, resolve, heard })`. Under `ta serve` `heard` is called as the event
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { TaAuthEvent } from './auth-protocol.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TaClientToolRequest, TaEventEnvelope } from './event-protocol.js';
|
|
3
|
+
import type { ImageContent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types.js';
|
|
3
4
|
import type { TaSessionPerson } from './presence-protocol.js';
|
|
4
5
|
import type { TaRemoteEvent } from './remote-protocol.js';
|
|
5
6
|
import type { TaRoomEvent } from './room-protocol.js';
|
|
6
7
|
import type { TaAsking } from './ta-extension-host.js';
|
|
7
8
|
import type { TaMemberInfo } from './team-protocol.js';
|
|
9
|
+
import type { TaVoiceEvent } from './voice-protocol.js';
|
|
8
10
|
export declare const TaServer: unique symbol;
|
|
9
11
|
export declare const TaClient: unique symbol;
|
|
10
12
|
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
@@ -59,52 +61,21 @@ export interface TaServerUpdate {
|
|
|
59
61
|
/** As TaServerInfo.build. */
|
|
60
62
|
build?: string;
|
|
61
63
|
}
|
|
62
|
-
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
63
|
-
export declare const TaErrorCode: {
|
|
64
|
-
readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
|
|
65
|
-
readonly SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED';
|
|
66
|
-
readonly TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS';
|
|
67
|
-
readonly MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT';
|
|
68
|
-
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
69
|
-
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
70
|
-
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
71
|
-
/** Compacting found nothing to compact: the conversation is still short. */
|
|
72
|
-
readonly NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT';
|
|
73
|
-
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
74
|
-
readonly ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED';
|
|
75
|
-
/** The session is answering or compacting, which has to end first. */
|
|
76
|
-
readonly SESSION_BUSY: 'CELL_TA_SESSION_BUSY';
|
|
77
|
-
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
78
|
-
readonly CANCELLED: 'CELL_TA_CANCELLED';
|
|
79
|
-
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
80
|
-
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
81
|
-
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
82
|
-
readonly ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED';
|
|
83
|
-
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
84
|
-
readonly RATE_LIMITED: 'CELL_TA_RATE_LIMITED';
|
|
85
|
-
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
86
|
-
readonly FORBIDDEN: 'CELL_TA_FORBIDDEN';
|
|
87
|
-
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
88
|
-
readonly LIMIT: 'CELL_TA_LIMIT';
|
|
89
|
-
/** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
|
|
90
|
-
readonly CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST';
|
|
91
|
-
};
|
|
92
|
-
export type TaErrorCode = (typeof TaErrorCode)[keyof typeof TaErrorCode];
|
|
93
|
-
export declare namespace TaErrorUtil {
|
|
94
|
-
/** The {@link TaErrorCode} of a failure: `code` of the client's error, `data.code` of the server's own, called in its process. */
|
|
95
|
-
function code(error: unknown): string | undefined;
|
|
96
|
-
}
|
|
97
|
-
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
98
|
-
export declare const TA_RPC_ERROR_CODE = -32050;
|
|
99
|
-
export interface TaErrorData {
|
|
100
|
-
code: TaErrorCode;
|
|
101
|
-
/** One sentence on what to do about it. */
|
|
102
|
-
hint: string;
|
|
103
|
-
}
|
|
104
64
|
/** A command name of pi's RPC mode (`get_state`, `follow_up`, ...). */
|
|
105
65
|
export type TaCommand = Extract<RpcResponse, {
|
|
106
66
|
success: true;
|
|
107
67
|
}>['command'];
|
|
68
|
+
/** The answer to `relocateDirectory`. */
|
|
69
|
+
export interface TaRelocateResult {
|
|
70
|
+
/** Conversations that work in the new directory now. */
|
|
71
|
+
conversations: number;
|
|
72
|
+
/** Conversations left where they were: running a turn now; move them again once they end. */
|
|
73
|
+
busy: number;
|
|
74
|
+
/** Packages whose data named the old directory. */
|
|
75
|
+
data: number;
|
|
76
|
+
/** The session files that moved, by their old paths: a page goes on with the new one. */
|
|
77
|
+
files: Record<string, string>;
|
|
78
|
+
}
|
|
108
79
|
/** The answer to `forkToFile`. */
|
|
109
80
|
export interface TaForkFileResult {
|
|
110
81
|
/** The new conversation; none when nothing comes before the message: then a new conversation starts. */
|
|
@@ -184,6 +155,11 @@ export interface TaSessionInfo {
|
|
|
184
155
|
firstMessage?: string;
|
|
185
156
|
/** The last thing said in it, by the user or the agent, on one line: what a list shows under its title. */
|
|
186
157
|
lastMessage?: string;
|
|
158
|
+
/**
|
|
159
|
+
* The directory it was in, which is no longer there (moved, renamed, deleted): it goes on in `cwd` instead,
|
|
160
|
+
* as pi's Continue; `forkHere` copies it there for good, as its Fork. None from a Ta service of before.
|
|
161
|
+
*/
|
|
162
|
+
movedFrom?: string;
|
|
187
163
|
/** `<provider>/<model id>`. */
|
|
188
164
|
model?: string;
|
|
189
165
|
isStreaming: boolean;
|
|
@@ -252,77 +228,6 @@ export interface TaPromptInput {
|
|
|
252
228
|
/** What to do when the agent is running; only for `prompt`. Default: `followUp`. */
|
|
253
229
|
streamingBehavior?: 'steer' | 'followUp';
|
|
254
230
|
}
|
|
255
|
-
/**
|
|
256
|
-
* A message of the user may start with a `<context>` block: what the model reads besides the message
|
|
257
|
-
* (where it is said, who is there, what was said before), which a client leaves out when it shows it.
|
|
258
|
-
*/
|
|
259
|
-
export declare namespace TaMessageContext {
|
|
260
|
-
function wrap(context: string, message: string): string;
|
|
261
|
-
/** The message without its context: what the user sees of it. */
|
|
262
|
-
function strip(message: string): string;
|
|
263
|
-
/** The context of the message, without its tags; undefined without one. */
|
|
264
|
-
function read(message: string): string | undefined;
|
|
265
|
-
}
|
|
266
|
-
/** Where a message of the user came from, when not from what they typed: see {@link TaMessageSource}. */
|
|
267
|
-
export interface TaMessageFrom {
|
|
268
|
-
/** The name of the package that sent it, or TaMessageSource.DOUBLE. */
|
|
269
|
-
from: string;
|
|
270
|
-
/** What the package says of it besides, in a few words (the channel and who spoke in it). */
|
|
271
|
-
detail?: string;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
|
|
275
|
-
* of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
|
|
276
|
-
* and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
|
|
277
|
-
*/
|
|
278
|
-
export declare namespace TaMessageSource {
|
|
279
|
-
/** The double of the web page: the tasks it hands out, what it tells them on the way. */
|
|
280
|
-
const DOUBLE = "ta:double";
|
|
281
|
-
/** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
|
|
282
|
-
function mark(message: string, from: string, detail?: string): string;
|
|
283
|
-
function of(message: string): TaMessageFrom | undefined;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* 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
|
|
287
|
-
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
288
|
-
*/
|
|
289
|
-
export declare namespace TaImageNote {
|
|
290
|
-
/** The text without the notes of its images: what the user sees of it. */
|
|
291
|
-
function strip(text: string): string;
|
|
292
|
-
}
|
|
293
|
-
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
294
|
-
export declare namespace TaImageSize {
|
|
295
|
-
function of(base64: string): {
|
|
296
|
-
width: number;
|
|
297
|
-
height: number;
|
|
298
|
-
} | undefined;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
302
|
-
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
303
|
-
*/
|
|
304
|
-
export declare namespace TaAgentSummary {
|
|
305
|
-
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
306
|
-
function read(text: string): string | undefined;
|
|
307
|
-
/** The text without the summary it starts with. */
|
|
308
|
-
function strip(text: string): string;
|
|
309
|
-
}
|
|
310
|
-
/** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
|
|
311
|
-
export interface TaSkillUse {
|
|
312
|
-
name: string;
|
|
313
|
-
/** The path of its SKILL.md. */
|
|
314
|
-
location: string;
|
|
315
|
-
/** What pi read of it, for the model. */
|
|
316
|
-
content: string;
|
|
317
|
-
/** What the user wrote after `/skill:name`. */
|
|
318
|
-
message?: string;
|
|
319
|
-
}
|
|
320
|
-
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
321
|
-
export declare namespace TaSkillUse {
|
|
322
|
-
function parse(message: string): TaSkillUse | undefined;
|
|
323
|
-
/** What the user typed: `/skill:name` and what follows. */
|
|
324
|
-
function command(use: TaSkillUse): string;
|
|
325
|
-
}
|
|
326
231
|
/**
|
|
327
232
|
* The server has taken the message; it says nothing about the run. A run is finished at the
|
|
328
233
|
* `agent_settled` event, when its history is on disk.
|
|
@@ -335,67 +240,6 @@ export interface TaPromptReceipt {
|
|
|
335
240
|
*/
|
|
336
241
|
status: 'accepted' | 'queued' | 'duplicate' | 'handled';
|
|
337
242
|
}
|
|
338
|
-
/** An extension's dialog was answered by another client, or expired. */
|
|
339
|
-
export interface TaUiRequestResolved {
|
|
340
|
-
type: 'ui_request_resolved';
|
|
341
|
-
id: string;
|
|
342
|
-
}
|
|
343
|
-
/** An extension threw while handling an event. */
|
|
344
|
-
export interface TaExtensionError {
|
|
345
|
-
type: 'extension_error';
|
|
346
|
-
extensionPath: string;
|
|
347
|
-
event: string;
|
|
348
|
-
error: string;
|
|
349
|
-
}
|
|
350
|
-
/** The open session now shows another conversation (`newSession`, `switchSession`, `fork`, `clone`, `navigateTree`): read it again. */
|
|
351
|
-
export interface TaSessionReplaced {
|
|
352
|
-
type: 'session_replaced';
|
|
353
|
-
info: TaSessionInfo;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* The session loaded its extensions, skills, prompts and themes again (`reload`, or an extension's
|
|
357
|
-
* `ctx.reload()`): its commands may have changed, read them again (`getCommands`).
|
|
358
|
-
*/
|
|
359
|
-
export interface TaSessionReloaded {
|
|
360
|
-
type: 'session_reloaded';
|
|
361
|
-
}
|
|
362
|
-
/** The session was closed; no more events come. */
|
|
363
|
-
export interface TaSessionClosed {
|
|
364
|
-
type: 'session_closed';
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* What the agent is doing while it works, from an extension (pi's `setWorkingMessage`), as starting the
|
|
368
|
-
* program of an external agent; none: the client's own words again.
|
|
369
|
-
*/
|
|
370
|
-
export interface TaWorkingMessage {
|
|
371
|
-
type: 'working_message';
|
|
372
|
-
message?: string;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* The model called a tool of `clientTools`: a client that runs it takes it with `claimClientTool`, so
|
|
376
|
-
* that one client runs it, however many are attached, and answers with `respondClientTool`. When that
|
|
377
|
-
* client leaves the session before it answers, the request comes again with the same id, for another.
|
|
378
|
-
* `client_tool_resolved` tells the others it was answered.
|
|
379
|
-
*/
|
|
380
|
-
export interface TaClientToolRequest {
|
|
381
|
-
type: 'client_tool_request';
|
|
382
|
-
/** The id of the tool call. */
|
|
383
|
-
id: string;
|
|
384
|
-
toolName: string;
|
|
385
|
-
input: unknown;
|
|
386
|
-
}
|
|
387
|
-
/** A call of a client tool was answered, or ended because the run was aborted or the session closed. */
|
|
388
|
-
export interface TaClientToolResolved {
|
|
389
|
-
type: 'client_tool_resolved';
|
|
390
|
-
id: string;
|
|
391
|
-
}
|
|
392
|
-
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed | TaWorkingMessage;
|
|
393
|
-
export interface TaEventEnvelope {
|
|
394
|
-
sessionId: string;
|
|
395
|
-
/** Increases by one per event of the session. */
|
|
396
|
-
seq: number;
|
|
397
|
-
event: TaEvent;
|
|
398
|
-
}
|
|
399
243
|
/** A message of the conversation, as `getMessages` gives it. */
|
|
400
244
|
export type TaMessage = TaCommandResult<'get_messages'>['messages'][number];
|
|
401
245
|
/** A call of a tool in the run of now, as its events left it. */
|
|
@@ -419,6 +263,17 @@ export interface TaConversation {
|
|
|
419
263
|
* `attach`): those before come with `getEarlierMessages`. None or 0: all of it.
|
|
420
264
|
*/
|
|
421
265
|
start?: number;
|
|
266
|
+
/** When `messages` start in the middle of a turn: the message of the user that asked for it (TaTurnHead). */
|
|
267
|
+
head?: TaTurnHead;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The message of the user that asked for a turn, when only its latest steps came (a turn too long for a page):
|
|
271
|
+
* the conversation shows who asked, above the steps, before the rest of the turn is loaded.
|
|
272
|
+
*/
|
|
273
|
+
export interface TaTurnHead {
|
|
274
|
+
/** Where it is in the whole conversation. */
|
|
275
|
+
index: number;
|
|
276
|
+
message: TaMessage;
|
|
422
277
|
}
|
|
423
278
|
export interface TaAttachOptions {
|
|
424
279
|
/**
|
|
@@ -446,6 +301,8 @@ export interface TaMessagePage {
|
|
|
446
301
|
start: number;
|
|
447
302
|
/** False when the message given is no longer there (the conversation was compacted or moved): read it again. */
|
|
448
303
|
found: boolean;
|
|
304
|
+
/** When they start in the middle of a turn: the message of the user that asked for it. */
|
|
305
|
+
head?: TaTurnHead;
|
|
449
306
|
}
|
|
450
307
|
export interface TaAttachResult {
|
|
451
308
|
info: TaSessionInfo;
|
|
@@ -569,6 +426,17 @@ export interface TaServer {
|
|
|
569
426
|
* stays where it is. Open the file with `openSession` to go on with it.
|
|
570
427
|
*/
|
|
571
428
|
forkToFile(sessionId: string, entryId: string, position?: 'before' | 'at'): Promise<TaForkFileResult>;
|
|
429
|
+
/**
|
|
430
|
+
* The whole conversation copied into the directory it works in now, a new conversation of its own (pi's
|
|
431
|
+
* `SessionManager.forkFrom`): for one whose directory is gone (TaSessionInfo.movedFrom), to go on there.
|
|
432
|
+
*/
|
|
433
|
+
forkHere(sessionId: string): Promise<TaForkFileResult>;
|
|
434
|
+
/**
|
|
435
|
+
* What of Ta names a directory, as it was (moved, renamed, or the path of another computer after a move) and its
|
|
436
|
+
* directories under it: their conversations (pi's session files go to the folder of the new directory), the data
|
|
437
|
+
* packages keep of it and the working directory, all made the directory `to`, which must exist.
|
|
438
|
+
*/
|
|
439
|
+
relocateDirectory(from: string, to: string): Promise<TaRelocateResult>;
|
|
572
440
|
clone(sessionId: string): Promise<TaCommandResult<'clone'>>;
|
|
573
441
|
getForkMessages(sessionId: string): Promise<TaCommandResult<'get_fork_messages'>>;
|
|
574
442
|
getEntries(sessionId: string, since?: string): Promise<TaCommandResult<'get_entries'>>;
|
|
@@ -613,5 +481,12 @@ export interface TaClient {
|
|
|
613
481
|
onRemoteEvent(event: TaRemoteEvent): Promise<void>;
|
|
614
482
|
/** What happens in the rooms, once this connection called TaRoomServer.watch. */
|
|
615
483
|
onRoomEvent(event: TaRoomEvent): Promise<void>;
|
|
484
|
+
/** What a voice this connection opened for a call tells (TaVoiceServer.openVoice). */
|
|
485
|
+
onVoiceEvent(event: TaVoiceEvent): Promise<void>;
|
|
486
|
+
/**
|
|
487
|
+
* ta serve asks this page something (TaPageServer.attach said it answers `kind`): what it answers, or an error. Only
|
|
488
|
+
* a page of the person whose run asks is asked (docs/design/ta-app-use.md 4.1).
|
|
489
|
+
*/
|
|
490
|
+
onPageAsk(kind: string, payload: unknown): Promise<unknown>;
|
|
616
491
|
}
|
|
617
492
|
export {};
|
|
@@ -13,50 +13,6 @@ export const TA_SERVE_RESTART_EXIT_CODE = 75;
|
|
|
13
13
|
* the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
|
|
14
14
|
*/
|
|
15
15
|
export const TA_RESUME_MESSAGE = 'ta-resume';
|
|
16
|
-
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
17
|
-
export const TaErrorCode = {
|
|
18
|
-
SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
|
|
19
|
-
SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
|
|
20
|
-
TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
|
|
21
|
-
MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
|
|
22
|
-
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
23
|
-
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
24
|
-
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
25
|
-
/** Compacting found nothing to compact: the conversation is still short. */
|
|
26
|
-
NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
|
|
27
|
-
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
28
|
-
ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
|
|
29
|
-
/** The session is answering or compacting, which has to end first. */
|
|
30
|
-
SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
|
|
31
|
-
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
32
|
-
CANCELLED: 'CELL_TA_CANCELLED',
|
|
33
|
-
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
34
|
-
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
35
|
-
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
36
|
-
ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
|
|
37
|
-
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
38
|
-
RATE_LIMITED: 'CELL_TA_RATE_LIMITED',
|
|
39
|
-
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
40
|
-
FORBIDDEN: 'CELL_TA_FORBIDDEN',
|
|
41
|
-
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
42
|
-
LIMIT: 'CELL_TA_LIMIT',
|
|
43
|
-
/** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
|
|
44
|
-
CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST',
|
|
45
|
-
};
|
|
46
|
-
export var TaErrorUtil;
|
|
47
|
-
(function (TaErrorUtil) {
|
|
48
|
-
/** The {@link TaErrorCode} of a failure: `code` of the client's error, `data.code` of the server's own, called in its process. */
|
|
49
|
-
function code(error) {
|
|
50
|
-
var _a;
|
|
51
|
-
var _b;
|
|
52
|
-
const failure = error;
|
|
53
|
-
const code = (_b = failure === null || failure === void 0 ? void 0 : failure.code) !== null && _b !== void 0 ? _b : (_a = failure === null || failure === void 0 ? void 0 : failure.data) === null || _a === void 0 ? void 0 : _a.code;
|
|
54
|
-
return typeof code === 'string' ? code : undefined;
|
|
55
|
-
}
|
|
56
|
-
TaErrorUtil.code = code;
|
|
57
|
-
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
58
|
-
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
59
|
-
export const TA_RPC_ERROR_CODE = -32050;
|
|
60
16
|
export var TaSlashCommandUtil;
|
|
61
17
|
(function (TaSlashCommandUtil) {
|
|
62
18
|
/** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
|
|
@@ -67,194 +23,4 @@ export var TaSlashCommandUtil;
|
|
|
67
23
|
}
|
|
68
24
|
TaSlashCommandUtil.description = description;
|
|
69
25
|
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
70
|
-
/**
|
|
71
|
-
* A message of the user may start with a `<context>` block: what the model reads besides the message
|
|
72
|
-
* (where it is said, who is there, what was said before), which a client leaves out when it shows it.
|
|
73
|
-
*/
|
|
74
|
-
export var TaMessageContext;
|
|
75
|
-
(function (TaMessageContext) {
|
|
76
|
-
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
77
|
-
function wrap(context, message) {
|
|
78
|
-
return `<context>\n${context}\n</context>\n${message}`;
|
|
79
|
-
}
|
|
80
|
-
TaMessageContext.wrap = wrap;
|
|
81
|
-
/** The message without its context: what the user sees of it. */
|
|
82
|
-
function strip(message) {
|
|
83
|
-
return message.replace(BLOCK, '');
|
|
84
|
-
}
|
|
85
|
-
TaMessageContext.strip = strip;
|
|
86
|
-
/** The context of the message, without its tags; undefined without one. */
|
|
87
|
-
function read(message) {
|
|
88
|
-
var _a;
|
|
89
|
-
const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
|
|
90
|
-
return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
|
|
91
|
-
}
|
|
92
|
-
TaMessageContext.read = read;
|
|
93
|
-
})(TaMessageContext || (TaMessageContext = {}));
|
|
94
|
-
/**
|
|
95
|
-
* A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
|
|
96
|
-
* of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
|
|
97
|
-
* and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
|
|
98
|
-
*/
|
|
99
|
-
export var TaMessageSource;
|
|
100
|
-
(function (TaMessageSource) {
|
|
101
|
-
/** The double of the web page: the tasks it hands out, what it tells them on the way. */
|
|
102
|
-
TaMessageSource.DOUBLE = 'ta:double';
|
|
103
|
-
const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
104
|
-
/** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
|
|
105
|
-
function mark(message, from, detail) {
|
|
106
|
-
if (/^[/!]/.test(message) || of(message)) {
|
|
107
|
-
return message;
|
|
108
|
-
}
|
|
109
|
-
const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
|
|
110
|
-
const context = TaMessageContext.read(message);
|
|
111
|
-
return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
|
|
112
|
-
}
|
|
113
|
-
TaMessageSource.mark = mark;
|
|
114
|
-
function of(message) {
|
|
115
|
-
const context = TaMessageContext.read(message);
|
|
116
|
-
const match = context === undefined ? null : LINE.exec(context);
|
|
117
|
-
return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
|
|
118
|
-
}
|
|
119
|
-
TaMessageSource.of = of;
|
|
120
|
-
})(TaMessageSource || (TaMessageSource = {}));
|
|
121
|
-
/**
|
|
122
|
-
* 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
|
|
123
|
-
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
124
|
-
*/
|
|
125
|
-
export var TaImageNote;
|
|
126
|
-
(function (TaImageNote) {
|
|
127
|
-
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 [^\]]+\.\]$/;
|
|
128
|
-
/** The text without the notes of its images: what the user sees of it. */
|
|
129
|
-
function strip(text) {
|
|
130
|
-
const lines = text.split('\n');
|
|
131
|
-
const kept = lines.filter(line => !NOTE.test(line.trim()));
|
|
132
|
-
if (kept.length === lines.length) {
|
|
133
|
-
return text;
|
|
134
|
-
}
|
|
135
|
-
return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
|
|
136
|
-
}
|
|
137
|
-
TaImageNote.strip = strip;
|
|
138
|
-
})(TaImageNote || (TaImageNote = {}));
|
|
139
|
-
/** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
|
|
140
|
-
export var TaImageSize;
|
|
141
|
-
(function (TaImageSize) {
|
|
142
|
-
/** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
|
|
143
|
-
const JPEG_BYTES = 256 * 1024;
|
|
144
|
-
function of(base64) {
|
|
145
|
-
var _a, _b, _c;
|
|
146
|
-
let bytes;
|
|
147
|
-
try {
|
|
148
|
-
// Whole groups of four characters only.
|
|
149
|
-
const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
|
|
150
|
-
bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
|
|
151
|
-
}
|
|
152
|
-
catch (_d) {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
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);
|
|
156
|
-
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
157
|
-
}
|
|
158
|
-
TaImageSize.of = of;
|
|
159
|
-
function u16be(bytes, at) {
|
|
160
|
-
return (bytes[at] << 8) | bytes[at + 1];
|
|
161
|
-
}
|
|
162
|
-
function u16le(bytes, at) {
|
|
163
|
-
return bytes[at] | (bytes[at + 1] << 8);
|
|
164
|
-
}
|
|
165
|
-
function u24le(bytes, at) {
|
|
166
|
-
return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
|
|
167
|
-
}
|
|
168
|
-
function u32be(bytes, at) {
|
|
169
|
-
return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
170
|
-
}
|
|
171
|
-
function text(bytes, at, length) {
|
|
172
|
-
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
173
|
-
}
|
|
174
|
-
function png(bytes) {
|
|
175
|
-
return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
176
|
-
}
|
|
177
|
-
function gif(bytes) {
|
|
178
|
-
return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
179
|
-
}
|
|
180
|
-
function webp(bytes) {
|
|
181
|
-
if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
|
|
182
|
-
return undefined;
|
|
183
|
-
}
|
|
184
|
-
switch (text(bytes, 12, 4)) {
|
|
185
|
-
case 'VP8 ':
|
|
186
|
-
return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
|
|
187
|
-
case 'VP8L': {
|
|
188
|
-
const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
|
|
189
|
-
return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
|
|
190
|
-
}
|
|
191
|
-
case 'VP8X':
|
|
192
|
-
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
193
|
-
default:
|
|
194
|
-
return undefined;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function jpeg(bytes) {
|
|
198
|
-
if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
let at = 2;
|
|
202
|
-
while (at + 9 < bytes.length) {
|
|
203
|
-
if (bytes[at] !== 0xff) {
|
|
204
|
-
return undefined;
|
|
205
|
-
}
|
|
206
|
-
const marker = bytes[at + 1];
|
|
207
|
-
// A start of frame (not DHT, JPG or DAC, which share the range) says the size.
|
|
208
|
-
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
209
|
-
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
210
|
-
}
|
|
211
|
-
at += 2 + u16be(bytes, at + 2);
|
|
212
|
-
}
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
})(TaImageSize || (TaImageSize = {}));
|
|
216
|
-
/**
|
|
217
|
-
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
218
|
-
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
219
|
-
*/
|
|
220
|
-
export var TaAgentSummary;
|
|
221
|
-
(function (TaAgentSummary) {
|
|
222
|
-
const START = /^\s*<conversation_history_summary>/;
|
|
223
|
-
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
224
|
-
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
225
|
-
function read(text) {
|
|
226
|
-
if (!START.test(text)) {
|
|
227
|
-
return undefined;
|
|
228
|
-
}
|
|
229
|
-
return text
|
|
230
|
-
.replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
|
|
231
|
-
.replace(/<\/?\w*$/, '')
|
|
232
|
-
.trim();
|
|
233
|
-
}
|
|
234
|
-
TaAgentSummary.read = read;
|
|
235
|
-
/** The text without the summary it starts with. */
|
|
236
|
-
function strip(text) {
|
|
237
|
-
return text.replace(BLOCK, '');
|
|
238
|
-
}
|
|
239
|
-
TaAgentSummary.strip = strip;
|
|
240
|
-
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
241
|
-
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
242
|
-
export var TaSkillUse;
|
|
243
|
-
(function (TaSkillUse) {
|
|
244
|
-
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
245
|
-
function parse(message) {
|
|
246
|
-
var _a;
|
|
247
|
-
const match = BLOCK.exec(message);
|
|
248
|
-
if (!match) {
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
|
|
252
|
-
}
|
|
253
|
-
TaSkillUse.parse = parse;
|
|
254
|
-
/** What the user typed: `/skill:name` and what follows. */
|
|
255
|
-
function command(use) {
|
|
256
|
-
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
257
|
-
}
|
|
258
|
-
TaSkillUse.command = command;
|
|
259
|
-
})(TaSkillUse || (TaSkillUse = {}));
|
|
260
26
|
//# sourceMappingURL=ta-protocol.js.map
|