@celljs/ta-protocol 4.8.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 +2 -0
  15. package/esm/common/ta-extension-host.d.ts +9 -0
  16. package/esm/common/ta-extension-host.js +6 -0
  17. package/esm/common/ta-protocol.d.ts +110 -4
  18. package/esm/common/ta-protocol.js +33 -0
  19. package/esm/common/workspace-protocol.d.ts +12 -1
  20. package/esm/common/workspace-protocol.js +16 -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 +2 -0
  33. package/lib/common/ta-extension-host.d.ts +9 -0
  34. package/lib/common/ta-extension-host.js +7 -1
  35. package/lib/common/ta-protocol.d.ts +110 -4
  36. package/lib/common/ta-protocol.js +34 -1
  37. package/lib/common/workspace-protocol.d.ts +12 -1
  38. package/lib/common/workspace-protocol.js +17 -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 -73
  90. package/src/common/ta-extension-host.ts +0 -97
  91. package/src/common/ta-protocol.spec.ts +0 -48
  92. package/src/common/ta-protocol.ts +0 -352
  93. package/src/common/workspace-protocol.ts +0 -120
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const auth_protocol_1 = require("./auth-protocol");
5
- const package_protocol_1 = require("./package-protocol");
6
- const relay_protocol_1 = require("./relay-protocol");
7
- const remote_protocol_1 = require("./remote-protocol");
8
- const settings_protocol_1 = require("./settings-protocol");
9
- const ta_protocol_1 = require("./ta-protocol");
10
- const workspace_protocol_1 = require("./workspace-protocol");
11
- const everyPiCommand = true;
12
- (0, bun_test_1.describe)('ta protocol', () => {
13
- (0, bun_test_1.it)('names each failure with a distinct CELL_TA_ code', () => {
14
- const codes = Object.values(ta_protocol_1.TaErrorCode);
15
- (0, bun_test_1.expect)(new Set(codes).size).toBe(codes.length);
16
- for (const code of codes) {
17
- (0, bun_test_1.expect)(code).toStartWith('CELL_TA_');
18
- }
19
- });
20
- (0, bun_test_1.it)('routes JSON-RPC methods by the names of the service symbols', () => {
21
- (0, bun_test_1.expect)(ta_protocol_1.TaServer.description).toBe(ta_protocol_1.TA_SERVER_SERVICE);
22
- (0, bun_test_1.expect)(ta_protocol_1.TaClient.description).toBe(ta_protocol_1.TA_CLIENT_SERVICE);
23
- (0, bun_test_1.expect)(workspace_protocol_1.TaWorkspaceServer.description).toBe(workspace_protocol_1.TA_WORKSPACE_SERVICE);
24
- (0, bun_test_1.expect)(workspace_protocol_1.TaTerminalServer.description).toBe(workspace_protocol_1.TA_TERMINAL_SERVICE);
25
- (0, bun_test_1.expect)(settings_protocol_1.TaSettingsServer.description).toBe(settings_protocol_1.TA_SETTINGS_SERVICE);
26
- (0, bun_test_1.expect)(package_protocol_1.TaPackageServer.description).toBe(package_protocol_1.TA_PACKAGE_SERVICE);
27
- (0, bun_test_1.expect)(auth_protocol_1.TaAuthServer.description).toBe(auth_protocol_1.TA_AUTH_SERVICE);
28
- (0, bun_test_1.expect)(relay_protocol_1.TaRelayServer.description).toBe(relay_protocol_1.TA_RELAY_SERVICE);
29
- (0, bun_test_1.expect)(remote_protocol_1.TaRemoteServer.description).toBe(remote_protocol_1.TA_REMOTE_SERVICE);
30
- });
31
- (0, bun_test_1.it)('has a method of TaServer for each command of pi', () => {
32
- (0, bun_test_1.expect)(everyPiCommand).toBe(true);
33
- });
34
- (0, bun_test_1.it)('leaves the context of a message out of what is shown', () => {
35
- const message = ta_protocol_1.TaMessageContext.wrap('[#test]\nMembers:\n- @a', '@a hi\nthere');
36
- (0, bun_test_1.expect)(message).toStartWith('<context>\n');
37
- (0, bun_test_1.expect)(ta_protocol_1.TaMessageContext.strip(message)).toBe('@a hi\nthere');
38
- (0, bun_test_1.expect)(ta_protocol_1.TaMessageContext.strip('no <context> here')).toBe('no <context> here');
39
- });
40
- });
41
- //# sourceMappingURL=ta-protocol.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ta-protocol.spec.js","sourceRoot":"","sources":["../../src/common/ta-protocol.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,mDAAgE;AAChE,yDAAyE;AACzE,qDAAmE;AACnE,uDAAsE;AACtE,2DAA4E;AAC5E,+CAA8I;AAC9I,6DAAsH;AAOtH,MAAM,cAAc,GAAmE,IAAI,CAAC;AAE5F,IAAA,mBAAQ,EAAC,aAAa,EAAE,GAAG,EAAE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U,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,4DAA4D;IAC5D,aAAa,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CAC9C"}
@@ -1 +0,0 @@
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;AAgCtD;;;GAGG;AACU,QAAA,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC"}
@@ -1,56 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
1
- export * from './auth-protocol';
2
- export * from './location';
3
- export * from './package-protocol';
4
- export * from './pi-types';
5
- export * from './relay-protocol';
6
- export * from './remote-protocol';
7
- export * from './settings-protocol';
8
- export * from './ta-extension-host';
9
- export * from './ta-protocol';
10
- export * from './workspace-protocol';
@@ -1,62 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { TaLocation } from './location';
3
-
4
- describe('TaLocation', () => {
5
- it('reads a path of this machine as no remote location', () => {
6
- expect(TaLocation.parse('/home/me/app')).toBeUndefined();
7
- expect(TaLocation.path('/home/me/app')).toBe('/home/me/app');
8
- expect(TaLocation.host('C:\\work')).toBeUndefined();
9
- });
10
-
11
- it('reads the host and the path of an ssh location', () => {
12
- expect(TaLocation.parse('ssh://dev/home/me/app')).toEqual({ host: 'dev', path: '/home/me/app' });
13
- expect(TaLocation.parse('ssh://me@10.0.0.2:2222//srv//app/')).toEqual({ host: 'me@10.0.0.2:2222', path: '/srv/app' });
14
- expect(TaLocation.parse('ssh://dev')).toEqual({ host: 'dev', path: '' });
15
- expect(TaLocation.parse('ssh://dev/')).toEqual({ host: 'dev', path: '/' });
16
- });
17
-
18
- it('refuses a host that ssh would read as an option, or none', () => {
19
- expect(() => TaLocation.parse('ssh://-oProxyCommand=x/tmp')).toThrow();
20
- expect(() => TaLocation.parse('ssh:///tmp')).toThrow();
21
- expect(() => TaLocation.parse('ssh://a b/tmp')).toThrow();
22
- expect(TaLocation.isHost('dev.example.com')).toBe(true);
23
- expect(TaLocation.isHost('-p')).toBe(false);
24
- });
25
-
26
- it('walks up and down remote directories as it does local ones', () => {
27
- expect(TaLocation.parent('ssh://dev/home/me')).toBe('ssh://dev/home');
28
- expect(TaLocation.parent('ssh://dev/home')).toBe('ssh://dev/');
29
- expect(TaLocation.parent('ssh://dev/')).toBeUndefined();
30
- expect(TaLocation.parent('ssh://dev')).toBeUndefined();
31
- expect(TaLocation.child('ssh://dev/', 'srv')).toBe('ssh://dev/srv');
32
- expect(TaLocation.child('ssh://dev/srv', 'app')).toBe('ssh://dev/srv/app');
33
- expect(TaLocation.parent('/home/me')).toBe('/home');
34
- expect(TaLocation.parent('/')).toBeUndefined();
35
- expect(TaLocation.parent('C:\\work')).toBe('C:\\');
36
- expect(TaLocation.child('C:\\work', 'app')).toBe('C:\\work\\app');
37
- });
38
-
39
- it('names a directory by its last name, the home of a host by the host', () => {
40
- expect(TaLocation.basename('ssh://dev/home/me/app/')).toBe('app');
41
- expect(TaLocation.basename('ssh://dev')).toBe('dev');
42
- expect(TaLocation.basename('/work/app')).toBe('app');
43
- expect(TaLocation.ssh('dev', 'srv/app')).toBe('ssh://dev/srv/app');
44
- });
45
-
46
- it('reads a host as the user writes it, the command line of ssh too', () => {
47
- expect(TaLocation.readHost('dev')).toEqual({ host: 'dev' });
48
- expect(TaLocation.readHost(' ssh://me@dev:2222/srv ')).toEqual({ host: 'me@dev:2222' });
49
- expect(TaLocation.readHost('ssh root@suboyang.devcloud.woa.com -p 36000')).toEqual({ host: 'root@suboyang.devcloud.woa.com:36000' });
50
- expect(TaLocation.readHost('ssh -p36000 -A -l root box')).toEqual({ host: 'root@box:36000' });
51
- expect(TaLocation.readHost('ssh -o Port=2200 -o User=me box')).toEqual({ host: 'me@box:2200' });
52
- expect(TaLocation.readHost('me@box -p 22')).toEqual({ host: 'me@box' });
53
- });
54
-
55
- it('says which options of ssh belong in ~/.ssh/config, and refuses what is no host', () => {
56
- expect(TaLocation.readHost('ssh -i ~/.ssh/key -J jump me@box')).toEqual({ error: 'options', options: ['-i ~/.ssh/key', '-J jump'] });
57
- expect(TaLocation.readHost('ssh -o ProxyCommand=nc box')).toEqual({ error: 'options', options: ['-o ProxyCommand=nc'] });
58
- expect(TaLocation.readHost('ssh')).toEqual({ error: 'empty' });
59
- expect(TaLocation.readHost('ssh box ls -la')).toEqual({ error: 'invalid' });
60
- expect(TaLocation.readHost('box -p abc')).toEqual({ error: 'invalid' });
61
- });
62
- });
@@ -1,177 +0,0 @@
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 namespace TaLocation {
8
- export const SSH = 'ssh://';
9
-
10
- /** A directory of another machine. */
11
- export interface Remote {
12
- host: string;
13
- /** Absolute, with `/`; empty for the home directory. */
14
- path: string;
15
- }
16
-
17
- /** Letters, digits and `_ . @ : % + - [ ]`, not first a `-`: ssh must not read a host as an option. */
18
- const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
19
-
20
- export function isRemote(location: string): boolean {
21
- return location.startsWith(SSH);
22
- }
23
-
24
- /** undefined for a path of the machine of ta serve; throws for an `ssh://` location that is not one. */
25
- export function parse(location: string): Remote | undefined {
26
- if (!isRemote(location)) {
27
- return undefined;
28
- }
29
- const rest = location.slice(SSH.length);
30
- const slash = rest.indexOf('/');
31
- const host = slash < 0 ? rest : rest.slice(0, slash);
32
- const path = slash < 0 ? '' : normalize(rest.slice(slash));
33
- if (!isHost(host)) {
34
- throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
35
- }
36
- return { host, path };
37
- }
38
-
39
- export function isHost(host: string): boolean {
40
- return HOST.test(host);
41
- }
42
-
43
- /** What {@link readHost} makes of what the user typed. */
44
- export type HostInput = { host: string } | { error: 'empty' | 'invalid' } | { error: 'options'; options: string[] };
45
-
46
- /** Options of ssh without a value, which change nothing for Ta. */
47
- const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
48
-
49
- /**
50
- * A host as the user may write it: `dev`, `me@dev`, `me@dev:2222`, `ssh://me@dev:2222/path`, or the
51
- * command line they use (`ssh -p 2222 me@dev`, `ssh me@dev -p 2222 -l root`). Options that a host
52
- * cannot hold (`-i`, `-J`, `-o ProxyCommand=…`) belong in ~/.ssh/config: they come back as `options`.
53
- */
54
- export function readHost(input: string): HostInput {
55
- const words = input.trim().split(/\s+/).filter(Boolean);
56
- if (words[0] === 'ssh') {
57
- words.shift();
58
- }
59
- let destination: string | undefined;
60
- let port: string | undefined;
61
- let user: string | undefined;
62
- const options: string[] = [];
63
- for (let i = 0; i < words.length; i++) {
64
- const word = words[i];
65
- const glued = /^-([pl])(.+)$/.exec(word);
66
- if (word === '-p' || word === '-l' || glued) {
67
- const value = glued ? glued[2] : words[++i];
68
- if (value === undefined) {
69
- return { error: 'invalid' };
70
- }
71
- if ((glued ? glued[1] : word[1]) === 'p') {
72
- port = value;
73
- } else {
74
- user = value;
75
- }
76
- } else if (word === '-o' || word.startsWith('-o')) {
77
- const value = word === '-o' ? words[++i] : word.slice(2);
78
- const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value ?? '');
79
- if (!option) {
80
- options.push(`-o ${value ?? ''}`.trim());
81
- } else if (option[1].toLowerCase() === 'port') {
82
- port = option[2];
83
- } else {
84
- user = option[2];
85
- }
86
- } else if (FLAGS.test(word)) {
87
- // No value, nothing for Ta.
88
- } else if (word.startsWith('-')) {
89
- options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
90
- } else if (destination === undefined) {
91
- destination = word;
92
- } else {
93
- // A command to run there: not a host.
94
- return { error: 'invalid' };
95
- }
96
- }
97
- if (options.length > 0) {
98
- return { error: 'options', options };
99
- }
100
- if (!destination) {
101
- return { error: 'empty' };
102
- }
103
- let host = destination.replace(/^ssh:\/\//, '').replace(/\/.*$/, '');
104
- if (user && !host.includes('@')) {
105
- host = `${user}@${host}`;
106
- }
107
- if (port) {
108
- if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host)) {
109
- return { error: 'invalid' };
110
- }
111
- host = port === '22' ? host : `${host}:${port}`;
112
- }
113
- return isHost(host) ? { host } : { error: 'invalid' };
114
- }
115
-
116
- /** `ssh://<host><path>`; `path` absolute, or empty for the home directory. */
117
- export function ssh(host: string, path = ''): string {
118
- return `${SSH}${host}${path ? normalize(path) : ''}`;
119
- }
120
-
121
- /** The host of a remote location; undefined for this machine. */
122
- export function host(location: string): string | undefined {
123
- return isRemote(location) ? parse(location)?.host : undefined;
124
- }
125
-
126
- /** The path inside its machine. */
127
- export function path(location: string): string {
128
- return parse(location)?.path ?? location;
129
- }
130
-
131
- /** The directory above; undefined at a root (`/`, `C:\\`, the root of a host). */
132
- export function parent(location: string): string | undefined {
133
- const remote = parse(location);
134
- if (remote) {
135
- const above = remote.path ? parentPath(remote.path) : undefined;
136
- return above === undefined ? undefined : ssh(remote.host, above);
137
- }
138
- return parentPath(location);
139
- }
140
-
141
- export function child(location: string, name: string): string {
142
- const remote = parse(location);
143
- if (remote) {
144
- return ssh(remote.host, childPath(remote.path || '/', name));
145
- }
146
- return childPath(location, name);
147
- }
148
-
149
- /** The last name of the path; the host for its home directory. */
150
- export function basename(location: string): string {
151
- const remote = parse(location);
152
- const path = (remote ? remote.path : location).replace(/[\\/]+$/, '');
153
- const name = path.slice(Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')) + 1);
154
- return name || remote?.host || location;
155
- }
156
-
157
- function parentPath(path: string): string | undefined {
158
- const trimmed = path.replace(/[\\/]+$/, '');
159
- const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
160
- if (at < 0) {
161
- return undefined;
162
- }
163
- const head = trimmed.slice(0, at);
164
- return head === '' || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
165
- }
166
-
167
- function childPath(path: string, name: string): string {
168
- const separator = path.includes('/') || !path.includes('\\') ? '/' : '\\';
169
- return path.endsWith(separator) ? path + name : path + separator + name;
170
- }
171
-
172
- /** One `/` between names, none at the end but for the root. */
173
- function normalize(path: string): string {
174
- const squeezed = `/${path}`.replace(/\/+/g, '/');
175
- return squeezed.length > 1 ? squeezed.replace(/\/$/, '') : squeezed;
176
- }
177
- }
@@ -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
- }