@celljs/ta-host 4.16.0 → 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 (75) hide show
  1. package/esm/node/app-commands.d.ts +111 -0
  2. package/esm/node/app-commands.js +629 -0
  3. package/esm/node/delegate-extension.d.ts +11 -0
  4. package/esm/node/delegate-extension.js +33 -0
  5. package/esm/node/directory-relocator.d.ts +49 -0
  6. package/esm/node/directory-relocator.js +267 -0
  7. package/esm/node/extension-providers.d.ts +16 -1
  8. package/esm/node/extension-providers.js +23 -3
  9. package/esm/node/index.d.ts +6 -0
  10. package/esm/node/index.js +6 -0
  11. package/esm/node/keep-awake.d.ts +5 -1
  12. package/esm/node/keep-awake.js +18 -2
  13. package/esm/node/message-page.d.ts +6 -1
  14. package/esm/node/message-page.js +50 -2
  15. package/esm/node/package-hosts.d.ts +6 -0
  16. package/esm/node/package-hosts.js +35 -0
  17. package/esm/node/package-webhooks.d.ts +26 -0
  18. package/esm/node/package-webhooks.js +101 -0
  19. package/esm/node/page-book.d.ts +48 -0
  20. package/esm/node/page-book.js +117 -0
  21. package/esm/node/relay-bridge.d.ts +2 -0
  22. package/esm/node/relay-bridge.js +35 -1
  23. package/esm/node/rooms-bridge.d.ts +3 -0
  24. package/esm/node/rooms-bridge.js +4 -0
  25. package/esm/node/session-info-util.d.ts +3 -1
  26. package/esm/node/session-info-util.js +32 -6
  27. package/esm/node/ta-server-impl.d.ts +5 -1
  28. package/esm/node/ta-server-impl.js +22 -0
  29. package/esm/node/ta-session-factory.d.ts +13 -1
  30. package/esm/node/ta-session-factory.js +39 -4
  31. package/esm/node/ta-session.d.ts +2 -0
  32. package/esm/node/ta-session.js +1 -0
  33. package/esm/node/team/team-calls.js +22 -0
  34. package/esm/node/voice-bridge.d.ts +68 -0
  35. package/esm/node/voice-bridge.js +273 -0
  36. package/esm/node/voices-file.d.ts +33 -0
  37. package/esm/node/voices-file.js +89 -0
  38. package/lib/node/app-commands.d.ts +112 -0
  39. package/lib/node/app-commands.js +633 -0
  40. package/lib/node/delegate-extension.d.ts +12 -0
  41. package/lib/node/delegate-extension.js +37 -0
  42. package/lib/node/directory-relocator.d.ts +50 -0
  43. package/lib/node/directory-relocator.js +270 -0
  44. package/lib/node/extension-providers.d.ts +16 -1
  45. package/lib/node/extension-providers.js +23 -3
  46. package/lib/node/index.d.ts +6 -0
  47. package/lib/node/index.js +6 -0
  48. package/lib/node/keep-awake.d.ts +5 -1
  49. package/lib/node/keep-awake.js +18 -2
  50. package/lib/node/message-page.d.ts +6 -1
  51. package/lib/node/message-page.js +50 -2
  52. package/lib/node/package-hosts.d.ts +6 -0
  53. package/lib/node/package-hosts.js +35 -0
  54. package/lib/node/package-webhooks.d.ts +27 -0
  55. package/lib/node/package-webhooks.js +104 -0
  56. package/lib/node/page-book.d.ts +49 -0
  57. package/lib/node/page-book.js +120 -0
  58. package/lib/node/relay-bridge.d.ts +2 -0
  59. package/lib/node/relay-bridge.js +34 -0
  60. package/lib/node/rooms-bridge.d.ts +3 -0
  61. package/lib/node/rooms-bridge.js +4 -0
  62. package/lib/node/session-info-util.d.ts +3 -1
  63. package/lib/node/session-info-util.js +31 -5
  64. package/lib/node/ta-server-impl.d.ts +5 -1
  65. package/lib/node/ta-server-impl.js +22 -0
  66. package/lib/node/ta-session-factory.d.ts +13 -1
  67. package/lib/node/ta-session-factory.js +38 -3
  68. package/lib/node/ta-session.d.ts +2 -0
  69. package/lib/node/ta-session.js +1 -0
  70. package/lib/node/team/team-calls.js +22 -0
  71. package/lib/node/voice-bridge.d.ts +69 -0
  72. package/lib/node/voice-bridge.js +274 -0
  73. package/lib/node/voices-file.d.ts +34 -0
  74. package/lib/node/voices-file.js +93 -0
  75. package/package.json +10 -10
@@ -45,13 +45,60 @@ var MessagePage;
45
45
  return start;
