@celljs/ta-protocol 4.14.0 → 4.15.1

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.
package/README.en.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Protocol between `ta serve` and clients: types and constants only, with no pi or Node.js modules loaded, so it works in browsers.
4
4
 
5
5
  - **Transport**: one WebSocket (`TA_WEBSOCKET_PATH`) with JSON-RPC 2.0 messages. Method names are `<service>/<method>`, and the server pushes `TaClient/onEvents` etc. HTTP-based calls are not offered; only workspace file bytes travel HTTP (`TA_FILES_PATH`, for images and iframes in pages to load via relative URLs).
6
- - **Services**: `TaServer` (sessions—pi's RPC commands), `TaWorkspaceServer` (files and commands in directories), `TaTerminalServer` (terminals), `TaSettingsServer` (pi's `settings.json`), `TaPackageServer` (packages, web extensions, and package data), `TaAuthServer` (login to model services, same as pi's `/login` and `/logout`), `TaRelayServer` (paired devices via Relay, same as `ta pair`), `TaRemoteServer` (hosts for `ssh://` directories, ssh prompts, port forwarding). Capabilities outside sessions split into separate services by responsibility, not added to `TaServer`.
6
+ - **Services**: `TaServer` (sessions—pi's RPC commands), `TaWorkspaceServer` (files and commands in directories), `TaTerminalServer` (terminals), `TaSettingsServer` (pi's `settings.json`), `TaPackageServer` (packages, web extensions, and package data), `TaAuthServer` (login to model services, same as pi's `/login` and `/logout`; custom model services added by their address and key), `TaRelayServer` (paired devices via Relay, same as `ta pair`), `TaRemoteServer` (hosts for `ssh://` directories, ssh prompts, port forwarding). Capabilities outside sessions split into separate services by responsibility, not added to `TaServer`.
7
7
  - **`TaServer` methods**: besides `openSession`, `closeSession`, `listSessions`, `attach`, `detach`, `respondUi`, and `respondClientTool`, the rest are pi RPC mode commands with the same name (snake_case → camelCase, see `PiCommandMethod`). The first parameter is `sessionId`, and return values match pi's; when pi adds an RPC command and `TaServer` lacks the method, this package's tests won't compile. `listSavedSessions` lists the conversations in pi's session files that are not open (closed while idle, or before a restart); `openSession` with their `sessionFile` opens them again (with the `sessionId` they had). A session closed while idle or by a restart also opens again by itself when any method is called with its old `sessionId`; only one closed with `closeSession`, or whose file is gone, gives `CELL_TA_SESSION_NOT_FOUND`. A session a package opened for its `group` gets a pi custom entry `ta-group` in its file, so the list carries its `group` and the package reopens it with its role; the role it was opened with (`appendSystemPrompt`) gets an entry `ta-role`, and opened again with only its `sessionFile` (a bot passing a message to a closed conversation of an agent) a session keeps the role and group written there. The page of the double keeps the session file of its conversation in the data `TA_DOUBLE_FILE` (`assistant.file` of `@celljs/ta-web`), by which packages on the server find the double. `setWorkingDirectory` sets ta serve's working directory (`TaServerInfo.cwd`, used when clients don't specify one, persists across restarts). Session operations not in pi RPC: `forkToFile` (saves the forked session to a file, current session untouched, then open with `openSession`), `navigateTree` (same as pi's `/tree`, returns `editorText`), `fork` has an optional `position` (`at` keeps the selected item, like pi's `/clone` but optional for any item).
8
8
  - **Events**: `TaEventEnvelope { sessionId, seq, event }`, where `event` is a pi JSON/RPC mode event or `extension_ui_request`. Ta adds only `ui_request_resolved`, `extension_error`, `session_replaced`, `session_reloaded`, `session_closed`, `working_message` (what an extension says the agent does, with pi's `setWorkingMessage`), and `client_tool_request` (reserved).
9
9
  - **`prompt` / `steer` / `followUp`**: carry client-generated `clientMessageId`. Retrying with the same ID returns `duplicate` and doesn't re-execute. Receipt only means accepted; the round end is marked by the `agent_settled` event.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `ta serve` 与客户端之间的协议:只有类型和常量,不加载 pi 和 Node.js 模块,浏览器可用。
4
4
 
5
5
  - 传输:一条 WebSocket(`TA_WEBSOCKET_PATH`)上的 JSON-RPC 2.0,方法名是 `<服务>/<方法>`,服务端推送 `TaClient/onEvents` 等。不提供 HTTP 形式的调用;只有工作区文件的字节走 HTTP(`TA_FILES_PATH`,供页面里的图片、iframe 用相对地址加载)。
6
- - 服务:`TaServer`(会话,即 pi 的 RPC 命令)、`TaWorkspaceServer`(目录里的文件与命令)、`TaTerminalServer`(终端)、`TaSettingsServer`(pi 的 `settings.json`)、`TaPackageServer`(包、Web 扩展与包的数据)、`TaAuthServer`(登录模型服务,同 pi 的 `/login` `/logout`)、`TaRelayServer`(经 Relay 配对设备,同 `ta pair`)、`TaRemoteServer`(`ssh://` 目录的主机、ssh 的提问、端口转发)。会话之外的能力按职责各成一个服务,不往 `TaServer` 里加。
6
+ - 服务:`TaServer`(会话,即 pi 的 RPC 命令)、`TaWorkspaceServer`(目录里的文件与命令)、`TaTerminalServer`(终端)、`TaSettingsServer`(pi 的 `settings.json`)、`TaPackageServer`(包、Web 扩展与包的数据)、`TaAuthServer`(登录模型服务,同 pi 的 `/login` `/logout`;按地址和 Key 添加的自定义模型服务)、`TaRelayServer`(经 Relay 配对设备,同 `ta pair`)、`TaRemoteServer`(`ssh://` 目录的主机、ssh 的提问、端口转发)。会话之外的能力按职责各成一个服务,不往 `TaServer` 里加。
7
7
  - `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。`listSavedSessions` 列出 pi 会话文件里没打开的对话(空闲回收或重启前关掉的),用其 `sessionFile` 调 `openSession` 即可重新打开(拿回它原来的 `sessionId`);空闲回收或重启关掉的会话,直接用原 `sessionId` 调任何方法也会自动重新打开,只有被 `closeSession` 关掉或会话文件已删的才报 `CELL_TA_SESSION_NOT_FOUND`;包按分组(`group`)打开的会话会在文件里记一条 pi 的自定义条目 `ta-group`,列表里带上 `group`,由该包自己带着角色重新打开;打开时给的角色(`appendSystemPrompt`)也记一条 `ta-role`,只给 `sessionFile` 重新打开时(如机器人把消息转进一个已关闭的智能体对话)沿用记下的角色和分组。分身的页面把分身对话的会话文件存在包数据 `TA_DOUBLE_FILE`(`@celljs/ta-web` 的 `assistant.file`)里,服务端的包据此找到分身。`setWorkingDirectory` 设置 ta serve 的工作目录(`TaServerInfo.cwd`,客户端没指定目录时在这里开对话,跨重启保留)。pi RPC 没有的会话操作:`forkToFile`(把 fork 出的对话另存成会话文件,当前会话不动,再用 `openSession` 打开),`navigateTree`(同 pi 的 `/tree`,返回 `editorText`),`fork` 多一个可选的 `position`(`at` 保留所选条目,同 pi 的 `/clone` 但可选任意条目)。
8
8
  - 事件:`TaEventEnvelope { sessionId, seq, event }`,`event` 是 pi JSON/RPC 模式的事件或 `extension_ui_request`;Ta 只多了 `ui_request_resolved`、`extension_error`、`session_replaced`、`session_reloaded`、`session_closed`、`working_message`(扩展用 pi 的 `setWorkingMessage` 说明正在做什么)、`client_tool_request`(预留)。
9
9
  - `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
@@ -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 {
@@ -70,6 +75,8 @@ export interface TaSignInSetup {
70
75
  fields: Record<string, string>;
71
76
  /** A secret is kept. */
72
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;
73
80
  }
74
81
  /** The ways to sign in, to set them up (Settings, Access), and where providers send the browser back. */
75
82
  export interface TaSignInConfig {
@@ -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,4 +140,14 @@ 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
  }
@@ -1,3 +1,4 @@
1
1
  export const TaAuthServer = Symbol('TaAuthServer');
2
2
  export const TA_AUTH_SERVICE = 'TaAuthServer';
3
+ export const TA_CUSTOM_APIS = ['openai-completions', 'openai-responses', 'anthropic-messages', 'google-generative-ai'];
3
4
  //# sourceMappingURL=auth-protocol.js.map
@@ -1,6 +1,7 @@
1
1
  export * from './access-protocol.js';
2
2
  export * from './auth-protocol.js';
3
3
  export * from './gateway-protocol.js';
4
+ export * from './language.js';
4
5
  export * from './location.js';
5
6
  export * from './package-protocol.js';
6
7
  export * from './pi-types.js';
@@ -1,6 +1,7 @@
1
1
  export * from './access-protocol.js';
2
2
  export * from './auth-protocol.js';
3
3
  export * from './gateway-protocol.js';
4
+ export * from './language.js';
4
5
  export * from './location.js';
5
6
  export * from './package-protocol.js';
6
7
  export * from './pi-types.js';
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,50 @@
1
+ export var TaLanguageUtil;
2
+ (function (TaLanguageUtil) {
3
+ /** In the order the settings list them. */
4
+ TaLanguageUtil.ALL = ['zh-CN', 'zh-TW', 'en-US', 'ja-JP'];
5
+ /** The name of each, in itself. */
6
+ TaLanguageUtil.NAMES = { 'zh-CN': '简体中文', 'zh-TW': '繁體中文', 'en-US': 'English', 'ja-JP': '日本語' };
7
+ /**
8
+ * The language of a tag (`zh-HK`, `ja`, `zh_TW.UTF-8` of `LANG`): Traditional Chinese for Taiwan, Hong Kong,
9
+ * Macau and `Hant`, Simplified for other Chinese, Japanese for Japanese, English for the rest.
10
+ */
11
+ function of(tag) {
12
+ const said = (tag !== null && tag !== void 0 ? tag : '').toLowerCase().replace(/_/g, '-');
13
+ if (/^zh(\b|-)/.test(said)) {
14
+ return /-hant\b/.test(said) || (!/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said)) ? 'zh-TW' : 'zh-CN';
15
+ }
16
+ return /^ja(\b|-)/.test(said) ? 'ja-JP' : 'en-US';
17
+ }
18
+ TaLanguageUtil.of = of;
19
+ /** The language of what the server says: that of Ta's pages (`TA_LANGUAGE`, see TaSettingsServer.setLanguage), else the computer's. */
20
+ function server(env = typeof process === 'undefined' ? {} : process.env) {
21
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
22
+ }
23
+ TaLanguageUtil.server = server;
24
+ /** The words of a language, of one for each. */
25
+ function pick(language, words) {
26
+ return words[of(language)];
27
+ }
28
+ TaLanguageUtil.pick = pick;
29
+ /** The words of the language of the server (`server()`), of one for each. */
30
+ function say(words) {
31
+ return words[server()];
32
+ }
33
+ TaLanguageUtil.say = say;
34
+ /** Chinese, either. */
35
+ function chinese(language) {
36
+ return of(language).startsWith('zh');
37
+ }
38
+ TaLanguageUtil.chinese = chinese;
39
+ /** Chinese or Japanese: words go without spaces, lists join with 、, a colon is :. */
40
+ function cjk(language) {
41
+ return of(language) !== 'en-US';
42
+ }
43
+ TaLanguageUtil.cjk = cjk;
44
+ /** A list of names in a language: `a、b`, `a, b`. */
45
+ function list(language, items) {
46
+ return items.join(cjk(language) ? '、' : ', ');
47
+ }
48
+ TaLanguageUtil.list = list;
49
+ })(TaLanguageUtil || (TaLanguageUtil = {}));
50
+ //# 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. */
@@ -2,13 +2,18 @@ export const TaPackageServer = Symbol('TaPackageServer');
2
2
  export const TA_PACKAGE_SERVICE = 'TaPackageServer';
3
3
  export var TaPackageTextUtil;
4
4
  (function (TaPackageTextUtil) {
5
- /** The text in a language such as `zh-CN`: that language, else its first part (`zh`), else English, else the first there is. */
5
+ /**
6
+ * The text in a language such as `zh-TW`: that language, else its first part (`zh`), else another of that part
7
+ * (`zh-CN` for `zh-TW`), else English, else the first there is.
8
+ */
6
9
  function pick(text, language) {
7
- var _a, _b, _c, _d;
10
+ var _a, _b, _c, _d, _e;
8
11
  if (text === undefined || typeof text === 'string') {
9
12
  return text;
10
13
  }
11
- 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];
14
+ const base = language.split('-')[0];
15
+ const kin = Object.keys(text).find(key => key.split('-')[0] === base);
16
+ 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];
12
17
  }
13
18
  TaPackageTextUtil.pick = pick;
14
19
  })(TaPackageTextUtil || (TaPackageTextUtil = {}));
