Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions apps/api/src/modules/skill/skill-engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ export class SkillEngineService implements OnModuleInit {
const result = await this.driveService.getDriveFileDetail(user, fileId);
return result;
},
listFiles: async (user, canvasId) => {
const result = await this.driveService.listDriveFiles(user, {
canvasId,
scope: 'present',
});
return result;
},
writeFile: async (user, param) => {
return await this.driveService.createDriveFile(user, param);
},
Expand Down
2 changes: 0 additions & 2 deletions apps/api/src/modules/skill/skill.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ import { AutoModelRouter } from '../provider/auto-model-router.service';
/**
* Fixed builtin toolsets that are always available for node_agent mode.
* These toolsets will be automatically appended to user-selected toolsets.
* Internal tools (read_file, list_files) are system-level tools hidden from mentionList.
* Note: IDs must match BuiltinToolsetDefinition.tools[].name for instantiateBuiltinToolsets to work.
*/
const FIXED_BUILTIN_TOOLSETS: GenericToolset[] = [
{ type: 'regular', id: 'execute_code', name: 'execute_code', builtin: true },
{ type: 'regular', id: 'read_file', name: 'read_file', builtin: true },
{ type: 'regular', id: 'list_files', name: 'list_files', builtin: true },
{ type: 'regular', id: 'get_time', name: 'get_time', builtin: true },
];

Expand Down
23 changes: 3 additions & 20 deletions apps/api/src/modules/tool/tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,9 @@ export class ToolService {
return key === 'web_search';
}

