@celljs/ta-host 4.13.1 → 4.14.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 (79) hide show
  1. package/README.en.md +1 -0
  2. package/README.md +1 -0
  3. package/esm/node/host-protocol.d.ts +17 -1
  4. package/esm/node/host-protocol.js +1 -0
  5. package/esm/node/index.d.ts +2 -0
  6. package/esm/node/index.js +2 -0
  7. package/esm/node/package-hosts.d.ts +2 -1
  8. package/esm/node/package-hosts.js +6 -2
  9. package/esm/node/presence-book.d.ts +38 -0
  10. package/esm/node/presence-book.js +159 -0
  11. package/esm/node/presence-server-impl.d.ts +13 -0
  12. package/esm/node/presence-server-impl.js +45 -0
  13. package/esm/node/rooms-bridge.d.ts +6 -1
  14. package/esm/node/rooms-bridge.js +21 -3
  15. package/esm/node/session-list-feed.js +2 -1
  16. package/esm/node/sign-in/access-server-impl.d.ts +5 -1
  17. package/esm/node/sign-in/access-server-impl.js +22 -1
  18. package/esm/node/sign-in/sign-in-flow.d.ts +14 -1
  19. package/esm/node/sign-in/sign-in-flow.js +24 -7
  20. package/esm/node/sign-in/sign-in-provider.d.ts +40 -1
  21. package/esm/node/sign-in/sign-in-provider.js +120 -0
  22. package/esm/node/sign-in/ta-sign-in.d.ts +9 -3
  23. package/esm/node/sign-in/ta-sign-in.js +32 -4
  24. package/esm/node/ta-server-impl.d.ts +7 -0
  25. package/esm/node/ta-server-impl.js +44 -7
  26. package/esm/node/ta-session-registry.d.ts +10 -3
  27. package/esm/node/ta-session-registry.js +29 -3
  28. package/esm/node/ta-session.d.ts +2 -0
  29. package/esm/node/ta-session.js +6 -0
  30. package/esm/node/team/host-team.d.ts +2 -1
  31. package/esm/node/team/host-team.js +10 -1
  32. package/esm/node/team/index.d.ts +1 -0
  33. package/esm/node/team/index.js +1 -0
  34. package/esm/node/team/member-accounts.d.ts +13 -0
  35. package/esm/node/team/member-accounts.js +37 -0
  36. package/esm/node/team/team-calls.d.ts +2 -1
  37. package/esm/node/team/team-calls.js +7 -0
  38. package/esm/node/team/team-gate.js +1 -1
  39. package/esm/node/team/team-protocol.d.ts +5 -1
  40. package/esm/node/team/team-protocol.js +2 -0
  41. package/lib/node/host-protocol.d.ts +17 -1
  42. package/lib/node/host-protocol.js +2 -1
  43. package/lib/node/index.d.ts +2 -0
  44. package/lib/node/index.js +2 -0
  45. package/lib/node/package-hosts.d.ts +2 -1
  46. package/lib/node/package-hosts.js +5 -1
  47. package/lib/node/presence-book.d.ts +39 -0
  48. package/lib/node/presence-book.js +162 -0
  49. package/lib/node/presence-server-impl.d.ts +14 -0
  50. package/lib/node/presence-server-impl.js +48 -0
  51. package/lib/node/rooms-bridge.d.ts +6 -1
  52. package/lib/node/rooms-bridge.js +20 -2
  53. package/lib/node/session-list-feed.js +2 -1
  54. package/lib/node/sign-in/access-server-impl.d.ts +5 -1
  55. package/lib/node/sign-in/access-server-impl.js +21 -0
  56. package/lib/node/sign-in/sign-in-flow.d.ts +14 -1
  57. package/lib/node/sign-in/sign-in-flow.js +24 -7
  58. package/lib/node/sign-in/sign-in-provider.d.ts +40 -1
  59. package/lib/node/sign-in/sign-in-provider.js +120 -0
  60. package/lib/node/sign-in/ta-sign-in.d.ts +9 -3
  61. package/lib/node/sign-in/ta-sign-in.js +32 -4
  62. package/lib/node/ta-server-impl.d.ts +7 -0
  63. package/lib/node/ta-server-impl.js +43 -6
  64. package/lib/node/ta-session-registry.d.ts +10 -3
  65. package/lib/node/ta-session-registry.js +27 -1
  66. package/lib/node/ta-session.d.ts +2 -0
  67. package/lib/node/ta-session.js +6 -0
  68. package/lib/node/team/host-team.d.ts +2 -1
  69. package/lib/node/team/host-team.js +9 -0
  70. package/lib/node/team/index.d.ts +1 -0
  71. package/lib/node/team/index.js +1 -0
  72. package/lib/node/team/member-accounts.d.ts +14 -0
  73. package/lib/node/team/member-accounts.js +40 -0
  74. package/lib/node/team/team-calls.d.ts +2 -1
  75. package/lib/node/team/team-calls.js +7 -0
  76. package/lib/node/team/team-gate.js +1 -1
  77. package/lib/node/team/team-protocol.d.ts +5 -1
  78. package/lib/node/team/team-protocol.js +3 -1
  79. package/package.json +12 -12
