interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / pi-spark-task / tools / interplane-request / src / main.rs

67 lines · 2588 bytes Raw Blame History
1//! Writes the INTERPLANE canonical tool request carried by the PST1 tool-call
2//! vectors (specs/pi-spark-task/SPEC.md section 11) and prints its digest.
3//!
4//! The request is built as a JSON value, checked to parse as an INTERPLANE
5//! `tool_request` payload, and written as interplane-core's RFC 8785 canonical
6//! bytes. It is longer than one PST1 payload (800 bytes) on purpose, so the
7//! vectors need three chunks.
8use std::process::ExitCode;
9
10use interplane_core::{canonicalize, digest_bytes, Payload};
11use serde_json::{json, Value};
12
13fn request() -> Value {
14 let text = "Find every receipt from the last week that mentions the garden \
15 hose, the rain barrel or the drip line. Summarise each one in a single \
16 plain sentence: what was bought, where, and for how much. Leave out card \
17 numbers and addresses. If two receipts look like the same purchase, say \
18 so instead of counting it twice.\n";
19 json!({
20 "kind": "tool_request",
21 "request_id": "pst1-c6-vector-1",
22 "tool": {"namespace": "aien.receipts", "name": "search"},
23 "arguments": {
24 "query": "garden hose OR rain barrel OR drip line",
25 "since_days": 7,
26 "limit": 25,
27 "fields": ["merchant", "date", "total", "items"],
28 "redact": ["card_number", "address"],
29 "instructions": text.repeat(4),
30 "locale": "en-GB",
31 "currency_hint": "\u{a3}",
32 "note": "caf\u{e9} \u{2615} \u{1f327}"
33 },
34 "provenance": {
35 "dialect": "openai",
36 "parser_version": "1.0.0",
37 "model": "pi-local-router",
38 "source_turn": 7,
39 "source_call_id": "call_pst1_c6"
40 }
41 })
42}
43
44fn main() -> ExitCode {
45 let Some(out) = std::env::args().nth(1) else {
46 eprintln!("usage: pst1-interplane-request OUT");
47 return ExitCode::from(2);
48 };
49 let v = request();
50 if !matches!(Payload::from_value(&v), Ok(Payload::ToolRequest(_))) {
51 eprintln!("not an INTERPLANE tool_request");
52 return ExitCode::from(1);
53 }
54 let canon = canonicalize(&v);
55 let again: Value = serde_json::from_str(&canon).expect("canonical text parses");
56 assert_eq!(canonicalize(&again), canon, "canonical form is stable");
57 if let Err(e) = std::fs::write(&out, canon.as_bytes()) {
58 eprintln!("cannot write {out}: {e}");
59 return ExitCode::from(2);
60 }
61 println!(
62 "bytes={} digest={}",
63 canon.len(),
64 digest_bytes(canon.as_bytes())
65 );
66 ExitCode::SUCCESS
67}