@livx.cc/agentx 0.99.135 → 0.99.137
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +50 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel-D-8AGmAT.d.ts → secondChannel-BqUiRI5w.d.ts} +3 -0
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-
|
|
2
|
+
import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-BqUiRI5w.js';
|
|
3
3
|
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
4
4
|
import { M as Message, U as UserQuestion, H as HostBridge, c as ContentPart, o as MessageContent } from './tools-DwfeF8VQ.js';
|
|
5
5
|
|
package/dist/cli.js
CHANGED
|
@@ -5872,9 +5872,10 @@ var Agent = class _Agent {
|
|
|
5872
5872
|
if (o.maxRepeats && repeats >= o.maxRepeats) return kill("loop");
|
|
5873
5873
|
toolCallsTotal += toolCalls.length;
|
|
5874
5874
|
if (o.maxToolCalls && toolCallsTotal > o.maxToolCalls) return kill("max_tool_calls");
|
|
5875
|
+
const cutAtCap = res.finishReason === "max_tokens" || res.finishReason === "length";
|
|
5875
5876
|
for (const tc of toolCalls) {
|
|
5876
5877
|
if (o.signal?.aborted) return kill("aborted");
|
|
5877
|
-
const raw = await this.dispatch(tc);
|
|
5878
|
+
const raw = cutAtCap && tc === toolCalls[toolCalls.length - 1] ? this.cutAtCapResult(tc) : await this.dispatch(tc);
|
|
5878
5879
|
let content;
|
|
5879
5880
|
if (typeof raw === "string") {
|
|
5880
5881
|
content = nonEmptyResult(raw, tc.function.name);
|
|
@@ -6092,6 +6093,15 @@ var Agent = class _Agent {
|
|
|
6092
6093
|
const invoked = new Set([...this.invokedTools].map(toolKey));
|
|
6093
6094
|
return [...this.fabricatedClaims].filter((n) => !invoked.has(toolKey(n)));
|
|
6094
6095
|
}
|
|
6096
|
+
/** A tool call the output cap cut mid-arguments: never run it (its args are incomplete), and say WHY —
|
|
6097
|
+
* a generic "missing argument" makes the model re-send the same oversized call. */
|
|
6098
|
+
cutAtCapResult(tc) {
|
|
6099
|
+
this.invokedTools.add(tc.function.name);
|
|
6100
|
+
const msg = `Error: your reply hit the output token limit while writing this ${tc.function.name} call, so its arguments were cut off and it did NOT run. Re-sending the same call will be cut again. Split it: write a smaller first part now, then add the rest in further calls (e.g. Edit to append), each well under the limit.`;
|
|
6101
|
+
log9.warn(`${tc.function.name} cut at the output cap \u2014 not run`);
|
|
6102
|
+
this.options.host?.notify?.({ kind: "tool_result", id: tc.id ?? "", output: msg, isError: true });
|
|
6103
|
+
return msg;
|
|
6104
|
+
}
|
|
6095
6105
|
async dispatch(tc) {
|
|
6096
6106
|
this.invokedTools.add(tc.function.name);
|
|
6097
6107
|
const tool = this.activeTools.find((t) => t.name === tc.function.name);
|
|
@@ -14912,19 +14922,21 @@ var McpOAuth = class {
|
|
|
14912
14922
|
const verifier = b64url(randomBytes2(32));
|
|
14913
14923
|
const challenge = b64url(createHash2("sha256").update(verifier).digest());
|
|
14914
14924
|
const state = b64url(randomBytes2(16));
|
|
14915
|
-
const { code, redirectUri } = await this.captureCode(meta
|
|
14925
|
+
const { code, redirectUri } = await this.captureCode(meta, clientId, challenge, state);
|
|
14916
14926
|
const tok = await this.exchange(meta.token_endpoint, {
|
|
14917
14927
|
grant_type: "authorization_code",
|
|
14918
14928
|
code,
|
|
14919
14929
|
redirect_uri: redirectUri,
|
|
14920
14930
|
client_id: clientId,
|
|
14921
|
-
code_verifier: verifier
|
|
14931
|
+
code_verifier: verifier,
|
|
14932
|
+
...meta.resource ? { resource: meta.resource } : {}
|
|
14922
14933
|
});
|
|
14923
14934
|
const bundle = {
|
|
14924
14935
|
access_token: tok.access_token,
|
|
14925
14936
|
refresh_token: tok.refresh_token,
|
|
14926
14937
|
expires_at: tok.expires_in ? this.options.now() + tok.expires_in * 1e3 : void 0,
|
|
14927
14938
|
client_id: clientId,
|
|
14939
|
+
resource: meta.resource,
|
|
14928
14940
|
token_endpoint: meta.token_endpoint
|
|
14929
14941
|
};
|
|
14930
14942
|
const store = this.load();
|
|
@@ -14945,7 +14957,8 @@ var McpOAuth = class {
|
|
|
14945
14957
|
const tok = await this.exchange(b.token_endpoint, {
|
|
14946
14958
|
grant_type: "refresh_token",
|
|
14947
14959
|
refresh_token: b.refresh_token,
|
|
14948
|
-
client_id: b.client_id ?? ""
|
|
14960
|
+
client_id: b.client_id ?? "",
|
|
14961
|
+
...b.resource ? { resource: b.resource } : {}
|
|
14949
14962
|
});
|
|
14950
14963
|
b.access_token = tok.access_token;
|
|
14951
14964
|
if (tok.refresh_token) b.refresh_token = tok.refresh_token;
|
|
@@ -14961,20 +14974,42 @@ var McpOAuth = class {
|
|
|
14961
14974
|
return !!this.load()[serverUrl];
|
|
14962
14975
|
}
|
|
14963
14976
|
// -- internals ----------------------------------------------------------------
|
|
14964
|
-
/** Discover the Authorization Server
|
|
14977
|
+
/** Discover the Authorization Server: RFC 9728 Protected Resource Metadata first, then the server's origin. */
|
|
14965
14978
|
async discover(serverUrl) {
|
|
14966
|
-
const origin = new URL(serverUrl)
|
|
14967
|
-
const
|
|
14968
|
-
|
|
14979
|
+
const { origin, pathname } = new URL(serverUrl);
|
|
14980
|
+
const path = pathname === "/" ? "" : pathname;
|
|
14981
|
+
const prm = await this.firstJson(
|
|
14982
|
+
[`${origin}/.well-known/oauth-protected-resource${path}`, `${origin}/.well-known/oauth-protected-resource`],
|
|
14983
|
+
(m) => m?.authorization_servers?.length
|
|
14984
|
+
);
|
|
14985
|
+
const issuer = prm?.authorization_servers?.[0] ?? origin;
|
|
14986
|
+
const { origin: asOrigin, pathname: asPathname } = new URL(issuer);
|
|
14987
|
+
const asPath = asPathname === "/" ? "" : asPathname.replace(/\/$/, "");
|
|
14988
|
+
const candidates = [.../* @__PURE__ */ new Set([
|
|
14989
|
+
`${asOrigin}/.well-known/oauth-authorization-server${asPath}`,
|
|
14990
|
+
// RFC 8414 path insertion
|
|
14991
|
+
`${asOrigin}${asPath}/.well-known/oauth-authorization-server`,
|
|
14992
|
+
// path-suffix servers
|
|
14993
|
+
`${asOrigin}${asPath}/.well-known/openid-configuration`,
|
|
14994
|
+
`${asOrigin}/.well-known/oauth-authorization-server`,
|
|
14995
|
+
`${asOrigin}/.well-known/openid-configuration`
|
|
14996
|
+
])];
|
|
14997
|
+
const meta = await this.firstJson(candidates, (m) => m?.authorization_endpoint && m?.token_endpoint);
|
|
14998
|
+
if (!meta) throw new Error(`could not discover OAuth metadata for ${serverUrl} (tried ${candidates.join(", ")})`);
|
|
14999
|
+
return { ...meta, resource: prm?.resource, scopes: prm?.scopes_supported };
|
|
15000
|
+
}
|
|
15001
|
+
/** First URL whose JSON body passes `valid`; a failed candidate just moves on to the next. */
|
|
15002
|
+
async firstJson(urls, valid) {
|
|
15003
|
+
for (const u of urls) {
|
|
14969
15004
|
try {
|
|
14970
15005
|
const r = await this.options.fetchImpl(u);
|
|
14971
15006
|
if (!r.ok) continue;
|
|
14972
15007
|
const m = await r.json();
|
|
14973
|
-
if (m
|
|
15008
|
+
if (valid(m)) return m;
|
|
14974
15009
|
} catch {
|
|
14975
15010
|
}
|
|
14976
15011
|
}
|
|
14977
|
-
|
|
15012
|
+
return void 0;
|
|
14978
15013
|
}
|
|
14979
15014
|
/** Dynamic Client Registration (RFC 7591) when no client_id was configured and the server supports it. */
|
|
14980
15015
|
async registerClient(meta, serverUrl) {
|
|
@@ -14992,7 +15027,7 @@ var McpOAuth = class {
|
|
|
14992
15027
|
return j.client_id;
|
|
14993
15028
|
}
|
|
14994
15029
|
/** Start a one-route loopback server, open the browser, and resolve with the returned auth code. */
|
|
14995
|
-
captureCode(
|
|
15030
|
+
captureCode(meta, clientId, challenge, state) {
|
|
14996
15031
|
return new Promise((resolve6, reject) => {
|
|
14997
15032
|
const server = createServer((req, res) => {
|
|
14998
15033
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
@@ -15017,14 +15052,16 @@ var McpOAuth = class {
|
|
|
15017
15052
|
server.listen(0, "127.0.0.1", async () => {
|
|
15018
15053
|
const port = server.address().port;
|
|
15019
15054
|
redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
15020
|
-
const auth = new URL(
|
|
15055
|
+
const auth = new URL(meta.authorization_endpoint);
|
|
15021
15056
|
auth.searchParams.set("response_type", "code");
|
|
15022
15057
|
auth.searchParams.set("client_id", clientId);
|
|
15023
15058
|
auth.searchParams.set("redirect_uri", redirectUri);
|
|
15024
15059
|
auth.searchParams.set("code_challenge", challenge);
|
|
15025
15060
|
auth.searchParams.set("code_challenge_method", "S256");
|
|
15026
15061
|
auth.searchParams.set("state", state);
|
|
15027
|
-
|
|
15062
|
+
const scope = this.options.scope ?? meta.scopes?.join(" ");
|
|
15063
|
+
if (scope) auth.searchParams.set("scope", scope);
|
|
15064
|
+
if (meta.resource) auth.searchParams.set("resource", meta.resource);
|
|
15028
15065
|
try {
|
|
15029
15066
|
await this.options.openBrowser(auth.toString());
|
|
15030
15067
|
} catch (e) {
|