Files
Agent-System-Backend/internal/server/project_lifecycle.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

83 lines
2.6 KiB
Go

package server
import (
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/store"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/pkg/extension"
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
"context"
"errors"
"net/http"
)
// SetProjectLifecycle is wired only for a registered in-process provider. The
// optional host factory constructs a capability scoped to this request's actor.
func (s *Server) SetProjectLifecycle(p extension.ProjectLifecycle, host func(string) extension.Host) {
s.projectLifecycle = &p
s.projectHost = host
}
func (s *Server) lifecycleHost(owner string) extension.Host {
if s.projectHost == nil {
return nil
}
return s.projectHost(owner)
}
func (s *Server) projectWork(ctx context.Context, owner, projectID string) error {
if s.projectLifecycle == nil {
return nil
}
if s.projectLifecycle.Work == nil {
return store.ErrNotFound
}
ok, err := s.projectLifecycle.Work(ctx, owner, core.ID(projectID))
if err != nil {
return err
}
if !ok {
return store.ErrNotFound
}
return nil
}
// createPrivateConversation is shared by the API and /new. Only live work
// authorization grants member creation; the resulting conversation stays owned.
func (s *Server) createPrivateConversation(ctx context.Context, owner, projectID, title, profile string) (core.Conversation, error) {
if s.projectLifecycle != nil {
if err := s.projectWork(ctx, owner, projectID); err != nil {
return core.Conversation{}, err
}
return s.st.CreateConversationInProject(owner, projectID, title, profile)
}
c, err := s.st.CreateConversation(owner, projectID, title, profile)
if errors.Is(err, store.ErrNotFound) && s.authorizeSharedResource(owner, "read", "project", core.ID(projectID), "", core.ID(projectID)) {
return s.st.CreateConversationInProject(owner, projectID, title, profile)
}
return c, err
}
func writeProjectErr(w http.ResponseWriter, err error) {
var coded interface{ StatusCode() int }
if errors.As(err, &coded) {
switch code := coded.StatusCode(); code {
case 400, 403, 404, 409, 503:
http.Error(w, err.Error(), code)
return
}
}
writeStoreErr(w, err)
}
func writeProjectJSON(w http.ResponseWriter, p any, err error) {
if err != nil {
writeProjectErr(w, err)
return
}
writeJSON(w, http.StatusOK, p)
}
// publicProjectMetadata also masks provider-returned metadata, since providers
// may obtain raw owner-management rows before producing a shared public view.
func (s *Server) publicProjectMetadata(p core.Project) core.Project {
if s.projectLifecycle != nil {
p.Settings = s.set.MaskedProjectMetadata(p.Settings)
}
return p
}