@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.
Files changed (73) hide show
  1. package/README.md +6 -5
  2. package/esm/common/auth-protocol.d.ts +89 -0
  3. package/esm/common/auth-protocol.js +3 -0
  4. package/esm/common/auth-protocol.js.map +1 -0
  5. package/esm/common/index.d.ts +6 -0
  6. package/esm/common/index.js +6 -0
  7. package/esm/common/index.js.map +1 -1
  8. package/esm/common/package-protocol.d.ts +92 -0
  9. package/esm/common/package-protocol.js +3 -0
  10. package/esm/common/package-protocol.js.map +1 -0
  11. package/esm/common/pi-types.d.ts +1 -0
  12. package/esm/common/relay-protocol.d.ts +28 -0
  13. package/esm/common/relay-protocol.js +3 -0
  14. package/esm/common/relay-protocol.js.map +1 -0
  15. package/esm/common/settings-protocol.d.ts +42 -0
  16. package/esm/common/settings-protocol.js +22 -0
  17. package/esm/common/settings-protocol.js.map +1 -0
  18. package/esm/common/ta-extension-host.d.ts +44 -0
  19. package/esm/common/ta-extension-host.js +8 -0
  20. package/esm/common/ta-extension-host.js.map +1 -0
  21. package/esm/common/ta-protocol.d.ts +110 -8
  22. package/esm/common/ta-protocol.js +21 -0
  23. package/esm/common/ta-protocol.js.map +1 -1
  24. package/esm/common/workspace-protocol.d.ts +91 -0
  25. package/esm/common/workspace-protocol.js +7 -0
  26. package/esm/common/workspace-protocol.js.map +1 -0
  27. package/lib/common/auth-protocol.d.ts +90 -0
  28. package/lib/common/auth-protocol.d.ts.map +1 -0
  29. package/lib/common/auth-protocol.js +6 -0
  30. package/lib/common/auth-protocol.js.map +1 -0
  31. package/lib/common/index.d.ts +6 -0
  32. package/lib/common/index.d.ts.map +1 -1
  33. package/lib/common/index.js +6 -0
  34. package/lib/common/index.js.map +1 -1
  35. package/lib/common/package-protocol.d.ts +93 -0
  36. package/lib/common/package-protocol.d.ts.map +1 -0
  37. package/lib/common/package-protocol.js +6 -0
  38. package/lib/common/package-protocol.js.map +1 -0
  39. package/lib/common/pi-types.d.ts +1 -0
  40. package/lib/common/pi-types.d.ts.map +1 -1
  41. package/lib/common/relay-protocol.d.ts +29 -0
  42. package/lib/common/relay-protocol.d.ts.map +1 -0
  43. package/lib/common/relay-protocol.js +6 -0
  44. package/lib/common/relay-protocol.js.map +1 -0
  45. package/lib/common/settings-protocol.d.ts +43 -0
  46. package/lib/common/settings-protocol.d.ts.map +1 -0
  47. package/lib/common/settings-protocol.js +25 -0
  48. package/lib/common/settings-protocol.js.map +1 -0
  49. package/lib/common/ta-extension-host.d.ts +45 -0
  50. package/lib/common/ta-extension-host.d.ts.map +1 -0
  51. package/lib/common/ta-extension-host.js +11 -0
  52. package/lib/common/ta-extension-host.js.map +1 -0
  53. package/lib/common/ta-protocol.d.ts +110 -8
  54. package/lib/common/ta-protocol.d.ts.map +1 -1
  55. package/lib/common/ta-protocol.js +22 -1
  56. package/lib/common/ta-protocol.js.map +1 -1
  57. package/lib/common/ta-protocol.spec.js +21 -0
  58. package/lib/common/ta-protocol.spec.js.map +1 -1
  59. package/lib/common/workspace-protocol.d.ts +92 -0
  60. package/lib/common/workspace-protocol.d.ts.map +1 -0
  61. package/lib/common/workspace-protocol.js +10 -0
  62. package/lib/common/workspace-protocol.js.map +1 -0
  63. package/package.json +1 -1
  64. package/src/common/auth-protocol.ts +56 -0
  65. package/src/common/index.ts +6 -0
  66. package/src/common/package-protocol.ts +99 -0
  67. package/src/common/pi-types.ts +1 -0
  68. package/src/common/relay-protocol.ts +28 -0
  69. package/src/common/settings-protocol.ts +66 -0
  70. package/src/common/ta-extension-host.ts +52 -0
  71. package/src/common/ta-protocol.spec.ts +30 -1
  72. package/src/common/ta-protocol.ts +123 -7
  73. package/src/common/workspace-protocol.ts +102 -0
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # Cell - ta Protocol
1
+ # Cell - Ta Protocol
2
2
 