package/README.en.md CHANGED
@@ -65,6 +65,7 @@ When `ta serve` runs in the cloud or on a server, besides the token, people can
65
65
  | Variable | Purpose |
66
66
  | --- | --- |
67
67
  | `TA_PUBLIC_URL` | The address at which browsers reach `ta serve`, such as `https://ta.example.com`. The callback of each provider is `<TA_PUBLIC_URL>/sign-in/<github\|google\|wechat\|oidc>/callback`, to register with the provider. Without it, it is worked out from the `Host` of the request and the `X-Forwarded-Proto` / `X-Forwarded-Host` of a reverse proxy |
68
+ | `sign-in.json` (agent directory) | The ways to sign in, as the variables below: `{ "github": { "clientId", "clientSecret", "url" }, "google": {…}, "wechat": { "appId", "appSecret" }, "oidc": { "issuer", "clientId", "clientSecret", "name" } }`, read as ta serve starts, the environment winning. Those invited sign in with them too, to say who they are (ta-team) |
68
69
  | `TA_GITHUB_CLIENT_ID` / `TA_GITHUB_CLIENT_SECRET` | A GitHub OAuth App; the account is `github:<login>`. `TA_GITHUB_URL` points to a GitHub Enterprise Server |
69
70
  | `TA_GOOGLE_CLIENT_ID` / `TA_GOOGLE_CLIENT_SECRET` | A Google OAuth client (web application); the account is `google:<email>`, verified addresses only |
70
71
  | `TA_WECHAT_APP_ID` / `TA_WECHAT_APP_SECRET` | A website app of the WeChat Open Platform (sign-in by scanning); the account is `wechat:<unionid>`, or the openid when the app has no unionid |
package/README.md CHANGED
@@ -65,6 +65,7 @@ ta:
65
65
  | 环境变量 | 作用 |
66
66
  | --- | --- |
67
67
  | `TA_PUBLIC_URL` | 浏览器访问 `ta serve` 的地址,如 `https://ta.example.com`。各家的回调地址是 `<TA_PUBLIC_URL>/sign-in/<github\|google\|wechat\|oidc>/callback`,要在服务商那里登记。没有时按请求的 `Host` 和反向代理的 `X-Forwarded-Proto` / `X-Forwarded-Host` 推算 |
68
+ | `sign-in.json`(智能体目录) | 和下面的环境变量一样配置登录方式:`{ "github": { "clientId", "clientSecret", "url" }, "google": {…}, "wechat": { "appId", "appSecret" }, "oidc": { "issuer", "clientId", "clientSecret", "name" } }`,启动时读取,环境变量优先。邀请进来的人也用这些方式登录说明自己是谁(ta-team) |
68
69
  | `TA_GITHUB_CLIENT_ID` / `TA_GITHUB_CLIENT_SECRET` | GitHub 的 OAuth App;账号是 `github:<用户名>`。`TA_GITHUB_URL` 指向 GitHub Enterprise Server |
69
70
  | `TA_GOOGLE_CLIENT_ID` / `TA_GOOGLE_CLIENT_SECRET` | Google 的 OAuth 客户端(Web 应用);账号是 `google:<邮箱>`,只认验证过的邮箱 |
70
71
  | `TA_WECHAT_APP_ID` / `TA_WECHAT_APP_SECRET` | 微信开放平台的网站应用(扫码登录);账号是 `wechat:<unionid>`,应用没有 unionid 时是 openid |
@@ -1,5 +1,5 @@
1
1
  import type { RpcConnection } from '@celljs/rpc/lib/node';
