From a85b1c46155771dcdf77c52416e130b48887baff Mon Sep 17 00:00:00 2001
From: lotherk
Date: Tue, 10 Nov 2026 08:16:50 +0000
Subject: [PATCH] a2a: text/plain raw and string data parts
The server accepts text, a string in data, and a text/plain raw part
(base64) via the new sp_b64_decode; a url part (not fetched) or a binary
part is refused with ContentTypeNotSupported (-32005). The client reads
text, string data and text/plain raw, ignoring parts it cannot render.
The agent card now says streaming:true and pushNotifications:false.
test_b64 covers the decoder; test_a2a reads raw/data from the fake
agent; test_a2a_server accepts a raw part and refuses a url. test_ui
waits for the turn label to disappear after Ctrl-C before typing again.
Full make check green.
---
Makefile | 9 +++--
README.md | 2 +-
TODO.md | 11 ++++--
docs/PLUGINS.md | 6 ++-
plugins/a2a/a2a.c | 55 +++++++++++++++++++++++----
src/a2aserver.c | 80 +++++++++++++++++++++++++++++++++-------
src/b64.c | 70 +++++++++++++++++++++++++++++++++++
src/b64.h | 16 ++++++++
src/www/index.en.html | 6 +--
src/www/index.html | 6 +--
src/www/index.pt.html | 6 +--
tests/fake_a2a.py | 11 ++++++
tests/test_a2a.sh | 7 ++++
tests/test_a2a_server.sh | 12 +++++-
tests/test_b64.c | 65 ++++++++++++++++++++++++++++++++
tests/test_ui.sh | 7 ++++
16 files changed, 329 insertions(+), 40 deletions(-)
create mode 100644 src/b64.c
create mode 100644 src/b64.h
create mode 100644 tests/test_b64.c
diff --git a/Makefile b/Makefile
index ee98178..628d569 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
LIB = libsplinter.so
LIBOBJ = src/buf.o src/tool.o src/session.o src/conv.o src/transport.o \
src/json.o src/sse.o src/openai.o src/transport_openai.o src/builtin.o \
- src/agent.o src/theme.o src/palettes.o src/decomp.o src/i18n.o src/delegate.o src/telegram.o src/log.o src/cmdscript.o src/folder.o src/interview.o src/ack.o src/mcpserver.o src/skills.o src/memory.o src/prompt.o src/config.o src/plugin.o src/curl.o src/swarm.o src/provstate.o src/md.o src/a2aserver.o
+ src/agent.o src/theme.o src/palettes.o src/decomp.o src/i18n.o src/delegate.o src/telegram.o src/log.o src/cmdscript.o src/folder.o src/interview.o src/ack.o src/mcpserver.o src/skills.o src/memory.o src/prompt.o src/config.o src/plugin.o src/curl.o src/swarm.o src/provstate.o src/md.o src/b64.o src/a2aserver.o
BIN = splinter
BINOBJ = src/main.o src/ui.o
PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
@@ -37,7 +37,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
plugins/tmux/tmux.so
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
tests/test_transport tests/test_agent tests/test_openai \
- tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_swarm tests/test_provstate tests/test_planner tests/test_jobs
+ tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_b64 tests/test_swarm tests/test_provstate tests/test_planner tests/test_jobs
RPATH = -Wl,-rpath,'$$ORIGIN'
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
@@ -107,7 +107,7 @@ plugins/cps/cps.so: plugins/cps/cps.c $(LIB)
# the day somebody adds an #include, every object depends on the headers that
# make up the interface: a change there rebuilds everything that could see it.
HDRS = include/splinter.h include/splinter_plugin.h src/config.h src/ack.h \
- src/curl.h src/log.h src/i18n.h src/md.h src/a2aserver.h
+ src/curl.h src/log.h src/i18n.h src/md.h src/b64.h src/a2aserver.h
$(LIBOBJ) $(BINOBJ): $(HDRS)
$(PLUGIN): $(HDRS)
@@ -142,6 +142,7 @@ src/config.o: src/config.h include/splinter.h
src/plugin.o: include/splinter.h include/splinter_plugin.h
src/ui.o: src/ui.h src/theme.h src/decomp.h src/i18n.h include/splinter.h include/splinter_plugin.h src/md.h
src/md.o: src/md.h include/splinter.h
+src/b64.o: src/b64.h include/splinter.h
src/a2aserver.o: src/a2aserver.h include/splinter.h vendor/libmcp/mcp.h
src/main.o: include/splinter.h src/config.h src/i18n.h include/splinter_plugin.h src/ui.h src/theme.h src/a2aserver.h
@@ -182,6 +183,8 @@ tests/test_ascii: tests/test_ascii.c $(LIB) $(BINOBJ)
$(TEST_RPATH) $(CURSES_A) $(LIBS)
tests/test_md: tests/test_md.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_md.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
+tests/test_b64: tests/test_b64.c $(LIB)
+ $(CC) $(CFLAGS) -o $@ tests/test_b64.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_swarm: tests/test_swarm.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_swarm.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_provstate: tests/test_provstate.c $(LIB)
diff --git a/README.md b/README.md
index 844a67b..a7258ae 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ the screen, a sidebar on one quarter, plugins that can put tools and widgets
into both.
make # libsplinter.so, the binary, the plugins
- make check # every test binary (31), no network, no model
+ make check # every test binary (32), no network, no model
splinter # starts the chat from ~/.config/splinter/config
diff --git a/TODO.md b/TODO.md
index e9efa65..f4134d6 100644
--- a/TODO.md
+++ b/TODO.md
@@ -25,8 +25,10 @@ Turn in der Konversation des `contextId`), `SendStreamingMessage` (SSE,
`PushNotificationNotSupported` (-32003), `SubscribeToTask`
`UnsupportedOperation` (-32004).
-Offen: Datei- und strukturierte Teile, echte Push-Notifications und die
-Fortsetzung eines unterbrochenen Tasks (`INPUT_REQUIRED`).
+Text, text/plain `raw` (base64) und String-`data`-Teile werden gelesen; ein
+`url`- oder binaerer Teil wird mit `ContentTypeNotSupported` (-32005) abgelehnt,
+nicht abgerufen. Offen: echte Push-Notifications und die Fortsetzung eines
+unterbrochenen Tasks (`INPUT_REQUIRED`).
Naechster Schritt: Datei-Teile.
@@ -72,8 +74,9 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code.
(JSON-RPC 2.0, Text, blockierend), in der UI `SendStreamingMessage` (SSE,
Artefakt-Text live) und findet den Endpunkt ueber `SPLINTER_A2A_CARD`;
`src/a2aserver.c` serviert `SendMessage`, `SendStreamingMessage` (SSE),
- `GetTask`, `ListTasks`, Multiturn ueber `contextId` und die Agent Card mit
- Bearer-Token. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
+ `GetTask`, `ListTasks`, Multiturn ueber `contextId`, text/plain-`raw`- und
+ String-`data`-Teile und die Agent Card mit Bearer-Token; die Karte meldet
+ `streaming:true`. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
Streaming und Discovery, `tests/test_a2a_ui.sh` den Streaming-Pfad,
`tests/test_a2a_server.sh` den Server und den Client gegen den Server
(Discovery, blockierend und streamend), `tests/test_a2a_context.sh` die
diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md
index d13237e..9c2eef8 100644
--- a/docs/PLUGINS.md
+++ b/docs/PLUGINS.md
@@ -292,8 +292,10 @@ selected like any other:
splinter --plugin plugins/a2a/a2a.so --transport a2a -p "..."
It sends `SendMessage` as JSON-RPC 2.0 with one text part, blocking, and reads
-either a direct `Message` or a `Task` in `TASK_STATE_COMPLETED`; text parts from
-the status message and the artifacts are joined. `SPLINTER_A2A_FULL=1` sends the
+either a direct `Message` or a `Task` in `TASK_STATE_COMPLETED`; text parts,
+text/plain `raw` parts (base64) and string `data` parts from the status message
+and the artifacts are joined. A `url` or binary part is ignored on the client
+and refused on the server with `ContentTypeNotSupported` (-32005). `SPLINTER_A2A_FULL=1` sends the
whole transcript instead of the last user turn, and `SPLINTER_A2A_TIMEOUT` sets
the curl timeout (default 300 seconds). The task id and context id are remembered
for the session, so the next turn stays in the same A2A context; a terminal task
diff --git a/plugins/a2a/a2a.c b/plugins/a2a/a2a.c
index 5070913..acbb3e5 100644
--- a/plugins/a2a/a2a.c
+++ b/plugins/a2a/a2a.c
@@ -42,6 +42,7 @@
#include "splinter_plugin.h"
#include "curl.h"
#include "mcp.h"
+#include "b64.h"
struct a2a_cfg {
char url[512];
@@ -124,7 +125,19 @@ build_request(struct a2a_cfg *c, const char *method, const char *text,
return 0;
}
-/* text parts -> out, joined by newlines; 0 when at least one was found */
+static int
+append_piece(struct sp_buf *out, const char *s)
+{
+ if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
+ return -1;
+ return sp_buf_puts(out, s);
+}
+
+/*
+ * Text, a string in data, or a text/plain raw part. A binary or url part is
+ * ignored: the transport has nowhere to put a file, and an answer made only of
+ * one becomes "empty answer" rather than a made-up string.
+ */
static int
collect_parts(const mcp_json *parts, struct sp_buf *out)
{
@@ -137,14 +150,42 @@ collect_parts(const mcp_json *parts, struct sp_buf *out)
for (i = 0; i < n; i++) {
const mcp_json *p = mcp_array_at(parts, i);
const char *t = mcp_arg_string(p, "text");
+ const char *d, *raw, *mt;
- if (t == NULL || *t == '\0')
+ if (t != NULL && *t != '\0') {
+ if (append_piece(out, t) != 0)
+ return 0;
+ found = 1;
continue;
- if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
- return 0;
- if (sp_buf_puts(out, t) != 0)
- return 0;
- found = 1;
+ }
+ d = mcp_arg_string(p, "data");
+ if (d != NULL && *d != '\0') {
+ if (append_piece(out, d) != 0)
+ return 0;
+ found = 1;
+ continue;
+ }
+ raw = mcp_arg_string(p, "raw");
+ if (raw == NULL || *raw == '\0')
+ continue;
+ mt = mcp_arg_string(p, "mediaType");
+ if (mt != NULL && *mt != '\0' && strncmp(mt, "text/", 5) != 0)
+ continue;
+ {
+ struct sp_buf dec;
+
+ if (sp_buf_init(&dec) != 0)
+ return 0;
+ if (sp_b64_decode(raw, strlen(raw), &dec) == 0 &&
+ dec.len > 0) {
+ if (append_piece(out, dec.p) != 0) {
+ sp_buf_free(&dec);
+ return 0;
+ }
+ found = 1;
+ }
+ sp_buf_free(&dec);
+ }
}
return found;
}
diff --git a/src/a2aserver.c b/src/a2aserver.c
index 62a7636..f0a450b 100644
--- a/src/a2aserver.c
+++ b/src/a2aserver.c
@@ -44,6 +44,7 @@
#include "splinter.h"
#include "mcp.h"
+#include "b64.h"
#include "a2aserver.h"
#define A2A_TASKS 32
@@ -253,25 +254,73 @@ json_id(const char *payload, char *out, size_t cap)
}
}
+/*
+ * A part can be text, a string in data, or a text/plain raw part (base64). A
+ * url is not fetched (that would be an SSRF hole in an agent server), and a
+ * structured object is not guessed at; both are refused with
+ * ContentTypeNotSupported. Returns 0 when text was collected, 1 when the
+ * content cannot be used, -1 on allocation failure.
+ */
+static int
+append_text(struct sp_buf *out, const char *s)
+{
+ if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
+ return -1;
+ return sp_buf_puts(out, s);
+}
+
static int
collect_text(const mcp_json *parts, struct sp_buf *out)
{
size_t i, n;
+ int got = 0;
if (parts == NULL || parts->t != MCP_ARR)
- return 0;
+ return 1;
n = mcp_array_len(parts);
for (i = 0; i < n; i++) {
- const char *t = mcp_arg_string(mcp_array_at(parts, i), "text");
+ const mcp_json *p = mcp_array_at(parts, i);
+ const char *t = mcp_arg_string(p, "text");
+ const char *d, *raw, *mt;
- if (t == NULL || *t == '\0')
+ if (t != NULL && *t != '\0') {
+ if (append_text(out, t) != 0)
+ return -1;
+ got = 1;
continue;
- if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
- return 0;
- if (sp_buf_puts(out, t) != 0)
- return 0;
+ }
+ d = mcp_arg_string(p, "data");
+ if (d != NULL && *d != '\0') {
+ if (append_text(out, d) != 0)
+ return -1;
+ got = 1;
+ continue;
+ }
+ raw = mcp_arg_string(p, "raw");
+ if (raw != NULL && *raw != '\0') {
+ struct sp_buf dec;
+
+ mt = mcp_arg_string(p, "mediaType");
+ if (mt != NULL && *mt != '\0' &&
+ strncmp(mt, "text/", 5) != 0)
+ return 1;
+ if (sp_buf_init(&dec) != 0)
+ return -1;
+ if (sp_b64_decode(raw, strlen(raw), &dec) != 0) {
+ sp_buf_free(&dec);
+ return 1;
+ }
+ if (dec.len > 0 && append_text(out, dec.p) != 0) {
+ sp_buf_free(&dec);
+ return -1;
+ }
+ sp_buf_free(&dec);
+ got = 1;
+ continue;
+ }
+ return 1;
}
- return out->len > 0;
+ return got ? 0 : 1;
}
static struct a2a_task *
@@ -578,8 +627,10 @@ handle_stream(int fd, struct sp_agent *ag, const char *id,
sse_start(fd);
message = mcp_arg(params, "message");
parts = message != NULL ? mcp_arg(message, "parts") : NULL;
- if (!collect_text(parts, &text)) {
- sse_error(&o, -32602, "message has no text parts");
+ rc = collect_text(parts, &text);
+ if (rc != 0) {
+ sse_error(&o, rc == 1 ? -32005 : -32603,
+ rc == 1 ? "unsupported content type" : "out of memory");
goto out;
}
ctx = mcp_arg_string(message, "contextId");
@@ -664,8 +715,11 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
}
message = mcp_arg(params, "message");
parts = message != NULL ? mcp_arg(message, "parts") : NULL;
- if (!collect_text(parts, &text)) {
- rpc_error(fd, id, -32602, "message has no text parts");
+ rc = collect_text(parts, &text);
+ if (rc != 0) {
+ rpc_error(fd, id, rc == 1 ? -32005 : -32603,
+ rc == 1 ? "unsupported content type" :
+ "out of memory");
goto send_out;
}
ctx = mcp_arg_string(message, "contextId");
@@ -836,7 +890,7 @@ serve_conn(int fd, struct sp_agent *ag, const char *token)
"\"supportedInterfaces\":[{\"url\":\"http://%s/a2a\","
"\"protocolBinding\":\"JSONRPC\","
"\"protocolVersion\":\"1.0\"}],"
- "\"capabilities\":{\"streaming\":false},"
+ "\"capabilities\":{\"streaming\":true,\"pushNotifications\":false},"
"\"defaultInputModes\":[\"text/plain\"],"
"\"defaultOutputModes\":[\"text/plain\"],"
"\"skills\":[]}", SP_VERSION, hostbuf);
diff --git a/src/b64.c b/src/b64.c
new file mode 100644
index 0000000..11ec3f5
--- /dev/null
+++ b/src/b64.c
@@ -0,0 +1,70 @@
+/*
+ * splinter -- base64 for A2A raw parts.
+ *
+ * Copyright (c) 2026 Konrad Lother
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Small on purpose: A2A's raw part is base64, and the harness only needs to
+ * turn a text/plain part back into text. Whitespace is ignored, padding is
+ * optional, and a character outside the alphabet is an error rather than a
+ * silently different byte.
+ */
+#include
+
+#include "splinter.h"
+#include "b64.h"
+
+static int
+b64_val(unsigned char c)
+{
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A';
+ if (c >= 'a' && c <= 'z')
+ return c - 'a' + 26;
+ if (c >= '0' && c <= '9')
+ return c - '0' + 52;
+ if (c == '+')
+ return 62;
+ if (c == '/')
+ return 63;
+ return -1;
+}
+
+int
+sp_b64_decode(const char *in, size_t len, struct sp_buf *out)
+{
+ unsigned acc = 0;
+ int bits = 0;
+ size_t i;
+ int pad = 0;
+
+ if (in == NULL || out == NULL)
+ return -1;
+ for (i = 0; i < len; i++) {
+ unsigned char c = (unsigned char)in[i];
+ int v;
+
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
+ continue;
+ if (c == '=') {
+ pad = 1;
+ continue;
+ }
+ if (pad)
+ return -1; /* data after padding */
+ v = b64_val(c);
+ if (v < 0)
+ return -1;
+ acc = (acc << 6) | (unsigned)v;
+ bits += 6;
+ if (bits >= 8) {
+ char ch;
+
+ bits -= 8;
+ ch = (char)((acc >> bits) & 0xff);
+ if (sp_buf_add(out, &ch, 1) != 0)
+ return -1;
+ }
+ }
+ return 0;
+}
diff --git a/src/b64.h b/src/b64.h
new file mode 100644
index 0000000..28785af
--- /dev/null
+++ b/src/b64.h
@@ -0,0 +1,16 @@
+/* splinter -- base64 for A2A raw parts. */
+#ifndef SPLINTER_B64_H
+#define SPLINTER_B64_H
+
+#include
+
+struct sp_buf;
+
+/*
+ * Decode standard base64 (A-Z a-z 0-9 + /, '=' padding, whitespace ignored)
+ * and append the bytes to 'out'. Padding is optional. Returns 0, or -1 for an
+ * invalid character or allocation failure.
+ */
+int sp_b64_decode(const char *in, size_t len, struct sp_buf *out);
+
+#endif /* SPLINTER_B64_H */
diff --git a/src/www/index.en.html b/src/www/index.en.html
index 8917e04..40b7d62 100644
--- a/src/www/index.en.html
+++ b/src/www/index.en.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
An agent harness you own: chat in the terminal, tools with authorization classes, plugins, any model that speaks OpenAI — built by us so we can change it, instead of getting used to how somebody else's client behaves.
-24433 lines of C99/POSIX ·
-23 tools · 31 test programs ·
+
24614 lines of C99/POSIX ·
+23 tools · 32 test programs ·
16 plugins · 42 palettes · BSD-3-Clause
What it is
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so
Building
$ git clone ssh://host/home/git/splinter.git
$ cd splinter && make small, nothing but libc and curses
-$ make check 31 test programs, plus the i18n checker
+$ make check 32 test programs, plus the i18n checker
$ ./splinter chat, the config is read
$ ./splinter --daemon Telegram gateway
POSIX make, C99, -Wall -Wextra -Werror. NetBSD curses is vendored, so the binary does not depend on a distribution's mood.
diff --git a/src/www/index.html b/src/www/index.html
index e039699..bbfaba7 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.
-24433 Zeilen C99/POSIX ·
-23 Werkzeuge · 31 Test-Programme ·
+
24614 Zeilen C99/POSIX ·
+23 Werkzeuge · 32 Test-Programme ·
16 Plugins · 42 Farbschemata · BSD-3-Clause
Was es ist
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so
Bauen
$ git clone ssh://host/home/git/splinter.git
$ cd splinter && make klein, nichts ausser libc und curses
-$ make check 31 Test-Programme, plus i18n-Pruefer
+$ make check 32 Test-Programme, plus i18n-Pruefer
$ ./splinter Chat, Konfiguration wird gelesen
$ ./splinter --daemon Telegram-Gateway
POSIX make, C99, -Wall -Wextra -Werror. Die NetBSD-curses liegt im Baum, damit das Binary nicht von der Laune einer Distribution abhaengt.
diff --git a/src/www/index.pt.html b/src/www/index.pt.html
index 2c14923..651e786 100644
--- a/src/www/index.pt.html
+++ b/src/www/index.pt.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.
-24433 linhas C99/POSIX ·
-23 ferramentas · 31 programas de teste ·
+
24614 linhas C99/POSIX ·
+23 ferramentas · 32 programas de teste ·
16 plugins · 42 paletas · BSD-3-Clause
O que e
@@ -117,7 +117,7 @@ botoes Sim/Nao.
Compilar
make
-make check # 31 binarios de teste, i18n, site
+make check # 32 binarios de teste, i18n, site
Sem dependencias alem de libc e pthread; ncurses vem do vendor.
O que nao e
diff --git a/tests/fake_a2a.py b/tests/fake_a2a.py
index 75dcb91..dbf81b0 100644
--- a/tests/fake_a2a.py
+++ b/tests/fake_a2a.py
@@ -89,6 +89,17 @@ class H(http.server.BaseHTTPRequestHandler):
else:
b = json.dumps({"jsonrpc": "2.0", "id": rid,
"result": {"message": msg}}).encode()
+ elif "raw" in text:
+ body = {"jsonrpc": "2.0", "id": rid, "result": {"task": {
+ "id": "task-1", "contextId": "ctx-1",
+ "status": {"state": "TASK_STATE_COMPLETED",
+ "message": {"messageId": "m5",
+ "role": "ROLE_AGENT",
+ "parts": [{"text": "text teil"}]}},
+ "artifacts": [{"artifactId": "a3", "parts": [
+ {"raw": "aGFsbG8=", "mediaType": "text/plain"},
+ {"data": "struktur"}]}]}}}
+ b = json.dumps(body).encode()
elif stream and "streamstatus" in text:
b = (event(rid, {"task": task_obj("TASK_STATE_WORKING")}) +
event(rid, {"statusUpdate": {
diff --git a/tests/test_a2a.sh b/tests/test_a2a.sh
index cc1276d..73d5436 100755
--- a/tests/test_a2a.sh
+++ b/tests/test_a2a.sh
@@ -57,6 +57,13 @@ out=$(blocking "direkt" 2>&1)
echo "$out" | grep -q 'direkt vom agenten'
check test $? -eq 0
+# raw (text/plain base64) and string data parts are read
+out=$(blocking "raw" 2>&1)
+echo "$out" | grep -q 'hallo'
+check test $? -eq 0
+echo "$out" | grep -q 'struktur'
+check test $? -eq 0
+
# the token goes out as a bearer header, and is required when the agent asks
out=$(SPLINTER_A2A_TOKEN=tok blocking "auth bitte" 2>&1)
echo "$out" | grep -q 'a2a sagt hallo'
diff --git a/tests/test_a2a_server.sh b/tests/test_a2a_server.sh
index 3c6ea8b..4f5e752 100755
--- a/tests/test_a2a_server.sh
+++ b/tests/test_a2a_server.sh
@@ -18,7 +18,7 @@ cleanup() {
}
trap cleanup EXIT
mkdir -p "$D/home"
-printf 'answer hallo von splinter\nanswer hallo von splinter\nanswer hallo von splinter\nanswer hallo von splinter\n' > "$D/model.txt"
+printf 'answer hallo von splinter\nanswer hallo von splinter\nanswer hallo von splinter\nanswer hallo von splinter\nanswer hallo von splinter\n' > "$D/model.txt"
fails=0
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
@@ -48,6 +48,8 @@ check wait_port "$P"
card=$(curl -s "http://127.0.0.1:$P/.well-known/agent-card.json")
echo "$card" | grep -q '"protocolBinding":"JSONRPC"'
check test $? -eq 0
+echo "$card" | grep -q '"streaming":true'
+check test $? -eq 0
echo "$card" | grep -q "/a2a"
check test $? -eq 0
@@ -96,6 +98,14 @@ resp4=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"4\",\"method\":\"GetTask\",\"pa
echo "$resp4" | grep -q '"code":-32001'
check test $? -eq 0
+# a text/plain raw part is accepted; a url part is refused, not fetched
+resp10=$(post "$P" '{"jsonrpc":"2.0","id":"10","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"raw":"aGFsbG8=","mediaType":"text/plain"}]}}}')
+echo "$resp10" | grep -q 'TASK_STATE_COMPLETED'
+check test $? -eq 0
+resp11=$(post "$P" '{"jsonrpc":"2.0","id":"11","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"url":"http://example/x"}]}}}')
+echo "$resp11" | grep -q '"code":-32005'
+check test $? -eq 0
+
# ---- the client half against the server half ----
# discovery (the agent card names /a2a) plus a blocking turn, then the
# streaming path: both sides of the protocol in one process pair
diff --git a/tests/test_b64.c b/tests/test_b64.c
new file mode 100644
index 0000000..e1451fe
--- /dev/null
+++ b/tests/test_b64.c
@@ -0,0 +1,65 @@
+/*
+ * splinter -- base64 for A2A raw parts.
+ *
+ * The vectors are the usual ones; the interesting cases are optional padding,
+ * whitespace (Telegram/JSON pretty-printing), and a byte that must not become
+ * a silently different byte.
+ */
+#include
+#include
+
+#include "splinter.h"
+#include "b64.h"
+
+static int failures;
+
+#define CHECK(cond) do { \
+ if (!(cond)) { \
+ fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
+ failures++; \
+ } \
+} while (0)
+
+static void
+decode_is(const char *in, const char *want, size_t want_len)
+{
+ struct sp_buf b;
+ int rc;
+
+ CHECK(sp_buf_init(&b) == 0);
+ rc = sp_b64_decode(in, strlen(in), &b);
+ if (rc != 0) {
+ fprintf(stderr, "FAIL %s:%d: rc %d for \"%s\"\n", __FILE__,
+ __LINE__, rc, in);
+ failures++;
+ } else {
+ CHECK(b.len == want_len);
+ CHECK(memcmp(b.p != NULL ? b.p : "", want, want_len) == 0);
+ }
+ sp_buf_free(&b);
+}
+
+int
+main(void)
+{
+ decode_is("", "", 0);
+ decode_is("aGVsbG8=", "hello", 5);
+ decode_is("aGVsbG8", "hello", 5); /* padding is optional */
+ decode_is("aGVs bG8=\n", "hello", 5); /* whitespace is ignored */
+ decode_is("AA==", "\0", 1);
+ decode_is("SGVsbG8sIFdvcmxkIQ==", "Hello, World!", 13);
+
+ {
+ struct sp_buf b;
+
+ CHECK(sp_buf_init(&b) == 0);
+ CHECK(sp_b64_decode("!!!!", 4, &b) != 0);
+ CHECK(sp_b64_decode(NULL, 0, &b) != 0);
+ CHECK(sp_b64_decode("aGVsbG8=", 8, NULL) != 0);
+ sp_buf_free(&b);
+ }
+
+ if (failures == 0)
+ printf("test_b64: ok\n");
+ return failures == 0 ? 0 : 1;
+}
diff --git a/tests/test_ui.sh b/tests/test_ui.sh
index 6019e18..9bb936c 100755
--- a/tests/test_ui.sh
+++ b/tests/test_ui.sh
@@ -47,6 +47,13 @@ shows() { # wait until the screen contains $1
done
return 1
}
+done_turn() { # wait until the turn label is gone
+ for i in $(seq 1 60); do
+ tmux capture-pane -t $S -p | grep -q 'working' || return 0
+ sleep 0.5
+ done
+ return 1
+}
start() { # a fresh fake model and a fresh UI
[ -n "$F" ] && kill "$F" 2>/dev/null
killserver