3
3
  `ta serve` 与客户端之间的协议:只有类型和常量,不加载 pi 和 Node.js 模块,浏览器可用。
4
4
 
5
- - 传输:JSON-RPC 2.0 over WebSocket(`TA_WEBSOCKET_PATH`),客户端调用 `TaServer/<方法>`,服务端推送 `TaClient/onEvents`。
6
- - `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase),第一个参数是 `sessionId`,返回值与 pi 相同。
7
- - 事件:`TaEventEnvelope { sessionId, seq, event }`,`event` 是 pi JSON/RPC 模式的事件或 `extension_ui_request`;ta 只多了 `ui_request_resolved`、`extension_error`、`session_replaced`、`session_closed`、`client_tool_request`(预留)。
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 扩展与包的数据)。会话之外的能力按职责各成一个服务,不往 `TaServer` 里加。
7
+ - `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。pi RPC 没有的会话操作:`forkToFile`(把 fork 出的对话另存成会话文件,当前会话不动,再用 `openSession` 打开),`navigateTree`(同 pi 的 `/tree`,返回 `editorText`),`fork` 多一个可选的 `position`(`at` 保留所选条目,同 pi 的 `/clone` 但可选任意条目)。
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`(预留)。
8
9
  - `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
9
- - 失败时 JSON-RPC 错误码为 `TA_RPC_ERROR_CODE`,`data` 里有稳定的 `code`(`TaErrorCode`,如 `CELL_TA_SESSION_LOCKED`)和一句处理建议 `hint`。
10
+ - 失败时 JSON-RPC 错误码为 `TA_RPC_ERROR_CODE`,`data` 里有稳定的 `code`(`TaErrorCode`,如 `CELL_TA_SESSION_LOCKED`)和一句处理建议 `hint`。`CELL_TA_CONNECTION_LOST` 由客户端产生:调用没能送到 ta serve,或连接断开时还没收到结果。
@@ -0,0 +1,89 @@
1
+ export declare const TaAuthServer: unique symbol;
2
+ export declare const TA_AUTH_SERVICE = "TaAuthServer";
3
+ /** How pi signs in to a provider: an account (OAuth), often a subscription, or an API key. */
4
+ export type TaAuthType = 'oauth' | 'api_key';
5
+ /** One way to sign in to a provider of models, as pi's `/login` lists them: a provider with both is listed twice. */
6
+ export interface TaAuthProvider {
7
+ /** pi's id of the provider, e.g. `anthropic`. */
8
+ id: string;
9
+ name: string;
10
+ type: TaAuthType;
11
+ /** The account is a subscription (Claude Pro, ChatGPT Plus…), not paid per request. */
12
+ subscription: boolean;
13
+ /** False for a key that only comes from the environment (variables, cloud profiles): there is nothing to type in. */
14
+ interactive: boolean;
15
+ /** How the provider is signed in now, if it is: with which kind, and from where (`stored credential`, an environment variable…). */
16
+ configured?: {
17
+ type: TaAuthType;
18
+ source?: string;
19
+ };
20
+ /** pi keeps a credential of it in auth.json, which `logout` removes. */
21
+ stored: boolean;
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';
26
+ message: string;
27
+ placeholder?: string;
28
+ } | {
29
+ type: 'select';
30
+ message: string;
31
+ options: {
32
+ id: string;
33
+ label: string;
34
+ description?: string;
35
+ }[];
36
+ };
37
+ /**
38
+ * What happens during a sign-in, to the connection that started it (TaClient.onAuthEvent). The first
39
+ * four are pi's AuthEvent: a page to open, a code to type in elsewhere, what it is doing.
40
+ */
41
+ export type TaAuthEvent = {
42
+ type: 'info';
43
+ message: string;
44
+ links?: {
45
+ url: string;
46
+ label?: string;
47
+ }[];
48
+ } | {
49
+ type: 'auth_url';
50
+ url: string;
51
+ instructions?: string;
52
+ } | {
53
+ type: 'device_code';
54
+ userCode: string;
55
+ verificationUri: string;
56
+ expiresInSeconds?: number;
57
+ } | {
58
+ type: 'progress';
59
+ message: string;
60
+ } | {
61
+ type: 'prompt';
62
+ promptId: string;
63
+ prompt: TaAuthPrompt;
64
+ }
65
+ /** The flow no longer waits for that answer: it got what it needed otherwise (a browser came back). */
66
+ | {
67
+ type: 'prompt_closed';
68
+ promptId: string;
69
+ } | {
70
+ type: 'done';
71
+ } | {
72
+ type: 'failed';
73
+ message: string;
74
+ cancelled?: boolean;
75
+ };
76
+ /**
77
+ * Signing in to providers of models from a client, as pi's `/login` and `/logout` do in the terminal.
78
+ * Credentials go to pi's auth.json on the server, for every session; they never come back to a client.
79
+ */
80
+ export interface TaAuthServer {
81
+ listProviders(): Promise<TaAuthProvider[]>;
82
+ /** Starts a sign-in; its events go to this connection only. Resolves at once with its id. */
83
+ login(providerId: string, type: TaAuthType): Promise<string>;
84
+ /** Answers a prompt of a sign-in of this connection; false when it no longer waits for it. */
85
+ answer(loginId: string, promptId: string, value: string): Promise<boolean>;
86
+ cancel(loginId: string): Promise<void>;
87
+ /** Removes the stored credential of the provider. */
88
+ logout(providerId: string): Promise<void>;
89
+ }
@@ -0,0 +1,3 @@
1
+ export const TaAuthServer = Symbol('TaAuthServer');
2
+ export const TA_AUTH_SERVICE = 'TaAuthServer';
3
+ //# sourceMappingURL=auth-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-protocol.js","sourceRoot":"","sources":["../../src/common/auth-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC"}
@@ -1,2 +1,8 @@
1
+ export * from './auth-protocol.js';
2
+ export * from './package-protocol.js';
1
3
  export * from './pi-types.js';