46
46
  }
47
47
  MessagePage.start = start;
48
+ /**
49
+ * A message of the user that the agent was given on the way, after the result of a tool it was written before:
50
+ * a step of the turn, not the start of another (as the web page reads it).
51
+ */
52
+ function steered(messages, index) {
53
+ var _a;
54
+ if (role(messages[index]) !== 'user') {
55
+ return false;
56
+ }
57
+ for (let before = index - 1; before >= 0; before--) {
58
+ const was = (_a = role(messages[before])) !== null && _a !== void 0 ? _a : '';
59
+ if (was === 'user') {
60
+ return steered(messages, before);
61
+ }
62
+ if (TURN_ROLES.has(was)) {
63
+ const at = timestamp(messages[index]);
64
+ const came = timestamp(messages[before]);
65
+ return was === 'toolResult' && at !== undefined && came !== undefined && at < came;
66
+ }
67
+ }
68
+ return false;
69
+ }
70
+ /**
71
+ * When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
72
+ * is a step of it): the message of the user that asked for the turn.
73
+ */
74
+ function head(messages, from) {
75
+ var _a;
76
+ let first = from;
77
+ while (first < messages.length && role(messages[first]) !== 'user' && !TURN_ROLES.has((_a = role(messages[first])) !== null && _a !== void 0 ? _a : '')) {
78
+ first++;
79
+ }
80
+ if (from <= 0 || first >= messages.length || (role(messages[first]) === 'user' && !steered(messages, first))) {
81
+ return undefined;
82
+ }
83
+ for (let index = from - 1; index >= 0; index--) {
84
+ if (role(messages[index]) === 'user' && !steered(messages, index)) {
85
+ return { index, message: messages[index] };
86
+ }
87
+ }
88
+ return undefined;
89
+ }
90
+ MessagePage.head = head;
48
91
  /** The latest part of a conversation, or all of it without a budget. */
49
92
  function recent(conversation, budget) {
50
93
  if (!budget || budget <= 0) {
51
94
  return conversation;
52
95
  }
53
96
  const from = start(conversation.messages, conversation.messages.length, budget);
54
- return from === 0 ? conversation : { ...conversation, messages: conversation.messages.slice(from), start: from };
97
+ if (from === 0) {
98
+ return conversation;
99
+ }
100
+ const turn = head(conversation.messages, from);
101
+ return { ...conversation, messages: conversation.messages.slice(from), start: from, ...(turn ? { head: turn } : {}) };
55
102
  }
56
103
  MessagePage.recent = recent;
57
104
  /** The part before message `before`, found again by its timestamp if messages came or went before it. */
@@ -67,7 +114,8 @@ var MessagePage;
67
114
  }
68
115
  }
69
116
  const from = start(messages, end, Math.max(1, budget));
70
- return { messages: messages.slice(from, end), start: from, found: true };
117
+ const turn = head(messages, from);
118
+ return { messages: messages.slice(from, end), start: from, found: true, ...(turn ? { head: turn } : {}) };
71
119
  }
72
120
  MessagePage.before = before;
73
121
  })(MessagePage || (exports.MessagePage = MessagePage = {}));
