- reasoning_effort, reasoning.effort, variant, thinking.type=disabled und ein model#variant werden zur opencode-Modellvariante. Ein explizites "#" gewinnt gegen den Body; default/auto bedeutet keine Variante. - Die Brücke liest assistant-Nachrichten als ganze Objekte. Die echte API setzt time.completed vor type; der bisherige Scan ab type verlor damit die fertige Antwort und lief in den Timeout. - Tests decken alle Effort-Formen, den as-Rewrite und die Modell-Politik über die opencode-Brücke ab.
46 lines
2.1 KiB
C
46 lines
2.1 KiB
C
/* junction/opencode.h — opencode serve as a first-class endpoint.
|
|
*
|
|
* An opencode serve speaks a session-oriented API:
|
|
*
|
|
* POST /api/session -> {"data":{"id":"ses_…"}}
|
|
* POST /api/session/<id>/model {"model":{"id":…,"providerID":…}}
|
|
* POST /api/session/<id>/prompt {"text":"…"}
|
|
* GET /api/session/<id>/message -> {"data":[{type,…},…]}
|
|
* DELETE /api/session/<id>
|
|
*
|
|
* There is no /v1/chat/completions. This module translates one into the other, so a
|
|
* client that speaks OpenAI never has to know it is talking to opencode.
|
|
*/
|
|
#ifndef JUNCTION_OPENCODE_H
|
|
#define JUNCTION_OPENCODE_H
|
|
|
|
#include <stddef.h>
|
|
|
|
/* Runs one complete chat completion through opencode.
|
|
*
|
|
* base "http://127.0.0.1:4096" (no /v1 suffix; the paths above are absolute)
|
|
* user,pass HTTP Basic credentials; opencode accepts "opencode:<password>"
|
|
* model the model to ask for. May be "provider/id", "id", or empty for the
|
|
* server's default. A trailing "#variant" selects an opencode model
|
|
* variant (its reasoning-effort selector).
|
|
* req_body the OpenAI request body as received. reasoning_effort,
|
|
* reasoning.effort, variant and thinking.type=disabled are carried into
|
|
* the session model's variant; other generation options have no slot in
|
|
* the session prompt API.
|
|
* out_body receives a malloc'ed OpenAI response body (caller frees)
|
|
*
|
|
* Returns 0 on success, -1 on failure with a reason in err.
|
|
*/
|
|
int j_opencode_chat(const char *base, const char *user, const char *pass,
|
|
const char *model, const char *req_body,
|
|
char **out_body, size_t *out_len,
|
|
double timeout_s, char *err, size_t errlen);
|
|
|
|
/* Lists the models an opencode server knows, as an OpenAI /v1/models body.
|
|
* Same ownership rules as above. */
|
|
int j_opencode_models(const char *base, const char *user, const char *pass,
|
|
char **out_body, size_t *out_len,
|
|
double timeout_s, char *err, size_t errlen);
|
|
|
|
#endif /* JUNCTION_OPENCODE_H */
|