@celljs/ta-protocol 4.12.0 → 4.13.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.
@@ -1,13 +1,14 @@
1
1
  import type { TaPackageServer } from './package-protocol';
2
- import type { TaShares } from './relay-protocol';
2
+ import type { TaRelayFeature, TaRelayService, TaRelayStore, TaRelayType, TaShares } from './relay-protocol';
3
3
  import type { TaRooms } from './room-protocol';
4
4
  import type { TaServer } from './ta-protocol';
5
+ import type { TaAuthorizer, TaMemberInfo, TaResource, TaSharedData, TaSharedRef } from './team-protocol';
5
6
  /**
6
7
  * What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
7
8
  * process, without a token. A subset of TaServer and TaPackageServer: it can open, drive, stop and close
8
9
  * sessions (best those it opened: closing one takes it from every client), not remove anything.
9
10
  */
10
- export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
11
+ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages' | 'callPackageHost' | 'installPackage' | 'removePackage'> {
11
12
  /** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
12
13
  readonly agentDir: string;
13
14
  /** 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. */
@@ -16,6 +17,8 @@ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listS
16
17
  readonly shares: TaShares;
17
18
  /** Rooms shared with other Ta, through the relay (docs/design/ta-link.md 3). */
18
19
  readonly rooms: TaRooms;
20
+ /** The services of relays.json, as the user chose them for each feature (docs/design/ta-relays.md). */
21
+ readonly relays: TaExtensionRelays;
19
22
  /** pi's messages of a session file, of the branch it is on (its first message first), without opening it. */
20
23
  sessionMessages(sessionFile: string): Promise<unknown[]>;
21
24
  /**
@@ -25,6 +28,47 @@ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listS
25
28
  createSession(cwd: string, messages: readonly unknown[], name?: string): Promise<string>;
26
29
  /** 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. */
27
30
  onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