@@ -1,13 +1,16 @@
1
1
  import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { type TaExtensionHost, type TaHostAnswer, type TaHostSessionEvent, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
4
+ import { TaAppCommands } from './app-commands';
4
5
  import { ExtensionDataStore } from './extension-data';
5
6
  import { TaPresenceBook, TaSessionRegistry } from './host-protocol';
7
+ import { TaPageBook } from './page-book';
6
8
  import { type RelayBridge } from './relay-bridge';
7
9
  import { PiDirectories } from './remote/remote-protocol';
8
10
  import { type RoomsBridge } from './rooms-bridge';
9
11
  import { TaSettingsStore } from './settings-store';
10
12
  import { TaHostTeamProvider } from './team/team-protocol';
13
+ import { type VoiceBridge } from './voice-bridge';
11
14
  export declare const PackageHosts: unique symbol;
12
15
  /**
13
16
  * The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
@@ -54,9 +57,12 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
54
57
  protected readonly packages: TaPackageServer;
55
58
  protected readonly relay: RelayBridge;
56
59
  protected readonly roomsBridge: RoomsBridge;
60
+ protected readonly voiceBridge: VoiceBridge;
57
61
  protected readonly settings: TaSettingsStore;
58
62
  protected readonly sessions: TaSessionRegistry;
59
63
  protected readonly presenceBook: TaPresenceBook;
64
+ protected readonly appCommands: TaAppCommands;
65
+ protected readonly pageBook: TaPageBook;
60
66
  protected readonly teamProvider: TaHostTeamProvider;
61
67
  protected readonly running: Map<string, Running>;
62
68
  protected extensionHost?: TaExtensionHost;
@@ -19,14 +19,18 @@ const core_1 = require("@celljs/core");
19
19
  const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
20
20
  const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
21
21
  const ta_protocol_1 = require("@celljs/ta-protocol");
22
+ const app_commands_1 = require("./app-commands");
22
23
  const extension_data_1 = require("./extension-data");
23
24
  const host_protocol_1 = require("./host-protocol");
25
+ const page_book_1 = require("./page-book");
24
26
  const relay_bridge_1 = require("./relay-bridge");
25
27
  const remote_protocol_1 = require("./remote/remote-protocol");
26
28
  const rooms_bridge_1 = require("./rooms-bridge");
29
+ const session_catalog_1 = require("./session-catalog");
27
30
  const settings_store_1 = require("./settings-store");
28
31
  const ta_errors_1 = require("./ta-errors");
29
32
  const team_protocol_1 = require("./team/team-protocol");
33
+ const voice_bridge_1 = require("./voice-bridge");
30
34
  exports.PackageHosts = Symbol('PackageHosts');
31
35
  var PackageHostUtil;
32
36
  (function (PackageHostUtil) {
@@ -158,6 +162,7 @@ let PackageHostsImpl = class PackageHostsImpl {
158
162
  var _a, _b;
159
163
  const running = this.running.get(name);
160
164
  this.running.delete(name);
165
+ this.appCommands.dropOwner(name);
161
166
  try {
162
167
  await ((_b = (_a = (await (running === null || running === void 0 ? void 0 : running.service))) === null || _a === void 0 ? void 0 : _a.dispose) === null || _b === void 0 ? void 0 : _b.call(_a));
163
168
  }
@@ -171,6 +176,12 @@ let PackageHostsImpl = class PackageHostsImpl {
171
176
  const mark = (input) => ({ ...input, message: ta_protocol_1.TaMessageSource.mark(input.message, name) });
172
177
  return {
173
178
  ...host,
179
+ commands: { ...host.commands, register: command => this.appCommands.registerOf(name, command) },
180
+ // A package asks the requests of its own web extension (`pi.ui.answer`), named after it.
181
+ pages: {
182
+ ask: (kind, payload, options = {}) => this.pageBook.ask(this.pageBook.principalOf(options), `${name}/${kind}`, payload, options.timeoutMs),
183
+ has: (kind, options = {}) => this.pageBook.has(this.pageBook.principalOf(options), `${name}/${kind}`),
184
+ },
174
185
  prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
175
186
  followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
176
187
  };
@@ -191,7 +202,9 @@ let PackageHostsImpl = class PackageHostsImpl {
191
202
  shares: this.relay.shares,
192
203
  rooms: this.roomsBridge.rooms,
193
204
  relays: this.relay.extensionRelays,
205
+ voices: this.voiceBridge.extensionVoices,
194
206
  sessionMessages: file => this.sessionMessages(file),
207
+ sessionRole: async (file) => session_catalog_1.SessionCatalogUtil.roleOf((await ai_coding_agent_1.PiSdkUtil.load()).SessionManager.open(file).getEntries()),
195
208
  createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
196
209
  getServerInfo: () => server.getServerInfo(),
197
210
  listSessions: () => server.listSessions(),
@@ -203,6 +216,7 @@ let PackageHostsImpl = class PackageHostsImpl {
203
216
  abort: sessionId => server.abort(sessionId),
204
217
  getState: sessionId => server.getState(sessionId),
205
218
  getLastAssistantText: sessionId => server.getLastAssistantText(sessionId),
219
+ relocateDirectory: (from, to) => server.relocateDirectory(from, to),
206
220
  getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
207
221
  setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
208
222
  onExtensionData: listener => this.data.onChange(listener),
@@ -214,6 +228,15 @@ let PackageHostsImpl = class PackageHostsImpl {
214
228
  }),
215
229
  presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt, people: this.presenceBook.everyone() }),
216
230
  team: this.teamProvider.team,
231
+ commands: {
232
+ list: () => this.appCommands.list(),
233
+ run: (id, input, options) => this.appCommands.run(id, input, options),
234
+ register: command => this.appCommands.register(command),
235
+ },
236
+ pages: {
237
+ ask: () => Promise.reject(new Error('Only a package asks a page: through its own host.')),
238
+ has: () => false,
239
+ },
217
240
  installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
218
241
  removePackage: (id, cwd) => packages.removePackage(id, cwd),
219
242
  updateSettings: update => this.settings.rewriteUser(update),
@@ -277,6 +300,10 @@ __decorate([
277
300
  (0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
278
301
  __metadata("design:type", Function)
279
302
  ], PackageHostsImpl.prototype, "roomsBridge", void 0);
303
+ __decorate([
304
+ (0, core_1.Autowired)({ id: voice_bridge_1.VOICE_BRIDGE, detached: true }),
305
+ __metadata("design:type", Function)
306
+ ], PackageHostsImpl.prototype, "voiceBridge", void 0);
280
307
  __decorate([
281
308
  (0, core_1.Autowired)({ id: settings_store_1.TaSettingsStore, detached: true }),
282
309
  __metadata("design:type", Object)
@@ -289,6 +316,14 @@ __decorate([
289
316
  (0, core_1.Autowired)({ id: host_protocol_1.TaPresenceBook, detached: true }),
290
317
  __metadata("design:type", Object)
291
318
  ], PackageHostsImpl.prototype, "presenceBook", void 0);
319
+ __decorate([
320
+ (0, core_1.Autowired)({ id: app_commands_1.TaAppCommands, detached: true }),
321
+ __metadata("design:type", Object)
322
+ ], PackageHostsImpl.prototype, "appCommands", void 0);
323
+ __decorate([
324
+ (0, core_1.Autowired)({ id: page_book_1.TaPageBook, detached: true }),
325
+ __metadata("design:type", Object)
326
+ ], PackageHostsImpl.prototype, "pageBook", void 0);
292
327
  __decorate([
293
328
  (0, core_1.Autowired)({ id: team_protocol_1.TaHostTeamProvider, detached: true }),
294
329
  __metadata("design:type", Object)
@@ -0,0 +1,27 @@
1
+ import type { IncomingMessage } from 'node:http';
2
+ import { type Context, Middleware } from '@celljs/web/lib/node';
3
+ import { PackageHosts } from './package-hosts';
4
+ /** Where ta serve takes the webhooks of packages: the directory name of a package, then its own path. */
5
+ export declare const WEBHOOK_PATH = "/api/hooks/";
6
+ export declare namespace PackageWebhookUtil {
7
+ /** The package and its path of a request to a webhook; undefined for another request. */
8
+ function target(request: Pick<IncomingMessage, 'url'>): {
9
+ name: string;
10
+ path: string;
11
+ } | undefined;
12
+ /** The body as text; undefined when it is larger than TA_WEBHOOK_MAX_BYTES. */
13
+ function body(request: IncomingMessage): Promise<string | undefined>;
14
+ }
15
+ /**
16
+ * The webhooks of the packages that come with Ta (TaPackageService.webhook): a POST to `/api/hooks/<package>/<path>`
17
+ * goes to its host without the token of ta serve; the package checks the secret of its path. Anything else (another
18
+ * method, a package without a webhook, a secret it does not know) is a 404 that says nothing more.
19
+ */
20
+ export declare class PackageWebhooks implements Middleware {
21
+ /** Before TaAccess, which would ask for the token. */
22
+ readonly priority: number;
23
+ protected readonly hosts: PackageHosts;
24
+ protected readonly host?: string;
25
+ handle(ctx: Context, next: () => Promise<void>): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=package-webhooks.d.ts.map
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PackageWebhooks = exports.PackageWebhookUtil = exports.WEBHOOK_PATH = void 0;
13
+ const core_1 = require("@celljs/core");
14
+ const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
15
+ const ta_protocol_1 = require("@celljs/ta-protocol");
16
+ const node_1 = require("@celljs/web/lib/node");
17
+ const package_hosts_1 = require("./package-hosts");
18
+ const ta_access_1 = require("./ta-access");
19
+ /** Where ta serve takes the webhooks of packages: the directory name of a package, then its own path. */
20
+ exports.WEBHOOK_PATH = '/api/hooks/';
21
+ var PackageWebhookUtil;
22
+ (function (PackageWebhookUtil) {
23
+ /** The package and its path of a request to a webhook; undefined for another request. */
24
+ function target(request) {
25
+ var _a;
26
+ const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split('?')[0];
27
+ if (!path.startsWith(exports.WEBHOOK_PATH)) {
28
+ return undefined;
29
+ }
30
+ const [directory, ...rest] = path.slice(exports.WEBHOOK_PATH.length).split('/');
31
+ const name = ta_packages_1.TaPackages.BUILTIN.find(builtin => ta_packages_1.TaPackages.directoryName(builtin) === directory);
32
+ return name ? { name, path: rest.map(part => decodeURIComponent(part)).join('/') } : { name: '', path: '' };
33
+ }
34
+ PackageWebhookUtil.target = target;
35
+ /** The body as text; undefined when it is larger than TA_WEBHOOK_MAX_BYTES. */
36
+ async function body(request) {
37
+ const chunks = [];
38
+ let size = 0;
39
+ for await (const chunk of request) {
40
+ size += chunk.length;
41
+ if (size > ta_protocol_1.TA_WEBHOOK_MAX_BYTES) {
42
+ return undefined;
43
+ }
44
+ chunks.push(chunk);
45
+ }
46
+ return Buffer.concat(chunks).toString('utf8');
47
+ }
48
+ PackageWebhookUtil.body = body;
49
+ })(PackageWebhookUtil || (exports.PackageWebhookUtil = PackageWebhookUtil = {}));
50
+ function end(response, status, value) {
51
+ response.statusCode = status;
52
+ response.setHeader('Content-Type', 'application/json; charset=utf-8');
53
+ response.end(JSON.stringify(value));
54
+ }
55
+ /**
56
+ * The webhooks of the packages that come with Ta (TaPackageService.webhook): a POST to `/api/hooks/<package>/<path>`
57
+ * goes to its host without the token of ta serve; the package checks the secret of its path. Anything else (another
58
+ * method, a package without a webhook, a secret it does not know) is a 404 that says nothing more.
59
+ */
60
+ let PackageWebhooks = class PackageWebhooks {
61
+ constructor() {
62
+ /** Before TaAccess, which would ask for the token. */
63
+ this.priority = ta_access_1.ACCESS_MIDDLEWARE_PRIORITY + 2;
64
+ }
65
+ async handle(ctx, next) {
66
+ const request = ctx.request;
67
+ const target = PackageWebhookUtil.target(request);
68
+ if (!target) {
69
+ await next();
70
+ return;
71
+ }
72
+ const response = ctx.response;
73
+ // A page that rebinds its domain to a ta serve of 127.0.0.1 reaches nothing, as with TaAccess.
74
+ if (!target.name || request.method !== 'POST' || (ta_access_1.TaAccessUtil.isLoopbackHost(this.host) && !ta_access_1.TaAccessUtil.isLoopbackHost(request.headers.host))) {
75
+ end(response, 404, { error: 'Not found' });
76
+ return;
77
+ }
78
+ const body = await PackageWebhookUtil.body(request);
79
+ if (body === undefined) {
80
+ end(response, 413, { error: 'Too large' });
81
+ return;
82
+ }
83
+ try {
84
+ const answer = await this.hosts.call(target.name, 'webhook', [{ path: target.path, body, contentType: request.headers['content-type'] }]);
85
+ end(response, 202, answer !== null && answer !== void 0 ? answer : { ok: true });
86
+ }
87
+ catch (_a) {
88
+ end(response, 404, { error: 'Not found' });
89
+ }
90
+ }
91
+ };
92
+ exports.PackageWebhooks = PackageWebhooks;
93
+ __decorate([
94
+ (0, core_1.Autowired)(package_hosts_1.PackageHosts),
95
+ __metadata("design:type", Object)
96
+ ], PackageWebhooks.prototype, "hosts", void 0);
97
+ __decorate([
98
+ (0, core_1.Value)('server.host'),
99
+ __metadata("design:type", String)
100
+ ], PackageWebhooks.prototype, "host", void 0);
101
+ exports.PackageWebhooks = PackageWebhooks = __decorate([
102
+ (0, core_1.Component)(node_1.Middleware)
103
+ ], PackageWebhooks);
104
+ //# sourceMappingURL=package-webhooks.js.map
@@ -0,0 +1,49 @@
1
+ import { type RpcConnection } from '@celljs/rpc/lib/node';
2
+ import { type TaPageAskOptions, type TaPageInfo, TaPageServer } from '@celljs/ta-protocol';
3
+ import { TaHostTeamProvider, TaPrincipals } from './team/team-protocol';
4
+ export declare const TaPageBook: unique symbol;
5
+ /** The pages that answer requests (TaPageServer.attach), by connection, in memory only. */
6
+ export interface TaPageBook {
7
+ attach(connection: RpcConnection, info: TaPageInfo): void;
8
+ /** Asks the page of `principal` that answers `kind` (PageChoice.pick) and resolves to its answer. */
9
+ ask(principal: string, kind: string, payload: unknown, timeoutMs?: number): Promise<unknown>;
10
+ has(principal: string, kind: string): boolean;
11
+ /** Whom a package's request is for: who asked the run of the session file, or the principal given. */
12
+ principalOf(options: TaPageAskOptions): string;
13
+ }
14
+ /** A page as the book keeps it. */
15
+ export interface PageEntry {
16
+ principal: string;
17
+ info: TaPageInfo;
18
+ /** `Date.now()` time it was last said active, or attached. */
19
+ activeAt: number;
20
+ }
21
+ export declare namespace PageChoice {
22
+ /**
23
+ * The page to ask among those of one person that answer the kind: the one in front of them, the latest touched of
24
+ * those; else the window of Ta Desktop, kept while closed; else the latest touched.
25
+ */
26
+ function pick<T extends PageEntry>(entries: readonly T[]): T | undefined;
27
+ /** What a page said of itself, made safe: only strings of kinds, a device it knows. */
28
+ function clean(info: TaPageInfo | undefined): TaPageInfo;
29
+ }
30
+ export declare class DefaultTaPageBook implements TaPageBook {
31
+ protected readonly principals: TaPrincipals;
32
+ protected readonly teamProvider: TaHostTeamProvider;
33
+ protected readonly entries: Map<RpcConnection, PageEntry & {
34
+ connection: RpcConnection;
35
+ }>;
36
+ attach(connection: RpcConnection, info: TaPageInfo): void;
37
+ ask(principal: string, kind: string, payload: unknown, timeoutMs?: number): Promise<unknown>;
38
+ has(principal: string, kind: string): boolean;
39
+ principalOf(options: TaPageAskOptions): string;
40
+ protected of(principal: string, kind: string): (PageEntry & {
41
+ connection: RpcConnection;
42
+ })[];
43
+ }
44
+ /** A page says which requests it answers (TaPageServer). */
45
+ export declare class TaPageServerImpl implements TaPageServer {
46
+ protected readonly book: TaPageBook;
47
+ attach(info: TaPageInfo): Promise<void>;
48
+ }
49
+ //# sourceMappingURL=page-book.d.ts.map
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TaPageServerImpl = exports.DefaultTaPageBook = exports.PageChoice = exports.TaPageBook = void 0;
13
+ const core_1 = require("@celljs/core");
14
+ const rpc_1 = require("@celljs/rpc");
15
+ const node_1 = require("@celljs/rpc/lib/node");
16
+ const ta_protocol_1 = require("@celljs/ta-protocol");
17
+ const ta_errors_1 = require("./ta-errors");
18
+ const team_protocol_1 = require("./team/team-protocol");
19
+ exports.TaPageBook = Symbol('TaPageBook');
20
+ var PageChoice;
21
+ (function (PageChoice) {
22
+ /**
23
+ * The page to ask among those of one person that answer the kind: the one in front of them, the latest touched of
24
+ * those; else the window of Ta Desktop, kept while closed; else the latest touched.
25
+ */
26
+ function pick(entries) {
27
+ var _a, _b;
28
+ const latest = (list) => list.reduce((best, one) => (!best || one.activeAt > best.activeAt ? one : best), undefined);
29
+ return (_b = (_a = latest(entries.filter(entry => entry.info.visible))) !== null && _a !== void 0 ? _a : latest(entries.filter(entry => entry.info.desktop))) !== null && _b !== void 0 ? _b : latest(entries);
30
+ }
31
+ PageChoice.pick = pick;
32
+ /** What a page said of itself, made safe: only strings of kinds, a device it knows. */
33
+ function clean(info) {
34
+ const kinds = Array.isArray(info === null || info === void 0 ? void 0 : info.kinds) ? info.kinds.filter(kind => typeof kind === 'string' && kind.length <= 100).slice(0, 100) : [];
35
+ const device = (info === null || info === void 0 ? void 0 : info.device) === 'phone' || (info === null || info === void 0 ? void 0 : info.device) === 'tablet' ? info.device : 'computer';
36
+ return { kinds, device, ...((info === null || info === void 0 ? void 0 : info.desktop) === true ? { desktop: true } : {}), ...((info === null || info === void 0 ? void 0 : info.visible) === true ? { visible: true } : {}) };
37
+ }
38
+ PageChoice.clean = clean;
39
+ })(PageChoice || (exports.PageChoice = PageChoice = {}));
40
+ let DefaultTaPageBook = class DefaultTaPageBook {
41
+ constructor() {
42
+ this.entries = new Map();
43
+ }
44
+ attach(connection, info) {
45
+ if (connection.closed) {
46
+ return;
47
+ }
48
+ const before = this.entries.get(connection);
49
+ const clean = PageChoice.clean(info);
50
+ this.entries.set(connection, {
51
+ connection,
52
+ principal: this.principals.of(connection),
53
+ info: clean,
54
+ activeAt: (info === null || info === void 0 ? void 0 : info.active) === true || !before ? Date.now() : before.activeAt,
55
+ });
56
+ if (!before) {
57
+ connection.onClose(() => this.entries.delete(connection));
58
+ }
59
+ }
60
+ async ask(principal, kind, payload, timeoutMs = ta_protocol_1.TA_PAGE_ASK_MS) {
61
+ const page = PageChoice.pick(this.of(principal, kind));
62
+ if (!page) {
63
+ throw ta_errors_1.TaErrors.invalidArgument('No page of Ta is open for this.', 'The user opens Ta on a phone or a computer; meanwhile do it without the screen.');
64
+ }
65
+ let timer;
66
+ try {
67
+ return await Promise.race([
68
+ page.connection.client(ta_protocol_1.TaClient).onPageAsk(kind, payload),
69
+ new Promise((_resolve, reject) => {
70
+ timer = setTimeout(() => reject(ta_errors_1.TaErrors.invalidArgument('The page of Ta did not answer in time.', 'Try again in a moment.')), timeoutMs);
71
+ }),
72
+ ]);
73
+ }
74
+ finally {
75
+ clearTimeout(timer);
76
+ }
77
+ }
78
+ has(principal, kind) {
79
+ return this.of(principal, kind).length > 0;
80
+ }
81
+ principalOf(options) {
82
+ var _a;
83
+ if (options.principal) {
84
+ return options.principal;
85
+ }
86
+ const team = this.teamProvider.team;
87
+ const actors = options.sessionFile ? team.actorsOf(options.sessionFile) : [team.current()];
88
+ return (_a = actors.find(actor => actor !== ta_protocol_1.TA_OWNER)) !== null && _a !== void 0 ? _a : ta_protocol_1.TA_OWNER;
89
+ }
90
+ of(principal, kind) {
91
+ return [...this.entries.values()].filter(entry => !entry.connection.closed && entry.principal === principal && entry.info.kinds.includes(kind));
92
+ }
93
+ };
94
+ exports.DefaultTaPageBook = DefaultTaPageBook;
95
+ __decorate([
96
+ (0, core_1.Autowired)(team_protocol_1.TaPrincipals),
97
+ __metadata("design:type", Object)
98
+ ], DefaultTaPageBook.prototype, "principals", void 0);
99
+ __decorate([
100
+ (0, core_1.Autowired)({ id: team_protocol_1.TaHostTeamProvider, detached: true }),
101
+ __metadata("design:type", Object)
102
+ ], DefaultTaPageBook.prototype, "teamProvider", void 0);
103
+ exports.DefaultTaPageBook = DefaultTaPageBook = __decorate([
104
+ (0, core_1.Component)(exports.TaPageBook)
105
+ ], DefaultTaPageBook);
106
+ /** A page says which requests it answers (TaPageServer). */
107
+ let TaPageServerImpl = class TaPageServerImpl {
108
+ async attach(info) {
109
+ this.book.attach(node_1.RpcContext.requireConnection(), info);
110
+ }
111
+ };
112
+ exports.TaPageServerImpl = TaPageServerImpl;
113
+ __decorate([
114
+ (0, core_1.Autowired)(exports.TaPageBook),
115
+ __metadata("design:type", Object)
116
+ ], TaPageServerImpl.prototype, "book", void 0);
117
+ exports.TaPageServerImpl = TaPageServerImpl = __decorate([
118
+ (0, rpc_1.Rpc)(ta_protocol_1.TaPageServer)
119
+ ], TaPageServerImpl);
120
+ //# sourceMappingURL=page-book.js.map
@@ -80,6 +80,8 @@ export declare class TaRelayServerImpl implements TaRelayServer {
80
80
  addStore(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
81
81
  removeRelay(id: string): Promise<void>;
82
82
  chooseRelay(feature: TaRelayFeature, id: string | null): Promise<TaRelays>;
83
+ joinDeployment(url: string): Promise<TaRelays>;
84
+ leaveDeployment(): Promise<TaRelays>;
83
85
  probeRelay(idOrUrl: string): Promise<TaRelayProbe>;
84
86
  /** A change of relays.json; what it refuses is said as the errors of Ta. */
85
87
  protected relaysCall<T>(change: () => T): T;
@@ -241,6 +241,7 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
241
241
  const url = node_1.RelayServiceUtil.isRelay(service) ? service.url : undefined;
242
242
  return [feature, service.id || ((_a = services.find(each => each.type === 'ta-relay' && each.url === url)) === null || _a === void 0 ? void 0 : _a.id) || ''];
243
243
  }));
244
+ const deployment = this.relays.deployment(config);
244
245
  const drives = node_1.RelayServiceUtil.drives().filter(drive => !services.some(service => service.type === 'folder' && service.path === drive.path));
245
246
  const types = [...this.types].map(([type, { title, hint, icon, options }]) => ({
246
247
  type,
@@ -256,6 +257,7 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
256
257
  ...(drives.length ? { drives } : {}),
257
258
  ...(types.length ? { types } : {}),
258
259
  ...(error ? { error } : {}),
260
+ ...(deployment ? { deployment } : {}),
259
261
  };
260
262
  }
261
263
  /** The store of a service of a type a package registered. */
@@ -427,6 +429,38 @@ let TaRelayServerImpl = class TaRelayServerImpl {
427
429
  return this.bridge.listRelays();
428
430
  });
429
431
  }
