app

package
v0.11.13 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package app is the public entry point for downstream projects that want to embed wick as a library. A typical main looks like:

package main

import "github.com/yogasw/wick/app"

func main() {
    app.RegisterTool(toolMeta, toolCfg, mytool.Register)
    app.RegisterJob(jobMeta, jobCfg, myjob.Run)
    app.Run()
}

Navbar, admin, auth, rendering, and the cron scheduler are handled by wick; downstream only supplies per-instance meta, a typed config value, and a RegisterFunc / RunFunc that does the work.

Index

Constants

This section is empty.

Variables

View Source
var (
	// BuildAppName is set in init() from appname.Resolve() so this
	// package and `internal/appname` always agree on the active brand.
	// The ldflag injection target lives in `internal/appname` (single
	// source of truth); this var is just the local mirror legacy
	// callers reach for via `app.BuildAppName`.
	BuildAppName     = "app"
	BuildAppVersion  = "dev"
	BuildWickVersion = "dev"
	BuildCommit      = "unknown"
	BuildTime        = "unknown"

	// GitHubPATEnc is the base64-of-XOR-encoded PAT injected by
	// `wick build --release-github-pat ...`. Stored obfuscated so plain
	// `strings <binary>` does not surface the token; init() below decodes
	// it into GitHubPAT at runtime.
	//
	// This is obfuscation, not encryption — a determined attacker can
	// extract patObfKey from the binary and decode. Real defense is
	// scoping PAT to read-only on the releases repo (see release.yml).
	GitHubPATEnc = ""
	GitHubPAT    string

	// GitHubRepo is the releases repo (owner/repo) — public information,
	// not obfuscated.
	GitHubRepo = ""
)

Build* vars are injected via -ldflags at build time:

BuildAppName     downstream app's `name:` from wick.yml
BuildAppVersion  downstream app's `version:` from wick.yml
BuildWickVersion wick framework version (semver of github.com/yogasw/wick)
BuildCommit      git short hash of the build
BuildTime        build timestamp (RFC3339)

The wick.yml `build` task injects BuildAppName + BuildAppVersion from the {{.NAME}} / {{.VERSION}} task vars. init() below auto-fills BuildWickVersion / BuildCommit / BuildTime from embedded build info when ldflags didn't override them — so binaries built without ldflags still report a sensible wick version.

Functions

func RegisterConnector added in v0.4.0

func RegisterConnector[C any](meta connector.Meta, creds C, ops []connector.Operation)

RegisterConnector adds a connector definition to the registry. One call = one Go module wired up to wick's MCP layer; per-instance rows (credentials, labels, tags) are created later from the admin UI and stored in the connector_instances table.

app.RegisterConnector(
    loki.Meta(),
    loki.Creds{},        // typed credential struct, reflected for the form
    loki.Operations(),   // []connector.Operation, one per LLM-callable action
)

creds is a typed struct whose exported fields carry `wick:"..."` tags and represent per-instance credential / endpoint values shared across every operation of this connector. ops is the list of named actions (one MCP tool per op per instance); each carries its own input schema and ExecuteFunc. Pass an empty struct{}{} for creds when the connector has no credentials.

func RegisterJob

func RegisterJob[C any](meta job.Meta, cfg C, run job.RunFunc)

RegisterJob adds a downstream background job to the registry. One call = one row in the jobs table; call again with a different meta.Key (and, if you want, a different cfg) to register a second scheduled instance backed by the same RunFunc. The job is seeded on first boot with meta.DefaultCron; admins override from /manager/jobs.

app.RegisterJob(
    job.Meta{Key: "auto-get-data", Name: "Auto Get Data", Icon: "🌐", DefaultCron: "*/30 * * * *"},
    autogetdata.Config{Endpoint: "https://api.example.com"},
    autogetdata.Run,
)

cfg is a typed struct whose exported fields carry `wick:"..."` tags. Wick reflects it once here into `configs` rows scoped to meta.Key — Run reads live values via job.FromContext(ctx).Cfg(...). Pass an empty struct{}{} when the job has no runtime-editable knobs.

func RegisterJobNoConfig

func RegisterJobNoConfig(meta job.Meta, run job.RunFunc)

RegisterJobNoConfig is the variant for jobs that have nothing to configure at runtime. Equivalent to RegisterJob with an empty struct{} cfg.

func RegisterTool

func RegisterTool[C any](meta tool.Tool, cfg C, register tool.RegisterFunc)

RegisterTool adds a tool instance to the registry. One call = one card on the home grid; call again with a different meta.Key (and, if you want, a different cfg) to register a second instance backed by the same RegisterFunc.

app.RegisterTool(
    tool.Tool{Key: "convert-text", Name: "Convert Text", Icon: "Aa"},
    converttext.Config{InitText: "hello world"},
    converttext.Register,
)

cfg is a typed struct whose exported fields carry `wick:"..."` tags. Wick reflects it once here into `configs` rows scoped to meta.Key — handlers read the live values via c.Cfg(...) at request time.

func RegisterToolNoConfig

func RegisterToolNoConfig(meta tool.Tool, register tool.RegisterFunc)

RegisterToolNoConfig is the variant for tools that have nothing to configure at runtime — e.g. external redirect links. Equivalent to RegisterTool with an empty struct{} cfg.

func Run

func Run()

Run parses the command-line flags and starts either the HTTP server or the background worker. Subcommands:

server   — run the HTTP server (default)
worker   — run the background job worker
mcp serve — run MCP server over stdio

Blocks until shutdown.

Types

This section is empty.

Jump to

Keyboard shortcuts

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