Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2b60db5
AI-4053: Read a workbook row by row with a column and cell limit
kanat Nov 26, 2026
b585689
AI-4053: Test the workbook limits and the format check
kanat Nov 26, 2026
c4f06cd
AI-4053: Test a sheet whose rows cannot be read
kanat Nov 26, 2026
367db79
AI-4053: Cover a sheet whose part is missing
kanat Nov 26, 2026
6363c32
Merge remote-tracking branch 'origin/main' into kanat/ai-4053-xlsx-bo…
kanat Nov 26, 2026
2fea478
AI-4053: Say why a row that cannot be read ends the sheet
kanat Nov 26, 2026
e1d5c98
AI-4053: merge origin/main
kanat Nov 26, 2026
47a6803
AI-4053: count a workbook's cells once for all its sheets, a row with…
kanat Nov 26, 2026
6bf9e8e
AI-4053: give a workbook a text budget, and stop its tables at the de…
kanat Nov 26, 2026
1d6c939
AI-4053: pin how a sheet ends on a row that cannot be read, and the c…
kanat Nov 26, 2026
77b29ae
Merge remote-tracking branch 'origin/main' into kanat/ai-4053-xlsx-bo…
kanat Nov 26, 2026
3f5f60e
AI-4053: count a workbook's shared strings before any row is built
kanat Nov 26, 2026
3640753
AI-4053: pin the text budget and a table's limit to the byte
kanat Nov 26, 2026
41dc02b
Merge remote-tracking branch 'origin/main' into kanat/ai-4053-xlsx-bo…
kanat Nov 26, 2026
a899094
AI-4053: count a cell's text as its number format writes it, and refu…
kanat Nov 26, 2026
ef0c3fc
AI-4053: pin that a shared string of runs is counted before its row i…
kanat Nov 26, 2026
626520a
AI-4053: pin that a cell of two values is counted at the last, as exc…
kanat Nov 26, 2026
5ca3897
AI-4053: check the deadline every 4,096 XML tokens as the cells are c…
kanat Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceleration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ require (
github.com/vektah/gqlparser/v2 v2.5.64
github.com/vmihailenco/msgpack/v5 v5.4.1
github.com/xuri/excelize/v2 v2.11.1
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0
go.opentelemetry.io/otel v1.46.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0
Expand Down Expand Up @@ -187,7 +188,6 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
github.com/xuri/efp v0.0.3-0.20260924042702-217b81952dec // indirect
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.44.0 // indirect
Expand Down
12 changes: 9 additions & 3 deletions acceleration/internal/api/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,20 @@ func (s *Server) readDocument(ctx context.Context, found *session.Session, sourc
if retry {
return sentDocument{file: sandbox.File{Name: name, MIME: http.DetectContentType(data), Data: data}, sha: hex.EncodeToString(digest[:])}, nil
}
read, err := s.documents.Extract(ctx, name, data)
// A format that is refused is refused before it is read: reading a workbook is work the
// person's file has no use for.
format, err := extract.Detect(data)
if err != nil {
return sentDocument{}, documentFailure(err)
}
mime, accepted := documentFormats[read.Format]
mime, accepted := documentFormats[format]
if !accepted {
return sentDocument{}, newAPIError(ErrorTypeUnsupportedMediaType,
fmt.Sprintf("the file is %s: a PDF or a Word document (DOCX or DOC) can be sent", read.Format))
fmt.Sprintf("the file is %s: a PDF or a Word document (DOCX or DOC) can be sent", format))
}
read, err := s.documents.Extract(ctx, name, data)
if err != nil {
return sentDocument{}, documentFailure(err)
}
if failure := s.readDocumentPictures(ctx, spec, &read); failure != nil {
return sentDocument{}, failure
Expand Down
26 changes: 26 additions & 0 deletions acceleration/internal/api/documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

"testing"

"github.com/xuri/excelize/v2"

"github.com/GetStream/Vision-Agents/acceleration/internal/harness"
"github.com/GetStream/Vision-Agents/acceleration/internal/llm"
)
Expand Down Expand Up @@ -268,6 +270,30 @@ func (s *DocumentsSuite) TestAPictureSentAsAFileIsRefused() {
s.Equal("unsupported_media_type", failure.Code)
}

// A workbook is no format a question takes, and it is refused for that before it is read: one that
// the reader would refuse as too large is answered as the wrong format all the same.
func (s *DocumentsSuite) TestAWorkbookIsRefusedAsTheWrongFormatWithoutBeingRead() {
opened := s.opening(s.client)
for name, column := range map[string]int{"menu.xlsx": 1, "wide.xlsx": 16384} {
book := excelize.NewFile()
for row := 1; row <= 1500; row++ {
cell, err := excelize.CoordinatesToCellName(column, row)
s.Require().NoError(err)
s.Require().NoError(book.SetCellValue("Sheet1", cell, "v"))
}
var out bytes.Buffer
s.Require().NoError(book.Write(&out))
s.Require().NoError(book.Close())
file := FileSource{Url: "data:application/octet-stream;base64," + base64.StdEncoding.EncodeToString(out.Bytes()), Name: &name}

status, failure := s.refused(opened, CreateResponseRequest{Text: "What is this?", Files: &[]FileSource{file}})

s.Equal(http.StatusUnsupportedMediaType, status, name)
s.Equal("unsupported_media_type", failure.Code, name)
s.Contains(failure.Message, "the file is xlsx", name)
}
}

func (s *DocumentsSuite) TestAnEncryptedFileIsRefusedAsUnreadable() {
opened := s.opening(s.client)
encrypted, err := os.ReadFile("../knowledge/extract/testdata/encrypted.docx")
Expand Down
9 changes: 5 additions & 4 deletions acceleration/internal/knowledge/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (e *Extractor) Extract(ctx context.Context, name string, data []byte) (Docu
ctx, cancel := context.WithTimeout(ctx, e.options.Timeout)
defer cancel()

format, err := detect(data)
format, err := Detect(data)
if err != nil {
return Document{}, err
}
Expand Down Expand Up @@ -315,9 +315,10 @@ var (
utf8BOM = []byte{0xEF, 0xBB, 0xBF}
)

// detect reads what a file is from its first bytes and, for the formats that are zip or
// OLE containers, from what the container holds.
func detect(data []byte) (Format, error) {
// Detect reads what a file is from its first bytes and, for the formats that are zip or
// OLE containers, from what the container holds. Extract reads it the same way, so a caller
// that takes only some formats can refuse the rest before any of them is read.
func Detect(data []byte) (Format, error) {
// A PDF may carry junk before its header, and readers accept one within the first
// kilobyte of the file.
if bytes.Contains(data[:min(len(data), 1024)], pdfMagic) {
Expand Down
Loading
Loading