edition

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package edition provides an extension-point mechanism that allows private overlay modules (e.g. an internal distribution) to customise CLI behaviour without modifying the open-source core. The open-source build uses the zero-value defaults; an overlay calls Override before Execute.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Override

func Override(h *Hooks)

Override replaces the active edition hooks. Must be called before Execute.

Types

type ContentBlock

type ContentBlock struct {
	Type string
	Text string
}

ContentBlock is a single content item in a ToolResult.

type Hooks

type Hooks struct {
	// --- identity ---
	Name         string // "open" (default) / overlay identifier
	ScenarioCode string // injected into x-dingtalk-scenario-code header

	// --- runtime mode ---
	IsEmbedded     bool // true when running inside a host application
	HideAuthLogin  bool // true suppresses the "dws auth login" command
	AutoPurgeToken bool // true deletes local token data on expiry

	// --- paths ---
	ConfigDir func() string // custom config directory; nil → ~/.dws

	// --- HTTP headers ---
	MergeHeaders func(base map[string]string) map[string]string

	// --- auth hooks ---
	OnAuthError   func(configDir string, err error) error
	TokenProvider func(ctx context.Context, fallback func() (string, error)) (string, error)

	// --- token persistence (overlay-only) ---
	// When non-nil, these override the default keychain-based token storage.
	// The data parameter is JSON-serialized TokenData.
	SaveToken   func(configDir string, data []byte) error
	LoadToken   func(configDir string) ([]byte, error)
	DeleteToken func(configDir string) error

	// --- auth credentials (overlay-only) ---
	AuthClientID      string // non-empty overrides DefaultClientID
	AuthClientFromMCP bool   // true routes OAuth through MCP endpoints

	// --- product & endpoint ---
	StaticServers         func() []ServerInfo                          // non-nil → skip Market discovery
	VisibleProducts       func() []string                              // non-nil → override help visibility
	RegisterExtraCommands func(root *cobra.Command, caller ToolCaller) // register overlay-only commands

	// AfterPersistentPreRun runs at the end of the root PersistentPreRunE after
	// global setup (OAuth flag overrides, log level, output sink). Overlays use
	// this for clients that bypass the MCP runner (e.g. A2A gateway).
	AfterPersistentPreRun func(cmd *cobra.Command, args []string) error

	// ClassifyToolResult is called before the framework's default business-error
	// detection on MCP tool results. If it returns a non-nil error, that error
	// is used instead of the generic CategoryAPI business error. Editions use
	// this to return custom error types with specific exit codes (e.g. PAT
	// authorization errors with exit code 4).
	ClassifyToolResult func(content map[string]any) error
}

Hooks groups all edition-specific behavioural overrides. Zero values fall back to open-source defaults so the struct is safe to use as-is.

func Get

func Get() *Hooks

Get returns the active edition hooks (never nil).

type ServerInfo

type ServerInfo struct {
	ID       string
	Name     string
	Endpoint string
	Prefixes []string
}

ServerInfo describes a static MCP server endpoint.

type ToolCaller

type ToolCaller interface {
	// CallTool invokes an MCP tool by product ID and tool name.
	CallTool(ctx context.Context, productID, toolName string, args map[string]any) (*ToolResult, error)
	// Format returns the current output format ("json", "table", "raw").
	Format() string
	// DryRun returns true when --dry-run is active.
	DryRun() bool
}

ToolCaller abstracts MCP tool invocation so private overlays can call MCP tools without importing internal packages. The open-source core provides a concrete adapter wrapping executor.Runner.

type ToolResult

type ToolResult struct {
	Content []ContentBlock
}

ToolResult holds the response from an MCP tool call.

Jump to

Keyboard shortcuts

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