effort: model#variant für alle Endpoint-Arten, Pool-Member mit Modell

- OpenAI-kompatible Endpoints bekommen aus model#max reasoning_effort;
  Anthropic output_config.effort; opencode behält seine Variante.
- Ein Rewrite-Ziel (as) kann selbst ein #effort tragen; ein Client-Selektor
  überlebt den as-Rewrite. Der Cache-Schlüssel bleibt der ursprüngliche Body.
- Pool-Member dürfen endpoint/model#effort oder endpoint#effort heißen; ein
  Regel-as bleibt für Member ohne eigenes Modell in Kraft.
- # ist nur am Wortanfang ein Kommentar, innerhalb eines Tokens Daten.
- Tests decken Anthropic, OpenAI-kompatibel, as, Pool-Member und rule-as ab.
This commit is contained in:
Hermes committed 2026-11-16 08:35:16 +00:00
1 parent b3c426872b
commit df61582139
11 files changed
+373 -75

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ LDFLAGS ?=
PREFIX ?= /usr/local
J_WITH_TLS ?= auto
SRC = src/mesh.c src/mcp.c src/control.c src/control_ops.c src/compress.c src/price.c src/models.c src/config.c src/conn.c src/http.c src/cache.c src/opencode.c src/anthropic.c src/junction.c
SRC = src/mesh.c src/mcp.c src/control.c src/control_ops.c src/compress.c src/price.c src/models.c src/config.c src/conn.c src/http.c src/cache.c src/opencode.c src/effort.c src/junction.c
OBJ = $(SRC:.c=.o)
TOOLS = tools/junction-wol
+17 -6
View File
@@ -78,8 +78,10 @@ curl -s localhost:8090/status
## Configuration — pf.conf style
Keyword, arguments, braces. `#` comments, double quotes group words, unknown
keywords are a **hard error with a line number**. Full example: `config.example`.
Keyword, arguments, braces. `#` starts a comment at the beginning of a word;
inside a word it is data (`model#max`, `endpoint/model#max`). Double quotes group
words, unknown keywords are a **hard error with a line number**. Full example:
`config.example`.
```
# listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem
@@ -426,6 +428,13 @@ Endpoint:
pool lokal box3, box6
pool alles cloud, lokal
A pool member may also carry a model and effort for that endpoint only:
pool ds41flash opencode-go/deepseek-v4.1-flash#max, ollama0/deepseek-v4.1-flash#max
`endpoint#max` keeps the request's model and only adds the selector. A rule's
`as` stays in force for members that do not name a model.
req for "*" pass alles
| `idle_timeout` | silence before `still_working` is logged (seconds) |
@@ -462,10 +471,12 @@ a `model#variant` selector become `output_config.effort`. `minimal` maps to `low
`anthropic-version`, the endpoint's static version header is not added a second
time.
For every other endpoint kind the request body goes out unchanged, so
`reasoning_effort`, `reasoning.effort` and the other generation options reach the
provider as written. That is why Ollama Cloud needs no special case: its
OpenAI-compatible endpoint understands both fields.
For every other endpoint kind the request body goes out unchanged, except for a
`model#variant` selector: it is stripped and becomes `reasoning_effort`
(`minimal`→`low`, `ultra`→`max`, `default`/`auto` means no explicit effort).
`reasoning_effort`, `reasoning.effort` and the other generation options already in
the body reach the provider as written. That is why Ollama Cloud needs no special
case: its OpenAI-compatible endpoint understands both fields.
## Hooks
+2 -1
View File
@@ -1,4 +1,5 @@
# junction.conf — pf.conf-style. keyword, arguments, braces. '#' starts a comment.
# junction.conf — pf.conf-style. keyword, arguments, braces. '#' starts a comment
# at the beginning of a word; inside a word it is data (model#max).
# Double quotes group words. Unknown keywords are a hard error with a line number.
# Plain listener:
+4
View File
@@ -527,6 +527,10 @@ req for "blocked-*" block
# so a rule does not have to spell out five targets every time.
pool lokal ollama1, ollama2
pool alles opencode-go, lokal
# A member may name a model and effort for that endpoint only. endpoint#max keeps
# the request's model; endpoint/model#max replaces it. A rule's "as" still applies
# to members that do not name a model.
# pool ds41flash opencode-go/deepseek-v4.1-flash#max, ollama0/deepseek-v4.1-flash#max
# An endpoint may also fit on one line when it is small:
# endpoint kurz { base http://127.0.0.1:8080/v1; timeout 60 }
-21
View File
@@ -1,21 +0,0 @@
/* junction/anthropic.h — normalize OpenAI-style effort for the Anthropic Messages API.
*
* Anthropic does not know `reasoning_effort`, `reasoning.effort` or a `variant`
* field. Its Messages API takes `output_config.effort` (current) or the older
* `thinking` object. The client's model selector may carry a "#high" suffix, which
* opencode uses directly but Anthropic must not see.
*
* The rewrite only touches those fields. Everything else in the body stays as the
* client wrote it, including native `thinking` and `output_config` values.
*/
#ifndef JUNCTION_ANTHROPIC_H
#define JUNCTION_ANTHROPIC_H
#include <stddef.h>
/* Returns 0 and a malloc'ed body in *out / *out_len when something changed.
* Returns -1 and leaves *out NULL when the body needs no rewrite or is not a JSON
* object. The caller owns *out. */
int j_anthropic_normalize(const char *body, size_t len, char **out, size_t *outlen);
#endif
+43 -4
View File
@@ -35,7 +35,12 @@ static void strip_comment(char *s)
int quoted = 0;
for (char *p = s; *p; p++) {
if (*p == '"') quoted = !quoted;
else if (*p == '#' && !quoted) { *p = '\0'; return; }
else if (*p == '#' && !quoted && (p == s || isspace((unsigned char)p[-1]))) {
/* A comment starts at the beginning of a word. Inside a word '#' is
* data: model#max and endpoint/model#max are selectors. */
*p = '\0';
return;
}
}
}
@@ -1051,7 +1056,9 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
pl->line = lineno;
snprintf(pl->name, sizeof pl->name, "%s", w[1]);
for (int i = 2; i < n; ) {
char t[J_NAME_MAX];
char t[J_NAME_MAX + J_GLOB_MAX];
char target[J_NAME_MAX];
char target_model[J_GLOB_MAX] = "";
snprintf(t, sizeof t, "%s", w[i++]);
size_t tl = strlen(t);
while (tl && (t[tl-1] == ',' || t[tl-1] == ' ')) t[--tl] = '\0';
@@ -1062,8 +1069,35 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
fclose(fh);
return -1;
}
/* A pool member may name a model: endpoint/model#effort.
* endpoint#effort keeps the request's model and only adds the
* effort selector. */
char *sep = strchr(t, '/');
char *hash = strchr(t, '#');
if (sep != NULL) {
*sep = '\0';
if (sep[1] != '\0')
snprintf(target_model, sizeof target_model, "%s", sep + 1);
} else if (hash != NULL && hash != t) {
*hash = '\0';
snprintf(target_model, sizeof target_model, "%s", hash + 1);
size_t ml = strlen(target_model);
if (ml + 2 <= sizeof target_model)
memmove(target_model + 1, target_model, ml + 1);
target_model[0] = '#';
}
snprintf(target, sizeof target, "%s", t);
if (strlen(t) >= sizeof pl->targets[0]) {
snprintf(err, errlen, "line %d: pool %s: endpoint name too long",
lineno, pl->name);
fclose(fh);
return -1;
}
int idx = pl->count;
snprintf(pl->targets[idx], sizeof pl->targets[idx], "%s", t);
snprintf(pl->targets[idx], sizeof pl->targets[idx], "%s", target);
if (target_model[0])
snprintf(pl->target_as[idx], sizeof pl->target_as[idx],
"%s", target_model);
if (i < n && !strcmp(w[i], "as")) {
if (i + 1 >= n) {
snprintf(err, errlen, "line %d: 'as' without a model", lineno);
@@ -1268,9 +1302,14 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
snprintf(r->targets[k + pl->count - 1], sizeof r->targets[0], "%s", r->targets[k]);
snprintf(r->target_as[k + pl->count - 1], sizeof r->target_as[0], "%s", r->target_as[k]);
}
char rule_as[J_GLOB_MAX];
snprintf(rule_as, sizeof rule_as, "%s", r->target_as[t]);
for (int c = 0; c < pl->count; c++) {
snprintf(r->targets[t + c], sizeof r->targets[0], "%s", pl->targets[c]);
snprintf(r->target_as[t + c], sizeof r->target_as[0], "%s", pl->target_as[c]);
/* A pool member's own model wins; otherwise the rule's "as"
* stays in force for every expanded target. */
snprintf(r->target_as[t + c], sizeof r->target_as[0], "%s",
pl->target_as[c][0] ? pl->target_as[c] : rule_as);
}
r->target_count += pl->count - 1;
t += pl->count - 1;
+161 -21
View File
@@ -1,9 +1,10 @@
/* junction/anthropic.c — the small protocol translation the Messages API needs.
/* junction/effort.c — the model#effort selector, per endpoint dialect.
*
* Why this exists at all: junction is a router, not a translator, and for most
* endpoints the body goes out exactly as the client wrote it. Anthropic is the
* exception where the effort selector has a different name. opencode is the other,
* because its session API has no request-body slot for generation options.
* endpoints the body goes out exactly as the client wrote it. Two dialects name
* the effort differently: OpenAI-compatible endpoints call it `reasoning_effort`,
* Anthropic `output_config.effort`. opencode has no request-body slot at all and
* takes the selector as a model variant in its bridge.
*/
#define _POSIX_C_SOURCE 200809L
@@ -12,7 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include "anthropic.h"
#include "effort.h"
typedef struct {
char *buf;
@@ -315,22 +316,57 @@ static int emit_model(outbuf *b, const char *ks, const char *colon,
return app(b, vs, (size_t)(ve - vs));
}
static int emit_output(outbuf *b, const char *ks, const char *colon,
const char *vs, const char *ve, const char *effort)
static int append_effort_pair(outbuf *b, const char *effort)
{
if (apps(b, "\"effort\":") != 0) return -1;
return app_json_string(b, effort);
}
/* Copy an object, setting its "effort" field to EFFORT (replacing an existing
* one, adding it when missing). Everything else in the object is preserved. */
static int emit_object_effort(outbuf *b, const char *ks, const char *colon,
const char *vs, const char *ve,
const char *effort)
{
if (app(b, ks, (size_t)(colon - ks) + 1) != 0) return -1;
if (app(b, "{", 1) != 0) return -1;
int has_content = 0;
for (const char *q = vs + 1; q < ve - 1; q++) {
if (!isspace((unsigned char)*q)) { has_content = 1; break; }
const char *end = ve - 1; /* the closing '}' */
const char *p = skip_ws(vs + 1, end);
int first = 1, seen = 0;
while (p < end) {
if (*p != '"') return -1;
const char *ks2 = p;
const char *ke2 = skip_string(p, end);
if (!ke2) return -1;
const char *kend2 = ke2 - 1;
size_t klen2 = (size_t)(kend2 - (ks2 + 1));
p = skip_ws(ke2, end);
if (p >= end || *p != ':') return -1;
p = skip_ws(p + 1, end);
const char *ve2 = skip_value(p, end);
if (!ve2) return -1;
if (!first && app(b, ",", 1) != 0) return -1;
first = 0;
if (key_is(ks2 + 1, klen2, "effort")) {
if (append_effort_pair(b, effort) != 0) return -1;
seen = 1;
} else if (app(b, ks2, (size_t)(ve2 - ks2)) != 0) {
return -1;
}
p = skip_ws(ve2, end);
if (p < end && *p == ',') { p++; continue; }
if (p >= end) break;
return -1;
}
if (has_content) {
if (app(b, vs + 1, (size_t)(ve - vs - 2)) != 0) return -1;
if (app(b, ",", 1) != 0) return -1;
if (!seen) {
if (!first && app(b, ",", 1) != 0) return -1;
if (append_effort_pair(b, effort) != 0) return -1;
}
if (apps(b, "\"effort\":") != 0) return -1;
if (app_json_string(b, effort) != 0) return -1;
return app(b, "}", 1);
}
@@ -346,7 +382,7 @@ static int append_thinking(outbuf *b)
return apps(b, "\"thinking\":{\"type\":\"disabled\"}");
}
int j_anthropic_normalize(const char *body, size_t len, char **out, size_t *outlen)
int j_effort_anthropic(const char *body, size_t len, char **out, size_t *outlen)
{
*out = NULL;
*outlen = 0;
@@ -357,11 +393,18 @@ int j_anthropic_normalize(const char *body, size_t len, char **out, size_t *outl
if (scan_body(body, len, &s) != 0) return -1;
const char *effort = s.effort_prio > 0 ? map_effort(s.effort) : NULL;
int need_output = (effort && strcmp(effort, "none") != 0 && !s.native_effort);
/* An explicit model#selector or top-level variant is a deliberate override.
* Without one, a native output_config.effort wins (the client already speaks
* Anthropic). */
int override = s.effort_prio >= 3;
int need_output = (effort && strcmp(effort, "none") != 0 &&
(!s.native_effort || override));
int need_disable = (effort && !strcmp(effort, "none") &&
!s.native_effort && !s.has_thinking);
(!s.native_effort || override) && !s.has_thinking);
int drop_output = (effort && !strcmp(effort, "none") && override);
int drop = s.saw_reasoning_effort || s.saw_variant || s.saw_reasoning;
if (!drop && !s.model_variant && !need_output && !need_disable && !s.bad_output)
if (!drop && !s.model_variant && !need_output && !need_disable &&
!s.bad_output && !drop_output)
return -1;
if (len > (size_t)-1 - 512) return -1;
@@ -405,7 +448,7 @@ int j_anthropic_normalize(const char *body, size_t len, char **out, size_t *outl
int is_reasoning = key_is(ks + 1, klen, "reasoning");
int is_output = key_is(ks + 1, klen, "output_config");
int skip = is_reasoning_effort || is_variant || is_reasoning ||
(is_output && s.bad_output);
(is_output && (s.bad_output || drop_output));
if (!skip) {
if (!first && app(&b, ",", 1) != 0) goto fail;
@@ -413,7 +456,8 @@ int j_anthropic_normalize(const char *body, size_t len, char **out, size_t *outl
if (is_model && s.model_variant) {
if (emit_model(&b, ks, colon, vs, ve) != 0) goto fail;
} else if (is_output && s.output_is_object && need_output) {
if (emit_output(&b, ks, colon, vs, ve, effort) != 0) goto fail;
if (emit_object_effort(&b, ks, colon, vs, ve, effort) != 0)
goto fail;
} else {
if (app(&b, ks, (size_t)(ve - ks)) != 0) goto fail;
}
@@ -445,3 +489,99 @@ fail:
free(b.buf);
return -1;
}
int j_effort_openai(const char *body, size_t len, char **out, size_t *outlen)
{
*out = NULL;
*outlen = 0;
if (!body || len == 0) return -1;
scan s;
memset(&s, 0, sizeof s);
if (scan_body(body, len, &s) != 0) return -1;
/* Without a variant selector there is nothing to translate: reasoning_effort
* and reasoning.effort already are the OpenAI dialect. */
if (!s.model_variant && !s.saw_variant) return -1;
const char *effort = s.effort_prio > 0 ? map_effort(s.effort) : NULL;
int set_effort = effort && effort[0];
if (len > (size_t)-1 - 512) return -1;
outbuf b;
b.cap = len + 512;
b.len = 0;
b.buf = malloc(b.cap);
if (!b.buf) return -1;
b.buf[0] = '\0';
const char *end = body + len;
const char *p = skip_ws(body, end);
if (p >= end || *p != '{') goto fail;
p++;
if (app(&b, "{", 1) != 0) goto fail;
int first = 1;
for (;;) {
p = skip_ws(p, end);
if (p >= end) goto fail;
if (*p == '}') break;
if (*p != '"') goto fail;
const char *ks = p;
const char *ke = skip_string(p, end);
if (!ke) goto fail;
const char *kend = ke - 1;
size_t klen = (size_t)(kend - (ks + 1));
p = skip_ws(ke, end);
if (p >= end || *p != ':') goto fail;
const char *colon = p;
p = skip_ws(p + 1, end);
const char *vs = p;
const char *ve = skip_value(p, end);
if (!ve) goto fail;
int is_model = key_is(ks + 1, klen, "model");
int is_variant = key_is(ks + 1, klen, "variant");
int is_effort = key_is(ks + 1, klen, "reasoning_effort");
int is_reasoning = key_is(ks + 1, klen, "reasoning");
int is_object = (vs < ve && *vs == '{');
int skip = is_variant || (set_effort && is_effort) ||
(set_effort && is_reasoning && !is_object);
if (!skip) {
if (!first && app(&b, ",", 1) != 0) goto fail;
first = 0;
if (is_model && s.model_variant) {
if (emit_model(&b, ks, colon, vs, ve) != 0) goto fail;
} else if (set_effort && is_reasoning && is_object) {
if (emit_object_effort(&b, ks, colon, vs, ve, effort) != 0)
goto fail;
} else {
if (app(&b, ks, (size_t)(ve - ks)) != 0) goto fail;
}
}
p = skip_ws(ve, end);
if (p < end && *p == ',') { p++; continue; }
if (p < end && *p == '}') break;
goto fail;
}
if (set_effort) {
if (!first && app(&b, ",", 1) != 0) goto fail;
first = 0;
if (apps(&b, "\"reasoning_effort\":") != 0) goto fail;
if (app_json_string(&b, effort) != 0) goto fail;
}
if (app(&b, "}", 1) != 0) goto fail;
*out = b.buf;
*outlen = b.len;
return 0;
fail:
free(b.buf);
return -1;
}
+24
View File
@@ -0,0 +1,24 @@
/* junction/effort.h — the model#effort selector for the HTTP endpoint kinds.
*
* OpenAI-compatible endpoints take `reasoning_effort`; Anthropic takes
* `output_config.effort` (or `thinking.type=disabled` for none); opencode takes
* the selector as a model variant and handles it in its bridge. The rest of the
* request body stays as the client wrote it.
*/
#ifndef JUNCTION_EFFORT_H
#define JUNCTION_EFFORT_H
#include <stddef.h>
/* Normalize an OpenAI-style effort request for the Anthropic Messages API.
* Returns 0 and a malloc'ed body in *out / *out_len when something changed.
* Returns -1 and leaves *out NULL when the body needs no rewrite or is not a
* JSON object. The caller owns *out. */
int j_effort_anthropic(const char *body, size_t len, char **out, size_t *outlen);
/* Normalize a model#effort selector for an OpenAI-compatible endpoint: the
* suffix becomes `reasoning_effort`, the model keeps its real ID. Returns 0 and
* a malloc'ed body in *out / *out_len when something changed; -1 otherwise. */
int j_effort_openai(const char *body, size_t len, char **out, size_t *outlen);
#endif
+57 -20
View File
@@ -21,7 +21,7 @@
void j_control_ops_install(void);
#include "conn.h"
#include "http.h"
#include "anthropic.h"
#include "effort.h"
#include <ctype.h>
#include <errno.h>
@@ -1869,6 +1869,31 @@ static char *rewrite_model(const char *body, const char *new_model)
return out;
}
/* A rule's target model may be plain; the client's effort selector still has to
* survive the rewrite. An explicit "#..." in the target wins. */
static void model_for_target(const char *target, const char *orig,
char *out, size_t outlen)
{
/* "#max" is an effort suffix on the model the client asked for. */
if (target[0] == '#') {
const char *hash = orig ? strchr(orig, '#') : NULL;
size_t n = hash ? (size_t)(hash - orig) : (orig ? strlen(orig) : 0);
if (n >= outlen) n = outlen - 1;
if (n > 0) memcpy(out, orig, n);
out[n] = '\0';
snprintf(out + n, outlen - n, "%s", target);
return;
}
snprintf(out, outlen, "%s", target);
if (strchr(out, '#') != NULL) return;
const char *hash = orig ? strrchr(orig, '#') : NULL;
if (hash && hash[1]) {
size_t n = strlen(out);
if (n < outlen - 1)
snprintf(out + n, outlen - n, "%s", hash);
}
}
/* ------------------------------------------------------------------- network */
static int split_url(const char *base, char *host, size_t hostlen, char *port,
size_t portlen, char *prefix, size_t prefixlen, int *is_tls)
@@ -2523,31 +2548,20 @@ static int forward_step(j_conn *client, j_endpoint *ep, const j_req *rq,
}
/* The model this endpoint answers to may differ from what was asked for.
* Anthropic also needs its own effort field; do that before the as_model
* rewrite, because the rule's target name does not carry the client's
* "#variant" selector. cache_body stays the pre-normalized request: the cache
* lookup in handle_client used that body, and a fill under a different key
* would never be found again. */
* The rewrite runs first, so the effort selector from the rule's target or
* from the client's model#effort is in the body when the dialect normalizer
* sees it. cache_body stays the pre-normalized request: the cache lookup in
* handle_client used that body, and a fill under a different key would never
* be found again. */
char *body_alloc = NULL;
const char *cache_body = out_body;
size_t cache_len = out_len;
if (!strcmp(ep->kind, "anthropic") && out_body &&
!strncmp(rq->path, "/v1/messages", 12) &&
(rq->path[12] == '\0' || rq->path[12] == '?')) {
char *normalized = NULL;
size_t normalized_len = 0;
if (j_anthropic_normalize(out_body, out_len, &normalized, &normalized_len) == 0) {
body_alloc = normalized;
out_body = normalized;
out_len = normalized_len;
}
}
if (as_model && as_model[0] && out_body) {
char *rewritten = rewrite_model(out_body, as_model);
char target_model[256];
model_for_target(as_model, rq_model, target_model, sizeof target_model);
char *rewritten = rewrite_model(out_body, target_model);
if (rewritten) {
free(body_alloc);
body_alloc = rewritten;
out_body = rewritten;
out_len = strlen(rewritten);
@@ -2556,6 +2570,29 @@ static int forward_step(j_conn *client, j_endpoint *ep, const j_req *rq,
}
}
/* OpenAI-compatible endpoints take reasoning_effort; Anthropic takes
* output_config.effort. opencode's bridge reads the selector from the model
* itself and must not have it stripped here. */
if (out_body && strcmp(ep->kind, "opencode") != 0) {
char *normalized = NULL;
size_t normalized_len = 0;
int changed;
if (!strcmp(ep->kind, "anthropic") &&
(!strncmp(rq->path, "/v1/messages", 12) &&
(rq->path[12] == '\0' || rq->path[12] == '?')))
changed = j_effort_anthropic(out_body, out_len, &normalized, &normalized_len);
else if (strcmp(ep->kind, "anthropic") != 0)
changed = j_effort_openai(out_body, out_len, &normalized, &normalized_len);
else
changed = -1;
if (changed == 0) {
free(body_alloc);
body_alloc = normalized;
out_body = normalized;
out_len = normalized_len;
}
}
j_conn up = J_CONN_INIT;
if (j_conn_open(&up, host, port, tls, tls ? ep->tls_verify : 0, ep->tls_ca,
ep->connect_timeout_ms > 0 ? ep->connect_timeout_ms : CFG.connect_timeout_ms,
+63
View File
@@ -65,6 +65,8 @@ contains "$R" "X-Stub-Effort-Set: 0" "none does not invent an output_config effo
R=$(apost '{"model":"claude-x","max_tokens":64,"output_config":{"effort":"xhigh"},"reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: xhigh" "a native output_config.effort wins over OpenAI effort"
R=$(apost '{"model":"claude-x#max","max_tokens":64,"output_config":{"effort":"low"},"messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: max" "an explicit model#variant overrides a native output_config"
case "$R" in
*"X-Stub-Reasoning: low"*) bad "the losing reasoning_effort stayed in the body";;
*) ok "the losing reasoning_effort is removed";;
@@ -116,3 +118,64 @@ contains "$R" "X-Stub-Reasoning: high" "reasoning_effort reaches an OpenAI-compa
R=$(opost '{"model":"m","reasoning":{"effort":"medium"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Effort: medium" "reasoning.effort reaches an OpenAI-compatible endpoint unchanged"
contains "$R" "X-Stub-Has-Reasoning: 1" "the OpenAI reasoning object is not stripped"
# The same selector on an OpenAI-compatible endpoint: #max strips from the model
# and becomes reasoning_effort.
R=$(opost '{"model":"m#max","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Model: m" "OpenAI #max is removed from the model id"
contains "$R" "X-Stub-Reasoning: max" "OpenAI #max becomes reasoning_effort"
R=$(opost '{"model":"m#minimal","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Reasoning: low" "OpenAI #minimal is mapped to low"
R=$(opost '{"model":"m#auto","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
case "$R" in
*"X-Stub-Reasoning: auto"*) bad "OpenAI #auto was sent as an effort";;
*) ok "OpenAI #auto means no explicit effort";;
esac
R=$(opost '{"model":"m#max","reasoning":{"effort":"low"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Effort: max" "an explicit model selector wins over reasoning.effort"
R=$(opost '{"model":"m","variant":"low","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Reasoning: low" "a top-level variant becomes reasoning_effort"
# A junction pool member can carry its own model and effort: endpoint/model#effort.
P2=$((PORT+253))
cat > "$TMP/effort-pool.conf" <<CFG
listen 127.0.0.1:$P2
endpoint a { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
endpoint b { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
pool membermodel a/deepseek-v4.1-flash#max, b/deepseek-v4.1-flash#high
req for "*" check none pass membermodel
CFG
./junction --config "$TMP/effort-pool.conf" > "$TMP/effort-pool.log" 2>&1 &
PIDS+=($!)
wait_port $P2 10
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"whatever","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P2/v1/chat/completions")
contains "$R" "X-Stub-Model: deepseek-v4.1-flash" "a pool member model replaces the request model"
contains "$R" "X-Stub-Reasoning: max" "a pool member effort becomes reasoning_effort"
# A rule's "as" survives the pool expansion with bare members; endpoint#effort
# keeps the request's model and only adds the selector.
P3=$((PORT+254))
cat > "$TMP/effort-pool-as.conf" <<CFG
listen 127.0.0.1:$P3
endpoint a { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
endpoint b { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
pool bare a, b
pool membereff a#max, b#high
req for "withbare*" check none pass bare as "#low"
req for "*" check none pass membereff
CFG
./junction --config "$TMP/effort-pool-as.conf" > "$TMP/effort-pool-as.log" 2>&1 &
PIDS+=($!)
wait_port $P3 10
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"withbare","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P3/v1/chat/completions")
contains "$R" "X-Stub-Model: withbare" "a rule's as effort keeps the request model"
contains "$R" "X-Stub-Reasoning: low" "a rule's as survives the bare pool expansion"
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"witheff","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P3/v1/chat/completions")
contains "$R" "X-Stub-Model: witheff" "a pool endpoint#effort keeps the request model"
contains "$R" "X-Stub-Reasoning: max" "a pool endpoint#effort becomes reasoning_effort"
+1 -1
View File
@@ -53,7 +53,7 @@ log_has() {
# answer requests with somebody else's config), so fail loudly and early.
# 8157 gehört auf dieser Maschine dem Hermes-Gateway — der Port wird von keinem
# Test benutzt, also darf er die Suite nicht aufhalten.
for port in 8361 8362 8363 8364 8357 8358 8359 8360 8355 8356 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8375 8376 8377 8378 8385 8386 8387 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8165 8166 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
for port in 8361 8362 8363 8364 8357 8358 8359 8360 8355 8356 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8375 8376 8377 8378 8385 8386 8387 8388 8389 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8165 8166 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
if ss -tln 2>/dev/null | grep -q ":$port "; then
echo "port $port is busy — a leftover junction/stub is still running:"
ss -tlnp 2>/dev/null | grep ":$port " | sed 's/^/ /'