mandala-computer-mcp 0.3.0 → 0.5.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 +462 -37
- package/dist/api.d.ts +12 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +262 -42
- package/dist/api.js.map +1 -1
- package/dist/artifacts.d.ts +63 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +81 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +35 -21
- package/dist/cli.js.map +1 -1
- package/dist/credentials.d.ts +33 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +395 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +53 -10
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +122 -35
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +11 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +213 -95
- package/dist/events.js.map +1 -1
- package/dist/executions.d.ts +43 -0
- package/dist/executions.d.ts.map +1 -0
- package/dist/executions.js +162 -0
- package/dist/executions.js.map +1 -0
- package/dist/format.d.ts +11 -11
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +159 -16
- package/dist/format.js.map +1 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +4 -0
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +17 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +17 -0
- package/dist/limits.js.map +1 -0
- package/dist/paths.d.ts +42 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +54 -3
- package/dist/paths.js.map +1 -1
- package/dist/poll.d.ts +5 -1
- package/dist/poll.d.ts.map +1 -1
- package/dist/poll.js +120 -16
- package/dist/poll.js.map +1 -1
- package/dist/results.d.ts +97 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +263 -0
- package/dist/results.js.map +1 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +61 -9
- package/dist/server.js.map +1 -1
- package/dist/stdio.d.ts +5 -1
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +10 -4
- package/dist/stdio.js.map +1 -1
- package/dist/tool-filters.d.ts +38 -0
- package/dist/tool-filters.d.ts.map +1 -0
- package/dist/tool-filters.js +129 -0
- package/dist/tool-filters.js.map +1 -0
- package/dist/tools/account.d.ts +3 -0
- package/dist/tools/account.d.ts.map +1 -0
- package/dist/tools/account.js +122 -0
- package/dist/tools/account.js.map +1 -0
- package/dist/tools/activities.d.ts +3 -0
- package/dist/tools/activities.d.ts.map +1 -0
- package/dist/tools/activities.js +140 -0
- package/dist/tools/activities.js.map +1 -0
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +72 -5
- package/dist/tools/agent.js.map +1 -1
- package/dist/tools/artifacts.d.ts +3 -0
- package/dist/tools/artifacts.d.ts.map +1 -0
- package/dist/tools/artifacts.js +97 -0
- package/dist/tools/artifacts.js.map +1 -0
- package/dist/tools/chat.d.ts +6 -0
- package/dist/tools/chat.d.ts.map +1 -0
- package/dist/tools/chat.js +192 -0
- package/dist/tools/chat.js.map +1 -0
- package/dist/tools/computers.d.ts.map +1 -1
- package/dist/tools/computers.js +300 -247
- package/dist/tools/computers.js.map +1 -1
- package/dist/tools/directory.d.ts +13 -0
- package/dist/tools/directory.d.ts.map +1 -0
- package/dist/tools/directory.js +88 -0
- package/dist/tools/directory.js.map +1 -0
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +66 -22
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/executions.d.ts +3 -0
- package/dist/tools/executions.d.ts.map +1 -0
- package/dist/tools/executions.js +87 -0
- package/dist/tools/executions.js.map +1 -0
- package/dist/tools/guest.d.ts.map +1 -1
- package/dist/tools/guest.js +57 -17
- package/dist/tools/guest.js.map +1 -1
- package/dist/tools/input.d.ts.map +1 -1
- package/dist/tools/input.js +63 -5
- package/dist/tools/input.js.map +1 -1
- package/dist/tools/results.d.ts +30 -0
- package/dist/tools/results.d.ts.map +1 -0
- package/dist/tools/results.js +106 -0
- package/dist/tools/results.js.map +1 -0
- package/dist/tools/secrets.d.ts +58 -0
- package/dist/tools/secrets.d.ts.map +1 -0
- package/dist/tools/secrets.js +204 -0
- package/dist/tools/secrets.js.map +1 -0
- package/dist/tools/signals.d.ts +3 -0
- package/dist/tools/signals.d.ts.map +1 -0
- package/dist/tools/signals.js +116 -0
- package/dist/tools/signals.js.map +1 -0
- package/dist/tools/snapshots.d.ts.map +1 -1
- package/dist/tools/snapshots.js +213 -167
- package/dist/tools/snapshots.js.map +1 -1
- package/dist/tools/ssh.d.ts +3 -0
- package/dist/tools/ssh.d.ts.map +1 -0
- package/dist/tools/ssh.js +186 -0
- package/dist/tools/ssh.js.map +1 -0
- package/dist/tools/templates.d.ts.map +1 -1
- package/dist/tools/templates.js +9 -13
- package/dist/tools/templates.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { DEFAULT_BASE_URL } from './api.js';
|
|
6
|
+
const MAX_BYTES = 65_536;
|
|
7
|
+
const RESERVED = new Set([
|
|
8
|
+
'__proto__',
|
|
9
|
+
'prototype',
|
|
10
|
+
'constructor',
|
|
11
|
+
'__defineGetter__',
|
|
12
|
+
'__defineSetter__',
|
|
13
|
+
'hasOwnProperty',
|
|
14
|
+
'__lookupGetter__',
|
|
15
|
+
'__lookupSetter__',
|
|
16
|
+
'isPrototypeOf',
|
|
17
|
+
'propertyIsEnumerable',
|
|
18
|
+
'toLocaleString',
|
|
19
|
+
'toString',
|
|
20
|
+
'valueOf',
|
|
21
|
+
]);
|
|
22
|
+
function credentialWhitespace(code) {
|
|
23
|
+
return ((code >= 9 && code <= 13) ||
|
|
24
|
+
code === 32 ||
|
|
25
|
+
code === 133 ||
|
|
26
|
+
code === 160 ||
|
|
27
|
+
code === 5760 ||
|
|
28
|
+
(code >= 8192 && code <= 8202) ||
|
|
29
|
+
code === 8232 ||
|
|
30
|
+
code === 8233 ||
|
|
31
|
+
code === 8239 ||
|
|
32
|
+
code === 8287 ||
|
|
33
|
+
code === 12288 ||
|
|
34
|
+
code === 65279);
|
|
35
|
+
}
|
|
36
|
+
/** Fixed credential whitespace, shared with the other local clients. */
|
|
37
|
+
export function trimCredentialWhitespace(value) {
|
|
38
|
+
let start = 0;
|
|
39
|
+
let end = value.length;
|
|
40
|
+
while (start < end && credentialWhitespace(value.charCodeAt(start)))
|
|
41
|
+
start++;
|
|
42
|
+
while (end > start && credentialWhitespace(value.charCodeAt(end - 1)))
|
|
43
|
+
end--;
|
|
44
|
+
return value.slice(start, end);
|
|
45
|
+
}
|
|
46
|
+
/** Local diagnostics never include file contents, keys, paths or supplied values. */
|
|
47
|
+
export class CredentialsError extends Error {
|
|
48
|
+
code;
|
|
49
|
+
constructor(code, detail) {
|
|
50
|
+
super(`${detail} Run mandala login with the TypeScript CLI, or set MANDALA_API_KEY.`);
|
|
51
|
+
this.code = code;
|
|
52
|
+
this.name = 'CredentialsError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function fail(code, detail = 'Invalid saved credentials.') {
|
|
56
|
+
throw new CredentialsError(code, detail);
|
|
57
|
+
}
|
|
58
|
+
function profileName(value) {
|
|
59
|
+
if (typeof value !== 'string' ||
|
|
60
|
+
value.length < 1 ||
|
|
61
|
+
value.length > 64 ||
|
|
62
|
+
!/[A-Za-z0-9]/.test(value[0]) ||
|
|
63
|
+
/[^A-Za-z0-9._-]/.test(value) ||
|
|
64
|
+
RESERVED.has(value)) {
|
|
65
|
+
fail('invalid_profile', 'Invalid profile name; use 1–64 ASCII letters, digits, dots, underscores or hyphens.');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Strict file-bound URL syntax; explicit-key transport behavior is separate. */
|
|
69
|
+
export function canonicalizeBaseUrl(value) {
|
|
70
|
+
const bad = () => fail('invalid_base_url', 'Invalid saved-credential base URL.');
|
|
71
|
+
if (typeof value !== 'string')
|
|
72
|
+
return bad();
|
|
73
|
+
const raw = trimCredentialWhitespace(value);
|
|
74
|
+
if (!raw || raw.length > 2048 || /[^\x21-\x7e]|[\\%?#]/.test(raw))
|
|
75
|
+
return bad();
|
|
76
|
+
const schemeMatch = /^(https?):\/\//i.exec(raw);
|
|
77
|
+
if (!schemeMatch)
|
|
78
|
+
return bad();
|
|
79
|
+
const scheme = schemeMatch[1].toLowerCase();
|
|
80
|
+
const rest = raw.slice(schemeMatch[0].length);
|
|
81
|
+
const slash = rest.indexOf('/');
|
|
82
|
+
const authority = slash < 0 ? rest : rest.slice(0, slash);
|
|
83
|
+
const pathname = slash < 0 ? '' : rest.slice(slash);
|
|
84
|
+
if (!authority || authority.includes('@'))
|
|
85
|
+
return bad();
|
|
86
|
+
let host;
|
|
87
|
+
let port;
|
|
88
|
+
if (authority.startsWith('[')) {
|
|
89
|
+
const close = authority.indexOf(']');
|
|
90
|
+
if (close < 0)
|
|
91
|
+
return bad();
|
|
92
|
+
const address = authority.slice(1, close);
|
|
93
|
+
if (isIP(address) !== 6)
|
|
94
|
+
return bad();
|
|
95
|
+
const suffix = authority.slice(close + 1);
|
|
96
|
+
if (suffix && !suffix.startsWith(':'))
|
|
97
|
+
return bad();
|
|
98
|
+
port = suffix ? suffix.slice(1) : undefined;
|
|
99
|
+
// Only IPv6 reaches the URL parser, after strict address validation. It
|
|
100
|
+
// serializes the first longest zero run and any dotted IPv4 tail.
|
|
101
|
+
host = new URL(`https://[${address}]`).hostname;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const parts = authority.split(':');
|
|
105
|
+
if (parts.length > 2)
|
|
106
|
+
return bad();
|
|
107
|
+
host = parts[0].toLowerCase();
|
|
108
|
+
port = parts[1];
|
|
109
|
+
if (!host || host.length > 253)
|
|
110
|
+
return bad();
|
|
111
|
+
const labels = host.split('.');
|
|
112
|
+
if (labels.some((label) => !label ||
|
|
113
|
+
label.length > 63 ||
|
|
114
|
+
/[^a-z0-9-]/.test(label) ||
|
|
115
|
+
!/[a-z0-9]/.test(label[0]) ||
|
|
116
|
+
!/[a-z0-9]/.test(label[label.length - 1])))
|
|
117
|
+
return bad();
|
|
118
|
+
const last = labels[labels.length - 1];
|
|
119
|
+
if (/^(?:[0-9]+|0x[0-9a-f]*)$/.test(last) && isIP(host) !== 4)
|
|
120
|
+
return bad();
|
|
121
|
+
}
|
|
122
|
+
let portSuffix = '';
|
|
123
|
+
if (port !== undefined) {
|
|
124
|
+
if (!port || /[^0-9]/.test(port))
|
|
125
|
+
return bad();
|
|
126
|
+
const n = Number(port);
|
|
127
|
+
if (!Number.isInteger(n) || n < 1 || n > 65535)
|
|
128
|
+
return bad();
|
|
129
|
+
if (!(scheme === 'https' && n === 443) && !(scheme === 'http' && n === 80))
|
|
130
|
+
portSuffix = `:${n}`;
|
|
131
|
+
}
|
|
132
|
+
if (scheme === 'http' &&
|
|
133
|
+
host !== 'localhost' &&
|
|
134
|
+
host !== '[::1]' &&
|
|
135
|
+
!(isIP(host) === 4 && host.startsWith('127.')))
|
|
136
|
+
return bad();
|
|
137
|
+
if (/[^A-Za-z0-9\-._~!$&'()*+,;=:@/]/.test(pathname) ||
|
|
138
|
+
pathname.split('/').some((part) => part === '.' || part === '..'))
|
|
139
|
+
return bad();
|
|
140
|
+
return `${scheme}://${host}${portSuffix}${pathname.replace(/\/+$/, '')}`;
|
|
141
|
+
}
|
|
142
|
+
function object(value) {
|
|
143
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
144
|
+
fail('invalid_schema');
|
|
145
|
+
}
|
|
146
|
+
function closed(value, keys) {
|
|
147
|
+
object(value);
|
|
148
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
149
|
+
fail('invalid_schema');
|
|
150
|
+
}
|
|
151
|
+
function nonempty(value) {
|
|
152
|
+
if (typeof value !== 'string' || !value.length)
|
|
153
|
+
fail('invalid_schema');
|
|
154
|
+
}
|
|
155
|
+
function stringsWellFormed(value) {
|
|
156
|
+
const pending = [value];
|
|
157
|
+
while (pending.length) {
|
|
158
|
+
const current = pending.pop();
|
|
159
|
+
if (typeof current === 'string') {
|
|
160
|
+
for (let i = 0; i < current.length; i++) {
|
|
161
|
+
const code = current.charCodeAt(i);
|
|
162
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
163
|
+
const next = current.charCodeAt(++i);
|
|
164
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
165
|
+
fail('invalid_schema');
|
|
166
|
+
}
|
|
167
|
+
else if (code >= 0xdc00 && code <= 0xdfff)
|
|
168
|
+
fail('invalid_schema');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (current && typeof current === 'object') {
|
|
172
|
+
for (const [key, child] of Object.entries(current))
|
|
173
|
+
pending.push(key, child);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export function parseCredentials(bytes) {
|
|
178
|
+
if (bytes.byteLength > MAX_BYTES)
|
|
179
|
+
fail('file_too_large', 'Saved credentials exceed 65,536 bytes.');
|
|
180
|
+
let text;
|
|
181
|
+
try {
|
|
182
|
+
text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return fail('invalid_utf8', 'Saved credentials must be valid UTF-8.');
|
|
186
|
+
}
|
|
187
|
+
let doc;
|
|
188
|
+
try {
|
|
189
|
+
doc = JSON.parse(text);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return fail('invalid_json', 'Saved credentials are not valid JSON.');
|
|
193
|
+
}
|
|
194
|
+
stringsWellFormed(doc);
|
|
195
|
+
object(doc);
|
|
196
|
+
if (typeof doc.version !== 'number' ||
|
|
197
|
+
!Number.isFinite(doc.version) ||
|
|
198
|
+
!Number.isInteger(doc.version))
|
|
199
|
+
fail('invalid_schema');
|
|
200
|
+
if (doc.version !== 1)
|
|
201
|
+
fail('unsupported_version', 'Unsupported saved-credentials version.');
|
|
202
|
+
if (!Object.hasOwn(doc, 'default_profile'))
|
|
203
|
+
fail('missing_default_profile', 'Saved credentials have no default profile.');
|
|
204
|
+
closed(doc, ['version', 'default_profile', 'profiles']);
|
|
205
|
+
if (typeof doc.default_profile !== 'string')
|
|
206
|
+
fail('invalid_schema');
|
|
207
|
+
profileName(doc.default_profile);
|
|
208
|
+
object(doc.profiles);
|
|
209
|
+
const names = Object.keys(doc.profiles);
|
|
210
|
+
if (!names.length)
|
|
211
|
+
fail('invalid_schema');
|
|
212
|
+
if (names.length > 100)
|
|
213
|
+
fail('too_many_profiles', 'Saved credentials contain more than 100 profiles.');
|
|
214
|
+
for (const name of names) {
|
|
215
|
+
profileName(name);
|
|
216
|
+
const entry = doc.profiles[name];
|
|
217
|
+
closed(entry, ['api_key', 'base_url', 'key_id', 'account', 'scope']);
|
|
218
|
+
nonempty(entry.api_key);
|
|
219
|
+
if (!trimCredentialWhitespace(entry.api_key))
|
|
220
|
+
fail('invalid_schema');
|
|
221
|
+
if (canonicalizeBaseUrl(entry.base_url) !== entry.base_url)
|
|
222
|
+
fail('invalid_base_url', 'Stored base URLs must be canonical.');
|
|
223
|
+
nonempty(entry.key_id);
|
|
224
|
+
closed(entry.account, ['id', 'name']);
|
|
225
|
+
nonempty(entry.account.id);
|
|
226
|
+
if (entry.account.name !== null && typeof entry.account.name !== 'string')
|
|
227
|
+
fail('invalid_schema');
|
|
228
|
+
object(entry.scope);
|
|
229
|
+
if (entry.scope.type === 'account')
|
|
230
|
+
closed(entry.scope, ['type']);
|
|
231
|
+
else if (entry.scope.type === 'workspace') {
|
|
232
|
+
closed(entry.scope, ['type', 'workspace_id', 'workspace_name']);
|
|
233
|
+
nonempty(entry.scope.workspace_id);
|
|
234
|
+
nonempty(entry.scope.workspace_name);
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
fail('invalid_schema');
|
|
238
|
+
}
|
|
239
|
+
if (!Object.hasOwn(doc.profiles, doc.default_profile))
|
|
240
|
+
fail('missing_default_profile', 'The saved default profile is missing.');
|
|
241
|
+
return doc;
|
|
242
|
+
}
|
|
243
|
+
const sameObject = (a, b) => a.dev === b.dev && a.ino === b.ino;
|
|
244
|
+
const sameDirectory = (initial, current) => sameObject(initial, current) &&
|
|
245
|
+
initial.ctimeNs === current.ctimeNs &&
|
|
246
|
+
initial.mtimeNs === current.mtimeNs;
|
|
247
|
+
/**
|
|
248
|
+
* Opened descriptors are checked against pre/post named directory AND file
|
|
249
|
+
* identities and the initial directory's change timestamps. Renaming a
|
|
250
|
+
* directory away and back preserves dev/ino and can preserve mtime, so ctime
|
|
251
|
+
* is essential. Bigint stats retain the filesystem's timestamp precision.
|
|
252
|
+
* Node has no portable openat: these checks reject observed substitutions
|
|
253
|
+
* rather than claiming an atomic directory-relative open.
|
|
254
|
+
*/
|
|
255
|
+
function readStore() {
|
|
256
|
+
if (process.platform === 'win32' ||
|
|
257
|
+
typeof process.getuid !== 'function' ||
|
|
258
|
+
!fs.constants.O_NOFOLLOW ||
|
|
259
|
+
!fs.constants.O_DIRECTORY) {
|
|
260
|
+
fail('unsupported_file_protection', 'Saved credentials require verified POSIX file protection.');
|
|
261
|
+
}
|
|
262
|
+
const deadline = performance.now() + 5000;
|
|
263
|
+
const checkTime = () => {
|
|
264
|
+
if (performance.now() >= deadline)
|
|
265
|
+
fail('credential_read_timeout', 'Reading saved credentials timed out.');
|
|
266
|
+
};
|
|
267
|
+
const uid = process.getuid();
|
|
268
|
+
const directoryUid = BigInt(uid);
|
|
269
|
+
const checkDir = (st) => {
|
|
270
|
+
if (!st.isDirectory() || st.uid !== directoryUid || (st.mode & 4095n) !== 448n)
|
|
271
|
+
fail('unsafe_directory', 'The credentials directory must be owned by you with mode 0700.');
|
|
272
|
+
};
|
|
273
|
+
const checkFile = (st) => {
|
|
274
|
+
if (!st.isFile() || st.uid !== uid || (st.mode & 0o7777) !== 0o600 || st.nlink !== 1)
|
|
275
|
+
fail('unsafe_file', 'The credentials file must be a private, owned regular file with mode 0600 and one link.');
|
|
276
|
+
if (st.size > MAX_BYTES)
|
|
277
|
+
fail('file_too_large', 'Saved credentials exceed 65,536 bytes.');
|
|
278
|
+
};
|
|
279
|
+
let dirFd;
|
|
280
|
+
let fileFd;
|
|
281
|
+
try {
|
|
282
|
+
const home = os.homedir();
|
|
283
|
+
if (!home || !path.isAbsolute(home))
|
|
284
|
+
fail('missing_credentials', 'Cannot discover your home directory.');
|
|
285
|
+
const directory = path.join(home, '.mandala');
|
|
286
|
+
const filename = path.join(directory, 'credentials.json');
|
|
287
|
+
const namedDir = fs.lstatSync(directory, { bigint: true });
|
|
288
|
+
checkDir(namedDir);
|
|
289
|
+
dirFd = fs.openSync(directory, fs.constants.O_RDONLY |
|
|
290
|
+
fs.constants.O_DIRECTORY |
|
|
291
|
+
fs.constants.O_NOFOLLOW |
|
|
292
|
+
fs.constants.O_NONBLOCK);
|
|
293
|
+
const openedDir = fs.fstatSync(dirFd, { bigint: true });
|
|
294
|
+
checkDir(openedDir);
|
|
295
|
+
if (!sameDirectory(namedDir, openedDir))
|
|
296
|
+
fail('unsafe_directory');
|
|
297
|
+
const namedFile = fs.lstatSync(filename);
|
|
298
|
+
checkFile(namedFile);
|
|
299
|
+
const beforeDir = fs.lstatSync(directory, { bigint: true });
|
|
300
|
+
checkDir(beforeDir);
|
|
301
|
+
if (!sameDirectory(namedDir, beforeDir))
|
|
302
|
+
fail('unsafe_directory');
|
|
303
|
+
checkTime();
|
|
304
|
+
fileFd = fs.openSync(filename, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
305
|
+
const openedFile = fs.fstatSync(fileFd);
|
|
306
|
+
checkFile(openedFile);
|
|
307
|
+
if (!sameObject(namedFile, openedFile))
|
|
308
|
+
fail('unsafe_file');
|
|
309
|
+
const buffer = Buffer.alloc(MAX_BYTES + 1);
|
|
310
|
+
let size = 0;
|
|
311
|
+
for (;;) {
|
|
312
|
+
checkTime();
|
|
313
|
+
const n = fs.readSync(fileFd, buffer, size, Math.min(8192, buffer.length - size), null);
|
|
314
|
+
size += n;
|
|
315
|
+
if (size > MAX_BYTES)
|
|
316
|
+
fail('file_too_large', 'Saved credentials exceed 65,536 bytes.');
|
|
317
|
+
if (!n)
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
const finalFile = fs.fstatSync(fileFd);
|
|
321
|
+
checkFile(finalFile);
|
|
322
|
+
if (!sameObject(openedFile, finalFile) ||
|
|
323
|
+
size !== finalFile.size ||
|
|
324
|
+
openedFile.size !== finalFile.size ||
|
|
325
|
+
openedFile.mtimeMs !== finalFile.mtimeMs ||
|
|
326
|
+
openedFile.ctimeMs !== finalFile.ctimeMs)
|
|
327
|
+
fail('unsafe_file');
|
|
328
|
+
const finalNamedFile = fs.lstatSync(filename);
|
|
329
|
+
checkFile(finalNamedFile);
|
|
330
|
+
if (!sameObject(openedFile, finalNamedFile))
|
|
331
|
+
fail('unsafe_file');
|
|
332
|
+
const finalDir = fs.fstatSync(dirFd, { bigint: true });
|
|
333
|
+
const finalNamedDir = fs.lstatSync(directory, { bigint: true });
|
|
334
|
+
checkDir(finalDir);
|
|
335
|
+
checkDir(finalNamedDir);
|
|
336
|
+
if (!sameDirectory(namedDir, finalDir) || !sameDirectory(namedDir, finalNamedDir))
|
|
337
|
+
fail('unsafe_directory');
|
|
338
|
+
checkTime();
|
|
339
|
+
return buffer.subarray(0, size);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (error instanceof CredentialsError)
|
|
343
|
+
throw error;
|
|
344
|
+
const code = error?.code;
|
|
345
|
+
if (code === 'ENOENT')
|
|
346
|
+
fail('missing_credentials', 'No API key or saved credentials found.');
|
|
347
|
+
return fail('unsafe_file', 'Cannot safely read saved credentials; check the directory and file protection.');
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
350
|
+
if (fileFd !== undefined)
|
|
351
|
+
fs.closeSync(fileFd);
|
|
352
|
+
if (dirFd !== undefined)
|
|
353
|
+
fs.closeSync(dirFd);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/** Resolve once at local startup, before constructing an explicit ServerConfig. */
|
|
357
|
+
export function resolveCredentials(options = {}) {
|
|
358
|
+
const explicit = options.apiKey;
|
|
359
|
+
const legacyBase = () => (options.baseUrl ?? process.env.MANDALA_BASE_URL?.trim()) || DEFAULT_BASE_URL;
|
|
360
|
+
if (explicit !== undefined) {
|
|
361
|
+
if (typeof explicit !== 'string' || !trimCredentialWhitespace(explicit))
|
|
362
|
+
fail('invalid_explicit_key', 'The supplied API key must be a nonempty string.');
|
|
363
|
+
return {
|
|
364
|
+
apiKey: trimCredentialWhitespace(explicit),
|
|
365
|
+
baseUrl: legacyBase(),
|
|
366
|
+
source: 'explicit',
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
const environment = trimCredentialWhitespace(process.env.MANDALA_API_KEY ?? '');
|
|
370
|
+
if (environment)
|
|
371
|
+
return { apiKey: environment, baseUrl: legacyBase(), source: 'environment' };
|
|
372
|
+
// null is supplied in JavaScript, and must not fall through to the environment.
|
|
373
|
+
const profile = options.profile !== undefined
|
|
374
|
+
? options.profile
|
|
375
|
+
: trimCredentialWhitespace(process.env.MANDALA_PROFILE ?? '') || undefined;
|
|
376
|
+
if (profile !== undefined)
|
|
377
|
+
profileName(profile);
|
|
378
|
+
const doc = parseCredentials(readStore());
|
|
379
|
+
const name = profile ?? doc.default_profile;
|
|
380
|
+
if (!Object.hasOwn(doc.profiles, name))
|
|
381
|
+
fail('missing_selected_profile', 'The selected credential profile is missing.');
|
|
382
|
+
const entry = doc.profiles[name];
|
|
383
|
+
const override = options.baseUrl !== undefined
|
|
384
|
+
? options.baseUrl
|
|
385
|
+
: trimCredentialWhitespace(process.env.MANDALA_BASE_URL ?? '') || undefined;
|
|
386
|
+
if (override !== undefined && canonicalizeBaseUrl(override) !== entry.base_url)
|
|
387
|
+
fail('base_binding_mismatch', 'The base URL does not match the selected credential profile.');
|
|
388
|
+
return {
|
|
389
|
+
apiKey: trimCredentialWhitespace(entry.api_key),
|
|
390
|
+
baseUrl: entry.base_url,
|
|
391
|
+
source: 'file',
|
|
392
|
+
profile: name,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,WAAW;IACX,WAAW;IACX,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,UAAU;IACV,SAAS;CACV,CAAC,CAAC;AACH,SAAS,oBAAoB,CAAC,IAAY;IACxC,OAAO,CACL,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,KAAK,EAAE;QACX,IAAI,KAAK,GAAG;QACZ,IAAI,KAAK,GAAG;QACZ,IAAI,KAAK,IAAI;QACb,CA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AAC,CAAC,OAAO,CAAC,OAAO;QACjB,CAAC,CAAC,wBAAwB,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,IAAI,SAAS,CAAC;IAChF,IAAI,QAAQ,KAAK,SAAS,IAAI,mBAAmB,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,QAAQ;QAC5E,IAAI,CAAC,uBAAuB,EAAE,8DAA8D,CAAC,CAAC;IAChG,OAAO;QACL,MAAM,EAAE,wBAAwB,CAAC,KAAK,CAAC,OAAO,CAAC;QAC/C,OAAO,EAAE,KAAK,CAAC,QAAQ;QACvB,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
export declare class MandalaError extends Error {
|
|
17
17
|
name: string;
|
|
18
18
|
}
|
|
19
|
+
/** Optional diagnostics supplied by an HTTP response; never permission to replay a request. */
|
|
20
|
+
export interface APIErrorMetadata {
|
|
21
|
+
requestId?: string;
|
|
22
|
+
allow?: string;
|
|
23
|
+
wwwAuthenticate?: string;
|
|
24
|
+
}
|
|
19
25
|
export declare class APIError extends MandalaError {
|
|
20
26
|
readonly status: number;
|
|
21
27
|
readonly body?: unknown | undefined;
|
|
@@ -24,9 +30,10 @@ export declare class APIError extends MandalaError {
|
|
|
24
30
|
name: string;
|
|
25
31
|
/**
|
|
26
32
|
* The platform's own word for what KIND of refusal this is, where it sent
|
|
27
|
-
* one: `contention`, `starting`, `unavailable` or `unsupported` (OPL-3898)
|
|
28
|
-
* `
|
|
29
|
-
*
|
|
33
|
+
* one: `contention`, `starting`, `unavailable` or `unsupported` (OPL-3898),
|
|
34
|
+
* or `revoked` (OPL-4801) — the one word about the caller rather than the
|
|
35
|
+
* computer. `undefined` for most errors, and always will be — the platform is
|
|
36
|
+
* explicit that an absent value means unclassified rather than "none of these".
|
|
30
37
|
*
|
|
31
38
|
* Read on the base class rather than on the one 409 it was filed for, because
|
|
32
39
|
* the platform keys it on the ERROR and not on the route: the same sentinel is
|
|
@@ -35,9 +42,15 @@ export declare class APIError extends MandalaError {
|
|
|
35
42
|
* the caller who arrived a moment earlier heard.
|
|
36
43
|
*/
|
|
37
44
|
readonly reason?: string;
|
|
45
|
+
/** Response header first, then the top-level body ID; never an idempotency key. */
|
|
46
|
+
readonly requestId?: string;
|
|
47
|
+
/** The received Allow header, when supplied. */
|
|
48
|
+
readonly allow?: string;
|
|
49
|
+
/** The received WWW-Authenticate header, when supplied. */
|
|
50
|
+
readonly wwwAuthenticate?: string;
|
|
38
51
|
constructor(message: string, status: number, body?: unknown | undefined,
|
|
39
52
|
/** Parsed Retry-After delay in milliseconds; absent when missing or invalid. */
|
|
40
|
-
retryAfterMs?: number | undefined);
|
|
53
|
+
retryAfterMs?: number | undefined, metadata?: APIErrorMetadata);
|
|
41
54
|
}
|
|
42
55
|
/** Whether waiting can change a classified refusal's answer. */
|
|
43
56
|
export type ReasonKind = 'clears' | 'permanent';
|
|
@@ -85,6 +98,30 @@ export declare function reasonKind(reason: string | undefined): ReasonKind | und
|
|
|
85
98
|
* platform's "absent means unclassified" contract exists to prevent.
|
|
86
99
|
*/
|
|
87
100
|
export declare function reasonAdvice(reason: string | undefined): string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* What to tell a model about a refusal that is about the CALLER, not the computer.
|
|
103
|
+
*
|
|
104
|
+
* The companion to {@link reasonAdvice}, for the three statuses the platform can
|
|
105
|
+
* answer with partway through a call rather than only at the start of one: the
|
|
106
|
+
* credential, the role and the plan are all checked again before the platform
|
|
107
|
+
* does anything further, so a long call can be refused after part of its work is
|
|
108
|
+
* already done.
|
|
109
|
+
*
|
|
110
|
+
* Which makes the wording the interesting part. A model reads one sentence and
|
|
111
|
+
* decides from it whether to send the call again, and the default instinct on
|
|
112
|
+
* anything that looks like a transport failure is to retry — so the sentence has
|
|
113
|
+
* to say, in words and not by omission, that a retry is wrong and that some of
|
|
114
|
+
* the work may already stand. None of the three is a fault on the computer, and
|
|
115
|
+
* a model told only "unauthorized (HTTP 401)" reads it as one.
|
|
116
|
+
*
|
|
117
|
+
* A 404 is deliberately not classified here: it does not separate deleted
|
|
118
|
+
* from out of this key's reach, so a single clause would have to be wrong about
|
|
119
|
+
* one of them — that judgement belongs to the tools that know which id they were
|
|
120
|
+
* given. Silence is the same discipline {@link reasonAdvice} keeps.
|
|
121
|
+
*/
|
|
122
|
+
export declare function authenticationAdvice(reason: string | undefined): string;
|
|
123
|
+
/** Status-specific guidance, with authentication provenance supplied by the refusal reason. */
|
|
124
|
+
export declare function statusAdvice(status: number | undefined, reason?: string): string | undefined;
|
|
88
125
|
/** 401 — the key is missing, malformed, or revoked. */
|
|
89
126
|
export declare class AuthenticationError extends APIError {
|
|
90
127
|
name: string;
|
|
@@ -97,10 +134,14 @@ export declare class PlanLimitError extends APIError {
|
|
|
97
134
|
export declare class PermissionDeniedError extends APIError {
|
|
98
135
|
name: string;
|
|
99
136
|
}
|
|
100
|
-
/** 404 — no such computer, snapshot, or route. */
|
|
137
|
+
/** 404 — no such computer, snapshot, guest path, or route. */
|
|
101
138
|
export declare class NotFoundError extends APIError {
|
|
102
139
|
name: string;
|
|
103
140
|
}
|
|
141
|
+
/** 405 — the path does not support the requested method; inspect the received Allow. */
|
|
142
|
+
export declare class MethodNotAllowedError extends APIError {
|
|
143
|
+
name: string;
|
|
144
|
+
}
|
|
104
145
|
/**
|
|
105
146
|
* 409 — the thing exists but is in the wrong state for this right now.
|
|
106
147
|
*
|
|
@@ -157,7 +198,7 @@ export declare class MoveRequiredError extends ConflictError {
|
|
|
157
198
|
name: string;
|
|
158
199
|
constructor(message: string, status: number, body: unknown,
|
|
159
200
|
/** Whether a host in this region could run the size that was asked for. */
|
|
160
|
-
movePossible: boolean, retryAfterMs?: number);
|
|
201
|
+
movePossible: boolean, retryAfterMs?: number, metadata?: APIErrorMetadata);
|
|
161
202
|
}
|
|
162
203
|
/**
|
|
163
204
|
* 416 — the `Range` named no byte the file has.
|
|
@@ -177,7 +218,7 @@ export declare class RangeNotSatisfiableError extends APIError {
|
|
|
177
218
|
name: string;
|
|
178
219
|
constructor(message: string, status: number, body?: unknown,
|
|
179
220
|
/** The file's real length, off `Content-Range`, when the response sent one. */
|
|
180
|
-
size?: number | undefined, retryAfterMs?: number);
|
|
221
|
+
size?: number | undefined, retryAfterMs?: number, metadata?: APIErrorMetadata);
|
|
181
222
|
}
|
|
182
223
|
/**
|
|
183
224
|
* 429 — the request is valid; the caller has spent a temporary rate budget.
|
|
@@ -196,7 +237,7 @@ export declare class RateLimitError extends APIError {
|
|
|
196
237
|
name: string;
|
|
197
238
|
constructor(message: string, status: number, body?: unknown,
|
|
198
239
|
/** From `Retry-After`, in milliseconds from now, when the response sent one. */
|
|
199
|
-
retryAfterMs?: number);
|
|
240
|
+
retryAfterMs?: number, metadata?: APIErrorMetadata);
|
|
200
241
|
}
|
|
201
242
|
/** 503 — a hypervisor could not be reached, so an inventory would be short. */
|
|
202
243
|
export declare class UnavailableError extends APIError {
|
|
@@ -441,7 +482,7 @@ export declare class OriginTLSError extends APIError {
|
|
|
441
482
|
*/
|
|
442
483
|
export declare function platformSaid(body: unknown): string | undefined;
|
|
443
484
|
/** Build the error for a status, with the platform's own message when it sent one. */
|
|
444
|
-
export declare function errorForStatus(status: number, message: string, body?: unknown, retryAfterMs?: number): APIError;
|
|
485
|
+
export declare function errorForStatus(status: number, message: string, body?: unknown, retryAfterMs?: number, metadata?: APIErrorMetadata): APIError;
|
|
445
486
|
/**
|
|
446
487
|
* Whether an error is worth trying again without changing the request.
|
|
447
488
|
*
|
|
@@ -451,7 +492,9 @@ export declare function errorForStatus(status: number, message: string, body?: u
|
|
|
451
492
|
* including one that creates something — so it names only failures that both
|
|
452
493
|
* clear on their own AND are safe to replay blind.
|
|
453
494
|
*
|
|
454
|
-
*
|
|
495
|
+
* Terminal authentication, authority, payment, missing-resource and method
|
|
496
|
+
* refusals stay terminal even with a contradictory reason. Other cases are
|
|
497
|
+
* answered by TYPE, which is the OPL-3724
|
|
455
498
|
* decision written down. Three clients had drifted into three mechanisms for
|
|
456
499
|
* one question: this file matched classes plus a list of numbers, the
|
|
457
500
|
* TypeScript SDK matched classes alone, and the Python SDK named the fatal
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC;AAED,qBAAa,QAAS,SAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC;AAED,+FAA+F;AAC/F,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAOD,qBAAa,QAAS,SAAQ,YAAY;IAwBtC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO;IACvB,gFAAgF;IAChF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;IA1BvB,IAAI,SAAc;IAC3B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;gBAEhC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,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