PAIPAI

createMongoFileProvider()

GridFS attachments next to Mongo thread storage.

createMongoFileProvider stores user attachments in Mongo GridFS. Required when the app sends files.

import { createMongoFileProvider } from "@pai/files-mongo";

const files = createMongoFileProvider({
  url: process.env.MONGO_URL!,
});
await files.initialize();

export const pai = createPai({
  agents: { main: assistantAgent },
  scopeKey: (identity) => identity.workspaceId,
  userKey: (identity) => identity.userId,
  files,
});

Upload first, then send — see Files.

Import

import { createMongoFileProvider } from "@pai/files-mongo";

Signature

function createMongoFileProvider(options: {
  url: string;
  dbName?: string;
  bucketName?: string;
} | {
  db: MongoDatabase;
  bucket?: GridFSBucket;
}): FileProvider & { initialize(): Promise<void> };

Parameters

options: MongoFileProviderOptions

Either { url } or { db }.

url: string

Mongo connection string. Mutually exclusive with db.

dbName?: string

db?: MongoDatabase

Injected database handle. Mutually exclusive with url.

bucketName?: string

Returns

A FileProvider & { initialize(): Promise<void> }.

Pass as createPai({ files }).

Learn more

On this page