4
+ export * from './relay-protocol.js';
5
+ export * from './settings-protocol.js';
6
+ export * from './ta-extension-host.js';
2
7
  export * from './ta-protocol.js';
8
+ export * from './workspace-protocol.js';
@@ -1,3 +1,9 @@
1
+ export * from './auth-protocol.js';
2
+ export * from './package-protocol.js';
1
3
  export * from './pi-types.js';
4
+ export * from './relay-protocol.js';
5
+ export * from './settings-protocol.js';
6
+ export * from './ta-extension-host.js';
2
7
  export * from './ta-protocol.js';
8
+ export * from './workspace-protocol.js';
3
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
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"}
@@ -0,0 +1,92 @@
1
+ import type { TaSettingsScope } from './settings-protocol.js';
2
+ export declare const TaPackageServer: unique symbol;
3
+ export declare const TA_PACKAGE_SERVICE = "TaPackageServer";
4
+ /**
5
+ * A web extension: the part of a pi package that extends the web client, as `extensions` extend pi. A
6
+ * package declares it in its `package.json`, `"pi": { "web": ["./web.js"] }`, or keeps it in `web/`.
7
+ * It is one ES module, without imports, that exports a function the web client calls with its API.
8
+ */
9
+ export interface TaWebExtensionInfo {
10
+ /** Stable while the package stays where it is. */
11
+ id: string;
12
+ /** The `name` of the package, or the name of its directory. */
13
+ name: string;
14
+ description?: string;
15
+ version?: string;
16
+ scope: 'user' | 'project';
17
+ /**
18
+ * `package`: a package of pi's `packages` setting (`ta install`). `directory`: a directory in `extensions/`.
19
+ * `builtin`: a package that comes with ta; it can be turned off (setPackageEnabled), not removed.
20
+ */
21
+ origin: 'package' | 'directory' | 'builtin';
22
+ /** False for a built-in package that is turned off; the others are always on. */
23
+ enabled: boolean;
24
+ /** The source in the `packages` setting, or the directory. */
25
+ source: string;
26
+ /** The file, relative to the package. */
27
+ entry: string;
28
+ /** Changes when the file changes. */
29
+ hash: string;
30
+ }
31
+ /** What a package holds: pi extensions, web extensions, skills, prompt templates, themes. */
32
+ export type TaPackageResource = 'extensions' | 'web' | 'skills' | 'prompts' | 'themes';
33
+ /** A pi package that Ta loads, whether it has a web extension or not. */
34
+ export interface TaPackageInfo {
35
+ /** Stable while the package stays where it is. */
36
+ id: string;
37
+ /** The `name` of its package.json, or the name of its directory. */
38
+ name: string;
39
+ description?: string;
40
+ version?: string;
41
+ scope: 'user' | 'project';
42
+ /** As TaWebExtensionInfo.origin. */
43
+ origin: TaWebExtensionInfo['origin'];
44
+ /** False for a built-in package that is turned off. */
45
+ enabled: boolean;
46
+ /** The source in the `packages` setting, or the directory. */
47
+ source: string;
48
+ /** Its directory, on the machine of the server. */
49
+ root: string;
50
+ /** What it holds, by its package.json or, without `pi` there, by the directories pi looks in. */
51
+ resources: TaPackageResource[];
52
+ }
53
+ export interface TaWebExtensionSource {
54
+ id: string;
55
+ hash: string;
56
+ code: string;
57
+ }
58
+ /** The packages of ta and the data they keep, on the same WebSocket as {@link TaServer}. */
59
+ export interface TaPackageServer {
60
+ /** The web extensions of the packages pi loads in `cwd` (default: the server's directory). */
61
+ listWebExtensions(cwd?: string): Promise<TaWebExtensionInfo[]>;
62
+ readWebExtension(id: string, cwd?: string): Promise<TaWebExtensionSource>;
63
+ /** Removes the package of a web extension: as `ta remove` for a package, deletes the directory for a directory. */
64
+ removeWebExtension(id: string, cwd?: string): Promise<void>;
65
+ /**
66
+ * Turns a package on or off, what pi loads of it and its web extension; sessions pick it up on reload.
67
+ * A built-in one by its name; another by its id of listPackages, as `ta config` turns each of its
68
+ * resources on or off, in the settings of its scope.
69
+ */
70
+ setPackageEnabled(nameOrId: string, enabled: boolean, cwd?: string): Promise<void>;
71
+ /** Every package pi loads in `cwd` (default: the server's directory), with a web extension or without. */
72
+ listPackages(cwd?: string): Promise<TaPackageInfo[]>;
73
+ /**
74
+ * Installs a package and adds it to pi's `packages` setting, as `ta install` does: `npm:<name>`,
75
+ * `git:<repository>`, a URL of a repository, or a path. `project` as `ta install -l`, in a trusted
76
+ * project. Sessions pick it up on reload.
77
+ */
78
+ installPackage(source: string, scope: TaSettingsScope, cwd?: string): Promise<void>;
79
+ /** Removes a package of listPackages: as `ta remove` for a package of the setting, deletes the directory for a directory. */
80
+ removePackage(id: string, cwd?: string): Promise<void>;
81
+ /**
82
+ * Calls a method of what the module of `pi.host` of a package that comes with Ta returned
83
+ * (TaPackageService), with JSON values, and answers what it returns: how its web extension reaches it.
84
+ */
85
+ callPackageHost(name: string, method: string, params?: unknown[]): Promise<unknown>;
86
+ /**
87
+ * A value a package keeps on the server (WebExtensionAPI.storage); undefined when there is none. With
88
+ * `cwd`, a value of that directory, in its execution environment: each directory has its own keys.
89
+ */
90
+ getExtensionData(name: string, key: string, cwd?: string): Promise<unknown>;
91
+ setExtensionData(name: string, key: string, value: unknown, cwd?: string): Promise<void>;
92
+ }
@@ -0,0 +1,3 @@
1
+ export const TaPackageServer = Symbol('TaPackageServer');
2
+ export const TA_PACKAGE_SERVICE = 'TaPackageServer';
3
+ //# sourceMappingURL=package-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-protocol.js","sourceRoot":"","sources":["../../src/common/package-protocol.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' } }).ImageContent;
2
2
  export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).JsonAgentSessionEvent;
