Interface: FileStore
Defined in: internal/file-store/FileStore.ts:64
FileStore -- the uploaded files: bytes in blob storage, pointers in the turns
About
The thread database stays small; the model gets the bytes only when it can read them.
Stores the files a user uploads for a question (images, PDFs) in the host's blob storage, at
<tenantId>/<path>/<userId>/<fileId>, and hands back an IFileRef pointer that the turn keeps. The call path loads the
bytes again for the model (loadInlineFiles, restoreInlineBytes); the pointer is the only record of the file.
- Tenant- and user-scoped by the key: the tenant is the first folder, the user the last, so nobody reaches another's files.
- Capped at the upload: the size (
maxBytes), the type (allowedMime), the name (255 characters, one line). - Deleted with the thread (
deleteThreads) and with the user (forgetUser): the user's whole folder in one call.
Created by createGatewayDeps with no deps; written by AIGateway.uploadFile, read inside prepareCall and continueRun.
Who needs it
AIGateway.uploadFile, deleteFile, removeFilesByUser; loadInlineFiles, restoreInlineBytes, deleteThreads, forgetUser.
What needs
IFileStoreConfig: the IBlobAdapter, the path (required, may be empty), the optional caps.
Usage
When to use it
A file the user attaches to a question, so the model can read it.
When shouldn't use it
Documents the model should search: that is the knowledge base (KbIngestor).
Pitfalls
path and every id are checked as folder names (no separator, no "." or ".."): a bad one is a 400 before the adapter is
reached. The default types exclude SVG on purpose.
Implements
Methods
getBytes()
getBytes(
__namedParameters):Promise<Uint8Array<ArrayBufferLike>>
Defined in: internal/file-store/FileStore.ts:174
getBytes -- the bytes of a file, for the model
About
The inline part of a message: the pointer back into bytes.
Reads the blob at the user's key; a file this user of this tenant does not have is the adapter's 404.
Who needs it
loadInlineFiles (the files of a question) and restoreInlineBytes (the files of a paused run on its resume).
Parameters
__namedParameters
fileId
string
tenantId
string
userId
string
The user who uploaded the file (IFileRef.userId).
Returns
Promise<Uint8Array<ArrayBufferLike>>
Implementation of
IFileStore.getBytes
getSignedUrl()
getSignedUrl(
__namedParameters):Promise<string>
Defined in: internal/file-store/FileStore.ts:202
getSignedUrl -- a short-lived URL of a file, for a screen
About
The bytes without passing through the server: the adapter signs, the browser fetches.
A file this user of this tenant does not have is the adapter's 404.
Who needs it
AIGateway.getFileUrl, for the host's chat screen that shows an uploaded image or opens a PDF.
Parameters
__namedParameters
fileId
string
tenantId
string
ttlSec?
number = DEFAULT_SIGNED_URL_TTL_SEC
How long the URL stays valid, in seconds.
Default
900
userId
string
The user who uploaded the file (IFileRef.userId).
Returns
Promise<string>
Implementation of
IFileStore.getSignedUrl
put()
put(
__namedParameters):Promise<IFileRef>
Defined in: internal/file-store/FileStore.ts:91
put -- stores an upload and returns its pointer
About
Bytes at
<tenantId>/<path>/<userId>/<fileId>, anIFileReffor the turn; nothing else is kept.
Checks before the write: the type must be allowed (400), the name at most 255 characters without control characters
(400; it reaches the model and the memory transcript, so it stays short and on one line), the file not empty (400) and
not over maxBytes (413). The id is a new UUID.
Who needs it
AIGateway.uploadFile, as a call of the uploading user.
Parameters
__namedParameters
bytes
Uint8Array
mime
string
name
string
tenantId
string
userId
string
Who uploads; the file is stored in this user's folder.
Returns
Promise<IFileRef>
Implementation of
IFileStore.put
remove()
remove(
__namedParameters):Promise<void>
Defined in: internal/file-store/FileStore.ts:240
remove -- deletes one file
About
The blob goes; the turn that pointed at it keeps the pointer.
A file that is not there changes nothing.
Who needs it
AIGateway.deleteFile; deleteThreads, for every file the deleted turns pointed at.
Parameters
__namedParameters
fileId
string
tenantId
string
userId
string
The user who uploaded the file (IFileRef.userId).
Returns
Promise<void>
Implementation of
IFileStore.remove
removeFilesByUser()
removeFilesByUser(
__namedParameters):Promise<number>
Defined in: internal/file-store/FileStore.ts:268
removeFilesByUser -- deletes every file a user uploaded
About
The user's whole folder in one adapter call, for "forget this user" (D54).
Returns the number of files deleted. The turns that pointed at them keep their pointers.
Who needs it
forgetUser (both modes) and AIGateway.removeFilesByUser.
Parameters
__namedParameters
tenantId
string
userId
string
Returns
Promise<number>
Implementation of
IFileStore.removeFilesByUser