hzhang e5ca677113 feat(translate): handle canonical.ImageBlock → Anthropic image content
Picks the most efficient source shape available:

  URL set        → {"type":"url", "url":...}
  DataBase64 set → {"type":"base64", "media_type":..., "data":...}
  Path set       → read file → base64 → {"type":"base64", ...}

MIME defaults to application/octet-stream when ImageBlock.MediaType is
empty (some servers accept that, some don't — operator's responsibility
to fill it in upstream).

File read failure → emits a "[image %q unavailable]" text block in its
place so the message still goes through with provenance preserved.

Verified live against Kimi K2.6 via Fabric channel: alice uploads
blue 32x32 PNG → Fabric plugin downloads + emits Media in inbound →
host turncore builds canonical.Message with ImageBlock → translator
reads file + base64s → Kimi responds "Blue".
2026-05-31 21:03:04 +01:00

Plexum-anthropic-compat-client

Shared HTTP+SSE Anthropic Messages API client + canonical ↔ Anthropic translator. Used by Plexum provider plugins that talk to any "Anthropic-compatible" endpoint (the one Anthropic itself, MiniMax, Kimi, Qwen, etc. all expose at /v1/messages).

Each provider plugin imports these two packages and adds:

  • its own cmd/plexum-<name>-provider-plugin/main.go entry
  • a list of supported model ids in the manifest
  • an endpoint URL + auth key + optional User-Agent override

Packages

anthropic/

Minimal HTTP+SSE client. Single entry point:

client := anthropic.New(baseURL, apiKey)
client.UserAgent = "claude-code/0.1.0" // optional
events, err := client.StreamMessages(ctx, anthropic.MessagesRequest{
    Model: "MiniMax-M2.7", MaxTokens: 4096,
    Messages: []anthropic.Message{...},
})
for ev := range events { /* anthropic.Event */ }

Features:

  • POST /v1/messages with stream: true
  • Parses standard SSE frames (event: + data: + blank line)
  • Surfaces non-2xx as HTTP error (before channel opens)
  • Surfaces mid-stream errors as Event{Type:"error"} final entry
  • UserAgent + ExtraHeaders fields for per-backend customization
  • 5min per-call timeout

translate/

Bidirectional canonical-types ↔ Anthropic-types adapter:

  • CanonicalToAnthropic(req canonical.TurnRequest, modelID, defaultMaxTokens) → anthropic.MessagesRequest
  • Translator state machine consumes <-chan anthropic.Event, emits []canonical.TurnEvent per event (handles text / thinking / tool_use / signature deltas + per-block close)

Usage

In a provider plugin's go.mod:

require git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client v0.0.0
replace git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client => ../Plexum-anthropic-compat-client

In code:

import (
    "git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client/anthropic"
    "git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client/translate"
)

History

Extracted from Plexum-minimax-provider and Plexum-kimi-provider — both had a near-identical copy. New providers (Qwen, Doubao, …) drop in without re-implementing the protocol.

License

Same as Plexum.

Description
Shared HTTP+SSE Anthropic Messages client + canonical translator for Plexum provider plugins
Readme 39 KiB
Languages
Go 100%