@celljs/ta-protocol 4.15.2 → 4.17.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 (67) hide show
  1. package/esm/common/app-protocol.d.ts +115 -0
  2. package/esm/common/app-protocol.js +199 -0
  3. package/esm/common/delegate-protocol.d.ts +30 -0
  4. package/esm/common/delegate-protocol.js +52 -0
  5. package/esm/common/deployment-protocol.d.ts +59 -0
  6. package/esm/common/deployment-protocol.js +135 -0
  7. package/esm/common/error-protocol.d.ts +42 -0
  8. package/esm/common/error-protocol.js +45 -0
  9. package/esm/common/event-protocol.d.ts +63 -0
  10. package/esm/common/event-protocol.js +2 -0
  11. package/esm/common/gateway-protocol.d.ts +54 -2
  12. package/esm/common/index.d.ts +9 -0
  13. package/esm/common/index.js +9 -0
  14. package/esm/common/location.d.ts +18 -1
  15. package/esm/common/location.js +51 -4
  16. package/esm/common/message-protocol.d.ts +95 -0
  17. package/esm/common/message-protocol.js +237 -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/remote-protocol.d.ts +12 -4
  27. package/esm/common/room-protocol.d.ts +7 -1
  28. package/esm/common/ta-extension-host.d.ts +31 -1
  29. package/esm/common/ta-extension-host.js +2 -0
  30. package/esm/common/ta-protocol.d.ts +50 -175
  31. package/esm/common/ta-protocol.js +0 -234
  32. package/esm/common/voice-protocol.d.ts +139 -0
  33. package/esm/common/voice-protocol.js +3 -0
  34. package/lib/common/app-protocol.d.ts +116 -0
  35. package/lib/common/app-protocol.js +202 -0
  36. package/lib/common/delegate-protocol.d.ts +31 -0
  37. package/lib/common/delegate-protocol.js +55 -0
  38. package/lib/common/deployment-protocol.d.ts +60 -0
  39. package/lib/common/deployment-protocol.js +139 -0
  40. package/lib/common/error-protocol.d.ts +43 -0
  41. package/lib/common/error-protocol.js +48 -0
  42. package/lib/common/event-protocol.d.ts +64 -0
  43. package/lib/common/event-protocol.js +3 -0
  44. package/lib/common/gateway-protocol.d.ts +54 -2
  45. package/lib/common/index.d.ts +9 -0
  46. package/lib/common/index.js +9 -0
  47. package/lib/common/location.d.ts +18 -1
  48. package/lib/common/location.js +51 -4
  49. package/lib/common/message-protocol.d.ts +96 -0
  50. package/lib/common/message-protocol.js +240 -0
  51. package/lib/common/page-protocol.d.ts +57 -0
  52. package/lib/common/page-protocol.js +15 -0
  53. package/lib/common/path-map.d.ts +25 -0
  54. package/lib/common/path-map.js +130 -0
  55. package/lib/common/presence-protocol.js +7 -7
  56. package/lib/common/redactor.d.ts +12 -0
  57. package/lib/common/redactor.js +49 -11
  58. package/lib/common/relay-protocol.d.ts +20 -0
  59. package/lib/common/remote-protocol.d.ts +12 -4
  60. package/lib/common/room-protocol.d.ts +7 -1
  61. package/lib/common/ta-extension-host.d.ts +31 -1
  62. package/lib/common/ta-extension-host.js +3 -1
  63. package/lib/common/ta-protocol.d.ts +50 -175
  64. package/lib/common/ta-protocol.js +1 -235
  65. package/lib/common/voice-protocol.d.ts +140 -0
  66. package/lib/common/voice-protocol.js +6 -0
  67. package/package.json +1 -1
