@celljs/ta-protocol 4.9.1 → 4.11.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaSkillUse = exports.TaMessageContext = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
3
+ exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageContext = exports.TaSlashCommandUtil = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
4
4
  exports.TaServer = Symbol('TaServer');
5
5
  exports.TaClient = Symbol('TaClient');
6
6
  /** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
@@ -18,6 +18,14 @@ exports.TaErrorCode = {
18
18
  MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
19
19
  INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
20
20
  COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
21
+ /** Compacting found nothing to compact: the conversation is still short. */
22
+ NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
23
+ /** Compacting found nothing to compact: nothing came after the last compaction. */
24
+ ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
25
+ /** The session is answering or compacting, which has to end first. */
26
+ SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
27
+ /** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
28
+ CANCELLED: 'CELL_TA_CANCELLED',
21
29
  /** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
22
30
  NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
23
31
  /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
@@ -39,6 +47,16 @@ var TaErrorUtil;
39
47
  })(TaErrorUtil || (exports.TaErrorUtil = TaErrorUtil = {}));
40
48
  /** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
41
49
  exports.TA_RPC_ERROR_CODE = -32050;
50
+ var TaSlashCommandUtil;
51
+ (function (TaSlashCommandUtil) {
52
+ /** Its description in a language such as `zh-CN`: in that language, else in its first part (`zh`), else its own. */
53
+ function description(command, language) {
54
+ var _a, _b;
55
+ const { descriptions } = command;
56
+ return (_b = (_a = descriptions === null || descriptions === void 0 ? void 0 : descriptions[language]) !== null && _a !== void 0 ? _a : descriptions === null || descriptions === void 0 ? void 0 : descriptions[language.split('-')[0]]) !== null && _b !== void 0 ? _b : command.description;
57
+ }
58
+ TaSlashCommandUtil.description = description;
59
+ })(TaSlashCommandUtil || (exports.TaSlashCommandUtil = TaSlashCommandUtil = {}));
42
60
  /**
43
61
  * A message of the user may start with a `<context>` block: what the model reads besides the message
44
62
  * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
@@ -56,6 +74,126 @@ var TaMessageContext;
56
74
  }
57
75
  TaMessageContext.strip = strip;
58
76
  })(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
77
+ /**
78
+ * pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
79
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
80
+ */
81
+ var TaImageNote;
82
+ (function (TaImageNote) {
83
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
84
+ /** The text without the notes of its images: what the user sees of it. */
85
+ function strip(text) {
86
+ const lines = text.split('\n');
87
+ const kept = lines.filter(line => !NOTE.test(line.trim()));
88
+ if (kept.length === lines.length) {
89
+ return text;
90
+ }
91
+ return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
92
+ }
93
+ TaImageNote.strip = strip;
94
+ })(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
95
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
96
+ var TaImageSize;
97
+ (function (TaImageSize) {
98
+ /** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
99
+ const JPEG_BYTES = 256 * 1024;
100
+ function of(base64) {
101
+ var _a, _b, _c;
102
+ let bytes;
103
+ try {
104
+ // Whole groups of four characters only.
105
+ const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
106
+ bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
107
+ }
108
+ catch (_d) {
109
+ return undefined;
110
+ }
111
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== void 0 ? _a : gif(bytes)) !== null && _b !== void 0 ? _b : webp(bytes)) !== null && _c !== void 0 ? _c : jpeg(bytes);
112
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
113
+ }
114
+ TaImageSize.of = of;
115
+ function u16be(bytes, at) {
116
+ return (bytes[at] << 8) | bytes[at + 1];
117
+ }
118
+ function u16le(bytes, at) {
119
+ return bytes[at] | (bytes[at + 1] << 8);
120
+ }
121
+ function u24le(bytes, at) {
122
+ return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
123
+ }
124
+ function u32be(bytes, at) {
125
+ return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
126
+ }
127
+ function text(bytes, at, length) {
128
+ return String.fromCharCode(...bytes.subarray(at, at + length));
129
+ }
130
+ function png(bytes) {
131
+ return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
132
+ }
133
+ function gif(bytes) {
134
+ return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
135
+ }
136
+ function webp(bytes) {
137
+ if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
138
+ return undefined;
139
+ }
140
+ switch (text(bytes, 12, 4)) {
141
+ case 'VP8 ':
142
+ return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
143
+ case 'VP8L': {
144
+ const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
145
+ return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
146
+ }
147
+ case 'VP8X':
148
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
149
+ default:
150
+ return undefined;
151
+ }
152
+ }
153
+ function jpeg(bytes) {
154
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
155
+ return undefined;
156
+ }
157
+ let at = 2;
158
+ while (at + 9 < bytes.length) {
159
+ if (bytes[at] !== 0xff) {
160
+ return undefined;
161
+ }
162
+ const marker = bytes[at + 1];
163
+ // A start of frame (not DHT, JPG or DAC, which share the range) says the size.
164
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
165
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
166
+ }
167
+ at += 2 + u16be(bytes, at + 2);
168
+ }
169
+ return undefined;
170
+ }
171
+ })(TaImageSize || (exports.TaImageSize = TaImageSize = {}));
172
+ /**
173
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
174
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
175
+ */
176
+ var TaAgentSummary;
177
+ (function (TaAgentSummary) {
178
+ const START = /^\s*<conversation_history_summary>/;
179
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
180
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
181
+ function read(text) {
182
+ if (!START.test(text)) {
183
+ return undefined;
184
+ }
185
+ return text
186
+ .replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
187
+ .replace(/<\/?\w*$/, '')
188
+ .trim();
189
+ }
190
+ TaAgentSummary.read = read;
191
+ /** The text without the summary it starts with. */
192
+ function strip(text) {
193
+ return text.replace(BLOCK, '');
194
+ }
195
+ TaAgentSummary.strip = strip;
196
+ })(TaAgentSummary || (exports.TaAgentSummary = TaAgentSummary = {}));
59
197
  /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
60
198
  var TaSkillUse;
61
199
  (function (TaSkillUse) {
@@ -82,7 +82,8 @@ export interface TaWorkspaceServer {
82
82
  * A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
83
83
  * what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
84
84
  * no token, so that a page loads the files beside it with relative URLs; each `cwd` has its own
85
- * secret part. Pages are answered sandboxed: they run in an origin of their own, not the server's.
85
+ * secret part. A file outside `cwd` (an absolute path an agent wrote) has a secret part of its
86
+ * own that serves that file alone. Pages are answered sandboxed: they run in an origin of their own, not the server's.
86
87
  */
87
88
  fileUrl(path: string, cwd?: string): Promise<string>;
88
89
  /** Paths of files whose name matches `query` loosely, best first; ignored files are left out. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-protocol",
3
- "version": "4.9.1",
3
+ "version": "4.11.0",
4
4
  "description": "The protocol between ta serve and its clients",
5
5
  "homepage": "https://github.com/cellbang/cell",
6
6
  "bugs": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {},
32
32
  "peerDependencies": {
33
- "@earendil-works/pi-coding-agent": "^1.5.0",
34
- "@earendil-works/pi-ai": "^1.5.0"
33
+ "@earendil-works/pi-coding-agent": "^1.5.2",
34
+ "@earendil-works/pi-ai": "^1.5.2"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@earendil-works/pi-coding-agent": {
@@ -42,8 +42,8 @@
42
42
  }
43
43
  },
44
44
  "devDependencies": {
45
- "@earendil-works/pi-coding-agent": "^1.5.0",
46
- "@earendil-works/pi-ai": "^1.5.0"
45
+ "@earendil-works/pi-coding-agent": "^1.5.2",
46
+ "@earendil-works/pi-ai": "^1.5.2"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"