3
+ export type RpcCommand = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcCommand;
3
4
  export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIRequest;
4
5
  export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIResponse;
5
6
  export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcResponse;
@@ -0,0 +1,28 @@
1
+ export declare const TaRelayServer: unique symbol;
2
+ export declare const TA_RELAY_SERVICE = "TaRelayServer";
3
+ /** A device paired with this ta serve, which reaches it through a relay (@celljs/ta-relay). */
4
+ export interface TaRelayDevice {
5
+ id: string;
6
+ name: string;
7
+ createdAt: number;
8
+ }
9
+ export interface TaRelayInfo {
10
+ /** The relay of the devices; none before the first is paired. */
11
+ relay?: string;
12
+ /** The relay a new pairing uses when the user names none. */
13
+ defaultRelay: string;
14
+ /** ta serve is connected to the relay now: the devices can reach it. */
15
+ online: boolean;
16
+ devices: TaRelayDevice[];
17
+ }
18
+ /** Pairing devices from a client, as `ta pair` does in a terminal. */
19
+ export interface TaRelayServer {
20
+ getRelay(): Promise<TaRelayInfo>;
21
+ /** A new device; `link` holds its key, for the device only: show it once (a QR code), do not keep it. */
22
+ pair(relay: string, name: string): Promise<{
23
+ link: string;
24
+ device: TaRelayDevice;
25
+ }>;
26
+ /** The device can no longer reach this ta serve, at once. */
27
+ unpair(deviceId: string): Promise<void>;
28
+ }
@@ -0,0 +1,3 @@
1
+ export const TaRelayServer = Symbol('TaRelayServer');
2
+ export const TA_RELAY_SERVICE = 'TaRelayServer';
3
+ //# sourceMappingURL=relay-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-protocol.js","sourceRoot":"","sources":["../../src/common/relay-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC"}
@@ -0,0 +1,42 @@
1
+ export declare const TaSettingsServer: unique symbol;
2
+ export declare const TA_SETTINGS_SERVICE = "TaSettingsServer";
3
+ /** 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. */
4
+ export type TaSettingsScope = 'user' | 'project';
5
+ /** A setting of ta that clients show and change; the key is its path in pi's `settings.json`. */
6
+ export interface TaSettingSpec {
7
+ key: string;
8
+ /** `model`: `<provider>/<model id>`, kept by pi as `defaultProvider` and `defaultModel`. */
9
+ type: 'boolean' | 'number' | 'string' | 'enum' | 'model';
10
+ values?: readonly string[];
11
+ /** What pi does when no file sets it; none when pi decides by itself (the model, a thinking level). */
12
+ default?: boolean | number | string;
13
+ }
14
+ /** The settings of ta that clients change, as pi names them; other keys of the files are left as they are. */
15
+ export declare const TA_SETTINGS: readonly TaSettingSpec[];
16
+ /** The settings of ta (TA_SETTINGS) in the files of the user and of a project: only the keys each file sets. */
17
+ export interface TaSettingsSnapshot {
18
+ user: Record<string, unknown>;
19
+ project: Record<string, unknown>;
20
+ /** The directory of the project. */
21
+ cwd: string;
22
+ userFile: string;
23
+ projectFile: string;
24
+ /**
25
+ * pi reads the settings of a project only when the user trusts it. Changing them from a client trusts a
26
+ * project that has nothing else to trust yet; one with extensions or skills of its own is trusted in `ta`.
27
+ */
28
+ projectTrusted: boolean;
29
+ /** `<provider>/<model id>` of the models with credentials, for the model setting. */
30
+ models: string[];
31
+ }
32
+ /** The settings of ta in pi's `settings.json` files, on the same WebSocket as {@link TaServer}. */
33
+ export interface TaSettingsServer {
34
+ /** The settings of ta (TA_SETTINGS) of the user and of the project in `cwd` (default: the server's directory). */
35
+ getSettings(cwd?: string): Promise<TaSettingsSnapshot>;
36
+ /**
37
+ * Sets settings of ta in one file, by key of TA_SETTINGS; `null` removes a key, so that the project
38
+ * follows the user and the user pi's default. Open sessions read them again; the model and the thinking
39
+ * level are for new sessions.
40
+ */
41
+ updateSettings(scope: TaSettingsScope, changes: Record<string, unknown>, cwd?: string): Promise<TaSettingsSnapshot>;
42
+ }
@@ -0,0 +1,22 @@
1
+ export const TaSettingsServer = Symbol('TaSettingsServer');
2
+ export const TA_SETTINGS_SERVICE = 'TaSettingsServer';
3
+ /** The settings of ta that clients change, as pi names them; other keys of the files are left as they are. */
4
+ export const TA_SETTINGS = [
5
+ { key: 'model', type: 'model' },
6
+ { key: 'defaultThinkingLevel', type: 'enum', values: ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] },
7
+ { key: 'transport', type: 'enum', values: ['auto', 'sse', 'websocket', 'websocket-cached'], default: 'auto' },
8
+ { key: 'steeringMode', type: 'enum', values: ['one-at-a-time', 'all'], default: 'one-at-a-time' },
9
+ { key: 'followUpMode', type: 'enum', values: ['one-at-a-time', 'all'], default: 'one-at-a-time' },
10
+ { key: 'compaction.enabled', type: 'boolean', default: true },
11
+ { key: 'compaction.reserveTokens', type: 'number', default: 16384 },
12
+ { key: 'compaction.keepRecentTokens', type: 'number', default: 20000 },
13
+ { key: 'retry.enabled', type: 'boolean', default: true },
14
+ { key: 'retry.maxRetries', type: 'number', default: 3 },
15
+ { key: 'codemode.mode', type: 'enum', values: ['only', 'on'], default: 'only' },
16
+ { key: 'enableSkillCommands', type: 'boolean', default: true },
17
+ { key: 'images.autoResize', type: 'boolean', default: true },
18
+ { key: 'images.blockImages', type: 'boolean', default: false },
19
+ { key: 'shellPath', type: 'string' },
20
+ { key: 'shellCommandPrefix', type: 'string' },
21
+ ];
22
+ //# sourceMappingURL=settings-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-protocol.js","sourceRoot":"","sources":["../../src/common/settings-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAetD,8GAA8G;AAC9G,MAAM,CAAC,MAAM,WAAW,GAA6B;IACjD,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;IAC/B,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE;IAClH,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE;IAC7G,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE;IACjG,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE;IACjG,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IAC7D,EAAE,GAAG,EAAE,0BAA0B,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;IACnE,EAAE,GAAG,EAAE,6BAA6B,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;IACtE,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACxD,EAAE,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;IACvD,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE;IAC/E,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IAC9D,EAAE,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IAC5D,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;IAC9D,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE;CAChD,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { TaPackageServer } from './package-protocol.js';
2
+ import type { TaServer } from './ta-protocol.js';
3
+ /**
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 and drive sessions, not
6
+ * close or remove anything.
7
+ */
8
+ export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'setSessionName' | 'prompt' | 'followUp' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
9
+ /** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
10
+ readonly agentDir: string;
11
+ /** 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
+ onExtensionData(listener: (name: string, key: string, cwd?: string) => void): () => void;
13
+ }
14
+ /**
15
+ * What the module of `pi.host` returns: anything the package's pi extensions should reach. Its web
16
+ * extension calls its methods with TaPackageServer.callPackageHost, with JSON values.
17
+ */
18
+ export interface TaPackageService {
19
+ /** `ta serve` stops, or the package is turned off. */
20
+ dispose?(): void | Promise<void>;
21
+ }
22
+ /**
23
+ * The default export of a module that a package names in `pi.host` of its package.json. `ta serve` runs it
24
+ * once when it starts (or when the package is turned on), for built-in packages; `ta` without `serve`
25
+ * does not run it.
26
+ */
27
+ export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService | undefined | Promise<TaPackageService | undefined>;
28
+ /**
29
+ * The event of pi's `pi.events` by which a pi extension asks for the host of its package:
30
+ * `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
31
+ * the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
32
+ * and the extension should say its tools need `ta serve`.
33
+ */
34
+ export declare const TA_HOST_EVENT = "ta:host";
35
+ export interface TaHostRequest {
36
+ /** The `name` of the package.json. */
37
+ name: string;
38
+ resolve(answer: TaHostAnswer): void;
39
+ }
40
+ export interface TaHostAnswer {
41
+ host: TaExtensionHost;
42
+ /** What the module of `pi.host` of the package returned; undefined when it has none or failed. */
43
+ service?: TaPackageService;
44
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The event of pi's `pi.events` by which a pi extension asks for the host of its package:
3
+ * `pi.events.emit(TA_HOST_EVENT, { name, resolve })`. Under `ta serve` `resolve` is called at once, if
4
+ * the extension asks after loading (on `session_start`, or in a tool); under `ta` alone nobody answers,
5
+ * and the extension should say its tools need `ta serve`.
6
+ */
7
+ export const TA_HOST_EVENT = 'ta:host';
8
+ //# sourceMappingURL=ta-extension-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ta-extension-host.js","sourceRoot":"","sources":["../../src/common/ta-extension-host.ts"],"names":[],"mappings":"AAiCA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC"}