Skip to content

Commit 2682446

Browse files
authored
fix: remove credential tools from dynamically added tools (#211)
Signed-off-by: Grant Linville <[email protected]>
1 parent 1675d87 commit 2682446

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

server/app.mjs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,35 @@ const mount = async (
253253
socket.emit('addingTool');
254254

255255
const loaded = await gptscript.loadTools(script, true);
256-
const newTools = toChatStateTools(loaded?.program?.toolSet);
256+
257+
// We need to filter out credential tools so that we do not give them to the LLM.
258+
// TODO - also filter out context tools maybe?
259+
const toolSet = {};
260+
const credentials = new Set();
261+
for (tool of Object.values(loaded?.program?.toolSet)) {
262+
if (tool.credentials) {
263+
for (let cred of tool.credentials) {
264+
for (let mapping of tool.toolMapping[cred]) {
265+
credentials.add(mapping.toolID);
266+
}
267+
}
268+
}
269+
if (tool['exportCredentials']) {
270+
for (let cred of tool['exportCredentials']) {
271+
for (let mapping of tool.toolMapping[cred]) {
272+
credentials.add(mapping.toolID);
273+
}
274+
}
275+
}
276+
}
277+
278+
for (let [key, value] of Object.entries(loaded?.program?.toolSet)) {
279+
if (!credentials.has(key)) {
280+
toolSet[key] = value;
281+
}
282+
}
283+
284+
const newTools = toChatStateTools(toolSet);
257285
const currentState = JSON.parse(state.chatState);
258286
currentState.continuation.state.completion.tools = newTools;
259287

0 commit comments

Comments
 (0)