api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserFromContext = staffio.UserFromContext
	ContextWithUser = staffio.ContextWithUser
)

vars from staffio

Functions

func GetOAuthTokenFromCookie

func GetOAuthTokenFromCookie(ctx context.Context, r *http.Request) string

GetOAuthTokenFromCookie retrieves token from cookie. tokenCN must stay consistent with handle_user.go.

func InitChannels added in v0.3.0

func InitChannels(r chi.Router, preset *aigc.Preset, sto stores.Storage, llmClient llm.Client, toolreg *tools.Registry) error

InitChannels initializes channel adapters from preset configuration.

func OAuthTokenMiddleware

func OAuthTokenMiddleware(getToken GetOAuthTokenFunc) func(http.Handler) http.Handler

OAuthTokenMiddleware creates a middleware that injects the OAuth token into the request context. First tries to get token via getToken func (default: cookie), falls back to SiteTokenKey header.

func StopChannels added in v0.3.0

func StopChannels()

StopChannels stops all channel adapters.

Types

type ChatMessage

type ChatMessage struct {
	ID    string `json:"id,omitempty"`
	Delta string `json:"delta,omitempty"`
	Text  string `json:"text,omitempty"`
	Think string `json:"think,omitempty"`
	Role  string `json:"role,omitempty"`
	Name  string `json:"name,omitempty"`

	// For Role=assistant prompts this may be set to the tool calls generated by the model, such as function calls.
	ToolCalls []map[string]any `json:"tool_calls,omitempty"`

	// For Role=tool prompts this should be set to the ID given in the assistant's prior request to call a tool.
	ToolCallID string `json:"tool_call_id,omitempty"`

	FinishReason string `json:"finishReason,omitempty"`

	ConversationID string `json:"csid,omitempty"`

	Title string `json:"title,omitempty"`
}

for response to client

type ChatRequest

type ChatRequest struct {
	Prompt          string `json:"prompt"`
	ConversationID  string `json:"csid"`
	ParentMessageID string `json:"pmid"` // TODO: rename to PreviousMessageID
	Regenerate      bool   `json:"regen"`
	Stream          bool   `json:"stream"`

	MCPs []string `json:"mcps,omitempty"`

	// deprecated: for github.com/Chanzhaoyu/chatgpt-web only
	Options struct {
		ConversationId string `json:"conversationId,omitempty"`
	} `json:"options,omitempty"`
}

func (*ChatRequest) GetConversionID

func (z *ChatRequest) GetConversionID() string

type Command added in v0.3.0

type Command struct {
	Name    string
	Aliases []string
	Desc    string
	Action  func(ctx context.Context, msg *channel.Message) (bool, error)
}

func DetectCommand added in v0.3.0

func DetectCommand(content string) Command

type Done

type Done = resp.Done

type Failure

type Failure = resp.Failure

type GetOAuthTokenFunc

type GetOAuthTokenFunc func(ctx context.Context, r *http.Request) string

GetOAuthTokenFunc is a function type for retrieving OAuth tokens. Currently reads from cookie, future implementations may use Redis/DB.

type M

type M = render.M

type O2User added in v0.3.0

type O2User = staffio.O2User

type ResultData

type ResultData = resp.ResultData

type ResultID

type ResultID = resp.ResultID

type SummaryRequest

type SummaryRequest struct {
	Tips string `json:"tips,omitempty"`
	Text string `json:"text"`
}

SummaryRequest 摘要请求

type ToolExecutor added in v0.3.0

type ToolExecutor struct {
	// contains filtered or unexported fields
}

ToolExecutor 封装工具调用循环逻辑

func NewToolExecutor added in v0.3.0

func NewToolExecutor(toolreg *tools.Registry) *ToolExecutor

NewToolExecutor 创建 ToolExecutor

func (*ToolExecutor) ExecuteToolCallLoop added in v0.3.0

func (e *ToolExecutor) ExecuteToolCallLoop(
	ctx context.Context,
	messages []llm.Message,
	tools []llm.ToolDefinition,
	exec chatExecutor,
) (string, []llm.ToolCall, *llm.Usage, error)

ExecuteToolCallLoop 执行工具调用循环,直到无 tool calls

type User

type User = staffio.User

Jump to

Keyboard shortcuts

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