@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.
Files changed (67) hide show
  1. package/esm/common/app-protocol.d.ts +115 -0
  2. package/esm/common/app-protocol.js +199 -0
  3. package/esm/common/delegate-protocol.d.ts +30 -0
  4. package/esm/common/delegate-protocol.js +52 -0
  5. package/esm/common/deployment-protocol.d.ts +59 -0
  6. package/esm/common/deployment-protocol.js +135 -0
  7. package/esm/common/error-protocol.d.ts +42 -0
  8. package/esm/common/error-protocol.js +45 -0
  9. package/esm/common/event-protocol.d.ts +63 -0
  10. package/esm/common/event-protocol.js +2 -0
  11. package/esm/common/gateway-protocol.d.ts +54 -2
  12. package/esm/common/index.d.ts +9 -0
  13. package/esm/common/index.js +9 -0
  14. package/esm/common/location.d.ts +18 -1
  15. package/esm/common/location.js +51 -4
  16. package/esm/common/message-protocol.d.ts +95 -0
  17. package/esm/common/message-protocol.js +237 -0
  18. package/esm/common/page-protocol.d.ts +56 -0
  19. package/esm/common/page-protocol.js +12 -0
  20. package/esm/common/path-map.d.ts +24 -0
  21. package/esm/common/path-map.js +127 -0
  22. package/esm/common/presence-protocol.js +1 -1
  23. package/esm/common/redactor.d.ts +12 -0
  24. package/esm/common/redactor.js +49 -11
  25. package/esm/common/relay-protocol.d.ts +20 -0
  26. package/esm/common/remote-protocol.d.ts +12 -4
  27. package/esm/common/room-protocol.d.ts +7 -1
  28. package/esm/common/ta-extension-host.d.ts +31 -1
  29. package/esm/common/ta-extension-host.js +2 -0
  30. package/esm/common/ta-protocol.d.ts +50 -175
  31. package/esm/common/ta-protocol.js +0 -234
  32. package/esm/common/voice-protocol.d.ts +139 -0
  33. package/esm/common/voice-protocol.js +3 -0
  34. package/lib/common/app-protocol.d.ts +116 -0
  35. package/lib/common/app-protocol.js +202 -0
  36. package/lib/common/delegate-protocol.d.ts +31 -0
  37. package/lib/common/delegate-protocol.js +55 -0
  38. package/lib/common/deployment-protocol.d.ts +60 -0
  39. package/lib/common/deployment-protocol.js +139 -0
  40. package/lib/common/error-protocol.d.ts +43 -0
  41. package/lib/common/error-protocol.js +48 -0
  42. package/lib/common/event-protocol.d.ts +64 -0
  43. package/lib/common/event-protocol.js +3 -0
  44. package/lib/common/gateway-protocol.d.ts +54 -2
  45. package/lib/common/index.d.ts +9 -0
  46. package/lib/common/index.js +9 -0
  47. package/lib/common/location.d.ts +18 -1
  48. package/lib/common/location.js +51 -4
  49. package/lib/common/message-protocol.d.ts +96 -0
  50. package/lib/common/message-protocol.js +240 -0
  51. package/lib/common/page-protocol.d.ts +57 -0
  52. package/lib/common/page-protocol.js +15 -0
  53. package/lib/common/path-map.d.ts +25 -0
  54. package/lib/common/path-map.js +130 -0
  55. package/lib/common/presence-protocol.js +7 -7
  56. package/lib/common/redactor.d.ts +12 -0
  57. package/lib/common/redactor.js +49 -11
  58. package/lib/common/relay-protocol.d.ts +20 -0
  59. package/lib/common/remote-protocol.d.ts +12 -4
  60. package/lib/common/room-protocol.d.ts +7 -1
  61. package/lib/common/ta-extension-host.d.ts +31 -1
  62. package/lib/common/ta-extension-host.js +3 -1
  63. package/lib/common/ta-protocol.d.ts +50 -175
  64. package/lib/common/ta-protocol.js +1 -235
  65. package/lib/common/voice-protocol.d.ts +140 -0
  66. package/lib/common/voice-protocol.js +6 -0
  67. package/package.json +1 -1
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Redactor = exports.REDACTED = void 0;
4
4
  /** What a secret is replaced with. */