2
- import type { TaEvent, TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSavedSessionQuery, TaSessionInfo, TaSettingsScope, TaSlashCommand, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
2
+ import type { TaEvent, TaOpenSessionOptions, TaPackageInfo, TaPresencePerson, TaPresenceReport, TaSavedSessionInfo, TaSavedSessionQuery, TaSessionInfo, TaSessionPerson, TaSettingsScope, TaSlashCommand, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
3
3
  import type { ClientChannel } from './client-channel.js';
4
4
  import type { TaSession } from './ta-session.js';
5
5
  export declare const TaSessionFactory: unique symbol;
@@ -7,6 +7,7 @@ export declare const TaSessionRegistry: unique symbol;
7
7
  export declare const TaSessionCatalog: unique symbol;
8
8
  export declare const WebExtensionCatalog: unique symbol;
9
9
  export declare const KeepAwake: unique symbol;
10
+ export declare const TaPresenceBook: unique symbol;
10
11
  export declare const TA_HOST_OPTIONS = "ta.host";
11
12
  export declare const TA_EXEC_OPTIONS = "ta.exec";
12
13
  /** `ta.host`. */
@@ -44,6 +45,8 @@ export interface TaSessionRegistry {
44
45
  */
45
46
  resolve(sessionId: string): Promise<TaSession>;
46
47
  list(): TaSession[];
48
+ /** The infos of the open sessions a connection may see, with who else is at each (TaSessionInfo.people). */
49
+ infos(connection: RpcConnection | undefined): TaSessionInfo[];
47
50
  /** The infos of the open sessions; the connection is told of each change from now on (TaServer.watchSessions). */
48
51
  watch(connection: RpcConnection): TaSessionInfo[];
49
52
  /** `idle`: closed to save its memory (idle, or the service stops), it keeps its id and opens again when called; otherwise for good. */
@@ -107,3 +110,16 @@ export interface KeepAwake {
107
110
  /** Holds or lets go as things are now: at once after the setting changed. */
108
111
  check(): void;
109
112
  }
113
+ /**
114
+ * What each page is at (TaPresenceServer.report), in memory only: who looks at which conversation and types in it. A page
115
+ * leaves it as its connection closes, or once it said nothing for TA_PRESENCE_EXPIRY_MS.
116
+ */
117
+ export interface TaPresenceBook {
118
+ report(connection: RpcConnection, state: TaPresenceReport): void;
119
+ /** The others at a session, as `principal` is told: those who look at it or type in it, and who asked its run while `streaming`. */
120
+ people(sessionId: string, principal: string, streaming: boolean): TaSessionPerson[] | undefined;
121
+ /** Each one with pages that report, and where the latest of them is. */
122
+ everyone(): TaPresencePerson[];
123
+ /** What `people` gives may have changed. */
124
+ onChange(listener: () => void): () => void;
125
+ }
@@ -3,6 +3,7 @@ export const TaSessionRegistry = Symbol('TaSessionRegistry');
3
3
  export const TaSessionCatalog = Symbol('TaSessionCatalog');
4
4
  export const WebExtensionCatalog = Symbol('WebExtensionCatalog');
5
5
  export const KeepAwake = Symbol('KeepAwake');
6
+ export const TaPresenceBook = Symbol('TaPresenceBook');
6
7
  export const TA_HOST_OPTIONS = 'ta.host';
7
8
  export const TA_EXEC_OPTIONS = 'ta.exec';
8
9
  //# sourceMappingURL=host-protocol.js.map
@@ -11,6 +11,8 @@ export * from './keep-awake.js';
11
11
  export * from './package-host-extension.js';
12
12
  export * from './package-hosts.js';
13
13
  export * from './package-server-impl.js';
14
+ export * from './presence-book.js';
15
+ export * from './presence-server-impl.js';
14
16
  export * from './receipt-book.js';
15
17
  export * from './relay-bridge.js';
16
18
  export * from './remote/index.js';
package/esm/node/index.js CHANGED
@@ -11,6 +11,8 @@ export * from './keep-awake.js';
11
11
  export * from './package-host-extension.js';
12
12
  export * from './package-hosts.js';
13
13
  export * from './package-server-impl.js';
14
+ export * from './presence-book.js';
15
+ export * from './presence-server-impl.js';
14
16
  export * from './receipt-book.js';
15
17
  export * from './relay-bridge.js';
16
18
  export * from './remote/index.js';
@@ -2,7 +2,7 @@ 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
4
  import { ExtensionDataStore } from './extension-data.js';
5
- import { TaSessionRegistry } from './host-protocol.js';
5
+ import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
6
6
  import { type RelayBridge } from './relay-bridge.js';
7
7
  import { PiDirectories } from './remote/remote-protocol.js';
8
8
  import { type RoomsBridge } from './rooms-bridge.js';
@@ -56,6 +56,7 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
56
56
  protected readonly roomsBridge: RoomsBridge;
57
57
  protected readonly settings: TaSettingsStore;
58
58
  protected readonly sessions: TaSessionRegistry;
59
+ protected readonly presenceBook: TaPresenceBook;
59
60
  protected readonly teamProvider: TaHostTeamProvider;
60
61
  protected readonly running: Map<string, Running>;
61
62
  protected extensionHost?: TaExtensionHost;
@@ -17,7 +17,7 @@ import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
17
17
  import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
18
18
  import { TaMessageSource, TaPackageServer, TaServer, } from '@celljs/ta-protocol';
19
19
  import { ExtensionDataStore } from './extension-data.js';
20
- import { TaSessionRegistry } from './host-protocol.js';
20
+ import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
21
21
  import { RELAY_BRIDGE } from './relay-bridge.js';
22
22
  import { PiDirectories } from './remote/remote-protocol.js';
23
23
  import { ROOMS_BRIDGE } from './rooms-bridge.js';
@@ -209,7 +209,7 @@ let PackageHostsImpl = class PackageHostsImpl {
209
209
  listener(turn);
210
210
  }
211
211
  }),
212
- presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt }),
212
+ presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt, people: this.presenceBook.everyone() }),
213
213
  team: this.teamProvider.team,
