@celljs/ta-protocol 4.5.1 → 4.6.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.md +6 -5
- package/esm/common/auth-protocol.d.ts +89 -0
- package/esm/common/auth-protocol.js +3 -0
- package/esm/common/auth-protocol.js.map +1 -0
- package/esm/common/index.d.ts +6 -0
- package/esm/common/index.js +6 -0
- package/esm/common/index.js.map +1 -1
- package/esm/common/package-protocol.d.ts +92 -0
- package/esm/common/package-protocol.js +3 -0
- package/esm/common/package-protocol.js.map +1 -0
- package/esm/common/pi-types.d.ts +1 -0
- package/esm/common/relay-protocol.d.ts +28 -0
- package/esm/common/relay-protocol.js +3 -0
- package/esm/common/relay-protocol.js.map +1 -0
- package/esm/common/settings-protocol.d.ts +42 -0
- package/esm/common/settings-protocol.js +22 -0
- package/esm/common/settings-protocol.js.map +1 -0
- package/esm/common/ta-extension-host.d.ts +44 -0
- package/esm/common/ta-extension-host.js +8 -0
- package/esm/common/ta-extension-host.js.map +1 -0
- package/esm/common/ta-protocol.d.ts +110 -8
- package/esm/common/ta-protocol.js +21 -0
- package/esm/common/ta-protocol.js.map +1 -1
- package/esm/common/workspace-protocol.d.ts +91 -0
- package/esm/common/workspace-protocol.js +7 -0
- package/esm/common/workspace-protocol.js.map +1 -0
- package/lib/common/auth-protocol.d.ts +90 -0
- package/lib/common/auth-protocol.d.ts.map +1 -0
- package/lib/common/auth-protocol.js +6 -0
- package/lib/common/auth-protocol.js.map +1 -0
- package/lib/common/index.d.ts +6 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +6 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/package-protocol.d.ts +93 -0
- package/lib/common/package-protocol.d.ts.map +1 -0
- package/lib/common/package-protocol.js +6 -0
- package/lib/common/package-protocol.js.map +1 -0
- package/lib/common/pi-types.d.ts +1 -0
- package/lib/common/pi-types.d.ts.map +1 -1
- package/lib/common/relay-protocol.d.ts +29 -0
- package/lib/common/relay-protocol.d.ts.map +1 -0
- package/lib/common/relay-protocol.js +6 -0
- package/lib/common/relay-protocol.js.map +1 -0
- package/lib/common/settings-protocol.d.ts +43 -0
- package/lib/common/settings-protocol.d.ts.map +1 -0
- package/lib/common/settings-protocol.js +25 -0
- package/lib/common/settings-protocol.js.map +1 -0
- package/lib/common/ta-extension-host.d.ts +45 -0
- package/lib/common/ta-extension-host.d.ts.map +1 -0
- package/lib/common/ta-extension-host.js +11 -0
- package/lib/common/ta-extension-host.js.map +1 -0
- package/lib/common/ta-protocol.d.ts +110 -8
- package/lib/common/ta-protocol.d.ts.map +1 -1
- package/lib/common/ta-protocol.js +22 -1
- package/lib/common/ta-protocol.js.map +1 -1
- package/lib/common/ta-protocol.spec.js +21 -0
- package/lib/common/ta-protocol.spec.js.map +1 -1
- package/lib/common/workspace-protocol.d.ts +92 -0
- package/lib/common/workspace-protocol.d.ts.map +1 -0
- package/lib/common/workspace-protocol.js +10 -0
- package/lib/common/workspace-protocol.js.map +1 -0
- package/package.json +1 -1
- package/src/common/auth-protocol.ts +56 -0
- package/src/common/index.ts +6 -0
- package/src/common/package-protocol.ts +99 -0
- package/src/common/pi-types.ts +1 -0
- package/src/common/relay-protocol.ts +28 -0
- package/src/common/settings-protocol.ts +66 -0
- package/src/common/ta-extension-host.ts +52 -0
- package/src/common/ta-protocol.spec.ts +30 -1
- package/src/common/ta-protocol.ts +123 -7
- package/src/common/workspace-protocol.ts +102 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Where the page loads the bytes of workspace files from: see {@link TaWorkspaceServer.fileUrl}. */
|
|
2
|
+
export declare const TA_FILES_PATH = "/api/files";
|
|
3
|
+
export declare const TaWorkspaceServer: unique symbol;
|
|
4
|
+
export declare const TA_WORKSPACE_SERVICE = "TaWorkspaceServer";
|
|
5
|
+
export declare const TaTerminalServer: unique symbol;
|
|
6
|
+
export declare const TA_TERMINAL_SERVICE = "TaTerminalServer";
|
|
7
|
+
/** An entry of a directory of the workspace. */
|
|
8
|
+
export interface TaDirEntry {
|
|
9
|
+
name: string;
|
|
10
|
+
/** Relative to the directory the call names as `cwd`, with `/`. */
|
|
11
|
+
path: string;
|
|
12
|
+
kind: 'file' | 'directory';
|
|
13
|
+
size?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TaFileContent {
|
|
16
|
+
path: string;
|
|
17
|
+
size: number;
|
|
18
|
+
/** Not text: `text` is left out. */
|
|
19
|
+
binary: boolean;
|
|
20
|
+
/** Larger than the limit (1 MB): `text` holds the start. */
|
|
21
|
+
truncated: boolean;
|
|
22
|
+
text?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TaRunCommandOptions {
|
|
25
|
+
/** Default: the server's directory. */
|
|
26
|
+
cwd?: string;
|
|
27
|
+
/** Written to the standard input, which is then closed. */
|
|
28
|
+
input?: string;
|
|
29
|
+
/** Default 30 s, at most 120 s; the process is killed then. */
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
/** Of each of stdout and stderr; default 1 MB, at most 8 MB. */
|
|
32
|
+
maxBytes?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface TaCommandOutput {
|
|
35
|
+
stdout: string;
|
|
36
|
+
stderr: string;
|
|
37
|
+
/** null when it was killed (`timedOut`) or ended by a signal. */
|
|
38
|
+
exitCode: number | null;
|
|
39
|
+
/** An output was longer than `maxBytes`: it holds the start. */
|
|
40
|
+
truncated: boolean;
|
|
41
|
+
timedOut: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The files of a directory of the machine of `ta serve` and programs run there, on the same WebSocket as
|
|
45
|
+
* {@link TaServer}. Paths are relative to `cwd` (default: the server's directory) and may not leave it;
|
|
46
|
+
* the work runs in the execution environment of `cwd`, as the tools of a session do.
|
|
47
|
+
*/
|
|
48
|
+
export interface TaWorkspaceServer {
|
|
49
|
+
/** Directories first, then by name; `.git` is left out. */
|
|
50
|
+
listDirectory(path: string, cwd?: string): Promise<TaDirEntry[]>;
|
|
51
|
+
readFile(path: string, cwd?: string): Promise<TaFileContent>;
|
|
52
|
+
/** Writes the text of a file; its directory must be there. */
|
|
53
|
+
writeFile(path: string, text: string, cwd?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
|
|
56
|
+
* what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
|
|
57
|
+
* no token, so that a page loads the files beside it with relative URLs; each `cwd` has its own
|
|
58
|
+
* secret part. Pages are answered sandboxed: they run in an origin of their own, not the server's.
|
|
59
|
+
*/
|
|
60
|
+
fileUrl(path: string, cwd?: string): Promise<string>;
|
|
61
|
+
/** Paths of files whose name matches `query` loosely, best first; ignored files are left out. */
|
|
62
|
+
findFiles(query: string, cwd?: string, limit?: number): Promise<string[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Runs a program with its arguments, without a shell, in the execution environment of `cwd`, and
|
|
65
|
+
* answers its output once it ends: what packages build on (git, rg) instead of a method each.
|
|
66
|
+
*/
|
|
67
|
+
runCommand(command: string, args: string[], options?: TaRunCommandOptions): Promise<TaCommandOutput>;
|
|
68
|
+
}
|
|
69
|
+
export interface TaTerminalInfo {
|
|
70
|
+
terminalId: string;
|
|
71
|
+
cwd: string;
|
|
72
|
+
shell: string;
|
|
73
|
+
/** False: plain pipes (no `script` on the server, or Windows): full-screen programs do not draw right. */
|
|
74
|
+
pty: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface TaOpenTerminalOptions {
|
|
77
|
+
/** Default: the server's directory. */
|
|
78
|
+
cwd?: string;
|
|
79
|
+
cols: number;
|
|
80
|
+
rows: number;
|
|
81
|
+
}
|
|
82
|
+
/** The shells of a connection, on the same WebSocket as {@link TaServer}. */
|
|
83
|
+
export interface TaTerminalServer {
|
|
84
|
+
/** A shell of this connection; its output comes by TaClient.onTerminalData. It closes 30 s after the connection drops. */
|
|
85
|
+
openTerminal(options: TaOpenTerminalOptions): Promise<TaTerminalInfo>;
|
|
86
|
+
writeTerminal(terminalId: string, data: string): Promise<void>;
|
|
87
|
+
resizeTerminal(terminalId: string, cols: number, rows: number): Promise<void>;
|
|
88
|
+
closeTerminal(terminalId: string): Promise<void>;
|
|
89
|
+
/** The terminals of this connection that are still open. */
|
|
90
|
+
listTerminals(): Promise<TaTerminalInfo[]>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=workspace-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-protocol.d.ts","sourceRoot":"","sources":["../../src/common/workspace-protocol.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TA_TERMINAL_SERVICE = exports.TaTerminalServer = exports.TA_WORKSPACE_SERVICE = exports.TaWorkspaceServer = exports.TA_FILES_PATH = void 0;
|
|
4
|
+
/** Where the page loads the bytes of workspace files from: see {@link TaWorkspaceServer.fileUrl}. */
|
|
5
|
+
exports.TA_FILES_PATH = '/api/files';
|
|
6
|
+
exports.TaWorkspaceServer = Symbol('TaWorkspaceServer');
|
|
7
|
+
exports.TA_WORKSPACE_SERVICE = 'TaWorkspaceServer';
|
|
8
|
+
exports.TaTerminalServer = Symbol('TaTerminalServer');
|
|
9
|
+
exports.TA_TERMINAL_SERVICE = 'TaTerminalServer';
|
|
10
|
+
//# sourceMappingURL=workspace-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-protocol.js","sourceRoot":"","sources":["../../src/common/workspace-protocol.ts"],"names":[],"mappings":";;;AAEA,qGAAqG;AACxF,QAAA,aAAa,GAAG,YAAY,CAAC;AAE7B,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAChD,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAC3C,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC9C,QAAA,mBAAmB,GAAG,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const TaAuthServer = Symbol('TaAuthServer');
|
|
2
|
+
export const TA_AUTH_SERVICE = 'TaAuthServer';
|
|
3
|
+
|
|
4
|
+
/** How pi signs in to a provider: an account (OAuth), often a subscription, or an API key. */
|
|
5
|
+
export type TaAuthType = 'oauth' | 'api_key';
|
|
6
|
+
|
|
7
|
+
/** One way to sign in to a provider of models, as pi's `/login` lists them: a provider with both is listed twice. */
|
|
8
|
+
export interface TaAuthProvider {
|
|
9
|
+
/** pi's id of the provider, e.g. `anthropic`. */
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: TaAuthType;
|
|
13
|
+
/** The account is a subscription (Claude Pro, ChatGPT Plus…), not paid per request. */
|
|
14
|
+
subscription: boolean;
|
|
15
|
+
/** False for a key that only comes from the environment (variables, cloud profiles): there is nothing to type in. */
|
|
16
|
+
interactive: boolean;
|
|
17
|
+
/** How the provider is signed in now, if it is: with which kind, and from where (`stored credential`, an environment variable…). */
|
|
18
|
+
configured?: { type: TaAuthType; source?: string };
|
|
19
|
+
/** pi keeps a credential of it in auth.json, which `logout` removes. */
|
|
20
|
+
stored: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What a sign-in asks the user, as pi's AuthPrompt: an answer goes back with `answer`, a choice by its id. */
|
|
24
|
+
export type TaAuthPrompt =
|
|
25
|
+
| { type: 'text' | 'secret' | 'manual_code'; message: string; placeholder?: string }
|
|
26
|
+
| { type: 'select'; message: string; options: { id: string; label: string; description?: string }[] };
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What happens during a sign-in, to the connection that started it (TaClient.onAuthEvent). The first
|
|
30
|
+
* four are pi's AuthEvent: a page to open, a code to type in elsewhere, what it is doing.
|
|
31
|
+
*/
|
|
32
|
+
export type TaAuthEvent =
|
|
33
|
+
| { type: 'info'; message: string; links?: { url: string; label?: string }[] }
|
|
34
|
+
| { type: 'auth_url'; url: string; instructions?: string }
|
|
35
|
+
| { type: 'device_code'; userCode: string; verificationUri: string; expiresInSeconds?: number }
|
|
36
|
+
| { type: 'progress'; message: string }
|
|
37
|
+
| { type: 'prompt'; promptId: string; prompt: TaAuthPrompt }
|
|
38
|
+
/** The flow no longer waits for that answer: it got what it needed otherwise (a browser came back). */
|
|
39
|
+
| { type: 'prompt_closed'; promptId: string }
|
|
40
|
+
| { type: 'done' }
|
|
41
|
+
| { type: 'failed'; message: string; cancelled?: boolean };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Signing in to providers of models from a client, as pi's `/login` and `/logout` do in the terminal.
|
|
45
|
+
* Credentials go to pi's auth.json on the server, for every session; they never come back to a client.
|
|
46
|
+
*/
|
|
47
|
+
export interface TaAuthServer {
|
|
48
|
+
listProviders(): Promise<TaAuthProvider[]>;
|
|
49
|
+
/** Starts a sign-in; its events go to this connection only. Resolves at once with its id. */
|
|
50
|
+
login(providerId: string, type: TaAuthType): Promise<string>;
|
|
51
|
+
/** Answers a prompt of a sign-in of this connection; false when it no longer waits for it. */
|
|
52
|
+
answer(loginId: string, promptId: string, value: string): Promise<boolean>;
|
|
53
|
+
cancel(loginId: string): Promise<void>;
|
|
54
|
+
/** Removes the stored credential of the provider. */
|
|
55
|
+
logout(providerId: string): Promise<void>;
|
|
56
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
export * from './auth-protocol';
|
|
2
|
+
export * from './package-protocol';
|
|
1
3
|
export * from './pi-types';
|
|
4
|
+
export * from './relay-protocol';
|
|
5
|
+
export * from './settings-protocol';
|
|
6
|
+
export * from './ta-extension-host';
|
|
2
7
|
export * from './ta-protocol';
|
|
8
|
+
export * from './workspace-protocol';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { TaSettingsScope } from './settings-protocol';
|
|
2
|
+
import type { TaServer } from './ta-protocol';
|
|
3
|
+
|
|
4
|
+
export const TaPackageServer = Symbol('TaPackageServer');
|
|
5
|
+
export const TA_PACKAGE_SERVICE = 'TaPackageServer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A web extension: the part of a pi package that extends the web client, as `extensions` extend pi. A
|
|
9
|
+
* package declares it in its `package.json`, `"pi": { "web": ["./web.js"] }`, or keeps it in `web/`.
|
|
10
|
+
* It is one ES module, without imports, that exports a function the web client calls with its API.
|
|
11
|
+
*/
|
|
12
|
+
export interface TaWebExtensionInfo {
|
|
13
|
+
/** Stable while the package stays where it is. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** The `name` of the package, or the name of its directory. */
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
scope: 'user' | 'project';
|
|
20
|
+
/**
|
|
21
|
+
* `package`: a package of pi's `packages` setting (`ta install`). `directory`: a directory in `extensions/`.
|
|
22
|
+
* `builtin`: a package that comes with ta; it can be turned off (setPackageEnabled), not removed.
|
|
23
|
+
*/
|
|
24
|
+
origin: 'package' | 'directory' | 'builtin';
|
|
25
|
+
/** False for a built-in package that is turned off; the others are always on. */
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
/** The source in the `packages` setting, or the directory. */
|
|
28
|
+
source: string;
|
|
29
|
+
/** The file, relative to the package. */
|
|
30
|
+
entry: string;
|
|
31
|
+
/** Changes when the file changes. */
|
|
32
|
+
hash: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What a package holds: pi extensions, web extensions, skills, prompt templates, themes. */
|
|
36
|
+
export type TaPackageResource = 'extensions' | 'web' | 'skills' | 'prompts' | 'themes';
|
|
37
|
+
|
|
38
|
+
/** A pi package that Ta loads, whether it has a web extension or not. */
|
|
39
|
+
export interface TaPackageInfo {
|
|
40
|
+
/** Stable while the package stays where it is. */
|
|
41
|
+
id: string;
|
|
42
|
+
/** The `name` of its package.json, or the name of its directory. */
|
|
43
|
+
name: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
version?: string;
|
|
46
|
+
scope: 'user' | 'project';
|
|
47
|
+
/** As TaWebExtensionInfo.origin. */
|
|
48
|
+
origin: TaWebExtensionInfo['origin'];
|
|
49
|
+
/** False for a built-in package that is turned off. */
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
/** The source in the `packages` setting, or the directory. */
|
|
52
|
+
source: string;
|
|
53
|
+
/** Its directory, on the machine of the server. */
|
|
54
|
+
root: string;
|
|
55
|
+
/** What it holds, by its package.json or, without `pi` there, by the directories pi looks in. */
|
|
56
|
+
resources: TaPackageResource[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TaWebExtensionSource {
|
|
60
|
+
id: string;
|
|
61
|
+
hash: string;
|
|
62
|
+
code: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The packages of ta and the data they keep, on the same WebSocket as {@link TaServer}. */
|
|
66
|
+
export interface TaPackageServer {
|
|
67
|
+
/** The web extensions of the packages pi loads in `cwd` (default: the server's directory). */
|
|
68
|
+
listWebExtensions(cwd?: string): Promise<TaWebExtensionInfo[]>;
|
|
69
|
+
readWebExtension(id: string, cwd?: string): Promise<TaWebExtensionSource>;
|
|
70
|
+
/** Removes the package of a web extension: as `ta remove` for a package, deletes the directory for a directory. */
|
|
71
|
+
removeWebExtension(id: string, cwd?: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Turns a package on or off, what pi loads of it and its web extension; sessions pick it up on reload.
|
|
74
|
+
* A built-in one by its name; another by its id of listPackages, as `ta config` turns each of its
|
|
75
|
+
* resources on or off, in the settings of its scope.
|
|
76
|
+
*/
|
|
77
|
+
setPackageEnabled(nameOrId: string, enabled: boolean, cwd?: string): Promise<void>;
|
|
78
|
+
/** Every package pi loads in `cwd` (default: the server's directory), with a web extension or without. */
|
|
79
|
+
listPackages(cwd?: string): Promise<TaPackageInfo[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Installs a package and adds it to pi's `packages` setting, as `ta install` does: `npm:<name>`,
|
|
82
|
+
* `git:<repository>`, a URL of a repository, or a path. `project` as `ta install -l`, in a trusted
|
|
83
|
+
* project. Sessions pick it up on reload.
|
|
84
|
+
*/
|
|
85
|
+
installPackage(source: string, scope: TaSettingsScope, cwd?: string): Promise<void>;
|
|
86
|
+
/** Removes a package of listPackages: as `ta remove` for a package of the setting, deletes the directory for a directory. */
|
|
87
|
+
removePackage(id: string, cwd?: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Calls a method of what the module of `pi.host` of a package that comes with Ta returned
|
|
90
|
+
* (TaPackageService), with JSON values, and answers what it returns: how its web extension reaches it.
|
|
91
|
+
*/
|
|
92
|
+
callPackageHost(name: string, method: string, params?: unknown[]): Promise<unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* A value a package keeps on the server (WebExtensionAPI.storage); undefined when there is none. With
|
|
95
|
+
* `cwd`, a value of that directory, in its execution environment: each directory has its own keys.
|
|
96
|
+
*/
|
|
97
|
+
getExtensionData(name: string, key: string, cwd?: string): Promise<unknown>;
|
|
98
|
+
setExtensionData(name: string, key: string, value: unknown, cwd?: string): Promise<void>;
|
|
99
|
+
}
|
package/src/common/pi-types.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// import types with `resolution-mode`. Only types: this package loads neither pi nor Node.js modules.
|
|
3
3
|
export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' }}).ImageContent;
|
|
4
4
|
export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).JsonAgentSessionEvent;
|
|
5
|
+
export type RpcCommand = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcCommand;
|
|
5
6
|
export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIRequest;
|
|
6
7
|
export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIResponse;
|
|
7
8
|
export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcResponse;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const TaRelayServer = Symbol('TaRelayServer');
|
|
2
|
+
export const TA_RELAY_SERVICE = 'TaRelayServer';
|
|
3
|
+
|
|
4
|
+
/** A device paired with this ta serve, which reaches it through a relay (@celljs/ta-relay). */
|
|
5
|
+
export interface TaRelayDevice {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TaRelayInfo {
|
|
12
|
+
/** The relay of the devices; none before the first is paired. */
|
|
13
|
+
relay?: string;
|
|
14
|
+
/** The relay a new pairing uses when the user names none. */
|
|
15
|
+
defaultRelay: string;
|
|
16
|
+
/** ta serve is connected to the relay now: the devices can reach it. */
|
|
17
|
+
online: boolean;
|
|
18
|
+
devices: TaRelayDevice[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Pairing devices from a client, as `ta pair` does in a terminal. */
|
|
22
|
+
export interface TaRelayServer {
|
|
23
|
+
getRelay(): Promise<TaRelayInfo>;
|
|
24
|
+
/** A new device; `link` holds its key, for the device only: show it once (a QR code), do not keep it. */
|
|
25
|
+
pair(relay: string, name: string): Promise<{ link: string; device: TaRelayDevice }>;
|
|
26
|
+
/** The device can no longer reach this ta serve, at once. */
|
|
27
|
+
unpair(deviceId: string): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { TaServer } from './ta-protocol';
|
|
2
|
+
|
|
3
|
+
export const TaSettingsServer = Symbol('TaSettingsServer');
|
|
4
|
+
export const TA_SETTINGS_SERVICE = 'TaSettingsServer';
|
|
5
|
+
|
|
6
|
+
/** Where a setting of ta is kept: pi's `settings.json` of the user (the agent directory), or of a project (`.ta/` of its directory), which wins. */
|
|
7
|
+
export type TaSettingsScope = 'user' | 'project';
|
|
8
|
+
|
|
9
|
+
/** A setting of ta that clients show and change; the key is its path in pi's `settings.json`. */
|
|
10
|
+
export interface TaSettingSpec {
|
|
11
|
+
key: string;
|
|
12
|
+
/** `model`: `<provider>/<model id>`, kept by pi as `defaultProvider` and `defaultModel`. */
|
|
13
|
+
type: 'boolean' | 'number' | 'string' | 'enum' | 'model';
|
|
14
|
+
values?: readonly string[];
|
|
15
|
+
/** What pi does when no file sets it; none when pi decides by itself (the model, a thinking level). */
|
|
16
|
+
default?: boolean | number | string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The settings of ta that clients change, as pi names them; other keys of the files are left as they are. */
|
|
20
|
+
export const TA_SETTINGS: readonly TaSettingSpec[] = [
|
|
21
|
+
{ key: 'model', type: 'model' },
|
|
22
|
+
{ key: 'defaultThinkingLevel', type: 'enum', values: ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] },
|
|
23
|
+
{ key: 'transport', type: 'enum', values: ['auto', 'sse', 'websocket', 'websocket-cached'], default: 'auto' },
|
|
24
|
+
{ key: 'steeringMode', type: 'enum', values: ['one-at-a-time', 'all'], default: 'one-at-a-time' },
|
|
25
|
+
{ key: 'followUpMode', type: 'enum', values: ['one-at-a-time', 'all'], default: 'one-at-a-time' },
|
|
26
|
+
{ key: 'compaction.enabled', type: 'boolean', default: true },
|
|
27
|
+
{ key: 'compaction.reserveTokens', type: 'number', default: 16384 },
|
|
28
|
+
{ key: 'compaction.keepRecentTokens', type: 'number', default: 20000 },
|
|
29
|
+
{ key: 'retry.enabled', type: 'boolean', default: true },
|
|
30
|
+
{ key: 'retry.maxRetries', type: 'number', default: 3 },
|
|
31
|
+
{ key: 'codemode.mode', type: 'enum', values: ['only', 'on'], default: 'only' },
|
|
32
|
+
{ key: 'enableSkillCommands', type: 'boolean', default: true },
|
|
33
|
+
{ key: 'images.autoResize', type: 'boolean', default: true },
|
|
34
|
+
{ key: 'images.blockImages', type: 'boolean', default: false },
|
|
35
|
+
{ key: 'shellPath', type: 'string' },
|
|
36
|
+
{ key: 'shellCommandPrefix', type: 'string' },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/** The settings of ta (TA_SETTINGS) in the files of the user and of a project: only the keys each file sets. */
|
|
40
|
+
export interface TaSettingsSnapshot {
|
|
41
|
+
user: Record<string, unknown>;
|
|
42
|
+
project: Record<string, unknown>;
|
|
43
|
+
/** The directory of the project. */
|
|
44
|
+
cwd: string;
|
|
45
|
+
userFile: string;
|
|
46
|
+
projectFile: string;
|
|
47
|
+
/**
|
|
48
|
+
* pi reads the settings of a project only when the user trusts it. Changing them from a client trusts a
|
|
49
|
+
* project that has nothing else to trust yet; one with extensions or skills of its own is trusted in `ta`.
|
|
50
|
+
*/
|
|
51
|
+
projectTrusted: boolean;
|
|
52
|
+
/** `<provider>/<model id>` of the models with credentials, for the model setting. */
|
|
53
|
+
models: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The settings of ta in pi's `settings.json` files, on the same WebSocket as {@link TaServer}. */
|
|
57
|
+
export interface TaSettingsServer {
|
|
58
|
+
/** The settings of ta (TA_SETTINGS) of the user and of the project in `cwd` (default: the server's directory). */
|
|
59
|
+
getSettings(cwd?: string): Promise<TaSettingsSnapshot>;
|
|
60
|
+
/**
|
|
61
|
+
* Sets settings of ta in one file, by key of TA_SETTINGS; `null` removes a key, so that the project
|
|
62
|
+
* follows the user and the user pi's default. Open sessions read them again; the model and the thinking
|
|
63
|
+
* level are for new sessions.
|
|
64
|
+
*/
|
|
65
|
+
updateSettings(scope: TaSettingsScope, changes: Record<string, unknown>, cwd?: string): Promise<TaSettingsSnapshot>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TaPackageServer } from './package-protocol';
|
|
2
|
+
import type { TaServer } from './ta-protocol';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
|
|
6
|
+
* process, without a token. A subset of TaServer and TaPackageServer: it can open and drive sessions, not
|
|
7
|
+
* close or remove anything.
|
|
8
|
+
*/
|
|
9
|
+
export interface TaExtensionHost
|
|
10
|
+
extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'setSessionName' | 'prompt' | 'followUp' | 'getState' | 'getLastAssistantText'>,
|
|
11
|
+
Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
|
|
12
|
+
/** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
|
|
13
|
+
readonly agentDir: string;
|
|
14
|
+
/** 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. */
|
|
15
|
+
onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What the module of `pi.host` returns: anything the package's pi extensions should reach. Its web
|
|
20
|
+
* extension calls its methods with TaPackageServer.callPackageHost, with JSON values.
|
|
21
|
+
*/
|
|
22
|
+
export interface TaPackageService {
|
|
23
|
+
/** `ta serve` stops, or the package is turned off. */
|
|
24
|
+
dispose?(): void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The default export of a module that a package names in `pi.host` of its package.json. `ta serve` runs it
|
|
29
|
+
* once when it starts (or when the package is turned on), for built-in packages; `ta` without `serve`
|
|
30
|
+
* does not run it.
|
|
31
|
+
*/
|
|
32
|
+
export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService | undefined | Promise<TaPackageService | undefined>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The event of pi's `pi.events` by which a pi extension asks for the host of its package:
|
|
36
|
+
* `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
|
|
37
|
+
* the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
|
|
38
|
+
* and the extension should say its tools need `ta serve`.
|
|
39
|
+
*/
|
|
40
|
+
export const TA_HOST_EVENT = 'ta:host';
|
|
41
|
+
|
|
42
|
+
export interface TaHostRequest {
|
|
43
|
+
/** The `name` of the package.json. */
|
|
44
|
+
name: string;
|
|
45
|
+
resolve(answer: TaHostAnswer): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface TaHostAnswer {
|
|
49
|
+
host: TaExtensionHost;
|
|
50
|
+
/** What the module of `pi.host` of the package returned; undefined when it has none or failed. */
|
|
51
|
+
service?: TaPackageService;
|
|
52
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { TA_AUTH_SERVICE, TaAuthServer } from './auth-protocol';
|
|
3
|
+
import { TA_PACKAGE_SERVICE, TaPackageServer } from './package-protocol';
|
|
4
|
+
import { TA_RELAY_SERVICE, TaRelayServer } from './relay-protocol';
|
|
5
|
+
import { TA_SETTINGS_SERVICE, TaSettingsServer } from './settings-protocol';
|
|
6
|
+
import { type PiCommandMethod, TA_CLIENT_SERVICE, TA_SERVER_SERVICE, TaClient, TaErrorCode, TaMessageContext, TaServer } from './ta-protocol';
|
|
7
|
+
import { TA_TERMINAL_SERVICE, TA_WORKSPACE_SERVICE, TaTerminalServer, TaWorkspaceServer } from './workspace-protocol';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fails to compile when pi's RPC mode has a command that TaServer has no method for: after an upgrade of
|
|
11
|
+
* pi, add the method, doing what pi's `rpc-mode` does for it.
|
|
12
|
+
*/
|
|
13
|
+
type MissingPiCommands = Exclude<PiCommandMethod, keyof TaServer>;
|
|
14
|
+
const everyPiCommand: [MissingPiCommands] extends [never] ? true : MissingPiCommands = true;
|
|
3
15
|
|
|
4
16
|
describe('ta protocol', () => {
|
|
5
17
|
it('names each failure with a distinct CELL_TA_ code', () => {
|
|
@@ -13,5 +25,22 @@ describe('ta protocol', () => {
|
|
|
13
25
|
it('routes JSON-RPC methods by the names of the service symbols', () => {
|
|
14
26
|
expect(TaServer.description).toBe(TA_SERVER_SERVICE);
|
|
15
27
|
expect(TaClient.description).toBe(TA_CLIENT_SERVICE);
|
|
28
|
+
expect(TaWorkspaceServer.description).toBe(TA_WORKSPACE_SERVICE);
|
|
29
|
+
expect(TaTerminalServer.description).toBe(TA_TERMINAL_SERVICE);
|
|
30
|
+
expect(TaSettingsServer.description).toBe(TA_SETTINGS_SERVICE);
|
|
31
|
+
expect(TaPackageServer.description).toBe(TA_PACKAGE_SERVICE);
|
|
32
|
+
expect(TaAuthServer.description).toBe(TA_AUTH_SERVICE);
|
|
33
|
+
expect(TaRelayServer.description).toBe(TA_RELAY_SERVICE);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('has a method of TaServer for each command of pi', () => {
|
|
37
|
+
expect(everyPiCommand).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('leaves the context of a message out of what is shown', () => {
|
|
41
|
+
const message = TaMessageContext.wrap('[#test]\nMembers:\n- @a', '@a hi\nthere');
|
|
42
|
+
expect(message).toStartWith('<context>\n');
|
|
43
|
+
expect(TaMessageContext.strip(message)).toBe('@a hi\nthere');
|
|
44
|
+
expect(TaMessageContext.strip('no <context> here')).toBe('no <context> here');
|
|
16
45
|
});
|
|
17
46
|
});
|