@celljs/ta-protocol 4.16.0 → 4.18.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 (81) hide show
  1. package/esm/common/access-protocol.d.ts +41 -0
  2. package/esm/common/access-protocol.js +7 -0
  3. package/esm/common/app-protocol.d.ts +120 -0
  4. package/esm/common/app-protocol.js +213 -0
  5. package/esm/common/delegate-protocol.d.ts +30 -0
  6. package/esm/common/delegate-protocol.js +52 -0
  7. package/esm/common/deployment-protocol.d.ts +72 -0
  8. package/esm/common/deployment-protocol.js +171 -0
  9. package/esm/common/error-protocol.d.ts +42 -0
  10. package/esm/common/error-protocol.js +45 -0
  11. package/esm/common/event-protocol.d.ts +63 -0
  12. package/esm/common/event-protocol.js +2 -0
  13. package/esm/common/gateway-protocol.d.ts +29 -0
  14. package/esm/common/index.d.ts +11 -0
  15. package/esm/common/index.js +11 -0
  16. package/esm/common/message-protocol.d.ts +134 -0
  17. package/esm/common/message-protocol.js +322 -0
  18. package/esm/common/page-protocol.d.ts +56 -0
  19. package/esm/common/page-protocol.js +12 -0
  20. package/esm/common/path-map.d.ts +24 -0
  21. package/esm/common/path-map.js +127 -0
  22. package/esm/common/presence-protocol.js +1 -1
  23. package/esm/common/redactor.d.ts +12 -0
  24. package/esm/common/redactor.js +49 -11
  25. package/esm/common/relay-protocol.d.ts +20 -0
  26. package/esm/common/room-protocol.d.ts +52 -1
  27. package/esm/common/said-protocol.d.ts +76 -0
  28. package/esm/common/said-protocol.js +239 -0
  29. package/esm/common/screen-share-protocol.d.ts +304 -0
  30. package/esm/common/screen-share-protocol.js +88 -0
  31. package/esm/common/settings-protocol.d.ts +8 -0
  32. package/esm/common/settings-protocol.js +2 -0
  33. package/esm/common/ta-extension-host.d.ts +64 -1
  34. package/esm/common/ta-extension-host.js +8 -0
  35. package/esm/common/ta-protocol.d.ts +53 -175
  36. package/esm/common/ta-protocol.js +0 -234
  37. package/esm/common/team-protocol.d.ts +13 -2
  38. package/esm/common/team-protocol.js +27 -2
  39. package/esm/common/voice-protocol.d.ts +184 -0
  40. package/esm/common/voice-protocol.js +57 -0
  41. package/lib/common/access-protocol.d.ts +41 -0
  42. package/lib/common/access-protocol.js +8 -1
  43. package/lib/common/app-protocol.d.ts +121 -0
  44. package/lib/common/app-protocol.js +216 -0
  45. package/lib/common/delegate-protocol.d.ts +31 -0
  46. package/lib/common/delegate-protocol.js +55 -0
  47. package/lib/common/deployment-protocol.d.ts +73 -0
  48. package/lib/common/deployment-protocol.js +175 -0
  49. package/lib/common/error-protocol.d.ts +43 -0
  50. package/lib/common/error-protocol.js +48 -0
  51. package/lib/common/event-protocol.d.ts +64 -0
  52. package/lib/common/event-protocol.js +3 -0
  53. package/lib/common/gateway-protocol.d.ts +29 -0
  54. package/lib/common/index.d.ts +11 -0
  55. package/lib/common/index.js +11 -0
  56. package/lib/common/message-protocol.d.ts +135 -0
  57. package/lib/common/message-protocol.js +325 -0
  58. package/lib/common/page-protocol.d.ts +57 -0
  59. package/lib/common/page-protocol.js +15 -0
  60. package/lib/common/path-map.d.ts +25 -0
  61. package/lib/common/path-map.js +130 -0
  62. package/lib/common/presence-protocol.js +7 -7
  63. package/lib/common/redactor.d.ts +12 -0
  64. package/lib/common/redactor.js +49 -11
  65. package/lib/common/relay-protocol.d.ts +20 -0
  66. package/lib/common/room-protocol.d.ts +52 -1
  67. package/lib/common/said-protocol.d.ts +77 -0
  68. package/lib/common/said-protocol.js +242 -0
  69. package/lib/common/screen-share-protocol.d.ts +305 -0
  70. package/lib/common/screen-share-protocol.js +91 -0
  71. package/lib/common/settings-protocol.d.ts +8 -0
  72. package/lib/common/settings-protocol.js +3 -1
  73. package/lib/common/ta-extension-host.d.ts +64 -1
  74. package/lib/common/ta-extension-host.js +9 -1
  75. package/lib/common/ta-protocol.d.ts +53 -175
  76. package/lib/common/ta-protocol.js +1 -235
  77. package/lib/common/team-protocol.d.ts +13 -2
  78. package/lib/common/team-protocol.js +28 -3
  79. package/lib/common/voice-protocol.d.ts +185 -0
  80. package/lib/common/voice-protocol.js +60 -0
  81. package/package.json +1 -1
