Documentation
¶
Overview ¶
Package clientsdk invokes installed NeKiro Agents through the platform Gateway. It is an application-facing SDK and is intentionally separate from the Agent SDK used for trusted nested Agent-to-Agent calls.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client invokes installed Agents through one configured Gateway and Workspace. A Client is immutable after construction and safe for concurrent independent calls.
Example ¶
package main
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"os"
"time"
"github.com/NeKiro-project/NeKiro/contracts"
clientsdk "github.com/NeKiro-project/nekiro-sdk-go/client"
)
func main() {
// Installation is a separate, explicit Gateway operation. Once an Agent is
// installed and enabled, application code binds one Client to that
// Workspace and never supplies an endpoint, version, Release, or Router.
client, err := clientsdk.NewClient(clientsdk.Config{
HTTPClient: &http.Client{Timeout: 30 * time.Second},
GatewayOrigin: "https://api.nekiro.dev",
WorkspaceID: "workspace-production",
ApplicationCredential: os.Getenv("NEKIRO_APPLICATION_CREDENTIAL"),
RequestLimitBytes: 1 << 20,
ResponseLimitBytes: 4 << 20,
StreamEventLimitBytes: 256 << 10,
})
if err != nil {
return
}
result, err := client.Invoke(context.Background(), clientsdk.InvokeRequest{
AgentID: "summarizer",
Capability: "document.summarize",
Input: json.RawMessage(`{"document":"..."}`),
})
if err != nil {
var platformError *clientsdk.PlatformError
if errors.As(err, &platformError) && platformError.Code == contracts.ErrorCodeAgentNotInstalled {
// Ask the Workspace owner to install the Agent; the SDK does not
// silently install or select another destination.
}
return
}
_ = result.Output
stream, err := client.InvokeStream(context.Background(), clientsdk.InvokeRequest{
AgentID: "summarizer",
Capability: "document.summarize",
Input: json.RawMessage(`{"document":"..."}`),
})
if err != nil {
return
}
defer func() { _ = stream.Close() }()
for {
event, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return
}
_ = event
}
}
Output:
func (Client) Format ¶
Format prevents generic log formatting from exposing the Client's bound application credential or transport configuration.
func (*Client) InvokeStream ¶
InvokeStream performs exactly one streaming Gateway invocation and returns after the HTTP status, media type, and Trace header have been validated.
type Config ¶
type Config struct {
HTTPClient *http.Client
GatewayOrigin string
WorkspaceID string
ApplicationCredential string `json:"-"`
RequestLimitBytes int64
ResponseLimitBytes int64
StreamEventLimitBytes int64
}
Config binds one Client to one Gateway origin and Workspace authorization context. Every field is required; the SDK supplies no transport, identity, credential, or byte-limit default.
type InvokeRequest ¶
type InvokeRequest struct {
AgentID string
Capability string
Input json.RawMessage
}
InvokeRequest contains the only business-controlled invocation fields. Workspace, routing, version, Release, correlation, and credentials are not accepted per call.
type PlatformError ¶
type PlatformError struct {
StatusCode int
Code contracts.PlatformErrorCode
TraceID contracts.TraceID
InvocationID string
RootTaskID string
}
PlatformError contains only validated, stable Gateway failure context. It deliberately does not retain the fixed wire message or raw response body.
func (*PlatformError) Correlated ¶
func (platformError *PlatformError) Correlated() bool
Correlated reports whether Gateway returned the complete accepted Invocation and root Task identity pair.
func (*PlatformError) Error ¶
func (platformError *PlatformError) Error() string
Error returns only the HTTP status and stable platform code.
type Result ¶
type Result struct {
InvocationID string
RootTaskID string
TraceID contracts.TraceID
Output json.RawMessage
}
Result is a validated non-streaming Gateway result.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream owns one successful live Gateway response. It has a single consumer and is not safe for concurrent Recv or Close calls.
func (*Stream) Close ¶
Close releases the response body. Until terminal followed by actual EOF has been observed, Close records and returns an interrupted-stream error.
func (*Stream) Recv ¶
func (stream *Stream) Recv() (StreamEvent, error)
Recv returns the next validated stream event. A clean io.EOF is returned only after one terminal event has been returned and transport EOF is then observed.
type StreamEvent ¶
type StreamEvent = contracts.InvocationResultStreamEventV2
StreamEvent is the active Result Stream Event v2 contract exposed after SDK framing, shape, sequence, and correlation validation.