ref: 07f47299051fec1a83d14bb024dfab182b4fc18f
parent: 584040ed6f329d180f03c374474fb9dc321e88e3
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Feb 24 14:28:34 EST 2026
adds file reading
--- a/oai.c
+++ b/oai.c
@@ -42,9 +42,36 @@
static char*
read_file(OToolcall toolcall, void*)
{- fprint(2, "toolcall: %s\n", toolcall.name);
- fprint(2, " args: %s\n", toolcall.arguments);
- return strdup("not implemented yet");+ JSON *j, *fj;
+ char *file;
+ Biobuf *io;
+ char *s;
+
+ j = jsonparse(toolcall.arguments);
+ fj = jsonbyname(j, "file");
+ if (!fj) {+ fprint(2, "no file in read_file request!\n");
+ return strdup("bad request in read_file!\n");+ }
+
+ file = jsonstr(fj);
+ if (!(file && file[0])) {+ fprint(2, "invalid file in read_file request!\n");
+ return strdup("bad request in read_file: no file!\n");+ }
+
+ io = Bopen(file, OREAD);
+ if (!io) {+ fprint(2, "open file: %r\n");
+ return smprint("open file in read_file: %r");+ }
+
+ fprint(2, "read_file: %s\n", file);
+
+ s = Brdstr(io, 0, 0);
+ jsonfree(j);
+ Bterm(io);
+ return s;
}
static char *readfileargs = "{"--
⑨