Files
xinmi/WORKBENCH_CONTRACT.md
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

4.2 KiB

Native workbench implementation contract

Brand: 私域Agent. Base API: /api/v1/workbench. All routes use the existing WeKnora auth middleware and tenant RBAC; no FastAPI calls or shared admin JWT.

HTTP

  • GET /modules: enabled module metadata.
  • GET /resources/:kind: {success:true,data:Resource[],total:number}; page/page_size/q.
  • POST /resources/:kind: {name,data} -> Resource.
  • GET /resources/:kind/:id: Resource.
  • PUT /resources/:kind/:id: {name,data,version} -> Resource; optimistic locking.
  • DELETE /resources/:kind/:id?detach=true: delete owned resource, optional explicit detach.
  • POST /resources/:kind/:id/actions/:action: {version, advice?, day?, segment_id?, agent_id?} -> {success:true,data:Job} for asynchronous AI work, Resource for synchronous work.
  • GET /jobs/:id: Job including progress, stage, error and generation usage metadata.
  • GET /notifications, POST /notifications/read-all.

Resource: {id,tenant_id,owner_id,owner_name,kind,name,status,version,data,created_at,updated_at}. Kinds in this package: training-maps, content-tasks, flows. Digital humans are implemented separately as typed /api/v1/digital-humans routes; skills and memories reuse native modules and receive extensions separately. IDs are UUIDs, owner/tenant derived from auth. Defaults private. Admin can inspect all resources in the active tenant, while mutations, deletion, queued AI actions and bindings remain owner-only. Data is versioned JSON with per-kind validation.

Job: {id,resource_id,kind,action,status,progress,stage,error,generation,created_at,updated_at}. Status queued/running/succeeded/failed/cancelled. Progress measures completed stages; the UI must not display invented countdowns. Concurrent writes use resource version.

Payloads

  • training-maps: {topic,days_count,agent_id,knowledge_base_ids:[],knowledge_ids:[],days:[{day,title,prerequisite,hook,nodes:[{id,label,children:[]}],framework,confirmed}],advice}. Actions generate/revise (optional day)/generate-day (day)/confirm-day (day)/confirm.
  • flows: {nodes:[{id,agent_id,label}],edges:[{source,target}],description}.
  • content-tasks: {map_id,day,flow_id,agent_id,knowledge_base_ids:[],segments:[{id,title,agent_id,status,content,review,source_ids:[]}],review,composed}. Actions decompose/generate (segment_id)/accept/skip/revise (segment_id + advice)/review/compose.
  • digital-humans: {description,source_text,agent_id,model_id,profile,versions:[]}. Actions distill (advice optional)/approve. Linked native CustomAgent created automatically.
  • instruction skills: /api/v1/skills/instructions lists/reads creator-owned Markdown rules; POST /instructions/import accepts UTF-8 .md (256 KB, 16k-token rule limit), and POST /instructions/mount accepts agent_ids, skill_ids and mode (add, remove, replace). Rules are creator-private, never executed as code, and are injected into native chat and workbench generation after access checks. Executable sandbox skills remain governed by the native catalog and are separate from these rules.
  • memories: {agent_id,content,source}.

Go package contract

Package internal/workbench. Root owns service.go, models.go, handler.go, jobs.go, generation.go, content/map operations, router/container wiring. Resources have Data JSON (map[string]any implementing SQL Scanner/Valuer). Service fields: db *gorm.DB, models interfaces.ModelService, agents interfaces.CustomAgentService, sessions interfaces.SessionService. Helpers: s.get(ctx,kind,id) (*Resource,error), s.save(ctx,*Resource,expectedVersion) error, s.complete(ctx,agentID,system,prompt string) (string,error), s.progress(ctx,jobID string,percent int,stage string) error. Digital humans use separate types/interfaces/repository/service/handler and migration 000091. Their default Agent is private and created transactionally; review syncs its persona, and deletion cleans its default Agent, bindings and IM channels. Workbench generation resolves mounted instruction skills through an injected resolver.

Implementation status must be recorded honestly. Persisted CRUD alone is not a complete port of a legacy workflow. Keep original data until verified ETL and parity.