@celljs/ta-protocol 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/esm/common/access-protocol.d.ts +73 -0
  4. package/esm/common/access-protocol.js +9 -0
  5. package/esm/common/gateway-protocol.d.ts +81 -0
  6. package/esm/common/gateway-protocol.js +3 -0
  7. package/esm/common/index.d.ts +2 -0
  8. package/esm/common/index.js +2 -0
  9. package/esm/common/location.d.ts +5 -0
  10. package/esm/common/location.js +12 -0
  11. package/esm/common/package-protocol.d.ts +60 -1
  12. package/esm/common/package-protocol.js +12 -0
  13. package/esm/common/relay-protocol.d.ts +17 -0
  14. package/esm/common/settings-protocol.d.ts +9 -0
  15. package/esm/common/ta-extension-host.d.ts +40 -3
  16. package/esm/common/ta-extension-host.js +13 -0
  17. package/esm/common/ta-protocol.d.ts +115 -4
  18. package/esm/common/ta-protocol.js +33 -0
  19. package/esm/common/workspace-protocol.d.ts +28 -1
  20. package/esm/common/workspace-protocol.js +21 -0
  21. package/lib/common/access-protocol.d.ts +74 -0
  22. package/lib/common/access-protocol.js +12 -0
  23. package/lib/common/gateway-protocol.d.ts +82 -0
  24. package/lib/common/gateway-protocol.js +6 -0
  25. package/lib/common/index.d.ts +2 -0
  26. package/lib/common/index.js +2 -0
  27. package/lib/common/location.d.ts +5 -0
  28. package/lib/common/location.js +12 -0
  29. package/lib/common/package-protocol.d.ts +60 -1
  30. package/lib/common/package-protocol.js +13 -1
  31. package/lib/common/relay-protocol.d.ts +17 -0
  32. package/lib/common/settings-protocol.d.ts +9 -0
  33. package/lib/common/ta-extension-host.d.ts +40 -3
  34. package/lib/common/ta-extension-host.js +14 -1
  35. package/lib/common/ta-protocol.d.ts +115 -4
  36. package/lib/common/ta-protocol.js +34 -1
  37. package/lib/common/workspace-protocol.d.ts +28 -1
  38. package/lib/common/workspace-protocol.js +22 -1
  39. package/package.json +3 -2
  40. package/esm/common/auth-protocol.js.map +0 -1
  41. package/esm/common/index.js.map +0 -1
  42. package/esm/common/location.js.map +0 -1
  43. package/esm/common/package-protocol.js.map +0 -1
  44. package/esm/common/pi-types.js.map +0 -1
  45. package/esm/common/relay-protocol.js.map +0 -1
  46. package/esm/common/remote-protocol.js.map +0 -1
  47. package/esm/common/settings-protocol.js.map +0 -1
  48. package/esm/common/ta-extension-host.js.map +0 -1
  49. package/esm/common/ta-protocol.js.map +0 -1
  50. package/esm/common/workspace-protocol.js.map +0 -1
  51. package/lib/common/auth-protocol.d.ts.map +0 -1
  52. package/lib/common/auth-protocol.js.map +0 -1
  53. package/lib/common/index.d.ts.map +0 -1
  54. package/lib/common/index.js.map +0 -1
  55. package/lib/common/location.d.ts.map +0 -1
  56. package/lib/common/location.js.map +0 -1
  57. package/lib/common/location.spec.d.ts +0 -2
  58. package/lib/common/location.spec.d.ts.map +0 -1
  59. package/lib/common/location.spec.js +0 -58
  60. package/lib/common/location.spec.js.map +0 -1
  61. package/lib/common/package-protocol.d.ts.map +0 -1
  62. package/lib/common/package-protocol.js.map +0 -1
  63. package/lib/common/pi-types.d.ts.map +0 -1
  64. package/lib/common/pi-types.js.map +0 -1
  65. package/lib/common/relay-protocol.d.ts.map +0 -1
  66. package/lib/common/relay-protocol.js.map +0 -1
  67. package/lib/common/remote-protocol.d.ts.map +0 -1
  68. package/lib/common/remote-protocol.js.map +0 -1
  69. package/lib/common/settings-protocol.d.ts.map +0 -1
  70. package/lib/common/settings-protocol.js.map +0 -1
  71. package/lib/common/ta-extension-host.d.ts.map +0 -1
  72. package/lib/common/ta-extension-host.js.map +0 -1
  73. package/lib/common/ta-protocol.d.ts.map +0 -1
  74. package/lib/common/ta-protocol.js.map +0 -1
  75. package/lib/common/ta-protocol.spec.d.ts +0 -2
  76. package/lib/common/ta-protocol.spec.d.ts.map +0 -1
  77. package/lib/common/ta-protocol.spec.js +0 -41
  78. package/lib/common/ta-protocol.spec.js.map +0 -1
  79. package/lib/common/workspace-protocol.d.ts.map +0 -1
  80. package/lib/common/workspace-protocol.js.map +0 -1
  81. package/src/common/auth-protocol.ts +0 -56
  82. package/src/common/index.ts +0 -10
  83. package/src/common/location.spec.ts +0 -62
  84. package/src/common/location.ts +0 -177
  85. package/src/common/package-protocol.ts +0 -99
  86. package/src/common/pi-types.ts +0 -11
  87. package/src/common/relay-protocol.ts +0 -28
  88. package/src/common/remote-protocol.ts +0 -76
  89. package/src/common/settings-protocol.ts +0 -66
  90. package/src/common/ta-extension-host.ts +0 -54
  91. package/src/common/ta-protocol.spec.ts +0 -48
  92. package/src/common/ta-protocol.ts +0 -347
  93. package/src/common/workspace-protocol.ts +0 -102