@@ -6,6 +6,42 @@ export declare const TA_ACCESS_SERVICE = "TaAccessServer";
6
6
  * pages the browser goes to, not calls: they need no token, and give one.
7
7
  */
8
8
  export declare const TA_SIGN_IN_PATH = "/sign-in";
9
+ /**
10
+ * Signing in a device that is not a browser of this address (the app on a phone, Ta Desktop, another Ta): as OAuth 2.0's
11
+ * device flow (RFC 8628), the device asks for a code (`POST` this path), the user signs in in a browser at
12
+ * {@link TaDeviceSignIn.url} and lets it in, and the device takes its token (`POST <path>/poll`). These two answer
13
+ * any origin: they hold no cookie, and what they give goes to who holds the secret of the device.
14
+ */
15
+ export declare const TA_DEVICE_SIGN_IN_PATH = "/sign-in/device";
16
+ /** What `POST` {@link TA_DEVICE_SIGN_IN_PATH} answers: the device keeps `device`, the user sees `code`. */
17
+ export interface TaDeviceSignIn {
18
+ /** The secret the device polls with: whoever holds it gets the token. */
19
+ device: string;
20
+ /** What the device shows, and the page of {@link url} too: the user checks they are the same. */
21
+ code: string;
22
+ /** Where the user signs in, with the code in it. */
23
+ url: string;
24
+ /** Until when the user may sign in (`Date.now()` time). */
25
+ expiresAt: number;
26
+ /** How often the device polls, in milliseconds. */
27
+ interval: number;
28
+ }
29
+ /**
30
+ * What polling says: `pending` until the user signed in; `waiting` while their account is not let in yet (they asked, and
31
+ * whoever manages it lets them in, or not); `done` once, with the token; `expired` for a device unknown or too late.
32
+ */
33
+ export type TaDeviceSignInState = {
34
+ status: 'pending';
35
+ } | {
36
+ status: 'waiting';
37
+ account: string;
38
+ } | {
39
+ status: 'done';
40
+ token: string;
41
+ account: string;
42
+ } | {
43
+ status: 'expired';
44
+ };
9
45
  /** What a sign-in that did not let the browser in says in the fragment of the page it comes back to. */
10
46
  export type TaSignInOutcome = 'denied' | 'failed';
11
47
  /** A way to sign in: `github`, `google`, `wechat`, `oidc` (a provider of the operator's). */
@@ -18,6 +54,11 @@ export interface TaSignInProvider {
18
54
  * back: Ta's own GitHub app, which needs no secret, for those asking to come in (docs/design/ta-team.md 17.4).
19
55
  */
20
56
  device?: true;
57
+ /**
58
+ * One signs in at it in a browser that does not come back, and Ta asks it who agreed (a company's sign-in for CLIs): for a
59
+ * device only, `<path>/<provider>?device=<code>` (TA_DEVICE_SIGN_IN_PATH); a page of this address signs in as a device.
60
+ */
61
+ polled?: true;
21
62
  }
22
63
  /** The answer of `GET` {@link TA_SIGN_IN_PATH}. */
