@vybestack/llxprt-code-tools 0.11.0 → 0.12.0-nightly.260910.2aac6841e
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/src/acquisition/bounded-http-response.d.ts +14 -17
- package/dist/src/acquisition/bounded-http-response.js +124 -99
- package/dist/src/acquisition/bounded-http-response.js.map +1 -1
- package/dist/src/formatters/ToolFormatter.js +7 -8
- package/dist/src/formatters/ToolFormatter.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces/ISkillService.d.ts +0 -6
- package/dist/src/interfaces/IToolHost.d.ts +0 -11
- package/dist/src/test-utils/loopback-test-helpers.d.ts +20 -0
- package/dist/src/test-utils/loopback-test-helpers.js +158 -0
- package/dist/src/test-utils/loopback-test-helpers.js.map +1 -0
- package/dist/src/tools/activate-skill.js +7 -18
- package/dist/src/tools/activate-skill.js.map +1 -1
- package/dist/src/tools/codesearch.js +0 -1
- package/dist/src/tools/codesearch.js.map +1 -1
- package/dist/src/tools/direct-web-fetch.js +25 -14
- package/dist/src/tools/direct-web-fetch.js.map +1 -1
- package/dist/src/tools/exa-web-search.js +0 -1
- package/dist/src/tools/exa-web-search.js.map +1 -1
- package/dist/src/tools/github-ops.d.ts +1 -1
- package/dist/src/tools/github-ops.js +16 -1
- package/dist/src/tools/github-ops.js.map +1 -1
- package/dist/src/tools/github.js +3 -2
- package/dist/src/tools/github.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +0 -4
- package/dist/src/tools/read-file.js +1 -5
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/tool-registry.js +0 -11
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/types/wire-types.d.ts +11 -0
- package/dist/src/utils/fileUtils.js +4 -1
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/flatOrNestedSetting.d.ts +19 -0
- package/dist/src/utils/flatOrNestedSetting.js +55 -0
- package/dist/src/utils/flatOrNestedSetting.js.map +1 -0
- package/dist/src/utils/imageResize.d.ts +11 -1
- package/dist/src/utils/imageResize.js +27 -9
- package/dist/src/utils/imageResize.js.map +1 -1
- package/dist/src/utils/imageTokenEstimation.d.ts +25 -1
- package/dist/src/utils/imageTokenEstimation.js +93 -7
- package/dist/src/utils/imageTokenEstimation.js.map +1 -1
- package/dist/src/utils/mediaUtils.d.ts +2 -2
- package/package.json +7 -4
- package/src/acquisition/bounded-http-response.ts +132 -112
- package/src/formatters/ToolFormatter.ts +8 -8
- package/src/index.ts +1 -0
- package/src/interfaces/ISkillService.ts +0 -7
- package/src/interfaces/IToolHost.ts +0 -13
- package/src/test-utils/loopback-test-helpers.ts +214 -0
- package/src/tools/activate-skill.ts +9 -23
- package/src/tools/codesearch.ts +2 -4
- package/src/tools/direct-web-fetch.ts +32 -20
- package/src/tools/exa-web-search.ts +1 -3
- package/src/tools/github-ops.ts +18 -1
- package/src/tools/github.ts +4 -2
- package/src/tools/read-file.ts +1 -14
- package/src/tools/tool-registry.ts +0 -15
- package/src/types/wire-types.ts +8 -0
- package/src/utils/fileUtils.ts +9 -0
- package/src/utils/flatOrNestedSetting.ts +63 -0
- package/src/utils/imageResize.ts +41 -9
- package/src/utils/imageTokenEstimation.ts +109 -5
- package/src/utils/mediaUtils.ts +2 -2
|
@@ -115,17 +115,4 @@ export interface IToolHost {
|
|
|
115
115
|
|
|
116
116
|
/** Returns the git stats service used for edit metadata when enabled. */
|
|
117
117
|
getGitStatsService?(): IToolHostGitStatsService | undefined;
|
|
118
|
-
|
|
119
|
-
/** Returns provider server-tools support for tools that delegate to provider-native tools. */
|
|
120
|
-
getServerToolsProvider?(): {
|
|
121
|
-
getServerTools: () => string[];
|
|
122
|
-
invokeServerTool: (
|
|
123
|
-
name: string,
|
|
124
|
-
params: { prompt: string },
|
|
125
|
-
options: { signal: AbortSignal },
|
|
126
|
-
) => Promise<unknown>;
|
|
127
|
-
} | null;
|
|
128
|
-
|
|
129
|
-
/** Whether the host has a provider manager configured. */
|
|
130
|
-
hasProviderManager?(): boolean;
|
|
131
118
|
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { afterEach } from 'bun:test';
|
|
8
|
+
import http from 'node:http';
|
|
9
|
+
import type { AddressInfo } from 'node:net';
|
|
10
|
+
|
|
11
|
+
export type LoopbackHandler = (
|
|
12
|
+
req: http.IncomingMessage,
|
|
13
|
+
res: http.ServerResponse,
|
|
14
|
+
) => void | Promise<void>;
|
|
15
|
+
|
|
16
|
+
type FetchImplementation = (
|
|
17
|
+
input: RequestInfo | URL,
|
|
18
|
+
init?: RequestInit,
|
|
19
|
+
) => Promise<Response>;
|
|
20
|
+
|
|
21
|
+
export interface LoopbackHarness {
|
|
22
|
+
startServer(handler: LoopbackHandler): Promise<http.Server>;
|
|
23
|
+
serverUrl(server: http.Server): string;
|
|
24
|
+
installFetchRouter(server: http.Server): void;
|
|
25
|
+
trackWriter(writer: Promise<void>): void;
|
|
26
|
+
settleWriters(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface KeyStorageLike {
|
|
30
|
+
resolveKey(name: string): Promise<string | null>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createLoopbackHarness(routedOrigin?: string): LoopbackHarness {
|
|
34
|
+
const nativeFetch = globalThis.fetch;
|
|
35
|
+
const servers: http.Server[] = [];
|
|
36
|
+
const pendingWriters = new Set<Promise<void>>();
|
|
37
|
+
let routerInstalled = false;
|
|
38
|
+
|
|
39
|
+
afterEach(async () => {
|
|
40
|
+
if (routerInstalled) {
|
|
41
|
+
setGlobalFetch(nativeFetch);
|
|
42
|
+
routerInstalled = false;
|
|
43
|
+
}
|
|
44
|
+
await closeServers(servers);
|
|
45
|
+
await Promise.allSettled([...pendingWriters]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const installFetchRouter = (server: http.Server): void => {
|
|
49
|
+
if (routedOrigin === undefined) {
|
|
50
|
+
throw new Error('Expected a routed origin for the fetch router');
|
|
51
|
+
}
|
|
52
|
+
if (routerInstalled) {
|
|
53
|
+
throw new Error('The fetch router is already installed');
|
|
54
|
+
}
|
|
55
|
+
setGlobalFetch(createFetchRouter(server, routedOrigin, nativeFetch));
|
|
56
|
+
routerInstalled = true;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const trackWriter = (writer: Promise<void>): void => {
|
|
60
|
+
pendingWriters.add(writer);
|
|
61
|
+
void writer.then(
|
|
62
|
+
() => pendingWriters.delete(writer),
|
|
63
|
+
() => pendingWriters.delete(writer),
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
startServer: (handler: LoopbackHandler): Promise<http.Server> =>
|
|
69
|
+
startServer(handler, servers),
|
|
70
|
+
serverUrl: (server: http.Server): string =>
|
|
71
|
+
`http://127.0.0.1:${serverPort(server)}/`,
|
|
72
|
+
installFetchRouter,
|
|
73
|
+
trackWriter,
|
|
74
|
+
settleWriters: async (): Promise<void> => {
|
|
75
|
+
await Promise.allSettled([...pendingWriters]);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function collectRequestBody(req: http.IncomingMessage): Promise<string> {
|
|
81
|
+
const chunks: Buffer[] = [];
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
let settled = false;
|
|
84
|
+
const onData = (chunk: Buffer): void => {
|
|
85
|
+
chunks.push(chunk);
|
|
86
|
+
};
|
|
87
|
+
const cleanup = (): void => {
|
|
88
|
+
req.removeListener('data', onData);
|
|
89
|
+
req.removeListener('end', settleSuccess);
|
|
90
|
+
req.removeListener('error', settleFailure);
|
|
91
|
+
req.removeListener('aborted', settleAborted);
|
|
92
|
+
req.removeListener('close', settleClosed);
|
|
93
|
+
};
|
|
94
|
+
const settleSuccess = (): void => {
|
|
95
|
+
if (settled) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
settled = true;
|
|
99
|
+
cleanup();
|
|
100
|
+
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
101
|
+
};
|
|
102
|
+
const settleFailure = (error: Error): void => {
|
|
103
|
+
if (settled) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
settled = true;
|
|
107
|
+
cleanup();
|
|
108
|
+
reject(error);
|
|
109
|
+
};
|
|
110
|
+
const settleAborted = (): void => {
|
|
111
|
+
settleFailure(new Error('Request aborted before body completed'));
|
|
112
|
+
};
|
|
113
|
+
const settleClosed = (): void => {
|
|
114
|
+
if (!req.complete) {
|
|
115
|
+
settleAborted();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
req.on('data', onData);
|
|
120
|
+
req.once('end', settleSuccess);
|
|
121
|
+
req.once('error', settleFailure);
|
|
122
|
+
req.once('aborted', settleAborted);
|
|
123
|
+
req.once('close', settleClosed);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function createKeyStorage(
|
|
128
|
+
resolveKey: (name: string) => Promise<string | null> = async () => null,
|
|
129
|
+
): KeyStorageLike {
|
|
130
|
+
return { resolveKey };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function startServer(
|
|
134
|
+
handler: LoopbackHandler,
|
|
135
|
+
servers: http.Server[],
|
|
136
|
+
): Promise<http.Server> {
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
const server = http.createServer((req, res) => {
|
|
139
|
+
Promise.resolve(handler(req, res)).catch((error: unknown) => {
|
|
140
|
+
res.destroy(normalizeError(error));
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
const onError = (error: Error): void => reject(error);
|
|
144
|
+
server.once('error', onError);
|
|
145
|
+
server.listen(0, '127.0.0.1', () => {
|
|
146
|
+
server.removeListener('error', onError);
|
|
147
|
+
servers.push(server);
|
|
148
|
+
resolve(server);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function closeServers(servers: http.Server[]): Promise<void> {
|
|
154
|
+
let server: http.Server | undefined = servers.pop();
|
|
155
|
+
while (server !== undefined) {
|
|
156
|
+
const currentServer = server;
|
|
157
|
+
currentServer.closeAllConnections();
|
|
158
|
+
await new Promise<void>((resolve) => currentServer.close(() => resolve()));
|
|
159
|
+
server = servers.pop();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function createFetchRouter(
|
|
164
|
+
server: http.Server,
|
|
165
|
+
routedOrigin: string,
|
|
166
|
+
nativeFetch: FetchImplementation,
|
|
167
|
+
): FetchImplementation {
|
|
168
|
+
const loopbackOrigin = `http://127.0.0.1:${serverPort(server)}`;
|
|
169
|
+
return (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
170
|
+
const inputUrl = new URL(
|
|
171
|
+
typeof input === 'string' || input instanceof URL ? input : input.url,
|
|
172
|
+
);
|
|
173
|
+
if (inputUrl.origin !== routedOrigin) {
|
|
174
|
+
return Promise.reject(
|
|
175
|
+
new Error(`Refusing unrouted fetch; expected ${routedOrigin}`),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const loopbackUrl = new URL(inputUrl);
|
|
179
|
+
const replacementOrigin = new URL(loopbackOrigin);
|
|
180
|
+
loopbackUrl.protocol = replacementOrigin.protocol;
|
|
181
|
+
loopbackUrl.hostname = replacementOrigin.hostname;
|
|
182
|
+
loopbackUrl.port = replacementOrigin.port;
|
|
183
|
+
const routedInput =
|
|
184
|
+
input instanceof Request ? new Request(loopbackUrl, input) : loopbackUrl;
|
|
185
|
+
return nativeFetch(routedInput, init);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function setGlobalFetch(fetchImplementation: FetchImplementation): void {
|
|
190
|
+
Object.defineProperty(globalThis, 'fetch', {
|
|
191
|
+
configurable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: fetchImplementation,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function serverPort(server: http.Server): number {
|
|
198
|
+
const address: string | AddressInfo | null = server.address();
|
|
199
|
+
if (typeof address !== 'object' || address === null) {
|
|
200
|
+
throw new Error('Expected a listening server address with a port');
|
|
201
|
+
}
|
|
202
|
+
const { port } = address;
|
|
203
|
+
if (typeof port !== 'number') {
|
|
204
|
+
throw new Error('Expected a numeric listening port');
|
|
205
|
+
}
|
|
206
|
+
return port;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function normalizeError(error: unknown): Error {
|
|
210
|
+
if (error instanceof Error) {
|
|
211
|
+
return error;
|
|
212
|
+
}
|
|
213
|
+
return new Error(String(error));
|
|
214
|
+
}
|
|
@@ -31,8 +31,6 @@ class ActivateSkillToolInvocation extends BaseToolInvocation<
|
|
|
31
31
|
ActivateSkillToolParams,
|
|
32
32
|
ToolResult
|
|
33
33
|
> {
|
|
34
|
-
private cachedFolderStructure: string | undefined;
|
|
35
|
-
|
|
36
34
|
constructor(
|
|
37
35
|
private readonly skillService: ISkillService,
|
|
38
36
|
params: ActivateSkillToolParams,
|
|
@@ -52,12 +50,6 @@ class ActivateSkillToolInvocation extends BaseToolInvocation<
|
|
|
52
50
|
return `"${skillName}" (?) unknown skill`;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
private async getOrFetchFolderStructure(skillName: string): Promise<string> {
|
|
56
|
-
this.cachedFolderStructure ??=
|
|
57
|
-
await this.skillService.getFolderStructure(skillName);
|
|
58
|
-
return this.cachedFolderStructure;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
53
|
override async shouldConfirmExecute(
|
|
62
54
|
_abortSignal: AbortSignal,
|
|
63
55
|
): Promise<ToolCallConfirmationDetails | false> {
|
|
@@ -72,18 +64,13 @@ class ActivateSkillToolInvocation extends BaseToolInvocation<
|
|
|
72
64
|
return false;
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
const folderStructure = await this.getOrFetchFolderStructure(skillName);
|
|
76
|
-
|
|
77
67
|
const confirmationDetails: ToolCallConfirmationDetails = {
|
|
78
68
|
type: 'info',
|
|
79
69
|
title: `Activate Skill: ${skillName}`,
|
|
80
70
|
prompt: `You are about to enable the specialized agent skill **${skillName}**.
|
|
81
71
|
|
|
82
72
|
**Description:**
|
|
83
|
-
${skill.description ?? ''}
|
|
84
|
-
|
|
85
|
-
**Resources to be shared with the model:**
|
|
86
|
-
${folderStructure}`,
|
|
73
|
+
${skill.description ?? ''}`,
|
|
87
74
|
onConfirm: async (outcome: ToolConfirmationOutcome) => {
|
|
88
75
|
await this.publishPolicyUpdate(outcome);
|
|
89
76
|
},
|
|
@@ -110,21 +97,20 @@ ${folderStructure}`,
|
|
|
110
97
|
};
|
|
111
98
|
}
|
|
112
99
|
|
|
113
|
-
const folderStructure =
|
|
114
|
-
result.folderStructure ??
|
|
115
|
-
(await this.getOrFetchFolderStructure(skillName));
|
|
116
|
-
|
|
117
100
|
return {
|
|
118
101
|
llmContent: `<activated_skill name="${skillName}">
|
|
119
102
|
<instructions>
|
|
120
103
|
${result.instructions ?? ''}
|
|
121
104
|
</instructions>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
105
|
+
${
|
|
106
|
+
result.resourceDirectory
|
|
107
|
+
? `<resource_directory>
|
|
108
|
+
${result.resourceDirectory}
|
|
109
|
+
</resource_directory>`
|
|
110
|
+
: ''
|
|
111
|
+
}
|
|
126
112
|
</activated_skill>`,
|
|
127
|
-
returnDisplay: `Skill **${skillName}** activated. Resources loaded from \`${result.resourceDirectory ?? ''}
|
|
113
|
+
returnDisplay: `Skill **${skillName}** activated. Resources loaded from \`${result.resourceDirectory ?? ''}\` (if a resource directory is present, it has been added to the workspace context).`,
|
|
128
114
|
};
|
|
129
115
|
}
|
|
130
116
|
}
|
package/src/tools/codesearch.ts
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
* Licensed under the MIT License.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import fetch from 'node-fetch';
|
|
12
|
-
|
|
13
11
|
import type {
|
|
14
12
|
ISettingsService,
|
|
15
13
|
IToolKeyStorage,
|
|
@@ -164,7 +162,7 @@ class CodeSearchToolInvocation extends BaseToolInvocation<
|
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
private async readResponseBody(
|
|
167
|
-
response:
|
|
165
|
+
response: Response,
|
|
168
166
|
signal: AbortSignal,
|
|
169
167
|
cancelRequest: () => void,
|
|
170
168
|
): Promise<string> {
|
|
@@ -182,7 +180,7 @@ class CodeSearchToolInvocation extends BaseToolInvocation<
|
|
|
182
180
|
* the HTTP status is preserved in the thrown error message.
|
|
183
181
|
*/
|
|
184
182
|
private async readErrorResponseBody(
|
|
185
|
-
response:
|
|
183
|
+
response: Response,
|
|
186
184
|
signal: AbortSignal,
|
|
187
185
|
cancelRequest: () => void,
|
|
188
186
|
): Promise<string> {
|
|
@@ -20,10 +20,8 @@ import { DIRECT_WEB_FETCH_TOOL } from '../types/tool-names.js';
|
|
|
20
20
|
import { ToolErrorType } from '../types/tool-error.js';
|
|
21
21
|
import { stringOrDefault } from '../utils/stringCoalescing.js';
|
|
22
22
|
import type { IToolHost, IToolMessageBus } from '../interfaces/index.js';
|
|
23
|
-
|
|
24
|
-
import fetch, { type RequestInit } from 'node-fetch';
|
|
23
|
+
import { htmlToText } from 'html-to-text';
|
|
25
24
|
import TurndownService from 'turndown';
|
|
26
|
-
import * as cheerio from 'cheerio';
|
|
27
25
|
import { retryWithBackoff } from '../utils/retry.js';
|
|
28
26
|
import { ensureJsonSafe } from '../utils/unicodeUtils.js';
|
|
29
27
|
import { createByteBudget } from '../acquisition/index.js';
|
|
@@ -37,11 +35,24 @@ const FETCH_BYTE_BUDGET = createByteBudget(MAX_RESPONSE_SIZE);
|
|
|
37
35
|
const DEFAULT_TIMEOUT = 30 * 1000; // 30 seconds
|
|
38
36
|
const MAX_TIMEOUT = 120 * 1000; // 2 minutes
|
|
39
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Every 4xx response is terminal for direct fetch. The shared retry helper also
|
|
40
|
+
* retries 401, 403, and 429 for consumers whose authentication or quota state
|
|
41
|
+
* can change between attempts.
|
|
42
|
+
*/
|
|
43
|
+
const TERMINAL_4XX_PREFIX = 400;
|
|
44
|
+
const TERMINAL_5XX_PREFIX = 500;
|
|
45
|
+
|
|
40
46
|
/** A fetched response paired with its per-attempt cancellation handle. */
|
|
41
47
|
interface FetchedResponse {
|
|
42
|
-
readonly response:
|
|
48
|
+
readonly response: Response;
|
|
43
49
|
readonly cancelRequest: () => void;
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
/** True when a status is a client error (4xx) that must not be retried. */
|
|
53
|
+
function isTerminal4xx(status: number): boolean {
|
|
54
|
+
return status >= TERMINAL_4XX_PREFIX && status < TERMINAL_5XX_PREFIX;
|
|
55
|
+
}
|
|
45
56
|
const ACCEPT_HEADERS: Record<DirectWebFetchToolParams['format'], string> = {
|
|
46
57
|
markdown:
|
|
47
58
|
'text/markdown;q=1.0, text/x-markdown;q=0.9, text/plain;q=0.8, text/html;q=0.7, */*;q=0.1',
|
|
@@ -211,15 +222,23 @@ class DirectWebFetchToolInvocation extends BaseToolInvocation<
|
|
|
211
222
|
Accept: ACCEPT_HEADERS[this.params.format],
|
|
212
223
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
213
224
|
},
|
|
214
|
-
}
|
|
225
|
+
});
|
|
215
226
|
|
|
216
227
|
const cancelRequest = (): void => attemptController.abort();
|
|
217
228
|
|
|
218
229
|
if (!resp.ok) {
|
|
219
230
|
disposeHttpResponseBody(resp, cancelRequest);
|
|
220
|
-
const error = new Error(
|
|
231
|
+
const error: Error & { status?: number } = new Error(
|
|
221
232
|
`Request failed with status code: ${resp.status}`,
|
|
222
|
-
)
|
|
233
|
+
);
|
|
234
|
+
// A 4xx is terminal here: the request URL and headers are in user
|
|
235
|
+
// control, so a client status is fixed by the caller, not by re-issuing
|
|
236
|
+
// the request. The shared retry helper would otherwise retry its
|
|
237
|
+
// previously-retryable 401/403/429 statuses, so each 4xx error is
|
|
238
|
+
// re-thrown locally as a plain Error without the status property.
|
|
239
|
+
if (isTerminal4xx(resp.status)) {
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
223
242
|
error.status = resp.status;
|
|
224
243
|
throw error;
|
|
225
244
|
}
|
|
@@ -238,7 +257,7 @@ class DirectWebFetchToolInvocation extends BaseToolInvocation<
|
|
|
238
257
|
}
|
|
239
258
|
|
|
240
259
|
private async readBoundedResponse(
|
|
241
|
-
response:
|
|
260
|
+
response: Response,
|
|
242
261
|
signal: AbortSignal,
|
|
243
262
|
cancelRequest: () => void,
|
|
244
263
|
): Promise<string> {
|
|
@@ -280,20 +299,16 @@ class DirectWebFetchToolInvocation extends BaseToolInvocation<
|
|
|
280
299
|
if (!(error instanceof Error)) return String(error);
|
|
281
300
|
|
|
282
301
|
let errorMessage = error.message;
|
|
283
|
-
|
|
284
|
-
if (this.hasTruthyCause(err)) {
|
|
302
|
+
if (this.isTruthyCause(error.cause)) {
|
|
285
303
|
const causeMessage =
|
|
286
|
-
|
|
304
|
+
error.cause instanceof Error
|
|
305
|
+
? error.cause.message
|
|
306
|
+
: String(error.cause);
|
|
287
307
|
errorMessage += `: ${causeMessage}`;
|
|
288
308
|
}
|
|
289
309
|
return errorMessage;
|
|
290
310
|
}
|
|
291
311
|
|
|
292
|
-
private hasTruthyCause(error: Error & { cause?: unknown }): boolean {
|
|
293
|
-
if (!('cause' in error)) return false;
|
|
294
|
-
return this.isTruthyCause(error.cause);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
312
|
private isTruthyCause(cause: unknown): boolean {
|
|
298
313
|
if (cause === undefined || cause === null) return false;
|
|
299
314
|
if (cause === false || cause === 0 || cause === '') return false;
|
|
@@ -301,10 +316,7 @@ class DirectWebFetchToolInvocation extends BaseToolInvocation<
|
|
|
301
316
|
}
|
|
302
317
|
|
|
303
318
|
private extractTextFromHTML(html: string): string {
|
|
304
|
-
|
|
305
|
-
// Remove scripts, styles, etc.
|
|
306
|
-
$('script, style, noscript, iframe, object, embed').remove();
|
|
307
|
-
return $.text().trim();
|
|
319
|
+
return htmlToText(html).trim();
|
|
308
320
|
}
|
|
309
321
|
|
|
310
322
|
private convertHTMLToMarkdown(html: string): string {
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
* Licensed under the MIT License.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import fetch from 'node-fetch';
|
|
12
|
-
|
|
13
11
|
import type { IToolKeyStorage, IToolMessageBus } from '../interfaces/index.js';
|
|
14
12
|
import { ToolErrorType } from '../types/tool-error.js';
|
|
15
13
|
import { ensureJsonSafe } from '../utils/unicodeUtils.js';
|
|
@@ -165,7 +163,7 @@ class ExaWebSearchToolInvocation extends BaseToolInvocation<
|
|
|
165
163
|
* the HTTP status is preserved in the thrown error message.
|
|
166
164
|
*/
|
|
167
165
|
private async readErrorResponseBody(
|
|
168
|
-
response:
|
|
166
|
+
response: Response,
|
|
169
167
|
signal: AbortSignal,
|
|
170
168
|
cancelRequest: () => void,
|
|
171
169
|
): Promise<string> {
|
package/src/tools/github-ops.ts
CHANGED
|
@@ -48,6 +48,7 @@ export type GithubParamKind =
|
|
|
48
48
|
| 'assignee'
|
|
49
49
|
| 'milestone'
|
|
50
50
|
| 'project'
|
|
51
|
+
| 'projectList'
|
|
51
52
|
| 'branch';
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -129,7 +130,7 @@ export const GITHUB_OP_SPECS: Readonly<Record<string, GithubOpSpec>> = {
|
|
|
129
130
|
removeLabel: 'label',
|
|
130
131
|
addAssignee: 'assignee',
|
|
131
132
|
removeAssignee: 'assignee',
|
|
132
|
-
addProject: '
|
|
133
|
+
addProject: 'projectList',
|
|
133
134
|
removeProject: 'project',
|
|
134
135
|
milestone: 'milestone',
|
|
135
136
|
type: 'freetext',
|
|
@@ -309,6 +310,7 @@ export const GITHUB_PARAM_KIND_HINTS: Readonly<
|
|
|
309
310
|
assignee: 'array of strings',
|
|
310
311
|
milestone: 'string',
|
|
311
312
|
project: 'string',
|
|
313
|
+
projectList: 'non-empty array of strings',
|
|
312
314
|
branch: 'string',
|
|
313
315
|
};
|
|
314
316
|
|
|
@@ -539,6 +541,20 @@ function validateStringOrArrayValue(
|
|
|
539
541
|
return null;
|
|
540
542
|
}
|
|
541
543
|
|
|
544
|
+
/**
|
|
545
|
+
* Validates issue.edit addProject as a string or non-empty string array.
|
|
546
|
+
*
|
|
547
|
+
* @plan project-plans/issue3592.md
|
|
548
|
+
* @requirement AC-1
|
|
549
|
+
* @issue 3592
|
|
550
|
+
*/
|
|
551
|
+
function validateProjectListValue(key: string, value: unknown): string | null {
|
|
552
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
553
|
+
return `Parameter ${key} must be a non-empty array of strings`;
|
|
554
|
+
}
|
|
555
|
+
return validateStringOrArrayValue(key, value);
|
|
556
|
+
}
|
|
557
|
+
|
|
542
558
|
/**
|
|
543
559
|
* Validates that `value` is a string within the allowed list, producing the
|
|
544
560
|
* same two-stage messages the broker always produced (non-string vs.
|
|
@@ -706,6 +722,7 @@ const KIND_VALIDATORS: Readonly<
|
|
|
706
722
|
assignee: validateStringOrArrayValue,
|
|
707
723
|
milestone: validateStringValue,
|
|
708
724
|
project: validateStringValue,
|
|
725
|
+
projectList: validateProjectListValue,
|
|
709
726
|
branch: validateStringValue,
|
|
710
727
|
body: validateStringValue,
|
|
711
728
|
freetext: validateStringValue,
|
package/src/tools/github.ts
CHANGED
|
@@ -170,7 +170,7 @@ function buildOpReferenceBlock(): string {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
* Array-of-strings parameters (labels, assignees).
|
|
173
|
+
* Array-of-strings parameters (labels, assignees, projects).
|
|
174
174
|
*
|
|
175
175
|
* The tool schema declares these as `{ type: 'array', items: { type: 'string' } }`
|
|
176
176
|
* rather than a `type: ['string', 'array']` union. A union type is
|
|
@@ -196,6 +196,8 @@ const ARRAY_PARAMS: Readonly<Record<string, string>> = {
|
|
|
196
196
|
'Logins to add as assignee, as an array (use a single-element array for one). Accepted by issue.edit, pr.edit.',
|
|
197
197
|
removeAssignee:
|
|
198
198
|
'Logins to remove as assignee, as an array (use a single-element array for one). Accepted by issue.edit.',
|
|
199
|
+
addProject:
|
|
200
|
+
'Project names to add, as a non-empty array of strings. Accepted by issue.edit.',
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
/** Schema for boolean-kind parameters (no additional constraints). */
|
|
@@ -273,6 +275,7 @@ function paramSchemaFor(name: string): Record<string, unknown> {
|
|
|
273
275
|
if (name in ARRAY_PARAMS) {
|
|
274
276
|
return {
|
|
275
277
|
type: 'array',
|
|
278
|
+
...(name === 'addProject' ? { minItems: 1 } : {}),
|
|
276
279
|
items: { type: 'string' },
|
|
277
280
|
description: ARRAY_PARAMS[name],
|
|
278
281
|
};
|
|
@@ -298,7 +301,6 @@ function textHintFor(name: string): string {
|
|
|
298
301
|
milestone:
|
|
299
302
|
'Milestone name or number. Accepted by issue.create, issue.edit.',
|
|
300
303
|
project: 'Project name. Accepted by issue.create.',
|
|
301
|
-
addProject: 'Project to add the item to. Accepted by issue.edit.',
|
|
302
304
|
removeProject: 'Project to remove the item from. Accepted by issue.edit.',
|
|
303
305
|
type: 'Issue type (e.g. Bug, Feature). Set AFTER creation via issue.edit; NOT accepted by issue.create.',
|
|
304
306
|
base: 'Base branch for the pull request. Accepted by pr.create.',
|
package/src/tools/read-file.ts
CHANGED
|
@@ -65,11 +65,6 @@ export interface ReadFileToolParams {
|
|
|
65
65
|
* When true, prefixes each text line with a git-change marker column.
|
|
66
66
|
*/
|
|
67
67
|
showGitChanges?: boolean;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* When true, returns original image bytes for this call.
|
|
71
|
-
*/
|
|
72
|
-
skip_image_resize?: boolean;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
function formatWithLineNumbers(content: string, startLine: number): string {
|
|
@@ -294,10 +289,7 @@ ${formattedContent}`;
|
|
|
294
289
|
let imageResizePolicy;
|
|
295
290
|
let imageBudget;
|
|
296
291
|
try {
|
|
297
|
-
imageResizePolicy = resolveImageResizePolicy(
|
|
298
|
-
ephemeralSettings,
|
|
299
|
-
this.params.skip_image_resize === true,
|
|
300
|
-
);
|
|
292
|
+
imageResizePolicy = resolveImageResizePolicy(ephemeralSettings);
|
|
301
293
|
imageBudget = resolveImageDimensionBudget(ephemeralSettings);
|
|
302
294
|
} catch (error) {
|
|
303
295
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -426,11 +418,6 @@ If git status cannot be read, the tool will still return file content and includ
|
|
|
426
418
|
"Optional: When true (text files only), prefixes each returned line with a single-character git-change marker column computed relative to HEAD (includes staged and unstaged changes). This marker column is virtual and not part of the file content. Legend: '░' unchanged, 'N' new, 'M' modified, 'D' deletion after line. Column order: git marker first, then (optional) the virtual line number column, then line content. If git status cannot be read, content is still returned and a brief warning is included.",
|
|
427
419
|
type: 'boolean',
|
|
428
420
|
},
|
|
429
|
-
skip_image_resize: {
|
|
430
|
-
description:
|
|
431
|
-
'Optional: When true, returns original image bytes without applying configured automatic resizing. This has no effect on non-image files.',
|
|
432
|
-
type: 'boolean',
|
|
433
|
-
},
|
|
434
421
|
},
|
|
435
422
|
// Don't require either in schema - validation handles this
|
|
436
423
|
type: 'object',
|
|
@@ -46,7 +46,6 @@ export const DISCOVERED_TOOL_PREFIX = 'discovered_tool_';
|
|
|
46
46
|
type ToolParams = Record<string, unknown>;
|
|
47
47
|
interface McpRegisteredTool {
|
|
48
48
|
readonly serverName: string;
|
|
49
|
-
getFullyQualifiedName?(): string;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
function isDiscoveredMcpTool(
|
|
@@ -912,20 +911,6 @@ export class ToolRegistry {
|
|
|
912
911
|
}
|
|
913
912
|
}
|
|
914
913
|
|
|
915
|
-
// If still not found and the name includes '__', try fallback lookup by fully qualified name
|
|
916
|
-
if (!tool && name.includes('__')) {
|
|
917
|
-
for (const t of this.tools.values()) {
|
|
918
|
-
if (
|
|
919
|
-
isDiscoveredMcpTool(t) &&
|
|
920
|
-
typeof t.getFullyQualifiedName === 'function' &&
|
|
921
|
-
t.getFullyQualifiedName() === name
|
|
922
|
-
) {
|
|
923
|
-
tool = t;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
|
|
929
914
|
if (!tool) {
|
|
930
915
|
const missingTool: AnyDeclarativeTool | undefined = void 0;
|
|
931
916
|
return missingTool;
|
package/src/types/wire-types.ts
CHANGED
|
@@ -49,6 +49,14 @@ export interface InlineData {
|
|
|
49
49
|
mimeType?: string;
|
|
50
50
|
data?: string;
|
|
51
51
|
displayName?: string;
|
|
52
|
+
originalData?: string;
|
|
53
|
+
originalMimeType?: string;
|
|
54
|
+
originalDimensions?: { readonly width: number; readonly height: number };
|
|
55
|
+
transformation?: {
|
|
56
|
+
readonly policyId: string;
|
|
57
|
+
readonly policyVersion: number;
|
|
58
|
+
readonly parameters: Readonly<Record<string, number>>;
|
|
59
|
+
};
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
/**
|
package/src/utils/fileUtils.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { ToolErrorType } from '../types/tool-error.js';
|
|
|
12
12
|
import { debugLogger } from './debugLogger.js';
|
|
13
13
|
import { isNodeError } from './errors.js';
|
|
14
14
|
import {
|
|
15
|
+
createImageResizeSourceMetadata,
|
|
15
16
|
ImageResizeError,
|
|
16
17
|
resizeImageIfNeeded,
|
|
17
18
|
type ImageResizePolicy,
|
|
@@ -842,6 +843,14 @@ async function processMediaFile(
|
|
|
842
843
|
data: outputBuffer.toString('base64'),
|
|
843
844
|
mimeType,
|
|
844
845
|
displayName,
|
|
846
|
+
...(fileType === 'image'
|
|
847
|
+
? createImageResizeSourceMetadata(
|
|
848
|
+
contentBuffer,
|
|
849
|
+
outputBuffer,
|
|
850
|
+
mimeType,
|
|
851
|
+
imageResizePolicy,
|
|
852
|
+
)
|
|
853
|
+
: undefined),
|
|
845
854
|
},
|
|
846
855
|
},
|
|
847
856
|
returnDisplay: `Read ${fileType} file: ${relativePathForDisplay}`,
|