Help us shape the future of Go! Take the 2026 Go Developer Survey

adapterkit

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package adapterkit holds the helpers every first-party adapter needs but no vendor SDK touches: schema rendering, the terminal-error rule, and the FilePart exactly-one guard. They lived as byte-identical copies in all three adapters until the 2026-09-18 review flagged the drift risk; they move here rather than into the root's public API — THE-END-GOAL principle 3 names internal/ as the tool that keeps the guaranteed surface small, and Go's path-based internal rule lets github.com/weftgo/weft/{openai,anthropic,google} import the package while third-party adapters cannot. Helpers that mention an SDK type (the stream readers) stay per-adapter by design (ADR 0013).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilePartSource

func FilePartSource(p weft.FilePart) error

FilePartSource validates that a FilePart sets exactly one of Data and URL — the shape every provider's file input takes. Both or neither is a caller bug, refused wrapping ErrUnsupported before any request.

func NextCallID

func NextCallID(used map[string]bool, ordinal int) string

NextCallID synthesises the id for a streamed tool call whose server omitted one: "call_<n>" with n starting at ordinal+1, skipping ids the step has already claimed and marking the chosen id in used. Skipping matters: a repeated id within one step fails the run with ErrModelContract — the exact failure the synthesis exists to prevent — when a server populates some ids of the step itself (llama.cpp-style) with the same call_<n> shape.

func SchemaMap

func SchemaMap(s *weft.Schema) map[string]any

SchemaMap renders a weft.Schema as the plain JSON map the vendors' tool-parameter fields expect (openai-go's FunctionParameters, anthropic-sdk-go's InputSchema). Nil stays nil: a schema-less tool takes the provider's default shape. The rendering goes through json.Marshal, which honours Schema.MarshalJSON — so a schema parsed with weft.ParseSchema reaches the provider as its verbatim foreign bytes (enum, oneOf and all), where the hand-built map this replaced degraded them to the struct's own vocabulary. One rendering change rode along: an unconstrained node (a recursion cut, an interface field) marshalled as {"type": ""} before and is {} now (ADR 0003's 2026-09-19 amendment).

func TerminalErr

func TerminalErr(ctx context.Context, err error) error

TerminalErr reports a stream's terminal error the way the Model contract expects: ctx.Err() when the caller's context ended (the vendor SDKs wrap cancellation in their own error types, and the reader goroutine can exit its handshake with a nil SDK error), the error unchanged otherwise — so callers can errors.As the SDK's type.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL