@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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/esm/common/access-protocol.d.ts +38 -0
- package/esm/common/auth-protocol.d.ts +64 -0
- package/esm/common/auth-protocol.js +1 -0
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/language.d.ts +25 -0
- package/esm/common/language.js +50 -0
- package/esm/common/package-protocol.d.ts +6 -1
- package/esm/common/package-protocol.js +8 -3
- package/esm/common/presence-protocol.d.ts +60 -0
- package/esm/common/presence-protocol.js +48 -0
- package/esm/common/room-protocol.d.ts +10 -0
- package/esm/common/ta-extension-host.d.ts +53 -0
- package/esm/common/ta-extension-host.js +6 -0
- package/esm/common/ta-protocol.d.ts +6 -0
- package/esm/common/team-protocol.d.ts +2 -0
- package/esm/common/team-protocol.js +48 -37
- package/lib/common/access-protocol.d.ts +38 -0
- package/lib/common/auth-protocol.d.ts +64 -0
- package/lib/common/auth-protocol.js +2 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/language.d.ts +26 -0
- package/lib/common/language.js +53 -0
- package/lib/common/package-protocol.d.ts +6 -1
- package/lib/common/package-protocol.js +8 -3
- package/lib/common/presence-protocol.d.ts +61 -0
- package/lib/common/presence-protocol.js +51 -0
- package/lib/common/room-protocol.d.ts +10 -0
- package/lib/common/ta-extension-host.d.ts +53 -0
- package/lib/common/ta-extension-host.js +7 -1
- package/lib/common/ta-protocol.d.ts +6 -0
- package/lib/common/team-protocol.d.ts +2 -0
- package/lib/common/team-protocol.js +48 -37
- package/package.json +3 -3
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
|
|
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
|
|
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 {
|
|
@@ -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,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
|
}
|
package/esm/common/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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';
|
|
8
|
+
export * from './presence-protocol.js';
|
|
7
9
|
export * from './relay-protocol.js';
|
|
8
10
|
export * from './remote-protocol.js';
|
|
9
11
|
export * from './room-protocol.js';
|
package/esm/common/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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';
|
|
8
|
+
export * from './presence-protocol.js';
|
|
7
9
|
export * from './relay-protocol.js';
|
|
8
10
|
export * from './remote-protocol.js';
|
|
9
11
|
export * from './room-protocol.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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
|
|
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 = {}));
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TaMessageContext } from './ta-protocol.js';
|
|
2
|
+
export const TaPresenceServer = Symbol('TaPresenceServer');
|
|
3
|
+
export const TA_PRESENCE_SERVICE = 'TaPresenceServer';
|
|
4
|
+
/** A page says what it is at again this often while it lasts, the same or not. */
|
|
5
|
+
export const TA_PRESENCE_HEARTBEAT_MS = 20000;
|
|
6
|
+
/** A page that said nothing for this long is gone, its connection open or not. */
|
|
7
|
+
export const TA_PRESENCE_EXPIRY_MS = 60000;
|
|
8
|
+
/**
|
|
9
|
+
* A message of the user sent by one let in says who in a line of its `<context>`, `[ta:by <principal> <name>]`: the
|
|
10
|
+
* page shows it as theirs, the model reads who asked. ta serve writes it, and takes out any such line a page wrote, so
|
|
11
|
+
* that no one sends as another.
|
|
12
|
+
*/
|
|
13
|
+
export var TaMessageAuthor;
|
|
14
|
+
(function (TaMessageAuthor) {
|
|
15
|
+
const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
16
|
+
const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
|
|
17
|
+
/** `message` without the lines of an author. */
|
|
18
|
+
function strip(message) {
|
|
19
|
+
const context = TaMessageContext.read(message);
|
|
20
|
+
if (context === undefined || !LINE.test(context)) {
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
const kept = context.replace(LINES, '').replace(/\n+$/, '');
|
|
24
|
+
const body = TaMessageContext.strip(message);
|
|
25
|
+
return kept.trim() ? TaMessageContext.wrap(kept, body) : body;
|
|
26
|
+
}
|
|
27
|
+
TaMessageAuthor.strip = strip;
|
|
28
|
+
/** `message` as written by `id`, called `name`; a command (`/compact`, `!ls`) stays a command. */
|
|
29
|
+
function mark(message, id, name) {
|
|
30
|
+
const plain = strip(message);
|
|
31
|
+
if (/^[/!]/.test(plain)) {
|
|
32
|
+
return plain;
|
|
33
|
+
}
|
|
34
|
+
const line = `[ta:by ${id.replace(/[\s\]]/g, '')} ${name.replace(/[\]\n]/g, ' ').trim() || id}]`;
|
|
35
|
+
const context = TaMessageContext.read(plain);
|
|
36
|
+
return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(plain));
|
|
37
|
+
}
|
|
38
|
+
TaMessageAuthor.mark = mark;
|
|
39
|
+
/** Who wrote it; undefined for the user of the Ta (no line). */
|
|
40
|
+
function of(message) {
|
|
41
|
+
var _a;
|
|
42
|
+
const context = TaMessageContext.read(message);
|
|
43
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
44
|
+
return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== void 0 ? _a : match[1]).trim() } : undefined;
|
|
45
|
+
}
|
|
46
|
+
TaMessageAuthor.of = of;
|
|
47
|
+
})(TaMessageAuthor || (TaMessageAuthor = {}));
|
|
48
|
+
//# 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.js';
|
|
1
2
|
import type { TaPackageServer } from './package-protocol.js';
|
|
3
|
+
import type { TaPresencePerson } from './presence-protocol.js';
|
|
2
4
|
import type { TaRelayFeature, TaRelayService, TaRelayStore, TaRelayType, TaShares } from './relay-protocol.js';
|
|
3
5
|
import type { TaRooms } from './room-protocol.js';
|
|
4
6
|
import type { TaServer } from './ta-protocol.js';
|
|
@@ -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
|
|
@@ -80,6 +80,12 @@ export const TA_FILE_WRITE_EVENT = 'ta:file-write';
|
|
|
80
80
|
* double first opened. The server side of a package that sends to the double reads it there.
|
|
81
81
|
*/
|
|
82
82
|
export const TA_DOUBLE_FILE = { name: '@celljs/ta-web', key: 'assistant.file' };
|
|
83
|
+
/**
|
|
84
|
+
* Where the web client keeps the kind of dinosaur the double is (`trex` till the user picks another): in the data of
|
|
85
|
+
* packages, under this name and key, a JSON string. It is the look of this Ta that others see (TaIdentity.look): the
|
|
86
|
+
* rooms of ta serve tell it to the Ta of friends and rooms.
|
|
87
|
+
*/
|
|
88
|
+
export const TA_DOUBLE_LOOK = { name: '@celljs/ta-web', key: 'assistant.species', initial: 'trex' };
|
|
83
89
|
/**
|
|
84
90
|
* Where the web client keeps the tasks the double handed out: in the data of packages, under this name and key; an
|
|
85
91
|
* array of `{ sessionId, sessionFile?, takenOver?, removed? }` among other fields. The double tells the user of these
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TaAuthEvent } from './auth-protocol.js';
|
|
2
2
|
import type { ImageContent, JsonAgentSessionEvent, RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types.js';
|
|
3
|
+
import type { TaSessionPerson } from './presence-protocol.js';
|
|
3
4
|
import type { TaRemoteEvent } from './remote-protocol.js';
|
|
4
5
|
import type { TaRoomEvent } from './room-protocol.js';
|
|
5
6
|
import type { TaAsking } from './ta-extension-host.js';
|
|
@@ -185,6 +186,11 @@ export interface TaSessionInfo {
|
|
|
185
186
|
updatedAt: number;
|
|
186
187
|
/** TaOpenSessionOptions.group. */
|
|
187
188
|
group?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Others at it now, as this page is told: who looks at it, types in it, or asked its run (TaPresenceServer); never
|
|
191
|
+
* the page's own principal. None in a Ta its user alone is in.
|
|
192
|
+
*/
|
|
193
|
+
people?: TaSessionPerson[];
|
|
188
194
|
}
|
|
189
195
|
/**
|
|
190
196
|
* A conversation in a session file of pi that no session has open: the service closed it while idle, or
|