diff options
| -rw-r--r-- | libpanto-go/panto.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/libpanto-go/panto.go b/libpanto-go/panto.go index 543d4b6..35bc5fa 100644 --- a/libpanto-go/panto.go +++ b/libpanto-go/panto.go @@ -1253,8 +1253,15 @@ func sessionInfo(i C.PantoSessionInfo) SessionInfo { // Tool callback support. type ( - ToolDecl struct{ Name, Description, SchemaJSON string } - ResultPart struct{ Text string } + ToolDecl struct{ Name, Description, SchemaJSON string } + ResultPart struct { + Text string + // Media carries raw bytes, not base64. libpanto detects/resizes/encodes + // supported images and PDFs for the provider; MediaType is an optional + // MIME hint. + MediaType string + Media []byte + } ResultParts []ResultPart ToolFunc func(input string) (ResultParts, error) Tool struct { @@ -1331,10 +1338,21 @@ func makeCResultParts(parts ResultParts) C.PantoResultParts { arr := (*C.PantoResultPart)(C.calloc(C.size_t(len(parts)), C.size_t(unsafe.Sizeof(C.PantoResultPart{})))) xs := unsafe.Slice(arr, len(parts)) for i, p := range parts { - cs := cSlice(p.Text) - xs[i].tag = C.PANTO_RESULT_TEXT - (*C.PantoSlice)(unsafe.Pointer(&xs[i].data[0])).ptr = cs.ptr - (*C.PantoSlice)(unsafe.Pointer(&xs[i].data[0])).len = cs.len + if p.Media == nil { + cs := cSlice(p.Text) + xs[i].tag = C.PANTO_RESULT_TEXT + (*C.PantoSlice)(unsafe.Pointer(&xs[i].data[0])).ptr = cs.ptr + (*C.PantoSlice)(unsafe.Pointer(&xs[i].data[0])).len = cs.len + continue + } + + xs[i].tag = C.PANTO_RESULT_MEDIA + m := (*C.PantoMediaPart)(unsafe.Pointer(&xs[i].data[0])) + m.data = C.PantoSlice{ptr: (*C.uint8_t)(C.CBytes(p.Media)), len: C.size_t(len(p.Media))} + if p.MediaType != "" { + m.media_type = cSlice(p.MediaType) + m.has_media_type = C.bool(true) + } } return C.PantoResultParts{ptr: arr, len: C.size_t(len(parts))} } |
