intake

package
v0.2.3-dev Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package intake implements the bulk-import HTTP surface (parse / confirm / rules) plus a small VK list cache. It is a thin orchestration shell: every vault-touching operation is delegated to the Rust aikey CLI via stdin-JSON IPC (see aikey-cli/src/commands_internal). Go never reads or writes vault.db and never performs AES-GCM.

Companion packages (post 2026-04-30 deep split):

  • pkg/userapi/cli — Bridge subprocess + shared error model
  • pkg/userapi/session — vault session store + RequireUnlock middleware
  • pkg/userapi/vault — unlock/lock/status/init + Vault-page CRUD

The top-level orchestrator (pkg/userapi.Handlers) wires all four together and exposes a single Register() that mounts every /api/user/{vault,import}/* route on the caller's mux.

Package name note: Go keyword `import` cannot be used for a package name, hence `intake` (documented decision in roadmap20260320/技术实现/阶段3-增强版KEY管理/批量导入-实施计划.md §Stage 4).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImportHandlers

type ImportHandlers struct {
	Bridge  *cli.Bridge
	VKCache *VKCache
}

ImportHandlers bundles the /api/user/import/* endpoints. Each handler is a thin envelope around one cli subcommand; the cli owns the business logic (parse engine, vault writes, audit log) and this layer only marshals JSON.

func (*ImportHandlers) ConfirmHandler

func (h *ImportHandlers) ConfirmHandler(w http.ResponseWriter, r *http.Request)

ConfirmHandler: POST /api/user/import/confirm Body: forwarded as the `payload` of cli `_internal vault-op` action="batch_import". Requires unlocked session (caller wraps with vault.Store.RequireUnlock).

func (*ImportHandlers) ParseHandler

func (h *ImportHandlers) ParseHandler(w http.ResponseWriter, r *http.Request)

ParseHandler: POST /api/user/import/parse Body: forwarded as the `payload` of cli `_internal parse` envelope. No vault unlock required — parse runs on plaintext input only.

func (*ImportHandlers) RulesHandler

func (h *ImportHandlers) RulesHandler(w http.ResponseWriter, r *http.Request)

RulesHandler: GET /api/user/import/rules

Delegates to `aikey _internal rules` so the YAML stays the single source of truth (the cli reads aikey-cli/data/provider_fingerprint.yaml).

Returned JSON shape:

{
  "layer_versions":    {"rules":"...", "crf":"...", "fingerprint":"..."},
  "sample_providers":  [...],
  "family_base_urls":  {"anthropic":"https://api.anthropic.com", ...},
  "family_login_urls": {"anthropic":"https://claude.ai/login", ...}
}

FALLBACK: if the cli is missing or fails, we serve a hardcoded snapshot so the Web UI keeps working with stale-but-valid data. The fallback WILL drift if the YAML is updated without redeploying the service binary, but a stale fallback is strictly better than a 5xx that breaks the import page entirely.

type VKCache

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

VKCache is a tiny in-memory TTL cache for the user's virtual-key list. The Web UI queries /api/user/virtual-keys while composing the import manifest to look up aliases + provider bindings; those queries repeat within one editing session, so a short cache avoids hitting the delivery handler on every keystroke.

Stage 4 ships the skeleton; actual wiring to the virtual-key delivery endpoint is Stage 5 work (together with the React interactions). The Get / Set methods are ready-to-call so Stage 5 can just bolt in a fetcher.

func NewVKCache

func NewVKCache(ttl time.Duration) *VKCache

NewVKCache returns a cache with the given per-entry TTL. Defaults recommended: 5 * time.Minute per UX v2 "sliding TTL on read".

func (*VKCache) Get

func (c *VKCache) Get(key string) ([]byte, bool)

Get returns the cached value and a cache-hit flag. Expired entries are evicted lazily on read.

func (*VKCache) Invalidate

func (c *VKCache) Invalidate(key string)

Invalidate drops a key (called after batch_import succeeds so the next VK list fetch reflects the newly imported aliases).

func (*VKCache) Set

func (c *VKCache) Set(key string, value []byte)

Set stores a value under key with the cache's configured TTL.

Jump to

Keyboard shortcuts

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