432
+ joinDeployment(url) {
433
+ return ta_errors_1.TaErrors.guard(async () => {
434
+ var _a, _b;
435
+ const address = ta_protocol_1.TaDeploymentUtil.url(url);
436
+ if (!address) {
437
+ throw ta_errors_1.TaErrors.invalidArgument(`${url} is not an address of http or https.`, 'Pass the address of the gateway or the relay of the deployment, https://….');
438
+ }
439
+ let deployment;
440
+ try {
441
+ deployment = await ta_protocol_1.TaDeploymentUtil.discover(address);
442
+ }
443
+ catch (error) {
444
+ throw ta_errors_1.TaErrors.invalidArgument(error instanceof Error ? error.message : String(error), 'Check the address: a service of a deployment answers /.well-known/ta. A relay alone is added as a relay.');
445
+ }
446
+ if (deployment.relay) {
447
+ const probe = await node_1.RelayInfoUtil.probe(deployment.relay);
448
+ if (!probe.online) {
449
+ throw ta_errors_1.TaErrors.invalidArgument(`The relay of ${(_a = deployment.name) !== null && _a !== void 0 ? _a : address}, ${deployment.relay}, does not answer: ${(_b = probe.error) !== null && _b !== void 0 ? _b : 'no answer'}.`, 'Ask whoever runs the deployment whether its relay runs.');
450
+ }
451
+ }
452
+ this.relaysCall(() => this.bridge.relays.join(address, deployment));
453
+ this.bridge.relaysChanged();
454
+ return this.bridge.listRelays();
455
+ });
456
+ }
457
+ leaveDeployment() {
458
+ return ta_errors_1.TaErrors.guard(async () => {
459
+ this.relaysCall(() => this.bridge.relays.leave());
460
+ this.bridge.relaysChanged();
461
+ return this.bridge.listRelays();
462
+ });
463
+ }
430
464
  async probeRelay(idOrUrl) {
431
465
  var _a, _b, _c;
432
466
  const text = String(idOrUrl !== null && idOrUrl !== void 0 ? idOrUrl : '');
@@ -53,6 +53,9 @@ export declare class TaRoomServerImpl implements TaRoomServer {
53
53
  listRequests(): Promise<TaRoomRequest[]>;
54
54
  answer(room: string, ask: string, accept: boolean): Promise<void>;
55
55
  removeMember(room: string, member: string): Promise<void>;
56
+ configureRoom(room: string, options: {
57
+ members?: number;
58
+ }): Promise<TaRoomInfo>;
56
59
  leave(room: string): Promise<void>;
57
60
  send(room: string, data: unknown, to?: string): Promise<void>;
58
61
  getState(room: string, prefix?: string): Promise<Record<string, TaRoomValue>>;
@@ -35,6 +35,7 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
35
35
  listRooms: async () => this.hubs.list(),
36
36
  createRoom: input => this.hubs.create(input),
37
37
  invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
38
+ configureRoom: async (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
38
39
  join: link => this.hubs.join(link),
39
40
  listRequests: () => this.hubs.requests(),
40
41
  answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
@@ -152,6 +153,9 @@ let TaRoomServerImpl = class TaRoomServerImpl {
152
153
  removeMember(room, member) {
153
154
  return ta_errors_1.TaErrors.guard(() => this.rooms.removeMember(room, member));
154
155
  }
156
+ configureRoom(room, options) {
157
+ return ta_errors_1.TaErrors.guard(() => this.rooms.configureRoom(room, { members: options === null || options === void 0 ? void 0 : options.members }));
158
+ }
155
159
  leave(room) {
156
160
  return ta_errors_1.TaErrors.guard(() => this.rooms.leave(room));
157
161
  }
@@ -15,7 +15,9 @@ export declare namespace SessionInfoUtil {
15
15
  * The text of the last message of the user or the agent that has some, on one line and cut to a preview's
16
16
  * length, as a messaging app shows the last thing said under its name: without its context, the marks of
17
17
  * markdown at the start of its lines, and the thinking and tool calls of the agent; a skill the user ran is
18
- * `/skill:name` and what follows, as the title says it, not the skill's file.
18
+ * `/skill:name` and what follows, as the title says it, not the skill's file. A note of the double's tasks
19
+ * (TaTaskNote) says the task: how one ended is its title and what it said, one handed to the double its title,
20
+ * and a note of a new id, for the double only, is passed over.
19
21
  */
20
22
  function lastMessage(messages: readonly MessageLike[]): string | undefined;
21
23
  /** The time of the last message that has one, else `fallback`. */