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 (
|
|
"database/sql"
|
|
"errors"
|
|
"time"
|
|
|
|
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
|
)
|
|
|
|
// Notice 是一条待投递的后台子代理完成通知(N2 WP5)。
|
|
type Notice struct {
|
|
ID string
|
|
ConversationID string
|
|
Owner string
|
|
Name string
|
|
Payload core.AgentResultPayload
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// AppendNotice 落一条待投递通知(重启后可重投)。
|
|
func (s *Store) AppendNotice(n Notice) error {
|
|
_, err := s.db.Exec(s.q(`INSERT INTO pending_notices (id,conversation_id,owner,name,payload,created_at) VALUES(?,?,?,?,?,?)`),
|
|
n.ID, n.ConversationID, n.Owner, n.Name, marshalJSON(&n.Payload), nowISO())
|
|
return err
|
|
}
|
|
|
|
// ListNotices 取回全部待投递通知(Manager 启动时装入内存队列)。
|
|
func (s *Store) ListNotices() ([]Notice, error) {
|
|
rows, err := s.db.Query(s.q(`SELECT id,conversation_id,owner,name,payload,created_at FROM pending_notices ORDER BY created_at`))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var out []Notice
|
|
for rows.Next() {
|
|
var n Notice
|
|
var payload, ca string
|
|
if err := rows.Scan(&n.ID, &n.ConversationID, &n.Owner, &n.Name, &payload, &ca); err != nil {
|
|
return nil, err
|
|
}
|
|
n.Payload, _ = unmarshalJSON[core.AgentResultPayload](payload)
|
|
n.CreatedAt, _ = parseTime(ca)
|
|
out = append(out, n)
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// DeleteNotice 投递成功后删除(按 id 幂等)。
|
|
func (s *Store) DeleteNotice(id string) error {
|
|
_, err := s.db.Exec(s.q(`DELETE FROM pending_notices WHERE id=?`), id)
|
|
return err
|
|
}
|
|
|
|
// DeleteNotices 批量删除(投递成功批)。
|
|
func (s *Store) DeleteNotices(ids []string) error {
|
|
for _, id := range ids {
|
|
if err := s.DeleteNotice(id); err != nil && !errors.Is(err, sql.ErrNoRows) {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|