5
5
  exports.REDACTED = '[redacted]';
6
- /** Secrets that have a shape of their own: the whole match goes. */
6
+ /** Secrets that have a shape of their own, by what they are: the whole match goes. */
7
7
  const WHOLE = [
8
- /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
9
- /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
10
- /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
11
- /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
12
- /\bglpat-[A-Za-z0-9_-]{20,}\b/g,
13
- /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
14
- /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
15
- /\bAIza[0-9A-Za-z_-]{35}\b/g,
16
- /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
8
+ ['PRIVATE_KEY', /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
9
+ ['API_KEY', /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g],
10
+ ['GITHUB_TOKEN', /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g],
11
+ ['GITHUB_TOKEN', /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g],
12
+ ['GITLAB_TOKEN', /\bglpat-[A-Za-z0-9_-]{20,}\b/g],
13
+ ['SLACK_TOKEN', /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g],
14
+ ['AWS_ACCESS_KEY_ID', /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
15
+ ['GOOGLE_API_KEY', /\bAIza[0-9A-Za-z_-]{35}\b/g],
16
+ ['JWT', /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g],
17
17
  ];
18
18
  /** Secrets named by what is before them: what is before stays. */
19
19
  const NAMED = [
@@ -33,7 +33,7 @@ class Redactor {
33
33
  }
34
34
  text(text) {
35
35
  let out = text;
36
- for (const pattern of WHOLE) {
36
+ for (const [, pattern] of WHOLE) {
37
37
  out = out.replace(pattern, () => this.hide());
38
38
  }
39
39
  out = out.replace(NAMED[0], (_match, before) => before + this.hide());
@@ -54,6 +54,44 @@ class Redactor {
54
54
  }
55
55
  return value;
56
56
  }
57
+ /**
58
+ * Where secrets are in a text, by the same patterns, none overlapping, the first first: what the vault of
59
+ * ta-secrets takes out of what the user sends. `kind` names it: `GITHUB_TOKEN`, `API_KEY` (an `sk-` key),
60
+ * `PRIVATE_KEY`, `BEARER_TOKEN`, `URL_PASSWORD`, or the name it was assigned to (`DB_PASSWORD`).
61
+ */
62
+ static spans(text) {
63
+ var _a;
64
+ var _b;
65
+ const found = [];
66
+ for (const [kind, pattern] of WHOLE) {
67
+ for (const match of text.matchAll(pattern)) {
68
+ found.push({ start: match.index, end: match.index + match[0].length, kind });
69
+ }
70
+ }
71
+ for (const match of text.matchAll(NAMED[0])) {
72
+ found.push({ start: match.index + match[1].length, end: match.index + match[0].length, kind: 'BEARER_TOKEN' });
73
+ }
74
+ for (const match of text.matchAll(NAMED[1])) {
75
+ if (!Redactor.placeholder(match[2])) {
76
+ const start = match.index + match[1].length;
77
+ const name = (_b = (_a = /[A-Za-z0-9_.-]+/.exec(match[1])) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 'SECRET';
78
+ found.push({ start, end: start + match[2].length, kind: name.replace(/[^A-Za-z0-9]+/g, '_').toUpperCase() });
79
+ }
80
+ }
81
+ for (const match of text.matchAll(NAMED[2])) {
82
+ const start = match.index + match[1].length;
83
+ found.push({ start, end: start + match[2].length, kind: 'URL_PASSWORD' });
84
+ }
85
+ found.sort((a, b) => a.start - b.start || b.end - a.end);
86
+ const spans = [];
87
+ for (const span of found) {
88
+ const last = spans.at(-1);
89
+ if (!last || span.start >= last.end) {
90
+ spans.push(span);
91
+ }
92
+ }
93
+ return spans;
94
+ }
57
95
  static cut(text, max) {
58
96
  return text.length > max ? `${text.slice(0, max)}…` : text;
59
97
  }
@@ -105,6 +105,18 @@ export interface TaRelays {
105
105
  }[];
106
106
  /** The types of services packages registered (WebDAV, S3…), to add one of. */
107
107
  types?: TaRelayTypeInfo[];
108
+ /** The deployment of Ta joined (TaRelayServer.joinDeployment): its relay is the default of what is new. */
109
+ deployment?: TaJoinedDeployment;
110
+ }
111
+ /** A deployment of Ta joined by its address (docs/design/ta-deploy.md 8). */
112
+ export interface TaJoinedDeployment {
113
+ /** The address the user gave. */
114
+ url: string;
115
+ name?: string;
116
+ /** Its gateway: a Ta in the cloud of one's own account there, or its sandbox as a cloud workspace. */
117
+ gateway?: string;
118
+ /** The id of its relay in TaRelays.relays. */
119
+ relay?: string;
108
120
  }
109
121
  /** What asking a relay what it is found (TaRelayServer.probeRelay). */
110
122
  export interface TaRelayProbe {
@@ -164,6 +176,14 @@ export interface TaRelayServer {
164
176
  * on the relay it was made on.
165
177
  */
166
178
  chooseRelay(feature: TaRelayFeature, id: string | null): Promise<TaRelays>;
179
+ /**
180
+ * Joins a deployment of Ta by the address of any of its services (its gateway, its relay), which says what it is at
181
+ * /.well-known/ta: its relay is added and made the default of new pairings, rooms and links; what was made before
182
+ * stays where it is.
183
+ */
184
+ joinDeployment(url: string): Promise<TaRelays>;
185
+ /** Leaves the deployment joined: the relay of this build is the default again. */
186
+ leaveDeployment(): Promise<TaRelays>;
167
187
  /** Asks a relay, by its id or address, what it can do and how much; never throws. */
168
188
  probeRelay(idOrUrl: string): Promise<TaRelayProbe>;
169
189
  /**
@@ -1,11 +1,13 @@
1
1
  export declare const TaRemoteServer: unique symbol;
2
2
  export declare const TA_REMOTE_SERVICE = "TaRemoteServer";
3
- /** A machine ta serve can reach with ssh. */
3
+ /** A machine ta serve can reach with ssh, or a cloud workspace it reaches over a WebSocket. */
4
4
  export interface TaRemoteHost {
5
- /** What follows `ssh://` in a location (TaLocation). */
5
+ /** What follows `ssh://` in a location (TaLocation), or `ta://<name>` for a cloud workspace. */
6
6
  host: string;
7
- /** A Host of ~/.ssh/config, or one opened before. */
8
- source: 'config' | 'recent';
7
+ /** A Host of ~/.ssh/config, one opened before, or a cloud workspace added (TaRemoteServer.addCloudHost). */
8
+ source: 'config' | 'recent' | 'cloud';
9
+ /** Of a cloud workspace: the address of its Ta gateway or Ta service, never its token. */
10
+ url?: string;
9
11
  /** ta serve is connected to it now. */
10
12
  connected: boolean;
11
13
  }
@@ -67,6 +69,12 @@ export interface TaRemoteServer {
67
69
  addHost(host: string): Promise<void>;
68
70
  /** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
69
71
  removeHost(host: string): Promise<void>;
72
+ /**
73
+ * A cloud workspace, `ta://<name>`: the sandbox of the account of `token` on the Ta gateway at `url` (or the
74
+ * machine of a Ta service, with its token), whose directories conversations work in while the agent stays here.
75
+ * Checked by connecting first; kept with its token, which never comes back.
76
+ */
77
+ addCloudHost(name: string, url: string, token: string): Promise<TaRemoteHost>;
70
78
  /**
71
79
  * A location as the user wrote it, whole: `~/src`, `ssh://<host>` (its home), `ssh://<host>/~/src`, or a path
72
80
  * relative to the default directory; one already whole as it is. Connects to the host when it needs its home.
@@ -49,6 +49,8 @@ export interface TaRoomInfo {
49
49
  relay?: string;
50
50
  /** This Ta made it. */
51
51
  owner: boolean;
52
+ /** Of a room this Ta made: the members it lets in at most (TaRoomServer.configureRoom). */
53
+ capacity?: number;
52
54
  ownerName: string;
53
55
  status: TaRoomStatus;
54
56
  /** Why it is `gone`: `closed` by the owner, `removed` by the owner, the `invite` no longer works. */
@@ -155,7 +157,7 @@ export interface TaRoomServer {
155
157
  }): Promise<TaRoomInfo>;
156
158
  /**
157
159
  * The link others ask to join by (the owner only): the one of before while it has a day left; else, or with `renew`,
158
- * a new one for `days` (7 by default, 30 at most), and the links of before stop working.
160
+ * a new one for `days` (7 by default, 365 at most), and the links of before stop working.
159
161
  */
160
162
  invite(room: string, options?: {
161
163
  days?: number;
@@ -164,6 +166,10 @@ export interface TaRoomServer {
164
166
  link: string;
165
167
  expiresAt: number;
166
168
  }>;
169
+ /** The owner's choices for a room: the members it lets in at most (16 by default, 2 to 100); those in already stay. */
170
+ configureRoom(room: string, options: {
171
+ members?: number;
172
+ }): Promise<TaRoomInfo>;
167
173
  /** Asks to join the room of a link: `waiting` till its owner answers. Ask the user first. */
168
174
  join(link: string): Promise<TaRoomInfo>;
169
175
  /** Those asking to join the rooms of this Ta. */
@@ -1,16 +1,19 @@
1
1
  import type { TaSignInProvider } from './access-protocol';
2
+ import type { TaHostCommands } from './app-protocol';
2
3
  import type { TaPackageServer } from './package-protocol';
4
+ import type { TaHostPages } from './page-protocol';
3
5
  import type { TaPresencePerson } from './presence-protocol';
4
6
  import type { TaRelayFeature, TaRelayService, TaRelayStore, TaRelayType, TaShares } from './relay-protocol';
5
7
  import type { TaRooms } from './room-protocol';
6
8
  import type { TaServer } from './ta-protocol';
7
9
  import type { TaAuthorizer, TaMemberInfo, TaResource, TaSharedData, TaSharedRef } from './team-protocol';
10
+ import type { TaExtensionVoices } from './voice-protocol';
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,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaAskUtil = exports.TA_ASK_ENTRY = exports.TA_BRIEF_SOURCE = exports.TA_KEEP_MARK = exports.TA_WITH_OTHERS_MARK = exports.TA_NOTICES = exports.TA_DOUBLE_TASKS = exports.TA_DOUBLE_LOOK = exports.TA_DOUBLE_FILE = exports.TA_FILE_WRITE_EVENT = exports.TaHostUtil = exports.TA_HOST_EVENT = void 0;
3
+ exports.TaAskUtil = exports.TA_ASK_ENTRY = exports.TA_BRIEF_SOURCE = exports.TA_KEEP_MARK = exports.TA_WITH_OTHERS_MARK = exports.TA_NOTICES = exports.TA_DOUBLE_TASKS = exports.TA_DOUBLE_LOOK = exports.TA_DOUBLE_FILE = exports.TA_FILE_WRITE_EVENT = exports.TaHostUtil = exports.TA_HOST_EVENT = exports.TA_WEBHOOK_MAX_BYTES = void 0;
4
+ /** The largest body a webhook takes; a larger one is refused (413). */
5
+ exports.TA_WEBHOOK_MAX_BYTES = 256 * 1024;
4
6
  /**
5
7
  * The event of pi's `pi.events` by which a pi extension asks for the host of its package:
6
8
  * `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';
2
- import type { ImageContent, JsonAgentSessionEvent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types';
2
+ import type { TaClientToolRequest, TaEventEnvelope } from './event-protocol';
3
+ import type { ImageContent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types';
3
4
  import type { TaSessionPerson } from './presence-protocol';
4
5
  import type { TaRemoteEvent } from './remote-protocol';
5
6
  import type { TaRoomEvent } from './room-protocol';
6
7
  import type { TaAsking } from './ta-extension-host';
7
8
  import type { TaMemberInfo } from './team-protocol';
9
+ import type { TaVoiceEvent } from './voice-protocol';
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,6 +481,13 @@ 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 {};
618
493
  //# sourceMappingURL=ta-protocol.d.ts.map