toolscript-mcp 1.0.1 → 1.0.2
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 +33 -0
- package/dist/host/main.js +189 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -916,6 +916,39 @@ shows the cause. The next search or call tries the refresh again.
|
|
|
916
916
|
Sessions that share one token store refresh one at a time, so a server that revokes a reused refresh token keeps your login.
|
|
917
917
|
A `.lock` file can show beside the store for a moment. If a session waits up to 20 s for another session, `search_tools` shows the cause. The next call tries again.
|
|
918
918
|
|
|
919
|
+
### AWS SigV4
|
|
920
|
+
|
|
921
|
+
toolscript-mcp signs the requests to an AWS HTTP server, such as the AWS MCP Server, with AWS SigV4. It uses the
|
|
922
|
+
credentials of a profile of the AWS CLI. You do not need a proxy such as `mcp-proxy-for-aws`, and you do not need a
|
|
923
|
+
login.
|
|
924
|
+
|
|
925
|
+
```json
|
|
926
|
+
{
|
|
927
|
+
"mcpServers": {
|
|
928
|
+
"aws": {
|
|
929
|
+
"type": "http",
|
|
930
|
+
"url": "https://aws-mcp.us-east-1.api.aws/mcp",
|
|
931
|
+
"sigv4": { "profile": "dev" }
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
1. Install the AWS CLI version 2 and put `aws` on your `PATH`.
|
|
938
|
+
2. For an SSO profile, run `aws sso login --profile <profile>`.
|
|
939
|
+
3. Add one entry for each profile. Each entry uses one account.
|
|
940
|
+
|
|
941
|
+
- toolscript-mcp gets the credentials with `aws configure export-credentials --profile <profile>`. It keeps them in
|
|
942
|
+
memory and gets new ones 5 minutes before they expire.
|
|
943
|
+
- When the credentials cannot be read, the call fails with the cause and the `aws sso login` command. After you log in
|
|
944
|
+
again, the next call works, with no restart.
|
|
945
|
+
- The region and the service come from the host of `url`, such as `us-east-1` and `aws-mcp`. For another host, set
|
|
946
|
+
`"region"` and `"service"` in `sigv4`.
|
|
947
|
+
- An entry with `sigv4` does not log in with OAuth. An entry with `sigv4` and `oauth`, or with an `Authorization`
|
|
948
|
+
header, is an error.
|
|
949
|
+
- toolscript-mcp signs only the requests to the origin of `url`. It never writes the credentials or the signature to a
|
|
950
|
+
log.
|
|
951
|
+
|
|
919
952
|
### Run log
|
|
920
953
|
|
|
921
954
|
toolscript-mcp writes one line to `~/.toolscript-mcp/runs.jsonl` for each `run_code` call.
|
package/dist/host/main.js
CHANGED
|
@@ -17677,6 +17677,49 @@ var nonEmpty = (v, path15, errors) => {
|
|
|
17677
17677
|
return "";
|
|
17678
17678
|
};
|
|
17679
17679
|
var OAUTH_KEYS = ["clientId", "clientSecret", "scopes", "callbackPort"];
|
|
17680
|
+
var SIGV4_KEYS = ["profile", "region", "service"];
|
|
17681
|
+
var AWS_PROFILE = /^[A-Za-z0-9][A-Za-z0-9_.+=@-]{0,127}$/;
|
|
17682
|
+
var AWS_REGION = /^[a-z]{2}(?:-[a-z]+)+-\d{1,2}$/;
|
|
17683
|
+
var AWS_SERVICE = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
17684
|
+
var awsEndpoint = (url2) => {
|
|
17685
|
+
if (!URL.canParse(url2)) return void 0;
|
|
17686
|
+
const host = /^https:\/\/([^/?#@:]+)(?::\d+)?(?:[/?#]|$)/i.exec(url2)?.[1]?.toLowerCase() ?? "";
|
|
17687
|
+
const m = /^([a-z0-9-]+)\.([a-z]{2}(?:-[a-z]+)+-\d{1,2})\.(?:api\.aws|amazonaws\.com)$/.exec(host);
|
|
17688
|
+
return m ? { service: m[1], region: m[2] } : void 0;
|
|
17689
|
+
};
|
|
17690
|
+
var parseSigV4 = (raw, url2, headers, oauth, path15, env, errors) => {
|
|
17691
|
+
if (raw === void 0) return void 0;
|
|
17692
|
+
if (!isObject2(raw)) {
|
|
17693
|
+
errors.push(`${path15}: must be an object with "profile"`);
|
|
17694
|
+
return void 0;
|
|
17695
|
+
}
|
|
17696
|
+
unknownKeys(raw, SIGV4_KEYS, path15, errors);
|
|
17697
|
+
if (oauth !== void 0 && oauth !== false)
|
|
17698
|
+
errors.push(`${path15}: an entry with "sigv4" does not log in: remove "oauth"`);
|
|
17699
|
+
if (Object.keys(headers).some((name) => name.toLowerCase() === "authorization"))
|
|
17700
|
+
errors.push(`${path15}: an entry with an Authorization header cannot sign with SigV4: remove one of them`);
|
|
17701
|
+
const field = (key, rule, fallback) => {
|
|
17702
|
+
const value = raw[key];
|
|
17703
|
+
if (value === void 0) {
|
|
17704
|
+
if (fallback === void 0) errors.push(`${path15}.${key}: is needed, because the URL is not an AWS endpoint`);
|
|
17705
|
+
return fallback;
|
|
17706
|
+
}
|
|
17707
|
+
const text2 = expand(nonEmpty(value, `${path15}.${key}`, errors), env, `${path15}.${key}`, errors);
|
|
17708
|
+
if (text2 !== "" && !rule.test(text2)) {
|
|
17709
|
+
errors.push(`${path15}.${key}: is not a valid ${key}`);
|
|
17710
|
+
return void 0;
|
|
17711
|
+
}
|
|
17712
|
+
return text2;
|
|
17713
|
+
};
|
|
17714
|
+
const endpoint = awsEndpoint(url2);
|
|
17715
|
+
const found = errors.length;
|
|
17716
|
+
if (raw.profile === void 0) errors.push(`${path15}.profile: is needed`);
|
|
17717
|
+
const profile = raw.profile === void 0 ? void 0 : field("profile", AWS_PROFILE, void 0);
|
|
17718
|
+
const region = field("region", AWS_REGION, endpoint?.region);
|
|
17719
|
+
const service = field("service", AWS_SERVICE, endpoint?.service);
|
|
17720
|
+
if (errors.length !== found || !profile || !region || !service) return void 0;
|
|
17721
|
+
return { profile, region, service };
|
|
17722
|
+
};
|
|
17680
17723
|
var parseOAuth = (raw, headers, path15, env, errors) => {
|
|
17681
17724
|
if (raw === false) return void 0;
|
|
17682
17725
|
if (raw === void 0) return Object.keys(headers).length === 0 ? { scopes: [] } : void 0;
|
|
@@ -17776,7 +17819,7 @@ var parseServer = (raw, path15, env, platform, errors) => {
|
|
|
17776
17819
|
};
|
|
17777
17820
|
}
|
|
17778
17821
|
if (type === "http") {
|
|
17779
|
-
unknownKeys(raw, ["type", "url", "headers", "oauth", "untrusted"], path15, errors);
|
|
17822
|
+
unknownKeys(raw, ["type", "url", "headers", "oauth", "sigv4", "untrusted"], path15, errors);
|
|
17780
17823
|
const found = errors.length;
|
|
17781
17824
|
const url2 = expand(nonEmpty(raw.url, `${path15}.url`, errors), env, `${path15}.url`, errors);
|
|
17782
17825
|
if (errors.length === found) {
|
|
@@ -17784,12 +17827,14 @@ var parseServer = (raw, path15, env, platform, errors) => {
|
|
|
17784
17827
|
else if (!URL.canParse(url2)) errors.push(`${path15}.url: must be a valid URL`);
|
|
17785
17828
|
}
|
|
17786
17829
|
const headers = stringMap(raw.headers, `${path15}.headers`, env, errors);
|
|
17787
|
-
const
|
|
17830
|
+
const sigv4 = parseSigV4(raw.sigv4, url2, headers, raw.oauth, `${path15}.sigv4`, env, errors);
|
|
17831
|
+
const oauth = raw.sigv4 === void 0 ? parseOAuth(raw.oauth, headers, `${path15}.oauth`, env, errors) : void 0;
|
|
17788
17832
|
return {
|
|
17789
17833
|
kind: "http",
|
|
17790
17834
|
url: url2,
|
|
17791
17835
|
headers,
|
|
17792
17836
|
...oauth && { oauth },
|
|
17837
|
+
...sigv4 && { sigv4 },
|
|
17793
17838
|
...parseTrust(raw.untrusted, `${path15}.untrusted`, errors)
|
|
17794
17839
|
};
|
|
17795
17840
|
}
|
|
@@ -29380,6 +29425,127 @@ var oauthProvider = (file2, oauth, mode, lockFs) => {
|
|
|
29380
29425
|
};
|
|
29381
29426
|
};
|
|
29382
29427
|
|
|
29428
|
+
// src/host/sigv4.ts
|
|
29429
|
+
var import_cross_spawn4 = __toESM(require_cross_spawn(), 1);
|
|
29430
|
+
import { createHash as createHash2, createHmac } from "node:crypto";
|
|
29431
|
+
var sha256 = (data) => createHash2("sha256").update(data).digest("hex");
|
|
29432
|
+
var hmac = (key, data) => createHmac("sha256", key).update(data).digest();
|
|
29433
|
+
var encode3 = (text2) => encodeURIComponent(text2).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
29434
|
+
var canonicalPath = (pathname) => pathname.split("/").map(encode3).join("/") || "/";
|
|
29435
|
+
var canonicalQuery = (params) => [...params].map(([k, v]) => [encode3(k), encode3(v)]).sort(([a, av], [b, bv]) => a < b ? -1 : a > b ? 1 : av < bv ? -1 : av > bv ? 1 : 0).map(([k, v]) => `${k}=${v}`).join("&");
|
|
29436
|
+
var signRequest = (request, credentials, scope, now) => {
|
|
29437
|
+
const url2 = new URL(request.url);
|
|
29438
|
+
const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
29439
|
+
const day = amzDate.slice(0, 8);
|
|
29440
|
+
const added = { "x-amz-date": amzDate };
|
|
29441
|
+
if (credentials.sessionToken !== void 0) added["x-amz-security-token"] = credentials.sessionToken;
|
|
29442
|
+
const signed = { host: url2.host, ...added };
|
|
29443
|
+
const contentType2 = request.headers.get("content-type");
|
|
29444
|
+
if (contentType2 !== null) signed["content-type"] = contentType2;
|
|
29445
|
+
const names = Object.keys(signed).sort();
|
|
29446
|
+
const canonical2 = [
|
|
29447
|
+
request.method.toUpperCase(),
|
|
29448
|
+
canonicalPath(url2.pathname),
|
|
29449
|
+
canonicalQuery(url2.searchParams),
|
|
29450
|
+
names.map((n) => `${n}:${signed[n].trim().replace(/\s+/g, " ")}
|
|
29451
|
+
`).join(""),
|
|
29452
|
+
names.join(";"),
|
|
29453
|
+
sha256(request.body)
|
|
29454
|
+
].join("\n");
|
|
29455
|
+
const credentialScope = `${day}/${scope.region}/${scope.service}/aws4_request`;
|
|
29456
|
+
const toSign = ["AWS4-HMAC-SHA256", amzDate, credentialScope, sha256(canonical2)].join("\n");
|
|
29457
|
+
let key = hmac(`AWS4${credentials.secretAccessKey}`, day);
|
|
29458
|
+
for (const part of [scope.region, scope.service, "aws4_request"]) key = hmac(key, part);
|
|
29459
|
+
const signature = createHmac("sha256", key).update(toSign).digest("hex");
|
|
29460
|
+
added.authorization = `AWS4-HMAC-SHA256 Credential=${credentials.accessKeyId}/${credentialScope}, SignedHeaders=${names.join(";")}, Signature=${signature}`;
|
|
29461
|
+
return added;
|
|
29462
|
+
};
|
|
29463
|
+
var EARLY_MS = 5 * 6e4;
|
|
29464
|
+
var CLI_TIMEOUT_MS = 3e4;
|
|
29465
|
+
var MAX_OUTPUT = 64 * 1024;
|
|
29466
|
+
var AwsCredentialsError = class extends Error {
|
|
29467
|
+
};
|
|
29468
|
+
var parseExported = (text2) => {
|
|
29469
|
+
let raw;
|
|
29470
|
+
try {
|
|
29471
|
+
raw = JSON.parse(text2);
|
|
29472
|
+
} catch {
|
|
29473
|
+
return void 0;
|
|
29474
|
+
}
|
|
29475
|
+
if (typeof raw !== "object" || raw === null) return void 0;
|
|
29476
|
+
const { AccessKeyId, SecretAccessKey, SessionToken, Expiration } = raw;
|
|
29477
|
+
if (typeof AccessKeyId !== "string" || AccessKeyId === "" || typeof SecretAccessKey !== "string") return void 0;
|
|
29478
|
+
if (SecretAccessKey === "") return void 0;
|
|
29479
|
+
const expiresAt = typeof Expiration === "string" ? Date.parse(Expiration) : NaN;
|
|
29480
|
+
return {
|
|
29481
|
+
accessKeyId: AccessKeyId,
|
|
29482
|
+
secretAccessKey: SecretAccessKey,
|
|
29483
|
+
...typeof SessionToken === "string" && SessionToken !== "" && { sessionToken: SessionToken },
|
|
29484
|
+
...Number.isFinite(expiresAt) && { expiresAt }
|
|
29485
|
+
};
|
|
29486
|
+
};
|
|
29487
|
+
var failure2 = (profile, why) => new AwsCredentialsError(
|
|
29488
|
+
`could not get AWS credentials for the profile "${profile}" (${why}). If it is an SSO profile, run: aws sso login --profile ${profile}`
|
|
29489
|
+
);
|
|
29490
|
+
var exportCredentials = (profile, command3 = "aws") => new Promise((resolve2, reject) => {
|
|
29491
|
+
let child;
|
|
29492
|
+
try {
|
|
29493
|
+
child = (0, import_cross_spawn4.default)(command3, ["configure", "export-credentials", "--profile", profile, "--format", "process"], {
|
|
29494
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
29495
|
+
windowsHide: true
|
|
29496
|
+
});
|
|
29497
|
+
} catch {
|
|
29498
|
+
reject(failure2(profile, "the AWS CLI did not start"));
|
|
29499
|
+
return;
|
|
29500
|
+
}
|
|
29501
|
+
let out = "";
|
|
29502
|
+
let err = "";
|
|
29503
|
+
child.stdout?.on("data", (b) => void (out.length < MAX_OUTPUT && (out += b.toString("utf8"))));
|
|
29504
|
+
child.stderr?.on("data", (b) => void (err.length < MAX_OUTPUT && (err += b.toString("utf8"))));
|
|
29505
|
+
const timer = setTimeout(() => child.kill(), CLI_TIMEOUT_MS);
|
|
29506
|
+
child.on("error", (e) => {
|
|
29507
|
+
clearTimeout(timer);
|
|
29508
|
+
reject(failure2(profile, e.code === "ENOENT" ? 'the AWS CLI "aws" is not on PATH' : "the AWS CLI did not start"));
|
|
29509
|
+
});
|
|
29510
|
+
child.on("close", (code) => {
|
|
29511
|
+
clearTimeout(timer);
|
|
29512
|
+
const credentials = code === 0 ? parseExported(out) : void 0;
|
|
29513
|
+
if (credentials) return resolve2(credentials);
|
|
29514
|
+
const line = err.split(/\r?\n/).find((l) => l.trim() !== "")?.trim().slice(0, 300);
|
|
29515
|
+
reject(failure2(profile, line ?? (code === 0 ? "the AWS CLI printed no credentials" : `exit ${code}`)));
|
|
29516
|
+
});
|
|
29517
|
+
});
|
|
29518
|
+
var sigv4Fetch = (server2, base, load = exportCredentials, clock = Date.now) => {
|
|
29519
|
+
const origin = new URL(server2.url).origin;
|
|
29520
|
+
let current;
|
|
29521
|
+
let pending;
|
|
29522
|
+
const credentials = async () => {
|
|
29523
|
+
if (current && (current.expiresAt === void 0 || current.expiresAt - EARLY_MS > clock())) return current;
|
|
29524
|
+
pending ??= load(server2.sigv4.profile).finally(() => pending = void 0);
|
|
29525
|
+
current = await pending;
|
|
29526
|
+
return current;
|
|
29527
|
+
};
|
|
29528
|
+
const signed = async (url2, init) => {
|
|
29529
|
+
const target = new URL(url2);
|
|
29530
|
+
if (target.origin !== origin) return base(url2, init);
|
|
29531
|
+
const headers = new Headers(init?.headers);
|
|
29532
|
+
for (const [name, value] of Object.entries(server2.headers ?? {})) headers.set(name, value);
|
|
29533
|
+
const body = init?.body;
|
|
29534
|
+
if (body !== void 0 && body !== null && typeof body !== "string" && !(body instanceof Uint8Array))
|
|
29535
|
+
throw new Error("a SigV4 request body must be a string or bytes");
|
|
29536
|
+
const added = signRequest(
|
|
29537
|
+
{ method: init?.method ?? "GET", url: target.href, headers, body: body ?? "" },
|
|
29538
|
+
await credentials(),
|
|
29539
|
+
server2.sigv4,
|
|
29540
|
+
new Date(clock())
|
|
29541
|
+
);
|
|
29542
|
+
for (const [name, value] of Object.entries(added)) headers.set(name, value);
|
|
29543
|
+
return base(url2, { ...init, headers, redirect: "manual" });
|
|
29544
|
+
};
|
|
29545
|
+
const secrets = () => current ? [current.accessKeyId, current.secretAccessKey, ...current.sessionToken ? [current.sessionToken] : []] : [];
|
|
29546
|
+
return Object.assign(signed, { secrets });
|
|
29547
|
+
};
|
|
29548
|
+
|
|
29383
29549
|
// src/host/downstream.ts
|
|
29384
29550
|
var CONNECT_TIMEOUT_MS = 3e4;
|
|
29385
29551
|
var MAX_PAGES = 100;
|
|
@@ -29483,13 +29649,16 @@ var isOAuthStop = (err) => err instanceof LoginNeeded || err instanceof RefreshF
|
|
|
29483
29649
|
var HttpTransport = class extends StreamableHTTPClientTransport {
|
|
29484
29650
|
#onSessionEnd;
|
|
29485
29651
|
#loginReason;
|
|
29486
|
-
|
|
29652
|
+
/** The AWS credentials of a SigV4 entry, to hide from the texts that reach the model and the log. */
|
|
29653
|
+
secrets;
|
|
29654
|
+
constructor(server2, onSessionEnd, auth2, signed = server2.sigv4 && !auth2 ? sigv4Fetch({ url: server2.url, sigv4: server2.sigv4, headers: server2.headers }, serverFetch(server2)) : void 0) {
|
|
29487
29655
|
super(new URL(server2.url), {
|
|
29488
|
-
fetch: auth2 ? auth2.provider.fetch(serverFetch(server2)) : serverFetch(server2),
|
|
29656
|
+
fetch: auth2 ? auth2.provider.fetch(serverFetch(server2)) : signed ?? serverFetch(server2),
|
|
29489
29657
|
...auth2 && { authProvider: auth2.provider }
|
|
29490
29658
|
});
|
|
29491
29659
|
this.#onSessionEnd = onSessionEnd;
|
|
29492
29660
|
this.#loginReason = auth2?.reason;
|
|
29661
|
+
this.secrets = signed?.secrets ?? (() => []);
|
|
29493
29662
|
}
|
|
29494
29663
|
async send(...args) {
|
|
29495
29664
|
const hadSession = this.sessionId !== void 0;
|
|
@@ -29669,6 +29838,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29669
29838
|
if (closing2) throw new OwnError("toolscript-mcp is shutting down");
|
|
29670
29839
|
const made = transportOf(key, server2, sessionEnded, auth2, childStderr, share, lazily);
|
|
29671
29840
|
lastError = made.lastError;
|
|
29841
|
+
if (made.transport instanceof HttpTransport && !auth2) secrets = made.transport.secrets;
|
|
29672
29842
|
if (made.child !== void 0) {
|
|
29673
29843
|
children.add(made.child);
|
|
29674
29844
|
if (closing2) made.child.hurry();
|
|
@@ -29716,7 +29886,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29716
29886
|
await client.close().catch(() => {
|
|
29717
29887
|
});
|
|
29718
29888
|
opened.delete(client);
|
|
29719
|
-
if (isOAuthStop(err) || err instanceof OwnError || err instanceof BrokerError)
|
|
29889
|
+
if (isOAuthStop(err) || err instanceof OwnError || err instanceof BrokerError || err instanceof AwsCredentialsError)
|
|
29720
29890
|
fail3(stderr === "" ? errorText(err) : `${errorText(err)}. ${STDERR_UNSHOWN}`);
|
|
29721
29891
|
else fail3(stderr === "" ? errorText(err) : `${errorText(err)}. ${STDERR_UNSHOWN}`, "the connect failed");
|
|
29722
29892
|
}
|
|
@@ -30254,17 +30424,17 @@ var launch = (o) => {
|
|
|
30254
30424
|
};
|
|
30255
30425
|
|
|
30256
30426
|
// src/host/toolscache.ts
|
|
30257
|
-
import { createHash as
|
|
30427
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
30258
30428
|
|
|
30259
30429
|
// src/host/shapes.ts
|
|
30260
|
-
import { createHash as
|
|
30430
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
30261
30431
|
import fs10 from "node:fs";
|
|
30262
30432
|
var hashes = /* @__PURE__ */ new WeakMap();
|
|
30263
30433
|
var schemaHash = (inputSchema) => {
|
|
30264
30434
|
const key = inputSchema !== null && typeof inputSchema === "object" ? inputSchema : void 0;
|
|
30265
30435
|
const known = key === void 0 ? void 0 : hashes.get(key);
|
|
30266
30436
|
if (known !== void 0) return known;
|
|
30267
|
-
const hash =
|
|
30437
|
+
const hash = createHash3("sha256").update(canonicalJson(inputSchema)).digest("hex").slice(0, 32);
|
|
30268
30438
|
if (key !== void 0) hashes.set(key, hash);
|
|
30269
30439
|
return hash;
|
|
30270
30440
|
};
|
|
@@ -30362,7 +30532,7 @@ var write = async (home, learned, log2) => {
|
|
|
30362
30532
|
// src/host/toolscache.ts
|
|
30363
30533
|
import fs11 from "node:fs";
|
|
30364
30534
|
import path8 from "node:path";
|
|
30365
|
-
var toolsKey = (server2) =>
|
|
30535
|
+
var toolsKey = (server2) => createHash4("sha256").update(toolsKeyText(server2, childEnv(server2))).digest("hex");
|
|
30366
30536
|
var read = async (home, log2) => {
|
|
30367
30537
|
try {
|
|
30368
30538
|
const text2 = await readText(toolsFile(home), MAX_CACHE_BYTES);
|
|
@@ -31437,7 +31607,7 @@ import http from "node:http";
|
|
|
31437
31607
|
import path11 from "node:path";
|
|
31438
31608
|
import { parseArgs as parseArgs5 } from "node:util";
|
|
31439
31609
|
var LOGIN_USAGE = "usage: toolscript-mcp login <server> [--config <path>] [--help]";
|
|
31440
|
-
var
|
|
31610
|
+
var failure3 = (err) => errorText(err) || (err instanceof OAuthError && err.errorCode ? `the authorization server answered ${err.errorCode}` : "no reason given");
|
|
31441
31611
|
var NO_REGISTRATION = "Incompatible auth server: does not support dynamic client registration";
|
|
31442
31612
|
var OTHER_RESOURCE = /^Protected resource (\S+) does not match expected/;
|
|
31443
31613
|
var STILL_ASKS = "the server still asks for a login after the token exchange";
|
|
@@ -31445,7 +31615,7 @@ var Reason = class extends Error {
|
|
|
31445
31615
|
};
|
|
31446
31616
|
var notStarted = (err, url2) => {
|
|
31447
31617
|
if (err instanceof Reason) return err.message;
|
|
31448
|
-
const text2 =
|
|
31618
|
+
const text2 = failure3(err);
|
|
31449
31619
|
if (text2 === NO_REGISTRATION)
|
|
31450
31620
|
return 'its authorization server has no dynamic client registration. Calls that need a token need "clientId" in "oauth": see "OAuth login" in the README';
|
|
31451
31621
|
const other = OTHER_RESOURCE.exec(text2)?.[1];
|
|
@@ -31535,7 +31705,7 @@ var metadataLike = (text2) => {
|
|
|
31535
31705
|
};
|
|
31536
31706
|
var invalidText = (err) => {
|
|
31537
31707
|
const issues = err?.issues;
|
|
31538
|
-
return Array.isArray(issues) ? issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") :
|
|
31708
|
+
return Array.isArray(issues) ? issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") : failure3(err);
|
|
31539
31709
|
};
|
|
31540
31710
|
var takesOAuth = async (url2, fetchFn) => {
|
|
31541
31711
|
let unsure = false;
|
|
@@ -31704,7 +31874,7 @@ ${url2.href}`);
|
|
|
31704
31874
|
io2.print(`Logged in to ${key}. It has ${plural2(tools.length)}. The tokens are in ${store}${mode}.`);
|
|
31705
31875
|
return 0;
|
|
31706
31876
|
} catch (err) {
|
|
31707
|
-
io2.print(`login to ${key} failed: ${hide2(
|
|
31877
|
+
io2.print(`login to ${key} failed: ${hide2(failure3(err))}`);
|
|
31708
31878
|
return 1;
|
|
31709
31879
|
} finally {
|
|
31710
31880
|
clearTimeout(timer);
|
|
@@ -33233,7 +33403,7 @@ import os4 from "node:os";
|
|
|
33233
33403
|
import path14 from "node:path";
|
|
33234
33404
|
|
|
33235
33405
|
// src/host/run.ts
|
|
33236
|
-
import { createHash as
|
|
33406
|
+
import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID5 } from "node:crypto";
|
|
33237
33407
|
import fs15 from "node:fs";
|
|
33238
33408
|
import path13 from "node:path";
|
|
33239
33409
|
|
|
@@ -33571,7 +33741,7 @@ var saveFile = async (dir, name, data) => {
|
|
|
33571
33741
|
await fs15.promises.writeFile(file2, text2, { mode: 384 });
|
|
33572
33742
|
return { ok: true, value: file2 };
|
|
33573
33743
|
};
|
|
33574
|
-
var
|
|
33744
|
+
var sha2562 = (bytes) => createHash5("sha256").update(bytes).digest("hex");
|
|
33575
33745
|
var writeAttachments = async (dir, files, written2) => {
|
|
33576
33746
|
if (files.length === 0) return;
|
|
33577
33747
|
await fs15.promises.mkdir(dir, { recursive: true, mode: 448 });
|
|
@@ -33584,7 +33754,7 @@ var writeAttachments = async (dir, files, written2) => {
|
|
|
33584
33754
|
});
|
|
33585
33755
|
throw err;
|
|
33586
33756
|
});
|
|
33587
|
-
done.push({ file: file2, record: { mimeType, bytes: bytes.length, sha256:
|
|
33757
|
+
done.push({ file: file2, record: { mimeType, bytes: bytes.length, sha256: sha2562(bytes) } });
|
|
33588
33758
|
}
|
|
33589
33759
|
} catch (err) {
|
|
33590
33760
|
await Promise.all(done.map(({ file: file2 }) => fs15.promises.rm(file2, { force: true }).catch(() => {
|
|
@@ -33609,7 +33779,7 @@ var showImages = async (written2, returned) => {
|
|
|
33609
33779
|
if (stat.size !== record2.bytes) return "changed";
|
|
33610
33780
|
const bytes = await fs15.promises.readFile(file2).catch(() => void 0);
|
|
33611
33781
|
if (bytes === void 0) return "unreadable";
|
|
33612
|
-
if (bytes.length !== record2.bytes ||
|
|
33782
|
+
if (bytes.length !== record2.bytes || sha2562(bytes) !== record2.sha256) return "changed";
|
|
33613
33783
|
if (!holdsImage(record2.mimeType, bytes)) return "not-image";
|
|
33614
33784
|
total += bytes.length;
|
|
33615
33785
|
return { data: bytes.toString("base64"), mimeType: record2.mimeType };
|
|
@@ -33802,7 +33972,7 @@ could not answer message ${id} of the program: ${errorText(err)}`;
|
|
|
33802
33972
|
const answerCall = async (id, tool, args, sentKey) => {
|
|
33803
33973
|
if (ended) return;
|
|
33804
33974
|
const began = performance.now();
|
|
33805
|
-
const { code:
|
|
33975
|
+
const { code: failure4, cls, untrusted: fromTool, ...r } = await callTool(id, tool, args);
|
|
33806
33976
|
if (closed) return;
|
|
33807
33977
|
if (fromTool === true) untrusted = true;
|
|
33808
33978
|
const tainted = untrusted;
|
|
@@ -33811,7 +33981,7 @@ could not answer message ${id} of the program: ${errorText(err)}`;
|
|
|
33811
33981
|
decision: decided.get(id),
|
|
33812
33982
|
ms: performance.now() - began,
|
|
33813
33983
|
ok: r.ok,
|
|
33814
|
-
...r.ok ? {} : { error:
|
|
33984
|
+
...r.ok ? {} : { error: failure4 ?? "failed" },
|
|
33815
33985
|
...r.ok || cls === void 0 ? {} : { class: cls }
|
|
33816
33986
|
});
|
|
33817
33987
|
const key = sentKey ?? callKey(tool, args);
|