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
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
|
)
|
|
|
|
// SavePromptModule 写用户提示词模块(覆盖或新建;按 owner 隔离)。
|
|
func (s *Store) SavePromptModule(owner string, m core.PromptModule) error {
|
|
if m.Owner == "" {
|
|
m.Owner = owner
|
|
}
|
|
payload, err := json.Marshal(m)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = s.db.Exec(s.q(`INSERT INTO prompt_modules(id, owner, payload) VALUES(?,?,?)
|
|
ON CONFLICT(id, owner) DO UPDATE SET payload=excluded.payload`), m.ID, owner, payload)
|
|
return err
|
|
}
|
|
|
|
// ListPromptModules 返回该 owner 的用户模块(不含内置——内置在 embed 库)。
|
|
func (s *Store) ListPromptModules(owner string) ([]core.PromptModule, error) {
|
|
rows, err := s.db.Query(s.q(`SELECT payload FROM prompt_modules WHERE owner=?`), owner)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var out []core.PromptModule
|
|
for rows.Next() {
|
|
var payload []byte
|
|
if err := rows.Scan(&payload); err != nil {
|
|
return nil, err
|
|
}
|
|
var m core.PromptModule
|
|
if err := json.Unmarshal(payload, &m); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, m)
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// GetPromptModule 读单个用户模块。
|
|
func (s *Store) GetPromptModule(owner, id string) (core.PromptModule, error) {
|
|
var payload []byte
|
|
err := s.db.QueryRow(s.q(`SELECT payload FROM prompt_modules WHERE id=? AND owner=?`), id, owner).Scan(&payload)
|
|
if err != nil {
|
|
return core.PromptModule{}, err
|
|
}
|
|
var m core.PromptModule
|
|
if err := json.Unmarshal(payload, &m); err != nil {
|
|
return core.PromptModule{}, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeletePromptModule 删除用户模块(内置不受影响)。
|
|
func (s *Store) DeletePromptModule(owner, id string) error {
|
|
_, err := s.db.Exec(s.q(`DELETE FROM prompt_modules WHERE id=? AND owner=?`), id, owner)
|
|
return err
|
|
}
|