23
64
  export interface TaSignInWays {
@@ -6,4 +6,11 @@ export const TA_ACCESS_SERVICE = 'TaAccessServer';
6
6
  * pages the browser goes to, not calls: they need no token, and give one.
7
7
  */
8
8
  export const TA_SIGN_IN_PATH = '/sign-in';
9
+ /**
10
+ * Signing in a device that is not a browser of this address (the app on a phone, Ta Desktop, another Ta): as OAuth 2.0's
11
+ * device flow (RFC 8628), the device asks for a code (`POST` this path), the user signs in in a browser at
12
+ * {@link TaDeviceSignIn.url} and lets it in, and the device takes its token (`POST <path>/poll`). These two answer
13
+ * any origin: they hold no cookie, and what they give goes to who holds the secret of the device.
14
+ */
15
+ export const TA_DEVICE_SIGN_IN_PATH = `${TA_SIGN_IN_PATH}/device`;
9
16
  //# sourceMappingURL=access-protocol.js.map
@@ -0,0 +1,120 @@
1
+ import type { TaLanguage } from './language.js';
2
+ /**
3
+ * What an action of the catalog of Ta risks (docs/design/ta-app-use.md 7): `read` only looks, `act` changes what can
4
+ * be changed back (a setting, a pin), `danger` what cannot or should not without the user (remove, publish, grant,
5
+ * answer for them): asked for by a run, that one waits for the user to agree on their screen (TA_PAGE_CONFIRM).
6
+ */
7
+ export type TaAppRisk = 'read' | 'act' | 'danger';
8
+ /** An action of the catalog, as the model and the pages read it. */
9
+ export interface TaAppCommandInfo {
10
+ /** `<area>.<verb>`: `settings.set`. */
11
+ id: string;
12
+ /** For the user, in the notice of what Ta did. */
13
+ title: Readonly<Record<TaLanguage, string>>;
14
+ /** For the model, in English: what it does, when to use it, what it answers. */
15
+ description: string;
16
+ /** A JSON schema of an object; none: it takes nothing. */
17
+ input?: Record<string, unknown>;
18
+ risk: TaAppRisk;
19
+ /** What it needs of who asked the run, an action of TA_ACTIONS or one a package declares. */
20
+ action: string;
21
+ /** The package that added it; none for those of Ta itself. */
22
+ owner?: string;
23
+ }
24
+ /** What an action did. */
25
+ export interface TaAppCommandResult {
26
+ /** For the model, in English, short. */
27
+ text: string;
28
+ /** What it read or changed, as JSON. */
29
+ data?: unknown;
30
+ /** For the user, in their language, a few words of what Ta did (`修改了设置`): the head of the notice; none for no notice. */
31
+ notice?: string;
32
+ /** For the user, in their language: what changed, a row each under the head of the notice. */
33
+ changes?: TaAppChange[];
34
+ /** What changes it back: an action and its input. */
35
+ undo?: {
36
+ command: string;
37
+ input: Record<string, unknown>;
38
+ };
39
+ }
40
+ /** One thing an action changed, as the user reads it: `通话字幕 关 → 开`, or a name alone (`登录修复`). */
41
+ export interface TaAppChange {
42
+ label?: string;
43
+ before?: string;
44
+ after: string;
45
+ }
46
+ /** Who an action runs for. */
47
+ export interface TaAppCommandContext {
48
+ /** TA_OWNER, or one let in (ta-team). */
49
+ principal: string;
50
+ /** That of the pages (TaLanguageUtil.server). */
51
+ language: TaLanguage;
52
+ /** The conversation whose run asked for it. */
53
+ sessionFile?: string;
54
+ }
55
+ /** An action of the catalog and what runs it. */
56
+ export interface TaAppCommand extends Omit<TaAppCommandInfo, 'owner'> {
57
+ /**
58
+ * For a danger action, what the user agrees to beyond its title, in their language (`登录修复:用哪个分支 → dev`);
59
+ * it may throw for an input that cannot run, so the user is not asked for nothing.
60
+ */
61
+ detail?(input: Record<string, unknown>, context: TaAppCommandContext): Promise<string | undefined>;
62
+ run(input: Record<string, unknown>, context: TaAppCommandContext): Promise<TaAppCommandResult>;
63
+ }
64
+ /** Who asks for an action: the run of a conversation (each who asked it), or one principal (a tap on a page). */
65
+ export interface TaAppRunOptions {
66
+ sessionFile?: string;
67
+ principal?: string;
68
+ }
69
+ /**
70
+ * The catalog of what can be done to Ta without its pages (docs/design/ta-app-use.md 2): change a setting, pin a
71
+ * conversation, turn an extension off. The buttons of the pages change the same data, so a page shows at once
72
+ * what an action did, and an agent does what the user can without moving a cursor.
73
+ */
74
+ export interface TaHostCommands {
75
+ list(): TaAppCommandInfo[];
76
+ /**
77
+ * Runs an action for who asked (TaAppRunOptions): each must be let to do its `action`. Throws with what is wrong:
78
+ * no such action, not let to, an input it does not take, a `danger` one the user did not agree to on their screen.
79
+ */
80
+ run(id: string, input?: Record<string, unknown>, options?: TaAppRunOptions): Promise<TaAppCommandResult>;
81
+ /** Adds an action, gone with the function returned or when the package stops. */
82
+ register(command: TaAppCommand): () => void;
83
+ }
84
+ /** The tools of ta-app-use, the catalog and the screen: a call's front has them too. */
85
+ export declare const TA_APP_TOOLS: readonly ['app_commands', 'app_run', 'app_look', 'app_go', 'app_do'];
86
+ /** Where the web client keeps its settings (TaState `user`): in the data of packages, under this name and key. */
87
+ export declare const TA_WEB_SETTINGS_DATA: {
88
+ readonly name: '@celljs/ta-web';
89
+ readonly key: 'settings';
90
+ };
91
+ /** Where the web client keeps the conversations pinned to the top of its lists: their session files, and keys of folders. */
92
+ export declare const TA_CHAT_PINNED: {
93
+ readonly name: '@celljs/ta-web';
94
+ readonly key: 'chat.pinned';
95
+ };
96
+ /** A setting of the web client an action may change (settings.set), as the settings page offers it. */
97
+ export interface TaWebSettingSpec {
98
+ key: string;
99
+ type: 'boolean' | 'enum' | 'number' | 'string' | 'model';
100
+ /** The values it may be, for `enum` and `number`. */
101
+ values?: readonly (string | number)[];
102
+ default: boolean | number | string;
103
+ /** For the model, in English. */
104
+ what: string;
105
+ title: Readonly<Record<TaLanguage, string>>;
106
+ /** What the user calls its values, by value, where the value itself is a word of the code. */
107
+ shown?: Readonly<Record<string, Readonly<Record<TaLanguage, string>>>>;
108
+ }
109
+ /**
110
+ * The settings of the web client (Settings of ta-web) an agent may change: those the settings page shows with a
111
+ * switch or a choice. Not `trustedDomains` (links open without asking), nor `navigation` and `builtinsOff`, which
112
+ * have pages and actions of their own. The tests of ta-web hold these to its defaults and choices.
113
+ */
114
+ export declare const TA_WEB_SETTINGS: readonly TaWebSettingSpec[];
115
+ export declare namespace TaAppUtil {
116
+ /** `value` for the setting, or why not: a value of its type and among its values. */
117
+ function check(spec: TaWebSettingSpec, value: unknown): string | undefined;
118
+ /** A value as the user reads it: on and off for a switch, the words of a choice (TaWebSettingSpec.shown). */
119
+ function shown(value: unknown, language: TaLanguage, spec?: TaWebSettingSpec): string;
120
+ }
@@ -0,0 +1,213 @@
1
+ import { TaDelegateUtil } from './delegate-protocol.js';
2
+ import { TaLanguageUtil } from './language.js';
3
+ /** The tools of ta-app-use, the catalog and the screen: a call's front has them too. */
4
+ export const TA_APP_TOOLS = ['app_commands', 'app_run', 'app_look', 'app_go', 'app_do'];
5
+ /** Where the web client keeps its settings (TaState `user`): in the data of packages, under this name and key. */
6
+ export const TA_WEB_SETTINGS_DATA = { name: '@celljs/ta-web', key: 'settings' };
7
+ /** Where the web client keeps the conversations pinned to the top of its lists: their session files, and keys of folders. */
8
+ export const TA_CHAT_PINNED = { name: '@celljs/ta-web', key: 'chat.pinned' };
9
+ const FONT_SIZES = ['small', 'standard', 'large', 'xlarge'];
10
+ const words = (en, zh, tw, ja) => ({ 'en-US': en, 'zh-CN': zh, 'zh-TW': tw, 'ja-JP': ja });
11
+ const SYSTEM = words('as the system', '跟随系统', '跟隨系統', 'システムに合わせる');
12
+ const FONT_SHOWN = {
13
+ small: words('small', '小', '小', '小'),
14
+ standard: words('standard', '标准', '標準', '標準'),
15
+ large: words('large', '大', '大', '大'),
16
+ xlarge: words('extra large', '特大', '特大', '特大'),
17
+ };
18
+ /**
19
+ * The settings of the web client (Settings of ta-web) an agent may change: those the settings page shows with a
20
+ * switch or a choice. Not `trustedDomains` (links open without asking), nor `navigation` and `builtinsOff`, which
21
+ * have pages and actions of their own. The tests of ta-web hold these to its defaults and choices.
22
+ */
23
+ export const TA_WEB_SETTINGS = [
24
+ {
25
+ key: 'theme',
26
+ type: 'enum',
27
+ values: ['system', 'light', 'dark'],
28
+ default: 'system',
29
+ what: 'Light or dark look; system follows the device.',
30
+ title: words('Theme', '外观', '外觀', '外観'),
31
+ shown: { system: SYSTEM, light: words('light', '浅色', '淺色', 'ライト'), dark: words('dark', '深色', '深色', 'ダーク') },
32
+ },
33
+ {
34
+ key: 'language',
35
+ type: 'enum',
36
+ values: ['system', ...TaLanguageUtil.ALL],
37
+ default: 'system',
38
+ what: "The language of Ta's pages and of what Ta says; system follows the device.",
39
+ title: words('Language', '语言', '語言', '言語'),
40
+ shown: {
41
+ system: SYSTEM,
42
+ ...Object.fromEntries(TaLanguageUtil.ALL.map(language => [
43
+ language,
44
+ words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language]),
45
+ ])),
46
+ },
47
+ },
48
+ {
49
+ key: 'fontSize',
50
+ type: 'enum',
51
+ values: FONT_SIZES,
52
+ default: 'standard',
53
+ what: 'The size of the text of the whole page.',
54
+ title: words('Text size', '字体大小', '字型大小', '文字サイズ'),
55
+ shown: FONT_SHOWN,
56
+ },
57
+ {
58
+ key: 'chatFontSize',
59
+ type: 'enum',
60
+ values: FONT_SIZES,
61
+ default: 'standard',
62
+ what: 'The size of the text of conversations, on top of fontSize.',
63
+ title: words('Text size of conversations', '对话字体大小', '對話字型大小', '会話の文字サイズ'),
64
+ shown: FONT_SHOWN,
65
+ },
66
+ {
67
+ key: 'speak',
68
+ type: 'boolean',
69
+ default: false,
70
+ what: 'Read every reply aloud.',
71
+ title: words('Read replies aloud', '朗读回复', '朗讀回覆', '返信を読み上げ'),
72
+ },
73
+ {
74
+ key: 'speakTalk',
75
+ type: 'boolean',
76
+ default: false,
77
+ what: 'Read the reply aloud when the user spoke to the double by voice.',
78
+ title: words('Read aloud what was asked by voice', '语音提问时朗读回复', '語音提問時朗讀回覆', '音声で聞いたら読み上げ'),
79
+ },
80
+ {
81
+ key: 'callCaptions',
82
+ type: 'boolean',
83
+ default: false,
84
+ what: 'Show captions in a call: what the user says and what Ta reads.',
85
+ title: words('Call captions', '通话字幕', '通話字幕', '通話の字幕'),
86
+ },
87
+ {
88
+ key: 'voice',
89
+ type: 'string',
90
+ default: '',
91
+ what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
92
+ title: words('Voice', '朗读声音', '朗讀聲音', '読み上げの声'),
93
+ },
94
+ {
95
+ key: 'confirmTasks',
96
+ type: 'boolean',
97
+ default: false,
98
+ what: 'The double asks before it hands out work.',
99
+ title: words('Ask before handing out work', '派任务前先问我', '派任務前先問我', '作業を割り当てる前に確認'),
100
+ },
101
+ {
102
+ key: 'maxTasks',
103
+ type: 'number',
104
+ values: [0, 2, 4, 8],
105
+ default: 0,
106
+ what: "How many of the double's tasks run at once; 0 for as many as it starts.",
107
+ title: words('Tasks at once', '同时运行的任务', '同時執行的任務', '同時に実行するタスク'),
108
+ },
109
+ {
110
+ key: 'delegate',
111
+ type: 'enum',
112
+ values: TaDelegateUtil.LEVELS,
113
+ default: TaDelegateUtil.DEFAULT,
114
+ what: 'How much of the work the double hands out to tasks rather than doing it itself.',
115
+ title: words('Hand out work', '派活多少', '派活多少', '作業の割り当て'),
116
+ shown: { less: words('less', '少', '少', '少なめ'), balanced: words('balanced', '适中', '適中', 'ふつう'), more: words('more', '多', '多', '多め') },
117
+ },
118
+ {
119
+ key: 'assistantModel',
120
+ type: 'model',
121
+ default: '',
122
+ what: 'The model of the double, <provider>/<model id>; empty for the default model.',
123
+ title: words('Model of the double', '分身的模型', '分身的模型', '分身のモデル'),
124
+ },
125
+ {
126
+ key: 'taskModel',
127
+ type: 'model',
128
+ default: '',
129
+ what: 'The model of the tasks the double starts; empty for the default model.',
130
+ title: words('Model of tasks', '任务的模型', '任務的模型', 'タスクのモデル'),
131
+ },
132
+ { key: 'reduceMotion', type: 'boolean', default: false, what: 'Fewer animations.', title: words('Reduce motion', '减少动画', '減少動畫', '動きを減らす') },
133
+ {
134
+ key: 'diagramStyle',
135
+ type: 'enum',
136
+ values: ['clean', 'sketch', 'colour', 'motion'],
137
+ default: 'clean',
138
+ what: 'How diagrams in replies draw: in the colours of the page, as by hand, a colour to a node, or coming in with flowing lines.',
139
+ title: words('Diagram style', '图表风格', '圖表風格', '図のスタイル'),
140
+ shown: {
141
+ clean: words('clean', '简洁', '簡潔', 'シンプル'),
142
+ sketch: words('sketch', '草图', '草圖', 'スケッチ'),
143
+ colour: words('colour', '彩色', '彩色', 'カラー'),
144
+ motion: words('motion', '动效', '動效', 'モーション'),
145
+ },
146
+ },
147
+ {
148
+ key: 'keepAliveMinutes',
149
+ type: 'number',
150
+ values: [1, 5, 15, 30],
151
+ default: 5,
152
+ what: 'How long an extension started on open keeps running once left, in minutes.',
153
+ title: words('Keep extensions running', '扩展离开后保留', '擴充功能離開後保留', '拡張機能を保持'),
154
+ },
155
+ {
156
+ key: 'chatFoldDays',
157
+ type: 'number',
158
+ values: [3, 7, 30, 0],
159
+ default: 7,
160
+ what: 'Conversations not updated for these days fold at the end of the list; 0 for none.',
161
+ title: words('Fold old conversations', '折叠旧对话', '摺疊舊對話', '古い会話を折りたたむ'),
162
+ },
163
+ {
164
+ key: 'chatArchiveDays',
165
+ type: 'number',
166
+ values: [30, 90, 365, 0],
167
+ default: 30,
168
+ what: 'Conversations not updated for these days are archived (out of the list, found by search); 0 for none.',
169
+ title: words('Archive old conversations', '归档旧对话', '歸檔舊對話', '古い会話をアーカイブ'),
170
+ },
171
+ {
172
+ key: 'recentShots',
173
+ type: 'boolean',
174
+ default: true,
175
+ what: 'The screenshot just taken is offered above the message box, once.',
176
+ title: words('Offer recent screenshots', '提示刚截的图', '提示剛截的圖', '撮ったばかりのスクリーンショットを提案'),
177
+ },
178
+ ];
179
+ export var TaAppUtil;
180
+ (function (TaAppUtil) {
181
+ /** `value` for the setting, or why not: a value of its type and among its values. */
182
+ function check(spec, value) {
183
+ var _a, _b;
184
+ switch (spec.type) {
185
+ case 'boolean':
186
+ return typeof value === 'boolean' ? undefined : 'true or false';
187
+ case 'string':
188
+ return typeof value === 'string' ? undefined : 'a string';
189
+ case 'model':
190
+ return value === '' || (typeof value === 'string' && /^[^/\s]+\/\S+$/.test(value)) ? undefined : '<provider>/<model id>, or empty';
191
+ default:
192
+ return ((_a = spec.values) === null || _a === void 0 ? void 0 : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === void 0 ? void 0 : _b.map(one => JSON.stringify(one)).join(', ')}`;
193
+ }
194
+ }
195
+ TaAppUtil.check = check;
196
+ /** A value as the user reads it: on and off for a switch, the words of a choice (TaWebSettingSpec.shown). */
197
+ function shown(value, language, spec) {
198
+ var _a;
199
+ const named = (_a = spec === null || spec === void 0 ? void 0 : spec.shown) === null || _a === void 0 ? void 0 : _a[String(value)];
200
+ if (named) {
201
+ return TaLanguageUtil.pick(language, named);
202
+ }
203
+ if (typeof value === 'boolean') {
204
+ return TaLanguageUtil.pick(language, value ? words('on', '开', '開', 'オン') : words('off', '关', '關', 'オフ'));
205
+ }
206
+ if (value === '' || value === undefined || value === null) {
207
+ return TaLanguageUtil.pick(language, words('default', '默认', '預設', 'デフォルト'));
208
+ }
209
+ return String(value);
210
+ }
211
+ TaAppUtil.shown = shown;
212
+ })(TaAppUtil || (TaAppUtil = {}));
213
+ //# sourceMappingURL=app-protocol.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How much of the work the double hands out to tasks rather than doing it itself (Settings.delegate): the user's
3
+ * dial. Its role says it, and a guard of ta serve (DelegateExtension) holds it to it, by the mark of the level in
4
+ * the role: the tools that change files are off for it, and the others after a few steps of one run.
5
+ */
6
+ export type TaDelegateLevel = 'less' | 'balanced' | 'more';
7
+ export interface TaDelegateLimits {
8
+ /** Its tools that change files (edit, write) are off. */
9
+ noChanges: boolean;
10
+ /** Of its own tools (TaDelegateUtil.WORK_TOOLS), how many one run may call; undefined for as many as it likes. */
11
+ steps?: number;
12
+ }
13
+ export declare namespace TaDelegateUtil {
14
+ const LEVELS: readonly TaDelegateLevel[];
15
+ const DEFAULT: TaDelegateLevel;
16
+ /** pi's own tools, those with which a session works itself; the tools of extensions (start_task, the team's) are not. */
17
+ const WORK_TOOLS: readonly string[];
18
+ const CHANGE_TOOLS: readonly string[];
19
+ function parse(value: unknown): TaDelegateLevel;
20
+ /** In the role of the double: the guard reads which level it was opened with. */
21
+ function mark(level: TaDelegateLevel): string;
22
+ /** The level of a session's role, by its mark; undefined for a session that is not the double (a task, a chat). */
23
+ function levelOf(systemPrompt: string | undefined): TaDelegateLevel | undefined;
24
+ function limits(level: TaDelegateLevel): TaDelegateLimits;
25
+ /**
26
+ * Why a call of a tool is turned down, or undefined to let it run: `steps`, how many of its own tools the run
27
+ * called before it. What is turned down says what to do instead, for the model to read.
28
+ */
29
+ function refusal(level: TaDelegateLevel, tool: string, steps: number): string | undefined;
30
+ }
@@ -0,0 +1,52 @@
1
+ import { TaHostUtil } from './ta-extension-host.js';
2
+ export var TaDelegateUtil;
3
+ (function (TaDelegateUtil) {
4
+ TaDelegateUtil.LEVELS = ['less', 'balanced', 'more'];
5
+ TaDelegateUtil.DEFAULT = 'balanced';
6
+ /** pi's own tools, those with which a session works itself; the tools of extensions (start_task, the team's) are not. */
7
+ TaDelegateUtil.WORK_TOOLS = ['read', 'bash', 'powershell', 'edit', 'write', 'grep', 'find', 'ls'];
8
+ TaDelegateUtil.CHANGE_TOOLS = ['edit', 'write'];
9
+ const LIMITS = {
10
+ less: { noChanges: false },
11
+ balanced: { noChanges: true, steps: 6 },
12
+ more: { noChanges: true, steps: 2 },
13
+ };
14
+ function parse(value) {
15
+ return TaDelegateUtil.LEVELS.includes(value) ? value : TaDelegateUtil.DEFAULT;
16
+ }
17
+ TaDelegateUtil.parse = parse;
18
+ /** In the role of the double: the guard reads which level it was opened with. */
19
+ function mark(level) {
20
+ return `(delegate=${level})`;
21
+ }
22
+ TaDelegateUtil.mark = mark;
23
+ /** The level of a session's role, by its mark; undefined for a session that is not the double (a task, a chat). */
24
+ function levelOf(systemPrompt) {
25
+ const role = TaHostUtil.role(systemPrompt);
26
+ return TaDelegateUtil.LEVELS.find(level => role.includes(mark(level)));
27
+ }
28
+ TaDelegateUtil.levelOf = levelOf;
29
+ function limits(level) {
30
+ return LIMITS[level];
31
+ }
32
+ TaDelegateUtil.limits = limits;
33
+ /**
34
+ * Why a call of a tool is turned down, or undefined to let it run: `steps`, how many of its own tools the run
35
+ * called before it. What is turned down says what to do instead, for the model to read.
36
+ */
37
+ function refusal(level, tool, steps) {
38
+ if (!TaDelegateUtil.WORK_TOOLS.includes(tool)) {
39
+ return undefined;
40
+ }
41
+ const limit = LIMITS[level];
42
+ if (limit.noChanges && TaDelegateUtil.CHANGE_TOOLS.includes(tool)) {
43
+ return 'You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.';
44
+ }
45
+ if (limit.steps !== undefined && steps >= limit.steps) {
46
+ return 'You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.';
47
+ }
48
+ return undefined;
49
+ }
50
+ TaDelegateUtil.refusal = refusal;
51
+ })(TaDelegateUtil || (TaDelegateUtil = {}));
52
+ //# sourceMappingURL=delegate-protocol.js.map
@@ -0,0 +1,72 @@
1
+ /**
2
+ * A deployment of Ta: its gateway, its relay, or both, for one group of people (docs/design/ta-deploy.md). Inside and
3
+ * outside a company each have one; nothing passes between them.
4
+ */
5
+ /** What every service of a deployment answers, to anyone (it holds nothing secret). */
6
+ export declare const TA_WELL_KNOWN_PATH = "/.well-known/ta";
7
+ /** What a deployment says of itself at TA_WELL_KNOWN_PATH: where its services are. */
8
+ export interface TaDeployment {
9
+ v: 1;
10
+ /** What its people call it: TA_DEPLOYMENT_NAME. */
11
+ name?: string;
12
+ /** Where its gateway is (cloud-hosted Ta), and its relay (devices, rooms, links). */
13
+ gateway?: string;
14
+ relay?: string;
15
+ version?: string;
16
+ }
17
+ /**
18
+ * What a build of Ta comes with (`distribution.json` beside its `dist/`, docs/design/ta-deploy.md 3): the addresses of the
19
+ * deployment it is for, as defaults of the environment; and where its desktop app updates from.
20
+ */
21
+ export interface TaDistribution {
22
+ name?: string;
23
+ relay?: string;
24
+ gateway?: string;
25
+ updates?: {
26
+ base?: string;
27
+ key?: string;
28
+ };
29
+ /**
30
+ * What a device does to reach the deployment, told when its gateway does not answer: by language (`zh-CN`, `en`,
31
+ * `*` for any), one sentence, as "Turn on Remote Work in your company's VPN app". A gateway on an intranet has one.
32
+ */
33
+ reach?: Record<string, string>;
34
+ /**
35
+ * An address of the company's network that answers without its VPN (its sign-in, as `https://iam.example.com`): a
36
+ * device that reaches it while the gateway does not is the company's, told `reach`; one that reaches neither is
37
+ * someone else's, shown no deployment at all.
38
+ */
39
+ inside?: string;
40
+ }
41
+ /** The environment a deployment is told by: the variables a distribution gives defaults of. */
42
+ export interface TaDeploymentEnv {
43
+ TA_DEPLOYMENT_NAME?: string;
44
+ TA_GATEWAY_URL?: string;
45
+ TA_RELAY_URL?: string;
46
+ }
47
+ export declare class TaDeploymentError extends Error {
48
+ }
49
+ export declare namespace TaDeploymentUtil {
50
+ const DISTRIBUTION_FILE = "distribution.json";
51
+ /** An address of a service as it is kept: http(s), its origin and path, no trailing slash; undefined for what is not one. */
52
+ function url(value: unknown): string | undefined;
53
+ /**
54
+ * What a service answers: `own` its own part (its address, TA_PUBLIC_URL or the origin it was reached at), the rest
55
+ * from the environment.
56
+ */
57
+ function describe(env: TaDeploymentEnv, own: {
58
+ gateway?: string;
59
+ relay?: string;
60
+ }, version?: string): TaDeployment;
61
+ const HEADERS: Readonly<Record<string, string>>;
62
+ /** What a deployment said, kept to what is known; undefined for what is not one. */
63
+ function parse(value: unknown): TaDeployment | undefined;
64
+ /** Asks a service of a deployment what it is part of: rejects with what went wrong. */
65
+ function discover(address: string, timeoutMs?: number): Promise<TaDeployment>;
66
+ /** A distribution as its file holds it: throws on what it cannot be, for a build not to ship a wrong one. */
67
+ function distribution(value: unknown): TaDistribution;
68
+ /** The sentence of `reach` in `language` (`zh-CN`): that language, else another of its kind (`zh`), else any, else English. */
69
+ function reachIn(reach: Record<string, string> | undefined, language: string): string | undefined;
70
+ /** The environment a distribution gives: its defaults, for what `env` does not set already. */
71
+ function apply(distribution: TaDistribution, env: Record<string, string | undefined>): void;
72
+ }