Crestapps core file sources

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core file sources is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for CrestApps.Core 2.0 file sources, the continuous intake path that keeps a File AI data source in step with a folder, an FTP server or an SFTP server. Covers CrestApps.Core.AI.FileSources, AddCoreFileSources with the CrestApps AI FileSources configuration section, AddCoreFileSystemConnector

How to use this skill

Skill file

CrestApps.Core File Sources

A File AI data source (AIDataSourceSourceTypes.File) is an inert bucket with no folder, credential or field mapping. A file source (FileSource record) picks a connector, configures it, and points at the File data source it fills. Several file sources can feed one knowledge base, each on its own schedule. Web crawlers (crestapps-core-web-crawlers) are the same shape for websites.

FileSource (FileSystem) -+
FileSource (Ftp)        -+->  File AI data source  ->  knowledge-base index (typed objects)
FileSource (Sftp)       -+

Each file becomes separately retrievable objects (document, article, text, figure, chart, table) with a page number and a link to its article and document. Data source concepts are in crestapps-core-data-sources; readers and figure processing are in crestapps-core-document-processing.

Registration

using CrestApps.Core.AI.Documents;
using CrestApps.Core.AI.Documents.Endpoints;
using CrestApps.Core.AI.FileSources;
using CrestApps.Core.AI.Ftp;
using CrestApps.Core.AI.Sftp;
using CrestApps.Core.Data.YesSql;

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddDocumentProcessing(documentProcessing => documentProcessing   // optional: chat uploads, Office readers
            .AddYesSqlStores()
            .AddPdf()
            .AddReferenceDownloads()))
    .AddIndexingServices(indexing => indexing
        .AddYesSqlStores()
        .AddPostgreSQL(
            builder.Configuration.GetSection("CrestApps:PostgreSQL"),
            postgreSQL => postgreSQL.AddAIDataSources())));

// After AddDocumentProcessing, so the HTML reader registered here wins .html.
builder.Services
    .AddCoreFileSources(builder.Configuration)
    .AddCoreFileSystemConnector()
    .AddCoreFtpIngestionConnector()    // CrestApps.Core.AI.Ftp (FluentFTP)
    .AddCoreSftpIngestionConnector();  // CrestApps.Core.AI.Sftp (SSH.NET)

builder.Services.AddCoreFileSourceStoresYesSql(); // or AddCoreFileSourceStoresEntityCore()

var app = builder.Build();

app.AddDownloadKnowledgeFigureEndpoint();

Configuration

{
  "CrestApps": {
    "AI": {
      "FileSources": {
        "MaxItemsPerRun": 200,
        "MaxConcurrentFetches": 2,
        "RunCheckIntervalMinutes": 15,
        "DefaultRunIntervalMinutes": 1440,
        "FileSystem": {
          "AllowedRoots": [ "App_Data/file-sources" ]
        }
      }
    }
  }
}

Creating Records in Code

using CrestApps.Core;
using CrestApps.Core.AI.FileSources.Connectors;
using CrestApps.Core.AI.Ingestion;
using CrestApps.Core.AI.Models;

var dataSource = new AIDataSource
{
    DisplayText = "Datasheets",
    Source = AIDataSourceSourceTypes.File,
    AIKnowledgeBaseIndexProfileName = "datasheets-kb",
};
await dataSourceCatalog.CreateAsync(dataSource, cancellationToken);

var fileSource = new FileSource
{
    DisplayText = "Datasheet folder",
    Source = FileSystemIngestionConnector.ConnectorName, // "FileSystem", "Ftp" or "Sftp"
    AIDataSourceId = dataSource.ItemId,
    ReindexIntervalMinutes = 60,
};

fileSource.Put(new FileSystemFileSourceMetadata
{
    RootPath = "App_Data/file-sources/datasheets",
    Recursive = true,
});

fileSource.Put(new FileSourceMetadata
{
    FigureMode = FigureProcessingMode.Auto,
    VisionDeploymentName = "gpt-4o",     // null means use the application's vision deployment
    MaxFigureDescriptionsPerDocument = 25,
    MaxItemsPerRun = 500,
    Language = "en",
});

await fileSourceStore.CreateAsync(fileSource, cancellationToken);

Running

| Service | Does |

|---|---|

| IIngestionRunService.RunAsync(source) | one run of one record; returns and stores a FileSourceRunSummary |

| IFileSourceScheduler.RunDueAsync() | runs every due source; returns FileSourceSchedulerResult(Considered, Ran, Failed) |

| IFileSourceScheduler.GetDueAsync(now) / IsDue(source, now) | lets a host spread work over its own workers |

| FileSourceBackgroundService | timer that calls RunDueAsync every RunCheckIntervalMinutes |

The scheduler is scoped and creates no scope. A host with its own scheduler (Orchard Core background tasks, a cron job) resolves it inside its own scope and should remove FileSourceBackgroundService, or sources run twice. Commit the store afterwards (IStoreCommitter.CommitAsync), as the background jobs do; otherwise objects, item state and summaries are discarded with the scope. Due-ness is read from the stored summary, so restarts do not rerun everything.

FileSourceRunSummary stores Status (Running, Succeeded, PartiallyCompleted, Failed), StartedUtc, CompletedUtc, DiscoveryCompleted, DiscoveryCursor, ItemsDiscovered, ItemsIndexed, ItemsSkipped, ItemsDeleted, ItemsFailed, FiguresDiscovered, FiguresPendingDescription and Error. Read it with source.TryGet<FileSourceRunSummary>(out var summary).

What Gets Removed

Figures found during a run are stored as PendingDescription and transcribed later by the figure backfill job, using the record's vision deployment.

Custom Connectors

Implement IIngestionConnector (namespace CrestApps.Core.AI.Indexing) and register it with AddCoreIngestionConnector<TConnector>(name, descriptor => ...). The record's Source must equal name. See references/connector-examples.md for a complete connector.

Upgrading from 1.x and 2.0 previews

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.