summaryrefslogtreecommitdiff
path: root/catalog.lua
diff options
context:
space:
mode:
Diffstat (limited to 'catalog.lua')
-rw-r--r--catalog.lua35
1 files changed, 34 insertions, 1 deletions
diff --git a/catalog.lua b/catalog.lua
index 31297d0..d4b0c80 100644
--- a/catalog.lua
+++ b/catalog.lua
@@ -1,5 +1,38 @@
local json = require('panto').ext.json
local M = {}
+-- agy 1.5.23 cuts the middle out of any MCP tool result it would store above
+-- 10,240 bytes (its built-in tool-output-max-bytes flag). Content blocks are
+-- joined first and its own ~80-byte timestamp header counts. The model is
+-- pointed at a spill file it has no tool to read, and no block type or setting
+-- avoids the cut, so the relay sends larger text in parts: the first with the
+-- result, the rest on request through this relay-only tool. docs/findings.md.
+M.result_bytes = 10000
+M.part_tool = {name='result_part',
+ description='Return one later part of a tool result that was too large for a single reply. Use it only when a result says it has more parts.',
+ inputSchema={type='object',properties={result={type='integer'},part={type='integer',minimum=1}},required={'result','part'}},
+ _meta={['antigravity/alwaysLoad']=true}}
+-- Consecutive pieces of at most result_bytes-400 bytes (room for the notice),
+-- ending on a newline when the piece's second half has one and never inside a
+-- UTF-8 character. table.concat(pages) == text.
+function M.pages(text)
+ local size, out, at = M.result_bytes - 400, {}, 1
+ while #text - at + 1 > size do
+ local stop = at + size - 1
+ local nl = text:sub(at, stop):match('^.*()\n')
+ if nl and nl > size // 2 then stop = at + nl - 1
+ else for _ = 1, 3 do if (text:byte(stop + 1) or 0) & 0xC0 ~= 0x80 then break end; stop = stop - 1 end end
+ out[#out + 1] = text:sub(at, stop); at = stop + 1
+ end
+ out[#out + 1] = text:sub(at); return out
+end
+-- What the model receives for part i of result n. The wording was checked
+-- against live Hydrogen: it fetched every remaining part in one response.
+function M.part(pages, n, i)
+ if i > 1 then return ('[pantograph: part %d of %d of result %d]\n'):format(i, #pages, n) .. pages[i] end
+ local bytes = 0; for _, p in ipairs(pages) do bytes = bytes + #p end
+ return pages[1] .. ('\n\n[pantograph: this is part 1 of %d of result %d (%d bytes in all); the tool ran once and nothing was lost. Call result_part with result=%d and part=2%s for the rest, requesting every part you need in a single response.]')
+ :format(#pages, n, bytes, n, #pages > 2 and ' through ' .. #pages or '')
+end
function M.catalog(req, names)
local all, by, list = {}, {}, json.array({})
for _,t in ipairs(req.tools) do all[t.name]=t end
@@ -9,7 +42,7 @@ function M.catalog(req, names)
for i,name in ipairs(names) do
local t=assert(all[name], 'Tool not in active rig: '..name); local s=json.decode(t.input_schema_json)
assert(s.type=='object','Expected MCP object input schema for '..name)
- local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire], 'Invalid or colliding MCP tool name: '..name)
+ local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire] and wire~=M.part_tool.name, 'Invalid or colliding MCP tool name: '..name)
by[wire]={name=name,schema=s}; list[i]={name=wire,description=t.description,inputSchema=s,_meta={['antigravity/alwaysLoad']=true}}
end
return by,list