214
214
  installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
215
215
  removePackage: (id, cwd) => packages.removePackage(id, cwd),
@@ -281,6 +281,10 @@ __decorate([
281
281
  Autowired({ id: TaSessionRegistry, detached: true }),
282
282
  __metadata("design:type", Object)
283
283
  ], PackageHostsImpl.prototype, "sessions", void 0);
284
+ __decorate([
285
+ Autowired({ id: TaPresenceBook, detached: true }),
286
+ __metadata("design:type", Object)
287
+ ], PackageHostsImpl.prototype, "presenceBook", void 0);
284
288
  __decorate([
285
289
  Autowired({ id: TaHostTeamProvider, detached: true }),
286
290
  __metadata("design:type", Object)
@@ -0,0 +1,38 @@
1
+ import type { RpcConnection } from '@celljs/rpc/lib/node';
2
+ import { type TaPresencePerson, type TaPresenceReport, type TaSessionPerson } from '@celljs/ta-protocol';
3
+ import { TaPresenceBook } from './host-protocol.js';
4
+ import { TaAuthority, TaPrincipals, TaRunActors } from './team/team-protocol.js';
5
+ interface Entry {
6
+ principal: string;
7
+ sessionId?: string;
8
+ typing: boolean;
9
+ /** `Date.now()` time of its last report. */
10
+ at: number;
11
+ }
12
+ /**
13
+ * What each page is at, by connection (docs/design/ta-team.md 7.1): who looks at which conversation and types in it,
14
+ * named as the page of members names them. Nothing of it is written anywhere; a connection closed, or silent for
15
+ * TA_PRESENCE_EXPIRY_MS, is out of it.
16
+ */
17
+ export declare class DefaultTaPresenceBook implements TaPresenceBook {
18
+ protected readonly principals: TaPrincipals;
19
+ protected readonly authority: TaAuthority;
20
+ protected readonly runs: TaRunActors;
21
+ protected readonly entries: Map<RpcConnection, Entry>;
22
+ protected readonly watched: WeakSet<RpcConnection>;
23
+ protected readonly listeners: Set<() => void>;
24
+ protected sweeper?: ReturnType<typeof setInterval>;
25
+ protected ownerName?: string;
26
+ /** How long a page may say nothing; less in specs. */
27
+ protected expiryMs: number;
28
+ report(connection: RpcConnection, state: TaPresenceReport): void;
29
+ people(sessionId: string, principal: string, streaming: boolean): TaSessionPerson[] | undefined;
30
+ everyone(): TaPresencePerson[];
31
+ onChange(listener: () => void): () => void;
32
+ protected nameOf(principal: string): string;
33
+ protected leave(connection: RpcConnection): void;
34
+ /** Pages silent too long are gone; looked for only while there are pages. */
35
+ protected sweep(): void;
36
+ protected changed(): void;
37
+ }
38
+ export {};
@@ -0,0 +1,159 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { userInfo } from 'node:os';
11
+ import { Autowired, Component } from '@celljs/core';
12
+ import { TA_OWNER, TA_PRESENCE_EXPIRY_MS } from '@celljs/ta-protocol';
13
+ import { TaPresenceBook } from './host-protocol.js';
14
+ import { TaAuthority, TaPrincipals, TaRunActors } from './team/team-protocol.js';
15
+ /**
16
+ * What each page is at, by connection (docs/design/ta-team.md 7.1): who looks at which conversation and types in it,
17
+ * named as the page of members names them. Nothing of it is written anywhere; a connection closed, or silent for
18
+ * TA_PRESENCE_EXPIRY_MS, is out of it.
19
+ */
20
+ let DefaultTaPresenceBook = class DefaultTaPresenceBook {
21
+ constructor() {
22
+ this.entries = new Map();
23
+ this.watched = new WeakSet();
24
+ this.listeners = new Set();
25
+ /** How long a page may say nothing; less in specs. */
26
+ this.expiryMs = TA_PRESENCE_EXPIRY_MS;
27
+ }
28
+ report(connection, state) {
29
+ if (connection.closed) {
30
+ return;
31
+ }
32
+ const sessionId = typeof (state === null || state === void 0 ? void 0 : state.sessionId) === 'string' && state.sessionId ? state.sessionId : undefined;
33
+ const entry = { principal: this.principals.of(connection), sessionId, typing: !!sessionId && (state === null || state === void 0 ? void 0 : state.typing) === true, at: Date.now() };
34
+ const before = this.entries.get(connection);
35
+ this.entries.set(connection, entry);
36
+ if (!this.watched.has(connection)) {
37
+ this.watched.add(connection);
38
+ connection.onClose(() => this.leave(connection));
39
+ }
40
+ this.sweep();
41
+ if (!before || before.sessionId !== entry.sessionId || before.typing !== entry.typing) {
42
+ this.changed();
43
+ }
44
+ }
45
+ people(sessionId, principal, streaming) {
46
+ var _a;
47
+ const found = new Map();
48
+ const person = (id) => {
49
+ let one = found.get(id);
50
+ if (!one) {
51
+ one = { id, name: this.nameOf(id) };
52
+ found.set(id, one);
53
+ }
54
+ return one;
55
+ };
56
+ for (const entry of this.entries.values()) {
57
+ if (entry.sessionId === sessionId && entry.principal !== principal) {
58
+ const one = person(entry.principal);
59
+ one.viewing = true;
60
+ if (entry.typing) {
61
+ one.typing = true;
62
+ }
63
+ }
64
+ }
65
+ if (streaming) {
66
+ for (const actor of (_a = this.runs.actorsOfSession(sessionId)) !== null && _a !== void 0 ? _a : []) {
67
+ if (actor !== principal) {
68
+ person(actor).asked = true;
69
+ }
70
+ }
71
+ }
72
+ // The same order each time: a list told again only when it differs.
73
+ return found.size ? [...found.values()].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)) : undefined;
74
+ }
75
+ everyone() {
76
+ var _a;
77
+ const people = new Map();
78
+ for (const entry of this.entries.values()) {
79
+ const one = (_a = people.get(entry.principal)) !== null && _a !== void 0 ? _a : { id: entry.principal, name: this.nameOf(entry.principal), pages: 0, at: 0 };
80
+ one.pages++;
81
+ if (entry.at >= one.at) {
82
+ one.at = entry.at;
83
+ one.sessionId = entry.sessionId;
84
+ one.typing = entry.typing || undefined;
85
+ }
86
+ people.set(entry.principal, one);
87
+ }
88
+ return [...people.values()].map(({ at: _at, sessionId, typing, ...one }) => ({
89
+ ...one,
90
+ ...(sessionId ? { sessionId } : {}),
91
+ ...(typing ? { typing } : {}),
92
+ }));
93
+ }
94
+ onChange(listener) {
95
+ this.listeners.add(listener);
96
+ return () => this.listeners.delete(listener);
97
+ }
98
+ nameOf(principal) {
99
+ var _a;
100
+ var _b, _c;
101
+ if (principal === TA_OWNER) {
102
+ (_b = this.ownerName) !== null && _b !== void 0 ? _b : (this.ownerName = userInfo().username);
103
+ return this.ownerName;
104
+ }
105
+ return (_c = (_a = this.authority.describe(principal)) === null || _a === void 0 ? void 0 : _a.name) !== null && _c !== void 0 ? _c : principal;
106
+ }
107
+ leave(connection) {
108
+ if (this.entries.delete(connection)) {
109
+ this.changed();
110
+ }
111
+ }
112
+ /** Pages silent too long are gone; looked for only while there are pages. */
113
+ sweep() {
114
+ var _a, _b;
115
+ if (this.sweeper || !this.entries.size) {
116
+ return;
117
+ }
118
+ this.sweeper = setInterval(() => {
119
+ const before = Date.now() - this.expiryMs;
120
+ let gone = false;
121
+ for (const [connection, entry] of this.entries) {
122
+ if (entry.at < before) {
123
+ this.entries.delete(connection);
124
+ gone = true;
125
+ }
126
+ }
127
+ if (!this.entries.size) {
128
+ clearInterval(this.sweeper);
129
+ this.sweeper = undefined;
130
+ }
131
+ if (gone) {
132
+ this.changed();
133
+ }
134
+ }, Math.max(1, Math.floor(this.expiryMs / 3)));
135
+ (_b = (_a = this.sweeper).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
136
+ }
137
+ changed() {
138
+ for (const listener of this.listeners) {
139
+ listener();
140
+ }
141
+ }
142
+ };
143
+ __decorate([
144
+ Autowired(TaPrincipals),
145
+ __metadata("design:type", Object)
146
+ ], DefaultTaPresenceBook.prototype, "principals", void 0);
147
+ __decorate([
148
+ Autowired(TaAuthority),
149
+ __metadata("design:type", Object)
150
+ ], DefaultTaPresenceBook.prototype, "authority", void 0);
151
+ __decorate([
152
+ Autowired(TaRunActors),
153
+ __metadata("design:type", Object)
154
+ ], DefaultTaPresenceBook.prototype, "runs", void 0);
155
+ DefaultTaPresenceBook = __decorate([
156
+ Component(TaPresenceBook)
157
+ ], DefaultTaPresenceBook);
158
+ export { DefaultTaPresenceBook };
159
+ //# sourceMappingURL=presence-book.js.map
@@ -0,0 +1,13 @@
1
+ import { type TaPresenceReport, TaPresenceServer } from '@celljs/ta-protocol';
2
+ import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
3
+ import { TaVisibility } from './team/team-protocol.js';
4
+ /**
5
+ * What each page says it is at (TaPresenceServer). A page is at a conversation only when it is open and the page may
6
+ * see it: no one shows at one they may not see, nor at one made up.
7
+ */
8
+ export declare class TaPresenceServerImpl implements TaPresenceServer {
9
+ protected readonly book: TaPresenceBook;
10
+ protected readonly sessions: TaSessionRegistry;
11
+ protected readonly visibility: TaVisibility;
12
+ report(state: TaPresenceReport): Promise<void>;
13
+ }
@@ -0,0 +1,45 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Autowired } from '@celljs/core';
11
+ import { Rpc } from '@celljs/rpc';
12
+ import { RpcContext } from '@celljs/rpc/lib/node';
13
+ import { TaPresenceServer } from '@celljs/ta-protocol';
14
+ import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
15
+ import { TaVisibility } from './team/team-protocol.js';
16
+ /**
17
+ * What each page says it is at (TaPresenceServer). A page is at a conversation only when it is open and the page may
18
+ * see it: no one shows at one they may not see, nor at one made up.
19
+ */
20
+ let TaPresenceServerImpl = class TaPresenceServerImpl {
21
+ async report(state) {
22
+ const connection = RpcContext.requireConnection();
23
+ const sessionId = typeof (state === null || state === void 0 ? void 0 : state.sessionId) === 'string' ? state.sessionId : undefined;
24
+ const session = sessionId ? this.sessions.list().find(one => one.id === sessionId) : undefined;
25
+ const seen = !!session && this.visibility.sessions(connection, [{ cwd: session.cwd, sessionFile: session.pi.sessionFile }]).length > 0;
26
+ this.book.report(connection, seen ? { sessionId, typing: (state === null || state === void 0 ? void 0 : state.typing) === true } : {});
27
+ }
28
+ };
29
+ __decorate([
30
+ Autowired(TaPresenceBook),
31
+ __metadata("design:type", Object)
32
+ ], TaPresenceServerImpl.prototype, "book", void 0);
33
+ __decorate([
34
+ Autowired(TaSessionRegistry),
35
+ __metadata("design:type", Object)
36
+ ], TaPresenceServerImpl.prototype, "sessions", void 0);
37
+ __decorate([
38
+ Autowired(TaVisibility),
39
+ __metadata("design:type", Object)
40
+ ], TaPresenceServerImpl.prototype, "visibility", void 0);
41
+ TaPresenceServerImpl = __decorate([
42
+ Rpc(TaPresenceServer)
43
+ ], TaPresenceServerImpl);
44
+ export { TaPresenceServerImpl };
45
+ //# sourceMappingURL=presence-server-impl.js.map
@@ -2,6 +2,7 @@ import { type Application, ApplicationLifecycle } from '@celljs/core';
2
2
  import { type RpcConnection } from '@celljs/rpc/lib/node';