@@ -1,99 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
1
- // pi is an ES module package: the CommonJS build of this package can only name its types through
2
- // import types with `resolution-mode`. Only types: this package loads neither pi nor Node.js modules.
3
- export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' }}).ImageContent;
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;
6
- export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIRequest;
7
- export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIResponse;
8
- export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcResponse;
9
- export type RpcSessionState = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcSessionState;
10
- export type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSession;
11
- export type ThinkingLevel = AgentSession['thinkingLevel'];
@@ -1,28 +0,0 @@
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
- }
@@ -1,76 +0,0 @@
1
- export const TaRemoteServer = Symbol('TaRemoteServer');
2
- export const TA_REMOTE_SERVICE = 'TaRemoteServer';
3
-
4
- /** A machine ta serve can reach with ssh. */
5
- export interface TaRemoteHost {
6
- /** What follows `ssh://` in a location (TaLocation). */
7
- host: string;
8
- /** A Host of ~/.ssh/config, or one opened before. */
9
- source: 'config' | 'recent';
10
- /** ta serve is connected to it now. */
11
- connected: boolean;
12
- }
13
-
14
- /**
15
- * What ssh asks while it connects (a password, a passphrase, whether to trust a new host key), for
16
- * whoever is there to answer: `confirm` takes `yes` or `no`, `secret` is not shown as typed.
17
- */
18
- export interface TaRemotePrompt {
19
- promptId: string;
20
- host: string;
21
- kind: 'secret' | 'confirm' | 'text';
22
- message: string;
23
- }
24
-
25
- /** What happens with the remote machines, to the connections that called TaRemoteServer.watch. */
26
- export type TaRemoteEvent =
27
- | { type: 'prompt'; prompt: TaRemotePrompt }
28
- /** Answered, by this client or another, or ssh no longer waits. */
29
- | { type: 'prompt_closed'; promptId: string }
30
- /** A step of connecting that takes a while: the first connection installs things there. */
31
- | { type: 'progress'; host: string; step: TaRemoteStep; detail?: string }
32
- /** Connected to the host, or no longer. */
33
- | { type: 'connection'; host: string; connected: boolean; error?: string };
34
-
35
- /**
36
- * The steps of connecting to a host: ssh signs in, then Ta looks at what the host has, installs Node.js
37
- * there when it has none (`detail`: the version), copies its small server, and starts it.
38
- */
39
- export type TaRemoteStep = 'connecting' | 'checking' | 'installing-node' | 'copying-server' | 'starting';
40
-
41
- /** A port of another machine, reachable on the machine of ta serve. */
42
- export interface TaForwardedPort {
43
- host: string;
44
- /** On the other machine. */
45
- remotePort: number;
46
- /** On the machine of ta serve, at 127.0.0.1. */
47
- localPort: number;
48
- }
49
-
50
- /**
51
- * Other machines that conversations work on, as VS Code's Remote SSH: the agent runs with ta serve, and
52
- * its commands and files are there, through the `ssh` of the machine of ta serve with its configuration.
53
- */
54
- export interface TaRemoteServer {
55
- /** The Hosts of ~/.ssh/config without wildcards, and those added or opened before, the latest first. */
56
- listHosts(): Promise<TaRemoteHost[]>;
57
- /** Keeps a host in the list (`recent`), without connecting to it. */
58
- addHost(host: string): Promise<void>;
59
- /** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
60
- removeHost(host: string): Promise<void>;
61
- /** The location with the path of the home directory when it has none; connects to the host. */
62
- resolveLocation(location: string): Promise<string>;
63
- /**
64
- * A port of the machine of `cwd` on the machine of ta serve, for a page served there: the same port
65
- * when `cwd` is a directory of this machine. It stays open while ta serve runs.
66
- */
67
- forwardPort(port: number, cwd?: string): Promise<TaForwardedPort>;
68
- listForwardedPorts(): Promise<TaForwardedPort[]>;
69
- closeForwardedPort(host: string, remotePort: number): Promise<void>;
70
- /** This connection hears TaClient.onRemoteEvent from now; resolves to the prompts that wait. */
71
- watch(): Promise<TaRemotePrompt[]>;
72
- /** The answer to a prompt; `null` cancels it. False when it no longer waits. */
73
- answer(promptId: string, value: string | null): Promise<boolean>;
74
- /** Ends the connection to the host, its processes and forwarded ports there. */
75
- disconnect(host: string): Promise<void>;
76
- }
@@ -1,66 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
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
- /** 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. */
15
- sessionCwd(sessionFile: string): Promise<string | undefined>;
16
- /** 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. */
17
- onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
18
- }
19
-
20
- /**
21
- * What the module of `pi.host` returns: anything the package's pi extensions should reach. Its web
22
- * extension calls its methods with TaPackageServer.callPackageHost, with JSON values.
23
- */
24
- export interface TaPackageService {
25
- /** `ta serve` stops, or the package is turned off. */
26
- dispose?(): void | Promise<void>;
27
- }
28
-
29
- /**
30
- * The default export of a module that a package names in `pi.host` of its package.json. `ta serve` runs it
31
- * once when it starts (or when the package is turned on), for built-in packages; `ta` without `serve`
32
- * does not run it.
33
- */
34
- export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService | undefined | Promise<TaPackageService | undefined>;
35
-
36
- /**
37
- * The event of pi's `pi.events` by which a pi extension asks for the host of its package:
38
- * `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
39
- * the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
40
- * and the extension should say its tools need `ta serve`.
41
- */
42
- export const TA_HOST_EVENT = 'ta:host';
43
-
44
- export interface TaHostRequest {
45
- /** The `name` of the package.json. */
46
- name: string;
47
- resolve(answer: TaHostAnswer): void;
48
- }
49
-
50
- export interface TaHostAnswer {
51
- host: TaExtensionHost;
52
- /** What the module of `pi.host` of the package returned; undefined when it has none or failed. */
53
- service?: TaPackageService;
54
- }
@@ -1,48 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
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_REMOTE_SERVICE, TaRemoteServer } from './remote-protocol';
6
- import { TA_SETTINGS_SERVICE, TaSettingsServer } from './settings-protocol';
7
- import { type PiCommandMethod, TA_CLIENT_SERVICE, TA_SERVER_SERVICE, TaClient, TaErrorCode, TaMessageContext, TaServer } from './ta-protocol';
8
- import { TA_TERMINAL_SERVICE, TA_WORKSPACE_SERVICE, TaTerminalServer, TaWorkspaceServer } from './workspace-protocol';
9
-
10
- /**
11
- * Fails to compile when pi's RPC mode has a command that TaServer has no method for: after an upgrade of
12
- * pi, add the method, doing what pi's `rpc-mode` does for it.
13
- */
14
- type MissingPiCommands = Exclude<PiCommandMethod, keyof TaServer>;
15
- const everyPiCommand: [MissingPiCommands] extends [never] ? true : MissingPiCommands = true;
16
-
17
- describe('ta protocol', () => {
18
- it('names each failure with a distinct CELL_TA_ code', () => {
19
- const codes = Object.values(TaErrorCode);
20
- expect(new Set(codes).size).toBe(codes.length);
21
- for (const code of codes) {
22
- expect(code).toStartWith('CELL_TA_');
23
- }
24
- });
25
-
26
- it('routes JSON-RPC methods by the names of the service symbols', () => {
27
- expect(TaServer.description).toBe(TA_SERVER_SERVICE);
28
- expect(TaClient.description).toBe(TA_CLIENT_SERVICE);
29
- expect(TaWorkspaceServer.description).toBe(TA_WORKSPACE_SERVICE);
30
- expect(TaTerminalServer.description).toBe(TA_TERMINAL_SERVICE);
31
- expect(TaSettingsServer.description).toBe(TA_SETTINGS_SERVICE);
32
- expect(TaPackageServer.description).toBe(TA_PACKAGE_SERVICE);
33
- expect(TaAuthServer.description).toBe(TA_AUTH_SERVICE);
34
- expect(TaRelayServer.description).toBe(TA_RELAY_SERVICE);
35
- expect(TaRemoteServer.description).toBe(TA_REMOTE_SERVICE);
36
- });
37
-
38
- it('has a method of TaServer for each command of pi', () => {
39
- expect(everyPiCommand).toBe(true);
40
- });
41
-
42
- it('leaves the context of a message out of what is shown', () => {
43
- const message = TaMessageContext.wrap('[#test]\nMembers:\n- @a', '@a hi\nthere');
44
- expect(message).toStartWith('<context>\n');
45
- expect(TaMessageContext.strip(message)).toBe('@a hi\nthere');
46
- expect(TaMessageContext.strip('no <context> here')).toBe('no <context> here');
47
- });
48
- });