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.
This commit is contained in:
1 parent
49d18361e2
commit
a85b1c4615
16 files changed
+329
-40
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+4
-2
@@ -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
|
||||
|
||||
+48
-7
@@ -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;
|
||||
}
|
||||
|
||||
+67
-13
@@ -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);
|
||||
|
||||
@@ -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 <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* splinter -- base64 for A2A raw parts. */
|
||||
#ifndef SPLINTER_B64_H
|
||||
#define SPLINTER_B64_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
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 */
|
||||
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>24433</b> lines of C99/POSIX ·
|
||||
<b>23</b> tools · <b>31</b> test programs ·
|
||||
<p class="meta"><b>24614</b> lines of C99/POSIX ·
|
||||
<b>23</b> tools · <b>32</b> test programs ·
|
||||
<b>16</b> plugins · <b>42</b> palettes · BSD-3-Clause</p>
|
||||
|
||||
<h2>What it is</h2>
|
||||
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so</pre>
|
||||
<h2>Building</h2>
|
||||
<pre><span class="u">$</span> git clone ssh://host/home/git/splinter.git
|
||||
<span class="u">$</span> cd splinter && make <span class="d">small, nothing but libc and curses</span>
|
||||
<span class="u">$</span> make check <span class="d">31 test programs, plus the i18n checker</span>
|
||||
<span class="u">$</span> make check <span class="d">32 test programs, plus the i18n checker</span>
|
||||
<span class="u">$</span> ./splinter <span class="d">chat, the config is read</span>
|
||||
<span class="u">$</span> ./splinter --daemon <span class="d">Telegram gateway</span></pre>
|
||||
<p>POSIX make, C99, <code>-Wall -Wextra -Werror</code>. NetBSD curses is vendored, so the binary does not depend on a distribution's mood.</p>
|
||||
|
||||
+3
-3
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>24433</b> Zeilen C99/POSIX ·
|
||||
<b>23</b> Werkzeuge · <b>31</b> Test-Programme ·
|
||||
<p class="meta"><b>24614</b> Zeilen C99/POSIX ·
|
||||
<b>23</b> Werkzeuge · <b>32</b> Test-Programme ·
|
||||
<b>16</b> Plugins · <b>42</b> Farbschemata · BSD-3-Clause</p>
|
||||
|
||||
<h2>Was es ist</h2>
|
||||
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so</pre>
|
||||
<h2>Bauen</h2>
|
||||
<pre><span class="u">$</span> git clone ssh://host/home/git/splinter.git
|
||||
<span class="u">$</span> cd splinter && make <span class="d">klein, nichts ausser libc und curses</span>
|
||||
<span class="u">$</span> make check <span class="d">31 Test-Programme, plus i18n-Pruefer</span>
|
||||
<span class="u">$</span> make check <span class="d">32 Test-Programme, plus i18n-Pruefer</span>
|
||||
<span class="u">$</span> ./splinter <span class="d">Chat, Konfiguration wird gelesen</span>
|
||||
<span class="u">$</span> ./splinter --daemon <span class="d">Telegram-Gateway</span></pre>
|
||||
<p>POSIX make, C99, <code>-Wall -Wextra -Werror</code>. Die NetBSD-curses liegt im Baum, damit das Binary nicht von der Laune einer Distribution abhaengt.</p>
|
||||
|
||||
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>24433</b> linhas C99/POSIX ·
|
||||
<b>23</b> ferramentas · <b>31</b> programas de teste ·
|
||||
<p class="meta"><b>24614</b> linhas C99/POSIX ·
|
||||
<b>23</b> ferramentas · <b>32</b> programas de teste ·
|
||||
<b>16</b> plugins · <b>42</b> paletas · BSD-3-Clause</p>
|
||||
|
||||
<h2>O que e</h2>
|
||||
@@ -117,7 +117,7 @@ botoes Sim/Nao.</p>
|
||||
|
||||
<h2>Compilar</h2>
|
||||
<pre>make
|
||||
make check <span class="d"># 31 binarios de teste, i18n, site</span></pre>
|
||||
make check <span class="d"># 32 binarios de teste, i18n, site</span></pre>
|
||||
<p>Sem dependencias alem de libc e pthread; ncurses vem do vendor.</p>
|
||||
|
||||
<h2>O que nao e</h2>
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user