@x-tech-laboratories/x-app 0.133.0 → 0.135.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.
- package/README.md +9 -7
- package/dist/app/web/app_page.d.ts +4 -1
- package/dist/app/web/app_page.js +11 -5
- package/dist/app/web/page_dashboards.d.ts +7 -1
- package/dist/app/web/page_dashboards.js +12 -1
- package/dist/config_watch.d.ts +1 -15
- package/dist/config_watch.js +2 -75
- package/dist/cron.d.ts +1 -34
- package/dist/cron.js +2 -187
- package/dist/log.d.ts +1 -30
- package/dist/log.js +2 -85
- package/dist/plugin_folder.d.ts +1 -24
- package/dist/plugin_folder.js +2 -107
- package/dist/plugins.d.ts +1 -138
- package/dist/plugins.js +2 -346
- package/dist/python_text.d.ts +1 -19
- package/dist/python_text.js +2 -363
- package/dist/server/agents/agent.d.ts +1 -27
- package/dist/server/agents/agent.js +2 -16
- package/dist/server/agents/connection.d.ts +1 -63
- package/dist/server/agents/connection.js +2 -266
- package/dist/server/agents/hub.d.ts +1 -110
- package/dist/server/agents/hub.js +2 -327
- package/dist/sql.d.ts +1 -27
- package/dist/sql.js +2 -61
- package/package.json +2 -4
package/dist/python_text.js
CHANGED
|
@@ -1,363 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
// format specs write (fixed decimals rounding an exact tie to even, thousands grouped), str.splitlines(), str.split(),
|
|
4
|
-
// str.partition(), int() and float() of text, fnmatch globs and named groups in regular expressions.
|
|
5
|
-
// ── Numbers ──────────────────────────────────────────────────────────────────
|
|
6
|
-
// A number with fixed decimals as Python's "{:.Nf}" writes it, rounding an exact tie to even where toFixed rounds up.
|
|
7
|
-
export function format_fixed(value, digits) {
|
|
8
|
-
if (!Number.isFinite(value))
|
|
9
|
-
return value > 0 ? "inf" : value < 0 ? "-inf" : "nan";
|
|
10
|
-
const exact = Math.abs(value).toFixed(Math.min(100, digits + 40));
|
|
11
|
-
const point = exact.indexOf(".");
|
|
12
|
-
const tail = exact.slice(point + 1 + digits);
|
|
13
|
-
if (!/^50*$/.test(tail))
|
|
14
|
-
return value.toFixed(digits);
|
|
15
|
-
const kept = exact.slice(0, point + 1 + digits).replace(/\.$/, "");
|
|
16
|
-
const last_digit = Number(kept.replace(".", "").slice(-1));
|
|
17
|
-
if (last_digit % 2 === 0)
|
|
18
|
-
return (value < 0 ? "-" : "") + kept;
|
|
19
|
-
return value.toFixed(digits);
|
|
20
|
-
}
|
|
21
|
-
// A number as Python's "{:,.Nf}" writes it: fixed decimals with commas between thousands.
|
|
22
|
-
export function format_grouped(value, digits) {
|
|
23
|
-
const text = format_fixed(value, digits);
|
|
24
|
-
const [whole, fraction] = text.split(".");
|
|
25
|
-
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
26
|
-
return fraction === undefined ? grouped : `${grouped}.${fraction}`;
|
|
27
|
-
}
|
|
28
|
-
// A number rounded as Python's round(value, digits) does, an exact tie going to even.
|
|
29
|
-
export function round_half_even(value, digits = 0) {
|
|
30
|
-
return Number(format_fixed(value, digits));
|
|
31
|
-
}
|
|
32
|
-
// A float as Python's str() and repr() write it: the shortest round-trip digits, "42.0" for a whole number, and an
|
|
33
|
-
// exponent such as "1e-05" below 1e-4 or from 1e16.
|
|
34
|
-
export function python_float_repr(value) {
|
|
35
|
-
if (Number.isNaN(value))
|
|
36
|
-
return "nan";
|
|
37
|
-
if (!Number.isFinite(value))
|
|
38
|
-
return value > 0 ? "inf" : "-inf";
|
|
39
|
-
if (value === 0)
|
|
40
|
-
return Object.is(value, -0) ? "-0.0" : "0.0";
|
|
41
|
-
const [mantissa, exponent_text] = value.toExponential().split("e");
|
|
42
|
-
const exponent = Number(exponent_text);
|
|
43
|
-
const negative = mantissa.startsWith("-");
|
|
44
|
-
const digits = mantissa.replace("-", "").replace(".", "");
|
|
45
|
-
const sign = negative ? "-" : "";
|
|
46
|
-
if (exponent < -4 || exponent >= 16) {
|
|
47
|
-
const body = digits.length > 1 ? `${digits[0]}.${digits.slice(1)}` : digits;
|
|
48
|
-
return `${sign}${body}e${exponent < 0 ? "-" : "+"}${String(Math.abs(exponent)).padStart(2, "0")}`;
|
|
49
|
-
}
|
|
50
|
-
if (exponent < 0)
|
|
51
|
-
return `${sign}0.${"0".repeat(-exponent - 1)}${digits}`;
|
|
52
|
-
const whole = digits.slice(0, exponent + 1).padEnd(exponent + 1, "0");
|
|
53
|
-
const fraction = digits.slice(exponent + 1);
|
|
54
|
-
return `${sign}${whole}.${fraction || "0"}`;
|
|
55
|
-
}
|
|
56
|
-
// ── Splitting ────────────────────────────────────────────────────────────────
|
|
57
|
-
// Lines as Python's str.splitlines() gives them: no line endings, and no empty last line after a final newline.
|
|
58
|
-
export function split_lines(text) {
|
|
59
|
-
if (text === "")
|
|
60
|
-
return [];
|
|
61
|
-
// oxlint-disable-next-line no-control-regex
|
|
62
|
-
const lines = text.split(/\r\n|[\n\r\v\f\x1c-\x1e\x85\u2028\u2029]/);
|
|
63
|
-
if (lines.at(-1) === "")
|
|
64
|
-
lines.pop();
|
|
65
|
-
return lines;
|
|
66
|
-
}
|
|
67
|
-
// Words as Python's str.split() with no separator gives them; with `max_split`, the rest stays whole in the last word.
|
|
68
|
-
export function split_words(text, max_split = -1) {
|
|
69
|
-
if (max_split < 0)
|
|
70
|
-
return text.split(/\s+/).filter((word) => word !== "");
|
|
71
|
-
const words = [];
|
|
72
|
-
let rest = text.replace(/^\s+/, "");
|
|
73
|
-
while (rest !== "" && words.length < max_split) {
|
|
74
|
-
const match = /\s+/.exec(rest);
|
|
75
|
-
if (match === null)
|
|
76
|
-
break;
|
|
77
|
-
words.push(rest.slice(0, match.index));
|
|
78
|
-
rest = rest.slice(match.index + match[0].length);
|
|
79
|
-
}
|
|
80
|
-
if (rest !== "")
|
|
81
|
-
words.push(words.length < max_split ? rest.replace(/\s+$/, "") : rest);
|
|
82
|
-
return words;
|
|
83
|
-
}
|
|
84
|
-
// Python's str.partition: the text before the first separator, the separator, and the rest.
|
|
85
|
-
export function partition(text, separator) {
|
|
86
|
-
const index = text.indexOf(separator);
|
|
87
|
-
if (index === -1)
|
|
88
|
-
return [text, "", ""];
|
|
89
|
-
return [text.slice(0, index), separator, text.slice(index + separator.length)];
|
|
90
|
-
}
|
|
91
|
-
// ── Numbers ──────────────────────────────────────────────────────────────────
|
|
92
|
-
// A whole number as Python's int() reads text, throwing on anything else.
|
|
93
|
-
export function parse_int(text) {
|
|
94
|
-
if (typeof text === "number") {
|
|
95
|
-
if (!Number.isFinite(text))
|
|
96
|
-
throw new Error(`cannot convert float ${text} to integer`);
|
|
97
|
-
return Math.trunc(text);
|
|
98
|
-
}
|
|
99
|
-
const value = String(text);
|
|
100
|
-
if (!/^\s*[+-]?\d+(_\d+)*\s*$/.test(value))
|
|
101
|
-
throw new Error(`invalid literal for int() with base 10: '${value}'`);
|
|
102
|
-
return Number(value.trim().replaceAll("_", ""));
|
|
103
|
-
}
|
|
104
|
-
// A number as Python's float() reads text, throwing on anything else.
|
|
105
|
-
export function parse_float(text) {
|
|
106
|
-
if (typeof text === "number")
|
|
107
|
-
return text;
|
|
108
|
-
const value = String(text);
|
|
109
|
-
const trimmed = value.trim();
|
|
110
|
-
if (/^[+-]?(inf|infinity)$/i.test(trimmed))
|
|
111
|
-
return trimmed.startsWith("-") ? -Infinity : Infinity;
|
|
112
|
-
if (/^[+-]?nan$/i.test(trimmed))
|
|
113
|
-
return Number.NaN;
|
|
114
|
-
if (!/^[+-]?(\d+(_\d+)*(\.(\d+(_\d+)*)?)?|\.\d+(_\d+)*)([eE][+-]?\d+)?$/.test(trimmed)) {
|
|
115
|
-
throw new Error(`could not convert string to float: '${value}'`);
|
|
116
|
-
}
|
|
117
|
-
return Number(trimmed.replaceAll("_", ""));
|
|
118
|
-
}
|
|
119
|
-
// Python's int(), or null where it would raise.
|
|
120
|
-
export function int_or_null(text) {
|
|
121
|
-
try {
|
|
122
|
-
return parse_int(text);
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// Python's float(), or null where it would raise.
|
|
129
|
-
export function float_or_null(text) {
|
|
130
|
-
try {
|
|
131
|
-
return parse_float(text);
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// ── Patterns ─────────────────────────────────────────────────────────────────
|
|
138
|
-
// Whether a name matches a shell-style pattern as Python's fnmatch.fnmatch does on POSIX: *, ?, [seq] and [!seq],
|
|
139
|
-
// case-sensitive, the whole name.
|
|
140
|
-
export function fnmatch(name, pattern) {
|
|
141
|
-
let source = "";
|
|
142
|
-
let index = 0;
|
|
143
|
-
while (index < pattern.length) {
|
|
144
|
-
const character = pattern[index++];
|
|
145
|
-
if (character === "*")
|
|
146
|
-
source += "[\\s\\S]*";
|
|
147
|
-
else if (character === "?")
|
|
148
|
-
source += "[\\s\\S]";
|
|
149
|
-
else if (character === "[") {
|
|
150
|
-
let end = index;
|
|
151
|
-
if (end < pattern.length && pattern[end] === "!")
|
|
152
|
-
end++;
|
|
153
|
-
if (end < pattern.length && pattern[end] === "]")
|
|
154
|
-
end++;
|
|
155
|
-
while (end < pattern.length && pattern[end] !== "]")
|
|
156
|
-
end++;
|
|
157
|
-
if (end >= pattern.length) {
|
|
158
|
-
source += "\\[";
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
let set = pattern.slice(index, end).replaceAll("\\", "\\\\");
|
|
162
|
-
index = end + 1;
|
|
163
|
-
if (set.startsWith("!"))
|
|
164
|
-
set = `^${set.slice(1)}`;
|
|
165
|
-
else if (set.startsWith("^"))
|
|
166
|
-
set = `\\${set}`;
|
|
167
|
-
source += `[${set}]`;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else
|
|
171
|
-
source += character.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
172
|
-
}
|
|
173
|
-
return new RegExp(`^(?:${source})$`).test(name);
|
|
174
|
-
}
|
|
175
|
-
// A Python regular expression as a JavaScript one: named groups (?P<name>...) and backreferences (?P=name) rewritten.
|
|
176
|
-
export function python_regex(pattern, flags = "") {
|
|
177
|
-
return new RegExp(pattern.replace(/\(\?P<([A-Za-z_]\w*)>/g, "(?<$1>").replace(/\(\?P=([A-Za-z_]\w*)\)/g, "\\k<$1>"), flags);
|
|
178
|
-
}
|
|
179
|
-
// ── repr ─────────────────────────────────────────────────────────────────────
|
|
180
|
-
// A string as Python's repr() writes it: single quotes unless the text holds one and no double quote.
|
|
181
|
-
function string_repr(text) {
|
|
182
|
-
const quote = text.includes("'") && !text.includes('"') ? '"' : "'";
|
|
183
|
-
let body = "";
|
|
184
|
-
for (const character of text) {
|
|
185
|
-
const code = character.codePointAt(0);
|
|
186
|
-
if (character === "\\")
|
|
187
|
-
body += "\\\\";
|
|
188
|
-
else if (character === quote)
|
|
189
|
-
body += `\\${quote}`;
|
|
190
|
-
else if (character === "\n")
|
|
191
|
-
body += "\\n";
|
|
192
|
-
else if (character === "\r")
|
|
193
|
-
body += "\\r";
|
|
194
|
-
else if (character === "\t")
|
|
195
|
-
body += "\\t";
|
|
196
|
-
else if (code < 0x20 || code === 0x7f)
|
|
197
|
-
body += `\\x${code.toString(16).padStart(2, "0")}`;
|
|
198
|
-
else
|
|
199
|
-
body += character;
|
|
200
|
-
}
|
|
201
|
-
return quote + body + quote;
|
|
202
|
-
}
|
|
203
|
-
// Any value as Python's repr() writes it; numbers print as JavaScript does, so a whole float loses its ".0".
|
|
204
|
-
export function python_repr(value) {
|
|
205
|
-
if (value === null || value === undefined)
|
|
206
|
-
return "None";
|
|
207
|
-
if (value === true)
|
|
208
|
-
return "True";
|
|
209
|
-
if (value === false)
|
|
210
|
-
return "False";
|
|
211
|
-
if (typeof value === "string")
|
|
212
|
-
return string_repr(value);
|
|
213
|
-
if (typeof value === "number") {
|
|
214
|
-
if (Number.isNaN(value))
|
|
215
|
-
return "nan";
|
|
216
|
-
if (!Number.isFinite(value))
|
|
217
|
-
return value > 0 ? "inf" : "-inf";
|
|
218
|
-
return String(value);
|
|
219
|
-
}
|
|
220
|
-
if (Array.isArray(value))
|
|
221
|
-
return `[${value.map(python_repr).join(", ")}]`;
|
|
222
|
-
if (value instanceof Set)
|
|
223
|
-
return value.size === 0 ? "set()" : `{${[...value].map(python_repr).join(", ")}}`;
|
|
224
|
-
if (value instanceof Date)
|
|
225
|
-
return `datetime(${value.toISOString()})`;
|
|
226
|
-
if (typeof value === "object") {
|
|
227
|
-
return `{${Object.entries(value).map(([key, item]) => `${string_repr(key)}: ${python_repr(item)}`).join(", ")}}`;
|
|
228
|
-
}
|
|
229
|
-
return String(value);
|
|
230
|
-
}
|
|
231
|
-
// ── json.dumps ───────────────────────────────────────────────────────────────
|
|
232
|
-
function ascii_string(text) {
|
|
233
|
-
return JSON.stringify(text).replace(/[\u007f-]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
234
|
-
}
|
|
235
|
-
// JSON as Python's json.dumps writes it: ", " and ": " separators, non-ASCII escaped, keys in insertion order unless
|
|
236
|
-
// `sort_keys`, so settings the Python app stored compare equal.
|
|
237
|
-
export function python_dumps(value, sort_keys = false) {
|
|
238
|
-
if (value === null || value === undefined)
|
|
239
|
-
return "null";
|
|
240
|
-
if (typeof value === "string")
|
|
241
|
-
return ascii_string(value);
|
|
242
|
-
if (typeof value === "number") {
|
|
243
|
-
if (Number.isNaN(value))
|
|
244
|
-
return "NaN";
|
|
245
|
-
if (!Number.isFinite(value))
|
|
246
|
-
return value > 0 ? "Infinity" : "-Infinity";
|
|
247
|
-
return JSON.stringify(value);
|
|
248
|
-
}
|
|
249
|
-
if (typeof value === "boolean")
|
|
250
|
-
return value ? "true" : "false";
|
|
251
|
-
if (value instanceof Date)
|
|
252
|
-
return ascii_string(value.toISOString());
|
|
253
|
-
if (Array.isArray(value))
|
|
254
|
-
return `[${value.map((item) => python_dumps(item, sort_keys)).join(", ")}]`;
|
|
255
|
-
if (typeof value === "object") {
|
|
256
|
-
const keys = Object.keys(value).filter((key) => value[key] !== undefined);
|
|
257
|
-
if (sort_keys)
|
|
258
|
-
keys.sort();
|
|
259
|
-
return `{${keys.map((key) => `${ascii_string(key)}: ${python_dumps(value[key], sort_keys)}`).join(", ")}}`;
|
|
260
|
-
}
|
|
261
|
-
return ascii_string(String(value));
|
|
262
|
-
}
|
|
263
|
-
// ── str() ────────────────────────────────────────────────────────────────────
|
|
264
|
-
// A value as Python's str() writes it: None, True and False by name, lists and dicts as JSON.
|
|
265
|
-
export function python_str(value) {
|
|
266
|
-
if (value === null || value === undefined)
|
|
267
|
-
return "None";
|
|
268
|
-
if (value === true)
|
|
269
|
-
return "True";
|
|
270
|
-
if (value === false)
|
|
271
|
-
return "False";
|
|
272
|
-
if (typeof value === "object")
|
|
273
|
-
return JSON.stringify(value);
|
|
274
|
-
return String(value);
|
|
275
|
-
}
|
|
276
|
-
function step_into(value, key) {
|
|
277
|
-
if (value === null || value === undefined)
|
|
278
|
-
return undefined;
|
|
279
|
-
if (typeof value === "function")
|
|
280
|
-
return value(key);
|
|
281
|
-
const found = value[key];
|
|
282
|
-
return found;
|
|
283
|
-
}
|
|
284
|
-
function resolve_field(field, lookup) {
|
|
285
|
-
const match = /^([^.[]*)(.*)$/.exec(field);
|
|
286
|
-
let value = lookup(match[1]);
|
|
287
|
-
const steps = match[2].matchAll(/\.([^.[]+)|\[([^\]]*)\]/g);
|
|
288
|
-
for (const step of steps)
|
|
289
|
-
value = step_into(value, step[1] ?? step[2]);
|
|
290
|
-
return value;
|
|
291
|
-
}
|
|
292
|
-
function group_thousands(text) {
|
|
293
|
-
const [whole, fraction] = text.split(".");
|
|
294
|
-
const sign = whole.startsWith("-") ? "-" : "";
|
|
295
|
-
const digits = whole.replace(/^-/, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
296
|
-
return sign + digits + (fraction !== undefined ? `.${fraction}` : "");
|
|
297
|
-
}
|
|
298
|
-
// Applies a format spec such as ".1f", ",", ">8" or "d" to one value.
|
|
299
|
-
export function apply_format_spec(value, spec) {
|
|
300
|
-
const match = /^(?:(.)?([<>^]))?(0)?(\d+)?(,)?(?:\.(\d+))?([sdfFeg%])?$/.exec(spec);
|
|
301
|
-
if (spec === "" || match === null)
|
|
302
|
-
return python_str(value);
|
|
303
|
-
const [, fill = " ", align, zero, width, comma, precision, kind] = match;
|
|
304
|
-
let text;
|
|
305
|
-
if (typeof value === "number" && kind !== "s") {
|
|
306
|
-
if (kind === "f" || kind === "F")
|
|
307
|
-
text = format_fixed(value, Number(precision ?? 6));
|
|
308
|
-
else if (kind === "%")
|
|
309
|
-
text = `${format_fixed(value * 100, Number(precision ?? 6))}%`;
|
|
310
|
-
else if (kind === "d")
|
|
311
|
-
text = String(Math.trunc(value));
|
|
312
|
-
else if (kind === "e")
|
|
313
|
-
text = value.toExponential(Number(precision ?? 6)).replace(/e([+-])(\d)$/, "e$10$2");
|
|
314
|
-
else if (precision !== undefined)
|
|
315
|
-
text = format_fixed(value, Number(precision));
|
|
316
|
-
else
|
|
317
|
-
text = String(value);
|
|
318
|
-
if (comma)
|
|
319
|
-
text = group_thousands(text);
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
text = python_str(value);
|
|
323
|
-
if (precision !== undefined)
|
|
324
|
-
text = text.slice(0, Number(precision));
|
|
325
|
-
}
|
|
326
|
-
const size = Number(width ?? 0);
|
|
327
|
-
if (text.length >= size)
|
|
328
|
-
return text;
|
|
329
|
-
const padding = (zero ? "0" : fill).repeat(size - text.length);
|
|
330
|
-
const side = align ?? (typeof value === "number" ? ">" : "<");
|
|
331
|
-
if (side === "<")
|
|
332
|
-
return text + padding;
|
|
333
|
-
if (side === "^")
|
|
334
|
-
return padding.slice(0, Math.floor(padding.length / 2)) + text + padding.slice(Math.floor(padding.length / 2));
|
|
335
|
-
return padding + text;
|
|
336
|
-
}
|
|
337
|
-
// Fills a Python str.format template: "{}" and "{0}" take positional arguments, "{name}" keywords, with ".attr" and
|
|
338
|
-
// "[key]" steps and a ":spec"; "{{" and "}}" are literal braces.
|
|
339
|
-
export function python_format(template, positional = [], keywords = {}) {
|
|
340
|
-
let auto_index = 0;
|
|
341
|
-
const lookup = (name) => {
|
|
342
|
-
if (name === "")
|
|
343
|
-
return positional[auto_index++];
|
|
344
|
-
if (/^\d+$/.test(name))
|
|
345
|
-
return positional[Number(name)];
|
|
346
|
-
return keywords[name];
|
|
347
|
-
};
|
|
348
|
-
return template.replace(/\{\{|\}\}|\{([^{}]*)\}/g, (whole, inner) => {
|
|
349
|
-
if (whole === "{{")
|
|
350
|
-
return "{";
|
|
351
|
-
if (whole === "}}")
|
|
352
|
-
return "}";
|
|
353
|
-
const body = inner ?? "";
|
|
354
|
-
const colon = body.indexOf(":");
|
|
355
|
-
const field = colon === -1 ? body : body.slice(0, colon);
|
|
356
|
-
const spec = colon === -1 ? "" : body.slice(colon + 1);
|
|
357
|
-
const conversion = /!([rs])$/.exec(field);
|
|
358
|
-
const value = resolve_field(conversion ? field.slice(0, -2) : field, lookup);
|
|
359
|
-
if (conversion?.[1] === "r")
|
|
360
|
-
return python_repr(value);
|
|
361
|
-
return apply_format_spec(value, spec);
|
|
362
|
-
});
|
|
363
|
-
}
|
|
1
|
+
// Moved to @x-tech-laboratories/x-app-agent, which a host agent installs without the rest of X-App.
|
|
2
|
+
export * from "@x-tech-laboratories/x-app-agent/python_text";
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { LongRun, LongRunPoll, RunResult } from "../../agent/protocol.ts";
|
|
3
|
-
export type { CommandStream } from "../../agent/commands.ts";
|
|
4
|
-
export type { LongRun, LongRunPoll, LongRunState, RunResult } from "../../agent/protocol.ts";
|
|
5
|
-
export interface AgentRunOptions {
|
|
6
|
-
timeout_in_seconds: number;
|
|
7
|
-
stdin?: string | null;
|
|
8
|
-
}
|
|
9
|
-
export interface AgentStreamOptions {
|
|
10
|
-
stdin?: string | null;
|
|
11
|
-
}
|
|
12
|
-
export declare class AgentError extends Error {
|
|
13
|
-
readonly unreachable: boolean;
|
|
14
|
-
constructor(message: string, unreachable?: boolean);
|
|
15
|
-
}
|
|
16
|
-
export declare function ended_stream(stderr: string): CommandStream;
|
|
17
|
-
export interface Agent<Task> {
|
|
18
|
-
run(task: Task, options: AgentRunOptions): Promise<RunResult>;
|
|
19
|
-
stream(task: Task, options?: AgentStreamOptions): CommandStream;
|
|
20
|
-
start(run_id: string, task: Task, options?: AgentStreamOptions): Promise<LongRun>;
|
|
21
|
-
poll(run_id: string, offset: number): Promise<LongRunPoll>;
|
|
22
|
-
attach(run_id: string, offset: number): CommandStream;
|
|
23
|
-
stop(run_id: string): Promise<LongRun>;
|
|
24
|
-
forget(run_id: string): Promise<void>;
|
|
25
|
-
runs(): Promise<LongRun[]>;
|
|
26
|
-
request(type: string, body?: Record<string, unknown>): Promise<unknown>;
|
|
27
|
-
}
|
|
1
|
+
export * from "@x-tech-laboratories/x-app-agent/server/agents/agent";
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { Readable } from "node:stream";
|
|
4
|
-
export class AgentError extends Error {
|
|
5
|
-
// Whether no usable answer came, as when the host never answered or answered with a malformed reply, so trying again later may work, rather than answering that it failed.
|
|
6
|
-
unreachable;
|
|
7
|
-
constructor(message, unreachable = false) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "AgentError";
|
|
10
|
-
this.unreachable = unreachable;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
// A stream that has already ended with an error, for a host with no agent or a run that cannot be followed.
|
|
14
|
-
export function ended_stream(stderr) {
|
|
15
|
-
return { stdout: Readable.from([]), done: Promise.resolve({ exit_code: -1, stderr }), stop: () => { } };
|
|
16
|
-
}
|
|
1
|
+
// Moved to @x-tech-laboratories/x-app-agent, so an engine on a host can hold agent connections without the rest of X-App.
|
|
2
|
+
export * from "@x-tech-laboratories/x-app-agent/server/agents/agent";
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { type AgentApp, type AgentMessage, type AppMessage, type LongRun, type LongRunPoll, type RunResult, type ServerMessage } from "../../agent/protocol.ts";
|
|
3
|
-
import { type Agent, type AgentRunOptions, type AgentStreamOptions, type CommandStream } from "./agent.ts";
|
|
4
|
-
export interface ServerSocket {
|
|
5
|
-
readonly readyState: number;
|
|
6
|
-
send(data: string): void;
|
|
7
|
-
close(code?: number, reason?: string): void;
|
|
8
|
-
on(event: "message", listener: (data: Buffer | ArrayBuffer | Buffer[], is_binary: boolean) => void): unknown;
|
|
9
|
-
on(event: "close", listener: () => void): unknown;
|
|
10
|
-
on(event: "error", listener: (error: Error) => void): unknown;
|
|
11
|
-
}
|
|
12
|
-
export interface ConnectionOptions {
|
|
13
|
-
window_in_bytes: number;
|
|
14
|
-
request_timeout_in_milliseconds: number;
|
|
15
|
-
heartbeat_in_milliseconds: number;
|
|
16
|
-
}
|
|
17
|
-
export type Hello = Omit<Extract<AgentMessage, {
|
|
18
|
-
type: "hello";
|
|
19
|
-
}>, "signature" | "agent_nonce">;
|
|
20
|
-
export interface MessageSigning {
|
|
21
|
-
server_key: KeyObject;
|
|
22
|
-
server_nonce: string;
|
|
23
|
-
agent_nonce: string;
|
|
24
|
-
}
|
|
25
|
-
export declare class AgentConnection<Task> implements Agent<Task> {
|
|
26
|
-
readonly host: string;
|
|
27
|
-
readonly hello: Hello;
|
|
28
|
-
readonly connected_epoch: number;
|
|
29
|
-
on_message: ((message: AppMessage) => void) | null;
|
|
30
|
-
private readonly socket;
|
|
31
|
-
private readonly app;
|
|
32
|
-
private readonly options;
|
|
33
|
-
private readonly pending;
|
|
34
|
-
private readonly streams;
|
|
35
|
-
private next_id;
|
|
36
|
-
private last_heard;
|
|
37
|
-
private readonly heartbeat;
|
|
38
|
-
private closed_reason;
|
|
39
|
-
private readonly signing;
|
|
40
|
-
private counter;
|
|
41
|
-
constructor(socket: ServerSocket, app: AgentApp<Task>, host: string, hello: Hello, options: ConnectionOptions, signing?: MessageSigning | null);
|
|
42
|
-
get is_open(): boolean;
|
|
43
|
-
get signs_messages(): boolean;
|
|
44
|
-
run(task: Task, options: AgentRunOptions): Promise<RunResult>;
|
|
45
|
-
stream(task: Task, options?: AgentStreamOptions): CommandStream;
|
|
46
|
-
start(run_id: string, task: Task, options?: AgentStreamOptions): Promise<LongRun>;
|
|
47
|
-
poll(run_id: string, offset: number): Promise<LongRunPoll>;
|
|
48
|
-
attach(run_id: string, offset: number): CommandStream;
|
|
49
|
-
stop(run_id: string): Promise<LongRun>;
|
|
50
|
-
forget(run_id: string): Promise<void>;
|
|
51
|
-
runs(): Promise<LongRun[]>;
|
|
52
|
-
request(type: string, body?: Record<string, unknown>): Promise<unknown>;
|
|
53
|
-
send(message: ServerMessage<Task> | AppMessage): void;
|
|
54
|
-
private seal;
|
|
55
|
-
receive(data: Buffer, is_binary: boolean): void;
|
|
56
|
-
closed(reason: string): void;
|
|
57
|
-
close(code: number, reason: string): void;
|
|
58
|
-
private malformed;
|
|
59
|
-
private reject_malformed;
|
|
60
|
-
private send_request;
|
|
61
|
-
private open_stream;
|
|
62
|
-
private beat;
|
|
63
|
-
}
|
|
1
|
+
export * from "@x-tech-laboratories/x-app-agent/server/agents/connection";
|