3
3
  import { type TaFriend, type TaFriendRequest, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
4
4
  import type { RelayHubs } from '@celljs/ta-relay/lib/node';
5
+ import { ExtensionDataStore } from './extension-data.js';
5
6
  import { type RelayBridge } from './relay-bridge.js';
6
7
  /** The id of {@link RoomsBridge}. */
7
8
  export declare const ROOMS_BRIDGE: unique symbol;
@@ -12,16 +13,20 @@ export declare const ROOMS_BRIDGE: unique symbol;
12
13
  */
13
14
  export declare class RoomsBridge implements ApplicationLifecycle<Application> {
14
15
  protected readonly relay: RelayBridge;
16
+ protected readonly data: ExtensionDataStore;
17
+ protected stopLook?: () => void;
15
18
  /** The connections that watch, and what they hear: messages and the state too, or the state of some keys. */
16
19
  protected readonly watchers: Map<RpcConnection, TaRoomWatch>;
17
20
  get hubs(): RelayHubs;
18
21
  readonly rooms: TaRooms;
19
22
  onStart(): void;
20
23
  onStop(): void;
24
+ /** The look of this Ta others see is the double's, as the user picked it on a page (TA_DOUBLE_LOOK). */
25
+ protected keepLook(): Promise<void>;
21
26
  /** `watch` undefined: no more. */
22
27
  watch(connection: RpcConnection, watch: TaRoomWatch | undefined): void;
23
28
  protected broadcast(event: TaRoomEvent): void;
24
- protected static identity({ id, name, shared }: TaIdentity): TaIdentity;
29
+ protected static identity({ id, name, look, shared }: TaIdentity): TaIdentity;
25
30
  }
26
31
  /** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
27
32
  export declare class TaRoomServerImpl implements TaRoomServer {
@@ -11,7 +11,8 @@ var RoomsBridge_1;
11
11
  import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
12
12
  import { Rpc } from '@celljs/rpc';
13
13
  import { RpcContext } from '@celljs/rpc/lib/node';
14
- import { TaClient, TaRoomServer, TaRoomWatchUtil, } from '@celljs/ta-protocol';
14
+ import { TA_DOUBLE_LOOK, TaClient, TaRoomServer, TaRoomWatchUtil, } from '@celljs/ta-protocol';
15
+ import { ExtensionDataStore } from './extension-data.js';
15
16
  import { RELAY_BRIDGE } from './relay-bridge.js';
16
17
  import { TaErrors } from './ta-errors.js';
17
18
  /** The id of {@link RoomsBridge}. */
@@ -62,10 +63,23 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
62
63
  onStart() {
63
64
  this.hubs.onEvent(event => this.broadcast(event));
64
65
  this.hubs.start();
66
+ void this.keepLook();
67
+ this.stopLook = this.data.onChange((name, key, cwd) => {
68
+ if (name === TA_DOUBLE_LOOK.name && key === TA_DOUBLE_LOOK.key && cwd === undefined) {
69
+ void this.keepLook();
70
+ }
71
+ });
65
72
  }
66
73
  onStop() {
74
+ var _a;
75
+ (_a = this.stopLook) === null || _a === void 0 ? void 0 : _a.call(this);
67
76
  this.hubs.stop();
68
77
  }
78
+ /** The look of this Ta others see is the double's, as the user picked it on a page (TA_DOUBLE_LOOK). */
79
+ async keepLook() {
80
+ const look = await this.data.get(TA_DOUBLE_LOOK.name, TA_DOUBLE_LOOK.key).catch(() => undefined);
81
+ await this.hubs.setLook(typeof look === 'string' && look ? look : TA_DOUBLE_LOOK.initial).catch(() => undefined);
82
+ }
69
83
  /** `watch` undefined: no more. */
70
84
  watch(connection, watch) {
71
85
  if (watch === undefined) {
@@ -87,14 +101,18 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
87
101
  }
88
102
  }
89
103
  }
