@celljs/ta-protocol 4.13.1 → 4.15.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 (37) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/common/access-protocol.d.ts +38 -0
  4. package/esm/common/auth-protocol.d.ts +64 -0
  5. package/esm/common/auth-protocol.js +1 -0
  6. package/esm/common/index.d.ts +2 -0
  7. package/esm/common/index.js +2 -0
  8. package/esm/common/language.d.ts +25 -0
  9. package/esm/common/language.js +50 -0
  10. package/esm/common/package-protocol.d.ts +6 -1
  11. package/esm/common/package-protocol.js +8 -3
  12. package/esm/common/presence-protocol.d.ts +60 -0
  13. package/esm/common/presence-protocol.js +48 -0
  14. package/esm/common/room-protocol.d.ts +10 -0
  15. package/esm/common/ta-extension-host.d.ts +53 -0
  16. package/esm/common/ta-extension-host.js +6 -0
  17. package/esm/common/ta-protocol.d.ts +6 -0
  18. package/esm/common/team-protocol.d.ts +2 -0
  19. package/esm/common/team-protocol.js +48 -37
  20. package/lib/common/access-protocol.d.ts +38 -0
  21. package/lib/common/auth-protocol.d.ts +64 -0
  22. package/lib/common/auth-protocol.js +2 -1
  23. package/lib/common/index.d.ts +2 -0
  24. package/lib/common/index.js +2 -0
  25. package/lib/common/language.d.ts +26 -0
  26. package/lib/common/language.js +53 -0
  27. package/lib/common/package-protocol.d.ts +6 -1
  28. package/lib/common/package-protocol.js +8 -3
  29. package/lib/common/presence-protocol.d.ts +61 -0
  30. package/lib/common/presence-protocol.js +51 -0
  31. package/lib/common/room-protocol.d.ts +10 -0
  32. package/lib/common/ta-extension-host.d.ts +53 -0
  33. package/lib/common/ta-extension-host.js +7 -1
  34. package/lib/common/ta-protocol.d.ts +6 -0
  35. package/lib/common/team-protocol.d.ts +2 -0
  36. package/lib/common/team-protocol.js +48 -37
  37. package/package.json +3 -3
@@ -4,6 +4,7 @@
4
4
  * owner in one place, by the authorizer a package gives it (TaExtensionHost.team); without one, only the owner
5
5
  * may do anything.
6
6
  */
7
+ import { TaLanguageUtil } from './language.js';
7
8
  /** The user of the Ta: its own pages, devices and token. Everyone else is let in by a package. */
8
9
  export const TA_OWNER = 'owner';
9
10
  /** A principal that holds a link of invitation only: `invite:<id>`. It may only ask to be let in. */
@@ -37,47 +38,47 @@ export var TaPermissionUtil;
37
38
  * `detail` is the TaDenial): the notice of a refused call has a button for it.
38
39
  */
39
40
  export const TA_ACCESS_REQUEST_EVENT = 'ta:access-request';
