La segunda opinión: un juicio sobre tus números, con la probabilidad que trae
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Preguntaste si se podía implementar Jev, y con qué API. Resulta que Jev se sirve por OpenCode Zen,
así que una sola cuenta cubre esto y cualquier otra cosa apuntada a ese gateway:
POST https://opencode.ai/zen/v1/systemone Bearer <clave> model: jev-1.13
Y ahí está la razón de que valga la pena: Jev no es un modelo de chat. Le mandás un *estado* y
preguntas tipadas — sí/no (`noul`), opción (`choice`), rúbrica (`score`) — y contesta todas en una
sola petición con el valor **y la probabilidad que le puso**. "62% probable" se puede discutir;
"tomate una semana de descarga" no. Así que no entra por el Coach (que necesita *escribir*) y no se
fuerza dentro de su lista de proveedores: tiene su módulo, sus dos rutas y su tarjeta.
Qué hace. En Salud, arriba de la grilla, una tarjeta con cuatro respuestas: qué tan listo estás para
entrenar fuerte (nivel 1-5, con el número al lado), si la semana pide bajar carga (62% probable), qué
parte del cuerpo parece menos recuperada, y qué métrica de salud merece atención — esa última con la
última lectura de la métrica que nombró, para que "vigilá tu frecuencia en reposo" venga con el 62
que lo motivó. La hoja detrás del ⓘ dice a dónde va y exactamente qué se envía, con el mismo resumen
que devuelve el servidor.
Lo que sale, y lo que no. Se decide en `api/jev.js` y son agregados: una semana de cada métrica por
campo como la escribió el teléfono, series por parte del cuerpo de 4 semanas y de la última, sesiones,
días desde la última, RPE medio, estancamientos *por nombre de ejercicio*, el último pesaje y su
cambio. Ningún identificador: ni perfil, ni nombre, ni títulos de entrenamientos, ni ids de
ejercicios, ni chat — hay un test que lo afirma sobre el JSON, porque es una promesa que hacen los
docs y nada más la miraba. La única excepción es deliberada y está documentada: la nota de
*limitaciones* del cuestionario del Coach, porque "hombro malo" cambia la respuesta. (Los títulos sí
estuvieron un rato ahí: los saqué al escribir ese test, y el test se quedó.)
Un juicio no es una instrucción, y el código lo trata así. Cada respuesta se muestra con su
probabilidad; una pregunta que el modelo no contestó se muestra como no contestada, nunca como un
cero; un nivel que no habíamos ofrecido se marca en vez de disfrazarse de propio; y si los datos
cambiaron desde que se pidió (una sesión registrada, una noche que llegó) la tarjeta lo dice en lugar
de seguir pareciendo actual. Tampoco corre por temporizador: cuesta una petición, así que pasa cuando
alguien aprieta *Preguntar*, con cupo por perfil y por día y un piso de diez minutos aplicados en el
servidor, no en la pantalla.
El Coach, además, lo recibe como `secondOpinion` en su payload **solo si tiene menos de seis horas**,
como evidencia con confianza adjunta para citar en `why`, nunca como una orden ni como un cambio de
plan. Es la mitad que faltaba de "y el Coach escribe con eso".
El lector de respuestas es tolerante a propósito: el contrato de la petición está documentado, la
respuesta no la vimos nunca del servicio real, así que acepta las formas plausibles
(`answers`/`results`, `option`/`answer`/`choice`, `probability` o una distribución sobre los niveles),
normaliza lo que encuentra y devuelve `null` por lo que no puede leer. El cuerpo crudo queda guardado
al lado del parseado (y sale con `?raw=1`): la primera llamada real se puede mirar, y una forma mal
adivinada es un arreglo, no un misterio.
Dos cosas que encontré escribiendo esto y que quedan arregladas: una variable de entorno vacía se
leía como **cero** (`Number('')` pasa un chequeo ingenuo), así que un cupo sin configurar era "cero
peticiones" — un feature que parece configurado y no funciona nunca; y agregar la palabra *Back*
para la espalda redefinió el botón *Atrás* de la app a "Espalda", porque en un objeto literal la
última clave gana y nada lo dice. El catálogo de español tiene ahora un test que falla si una clave
se escribe dos veces, mutación comprobada.
Cobertura: 11 tests del módulo (el estado, las preguntas, cada forma de respuesta, la promesa de
privacidad, el cupo), 5 de las rutas contra un gateway de mentira y el servidor real, 6 del modelo de
vista en el frontend y 5 de render por la tarjeta real. API 259 en verde, frontend 1696, build OK.
This commit is contained in:
1 parent
5c69540f62
commit
90aa802980
24 files changed
+2078
-6
No files matched your search
@@ -774,6 +774,135 @@ paths:
|
||||
f: { qty: { n: 12, sum: 1340, min: 8, max: 310, last: 96, avg: 111.7 } }
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/insights:
|
||||
get:
|
||||
tags: [health]
|
||||
operationId: insightsGet
|
||||
summary: The profile's last second opinion, if the instance has one
|
||||
description: |
|
||||
Whether this instance is configured for a second opinion at all (`configured`, false unless
|
||||
`JEV_API_KEY` or `OPENCODE_API_KEY` is set), what was judged last, whether that judgment is
|
||||
still about the data on screen, and what is left of today's budget.
|
||||
|
||||
The judgment itself is a small object: one entry per question the server asked, each with
|
||||
the option or level the model chose and the probability it put there. A question it did not
|
||||
answer is `null` — the server never fills a gap with a guess, and the screen says the
|
||||
question went unanswered rather than drawing a zero.
|
||||
parameters:
|
||||
- name: raw
|
||||
in: query
|
||||
schema: { type: string, enum: ['1'] }
|
||||
description: >-
|
||||
Include the gateway's own response body, exactly as it arrived. Debugging detail: the
|
||||
default response leaves it out, because a screen polling this does not need it.
|
||||
responses:
|
||||
'200':
|
||||
description: The state of the feature and the last judgment.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
ok: { type: boolean }
|
||||
configured: { type: boolean }
|
||||
model:
|
||||
type: string
|
||||
nullable: true
|
||||
description: The model id this instance would ask, null when unconfigured.
|
||||
host:
|
||||
type: string
|
||||
nullable: true
|
||||
description: The gateway's hostname, for the screen to name. Never the key.
|
||||
insight:
|
||||
type: object
|
||||
nullable: true
|
||||
description: The stored judgment, or null before the first ask.
|
||||
freshness:
|
||||
type: object
|
||||
properties:
|
||||
fresh: { type: boolean }
|
||||
reason:
|
||||
type: string
|
||||
nullable: true
|
||||
enum: [none, old, data]
|
||||
description: >-
|
||||
`old` past its six hours, `data` because the profile changed since, `none`
|
||||
because there is no judgment at all.
|
||||
budget:
|
||||
type: object
|
||||
properties:
|
||||
used: { type: integer }
|
||||
remaining: { type: integer }
|
||||
allowed: { type: boolean }
|
||||
waitMs: { type: integer }
|
||||
nextAt: { type: integer, nullable: true }
|
||||
example:
|
||||
ok: true
|
||||
configured: true
|
||||
model: jev-1.13
|
||||
host: opencode.ai
|
||||
insight:
|
||||
v: 1
|
||||
at: 1758650400000
|
||||
model: jev-1.13
|
||||
answers:
|
||||
readiness: { type: score, value: 2.4, p: 0.58 }
|
||||
deload: { type: noul, p: 0.62, option: 'false' }
|
||||
limiter: { type: choice, option: back, p: 0.55, known: true }
|
||||
freshness: { fresh: true, reason: null }
|
||||
budget: { used: 1, remaining: 11, allowed: true, waitMs: 0, nextAt: null }
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
post:
|
||||
tags: [health]
|
||||
operationId: insightsAsk
|
||||
summary: Ask for a second opinion about this profile
|
||||
description: |
|
||||
Builds a state from the profile's own aggregates — a week of every health metric it has, the
|
||||
sets per body part over four weeks, the last few sessions, the newest weigh-in, and the Coach
|
||||
intake's goal and limitations note — sends it to Jev (TypeSafe's System One model, through
|
||||
the OpenCode Zen gateway) with four typed questions, and stores the answers.
|
||||
|
||||
**What leaves the instance is decided server-side and is aggregates only**: no name, no ids,
|
||||
no workout titles, no chat. The one piece of the person's own writing that goes is the
|
||||
intake's `limitations` field, because "bad shoulder" changes the answer; the sheet in front
|
||||
of the button lists exactly what will be sent before it is sent.
|
||||
|
||||
It costs a request, so it is never on a timer: the call is the ask, and the budget (`per
|
||||
profile per day`, plus a ten-minute floor) is enforced here rather than trusted to the
|
||||
client. A profile with no health data and no training still gets an answer — the questions
|
||||
that cannot be answered are simply not asked.
|
||||
responses:
|
||||
'200':
|
||||
description: The judgment, parsed. Every question the model left unanswered is null.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
ok: { type: boolean }
|
||||
model: { type: string }
|
||||
host: { type: string }
|
||||
insight: { type: object }
|
||||
freshness: { type: object }
|
||||
budget: { type: object }
|
||||
sent:
|
||||
type: object
|
||||
description: Counts, never content — what was just sent, for the screen to show.
|
||||
properties:
|
||||
metrics: { type: array, items: { type: string } }
|
||||
health_days: { type: integer }
|
||||
sessions: { type: integer }
|
||||
last_session_days_ago: { type: integer, nullable: true }
|
||||
body_parts: { type: array, items: { type: string } }
|
||||
includes_limitations: { type: boolean }
|
||||
'400':
|
||||
description: The instance has no key configured — the message names the variable to set.
|
||||
'429':
|
||||
description: Today's budget is spent, or ten minutes have not passed since the last ask.
|
||||
'502':
|
||||
description: The gateway refused or failed; the message carries what it said.
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/vitals/ingest:
|
||||
post:
|
||||
tags: [health]
|
||||
|
||||
Reference in new issue
Block a user