90
- static identity({ id, name, shared }) {
91
- return { id, name, ...(shared ? { shared } : {}) };
104
+ static identity({ id, name, look, shared }) {
105
+ return { id, name, ...(look ? { look } : {}), ...(shared ? { shared } : {}) };
92
106
  }
93
107
  };
94
108
  __decorate([
95
109
  Autowired({ id: RELAY_BRIDGE, detached: true }),
96
110
  __metadata("design:type", Function)
97
111
  ], RoomsBridge.prototype, "relay", void 0);
112
+ __decorate([
113
+ Autowired(ExtensionDataStore),
114
+ __metadata("design:type", Object)
115
+ ], RoomsBridge.prototype, "data", void 0);
98
116
  RoomsBridge = RoomsBridge_1 = __decorate([
99
117
  Component([ROOMS_BRIDGE, ApplicationLifecycle])
100
118
  ], RoomsBridge);
@@ -56,7 +56,6 @@ export class SessionListFeed {
56
56
  const wait = Math.max(0, watcher.lastAt + this.intervalMs - performance.now());
57
57
  watcher.timer = setTimeout(() => {
58
58
  watcher.timer = undefined;
59
- watcher.lastAt = performance.now();
60
59
  if (connection.closed) {
61
60
  return;
62
61
  }
@@ -65,6 +64,8 @@ export class SessionListFeed {
65
64
  if (json === watcher.sent) {
66
65
  return;
67
66
  }
67
+ // Only a list sent counts against the interval: what did not change this one does not hold back the next.
68
+ watcher.lastAt = performance.now();
68
69
  watcher.sent = json;
69
70
  connection
70
71
  .client(TaClient)
@@ -1,5 +1,6 @@
1
1
  import { RpcConnectionManager } from '@celljs/rpc/lib/node';
2
- import { type TaAccessInfo, TaAccessServer } from '@celljs/ta-protocol';
2
+ import { type TaAccessInfo, TaAccessServer, type TaSignInConfig, type TaSignInKind } from '@celljs/ta-protocol';
3
+ import { type RelayBridge } from '../relay-bridge.js';
3
4
  import { type TaAccess } from '../ta-access.js';
4
5
  import { type TaSignIn } from './ta-sign-in.js';
5
6
  /** Who may sign in with an account, for anyone in; a browser that loses its sign-in is cut off at once. */
@@ -7,6 +8,9 @@ export declare class TaAccessServerImpl implements TaAccessServer {
7
8
  protected readonly signIn: TaSignIn;
8
9
  protected readonly access: TaAccess;
9
10
  protected readonly connections: RpcConnectionManager;
11
+ protected readonly relay: RelayBridge;
12
+ getSignInConfig(): Promise<TaSignInConfig>;
13
+ setSignInProvider(id: TaSignInKind, fields: Record<string, string> | null): Promise<void>;
10
14
  getAccess(): Promise<TaAccessInfo>;
11
15
  bindUrl(provider: string): Promise<string>;
12
16
  allow(account: string, name?: string): Promise<void>;
@@ -10,7 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { Autowired } from '@celljs/core';
11
11
  import { Rpc } from '@celljs/rpc';
12
12
  import { RpcConnectionManager, RpcContext } from '@celljs/rpc/lib/node';
13
- import { TaAccessServer } from '@celljs/ta-protocol';
13
+ import { TA_SIGN_IN_PATH, TaAccessServer } from '@celljs/ta-protocol';
14
+ import { RELAY_JOIN_PATH } from '@celljs/ta-relay/lib/common/relay-team';
15
+ import { RELAY_BRIDGE } from '../relay-bridge.js';
14
16
  import { TA_ACCESS, TaAccessUtil } from '../ta-access.js';
15
17
  import { TaErrors } from '../ta-errors.js';
16
18
  import { AccessUtil } from './access-store.js';
@@ -18,6 +20,21 @@ import { TA_SIGN_IN } from './ta-sign-in.js';
18
20
  const ACCOUNT = /^[a-z][a-z0-9-]*:\S+$/;
19
21
  /** Who may sign in with an account, for anyone in; a browser that loses its sign-in is cut off at once. */
20
22
  let TaAccessServerImpl = class TaAccessServerImpl {
23
+ async getSignInConfig() {
24
+ const join = `${this.relay.relayFor('devices').replace(/\/+$/, '')}${RELAY_JOIN_PATH}`;
25
+ const serve = this.signIn.publicUrl ? `${this.signIn.publicUrl}${TA_SIGN_IN_PATH}/<provider>/callback` : undefined;
26
+ return { providers: this.signIn.setups(), callbacks: { join, ...(serve ? { serve } : {}) } };
27
+ }
28
+ setSignInProvider(id, fields) {
29
+ return TaErrors.guard(async () => {
30
+ try {
31
+ this.signIn.setProvider(id, fields && typeof fields === 'object' ? fields : null);
32
+ }
33
+ catch (failure) {
34
+ throw TaErrors.invalidArgument(failure instanceof Error ? failure.message : String(failure), 'Give the id and the secret the provider gave.');
35
+ }
36
+ });
37
+ }
21
38
  async getAccess() {
22
39
  var _a;
23
40
  const providers = this.signIn.providers.map(({ id, name }) => ({ id, name }));
@@ -75,6 +92,10 @@ __decorate([
75
92
  Autowired(RpcConnectionManager),
76
93
  __metadata("design:type", Object)
77
94
  ], TaAccessServerImpl.prototype, "connections", void 0);
95
+ __decorate([
96
+ Autowired({ id: RELAY_BRIDGE, detached: true }),
97
+ __metadata("design:type", Function)
98
+ ], TaAccessServerImpl.prototype, "relay", void 0);
78
99
  TaAccessServerImpl = __decorate([
79
100
  Rpc(TaAccessServer)
80
101
  ], TaAccessServerImpl);
@@ -9,6 +9,8 @@ interface Pending {
9
9
  redirectUri: string;
10
10
  /** Lets the account in: started by someone already in. */
11
11
  bind: boolean;
12
+ /** Only says who signed in (TaHostAccounts.verify): lets no one into ta serve. */
13
+ verify?: true;
12
14
  at: number;
13
15
  }
14
16
  export type SignInResult = {
@@ -36,7 +38,7 @@ export declare namespace SignInUtil {
36
38
  * gateway (`ta gateway`) use it alike.
37
39
  */
38
40
  export declare class SignInFlow {
39
- readonly providers: SignInProvider[];
41
+ providers: SignInProvider[];
40
42
  readonly store: AccessStore;
41
43
  readonly publicUrl?: string | undefined;
42
44
  constructor(providers: SignInProvider[], store: AccessStore, publicUrl?: string | undefined);
@@ -53,6 +55,17 @@ export declare class SignInFlow {
53
55
  url: string;
54
56
  state: string;
55
57
  }>;
58
+ /** A sign-in that only says who it is ({@link verify}), coming back to `redirectUri`: the page of a relay, say. */
59
+ startVerify(providerId: string, redirectUri: string, now?: number): Promise<{
60
+ url: string;
61
+ state: string;
62
+ }>;
63
+ /** The account of a sign-in of {@link startVerify}: no token, nothing let in. */
64
+ verify(state: string, code: string, now?: number): Promise<SignInAccount>;
65
+ protected begin(providerId: string, redirectUri: string, kind: Pick<Pending, 'bind' | 'verify'>, now: number): Promise<{
66
+ url: string;
67
+ state: string;
68
+ }>;
56
69
  /** The browser came back from the provider with a code: in with a token of its own, or told to wait. */
57
70
  finish(providerId: string, state: string, code: string, device?: string, now?: number): Promise<SignInResult>;
58
71
  protected prune(now: number): void;