Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

2.9 KB
Raw Blame
import { MCPTool, RAG_INTERNAL_SERVER } from '@janhq/core'

// Tool names
export const RETRIEVE = 'retrieve'
export const LIST_ATTACHMENTS = 'list_attachments'
export const GET_CHUNKS = 'get_chunks'

export function getRAGTools(retrievalLimit: number): MCPTool[] {
  // Coerce nullish/NaN to the default 3; a numeric-but-low value still clamps
  // to a minimum of 1 below.
  const parsedLimit = Number(retrievalLimit ?? 3)
  const safeLimit = Number.isFinite(parsedLimit) ? parsedLimit : 3
  const maxTopK = Math.max(1, safeLimit)

  return [
    {
      name: LIST_ATTACHMENTS,
      description:
        'List files attached to the current thread or project. Use scope to specify: "thread" for thread-level files (default), "project" for project-level files shared across all threads in the project.',
      inputSchema: {
        type: 'object',
        properties: {},
        required: [],
      },
      server: RAG_INTERNAL_SERVER,
    },
    {
      name: RETRIEVE,
      description:
        'Retrieve relevant snippets from locally attached, indexed documents. Use query only; do not pass raw document content. Use scope to search: "thread" (default) for thread-level files, "project" for project-level files shared across all threads. Use file_ids to search within specific files only.',
      inputSchema: {
        type: 'object',
        properties: {
          query: { type: 'string', description: 'User query to search for' },
          top_k: {
            type: 'number',
            description: 'Optional: Max citations to return. Adjust as needed.',
            minimum: 1,
            maximum: maxTopK,
            default: safeLimit,
          },
          file_ids: {
            type: 'array',
            items: { type: 'string' },
            description:
              'Optional: Filter search to specific file IDs from list_attachments',
          },
        },
        required: ['query'],
      },
      server: RAG_INTERNAL_SERVER,
    },
    {
      name: GET_CHUNKS,
      description:
        'Retrieve chunks from a file by their order range. For a single chunk, use start_order = end_order. Use scope to specify source: "thread" (default) for thread-level, "project" for project-level files. Use sparingly; intended for advanced usage. Prefer using retrieve instead for relevance-based fetching.',
      inputSchema: {
        type: 'object',
        properties: {
          file_id: {
            type: 'string',
            description: 'File ID from list_attachments',
          },
          start_order: {
            type: 'number',
            description: 'Start of chunk range (inclusive, 0-indexed)',
          },
          end_order: {
            type: 'number',
            description:
              'End of chunk range (inclusive, 0-indexed). For single chunk, use start_order = end_order.',
          },
        },
        required: ['file_id', 'start_order', 'end_order'],
      },
      server: RAG_INTERNAL_SERVER,
    },
  ]
}