Merged in feature/chatbot1 (pull request #223)

Chatbot functionality

* baseline working

* missing test file

* more tests
This commit is contained in:
Jay Brown
2026-05-07 20:56:18 +00:00
parent 17fc813823
commit 72de690894
62 changed files with 19150 additions and 445 deletions
@@ -288,6 +288,81 @@ func (q *Queries) GetDocumentEnriched(ctx context.Context, id uuid.UUID) (*GetDo
return &i, err
}
const getDocumentEnrichedForClient = `-- name: GetDocumentEnrichedForClient :one
SELECT
d.id,
d.clientId,
d.hash,
d.folderId,
d.filename,
d.originalPath,
d.file_size_bytes,
d.custom_schema_id,
EXISTS(
SELECT 1 FROM document_custom_metadata
WHERE document_id = d.id
) AS has_custom_metadata
FROM documents d
WHERE d.id = $1
AND d.clientId = $2
`
type GetDocumentEnrichedForClientParams struct {
ID uuid.UUID `db:"id"`
ClientID string `db:"client_id"`
}
type GetDocumentEnrichedForClientRow struct {
ID uuid.UUID `db:"id"`
Clientid string `db:"clientid"`
Hash string `db:"hash"`
Folderid *uuid.UUID `db:"folderid"`
Filename *string `db:"filename"`
Originalpath *string `db:"originalpath"`
FileSizeBytes *int64 `db:"file_size_bytes"`
CustomSchemaID *uuid.UUID `db:"custom_schema_id"`
HasCustomMetadata bool `db:"has_custom_metadata"`
}
// Chatbot-scoped read: same column set as GetDocumentEnriched, but adds a
// clientId filter so cross-client lookups miss with pgx.ErrNoRows.
// Plan §5 mandates a clientId filter on every chatbot document/folder
// read so document scope cannot leak between clients. documents.clientId
// is the unquoted (lowercased) varchar column from migration 5.
//
// SELECT
// d.id,
// d.clientId,
// d.hash,
// d.folderId,
// d.filename,
// d.originalPath,
// d.file_size_bytes,
// d.custom_schema_id,
// EXISTS(
// SELECT 1 FROM document_custom_metadata
// WHERE document_id = d.id
// ) AS has_custom_metadata
// FROM documents d
// WHERE d.id = $1
// AND d.clientId = $2
func (q *Queries) GetDocumentEnrichedForClient(ctx context.Context, arg *GetDocumentEnrichedForClientParams) (*GetDocumentEnrichedForClientRow, error) {
row := q.db.QueryRow(ctx, getDocumentEnrichedForClient, arg.ID, arg.ClientID)
var i GetDocumentEnrichedForClientRow
err := row.Scan(
&i.ID,
&i.Clientid,
&i.Hash,
&i.Folderid,
&i.Filename,
&i.Originalpath,
&i.FileSizeBytes,
&i.CustomSchemaID,
&i.HasCustomMetadata,
)
return &i, err
}
const getDocumentEntry = `-- name: GetDocumentEntry :one
SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1
`