Skip to content

Latest commit

Β 

History

History
108 lines (77 loc) Β· 2.95 KB

File metadata and controls

108 lines (77 loc) Β· 2.95 KB

πŸ“¦ hawk-sdk-go Architecture

Go SDK for the Hawk Daemon API

Go Dependency


🎯 Overview

Dependency-free Go client for the hawk daemon HTTP API. Exposes idiomatic Go types for chat, streaming, sessions, messages, and stats with automatic retry and typed errors.


🧱 Components

hawk-sdk-go/
β”œβ”€β”€ api/openapi.yaml     πŸ“œ SDK method surface reference
β”œβ”€β”€ client.go            πŸ”Œ Client, New(), With* options, HTTP transport
β”œβ”€β”€ types.go             πŸ“‹ API types (ChatRequest, ChatResponse, Session, Message, Stats)
β”œβ”€β”€ errors.go            ❌ APIError base + typed subclasses
β”œβ”€β”€ retry.go             πŸ”„ RetryConfig, doWithRetry(), sleepWithContext()
β”œβ”€β”€ stream.go            πŸ“‘ StreamReader, SSE parsing
β”œβ”€β”€ stream_helpers.go    πŸ› οΈ collect_text(), collect_tool_calls()
β”œβ”€β”€ agent.go             πŸ€– Agent (conversation history, mutex-safe session ID)
β”œβ”€β”€ tools.go             πŸ› οΈ Tool definitions
β”œβ”€β”€ workflow.go          πŸ”§ Workflow engine
β”œβ”€β”€ version.go           🏷️ Version constant
└── *_test.go            πŸ§ͺ Test files (httptest-based)

πŸ“€ Client Usage

import hawksdk "github.com/GrayCodeAI/hawk-sdk-go"

c := hawksdk.New(
    hawksdk.WithBaseURL("http://localhost:4590"),
    hawksdk.WithAPIKey("sk-..."),
    hawksdk.WithRetry(hawksdk.DefaultRetryConfig()),
)

// 🩺 Health check
health, err := c.Health(ctx)

// πŸ’¬ Non-streaming chat
resp, err := c.Chat(ctx, hawksdk.ChatRequest{Message: "list files"})

// πŸ“‘ Streaming chat
stream, err := c.ChatStream(ctx, hawksdk.ChatRequest{Message: "explain this code"})
defer stream.Close()
for { ev, err := stream.Next(); if err != nil { break }; fmt.Print(ev.Data) }

// πŸ“‹ Sessions
sessions, _ := c.Sessions(ctx, hawksdk.ListOptions{Limit: 10})
msgs, _     := c.Messages(ctx, sessionID, hawksdk.ListOptions{})
_            = c.DeleteSession(ctx, sessionID)

// πŸ“Š Stats
stats, _ := c.Stats(ctx)

πŸ€– Agent (Higher-Level)

agent := hawksdk.NewAgent(c, hawksdk.AgentConfig{SystemPrompt: "You are a Go expert"})
resp, _ := agent.Chat(ctx, "refactor this function")
// Subsequent calls automatically continue the same session

❌ Error Handling

var notFound *hawksdk.NotFoundError
var rateLimit *hawksdk.RateLimitError

if errors.As(err, &notFound)   { /* handle 404 */ }
if errors.As(err, &rateLimit)  { time.Sleep(rateLimit.RetryAfter) }
Error Type HTTP Status
NotFoundError 404
RateLimitError 429
InternalServerError 500

πŸ”Œ Connecting

The daemon must be running: hawk daemon start

Default URL http://127.0.0.1:4590
Override WithBaseURL() or HAWK_BASE_URL env