@@ -0,0 +1,115 @@
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
+ * that one waits for a confirmation on the user's screen, which is not there yet, so the catalog refuses it.
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
+ run(input: Record<string, unknown>, context: TaAppCommandContext): Promise<TaAppCommandResult>;
58
+ }
59
+ /** Who asks for an action: the run of a conversation (each who asked it), or one principal (a tap on a page). */
60
+ export interface TaAppRunOptions {
61
+ sessionFile?: string;
62
+ principal?: string;
63
+ }
64
+ /**
65
+ * The catalog of what can be done to Ta without its pages (docs/design/ta-app-use.md 2): change a setting, pin a
66
+ * conversation, turn an extension off. The buttons of the pages change the same data, so a page shows at once
67
+ * what an action did, and an agent does what the user can without moving a cursor.
68
+ */
69
+ export interface TaHostCommands {
70
+ list(): TaAppCommandInfo[];
71
+ /**
72
+ * Runs an action for who asked (TaAppRunOptions): each must be let to do its `action`. Throws with what is wrong:
73
+ * no such action, not let to, an input it does not take, a `danger` one the user did not agree to on their screen.
74
+ */
75
+ run(id: string, input?: Record<string, unknown>, options?: TaAppRunOptions): Promise<TaAppCommandResult>;
76
+ /** Adds an action, gone with the function returned or when the package stops. */
77
+ register(command: TaAppCommand): () => void;
78
+ }
79
+ /** The tools of ta-app-use, the catalog and the screen: a call's front has them too. */
80
+ export declare const TA_APP_TOOLS: readonly ['app_commands', 'app_run', 'app_look', 'app_go', 'app_do'];
81
+ /** Where the web client keeps its settings (TaState `user`): in the data of packages, under this name and key. */
82
+ export declare const TA_WEB_SETTINGS_DATA: {
83
+ readonly name: '@celljs/ta-web';
84
+ readonly key: 'settings';
85
+ };
86
+ /** Where the web client keeps the conversations pinned to the top of its lists: their session files, and keys of folders. */
87
+ export declare const TA_CHAT_PINNED: {
88
+ readonly name: '@celljs/ta-web';
89
+ readonly key: 'chat.pinned';
90
+ };
91
+ /** A setting of the web client an action may change (settings.set), as the settings page offers it. */
92
+ export interface TaWebSettingSpec {
93
+ key: string;
94
+ type: 'boolean' | 'enum' | 'number' | 'string' | 'model';
95
+ /** The values it may be, for `enum` and `number`. */
96
+ values?: readonly (string | number)[];
97
+ default: boolean | number | string;
98
+ /** For the model, in English. */
99
+ what: string;
100
+ title: Readonly<Record<TaLanguage, string>>;
101
+ /** What the user calls its values, by value, where the value itself is a word of the code. */
102
+ shown?: Readonly<Record<string, Readonly<Record<TaLanguage, string>>>>;
103
+ }
104
+ /**
105
+ * The settings of the web client (Settings of ta-web) an agent may change: those the settings page shows with a
106
+ * switch or a choice. Not `trustedDomains` (links open without asking), nor `navigation` and `builtinsOff`, which
107
+ * have pages and actions of their own. The tests of ta-web hold these to its defaults and choices.
108
+ */
109
+ export declare const TA_WEB_SETTINGS: readonly TaWebSettingSpec[];
110
+ export declare namespace TaAppUtil {
111
+ /** `value` for the setting, or why not: a value of its type and among its values. */
112
+ function check(spec: TaWebSettingSpec, value: unknown): string | undefined;
113
+ /** A value as the user reads it: on and off for a switch, the words of a choice (TaWebSettingSpec.shown). */
114
+ function shown(value: unknown, language: TaLanguage, spec?: TaWebSettingSpec): string;
115
+ }
@@ -0,0 +1,199 @@
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: 'keepAliveMinutes',
135
+ type: 'number',
136
+ values: [1, 5, 15, 30],
137
+ default: 5,
138
+ what: 'How long an extension started on open keeps running once left, in minutes.',
139
+ title: words('Keep extensions running', '扩展离开后保留', '擴充功能離開後保留', '拡張機能を保持'),
140
+ },
141
+ {
142
+ key: 'chatFoldDays',
143
+ type: 'number',
144
+ values: [3, 7, 30, 0],
145
+ default: 7,
146
+ what: 'Conversations not updated for these days fold at the end of the list; 0 for none.',
147
+ title: words('Fold old conversations', '折叠旧对话', '摺疊舊對話', '古い会話を折りたたむ'),
148
+ },
149
+ {
150
+ key: 'chatArchiveDays',
151
+ type: 'number',
152
+ values: [30, 90, 365, 0],
153
+ default: 30,
154
+ what: 'Conversations not updated for these days are archived (out of the list, found by search); 0 for none.',
155
+ title: words('Archive old conversations', '归档旧对话', '歸檔舊對話', '古い会話をアーカイブ'),
156
+ },
157
+ {
158
+ key: 'recentShots',
159
+ type: 'boolean',
160
+ default: true,
161
+ what: 'The screenshot just taken is offered above the message box, once.',
162
+ title: words('Offer recent screenshots', '提示刚截的图', '提示剛截的圖', '撮ったばかりのスクリーンショットを提案'),
163
+ },
164
+ ];
165
+ export var TaAppUtil;
166
+ (function (TaAppUtil) {
167
+ /** `value` for the setting, or why not: a value of its type and among its values. */
168
+ function check(spec, value) {
169
+ var _a, _b;
170
+ switch (spec.type) {
171
+ case 'boolean':
172
+ return typeof value === 'boolean' ? undefined : 'true or false';
173
+ case 'string':
174
+ return typeof value === 'string' ? undefined : 'a string';
175
+ case 'model':
176
+ return value === '' || (typeof value === 'string' && /^[^/\s]+\/\S+$/.test(value)) ? undefined : '<provider>/<model id>, or empty';
177
+ default:
178
+ 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(', ')}`;
179
+ }
180
+ }
181
+ TaAppUtil.check = check;
182
+ /** A value as the user reads it: on and off for a switch, the words of a choice (TaWebSettingSpec.shown). */
183
+ function shown(value, language, spec) {
184
+ var _a;
185
+ const named = (_a = spec === null || spec === void 0 ? void 0 : spec.shown) === null || _a === void 0 ? void 0 : _a[String(value)];
186
+ if (named) {
187
+ return TaLanguageUtil.pick(language, named);
188
+ }
189
+ if (typeof value === 'boolean') {
190
+ return TaLanguageUtil.pick(language, value ? words('on', '开', '開', 'オン') : words('off', '关', '關', 'オフ'));
191
+ }
192
+ if (value === '' || value === undefined || value === null) {
193
+ return TaLanguageUtil.pick(language, words('default', '默认', '預設', 'デフォルト'));
194
+ }
195
+ return String(value);
196
+ }
197
+ TaAppUtil.shown = shown;
198
+ })(TaAppUtil || (TaAppUtil = {}));
199
+ //# 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,59 @@
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
+ /** The environment a deployment is told by: the variables a distribution gives defaults of. */
31
+ export interface TaDeploymentEnv {
32
+ TA_DEPLOYMENT_NAME?: string;
33
+ TA_GATEWAY_URL?: string;
34
+ TA_RELAY_URL?: string;
35
+ }
36
+ export declare class TaDeploymentError extends Error {
37
+ }
38
+ export declare namespace TaDeploymentUtil {
39
+ const DISTRIBUTION_FILE = "distribution.json";
40
+ /** An address of a service as it is kept: http(s), its origin and path, no trailing slash; undefined for what is not one. */
41
+ function url(value: unknown): string | undefined;
42
+ /**
43
+ * What a service answers: `own` its own part (its address, TA_PUBLIC_URL or the origin it was reached at), the rest
44
+ * from the environment.
45
+ */
46
+ function describe(env: TaDeploymentEnv, own: {
47
+ gateway?: string;
48
+ relay?: string;
49
+ }, version?: string): TaDeployment;
50
+ const HEADERS: Readonly<Record<string, string>>;
51
+ /** What a deployment said, kept to what is known; undefined for what is not one. */
52
+ function parse(value: unknown): TaDeployment | undefined;
53
+ /** Asks a service of a deployment what it is part of: rejects with what went wrong. */
54
+ function discover(address: string, timeoutMs?: number): Promise<TaDeployment>;
55
+ /** A distribution as its file holds it: throws on what it cannot be, for a build not to ship a wrong one. */
56
+ function distribution(value: unknown): TaDistribution;
57
+ /** The environment a distribution gives: its defaults, for what `env` does not set already. */
58
+ function apply(distribution: TaDistribution, env: Record<string, string | undefined>): void;
59
+ }
@@ -0,0 +1,135 @@
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 const TA_WELL_KNOWN_PATH = '/.well-known/ta';
7
+ export class TaDeploymentError extends Error {
8
+ }
9
+ export var TaDeploymentUtil;
10
+ (function (TaDeploymentUtil) {
11
+ TaDeploymentUtil.DISTRIBUTION_FILE = 'distribution.json';
12
+ /** An address of a service as it is kept: http(s), its origin and path, no trailing slash; undefined for what is not one. */
13
+ function url(value) {
14
+ if (typeof value !== 'string' || !value.trim()) {
15
+ return undefined;
16
+ }
17
+ try {
18
+ const parsed = new URL(value.trim());
19
+ if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
20
+ return undefined;
21
+ }
22
+ return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, '');
23
+ }
24
+ catch (_a) {
25
+ return undefined;
26
+ }
27
+ }
28
+ TaDeploymentUtil.url = url;
29
+ function name(value) {
30
+ return typeof value === 'string' && value.trim() ? value.trim().slice(0, 80) : undefined;
31
+ }
32
+ /**
33
+ * What a service answers: `own` its own part (its address, TA_PUBLIC_URL or the origin it was reached at), the rest
34
+ * from the environment.
35
+ */
36
+ function describe(env, own, version) {
37
+ var _a, _b;
38
+ const gateway = (_a = url(own.gateway)) !== null && _a !== void 0 ? _a : url(env.TA_GATEWAY_URL);
39
+ const relay = (_b = url(own.relay)) !== null && _b !== void 0 ? _b : url(env.TA_RELAY_URL);
40
+ const called = name(env.TA_DEPLOYMENT_NAME);
41
+ return { v: 1, ...(called ? { name: called } : {}), ...(gateway ? { gateway } : {}), ...(relay ? { relay } : {}), ...(version ? { version } : {}) };
42
+ }
43
+ TaDeploymentUtil.describe = describe;
44
+ TaDeploymentUtil.HEADERS = {
45
+ 'content-type': 'application/json',
46
+ 'access-control-allow-origin': '*',
47
+ 'cache-control': 'no-store',
48
+ };
49
+ /** What a deployment said, kept to what is known; undefined for what is not one. */
50
+ function parse(value) {
51
+ const given = value;
52
+ if (!given || typeof given !== 'object' || given.v !== 1) {
53
+ return undefined;
54
+ }
55
+ const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
56
+ const version = name(given.version);
57
+ return version ? { ...deployment, version } : deployment;
58
+ }
59
+ TaDeploymentUtil.parse = parse;
60
+ /** Asks a service of a deployment what it is part of: rejects with what went wrong. */
61
+ async function discover(address, timeoutMs = 6000) {
62
+ const base = url(address);
63
+ if (!base) {
64
+ throw new TaDeploymentError(`${address} is not an address of http or https.`);
65
+ }
66
+ const controller = new AbortController();
67
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
68
+ try {
69
+ const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: 'follow' });
70
+ if (!response.ok) {
71
+ throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
72
+ }
73
+ const deployment = parse(await response.json().catch(() => undefined));
74
+ if (!deployment || (!deployment.gateway && !deployment.relay)) {
75
+ throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
76
+ }
77
+ return deployment;
78
+ }
79
+ catch (error) {
80
+ if ((error === null || error === void 0 ? void 0 : error.name) === 'AbortError') {
81
+ throw new TaDeploymentError(`${base} did not answer in time.`);
82
+ }
83
+ throw error;
84
+ }
85
+ finally {
86
+ clearTimeout(timer);
87
+ }
88
+ }
89
+ TaDeploymentUtil.discover = discover;
90
+ /** A distribution as its file holds it: throws on what it cannot be, for a build not to ship a wrong one. */
91
+ function distribution(value) {
92
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
93
+ throw new TaDeploymentError(`${TaDeploymentUtil.DISTRIBUTION_FILE} holds a JSON object.`);
94
+ }
95
+ const given = value;
96
+ const result = {};
97
+ if (given.name !== undefined) {
98
+ result.name = name(given.name);
99
+ }
100
+ for (const key of ['relay', 'gateway']) {
101
+ if (given[key] !== undefined) {
102
+ const address = url(given[key]);
103
+ if (!address) {
104
+ throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil.DISTRIBUTION_FILE} is not an address of http or https.`);
105
+ }
106
+ result[key] = address;
107
+ }
108
+ }
109
+ if (given.updates !== undefined) {
110
+ const updates = given.updates;
111
+ const base = url(updates === null || updates === void 0 ? void 0 : updates.base);
112
+ if (!base && (updates === null || updates === void 0 ? void 0 : updates.base) !== undefined) {
113
+ throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil.DISTRIBUTION_FILE} is not an address of http or https.`);
114
+ }
115
+ const key = typeof (updates === null || updates === void 0 ? void 0 : updates.key) === 'string' && updates.key.includes('PUBLIC KEY') ? updates.key : undefined;
116
+ if ((updates === null || updates === void 0 ? void 0 : updates.key) !== undefined && !key) {
117
+ throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil.DISTRIBUTION_FILE} is a public key in PEM.`);
118
+ }
119
+ result.updates = { ...(base ? { base } : {}), ...(key ? { key } : {}) };
120
+ }
121
+ return result;
122
+ }
123
+ TaDeploymentUtil.distribution = distribution;
124
+ /** The environment a distribution gives: its defaults, for what `env` does not set already. */
125
+ function apply(distribution, env) {
126
+ const defaults = { TA_DEPLOYMENT_NAME: distribution.name, TA_RELAY_URL: distribution.relay, TA_GATEWAY_URL: distribution.gateway };
127
+ for (const [key, value] of Object.entries(defaults)) {
128
+ if (value && !env[key]) {
129
+ env[key] = value;
130
+ }
131
+ }
132
+ }
133
+ TaDeploymentUtil.apply = apply;
134
+ })(TaDeploymentUtil || (TaDeploymentUtil = {}));
135
+ //# sourceMappingURL=deployment-protocol.js.map
@@ -0,0 +1,42 @@
1
+ /** The stable `code` of each failure of a {@link TaServer} call. */
2
+ export declare const TaErrorCode: {
3
+ readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
4
+ readonly SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED';
5
+ readonly TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS';
6
+ readonly MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT';
7
+ readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
8
+ readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
9
+ readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
10
+ /** Compacting found nothing to compact: the conversation is still short. */
11
+ readonly NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT';
12
+ /** Compacting found nothing to compact: nothing came after the last compaction. */
13
+ readonly ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED';
14
+ /** The session is answering or compacting, which has to end first. */
15
+ readonly SESSION_BUSY: 'CELL_TA_SESSION_BUSY';
16
+ /** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
17
+ readonly CANCELLED: 'CELL_TA_CANCELLED';
18
+ /** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
19
+ readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
20
+ /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
21
+ readonly ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED';
22
+ /** Behind a gateway: more messages a minute than one may send; try again in a moment. */
23
+ readonly RATE_LIMITED: 'CELL_TA_RATE_LIMITED';
24
+ /** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
25
+ readonly FORBIDDEN: 'CELL_TA_FORBIDDEN';
26
+ /** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
27
+ readonly LIMIT: 'CELL_TA_LIMIT';
28
+ /** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
29
+ readonly CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST';
30
+ };
31
+ export type TaErrorCode = (typeof TaErrorCode)[keyof typeof TaErrorCode];
32
+ export declare namespace TaErrorUtil {
33
+ /** The {@link TaErrorCode} of a failure: `code` of the client's error, `data.code` of the server's own, called in its process. */
34
+ function code(error: unknown): string | undefined;
35
+ }
36
+ /** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
37
+ export declare const TA_RPC_ERROR_CODE = -32050;
38
+ export interface TaErrorData {
39
+ code: TaErrorCode;
40
+ /** One sentence on what to do about it. */
41
+ hint: string;
42
+ }