CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged between them; they stack on phones. HTML export and import keep them (also Notion column lists and Confluence page layouts). - Suggesting mode: edits become suggested insertions and deletions that editors accept or reject one by one or all at once. Text only. - Verified pages: editors verify a page for a while or without end; the verifier is notified when it runs out (migration 1764700000). - Scanned PDFs attached to pages are read by AI for search where a workspace turns it on. - The server writes error messages, emails, digests and phone notifications in English, Polish, German, French and Spanish; the apps send their language with each request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
// Scanned PDFs attached to pages have no text layer, so search cannot read
|
|
// them. A workspace that turns on Settings.ReadScans has its AI provider
|
|
// write them out, once each, for the search index (search/scans.go). It
|
|
// costs tokens, counted against the workspace's monthly limit like any
|
|
// other use.
|
|
|
|
// ErrScansOff is returned when the workspace does not read scanned PDFs (AI
|
|
// or the setting is off, or no provider is set up).
|
|
var ErrScansOff = errors.New("ai: the workspace does not read scanned PDFs")
|
|
|
|
// ReadsScans reports whether a workspace reads scanned PDFs for search.
|
|
func (s *Service) ReadsScans(ctx context.Context, wsID string) bool {
|
|
st, err := s.settings(ctx, wsID)
|
|
return err == nil && st.Enabled && st.ReadScans
|
|
}
|
|
|
|
// ReadScan writes out the text of a scanned PDF for the search index of a
|
|
// workspace that reads scans. It runs as the server, not as a person.
|
|
func (s *Service) ReadScan(ctx context.Context, wsID string, data []byte) (string, error) {
|
|
st, err := s.settings(ctx, wsID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !st.Enabled || !st.ReadScans {
|
|
return "", ErrScansOff
|
|
}
|
|
chain, err := s.chain(ctx, wsID, st)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if chain, err = s.limit(ctx, wsID, st, chain); err != nil {
|
|
return "", err
|
|
}
|
|
var out strings.Builder
|
|
_, err = s.chat(ctx, wsID, chain, ChatRequest{
|
|
System: ocrSystem, MaxTokens: 32000, PDF: data,
|
|
Messages: []Message{{Role: "user", Content: "Write out the text of this document."}},
|
|
}, func(d string) { out.WriteString(d) })
|
|
if errors.Is(err, errNoProfile) {
|
|
return "", ErrScansOff
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return out.String(), nil
|
|
}
|