40
- const action = (id, en, zh, more = {}) => ({
41
+ const action = (id, en, zh, tw, ja, more = {}) => ({
41
42
  id,
42
43
  area: id.split('.')[0],
43
- title: { en, 'zh-CN': zh },
44
+ title: { en, 'zh-CN': zh, ...(tw ? { 'zh-TW': tw } : {}), ...(ja ? { 'ja-JP': ja } : {}) },
44
45
  ...more,
45
46
  });
46
47
  /** Every action of Ta itself; packages add their own (`pi.permissions` of their package.json). */
47
48
  export const TA_ACTIONS = [
48
- action('chat.view', 'See conversations', '查看对话'),
49
- action('chat.send', 'Send in conversations', '在对话里发消息'),
50
- action('chat.create', 'Start conversations', '新建对话'),
51
- action('chat.stop', 'Stop a reply', '停止回复'),
52
- action('chat.manage', 'Rename, archive and close conversations', '改名、归档、关闭对话'),
53
- action('chat.share', 'Share by a link', '生成分享链接'),
54
- action('agent.view', 'See agents', '查看智能体'),
55
- action('agent.use', 'Talk with agents', '和智能体对话'),
56
- action('agent.edit', 'Create, change and remove agents', '新建、修改、删除智能体'),
57
- action('channel.view', 'See channels', '查看频道'),
58
- action('channel.post', 'Post in channels', '在频道里发言'),
59
- action('channel.manage', 'Create and change channels', '新建、管理频道'),
60
- action('task.view', 'See tasks', '查看任务'),
61
- action('task.create', 'Hand out tasks', '派任务'),
62
- action('task.manage', 'Take over and stop tasks', '接管、停止任务'),
63
- action('files.read', 'Read files', '读文件', { scoped: true }),
64
- action('files.write', 'Change files', '改文件', { scoped: true }),
65
- action('commands.run', 'Let Ta run commands', '让 Ta 运行命令', { scoped: true, risky: true }),
66
- action('commands.terminal', 'Open terminals', '打开终端', { scoped: true, risky: true }),
67
- action('hosts.use', 'Use remote hosts', '使用远程主机', { risky: true }),
68
- action('models.use', 'Use the models', '使用模型'),
69
- action('models.manage', 'Sign in to models', '登录和更换模型账号'),
70
- action('cron.view', 'See scheduled tasks', '查看定时任务'),
71
- action('cron.manage', 'Change scheduled tasks', '管理定时任务'),
72
- action('extensions.use', 'Use extensions', '使用扩展'),
73
- action('extensions.install', 'Install and turn off extensions', '安装、停用扩展'),
74
- action('settings.view', 'See settings', '查看设置'),
75
- action('settings.manage', 'Change settings', '修改设置'),
76
- action('members.view', 'See members', '查看成员'),
77
- action('members.invite', 'Invite people', '邀请别人'),
78
- action('members.approve', 'Answer requests', '处理申请'),
79
- action('members.roles', 'Change roles and members', '管理角色和成员'),
80
- action('audit.view', 'See the record', '查看记录'),
49
+ action('chat.view', 'See conversations', '查看对话', '檢視對話', '会話を確認'),
50
+ action('chat.send', 'Send in conversations', '在对话里发消息', '在對話裡發訊息', '会話にメッセージを送信'),
51
+ action('chat.create', 'Start conversations', '新建对话', '新建對話', '新しい会話を開始'),
52
+ action('chat.stop', 'Stop a reply', '停止回复', '停止回覆', '返信を停止'),
53
+ action('chat.manage', 'Rename, archive and close conversations', '改名、归档、关闭对话', '改名、歸檔、關閉對話', '会話の名前変更、アーカイブ、クローズ'),
54
+ action('chat.share', 'Share by a link', '生成分享链接', '生成分享連結', '共有リンクで共有'),
55
+ action('agent.view', 'See agents', '查看智能体', '檢視智慧體', 'エージェントを確認'),
56
+ action('agent.use', 'Talk with agents', '和智能体对话', '和智慧體對話', 'エージェントと対話'),
57
+ action('agent.edit', 'Create, change and remove agents', '新建、修改、删除智能体', '新建、修改、刪除智慧體', 'エージェントを作成・変更・削除'),
58
+ action('channel.view', 'See channels', '查看频道', '檢視頻道', 'チャネルを確認'),
59
+ action('channel.post', 'Post in channels', '在频道里发言', '在頻道里發言', 'チャネルに投稿'),
60
+ action('channel.manage', 'Create and change channels', '新建、管理频道', '新建、管理頻道', 'チャネルを作成・管理'),
61
+ action('task.view', 'See tasks', '查看任务', '檢視任務', 'タスクを確認'),
62
+ action('task.create', 'Hand out tasks', '派任务', '派任務', 'タスクを割り当て'),
63
+ action('task.manage', 'Take over and stop tasks', '接管、停止任务', '接管、停止任務', 'タスクを引き継ぎ・停止'),
64
+ action('files.read', 'Read files', '读文件', '讀檔案', 'ファイルを読取', { scoped: true }),
65
+ action('files.write', 'Change files', '改文件', '改檔案', 'ファイルを変更', { scoped: true }),
66
+ action('commands.run', 'Let Ta run commands', '让 Ta 运行命令', '讓 Ta 執行命令', 'Ta にコマンド実行を許可', { scoped: true, risky: true }),
67
+ action('commands.terminal', 'Open terminals', '打开终端', '開啟終端機', 'ターミナルを開く', { scoped: true, risky: true }),
68
+ action('hosts.use', 'Use remote hosts', '使用远程主机', '使用遠端主機', 'リモートホストを使用', { risky: true }),
69
+ action('models.use', 'Use the models', '使用模型', '使用模型', 'モデルを使用'),
70
+ action('models.manage', 'Sign in to models', '登录和更换模型账号', '登入和更換模型帳號', 'モデルアカウントにサインイン・変更'),
71
+ action('cron.view', 'See scheduled tasks', '查看定时任务', '檢視定時任務', 'スケジュールタスクを確認'),
72
+ action('cron.manage', 'Change scheduled tasks', '管理定时任务', '管理定時任務', 'スケジュールタスクを管理'),
73
+ action('extensions.use', 'Use extensions', '使用扩展', '使用擴充功能', '拡張機能を使用'),
74
+ action('extensions.install', 'Install and turn off extensions', '安装、停用扩展', '安裝、停用擴充功能', '拡張機能をインストール・無効化'),
75
+ action('settings.view', 'See settings', '查看设置', '檢視設定', '設定を確認'),
76
+ action('settings.manage', 'Change settings', '修改设置', '修改設定', '設定を変更'),
77
+ action('members.view', 'See members', '查看成员', '檢視成員', 'メンバーを確認'),
78
+ action('members.invite', 'Invite people', '邀请别人', '邀請別人', 'メンバーを招待'),
79
+ action('members.approve', 'Answer requests', '处理申请', '處理申請', 'リクエストに対応'),
80
+ action('members.roles', 'Change roles and members', '管理角色和成员', '管理角色和成員', 'ロールとメンバーを管理'),
81
+ action('audit.view', 'See the record', '查看记录', '檢視記錄', 'レコードを確認'),
81
82
  ];
82
83
  export var TaActionUtil;
83
84
  (function (TaActionUtil) {
@@ -88,8 +89,18 @@ export var TaActionUtil;
88
89
  TaActionUtil.info = info;
89
90
  /** Its title in a language such as `zh-CN`; the id for an action of no catalog. */
90
91
  function title(id, language) {
91
- const found = byId.get(id);
92
- return found ? (language.startsWith('zh') ? found.title['zh-CN'] : found.title.en) : id;
92
+ var _a;
93
+ var _b, _c;
94
+ const title = (_a = byId.get(id)) === null || _a === void 0 ? void 0 : _a.title;
95
+ if (!title) {
96
+ return id;
97
+ }
98
+ return TaLanguageUtil.pick(language, {
99
+ 'zh-CN': title['zh-CN'],
100
+ 'zh-TW': (_b = title['zh-TW']) !== null && _b !== void 0 ? _b : title['zh-CN'],
101
+ 'en-US': title.en,
102
+ 'ja-JP': (_c = title['ja-JP']) !== null && _c !== void 0 ? _c : title.en,
103
+ });
93
104
  }
94
105
  TaActionUtil.title = title;
95
106
  /** Whether `path` is `dir` or inside it; both absolute, `/` separated. */
@@ -13,6 +13,11 @@ export interface TaSignInProvider {
13
13
  id: string;
14
14
  /** What the button says: GitHub, Google, WeChat, or the name of the operator's provider. */
15
15
  name: string;
16
+ /**
17
+ * One signs in by typing a code at the provider (OAuth 2.0's device flow, as GitHub's), not by going there and coming
18
+ * back: Ta's own GitHub app, which needs no secret, for those asking to come in (docs/design/ta-team.md 17.4).
19
+ */
20
+ device?: true;
16
21
  }
17
22
  /** The answer of `GET` {@link TA_SIGN_IN_PATH}. */
18
23
  export interface TaSignInWays {
@@ -56,8 +61,41 @@ export interface TaAccessInfo {
56
61
  requests: TaAccessRequest[];
57
62
  signIns: TaAccessSignIn[];
58
63
  }
64
+ /** The kinds of providers ta serve signs in with: GitHub, Google, WeChat (a website app), an OpenID Connect provider. */
65
+ export type TaSignInKind = 'github' | 'google' | 'wechat' | 'oidc';
66
+ /** A kind of provider as configured: its fields but the secret, which is only said to be there. */
67
+ export interface TaSignInSetup {
68
+ id: TaSignInKind;
69
+ name: string;
70
+ /** It has its id and its secret: it is offered. */
71
+ configured: boolean;
72
+ /** `env`: the environment of ta serve sets it, which this cannot change; `file`: sign-in.json of the agent directory. */
73
+ source?: 'env' | 'file';
74
+ /** `clientId` (`appId` for WeChat), and `url` (GitHub Enterprise), `issuer` and `name` (OpenID Connect). */
75
+ fields: Record<string, string>;
76
+ /** A secret is kept. */
77
+ secret: boolean;
78
+ /** Not set up, yet those asking to come in sign in with it by a code, with Ta's own app (GitHub's device flow). */
79
+ device?: boolean;
80
+ }
81
+ /** The ways to sign in, to set them up (Settings, Access), and where providers send the browser back. */
82
+ export interface TaSignInConfig {
83
+ providers: TaSignInSetup[];
84
+ /** Register these with a provider: the page of joining by a link on the relay, ta serve's own when it has an address. */
85
+ callbacks: {
86
+ join?: string;
87
+ serve?: string;
88
+ };
89
+ }
59
90
  /** Who may reach this ta serve with an account, for whoever is in (with the token, or an account let in). */
60
91
  export interface TaAccessServer {
92
+ /** The ways to sign in as set up; only the owner. */
93
+ getSignInConfig(): Promise<TaSignInConfig>;
94
+ /**
95
+ * Sets up a kind of provider in sign-in.json, offered at once; `null` takes it out. An empty secret keeps the one kept.
96
+ * One the environment sets is not changed here.
97
+ */
98
+ setSignInProvider(id: TaSignInKind, fields: Record<string, string> | null): Promise<void>;
61
99
  getAccess(): Promise<TaAccessInfo>;
62
100
  /**
63
101
  * Where the browser goes to sign in with `provider` and let that account in at once: the owner, in with
@@ -19,6 +19,60 @@ export interface TaAuthProvider {
19
19
  };
20
20
  /** pi keeps a credential of it in auth.json, which `logout` removes. */
21
21
  stored: boolean;
22
+ /** The user added it by its address (`saveCustomProvider`): it is changed there, not signed in to. */
23
+ custom?: boolean;
24
+ }
25
+ /** What the endpoint of a provider added by its address speaks, as `api` of pi's models.json; most services speak the first. */
26
+ export type TaCustomApi = 'openai-completions' | 'openai-responses' | 'anthropic-messages' | 'google-generative-ai';
27
+ export declare const TA_CUSTOM_APIS: readonly TaCustomApi[];
28
+ /**
29
+ * A provider of models the user added by its address and key (a compatible service, a gateway, a server on their
30
+ * computer), kept in pi's models.json of ta serve.
31
+ */
32
+ export interface TaCustomProvider {
33
+ /** Its key under `providers` of models.json, which is pi's id of the provider. */
34
+ id: string;
35
+ name: string;
36
+ api: TaCustomApi;
37
+ baseUrl: string;
38
+ /** It has a key; the key never leaves ta serve. */
39
+ hasKey: boolean;
40
+ /** The ids of its models. */
41
+ models: string[];
42
+ /** What its models are, of those every model has alike. */
43
+ options: TaCustomModelOptions;
44
+ /** What its models do not have alike: left out of a save, each keeps its own. */
45
+ mixed: (keyof TaCustomModelOptions)[];
46
+ /** The names of the headers it sends; their values stay on ta serve. */
47
+ headers: string[];
48
+ }
49
+ /**
50
+ * What the models of a provider added by its address are, as fields of each model of pi's models.json; left out, pi
51
+ * takes 128000 tokens of context, 16384 of output, no thinking and text alone.
52
+ */
53
+ export interface TaCustomModelOptions {
54
+ contextWindow?: number;
55
+ maxTokens?: number;
56
+ /** It thinks before it answers (pi's `reasoning`): the thinking levels of the + apply. */
57
+ reasoning?: boolean;
58
+ /** It takes pictures (`input` of text and image). */
59
+ images?: boolean;
60
+ }
61
+ /** A provider to save: without `id` it is added. `apiKey` left out keeps the key it has, empty removes it. */
62
+ export interface TaCustomProviderInput {
63
+ id?: string;
64
+ /** Left blank, the host of `baseUrl`. */
65
+ name?: string;
66
+ api: TaCustomApi;
67
+ baseUrl: string;
68
+ apiKey?: string;
69
+ models: string[];
70
+ /** For every model: a field left out keeps what each has, null removes it. */
71
+ options?: {
72
+ [K in keyof TaCustomModelOptions]?: TaCustomModelOptions[K] | null;
73
+ };
74
+ /** Every header it sends, left out keeping them as they are: an empty value keeps the one it has. */
75
+ headers?: Record<string, string>;
22
76
  }
23
77
  /** What a sign-in asks the user, as pi's AuthPrompt: an answer goes back with `answer`, a choice by its id. */
24
78
  export type TaAuthPrompt = {
@@ -86,5 +140,15 @@ export interface TaAuthServer {
86
140
  cancel(loginId: string): Promise<void>;
87
141
  /** Removes the stored credential of the provider. */
88
142
  logout(providerId: string): Promise<void>;
143
+ /** The providers the user added by their address. */
144
+ listCustomProviders(): Promise<TaCustomProvider[]>;
145
+ /** Adds or changes one; its models can be picked at once, and the open sessions without a model take its first. */
146
+ saveCustomProvider(input: TaCustomProviderInput): Promise<TaCustomProvider>;
147
+ removeCustomProvider(id: string): Promise<void>;
148
+ /**
149
+ * The ids of the models the service lists (its `/models`), asked by ta serve with the key given, else with the key
150
+ * kept of the provider `id`.
151
+ */
152
+ fetchCustomModels(input: Pick<TaCustomProviderInput, 'id' | 'api' | 'baseUrl' | 'apiKey' | 'headers'>): Promise<string[]>;
89
153
  }
90
154
  //# sourceMappingURL=auth-protocol.d.ts.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TA_AUTH_SERVICE = exports.TaAuthServer = void 0;
3
+ exports.TA_CUSTOM_APIS = exports.TA_AUTH_SERVICE = exports.TaAuthServer = void 0;
4
4
  exports.TaAuthServer = Symbol('TaAuthServer');
5
5
  exports.TA_AUTH_SERVICE = 'TaAuthServer';
6
+ exports.TA_CUSTOM_APIS = ['openai-completions', 'openai-responses', 'anthropic-messages', 'google-generative-ai'];
6
7
  //# sourceMappingURL=auth-protocol.js.map
@@ -1,9 +1,11 @@
1
1
  export * from './access-protocol';
2
2
  export * from './auth-protocol';
3
3
  export * from './gateway-protocol';
4
+ export * from './language';
4
5
  export * from './location';
5
6
  export * from './package-protocol';
6
7
  export * from './pi-types';
8
+ export * from './presence-protocol';
7
9
  export * from './relay-protocol';
8
10
  export * from './remote-protocol';
9
11
  export * from './room-protocol';
@@ -17,9 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./access-protocol"), exports);
18
18
  __exportStar(require("./auth-protocol"), exports);
19
19
  __exportStar(require("./gateway-protocol"), exports);
20
+ __exportStar(require("./language"), exports);
20
21
  __exportStar(require("./location"), exports);
21
22
  __exportStar(require("./package-protocol"), exports);
22
23
  __exportStar(require("./pi-types"), exports);
24
+ __exportStar(require("./presence-protocol"), exports);
23
25
  __exportStar(require("./relay-protocol"), exports);
24
26
  __exportStar(require("./remote-protocol"), exports);
25
27
  __exportStar(require("./room-protocol"), exports);
@@ -0,0 +1,26 @@
1
+ /** A language of Ta's pages and of what its packages say to the user. */
2
+ export type TaLanguage = 'zh-CN' | 'zh-TW' | 'en-US' | 'ja-JP';
3
+ export declare namespace TaLanguageUtil {
4
+ /** In the order the settings list them. */
5
+ const ALL: readonly TaLanguage[];
6
+ /** The name of each, in itself. */
7
+ const NAMES: Readonly<Record<TaLanguage, string>>;
8
+ /**
9
+ * The language of a tag (`zh-HK`, `ja`, `zh_TW.UTF-8` of `LANG`): Traditional Chinese for Taiwan, Hong Kong,
10
+ * Macau and `Hant`, Simplified for other Chinese, Japanese for Japanese, English for the rest.
11
+ */
12
+ function of(tag: string | undefined): TaLanguage;
13
+ /** The language of what the server says: that of Ta's pages (`TA_LANGUAGE`, see TaSettingsServer.setLanguage), else the computer's. */
14
+ function server(env?: Record<string, string | undefined>): TaLanguage;
15
+ /** The words of a language, of one for each. */
16
+ function pick<T>(language: string, words: Readonly<Record<TaLanguage, T>>): T;
17
+ /** The words of the language of the server (`server()`), of one for each. */
18
+ function say<T>(words: Readonly<Record<TaLanguage, T>>): T;
19
+ /** Chinese, either. */
20
+ function chinese(language: string): boolean;
21
+ /** Chinese or Japanese: words go without spaces, lists join with 、, a colon is :. */
22
+ function cjk(language: string): boolean;
23
+ /** A list of names in a language: `a、b`, `a, b`. */
24
+ function list(language: string, items: readonly string[]): string;
25
+ }
26
+ //# sourceMappingURL=language.d.ts.map
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaLanguageUtil = void 0;
4
+ var TaLanguageUtil;
5
+ (function (TaLanguageUtil) {
6
+ /** In the order the settings list them. */
7
+ TaLanguageUtil.ALL = ['zh-CN', 'zh-TW', 'en-US', 'ja-JP'];
8
+ /** The name of each, in itself. */
9
+ TaLanguageUtil.NAMES = { 'zh-CN': '简体中文', 'zh-TW': '繁體中文', 'en-US': 'English', 'ja-JP': '日本語' };
10
+ /**
11
+ * The language of a tag (`zh-HK`, `ja`, `zh_TW.UTF-8` of `LANG`): Traditional Chinese for Taiwan, Hong Kong,
12
+ * Macau and `Hant`, Simplified for other Chinese, Japanese for Japanese, English for the rest.
13
+ */
14
+ function of(tag) {
15
+ const said = (tag !== null && tag !== void 0 ? tag : '').toLowerCase().replace(/_/g, '-');
16
+ if (/^zh(\b|-)/.test(said)) {
17
+ return /-hant\b/.test(said) || (!/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said)) ? 'zh-TW' : 'zh-CN';
18
+ }
19
+ return /^ja(\b|-)/.test(said) ? 'ja-JP' : 'en-US';
20
+ }
21
+ TaLanguageUtil.of = of;
22
+ /** The language of what the server says: that of Ta's pages (`TA_LANGUAGE`, see TaSettingsServer.setLanguage), else the computer's. */
23
+ function server(env = typeof process === 'undefined' ? {} : process.env) {
24
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
25
+ }
26
+ TaLanguageUtil.server = server;
27
+ /** The words of a language, of one for each. */
28
+ function pick(language, words) {
29
+ return words[of(language)];
30
+ }
31
+ TaLanguageUtil.pick = pick;
32
+ /** The words of the language of the server (`server()`), of one for each. */
33
+ function say(words) {
34
+ return words[server()];
35
+ }
36
+ TaLanguageUtil.say = say;
37
+ /** Chinese, either. */
38
+ function chinese(language) {
39
+ return of(language).startsWith('zh');
40
+ }
41
+ TaLanguageUtil.chinese = chinese;
42
+ /** Chinese or Japanese: words go without spaces, lists join with 、, a colon is :. */
43
+ function cjk(language) {
44
+ return of(language) !== 'en-US';
45
+ }
46
+ TaLanguageUtil.cjk = cjk;
47
+ /** A list of names in a language: `a、b`, `a, b`. */
48
+ function list(language, items) {
49
+ return items.join(cjk(language) ? '、' : ', ');
50
+ }
51
+ TaLanguageUtil.list = list;
52
+ })(TaLanguageUtil || (exports.TaLanguageUtil = TaLanguageUtil = {}));
53
+ //# sourceMappingURL=language.js.map
@@ -25,6 +25,8 @@ export interface TaWebExtensionInfo {
25
25
  enabled: boolean;
26
26
  /** The source in the `packages` setting, or the directory. */
27
27
  source: string;
28
+ /** Its directory, on the machine of the server: where `fileUrl` of the web extension finds its files. Not from an older ta serve. */
29
+ root?: string;
28
30
  /** The file, relative to the package. */
29
31
  entry: string;
30
32
  /** Changes when the file changes. */
@@ -69,7 +71,10 @@ export type TaPackageResource = 'extensions' | 'web' | 'skills' | 'prompts' | 't
69
71
  /** Text of a package for people, as `pi.title` and `pi.summary` of its package.json give it: one string, or one per language (`en`, `zh-CN`). */
70
72
  export type TaPackageText = string | Readonly<Record<string, string>>;
71
73
  export declare namespace TaPackageTextUtil {
72
- /** The text in a language such as `zh-CN`: that language, else its first part (`zh`), else English, else the first there is. */
74
+ /**
75
+ * The text in a language such as `zh-TW`: that language, else its first part (`zh`), else another of that part
76
+ * (`zh-CN` for `zh-TW`), else English, else the first there is.
77
+ */
73
78
  function pick(text: TaPackageText | undefined, language: string): string | undefined;
74
79
  }
75
80
  /** A pi package that Ta loads, whether it has a web extension or not. */
@@ -5,13 +5,18 @@ exports.TaPackageServer = Symbol('TaPackageServer');
5
5
  exports.TA_PACKAGE_SERVICE = 'TaPackageServer';
6
6
  var TaPackageTextUtil;
7
7
  (function (TaPackageTextUtil) {
8
- /** The text in a language such as `zh-CN`: that language, else its first part (`zh`), else English, else the first there is. */
8
+ /**
9
+ * The text in a language such as `zh-TW`: that language, else its first part (`zh`), else another of that part
10
+ * (`zh-CN` for `zh-TW`), else English, else the first there is.
11
+ */
9
12
  function pick(text, language) {
10
- var _a, _b, _c, _d;
13
+ var _a, _b, _c, _d, _e;
11
14
  if (text === undefined || typeof text === 'string') {
12
15
  return text;
13
16
  }
14
- return (_d = (_c = (_b = (_a = text[language]) !== null && _a !== void 0 ? _a : text[language.split('-')[0]]) !== null && _b !== void 0 ? _b : text.en) !== null && _c !== void 0 ? _c : text['en-US']) !== null && _d !== void 0 ? _d : Object.values(text)[0];
17
+ const base = language.split('-')[0];
18
+ const kin = Object.keys(text).find(key => key.split('-')[0] === base);
19
+ return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== void 0 ? _a : text[base]) !== null && _b !== void 0 ? _b : (kin === undefined ? undefined : text[kin])) !== null && _c !== void 0 ? _c : text.en) !== null && _d !== void 0 ? _d : text['en-US']) !== null && _e !== void 0 ? _e : Object.values(text)[0];
15
20
  }
16
21
  TaPackageTextUtil.pick = pick;
17
22
  })(TaPackageTextUtil || (exports.TaPackageTextUtil = TaPackageTextUtil = {}));
@@ -0,0 +1,61 @@
1
+ export declare const TaPresenceServer: unique symbol;
2
+ export declare const TA_PRESENCE_SERVICE = "TaPresenceServer";
3
+ /** A page says what it is at again this often while it lasts, the same or not. */
4
+ export declare const TA_PRESENCE_HEARTBEAT_MS = 20000;
5
+ /** A page that said nothing for this long is gone, its connection open or not. */
6
+ export declare const TA_PRESENCE_EXPIRY_MS = 60000;
7
+ /** What a page of Ta is at now (TaPresenceServer.report). */
8
+ export interface TaPresenceReport {
9
+ /** The conversation the user looks at, in a page shown; none while the page is hidden or shows no conversation. */
10
+ sessionId?: string;
11
+ /** They are typing in its message box. */
12
+ typing?: boolean;
13
+ }
14
+ /**
15
+ * Who else is in this Ta, and where (docs/design/ta-team.md 7): each page says what it is at, as it changes and every
16
+ * TA_PRESENCE_HEARTBEAT_MS; ta serve tells the others through the list of sessions (TaSessionInfo.people), only of the
17
+ * conversations each may see, and keeps nothing on disk.
18
+ */
19
+ export interface TaPresenceServer {
20
+ report(state: TaPresenceReport): Promise<void>;
21
+ }
22
+ /** Someone else at a conversation now, as a page is told (TaSessionInfo.people): never the page's own principal. */
23
+ export interface TaSessionPerson {
24
+ /** TA_OWNER, or the principal of one let in. */
25
+ id: string;
26
+ name: string;
27
+ /** Looks at it, in a page shown. */
28
+ viewing?: boolean;
29
+ /** Types in its message box. */
30
+ typing?: boolean;
31
+ /** Asked the run going on. */
32
+ asked?: boolean;
33
+ }
34
+ /** One person with pages of Ta open, and where the latest of them is (TaPresence.people). */
35
+ export interface TaPresencePerson {
36
+ /** TA_OWNER, or the principal of one let in. */
37
+ id: string;
38
+ name: string;
39
+ /** Their pages that say what they are at. */
40
+ pages: number;
41
+ /** The conversation the latest of them looks at. */
42
+ sessionId?: string;
43
+ typing?: boolean;
44
+ }
45
+ /**
46
+ * A message of the user sent by one let in says who in a line of its `<context>`, `[ta:by <principal> <name>]`: the
47
+ * page shows it as theirs, the model reads who asked. ta serve writes it, and takes out any such line a page wrote, so
48
+ * that no one sends as another.
49
+ */
50
+ export declare namespace TaMessageAuthor {
51
+ /** `message` without the lines of an author. */
52
+ function strip(message: string): string;
53
+ /** `message` as written by `id`, called `name`; a command (`/compact`, `!ls`) stays a command. */
54
+ function mark(message: string, id: string, name: string): string;
55
+ /** Who wrote it; undefined for the user of the Ta (no line). */
56
+ function of(message: string): {
57
+ id: string;
58
+ name: string;
59
+ } | undefined;
60
+ }
61
+ //# sourceMappingURL=presence-protocol.d.ts.map
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaMessageAuthor = exports.TA_PRESENCE_EXPIRY_MS = exports.TA_PRESENCE_HEARTBEAT_MS = exports.TA_PRESENCE_SERVICE = exports.TaPresenceServer = void 0;
4
+ const ta_protocol_1 = require("./ta-protocol");
5
+ exports.TaPresenceServer = Symbol('TaPresenceServer');
6
+ exports.TA_PRESENCE_SERVICE = 'TaPresenceServer';
7
+ /** A page says what it is at again this often while it lasts, the same or not. */
8
+ exports.TA_PRESENCE_HEARTBEAT_MS = 20000;
9
+ /** A page that said nothing for this long is gone, its connection open or not. */
10
+ exports.TA_PRESENCE_EXPIRY_MS = 60000;
11
+ /**
12
+ * A message of the user sent by one let in says who in a line of its `<context>`, `[ta:by <principal> <name>]`: the
13
+ * page shows it as theirs, the model reads who asked. ta serve writes it, and takes out any such line a page wrote, so
14
+ * that no one sends as another.
15
+ */
16
+ var TaMessageAuthor;
17
+ (function (TaMessageAuthor) {
18
+ const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
19
+ const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
20
+ /** `message` without the lines of an author. */
21
+ function strip(message) {
22
+ const context = ta_protocol_1.TaMessageContext.read(message);
23
+ if (context === undefined || !LINE.test(context)) {
24
+ return message;
25
+ }
26
+ const kept = context.replace(LINES, '').replace(/\n+$/, '');
27
+ const body = ta_protocol_1.TaMessageContext.strip(message);
28
+ return kept.trim() ? ta_protocol_1.TaMessageContext.wrap(kept, body) : body;
29
+ }
30
+ TaMessageAuthor.strip = strip;
31
+ /** `message` as written by `id`, called `name`; a command (`/compact`, `!ls`) stays a command. */
32
+ function mark(message, id, name) {
33
+ const plain = strip(message);
34
+ if (/^[/!]/.test(plain)) {
35
+ return plain;
36
+ }
37
+ const line = `[ta:by ${id.replace(/[\s\]]/g, '')} ${name.replace(/[\]\n]/g, ' ').trim() || id}]`;
38
+ const context = ta_protocol_1.TaMessageContext.read(plain);
39
+ return ta_protocol_1.TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, ta_protocol_1.TaMessageContext.strip(plain));
40
+ }
41
+ TaMessageAuthor.mark = mark;
42
+ /** Who wrote it; undefined for the user of the Ta (no line). */
43
+ function of(message) {
44
+ var _a;
45
+ const context = ta_protocol_1.TaMessageContext.read(message);
46
+ const match = context === undefined ? null : LINE.exec(context);
47
+ return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== void 0 ? _a : match[1]).trim() } : undefined;
48
+ }
49
+ TaMessageAuthor.of = of;
50
+ })(TaMessageAuthor || (exports.TaMessageAuthor = TaMessageAuthor = {}));
51
+ //# sourceMappingURL=presence-protocol.js.map
@@ -11,6 +11,8 @@ export type TaRoomStatus = 'member' | 'waiting' | 'refused' | 'gone';
11
11
  export interface TaIdentity {
12
12
  id: string;
13
13
  name: string;
14
+ /** The kind of dinosaur its double is (a species of the page, TA_DOUBLE_LOOK): drawn as that double. None from a Ta of before. */
15
+ look?: string;
14
16
  /**
15
17
  * The user's other computers are this Ta too (ta-sync shares the identity, or a move brought it): what answers in a
16
18
  * room agrees first which computer does (docs/design/ta-sync.md 9).
@@ -23,6 +25,8 @@ export interface TaRoomMember {
23
25
  /** The identity of its Ta. */
24
26
  id: string;
25
27
  name: string;
28
+ /** The kind of dinosaur its double is (a species of the page, TA_DOUBLE_LOOK): drawn as that double. None from a Ta of before. */
29
+ look?: string;
26
30
  owner: boolean;
27
31
  online: boolean;
28
32
  self: boolean;
@@ -63,6 +67,8 @@ export interface TaRoomRequest {
63
67
  /** Its identity, and the name it gives. */
64
68
  id: string;
65
69
  name: string;
70
+ /** The kind of dinosaur its double is (a species of the page, TA_DOUBLE_LOOK): drawn as that double. None from a Ta of before. */
71
+ look?: string;
66
72
  /** A friend of the user. */
67
73
  friend: boolean;
68
74
  /** Asks from a browser, without Ta: admitted, it only chats. */
@@ -76,6 +82,8 @@ export interface TaRoomRequest {
76
82
  export interface TaFriend {
77
83
  id: string;
78
84
  name: string;
85
+ /** The kind of dinosaur its double is (a species of the page, TA_DOUBLE_LOOK): drawn as that double. None from a Ta of before. */
86
+ look?: string;
79
87
  status: 'friend' | 'adding';
80
88
  online: boolean;
81
89
  metAt: number;
@@ -85,6 +93,8 @@ export interface TaFriend {
85
93
  export interface TaFriendRequest {
86
94
  id: string;
87
95
  name: string;
96
+ /** The kind of dinosaur its double is (a species of the page, TA_DOUBLE_LOOK): drawn as that double. None from a Ta of before. */
97
+ look?: string;
88
98
  at: number;
89
99
  via: 'link' | 'room';
90
100
  room?: string;
@@ -1,4 +1,6 @@
1
+ import type { TaSignInProvider } from './access-protocol';
1
2
  import type { TaPackageServer } from './package-protocol';
3
+ import type { TaPresencePerson } from './presence-protocol';
2
4
  import type { TaRelayFeature, TaRelayService, TaRelayStore, TaRelayType, TaShares } from './relay-protocol';
3
5
  import type { TaRooms } from './room-protocol';
4
6
  import type { TaServer } from './ta-protocol';
@@ -173,6 +175,45 @@ export interface TaHostTeam {
173
175
  unpair(deviceId: string): void;
174
176
  /** The devices of principals other than the owner. */
175
177
  devices(): TaTeamDevice[];
178
+ /** Accounts of the providers ta serve signs in with, to know who one asking to come in is (docs/design/ta-team.md 17). */
179
+ readonly accounts: TaHostAccounts;
180
+ }
181
+ /** An account as its provider says it: `github:<login>`, `google:<email>`, `wechat:<unionid>`, `oidc:<email or sub>`. */
182
+ export interface TaAccount {
183
+ id: string;
184
+ name?: string;
185
+ avatar?: string;
186
+ }
187
+ /**
188
+ * Signing in with an account to say who one is, not to come into ta serve (that is TaAccessServer): the browser goes to
189
+ * the provider and back to `redirectUri` with a code, which ta serve turns into the account with the secret of the
190
+ * provider and PKCE's verifier, both kept here. Whoever sees the code on its way (the relay of a page it serves) can do
191
+ * nothing with it.
192
+ */
193
+ export interface TaHostAccounts {
194
+ /** Those configured (the environment, sign-in.json of the agent directory); none: no one signs in. */
195
+ providers(): TaSignInProvider[];
196
+ /** Where the browser goes and the state it comes back with, or, for a provider of `device`, the code to type at it. */
197
+ start(provider: string, redirectUri: string): Promise<TaAccountStart>;
198
+ /** The account of a code, for a state `start` gave (once, for 10 minutes); throws when the provider refuses it. */
199
+ verify(state: string, code: string): Promise<TaAccount>;
200
+ /**
201
+ * The account of a sign-in by a code (`device` of {@link start}) once it was typed at the provider and agreed to,
202
+ * waiting for it up to `waitMs`: undefined while not yet; throws when it was refused, or ran out.
203
+ */
204
+ typed(state: string, waitMs?: number): Promise<TaAccount | undefined>;
205
+ }
206
+ /** A sign-in started: `url`, where the browser goes; `device`, the code to type at the provider's `uri` instead. */
207
+ export interface TaAccountStart {
208
+ state: string;
209
+ url?: string;
210
+ device?: TaAccountCode;
211
+ }
212
+ /** The code of a sign-in by a code (GitHub's device flow): typed at `uri` by `expiresAt`, by whoever signs in. */
213
+ export interface TaAccountCode {
214
+ code: string;
215
+ uri: string;
216
+ expiresAt: number;
176
217
  }
177
218
  /** A device of a principal, and what reaches this Ta with it (RelayPairing). The key goes to that principal alone. */
178
219
  export interface TaTeamPairing {
@@ -196,6 +237,8 @@ export interface TaPresence {
196
237
  pages: number;
197
238
  /** `Date.now()` time a page was last connected: now while one is. 0 for never since the service started. */
198
239
  seenAt: number;
240
+ /** Each one with pages that say what they are at (TaPresenceServer), the user (TA_OWNER) and those let in, and where. */
241
+ people: TaPresencePerson[];
199
242
  }
200
243
  /**
201
244
  * Where the web client keeps the session file of the double's conversation: in the data of packages
@@ -206,6 +249,16 @@ export declare const TA_DOUBLE_FILE: {
206
249
  readonly name: '@celljs/ta-web';
207
250
  readonly key: 'assistant.file';
208
251
  };
252
+ /**
253
+ * Where the web client keeps the kind of dinosaur the double is (`trex` till the user picks another): in the data of
254
+ * packages, under this name and key, a JSON string. It is the look of this Ta that others see (TaIdentity.look): the
255
+ * rooms of ta serve tell it to the Ta of friends and rooms.
256
+ */
257
+ export declare const TA_DOUBLE_LOOK: {
258
+ readonly name: '@celljs/ta-web';
259
+ readonly key: 'assistant.species';
260
+ readonly initial: 'trex';
261
+ };
209
262
  /**
210
263
  * Where the web client keeps the tasks the double handed out: in the data of packages, under this name and key; an
211
264
  * array of `{ sessionId, sessionFile?, takenOver?, removed? }` among other fields. The double tells the user of these