|
| 1 | +# Staged media provider proof |
| 2 | + |
| 3 | +Use when a change alters how an uploaded document or image reaches the provider. |
| 4 | + |
| 5 | +```bash |
| 6 | +lane="$OPENCLAW_TELEGRAM_MANTIS_LANE_CMD" |
| 7 | +media="$MANTIS_OUTPUT_DIR/sample.pdf" |
| 8 | +sent="$($lane send --lane baseline --media "$media" --text '@{sut} inspect this document')" |
| 9 | +message_id="$(jq -er '.sent.messageId' <<<"$sent")" |
| 10 | +$lane observe --lane baseline --seconds 60 --until-provider-requests 1 |
| 11 | +requests="$($lane requests --lane baseline)" |
| 12 | +jq -e '[.requests[].contentFacts[]? | select(.type == "legacy_media")] | length > 0' \ |
| 13 | + <<<"$requests" |
| 14 | +``` |
| 15 | + |
| 16 | +With no tool round trip, finish now using `message_id`. Otherwise continue below; |
| 17 | +`finish` stops the lane. |
| 18 | + |
| 19 | +For a reply-mention turn, first `send --media "$media"` without text, capture its |
| 20 | +`.sent.messageId`, then `send --reply-to "$message_id" --text '@{sut} inspect this document'`. |
| 21 | +A bare unmentioned upload stages the file but produces no provider turn. |
| 22 | + |
| 23 | +Repeat for `candidate` with its returned message id, selecting `type == "input_file"`. |
| 24 | +Assert the complete selected facts: `filename`, `mimeType`, and `byteLength` when present. |
| 25 | +The structured facts are comparison evidence; never scrape `body` strings. |
| 26 | + |
| 27 | +For a PDF tool round trip, start each lane with this patch. `pdf` is already in |
| 28 | +the Code Mode catalog; `document-extract` lets the mock OpenAI route execute it. |
| 29 | + |
| 30 | +```json |
| 31 | +{ "configPatch": { "plugins": { "allow": ["telegram", "openai", "document-extract"] } } } |
| 32 | +``` |
| 33 | + |
| 34 | +Replace `<legacy_media.filename>` below with the recorded value and save the |
| 35 | +array as `pdf-exec-events.json` under `MANTIS_OUTPUT_DIR`: |
| 36 | + |
| 37 | +```json |
| 38 | +[ |
| 39 | + { |
| 40 | + "type": "response.output_item.added", |
| 41 | + "item": { |
| 42 | + "type": "function_call", |
| 43 | + "id": "fc_mantis_pdf_exec", |
| 44 | + "call_id": "call_mantis_pdf_exec", |
| 45 | + "name": "exec", |
| 46 | + "arguments": "" |
| 47 | + } |
| 48 | + }, |
| 49 | + { |
| 50 | + "type": "response.function_call_arguments.delta", |
| 51 | + "delta": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}" |
| 52 | + }, |
| 53 | + { |
| 54 | + "type": "response.output_item.done", |
| 55 | + "item": { |
| 56 | + "type": "function_call", |
| 57 | + "id": "fc_mantis_pdf_exec", |
| 58 | + "call_id": "call_mantis_pdf_exec", |
| 59 | + "name": "exec", |
| 60 | + "arguments": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}" |
| 61 | + } |
| 62 | + }, |
| 63 | + { |
| 64 | + "type": "response.completed", |
| 65 | + "response": { |
| 66 | + "id": "resp_mantis_pdf_exec", |
| 67 | + "status": "completed", |
| 68 | + "output": [ |
| 69 | + { |
| 70 | + "type": "function_call", |
| 71 | + "id": "fc_mantis_pdf_exec", |
| 72 | + "call_id": "call_mantis_pdf_exec", |
| 73 | + "name": "exec", |
| 74 | + "arguments": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}" |
| 75 | + } |
| 76 | + ], |
| 77 | + "usage": { |
| 78 | + "input_tokens": 64, |
| 79 | + "output_tokens": 16, |
| 80 | + "total_tokens": 80, |
| 81 | + "input_tokens_details": { "cached_tokens": 0 } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +] |
| 86 | +``` |
| 87 | + |
| 88 | +Save this beside it as `pdf-exec-script.json`, install the two-response script, |
| 89 | +then send the tool-driven turn: |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "responses": [ |
| 94 | + { "eventsFile": "pdf-exec-events.json" }, |
| 95 | + { "text": "PDF tool round trip complete." } |
| 96 | + ] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +```bash |
| 101 | +script="$MANTIS_OUTPUT_DIR/pdf-exec-script.json" |
| 102 | +sha256="$(sha256sum "$script" | cut -d ' ' -f 1)" |
| 103 | +$lane mock --lane baseline --script "$script" "$sha256" |
| 104 | +tool_sent="$($lane send --lane baseline --text '@{sut} inspect the staged PDF with the pdf tool')" |
| 105 | +tool_message_id="$(jq -er '.sent.messageId' <<<"$tool_sent")" |
| 106 | +$lane observe --lane baseline --seconds 120 --until-provider-requests 4 |
| 107 | +requests="$($lane requests --lane baseline)" |
| 108 | +jq -e '[.requests[] | .body.input[]? | select(.type == "function_call_output" |
| 109 | + and .call_id == "call_mantis_pdf_exec")] | length > 0' <<<"$requests" |
| 110 | +$lane finish --lane baseline --focus-message-id "$tool_message_id" |
| 111 | +``` |
| 112 | + |
| 113 | +`finish` tears the lane down, so wait for the cumulative provider-request count |
| 114 | +(staging turn, exec turn, the pdf tool's own model call, follow-up) and assert |
| 115 | +the recorded `function_call_output` before finishing; its `output` carries the |
| 116 | +serialized exec result. The pdf tool's model call consumes the script's second |
| 117 | +response; the follow-up then repeats the exhausted script's last entry, which |
| 118 | +is fine. The pdf tool's request is where the lanes diverge: compare its |
| 119 | +`contentFacts` for `input_file` versus extracted text. Repeat the same script, |
| 120 | +turn, wait, and assertions for `candidate`. |
0 commit comments