/**
* Check if a toolset should be exposed to users in mentionList.
* Filters out deprecated and internal (system-level) toolsets.
* Internal toolsets are auto-included by the system and not user-selectable.
*/
private shouldExposeToolset(key?: string, options?: { internal?: boolean }): boolean {
private shouldExposeToolset(key?: string): boolean {
if (!key) return true;
if (this.isDeprecatedToolset(key)) return false;
// Filter out internal/system-level toolsets (e.g., read_file, list_files)
if (options?.internal) return false;
return true;
return !this.isDeprecatedToolset(key);
}
Comment on lines +81 to 84
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# First, let's find the tool.service.ts file and examine the method around lines 81-84
find . -name "tool.service.ts" -type f | head -5

# Also search for shouldExposeToolset method definition
echo "=== Searching for shouldExposeToolset method definition ==="
rg -n "shouldExposeToolset" --type=ts -B 2 -A 3 | head -50

# Search for internal: true in tool definitions
echo "=== Searching for internal: true ==="
rg -n "internal:\s*true" --type=ts | head -30

# Search for isDeprecatedToolset method
echo "=== Searching for isDeprecatedToolset method ==="
rg -n "isDeprecatedToolset" --type=ts -B 2 -A 5 | head -50

Repository: refly-ai/refly

Length of output: 3883


🏁 Script executed:

#!/bin/bash

# Find the tool.service.ts file
TOOL_SERVICE=$(find . -name "tool.service.ts" -type f 2>/dev/null | head -1)

if [ -z "$TOOL_SERVICE" ]; then
  echo "tool.service.ts not found, searching for similar files..."
  find . -path "*/tool/*" -name "*.service.ts" -type f | head -10
else
  echo "Found: $TOOL_SERVICE"
  echo ""
  echo "=== Lines 75-90 of tool.service.ts ==="
  sed -n '75,90p' "$TOOL_SERVICE" | cat -n
  echo ""
  echo "=== Full shouldExposeToolset method ==="
  rg -n "shouldExposeToolset" "$TOOL_SERVICE" -A 10
fi

# Search for internal flag usage
echo ""
echo "=== Searching for internal: true in builtin tools ==="
find . -path "*/builtin/*" -name "*.ts" -type f | head -5

Repository: refly-ai/refly

Length of output: 3135


🏁 Script executed:

#!/bin/bash

# Find and examine tool.service.ts
find . -name "tool.service.ts" -type f 2>/dev/null | while read file; do
  echo "Found: $file"
  echo "=== Lines 75-95 ==="
  head -95 "$file" | tail -20 | cat -n
  
  # Look for the shouldExposeToolset method
  echo ""
  echo "=== shouldExposeToolset method ==="
  grep -n "shouldExposeToolset\|isDeprecatedToolset" "$file"
done

# Search for internal: true
echo ""
echo "=== Tools marked as internal: true ==="
find . -path "*/builtin/*" -name "*.ts" -exec grep -l "internal:\s*true" {} \;

Repository: refly-ai/refly

Length of output: 1374


🏁 Script executed:

#!/bin/bash
# Search the entire repo for tool.service.ts and examine it

find . -type f -name "tool.service.ts" 2>/dev/null | while IFS= read -r file; do
  echo "=== Found: $file ==="
  # Print lines around 81-84
  awk 'NR>=75 && NR<=90 {print NR": "$0}' "$file"
  
  echo ""
  echo "=== Method signatures for shouldExposeToolset ==="
  grep -n "shouldExposeToolset" "$file" | head -20
  
  echo ""
  echo "=== Method signatures for isDeprecatedToolset ==="
  grep -n "isDeprecatedToolset" "$file"
done

echo ""
echo "=== Checking for internal: true in tool definitions ==="
find . -type f \( -name "*.ts" -o -name "*.tsx" \) 2>/dev/null | xargs grep -l "internal:\s*true" | head -10

Repository: refly-ai/refly

Length of output: 1225


🏁 Script executed:

#!/bin/bash

# Locate tool.service.ts
echo "=== Locating tool.service.ts ==="
git ls-files "**/tool.service.ts" 2>/dev/null || find . -name "tool.service.ts" -type f 2>/dev/null

echo ""
echo "=== All usages of shouldExposeToolset ==="
git grep -n "shouldExposeToolset" 2>/dev/null || grep -rn "shouldExposeToolset" --include="*.ts" .

echo ""
echo "=== All tools marked as internal: true ==="
git grep -n "internal:\s*true" 2>/dev/null | head -20 || grep -rn "internal:\s*true" --include="*.ts" . | head -20

Repository: refly-ai/refly

Length of output: 1025


🏁 Script executed:

#!/bin/bash

echo "=== Files in apps/api/src/modules/tool/ ==="
git ls-files "apps/api/src/modules/tool/" 2>/dev/null || find apps/api/src/modules/tool -type f 2>/dev/null

echo ""
echo "=== Files in packages/agent-tools/ ==="
git ls-files "packages/agent-tools/" 2>/dev/null || find packages/agent-tools -type f 2>/dev/null | head -20

echo ""
echo "=== Searching for shouldExposeToolset ==="
git grep -n "shouldExposeToolset" 2>/dev/null || grep -rn "shouldExposeToolset" . 2>/dev/null | head -20

Repository: refly-ai/refly

Length of output: 5495


🏁 Script executed:

#!/bin/bash

# List repository structure
echo "=== Repository structure ==="
ls -la

echo ""
echo "=== Check for apps directory ==="
if [ -d "apps" ]; then
  find apps -type f -name "*.service.ts" | head -10
fi

echo ""
echo "=== Check for packages directory ==="
if [ -d "packages" ]; then
  find packages -type f -name "index.ts" | grep builtin | head -5
fi

echo ""
echo "=== Search for shouldExposeToolset anywhere ==="
find . -type f \( -name "*.ts" -o -name "*.js" \) -exec grep -l "shouldExposeToolset" {} \; 2>/dev/null | head -10

Repository: refly-ai/refly

Length of output: 2868


🏁 Script executed:

#!/bin/bash

echo "=== Examining packages/agent-tools/src/builtin/index.ts for internal: true tools ==="
grep -n -B 10 "internal:\s*true" packages/agent-tools/src/builtin/index.ts | head -80

echo ""
echo "=== Checking if internal flag is used elsewhere in the codebase ==="
grep -rn "\.internal" --include="*.ts" apps/api/src/modules/tool/ | head -20

echo ""
echo "=== Checking ToolsetDefinition interface ==="
grep -rn "interface ToolsetDefinition\|type ToolsetDefinition" --include="*.ts" | head -5

echo ""
echo "=== Search for where internal property is defined in tool definitions ==="
grep -rn "internal\s*:" --include="*.ts" packages/agent-tools/src/builtin/ | head -20

Repository: refly-ai/refly

Length of output: 1864


🏁 Script executed:

#!/bin/bash

# Get more context about the internal: true tools
echo "=== Tools with internal: true in packages/agent-tools/src/builtin/index.ts ==="
awk '/internal:\s*true/ {for(i=1;i<=20;i++) {print NR-i": "prev[NR%20]; getline; prev[NR%20]=$0} print NR": "$0}' packages/agent-tools/src/builtin/index.ts | head -100

# Better approach - just show tool definitions
echo ""
echo "=== First tool with internal: true (around line 142) ==="
sed -n '135,150p' packages/agent-tools/src/builtin/index.ts

echo ""
echo "=== Second tool with internal: true (around line 155) ==="
sed -n '148,163p' packages/agent-tools/src/builtin/index.ts

echo ""
echo "=== Third tool with internal: true (around line 168) ==="
sed -n '161,176p' packages/agent-tools/src/builtin/index.ts

# Check if internal is documented
echo ""
echo "=== Search for internal property usage in API ==="
grep -rn "internal" packages/agent-tools/src/builtin/interface.ts

Repository: refly-ai/refly

Length of output: 2706


🏁 Script executed:

#!/bin/bash

# Read the actual tools to see structure
cat packages/agent-tools/src/builtin/index.ts | head -200 | tail -100

Repository: refly-ai/refly

Length of output: 2653


🏁 Script executed:

#!/bin/bash

# Get the full structure of one tool definition with internal: true
sed -n '130,175p' packages/agent-tools/src/builtin/index.ts

echo ""
echo "=== Check if internal property is defined in ToolsetDefinition ==="
grep -A 20 "export.*ToolsetDefinition\|interface ToolsetDefinition" packages/agent-tools/src/builtin/interface.ts

echo ""
echo "=== Check if internal flag is ever read in tool.service.ts ==="
grep -n "internal" apps/api/src/modules/tool/tool.service.ts

Repository: refly-ai/refly

Length of output: 1210


🏁 Script executed:

#!/bin/bash

# Check recent commits to tool.service.ts
echo "=== Recent commits to tool.service.ts ==="
cd apps/api/src/modules/tool && git log -10 --oneline tool.service.ts

echo ""
echo "=== Git diff for shouldExposeToolset method changes ==="
cd ../../../.. && git show HEAD:apps/api/src/modules/tool/tool.service.ts 2>/dev/null | grep -A 10 "shouldExposeToolset\|private shouldExposeToolset"

echo ""
echo "=== Check git blame for the shouldExposeToolset method ==="
git blame -L81,84 apps/api/src/modules/tool/tool.service.ts

Repository: refly-ai/refly

Length of output: 2500


🏁 Script executed:

#!/bin/bash

# Find where ToolsetDefinition is defined
echo "=== ToolsetDefinition type definition ==="
grep -r "type ToolsetDefinition\|interface ToolsetDefinition" --include="*.ts" packages/ | grep -v ".gen.ts" | head -5

# Look at one of the definitions
DEFS_FILE=$(grep -r "type ToolsetDefinition\|interface ToolsetDefinition" --include="*.ts" packages/ | grep -v ".gen.ts" | cut -d: -f1 | head -1)

if [ -n "$DEFS_FILE" ]; then
  echo ""
  echo "=== $DEFS_FILE ==="
  grep -A 30 "type ToolsetDefinition\|interface ToolsetDefinition" "$DEFS_FILE" | head -35
fi

echo ""
echo "=== Check if internal property appears in generated types ==="
grep -A 30 "type ToolsetDefinition" packages/request/src/requests/types.gen.ts | head -40

Repository: refly-ai/refly

Length of output: 1413


Clean up or restore internal flag usage in builtin tools.

This is a revert of the internal toolset filtering feature. However, the three builtin tools (get_time, read_file, execute_code) remain marked with internal: true in their definitions, while the shouldExposeToolset() method no longer checks this property. The internal field is still defined in ToolsetDefinition (in the generated types) but has no runtime effect.

Either remove the internal: true flags from the tool definitions in packages/agent-tools/src/builtin/index.ts, or restore the filtering logic in shouldExposeToolset() to respect them. This prevents leaving orphaned metadata that suggests functionality that no longer exists.

🤖 Prompt for AI Agents
In apps/api/src/modules/tool/tool.service.ts around lines 81-84,
shouldExposeToolset() currently ignores the ToolsetDefinition.internal flag,
leaving builtin tools marked internal with no effect; either remove the
internal: true flags from the three builtin tool definitions in
packages/agent-tools/src/builtin/index.ts (get_time, read_file, execute_code) so
metadata matches runtime, or update shouldExposeToolset() to return false when
the toolset definition has internal === true (i.e., after the existing checks,
add a check that if key maps to a toolset with internal flag set then do not
expose it); implement one of these two fixes so metadata and runtime behavior
are consistent.


async getToolsetInventory(): Promise<
Expand All @@ -115,8 +107,6 @@ export class ToolService {

/**
* Load toolset inventory from sources (builtin + external)
* Note: This is for /tool/inventory/list API, which includes all tools for rendering.
* Internal tools are NOT filtered here as they need to be available for ToolCall rendering.
*/
private async loadToolsetInventory(): Promise<ToolsetDefinition[]> {
const builtinInventory = Object.values(builtinToolsetInventory).map((toolset) => ({
Expand Down Expand Up @@ -176,18 +166,11 @@ export class ToolService {
return [...authorizedItems, ...unauthorizedItems];
}

/**
* List builtin tools for mentionList.
* Filters out internal (system-level) tools that are auto-included.
*/
listBuiltinTools(): GenericToolset[] {
return Object.values(builtinToolsetInventory)
.filter(
(toolset) =>
Boolean(toolset.definition) &&
this.shouldExposeToolset(toolset.definition.key, {
internal: toolset.definition.internal,
}),
Boolean(toolset.definition) && this.shouldExposeToolset(toolset.definition.key),
)
.map((toolset) => ({
type: ToolsetType.REGULAR,
Expand Down
105 changes: 2 additions & 103 deletions packages/agent-tools/src/builtin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ export const BuiltinToolsetDefinition: ToolsetDefinition = {
},
modelOnly: true,
},
{
name: 'list_files',
descriptionDict: {
en: 'List all files in the current canvas.',
'zh-CN': '列出当前画布中的所有文件。',
},
modelOnly: true,
},
{
name: 'generate_doc',
descriptionDict: {
Expand Down Expand Up @@ -147,7 +139,7 @@ export const BuiltinSendEmailDefinition: ToolsetDefinition = {

export const BuiltinGetTimeDefinition: ToolsetDefinition = {
key: 'get_time',
// internal: true - This tool should be visible in mentionList for user selection
internal: true,
labelDict: {
en: 'Get Time',
'zh-CN': '获取时间',
Expand All @@ -160,7 +152,6 @@ export const BuiltinGetTimeDefinition: ToolsetDefinition = {

export const BuiltinReadFileDefinition: ToolsetDefinition = {
key: 'read_file',
// System-level tool, auto-included, hidden from mentionList, uses compact rendering
internal: true,
labelDict: {
en: 'Read File',
Expand All @@ -174,7 +165,7 @@ export const BuiltinReadFileDefinition: ToolsetDefinition = {

export const BuiltinExecuteCodeDefinition: ToolsetDefinition = {
key: 'execute_code',
// internal: true - This tool should be visible in mentionList for user selection
internal: true,
labelDict: {
en: 'Execute Code',
'zh-CN': '执行代码',
Expand All @@ -185,20 +176,6 @@ export const BuiltinExecuteCodeDefinition: ToolsetDefinition = {
},
};

export const BuiltinListFilesDefinition: ToolsetDefinition = {
key: 'list_files',
// System-level tool, auto-included, hidden from mentionList, uses compact rendering
internal: true,
labelDict: {
en: 'List Files',
'zh-CN': '列出文件',
},
descriptionDict: {
en: 'List all files in the current canvas.',
'zh-CN': '列出当前画布中的所有文件。',
},
};

export class BuiltinLibrarySearch extends AgentBaseTool<BuiltinToolParams> {
name = 'library_search';
toolsetKey = 'library_search';
Expand Down Expand Up @@ -764,10 +741,6 @@ export class BuiltinReadFile extends AgentBaseTool<BuiltinToolParams> {

schema = z.object({
fileId: z.string().describe('The ID of the file to read (format: df-xxx, from context)'),
fileName: z
.string()
.optional()
.describe('Optional file name for frontend display purpose only'),
});

description = `Read content from a file.
Expand Down Expand Up @@ -808,74 +781,6 @@ Latency: <2s`;
}
}

export class BuiltinListFiles extends AgentBaseTool<BuiltinToolParams> {
name = 'list_files';
toolsetKey = 'list_files';

// No parameters needed - canvasId is obtained from context automatically
schema = z.object({});

description = `List all files in the current canvas.

Returns a list of files with their IDs and names. Use the fileId with read_file tool to read file content.`;

protected params: BuiltinToolParams;

constructor(params: BuiltinToolParams) {
super(params);
this.params = params;
}

async _call(
_input: z.infer<typeof this.schema>,
_: unknown,
config: RunnableConfig,
): Promise<ToolCallResult> {
try {
const { reflyService, user } = this.params;
const canvasId = config.configurable?.canvasId;

if (!canvasId) {
return {
status: 'error',
error: 'Canvas ID not found in context',
summary: 'Cannot list files: canvas context is not available',
};
}

const files = await reflyService.listFiles(user, canvasId);

if (!files || files.length === 0) {
return {
status: 'success',
data: [],
summary: 'No files found in the current canvas',
};
}

// Return simplified file info for LLM consumption
const fileList = files.map((f) => ({
fileId: f.fileId,
fileName: f.name,
type: f.type,
}));

return {
status: 'success',
data: fileList,
summary: `Found ${files.length} file(s) in the canvas: ${files.map((f) => f.name).join(', ')}`,
};
} catch (error) {
return {
status: 'error',
error: 'Error listing files',
summary:
error instanceof Error ? error.message : 'Unknown error occurred while listing files',
};
}
}
}

export class BuiltinLibrarySearchToolset extends AgentBaseToolset<BuiltinToolParams> {
toolsetKey = BuiltinLibrarySearchDefinition.key;
tools = [BuiltinLibrarySearch] satisfies readonly AgentToolConstructor<BuiltinToolParams>[];
Expand Down Expand Up @@ -913,11 +818,6 @@ export class BuiltinReadFileToolset extends AgentBaseToolset<BuiltinToolParams>
tools = [BuiltinReadFile] satisfies readonly AgentToolConstructor<BuiltinToolParams>[];
}

export class BuiltinListFilesToolset extends AgentBaseToolset<BuiltinToolParams> {
toolsetKey = BuiltinListFilesDefinition.key;
tools = [BuiltinListFiles] satisfies readonly AgentToolConstructor<BuiltinToolParams>[];
}

export class BuiltinExecuteCodeToolset extends AgentBaseToolset<BuiltinToolParams> {
toolsetKey = BuiltinExecuteCodeDefinition.key;
tools = [BuiltinExecuteCode] satisfies readonly AgentToolConstructor<BuiltinToolParams>[];
Expand All @@ -932,7 +832,6 @@ export class BuiltinToolset extends AgentBaseToolset<BuiltinToolParams> {
BuiltinSendEmail,
BuiltinGetTime,
BuiltinReadFile,
BuiltinListFiles,
BuiltinExecuteCode,
] satisfies readonly AgentToolConstructor<BuiltinToolParams>[];
}
1 change: 0 additions & 1 deletion packages/agent-tools/src/builtin/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export interface ReflyService {
options?: { topN?: number; relevanceThreshold?: number },
) => Promise<RerankResponse>;
readFile: (user: User, fileId: string) => Promise<DriveFile>;
listFiles: (user: User, canvasId: string) => Promise<DriveFile[]>;
writeFile: (user: User, param: UpsertDriveFileRequest) => Promise<DriveFile>;
inMemorySearchWithIndexing: (
user: User,
Expand Down
6 changes: 0 additions & 6 deletions packages/agent-tools/src/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
BuiltinGetTimeDefinition,
BuiltinReadFileToolset,
BuiltinReadFileDefinition,
BuiltinListFilesToolset,
BuiltinListFilesDefinition,
BuiltinExecuteCodeToolset,
BuiltinExecuteCodeDefinition,
} from './builtin';
Expand Down Expand Up @@ -67,10 +65,6 @@ export const builtinToolsetInventory: Record<
class: BuiltinReadFileToolset,
definition: BuiltinReadFileDefinition,
},
[BuiltinListFilesDefinition.key]: {
class: BuiltinListFilesToolset,
definition: BuiltinListFilesDefinition,
},
[BuiltinExecuteCodeDefinition.key]: {
class: BuiltinExecuteCodeToolset,
definition: BuiltinExecuteCodeDefinition,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading