@celljs/ta-protocol 4.6.1 → 4.8.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 +11 -0
- package/README.md +4 -3
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/index.js.map +1 -1
- package/esm/common/location.d.ts +45 -0
- package/esm/common/location.js +175 -0
- package/esm/common/location.js.map +1 -0
- package/esm/common/remote-protocol.d.ts +85 -0
- package/esm/common/remote-protocol.js +3 -0
- package/esm/common/remote-protocol.js.map +1 -0
- package/esm/common/settings-protocol.d.ts +7 -0
- package/esm/common/ta-extension-host.d.ts +33 -3
- package/esm/common/ta-extension-host.js +7 -0
- package/esm/common/ta-extension-host.js.map +1 -1
- package/esm/common/ta-protocol.d.ts +14 -2
- package/esm/common/ta-protocol.js.map +1 -1
- package/esm/common/workspace-protocol.d.ts +16 -0
- package/esm/common/workspace-protocol.js +5 -0
- package/esm/common/workspace-protocol.js.map +1 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/location.d.ts +46 -0
- package/lib/common/location.d.ts.map +1 -0
- package/lib/common/location.js +178 -0
- package/lib/common/location.js.map +1 -0
- package/lib/common/location.spec.d.ts +2 -0
- package/lib/common/location.spec.d.ts.map +1 -0
- package/lib/common/location.spec.js +58 -0
- package/lib/common/location.spec.js.map +1 -0
- package/lib/common/remote-protocol.d.ts +86 -0
- package/lib/common/remote-protocol.d.ts.map +1 -0
- package/lib/common/remote-protocol.js +6 -0
- package/lib/common/remote-protocol.js.map +1 -0
- package/lib/common/settings-protocol.d.ts +7 -0
- package/lib/common/settings-protocol.d.ts.map +1 -1
- package/lib/common/ta-extension-host.d.ts +33 -3
- package/lib/common/ta-extension-host.d.ts.map +1 -1
- package/lib/common/ta-extension-host.js +8 -1
- package/lib/common/ta-extension-host.js.map +1 -1
- package/lib/common/ta-protocol.d.ts +14 -2
- package/lib/common/ta-protocol.d.ts.map +1 -1
- package/lib/common/ta-protocol.js.map +1 -1
- package/lib/common/ta-protocol.spec.js +2 -0
- package/lib/common/ta-protocol.spec.js.map +1 -1
- package/lib/common/workspace-protocol.d.ts +16 -0
- package/lib/common/workspace-protocol.d.ts.map +1 -1
- package/lib/common/workspace-protocol.js +6 -1
- package/lib/common/workspace-protocol.js.map +1 -1
- package/package.json +1 -1
- package/src/common/index.ts +2 -0
- package/src/common/location.spec.ts +62 -0
- package/src/common/location.ts +177 -0
- package/src/common/remote-protocol.ts +76 -0
- package/src/common/settings-protocol.ts +7 -0
- package/src/common/ta-extension-host.ts +48 -3
- package/src/common/ta-protocol.spec.ts +2 -0
- package/src/common/ta-protocol.ts +14 -2
- package/src/common/workspace-protocol.ts +18 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Cell - Ta Protocol
|
|
2
|
+
|
|
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
|
+
|
|
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`.
|
|
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. `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
|
+
- **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_closed`, and `client_tool_request` (reserved).
|
|
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.
|
|
10
|
+
- **Locations** (`cwd`): a path is either local or on another machine in the form `ssh://<host>/<absolute-path>` (`TaLocation` parses, handles parent/child, and names).
|
|
11
|
+
- **Errors**: the JSON-RPC error code is `TA_RPC_ERROR_CODE`. The `data` field includes a stable `code` (`TaErrorCode`, e.g., `CELL_TA_SESSION_LOCKED`) and a one-line handling hint. When no model is available or the model service isn't signed in, the code is `CELL_TA_NOT_SIGNED_IN`; clients open the login page accordingly. `CELL_TA_CONNECTION_LOST` is client-generated: the call didn't reach ta serve, or the connection dropped before the result arrived.
|
package/README.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
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
|
|
7
|
-
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer`
|
|
6
|
+
- 服务:`TaServer`(会话,即 pi 的 RPC 命令)、`TaWorkspaceServer`(目录里的文件与命令)、`TaTerminalServer`(终端)、`TaSettingsServer`(pi 的 `settings.json`)、`TaPackageServer`(包、Web 扩展与包的数据)、`TaAuthServer`(登录模型服务,同 pi 的 `/login` `/logout`)、`TaRelayServer`(经 Relay 配对设备,同 `ta pair`)、`TaRemoteServer`(`ssh://` 目录的主机、ssh 的提问、端口转发)。会话之外的能力按职责各成一个服务,不往 `TaServer` 里加。
|
|
7
|
+
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。`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_closed`、`client_tool_request`(预留)。
|
|
9
9
|
- `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
|
|
10
|
-
-
|
|
10
|
+
- 目录(`cwd`)是位置:本机路径,或另一台机器的 `ssh://<host>/<绝对路径>`(`TaLocation` 解析、上下级、名字)。
|
|
11
|
+
- 失败时 JSON-RPC 错误码为 `TA_RPC_ERROR_CODE`,`data` 里有稳定的 `code`(`TaErrorCode`,如 `CELL_TA_SESSION_LOCKED`)和一句处理建议 `hint`。没有可用的模型或模型服务没登录时是 `CELL_TA_NOT_SIGNED_IN`,客户端据此打开登录页。`CELL_TA_CONNECTION_LOST` 由客户端产生:调用没能送到 ta serve,或连接断开时还没收到结果。
|
package/esm/common/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './auth-protocol.js';
|
|
2
|
+
export * from './location.js';
|
|
2
3
|
export * from './package-protocol.js';
|
|
3
4
|
export * from './pi-types.js';
|
|
4
5
|
export * from './relay-protocol.js';
|
|
6
|
+
export * from './remote-protocol.js';
|
|
5
7
|
export * from './settings-protocol.js';
|
|
6
8
|
export * from './ta-extension-host.js';
|
|
7
9
|
export * from './ta-protocol.js';
|
package/esm/common/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './auth-protocol.js';
|
|
2
|
+
export * from './location.js';
|
|
2
3
|
export * from './package-protocol.js';
|
|
3
4
|
export * from './pi-types.js';
|
|
4
5
|
export * from './relay-protocol.js';
|
|
6
|
+
export * from './remote-protocol.js';
|
|
5
7
|
export * from './settings-protocol.js';
|
|
6
8
|
export * from './ta-extension-host.js';
|
|
7
9
|
export * from './ta-protocol.js';
|
package/esm/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a conversation works: a directory of the machine of ta serve, as a path, or a directory of another
|
|
3
|
+
* machine that ta serve reaches with ssh, as `ssh://<host>/<absolute path>`. `<host>` is what ssh takes:
|
|
4
|
+
* a Host of ~/.ssh/config, or `[user@]host[:port]`. Without a path (`ssh://<host>`) it is the home
|
|
5
|
+
* directory there, which TaRemoteServer.resolveLocation turns into a path.
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace TaLocation {
|
|
8
|
+
const SSH = "ssh://";
|
|
9
|
+
/** A directory of another machine. */
|
|
10
|
+
interface Remote {
|
|
11
|
+
host: string;
|
|
12
|
+
/** Absolute, with `/`; empty for the home directory. */
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
function isRemote(location: string): boolean;
|
|
16
|
+
/** undefined for a path of the machine of ta serve; throws for an `ssh://` location that is not one. */
|
|
17
|
+
function parse(location: string): Remote | undefined;
|
|
18
|
+
function isHost(host: string): boolean;
|
|
19
|
+
/** What {@link readHost} makes of what the user typed. */
|
|
20
|
+
type HostInput = {
|
|
21
|
+
host: string;
|
|
22
|
+
} | {
|
|
23
|
+
error: 'empty' | 'invalid';
|
|
24
|
+
} | {
|
|
25
|
+
error: 'options';
|
|
26
|
+
options: string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A host as the user may write it: `dev`, `me@dev`, `me@dev:2222`, `ssh://me@dev:2222/path`, or the
|
|
30
|
+
* command line they use (`ssh -p 2222 me@dev`, `ssh me@dev -p 2222 -l root`). Options that a host
|
|
31
|
+
* cannot hold (`-i`, `-J`, `-o ProxyCommand=…`) belong in ~/.ssh/config: they come back as `options`.
|
|
32
|
+
*/
|
|
33
|
+
function readHost(input: string): HostInput;
|
|
34
|
+
/** `ssh://<host><path>`; `path` absolute, or empty for the home directory. */
|
|
35
|
+
function ssh(host: string, path?: string): string;
|
|
36
|
+
/** The host of a remote location; undefined for this machine. */
|
|
37
|
+
function host(location: string): string | undefined;
|
|
38
|
+
/** The path inside its machine. */
|
|
39
|
+
function path(location: string): string;
|
|
40
|
+
/** The directory above; undefined at a root (`/`, `C:\\`, the root of a host). */
|
|
41
|
+
function parent(location: string): string | undefined;
|
|
42
|
+
function child(location: string, name: string): string;
|
|
43
|
+
/** The last name of the path; the host for its home directory. */
|
|
44
|
+
function basename(location: string): string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a conversation works: a directory of the machine of ta serve, as a path, or a directory of another
|
|
3
|
+
* machine that ta serve reaches with ssh, as `ssh://<host>/<absolute path>`. `<host>` is what ssh takes:
|
|
4
|
+
* a Host of ~/.ssh/config, or `[user@]host[:port]`. Without a path (`ssh://<host>`) it is the home
|
|
5
|
+
* directory there, which TaRemoteServer.resolveLocation turns into a path.
|
|
6
|
+
*/
|
|
7
|
+
export var TaLocation;
|
|
8
|
+
(function (TaLocation) {
|
|
9
|
+
TaLocation.SSH = 'ssh://';
|
|
10
|
+
/** Letters, digits and `_ . @ : % + - [ ]`, not first a `-`: ssh must not read a host as an option. */
|
|
11
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
12
|
+
function isRemote(location) {
|
|
13
|
+
return location.startsWith(TaLocation.SSH);
|
|
14
|
+
}
|
|
15
|
+
TaLocation.isRemote = isRemote;
|
|
16
|
+
/** undefined for a path of the machine of ta serve; throws for an `ssh://` location that is not one. */
|
|
17
|
+
function parse(location) {
|
|
18
|
+
if (!isRemote(location)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const rest = location.slice(TaLocation.SSH.length);
|
|
22
|
+
const slash = rest.indexOf('/');
|
|
23
|
+
const host = slash < 0 ? rest : rest.slice(0, slash);
|
|
24
|
+
const path = slash < 0 ? '' : normalize(rest.slice(slash));
|
|
25
|
+
if (!isHost(host)) {
|
|
26
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
27
|
+
}
|
|
28
|
+
return { host, path };
|
|
29
|
+
}
|
|
30
|
+
TaLocation.parse = parse;
|
|
31
|
+
function isHost(host) {
|
|
32
|
+
return HOST.test(host);
|
|
33
|
+
}
|
|
34
|
+
TaLocation.isHost = isHost;
|
|
35
|
+
/** Options of ssh without a value, which change nothing for Ta. */
|
|
36
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
37
|
+
/**
|
|
38
|
+
* A host as the user may write it: `dev`, `me@dev`, `me@dev:2222`, `ssh://me@dev:2222/path`, or the
|
|
39
|
+
* command line they use (`ssh -p 2222 me@dev`, `ssh me@dev -p 2222 -l root`). Options that a host
|
|
40
|
+
* cannot hold (`-i`, `-J`, `-o ProxyCommand=…`) belong in ~/.ssh/config: they come back as `options`.
|
|
41
|
+
*/
|
|
42
|
+
function readHost(input) {
|
|
43
|
+
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
44
|
+
if (words[0] === 'ssh') {
|
|
45
|
+
words.shift();
|
|
46
|
+
}
|
|
47
|
+
let destination;
|
|
48
|
+
let port;
|
|
49
|
+
let user;
|
|
50
|
+
const options = [];
|
|
51
|
+
for (let i = 0; i < words.length; i++) {
|
|
52
|
+
const word = words[i];
|
|
53
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
54
|
+
if (word === '-p' || word === '-l' || glued) {
|
|
55
|
+
const value = glued ? glued[2] : words[++i];
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
return { error: 'invalid' };
|
|
58
|
+
}
|
|
59
|
+
if ((glued ? glued[1] : word[1]) === 'p') {
|
|
60
|
+
port = value;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
user = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (word === '-o' || word.startsWith('-o')) {
|
|
67
|
+
const value = word === '-o' ? words[++i] : word.slice(2);
|
|
68
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== void 0 ? value : '');
|
|
69
|
+
if (!option) {
|
|
70
|
+
options.push(`-o ${value !== null && value !== void 0 ? value : ''}`.trim());
|
|
71
|
+
}
|
|
72
|
+
else if (option[1].toLowerCase() === 'port') {
|
|
73
|
+
port = option[2];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
user = option[2];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (FLAGS.test(word)) {
|
|
80
|
+
// No value, nothing for Ta.
|
|
81
|
+
}
|
|
82
|
+
else if (word.startsWith('-')) {
|
|
83
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
84
|
+
}
|
|
85
|
+
else if (destination === undefined) {
|
|
86
|
+
destination = word;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// A command to run there: not a host.
|
|
90
|
+
return { error: 'invalid' };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (options.length > 0) {
|
|
94
|
+
return { error: 'options', options };
|
|
95
|
+
}
|
|
96
|
+
if (!destination) {
|
|
97
|
+
return { error: 'empty' };
|
|
98
|
+
}
|
|
99
|
+
let host = destination.replace(/^ssh:\/\//, '').replace(/\/.*$/, '');
|
|
100
|
+
if (user && !host.includes('@')) {
|
|
101
|
+
host = `${user}@${host}`;
|
|
102
|
+
}
|
|
103
|
+
if (port) {
|
|
104
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host)) {
|
|
105
|
+
return { error: 'invalid' };
|
|
106
|
+
}
|
|
107
|
+
host = port === '22' ? host : `${host}:${port}`;
|
|
108
|
+
}
|
|
109
|
+
return isHost(host) ? { host } : { error: 'invalid' };
|
|
110
|
+
}
|
|
111
|
+
TaLocation.readHost = readHost;
|
|
112
|
+
/** `ssh://<host><path>`; `path` absolute, or empty for the home directory. */
|
|
113
|
+
function ssh(host, path = '') {
|
|
114
|
+
return `${TaLocation.SSH}${host}${path ? normalize(path) : ''}`;
|
|
115
|
+
}
|
|
116
|
+
TaLocation.ssh = ssh;
|
|
117
|
+
/** The host of a remote location; undefined for this machine. */
|
|
118
|
+
function host(location) {
|
|
119
|
+
var _a;
|
|
120
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === void 0 ? void 0 : _a.host : undefined;
|
|
121
|
+
}
|
|
122
|
+
TaLocation.host = host;
|
|
123
|
+
/** The path inside its machine. */
|
|
124
|
+
function path(location) {
|
|
125
|
+
var _a;
|
|
126
|
+
var _b;
|
|
127
|
+
return (_b = (_a = parse(location)) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : location;
|
|
128
|
+
}
|
|
129
|
+
TaLocation.path = path;
|
|
130
|
+
/** The directory above; undefined at a root (`/`, `C:\\`, the root of a host). */
|
|
131
|
+
function parent(location) {
|
|
132
|
+
const remote = parse(location);
|
|
133
|
+
if (remote) {
|
|
134
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
135
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
136
|
+
}
|
|
137
|
+
return parentPath(location);
|
|
138
|
+
}
|
|
139
|
+
TaLocation.parent = parent;
|
|
140
|
+
function child(location, name) {
|
|
141
|
+
const remote = parse(location);
|
|
142
|
+
if (remote) {
|
|
143
|
+
return ssh(remote.host, childPath(remote.path || '/', name));
|
|
144
|
+
}
|
|
145
|
+
return childPath(location, name);
|
|
146
|
+
}
|
|
147
|
+
TaLocation.child = child;
|
|
148
|
+
/** The last name of the path; the host for its home directory. */
|
|
149
|
+
function basename(location) {
|
|
150
|
+
const remote = parse(location);
|
|
151
|
+
const path = (remote ? remote.path : location).replace(/[\\/]+$/, '');
|
|
152
|
+
const name = path.slice(Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')) + 1);
|
|
153
|
+
return name || (remote === null || remote === void 0 ? void 0 : remote.host) || location;
|
|
154
|
+
}
|
|
155
|
+
TaLocation.basename = basename;
|
|
156
|
+
function parentPath(path) {
|
|
157
|
+
const trimmed = path.replace(/[\\/]+$/, '');
|
|
158
|
+
const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
159
|
+
if (at < 0) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const head = trimmed.slice(0, at);
|
|
163
|
+
return head === '' || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
164
|
+
}
|
|
165
|
+
function childPath(path, name) {
|
|
166
|
+
const separator = path.includes('/') || !path.includes('\\') ? '/' : '\\';
|
|
167
|
+
return path.endsWith(separator) ? path + name : path + separator + name;
|
|
168
|
+
}
|
|
169
|
+
/** One `/` between names, none at the end but for the root. */
|
|
170
|
+
function normalize(path) {
|
|
171
|
+
const squeezed = `/${path}`.replace(/\/+/g, '/');
|
|
172
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, '') : squeezed;
|
|
173
|
+
}
|
|
174
|
+
})(TaLocation || (TaLocation = {}));
|
|
175
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.js","source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IAAI,CAAC;IAC/E,CAAC;IAED,SAAS,SAAS,CAAC,IAAY,EAAE,IAAY;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;IAC5E,CAAC;IAED,+DAA+D;IAC/D,SAAS,SAAS,CAAC,IAAY;QAC3B,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxE,CAAC;AACL,CAAC,EA1KgB,UAAU,KAAV,UAAU,QA0K1B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export declare const TaRemoteServer: unique symbol;
|
|
2
|
+
export declare const TA_REMOTE_SERVICE = "TaRemoteServer";
|
|
3
|
+
/** A machine ta serve can reach with ssh. */
|
|
4
|
+
export interface TaRemoteHost {
|
|
5
|
+
/** What follows `ssh://` in a location (TaLocation). */
|
|
6
|
+
host: string;
|
|
7
|
+
/** A Host of ~/.ssh/config, or one opened before. */
|
|
8
|
+
source: 'config' | 'recent';
|
|
9
|
+
/** ta serve is connected to it now. */
|
|
10
|
+
connected: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What ssh asks while it connects (a password, a passphrase, whether to trust a new host key), for
|
|
14
|
+
* whoever is there to answer: `confirm` takes `yes` or `no`, `secret` is not shown as typed.
|
|
15
|
+
*/
|
|
16
|
+
export interface TaRemotePrompt {
|
|
17
|
+
promptId: string;
|
|
18
|
+
host: string;
|
|
19
|
+
kind: 'secret' | 'confirm' | 'text';
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
/** What happens with the remote machines, to the connections that called TaRemoteServer.watch. */
|
|
23
|
+
export type TaRemoteEvent = {
|
|
24
|
+
type: 'prompt';
|
|
25
|
+
prompt: TaRemotePrompt;
|
|
26
|
+
}
|
|
27
|
+
/** Answered, by this client or another, or ssh no longer waits. */
|
|
28
|
+
| {
|
|
29
|
+
type: 'prompt_closed';
|
|
30
|
+
promptId: string;
|
|
31
|
+
}
|
|
32
|
+
/** A step of connecting that takes a while: the first connection installs things there. */
|
|
33
|
+
| {
|
|
34
|
+
type: 'progress';
|
|
35
|
+
host: string;
|
|
36
|
+
step: TaRemoteStep;
|
|
37
|
+
detail?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Connected to the host, or no longer. */
|
|
40
|
+
| {
|
|
41
|
+
type: 'connection';
|
|
42
|
+
host: string;
|
|
43
|
+
connected: boolean;
|
|
44
|
+
error?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The steps of connecting to a host: ssh signs in, then Ta looks at what the host has, installs Node.js
|
|
48
|
+
* there when it has none (`detail`: the version), copies its small server, and starts it.
|
|
49
|
+
*/
|
|
50
|
+
export type TaRemoteStep = 'connecting' | 'checking' | 'installing-node' | 'copying-server' | 'starting';
|
|
51
|
+
/** A port of another machine, reachable on the machine of ta serve. */
|
|
52
|
+
export interface TaForwardedPort {
|
|
53
|
+
host: string;
|
|
54
|
+
/** On the other machine. */
|
|
55
|
+
remotePort: number;
|
|
56
|
+
/** On the machine of ta serve, at 127.0.0.1. */
|
|
57
|
+
localPort: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Other machines that conversations work on, as VS Code's Remote SSH: the agent runs with ta serve, and
|
|
61
|
+
* its commands and files are there, through the `ssh` of the machine of ta serve with its configuration.
|
|
62
|
+
*/
|
|
63
|
+
export interface TaRemoteServer {
|
|
64
|
+
/** The Hosts of ~/.ssh/config without wildcards, and those added or opened before, the latest first. */
|
|
65
|
+
listHosts(): Promise<TaRemoteHost[]>;
|
|
66
|
+
/** Keeps a host in the list (`recent`), without connecting to it. */
|
|
67
|
+
addHost(host: string): Promise<void>;
|
|
68
|
+
/** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
|
|
69
|
+
removeHost(host: string): Promise<void>;
|
|
70
|
+
/** The location with the path of the home directory when it has none; connects to the host. */
|
|
71
|
+
resolveLocation(location: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* A port of the machine of `cwd` on the machine of ta serve, for a page served there: the same port
|
|
74
|
+
* when `cwd` is a directory of this machine. It stays open while ta serve runs.
|
|
75
|
+
*/
|
|
76
|
+
forwardPort(port: number, cwd?: string): Promise<TaForwardedPort>;
|
|
77
|
+
listForwardedPorts(): Promise<TaForwardedPort[]>;
|
|
78
|
+
closeForwardedPort(host: string, remotePort: number): Promise<void>;
|
|
79
|
+
/** This connection hears TaClient.onRemoteEvent from now; resolves to the prompts that wait. */
|
|
80
|
+
watch(): Promise<TaRemotePrompt[]>;
|
|
81
|
+
/** The answer to a prompt; `null` cancels it. False when it no longer waits. */
|
|
82
|
+
answer(promptId: string, value: string | null): Promise<boolean>;
|
|
83
|
+
/** Ends the connection to the host, its processes and forwarded ports there. */
|
|
84
|
+
disconnect(host: string): Promise<void>;
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-protocol.js","sourceRoot":"","sources":["../../src/common/remote-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC"}
|
|
@@ -28,6 +28,8 @@ export interface TaSettingsSnapshot {
|
|
|
28
28
|
projectTrusted: boolean;
|
|
29
29
|
/** `<provider>/<model id>` of the models with credentials, for the model setting. */
|
|
30
30
|
models: string[];
|
|
31
|
+
/** The names of those of `models` that have one other than their id. */
|
|
32
|
+
modelNames?: Record<string, string>;
|
|
31
33
|
}
|
|
32
34
|
/** The settings of ta in pi's `settings.json` files, on the same WebSocket as {@link TaServer}. */
|
|
33
35
|
export interface TaSettingsServer {
|
|
@@ -39,4 +41,9 @@ export interface TaSettingsServer {
|
|
|
39
41
|
* level are for new sessions.
|
|
40
42
|
*/
|
|
41
43
|
updateSettings(scope: TaSettingsScope, changes: Record<string, unknown>, cwd?: string): Promise<TaSettingsSnapshot>;
|
|
44
|
+
/**
|
|
45
|
+
* The language the user reads (`zh-CN`, `en-US`), for what the server and the pi packages it runs say:
|
|
46
|
+
* it is `TA_LANGUAGE` of the process of ta serve, which they read. The client that set it last wins.
|
|
47
|
+
*/
|
|
48
|
+
setLanguage(language: string): Promise<void>;
|
|
42
49
|
}
|
|
@@ -2,12 +2,14 @@ import type { TaPackageServer } from './package-protocol.js';
|
|
|
2
2
|
import type { TaServer } from './ta-protocol.js';
|
|
3
3
|
/**
|
|
4
4
|
* What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
|
|
5
|
-
* process, without a token. A subset of TaServer and TaPackageServer: it can open
|
|
6
|
-
*
|
|
5
|
+
* process, without a token. A subset of TaServer and TaPackageServer: it can open, drive, stop and close
|
|
6
|
+
* sessions (best those it opened: closing one takes it from every client), not remove anything.
|
|
7
7
|
*/
|
|
8
|
-
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'setSessionName' | 'prompt' | 'followUp' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
|
|
8
|
+
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
|
|
9
9
|
/** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
|
|
10
10
|
readonly agentDir: string;
|
|
11
|
+
/** Where the conversation of a session file works, as clients name it (a path or an `ssh://` location), without opening it; undefined when it cannot be read. */
|
|
12
|
+
sessionCwd(sessionFile: string): Promise<string | undefined>;
|
|
11
13
|
/** Keys of the data of a package that changed, by a page or by the server, as they change; `cwd` for a key of a directory. */
|
|
12
14
|
onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
|
|
13
15
|
}
|
|
@@ -32,6 +34,19 @@ export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService |
|
|
|
32
34
|
* and the extension should say its tools need `ta serve`.
|
|
33
35
|
*/
|
|
34
36
|
export declare const TA_HOST_EVENT = "ta:host";
|
|
37
|
+
/**
|
|
38
|
+
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
39
|
+
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
40
|
+
* write if it can: `pi.events.emit(TA_FILE_WRITE_EVENT, file)`. The list of changed files (ta-changes)
|
|
41
|
+
* keeps what the file holds then.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TA_FILE_WRITE_EVENT = "ta:file-write";
|
|
44
|
+
export interface TaFileWrite {
|
|
45
|
+
/** Absolute, on the machine where the session's tools work. */
|
|
46
|
+
path: string;
|
|
47
|
+
/** Its text before the change, when known (a diff of the agent); null: there was no file. */
|
|
48
|
+
before?: string | null;
|
|
49
|
+
}
|
|
35
50
|
export interface TaHostRequest {
|
|
36
51
|
/** The `name` of the package.json. */
|
|
37
52
|
name: string;
|
|
@@ -41,4 +56,19 @@ export interface TaHostAnswer {
|
|
|
41
56
|
host: TaExtensionHost;
|
|
42
57
|
/** What the module of `pi.host` of the package returned; undefined when it has none or failed. */
|
|
43
58
|
service?: TaPackageService;
|
|
59
|
+
/** The files of the session that asked, where its tools read and write. */
|
|
60
|
+
files: TaSessionFiles;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The files of a session where its tools work: on the machine of `ta serve`, or on the one of an
|
|
64
|
+
* `ssh://` directory (ExecEnvironment). Paths are those {@link resolve} gives.
|
|
65
|
+
*/
|
|
66
|
+
export interface TaSessionFiles {
|
|
67
|
+
/** The path a tool of the session (read, edit, write) works on for a path of its arguments. */
|
|
68
|
+
resolve(path: string): string;
|
|
69
|
+
/** The bytes of a file; undefined when there is no file there. */
|
|
70
|
+
read(path: string): Promise<Uint8Array | undefined>;
|
|
71
|
+
/** Writes a file, and the directories it needs. */
|
|
72
|
+
write(path: string, data: Uint8Array): Promise<void>;
|
|
73
|
+
remove(path: string): Promise<void>;
|
|
44
74
|
}
|
|
@@ -5,4 +5,11 @@
|
|
|
5
5
|
* and the extension should say its tools need `ta serve`.
|
|
6
6
|
*/
|
|
7
7
|
export const TA_HOST_EVENT = 'ta:host';
|
|
8
|
+
/**
|
|
9
|
+
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
10
|
+
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
11
|
+
* write if it can: `pi.events.emit(TA_FILE_WRITE_EVENT, file)`. The list of changed files (ta-changes)
|
|
12
|
+
* keeps what the file holds then.
|
|
13
|
+
*/
|
|
14
|
+
export const TA_FILE_WRITE_EVENT = 'ta:file-write';
|
|
8
15
|
//# sourceMappingURL=ta-extension-host.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ta-extension-host.js","sourceRoot":"","sources":["../../src/common/ta-extension-host.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ta-extension-host.js","sourceRoot":"","sources":["../../src/common/ta-extension-host.ts"],"names":[],"mappings":"AA+CA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC"}
|
|
@@ -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 { TaRemoteEvent } from './remote-protocol.js';
|
|
3
4
|
export declare const TaServer: unique symbol;
|
|
4
5
|
export declare const TaClient: unique symbol;
|
|
5
6
|
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
@@ -23,6 +24,10 @@ export interface TaServerInfo {
|
|
|
23
24
|
* `setWorkingDirectory`, else the working directory of `ta serve`, or of its execution environment.
|
|
24
25
|
*/
|
|
25
26
|
cwd: string;
|
|
27
|
+
/** The user who runs `ta serve`, as the system names them: whose Ta the client is signed in to. */
|
|
28
|
+
user: string;
|
|
29
|
+
/** The name of the machine of `ta serve`, without a `.local` suffix. */
|
|
30
|
+
host: string;
|
|
26
31
|
}
|
|
27
32
|
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
28
33
|
export declare const TaErrorCode: {
|
|
@@ -82,7 +87,7 @@ export interface TaClientToolDefinition {
|
|
|
82
87
|
parameters: Record<string, unknown>;
|
|
83
88
|
}
|
|
84
89
|
export interface TaOpenSessionOptions {
|
|
85
|
-
/** Working directory of the session
|
|
90
|
+
/** Working directory of the session: a path of the machine of the server, or an `ssh://` location of another (TaLocation). */
|
|
86
91
|
cwd: string;
|
|
87
92
|
/** Opens this session file; default: a new session. */
|
|
88
93
|
sessionFile?: string;
|
|
@@ -197,6 +202,11 @@ export interface TaAttachResult {
|
|
|
197
202
|
pendingUi: RpcExtensionUIRequest[];
|
|
198
203
|
/** The calls of client tools still waiting for a result. */
|
|
199
204
|
pendingClientTools: TaClientToolRequest[];
|
|
205
|
+
/**
|
|
206
|
+
* What the extensions show now (`setStatus`, `setWidget`), as a terminal keeps it on screen: a client
|
|
207
|
+
* that attaches draws it, whatever it missed. None from a server before it.
|
|
208
|
+
*/
|
|
209
|
+
shownUi?: RpcExtensionUIRequest[];
|
|
200
210
|
/** Seq of the last event of the session. */
|
|
201
211
|
lastSeq: number;
|
|
202
212
|
/** Some events after `afterSeq` are gone: read the conversation again with `getMessages`. */
|
|
@@ -214,7 +224,7 @@ export interface TaClientToolResult {
|
|
|
214
224
|
* The sessions of `ta serve`, over JSON-RPC 2.0 on a WebSocket. Besides opening, attaching and answering,
|
|
215
225
|
* each method is the command of pi's RPC mode with the same name in camelCase, on the open session
|
|
216
226
|
* `sessionId` (see PiCommandMethod). The same WebSocket carries the other services of ta serve, each
|
|
217
|
-
* under its own name: TaWorkspaceServer, TaTerminalServer, TaSettingsServer and
|
|
227
|
+
* under its own name: TaWorkspaceServer, TaTerminalServer, TaSettingsServer, TaPackageServer, TaRemoteServer and others.
|
|
218
228
|
*/
|
|
219
229
|
export interface TaServer {
|
|
220
230
|
getServerInfo(): Promise<TaServerInfo>;
|
|
@@ -296,5 +306,7 @@ export interface TaClient {
|
|
|
296
306
|
onExtensionData(name: string, keys: string[], cwd?: string): Promise<void>;
|
|
297
307
|
/** What happens during a sign-in this connection started (TaAuthServer.login). */
|
|
298
308
|
onAuthEvent(loginId: string, event: TaAuthEvent): Promise<void>;
|
|
309
|
+
/** What happens with the remote machines, once this connection called TaRemoteServer.watch. */
|
|
310
|
+
onRemoteEvent(event: TaRemoteEvent): Promise<void>;
|
|
299
311
|
}
|
|
300
312
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ta-protocol.js","sourceRoot":"","sources":["../../src/common/ta-protocol.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ta-protocol.js","sourceRoot":"","sources":["../../src/common/ta-protocol.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,QAAQ,GAAG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MB. */
|
|
32
32
|
maxBytes?: number;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The most bytes of a part of {@link TaWorkspaceServer.uploadFile}: a larger file goes in parts of this size,
|
|
36
|
+
* well within what a message of the WebSocket may hold once in base64.
|
|
37
|
+
*/
|
|
38
|
+
export declare const TA_UPLOAD_PART_BYTES: number;
|
|
39
|
+
export interface TaUploadOptions {
|
|
40
|
+
/** Default: the server's directory. */
|
|
41
|
+
cwd?: string;
|
|
42
|
+
/** After what the file holds: each part of a file sent in parts but the first. */
|
|
43
|
+
append?: boolean;
|
|
44
|
+
}
|
|
34
45
|
export interface TaCommandOutput {
|
|
35
46
|
stdout: string;
|
|
36
47
|
stderr: string;
|
|
@@ -51,6 +62,11 @@ export interface TaWorkspaceServer {
|
|
|
51
62
|
readFile(path: string, cwd?: string): Promise<TaFileContent>;
|
|
52
63
|
/** Writes the text of a file; its directory must be there. */
|
|
53
64
|
writeFile(path: string, text: string, cwd?: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Writes bytes, in base64, to a file (one uploaded): the folders on its way are made, and a file there is
|
|
67
|
+
* replaced. A file larger than {@link TA_UPLOAD_PART_BYTES} goes in parts, each after the first with `append`.
|
|
68
|
+
*/
|
|
69
|
+
uploadFile(path: string, data: string, options?: TaUploadOptions): Promise<void>;
|
|
54
70
|
/**
|
|
55
71
|
* A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
|
|
56
72
|
* what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
|
|
@@ -4,4 +4,9 @@ export const TaWorkspaceServer = Symbol('TaWorkspaceServer');
|
|
|
4
4
|
export const TA_WORKSPACE_SERVICE = 'TaWorkspaceServer';
|
|
5
5
|
export const TaTerminalServer = Symbol('TaTerminalServer');
|
|
6
6
|
export const TA_TERMINAL_SERVICE = 'TaTerminalServer';
|
|
7
|
+
/**
|
|
8
|
+
* The most bytes of a part of {@link TaWorkspaceServer.uploadFile}: a larger file goes in parts of this size,
|
|
9
|
+
* well within what a message of the WebSocket may hold once in base64.
|
|
10
|
+
*/
|
|
11
|
+
export const TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
|
|
7
12
|
//# sourceMappingURL=workspace-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-protocol.js","sourceRoot":"","sources":["../../src/common/workspace-protocol.ts"],"names":[],"mappings":"AAEA,qGAAqG;AACrG,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"workspace-protocol.js","sourceRoot":"","sources":["../../src/common/workspace-protocol.ts"],"names":[],"mappings":"AAEA,qGAAqG;AACrG,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAgCtD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC"}
|
package/lib/common/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './auth-protocol';
|
|
2
|
+
export * from './location';
|
|
2
3
|
export * from './package-protocol';
|
|
3
4
|
export * from './pi-types';
|
|
4
5
|
export * from './relay-protocol';
|
|
6
|
+
export * from './remote-protocol';
|
|
5
7
|
export * from './settings-protocol';
|
|
6
8
|
export * from './ta-extension-host';
|
|
7
9
|
export * from './ta-protocol';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
|
package/lib/common/index.js
CHANGED
|
@@ -15,9 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./auth-protocol"), exports);
|
|
18
|
+
__exportStar(require("./location"), exports);
|
|
18
19
|
__exportStar(require("./package-protocol"), exports);
|
|
19
20
|
__exportStar(require("./pi-types"), exports);
|
|
20
21
|
__exportStar(require("./relay-protocol"), exports);
|
|
22
|
+
__exportStar(require("./remote-protocol"), exports);
|
|
21
23
|
__exportStar(require("./settings-protocol"), exports);
|
|
22
24
|
__exportStar(require("./ta-extension-host"), exports);
|
|
23
25
|
__exportStar(require("./ta-protocol"), exports);
|
package/lib/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,qDAAmC;AACnC,6CAA2B;AAC3B,mDAAiC;AACjC,sDAAoC;AACpC,sDAAoC;AACpC,gDAA8B;AAC9B,uDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6CAA2B;AAC3B,qDAAmC;AACnC,6CAA2B;AAC3B,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,sDAAoC;AACpC,gDAA8B;AAC9B,uDAAqC"}
|