@@ -193,13 +193,27 @@ export interface TaAccount {
193
193
  export interface TaHostAccounts {
194
194
  /** Those configured (the environment, sign-in.json of the agent directory); none: no one signs in. */
195
195
  providers(): TaSignInProvider[];
196
- /** Where the browser goes, and the state it comes back with. */
197
- start(provider: string, redirectUri: string): Promise<{
198
- url: string;
199
- state: string;
200
- }>;
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>;
201
198
  /** The account of a code, for a state `start` gave (once, for 10 minutes); throws when the provider refuses it. */
202
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;
203
217
  }
204
218
  /** A device of a principal, and what reaches this Ta with it (RelayPairing). The key goes to that principal alone. */
205
219
  export interface TaTeamPairing {
@@ -13,6 +13,8 @@ export declare const TA_SERVER_SERVICE = "TaServer";
13
13
  export declare const TA_CLIENT_SERVICE = "TaClient";
14
14
  /** The file `ta serve` writes in the agent directory, readable only by its user. */
15
15
  export declare const TA_SERVE_FILE = "serve.json";
16
+ /** What a `ta serve` started by an app (Ta Desktop) exits with when asked to restart (TaServer.restartServer): the app restarts. */
17
+ export declare const TA_SERVE_RESTART_EXIT_CODE = 75;
16
18
  /** The contents of {@link TA_SERVE_FILE}: how to reach the running `ta serve`. */
17
19
  export interface TaServeInfo {
18
20
  url: string;
@@ -26,8 +28,17 @@ export interface TaServeInfo {
26
28
  export declare const TA_RESUME_MESSAGE = "ta-resume";
27
29
  /** What a client needs to know of the server before it opens a session. */
28
30
  export interface TaServerInfo {
29
- /** The version of ta. */
31
+ /** The version of ta that runs. */
30
32
  version: string;
33
+ /** The commit of a build of the development channel (Ta Desktop's ta-build.json); none for a release. */
34
+ build?: string;
35
+ /**
36
+ * Another build of Ta was installed over the one that runs (an update, a reinstall, a build of the repository):
37
+ * it runs once ta serve restarts (restartServer). None from a ta serve of before.
38
+ */
39
+ update?: TaServerUpdate;
40
+ /** It can restart itself (restartServer): a ta serve of before, or one not started as `ta serve`, cannot. */
41
+ restartable?: boolean;
31
42
  /**
32
43
  * Where a client opens a session when the user names no directory: the one set with
33
44
  * `setWorkingDirectory`, else the working directory of `ta serve`, or of its execution environment.
@@ -42,6 +53,12 @@ export interface TaServerInfo {
42
53
  /** The page is of one the user let in (docs/design/ta-team.md), not the user: who, and as what. */
43
54
  member?: TaMemberInfo;
44
55
  }
56
+ /** The build of Ta installed now, which a restart of ta serve runs (TaServerInfo.update). */
57
+ export interface TaServerUpdate {
58
+ version: string;
59
+ /** As TaServerInfo.build. */
60
+ build?: string;
61
+ }
45
62
  /** The stable `code` of each failure of a {@link TaServer} call. */
46
63
  export declare const TaErrorCode: {
47
64
  readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
@@ -469,6 +486,12 @@ export interface TaServer {
469
486
  * restarts: where conversations open when the user names no directory. Sessions already open stay where they are.
470
487
  */
471
488
  setWorkingDirectory(cwd: string): Promise<TaServerInfo>;
489
+ /**
490
+ * Stops ta serve and starts it again, from the files installed now (TaServerInfo.update): what runs pauses and
491
+ * goes on after the start. It answers first; connections then close and connect again. The owner's alone; fails
492
+ * with INVALID_ARGUMENT where it cannot restart (TaServerInfo.restartable).
493
+ */
494
+ restartServer(): Promise<void>;
472
495
  openSession(options: TaOpenSessionOptions): Promise<TaOpenedSession>;
473
496
  closeSession(sessionId: string): Promise<void>;
474
497
  listSessions(): Promise<TaSessionInfo[]>;
@@ -6,6 +6,8 @@ export const TA_SERVER_SERVICE = 'TaServer';
6
6
  export const TA_CLIENT_SERVICE = 'TaClient';
7
7
  /** The file `ta serve` writes in the agent directory, readable only by its user. */
8
8
  export const TA_SERVE_FILE = 'serve.json';
9
+ /** What a `ta serve` started by an app (Ta Desktop) exits with when asked to restart (TaServer.restartServer): the app restarts. */
10
+ export const TA_SERVE_RESTART_EXIT_CODE = 75;
9
11
  /**
10
12
  * The type of the custom message `ta serve` adds to a conversation whose run a restart of it cut off, when it opens
11
13
  * the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
@@ -121,6 +121,8 @@ export interface TaActionInfo {
121
121
  title: {
122
122
  en: string;
123
123
  'zh-CN': string;
124
+ 'zh-TW'?: string;
125
+ 'ja-JP'?: string;
124
126
  };
125
127
  /** Given for a directory: its scope is a list of directories. */
126
128
  scoped?: boolean;
@@ -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 {
@@ -70,6 +75,8 @@ export interface TaSignInSetup {
70
75
  fields: Record<string, string>;
71
76
  /** A secret is kept. */
72
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;
73
80
  }
74
81
  /** The ways to sign in, to set them up (Settings, Access), and where providers send the browser back. */
75
82
  export interface TaSignInConfig {
@@ -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,6 +1,7 @@
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';
@@ -17,6 +17,7 @@ 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);
@@ -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 = {}));
@@ -193,13 +193,27 @@ export interface TaAccount {
193
193
  export interface TaHostAccounts {
194
194
  /** Those configured (the environment, sign-in.json of the agent directory); none: no one signs in. */
195
195
  providers(): TaSignInProvider[];
196
- /** Where the browser goes, and the state it comes back with. */
197
- start(provider: string, redirectUri: string): Promise<{
198
- url: string;
199
- state: string;
200
- }>;
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>;
201
198
  /** The account of a code, for a state `start` gave (once, for 10 minutes); throws when the provider refuses it. */
202
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;
203
217
  }
204
218
  /** A device of a principal, and what reaches this Ta with it (RelayPairing). The key goes to that principal alone. */
205
219
  export interface TaTeamPairing {
@@ -13,6 +13,8 @@ export declare const TA_SERVER_SERVICE = "TaServer";
13
13
  export declare const TA_CLIENT_SERVICE = "TaClient";
14
14
  /** The file `ta serve` writes in the agent directory, readable only by its user. */
15
15
  export declare const TA_SERVE_FILE = "serve.json";
16
+ /** What a `ta serve` started by an app (Ta Desktop) exits with when asked to restart (TaServer.restartServer): the app restarts. */
17
+ export declare const TA_SERVE_RESTART_EXIT_CODE = 75;
16
18
  /** The contents of {@link TA_SERVE_FILE}: how to reach the running `ta serve`. */
17
19
  export interface TaServeInfo {
18
20
  url: string;
@@ -26,8 +28,17 @@ export interface TaServeInfo {
26
28
  export declare const TA_RESUME_MESSAGE = "ta-resume";
27
29
  /** What a client needs to know of the server before it opens a session. */
28
30
  export interface TaServerInfo {
29
- /** The version of ta. */
31
+ /** The version of ta that runs. */
30
32
  version: string;
33
+ /** The commit of a build of the development channel (Ta Desktop's ta-build.json); none for a release. */
34
+ build?: string;
35
+ /**
36
+ * Another build of Ta was installed over the one that runs (an update, a reinstall, a build of the repository):
37
+ * it runs once ta serve restarts (restartServer). None from a ta serve of before.
38
+ */
39
+ update?: TaServerUpdate;
40
+ /** It can restart itself (restartServer): a ta serve of before, or one not started as `ta serve`, cannot. */
41
+ restartable?: boolean;
31
42
  /**
32
43
  * Where a client opens a session when the user names no directory: the one set with
33
44
  * `setWorkingDirectory`, else the working directory of `ta serve`, or of its execution environment.
@@ -42,6 +53,12 @@ export interface TaServerInfo {
42
53
  /** The page is of one the user let in (docs/design/ta-team.md), not the user: who, and as what. */
43
54
  member?: TaMemberInfo;
44
55
  }
56
+ /** The build of Ta installed now, which a restart of ta serve runs (TaServerInfo.update). */
57
+ export interface TaServerUpdate {
58
+ version: string;
59
+ /** As TaServerInfo.build. */
60
+ build?: string;
61
+ }
45
62
  /** The stable `code` of each failure of a {@link TaServer} call. */
46
63
  export declare const TaErrorCode: {
47
64
  readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
@@ -469,6 +486,12 @@ export interface TaServer {
469
486
  * restarts: where conversations open when the user names no directory. Sessions already open stay where they are.
470
487
  */
471
488
  setWorkingDirectory(cwd: string): Promise<TaServerInfo>;
489
+ /**
490
+ * Stops ta serve and starts it again, from the files installed now (TaServerInfo.update): what runs pauses and
491
+ * goes on after the start. It answers first; connections then close and connect again. The owner's alone; fails
492
+ * with INVALID_ARGUMENT where it cannot restart (TaServerInfo.restartable).
493
+ */
494
+ restartServer(): Promise<void>;
472
495
  openSession(options: TaOpenSessionOptions): Promise<TaOpenedSession>;
473
496
  closeSession(sessionId: string): Promise<void>;
474
497
  listSessions(): Promise<TaSessionInfo[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_RESUME_MESSAGE = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
3
+ exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_RESUME_MESSAGE = exports.TA_SERVE_RESTART_EXIT_CODE = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
4
4
  exports.TaServer = Symbol('TaServer');
5
5
  exports.TaClient = Symbol('TaClient');
6
6
  /** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
@@ -9,6 +9,8 @@ exports.TA_SERVER_SERVICE = 'TaServer';
9
9
  exports.TA_CLIENT_SERVICE = 'TaClient';
10
10
  /** The file `ta serve` writes in the agent directory, readable only by its user. */
11
11
  exports.TA_SERVE_FILE = 'serve.json';
12
+ /** What a `ta serve` started by an app (Ta Desktop) exits with when asked to restart (TaServer.restartServer): the app restarts. */
13
+ exports.TA_SERVE_RESTART_EXIT_CODE = 75;
12
14
  /**
13
15
  * The type of the custom message `ta serve` adds to a conversation whose run a restart of it cut off, when it opens
14
16
  * the conversation again and has it carry on (TaSessionResume of ta-host); the web client shows it as a mark.
@@ -121,6 +121,8 @@ export interface TaActionInfo {
121
121
  title: {
122
122
  en: string;
123
123
  'zh-CN': string;
124
+ 'zh-TW'?: string;
125
+ 'ja-JP'?: string;
124
126
  };
125
127
  /** Given for a directory: its scope is a list of directories. */
126
128
  scoped?: boolean;
@@ -7,6 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.TaActionUtil = exports.TA_ACTIONS = exports.TA_ACCESS_REQUEST_EVENT = exports.TaPermissionUtil = exports.TA_UNDECLARED = exports.TA_INVITE_PREFIX = exports.TA_OWNER = void 0;
10
+ const language_1 = require("./language");
10
11
  /** The user of the Ta: its own pages, devices and token. Everyone else is let in by a package. */
11
12
  exports.TA_OWNER = 'owner';
12
13
  /** A principal that holds a link of invitation only: `invite:<id>`. It may only ask to be let in. */
@@ -40,47 +41,47 @@ var TaPermissionUtil;
40
41
  * `detail` is the TaDenial): the notice of a refused call has a button for it.
41
42
  */
42
43
  exports.TA_ACCESS_REQUEST_EVENT = 'ta:access-request';
43
- const action = (id, en, zh, more = {}) => ({
44
+ const action = (id, en, zh, tw, ja, more = {}) => ({
44
45
  id,
45
46
  area: id.split('.')[0],
46
- title: { en, 'zh-CN': zh },
47
+ title: { en, 'zh-CN': zh, ...(tw ? { 'zh-TW': tw } : {}), ...(ja ? { 'ja-JP': ja } : {}) },
47
48
  ...more,
48
49
  });
49
50
  /** Every action of Ta itself; packages add their own (`pi.permissions` of their package.json). */
50
51
  exports.TA_ACTIONS = [
51
- action('chat.view', 'See conversations', '查看对话'),
52
- action('chat.send', 'Send in conversations', '在对话里发消息'),
53
- action('chat.create', 'Start conversations', '新建对话'),
54
- action('chat.stop', 'Stop a reply', '停止回复'),
55
- action('chat.manage', 'Rename, archive and close conversations', '改名、归档、关闭对话'),
56
- action('chat.share', 'Share by a link', '生成分享链接'),
57
- action('agent.view', 'See agents', '查看智能体'),
58
- action('agent.use', 'Talk with agents', '和智能体对话'),
59
- action('agent.edit', 'Create, change and remove agents', '新建、修改、删除智能体'),
60
- action('channel.view', 'See channels', '查看频道'),
61
- action('channel.post', 'Post in channels', '在频道里发言'),
62
- action('channel.manage', 'Create and change channels', '新建、管理频道'),
63
- action('task.view', 'See tasks', '查看任务'),
64
- action('task.create', 'Hand out tasks', '派任务'),
65
- action('task.manage', 'Take over and stop tasks', '接管、停止任务'),
66
- action('files.read', 'Read files', '读文件', { scoped: true }),
67
- action('files.write', 'Change files', '改文件', { scoped: true }),
68
- action('commands.run', 'Let Ta run commands', '让 Ta 运行命令', { scoped: true, risky: true }),
69
- action('commands.terminal', 'Open terminals', '打开终端', { scoped: true, risky: true }),
70
- action('hosts.use', 'Use remote hosts', '使用远程主机', { risky: true }),
71
- action('models.use', 'Use the models', '使用模型'),
72
- action('models.manage', 'Sign in to models', '登录和更换模型账号'),
73
- action('cron.view', 'See scheduled tasks', '查看定时任务'),
74
- action('cron.manage', 'Change scheduled tasks', '管理定时任务'),
75
- action('extensions.use', 'Use extensions', '使用扩展'),
76
- action('extensions.install', 'Install and turn off extensions', '安装、停用扩展'),
77
- action('settings.view', 'See settings', '查看设置'),
78
- action('settings.manage', 'Change settings', '修改设置'),
79
- action('members.view', 'See members', '查看成员'),
80
- action('members.invite', 'Invite people', '邀请别人'),
81
- action('members.approve', 'Answer requests', '处理申请'),
82
- action('members.roles', 'Change roles and members', '管理角色和成员'),
83
- action('audit.view', 'See the record', '查看记录'),
52
+ action('chat.view', 'See conversations', '查看对话', '檢視對話', '会話を確認'),
53
+ action('chat.send', 'Send in conversations', '在对话里发消息', '在對話裡發訊息', '会話にメッセージを送信'),
54
+ action('chat.create', 'Start conversations', '新建对话', '新建對話', '新しい会話を開始'),
55
+ action('chat.stop', 'Stop a reply', '停止回复', '停止回覆', '返信を停止'),
56
+ action('chat.manage', 'Rename, archive and close conversations', '改名、归档、关闭对话', '改名、歸檔、關閉對話', '会話の名前変更、アーカイブ、クローズ'),
57
+ action('chat.share', 'Share by a link', '生成分享链接', '生成分享連結', '共有リンクで共有'),
58
+ action('agent.view', 'See agents', '查看智能体', '檢視智慧體', 'エージェントを確認'),
59
+ action('agent.use', 'Talk with agents', '和智能体对话', '和智慧體對話', 'エージェントと対話'),
60
+ action('agent.edit', 'Create, change and remove agents', '新建、修改、删除智能体', '新建、修改、刪除智慧體', 'エージェントを作成・変更・削除'),
61
+ action('channel.view', 'See channels', '查看频道', '檢視頻道', 'チャネルを確認'),
62
+ action('channel.post', 'Post in channels', '在频道里发言', '在頻道里發言', 'チャネルに投稿'),
63
+ action('channel.manage', 'Create and change channels', '新建、管理频道', '新建、管理頻道', 'チャネルを作成・管理'),
64
+ action('task.view', 'See tasks', '查看任务', '檢視任務', 'タスクを確認'),
65
+ action('task.create', 'Hand out tasks', '派任务', '派任務', 'タスクを割り当て'),
66
+ action('task.manage', 'Take over and stop tasks', '接管、停止任务', '接管、停止任務', 'タスクを引き継ぎ・停止'),
67
+ action('files.read', 'Read files', '读文件', '讀檔案', 'ファイルを読取', { scoped: true }),
68
+ action('files.write', 'Change files', '改文件', '改檔案', 'ファイルを変更', { scoped: true }),
69
+ action('commands.run', 'Let Ta run commands', '让 Ta 运行命令', '讓 Ta 執行命令', 'Ta にコマンド実行を許可', { scoped: true, risky: true }),
70
+ action('commands.terminal', 'Open terminals', '打开终端', '開啟終端機', 'ターミナルを開く', { scoped: true, risky: true }),
71
+ action('hosts.use', 'Use remote hosts', '使用远程主机', '使用遠端主機', 'リモートホストを使用', { risky: true }),
72
+ action('models.use', 'Use the models', '使用模型', '使用模型', 'モデルを使用'),
73
+ action('models.manage', 'Sign in to models', '登录和更换模型账号', '登入和更換模型帳號', 'モデルアカウントにサインイン・変更'),
74
+ action('cron.view', 'See scheduled tasks', '查看定时任务', '檢視定時任務', 'スケジュールタスクを確認'),
75
+ action('cron.manage', 'Change scheduled tasks', '管理定时任务', '管理定時任務', 'スケジュールタスクを管理'),
76
+ action('extensions.use', 'Use extensions', '使用扩展', '使用擴充功能', '拡張機能を使用'),
77
+ action('extensions.install', 'Install and turn off extensions', '安装、停用扩展', '安裝、停用擴充功能', '拡張機能をインストール・無効化'),
78
+ action('settings.view', 'See settings', '查看设置', '檢視設定', '設定を確認'),
79
+ action('settings.manage', 'Change settings', '修改设置', '修改設定', '設定を変更'),
80
+ action('members.view', 'See members', '查看成员', '檢視成員', 'メンバーを確認'),
81
+ action('members.invite', 'Invite people', '邀请别人', '邀請別人', 'メンバーを招待'),
82
+ action('members.approve', 'Answer requests', '处理申请', '處理申請', 'リクエストに対応'),
83
+ action('members.roles', 'Change roles and members', '管理角色和成员', '管理角色和成員', 'ロールとメンバーを管理'),
84
+ action('audit.view', 'See the record', '查看记录', '檢視記錄', 'レコードを確認'),
84
85
  ];
85
86
  var TaActionUtil;
86
87
  (function (TaActionUtil) {
@@ -91,8 +92,18 @@ var TaActionUtil;
91
92
  TaActionUtil.info = info;
92
93
  /** Its title in a language such as `zh-CN`; the id for an action of no catalog. */
93
94
  function title(id, language) {
94
- const found = byId.get(id);
95
- return found ? (language.startsWith('zh') ? found.title['zh-CN'] : found.title.en) : id;
95
+ var _a;
96
+ var _b, _c;
97
+ const title = (_a = byId.get(id)) === null || _a === void 0 ? void 0 : _a.title;
98
+ if (!title) {
99
+ return id;
100
+ }
101
+ return language_1.TaLanguageUtil.pick(language, {
102
+ 'zh-CN': title['zh-CN'],
103
+ 'zh-TW': (_b = title['zh-TW']) !== null && _b !== void 0 ? _b : title['zh-CN'],
104
+ 'en-US': title.en,
105
+ 'ja-JP': (_c = title['ja-JP']) !== null && _c !== void 0 ? _c : title.en,
106
+ });
96
107
  }
97
108
  TaActionUtil.title = title;
98
109
  /** Whether `path` is `dir` or inside it; both absolute, `/` separated. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-protocol",
3
- "version": "4.14.0",
3
+ "version": "4.15.1",
4
4
  "description": "The protocol between ta serve and its clients",
5
5
  "homepage": "https://github.com/cellbang/ta",
6
6
  "bugs": {