31
+ /**
32
+ * The turns of every open session, as they start and end: what a package acts on without a pi extension in each
33
+ * session (a turn that failed, docs/design/ta-initiative.md 3.1).
34
+ */
35
+ onSessionEvent(listener: (event: TaHostSessionEvent) => void): () => void;
36
+ /** Whether the user is around now: the pages of Ta connected, on any device. */
37
+ presence(): TaPresence;
38
+ /** The people let into this Ta besides its user, and what they may do (docs/design/ta-team.md). */
39
+ readonly team: TaHostTeam;
40
+ /**
41
+ * Rewrites pi's `settings.json` of the user as pi does, under its lock: `update` gets the settings read under the
42
+ * lock and returns them whole; the open sessions read them again. For what changes settings of the user that are no
43
+ * setting of Ta (TA_SETTINGS), as a sync from another computer.
44
+ */
45
+ updateSettings(update: (settings: Record<string, unknown>) => Record<string, unknown>): Promise<void>;
46
+ }
47
+ /** relays.json for the server side of packages: which service a feature uses, and choosing one for it. */
48
+ export interface TaExtensionRelays {
49
+ /** The service a feature uses now: a relay of Ta, or a folder (only `sync` goes to one). */
50
+ serviceFor(feature: TaRelayFeature): Promise<TaRelayService>;
51
+ /** Adds a folder of a cloud drive: its id, the one of before for the same folder. */
52
+ addFolder(path: string, name?: string): Promise<string>;
53
+ /** The service a feature uses from now on; `null` for the default. */
54
+ choose(feature: TaRelayFeature, id: string | null): Promise<void>;
55
+ /** The services of relays.json, the official relay among them. */
56
+ list(): Promise<TaRelayService[]>;
57
+ /**
58
+ * A type of service for relays.json (`webdav`, `s3`): `"type": "<type>"` there, its options beside it, and a form to
59
+ * add one in Settings → Relays. Only sync uses such a store. Gone again with what it returns, or when the package stops.
60
+ */
61
+ registerType(type: string, definition: TaRelayType): () => void;
62
+ /** The store of a service of a type a package registered; throws when its package is off. */
63
+ openStore(id: string): Promise<TaRelayStore>;
64
+ /** Adds a service of a registered type, as the form of Settings → Relays does: its id. */
65
+ addStore(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
66
+ /** A store service as relays.json has it, its secrets too: for a link to the user's own computers (ta-sync) alone. */
67
+ storeConfig(id: string): Promise<{
68
+ type: string;
69
+ options: Record<string, unknown>;
70
+ name?: string;
71
+ } | undefined>;
28
72
  }
29
73
  /**
30
74
  * What the module of `pi.host` returns: anything the package's pi extensions should reach. Its web
@@ -42,9 +86,9 @@ export interface TaPackageService {
42
86
  export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService | undefined | Promise<TaPackageService | undefined>;
43
87
  /**
44
88
  * The event of pi's `pi.events` by which a pi extension asks for the host of its package:
45
- * `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
46
- * the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
47
- * and the extension should say its tools need `ta serve`.
89
+ * `pi.events.emit(TA_HOST_EVENT, { name, resolve, heard })`. Under `ta serve` `heard` is called as the event
90
+ * is emitted and `resolve` soon after, if the extension asks after loading (on `session_start`, or in a tool);
91
+ * under `ta` alone nobody answers, and the extension should say its tools need `ta serve`.
48
92
  */
49
93
  export declare const TA_HOST_EVENT = "ta:host";
50
94
  /**
@@ -52,12 +96,13 @@ export declare const TA_HOST_EVENT = "ta:host";
52
96
  * in a bundle: this file has nothing else to run, where the whole protocol would come along with its index.
53
97
  */
54
98
  export declare namespace TaHostUtil {
99
+ /** How long the host has to answer once it heard the request; undefined after it. */
100
+ const WAIT_MS = 1000;
55
101
  /**
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.
102
+ * Asks for the host of the package `name` (TA_HOST_EVENT); undefined when nobody answers: not under `ta serve`.
103
+ * Nobody heard the event as it was emitted: undefined at once, not after WAIT_MS (each of the built-in packages
104
+ * asks as a session starts, and `ta -p` waited a second for several of them in turn).
58
105
  */
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
106
  function reach(events: {
62
107
  emit(event: string, data: unknown): void;
63
108
  }, name: string, waitMs?: number): Promise<TaHostAnswer | undefined>;
@@ -69,6 +114,81 @@ export declare namespace TaHostUtil {
69
114
  * keeps what the file holds then.
70
115
  */
71
116
  export declare const TA_FILE_WRITE_EVENT = "ta:file-write";
117
+ /** A turn of an open session started, or ended (TaExtensionHost.onSessionEvent). */
118
+ export interface TaHostSessionEvent {
119
+ type: 'turn_start' | 'turn_end';
120
+ sessionId: string;
121
+ sessionFile?: string;
122
+ cwd: string;
123
+ /** TaOpenSessionOptions.group: the package that opened it for a role of its own. */
124
+ group?: string;
125
+ /** `turn_end`: the error it ended with (pi's last answer stopped with an error, retries done). */
126
+ error?: string;
127
+ /** `turn_end`: the user stopped it. */
128
+ aborted?: boolean;
129
+ }
130
+ /**
131
+ * What ta serve gives the package that lets people in (ta-team): it checks every call of a principal other than the
132
+ * owner with the authorizer given, and knows who connected, who asked a turn, and the devices of each.
133
+ */
134
+ export interface TaHostTeam {
135
+ /** The authorizer from now on, till the function returned is called; without one, only the owner may do anything. */
136
+ authorize(authorizer: TaAuthorizer): () => void;
137
+ /** Who makes the call being served (a call of a page reaching the host of a package): TA_OWNER outside of one. */
138
+ current(): string;
139
+ /**
140
+ * Runs `run` as made by a principal: what it sends to a session is that principal's, and the run it starts does only
141
+ * what they may (a turn that goes on once what it asked for was granted).
142
+ */
143
+ actAs<T>(principal: string, run: () => Promise<T>): Promise<T>;
144
+ /**
145
+ * The principals whose messages the run going on in a session answers, TA_OWNER among them when the owner asked it;
146
+ * none while it is idle, or for a run no page asked (a package, a scheduled task, a tool's result coming back).
147
+ */
148
+ actorsOf(sessionFile: string): string[];
149
+ /** The principals connected now, other than the owner, with how many connections each. */
150
+ connected(): Record<string, number>;
151
+ /** What a tool needs of who asked the run, as its package declares it (TaPermissionManifest); undefined: not declared. */
152
+ toolAction(tool: string): string | undefined;
153
+ /** Who a principal is (TaAuthorizer.describe); undefined for the owner. */
154
+ describe(principal: string): TaMemberInfo | undefined;
155
+ /** Whether a principal may do an action: what the authorizer says, the owner anything. */
156
+ can(principal: string, action: string, resource?: TaResource): boolean;
157
+ /** Data of the package that is the Ta's (TaSharedData): pages of those let in read the owner's value through `view`. */
158
+ shareData(name: string, data: TaSharedData): () => void;
159
+ /** A conversation is that of an agent or a channel: who may use that one may use the conversation. */
160
+ link(sessionFile: string, ref: TaSharedRef | undefined): void;
161
+ /** Closes every connection of a principal, at once: what it was let to do was taken back. */
162
+ disconnect(principal: string): number;
163
+ /** A device for a principal: what it connects through the relay with, end to end; `expiresAt` for an invitation. */
164
+ pair(principal: string, name: string, expiresAt?: number): Promise<TaTeamPairing>;
165
+ unpair(deviceId: string): void;
166
+ /** The devices of principals other than the owner. */
167
+ devices(): TaTeamDevice[];
168
+ }
169
+ /** A device of a principal, and what reaches this Ta with it (RelayPairing). The key goes to that principal alone. */
170
+ export interface TaTeamPairing {
171
+ link: string;
172
+ relay: string;
173
+ host: string;
174
+ device: string;
175
+ key: string;
176
+ name?: string;
177
+ }
178
+ export interface TaTeamDevice {
179
+ id: string;
180
+ name: string;
181
+ member: string;
182
+ createdAt: number;
183
+ expiresAt?: number;
184
+ }
185
+ /** Whether the user is around (TaExtensionHost.presence). */
186
+ export interface TaPresence {
187
+ /** Pages of Ta connected now (a browser, Ta Desktop, the app on a phone, through the relay too). */
188
+ pages: number;
189
+ /** `Date.now()` time a page was last connected: now while one is. 0 for never since the service started. */
190
+ seenAt: number;
191
+ }
72
192
  /**
73
193
  * Where the web client keeps the session file of the double's conversation: in the data of packages
74
194
  * (TaExtensionHost.getExtensionData), under this package name and key; a JSON string, empty before the
@@ -78,12 +198,106 @@ export declare const TA_DOUBLE_FILE: {
78
198
  readonly name: '@celljs/ta-web';
79
199
  readonly key: 'assistant.file';
80
200
  };
201
+ /**
202
+ * Where the web client keeps the tasks the double handed out: in the data of packages, under this name and key; an
203
+ * array of `{ sessionId, sessionFile?, takenOver?, removed? }` among other fields. The double tells the user of these
204
+ * itself, so a package that tells of conversations (ta-notify) leaves them to it unless they ask.
205
+ */
206
+ export declare const TA_DOUBLE_TASKS: {
207
+ readonly name: '@celljs/ta-web';
208
+ readonly key: 'assistant.tasks';
209
+ };
210
+ /**
211
+ * Where ta-notify keeps what conversations and packages tell the user, for the pages and Ta Desktop: in the data of
212
+ * packages, under this name and key, the latest last ({@link TaNotice}[]).
213
+ */
214
+ export declare const TA_NOTICES: {
215
+ readonly name: '@celljs/ta-notify';
216
+ readonly key: 'notices';
217
+ };
218
+ /** A notice of ta-notify (TA_NOTICES), as those who tell of it read it. */
219
+ export interface TaNotice {
220
+ /** The same everywhere: each tells of a key once. */
221
+ key: string;
222
+ /** When it came (`Date.now()` of the Ta service). */
223
+ at: number;
224
+ /** `ask`: it needs the user; `failed`; `done`: it answered. */
225
+ level: 'ask' | 'failed' | 'done';
226
+ text: string;
227
+ sessionId?: string;
228
+ sessionFile?: string;
229
+ cwd?: string;
230
+ /** The name of its conversation then, or what a notice of a package is about. */
231
+ title?: string;
232
+ /** A notice of a package: the view a tap opens. */
233
+ view?: string;
234
+ }
81
235
  /**
82
236
  * In the system prompt of a session that speaks with other people for the user: their double in a room of Ta
83
237
  * (ta-rooms, docs/design/ta-link.md 4). An extension that brings in what is the user's own (their other
84
238
  * conversations, what they asked before) leaves such a session out: what it says goes to others.
85
239
  */
86
240
  export declare const TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
241
+ /**
242
+ * Starts the `<context>` of a message of the user that asks Ta to keep how a conversation got its work done, so that it
243
+ * need not be told again (Keep of ta-recall, in the + of the message box): Ta picks the form that fits. A package that
244
+ * keeps work a way of its own (ta-cron: a scheduled task) tells the model about it, in a section of the system prompt of
245
+ * its own, on the turns of such a message.
246
+ */
247
+ export declare const TA_KEEP_MARK = "[ta:keep]";
248
+ /**
249
+ * Where a package gives the daily brief of ta-recall what it has to tell (docs/design/ta-recall.md 4): its own data
250
+ * (TaExtensionHost.setExtensionData) under this key, a {@link TaBriefSource}. ta-recall reads it of every package that
251
+ * is on as it writes a brief, and gives the model the items since the last one, with the package's instruction.
252
+ */
253
+ export declare const TA_BRIEF_SOURCE = "brief";
254
+ /** What a package has for the daily brief (TA_BRIEF_SOURCE). */
255
+ export interface TaBriefSource {
256
+ /** What the items are, in English, for the model: `Posts of the user's Ta friends`. */
257
+ section: string;
258
+ /** What the model does with them, in English: pick some, write a part of its own. */
259
+ instruction: string;
260
+ /** The latest last; those before the last brief are left out. 30 at most are read. */
261
+ items: {
262
+ at: number;
263
+ text: string;
264
+ }[];
265
+ }
266
+ /**
267
+ * pi's custom entry by which an extension says that the turn just ended asks the user to decide (a choice of a card,
268
+ * a question of a tool): `pi.appendEntry(TA_ASK_ENTRY, TaAskUtil.entry(question))`, the model never reads it. The
269
+ * conversation waits for the user (TaSessionInfo.asking) until a message of theirs comes after it, typed or tapped;
270
+ * an entry without a question takes the ask back.
271
+ */
272
+ export declare const TA_ASK_ENTRY = "ta-ask";
273
+ /** What a conversation asks the user to decide, from the last {@link TA_ASK_ENTRY} after their last message. */
274
+ export interface TaAsking {
275
+ /** On one line, cut to a preview's length. */
276
+ question: string;
277
+ /** When it was asked (`Date.now()` time): a page that let it go (dismissed it) knows it by this. */
278
+ at: number;
279
+ }
280
+ /** What TaAskUtil reads of pi's session entries (a custom entry, a message), as a session file has them. */
281
+ export interface TaAskEntryLike {
282
+ type: string;
283
+ customType?: string;
284
+ data?: unknown;
285
+ /** ISO time, as pi writes it. */
286
+ timestamp?: string;
287
+ message?: {
288
+ role?: string;
289
+ };
290
+ }
291
+ export declare namespace TaAskUtil {
292
+ /** The data of an ask: its question on one line, cut to a preview's length. */
293
+ function entry(question: string): {
294
+ question: string;
295
+ };
296
+ /** What the entries of a branch, oldest first, still ask: the last ask after the last message of the user. */
297
+ function asking(entries: readonly TaAskEntryLike[]): TaAsking | undefined;
298
+ /** What is asked after this entry, `asked` what was asked before it: as a file is read line by line. */
299
+ function next(asked: TaAsking | undefined, entry: TaAskEntryLike): TaAsking | undefined;
300
+ }
87
301
  export interface TaFileWrite {
88
302
  /** Absolute, on the machine where the session's tools work. */
89
303
  path: string;
@@ -94,6 +308,8 @@ export interface TaHostRequest {
94
308
  /** The `name` of the package.json. */
95
309
  name: string;
96
310
  resolve(answer: TaHostAnswer): void;
311
+ /** The host calls it as it hears the request, when it answers later: without either the request has nobody to answer. */
312
+ heard?(): void;
97
313
  }
98
314
  export interface TaHostAnswer {
99
315
  host: TaExtensionHost;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TA_WITH_OTHERS_MARK = 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_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
- * `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
7
- * the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
8
- * and the extension should say its tools need `ta serve`.
6
+ * `pi.events.emit(TA_HOST_EVENT, { name, resolve, heard })`. Under `ta serve` `heard` is called as the event
7
+ * is emitted and `resolve` soon after, if the extension asks after loading (on `session_start`, or in a tool);
8
+ * under `ta` alone nobody answers, and the extension should say its tools need `ta serve`.
9
9
  */
10
10
  exports.TA_HOST_EVENT = 'ta:host';
11
11
  /**
@@ -14,23 +14,34 @@ exports.TA_HOST_EVENT = 'ta:host';
14
14
  */
15
15
  var TaHostUtil;
16
16
  (function (TaHostUtil) {
17
+ /** How long the host has to answer once it heard the request; undefined after it. */
18
+ TaHostUtil.WAIT_MS = 1000;
17
19
  /**
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
+ * Asks for the host of the package `name` (TA_HOST_EVENT); undefined when nobody answers: not under `ta serve`.
21
+ * Nobody heard the event as it was emitted: undefined at once, not after WAIT_MS (each of the built-in packages
22
+ * asks as a session starts, and `ta -p` waited a second for several of them in turn).
20
23
  */
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
24
  function reach(events, name, waitMs = TaHostUtil.WAIT_MS) {
24
25
  return new Promise(resolve => {
26
+ let heard = false;
27
+ let answered = false;
25
28
  const timer = setTimeout(() => resolve(undefined), waitMs);
26
29
  const request = {
27
30
  name,
31
+ heard: () => {
32
+ heard = true;
33
+ },
28
34
  resolve: answer => {
35
+ answered = true;
29
36
  clearTimeout(timer);
30
37
  resolve(answer);
31
38
  },
32
39
  };
33
40
  events.emit(exports.TA_HOST_EVENT, request);
41
+ if (!heard && !answered) {
42
+ clearTimeout(timer);
43
+ resolve(undefined);
44
+ }
34
45
  });
35
46
  }
36
47
  TaHostUtil.reach = reach;
@@ -48,10 +59,84 @@ exports.TA_FILE_WRITE_EVENT = 'ta:file-write';
48
59
  * double first opened. The server side of a package that sends to the double reads it there.
49
60
  */
50
61
  exports.TA_DOUBLE_FILE = { name: '@celljs/ta-web', key: 'assistant.file' };
62
+ /**
63
+ * Where the web client keeps the tasks the double handed out: in the data of packages, under this name and key; an
64
+ * array of `{ sessionId, sessionFile?, takenOver?, removed? }` among other fields. The double tells the user of these
65
+ * itself, so a package that tells of conversations (ta-notify) leaves them to it unless they ask.
66
+ */
67
+ exports.TA_DOUBLE_TASKS = { name: '@celljs/ta-web', key: 'assistant.tasks' };
68
+ /**
69
+ * Where ta-notify keeps what conversations and packages tell the user, for the pages and Ta Desktop: in the data of
70
+ * packages, under this name and key, the latest last ({@link TaNotice}[]).
71
+ */
72
+ exports.TA_NOTICES = { name: '@celljs/ta-notify', key: 'notices' };
51
73
  /**
52
74
  * In the system prompt of a session that speaks with other people for the user: their double in a room of Ta
53
75
  * (ta-rooms, docs/design/ta-link.md 4). An extension that brings in what is the user's own (their other
54
76
  * conversations, what they asked before) leaves such a session out: what it says goes to others.
55
77
  */
56
78
  exports.TA_WITH_OTHERS_MARK = '[ta:speaks-with-others]';
79
+ /**
80
+ * Starts the `<context>` of a message of the user that asks Ta to keep how a conversation got its work done, so that it
81
+ * need not be told again (Keep of ta-recall, in the + of the message box): Ta picks the form that fits. A package that
82
+ * keeps work a way of its own (ta-cron: a scheduled task) tells the model about it, in a section of the system prompt of
83
+ * its own, on the turns of such a message.
84
+ */
85
+ exports.TA_KEEP_MARK = '[ta:keep]';
86
+ /**
87
+ * Where a package gives the daily brief of ta-recall what it has to tell (docs/design/ta-recall.md 4): its own data
88
+ * (TaExtensionHost.setExtensionData) under this key, a {@link TaBriefSource}. ta-recall reads it of every package that
89
+ * is on as it writes a brief, and gives the model the items since the last one, with the package's instruction.
90
+ */
91
+ exports.TA_BRIEF_SOURCE = 'brief';
92
+ /**
93
+ * pi's custom entry by which an extension says that the turn just ended asks the user to decide (a choice of a card,
94
+ * a question of a tool): `pi.appendEntry(TA_ASK_ENTRY, TaAskUtil.entry(question))`, the model never reads it. The
95
+ * conversation waits for the user (TaSessionInfo.asking) until a message of theirs comes after it, typed or tapped;
96
+ * an entry without a question takes the ask back.
97
+ */
98
+ exports.TA_ASK_ENTRY = 'ta-ask';
99
+ var TaAskUtil;
100
+ (function (TaAskUtil) {
101
+ const LENGTH = 120;
102
+ /** The data of an ask: its question on one line, cut to a preview's length. */
103
+ function entry(question) {
104
+ const line = question.replace(/\s+/g, ' ').trim();
105
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
106
+ }
107
+ TaAskUtil.entry = entry;
108
+ /** What the entries of a branch, oldest first, still ask: the last ask after the last message of the user. */
109
+ function asking(entries) {
110
+ var _a;
111
+ for (let i = entries.length - 1; i >= 0; i--) {
112
+ const entry = entries[i];
113
+ if (entry.type === 'message' && ((_a = entry.message) === null || _a === void 0 ? void 0 : _a.role) === 'user') {
114
+ return undefined;
115
+ }
116
+ if (entry.type === 'custom' && entry.customType === exports.TA_ASK_ENTRY) {
117
+ return read(entry);
118
+ }
119
+ }
120
+ return undefined;
121
+ }
122
+ TaAskUtil.asking = asking;
123
+ /** What is asked after this entry, `asked` what was asked before it: as a file is read line by line. */
124
+ function next(asked, entry) {
125
+ var _a;
126
+ if (entry.type === 'message' && ((_a = entry.message) === null || _a === void 0 ? void 0 : _a.role) === 'user') {
127
+ return undefined;
128
+ }
129
+ return entry.type === 'custom' && entry.customType === exports.TA_ASK_ENTRY ? read(entry) : asked;
130
+ }
131
+ TaAskUtil.next = next;
132
+ function read(found) {
133
+ var _a;
134
+ const question = (_a = found.data) === null || _a === void 0 ? void 0 : _a.question;
135
+ if (typeof question !== 'string' || !question.trim()) {
136
+ return undefined;
137
+ }
138
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
139
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
140
+ }
141
+ })(TaAskUtil || (exports.TaAskUtil = TaAskUtil = {}));
57
142
  //# sourceMappingURL=ta-extension-host.js.map
@@ -2,6 +2,8 @@ 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
4
  import type { TaRoomEvent } from './room-protocol';
5
+ import type { TaAsking } from './ta-extension-host';
6
+ import type { TaMemberInfo } from './team-protocol';
5
7
  export declare const TaServer: unique symbol;
6
8
  export declare const TaClient: unique symbol;
7
9
  /** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
@@ -16,6 +18,11 @@ export interface TaServeInfo {
16
18
  token: string;
17
19
  pid: number;
18
20
  }
21
+ /**
22
+ * The type of the custom message `ta serve` adds to a conversation whose run a restart of it cut off, when it opens
23
+ * the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
24
+ */
25
+ export declare const TA_RESUME_MESSAGE = "ta-resume";
19
26
  /** What a client needs to know of the server before it opens a session. */
20
27
  export interface TaServerInfo {
21
28
  /** The version of ta. */
@@ -31,6 +38,8 @@ export interface TaServerInfo {
31
38
  host: string;
32
39
  /** The home directory of that user there: what `~` of a path a reply names is. None from a ta serve of before. */
33
40
  home?: string;
41
+ /** The page is of one the user let in (docs/design/ta-team.md), not the user: who, and as what. */
42
+ member?: TaMemberInfo;
34
43
  }
35
44
  /** The stable `code` of each failure of a {@link TaServer} call. */
36
45
  export declare const TaErrorCode: {
@@ -53,6 +62,10 @@ export declare const TaErrorCode: {
53
62
  readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
54
63
  /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
55
64
  readonly ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED';
65
+ /** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
66
+ readonly FORBIDDEN: 'CELL_TA_FORBIDDEN';
67
+ /** 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. */
68
+ readonly LIMIT: 'CELL_TA_LIMIT';
56
69
  /** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
57
70
  readonly CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST';
58
71
  };
@@ -159,6 +172,11 @@ export interface TaSessionInfo {
159
172
  * session needs them. None from a Ta service of before.
160
173
  */
161
174
  waiting?: boolean;
175
+ /**
176
+ * Its last turn asked the user to decide and no message of theirs came since (TA_ASK_ENTRY): a list shows that
177
+ * the conversation waits for them, after they saw it too. None from a Ta service of before.
178
+ */
179
+ asking?: TaAsking;
162
180
  messageCount: number;
163
181
  /** Number of clients attached. */
164
182
  attached: number;
@@ -187,6 +205,8 @@ export interface TaSavedSessionInfo {
187
205
  updatedAt: number;
188
206
  /** The group it was opened for (TaOpenSessionOptions.group): its package opens it again, with its role. */
189
207
  group?: string;
208
+ /** TaSessionInfo.asking. */
209
+ asking?: TaAsking;
190
210
  }
191
211
  /**
192
212
  * Which saved conversations a list reads, by when they were updated (TaSavedSessionInfo.updatedAt): a list
@@ -215,6 +235,27 @@ export declare namespace TaMessageContext {
215
235
  function wrap(context: string, message: string): string;
216
236
  /** The message without its context: what the user sees of it. */
217
237
  function strip(message: string): string;
238
+ /** The context of the message, without its tags; undefined without one. */
239
+ function read(message: string): string | undefined;
240
+ }
241
+ /** Where a message of the user came from, when not from what they typed: see {@link TaMessageSource}. */
242
+ export interface TaMessageFrom {
243
+ /** The name of the package that sent it, or TaMessageSource.DOUBLE. */
244
+ from: string;
245
+ /** What the package says of it besides, in a few words (the channel and who spoke in it). */
246
+ detail?: string;
247
+ }
248
+ /**
249
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
250
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
251
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
252
+ */
253
+ export declare namespace TaMessageSource {
254
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
255
+ const DOUBLE = "ta:double";
256
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
257
+ function mark(message: string, from: string, detail?: string): string;
258
+ function of(message: string): TaMessageFrom | undefined;
218
259
  }
219
260
  /**
220
261
  * 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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_RESUME_MESSAGE = 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. */
@@ -9,6 +9,11 @@ exports.TA_SERVER_SERVICE = 'TaServer';
9
9
  exports.TA_CLIENT_SERVICE = 'TaClient';
10
10
  /** The file `ta serve` writes in the agent directory, readable only by its user. */
11
11
  exports.TA_SERVE_FILE = 'serve.json';
12
+ /**
13
+ * The type of the custom message `ta serve` adds to a conversation whose run a restart of it cut off, when it opens
14
+ * the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
15
+ */
16
+ exports.TA_RESUME_MESSAGE = 'ta-resume';
12
17
  /** The stable `code` of each failure of a {@link TaServer} call. */
13
18
  exports.TaErrorCode = {
14
19
  SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
@@ -30,6 +35,10 @@ exports.TaErrorCode = {
30
35
  NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
31
36
  /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
32
37
  ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
38
+ /** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
39
+ FORBIDDEN: 'CELL_TA_FORBIDDEN',
40
+ /** 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. */
41
+ LIMIT: 'CELL_TA_LIMIT',
33
42
  /** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
34
43
  CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST',
35
44
  };
@@ -73,7 +82,41 @@ var TaMessageContext;
73
82
  return message.replace(BLOCK, '');
74
83
  }
75
84
  TaMessageContext.strip = strip;
85
+ /** The context of the message, without its tags; undefined without one. */
86
+ function read(message) {
87
+ var _a;
88
+ const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
89
+ return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
90
+ }
91
+ TaMessageContext.read = read;
76
92
  })(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
93
+ /**
94
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
95
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
96
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
97
+ */
98
+ var TaMessageSource;
99
+ (function (TaMessageSource) {
100
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
101
+ TaMessageSource.DOUBLE = 'ta:double';
102
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
103
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
104
+ function mark(message, from, detail) {
105
+ if (/^[/!]/.test(message) || of(message)) {
106
+ return message;
107
+ }
108
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
109
+ const context = TaMessageContext.read(message);
110
+ return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
111
+ }
112
+ TaMessageSource.mark = mark;
113
+ function of(message) {
114
+ const context = TaMessageContext.read(message);
115
+ const match = context === undefined ? null : LINE.exec(context);
116
+ return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
117
+ }
118
+ TaMessageSource.of = of;
119
+ })(TaMessageSource || (exports.TaMessageSource = TaMessageSource = {}));
77
120
  /**
78
121
  * 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
79
122
  * the image was before it made it smaller, and what it was converted from. Clients leave them out.